ReactOS  0.4.14-dev-115-g4576127
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 
20 static 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 
46 static 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 
106 static 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 
120 static 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 
136 static 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 
179 static 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 
207 static 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 
231 static VOID
233 {
235  HIMAGELIST hImgList;
236  PTEST_ITEM pTestItem;
237  LPWSTR lpExePath;
238  LPWSTR lpTestName;
239  INT i;
240 
241  pInfo->hBrowseTV = GetDlgItem(pInfo->hBrowseDlg, IDC_TREEVIEW);
242 
244 
245  hImgList = InitImageList(IDI_ICON,
246  IDI_TESTS,
247  16,
248  16);
249  if (!hImgList) return;
250 
252  hImgList,
253  TVSIL_NORMAL);
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  {
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 
285  hRoot,
286  lpTestName,
287  (LPARAM)pTestItem,
288  IL_TEST,
289  HAS_CHILD);
290  }
291  }
292  }
293 
294  if (hRoot)
295  {
296  TreeView_Expand(pInfo->hBrowseTV,
297  hRoot,
298  TVE_EXPAND);
299  }
300 }
301 
302 static VOID
304 {
305  pInfo->numExes = GetListOfTestExes(pInfo);
306  if (pInfo->numExes)
307  {
308  PopulateTreeView(pInfo);
309  }
310 }
311 
312 static BOOL
314  LPARAM lParam)
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 
333  UINT Message,
334  WPARAM wParam,
335  LPARAM lParam)
336 {
337  PMAIN_WND_INFO pInfo;
338 
339  /* Get the window context */
340  pInfo = (PMAIN_WND_INFO)GetWindowLongPtr(hDlg,
341  GWLP_USERDATA);
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 
408 HandleDefaultMessage:
409  default:
410  return FALSE;
411  }
412 
413  return FALSE;
414 }
#define IDI_ICON
Definition: resource.h:5
static VOID PopulateTreeView(PMAIN_WND_INFO pInfo)
Definition: browsewnd.c:232
#define EXE_SEARCH_DIR
Definition: browsewnd.c:12
static INT GetNumberOfExesInFolder(LPWSTR lpFolder)
Definition: browsewnd.c:21
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
WCHAR szName[MAX_NAME]
Definition: precomp.h:17
struct _TEST_ITEM TEST_ITEM
#define TreeView_DeleteAllItems(hwnd)
Definition: commctrl.h:3389
#define TreeView_GetChild(hwnd, hitem)
Definition: commctrl.h:3438
static VOID PopulateTestList(PMAIN_WND_INFO pInfo)
Definition: browsewnd.c:303
BOOL CALLBACK BrowseDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
Definition: browsewnd.c:332
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:413
#define CALLBACK
Definition: compat.h:27
_In_ LPCSTR lpName
Definition: winbase.h:2736
static PWSTR Image
Definition: pageheap.c:13
struct _TEST_ITEM * PTEST_ITEM
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1642
#define IL_TEST
Definition: browsewnd.c:14
UINT_PTR WPARAM
Definition: windef.h:207
static BOOL NodeHasChild(PMAIN_WND_INFO pInfo, HTREEITEM hItem)
Definition: browsewnd.c:107
#define TreeView_GetNextSibling(hwnd, hitem)
Definition: commctrl.h:3439
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3243
int32_t INT
Definition: typedefs.h:56
#define SetWindowLongPtr
Definition: treelist.c:70
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define IL_MAIN
Definition: browsewnd.c:13
#define TreeView_InsertItem(hwnd, lpis)
Definition: commctrl.h:3384
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
#define MAX_RUN_CMD
Definition: precomp.h:13
#define TVIF_CHILDREN
Definition: commctrl.h:3244
unsigned int BOOL
Definition: ntddk_ex.h:94
static HTREEITEM hRoot
Definition: treeview.c:381
static PVOID ptr
Definition: dispmode.c:27
#define GWLP_USERDATA
Definition: treelist.c:63
HTREEITEM hItem
Definition: treelist.h:37
smooth NULL
Definition: ftsmooth.c:416
WCHAR szRunCmd[MAX_RUN_CMD]
Definition: precomp.h:18
LONG_PTR LPARAM
Definition: windef.h:208
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
HWND hBrowseTV
Definition: precomp.h:26
#define TreeView_SetImageList(hwnd, himl, iImage)
Definition: commctrl.h:3419
static INT GetListOfTestExes(PMAIN_WND_INFO pInfo)
Definition: browsewnd.c:47
static VOID FreeItemTag(PMAIN_WND_INFO pInfo, HTREEITEM hItem)
Definition: browsewnd.c:121
#define IDI_TESTS
Definition: resource.h:7
#define WM_DESTROY
Definition: winuser.h:1591
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3445
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
if(!(yy_init))
Definition: macro.lex.yy.c:714
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static BOOL OnInitBrowseDialog(HWND hDlg, LPARAM lParam)
Definition: browsewnd.c:313
#define FindNextFile
Definition: winbase.h:3612
#define MAX_PATH
Definition: compat.h:26
LPWSTR lpExeList
Definition: precomp.h:37
struct _MAIN_WND_INFO * PMAIN_WND_INFO
#define CopyMemory
Definition: winbase.h:1640
#define TVE_EXPAND
Definition: commctrl.h:3395
TEST_ITEM SelectedTest
Definition: precomp.h:40
CHAR Message[80]
Definition: alive.c:5
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
HIMAGELIST InitImageList(UINT StartResource, UINT EndResource, UINT Width, UINT Height, ULONG type)
Definition: misc.c:219
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
GLenum GLsizei len
Definition: glext.h:6722
#define IDC_TREEVIEW
Definition: resource.h:12
HWND hBrowseDlg
Definition: precomp.h:25
#define TreeView_GetParent(hwnd, hitem)
Definition: commctrl.h:3441
#define WM_COMMAND
Definition: winuser.h:1722
_CRTIMP wchar_t *__cdecl wcsncat(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
VOID DisplayError(DWORD dwError)
Definition: logoff.c:33
#define TV_ITEM
Definition: commctrl.h:3272
#define lstrlen
Definition: winbase.h:3700
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define TreeView_GetRoot(hwnd)
Definition: commctrl.h:3447
#define TVIF_TEXT
Definition: commctrl.h:3238
#define TVIF_IMAGE
Definition: commctrl.h:3239
static PTEST_ITEM BuildTestItemData(LPWSTR lpName, LPWSTR lpRunCmd)
Definition: browsewnd.c:208
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
#define TVSIL_NORMAL
Definition: commctrl.h:3415
#define HAS_CHILD
Definition: browsewnd.c:17
static VOID TraverseTreeView(PMAIN_WND_INFO pInfo, HTREEITEM hItem)
Definition: browsewnd.c:137
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE ACPI_HANDLE Child
Definition: acpixf.h:722
#define TVIF_PARAM
Definition: commctrl.h:3240
#define GetWindowLongPtr
Definition: treelist.c:73
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDCANCEL
Definition: winuser.h:825
static HTREEITEM InsertIntoTreeView(HWND hTreeView, HTREEITEM hRoot, LPWSTR lpLabel, LPARAM Tag, INT Image, INT Child)
Definition: browsewnd.c:180
void DisplayMessage(BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
Definition: regsvr32.c:239
#define TV_INSERTSTRUCT
Definition: commctrl.h:3349
#define TreeView_Expand(hwnd, hitem, code)
Definition: commctrl.h:3392
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3462
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320