Merge from emacs-24; up to 2012-05-07T21:26:08Z!rgm@gnu.org
[bpt/emacs.git] / src / emacsgtkfixed.c
CommitLineData
c80e3b4a 1/* A Gtk Widget that inherits GtkFixed, but can be shrunk.
c7e73be5 2This file is only use when compiling with Gtk+ 3.
c195f2de 3
acaf905b 4Copyright (C) 2011-2012 Free Software Foundation, Inc.
c195f2de
JD
5
6This file is part of GNU Emacs.
7
8GNU Emacs is free software: you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation, either version 3 of the License, or
11(at your option) any later version.
12
13GNU Emacs is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20
c7e73be5 21#include <config.h>
c195f2de 22
c7e73be5 23#include "emacsgtkfixed.h"
c7e73be5 24#include <stdio.h>
0328b6de 25
c7e73be5
JD
26#include "lisp.h"
27#include "frame.h"
28#include "xterm.h"
c195f2de 29
5f0cb45a 30/* Silence a bogus diagnostic; see GNOME bug 683906. */
8ea47e3a
PE
31#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
32# pragma GCC diagnostic push
33# pragma GCC diagnostic ignored "-Wunused-local-typedefs"
34#endif
5f0cb45a 35
1068fe4d
PE
36#define EMACS_TYPE_FIXED emacs_fixed_get_type ()
37#define EMACS_FIXED(obj) \
38 G_TYPE_CHECK_INSTANCE_CAST (obj, EMACS_TYPE_FIXED, EmacsFixed)
39
40typedef struct _EmacsFixed EmacsFixed;
41typedef struct _EmacsFixedPrivate EmacsFixedPrivate;
42typedef struct _EmacsFixedClass EmacsFixedClass;
43
44struct _EmacsFixed
45{
46 GtkFixed container;
47
48 /*< private >*/
49 EmacsFixedPrivate *priv;
50};
51
52struct _EmacsFixedClass
53{
54 GtkFixedClass parent_class;
55};
56
c195f2de
JD
57struct _EmacsFixedPrivate
58{
c7e73be5 59 struct frame *f;
c195f2de
JD
60};
61
62
63static void emacs_fixed_get_preferred_width (GtkWidget *widget,
64 gint *minimum,
65 gint *natural);
66static void emacs_fixed_get_preferred_height (GtkWidget *widget,
67 gint *minimum,
68 gint *natural);
1068fe4d 69static GType emacs_fixed_get_type (void);
c195f2de
JD
70G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED)
71
72static void
73emacs_fixed_class_init (EmacsFixedClass *klass)
74{
75 GtkWidgetClass *widget_class;
c195f2de
JD
76
77 widget_class = (GtkWidgetClass*) klass;
c195f2de
JD
78
79 widget_class->get_preferred_width = emacs_fixed_get_preferred_width;
80 widget_class->get_preferred_height = emacs_fixed_get_preferred_height;
81 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate));
82}
83
c195f2de
JD
84static void
85emacs_fixed_init (EmacsFixed *fixed)
86{
87 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, EMACS_TYPE_FIXED,
88 EmacsFixedPrivate);
c7e73be5 89 fixed->priv->f = 0;
c195f2de
JD
90}
91
92/**
93 * emacs_fixed_new:
94 *
95 * Creates a new #EmacsFixed.
96 *
97 * Returns: a new #EmacsFixed.
98 */
99GtkWidget*
c7e73be5 100emacs_fixed_new (struct frame *f)
c195f2de 101{
c7e73be5
JD
102 EmacsFixed *fixed = g_object_new (EMACS_TYPE_FIXED, NULL);
103 EmacsFixedPrivate *priv = fixed->priv;
104 priv->f = f;
105 return GTK_WIDGET (fixed);
c195f2de
JD
106}
107
108static void
109emacs_fixed_get_preferred_width (GtkWidget *widget,
110 gint *minimum,
111 gint *natural)
112{
113 EmacsFixed *fixed = EMACS_FIXED (widget);
114 EmacsFixedPrivate *priv = fixed->priv;
c7e73be5
JD
115 int w = priv->f->output_data.x->size_hints.min_width;
116 if (minimum) *minimum = w;
117 if (natural) *natural = w;
c195f2de
JD
118}
119
120static void
121emacs_fixed_get_preferred_height (GtkWidget *widget,
122 gint *minimum,
123 gint *natural)
124{
125 EmacsFixed *fixed = EMACS_FIXED (widget);
126 EmacsFixedPrivate *priv = fixed->priv;
c7e73be5
JD
127 int h = priv->f->output_data.x->size_hints.min_height;
128 if (minimum) *minimum = h;
129 if (natural) *natural = h;
c195f2de
JD
130}
131
c7e73be5
JD
132
133/* Override the X function so we can intercept Gtk+ 3 calls.
134 Use our values for min_width/height so that KDE don't freak out
135 (Bug#8919), and so users can resize our frames as they wish. */
136
c195f2de 137void
5e617bc2
JB
138XSetWMSizeHints (Display* d,
139 Window w,
140 XSizeHints* hints,
141 Atom prop)
c195f2de 142{
c7e73be5
JD
143 struct x_display_info *dpyinfo = x_display_info_for_display (d);
144 struct frame *f = x_top_window_to_frame (dpyinfo, w);
145 long data[18];
146 data[0] = hints->flags;
147 data[1] = hints->x;
148 data[2] = hints->y;
149 data[3] = hints->width;
150 data[4] = hints->height;
151 data[5] = hints->min_width;
152 data[6] = hints->min_height;
153 data[7] = hints->max_width;
154 data[8] = hints->max_height;
155 data[9] = hints->width_inc;
156 data[10] = hints->height_inc;
157 data[11] = hints->min_aspect.x;
158 data[12] = hints->min_aspect.y;
159 data[13] = hints->max_aspect.x;
160 data[14] = hints->max_aspect.y;
161 data[15] = hints->base_width;
162 data[16] = hints->base_height;
163 data[17] = hints->win_gravity;
164
165 if ((hints->flags & PMinSize) && f)
166 {
167 int w = f->output_data.x->size_hints.min_width;
168 int h = f->output_data.x->size_hints.min_height;
169 data[5] = w;
170 data[6] = h;
171 }
172
173 XChangeProperty (d, w, prop, XA_WM_SIZE_HINTS, 32, PropModeReplace,
174 (unsigned char *) data, 18);
175}
c195f2de 176
c7e73be5
JD
177/* Override this X11 function.
178 This function is in the same X11 file as the one above. So we must
179 provide it also. */
5e617bc2 180
c7e73be5
JD
181void
182XSetWMNormalHints (Display *d, Window w, XSizeHints *hints)
183{
184 XSetWMSizeHints (d, w, hints, XA_WM_NORMAL_HINTS);
c195f2de 185}