GTK+2 panel 

GTK+2 panel Git Source Tree

Root/libgpwidgets/gpw-pager.c

1/* Gtk2Panel - A bleeding edge Gtk+2 panel
2 * Copyright (C) 2009 Nicola Fontana <ntd at entidi.it>
3 *
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.
8 *
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.
13 *
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., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20
21/**
22 * SECTION:gpw-pager
23 * @title: GpwPager
24 * @short_description: A wrapper for #WnckPager
25 *
26 * The original pager provided by libwnck does not expose its
27 * internals as properties and this limits a lot of glade customizations.
28 * This wrapper simply implements the available features as properties.
29 **/
30
31/**
32 * GpwPager:
33 *
34 * All fields are private and should not be used directly.
35 * Use its public methods instead.
36 **/
37
38
39#include "gpw-wnck.h"
40#include "gpw-pager.h"
41#include "gpw-pager-private.h"
42#include "gpw-intl.h"
43
44
45enum {
46 PROP_0,
47 PROP_ORIENTATION,
48 PROP_N_ROWS,
49 PROP_DISPLAY_MODE,
50 PROP_SHOW_ALL,
51 PROP_SHADOW_TYPE
52};
53
54
55static void get_property (GObject *object,
56 guint prop_id,
57 GValue *value,
58 GParamSpec *pspec);
59static void set_property (GObject *object,
60 guint prop_id,
61 const GValue *value,
62 GParamSpec *pspec);
63static void size_request (GtkWidget *widget,
64 GtkRequisition *requisition);
65
66
67G_DEFINE_TYPE(GpwPager, gpw_pager, WNCK_TYPE_PAGER);
68
69
70static void
71gpw_pager_class_init(GpwPagerClass *klass)
72{
73 GObjectClass *gobject_class;
74 GtkWidgetClass *widget_class;
75 GParamSpec *param;
76
77 gobject_class = (GObjectClass *) klass;
78 widget_class = (GtkWidgetClass *) klass;
79
80 g_type_class_add_private(klass, sizeof(GpwPagerPrivate));
81
82 gobject_class->get_property = get_property;
83 gobject_class->set_property = set_property;
84
85 widget_class->size_request = size_request;
86
87 param = g_param_spec_enum("orientation",
88 P_("Orientation"),
89 P_("Try to change the orientation of the layout of workspaces the pager is watching"),
90 GTK_TYPE_ORIENTATION,
91 GTK_ORIENTATION_HORIZONTAL,
92 G_PARAM_READWRITE);
93 g_object_class_install_property(gobject_class, PROP_ORIENTATION, param);
94
95 param = g_param_spec_int("n-rows",
96 P_("Number of Rows"),
97 P_("Try to change the number of rows in the layout of workspaces the pager is watching"),
98 0, G_MAXINT, 1,
99 G_PARAM_READWRITE);
100 g_object_class_install_property(gobject_class, PROP_N_ROWS, param);
101
102 param = g_param_spec_enum("display-mode",
103 P_("Display Mode"),
104 P_("Set the display mode for this pager"),
105 WNCK_TYPE_PAGER_DISPLAY_MODE,
106 WNCK_PAGER_DISPLAY_CONTENT,
107 G_PARAM_READWRITE);
108 g_object_class_install_property(gobject_class, PROP_DISPLAY_MODE, param);
109
110 param = g_param_spec_boolean("show-all",
111 P_("Show All"),
112 P_("Display all workspaces or not"),
113 TRUE,
114 G_PARAM_READWRITE);
115 g_object_class_install_property(gobject_class, PROP_SHOW_ALL, param);
116
117 param = g_param_spec_enum("shadow-type",
118 P_("Shadow Type"),
119 P_("Set the shadow type for this pager"),
120 GTK_TYPE_SHADOW_TYPE,
121 GTK_SHADOW_NONE,
122 G_PARAM_READWRITE);
123 g_object_class_install_property(gobject_class, PROP_SHADOW_TYPE, param);
124}
125
126static void
127gpw_pager_init(GpwPager *gpw_pager)
128{
129 WnckPager *pager;
130 GpwPagerPrivate *data;
131
132 pager = (WnckPager *) gpw_pager;
133 data = G_TYPE_INSTANCE_GET_PRIVATE(pager, GPW_TYPE_PAGER, GpwPagerPrivate);
134
135 data->orientation = GTK_ORIENTATION_HORIZONTAL;
136 data->n_rows = 1;
137 data->display_mode = WNCK_PAGER_DISPLAY_CONTENT;
138 data->show_all = TRUE;
139 data->shadow_type = GTK_SHADOW_NONE;
140
141 /* Force the default behaviours of the pager,
142 * as I am not sure what is their default values */
143 wnck_pager_set_orientation(pager, data->orientation);
144 wnck_pager_set_n_rows(pager, data->n_rows);
145 wnck_pager_set_display_mode(pager, data->display_mode);
146 wnck_pager_set_show_all(pager, data->show_all);
147 wnck_pager_set_shadow_type(pager, data->shadow_type);
148
149 /* Shut up the fucking pager: it does not work anyway, but at least
150 * so it stops to bother and is accettable with the default menu.
151 * TODO: find a decent solution */
152 gtk_widget_set_size_request((GtkWidget *) pager, 200, 1);
153
154 gpw_pager->data = data;
155}
156
157static void
158get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
159{
160 GpwPagerPrivate *data = GPW_PAGER_GET_DATA(object);
161
162 switch (prop_id) {
163 case PROP_ORIENTATION:
164 g_value_set_enum(value, data->orientation);
165 break;
166 case PROP_N_ROWS:
167 g_value_set_int(value, data->n_rows);
168 break;
169 case PROP_DISPLAY_MODE:
170 g_value_set_enum(value, data->display_mode);
171 break;
172 case PROP_SHOW_ALL:
173 g_value_set_boolean(value, data->show_all);
174 break;
175 case PROP_SHADOW_TYPE:
176 g_value_set_enum(value, data->shadow_type);
177 break;
178 default:
179 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
180 break;
181 }
182}
183
184static void
185set_property(GObject *object,
186 guint prop_id, const GValue *value, GParamSpec *pspec)
187{
188 WnckPager *pager = (WnckPager *) object;
189 GpwPagerPrivate *data = GPW_PAGER_GET_DATA(object);
190
191 switch (prop_id) {
192 case PROP_ORIENTATION:
193 data->orientation = g_value_get_enum(value);
194 wnck_pager_set_orientation(pager, data->orientation);
195 break;
196 case PROP_N_ROWS:
197 data->n_rows = g_value_get_int(value);
198 wnck_pager_set_n_rows(pager, data->n_rows);
199 break;
200 case PROP_DISPLAY_MODE:
201 data->display_mode = g_value_get_enum(value);
202 wnck_pager_set_display_mode(pager, data->display_mode);
203 break;
204 case PROP_SHOW_ALL:
205 data->show_all = g_value_get_boolean(value);
206 wnck_pager_set_show_all(pager, data->show_all);
207 break;
208 case PROP_SHADOW_TYPE:
209 data->shadow_type = g_value_get_enum(value);
210 wnck_pager_set_shadow_type(pager, data->shadow_type);
211 break;
212 default:
213 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
214 break;
215 }
216}
217
218static void
219size_request(GtkWidget *widget, GtkRequisition *requisition)
220{
221 if (!gtk_widget_has_screen(widget)) {
222 /* Force a dummy requisition without screen:
223 * this is happening with glade and crashes it */
224 requisition->width = 20;
225 requisition->height = 15;
226 return;
227 }
228
229 ((GtkWidgetClass *) gpw_pager_parent_class)->
230 size_request(widget, requisition);
231}

Archive Download this file

Branches

Tags