summaryrefslogtreecommitdiff
path: root/plugins/TopToolBar/InternalButtons.cpp
blob: 5e2413f5d0ec3e1b80bb9e234ff9bf44cb0c717a (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

#include "common.h"
#pragma hdrstop

#define TTBI_GROUPSHOWHIDE				"TTBInternal/GroupShowHide"
#define TTBI_SOUNDSONOFF					"TTBInternal/SoundsOnOFF"
#define TTBI_MAINMENUBUTT					"TTBInternal/MainMenuBUTT"

int LoadInternalButtons( HWND );
int UnLoadInternalButtons();
extern HINSTANCE hInst;

HANDLE hSettingChangedHook;

static int ShowOnline, ShowGroups, SoundsEnabled;
static HANDLE hOnlineBut, hGroupBut, hSoundsBut, hOptionsBut, hMainMenuBut;
static HANDLE hMinimizeBut;
static HANDLE hFindUsers;

static HANDLE OnSettingChg;

static HWND hwndContactTree;

int OnSettingChanging(WPARAM wParam, LPARAM lParam)
{
	if (wParam != 0)
		return 0;
	
	DBCONTACTWRITESETTING *dbcws = (DBCONTACTWRITESETTING *)lParam;
	if (dbcws == NULL)
		return 0;

	if ( !strcmp(dbcws->szModule, "CList")) {
		if ( !strcmp(dbcws->szSetting, "HideOffline")) {
			int val = dbcws->value.bVal;

			CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hOnlineBut, (LPARAM)(val)?TTBST_PUSHED:TTBST_RELEASED);		

			CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hOnlineBut), 
				(LPARAM)((!val)?Translate("Hide Offline Users"):Translate("Show All Users")));

			return 0;
		}

		if (!strcmp(dbcws->szSetting, "UseGroups")) {
			int val = dbcws->value.bVal;
			CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hGroupBut, (LPARAM)((val)?TTBST_PUSHED:TTBST_RELEASED));
			return 0;
		}
	}

	if (!strcmp(dbcws->szModule, "Skin")) {
		if (!strcmp(dbcws->szSetting, "UseSound")) {
			int val = dbcws->value.bVal;
			CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hSoundsBut, (LPARAM)(val)?TTBST_PUSHED:TTBST_RELEASED);		
			return 0;
		}
	}

	return 0;
}

INT_PTR TTBInternalMainMenuButt(WPARAM wParam, LPARAM lParam)
{
	HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUGETMAIN, 0, 0);

	POINT pt;
	GetCursorPos(&pt);
	TrackPopupMenu(hMenu, TPM_TOPALIGN|TPM_LEFTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, 0, (HWND)CallService(MS_CLUI_GETHWND, 0, 0), NULL);	
	
	return 0;
}

INT_PTR TTBInternalGroupShowHide(WPARAM wParam, LPARAM lParam)
{
	int newVal = !(GetWindowLongPtr(hwndContactTree, GWL_STYLE)&CLS_USEGROUPS);
	DBWriteContactSettingByte(NULL, "CList", "UseGroups", (BYTE)newVal);
	SendMessage(hwndContactTree, CLM_SETUSEGROUPS, newVal, 0);
	return 0;
}

INT_PTR TTBInternalSoundsOnOff(WPARAM wParam, LPARAM lParam)
{
	int newVal = !(DBGetContactSettingByte(NULL, "Skin", "UseSound", 1));
	DBWriteContactSettingByte(NULL, "Skin", "UseSound", (BYTE)newVal);
	CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hSoundsBut), 
		(LPARAM)((newVal)?Translate("Disable Sounds"):Translate("Enable Sounds")));
	return 0;
}

int UnLoadInternalButtons()
{
	if (hSettingChangedHook)
		UnhookEvent(hSettingChangedHook);
	return 0;
}

int LoadInternalButtons(HWND hwnd)
{
	hwndContactTree = hwnd;
	hSettingChangedHook = 0;
	arServices.insert( CreateServiceFunction(TTBI_GROUPSHOWHIDE, TTBInternalGroupShowHide));
	arServices.insert( CreateServiceFunction(TTBI_SOUNDSONOFF, TTBInternalSoundsOnOff));

	arServices.insert( CreateServiceFunction(TTBI_MAINMENUBUTT, TTBInternalMainMenuButt));

	ShowOnline = DBGetContactSettingByte(NULL, "CList", "HideOffline", 0);
	ShowGroups = DBGetContactSettingByte(NULL, "CList", "UseGroups", 2);
	SoundsEnabled = DBGetContactSettingByte(NULL, "Skin", "UseSound", 1);

	TTBButton ttb = { 0 };
	ttb.cbSize = sizeof(ttb);
	ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_SHOWONLINEUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_SHOWONLINEDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.dwFlags = (ShowOnline?TTBBF_PUSHED:0)|TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP|TTBBF_ASPUSHBUTTON;
	ttb.pszService = MS_CLIST_SETHIDEOFFLINE;
	ttb.wParamUp = ttb.wParamDown = -1;
	ttb.name = "Show only Online Users";
	hOnlineBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);

	ttb.wParamUp = ttb.wParamDown = 0;

	ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_GROUPSUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_GROUPSDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.dwFlags = (ShowGroups?TTBBF_PUSHED:0)|TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP|TTBBF_ASPUSHBUTTON;
	ttb.pszService = TTBI_GROUPSHOWHIDE;
	ttb.name = "Groups On/Off";
	hGroupBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);

	ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_SOUNDUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_SOUNDDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.dwFlags = (SoundsEnabled?TTBBF_PUSHED:0)|TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP|TTBBF_ASPUSHBUTTON;
	ttb.pszService = TTBI_SOUNDSONOFF;
	ttb.name = "Sounds Enable/Disable";
	hSoundsBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);

	ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_OPTIONSUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_OPTIONSDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.dwFlags = TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
	ttb.pszService = "Options/OptionsCommand";
	ttb.name = "Show Options Page";
	hOptionsBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);

	ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MINIMIZEUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MINIMIZEDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.dwFlags = TTBBF_VISIBLE;
	ttb.pszService = MS_CLIST_SHOWHIDE;
	ttb.name = "Minimize Button";
	hMinimizeBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);

	ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_FINDADDUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_FINDADDDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.dwFlags = TTBBF_VISIBLE;
	ttb.pszService = MS_FINDADD_FINDADD;
	ttb.name = "Find/Add Contacts";
	hFindUsers = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);

	ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MIRANDAUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MIRANDADN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	ttb.dwFlags = TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
	ttb.pszService = TTBI_MAINMENUBUTT;
	ttb.name = "Show Main Menu";
	hMainMenuBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);

	CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hOnlineBut), 
		(LPARAM)((ShowOnline) ? "Hide Offline Users" : "Show All Users" ));

	CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hGroupBut), 
		(LPARAM)((ShowGroups) ? "Hide Groups" : "Show Groups" ));

	CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hSoundsBut), 
		(LPARAM)((SoundsEnabled) ? "Disable Sounds" : "Enable Sounds" ));

	CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hOptionsBut), 
		(LPARAM)"Show Options");

	return 0;
}