ReactOS 0.4.16-dev-258-g81860b4
searchprogram.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2003, 2004, 2005 Martin Fuchs
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19
20 //
21 // Explorer clone
22 //
23 // dialogs/searchprogram.cpp
24 //
25 // Explorer dialogs
26 //
27 // Martin Fuchs, 02.10.2003
28 //
29
30
31#include <precomp.h>
32
33#include "searchprogram.h"
34
35
37{
38 try {
40 } catch(COMException&) {
41 }
42
43 if (_alive)
44 try {
46 } catch(COMException&) {
47 }
48
49 if (_alive)
50 _cache_valid = true;
51
52 return 0;
53}
54
56{
58 _dirs.push(dir);
59
60 dir->smart_scan(SORT_NONE);
61
62 for(Entry*entry=dir->_down; _alive && entry; entry=entry->_next) {
63 if (entry->_shell_attribs & SFGAO_HIDDEN)
64 continue;
65
66 if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
67 collect_programs(entry->create_absolute_pidl());
68 else if (entry->_shell_attribs & SFGAO_LINK)
69 if (_alive)
71 }
72}
73
75{
76 while(!_dirs.empty()) {
78 dir->free_subentries();
79 _dirs.pop();
80 }
81}
82
83
84#ifdef _MSC_VER
85#pragma warning(disable: 4355)
86#endif
87
89 : super(hwnd),
91 _thread(collect_programs_callback, hwnd, this),
92 _sort(_list_ctrl, CompareFunc/*, (LPARAM)this*/)
93{
94 TCHAR szTemp[256];
95 const size_t nChars = sizeof(szTemp)/sizeof(*szTemp);
97
101
102 _resize_mgr.Resize(+520, +300);
103
105
107
109
111 column.pszText = szTemp;
113
114 column.cx = 300;
116 column.pszText = szTemp;
118
119 column.cx = 400;
121 column.pszText = szTemp;
123
125
127 if (!_common_programs.empty())
128 _common_programs.append(_T("\\"));
129
131 if (!_user_programs.empty())
132 _user_programs.append(_T("\\"));
133
135
136 Refresh();
137
139}
140
142{
143 _thread.Stop();
144
146}
147
148
150{
151 WaitCursor wait;
152
153 _thread.Stop();
154
155 TCHAR buffer[1024];
159
160 HiddenWindow hide_listctrl(_list_ctrl);
161
163
166 _thread.Start();
167 } else {
168 for(FPDCache::const_iterator it=_cache.begin(); it!=_cache.end(); ++it)
169 add_entry(*it);
170 }
171}
172
174{
176
177 IShellLink* pShellLink;
178 HRESULT hr = entry->GetUIObjectOf(pThis->_hwnd, IID_IShellLink, (LPVOID*)&pShellLink);
179
180 if (SUCCEEDED(hr)) {
181 ShellLinkPtr shell_link(pShellLink);
182
183 shell_link->Release();
184
185 /*hr = pShellLink->Resolve(pThis->_hwnd, SLR_NO_UI);
186 if (SUCCEEDED(hr))*/ {
187 WIN32_FIND_DATA wfd;
189
190 hr = pShellLink->GetPath(path, COUNTOF(path)-1, &wfd, SLGP_UNCPRIORITY);
191
192 if (SUCCEEDED(hr)) {
193 TCHAR entry_path[MAX_PATH];
194
195 entry->get_path(entry_path, COUNTOF(entry_path));
196
197 String menu_path;
198
199 int len = pThis->_common_programs.size();
200
201 if (len && !_tcsnicmp(entry_path, pThis->_common_programs, len))
202 menu_path = ResString(IDS_ALL_USERS) + (String(entry_path)+len);
203 else if ((len=pThis->_user_programs.size()) && !_tcsnicmp(entry_path, pThis->_user_programs, len))
204 menu_path = String(entry_path)+len;
205
206 // store info in cache
207 FPDEntry new_entry;
208
209 new_entry._entry = entry;
210 new_entry._menu_path = menu_path;
211 new_entry._path = path;
212 new_entry._idxIcon = I_IMAGECALLBACK;
213
214 pThis->_cache.push_front(new_entry);
215 FPDEntry& cache_entry = pThis->_cache.front();
216
217 Lock lock(pThis->_thread._crit_sect);
218
219 // resolve deadlocks while executing Thread::Stop()
220 if (!pThis->_thread.is_alive())
221 return;
222
223 pThis->add_entry(cache_entry);
224 }
225 }
226 }
227}
228
230{
231 String lwr_path = cache_entry._path;
232 String lwr_name = cache_entry._entry->_display_name;
233
234 lwr_path.toLower();
235 lwr_name.toLower();
236
237 if (_lwr_filter.empty())
238 if (_tcsstr(lwr_name, _T("uninstal")) || _tcsstr(lwr_name, _T("deinstal"))) // filter out deinstallation links
239 return;
240
241 if (!_tcsstr(lwr_path, _lwr_filter) && !_tcsstr(lwr_name, _lwr_filter))
242 return;
243
245
246 item.pszText = cache_entry._entry->_display_name;
247 item.iImage = cache_entry._idxIcon;
248 item.lParam = (LPARAM) &cache_entry;
249 item.iItem = ListView_InsertItem(_list_ctrl, &item); // We could use the information in _sort to enable manual sorting while populating the list.
250
251 item.mask = LVIF_TEXT;
252
253 item.iSubItem = 1;
254 item.pszText = (LPTSTR)(LPCTSTR)cache_entry._path;
256
257 item.iSubItem = 2;
258 item.pszText = (LPTSTR)(LPCTSTR)cache_entry._menu_path;
260}
261
263{
264 switch(nmsg) {
265 case WM_CLOSE:
266 (void)ListView_SetImageList(_list_ctrl, 0, LVSIL_SMALL); // detach system image list
267 goto def;
268
269 case PM_TRANSLATE_MSG: {
270 MSG* pmsg = (MSG*) lparam;
271
272 if (TranslateAccelerator(_hwnd, _haccel, pmsg))
273 return TRUE;
274
275 return FALSE;}
276
277 default: def:
278 return super::WndProc(nmsg, wparam, lparam);
279 }
280
281 return 0;
282}
283
285{
286 if (code == BN_CLICKED) {
287 switch(id) {
288 case ID_REFRESH:
289 Refresh(true);
290 break;
291
292 case IDOK:
294 break;
295
297 CheckEntries();
298 break;
299
300 default:
301 return super::Command(id, code);
302 }
303
304 return 0;
305 }
306 else if (code == EN_CHANGE) {
307 switch(id) {
308 case IDC_FILTER:
309 Refresh();
310 break;
311 }
312
313 return 0;
314 }
315
316 return 1;
317}
318
320{
321 Lock lock(_thread._crit_sect);
322
324
325 if (count > 1)
327 return;
328
329 for(int idx=-1; (idx=ListView_GetNextItem(_list_ctrl, idx, LVNI_SELECTED))!=-1; ) {
331
332 if (lparam) {
334 cache_entry._entry->launch_entry(_hwnd);
335 }
336 }
337}
338
340{
341 switch(pnmh->code) {
342 case LVN_GETDISPINFO: {
343 LV_DISPINFO* pDispInfo = (LV_DISPINFO*) pnmh;
344
345 if (pnmh->hwndFrom == _list_ctrl) {
346 if (pDispInfo->item.mask & LVIF_IMAGE) {
347 FPDEntry& cache_entry = *(FPDEntry*)pDispInfo->item.lParam;
348 Entry* entry = cache_entry._entry;
349
350 if (entry->_icon_id == ICID_UNKNOWN)
351 entry->_icon_id = entry->extract_icon(ICF_SYSCACHE);
352
353 pDispInfo->item.iImage = g_Globals._icon_cache.get_icon(entry->_icon_id).get_sysiml_idx();
354 pDispInfo->item.mask |= LVIF_DI_SETITEM;
355
356 return 1;
357 }
358 }}
359 break;
360
361 case NM_DBLCLK:
362 if (pnmh->hwndFrom == _list_ctrl)
364 /*{
365 Lock lock(_thread._crit_sect);
366
367 LPNMLISTVIEW pnmv = (LPNMLISTVIEW) pnmh;
368 LPARAM lparam = ListView_GetItemData(pnmh->hwndFrom, pnmv->iItem);
369
370 if (lparam) {
371 FPDEntry& cache_entry = *(FPDEntry*)lparam;
372 cache_entry._entry->launch_entry(_hwnd);
373 }
374 }*/
375 break;
376
377 case HDN_ITEMCLICK: {
378 WaitCursor wait;
379 NMHEADER* phdr = (NMHEADER*)pnmh;
380
381 if (GetParent(pnmh->hwndFrom) == _list_ctrl) {
382 if (_thread._cache_valid) { // disable manual sorting while populating the list
383 _sort.toggle_sort(phdr->iItem);
384 _sort.sort();
385 }
386 }
387 break;}
388 }
389
390 return 0;
391}
392
393int CALLBACK FindProgramDlg::CompareFunc(LPARAM lparam1, LPARAM lparam2, LPARAM lparamSort)
394{
395 ListSort* sort = (ListSort*)lparamSort;
396
397 FPDEntry& a = *(FPDEntry*)lparam1;
398 FPDEntry& b = *(FPDEntry*)lparam2;
399
400 int cmp = 0;
401
402 switch(sort->_sort_crit) {
403 case 0:
404 cmp = _tcsicoll(a._entry->_display_name, b._entry->_display_name);
405 break;
406
407 case 1:
408 cmp = _tcsicoll(a._path, b._path);
409 break;
410
411 case 2:
412 cmp = _tcsicoll(a._menu_path, b._menu_path);
413 }
414
415 return sort->_direction? -cmp: cmp;
416}
417
419{
421}
@ lparam
Definition: SystemMenu.c:31
@ wparam
Definition: SystemMenu.c:30
_STLP_MOVE_TO_STD_NAMESPACE void sort(_RandomAccessIter __first, _RandomAccessIter __last)
Definition: _algo.c:993
unsigned int dir
Definition: maze.c:112
#define IDS_TITLE
Definition: resource.h:30
static INT CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
Definition: mainwnd.c:243
#define ID_REFRESH
Definition: resource.h:16
VOID WaitCursor(BOOL bBegin)
Definition: dialog.c:120
static VOID CenterWindow(HWND hWnd)
Definition: reactos.c:61
_STLP_PRIV _List_iterator< FPDEntry, _Const_traits< FPDEntry > > const_iterator
Definition: _list.h:276
iterator begin()
Definition: _list.h:367
iterator end()
Definition: _list.h:370
void push_front(const_reference __x)
Definition: _list.h:508
reference front()
Definition: _list.h:385
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:41
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
@ ICF_SYSCACHE
Definition: entries.h:73
@ SORT_NONE
Definition: entries.h:45
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLfloat param
Definition: glext.h:5796
GLenum GLsizei len
Definition: glext.h:6722
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define _tcsicoll
Definition: tchar.h:1436
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define INT_MAX
Definition: intsafe.h:150
uint32_t entry
Definition: isohybrid.c:63
if(dx< 0)
Definition: linetemp.h:194
void Refresh(void)
Definition: magnifier.c:317
void SetWindowIcon(HWND hwnd, UINT nid)
set big and small icons out of the resources for a window
Definition: explorer.cpp:689
ExplorerGlobals g_Globals
Definition: explorer.cpp:52
@ ICID_UNKNOWN
Definition: globals.h:63
#define IDC_CHECK_ENTRIES
Definition: resource.h:176
#define IDS_NAMECOLUMN
Definition: resource.h:51
#define IDS_ALL_USERS
Definition: resource.h:29
#define IDC_FILTER
Definition: resource.h:165
#define IDS_PATHCOLUMN
Definition: resource.h:52
#define IDI_SEARCH
Definition: resource.h:88
#define IDS_LAUNCH_MANY_PROGRAMS
Definition: resource.h:32
#define IDC_PROGRAMS_FOUND
Definition: resource.h:166
#define IDS_MENUCOLUMN
Definition: resource.h:53
#define IDA_SEARCH_PROGRAM
Definition: resource.h:77
#define COUNTOF(x)
Definition: utility.h:93
#define PM_TRANSLATE_MSG
Definition: window.h:266
@ MOVE_X
Definition: window.h:461
@ RESIZE_X
Definition: window.h:463
@ RESIZE
Definition: window.h:467
int ListView_GetItemData(HWND list_ctrl, int idx)
Definition: window.h:915
#define cmp(status, error)
Definition: error.c:114
static ATOM item
Definition: dde.c:856
unsigned int UINT
Definition: ndis.h:50
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define LVSIL_SMALL
Definition: commctrl.h:2304
#define I_IMAGECALLBACK
Definition: commctrl.h:2390
#define ListView_InsertItem(hwnd, pitem)
Definition: commctrl.h:2413
#define ListView_SetExtendedListViewStyleEx(hwndLV, dwMask, dw)
Definition: commctrl.h:2731
#define ListView_InsertColumn(hwnd, iCol, pcol)
Definition: commctrl.h:2641
#define NM_DBLCLK
Definition: commctrl.h:131
#define ListView_SetImageList(hwnd, himl, iImageList)
Definition: commctrl.h:2309
#define LVNI_SELECTED
Definition: commctrl.h:2429
#define LVN_GETDISPINFO
Definition: commctrl.h:3165
#define LVCF_WIDTH
Definition: commctrl.h:2592
#define LV_DISPINFO
Definition: commctrl.h:3175
#define ListView_GetNextItem(hwnd, i, flags)
Definition: commctrl.h:2439
#define LVS_EX_FULLROWSELECT
Definition: commctrl.h:2739
#define HDN_ITEMCLICK
Definition: commctrl.h:868
#define ListView_GetSelectedCount(hwndLV)
Definition: commctrl.h:2714
#define LVIF_PARAM
Definition: commctrl.h:2316
#define LV_ITEM
Definition: commctrl.h:2342
#define ListView_DeleteAllItems(hwnd)
Definition: commctrl.h:2419
#define NMHEADER
Definition: commctrl.h:894
#define LVIF_TEXT
Definition: commctrl.h:2314
#define ListView_SetItem(hwnd, pitem)
Definition: commctrl.h:2406
#define LVCF_FMT
Definition: commctrl.h:2591
#define LVCFMT_LEFT
Definition: commctrl.h:2603
#define LVIF_IMAGE
Definition: commctrl.h:2315
#define LVIF_DI_SETITEM
Definition: commctrl.h:3171
#define LVCF_TEXT
Definition: commctrl.h:2593
#define LV_COLUMN
Definition: commctrl.h:2552
static void delete_cache(struct netbuf *)
Definition: rpcb_clnt.c:171
ShellFolder & GetDesktopFolder()
HRESULT hr
Definition: shlfolder.c:183
#define IID_IShellLink
Definition: shlguid.h:131
#define CSIDL_COMMON_PROGRAMS
Definition: shlobj.h:2195
#define CSIDL_PROGRAMS
Definition: shlobj.h:2175
Exception with context information.
Definition: shellclasses.h:114
void collect_programs(const ShellPath &path)
COLLECT_CALLBACK _callback
Definition: searchprogram.h:56
ShellDirectoryStack _dirs
Definition: searchprogram.h:59
base of all file and directory entries
Definition: entries.h:83
HINSTANCE _hInstance
Definition: globals.h:270
IconCache _icon_cache
Definition: globals.h:285
entry for the list in "find program" dialogs
Definition: searchprogram.h:67
int _idxIcon
Definition: searchprogram.h:69
String _path
Definition: searchprogram.h:71
Entry * _entry
Definition: searchprogram.h:68
String _menu_path
Definition: searchprogram.h:70
Dialog to work with the complete list of start menu entries.
Definition: searchprogram.h:79
FPDCache _cache
Definition: searchprogram.h:91
String _lwr_filter
Definition: searchprogram.h:88
FindProgramDlg(HWND hwnd)
virtual LRESULT WndProc(UINT, WPARAM, LPARAM)
static void collect_programs_callback(Entry *entry, void *param)
virtual int Notify(int id, NMHDR *pnmh)
CollectProgramsThread _thread
Definition: searchprogram.h:90
static int CALLBACK CompareFunc(LPARAM lparam1, LPARAM lparam2, LPARAM lparamSort)
String _user_programs
Definition: searchprogram.h:93
virtual int Command(int id, int code)
String _common_programs
Definition: searchprogram.h:93
void add_entry(const FPDEntry &cache_entry)
ListSort _sort
Definition: searchprogram.h:95
void Refresh(bool delete_cache=false)
const Icon & get_icon(int icon_id)
Definition: explorer.cpp:625
HIMAGELIST get_sys_imagelist() const
Definition: globals.h:143
int get_sysiml_idx() const
Definition: globals.h:109
sorting of list controls
Definition: window.h:952
void toggle_sort(int idx)
Definition: window.cpp:1282
void sort()
Definition: window.cpp:1292
convenient loading of string resources
Definition: globals.h:304
ResizeManager _resize_mgr
Definition: window.h:563
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
Definition: window.h:525
void Resize(int dx, int dy)
Definition: window.cpp:847
void Add(UINT id, int flags)
Definition: window.h:491
shell folder entry
Definition: shellfs.h:54
IShellLink smart pointer.
Definition: shellclasses.h:608
wrapper class for item ID lists
Definition: shellclasses.h:652
file system path of special folder
Retrieval of special shell folder paths.
Definition: shellclasses.h:982
static void register_pretranslate(HWND hwnd)
Definition: window.cpp:579
virtual int Command(int id, int code)
Definition: window.cpp:285
static void unregister_pretranslate(HWND hwnd)
Definition: window.cpp:584
Definition: svc_auth_des.c:77
Definition: inflate.c:139
bool empty() const
Definition: _stack.h:82
reference top()
Definition: _stack.h:84
void push(const value_type &__x)
Definition: _stack.h:86
void pop()
Definition: _stack.h:87
UINT code
Definition: winuser.h:3162
HWND hwndFrom
Definition: winuser.h:3160
rwlock_t lock
Definition: tcpcore.h:0
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define _T(x)
Definition: vfdio.h:22
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WM_CLOSE
Definition: winuser.h:1624
#define CharLower
Definition: winuser.h:5749
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:833
#define MB_OKCANCEL
Definition: winuser.h:807
#define GetWindowText
Definition: winuser.h:5810
HWND WINAPI GetParent(_In_ HWND)
#define LoadString
Definition: winuser.h:5831
#define MessageBox
Definition: winuser.h:5834
#define BN_CLICKED
Definition: winuser.h:1928
#define TranslateAccelerator
Definition: winuser.h:5872
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define LoadAccelerators
Definition: winuser.h:5822
#define EN_CHANGE
Definition: winuser.h:2025
char TCHAR
Definition: xmlstorage.h:189
#define _tcsnicmp
Definition: xmlstorage.h:207
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define _tcsstr
Definition: xmlstorage.h:199