2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
14 #include <afs/param.h>
20 #include "propcache.h"
23 #define REGVAL_INCLUSIVE TEXT("Inclusive List")
26 * PROTOTYPES _________________________________________________________________
30 BOOL CALLBACK
Subsets_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
31 void Subsets_OnInitDialog (HWND hDlg
, LPSUBSET sub
);
32 void Subsets_OnApply (HWND hDlg
, LPSUBSET sub
);
33 LPSUBSET
Subsets_OnLoad (HWND hDlg
, LPSUBSET sub
);
34 void Subsets_OnSave (HWND hDlg
, LPSUBSET sub
);
35 void Subsets_SetName (HWND hDlg
, LPSUBSET sub
);
36 void Subsets_PutSubsetOnDialog (HWND hDlg
, LPSUBSET sub
);
37 void Subsets_GetSubsetFromDialog (HWND hDlg
, LPSUBSET sub
);
38 LPSUBSET
Subsets_OnCheck (HWND hDlg
, int iSel
, LPSUBSET subOld
);
39 LPSUBSET
Subsets_OnCheckAll (HWND hDlg
, LPSUBSET subOld
, BOOL fCheck
);
41 BOOL
Subsets_GetLoadName (HWND hParent
, LPTSTR pszSubset
);
42 BOOL
Subsets_GetSaveName (HWND hParent
, LPTSTR pszSubset
);
46 * ROUTINES ___________________________________________________________________
50 BOOL
Subsets_fMonitorServer (LPSUBSET sub
, LPIDENT lpiServer
)
54 TCHAR szLong
[ cchNAME
];
55 TCHAR szShort
[ cchNAME
];
56 lpiServer
->GetLongServerName (szLong
);
57 lpiServer
->GetShortServerName (szShort
);
61 if (sub
->pszMonitored
)
63 fMonitor
= FALSE
; // unless it shows up here.
65 for (LPTSTR psz
= sub
->pszMonitored
; !fMonitor
&& *psz
; psz
+= 1+lstrlen(psz
))
67 if (!lstrcmpi (psz
, szLong
))
69 else if (!lstrcmpi (psz
, szShort
))
73 else if (sub
->pszUnmonitored
)
75 for (LPTSTR psz
= sub
->pszUnmonitored
; fMonitor
&& *psz
; psz
+= 1+lstrlen(psz
))
77 if (!lstrcmpi (psz
, szLong
))
79 else if (!lstrcmpi (psz
, szShort
))
89 LPSUBSET
Subsets_SetMonitor (LPSUBSET sub
, LPIDENT lpiServer
, BOOL fMonitor
)
94 memset (sub
, 0x00, sizeof(SUBSET
));
97 if (fMonitor
!= Subsets_fMonitorServer (sub
, lpiServer
))
99 sub
->fModified
= TRUE
;
101 TCHAR szLong
[ cchNAME
];
102 TCHAR szShort
[ cchNAME
];
103 lpiServer
->GetShortServerName (szShort
);
104 lpiServer
->GetLongServerName (szLong
);
106 // First ensure that the server name doesn't appear anywhere
109 LPTSTR pszMonitoredNew
= NULL
;
110 LPTSTR pszUnmonitoredNew
= NULL
;
112 if (sub
->pszMonitored
)
114 for (LPTSTR psz
= sub
->pszMonitored
; *psz
; psz
+= 1+lstrlen(psz
))
116 if (lstrcmpi (psz
, szLong
) && lstrcmpi (psz
, szShort
))
118 FormatMultiString (&pszMonitoredNew
, TRUE
, TEXT("%1"), TEXT("%s"), psz
);
122 else if (sub
->pszUnmonitored
)
124 for (LPTSTR psz
= sub
->pszUnmonitored
; *psz
; psz
+= 1+lstrlen(psz
))
126 if (lstrcmpi (psz
, szLong
) && lstrcmpi (psz
, szShort
))
128 FormatMultiString (&pszUnmonitoredNew
, TRUE
, TEXT("%1"), TEXT("%s"), psz
);
133 // Then ensure it shows up only where necessary.
135 if (sub
->pszMonitored
&& fMonitor
)
137 FormatMultiString (&pszMonitoredNew
, TRUE
, TEXT("%1"), TEXT("%s"), szLong
);
139 else if (!sub
->pszMonitored
&& !fMonitor
)
141 FormatMultiString (&pszUnmonitoredNew
, TRUE
, TEXT("%1"), TEXT("%s"), szLong
);
144 if (sub
->pszMonitored
&& !pszMonitoredNew
)
146 pszMonitoredNew
= AllocateString (2);
147 pszMonitoredNew
[0] = TEXT('\0');
148 pszMonitoredNew
[1] = TEXT('\0');
150 if (sub
->pszUnmonitored
&& !pszUnmonitoredNew
)
152 pszUnmonitoredNew
= AllocateString (2);
153 pszUnmonitoredNew
[0] = TEXT('\0');
154 pszUnmonitoredNew
[1] = TEXT('\0');
157 // Finally, update the subset's members.
159 if (sub
->pszMonitored
)
160 FreeString (sub
->pszMonitored
);
161 if (sub
->pszUnmonitored
)
162 FreeString (sub
->pszUnmonitored
);
164 sub
->pszMonitored
= pszMonitoredNew
;
165 sub
->pszUnmonitored
= pszUnmonitoredNew
;
172 void ShowSubsetsDialog (void)
174 LPPROPSHEET psh
= PropSheet_Create (IDS_SUBSET_TAB
, FALSE
);
175 psh
->sh
.hwndParent
= g
.hMain
;
177 LPSUBSET sub
= Subsets_CopySubset (g
.sub
);
178 PropSheet_AddTab (psh
, 0, IDD_SUBSETS
, (DLGPROC
)Subsets_DlgProc
, (LPARAM
)sub
, TRUE
);
179 PropSheet_ShowModal (psh
, PumpMessage
);
183 BOOL CALLBACK
Subsets_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
185 if (AfsAppLib_HandleHelp (IDD_SUBSETS
, hDlg
, msg
, wp
, lp
))
188 if (msg
== WM_INITDIALOG
)
189 SetWindowLongPtr (hDlg
, DWLP_USER
, ((LPPROPSHEETPAGE
)lp
)->lParam
);
191 LPSUBSET sub
= (LPSUBSET
)GetWindowLongPtr (hDlg
, DWLP_USER
);
195 case WM_INITDIALOG_SHEET
:
196 PropCache_Add (pcGENERAL
, NULL
, hDlg
);
199 case WM_DESTROY_SHEET
:
200 PropCache_Delete (hDlg
);
204 Subsets_OnInitDialog (hDlg
, sub
);
211 Subsets_OnApply (hDlg
, sub
);
216 EndDialog (hDlg
, LOWORD(wp
));
219 case IDC_SUBSET_LOAD
:
221 subNew
= Subsets_OnLoad (hDlg
, sub
);
225 Subsets_FreeSubset (sub
);
226 SetWindowLongPtr (hDlg
, DWLP_USER
, (LONG_PTR
)subNew
);
230 case IDC_SUBSET_LIST
:
231 if (HIWORD(wp
) == LBN_CLICKED
) // checked or unchecked?
233 int iSel
= LB_GetSelected (GetDlgItem (hDlg
, IDC_SUBSET_LIST
));
234 subNew
= Subsets_OnCheck (hDlg
, iSel
, sub
);
235 if (subNew
&& (subNew
!= sub
))
238 Subsets_FreeSubset (sub
);
239 SetWindowLongPtr (hDlg
, DWLP_USER
, (LONG_PTR
)subNew
);
244 case IDC_SUBSET_SAVE
:
245 Subsets_OnSave (hDlg
, sub
);
249 case IDC_SUBSET_NONE
:
250 subNew
= Subsets_OnCheckAll (hDlg
, sub
, (LOWORD(wp
) == IDC_SUBSET_ALL
) ? TRUE
: FALSE
);
251 if (subNew
&& (subNew
!= sub
))
254 Subsets_FreeSubset (sub
);
255 SetWindowLongPtr (hDlg
, DWLP_USER
, (LONG_PTR
)subNew
);
266 void Subsets_OnInitDialog (HWND hDlg
, LPSUBSET sub
)
268 Subsets_SetName (hDlg
, sub
);
269 Subsets_PutSubsetOnDialog (hDlg
, sub
);
273 void Subsets_SetName (HWND hDlg
, LPSUBSET sub
)
277 BOOL fIsOneServer
= FALSE
;
278 if (sub
&& sub
->pszMonitored
&& *(sub
->pszMonitored
))
280 LPTSTR pszNext
= &sub
->pszMonitored
[ 1+lstrlen(sub
->pszMonitored
) ];
285 if (sub
&& sub
->szSubset
[0])
288 pszText
= FormatString (IDS_SUBSET_CHANGED
, TEXT("%s"), sub
->szSubset
);
290 pszText
= FormatString (TEXT("%1"), TEXT("%s"), sub
->szSubset
);
292 else if (fIsOneServer
)
294 pszText
= FormatString (IDS_SUBSET_SERVERSUBSET
, TEXT("%s"), sub
->pszMonitored
);
296 else if (sub
) // && !sub->szSubset[0]
299 pszText
= FormatString (IDS_SUBSET_CHANGED
, TEXT("%m"), IDS_SUBSET_NONAME
);
301 pszText
= FormatString (TEXT("%1"), TEXT("%m"), IDS_SUBSET_NONAME
);
303 else // no current subset specified
305 pszText
= FormatString (TEXT("%1"), TEXT("%m"), IDS_SUBSET_NOSUBSET
);
308 SetDlgItemText (hDlg
, IDC_SUBSET_NAME
, pszText
);
309 FreeString (pszText
);
313 void Subsets_PutSubsetOnDialog (HWND hDlg
, LPSUBSET sub
)
315 LPSUBSET_TO_LIST_PACKET lpp
= New (SUBSET_TO_LIST_PACKET
);
316 memset (lpp
, 0x00, sizeof(SUBSET_TO_LIST_PACKET
));
318 lpp
->hList
= GetDlgItem (hDlg
, IDC_SUBSET_LIST
);
319 lpp
->sub
= Subsets_CopySubset (sub
);
321 StartTask (taskSUBSET_TO_LIST
, NULL
, lpp
);
325 void Subsets_GetSubsetFromDialog (HWND hDlg
, LPSUBSET sub
)
327 HWND hList
= GetDlgItem (hDlg
, IDC_SUBSET_LIST
);
329 if (sub
->pszMonitored
)
331 FreeString (sub
->pszMonitored
);
332 sub
->pszMonitored
= NULL
;
334 if (sub
->pszUnmonitored
)
336 FreeString (sub
->pszUnmonitored
);
337 sub
->pszUnmonitored
= NULL
;
340 // Is there only one server box checked?
342 int iiMax
= (int) SendMessage (hList
, LB_GETCOUNT
, 0, 0);
346 for (int ii
= 0; ii
< iiMax
; ++ii
)
348 if (LB_GetCheck (hList
, ii
))
351 if ((++cChecked
) > 1)
355 if (cChecked
== 1) // Only one is checked--use pszMonitored.
357 TCHAR szServer
[ cchNAME
];
358 SendMessage (hList
, LB_GETTEXT
, iiChecked
, (LPARAM
)szServer
);
359 FormatMultiString (&sub
->pszMonitored
, TRUE
, TEXT("%1"), TEXT("%s"), szServer
);
361 else // Use pszUnmonitored.
363 for (int ii
= 0; ii
< iiMax
; ++ii
)
365 if (!LB_GetCheck (hList
, ii
))
367 TCHAR szServer
[ cchNAME
];
368 SendMessage (hList
, LB_GETTEXT
, ii
, (LPARAM
)szServer
);
369 FormatMultiString (&sub
->pszUnmonitored
, TRUE
, TEXT("%1"), TEXT("%s"), szServer
);
376 LPSUBSET
Subsets_OnCheck (HWND hDlg
, int iSel
, LPSUBSET subOld
)
378 LPSUBSET sub
= subOld
;
379 HWND hList
= GetDlgItem (hDlg
, IDC_SUBSET_LIST
);
381 if (!LB_GetCheck (hList
, iSel
)) // unchecked?
386 memset (sub
, 0x00, sizeof(SUBSET
));
392 sub
->fModified
= TRUE
;
393 Subsets_GetSubsetFromDialog (hDlg
, sub
);
394 Subsets_SetName (hDlg
, sub
);
395 PropSheetChanged (hDlg
);
402 LPSUBSET
Subsets_OnCheckAll (HWND hDlg
, LPSUBSET subOld
, BOOL fCheck
)
404 LPSUBSET sub
= subOld
;
405 HWND hList
= GetDlgItem (hDlg
, IDC_SUBSET_LIST
);
407 if (!fCheck
) // unchecking things?
412 memset (sub
, 0x00, sizeof(SUBSET
));
416 int iiMax
= (int) SendMessage (hList
, LB_GETCOUNT
, 0, 0);
418 for (int ii
= 0; ii
< iiMax
; ++ii
)
420 if (LB_GetCheck (hList
, ii
) != fCheck
)
422 LB_SetCheck (hList
, ii
, fCheck
);
428 sub
->fModified
= TRUE
;
429 Subsets_GetSubsetFromDialog (hDlg
, sub
);
430 Subsets_SetName (hDlg
, sub
);
431 PropSheetChanged (hDlg
);
438 LPSUBSET
Subsets_OnLoad (HWND hDlg
, LPSUBSET subOld
)
440 LPSUBSET subNew
= NULL
;
442 TCHAR szSubset
[ cchNAME
] = TEXT("");
444 lstrcpy (szSubset
, subOld
->szSubset
);
446 if (Subsets_GetLoadName (hDlg
, szSubset
))
448 if ((subNew
= Subsets_LoadSubset (NULL
, szSubset
)) != NULL
)
450 Subsets_SetName (hDlg
, subNew
);
451 Subsets_PutSubsetOnDialog (hDlg
, subNew
);
452 PropSheetChanged (hDlg
);
460 void Subsets_OnSave (HWND hDlg
, LPSUBSET sub
)
464 TCHAR szSubset
[ cchNAME
];
465 lstrcpy (szSubset
, sub
->szSubset
);
467 if (Subsets_GetSaveName (hDlg
, szSubset
))
469 Subsets_GetSubsetFromDialog (hDlg
, sub
);
471 if (Subsets_SaveSubset (NULL
, szSubset
, sub
))
473 lstrcpy (sub
->szSubset
, szSubset
);
474 sub
->fModified
= FALSE
;
476 Subsets_SetName (hDlg
, sub
);
483 void Subsets_OnApply (HWND hDlg
, LPSUBSET sub
)
486 if ((subCopy
= Subsets_CopySubset (sub
, TRUE
)) != NULL
)
488 Subsets_GetSubsetFromDialog (hDlg
, subCopy
);
491 LPSUBSET subOld
= g
.sub
;
494 Subsets_FreeSubset (subOld
);
496 StartTask (taskAPPLY_SUBSET
, NULL
, sub
);
500 BOOL
Subsets_SaveIfDirty (LPSUBSET sub
)
502 if (!sub
|| !sub
->fModified
)
506 rc
= Message (MB_YESNOCANCEL
| MB_ICONQUESTION
, IDS_SUBSET_DISCARD_TITLE
, IDS_SUBSET_DISCARD_DESC
);
510 sub
->fModified
= FALSE
;
511 sub
->szSubset
[0] = TEXT('\0');
513 else if (rc
== IDYES
)
515 TCHAR szSubset
[ cchNAME
];
516 lstrcpy (szSubset
, sub
->szSubset
);
518 if (!Subsets_GetSaveName (g
.hMain
, szSubset
))
521 if (!Subsets_SaveSubset (NULL
, szSubset
, sub
))
524 sub
->fModified
= FALSE
;
525 lstrcpy (sub
->szSubset
, szSubset
);
527 else // (rc == IDCANCEL)
536 BOOL
Subsets_EnumSubsets (LPTSTR pszCell
, size_t iIndex
, LPTSTR pszSubset
)
541 if ((hk
= OpenSubsetsKey (pszCell
, FALSE
)) != NULL
)
543 if (RegEnumKey (hk
, (DWORD
)iIndex
, pszSubset
, cchNAME
) == 0)
553 BOOL
Subsets_SaveSubset (LPTSTR pszCell
, LPTSTR pszSubset
, LPSUBSET sub
)
557 if (sub
&& pszSubset
&& *pszSubset
)
560 if ((hk
= OpenSubsetsSubKey (pszCell
, pszSubset
, TRUE
)) != NULL
)
562 DWORD dwMonitored
= (sub
->pszMonitored
) ? 1 : 0;
563 RegSetValueEx (hk
, REGVAL_INCLUSIVE
, 0, REG_DWORD
, (LPBYTE
)&dwMonitored
, sizeof(DWORD
));
565 for (LPTSTR psz
= (sub
->pszMonitored
) ? sub
->pszMonitored
: sub
->pszUnmonitored
;
567 psz
+= 1+lstrlen(psz
))
569 RegSetValueEx (hk
, psz
, 0, REG_SZ
, (PBYTE
)TEXT("X"), sizeof(TCHAR
)*2);
582 LPSUBSET
Subsets_LoadSubset (LPTSTR pszCell
, LPTSTR pszSubset
)
587 if ((hk
= OpenSubsetsSubKey (pszCell
, pszSubset
, FALSE
)) != NULL
)
592 dwSize
= sizeof(dwMonitored
);
593 if (RegQueryValueEx (hk
, REGVAL_INCLUSIVE
, 0, &dwType
, (LPBYTE
)&dwMonitored
, &dwSize
) == 0)
596 memset (sub
, 0x00, sizeof(SUBSET
));
597 lstrcpy (sub
->szSubset
, pszSubset
);
598 sub
->fModified
= FALSE
;
601 ppsz
= (dwMonitored
) ? &sub
->pszMonitored
: &sub
->pszUnmonitored
;
603 for (size_t iIndex
= 0; ; ++iIndex
)
605 TCHAR szServer
[ cchNAME
];
606 dwSize
= sizeof(szServer
);
608 if (RegEnumValue (hk
, (DWORD
)iIndex
, szServer
, &dwSize
, 0, NULL
, NULL
, NULL
) != 0)
611 if (szServer
[0] && lstrcmpi (szServer
, REGVAL_INCLUSIVE
))
612 FormatMultiString (ppsz
, FALSE
, TEXT("%1"), TEXT("%s"), szServer
);
615 if (dwMonitored
&& !sub
->pszMonitored
)
617 sub
->pszMonitored
= AllocateString(2);
618 sub
->pszMonitored
[0] = TEXT('\0');
619 sub
->pszMonitored
[1] = TEXT('\0');
630 LPSUBSET
Subsets_CopySubset (LPSUBSET sub
, BOOL fCreateIfNULL
)
632 LPSUBSET subCopy
= NULL
;
636 subCopy
= New (SUBSET
);
637 memset (subCopy
, 0x00, sizeof(SUBSET
));
638 lstrcpy (subCopy
->szSubset
, sub
->szSubset
);
639 subCopy
->fModified
= sub
->fModified
;
642 if (sub
->pszMonitored
)
645 for (LPTSTR psz
= sub
->pszMonitored
; *psz
; psz
+= 1+lstrlen(psz
))
646 cch
+= 1+lstrlen(psz
);
647 subCopy
->pszMonitored
= AllocateString (cch
);
648 memcpy (subCopy
->pszMonitored
, sub
->pszMonitored
, sizeof(TCHAR
)*cch
);
651 if (sub
->pszUnmonitored
)
654 for (LPTSTR psz
= sub
->pszUnmonitored
; *psz
; psz
+= 1+lstrlen(psz
))
655 cch
+= 1+lstrlen(psz
);
656 subCopy
->pszUnmonitored
= AllocateString (cch
);
657 memcpy (subCopy
->pszUnmonitored
, sub
->pszUnmonitored
, sizeof(TCHAR
)*cch
);
660 else if (fCreateIfNULL
)
662 subCopy
= New (SUBSET
);
663 memset (subCopy
, 0x00, sizeof(SUBSET
));
670 void Subsets_FreeSubset (LPSUBSET sub
)
674 if (sub
->pszMonitored
)
675 FreeString (sub
->pszMonitored
);
676 if (sub
->pszUnmonitored
)
677 FreeString (sub
->pszUnmonitored
);
685 * SUBSET OPEN/SAVE DIALOG ____________________________________________________
692 TCHAR szCell
[ cchNAME
];
693 TCHAR szSubset
[ cchNAME
];
694 } SUBSET_OPENSAVE_PARAMS
, *LPSUBSET_OPENSAVE_PARAMS
;
696 BOOL CALLBACK
Subsets_OpenSave_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
697 void Subsets_OpenSave_OnInitDialog (HWND hDlg
, LPSUBSET_OPENSAVE_PARAMS lpp
);
698 void Subsets_OpenSave_OnSelect (HWND hDlg
);
699 void Subsets_OpenSave_Populate (HWND hDlg
);
700 void Subsets_OpenSave_OnDelete (HWND hDlg
);
701 void Subsets_OpenSave_OnRename (HWND hDlg
);
704 BOOL
Subsets_GetLoadName (HWND hParent
, LPTSTR pszSubset
)
706 SUBSET_OPENSAVE_PARAMS lpp
;
708 lpp
.szCell
[0] = TEXT('\0');
709 lstrcpy (lpp
.szSubset
, pszSubset
);
712 g
.lpiCell
->GetCellName (lpp
.szCell
);
714 INT_PTR rc
= ModalDialogParam (IDD_SUBSET_LOADSAVE
,
715 hParent
, (DLGPROC
)Subsets_OpenSave_DlgProc
,
720 lstrcpy (pszSubset
, lpp
.szSubset
);
723 return (rc
== IDOK
) ? TRUE
: FALSE
;
727 BOOL
Subsets_GetSaveName (HWND hParent
, LPTSTR pszSubset
)
729 SUBSET_OPENSAVE_PARAMS lpp
;
731 lpp
.szCell
[0] = TEXT('\0');
732 lstrcpy (lpp
.szSubset
, pszSubset
);
735 g
.lpiCell
->GetCellName (lpp
.szCell
);
737 INT_PTR rc
= ModalDialogParam (IDD_SUBSET_LOADSAVE
,
738 hParent
, (DLGPROC
)Subsets_OpenSave_DlgProc
,
743 lstrcpy (pszSubset
, lpp
.szSubset
);
746 return (rc
== IDOK
) ? TRUE
: FALSE
;
750 BOOL CALLBACK
Subsets_OpenSave_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
752 static BOOL fEditing
= FALSE
;
754 if (msg
== WM_INITDIALOG
)
755 SetWindowLongPtr (hDlg
, DWLP_USER
, lp
);
757 LPSUBSET_OPENSAVE_PARAMS lpp
;
758 if ((lpp
= (LPSUBSET_OPENSAVE_PARAMS
)GetWindowLongPtr (hDlg
, DWLP_USER
)) != NULL
)
764 Subsets_OpenSave_OnInitDialog (hDlg
, lpp
);
773 EndDialog (hDlg
, IDCANCEL
);
777 GetDlgItemText (hDlg
, IDC_SUBSET_NAME
, lpp
->szSubset
, cchNAME
);
778 if (lpp
->szSubset
[0] != TEXT('\0'))
785 if ((hk
= OpenSubsetsSubKey (NULL
, lpp
->szSubset
, FALSE
)) != NULL
)
789 int rc
= Message (MB_YESNO
| MB_ICONASTERISK
, IDS_SUBSET_SAVE_TITLE
, IDS_SUBSET_SAVE_DESC
, TEXT("%s"), lpp
->szSubset
);
796 EndDialog (hDlg
, IDOK
);
800 case IDC_SUBSET_DELETE
:
801 Subsets_OpenSave_OnDelete (hDlg
);
804 case IDC_SUBSET_RENAME
:
805 Subsets_OpenSave_OnRename (hDlg
);
812 switch (((LPNMHDR
)lp
)->code
)
814 case LVN_ITEMCHANGED
:
817 if ( ((LPNM_LISTVIEW
)lp
)->uNewState
& LVIS_SELECTED
)
818 Subsets_OpenSave_OnSelect (hDlg
);
825 if (((LPNMHDR
)lp
)->hwndFrom
== GetDlgItem (hDlg
, IDC_SUBSET_LIST
))
827 Subsets_OpenSave_OnSelect (hDlg
);
828 PostMessage (hDlg
, WM_COMMAND
, IDOK
, 0);
833 case LVN_BEGINLABELEDIT
:
835 return FALSE
; // okay to edit label
837 case LVN_ENDLABELEDIT
:
839 if ((plvdi
= (LV_DISPINFO
*)lp
) != NULL
)
841 if ((plvdi
->item
.iItem
!= -1) &&
842 (plvdi
->item
.pszText
!= NULL
))
844 HWND hList
= GetDlgItem (hDlg
, IDC_SUBSET_LIST
);
845 TCHAR szOldName
[ cchNAME
];
846 LV_GetItemText (hList
, plvdi
->item
.iItem
, 0, szOldName
);
848 if (lstrcmpi (szOldName
, plvdi
->item
.pszText
))
851 BOOL fRepopulate
= FALSE
;
854 if ((hk
= OpenSubsetsSubKey (NULL
, plvdi
->item
.pszText
, FALSE
)) != NULL
)
858 int rc
= Message (MB_YESNO
| MB_ICONASTERISK
, IDS_SUBSET_SAVE_TITLE
, IDS_SUBSET_SAVE_DESC
, TEXT("%s"), lpp
->szSubset
);
868 if ((subRename
= Subsets_LoadSubset (NULL
, szOldName
)) != NULL
)
870 if (Subsets_SaveSubset (NULL
, plvdi
->item
.pszText
, subRename
))
872 (void)OpenSubsetsSubKey (NULL
, szOldName
, 2); // 0=open,1=create,2=delete
875 Subsets_OpenSave_Populate (hDlg
);
878 LV_SetItemText (hList
, plvdi
->item
.iItem
, 0, plvdi
->item
.pszText
);
879 Subsets_OpenSave_OnSelect (hDlg
);
882 Subsets_FreeSubset (subRename
);
901 void Subsets_OpenSave_OnInitDialog (HWND hDlg
, LPSUBSET_OPENSAVE_PARAMS lpp
)
903 // Fix the buttons in the toolbar, so that they looks pretty
905 HWND hButton
= GetDlgItem (hDlg
, IDC_SUBSET_DELETE
);
906 HICON hi
= TaLocale_LoadIcon (IDI_BTN_DELETE
);
907 SendMessage (hButton
, BM_SETIMAGE
, (WPARAM
)IMAGE_ICON
, (LPARAM
)hi
);
909 hButton
= GetDlgItem (hDlg
, IDC_SUBSET_RENAME
);
910 hi
= TaLocale_LoadIcon (IDI_BTN_RENAME
);
911 SendMessage (hButton
, BM_SETIMAGE
, (WPARAM
)IMAGE_ICON
, (LPARAM
)hi
);
913 // Set up an ImageList so we'll have icons in the ListView
915 HWND hList
= GetDlgItem (hDlg
, IDC_SUBSET_LIST
);
916 HIMAGELIST hil
= ImageList_Create (16, 16, ILC_COLOR4
| ILC_MASK
, 1, 1);
918 hi
= TaLocale_LoadIcon (IDI_SUBSET
);
919 ImageList_AddIcon (hil
, hi
);
921 ListView_SetImageList (hList
, hil
, LVSIL_SMALL
);
923 // Then populate the ListView with the names of the subsets
924 // defined for this cell
926 Subsets_OpenSave_Populate (hDlg
);
927 // Finally, fill in the rest of the dialog.
929 SetDlgItemText (hDlg
, IDC_SUBSET_NAME
, lpp
->szSubset
);
931 TCHAR szText
[ cchRESOURCE
];
932 GetString (szText
, (lpp
->fOpen
) ? IDS_SUBSET_TITLE_LOAD
: IDS_SUBSET_TITLE_SAVE
);
933 SetWindowText (hDlg
, szText
);
935 GetString (szText
, (lpp
->fOpen
) ? IDS_BUTTON_OPEN
: IDS_BUTTON_SAVE
);
936 SetDlgItemText (hDlg
, IDOK
, szText
);
940 void Subsets_OpenSave_Populate (HWND hDlg
)
942 HWND hList
= GetDlgItem (hDlg
, IDC_SUBSET_LIST
);
943 LV_StartChange (hList
, TRUE
);
945 TCHAR szSubset
[ cchNAME
];
946 for (size_t iIndex
= 0; Subsets_EnumSubsets (NULL
, iIndex
, szSubset
); ++iIndex
)
948 LV_AddItem (hList
, 1, 0, 0, 0, szSubset
);
951 LV_EndChange (hList
);
955 void Subsets_OpenSave_OnSelect (HWND hDlg
)
957 TCHAR szSubset
[ cchNAME
];
959 HWND hList
= GetDlgItem (hDlg
, IDC_SUBSET_LIST
);
960 short idxSelected
= LV_GetSelected (hList
);
962 if (idxSelected
== -1)
963 szSubset
[0] = TEXT('\0');
965 LV_GetItemText (hList
, idxSelected
, 0, szSubset
);
967 SetDlgItemText (hDlg
, IDC_SUBSET_NAME
, szSubset
);
971 void Subsets_OpenSave_OnDelete (HWND hDlg
)
973 HWND hList
= GetDlgItem (hDlg
, IDC_SUBSET_LIST
);
974 short idxSelected
= LV_GetSelected (hList
);
976 if (idxSelected
!= -1)
978 TCHAR szSubset
[ cchNAME
];
979 LV_GetItemText (hList
, idxSelected
, 0, szSubset
);
981 if (Message (MB_ICONASTERISK
| MB_YESNO
, IDS_SUBSET_DELETE_TITLE
, IDS_SUBSET_DELETE_DESC
, TEXT("%s"), szSubset
) == IDYES
)
983 (void)OpenSubsetsSubKey (NULL
, szSubset
, 2); // 0=open,1=create,2=delete
984 Subsets_OpenSave_Populate (hDlg
);
990 void Subsets_OpenSave_OnRename (HWND hDlg
)
992 HWND hList
= GetDlgItem (hDlg
, IDC_SUBSET_LIST
);
993 short idxSelected
= LV_GetSelected (hList
);
995 if (idxSelected
!= -1)
998 ListView_EditLabel (hList
, idxSelected
);