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
*w
= f
->output_data
.x
->widget
;
300 gtk_container_set_reallocate_redraws (GTK_CONTAINER (w
), TRUE
);
301 gtk_container_foreach (GTK_CONTAINER (w
),
302 (GtkCallback
) gtk_widget_queue_draw
,
304 gdk_window_process_all_updates ();
308 /* Function to handle resize of our widgets. Since Emacs has some layouts
309 that does not fit well with GTK standard containers, we do most layout
311 F is the frame to resize.
312 PIXELWIDTH, PIXELHEIGHT is the new size in pixels. */
314 xg_resize_widgets (f
, pixelwidth
, pixelheight
)
316 int pixelwidth
, pixelheight
;
318 int mbheight
= FRAME_MENUBAR_HEIGHT (f
);
319 int tbheight
= FRAME_TOOLBAR_HEIGHT (f
);
320 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, pixelheight
- mbheight
- tbheight
);
321 int columns
= PIXEL_TO_CHAR_WIDTH (f
, pixelwidth
);
323 if (FRAME_GTK_WIDGET (f
)
324 && (columns
!= FRAME_WIDTH (f
) || rows
!= FRAME_HEIGHT (f
)
325 || pixelwidth
!= PIXEL_WIDTH (f
) || pixelheight
!= PIXEL_HEIGHT (f
)))
327 struct x_output
*x
= f
->output_data
.x
;
330 all
.y
= mbheight
+ tbheight
;
333 all
.width
= pixelwidth
;
334 all
.height
= pixelheight
- mbheight
- tbheight
;
336 gtk_widget_size_allocate (x
->edit_widget
, &all
);
338 xg_frame_cleared (f
);
340 change_frame_size (f
, rows
, columns
, 0, 1, 0);
341 SET_FRAME_GARBAGED (f
);
342 cancel_mouse_face (f
);
347 /* Update our widget size to be COLS/ROWS characters for frame F. */
349 xg_frame_set_char_size (f
, cols
, rows
)
354 int pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
)
355 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
356 int pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
358 /* Take into account the size of the scroll bar. Always use the
359 number of columns occupied by the scroll bar here otherwise we
360 might end up with a frame width that is not a multiple of the
361 frame's character width which is bad for vertically split
363 f
->output_data
.x
->vertical_scroll_bar_extra
364 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
366 : (FRAME_SCROLL_BAR_COLS (f
)
367 * FONT_WIDTH (f
->output_data
.x
->font
)));
369 compute_fringe_widths (f
, 0);
371 /* Must resize our top level widget. Font size may have changed,
372 but not rows/cols. */
373 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
374 pixelwidth
, pixelheight
);
375 xg_resize_widgets (f
, pixelwidth
, pixelheight
);
378 /* Convert an X Window WSESC to its corresponding GtkWidget.
379 Must be done like this, because GtkWidget:s can have "hidden"
380 X Window that aren't accessible.
382 Return 0 if no widget match WDESC. */
384 xg_win_to_widget (wdesc
)
388 GtkWidget
*gwdesc
= 0;
391 gdkwin
= gdk_xid_table_lookup (wdesc
);
395 event
.any
.window
= gdkwin
;
396 gwdesc
= gtk_get_event_widget (&event
);
403 /* Fill in the GdkColor C so that it represents PIXEL.
404 W is the widget that color will be used for. Used to find colormap. */
406 xg_pix_to_gcolor (w
, pixel
, c
)
411 GdkColormap
*map
= gtk_widget_get_colormap (w
);
412 gdk_colormap_query_color (map
, pixel
, c
);
415 /* Create and set up the GTK widgets for frame F.
416 Return 0 if creation failed, non-zero otherwise. */
418 xg_create_frame_widgets (f
)
431 wtop
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
432 wvbox
= gtk_vbox_new (FALSE
, 0);
433 wfixed
= gtk_fixed_new (); /* Must have this to place scroll bars */
435 if (! wtop
|| ! wvbox
|| ! wfixed
)
437 if (wtop
) gtk_widget_destroy (wtop
);
438 if (wvbox
) gtk_widget_destroy (wvbox
);
439 if (wfixed
) gtk_widget_destroy (wfixed
);
444 /* Use same names as the Xt port does. I.e. Emacs.pane.emacs by default */
445 gtk_widget_set_name (wtop
, EMACS_CLASS
);
446 gtk_widget_set_name (wvbox
, "pane");
447 gtk_widget_set_name (wfixed
, SDATA (Vx_resource_name
));
449 /* If this frame has a title or name, set it in the title bar. */
450 if (! NILP (f
->title
)) title
= SDATA (f
->title
);
451 else if (! NILP (f
->name
)) title
= SDATA (f
->name
);
453 if (title
) gtk_window_set_title (GTK_WINDOW (wtop
), title
);
455 FRAME_GTK_OUTER_WIDGET (f
) = wtop
;
456 FRAME_GTK_WIDGET (f
) = wfixed
;
457 f
->output_data
.x
->vbox_widget
= wvbox
;
459 gtk_fixed_set_has_window (GTK_FIXED (wfixed
), TRUE
);
461 gtk_widget_set_size_request (wfixed
,
465 gtk_container_add (GTK_CONTAINER (wtop
), wvbox
);
466 gtk_box_pack_end (GTK_BOX (wvbox
), wfixed
, TRUE
, TRUE
, 0);
468 if (FRAME_EXTERNAL_TOOL_BAR (f
))
469 update_frame_tool_bar (f
);
471 /* The tool bar is created but first there are no items in it.
472 This causes it to be zero height. Later items are added, but then
473 the frame is already mapped, so there is a "jumping" resize.
474 This makes geometry handling difficult, for example -0-0 will end
475 up in the wrong place as tool bar height has not been taken into account.
476 So we cheat a bit by setting a height that is what it will have
477 later on when tool bar items are added. */
478 if (FRAME_EXTERNAL_TOOL_BAR (f
) && FRAME_TOOLBAR_HEIGHT (f
) == 0)
479 FRAME_TOOLBAR_HEIGHT (f
) = 34;
481 gtk_widget_set_double_buffered (wvbox
, FALSE
);
482 gtk_widget_set_double_buffered (wfixed
, FALSE
);
483 gtk_widget_set_double_buffered (wtop
, FALSE
);
485 /* GTK documents says use gtk_window_set_resizable. But then a user
486 can't shrink the window from its starting size. */
487 gtk_window_set_policy (GTK_WINDOW (wtop
), TRUE
, TRUE
, TRUE
);
488 gtk_window_set_wmclass (GTK_WINDOW (wtop
),
489 SDATA (Vx_resource_name
),
490 SDATA (Vx_resource_class
));
492 /* Add callback to do nothing on WM_DELETE_WINDOW. The default in
493 GTK is to destroy the widget. We want Emacs to do that instead. */
494 g_signal_connect (G_OBJECT (wtop
), "delete-event",
495 G_CALLBACK (gtk_true
), 0);
497 /* Convert our geometry parameters into a geometry string
499 GTK will itself handle calculating the real position this way. */
502 gtk_widget_add_events (wfixed
,
503 GDK_POINTER_MOTION_MASK
505 | GDK_BUTTON_PRESS_MASK
506 | GDK_BUTTON_RELEASE_MASK
508 | GDK_ENTER_NOTIFY_MASK
509 | GDK_LEAVE_NOTIFY_MASK
510 | GDK_FOCUS_CHANGE_MASK
512 | GDK_VISIBILITY_NOTIFY_MASK
);
514 /* Must realize the windows so the X window gets created. It is used
515 by callers of this function. */
516 gtk_widget_realize (wfixed
);
517 FRAME_X_WINDOW (f
) = GTK_WIDGET_TO_X_WIN (wfixed
);
519 /* Since GTK clears its window by filling with the background color,
520 we must keep X and GTK background in sync. */
521 xg_pix_to_gcolor (wfixed
, f
->output_data
.x
->background_pixel
, &bg
);
522 gtk_widget_modify_bg (wfixed
, GTK_STATE_NORMAL
, &bg
);
524 /* Also, do not let any background pixmap to be set, this looks very
525 bad as Emacs overwrites the background pixmap with its own idea
526 of background color. */
527 style
= gtk_widget_get_modifier_style (wfixed
);
529 /* Must use g_strdup because gtk_widget_modify_style does g_free. */
530 style
->bg_pixmap_name
[GTK_STATE_NORMAL
] = g_strdup ("<none>");
531 gtk_widget_modify_style (wfixed
, style
);
533 /* GTK does not set any border, and they look bad with GTK. */
534 f
->output_data
.x
->border_width
= 0;
535 f
->output_data
.x
->internal_border_width
= 0;
542 /* Set the normal size hints for the window manager, for frame F.
543 FLAGS is the flags word to use--or 0 meaning preserve the flags
544 that the window now has.
545 If USER_POSITION is nonzero, we set the User Position
546 flag (this is useful when FLAGS is 0). */
548 x_wm_set_size_hint (f
, flags
, user_position
)
553 if (FRAME_GTK_OUTER_WIDGET (f
))
555 /* Must use GTK routines here, otherwise GTK resets the size hints
556 to its own defaults. */
557 GdkGeometry size_hints
;
559 int base_width
, base_height
;
560 int min_rows
= 0, min_cols
= 0;
561 int win_gravity
= f
->output_data
.x
->win_gravity
;
565 memset (&size_hints
, 0, sizeof (size_hints
));
566 f
->output_data
.x
->size_hints
= size_hints
;
567 f
->output_data
.x
->hint_flags
= hint_flags
;
570 flags
= f
->output_data
.x
->size_hint_flags
;
572 size_hints
= f
->output_data
.x
->size_hints
;
573 hint_flags
= f
->output_data
.x
->hint_flags
;
575 hint_flags
|= GDK_HINT_RESIZE_INC
| GDK_HINT_MIN_SIZE
;
576 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
577 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
579 hint_flags
|= GDK_HINT_BASE_SIZE
;
580 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
581 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0)
582 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
584 check_frame_size (f
, &min_rows
, &min_cols
);
586 size_hints
.base_width
= base_width
;
587 size_hints
.base_height
= base_height
;
588 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
589 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
592 /* These currently have a one to one mapping with the X values, but I
593 don't think we should rely on that. */
594 hint_flags
|= GDK_HINT_WIN_GRAVITY
;
595 size_hints
.win_gravity
= 0;
596 if (win_gravity
== NorthWestGravity
)
597 size_hints
.win_gravity
= GDK_GRAVITY_NORTH_WEST
;
598 else if (win_gravity
== NorthGravity
)
599 size_hints
.win_gravity
= GDK_GRAVITY_NORTH
;
600 else if (win_gravity
== NorthEastGravity
)
601 size_hints
.win_gravity
= GDK_GRAVITY_NORTH_EAST
;
602 else if (win_gravity
== WestGravity
)
603 size_hints
.win_gravity
= GDK_GRAVITY_WEST
;
604 else if (win_gravity
== CenterGravity
)
605 size_hints
.win_gravity
= GDK_GRAVITY_CENTER
;
606 else if (win_gravity
== EastGravity
)
607 size_hints
.win_gravity
= GDK_GRAVITY_EAST
;
608 else if (win_gravity
== SouthWestGravity
)
609 size_hints
.win_gravity
= GDK_GRAVITY_SOUTH_WEST
;
610 else if (win_gravity
== SouthGravity
)
611 size_hints
.win_gravity
= GDK_GRAVITY_SOUTH
;
612 else if (win_gravity
== SouthEastGravity
)
613 size_hints
.win_gravity
= GDK_GRAVITY_SOUTH_EAST
;
614 else if (win_gravity
== StaticGravity
)
615 size_hints
.win_gravity
= GDK_GRAVITY_STATIC
;
617 if (flags
& PPosition
) hint_flags
|= GDK_HINT_POS
;
618 if (flags
& USPosition
) hint_flags
|= GDK_HINT_USER_POS
;
619 if (flags
& USSize
) hint_flags
|= GDK_HINT_USER_SIZE
;
623 hint_flags
&= ~GDK_HINT_POS
;
624 hint_flags
|= GDK_HINT_USER_POS
;
629 gtk_window_set_geometry_hints (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
630 FRAME_GTK_OUTER_WIDGET (f
),
634 f
->output_data
.x
->size_hints
= size_hints
;
635 f
->output_data
.x
->hint_flags
= hint_flags
;
640 /* Change background color of a frame.
641 Since GTK uses the background colour to clear the window, we must
642 keep the GTK and X colors in sync.
643 F is the frame to change,
644 BG is the pixel value to change to. */
646 xg_set_background_color (f
, bg
)
650 if (FRAME_GTK_WIDGET (f
))
655 xg_pix_to_gcolor (FRAME_GTK_WIDGET (f
), bg
, &gdk_bg
);
656 gtk_widget_modify_bg (FRAME_GTK_WIDGET (f
), GTK_STATE_NORMAL
, &gdk_bg
);
663 /***********************************************************************
665 ***********************************************************************/
666 /* Return the dialog title to use for a dialog of type KEY.
667 This is the encoding used by lwlib. We use the same for GTK. */
669 get_dialog_title (char key
)
679 title
= "Information";
698 /* Callback for dialogs that get WM_DELETE_WINDOW. We pop down
699 the dialog, but return TRUE so the event does not propagate further
700 in GTK. This prevents GTK from destroying the dialog widget automatically
701 and we can always destrou the widget manually, regardles of how
702 it was popped down (button press or WM_DELETE_WINDOW).
703 W is the dialog widget.
704 EVENT is the GdkEvent that represents WM_DELETE_WINDOW (not used).
705 user_data is NULL (not used).
707 Returns TRUE to end propagation of event. */
709 dialog_delete_callback (w
, event
, user_data
)
714 gtk_widget_unmap (w
);
718 /* Create a popup dialog window. See also xg_create_widget below.
719 WV is a widget_value describing the dialog.
720 SELECT_CB is the callback to use when a button has been pressed.
721 DEACTIVATE_CB is the callback to use when the dialog pops down.
723 Returns the GTK dialog widget. */
725 create_dialog (wv
, select_cb
, deactivate_cb
)
728 GCallback deactivate_cb
;
730 char *title
= get_dialog_title (wv
->name
[0]);
731 int total_buttons
= wv
->name
[1] - '0';
732 int right_buttons
= wv
->name
[4] - '0';
735 int button_spacing
= 10;
736 GtkWidget
*wdialog
= gtk_dialog_new ();
741 GtkWidget
*whbox_down
;
743 /* If the number of buttons is greater than 4, make two rows of buttons
744 instead. This looks better. */
745 int make_two_rows
= total_buttons
> 4;
747 if (right_buttons
== 0) right_buttons
= total_buttons
/2;
748 left_buttons
= total_buttons
- right_buttons
;
750 gtk_window_set_title (GTK_WINDOW (wdialog
), title
);
751 gtk_widget_set_name (wdialog
, "emacs-dialog");
753 cur_box
= GTK_BOX (GTK_DIALOG (wdialog
)->action_area
);
757 wvbox
= gtk_vbox_new (TRUE
, button_spacing
);
758 whbox_up
= gtk_hbox_new (FALSE
, 0);
759 whbox_down
= gtk_hbox_new (FALSE
, 0);
761 gtk_box_pack_start (cur_box
, wvbox
, FALSE
, FALSE
, 0);
762 gtk_box_pack_start (GTK_BOX (wvbox
), whbox_up
, FALSE
, FALSE
, 0);
763 gtk_box_pack_start (GTK_BOX (wvbox
), whbox_down
, FALSE
, FALSE
, 0);
765 cur_box
= GTK_BOX (whbox_up
);
768 g_signal_connect (G_OBJECT (wdialog
), "delete-event",
769 G_CALLBACK (dialog_delete_callback
), 0);
773 g_signal_connect (G_OBJECT (wdialog
), "close", deactivate_cb
, 0);
774 g_signal_connect (G_OBJECT (wdialog
), "response", deactivate_cb
, 0);
777 for (item
= wv
->contents
; item
; item
= item
->next
)
779 char *utf8_label
= get_utf8_string (item
->value
);
783 if (item
->name
&& strcmp (item
->name
, "message") == 0)
785 /* This is the text part of the dialog. */
786 w
= gtk_label_new (utf8_label
);
787 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (wdialog
)->vbox
),
790 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (wdialog
)->vbox
), w
,
792 gtk_misc_set_alignment (GTK_MISC (w
), 0.1, 0.5);
794 /* Try to make dialog look better. Must realize first so
795 the widget can calculate the size it needs. */
796 gtk_widget_realize (w
);
797 gtk_widget_size_request (w
, &req
);
798 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (wdialog
)->vbox
),
800 if (item
->value
&& strlen (item
->value
) > 0)
801 button_spacing
= 2*req
.width
/strlen (item
->value
);
805 /* This is one button to add to the dialog. */
806 w
= gtk_button_new_with_mnemonic (utf8_label
);
808 gtk_widget_set_sensitive (w
, FALSE
);
810 g_signal_connect (G_OBJECT (w
), "clicked",
811 select_cb
, item
->call_data
);
813 gtk_box_pack_start (cur_box
, w
, TRUE
, TRUE
, button_spacing
);
814 if (++button_nr
== left_buttons
)
817 cur_box
= GTK_BOX (whbox_down
);
819 gtk_box_pack_start (cur_box
,
826 if (utf8_label
&& utf8_label
!= item
->value
)
842 /* Callback function invoked when the Ok button is pressed in
844 W is the file dialog widget,
845 ARG points to an integer where we record what has happend. */
847 xg_file_sel_ok (w
, arg
)
851 *(int*)arg
= XG_FILE_OK
;
854 /* Callback function invoked when the Cancel button is pressed in
856 W is the file dialog widget,
857 ARG points to an integer where we record what has happend. */
859 xg_file_sel_cancel (w
, arg
)
863 *(int*)arg
= XG_FILE_CANCEL
;
866 /* Callback function invoked when the file dialog is destroyed (i.e.
867 popped down). We must keep track of this, because if this
868 happens, GTK destroys the widget. But if for example, Ok is pressed,
869 the dialog is popped down, but the dialog widget is not destroyed.
870 W is the file dialog widget,
871 ARG points to an integer where we record what has happend. */
873 xg_file_sel_destroy (w
, arg
)
877 *(int*)arg
= XG_FILE_DESTROYED
;
880 /* Read a file name from the user using a file dialog.
881 F is the current frame.
882 PROMPT is a prompt to show to the user. May not be NULL.
883 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
884 If MUSTMATCH_P is non-zero, the returned file name must be an existing
887 Returns a file name or NULL if no file was selected.
888 The returned string must be freed by the caller. */
890 xg_get_file_name (f
, prompt
, default_filename
, mustmatch_p
)
893 char *default_filename
;
897 GtkFileSelection
*filesel
;
898 int filesel_done
= XG_FILE_NOT_DONE
;
901 filewin
= gtk_file_selection_new (prompt
);
902 filesel
= GTK_FILE_SELECTION (filewin
);
904 gtk_widget_set_name (filewin
, "emacs-filedialog");
906 gtk_window_set_transient_for (GTK_WINDOW (filewin
),
907 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
908 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin
), TRUE
);
910 g_signal_connect (G_OBJECT (filesel
->ok_button
),
912 G_CALLBACK (xg_file_sel_ok
),
914 g_signal_connect (G_OBJECT (filesel
->cancel_button
),
916 G_CALLBACK (xg_file_sel_cancel
),
918 g_signal_connect (G_OBJECT (filesel
),
920 G_CALLBACK (xg_file_sel_destroy
),
923 if (default_filename
)
924 gtk_file_selection_set_filename (filesel
, default_filename
);
928 /* The selection_entry part of filesel is not documented. */
929 gtk_widget_set_sensitive (filesel
->selection_entry
, FALSE
);
930 gtk_file_selection_hide_fileop_buttons (filesel
);
934 gtk_widget_show_all (filewin
);
936 while (filesel_done
== XG_FILE_NOT_DONE
)
937 gtk_main_iteration ();
939 if (filesel_done
== XG_FILE_OK
)
940 fn
= xstrdup ((char*) gtk_file_selection_get_filename (filesel
));
942 if (filesel_done
!= XG_FILE_DESTROYED
)
943 gtk_widget_destroy (filewin
);
949 /***********************************************************************
951 ***********************************************************************/
953 /* The name of menu items that can be used for citomization. Since GTK
954 RC files are very crude and primitive, we have to set this on all
955 menu item names so a user can easily cutomize menu items. */
957 #define MENU_ITEM_NAME "emacs-menuitem"
960 /* Linked list of all allocated struct xg_menu_cb_data. Used for marking
961 during GC. The next member points to the items. */
962 static xg_list_node xg_menu_cb_list
;
964 /* Linked list of all allocated struct xg_menu_item_cb_data. Used for marking
965 during GC. The next member points to the items. */
966 static xg_list_node xg_menu_item_cb_list
;
968 /* Allocate and initialize CL_DATA if NULL, otherwise increase ref_count.
969 F is the frame CL_DATA will be initialized for.
970 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
972 The menu bar and all sub menus under the menu bar in a frame
973 share the same structure, hence the reference count.
975 Returns CL_DATA if CL_DATA is not NULL, or a pointer to a newly
976 allocated xg_menu_cb_data if CL_DATA is NULL. */
977 static xg_menu_cb_data
*
978 make_cl_data (cl_data
, f
, highlight_cb
)
979 xg_menu_cb_data
*cl_data
;
981 GCallback highlight_cb
;
985 cl_data
= (xg_menu_cb_data
*) xmalloc (sizeof (*cl_data
));
987 cl_data
->menu_bar_vector
= f
->menu_bar_vector
;
988 cl_data
->menu_bar_items_used
= f
->menu_bar_items_used
;
989 cl_data
->highlight_cb
= highlight_cb
;
990 cl_data
->ref_count
= 0;
992 xg_list_insert (&xg_menu_cb_list
, &cl_data
->ptrs
);
995 cl_data
->ref_count
++;
1000 /* Update CL_DATA with values from frame F and with HIGHLIGHT_CB.
1001 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1003 When the menu bar is updated, menu items may have been added and/or
1004 removed, so menu_bar_vector and menu_bar_items_used change. We must
1005 then update CL_DATA since it is used to determine which menu
1006 item that is invoked in the menu.
1007 HIGHLIGHT_CB could change, there is no check that the same
1008 function is given when modifying a menu bar as was given when
1009 creating the menu bar. */
1011 update_cl_data (cl_data
, f
, highlight_cb
)
1012 xg_menu_cb_data
*cl_data
;
1014 GCallback highlight_cb
;
1019 cl_data
->menu_bar_vector
= f
->menu_bar_vector
;
1020 cl_data
->menu_bar_items_used
= f
->menu_bar_items_used
;
1021 cl_data
->highlight_cb
= highlight_cb
;
1025 /* Decrease reference count for CL_DATA.
1026 If reference count is zero, free CL_DATA. */
1028 unref_cl_data (cl_data
)
1029 xg_menu_cb_data
*cl_data
;
1031 if (cl_data
&& cl_data
->ref_count
> 0)
1033 cl_data
->ref_count
--;
1034 if (cl_data
->ref_count
== 0)
1036 xg_list_remove (&xg_menu_cb_list
, &cl_data
->ptrs
);
1042 /* Function that marks all lisp data during GC. */
1048 for (iter
= xg_menu_cb_list
.next
; iter
; iter
= iter
->next
)
1049 mark_object (&((xg_menu_cb_data
*) iter
)->menu_bar_vector
);
1051 for (iter
= xg_menu_item_cb_list
.next
; iter
; iter
= iter
->next
)
1053 xg_menu_item_cb_data
*cb_data
= (xg_menu_item_cb_data
*) iter
;
1055 if (! NILP (cb_data
->help
))
1056 mark_object (&cb_data
->help
);
1061 /* Callback called when a menu item is destroyed. Used to free data.
1062 W is the widget that is being destroyed (not used).
1063 CLIENT_DATA points to the xg_menu_item_cb_data associated with the W. */
1065 menuitem_destroy_callback (w
, client_data
)
1067 gpointer client_data
;
1071 xg_menu_item_cb_data
*data
= (xg_menu_item_cb_data
*) client_data
;
1072 xg_list_remove (&xg_menu_item_cb_list
, &data
->ptrs
);
1077 /* Callback called when the pointer enters/leaves a menu item.
1079 EVENT is either an enter event or leave event.
1080 CLIENT_DATA points to the xg_menu_item_cb_data associated with the W.
1082 Returns FALSE to tell GTK to keep processing this event. */
1084 menuitem_highlight_callback (w
, event
, client_data
)
1086 GdkEventCrossing
*event
;
1087 gpointer client_data
;
1091 xg_menu_item_cb_data
*data
= (xg_menu_item_cb_data
*) client_data
;
1092 gpointer call_data
= event
->type
== GDK_LEAVE_NOTIFY
? 0 : client_data
;
1094 if (! NILP (data
->help
) && data
->cl_data
->highlight_cb
)
1096 GtkCallback func
= (GtkCallback
) data
->cl_data
->highlight_cb
;
1097 (*func
) (w
, call_data
);
1104 /* Callback called when a menu is destroyed. Used to free data.
1105 W is the widget that is being destroyed (not used).
1106 CLIENT_DATA points to the xg_menu_cb_data associated with W. */
1108 menu_destroy_callback (w
, client_data
)
1110 gpointer client_data
;
1112 unref_cl_data ((xg_menu_cb_data
*) client_data
);
1115 /* Callback called when a menu does a grab or ungrab. That means the
1116 menu has been activated or deactivated.
1117 Used to start a timer so the small timeout the menus in GTK uses before
1118 popping down a menu is seen by Emacs (see xg_process_timeouts above).
1119 W is the widget that does the grab (not used).
1120 UNGRAB_P is TRUE if this is an ungrab, FALSE if it is a grab.
1121 CLIENT_DATA is NULL (not used). */
1123 menu_grab_callback (GtkWidget
*widget
,
1125 gpointer client_data
)
1127 /* Keep track of total number of grabs. */
1130 if (ungrab_p
) cnt
--;
1133 if (cnt
> 0 && ! xg_timer
) xg_start_timer ();
1134 else if (cnt
== 0 && xg_timer
) xg_stop_timer ();
1137 /* Make a GTK widget that contains both UTF8_LABEL and UTF8_KEY (both
1138 must be non-NULL) and can be inserted into a menu item.
1140 Returns the GtkHBox. */
1142 make_widget_for_menu_item (utf8_label
, utf8_key
)
1150 wbox
= gtk_hbox_new (FALSE
, 0);
1151 wlbl
= gtk_label_new_with_mnemonic (utf8_label
);
1152 wkey
= gtk_label_new (utf8_key
);
1154 gtk_misc_set_alignment (GTK_MISC (wlbl
), 0.0, 0.5);
1155 gtk_misc_set_alignment (GTK_MISC (wkey
), 0.0, 0.5);
1157 gtk_box_pack_start (GTK_BOX (wbox
), wlbl
, TRUE
, TRUE
, 0);
1158 gtk_box_pack_start (GTK_BOX (wbox
), wkey
, FALSE
, FALSE
, 0);
1160 gtk_widget_set_name (wlbl
, MENU_ITEM_NAME
);
1161 gtk_widget_set_name (wkey
, MENU_ITEM_NAME
);
1166 /* Make and return a menu item widget with the key to the right.
1167 UTF8_LABEL is the text for the menu item (GTK uses UTF8 internally).
1168 UTF8_KEY is the text representing the key binding.
1169 ITEM is the widget_value describing the menu item.
1171 GROUP is an in/out parameter. If the menu item to be created is not
1172 part of any radio menu group, *GROUP contains NULL on entry and exit.
1173 If the menu item to be created is part of a radio menu group, on entry
1174 *GROUP contains the group to use, or NULL if this is the first item
1175 in the group. On exit, *GROUP contains the radio item group.
1177 Unfortunately, keys don't line up as nicely as in Motif,
1178 but the MacOS X version doesn't either, so I guess that is OK. */
1180 make_menu_item (utf8_label
, utf8_key
, item
, group
)
1187 GtkWidget
*wtoadd
= 0;
1190 wtoadd
= make_widget_for_menu_item (utf8_label
, utf8_key
);
1192 if (item
->button_type
== BUTTON_TYPE_TOGGLE
)
1195 if (utf8_key
) w
= gtk_check_menu_item_new ();
1196 else w
= gtk_check_menu_item_new_with_mnemonic (utf8_label
);
1197 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), item
->selected
);
1199 else if (item
->button_type
== BUTTON_TYPE_RADIO
)
1201 if (utf8_key
) w
= gtk_radio_menu_item_new (*group
);
1202 else w
= gtk_radio_menu_item_new_with_mnemonic (*group
, utf8_label
);
1203 *group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (w
));
1205 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), TRUE
);
1210 if (utf8_key
) w
= gtk_menu_item_new ();
1211 else w
= gtk_menu_item_new_with_mnemonic (utf8_label
);
1214 if (wtoadd
) gtk_container_add (GTK_CONTAINER (w
), wtoadd
);
1215 if (! item
->enabled
) gtk_widget_set_sensitive (w
, FALSE
);
1220 /* Return non-zero if NAME specifies a separator (GTK only has one
1223 xg_separator_p (char *name
)
1225 if (! name
) return 0;
1227 return strcmp (name
, "--") == 0
1228 || strncmp (name
, "--:", 3) == 0
1229 || strcmp (name
, "---") == 0;
1232 GtkWidget
*xg_did_tearoff
;
1234 /* Callback invoked when a detached menu window is removed. Here we
1235 delete the popup menu.
1236 WIDGET is the top level window that is removed (the parent of the menu).
1237 EVENT is the event that triggers the window removal.
1238 CLIENT_DATA points to the menu that is detached.
1240 Returns TRUE to tell GTK to stop processing this event. */
1242 tearoff_remove (widget
, event
, client_data
)
1245 gpointer client_data
;
1247 gtk_widget_destroy (GTK_WIDGET (client_data
));
1251 /* Callback invoked when a menu is detached. It sets the xg_did_tearoff
1253 WIDGET is the GtkTearoffMenuItem.
1254 CLIENT_DATA is not used. */
1256 tearoff_activate (widget
, client_data
)
1258 gpointer client_data
;
1260 GtkWidget
*menu
= gtk_widget_get_parent (widget
);
1261 if (! gtk_menu_get_tearoff_state (GTK_MENU (menu
)))
1264 xg_did_tearoff
= menu
;
1267 /* If a detach of a popup menu is done, this function should be called
1268 to keep the menu around until the detached window is removed.
1269 MENU is the top level menu for the popup,
1270 SUBMENU is the menu that got detached (that is MENU or a
1271 submenu of MENU), see the xg_did_tearoff variable. */
1273 xg_keep_popup (menu
, submenu
)
1279 /* Find the top widget for the detached menu. */
1280 p
= gtk_widget_get_toplevel (submenu
);
1282 /* Delay destroying the menu until the detached menu is removed. */
1283 g_signal_connect (G_OBJECT (p
), "unmap_event",
1284 G_CALLBACK (tearoff_remove
), menu
);
1289 /* Create a menu item widget, and connect the callbacks.
1290 ITEM decribes the menu item.
1291 F is the frame the created menu belongs to.
1292 SELECT_CB is the callback to use when a menu item is selected.
1293 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1294 CL_DATA points to the callback data to be used for this menu.
1295 GROUP is an in/out parameter. If the menu item to be created is not
1296 part of any radio menu group, *GROUP contains NULL on entry and exit.
1297 If the menu item to be created is part of a radio menu group, on entry
1298 *GROUP contains the group to use, or NULL if this is the first item
1299 in the group. On exit, *GROUP contains the radio item group.
1301 Returns the created GtkWidget. */
1303 xg_create_one_menuitem (item
, f
, select_cb
, highlight_cb
, cl_data
, group
)
1306 GCallback select_cb
;
1307 GCallback highlight_cb
;
1308 xg_menu_cb_data
*cl_data
;
1314 xg_menu_item_cb_data
*cb_data
;
1316 utf8_label
= get_utf8_string (item
->name
);
1317 utf8_key
= get_utf8_string (item
->key
);
1319 w
= make_menu_item (utf8_label
, utf8_key
, item
, group
);
1321 if (utf8_label
&& utf8_label
!= item
->name
) g_free (utf8_label
);
1322 if (utf8_key
&& utf8_key
!= item
->key
) g_free (utf8_key
);
1324 cb_data
= xmalloc (sizeof (xg_menu_item_cb_data
));
1326 xg_list_insert (&xg_menu_item_cb_list
, &cb_data
->ptrs
);
1328 cb_data
->unhighlight_id
= cb_data
->highlight_id
= cb_data
->select_id
= 0;
1329 cb_data
->help
= item
->help
;
1330 cb_data
->cl_data
= cl_data
;
1331 cb_data
->call_data
= item
->call_data
;
1333 g_signal_connect (G_OBJECT (w
),
1335 G_CALLBACK (menuitem_destroy_callback
),
1338 /* Put cb_data in widget, so we can get at it when modifying menubar */
1339 g_object_set_data (G_OBJECT (w
), XG_ITEM_DATA
, cb_data
);
1341 /* final item, not a submenu */
1342 if (item
->call_data
&& ! item
->contents
)
1346 = g_signal_connect (G_OBJECT (w
), "activate", select_cb
, cb_data
);
1349 if (! NILP (item
->help
) && highlight_cb
)
1351 /* We use enter/leave notify instead of select/deselect because
1352 select/deselect doesn't go well with detached menus. */
1353 cb_data
->highlight_id
1354 = g_signal_connect (G_OBJECT (w
),
1355 "enter-notify-event",
1356 G_CALLBACK (menuitem_highlight_callback
),
1358 cb_data
->unhighlight_id
1359 = g_signal_connect (G_OBJECT (w
),
1360 "leave-notify-event",
1361 G_CALLBACK (menuitem_highlight_callback
),
1368 static GtkWidget
*create_menus
P_ ((widget_value
*, FRAME_PTR
, GCallback
,
1369 GCallback
, GCallback
, int, int, int,
1370 GtkWidget
*, xg_menu_cb_data
*, char *));
1372 /* Create a full menu tree specified by DATA.
1373 F is the frame the created menu belongs to.
1374 SELECT_CB is the callback to use when a menu item is selected.
1375 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
1376 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1377 POP_UP_P is non-zero if we shall create a popup menu.
1378 MENU_BAR_P is non-zero if we shall create a menu bar.
1379 ADD_TEAROFF_P is non-zero if we shall add a teroff menu item. Ignored
1380 if MENU_BAR_P is non-zero.
1381 TOPMENU is the topmost GtkWidget that others shall be placed under.
1382 It may be NULL, in that case we create the appropriate widget
1383 (menu bar or menu item depending on POP_UP_P and MENU_BAR_P)
1384 CL_DATA is the callback data we shall use for this menu, or NULL
1385 if we haven't set the first callback yet.
1386 NAME is the name to give to the top level menu if this function
1387 creates it. May be NULL to not set any name.
1389 Returns the top level GtkWidget. This is TOPLEVEL if TOPLEVEL is
1392 This function calls itself to create submenus. */
1395 create_menus (data
, f
, select_cb
, deactivate_cb
, highlight_cb
,
1396 pop_up_p
, menu_bar_p
, add_tearoff_p
, topmenu
, cl_data
, name
)
1399 GCallback select_cb
;
1400 GCallback deactivate_cb
;
1401 GCallback highlight_cb
;
1406 xg_menu_cb_data
*cl_data
;
1410 GtkWidget
*wmenu
= topmenu
;
1411 GSList
*group
= NULL
;
1415 if (! menu_bar_p
) wmenu
= gtk_menu_new ();
1416 else wmenu
= gtk_menu_bar_new ();
1418 /* Put cl_data on the top menu for easier access. */
1419 cl_data
= make_cl_data (cl_data
, f
, highlight_cb
);
1420 g_object_set_data (G_OBJECT (wmenu
), XG_FRAME_DATA
, (gpointer
)cl_data
);
1421 g_signal_connect (G_OBJECT (wmenu
), "destroy",
1422 G_CALLBACK (menu_destroy_callback
), cl_data
);
1425 gtk_widget_set_name (wmenu
, name
);
1428 g_signal_connect (G_OBJECT (wmenu
),
1429 "deactivate", deactivate_cb
, 0);
1431 g_signal_connect (G_OBJECT (wmenu
),
1432 "grab-notify", G_CALLBACK (menu_grab_callback
), 0);
1435 if (! menu_bar_p
&& add_tearoff_p
)
1437 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new ();
1438 gtk_menu_shell_append (GTK_MENU_SHELL (wmenu
), tearoff
);
1440 g_signal_connect (G_OBJECT (tearoff
), "activate",
1441 G_CALLBACK (tearoff_activate
), 0);
1444 for (item
= data
; item
; item
= item
->next
)
1448 if (pop_up_p
&& !item
->contents
&& !item
->call_data
1449 && !xg_separator_p (item
->name
))
1452 /* A title for a popup. We do the same as GTK does when
1453 creating titles, but it does not look good. */
1455 utf8_label
= get_utf8_string (item
->name
);
1457 gtk_menu_set_title (GTK_MENU (wmenu
), utf8_label
);
1458 w
= gtk_menu_item_new_with_mnemonic (utf8_label
);
1459 gtk_widget_set_sensitive (w
, FALSE
);
1460 if (utf8_label
&& utf8_label
!= item
->name
) g_free (utf8_label
);
1462 else if (xg_separator_p (item
->name
))
1465 /* GTK only have one separator type. */
1466 w
= gtk_separator_menu_item_new ();
1470 w
= xg_create_one_menuitem (item
,
1472 item
->contents
? 0 : select_cb
,
1479 GtkWidget
*submenu
= create_menus (item
->contents
,
1490 gtk_menu_item_set_submenu (GTK_MENU_ITEM (w
), submenu
);
1494 gtk_menu_shell_append (GTK_MENU_SHELL (wmenu
), w
);
1495 gtk_widget_set_name (w
, MENU_ITEM_NAME
);
1501 /* Create a menubar, popup menu or dialog, depending on the TYPE argument.
1502 TYPE can be "menubar", "popup" for popup menu, or "dialog" for a dialog
1503 with some text and buttons.
1504 F is the frame the created item belongs to.
1505 NAME is the name to use for the top widget.
1506 VAL is a widget_value structure describing items to be created.
1507 SELECT_CB is the callback to use when a menu item is selected or
1508 a dialog button is pressed.
1509 DEACTIVATE_CB is the callback to use when an item is deactivated.
1510 For a menu, when a sub menu is not shown anymore, for a dialog it is
1511 called when the dialog is popped down.
1512 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1514 Returns the widget created. */
1516 xg_create_widget (type
, name
, f
, val
,
1517 select_cb
, deactivate_cb
, highlight_cb
)
1522 GCallback select_cb
;
1523 GCallback deactivate_cb
;
1524 GCallback highlight_cb
;
1527 if (strcmp (type
, "dialog") == 0)
1529 w
= create_dialog (val
, select_cb
, deactivate_cb
);
1530 gtk_window_set_transient_for (GTK_WINDOW (w
),
1531 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
1532 gtk_window_set_destroy_with_parent (GTK_WINDOW (w
), TRUE
);
1535 gtk_widget_set_name (w
, "emacs-dialog");
1537 else if (strcmp (type
, "menubar") == 0 || strcmp (type
, "popup") == 0)
1539 w
= create_menus (val
->contents
,
1544 strcmp (type
, "popup") == 0,
1545 strcmp (type
, "menubar") == 0,
1551 /* Set the cursor to an arrow for popup menus when they are mapped.
1552 This is done by default for menu bar menus. */
1553 if (strcmp (type
, "popup") == 0)
1555 /* Must realize so the GdkWindow inside the widget is created. */
1556 gtk_widget_realize (w
);
1557 xg_set_cursor (w
, &xg_left_ptr_cursor
);
1562 fprintf (stderr
, "bad type in xg_create_widget: %s, doing nothing\n",
1569 /* Return the label for menu item WITEM. */
1571 xg_get_menu_item_label (witem
)
1574 GtkLabel
*wlabel
= GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem
)));
1575 return gtk_label_get_label (wlabel
);
1578 /* Return non-zero if the menu item WITEM has the text LABEL. */
1580 xg_item_label_same_p (witem
, label
)
1585 char *utf8_label
= get_utf8_string (label
);
1586 const char *old_label
= witem
? xg_get_menu_item_label (witem
) : 0;
1588 if (! old_label
&& ! utf8_label
)
1590 else if (old_label
&& utf8_label
)
1591 is_same
= strcmp (utf8_label
, old_label
) == 0;
1593 if (utf8_label
&& utf8_label
!= label
) g_free (utf8_label
);
1598 /* Remove widgets in LIST from container WCONT. */
1600 remove_from_container (wcont
, list
)
1606 for (iter
= list
; iter
; iter
= g_list_next (iter
))
1608 GtkWidget
*w
= GTK_WIDGET (iter
->data
);
1610 /* Add a ref to w so we can explicitly destroy it later. */
1612 gtk_container_remove (GTK_CONTAINER (wcont
), w
);
1614 /* If there is a menu under this widget that has been detached,
1615 there is a reference to it, and just removing w from the
1616 container does not destroy the submenu. By explicitly
1617 destroying w we make sure the submenu is destroyed, thus
1618 removing the detached window also if there was one. */
1619 gtk_widget_destroy (w
);
1623 /* Update the top level names in MENUBAR (i.e. not submenus).
1624 F is the frame the menu bar belongs to.
1625 *LIST is a list with the current menu bar names (menu item widgets).
1626 ITER is the item within *LIST that shall be updated.
1627 POS is the numerical position, starting at 0, of ITER in *LIST.
1628 VAL describes what the menu bar shall look like after the update.
1629 SELECT_CB is the callback to use when a menu item is selected.
1630 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1631 CL_DATA points to the callback data to be used for this menu bar.
1633 This function calls itself to walk through the menu bar names. */
1635 xg_update_menubar (menubar
, f
, list
, iter
, pos
, val
,
1636 select_cb
, highlight_cb
, cl_data
)
1643 GCallback select_cb
;
1644 GCallback highlight_cb
;
1645 xg_menu_cb_data
*cl_data
;
1647 if (! iter
&& ! val
)
1649 else if (iter
&& ! val
)
1651 /* Item(s) have been removed. Remove all remaining items. */
1652 remove_from_container (menubar
, iter
);
1658 else if (! iter
&& val
)
1660 /* Item(s) added. Add all new items in one call. */
1661 create_menus (val
, f
, select_cb
, 0, highlight_cb
,
1662 0, 1, 0, menubar
, cl_data
, 0);
1668 /* Below this neither iter or val is NULL */
1669 else if (xg_item_label_same_p (GTK_MENU_ITEM (iter
->data
), val
->name
))
1671 /* This item is still the same, check next item. */
1673 iter
= g_list_next (iter
);
1676 else /* This item is changed. */
1678 GtkMenuItem
*witem
= GTK_MENU_ITEM (iter
->data
);
1679 GtkMenuItem
*witem2
= 0;
1680 int val_in_menubar
= 0;
1681 int iter_in_new_menubar
= 0;
1685 /* See if the changed entry (val) is present later in the menu bar */
1687 iter2
&& ! val_in_menubar
;
1688 iter2
= g_list_next (iter2
))
1690 witem2
= GTK_MENU_ITEM (iter2
->data
);
1691 val_in_menubar
= xg_item_label_same_p (witem2
, val
->name
);
1694 /* See if the current entry (iter) is present later in the
1695 specification for the new menu bar. */
1696 for (cur
= val
; cur
&& ! iter_in_new_menubar
; cur
= cur
->next
)
1697 iter_in_new_menubar
= xg_item_label_same_p (witem
, cur
->name
);
1699 if (val_in_menubar
&& ! iter_in_new_menubar
)
1703 /* This corresponds to:
1708 gtk_widget_ref (GTK_WIDGET (witem
));
1709 gtk_container_remove (GTK_CONTAINER (menubar
), GTK_WIDGET (witem
));
1710 gtk_widget_destroy (GTK_WIDGET (witem
));
1712 /* Must get new list since the old changed. */
1713 g_list_free (*list
);
1714 *list
= iter
= gtk_container_get_children (GTK_CONTAINER (menubar
));
1715 while (nr
-- > 0) iter
= g_list_next (iter
);
1717 else if (! val_in_menubar
&& ! iter_in_new_menubar
)
1719 /* This corresponds to:
1722 Rename B to X. This might seem to be a strange thing to do,
1723 since if there is a menu under B it will be totally wrong for X.
1724 But consider editing a C file. Then there is a C-mode menu
1725 (corresponds to B above).
1726 If then doing C-x C-f the minibuf menu (X above) replaces the
1727 C-mode menu. When returning from the minibuffer, we get
1728 back the C-mode menu. Thus we do:
1729 Rename B to X (C-mode to minibuf menu)
1730 Rename X to B (minibuf to C-mode menu).
1731 If the X menu hasn't been invoked, the menu under B
1732 is up to date when leaving the minibuffer. */
1733 GtkLabel
*wlabel
= GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem
)));
1734 char *utf8_label
= get_utf8_string (val
->name
);
1736 gtk_label_set_text_with_mnemonic (wlabel
, utf8_label
);
1738 iter
= g_list_next (iter
);
1742 else if (! val_in_menubar
&& iter_in_new_menubar
)
1744 /* This corresponds to:
1751 GtkWidget
*w
= xg_create_one_menuitem (val
,
1758 gtk_widget_set_name (w
, MENU_ITEM_NAME
);
1759 gtk_menu_shell_insert (GTK_MENU_SHELL (menubar
), w
, pos
);
1761 g_list_free (*list
);
1762 *list
= iter
= gtk_container_get_children (GTK_CONTAINER (menubar
));
1763 while (nr
-- > 0) iter
= g_list_next (iter
);
1764 iter
= g_list_next (iter
);
1768 else /* if (val_in_menubar && iter_in_new_menubar) */
1771 /* This corresponds to:
1776 gtk_widget_ref (GTK_WIDGET (witem2
));
1777 gtk_container_remove (GTK_CONTAINER (menubar
), GTK_WIDGET (witem2
));
1778 gtk_menu_shell_insert (GTK_MENU_SHELL (menubar
),
1779 GTK_WIDGET (witem2
), pos
);
1780 gtk_widget_unref (GTK_WIDGET (witem2
));
1782 g_list_free (*list
);
1783 *list
= iter
= gtk_container_get_children (GTK_CONTAINER (menubar
));
1784 while (nr
-- > 0) iter
= g_list_next (iter
);
1790 /* Update the rest of the menu bar. */
1791 xg_update_menubar (menubar
, f
, list
, iter
, pos
, val
,
1792 select_cb
, highlight_cb
, cl_data
);
1795 /* Update the menu item W so it corresponds to VAL.
1796 SELECT_CB is the callback to use when a menu item is selected.
1797 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1798 CL_DATA is the data to set in the widget for menu invokation. */
1800 xg_update_menu_item (val
, w
, select_cb
, highlight_cb
, cl_data
)
1803 GCallback select_cb
;
1804 GCallback highlight_cb
;
1805 xg_menu_cb_data
*cl_data
;
1812 const char *old_label
= 0;
1813 const char *old_key
= 0;
1814 xg_menu_item_cb_data
*cb_data
;
1816 wchild
= gtk_bin_get_child (GTK_BIN (w
));
1817 utf8_label
= get_utf8_string (val
->name
);
1818 utf8_key
= get_utf8_string (val
->key
);
1820 /* See if W is a menu item with a key. See make_menu_item above. */
1821 if (GTK_IS_HBOX (wchild
))
1823 GList
*list
= gtk_container_get_children (GTK_CONTAINER (wchild
));
1825 wlbl
= GTK_LABEL (list
->data
);
1826 wkey
= GTK_LABEL (list
->next
->data
);
1831 /* Remove the key and keep just the label. */
1832 gtk_widget_ref (GTK_WIDGET (wlbl
));
1833 gtk_container_remove (GTK_CONTAINER (w
), wchild
);
1834 gtk_container_add (GTK_CONTAINER (w
), GTK_WIDGET (wlbl
));
1839 else /* Just a label. */
1841 wlbl
= GTK_LABEL (wchild
);
1843 /* Check if there is now a key. */
1846 GtkWidget
*wtoadd
= make_widget_for_menu_item (utf8_label
, utf8_key
);
1847 GList
*list
= gtk_container_get_children (GTK_CONTAINER (wtoadd
));
1849 wlbl
= GTK_LABEL (list
->data
);
1850 wkey
= GTK_LABEL (list
->next
->data
);
1853 gtk_container_remove (GTK_CONTAINER (w
), wchild
);
1854 gtk_container_add (GTK_CONTAINER (w
), wtoadd
);
1859 if (wkey
) old_key
= gtk_label_get_label (wkey
);
1860 if (wlbl
) old_label
= gtk_label_get_label (wlbl
);
1862 if (wkey
&& utf8_key
&& (! old_key
|| strcmp (utf8_key
, old_key
) != 0))
1863 gtk_label_set_text (wkey
, utf8_key
);
1865 if (! old_label
|| strcmp (utf8_label
, old_label
) != 0)
1866 gtk_label_set_text_with_mnemonic (wlbl
, utf8_label
);
1868 if (utf8_key
&& utf8_key
!= val
->key
) g_free (utf8_key
);
1869 if (utf8_label
&& utf8_label
!= val
->name
) g_free (utf8_label
);
1871 if (! val
->enabled
&& GTK_WIDGET_SENSITIVE (w
))
1872 gtk_widget_set_sensitive (w
, FALSE
);
1873 else if (val
->enabled
&& ! GTK_WIDGET_SENSITIVE (w
))
1874 gtk_widget_set_sensitive (w
, TRUE
);
1876 cb_data
= (xg_menu_item_cb_data
*) g_object_get_data (G_OBJECT (w
),
1880 cb_data
->call_data
= val
->call_data
;
1881 cb_data
->help
= val
->help
;
1882 cb_data
->cl_data
= cl_data
;
1884 /* We assume the callback functions don't change. */
1885 if (val
->call_data
&& ! val
->contents
)
1887 /* This item shall have a select callback. */
1888 if (! cb_data
->select_id
)
1890 = g_signal_connect (G_OBJECT (w
), "activate",
1891 select_cb
, cb_data
);
1893 else if (cb_data
->select_id
)
1895 g_signal_handler_disconnect (w
, cb_data
->select_id
);
1896 cb_data
->select_id
= 0;
1899 if (NILP (cb_data
->help
))
1901 /* Shall not have help. Remove if any existed previously. */
1902 if (cb_data
->highlight_id
)
1904 g_signal_handler_disconnect (G_OBJECT (w
),
1905 cb_data
->highlight_id
);
1906 cb_data
->highlight_id
= 0;
1908 if (cb_data
->unhighlight_id
)
1910 g_signal_handler_disconnect (G_OBJECT (w
),
1911 cb_data
->unhighlight_id
);
1912 cb_data
->unhighlight_id
= 0;
1915 else if (! cb_data
->highlight_id
&& highlight_cb
)
1917 /* Have help now, but didn't previously. Add callback. */
1918 cb_data
->highlight_id
1919 = g_signal_connect (G_OBJECT (w
),
1920 "enter-notify-event",
1921 G_CALLBACK (menuitem_highlight_callback
),
1923 cb_data
->unhighlight_id
1924 = g_signal_connect (G_OBJECT (w
),
1925 "leave-notify-event",
1926 G_CALLBACK (menuitem_highlight_callback
),
1932 /* Update the toggle menu item W so it corresponds to VAL. */
1934 xg_update_toggle_item (val
, w
)
1938 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), val
->selected
);
1941 /* Update the radio menu item W so it corresponds to VAL. */
1943 xg_update_radio_item (val
, w
)
1947 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), val
->selected
);
1950 /* Update the sub menu SUBMENU and all its children so it corresponds to VAL.
1951 SUBMENU may be NULL, in that case a new menu is created.
1952 F is the frame the menu bar belongs to.
1953 VAL describes the contents of the menu bar.
1954 SELECT_CB is the callback to use when a menu item is selected.
1955 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
1956 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1957 CL_DATA is the call back data to use for any newly created items.
1959 Returns the updated submenu widget, that is SUBMENU unless SUBMENU
1963 xg_update_submenu (submenu
, f
, val
,
1964 select_cb
, deactivate_cb
, highlight_cb
, cl_data
)
1968 GCallback select_cb
;
1969 GCallback deactivate_cb
;
1970 GCallback highlight_cb
;
1971 xg_menu_cb_data
*cl_data
;
1973 GtkWidget
*newsub
= submenu
;
1977 int has_tearoff_p
= 0;
1978 GList
*first_radio
= 0;
1981 list
= gtk_container_get_children (GTK_CONTAINER (submenu
));
1983 for (cur
= val
, iter
= list
;
1985 iter
= g_list_next (iter
), cur
= cur
->next
)
1987 GtkWidget
*w
= GTK_WIDGET (iter
->data
);
1989 /* Skip tearoff items, they have no counterpart in val. */
1990 if (GTK_IS_TEAROFF_MENU_ITEM (w
))
1993 iter
= g_list_next (iter
);
1994 if (iter
) w
= GTK_WIDGET (iter
->data
);
1998 /* Remember first radio button in a group. If we get a mismatch in
1999 a radio group we must rebuild the whole group so that the connections
2000 in GTK becomes correct. */
2001 if (cur
->button_type
== BUTTON_TYPE_RADIO
&& ! first_radio
)
2003 else if (cur
->button_type
!= BUTTON_TYPE_RADIO
2004 && ! GTK_IS_RADIO_MENU_ITEM (w
))
2007 if (GTK_IS_SEPARATOR_MENU_ITEM (w
))
2009 if (! xg_separator_p (cur
->name
))
2012 else if (GTK_IS_CHECK_MENU_ITEM (w
))
2014 if (cur
->button_type
!= BUTTON_TYPE_TOGGLE
)
2016 xg_update_toggle_item (cur
, w
);
2017 xg_update_menu_item (cur
, w
, select_cb
, highlight_cb
, cl_data
);
2019 else if (GTK_IS_RADIO_MENU_ITEM (w
))
2021 if (cur
->button_type
!= BUTTON_TYPE_RADIO
)
2023 xg_update_radio_item (cur
, w
);
2024 xg_update_menu_item (cur
, w
, select_cb
, highlight_cb
, cl_data
);
2026 else if (GTK_IS_MENU_ITEM (w
))
2028 GtkMenuItem
*witem
= GTK_MENU_ITEM (w
);
2031 if (cur
->button_type
!= BUTTON_TYPE_NONE
||
2032 xg_separator_p (cur
->name
))
2035 xg_update_menu_item (cur
, w
, select_cb
, highlight_cb
, cl_data
);
2037 sub
= gtk_menu_item_get_submenu (witem
);
2038 if (sub
&& ! cur
->contents
)
2040 /* Not a submenu anymore. */
2041 gtk_widget_ref (sub
);
2042 gtk_menu_item_remove_submenu (witem
);
2043 gtk_widget_destroy (sub
);
2045 else if (cur
->contents
)
2049 nsub
= xg_update_submenu (sub
, f
, cur
->contents
,
2050 select_cb
, deactivate_cb
,
2051 highlight_cb
, cl_data
);
2053 /* If this item just became a submenu, we must set it. */
2055 gtk_menu_item_set_submenu (witem
, nsub
);
2060 /* Structural difference. Remove everything from here and down
2066 /* Remove widgets from first structual change. */
2069 /* If we are adding new menu items below, we must remove from
2070 first radio button so that radio groups become correct. */
2071 if (cur
&& first_radio
) remove_from_container (submenu
, first_radio
);
2072 else remove_from_container (submenu
, iter
);
2077 /* More items added. Create them. */
2078 newsub
= create_menus (cur
,
2091 if (list
) g_list_free (list
);
2096 /* Update the MENUBAR.
2097 F is the frame the menu bar belongs to.
2098 VAL describes the contents of the menu bar.
2099 If DEEP_P is non-zero, rebuild all but the top level menu names in
2100 the MENUBAR. If DEEP_P is zero, just rebuild the names in the menubar.
2101 SELECT_CB is the callback to use when a menu item is selected.
2102 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
2103 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. */
2105 xg_modify_menubar_widgets (menubar
, f
, val
, deep_p
,
2106 select_cb
, deactivate_cb
, highlight_cb
)
2111 GCallback select_cb
;
2112 GCallback deactivate_cb
;
2113 GCallback highlight_cb
;
2115 xg_menu_cb_data
*cl_data
;
2116 GList
*list
= gtk_container_get_children (GTK_CONTAINER (menubar
));
2120 cl_data
= (xg_menu_cb_data
*) g_object_get_data (G_OBJECT (menubar
),
2125 widget_value
*cur
= val
->contents
;
2126 xg_update_menubar (menubar
, f
, &list
, list
, 0, cur
,
2127 select_cb
, highlight_cb
, cl_data
);
2133 /* Update all sub menus.
2134 We must keep the submenu names (GTK menu item widgets) since the
2135 X Window in the XEvent that activates the menu are those widgets. */
2137 /* Update cl_data, menu_item things in F may have changed. */
2138 update_cl_data (cl_data
, f
, highlight_cb
);
2140 for (cur
= val
->contents
; cur
; cur
= cur
->next
)
2147 /* Find sub menu that corresponds to val and update it. */
2148 for (iter
= list
; iter
; iter
= g_list_next (iter
))
2150 witem
= GTK_MENU_ITEM (iter
->data
);
2151 if (xg_item_label_same_p (witem
, cur
->name
))
2153 sub
= gtk_menu_item_get_submenu (witem
);
2158 newsub
= xg_update_submenu (sub
,
2165 /* sub may still be NULL. If we just updated non deep and added
2166 a new menu bar item, it has no sub menu yet. So we set the
2167 newly created sub menu under witem. */
2169 gtk_menu_item_set_submenu (witem
, newsub
);
2175 gtk_widget_show_all (menubar
);
2178 /* Recompute all the widgets of frame F, when the menu bar has been
2179 changed. Value is non-zero if widgets were updated. */
2182 xg_update_frame_menubar (f
)
2185 struct x_output
*x
= f
->output_data
.x
;
2188 if (!x
->menubar_widget
|| GTK_WIDGET_MAPPED (x
->menubar_widget
))
2193 gtk_box_pack_start (GTK_BOX (x
->vbox_widget
), x
->menubar_widget
,
2195 gtk_box_reorder_child (GTK_BOX (x
->vbox_widget
), x
->menubar_widget
, 0);
2197 gtk_widget_show_all (x
->menubar_widget
);
2198 gtk_widget_size_request (x
->menubar_widget
, &req
);
2200 FRAME_MENUBAR_HEIGHT (f
) = req
.height
;
2202 /* The height has changed, resize outer widget and set columns
2203 rows to what we had before adding the menu bar. */
2204 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2206 SET_FRAME_GARBAGED (f
);
2212 /* Get rid of the menu bar of frame F, and free its storage.
2213 This is used when deleting a frame, and when turning off the menu bar. */
2216 free_frame_menubar (f
)
2219 struct x_output
*x
= f
->output_data
.x
;
2221 if (x
->menubar_widget
)
2225 gtk_container_remove (GTK_CONTAINER (x
->vbox_widget
), x
->menubar_widget
);
2226 /* The menubar and its children shall be deleted when removed from
2228 x
->menubar_widget
= 0;
2229 FRAME_MENUBAR_HEIGHT (f
) = 0;
2231 /* The height has changed, resize outer widget and set columns
2232 rows to what we had before removing the menu bar. */
2233 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2235 SET_FRAME_GARBAGED (f
);
2242 /***********************************************************************
2243 Scroll bar functions
2244 ***********************************************************************/
2247 /* Setting scroll bar values invokes the callback. Use this variable
2248 to indicate that callback should do nothing. */
2249 int xg_ignore_gtk_scrollbar
;
2251 /* SET_SCROLL_BAR_X_WINDOW assumes the second argument fits in
2252 32 bits. But we want to store pointers, and they may be larger
2253 than 32 bits. Keep a mapping from integer index to widget pointers
2254 to get around the 32 bit limitation. */
2257 GtkWidget
**widgets
;
2262 /* Grow this much every time we need to allocate more */
2263 #define ID_TO_WIDGET_INCR 32
2265 /* Store the widget pointer W in id_to_widget and return the integer index. */
2267 xg_store_widget_in_map (w
)
2272 if (id_to_widget
.max_size
== id_to_widget
.used
)
2274 int new_size
= id_to_widget
.max_size
+ ID_TO_WIDGET_INCR
;
2276 id_to_widget
.widgets
= xrealloc (id_to_widget
.widgets
,
2277 sizeof (GtkWidget
*)*new_size
);
2279 for (i
= id_to_widget
.max_size
; i
< new_size
; ++i
)
2280 id_to_widget
.widgets
[i
] = 0;
2281 id_to_widget
.max_size
= new_size
;
2284 /* Just loop over the array and find a free place. After all,
2285 how many scroll bars are we creating? Should be a small number.
2286 The check above guarantees we will find a free place. */
2287 for (i
= 0; i
< id_to_widget
.max_size
; ++i
)
2289 if (! id_to_widget
.widgets
[i
])
2291 id_to_widget
.widgets
[i
] = w
;
2292 ++id_to_widget
.used
;
2298 /* Should never end up here */
2302 /* Remove pointer at IDX from id_to_widget.
2303 Called when scroll bar is destroyed. */
2305 xg_remove_widget_from_map (idx
)
2308 if (idx
< id_to_widget
.max_size
&& id_to_widget
.widgets
[idx
] != 0)
2310 id_to_widget
.widgets
[idx
] = 0;
2311 --id_to_widget
.used
;
2315 /* Get the widget pointer at IDX from id_to_widget. */
2317 xg_get_widget_from_map (idx
)
2320 if (idx
< id_to_widget
.max_size
&& id_to_widget
.widgets
[idx
] != 0)
2321 return id_to_widget
.widgets
[idx
];
2326 /* Return the scrollbar id for X Window WID.
2327 Return -1 if WID not in id_to_widget. */
2329 xg_get_scroll_id_for_window (wid
)
2335 w
= xg_win_to_widget (wid
);
2339 for (idx
= 0; idx
< id_to_widget
.max_size
; ++idx
)
2340 if (id_to_widget
.widgets
[idx
] == w
)
2347 /* Callback invoked when scroll bar WIDGET is destroyed.
2348 DATA is the index into id_to_widget for WIDGET.
2349 We free pointer to last scroll bar values here and remove the index. */
2351 xg_gtk_scroll_destroy (widget
, data
)
2358 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
2360 xg_remove_widget_from_map (id
);
2363 /* Callback for button press/release events. Used to start timer so that
2364 the scroll bar repetition timer in GTK gets handeled.
2365 Also, sets bar->dragging to Qnil when dragging (button release) is done.
2366 WIDGET is the scroll bar widget the event is for (not used).
2367 EVENT contains the event.
2368 USER_DATA points to the struct scrollbar structure.
2370 Returns FALSE to tell GTK that it shall continue propagate the event
2373 scroll_bar_button_cb (widget
, event
, user_data
)
2375 GdkEventButton
*event
;
2378 if (event
->type
== GDK_BUTTON_PRESS
&& ! xg_timer
)
2380 else if (event
->type
== GDK_BUTTON_RELEASE
)
2382 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
2383 if (xg_timer
) xg_stop_timer ();
2384 bar
->dragging
= Qnil
;
2390 /* Create a scroll bar widget for frame F. Store the scroll bar
2392 SCROLL_CALLBACK is the callback to invoke when the value of the
2394 SCROLL_BAR_NAME is the name we use for the scroll bar. Can be used
2395 to set resources for the widget. */
2397 xg_create_scroll_bar (f
, bar
, scroll_callback
, scroll_bar_name
)
2399 struct scroll_bar
*bar
;
2400 GCallback scroll_callback
;
2401 char *scroll_bar_name
;
2407 /* Page, step increment values are not so important here, they
2408 will be corrected in x_set_toolkit_scroll_bar_thumb. */
2409 vadj
= gtk_adjustment_new (XG_SB_MIN
, XG_SB_MIN
, XG_SB_MAX
,
2412 wscroll
= gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj
));
2413 gtk_widget_set_name (wscroll
, scroll_bar_name
);
2414 gtk_range_set_update_policy (GTK_RANGE (wscroll
), GTK_UPDATE_CONTINUOUS
);
2416 scroll_id
= xg_store_widget_in_map (wscroll
);
2418 g_signal_connect (G_OBJECT (vadj
),
2422 g_signal_connect (G_OBJECT (wscroll
),
2424 G_CALLBACK (xg_gtk_scroll_destroy
),
2425 (gpointer
)scroll_id
);
2427 /* Connect to button press and button release to detect if any scroll bar
2429 g_signal_connect (G_OBJECT (wscroll
),
2430 "button-press-event",
2431 G_CALLBACK (scroll_bar_button_cb
),
2433 g_signal_connect (G_OBJECT (wscroll
),
2434 "button-release-event",
2435 G_CALLBACK (scroll_bar_button_cb
),
2438 gtk_fixed_put (GTK_FIXED (f
->output_data
.x
->edit_widget
),
2441 /* Set the cursor to an arrow. */
2442 xg_set_cursor (wscroll
, &xg_left_ptr_cursor
);
2444 SET_SCROLL_BAR_X_WINDOW (bar
, scroll_id
);
2447 /* Make the scroll bar represented by SCROLLBAR_ID visible. */
2449 xg_show_scroll_bar (scrollbar_id
)
2452 GtkWidget
*w
= xg_get_widget_from_map (scrollbar_id
);
2454 gtk_widget_show (w
);
2457 /* Remove the scroll bar represented by SCROLLBAR_ID from the frame F. */
2459 xg_remove_scroll_bar (f
, scrollbar_id
)
2463 GtkWidget
*w
= xg_get_widget_from_map (scrollbar_id
);
2466 gtk_widget_destroy (w
);
2467 SET_FRAME_GARBAGED (f
);
2471 /* Find left/top for widget W in GtkFixed widget WFIXED. */
2473 xg_find_top_left_in_fixed (w
, wfixed
, left
, top
)
2474 GtkWidget
*w
, *wfixed
;
2479 for (iter
= GTK_FIXED (wfixed
)->children
; iter
; iter
= g_list_next (iter
))
2481 GtkFixedChild
*child
= (GtkFixedChild
*) iter
->data
;
2483 if (child
->widget
== w
)
2491 /* Shall never end up here. */
2495 /* Update the position of the vertical scroll bar represented by SCROLLBAR_ID
2497 TOP/LEFT are the new pixel positions where the bar shall appear.
2498 WIDTH, HEIGHT is the size in pixels the bar shall have. */
2500 xg_update_scrollbar_pos (f
, scrollbar_id
, top
, left
, width
, height
)
2509 GtkWidget
*wscroll
= xg_get_widget_from_map (scrollbar_id
);
2513 GtkWidget
*wfixed
= f
->output_data
.x
->edit_widget
;
2514 int gheight
= max (height
, 1);
2515 int canon_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
2516 int winextra
= canon_width
> width
? (canon_width
- width
) / 2 : 0;
2517 int bottom
= top
+ gheight
;
2520 int oldtop
, oldleft
, oldbottom
;
2523 /* Get old values. */
2524 xg_find_top_left_in_fixed (wscroll
, wfixed
, &oldleft
, &oldtop
);
2525 gtk_widget_size_request (wscroll
, &req
);
2526 oldbottom
= oldtop
+ req
.height
;
2528 /* Scroll bars in GTK has a fixed width, so if we say width 16, it
2529 will only be its fixed width (14 is default) anyway, the rest is
2530 blank. We are drawing the mode line across scroll bars when
2538 When we "unsplit" the frame:
2547 the remains of the mode line can be seen in these blank spaces.
2548 So we must clear them explicitly.
2549 GTK scroll bars should do that, but they don't.
2550 Also, the scroll bar canonical width may be wider than the width
2553 if (oldtop
!= -1 && oldleft
!= -1)
2557 int bottomdiff
, topdiff
;
2559 gtk_widget_style_get (wscroll
, "slider_width", &slider_width
, NULL
);
2560 gtkextra
= width
> slider_width
? (width
- slider_width
) / 2 : 0;
2562 xl
= left
- winextra
;
2563 wblank
= gtkextra
+ winextra
;
2564 xr
= left
+ gtkextra
+ slider_width
;
2565 bottomdiff
= abs (oldbottom
- bottom
);
2566 topdiff
= abs (oldtop
- top
);
2570 gdk_window_clear_area (wfixed
->window
, xl
, top
, wblank
, topdiff
);
2571 gdk_window_clear_area (wfixed
->window
, xr
, top
, wblank
, topdiff
);
2573 else if (oldtop
< top
)
2575 gdk_window_clear_area (wfixed
->window
, xl
, oldtop
, wblank
,
2577 gdk_window_clear_area (wfixed
->window
, xr
, oldtop
, wblank
,
2581 if (oldbottom
> bottom
)
2583 gdk_window_clear_area (wfixed
->window
, xl
, bottom
, wblank
,
2585 gdk_window_clear_area (wfixed
->window
, xr
, bottom
, wblank
,
2588 else if (oldbottom
< bottom
)
2590 gdk_window_clear_area (wfixed
->window
, xl
, oldbottom
, wblank
,
2592 gdk_window_clear_area (wfixed
->window
, xr
, oldbottom
, wblank
,
2597 /* Move and resize to new values. */
2598 gtk_fixed_move (GTK_FIXED (wfixed
), wscroll
, left
, top
);
2599 gtk_widget_set_size_request (wscroll
, width
, gheight
);
2601 gtk_container_set_reallocate_redraws (GTK_CONTAINER (wfixed
), TRUE
);
2603 /* Make GTK draw the new sizes. We are not using a pure GTK event
2604 loop so we need to do this. */
2605 gdk_window_process_all_updates ();
2607 SET_FRAME_GARBAGED (f
);
2608 cancel_mouse_face (f
);
2612 /* Set the thumb size and position of scroll bar BAR. We are currently
2613 displaying PORTION out of a whole WHOLE, and our position POSITION. */
2615 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
2616 struct scroll_bar
*bar
;
2617 int portion
, position
, whole
;
2619 GtkWidget
*wscroll
= xg_get_widget_from_map (SCROLL_BAR_X_WINDOW (bar
));
2621 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2625 if (wscroll
&& NILP (bar
->dragging
))
2631 int new_upper
, new_step
;
2633 adj
= gtk_range_get_adjustment (GTK_RANGE (wscroll
));
2635 /* We do the same as for MOTIF in xterm.c, assume 30 chars per line
2636 rather than the real portion value. This makes the thumb less likely
2637 to resize and that looks better. */
2638 portion
= XFASTINT (XWINDOW (bar
->window
)->height
) * 30;
2639 /* When the thumb is at the bottom, position == whole.
2640 So we need to increase `whole' to make space for the thumb. */
2647 shown
= (gdouble
) portion
/ whole
;
2648 top
= (gdouble
) position
/ whole
;
2651 size
= shown
* whole
;
2652 size
= min (size
, whole
);
2653 size
= max (size
, 1);
2655 value
= top
* whole
;
2656 value
= min (value
, whole
- size
);
2657 value
= max (value
, XG_SB_MIN
);
2659 /* gtk_range_set_value invokes the callback. Set
2660 ignore_gtk_scrollbar to make the callback do nothing */
2661 xg_ignore_gtk_scrollbar
= 1;
2663 new_upper
= max (whole
, size
);
2664 new_step
= portion
/ max (1, FRAME_HEIGHT (f
));
2666 if ((int) adj
->page_size
!= size
2667 || (int) adj
->upper
!= new_upper
2668 || (int) adj
->step_increment
!= new_step
)
2670 adj
->page_size
= (int) size
;
2672 gtk_range_set_range (GTK_RANGE (wscroll
), adj
->lower
,
2673 (gdouble
) new_upper
);
2675 /* Assume all lines are of equal size. */
2676 /* Assume a page increment is about 95% of the page size */
2677 gtk_range_set_increments (GTK_RANGE (wscroll
),
2678 portion
/ max (1, FRAME_HEIGHT (f
)),
2679 (int) (0.95*adj
->page_size
));
2683 if ((int) gtk_range_get_value (GTK_RANGE (wscroll
)) != value
)
2684 gtk_range_set_value (GTK_RANGE (wscroll
), (gdouble
)value
);
2686 xg_ignore_gtk_scrollbar
= 0;
2688 /* Make GTK draw the new thumb. We are not using a pure GTK event
2689 loop so we need to do this. */
2690 gdk_window_process_all_updates ();
2697 /***********************************************************************
2699 ***********************************************************************/
2700 /* The key for the data we put in the GtkImage widgets. The data is
2701 the image used by Emacs. We use this to see if we need to update
2702 the GtkImage with a new image. */
2703 #define XG_TOOL_BAR_IMAGE_DATA "emacs-tool-bar-image"
2705 /* Callback function invoked when a tool bar item is pressed.
2706 W is the button widget in the tool bar that got pressed,
2707 CLIENT_DATA is an integer that is the index of the button in the
2708 tool bar. 0 is the first button. */
2710 xg_tool_bar_callback (w
, client_data
)
2712 gpointer client_data
;
2714 int idx
= (int)client_data
;
2715 FRAME_PTR f
= (FRAME_PTR
) g_object_get_data (G_OBJECT (w
), XG_FRAME_DATA
);
2716 Lisp_Object key
, frame
;
2717 struct input_event event
;
2719 if (! f
|| ! f
->n_tool_bar_items
|| NILP (f
->tool_bar_items
))
2722 idx
*= TOOL_BAR_ITEM_NSLOTS
;
2724 key
= AREF (f
->tool_bar_items
, idx
+ TOOL_BAR_ITEM_KEY
);
2725 XSETFRAME (frame
, f
);
2726 event
.kind
= TOOL_BAR_EVENT
;
2727 event
.frame_or_window
= frame
;
2729 kbd_buffer_store_event (&event
);
2731 event
.kind
= TOOL_BAR_EVENT
;
2732 event
.frame_or_window
= frame
;
2734 event
.modifiers
= 0; /* These are not available. */
2735 kbd_buffer_store_event (&event
);
2738 /* This callback is called when a tool bar is detached. We must set
2739 the height of the tool bar to zero when this happens so frame sizes
2740 are correctly calculated.
2741 WBOX is the handle box widget that enables detach/attach of the tool bar.
2742 W is the tool bar widget.
2743 CLIENT_DATA is a pointer to the frame the tool bar belongs to. */
2745 xg_tool_bar_detach_callback (wbox
, w
, client_data
)
2748 gpointer client_data
;
2750 FRAME_PTR f
= (FRAME_PTR
) client_data
;
2754 /* When detaching a tool bar, not everything dissapear. There are
2755 a few pixels left that are used to drop the tool bar back into
2757 int bw
= gtk_container_get_border_width (GTK_CONTAINER (wbox
));
2758 FRAME_TOOLBAR_HEIGHT (f
) = 2;
2760 /* The height has changed, resize outer widget and set columns
2761 rows to what we had before detaching the tool bar. */
2762 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2766 /* This callback is called when a tool bar is reattached. We must set
2767 the height of the tool bar when this happens so frame sizes
2768 are correctly calculated.
2769 WBOX is the handle box widget that enables detach/attach of the tool bar.
2770 W is the tool bar widget.
2771 CLIENT_DATA is a pointer to the frame the tool bar belongs to. */
2773 xg_tool_bar_attach_callback (wbox
, w
, client_data
)
2776 gpointer client_data
;
2778 FRAME_PTR f
= (FRAME_PTR
) client_data
;
2784 gtk_widget_size_request (w
, &req
);
2785 FRAME_TOOLBAR_HEIGHT (f
) = req
.height
;
2787 /* The height has changed, resize outer widget and set columns
2788 rows to what we had before detaching the tool bar. */
2789 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2793 /* This callback is called when the mouse enters or leaves a tool bar item.
2794 It is used for displaying and hiding the help text.
2795 W is the tool bar item, a button.
2796 EVENT is either an enter event or leave event.
2797 CLIENT_DATA is an integer that is the index of the button in the
2798 tool bar. 0 is the first button.
2800 Returns FALSE to tell GTK to keep processing this event. */
2802 xg_tool_bar_help_callback (w
, event
, client_data
)
2804 GdkEventCrossing
*event
;
2805 gpointer client_data
;
2807 int idx
= (int)client_data
;
2808 FRAME_PTR f
= (FRAME_PTR
) g_object_get_data (G_OBJECT (w
), XG_FRAME_DATA
);
2809 Lisp_Object help
, frame
;
2811 if (! GTK_IS_BUTTON (w
))
2816 if (! f
|| ! f
->n_tool_bar_items
|| NILP (f
->tool_bar_items
))
2819 if (event
->type
== GDK_ENTER_NOTIFY
)
2821 idx
*= TOOL_BAR_ITEM_NSLOTS
;
2822 help
= AREF (f
->tool_bar_items
, idx
+ TOOL_BAR_ITEM_HELP
);
2825 help
= AREF (f
->tool_bar_items
, idx
+ TOOL_BAR_ITEM_CAPTION
);
2830 XSETFRAME (frame
, f
);
2831 kbd_buffer_store_help_event (frame
, help
);
2837 /* This callback is called when a tool bar item shall be redrawn.
2838 It modifies the expose event so that the GtkImage widget redraws the
2839 whole image. This to overcome a bug that makes GtkImage draw the image
2840 in the wrong place when it tries to redraw just a part of the image.
2841 W is the GtkImage to be redrawn.
2842 EVENT is the expose event for W.
2843 CLIENT_DATA is unused.
2845 Returns FALSE to tell GTK to keep processing this event. */
2847 xg_tool_bar_item_expose_callback (w
, event
, client_data
)
2849 GdkEventExpose
*event
;
2850 gpointer client_data
;
2852 event
->area
.x
= event
->area
.y
= 0;
2853 event
->area
.width
= event
->area
.height
= 1000;
2857 /* This callback is called when a tool bar shall be redrawn.
2858 We need to update the tool bar from here in case the image cache
2859 has deleted the pixmaps used in the tool bar.
2860 W is the GtkToolbar to be redrawn.
2861 EVENT is the expose event for W.
2862 CLIENT_DATA is pointing to the frame for this tool bar.
2864 Returns FALSE to tell GTK to keep processing this event. */
2866 xg_tool_bar_expose_callback (w
, event
, client_data
)
2868 GdkEventExpose
*event
;
2869 gpointer client_data
;
2871 update_frame_tool_bar((FRAME_PTR
)client_data
);
2876 xg_create_tool_bar (f
)
2879 struct x_output
*x
= f
->output_data
.x
;
2881 int vbox_pos
= x
->menubar_widget
? 1 : 0;
2883 x
->toolbar_widget
= gtk_toolbar_new ();
2884 x
->handlebox_widget
= gtk_handle_box_new ();
2885 gtk_container_add (GTK_CONTAINER (x
->handlebox_widget
),
2888 gtk_box_pack_start (GTK_BOX (x
->vbox_widget
), x
->handlebox_widget
,
2891 gtk_box_reorder_child (GTK_BOX (x
->vbox_widget
), x
->handlebox_widget
,
2894 gtk_widget_set_name (x
->toolbar_widget
, "emacs-toolbar");
2896 /* We only have icons, so override any user setting. We could
2897 use the caption property of the toolbar item (see update_frame_tool_bar
2898 below), but some of those strings are long, making the toolbar so
2899 long it does not fit on the screen. The GtkToolbar widget makes every
2900 item equal size, so the longest caption determine the size of every
2901 tool bar item. I think the creators of the GtkToolbar widget
2902 counted on 4 or 5 character long strings. */
2903 gtk_toolbar_set_style (GTK_TOOLBAR (x
->toolbar_widget
), GTK_TOOLBAR_ICONS
);
2904 gtk_toolbar_set_orientation (GTK_TOOLBAR (x
->toolbar_widget
),
2905 GTK_ORIENTATION_HORIZONTAL
);
2907 g_signal_connect (G_OBJECT (x
->handlebox_widget
), "child-detached",
2908 G_CALLBACK (xg_tool_bar_detach_callback
), f
);
2909 g_signal_connect (G_OBJECT (x
->handlebox_widget
), "child-attached",
2910 G_CALLBACK (xg_tool_bar_attach_callback
), f
);
2911 g_signal_connect (G_OBJECT (x
->toolbar_widget
),
2913 G_CALLBACK (xg_tool_bar_expose_callback
),
2916 gtk_widget_show_all (x
->handlebox_widget
);
2918 gtk_widget_size_request (x
->toolbar_widget
, &req
);
2919 FRAME_TOOLBAR_HEIGHT (f
) = req
.height
;
2921 /* The height has changed, resize outer widget and set columns
2922 rows to what we had before adding the tool bar. */
2923 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2925 SET_FRAME_GARBAGED (f
);
2929 update_frame_tool_bar (f
)
2933 GtkRequisition old_req
, new_req
;
2936 struct x_output
*x
= f
->output_data
.x
;
2938 if (! FRAME_GTK_WIDGET (f
))
2943 if (! x
->toolbar_widget
)
2944 xg_create_tool_bar (f
);
2946 gtk_widget_size_request (x
->toolbar_widget
, &old_req
);
2948 icon_list
= gtk_container_get_children (GTK_CONTAINER (x
->toolbar_widget
));
2951 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
2953 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
2955 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
2956 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
2961 GtkWidget
*wicon
= iter
? GTK_WIDGET (iter
->data
) : 0;
2963 if (iter
) iter
= g_list_next (iter
);
2965 /* If image is a vector, choose the image according to the
2967 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
2968 if (VECTORP (image
))
2972 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
2973 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
2976 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
2977 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
2979 xassert (ASIZE (image
) >= idx
);
2980 image
= AREF (image
, idx
);
2985 /* Ignore invalid image specifications. */
2986 if (!valid_image_p (image
))
2988 if (wicon
) gtk_widget_hide (wicon
);
2992 img_id
= lookup_image (f
, image
);
2993 img
= IMAGE_FROM_ID (f
, img_id
);
2994 prepare_image_for_display (f
, img
);
2996 if (img
->load_failed_p
|| img
->pixmap
== None
)
2998 if (wicon
) gtk_widget_hide (wicon
);
3004 GdkPixmap
*gpix
= gdk_pixmap_foreign_new (img
->pixmap
);
3005 GdkBitmap
*gmask
= img
->mask
?
3006 (GdkBitmap
*) gdk_pixmap_foreign_new (img
->mask
) : 0;
3008 GtkWidget
*w
= gtk_image_new_from_pixmap (gpix
, gmask
);
3009 gtk_toolbar_append_item (GTK_TOOLBAR (x
->toolbar_widget
),
3012 GTK_SIGNAL_FUNC (xg_tool_bar_callback
),
3015 /* Save the image so we can see if an update is needed when
3016 this function is called again. */
3017 g_object_set_data (G_OBJECT (w
), XG_TOOL_BAR_IMAGE_DATA
,
3018 (gpointer
)img
->pixmap
);
3020 /* Catch expose events to overcome an annoying redraw bug, see
3021 comment for xg_tool_bar_item_expose_callback. */
3022 g_signal_connect (G_OBJECT (w
),
3024 G_CALLBACK (xg_tool_bar_item_expose_callback
),
3027 /* We must set sensitive on the button that is the parent
3028 of the GtkImage parent. Go upwards until we find the button. */
3029 while (! GTK_IS_BUTTON (w
))
3030 w
= gtk_widget_get_parent (w
);
3034 /* Save the frame in the button so the xg_tool_bar_callback
3036 g_object_set_data (G_OBJECT (w
), XG_FRAME_DATA
, (gpointer
)f
);
3037 gtk_widget_set_sensitive (w
, enabled_p
);
3039 /* Use enter/leave notify to show help. We use the events
3040 rather than the GtkButton specific signals "enter" and
3041 "leave", so we can have only one callback. The event
3042 will tell us what kind of event it is. */
3043 g_signal_connect (G_OBJECT (w
),
3044 "enter-notify-event",
3045 G_CALLBACK (xg_tool_bar_help_callback
),
3047 g_signal_connect (G_OBJECT (w
),
3048 "leave-notify-event",
3049 G_CALLBACK (xg_tool_bar_help_callback
),
3055 /* The child of the tool bar is a button. Inside that button
3056 is a vbox. Inside that vbox is the GtkImage. */
3057 GtkWidget
*wvbox
= gtk_bin_get_child (GTK_BIN (wicon
));
3058 GList
*chlist
= gtk_container_get_children (GTK_CONTAINER (wvbox
));
3059 GtkImage
*wimage
= GTK_IMAGE (chlist
->data
);
3060 Pixmap old_img
= (Pixmap
)g_object_get_data (G_OBJECT (wimage
),
3061 XG_TOOL_BAR_IMAGE_DATA
);
3062 g_list_free (chlist
);
3064 if (old_img
!= img
->pixmap
)
3066 GdkPixmap
*gpix
= gdk_pixmap_foreign_new (img
->pixmap
);
3067 GdkBitmap
*gmask
= img
->mask
?
3068 (GdkBitmap
*) gdk_pixmap_foreign_new (img
->mask
) : 0;
3070 gtk_image_set_from_pixmap (wimage
, gpix
, gmask
);
3073 g_object_set_data (G_OBJECT (wimage
), XG_TOOL_BAR_IMAGE_DATA
,
3074 (gpointer
)img
->pixmap
);
3076 gtk_widget_set_sensitive (wicon
, enabled_p
);
3077 gtk_widget_show (wicon
);
3083 /* Remove buttons not longer needed. We just hide them so they
3084 can be reused later on. */
3087 GtkWidget
*w
= GTK_WIDGET (iter
->data
);
3088 gtk_widget_hide (w
);
3089 iter
= g_list_next (iter
);
3092 gtk_widget_size_request (x
->toolbar_widget
, &new_req
);
3093 if (old_req
.height
!= new_req
.height
)
3095 FRAME_TOOLBAR_HEIGHT (f
) = new_req
.height
;
3096 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
3099 /* Must force out update so changed images gets redrawn. */
3100 gdk_window_process_all_updates ();
3102 if (icon_list
) g_list_free (icon_list
);
3108 free_frame_tool_bar (f
)
3111 struct x_output
*x
= f
->output_data
.x
;
3113 if (x
->toolbar_widget
)
3116 gtk_container_remove (GTK_CONTAINER (x
->vbox_widget
),
3117 x
->handlebox_widget
);
3118 x
->toolbar_widget
= 0;
3119 x
->handlebox_widget
= 0;
3120 FRAME_TOOLBAR_HEIGHT (f
) = 0;
3122 /* The height has changed, resize outer widget and set columns
3123 rows to what we had before removing the tool bar. */
3124 xg_resize_outer_widget (f
, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
3126 SET_FRAME_GARBAGED (f
);
3133 /***********************************************************************
3135 ***********************************************************************/
3139 xg_ignore_gtk_scrollbar
= 0;
3140 xg_left_ptr_cursor
= 0;
3143 xg_menu_cb_list
.prev
= xg_menu_cb_list
.next
=
3144 xg_menu_item_cb_list
.prev
= xg_menu_item_cb_list
.next
= 0;
3146 id_to_widget
.max_size
= id_to_widget
.used
= 0;
3147 id_to_widget
.widgets
= 0;
3149 /* Remove F10 as a menu accelerator, it does not mix well with Emacs key
3150 bindings. It doesn't seem to be any way to remove properties,
3151 so we set it to VoidSymbol which in X means "no key". */
3152 gtk_settings_set_string_property (gtk_settings_get_default (),
3153 "gtk-menu-bar-accel",
3157 /* Make GTK text input widgets use Emacs style keybindings. This is
3159 gtk_settings_set_string_property (gtk_settings_get_default (),
3160 "gtk-key-theme-name",
3165 #endif /* USE_GTK */