1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | /** |
---|
3 | * bonobo-ui-toolbar-popup-item.h |
---|
4 | * |
---|
5 | * Author: |
---|
6 | * Ettore Perazzoli |
---|
7 | * |
---|
8 | * Copyright (C) 2000 Helix Code, Inc. |
---|
9 | */ |
---|
10 | |
---|
11 | #ifdef HAVE_CONFIG_H |
---|
12 | #include <config.h> |
---|
13 | #endif |
---|
14 | |
---|
15 | #include <gnome.h> |
---|
16 | |
---|
17 | #include "bonobo-ui-toolbar-popup-item.h" |
---|
18 | |
---|
19 | |
---|
20 | #define PARENT_TYPE bonobo_ui_toolbar_toggle_button_item_get_type () |
---|
21 | static BonoboUIToolbarToggleButtonItemClass *parent_class = NULL; |
---|
22 | |
---|
23 | static GdkPixbuf *right_arrow_pixbuf = NULL; |
---|
24 | static GdkPixbuf *down_arrow_pixbuf = NULL; |
---|
25 | |
---|
26 | static const char *right_arrow_xpm_data[] = { |
---|
27 | "8 10 2 1", |
---|
28 | " c none", |
---|
29 | ". c #000000000000", |
---|
30 | " ", |
---|
31 | " . ", |
---|
32 | " .. ", |
---|
33 | " ... ", |
---|
34 | " .... ", |
---|
35 | " ..... ", |
---|
36 | " .... ", |
---|
37 | " ... ", |
---|
38 | " .. ", |
---|
39 | " . ", |
---|
40 | " " |
---|
41 | }; |
---|
42 | |
---|
43 | static const char *down_arrow_xpm_data[] = { |
---|
44 | "11 7 2 1", |
---|
45 | " c none", |
---|
46 | ". c #000000000000", |
---|
47 | " ", |
---|
48 | " ......... ", |
---|
49 | " ....... ", |
---|
50 | " ..... ", |
---|
51 | " ... ", |
---|
52 | " . ", |
---|
53 | " ", |
---|
54 | }; |
---|
55 | |
---|
56 | |
---|
57 | /* Utility functions. */ |
---|
58 | |
---|
59 | static void |
---|
60 | create_arrow_pixbufs (void) |
---|
61 | { |
---|
62 | g_assert (right_arrow_pixbuf == NULL); |
---|
63 | right_arrow_pixbuf = gdk_pixbuf_new_from_xpm_data (right_arrow_xpm_data); |
---|
64 | |
---|
65 | g_assert (down_arrow_pixbuf == NULL); |
---|
66 | down_arrow_pixbuf = gdk_pixbuf_new_from_xpm_data (down_arrow_xpm_data); |
---|
67 | } |
---|
68 | |
---|
69 | static GdkPixbuf * |
---|
70 | get_icon_for_orientation (BonoboUIToolbarPopupItem *popup_item) |
---|
71 | { |
---|
72 | GtkOrientation orientation; |
---|
73 | |
---|
74 | orientation = bonobo_ui_toolbar_item_get_orientation (BONOBO_UI_TOOLBAR_ITEM (popup_item)); |
---|
75 | |
---|
76 | if (orientation == GTK_ORIENTATION_HORIZONTAL) |
---|
77 | return right_arrow_pixbuf; |
---|
78 | else |
---|
79 | return down_arrow_pixbuf; |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | static void |
---|
84 | impl_set_orientation (BonoboUIToolbarItem *item, |
---|
85 | GtkOrientation orientation) |
---|
86 | { |
---|
87 | BonoboUIToolbarPopupItem *popup_item; |
---|
88 | GdkPixbuf *icon; |
---|
89 | |
---|
90 | if (BONOBO_UI_TOOLBAR_ITEM_CLASS (parent_class)->set_orientation != NULL) |
---|
91 | (* BONOBO_UI_TOOLBAR_ITEM_CLASS (parent_class)->set_orientation) (item, orientation); |
---|
92 | |
---|
93 | popup_item = BONOBO_UI_TOOLBAR_POPUP_ITEM (item); |
---|
94 | |
---|
95 | icon = get_icon_for_orientation (popup_item); |
---|
96 | bonobo_ui_toolbar_button_item_set_icon (BONOBO_UI_TOOLBAR_BUTTON_ITEM (item), icon); |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | static void |
---|
101 | class_init (BonoboUIToolbarPopupItemClass *popup_item_class) |
---|
102 | { |
---|
103 | BonoboUIToolbarItemClass *toolbar_item_class; |
---|
104 | |
---|
105 | toolbar_item_class = BONOBO_UI_TOOLBAR_ITEM_CLASS (popup_item_class); |
---|
106 | toolbar_item_class->set_orientation = impl_set_orientation; |
---|
107 | |
---|
108 | parent_class = gtk_type_class (PARENT_TYPE); |
---|
109 | |
---|
110 | create_arrow_pixbufs (); |
---|
111 | } |
---|
112 | |
---|
113 | static void |
---|
114 | init (BonoboUIToolbarPopupItem *toolbar_popup_item) |
---|
115 | { |
---|
116 | /* Nothing to do here. */ |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | GtkType |
---|
121 | bonobo_ui_toolbar_popup_item_get_type (void) |
---|
122 | { |
---|
123 | static GtkType type = 0; |
---|
124 | |
---|
125 | if (type == 0) { |
---|
126 | static const GtkTypeInfo info = { |
---|
127 | "BonoboUIToolbarPopupItem", |
---|
128 | sizeof (BonoboUIToolbarPopupItem), |
---|
129 | sizeof (BonoboUIToolbarPopupItemClass), |
---|
130 | (GtkClassInitFunc) class_init, |
---|
131 | (GtkObjectInitFunc) init, |
---|
132 | /* reserved_1 */ NULL, |
---|
133 | /* reserved_2 */ NULL, |
---|
134 | (GtkClassInitFunc) NULL, |
---|
135 | }; |
---|
136 | |
---|
137 | type = gtk_type_unique (PARENT_TYPE, &info); |
---|
138 | } |
---|
139 | |
---|
140 | return type; |
---|
141 | } |
---|
142 | |
---|
143 | void |
---|
144 | bonobo_ui_toolbar_popup_item_construct (BonoboUIToolbarPopupItem *popup_item) |
---|
145 | { |
---|
146 | GdkPixbuf *icon; |
---|
147 | |
---|
148 | g_return_if_fail (popup_item != NULL); |
---|
149 | g_return_if_fail (BONOBO_IS_UI_TOOLBAR_POPUP_ITEM (popup_item)); |
---|
150 | |
---|
151 | icon = get_icon_for_orientation (popup_item); |
---|
152 | |
---|
153 | bonobo_ui_toolbar_toggle_button_item_construct (BONOBO_UI_TOOLBAR_TOGGLE_BUTTON_ITEM (popup_item), icon, NULL); |
---|
154 | } |
---|
155 | |
---|
156 | GtkWidget * |
---|
157 | bonobo_ui_toolbar_popup_item_new (void) |
---|
158 | { |
---|
159 | BonoboUIToolbarPopupItem *popup_item; |
---|
160 | |
---|
161 | popup_item = gtk_type_new (bonobo_ui_toolbar_popup_item_get_type ()); |
---|
162 | |
---|
163 | bonobo_ui_toolbar_popup_item_construct (popup_item); |
---|
164 | |
---|
165 | return GTK_WIDGET (popup_item); |
---|
166 | } |
---|