]> code.delx.au - gnu-emacs/blob - src/emacsgtkfixed.c
Merge branch 'master' into xwidget
[gnu-emacs] / src / emacsgtkfixed.c
1 /* A Gtk Widget that inherits GtkFixed, but can be shrunk.
2 This file is only use when compiling with Gtk+ 3.
3
4 Copyright (C) 2011-2015 Free Software Foundation, Inc.
5
6 This file is part of GNU Emacs.
7
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include <config.h>
22
23 #include "lisp.h"
24 #include "frame.h"
25 #include "xterm.h"
26 #ifdef HAVE_XWIDGETS
27 #include "xwidget.h"
28 #endif
29 #include "emacsgtkfixed.h"
30
31 /* Silence a bogus diagnostic; see GNOME bug 683906. */
32 #if 4 < __GNUC__ + (7 <= __GNUC_MINOR__)
33 # pragma GCC diagnostic push
34 # pragma GCC diagnostic ignored "-Wunused-local-typedefs"
35 #endif
36
37 //#define EMACS_TYPE_FIXED emacs_fixed_get_type ()
38 /* #define EMACS_FIXED(obj) \ */
39 /* G_TYPE_CHECK_INSTANCE_CAST (obj, EMACS_TYPE_FIXED, EmacsFixed) */
40
41 typedef struct _EmacsFixed EmacsFixed;
42 typedef struct _EmacsFixedPrivate EmacsFixedPrivate;
43 typedef struct _EmacsFixedClass EmacsFixedClass;
44
45 /* struct _EmacsFixed */
46 /* { */
47 /* GtkFixed container; */
48
49 /* /\*< private >*\/ */
50 /* EmacsFixedPrivate *priv; */
51 /* }; */
52
53 /* struct _EmacsFixedClass */
54 /* { */
55 /* GtkFixedClass parent_class; */
56 /* }; */
57
58 struct _EmacsFixedPrivate
59 {
60 struct frame *f;
61 };
62
63
64 static void emacs_fixed_get_preferred_width (GtkWidget *widget,
65 gint *minimum,
66 gint *natural);
67 static void emacs_fixed_get_preferred_height (GtkWidget *widget,
68 gint *minimum,
69 gint *natural);
70 G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED)
71
72 #ifdef HAVE_XWIDGETS
73
74 struct GtkFixedPrivateL
75 {
76 GList *children;
77 };
78
79 static void emacs_fixed_gtk_widget_size_allocate (GtkWidget *widget,
80 GtkAllocation *allocation){
81 //for xwidgets
82
83 //TODO 1st call base class method
84 EmacsFixedClass *klass;
85 GtkWidgetClass *parent_class;
86 struct GtkFixedPrivateL* priv;
87 GtkFixedChild *child;
88 GtkAllocation child_allocation;
89 GtkRequisition child_requisition;
90 GList *children;
91 struct xwidget_view* xv;
92
93 klass = EMACS_FIXED_GET_CLASS (widget);
94 parent_class = g_type_class_peek_parent (klass);
95 parent_class->size_allocate (widget, allocation);
96
97 priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
98 GTK_TYPE_FIXED,
99 struct GtkFixedPrivateL);
100
101 gtk_widget_set_allocation (widget, allocation);
102
103 if (gtk_widget_get_has_window (widget))
104 {
105 if (gtk_widget_get_realized (widget))
106 gdk_window_move_resize (gtk_widget_get_window (widget),
107 allocation->x,
108 allocation->y,
109 allocation->width,
110 allocation->height);
111 }
112
113 for (children = priv->children;
114 children;
115 children = children->next)
116 {
117 child = children->data;
118
119 if (!gtk_widget_get_visible (child->widget))
120 continue;
121
122 gtk_widget_get_preferred_size (child->widget, &child_requisition, NULL);
123 child_allocation.x = child->x;
124 child_allocation.y = child->y;
125
126 if (!gtk_widget_get_has_window (widget))
127 {
128 child_allocation.x += allocation->x;
129 child_allocation.y += allocation->y;
130 }
131
132 child_allocation.width = child_requisition.width;
133 child_allocation.height = child_requisition.height;
134
135
136
137 xv = (struct xwidget_view*) g_object_get_data (G_OBJECT (child->widget), XG_XWIDGET_VIEW);
138 if(xv){
139 child_allocation.width = xv->clip_right;
140 child_allocation.height = xv->clip_bottom - xv->clip_top;
141 }
142 gtk_widget_size_allocate (child->widget, &child_allocation);
143
144 }
145
146 }
147
148 #endif /* HAVE_XWIDGETS */
149
150 static void
151 emacs_fixed_class_init (EmacsFixedClass *klass)
152 {
153 GtkWidgetClass *widget_class;
154 GtkFixedClass *fixed_class;
155
156 widget_class = (GtkWidgetClass*) klass;
157 fixed_class = (GtkFixedClass*) klass;
158
159 widget_class->get_preferred_width = emacs_fixed_get_preferred_width;
160 widget_class->get_preferred_height = emacs_fixed_get_preferred_height;
161 #ifdef HAVE_XWIDGETS
162 widget_class->size_allocate = emacs_fixed_gtk_widget_size_allocate;
163 #endif
164 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate));
165 }
166
167 static GType
168 emacs_fixed_child_type (GtkFixed *container)
169 {
170 return GTK_TYPE_WIDGET;
171 }
172
173 static void
174 emacs_fixed_init (EmacsFixed *fixed)
175 {
176 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, EMACS_TYPE_FIXED,
177 EmacsFixedPrivate);
178 fixed->priv->f = 0;
179 }
180
181 /**
182 * emacs_fixed_new:
183 *
184 * Creates a new #EmacsFixed.
185 *
186 * Returns: a new #EmacsFixed.
187 */
188 GtkWidget*
189 emacs_fixed_new (struct frame *f)
190 {
191 EmacsFixed *fixed = g_object_new (EMACS_TYPE_FIXED, NULL);
192 EmacsFixedPrivate *priv = fixed->priv;
193 priv->f = f;
194 return GTK_WIDGET (fixed);
195 }
196
197 static void
198 emacs_fixed_get_preferred_width (GtkWidget *widget,
199 gint *minimum,
200 gint *natural)
201 {
202 EmacsFixed *fixed = EMACS_FIXED (widget);
203 EmacsFixedPrivate *priv = fixed->priv;
204 int w = priv->f->output_data.x->size_hints.min_width;
205 if (minimum) *minimum = w;
206 if (natural) *natural = w;
207 }
208
209 static void
210 emacs_fixed_get_preferred_height (GtkWidget *widget,
211 gint *minimum,
212 gint *natural)
213 {
214 EmacsFixed *fixed = EMACS_FIXED (widget);
215 EmacsFixedPrivate *priv = fixed->priv;
216 int h = priv->f->output_data.x->size_hints.min_height;
217 if (minimum) *minimum = h;
218 if (natural) *natural = h;
219 }
220
221
222 /* Override the X function so we can intercept Gtk+ 3 calls.
223 Use our values for min_width/height so that KDE don't freak out
224 (Bug#8919), and so users can resize our frames as they wish. */
225
226 void
227 XSetWMSizeHints (Display* d,
228 Window w,
229 XSizeHints* hints,
230 Atom prop)
231 {
232 struct x_display_info *dpyinfo = x_display_info_for_display (d);
233 struct frame *f = x_top_window_to_frame (dpyinfo, w);
234 long data[18];
235 data[0] = hints->flags;
236 data[1] = hints->x;
237 data[2] = hints->y;
238 data[3] = hints->width;
239 data[4] = hints->height;
240 data[5] = hints->min_width;
241 data[6] = hints->min_height;
242 data[7] = hints->max_width;
243 data[8] = hints->max_height;
244 data[9] = hints->width_inc;
245 data[10] = hints->height_inc;
246 data[11] = hints->min_aspect.x;
247 data[12] = hints->min_aspect.y;
248 data[13] = hints->max_aspect.x;
249 data[14] = hints->max_aspect.y;
250 data[15] = hints->base_width;
251 data[16] = hints->base_height;
252 data[17] = hints->win_gravity;
253
254 if ((hints->flags & PMinSize) && f)
255 {
256 int w = f->output_data.x->size_hints.min_width;
257 int h = f->output_data.x->size_hints.min_height;
258 data[5] = w;
259 data[6] = h;
260 }
261
262 XChangeProperty (d, w, prop, XA_WM_SIZE_HINTS, 32, PropModeReplace,
263 (unsigned char *) data, 18);
264 }
265
266 /* Override this X11 function.
267 This function is in the same X11 file as the one above. So we must
268 provide it also. */
269
270 void
271 XSetWMNormalHints (Display *d, Window w, XSizeHints *hints)
272 {
273 XSetWMSizeHints (d, w, hints, XA_WM_NORMAL_HINTS);
274 }