summaryrefslogtreecommitdiff
path: root/plugins/SmartAutoAway/dlgproc.cpp
blob: 72836cc6a8a858bb9e119997e88a548bbcf4cda9 (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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*

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 "globals.h"

INT_PTR CALLBACK DlgProcAutoAwayOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
//	char str[MAXMODULELABELLENGTH];
	static short int tabprotosel;
	switch (msg)
	{
		case WM_INITDIALOG: 
		{	
			short int t,p,protoListed;
			TCITEM tci;
			RECT theTabSpace;
			RECT rcClient;
			{
				RECT rcTab, rcDlg;
				TabCtrl_GetItemRect(GetDlgItem(hwndDlg, IDC_OPT_SAA_TAB),0,&rcTab);
				theTabSpace.top = rcTab.bottom; // the size of the tab
				GetWindowRect(GetDlgItem(hwndDlg, IDC_OPT_SAA_TAB), &rcTab);
				GetWindowRect(hwndDlg, &rcDlg);
				theTabSpace.bottom = rcTab.bottom -rcTab.top  -theTabSpace.top;
				theTabSpace.top =  rcTab.top -rcDlg.top +theTabSpace.top;
				theTabSpace.left = rcTab.left - rcDlg.left;
				theTabSpace.right = rcTab.right-rcTab.left;
			}
			theDialog = hwndDlg;
			TranslateDialogDefault(hwndDlg);
			protoListed = 0;
			for (p = 0 ; p < protoCount ;p++) {
				int caps=0;
				if ( !isInterestingProto(p) ) continue;
				caps = CallProtoService(accounts[p]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0);
				PROTOACCOUNT* protoAccount=ProtoGetAccount(accounts[p]->szModuleName);
				if ((int)protoAccount!=CALLSERVICE_NOTFOUND){
					SendDlgItemMessage(hwndDlg, IDC_AAPROTOCOL, CB_ADDSTRING, 0, (LPARAM)protoAccount->tszAccountName );
				} else SendDlgItemMessageA(hwndDlg, IDC_AAPROTOCOL, CB_ADDSTRING, 0, (LPARAM)accounts[p]->szModuleName );
				protoListed++;
			}
			tabprotosel = db_get_w(NULL, AA_MODULE, AA_PROTOSELECTION, 0);
			t = (tabprotosel&0x0F00) >> 8; if (t>3) t=3;
			p = (tabprotosel&0x00FF);
			if ((p>=protoListed)) p= protoListed-1;
			SendDlgItemMessage(hwndDlg, IDC_AAPROTOCOL, CB_SETCURSEL, p, 0);
			SetDlgItems(hwndDlg, courProtocolSelection = GetCourSelProtocol(p));

			tci.mask = TCIF_PARAM|TCIF_TEXT;
			
#ifdef SAA_PLUGIN
			theDialogAA =  CreateDialog(g_hInst,MAKEINTRESOURCE(IDD_OPT_SAA_AA), hwndDlg, DlgProcOptsAA);
#else
			theDialogAA =  CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OPT_SAA_AA), hwndDlg, DlgProcOptsAA);
#endif                  
			tci.lParam = (LPARAM)theDialogAA;
			tci.pszText = TranslateT("Statuses");
			GetClientRect(theDialogAA,&rcClient);
			SendMessage(GetDlgItem(hwndDlg, IDC_OPT_SAA_TAB), TCM_INSERTITEM, 0, (LPARAM)&tci);
			MoveWindow((HWND)theDialogAA,theTabSpace.left+(theTabSpace.right-rcClient.right)/2,
				theTabSpace.top+(theTabSpace.bottom-rcClient.bottom)/2,
				rcClient.right,rcClient.bottom,1);
			ShowWindow((HWND)tci.lParam, (t==0)?SW_SHOW:SW_HIDE);

			
#ifdef SAA_PLUGIN
			theDialogIdle = CreateDialog(g_hInst,MAKEINTRESOURCE(IDD_OPT_SAA_IDLE), hwndDlg, DlgProcOptsIdle);
#else
			theDialogIdle = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OPT_SAA_IDLE), hwndDlg, DlgProcOptsIdle);
#endif
			tci.lParam = (LPARAM)theDialogIdle;
			tci.pszText = TranslateT("Idle");
			GetClientRect(theDialogIdle,&rcClient);
			SendMessage(GetDlgItem(hwndDlg, IDC_OPT_SAA_TAB), TCM_INSERTITEM, (WPARAM)1, (LPARAM)&tci);
			MoveWindow((HWND)theDialogIdle,theTabSpace.left+(theTabSpace.right-rcClient.right)/2,
				theTabSpace.top+(theTabSpace.bottom-rcClient.bottom)/2,
				rcClient.right,rcClient.bottom,1);
			ShowWindow((HWND)tci.lParam, (t==1)?SW_SHOW:SW_HIDE);

