comparison finch/libgnt/wms/s.c @ 15818:0e3a8505ebbe

renamed gaim-text to finch
author Sean Egan <seanegan@gmail.com>
date Sun, 18 Mar 2007 19:38:15 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15817:317e7613e581 15818:0e3a8505ebbe
1 #include <string.h>
2 #include <sys/types.h>
3
4 #include "gnt.h"
5 #include "gntbox.h"
6 #include "gntmenu.h"
7 #include "gntstyle.h"
8 #include "gntwm.h"
9 #include "gntwindow.h"
10 #include "gntlabel.h"
11
12 #include "blist.h"
13
14 #define TYPE_S (s_get_gtype())
15
16 typedef struct _S
17 {
18 GntWM inherit;
19 } S;
20
21 typedef struct _SClass
22 {
23 GntWMClass inherit;
24 } SClass;
25
26 GType s_get_gtype(void);
27 void gntwm_init(GntWM **wm);
28
29 static void (*org_new_window)(GntWM *wm, GntWidget *win);
30
31 static void
32 envelope_buddylist(GntWidget *win)
33 {
34 int w, h;
35 gnt_widget_get_size(win, &w, &h);
36 wresize(win->window, h, w + 1);
37 mvwvline(win->window, 0, w, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL), h);
38 touchwin(win->window);
39 }
40
41 static void
42 envelope_normal_window(GntWidget *win)
43 {
44 int w, h;
45
46 if (GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_NO_BORDER | GNT_WIDGET_TRANSIENT))
47 return;
48
49 gnt_widget_get_size(win, &w, &h);
50 wbkgdset(win->window, ' ' | COLOR_PAIR(GNT_COLOR_NORMAL));
51 mvwprintw(win->window, 0, w - 4, "[X]");
52 }
53
54 static void
55 s_decorate_window(GntWM *wm, GntWidget *win)
56 {
57 const char *name;
58
59 name = gnt_widget_get_name(win);
60 if (name && strcmp(name, "buddylist") == 0) {
61 envelope_buddylist(win);
62 } else {
63 envelope_normal_window(win);
64 }
65 }
66
67 static void
68 s_window_update(GntWM *wm, GntNode *node)
69 {
70 s_decorate_window(wm, node->me);
71 }
72
73 static void
74 s_new_window(GntWM *wm, GntWidget *win)
75 {
76 int x, y, w, h;
77 int maxx, maxy;
78 const char *name;
79 gboolean blist = FALSE;
80
81 if (!GNT_IS_MENU(win)) {
82 getmaxyx(stdscr, maxy, maxx);
83
84 gnt_widget_get_position(win, &x, &y);
85 gnt_widget_get_size(win, &w, &h);
86
87 name = gnt_widget_get_name(win);
88
89 if (name && strcmp(name, "buddylist") == 0) {
90 /* The buddylist doesn't have no border nor nothing! */
91 x = 0;
92 y = 0;
93 h = maxy - 1;
94 blist = TRUE;
95
96 gnt_box_set_toplevel(GNT_BOX(win), FALSE);
97 GNT_WIDGET_SET_FLAGS(win, GNT_WIDGET_CAN_TAKE_FOCUS);
98
99 gnt_widget_set_position(win, x, y);
100 mvwin(win->window, y, x);
101
102 gnt_widget_set_size(win, -1, h + 2); /* XXX: Why is the +2 needed here? -- sadrul */
103 } else if (!GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_TRANSIENT)) {
104 const char *title = GNT_BOX(win)->title;
105 if (title == NULL || !g_hash_table_lookup(wm->positions, title)) {
106 /* In the middle of the screen */
107 x = (maxx - w) / 2;
108 y = (maxy - h) / 2;
109
110 gnt_widget_set_position(win, x, y);
111 mvwin(win->window, y, x);
112 }
113 }
114 }
115 org_new_window(wm, win);
116
117 if (blist)
118 gnt_wm_raise_window(wm, win);
119 }
120
121 static GntWidget *
122 find_widget(GntWM *wm, const char *wname)
123 {
124 const GList *iter = wm->list;
125 for (; iter; iter = iter->next) {
126 GntWidget *widget = iter->data;
127 const char *name = gnt_widget_get_name(widget);
128 if (name && strcmp(name, wname) == 0) {
129 return widget;
130 }
131 }
132 return NULL;
133 }
134
135 static gboolean
136 s_mouse_clicked(GntWM *wm, GntMouseEvent event, int cx, int cy, GntWidget *widget)
137 {
138 int x, y, w, h;
139
140 if (!widget)
141 return FALSE;
142 /* This might be a place to bring up a context menu */
143
144 if (event != GNT_LEFT_MOUSE_DOWN ||
145 GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
146 return FALSE;
147
148 gnt_widget_get_position(widget, &x, &y);
149 gnt_widget_get_size(widget, &w, &h);
150
151 if (cy == y && cx == x + w - 3) {
152 gnt_widget_destroy(widget);
153 return TRUE;
154 }
155
156 return FALSE;
157 }
158
159 static gboolean
160 toggle_buddylist(GntBindable *bindable, GList *null)
161 {
162 GntWM *wm = GNT_WM(bindable);
163 GntWidget *blist = find_widget(wm, "buddylist");
164 if (blist)
165 gnt_widget_destroy(blist);
166 else
167 gaim_blist_show();
168 return TRUE;
169 }
170
171 static gboolean
172 toggle_clipboard(GntBindable *bindable, GList *n)
173 {
174 static GntWidget *clip;
175 gchar *text;
176 int maxx, maxy;
177 if (clip) {
178 gnt_widget_destroy(clip);
179 clip = NULL;
180 return TRUE;
181 }
182 getmaxyx(stdscr, maxy, maxx);
183 text = gnt_get_clipboard_string();
184 clip = gnt_hwindow_new(FALSE);
185 GNT_WIDGET_SET_FLAGS(clip, GNT_WIDGET_TRANSIENT);
186 GNT_WIDGET_SET_FLAGS(clip, GNT_WIDGET_NO_BORDER);
187 gnt_box_set_pad(GNT_BOX(clip), 0);
188 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(" "));
189 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(text));
190 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(" "));
191 gnt_widget_set_position(clip, 0, 0);
192 gnt_widget_draw(clip);
193 g_free(text);
194 return TRUE;
195 }
196
197 static void
198 s_class_init(SClass *klass)
199 {
200 GntWMClass *pclass = GNT_WM_CLASS(klass);
201
202 org_new_window = pclass->new_window;
203
204 pclass->new_window = s_new_window;
205 pclass->decorate_window = s_decorate_window;
206 pclass->window_update = s_window_update;
207 pclass->mouse_clicked = s_mouse_clicked;
208
209 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-buddylist",
210 toggle_buddylist, "\033" "b", NULL);
211 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-clipboard",
212 toggle_clipboard, "\033" "C", NULL);
213 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
214 GNTDEBUG;
215 }
216
217 void gntwm_init(GntWM **wm)
218 {
219 *wm = g_object_new(TYPE_S, NULL);
220 }
221
222 GType s_get_gtype(void)
223 {
224 static GType type = 0;
225
226 if(type == 0) {
227 static const GTypeInfo info = {
228 sizeof(SClass),
229 NULL, /* base_init */
230 NULL, /* base_finalize */
231 (GClassInitFunc)s_class_init,
232 NULL,
233 NULL, /* class_data */
234 sizeof(S),
235 0, /* n_preallocs */
236 NULL, /* instance_init */
237 NULL
238 };
239
240 type = g_type_register_static(GNT_TYPE_WM,
241 "GntS",
242 &info, 0);
243 }
244
245 return type;
246 }
247