~ubuntu-branches/ubuntu/oneiric/gnome-panel/oneiric

« back to all changes in this revision

Viewing changes to gnome-panel/panel-separator.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-05-30 11:04:49 UTC
  • mfrom: (1.3.4 upstream)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: james.westby@ubuntu.com-20110530110449-ut1tc5t61rpvf9e3
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include <config.h>
26
26
 
 
27
#include "panel-background.h"
 
28
#include "panel-layout.h"
 
29
 
27
30
#include "panel-separator.h"
28
 
#include "panel-background.h"
29
 
#include "panel-profile.h"
30
31
 
31
32
#define SEPARATOR_SIZE 10
32
33
 
41
42
 
42
43
G_DEFINE_TYPE (PanelSeparator, panel_separator, GTK_TYPE_EVENT_BOX)
43
44
 
44
 
static void
45
 
panel_separator_paint (GtkWidget    *widget,
46
 
                       GdkRectangle *area)
 
45
static gboolean
 
46
panel_separator_draw (GtkWidget *widget,
 
47
                      cairo_t   *cr)
47
48
{
48
 
        PanelSeparator *separator;
49
 
        GdkWindow      *window;
50
 
        GtkStyle       *style;
51
 
        GtkAllocation   allocation;
 
49
        PanelSeparator  *separator = PANEL_SEPARATOR (widget);
 
50
        GdkWindow       *window;
 
51
        GtkStyleContext *context;
 
52
        GtkStateFlags    state;
 
53
        GtkBorder        padding;
 
54
        int              width, height;
52
55
 
53
 
        separator = PANEL_SEPARATOR (widget);
 
56
        if (GTK_WIDGET_CLASS (panel_separator_parent_class)->draw)
 
57
                GTK_WIDGET_CLASS (panel_separator_parent_class)->draw (widget, cr);
54
58
 
55
59
        window = gtk_widget_get_window (widget);
56
 
        style = gtk_widget_get_style (widget);
57
 
        gtk_widget_get_allocation (widget, &allocation);
58
 
 
 
60
        state = gtk_widget_get_state_flags (widget);
 
61
        width = gtk_widget_get_allocated_width (widget);
 
62
        height = gtk_widget_get_allocated_height (widget);
 
63
 
 
64
        context = gtk_widget_get_style_context (widget);
 
65
        gtk_style_context_get_padding (context, state, &padding);
 
66
 
 
67
        gtk_style_context_save (context);
 
68
        gtk_style_context_set_state (context, state);
 
69
 
 
70
        cairo_save (cr);
59
71
        if (separator->priv->orientation == GTK_ORIENTATION_HORIZONTAL) {
60
 
                gtk_paint_vline (style, window,
61
 
                                 gtk_widget_get_state (widget),
62
 
                                 area, widget, "separator",
63
 
                                 style->xthickness,
64
 
                                 allocation.height - style->xthickness,
65
 
                                 (allocation.width - style->xthickness) / 2);
 
72
                int x;
 
73
 
 
74
                x= (width - padding.left - padding.right) / 2 + padding.left;
 
75
                x = MIN (x, width - padding.right);
 
76
 
 
77
                gtk_render_line (context, cr,
 
78
                                 x, padding.top,
 
79
                                 x, height - padding.bottom);
66
80
        } else {
67
 
                gtk_paint_hline (style, window,
68
 
                                 gtk_widget_get_state (widget),
69
 
                                 area, widget, "separator",
70
 
                                 style->ythickness,
71
 
                                 allocation.width - style->ythickness,
72
 
                                 (allocation.height  - style->ythickness) / 2);
73
 
        }
74
 
}
75
 
 
76
 
static gboolean
77
 
panel_separator_expose_event (GtkWidget      *widget,
78
 
                              GdkEventExpose *event)
79
 
{
80
 
        if (gtk_widget_is_drawable (widget)) {
81
 
                GTK_WIDGET_CLASS (panel_separator_parent_class)->expose_event (widget, event);
82
 
 
83
 
                panel_separator_paint (widget, &event->area);
84
 
        }
 
81
                int y;
 
82
 
 
83
                y = (height - padding.top - padding.bottom) / 2 + padding.top;
 
84
                y = MIN (y, height - padding.bottom);
 
85
 
 
86
                gtk_render_line (context, cr,
 
87
                                 padding.left, y,
 
88
                                 width - padding.right, y);
 
89
        }
 
90
        cairo_restore (cr);
 
91
 
 
92
        gtk_style_context_restore (context);
85
93
 
86
94
        return FALSE;
87
95
}
88
96
 
89
97
static void
90
 
panel_separator_size_request (GtkWidget      *widget,
91
 
                              GtkRequisition *requisition)
92
 
