1 /* toolbar implementation -- GTK interface.
2 Copyright (C) 2000 Aaron Lehmann
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Synched up with: Not in FSF. */
26 #include "console-gtk.h"
27 #include "glyphs-gtk.h"
28 #include "objects-gtk.h"
35 #define SET_TOOLBAR_WAS_VISIBLE_FLAG(frame, pos, flag) \
40 (frame)->top_toolbar_was_visible = flag; \
42 case BOTTOM_TOOLBAR: \
43 (frame)->bottom_toolbar_was_visible = flag; \
46 (frame)->left_toolbar_was_visible = flag; \
49 (frame)->right_toolbar_was_visible = flag; \
57 gtk_clear_toolbar (struct frame *f, enum toolbar_pos pos);
60 gtk_toolbar_callback (GtkWidget *w, gpointer user_data)
62 struct toolbar_button *tb = (struct toolbar_button *) user_data;
69 gtk_output_toolbar (struct frame *f, enum toolbar_pos pos)
72 Lisp_Object button, window, glyph, instance;
73 unsigned int checksum = 0;
75 int x, y, bar_width, bar_height, vert;
78 window = FRAME_LAST_NONMINIBUF_WINDOW (f);
81 get_toolbar_coords (f, pos, &x, &y, &bar_width, &bar_height, &vert, 0);
83 /* Get the toolbar and delete the old widgets in it */
84 button = FRAME_TOOLBAR_BUTTONS (f, pos);
86 /* First loop over all of the buttons to determine how many there
87 are. This loop will also make sure that all instances are
88 instantiated so when we actually output them they will come up
90 while (!NILP (button))
92 struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
93 checksum = HASH4 (checksum,
94 internal_hash (get_toolbar_button_glyph(w, tb), 0),
95 internal_hash (tb->callback, 0),
100 /* Only do updates if the toolbar has changed, or this is the first
101 time we have drawn it in this position
103 if (FRAME_GTK_TOOLBAR_WIDGET (f)[pos] &&
104 FRAME_GTK_TOOLBAR_CHECKSUM (f, pos) == checksum)
109 /* Loop through buttons and add them to our toolbar.
110 This code ignores the button dimensions as we let GTK handle that :)
111 Attach the toolbar_button struct to the toolbar button so we know what
112 function to use as a callback. */
115 gtk_clear_toolbar (f, pos);
116 FRAME_GTK_TOOLBAR_WIDGET (f)[pos] = toolbar =
117 gtk_toolbar_new (((pos == TOP_TOOLBAR) || (pos == BOTTOM_TOOLBAR)) ?
118 GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL,
122 if (NILP (w->toolbar_buttons_captioned_p))
123 gtk_toolbar_set_style (toolbar, GTK_TOOLBAR_ICONS);
125 gtk_toolbar_set_style (toolbar, GTK_TOOLBAR_BOTH);
127 FRAME_GTK_TOOLBAR_CHECKSUM(f, pos) = checksum;
128 button = FRAME_TOOLBAR_BUTTONS (f, pos);
133 while (!NILP (button))
135 struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
139 /* It is a blank space... we do not pay attention to the
140 size, because the GTK toolbar does not allow us to
141 specify different spacings. *sigh*
143 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
147 /* It actually has a glyph associated with it! What WILL
150 glyph = tb->up_glyph;
152 /* #### It is currently possible for users to trash us by directly
153 changing the toolbar glyphs. Avoid crashing in that case. */
155 instance = glyph_image_instance (glyph, window, ERROR_ME_NOT, 1);
159 if (IMAGE_INSTANCEP(instance))
161 GtkWidget *pixmapwid;
164 char *tooltip = NULL;
166 if (STRINGP (tb->help_string))
167 tooltip = XSTRING_DATA (tb->help_string);
169 pixmap = XIMAGE_INSTANCE_GTK_PIXMAP(instance);
170 mask = XIMAGE_INSTANCE_GTK_MASK(instance);
171 pixmapwid = gtk_pixmap_new (pixmap, mask);
173 gtk_widget_set_usize (pixmapwid, tb->width, tb->height);
175 gtk_toolbar_append_item (GTK_TOOLBAR(toolbar), NULL, tooltip, NULL,
176 pixmapwid, gtk_toolbar_callback, (gpointer) tb);
179 cur_x += vert ? 0 : tb->width;
180 cur_y += vert ? tb->height : 0;
181 /* Who's idea was it to use a linked list for toolbar buttons? */
185 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 1);
190 gtk_fixed_put (GTK_FIXED (FRAME_GTK_TEXT_WIDGET (f)), FRAME_GTK_TOOLBAR_WIDGET (f)[pos],x, y);
191 gtk_widget_show_all (FRAME_GTK_TOOLBAR_WIDGET (f)[pos]);
195 gtk_clear_toolbar (struct frame *f, enum toolbar_pos pos)
197 FRAME_GTK_TOOLBAR_CHECKSUM (f, pos) = 0;
198 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 0);
199 if (FRAME_GTK_TOOLBAR_WIDGET(f)[pos])
200 gtk_widget_destroy (FRAME_GTK_TOOLBAR_WIDGET(f)[pos]);
204 gtk_output_frame_toolbars (struct frame *f)
206 if (FRAME_REAL_TOP_TOOLBAR_VISIBLE (f))
207 gtk_output_toolbar (f, TOP_TOOLBAR);
208 else if (f->top_toolbar_was_visible)
209 gtk_clear_toolbar (f, TOP_TOOLBAR);
211 if (FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f))
212 gtk_output_toolbar (f, BOTTOM_TOOLBAR);
213 else if (f->bottom_toolbar_was_visible)
214 gtk_clear_toolbar (f, LEFT_TOOLBAR);
216 if (FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f))
217 gtk_output_toolbar (f, LEFT_TOOLBAR);
218 else if (f->left_toolbar_was_visible)
219 gtk_clear_toolbar (f, LEFT_TOOLBAR);
221 if (FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f))
222 gtk_output_toolbar (f, RIGHT_TOOLBAR);
223 else if (f->right_toolbar_was_visible)
224 gtk_clear_toolbar (f, RIGHT_TOOLBAR);
228 gtk_initialize_frame_toolbars (struct frame *f)
230 stderr_out ("We should draw toolbars\n");
234 /************************************************************************/
236 /************************************************************************/
239 console_type_create_toolbar_gtk (void)
241 CONSOLE_HAS_METHOD (gtk, output_frame_toolbars);
242 CONSOLE_HAS_METHOD (gtk, initialize_frame_toolbars);