Dialog to work with the complete list of start menu entries. More...
#include <searchprogram.h>
Public Types | |
typedef ResizeController< Dialog > | super |
Public Member Functions | |
FindProgramDlg (HWND hwnd) | |
~FindProgramDlg () | |
Protected Member Functions | |
virtual LRESULT | WndProc (UINT, WPARAM, LPARAM) |
virtual int | Command (int id, int code) |
virtual int | Notify (int id, NMHDR *pnmh) |
void | Refresh (bool delete_cache=false) |
void | add_entry (const FPDEntry &cache_entry) |
void | LaunchSelected () |
void | CheckEntries () |
Static Protected Member Functions | |
static void | collect_programs_callback (Entry *entry, void *param) |
static int CALLBACK | CompareFunc (LPARAM lparam1, LPARAM lparam2, LPARAM lparamSort) |
Protected Attributes | |
HWND | _list_ctrl |
HACCEL | _haccel |
String | _lwr_filter |
CollectProgramsThread | _thread |
FPDCache | _cache |
String | _common_programs |
String | _user_programs |
ListSort | _sort |
Dialog to work with the complete list of start menu entries.
Definition at line 78 of file searchprogram.h.
typedef ResizeController<Dialog> FindProgramDlg::super |
Reimplemented from ResizeController< Dialog >.
Definition at line 80 of file searchprogram.h.
FindProgramDlg::FindProgramDlg | ( | HWND | hwnd ) |
Definition at line 90 of file searchprogram.cpp.
References _common_programs, _haccel, ExplorerGlobals::_hInstance, ExplorerGlobals::_icon_cache, _list_ctrl, ResizeController< Dialog >::_resize_mgr, _user_programs, ResizeManager::Add(), CenterWindow(), g_Globals, IconCache::get_sys_imagelist(), IDA_SEARCH_PROGRAM, IDC_CHECK_ENTRIES, IDC_FILTER, IDC_PROGRAMS_FOUND, IDI_SEARCH, IDS_MENUCOLUMN, IDS_NAMECOLUMN, IDS_PATHCOLUMN, MOVE_X, Refresh(), Window::register_pretranslate(), ResizeManager::Resize(), RESIZE, RESIZE_X, and SetWindowIcon().
: super(hwnd), _list_ctrl(GetDlgItem(hwnd, IDC_PROGRAMS_FOUND)), _thread(collect_programs_callback, hwnd, this), _sort(_list_ctrl, CompareFunc/*, (LPARAM)this*/) { TCHAR szTemp[256]; const size_t nChars = sizeof(szTemp)/sizeof(*szTemp); SetWindowIcon(hwnd, IDI_SEARCH); _resize_mgr.Add(IDC_FILTER, RESIZE_X); _resize_mgr.Add(IDC_CHECK_ENTRIES, MOVE_X); _resize_mgr.Add(IDC_PROGRAMS_FOUND, RESIZE); _resize_mgr.Resize(+520, +300); _haccel = LoadAccelerators(g_Globals._hInstance, MAKEINTRESOURCE(IDA_SEARCH_PROGRAM)); (void)ListView_SetImageList(_list_ctrl, g_Globals._icon_cache.get_sys_imagelist(), LVSIL_SMALL); LV_COLUMN column = {LVCF_FMT|LVCF_WIDTH|LVCF_TEXT, LVCFMT_LEFT, 250}; LoadString(g_Globals._hInstance, IDS_NAMECOLUMN, szTemp, nChars); column.pszText = szTemp; ListView_InsertColumn(_list_ctrl, 0, &column); column.cx = 300; LoadString(g_Globals._hInstance, IDS_PATHCOLUMN, szTemp, nChars); column.pszText = szTemp; ListView_InsertColumn(_list_ctrl, 1, &column); column.cx = 400; LoadString(g_Globals._hInstance, IDS_MENUCOLUMN, szTemp, nChars); column.pszText = szTemp; ListView_InsertColumn(_list_ctrl, 2, &column); ListView_SetExtendedListViewStyleEx(_list_ctrl, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT); _common_programs = SpecialFolderFSPath(CSIDL_COMMON_PROGRAMS, hwnd); if (!_common_programs.empty()) _common_programs.append(_T("\\")); _user_programs = SpecialFolderFSPath(CSIDL_PROGRAMS, hwnd); if (!_user_programs.empty()) _user_programs.append(_T("\\")); CenterWindow(hwnd); Refresh(); register_pretranslate(hwnd); }
FindProgramDlg::~FindProgramDlg | ( | ) |
Definition at line 143 of file searchprogram.cpp.
References WindowHandle::_hwnd, _thread, Thread::Stop(), and Window::unregister_pretranslate().
{ _thread.Stop(); unregister_pretranslate(_hwnd); }
void FindProgramDlg::add_entry | ( | const FPDEntry & | cache_entry ) | [protected] |
Definition at line 231 of file searchprogram.cpp.
References Entry::_display_name, FPDEntry::_entry, FPDEntry::_idxIcon, _list_ctrl, _lwr_filter, FPDEntry::_menu_path, FPDEntry::_path, _tcsstr, and String::toLower().
Referenced by collect_programs_callback(), and Refresh().
{ String lwr_path = cache_entry._path; String lwr_name = cache_entry._entry->_display_name; lwr_path.toLower(); lwr_name.toLower(); if (_lwr_filter.empty()) if (_tcsstr(lwr_name, _T("uninstal")) || _tcsstr(lwr_name, _T("deinstal"))) // filter out deinstallation links return; if (!_tcsstr(lwr_path, _lwr_filter) && !_tcsstr(lwr_name, _lwr_filter)) return; LV_ITEM item = {LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM, INT_MAX}; item.pszText = cache_entry._entry->_display_name; item.iImage = cache_entry._idxIcon; item.lParam = (LPARAM) &cache_entry; item.iItem = ListView_InsertItem(_list_ctrl, &item); // We could use the information in _sort to enable manual sorting while populating the list. item.mask = LVIF_TEXT; item.iSubItem = 1; item.pszText = (LPTSTR)(LPCTSTR)cache_entry._path; ListView_SetItem(_list_ctrl, &item); item.iSubItem = 2; item.pszText = (LPTSTR)(LPCTSTR)cache_entry._menu_path; ListView_SetItem(_list_ctrl, &item); }
void FindProgramDlg::CheckEntries | ( | ) | [protected] |
Definition at line 420 of file searchprogram.cpp.
Referenced by Command().
{
///@todo check all entries for existing targets, display a list of not working entries and ask the user for permission to delete them
}
void FindProgramDlg::collect_programs_callback | ( | Entry * | entry, |
void * | param | ||
) | [static, protected] |
Definition at line 175 of file searchprogram.cpp.
References _cache, _common_programs, Thread::_crit_sect, FPDEntry::_entry, WindowHandle::_hwnd, FPDEntry::_idxIcon, FPDEntry::_menu_path, FPDEntry::_path, _tcsnicmp, _thread, _user_programs, add_entry(), COUNTOF, Entry::get_path(), Entry::GetUIObjectOf(), IDS_ALL_USERS, and Thread::is_alive().
{ FindProgramDlg* pThis = (FindProgramDlg*) param; IShellLink* pShellLink; HRESULT hr = entry->GetUIObjectOf(pThis->_hwnd, IID_IShellLink, (LPVOID*)&pShellLink); if (SUCCEEDED(hr)) { ShellLinkPtr shell_link(pShellLink); shell_link->Release(); /*hr = pShellLink->Resolve(pThis->_hwnd, SLR_NO_UI); if (SUCCEEDED(hr))*/ { WIN32_FIND_DATA wfd; TCHAR path[MAX_PATH]; hr = pShellLink->GetPath(path, COUNTOF(path)-1, &wfd, SLGP_UNCPRIORITY); if (SUCCEEDED(hr)) { TCHAR entry_path[MAX_PATH]; entry->get_path(entry_path, COUNTOF(entry_path)); String menu_path; int len = pThis->_common_programs.size(); if (len && !_tcsnicmp(entry_path, pThis->_common_programs, len)) menu_path = ResString(IDS_ALL_USERS) + (String(entry_path)+len); else if ((len=pThis->_user_programs.size()) && !_tcsnicmp(entry_path, pThis->_user_programs, len)) menu_path = String(entry_path)+len; // store info in cache FPDEntry new_entry; new_entry._entry = entry; new_entry._menu_path = menu_path; new_entry._path = path; new_entry._idxIcon = I_IMAGECALLBACK; pThis->_cache.push_front(new_entry); FPDEntry& cache_entry = pThis->_cache.front(); Lock lock(pThis->_thread._crit_sect); // resolve deadlocks while executing Thread::Stop() if (!pThis->_thread.is_alive()) return; pThis->add_entry(cache_entry); } } } }
int FindProgramDlg::Command | ( | int | id, |
int | code | ||
) | [protected, virtual] |
Reimplemented from Dialog.
Definition at line 286 of file searchprogram.cpp.
References CheckEntries(), Dialog::Command(), ID_REFRESH, IDC_CHECK_ENTRIES, IDC_FILTER, LaunchSelected(), and Refresh().
{ if (code == BN_CLICKED) { switch(id) { case ID_REFRESH: Refresh(true); break; case IDOK: LaunchSelected(); break; case IDC_CHECK_ENTRIES: CheckEntries(); break; default: return super::Command(id, code); } return 0; } else if (code == EN_CHANGE) { switch(id) { case IDC_FILTER: Refresh(); break; } return 0; } return 1; }
int CALLBACK FindProgramDlg::CompareFunc | ( | LPARAM | lparam1, |
LPARAM | lparam2, | ||
LPARAM | lparamSort | ||
) | [static, protected] |
Definition at line 395 of file searchprogram.cpp.
References ListSort::_direction, Entry::_display_name, FPDEntry::_entry, FPDEntry::_menu_path, FPDEntry::_path, and ListSort::_sort_crit.
{ ListSort* sort = (ListSort*)lparamSort; FPDEntry& a = *(FPDEntry*)lparam1; FPDEntry& b = *(FPDEntry*)lparam2; int cmp = 0; switch(sort->_sort_crit) { case 0: cmp = _tcsicoll(a._entry->_display_name, b._entry->_display_name); break; case 1: cmp = _tcsicoll(a._path, b._path); break; case 2: cmp = _tcsicoll(a._menu_path, b._menu_path); } return sort->_direction? -cmp: cmp; }
void FindProgramDlg::LaunchSelected | ( | ) | [protected] |
Definition at line 321 of file searchprogram.cpp.
References Thread::_crit_sect, FPDEntry::_entry, WindowHandle::_hwnd, _list_ctrl, _thread, IDS_LAUNCH_MANY_PROGRAMS, IDS_TITLE, Entry::launch_entry(), and ListView_GetItemData().
Referenced by Command(), and Notify().
{ Lock lock(_thread._crit_sect); int count = ListView_GetSelectedCount(_list_ctrl); if (count > 1) if (MessageBox(_hwnd, ResString(IDS_LAUNCH_MANY_PROGRAMS), ResString(IDS_TITLE), MB_OKCANCEL) != IDOK) return; for(int idx=-1; (idx=ListView_GetNextItem(_list_ctrl, idx, LVNI_SELECTED))!=-1; ) { LPARAM lparam = ListView_GetItemData(_list_ctrl, idx); if (lparam) { FPDEntry& cache_entry = *(FPDEntry*)lparam; cache_entry._entry->launch_entry(_hwnd); } } }
int FindProgramDlg::Notify | ( | int | id, |
NMHDR * | pnmh | ||
) | [protected, virtual] |
Reimplemented from Window.
Definition at line 341 of file searchprogram.cpp.
References CollectProgramsThread::_cache_valid, FPDEntry::_entry, ExplorerGlobals::_icon_cache, Entry::_icon_id, _list_ctrl, _sort, _thread, g_Globals, IconCache::get_icon(), Icon::get_sysiml_idx(), ICF_SYSCACHE, ICID_UNKNOWN, LaunchSelected(), ListSort::sort(), and ListSort::toggle_sort().
{ switch(pnmh->code) { case LVN_GETDISPINFO: { LV_DISPINFO* pDispInfo = (LV_DISPINFO*) pnmh; if (pnmh->hwndFrom == _list_ctrl) { if (pDispInfo->item.mask & LVIF_IMAGE) { FPDEntry& cache_entry = *(FPDEntry*)pDispInfo->item.lParam; Entry* entry = cache_entry._entry; if (entry->_icon_id == ICID_UNKNOWN) entry->_icon_id = entry->extract_icon(ICF_SYSCACHE); pDispInfo->item.iImage = g_Globals._icon_cache.get_icon(entry->_icon_id).get_sysiml_idx(); pDispInfo->item.mask |= LVIF_DI_SETITEM; return 1; } }} break; case NM_DBLCLK: if (pnmh->hwndFrom == _list_ctrl) LaunchSelected(); /*{ Lock lock(_thread._crit_sect); LPNMLISTVIEW pnmv = (LPNMLISTVIEW) pnmh; LPARAM lparam = ListView_GetItemData(pnmh->hwndFrom, pnmv->iItem); if (lparam) { FPDEntry& cache_entry = *(FPDEntry*)lparam; cache_entry._entry->launch_entry(_hwnd); } }*/ break; case HDN_ITEMCLICK: { WaitCursor wait; NMHEADER* phdr = (NMHEADER*)pnmh; if (GetParent(pnmh->hwndFrom) == _list_ctrl) { if (_thread._cache_valid) { // disable manual sorting while populating the list _sort.toggle_sort(phdr->iItem); _sort.sort(); } } break;} } return 0; }
void FindProgramDlg::Refresh | ( | bool | delete_cache = false ) |
[protected] |
Definition at line 151 of file searchprogram.cpp.
References _cache, CollectProgramsThread::_cache_valid, WindowHandle::_hwnd, _list_ctrl, _lwr_filter, _thread, add_entry(), COUNTOF, CollectProgramsThread::free_dirs(), IDC_FILTER, Thread::Start(), and Thread::Stop().
Referenced by Command(), and FindProgramDlg().
{ WaitCursor wait; _thread.Stop(); TCHAR buffer[1024]; GetWindowText(GetDlgItem(_hwnd, IDC_FILTER), buffer, COUNTOF(buffer)); CharLower(buffer); _lwr_filter = buffer; HiddenWindow hide_listctrl(_list_ctrl); ListView_DeleteAllItems(_list_ctrl); if (delete_cache || !_thread._cache_valid) { _thread.free_dirs(); _thread.Start(); } else { for(FPDCache::const_iterator it=_cache.begin(); it!=_cache.end(); ++it) add_entry(*it); } }
LRESULT FindProgramDlg::WndProc | ( | UINT | nmsg, |
WPARAM | wparam, | ||
LPARAM | lparam | ||
) | [protected, virtual] |
Reimplemented from ResizeController< Dialog >.
Definition at line 264 of file searchprogram.cpp.
References _haccel, WindowHandle::_hwnd, _list_ctrl, PM_TRANSLATE_MSG, and ResizeController< Dialog >::WndProc().
{ switch(nmsg) { case WM_CLOSE: (void)ListView_SetImageList(_list_ctrl, 0, LVSIL_SMALL); // detach system image list goto def; case PM_TRANSLATE_MSG: { MSG* pmsg = (MSG*) lparam; if (TranslateAccelerator(_hwnd, _haccel, pmsg)) return TRUE; return FALSE;} default: def: return super::WndProc(nmsg, wparam, lparam); } return 0; }
FPDCache FindProgramDlg::_cache [protected] |
Definition at line 91 of file searchprogram.h.
Referenced by collect_programs_callback(), and Refresh().
String FindProgramDlg::_common_programs [protected] |
Definition at line 93 of file searchprogram.h.
Referenced by collect_programs_callback(), and FindProgramDlg().
HACCEL FindProgramDlg::_haccel [protected] |
Definition at line 87 of file searchprogram.h.
Referenced by FindProgramDlg(), and WndProc().
HWND FindProgramDlg::_list_ctrl [protected] |
Definition at line 86 of file searchprogram.h.
Referenced by add_entry(), FindProgramDlg(), LaunchSelected(), Notify(), Refresh(), and WndProc().
String FindProgramDlg::_lwr_filter [protected] |
Definition at line 88 of file searchprogram.h.
Referenced by add_entry(), and Refresh().
ListSort FindProgramDlg::_sort [protected] |
Definition at line 95 of file searchprogram.h.
Referenced by Notify().
CollectProgramsThread FindProgramDlg::_thread [protected] |
Definition at line 90 of file searchprogram.h.
Referenced by collect_programs_callback(), LaunchSelected(), Notify(), Refresh(), and ~FindProgramDlg().
String FindProgramDlg::_user_programs [protected] |
Definition at line 93 of file searchprogram.h.
Referenced by collect_programs_callback(), and FindProgramDlg().
ROS Explorer Source Code Documentation
generated on 02.01.2013 by ![]() |