Mercurial > pidgin
annotate finch/libgnt/gntbutton.c @ 21165:184f5991502d
Change the ordering of the options in the system tray dropdown menu so
they're ordered high-medium-low instead of high-low-medium
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 08 Nov 2007 08:28:09 +0000 |
parents | 44b4e8bd759b |
children | 9187d331aebe |
rev | line source |
---|---|
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19295
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
22 |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
23 #include <stdlib.h> |
15817 | 24 #include <string.h> |
25 | |
26 #include "gntbutton.h" | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
27 #include "gntstyle.h" |
15817 | 28 #include "gntutils.h" |
29 | |
30 enum | |
31 { | |
32 SIGS = 1, | |
33 }; | |
34 | |
35 static GntWidgetClass *parent_class = NULL; | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
36 static gboolean small_button = FALSE; |
15817 | 37 |
38 static void | |
39 gnt_button_draw(GntWidget *widget) | |
40 { | |
41 GntButton *button = GNT_BUTTON(widget); | |
42 GntColorType type; | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
43 gboolean focus; |
15817 | 44 |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
45 if ((focus = gnt_widget_has_focus(widget))) |
15817 | 46 type = GNT_COLOR_HIGHLIGHT; |
47 else | |
48 type = GNT_COLOR_NORMAL; | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
49 |
15817 | 50 wbkgdset(widget->window, '\0' | COLOR_PAIR(type)); |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
51 mvwaddstr(widget->window, (small_button) ? 0 : 1, 2, button->priv->text); |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
52 if (small_button) { |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
53 type = GNT_COLOR_HIGHLIGHT; |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
54 mvwchgat(widget->window, 0, 0, widget->priv.width, focus ? A_BOLD : A_REVERSE, type, NULL); |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
55 } |
15817 | 56 |
57 GNTDEBUG; | |
58 } | |
59 | |
60 static void | |
61 gnt_button_size_request(GntWidget *widget) | |
62 { | |
63 GntButton *button = GNT_BUTTON(widget); | |
64 gnt_util_get_text_bound(button->priv->text, | |
65 &widget->priv.width, &widget->priv.height); | |
66 widget->priv.width += 4; | |
67 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
68 widget->priv.height += 2; | |
69 } | |
70 | |
71 static void | |
72 gnt_button_map(GntWidget *widget) | |
73 { | |
74 if (widget->priv.width == 0 || widget->priv.height == 0) | |
75 gnt_widget_size_request(widget); | |
76 GNTDEBUG; | |
77 } | |
78 | |
79 static gboolean | |
80 gnt_button_key_pressed(GntWidget *widget, const char *key) | |
81 { | |
82 if (strcmp(key, GNT_KEY_ENTER) == 0) | |
83 { | |
84 gnt_widget_activate(widget); | |
85 return TRUE; | |
86 } | |
87 return FALSE; | |
88 } | |
89 | |
90 static gboolean | |
91 gnt_button_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
92 { | |
93 if (event == GNT_LEFT_MOUSE_DOWN) { | |
94 gnt_widget_activate(widget); | |
95 return TRUE; | |
96 } | |
97 return FALSE; | |
98 } | |
99 | |
100 static void | |
101 gnt_button_class_init(GntWidgetClass *klass) | |
102 { | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
103 char *style; |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
104 |
15817 | 105 parent_class = GNT_WIDGET_CLASS(klass); |
106 parent_class->draw = gnt_button_draw; | |
107 parent_class->map = gnt_button_map; | |
108 parent_class->size_request = gnt_button_size_request; | |
109 parent_class->key_pressed = gnt_button_key_pressed; | |
110 parent_class->clicked = gnt_button_clicked; | |
111 | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
112 style = gnt_style_get_from_name(NULL, "small-button"); |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
113 small_button = gnt_style_parse_bool(style); |
19295 | 114 g_free(style); |
15817 | 115 GNTDEBUG; |
116 } | |
117 | |
118 static void | |
119 gnt_button_init(GTypeInstance *instance, gpointer class) | |
120 { | |
121 GntWidget *widget = GNT_WIDGET(instance); | |
122 GntButton *button = GNT_BUTTON(instance); | |
123 button->priv = g_new0(GntButtonPriv, 1); | |
124 | |
125 widget->priv.minw = 4; | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
126 widget->priv.minh = small_button ? 1 : 3; |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
127 if (small_button) |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
128 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); |
15817 | 129 GNTDEBUG; |
130 } | |
131 | |
132 /****************************************************************************** | |
133 * GntButton API | |
134 *****************************************************************************/ | |
135 GType | |
136 gnt_button_get_gtype(void) { | |
137 static GType type = 0; | |
138 | |
139 if(type == 0) { | |
140 static const GTypeInfo info = { | |
141 sizeof(GntButtonClass), | |
142 NULL, /* base_init */ | |
143 NULL, /* base_finalize */ | |
144 (GClassInitFunc)gnt_button_class_init, | |
145 NULL, /* class_finalize */ | |
146 NULL, /* class_data */ | |
147 sizeof(GntButton), | |
148 0, /* n_preallocs */ | |
149 gnt_button_init, /* instance_init */ | |
150 NULL /* value_table */ | |
151 }; | |
152 | |
153 type = g_type_register_static(GNT_TYPE_WIDGET, | |
154 "GntButton", | |
155 &info, 0); | |
156 } | |
157 | |
158 return type; | |
159 } | |
160 | |
161 GntWidget *gnt_button_new(const char *text) | |
162 { | |
163 GntWidget *widget = g_object_new(GNT_TYPE_BUTTON, NULL); | |
164 GntButton *button = GNT_BUTTON(widget); | |
165 | |
166 button->priv->text = gnt_util_onscreen_fit_string(text, -1); | |
167 gnt_widget_set_take_focus(widget, TRUE); | |
168 | |
169 return widget; | |
170 } | |
171 |