ReactOS 0.4.15-dev-7654-g6bc40d3
browsewnd.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Test GUI
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE:
5 * PURPOSE: browse dialog implementation
6 * COPYRIGHT: Copyright 2008 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10#include <precomp.h>
11
12#define EXE_SEARCH_DIR L"\\Debug\\testexes\\*"
13#define IL_MAIN 0
14#define IL_TEST 1
15
16#define HAS_NO_CHILD 0
17#define HAS_CHILD 1
18
19
20static INT
22{
23 HANDLE hFind;
24 WIN32_FIND_DATAW findFileData;
25 INT numFiles = 0;
26
27 hFind = FindFirstFileW(lpFolder,
28 &findFileData);
29 if (hFind == INVALID_HANDLE_VALUE)
30 {
32 return 0;
33 }
34
35 do
36 {
37 if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
38 {
39 numFiles++;
40 }
41 } while (FindNextFile(hFind, &findFileData) != 0);
42
43 return numFiles;
44}
45
46static INT
48{
49 HANDLE hFind;
50 WIN32_FIND_DATAW findFileData;
51 WCHAR szExePath[MAX_PATH];
52 LPWSTR ptr;
53 INT numFiles = 0;
54 INT len;
55
56 len = GetCurrentDirectoryW(MAX_PATH, szExePath);
57 if (!len) return 0;
58
59 wcsncat(szExePath, EXE_SEARCH_DIR, MAX_PATH - (len + 1));
60
61 numFiles = GetNumberOfExesInFolder(szExePath);
62 if (!numFiles) return 0;
63
65 0,
66 numFiles * (MAX_PATH * sizeof(WCHAR)));
67 if (!pInfo->lpExeList)
68 return 0;
69
70 hFind = FindFirstFileW(szExePath,
71 &findFileData);
72 if (hFind == INVALID_HANDLE_VALUE)
73 {
75 HeapFree(GetProcessHeap(), 0, pInfo->lpExeList);
76 return 0;
77 }
78
79 /* remove the glob */
80 ptr = wcschr(szExePath, L'*');
81 if (ptr)
82 *ptr = L'\0';
83
84 /* don't modify our base pointer */
85 ptr = pInfo->lpExeList;
86
87 do
88 {
89 if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
90 {
91 /* set the path */
92 wcscpy(ptr, szExePath);
93
94 /* tag the file onto the path */
95 len = MAX_PATH - (wcslen(ptr) + 1);
96 wcsncat(ptr, findFileData.cFileName, len);
97
98 /* move the pointer along by MAX_PATH */
99 ptr += MAX_PATH;
100 }
101 } while (FindNextFile(hFind, &findFileData) != 0);
102
103 return numFiles;
104}
105
106static BOOL
109{
110 TV_ITEM tvItem;
111
112 tvItem.hItem = hItem;
113 tvItem.mask = TVIF_CHILDREN;
114
115 (void)TreeView_GetItem(pInfo->hBrowseTV, &tvItem);
116
117 return (tvItem.cChildren == 1);
118}
119
120static VOID
123{
124 TV_ITEM tvItem;
125
126 tvItem.hItem = hItem;
127 tvItem.mask = TVIF_PARAM;
128
129 (void)TreeView_GetItem(pInfo->hBrowseTV, &tvItem);
130
132 0,
133 (PTEST_ITEM)tvItem.lParam);
134}
135
136static VOID
139{
140 while (NodeHasChild(pInfo, hItem))
141 {
142 HTREEITEM hChildItem;
143
144 FreeItemTag(pInfo, hItem);
145
146 hChildItem = TreeView_GetChild(pInfo->hBrowseTV,
147 hItem);
148
149 TraverseTreeView(pInfo,
150 hChildItem);
151
153 hItem);
154 }
155
156 if (hItem)
157 {
158 /* loop the child items and free the tags */
159 while (TRUE)
160 {
161 HTREEITEM hOldItem;
162
163 FreeItemTag(pInfo, hItem);
164 hOldItem = hItem;
166 hItem);
167 if (hItem == NULL)
168 {
169 hItem = hOldItem;
170 break;
171 }
172 }
173
175 hItem);
176 }
177}
178
179static HTREEITEM
182 LPWSTR lpLabel,
183 LPARAM Tag,
184 INT Image,
185 INT Child)
186{
187 TV_ITEM tvi;
188 TV_INSERTSTRUCT tvins;
189
190 ZeroMemory(&tvi, sizeof(tvi));
191 ZeroMemory(&tvins, sizeof(tvins));
192
194 tvi.pszText = lpLabel;
195 tvi.cchTextMax = lstrlen(lpLabel);
196 tvi.lParam = Tag;
197 tvi.iImage = Image;
198 tvi.iSelectedImage = Image;
199 tvi.cChildren = Child;
200
201 tvins.item = tvi;
202 tvins.hParent = hRoot;
203
204 return TreeView_InsertItem(hTreeView, &tvins);
205}
206
207static PTEST_ITEM
209 LPWSTR lpRunCmd)
210{
211 PTEST_ITEM pItem;
212
214 0,
215 sizeof(TEST_ITEM));
216 if (pItem)
217 {
218 if (lpName)
219 {
220 wcsncpy(pItem->szName, lpName, MAX_PATH);
221 }
222 if (lpRunCmd)
223 {
224 wcsncpy(pItem->szRunCmd, lpRunCmd, MAX_RUN_CMD);
225 }
226 }
227
228 return pItem;
229}
230
231static VOID
233{
235 HIMAGELIST hImgList;
236 PTEST_ITEM pTestItem;
237 LPWSTR lpExePath;
238 LPWSTR lpTestName;
239 INT i;
240
242
244
245 hImgList = InitImageList(IDI_ICON,
246 IDI_TESTS,
247 16,
248 16);
249 if (!hImgList) return;
250
252 hImgList,
254
255 pTestItem = BuildTestItemData(L"Full", L"runall");
256
257 /* insert the root item into the tree */
259 NULL,
260 L"Full",
261 (LPARAM)pTestItem,
262 IL_MAIN,
263 HAS_CHILD);
264
265 for (i = 0; i < pInfo->numExes; i++)
266 {
267 HTREEITEM hParent;
268 LPWSTR lpStr;
269
270 lpExePath = pInfo->lpExeList + (MAX_PATH * i);
271
272 lpTestName = wcsrchr(lpExePath, L'\\');
273 if (lpTestName)
274 {
275 lpTestName++;
276
277 lpStr = wcschr(lpTestName, L'_');
278 if (lpStr)
279 {
280 //FIXME: Query the test name from the exe directly
281
282 pTestItem = BuildTestItemData(lpTestName, lpExePath);
283
284 hParent = InsertIntoTreeView(pInfo->hBrowseTV,
285 hRoot,
286 lpTestName,
287 (LPARAM)pTestItem,
288 IL_TEST,
289 HAS_CHILD);
290 }
291 }
292 }
293
294 if (hRoot)
295 {
297 hRoot,
298 TVE_EXPAND);
299 }
300}
301
302static VOID
304{
305 pInfo->numExes = GetListOfTestExes(pInfo);
306 if (pInfo->numExes)
307 {
308 PopulateTreeView(pInfo);
309 }
310}
311
312static BOOL
315{
316 PMAIN_WND_INFO pInfo;
317
318 pInfo = (PMAIN_WND_INFO)lParam;
319
320 pInfo->hBrowseDlg = hDlg;
321
322 SetWindowLongPtr(hDlg,
324 (LONG_PTR)pInfo);
325
326 PopulateTestList(pInfo);
327
328 return TRUE;
329}
330
336{
337 PMAIN_WND_INFO pInfo;
338
339 /* Get the window context */
340 pInfo = (PMAIN_WND_INFO)GetWindowLongPtr(hDlg,
342 if (pInfo == NULL && Message != WM_INITDIALOG)
343 {
344 goto HandleDefaultMessage;
345 }
346
347 switch(Message)
348 {
349 case WM_INITDIALOG:
350 return OnInitBrowseDialog(hDlg, lParam);
351
352 case WM_COMMAND:
353 {
354 switch (LOWORD(wParam))
355 {
356 case IDOK:
357 {
358 TV_ITEM tvItem;
359
360 tvItem.hItem = TreeView_GetSelection(pInfo->hBrowseTV);
361 tvItem.mask = TVIF_PARAM;
362
363 if (TreeView_GetItem(pInfo->hBrowseTV, &tvItem))
364 {
365 PTEST_ITEM pItem;
366
367 pItem = (PTEST_ITEM)tvItem.lParam;
368 if (pItem)
369 CopyMemory(&pInfo->SelectedTest, pItem, sizeof(TEST_ITEM));
370
371 EndDialog(hDlg,
372 LOWORD(wParam));
373 }
374 else
375 {
376 DisplayMessage(L"Please select an item");
377 }
378
379 return TRUE;
380 }
381
382 case IDCANCEL:
383 {
384 HeapFree(GetProcessHeap(), 0, pInfo->lpExeList);
385 pInfo->lpExeList = NULL;
386
387 EndDialog(hDlg,
388 LOWORD(wParam));
389
390 return TRUE;
391 }
392 }
393
394 break;
395 }
396
397 case WM_DESTROY:
398 {
400
401 TraverseTreeView(pInfo, hItem);
402
403 pInfo->hBrowseDlg = NULL;
404
405 break;
406 }
407
408HandleDefaultMessage:
409 default:
410 return FALSE;
411 }
412
413 return FALSE;
414}
#define IDI_ICON
Definition: resource.h:5
HIMAGELIST InitImageList(UINT StartResource, UINT EndResource, UINT Width, UINT Height, ULONG type)
Definition: misc.c:219
struct _MAIN_WND_INFO * PMAIN_WND_INFO
static VOID PopulateTreeView(PMAIN_WND_INFO pInfo)
Definition: browsewnd.c:232
#define HAS_CHILD
Definition: browsewnd.c:17
#define EXE_SEARCH_DIR
Definition: browsewnd.c:12
static PTEST_ITEM BuildTestItemData(LPWSTR lpName, LPWSTR lpRunCmd)
Definition: browsewnd.c:208
static INT GetListOfTestExes(PMAIN_WND_INFO pInfo)
Definition: browsewnd.c:47
static HTREEITEM InsertIntoTreeView(HWND hTreeView, HTREEITEM hRoot, LPWSTR lpLabel, LPARAM Tag, INT Image, INT Child)
Definition: browsewnd.c:180
#define IL_MAIN
Definition: browsewnd.c:13
#define IL_TEST
Definition: browsewnd.c:14
static VOID FreeItemTag(PMAIN_WND_INFO pInfo, HTREEITEM hItem)
Definition: browsewnd.c:121
static VOID PopulateTestList(PMAIN_WND_INFO pInfo)
Definition: browsewnd.c:303
static VOID TraverseTreeView(PMAIN_WND_INFO pInfo, HTREEITEM hItem)
Definition: browsewnd.c:137
BOOL CALLBACK BrowseDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
Definition: browsewnd.c:332
static BOOL NodeHasChild(PMAIN_WND_INFO pInfo, HTREEITEM hItem)
Definition: browsewnd.c:107
static BOOL OnInitBrowseDialog(HWND hDlg, LPARAM lParam)
Definition: browsewnd.c:313
static INT GetNumberOfExesInFolder(LPWSTR lpFolder)
Definition: browsewnd.c:21
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define wcsrchr
Definition: compat.h:16
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define IDC_TREEVIEW
Definition: resource.h:13
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
static const WCHAR Message[]
Definition: register.c:74
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
if(dx< 0)
Definition: linetemp.h:194
VOID DisplayError(DWORD dwError)
Definition: logoff.c:33
static PVOID ptr
Definition: dispmode.c:27
#define MAX_RUN_CMD
Definition: precomp.h:13
struct _TEST_ITEM * PTEST_ITEM
struct _TEST_ITEM TEST_ITEM
#define IDI_TESTS
Definition: resource.h:7
static HTREEITEM hRoot
Definition: treeview.c:381
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define TreeView_DeleteAllItems(hwnd)
Definition: commctrl.h:3417
#define TVIF_TEXT
Definition: commctrl.h:3266
#define TreeView_Expand(hwnd, hitem, code)
Definition: commctrl.h:3420
#define TreeView_GetChild(hwnd, hitem)
Definition: commctrl.h:3466
#define TVIF_IMAGE
Definition: commctrl.h:3267
#define TVSIL_NORMAL
Definition: commctrl.h:3443
#define TreeView_GetParent(hwnd, hitem)
Definition: commctrl.h:3469
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3473
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3490
#define TVE_EXPAND
Definition: commctrl.h:3423
#define TV_INSERTSTRUCT
Definition: commctrl.h:3377
#define TV_ITEM
Definition: commctrl.h:3300
#define TreeView_GetRoot(hwnd)
Definition: commctrl.h:3475
#define TreeView_GetNextSibling(hwnd, hitem)
Definition: commctrl.h:3467
#define TVIF_PARAM
Definition: commctrl.h:3268
#define TreeView_SetImageList(hwnd, himl, iImage)
Definition: commctrl.h:3447
#define TVIF_CHILDREN
Definition: commctrl.h:3272
#define TreeView_InsertItem(hwnd, lpis)
Definition: commctrl.h:3412
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3271
void DisplayMessage(BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
Definition: regsvr32.c:239
_CRTIMP wchar_t *__cdecl wcsncat(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
HWND hBrowseTV
Definition: precomp.h:26
LPWSTR lpExeList
Definition: precomp.h:37
HWND hBrowseDlg
Definition: precomp.h:25
TEST_ITEM SelectedTest
Definition: precomp.h:40
WCHAR szRunCmd[MAX_RUN_CMD]
Definition: precomp.h:18
WCHAR szName[MAX_NAME]
Definition: precomp.h:17
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_USERDATA
Definition: treelist.c:63
HTREEITEM hItem
Definition: treelist.h:37
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFDEVICE Child
Definition: wdffdo.h:536
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ LPCSTR lpName
Definition: winbase.h:2789
#define CopyMemory
Definition: winbase.h:1710
#define FindNextFile
Definition: winbase.h:3723
#define lstrlen
Definition: winbase.h:3811
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define IDCANCEL
Definition: winuser.h:830
#define WM_COMMAND
Definition: winuser.h:1739
#define WM_INITDIALOG
Definition: winuser.h:1738
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:829
#define WM_DESTROY
Definition: winuser.h:1608
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184