1 /* Functions for creating and updating GTK widgets.
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
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)
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.
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. */
29 #include "blockinput.h"
33 #include "termhooks.h"
34 #include <gdk/gdkkeysyms.h>
36 #define FRAME_TOTAL_PIXEL_HEIGHT(f) \
37 (PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f))
41 /***********************************************************************
43 ***********************************************************************/
44 /* The timer for scroll bar repetition and menu bar timeouts.
45 NULL if no timer is started. */
46 static struct atimer
*xg_timer
;
48 /* The cursor used for scroll bars and popup menus.
49 We only have one cursor for all scroll bars and all popup menus. */
50 static GdkCursor
*xg_left_ptr_cursor
;
53 /* The next two variables and functions are taken from lwlib. */
54 static widget_value
*widget_value_free_list
;
55 static int malloc_cpt
;
57 /* Allocate a widget_value structure, either by taking one from the
58 widget_value_free_list or by malloc:ing a new one.
60 Return a pointer to the allocated structure. */
62 malloc_widget_value ()
65 if (widget_value_free_list
)
67 wv
= widget_value_free_list
;
68 widget_value_free_list
= wv
->free_list
;
73 wv
= (widget_value
*) malloc (sizeof (widget_value
));
76 memset (wv
, 0, sizeof (widget_value
));
80 /* This is analogous to free. It frees only what was allocated
81 by malloc_widget_value, and no substructures. */
83 free_widget_value (wv
)
91 /* When the number of already allocated cells is too big,
98 wv
->free_list
= widget_value_free_list
;
99 widget_value_free_list
= wv
;
103 /* Set *CURSOR on W and all widgets W contain. We must do like this
104 for scroll bars and menu because they create widgets internally,
105 and it is those widgets that are visible.
107 If *CURSOR is NULL, create a GDK_LEFT_PTR cursor and set *CURSOR to
108 the created cursor. */
110 xg_set_cursor (w
, cursor
)
114 GList
*children
= gdk_window_peek_children (w
->window
);
116 /* Create the cursor unless already created. */
118 *cursor
= gdk_cursor_new (GDK_LEFT_PTR
);
120 gdk_window_set_cursor (w
->window
, *cursor
);
122 /* The scroll bar widget has more than one GDK window (had to look at
123 the source to figure this out), and there is no way to set cursor
124 on widgets in GTK. So we must set the cursor for all GDK windows.
127 for ( ; children
; children
= g_list_next (children
))
128 gdk_window_set_cursor (GDK_WINDOW (children
->data
), *cursor
);
131 /* Timer function called when a timeout occurs for xg_timer.
132 This function processes all GTK events in a recursive event loop.
133 This is done because GTK timer events are not seen by Emacs event
134 detection, Emacs only looks for X events. When a scroll bar has the
135 pointer (detected by button press/release events below) an Emacs
136 timer is started, and this function can then check if the GTK timer
137 has expired by calling the GTK event loop.
138 Also, when a menu is active, it has a small timeout before it
139 pops down the sub menu under it. */
141 xg_process_timeouts (timer
)
142 struct atimer
*timer
;
145 /* Ideally we would like to just handle timer events, like the Xt version
146 of this does in xterm.c, but there is no such feature in GTK. */
147 while (gtk_events_pending ())
148 gtk_main_iteration ();
152 /* Start the xg_timer with an interval of 0.1 seconds, if not already started.
153 xg_process_timeouts is called when the timer expires. The timer
154 stared is continuous, i.e. runs until xg_stop_timer is called. */
161 EMACS_SET_SECS_USECS (interval
, 0, 100000);
162 xg_timer
= start_atimer (ATIMER_CONTINUOUS
,
169 /* Stop the xg_timer if started. */
175 cancel_atimer (xg_timer
);
180 /* Insert NODE into linked LIST. */
182 xg_list_insert (xg_list_node
*list
, xg_list_node
*node
)
184 xg_list_node
*list_start
= list
->next
;
186 if (list_start
) list_start
->prev
= node
;
187 node
->next
= list_start
;
192 /* Remove NODE from linked LIST. */
194 xg_list_remove (xg_list_node
*list
, xg_list_node
*node
)
196 xg_list_node
*list_start
= list
->next
;
197 if (node
== list_start
)
199 list
->next
= node
->next
;
200 if (list
->next
) list
->next
->prev
= 0;
204 node
->prev
->next
= node
->next
;
205 if (node
->next
) node
->next
->prev
= node
->prev
;
209 /* Allocate and return a utf8 version of STR. If STR is already
210 utf8 or NULL, just return STR.
211 If not, a new string is allocated and the caller must free the result
214 get_utf8_string (str
)
217 char *utf8_str
= str
;
219 /* If not UTF-8, try current locale. */
220 if (str
&& !g_utf8_validate (str
, -1, NULL
))
221 utf8_str
= g_locale_to_utf8 (str
, -1, 0, 0, 0);
228 /***********************************************************************
229 General functions for creating widgets, resizing, events, e.t.c.
230 ***********************************************************************/
232 /* Make a geometry string and pass that to GTK. It seems this is the
233 only way to get geometry position right if the user explicitly
234 asked for a position when starting Emacs.
235 F is the frame we shall set geometry for. */
240 if (f
->output_data
.x
->size_hint_flags
& USPosition
)
242 int left
= f
->output_data
.x
->left_pos
;
243 int xneg
= f
->output_data
.x
->size_hint_flags
& XNegative
;
244 int top
= f
->output_data
.x
->top_pos
;
245 int yneg
= f
->output_data
.x
->size_hint_flags
& YNegative
;
253 sprintf (geom_str
, "=%dx%d%c%d%c%d",
255 FRAME_TOTAL_PIXEL_HEIGHT (f
),
256 (xneg
? '-' : '+'), left
,
257 (yneg
? '-' : '+'), top
);
259 if (!gtk_window_parse_geometry (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
261 fprintf (stderr
, "Failed to parse: '%s'\n", geom_str
);
266 /* Resize the outer window of frame F after chainging the height.
267 This happend when the menu bar or the tool bar is added or removed.
268 COLUMNS/ROWS is the size the edit area shall have after the resize. */
270 xg_resize_outer_widget (f
, columns
, rows
)
275 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
276 PIXEL_WIDTH (f
), FRAME_TOTAL_PIXEL_HEIGHT (f
));
278 /* base_height is now changed. */
279 x_wm_set_size_hint (f
, 0, 0);
281 /* If we are not mapped yet, set geometry once again, as window
282 height now have changed. */
283 if (! GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
286 xg_frame_set_char_size (f
, columns
, rows
);
287 gdk_window_process_all_updates ();
290 /* This gets called after the frame F has been cleared. Since that is
291 done with X calls, we need to redraw GTK widget (scroll bars). */
296 GtkWidget
*wfixed
= f
->output_data
.x
->edit_widget
;
300 gtk_container_set_reallocate_redraws (GTK_CONTAINER (wfixed
), TRUE
);
301 gdk_window_process_all_updates ();
305 /* Function to handle resize of our widgets. Since Emacs has some layouts
306 that does not fit well with GTK standard containers, we do most layout
308 F is the frame to resize.
309 PIXELWIDTH, PIXELHEIGHT is the new size in pixels. */
311 xg_resize_widgets (f
, pixelwidth
, pixelheight
)
313 int pixelwidth
, pixelheight
;
315 int mbheight
= FRAME_MENUBAR_HEIGHT (f
);
316 int tbheight
= FRAME_TOOLBAR_HEIGHT (f
);
317 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, pixelheight
- mbheight
- tbheight
);
318 int columns
= PIXEL_TO_CHAR_WIDTH (f
, pixelwidth
);
320 if (FRAME_GTK_WIDGET (f
)
321 && (columns
!= FRAME_WIDTH (f
) || rows
!= FRAME_HEIGHT (f
)
322 || pixelwidth
!= PIXEL_WIDTH (f
) || pixelheight
!= PIXEL_HEIGHT (f
)))
324 struct x_output
*x
= f
->output_data
.x
;
327 all
.y
= mbheight
+ tbheight
;
330 all
.width
= pixelwidth
;
331 all
.height
= pixelheight
- mbheight
- tbheight
;
333 gtk_widget_size_allocate (x
->edit_widget
, &all
);
335 xg_frame_cleared (f
);
337 change_frame_size (f
, rows
, columns
, 0, 1, 0);
338 SET_FRAME_GARBAGED (f
);
339 cancel_mouse_face (f
);
344 /* Update our widget size to be COLS/ROWS characters for frame F. */
346 xg_frame_set_char_size (f
, cols
, rows
)
351 int pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
)
352 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
353 int pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
355 /* Take into account the size of the scroll bar. Always use the
356 number of columns occupied by the scroll bar here otherwise we
357 might end up with a frame width that is not a multiple of the
358 frame's character width which is bad for vertically split
360 f
->output_data
.x
->vertical_scroll_bar_extra
361 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
363 : (FRAME_SCROLL_BAR_COLS (f
)
364 * FONT_WIDTH (f
->output_data
.x
->font
)));
366 compute_fringe_widths (f
, 0);
368 /* Must resize our top level widget. Font size may have changed,
369 but not rows/cols. */
370 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
371 pixelwidth
, pixelheight
);
372 xg_resize_widgets (f
, pixelwidth
, pixelheight
);
375 /* Convert an X Window WSESC to its corresponding GtkWidget.
376 Must be done like this, because GtkWidget:s can have "hidden"
377 X Window that aren't accessible.
379 Return 0 if no widget match WDESC. */
381 xg_win_to_widget (wdesc
)
385 GtkWidget
*gwdesc
= 0;
388 gdkwin
= gdk_xid_table_lookup (wdesc
);
392 event
.any
.window
= gdkwin
;
393 gwdesc
= gtk_get_event_widget (&event
);
400 /* Fill in the GdkColor C so that it represents PIXEL.
401 W is the widget that color will be used for. Used to find colormap. */
403 xg_pix_to_gcolor (w
, pixel
, c
)
408 GdkColormap
*map
= gtk_widget_get_colormap (w
);
409 gdk_colormap_query_color (map
, pixel
, c
);
412 /* Create and set up the GTK widgets for frame F.
413 Return 0 if creation failed, non-zero otherwise. */
415 xg_create_frame_widgets (f
)
428 wtop
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
429 wvbox
= gtk_vbox_new (FALSE
, 0);
430 wfixed
= gtk_fixed_new (); /* Must have this to place scroll bars */
432 if (! wtop
|| ! wvbox
|| ! wfixed
)
434 if (wtop
) gtk_widget_destroy (wtop
);
435 if (wvbox
) gtk_widget_destroy (wvbox
);
436 if (wfixed
) gtk_widget_destroy (wfixed
);
441 /* Use same names as the Xt port does. I.e. Emacs.pane.emacs by default */
442 gtk_widget_set_name (wtop
, EMACS_CLASS
);
443 gtk_widget_set_name (wvbox
, "pane");
444 gtk_widget_set_name (wfixed
, SDATA (Vx_resource_name
));
446 /* If this frame has a title or name, set it in the title bar. */
447 if (! NILP (f
->title
)) title
= SDATA (f
->title
);
448 else if (! NILP (f
->name
)) title
= SDATA (f
->name
);
450 if (title
) gtk_window_set_title (GTK_WINDOW (wtop
), title
);
452 FRAME_GTK_OUTER_WIDGET (f
) = wtop
;
453 FRAME_GTK_WIDGET (f
) = wfixed
;
454 f
->output_data
.x
->vbox_widget
= wvbox
;
456 gtk_fixed_set_has_window (GTK_FIXED (wfixed
), TRUE
);
458 gtk_widget_set_size_request (wfixed
,
462 gtk_container_add (GTK_CONTAINER (wtop
), wvbox
);
463 gtk_box_pack_end (GTK_BOX (wvbox
), wfixed
, TRUE
, TRUE
, 0);
465 if (FRAME_EXTERNAL_TOOL_BAR (f
))
466 update_frame_tool_bar (f
);
468 /* The tool bar is created but first there are no items in it.
469 This causes it to be zero height. Later items are added, but then
470 the frame is already mapped, so there is a "jumping" resize.
471 This makes geometry handling difficult, for example -0-0 will end
472 up in the wrong place as tool bar height has not been taken into account.
473 So we cheat a bit by setting a height that is what it will have
474 later on when tool bar items are added. */
475 if (FRAME_EXTERNAL_TOOL_BAR (f
) && FRAME_TOOLBAR_HEIGHT (f
) == 0)
476 FRAME_TOOLBAR_HEIGHT (f
) = 34;
478 gtk_widget_set_double_buffered (wvbox
, FALSE
);
479 gtk_widget_set_double_buffered (wfixed
, FALSE
);
480 gtk_widget_set_double_buffered (wtop
, FALSE
);
482 /* GTK documents says use gtk_window_set_resizable. But then a user
483 can't shrink the window from its starting size. */
484 gtk_window_set_policy (GTK_WINDOW (wtop
), TRUE
, TRUE
, TRUE
);
485 gtk_window_set_wmclass (GTK_WINDOW (wtop
),
486 SDATA (Vx_resource_name
),
487 SDATA (Vx_resource_class
));
489 /* Add callback to do nothing on WM_DELETE_WINDOW. The default in
490 GTK is to destroy the widget. We want Emacs to do that instead. */
491 g_signal_connect (G_OBJECT (wtop
), "delete-event",
492 G_CALLBACK (gtk_true
), 0);
494 /* Convert our geometry parameters into a geometry string
496 GTK will itself handle calculating the real position this way. */
499 gtk_widget_add_events (wfixed
,
500 GDK_POINTER_MOTION_MASK
502 | GDK_BUTTON_PRESS_MASK
503 | GDK_BUTTON_RELEASE_MASK
505 | GDK_ENTER_NOTIFY_MASK
506 | GDK_LEAVE_NOTIFY_MASK
507 | GDK_FOCUS_CHANGE_MASK
509 | GDK_VISIBILITY_NOTIFY_MASK
);
511 /* Must realize the windows so the X window gets created. It is used
512 by callers of this function. */
513 gtk_widget_realize (wfixed
);
514 FRAME_X_WINDOW (f
) = GTK_WIDGET_TO_X_WIN (wfixed
);
516 /* Since GTK clears its window by filling with the background color,
517 we must keep X and GTK background in sync. */
518 xg_pix_to_gcolor (wfixed
, f
->output_data
.x
->background_pixel
, &bg
);
519 gtk_widget_modify_bg (wfixed
, GTK_STATE_NORMAL
, &bg
);
521 /* Also, do not let any background pixmap to be set, this looks very
522 bad as Emacs overwrites the background pixmap with its own idea
523 of background color. */
524 style
= gtk_widget_get_modifier_style (wfixed
);
526 /* Must use g_strdup because gtk_widget_modify_style does g_free. */
527 style
->bg_pixmap_name
[GTK_STATE_NORMAL
] = g_strdup ("<none>");
528 gtk_widget_modify_style (wfixed
, style
);
530 /* GTK does not set any border, and they look bad with GTK. */
531 f
->output_data
.x
->border_width
= 0;
532 f
->output_data
.x
->internal_border_width
= 0;
539 /* Set the normal size hints for the window manager, for frame F.
540 FLAGS is the flags word to use--or 0 meaning preserve the flags
541 that the window now has.
542 If USER_POSITION is nonzero, we set the User Position
543 flag (this is useful when FLAGS is 0). */
545 x_wm_set_size_hint (f
, flags
, user_position
)
550 if (FRAME_GTK_OUTER_WIDGET (f
))
552 /* Must use GTK routines here, otherwise GTK resets the size hints
553 to its own defaults. */
554 GdkGeometry size_hints
;
556 int base_width
, base_height
;
557 int min_rows
= 0, min_cols
= 0;
558 int win_gravity
= f
->output_data
.x
->win_gravity
;
562 memset (&size_hints
, 0, sizeof (size_hints
));
563 f
->output_data
.x
->size_hints
= size_hints
;
564 f
->output_data
.x
->hint_flags
= hint_flags
;
567 flags
= f
->output_data
.x
->size_hint_flags
;
569 size_hints
= f
->output_data
.x
->size_hints
;
570 hint_flags
= f
->output_data
.x
->hint_flags
;
572 hint_flags
|= GDK_HINT_RESIZE_INC
| GDK_HINT_MIN_SIZE
;
573 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
574 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
576 hint_flags
|= GDK_HINT_BASE_SIZE
;
577 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
578 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0)
579 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
581 check_frame_size (f
, &min_rows
, &min_cols
);
583 size_hints
.base_width
= base_width
;
584 size_hints
.base_height
= base_height
;
585 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
586 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
589 /* These currently have a one to one mapping with the X values, but I
590 don't think we should rely on that. */
591 hint_flags
|= GDK_HINT_WIN_GRAVITY
;
592 size_hints
.win_gravity
= 0;
593 if (win_gravity
== NorthWestGravity
)
594 size_hints
.win_gravity
= GDK_GRAVITY_NORTH_WEST
;
595 else if (win_gravity
== NorthGravity
)
596 size_hints
.win_gravity
= GDK_GRAVITY_NORTH
;
597 else if (win_gravity
== NorthEastGravity
)
598 size_hints
.win_gravity
= GDK_GRAVITY_NORTH_EAST
;
599 else if (win_gravity
== WestGravity
)
600 size_hints
.win_gravity
= GDK_GRAVITY_WEST
;
601 else if (win_gravity
== CenterGravity
)
602 size_hints
.win_gravity
= GDK_GRAVITY_CENTER
;
603 else if (win_gravity
== EastGravity
)
604 size_hints
.win_gravity
= GDK_GRAVITY_EAST
;
605 else if (win_gravity
== SouthWestGravity
)
606 size_hints
.win_gravity
= GDK_GRAVITY_SOUTH_WEST
;
607 else if (win_gravity
== SouthGravity
)
608 size_hints
.win_gravity
= GDK_GRAVITY_SOUTH
;
609 else if (win_gravity
== SouthEastGravity
)
610 size_hints
.win_gravity
= GDK_GRAVITY_SOUTH_EAST
;
611 else if (win_gravity
== StaticGravity
)
612 size_hints
.win_gravity
= GDK_GRAVITY_STATIC
;
614 if (flags
& PPosition
) hint_flags
|= GDK_HINT_POS
;
615 if (flags
& USPosition
) hint_flags
|= GDK_HINT_USER_POS
;
616 if (flags
& USSize
) hint_flags
|= GDK_HINT_USER_SIZE
;
620 hint_flags
&= ~GDK_HINT_POS
;
621 hint_flags
|= GDK_HINT_USER_POS
;
626 gtk_window_set_geometry_hints (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
627 FRAME_GTK_OUTER_WIDGET (f
),
631 f
->output_data
.x
->size_hints
= size_hints
;
632 f
->output_data
.x
->hint_flags
= hint_flags
;
637 /* Change background color of a frame.
638 Since GTK uses the background colour to clear the window, we must
639 keep the GTK and X colors in sync.
640 F is the frame to change,
641 BG is the pixel value to change to. */
643 xg_set_background_color (f
, bg
)
647 if (FRAME_GTK_WIDGET (f
))
652 xg_pix_to_gcolor (FRAME_GTK_WIDGET (f
), bg
, &gdk_bg
);
653 gtk_widget_modify_bg (FRAME_GTK_WIDGET (f
), GTK_STATE_NORMAL
, &gdk_bg
);
660 /***********************************************************************
662 ***********************************************************************/
663 /* Return the dialog title to use for a dialog of type KEY.
664 This is the encoding used by lwlib. We use the same for GTK. */
666 get_dialog_title (char key
)
676 title
= "Information";
695 /* Callback for dialogs that get WM_DELETE_WINDOW. We pop down
696 the dialog, but return TRUE so the event does not propagate further
697 in GTK. This prevents GTK from destroying the dialog widget automatically
698 and we can always destrou the widget manually, regardles of how
699 it was popped down (button press or WM_DELETE_WINDOW).
700 W is the dialog widget.
701 EVENT is the GdkEvent that represents WM_DELETE_WINDOW (not used).
702 user_data is NULL (not used).
704 Returns TRUE to end propagation of event. */
706 dialog_delete_callback (w
, event
, user_data
)
711 gtk_widget_unmap (w
);
715 /* Create a popup dialog window. See also xg_create_widget below.
716 WV is a widget_value describing the dialog.
717 SELECT_CB is the callback to use when a button has been pressed.
718 DEACTIVATE_CB is the callback to use when the dialog pops down.
720 Returns the GTK dialog widget. */
722 create_dialog (wv
, select_cb
, deactivate_cb
)
725 GCallback deactivate_cb
;
727 char *title
= get_dialog_title (wv
->name
[0]);
728 int total_buttons
= wv
->name
[1] - '0';
729 int right_buttons
= wv
->name
[4] - '0';
732 int button_spacing
= 10;
733 GtkWidget
*wdialog
= gtk_dialog_new ();
738 GtkWidget
*whbox_down
;
740 /* If the number of buttons is greater than 4, make two rows of buttons
741 instead. This looks better. */
742 int make_two_rows
= total_buttons
> 4;
744 if (right_buttons
== 0) right_buttons
= total_buttons
/2;
745 left_buttons
= total_buttons
- right_buttons
;
747 gtk_window_set_title (GTK_WINDOW (wdialog
), title
);
748 gtk_widget_set_name (wdialog
, "emacs-dialog");
750 cur_box
= GTK_BOX (GTK_DIALOG (wdialog
)->action_area
);
754 wvbox
= gtk_vbox_new (TRUE
, button_spacing
);
755 whbox_up
= gtk_hbox_new (FALSE
, 0);
756 whbox_down
= gtk_hbox_new (FALSE
, 0);
758 gtk_box_pack_start (cur_box
, wvbox
, FALSE
, FALSE
, 0);
759 gtk_box_pack_start (GTK_BOX (wvbox
), whbox_up
, FALSE
, FALSE
, 0);
760 gtk_box_pack_start (GTK_BOX (wvbox
), whbox_down
, FALSE
, FALSE
, 0);
762 cur_box
= GTK_BOX (whbox_up
);
765 g_signal_connect (G_OBJECT (wdialog
), "delete-event",
766 G_CALLBACK (dialog_delete_callback
), 0);
770 g_signal_connect (G_OBJECT (wdialog
), "close", deactivate_cb
, 0);
771 g_signal_connect (G_OBJECT (wdialog
), "response", deactivate_cb
, 0);
774 for (item
= wv
->contents
; item
; item
= item
->next
)
776 char *utf8_label
= get_utf8_string (item
->value
);
780 if (item
->name
&& strcmp (item
->name
, "message") == 0)
782 /* This is the text part of the dialog. */
783 w
= gtk_label_new (utf8_label
);
784 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (wdialog
)->vbox
),
787 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (wdialog
)->vbox
), w
,
789 gtk_misc_set_alignment (GTK_MISC (w
), 0.1, 0.5);
791 /* Try to make dialog look better. Must realize first so
792 the widget can calculate the size it needs. */
793 gtk_widget_realize (w
);
794 gtk_widget_size_request (w
, &req
);
795 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (wdialog
)->vbox
),
797 if (item
->value
&& strlen (item
->value
) > 0)
798 button_spacing
= 2*req
.width
/strlen (item
->value
);
802 /* This is one button to add to the dialog. */
803 w
= gtk_button_new_with_mnemonic (utf8_label
);
805 gtk_widget_set_sensitive (w
, FALSE
);
807 g_signal_connect (G_OBJECT (w
), "clicked",
808 select_cb
, item
->call_data
);
810 gtk_box_pack_start (cur_box
, w
, TRUE
, TRUE
, button_spacing
);
811 if (++button_nr
== left_buttons
)
814 cur_box
= GTK_BOX (whbox_down
);
816 gtk_box_pack_start (cur_box
,
823 if (utf8_label
&& utf8_label
!= item
->value
)
839 /* Callback function invoked when the Ok button is pressed in
841 W is the file dialog widget,
842 ARG points to an integer where we record what has happend. */
844 xg_file_sel_ok (w
, arg
)
848 *(int*)arg
= XG_FILE_OK
;
851 /* Callback function invoked when the Cancel button is pressed in
853 W is the file dialog widget,
854 ARG points to an integer where we record what has happend. */
856 xg_file_sel_cancel (w
, arg
)
860 *(int*)arg
= XG_FILE_CANCEL
;
863 /* Callback function invoked when the file dialog is destroyed (i.e.
864 popped down). We must keep track of this, because if this
865 happens, GTK destroys the widget. But if for example, Ok is pressed,
866 the dialog is popped down, but the dialog widget is not destroyed.
867 W is the file dialog widget,
868 ARG points to an integer where we record what has happend. */
870 xg_file_sel_destroy (w
, arg
)
874 *(int*)arg
= XG_FILE_DESTROYED
;
877 /* Read a file name from the user using a file dialog.
878 F is the current frame.
879 PROMPT is a prompt to show to the user. May not be NULL.
880 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
881 If MUSTMATCH_P is non-zero, the returned file name must be an existing
884 Returns a file name or NULL if no file was selected.
885 The returned string must be freed by the caller. */
887 xg_get_file_name (f
, prompt
, default_filename
, mustmatch_p
)
890 char *default_filename
;
894 GtkFileSelection
*filesel
;
895 int filesel_done
= XG_FILE_NOT_DONE
;
898 filewin
= gtk_file_selection_new (prompt
);
899 filesel
= GTK_FILE_SELECTION (filewin
);
901 gtk_widget_set_name (filewin
, "emacs-filedialog");
903 gtk_window_set_transient_for (GTK_WINDOW (filewin
),
904 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
905 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin
), TRUE
);
907 g_signal_connect (G_OBJECT (filesel
->ok_button
),
909 G_CALLBACK (xg_file_sel_ok
),
911 g_signal_connect (G_OBJECT (filesel
->cancel_button
),
913 G_CALLBACK (xg_file_sel_cancel
),
915 g_signal_connect (G_OBJECT (filesel
),
917 G_CALLBACK (xg_file_sel_destroy
),
920 if (default_filename
)
921 gtk_file_selection_set_filename (filesel
, default_filename
);
925 /* The selection_entry part of filesel is not documented. */
926 gtk_widget_set_sensitive (filesel
->selection_entry
, FALSE
);
927 gtk_file_selection_hide_fileop_buttons (filesel
);
931 gtk_widget_show_all (filewin
);
933 while (filesel_done
== XG_FILE_NOT_DONE
)
934 gtk_main_iteration ();
936 if (filesel_done
== XG_FILE_OK
)
937 fn
= xstrdup ((char*) gtk_file_selection_get_filename (filesel
));
939 if (filesel_done
!= XG_FILE_DESTROYED
)
940 gtk_widget_destroy (filewin
);
946 /***********************************************************************
948 ***********************************************************************/
950 /* The name of menu items that can be used for citomization. Since GTK
951 RC files are very crude and primitive, we have to set this on all
952 menu item names so a user can easily cutomize menu items. */
954 #define MENU_ITEM_NAME "emacs-menuitem"
957 /* Linked list of all allocated struct xg_menu_cb_data. Used for marking
958 during GC. The next member points to the items. */
959 static xg_list_node xg_menu_cb_list
;
961 /* Linked list of all allocated struct xg_menu_item_cb_data. Used for marking
962 during GC. The next member points to the items. */
963 static xg_list_node xg_menu_item_cb_list
;
965 /* Allocate and initialize CL_DATA if NULL, otherwise increase ref_count.
966 F is the frame CL_DATA will be initialized for.
967 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
969 The menu bar and all sub menus under the menu bar in a frame
970 share the same structure, hence the reference count.
972 Returns CL_DATA if CL_DATA is not NULL, or a pointer to a newly
973 allocated xg_menu_cb_data if CL_DATA is NULL. */
974 static xg_menu_cb_data
*
975 make_cl_data (cl_data
, f
, highlight_cb
)
976 xg_menu_cb_data
*cl_data
;
978 GCallback highlight_cb
;
982 cl_data
= (xg_menu_cb_data
*) xmalloc (sizeof (*cl_data
));
984 cl_data
->menu_bar_vector
= f
->menu_bar_vector
;
985 cl_data
->menu_bar_items_used
= f
->menu_bar_items_used
;
986 cl_data
->highlight_cb
= highlight_cb
;
987 cl_data
->ref_count
= 0;
989 xg_list_insert (&xg_menu_cb_list
, &cl_data
->ptrs
);
992 cl_data
->ref_count
++;
997 /* Update CL_DATA with values from frame F and with HIGHLIGHT_CB.
998 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1000 When the menu bar is updated, menu items may have been added and/or
1001 removed, so menu_bar_vector and menu_bar_items_used change. We must
1002 then update CL_DATA since it is used to determine which menu
1003 item that is invoked in the menu.
1004 HIGHLIGHT_CB could change, there is no check that the same
1005 function is given when modifying a menu bar as was given when
1006 creating the menu bar. */
1008 update_cl_data (cl_data
, f
, highlight_cb
)
1009 xg_menu_cb_data
*cl_data
;
1011 GCallback highlight_cb
;
1016 cl_data
->menu_bar_vector
= f
->menu_bar_vector
;
1017 cl_data
->menu_bar_items_used
= f
->menu_bar_items_used
;
1018 cl_data
->highlight_cb
= highlight_cb
;
1022 /* Decrease reference count for CL_DATA.
1023 If reference count is zero, free CL_DATA. */
1025 unref_cl_data (cl_data
)
1026 xg_menu_cb_data
*cl_data
;
1028 if (cl_data
&& cl_data
->ref_count
> 0)
1030 cl_data
->ref_count
--;
1031 if (cl_data
->ref_count
== 0)
1033 xg_list_remove (&xg_menu_cb_list
, &cl_data
->ptrs
);
1039 /* Function that marks all lisp data during GC. */
1045 for (iter
= xg_menu_cb_list
.next
; iter
; iter
= iter
->next
)
1046 mark_object (&((xg_menu_cb_data
*) iter
)->menu_bar_vector
);
1048 for (iter
= xg_menu_item_cb_list
.next
; iter
; iter
= iter
->next
)
1050 xg_menu_item_cb_data
*cb_data
= (xg_menu_item_cb_data
*) iter
;
1052 if (! NILP (cb_data
->help
))
1053 mark_object (&cb_data
->help
);
1058 /* Callback called when a menu item is destroyed. Used to free data.
1059 W is the widget that is being destroyed (not used).
1060 CLIENT_DATA points to the xg_menu_item_cb_data associated with the W. */
1062 menuitem_destroy_callback (w
, client_data
)
1064 gpointer client_data
;
1068 xg_menu_item_cb_data
*data
= (xg_menu_item_cb_data
*) client_data
;
1069 xg_list_remove (&xg_menu_item_cb_list
, &data
->ptrs
);
1074 /* Callback called when the pointer enters/leaves a menu item.
1076 EVENT is either an enter event or leave event.
1077 CLIENT_DATA points to the xg_menu_item_cb_data associated with the W.
1079 Returns FALSE to tell GTK to keep processing this event. */
1081 menuitem_highlight_callback (w
, event
, client_data
)
1083 GdkEventCrossing
*event
;
1084 gpointer client_data
;
1088 xg_menu_item_cb_data
*data
= (xg_menu_item_cb_data
*) client_data
;
1089 gpointer call_data
= event
->type
== GDK_LEAVE_NOTIFY
? 0 : client_data
;
1091 if (! NILP (data
->help
) && data
->cl_data
->highlight_cb
)
1093 GtkCallback func
= (GtkCallback
) data
->cl_data
->highlight_cb
;
1094 (*func
) (w
, call_data
);
1101 /* Callback called when a menu is destroyed. Used to free data.
1102 W is the widget that is being destroyed (not used).
1103 CLIENT_DATA points to the xg_menu_cb_data associated with W. */
1105 menu_destroy_callback (w
, client_data
)
1107 gpointer client_data
;
1109 unref_cl_data ((xg_menu_cb_data
*) client_data
);
1112 /* Callback called when a menu does a grab or ungrab. That means the
1113 menu has been activated or deactivated.
1114 Used to start a timer so the small timeout the menus in GTK uses before
1115 popping down a menu is seen by Emacs (see xg_process_timeouts above).
1116 W is the widget that does the grab (not used).
1117 UNGRAB_P is TRUE if this is an ungrab, FALSE if it is a grab.
1118 CLIENT_DATA is NULL (not used). */
1120 menu_grab_callback (GtkWidget
*widget
,
1122 gpointer client_data
)
1124 /* Keep track of total number of grabs. */
1127 if (ungrab_p
) cnt
--;
1130 if (cnt
> 0 && ! xg_timer
) xg_start_timer ();
1131 else if (cnt
== 0 && xg_timer
) xg_stop_timer ();
1134 /* Make a GTK widget that contains both UTF8_LABEL and UTF8_KEY (both
1135 must be non-NULL) and can be inserted into a menu item.
1137 Returns the GtkHBox. */
1139 make_widget_for_menu_item (utf8_label
, utf8_key
)
1147 wbox
= gtk_hbox_new (FALSE
, 0);
1148 wlbl
= gtk_label_new_with_mnemonic (utf8_label
);
1149 wkey
= gtk_label_new (utf8_key
);
1151 gtk_misc_set_alignment (GTK_MISC (wlbl
), 0.0, 0.5);
1152 gtk_misc_set_alignment (GTK_MISC (wkey
), 0.0, 0.5);
1154 gtk_box_pack_start (GTK_BOX (wbox
), wlbl
, TRUE
, TRUE
, 0);
1155 gtk_box_pack_start (GTK_BOX (wbox
), wkey
, FALSE
, FALSE
, 0);
1157 gtk_widget_set_name (wlbl
, MENU_ITEM_NAME
);
1158 gtk_widget_set_name (wkey
, MENU_ITEM_NAME
);
1163 /* Make and return a menu item widget with the key to the right.
1164 UTF8_LABEL is the text for the menu item (GTK uses UTF8 internally).
1165 UTF8_KEY is the text representing the key binding.
1166 ITEM is the widget_value describing the menu item.
1168 GROUP is an in/out parameter. If the menu item to be created is not
1169 part of any radio menu group, *GROUP contains NULL on entry and exit.
1170 If the menu item to be created is part of a radio menu group, on entry
1171 *GROUP contains the group to use, or NULL if this is the first item
1172 in the group. On exit, *GROUP contains the radio item group.
1174 Unfortunately, keys don't line up as nicely as in Motif,
1175 but the MacOS X version doesn't either, so I guess that is OK. */
1177 make_menu_item (utf8_label
, utf8_key
, item
, group
)
1184 GtkWidget
*wtoadd
= 0;
1187 wtoadd
= make_widget_for_menu_item (utf8_label
, utf8_key
);
1189 if (item
->button_type
== BUTTON_TYPE_TOGGLE
)
1192 if (utf8_key
) w
= gtk_check_menu_item_new ();
1193 else w
= gtk_check_menu_item_new_with_mnemonic (utf8_label
);
1194 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), item
->selected
);
1196 else if (item
->button_type
== BUTTON_TYPE_RADIO
)
1198 if (utf8_key
) w
= gtk_radio_menu_item_new (*group
);
1199 else w
= gtk_radio_menu_item_new_with_mnemonic (*group
, utf8_label
);
1200 *group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (w
));
1202 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), TRUE
);
1207 if (utf8_key
) w
= gtk_menu_item_new ();
1208 else w
= gtk_menu_item_new_with_mnemonic (utf8_label
);
1211 if (wtoadd
) gtk_container_add (GTK_CONTAINER (w
), wtoadd
);
1212 if (! item
->enabled
) gtk_widget_set_sensitive (w
, FALSE
);
1217 /* Return non-zero if NAME specifies a separator (GTK only has one
1220 xg_separator_p (char *name
)
1222 if (! name
) return 0;
1224 return strcmp (name
, "--") == 0
1225 || strncmp (name
, "--:", 3) == 0
1226 || strcmp (name
, "---") == 0;
1229 GtkWidget
*xg_did_tearoff
;
1231 /* Callback invoked when a detached menu window is removed. Here we
1232 delete the popup menu.
1233 WIDGET is the top level window that is removed (the parent of the menu).
1234 EVENT is the event that triggers the window removal.
1235 CLIENT_DATA points to the menu that is detached.
1237 Returns TRUE to tell GTK to stop processing this event. */
1239 tearoff_remove (widget
, event
, client_data
)
1242 gpointer client_data
;
1244 gtk_widget_destroy (GTK_WIDGET (client_data
));
1248 /* Callback invoked when a menu is detached. It sets the xg_did_tearoff
1250 WIDGET is the GtkTearoffMenuItem.
1251 CLIENT_DATA is not used. */
1253 tearoff_activate (widget
, client_data
)
1255 gpointer client_data
;
1257 GtkWidget
*menu
= gtk_widget_get_parent (widget
);
1258 if (! gtk_menu_get_tearoff_state (GTK_MENU (menu
)))
1261 xg_did_tearoff
= menu
;
1264 /* If a detach of a popup menu is done, this function should be called
1265 to keep the menu around until the detached window is removed.
1266 MENU is the top level menu for the popup,
1267 SUBMENU is the menu that got detached (that is MENU or a
1268 submenu of MENU), see the xg_did_tearoff variable. */
1270 xg_keep_popup (menu
, submenu
)
1276 /* Find the top widget for the detached menu. */
1277 p
= gtk_widget_get_toplevel (submenu
);
1279 /* Delay destroying the menu until the detached menu is removed. */
1280 g_signal_connect (G_OBJECT (p
), "unmap_event",
1281 G_CALLBACK (tearoff_remove
), menu
);
1286 /* Create a menu item widget, and connect the callbacks.
1287 ITEM decribes the menu item.
1288 F is the frame the created menu belongs to.
1289 SELECT_CB is the callback to use when a menu item is selected.
1290 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1291 CL_DATA points to the callback data to be used for this menu.
1292 GROUP is an in/out parameter. If the menu item to be created is not
1293 part of any radio menu group, *GROUP contains NULL on entry and exit.
1294 If the menu item to be created is part of a radio menu group, on entry
1295 *GROUP contains the group to use, or NULL if this is the first item
1296 in the group. On exit, *GROUP contains the radio item group.
1298 Returns the created GtkWidget. */
1300 xg_create_one_menuitem (item
, f
, select_cb
, highlight_cb
, cl_data
, group
)
1303 GCallback select_cb
;
1304 GCallback highlight_cb
;
1305 xg_menu_cb_data
*cl_data
;
1311 xg_menu_item_cb_data
*cb_data
;
1313 utf8_label
= get_utf8_string (item
->name
);
1314 utf8_key
= get_utf8_string (item
->key
);
1316 w
= make_menu_item (utf8_label
, utf8_key
, item
, group
);
1318 if (utf8_label
&& utf8_label
!= item
->name
) g_free (utf8_label
);
1319 if (utf8_key
&& utf8_key
!= item
->key
) g_free (utf8_key
);
1321 cb_data
= xmalloc (sizeof (xg_menu_item_cb_data
));
1323 xg_list_insert (&xg_menu_item_cb_list
, &cb_data
->ptrs
);
1325 cb_data
->unhighlight_id
= cb_data
->highlight_id
= cb_data
->select_id
= 0;
1326 cb_data
->help
= item
->help
;
1327 cb_data
->cl_data
= cl_data
;
1328 cb_data
->call_data
= item
->call_data
;
1330 g_signal_connect (G_OBJECT (w
),
1332 G_CALLBACK (menuitem_destroy_callback
),
1335 /* Put cb_data in widget, so we can get at it when modifying menubar */
1336 g_object_set_data (G_OBJECT (w
), XG_ITEM_DATA
, cb_data
);
1338 /* final item, not a submenu */
1339 if (item
->call_data
&& ! item
->contents
)
1343 = g_signal_connect (G_OBJECT (w
), "activate", select_cb
, cb_data
);
1346 if (! NILP (item
->help
) && highlight_cb
)
1348 /* We use enter/leave notify instead of select/deselect because
1349 select/deselect doesn't go well with detached menus. */
1350 cb_data
->highlight_id
1351 = g_signal_connect (G_OBJECT (w
),
1352 "enter-notify-event",
1353 G_CALLBACK (menuitem_highlight_callback
),
1355 cb_data
->unhighlight_id
1356 = g_signal_connect (G_OBJECT (w
),
1357 "leave-notify-event",
1358 G_CALLBACK (menuitem_highlight_callback
),
1365 static GtkWidget
*create_menus
P_ ((widget_value
*, FRAME_PTR
, GCallback
,
1366 GCallback
, GCallback
, int, int, int,
1367 GtkWidget
*, xg_menu_cb_data
*, char *));
1369 /* Create a full menu tree specified by DATA.
1370 F is the frame the created menu belongs to.
1371 SELECT_CB is the callback to use when a menu item is selected.
1372 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
1373 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1374 POP_UP_P is non-zero if we shall create a popup menu.
1375 MENU_BAR_P is non-zero if we shall create a menu bar.
1376 ADD_TEAROFF_P is non-zero if we shall add a teroff menu item. Ignored
1377 if MENU_BAR_P is non-zero.
1378 TOPMENU is the topmost GtkWidget that others shall be placed under.
1379 It may be NULL, in that case we create the appropriate widget
1380 (menu bar or menu item depending on POP_UP_P and MENU_BAR_P)
1381 CL_DATA is the callback data we shall use for this menu, or NULL
1382 if we haven't set the first callback yet.
1383 NAME is the name to give to the top level menu if this function
1384 creates it. May be NULL to not set any name.
1386 Returns the top level GtkWidget. This is TOPLEVEL if TOPLEVEL is
1389 This function calls itself to create submenus. */
1392 create_menus (data
, f
, select_cb
, deactivate_cb
, highlight_cb
,
1393 pop_up_p
, menu_bar_p
, add_tearoff_p
, topmenu
, cl_data
, name
)
1396 GCallback select_cb
;
1397 GCallback deactivate_cb
;
1398 GCallback highlight_cb
;
1403 xg_menu_cb_data
*cl_data
;
1407 GtkWidget
*wmenu
= topmenu
;
1408 GSList
*group
= NULL
;
1412 if (! menu_bar_p
) wmenu
= gtk_menu_new ();
1413 else wmenu
= gtk_menu_bar_new ();
1415 /* Put cl_data on the top menu for easier access. */
1416 cl_data
= make_cl_data (cl_data
, f
, highlight_cb
);
1417 g_object_set_data (G_OBJECT (wmenu
), XG_FRAME_DATA
, (gpointer
)cl_data
);
1418 g_signal_connect (G_OBJECT (wmenu
), "destroy",
1419 G_CALLBACK (menu_destroy_callback
), cl_data
);
1422 gtk_widget_set_name (wmenu
, name
);
1425 g_signal_connect (G_OBJECT (wmenu
),
1426 "deactivate", deactivate_cb
, 0);
1428 g_signal_connect (G_OBJECT (wmenu
),
1429 "grab-notify", G_CALLBACK (menu_grab_callback
), 0);
1432 if (! menu_bar_p
&& add_tearoff_p
)
1434 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new ();
1435 gtk_menu_shell_append (GTK_MENU_SHELL (wmenu
), tearoff
);
1437 g_signal_connect (G_OBJECT (tearoff
), "activate",
1438 G_CALLBACK (tearoff_activate
), 0);
1441 for (item
= data
; item
; item
= item
->next
)
1445 if (pop_up_p
&& !item
->contents
&& !item
->call_data
1446 && !xg_separator_p (item
->name
))
1449 /* A title for a popup. We do the same as GTK does when
1450 creating titles, but it does not look good. */
1452 utf8_label
= get_utf8_string (item
->name
);
1454 gtk_menu_set_title (GTK_MENU (wmenu
), utf8_label
);
1455 w
= gtk_menu_item_new_with_mnemonic (utf8_label
);
1456 gtk_widget_set_sensitive (w
, FALSE
);
1457 if (utf8_label
&& utf8_label
!= item
->name
) g_free (utf8_label
);
1459 else if (xg_separator_p (item
->name
))
1462 /* GTK only have one separator type. */
1463 w
= gtk_separator_menu_item_new ();
1467 w
= xg_create_one_menuitem (item
,
1469 item
->contents
? 0 : select_cb
,
1476 GtkWidget
*submenu
= create_menus (item
->contents
,
1487 gtk_menu_item_set_submenu (GTK_MENU_ITEM (w
), submenu
);
1491 gtk_menu_shell_append (GTK_MENU_SHELL (wmenu
), w
);
1492 gtk_widget_set_name (w
, MENU_ITEM_NAME
);
1498 /* Create a menubar, popup menu or dialog, depending on the TYPE argument.
1499 TYPE can be "menubar", "popup" for popup menu, or "dialog" for a dialog
1500 with some text and buttons.
1501 F is the frame the created item belongs to.
1502 NAME is the name to use for the top widget.
1503 VAL is a widget_value structure describing items to be created.
1504 SELECT_CB is the callback to use when a menu item is selected or
1505 a dialog button is pressed.
1506 DEACTIVATE_CB is the callback to use when an item is deactivated.
1507 For a menu, when a sub menu is not shown anymore, for a dialog it is
1508 called when the dialog is popped down.
1509 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1511 Returns the widget created. */
1513 xg_create_widget (type
, name
, f
, val
,
1514 select_cb
, deactivate_cb
, highlight_cb
)
1519 GCallback select_cb
;
1520 GCallback deactivate_cb
;
1521 GCallback highlight_cb
;
1524 if (strcmp (type
, "dialog") == 0)
1526 w
= create_dialog (val
, select_cb
, deactivate_cb
);
1527 gtk_window_set_transient_for (GTK_WINDOW (w
),
1528 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
1529 gtk_window_set_destroy_with_parent (GTK_WINDOW (w
), TRUE
);
1532 gtk_widget_set_name (w
, "emacs-dialog");
1534 else if (strcmp (type
, "menubar") == 0 || strcmp (type
, "popup") == 0)
1536 w
= create_menus (val
->contents
,
1541 strcmp (type
, "popup") == 0,
1542 strcmp (type
, "menubar") == 0,
1548 /* Set the cursor to an arrow for popup menus when they are mapped.
1549 This is done by default for menu bar menus. */
1550 if (strcmp (type
, "popup") == 0)
1552 /* Must realize so the GdkWindow inside the widget is created. */
1553 gtk_widget_realize (w
);
1554 xg_set_cursor (w
, &xg_left_ptr_cursor
);
1559 fprintf (stderr
, "bad type in xg_create_widget: %s, doing nothing\n",
1566 /* Return the label for menu item WITEM. */
1568 xg_get_menu_item_label (witem
)
1571 GtkLabel
*wlabel
= GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem
)));
1572 return gtk_label_get_label (wlabel
);
1575 /* Return non-zero if the menu item WITEM has the text LABEL. */
1577 xg_item_label_same_p (witem
, label
)
1582 char *utf8_label
= get_utf8_string (label
);
1583 const char *old_label
= witem
? xg_get_menu_item_label (witem
) : 0;
1585 if (! old_label
&& ! utf8_label
)
1587 else if (old_label
&& utf8_label
)
1588 is_same
= strcmp (utf8_label
, old_label
) == 0;
1590 if (utf8_label
&& utf8_label
!= label
) g_free (utf8_label
);
1595 /* Remove widgets in LIST from container WCONT. */
1597 remove_from_container (wcont
, list
)
1603 for (iter
= list
; iter
; iter
= g_list_next (iter
))
1605 GtkWidget
*w
= GTK_WIDGET (iter
->data
);
1607 /* Add a ref to w so we can explicitly destroy it later. */
1609 gtk_container_remove (GTK_CONTAINER (wcont
), w
);
1611 /* If there is a menu under this widget that has been detached,
1612 there is a reference to it, and just removing w from the
1613 container does not destroy the submenu. By explicitly
1614 destroying w we make sure the submenu is destroyed, thus
1615 removing the detached window also if there was one. */
1616 gtk_widget_destroy (w
);
1620 /* Update the top level names in MENUBAR (i.e. not submenus).
1621 F is the frame the menu bar belongs to.
1622 *LIST is a list with the current menu bar names (menu item widgets).
1623 ITER is the item within *LIST that shall be updated.
1624 POS is the numerical position, starting at 0, of ITER in *LIST.
1625 VAL describes what the menu bar shall look like after the update.
1626 SELECT_CB is the callback to use when a menu item is selected.
1627 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1628 CL_DATA points to the callback data to be used for this menu bar.
1630 This function calls itself to walk through the menu bar names. */
1632 xg_update_menubar (menubar
, f
, list
, iter
, pos
, val
,
1633 select_cb
, highlight_cb
, cl_data
)
1640 GCallback select_cb
;
1641 GCallback highlight_cb
;
1642 xg_menu_cb_data
*cl_data
;
1644 if (! iter
&& ! val
)
1646 else if (iter
&& ! val
)
1648 /* Item(s) have been removed. Remove all remaining items. */
1649 remove_from_container (menubar
, iter
);
1655 else if (! iter
&& val
)
1657 /* Item(s) added. Add all new items in one call. */
1658 create_menus (val
, f
, select_cb
, 0, highlight_cb
,
1659 0, 1, 0, menubar
, cl_data
, 0);
1665 /* Below this neither iter or val is NULL */
1666 else if (xg_item_label_same_p (GTK_MENU_ITEM (iter
->data
), val
->name
))
1668 /* This item is still the same, check next item. */
1670 iter
= g_list_next (iter
);
1673 else /* This item is changed. */
1675 GtkMenuItem
*witem
= GTK_MENU_ITEM (iter
->data
);
1676 GtkMenuItem
*witem2
= 0;
1677 int val_in_menubar
= 0;
1678 int iter_in_new_menubar
= 0;
1682 /* See if the changed entry (val) is present later in the menu bar */
1684 iter2
&& ! val_in_menubar
;
1685 iter2
= g_list_next (iter2
))
1687 witem2
= GTK_MENU_ITEM (iter2
->data
);
1688 val_in_menubar
= xg_item_label_same_p (witem2
, val
->name
);
1691 /* See if the current entry (iter) is present later in the
1692 specification for the new menu bar. */
1693 for (cur
= val
; cur
&& ! iter_in_new_menubar
; cur
= cur
->next
)
1694 iter_in_new_menubar
= xg_item_label_same_p (witem
, cur
->name
);
1696 if (val_in_menubar
&& ! iter_in_new_menubar
)
1700 /* This corresponds to:
1705 gtk_widget_ref (GTK_WIDGET (witem
));
1706 gtk_container_remove (GTK_CONTAINER (menubar
), GTK_WIDGET (witem
));
1707 gtk_widget_destroy (GTK_WIDGET (witem
));
1709 /* Must get new list since the old changed. */
1710 g_list_free (*list
);
1711 *list
= iter
= gtk_container_get_children (GTK_CONTAINER (menubar
));
1712 while (nr
-- > 0) iter
= g_list_next (iter
);
1714 else if (! val_in_menubar
&& ! iter_in_new_menubar
)
1716 /* This corresponds to:
1719 Rename B to X. This might seem to be a strange thing to do,
1720 since if there is a menu under B it will be totally wrong for X.
1721 But consider editing a C file. Then there is a C-mode menu
1722 (corresponds to B above).
1723 If then doing C-x C-f the minibuf menu (X above) replaces the
1724 C-mode menu. When returning from the minibuffer, we get
1725 back the C-mode menu. Thus we do:
1726 Rename B to X (C-mode to minibuf menu)
1727 Rename X to B (minibuf to C-mode menu).
1728 If the X menu hasn't been invoked, the menu under B
1729 is up to date when leaving the minibuffer. */
1730 GtkLabel
*wlabel
= GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem
)));
1731 char *utf8_label
= get_utf8_string (val
->name
);
1733 gtk_label_set_text_with_mnemonic (wlabel
, utf8_label
);
1735 iter
= g_list_next (iter
);
1739 else if (! val_in_menubar
&& iter_in_new_menubar
)
1741 /* This corresponds to:
1748 GtkWidget
*w
= xg_create_one_menuitem (val
,
1755 gtk_widget_set_name (w
, MENU_ITEM_NAME
);
1756 gtk_menu_shell_insert (GTK_MENU_SHELL (menubar
), w
, pos
);
1758 g_list_free (*list
);
1759 *list
= iter
= gtk_container_get_children (GTK_CONTAINER (menubar
));
1760 while (nr
-- > 0) iter
= g_list_next (iter
);
1761 iter
= g_list_next (iter
);
1765 else /* if (val_in_menubar && iter_in_new_menubar) */
1768 /* This corresponds to:
1773 gtk_widget_ref (GTK_WIDGET (witem2
));
1774 gtk_container_remove (GTK_CONTAINER (menubar
), GTK_WIDGET (witem2
));
1775 gtk_menu_shell_insert (GTK_MENU_SHELL (menubar
),
1776 GTK_WIDGET (witem2
), pos
);
1777 gtk_widget_unref (GTK_WIDGET (witem2
));
1779 g_list_free (*list
);
1780 *list
= iter
= gtk_container_get_children (GTK_CONTAINER (menubar
));
1781 while (nr
-- > 0) iter
= g_list_next (iter
);
1787 /* Update the rest of the menu bar. */
1788 xg_update_menubar (menubar
, f
, list
, iter
, pos
, val
,
1789 select_cb
, highlight_cb
, cl_data
);
1792 /* Update the menu item W so it corresponds to VAL.
1793 SELECT_CB is the callback to use when a menu item is selected.
1794 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1795 CL_DATA is the data to set in the widget for menu invokation. */
1797 xg_update_menu_item (val
, w
, select_cb
, highlight_cb
, cl_data
)
1800 GCallback select_cb
;
1801 GCallback highlight_cb
;
1802 xg_menu_cb_data
*cl_data
;
1809 const char *old_label
= 0;
1810 const char *old_key
= 0;
1811 xg_menu_item_cb_data
*cb_data
;
1813 wchild
= gtk_bin_get_child (GTK_BIN (w
));
1814 utf8_label
= get_utf8_string (val
->name
);
1815 utf8_key
= get_utf8_string (val
->key
);
1817 /* See if W is a menu item with a key. See make_menu_item above. */
1818 if (GTK_IS_HBOX (wchild
))
1820 GList
*list
= gtk_container_get_children (GTK_CONTAINER (wchild
));
1822 wlbl
= GTK_LABEL (list
->data
);
1823 wkey
= GTK_LABEL (list
->next
->data
);
1828 /* Remove the key and keep just the label. */
1829 gtk_widget_ref (GTK_WIDGET (wlbl
));
1830 gtk_container_remove (GTK_CONTAINER (w
), wchild
);
1831 gtk_container_add (GTK_CONTAINER (w
), GTK_WIDGET (wlbl
));
1836 else /* Just a label. */
1838 wlbl
= GTK_LABEL (wchild
);
1840 /* Check if there is now a key. */
1843 GtkWidget
*wtoadd
= make_widget_for_menu_item (utf8_label
, utf8_key
);
1844 GList
*list
= gtk_container_get_children (GTK_CONTAINER (wtoadd
));
1846 wlbl
= GTK_LABEL (list
->data
);
1847 wkey
= GTK_LABEL (list
->next
->data
);
1850 gtk_container_remove (GTK_CONTAINER (w
), wchild
);
1851 gtk_container_add (GTK_CONTAINER (w
), wtoadd
);
1856 if (wkey
) old_key
= gtk_label_get_label (wkey
);
1857 if (wlbl
) old_label
= gtk_label_get_label (wlbl
);
1859 if (wkey
&& utf8_key
&& (! old_key
|| strcmp (utf8_key
, old_key
) != 0))
1860 gtk_label_set_text (wkey
, utf8_key
);
1862 if (! old_label
|| strcmp (utf8_label
, old_label
) != 0)
1863 gtk_label_set_text_with_mnemonic (wlbl
, utf8_label
);
1865 if (utf8_key
&& utf8_key
!= val
->key
) g_free (utf8_key
);
1866 if (utf8_label
&& utf8_label
!= val
->name
) g_free (utf8_label
);
1868 if (! val
->enabled
&& GTK_WIDGET_SENSITIVE (w
))
1869 gtk_widget_set_sensitive (w
, FALSE
);
1870 else if (val
->enabled
&& ! GTK_WIDGET_SENSITIVE (w
))
1871 gtk_widget_set_sensitive (w
, TRUE
);
1873 cb_data
= (xg_menu_item_cb_data
*) g_object_get_data (G_OBJECT (w
),
1877 cb_data
->call_data
= val
->call_data
;
1878 cb_data
->help
= val
->help
;
1879 cb_data
->cl_data
= cl_data
;
1881 /* We assume the callback functions don't change. */
1882 if (val
->call_data
&& ! val
->contents
)
1884 /* This item shall have a select callback. */
1885 if (! cb_data
->select_id
)
1887 = g_signal_connect (G_OBJECT (w
), "activate",
1888 select_cb
, cb_data
);
1890 else if (cb_data
->select_id
)
1892 g_signal_handler_disconnect (w
, cb_data
->select_id
);
1893 cb_data
->select_id
= 0;
1896 if (NILP (cb_data
->help
))
1898 /* Shall not have help. Remove if any existed previously. */
1899 if (cb_data
->highlight_id
)
1901 g_signal_handler_disconnect (G_OBJECT (w
),
1902 cb_data
->highlight_id
);
1903 cb_data
->highlight_id
= 0;
1905 if (cb_data
->unhighlight_id
)
1907 g_signal_handler_disconnect (G_OBJECT (w
),
1908 cb_data
->unhighlight_id
);
1909 cb_data
->unhighlight_id
= 0;
1912 else if (! cb_data
->highlight_id
&& highlight_cb
)
1914 /* Have help now, but didn't previously. Add callback. */
1915 cb_data
->highlight_id
1916 = g_signal_connect (G_OBJECT (w
),
1917 "enter-notify-event",
1918 G_CALLBACK (menuitem_highlight_callback
),
1920 cb_data
->unhighlight_id
1921 = g_signal_connect (G_OBJECT (w
),
1922 "leave-notify-event",
1923 G_CALLBACK (menuitem_highlight_callback
),
1929 /* Update the toggle menu item W so it corresponds to VAL. */
1931 xg_update_toggle_item (val
, w
)
1935 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), val
->selected
);
1938 /* Update the radio menu item W so it corresponds to VAL. */
1940 xg_update_radio_item (val
, w
)
1944 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), val
->selected
);
1947 /* Update the sub menu SUBMENU and all its children so it corresponds to VAL.
1948 SUBMENU may be NULL, in that case a new menu is created.
1949 F is the frame the menu bar belongs to.
1950 VAL describes the contents of the menu bar.
1951 SELECT_CB is the callback to use when a menu item is selected.
1952 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
1953 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1954 CL_DATA is the call back data to use for any newly created items.
1956 Returns the updated submenu widget, that is SUBMENU unless SUBMENU
1960 xg_update_submenu (submenu
, f
, val
,
1961 select_cb
, deactivate_cb
, highlight_cb
, cl_data
)
1965 GCallback select_cb
;
1966 GCallback deactivate_cb
;
1967 GCallback highlight_cb
;
1968 xg_menu_cb_data
*cl_data
;
1970 GtkWidget
*newsub
= submenu
;
1974 int has_tearoff_p
= 0;
1975 GList
*first_radio
= 0;
1978 list
= gtk_container_get_children (GTK_CONTAINER (submenu
));
1980 for (cur
= val
, iter
= list
;
1982 iter
= g_list_next (iter
), cur
= cur
->next
)
1984 GtkWidget
*w
= GTK_WIDGET (iter
->data
);
1986 /* Skip tearoff items, they have no counterpart in val. */
1987 if (GTK_IS_TEAROFF_MENU_ITEM (w
))
1990 iter
= g_list_next (iter
);
1991 if (iter
) w
= GTK_WIDGET (iter
->data
);
1995 /* Remember first radio button in a group. If we get a mismatch in
1996 a radio group we must rebuild the whole group so that the connections
1997 in GTK becomes correct. */
1998 if (cur
->button_type
== BUTTON_TYPE_RADIO
&& ! first_radio
)
2000 else if (cur
->button_type
!= BUTTON_TYPE_RADIO
2001 && ! GTK_IS_RADIO_MENU_ITEM (w
))
2004 if (GTK_IS_SEPARATOR_MENU_ITEM (w
))
2006 if (! xg_separator_p (cur
->name
))
2009 else if (GTK_IS_CHECK_MENU_ITEM (w
))
2011 if (cur
->button_type
!= BUTTON_TYPE_TOGGLE
)
2013 xg_update_toggle_item (cur
, w
);
2014 xg_update_menu_item (cur
, w
, select_cb
, highlight_cb
, cl_data
);
2016 else if (GTK_IS_RADIO_MENU_ITEM (w
))
2018 if (cur
->button_type
!= BUTTON_TYPE_RADIO
)
2020 xg_update_radio_item (cur
, w
);
2021 xg_update_menu_item (cur
, w
, select_cb
, highlight_cb
, cl_data
);
2023 else if (GTK_IS_MENU_ITEM (w
))
2025 GtkMenuItem
*witem
= GTK_MENU_ITEM (w
);
2028 if (cur
->button_type
!= BUTTON_TYPE_NONE
||
2029 xg_separator_p (cur
->name
))
2032 xg_update_menu_item (cur
, w
, select_cb
, highlight_cb
, cl_data
);
2034 sub
= gtk_menu_item_get_submenu (witem
);
2035 if (sub
&& ! cur
->contents
)
2037 /* Not a submenu anymore. */
2038 gtk_widget_ref (sub
);
2039 gtk_menu_item_remove_submenu (witem
);
2040 gtk_widget_destroy (sub
);
2042 else if (cur
->contents
)
2046 nsub
= xg_update_submenu (sub
, f
, cur
->contents
,
2047 select_cb
, deactivate_cb
,
2048 highlight_cb
, cl_data
);
2050 /* If this item just became a submenu, we must set it. */
2052 gtk_menu_item_set_submenu (witem
, nsub
);
2057 /* Structural difference. Remove everything from here and down
2063 /* Remove widgets from first structual change. */
2066 /* If we are adding new menu items below, we must remove from
2067 first radio button so that radio groups become correct. */
2068 if (cur
&& first_radio
) remove_from_container (submenu
, first_radio
);
2069 else remove_from_container (submenu
, iter
);
2074 /* More items added. Create them. */
2075 newsub
= create_menus (cur
,
2088 if (list
) g_list_free (list
);
2093 /* Update the MENUBAR.
2094 F is the frame the menu bar belongs to.
2095 VAL describes the contents of the menu bar.
2096 If DEEP_P is non-zero, rebuild all but the top level menu names in
2097 the MENUBAR. If DEEP_P is zero, just rebuild the names in the menubar.
2098 SELECT_CB is the callback to use when a menu item is selected.
2099 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
2100 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. */
2102 xg_modify_menubar_widgets (menubar
, f
, val
, deep_p
,
2103 select_cb
, deactivate_cb
, highlight_cb
)
2108 GCallback select_cb
;
2109 GCallback deactivate_cb
;
2110 GCallback highlight_cb
;
2112 xg_menu_cb_data
*cl_data
;
2113 GList
*list
= gtk_container_get_children (GTK_CONTAINER (menubar
));
2117 cl_data
= (xg_menu_cb_data
*) g_object_get_data (G_OBJECT (menubar
),
2122 widget_value
*cur
= val
->contents
;
2123 xg_update_menubar (menubar
, f
, &list
, list
, 0, cur
,
2124 select_cb
, highlight_cb
, cl_data
);
2130 /* Update all sub menus.
2131 We must keep the submenu names (GTK menu item widgets) since the
2132 X Window in the XEvent that activates the menu are those widgets. */
2134 /* Update cl_data, menu_item things in F may have changed. */
2135 update_cl_data (cl_data
, f
, highlight_cb
);
2137 for (cur
= val
->contents
; cur
; cur
= cur
->next
)
2144 /* Find sub menu that corresponds to val and update it. */
2145 for (iter
= list
; iter
; iter
= g_list_next (iter
))
2147 witem
= GTK_MENU_ITEM (iter
->data
);
2148 if (xg_item_label_same_p (witem
, cur
->name
))
2150 sub
= gtk_menu_item_get_submenu (witem
);
2155 newsub
= xg_update_submenu (sub
,
2162 /* sub may still be NULL. If we just updated non deep and added
2163 a new menu bar item, it has no sub menu yet. So we set the
2164 newly created sub menu under witem. */
2166 gtk_menu_item_set_submenu (witem
, newsub
);
2172 gtk_widget_show_all (menubar
);
2175 /* Recompute all the widgets of frame F, when the menu bar has been
2176 changed. Value is non-zero if widgets were updated. */
2179 xg_update_frame_menubar (f
)
2182 struct x_output
*x
= f
->output_data
.x
;
2185 if (!x
->menubar_widget
|| GTK_WIDGET_MAPPED (x
->menubar_widget
))
2190 gtk_box_pack_start (GTK_BOX (x
->vbox_widget
), x
->menubar_widget
,
2192 gtk_box_reorder_child (GTK_BOX (x
->vbox_widget
), x
->menubar_widget
, 0);
2194 gtk_widget_show_all (x
->menubar_widget
);
2195 gtk_widget_size_request (x
->menubar_widget
, &req
);
2197 FRAME_MENUBAR_HEIGHT (f
) = req
.height
;
2199 /* The height has changed, resize outer widget and set columns
2200 rows to what we had before adding the menu bar. */
2201 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2203 SET_FRAME_GARBAGED (f
);
2209 /* Get rid of the menu bar of frame F, and free its storage.
2210 This is used when deleting a frame, and when turning off the menu bar. */
2213 free_frame_menubar (f
)
2216 struct x_output
*x
= f
->output_data
.x
;
2218 if (x
->menubar_widget
)
2222 gtk_container_remove (GTK_CONTAINER (x
->vbox_widget
), x
->menubar_widget
);
2223 /* The menubar and its children shall be deleted when removed from
2225 x
->menubar_widget
= 0;
2226 FRAME_MENUBAR_HEIGHT (f
) = 0;
2228 /* The height has changed, resize outer widget and set columns
2229 rows to what we had before removing the menu bar. */
2230 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2232 SET_FRAME_GARBAGED (f
);
2239 /***********************************************************************
2240 Scroll bar functions
2241 ***********************************************************************/
2244 /* Setting scroll bar values invokes the callback. Use this variable
2245 to indicate that callback should do nothing. */
2246 int xg_ignore_gtk_scrollbar
;
2248 /* SET_SCROLL_BAR_X_WINDOW assumes the second argument fits in
2249 32 bits. But we want to store pointers, and they may be larger
2250 than 32 bits. Keep a mapping from integer index to widget pointers
2251 to get around the 32 bit limitation. */
2254 GtkWidget
**widgets
;
2259 /* Grow this much every time we need to allocate more */
2260 #define ID_TO_WIDGET_INCR 32
2262 /* Store the widget pointer W in id_to_widget and return the integer index. */
2264 xg_store_widget_in_map (w
)
2269 if (id_to_widget
.max_size
== id_to_widget
.used
)
2271 int new_size
= id_to_widget
.max_size
+ ID_TO_WIDGET_INCR
;
2273 id_to_widget
.widgets
= xrealloc (id_to_widget
.widgets
,
2274 sizeof (GtkWidget
*)*new_size
);
2276 for (i
= id_to_widget
.max_size
; i
< new_size
; ++i
)
2277 id_to_widget
.widgets
[i
] = 0;
2278 id_to_widget
.max_size
= new_size
;
2281 /* Just loop over the array and find a free place. After all,
2282 how many scroll bars are we creating? Should be a small number.
2283 The check above guarantees we will find a free place. */
2284 for (i
= 0; i
< id_to_widget
.max_size
; ++i
)
2286 if (! id_to_widget
.widgets
[i
])
2288 id_to_widget
.widgets
[i
] = w
;
2289 ++id_to_widget
.used
;
2295 /* Should never end up here */
2299 /* Remove pointer at IDX from id_to_widget.
2300 Called when scroll bar is destroyed. */
2302 xg_remove_widget_from_map (idx
)
2305 if (idx
< id_to_widget
.max_size
&& id_to_widget
.widgets
[idx
] != 0)
2307 id_to_widget
.widgets
[idx
] = 0;
2308 --id_to_widget
.used
;
2312 /* Get the widget pointer at IDX from id_to_widget. */
2314 xg_get_widget_from_map (idx
)
2317 if (idx
< id_to_widget
.max_size
&& id_to_widget
.widgets
[idx
] != 0)
2318 return id_to_widget
.widgets
[idx
];
2323 /* Return the scrollbar id for X Window WID.
2324 Return -1 if WID not in id_to_widget. */
2326 xg_get_scroll_id_for_window (wid
)
2332 w
= xg_win_to_widget (wid
);
2336 for (idx
= 0; idx
< id_to_widget
.max_size
; ++idx
)
2337 if (id_to_widget
.widgets
[idx
] == w
)
2344 /* Callback invoked when scroll bar WIDGET is destroyed.
2345 DATA is the index into id_to_widget for WIDGET.
2346 We free pointer to last scroll bar values here and remove the index. */
2348 xg_gtk_scroll_destroy (widget
, data
)
2355 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
2357 xg_remove_widget_from_map (id
);
2360 /* Callback for button press/release events. Used to start timer so that
2361 the scroll bar repetition timer in GTK gets handeled.
2362 Also, sets bar->dragging to Qnil when dragging (button release) is done.
2363 WIDGET is the scroll bar widget the event is for (not used).
2364 EVENT contains the event.
2365 USER_DATA points to the struct scrollbar structure.
2367 Returns FALSE to tell GTK that it shall continue propagate the event
2370 scroll_bar_button_cb (widget
, event
, user_data
)
2372 GdkEventButton
*event
;
2375 if (event
->type
== GDK_BUTTON_PRESS
&& ! xg_timer
)
2377 else if (event
->type
== GDK_BUTTON_RELEASE
)
2379 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
2380 if (xg_timer
) xg_stop_timer ();
2381 bar
->dragging
= Qnil
;
2387 /* Create a scroll bar widget for frame F. Store the scroll bar
2389 SCROLL_CALLBACK is the callback to invoke when the value of the
2391 SCROLL_BAR_NAME is the name we use for the scroll bar. Can be used
2392 to set resources for the widget. */
2394 xg_create_scroll_bar (f
, bar
, scroll_callback
, scroll_bar_name
)
2396 struct scroll_bar
*bar
;
2397 GCallback scroll_callback
;
2398 char *scroll_bar_name
;
2404 /* Page, step increment values are not so important here, they
2405 will be corrected in x_set_toolkit_scroll_bar_thumb. */
2406 vadj
= gtk_adjustment_new (XG_SB_MIN
, XG_SB_MIN
, XG_SB_MAX
,
2409 wscroll
= gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj
));
2410 gtk_widget_set_name (wscroll
, scroll_bar_name
);
2411 gtk_range_set_update_policy (GTK_RANGE (wscroll
), GTK_UPDATE_CONTINUOUS
);
2413 scroll_id
= xg_store_widget_in_map (wscroll
);
2415 g_signal_connect (G_OBJECT (vadj
),
2419 g_signal_connect (G_OBJECT (wscroll
),
2421 G_CALLBACK (xg_gtk_scroll_destroy
),
2422 (gpointer
)scroll_id
);
2424 /* Connect to button press and button release to detect if any scroll bar
2426 g_signal_connect (G_OBJECT (wscroll
),
2427 "button-press-event",
2428 G_CALLBACK (scroll_bar_button_cb
),
2430 g_signal_connect (G_OBJECT (wscroll
),
2431 "button-release-event",
2432 G_CALLBACK (scroll_bar_button_cb
),
2435 gtk_fixed_put (GTK_FIXED (f
->output_data
.x
->edit_widget
),
2438 /* Set the cursor to an arrow. */
2439 xg_set_cursor (wscroll
, &xg_left_ptr_cursor
);
2441 SET_SCROLL_BAR_X_WINDOW (bar
, scroll_id
);
2444 /* Make the scroll bar represented by SCROLLBAR_ID visible. */
2446 xg_show_scroll_bar (scrollbar_id
)
2449 GtkWidget
*w
= xg_get_widget_from_map (scrollbar_id
);
2451 gtk_widget_show (w
);
2454 /* Remove the scroll bar represented by SCROLLBAR_ID from the frame F. */
2456 xg_remove_scroll_bar (f
, scrollbar_id
)
2460 GtkWidget
*w
= xg_get_widget_from_map (scrollbar_id
);
2463 gtk_widget_destroy (w
);
2464 SET_FRAME_GARBAGED (f
);
2468 /* Find left/top for widget W in GtkFixed widget WFIXED. */
2470 xg_find_top_left_in_fixed (w
, wfixed
, left
, top
)
2471 GtkWidget
*w
, *wfixed
;
2476 for (iter
= GTK_FIXED (wfixed
)->children
; iter
; iter
= g_list_next (iter
))
2478 GtkFixedChild
*child
= (GtkFixedChild
*) iter
->data
;
2480 if (child
->widget
== w
)
2488 /* Shall never end up here. */
2492 /* Update the position of the vertical scroll bar represented by SCROLLBAR_ID
2494 TOP/LEFT are the new pixel positions where the bar shall appear.
2495 WIDTH, HEIGHT is the size in pixels the bar shall have. */
2497 xg_update_scrollbar_pos (f
, scrollbar_id
, top
, left
, width
, height
)
2506 GtkWidget
*wscroll
= xg_get_widget_from_map (scrollbar_id
);
2510 GtkWidget
*wfixed
= f
->output_data
.x
->edit_widget
;
2511 int gheight
= max (height
, 1);
2512 int canon_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
2513 int winextra
= canon_width
> width
? (canon_width
- width
) / 2 : 0;
2514 int bottom
= top
+ gheight
;
2517 int oldtop
, oldleft
, oldbottom
;
2520 /* Get old values. */
2521 xg_find_top_left_in_fixed (wscroll
, wfixed
, &oldleft
, &oldtop
);
2522 gtk_widget_size_request (wscroll
, &req
);
2523 oldbottom
= oldtop
+ req
.height
;
2525 /* Scroll bars in GTK has a fixed width, so if we say width 16, it
2526 will only be its fixed width (14 is default) anyway, the rest is
2527 blank. We are drawing the mode line across scroll bars when
2535 When we "unsplit" the frame:
2544 the remains of the mode line can be seen in these blank spaces.
2545 So we must clear them explicitly.
2546 GTK scroll bars should do that, but they don't.
2547 Also, the scroll bar canonical width may be wider than the width
2550 if (oldtop
!= -1 && oldleft
!= -1)
2554 int bottomdiff
, topdiff
;
2556 gtk_widget_style_get (wscroll
, "slider_width", &slider_width
, NULL
);
2557 gtkextra
= width
> slider_width
? (width
- slider_width
) / 2 : 0;
2559 xl
= left
- winextra
;
2560 wblank
= gtkextra
+ winextra
;
2561 xr
= left
+ gtkextra
+ slider_width
;
2562 bottomdiff
= abs (oldbottom
- bottom
);
2563 topdiff
= abs (oldtop
- top
);
2567 gdk_window_clear_area (wfixed
->window
, xl
, top
, wblank
, topdiff
);
2568 gdk_window_clear_area (wfixed
->window
, xr
, top
, wblank
, topdiff
);
2570 else if (oldtop
< top
)
2572 gdk_window_clear_area (wfixed
->window
, xl
, oldtop
, wblank
,
2574 gdk_window_clear_area (wfixed
->window
, xr
, oldtop
, wblank
,
2578 if (oldbottom
> bottom
)
2580 gdk_window_clear_area (wfixed
->window
, xl
, bottom
, wblank
,
2582 gdk_window_clear_area (wfixed
->window
, xr
, bottom
, wblank
,
2585 else if (oldbottom
< bottom
)
2587 gdk_window_clear_area (wfixed
->window
, xl
, oldbottom
, wblank
,
2589 gdk_window_clear_area (wfixed
->window
, xr
, oldbottom
, wblank
,
2594 /* Move and resize to new values. */
2595 gtk_fixed_move (GTK_FIXED (wfixed
), wscroll
, left
, top
);
2596 gtk_widget_set_size_request (wscroll
, width
, gheight
);
2598 gtk_container_set_reallocate_redraws (GTK_CONTAINER (wfixed
), TRUE
);
2600 /* Make GTK draw the new sizes. We are not using a pure GTK event
2601 loop so we need to do this. */
2602 gdk_window_process_all_updates ();
2604 SET_FRAME_GARBAGED (f
);
2605 cancel_mouse_face (f
);
2609 /* Set the thumb size and position of scroll bar BAR. We are currently
2610 displaying PORTION out of a whole WHOLE, and our position POSITION. */
2612 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
2613 struct scroll_bar
*bar
;
2614 int portion
, position
, whole
;
2616 GtkWidget
*wscroll
= xg_get_widget_from_map (SCROLL_BAR_X_WINDOW (bar
));
2618 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2622 if (wscroll
&& NILP (bar
->dragging
))
2629 adj
= gtk_range_get_adjustment (GTK_RANGE (wscroll
));
2631 /* We do the same as for MOTIF in xterm.c, assume 30 chars per line
2632 rather than the real portion value. This makes the thumb less likely
2633 to resize and that looks better. */
2634 portion
= XFASTINT (XWINDOW (bar
->window
)->height
) * 30;
2635 /* When the thumb is at the bottom, position == whole.
2636 So we need to increase `whole' to make space for the thumb. */
2643 shown
= (gdouble
) portion
/ whole
;
2644 top
= (gdouble
) position
/ whole
;
2647 size
= shown
* whole
;
2648 size
= min (size
, whole
);
2649 size
= max (size
, 1);
2651 value
= top
* whole
;
2652 value
= min (value
, whole
- size
);
2653 value
= max (value
, XG_SB_MIN
);
2655 adj
->page_size
= (int)size
;
2657 /* gtk_range_set_value invokes the callback. Set
2658 ignore_gtk_scrollbar to make the callback do nothing */
2659 xg_ignore_gtk_scrollbar
= 1;
2661 gtk_range_set_range (GTK_RANGE (wscroll
), adj
->lower
, max (whole
, size
));
2663 /* Assume all lines are of equal size. */
2664 /* Assume a page increment is about 95% of the page size */
2665 gtk_range_set_increments (GTK_RANGE (wscroll
),
2666 portion
/ max (1, FRAME_HEIGHT (f
)),
2667 (int) (0.95*adj
->page_size
));
2669 gtk_range_set_value (GTK_RANGE (wscroll
), (gdouble
)value
);
2670 xg_ignore_gtk_scrollbar
= 0;
2672 /* Make GTK draw the new thumb. We are not using a pure GTK event
2673 loop so we need to do this. */
2674 gdk_window_process_all_updates ();
2681 /***********************************************************************
2683 ***********************************************************************/
2684 /* The key for the data we put in the GtkImage widgets. The data is
2685 the image used by Emacs. We use this to see if we need to update
2686 the GtkImage with a new image. */
2687 #define XG_TOOL_BAR_IMAGE_DATA "emacs-tool-bar-image"
2689 /* Callback function invoked when a tool bar item is pressed.
2690 W is the button widget in the tool bar that got pressed,
2691 CLIENT_DATA is an integer that is the index of the button in the
2692 tool bar. 0 is the first button. */
2694 xg_tool_bar_callback (w
, client_data
)
2696 gpointer client_data
;
2698 int idx
= (int)client_data
;
2699 FRAME_PTR f
= (FRAME_PTR
) g_object_get_data (G_OBJECT (w
), XG_FRAME_DATA
);
2700 Lisp_Object key
, frame
;
2701 struct input_event event
;
2703 if (! f
|| ! f
->n_tool_bar_items
|| NILP (f
->tool_bar_items
))
2706 idx
*= TOOL_BAR_ITEM_NSLOTS
;
2708 key
= AREF (f
->tool_bar_items
, idx
+ TOOL_BAR_ITEM_KEY
);
2709 XSETFRAME (frame
, f
);
2710 event
.kind
= TOOL_BAR_EVENT
;
2711 event
.frame_or_window
= frame
;
2713 kbd_buffer_store_event (&event
);
2715 event
.kind
= TOOL_BAR_EVENT
;
2716 event
.frame_or_window
= frame
;
2718 event
.modifiers
= 0; /* These are not available. */
2719 kbd_buffer_store_event (&event
);
2722 /* This callback is called when a tool bar is detached. We must set
2723 the height of the tool bar to zero when this happens so frame sizes
2724 are correctly calculated.
2725 WBOX is the handle box widget that enables detach/attach of the tool bar.
2726 W is the tool bar widget.
2727 CLIENT_DATA is a pointer to the frame the tool bar belongs to. */
2729 xg_tool_bar_detach_callback (wbox
, w
, client_data
)
2732 gpointer client_data
;
2734 FRAME_PTR f
= (FRAME_PTR
) client_data
;
2738 /* When detaching a tool bar, not everything dissapear. There are
2739 a few pixels left that are used to drop the tool bar back into
2741 int bw
= gtk_container_get_border_width (GTK_CONTAINER (wbox
));
2742 FRAME_TOOLBAR_HEIGHT (f
) = 2;
2744 /* The height has changed, resize outer widget and set columns
2745 rows to what we had before detaching the tool bar. */
2746 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2750 /* This callback is called when a tool bar is reattached. We must set
2751 the height of the tool bar when this happens so frame sizes
2752 are correctly calculated.
2753 WBOX is the handle box widget that enables detach/attach of the tool bar.
2754 W is the tool bar widget.
2755 CLIENT_DATA is a pointer to the frame the tool bar belongs to. */
2757 xg_tool_bar_attach_callback (wbox
, w
, client_data
)
2760 gpointer client_data
;
2762 FRAME_PTR f
= (FRAME_PTR
) client_data
;
2768 gtk_widget_size_request (w
, &req
);
2769 FRAME_TOOLBAR_HEIGHT (f
) = req
.height
;
2771 /* The height has changed, resize outer widget and set columns
2772 rows to what we had before detaching the tool bar. */
2773 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2777 /* This callback is called when the mouse enters or leaves a tool bar item.
2778 It is used for displaying and hiding the help text.
2779 W is the tool bar item, a button.
2780 EVENT is either an enter event or leave event.
2781 CLIENT_DATA is an integer that is the index of the button in the
2782 tool bar. 0 is the first button.
2784 Returns FALSE to tell GTK to keep processing this event. */
2786 xg_tool_bar_help_callback (w
, event
, client_data
)
2788 GdkEventCrossing
*event
;
2789 gpointer client_data
;
2791 int idx
= (int)client_data
;
2792 FRAME_PTR f
= (FRAME_PTR
) g_object_get_data (G_OBJECT (w
), XG_FRAME_DATA
);
2793 Lisp_Object help
, frame
;
2795 if (! GTK_IS_BUTTON (w
))
2800 if (! f
|| ! f
->n_tool_bar_items
|| NILP (f
->tool_bar_items
))
2803 if (event
->type
== GDK_ENTER_NOTIFY
)
2805 idx
*= TOOL_BAR_ITEM_NSLOTS
;
2806 help
= AREF (f
->tool_bar_items
, idx
+ TOOL_BAR_ITEM_HELP
);
2809 help
= AREF (f
->tool_bar_items
, idx
+ TOOL_BAR_ITEM_CAPTION
);
2814 XSETFRAME (frame
, f
);
2815 kbd_buffer_store_help_event (frame
, help
);
2821 /* This callback is called when a tool bar item shall be redrawn.
2822 It modifies the expose event so that the GtkImage widget redraws the
2823 whole image. This to overcome a bug that makes GtkImage draw the image
2824 in the wrong place when it tries to redraw just a part of the image.
2825 W is the GtkImage to be redrawn.
2826 EVENT is the expose event for W.
2827 CLIENT_DATA is unused.
2829 Returns FALSE to tell GTK to keep processing this event. */
2831 xg_tool_bar_item_expose_callback (w
, event
, client_data
)
2833 GdkEventExpose
*event
;
2834 gpointer client_data
;
2836 event
->area
.x
= event
->area
.y
= 0;
2837 event
->area
.width
= event
->area
.height
= 1000;
2841 /* This callback is called when a tool bar shall be redrawn.
2842 We need to update the tool bar from here in case the image cache
2843 has deleted the pixmaps used in the tool bar.
2844 W is the GtkToolbar to be redrawn.
2845 EVENT is the expose event for W.
2846 CLIENT_DATA is pointing to the frame for this tool bar.
2848 Returns FALSE to tell GTK to keep processing this event. */
2850 xg_tool_bar_expose_callback (w
, event
, client_data
)
2852 GdkEventExpose
*event
;
2853 gpointer client_data
;
2855 update_frame_tool_bar((FRAME_PTR
)client_data
);
2860 xg_create_tool_bar (f
)
2863 struct x_output
*x
= f
->output_data
.x
;
2865 int vbox_pos
= x
->menubar_widget
? 1 : 0;
2867 x
->toolbar_widget
= gtk_toolbar_new ();
2868 x
->handlebox_widget
= gtk_handle_box_new ();
2869 gtk_container_add (GTK_CONTAINER (x
->handlebox_widget
),
2872 gtk_box_pack_start (GTK_BOX (x
->vbox_widget
), x
->handlebox_widget
,
2875 gtk_box_reorder_child (GTK_BOX (x
->vbox_widget
), x
->handlebox_widget
,
2878 gtk_widget_set_name (x
->toolbar_widget
, "emacs-toolbar");
2880 /* We only have icons, so override any user setting. We could
2881 use the caption property of the toolbar item (see update_frame_tool_bar
2882 below), but some of those strings are long, making the toolbar so
2883 long it does not fit on the screen. The GtkToolbar widget makes every
2884 item equal size, so the longest caption determine the size of every
2885 tool bar item. I think the creators of the GtkToolbar widget
2886 counted on 4 or 5 character long strings. */
2887 gtk_toolbar_set_style (GTK_TOOLBAR (x
->toolbar_widget
), GTK_TOOLBAR_ICONS
);
2888 gtk_toolbar_set_orientation (GTK_TOOLBAR (x
->toolbar_widget
),
2889 GTK_ORIENTATION_HORIZONTAL
);
2891 g_signal_connect (G_OBJECT (x
->handlebox_widget
), "child-detached",
2892 G_CALLBACK (xg_tool_bar_detach_callback
), f
);
2893 g_signal_connect (G_OBJECT (x
->handlebox_widget
), "child-attached",
2894 G_CALLBACK (xg_tool_bar_attach_callback
), f
);
2895 g_signal_connect (G_OBJECT (x
->toolbar_widget
),
2897 G_CALLBACK (xg_tool_bar_expose_callback
),
2900 gtk_widget_show_all (x
->handlebox_widget
);
2902 gtk_widget_size_request (x
->toolbar_widget
, &req
);
2903 FRAME_TOOLBAR_HEIGHT (f
) = req
.height
;
2905 /* The height has changed, resize outer widget and set columns
2906 rows to what we had before adding the tool bar. */
2907 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2909 SET_FRAME_GARBAGED (f
);
2913 update_frame_tool_bar (f
)
2917 GtkRequisition old_req
, new_req
;
2920 struct x_output
*x
= f
->output_data
.x
;
2922 if (! FRAME_GTK_WIDGET (f
))
2927 if (! x
->toolbar_widget
)
2928 xg_create_tool_bar (f
);
2930 gtk_widget_size_request (x
->toolbar_widget
, &old_req
);
2932 icon_list
= gtk_container_get_children (GTK_CONTAINER (x
->toolbar_widget
));
2935 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
2937 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
2939 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
2940 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
2945 GtkWidget
*wicon
= iter
? GTK_WIDGET (iter
->data
) : 0;
2947 if (iter
) iter
= g_list_next (iter
);
2949 /* If image is a vector, choose the image according to the
2951 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
2952 if (VECTORP (image
))
2956 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
2957 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
2960 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
2961 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
2963 xassert (ASIZE (image
) >= idx
);
2964 image
= AREF (image
, idx
);
2969 /* Ignore invalid image specifications. */
2970 if (!valid_image_p (image
))
2972 if (wicon
) gtk_widget_hide (wicon
);
2976 img_id
= lookup_image (f
, image
);
2977 img
= IMAGE_FROM_ID (f
, img_id
);
2978 prepare_image_for_display (f
, img
);
2980 if (img
->load_failed_p
|| img
->pixmap
== None
)
2982 if (wicon
) gtk_widget_hide (wicon
);
2988 GdkPixmap
*gpix
= gdk_pixmap_foreign_new (img
->pixmap
);
2989 GdkBitmap
*gmask
= img
->mask
?
2990 (GdkBitmap
*) gdk_pixmap_foreign_new (img
->mask
) : 0;
2992 GtkWidget
*w
= gtk_image_new_from_pixmap (gpix
, gmask
);
2993 gtk_toolbar_append_item (GTK_TOOLBAR (x
->toolbar_widget
),
2996 GTK_SIGNAL_FUNC (xg_tool_bar_callback
),
2999 /* Save the image so we can see if an update is needed when
3000 this function is called again. */
3001 g_object_set_data (G_OBJECT (w
), XG_TOOL_BAR_IMAGE_DATA
,
3002 (gpointer
)img
->pixmap
);
3004 /* Catch expose events to overcome an annoying redraw bug, see
3005 comment for xg_tool_bar_item_expose_callback. */
3006 g_signal_connect (G_OBJECT (w
),
3008 G_CALLBACK (xg_tool_bar_item_expose_callback
),
3011 /* We must set sensitive on the button that is the parent
3012 of the GtkImage parent. Go upwards until we find the button. */
3013 while (! GTK_IS_BUTTON (w
))
3014 w
= gtk_widget_get_parent (w
);
3018 /* Save the frame in the button so the xg_tool_bar_callback
3020 g_object_set_data (G_OBJECT (w
), XG_FRAME_DATA
, (gpointer
)f
);
3021 gtk_widget_set_sensitive (w
, enabled_p
);
3023 /* Use enter/leave notify to show help. We use the events
3024 rather than the GtkButton specific signals "enter" and
3025 "leave", so we can have only one callback. The event
3026 will tell us what kind of event it is. */
3027 g_signal_connect (G_OBJECT (w
),
3028 "enter-notify-event",
3029 G_CALLBACK (xg_tool_bar_help_callback
),
3031 g_signal_connect (G_OBJECT (w
),
3032 "leave-notify-event",
3033 G_CALLBACK (xg_tool_bar_help_callback
),
3039 /* The child of the tool bar is a button. Inside that button
3040 is a vbox. Inside that vbox is the GtkImage. */
3041 GtkWidget
*wvbox
= gtk_bin_get_child (GTK_BIN (wicon
));
3042 GList
*chlist
= gtk_container_get_children (GTK_CONTAINER (wvbox
));
3043 GtkImage
*wimage
= GTK_IMAGE (chlist
->data
);
3044 Pixmap old_img
= (Pixmap
)g_object_get_data (G_OBJECT (wimage
),
3045 XG_TOOL_BAR_IMAGE_DATA
);
3046 g_list_free (chlist
);
3048 if (old_img
!= img
->pixmap
)
3050 GdkPixmap
*gpix
= gdk_pixmap_foreign_new (img
->pixmap
);
3051 GdkBitmap
*gmask
= img
->mask
?
3052 (GdkBitmap
*) gdk_pixmap_foreign_new (img
->mask
) : 0;
3054 gtk_image_set_from_pixmap (wimage
, gpix
, gmask
);
3057 g_object_set_data (G_OBJECT (wimage
), XG_TOOL_BAR_IMAGE_DATA
,
3058 (gpointer
)img
->pixmap
);
3060 gtk_widget_set_sensitive (wicon
, enabled_p
);
3061 gtk_widget_show (wicon
);
3067 /* Remove buttons not longer needed. We just hide them so they
3068 can be reused later on. */
3071 GtkWidget
*w
= GTK_WIDGET (iter
->data
);
3072 gtk_widget_hide (w
);
3073 iter
= g_list_next (iter
);
3076 gtk_widget_size_request (x
->toolbar_widget
, &new_req
);
3077 if (old_req
.height
!= new_req
.height
)
3079 FRAME_TOOLBAR_HEIGHT (f
) = new_req
.height
;
3080 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
3083 /* Must force out update so changed images gets redrawn. */
3084 gdk_window_process_all_updates ();
3086 if (icon_list
) g_list_free (icon_list
);
3092 free_frame_tool_bar (f
)
3095 struct x_output
*x
= f
->output_data
.x
;
3097 if (x
->toolbar_widget
)
3100 gtk_container_remove (GTK_CONTAINER (x
->vbox_widget
),
3101 x
->handlebox_widget
);
3102 x
->toolbar_widget
= 0;
3103 x
->handlebox_widget
= 0;
3104 FRAME_TOOLBAR_HEIGHT (f
) = 0;
3106 /* The height has changed, resize outer widget and set columns
3107 rows to what we had before removing the tool bar. */
3108 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
3110 SET_FRAME_GARBAGED (f
);
3117 /***********************************************************************
3119 ***********************************************************************/
3123 xg_ignore_gtk_scrollbar
= 0;
3124 xg_left_ptr_cursor
= 0;
3127 xg_menu_cb_list
.prev
= xg_menu_cb_list
.next
=
3128 xg_menu_item_cb_list
.prev
= xg_menu_item_cb_list
.next
= 0;
3130 id_to_widget
.max_size
= id_to_widget
.used
= 0;
3131 id_to_widget
.widgets
= 0;
3133 /* Remove F10 as a menu accelerator, it does not mix well with Emacs key
3134 bindings. It doesn't seem to be any way to remove properties,
3135 so we set it to VoidSymbol which in X means "no key". */
3136 gtk_settings_set_string_property (gtk_settings_get_default (),
3137 "gtk-menu-bar-accel",
3141 /* Make GTK text input widgets use Emacs style keybindings. This is
3143 gtk_settings_set_string_property (gtk_settings_get_default (),
3144 "gtk-key-theme-name",
3149 #endif /* USE_GTK */