-
Notifications
You must be signed in to change notification settings - Fork 3
/
time-selector.c
122 lines (107 loc) · 3.43 KB
/
time-selector.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* This file is part of rev-browser
*
* AUTHORS
* Sven Herzberg <sven@imendio.com>
*
* Copyright (C) 2008 Sven Herzberg
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "time-selector.h"
#define FOCUS_OFFSET 2
#define HORIZONTAL_BAR_HEIGHT 9
#define VERTICAL_BAR_WIDTH 3
/* GType Implementation */
G_DEFINE_TYPE (TimeSelector, time_selector, GTK_TYPE_WIDGET);
static void
time_selector_init (TimeSelector* self)
{
GTK_WIDGET_SET_FLAGS (self, GTK_NO_WINDOW);
GTK_WIDGET_SET_FLAGS (self, GTK_CAN_FOCUS);
}
static gboolean
selector_expose_event (GtkWidget * widget,
GdkEventExpose* event)
{
GdkRectangle rectangles[] = {
/* above the eye */
{widget->allocation.x, widget->allocation.y,
widget->allocation.width, HORIZONTAL_BAR_HEIGHT},
/* below the eye */
{widget->allocation.x,
widget->allocation.y + widget->allocation.height - HORIZONTAL_BAR_HEIGHT,
widget->allocation.width, HORIZONTAL_BAR_HEIGHT},
/* left of the eye */
{widget->allocation.x, widget->allocation.y + HORIZONTAL_BAR_HEIGHT,
VERTICAL_BAR_WIDTH, widget->allocation.height - 2 * HORIZONTAL_BAR_HEIGHT},
/* right of the eye */
{widget->allocation.x + widget->allocation.width - VERTICAL_BAR_WIDTH,
widget->allocation.y + HORIZONTAL_BAR_HEIGHT,
VERTICAL_BAR_WIDTH, widget->allocation.height - 2 * HORIZONTAL_BAR_HEIGHT}
};
gsize i;
for (i = 0; i < G_N_ELEMENTS (rectangles); i++) {
gtk_paint_box (widget->style,
widget->window,
GTK_STATE_NORMAL,
GTK_SHADOW_OUT,
&rectangles[i],
widget,
NULL,
widget->allocation.x,
widget->allocation.y,
widget->allocation.width,
widget->allocation.height);
}
/* inner shadow */
gtk_paint_shadow (widget->style,
widget->window,
GTK_STATE_NORMAL,
GTK_SHADOW_IN,
&widget->allocation,
widget,
NULL,
widget->allocation.x + VERTICAL_BAR_WIDTH,
widget->allocation.y + HORIZONTAL_BAR_HEIGHT,
widget->allocation.width - 2 * VERTICAL_BAR_WIDTH,
widget->allocation.height - 2 * HORIZONTAL_BAR_HEIGHT);
if (GTK_WIDGET_HAS_FOCUS (widget)) {
gtk_paint_focus (widget->style,
widget->window,
GTK_STATE_NORMAL,
&widget->allocation,
widget,
NULL,
widget->allocation.x + FOCUS_OFFSET,
widget->allocation.y + FOCUS_OFFSET,
widget->allocation.width - 2 * FOCUS_OFFSET,
widget->allocation.height - 2 * FOCUS_OFFSET);
}
return FALSE;
}
static void
time_selector_class_init (TimeSelectorClass* self_class)
{
GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (self_class);
widget_class->expose_event = selector_expose_event;
}
/* Public API Implementation */
GtkWidget*
time_selector_new (void)
{
return g_object_new (TYPE_TIME_SELECTOR,
NULL);
}