#ifdef SAA_PLUGIN
			theDialogIdleMessages = CreateDialog(g_hInst,MAKEINTRESOURCE(IDD_OPT_SAA_IDLEMESSAGES), hwndDlg, DlgProcOptsIdleMessages);
#else
			theDialogIdleMessages = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OPT_SAA_IDLEMESSAGES), hwndDlg, DlgProcOptsIdleMessages);
#endif
			tci.lParam = (LPARAM)theDialogIdleMessages;
			tci.pszText = TranslateT("Status Messages");
			GetClientRect(theDialogIdleMessages,&rcClient);
			SendMessage(GetDlgItem(hwndDlg, IDC_OPT_SAA_TAB), TCM_INSERTITEM, (WPARAM)2, (LPARAM)&tci);
			MoveWindow((HWND)theDialogIdleMessages,theTabSpace.left+(theTabSpace.right-rcClient.right)/2,
				theTabSpace.top+(theTabSpace.bottom-rcClient.bottom)/2,
				rcClient.right,rcClient.bottom,1);
			ShowWindow((HWND)tci.lParam, (t==2)?SW_SHOW:SW_HIDE);

#ifdef SAA_PLUGIN
			theDialogReconnect = CreateDialog(g_hInst,MAKEINTRESOURCE(IDD_OPT_SAA_RECONNECT), hwndDlg, DlgProcOptsReconnect);
#else
			theDialogReconnect = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OPT_SAA_RECONNECT), hwndDlg, DlgProcOptsReconnect);
#endif
			tci.lParam = (LPARAM)theDialogReconnect;
			tci.pszText = TranslateT("Reconnect");
			GetClientRect(theDialogReconnect,&rcClient);
			SendMessage(GetDlgItem(hwndDlg, IDC_OPT_SAA_TAB), TCM_INSERTITEM, (WPARAM)3, (LPARAM)&tci);
			MoveWindow((HWND)theDialogReconnect,theTabSpace.left+(theTabSpace.right-rcClient.right)/2,
				theTabSpace.top+(theTabSpace.bottom-rcClient.bottom)/2,
				rcClient.right,rcClient.bottom,1);
			ShowWindow((HWND)tci.lParam, (t==3)?SW_SHOW:SW_HIDE);
			TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_OPT_SAA_TAB),t);

			if(enableThemeDialogTexture) {
					enableThemeDialogTexture(theDialogAA, ETDT_ENABLETAB);
					enableThemeDialogTexture(theDialogIdle, ETDT_ENABLETAB);
					enableThemeDialogTexture(theDialogIdleMessages, ETDT_ENABLETAB);
					enableThemeDialogTexture(theDialogReconnect, ETDT_ENABLETAB);
			}
			return TRUE;
		}

		case WM_COMMAND:
		{
            switch (LOWORD(wParam)) {
				case IDC_AAPROTOCOL:
					{
						int cour = SendDlgItemMessage(hwndDlg, IDC_AAPROTOCOL, CB_GETCURSEL, 0, 0);
						courProtocolSelection = GetCourSelProtocol(cour);
						if ( HIWORD(wParam) != CBN_SELCHANGE ) return TRUE;
						db_set_w(NULL, AA_MODULE, AA_PROTOSELECTION, 
							(unsigned short)(tabprotosel=courProtocolSelection|(tabprotosel&0xFF00)));
						SetDlgItems(hwndDlg, courProtocolSelection);
						SetDlgItemsReconnect(theDialogReconnect,courProtocolSelection);
						SetDlgItemsAA(theDialogAA,courProtocolSelection);
						SetDlgItemsIdleMessages(theDialogIdleMessages,courProtocolSelection);
						break;
					}
				case IDC_APPLYTOALL:
					{
						int i;
						for (i=0;i<protoCount;i++){
							if (isInterestingProto(i)) {
								awayStatuses[i]=awayStatuses[courProtocolSelection];
								onlyIfBits[i]=onlyIfBits[courProtocolSelection];
								reconnectOpts[i]=reconnectOpts[courProtocolSelection];
								if (messCaps[i]) {
									_tcscpy(mesgHere[i],mesgHerePerm[courProtocolSelection]);
									_tcscpy(mesgShort[i],mesgShortPerm[courProtocolSelection]);
									_tcscpy(mesgLong[i],mesgLongPerm[courProtocolSelection]);
								}
							}
						}
						SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
						break;
					}
			} //switch
			break;
		}
		case PSM_CHANGED:
#ifdef _DEBUG
			MessageBoxA(hwndDlg,"Child dialog changed","EventHapened",0);
