1 const char w32rulesdlg_rcs[] = "$Id: w32rulesdlg.c,v 1.1 2001/05/13 21:57:07 administrator Exp $";
2 /*********************************************************************
4 * File : $Source: /home/administrator/cvs/ijb/w32rulesdlg.c,v $
6 * Purpose : A dialog to allow GUI editing of the rules.
9 * Copyright : Written by and Copyright (C) 2001 the SourceForge
10 * IJBSWA team. http://ijbswa.sourceforge.net
12 * Written by and Copyright (C) 1999 Adam Lock
15 * This program is free software; you can redistribute it
16 * and/or modify it under the terms of the GNU General
17 * Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at
19 * your option) any later version.
21 * This program is distributed in the hope that it will
22 * be useful, but WITHOUT ANY WARRANTY; without even the
23 * implied warranty of MERCHANTABILITY or FITNESS FOR A
24 * PARTICULAR PURPOSE. See the GNU General Public
25 * License for more details.
27 * The GNU General Public License should be included with
28 * this file. If not, you can view it at
29 * http://www.gnu.org/copyleft/gpl.html
30 * or write to the Free Software Foundation, Inc., 59
31 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 * $Log: w32rulesdlg.c,v $
36 *********************************************************************/
46 #include "w32rulesdlg.h"
53 const char w32rulesdlg_h_rcs[] = W32RULESDLG_H_VERSION;
55 const int nSmallIconWidth = 16;
56 const int nSmallIconHeight = 16;
58 static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
60 static HIMAGELIST g_hImageList = NULL;
61 static char *g_pszDefaultRule;
62 static BOOL g_bDirty = FALSE;
66 /*********************************************************************
68 * Function : ShowRulesDialog
70 * Description : (Please fill me in!)
73 * 1 : hwndParent = (what?)
75 * Returns : (Please fill me in!)
77 *********************************************************************/
78 int ShowRulesDialog(HWND hwndParent)
80 DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_RULES), hwndParent, DialogProc);
86 /*********************************************************************
88 * Function : SetDefaultRule
90 * Description : (Please fill me in!)
93 * 1 : pszRule = (what?)
97 *********************************************************************/
98 void SetDefaultRule(const char *pszRule)
102 if (g_pszDefaultRule)
104 free(g_pszDefaultRule);
105 g_pszDefaultRule = NULL;
110 g_pszDefaultRule = strdup(pszRule);
116 #define IMAGE_ALLOW 0
119 /*********************************************************************
121 * Function : InsertRule
123 * Description : (Please fill me in!)
126 * 1 : hwndListView = (what?)
127 * 2 : pszRule = (what?)
128 * 3 : bAllow = (what?)
132 *********************************************************************/
133 static void InsertRule(HWND hwndListView, const char *pszRule, BOOL bAllow)
136 item.mask = LVIF_TEXT | LVIF_IMAGE;
137 item.pszText = (char *)pszRule;
138 item.iItem = ListView_GetItemCount(hwndListView) + 1;
140 item.iImage = bAllow ? IMAGE_ALLOW : IMAGE_DENY;
141 ListView_InsertItem(hwndListView, &item);
142 /* TODO add subitem for whether the rule is always or never */
147 /*********************************************************************
149 * Function : SetDirty
151 * Description : (Please fill me in!)
154 * 1 : bDirty = (what?)
158 *********************************************************************/
159 static void SetDirty(BOOL bDirty)
162 /* TODO Change some values */
167 /*********************************************************************
169 * Function : OnInitDialog
171 * Description : (Please fill me in!)
174 * 1 : hwndDlg = (what?)
178 *********************************************************************/
179 static void OnInitDialog(HWND hwndDlg)
186 if (g_hImageList == NULL)
188 /* Create image list and add icons */
189 HICON hIconDeny = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_DENYRULE), IMAGE_ICON, nSmallIconWidth, nSmallIconHeight, 0);
190 HICON hIconAllow = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ALLOWRULE), IMAGE_ICON, nSmallIconWidth, nSmallIconHeight, 0);
191 g_hImageList = ImageList_Create(nSmallIconWidth, nSmallIconHeight, ILC_COLOR | ILC_MASK, 0, 10);
192 ImageList_AddIcon(g_hImageList, hIconAllow);
193 ImageList_AddIcon(g_hImageList, hIconDeny);
196 /* Set the default rule value if there is one */
197 if (g_pszDefaultRule)
199 SetDlgItemText(hwndDlg, IDC_NEW, g_pszDefaultRule);
200 SetDefaultRule(NULL);
203 /* Initialise the list view */
204 hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
205 ListView_SetImageList(hwndListView, g_hImageList, LVSIL_SMALL);
206 GetClientRect(hwndListView, &rcListView);
207 cx = rcListView.right - rcListView.left;
208 aCols[0].mask = LVCF_TEXT | LVCF_WIDTH;
209 aCols[0].pszText = "Rule";
210 aCols[0].cx = (70 * cx) / 100;
211 aCols[1].mask = LVCF_TEXT | LVCF_WIDTH;
212 aCols[1].pszText = "Applies when";
213 aCols[1].cx = cx - aCols[0].cx;
214 ListView_InsertColumn(hwndListView, 0, &aCols[0]);
215 ListView_InsertColumn(hwndListView, 1, &aCols[1]);
217 /* Read and add rules to the list */
219 InsertRule(hwndListView, "Test rule 1", TRUE);
220 InsertRule(hwndListView, "Test rule 2", TRUE);
221 InsertRule(hwndListView, "Test rule 3", FALSE);
222 InsertRule(hwndListView, "Test rule 4", FALSE);
227 /*********************************************************************
229 * Function : GetFirstSelectedItem
231 * Description : (Please fill me in!)
234 * 1 : hwndDlg = (what?)
236 * Returns : (Please fill me in!)
238 *********************************************************************/
239 static int GetFirstSelectedItem(HWND hwndDlg)
241 /* Check for selected items */
242 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
246 nItem = ListView_GetNextItem(hwndListView, nItem, LVNI_SELECTED);
251 } while (nItem >= 0);
257 /*********************************************************************
259 * Function : OnRulesItemChanged
261 * Description : (Please fill me in!)
264 * 1 : hwndDlg = (what?)
268 *********************************************************************/
269 static void OnRulesItemChanged(HWND hwndDlg)
271 int nItem = GetFirstSelectedItem(hwndDlg);
272 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
273 int nItems = ListView_GetItemCount(hwndListView);
274 BOOL bHaveSelection = (nItem >= 0) ? TRUE : FALSE;
275 BOOL bMoveUp = (bHaveSelection && nItem > 0) ? TRUE : FALSE;
276 BOOL bMoveDown = (bHaveSelection && nItem < nItems - 1) ? TRUE : FALSE;
278 /* Enable/disable buttons */
279 EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), bHaveSelection);
280 EnableWindow(GetDlgItem(hwndDlg, IDC_MOVEUP), bMoveUp);
281 EnableWindow(GetDlgItem(hwndDlg, IDC_MOVEDOWN), bMoveDown);
286 /*********************************************************************
288 * Function : MoveRules
290 * Description : (Please fill me in!)
293 * 1 : hwndDlg = (what?)
294 * 2 : bMoveUp = (what?)
298 *********************************************************************/
299 static void MoveRules(HWND hwndDlg, BOOL bMoveUp)
304 /*********************************************************************
306 * Function : OnMoveRuleUpClick
308 * Description : (Please fill me in!)
311 * 1 : hwndDlg = (what?)
315 *********************************************************************/
316 static void OnMoveRuleUpClick(HWND hwndDlg)
321 /*********************************************************************
323 * Function : OnMoveRuleDownClick
325 * Description : (Please fill me in!)
328 * 1 : hwndDlg = (what?)
332 *********************************************************************/
333 static void OnMoveRuleDownClick(HWND hwndDlg)
338 /*********************************************************************
340 * Function : OnCreateRuleClick
342 * Description : (Please fill me in!)
345 * 1 : hwndDlg = (what?)
349 *********************************************************************/
350 static void OnCreateRuleClick(HWND hwndDlg)
355 /*********************************************************************
357 * Function : OnDeleteRuleClick
359 * Description : (Please fill me in!)
362 * 1 : hwndDlg = (what?)
366 *********************************************************************/
367 static void OnDeleteRuleClick(HWND hwndDlg)
369 /* Get selection and remove it */
370 int nItem = GetFirstSelectedItem(hwndDlg);
374 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
375 item.mask = LVIF_PARAM;
378 ListView_GetItem(hwndListView, &item);
379 /* TODO erase data stored with item */
380 ListView_DeleteItem(hwndListView, nItem);
386 /*********************************************************************
388 * Function : OnCommand
390 * Description : (Please fill me in!)
393 * 1 : hwndDlg = (what?)
394 * 2 : nCommand = (what?)
395 * 3 : nNotifyCode = (what?)
396 * 4 : hwndItem = (what?)
400 *********************************************************************/
401 static void OnCommand(HWND hwndDlg, int nCommand, int nNotifyCode, HWND hwndItem)
407 EndDialog(hwndDlg, IDOK);
410 if (nNotifyCode == BN_CLICKED)
412 OnCreateRuleClick(hwndDlg);
416 if (nNotifyCode == BN_CLICKED)
418 OnDeleteRuleClick(hwndDlg);
422 if (nNotifyCode == BN_CLICKED)
424 OnMoveRuleUpClick(hwndDlg);
428 if (nNotifyCode == BN_CLICKED)
430 OnMoveRuleDownClick(hwndDlg);
438 /*********************************************************************
440 * Function : OnNotify
442 * Description : (Please fill me in!)
445 * 1 : hwndDlg = (what?)
446 * 2 : nIdCtrl = (what?)
451 *********************************************************************/
452 static void OnNotify(HWND hwndDlg, int nIdCtrl, LPNMHDR pnmh)
459 case LVN_ITEMCHANGED:
460 OnRulesItemChanged(hwndDlg);
469 /*********************************************************************
471 * Function : OnDestroy
473 * Description : (Please fill me in!)
476 * 1 : hwndDlg = (what?)
480 *********************************************************************/
481 static void OnDestroy(HWND hwndDlg)
483 /* TODO any destruction cleanup */
488 /*********************************************************************
490 * Function : DialogProc
492 * Description : (Please fill me in!)
495 * 1 : hwndDlg = (what?)
497 * 3 : wParam = (what?)
498 * 4 : lParam = (what?)
500 * Returns : (Please fill me in!)
502 *********************************************************************/
503 static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
508 OnInitDialog(hwndDlg);
516 OnCommand(hwndDlg, LOWORD(wParam), HIWORD(wParam), (HWND) lParam);
520 OnNotify(hwndDlg, (int) wParam, (LPNMHDR) lParam);