summaryrefslogtreecommitdiff
path: root/miranda-wine/src/modules/clist/keyboard.c
blob: d64c0b907b86e7a6b7def3650634e6c599fdea03 (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
/*

Miranda IM: the free IM client for Microsoft* Windows*

Copyright 2000-2006 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"
#include "clc.h"

static ATOM aHide = 0;
static ATOM aRead = 0;
static ATOM aSearch = 0;
static ATOM aOpts = 0;

static void WordToModAndVk(WORD w, UINT * mod, UINT * vk)
{
	*mod = 0;
	if (HIBYTE(w) & HOTKEYF_CONTROL)
		*mod |= MOD_CONTROL;
	if (HIBYTE(w) & HOTKEYF_SHIFT)
		*mod |= MOD_SHIFT;
	if (HIBYTE(w) & HOTKEYF_ALT)
		*mod |= MOD_ALT;
	if (HIBYTE(w) & HOTKEYF_EXT)
		*mod |= MOD_WIN;
	*vk = LOBYTE(w);
}

int fnHotKeysRegister(HWND hwnd)
{
	UINT mod, vk;

	if (DBGetContactSettingByte(NULL, "CList", "HKEnShowHide", 0)) {
		if (!aHide)
			aHide = GlobalAddAtomA("HKEnShowHide");
		WordToModAndVk((WORD) DBGetContactSettingWord(NULL, "CList", "HKShowHide", 0), &mod, &vk);
		RegisterHotKey(hwnd, aHide, mod, vk);
	}
	if (DBGetContactSettingByte(NULL, "CList", "HKEnReadMsg", 0)) {
		if (!aRead)
			aRead = GlobalAddAtomA("HKEnReadMsg");
		WordToModAndVk((WORD) DBGetContactSettingWord(NULL, "CList", "HKReadMsg", 0), &mod, &vk);
		RegisterHotKey(hwnd, aRead, mod, vk);
	}
	if (DBGetContactSettingByte(NULL, "CList", "HKEnNetSearch", 0)) {
		if (!aSearch)
			aSearch = GlobalAddAtomA("HKEnNetSearch");
		WordToModAndVk((WORD) DBGetContactSettingWord(NULL, "CList", "HKNetSearch", 0), &mod, &vk);
		RegisterHotKey(hwnd, aSearch, mod, vk);
	}
	if (DBGetContactSettingByte(NULL, "CList", "HKEnShowOptions", 0)) {
		if (!aOpts)
			aOpts = GlobalAddAtomA("HKEnShowOptions");
		WordToModAndVk((WORD) DBGetContactSettingWord(NULL, "CList", "HKShowOptions", 0), &mod, &vk);
		RegisterHotKey(hwnd, aOpts, mod, vk);
	}
	return 0;
}

void fnHotKeysUnregister(HWND hwnd)
{
	if (aHide) {
		UnregisterHotKey(hwnd, aHide);
		GlobalDeleteAtom(aHide);
	}
	if (aRead) {
		UnregisterHotKey(hwnd, aRead);
		GlobalDeleteAtom(aRead);
	}
	if (aSearch) {
		UnregisterHotKey(hwnd, aSearch);
		GlobalDeleteAtom(aSearch);
	}
	if (aOpts) {
		UnregisterHotKey(hwnd, aOpts);
		GlobalDeleteAtom(aOpts);
	}
}

int fnHotKeysProcess(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
	if (wParam == aHide)
		cli.pfnShowHide(0, 0);
	else if (wParam == aSearch) {
		DBVARIANT dbv;
		if (!DBGetContactSetting(NULL, "CList", "SearchUrl", &dbv)) {
			CallService(MS_UTILS_OPENURL, DBGetContactSettingByte(NULL, "CList", "HKSearchNewWnd", 0), (LPARAM) dbv.pszVal);
			DBFreeVariant( &dbv );
		}
	}
	else if (wParam == aRead) {
		if (cli.pfnEventsProcessTrayDoubleClick() == 0)
			return TRUE;
		SetForegroundWindow(hwnd);
		SetFocus(hwnd);
	}
	else if (wParam == aOpts) {
		CallService("Options/OptionsCommand", 0, 0);
	}
	return TRUE;
}

int fnHotkeysProcessMessage(WPARAM wParam, LPARAM lParam)
{
	MSG *msg = (MSG *) wParam;
	switch (msg->message) {
	case WM_CREATE:
		cli.pfnHotKeysRegister(msg->hwnd);
		break;
	case WM_HOTKEY:
		*((LRESULT *) lParam) = cli.pfnHotKeysProcess(msg->hwnd, msg->wParam, msg->lParam);
		return TRUE;
	case WM_DESTROY:
		cli.pfnHotKeysUnregister(msg->hwnd);
		break;
	}

	return FALSE;
}