#endif
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, (unsigned int)hwndDlg, 0);
			break;
		case WM_NOTIFY:
		{
		  switch(((LPNMHDR)lParam)->idFrom) {
            case 0:	{
			  BOOL CommandApply;
			  if ( (CommandApply = lParam && ((LPNMHDR)lParam)->code == PSN_APPLY) || (lParam && ((LPNMHDR)lParam)->code == PSN_RESET) ) {
				int j=0;
#ifdef _DEBUG
				//MessageBox(hwndDlg,CommandApply?"Apply":"Cancel","EventHapened",0);
#endif
				for (j = 0 ; j < protoCount ; j++) {
					if ( isInterestingProto(j) ) {
						char str[256];
						if (CommandApply) {
							onlyIfBitsPerm[j] = onlyIfBits[j];
							awayStatusesPerm[j] = awayStatuses[j];
							reconnectOptsPerm[j] = reconnectOpts[j];
							sprintf(str,AA_BITSONLYIF,accounts[j]->szModuleName);
							db_set_dw(NULL,AA_MODULE,str,onlyIfBitsPerm[j]);
							sprintf(str,AA_AWAYSTATUSES,accounts[j]->szModuleName);
							db_set_w(NULL,AA_MODULE,str,awayStatusesPerm[j]);
							sprintf(str,AA_RECONNECTOPTS,accounts[j]->szModuleName);
							db_set_dw(NULL,AA_MODULE,str,reconnectOptsPerm[j]);
							if (messCaps[j]) {
								idleMessOptsPerm[j] = idleMessOpts[j];
								sprintf(str,idleMsgOptionsName,accounts[j]->szModuleName);
								db_set_dw(NULL,AA_MODULE,str,idleMessOptsPerm[j]);

								sprintf(str,idleMsgOptionsTextHere,accounts[j]->szModuleName);
								_tcscpy(mesgHerePerm[j],mesgHere[j]);
								db_set_ts(NULL,AA_MODULE,str,mesgHerePerm[j]);

								sprintf(str,idleMsgOptionsTextShort,accounts[j]->szModuleName);
								_tcscpy(mesgShortPerm[j],mesgShort[j]);
								db_set_ts(NULL,AA_MODULE,str,mesgShortPerm[j]);

								sprintf(str,idleMsgOptionsTextLong,accounts[j]->szModuleName);
								_tcscpy(mesgLongPerm[j],mesgLong[j]);
								db_set_ts(NULL,AA_MODULE,str,mesgLongPerm[j]);
							}
						} else {
							onlyIfBits[j] = onlyIfBitsPerm[j];
							awayStatuses[j] = awayStatusesPerm[j];
							reconnectOpts[j] = reconnectOptsPerm[j];
							idleMessOpts[j] = idleMessOptsPerm[j];
							if (messCaps[j]) {
								_tcscpy(mesgHere[j],mesgHerePerm[j]);
								_tcscpy(mesgShort[j],mesgShortPerm[j]);
								_tcscpy(mesgLong[j],mesgLongPerm[j]);
							}
						}
					}
				}
				if (CommandApply) {
					idleOptsPerm = idleOpts;
					db_set_dw(NULL,AA_MODULE,AA_IDLEOPTIONS,idleOptsPerm);
				} else {
					idleOpts = idleOptsPerm;
				}
			  } //if PSN_APPLY
              break;
            case IDC_OPT_SAA_TAB:
               switch (((LPNMHDR)lParam)->code)
               {
                  case TCN_SELCHANGING:
                     {
                        TCITEM tci;
                        tci.mask = TCIF_PARAM;
                        TabCtrl_GetItem(GetDlgItem(hwndDlg,IDC_OPT_SAA_TAB),TabCtrl_GetCurSel(GetDlgItem(hwndDlg,IDC_OPT_SAA_TAB)),&tci);
                        ShowWindow((HWND)tci.lParam,SW_HIDE);                     
                     }
                  break;
                  case TCN_SELCHANGE:
                     {
                        TCITEM tci;
						short int t;
                        tci.mask = TCIF_PARAM;
						t = TabCtrl_GetCurSel(GetDlgItem(hwndDlg,IDC_OPT_SAA_TAB));
                        TabCtrl_GetItem(GetDlgItem(hwndDlg,IDC_OPT_SAA_TAB),t,&tci);
						db_set_w(NULL, AA_MODULE, AA_PROTOSELECTION, 
							(unsigned short)(tabprotosel=(t<<8)|(tabprotosel&0xF0FF)));
                        ShowWindow((HWND)tci.lParam,SW_SHOW);                     
						{ BOOL enableW = (tci.lParam!=(long)theDialogIdle);
							EnableWindow(GetDlgItem(hwndDlg,IDC_AAPROTOCOL),enableW);
							EnableWindow(GetDlgItem(hwndDlg,IDC_APPLYTOALL),enableW);
						}
                     }
                  break;
               }
			   break;
			}
		  }//end case(LPNMHDR)lParam)->idFrom
					
		}
//WTF???		if(wParam!=0x12345678) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		break; 
	}
	return FALSE;
}