comparison plugins/win32/transparency/win2ktrans.c @ 9840:e8caffe42e38

[gaim-migrate @ 10717] See le ChangeLog.win32 committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 23 Aug 2004 21:59:27 +0000
parents d9a1674a9475
children 0ddc84d81eac
comparison
equal deleted inserted replaced
9839:96e98bb4ded5 9840:e8caffe42e38
70 static const char *OPT_WINTRANS_IM_SLIDER ="/plugins/gtk/win32/wintrans/im_slider"; 70 static const char *OPT_WINTRANS_IM_SLIDER ="/plugins/gtk/win32/wintrans/im_slider";
71 static const char *OPT_WINTRANS_BL_ENABLED="/plugins/gtk/win32/wintrans/bl_enabled"; 71 static const char *OPT_WINTRANS_BL_ENABLED="/plugins/gtk/win32/wintrans/bl_enabled";
72 static const char *OPT_WINTRANS_BL_ALPHA ="/plugins/gtk/win32/wintrans/bl_alpha"; 72 static const char *OPT_WINTRANS_BL_ALPHA ="/plugins/gtk/win32/wintrans/bl_alpha";
73 static int imalpha = 255; 73 static int imalpha = 255;
74 static int blalpha = 255; 74 static int blalpha = 255;
75 GList *window_list = NULL; 75 static GList *window_list = NULL;
76 76
77 /* 77 /*
78 * PROTOS 78 * PROTOS
79 */ 79 */
80 BOOL (*MySetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags)=NULL; 80 BOOL (*MySetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags)=NULL;
90 gtk_widget_show(button); 90 gtk_widget_show(button);
91 return button; 91 return button;
92 } 92 }
93 93
94 /* Set window transparency level */ 94 /* Set window transparency level */
95 void set_wintrans(GtkWidget *window, int trans) { 95 static void set_wintrans(GtkWidget *window, int trans) {
96 if(MySetLayeredWindowAttributes) { 96 if(MySetLayeredWindowAttributes) {
97 HWND hWnd = GDK_WINDOW_HWND(window->window); 97 HWND hWnd = GDK_WINDOW_HWND(window->window);
98 SetWindowLong(hWnd,GWL_EXSTYLE,GetWindowLong(hWnd,GWL_EXSTYLE) | WS_EX_LAYERED); 98 SetWindowLong(hWnd,GWL_EXSTYLE,GetWindowLong(hWnd,GWL_EXSTYLE) | WS_EX_LAYERED);
99 MySetLayeredWindowAttributes(hWnd,0,trans,LWA_ALPHA); 99 MySetLayeredWindowAttributes(hWnd,0,trans,LWA_ALPHA);
100 } 100 }
101 } 101 }
102 102
103 void set_wintrans_off(GtkWidget *window) { 103 static void set_wintrans_off(GtkWidget *window) {
104 if(MySetLayeredWindowAttributes) { 104 if(MySetLayeredWindowAttributes) {
105 HWND hWnd = GDK_WINDOW_HWND(window->window); 105 HWND hWnd = GDK_WINDOW_HWND(window->window);
106 SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) & ~WS_EX_LAYERED); 106 SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);
107 107
108 /* Ask the window and its children to repaint */ 108 /* Ask the window and its children to repaint */
112 112
113 static void change_alpha(GtkWidget *w, gpointer data) { 113 static void change_alpha(GtkWidget *w, gpointer data) {
114 set_wintrans(GTK_WIDGET(data), gtk_range_get_value(GTK_RANGE(w))); 114 set_wintrans(GTK_WIDGET(data), gtk_range_get_value(GTK_RANGE(w)));
115 } 115 }
116 116
117 int has_transparency() { 117 static int has_transparency() {
118 return MySetLayeredWindowAttributes ? TRUE : FALSE; 118 return MySetLayeredWindowAttributes ? TRUE : FALSE;
119 } 119 }
120 120
121 GtkWidget *wintrans_slider(GtkWidget *win) { 121 static GtkWidget *wintrans_slider(GtkWidget *win) {
122 GtkWidget *hbox; 122 GtkWidget *hbox;
123 GtkWidget *label, *slider; 123 GtkWidget *label, *slider;
124 GtkWidget *frame; 124 GtkWidget *frame;
125 125
126 frame = gtk_frame_new(NULL); 126 frame = gtk_frame_new(NULL);
160 tmp = tmp->next; 160 tmp = tmp->next;
161 } 161 }
162 return NULL; 162 return NULL;
163 } 163 }
164 164
165 gboolean win_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) { 165 static gboolean win_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) {
166 slider_win *slidwin=NULL; 166 slider_win *slidwin=NULL;
167 /* Remove window from the window list */ 167 /* Remove window from the window list */
168 gaim_debug_info(WINTRANS_PLUGIN_ID, "Conv window destoyed.. removing from list\n"); 168 gaim_debug_info(WINTRANS_PLUGIN_ID, "Conv window destoyed.. removing from list\n");
169 169
170 if((slidwin=find_slidwin(widget))) { 170 if((slidwin=find_slidwin(widget))) {
225 static void remove_sliders() { 225 static void remove_sliders() {
226 if(window_list) { 226 if(window_list) {
227 GList *tmp=window_list; 227 GList *tmp=window_list;
228 while(tmp) { 228 while(tmp) {
229 slider_win *slidwin = (slider_win*)tmp->data; 229 slider_win *slidwin = (slider_win*)tmp->data;
230 gtk_widget_destroy(slidwin->slider); 230 if (slidwin != NULL && GTK_IS_WINDOW(slidwin->win))
231 gtk_widget_destroy(slidwin->slider);
231 g_free(slidwin); 232 g_free(slidwin);
232 tmp=tmp->next; 233 tmp=tmp->next;
233 } 234 }
234 g_list_free(window_list); 235 g_list_free(window_list);
235 window_list = NULL; 236 window_list = NULL;
292 set_wintrans_off(blist); 293 set_wintrans_off(blist);
293 } 294 }
294 } 295 }
295 296
296 static void alpha_change(GtkWidget *w, gpointer data) { 297 static void alpha_change(GtkWidget *w, gpointer data) {
297 int *alpha = (int*)data;
298 GList *conv; 298 GList *conv;
299 *alpha = gtk_range_get_value(GTK_RANGE(w)); 299 imalpha = gtk_range_get_value(GTK_RANGE(w));
300 300
301 for(conv = gaim_get_conversations(); conv != NULL; conv = conv->next) 301 for(conv = gaim_get_conversations(); conv != NULL; conv = conv->next)
302 set_wintrans(GAIM_GTK_WINDOW(gaim_conversation_get_window(conv->data))->window, *alpha); 302 set_wintrans(GAIM_GTK_WINDOW(gaim_conversation_get_window(conv->data))->window, imalpha);
303 } 303 }
304 304
305 static void alpha_pref_set_int(GtkWidget *w, GdkEventFocus *e, const char *pref) { 305 static void alpha_pref_set_int(GtkWidget *w, GdkEventFocus *e, const char *pref)
306 int alpha = 0; 306 {
307 if (pref == OPT_WINTRANS_IM_ALPHA) 307 if (pref == OPT_WINTRANS_IM_ALPHA)
308 alpha = imalpha; 308 gaim_prefs_set_int(pref, imalpha);
309 else if (pref == OPT_WINTRANS_BL_ALPHA) 309 else if (pref == OPT_WINTRANS_BL_ALPHA)
310 alpha = blalpha; 310 gaim_prefs_set_int(pref, blalpha);
311
312 gaim_prefs_set_int(pref, alpha);
313 } 311 }
314 312
315 static void bl_alpha_change(GtkWidget *w, gpointer data) { 313 static void bl_alpha_change(GtkWidget *w, gpointer data) {
314 blalpha = gtk_range_get_value(GTK_RANGE(w));
316 if(blist) 315 if(blist)
317 change_alpha(w, blist); 316 change_alpha(w, blist);
318 } 317 }
319 318
320 /* 319 /*
321 * EXPORTED FUNCTIONS 320 * EXPORTED FUNCTIONS
322 */ 321 */
323 G_MODULE_EXPORT gboolean plugin_load(GaimPlugin *plugin) { 322 gboolean plugin_load(GaimPlugin *plugin) {
324 imalpha = gaim_prefs_get_int(OPT_WINTRANS_IM_ALPHA); 323 imalpha = gaim_prefs_get_int(OPT_WINTRANS_IM_ALPHA);
325 blalpha = gaim_prefs_get_int(OPT_WINTRANS_BL_ALPHA); 324 blalpha = gaim_prefs_get_int(OPT_WINTRANS_BL_ALPHA);
326 325
327 gaim_signal_connect((void*)gaim_conversations_get_handle(), 326 gaim_signal_connect((void*)gaim_conversations_get_handle(),
328 "conversation-created", 327 "conversation-created",
329 plugin, 328 plugin,
330 GAIM_CALLBACK(gaim_new_conversation), 329 GAIM_CALLBACK(gaim_new_conversation),
331 NULL); 330 NULL);
332 gaim_signal_connect((void*)gaim_connections_get_handle(), "signed-on", plugin, GAIM_CALLBACK(blist_created), NULL); 331 gaim_signal_connect((void*)gaim_connections_get_handle(), "signed-on", plugin, GAIM_CALLBACK(blist_created), NULL);
333 MySetLayeredWindowAttributes = (void*)wgaim_find_and_loadproc("user32.dll", "SetLayeredWindowAttributes" ); 332 MySetLayeredWindowAttributes = (void*)wgaim_find_and_loadproc("user32.dll", "SetLayeredWindowAttributes" );
334 333
335 gaim_signal_connect((void*)gaim_gtk_conversations_get_handle(), "conversation-drag-ended", plugin, GAIM_CALLBACK(set_window_trans), NULL); 334 gaim_signal_connect((void*)gaim_gtk_conversations_get_handle(), "conversation-drag-ended", plugin, GAIM_CALLBACK(set_window_trans), NULL);
336 335
337 update_convs_wintrans(NULL, NULL); 336 update_convs_wintrans(NULL, NULL);
338 337
339 if(blist) { 338 if(blist)
340 blist_created(); 339 blist_created();
341 }
342 340
343 return TRUE; 341 return TRUE;
344 } 342 }
345 343
346 G_MODULE_EXPORT gboolean plugin_unload(GaimPlugin *plugin) { 344 gboolean plugin_unload(GaimPlugin *plugin) {
347 gaim_debug_info(WINTRANS_PLUGIN_ID, "Removing win2ktrans.dll plugin\n"); 345 gaim_debug_info(WINTRANS_PLUGIN_ID, "Removing win2ktrans.dll plugin\n");
348 346
349 remove_convs_wintrans(); 347 remove_convs_wintrans();
350 348 remove_sliders();
351 if(blist) { 349
350 if(blist)
352 set_wintrans_off(blist); 351 set_wintrans_off(blist);
353 } 352
354 return TRUE; 353 return TRUE;
355 } 354 }
356 355
357 G_MODULE_EXPORT GtkWidget *get_config_frame(GaimPlugin *plugin) { 356 GtkWidget *get_config_frame(GaimPlugin *plugin) {
358 GtkWidget *ret; 357 GtkWidget *ret;
359 GtkWidget *imtransbox, *bltransbox; 358 GtkWidget *imtransbox, *bltransbox;
360 GtkWidget *hbox; 359 GtkWidget *hbox;
361 GtkWidget *label, *slider; 360 GtkWidget *label, *slider;
362 GtkWidget *button; 361 GtkWidget *button;
374 if (!gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)) 373 if (!gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED))
375 gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE); 374 gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE);
376 gtk_widget_show(trans_box); 375 gtk_widget_show(trans_box);
377 376
378 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gaim_gtk_toggle_sensitive), trans_box); 377 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gaim_gtk_toggle_sensitive), trans_box);
379 378
380 button = wgaim_button(_("_Show slider bar in IM window"), OPT_WINTRANS_IM_SLIDER, trans_box); 379 button = wgaim_button(_("_Show slider bar in IM window"), OPT_WINTRANS_IM_SLIDER, trans_box);
381 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(update_convs_wintrans), (void *)OPT_WINTRANS_IM_SLIDER); 380 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(update_convs_wintrans), (void *)OPT_WINTRANS_IM_SLIDER);
382 381
383 gtk_box_pack_start(GTK_BOX(imtransbox), trans_box, FALSE, FALSE, 5); 382 gtk_box_pack_start(GTK_BOX(imtransbox), trans_box, FALSE, FALSE, 5);
384 383
389 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); 388 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
390 389
391 slider = gtk_hscale_new_with_range(50,255,1); 390 slider = gtk_hscale_new_with_range(50,255,1);
392 gtk_range_set_value(GTK_RANGE(slider), imalpha); 391 gtk_range_set_value(GTK_RANGE(slider), imalpha);
393 gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1); 392 gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1);
394 393
395 gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(alpha_change), (void*)&imalpha); 394 gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(alpha_change), NULL);
396 gtk_signal_connect(GTK_OBJECT(slider), "focus-out-event", GTK_SIGNAL_FUNC(alpha_pref_set_int), (void *)OPT_WINTRANS_IM_ALPHA); 395 gtk_signal_connect(GTK_OBJECT(slider), "focus-out-event", GTK_SIGNAL_FUNC(alpha_pref_set_int), (void *)OPT_WINTRANS_IM_ALPHA);
397 396
398 gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5); 397 gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5);
399 398
400 gtk_widget_show_all(hbox); 399 gtk_widget_show_all(hbox);
401 400
402 gtk_box_pack_start(GTK_BOX(trans_box), hbox, FALSE, FALSE, 5); 401 gtk_box_pack_start(GTK_BOX(trans_box), hbox, FALSE, FALSE, 5);
403 402
404 /* Buddy List trans options */ 403 /* Buddy List trans options */
405 bltransbox = gaim_gtk_make_frame (ret, _("Buddy List Window")); 404 bltransbox = gaim_gtk_make_frame (ret, _("Buddy List Window"));
406 button = wgaim_button(_("_Buddy List window transparency"), OPT_WINTRANS_BL_ENABLED, bltransbox); 405 button = wgaim_button(_("_Buddy List window transparency"), OPT_WINTRANS_BL_ENABLED, bltransbox);
407 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_trans_option), (void *)OPT_WINTRANS_BL_ENABLED); 406 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_trans_option), (void *)OPT_WINTRANS_BL_ENABLED);
408 407
420 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); 419 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
421 420
422 slider = gtk_hscale_new_with_range(50,255,1); 421 slider = gtk_hscale_new_with_range(50,255,1);
423 gtk_range_set_value(GTK_RANGE(slider), blalpha); 422 gtk_range_set_value(GTK_RANGE(slider), blalpha);
424 gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1); 423 gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1);
425 424
426 gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(bl_alpha_change), (void*)&blalpha); 425 gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(bl_alpha_change), NULL);
427 gtk_signal_connect(GTK_OBJECT(slider), "focus-out-event", GTK_SIGNAL_FUNC(alpha_pref_set_int), (void *)OPT_WINTRANS_BL_ALPHA); 426 gtk_signal_connect(GTK_OBJECT(slider), "focus-out-event", GTK_SIGNAL_FUNC(alpha_pref_set_int), (void *)OPT_WINTRANS_BL_ALPHA);
428 427
429 gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5); 428 gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5);
430 429
431 gtk_widget_show_all(hbox); 430 gtk_widget_show_all(hbox);
480 }; 479 };
481 480
482 static void 481 static void
483 init_plugin(GaimPlugin *plugin) 482 init_plugin(GaimPlugin *plugin)
484 { 483 {
485 gaim_prefs_add_none("/plugins/gtk/win32"); 484 gaim_prefs_add_none("/plugins/gtk/win32");
486 gaim_prefs_add_none("/plugins/gtk/win32/wintrans"); 485 gaim_prefs_add_none("/plugins/gtk/win32/wintrans");
487 gaim_prefs_add_bool("/plugins/gtk/win32/wintrans/im_enabled", FALSE); 486 gaim_prefs_add_bool("/plugins/gtk/win32/wintrans/im_enabled", FALSE);
488 gaim_prefs_add_int("/plugins/gtk/win32/wintrans/im_alpha", 255); 487 gaim_prefs_add_int("/plugins/gtk/win32/wintrans/im_alpha", 255);
489 gaim_prefs_add_bool("/plugins/gtk/win32/wintrans/im_slider", FALSE); 488 gaim_prefs_add_bool("/plugins/gtk/win32/wintrans/im_slider", FALSE);
490 gaim_prefs_add_bool("/plugins/gtk/win32/wintrans/bl_enabled", FALSE); 489 gaim_prefs_add_bool("/plugins/gtk/win32/wintrans/bl_enabled", FALSE);
491 gaim_prefs_add_int("/plugins/gtk/win32/wintrans/bl_alpha", 255); 490 gaim_prefs_add_int("/plugins/gtk/win32/wintrans/bl_alpha", 255);
492 } 491 }
493 492
494 GAIM_INIT_PLUGIN(wintrans, init_plugin, info) 493 GAIM_INIT_PLUGIN(wintrans, init_plugin, info)