summaryrefslogtreecommitdiff
path: root/plugins/Scriver/src/statusicon.cpp
blob: c10c0b06113445f51f31ecc99cd056976fa05527 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Scriver

Copyright 2000-2009 Miranda ICQ/IM project,

all portions of this codebase are copyrighted to the people
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "commonheaders.h"

HANDLE hHookIconPressedEvt;

void DrawStatusIcons(HANDLE hContact, HDC hDC, RECT r, int gap)
{
	HICON hIcon;
	int x = r.left;

	int nIcon = 0;
	while (StatusIconData *si = Srmm_GetNthIcon(hContact, nIcon++)) {
		if ((si->flags & MBF_DISABLED) && si->hIconDisabled) hIcon = si->hIconDisabled;
		else hIcon = si->hIcon;

		SetBkMode(hDC, TRANSPARENT);
		DrawIconEx(hDC, x, (r.top + r.bottom - GetSystemMetrics(SM_CYSMICON)) >> 1, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL);

		x += GetSystemMetrics(SM_CYSMICON) + gap;
	}
}

void CheckStatusIconClick(HANDLE hContact, HWND hwndFrom, POINT pt, RECT r, int gap, int click_flags)
{
	unsigned int iconNum = (pt.x - r.left) / (GetSystemMetrics(SM_CXSMICON) + gap);
	StatusIconData *si = Srmm_GetNthIcon(hContact, iconNum);
	if (si == NULL)
		return;

	ClientToScreen(hwndFrom, &pt);

	StatusIconClickData sicd = { sizeof(sicd) };
	sicd.clickLocation = pt;
	sicd.dwId = si->dwId;
	sicd.szModule = si->szModule;
	sicd.flags = click_flags;
	NotifyEventHooks(hHookIconPressedEvt, (WPARAM)hContact, (LPARAM)&sicd);
}

static int OnSrmmIconChanged(WPARAM wParam, LPARAM)
{
	HANDLE hContact = (HANDLE)wParam;
	if (hContact == NULL)
		WindowList_Broadcast(g_dat.hParentWindowList, DM_STATUSICONCHANGE, 0, 0);
	else {
		HWND hwnd = WindowList_Find(g_dat.hMessageWindowList, hContact);
		if (hwnd == NULL)
			hwnd = SM_FindWindowByContact(hContact);
		if (hwnd != NULL)
			PostMessage(GetParent(hwnd), DM_STATUSICONCHANGE, 0, 0);
	}
	return 0;
}

int InitStatusIcons()
{
	HookEvent(ME_MSG_ICONSCHANGED, OnSrmmIconChanged);

	hHookIconPressedEvt = CreateHookableEvent(ME_MSG_ICONPRESSED);
	return 0;
}

int DeinitStatusIcons()
{
	DestroyHookableEvent(hHookIconPressedEvt);
	return 0;
}

int GetStatusIconsCount(HANDLE hContact)
{
	int nIcon = 0;
	while ( Srmm_GetNthIcon(hContact, nIcon) != NULL)
		nIcon++;
	return nIcon;
}