1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | /** |
---|
3 | * bonobo-ui-toolbar-separator-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 | #include "bonobo-ui-toolbar-separator-item.h" |
---|
17 | |
---|
18 | |
---|
19 | #define PARENT_TYPE bonobo_ui_toolbar_item_get_type () |
---|
20 | static BonoboUIToolbarItemClass *parent_class = NULL; |
---|
21 | |
---|
22 | |
---|
23 | #define BORDER_WIDTH 2 |
---|
24 | |
---|
25 | #define SPACE_LINE_DIVISION 10 |
---|
26 | #define SPACE_LINE_START 3 |
---|
27 | #define SPACE_LINE_END 7 |
---|
28 | |
---|
29 | |
---|
30 | /* GtkWidget methods. */ |
---|
31 | |
---|
32 | static void |
---|
33 | impl_size_request (GtkWidget *widget, |
---|
34 | GtkRequisition *requisition) |
---|
35 | { |
---|
36 | int border_width; |
---|
37 | |
---|
38 | border_width = GTK_CONTAINER (widget)->border_width; |
---|
39 | |
---|
40 | requisition->width = 2 * border_width + widget->style->klass->xthickness; |
---|
41 | requisition->height = 2 * border_width + widget->style->klass->ythickness; |
---|
42 | } |
---|
43 | |
---|
44 | static void |
---|
45 | impl_draw (GtkWidget *widget, |
---|
46 | GdkRectangle *area) |
---|
47 | { |
---|
48 | BonoboUIToolbarItem *item; |
---|
49 | const GtkAllocation *allocation; |
---|
50 | GtkOrientation orientation; |
---|
51 | int border_width; |
---|
52 | |
---|
53 | item = BONOBO_UI_TOOLBAR_ITEM (widget); |
---|
54 | |
---|
55 | allocation = &widget->allocation; |
---|
56 | border_width = GTK_CONTAINER (widget)->border_width; |
---|
57 | |
---|
58 | orientation = bonobo_ui_toolbar_item_get_orientation (item); |
---|
59 | |
---|
60 | if (orientation == GTK_ORIENTATION_HORIZONTAL) |
---|
61 | gtk_paint_vline (widget->style, widget->window, |
---|
62 | GTK_WIDGET_STATE (widget), area, widget, |
---|
63 | "toolbar", |
---|
64 | allocation->y + allocation->height * SPACE_LINE_START / SPACE_LINE_DIVISION, |
---|
65 | allocation->y + allocation->height * SPACE_LINE_END / SPACE_LINE_DIVISION, |
---|
66 | allocation->x + border_width); |
---|
67 | else |
---|
68 | gtk_paint_hline (widget->style, widget->window, |
---|
69 | GTK_WIDGET_STATE (widget), area, widget, |
---|
70 | "toolbar", |
---|
71 | allocation->x + allocation->width * SPACE_LINE_START / SPACE_LINE_DIVISION, |
---|
72 | allocation->x + allocation->width * SPACE_LINE_END / SPACE_LINE_DIVISION, |
---|
73 | allocation->y + border_width); |
---|
74 | } |
---|
75 | |
---|
76 | static int |
---|
77 | impl_expose_event (GtkWidget *widget, |
---|
78 | GdkEventExpose *expose) |
---|
79 | { |
---|
80 | gtk_widget_draw (widget, &expose->area); |
---|
81 | |
---|
82 | return FALSE; |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | static void |
---|
87 | class_init (BonoboUIToolbarSeparatorItemClass *separator_item_class) |
---|
88 | { |
---|
89 | GtkWidgetClass *widget_class; |
---|
90 | |
---|
91 | widget_class = GTK_WIDGET_CLASS (separator_item_class); |
---|
92 | widget_class->size_request = impl_size_request; |
---|
93 | widget_class->draw = impl_draw; |
---|
94 | widget_class->expose_event = impl_expose_event; |
---|
95 | |
---|
96 | parent_class = gtk_type_class (bonobo_ui_toolbar_item_get_type ()); |
---|
97 | } |
---|
98 | |
---|
99 | static void |
---|
100 | init (BonoboUIToolbarSeparatorItem *toolbar_separator_item) |
---|
101 | { |
---|
102 | gtk_container_set_border_width (GTK_CONTAINER (toolbar_separator_item), BORDER_WIDTH); |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | GtkType |
---|
107 | bonobo_ui_toolbar_separator_item_get_type (void) |
---|
108 | { |
---|
109 | static GtkType type = 0; |
---|
110 | |
---|
111 | if (type == 0) { |
---|
112 | static const GtkTypeInfo info = { |
---|
113 | "BonoboUIToolbarSeparatorItem", |
---|
114 | sizeof (BonoboUIToolbarSeparatorItem), |
---|
115 | sizeof (BonoboUIToolbarSeparatorItemClass), |
---|
116 | (GtkClassInitFunc) class_init, |
---|
117 | (GtkObjectInitFunc) init, |
---|
118 | /* reserved_1 */ NULL, |
---|
119 | /* reserved_2 */ NULL, |
---|
120 | (GtkClassInitFunc) NULL, |
---|
121 | }; |
---|
122 | |
---|
123 | type = gtk_type_unique (PARENT_TYPE, &info); |
---|
124 | } |
---|
125 | |
---|
126 | return type; |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | GtkWidget * |
---|
131 | bonobo_ui_toolbar_separator_item_new (void) |
---|
132 | { |
---|
133 | BonoboUIToolbarSeparatorItem *new; |
---|
134 | |
---|
135 | new = gtk_type_new (bonobo_ui_toolbar_separator_item_get_type ()); |
---|
136 | |
---|
137 | return GTK_WIDGET (new); |
---|
138 | } |
---|