summaryrefslogtreecommitdiff
path: root/plugins/Alarms/src/alarms.cpp
blob: dc7de3ca637ed3fa340ff8917a19d645b2eb0b09 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
Miranda plugin template, originally by Richard Hughes
http://miranda-icq.sourceforge.net/

This file is placed in the public domain. Anybody is free to use or
modify it as they wish with no restriction.
There is no warranty.
*/

#include "stdafx.h"
#include "alarms.h"

#define SERVICENAME L"mp"
#define COMMANDPREFIX L"/" SERVICENAME

#define WMP_PAUSE	32808
#define WMP_NEXT	0x497B

wchar_t szGamePrefix[] = COMMANDPREFIX;

CLIST_INTERFACE *pcli;
HINSTANCE hInst;
int hLangpack;

HANDLE hTopToolbarButton;

PLUGININFOEX pluginInfo = {
	sizeof(PLUGININFOEX),
	__PLUGIN_NAME,
	PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
	__DESCRIPTION,
	__AUTHOR,
	__AUTHOREMAIL,
	__COPYRIGHT,
	__AUTHORWEB,
	UNICODE_AWARE,
	// {4DD7762B-D612-4f84-AA86-068F17859B6D}
	{0x4dd7762b, 0xd612, 0x4f84, {0xaa, 0x86, 0x6, 0x8f, 0x17, 0x85, 0x9b, 0x6d}}
};

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID)
{
	hInst = hinstDLL;
	return TRUE;
}

extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
	return &pluginInfo;
}

static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
	case WM_COMMAND:
		if (HIWORD(wParam) == STN_CLICKED) { //It was a click on the Popup.
			PUDeletePopup(hWnd);
			return TRUE;
		}
		break;

	case UM_FREEPLUGINDATA:
		return TRUE;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}

void ShowPopup(MCONTACT hContact, const wchar_t *msg)
{
	if (ServiceExists(MS_POPUP_ADDPOPUPT)) {
		wchar_t *lpzContactName = (wchar_t *)pcli->pfnGetContactDisplayName(hContact, 0);

		POPUPDATAT ppd = { 0 };
		ppd.lchContact = hContact; //Be sure to use a GOOD handle, since this will not be checked.
		ppd.lchIcon = hIconList1;
		mir_wstrncpy(ppd.lptzContactName, lpzContactName, MAX_CONTACTNAME);
		mir_wstrncpy(ppd.lptzText, msg, MAX_SECONDLINE);
		ppd.colorBack = GetSysColor(COLOR_BTNFACE);
		ppd.colorText = RGB(0, 0, 0);
		ppd.PluginWindowProc = PopupDlgProc;
		ppd.PluginData = 0;
		ppd.iSeconds = 3;

		// Now that every field has been filled, we want to see the popup.
		PUAddPopupT(&ppd);
	}
}

HBITMAP LoadBmpFromIcon(int IdRes)
{
	HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IdRes));

	BITMAPINFOHEADER bih = { 0 };
	bih.biSize = sizeof(bih);
	bih.biBitCount = 24;
	bih.biPlanes = 1;
	bih.biCompression = BI_RGB;
	bih.biHeight = 16;
	bih.biWidth = 20;

	RECT rc;
	rc.top = rc.left = 0;
	rc.right = bih.biWidth;
	rc.bottom = bih.biHeight;

	HDC hdc = GetDC(NULL);
	HBITMAP hBmp = CreateCompatibleBitmap(hdc, bih.biWidth, bih.biHeight);
	HDC hdcMem = CreateCompatibleDC(hdc);
	HBITMAP hoBmp = (HBITMAP)SelectObject(hdcMem, hBmp);

	HBRUSH hBkgBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
	FillRect(hdcMem, &rc, hBkgBrush);
	DrawIconEx(hdcMem, 2, 0, hIcon, 16, 16, 0, NULL, DI_NORMAL);

	SelectObject(hdcMem, hoBmp);
	DeleteDC(hdcMem);
	ReleaseDC(NULL, hdc);
	DeleteObject(hBkgBrush);

	DeleteObject(hIcon);

	return hBmp;
}

static int InitTopToolbarButton(WPARAM, LPARAM)
{
	TTBButton ttb = { 0 };
	ttb.hIconUp = LoadIcon(hInst, MAKEINTRESOURCE(IDI_TBUP));
	ttb.hIconDn = LoadIcon(hInst, MAKEINTRESOURCE(IDI_TBDN));
	ttb.pszService = MODULE "/NewAlarm";
	ttb.dwFlags = TTBBF_VISIBLE;
	ttb.name = ttb.pszTooltipUp = LPGEN("Set alarm");
	hTopToolbarButton = TopToolbar_AddButton(&ttb);
	return 0;
}

static int MainInit(WPARAM, LPARAM)
{
	// TopToolbar support
	HookEvent(ME_TTB_MODULELOADED, InitTopToolbarButton);

	InitFrames();
	return 0;
}

static int MainDeInit(WPARAM, LPARAM)
{
	DeinitFrames();
	DeinitList();
	return 0;
}

extern "C" int __declspec(dllexport) Load(void)
{
	mir_getLP(&pluginInfo);
	pcli = Clist_GetInterface();

	// ensure datetime picker is loaded
	INITCOMMONCONTROLSEX ccx;
	ccx.dwSize = sizeof(ccx);
	ccx.dwICC = ICC_DATE_CLASSES;
	InitCommonControlsEx(&ccx);

	HookEvent(ME_SYSTEM_MODULESLOADED, MainInit);
	HookEvent(ME_SYSTEM_PRESHUTDOWN, MainDeInit);

	LoadOptions();
	InitList();

	// initialize icons
	InitIcons();

	HookEvent(ME_OPT_INITIALISE, OptInit);

	return 0;
}

extern "C" int __declspec(dllexport) Unload(void)
{
	return 0;
}