summaryrefslogtreecommitdiff
path: root/plugins/NotesAndReminders/src/hotkeys.cpp
blob: 052e8d4dfd2d156a4202bb7f5f00ef29aa5c35b3 (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
#include "globals.h"

#define MSG_WND_CLASS "MIM_SNMsgWindow"


HWND HKHwnd;


enum KB_ACTIONS {KB_NEW_NOTE = 1, KB_TOGGLE_NOTES, KB_NEW_REMINDER};


void RegisterKeyBindings()
{
	HOTKEYDESC desc;

	memset(&desc, 0, sizeof(desc));
	desc.cbSize = sizeof(desc);
	desc.ptszSection = _T(SECTIONNAME);
	desc.dwFlags = HKD_TCHAR;

	desc.pszName = MODULENAME"/NewNote";
	desc.ptszDescription = LPGENT("New Note");
	desc.lParam = KB_NEW_NOTE;
	desc.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL|HOTKEYF_SHIFT, VK_INSERT);
	desc.pszService = MODULENAME"/MenuCommandAddNew";
	Hotkey_Register(&desc);

	desc.pszName = MODULENAME"/ToggleNotesVis";
	desc.ptszDescription = LPGENT("Toggle Notes Visibility");
	desc.lParam = KB_TOGGLE_NOTES;
	desc.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL|HOTKEYF_SHIFT, VK_ADD);
	desc.pszService = MODULENAME"/MenuCommandShowHide";
	Hotkey_Register(&desc);

	desc.pszName = MODULENAME"/BringNotesFront";
	desc.ptszDescription = LPGENT("Bring All Notes to Front");
	desc.lParam = KB_TOGGLE_NOTES;
	desc.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL|HOTKEYF_SHIFT, VK_HOME);
	desc.pszService = MODULENAME"/MenuCommandBringAllFront";
	Hotkey_Register(&desc);

	desc.pszName = MODULENAME"/NewReminder";
	desc.ptszDescription = LPGENT("New Reminder");
	desc.lParam = KB_NEW_REMINDER;
	desc.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL|HOTKEYF_SHIFT, VK_SUBTRACT);
	desc.pszService = MODULENAME"/MenuCommandNewReminder";
	Hotkey_Register(&desc);
}


/*int HandleNRShortcuts(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	STICKYNOTE* PSN;

	BOOL isShift = GetKeyState(VK_SHIFT) & 0x8000;
	BOOL isAlt = GetKeyState(VK_MENU) & 0x8000;
	BOOL isCtrl = (GetKeyState(VK_CONTROL) & 0x8000) && !isAlt;

	int action;
	MSG amsg;
	amsg.hwnd = hwnd;
	amsg.message = msg;
	amsg.wParam = wParam;
	amsg.lParam = lParam;

	switch ( (action = CallService(MS_HOTKEY_CHECK, (WPARAM)&amsg, (LPARAM)SECTIONNAME)) )
	{
	case KB_NEW_NOTE:
		PSN = NewNote(0,0,0,0,NULL,NULL,TRUE,TRUE,0);
		SetFocus(PSN->REHwnd);
		return FALSE;
	case KB_TOGGLE_NOTES:
		ShowHideNotes();
		return FALSE;
	case KB_NEW_REMINDER:
		NewReminder();
		return FALSE;
	}

	return -1;
}*/


LRESULT CALLBACK NotifyHotKeyWndProc(HWND AHwnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
	BOOL b;

	switch (Message)
	{
	case WM_TIMER:
		{
			KillTimer(HKHwnd,1026);
			b = CheckRemindersAndStart();
			SetTimer(HKHwnd,1026,b ? REMINDER_UPDATE_INTERVAL_SHORT : REMINDER_UPDATE_INTERVAL,0);

			return FALSE;
		}
	}

	return DefWindowProc(AHwnd,Message,wParam,lParam);
}

void CreateMsgWindow(void)
{
	HWND hParent = NULL;
	WNDCLASSEX TWC = {0};

	if (!GetClassInfoEx(hmiranda, MSG_WND_CLASS, &TWC))
	{
		TWC.style = 0;
		TWC.cbClsExtra = 0;
		TWC.cbWndExtra = 0;
		TWC.hInstance = hmiranda;
		TWC.hIcon = 0;
		TWC.hCursor = 0;
		TWC.hbrBackground = 0;
		TWC.lpszMenuName = NULL;
		TWC.lpszClassName = MSG_WND_CLASS;
		TWC.cbSize = sizeof(TWC);
		TWC.lpfnWndProc = NotifyHotKeyWndProc;
		RegisterClassEx(&TWC);
	}

	hParent = HWND_MESSAGE;

	HKHwnd = CreateWindowEx(WS_EX_TOOLWINDOW, MSG_WND_CLASS, "StickyNotes", 0, 0, 0, 0, 0, hParent, NULL, hmiranda, NULL);
	SetTimer(HKHwnd, 1026, REMINDER_UPDATE_INTERVAL, 0);
}

void DestroyMsgWindow(void)
{
	KillTimer(HKHwnd,1026);
	DestroyWindow(HKHwnd);
}