changeset 4105:e92d7712b8ba

[gaim-migrate @ 4320] Buddy List now has trans options committer: Tailor Script <tailor@pidgin.im>
author Herman Bloggs <hermanator12002@yahoo.com>
date Fri, 20 Dec 2002 18:08:47 +0000
parents 1fb22bf10b4f
children a843ce9d77ea
files plugins/win32/transparency/win2ktrans.c
diffstat 1 files changed, 117 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/win32/transparency/win2ktrans.c	Fri Dec 20 04:03:43 2002 +0000
+++ b/plugins/win32/transparency/win2ktrans.c	Fri Dec 20 18:08:47 2002 +0000
@@ -24,7 +24,6 @@
 
 #include <gtk/gtk.h>
 #include <gdk/gdkwin32.h>
-/*#include "wintransparency.h"*/
 #include "gaim.h"
 #include "win32dep.h"
 
@@ -45,18 +44,22 @@
 /* Transparency plugin configuration */
 #define OPT_WGAIM_IMTRANS               0x00000001
 #define OPT_WGAIM_SHOW_IMTRANS          0x00000002
+#define OPT_WGAIM_BLTRANS               0x00000004
+#define OPT_WGAIM_BUDDYWIN_ONTOP        0x00000008
 
 /*
  *  GLOBALS
  */
 G_MODULE_IMPORT guint im_options;
 G_MODULE_IMPORT GtkWidget *all_convos;
+G_MODULE_IMPORT GtkWidget *blist;
 
 /*
  *  LOCALS
  */
 static GtkWidget *slider_box=NULL;
 static int imalpha = 255;
+static int blalpha = 255;
 guint trans_options=0;
 
 /*
@@ -78,7 +81,17 @@
 	}
 }
 
-static void change_im_alpha(GtkWidget *w, gpointer data) {
+void set_wintrans_off(GtkWidget *window) {
+	if(MySetLayeredWindowAttributes) {
+		HWND hWnd = GDK_WINDOW_HWND(window->window);
+		SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);
+		
+		/* Ask the window and its children to repaint */
+		RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
+	}
+}
+
+static void change_alpha(GtkWidget *w, gpointer data) {
 	set_wintrans(GTK_WIDGET(data), gtk_range_get_value(GTK_RANGE(w)));
 }
 
@@ -107,7 +120,7 @@
 	gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1);
 
 	/* On slider val change, update window's transparency level */
-	gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(change_im_alpha), win);
+	gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(change_alpha), win);
 
 	gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5);
 
@@ -184,8 +197,29 @@
 	}
 }
 
-static void im_alpha_change(GtkWidget *w, gpointer data) {
-	imalpha = gtk_range_get_value(GTK_RANGE(w));
+static void blist_created() {
+	if(blist) {
+		if(trans_options & OPT_WGAIM_BUDDYWIN_ONTOP)
+			SetWindowPos(GDK_WINDOW_HWND(blist->window), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+		else
+			SetWindowPos(GDK_WINDOW_HWND(blist->window), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+
+		if(trans_options & OPT_WGAIM_BLTRANS)
+			set_wintrans(blist, blalpha);
+		else
+			set_wintrans_off(blist);
+	}
+}
+
+static void alpha_change(GtkWidget *w, gpointer data) {
+	int *alpha = (int*)data;
+	*alpha = gtk_range_get_value(GTK_RANGE(w));
+}
+
+static void bl_alpha_change(GtkWidget *w, gpointer data) {
+	alpha_change(w, data);
+	if(blist)
+		change_alpha(w, blist);
 }
 
 /* Load options */
@@ -214,14 +248,22 @@
 				sscanf(buf, "\ttrans_options { %d", &trans_options);
 				continue;
 			} else if (strcmp(tag, "trans")==0) {
-				fgets(buf, sizeof(buf), f);
-				sscanf(buf, "\timalpha { %d", &imalpha);
-				continue;
+				int num;
+				for(fgets(buf, sizeof(buf), f);buf[0] != '}' && !feof(f);fgets(buf, sizeof(buf), f)) {
+					sscanf(buf, "\t%s { %d", tag, &num);
+					if(strcmp(tag, "imalpha")==0) {
+						imalpha = num;
+					}
+					else if(strcmp(tag, "blalpha")==0) {
+						blalpha = num;
+					}
+				}
 			}
 		}
 	}
 	else
 		save_trans_prefs();
