1 const char w32rulesdlg_rcs[] = "$Id: w32rulesdlg.c,v 1.3 2001/05/22 18:56:28 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.3 2001/05/22 18:56:28 oes
38 * Revision 1.2 2001/05/20 15:07:54 jongfoster
39 * File is now ignored if _WIN_CONSOLE is defined.
41 * Revision 1.1.1.1 2001/05/15 13:59:08 oes
42 * Initial import of version 2.9.3 source tree
45 *********************************************************************/
55 #include "w32rulesdlg.h"
62 const char w32rulesdlg_h_rcs[] = W32RULESDLG_H_VERSION;
65 #ifndef _WIN_CONSOLE /* entire file */
66 #ifdef WIN_GUI_EDIT /* entire file */
69 const int nSmallIconWidth = 16;
70 const int nSmallIconHeight = 16;
72 static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
74 static HIMAGELIST g_hImageList = NULL;
75 static char *g_pszDefaultRule;
76 static BOOL g_bDirty = FALSE;
80 /*********************************************************************
82 * Function : ShowRulesDialog
84 * Description : (Please fill me in!)
87 * 1 : hwndParent = (what?)
89 * Returns : (Please fill me in!)
91 *********************************************************************/
92 int ShowRulesDialog(HWND hwndParent)
94 DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_RULES), hwndParent, DialogProc);
100 /*********************************************************************
102 * Function : SetDefaultRule
104 * Description : (Please fill me in!)
107 * 1 : pszRule = (what?)
111 *********************************************************************/
112 void SetDefaultRule(const char *pszRule)
116 if (g_pszDefaultRule)
118 free(g_pszDefaultRule);
119 g_pszDefaultRule = NULL;
124 g_pszDefaultRule = strdup(pszRule);
130 #define IMAGE_ALLOW 0
133 /*********************************************************************
135 * Function : InsertRule
137 * Description : (Please fill me in!)
140 * 1 : hwndListView = (what?)
141 * 2 : pszRule = (what?)
142 * 3 : bAllow = (what?)
146 *********************************************************************/
147 static void InsertRule(HWND hwndListView, const char *pszRule, BOOL bAllow)
150 item.mask = LVIF_TEXT | LVIF_IMAGE;
151 item.pszText = (char *)pszRule;
152 item.iItem = ListView_GetItemCount(hwndListView) + 1;
154 item.iImage = bAllow ? IMAGE_ALLOW : IMAGE_DENY;
155 ListView_InsertItem(hwndListView, &item);
156 /* TODO add subitem for whether the rule is always or never */
161 /*********************************************************************
163 * Function : SetDirty
165 * Description : (Please fill me in!)
168 * 1 : bDirty = (what?)
172 *********************************************************************/
173 static void SetDirty(BOOL bDirty)
176 /* TODO Change some values */
181 /*********************************************************************
183 * Function : OnInitDialog
185 * Description : (Please fill me in!)
188 * 1 : hwndDlg = (what?)
192 *********************************************************************/
193 static void OnInitDialog(HWND hwndDlg)
200 if (g_hImageList == NULL)
202 /* Create image list and add icons */
203 HICON hIconDeny = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_DENYRULE), IMAGE_ICON, nSmallIconWidth, nSmallIconHeight, 0);
204 HICON hIconAllow = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ALLOWRULE), IMAGE_ICON, nSmallIconWidth, nSmallIconHeight, 0);
205 g_hImageList = ImageList_Create(nSmallIconWidth, nSmallIconHeight, ILC_COLOR | ILC_MASK, 0, 10);
206 ImageList_AddIcon(g_hImageList, hIconAllow);
207 ImageList_AddIcon(g_hImageList, hIconDeny);
210 /* Set the default rule value if there is one */
211 if (g_pszDefaultRule)
213 SetDlgItemText(hwndDlg, IDC_NEW, g_pszDefaultRule);
214 SetDefaultRule(NULL);
217 /* Initialise the list view */
218 hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
219 ListView_SetImageList(hwndListView, g_hImageList, LVSIL_SMALL);
220 GetClientRect(hwndListView, &rcListView);
221 cx = rcListView.right - rcListView.left;
222 aCols[0].mask = LVCF_TEXT | LVCF_WIDTH;
223 aCols[0].pszText = "Rule";
224 aCols[0].cx = (70 * cx) / 100;
225 aCols[1].mask = LVCF_TEXT | LVCF_WIDTH;
226 aCols[1].pszText = "Applies when";
227 aCols[1].cx = cx - aCols[0].cx;
228 ListView_InsertColumn(hwndListView, 0, &aCols[0]);
229 ListView_InsertColumn(hwndListView, 1, &aCols[1]);
231 /* Read and add rules to the list */
233 InsertRule(hwndListView, "Test rule 1", TRUE);
234 InsertRule(hwndListView, "Test rule 2", TRUE);
235 InsertRule(hwndListView, "Test rule 3", FALSE);
236 InsertRule(hwndListView, "Test rule 4", FALSE);
241 /*********************************************************************
243 * Function : GetFirstSelectedItem
245 * Description : (Please fill me in!)
248 * 1 : hwndDlg = (what?)
250 * Returns : (Please fill me in!)
252 *********************************************************************/
253 static int GetFirstSelectedItem(HWND hwndDlg)
255 /* Check for selected items */
256 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
260 nItem = ListView_GetNextItem(hwndListView, nItem, LVNI_SELECTED);
265 } while (nItem >= 0);
271 /*********************************************************************
273 * Function : OnRulesItemChanged
275 * Description : (Please fill me in!)
278 * 1 : hwndDlg = (what?)
282 *********************************************************************/
283 static void OnRulesItemChanged(HWND hwndDlg)
285 int nItem = GetFirstSelectedItem(hwndDlg);
286 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
287 int nItems = ListView_GetItemCount(hwndListView);
288 BOOL bHaveSelection = (nItem >= 0) ? TRUE : FALSE;
289 BOOL bMoveUp = (bHaveSelection && nItem > 0) ? TRUE : FALSE;
290 BOOL bMoveDown = (bHaveSelection && nItem < nItems - 1) ? TRUE : FALSE;
292 /* Enable/disable buttons */
293 EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), bHaveSelection);
294 EnableWindow(GetDlgItem(hwndDlg, IDC_MOVEUP), bMoveUp);
295 EnableWindow(GetDlgItem(hwndDlg, IDC_MOVEDOWN), bMoveDown);
300 /*********************************************************************
302 * Function : MoveRules
304 * Description : (Please fill me in!)
307 * 1 : hwndDlg = (what?)
308 * 2 : bMoveUp = (what?)
312 *********************************************************************/
313 static void MoveRules(HWND hwndDlg, BOOL bMoveUp)
318 /*********************************************************************
320 * Function : OnMoveRuleUpClick
322 * Description : (Please fill me in!)
325 * 1 : hwndDlg = (what?)
329 *********************************************************************/
330 static void OnMoveRuleUpClick(HWND hwndDlg)
335 /*********************************************************************
337 * Function : OnMoveRuleDownClick
339 * Description : (Please fill me in!)
342 * 1 : hwndDlg = (what?)
346 *********************************************************************/
347 static void OnMoveRuleDownClick(HWND hwndDlg)
352 /*********************************************************************
354 * Function : OnCreateRuleClick
356 * Description : (Please fill me in!)
359 * 1 : hwndDlg = (what?)
363 *********************************************************************/
364 static void OnCreateRuleClick(HWND hwndDlg)
369 /*********************************************************************
371 * Function : OnDeleteRuleClick
373 * Description : (Please fill me in!)
376 * 1 : hwndDlg = (what?)
380 *********************************************************************/
381 static void OnDeleteRuleClick(HWND hwndDlg)
383 /* Get selection and remove it */
384 int nItem = GetFirstSelectedItem(hwndDlg);
388 HWND hwndListView = GetDlgItem(hwndDlg, IDC_RULES);
389 item.mask = LVIF_PARAM;
392 ListView_GetItem(hwndListView, &item);
393 /* TODO erase data stored with item */
394 ListView_DeleteItem(hwndListView, nItem);
400 /*********************************************************************
402 * Function : OnCommand
404 * Description : (Please fill me in!)
407 * 1 : hwndDlg = (what?)
408 * 2 : nCommand = (what?)
409 * 3 : nNotifyCode = (what?)
410 * 4 : hwndItem = (what?)
414 *********************************************************************/
415 static void OnCommand(HWND hwndDlg, int nCommand, int nNotifyCode, HWND hwndItem)
421 EndDialog(hwndDlg, IDOK);
424 if (nNotifyCode == BN_CLICKED)
426 OnCreateRuleClick(hwndDlg);
430 if (nNotifyCode == BN_CLICKED)
432 OnDeleteRuleClick(hwndDlg);
436 if (nNotifyCode == BN_CLICKED)
438 OnMoveRuleUpClick(hwndDlg);
442 if (nNotifyCode == BN_CLICKED)
444 OnMoveRuleDownClick(hwndDlg);
452 /*********************************************************************
454 * Function : OnNotify
456 * Description : (Please fill me in!)
459 * 1 : hwndDlg = (what?)
460 * 2 : nIdCtrl = (what?)
465 *********************************************************************/
466 static void OnNotify(HWND hwndDlg, int nIdCtrl, LPNMHDR pnmh)
473 case LVN_ITEMCHANGED:
474 OnRulesItemChanged(hwndDlg);
483 /*********************************************************************
485 * Function : OnDestroy
487 * Description : (Please fill me in!)
490 * 1 : hwndDlg = (what?)
494 *********************************************************************/
495 static void OnDestroy(HWND hwndDlg)
497 /* TODO any destruction cleanup */
502 /*********************************************************************
504 * Function : DialogProc
506 * Description : (Please fill me in!)
509 * 1 : hwndDlg = (what?)
511 * 3 : wParam = (what?)
512 * 4 : lParam = (what?)
514 * Returns : (Please fill me in!)
516 *********************************************************************/
517 static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
522 OnInitDialog(hwndDlg);
530 OnCommand(hwndDlg, LOWORD(wParam), HIWORD(wParam), (HWND) lParam);
534 OnNotify(hwndDlg, (int) wParam, (LPNMHDR) lParam);
541 #endif /* def WIN_GUI_EDIT - entire file */
542 #endif /* ndef _WIN_CONSOLE - entire file */