Mercurial > emacs
annotate src/gtkutil.c @ 50286:53cf1a79b0f5
*** empty log message ***
author | John Paul Wallington <jpw@pobox.com> |
---|---|
date | Mon, 24 Mar 2003 03:33:53 +0000 |
parents | c5e286e85257 |
children | 5b50d76d9211 |
rev | line source |
---|---|
49323 | 1 /* Functions for creating and updating GTK widgets. |
2 Copyright (C) 2003 | |
3 Free Software Foundation, Inc. | |
4 | |
5 This file is part of GNU Emacs. | |
6 | |
7 GNU Emacs is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 2, or (at your option) | |
10 any later version. | |
11 | |
12 GNU Emacs is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GNU Emacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 #include "config.h" | |
23 | |
24 #ifdef USE_GTK | |
49359
14cf50ecf91a
gtkutil.c: Must include stdio.h before termhooks.h
Jan Djärv <jan.h.d@swipnet.se>
parents:
49325
diff
changeset
|
25 #include <string.h> |
14cf50ecf91a
gtkutil.c: Must include stdio.h before termhooks.h
Jan Djärv <jan.h.d@swipnet.se>
parents:
49325
diff
changeset
|
26 #include <stdio.h> |
49323 | 27 #include "lisp.h" |
28 #include "xterm.h" | |
29 #include "blockinput.h" | |
30 #include "window.h" | |
31 #include "atimer.h" | |
32 #include "gtkutil.h" | |
33 #include "termhooks.h" | |
34 #include <gdk/gdkkeysyms.h> | |
35 | |
36 #define FRAME_TOTAL_PIXEL_HEIGHT(f) \ | |
37 (PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f)) | |
50129
d0142038feaa
Reduce flicker in GTK scrollbars.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50112
diff
changeset
|
38 |
d0142038feaa
Reduce flicker in GTK scrollbars.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50112
diff
changeset
|
39 |
49323 | 40 |
41 /*********************************************************************** | |
42 Utility functions | |
43 ***********************************************************************/ | |
44 /* The timer for scroll bar repetition and menu bar timeouts. | |
45 NULL if no timer is started. */ | |
46 static struct atimer *xg_timer; | |
47 | |
48 /* The cursor used for scroll bars and popup menus. | |
49 We only have one cursor for all scroll bars and all popup menus. */ | |
50 static GdkCursor *xg_left_ptr_cursor; | |
51 | |
52 | |
53 /* The next two variables and functions are taken from lwlib. */ | |
54 static widget_value *widget_value_free_list; | |
55 static int malloc_cpt; | |
56 | |
57 /* Allocate a widget_value structure, either by taking one from the | |
58 widget_value_free_list or by malloc:ing a new one. | |
59 | |
60 Return a pointer to the allocated structure. */ | |
61 widget_value * | |
62 malloc_widget_value () | |
63 { | |
64 widget_value *wv; | |
65 if (widget_value_free_list) | |
66 { | |
67 wv = widget_value_free_list; | |
68 widget_value_free_list = wv->free_list; | |
69 wv->free_list = 0; | |
70 } | |
71 else | |
72 { | |
73 wv = (widget_value *) malloc (sizeof (widget_value)); | |
74 malloc_cpt++; | |
75 } | |
76 memset (wv, 0, sizeof (widget_value)); | |
77 return wv; | |
78 } | |
79 | |
80 /* This is analogous to free. It frees only what was allocated | |
81 by malloc_widget_value, and no substructures. */ | |
82 void | |
83 free_widget_value (wv) | |
84 widget_value *wv; | |
85 { | |
86 if (wv->free_list) | |
87 abort (); | |
88 | |
89 if (malloc_cpt > 25) | |
90 { | |
91 /* When the number of already allocated cells is too big, | |
92 We free it. */ | |
93 free (wv); | |
94 malloc_cpt--; | |
95 } | |
96 else | |
97 { | |
98 wv->free_list = widget_value_free_list; | |
99 widget_value_free_list = wv; | |
100 } | |
101 } | |
102 | |
103 /* Set *CURSOR on W and all widgets W contain. We must do like this | |
104 for scroll bars and menu because they create widgets internally, | |
105 and it is those widgets that are visible. | |
106 | |
107 If *CURSOR is NULL, create a GDK_LEFT_PTR cursor and set *CURSOR to | |
108 the created cursor. */ | |
109 void | |
110 xg_set_cursor (w, cursor) | |
111 GtkWidget *w; | |
112 GdkCursor **cursor; | |
113 { | |
114 GList *children = gdk_window_peek_children (w->window); | |
115 | |
116 /* Create the cursor unless already created. */ | |
117 if (! *cursor) | |
118 *cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
119 | |
120 gdk_window_set_cursor (w->window, *cursor); | |
121 | |
122 /* The scroll bar widget has more than one GDK window (had to look at | |
123 the source to figure this out), and there is no way to set cursor | |
124 on widgets in GTK. So we must set the cursor for all GDK windows. | |
125 Ditto for menus. */ | |
126 | |
127 for ( ; children; children = g_list_next (children)) | |
128 gdk_window_set_cursor (GDK_WINDOW (children->data), *cursor); | |
129 } | |
130 | |
131 /* Timer function called when a timeout occurs for xg_timer. | |
132 This function processes all GTK events in a recursive event loop. | |
133 This is done because GTK timer events are not seen by Emacs event | |
134 detection, Emacs only looks for X events. When a scroll bar has the | |
135 pointer (detected by button press/release events below) an Emacs | |
136 timer is started, and this function can then check if the GTK timer | |
137 has expired by calling the GTK event loop. | |
138 Also, when a menu is active, it has a small timeout before it | |
139 pops down the sub menu under it. */ | |
140 static void | |
141 xg_process_timeouts (timer) | |
142 struct atimer *timer; | |
143 { | |
144 BLOCK_INPUT; | |
145 /* Ideally we would like to just handle timer events, like the Xt version | |
146 of this does in xterm.c, but there is no such feature in GTK. */ | |
147 while (gtk_events_pending ()) | |
148 gtk_main_iteration (); | |
149 UNBLOCK_INPUT; | |
150 } | |
151 | |
152 /* Start the xg_timer with an interval of 0.1 seconds, if not already started. | |
153 xg_process_timeouts is called when the timer expires. The timer | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
154 started is continuous, i.e. runs until xg_stop_timer is called. */ |
49323 | 155 static void |
156 xg_start_timer () | |
157 { | |
158 if (! xg_timer) | |
159 { | |
160 EMACS_TIME interval; | |
161 EMACS_SET_SECS_USECS (interval, 0, 100000); | |
162 xg_timer = start_atimer (ATIMER_CONTINUOUS, | |
163 interval, | |
164 xg_process_timeouts, | |
165 0); | |
166 } | |
167 } | |
168 | |
169 /* Stop the xg_timer if started. */ | |
170 static void | |
171 xg_stop_timer () | |
172 { | |
173 if (xg_timer) | |
174 { | |
175 cancel_atimer (xg_timer); | |
176 xg_timer = 0; | |
177 } | |
178 } | |
179 | |
180 /* Insert NODE into linked LIST. */ | |
181 static void | |
182 xg_list_insert (xg_list_node *list, xg_list_node *node) | |
183 { | |
184 xg_list_node *list_start = list->next; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
185 |
49323 | 186 if (list_start) list_start->prev = node; |
187 node->next = list_start; | |
188 node->prev = 0; | |
189 list->next = node; | |
190 } | |
191 | |
192 /* Remove NODE from linked LIST. */ | |
193 static void | |
194 xg_list_remove (xg_list_node *list, xg_list_node *node) | |
195 { | |
196 xg_list_node *list_start = list->next; | |
197 if (node == list_start) | |
198 { | |
199 list->next = node->next; | |
200 if (list->next) list->next->prev = 0; | |
201 } | |
202 else | |
203 { | |
204 node->prev->next = node->next; | |
205 if (node->next) node->next->prev = node->prev; | |
206 } | |
207 } | |
208 | |
209 /* Allocate and return a utf8 version of STR. If STR is already | |
210 utf8 or NULL, just return STR. | |
211 If not, a new string is allocated and the caller must free the result | |
212 with g_free. */ | |
213 static char * | |
214 get_utf8_string (str) | |
215 char *str; | |
216 { | |
217 char *utf8_str = str; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
218 |
49323 | 219 /* If not UTF-8, try current locale. */ |
220 if (str && !g_utf8_validate (str, -1, NULL)) | |
221 utf8_str = g_locale_to_utf8 (str, -1, 0, 0, 0); | |
222 | |
223 return utf8_str; | |
224 } | |
225 | |
226 | |
227 | |
228 /*********************************************************************** | |
229 General functions for creating widgets, resizing, events, e.t.c. | |
230 ***********************************************************************/ | |
231 | |
232 /* Make a geometry string and pass that to GTK. It seems this is the | |
233 only way to get geometry position right if the user explicitly | |
234 asked for a position when starting Emacs. | |
235 F is the frame we shall set geometry for. */ | |
236 static void | |
237 xg_set_geometry (f) | |
238 FRAME_PTR f; | |
239 { | |
240 if (f->output_data.x->size_hint_flags & USPosition) | |
241 { | |
242 int left = f->output_data.x->left_pos; | |
243 int xneg = f->output_data.x->size_hint_flags & XNegative; | |
244 int top = f->output_data.x->top_pos; | |
245 int yneg = f->output_data.x->size_hint_flags & YNegative; | |
246 char geom_str[32]; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
247 |
49323 | 248 if (xneg) |
249 left = -left; | |
250 if (yneg) | |
251 top = -top; | |
252 | |
253 sprintf (geom_str, "=%dx%d%c%d%c%d", | |
254 PIXEL_WIDTH (f), | |
255 FRAME_TOTAL_PIXEL_HEIGHT (f), | |
256 (xneg ? '-' : '+'), left, | |
257 (yneg ? '-' : '+'), top); | |
258 | |
259 if (!gtk_window_parse_geometry (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
260 geom_str)) | |
261 fprintf (stderr, "Failed to parse: '%s'\n", geom_str); | |
262 } | |
263 } | |
264 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
265 |
49323 | 266 /* Resize the outer window of frame F after chainging the height. |
267 This happend when the menu bar or the tool bar is added or removed. | |
268 COLUMNS/ROWS is the size the edit area shall have after the resize. */ | |
269 static void | |
270 xg_resize_outer_widget (f, columns, rows) | |
271 FRAME_PTR f; | |
272 int columns; | |
273 int rows; | |
274 { | |
275 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
276 PIXEL_WIDTH (f), FRAME_TOTAL_PIXEL_HEIGHT (f)); | |
277 | |
278 /* base_height is now changed. */ | |
279 x_wm_set_size_hint (f, 0, 0); | |
280 | |
281 /* If we are not mapped yet, set geometry once again, as window | |
282 height now have changed. */ | |
283 if (! GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f))) | |
284 xg_set_geometry (f); | |
285 | |
286 xg_frame_set_char_size (f, columns, rows); | |
287 gdk_window_process_all_updates (); | |
288 } | |
289 | |
50130
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
290 /* This gets called after the frame F has been cleared. Since that is |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
291 done with X calls, we need to redraw GTK widget (scroll bars). */ |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
292 void |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
293 xg_frame_cleared (f) |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
294 FRAME_PTR f; |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
295 { |
50192
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
296 GtkWidget *w = f->output_data.x->widget; |
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
297 |
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
298 if (w) |
50130
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
299 { |
50192
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
300 gtk_container_set_reallocate_redraws (GTK_CONTAINER (w), TRUE); |
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
301 gtk_container_foreach (GTK_CONTAINER (w), |
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
302 (GtkCallback) gtk_widget_queue_draw, |
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
303 0); |
50130
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
304 gdk_window_process_all_updates (); |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
305 } |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
306 } |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
307 |
49323 | 308 /* Function to handle resize of our widgets. Since Emacs has some layouts |
309 that does not fit well with GTK standard containers, we do most layout | |
310 manually. | |
311 F is the frame to resize. | |
312 PIXELWIDTH, PIXELHEIGHT is the new size in pixels. */ | |
313 void | |
314 xg_resize_widgets (f, pixelwidth, pixelheight) | |
315 FRAME_PTR f; | |
316 int pixelwidth, pixelheight; | |
317 { | |
318 int mbheight = FRAME_MENUBAR_HEIGHT (f); | |
319 int tbheight = FRAME_TOOLBAR_HEIGHT (f); | |
320 int rows = PIXEL_TO_CHAR_HEIGHT (f, pixelheight - mbheight - tbheight); | |
321 int columns = PIXEL_TO_CHAR_WIDTH (f, pixelwidth); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
322 |
49323 | 323 if (FRAME_GTK_WIDGET (f) |
324 && (columns != FRAME_WIDTH (f) || rows != FRAME_HEIGHT (f) | |
325 || pixelwidth != PIXEL_WIDTH (f) || pixelheight != PIXEL_HEIGHT (f))) | |
326 { | |
327 struct x_output *x = f->output_data.x; | |
328 GtkAllocation all; | |
329 | |
330 all.y = mbheight + tbheight; | |
331 all.x = 0; | |
332 | |
333 all.width = pixelwidth; | |
334 all.height = pixelheight - mbheight - tbheight; | |
335 | |
336 gtk_widget_size_allocate (x->edit_widget, &all); | |
50129
d0142038feaa
Reduce flicker in GTK scrollbars.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50112
diff
changeset
|
337 |
50130
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
338 xg_frame_cleared (f); |
49323 | 339 |
340 change_frame_size (f, rows, columns, 0, 1, 0); | |
341 SET_FRAME_GARBAGED (f); | |
342 cancel_mouse_face (f); | |
343 } | |
344 } | |
345 | |
346 | |
347 /* Update our widget size to be COLS/ROWS characters for frame F. */ | |
348 void | |
349 xg_frame_set_char_size (f, cols, rows) | |
350 FRAME_PTR f; | |
351 int cols; | |
352 int rows; | |
353 { | |
354 int pixelheight = CHAR_TO_PIXEL_HEIGHT (f, rows) | |
355 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f); | |
356 int pixelwidth = CHAR_TO_PIXEL_WIDTH (f, cols); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
357 |
49323 | 358 /* Take into account the size of the scroll bar. Always use the |
359 number of columns occupied by the scroll bar here otherwise we | |
360 might end up with a frame width that is not a multiple of the | |
361 frame's character width which is bad for vertically split | |
362 windows. */ | |
363 f->output_data.x->vertical_scroll_bar_extra | |
364 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f) | |
365 ? 0 | |
366 : (FRAME_SCROLL_BAR_COLS (f) | |
367 * FONT_WIDTH (f->output_data.x->font))); | |
368 | |
50099
a62497b91c74
Use generic compute_fringe_widths.
Kim F. Storm <storm@cua.dk>
parents:
50063
diff
changeset
|
369 compute_fringe_widths (f, 0); |
49323 | 370 |
371 /* Must resize our top level widget. Font size may have changed, | |
372 but not rows/cols. */ | |
373 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
374 pixelwidth, pixelheight); | |
375 xg_resize_widgets (f, pixelwidth, pixelheight); | |
376 } | |
377 | |
378 /* Convert an X Window WSESC to its corresponding GtkWidget. | |
379 Must be done like this, because GtkWidget:s can have "hidden" | |
380 X Window that aren't accessible. | |
381 | |
382 Return 0 if no widget match WDESC. */ | |
383 GtkWidget * | |
384 xg_win_to_widget (wdesc) | |
385 Window wdesc; | |
386 { | |
387 gpointer gdkwin; | |
388 GtkWidget *gwdesc = 0; | |
389 | |
390 BLOCK_INPUT; | |
391 gdkwin = gdk_xid_table_lookup (wdesc); | |
392 if (gdkwin) | |
393 { | |
394 GdkEvent event; | |
395 event.any.window = gdkwin; | |
396 gwdesc = gtk_get_event_widget (&event); | |
397 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
398 |
49323 | 399 UNBLOCK_INPUT; |
400 return gwdesc; | |
401 } | |
402 | |
403 /* Fill in the GdkColor C so that it represents PIXEL. | |
404 W is the widget that color will be used for. Used to find colormap. */ | |
405 static void | |
406 xg_pix_to_gcolor (w, pixel, c) | |
407 GtkWidget *w; | |
408 unsigned long pixel; | |
409 GdkColor *c; | |
410 { | |
411 GdkColormap *map = gtk_widget_get_colormap (w); | |
412 gdk_colormap_query_color (map, pixel, c); | |
413 } | |
414 | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
415 /* Turning off double buffering for our GtkFixed widget has the side |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
416 effect of turning it off also for its children (scroll bars). |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
417 But we want those to be double buffered to not flicker so handle |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
418 expose manually here. |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
419 WIDGET is the GtkFixed widget that gets exposed. |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
420 EVENT is the expose event. |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
421 USER_DATA is unused. |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
422 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
423 Return TRUE to tell GTK that this expose event has been fully handeled |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
424 and that GTK shall do nothing more with it. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
425 static gboolean |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
426 xg_fixed_handle_expose(GtkWidget *widget, |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
427 GdkEventExpose *event, |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
428 gpointer user_data) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
429 { |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
430 GList *iter; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
431 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
432 for (iter = GTK_FIXED (widget)->children; iter; iter = g_list_next (iter)) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
433 { |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
434 GtkFixedChild *child_data = (GtkFixedChild *) iter->data; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
435 GtkWidget *child = child_data->widget; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
436 GdkWindow *window = child->window; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
437 GdkRegion *region = gtk_widget_region_intersect (child, event->region); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
438 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
439 if (! gdk_region_empty (region)) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
440 { |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
441 GdkEvent child_event; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
442 child_event.expose = *event; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
443 child_event.expose.region = region; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
444 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
445 /* Turn on double buffering, i.e. draw to an off screen area. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
446 gdk_window_begin_paint_region (window, region); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
447 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
448 /* Tell child to redraw itself. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
449 gdk_region_get_clipbox (region, &child_event.expose.area); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
450 gtk_widget_send_expose (child, &child_event); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
451 gdk_window_process_updates (window, TRUE); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
452 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
453 /* Copy off screen area to the window. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
454 gdk_window_end_paint (window); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
455 } |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
456 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
457 gdk_region_destroy (region); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
458 } |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
459 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
460 return TRUE; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
461 } |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
462 |
49323 | 463 /* Create and set up the GTK widgets for frame F. |
464 Return 0 if creation failed, non-zero otherwise. */ | |
465 int | |
466 xg_create_frame_widgets (f) | |
467 FRAME_PTR f; | |
468 { | |
469 GtkWidget *wtop; | |
470 GtkWidget *wvbox; | |
471 GtkWidget *wfixed; | |
472 GdkColor bg; | |
473 GtkRcStyle *style; | |
474 int i; | |
475 char *title = 0; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
476 |
49323 | 477 BLOCK_INPUT; |
478 | |
479 wtop = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
480 wvbox = gtk_vbox_new (FALSE, 0); | |
481 wfixed = gtk_fixed_new (); /* Must have this to place scroll bars */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
482 |
49323 | 483 if (! wtop || ! wvbox || ! wfixed) |
484 { | |
485 if (wtop) gtk_widget_destroy (wtop); | |
486 if (wvbox) gtk_widget_destroy (wvbox); | |
487 if (wfixed) gtk_widget_destroy (wfixed); | |
488 | |
489 return 0; | |
490 } | |
491 | |
492 /* Use same names as the Xt port does. I.e. Emacs.pane.emacs by default */ | |
493 gtk_widget_set_name (wtop, EMACS_CLASS); | |
494 gtk_widget_set_name (wvbox, "pane"); | |
495 gtk_widget_set_name (wfixed, SDATA (Vx_resource_name)); | |
496 | |
497 /* If this frame has a title or name, set it in the title bar. */ | |
498 if (! NILP (f->title)) title = SDATA (f->title); | |
499 else if (! NILP (f->name)) title = SDATA (f->name); | |
500 | |
501 if (title) gtk_window_set_title (GTK_WINDOW (wtop), title); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
502 |
49323 | 503 FRAME_GTK_OUTER_WIDGET (f) = wtop; |
504 FRAME_GTK_WIDGET (f) = wfixed; | |
505 f->output_data.x->vbox_widget = wvbox; | |
506 | |
507 gtk_fixed_set_has_window (GTK_FIXED (wfixed), TRUE); | |
508 | |
509 gtk_widget_set_size_request (wfixed, | |
510 PIXEL_WIDTH (f), | |
511 PIXEL_HEIGHT (f)); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
512 |
49323 | 513 gtk_container_add (GTK_CONTAINER (wtop), wvbox); |
514 gtk_box_pack_end (GTK_BOX (wvbox), wfixed, TRUE, TRUE, 0); | |
515 | |
516 if (FRAME_EXTERNAL_TOOL_BAR (f)) | |
517 update_frame_tool_bar (f); | |
518 | |
519 /* The tool bar is created but first there are no items in it. | |
520 This causes it to be zero height. Later items are added, but then | |
521 the frame is already mapped, so there is a "jumping" resize. | |
522 This makes geometry handling difficult, for example -0-0 will end | |
523 up in the wrong place as tool bar height has not been taken into account. | |
524 So we cheat a bit by setting a height that is what it will have | |
525 later on when tool bar items are added. */ | |
49325 | 526 if (FRAME_EXTERNAL_TOOL_BAR (f) && FRAME_TOOLBAR_HEIGHT (f) == 0) |
49323 | 527 FRAME_TOOLBAR_HEIGHT (f) = 34; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
528 |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
529 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
530 /* We don't want this widget double buffered, because we draw on it |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
531 with regular X drawing primitives, so from a GTK/GDK point of |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
532 view, the widget is totally blank. When an expose comes, this |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
533 will make the widget blank, and then Emacs redraws it. This flickers |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
534 a lot, so we turn off double buffering. */ |
49323 | 535 gtk_widget_set_double_buffered (wfixed, FALSE); |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
536 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
537 /* Turning off double buffering above has the side effect of turning |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
538 it off also for its children (scroll bars). But we want those |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
539 to be double buffered to not flicker so handle expose manually. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
540 g_signal_connect (G_OBJECT (wfixed), "expose-event", |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
541 G_CALLBACK (xg_fixed_handle_expose), 0); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
542 |
49323 | 543 /* GTK documents says use gtk_window_set_resizable. But then a user |
544 can't shrink the window from its starting size. */ | |
545 gtk_window_set_policy (GTK_WINDOW (wtop), TRUE, TRUE, TRUE); | |
546 gtk_window_set_wmclass (GTK_WINDOW (wtop), | |
547 SDATA (Vx_resource_name), | |
548 SDATA (Vx_resource_class)); | |
549 | |
550 /* Add callback to do nothing on WM_DELETE_WINDOW. The default in | |
551 GTK is to destroy the widget. We want Emacs to do that instead. */ | |
552 g_signal_connect (G_OBJECT (wtop), "delete-event", | |
553 G_CALLBACK (gtk_true), 0); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
554 |
49323 | 555 /* Convert our geometry parameters into a geometry string |
556 and specify it. | |
557 GTK will itself handle calculating the real position this way. */ | |
558 xg_set_geometry (f); | |
559 | |
560 gtk_widget_add_events (wfixed, | |
561 GDK_POINTER_MOTION_MASK | |
562 | GDK_EXPOSURE_MASK | |
563 | GDK_BUTTON_PRESS_MASK | |
564 | GDK_BUTTON_RELEASE_MASK | |
565 | GDK_KEY_PRESS_MASK | |
566 | GDK_ENTER_NOTIFY_MASK | |
567 | GDK_LEAVE_NOTIFY_MASK | |
568 | GDK_FOCUS_CHANGE_MASK | |
569 | GDK_STRUCTURE_MASK | |
570 | GDK_VISIBILITY_NOTIFY_MASK); | |
571 | |
572 /* Must realize the windows so the X window gets created. It is used | |
573 by callers of this function. */ | |
574 gtk_widget_realize (wfixed); | |
575 FRAME_X_WINDOW (f) = GTK_WIDGET_TO_X_WIN (wfixed); | |
576 | |
577 /* Since GTK clears its window by filling with the background color, | |
578 we must keep X and GTK background in sync. */ | |
579 xg_pix_to_gcolor (wfixed, f->output_data.x->background_pixel, &bg); | |
580 gtk_widget_modify_bg (wfixed, GTK_STATE_NORMAL, &bg); | |
581 | |
582 /* Also, do not let any background pixmap to be set, this looks very | |
583 bad as Emacs overwrites the background pixmap with its own idea | |
584 of background color. */ | |
585 style = gtk_widget_get_modifier_style (wfixed); | |
586 | |
587 /* Must use g_strdup because gtk_widget_modify_style does g_free. */ | |
588 style->bg_pixmap_name[GTK_STATE_NORMAL] = g_strdup ("<none>"); | |
589 gtk_widget_modify_style (wfixed, style); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
590 |
49323 | 591 /* GTK does not set any border, and they look bad with GTK. */ |
592 f->output_data.x->border_width = 0; | |
593 f->output_data.x->internal_border_width = 0; | |
594 | |
595 UNBLOCK_INPUT; | |
596 | |
597 return 1; | |
598 } | |
599 | |
600 /* Set the normal size hints for the window manager, for frame F. | |
601 FLAGS is the flags word to use--or 0 meaning preserve the flags | |
602 that the window now has. | |
603 If USER_POSITION is nonzero, we set the User Position | |
604 flag (this is useful when FLAGS is 0). */ | |
605 void | |
606 x_wm_set_size_hint (f, flags, user_position) | |
607 FRAME_PTR f; | |
608 long flags; | |
609 int user_position; | |
610 { | |
611 if (FRAME_GTK_OUTER_WIDGET (f)) | |
612 { | |
613 /* Must use GTK routines here, otherwise GTK resets the size hints | |
614 to its own defaults. */ | |
615 GdkGeometry size_hints; | |
616 gint hint_flags = 0; | |
617 int base_width, base_height; | |
618 int min_rows = 0, min_cols = 0; | |
619 int win_gravity = f->output_data.x->win_gravity; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
620 |
49323 | 621 if (flags) |
622 { | |
623 memset (&size_hints, 0, sizeof (size_hints)); | |
624 f->output_data.x->size_hints = size_hints; | |
625 f->output_data.x->hint_flags = hint_flags; | |
626 } | |
627 else | |
628 flags = f->output_data.x->size_hint_flags; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
629 |
49323 | 630 size_hints = f->output_data.x->size_hints; |
631 hint_flags = f->output_data.x->hint_flags; | |
632 | |
633 hint_flags |= GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE; | |
634 size_hints.width_inc = FONT_WIDTH (f->output_data.x->font); | |
635 size_hints.height_inc = f->output_data.x->line_height; | |
636 | |
637 hint_flags |= GDK_HINT_BASE_SIZE; | |
638 base_width = CHAR_TO_PIXEL_WIDTH (f, 0); | |
639 base_height = CHAR_TO_PIXEL_HEIGHT (f, 0) | |
640 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f); | |
641 | |
642 check_frame_size (f, &min_rows, &min_cols); | |
643 | |
644 size_hints.base_width = base_width; | |
645 size_hints.base_height = base_height; | |
646 size_hints.min_width = base_width + min_cols * size_hints.width_inc; | |
647 size_hints.min_height = base_height + min_rows * size_hints.height_inc; | |
648 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
649 |
49323 | 650 /* These currently have a one to one mapping with the X values, but I |
651 don't think we should rely on that. */ | |
652 hint_flags |= GDK_HINT_WIN_GRAVITY; | |
653 size_hints.win_gravity = 0; | |
654 if (win_gravity == NorthWestGravity) | |
655 size_hints.win_gravity = GDK_GRAVITY_NORTH_WEST; | |
656 else if (win_gravity == NorthGravity) | |
657 size_hints.win_gravity = GDK_GRAVITY_NORTH; | |
658 else if (win_gravity == NorthEastGravity) | |
659 size_hints.win_gravity = GDK_GRAVITY_NORTH_EAST; | |
660 else if (win_gravity == WestGravity) | |
661 size_hints.win_gravity = GDK_GRAVITY_WEST; | |
662 else if (win_gravity == CenterGravity) | |
663 size_hints.win_gravity = GDK_GRAVITY_CENTER; | |
664 else if (win_gravity == EastGravity) | |
665 size_hints.win_gravity = GDK_GRAVITY_EAST; | |
666 else if (win_gravity == SouthWestGravity) | |
667 size_hints.win_gravity = GDK_GRAVITY_SOUTH_WEST; | |
668 else if (win_gravity == SouthGravity) | |
669 size_hints.win_gravity = GDK_GRAVITY_SOUTH; | |
670 else if (win_gravity == SouthEastGravity) | |
671 size_hints.win_gravity = GDK_GRAVITY_SOUTH_EAST; | |
672 else if (win_gravity == StaticGravity) | |
673 size_hints.win_gravity = GDK_GRAVITY_STATIC; | |
674 | |
675 if (flags & PPosition) hint_flags |= GDK_HINT_POS; | |
676 if (flags & USPosition) hint_flags |= GDK_HINT_USER_POS; | |
677 if (flags & USSize) hint_flags |= GDK_HINT_USER_SIZE; | |
678 | |
679 if (user_position) | |
680 { | |
681 hint_flags &= ~GDK_HINT_POS; | |
682 hint_flags |= GDK_HINT_USER_POS; | |
683 } | |
684 | |
685 BLOCK_INPUT; | |
686 | |
687 gtk_window_set_geometry_hints (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
688 FRAME_GTK_OUTER_WIDGET (f), | |
689 &size_hints, | |
690 hint_flags); | |
691 | |
692 f->output_data.x->size_hints = size_hints; | |
693 f->output_data.x->hint_flags = hint_flags; | |
694 UNBLOCK_INPUT; | |
695 } | |
696 } | |
697 | |
698 /* Change background color of a frame. | |
699 Since GTK uses the background colour to clear the window, we must | |
700 keep the GTK and X colors in sync. | |
701 F is the frame to change, | |
702 BG is the pixel value to change to. */ | |
703 void | |
704 xg_set_background_color (f, bg) | |
705 FRAME_PTR f; | |
706 unsigned long bg; | |
707 { | |
708 if (FRAME_GTK_WIDGET (f)) | |
709 { | |
710 GdkColor gdk_bg; | |
711 | |
712 BLOCK_INPUT; | |
713 xg_pix_to_gcolor (FRAME_GTK_WIDGET (f), bg, &gdk_bg); | |
714 gtk_widget_modify_bg (FRAME_GTK_WIDGET (f), GTK_STATE_NORMAL, &gdk_bg); | |
715 UNBLOCK_INPUT; | |
716 } | |
717 } | |
718 | |
719 | |
720 | |
721 /*********************************************************************** | |
722 Dialog functions | |
723 ***********************************************************************/ | |
724 /* Return the dialog title to use for a dialog of type KEY. | |
725 This is the encoding used by lwlib. We use the same for GTK. */ | |
726 static char * | |
727 get_dialog_title (char key) | |
728 { | |
729 char *title = ""; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
730 |
49323 | 731 switch (key) { |
732 case 'E': case 'e': | |
733 title = "Error"; | |
734 break; | |
735 | |
736 case 'I': case 'i': | |
737 title = "Information"; | |
738 break; | |
739 | |
740 case 'L': case 'l': | |
741 title = "Prompt"; | |
742 break; | |
743 | |
744 case 'P': case 'p': | |
745 title = "Prompt"; | |
746 break; | |
747 | |
748 case 'Q': case 'q': | |
749 title = "Question"; | |
750 break; | |
751 } | |
752 | |
753 return title; | |
754 } | |
755 | |
756 /* Callback for dialogs that get WM_DELETE_WINDOW. We pop down | |
757 the dialog, but return TRUE so the event does not propagate further | |
758 in GTK. This prevents GTK from destroying the dialog widget automatically | |
759 and we can always destrou the widget manually, regardles of how | |
760 it was popped down (button press or WM_DELETE_WINDOW). | |
761 W is the dialog widget. | |
762 EVENT is the GdkEvent that represents WM_DELETE_WINDOW (not used). | |
763 user_data is NULL (not used). | |
764 | |
765 Returns TRUE to end propagation of event. */ | |
766 static gboolean | |
767 dialog_delete_callback (w, event, user_data) | |
768 GtkWidget *w; | |
769 GdkEvent *event; | |
770 gpointer user_data; | |
771 { | |
772 gtk_widget_unmap (w); | |
773 return TRUE; | |
774 } | |
775 | |
776 /* Create a popup dialog window. See also xg_create_widget below. | |
777 WV is a widget_value describing the dialog. | |
778 SELECT_CB is the callback to use when a button has been pressed. | |
779 DEACTIVATE_CB is the callback to use when the dialog pops down. | |
780 | |
781 Returns the GTK dialog widget. */ | |
782 static GtkWidget * | |
783 create_dialog (wv, select_cb, deactivate_cb) | |
784 widget_value *wv; | |
785 GCallback select_cb; | |
786 GCallback deactivate_cb; | |
787 { | |
788 char *title = get_dialog_title (wv->name[0]); | |
789 int total_buttons = wv->name[1] - '0'; | |
790 int right_buttons = wv->name[4] - '0'; | |
791 int left_buttons; | |
792 int button_nr = 0; | |
793 int button_spacing = 10; | |
794 GtkWidget *wdialog = gtk_dialog_new (); | |
795 widget_value *item; | |
796 GtkBox *cur_box; | |
797 GtkWidget *wvbox; | |
798 GtkWidget *whbox_up; | |
799 GtkWidget *whbox_down; | |
800 | |
801 /* If the number of buttons is greater than 4, make two rows of buttons | |
802 instead. This looks better. */ | |
803 int make_two_rows = total_buttons > 4; | |
804 | |
805 if (right_buttons == 0) right_buttons = total_buttons/2; | |
806 left_buttons = total_buttons - right_buttons; | |
807 | |
808 gtk_window_set_title (GTK_WINDOW (wdialog), title); | |
809 gtk_widget_set_name (wdialog, "emacs-dialog"); | |
810 | |
811 cur_box = GTK_BOX (GTK_DIALOG (wdialog)->action_area); | |
812 | |
813 if (make_two_rows) | |
814 { | |
815 wvbox = gtk_vbox_new (TRUE, button_spacing); | |
816 whbox_up = gtk_hbox_new (FALSE, 0); | |
817 whbox_down = gtk_hbox_new (FALSE, 0); | |
818 | |
819 gtk_box_pack_start (cur_box, wvbox, FALSE, FALSE, 0); | |
820 gtk_box_pack_start (GTK_BOX (wvbox), whbox_up, FALSE, FALSE, 0); | |
821 gtk_box_pack_start (GTK_BOX (wvbox), whbox_down, FALSE, FALSE, 0); | |
822 | |
823 cur_box = GTK_BOX (whbox_up); | |
824 } | |
825 | |
826 g_signal_connect (G_OBJECT (wdialog), "delete-event", | |
827 G_CALLBACK (dialog_delete_callback), 0); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
828 |
49323 | 829 if (deactivate_cb) |
830 { | |
831 g_signal_connect (G_OBJECT (wdialog), "close", deactivate_cb, 0); | |
832 g_signal_connect (G_OBJECT (wdialog), "response", deactivate_cb, 0); | |
833 } | |
834 | |
835 for (item = wv->contents; item; item = item->next) | |
836 { | |
837 char *utf8_label = get_utf8_string (item->value); | |
838 GtkWidget *w; | |
839 GtkRequisition req; | |
840 | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
841 if (item->name && strcmp (item->name, "message") == 0) |
49323 | 842 { |
843 /* This is the text part of the dialog. */ | |
844 w = gtk_label_new (utf8_label); | |
845 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (wdialog)->vbox), | |
846 gtk_label_new (""), | |
847 FALSE, FALSE, 0); | |
848 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (wdialog)->vbox), w, | |
849 TRUE, TRUE, 0); | |
850 gtk_misc_set_alignment (GTK_MISC (w), 0.1, 0.5); | |
851 | |
852 /* Try to make dialog look better. Must realize first so | |
853 the widget can calculate the size it needs. */ | |
854 gtk_widget_realize (w); | |
855 gtk_widget_size_request (w, &req); | |
856 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (wdialog)->vbox), | |
857 req.height); | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
858 if (item->value && strlen (item->value) > 0) |
49323 | 859 button_spacing = 2*req.width/strlen (item->value); |
860 } | |
861 else | |
862 { | |
863 /* This is one button to add to the dialog. */ | |
864 w = gtk_button_new_with_mnemonic (utf8_label); | |
865 if (! item->enabled) | |
866 gtk_widget_set_sensitive (w, FALSE); | |
867 if (select_cb) | |
868 g_signal_connect (G_OBJECT (w), "clicked", | |
869 select_cb, item->call_data); | |
870 | |
871 gtk_box_pack_start (cur_box, w, TRUE, TRUE, button_spacing); | |
872 if (++button_nr == left_buttons) | |
873 { | |
874 if (make_two_rows) | |
875 cur_box = GTK_BOX (whbox_down); | |
876 else | |
877 gtk_box_pack_start (cur_box, | |
878 gtk_label_new (""), | |
879 TRUE, TRUE, | |
880 button_spacing); | |
881 } | |
882 } | |
883 | |
884 if (utf8_label && utf8_label != item->value) | |
885 g_free (utf8_label); | |
886 } | |
887 | |
888 return wdialog; | |
889 } | |
890 | |
891 | |
892 enum | |
893 { | |
894 XG_FILE_NOT_DONE, | |
895 XG_FILE_OK, | |
896 XG_FILE_CANCEL, | |
897 XG_FILE_DESTROYED, | |
898 }; | |
899 | |
900 /* Callback function invoked when the Ok button is pressed in | |
901 a file dialog. | |
902 W is the file dialog widget, | |
903 ARG points to an integer where we record what has happend. */ | |
904 static void | |
905 xg_file_sel_ok (w, arg) | |
906 GtkWidget *w; | |
907 gpointer arg; | |
908 { | |
909 *(int*)arg = XG_FILE_OK; | |
910 } | |
911 | |
912 /* Callback function invoked when the Cancel button is pressed in | |
913 a file dialog. | |
914 W is the file dialog widget, | |
915 ARG points to an integer where we record what has happend. */ | |
916 static void | |
917 xg_file_sel_cancel (w, arg) | |
918 GtkWidget *w; | |
919 gpointer arg; | |
920 { | |
921 *(int*)arg = XG_FILE_CANCEL; | |
922 } | |
923 | |
924 /* Callback function invoked when the file dialog is destroyed (i.e. | |
925 popped down). We must keep track of this, because if this | |
926 happens, GTK destroys the widget. But if for example, Ok is pressed, | |
927 the dialog is popped down, but the dialog widget is not destroyed. | |
928 W is the file dialog widget, | |
929 ARG points to an integer where we record what has happend. */ | |
930 static void | |
931 xg_file_sel_destroy (w, arg) | |
932 GtkWidget *w; | |
933 gpointer arg; | |
934 { | |
935 *(int*)arg = XG_FILE_DESTROYED; | |
936 } | |
937 | |
938 /* Read a file name from the user using a file dialog. | |
939 F is the current frame. | |
940 PROMPT is a prompt to show to the user. May not be NULL. | |
941 DEFAULT_FILENAME is a default selection to be displayed. May be NULL. | |
942 If MUSTMATCH_P is non-zero, the returned file name must be an existing | |
943 file. | |
944 | |
945 Returns a file name or NULL if no file was selected. | |
946 The returned string must be freed by the caller. */ | |
947 char * | |
948 xg_get_file_name (f, prompt, default_filename, mustmatch_p) | |
949 FRAME_PTR f; | |
950 char *prompt; | |
951 char *default_filename; | |
952 int mustmatch_p; | |
953 { | |
954 GtkWidget *filewin; | |
955 GtkFileSelection *filesel; | |
956 int filesel_done = XG_FILE_NOT_DONE; | |
957 char *fn = 0; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
958 |
49323 | 959 filewin = gtk_file_selection_new (prompt); |
960 filesel = GTK_FILE_SELECTION (filewin); | |
961 | |
962 gtk_widget_set_name (filewin, "emacs-filedialog"); | |
963 | |
964 gtk_window_set_transient_for (GTK_WINDOW (filewin), | |
965 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); | |
966 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE); | |
967 | |
968 g_signal_connect (G_OBJECT (filesel->ok_button), | |
969 "clicked", | |
970 G_CALLBACK (xg_file_sel_ok), | |
971 &filesel_done); | |
972 g_signal_connect (G_OBJECT (filesel->cancel_button), | |
973 "clicked", | |
974 G_CALLBACK (xg_file_sel_cancel), | |
975 &filesel_done); | |
976 g_signal_connect (G_OBJECT (filesel), | |
977 "destroy", | |
978 G_CALLBACK (xg_file_sel_destroy), | |
979 &filesel_done); | |
980 | |
981 if (default_filename) | |
982 gtk_file_selection_set_filename (filesel, default_filename); | |
983 | |
984 if (mustmatch_p) | |
985 { | |
986 /* The selection_entry part of filesel is not documented. */ | |
987 gtk_widget_set_sensitive (filesel->selection_entry, FALSE); | |
988 gtk_file_selection_hide_fileop_buttons (filesel); | |
989 } | |
990 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
991 |
49323 | 992 gtk_widget_show_all (filewin); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
993 |
49323 | 994 while (filesel_done == XG_FILE_NOT_DONE) |
995 gtk_main_iteration (); | |
996 | |
997 if (filesel_done == XG_FILE_OK) | |
998 fn = xstrdup ((char*) gtk_file_selection_get_filename (filesel)); | |
999 | |
1000 if (filesel_done != XG_FILE_DESTROYED) | |
1001 gtk_widget_destroy (filewin); | |
1002 | |
1003 return fn; | |
1004 } | |
1005 | |
1006 | |
1007 /*********************************************************************** | |
1008 Menu functions. | |
1009 ***********************************************************************/ | |
1010 | |
1011 /* The name of menu items that can be used for citomization. Since GTK | |
1012 RC files are very crude and primitive, we have to set this on all | |
1013 menu item names so a user can easily cutomize menu items. */ | |
1014 | |
1015 #define MENU_ITEM_NAME "emacs-menuitem" | |
1016 | |
1017 | |
1018 /* Linked list of all allocated struct xg_menu_cb_data. Used for marking | |
1019 during GC. The next member points to the items. */ | |
1020 static xg_list_node xg_menu_cb_list; | |
1021 | |
1022 /* Linked list of all allocated struct xg_menu_item_cb_data. Used for marking | |
1023 during GC. The next member points to the items. */ | |
1024 static xg_list_node xg_menu_item_cb_list; | |
1025 | |
1026 /* Allocate and initialize CL_DATA if NULL, otherwise increase ref_count. | |
1027 F is the frame CL_DATA will be initialized for. | |
1028 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1029 | |
1030 The menu bar and all sub menus under the menu bar in a frame | |
1031 share the same structure, hence the reference count. | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1032 |
49323 | 1033 Returns CL_DATA if CL_DATA is not NULL, or a pointer to a newly |
1034 allocated xg_menu_cb_data if CL_DATA is NULL. */ | |
1035 static xg_menu_cb_data * | |
1036 make_cl_data (cl_data, f, highlight_cb) | |
1037 xg_menu_cb_data *cl_data; | |
1038 FRAME_PTR f; | |
1039 GCallback highlight_cb; | |
1040 { | |
1041 if (! cl_data) | |
1042 { | |
1043 cl_data = (xg_menu_cb_data*) xmalloc (sizeof (*cl_data)); | |
1044 cl_data->f = f; | |
1045 cl_data->menu_bar_vector = f->menu_bar_vector; | |
1046 cl_data->menu_bar_items_used = f->menu_bar_items_used; | |
1047 cl_data->highlight_cb = highlight_cb; | |
1048 cl_data->ref_count = 0; | |
1049 | |
1050 xg_list_insert (&xg_menu_cb_list, &cl_data->ptrs); | |
1051 } | |
1052 | |
1053 cl_data->ref_count++; | |
1054 | |
1055 return cl_data; | |
1056 } | |
1057 | |
1058 /* Update CL_DATA with values from frame F and with HIGHLIGHT_CB. | |
1059 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1060 | |
1061 When the menu bar is updated, menu items may have been added and/or | |
1062 removed, so menu_bar_vector and menu_bar_items_used change. We must | |
1063 then update CL_DATA since it is used to determine which menu | |
1064 item that is invoked in the menu. | |
1065 HIGHLIGHT_CB could change, there is no check that the same | |
1066 function is given when modifying a menu bar as was given when | |
1067 creating the menu bar. */ | |
1068 static void | |
1069 update_cl_data (cl_data, f, highlight_cb) | |
1070 xg_menu_cb_data *cl_data; | |
1071 FRAME_PTR f; | |
1072 GCallback highlight_cb; | |
1073 { | |
1074 if (cl_data) | |
1075 { | |
1076 cl_data->f = f; | |
1077 cl_data->menu_bar_vector = f->menu_bar_vector; | |
1078 cl_data->menu_bar_items_used = f->menu_bar_items_used; | |
1079 cl_data->highlight_cb = highlight_cb; | |
1080 } | |
1081 } | |
1082 | |
1083 /* Decrease reference count for CL_DATA. | |
1084 If reference count is zero, free CL_DATA. */ | |
1085 static void | |
1086 unref_cl_data (cl_data) | |
1087 xg_menu_cb_data *cl_data; | |
1088 { | |
1089 if (cl_data && cl_data->ref_count > 0) | |
1090 { | |
1091 cl_data->ref_count--; | |
1092 if (cl_data->ref_count == 0) | |
1093 { | |
1094 xg_list_remove (&xg_menu_cb_list, &cl_data->ptrs); | |
1095 xfree (cl_data); | |
1096 } | |
1097 } | |
1098 } | |
1099 | |
1100 /* Function that marks all lisp data during GC. */ | |
1101 void | |
1102 xg_mark_data () | |
1103 { | |
1104 xg_list_node *iter; | |
1105 | |
1106 for (iter = xg_menu_cb_list.next; iter; iter = iter->next) | |
1107 mark_object (&((xg_menu_cb_data *) iter)->menu_bar_vector); | |
1108 | |
1109 for (iter = xg_menu_item_cb_list.next; iter; iter = iter->next) | |
1110 { | |
1111 xg_menu_item_cb_data *cb_data = (xg_menu_item_cb_data *) iter; | |
1112 | |
1113 if (! NILP (cb_data->help)) | |
1114 mark_object (&cb_data->help); | |
1115 } | |
1116 } | |
1117 | |
1118 | |
1119 /* Callback called when a menu item is destroyed. Used to free data. | |
1120 W is the widget that is being destroyed (not used). | |
1121 CLIENT_DATA points to the xg_menu_item_cb_data associated with the W. */ | |
1122 static void | |
1123 menuitem_destroy_callback (w, client_data) | |
1124 GtkWidget *w; | |
1125 gpointer client_data; | |
1126 { | |
1127 if (client_data) | |
1128 { | |
1129 xg_menu_item_cb_data *data = (xg_menu_item_cb_data*) client_data; | |
1130 xg_list_remove (&xg_menu_item_cb_list, &data->ptrs); | |
1131 xfree (data); | |
1132 } | |
1133 } | |
1134 | |
1135 /* Callback called when the pointer enters/leaves a menu item. | |
1136 W is the menu item. | |
1137 EVENT is either an enter event or leave event. | |
1138 CLIENT_DATA points to the xg_menu_item_cb_data associated with the W. | |
1139 | |
1140 Returns FALSE to tell GTK to keep processing this event. */ | |
1141 static gboolean | |
1142 menuitem_highlight_callback (w, event, client_data) | |
1143 GtkWidget *w; | |
1144 GdkEventCrossing *event; | |
1145 gpointer client_data; | |
1146 { | |
1147 if (client_data) | |
1148 { | |
1149 xg_menu_item_cb_data *data = (xg_menu_item_cb_data*) client_data; | |
1150 gpointer call_data = event->type == GDK_LEAVE_NOTIFY ? 0 : client_data; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1151 |
49323 | 1152 if (! NILP (data->help) && data->cl_data->highlight_cb) |
1153 { | |
1154 GtkCallback func = (GtkCallback) data->cl_data->highlight_cb; | |
1155 (*func) (w, call_data); | |
1156 } | |
1157 } | |
1158 | |
1159 return FALSE; | |
1160 } | |
1161 | |
1162 /* Callback called when a menu is destroyed. Used to free data. | |
1163 W is the widget that is being destroyed (not used). | |
1164 CLIENT_DATA points to the xg_menu_cb_data associated with W. */ | |
1165 static void | |
1166 menu_destroy_callback (w, client_data) | |
1167 GtkWidget *w; | |
1168 gpointer client_data; | |
1169 { | |
1170 unref_cl_data ((xg_menu_cb_data*) client_data); | |
1171 } | |
1172 | |
1173 /* Callback called when a menu does a grab or ungrab. That means the | |
1174 menu has been activated or deactivated. | |
1175 Used to start a timer so the small timeout the menus in GTK uses before | |
1176 popping down a menu is seen by Emacs (see xg_process_timeouts above). | |
1177 W is the widget that does the grab (not used). | |
1178 UNGRAB_P is TRUE if this is an ungrab, FALSE if it is a grab. | |
1179 CLIENT_DATA is NULL (not used). */ | |
1180 static void | |
1181 menu_grab_callback (GtkWidget *widget, | |
1182 gboolean ungrab_p, | |
1183 gpointer client_data) | |
1184 { | |
1185 /* Keep track of total number of grabs. */ | |
1186 static int cnt; | |
1187 | |
1188 if (ungrab_p) cnt--; | |
1189 else cnt++; | |
1190 | |
1191 if (cnt > 0 && ! xg_timer) xg_start_timer (); | |
1192 else if (cnt == 0 && xg_timer) xg_stop_timer (); | |
1193 } | |
1194 | |
1195 /* Make a GTK widget that contains both UTF8_LABEL and UTF8_KEY (both | |
1196 must be non-NULL) and can be inserted into a menu item. | |
1197 | |
1198 Returns the GtkHBox. */ | |
1199 static GtkWidget * | |
1200 make_widget_for_menu_item (utf8_label, utf8_key) | |
1201 char *utf8_label; | |
1202 char *utf8_key; | |
1203 { | |
1204 GtkWidget *wlbl; | |
1205 GtkWidget *wkey; | |
1206 GtkWidget *wbox; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1207 |
49323 | 1208 wbox = gtk_hbox_new (FALSE, 0); |
1209 wlbl = gtk_label_new_with_mnemonic (utf8_label); | |
1210 wkey = gtk_label_new (utf8_key); | |
1211 | |
1212 gtk_misc_set_alignment (GTK_MISC (wlbl), 0.0, 0.5); | |
1213 gtk_misc_set_alignment (GTK_MISC (wkey), 0.0, 0.5); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1214 |
49323 | 1215 gtk_box_pack_start (GTK_BOX (wbox), wlbl, TRUE, TRUE, 0); |
1216 gtk_box_pack_start (GTK_BOX (wbox), wkey, FALSE, FALSE, 0); | |
1217 | |
1218 gtk_widget_set_name (wlbl, MENU_ITEM_NAME); | |
1219 gtk_widget_set_name (wkey, MENU_ITEM_NAME); | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
1220 gtk_widget_set_name (wbox, MENU_ITEM_NAME); |
49323 | 1221 |
1222 return wbox; | |
1223 } | |
1224 | |
1225 /* Make and return a menu item widget with the key to the right. | |
1226 UTF8_LABEL is the text for the menu item (GTK uses UTF8 internally). | |
1227 UTF8_KEY is the text representing the key binding. | |
1228 ITEM is the widget_value describing the menu item. | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1229 |
49323 | 1230 GROUP is an in/out parameter. If the menu item to be created is not |
1231 part of any radio menu group, *GROUP contains NULL on entry and exit. | |
1232 If the menu item to be created is part of a radio menu group, on entry | |
1233 *GROUP contains the group to use, or NULL if this is the first item | |
1234 in the group. On exit, *GROUP contains the radio item group. | |
1235 | |
1236 Unfortunately, keys don't line up as nicely as in Motif, | |
1237 but the MacOS X version doesn't either, so I guess that is OK. */ | |
1238 static GtkWidget * | |
1239 make_menu_item (utf8_label, utf8_key, item, group) | |
1240 char *utf8_label; | |
1241 char *utf8_key; | |
1242 widget_value *item; | |
1243 GSList **group; | |
1244 { | |
1245 GtkWidget *w; | |
1246 GtkWidget *wtoadd = 0; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1247 |
49323 | 1248 if (utf8_key) |
1249 wtoadd = make_widget_for_menu_item (utf8_label, utf8_key); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1250 |
49323 | 1251 if (item->button_type == BUTTON_TYPE_TOGGLE) |
1252 { | |
1253 *group = NULL; | |
1254 if (utf8_key) w = gtk_check_menu_item_new (); | |
1255 else w = gtk_check_menu_item_new_with_mnemonic (utf8_label); | |
1256 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), item->selected); | |
1257 } | |
1258 else if (item->button_type == BUTTON_TYPE_RADIO) | |
1259 { | |
1260 if (utf8_key) w = gtk_radio_menu_item_new (*group); | |
1261 else w = gtk_radio_menu_item_new_with_mnemonic (*group, utf8_label); | |
1262 *group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (w)); | |
1263 if (item->selected) | |
1264 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), TRUE); | |
1265 } | |
1266 else | |
1267 { | |
1268 *group = NULL; | |
1269 if (utf8_key) w = gtk_menu_item_new (); | |
1270 else w = gtk_menu_item_new_with_mnemonic (utf8_label); | |
1271 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1272 |
49323 | 1273 if (wtoadd) gtk_container_add (GTK_CONTAINER (w), wtoadd); |
1274 if (! item->enabled) gtk_widget_set_sensitive (w, FALSE); | |
1275 | |
1276 return w; | |
1277 } | |
1278 | |
1279 /* Return non-zero if NAME specifies a separator (GTK only has one | |
1280 separator type) */ | |
1281 static int | |
1282 xg_separator_p (char *name) | |
1283 { | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1284 if (! name) return 0; |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1285 |
49323 | 1286 return strcmp (name, "--") == 0 |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1287 || strncmp (name, "--:", 3) == 0 |
49323 | 1288 || strcmp (name, "---") == 0; |
1289 } | |
1290 | |
1291 GtkWidget *xg_did_tearoff; | |
1292 | |
1293 /* Callback invoked when a detached menu window is removed. Here we | |
1294 delete the popup menu. | |
1295 WIDGET is the top level window that is removed (the parent of the menu). | |
1296 EVENT is the event that triggers the window removal. | |
1297 CLIENT_DATA points to the menu that is detached. | |
1298 | |
1299 Returns TRUE to tell GTK to stop processing this event. */ | |
1300 static gboolean | |
1301 tearoff_remove (widget, event, client_data) | |
1302 GtkWidget *widget; | |
1303 GdkEvent *event; | |
1304 gpointer client_data; | |
1305 { | |
1306 gtk_widget_destroy (GTK_WIDGET (client_data)); | |
1307 return TRUE; | |
1308 } | |
1309 | |
1310 /* Callback invoked when a menu is detached. It sets the xg_did_tearoff | |
1311 variable. | |
1312 WIDGET is the GtkTearoffMenuItem. | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1313 CLIENT_DATA is not used. */ |
49323 | 1314 static void |
1315 tearoff_activate (widget, client_data) | |
1316 GtkWidget *widget; | |
1317 gpointer client_data; | |
1318 { | |
1319 GtkWidget *menu = gtk_widget_get_parent (widget); | |
1320 if (! gtk_menu_get_tearoff_state (GTK_MENU (menu))) | |
1321 return; | |
1322 | |
1323 xg_did_tearoff = menu; | |
1324 } | |
1325 | |
1326 /* If a detach of a popup menu is done, this function should be called | |
1327 to keep the menu around until the detached window is removed. | |
1328 MENU is the top level menu for the popup, | |
1329 SUBMENU is the menu that got detached (that is MENU or a | |
1330 submenu of MENU), see the xg_did_tearoff variable. */ | |
1331 void | |
1332 xg_keep_popup (menu, submenu) | |
1333 GtkWidget *menu; | |
1334 GtkWidget *submenu; | |
1335 { | |
1336 GtkWidget *p; | |
1337 | |
1338 /* Find the top widget for the detached menu. */ | |
1339 p = gtk_widget_get_toplevel (submenu); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1340 |
49323 | 1341 /* Delay destroying the menu until the detached menu is removed. */ |
1342 g_signal_connect (G_OBJECT (p), "unmap_event", | |
1343 G_CALLBACK (tearoff_remove), menu); | |
1344 } | |
1345 | |
1346 int xg_debug = 0; | |
1347 | |
1348 /* Create a menu item widget, and connect the callbacks. | |
1349 ITEM decribes the menu item. | |
1350 F is the frame the created menu belongs to. | |
1351 SELECT_CB is the callback to use when a menu item is selected. | |
1352 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1353 CL_DATA points to the callback data to be used for this menu. | |
1354 GROUP is an in/out parameter. If the menu item to be created is not | |
1355 part of any radio menu group, *GROUP contains NULL on entry and exit. | |
1356 If the menu item to be created is part of a radio menu group, on entry | |
1357 *GROUP contains the group to use, or NULL if this is the first item | |
1358 in the group. On exit, *GROUP contains the radio item group. | |
1359 | |
1360 Returns the created GtkWidget. */ | |
1361 static GtkWidget * | |
1362 xg_create_one_menuitem (item, f, select_cb, highlight_cb, cl_data, group) | |
1363 widget_value *item; | |
1364 FRAME_PTR f; | |
1365 GCallback select_cb; | |
1366 GCallback highlight_cb; | |
1367 xg_menu_cb_data *cl_data; | |
1368 GSList **group; | |
1369 { | |
1370 char *utf8_label; | |
1371 char *utf8_key; | |
1372 GtkWidget *w; | |
1373 xg_menu_item_cb_data *cb_data; | |
1374 | |
1375 utf8_label = get_utf8_string (item->name); | |
1376 utf8_key = get_utf8_string (item->key); | |
1377 | |
1378 w = make_menu_item (utf8_label, utf8_key, item, group); | |
1379 | |
1380 if (utf8_label && utf8_label != item->name) g_free (utf8_label); | |
1381 if (utf8_key && utf8_key != item->key) g_free (utf8_key); | |
1382 | |
1383 cb_data = xmalloc (sizeof (xg_menu_item_cb_data)); | |
1384 | |
1385 xg_list_insert (&xg_menu_item_cb_list, &cb_data->ptrs); | |
1386 | |
1387 cb_data->unhighlight_id = cb_data->highlight_id = cb_data->select_id = 0; | |
1388 cb_data->help = item->help; | |
1389 cb_data->cl_data = cl_data; | |
1390 cb_data->call_data = item->call_data; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1391 |
49323 | 1392 g_signal_connect (G_OBJECT (w), |
1393 "destroy", | |
1394 G_CALLBACK (menuitem_destroy_callback), | |
1395 cb_data); | |
1396 | |
1397 /* Put cb_data in widget, so we can get at it when modifying menubar */ | |
1398 g_object_set_data (G_OBJECT (w), XG_ITEM_DATA, cb_data); | |
1399 | |
1400 /* final item, not a submenu */ | |
1401 if (item->call_data && ! item->contents) | |
1402 { | |
1403 if (select_cb) | |
1404 cb_data->select_id | |
1405 = g_signal_connect (G_OBJECT (w), "activate", select_cb, cb_data); | |
1406 } | |
1407 | |
1408 if (! NILP (item->help) && highlight_cb) | |
1409 { | |
1410 /* We use enter/leave notify instead of select/deselect because | |
1411 select/deselect doesn't go well with detached menus. */ | |
1412 cb_data->highlight_id | |
1413 = g_signal_connect (G_OBJECT (w), | |
1414 "enter-notify-event", | |
1415 G_CALLBACK (menuitem_highlight_callback), | |
1416 cb_data); | |
1417 cb_data->unhighlight_id | |
1418 = g_signal_connect (G_OBJECT (w), | |
1419 "leave-notify-event", | |
1420 G_CALLBACK (menuitem_highlight_callback), | |
1421 cb_data); | |
1422 } | |
1423 | |
1424 return w; | |
1425 } | |
1426 | |
50112
50df9e41f1a3
Add prototype for create_menus.
Andreas Schwab <schwab@suse.de>
parents:
50108
diff
changeset
|
1427 static GtkWidget *create_menus P_ ((widget_value *, FRAME_PTR, GCallback, |
50df9e41f1a3
Add prototype for create_menus.
Andreas Schwab <schwab@suse.de>
parents:
50108
diff
changeset
|
1428 GCallback, GCallback, int, int, int, |
50df9e41f1a3
Add prototype for create_menus.
Andreas Schwab <schwab@suse.de>
parents:
50108
diff
changeset
|
1429 GtkWidget *, xg_menu_cb_data *, char *)); |
50df9e41f1a3
Add prototype for create_menus.
Andreas Schwab <schwab@suse.de>
parents:
50108
diff
changeset
|
1430 |
49323 | 1431 /* Create a full menu tree specified by DATA. |
1432 F is the frame the created menu belongs to. | |
1433 SELECT_CB is the callback to use when a menu item is selected. | |
1434 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore. | |
1435 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1436 POP_UP_P is non-zero if we shall create a popup menu. | |
1437 MENU_BAR_P is non-zero if we shall create a menu bar. | |
1438 ADD_TEAROFF_P is non-zero if we shall add a teroff menu item. Ignored | |
1439 if MENU_BAR_P is non-zero. | |
1440 TOPMENU is the topmost GtkWidget that others shall be placed under. | |
1441 It may be NULL, in that case we create the appropriate widget | |
1442 (menu bar or menu item depending on POP_UP_P and MENU_BAR_P) | |
1443 CL_DATA is the callback data we shall use for this menu, or NULL | |
1444 if we haven't set the first callback yet. | |
1445 NAME is the name to give to the top level menu if this function | |
1446 creates it. May be NULL to not set any name. | |
1447 | |
1448 Returns the top level GtkWidget. This is TOPLEVEL if TOPLEVEL is | |
1449 not NULL. | |
1450 | |
1451 This function calls itself to create submenus. */ | |
1452 | |
1453 static GtkWidget * | |
1454 create_menus (data, f, select_cb, deactivate_cb, highlight_cb, | |
1455 pop_up_p, menu_bar_p, add_tearoff_p, topmenu, cl_data, name) | |
1456 widget_value *data; | |
1457 FRAME_PTR f; | |
1458 GCallback select_cb; | |
1459 GCallback deactivate_cb; | |
1460 GCallback highlight_cb; | |
1461 int pop_up_p; | |
1462 int menu_bar_p; | |
1463 int add_tearoff_p; | |
1464 GtkWidget *topmenu; | |
1465 xg_menu_cb_data *cl_data; | |
1466 char *name; | |
1467 { | |
1468 widget_value *item; | |
1469 GtkWidget *wmenu = topmenu; | |
1470 GSList *group = NULL; | |
1471 | |
1472 if (! topmenu) | |
1473 { | |
1474 if (! menu_bar_p) wmenu = gtk_menu_new (); | |
1475 else wmenu = gtk_menu_bar_new (); | |
1476 | |
1477 /* Put cl_data on the top menu for easier access. */ | |
1478 cl_data = make_cl_data (cl_data, f, highlight_cb); | |
1479 g_object_set_data (G_OBJECT (wmenu), XG_FRAME_DATA, (gpointer)cl_data); | |
1480 g_signal_connect (G_OBJECT (wmenu), "destroy", | |
1481 G_CALLBACK (menu_destroy_callback), cl_data); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1482 |
49323 | 1483 if (name) |
1484 gtk_widget_set_name (wmenu, name); | |
1485 | |
1486 if (deactivate_cb) | |
1487 g_signal_connect (G_OBJECT (wmenu), | |
1488 "deactivate", deactivate_cb, 0); | |
1489 | |
1490 g_signal_connect (G_OBJECT (wmenu), | |
1491 "grab-notify", G_CALLBACK (menu_grab_callback), 0); | |
1492 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1493 |
49323 | 1494 if (! menu_bar_p && add_tearoff_p) |
1495 { | |
1496 GtkWidget *tearoff = gtk_tearoff_menu_item_new (); | |
1497 gtk_menu_shell_append (GTK_MENU_SHELL (wmenu), tearoff); | |
1498 | |
1499 g_signal_connect (G_OBJECT (tearoff), "activate", | |
1500 G_CALLBACK (tearoff_activate), 0); | |
1501 } | |
1502 | |
1503 for (item = data; item; item = item->next) | |
1504 { | |
1505 GtkWidget *w; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1506 |
49323 | 1507 if (pop_up_p && !item->contents && !item->call_data |
1508 && !xg_separator_p (item->name)) | |
1509 { | |
1510 char *utf8_label; | |
1511 /* A title for a popup. We do the same as GTK does when | |
1512 creating titles, but it does not look good. */ | |
1513 group = NULL; | |
1514 utf8_label = get_utf8_string (item->name); | |
1515 | |
1516 gtk_menu_set_title (GTK_MENU (wmenu), utf8_label); | |
1517 w = gtk_menu_item_new_with_mnemonic (utf8_label); | |
1518 gtk_widget_set_sensitive (w, FALSE); | |
1519 if (utf8_label && utf8_label != item->name) g_free (utf8_label); | |
1520 } | |
1521 else if (xg_separator_p (item->name)) | |
1522 { | |
1523 group = NULL; | |
1524 /* GTK only have one separator type. */ | |
1525 w = gtk_separator_menu_item_new (); | |
1526 } | |
1527 else | |
1528 { | |
1529 w = xg_create_one_menuitem (item, | |
1530 f, | |
1531 item->contents ? 0 : select_cb, | |
1532 highlight_cb, | |
1533 cl_data, | |
1534 &group); | |
1535 | |
1536 if (item->contents) | |
1537 { | |
1538 GtkWidget *submenu = create_menus (item->contents, | |
1539 f, | |
1540 select_cb, | |
1541 deactivate_cb, | |
1542 highlight_cb, | |
1543 0, | |
1544 0, | |
1545 1, | |
1546 0, | |
1547 cl_data, | |
1548 0); | |
1549 gtk_menu_item_set_submenu (GTK_MENU_ITEM (w), submenu); | |
1550 } | |
1551 } | |
1552 | |
1553 gtk_menu_shell_append (GTK_MENU_SHELL (wmenu), w); | |
1554 gtk_widget_set_name (w, MENU_ITEM_NAME); | |
1555 } | |
1556 | |
1557 return wmenu; | |
1558 } | |
1559 | |
1560 /* Create a menubar, popup menu or dialog, depending on the TYPE argument. | |
1561 TYPE can be "menubar", "popup" for popup menu, or "dialog" for a dialog | |
1562 with some text and buttons. | |
1563 F is the frame the created item belongs to. | |
1564 NAME is the name to use for the top widget. | |
1565 VAL is a widget_value structure describing items to be created. | |
1566 SELECT_CB is the callback to use when a menu item is selected or | |
1567 a dialog button is pressed. | |
1568 DEACTIVATE_CB is the callback to use when an item is deactivated. | |
1569 For a menu, when a sub menu is not shown anymore, for a dialog it is | |
1570 called when the dialog is popped down. | |
1571 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1572 | |
1573 Returns the widget created. */ | |
1574 GtkWidget * | |
1575 xg_create_widget (type, name, f, val, | |
1576 select_cb, deactivate_cb, highlight_cb) | |
1577 char *type; | |
1578 char *name; | |
1579 FRAME_PTR f; | |
1580 widget_value *val; | |
1581 GCallback select_cb; | |
1582 GCallback deactivate_cb; | |
1583 GCallback highlight_cb; | |
1584 { | |
1585 GtkWidget *w = 0; | |
1586 if (strcmp (type, "dialog") == 0) | |
1587 { | |
1588 w = create_dialog (val, select_cb, deactivate_cb); | |
1589 gtk_window_set_transient_for (GTK_WINDOW (w), | |
1590 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); | |
1591 gtk_window_set_destroy_with_parent (GTK_WINDOW (w), TRUE); | |
1592 | |
1593 if (w) | |
1594 gtk_widget_set_name (w, "emacs-dialog"); | |
1595 } | |
1596 else if (strcmp (type, "menubar") == 0 || strcmp (type, "popup") == 0) | |
1597 { | |
1598 w = create_menus (val->contents, | |
1599 f, | |
1600 select_cb, | |
1601 deactivate_cb, | |
1602 highlight_cb, | |
1603 strcmp (type, "popup") == 0, | |
1604 strcmp (type, "menubar") == 0, | |
1605 1, | |
1606 0, | |
1607 0, | |
1608 name); | |
1609 | |
1610 /* Set the cursor to an arrow for popup menus when they are mapped. | |
1611 This is done by default for menu bar menus. */ | |
1612 if (strcmp (type, "popup") == 0) | |
1613 { | |
1614 /* Must realize so the GdkWindow inside the widget is created. */ | |
1615 gtk_widget_realize (w); | |
1616 xg_set_cursor (w, &xg_left_ptr_cursor); | |
1617 } | |
1618 } | |
1619 else | |
1620 { | |
1621 fprintf (stderr, "bad type in xg_create_widget: %s, doing nothing\n", | |
1622 type); | |
1623 } | |
1624 | |
1625 return w; | |
1626 } | |
1627 | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1628 /* Return the label for menu item WITEM. */ |
49323 | 1629 static const char * |
1630 xg_get_menu_item_label (witem) | |
1631 GtkMenuItem *witem; | |
1632 { | |
1633 GtkLabel *wlabel = GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem))); | |
1634 return gtk_label_get_label (wlabel); | |
1635 } | |
1636 | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1637 /* Return non-zero if the menu item WITEM has the text LABEL. */ |
49323 | 1638 static int |
1639 xg_item_label_same_p (witem, label) | |
1640 GtkMenuItem *witem; | |
1641 char *label; | |
1642 { | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1643 int is_same = 0; |
49323 | 1644 char *utf8_label = get_utf8_string (label); |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1645 const char *old_label = witem ? xg_get_menu_item_label (witem) : 0; |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1646 |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1647 if (! old_label && ! utf8_label) |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1648 is_same = 1; |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1649 else if (old_label && utf8_label) |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1650 is_same = strcmp (utf8_label, old_label) == 0; |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1651 |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1652 if (utf8_label && utf8_label != label) g_free (utf8_label); |
49323 | 1653 |
1654 return is_same; | |
1655 } | |
1656 | |
1657 /* Remove widgets in LIST from container WCONT. */ | |
1658 static void | |
1659 remove_from_container (wcont, list) | |
1660 GtkWidget *wcont; | |
1661 GList *list; | |
1662 { | |
1663 GList *iter; | |
1664 | |
49572 | 1665 for (iter = list; iter; iter = g_list_next (iter)) |
49323 | 1666 { |
1667 GtkWidget *w = GTK_WIDGET (iter->data); | |
1668 | |
1669 /* Add a ref to w so we can explicitly destroy it later. */ | |
1670 gtk_widget_ref (w); | |
1671 gtk_container_remove (GTK_CONTAINER (wcont), w); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1672 |
49323 | 1673 /* If there is a menu under this widget that has been detached, |
1674 there is a reference to it, and just removing w from the | |
1675 container does not destroy the submenu. By explicitly | |
1676 destroying w we make sure the submenu is destroyed, thus | |
1677 removing the detached window also if there was one. */ | |
1678 gtk_widget_destroy (w); | |
1679 } | |
1680 } | |
1681 | |
1682 /* Update the top level names in MENUBAR (i.e. not submenus). | |
1683 F is the frame the menu bar belongs to. | |
49572 | 1684 *LIST is a list with the current menu bar names (menu item widgets). |
1685 ITER is the item within *LIST that shall be updated. | |
1686 POS is the numerical position, starting at 0, of ITER in *LIST. | |
49323 | 1687 VAL describes what the menu bar shall look like after the update. |
1688 SELECT_CB is the callback to use when a menu item is selected. | |
1689 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
49572 | 1690 CL_DATA points to the callback data to be used for this menu bar. |
49323 | 1691 |
1692 This function calls itself to walk through the menu bar names. */ | |
1693 static void | |
49572 | 1694 xg_update_menubar (menubar, f, list, iter, pos, val, |
1695 select_cb, highlight_cb, cl_data) | |
49323 | 1696 GtkWidget *menubar; |
1697 FRAME_PTR f; | |
49572 | 1698 GList **list; |
1699 GList *iter; | |
1700 int pos; | |
49323 | 1701 widget_value *val; |
1702 GCallback select_cb; | |
1703 GCallback highlight_cb; | |
1704 xg_menu_cb_data *cl_data; | |
1705 { | |
49572 | 1706 if (! iter && ! val) |
49323 | 1707 return; |
49572 | 1708 else if (iter && ! val) |
49323 | 1709 { |
49572 | 1710 /* Item(s) have been removed. Remove all remaining items. */ |
1711 remove_from_container (menubar, iter); | |
49323 | 1712 |
1713 /* All updated. */ | |
1714 val = 0; | |
49572 | 1715 iter = 0; |
49323 | 1716 } |
49572 | 1717 else if (! iter && val) |
49323 | 1718 { |
1719 /* Item(s) added. Add all new items in one call. */ | |
1720 create_menus (val, f, select_cb, 0, highlight_cb, | |
1721 0, 1, 0, menubar, cl_data, 0); | |
1722 | |
1723 /* All updated. */ | |
1724 val = 0; | |
49572 | 1725 iter = 0; |
49323 | 1726 } |
49572 | 1727 /* Below this neither iter or val is NULL */ |
1728 else if (xg_item_label_same_p (GTK_MENU_ITEM (iter->data), val->name)) | |
49323 | 1729 { |
1730 /* This item is still the same, check next item. */ | |
1731 val = val->next; | |
49572 | 1732 iter = g_list_next (iter); |
1733 ++pos; | |
49323 | 1734 } |
1735 else /* This item is changed. */ | |
1736 { | |
49572 | 1737 GtkMenuItem *witem = GTK_MENU_ITEM (iter->data); |
49323 | 1738 GtkMenuItem *witem2 = 0; |
1739 int val_in_menubar = 0; | |
49572 | 1740 int iter_in_new_menubar = 0; |
1741 GList *iter2; | |
49323 | 1742 widget_value *cur; |
1743 | |
1744 /* See if the changed entry (val) is present later in the menu bar */ | |
49572 | 1745 for (iter2 = iter; |
1746 iter2 && ! val_in_menubar; | |
1747 iter2 = g_list_next (iter2)) | |
49323 | 1748 { |
49572 | 1749 witem2 = GTK_MENU_ITEM (iter2->data); |
49323 | 1750 val_in_menubar = xg_item_label_same_p (witem2, val->name); |
1751 } | |
1752 | |
49572 | 1753 /* See if the current entry (iter) is present later in the |
49323 | 1754 specification for the new menu bar. */ |
49572 | 1755 for (cur = val; cur && ! iter_in_new_menubar; cur = cur->next) |
1756 iter_in_new_menubar = xg_item_label_same_p (witem, cur->name); | |
1757 | |
1758 if (val_in_menubar && ! iter_in_new_menubar) | |
49323 | 1759 { |
49572 | 1760 int nr = pos; |
1761 | |
49323 | 1762 /* This corresponds to: |
1763 Current: A B C | |
1764 New: A C | |
1765 Remove B. */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1766 |
49323 | 1767 gtk_widget_ref (GTK_WIDGET (witem)); |
1768 gtk_container_remove (GTK_CONTAINER (menubar), GTK_WIDGET (witem)); | |
1769 gtk_widget_destroy (GTK_WIDGET (witem)); | |
1770 | |
1771 /* Must get new list since the old changed. */ | |
49572 | 1772 g_list_free (*list); |
1773 *list = iter = gtk_container_get_children (GTK_CONTAINER (menubar)); | |
1774 while (nr-- > 0) iter = g_list_next (iter); | |
49323 | 1775 } |
49572 | 1776 else if (! val_in_menubar && ! iter_in_new_menubar) |
49323 | 1777 { |
1778 /* This corresponds to: | |
1779 Current: A B C | |
1780 New: A X C | |
1781 Rename B to X. This might seem to be a strange thing to do, | |
1782 since if there is a menu under B it will be totally wrong for X. | |
1783 But consider editing a C file. Then there is a C-mode menu | |
1784 (corresponds to B above). | |
1785 If then doing C-x C-f the minibuf menu (X above) replaces the | |
1786 C-mode menu. When returning from the minibuffer, we get | |
1787 back the C-mode menu. Thus we do: | |
1788 Rename B to X (C-mode to minibuf menu) | |
1789 Rename X to B (minibuf to C-mode menu). | |
1790 If the X menu hasn't been invoked, the menu under B | |
1791 is up to date when leaving the minibuffer. */ | |
1792 GtkLabel *wlabel = GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem))); | |
1793 char *utf8_label = get_utf8_string (val->name); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1794 |
49323 | 1795 gtk_label_set_text_with_mnemonic (wlabel, utf8_label); |
1796 | |
49572 | 1797 iter = g_list_next (iter); |
49323 | 1798 val = val->next; |
49572 | 1799 ++pos; |
49323 | 1800 } |
49572 | 1801 else if (! val_in_menubar && iter_in_new_menubar) |
49323 | 1802 { |
1803 /* This corresponds to: | |
1804 Current: A B C | |
1805 New: A X B C | |
1806 Insert X. */ | |
1807 | |
49572 | 1808 int nr = pos; |
49323 | 1809 GList *group = 0; |
1810 GtkWidget *w = xg_create_one_menuitem (val, | |
1811 f, | |
1812 select_cb, | |
1813 highlight_cb, | |
1814 cl_data, | |
1815 &group); | |
1816 | |
1817 gtk_widget_set_name (w, MENU_ITEM_NAME); | |
1818 gtk_menu_shell_insert (GTK_MENU_SHELL (menubar), w, pos); | |
1819 | |
49572 | 1820 g_list_free (*list); |
1821 *list = iter = gtk_container_get_children (GTK_CONTAINER (menubar)); | |
1822 while (nr-- > 0) iter = g_list_next (iter); | |
1823 iter = g_list_next (iter); | |
49323 | 1824 val = val->next; |
49572 | 1825 ++pos; |
49323 | 1826 } |
49572 | 1827 else /* if (val_in_menubar && iter_in_new_menubar) */ |
49323 | 1828 { |
49572 | 1829 int nr = pos; |
49323 | 1830 /* This corresponds to: |
1831 Current: A B C | |
1832 New: A C B | |
1833 Move C before B */ | |
1834 | |
1835 gtk_widget_ref (GTK_WIDGET (witem2)); | |
1836 gtk_container_remove (GTK_CONTAINER (menubar), GTK_WIDGET (witem2)); | |
1837 gtk_menu_shell_insert (GTK_MENU_SHELL (menubar), | |
1838 GTK_WIDGET (witem2), pos); | |
1839 gtk_widget_unref (GTK_WIDGET (witem2)); | |
1840 | |
49572 | 1841 g_list_free (*list); |
1842 *list = iter = gtk_container_get_children (GTK_CONTAINER (menubar)); | |
1843 while (nr-- > 0) iter = g_list_next (iter); | |
49323 | 1844 val = val->next; |
49572 | 1845 ++pos; |
49323 | 1846 } |
1847 } | |
1848 | |
1849 /* Update the rest of the menu bar. */ | |
49572 | 1850 xg_update_menubar (menubar, f, list, iter, pos, val, |
1851 select_cb, highlight_cb, cl_data); | |
49323 | 1852 } |
1853 | |
1854 /* Update the menu item W so it corresponds to VAL. | |
1855 SELECT_CB is the callback to use when a menu item is selected. | |
1856 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1857 CL_DATA is the data to set in the widget for menu invokation. */ | |
1858 static void | |
1859 xg_update_menu_item (val, w, select_cb, highlight_cb, cl_data) | |
1860 widget_value *val; | |
1861 GtkWidget *w; | |
1862 GCallback select_cb; | |
1863 GCallback highlight_cb; | |
1864 xg_menu_cb_data *cl_data; | |
1865 { | |
1866 GtkWidget *wchild; | |
1867 GtkLabel *wlbl = 0; | |
1868 GtkLabel *wkey = 0; | |
1869 char *utf8_label; | |
1870 char *utf8_key; | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1871 const char *old_label = 0; |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1872 const char *old_key = 0; |
49323 | 1873 xg_menu_item_cb_data *cb_data; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1874 |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1875 wchild = gtk_bin_get_child (GTK_BIN (w)); |
49323 | 1876 utf8_label = get_utf8_string (val->name); |
1877 utf8_key = get_utf8_string (val->key); | |
1878 | |
1879 /* See if W is a menu item with a key. See make_menu_item above. */ | |
1880 if (GTK_IS_HBOX (wchild)) | |
1881 { | |
1882 GList *list = gtk_container_get_children (GTK_CONTAINER (wchild)); | |
1883 | |
1884 wlbl = GTK_LABEL (list->data); | |
1885 wkey = GTK_LABEL (list->next->data); | |
49572 | 1886 g_list_free (list); |
1887 | |
49323 | 1888 if (! utf8_key) |
1889 { | |
1890 /* Remove the key and keep just the label. */ | |
1891 gtk_widget_ref (GTK_WIDGET (wlbl)); | |
1892 gtk_container_remove (GTK_CONTAINER (w), wchild); | |
1893 gtk_container_add (GTK_CONTAINER (w), GTK_WIDGET (wlbl)); | |
1894 wkey = 0; | |
1895 } | |
49572 | 1896 |
49323 | 1897 } |
1898 else /* Just a label. */ | |
1899 { | |
1900 wlbl = GTK_LABEL (wchild); | |
1901 | |
1902 /* Check if there is now a key. */ | |
1903 if (utf8_key) | |
1904 { | |
1905 GtkWidget *wtoadd = make_widget_for_menu_item (utf8_label, utf8_key); | |
1906 GList *list = gtk_container_get_children (GTK_CONTAINER (wtoadd)); | |
49572 | 1907 |
49323 | 1908 wlbl = GTK_LABEL (list->data); |
1909 wkey = GTK_LABEL (list->next->data); | |
49572 | 1910 g_list_free (list); |
49323 | 1911 |
1912 gtk_container_remove (GTK_CONTAINER (w), wchild); | |
1913 gtk_container_add (GTK_CONTAINER (w), wtoadd); | |
1914 } | |
1915 } | |
1916 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1917 |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1918 if (wkey) old_key = gtk_label_get_label (wkey); |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1919 if (wlbl) old_label = gtk_label_get_label (wlbl); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1920 |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1921 if (wkey && utf8_key && (! old_key || strcmp (utf8_key, old_key) != 0)) |
49323 | 1922 gtk_label_set_text (wkey, utf8_key); |
1923 | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1924 if (! old_label || strcmp (utf8_label, old_label) != 0) |
49323 | 1925 gtk_label_set_text_with_mnemonic (wlbl, utf8_label); |
1926 | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1927 if (utf8_key && utf8_key != val->key) g_free (utf8_key); |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1928 if (utf8_label && utf8_label != val->name) g_free (utf8_label); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1929 |
49323 | 1930 if (! val->enabled && GTK_WIDGET_SENSITIVE (w)) |
1931 gtk_widget_set_sensitive (w, FALSE); | |
1932 else if (val->enabled && ! GTK_WIDGET_SENSITIVE (w)) | |
1933 gtk_widget_set_sensitive (w, TRUE); | |
1934 | |
1935 cb_data = (xg_menu_item_cb_data*) g_object_get_data (G_OBJECT (w), | |
1936 XG_ITEM_DATA); | |
1937 if (cb_data) | |
1938 { | |
1939 cb_data->call_data = val->call_data; | |
1940 cb_data->help = val->help; | |
1941 cb_data->cl_data = cl_data; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1942 |
49323 | 1943 /* We assume the callback functions don't change. */ |
1944 if (val->call_data && ! val->contents) | |
1945 { | |
1946 /* This item shall have a select callback. */ | |
1947 if (! cb_data->select_id) | |
1948 cb_data->select_id | |
1949 = g_signal_connect (G_OBJECT (w), "activate", | |
1950 select_cb, cb_data); | |
1951 } | |
1952 else if (cb_data->select_id) | |
1953 { | |
1954 g_signal_handler_disconnect (w, cb_data->select_id); | |
1955 cb_data->select_id = 0; | |
1956 } | |
1957 | |
1958 if (NILP (cb_data->help)) | |
1959 { | |
1960 /* Shall not have help. Remove if any existed previously. */ | |
1961 if (cb_data->highlight_id) | |
1962 { | |
1963 g_signal_handler_disconnect (G_OBJECT (w), | |
1964 cb_data->highlight_id); | |
1965 cb_data->highlight_id = 0; | |
1966 } | |
1967 if (cb_data->unhighlight_id) | |
1968 { | |
1969 g_signal_handler_disconnect (G_OBJECT (w), | |
1970 cb_data->unhighlight_id); | |
1971 cb_data->unhighlight_id = 0; | |
1972 } | |
1973 } | |
1974 else if (! cb_data->highlight_id && highlight_cb) | |
1975 { | |
1976 /* Have help now, but didn't previously. Add callback. */ | |
1977 cb_data->highlight_id | |
1978 = g_signal_connect (G_OBJECT (w), | |
1979 "enter-notify-event", | |
1980 G_CALLBACK (menuitem_highlight_callback), | |
1981 cb_data); | |
1982 cb_data->unhighlight_id | |
1983 = g_signal_connect (G_OBJECT (w), | |
1984 "leave-notify-event", | |
1985 G_CALLBACK (menuitem_highlight_callback), | |
1986 cb_data); | |
1987 } | |
1988 } | |
1989 } | |
1990 | |
1991 /* Update the toggle menu item W so it corresponds to VAL. */ | |
1992 static void | |
1993 xg_update_toggle_item (val, w) | |
1994 widget_value *val; | |
1995 GtkWidget *w; | |
1996 { | |
1997 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), val->selected); | |
1998 } | |
1999 | |
2000 /* Update the radio menu item W so it corresponds to VAL. */ | |
2001 static void | |
2002 xg_update_radio_item (val, w) | |
2003 widget_value *val; | |
2004 GtkWidget *w; | |
2005 { | |
2006 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), val->selected); | |
2007 } | |
2008 | |
2009 /* Update the sub menu SUBMENU and all its children so it corresponds to VAL. | |
2010 SUBMENU may be NULL, in that case a new menu is created. | |
2011 F is the frame the menu bar belongs to. | |
2012 VAL describes the contents of the menu bar. | |
2013 SELECT_CB is the callback to use when a menu item is selected. | |
2014 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore. | |
2015 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
2016 CL_DATA is the call back data to use for any newly created items. | |
2017 | |
2018 Returns the updated submenu widget, that is SUBMENU unless SUBMENU | |
2019 was NULL. */ | |
2020 | |
2021 static GtkWidget * | |
2022 xg_update_submenu (submenu, f, val, | |
2023 select_cb, deactivate_cb, highlight_cb, cl_data) | |
2024 GtkWidget *submenu; | |
2025 FRAME_PTR f; | |
2026 widget_value *val; | |
2027 GCallback select_cb; | |
2028 GCallback deactivate_cb; | |
2029 GCallback highlight_cb; | |
2030 xg_menu_cb_data *cl_data; | |
2031 { | |
2032 GtkWidget *newsub = submenu; | |
2033 GList *list = 0; | |
2034 GList *iter; | |
2035 widget_value *cur; | |
2036 int has_tearoff_p = 0; | |
2037 GList *first_radio = 0; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2038 |
49323 | 2039 if (submenu) |
2040 list = gtk_container_get_children (GTK_CONTAINER (submenu)); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2041 |
49323 | 2042 for (cur = val, iter = list; |
2043 cur && iter; | |
2044 iter = g_list_next (iter), cur = cur->next) | |
2045 { | |
2046 GtkWidget *w = GTK_WIDGET (iter->data); | |
2047 | |
2048 /* Skip tearoff items, they have no counterpart in val. */ | |
2049 if (GTK_IS_TEAROFF_MENU_ITEM (w)) | |
2050 { | |
2051 has_tearoff_p = 1; | |
2052 iter = g_list_next (iter); | |
2053 if (iter) w = GTK_WIDGET (iter->data); | |
2054 else break; | |
2055 } | |
2056 | |
2057 /* Remember first radio button in a group. If we get a mismatch in | |
2058 a radio group we must rebuild the whole group so that the connections | |
2059 in GTK becomes correct. */ | |
2060 if (cur->button_type == BUTTON_TYPE_RADIO && ! first_radio) | |
2061 first_radio = iter; | |
2062 else if (cur->button_type != BUTTON_TYPE_RADIO | |
2063 && ! GTK_IS_RADIO_MENU_ITEM (w)) | |
2064 first_radio = 0; | |
2065 | |
2066 if (GTK_IS_SEPARATOR_MENU_ITEM (w)) | |
2067 { | |
2068 if (! xg_separator_p (cur->name)) | |
2069 break; | |
2070 } | |
2071 else if (GTK_IS_CHECK_MENU_ITEM (w)) | |
2072 { | |
2073 if (cur->button_type != BUTTON_TYPE_TOGGLE) | |
2074 break; | |
2075 xg_update_toggle_item (cur, w); | |
2076 xg_update_menu_item (cur, w, select_cb, highlight_cb, cl_data); | |
2077 } | |
2078 else if (GTK_IS_RADIO_MENU_ITEM (w)) | |
2079 { | |
2080 if (cur->button_type != BUTTON_TYPE_RADIO) | |
2081 break; | |
2082 xg_update_radio_item (cur, w); | |
2083 xg_update_menu_item (cur, w, select_cb, highlight_cb, cl_data); | |
2084 } | |
2085 else if (GTK_IS_MENU_ITEM (w)) | |
2086 { | |
2087 GtkMenuItem *witem = GTK_MENU_ITEM (w); | |
2088 GtkWidget *sub; | |
2089 | |
2090 if (cur->button_type != BUTTON_TYPE_NONE || | |
2091 xg_separator_p (cur->name)) | |
2092 break; | |
2093 | |
2094 xg_update_menu_item (cur, w, select_cb, highlight_cb, cl_data); | |
2095 | |
2096 sub = gtk_menu_item_get_submenu (witem); | |
2097 if (sub && ! cur->contents) | |
2098 { | |
2099 /* Not a submenu anymore. */ | |
2100 gtk_widget_ref (sub); | |
2101 gtk_menu_item_remove_submenu (witem); | |
2102 gtk_widget_destroy (sub); | |
2103 } | |
2104 else if (cur->contents) | |
2105 { | |
2106 GtkWidget *nsub; | |
2107 | |
2108 nsub = xg_update_submenu (sub, f, cur->contents, | |
2109 select_cb, deactivate_cb, | |
2110 highlight_cb, cl_data); | |
2111 | |
2112 /* If this item just became a submenu, we must set it. */ | |
2113 if (nsub != sub) | |
2114 gtk_menu_item_set_submenu (witem, nsub); | |
2115 } | |
2116 } | |
2117 else | |
2118 { | |
2119 /* Structural difference. Remove everything from here and down | |
2120 in SUBMENU. */ | |
2121 break; | |
2122 } | |
2123 } | |
2124 | |
2125 /* Remove widgets from first structual change. */ | |
2126 if (iter) | |
2127 { | |
2128 /* If we are adding new menu items below, we must remove from | |
2129 first radio button so that radio groups become correct. */ | |
2130 if (cur && first_radio) remove_from_container (submenu, first_radio); | |
2131 else remove_from_container (submenu, iter); | |
2132 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2133 |
49323 | 2134 if (cur) |
2135 { | |
2136 /* More items added. Create them. */ | |
2137 newsub = create_menus (cur, | |
2138 f, | |
2139 select_cb, | |
2140 deactivate_cb, | |
2141 highlight_cb, | |
2142 0, | |
2143 0, | |
2144 ! has_tearoff_p, | |
2145 submenu, | |
2146 cl_data, | |
2147 0); | |
2148 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2149 |
49572 | 2150 if (list) g_list_free (list); |
2151 | |
49323 | 2152 return newsub; |
2153 } | |
2154 | |
2155 /* Update the MENUBAR. | |
2156 F is the frame the menu bar belongs to. | |
2157 VAL describes the contents of the menu bar. | |
2158 If DEEP_P is non-zero, rebuild all but the top level menu names in | |
2159 the MENUBAR. If DEEP_P is zero, just rebuild the names in the menubar. | |
2160 SELECT_CB is the callback to use when a menu item is selected. | |
2161 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore. | |
2162 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. */ | |
2163 void | |
2164 xg_modify_menubar_widgets (menubar, f, val, deep_p, | |
2165 select_cb, deactivate_cb, highlight_cb) | |
2166 GtkWidget *menubar; | |
2167 FRAME_PTR f; | |
2168 widget_value *val; | |
2169 int deep_p; | |
2170 GCallback select_cb; | |
2171 GCallback deactivate_cb; | |
2172 GCallback highlight_cb; | |
2173 { | |
2174 xg_menu_cb_data *cl_data; | |
2175 GList *list = gtk_container_get_children (GTK_CONTAINER (menubar)); | |
2176 | |
2177 if (! list) return; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2178 |
49323 | 2179 cl_data = (xg_menu_cb_data*) g_object_get_data (G_OBJECT (menubar), |
2180 XG_FRAME_DATA); | |
2181 | |
2182 if (! deep_p) | |
2183 { | |
2184 widget_value *cur = val->contents; | |
49572 | 2185 xg_update_menubar (menubar, f, &list, list, 0, cur, |
49323 | 2186 select_cb, highlight_cb, cl_data); |
2187 } | |
2188 else | |
2189 { | |
2190 widget_value *cur; | |
2191 | |
2192 /* Update all sub menus. | |
2193 We must keep the submenu names (GTK menu item widgets) since the | |
2194 X Window in the XEvent that activates the menu are those widgets. */ | |
2195 | |
2196 /* Update cl_data, menu_item things in F may have changed. */ | |
2197 update_cl_data (cl_data, f, highlight_cb); | |
2198 | |
2199 for (cur = val->contents; cur; cur = cur->next) | |
2200 { | |
49572 | 2201 GList *iter; |
49323 | 2202 GtkWidget *sub = 0; |
2203 GtkWidget *newsub; | |
2204 GtkMenuItem *witem; | |
2205 | |
2206 /* Find sub menu that corresponds to val and update it. */ | |
2207 for (iter = list ; iter; iter = g_list_next (iter)) | |
2208 { | |
2209 witem = GTK_MENU_ITEM (iter->data); | |
2210 if (xg_item_label_same_p (witem, cur->name)) | |
2211 { | |
2212 sub = gtk_menu_item_get_submenu (witem); | |
2213 break; | |
2214 } | |
2215 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2216 |
49323 | 2217 newsub = xg_update_submenu (sub, |
2218 f, | |
2219 cur->contents, | |
2220 select_cb, | |
2221 deactivate_cb, | |
2222 highlight_cb, | |
2223 cl_data); | |
2224 /* sub may still be NULL. If we just updated non deep and added | |
2225 a new menu bar item, it has no sub menu yet. So we set the | |
2226 newly created sub menu under witem. */ | |
2227 if (newsub != sub) | |
2228 gtk_menu_item_set_submenu (witem, newsub); | |
2229 | |
2230 } | |
2231 } | |
2232 | |
49572 | 2233 g_list_free (list); |
49323 | 2234 gtk_widget_show_all (menubar); |
2235 } | |
2236 | |
2237 /* Recompute all the widgets of frame F, when the menu bar has been | |
2238 changed. Value is non-zero if widgets were updated. */ | |
2239 | |
2240 int | |
2241 xg_update_frame_menubar (f) | |
2242 FRAME_PTR f; | |
2243 { | |
2244 struct x_output *x = f->output_data.x; | |
2245 GtkRequisition req; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2246 |
49323 | 2247 if (!x->menubar_widget || GTK_WIDGET_MAPPED (x->menubar_widget)) |
2248 return 0; | |
2249 | |
2250 BLOCK_INPUT; | |
2251 | |
2252 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->menubar_widget, | |
2253 FALSE, FALSE, 0); | |
2254 gtk_box_reorder_child (GTK_BOX (x->vbox_widget), x->menubar_widget, 0); | |
2255 | |
2256 gtk_widget_show_all (x->menubar_widget); | |
2257 gtk_widget_size_request (x->menubar_widget, &req); | |
2258 | |
2259 FRAME_MENUBAR_HEIGHT (f) = req.height; | |
2260 | |
2261 /* The height has changed, resize outer widget and set columns | |
2262 rows to what we had before adding the menu bar. */ | |
2263 xg_resize_outer_widget (f, FRAME_WIDTH (f), FRAME_HEIGHT (f)); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2264 |
49323 | 2265 SET_FRAME_GARBAGED (f); |
2266 UNBLOCK_INPUT; | |
50106
5675d6a0080c
(xg_update_frame_menubar): Add missing return value.
Andreas Schwab <schwab@suse.de>
parents:
50099
diff
changeset
|
2267 |
5675d6a0080c
(xg_update_frame_menubar): Add missing return value.
Andreas Schwab <schwab@suse.de>
parents:
50099
diff
changeset
|
2268 return 1; |
49323 | 2269 } |
2270 | |
2271 /* Get rid of the menu bar of frame F, and free its storage. | |
2272 This is used when deleting a frame, and when turning off the menu bar. */ | |
2273 | |
2274 void | |
2275 free_frame_menubar (f) | |
2276 FRAME_PTR f; | |
2277 { | |
2278 struct x_output *x = f->output_data.x; | |
2279 | |
2280 if (x->menubar_widget) | |
2281 { | |
2282 BLOCK_INPUT; | |
2283 | |
2284 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), x->menubar_widget); | |
2285 /* The menubar and its children shall be deleted when removed from | |
2286 the container. */ | |
2287 x->menubar_widget = 0; | |
2288 FRAME_MENUBAR_HEIGHT (f) = 0; | |
2289 | |
2290 /* The height has changed, resize outer widget and set columns | |
2291 rows to what we had before removing the menu bar. */ | |
2292 xg_resize_outer_widget (f, FRAME_WIDTH (f), FRAME_HEIGHT (f)); | |
2293 | |
2294 SET_FRAME_GARBAGED (f); | |
2295 UNBLOCK_INPUT; | |
2296 } | |
2297 } | |
2298 | |
2299 | |
2300 | |
2301 /*********************************************************************** | |
2302 Scroll bar functions | |
2303 ***********************************************************************/ | |
2304 | |
2305 | |
2306 /* Setting scroll bar values invokes the callback. Use this variable | |
2307 to indicate that callback should do nothing. */ | |
2308 int xg_ignore_gtk_scrollbar; | |
2309 | |
2310 /* SET_SCROLL_BAR_X_WINDOW assumes the second argument fits in | |
2311 32 bits. But we want to store pointers, and they may be larger | |
2312 than 32 bits. Keep a mapping from integer index to widget pointers | |
2313 to get around the 32 bit limitation. */ | |
2314 static struct | |
2315 { | |
2316 GtkWidget **widgets; | |
2317 int max_size; | |
2318 int used; | |
49419
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
2319 } id_to_widget; |
49323 | 2320 |
2321 /* Grow this much every time we need to allocate more */ | |
2322 #define ID_TO_WIDGET_INCR 32 | |
2323 | |
2324 /* Store the widget pointer W in id_to_widget and return the integer index. */ | |
2325 static int | |
2326 xg_store_widget_in_map (w) | |
2327 GtkWidget *w; | |
2328 { | |
2329 int i; | |
2330 | |
2331 if (id_to_widget.max_size == id_to_widget.used) | |
2332 { | |
2333 int new_size = id_to_widget.max_size + ID_TO_WIDGET_INCR; | |
2334 | |
2335 id_to_widget.widgets = xrealloc (id_to_widget.widgets, | |
2336 sizeof (GtkWidget *)*new_size); | |
2337 | |
2338 for (i = id_to_widget.max_size; i < new_size; ++i) | |
2339 id_to_widget.widgets[i] = 0; | |
2340 id_to_widget.max_size = new_size; | |
2341 } | |
2342 | |
2343 /* Just loop over the array and find a free place. After all, | |
2344 how many scroll bars are we creating? Should be a small number. | |
2345 The check above guarantees we will find a free place. */ | |
2346 for (i = 0; i < id_to_widget.max_size; ++i) | |
2347 { | |
2348 if (! id_to_widget.widgets[i]) | |
2349 { | |
2350 id_to_widget.widgets[i] = w; | |
2351 ++id_to_widget.used; | |
2352 | |
2353 return i; | |
2354 } | |
2355 } | |
2356 | |
2357 /* Should never end up here */ | |
2358 abort (); | |
2359 } | |
2360 | |
2361 /* Remove pointer at IDX from id_to_widget. | |
2362 Called when scroll bar is destroyed. */ | |
2363 static void | |
2364 xg_remove_widget_from_map (idx) | |
2365 int idx; | |
2366 { | |
2367 if (idx < id_to_widget.max_size && id_to_widget.widgets[idx] != 0) | |
2368 { | |
2369 id_to_widget.widgets[idx] = 0; | |
2370 --id_to_widget.used; | |
2371 } | |
2372 } | |
2373 | |
2374 /* Get the widget pointer at IDX from id_to_widget. */ | |
2375 static GtkWidget * | |
2376 xg_get_widget_from_map (idx) | |
2377 int idx; | |
2378 { | |
2379 if (idx < id_to_widget.max_size && id_to_widget.widgets[idx] != 0) | |
2380 return id_to_widget.widgets[idx]; | |
2381 | |
2382 return 0; | |
2383 } | |
2384 | |
50063 | 2385 /* Return the scrollbar id for X Window WID. |
2386 Return -1 if WID not in id_to_widget. */ | |
2387 int | |
2388 xg_get_scroll_id_for_window (wid) | |
2389 Window wid; | |
2390 { | |
2391 int idx; | |
2392 GtkWidget *w; | |
2393 | |
2394 w = xg_win_to_widget (wid); | |
2395 | |
2396 if (w) | |
2397 { | |
2398 for (idx = 0; idx < id_to_widget.max_size; ++idx) | |
2399 if (id_to_widget.widgets[idx] == w) | |
2400 return idx; | |
2401 } | |
2402 | |
2403 return -1; | |
2404 } | |
2405 | |
49323 | 2406 /* Callback invoked when scroll bar WIDGET is destroyed. |
2407 DATA is the index into id_to_widget for WIDGET. | |
50129
d0142038feaa
Reduce flicker in GTK scrollbars.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50112
diff
changeset
|
2408 We free pointer to last scroll bar values here and remove the index. */ |
49323 | 2409 static void |
2410 xg_gtk_scroll_destroy (widget, data) | |
2411 GtkWidget *widget; | |
2412 gpointer data; | |
2413 { | |
2414 gpointer p; | |
2415 int id = (int)data; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2416 |
49323 | 2417 p = g_object_get_data (G_OBJECT (widget), XG_LAST_SB_DATA); |
2418 if (p) xfree (p); | |
2419 xg_remove_widget_from_map (id); | |
2420 } | |
2421 | |
2422 /* Callback for button press/release events. Used to start timer so that | |
2423 the scroll bar repetition timer in GTK gets handeled. | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2424 Also, sets bar->dragging to Qnil when dragging (button release) is done. |
49323 | 2425 WIDGET is the scroll bar widget the event is for (not used). |
2426 EVENT contains the event. | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2427 USER_DATA points to the struct scrollbar structure. |
49323 | 2428 |
2429 Returns FALSE to tell GTK that it shall continue propagate the event | |
2430 to widgets. */ | |
2431 static gboolean | |
2432 scroll_bar_button_cb (widget, event, user_data) | |
2433 GtkWidget *widget; | |
2434 GdkEventButton *event; | |
2435 gpointer user_data; | |
2436 { | |
2437 if (event->type == GDK_BUTTON_PRESS && ! xg_timer) | |
2438 xg_start_timer (); | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2439 else if (event->type == GDK_BUTTON_RELEASE) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2440 { |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2441 struct scroll_bar *bar = (struct scroll_bar *) user_data; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2442 if (xg_timer) xg_stop_timer (); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2443 bar->dragging = Qnil; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2444 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2445 |
49323 | 2446 return FALSE; |
2447 } | |
2448 | |
2449 /* Create a scroll bar widget for frame F. Store the scroll bar | |
2450 in BAR. | |
2451 SCROLL_CALLBACK is the callback to invoke when the value of the | |
2452 bar changes. | |
2453 SCROLL_BAR_NAME is the name we use for the scroll bar. Can be used | |
2454 to set resources for the widget. */ | |
2455 void | |
2456 xg_create_scroll_bar (f, bar, scroll_callback, scroll_bar_name) | |
2457 FRAME_PTR f; | |
2458 struct scroll_bar *bar; | |
2459 GCallback scroll_callback; | |
2460 char *scroll_bar_name; | |
2461 { | |
2462 GtkWidget *wscroll; | |
2463 GtkObject *vadj; | |
2464 int scroll_id; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2465 |
49323 | 2466 /* Page, step increment values are not so important here, they |
2467 will be corrected in x_set_toolkit_scroll_bar_thumb. */ | |
2468 vadj = gtk_adjustment_new (XG_SB_MIN, XG_SB_MIN, XG_SB_MAX, | |
2469 0.1, 0.1, 0.1); | |
2470 | |
2471 wscroll = gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj)); | |
2472 gtk_widget_set_name (wscroll, scroll_bar_name); | |
2473 gtk_range_set_update_policy (GTK_RANGE (wscroll), GTK_UPDATE_CONTINUOUS); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2474 |
49323 | 2475 scroll_id = xg_store_widget_in_map (wscroll); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2476 |
49323 | 2477 g_signal_connect (G_OBJECT (vadj), |
2478 "value-changed", | |
2479 scroll_callback, | |
2480 (gpointer)bar); | |
2481 g_signal_connect (G_OBJECT (wscroll), | |
2482 "destroy", | |
2483 G_CALLBACK (xg_gtk_scroll_destroy), | |
2484 (gpointer)scroll_id); | |
2485 | |
2486 /* Connect to button press and button release to detect if any scroll bar | |
2487 has the pointer. */ | |
2488 g_signal_connect (G_OBJECT (wscroll), | |
2489 "button-press-event", | |
2490 G_CALLBACK (scroll_bar_button_cb), | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2491 (gpointer)bar); |
49323 | 2492 g_signal_connect (G_OBJECT (wscroll), |
2493 "button-release-event", | |
2494 G_CALLBACK (scroll_bar_button_cb), | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2495 (gpointer)bar); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2496 |
49323 | 2497 gtk_fixed_put (GTK_FIXED (f->output_data.x->edit_widget), |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2498 wscroll, -1, -1); |
49323 | 2499 |
2500 /* Set the cursor to an arrow. */ | |
2501 xg_set_cursor (wscroll, &xg_left_ptr_cursor); | |
2502 | |
2503 SET_SCROLL_BAR_X_WINDOW (bar, scroll_id); | |
2504 } | |
2505 | |
2506 /* Make the scroll bar represented by SCROLLBAR_ID visible. */ | |
2507 void | |
2508 xg_show_scroll_bar (scrollbar_id) | |
2509 int scrollbar_id; | |
2510 { | |
2511 GtkWidget *w = xg_get_widget_from_map (scrollbar_id); | |
2512 if (w) | |
2513 gtk_widget_show (w); | |
2514 } | |
2515 | |
2516 /* Remove the scroll bar represented by SCROLLBAR_ID from the frame F. */ | |
2517 void | |
2518 xg_remove_scroll_bar (f, scrollbar_id) | |
2519 FRAME_PTR f; | |
2520 int scrollbar_id; | |
2521 { | |
2522 GtkWidget *w = xg_get_widget_from_map (scrollbar_id); | |
2523 if (w) | |
2524 { | |
2525 gtk_widget_destroy (w); | |
2526 SET_FRAME_GARBAGED (f); | |
2527 } | |
2528 } | |
2529 | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2530 /* Find left/top for widget W in GtkFixed widget WFIXED. */ |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2531 static void |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2532 xg_find_top_left_in_fixed (w, wfixed, left, top) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2533 GtkWidget *w, *wfixed; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2534 int *left, *top; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2535 { |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2536 GList *iter; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2537 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2538 for (iter = GTK_FIXED (wfixed)->children; iter; iter = g_list_next (iter)) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2539 { |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2540 GtkFixedChild *child = (GtkFixedChild *) iter->data; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2541 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2542 if (child->widget == w) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2543 { |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2544 *left = child->x; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2545 *top = child->y; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2546 return; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2547 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2548 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2549 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2550 /* Shall never end up here. */ |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2551 abort (); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2552 } |
49323 | 2553 |
2554 /* Update the position of the vertical scroll bar represented by SCROLLBAR_ID | |
2555 in frame F. | |
2556 TOP/LEFT are the new pixel positions where the bar shall appear. | |
2557 WIDTH, HEIGHT is the size in pixels the bar shall have. */ | |
2558 void | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2559 xg_update_scrollbar_pos (f, scrollbar_id, top, left, width, height, |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2560 real_left, canon_width) |
49323 | 2561 FRAME_PTR f; |
2562 int scrollbar_id; | |
2563 int top; | |
2564 int left; | |
2565 int width; | |
2566 int height; | |
2567 { | |
49572 | 2568 |
2569 GtkWidget *wscroll = xg_get_widget_from_map (scrollbar_id); | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2570 |
49572 | 2571 if (wscroll) |
2572 { | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2573 GtkWidget *wfixed = f->output_data.x->edit_widget; |
49572 | 2574 int gheight = max (height, 1); |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2575 int winextra = canon_width > width ? (canon_width - width) / 2 : 0; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2576 int bottom = top + gheight; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2577 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2578 gint slider_width; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2579 int oldtop, oldleft, oldbottom; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2580 GtkRequisition req; |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2581 |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2582 /* Get old values. */ |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2583 xg_find_top_left_in_fixed (wscroll, wfixed, &oldleft, &oldtop); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2584 gtk_widget_size_request (wscroll, &req); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2585 oldbottom = oldtop + req.height; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2586 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2587 /* Scroll bars in GTK has a fixed width, so if we say width 16, it |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2588 will only be its fixed width (14 is default) anyway, the rest is |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2589 blank. We are drawing the mode line across scroll bars when |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2590 the frame is split: |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2591 |bar| |fringe| |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2592 ---------------- |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2593 mode line |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2594 ---------------- |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2595 |bar| |fringe| |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2596 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2597 When we "unsplit" the frame: |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2598 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2599 |bar| |fringe| |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2600 -| |-| | |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2601 m¦ |i| | |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2602 -| |-| | |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2603 | | | | |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2604 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2605 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2606 the remains of the mode line can be seen in these blank spaces. |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2607 So we must clear them explicitly. |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2608 GTK scroll bars should do that, but they don't. |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2609 Also, the canonical width may be wider than the width for the |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2610 scroll bar so that there is some space (typically 1 pixel) between |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2611 the scroll bar and the edge of the window and between the scroll |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2612 bar and the fringe. */ |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2613 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2614 if (oldtop != -1 && oldleft != -1) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2615 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2616 int gtkextral, gtkextrah; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2617 int xl, xr, wbl, wbr; |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2618 int bottomdiff, topdiff; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2619 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2620 gtk_widget_style_get (wscroll, "slider_width", &slider_width, NULL); |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2621 gtkextral = width > slider_width ? (width - slider_width) / 2 : 0; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2622 gtkextrah = gtkextral ? (width - slider_width - gtkextral) : 0; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2623 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2624 xl = real_left; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2625 wbl = gtkextral + winextra; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2626 wbr = gtkextrah + winextra; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2627 xr = left + gtkextral + slider_width; |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2628 bottomdiff = abs (oldbottom - bottom); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2629 topdiff = abs (oldtop - top); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2630 |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2631 if (oldleft != left) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2632 { |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2633 gdk_window_clear_area (wfixed->window, xl, top, wbl, gheight); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2634 gdk_window_clear_area (wfixed->window, xr, top, wbr, gheight); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2635 } |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2636 |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2637 if (oldtop > top) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2638 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2639 gdk_window_clear_area (wfixed->window, xl, top, wbl, topdiff); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2640 gdk_window_clear_area (wfixed->window, xr, top, wbr, topdiff); |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2641 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2642 else if (oldtop < top) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2643 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2644 gdk_window_clear_area (wfixed->window, xl, oldtop, wbl, topdiff); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2645 gdk_window_clear_area (wfixed->window, xr, oldtop, wbr, topdiff); |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2646 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2647 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2648 if (oldbottom > bottom) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2649 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2650 gdk_window_clear_area (wfixed->window, xl, bottom, wbl, |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2651 bottomdiff); |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2652 gdk_window_clear_area (wfixed->window, xr, bottom, wbr, |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2653 bottomdiff); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2654 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2655 else if (oldbottom < bottom) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2656 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2657 gdk_window_clear_area (wfixed->window, xl, oldbottom, wbl, |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2658 bottomdiff); |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2659 gdk_window_clear_area (wfixed->window, xr, oldbottom, wbr, |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2660 bottomdiff); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2661 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2662 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2663 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2664 /* Move and resize to new values. */ |
50129
d0142038feaa
Reduce flicker in GTK scrollbars.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50112
diff
changeset
|
2665 gtk_fixed_move (GTK_FIXED (wfixed), wscroll, left, top); |
49572 | 2666 gtk_widget_set_size_request (wscroll, width, gheight); |
2667 | |
50272 | 2668 /* Must force out update so changed scroll bars gets redrawn. */ |
2669 gdk_window_process_all_updates (); | |
2670 | |
49572 | 2671 SET_FRAME_GARBAGED (f); |
2672 cancel_mouse_face (f); | |
2673 } | |
49323 | 2674 } |
2675 | |
2676 /* Set the thumb size and position of scroll bar BAR. We are currently | |
2677 displaying PORTION out of a whole WHOLE, and our position POSITION. */ | |
2678 void | |
2679 xg_set_toolkit_scroll_bar_thumb (bar, portion, position, whole) | |
2680 struct scroll_bar *bar; | |
2681 int portion, position, whole; | |
2682 { | |
2683 GtkWidget *wscroll = xg_get_widget_from_map (SCROLL_BAR_X_WINDOW (bar)); | |
2684 | |
2685 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
2686 | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2687 if (wscroll && NILP (bar->dragging)) |
49323 | 2688 { |
2689 GtkAdjustment *adj; | |
2690 gdouble shown; | |
2691 gdouble top; | |
2692 int size, value; | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2693 int new_step; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2694 int changed = 0; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2695 |
49323 | 2696 adj = gtk_range_get_adjustment (GTK_RANGE (wscroll)); |
2697 | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2698 /* We do the same as for MOTIF in xterm.c, assume 30 chars per line |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2699 rather than the real portion value. This makes the thumb less likely |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2700 to resize and that looks better. */ |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2701 portion = XFASTINT (XWINDOW (bar->window)->height) * 30; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2702 /* When the thumb is at the bottom, position == whole. |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2703 So we need to increase `whole' to make space for the thumb. */ |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2704 whole += portion; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2705 |
49323 | 2706 if (whole <= 0) |
2707 top = 0, shown = 1; | |
2708 else | |
2709 { | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2710 top = (gdouble) position / whole; |
49323 | 2711 shown = (gdouble) portion / whole; |
2712 } | |
2713 | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2714 size = shown * XG_SB_RANGE; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2715 size = min (size, XG_SB_RANGE); |
49323 | 2716 size = max (size, 1); |
2717 | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2718 value = top * XG_SB_RANGE; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2719 value = min (value, XG_SB_MAX - size); |
49323 | 2720 value = max (value, XG_SB_MIN); |
2721 | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2722 /* Assume all lines are of equal size. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2723 new_step = size / max (1, FRAME_HEIGHT (f)); |
50178
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2724 |
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2725 if ((int) adj->page_size != size |
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2726 || (int) adj->step_increment != new_step) |
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2727 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2728 adj->page_size = size; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2729 adj->step_increment = new_step; |
50178
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2730 /* Assume a page increment is about 95% of the page size */ |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2731 adj->page_increment = (int) (0.95*adj->page_size); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2732 changed = 1; |
50178
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2733 } |
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2734 |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2735 if (changed || (int) gtk_range_get_value (GTK_RANGE (wscroll)) != value) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2736 { |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2737 GtkWidget *wfixed = f->output_data.x->edit_widget; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2738 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2739 BLOCK_INPUT; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2740 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2741 /* gtk_range_set_value invokes the callback. Set |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2742 ignore_gtk_scrollbar to make the callback do nothing */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2743 xg_ignore_gtk_scrollbar = 1; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2744 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2745 if ((int) gtk_range_get_value (GTK_RANGE (wscroll)) != value) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2746 gtk_range_set_value (GTK_RANGE (wscroll), (gdouble)value); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2747 else if (changed) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2748 gtk_adjustment_changed (adj); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2749 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2750 xg_ignore_gtk_scrollbar = 0; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2751 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2752 UNBLOCK_INPUT; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2753 } |
49323 | 2754 } |
2755 } | |
2756 | |
2757 | |
2758 /*********************************************************************** | |
2759 Tool bar functions | |
2760 ***********************************************************************/ | |
2761 /* The key for the data we put in the GtkImage widgets. The data is | |
2762 the image used by Emacs. We use this to see if we need to update | |
2763 the GtkImage with a new image. */ | |
2764 #define XG_TOOL_BAR_IMAGE_DATA "emacs-tool-bar-image" | |
2765 | |
2766 /* Callback function invoked when a tool bar item is pressed. | |
2767 W is the button widget in the tool bar that got pressed, | |
2768 CLIENT_DATA is an integer that is the index of the button in the | |
2769 tool bar. 0 is the first button. */ | |
2770 static void | |
2771 xg_tool_bar_callback (w, client_data) | |
2772 GtkWidget *w; | |
2773 gpointer client_data; | |
2774 { | |
2775 int idx = (int)client_data; | |
2776 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA); | |
2777 Lisp_Object key, frame; | |
2778 struct input_event event; | |
2779 | |
2780 if (! f || ! f->n_tool_bar_items || NILP (f->tool_bar_items)) | |
2781 return; | |
2782 | |
2783 idx *= TOOL_BAR_ITEM_NSLOTS; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2784 |
49323 | 2785 key = AREF (f->tool_bar_items, idx + TOOL_BAR_ITEM_KEY); |
2786 XSETFRAME (frame, f); | |
2787 event.kind = TOOL_BAR_EVENT; | |
2788 event.frame_or_window = frame; | |
2789 event.arg = frame; | |
2790 kbd_buffer_store_event (&event); | |
2791 | |
2792 event.kind = TOOL_BAR_EVENT; | |
2793 event.frame_or_window = frame; | |
2794 event.arg = key; | |
2795 event.modifiers = 0; /* These are not available. */ | |
2796 kbd_buffer_store_event (&event); | |
2797 } | |
2798 | |
2799 /* This callback is called when a tool bar is detached. We must set | |
2800 the height of the tool bar to zero when this happens so frame sizes | |
2801 are correctly calculated. | |
2802 WBOX is the handle box widget that enables detach/attach of the tool bar. | |
2803 W is the tool bar widget. | |
2804 CLIENT_DATA is a pointer to the frame the tool bar belongs to. */ | |
2805 static void | |
2806 xg_tool_bar_detach_callback (wbox, w, client_data) | |
2807 GtkHandleBox *wbox; | |
2808 GtkWidget *w; | |
2809 gpointer client_data; | |
2810 { | |
2811 FRAME_PTR f = (FRAME_PTR) client_data; | |
2812 | |
2813 if (f) | |
2814 { | |
2815 /* When detaching a tool bar, not everything dissapear. There are | |
2816 a few pixels left that are used to drop the tool bar back into | |
2817 place. */ | |
2818 int bw = gtk_container_get_border_width (GTK_CONTAINER (wbox)); | |
2819 FRAME_TOOLBAR_HEIGHT (f) = 2; | |
2820 | |
2821 /* The height has changed, resize outer widget and set columns | |
2822 rows to what we had before detaching the tool bar. */ | |
2823 xg_resize_outer_widget (f, FRAME_WIDTH (f), FRAME_HEIGHT (f)); | |
2824 } | |
2825 } | |
2826 | |
2827 /* This callback is called when a tool bar is reattached. We must set | |
2828 the height of the tool bar when this happens so frame sizes | |
2829 are correctly calculated. | |
2830 WBOX is the handle box widget that enables detach/attach of the tool bar. | |
2831 W is the tool bar widget. | |
2832 CLIENT_DATA is a pointer to the frame the tool bar belongs to. */ | |
2833 static void | |
2834 xg_tool_bar_attach_callback (wbox, w, client_data) | |
2835 GtkHandleBox *wbox; | |
2836 GtkWidget *w; | |
2837 gpointer client_data; | |
2838 { | |
2839 FRAME_PTR f = (FRAME_PTR) client_data; | |
2840 | |
2841 if (f) | |
2842 { | |
2843 GtkRequisition req; | |
2844 | |
2845 gtk_widget_size_request (w, &req); | |
2846 FRAME_TOOLBAR_HEIGHT (f) = req.height; | |
2847 | |
2848 /* The height has changed, resize outer widget and set columns | |
2849 rows to what we had before detaching the tool bar. */ | |
2850 xg_resize_outer_widget (f, FRAME_WIDTH (f), FRAME_HEIGHT (f)); | |
2851 } | |
2852 } | |
2853 | |
2854 /* This callback is called when the mouse enters or leaves a tool bar item. | |
2855 It is used for displaying and hiding the help text. | |
2856 W is the tool bar item, a button. | |
2857 EVENT is either an enter event or leave event. | |
2858 CLIENT_DATA is an integer that is the index of the button in the | |
2859 tool bar. 0 is the first button. | |
2860 | |
2861 Returns FALSE to tell GTK to keep processing this event. */ | |
2862 static gboolean | |
2863 xg_tool_bar_help_callback (w, event, client_data) | |
2864 GtkWidget *w; | |
2865 GdkEventCrossing *event; | |
2866 gpointer client_data; | |
2867 { | |
2868 int idx = (int)client_data; | |
2869 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA); | |
2870 Lisp_Object help, frame; | |
2871 | |
2872 if (! GTK_IS_BUTTON (w)) | |
2873 { | |
2874 return FALSE; | |
2875 } | |
2876 | |
2877 if (! f || ! f->n_tool_bar_items || NILP (f->tool_bar_items)) | |
50108
a9ff586d3d09
(xg_tool_bar_help_callback): Add missing return value.
Andreas Schwab <schwab@suse.de>
parents:
50106
diff
changeset
|
2878 return FALSE; |
49323 | 2879 |
2880 if (event->type == GDK_ENTER_NOTIFY) | |
2881 { | |
2882 idx *= TOOL_BAR_ITEM_NSLOTS; | |
2883 help = AREF (f->tool_bar_items, idx + TOOL_BAR_ITEM_HELP); | |
2884 | |
2885 if (NILP (help)) | |
2886 help = AREF (f->tool_bar_items, idx + TOOL_BAR_ITEM_CAPTION); | |
2887 } | |
2888 else | |
2889 help = Qnil; | |
2890 | |
2891 XSETFRAME (frame, f); | |
2892 kbd_buffer_store_help_event (frame, help); | |
2893 | |
2894 return FALSE; | |
2895 } | |
2896 | |
2897 | |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2898 /* This callback is called when a tool bar item shall be redrawn. |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2899 It modifies the expose event so that the GtkImage widget redraws the |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2900 whole image. This to overcome a bug that makes GtkImage draw the image |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2901 in the wrong place when it tries to redraw just a part of the image. |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2902 W is the GtkImage to be redrawn. |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2903 EVENT is the expose event for W. |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2904 CLIENT_DATA is unused. |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2905 |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2906 Returns FALSE to tell GTK to keep processing this event. */ |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2907 static gboolean |
50063 | 2908 xg_tool_bar_item_expose_callback (w, event, client_data) |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2909 GtkWidget *w; |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2910 GdkEventExpose *event; |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2911 gpointer client_data; |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2912 { |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2913 event->area.x = event->area.y = 0; |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2914 event->area.width = event->area.height = 1000; |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2915 return FALSE; |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2916 } |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2917 |
50063 | 2918 /* This callback is called when a tool bar shall be redrawn. |
2919 We need to update the tool bar from here in case the image cache | |
2920 has deleted the pixmaps used in the tool bar. | |
2921 W is the GtkToolbar to be redrawn. | |
2922 EVENT is the expose event for W. | |
2923 CLIENT_DATA is pointing to the frame for this tool bar. | |
2924 | |
2925 Returns FALSE to tell GTK to keep processing this event. */ | |
2926 static gboolean | |
2927 xg_tool_bar_expose_callback (w, event, client_data) | |
2928 GtkWidget *w; | |
2929 GdkEventExpose *event; | |
2930 gpointer client_data; | |
2931 { | |
2932 update_frame_tool_bar((FRAME_PTR)client_data); | |
2933 return FALSE; | |
2934 } | |
2935 | |
49323 | 2936 static void |
2937 xg_create_tool_bar (f) | |
2938 FRAME_PTR f; | |
2939 { | |
2940 struct x_output *x = f->output_data.x; | |
2941 GtkRequisition req; | |
2942 int vbox_pos = x->menubar_widget ? 1 : 0; | |
2943 | |
2944 x->toolbar_widget = gtk_toolbar_new (); | |
2945 x->handlebox_widget = gtk_handle_box_new (); | |
2946 gtk_container_add (GTK_CONTAINER (x->handlebox_widget), | |
2947 x->toolbar_widget); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2948 |
49323 | 2949 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->handlebox_widget, |
2950 FALSE, FALSE, 0); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2951 |
49323 | 2952 gtk_box_reorder_child (GTK_BOX (x->vbox_widget), x->handlebox_widget, |
2953 vbox_pos); | |
2954 | |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2955 gtk_widget_set_name (x->toolbar_widget, "emacs-toolbar"); |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2956 |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2957 /* We only have icons, so override any user setting. We could |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2958 use the caption property of the toolbar item (see update_frame_tool_bar |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2959 below), but some of those strings are long, making the toolbar so |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2960 long it does not fit on the screen. The GtkToolbar widget makes every |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2961 item equal size, so the longest caption determine the size of every |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2962 tool bar item. I think the creators of the GtkToolbar widget |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2963 counted on 4 or 5 character long strings. */ |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2964 gtk_toolbar_set_style (GTK_TOOLBAR (x->toolbar_widget), GTK_TOOLBAR_ICONS); |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2965 gtk_toolbar_set_orientation (GTK_TOOLBAR (x->toolbar_widget), |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2966 GTK_ORIENTATION_HORIZONTAL); |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
2967 |
49323 | 2968 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-detached", |
2969 G_CALLBACK (xg_tool_bar_detach_callback), f); | |
2970 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-attached", | |
2971 G_CALLBACK (xg_tool_bar_attach_callback), f); | |
50063 | 2972 g_signal_connect (G_OBJECT (x->toolbar_widget), |
2973 "expose-event", | |
2974 G_CALLBACK (xg_tool_bar_expose_callback), | |
2975 f); | |
49323 | 2976 |
2977 gtk_widget_show_all (x->handlebox_widget); | |
2978 | |
2979 gtk_widget_size_request (x->toolbar_widget, &req); | |
2980 FRAME_TOOLBAR_HEIGHT (f) = req.height; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2981 |
49323 | 2982 /* The height has changed, resize outer widget and set columns |
2983 rows to what we had before adding the tool bar. */ | |
2984 xg_resize_outer_widget (f, FRAME_WIDTH (f), FRAME_HEIGHT (f)); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2985 |
49323 | 2986 SET_FRAME_GARBAGED (f); |
2987 } | |
2988 | |
2989 void | |
2990 update_frame_tool_bar (f) | |
2991 FRAME_PTR f; | |
2992 { | |
2993 int i; | |
2994 GtkRequisition old_req, new_req; | |
2995 GList *icon_list; | |
49572 | 2996 GList *iter; |
49323 | 2997 struct x_output *x = f->output_data.x; |
2998 | |
2999 if (! FRAME_GTK_WIDGET (f)) | |
3000 return; | |
3001 | |
3002 BLOCK_INPUT; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3003 |
49323 | 3004 if (! x->toolbar_widget) |
3005 xg_create_tool_bar (f); | |
3006 | |
3007 gtk_widget_size_request (x->toolbar_widget, &old_req); | |
3008 | |
3009 icon_list = gtk_container_get_children (GTK_CONTAINER (x->toolbar_widget)); | |
49572 | 3010 iter = icon_list; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3011 |
49323 | 3012 for (i = 0; i < f->n_tool_bar_items; ++i) |
3013 { | |
3014 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX)) | |
3015 | |
3016 int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); | |
3017 int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); | |
3018 int idx; | |
3019 int img_id; | |
3020 struct image *img; | |
3021 Lisp_Object image; | |
49572 | 3022 GtkWidget *wicon = iter ? GTK_WIDGET (iter->data) : 0; |
50059
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3023 |
49572 | 3024 if (iter) iter = g_list_next (iter); |
49323 | 3025 |
3026 /* If image is a vector, choose the image according to the | |
3027 button state. */ | |
3028 image = PROP (TOOL_BAR_ITEM_IMAGES); | |
3029 if (VECTORP (image)) | |
3030 { | |
3031 if (enabled_p) | |
3032 idx = (selected_p | |
3033 ? TOOL_BAR_IMAGE_ENABLED_SELECTED | |
3034 : TOOL_BAR_IMAGE_ENABLED_DESELECTED); | |
3035 else | |
3036 idx = (selected_p | |
3037 ? TOOL_BAR_IMAGE_DISABLED_SELECTED | |
3038 : TOOL_BAR_IMAGE_DISABLED_DESELECTED); | |
3039 | |
3040 xassert (ASIZE (image) >= idx); | |
3041 image = AREF (image, idx); | |
3042 } | |
3043 else | |
3044 idx = -1; | |
3045 | |
3046 /* Ignore invalid image specifications. */ | |
3047 if (!valid_image_p (image)) | |
3048 { | |
3049 if (wicon) gtk_widget_hide (wicon); | |
3050 continue; | |
3051 } | |
3052 | |
3053 img_id = lookup_image (f, image); | |
3054 img = IMAGE_FROM_ID (f, img_id); | |
49468
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3055 prepare_image_for_display (f, img); |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3056 |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3057 if (img->load_failed_p || img->pixmap == None) |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3058 { |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3059 if (wicon) gtk_widget_hide (wicon); |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3060 continue; |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3061 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3062 |
49323 | 3063 if (! wicon) |
3064 { | |
3065 GdkPixmap *gpix = gdk_pixmap_foreign_new (img->pixmap); | |
3066 GdkBitmap *gmask = img->mask ? | |
3067 (GdkBitmap*) gdk_pixmap_foreign_new (img->mask) : 0; | |
3068 | |
3069 GtkWidget *w = gtk_image_new_from_pixmap (gpix, gmask); | |
3070 gtk_toolbar_append_item (GTK_TOOLBAR (x->toolbar_widget), | |
3071 0, 0, 0, | |
3072 w, | |
3073 GTK_SIGNAL_FUNC (xg_tool_bar_callback), | |
3074 (gpointer)i); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3075 |
49323 | 3076 /* Save the image so we can see if an update is needed when |
3077 this function is called again. */ | |
3078 g_object_set_data (G_OBJECT (w), XG_TOOL_BAR_IMAGE_DATA, | |
50059
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3079 (gpointer)img->pixmap); |
49323 | 3080 |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3081 /* Catch expose events to overcome an annoying redraw bug, see |
50063 | 3082 comment for xg_tool_bar_item_expose_callback. */ |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3083 g_signal_connect (G_OBJECT (w), |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3084 "expose-event", |
50063 | 3085 G_CALLBACK (xg_tool_bar_item_expose_callback), |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3086 0); |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3087 |
49323 | 3088 /* We must set sensitive on the button that is the parent |
3089 of the GtkImage parent. Go upwards until we find the button. */ | |
3090 while (! GTK_IS_BUTTON (w)) | |
3091 w = gtk_widget_get_parent (w); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3092 |
49323 | 3093 if (w) |
3094 { | |
3095 /* Save the frame in the button so the xg_tool_bar_callback | |
3096 can get at it. */ | |
3097 g_object_set_data (G_OBJECT (w), XG_FRAME_DATA, (gpointer)f); | |
3098 gtk_widget_set_sensitive (w, enabled_p); | |
3099 | |
3100 /* Use enter/leave notify to show help. We use the events | |
3101 rather than the GtkButton specific signals "enter" and | |
3102 "leave", so we can have only one callback. The event | |
3103 will tell us what kind of event it is. */ | |
3104 g_signal_connect (G_OBJECT (w), | |
3105 "enter-notify-event", | |
3106 G_CALLBACK (xg_tool_bar_help_callback), | |
3107 (gpointer)i); | |
3108 g_signal_connect (G_OBJECT (w), | |
3109 "leave-notify-event", | |
3110 G_CALLBACK (xg_tool_bar_help_callback), | |
3111 (gpointer)i); | |
3112 } | |
3113 } | |
3114 else | |
3115 { | |
3116 /* The child of the tool bar is a button. Inside that button | |
3117 is a vbox. Inside that vbox is the GtkImage. */ | |
3118 GtkWidget *wvbox = gtk_bin_get_child (GTK_BIN (wicon)); | |
49572 | 3119 GList *chlist = gtk_container_get_children (GTK_CONTAINER (wvbox)); |
3120 GtkImage *wimage = GTK_IMAGE (chlist->data); | |
50059
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3121 Pixmap old_img = (Pixmap)g_object_get_data (G_OBJECT (wimage), |
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3122 XG_TOOL_BAR_IMAGE_DATA); |
49572 | 3123 g_list_free (chlist); |
49323 | 3124 |
50059
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3125 if (old_img != img->pixmap) |
49323 | 3126 { |
3127 GdkPixmap *gpix = gdk_pixmap_foreign_new (img->pixmap); | |
3128 GdkBitmap *gmask = img->mask ? | |
3129 (GdkBitmap*) gdk_pixmap_foreign_new (img->mask) : 0; | |
3130 | |
3131 gtk_image_set_from_pixmap (wimage, gpix, gmask); | |
3132 } | |
3133 | |
3134 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA, | |
50059
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3135 (gpointer)img->pixmap); |
49323 | 3136 |
3137 gtk_widget_set_sensitive (wicon, enabled_p); | |
3138 gtk_widget_show (wicon); | |
3139 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3140 |
49323 | 3141 #undef PROP |
3142 } | |
3143 | |
3144 /* Remove buttons not longer needed. We just hide them so they | |
3145 can be reused later on. */ | |
49572 | 3146 while (iter) |
49323 | 3147 { |
49572 | 3148 GtkWidget *w = GTK_WIDGET (iter->data); |
49323 | 3149 gtk_widget_hide (w); |
49572 | 3150 iter = g_list_next (iter); |
49323 | 3151 } |
3152 | |
3153 gtk_widget_size_request (x->toolbar_widget, &new_req); | |
3154 if (old_req.height != new_req.height) | |
3155 { | |
3156 FRAME_TOOLBAR_HEIGHT (f) = new_req.height; | |
3157 xg_resize_outer_widget (f, FRAME_WIDTH (f), FRAME_HEIGHT (f)); | |
3158 } | |
3159 | |
3160 /* Must force out update so changed images gets redrawn. */ | |
3161 gdk_window_process_all_updates (); | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
3162 |
49572 | 3163 if (icon_list) g_list_free (icon_list); |
3164 | |
49323 | 3165 UNBLOCK_INPUT; |
3166 } | |
3167 | |
3168 void | |
3169 free_frame_tool_bar (f) | |
3170 FRAME_PTR f; | |
3171 { | |
3172 struct x_output *x = f->output_data.x; | |
3173 | |
3174 if (x->toolbar_widget) | |
3175 { | |
3176 BLOCK_INPUT; | |
3177 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), | |
3178 x->handlebox_widget); | |
3179 x->toolbar_widget = 0; | |
3180 x->handlebox_widget = 0; | |
3181 FRAME_TOOLBAR_HEIGHT (f) = 0; | |
3182 | |
3183 /* The height has changed, resize outer widget and set columns | |
3184 rows to what we had before removing the tool bar. */ | |
3185 xg_resize_outer_widget (f, FRAME_WIDTH (f), FRAME_HEIGHT (f)); | |
3186 | |
3187 SET_FRAME_GARBAGED (f); | |
3188 UNBLOCK_INPUT; | |
3189 } | |
3190 } | |
3191 | |
3192 | |
3193 | |
3194 /*********************************************************************** | |
3195 Initializing | |
3196 ***********************************************************************/ | |
3197 void | |
3198 xg_initialize () | |
3199 { | |
3200 xg_ignore_gtk_scrollbar = 0; | |
3201 xg_left_ptr_cursor = 0; | |
3202 xg_did_tearoff = 0; | |
3203 | |
3204 xg_menu_cb_list.prev = xg_menu_cb_list.next = | |
3205 xg_menu_item_cb_list.prev = xg_menu_item_cb_list.next = 0; | |
3206 | |
49419
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3207 id_to_widget.max_size = id_to_widget.used = 0; |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3208 id_to_widget.widgets = 0; |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3209 |
49323 | 3210 /* Remove F10 as a menu accelerator, it does not mix well with Emacs key |
3211 bindings. It doesn't seem to be any way to remove properties, | |
3212 so we set it to VoidSymbol which in X means "no key". */ | |
3213 gtk_settings_set_string_property (gtk_settings_get_default (), | |
3214 "gtk-menu-bar-accel", | |
3215 "VoidSymbol", | |
3216 EMACS_CLASS); | |
49419
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3217 |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3218 /* Make GTK text input widgets use Emacs style keybindings. This is |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3219 Emacs after all. */ |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3220 gtk_settings_set_string_property (gtk_settings_get_default (), |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3221 "gtk-key-theme-name", |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3222 "Emacs", |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3223 EMACS_CLASS); |
49323 | 3224 } |
3225 | |
3226 #endif /* USE_GTK */ |