2 * Copyright 2003, 2004 Martin Fuchs
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 // Explorer start menu
27 // Martin Fuchs, 19.08.2003
29 // Credits: Thanks to Everaldo (http://www.everaldo.com) for his nice looking icons.
35 #include "../resource.h"
37 #include "desktopbar.h"
38 #include "startmenu.h"
40 #include "../dialogs/searchprogram.h"
41 #include "../dialogs/settings.h"
44 #define SHELLPATH_CONTROL_PANEL TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}")
45 #define SHELLPATH_PRINTERS TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}")
46 #define SHELLPATH_NET_CONNECTIONS TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}")
49 StartMenu::StartMenu(HWND hwnd
)
52 _next_id
= IDC_FIRST_MENU
;
57 _bottom_max
= INT_MAX
;
59 _floating_btn
= false;
61 _scroll_mode
= SCROLL_NOT
;
65 _last_pos
= WindowRect(hwnd
).pos();
66 #ifdef _LIGHT_STARTMENU
72 StartMenu::StartMenu(HWND hwnd
, const StartMenuCreateInfo
& create_info
)
74 _create_info(create_info
)
76 for(StartMenuFolders::const_iterator it
=create_info
._folders
.begin(); it
!=create_info
._folders
.end(); ++it
)
78 _dirs
.push_back(ShellDirectory(GetDesktopFolder(), *it
, _hwnd
));
80 _next_id
= IDC_FIRST_MENU
;
84 _border_top
= create_info
._border_top
;
85 _bottom_max
= INT_MAX
;
87 _floating_btn
= create_info
._border_top
? true: false;
89 _scroll_mode
= SCROLL_NOT
;
93 _last_pos
= WindowRect(hwnd
).pos();
94 #ifdef _LIGHT_STARTMENU
100 StartMenu::~StartMenu()
102 SendParent(PM_STARTMENU_CLOSED
);
106 // We need this wrapper function for s_wcStartMenu, it calls the WIN32 API,
107 // though static C++ initializers are not allowed for Winelib applications.
108 BtnWindowClass
& StartMenu::GetWndClasss()
110 static BtnWindowClass
s_wcStartMenu(CLASSNAME_STARTMENU
);
112 return s_wcStartMenu
;
116 Window::CREATORFUNC_INFO
StartMenu::s_def_creator
= STARTMENU_CREATOR(StartMenu
);
118 HWND
StartMenu::Create(int x
, int y
, const StartMenuFolders
& folders
, HWND hwndParent
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
, const String
& filter
)
120 UINT style
, ex_style
;
124 style
= WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
;
126 top_height
= STARTMENU_TOP_BTN_SPACE
;
128 style
= WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|WS_CLIPCHILDREN
|WS_VISIBLE
;
129 ex_style
= WS_EX_TOOLWINDOW
;
133 RECT rect
= {x
, y
-STARTMENU_LINE_HEIGHT
-top_height
, x
+STARTMENU_WIDTH_MIN
, y
};
135 #ifndef _LIGHT_STARTMENU
136 rect
.top
+= STARTMENU_LINE_HEIGHT
;
139 AdjustWindowRectEx(&rect
, style
, FALSE
, ex_style
);
141 StartMenuCreateInfo create_info
;
143 create_info
._folders
= folders
;
144 create_info
._border_top
= top_height
;
145 create_info
._creator
= creator
;
146 create_info
._info
= info
;
147 create_info
._filter
= filter
;
150 create_info
._title
= title
;
152 HWND hwnd
= Window::Create(creator
, &create_info
, ex_style
, GetWndClasss(), title
,
153 style
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndParent
);
155 // make sure the window is not off the screen
162 LRESULT
StartMenu::Init(LPCREATESTRUCT pcs
)
167 if (super::Init(pcs
))
170 // create buttons for registered entries in _entries
171 for(ShellEntryMap::const_iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
172 const StartMenuEntry
& sme
= it
->second
;
173 bool hasSubmenu
= false;
175 for(ShellEntrySet::const_iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
)
176 if ((*it
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
179 #ifdef _LIGHT_STARTMENU
180 _buttons
.push_back(SMBtnInfo(sme
, it
->first
, hasSubmenu
));
182 AddButton(sme
._title
, sme
._hIcon
, hasSubmenu
, it
->first
);
186 #ifdef _LIGHT_STARTMENU
187 if (_buttons
.empty())
189 if (!GetWindow(_hwnd
, GW_CHILD
))
191 AddButton(ResString(IDS_EMPTY
), ICID_NONE
, false, 0, false);
193 #ifdef _LIGHT_STARTMENU
197 #ifdef _LAZY_ICONEXTRACT
198 PostMessage(_hwnd
, PM_UPDATE_ICONS
, 0, 0);
200 } catch(COMException
& e
) {
201 HandleException(e
, pcs
->hwndParent
); // destroys the start menu window while switching focus
207 void StartMenu::AddEntries()
209 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
210 StartMenuDirectory
& smd
= *it
;
211 ShellDirectory
& dir
= smd
._dir
;
216 #ifdef _LAZY_ICONEXTRACT
217 dir
.smart_scan(SORT_NAME
, SCAN_FILESYSTEM
); // lazy icon extraction, try to read directly from filesystem
219 dir
.smart_scan(SORT_NAME
, SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
223 AddShellEntries(dir
, -1, smd
._ignore
);
228 static LPTSTR
trim_path_slash(LPTSTR path
)
235 if (p
>path
&& (p
[-1]=='\\' || p
[-1]=='/'))
241 void StartMenu::AddShellEntries(const ShellDirectory
& dir
, int max
, const String
& ignore
)
243 TCHAR ignore_path
[MAX_PATH
], ignore_dir
[MAX_PATH
], ignore_name
[_MAX_FNAME
], ignore_ext
[_MAX_EXT
];
244 TCHAR dir_path
[MAX_PATH
];
246 if (!ignore
.empty()) {
247 _tsplitpath(ignore
, ignore_path
, ignore_dir
, ignore_name
, ignore_ext
);
249 _tcscat(ignore_path
, ignore_dir
);
250 _tcscat(ignore_name
, ignore_ext
);
252 dir
.get_path(dir_path
, COUNTOF(dir_path
));
254 if (_tcsicmp(trim_path_slash(dir_path
), trim_path_slash(ignore_path
)))
259 String lwr_filter
= _create_info
._filter
;
260 #ifndef __WINE__ ///@todo _tcslwr() for Wine
261 _tcslwr((LPTSTR
)lwr_filter
.c_str());
265 for(Entry
*entry
=dir
._down
; entry
; entry
=entry
->_next
) {
266 // hide files like "desktop.ini"
267 if (entry
->_shell_attribs
& SFGAO_HIDDEN
)
268 //not appropriate for drive roots: if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
271 // hide "Programs" subfolders if requested
272 if (*ignore_name
&& !_tcsicmp(entry
->_data
.cFileName
, ignore_name
))
275 // only 'max' entries shall be added.
279 // filter only non-directory entries
280 if (!(entry
->_data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
) && !lwr_filter
.empty()) {
281 String lwr_name
= entry
->_data
.cFileName
;
282 String lwr_disp
= entry
->_display_name
;
284 #ifndef __WINE__ ///@todo _tcslwr() for Wine
285 _tcslwr((LPTSTR
)lwr_name
.c_str());
286 _tcslwr((LPTSTR
)lwr_disp
.c_str());
289 if (!_tcsstr(lwr_name
,lwr_filter
) && !_tcsstr(lwr_disp
,lwr_filter
))
293 if (entry
->_etype
== ET_SHELL
)
294 AddEntry(dir
._folder
, static_cast<ShellEntry
*>(entry
));
296 AddEntry(dir
._folder
, entry
);
301 LRESULT
StartMenu::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
305 PaintCanvas
canvas(_hwnd
);
310 ResizeButtons(LOWORD(lparam
)-_border_left
);
314 POINTS
& pos
= MAKEPOINTS(lparam
);
316 // move open submenus of floating menus
318 int dx
= pos
.x
- _last_pos
.x
;
319 int dy
= pos
.y
- _last_pos
.y
;
322 WindowRect
rt(_submenu
);
323 SetWindowPos(_submenu
, 0, rt
.left
+dx
, rt
.top
+dy
, 0, 0, SWP_NOSIZE
|SWP_NOACTIVATE
);
324 //MoveVisible(_submenu);
333 LRESULT res
= super::WndProc(nmsg
, wparam
, lparam
);
335 if (res
>=HTSIZEFIRST
&& res
<=HTSIZELAST
)
336 return HTCLIENT
; // disable window resizing
340 case WM_LBUTTONDOWN
: {
343 // check mouse cursor for coordinates of floating button
344 GetFloatingButtonRect(&rect
);
346 if (PtInRect(&rect
, Point(lparam
))) {
347 // create a floating copy of the current start menu
348 WindowRect
pos(_hwnd
);
350 ///@todo do something similar to StartMenuRoot::TrackStartmenu() in order to automatically close submenus when clicking on the desktop background
351 StartMenu::Create(pos
.left
+3, pos
.bottom
-3, _create_info
._folders
, 0, _create_info
._title
, _create_info
._creator
, _create_info
._info
);
355 #ifdef _LIGHT_STARTMENU
356 int id
= ButtonHitTest(Point(lparam
));
359 Command(id
, BN_CLICKED
);
364 if ((wparam
&0xFFF0) == SC_SIZE
)
365 return 0; // disable window resizing
369 // close start menu when activating another application
372 break; // don't call super::WndProc in case "this" has been deleted
377 #ifdef _LIGHT_STARTMENU
378 if (_scroll_mode
!= SCROLL_NOT
) {
385 #ifdef _LIGHT_STARTMENU
387 // automatically set the focus to startmenu entries when moving the mouse over them
388 if (lparam
!= _last_mouse_pos
) { // don't process WM_MOUSEMOVE when opening submenus using keyboard navigation
392 RECT rect_up
, rect_down
;
394 GetArrowButtonRects(&rect_up
, &rect_down
);
396 SCROLL_MODE scroll_mode
= SCROLL_NOT
;
398 if (PtInRect(&rect_up
, pt
))
399 scroll_mode
= SCROLL_UP
;
400 else if (PtInRect(&rect_down
, pt
))
401 scroll_mode
= SCROLL_DOWN
;
403 if (scroll_mode
!= _scroll_mode
) {
404 if (scroll_mode
== SCROLL_NOT
) {
409 SetTimer(_hwnd
, 0, 150, NULL
); // 150 ms scroll interval
413 _scroll_mode
= scroll_mode
;
417 int new_id
= ButtonHitTest(pt
);
419 if (new_id
> 0 && new_id
!= _selected_id
)
420 SelectButton(new_id
);
422 _last_mouse_pos
= lparam
;
427 if (_scroll_mode
== SCROLL_UP
) {
428 if (_scroll_pos
> 0) {
430 InvalidateRect(_hwnd
, NULL
, TRUE
);
433 if (_scroll_pos
<= _invisible_lines
) {
435 InvalidateRect(_hwnd
, NULL
, TRUE
);
444 case PM_STARTENTRY_FOCUSED
: { ///@todo use TrackMouseEvent() and WM_MOUSEHOVER to wait a bit before opening submenus
445 BOOL hasSubmenu
= wparam
;
446 HWND hctrl
= (HWND
)lparam
;
448 // automatically open submenus
450 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
451 //SendMessage(_hwnd, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hctrl),BN_CLICKED), (LPARAM)hctrl);
452 Command(GetDlgCtrlID(hctrl
), BN_CLICKED
);
454 // close any open submenu
455 CloseOtherSubmenus();
460 #ifdef _LAZY_ICONEXTRACT
461 case PM_UPDATE_ICONS
:
462 UpdateIcons(/*wparam*/);
466 case PM_STARTENTRY_LAUNCHED
:
467 if (GetWindowStyle(_hwnd
) & WS_CAPTION
) // don't automatically close floating menus
470 // route message to the parent menu and close menus after launching an entry
471 if (!SendParent(nmsg
, wparam
, lparam
))
473 return 1; // signal that we have received and processed the message
475 case PM_STARTMENU_CLOSED
:
479 case PM_SELECT_ENTRY
:
480 SelectButtonIndex(0, wparam
!=0);
483 #ifdef _LIGHT_STARTMENU
484 case WM_CONTEXTMENU
: {
485 Point
screen_pt(lparam
), clnt_pt
=screen_pt
;
486 ScreenToClient(_hwnd
, &clnt_pt
);
488 int id
= ButtonHitTest(clnt_pt
);
491 StartMenuEntry
& sme
= _entries
[id
];
493 for(ShellEntrySet::iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
) {
497 CHECKERROR(entry
->do_context_menu(_hwnd
, screen_pt
, _cm_ifs
)); // may close start menu because of focus loss
498 break; ///@todo handle context menu for more than one entry
506 return super::WndProc(nmsg
, wparam
, lparam
);
513 #ifdef _LIGHT_STARTMENU
515 int StartMenu::ButtonHitTest(POINT pt
)
517 ClientRect
clnt(_hwnd
);
518 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
520 if (pt
.x
<rect
.left
|| pt
.x
>rect
.right
)
523 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
524 const SMBtnInfo
& info
= *it
;
529 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
531 if (rect
.bottom
> _bottom_max
)
534 if (pt
.y
< rect
.bottom
) // PtInRect(&rect, pt)
537 rect
.top
= rect
.bottom
;
543 void StartMenu::InvalidateSelection()
545 if (_selected_id
<= 0)
548 ClientRect
clnt(_hwnd
);
549 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
551 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
552 const SMBtnInfo
& info
= *it
;
554 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
556 if (info
._id
== _selected_id
) {
557 InvalidateRect(_hwnd
, &rect
, TRUE
);
561 rect
.top
= rect
.bottom
;
565 const SMBtnInfo
* StartMenu::GetButtonInfo(int id
) const
567 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
)
574 bool StartMenu::SelectButton(int id
, bool open_sub
)
579 if (id
== _selected_id
)
582 InvalidateSelection();
584 const SMBtnInfo
* btn
= GetButtonInfo(id
);
586 if (btn
&& btn
->_enabled
) {
589 InvalidateSelection();
591 // automatically open submenus
592 if (btn
->_hasSubmenu
) {
596 CloseOtherSubmenus(); // close any open submenu
605 bool StartMenu::OpenSubmenu(bool select_first
)
607 if (_selected_id
== -1)
610 InvalidateSelection();
612 const SMBtnInfo
* btn
= GetButtonInfo(_selected_id
);
614 // automatically open submenus
615 if (btn
->_hasSubmenu
) {
616 //@@ allows destroying of startmenu when processing PM_UPDATE_ICONS -> GPF
617 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
618 Command(_selected_id
, BN_CLICKED
);
620 if (select_first
&& _submenu
)
621 SendMessage(_submenu
, PM_SELECT_ENTRY
, (WPARAM
)false, 0);
629 int StartMenu::GetSelectionIndex()
631 if (_selected_id
== -1)
634 for(int i
=0; i
<(int)_buttons
.size(); ++i
)
635 if (_buttons
[i
]._id
== _selected_id
)
641 bool StartMenu::SelectButtonIndex(int idx
, bool open_sub
)
643 if (idx
>=0 && idx
<(int)_buttons
.size())
644 return SelectButton(_buttons
[idx
]._id
, open_sub
);
649 void StartMenu::ProcessKey(int vk
)
654 Command(_selected_id
, BN_CLICKED
);
666 SelectButtonIndex(0, false);
670 SelectButtonIndex(_buttons
.size()-1, false);
675 CloseOtherSubmenus();
676 else if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) // don't automatically close floating menus
677 DestroyWindow(_hwnd
);
689 if (vk
>='0' && vk
<='Z')
690 JumpToNextShortcut(vk
);
694 bool StartMenu::Navigate(int step
)
696 int idx
= GetSelectionIndex();
702 idx
= _buttons
.size() - step
;
707 if (idx
<0 || idx
>(int)_buttons
.size())
710 if (SelectButtonIndex(idx
, false))
717 bool StartMenu::JumpToNextShortcut(char c
)
719 int cur_idx
= GetSelectionIndex();
727 SMBtnVector::const_iterator cur_it
= _buttons
.begin();
728 cur_it
+= cur_idx
+ 1;
730 // first search down from current item...
731 SMBtnVector::const_iterator it
= cur_it
;
732 for(; it
!=_buttons
.end(); ++it
) {
733 const SMBtnInfo
& btn
= *it
;
735 if (!btn
._title
.empty() && toupper((TBYTE
)btn
._title
.at(0)) == c
) {
737 first_found
= btn
._id
;
743 // ...now search from top to the current item
744 it
= _buttons
.begin();
745 for(; it
!=_buttons
.end() && it
!=cur_it
; ++it
) {
746 const SMBtnInfo
& btn
= *it
;
748 if (!btn
._title
.empty() && toupper((TBYTE
)btn
._title
.at(0)) == c
) {
750 first_found
= btn
._id
;
757 SelectButton(first_found
);
760 Command(first_found
, BN_CLICKED
);
767 #endif // _LIGHT_STARTMENU
770 bool StartMenu::GetButtonRect(int id
, PRECT prect
) const
772 #ifdef _LIGHT_STARTMENU
773 ClientRect
clnt(_hwnd
);
774 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
776 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
777 const SMBtnInfo
& info
= *it
;
779 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
781 if (info
._id
== id
) {
786 rect
.top
= rect
.bottom
;
791 HWND btn
= GetDlgItem(_hwnd
, id
);
794 GetWindowRect(btn
, prect
);
795 ScreenToClient(_hwnd
, prect
);
804 void StartMenu::DrawFloatingButton(HDC hdc
)
806 static ResIconEx
floatingIcon(IDI_FLOATING
, 8, 4);
808 ClientRect
clnt(_hwnd
);
810 DrawIconEx(hdc
, clnt
.right
-12, 0, floatingIcon
, 8, 4, 0, 0, DI_NORMAL
);
813 void StartMenu::GetFloatingButtonRect(LPRECT prect
)
815 GetClientRect(_hwnd
, prect
);
818 prect
->left
= prect
->right
- 8;
823 void StartMenu::DrawArrows(HDC hdc
)
825 static ResIconEx
arrowUpIcon(IDI_ARROW_UP
, 8, 4);
826 static ResIconEx
arrowDownIcon(IDI_ARROW_DOWN
, 8, 4);
828 ClientRect
clnt(_hwnd
);
830 DrawIconEx(hdc
, clnt
.right
/2-4, _floating_btn
?3:1, arrowUpIcon
, 8, 4, 0, 0, DI_NORMAL
);
831 DrawIconEx(hdc
, clnt
.right
/2-4, clnt
.bottom
-5, arrowDownIcon
, 8, 4, 0, 0, DI_NORMAL
);
834 void StartMenu::GetArrowButtonRects(LPRECT prect_up
, LPRECT prect_down
)
836 GetClientRect(_hwnd
, prect_up
);
837 *prect_down
= *prect_up
;
839 // prect_up->left = prect_up->right/2 - 4;
840 // prect_up->right = prect_up->left + 8;
841 prect_up
->right
-= 8;
842 prect_up
->top
= _floating_btn
? 3: 1;
843 prect_up
->bottom
= prect_up
->top
+ 4;
845 // prect_down->left = prect_down->right/2 - 4;
846 // prect_down->right = prect_down->left + 8;
847 prect_down
->right
-= 8;
848 prect_down
->top
= prect_down
->bottom
- 5;
852 void StartMenu::Paint(PaintCanvas
& canvas
)
855 DrawFloatingButton(canvas
);
857 #ifdef _LIGHT_STARTMENU
861 ClientRect
clnt(_hwnd
);
862 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
864 int sep_width
= rect
.right
-rect
.left
- 4;
866 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
867 BkMode
bk_mode(canvas
, TRANSPARENT
);
869 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
870 const SMBtnInfo
& btn
= *it
;
872 if (rect
.top
> canvas
.rcPaint
.bottom
)
875 if (btn
._id
== -1) { // a separator?
876 rect
.bottom
= rect
.top
+ STARTMENU_SEP_HEIGHT
;
878 if (rect
.bottom
> _bottom_max
)
881 BrushSelection
brush_sel(canvas
, GetSysColorBrush(COLOR_BTNSHADOW
));
882 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2-1, sep_width
, 1, PATCOPY
);
884 SelectBrush(canvas
, GetSysColorBrush(COLOR_BTNHIGHLIGHT
));
885 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2, sep_width
, 1, PATCOPY
);
887 rect
.bottom
= rect
.top
+ STARTMENU_LINE_HEIGHT
;
889 if (rect
.bottom
> _bottom_max
)
892 if (rect
.top
>= canvas
.rcPaint
.top
)
893 DrawStartMenuButton(canvas
, rect
, btn
._title
, btn
, btn
._id
==_selected_id
, false);
896 rect
.top
= rect
.bottom
;
901 #ifdef _LAZY_ICONEXTRACT
902 void StartMenu::UpdateIcons(/*int idx*/)
906 #ifdef _SINGLE_ICONEXTRACT
909 int idx
= _scroll_pos
;
911 for(; idx
<(int)_buttons
.size(); ++idx
) {
912 SMBtnInfo
& btn
= _buttons
[idx
];
914 if (btn
._icon_id
==ICID_UNKNOWN
&& btn
._id
>0) {
915 StartMenuEntry
& sme
= _entries
[btn
._id
];
917 btn
._icon_id
= ICID_NONE
;
919 for(ShellEntrySet::iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
) {
922 if (entry
->_icon_id
== ICID_UNKNOWN
)
924 entry
->extract_icon();
925 } catch(COMException
&) {
926 // ignore unexpected exceptions while extracting icons
929 if (entry
->_icon_id
> ICID_NONE
) {
930 btn
._icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
934 GetButtonRect(btn
._id
, &rect
);
936 if (rect
.bottom
> _bottom_max
)
939 WindowCanvas
canvas(_hwnd
);
940 DrawStartMenuButton(canvas
, rect
, NULL
, btn
, btn
._id
==_selected_id
, false);
942 //InvalidateRect(_hwnd, &rect, FALSE);
943 //UpdateWindow(_hwnd);
952 // if (++idx < (int)_buttons.size())
953 // PostMessage(_hwnd, PM_UPDATE_ICONS, idx, 0);
957 int icons_extracted
= 0;
958 int icons_updated
= 0;
960 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
961 ShellDirectory
& dir
= it
->_dir
;
963 icons_extracted
+= dir
.extract_icons();
966 if (icons_extracted
) {
967 for(ShellEntryMap::iterator it1
=_entries
.begin(); it1
!=_entries
.end(); ++it1
) {
968 StartMenuEntry
& sme
= it1
->second
;
971 sme
._hIcon
= (HICON
)-1;
973 for(ShellEntrySet::const_iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
974 const Entry
* sm_entry
= *it2
;
976 if (sm_entry
->_hIcon
) {
977 sme
._hIcon
= sm_entry
->_hIcon
;
984 for(SMBtnVector::iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
985 SMBtnInfo
& info
= *it
;
987 if (info
._id
>0 && !info
._hIcon
) {
988 info
._hIcon
= _entries
[info
._id
]._hIcon
;
995 InvalidateRect(_hwnd
, NULL
, FALSE
);
1003 // resize child button controls to accomodate for new window size
1004 void StartMenu::ResizeButtons(int cx
)
1006 HDWP hdwp
= BeginDeferWindowPos(10);
1008 for(HWND ctrl
=GetWindow(_hwnd
,GW_CHILD
); ctrl
; ctrl
=GetNextWindow(ctrl
,GW_HWNDNEXT
)) {
1009 ClientRect
rt(ctrl
);
1011 if (rt
.right
!= cx
) {
1012 int height
= rt
.bottom
- rt
.top
;
1014 // special handling for separator controls
1015 if (!height
&& (GetWindowStyle(ctrl
)&SS_TYPEMASK
)==SS_ETCHEDHORZ
)
1018 hdwp
= DeferWindowPos(hdwp
, ctrl
, 0, 0, 0, cx
, height
, SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
);
1022 EndDeferWindowPos(hdwp
);
1026 int StartMenu::Command(int id
, int code
)
1028 #ifndef _LIGHT_STARTMENU
1036 ShellEntryMap::iterator found
= _entries
.find(id
);
1038 if (found
!= _entries
.end()) {
1039 ActivateEntry(id
, found
->second
._entries
);
1043 return super::Command(id
, code
);
1044 #ifndef _LIGHT_STARTMENU
1053 ShellEntryMap::iterator
StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, Entry
* entry
)
1055 // search for an already existing subdirectory entry with the same name
1056 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1057 for(ShellEntryMap::iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
1058 StartMenuEntry
& sme
= it
->second
;
1060 if (!_tcsicmp(sme
._title
, title
)) ///@todo speed up by using a map indexed by name
1061 for(ShellEntrySet::iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
1062 if ((*it2
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1063 // merge the new shell entry with the existing of the same name
1064 sme
._entries
.insert(entry
);
1071 ShellEntryMap::iterator sme
= AddEntry(title
, icon_id
);
1073 sme
->second
._entries
.insert(entry
);
1078 ShellEntryMap::iterator
StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, int id
)
1086 sme
._icon_id
= icon_id
;
1088 ShellEntryMap::iterator it
= _entries
.insert(make_pair(id
, sme
)).first
;
1093 ShellEntryMap::iterator
StartMenu::AddEntry(const ShellFolder folder
, ShellEntry
* entry
)
1097 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1098 icon_id
= ICID_FOLDER
;
1100 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
1102 return AddEntry(folder
.get_name(entry
->_pidl
), icon_id
, entry
);
1105 ShellEntryMap::iterator
StartMenu::AddEntry(const ShellFolder folder
, Entry
* entry
)
1109 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1110 icon_id
= ICID_FOLDER
;
1112 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
1114 return AddEntry(entry
->_display_name
, icon_id
, entry
);
1118 void StartMenu::AddButton(LPCTSTR title
, ICON_ID icon_id
, bool hasSubmenu
, int id
, bool enabled
)
1120 #ifdef _LIGHT_STARTMENU
1121 _buttons
.push_back(SMBtnInfo(title
, icon_id
, id
, hasSubmenu
, enabled
));
1123 DWORD style
= enabled
? WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
: WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
|WS_DISABLED
;
1125 WindowRect
rect(_hwnd
);
1126 ClientRect
clnt(_hwnd
);
1128 // increase window height to make room for the new button
1129 rect
.top
-= STARTMENU_LINE_HEIGHT
;
1131 // move down if we are too high now
1133 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1134 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1137 WindowCanvas
canvas(_hwnd
);
1138 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1140 // widen window, if it is too small
1141 int text_width
= GetStartMenuBtnTextWidth(canvas
, title
, _hwnd
) + 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1143 int cx
= clnt
.right
- _border_left
;
1144 if (text_width
> cx
)
1145 rect
.right
+= text_width
-cx
;
1147 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1149 StartMenuCtrl(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
,
1150 title
, id
, g_Globals
._icon_cache
.get_icon(icon_id
)._hIcon
, hasSubmenu
, style
);
1154 void StartMenu::AddSeparator()
1156 #ifdef _LIGHT_STARTMENU
1157 _buttons
.push_back(SMBtnInfo(NULL
, ICID_NONE
, -1, false));
1159 WindowRect
rect(_hwnd
);
1160 ClientRect
clnt(_hwnd
);
1162 // increase window height to make room for the new separator
1163 rect
.top
-= STARTMENU_SEP_HEIGHT
;
1165 // move down if we are too high now
1167 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1168 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1171 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1173 StartMenuSeparator(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
);
1178 bool StartMenu::CloseOtherSubmenus(int id
)
1181 if (IsWindow(_submenu
)) {
1182 if (_submenu_id
== id
)
1186 DestroyWindow(_submenu
);
1187 // _submenu should be reset automatically by PM_STARTMENU_CLOSED, but safety first...
1198 void StartMenu::CreateSubmenu(int id
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1200 CreateSubmenu(id
, StartMenuFolders(), title
, creator
, info
);
1203 bool StartMenu::CreateSubmenu(int id
, int folder_id
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1206 SpecialFolderPath
folder(folder_id
, _hwnd
);
1208 StartMenuFolders new_folders
;
1209 new_folders
.push_back(folder
);
1211 CreateSubmenu(id
, new_folders
, title
, creator
, info
);
1214 } catch(COMException
&) {
1215 // ignore Exception and don't display anything
1216 CloseOtherSubmenus(id
);
1217 _buttons
[GetSelectionIndex()]._enabled
= false; // disable entries for non-existing folders
1222 bool StartMenu::CreateSubmenu(int id
, int folder_id1
, int folder_id2
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1224 StartMenuFolders new_folders
;
1227 new_folders
.push_back(SpecialFolderPath(folder_id1
, _hwnd
));
1228 } catch(COMException
&) {
1232 new_folders
.push_back(SpecialFolderPath(folder_id2
, _hwnd
));
1233 } catch(COMException
&) {
1236 if (!new_folders
.empty()) {
1237 CreateSubmenu(id
, new_folders
, title
, creator
, info
);
1240 CloseOtherSubmenus(id
);
1241 _buttons
[GetSelectionIndex()]._enabled
= false; // disable entries for non-existing folders
1246 void StartMenu::CreateSubmenu(int id
, const StartMenuFolders
& new_folders
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1248 // Only open one submenu at a time.
1249 if (!CloseOtherSubmenus(id
))
1255 if (GetButtonRect(id
, &rect
)) {
1256 ClientToScreen(_hwnd
, &rect
);
1258 x
= rect
.right
; // Submenus should overlap their parent a bit.
1259 y
= rect
.top
+STARTMENU_LINE_HEIGHT
+_border_top
/*own border*/ -STARTMENU_TOP_BTN_SPACE
/*border of new submenu*/;
1261 WindowRect
pos(_hwnd
);
1268 _submenu
= StartMenu::Create(x
, y
, new_folders
, _hwnd
, title
, creator
, info
, _create_info
._filter
);
1272 void StartMenu::ActivateEntry(int id
, const ShellEntrySet
& entries
)
1274 StartMenuFolders new_folders
;
1277 for(ShellEntrySet::const_iterator it
=entries
.begin(); it
!=entries
.end(); ++it
) {
1278 Entry
* entry
= const_cast<Entry
*>(*it
);
1280 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1282 ///@todo If the user explicitly clicked on a submenu, display this folder as floating start menu.
1284 if (entry
->_etype
== ET_SHELL
)
1285 new_folders
.push_back(entry
->create_absolute_pidl());
1287 TCHAR path
[MAX_PATH
];
1289 if (entry
->get_path(path
, COUNTOF(path
)))
1290 new_folders
.push_back(path
);
1294 title
= entry
->_display_name
;
1296 // The entry is no subdirectory, so there can only be one shell entry.
1297 assert(entries
.size()==1);
1299 HWND hparent
= GetParent(_hwnd
);
1300 ShellPath shell_path
= entry
->create_absolute_pidl();
1302 // close start menus when launching the selected entry
1305 ///@todo launch in the background; specify correct HWND for error message box titles
1306 SHELLEXECUTEINFO shexinfo
;
1308 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
1309 shexinfo
.fMask
= SEE_MASK_IDLIST
; // SEE_MASK_INVOKEIDLIST is also possible.
1310 shexinfo
.hwnd
= hparent
;
1311 shexinfo
.lpVerb
= NULL
;
1312 shexinfo
.lpFile
= NULL
;
1313 shexinfo
.lpParameters
= NULL
;
1314 shexinfo
.lpDirectory
= NULL
;
1315 shexinfo
.nShow
= SW_SHOWNORMAL
;
1317 shexinfo
.lpIDList
= &*shell_path
;
1319 // add PIDL to the recent file list
1320 SHAddToRecentDocs(SHARD_PIDL
, shexinfo
.lpIDList
);
1322 if (!ShellExecuteEx(&shexinfo
))
1323 display_error(hparent
, GetLastError());
1325 // we may have deleted 'this' - ensure we leave the loop and function
1330 if (!new_folders
.empty()) {
1331 // Only open one submenu at a time.
1332 if (!CloseOtherSubmenus(id
))
1335 CreateSubmenu(id
, new_folders
, title
);
1340 /// close all windows of the start menu popup
1341 void StartMenu::CloseStartMenu(int id
)
1343 if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) { // don't automatically close floating menus
1344 if (!SendParent(PM_STARTENTRY_LAUNCHED
, id
, (LPARAM
)_hwnd
))
1345 DestroyWindow(_hwnd
);
1346 } else if (_submenu
) // instead close submenus of floating parent menus
1351 int GetStartMenuBtnTextWidth(HDC hdc
, LPCTSTR title
, HWND hwnd
)
1353 RECT rect
= {0, 0, 0, 0};
1354 DrawText(hdc
, title
, -1, &rect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_CALCRECT
);
1356 return rect
.right
-rect
.left
;
1359 #ifdef _LIGHT_STARTMENU
1360 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, const SMBtnInfo
& btn
, bool has_focus
, bool pushed
)
1362 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, HICON hIcon
,
1363 bool hasSubmenu
, bool enabled
, bool has_focus
, bool pushed
);
1366 UINT style
= DFCS_BUTTONPUSH
;
1369 style
|= DFCS_INACTIVE
;
1371 POINT iconPos
= {rect
.left
+2, (rect
.top
+rect
.bottom
-16)/2};
1372 RECT textRect
= {rect
.left
+16+4, rect
.top
+2, rect
.right
-4, rect
.bottom
-4};
1375 style
|= DFCS_PUSHED
;
1376 ++iconPos
.x
; ++iconPos
.y
;
1377 ++textRect
.left
; ++textRect
.top
;
1378 ++textRect
.right
; ++textRect
.bottom
;
1381 int bk_color_idx
= COLOR_BTNFACE
;
1382 int text_color_idx
= COLOR_BTNTEXT
;
1385 bk_color_idx
= COLOR_HIGHLIGHT
;
1386 text_color_idx
= COLOR_HIGHLIGHTTEXT
;
1389 COLORREF bk_color
= GetSysColor(bk_color_idx
);
1390 HBRUSH bk_brush
= GetSysColorBrush(bk_color_idx
);
1393 FillRect(hdc
, &rect
, bk_brush
);
1395 if (btn
._icon_id
> ICID_NONE
)
1396 g_Globals
._icon_cache
.get_icon(btn
._icon_id
).draw(hdc
, iconPos
.x
, iconPos
.y
, 16, 16, bk_color
, bk_brush
);
1398 // draw submenu arrow at the right
1399 if (btn
._hasSubmenu
) {
1400 static SmallIcon
arrowIcon(IDI_ARROW
);
1401 static SmallIcon
selArrowIcon(IDI_ARROW_SELECTED
);
1403 DrawIconEx(hdc
, rect
.right
-16, iconPos
.y
,
1404 has_focus
? selArrowIcon
: arrowIcon
,
1405 16, 16, 0, bk_brush
, DI_NORMAL
);
1409 BkMode
bk_mode(hdc
, TRANSPARENT
);
1411 if (!btn
._enabled
) // dis->itemState & (ODS_DISABLED|ODS_GRAYED)
1412 DrawGrayText(hdc
, &textRect
, title
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1414 TextColor
lcColor(hdc
, GetSysColor(text_color_idx
));
1415 DrawText(hdc
, title
, -1, &textRect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1421 #ifdef _LIGHT_STARTMENU
1423 void StartMenu::ResizeToButtons()
1425 WindowRect
rect(_hwnd
);
1427 WindowCanvas
canvas(_hwnd
);
1428 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1430 int max_width
= STARTMENU_WIDTH_MIN
;
1433 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
1434 int w
= GetStartMenuBtnTextWidth(canvas
, it
->_title
, _hwnd
);
1440 height
+= STARTMENU_SEP_HEIGHT
;
1442 height
+= STARTMENU_LINE_HEIGHT
;
1445 // calculate new window size
1446 int text_width
= max_width
+ 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1448 RECT rt_hgt
= {rect
.left
, rect
.bottom
-_border_top
-height
, rect
.left
+_border_left
+text_width
, rect
.bottom
};
1449 AdjustWindowRectEx(&rt_hgt
, GetWindowStyle(_hwnd
), FALSE
, GetWindowExStyle(_hwnd
));
1451 // ignore movement, only look at the size change
1452 rect
.right
= rect
.left
+ (rt_hgt
.right
-rt_hgt
.left
);
1453 rect
.top
= rect
.bottom
- (rt_hgt
.bottom
-rt_hgt
.top
);
1455 // move down if we are too high
1462 // enable scroll mode for long start menus, which span more than the whole screen height
1463 int cyscreen
= GetSystemMetrics(SM_CYSCREEN
);
1466 if (rect
.bottom
> cyscreen
) {
1469 _invisible_lines
= (rect
.bottom
-cyscreen
+(STARTMENU_LINE_HEIGHT
-1))/STARTMENU_LINE_HEIGHT
+ 1;
1470 rect
.bottom
-= _invisible_lines
* STARTMENU_LINE_HEIGHT
;
1472 bottom_max
= rect
.bottom
;
1475 rect
.bottom
+= 6; // lower scroll arrow
1477 _border_top
+= 6; // upper scroll arrow
1478 rect
.bottom
+= 2*6; // upper+lower scroll arrow
1482 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1485 POINT pt
= {0, bottom_max
};
1487 ScreenToClient(_hwnd
, &pt
);
1493 #else // _LIGHT_STARTMENU
1495 LRESULT
StartMenuButton::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1499 // automatically set the focus to startmenu entries when moving the mouse over them
1500 if (GetFocus()!=_hwnd
&& !(GetWindowStyle(_hwnd
)&WS_DISABLED
))
1505 PostParent(PM_STARTENTRY_FOCUSED
, _hasSubmenu
, (LPARAM
)_hwnd
);
1509 // route WM_CANCELMODE to the startmenu window
1510 return SendParent(nmsg
, wparam
, lparam
);
1513 return super::WndProc(nmsg
, wparam
, lparam
);
1519 void StartMenuButton::DrawItem(LPDRAWITEMSTRUCT dis
)
1521 TCHAR title
[BUFFER_LEN
];
1523 GetWindowText(_hwnd
, title
, BUFFER_LEN
);
1525 DrawStartMenuButton(dis
->hDC
, dis
->rcItem
, title
, _hIcon
,
1527 !(dis
->itemState
& ODS_DISABLED
),
1528 dis
->itemState
&ODS_FOCUS
? true: false,
1529 dis
->itemState
&ODS_SELECTED
? true: false);
1535 StartMenuRoot::StartMenuRoot(HWND hwnd
)
1538 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1539 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCOMMONGROUPS
))
1542 // insert directory "All Users\Start Menu"
1543 ShellDirectory
cmn_startmenu(GetDesktopFolder(), SpecialFolderPath(CSIDL_COMMON_STARTMENU
, _hwnd
), _hwnd
);
1544 _dirs
.push_back(StartMenuDirectory(cmn_startmenu
, (LPCTSTR
)SpecialFolderFSPath(CSIDL_COMMON_PROGRAMS
, _hwnd
)));
1545 } catch(COMException
&) {
1546 // ignore exception and don't show additional shortcuts
1550 // insert directory "<user name>\Start Menu"
1552 ShellDirectory
usr_startmenu(GetDesktopFolder(), SpecialFolderPath(CSIDL_STARTMENU
, _hwnd
), _hwnd
);
1553 _dirs
.push_back(StartMenuDirectory(usr_startmenu
, (LPCTSTR
)SpecialFolderFSPath(CSIDL_PROGRAMS
, _hwnd
)));
1554 } catch(COMException
&) {
1555 // ignore exception and don't show additional shortcuts
1558 // read size of logo bitmap
1560 GetObject(ResBitmap(IDB_LOGOV
), sizeof(BITMAP
), &bmp_hdr
);
1561 _logo_size
.cx
= bmp_hdr
.bmWidth
;
1562 _logo_size
.cy
= bmp_hdr
.bmHeight
;
1564 _border_left
= _logo_size
.cx
+ 1;
1568 static void CalculateStartPos(HWND hwndOwner
, RECT
& rect
)
1570 WindowRect
pos(hwndOwner
);
1572 rect
.left
= pos
.left
;
1573 rect
.top
= pos
.top
-STARTMENU_LINE_HEIGHT
-4;
1574 rect
.right
= pos
.left
+STARTMENU_WIDTH_MIN
;
1575 rect
.bottom
= pos
.top
;
1577 #ifndef _LIGHT_STARTMENU
1578 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1581 AdjustWindowRectEx(&rect
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
, FALSE
, 0);
1584 HWND
StartMenuRoot::Create(HWND hwndOwner
)
1588 CalculateStartPos(hwndOwner
, rect
);
1590 return Window::Create(WINDOW_CREATOR(StartMenuRoot
), 0, GetWndClasss(), TITLE_STARTMENU
,
1591 WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
,
1592 rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndOwner
);
1596 void StartMenuRoot::TrackStartmenu()
1601 #ifdef _LIGHT_STARTMENU
1605 #ifdef _LIGHT_STARTMENU
1606 // recalculate start menu root position
1609 CalculateStartPos(GetParent(hwnd
), rect
);
1611 SetWindowPos(hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, 0);
1616 // show previously hidden start menu
1617 ShowWindow(hwnd
, SW_SHOW
);
1618 SetForegroundWindow(hwnd
);
1620 while(IsWindow(hwnd
)) {
1621 if (!GetMessage(&msg
, 0, 0, 0)) {
1622 PostQuitMessage(msg
.wParam
);
1626 // Check for a mouse click on any window, which is not part of the start menu
1627 if (msg
.message
==WM_LBUTTONDOWN
|| msg
.message
==WM_MBUTTONDOWN
|| msg
.message
==WM_RBUTTONDOWN
) {
1628 StartMenu
* menu_wnd
= NULL
;
1630 for(HWND hwnd
=msg
.hwnd
; hwnd
; hwnd
=GetParent(hwnd
)) {
1631 menu_wnd
= WINDOW_DYNAMIC_CAST(StartMenu
, hwnd
);
1644 if (pretranslate_msg(&msg
))
1647 if (dispatch_dialog_msg(&msg
))
1650 TranslateMessage(&msg
);
1653 DispatchMessage(&msg
);
1654 } catch(COMException
& e
) {
1655 HandleException(e
, _hwnd
);
1657 } catch(COMException
& e
) {
1658 HandleException(e
, _hwnd
);
1664 LRESULT
StartMenuRoot::Init(LPCREATESTRUCT pcs
)
1666 // add buttons for entries in _entries
1667 if (super::Init(pcs
))
1677 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"), &hkey
))
1680 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), &hkeyAdv
))
1683 #define IS_VALUE_ZERO(hk, name) \
1684 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || !value))
1686 #define IS_VALUE_NOT_ZERO(hk, name) \
1687 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || value>0))
1691 // insert hard coded start entries
1692 AddButton(ResString(IDS_PROGRAMS
), ICID_APPS
, true, IDC_PROGRAMS
);
1694 AddButton(ResString(IDS_DOCUMENTS
), ICID_DOCUMENTS
, true, IDC_DOCUMENTS
);
1696 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1697 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORECENTDOCSMENU
))
1699 if (IS_VALUE_ZERO(hkey
, _T("NoRecentDocsMenu")))
1701 AddButton(ResString(IDS_RECENT
), ICID_DOCUMENTS
, true, IDC_RECENT
);
1703 AddButton(ResString(IDS_FAVORITES
), ICID_FAVORITES
, true, IDC_FAVORITES
);
1705 AddButton(ResString(IDS_SETTINGS
), ICID_CONFIG
, true, IDC_SETTINGS
);
1707 AddButton(ResString(IDS_BROWSE
), ICID_FOLDER
, true, IDC_BROWSE
);
1709 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1710 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOFIND
))
1712 if (IS_VALUE_ZERO(hkey
, _T("NoFind")))
1714 AddButton(ResString(IDS_SEARCH
), ICID_SEARCH
, true, IDC_SEARCH
);
1716 AddButton(ResString(IDS_START_HELP
), ICID_INFO
, false, IDC_START_HELP
);
1718 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1719 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORUN
))
1721 if (IS_VALUE_ZERO(hkey
, _T("NoRun")))
1723 AddButton(ResString(IDS_LAUNCH
), ICID_ACTION
, false, IDC_LAUNCH
);
1729 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1730 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCLOSE
))
1732 if (IS_VALUE_NOT_ZERO(hkeyAdv
, _T("StartMenuLogoff")))
1734 AddButton(ResString(IDS_LOGOFF
), ICID_LOGOFF
, false, IDC_LOGOFF
);
1737 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1738 if (!g_Globals
._SHRestricted
|| SHRestricted(REST_STARTMENULOGOFF
) != 1)
1740 if (IS_VALUE_ZERO(hkey
, _T("NoClose")))
1742 AddButton(ResString(IDS_SHUTDOWN
), ICID_LOGOFF
, false, IDC_SHUTDOWN
);
1745 AddButton(ResString(IDS_TERMINATE
), ICID_LOGOFF
, false, IDC_TERMINATE
);
1749 RegCloseKey(hkeyAdv
);
1754 #ifdef _LIGHT_STARTMENU
1755 // set the window size to fit all buttons
1763 void StartMenuRoot::AddEntries()
1765 super::AddEntries();
1767 AddButton(ResString(IDS_EXPLORE
), ICID_EXPLORER
, false, IDC_EXPLORE
);
1771 LRESULT
StartMenuRoot::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1775 PaintCanvas
canvas(_hwnd
);
1780 return super::WndProc(nmsg
, wparam
, lparam
);
1786 void StartMenuRoot::Paint(PaintCanvas
& canvas
)
1789 {WindowCanvas
dc(_hwnd
); clr_bits
=GetDeviceCaps(dc
, BITSPIXEL
);}
1792 ResBitmap
bmp(clr_bits
<=8? clr_bits
<=4? IDB_LOGOV16
: IDB_LOGOV256
: IDB_LOGOV
);
1793 BitmapSelection
sel(mem_dc
, bmp
);
1795 ClientRect
clnt(_hwnd
);
1796 int h
= min(_logo_size
.cy
, clnt
.bottom
);
1798 RECT rect
= {0, 0, _logo_size
.cx
, clnt
.bottom
-h
};
1799 HBRUSH hbr
= CreateSolidBrush(GetPixel(mem_dc
, 0, 0));
1800 FillRect(canvas
, &rect
, hbr
);
1803 PatBlt(canvas
, _logo_size
.cx
, 0, 1, clnt
.bottom
, WHITENESS
);
1805 BitBlt(canvas
, 0, clnt
.bottom
-h
, _logo_size
.cx
, h
, mem_dc
, 0, 0, SRCCOPY
);
1807 super::Paint(canvas
);
1811 void StartMenuRoot::CloseStartMenu(int id
)
1816 ShowWindow(_hwnd
, SW_HIDE
);
1819 void StartMenuRoot::ProcessKey(int vk
)
1824 CloseOtherSubmenus();
1825 // don't close start menu root
1829 super::ProcessKey(vk
);
1834 int StartMenuHandler::Command(int id
, int code
)
1841 CreateSubmenu(id
, CSIDL_COMMON_PROGRAMS
, CSIDL_PROGRAMS
, ResString(IDS_PROGRAMS
));
1846 explorer_show_frame(SW_SHOWNORMAL
);
1851 ShowLaunchDialog(g_Globals
._hwndDesktopBar
);
1855 CreateSubmenu(id
, CSIDL_PERSONAL
, ResString(IDS_DOCUMENTS
));
1859 CreateSubmenu(id
, CSIDL_RECENT
, ResString(IDS_RECENT
), STARTMENU_CREATOR(RecentStartMenu
));
1863 #ifndef _SHELL32_FAVORITES
1864 CreateSubmenu(id
, ResString(IDS_FAVORITES
), STARTMENU_CREATOR(FavoritesMenu
), &static_cast<BookmarkList
&>(g_Globals
._favorites
));
1866 CreateSubmenu(id
, CSIDL_COMMON_FAVORITES
, CSIDL_FAVORITES
, ResString(IDS_FAVORITES
));
1871 CreateSubmenu(id
, ResString(IDS_BROWSE
), STARTMENU_CREATOR(BrowseMenu
));
1875 CreateSubmenu(id
, ResString(IDS_SETTINGS
), STARTMENU_CREATOR(SettingsMenu
));
1879 CreateSubmenu(id
, ResString(IDS_SEARCH
), STARTMENU_CREATOR(SearchMenu
));
1882 case IDC_START_HELP
:
1884 MessageBox(g_Globals
._hwndDesktopBar
, TEXT("Help not yet implemented"), ResString(IDS_TITLE
), MB_OK
);
1889 ShowLogoffDialog(g_Globals
._hwndDesktopBar
);
1893 DestroyWindow(GetParent(_hwnd
));
1898 ShowExitWindowsDialog(g_Globals
._hwndDesktopBar
);
1904 case ID_DESKTOPBAR_SETTINGS
:
1906 ExplorerPropertySheet(g_Globals
._hwndDesktopBar
);
1909 case IDC_CONTROL_PANEL
: {
1913 XMLPos explorer_options
= g_Globals
.get_cfg("general/explorer");
1914 bool mdi
= XMLBool(explorer_options
, "mdi", true);
1917 MDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
1920 SDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
1922 launch_file(_hwnd
, SHELLPATH_CONTROL_PANEL
);
1926 case IDC_SETTINGS_MENU
:
1927 CreateSubmenu(id
, CSIDL_CONTROLS
, ResString(IDS_SETTINGS_MENU
));
1930 case IDC_PRINTERS
: {
1934 #ifdef _ROS_ // to be removed when printer folder will be implemented
1935 MessageBox(0, TEXT("printer folder not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1938 XMLPos explorer_options
= g_Globals
.get_cfg("general/explorer");
1939 bool mdi
= XMLBool(explorer_options
, "mdi", true);
1942 MDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}"), 0);
1945 SDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}"), 0);
1948 launch_file(_hwnd
, SHELLPATH_PRINTERS
);
1952 case IDC_PRINTERS_MENU
:
1953 CreateSubmenu(id
, CSIDL_PRINTERS
, CSIDL_PRINTHOOD
, ResString(IDS_PRINTERS
));
1954 /* StartMenuFolders new_folders;
1957 new_folders.push_back(ShellPath(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}")));
1958 } catch(COMException&) {
1961 CreateSubmenu(id, new_folders, ResString(IDS_PRINTERS));*/
1966 CreateSubmenu(id
, CSIDL_COMMON_ADMINTOOLS
, CSIDL_ADMINTOOLS
, ResString(IDS_ADMIN
));
1967 //CloseStartMenu(id);
1968 //MainFrame::Create(SpecialFolderPath(CSIDL_COMMON_ADMINTOOLS, _hwnd), OWM_PIDL);
1970 launch_file(_hwnd
, SpecialFolderFSPath(CSIDL_COMMON_ADMINTOOLS
, _hwnd
));
1974 case IDC_CONNECTIONS
:
1976 #ifdef _ROS_ // to be removed when RAS will be implemented
1977 MessageBox(0, TEXT("RAS folder not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1979 CreateSubmenu(id
, CSIDL_CONNECTIONS
, ResString(IDS_CONNECTIONS
));
1980 //CloseStartMenu(id);
1981 //MainFrame::Create(SpecialFolderPath(CSIDL_CONNECTIONS, _hwnd), OWM_PIDL);
1984 launch_file(_hwnd
, SHELLPATH_NET_CONNECTIONS
);
1992 #ifdef _ROS_ // to be removed when network will be implemented
1993 MessageBox(0, TEXT("network not yet implemented"), ResString(IDS_TITLE
), MB_OK
);
1995 CreateSubmenu(id
, CSIDL_NETWORK
, ResString(IDS_NETWORK
));
2000 ///@todo exclude removable drives
2001 CreateSubmenu(id
, CSIDL_DRIVES
, ResString(IDS_DRIVES
));
2007 case IDC_SEARCH_PROGRAM
:
2009 Dialog::DoModal(IDD_SEARCH_PROGRAM
, WINDOW_CREATOR(FindProgramDlg
));
2012 case IDC_SEARCH_FILES
:
2017 case IDC_SEARCH_COMPUTER
:
2019 ShowSearchComputer();
2024 return super::Command(id
, code
);
2031 void StartMenuHandler::ShowSearchDialog()
2033 static DynamicFct
<SHFINDFILES
> SHFindFiles(TEXT("SHELL32"), 90);
2036 (*SHFindFiles
)(NULL
, NULL
);
2038 MessageBox(0, TEXT("SHFindFiles() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2041 void StartMenuHandler::ShowSearchComputer()
2043 static DynamicFct
<SHFINDCOMPUTER
> SHFindComputer(TEXT("SHELL32"), 91);
2046 (*SHFindComputer
)(NULL
, NULL
);
2048 MessageBox(0, TEXT("SHFindComputer() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2051 void StartMenuHandler::ShowLaunchDialog(HWND hwndOwner
)
2053 ///@todo All text phrases should be put into the resources.
2054 static LPCSTR szTitle
= "Run";
2055 static LPCSTR szText
= "Type the name of a program, folder, document, or Internet resource, and Explorer will open it for you.";
2057 static DynamicFct
<RUNFILEDLG
> RunFileDlg(TEXT("SHELL32"), 61);
2059 // Show "Run..." dialog
2061 #ifndef _ROS_ /* FIXME: our shell32 always expects Ansi strings */
2062 if ((HIWORD(GetVersion())>>14) == W_VER_NT
) {
2063 WCHAR wTitle
[40], wText
[256];
2065 MultiByteToWideChar(CP_ACP
, 0, szTitle
, -1, wTitle
, 40);
2066 MultiByteToWideChar(CP_ACP
, 0, szText
, -1, wText
, 256);
2068 (*RunFileDlg
)(hwndOwner
, 0, NULL
, (LPCSTR
)wTitle
, (LPCSTR
)wText
, RFF_CALCDIRECTORY
);
2072 (*RunFileDlg
)(hwndOwner
, 0, NULL
, szTitle
, szText
, RFF_CALCDIRECTORY
);
2076 void StartMenuHandler::ShowLogoffDialog(HWND hwndOwner
)
2078 static DynamicFct
<LOGOFFWINDOWSDIALOG
> LogoffWindowsDialog(TEXT("SHELL32"), 54);
2079 // static DynamicFct<RESTARTWINDOWSDLG> RestartDialog(TEXT("SHELL32"), 59);
2081 if (LogoffWindowsDialog
)
2082 (*LogoffWindowsDialog
)(0);
2083 /* The RestartDialog function prompts about some system setting change. This is not what we want to display here.
2084 else if (RestartDialog)
2085 return (*RestartDialog)(hwndOwner, (LPWSTR)L"You selected <Log Off>.\n\n", EWX_LOGOFF) == 1; ///@todo ANSI string conversion if needed
2088 MessageBox(hwndOwner
, TEXT("LogoffWindowsDialog() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2091 void ShowExitWindowsDialog(HWND hwndOwner
)
2093 static DynamicFct
<EXITWINDOWSDLG
> ExitWindowsDialog(TEXT("SHELL32"), 60);
2095 if (ExitWindowsDialog
)
2096 (*ExitWindowsDialog
)(hwndOwner
);
2098 MessageBox(hwndOwner
, TEXT("ExitWindowsDialog() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2102 void SettingsMenu::AddEntries()
2104 super::AddEntries();
2106 #if defined(ROSSHELL) || defined(_ROS_) // _ROS_ to be removed when printer/network will be implemented
2107 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, false, IDC_PRINTERS_MENU
);
2108 AddButton(ResString(IDS_CONNECTIONS
), ICID_NETWORK
, false, IDC_CONNECTIONS
);
2110 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, true, IDC_PRINTERS_MENU
);
2111 AddButton(ResString(IDS_CONNECTIONS
), ICID_NETWORK
, true, IDC_CONNECTIONS
);
2113 AddButton(ResString(IDS_ADMIN
), ICID_CONFIG
, true, IDC_ADMIN
);
2115 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2116 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
2118 AddButton(ResString(IDS_SETTINGS_MENU
), ICID_CONFIG
, true, IDC_SETTINGS_MENU
);
2120 AddButton(ResString(IDS_DESKTOPBAR_SETTINGS
), ICID_CONFIG
, false, ID_DESKTOPBAR_SETTINGS
);
2122 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, false, IDC_PRINTERS
);
2124 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2125 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
2127 AddButton(ResString(IDS_CONTROL_PANEL
), ICID_CONFIG
, false, IDC_CONTROL_PANEL
);
2130 void BrowseMenu::AddEntries()
2132 super::AddEntries();
2134 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2135 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NONETHOOD
)) // or REST_NOENTIRENETWORK ?
2137 #if defined(ROSSHELL) || defined(_ROS_) // _ROS_ to be removed when printer/network will be implemented
2138 AddButton(ResString(IDS_NETWORK
), ICID_NETWORK
, false, IDC_NETWORK
);
2140 AddButton(ResString(IDS_NETWORK
), ICID_NETWORK
, true, IDC_NETWORK
);
2143 AddButton(ResString(IDS_DRIVES
), ICID_FOLDER
, true, IDC_DRIVES
);
2146 void SearchMenu::AddEntries()
2148 super::AddEntries();
2150 AddButton(ResString(IDS_SEARCH_FILES
), ICID_SEARCH_DOC
, false, IDC_SEARCH_FILES
);
2152 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2153 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_HASFINDCOMPUTERS
))
2155 AddButton(ResString(IDS_SEARCH_COMPUTER
),ICID_COMPUTER
, false, IDC_SEARCH_COMPUTER
);
2157 AddButton(ResString(IDS_SEARCH_PRG
), ICID_APPS
, false, IDC_SEARCH_PROGRAM
);
2161 void RecentStartMenu::AddEntries()
2163 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
2164 StartMenuDirectory
& smd
= *it
;
2165 ShellDirectory
& dir
= smd
._dir
;
2167 if (!dir
._scanned
) {
2170 #ifdef _LAZY_ICONEXTRACT
2171 dir
.smart_scan(SORT_NAME
, SCAN_FILESYSTEM
);
2173 dir
.smart_scan(SORT_NAME
, SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
2177 dir
.sort_directory(SORT_DATE
);
2178 AddShellEntries(dir
, RECENT_DOCS_COUNT
, smd
._ignore
); ///@todo read max. count of entries from registry
2183 #ifndef _SHELL32_FAVORITES
2185 void FavoritesMenu::AddEntries()
2187 super::AddEntries();
2189 String lwr_filter
= _create_info
._filter
;
2190 #ifndef __WINE__ ///@todo _tcslwr() for Wine
2191 _tcslwr((LPTSTR
)lwr_filter
.c_str());
2194 for(BookmarkList::iterator it
=_bookmarks
.begin(); it
!=_bookmarks
.end(); ++it
) {
2195 BookmarkNode
& node
= *it
;
2197 int id
= ++_next_id
;
2199 _entries
[id
] = node
;
2201 if (node
._type
== BookmarkNode::BMNT_FOLDER
) {
2202 BookmarkFolder
& folder
= *node
._pfolder
;
2204 AddButton(folder
._name
, ICID_FOLDER
, true, id
);
2205 } else if (node
._type
== BookmarkNode::BMNT_BOOKMARK
) {
2206 Bookmark
& bookmark
= *node
._pbookmark
;
2208 ICON_ID icon
= ICID_NONE
;
2210 if (!bookmark
._icon_path
.empty())
2211 icon
= g_Globals
._icon_cache
.extract(bookmark
._icon_path
, bookmark
._icon_idx
);
2213 // filter non-directory entries
2214 if (!lwr_filter
.empty()) {
2215 String lwr_name
= bookmark
._name
;
2216 String lwr_desc
= bookmark
._description
;
2217 String lwr_url
= bookmark
._url
;
2219 #ifndef __WINE__ ///@todo _tcslwr() for Wine
2220 _tcslwr((LPTSTR
)lwr_name
.c_str());
2221 _tcslwr((LPTSTR
)lwr_desc
.c_str());
2222 _tcslwr((LPTSTR
)lwr_url
.c_str());
2225 if (!_tcsstr(lwr_name
,lwr_filter
) && !_tcsstr(lwr_desc
,lwr_filter
) && !_tcsstr(lwr_url
,lwr_filter
))
2229 AddButton(bookmark
._name
, icon
!=ICID_NONE
?icon
:ICID_BOOKMARK
, false, id
);
2234 int FavoritesMenu::Command(int id
, int code
)
2236 BookmarkMap::iterator found
= _entries
.find(id
);
2238 if (found
!= _entries
.end()) {
2239 BookmarkNode
& node
= found
->second
;
2241 if (node
._type
== BookmarkNode::BMNT_FOLDER
) {
2242 BookmarkFolder
& folder
= *node
._pfolder
;
2244 if (CloseOtherSubmenus(id
))
2245 CreateSubmenu(id
, folder
._name
, STARTMENU_CREATOR(FavoritesMenu
), &static_cast<BookmarkList
&>(folder
._bookmarks
));
2246 } else if (node
._type
== BookmarkNode::BMNT_BOOKMARK
) {
2247 Bookmark
& bookmark
= *node
._pbookmark
;
2249 String url
= bookmark
._url
;
2250 HWND hparent
= GetParent(_hwnd
);
2254 launch_file(hparent
, url
, SW_SHOWNORMAL
);
2260 return super::Command(id
, code
);