2 /* Author: Dietmar Maurer <dm@vlsivie.tuwien.ac.at> */
4 /* This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "gtkpixmapmenuitem.h"
22 #include <gtk/gtkaccellabel.h>
23 #include <gtk/gtksignal.h>
25 static void gtk_pixmap_menu_item_class_init (GtkPixmapMenuItemClass
*klass
);
26 static void gtk_pixmap_menu_item_init (GtkPixmapMenuItem
*menu_item
);
27 static void gtk_pixmap_menu_item_draw (GtkWidget
*widget
,
29 static gint
gtk_pixmap_menu_item_expose (GtkWidget
*widget
,
30 GdkEventExpose
*event
);
32 /* we must override the following functions */
34 static void gtk_pixmap_menu_item_map (GtkWidget
*widget
);
35 static void gtk_pixmap_menu_item_size_allocate (GtkWidget
*widget
,
36 GtkAllocation
*allocation
);
37 static void gtk_pixmap_menu_item_forall (GtkContainer
*container
,
38 gboolean include_internals
,
40 gpointer callback_data
);
41 static void gtk_pixmap_menu_item_size_request (GtkWidget
*widget
,
42 GtkRequisition
*requisition
);
43 static void gtk_pixmap_menu_item_remove (GtkContainer
*container
,
47 static GtkMenuItemClass
*parent_class
= NULL
;
52 gtk_pixmap_menu_item_get_type (void)
54 static GtkType pixmap_menu_item_type
= 0;
56 if (!pixmap_menu_item_type
)
58 GtkTypeInfo pixmap_menu_item_info
=
61 sizeof (GtkPixmapMenuItem
),
62 sizeof (GtkPixmapMenuItemClass
),
63 (GtkClassInitFunc
) gtk_pixmap_menu_item_class_init
,
64 (GtkObjectInitFunc
) gtk_pixmap_menu_item_init
,
65 /* reserved_1 */ NULL
,
66 /* reserved_2 */ NULL
,
67 (GtkClassInitFunc
) NULL
,
70 pixmap_menu_item_type
= gtk_type_unique (gtk_menu_item_get_type (),
71 &pixmap_menu_item_info
);
74 return pixmap_menu_item_type
;
78 gtk_pixmap_menu_item_new (void)
80 return GTK_WIDGET (gtk_type_new (gtk_pixmap_menu_item_get_type ()));
84 gtk_pixmap_menu_item_class_init (GtkPixmapMenuItemClass
*klass
)
86 GtkObjectClass
*object_class
;
87 GtkWidgetClass
*widget_class
;
88 GtkMenuItemClass
*menu_item_class
;
89 GtkContainerClass
*container_class
;
91 object_class
= (GtkObjectClass
*) klass
;
92 widget_class
= (GtkWidgetClass
*) klass
;
93 menu_item_class
= (GtkMenuItemClass
*) klass
;
94 container_class
= (GtkContainerClass
*) klass
;
96 parent_class
= gtk_type_class (gtk_menu_item_get_type ());
98 widget_class
->draw
= gtk_pixmap_menu_item_draw
;
99 widget_class
->expose_event
= gtk_pixmap_menu_item_expose
;
100 widget_class
->map
= gtk_pixmap_menu_item_map
;
101 widget_class
->size_allocate
= gtk_pixmap_menu_item_size_allocate
;
102 widget_class
->size_request
= gtk_pixmap_menu_item_size_request
;
104 container_class
->forall
= gtk_pixmap_menu_item_forall
;
105 container_class
->remove
= gtk_pixmap_menu_item_remove
;
106 menu_item_class
->toggle_size
= INDENT
;
110 gtk_pixmap_menu_item_init (GtkPixmapMenuItem
*menu_item
)
112 menu_item
->pixmap
= NULL
;
116 gtk_pixmap_menu_item_draw (GtkWidget
*widget
,
119 g_return_if_fail (widget
!= NULL
);
120 g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (widget
));
121 g_return_if_fail (area
!= NULL
);
123 if (GTK_WIDGET_CLASS (parent_class
)->draw
)
124 (* GTK_WIDGET_CLASS (parent_class
)->draw
) (widget
, area
);
126 if (GTK_WIDGET_DRAWABLE (widget
) &&
127 GTK_PIXMAP_MENU_ITEM(widget
)->pixmap
) {
128 gtk_widget_draw(GTK_WIDGET(GTK_PIXMAP_MENU_ITEM(widget
)->pixmap
),NULL
);
133 gtk_pixmap_menu_item_expose (GtkWidget
*widget
,
134 GdkEventExpose
*event
)
136 g_return_val_if_fail (widget
!= NULL
, FALSE
);
137 g_return_val_if_fail (GTK_IS_PIXMAP_MENU_ITEM (widget
), FALSE
);
138 g_return_val_if_fail (event
!= NULL
, FALSE
);
140 if (GTK_WIDGET_CLASS (parent_class
)->expose_event
)
141 (* GTK_WIDGET_CLASS (parent_class
)->expose_event
) (widget
, event
);
143 if (GTK_WIDGET_DRAWABLE (widget
) &&
144 GTK_PIXMAP_MENU_ITEM(widget
)->pixmap
) {
145 gtk_widget_draw(GTK_WIDGET(GTK_PIXMAP_MENU_ITEM(widget
)->pixmap
),NULL
);
152 gtk_pixmap_menu_item_set_pixmap (GtkPixmapMenuItem
*menu_item
,
155 g_return_if_fail (menu_item
!= NULL
);
156 g_return_if_fail (pixmap
!= NULL
);
157 g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (menu_item
));
158 g_return_if_fail (GTK_IS_WIDGET (pixmap
));
159 g_return_if_fail (menu_item
->pixmap
== NULL
);
161 gtk_widget_set_parent (pixmap
, GTK_WIDGET (menu_item
));
162 menu_item
->pixmap
= pixmap
;
164 if (GTK_WIDGET_VISIBLE (pixmap
->parent
)) {
165 if (GTK_WIDGET_REALIZED (pixmap
->parent
) &&
166 !GTK_WIDGET_REALIZED (pixmap
))
167 gtk_widget_realize (pixmap
);
169 if (GTK_WIDGET_MAPPED (pixmap
->parent
) &&
170 !GTK_WIDGET_MAPPED (pixmap
))
171 gtk_widget_map (pixmap
);
174 if (GTK_WIDGET_VISIBLE (pixmap
) && GTK_WIDGET_VISIBLE (menu_item
))
175 gtk_widget_queue_resize (pixmap
);
180 gtk_pixmap_menu_item_map (GtkWidget
*widget
)
182 GtkPixmapMenuItem
*menu_item
;
184 g_return_if_fail (widget
!= NULL
);
185 g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (widget
));
187 menu_item
= GTK_PIXMAP_MENU_ITEM(widget
);
189 GTK_WIDGET_CLASS(parent_class
)->map(widget
);
191 if (menu_item
->pixmap
&&
192 GTK_WIDGET_VISIBLE (menu_item
->pixmap
) &&
193 !GTK_WIDGET_MAPPED (menu_item
->pixmap
))
194 gtk_widget_map (menu_item
->pixmap
);
198 gtk_pixmap_menu_item_size_allocate (GtkWidget
*widget
,
199 GtkAllocation
*allocation
)
201 GtkPixmapMenuItem
*menu_item
;
202 GtkAllocation child_allocation
;
204 g_return_if_fail (widget
!= NULL
);
205 g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (widget
));
206 g_return_if_fail (allocation
!= NULL
);
208 menu_item
= GTK_PIXMAP_MENU_ITEM(widget
);
210 if (menu_item
->pixmap
) {
211 child_allocation
.x
= GTK_CONTAINER (widget
)->border_width
+
212 widget
->style
->klass
->xthickness
+ 3;
213 child_allocation
.y
= GTK_CONTAINER (widget
)->border_width
+4;
214 child_allocation
.width
= INDENT
-child_allocation
.x
;
215 child_allocation
.height
= allocation
->height
-2*child_allocation
.y
;
216 gtk_widget_size_allocate (menu_item
->pixmap
, &child_allocation
);
219 GTK_WIDGET_CLASS(parent_class
)->size_allocate(widget
,allocation
);
223 gtk_pixmap_menu_item_forall (GtkContainer
*container
,
224 gboolean include_internals
,
225 GtkCallback callback
,
226 gpointer callback_data
)
228 GtkPixmapMenuItem
*menu_item
;
230 g_return_if_fail (container
!= NULL
);
231 g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (container
));
232 g_return_if_fail (callback
!= NULL
);
234 menu_item
= GTK_PIXMAP_MENU_ITEM (container
);
236 if (menu_item
->pixmap
)
237 (* callback
) (menu_item
->pixmap
, callback_data
);
239 GTK_CONTAINER_CLASS(parent_class
)->forall(container
,include_internals
,
240 callback
,callback_data
);
244 gtk_pixmap_menu_item_size_request (GtkWidget
*widget
,
245 GtkRequisition
*requisition
)
247 GtkPixmapMenuItem
*menu_item
;
250 g_return_if_fail (widget
!= NULL
);
251 g_return_if_fail (GTK_IS_MENU_ITEM (widget
));
252 g_return_if_fail (requisition
!= NULL
);
254 GTK_WIDGET_CLASS(parent_class
)->size_request(widget
,requisition
);
256 menu_item
= GTK_PIXMAP_MENU_ITEM (widget
);
258 /* some widgets needs this */
259 if (menu_item
->pixmap
)
260 gtk_widget_size_request(menu_item
->pixmap
,&req
);
265 gtk_pixmap_menu_item_remove (GtkContainer
*container
,
269 gboolean widget_was_visible
;
271 g_return_if_fail (container
!= NULL
);
272 g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (container
));
273 g_return_if_fail (child
!= NULL
);
274 g_return_if_fail (GTK_IS_WIDGET (child
));
276 bin
= GTK_BIN (container
);
277 g_return_if_fail ((bin
->child
== child
||
278 (GTK_PIXMAP_MENU_ITEM(container
)->pixmap
== child
)));
280 widget_was_visible
= GTK_WIDGET_VISIBLE (child
);
282 gtk_widget_unparent (child
);
283 if (bin
->child
== child
)
286 GTK_PIXMAP_MENU_ITEM(container
)->pixmap
= NULL
;
288 if (widget_was_visible
)
289 gtk_widget_queue_resize (GTK_WIDGET (container
));