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"
37 #include <gdk/gdkkeysyms.h>
39 #define FRAME_TOTAL_PIXEL_HEIGHT(f) \
40 (FRAME_PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f))
44 /***********************************************************************
46 ***********************************************************************/
47 /* The timer for scroll bar repetition and menu bar timeouts.
48 NULL if no timer is started. */
49 static struct atimer
*xg_timer
;
51 /* The cursor used for scroll bars and popup menus.
52 We only have one cursor for all scroll bars and all popup menus. */
53 static GdkCursor
*xg_left_ptr_cursor
;
56 /* The next two variables and functions are taken from lwlib. */
57 static widget_value
*widget_value_free_list
;
58 static int malloc_cpt
;
60 /* Allocate a widget_value structure, either by taking one from the
61 widget_value_free_list or by malloc:ing a new one.
63 Return a pointer to the allocated structure. */
65 malloc_widget_value ()
68 if (widget_value_free_list
)
70 wv
= widget_value_free_list
;
71 widget_value_free_list
= wv
->free_list
;
76 wv
= (widget_value
*) malloc (sizeof (widget_value
));
79 memset (wv
, 0, sizeof (widget_value
));
83 /* This is analogous to free. It frees only what was allocated
84 by malloc_widget_value, and no substructures. */
86 free_widget_value (wv
)
94 /* When the number of already allocated cells is too big,
101 wv
->free_list
= widget_value_free_list
;
102 widget_value_free_list
= wv
;
106 /* Set *CURSOR on W and all widgets W contain. We must do like this
107 for scroll bars and menu because they create widgets internally,
108 and it is those widgets that are visible.
110 If *CURSOR is NULL, create a GDK_LEFT_PTR cursor and set *CURSOR to
111 the created cursor. */
113 xg_set_cursor (w
, cursor
)
117 GList
*children
= gdk_window_peek_children (w
->window
);
119 /* Create the cursor unless already created. */
121 *cursor
= gdk_cursor_new (GDK_LEFT_PTR
);
123 gdk_window_set_cursor (w
->window
, *cursor
);
125 /* The scroll bar widget has more than one GDK window (had to look at
126 the source to figure this out), and there is no way to set cursor
127 on widgets in GTK. So we must set the cursor for all GDK windows.
130 for ( ; children
; children
= g_list_next (children
))
131 gdk_window_set_cursor (GDK_WINDOW (children
->data
), *cursor
);
134 /* Timer function called when a timeout occurs for xg_timer.
135 This function processes all GTK events in a recursive event loop.
136 This is done because GTK timer events are not seen by Emacs event
137 detection, Emacs only looks for X events. When a scroll bar has the
138 pointer (detected by button press/release events below) an Emacs
139 timer is started, and this function can then check if the GTK timer
140 has expired by calling the GTK event loop.
141 Also, when a menu is active, it has a small timeout before it
142 pops down the sub menu under it. */
144 xg_process_timeouts (timer
)
145 struct atimer
*timer
;
148 /* Ideally we would like to just handle timer events, like the Xt version
149 of this does in xterm.c, but there is no such feature in GTK. */
150 while (gtk_events_pending ())
151 gtk_main_iteration ();
155 /* Start the xg_timer with an interval of 0.1 seconds, if not already started.
156 xg_process_timeouts is called when the timer expires. The timer
157 started is continuous, i.e. runs until xg_stop_timer is called. */
164 EMACS_SET_SECS_USECS (interval
, 0, 100000);
165 xg_timer
= start_atimer (ATIMER_CONTINUOUS
,
172 /* Stop the xg_timer if started. */
178 cancel_atimer (xg_timer
);
183 /* Insert NODE into linked LIST. */
185 xg_list_insert (xg_list_node
*list
, xg_list_node
*node
)
187 xg_list_node
*list_start
= list
->next
;
189 if (list_start
) list_start
->prev
= node
;
190 node
->next
= list_start
;
195 /* Remove NODE from linked LIST. */
197 xg_list_remove (xg_list_node
*list
, xg_list_node
*node
)
199 xg_list_node
*list_start
= list
->next
;
200 if (node
== list_start
)
202 list
->next
= node
->next
;
203 if (list
->next
) list
->next
->prev
= 0;
207 node
->prev
->next
= node
->next
;
208 if (node
->next
) node
->next
->prev
= node
->prev
;
212 /* Allocate and return a utf8 version of STR. If STR is already
213 utf8 or NULL, just return STR.
214 If not, a new string is allocated and the caller must free the result
217 get_utf8_string (str
)
220 char *utf8_str
= str
;
222 /* If not UTF-8, try current locale. */
223 if (str
&& !g_utf8_validate (str
, -1, NULL
))
224 utf8_str
= g_locale_to_utf8 (str
, -1, 0, 0, 0);
231 /***********************************************************************
232 General functions for creating widgets, resizing, events, e.t.c.
233 ***********************************************************************/
235 /* Make a geometry string and pass that to GTK. It seems this is the
236 only way to get geometry position right if the user explicitly
237 asked for a position when starting Emacs.
238 F is the frame we shall set geometry for. */
243 if (f
->size_hint_flags
& USPosition
)
245 int left
= f
->left_pos
;
246 int xneg
= f
->size_hint_flags
& XNegative
;
247 int top
= f
->top_pos
;
248 int yneg
= f
->size_hint_flags
& YNegative
;
256 sprintf (geom_str
, "=%dx%d%c%d%c%d",
257 FRAME_PIXEL_WIDTH (f
),
258 FRAME_TOTAL_PIXEL_HEIGHT (f
),
259 (xneg
? '-' : '+'), left
,
260 (yneg
? '-' : '+'), top
);
262 if (!gtk_window_parse_geometry (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
264 fprintf (stderr
, "Failed to parse: '%s'\n", geom_str
);
269 /* Resize the outer window of frame F after chainging the height.
270 This happend when the menu bar or the tool bar is added or removed.
271 COLUMNS/ROWS is the size the edit area shall have after the resize. */
273 xg_resize_outer_widget (f
, columns
, rows
)
278 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
279 FRAME_PIXEL_WIDTH (f
), FRAME_TOTAL_PIXEL_HEIGHT (f
));
281 /* base_height is now changed. */
282 x_wm_set_size_hint (f
, 0, 0);
284 /* If we are not mapped yet, set geometry once again, as window
285 height now have changed. */
286 if (! GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
289 xg_frame_set_char_size (f
, columns
, rows
);
290 gdk_window_process_all_updates ();
293 /* This gets called after the frame F has been cleared. Since that is
294 done with X calls, we need to redraw GTK widget (scroll bars). */
299 GtkWidget
*w
= f
->output_data
.x
->widget
;
303 gtk_container_set_reallocate_redraws (GTK_CONTAINER (w
), TRUE
);
304 gtk_container_foreach (GTK_CONTAINER (w
),
305 (GtkCallback
) gtk_widget_queue_draw
,
307 gdk_window_process_all_updates ();
311 /* Function to handle resize of our widgets. Since Emacs has some layouts
312 that does not fit well with GTK standard containers, we do most layout
314 F is the frame to resize.
315 PIXELWIDTH, PIXELHEIGHT is the new size in pixels. */
317 xg_resize_widgets (f
, pixelwidth
, pixelheight
)
319 int pixelwidth
, pixelheight
;
321 int mbheight
= FRAME_MENUBAR_HEIGHT (f
);
322 int tbheight
= FRAME_TOOLBAR_HEIGHT (f
);
323 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, (pixelheight
324 - mbheight
- tbheight
));
325 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pixelwidth
);
327 if (FRAME_GTK_WIDGET (f
)
328 && (columns
!= FRAME_COLS (f
) || rows
!= FRAME_LINES (f
)
329 || pixelwidth
!= FRAME_PIXEL_WIDTH (f
) || pixelheight
!= FRAME_PIXEL_HEIGHT (f
)))
331 struct x_output
*x
= f
->output_data
.x
;
334 all
.y
= mbheight
+ tbheight
;
337 all
.width
= pixelwidth
;
338 all
.height
= pixelheight
- mbheight
- tbheight
;
340 gtk_widget_size_allocate (x
->edit_widget
, &all
);
342 change_frame_size (f
, rows
, columns
, 0, 1, 0);
343 SET_FRAME_GARBAGED (f
);
344 cancel_mouse_face (f
);
349 /* Update our widget size to be COLS/ROWS characters for frame F. */
351 xg_frame_set_char_size (f
, cols
, rows
)
356 int pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
357 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
360 /* Take into account the size of the scroll bar. Always use the
361 number of columns occupied by the scroll bar here otherwise we
362 might end up with a frame width that is not a multiple of the
363 frame's character width which is bad for vertically split
365 f
->scroll_bar_actual_width
366 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
368 compute_fringe_widths (f
, 0);
370 /* FRAME_TEXT_COLS_TO_PIXEL_WIDTH uses scroll_bar_actual_width, so call it
371 after calculating that value. */
372 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
374 /* Must resize our top level widget. Font size may have changed,
375 but not rows/cols. */
376 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
377 pixelwidth
, pixelheight
);
378 xg_resize_widgets (f
, pixelwidth
, pixelheight
);
380 SET_FRAME_GARBAGED (f
);
381 cancel_mouse_face (f
);
384 /* Convert an X Window WSESC to its corresponding GtkWidget.
385 Must be done like this, because GtkWidget:s can have "hidden"
386 X Window that aren't accessible.
388 Return 0 if no widget match WDESC. */
390 xg_win_to_widget (wdesc
)
394 GtkWidget
*gwdesc
= 0;
397 gdkwin
= gdk_xid_table_lookup (wdesc
);
401 event
.any
.window
= gdkwin
;
402 gwdesc
= gtk_get_event_widget (&event
);
409 /* Fill in the GdkColor C so that it represents PIXEL.
410 W is the widget that color will be used for. Used to find colormap. */
412 xg_pix_to_gcolor (w
, pixel
, c
)
417 GdkColormap
*map
= gtk_widget_get_colormap (w
);
418 gdk_colormap_query_color (map
, pixel
, c
);
421 /* Turning off double buffering for our GtkFixed widget has the side
422 effect of turning it off also for its children (scroll bars).
423 But we want those to be double buffered to not flicker so handle
424 expose manually here.
425 WIDGET is the GtkFixed widget that gets exposed.
426 EVENT is the expose event.
429 Return TRUE to tell GTK that this expose event has been fully handeled
430 and that GTK shall do nothing more with it. */
432 xg_fixed_handle_expose(GtkWidget
*widget
,
433 GdkEventExpose
*event
,
438 for (iter
= GTK_FIXED (widget
)->children
; iter
; iter
= g_list_next (iter
))
440 GtkFixedChild
*child_data
= (GtkFixedChild
*) iter
->data
;
441 GtkWidget
*child
= child_data
->widget
;
442 GdkWindow
*window
= child
->window
;
443 GdkRegion
*region
= gtk_widget_region_intersect (child
, event
->region
);
445 if (! gdk_region_empty (region
))
447 GdkEvent child_event
;
448 child_event
.expose
= *event
;
449 child_event
.expose
.region
= region
;
451 /* Turn on double buffering, i.e. draw to an off screen area. */
452 gdk_window_begin_paint_region (window
, region
);
454 /* Tell child to redraw itself. */
455 gdk_region_get_clipbox (region
, &child_event
.expose
.area
);
456 gtk_widget_send_expose (child
, &child_event
);
457 gdk_window_process_updates (window
, TRUE
);
459 /* Copy off screen area to the window. */
460 gdk_window_end_paint (window
);
463 gdk_region_destroy (region
);
469 /* Create and set up the GTK widgets for frame F.
470 Return 0 if creation failed, non-zero otherwise. */
472 xg_create_frame_widgets (f
)
485 wtop
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
486 wvbox
= gtk_vbox_new (FALSE
, 0);
487 wfixed
= gtk_fixed_new (); /* Must have this to place scroll bars */
489 if (! wtop
|| ! wvbox
|| ! wfixed
)
491 if (wtop
) gtk_widget_destroy (wtop
);
492 if (wvbox
) gtk_widget_destroy (wvbox
);
493 if (wfixed
) gtk_widget_destroy (wfixed
);
498 /* Use same names as the Xt port does. I.e. Emacs.pane.emacs by default */
499 gtk_widget_set_name (wtop
, EMACS_CLASS
);
500 gtk_widget_set_name (wvbox
, "pane");
501 gtk_widget_set_name (wfixed
, SDATA (Vx_resource_name
));
503 /* If this frame has a title or name, set it in the title bar. */
504 if (! NILP (f
->title
)) title
= SDATA (ENCODE_UTF_8 (f
->title
));
505 else if (! NILP (f
->name
)) title
= SDATA (ENCODE_UTF_8 (f
->name
));
507 if (title
) gtk_window_set_title (GTK_WINDOW (wtop
), title
);
509 FRAME_GTK_OUTER_WIDGET (f
) = wtop
;
510 FRAME_GTK_WIDGET (f
) = wfixed
;
511 f
->output_data
.x
->vbox_widget
= wvbox
;
513 gtk_fixed_set_has_window (GTK_FIXED (wfixed
), TRUE
);
515 gtk_widget_set_size_request (wfixed
, FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
));
517 gtk_container_add (GTK_CONTAINER (wtop
), wvbox
);
518 gtk_box_pack_end (GTK_BOX (wvbox
), wfixed
, TRUE
, TRUE
, 0);
520 if (FRAME_EXTERNAL_TOOL_BAR (f
))
521 update_frame_tool_bar (f
);
523 /* The tool bar is created but first there are no items in it.
524 This causes it to be zero height. Later items are added, but then
525 the frame is already mapped, so there is a "jumping" resize.
526 This makes geometry handling difficult, for example -0-0 will end
527 up in the wrong place as tool bar height has not been taken into account.
528 So we cheat a bit by setting a height that is what it will have
529 later on when tool bar items are added. */
530 if (FRAME_EXTERNAL_TOOL_BAR (f
) && FRAME_TOOLBAR_HEIGHT (f
) == 0)
531 FRAME_TOOLBAR_HEIGHT (f
) = 34;
534 /* We don't want this widget double buffered, because we draw on it
535 with regular X drawing primitives, so from a GTK/GDK point of
536 view, the widget is totally blank. When an expose comes, this
537 will make the widget blank, and then Emacs redraws it. This flickers
538 a lot, so we turn off double buffering. */
539 gtk_widget_set_double_buffered (wfixed
, FALSE
);
541 /* Turning off double buffering above has the side effect of turning
542 it off also for its children (scroll bars). But we want those
543 to be double buffered to not flicker so handle expose manually. */
544 g_signal_connect (G_OBJECT (wfixed
), "expose-event",
545 G_CALLBACK (xg_fixed_handle_expose
), 0);
547 /* GTK documents says use gtk_window_set_resizable. But then a user
548 can't shrink the window from its starting size. */
549 gtk_window_set_policy (GTK_WINDOW (wtop
), TRUE
, TRUE
, TRUE
);
550 gtk_window_set_wmclass (GTK_WINDOW (wtop
),
551 SDATA (Vx_resource_name
),
552 SDATA (Vx_resource_class
));
554 /* Add callback to do nothing on WM_DELETE_WINDOW. The default in
555 GTK is to destroy the widget. We want Emacs to do that instead. */
556 g_signal_connect (G_OBJECT (wtop
), "delete-event",
557 G_CALLBACK (gtk_true
), 0);
559 /* Convert our geometry parameters into a geometry string
561 GTK will itself handle calculating the real position this way. */
564 gtk_widget_add_events (wfixed
,
565 GDK_POINTER_MOTION_MASK
567 | GDK_BUTTON_PRESS_MASK
568 | GDK_BUTTON_RELEASE_MASK
570 | GDK_ENTER_NOTIFY_MASK
571 | GDK_LEAVE_NOTIFY_MASK
572 | GDK_FOCUS_CHANGE_MASK
574 | GDK_VISIBILITY_NOTIFY_MASK
);
576 /* Must realize the windows so the X window gets created. It is used
577 by callers of this function. */
578 gtk_widget_realize (wfixed
);
579 FRAME_X_WINDOW (f
) = GTK_WIDGET_TO_X_WIN (wfixed
);
581 /* Since GTK clears its window by filling with the background color,
582 we must keep X and GTK background in sync. */
583 xg_pix_to_gcolor (wfixed
, f
->output_data
.x
->background_pixel
, &bg
);
584 gtk_widget_modify_bg (wfixed
, GTK_STATE_NORMAL
, &bg
);
586 /* Also, do not let any background pixmap to be set, this looks very
587 bad as Emacs overwrites the background pixmap with its own idea
588 of background color. */
589 style
= gtk_widget_get_modifier_style (wfixed
);
591 /* Must use g_strdup because gtk_widget_modify_style does g_free. */
592 style
->bg_pixmap_name
[GTK_STATE_NORMAL
] = g_strdup ("<none>");
593 gtk_widget_modify_style (wfixed
, style
);
595 /* GTK does not set any border, and they look bad with GTK. */
597 f
->internal_border_width
= 0;
604 /* Set the normal size hints for the window manager, for frame F.
605 FLAGS is the flags word to use--or 0 meaning preserve the flags
606 that the window now has.
607 If USER_POSITION is nonzero, we set the User Position
608 flag (this is useful when FLAGS is 0). */
610 x_wm_set_size_hint (f
, flags
, user_position
)
615 if (FRAME_GTK_OUTER_WIDGET (f
))
617 /* Must use GTK routines here, otherwise GTK resets the size hints
618 to its own defaults. */
619 GdkGeometry size_hints
;
621 int base_width
, base_height
;
622 int min_rows
= 0, min_cols
= 0;
623 int win_gravity
= f
->win_gravity
;
627 memset (&size_hints
, 0, sizeof (size_hints
));
628 f
->output_data
.x
->size_hints
= size_hints
;
629 f
->output_data
.x
->hint_flags
= hint_flags
;
632 flags
= f
->size_hint_flags
;
634 size_hints
= f
->output_data
.x
->size_hints
;
635 hint_flags
= f
->output_data
.x
->hint_flags
;
637 hint_flags
|= GDK_HINT_RESIZE_INC
| GDK_HINT_MIN_SIZE
;
638 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
639 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
641 hint_flags
|= GDK_HINT_BASE_SIZE
;
642 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
643 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0)
644 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
646 check_frame_size (f
, &min_rows
, &min_cols
);
648 size_hints
.base_width
= base_width
;
649 size_hints
.base_height
= base_height
;
650 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
651 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
654 /* These currently have a one to one mapping with the X values, but I
655 don't think we should rely on that. */
656 hint_flags
|= GDK_HINT_WIN_GRAVITY
;
657 size_hints
.win_gravity
= 0;
658 if (win_gravity
== NorthWestGravity
)
659 size_hints
.win_gravity
= GDK_GRAVITY_NORTH_WEST
;
660 else if (win_gravity
== NorthGravity
)
661 size_hints
.win_gravity
= GDK_GRAVITY_NORTH
;
662 else if (win_gravity
== NorthEastGravity
)
663 size_hints
.win_gravity
= GDK_GRAVITY_NORTH_EAST
;
664 else if (win_gravity
== WestGravity
)
665 size_hints
.win_gravity
= GDK_GRAVITY_WEST
;
666 else if (win_gravity
== CenterGravity
)
667 size_hints
.win_gravity
= GDK_GRAVITY_CENTER
;
668 else if (win_gravity
== EastGravity
)
669 size_hints
.win_gravity
= GDK_GRAVITY_EAST
;
670 else if (win_gravity
== SouthWestGravity
)
671 size_hints
.win_gravity
= GDK_GRAVITY_SOUTH_WEST
;
672 else if (win_gravity
== SouthGravity
)
673 size_hints
.win_gravity
= GDK_GRAVITY_SOUTH
;
674 else if (win_gravity
== SouthEastGravity
)
675 size_hints
.win_gravity
= GDK_GRAVITY_SOUTH_EAST
;
676 else if (win_gravity
== StaticGravity
)
677 size_hints
.win_gravity
= GDK_GRAVITY_STATIC
;
679 if (flags
& PPosition
) hint_flags
|= GDK_HINT_POS
;
680 if (flags
& USPosition
) hint_flags
|= GDK_HINT_USER_POS
;
681 if (flags
& USSize
) hint_flags
|= GDK_HINT_USER_SIZE
;
685 hint_flags
&= ~GDK_HINT_POS
;
686 hint_flags
|= GDK_HINT_USER_POS
;
691 gtk_window_set_geometry_hints (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
692 FRAME_GTK_OUTER_WIDGET (f
),
696 f
->output_data
.x
->size_hints
= size_hints
;
697 f
->output_data
.x
->hint_flags
= hint_flags
;
702 /* Change background color of a frame.
703 Since GTK uses the background colour to clear the window, we must
704 keep the GTK and X colors in sync.
705 F is the frame to change,
706 BG is the pixel value to change to. */
708 xg_set_background_color (f
, bg
)
712 if (FRAME_GTK_WIDGET (f
))
717 xg_pix_to_gcolor (FRAME_GTK_WIDGET (f
), bg
, &gdk_bg
);
718 gtk_widget_modify_bg (FRAME_GTK_WIDGET (f
), GTK_STATE_NORMAL
, &gdk_bg
);
725 /***********************************************************************
727 ***********************************************************************/
728 /* Return the dialog title to use for a dialog of type KEY.
729 This is the encoding used by lwlib. We use the same for GTK. */
731 get_dialog_title (char key
)
741 title
= "Information";
760 /* Callback for dialogs that get WM_DELETE_WINDOW. We pop down
761 the dialog, but return TRUE so the event does not propagate further
762 in GTK. This prevents GTK from destroying the dialog widget automatically
763 and we can always destrou the widget manually, regardles of how
764 it was popped down (button press or WM_DELETE_WINDOW).
765 W is the dialog widget.
766 EVENT is the GdkEvent that represents WM_DELETE_WINDOW (not used).
767 user_data is NULL (not used).
769 Returns TRUE to end propagation of event. */
771 dialog_delete_callback (w
, event
, user_data
)
776 gtk_widget_unmap (w
);
780 /* Create a popup dialog window. See also xg_create_widget below.
781 WV is a widget_value describing the dialog.
782 SELECT_CB is the callback to use when a button has been pressed.
783 DEACTIVATE_CB is the callback to use when the dialog pops down.
785 Returns the GTK dialog widget. */
787 create_dialog (wv
, select_cb
, deactivate_cb
)
790 GCallback deactivate_cb
;
792 char *title
= get_dialog_title (wv
->name
[0]);
793 int total_buttons
= wv
->name
[1] - '0';
794 int right_buttons
= wv
->name
[4] - '0';
797 int button_spacing
= 10;
798 GtkWidget
*wdialog
= gtk_dialog_new ();
803 GtkWidget
*whbox_down
;
805 /* If the number of buttons is greater than 4, make two rows of buttons
806 instead. This looks better. */
807 int make_two_rows
= total_buttons
> 4;
809 if (right_buttons
== 0) right_buttons
= total_buttons
/2;
810 left_buttons
= total_buttons
- right_buttons
;
812 gtk_window_set_title (GTK_WINDOW (wdialog
), title
);
813 gtk_widget_set_name (wdialog
, "emacs-dialog");
815 cur_box
= GTK_BOX (GTK_DIALOG (wdialog
)->action_area
);
819 wvbox
= gtk_vbox_new (TRUE
, button_spacing
);
820 whbox_up
= gtk_hbox_new (FALSE
, 0);
821 whbox_down
= gtk_hbox_new (FALSE
, 0);
823 gtk_box_pack_start (cur_box
, wvbox
, FALSE
, FALSE
, 0);
824 gtk_box_pack_start (GTK_BOX (wvbox
), whbox_up
, FALSE
, FALSE
, 0);
825 gtk_box_pack_start (GTK_BOX (wvbox
), whbox_down
, FALSE
, FALSE
, 0);
827 cur_box
= GTK_BOX (whbox_up
);
830 g_signal_connect (G_OBJECT (wdialog
), "delete-event",
831 G_CALLBACK (dialog_delete_callback
), 0);
835 g_signal_connect (G_OBJECT (wdialog
), "close", deactivate_cb
, 0);
836 g_signal_connect (G_OBJECT (wdialog
), "response", deactivate_cb
, 0);
839 for (item
= wv
->contents
; item
; item
= item
->next
)
841 char *utf8_label
= get_utf8_string (item
->value
);
845 if (item
->name
&& strcmp (item
->name
, "message") == 0)
847 /* This is the text part of the dialog. */
848 w
= gtk_label_new (utf8_label
);
849 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (wdialog
)->vbox
),
852 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (wdialog
)->vbox
), w
,
854 gtk_misc_set_alignment (GTK_MISC (w
), 0.1, 0.5);
856 /* Try to make dialog look better. Must realize first so
857 the widget can calculate the size it needs. */
858 gtk_widget_realize (w
);
859 gtk_widget_size_request (w
, &req
);
860 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (wdialog
)->vbox
),
862 if (item
->value
&& strlen (item
->value
) > 0)
863 button_spacing
= 2*req
.width
/strlen (item
->value
);
867 /* This is one button to add to the dialog. */
868 w
= gtk_button_new_with_label (utf8_label
);
870 gtk_widget_set_sensitive (w
, FALSE
);
872 g_signal_connect (G_OBJECT (w
), "clicked",
873 select_cb
, item
->call_data
);
875 gtk_box_pack_start (cur_box
, w
, TRUE
, TRUE
, button_spacing
);
876 if (++button_nr
== left_buttons
)
879 cur_box
= GTK_BOX (whbox_down
);
881 gtk_box_pack_start (cur_box
,
888 if (utf8_label
&& utf8_label
!= item
->value
)
904 /* Callback function invoked when the Ok button is pressed in
906 W is the file dialog widget,
907 ARG points to an integer where we record what has happend. */
909 xg_file_sel_ok (w
, arg
)
913 *(int*)arg
= XG_FILE_OK
;
916 /* Callback function invoked when the Cancel button is pressed in
918 W is the file dialog widget,
919 ARG points to an integer where we record what has happend. */
921 xg_file_sel_cancel (w
, arg
)
925 *(int*)arg
= XG_FILE_CANCEL
;
928 /* Callback function invoked when the file dialog is destroyed (i.e.
929 popped down). We must keep track of this, because if this
930 happens, GTK destroys the widget. But if for example, Ok is pressed,
931 the dialog is popped down, but the dialog widget is not destroyed.
932 W is the file dialog widget,
933 ARG points to an integer where we record what has happend. */
935 xg_file_sel_destroy (w
, arg
)
939 *(int*)arg
= XG_FILE_DESTROYED
;
942 /* Read a file name from the user using a file dialog.
943 F is the current frame.
944 PROMPT is a prompt to show to the user. May not be NULL.
945 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
946 If MUSTMATCH_P is non-zero, the returned file name must be an existing
949 Returns a file name or NULL if no file was selected.
950 The returned string must be freed by the caller. */
952 xg_get_file_name (f
, prompt
, default_filename
, mustmatch_p
)
955 char *default_filename
;
959 GtkFileSelection
*filesel
;
960 int filesel_done
= XG_FILE_NOT_DONE
;
963 filewin
= gtk_file_selection_new (prompt
);
964 filesel
= GTK_FILE_SELECTION (filewin
);
966 gtk_widget_set_name (filewin
, "emacs-filedialog");
968 gtk_window_set_transient_for (GTK_WINDOW (filewin
),
969 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
970 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin
), TRUE
);
972 g_signal_connect (G_OBJECT (filesel
->ok_button
),
974 G_CALLBACK (xg_file_sel_ok
),
976 g_signal_connect (G_OBJECT (filesel
->cancel_button
),
978 G_CALLBACK (xg_file_sel_cancel
),
980 g_signal_connect (G_OBJECT (filesel
),
982 G_CALLBACK (xg_file_sel_destroy
),
985 if (default_filename
)
986 gtk_file_selection_set_filename (filesel
, default_filename
);
990 /* The selection_entry part of filesel is not documented. */
991 gtk_widget_set_sensitive (filesel
->selection_entry
, FALSE
);
992 gtk_file_selection_hide_fileop_buttons (filesel
);
996 gtk_widget_show_all (filewin
);
998 while (filesel_done
== XG_FILE_NOT_DONE
)
999 gtk_main_iteration ();
1001 if (filesel_done
== XG_FILE_OK
)
1002 fn
= xstrdup ((char*) gtk_file_selection_get_filename (filesel
));
1004 if (filesel_done
!= XG_FILE_DESTROYED
)
1005 gtk_widget_destroy (filewin
);
1011 /***********************************************************************
1013 ***********************************************************************/
1015 /* The name of menu items that can be used for citomization. Since GTK
1016 RC files are very crude and primitive, we have to set this on all
1017 menu item names so a user can easily cutomize menu items. */
1019 #define MENU_ITEM_NAME "emacs-menuitem"
1022 /* Linked list of all allocated struct xg_menu_cb_data. Used for marking
1023 during GC. The next member points to the items. */
1024 static xg_list_node xg_menu_cb_list
;
1026 /* Linked list of all allocated struct xg_menu_item_cb_data. Used for marking
1027 during GC. The next member points to the items. */
1028 static xg_list_node xg_menu_item_cb_list
;
1030 /* Allocate and initialize CL_DATA if NULL, otherwise increase ref_count.
1031 F is the frame CL_DATA will be initialized for.
1032 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1034 The menu bar and all sub menus under the menu bar in a frame
1035 share the same structure, hence the reference count.
1037 Returns CL_DATA if CL_DATA is not NULL, or a pointer to a newly
1038 allocated xg_menu_cb_data if CL_DATA is NULL. */
1039 static xg_menu_cb_data
*
1040 make_cl_data (cl_data
, f
, highlight_cb
)
1041 xg_menu_cb_data
*cl_data
;
1043 GCallback highlight_cb
;
1047 cl_data
= (xg_menu_cb_data
*) xmalloc (sizeof (*cl_data
));
1049 cl_data
->menu_bar_vector
= f
->menu_bar_vector
;
1050 cl_data
->menu_bar_items_used
= f
->menu_bar_items_used
;
1051 cl_data
->highlight_cb
= highlight_cb
;
1052 cl_data
->ref_count
= 0;
1054 xg_list_insert (&xg_menu_cb_list
, &cl_data
->ptrs
);
1057 cl_data
->ref_count
++;
1062 /* Update CL_DATA with values from frame F and with HIGHLIGHT_CB.
1063 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1065 When the menu bar is updated, menu items may have been added and/or
1066 removed, so menu_bar_vector and menu_bar_items_used change. We must
1067 then update CL_DATA since it is used to determine which menu
1068 item that is invoked in the menu.
1069 HIGHLIGHT_CB could change, there is no check that the same
1070 function is given when modifying a menu bar as was given when
1071 creating the menu bar. */
1073 update_cl_data (cl_data
, f
, highlight_cb
)
1074 xg_menu_cb_data
*cl_data
;
1076 GCallback highlight_cb
;
1081 cl_data
->menu_bar_vector
= f
->menu_bar_vector
;
1082 cl_data
->menu_bar_items_used
= f
->menu_bar_items_used
;
1083 cl_data
->highlight_cb
= highlight_cb
;
1087 /* Decrease reference count for CL_DATA.
1088 If reference count is zero, free CL_DATA. */
1090 unref_cl_data (cl_data
)
1091 xg_menu_cb_data
*cl_data
;
1093 if (cl_data
&& cl_data
->ref_count
> 0)
1095 cl_data
->ref_count
--;
1096 if (cl_data
->ref_count
== 0)
1098 xg_list_remove (&xg_menu_cb_list
, &cl_data
->ptrs
);
1104 /* Function that marks all lisp data during GC. */
1110 for (iter
= xg_menu_cb_list
.next
; iter
; iter
= iter
->next
)
1111 mark_object (&((xg_menu_cb_data
*) iter
)->menu_bar_vector
);
1113 for (iter
= xg_menu_item_cb_list
.next
; iter
; iter
= iter
->next
)
1115 xg_menu_item_cb_data
*cb_data
= (xg_menu_item_cb_data
*) iter
;
1117 if (! NILP (cb_data
->help
))
1118 mark_object (&cb_data
->help
);
1123 /* Callback called when a menu item is destroyed. Used to free data.
1124 W is the widget that is being destroyed (not used).
1125 CLIENT_DATA points to the xg_menu_item_cb_data associated with the W. */
1127 menuitem_destroy_callback (w
, client_data
)
1129 gpointer client_data
;
1133 xg_menu_item_cb_data
*data
= (xg_menu_item_cb_data
*) client_data
;
1134 xg_list_remove (&xg_menu_item_cb_list
, &data
->ptrs
);
1139 /* Callback called when the pointer enters/leaves a menu item.
1141 EVENT is either an enter event or leave event.
1142 CLIENT_DATA points to the xg_menu_item_cb_data associated with the W.
1144 Returns FALSE to tell GTK to keep processing this event. */
1146 menuitem_highlight_callback (w
, event
, client_data
)
1148 GdkEventCrossing
*event
;
1149 gpointer client_data
;
1153 xg_menu_item_cb_data
*data
= (xg_menu_item_cb_data
*) client_data
;
1154 gpointer call_data
= event
->type
== GDK_LEAVE_NOTIFY
? 0 : client_data
;
1156 if (! NILP (data
->help
) && data
->cl_data
->highlight_cb
)
1158 GtkCallback func
= (GtkCallback
) data
->cl_data
->highlight_cb
;
1159 (*func
) (w
, call_data
);
1166 /* Callback called when a menu is destroyed. Used to free data.
1167 W is the widget that is being destroyed (not used).
1168 CLIENT_DATA points to the xg_menu_cb_data associated with W. */
1170 menu_destroy_callback (w
, client_data
)
1172 gpointer client_data
;
1174 unref_cl_data ((xg_menu_cb_data
*) client_data
);
1177 /* Callback called when a menu does a grab or ungrab. That means the
1178 menu has been activated or deactivated.
1179 Used to start a timer so the small timeout the menus in GTK uses before
1180 popping down a menu is seen by Emacs (see xg_process_timeouts above).
1181 W is the widget that does the grab (not used).
1182 UNGRAB_P is TRUE if this is an ungrab, FALSE if it is a grab.
1183 CLIENT_DATA is NULL (not used). */
1185 menu_grab_callback (GtkWidget
*widget
,
1187 gpointer client_data
)
1189 /* Keep track of total number of grabs. */
1192 if (ungrab_p
) cnt
--;
1195 if (cnt
> 0 && ! xg_timer
) xg_start_timer ();
1196 else if (cnt
== 0 && xg_timer
) xg_stop_timer ();
1199 /* Make a GTK widget that contains both UTF8_LABEL and UTF8_KEY (both
1200 must be non-NULL) and can be inserted into a menu item.
1202 Returns the GtkHBox. */
1204 make_widget_for_menu_item (utf8_label
, utf8_key
)
1212 wbox
= gtk_hbox_new (FALSE
, 0);
1213 wlbl
= gtk_label_new (utf8_label
);
1214 wkey
= gtk_label_new (utf8_key
);
1216 gtk_misc_set_alignment (GTK_MISC (wlbl
), 0.0, 0.5);
1217 gtk_misc_set_alignment (GTK_MISC (wkey
), 0.0, 0.5);
1219 gtk_box_pack_start (GTK_BOX (wbox
), wlbl
, TRUE
, TRUE
, 0);
1220 gtk_box_pack_start (GTK_BOX (wbox
), wkey
, FALSE
, FALSE
, 0);
1222 gtk_widget_set_name (wlbl
, MENU_ITEM_NAME
);
1223 gtk_widget_set_name (wkey
, MENU_ITEM_NAME
);
1224 gtk_widget_set_name (wbox
, MENU_ITEM_NAME
);
1229 /* Make and return a menu item widget with the key to the right.
1230 UTF8_LABEL is the text for the menu item (GTK uses UTF8 internally).
1231 UTF8_KEY is the text representing the key binding.
1232 ITEM is the widget_value describing the menu item.
1234 GROUP is an in/out parameter. If the menu item to be created is not
1235 part of any radio menu group, *GROUP contains NULL on entry and exit.
1236 If the menu item to be created is part of a radio menu group, on entry
1237 *GROUP contains the group to use, or NULL if this is the first item
1238 in the group. On exit, *GROUP contains the radio item group.
1240 Unfortunately, keys don't line up as nicely as in Motif,
1241 but the MacOS X version doesn't either, so I guess that is OK. */
1243 make_menu_item (utf8_label
, utf8_key
, item
, group
)
1250 GtkWidget
*wtoadd
= 0;
1253 wtoadd
= make_widget_for_menu_item (utf8_label
, utf8_key
);
1255 if (item
->button_type
== BUTTON_TYPE_TOGGLE
)
1258 if (utf8_key
) w
= gtk_check_menu_item_new ();
1259 else w
= gtk_check_menu_item_new_with_label (utf8_label
);
1260 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), item
->selected
);
1262 else if (item
->button_type
== BUTTON_TYPE_RADIO
)
1264 if (utf8_key
) w
= gtk_radio_menu_item_new (*group
);
1265 else w
= gtk_radio_menu_item_new_with_label (*group
, utf8_label
);
1266 *group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (w
));
1268 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), TRUE
);
1273 if (utf8_key
) w
= gtk_menu_item_new ();
1274 else w
= gtk_menu_item_new_with_label (utf8_label
);
1277 if (wtoadd
) gtk_container_add (GTK_CONTAINER (w
), wtoadd
);
1278 if (! item
->enabled
) gtk_widget_set_sensitive (w
, FALSE
);
1283 /* Return non-zero if LABEL specifies a separator (GTK only has one
1286 xg_separator_p (char *label
)
1288 if (! label
) return 0;
1289 else if (strlen (label
) > 3
1290 && strncmp (label
, "--", 2) == 0
1293 static char* separator_names
[] = {
1298 "single-dashed-line",
1299 "double-dashed-line",
1301 "shadow-etched-out",
1302 "shadow-etched-in-dash",
1303 "shadow-etched-out-dash",
1304 "shadow-double-etched-in",
1305 "shadow-double-etched-out",
1306 "shadow-double-etched-in-dash",
1307 "shadow-double-etched-out-dash",
1314 for (i
= 0; separator_names
[i
]; ++i
)
1315 if (strcmp (label
, separator_names
[i
]) == 0)
1320 /* Old-style separator, maybe. It's a separator if it contains
1322 while (*label
== '-')
1324 if (*label
== 0) return 1;
1330 GtkWidget
*xg_did_tearoff
;
1332 /* Callback invoked when a detached menu window is removed. Here we
1333 delete the popup menu.
1334 WIDGET is the top level window that is removed (the parent of the menu).
1335 EVENT is the event that triggers the window removal.
1336 CLIENT_DATA points to the menu that is detached.
1338 Returns TRUE to tell GTK to stop processing this event. */
1340 tearoff_remove (widget
, event
, client_data
)
1343 gpointer client_data
;
1345 gtk_widget_destroy (GTK_WIDGET (client_data
));
1349 /* Callback invoked when a menu is detached. It sets the xg_did_tearoff
1351 WIDGET is the GtkTearoffMenuItem.
1352 CLIENT_DATA is not used. */
1354 tearoff_activate (widget
, client_data
)
1356 gpointer client_data
;
1358 GtkWidget
*menu
= gtk_widget_get_parent (widget
);
1359 if (! gtk_menu_get_tearoff_state (GTK_MENU (menu
)))
1362 xg_did_tearoff
= menu
;
1365 /* If a detach of a popup menu is done, this function should be called
1366 to keep the menu around until the detached window is removed.
1367 MENU is the top level menu for the popup,
1368 SUBMENU is the menu that got detached (that is MENU or a
1369 submenu of MENU), see the xg_did_tearoff variable. */
1371 xg_keep_popup (menu
, submenu
)
1377 /* Find the top widget for the detached menu. */
1378 p
= gtk_widget_get_toplevel (submenu
);
1380 /* Delay destroying the menu until the detached menu is removed. */
1381 g_signal_connect (G_OBJECT (p
), "unmap_event",
1382 G_CALLBACK (tearoff_remove
), menu
);
1385 /* Create a menu item widget, and connect the callbacks.
1386 ITEM decribes the menu item.
1387 F is the frame the created menu belongs to.
1388 SELECT_CB is the callback to use when a menu item is selected.
1389 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1390 CL_DATA points to the callback data to be used for this menu.
1391 GROUP is an in/out parameter. If the menu item to be created is not
1392 part of any radio menu group, *GROUP contains NULL on entry and exit.
1393 If the menu item to be created is part of a radio menu group, on entry
1394 *GROUP contains the group to use, or NULL if this is the first item
1395 in the group. On exit, *GROUP contains the radio item group.
1397 Returns the created GtkWidget. */
1399 xg_create_one_menuitem (item
, f
, select_cb
, highlight_cb
, cl_data
, group
)
1402 GCallback select_cb
;
1403 GCallback highlight_cb
;
1404 xg_menu_cb_data
*cl_data
;
1410 xg_menu_item_cb_data
*cb_data
;
1412 utf8_label
= get_utf8_string (item
->name
);
1413 utf8_key
= get_utf8_string (item
->key
);
1415 w
= make_menu_item (utf8_label
, utf8_key
, item
, group
);
1417 if (utf8_label
&& utf8_label
!= item
->name
) g_free (utf8_label
);
1418 if (utf8_key
&& utf8_key
!= item
->key
) g_free (utf8_key
);
1420 cb_data
= xmalloc (sizeof (xg_menu_item_cb_data
));
1422 xg_list_insert (&xg_menu_item_cb_list
, &cb_data
->ptrs
);
1424 cb_data
->unhighlight_id
= cb_data
->highlight_id
= cb_data
->select_id
= 0;
1425 cb_data
->help
= item
->help
;
1426 cb_data
->cl_data
= cl_data
;
1427 cb_data
->call_data
= item
->call_data
;
1429 g_signal_connect (G_OBJECT (w
),
1431 G_CALLBACK (menuitem_destroy_callback
),
1434 /* Put cb_data in widget, so we can get at it when modifying menubar */
1435 g_object_set_data (G_OBJECT (w
), XG_ITEM_DATA
, cb_data
);
1437 /* final item, not a submenu */
1438 if (item
->call_data
&& ! item
->contents
)
1442 = g_signal_connect (G_OBJECT (w
), "activate", select_cb
, cb_data
);
1445 if (! NILP (item
->help
) && highlight_cb
)
1447 /* We use enter/leave notify instead of select/deselect because
1448 select/deselect doesn't go well with detached menus. */
1449 cb_data
->highlight_id
1450 = g_signal_connect (G_OBJECT (w
),
1451 "enter-notify-event",
1452 G_CALLBACK (menuitem_highlight_callback
),
1454 cb_data
->unhighlight_id
1455 = g_signal_connect (G_OBJECT (w
),
1456 "leave-notify-event",
1457 G_CALLBACK (menuitem_highlight_callback
),
1464 static GtkWidget
*create_menus
P_ ((widget_value
*, FRAME_PTR
, GCallback
,
1465 GCallback
, GCallback
, int, int, int,
1466 GtkWidget
*, xg_menu_cb_data
*, char *));
1468 /* Create a full menu tree specified by DATA.
1469 F is the frame the created menu belongs to.
1470 SELECT_CB is the callback to use when a menu item is selected.
1471 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
1472 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1473 POP_UP_P is non-zero if we shall create a popup menu.
1474 MENU_BAR_P is non-zero if we shall create a menu bar.
1475 ADD_TEAROFF_P is non-zero if we shall add a teroff menu item. Ignored
1476 if MENU_BAR_P is non-zero.
1477 TOPMENU is the topmost GtkWidget that others shall be placed under.
1478 It may be NULL, in that case we create the appropriate widget
1479 (menu bar or menu item depending on POP_UP_P and MENU_BAR_P)
1480 CL_DATA is the callback data we shall use for this menu, or NULL
1481 if we haven't set the first callback yet.
1482 NAME is the name to give to the top level menu if this function
1483 creates it. May be NULL to not set any name.
1485 Returns the top level GtkWidget. This is TOPLEVEL if TOPLEVEL is
1488 This function calls itself to create submenus. */
1491 create_menus (data
, f
, select_cb
, deactivate_cb
, highlight_cb
,
1492 pop_up_p
, menu_bar_p
, add_tearoff_p
, topmenu
, cl_data
, name
)
1495 GCallback select_cb
;
1496 GCallback deactivate_cb
;
1497 GCallback highlight_cb
;
1502 xg_menu_cb_data
*cl_data
;
1506 GtkWidget
*wmenu
= topmenu
;
1507 GSList
*group
= NULL
;
1511 if (! menu_bar_p
) wmenu
= gtk_menu_new ();
1512 else wmenu
= gtk_menu_bar_new ();
1514 /* Put cl_data on the top menu for easier access. */
1515 cl_data
= make_cl_data (cl_data
, f
, highlight_cb
);
1516 g_object_set_data (G_OBJECT (wmenu
), XG_FRAME_DATA
, (gpointer
)cl_data
);
1517 g_signal_connect (G_OBJECT (wmenu
), "destroy",
1518 G_CALLBACK (menu_destroy_callback
), cl_data
);
1521 gtk_widget_set_name (wmenu
, name
);
1524 g_signal_connect (G_OBJECT (wmenu
),
1525 "deactivate", deactivate_cb
, 0);
1527 g_signal_connect (G_OBJECT (wmenu
),
1528 "grab-notify", G_CALLBACK (menu_grab_callback
), 0);
1531 if (! menu_bar_p
&& add_tearoff_p
)
1533 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new ();
1534 gtk_menu_shell_append (GTK_MENU_SHELL (wmenu
), tearoff
);
1536 g_signal_connect (G_OBJECT (tearoff
), "activate",
1537 G_CALLBACK (tearoff_activate
), 0);
1540 for (item
= data
; item
; item
= item
->next
)
1544 if (pop_up_p
&& !item
->contents
&& !item
->call_data
1545 && !xg_separator_p (item
->name
))
1548 /* A title for a popup. We do the same as GTK does when
1549 creating titles, but it does not look good. */
1551 utf8_label
= get_utf8_string (item
->name
);
1553 gtk_menu_set_title (GTK_MENU (wmenu
), utf8_label
);
1554 w
= gtk_menu_item_new_with_label (utf8_label
);
1555 gtk_widget_set_sensitive (w
, FALSE
);
1556 if (utf8_label
&& utf8_label
!= item
->name
) g_free (utf8_label
);
1558 else if (xg_separator_p (item
->name
))
1561 /* GTK only have one separator type. */
1562 w
= gtk_separator_menu_item_new ();
1566 w
= xg_create_one_menuitem (item
,
1568 item
->contents
? 0 : select_cb
,
1575 GtkWidget
*submenu
= create_menus (item
->contents
,
1586 gtk_menu_item_set_submenu (GTK_MENU_ITEM (w
), submenu
);
1590 gtk_menu_shell_append (GTK_MENU_SHELL (wmenu
), w
);
1591 gtk_widget_set_name (w
, MENU_ITEM_NAME
);
1597 /* Create a menubar, popup menu or dialog, depending on the TYPE argument.
1598 TYPE can be "menubar", "popup" for popup menu, or "dialog" for a dialog
1599 with some text and buttons.
1600 F is the frame the created item belongs to.
1601 NAME is the name to use for the top widget.
1602 VAL is a widget_value structure describing items to be created.
1603 SELECT_CB is the callback to use when a menu item is selected or
1604 a dialog button is pressed.
1605 DEACTIVATE_CB is the callback to use when an item is deactivated.
1606 For a menu, when a sub menu is not shown anymore, for a dialog it is
1607 called when the dialog is popped down.
1608 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1610 Returns the widget created. */
1612 xg_create_widget (type
, name
, f
, val
,
1613 select_cb
, deactivate_cb
, highlight_cb
)
1618 GCallback select_cb
;
1619 GCallback deactivate_cb
;
1620 GCallback highlight_cb
;
1623 if (strcmp (type
, "dialog") == 0)
1625 w
= create_dialog (val
, select_cb
, deactivate_cb
);
1626 gtk_window_set_transient_for (GTK_WINDOW (w
),
1627 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
1628 gtk_window_set_destroy_with_parent (GTK_WINDOW (w
), TRUE
);
1631 gtk_widget_set_name (w
, "emacs-dialog");
1633 else if (strcmp (type
, "menubar") == 0 || strcmp (type
, "popup") == 0)
1635 w
= create_menus (val
->contents
,
1640 strcmp (type
, "popup") == 0,
1641 strcmp (type
, "menubar") == 0,
1647 /* Set the cursor to an arrow for popup menus when they are mapped.
1648 This is done by default for menu bar menus. */
1649 if (strcmp (type
, "popup") == 0)
1651 /* Must realize so the GdkWindow inside the widget is created. */
1652 gtk_widget_realize (w
);
1653 xg_set_cursor (w
, &xg_left_ptr_cursor
);
1658 fprintf (stderr
, "bad type in xg_create_widget: %s, doing nothing\n",
1665 /* Return the label for menu item WITEM. */
1667 xg_get_menu_item_label (witem
)
1670 GtkLabel
*wlabel
= GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem
)));
1671 return gtk_label_get_label (wlabel
);
1674 /* Return non-zero if the menu item WITEM has the text LABEL. */
1676 xg_item_label_same_p (witem
, label
)
1681 char *utf8_label
= get_utf8_string (label
);
1682 const char *old_label
= witem
? xg_get_menu_item_label (witem
) : 0;
1684 if (! old_label
&& ! utf8_label
)
1686 else if (old_label
&& utf8_label
)
1687 is_same
= strcmp (utf8_label
, old_label
) == 0;
1689 if (utf8_label
&& utf8_label
!= label
) g_free (utf8_label
);
1694 /* Remove widgets in LIST from container WCONT. */
1696 remove_from_container (wcont
, list
)
1702 for (iter
= list
; iter
; iter
= g_list_next (iter
))
1704 GtkWidget
*w
= GTK_WIDGET (iter
->data
);
1706 /* Add a ref to w so we can explicitly destroy it later. */
1708 gtk_container_remove (GTK_CONTAINER (wcont
), w
);
1710 /* If there is a menu under this widget that has been detached,
1711 there is a reference to it, and just removing w from the
1712 container does not destroy the submenu. By explicitly
1713 destroying w we make sure the submenu is destroyed, thus
1714 removing the detached window also if there was one. */
1715 gtk_widget_destroy (w
);
1719 /* Update the top level names in MENUBAR (i.e. not submenus).
1720 F is the frame the menu bar belongs to.
1721 *LIST is a list with the current menu bar names (menu item widgets).
1722 ITER is the item within *LIST that shall be updated.
1723 POS is the numerical position, starting at 0, of ITER in *LIST.
1724 VAL describes what the menu bar shall look like after the update.
1725 SELECT_CB is the callback to use when a menu item is selected.
1726 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1727 CL_DATA points to the callback data to be used for this menu bar.
1729 This function calls itself to walk through the menu bar names. */
1731 xg_update_menubar (menubar
, f
, list
, iter
, pos
, val
,
1732 select_cb
, highlight_cb
, cl_data
)
1739 GCallback select_cb
;
1740 GCallback highlight_cb
;
1741 xg_menu_cb_data
*cl_data
;
1743 if (! iter
&& ! val
)
1745 else if (iter
&& ! val
)
1747 /* Item(s) have been removed. Remove all remaining items. */
1748 remove_from_container (menubar
, iter
);
1754 else if (! iter
&& val
)
1756 /* Item(s) added. Add all new items in one call. */
1757 create_menus (val
, f
, select_cb
, 0, highlight_cb
,
1758 0, 1, 0, menubar
, cl_data
, 0);
1764 /* Below this neither iter or val is NULL */
1765 else if (xg_item_label_same_p (GTK_MENU_ITEM (iter
->data
), val
->name
))
1767 /* This item is still the same, check next item. */
1769 iter
= g_list_next (iter
);
1772 else /* This item is changed. */
1774 GtkMenuItem
*witem
= GTK_MENU_ITEM (iter
->data
);
1775 GtkMenuItem
*witem2
= 0;
1776 int val_in_menubar
= 0;
1777 int iter_in_new_menubar
= 0;
1781 /* See if the changed entry (val) is present later in the menu bar */
1783 iter2
&& ! val_in_menubar
;
1784 iter2
= g_list_next (iter2
))
1786 witem2
= GTK_MENU_ITEM (iter2
->data
);
1787 val_in_menubar
= xg_item_label_same_p (witem2
, val
->name
);
1790 /* See if the current entry (iter) is present later in the
1791 specification for the new menu bar. */
1792 for (cur
= val
; cur
&& ! iter_in_new_menubar
; cur
= cur
->next
)
1793 iter_in_new_menubar
= xg_item_label_same_p (witem
, cur
->name
);
1795 if (val_in_menubar
&& ! iter_in_new_menubar
)
1799 /* This corresponds to:
1804 gtk_widget_ref (GTK_WIDGET (witem
));
1805 gtk_container_remove (GTK_CONTAINER (menubar
), GTK_WIDGET (witem
));
1806 gtk_widget_destroy (GTK_WIDGET (witem
));
1808 /* Must get new list since the old changed. */
1809 g_list_free (*list
);
1810 *list
= iter
= gtk_container_get_children (GTK_CONTAINER (menubar
));
1811 while (nr
-- > 0) iter
= g_list_next (iter
);
1813 else if (! val_in_menubar
&& ! iter_in_new_menubar
)
1815 /* This corresponds to:
1818 Rename B to X. This might seem to be a strange thing to do,
1819 since if there is a menu under B it will be totally wrong for X.
1820 But consider editing a C file. Then there is a C-mode menu
1821 (corresponds to B above).
1822 If then doing C-x C-f the minibuf menu (X above) replaces the
1823 C-mode menu. When returning from the minibuffer, we get
1824 back the C-mode menu. Thus we do:
1825 Rename B to X (C-mode to minibuf menu)
1826 Rename X to B (minibuf to C-mode menu).
1827 If the X menu hasn't been invoked, the menu under B
1828 is up to date when leaving the minibuffer. */
1829 GtkLabel
*wlabel
= GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem
)));
1830 char *utf8_label
= get_utf8_string (val
->name
);
1832 gtk_label_set_text (wlabel
, utf8_label
);
1834 iter
= g_list_next (iter
);
1838 else if (! val_in_menubar
&& iter_in_new_menubar
)
1840 /* This corresponds to:
1847 GtkWidget
*w
= xg_create_one_menuitem (val
,
1854 gtk_widget_set_name (w
, MENU_ITEM_NAME
);
1855 gtk_menu_shell_insert (GTK_MENU_SHELL (menubar
), w
, pos
);
1857 g_list_free (*list
);
1858 *list
= iter
= gtk_container_get_children (GTK_CONTAINER (menubar
));
1859 while (nr
-- > 0) iter
= g_list_next (iter
);
1860 iter
= g_list_next (iter
);
1864 else /* if (val_in_menubar && iter_in_new_menubar) */
1867 /* This corresponds to:
1872 gtk_widget_ref (GTK_WIDGET (witem2
));
1873 gtk_container_remove (GTK_CONTAINER (menubar
), GTK_WIDGET (witem2
));
1874 gtk_menu_shell_insert (GTK_MENU_SHELL (menubar
),
1875 GTK_WIDGET (witem2
), pos
);
1876 gtk_widget_unref (GTK_WIDGET (witem2
));
1878 g_list_free (*list
);
1879 *list
= iter
= gtk_container_get_children (GTK_CONTAINER (menubar
));
1880 while (nr
-- > 0) iter
= g_list_next (iter
);
1886 /* Update the rest of the menu bar. */
1887 xg_update_menubar (menubar
, f
, list
, iter
, pos
, val
,
1888 select_cb
, highlight_cb
, cl_data
);
1891 /* Update the menu item W so it corresponds to VAL.
1892 SELECT_CB is the callback to use when a menu item is selected.
1893 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
1894 CL_DATA is the data to set in the widget for menu invokation. */
1896 xg_update_menu_item (val
, w
, select_cb
, highlight_cb
, cl_data
)
1899 GCallback select_cb
;
1900 GCallback highlight_cb
;
1901 xg_menu_cb_data
*cl_data
;
1908 const char *old_label
= 0;
1909 const char *old_key
= 0;
1910 xg_menu_item_cb_data
*cb_data
;
1912 wchild
= gtk_bin_get_child (GTK_BIN (w
));
1913 utf8_label
= get_utf8_string (val
->name
);
1914 utf8_key
= get_utf8_string (val
->key
);
1916 /* See if W is a menu item with a key. See make_menu_item above. */
1917 if (GTK_IS_HBOX (wchild
))
1919 GList
*list
= gtk_container_get_children (GTK_CONTAINER (wchild
));
1921 wlbl
= GTK_LABEL (list
->data
);
1922 wkey
= GTK_LABEL (list
->next
->data
);
1927 /* Remove the key and keep just the label. */
1928 gtk_widget_ref (GTK_WIDGET (wlbl
));
1929 gtk_container_remove (GTK_CONTAINER (w
), wchild
);
1930 gtk_container_add (GTK_CONTAINER (w
), GTK_WIDGET (wlbl
));
1935 else /* Just a label. */
1937 wlbl
= GTK_LABEL (wchild
);
1939 /* Check if there is now a key. */
1942 GtkWidget
*wtoadd
= make_widget_for_menu_item (utf8_label
, utf8_key
);
1943 GList
*list
= gtk_container_get_children (GTK_CONTAINER (wtoadd
));
1945 wlbl
= GTK_LABEL (list
->data
);
1946 wkey
= GTK_LABEL (list
->next
->data
);
1949 gtk_container_remove (GTK_CONTAINER (w
), wchild
);
1950 gtk_container_add (GTK_CONTAINER (w
), wtoadd
);
1955 if (wkey
) old_key
= gtk_label_get_label (wkey
);
1956 if (wlbl
) old_label
= gtk_label_get_label (wlbl
);
1958 if (wkey
&& utf8_key
&& (! old_key
|| strcmp (utf8_key
, old_key
) != 0))
1959 gtk_label_set_text (wkey
, utf8_key
);
1961 if (! old_label
|| strcmp (utf8_label
, old_label
) != 0)
1962 gtk_label_set_text (wlbl
, utf8_label
);
1964 if (utf8_key
&& utf8_key
!= val
->key
) g_free (utf8_key
);
1965 if (utf8_label
&& utf8_label
!= val
->name
) g_free (utf8_label
);
1967 if (! val
->enabled
&& GTK_WIDGET_SENSITIVE (w
))
1968 gtk_widget_set_sensitive (w
, FALSE
);
1969 else if (val
->enabled
&& ! GTK_WIDGET_SENSITIVE (w
))
1970 gtk_widget_set_sensitive (w
, TRUE
);
1972 cb_data
= (xg_menu_item_cb_data
*) g_object_get_data (G_OBJECT (w
),
1976 cb_data
->call_data
= val
->call_data
;
1977 cb_data
->help
= val
->help
;
1978 cb_data
->cl_data
= cl_data
;
1980 /* We assume the callback functions don't change. */
1981 if (val
->call_data
&& ! val
->contents
)
1983 /* This item shall have a select callback. */
1984 if (! cb_data
->select_id
)
1986 = g_signal_connect (G_OBJECT (w
), "activate",
1987 select_cb
, cb_data
);
1989 else if (cb_data
->select_id
)
1991 g_signal_handler_disconnect (w
, cb_data
->select_id
);
1992 cb_data
->select_id
= 0;
1995 if (NILP (cb_data
->help
))
1997 /* Shall not have help. Remove if any existed previously. */
1998 if (cb_data
->highlight_id
)
2000 g_signal_handler_disconnect (G_OBJECT (w
),
2001 cb_data
->highlight_id
);
2002 cb_data
->highlight_id
= 0;
2004 if (cb_data
->unhighlight_id
)
2006 g_signal_handler_disconnect (G_OBJECT (w
),
2007 cb_data
->unhighlight_id
);
2008 cb_data
->unhighlight_id
= 0;
2011 else if (! cb_data
->highlight_id
&& highlight_cb
)
2013 /* Have help now, but didn't previously. Add callback. */
2014 cb_data
->highlight_id
2015 = g_signal_connect (G_OBJECT (w
),
2016 "enter-notify-event",
2017 G_CALLBACK (menuitem_highlight_callback
),
2019 cb_data
->unhighlight_id
2020 = g_signal_connect (G_OBJECT (w
),
2021 "leave-notify-event",
2022 G_CALLBACK (menuitem_highlight_callback
),
2028 /* Update the toggle menu item W so it corresponds to VAL. */
2030 xg_update_toggle_item (val
, w
)
2034 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), val
->selected
);
2037 /* Update the radio menu item W so it corresponds to VAL. */
2039 xg_update_radio_item (val
, w
)
2043 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w
), val
->selected
);
2046 /* Update the sub menu SUBMENU and all its children so it corresponds to VAL.
2047 SUBMENU may be NULL, in that case a new menu is created.
2048 F is the frame the menu bar belongs to.
2049 VAL describes the contents of the menu bar.
2050 SELECT_CB is the callback to use when a menu item is selected.
2051 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
2052 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
2053 CL_DATA is the call back data to use for any newly created items.
2055 Returns the updated submenu widget, that is SUBMENU unless SUBMENU
2059 xg_update_submenu (submenu
, f
, val
,
2060 select_cb
, deactivate_cb
, highlight_cb
, cl_data
)
2064 GCallback select_cb
;
2065 GCallback deactivate_cb
;
2066 GCallback highlight_cb
;
2067 xg_menu_cb_data
*cl_data
;
2069 GtkWidget
*newsub
= submenu
;
2073 int has_tearoff_p
= 0;
2074 GList
*first_radio
= 0;
2077 list
= gtk_container_get_children (GTK_CONTAINER (submenu
));
2079 for (cur
= val
, iter
= list
;
2081 iter
= g_list_next (iter
), cur
= cur
->next
)
2083 GtkWidget
*w
= GTK_WIDGET (iter
->data
);
2085 /* Skip tearoff items, they have no counterpart in val. */
2086 if (GTK_IS_TEAROFF_MENU_ITEM (w
))
2089 iter
= g_list_next (iter
);
2090 if (iter
) w
= GTK_WIDGET (iter
->data
);
2094 /* Remember first radio button in a group. If we get a mismatch in
2095 a radio group we must rebuild the whole group so that the connections
2096 in GTK becomes correct. */
2097 if (cur
->button_type
== BUTTON_TYPE_RADIO
&& ! first_radio
)
2099 else if (cur
->button_type
!= BUTTON_TYPE_RADIO
2100 && ! GTK_IS_RADIO_MENU_ITEM (w
))
2103 if (GTK_IS_SEPARATOR_MENU_ITEM (w
))
2105 if (! xg_separator_p (cur
->name
))
2108 else if (GTK_IS_CHECK_MENU_ITEM (w
))
2110 if (cur
->button_type
!= BUTTON_TYPE_TOGGLE
)
2112 xg_update_toggle_item (cur
, w
);
2113 xg_update_menu_item (cur
, w
, select_cb
, highlight_cb
, cl_data
);
2115 else if (GTK_IS_RADIO_MENU_ITEM (w
))
2117 if (cur
->button_type
!= BUTTON_TYPE_RADIO
)
2119 xg_update_radio_item (cur
, w
);
2120 xg_update_menu_item (cur
, w
, select_cb
, highlight_cb
, cl_data
);
2122 else if (GTK_IS_MENU_ITEM (w
))
2124 GtkMenuItem
*witem
= GTK_MENU_ITEM (w
);
2127 if (cur
->button_type
!= BUTTON_TYPE_NONE
||
2128 xg_separator_p (cur
->name
))
2131 xg_update_menu_item (cur
, w
, select_cb
, highlight_cb
, cl_data
);
2133 sub
= gtk_menu_item_get_submenu (witem
);
2134 if (sub
&& ! cur
->contents
)
2136 /* Not a submenu anymore. */
2137 gtk_widget_ref (sub
);
2138 gtk_menu_item_remove_submenu (witem
);
2139 gtk_widget_destroy (sub
);
2141 else if (cur
->contents
)
2145 nsub
= xg_update_submenu (sub
, f
, cur
->contents
,
2146 select_cb
, deactivate_cb
,
2147 highlight_cb
, cl_data
);
2149 /* If this item just became a submenu, we must set it. */
2151 gtk_menu_item_set_submenu (witem
, nsub
);
2156 /* Structural difference. Remove everything from here and down
2162 /* Remove widgets from first structual change. */
2165 /* If we are adding new menu items below, we must remove from
2166 first radio button so that radio groups become correct. */
2167 if (cur
&& first_radio
) remove_from_container (submenu
, first_radio
);
2168 else remove_from_container (submenu
, iter
);
2173 /* More items added. Create them. */
2174 newsub
= create_menus (cur
,
2187 if (list
) g_list_free (list
);
2192 /* Update the MENUBAR.
2193 F is the frame the menu bar belongs to.
2194 VAL describes the contents of the menu bar.
2195 If DEEP_P is non-zero, rebuild all but the top level menu names in
2196 the MENUBAR. If DEEP_P is zero, just rebuild the names in the menubar.
2197 SELECT_CB is the callback to use when a menu item is selected.
2198 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore.
2199 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. */
2201 xg_modify_menubar_widgets (menubar
, f
, val
, deep_p
,
2202 select_cb
, deactivate_cb
, highlight_cb
)
2207 GCallback select_cb
;
2208 GCallback deactivate_cb
;
2209 GCallback highlight_cb
;
2211 xg_menu_cb_data
*cl_data
;
2212 GList
*list
= gtk_container_get_children (GTK_CONTAINER (menubar
));
2216 cl_data
= (xg_menu_cb_data
*) g_object_get_data (G_OBJECT (menubar
),
2221 widget_value
*cur
= val
->contents
;
2222 xg_update_menubar (menubar
, f
, &list
, list
, 0, cur
,
2223 select_cb
, highlight_cb
, cl_data
);
2229 /* Update all sub menus.
2230 We must keep the submenu names (GTK menu item widgets) since the
2231 X Window in the XEvent that activates the menu are those widgets. */
2233 /* Update cl_data, menu_item things in F may have changed. */
2234 update_cl_data (cl_data
, f
, highlight_cb
);
2236 for (cur
= val
->contents
; cur
; cur
= cur
->next
)
2243 /* Find sub menu that corresponds to val and update it. */
2244 for (iter
= list
; iter
; iter
= g_list_next (iter
))
2246 witem
= GTK_MENU_ITEM (iter
->data
);
2247 if (xg_item_label_same_p (witem
, cur
->name
))
2249 sub
= gtk_menu_item_get_submenu (witem
);
2254 newsub
= xg_update_submenu (sub
,
2261 /* sub may still be NULL. If we just updated non deep and added
2262 a new menu bar item, it has no sub menu yet. So we set the
2263 newly created sub menu under witem. */
2265 gtk_menu_item_set_submenu (witem
, newsub
);
2271 gtk_widget_show_all (menubar
);
2274 /* Recompute all the widgets of frame F, when the menu bar has been
2275 changed. Value is non-zero if widgets were updated. */
2278 xg_update_frame_menubar (f
)
2281 struct x_output
*x
= f
->output_data
.x
;
2284 if (!x
->menubar_widget
|| GTK_WIDGET_MAPPED (x
->menubar_widget
))
2289 gtk_box_pack_start (GTK_BOX (x
->vbox_widget
), x
->menubar_widget
,
2291 gtk_box_reorder_child (GTK_BOX (x
->vbox_widget
), x
->menubar_widget
, 0);
2293 gtk_widget_show_all (x
->menubar_widget
);
2294 gtk_widget_size_request (x
->menubar_widget
, &req
);
2296 FRAME_MENUBAR_HEIGHT (f
) = req
.height
;
2298 /* The height has changed, resize outer widget and set columns
2299 rows to what we had before adding the menu bar. */
2300 xg_resize_outer_widget (f
, FRAME_COLS (f
), FRAME_LINES (f
));
2302 SET_FRAME_GARBAGED (f
);
2308 /* Get rid of the menu bar of frame F, and free its storage.
2309 This is used when deleting a frame, and when turning off the menu bar. */
2312 free_frame_menubar (f
)
2315 struct x_output
*x
= f
->output_data
.x
;
2317 if (x
->menubar_widget
)
2321 gtk_container_remove (GTK_CONTAINER (x
->vbox_widget
), x
->menubar_widget
);
2322 /* The menubar and its children shall be deleted when removed from
2324 x
->menubar_widget
= 0;
2325 FRAME_MENUBAR_HEIGHT (f
) = 0;
2327 /* The height has changed, resize outer widget and set columns
2328 rows to what we had before removing the menu bar. */
2329 xg_resize_outer_widget (f
, FRAME_COLS (f
), FRAME_LINES (f
));
2331 SET_FRAME_GARBAGED (f
);
2338 /***********************************************************************
2339 Scroll bar functions
2340 ***********************************************************************/
2343 /* Setting scroll bar values invokes the callback. Use this variable
2344 to indicate that callback should do nothing. */
2345 int xg_ignore_gtk_scrollbar
;
2347 /* SET_SCROLL_BAR_X_WINDOW assumes the second argument fits in
2348 32 bits. But we want to store pointers, and they may be larger
2349 than 32 bits. Keep a mapping from integer index to widget pointers
2350 to get around the 32 bit limitation. */
2353 GtkWidget
**widgets
;
2358 /* Grow this much every time we need to allocate more */
2359 #define ID_TO_WIDGET_INCR 32
2361 /* Store the widget pointer W in id_to_widget and return the integer index. */
2363 xg_store_widget_in_map (w
)
2368 if (id_to_widget
.max_size
== id_to_widget
.used
)
2370 int new_size
= id_to_widget
.max_size
+ ID_TO_WIDGET_INCR
;
2372 id_to_widget
.widgets
= xrealloc (id_to_widget
.widgets
,
2373 sizeof (GtkWidget
*)*new_size
);
2375 for (i
= id_to_widget
.max_size
; i
< new_size
; ++i
)
2376 id_to_widget
.widgets
[i
] = 0;
2377 id_to_widget
.max_size
= new_size
;
2380 /* Just loop over the array and find a free place. After all,
2381 how many scroll bars are we creating? Should be a small number.
2382 The check above guarantees we will find a free place. */
2383 for (i
= 0; i
< id_to_widget
.max_size
; ++i
)
2385 if (! id_to_widget
.widgets
[i
])
2387 id_to_widget
.widgets
[i
] = w
;
2388 ++id_to_widget
.used
;
2394 /* Should never end up here */
2398 /* Remove pointer at IDX from id_to_widget.
2399 Called when scroll bar is destroyed. */
2401 xg_remove_widget_from_map (idx
)
2404 if (idx
< id_to_widget
.max_size
&& id_to_widget
.widgets
[idx
] != 0)
2406 id_to_widget
.widgets
[idx
] = 0;
2407 --id_to_widget
.used
;
2411 /* Get the widget pointer at IDX from id_to_widget. */
2413 xg_get_widget_from_map (idx
)
2416 if (idx
< id_to_widget
.max_size
&& id_to_widget
.widgets
[idx
] != 0)
2417 return id_to_widget
.widgets
[idx
];
2422 /* Return the scrollbar id for X Window WID.
2423 Return -1 if WID not in id_to_widget. */
2425 xg_get_scroll_id_for_window (wid
)
2431 w
= xg_win_to_widget (wid
);
2435 for (idx
= 0; idx
< id_to_widget
.max_size
; ++idx
)
2436 if (id_to_widget
.widgets
[idx
] == w
)
2443 /* Callback invoked when scroll bar WIDGET is destroyed.
2444 DATA is the index into id_to_widget for WIDGET.
2445 We free pointer to last scroll bar values here and remove the index. */
2447 xg_gtk_scroll_destroy (widget
, data
)
2454 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
2456 xg_remove_widget_from_map (id
);
2459 /* Callback for button press/release events. Used to start timer so that
2460 the scroll bar repetition timer in GTK gets handeled.
2461 Also, sets bar->dragging to Qnil when dragging (button release) is done.
2462 WIDGET is the scroll bar widget the event is for (not used).
2463 EVENT contains the event.
2464 USER_DATA points to the struct scrollbar structure.
2466 Returns FALSE to tell GTK that it shall continue propagate the event
2469 scroll_bar_button_cb (widget
, event
, user_data
)
2471 GdkEventButton
*event
;
2474 if (event
->type
== GDK_BUTTON_PRESS
&& ! xg_timer
)
2476 else if (event
->type
== GDK_BUTTON_RELEASE
)
2478 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
2479 if (xg_timer
) xg_stop_timer ();
2480 bar
->dragging
= Qnil
;
2486 /* Create a scroll bar widget for frame F. Store the scroll bar
2488 SCROLL_CALLBACK is the callback to invoke when the value of the
2490 SCROLL_BAR_NAME is the name we use for the scroll bar. Can be used
2491 to set resources for the widget. */
2493 xg_create_scroll_bar (f
, bar
, scroll_callback
, scroll_bar_name
)
2495 struct scroll_bar
*bar
;
2496 GCallback scroll_callback
;
2497 char *scroll_bar_name
;
2503 /* Page, step increment values are not so important here, they
2504 will be corrected in x_set_toolkit_scroll_bar_thumb. */
2505 vadj
= gtk_adjustment_new (XG_SB_MIN
, XG_SB_MIN
, XG_SB_MAX
,
2508 wscroll
= gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj
));
2509 gtk_widget_set_name (wscroll
, scroll_bar_name
);
2510 gtk_range_set_update_policy (GTK_RANGE (wscroll
), GTK_UPDATE_CONTINUOUS
);
2512 scroll_id
= xg_store_widget_in_map (wscroll
);
2514 g_signal_connect (G_OBJECT (wscroll
),
2518 g_signal_connect (G_OBJECT (wscroll
),
2520 G_CALLBACK (xg_gtk_scroll_destroy
),
2521 (gpointer
) scroll_id
);
2523 /* Connect to button press and button release to detect if any scroll bar
2525 g_signal_connect (G_OBJECT (wscroll
),
2526 "button-press-event",
2527 G_CALLBACK (scroll_bar_button_cb
),
2529 g_signal_connect (G_OBJECT (wscroll
),
2530 "button-release-event",
2531 G_CALLBACK (scroll_bar_button_cb
),
2534 gtk_fixed_put (GTK_FIXED (f
->output_data
.x
->edit_widget
),
2537 /* Set the cursor to an arrow. */
2538 xg_set_cursor (wscroll
, &xg_left_ptr_cursor
);
2540 SET_SCROLL_BAR_X_WINDOW (bar
, scroll_id
);
2543 /* Make the scroll bar represented by SCROLLBAR_ID visible. */
2545 xg_show_scroll_bar (scrollbar_id
)
2548 GtkWidget
*w
= xg_get_widget_from_map (scrollbar_id
);
2550 gtk_widget_show (w
);
2553 /* Remove the scroll bar represented by SCROLLBAR_ID from the frame F. */
2555 xg_remove_scroll_bar (f
, scrollbar_id
)
2559 GtkWidget
*w
= xg_get_widget_from_map (scrollbar_id
);
2562 gtk_widget_destroy (w
);
2563 SET_FRAME_GARBAGED (f
);
2567 /* Find left/top for widget W in GtkFixed widget WFIXED. */
2569 xg_find_top_left_in_fixed (w
, wfixed
, left
, top
)
2570 GtkWidget
*w
, *wfixed
;
2575 for (iter
= GTK_FIXED (wfixed
)->children
; iter
; iter
= g_list_next (iter
))
2577 GtkFixedChild
*child
= (GtkFixedChild
*) iter
->data
;
2579 if (child
->widget
== w
)
2587 /* Shall never end up here. */
2591 /* Update the position of the vertical scroll bar represented by SCROLLBAR_ID
2593 TOP/LEFT are the new pixel positions where the bar shall appear.
2594 WIDTH, HEIGHT is the size in pixels the bar shall have. */
2596 xg_update_scrollbar_pos (f
, scrollbar_id
, top
, left
, width
, height
,
2597 real_left
, canon_width
)
2606 GtkWidget
*wscroll
= xg_get_widget_from_map (scrollbar_id
);
2610 GtkWidget
*wfixed
= f
->output_data
.x
->edit_widget
;
2611 int winextra
= canon_width
> width
? (canon_width
- width
) / 2 : 0;
2612 int bottom
= top
+ height
;
2615 int oldtop
, oldleft
, oldbottom
;
2618 /* Get old values. */
2619 xg_find_top_left_in_fixed (wscroll
, wfixed
, &oldleft
, &oldtop
);
2620 gtk_widget_size_request (wscroll
, &req
);
2621 oldbottom
= oldtop
+ req
.height
;
2623 /* Scroll bars in GTK has a fixed width, so if we say width 16, it
2624 will only be its fixed width (14 is default) anyway, the rest is
2625 blank. We are drawing the mode line across scroll bars when
2633 When we "unsplit" the frame:
2642 the remains of the mode line can be seen in these blank spaces.
2643 So we must clear them explicitly.
2644 GTK scroll bars should do that, but they don't.
2645 Also, the canonical width may be wider than the width for the
2646 scroll bar so that there is some space (typically 1 pixel) between
2647 the scroll bar and the edge of the window and between the scroll
2648 bar and the fringe. */
2650 if (oldtop
!= -1 && oldleft
!= -1)
2652 int gtkextral
, gtkextrah
;
2653 int xl
, xr
, wbl
, wbr
;
2654 int bottomdiff
, topdiff
;
2656 gtk_widget_style_get (wscroll
, "slider_width", &slider_width
, NULL
);
2657 gtkextral
= width
> slider_width
? (width
- slider_width
) / 2 : 0;
2658 gtkextrah
= gtkextral
? (width
- slider_width
- gtkextral
) : 0;
2661 wbl
= gtkextral
+ winextra
;
2662 wbr
= gtkextrah
+ winextra
;
2663 xr
= left
+ gtkextral
+ slider_width
;
2664 bottomdiff
= abs (oldbottom
- bottom
);
2665 topdiff
= abs (oldtop
- top
);
2667 if (oldleft
!= left
)
2669 gdk_window_clear_area (wfixed
->window
, xl
, top
, wbl
, height
);
2670 gdk_window_clear_area (wfixed
->window
, xr
, top
, wbr
, height
);
2675 gdk_window_clear_area (wfixed
->window
, xl
, top
, wbl
, topdiff
);
2676 gdk_window_clear_area (wfixed
->window
, xr
, top
, wbr
, topdiff
);
2678 else if (oldtop
< top
)
2680 gdk_window_clear_area (wfixed
->window
, xl
, oldtop
, wbl
, topdiff
);
2681 gdk_window_clear_area (wfixed
->window
, xr
, oldtop
, wbr
, topdiff
);
2684 if (oldbottom
> bottom
)
2686 gdk_window_clear_area (wfixed
->window
, xl
, bottom
, wbl
,
2688 gdk_window_clear_area (wfixed
->window
, xr
, bottom
, wbr
,
2691 else if (oldbottom
< bottom
)
2693 gdk_window_clear_area (wfixed
->window
, xl
, oldbottom
, wbl
,
2695 gdk_window_clear_area (wfixed
->window
, xr
, oldbottom
, wbr
,
2700 /* Move and resize to new values. */
2701 gtk_fixed_move (GTK_FIXED (wfixed
), wscroll
, left
, top
);
2702 gtk_widget_set_size_request (wscroll
, width
, height
);
2704 /* Must force out update so changed scroll bars gets redrawn. */
2705 gdk_window_process_all_updates ();
2707 SET_FRAME_GARBAGED (f
);
2708 cancel_mouse_face (f
);
2712 /* Set the thumb size and position of scroll bar BAR. We are currently
2713 displaying PORTION out of a whole WHOLE, and our position POSITION. */
2715 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
2716 struct scroll_bar
*bar
;
2717 int portion
, position
, whole
;
2719 GtkWidget
*wscroll
= xg_get_widget_from_map (SCROLL_BAR_X_WINDOW (bar
));
2721 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2723 if (wscroll
&& NILP (bar
->dragging
))
2732 adj
= gtk_range_get_adjustment (GTK_RANGE (wscroll
));
2734 /* We do the same as for MOTIF in xterm.c, assume 30 chars per line
2735 rather than the real portion value. This makes the thumb less likely
2736 to resize and that looks better. */
2737 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
2738 /* When the thumb is at the bottom, position == whole.
2739 So we need to increase `whole' to make space for the thumb. */
2746 top
= (gdouble
) position
/ whole
;
2747 shown
= (gdouble
) portion
/ whole
;
2750 size
= shown
* XG_SB_RANGE
;
2751 size
= min (size
, XG_SB_RANGE
);
2752 size
= max (size
, 1);
2754 value
= top
* XG_SB_RANGE
;
2755 value
= min (value
, XG_SB_MAX
- size
);
2756 value
= max (value
, XG_SB_MIN
);
2758 /* Assume all lines are of equal size. */
2759 new_step
= size
/ max (1, FRAME_LINES (f
));
2761 if ((int) adj
->page_size
!= size
2762 || (int) adj
->step_increment
!= new_step
)
2764 adj
->page_size
= size
;
2765 adj
->step_increment
= new_step
;
2766 /* Assume a page increment is about 95% of the page size */
2767 adj
->page_increment
= (int) (0.95*adj
->page_size
);
2771 if (changed
|| (int) gtk_range_get_value (GTK_RANGE (wscroll
)) != value
)
2773 GtkWidget
*wfixed
= f
->output_data
.x
->edit_widget
;
2777 /* gtk_range_set_value invokes the callback. Set
2778 ignore_gtk_scrollbar to make the callback do nothing */
2779 xg_ignore_gtk_scrollbar
= 1;
2781 if ((int) gtk_range_get_value (GTK_RANGE (wscroll
)) != value
)
2782 gtk_range_set_value (GTK_RANGE (wscroll
), (gdouble
)value
);
2784 gtk_adjustment_changed (adj
);
2786 xg_ignore_gtk_scrollbar
= 0;
2794 /***********************************************************************
2796 ***********************************************************************/
2797 /* The key for the data we put in the GtkImage widgets. The data is
2798 the image used by Emacs. We use this to see if we need to update
2799 the GtkImage with a new image. */
2800 #define XG_TOOL_BAR_IMAGE_DATA "emacs-tool-bar-image"
2802 /* Callback function invoked when a tool bar item is pressed.
2803 W is the button widget in the tool bar that got pressed,
2804 CLIENT_DATA is an integer that is the index of the button in the
2805 tool bar. 0 is the first button. */
2807 xg_tool_bar_callback (w
, client_data
)
2809 gpointer client_data
;
2811 int idx
= (int)client_data
;
2812 FRAME_PTR f
= (FRAME_PTR
) g_object_get_data (G_OBJECT (w
), XG_FRAME_DATA
);
2813 Lisp_Object key
, frame
;
2814 struct input_event event
;
2816 if (! f
|| ! f
->n_tool_bar_items
|| NILP (f
->tool_bar_items
))
2819 idx
*= TOOL_BAR_ITEM_NSLOTS
;
2821 key
= AREF (f
->tool_bar_items
, idx
+ TOOL_BAR_ITEM_KEY
);
2822 XSETFRAME (frame
, f
);
2823 event
.kind
= TOOL_BAR_EVENT
;
2824 event
.frame_or_window
= frame
;
2826 kbd_buffer_store_event (&event
);
2828 event
.kind
= TOOL_BAR_EVENT
;
2829 event
.frame_or_window
= frame
;
2831 event
.modifiers
= 0; /* These are not available. */
2832 kbd_buffer_store_event (&event
);
2835 /* This callback is called when a tool bar is detached. We must set
2836 the height of the tool bar to zero when this happens so frame sizes
2837 are correctly calculated.
2838 WBOX is the handle box widget that enables detach/attach of the tool bar.
2839 W is the tool bar widget.
2840 CLIENT_DATA is a pointer to the frame the tool bar belongs to. */
2842 xg_tool_bar_detach_callback (wbox
, w
, client_data
)
2845 gpointer client_data
;
2847 FRAME_PTR f
= (FRAME_PTR
) client_data
;
2851 /* When detaching a tool bar, not everything dissapear. There are
2852 a few pixels left that are used to drop the tool bar back into
2854 int bw
= gtk_container_get_border_width (GTK_CONTAINER (wbox
));
2855 FRAME_TOOLBAR_HEIGHT (f
) = 2;
2857 /* The height has changed, resize outer widget and set columns
2858 rows to what we had before detaching the tool bar. */
2859 xg_resize_outer_widget (f
, FRAME_COLS (f
), FRAME_LINES (f
));
2863 /* This callback is called when a tool bar is reattached. We must set
2864 the height of the tool bar when this happens so frame sizes
2865 are correctly calculated.
2866 WBOX is the handle box widget that enables detach/attach of the tool bar.
2867 W is the tool bar widget.
2868 CLIENT_DATA is a pointer to the frame the tool bar belongs to. */
2870 xg_tool_bar_attach_callback (wbox
, w
, client_data
)
2873 gpointer client_data
;
2875 FRAME_PTR f
= (FRAME_PTR
) client_data
;
2881 gtk_widget_size_request (w
, &req
);
2882 FRAME_TOOLBAR_HEIGHT (f
) = req
.height
;
2884 /* The height has changed, resize outer widget and set columns
2885 rows to what we had before detaching the tool bar. */
2886 xg_resize_outer_widget (f
, FRAME_COLS (f
), FRAME_LINES (f
));
2890 /* This callback is called when the mouse enters or leaves a tool bar item.
2891 It is used for displaying and hiding the help text.
2892 W is the tool bar item, a button.
2893 EVENT is either an enter event or leave event.
2894 CLIENT_DATA is an integer that is the index of the button in the
2895 tool bar. 0 is the first button.
2897 Returns FALSE to tell GTK to keep processing this event. */
2899 xg_tool_bar_help_callback (w
, event
, client_data
)
2901 GdkEventCrossing
*event
;
2902 gpointer client_data
;
2904 int idx
= (int)client_data
;
2905 FRAME_PTR f
= (FRAME_PTR
) g_object_get_data (G_OBJECT (w
), XG_FRAME_DATA
);
2906 Lisp_Object help
, frame
;
2908 if (! GTK_IS_BUTTON (w
))
2913 if (! f
|| ! f
->n_tool_bar_items
|| NILP (f
->tool_bar_items
))
2916 if (event
->type
== GDK_ENTER_NOTIFY
)
2918 idx
*= TOOL_BAR_ITEM_NSLOTS
;
2919 help
= AREF (f
->tool_bar_items
, idx
+ TOOL_BAR_ITEM_HELP
);
2922 help
= AREF (f
->tool_bar_items
, idx
+ TOOL_BAR_ITEM_CAPTION
);
2927 XSETFRAME (frame
, f
);
2928 kbd_buffer_store_help_event (frame
, help
);
2934 /* This callback is called when a tool bar item shall be redrawn.
2935 It modifies the expose event so that the GtkImage widget redraws the
2936 whole image. This to overcome a bug that makes GtkImage draw the image
2937 in the wrong place when it tries to redraw just a part of the image.
2938 W is the GtkImage to be redrawn.
2939 EVENT is the expose event for W.
2940 CLIENT_DATA is unused.
2942 Returns FALSE to tell GTK to keep processing this event. */
2944 xg_tool_bar_item_expose_callback (w
, event
, client_data
)
2946 GdkEventExpose
*event
;
2947 gpointer client_data
;
2951 gdk_drawable_get_size (event
->window
, &width
, &height
);
2953 event
->area
.x
-= width
> event
->area
.width
? width
-event
->area
.width
: 0;
2954 event
->area
.y
-= height
> event
->area
.height
? height
-event
->area
.height
: 0;
2956 event
->area
.x
= max(0, event
->area
.x
);
2957 event
->area
.y
= max(0, event
->area
.y
);
2959 event
->area
.width
= max (width
, event
->area
.width
);
2960 event
->area
.height
= max (height
, event
->area
.height
);
2965 /* This callback is called when a tool bar shall be redrawn.
2966 We need to update the tool bar from here in case the image cache
2967 has deleted the pixmaps used in the tool bar.
2968 W is the GtkToolbar to be redrawn.
2969 EVENT is the expose event for W.
2970 CLIENT_DATA is pointing to the frame for this tool bar.
2972 Returns FALSE to tell GTK to keep processing this event. */
2974 xg_tool_bar_expose_callback (w
, event
, client_data
)
2976 GdkEventExpose
*event
;
2977 gpointer client_data
;
2979 update_frame_tool_bar((FRAME_PTR
)client_data
);
2984 xg_create_tool_bar (f
)
2987 struct x_output
*x
= f
->output_data
.x
;
2989 int vbox_pos
= x
->menubar_widget
? 1 : 0;
2991 x
->toolbar_widget
= gtk_toolbar_new ();
2992 x
->handlebox_widget
= gtk_handle_box_new ();
2993 gtk_container_add (GTK_CONTAINER (x
->handlebox_widget
),
2996 gtk_box_pack_start (GTK_BOX (x
->vbox_widget
), x
->handlebox_widget
,
2999 gtk_box_reorder_child (GTK_BOX (x
->vbox_widget
), x
->handlebox_widget
,
3002 gtk_widget_set_name (x
->toolbar_widget
, "emacs-toolbar");
3004 /* We only have icons, so override any user setting. We could
3005 use the caption property of the toolbar item (see update_frame_tool_bar
3006 below), but some of those strings are long, making the toolbar so
3007 long it does not fit on the screen. The GtkToolbar widget makes every
3008 item equal size, so the longest caption determine the size of every
3009 tool bar item. I think the creators of the GtkToolbar widget
3010 counted on 4 or 5 character long strings. */
3011 gtk_toolbar_set_style (GTK_TOOLBAR (x
->toolbar_widget
), GTK_TOOLBAR_ICONS
);
3012 gtk_toolbar_set_orientation (GTK_TOOLBAR (x
->toolbar_widget
),
3013 GTK_ORIENTATION_HORIZONTAL
);
3015 g_signal_connect (G_OBJECT (x
->handlebox_widget
), "child-detached",
3016 G_CALLBACK (xg_tool_bar_detach_callback
), f
);
3017 g_signal_connect (G_OBJECT (x
->handlebox_widget
), "child-attached",
3018 G_CALLBACK (xg_tool_bar_attach_callback
), f
);
3019 g_signal_connect (G_OBJECT (x
->toolbar_widget
),
3021 G_CALLBACK (xg_tool_bar_expose_callback
),
3024 gtk_widget_show_all (x
->handlebox_widget
);
3026 gtk_widget_size_request (x
->toolbar_widget
, &req
);
3027 FRAME_TOOLBAR_HEIGHT (f
) = req
.height
;
3029 /* The height has changed, resize outer widget and set columns
3030 rows to what we had before adding the tool bar. */
3031 xg_resize_outer_widget (f
, FRAME_COLS (f
), FRAME_LINES (f
));
3033 SET_FRAME_GARBAGED (f
);
3037 update_frame_tool_bar (f
)
3041 GtkRequisition old_req
, new_req
;
3044 struct x_output
*x
= f
->output_data
.x
;
3046 if (! FRAME_GTK_WIDGET (f
))
3051 if (! x
->toolbar_widget
)
3052 xg_create_tool_bar (f
);
3054 gtk_widget_size_request (x
->toolbar_widget
, &old_req
);
3056 icon_list
= gtk_container_get_children (GTK_CONTAINER (x
->toolbar_widget
));
3059 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
3061 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
3063 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
3064 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
3069 GtkWidget
*wicon
= iter
? GTK_WIDGET (iter
->data
) : 0;
3071 if (iter
) iter
= g_list_next (iter
);
3073 /* If image is a vector, choose the image according to the
3075 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
3076 if (VECTORP (image
))
3080 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
3081 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
3084 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
3085 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
3087 xassert (ASIZE (image
) >= idx
);
3088 image
= AREF (image
, idx
);
3093 /* Ignore invalid image specifications. */
3094 if (!valid_image_p (image
))
3096 if (wicon
) gtk_widget_hide (wicon
);
3100 img_id
= lookup_image (f
, image
);
3101 img
= IMAGE_FROM_ID (f
, img_id
);
3102 prepare_image_for_display (f
, img
);
3104 if (img
->load_failed_p
|| img
->pixmap
== None
)
3106 if (wicon
) gtk_widget_hide (wicon
);
3112 GdkPixmap
*gpix
= gdk_pixmap_foreign_new (img
->pixmap
);
3113 GdkBitmap
*gmask
= img
->mask
?
3114 (GdkBitmap
*) gdk_pixmap_foreign_new (img
->mask
) : 0;
3116 GtkWidget
*w
= gtk_image_new_from_pixmap (gpix
, gmask
);
3117 gtk_toolbar_append_item (GTK_TOOLBAR (x
->toolbar_widget
),
3120 GTK_SIGNAL_FUNC (xg_tool_bar_callback
),
3123 /* Save the image so we can see if an update is needed when
3124 this function is called again. */
3125 g_object_set_data (G_OBJECT (w
), XG_TOOL_BAR_IMAGE_DATA
,
3126 (gpointer
)img
->pixmap
);
3128 /* Catch expose events to overcome an annoying redraw bug, see
3129 comment for xg_tool_bar_item_expose_callback. */
3130 g_signal_connect (G_OBJECT (w
),
3132 G_CALLBACK (xg_tool_bar_item_expose_callback
),
3135 /* We must set sensitive on the button that is the parent
3136 of the GtkImage parent. Go upwards until we find the button. */
3137 while (! GTK_IS_BUTTON (w
))
3138 w
= gtk_widget_get_parent (w
);
3142 /* Save the frame in the button so the xg_tool_bar_callback
3144 g_object_set_data (G_OBJECT (w
), XG_FRAME_DATA
, (gpointer
)f
);
3145 gtk_widget_set_sensitive (w
, enabled_p
);
3147 /* Use enter/leave notify to show help. We use the events
3148 rather than the GtkButton specific signals "enter" and
3149 "leave", so we can have only one callback. The event
3150 will tell us what kind of event it is. */
3151 g_signal_connect (G_OBJECT (w
),
3152 "enter-notify-event",
3153 G_CALLBACK (xg_tool_bar_help_callback
),
3155 g_signal_connect (G_OBJECT (w
),
3156 "leave-notify-event",
3157 G_CALLBACK (xg_tool_bar_help_callback
),
3163 /* The child of the tool bar is a button. Inside that button
3164 is a vbox. Inside that vbox is the GtkImage. */
3165 GtkWidget
*wvbox
= gtk_bin_get_child (GTK_BIN (wicon
));
3166 GList
*chlist
= gtk_container_get_children (GTK_CONTAINER (wvbox
));
3167 GtkImage
*wimage
= GTK_IMAGE (chlist
->data
);
3168 Pixmap old_img
= (Pixmap
)g_object_get_data (G_OBJECT (wimage
),
3169 XG_TOOL_BAR_IMAGE_DATA
);
3170 g_list_free (chlist
);
3172 if (old_img
!= img
->pixmap
)
3174 GdkPixmap
*gpix
= gdk_pixmap_foreign_new (img
->pixmap
);
3175 GdkBitmap
*gmask
= img
->mask
?
3176 (GdkBitmap
*) gdk_pixmap_foreign_new (img
->mask
) : 0;
3178 gtk_image_set_from_pixmap (wimage
, gpix
, gmask
);
3181 g_object_set_data (G_OBJECT (wimage
), XG_TOOL_BAR_IMAGE_DATA
,
3182 (gpointer
)img
->pixmap
);
3184 gtk_widget_set_sensitive (wicon
, enabled_p
);
3185 gtk_widget_show (wicon
);
3191 /* Remove buttons not longer needed. We just hide them so they
3192 can be reused later on. */
3195 GtkWidget
*w
= GTK_WIDGET (iter
->data
);
3196 gtk_widget_hide (w
);
3197 iter
= g_list_next (iter
);
3200 gtk_widget_size_request (x
->toolbar_widget
, &new_req
);
3201 if (old_req
.height
!= new_req
.height
)
3203 FRAME_TOOLBAR_HEIGHT (f
) = new_req
.height
;
3204 xg_resize_outer_widget (f
, FRAME_COLS (f
), FRAME_LINES (f
));
3207 if (icon_list
) g_list_free (icon_list
);
3213 free_frame_tool_bar (f
)
3216 struct x_output
*x
= f
->output_data
.x
;
3218 if (x
->toolbar_widget
)
3221 gtk_container_remove (GTK_CONTAINER (x
->vbox_widget
),
3222 x
->handlebox_widget
);
3223 x
->toolbar_widget
= 0;
3224 x
->handlebox_widget
= 0;
3225 FRAME_TOOLBAR_HEIGHT (f
) = 0;
3227 /* The height has changed, resize outer widget and set columns
3228 rows to what we had before removing the tool bar. */
3229 xg_resize_outer_widget (f
, FRAME_COLS (f
), FRAME_LINES (f
));
3231 SET_FRAME_GARBAGED (f
);
3238 /***********************************************************************
3240 ***********************************************************************/
3244 xg_ignore_gtk_scrollbar
= 0;
3245 xg_left_ptr_cursor
= 0;
3248 xg_menu_cb_list
.prev
= xg_menu_cb_list
.next
=
3249 xg_menu_item_cb_list
.prev
= xg_menu_item_cb_list
.next
= 0;
3251 id_to_widget
.max_size
= id_to_widget
.used
= 0;
3252 id_to_widget
.widgets
= 0;
3254 /* Remove F10 as a menu accelerator, it does not mix well with Emacs key
3255 bindings. It doesn't seem to be any way to remove properties,
3256 so we set it to VoidSymbol which in X means "no key". */
3257 gtk_settings_set_string_property (gtk_settings_get_default (),
3258 "gtk-menu-bar-accel",
3262 /* Make GTK text input widgets use Emacs style keybindings. This is
3264 gtk_settings_set_string_property (gtk_settings_get_default (),
3265 "gtk-key-theme-name",
3270 #endif /* USE_GTK */