-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwindowbutton.c
203 lines (169 loc) · 5.89 KB
/
windowbutton.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
*
* postfish
*
* Copyright (C) 2002-2005 Monty
*
* Postfish is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* Postfish 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Postfish; see the file COPYING. If not, write to the
* Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
*/
#include "windowbutton.h"
static GtkCheckButtonClass *parent_class = NULL;
static void draw_triangle (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
gint x,
gint y,
gint size){
GdkGC *gc=style->bg_gc[state_type];
GdkGC *light_gc=style->light_gc[state_type];
GdkGC *dark_gc=style->dark_gc[state_type];
GdkGC *black_gc=style->black_gc;
int i;
/* fill the main triangle */
for(i=0;i<size;i++)
gdk_draw_line(window,gc,x+i,y+((i)>>1),x+i,y+size-1-((i)>>1));
/* draw border */
switch(shadow_type){
case GTK_SHADOW_ETCHED_IN:
for(i=0;i<size;i++){
if(y+size-1-(i>>1) > y+(i>>1)+1){
gdk_draw_point(window,dark_gc,x+i,y+size-1-(i>>1)-1);
gdk_draw_point(window,light_gc,x+i,y+(i>>1)+1);
}
gdk_draw_point(window,light_gc,x+i,y+size-1-(i>>1));
gdk_draw_point(window,dark_gc,x+i,y+(i>>1));
}
gdk_draw_line(window,dark_gc,x,y,x,y+size-1);
gdk_draw_line(window,light_gc,x+1,y+1,x+1,y+size-2);
break;
case GTK_SHADOW_IN:
for(i=0;i<size;i++){
if(y+size-1-(i>>1) > y+(i>>1)+1)
gdk_draw_point(window,black_gc,x+i,y+(i>>1)+1);
gdk_draw_point(window,light_gc,x+i,y+size-1-(i>>1));
gdk_draw_point(window,dark_gc,x+i,y+(i>>1));
}
gdk_draw_line(window,dark_gc,x,y,x,y+size-1);
gdk_draw_line(window,black_gc,x+1,y+1,x+1,y+size-2);
break;
case GTK_SHADOW_OUT:
for(i=0;i<size;i++){
if(y+size-1-(i>>1)-1 > y+(i>>1))
gdk_draw_point(window,dark_gc,x+i,y+size-1-(i>>1)-1);
gdk_draw_point(window,light_gc,x+i,y+(i>>1));
gdk_draw_point(window,black_gc,x+i,y+size-1-(i>>1));
}
gdk_draw_line(window,light_gc,x,y,x,y+size-2);
break;
case GTK_SHADOW_NONE:
break;
case GTK_SHADOW_ETCHED_OUT:
/* unimplemented, unused */
break;
}
}
static void windowbutton_get_props (GtkCheckButton *check_button,
gint *indicator_size,
gint *indicator_spacing){
GtkWidget *widget = GTK_WIDGET (check_button);
if (indicator_size)
gtk_widget_style_get (widget, "indicator_size", indicator_size, NULL);
if (indicator_spacing)
gtk_widget_style_get (widget, "indicator_spacing", indicator_spacing, NULL);
}
static void windowbutton_draw_indicator (GtkCheckButton *check_button,
GdkRectangle *area){
GtkWidget *widget;
GtkWidget *child;
GtkButton *button;
GtkToggleButton *toggle_button;
GtkStateType state_type;
GtkShadowType shadow_type;
GtkAllocation allocation;
gint x, y;
gint indicator_size;
gint indicator_spacing;
gint focus_width;
gint focus_pad;
gboolean interior_focus;
widget = GTK_WIDGET (check_button);
if (gtk_widget_is_drawable (widget)){
button = GTK_BUTTON (check_button);
toggle_button = GTK_TOGGLE_BUTTON (check_button);
gtk_widget_style_get (widget, "interior_focus", &interior_focus,
"focus-line-width", &focus_width,
"focus-padding", &focus_pad, NULL);
windowbutton_get_props (check_button, &indicator_size,
&indicator_spacing);
gtk_widget_get_allocation(widget, &allocation);
x = allocation.x +
indicator_spacing + gtk_container_get_border_width(GTK_CONTAINER(widget));
y = allocation.y +
(allocation.height - indicator_size) / 2;
child = gtk_bin_get_child(GTK_BIN (check_button));
if (!interior_focus || !(child && gtk_widget_get_visible (child)))
x += focus_width + focus_pad;
if (gtk_toggle_button_get_inconsistent(toggle_button))
shadow_type = GTK_SHADOW_ETCHED_IN;
else if (gtk_toggle_button_get_active(toggle_button))
shadow_type = GTK_SHADOW_IN;
else
shadow_type = GTK_SHADOW_OUT;
state_type = gtk_widget_get_state(GTK_WIDGET(toggle_button));
if (state_type == GTK_STATE_INSENSITIVE) {
shadow_type = GTK_SHADOW_ETCHED_IN;
}
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
x = allocation.x + allocation.width -
(indicator_size + x - allocation.x);
draw_triangle (gtk_widget_get_style(widget), gtk_widget_get_window(widget),
state_type, shadow_type,
x, y, indicator_size);
}
}
static void windowbutton_class_init (WindowbuttonClass *class){
GtkCheckButtonClass *cb_class = (GtkCheckButtonClass*) class;
parent_class = g_type_class_peek_parent (class);
cb_class->draw_indicator = windowbutton_draw_indicator;
}
static void windowbutton_init (Windowbutton *r){
}
GType windowbutton_get_type (void){
static GType m_type = 0;
if (!m_type){
static const GTypeInfo m_info={
sizeof (WindowbuttonClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) windowbutton_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (Windowbutton),
0,
(GInstanceInitFunc) windowbutton_init,
0
};
m_type = g_type_register_static (GTK_TYPE_CHECK_BUTTON, "Windowbutton", &m_info, 0);
}
return m_type;
}
GtkWidget* windowbutton_new (char *markup){
return g_object_new (windowbutton_get_type (),
"label", markup,
"use_underline", TRUE, NULL);
}