Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / subset.cpp
blob75a14e7e1f36df9e8f3568f3bffe7e2736abf1d4
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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
8 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "svrmgr.h"
19 #include "subset.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)
52 BOOL fMonitor = TRUE;
54 TCHAR szLong[ cchNAME ];
55 TCHAR szShort[ cchNAME ];
56 lpiServer->GetLongServerName (szLong);
57 lpiServer->GetShortServerName (szShort);
59 if (sub)
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))
68 fMonitor = TRUE;
69 else if (!lstrcmpi (psz, szShort))
70 fMonitor = TRUE;
73 else if (sub->pszUnmonitored)
75 for (LPTSTR psz = sub->pszUnmonitored; fMonitor && *psz; psz += 1+lstrlen(psz))
77 if (!lstrcmpi (psz, szLong))
78 fMonitor = FALSE;
79 else if (!lstrcmpi (psz, szShort))
80 fMonitor = FALSE;
85 return fMonitor;
89 LPSUBSET Subsets_SetMonitor (LPSUBSET sub, LPIDENT lpiServer, BOOL fMonitor)
91 if (sub == NULL)
93 sub = New (SUBSET);
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
107 // in the subset.
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;
168 return sub;
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))
186 return TRUE;
188 if (msg == WM_INITDIALOG)
189 SetWindowLongPtr (hDlg, DWLP_USER, ((LPPROPSHEETPAGE)lp)->lParam);
191 LPSUBSET sub = (LPSUBSET)GetWindowLongPtr (hDlg, DWLP_USER);
193 switch (msg)
195 case WM_INITDIALOG_SHEET:
196 PropCache_Add (pcGENERAL, NULL, hDlg);
197 break;
199 case WM_DESTROY_SHEET:
200 PropCache_Delete (hDlg);
201 break;
203 case WM_INITDIALOG:
204 Subsets_OnInitDialog (hDlg, sub);
205 break;
207 case WM_COMMAND:
208 switch (LOWORD(wp))
210 case IDAPPLY:
211 Subsets_OnApply (hDlg, sub);
212 break;
214 case IDOK:
215 case IDCANCEL:
216 EndDialog (hDlg, LOWORD(wp));
217 break;
219 case IDC_SUBSET_LOAD:
220 LPSUBSET subNew;
221 subNew = Subsets_OnLoad (hDlg, sub);
222 if (subNew != NULL)
224 if (sub)
225 Subsets_FreeSubset (sub);
226 SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR)subNew);
228 break;
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))
237 if (sub)
238 Subsets_FreeSubset (sub);
239 SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR)subNew);
242 break;
244 case IDC_SUBSET_SAVE:
245 Subsets_OnSave (hDlg, sub);
246 break;
248 case IDC_SUBSET_ALL:
249 case IDC_SUBSET_NONE:
250 subNew = Subsets_OnCheckAll (hDlg, sub, (LOWORD(wp) == IDC_SUBSET_ALL) ? TRUE : FALSE);
251 if (subNew && (subNew != sub))
253 if (sub)
254 Subsets_FreeSubset (sub);
255 SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR)subNew);
257 break;
259 break;
262 return FALSE;
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)
275 LPTSTR pszText;
277 BOOL fIsOneServer = FALSE;
278 if (sub && sub->pszMonitored && *(sub->pszMonitored))
280 LPTSTR pszNext = &sub->pszMonitored[ 1+lstrlen(sub->pszMonitored) ];
281 if (!*pszNext)
282 fIsOneServer = TRUE;
285 if (sub && sub->szSubset[0])
287 if (sub->fModified)
288 pszText = FormatString (IDS_SUBSET_CHANGED, TEXT("%s"), sub->szSubset);
289 else
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]
298 if (sub->fModified)
299 pszText = FormatString (IDS_SUBSET_CHANGED, TEXT("%m"), IDS_SUBSET_NONAME);
300 else
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);
344 size_t cChecked = 0;
345 int iiChecked;
346 for (int ii = 0; ii < iiMax; ++ii)
348 if (LB_GetCheck (hList, ii))
350 iiChecked = ii;
351 if ((++cChecked) > 1)
352 break;
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?
383 if (!sub)
385 sub = New (SUBSET);
386 memset (sub, 0x00, sizeof(SUBSET));
390 if (sub)
392 sub->fModified = TRUE;
393 Subsets_GetSubsetFromDialog (hDlg, sub);
394 Subsets_SetName (hDlg, sub);
395 PropSheetChanged (hDlg);
398 return sub;
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?
409 if (!sub)
411 sub = New (SUBSET);
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);
426 if (sub)
428 sub->fModified = TRUE;
429 Subsets_GetSubsetFromDialog (hDlg, sub);
430 Subsets_SetName (hDlg, sub);
431 PropSheetChanged (hDlg);
434 return sub;
438 LPSUBSET Subsets_OnLoad (HWND hDlg, LPSUBSET subOld)
440 LPSUBSET subNew = NULL;
442 TCHAR szSubset[ cchNAME ] = TEXT("");
443 if (subOld)
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);
456 return subNew;
460 void Subsets_OnSave (HWND hDlg, LPSUBSET sub)
462 if (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)
485 LPSUBSET subCopy;
486 if ((subCopy = Subsets_CopySubset (sub, TRUE)) != NULL)
488 Subsets_GetSubsetFromDialog (hDlg, subCopy);
491 LPSUBSET subOld = g.sub;
492 g.sub = subCopy;
493 if (subOld)
494 Subsets_FreeSubset (subOld);
496 StartTask (taskAPPLY_SUBSET, NULL, sub);
500 BOOL Subsets_SaveIfDirty (LPSUBSET sub)
502 if (!sub || !sub->fModified)
503 return TRUE;
505 int rc;
506 rc = Message (MB_YESNOCANCEL | MB_ICONQUESTION, IDS_SUBSET_DISCARD_TITLE, IDS_SUBSET_DISCARD_DESC);
508 if (rc == IDNO)
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))
519 return FALSE;
521 if (!Subsets_SaveSubset (NULL, szSubset, sub))
522 return FALSE;
524 sub->fModified = FALSE;
525 lstrcpy (sub->szSubset, szSubset);
527 else // (rc == IDCANCEL)
529 return FALSE;
532 return TRUE;
536 BOOL Subsets_EnumSubsets (LPTSTR pszCell, size_t iIndex, LPTSTR pszSubset)
538 BOOL rc = FALSE;
540 HKEY hk;
541 if ((hk = OpenSubsetsKey (pszCell, FALSE)) != NULL)
543 if (RegEnumKey (hk, (DWORD)iIndex, pszSubset, cchNAME) == 0)
544 rc = TRUE;
546 RegCloseKey (hk);
549 return rc;
553 BOOL Subsets_SaveSubset (LPTSTR pszCell, LPTSTR pszSubset, LPSUBSET sub)
555 BOOL rc = FALSE;
557 if (sub && pszSubset && *pszSubset)
559 HKEY hk;
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;
566 psz && *psz;
567 psz += 1+lstrlen(psz))
569 RegSetValueEx (hk, psz, 0, REG_SZ, (PBYTE)TEXT("X"), sizeof(TCHAR)*2);
572 rc = TRUE;
574 RegCloseKey (hk);
578 return rc;
582 LPSUBSET Subsets_LoadSubset (LPTSTR pszCell, LPTSTR pszSubset)
584 LPSUBSET sub = NULL;
586 HKEY hk;
587 if ((hk = OpenSubsetsSubKey (pszCell, pszSubset, FALSE)) != NULL)
589 DWORD dwMonitored;
590 DWORD dwSize;
591 DWORD dwType;
592 dwSize = sizeof(dwMonitored);
593 if (RegQueryValueEx (hk, REGVAL_INCLUSIVE, 0, &dwType, (LPBYTE)&dwMonitored, &dwSize) == 0)
595 sub = New (SUBSET);
596 memset (sub, 0x00, sizeof(SUBSET));
597 lstrcpy (sub->szSubset, pszSubset);
598 sub->fModified = FALSE;
600 LPTSTR *ppsz;
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)
609 break;
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');
623 RegCloseKey (hk);
626 return sub;
630 LPSUBSET Subsets_CopySubset (LPSUBSET sub, BOOL fCreateIfNULL)
632 LPSUBSET subCopy = NULL;
634 if (sub != NULL)
636 subCopy = New (SUBSET);
637 memset (subCopy, 0x00, sizeof(SUBSET));
638 lstrcpy (subCopy->szSubset, sub->szSubset);
639 subCopy->fModified = sub->fModified;
641 size_t cch;
642 if (sub->pszMonitored)
644 cch = 1;
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)
653 cch = 1;
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));
666 return subCopy;
670 void Subsets_FreeSubset (LPSUBSET sub)
672 if (sub != NULL)
674 if (sub->pszMonitored)
675 FreeString (sub->pszMonitored);
676 if (sub->pszUnmonitored)
677 FreeString (sub->pszUnmonitored);
679 Delete (sub);
685 * SUBSET OPEN/SAVE DIALOG ____________________________________________________
689 typedef struct
691 BOOL fOpen;
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;
707 lpp.fOpen = TRUE;
708 lpp.szCell[0] = TEXT('\0');
709 lstrcpy (lpp.szSubset, pszSubset);
711 if (g.lpiCell)
712 g.lpiCell->GetCellName (lpp.szCell);
714 INT_PTR rc = ModalDialogParam (IDD_SUBSET_LOADSAVE,
715 hParent, (DLGPROC)Subsets_OpenSave_DlgProc,
716 (LPARAM)&lpp);
718 if (rc == IDOK)
720 lstrcpy (pszSubset, lpp.szSubset);
723 return (rc == IDOK) ? TRUE : FALSE;
727 BOOL Subsets_GetSaveName (HWND hParent, LPTSTR pszSubset)
729 SUBSET_OPENSAVE_PARAMS lpp;
730 lpp.fOpen = FALSE;
731 lpp.szCell[0] = TEXT('\0');
732 lstrcpy (lpp.szSubset, pszSubset);
734 if (g.lpiCell)
735 g.lpiCell->GetCellName (lpp.szCell);
737 INT_PTR rc = ModalDialogParam (IDD_SUBSET_LOADSAVE,
738 hParent, (DLGPROC)Subsets_OpenSave_DlgProc,
739 (LPARAM)&lpp);
741 if (rc == IDOK)
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)
760 switch (msg)
762 case WM_INITDIALOG:
763 fEditing = FALSE;
764 Subsets_OpenSave_OnInitDialog (hDlg, lpp);
765 break;
767 case WM_COMMAND:
768 if (!fEditing)
770 switch (LOWORD(wp))
772 case IDCANCEL:
773 EndDialog (hDlg, IDCANCEL);
774 break;
776 case IDOK:
777 GetDlgItemText (hDlg, IDC_SUBSET_NAME, lpp->szSubset, cchNAME);
778 if (lpp->szSubset[0] != TEXT('\0'))
780 BOOL fClose = TRUE;
782 if (!lpp->fOpen)
784 HKEY hk;
785 if ((hk = OpenSubsetsSubKey (NULL, lpp->szSubset, FALSE)) != NULL)
787 RegCloseKey (hk);
789 int rc = Message (MB_YESNO | MB_ICONASTERISK, IDS_SUBSET_SAVE_TITLE, IDS_SUBSET_SAVE_DESC, TEXT("%s"), lpp->szSubset);
790 if (rc != IDYES)
791 fClose = FALSE;
795 if (fClose)
796 EndDialog (hDlg, IDOK);
798 break;
800 case IDC_SUBSET_DELETE:
801 Subsets_OpenSave_OnDelete (hDlg);
802 break;
804 case IDC_SUBSET_RENAME:
805 Subsets_OpenSave_OnRename (hDlg);
806 break;
809 break;
811 case WM_NOTIFY:
812 switch (((LPNMHDR)lp)->code)
814 case LVN_ITEMCHANGED:
815 if (!fEditing)
817 if ( ((LPNM_LISTVIEW)lp)->uNewState & LVIS_SELECTED )
818 Subsets_OpenSave_OnSelect (hDlg);
820 break;
822 case NM_DBLCLK:
823 if (!fEditing)
825 if (((LPNMHDR)lp)->hwndFrom == GetDlgItem (hDlg, IDC_SUBSET_LIST))
827 Subsets_OpenSave_OnSelect (hDlg);
828 PostMessage (hDlg, WM_COMMAND, IDOK, 0);
831 break;
833 case LVN_BEGINLABELEDIT:
834 fEditing = TRUE;
835 return FALSE; // okay to edit label
837 case LVN_ENDLABELEDIT:
838 LV_DISPINFO *plvdi;
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))
850 BOOL fRename = TRUE;
851 BOOL fRepopulate = FALSE;
853 HKEY hk;
854 if ((hk = OpenSubsetsSubKey (NULL, plvdi->item.pszText, FALSE)) != NULL)
856 RegCloseKey (hk);
858 int rc = Message (MB_YESNO | MB_ICONASTERISK, IDS_SUBSET_SAVE_TITLE, IDS_SUBSET_SAVE_DESC, TEXT("%s"), lpp->szSubset);
859 if (rc != IDYES)
860 fRename = FALSE;
861 else
862 fRepopulate = TRUE;
865 if (fRename)
867 LPSUBSET subRename;
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
874 if (fRepopulate)
875 Subsets_OpenSave_Populate (hDlg);
876 else
878 LV_SetItemText (hList, plvdi->item.iItem, 0, plvdi->item.pszText);
879 Subsets_OpenSave_OnSelect (hDlg);
882 Subsets_FreeSubset (subRename);
890 fEditing = FALSE;
891 break;
893 break;
897 return FALSE;
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');
964 else
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)
997 SetFocus (hList);
998 ListView_EditLabel (hList, idxSelected);