1 const char w32rulesdlg_rcs[] = "$Id: w32rulesdlg.c,v 1.2 2001/05/20 15:07:54 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/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 $
35 * Revision 1.2 2001/05/20 15:07:54 jongfoster
36 * File is now ignored if _WIN_CONSOLE is defined.
38 * Revision 1.1.1.1 2001/05/15 13:59:08 oes
39 * Initial import of version 2.9.3 source tree
42 *********************************************************************/
52 #include "w32rulesdlg.h"
59 const char w32rulesdlg_h_rcs[] = W32RULESDLG_H_VERSION;
61 #ifndef _WIN_CONSOLE /* entire file */
63 const int nSmallIconWidth = 16;
64 const int nSmallIconHeight = 16;
66 static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
68 static HIMAGELIST g_hImageList = NULL;
69 static char *g_pszDefaultRule;
70 static BOOL g_bDirty = FALSE;
74 /*********************************************************************
76 * Function : ShowRulesDialog
78 * Description : (Please fill me in!)
81 * 1 : hwndParent = (what?)
83 * Returns : (Please fill me in!)
85 *********************************************************************/
86 int ShowRulesDialog(HWND hwndParent)
88 DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_RULES), hwndParent, DialogProc);
94 /*********************************************************************
96 * Function : SetDefaultRule
98 * Description : (Please fill me in!)
101 * 1 : pszRule = (what?)
105 *********************************************************************/
106 void SetDefaultRule(const char *pszRule)
110 if (g_pszDefaultRule)
112 free(g_pszDefaultRule);
113 g_pszDefaultRule = NULL;
118 g_pszDefaultRule = strdup(pszRule);
124 #define IMAGE_ALLOW 0
127 /*********************************************************************
129 * Function : InsertRule
131 * Description : (Please fill me in!)
134 * 1 : hwndListView = (what?)
135 * 2 : pszRule = (what?)
136 * 3 : bAllow = (what?)
140 *********************************************************************/
141 static void InsertRule(HWND hwndListView, const char *pszRule, BOOL bAllow)
144 item.mask = LVIF_TEXT | LVIF_IMAGE;
145 item.pszText = (char *)pszRule;
146 item.iItem = ListView_GetItemCount(hwndListView) + 1;
148 item.iImage = bAllow ? IMAGE_ALLOW : IMAGE_DENY;
149 ListView_InsertItem(hwndListView, &item);
150 /* TODO add subitem for whether the rule is always or never */
155 /*********************************************************************
157 * Function : SetDirty
159 * Description : (Please fill me in!)
162 * 1 : bDirty = (what?)
166 *********************************************************************/
167 static void SetDirty(BOOL bDirty)
170 /* TODO Change some values */
175 /*********************************************************************
177 * Function : OnInitDialog
179 * Description : (Please fill me in!)
182 * 1 : hwndDlg = (what?)
186 *********************************************************************/
187 static void OnInitDialog(HWND hwndDlg)
194 if (g_hImageList == NULL)
196 /* Create image list and add icons */
197 HICON hIconDeny = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_DENYRULE), IMAGE_ICON, nSmallIconWidth, nSmallIconHeight, 0);
198 HICON hIconAllow = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ALLOWRULE), IMAGE_ICON, nSmallIconWidth, nSmallIconHeight, 0);
199 g_hImageList = ImageList_Create(nSmallIconWidth, nSmallIconHeight, ILC_COLOR | ILC_MASK, 0, 10);
200 ImageList_AddIcon(g_hImageList, hIconAllow);
201 ImageList_AddIcon(g_hImageList, hIconDeny);
204 /* Set the default rule value if there is one */
205 if (g_pszDefaultRule)
207 SetDlgItemText(hwndDlg, IDC_NEW, g_pszDefaultRule);
208 SetDefaultRule(NULL);
211 /* Initialise the list view */
212 hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
213 ListView_SetImageList(hwndListView, g_hImageList, LVSIL_SMALL);
214 GetClientRect(hwndListView, &rcListView);
215 cx = rcListView.right - rcListView.left;
216 aCols[0].mask = LVCF_TEXT | LVCF_WIDTH;
217 aCols[0].pszText = "Rule";
218 aCols[0].cx = (70 * cx) / 100;
219 aCols[1].mask = LVCF_TEXT | LVCF_WIDTH;
220 aCols[1].pszText = "Applies when";
221 aCols[1].cx = cx - aCols[0].cx;
222 ListView_InsertColumn(hwndListView, 0, &aCols[0]);
223 ListView_InsertColumn(hwndListView, 1, &aCols[1]);
225 /* Read and add rules to the list */
227 InsertRule(hwndListView, "Test rule 1", TRUE);
228 InsertRule(hwndListView, "Test rule 2", TRUE);
229 InsertRule(hwndListView, "Test rule 3", FALSE);
230 InsertRule(hwndListView, "Test rule 4", FALSE);
235 /*********************************************************************
237 * Function : GetFirstSelectedItem
239 * Description : (Please fill me in!)
242 * 1 : hwndDlg = (what?)
244 * Returns : (Please fill me in!)
246 *********************************************************************/
247 static int GetFirstSelectedItem(HWND hwndDlg)
249 /* Check for selected items */
250 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
254 nItem = ListView_GetNextItem(hwndListView, nItem, LVNI_SELECTED);
259 } while (nItem >= 0);
265 /*********************************************************************
267 * Function : OnRulesItemChanged
269 * Description : (Please fill me in!)
272 * 1 : hwndDlg = (what?)
276 *********************************************************************/
277 static void OnRulesItemChanged(HWND hwndDlg)
279 int nItem = GetFirstSelectedItem(hwndDlg);
280 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
281 int nItems = ListView_GetItemCount(hwndListView);
282 BOOL bHaveSelection = (nItem >= 0) ? TRUE : FALSE;
283 BOOL bMoveUp = (bHaveSelection && nItem > 0) ? TRUE : FALSE;
284 BOOL bMoveDown = (bHaveSelection && nItem < nItems - 1) ? TRUE : FALSE;
286 /* Enable/disable buttons */
287 EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), bHaveSelection);
288 EnableWindow(GetDlgItem(hwndDlg, IDC_MOVEUP), bMoveUp);
289 EnableWindow(GetDlgItem(hwndDlg, IDC_MOVEDOWN), bMoveDown);
294 /*********************************************************************
296 * Function : MoveRules
298 * Description : (Please fill me in!)
301 * 1 : hwndDlg = (what?)
302 * 2 : bMoveUp = (what?)
306 *********************************************************************/
307 static void MoveRules(HWND hwndDlg, BOOL bMoveUp)
312 /*********************************************************************
314 * Function : OnMoveRuleUpClick
316 * Description : (Please fill me in!)
319 * 1 : hwndDlg = (what?)
323 *********************************************************************/
324 static void OnMoveRuleUpClick(HWND hwndDlg)
329 /*********************************************************************
331 * Function : OnMoveRuleDownClick
333 * Description : (Please fill me in!)
336 * 1 : hwndDlg = (what?)
340 *********************************************************************/
341 static void OnMoveRuleDownClick(HWND hwndDlg)
346 /*********************************************************************
348 * Function : OnCreateRuleClick
350 * Description : (Please fill me in!)
353 * 1 : hwndDlg = (what?)
357 *********************************************************************/
358 static void OnCreateRuleClick(HWND hwndDlg)
363 /*********************************************************************
365 * Function : OnDeleteRuleClick
367 * Description : (Please fill me in!)
370 * 1 : hwndDlg = (what?)
374 *********************************************************************/
375 static void OnDeleteRuleClick(HWND hwndDlg)
377 /* Get selection and remove it */
378 int nItem = GetFirstSelectedItem(hwndDlg);
382 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
383 item.mask = LVIF_PARAM;
386 ListView_GetItem(hwndListView, &item);
387 /* TODO erase data stored with item */
388 ListView_DeleteItem(hwndListView, nItem);
394 /*********************************************************************
396 * Function : OnCommand
398 * Description : (Please fill me in!)
401 * 1 : hwndDlg = (what?)
402 * 2 : nCommand = (what?)
403 * 3 : nNotifyCode = (what?)
404 * 4 : hwndItem = (what?)
408 *********************************************************************/
409 static void OnCommand(HWND hwndDlg, int nCommand, int nNotifyCode, HWND hwndItem)
415 EndDialog(hwndDlg, IDOK);
418 if (nNotifyCode == BN_CLICKED)
420 OnCreateRuleClick(hwndDlg);
424 if (nNotifyCode == BN_CLICKED)
426 OnDeleteRuleClick(hwndDlg);
430 if (nNotifyCode == BN_CLICKED)
432 OnMoveRuleUpClick(hwndDlg);
436 if (nNotifyCode == BN_CLICKED)
438 OnMoveRuleDownClick(hwndDlg);
446 /*********************************************************************
448 * Function : OnNotify
450 * Description : (Please fill me in!)
453 * 1 : hwndDlg = (what?)
454 * 2 : nIdCtrl = (what?)
459 *********************************************************************/
460 static void OnNotify(HWND hwndDlg, int nIdCtrl, LPNMHDR pnmh)
467 case LVN_ITEMCHANGED:
468 OnRulesItemChanged(hwndDlg);
477 /*********************************************************************
479 * Function : OnDestroy
481 * Description : (Please fill me in!)
484 * 1 : hwndDlg = (what?)
488 *********************************************************************/
489 static void OnDestroy(HWND hwndDlg)
491 /* TODO any destruction cleanup */
496 /*********************************************************************
498 * Function : DialogProc
500 * Description : (Please fill me in!)
503 * 1 : hwndDlg = (what?)
505 * 3 : wParam = (what?)
506 * 4 : lParam = (what?)
508 * Returns : (Please fill me in!)
510 *********************************************************************/
511 static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
516 OnInitDialog(hwndDlg);
524 OnCommand(hwndDlg, LOWORD(wParam), HIWORD(wParam), (HWND) lParam);
528 OnNotify(hwndDlg, (int) wParam, (LPNMHDR) lParam);
535 #endif /* ndef _WIN_CONSOLE - entire file */