view pidgin/win32/MinimizeToTray.c @ 30106:ab168cf2713e

oscar: In aim_parse_extstatus, always pass the type (always expected). Patch and valgrind log from Florian Quze, though IMHO this is not the crash also linked to (http://crash-stats.instantbird.com/report/index/57fd593b-4545-4f5b-a7b6-5fe7f2100409) ==16902== Conditional jump or move depends on uninitialised value(s) ==16902== at 0x2200BD0E: oscar_icon_req (oscar.c:6141) ==16902== by 0x21FF10E4: aim_parse_extstatus (family_oservice.c:1123) ==16902== by 0x21FF145D: snachandler (family_oservice.c:1160) ==16902== by 0x21FF725D: parse_snac (flap_connection.c:765) ==16902== by 0x21FF74F9: parse_flap (flap_connection.c:851) ==16902== by 0x21FF7867: flap_connection_recv (flap_connection.c:986) ==16902== by 0x21FF78D8: flap_connection_recv_cb_ssl (flap_connection.c:1009) ==16902== by 0x21EC33B4: recv_cb (sslconn.c:157) ==16902== by 0x21B92F78: purpleSocket::CallLibpurpleCallback() (purpleSockets.cpp:135) ==16902== by 0x21B93B68: purpleSocket::NotifyLibPurple(short) (purpleSockets.cpp:152) ==16902== by 0x5BF40A: NS_InvokeByIndex_P (xptcinvoke_unixish_x86.cpp:179) ==16902== by 0x5AC277: nsProxyObjectCallInfo::Run() (nsProxyEvent.cpp:181) ==16902== ==16902== Conditional jump or move depends on uninitialised value(s) ==16902== at 0x2200BD14: oscar_icon_req (oscar.c:6141) ==16902== by 0x21FF10E4: aim_parse_extstatus (family_oservice.c:1123) ==16902== by 0x21FF145D: snachandler (family_oservice.c:1160) ==16902== by 0x21FF725D: parse_snac (flap_connection.c:765) ==16902== by 0x21FF74F9: parse_flap (flap_connection.c:851) ==16902== by 0x21FF7867: flap_connection_recv (flap_connection.c:986) ==16902== by 0x21FF78D8: flap_connection_recv_cb_ssl (flap_connection.c:1009) ==16902== by 0x21EC33B4: recv_cb (sslconn.c:157) ==16902== by 0x21B92F78: purpleSocket::CallLibpurpleCallback() (purpleSockets.cpp:135) ==16902== by 0x21B93B68: purpleSocket::NotifyLibPurple(short) (purpleSockets.cpp:152) ==16902== by 0x5BF40A: NS_InvokeByIndex_P (xptcinvoke_unixish_x86.cpp:179) ==16902== by 0x5AC277: nsProxyObjectCallInfo::Run() (nsProxyEvent.cpp:181) ==16902== ==16902== Conditional jump or move depends on uninitialised value(s) ==16902== at 0x2200BE12: oscar_icon_req (oscar.c:6160) ==16902== by 0x21FF10E4: aim_parse_extstatus (family_oservice.c:1123) ==16902== by 0x21FF145D: snachandler (family_oservice.c:1160) ==16902== by 0x21FF725D: parse_snac (flap_connection.c:765) ==16902== by 0x21FF74F9: parse_flap (flap_connection.c:851) ==16902== by 0x21FF7867: flap_connection_recv (flap_connection.c:986) ==16902== by 0x21FF78D8: flap_connection_recv_cb_ssl (flap_connection.c:1009) ==16902== by 0x21EC33B4: recv_cb (sslconn.c:157) ==16902== by 0x21B92F78: purpleSocket::CallLibpurpleCallback() (purpleSockets.cpp:135) ==16902== by 0x21B93B68: purpleSocket::NotifyLibPurple(short) (purpleSockets.cpp:152) ==16902== by 0x5BF40A: NS_InvokeByIndex_P (xptcinvoke_unixish_x86.cpp:179) ==16902== by 0x5AC277: nsProxyObjectCallInfo::Run() (nsProxyEvent.cpp:181) ==16902== committer: Paul Aurich <paul@darkrain42.org>
author Florian Quèze <florian@instantbird.org>
date Sat, 10 Apr 2010 18:28:45 +0000
parents 5fe8042783c1
children
line wrap: on
line source

/* MinimizeToTray
 *
 * A couple of routines to show how to make it produce a custom caption
 * animation to make it look like we are minimizing to and maximizing
 * from the system tray
 *
 * These routines are public domain, but it would be nice if you dropped
 * me a line if you use them!
 *
 * 1.0 29.06.2000 Initial version
 * 1.1 01.07.2000 The window retains it's place in the Z-order of windows
 *     when minimized/hidden. This means that when restored/shown, it doesn't
 *     always appear as the foreground window unless we call SetForegroundWindow
 *
 * Copyright 2000 Matthew Ellis <m.t.ellis@bigfoot.com>
 */
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include "MinimizeToTray.h"

#define DEFAULT_RECT_WIDTH 150
#define DEFAULT_RECT_HEIGHT 30

static void GetTrayWndRect(LPRECT lpTrayRect) {
	APPBARDATA appBarData;
	HWND hShellTrayWnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"),
		NULL);

	if(hShellTrayWnd) {
		HWND hTrayNotifyWnd = FindWindowEx(hShellTrayWnd, NULL,
			TEXT("TrayNotifyWnd"), NULL);

		if(hTrayNotifyWnd) {
			GetWindowRect(hTrayNotifyWnd,lpTrayRect);
			return;
		}
	}

	appBarData.cbSize = sizeof(appBarData);
	if(SHAppBarMessage(ABM_GETTASKBARPOS, &appBarData)) {
		switch(appBarData.uEdge) {
			case ABE_LEFT:
			case ABE_RIGHT:
				lpTrayRect->top = appBarData.rc.bottom - 100;
				lpTrayRect->bottom = appBarData.rc.bottom - 16;
				lpTrayRect->left = appBarData.rc.left;
				lpTrayRect->right = appBarData.rc.right;
				break;
			case ABE_TOP:
			case ABE_BOTTOM:
				lpTrayRect->top = appBarData.rc.top;
				lpTrayRect->bottom = appBarData.rc.bottom;
				lpTrayRect->left = appBarData.rc.right - 100;
				lpTrayRect->right = appBarData.rc.right - 16;
				break;
		}
		return;
	}

	hShellTrayWnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"), NULL);
	if(hShellTrayWnd) {
		GetWindowRect(hShellTrayWnd, lpTrayRect);
		if(lpTrayRect->right-lpTrayRect->left > DEFAULT_RECT_WIDTH)
			lpTrayRect->left = lpTrayRect->right - DEFAULT_RECT_WIDTH;
		if(lpTrayRect->bottom-lpTrayRect->top > DEFAULT_RECT_HEIGHT)
			lpTrayRect->top=lpTrayRect->bottom - DEFAULT_RECT_HEIGHT;

		return;
	}

	SystemParametersInfo(SPI_GETWORKAREA, 0, lpTrayRect, 0);
	lpTrayRect->left = lpTrayRect->right - DEFAULT_RECT_WIDTH;
	lpTrayRect->top = lpTrayRect->bottom - DEFAULT_RECT_HEIGHT;
}