+	blist_created();
 }
 
 /* Save options */
@@ -232,10 +274,10 @@
 	fprintf(f, "}\n");
 }
 
-static void write_trans(FILE *f)
-{
+static void write_trans(FILE *f) {
 	fprintf(f, "trans {\n");
 	fprintf(f, "\timalpha { %d }\n", imalpha);
+	fprintf(f, "\tblalpha { %d }\n", blalpha);
 	fprintf(f, "}\n");
 }
 
@@ -246,9 +288,8 @@
 	if (gaim_home_dir()) {
 		g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S ".gaim" G_DIR_SEPARATOR_S "wintransrc", gaim_home_dir());
 	}
-	else {
+	else
 		return;
-	}
 
 	if ((f = fopen(buf, "w"))) {
 		fprintf(f, "# wintransrc v%d\n", WINTRANS_VERSION);
@@ -260,10 +301,25 @@
 		debug_printf("Error opening wintransrc\n");
 }
 
-static void set_trans_option(GtkWidget *w, int option)
-{
+static void set_trans_option(GtkWidget *w, int option) {
 	trans_options ^= option;
 	save_trans_prefs();
+
+	if(option == OPT_WGAIM_BUDDYWIN_ONTOP) {
+		if(blist) {
+			if(trans_options & OPT_WGAIM_BUDDYWIN_ONTOP)
+				SetWindowPos(GDK_WINDOW_HWND(blist->window), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+			else
+				SetWindowPos(GDK_WINDOW_HWND(blist->window), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+		}
+	} else if(option == OPT_WGAIM_BLTRANS) {
+		if(blist) {
+			if(trans_options & OPT_WGAIM_BLTRANS)
+				set_wintrans(blist, blalpha);
+			else
+				set_wintrans_off(blist);
+		}
+	}
 }
 
 /*
@@ -273,6 +329,7 @@
 G_MODULE_EXPORT char *gaim_plugin_init(GModule *handle) {
 	gaim_signal_connect(handle, event_new_conversation, gaim_new_conversation, NULL); 
 	gaim_signal_connect(handle, event_del_conversation, gaim_del_conversation, NULL); 
+	gaim_signal_connect(handle, event_signon, blist_created, NULL);
 	MySetLayeredWindowAttributes = (void*)wgaim_find_and_loadproc("user32.dll", "SetLayeredWindowAttributes" );
 	load_trans_prefs();
 
@@ -304,7 +361,7 @@
 
 G_MODULE_EXPORT GtkWidget *gaim_plugin_config_gtk() {
 	GtkWidget *ret;
-	GtkWidget *vbox;
+	GtkWidget *imtransbox, *bltransbox;
 	GtkWidget *hbox;
 	GtkWidget *label, *slider;
 	GtkWidget *button;
@@ -313,9 +370,9 @@
 	ret = gtk_vbox_new(FALSE, 18);
 	gtk_container_set_border_width (GTK_CONTAINER (ret), 12);
 
-	/* transparency options */
-	vbox = make_frame (ret, _("Transparency"));
-	button = gaim_button(_("_IM window transparency"), &trans_options, OPT_WGAIM_IMTRANS, vbox);
+	/* IM Convo trans options */
+	imtransbox = make_frame (ret, _("IM Conversation Windows"));
+	button = gaim_button(_("_IM window transparency"), &trans_options, OPT_WGAIM_IMTRANS, imtransbox);
 	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_trans_option), (int *)OPT_WGAIM_IMTRANS);
 
 	trans_box =  gtk_vbox_new(FALSE, 18);
@@ -328,19 +385,19 @@
 	button = gaim_button(_("_Show slider bar in IM window"), &trans_options, OPT_WGAIM_SHOW_IMTRANS, trans_box);
 	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_trans_option), (int *)OPT_WGAIM_SHOW_IMTRANS);
 
