2 * misc. generic helper routines for Gtk+, that aren't at all specfic to
3 * this particular application. - Steve Tell
4 * May have been borrowed from elsewhere.
13 #include <guile-gnome-gobject/gobject.h>
14 #include <scwm_guile.h>
16 /* A couple of routines to make it easier to build menus.
17 * These are by Steve Tell.
20 * Create a (sub)menu and the item that activates it.
21 * Returns GtkMenu widget pointer.
24 create_menu(char *label
, GtkWidget
*parent
)
26 GtkWidget
*item
, *menu
;
29 item
= gtk_menu_item_new_with_label(label
);
31 item
= gtk_menu_item_new();
33 menu
= gtk_menu_new();
34 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), menu
);
37 if(GTK_IS_MENU_BAR(parent
))
38 gtk_menu_bar_append (GTK_MENU_BAR (parent
), item
);
39 else if(GTK_IS_MENU(parent
))
40 gtk_menu_append(GTK_MENU(parent
), item
);
42 gtk_widget_show(item
);
47 * helper function for making menu items. Returns menu item widget pointer,
48 * but it can often be ignored, since the item is already added to the parent.
51 create_menuitem(char *label
, GtkWidget
*parent
, GtkSignalFunc action
,
56 item
= gtk_menu_item_new_with_label(label
);
58 item
= gtk_menu_item_new();
61 gtk_signal_connect (GTK_OBJECT (item
), "activate", action
, p
);
63 gtk_menu_append (GTK_MENU(parent
), item
);
64 gtk_widget_show (item
);
69 /* these routines were borrowed from testgtk.c:
75 * I created shape_create_icon_d by making a trivial change to a copy
76 * of shape_create_icon, and hearby disclaim all rights to that
77 * derivative work. - sgt.
80 * Original copyright message from testgtk.c follows:
82 * GTK - The GIMP Toolkit
83 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
85 * This library is free software; you can redistribute it and/or
86 * modify it under the terms of the GNU Library General Public
87 * License as published by the Free Software Foundation; either
88 * version 2 of the License, or (at your option) any later version.
90 * This library is distributed in the hope that it will be useful,
91 * but WITHOUT ANY WARRANTY; without even the implied warranty of
92 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93 * Library General Public License for more details.
95 * You should have received a copy of the GNU Library General Public
96 * License along with this library; if not, write to the
97 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
98 * Boston, MA 02111-1307, USA.
106 static GdkWindow
*root_win
= NULL
;
108 typedef struct _cursoroffset
{gint x
,y
;} CursorOffset
;
111 shape_pressed (GtkWidget
*widget
, GdkEventButton
*event
)
115 /* ignore double and triple click */
116 if (event
->type
!= GDK_BUTTON_PRESS
)
119 p
= gtk_object_get_user_data (GTK_OBJECT(widget
));
120 p
->x
= (int) event
->x
;
121 p
->y
= (int) event
->y
;
123 gtk_grab_add (widget
);
124 gdk_pointer_grab (widget
->window
, TRUE
,
125 GDK_BUTTON_RELEASE_MASK
|
126 GDK_BUTTON_MOTION_MASK
|
127 GDK_POINTER_MOTION_HINT_MASK
,
133 shape_released (GtkWidget
*widget
)
135 gtk_grab_remove (widget
);
136 gdk_pointer_ungrab (0);
140 shape_motion (GtkWidget
*widget
,
141 GdkEventMotion
*event
)
145 GdkModifierType mask
;
147 p
= gtk_object_get_user_data (GTK_OBJECT (widget
));
150 * Can't use event->x / event->y here
151 * because I need absolute coordinates.
153 gdk_window_get_pointer (root_win
, &xp
, &yp
, &mask
);
154 gtk_widget_set_uposition (widget
, xp
- p
->x
, yp
- p
->y
);
158 shape_create_icon (char *xpm_file
,
168 CursorOffset
* icon_pos
;
170 GdkBitmap
*gdk_pixmap_mask
;
171 GdkPixmap
*gdk_pixmap
;
174 style
= gtk_widget_get_default_style ();
175 gc
= style
->black_gc
;
178 * GDK_WINDOW_TOPLEVEL works also, giving you a title border
180 window
= gtk_window_new (window_type
);
182 fixed
= gtk_fixed_new ();
183 gtk_widget_set_usize (fixed
, 100,100);
184 gtk_container_add (GTK_CONTAINER (window
), fixed
);
185 gtk_widget_show (fixed
);
187 gtk_widget_set_events (window
,
188 gtk_widget_get_events (window
) |
189 GDK_BUTTON_MOTION_MASK
|
190 GDK_POINTER_MOTION_HINT_MASK
|
191 GDK_BUTTON_PRESS_MASK
);
193 gtk_widget_realize (window
);
194 gdk_pixmap
= gdk_pixmap_create_from_xpm (window
->window
, &gdk_pixmap_mask
,
195 &style
->bg
[GTK_STATE_NORMAL
],
198 pixmap
= gtk_pixmap_new (gdk_pixmap
, gdk_pixmap_mask
);
199 gtk_fixed_put (GTK_FIXED (fixed
), pixmap
, px
,py
);
200 gtk_widget_show (pixmap
);
202 gtk_widget_shape_combine_mask (window
, gdk_pixmap_mask
, px
,py
);
205 gtk_signal_connect (GTK_OBJECT (window
), "button_press_event",
206 GTK_SIGNAL_FUNC (shape_pressed
),NULL
);
207 gtk_signal_connect (GTK_OBJECT (window
), "button_release_event",
208 GTK_SIGNAL_FUNC (shape_released
),NULL
);
209 gtk_signal_connect (GTK_OBJECT (window
), "motion_notify_event",
210 GTK_SIGNAL_FUNC (shape_motion
),NULL
);
212 icon_pos
= g_new (CursorOffset
, 1);
213 gtk_object_set_user_data(GTK_OBJECT(window
), icon_pos
);
215 gtk_widget_set_uposition (window
, x
, y
);
216 gtk_widget_show (window
);
223 shape_create_icon_d (char **xpm_data
,
233 CursorOffset
* icon_pos
;
235 GdkBitmap
*gdk_pixmap_mask
;
236 GdkPixmap
*gdk_pixmap
;
239 style
= gtk_widget_get_default_style ();
240 gc
= style
->black_gc
;
243 * GDK_WINDOW_TOPLEVEL works also, giving you a title border
245 window
= gtk_window_new (window_type
);
247 fixed
= gtk_fixed_new ();
248 gtk_widget_set_usize (fixed
, 100,100);
249 gtk_container_add (GTK_CONTAINER (window
), fixed
);
250 gtk_widget_show (fixed
);
252 gtk_widget_set_events (window
,
253 gtk_widget_get_events (window
) |
254 GDK_BUTTON_MOTION_MASK
|
255 GDK_POINTER_MOTION_HINT_MASK
|
256 GDK_BUTTON_PRESS_MASK
);
258 gtk_widget_realize (window
);
259 gdk_pixmap
= gdk_pixmap_create_from_xpm_d (window
->window
, &gdk_pixmap_mask
,
260 &style
->bg
[GTK_STATE_NORMAL
],
263 pixmap
= gtk_pixmap_new (gdk_pixmap
, gdk_pixmap_mask
);
264 gtk_fixed_put (GTK_FIXED (fixed
), pixmap
, px
,py
);
265 gtk_widget_show (pixmap
);
267 gtk_widget_shape_combine_mask (window
, gdk_pixmap_mask
, px
,py
);
270 gtk_signal_connect (GTK_OBJECT (window
), "button_press_event",
271 GTK_SIGNAL_FUNC (shape_pressed
),NULL
);
272 gtk_signal_connect (GTK_OBJECT (window
), "button_release_event",
273 GTK_SIGNAL_FUNC (shape_released
),NULL
);
274 gtk_signal_connect (GTK_OBJECT (window
), "motion_notify_event",
275 GTK_SIGNAL_FUNC (shape_motion
),NULL
);
277 icon_pos
= g_new (CursorOffset
, 1);
278 gtk_object_set_user_data(GTK_OBJECT(window
), icon_pos
);
280 gtk_widget_set_uposition (window
, x
, y
);
281 gtk_widget_show (window
);
286 SCM_DEFINE(gtk_tooltips_enabled_p
, "gtk-tooltips-enabled?", 1, 0, 0, (SCM tt
),
287 "Return #t if the GtkTooltips object TT is enabled, otherwise"
288 "return #f. See gtk-tooltips-enable in the guile-gtk documentation,"
289 "or gtk_tooltips_enable in the Gtk+ documentation for GtkTooltips.")
290 #define FUNC_NAME s_gtk_tooltips_enabled_p
296 // VALIDATE_ARG_GTK_COPY(1, tt, GTK_TYPE_TOOLTIPS, gtktt);
297 SCM_VALIDATE_GOBJECT_COPY(1, tt
, gobj
);
298 gtktt
= GTK_TOOLTIPS(gobj
);
307 #ifndef HAVE_GUILE_GTK_MENU_POPUP
309 SCM_DEFINE(gwave_gtk_menu_popup
, "gtk-menu-popup", 7, 0, 0,
310 (SCM menu
, SCM n2
, SCM n3
, SCM n4
, SCM n5
, SCM button
, SCM activate_time
),
311 "Guile wrapper for the gtk-menu-popup function, which is missing in some versions of guile-gnome-platform")
312 #define FUNC_NAME s_gwave_gtk_menu_popup
318 SCM_VALIDATE_GOBJECT_COPY(1, menu
, cmenu
);
319 if(!GTK_IS_MENU(cmenu
))
320 scm_wrong_type_arg(FUNC_NAME
,1,menu
);;
321 VALIDATE_ARG_INT_COPY(6, button
, cbutton
);
322 VALIDATE_ARG_INT_COPY(7, activate_time
, ctime
);
324 gtk_menu_popup(cmenu
, NULL
, NULL
, NULL
, NULL
, cbutton
, ctime
);
326 return SCM_UNSPECIFIED
;
329 #endif /* HAVE_GUILE_GTK_MENU_POPUP */
331 /* guile initialization */
334 #ifndef XSCM_MAGIC_SNARF_INITS