1 const char w32rulesdlg_rcs[] = "$Id: w32rulesdlg.c,v 1.1.1.1 2001/05/15 13:59:08 oes 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.1.1.1 2001/05/15 13:59:08 oes
36 * Initial import of version 2.9.3 source tree
39 *********************************************************************/
49 #include "w32rulesdlg.h"
56 const char w32rulesdlg_h_rcs[] = W32RULESDLG_H_VERSION;
58 #ifndef _WIN_CONSOLE /* entire file */
\r
60 const int nSmallIconWidth = 16;
61 const int nSmallIconHeight = 16;
63 static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
65 static HIMAGELIST g_hImageList = NULL;
66 static char *g_pszDefaultRule;
67 static BOOL g_bDirty = FALSE;
71 /*********************************************************************
73 * Function : ShowRulesDialog
75 * Description : (Please fill me in!)
78 * 1 : hwndParent = (what?)
80 * Returns : (Please fill me in!)
82 *********************************************************************/
83 int ShowRulesDialog(HWND hwndParent)
85 DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_RULES), hwndParent, DialogProc);
91 /*********************************************************************
93 * Function : SetDefaultRule
95 * Description : (Please fill me in!)
98 * 1 : pszRule = (what?)
102 *********************************************************************/
103 void SetDefaultRule(const char *pszRule)
107 if (g_pszDefaultRule)
109 free(g_pszDefaultRule);
110 g_pszDefaultRule = NULL;
115 g_pszDefaultRule = strdup(pszRule);
121 #define IMAGE_ALLOW 0
124 /*********************************************************************
126 * Function : InsertRule
128 * Description : (Please fill me in!)
131 * 1 : hwndListView = (what?)
132 * 2 : pszRule = (what?)
133 * 3 : bAllow = (what?)
137 *********************************************************************/
138 static void InsertRule(HWND hwndListView, const char *pszRule, BOOL bAllow)
141 item.mask = LVIF_TEXT | LVIF_IMAGE;
142 item.pszText = (char *)pszRule;
143 item.iItem = ListView_GetItemCount(hwndListView) + 1;
145 item.iImage = bAllow ? IMAGE_ALLOW : IMAGE_DENY;
146 ListView_InsertItem(hwndListView, &item);
147 /* TODO add subitem for whether the rule is always or never */
152 /*********************************************************************
154 * Function : SetDirty
156 * Description : (Please fill me in!)
159 * 1 : bDirty = (what?)
163 *********************************************************************/
164 static void SetDirty(BOOL bDirty)
167 /* TODO Change some values */
172 /*********************************************************************
174 * Function : OnInitDialog
176 * Description : (Please fill me in!)
179 * 1 : hwndDlg = (what?)
183 *********************************************************************/
184 static void OnInitDialog(HWND hwndDlg)
191 if (g_hImageList == NULL)
193 /* Create image list and add icons */
194 HICON hIconDeny = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_DENYRULE), IMAGE_ICON, nSmallIconWidth, nSmallIconHeight, 0);
195 HICON hIconAllow = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ALLOWRULE), IMAGE_ICON, nSmallIconWidth, nSmallIconHeight, 0);
196 g_hImageList = ImageList_Create(nSmallIconWidth, nSmallIconHeight, ILC_COLOR | ILC_MASK, 0, 10);
197 ImageList_AddIcon(g_hImageList, hIconAllow);
198 ImageList_AddIcon(g_hImageList, hIconDeny);
201 /* Set the default rule value if there is one */
202 if (g_pszDefaultRule)
204 SetDlgItemText(hwndDlg, IDC_NEW, g_pszDefaultRule);
205 SetDefaultRule(NULL);
208 /* Initialise the list view */
209 hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
210 ListView_SetImageList(hwndListView, g_hImageList, LVSIL_SMALL);
211 GetClientRect(hwndListView, &rcListView);
212 cx = rcListView.right - rcListView.left;
213 aCols[0].mask = LVCF_TEXT | LVCF_WIDTH;
214 aCols[0].pszText = "Rule";
215 aCols[0].cx = (70 * cx) / 100;
216 aCols[1].mask = LVCF_TEXT | LVCF_WIDTH;
217 aCols[1].pszText = "Applies when";
218 aCols[1].cx = cx - aCols[0].cx;
219 ListView_InsertColumn(hwndListView, 0, &aCols[0]);
220 ListView_InsertColumn(hwndListView, 1, &aCols[1]);
222 /* Read and add rules to the list */
224 InsertRule(hwndListView, "Test rule 1", TRUE);
225 InsertRule(hwndListView, "Test rule 2", TRUE);
226 InsertRule(hwndListView, "Test rule 3", FALSE);
227 InsertRule(hwndListView, "Test rule 4", FALSE);
232 /*********************************************************************
234 * Function : GetFirstSelectedItem
236 * Description : (Please fill me in!)
239 * 1 : hwndDlg = (what?)
241 * Returns : (Please fill me in!)
243 *********************************************************************/
244 static int GetFirstSelectedItem(HWND hwndDlg)
246 /* Check for selected items */
247 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
251 nItem = ListView_GetNextItem(hwndListView, nItem, LVNI_SELECTED);
256 } while (nItem >= 0);
262 /*********************************************************************
264 * Function : OnRulesItemChanged
266 * Description : (Please fill me in!)
269 * 1 : hwndDlg = (what?)
273 *********************************************************************/
274 static void OnRulesItemChanged(HWND hwndDlg)
276 int nItem = GetFirstSelectedItem(hwndDlg);
277 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
278 int nItems = ListView_GetItemCount(hwndListView);
279 BOOL bHaveSelection = (nItem >= 0) ? TRUE : FALSE;
280 BOOL bMoveUp = (bHaveSelection && nItem > 0) ? TRUE : FALSE;
281 BOOL bMoveDown = (bHaveSelection && nItem < nItems - 1) ? TRUE : FALSE;
283 /* Enable/disable buttons */
284 EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), bHaveSelection);
285 EnableWindow(GetDlgItem(hwndDlg, IDC_MOVEUP), bMoveUp);
286 EnableWindow(GetDlgItem(hwndDlg, IDC_MOVEDOWN), bMoveDown);
291 /*********************************************************************
293 * Function : MoveRules
295 * Description : (Please fill me in!)
298 * 1 : hwndDlg = (what?)
299 * 2 : bMoveUp = (what?)
303 *********************************************************************/
304 static void MoveRules(HWND hwndDlg, BOOL bMoveUp)
309 /*********************************************************************
311 * Function : OnMoveRuleUpClick
313 * Description : (Please fill me in!)
316 * 1 : hwndDlg = (what?)
320 *********************************************************************/
321 static void OnMoveRuleUpClick(HWND hwndDlg)
326 /*********************************************************************
328 * Function : OnMoveRuleDownClick
330 * Description : (Please fill me in!)
333 * 1 : hwndDlg = (what?)
337 *********************************************************************/
338 static void OnMoveRuleDownClick(HWND hwndDlg)
343 /*********************************************************************
345 * Function : OnCreateRuleClick
347 * Description : (Please fill me in!)
350 * 1 : hwndDlg = (what?)
354 *********************************************************************/
355 static void OnCreateRuleClick(HWND hwndDlg)
360 /*********************************************************************
362 * Function : OnDeleteRuleClick
364 * Description : (Please fill me in!)
367 * 1 : hwndDlg = (what?)
371 *********************************************************************/
372 static void OnDeleteRuleClick(HWND hwndDlg)
374 /* Get selection and remove it */
375 int nItem = GetFirstSelectedItem(hwndDlg);
379 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
380 item.mask = LVIF_PARAM;
383 ListView_GetItem(hwndListView, &item);
384 /* TODO erase data stored with item */
385 ListView_DeleteItem(hwndListView, nItem);
391 /*********************************************************************
393 * Function : OnCommand
395 * Description : (Please fill me in!)
398 * 1 : hwndDlg = (what?)
399 * 2 : nCommand = (what?)
400 * 3 : nNotifyCode = (what?)
401 * 4 : hwndItem = (what?)
405 *********************************************************************/
406 static void OnCommand(HWND hwndDlg, int nCommand, int nNotifyCode, HWND hwndItem)
412 EndDialog(hwndDlg, IDOK);
415 if (nNotifyCode == BN_CLICKED)
417 OnCreateRuleClick(hwndDlg);
421 if (nNotifyCode == BN_CLICKED)
423 OnDeleteRuleClick(hwndDlg);
427 if (nNotifyCode == BN_CLICKED)
429 OnMoveRuleUpClick(hwndDlg);
433 if (nNotifyCode == BN_CLICKED)
435 OnMoveRuleDownClick(hwndDlg);
443 /*********************************************************************
445 * Function : OnNotify
447 * Description : (Please fill me in!)
450 * 1 : hwndDlg = (what?)
451 * 2 : nIdCtrl = (what?)
456 *********************************************************************/
457 static void OnNotify(HWND hwndDlg, int nIdCtrl, LPNMHDR pnmh)
464 case LVN_ITEMCHANGED:
465 OnRulesItemChanged(hwndDlg);
474 /*********************************************************************
476 * Function : OnDestroy
478 * Description : (Please fill me in!)
481 * 1 : hwndDlg = (what?)
485 *********************************************************************/
486 static void OnDestroy(HWND hwndDlg)
488 /* TODO any destruction cleanup */
493 /*********************************************************************
495 * Function : DialogProc
497 * Description : (Please fill me in!)
500 * 1 : hwndDlg = (what?)
502 * 3 : wParam = (what?)
503 * 4 : lParam = (what?)
505 * Returns : (Please fill me in!)
507 *********************************************************************/
508 static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
513 OnInitDialog(hwndDlg);
521 OnCommand(hwndDlg, LOWORD(wParam), HIWORD(wParam), (HWND) lParam);
525 OnNotify(hwndDlg, (int) wParam, (LPNMHDR) lParam);
532 #endif /* ndef _WIN_CONSOLE - entire file */
\r