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