Mercurial > pidgin
annotate finch/libgnt/wms/s.c @ 19017:e6558bae2bc6
- GnuTLS plugin now uses reference counting to manage its underlying
X.509 certificate data
author | William Ehlhardt <williamehlhardt@gmail.com> |
---|---|
date | Fri, 13 Jul 2007 08:10:33 +0000 |
parents | b8572b937c09 |
children | 6f2e068cf629 |
rev | line source |
---|---|
15817 | 1 #include <string.h> |
2 #include <sys/types.h> | |
3 | |
18210
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18118
diff
changeset
|
4 #include "internal.h" |
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18118
diff
changeset
|
5 |
15817 | 6 #include "gnt.h" |
7 #include "gntbox.h" | |
8 #include "gntmenu.h" | |
9 #include "gntstyle.h" | |
10 #include "gntwm.h" | |
11 #include "gntwindow.h" | |
12 #include "gntlabel.h" | |
13 | |
14 #include "blist.h" | |
15 | |
16 #define TYPE_S (s_get_gtype()) | |
17 | |
18 typedef struct _S | |
19 { | |
20 GntWM inherit; | |
21 } S; | |
22 | |
23 typedef struct _SClass | |
24 { | |
25 GntWMClass inherit; | |
26 } SClass; | |
27 | |
28 GType s_get_gtype(void); | |
29 void gntwm_init(GntWM **wm); | |
30 | |
31 static void (*org_new_window)(GntWM *wm, GntWidget *win); | |
32 | |
33 static void | |
34 envelope_buddylist(GntWidget *win) | |
35 { | |
36 int w, h; | |
37 gnt_widget_get_size(win, &w, &h); | |
38 wresize(win->window, h, w + 1); | |
39 mvwvline(win->window, 0, w, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL), h); | |
40 touchwin(win->window); | |
41 } | |
42 | |
43 static void | |
44 envelope_normal_window(GntWidget *win) | |
45 { | |
46 int w, h; | |
47 | |
48 if (GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_NO_BORDER | GNT_WIDGET_TRANSIENT)) | |
49 return; | |
50 | |
51 gnt_widget_get_size(win, &w, &h); | |
52 wbkgdset(win->window, ' ' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
53 mvwprintw(win->window, 0, w - 4, "[X]"); | |
54 } | |
55 | |
56 static void | |
57 s_decorate_window(GntWM *wm, GntWidget *win) | |
58 { | |
59 const char *name; | |
60 | |
61 name = gnt_widget_get_name(win); | |
62 if (name && strcmp(name, "buddylist") == 0) { | |
63 envelope_buddylist(win); | |
64 } else { | |
65 envelope_normal_window(win); | |
66 } | |
67 } | |
68 | |
69 static void | |
70 s_window_update(GntWM *wm, GntNode *node) | |
71 { | |
72 s_decorate_window(wm, node->me); | |
73 } | |
74 | |
75 static void | |
76 s_new_window(GntWM *wm, GntWidget *win) | |
77 { | |
78 int x, y, w, h; | |
79 int maxx, maxy; | |
80 const char *name; | |
81 gboolean blist = FALSE; | |
82 | |
83 if (!GNT_IS_MENU(win)) { | |
84 getmaxyx(stdscr, maxy, maxx); | |
85 | |
86 gnt_widget_get_position(win, &x, &y); | |
87 gnt_widget_get_size(win, &w, &h); | |
88 | |
89 name = gnt_widget_get_name(win); | |
90 | |
91 if (name && strcmp(name, "buddylist") == 0) { | |
92 /* The buddylist doesn't have no border nor nothing! */ | |
93 x = 0; | |
94 y = 0; | |
95 h = maxy - 1; | |
96 blist = TRUE; | |
97 | |
98 gnt_box_set_toplevel(GNT_BOX(win), FALSE); | |
99 GNT_WIDGET_SET_FLAGS(win, GNT_WIDGET_CAN_TAKE_FOCUS); | |
100 | |
101 gnt_widget_set_position(win, x, y); | |
102 mvwin(win->window, y, x); | |
103 | |
104 gnt_widget_set_size(win, -1, h + 2); /* XXX: Why is the +2 needed here? -- sadrul */ | |
105 } else if (!GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_TRANSIENT)) { | |
106 const char *title = GNT_BOX(win)->title; | |
107 if (title == NULL || !g_hash_table_lookup(wm->positions, title)) { | |
108 /* In the middle of the screen */ | |
109 x = (maxx - w) / 2; | |
110 y = (maxy - h) / 2; | |
111 | |
112 gnt_widget_set_position(win, x, y); | |
113 mvwin(win->window, y, x); | |
114 } | |
115 } | |
116 } | |
117 org_new_window(wm, win); | |
118 | |
119 if (blist) | |
120 gnt_wm_raise_window(wm, win); | |
121 } | |
122 | |
123 static GntWidget * | |
124 find_widget(GntWM *wm, const char *wname) | |
125 { | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
17705
diff
changeset
|
126 GList *iter = wm->cws->list; |
15817 | 127 for (; iter; iter = iter->next) { |
128 GntWidget *widget = iter->data; | |
129 const char *name = gnt_widget_get_name(widget); | |
130 if (name && strcmp(name, wname) == 0) { | |
131 return widget; | |
132 } | |
133 } | |
134 return NULL; | |
135 } | |
136 | |
137 static gboolean | |
138 s_mouse_clicked(GntWM *wm, GntMouseEvent event, int cx, int cy, GntWidget *widget) | |
139 { | |
140 int x, y, w, h; | |
141 | |
142 if (!widget) | |
143 return FALSE; | |
144 /* This might be a place to bring up a context menu */ | |
145 | |
146 if (event != GNT_LEFT_MOUSE_DOWN || | |
147 GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) | |
148 return FALSE; | |
149 | |
150 gnt_widget_get_position(widget, &x, &y); | |
151 gnt_widget_get_size(widget, &w, &h); | |
152 | |
153 if (cy == y && cx == x + w - 3) { | |
154 gnt_widget_destroy(widget); | |
155 return TRUE; | |
156 } | |
157 | |
158 return FALSE; | |
159 } | |
160 | |
161 static gboolean | |
162 toggle_buddylist(GntBindable *bindable, GList *null) | |
163 { | |
164 GntWM *wm = GNT_WM(bindable); | |
165 GntWidget *blist = find_widget(wm, "buddylist"); | |
166 if (blist) | |
167 gnt_widget_destroy(blist); | |
168 else | |
15822 | 169 purple_blist_show(); |
15817 | 170 return TRUE; |
171 } | |
172 | |
173 static void | |
174 s_class_init(SClass *klass) | |
175 { | |
176 GntWMClass *pclass = GNT_WM_CLASS(klass); | |
177 | |
178 org_new_window = pclass->new_window; | |
179 | |
180 pclass->new_window = s_new_window; | |
181 pclass->decorate_window = s_decorate_window; | |
182 pclass->window_update = s_window_update; | |
183 pclass->mouse_clicked = s_mouse_clicked; | |
184 | |
185 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-buddylist", | |
186 toggle_buddylist, "\033" "b", NULL); | |
187 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
188 GNTDEBUG; | |
189 } | |
190 | |
191 void gntwm_init(GntWM **wm) | |
192 { | |
193 *wm = g_object_new(TYPE_S, NULL); | |
194 } | |
195 | |
196 GType s_get_gtype(void) | |
197 { | |
198 static GType type = 0; | |
199 | |
200 if(type == 0) { | |
201 static const GTypeInfo info = { | |
202 sizeof(SClass), | |
203 NULL, /* base_init */ | |
204 NULL, /* base_finalize */ | |
205 (GClassInitFunc)s_class_init, | |
206 NULL, | |
207 NULL, /* class_data */ | |
208 sizeof(S), | |
209 0, /* n_preallocs */ | |
210 NULL, /* instance_init */ | |
211 NULL | |
212 }; | |
213 | |
214 type = g_type_register_static(GNT_TYPE_WM, | |
215 "GntS", | |
216 &info, 0); | |
217 } | |
218 | |
219 return type; | |
220 } | |
221 |