Mercurial > pidgin.yaz
annotate finch/libgnt/gntbutton.c @ 19140:7a5025b8698c
propagate from branch 'im.pidgin.pidgin' (head 007693114b23cd2711c1cb9030a148e2f63de8c8)
to branch 'im.pidgin.soc.2007.finchfeat' (head e338ac75e7034d8253e0e6b928940c27c2dcf5f0)
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 07 Jul 2007 00:41:03 +0000 |
parents | 8410511f4dbb |
children | 9f029b7208f1 |
rev | line source |
---|---|
17718
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 |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15970
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
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 |
15818 | 23 #include <string.h> |
24 | |
25 #include "gntbutton.h" | |
26 #include "gntutils.h" | |
27 | |
28 enum | |
29 { | |
30 SIGS = 1, | |
31 }; | |
32 | |
33 static GntWidgetClass *parent_class = NULL; | |
34 | |
35 static void | |
36 gnt_button_draw(GntWidget *widget) | |
37 { | |
38 GntButton *button = GNT_BUTTON(widget); | |
39 GntColorType type; | |
40 | |
41 if (gnt_widget_has_focus(widget)) | |
42 type = GNT_COLOR_HIGHLIGHT; | |
43 else | |
44 type = GNT_COLOR_NORMAL; | |
45 | |
46 wbkgdset(widget->window, '\0' | COLOR_PAIR(type)); | |
47 mvwaddstr(widget->window, 1, 2, button->priv->text); | |
48 | |
49 GNTDEBUG; | |
50 } | |
51 | |
52 static void | |
53 gnt_button_size_request(GntWidget *widget) | |
54 { | |
55 GntButton *button = GNT_BUTTON(widget); | |
56 gnt_util_get_text_bound(button->priv->text, | |
57 &widget->priv.width, &widget->priv.height); | |
58 widget->priv.width += 4; | |
59 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
60 widget->priv.height += 2; | |
61 } | |
62 | |
63 static void | |
64 gnt_button_map(GntWidget *widget) | |
65 { | |
66 if (widget->priv.width == 0 || widget->priv.height == 0) | |
67 gnt_widget_size_request(widget); | |
68 GNTDEBUG; | |
69 } | |
70 | |
71 static gboolean | |
72 gnt_button_key_pressed(GntWidget *widget, const char *key) | |
73 { | |
74 if (strcmp(key, GNT_KEY_ENTER) == 0) | |
75 { | |
76 gnt_widget_activate(widget); | |
77 return TRUE; | |
78 } | |
79 return FALSE; | |
80 } | |
81 | |
82 static gboolean | |
83 gnt_button_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
84 { | |
85 if (event == GNT_LEFT_MOUSE_DOWN) { | |
86 gnt_widget_activate(widget); | |
87 return TRUE; | |
88 } | |
89 return FALSE; | |
90 } | |
91 | |
92 static void | |
93 gnt_button_class_init(GntWidgetClass *klass) | |
94 { | |
95 parent_class = GNT_WIDGET_CLASS(klass); | |
96 parent_class->draw = gnt_button_draw; | |
97 parent_class->map = gnt_button_map; | |
98 parent_class->size_request = gnt_button_size_request; | |
99 parent_class->key_pressed = gnt_button_key_pressed; | |
100 parent_class->clicked = gnt_button_clicked; | |
101 | |
102 GNTDEBUG; | |
103 } | |
104 | |
105 static void | |
106 gnt_button_init(GTypeInstance *instance, gpointer class) | |
107 { | |
108 GntWidget *widget = GNT_WIDGET(instance); | |
109 GntButton *button = GNT_BUTTON(instance); | |
110 button->priv = g_new0(GntButtonPriv, 1); | |
111 | |
112 widget->priv.minw = 4; | |
113 widget->priv.minh = 3; | |
114 GNTDEBUG; | |
115 } | |
116 | |
117 /****************************************************************************** | |
118 * GntButton API | |
119 *****************************************************************************/ | |
120 GType | |
121 gnt_button_get_gtype(void) { | |
122 static GType type = 0; | |
123 | |
124 if(type == 0) { | |
125 static const GTypeInfo info = { | |
126 sizeof(GntButtonClass), | |
127 NULL, /* base_init */ | |
128 NULL, /* base_finalize */ | |
129 (GClassInitFunc)gnt_button_class_init, | |
130 NULL, /* class_finalize */ | |
131 NULL, /* class_data */ | |
132 sizeof(GntButton), | |
133 0, /* n_preallocs */ | |
134 gnt_button_init, /* instance_init */ | |
135 NULL /* value_table */ | |
136 }; | |
137 | |
138 type = g_type_register_static(GNT_TYPE_WIDGET, | |
139 "GntButton", | |
140 &info, 0); | |
141 } | |
142 | |
143 return type; | |
144 } | |
145 | |
146 GntWidget *gnt_button_new(const char *text) | |
147 { | |
148 GntWidget *widget = g_object_new(GNT_TYPE_BUTTON, NULL); | |
149 GntButton *button = GNT_BUTTON(widget); | |
150 | |
151 button->priv->text = gnt_util_onscreen_fit_string(text, -1); | |
152 gnt_widget_set_take_focus(widget, TRUE); | |
153 | |
154 return widget; | |
155 } | |
156 |