{
93
 
        PanelSeparator *separator;
94
 
        int             size;
95
 
 
96
 
        separator = PANEL_SEPARATOR (widget);
97
 
 
98
 
        size = panel_toplevel_get_size (separator->priv->panel->toplevel);
99
 
 
100
 
        if (separator->priv->orientation == GTK_ORIENTATION_VERTICAL) {
101
 
                requisition->width = size;
102
 
                requisition->height = SEPARATOR_SIZE;
103
 
        } else {
104
 
                requisition->width = SEPARATOR_SIZE;
105
 
                requisition->height = size;
106
 
        }
 
98
panel_separator_get_preferred_width (GtkWidget *widget,
 
99
                                     gint      *minimal_width,
 
100
                                     gint      *natural_width)
 
101
{
 
102
        PanelSeparator *separator;
 
103
        int             size;
 
104
 
 
105
        separator = PANEL_SEPARATOR (widget);
 
106
 
 
107
        size = panel_toplevel_get_size (separator->priv->panel->toplevel);
 
108
 
 
109
        if (separator->priv->orientation == GTK_ORIENTATION_VERTICAL)
 
110
                *minimal_width = *natural_width = size;
 
111
        else
 
112
                *minimal_width = *natural_width = SEPARATOR_SIZE;
 
113
}
 
114
 
 
115
static void
 
116
panel_separator_get_preferred_height (GtkWidget *widget,
 
117
                                      gint      *minimal_height,
 
118
                                      gint      *natural_height)
 
119
{
 
120
        PanelSeparator *separator;
 
121
        int             size;
 
122
 
 
123
        separator = PANEL_SEPARATOR (widget);
 
124
 
 
125
        size = panel_toplevel_get_size (separator->priv->panel->toplevel);
 
126
 
 
127
        if (separator->priv->orientation == GTK_ORIENTATION_VERTICAL)
 
128
                *minimal_height = *natural_height = SEPARATOR_SIZE;
 
129
        else
 
130
                *minimal_height = *natural_height = size;
107
131
}
108
132
 
109
133
static void
158
182
{
159
183
        GtkWidgetClass *widget_class  = GTK_WIDGET_CLASS (klass);
160
184
 
161
 
        widget_class->expose_event  = panel_separator_expose_event;
162
 
        widget_class->size_request  = panel_separator_size_request;
163
 
        widget_class->size_allocate = panel_separator_size_allocate;
164
 
        widget_class->parent_set    = panel_separator_parent_set;
 
185
        widget_class->draw                 = panel_separator_draw;
 
186
        widget_class->get_preferred_width  = panel_separator_get_preferred_width;
 
187
        widget_class->get_preferred_height = panel_separator_get_preferred_height;
 
188
        widget_class->size_allocate        = panel_separator_size_allocate;
 
189
        widget_class->parent_set           = panel_separator_parent_set;
165
190
 
166
191
        g_type_class_add_private (klass, sizeof (PanelSeparatorPrivate));
167
192
}
204
229
}
205
230
 
206
231
void
207
 
panel_separator_load_from_gconf (PanelWidget *panel,
208
 
                                 gboolean     locked,
209
 
                                 int          position,
210
 
                                 const char  *id)
 
232
panel_separator_load (PanelWidget *panel,
 
233
                      const char  *id,
 
234
                      GSettings   *settings)
211
235
{
212
236
        PanelSeparator *separator;
213
237
 
214
238
        separator = g_object_new (PANEL_TYPE_SEPARATOR, NULL);
215
239
 
216
240
        separator->priv->info = panel_applet_register (GTK_WIDGET (separator),
217
 
                                                       NULL, NULL,
218
 
                                                       panel, locked, position,
219
 
                                                       TRUE,
 
241
                                                       panel,
220
242
                                                       PANEL_OBJECT_SEPARATOR,
221
 
                                                       id);
 
243
                                                       id, settings,
 
244
                                                       NULL, NULL
 
245
                                                       );
222
246
 
223
247
        if (!separator->priv->info) {
224
248
                gtk_widget_destroy (GTK_WIDGET (separator));
232
256
}
233
257
 
234
258
void
235
 
panel_separator_create (PanelToplevel *toplevel,
236
 
                        int            position)
 
259
panel_separator_create (PanelToplevel       *toplevel,
 
260
                        PanelObjectPackType  pack_type,
 
261
                        int                  pack_index)
237
262
{
238
 
        char *id;
239
 
 
240
 
        id = panel_profile_prepare_object (PANEL_OBJECT_SEPARATOR,
241
 
                                           toplevel, position, FALSE);
242
 
        panel_profile_add_to_list (PANEL_GCONF_OBJECTS, id);
243
 
        g_free (id);
 
263
        panel_layout_object_create (PANEL_OBJECT_SEPARATOR, NULL,
 
264
                                    panel_toplevel_get_id (toplevel),
 
265
                                    pack_type, pack_index);
244
266
}
245
267
 
246
268
void