-	gtk_box_pack_start(GTK_BOX(vbox), trans_box, FALSE, FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(imtransbox), trans_box, FALSE, FALSE, 5);
 
-	/* transparency slider */
+	/* IM transparency slider */
 	hbox = gtk_hbox_new(FALSE, 5);
 
-	label = gtk_label_new(_("Default Opacity:"));
+	label = gtk_label_new(_("Opacity:"));
 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
 
 	slider = gtk_hscale_new_with_range(50,255,1);
 	gtk_range_set_value(GTK_RANGE(slider), imalpha);
 	gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1);
 	
-	gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(im_alpha_change), NULL);
+	gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(alpha_change), (void*)&imalpha);
 	gtk_signal_connect(GTK_OBJECT(slider), "focus-out-event", GTK_SIGNAL_FUNC(save_trans_prefs), NULL);
 
 	gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5);
@@ -349,9 +406,46 @@
 
 	gtk_box_pack_start(GTK_BOX(trans_box), hbox, FALSE, FALSE, 5);
 	
+	/* Buddy List trans options */
+	bltransbox = make_frame (ret, _("Buddy List Window"));
+	button = gaim_button(_("_Keep Buddy List window on top"), &trans_options, OPT_WGAIM_BUDDYWIN_ONTOP, bltransbox);
+	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_trans_option), (int *)OPT_WGAIM_BUDDYWIN_ONTOP);
+
+	button = gaim_button(_("_Buddy List window transparency"), &trans_options, OPT_WGAIM_BLTRANS, bltransbox);
+	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_trans_option), (int *)OPT_WGAIM_BLTRANS);
+
+	trans_box =  gtk_vbox_new(FALSE, 18);
+	if (!(trans_options & OPT_WGAIM_BLTRANS))
+		gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE);
+	gtk_widget_show(trans_box);
+	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive),  trans_box);
+	gtk_box_pack_start(GTK_BOX(bltransbox), trans_box, FALSE, FALSE, 5);
+
+	/* IM transparency slider */
+	hbox = gtk_hbox_new(FALSE, 5);
+
+	label = gtk_label_new(_("Opacity:"));
+	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
+
+	slider = gtk_hscale_new_with_range(50,255,1);
+	gtk_range_set_value(GTK_RANGE(slider), blalpha);
+	gtk_widget_set_usize(GTK_WIDGET(slider), 200, -1);
+	
+	gtk_signal_connect(GTK_OBJECT(slider), "value-changed", GTK_SIGNAL_FUNC(bl_alpha_change), (void*)&blalpha);
+	gtk_signal_connect(GTK_OBJECT(slider), "focus-out-event", GTK_SIGNAL_FUNC(save_trans_prefs), NULL);
+
+	gtk_box_pack_start(GTK_BOX(hbox), slider, FALSE, TRUE, 5);
+
+	gtk_widget_show_all(hbox);
+
+	gtk_box_pack_start(GTK_BOX(trans_box), hbox, FALSE, FALSE, 5);
+
 	/* If this version of Windows dosn't support Transparency, grey out options */
 	if(!has_transparency()) {
-		gtk_widget_set_sensitive(GTK_WIDGET(vbox), FALSE);
+		debug_printf("This version of windows dosn't support transparency\n");
+		gtk_widget_set_sensitive(GTK_WIDGET(imtransbox), FALSE);
+		gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
+		gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE);
 	}
 
 	gtk_widget_show_all(ret);