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