Mercurial > pidgin.yaz
comparison plugins/win32/transparency/win2ktrans.c @ 4096:72d973958607
[gaim-migrate @ 4311]
Improved prefs page, added slider option for IM windowswintransparency.c
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Thu, 19 Dec 2002 02:41:31 +0000 |
parents | 0d1d4ba2c843 |
children | e92d7712b8ba |
comparison
equal
deleted
inserted
replaced
4095:260ebd4bdc8d | 4096:72d973958607 |
---|---|
1 /* | 1 /* |
2 * win2ktrans | 2 * win2ktrans |
3 * | 3 * |
4 * copyright (c) 1998-2002, rob flynn <rob@marko.net> | 4 * copyright (c) 1998-2002, rob flynn <rob@marko.net> |
5 * | |
6 * Contributions by Herman Bloggs <hermanator12002@yahoo.com> | |
5 * | 7 * |
6 * this program is free software; you can redistribute it and/or modify | 8 * this program is free software; you can redistribute it and/or modify |
7 * it under the terms of the gnu general public license as published by | 9 * it under the terms of the gnu general public license as published by |
8 * the free software foundation; either version 2 of the license, or | 10 * the free software foundation; either version 2 of the license, or |
9 * (at your option) any later version. | 11 * (at your option) any later version. |
19 * | 21 * |
20 */ | 22 */ |
21 #define GAIM_PLUGINS | 23 #define GAIM_PLUGINS |
22 | 24 |
23 #include <gtk/gtk.h> | 25 #include <gtk/gtk.h> |
24 #include "wintransparency.h" | 26 #include <gdk/gdkwin32.h> |
27 /*#include "wintransparency.h"*/ | |
25 #include "gaim.h" | 28 #include "gaim.h" |
26 | 29 #include "win32dep.h" |
27 int alpha = 255; | 30 |
31 /* | |
32 * MACROS & DEFINES | |
33 */ | |
34 #define WINTRANS_VERSION 1 | |
35 | |
36 /* These defines aren't found in mingw's winuser.h */ | |
37 #ifndef LWA_ALPHA | |
38 #define LWA_ALPHA 0x00000002 | |
39 #endif | |
40 | |
41 #ifndef WS_EX_LAYERED | |
42 #define WS_EX_LAYERED 0x00080000 | |
43 #endif | |
44 | |
45 /* Transparency plugin configuration */ | |
46 #define OPT_WGAIM_IMTRANS 0x00000001 | |
47 #define OPT_WGAIM_SHOW_IMTRANS 0x00000002 | |
48 | |
49 /* | |
50 * GLOBALS | |
51 */ | |
52 G_MODULE_IMPORT guint im_options; | |
53 G_MODULE_IMPORT GtkWidget *all_convos; | |
54 | |
55 /* | |
56 * LOCALS | |
57 */ | |
58 static GtkWidget *slider_box=NULL; | |
59 static int imalpha = 255; | |
60 guint trans_options=0; | |
61 | |
62 /* | |
63 * PROTOS | |
64 */ | |
65 BOOL (*MySetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags)=NULL; | |
66 extern GtkWidget *gaim_button(const char*, guint*, int, GtkWidget*); | |
67 static void save_trans_prefs(); | |
68 | |
69 /* | |
70 * CODE | |
71 */ | |
72 /* Set window transparency level */ | |
73 void set_wintrans(GtkWidget *window, int trans) { | |
74 if(MySetLayeredWindowAttributes) { | |
75 HWND hWnd = GDK_WINDOW_HWND(window->window); | |
76 SetWindowLong(hWnd,GWL_EXSTYLE,GetWindowLong(hWnd,GWL_EXSTYLE) | WS_EX_LAYERED); | |
77 MySetLayeredWindowAttributes(hWnd,0,trans,LWA_ALPHA); | |
78 } | |
79 } | |
80 | |
81 static void change_im_alpha(GtkWidget *w, gpointer data) { | |
82 set_wintrans(GTK_WIDGET(data), gtk_range_get_value(GTK_RANGE(w))); | |
83 } | |
84 | |
85 int has_transparency() { | |
86 return MySetLayeredWindowAttributes ? TRUE : FALSE; | |
87 } | |
88 | |
89 GtkWidget *wintrans_slider(GtkWidget *win) { | |
90 GtkWidget *hbox; | |
91 GtkWidget *label, *slider; | |
92 GtkWidget *frame; | |
93 | |
94 frame = gtk_frame_new(NULL); | |
95 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); | |
96 gtk_widget_show(frame); | |
97 | |
98 hbox = gtk_hbox_new(FALSE, 5); | |
99 gtk_container_add(GTK_CONTAINER(frame), hbox); | |
100 | |
101 label = gtk_label_new(_("Opacity:")); | |
102 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
103 gtk_widget_show(hbox); | |
104 | |
105 slider = gtk_hscale_new_with_range(50,255,1); | |
106 gtk_range_set_value(GTK_RANGE(slider), imalpha); | |
107 gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1); | |
108 | |
109 /* On slider val change, update window's transparency level */ | |
110 gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(change_im_alpha), win); | |
111 | |
112 gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5); | |
113 | |
114 /* Set the initial transparency level */ | |
115 set_wintrans(win, imalpha); | |
116 | |
117 gtk_widget_show_all(hbox); | |
118 | |
119 return frame; | |
120 } | |
121 | |
122 static void gaim_del_conversation(char *who) { | |
123 if(!all_convos) | |
124 slider_box = NULL; | |
125 } | |
28 | 126 |
29 static void gaim_new_conversation(char *who) { | 127 static void gaim_new_conversation(char *who) { |
128 GList *wl, *wl1; | |
129 GtkWidget *vbox=NULL; | |
130 | |
30 struct conversation *c = find_conversation(who); | 131 struct conversation *c = find_conversation(who); |
31 | 132 |
32 if (!c || alpha == 255) | 133 /* Single convo window */ |
134 if((im_options & OPT_IM_ONE_WINDOW)) { | |
135 /* check prefs to see if we want trans */ | |
136 if ((trans_options & OPT_WGAIM_IMTRANS) && | |
137 (trans_options & OPT_WGAIM_SHOW_IMTRANS)) { | |
138 if(!slider_box) { | |
139 /* Get vbox which to add slider to.. */ | |
140 for ( wl1 = wl = gtk_container_children(GTK_CONTAINER(c->window)); | |
141 wl != NULL; | |
142 wl = wl->next ) { | |
143 if ( GTK_IS_VBOX(GTK_OBJECT(wl->data)) ) | |
144 vbox = GTK_WIDGET(wl->data); | |
145 else | |
146 debug_printf("no vbox found\n"); | |
147 } | |
148 g_list_free(wl1); | |
149 | |
150 slider_box = wintrans_slider(c->window); | |
151 gtk_box_pack_start(GTK_BOX(vbox), | |
152 slider_box, | |
153 FALSE, FALSE, 0); | |
154 } | |
155 } | |
156 } | |
157 /* One window per convo */ | |
158 else { | |
159 if ((trans_options & OPT_WGAIM_IMTRANS) && | |
160 (trans_options & OPT_WGAIM_SHOW_IMTRANS)) { | |
161 GtkWidget *paned; | |
162 | |
163 /* Get container which to add slider to.. */ | |
164 wl = gtk_container_children(GTK_CONTAINER(c->window)); | |
165 paned = GTK_WIDGET(wl->data); | |
166 g_list_free(wl); | |
167 wl = gtk_container_children(GTK_CONTAINER(paned)); | |
168 /* 2nd child */ | |
169 vbox = GTK_WIDGET((wl->next)->data); | |
170 g_list_free(wl); | |
171 | |
172 if(!GTK_IS_VBOX(vbox)) | |
173 debug_printf("vbox isn't a vbox widget\n"); | |
174 | |
175 gtk_box_pack_start(GTK_BOX(vbox), | |
176 wintrans_slider(c->window), | |
177 FALSE, FALSE, 0); | |
178 } | |
179 } | |
180 | |
181 if((trans_options & OPT_WGAIM_IMTRANS) && | |
182 !(trans_options & OPT_WGAIM_SHOW_IMTRANS)) { | |
183 set_wintrans(c->window, imalpha); | |
184 } | |
185 } | |
186 | |
187 static void im_alpha_change(GtkWidget *w, gpointer data) { | |
188 imalpha = gtk_range_get_value(GTK_RANGE(w)); | |
189 } | |
190 | |
191 /* Load options */ | |
192 static void load_trans_prefs() { | |
193 FILE *f; | |
194 char buf[1024]; | |
195 int ver=0; | |
196 char tag[256]; | |
197 | |
198 if (gaim_home_dir()) | |
199 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S ".gaim" G_DIR_SEPARATOR_S "wintransrc", gaim_home_dir()); | |
200 else | |
33 return; | 201 return; |
34 | 202 |
35 gdk_window_add_filter (GTK_WIDGET(c->window)->window, wgaim_window_filter, c); | 203 if ((f = fopen(buf, "r"))) { |
36 } | 204 fgets(buf, sizeof(buf), f); |
37 | 205 sscanf(buf, "# wintransrc v%d", &ver); |
206 if ((ver > 1) || (buf[0] != '#')) | |
207 return; | |
208 | |
209 while (!feof(f)) { | |
210 fgets(buf, sizeof(buf), f); | |
211 sscanf(buf, "%s {", tag); | |
212 if (strcmp(tag, "options")==0) { | |
213 fgets(buf, sizeof(buf), f); | |
214 sscanf(buf, "\ttrans_options { %d", &trans_options); | |
215 continue; | |
216 } else if (strcmp(tag, "trans")==0) { | |
217 fgets(buf, sizeof(buf), f); | |
218 sscanf(buf, "\timalpha { %d", &imalpha); | |
219 continue; | |
220 } | |
221 } | |
222 } | |
223 else | |
224 save_trans_prefs(); | |
225 } | |
226 | |
227 /* Save options */ | |
228 | |
229 static void write_options(FILE *f) { | |
230 fprintf(f, "options {\n"); | |
231 fprintf(f, "\ttrans_options { %u }\n", trans_options); | |
232 fprintf(f, "}\n"); | |
233 } | |
234 | |
235 static void write_trans(FILE *f) | |
236 { | |
237 fprintf(f, "trans {\n"); | |
238 fprintf(f, "\timalpha { %d }\n", imalpha); | |
239 fprintf(f, "}\n"); | |
240 } | |
241 | |
242 static void save_trans_prefs() { | |
243 FILE *f; | |
244 char buf[1024]; | |
245 | |
246 if (gaim_home_dir()) { | |
247 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S ".gaim" G_DIR_SEPARATOR_S "wintransrc", gaim_home_dir()); | |
248 } | |
249 else { | |
250 return; | |
251 } | |
252 | |
253 if ((f = fopen(buf, "w"))) { | |
254 fprintf(f, "# wintransrc v%d\n", WINTRANS_VERSION); | |
255 write_trans(f); | |
256 write_options(f); | |
257 fclose(f); | |
258 } | |
259 else | |
260 debug_printf("Error opening wintransrc\n"); | |
261 } | |
262 | |
263 static void set_trans_option(GtkWidget *w, int option) | |
264 { | |
265 trans_options ^= option; | |
266 save_trans_prefs(); | |
267 } | |
268 | |
269 /* | |
270 * EXPORTED FUNCTIONS | |
271 */ | |
38 | 272 |
39 G_MODULE_EXPORT char *gaim_plugin_init(GModule *handle) { | 273 G_MODULE_EXPORT char *gaim_plugin_init(GModule *handle) { |
40 | |
41 | |
42 gaim_signal_connect(handle, event_new_conversation, gaim_new_conversation, NULL); | 274 gaim_signal_connect(handle, event_new_conversation, gaim_new_conversation, NULL); |
275 gaim_signal_connect(handle, event_del_conversation, gaim_del_conversation, NULL); | |
276 MySetLayeredWindowAttributes = (void*)wgaim_find_and_loadproc("user32.dll", "SetLayeredWindowAttributes" ); | |
277 load_trans_prefs(); | |
43 | 278 |
44 return NULL; | 279 return NULL; |
45 } | 280 } |
46 | 281 |
47 G_MODULE_EXPORT void gaim_plugin_remove() { | 282 G_MODULE_EXPORT void gaim_plugin_remove() { |
65 | 300 |
66 G_MODULE_EXPORT char *description() { | 301 G_MODULE_EXPORT char *description() { |
67 return _("This plugin enables variable alpha transparency on conversation windows.\n\n* Note: This plugin requires Win2000 or WinXP."); | 302 return _("This plugin enables variable alpha transparency on conversation windows.\n\n* Note: This plugin requires Win2000 or WinXP."); |
68 } | 303 } |
69 | 304 |
70 void alpha_value_changed(GtkWidget *w, gpointer data) | |
71 { | |
72 alpha = gtk_range_get_value(GTK_RANGE(w)); | |
73 } | |
74 | |
75 G_MODULE_EXPORT GtkWidget *gaim_plugin_config_gtk() { | 305 G_MODULE_EXPORT GtkWidget *gaim_plugin_config_gtk() { |
306 GtkWidget *ret; | |
307 GtkWidget *vbox; | |
76 GtkWidget *hbox; | 308 GtkWidget *hbox; |
77 GtkWidget *label, *slider; | 309 GtkWidget *label, *slider; |
78 | 310 GtkWidget *button; |
311 GtkWidget *trans_box; | |
312 | |
313 ret = gtk_vbox_new(FALSE, 18); | |
314 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | |
315 | |
316 /* transparency options */ | |
317 vbox = make_frame (ret, _("Transparency")); | |
318 button = gaim_button(_("_IM window transparency"), &trans_options, OPT_WGAIM_IMTRANS, vbox); | |
319 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_trans_option), (int *)OPT_WGAIM_IMTRANS); | |
320 | |
321 trans_box = gtk_vbox_new(FALSE, 18); | |
322 if (!(trans_options & OPT_WGAIM_IMTRANS)) | |
323 gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE); | |
324 gtk_widget_show(trans_box); | |
325 | |
326 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive), trans_box); | |
327 | |
328 button = gaim_button(_("_Show slider bar in IM window"), &trans_options, OPT_WGAIM_SHOW_IMTRANS, trans_box); | |
329 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_trans_option), (int *)OPT_WGAIM_SHOW_IMTRANS); | |
330 | |
331 gtk_box_pack_start(GTK_BOX(vbox), trans_box, FALSE, FALSE, 5); | |
332 | |
333 /* transparency slider */ | |
79 hbox = gtk_hbox_new(FALSE, 5); | 334 hbox = gtk_hbox_new(FALSE, 5); |
80 | 335 |
81 label = gtk_label_new(_("Opacity:")); | 336 label = gtk_label_new(_("Default Opacity:")); |
82 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | 337 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
83 | 338 |
84 slider = gtk_hscale_new_with_range(50,255,1); | 339 slider = gtk_hscale_new_with_range(50,255,1); |
85 gtk_range_set_value(GTK_RANGE(slider), 255); | 340 gtk_range_set_value(GTK_RANGE(slider), imalpha); |
86 gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1); | 341 gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1); |
87 | 342 |
88 gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(alpha_value_changed), NULL); | 343 gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(im_alpha_change), NULL); |
344 gtk_signal_connect(GTK_OBJECT(slider), "focus-out-event", GTK_SIGNAL_FUNC(save_trans_prefs), NULL); | |
89 | 345 |
90 gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5); | 346 gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5); |
91 | 347 |
92 gtk_widget_show_all(hbox); | 348 gtk_widget_show_all(hbox); |
93 | 349 |
94 return hbox; | 350 gtk_box_pack_start(GTK_BOX(trans_box), hbox, FALSE, FALSE, 5); |
95 } | 351 |
352 /* If this version of Windows dosn't support Transparency, grey out options */ | |
353 if(!has_transparency()) { | |
354 gtk_widget_set_sensitive(GTK_WIDGET(vbox), FALSE); | |
355 } | |
356 | |
357 gtk_widget_show_all(ret); | |
358 return ret; | |
359 } |