1
/* GTK - The GIMP Toolkit
2
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library 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 GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
21
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22
* file for a list of people on the GTK+ Team. See the ChangeLog
23
* files for a list of changes. These files are distributed with
24
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30
#include "gtktearoffmenuitem.h"
36
#define BORDER_SPACING 3
38
static void gtk_tearoff_menu_item_size_request (GtkWidget *widget,
39
GtkRequisition *requisition);
40
static gint gtk_tearoff_menu_item_expose (GtkWidget *widget,
41
GdkEventExpose *event);
42
static void gtk_tearoff_menu_item_activate (GtkMenuItem *menu_item);
43
static void gtk_tearoff_menu_item_parent_set (GtkWidget *widget,
46
G_DEFINE_TYPE (GtkTearoffMenuItem, gtk_tearoff_menu_item, GTK_TYPE_MENU_ITEM)
49
gtk_tearoff_menu_item_new (void)
51
return g_object_new (GTK_TYPE_TEAROFF_MENU_ITEM, NULL);
55
gtk_tearoff_menu_item_class_init (GtkTearoffMenuItemClass *klass)
57
GtkWidgetClass *widget_class;
58
GtkMenuItemClass *menu_item_class;
60
widget_class = (GtkWidgetClass*) klass;
61
menu_item_class = (GtkMenuItemClass*) klass;
63
widget_class->expose_event = gtk_tearoff_menu_item_expose;
64
widget_class->size_request = gtk_tearoff_menu_item_size_request;
65
widget_class->parent_set = gtk_tearoff_menu_item_parent_set;
67
menu_item_class->activate = gtk_tearoff_menu_item_activate;
71
gtk_tearoff_menu_item_init (GtkTearoffMenuItem *tearoff_menu_item)
73
tearoff_menu_item->torn_off = FALSE;
77
gtk_tearoff_menu_item_size_request (GtkWidget *widget,
78
GtkRequisition *requisition)
80
requisition->width = (GTK_CONTAINER (widget)->border_width +
81
widget->style->xthickness +
83
requisition->height = (GTK_CONTAINER (widget)->border_width +
84
widget->style->ythickness) * 2;
86
if (GTK_IS_MENU (widget->parent) && GTK_MENU (widget->parent)->torn_off)
88
requisition->height += ARROW_SIZE;
92
requisition->height += widget->style->ythickness + 4;
97
gtk_tearoff_menu_item_paint (GtkWidget *widget,
100
GtkMenuItem *menu_item;
101
GtkShadowType shadow_type;
105
GtkArrowType arrow_type;
106
GtkTextDirection direction;
108
if (GTK_WIDGET_DRAWABLE (widget))
110
menu_item = GTK_MENU_ITEM (widget);
112
direction = gtk_widget_get_direction (widget);
114
x = widget->allocation.x + GTK_CONTAINER (menu_item)->border_width;
115
y = widget->allocation.y + GTK_CONTAINER (menu_item)->border_width;
116
width = widget->allocation.width - GTK_CONTAINER (menu_item)->border_width * 2;
117
height = widget->allocation.height - GTK_CONTAINER (menu_item)->border_width * 2;
118
right_max = x + width;
120
if (widget->state == GTK_STATE_PRELIGHT)
122
gint selected_shadow_type;
124
gtk_widget_style_get (widget,
125
"selected-shadow-type", &selected_shadow_type,
127
gtk_paint_box (widget->style,
130
selected_shadow_type,
131
area, widget, "menuitem",
132
x, y, width, height);
135
gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height);
137
if (GTK_IS_MENU (widget->parent) && GTK_MENU (widget->parent)->torn_off)
141
if (widget->state == GTK_STATE_PRELIGHT)
142
shadow_type = GTK_SHADOW_IN;
144
shadow_type = GTK_SHADOW_OUT;
146
if (menu_item->toggle_size > ARROW_SIZE)
148
if (direction == GTK_TEXT_DIR_LTR) {
149
arrow_x = x + (menu_item->toggle_size - ARROW_SIZE)/2;
150
arrow_type = GTK_ARROW_LEFT;
153
arrow_x = x + width - menu_item->toggle_size + (menu_item->toggle_size - ARROW_SIZE)/2;
154
arrow_type = GTK_ARROW_RIGHT;
156
x += menu_item->toggle_size + BORDER_SPACING;
160
if (direction == GTK_TEXT_DIR_LTR) {
161
arrow_x = ARROW_SIZE / 2;
162
arrow_type = GTK_ARROW_LEFT;
165
arrow_x = x + width - 2 * ARROW_SIZE + ARROW_SIZE / 2;
166
arrow_type = GTK_ARROW_RIGHT;
172
gtk_paint_arrow (widget->style, widget->window,
173
widget->state, shadow_type,
174
NULL, widget, "tearoffmenuitem",
176
arrow_x, y + height / 2 - 5,
177
ARROW_SIZE, ARROW_SIZE);
180
while (x < right_max)
184
if (direction == GTK_TEXT_DIR_LTR) {
186
x2 = MIN (x + TEAR_LENGTH, right_max);
190
x2 = MAX (right_max - x - TEAR_LENGTH, 0);
193
gtk_paint_hline (widget->style, widget->window, GTK_STATE_NORMAL,
194
NULL, widget, "tearoffmenuitem",
195
x1, x2, y + (height - widget->style->ythickness) / 2);
196
x += 2 * TEAR_LENGTH;
202
gtk_tearoff_menu_item_expose (GtkWidget *widget,
203
GdkEventExpose *event)
205
gtk_tearoff_menu_item_paint (widget, &event->area);
211
gtk_tearoff_menu_item_activate (GtkMenuItem *menu_item)
213
if (GTK_IS_MENU (GTK_WIDGET (menu_item)->parent))
215
GtkMenu *menu = GTK_MENU (GTK_WIDGET (menu_item)->parent);
217
gtk_widget_queue_resize (GTK_WIDGET (menu_item));
218
gtk_menu_set_tearoff_state (GTK_MENU (GTK_WIDGET (menu_item)->parent),
224
tearoff_state_changed (GtkMenu *menu,
228
GtkTearoffMenuItem *tearoff_menu_item = GTK_TEAROFF_MENU_ITEM (data);
230
tearoff_menu_item->torn_off = gtk_menu_get_tearoff_state (menu);
234
gtk_tearoff_menu_item_parent_set (GtkWidget *widget,
237
GtkTearoffMenuItem *tearoff_menu_item = GTK_TEAROFF_MENU_ITEM (widget);
238
GtkMenu *menu = GTK_IS_MENU (widget->parent) ? GTK_MENU (widget->parent) : NULL;
241
g_signal_handlers_disconnect_by_func (previous,
242
tearoff_state_changed,
247
tearoff_menu_item->torn_off = gtk_menu_get_tearoff_state (menu);
248
g_signal_connect (menu, "notify::tearoff-state",
249
G_CALLBACK (tearoff_state_changed),
254
#define __GTK_TEAROFF_MENU_ITEM_C__
255
#include "gtkaliasdef.c"