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