]> git.pld-linux.org Git - packages/glabels.git/blame - glabels-gnome_2_5.patch
- in order to build against the GNOME 2.5 platform, renamed gtk_combo_box
[packages/glabels.git] / glabels-gnome_2_5.patch
CommitLineData
0fb7f7f7 1diff -urN aa/glabels-1.93.1/po/POTFILES.in glabels-1.93.1/po/POTFILES.in
2--- aa/glabels-1.93.1/po/POTFILES.in 2003-12-14 07:04:59.000000000 +0100
3+++ glabels-1.93.1/po/POTFILES.in 2003-12-28 23:24:52.434158696 +0100
4@@ -149,8 +149,8 @@
5 src/mygal/e-colors.c
6 src/mygal/e-colors.h
7 src/mygal/e-util.h
8-src/mygal/gtk-combo-box.c
9-src/mygal/gtk-combo-box.h
10+src/mygal/mygal-combo-box.c
11+src/mygal/mygal-combo-box.h
12 src/mygal/widget-color-combo.c
13 src/mygal/widget-color-combo.h
14 data/paper-sizes.xml
15diff -urN aa/glabels-1.93.1/src/Makefile.am glabels-1.93.1/src/Makefile.am
16--- aa/glabels-1.93.1/src/Makefile.am 2003-12-06 03:35:56.000000000 +0100
17+++ glabels-1.93.1/src/Makefile.am 2003-12-28 23:26:16.952309984 +0100
18@@ -19,12 +19,7 @@
19 -DLIBDIR=\""$(libdir)"\" \
20 -DGLABELS_LOCALEDIR=\""$(datadir)/locale"\" \
21 -DGLABELS_UI_DIR=\""$(datadir)/glabels/ui/"\" \
22- -DGLABELS_GLADE_DIR=\""$(datadir)/glabels/glade/"\" \
23- -DG_DISABLE_DEPRECATED \
24- -DGDK_DISABLE_DEPRECATED \
25- -DGTK_DISABLE_DEPRECATED \
26- -DGDK_PIXBUF_DISABLE_DEPRECATED \
27- -DGNOME_DISABLE_DEPRECATED
28+ -DGLABELS_GLADE_DIR=\""$(datadir)/glabels/glade/"\"
29
30 glabels_LDFLAGS = -export-dynamic
31
32diff -urN aa/glabels-1.93.1/src/mygal/Makefile.am glabels-1.93.1/src/mygal/Makefile.am
33--- aa/glabels-1.93.1/src/mygal/Makefile.am 2003-07-27 06:07:19.000000000 +0200
34+++ glabels-1.93.1/src/mygal/Makefile.am 2003-12-28 23:23:37.195596696 +0100
35@@ -1,10 +1,5 @@
36 INCLUDES = \
37- $(GLABELS_CFLAGS) \
38- -DG_DISABLE_DEPRECATED \
39- -DGDK_DISABLE_DEPRECATED \
40- -DGTK_DISABLE_DEPRECATED \
41- -DGDK_PIXBUF_DISABLE_DEPRECATED \
42- -DGNOME_DISABLE_DEPRECATED
43+ $(GLABELS_CFLAGS)
44
45 noinst_LTLIBRARIES = libmygal.la
46
47@@ -14,8 +9,8 @@
48 e-util.h \
49 e-colors.c \
50 e-colors.h \
51- gtk-combo-box.c \
52- gtk-combo-box.h \
53+ mygal-combo-box.c \
54+ mygal-combo-box.h \
55 color-palette.c \
56 color-palette.h \
57 color-group.c \
58diff -urN aa/glabels-1.93.1/src/mygal/mygal-combo-box.c glabels-1.93.1/src/mygal/mygal-combo-box.c
59--- aa/glabels-1.93.1/src/mygal/mygal-combo-box.c 1970-01-01 01:00:00.000000000 +0100
60+++ glabels-1.93.1/src/mygal/mygal-combo-box.c 2003-12-28 23:21:51.273699272 +0100
61@@ -0,0 +1,838 @@
62+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
63+/*
64+ * mygal-combo-box.c - a customizable combobox
65+ * Copyright 2000, 2001, Ximian, Inc.
66+ *
67+ * Authors:
68+ * Miguel de Icaza (miguel@gnu.org)
69+ * Adrian E Feiguin (feiguin@ifir.edu.ar)
70+ * Paolo Molnaro (lupus@debian.org).
71+ * Jon K Hellan (hellan@acm.org)
72+ *
73+ * Modified for gLabels by:
74+ * Jim Evins <evins@snaught.com>
75+ *
76+ * This library is free software; you can redistribute it and/or
77+ * modify it under the terms of the GNU General Public
78+ * License, version 2, as published by the Free Software Foundation.
79+ *
80+ * This library is distributed in the hope that it will be useful, but
81+ * WITHOUT ANY WARRANTY; without even the implied warranty of
82+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
83+ * General Public License for more details.
84+ *
85+ * You should have received a copy of the GNU General Public
86+ * License along with this library; if not, write to the Free Software
87+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
88+ * 02111-1307, USA.
89+ */
90+
91+#include <config.h>
92+#include <gtk/gtkhbox.h>
93+#include <gtk/gtktogglebutton.h>
94+#include <gtk/gtkarrow.h>
95+#include <gtk/gtkeventbox.h>
96+#include <gtk/gtkmain.h>
97+#include <gtk/gtksignal.h>
98+#include <gtk/gtkwindow.h>
99+#include <gtk/gtkframe.h>
100+#include <gtk/gtkvbox.h>
101+#include <gtk/gtktearoffmenuitem.h>
102+#include <gdk/gdkkeysyms.h>
103+#include "mygal-combo-box.h"
104+#include "e-util.h"
105+
106+#define PARENT_TYPE GTK_TYPE_HBOX
107+static GObjectClass *mygal_combo_box_parent_class;
108+
109+static int gtk_combo_toggle_pressed (GtkToggleButton *tbutton,
110+ MygalComboBox *combo_box);
111+static void gtk_combo_popup_tear_off (MygalComboBox *combo,
112+ gboolean set_position);
113+static void gtk_combo_set_tearoff_state (MygalComboBox *combo,
114+ gboolean torn_off);
115+static void gtk_combo_popup_reparent (GtkWidget *popup, GtkWidget *new_parent,
116+ gboolean unrealize);
117+static gboolean cb_popup_delete (GtkWidget *w, GdkEventAny *event,
118+ MygalComboBox *combo);
119+static void gtk_combo_tearoff_bg_copy (MygalComboBox *combo);
120+
121+enum {
122+ POP_DOWN_WIDGET,
123+ POP_DOWN_DONE,
124+ PRE_POP_DOWN,
125+ POST_POP_HIDE,
126+ LAST_SIGNAL
127+};
128+
129+static guint mygal_combo_box_signals [LAST_SIGNAL] = { 0, };
130+
131+struct _MygalComboBoxPrivate {
132+ GtkWidget *pop_down_widget;
133+ GtkWidget *display_widget;
134+
135+ /*
136+ * Internal widgets used to implement the ComboBox
137+ */
138+ GtkWidget *frame;
139+ GtkWidget *arrow_button;
140+
141+ GtkWidget *toplevel; /* Popup's toplevel when not torn off */
142+ GtkWidget *tearoff_window; /* Popup's toplevel when torn off */
143+ guint torn_off;
144+
145+ GtkWidget *tearable; /* The tearoff "button" */
146+ GtkWidget *popup; /* Popup */
147+
148+ /*
149+ * Closure for invoking the callbacks above
150+ */
151+ void *closure;
152+};
153+
154+static void
155+mygal_combo_box_finalize (GObject *object)
156+{
157+ MygalComboBox *combo_box = MYGAL_COMBO_BOX (object);
158+
159+ g_free (combo_box->priv);
160+
161+ mygal_combo_box_parent_class->finalize (object);
162+}
163+
164+static void
165+mygal_combo_box_destroy (GtkObject *object)
166+{
167+ GtkObjectClass *klass = (GtkObjectClass *)mygal_combo_box_parent_class;
168+ MygalComboBox *combo_box = MYGAL_COMBO_BOX (object);
169+
170+ if (combo_box->priv->toplevel) {
171+ gtk_object_destroy (GTK_OBJECT (combo_box->priv->toplevel));
172+ combo_box->priv->toplevel = NULL;
173+ }
174+
175+ if (combo_box->priv->tearoff_window) {
176+ gtk_object_destroy (GTK_OBJECT (combo_box->priv->tearoff_window));
177+ combo_box->priv->tearoff_window = NULL;
178+ }
179+
180+ if (klass->destroy)
181+ klass->destroy (object);
182+}
183+
184+static gboolean
185+mygal_combo_box_mnemonic_activate (GtkWidget *w, gboolean group_cycling)
186+{
187+ MygalComboBox *combo_box = MYGAL_COMBO_BOX (w);
188+ gtk_toggle_button_set_active (
189+ GTK_TOGGLE_BUTTON (combo_box->priv->arrow_button), TRUE);
190+ return TRUE;
191+}
192+
193+static void
194+mygal_combo_box_class_init (GObjectClass *object_class)
195+{
196+ GtkWidgetClass *widget_class = (GtkWidgetClass *)object_class;
197+ mygal_combo_box_parent_class = g_type_class_peek_parent (object_class);
198+
199+ object_class->finalize = mygal_combo_box_finalize;
200+ widget_class->mnemonic_activate = mygal_combo_box_mnemonic_activate;
201+ ((GtkObjectClass *)object_class)->destroy = mygal_combo_box_destroy;
202+
203+ mygal_combo_box_signals [POP_DOWN_WIDGET] = g_signal_new (
204+ "pop_down_widget",
205+ G_OBJECT_CLASS_TYPE (object_class),
206+ G_SIGNAL_RUN_LAST,
207+ G_STRUCT_OFFSET (MygalComboBoxClass, pop_down_widget),
208+ NULL, NULL,
209+ e_marshal_POINTER__NONE,
210+ G_TYPE_POINTER, 0, G_TYPE_NONE);
211+
212+ mygal_combo_box_signals [POP_DOWN_DONE] = g_signal_new (
213+ "pop_down_done",
214+ G_OBJECT_CLASS_TYPE (object_class),
215+ G_SIGNAL_RUN_LAST,
216+ G_STRUCT_OFFSET (MygalComboBoxClass, pop_down_done),
217+ NULL, NULL,
218+ e_marshal_BOOLEAN__OBJECT,
219+ G_TYPE_BOOLEAN, 1, G_TYPE_OBJECT);
220+
221+ mygal_combo_box_signals [PRE_POP_DOWN] = g_signal_new (
222+ "pre_pop_down",
223+ G_OBJECT_CLASS_TYPE (object_class),
224+ G_SIGNAL_RUN_LAST,
225+ G_STRUCT_OFFSET (MygalComboBoxClass, pre_pop_down),
226+ NULL, NULL,
227+ e_marshal_NONE__NONE,
228+ G_TYPE_NONE, 0);
229+
230+ mygal_combo_box_signals [POST_POP_HIDE] = g_signal_new (
231+ "post_pop_hide",
232+ G_OBJECT_CLASS_TYPE (object_class),
233+ G_SIGNAL_RUN_LAST,
234+ G_STRUCT_OFFSET (MygalComboBoxClass, post_pop_hide),
235+ NULL, NULL,
236+ e_marshal_NONE__NONE,
237+ G_TYPE_NONE, 0);
238+}
239+
240+static void
241+deactivate_arrow (MygalComboBox *combo_box)
242+{
243+ GtkToggleButton *arrow;
244+
245+ arrow = GTK_TOGGLE_BUTTON (combo_box->priv->arrow_button);
246+ g_signal_handlers_block_matched (arrow,
247+ G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
248+ 0, 0, NULL,
249+ gtk_combo_toggle_pressed, combo_box);
250+
251+ gtk_toggle_button_set_active (arrow, FALSE);
252+
253+ g_signal_handlers_unblock_matched (arrow,
254+ G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
255+ 0, 0, NULL,
256+ gtk_combo_toggle_pressed, combo_box);
257+}
258+
259+/**
260+ * mygal_combo_box_popup_hide_unconditional
261+ * @combo_box: Combo box
262+ *
263+ * Hide popup, whether or not it is torn off.
264+ */
265+static void
266+mygal_combo_box_popup_hide_unconditional (MygalComboBox *combo_box)
267+{
268+ gboolean popup_info_destroyed = FALSE;
269+
270+ g_return_if_fail (combo_box != NULL);
271+ g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
272+
273+ gtk_widget_hide (combo_box->priv->toplevel);
274+ gtk_widget_hide (combo_box->priv->popup);
275+ if (combo_box->priv->torn_off) {
276+ GTK_TEAROFF_MENU_ITEM (combo_box->priv->tearable)->torn_off
277+ = FALSE;
278+ gtk_combo_set_tearoff_state (combo_box, FALSE);
279+ }
280+
281+ gtk_grab_remove (combo_box->priv->toplevel);
282+ gdk_pointer_ungrab (GDK_CURRENT_TIME);
283+
284+ g_object_ref (combo_box->priv->pop_down_widget);
285+ g_signal_emit (combo_box,
286+ mygal_combo_box_signals [POP_DOWN_DONE], 0,
287+ combo_box->priv->pop_down_widget, &popup_info_destroyed);
288+
289+ if (popup_info_destroyed){
290+ gtk_container_remove (
291+ GTK_CONTAINER (combo_box->priv->frame),
292+ combo_box->priv->pop_down_widget);
293+ combo_box->priv->pop_down_widget = NULL;
294+ }
295+ g_object_unref (combo_box->priv->pop_down_widget);
296+ deactivate_arrow (combo_box);
297+
298+ g_signal_emit (combo_box, mygal_combo_box_signals [POST_POP_HIDE], 0);
299+}
300+
301+/**
302+ * mygal_combo_box_popup_hide:
303+ * @combo_box: Combo box
304+ *
305+ * Hide popup, but not when it is torn off.
306+ * This is the external interface - for subclasses and apps which expect a
307+ * regular combo which doesn't do tearoffs.
308+ */
309+void
310+mygal_combo_box_popup_hide (MygalComboBox *combo_box)
311+{
312+ if (!combo_box->priv->torn_off)
313+ mygal_combo_box_popup_hide_unconditional (combo_box);
314+ else if (GTK_WIDGET_VISIBLE (combo_box->priv->toplevel)) {
315+ /* Both popup and tearoff window present. Get rid of just
316+ the popup shell. */
317+ gtk_combo_popup_tear_off (combo_box, FALSE);
318+ deactivate_arrow (combo_box);
319+ }
320+}
321+
322+/*
323+ * Find best location for displaying
324+ */
325+void
326+mygal_combo_box_get_pos (MygalComboBox *combo_box, int *x, int *y)
327+{
328+ GtkWidget *wcombo = GTK_WIDGET (combo_box);
329+ int ph, pw;
330+
331+ gdk_window_get_origin (wcombo->window, x, y);
332+ *y += wcombo->allocation.height + wcombo->allocation.y;
333+ *x += wcombo->allocation.x;
334+
335+ ph = combo_box->priv->popup->allocation.height;
336+ pw = combo_box->priv->popup->allocation.width;
337+
338+ if ((*y + ph) > gdk_screen_height ())
339+ *y = gdk_screen_height () - ph;
340+
341+ if ((*x + pw) > gdk_screen_width ())
342+ *x = gdk_screen_width () - pw;
343+}
344+
345+static void
346+mygal_combo_box_popup_display (MygalComboBox *combo_box)
347+{
348+ int x, y;
349+
350+ g_return_if_fail (combo_box != NULL);
351+ g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
352+
353+ /*
354+ * If we have no widget to display on the popdown,
355+ * create it
356+ */
357+ if (!combo_box->priv->pop_down_widget){
358+ GtkWidget *pw = NULL;
359+
360+ g_signal_emit (combo_box,
361+ mygal_combo_box_signals [POP_DOWN_WIDGET], 0, &pw);
362+ g_assert (pw != NULL);
363+ combo_box->priv->pop_down_widget = pw;
364+ gtk_container_add (GTK_CONTAINER (combo_box->priv->frame), pw);
365+ }
366+
367+ g_signal_emit (combo_box, mygal_combo_box_signals [PRE_POP_DOWN], 0);
368+
369+ if (combo_box->priv->torn_off) {
370+ /* To give the illusion that tearoff still displays the
371+ * popup, we copy the image in the popup window to the
372+ * background. Thus, it won't be blank after reparenting */
373+ gtk_combo_tearoff_bg_copy (combo_box);
374+
375+ /* We force an unrealize here so that we don't trigger
376+ * redrawing/ clearing code - we just want to reveal our
377+ * backing pixmap.
378+ */
379+ gtk_combo_popup_reparent (combo_box->priv->popup,
380+ combo_box->priv->toplevel, TRUE);
381+ }
382+
383+ mygal_combo_box_get_pos (combo_box, &x, &y);
384+
385+ gtk_widget_set_uposition (combo_box->priv->toplevel, x, y);
386+ gtk_widget_realize (combo_box->priv->popup);
387+ gtk_widget_show (combo_box->priv->popup);
388+ gtk_widget_realize (combo_box->priv->toplevel);
389+ gtk_widget_show (combo_box->priv->toplevel);
390+
391+ gtk_grab_add (combo_box->priv->toplevel);
392+ gdk_pointer_grab (combo_box->priv->toplevel->window, TRUE,
393+ GDK_BUTTON_PRESS_MASK |
394+ GDK_BUTTON_RELEASE_MASK |
395+ GDK_POINTER_MOTION_MASK,
396+ NULL, NULL, GDK_CURRENT_TIME);
397+}
398+
399+static int
400+gtk_combo_toggle_pressed (GtkToggleButton *tbutton, MygalComboBox *combo_box)
401+{
402+ if (tbutton->active)
403+ mygal_combo_box_popup_display (combo_box);
404+ else
405+ mygal_combo_box_popup_hide_unconditional (combo_box);
406+
407+ return TRUE;
408+}
409+
410+static gint
411+mygal_combo_box_button_press (GtkWidget *widget, GdkEventButton *event, MygalComboBox *combo_box)
412+{
413+ GtkWidget *child;
414+
415+ child = gtk_get_event_widget ((GdkEvent *) event);
416+ if (child != widget){
417+ while (child){
418+ if (child == widget)
419+ return FALSE;
420+ child = child->parent;
421+ }
422+ }
423+
424+ mygal_combo_box_popup_hide (combo_box);
425+ return TRUE;
426+}
427+
428+/**
429+ * mygal_combo_box_key_press
430+ * @widget: Widget
431+ * @event: Event
432+ * @combo_box: Combo box
433+ *
434+ * Key press handler which dismisses popup on escape.
435+ * Popup is dismissed whether or not popup is torn off.
436+ */
437+static gint
438+mygal_combo_box_key_press (GtkWidget *widget, GdkEventKey *event,
439+ MygalComboBox *combo_box)
440+{
441+ if (event->keyval == GDK_Escape) {
442+ mygal_combo_box_popup_hide_unconditional (combo_box);
443+ return TRUE;
444+ } else
445+ return FALSE;
446+}
447+
448+static void
449+cb_state_change (GtkWidget *widget, GtkStateType old_state, MygalComboBox *combo_box)
450+{
451+ GtkStateType const new_state = GTK_WIDGET_STATE(widget);
452+ gtk_widget_set_state (combo_box->priv->display_widget, new_state);
453+}
454+
455+static void
456+mygal_combo_box_init (MygalComboBox *combo_box)
457+{
458+ GtkWidget *arrow;
459+ GdkCursor *cursor;
460+
461+ combo_box->priv = g_new0 (MygalComboBoxPrivate, 1);
462+
463+ /*
464+ * Create the arrow
465+ */
466+ combo_box->priv->arrow_button = gtk_toggle_button_new ();
467+ gtk_button_set_relief (GTK_BUTTON (combo_box->priv->arrow_button), GTK_RELIEF_NONE);
468+ GTK_WIDGET_UNSET_FLAGS (combo_box->priv->arrow_button, GTK_CAN_FOCUS);
469+
470+ arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
471+ gtk_container_add (GTK_CONTAINER (combo_box->priv->arrow_button), arrow);
472+ gtk_box_pack_end (GTK_BOX (combo_box), combo_box->priv->arrow_button, FALSE, FALSE, 0);
473+ g_signal_connect (combo_box->priv->arrow_button, "toggled",
474+ G_CALLBACK (gtk_combo_toggle_pressed), combo_box);
475+ gtk_widget_show_all (combo_box->priv->arrow_button);
476+
477+ /*
478+ * prelight the display widget when mousing over the arrow.
479+ */
480+ g_signal_connect (combo_box->priv->arrow_button, "state-changed",
481+ G_CALLBACK (cb_state_change), combo_box);
482+
483+ /*
484+ * The pop-down container
485+ */
486+
487+ combo_box->priv->toplevel = gtk_window_new (GTK_WINDOW_POPUP);
488+ gtk_widget_ref (combo_box->priv->toplevel);
489+ gtk_object_sink (GTK_OBJECT (combo_box->priv->toplevel));
490+ gtk_window_set_policy (GTK_WINDOW (combo_box->priv->toplevel),
491+ FALSE, TRUE, FALSE);
492+
493+ combo_box->priv->popup = gtk_event_box_new ();
494+ gtk_container_add (GTK_CONTAINER (combo_box->priv->toplevel),
495+ combo_box->priv->popup);
496+ gtk_widget_show (combo_box->priv->popup);
497+
498+ gtk_widget_realize (combo_box->priv->popup);
499+ cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
500+ gdk_window_set_cursor (combo_box->priv->popup->window, cursor);
501+ gdk_cursor_unref (cursor);
502+
503+ combo_box->priv->torn_off = FALSE;
504+ combo_box->priv->tearoff_window = NULL;
505+
506+ combo_box->priv->frame = gtk_frame_new (NULL);
507+ gtk_container_add (GTK_CONTAINER (combo_box->priv->popup),
508+ combo_box->priv->frame);
509+ gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->frame), GTK_SHADOW_OUT);
510+
511+ g_signal_connect (combo_box->priv->toplevel, "button_press_event",
512+ G_CALLBACK (mygal_combo_box_button_press), combo_box);
513+ g_signal_connect (combo_box->priv->toplevel, "key_press_event",
514+ G_CALLBACK (mygal_combo_box_key_press), combo_box);
515+}
516+
517+E_MAKE_TYPE (mygal_combo_box,
518+ "MygalComboBox",
519+ MygalComboBox,
520+ mygal_combo_box_class_init,
521+ mygal_combo_box_init,
522+ PARENT_TYPE)
523+
524+/**
525+ * mygal_combo_box_set_display:
526+ * @combo_box: the Combo Box to modify
527+ * @display_widget: The widget to be displayed
528+
529+ * Sets the displayed widget for the @combo_box to be @display_widget
530+ */
531+void
532+mygal_combo_box_set_display (MygalComboBox *combo_box, GtkWidget *display_widget)
533+{
534+ g_return_if_fail (combo_box != NULL);
535+ g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
536+ g_return_if_fail (display_widget != NULL);
537+ g_return_if_fail (GTK_IS_WIDGET (display_widget));
538+
539+ if (combo_box->priv->display_widget &&
540+ combo_box->priv->display_widget != display_widget)
541+ gtk_container_remove (GTK_CONTAINER (combo_box),
542+ combo_box->priv->display_widget);
543+
544+ combo_box->priv->display_widget = display_widget;
545+
546+ gtk_box_pack_start (GTK_BOX (combo_box), display_widget, TRUE, TRUE, 0);
547+}
548+
549+static gboolean
550+cb_tearable_enter_leave (GtkWidget *w, GdkEventCrossing *event, gpointer data)
551+{
552+ gboolean const flag = GPOINTER_TO_INT(data);
553+ gtk_widget_set_state (w, flag ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL);
554+ return FALSE;
555+}
556+
557+/**
558+ * gtk_combo_popup_tear_off
559+ * @combo: Combo box
560+ * @set_position: Set to position of popup shell if true
561+ *
562+ * Tear off the popup
563+ *
564+ * FIXME:
565+ * Gtk popup menus are toplevel windows, not dialogs. I think this is wrong,
566+ * and make the popups dialogs. But may be there should be a way to make
567+ * them toplevel. We can do this after creating:
568+ * GTK_WINDOW (tearoff)->type = GTK_WINDOW_TOPLEVEL;
569+ */
570+static void
571+gtk_combo_popup_tear_off (MygalComboBox *combo, gboolean set_position)
572+{
573+ int x, y;
574+
575+ if (!combo->priv->tearoff_window) {
576+ GtkWidget *tearoff;
577+ gchar *title;
578+
579+ /* FIXME: made this a toplevel, not a dialog ! */
580+ tearoff = gtk_window_new (GTK_WINDOW_TOPLEVEL);
581+ gtk_widget_ref (tearoff);
582+ gtk_object_sink (GTK_OBJECT (tearoff));
583+ combo->priv->tearoff_window = tearoff;
584+ gtk_widget_set_app_paintable (tearoff, TRUE);
585+ g_signal_connect (tearoff, "key_press_event",
586+ G_CALLBACK (mygal_combo_box_key_press),
587+ combo);
588+ gtk_widget_realize (tearoff);
589+ title = g_object_get_data (G_OBJECT (combo),
590+ "gtk-combo-title");
591+ if (title)
592+ gdk_window_set_title (tearoff->window, title);
593+ gtk_window_set_policy (GTK_WINDOW (tearoff),
594+ FALSE, TRUE, FALSE);
595+ gtk_window_set_transient_for
596+ (GTK_WINDOW (tearoff),
597+ GTK_WINDOW (gtk_widget_get_toplevel
598+ GTK_WIDGET (combo)));
599+ }
600+
601+ if (GTK_WIDGET_VISIBLE (combo->priv->popup)) {
602+ gtk_widget_hide (combo->priv->toplevel);
603+
604+ gtk_grab_remove (combo->priv->toplevel);
605+ gdk_pointer_ungrab (GDK_CURRENT_TIME);
606+ }
607+
608+ gtk_combo_popup_reparent (combo->priv->popup,
609+ combo->priv->tearoff_window, FALSE);
610+
611+ /* It may have got confused about size */
612+ gtk_widget_queue_resize (GTK_WIDGET (combo->priv->popup));
613+
614+ if (set_position) {
615+ mygal_combo_box_get_pos (combo, &x, &y);
616+ gtk_widget_set_uposition (combo->priv->tearoff_window, x, y);
617+ }
618+ gtk_widget_show (GTK_WIDGET (combo->priv->popup));
619+ gtk_widget_show (combo->priv->tearoff_window);
620+
621+}
622+
623+/**
624+ * gtk_combo_set_tearoff_state
625+ * @combo_box: Combo box
626+ * @torn_off: TRUE: Tear off. FALSE: Pop down and reattach
627+ *
628+ * Set the tearoff state of the popup
629+ *
630+ * Compare with gtk_menu_set_tearoff_state in gtk/gtkmenu.c
631+ */
632+static void
633+gtk_combo_set_tearoff_state (MygalComboBox *combo,
634+ gboolean torn_off)
635+{
636+ g_return_if_fail (combo != NULL);
637+ g_return_if_fail (GTK_IS_COMBO_BOX (combo));
638+
639+ if (combo->priv->torn_off != torn_off) {
640+ combo->priv->torn_off = torn_off;
641+
642+ if (combo->priv->torn_off) {
643+ gtk_combo_popup_tear_off (combo, TRUE);
644+ deactivate_arrow (combo);
645+ } else {
646+ gtk_widget_hide (combo->priv->tearoff_window);
647+ gtk_combo_popup_reparent (combo->priv->popup,
648+ combo->priv->toplevel,
649+ FALSE);
650+ }
651+ }
652+}
653+
654+/**
655+ * gtk_combo_tearoff_bg_copy
656+ * @combo_box: Combo box
657+ *
658+ * Copy popup window image to the tearoff window.
659+ */
660+static void
661+gtk_combo_tearoff_bg_copy (MygalComboBox *combo)
662+{
663+ GdkPixmap *pixmap;
664+ GdkGC *gc;
665+ GdkGCValues gc_values;
666+
667+ GtkWidget *widget = combo->priv->popup;
668+
669+ if (combo->priv->torn_off) {
670+ gc_values.subwindow_mode = GDK_INCLUDE_INFERIORS;
671+ gc = gdk_gc_new_with_values (widget->window,
672+ &gc_values, GDK_GC_SUBWINDOW);
673+
674+ pixmap = gdk_pixmap_new (widget->window,
675+ widget->allocation.width,
676+ widget->allocation.height,
677+ -1);
678+
679+ gdk_draw_drawable (pixmap, gc,
680+ widget->window,
681+ 0, 0, 0, 0, -1, -1);
682+ gdk_gc_unref (gc);
683+
684+ gtk_widget_set_usize (combo->priv->tearoff_window,
685+ widget->allocation.width,
686+ widget->allocation.height);
687+
688+ gdk_window_set_back_pixmap
689+ (combo->priv->tearoff_window->window, pixmap, FALSE);
690+ gdk_drawable_unref (pixmap);
691+ }
692+}
693+
694+/**
695+ * gtk_combo_popup_reparent
696+ * @popup: Popup
697+ * @new_parent: New parent
698+ * @unrealize: Unrealize popup if TRUE.
699+ *
700+ * Reparent the popup, taking care of the refcounting
701+ *
702+ * Compare with gtk_menu_reparent in gtk/gtkmenu.c
703+ */
704+static void
705+gtk_combo_popup_reparent (GtkWidget *popup,
706+ GtkWidget *new_parent,
707+ gboolean unrealize)
708+{
709+ GtkObject *object = GTK_OBJECT (popup);
710+ gboolean was_floating = GTK_OBJECT_FLOATING (object);
711+
712+ g_object_ref (object);
713+ gtk_object_sink (object);
714+
715+ if (unrealize) {
716+ g_object_ref (object);
717+ gtk_container_remove (GTK_CONTAINER (popup->parent), popup);
718+ gtk_container_add (GTK_CONTAINER (new_parent), popup);
719+ g_object_unref (object);
720+ }
721+ else
722+ gtk_widget_reparent (GTK_WIDGET (popup), new_parent);
723+ gtk_widget_set_usize (new_parent, -1, -1);
724+
725+ if (was_floating)
726+ GTK_OBJECT_SET_FLAGS (object, GTK_FLOATING);
727+ else
728+ g_object_unref (object);
729+}
730+
731+/**
732+ * cb_tearable_button_release
733+ * @w: Widget
734+ * @event: Event
735+ * @combo: Combo box
736+ *
737+ * Toggle tearoff state.
738+ */
739+static gboolean
740+cb_tearable_button_release (GtkWidget *w, GdkEventButton *event,
741+ MygalComboBox *combo)
742+{
743+ GtkTearoffMenuItem *tearable;
744+
745+ g_return_val_if_fail (w != NULL, FALSE);
746+ g_return_val_if_fail (GTK_IS_TEAROFF_MENU_ITEM (w), FALSE);
747+
748+ tearable = GTK_TEAROFF_MENU_ITEM (w);
749+ tearable->torn_off = !tearable->torn_off;
750+
751+ if (!combo->priv->torn_off) {
752+ gboolean need_connect;
753+
754+ need_connect = (!combo->priv->tearoff_window);
755+ gtk_combo_set_tearoff_state (combo, TRUE);
756+ if (need_connect)
757+ g_signal_connect (combo->priv->tearoff_window,
758+ "delete_event",
759+ G_CALLBACK (cb_popup_delete),
760+ combo);
761+ } else
762+ mygal_combo_box_popup_hide_unconditional (combo);
763+
764+ return TRUE;
765+}
766+
767+static gboolean
768+cb_popup_delete (GtkWidget *w, GdkEventAny *event, MygalComboBox *combo)
769+{
770+ mygal_combo_box_popup_hide_unconditional (combo);
771+ return TRUE;
772+}
773+
774+void
775+mygal_combo_box_construct (MygalComboBox *combo_box, GtkWidget *display_widget, GtkWidget *pop_down_widget)
776+{
777+ GtkWidget *tearable;
778+ GtkWidget *vbox;
779+
780+ g_return_if_fail (combo_box != NULL);
781+ g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
782+ g_return_if_fail (display_widget != NULL);
783+ g_return_if_fail (GTK_IS_WIDGET (display_widget));
784+
785+ GTK_BOX (combo_box)->spacing = 0;
786+ GTK_BOX (combo_box)->homogeneous = FALSE;
787+
788+ combo_box->priv->pop_down_widget = pop_down_widget;
789+ combo_box->priv->display_widget = NULL;
790+
791+ vbox = gtk_vbox_new (FALSE, 5);
792+ tearable = gtk_tearoff_menu_item_new ();
793+ g_signal_connect (tearable, "enter-notify-event",
794+ G_CALLBACK (cb_tearable_enter_leave),
795+ GINT_TO_POINTER (TRUE));
796+ g_signal_connect (tearable, "leave-notify-event",
797+ G_CALLBACK (cb_tearable_enter_leave),
798+ GINT_TO_POINTER (FALSE));
799+ g_signal_connect (tearable, "button-release-event",
800+ G_CALLBACK (cb_tearable_button_release),
801+ (gpointer) combo_box);
802+ gtk_box_pack_start (GTK_BOX (vbox), tearable, FALSE, FALSE, 0);
803+ gtk_box_pack_start (GTK_BOX (vbox), pop_down_widget, TRUE, TRUE, 0);
804+ combo_box->priv->tearable = tearable;
805+
806+ /*
807+ * Finish setup
808+ */
809+ mygal_combo_box_set_display (combo_box, display_widget);
810+
811+ gtk_container_add (GTK_CONTAINER (combo_box->priv->frame), vbox);
812+ gtk_widget_show_all (combo_box->priv->frame);
813+}
814+
815+GtkWidget *
816+mygal_combo_box_new (GtkWidget *display_widget, GtkWidget *optional_popdown)
817+{
818+ MygalComboBox *combo_box;
819+
820+ g_return_val_if_fail (display_widget != NULL, NULL);
821+ g_return_val_if_fail (GTK_IS_WIDGET (display_widget), NULL);
822+
823+ combo_box = g_object_new (MYGAL_COMBO_BOX_TYPE, NULL);
824+ mygal_combo_box_construct (combo_box, display_widget, optional_popdown);
825+ return GTK_WIDGET (combo_box);
826+}
827+
828+void
829+mygal_combo_box_set_arrow_relief (MygalComboBox *cc, GtkReliefStyle relief)
830+{
831+ g_return_if_fail (cc != NULL);
832+ g_return_if_fail (GTK_IS_COMBO_BOX (cc));
833+
834+ gtk_button_set_relief (GTK_BUTTON (cc->priv->arrow_button), relief);
835+}
836+
837+/**
838+ * mygal_combo_box_set_title
839+ * @combo: Combo box
840+ * @title: Title
841+ *
842+ * Set a title to display over the tearoff window.
843+ *
844+ * FIXME:
845+ *
846+ * This should really change the title even when the popup is already torn off.
847+ * I guess the tearoff window could attach a listener to title change or
848+ * something. But I don't think we need the functionality, so I didn't bother
849+ * to investigate.
850+ */
851+void
852+mygal_combo_box_set_title (MygalComboBox *combo,
853+ const gchar *title)
854+{
855+ g_return_if_fail (combo != NULL);
856+ g_return_if_fail (GTK_IS_COMBO_BOX (combo));
857+
858+ g_object_set_data_full (G_OBJECT (combo), "gtk-combo-title",
859+ g_strdup (title), (GDestroyNotify) g_free);
860+}
861+
862+/**
863+ * mygal_combo_box_set_arrow_sensitive
864+ * @combo: Combo box
865+ * @sensitive: Sensitivity value
866+ *
867+ * Toggle the sensitivity of the arrow button
868+ */
869+
870+void
871+mygal_combo_box_set_arrow_sensitive (MygalComboBox *combo,
872+ gboolean sensitive)
873+{
874+ g_return_if_fail (combo != NULL);
875+
876+ gtk_widget_set_sensitive (combo->priv->arrow_button, sensitive);
877+}
878+
879+/**
880+ * mygal_combo_box_set_tearable:
881+ * @combo: Combo box
882+ * @tearable: whether to allow the @combo to be tearable
883+ *
884+ * controls whether the combo box's pop up widget can be torn off.
885+ */
886+void
887+mygal_combo_box_set_tearable (MygalComboBox *combo, gboolean tearable)
888+{
889+ g_return_if_fail (combo != NULL);
890+ g_return_if_fail (GTK_IS_COMBO_BOX (combo));
891+
892+ if (tearable){
893+ gtk_widget_show (combo->priv->tearable);
894+ } else {
895+ gtk_combo_set_tearoff_state (combo, FALSE);
896+ gtk_widget_hide (combo->priv->tearable);
897+ }
898+}
899+
900diff -urN aa/glabels-1.93.1/src/mygal/mygal-combo-box.h glabels-1.93.1/src/mygal/mygal-combo-box.h
901--- aa/glabels-1.93.1/src/mygal/mygal-combo-box.h 1970-01-01 01:00:00.000000000 +0100
902+++ glabels-1.93.1/src/mygal/mygal-combo-box.h 2003-12-28 23:22:19.782365296 +0100
903@@ -0,0 +1,95 @@
904+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
905+/*
906+ * mygal-combo-box.h - a customizable combobox
907+ * Copyright 2000, 2001, Ximian, Inc.
908+ *
909+ * Authors:
910+ * Miguel de Icaza <miguel@ximian.com>
911+ *
912+ * Modified for gLabels by:
913+ * Jim Evins <evins@snaught.com>
914+ *
915+ * This library is free software; you can redistribute it and/or
916+ * modify it under the terms of the GNU General Public
917+ * License, version 2, as published by the Free Software Foundation.
918+ *
919+ * This library is distributed in the hope that it will be useful, but
920+ * WITHOUT ANY WARRANTY; without even the implied warranty of
921+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
922+ * General Public License for more details.
923+ *
924+ * You should have received a copy of the GNU General Public
925+ * License along with this library; if not, write to the Free Software
926+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
927+ * 02111-1307, USA.
928+ */
929+
930+#ifndef _MYGAL_COMBO_BOX_H_
931+#define _MYGAL_COMBO_BOX_H_
932+
933+#include <gtk/gtkhbox.h>
934+
935+#ifdef __cplusplus
936+extern "C" {
937+#endif /* __cplusplus */
938+
939+#define MYGAL_COMBO_BOX_TYPE (mygal_combo_box_get_type())
940+#define MYGAL_COMBO_BOX(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, mygal_combo_box_get_type (), MygalComboBox)
941+#define MYGAL_COMBO_BOX_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, mygal_combo_box_get_type (), MygalComboBoxClass)
942+#define GTK_IS_COMBO_BOX(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, mygal_combo_box_get_type ())
943+
944+typedef struct _MygalComboBox MygalComboBox;
945+typedef struct _MygalComboBoxPrivate MygalComboBoxPrivate;
946+typedef struct _MygalComboBoxClass MygalComboBoxClass;
947+
948+struct _MygalComboBox {
949+ GtkHBox hbox;
950+ MygalComboBoxPrivate *priv;
951+};
952+
953+struct _MygalComboBoxClass {
954+ GtkHBoxClass parent_class;
955+
956+ GtkWidget *(*pop_down_widget) (MygalComboBox *cbox);
957+
958+ /*
959+ * invoked when the popup has been hidden, if the signal
960+ * returns TRUE, it means it should be killed from the
961+ */
962+ gboolean *(*pop_down_done) (MygalComboBox *cbox, GtkWidget *);
963+
964+ /*
965+ * Notification signals.
966+ */
967+ void (*pre_pop_down) (MygalComboBox *cbox);
968+ void (*post_pop_hide) (MygalComboBox *cbox);
969+};
970+
971+GtkType mygal_combo_box_get_type (void);
972+void mygal_combo_box_construct (MygalComboBox *combo_box,
973+ GtkWidget *display_widget,
974+ GtkWidget *optional_pop_down_widget);
975+void mygal_combo_box_get_pos (MygalComboBox *combo_box, int *x, int *y);
976+
977+GtkWidget *mygal_combo_box_new (GtkWidget *display_widget,
978+ GtkWidget *optional_pop_down_widget);
979+void mygal_combo_box_popup_hide (MygalComboBox *combo_box);
980+
981+void mygal_combo_box_set_display (MygalComboBox *combo_box,
982+ GtkWidget *display_widget);
983+
984+void mygal_combo_box_set_title (MygalComboBox *combo,
985+ const gchar *title);
986+
987+void mygal_combo_box_set_tearable (MygalComboBox *combo,
988+ gboolean tearable);
989+void mygal_combo_box_set_arrow_sensitive (MygalComboBox *combo,
990+ gboolean sensitive);
991+void mygal_combo_box_set_arrow_relief (MygalComboBox *cc,
992+ GtkReliefStyle relief);
993+#ifdef __cplusplus
994+};
995+#endif /* __cplusplus */
996+
997+#endif /* _MYGAL_COMBO_BOX_H_ */
998+
999diff -urN aa/glabels-1.93.1/src/mygal/widget-color-combo.c glabels-1.93.1/src/mygal/widget-color-combo.c
1000--- aa/glabels-1.93.1/src/mygal/widget-color-combo.c 2003-12-16 02:08:49.000000000 +0100
1001+++ glabels-1.93.1/src/mygal/widget-color-combo.c 2003-12-28 23:33:12.067202928 +0100
1002@@ -47,7 +47,7 @@
1003
1004 static guint color_combo_signals [LAST_SIGNAL] = { 0, };
1005
1006-#define PARENT_TYPE GTK_COMBO_BOX_TYPE
1007+#define PARENT_TYPE MYGAL_COMBO_BOX_TYPE
1008 static GObjectClass *color_combo_parent_class;
1009
1010 #define make_color(CC,COL) (((COL) != NULL) ? (COL) : ((CC) ? ((CC)->default_color) : NULL))
1011@@ -140,7 +140,7 @@
1012 g_signal_emit (cc,
1013 color_combo_signals [CHANGED], 0,
1014 color, is_custom, by_user, is_default);
1015- gtk_combo_box_popup_hide (GTK_COMBO_BOX (cc));
1016+ mygal_combo_box_popup_hide (MYGAL_COMBO_BOX (cc));
1017 }
1018
1019 static void
1020@@ -165,7 +165,7 @@
1021 static void
1022 cb_cust_color_clicked (GtkWidget *widget, ColorCombo *cc)
1023 {
1024- gtk_combo_box_popup_hide (GTK_COMBO_BOX (cc));
1025+ mygal_combo_box_popup_hide (MYGAL_COMBO_BOX (cc));
1026 }
1027
1028 /*
1029@@ -255,11 +255,11 @@
1030
1031 gtk_widget_show_all (cc->preview_button);
1032
1033- gtk_combo_box_construct (GTK_COMBO_BOX (cc),
1034+ mygal_combo_box_construct (MYGAL_COMBO_BOX (cc),
1035 cc->preview_button,
1036 GTK_WIDGET (cc->palette));
1037
1038- gtk_combo_box_set_tearable (GTK_COMBO_BOX (cc), FALSE);
1039+ mygal_combo_box_set_tearable (MYGAL_COMBO_BOX (cc), FALSE);
1040
1041 color = color_palette_get_current_color (cc->palette, NULL);
1042 color_combo_set_color_internal (cc, color);
1043diff -urN aa/glabels-1.93.1/src/mygal/widget-color-combo.h glabels-1.93.1/src/mygal/widget-color-combo.h
1044--- aa/glabels-1.93.1/src/mygal/widget-color-combo.h 2003-10-08 05:28:31.000000000 +0200
1045+++ glabels-1.93.1/src/mygal/widget-color-combo.h 2003-12-28 23:18:42.952328472 +0100
1046@@ -35,13 +35,13 @@
1047 #define GNUMERIC_WIDGET_COLOR_COMBO_H
1048
1049 #include <gtk/gtkwidget.h>
1050-#include "gtk-combo-box.h"
1051+#include "mygal-combo-box.h"
1052 #include "color-palette.h"
1053
1054 G_BEGIN_DECLS
1055
1056 typedef struct _ColorCombo {
1057- GtkComboBox combo_box;
1058+ MygalComboBox combo_box;
1059
1060 /*
1061 * GtkImage where we display
1062@@ -57,7 +57,7 @@
1063 } ColorCombo;
1064
1065 typedef struct {
1066- GtkComboBoxClass parent_class;
1067+ MygalComboBoxClass parent_class;
1068
1069 /* Signals emited by this widget */
1070 void (* color_changed) (ColorCombo *color_combo, GdkColor *color,
1071diff -urN aa/glabels-1.93.1/src/recent-files/Makefile.am glabels-1.93.1/src/recent-files/Makefile.am
1072--- aa/glabels-1.93.1/src/recent-files/Makefile.am 2003-10-19 06:10:14.000000000 +0200
1073+++ glabels-1.93.1/src/recent-files/Makefile.am 2003-12-28 23:27:00.186737352 +0100
1074@@ -1,10 +1,5 @@
1075 INCLUDES = \
1076- $(GLABELS_CFLAGS) \
1077- -DG_DISABLE_DEPRECATED \
1078- -DGDK_DISABLE_DEPRECATED \
1079- -DGTK_DISABLE_DEPRECATED \
1080- -DGDK_PIXBUF_DISABLE_DEPRECATED \
1081- -DGNOME_DISABLE_DEPRECATED
1082+ $(GLABELS_CFLAGS)
1083
1084 EGG_FILES = \
1085 egg-recent-model.c \
This page took 0.143044 seconds and 4 git commands to generate.