]> Pileus Git - ~andy/gtk/blob - gtk/gtkseparatortoolitem.c
remove accidentally committed debugging spew
[~andy/gtk] / gtk / gtkseparatortoolitem.c
1 /* gtkseparatortoolitem.c
2  *
3  * Copyright (C) 2002 Anders Carlsson <andersca@codefactory.se>
4  * Copyright (C) 2002 James Henstridge <james@daa.com.au>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #undef GTK_DISABLE_DEPRECATED
23
24 #include "gtkseparatormenuitem.h"
25 #include "gtkseparatortoolitem.h"
26 #include "gtkintl.h"
27 #include "gtktoolbar.h"
28
29 /* note: keep in sync with DEFAULT_SPACE_SIZE and DEFAULT_SPACE_STYLE in gtktoolbar.c */
30 #define DEFAULT_SPACE_SIZE 5    
31 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
32
33 #define SPACE_LINE_DIVISION 10
34 #define SPACE_LINE_START    3
35 #define SPACE_LINE_END      7
36
37 static void                 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class);
38 static gboolean             gtk_separator_tool_item_expose     (GtkWidget                 *widget,
39                                                                 GdkEventExpose            *event);
40 static void                 gtk_separator_tool_item_add        (GtkContainer              *container,
41                                                                 GtkWidget                 *child);
42 static GtkToolbarSpaceStyle get_space_style                    (GtkToolItem               *tool_item);
43 static gint                 get_space_size                     (GtkToolItem               *tool_item);
44
45 static GObjectClass *parent_class = NULL;
46
47
48 GType
49 gtk_separator_tool_item_get_type (void)
50 {
51   static GType type = 0;
52
53   if (!type)
54     {
55       static const GTypeInfo type_info =
56         {
57           sizeof (GtkSeparatorToolItemClass),
58           (GBaseInitFunc) 0,
59           (GBaseFinalizeFunc) 0,
60           (GClassInitFunc) gtk_separator_tool_item_class_init,
61           (GClassFinalizeFunc) 0,
62           NULL,
63           sizeof (GtkSeparatorToolItem),
64           0, /* n_preallocs */
65           (GInstanceInitFunc) NULL,
66         };
67
68       type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
69                                      "GtkSeparatorToolItem", &type_info, 0);
70     }
71   return type;
72 }
73
74 static GtkToolbarSpaceStyle
75 get_space_style (GtkToolItem *tool_item)
76 {
77   GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
78   GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
79
80   if (GTK_IS_TOOLBAR (parent))
81     {
82       gtk_widget_style_get (parent,
83                             "space_style", &space_style,
84                             NULL);
85     }
86
87   return space_style;  
88 }
89
90 static gint
91 get_space_size (GtkToolItem *tool_item)
92 {
93   gint space_size = DEFAULT_SPACE_SIZE;
94   GtkWidget *parent = GTK_WIDGET (tool_item)->parent;
95   
96   if (GTK_IS_TOOLBAR (parent))
97     {
98       gtk_widget_style_get (parent,
99                             "space_size", &space_size,
100                             NULL);
101     }
102
103   return space_size;
104 }
105
106 static void
107 gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
108 {
109   GtkContainerClass *container_class;
110   GtkToolItemClass *toolitem_class;
111   GtkWidgetClass *widget_class;
112
113   parent_class = g_type_class_peek_parent (class);
114   container_class = (GtkContainerClass *)class;
115   toolitem_class = (GtkToolItemClass *)class;
116   widget_class = (GtkWidgetClass *)class;
117
118   widget_class->expose_event = gtk_separator_tool_item_expose;
119   
120   container_class->add = gtk_separator_tool_item_add;
121 }
122
123 static void
124 gtk_separator_tool_item_add (GtkContainer *container,
125                              GtkWidget    *child)
126 {
127   g_warning("attempt to add a child to an GtkSeparatorToolItem");
128 }
129
130 static gboolean
131 gtk_separator_tool_item_expose (GtkWidget      *widget,
132                                 GdkEventExpose *event)
133 {
134   GtkToolItem *tool_item = GTK_TOOL_ITEM (widget);
135   gint space_size;
136   GtkAllocation *allocation;
137   GtkOrientation orientation;
138   GdkRectangle *area;
139
140   if (get_space_style (tool_item) == GTK_TOOLBAR_SPACE_LINE)
141     {
142       space_size = get_space_size (tool_item);
143       allocation = &(widget->allocation);
144       orientation = gtk_tool_item_get_orientation (tool_item);
145       area = &(event->area);
146       
147       if (orientation == GTK_ORIENTATION_HORIZONTAL)
148         {
149           gtk_paint_vline (widget->style, widget->window,
150                            GTK_WIDGET_STATE (widget), area, widget,
151                            "separator_tool_item",
152                            allocation->y + allocation->height *
153                            SPACE_LINE_START / SPACE_LINE_DIVISION,
154                            allocation->y + allocation->height *
155                            SPACE_LINE_END / SPACE_LINE_DIVISION,
156                            allocation->x + (space_size - widget->style->xthickness) / 2);
157         }
158       else if (orientation == GTK_ORIENTATION_VERTICAL)
159         {
160           gtk_paint_hline (widget->style, widget->window,
161                            GTK_WIDGET_STATE (widget), area, widget,
162                            "separator_tool_item",
163                            allocation->x + allocation->width *
164                            SPACE_LINE_START / SPACE_LINE_DIVISION,
165                            allocation->x + allocation->width *
166                            SPACE_LINE_END / SPACE_LINE_DIVISION,
167                            allocation->y + (space_size - widget->style->ythickness) / 2);
168         }
169     }
170   
171   return TRUE;
172 }
173
174 GtkToolItem *
175 gtk_separator_tool_item_new (void)
176 {
177   GtkToolItem *self;
178
179   self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
180                        NULL);
181   
182   return self;
183 }