pidgin: adb61741: Avoid looking up functions by name that ...

datallah at pidgin.im datallah at pidgin.im
Fri Feb 19 14:55:41 EST 2010


-----------------------------------------------------------------
Revision: adb61741bcb6be653032843d5cd82714f4729d02
Ancestor: 863d08c66b1460f2569fb30822600a2008a24e45
Author: datallah at pidgin.im
Date: 2010-02-19T19:27:23
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/adb61741bcb6be653032843d5cd82714f4729d02

Modified files:
        pidgin/plugins/win32/transparency/win2ktrans.c
        pidgin/win32/gtkwin32dep.c

ChangeLog: 

Avoid looking up functions by name that will be present on all supported Windows versions.

-------------- next part --------------
============================================================
--- pidgin/plugins/win32/transparency/win2ktrans.c	d3ba36f1147cdf9c249ccfea1b32729203f55bc6
+++ pidgin/plugins/win32/transparency/win2ktrans.c	9efe0cae42a0c5881be22b93fb0c2ea1c3d69217
@@ -72,8 +72,6 @@ static GSList *window_list = NULL;
 static const char *OPT_WINTRANS_BL_ONTOP  = "/plugins/gtk/win32/wintrans/bl_always_on_top";
 static GSList *window_list = NULL;
 
-static BOOL (*MySetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags) = NULL;
-
 /*
  *  CODE
  */
