summaryrefslogtreecommitdiff
path: root/plugins/NewStory/src/calendartool.cpp
blob: d7c3a4bb272b86806e70a11547b0d47faffe3d9e (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
/*
Copyright (c) 2005 Victor Pavlychko (nullbyte@sotline.net.ua)
Copyright (C) 2012-24 Miranda NG team (https://miranda-ng.org)

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 version 2
of the License.

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, see <http://www.gnu.org/licenses/>.
*/

#include "stdafx.h"

INT_PTR CALLBACK CalendarToolDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		// This causes ALL miranda dialogs to have drop-shadow enabled. That's bad =(
		// SetClassLong(hwnd, GCL_STYLE, GetClassLong(hwnd, GCL_STYLE)|CS_DROPSHADOW);
		SetWindowPos(hwnd, HWND_TOP, LOWORD(lParam), HIWORD(lParam), 0, 0, SWP_NOSIZE);
		return TRUE;

	case WM_ACTIVATE:
		if (wParam == WA_INACTIVE)
			PostMessage(hwnd, WM_CLOSE, 0, 0);
		break;

	case WM_NOTIFY:
		{
			LPNMHDR hdr = (LPNMHDR)lParam;
			if ((hdr->idFrom == IDC_MONTHCALENDAR) && (hdr->code == MCN_SELECT)) {
				LPNMSELCHANGE lpnmsc = (LPNMSELCHANGE)lParam;
				struct tm tm_sel;
				tm_sel.tm_hour = tm_sel.tm_min = tm_sel.tm_sec = 0;
				tm_sel.tm_isdst = 1;
				tm_sel.tm_mday = lpnmsc->stSelStart.wDay;
				tm_sel.tm_mon = lpnmsc->stSelStart.wMonth - 1;
				tm_sel.tm_year = lpnmsc->stSelStart.wYear - 1900;
				PostMessage(GetParent(hwnd), WM_USER + 0x600, mktime(&tm_sel), 0);
				EndDialog(hwnd, 0);
			}
		}
		return TRUE;

	case WM_CLOSE:
		DestroyWindow(hwnd);
		return TRUE;
	}
	return FALSE;
}

time_t CalendarTool_Show(HWND hwnd, int x, int y)
{
	HWND hwndCalendar = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_CALENDARTOOL), hwnd, CalendarToolDlgProc, MAKELONG(x, y));
	ShowWindow(hwndCalendar, SW_SHOW);
	return 0;
}