static BOOL GetDoAnimateMinimize(void) {
	ANIMATIONINFO ai;

	ai.cbSize = sizeof(ai);
	SystemParametersInfo(SPI_GETANIMATION, sizeof(ai), &ai, 0);

	return ai.iMinAnimate ? TRUE : FALSE;
}

void MinimizeWndToTray(HWND hWnd) {

	if(!IsWindowVisible(hWnd))
		return;

	if(GetDoAnimateMinimize()) {
		RECT rcFrom, rcTo;

		GetWindowRect(hWnd, &rcFrom);
		GetTrayWndRect(&rcTo);

		DrawAnimatedRects(hWnd, IDANI_CAPTION, &rcFrom, &rcTo);
	}

	ShowWindow(hWnd, SW_HIDE);
}

void RestoreWndFromTray(HWND hWnd) {

	if(IsWindowVisible(hWnd))
		return;

	if(GetDoAnimateMinimize()) {
		RECT rcFrom, rcTo;
		GetTrayWndRect(&rcFrom);
		GetWindowRect(hWnd, &rcTo);

		DrawAnimatedRects(hWnd, IDANI_CAPTION, &rcFrom, &rcTo);
	}

	ShowWindow(hWnd, SW_SHOW);
	SetActiveWindow(hWnd);
	SetForegroundWindow(hWnd);
}