Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afsapplib / al_browseset.cpp
blob672c45f45fe2539cd4678ecb6964ba4ca534e195
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 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
15 #include <WINNT/afsapplib.h>
17 #define WM_FOUNDNAME (WM_USER +100)
18 #define WM_THREADSTART (WM_USER +101)
19 #define WM_THREADDONE (WM_USER +102)
23 * VARIABLES __________________________________________________________________
29 * PROTOTYPES _________________________________________________________________
33 HRESULT CALLBACK BrowseSet_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
34 void BrowseSet_OnInitDialog (HWND hDlg, LPBROWSESETDLG_PARAMS pszFilename);
35 void BrowseSet_OnDestroy (HWND hDlg);
36 void BrowseSet_OnAddString (HWND hDlg, LPTSTR pszString);
37 void BrowseSet_OnSelectedEntry (HWND hDlg);
39 void BrowseSet_StartSearch (HWND hDlg, LPBROWSESETDLG_PARAMS lpp);
40 void BrowseSet_OnSearchStart (HWND hDlg);
41 void BrowseSet_OnSearchDone (HWND hDlg);
42 void BrowseSet_EmptyList (HWND hDlg);
43 DWORD WINAPI BrowseSet_Init_ThreadProc (LPARAM lp);
47 * ROUTINES ___________________________________________________________________
51 BOOL AfsAppLib_ShowBrowseFilesetDialog (LPBROWSESETDLG_PARAMS lpp)
53 return (ModalDialogParam (IDD_APPLIB_BROWSE_FILESET, lpp->hParent, (DLGPROC)BrowseSet_DlgProc, (LPARAM)lpp) == IDOK) ? TRUE : FALSE;
57 HRESULT CALLBACK BrowseSet_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
59 if (AfsAppLib_HandleHelp (IDD_APPLIB_BROWSE_FILESET, hDlg, msg, wp, lp))
60 return TRUE;
62 if (msg == WM_INITDIALOG)
63 SetWindowLongPtr (hDlg, DWLP_USER, lp);
65 LPBROWSESETDLG_PARAMS lpp;
66 if ((lpp = (LPBROWSESETDLG_PARAMS)GetWindowLongPtr (hDlg, DWLP_USER)) != NULL)
68 switch (msg)
70 case WM_INITDIALOG:
71 lpp->pInternal = (PVOID)hDlg;
72 BrowseSet_OnInitDialog (hDlg, lpp);
73 break;
75 case WM_DESTROY:
76 BrowseSet_OnDestroy (hDlg);
77 lpp->pInternal = NULL;
78 break;
80 case WM_THREADSTART:
81 BrowseSet_OnSearchStart (hDlg);
82 break;
84 case WM_THREADDONE:
85 BrowseSet_OnSearchDone (hDlg);
86 break;
88 case WM_FOUNDNAME:
89 BrowseSet_OnAddString (hDlg, (LPTSTR)wp);
90 break;
92 case WM_COMMAND:
93 switch (LOWORD(wp))
95 case IDOK:
96 GetDlgItemText (hDlg, IDC_BROWSE_NAMED, lpp->szFileset, cchNAME);
97 case IDCANCEL:
98 EndDialog (hDlg, LOWORD(wp));
99 break;
101 case IDC_BROWSE_CELL:
102 if (HIWORD(wp) == CBN_SELCHANGE)
104 GetDlgItemText (hDlg, IDC_BROWSE_CELL, lpp->szCell, cchNAME);
105 BrowseSet_StartSearch (hDlg, lpp);
107 break;
109 case IDC_BROWSE_NAMED:
110 if (HIWORD(wp) == EN_UPDATE) // has the user hit Enter here?
112 TCHAR szTest[ cchRESOURCE ];
113 GetDlgItemText (hDlg, IDC_BROWSE_NAMED, szTest, cchRESOURCE);
115 if ( (lstrlen (szTest) > 0) && (szTest[ lstrlen(szTest)-1 ] == TEXT('\n')) )
117 szTest[ lstrlen(szTest)-1 ] = TEXT('\0');
119 if ( (lstrlen (szTest) > 0) && (szTest[ lstrlen(szTest)-1 ] == TEXT('\r')) )
120 szTest[ lstrlen(szTest)-1 ] = TEXT('\0');
122 SetDlgItemText (hDlg, IDC_BROWSE_NAMED, szTest);
123 PostMessage (hDlg, WM_COMMAND, MAKELONG(IDOK,BN_CLICKED), (LPARAM)GetDlgItem(hDlg,IDOK));
126 break;
128 case IDC_BROWSE_RESTART:
129 GetDlgItemText (hDlg, IDC_BROWSE_CELL, lpp->szCell, cchNAME);
130 BrowseSet_StartSearch (hDlg, lpp);
131 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (hDlg, IDC_BROWSE_NAMED), (LPARAM)TRUE);
132 break;
134 break;
136 case WM_NOTIFY:
137 switch (((LPNMHDR)lp)->code)
139 case LVN_ITEMCHANGED:
140 if ( ((LPNM_LISTVIEW)lp)->uNewState & LVIS_SELECTED )
141 BrowseSet_OnSelectedEntry (hDlg);
142 break;
144 case NM_DBLCLK:
145 PostMessage (hDlg, WM_COMMAND, MAKELONG(IDOK,BN_CLICKED), (LPARAM)GetDlgItem(hDlg,IDOK));
146 break;
148 break;
152 return FALSE;
156 void BrowseSet_OnInitDialog (HWND hDlg, LPBROWSESETDLG_PARAMS lpp)
158 if (lpp->idsTitle)
160 TCHAR szText[ cchRESOURCE ];
161 GetString (szText, lpp->idsTitle);
162 SetWindowText (hDlg, szText);
165 if (lpp->idsPrompt)
167 TCHAR szText[ cchRESOURCE ];
168 GetString (szText, lpp->idsPrompt);
169 SetDlgItemText (hDlg, IDC_BROWSE_TYPE, szText);
172 ListView_SetImageList (GetDlgItem (hDlg, IDC_BROWSE_LIST), AfsAppLib_CreateImageList(FALSE), LVSIL_SMALL);
173 SetDlgItemText (hDlg, IDC_BROWSE_NAMED, lpp->szFileset);
175 if (!lpp->lpcl)
177 EnableWindow (GetDlgItem (hDlg, IDC_BROWSE_CELL), FALSE);
179 else
181 CB_StartChange (GetDlgItem (hDlg, IDC_BROWSE_CELL));
182 for (size_t ii = 0; ii < lpp->lpcl->nCells; ++ii)
183 CB_AddItem (GetDlgItem (hDlg, IDC_BROWSE_CELL), lpp->lpcl->aCells[ii], 1+ii);
184 CB_EndChange (GetDlgItem (hDlg, IDC_BROWSE_CELL), 1);
186 if (lpp->szCell[0] != TEXT('\0'))
188 SetDlgItemText (hDlg, IDC_BROWSE_CELL, lpp->szCell);
191 BrowseSet_StartSearch (hDlg, lpp);
193 // There's a default pushbutton on this dialog, so that hitting
194 // RETURN when you're in the Cell combobox will restart the search
195 // (a default pushbutton always gets called when RETURN is hit,
196 // unless your control traps it). But the user doesn't want to *see*
197 // that thing, so move it way off the dialog's client area.
199 RECT r;
200 GetWindowRect (GetDlgItem (hDlg, IDC_BROWSE_RESTART), &r);
201 SetWindowPos (GetDlgItem (hDlg, IDC_BROWSE_RESTART), NULL,
202 0 - (r.right-r.left), 0 - (r.bottom-r.top), 0, 0,
203 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
207 void BrowseSet_OnDestroy (HWND hDlg)
209 BrowseSet_EmptyList (hDlg);
213 void BrowseSet_OnSelectedEntry (HWND hDlg)
215 HWND hList = GetDlgItem (hDlg, IDC_BROWSE_LIST);
216 LPTSTR pszString = (LPTSTR)LV_GetSelectedData (hList);
217 if (pszString != NULL)
219 SetDlgItemText (hDlg, IDC_BROWSE_NAMED, pszString);
224 void BrowseSet_StartSearch (HWND hDlg, LPBROWSESETDLG_PARAMS lpp)
226 BrowseSet_EmptyList (hDlg);
228 LPBROWSESETDLG_PARAMS lppNew = New (BROWSESETDLG_PARAMS);
229 memcpy (lppNew, lpp, sizeof(BROWSESETDLG_PARAMS));
231 DWORD dwThreadID;
232 HANDLE hThread;
233 if ((hThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)BrowseSet_Init_ThreadProc, (PVOID)lppNew, 0, &dwThreadID)) == INVALID_HANDLE_VALUE)
235 EnableWindow (GetDlgItem (hDlg, IDC_BROWSE_LIST), FALSE);
236 Delete (lppNew);
241 void BrowseSet_OnSearchStart (HWND hDlg)
243 TCHAR szWait[ cchRESOURCE ];
244 GetString (szWait, IDS_BROWSE_WAITING);
245 SetDlgItemText (hDlg, IDC_BROWSE_STATUS, szWait);
249 void BrowseSet_OnSearchDone (HWND hDlg)
251 SetDlgItemText (hDlg, IDC_BROWSE_STATUS, TEXT(""));
252 EnableWindow (GetDlgItem (hDlg, IDC_BROWSE_LIST), TRUE);
256 void BrowseSet_OnAddString (HWND hDlg, LPTSTR pszString)
258 HWND hList = GetDlgItem (hDlg, IDC_BROWSE_LIST);
259 LV_AddItem (hList, 1, INDEX_SORT, (LPARAM)pszString, imageFILESET, pszString);
260 // string freed when list destroyed
264 void BrowseSet_EmptyList (HWND hDlg)
266 HWND hList = GetDlgItem (hDlg, IDC_BROWSE_LIST);
268 int iiMax = ListView_GetItemCount (hList);
269 for (int ii = 0; ii < iiMax; ++ii)
271 LV_ITEM lvi;
272 memset (&lvi, 0x00, sizeof(LV_ITEM));
273 lvi.mask = LVIF_PARAM;
274 lvi.iItem = ii;
275 if (ListView_GetItem (hList, &lvi))
277 LPTSTR psz;
278 if ((psz = (LPTSTR)lvi.lParam) != NULL)
280 lvi.mask = LVIF_PARAM;
281 lvi.iItem = ii;
282 lvi.lParam = 0;
283 ListView_SetItem (hList, &lvi);
284 FreeString (psz);
291 DWORD WINAPI BrowseSet_Init_ThreadProc (LPARAM lp)
293 LPBROWSESETDLG_PARAMS lpp = (LPBROWSESETDLG_PARAMS)lp;
295 char szCellA[ cchNAME ];
296 CopyStringToAnsi (szCellA, lpp->szCell);
298 if (IsWindow ((HWND)(lpp->pInternal)))
299 PostMessage ((HWND)(lpp->pInternal), WM_THREADSTART, 0, 0);
301 // Fill in hList with the names of all filesets in the cell.
303 ULONG status = 0;
304 #if 0
305 // TODO
306 if (OpenFTS (&status))
308 PVOID hCell;
309 if ((status = FtsOpenCell (szCellA, &hCell)) == 0)
311 fldb_short_ft_info_t *fti;
312 if ((status = FtsAllocateShortFtInfoBuffer (&fti)) == 0)
314 PVOID cookie = 0;
315 ULONG nEntries;
317 while ( (FtsListFilesetsFromFldb (hCell, fti, &nEntries, &cookie) == 0) && (nEntries > 0) )
319 if (!IsWindow ((HWND)(lpp->pInternal)))
320 break;
322 for (ULONG ii = 0; ii < nEntries; ++ii)
324 #define DECODE_SHINFO_TYPE_FLAGS(_fl) ((_fl) >> 12)
325 if (DECODE_SHINFO_TYPE_FLAGS(fti[ ii ].flags) & FTS_FT_SHINFO_TYPE_RW)
327 LPTSTR pszFileset;
328 if ((pszFileset = CloneString (fti[ii].name)) != NULL)
330 PostMessage ((HWND)(lpp->pInternal), WM_FOUNDNAME, (WPARAM)pszFileset, 0);
331 // string memory is freed by recipient of message
336 FtsFreeShortFtInfoBuffer (fti);
338 FtsCloseCell (hCell);
340 CloseFTS();
342 #endif
344 if (IsWindow ((HWND)(lpp->pInternal)))
345 PostMessage ((HWND)(lpp->pInternal), WM_THREADDONE, status, 0);
347 Delete (lpp);
348 return 0;