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
11 #include <afs/param.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
))
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
)
71 lpp
->pInternal
= (PVOID
)hDlg
;
72 BrowseSet_OnInitDialog (hDlg
, lpp
);
76 BrowseSet_OnDestroy (hDlg
);
77 lpp
->pInternal
= NULL
;
81 BrowseSet_OnSearchStart (hDlg
);
85 BrowseSet_OnSearchDone (hDlg
);
89 BrowseSet_OnAddString (hDlg
, (LPTSTR
)wp
);
96 GetDlgItemText (hDlg
, IDC_BROWSE_NAMED
, lpp
->szFileset
, cchNAME
);
98 EndDialog (hDlg
, LOWORD(wp
));
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
);
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
));
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
);
137 switch (((LPNMHDR
)lp
)->code
)
139 case LVN_ITEMCHANGED
:
140 if ( ((LPNM_LISTVIEW
)lp
)->uNewState
& LVIS_SELECTED
)
141 BrowseSet_OnSelectedEntry (hDlg
);
145 PostMessage (hDlg
, WM_COMMAND
, MAKELONG(IDOK
,BN_CLICKED
), (LPARAM
)GetDlgItem(hDlg
,IDOK
));
156 void BrowseSet_OnInitDialog (HWND hDlg
, LPBROWSESETDLG_PARAMS lpp
)
160 TCHAR szText
[ cchRESOURCE
];
161 GetString (szText
, lpp
->idsTitle
);
162 SetWindowText (hDlg
, szText
);
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
);
177 EnableWindow (GetDlgItem (hDlg
, IDC_BROWSE_CELL
), FALSE
);
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.
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
));
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
);
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
)
272 memset (&lvi
, 0x00, sizeof(LV_ITEM
));
273 lvi
.mask
= LVIF_PARAM
;
275 if (ListView_GetItem (hList
, &lvi
))
278 if ((psz
= (LPTSTR
)lvi
.lParam
) != NULL
)
280 lvi
.mask
= LVIF_PARAM
;
283 ListView_SetItem (hList
, &lvi
);
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.
306 if (OpenFTS (&status
))
309 if ((status
= FtsOpenCell (szCellA
, &hCell
)) == 0)
311 fldb_short_ft_info_t
*fti
;
312 if ((status
= FtsAllocateShortFtInfoBuffer (&fti
)) == 0)
317 while ( (FtsListFilesetsFromFldb (hCell
, fti
, &nEntries
, &cookie
) == 0) && (nEntries
> 0) )
319 if (!IsWindow ((HWND
)(lpp
->pInternal
)))
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
)
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
);
344 if (IsWindow ((HWND
)(lpp
->pInternal
)))
345 PostMessage ((HWND
)(lpp
->pInternal
), WM_THREADDONE
, status
, 0);