@@ -81,31 +79,31 @@ static void set_wintrans(GtkWidget *wind
 /* Set window transparency level */
 static void set_wintrans(GtkWidget *window, int alpha, gboolean enabled,
 		gboolean always_on_top) {
-	if (MySetLayeredWindowAttributes) {
-		HWND hWnd = GDK_WINDOW_HWND(window->window);
-		LONG style = GetWindowLong(hWnd, GWL_EXSTYLE);
-		if (enabled) {
-			style |= WS_EX_LAYERED;
-		} else {
-			style &= ~WS_EX_LAYERED;
-		}
-		SetWindowLong(hWnd, GWL_EXSTYLE, style);
 
+	HWND hWnd = GDK_WINDOW_HWND(window->window);
+	LONG style = GetWindowLong(hWnd, GWL_EXSTYLE);
+	if (enabled) {
+		style |= WS_EX_LAYERED;
+	} else {
+		style &= ~WS_EX_LAYERED;
+	}
+	SetWindowLong(hWnd, GWL_EXSTYLE, style);
 
-		if (enabled) {
-			SetWindowPos(hWnd,
-				always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST,
-				0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
-			MySetLayeredWindowAttributes(hWnd, 0, alpha, LWA_ALPHA);
-		} else {
-			/* Ask the window and its children to repaint */
-			SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
-				SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
 
-			RedrawWindow(hWnd, NULL, NULL,
-				RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
-		}
+	if (enabled) {
+		SetWindowPos(hWnd,
+			always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST,
+			0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+		SetLayeredWindowAttributes(hWnd, 0, alpha, LWA_ALPHA);
+	} else {
+		/* Ask the window and its children to repaint */
+		SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
+			SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+
+		RedrawWindow(hWnd, NULL, NULL,
+			RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
 	}
+
 }
 
 /* When a conv window is focused, if we're only transparent when unfocused,
@@ -491,15 +489,7 @@ static gboolean plugin_load(PurplePlugin
  *  EXPORTED FUNCTIONS
  */
 static gboolean plugin_load(PurplePlugin *plugin) {
-	MySetLayeredWindowAttributes = (void*) wpurple_find_and_loadproc(
-		"user32.dll", "SetLayeredWindowAttributes");
 
-	if (!MySetLayeredWindowAttributes) {
-		purple_debug_error(WINTRANS_PLUGIN_ID,
-			"SetLayeredWindowAttributes API not found (Required W2K+)\n");
-		return FALSE;
-	}
-
 	purple_signal_connect(purple_conversations_get_handle(),
 		"conversation-created", plugin,
 		PURPLE_CALLBACK(new_conversation_cb), NULL);
============================================================
--- pidgin/win32/gtkwin32dep.c	31af4e8ef17dec6383c649cfd91d8745f219329e
+++ pidgin/win32/gtkwin32dep.c	86796839088a2c61f9ad7ac1c78cf260e9072664
@@ -47,8 +47,6 @@
 #include "zlib.h"
 #include "untar.h"
 
-#include <libintl.h>
-
 #include "gtkwin32dep.h"
 #include "win32dep.h"
 #include "gtkconv.h"
@@ -64,8 +62,6 @@ static int gtkwin32_handle;
 HWND messagewin_hwnd;
 static int gtkwin32_handle;
 
-typedef BOOL (CALLBACK* LPFNFLASHWINDOWEX)(PFLASHWINFO);
-static LPFNFLASHWINDOWEX MyFlashWindowEx = NULL;
 static gboolean pwm_handles_connections = TRUE;
 
 
@@ -308,6 +304,7 @@ winpidgin_window_flash(GtkWindow *window
 void
 winpidgin_window_flash(GtkWindow *window, gboolean flash) {
 	GdkWindow * gdkwin;
+	FLASHWINFO info;
 
 	g_return_if_fail(window != NULL);
 
@@ -319,25 +316,19 @@ winpidgin_window_flash(GtkWindow *window
 	if(GDK_WINDOW_DESTROYED(gdkwin))
 		return;
 
-	if(MyFlashWindowEx) {
-		FLASHWINFO info;
-
-		memset(&info, 0, sizeof(FLASHWINFO));
-		info.cbSize = sizeof(FLASHWINFO);
-		info.hwnd = GDK_WINDOW_HWND(gdkwin);
-		if (flash) {
-			DWORD flashCount;
-			info.uCount = 3;
-			if (SystemParametersInfo(SPI_GETFOREGROUNDFLASHCOUNT, 0, &flashCount, 0))
-				info.uCount = flashCount;
-			info.dwFlags = FLASHW_ALL | FLASHW_TIMER;
-		} else
-			info.dwFlags = FLASHW_STOP;
-		info.dwTimeout = 0;
-
-		MyFlashWindowEx(&info);
+	memset(&info, 0, sizeof(FLASHWINFO));
+	info.cbSize = sizeof(FLASHWINFO);
+	info.hwnd = GDK_WINDOW_HWND(gdkwin);
+	if (flash) {
+		DWORD flashCount;
+		info.uCount = 3;
+		if (SystemParametersInfo(SPI_GETFOREGROUNDFLASHCOUNT, 0, &flashCount, 0))
+			info.uCount = flashCount;
+		info.dwFlags = FLASHW_ALL | FLASHW_TIMER;
 	} else
-		FlashWindow(GDK_WINDOW_HWND(gdkwin), flash);
+		info.dwFlags = FLASHW_STOP;
+	info.dwTimeout = 0;
+
 }
 
 void
@@ -399,8 +390,6 @@ void winpidgin_init(HINSTANCE hint) {
 
 	messagewin_hwnd = winpidgin_message_window_init();
 
-	MyFlashWindowEx = (LPFNFLASHWINDOWEX) wpurple_find_and_loadproc("user32.dll", "FlashWindowEx");
-
 	purple_debug_info("winpidgin", "winpidgin_init end\n");
 }
 
@@ -436,36 +425,16 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, 
 	return TRUE;
 }
 
-typedef HMONITOR WINAPI _MonitorFromWindow(HWND, DWORD);
-typedef BOOL WINAPI _GetMonitorInfo(HMONITOR, LPMONITORINFO);
-
 static gboolean
 get_WorkingAreaRectForWindow(HWND hwnd, RECT *workingAreaRc) {
-	static _MonitorFromWindow *the_MonitorFromWindow;
-	static _GetMonitorInfo *the_GetMonitorInfo;
-	static gboolean initialized = FALSE;
 
 	HMONITOR monitor;
 	MONITORINFO info;
 
-	if(!initialized) {
-		the_MonitorFromWindow = (_MonitorFromWindow*)
-			wpurple_find_and_loadproc("user32", "MonitorFromWindow");
-		the_GetMonitorInfo = (_GetMonitorInfo*)
-			wpurple_find_and_loadproc("user32", "GetMonitorInfoA");
-		initialized = TRUE;
-	}
+	monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
 
-	if(!the_MonitorFromWindow)
-		return FALSE;
-
-	if(!the_GetMonitorInfo)
-		return FALSE;
-
-	monitor = the_MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
-
 	info.cbSize = sizeof(info);
-	if(!the_GetMonitorInfo(monitor, &info))
+	if(!GetMonitorInfo(monitor, &info))
 		return FALSE;
 
 	CopyRect(workingAreaRc, &(info.rcWork));


More information about the Commits mailing list