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