changeset 3983:a1245dcf7b31

[gaim-migrate @ 4174] Flashing window fixed to work with all Windows vers committer: Tailor Script <tailor@pidgin.im>
author Herman Bloggs <hermanator12002@yahoo.com>
date Mon, 18 Nov 2002 22:51:06 +0000
parents 156d2c2fc3d5
children e0f868943dee
files src/win32/win32dep.c
diffstat 1 files changed, 86 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/win32/win32dep.c	Mon Nov 18 22:22:30 2002 +0000
+++ b/src/win32/win32dep.c	Mon Nov 18 22:51:06 2002 +0000
@@ -8,6 +8,7 @@
 #include <windows.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <winuser.h>
 #include <glib.h>
 #include <gdk/gdkwin32.h>
 #include "gaim.h"
@@ -24,6 +25,15 @@
  */
 
 /*
+ * DATA STRUCTS
+ */
+struct _WGAIM_FLASH_INFO {
+	guint t_handle;
+	guint sig_handler;
+};
+typedef struct _WGAIM_FLASH_INFO WGAIM_FLASH_INFO;
+
+/*
  * LOCALS
  */
 static char install_dir[MAXPATHLEN];
@@ -39,9 +49,66 @@
 HINSTANCE gaimdll_hInstance = 0;
 
 /*
+ *  PROTOS
+ */
+BOOL (*MyFlashWindowEx)(PFLASHWINFO pfwi)=NULL;
+ 
+
+/*
  *  STATIC CODE
  */
 
+/* Window flasher */
+static gboolean flash_window_cb(gpointer data) {
+	FlashWindow((HWND)data, TRUE);
+	return TRUE;
+}
+
+static void halt_flash_filter(GtkWidget *widget, GdkEventFocus *event, WGAIM_FLASH_INFO *finfo) {
+	/* Stop flashing and remove filter */
+	debug_printf("Removing timeout\n");
+	gtk_timeout_remove(finfo->t_handle);
+	debug_printf("Disconnecting signal handler\n");
+	g_signal_handler_disconnect(G_OBJECT(widget),finfo->sig_handler);
+	debug_printf("done\n");
+}
+
+/* Determine whether the specified dll contains the specified procedure.
+   If so, load it (if not already loaded). */
+static FARPROC find_and_loadproc( char* dllname, char* procedure ) {
+	HMODULE hmod;
+	int did_load=0;
+	FARPROC proc = 0;
+
+	if(!(hmod=GetModuleHandle(dllname))) {
+		debug_printf("%s not found. Loading it..\n", dllname);
+		if(!(hmod = LoadLibrary(dllname))) {
+			debug_printf("Could not load: %s\n", dllname);
+			return NULL;
+		}
+		else
+			did_load = 1;
+ 	}
+
+	if((proc=GetProcAddress(hmod, procedure))) {
+		debug_printf("This version of %s contains %s\n", dllname, procedure);
+		return proc;
+	}
+	else {
+		debug_printf("Function: %s not found in dll: %s\n", procedure, dllname);
+		if(did_load) {
+			/* unload dll */
+			FreeLibrary(hmod);
+		}
+		return NULL;
+	}
+}
+
+
+void load_winver_specific_procs(void) {
+	/* Used for Win98+ and WinNT5+ */
+	MyFlashWindowEx = (void*)find_and_loadproc("user32.dll", "FlashWindowEx" );
+}
 
 
 /*
@@ -93,15 +160,25 @@
 
 /* Miscellaneous */
 
-/* FlashWindowEx is only supported by Win98+ and WinNT5+ */
+/* FlashWindowEx is only supported by Win98+ and WinNT5+. If its
+   not supported we do it our own way */
 void wgaim_im_blink(GtkWidget *window) {
-	FLASHWINFO info;
+	if(MyFlashWindowEx) {
+		FLASHWINFO info;
 
-	info.cbSize = sizeof(FLASHWINFO);
-	info.hwnd = GDK_WINDOW_HWND(window->window);
-	info.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
-	info.dwTimeout = 0;
-	FlashWindowEx(&info);
+		info.cbSize = sizeof(FLASHWINFO);
+		info.hwnd = GDK_WINDOW_HWND(window->window);
+		info.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
+		info.dwTimeout = 0;
+		MyFlashWindowEx(&info);
+	}
+	else {
+		WGAIM_FLASH_INFO *finfo = g_new0(WGAIM_FLASH_INFO, 1);
+
+		/* Start Flashing window */
+		finfo->t_handle = gtk_timeout_add(1000, flash_window_cb, GDK_WINDOW_HWND(window->window));
+		finfo->sig_handler = g_signal_connect(G_OBJECT(window), "focus-in-event", G_CALLBACK(halt_flash_filter), finfo);
+	}
 }
 
 /* Windows Initializations */
@@ -115,6 +192,8 @@
 
 	debug_printf("wgaim_init\n");
 
+	load_winver_specific_procs();
+
 	/* Initialize Wingaim systray icon */
 	wgaim_systray_init();