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 "../explorer_intres.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
)
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
;
149 create_info
._title
= title
;
151 HWND hwnd
= Window::Create(creator
, &create_info
, ex_style
, GetWndClasss(), title
,
152 style
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndParent
);
154 // make sure the window is not off the screen
161 LRESULT
StartMenu::Init(LPCREATESTRUCT pcs
)
166 if (super::Init(pcs
))
169 // create buttons for registered entries in _entries
170 for(ShellEntryMap::const_iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
171 const StartMenuEntry
& sme
= it
->second
;
172 bool hasSubmenu
= false;
174 for(ShellEntrySet::const_iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
)
175 if ((*it
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
178 #ifdef _LIGHT_STARTMENU
179 _buttons
.push_back(SMBtnInfo(sme
, it
->first
, hasSubmenu
));
181 AddButton(sme
._title
, sme
._hIcon
, hasSubmenu
, it
->first
);
185 #ifdef _LIGHT_STARTMENU
186 if (_buttons
.empty())
188 if (!GetWindow(_hwnd
, GW_CHILD
))
190 AddButton(ResString(IDS_EMPTY
), ICID_NONE
, false, 0, false);
192 #ifdef _LIGHT_STARTMENU
196 #ifdef _LAZY_ICONEXTRACT
197 PostMessage(_hwnd
, PM_UPDATE_ICONS
, 0, 0);
199 } catch(COMException
& e
) {
200 HandleException(e
, pcs
->hwndParent
); // destroys the start menu window while switching focus
206 void StartMenu::AddEntries()
208 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
209 StartMenuDirectory
& smd
= *it
;
210 ShellDirectory
& dir
= smd
._dir
;
215 #ifdef _LAZY_ICONEXTRACT
216 dir
.smart_scan(SORT_NAME
, SCAN_FILESYSTEM
); // lazy icon extraction, try to read directly from filesystem
218 dir
.smart_scan(SORT_NAME
, SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
222 AddShellEntries(dir
, -1, smd
._ignore
);
227 static LPTSTR
trim_path_slash(LPTSTR path
)
234 if (p
>path
&& (p
[-1]=='\\' || p
[-1]=='/'))
240 void StartMenu::AddShellEntries(const ShellDirectory
& dir
, int max
, const String
& ignore
)
242 TCHAR ignore_path
[MAX_PATH
], ignore_dir
[MAX_PATH
], ignore_name
[_MAX_FNAME
], ignore_ext
[_MAX_EXT
];
243 TCHAR dir_path
[MAX_PATH
];
245 if (!ignore
.empty()) {
246 _tsplitpath(ignore
, ignore_path
, ignore_dir
, ignore_name
, ignore_ext
);
248 _tcscat(ignore_path
, ignore_dir
);
249 _tcscat(ignore_name
, ignore_ext
);
251 dir
.get_path(dir_path
);
253 if (_tcsicmp(trim_path_slash(dir_path
), trim_path_slash(ignore_path
)))
259 for(Entry
*entry
=dir
._down
; entry
; entry
=entry
->_next
) {
260 // hide files like "desktop.ini"
261 if (entry
->_shell_attribs
& SFGAO_HIDDEN
)
262 //not appropriate for drive roots: if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
265 // hide "Programs" subfolders if requested
266 if (*ignore_name
&& !_tcsicmp(entry
->_data
.cFileName
, ignore_name
))
269 // only 'max' entries shall be added.
273 if (entry
->_etype
== ET_SHELL
)
274 AddEntry(dir
._folder
, static_cast<ShellEntry
*>(entry
));
276 AddEntry(dir
._folder
, entry
);
281 LRESULT
StartMenu::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
285 PaintCanvas
canvas(_hwnd
);
290 ResizeButtons(LOWORD(lparam
)-_border_left
);
294 POINTS
& pos
= MAKEPOINTS(lparam
);
296 // move open submenus of floating menus
298 int dx
= pos
.x
- _last_pos
.x
;
299 int dy
= pos
.y
- _last_pos
.y
;
302 WindowRect
rt(_submenu
);
303 SetWindowPos(_submenu
, 0, rt
.left
+dx
, rt
.top
+dy
, 0, 0, SWP_NOSIZE
|SWP_NOACTIVATE
);
304 //MoveVisible(_submenu);
313 LRESULT res
= super::WndProc(nmsg
, wparam
, lparam
);
315 if (res
>=HTSIZEFIRST
&& res
<=HTSIZELAST
)
316 return HTCLIENT
; // disable window resizing
320 case WM_LBUTTONDOWN
: {
323 // check mouse cursor for coordinates of floating button
324 GetFloatingButtonRect(&rect
);
326 if (PtInRect(&rect
, Point(lparam
))) {
327 // create a floating copy of the current start menu
328 WindowRect
pos(_hwnd
);
330 ///@todo do something similar to StartMenuRoot::TrackStartmenu() in order to automatically close submenus when clicking on the desktop background
331 StartMenu::Create(pos
.left
+3, pos
.bottom
-3, _create_info
._folders
, 0, _create_info
._title
, _create_info
._creator
, _create_info
._info
);
335 #ifdef _LIGHT_STARTMENU
336 int id
= ButtonHitTest(Point(lparam
));
339 Command(id
, BN_CLICKED
);
344 if ((wparam
&0xFFF0) == SC_SIZE
)
345 return 0; // disable window resizing
349 // close start menu when activating another application
352 break; // don't call super::WndProc in case "this" has been deleted
357 #ifdef _LIGHT_STARTMENU
358 if (_scroll_mode
!= SCROLL_NOT
) {
365 #ifdef _LIGHT_STARTMENU
367 // automatically set the focus to startmenu entries when moving the mouse over them
368 if (lparam
!= _last_mouse_pos
) { // don't process WM_MOUSEMOVE when opening submenus using keyboard navigation
372 RECT rect_up
, rect_down
;
374 GetArrowButtonRects(&rect_up
, &rect_down
);
376 SCROLL_MODE scroll_mode
= SCROLL_NOT
;
378 if (PtInRect(&rect_up
, pt
))
379 scroll_mode
= SCROLL_UP
;
380 else if (PtInRect(&rect_down
, pt
))
381 scroll_mode
= SCROLL_DOWN
;
383 if (scroll_mode
!= _scroll_mode
) {
384 if (scroll_mode
== SCROLL_NOT
) {
389 SetTimer(_hwnd
, 0, 150, NULL
); // 150 ms scroll interval
393 _scroll_mode
= scroll_mode
;
397 int new_id
= ButtonHitTest(pt
);
399 if (new_id
> 0 && new_id
!= _selected_id
)
400 SelectButton(new_id
);
402 _last_mouse_pos
= lparam
;
407 if (_scroll_mode
== SCROLL_UP
) {
408 if (_scroll_pos
> 0) {
410 InvalidateRect(_hwnd
, NULL
, TRUE
);
413 if (_scroll_pos
<= _invisible_lines
) {
415 InvalidateRect(_hwnd
, NULL
, TRUE
);
424 case PM_STARTENTRY_FOCUSED
: { ///@todo use TrackMouseEvent() and WM_MOUSEHOVER to wait a bit before opening submenus
425 BOOL hasSubmenu
= wparam
;
426 HWND hctrl
= (HWND
)lparam
;
428 // automatically open submenus
430 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
431 //SendMessage(_hwnd, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hctrl),BN_CLICKED), (LPARAM)hctrl);
432 Command(GetDlgCtrlID(hctrl
), BN_CLICKED
);
434 // close any open submenu
435 CloseOtherSubmenus();
440 #ifdef _LAZY_ICONEXTRACT
441 case PM_UPDATE_ICONS
:
442 UpdateIcons(/*wparam*/);
446 case PM_STARTENTRY_LAUNCHED
:
447 if (GetWindowStyle(_hwnd
) & WS_CAPTION
) // don't automatically close floating menus
450 // route message to the parent menu and close menus after launching an entry
451 if (!SendParent(nmsg
, wparam
, lparam
))
453 return 1; // signal that we have received and processed the message
455 case PM_STARTMENU_CLOSED
:
459 case PM_SELECT_ENTRY
:
460 SelectButtonIndex(0, wparam
!=0);
463 #ifdef _LIGHT_STARTMENU
464 case WM_CONTEXTMENU
: {
465 Point
screen_pt(lparam
), clnt_pt
=screen_pt
;
466 ScreenToClient(_hwnd
, &clnt_pt
);
468 int id
= ButtonHitTest(clnt_pt
);
471 StartMenuEntry
& sme
= _entries
[id
];
473 for(ShellEntrySet::iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
) {
477 CHECKERROR(entry
->do_context_menu(_hwnd
, screen_pt
, _cm_ifs
)); // may close start menu because of focus loss
478 break; ///@todo handle context menu for more than one entry
486 return super::WndProc(nmsg
, wparam
, lparam
);
493 #ifdef _LIGHT_STARTMENU
495 int StartMenu::ButtonHitTest(POINT pt
)
497 ClientRect
clnt(_hwnd
);
498 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
500 if (pt
.x
<rect
.left
|| pt
.x
>rect
.right
)
503 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
504 const SMBtnInfo
& info
= *it
;
509 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
511 if (rect
.bottom
> _bottom_max
)
514 if (pt
.y
< rect
.bottom
) // PtInRect(&rect, pt)
517 rect
.top
= rect
.bottom
;
523 void StartMenu::InvalidateSelection()
525 if (_selected_id
<= 0)
528 ClientRect
clnt(_hwnd
);
529 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
531 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
532 const SMBtnInfo
& info
= *it
;
534 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
536 if (info
._id
== _selected_id
) {
537 InvalidateRect(_hwnd
, &rect
, TRUE
);
541 rect
.top
= rect
.bottom
;
545 const SMBtnInfo
* StartMenu::GetButtonInfo(int id
) const
547 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
)
554 bool StartMenu::SelectButton(int id
, bool open_sub
)
559 if (id
== _selected_id
)
562 InvalidateSelection();
564 const SMBtnInfo
* btn
= GetButtonInfo(id
);
566 if (btn
&& btn
->_enabled
) {
569 InvalidateSelection();
571 // automatically open submenus
572 if (btn
->_hasSubmenu
) {
576 CloseOtherSubmenus(); // close any open submenu
585 bool StartMenu::OpenSubmenu(bool select_first
)
587 if (_selected_id
== -1)
590 InvalidateSelection();
592 const SMBtnInfo
* btn
= GetButtonInfo(_selected_id
);
594 // automatically open submenus
595 if (btn
->_hasSubmenu
) {
596 //@@ allows destroying of startmenu when processing PM_UPDATE_ICONS -> GPF
597 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
598 Command(_selected_id
, BN_CLICKED
);
600 if (select_first
&& _submenu
)
601 SendMessage(_submenu
, PM_SELECT_ENTRY
, (WPARAM
)false, 0);
609 int StartMenu::GetSelectionIndex()
611 if (_selected_id
== -1)
614 for(int i
=0; i
<(int)_buttons
.size(); ++i
)
615 if (_buttons
[i
]._id
== _selected_id
)
621 bool StartMenu::SelectButtonIndex(int idx
, bool open_sub
)
623 if (idx
>=0 && idx
<(int)_buttons
.size())
624 return SelectButton(_buttons
[idx
]._id
, open_sub
);
629 void StartMenu::ProcessKey(int vk
)
634 Command(_selected_id
, BN_CLICKED
);
646 SelectButtonIndex(0, false);
650 SelectButtonIndex(_buttons
.size()-1, false);
655 CloseOtherSubmenus();
656 else if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) // don't automatically close floating menus
657 DestroyWindow(_hwnd
);
669 if (vk
>='0' && vk
<='Z')
670 JumpToNextShortcut(vk
);
674 bool StartMenu::Navigate(int step
)
676 int idx
= GetSelectionIndex();
682 idx
= _buttons
.size() - step
;
687 if (idx
<0 || idx
>(int)_buttons
.size())
690 if (SelectButtonIndex(idx
, false))
697 bool StartMenu::JumpToNextShortcut(char c
)
699 int cur_idx
= GetSelectionIndex();
707 SMBtnVector::const_iterator cur_it
= _buttons
.begin();
708 cur_it
+= cur_idx
+ 1;
710 // first search down from current item...
711 SMBtnVector::const_iterator it
= cur_it
;
712 for(; it
!=_buttons
.end(); ++it
) {
713 const SMBtnInfo
& btn
= *it
;
715 if (!btn
._title
.empty() && toupper((TBYTE
)btn
._title
.at(0)) == c
) {
717 first_found
= btn
._id
;
723 // ...now search from top to the current item
724 it
= _buttons
.begin();
725 for(; it
!=_buttons
.end() && it
!=cur_it
; ++it
) {
726 const SMBtnInfo
& btn
= *it
;
728 if (!btn
._title
.empty() && toupper((TBYTE
)btn
._title
.at(0)) == c
) {
730 first_found
= btn
._id
;
737 SelectButton(first_found
);
740 Command(first_found
, BN_CLICKED
);
747 #endif // _LIGHT_STARTMENU
750 bool StartMenu::GetButtonRect(int id
, PRECT prect
) const
752 #ifdef _LIGHT_STARTMENU
753 ClientRect
clnt(_hwnd
);
754 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
756 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
757 const SMBtnInfo
& info
= *it
;
759 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
761 if (info
._id
== id
) {
766 rect
.top
= rect
.bottom
;
771 HWND btn
= GetDlgItem(_hwnd
, id
);
774 GetWindowRect(btn
, prect
);
775 ScreenToClient(_hwnd
, prect
);
784 void StartMenu::DrawFloatingButton(HDC hdc
)
786 static ResIconEx
floatingIcon(IDI_FLOATING
, 8, 4);
788 ClientRect
clnt(_hwnd
);
790 DrawIconEx(hdc
, clnt
.right
-12, 0, floatingIcon
, 8, 4, 0, 0, DI_NORMAL
);
793 void StartMenu::GetFloatingButtonRect(LPRECT prect
)
795 GetClientRect(_hwnd
, prect
);
798 prect
->left
= prect
->right
- 8;
803 void StartMenu::DrawArrows(HDC hdc
)
805 static ResIconEx
arrowUpIcon(IDI_ARROW_UP
, 8, 4);
806 static ResIconEx
arrowDownIcon(IDI_ARROW_DOWN
, 8, 4);
808 ClientRect
clnt(_hwnd
);
810 DrawIconEx(hdc
, clnt
.right
/2-4, _floating_btn
?3:1, arrowUpIcon
, 8, 4, 0, 0, DI_NORMAL
);
811 DrawIconEx(hdc
, clnt
.right
/2-4, clnt
.bottom
-5, arrowDownIcon
, 8, 4, 0, 0, DI_NORMAL
);
814 void StartMenu::GetArrowButtonRects(LPRECT prect_up
, LPRECT prect_down
)
816 GetClientRect(_hwnd
, prect_up
);
817 *prect_down
= *prect_up
;
819 // prect_up->left = prect_up->right/2 - 4;
820 // prect_up->right = prect_up->left + 8;
821 prect_up
->right
-= 8;
822 prect_up
->top
= _floating_btn
? 3: 1;
823 prect_up
->bottom
= prect_up
->top
+ 4;
825 // prect_down->left = prect_down->right/2 - 4;
826 // prect_down->right = prect_down->left + 8;
827 prect_down
->right
-= 8;
828 prect_down
->top
= prect_down
->bottom
- 5;
832 void StartMenu::Paint(PaintCanvas
& canvas
)
835 DrawFloatingButton(canvas
);
837 #ifdef _LIGHT_STARTMENU
841 ClientRect
clnt(_hwnd
);
842 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
844 int sep_width
= rect
.right
-rect
.left
- 4;
846 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
847 BkMode
bk_mode(canvas
, TRANSPARENT
);
849 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
850 const SMBtnInfo
& btn
= *it
;
852 if (rect
.top
> canvas
.rcPaint
.bottom
)
855 if (btn
._id
== -1) { // a separator?
856 rect
.bottom
= rect
.top
+ STARTMENU_SEP_HEIGHT
;
858 if (rect
.bottom
> _bottom_max
)
861 BrushSelection
brush_sel(canvas
, GetSysColorBrush(COLOR_BTNSHADOW
));
862 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2-1, sep_width
, 1, PATCOPY
);
864 SelectBrush(canvas
, GetSysColorBrush(COLOR_BTNHIGHLIGHT
));
865 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2, sep_width
, 1, PATCOPY
);
867 rect
.bottom
= rect
.top
+ STARTMENU_LINE_HEIGHT
;
869 if (rect
.bottom
> _bottom_max
)
872 if (rect
.top
>= canvas
.rcPaint
.top
)
873 DrawStartMenuButton(canvas
, rect
, btn
._title
, btn
, btn
._id
==_selected_id
, false);
876 rect
.top
= rect
.bottom
;
881 #ifdef _LAZY_ICONEXTRACT
882 void StartMenu::UpdateIcons(/*int idx*/)
886 #ifdef _SINGLE_ICONEXTRACT
889 int idx
= _scroll_pos
;
891 for(; idx
<(int)_buttons
.size(); ++idx
) {
892 SMBtnInfo
& btn
= _buttons
[idx
];
894 if (btn
._icon_id
==ICID_UNKNOWN
&& btn
._id
>0) {
895 StartMenuEntry
& sme
= _entries
[btn
._id
];
897 btn
._icon_id
= ICID_NONE
;
899 for(ShellEntrySet::iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
) {
902 if (entry
->_icon_id
== ICID_UNKNOWN
)
904 entry
->extract_icon();
905 } catch(COMException
&) {
906 // ignore unexpected exceptions while extracting icons
909 if (entry
->_icon_id
> ICID_NONE
) {
910 btn
._icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
914 GetButtonRect(btn
._id
, &rect
);
916 if (rect
.bottom
> _bottom_max
)
919 WindowCanvas
canvas(_hwnd
);
920 DrawStartMenuButton(canvas
, rect
, NULL
, btn
, btn
._id
==_selected_id
, false);
922 //InvalidateRect(_hwnd, &rect, FALSE);
923 //UpdateWindow(_hwnd);
932 // if (++idx < (int)_buttons.size())
933 // PostMessage(_hwnd, PM_UPDATE_ICONS, idx, 0);
937 int icons_extracted
= 0;
938 int icons_updated
= 0;
940 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
941 ShellDirectory
& dir
= it
->_dir
;
943 icons_extracted
+= dir
.extract_icons();
946 if (icons_extracted
) {
947 for(ShellEntryMap::iterator it1
=_entries
.begin(); it1
!=_entries
.end(); ++it1
) {
948 StartMenuEntry
& sme
= it1
->second
;
951 sme
._hIcon
= (HICON
)-1;
953 for(ShellEntrySet::const_iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
954 const Entry
* sm_entry
= *it2
;
956 if (sm_entry
->_hIcon
) {
957 sme
._hIcon
= sm_entry
->_hIcon
;
964 for(SMBtnVector::iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
965 SMBtnInfo
& info
= *it
;
967 if (info
._id
>0 && !info
._hIcon
) {
968 info
._hIcon
= _entries
[info
._id
]._hIcon
;
975 InvalidateRect(_hwnd
, NULL
, FALSE
);
983 // resize child button controls to accomodate for new window size
984 void StartMenu::ResizeButtons(int cx
)
986 HDWP hdwp
= BeginDeferWindowPos(10);
988 for(HWND ctrl
=GetWindow(_hwnd
,GW_CHILD
); ctrl
; ctrl
=GetNextWindow(ctrl
,GW_HWNDNEXT
)) {
991 if (rt
.right
!= cx
) {
992 int height
= rt
.bottom
- rt
.top
;
994 // special handling for separator controls
995 if (!height
&& (GetWindowStyle(ctrl
)&SS_TYPEMASK
)==SS_ETCHEDHORZ
)
998 hdwp
= DeferWindowPos(hdwp
, ctrl
, 0, 0, 0, cx
, height
, SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
);
1002 EndDeferWindowPos(hdwp
);
1006 int StartMenu::Command(int id
, int code
)
1008 #ifndef _LIGHT_STARTMENU
1016 ShellEntryMap::iterator found
= _entries
.find(id
);
1018 if (found
!= _entries
.end()) {
1019 ActivateEntry(id
, found
->second
._entries
);
1023 return super::Command(id
, code
);
1024 #ifndef _LIGHT_STARTMENU
1033 ShellEntryMap::iterator
StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, Entry
* entry
)
1035 // search for an already existing subdirectory entry with the same name
1036 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1037 for(ShellEntryMap::iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
1038 StartMenuEntry
& sme
= it
->second
;
1040 if (sme
._title
== title
) ///@todo speed up by using a map indexed by name
1041 for(ShellEntrySet::iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
1042 if ((*it2
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1043 // merge the new shell entry with the existing of the same name
1044 sme
._entries
.insert(entry
);
1051 ShellEntryMap::iterator sme
= AddEntry(title
, icon_id
);
1053 sme
->second
._entries
.insert(entry
);
1058 ShellEntryMap::iterator
StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, int id
)
1066 sme
._icon_id
= icon_id
;
1068 ShellEntryMap::iterator it
= _entries
.insert(make_pair(id
, sme
)).first
;
1073 ShellEntryMap::iterator
StartMenu::AddEntry(const ShellFolder folder
, ShellEntry
* entry
)
1077 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1078 icon_id
= ICID_FOLDER
;
1080 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
1082 return AddEntry(folder
.get_name(entry
->_pidl
), icon_id
, entry
);
1085 ShellEntryMap::iterator
StartMenu::AddEntry(const ShellFolder folder
, Entry
* entry
)
1089 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1090 icon_id
= ICID_FOLDER
;
1092 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
1094 return AddEntry(entry
->_display_name
, icon_id
, entry
);
1098 void StartMenu::AddButton(LPCTSTR title
, ICON_ID icon_id
, bool hasSubmenu
, int id
, bool enabled
)
1100 #ifdef _LIGHT_STARTMENU
1101 _buttons
.push_back(SMBtnInfo(title
, icon_id
, id
, hasSubmenu
, enabled
));
1103 DWORD style
= enabled
? WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
: WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
|WS_DISABLED
;
1105 WindowRect
rect(_hwnd
);
1106 ClientRect
clnt(_hwnd
);
1108 // increase window height to make room for the new button
1109 rect
.top
-= STARTMENU_LINE_HEIGHT
;
1111 // move down if we are too high now
1113 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1114 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1117 WindowCanvas
canvas(_hwnd
);
1118 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1120 // widen window, if it is too small
1121 int text_width
= GetStartMenuBtnTextWidth(canvas
, title
, _hwnd
) + 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1123 int cx
= clnt
.right
- _border_left
;
1124 if (text_width
> cx
)
1125 rect
.right
+= text_width
-cx
;
1127 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1129 StartMenuCtrl(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
,
1130 title
, id
, g_Globals
._icon_cache
.get_icon(icon_id
)._hIcon
, hasSubmenu
, style
);
1134 void StartMenu::AddSeparator()
1136 #ifdef _LIGHT_STARTMENU
1137 _buttons
.push_back(SMBtnInfo(NULL
, ICID_NONE
, -1, false));
1139 WindowRect
rect(_hwnd
);
1140 ClientRect
clnt(_hwnd
);
1142 // increase window height to make room for the new separator
1143 rect
.top
-= STARTMENU_SEP_HEIGHT
;
1145 // move down if we are too high now
1147 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1148 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1151 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1153 StartMenuSeparator(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
);
1158 bool StartMenu::CloseOtherSubmenus(int id
)
1161 if (IsWindow(_submenu
)) {
1162 if (_submenu_id
== id
)
1166 DestroyWindow(_submenu
);
1167 // _submenu should be reset automatically by PM_STARTMENU_CLOSED, but safety first...
1178 void StartMenu::CreateSubmenu(int id
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1180 CreateSubmenu(id
, StartMenuFolders(), title
, creator
, info
);
1183 bool StartMenu::CreateSubmenu(int id
, int folder_id
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1186 SpecialFolderPath
folder(folder_id
, _hwnd
);
1188 StartMenuFolders new_folders
;
1189 new_folders
.push_back(folder
);
1191 CreateSubmenu(id
, new_folders
, title
, creator
, info
);
1194 } catch(COMException
&) {
1195 // ignore Exception and don't display anything
1196 CloseOtherSubmenus(id
);
1197 _buttons
[GetSelectionIndex()]._enabled
= false; // disable entries for non-existing folders
1202 bool StartMenu::CreateSubmenu(int id
, int folder_id1
, int folder_id2
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1204 StartMenuFolders new_folders
;
1207 new_folders
.push_back(SpecialFolderPath(folder_id1
, _hwnd
));
1208 } catch(COMException
&) {
1212 new_folders
.push_back(SpecialFolderPath(folder_id2
, _hwnd
));
1213 } catch(COMException
&) {
1216 if (!new_folders
.empty()) {
1217 CreateSubmenu(id
, new_folders
, title
, creator
, info
);
1220 CloseOtherSubmenus(id
);
1221 _buttons
[GetSelectionIndex()]._enabled
= false; // disable entries for non-existing folders
1226 void StartMenu::CreateSubmenu(int id
, const StartMenuFolders
& new_folders
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1228 // Only open one submenu at a time.
1229 if (!CloseOtherSubmenus(id
))
1235 if (GetButtonRect(id
, &rect
)) {
1236 ClientToScreen(_hwnd
, &rect
);
1238 x
= rect
.right
; // Submenus should overlap their parent a bit.
1239 y
= rect
.top
+STARTMENU_LINE_HEIGHT
+_border_top
/*own border*/ -STARTMENU_TOP_BTN_SPACE
/*border of new submenu*/;
1241 WindowRect
pos(_hwnd
);
1248 _submenu
= StartMenu::Create(x
, y
, new_folders
, _hwnd
, title
, creator
, info
);
1252 void StartMenu::ActivateEntry(int id
, const ShellEntrySet
& entries
)
1254 StartMenuFolders new_folders
;
1257 for(ShellEntrySet::const_iterator it
=entries
.begin(); it
!=entries
.end(); ++it
) {
1258 Entry
* entry
= const_cast<Entry
*>(*it
);
1260 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1262 ///@todo If the user explicitly clicked on a submenu, display this folder as floating start menu.
1264 if (entry
->_etype
== ET_SHELL
)
1265 new_folders
.push_back(entry
->create_absolute_pidl());
1267 TCHAR path
[MAX_PATH
];
1269 if (entry
->get_path(path
))
1270 new_folders
.push_back(path
);
1274 title
= entry
->_display_name
;
1276 // The entry is no subdirectory, so there can only be one shell entry.
1277 assert(entries
.size()==1);
1279 HWND hparent
= GetParent(_hwnd
);
1280 ShellPath shell_path
= entry
->create_absolute_pidl();
1282 // close start menus when launching the selected entry
1285 ///@todo launch in the background; specify correct HWND for error message box titles
1286 SHELLEXECUTEINFO shexinfo
;
1288 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
1289 shexinfo
.fMask
= SEE_MASK_IDLIST
; // SEE_MASK_INVOKEIDLIST is also possible.
1290 shexinfo
.hwnd
= hparent
;
1291 shexinfo
.lpVerb
= NULL
;
1292 shexinfo
.lpFile
= NULL
;
1293 shexinfo
.lpParameters
= NULL
;
1294 shexinfo
.lpDirectory
= NULL
;
1295 shexinfo
.nShow
= SW_SHOWNORMAL
;
1297 shexinfo
.lpIDList
= &*shell_path
;
1299 // add PIDL to the recent file list
1300 SHAddToRecentDocs(SHARD_PIDL
, shexinfo
.lpIDList
);
1302 if (!ShellExecuteEx(&shexinfo
))
1303 display_error(hparent
, GetLastError());
1305 // we may have deleted 'this' - ensure we leave the loop and function
1310 if (!new_folders
.empty()) {
1311 // Only open one submenu at a time.
1312 if (!CloseOtherSubmenus(id
))
1315 CreateSubmenu(id
, new_folders
, title
);
1320 /// close all windows of the start menu popup
1321 void StartMenu::CloseStartMenu(int id
)
1323 if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) { // don't automatically close floating menus
1324 if (!SendParent(PM_STARTENTRY_LAUNCHED
, id
, (LPARAM
)_hwnd
))
1325 DestroyWindow(_hwnd
);
1326 } else if (_submenu
) // instead close submenus of floating parent menus
1331 int GetStartMenuBtnTextWidth(HDC hdc
, LPCTSTR title
, HWND hwnd
)
1333 RECT rect
= {0, 0, 0, 0};
1334 DrawText(hdc
, title
, -1, &rect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_CALCRECT
);
1336 return rect
.right
-rect
.left
;
1339 #ifdef _LIGHT_STARTMENU
1340 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, const SMBtnInfo
& btn
, bool has_focus
, bool pushed
)
1342 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, HICON hIcon
,
1343 bool hasSubmenu
, bool enabled
, bool has_focus
, bool pushed
);
1346 UINT style
= DFCS_BUTTONPUSH
;
1349 style
|= DFCS_INACTIVE
;
1351 POINT iconPos
= {rect
.left
+2, (rect
.top
+rect
.bottom
-16)/2};
1352 RECT textRect
= {rect
.left
+16+4, rect
.top
+2, rect
.right
-4, rect
.bottom
-4};
1355 style
|= DFCS_PUSHED
;
1356 ++iconPos
.x
; ++iconPos
.y
;
1357 ++textRect
.left
; ++textRect
.top
;
1358 ++textRect
.right
; ++textRect
.bottom
;
1361 int bk_color_idx
= COLOR_BTNFACE
;
1362 int text_color_idx
= COLOR_BTNTEXT
;
1365 bk_color_idx
= COLOR_HIGHLIGHT
;
1366 text_color_idx
= COLOR_HIGHLIGHTTEXT
;
1369 COLORREF bk_color
= GetSysColor(bk_color_idx
);
1370 HBRUSH bk_brush
= GetSysColorBrush(bk_color_idx
);
1373 FillRect(hdc
, &rect
, bk_brush
);
1375 if (btn
._icon_id
> ICID_NONE
)
1376 g_Globals
._icon_cache
.get_icon(btn
._icon_id
).draw(hdc
, iconPos
.x
, iconPos
.y
, 16, 16, bk_color
, bk_brush
);
1378 // draw submenu arrow at the right
1379 if (btn
._hasSubmenu
) {
1380 static SmallIcon
arrowIcon(IDI_ARROW
);
1381 static SmallIcon
selArrowIcon(IDI_ARROW_SELECTED
);
1383 DrawIconEx(hdc
, rect
.right
-16, iconPos
.y
,
1384 has_focus
? selArrowIcon
: arrowIcon
,
1385 16, 16, 0, bk_brush
, DI_NORMAL
);
1389 BkMode
bk_mode(hdc
, TRANSPARENT
);
1391 if (!btn
._enabled
) // dis->itemState & (ODS_DISABLED|ODS_GRAYED)
1392 DrawGrayText(hdc
, &textRect
, title
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1394 TextColor
lcColor(hdc
, GetSysColor(text_color_idx
));
1395 DrawText(hdc
, title
, -1, &textRect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1401 #ifdef _LIGHT_STARTMENU
1403 void StartMenu::ResizeToButtons()
1405 WindowRect
rect(_hwnd
);
1407 WindowCanvas
canvas(_hwnd
);
1408 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1410 int max_width
= STARTMENU_WIDTH_MIN
;
1413 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
1414 int w
= GetStartMenuBtnTextWidth(canvas
, it
->_title
, _hwnd
);
1420 height
+= STARTMENU_SEP_HEIGHT
;
1422 height
+= STARTMENU_LINE_HEIGHT
;
1425 // calculate new window size
1426 int text_width
= max_width
+ 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1428 RECT rt_hgt
= {rect
.left
, rect
.bottom
-_border_top
-height
, rect
.left
+_border_left
+text_width
, rect
.bottom
};
1429 AdjustWindowRectEx(&rt_hgt
, GetWindowStyle(_hwnd
), FALSE
, GetWindowExStyle(_hwnd
));
1431 // ignore movement, only look at the size change
1432 rect
.right
= rect
.left
+ (rt_hgt
.right
-rt_hgt
.left
);
1433 rect
.top
= rect
.bottom
- (rt_hgt
.bottom
-rt_hgt
.top
);
1435 // move down if we are too high
1442 // enable scroll mode for long start menus, which span more than the whole screen height
1443 int cyscreen
= GetSystemMetrics(SM_CYSCREEN
);
1446 if (rect
.bottom
> cyscreen
) {
1449 _invisible_lines
= (rect
.bottom
-cyscreen
+(STARTMENU_LINE_HEIGHT
-1))/STARTMENU_LINE_HEIGHT
+ 1;
1450 rect
.bottom
-= _invisible_lines
* STARTMENU_LINE_HEIGHT
;
1452 bottom_max
= rect
.bottom
;
1455 rect
.bottom
+= 6; // lower scroll arrow
1457 _border_top
+= 6; // upper scroll arrow
1458 rect
.bottom
+= 2*6; // upper+lower scroll arrow
1462 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1465 POINT pt
= {0, bottom_max
};
1467 ScreenToClient(_hwnd
, &pt
);
1473 #else // _LIGHT_STARTMENU
1475 LRESULT
StartMenuButton::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1479 // automatically set the focus to startmenu entries when moving the mouse over them
1480 if (GetFocus()!=_hwnd
&& !(GetWindowStyle(_hwnd
)&WS_DISABLED
))
1485 PostParent(PM_STARTENTRY_FOCUSED
, _hasSubmenu
, (LPARAM
)_hwnd
);
1489 // route WM_CANCELMODE to the startmenu window
1490 return SendParent(nmsg
, wparam
, lparam
);
1493 return super::WndProc(nmsg
, wparam
, lparam
);
1499 void StartMenuButton::DrawItem(LPDRAWITEMSTRUCT dis
)
1501 TCHAR title
[BUFFER_LEN
];
1503 GetWindowText(_hwnd
, title
, BUFFER_LEN
);
1505 DrawStartMenuButton(dis
->hDC
, dis
->rcItem
, title
, _hIcon
,
1507 !(dis
->itemState
& ODS_DISABLED
),
1508 dis
->itemState
&ODS_FOCUS
? true: false,
1509 dis
->itemState
&ODS_SELECTED
? true: false);
1515 StartMenuRoot::StartMenuRoot(HWND hwnd
)
1518 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1519 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCOMMONGROUPS
))
1522 // insert directory "All Users\Start Menu"
1523 ShellDirectory
cmn_startmenu(GetDesktopFolder(), SpecialFolderPath(CSIDL_COMMON_STARTMENU
, _hwnd
), _hwnd
);
1524 _dirs
.push_back(StartMenuDirectory(cmn_startmenu
, (LPCTSTR
)SpecialFolderFSPath(CSIDL_COMMON_PROGRAMS
, _hwnd
)));
1525 } catch(COMException
&) {
1526 // ignore exception and don't show additional shortcuts
1530 // insert directory "<user name>\Start Menu"
1532 ShellDirectory
usr_startmenu(GetDesktopFolder(), SpecialFolderPath(CSIDL_STARTMENU
, _hwnd
), _hwnd
);
1533 _dirs
.push_back(StartMenuDirectory(usr_startmenu
, (LPCTSTR
)SpecialFolderFSPath(CSIDL_PROGRAMS
, _hwnd
)));
1534 } catch(COMException
&) {
1535 // ignore exception and don't show additional shortcuts
1538 // read size of logo bitmap
1540 GetObject(ResBitmap(IDB_LOGOV
), sizeof(BITMAP
), &bmp_hdr
);
1541 _logo_size
.cx
= bmp_hdr
.bmWidth
;
1542 _logo_size
.cy
= bmp_hdr
.bmHeight
;
1544 _border_left
= _logo_size
.cx
+ 1;
1548 static void CalculateStartPos(HWND hwndOwner
, RECT
& rect
)
1550 WindowRect
pos(hwndOwner
);
1552 rect
.left
= pos
.left
;
1553 rect
.top
= pos
.top
-STARTMENU_LINE_HEIGHT
-4;
1554 rect
.right
= pos
.left
+STARTMENU_WIDTH_MIN
;
1555 rect
.bottom
= pos
.top
;
1557 #ifndef _LIGHT_STARTMENU
1558 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1561 AdjustWindowRectEx(&rect
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
, FALSE
, 0);
1564 HWND
StartMenuRoot::Create(HWND hwndOwner
)
1568 CalculateStartPos(hwndOwner
, rect
);
1570 return Window::Create(WINDOW_CREATOR(StartMenuRoot
), 0, GetWndClasss(), TITLE_STARTMENU
,
1571 WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
,
1572 rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndOwner
);
1576 void StartMenuRoot::TrackStartmenu()
1581 #ifdef _LIGHT_STARTMENU
1585 #ifdef _LIGHT_STARTMENU
1586 // recalculate start menu root position
1589 CalculateStartPos(GetParent(hwnd
), rect
);
1591 SetWindowPos(hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, 0);
1596 // show previously hidden start menu
1597 ShowWindow(hwnd
, SW_SHOW
);
1598 SetForegroundWindow(hwnd
);
1600 while(IsWindow(hwnd
)) {
1601 if (!GetMessage(&msg
, 0, 0, 0)) {
1602 PostQuitMessage(msg
.wParam
);
1606 // Check for a mouse click on any window, which is not part of the start menu
1607 if (msg
.message
==WM_LBUTTONDOWN
|| msg
.message
==WM_MBUTTONDOWN
|| msg
.message
==WM_RBUTTONDOWN
) {
1608 StartMenu
* menu_wnd
= NULL
;
1610 for(HWND hwnd
=msg
.hwnd
; hwnd
; hwnd
=GetParent(hwnd
)) {
1611 menu_wnd
= WINDOW_DYNAMIC_CAST(StartMenu
, hwnd
);
1624 if (pretranslate_msg(&msg
))
1627 if (dispatch_dialog_msg(&msg
))
1630 TranslateMessage(&msg
);
1633 DispatchMessage(&msg
);
1634 } catch(COMException
& e
) {
1635 HandleException(e
, _hwnd
);
1637 } catch(COMException
& e
) {
1638 HandleException(e
, _hwnd
);
1644 LRESULT
StartMenuRoot::Init(LPCREATESTRUCT pcs
)
1646 // add buttons for entries in _entries
1647 if (super::Init(pcs
))
1657 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"), &hkey
))
1660 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), &hkeyAdv
))
1663 #define IS_VALUE_ZERO(hk, name) \
1664 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || !value))
1666 #define IS_VALUE_NOT_ZERO(hk, name) \
1667 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || value>0))
1671 // insert hard coded start entries
1672 AddButton(ResString(IDS_PROGRAMS
), ICID_APPS
, true, IDC_PROGRAMS
);
1674 AddButton(ResString(IDS_DOCUMENTS
), ICID_DOCUMENTS
, true, IDC_DOCUMENTS
);
1676 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1677 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORECENTDOCSMENU
))
1679 if (IS_VALUE_ZERO(hkey
, _T("NoRecentDocsMenu")))
1681 AddButton(ResString(IDS_RECENT
), ICID_DOCUMENTS
, true, IDC_RECENT
);
1683 AddButton(ResString(IDS_FAVORITES
), ICID_FAVORITES
, true, IDC_FAVORITES
);
1685 AddButton(ResString(IDS_SETTINGS
), ICID_CONFIG
, true, IDC_SETTINGS
);
1687 AddButton(ResString(IDS_BROWSE
), ICID_FOLDER
, true, IDC_BROWSE
);
1689 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1690 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOFIND
))
1692 if (IS_VALUE_ZERO(hkey
, _T("NoFind")))
1694 AddButton(ResString(IDS_SEARCH
), ICID_SEARCH
, true, IDC_SEARCH
);
1696 AddButton(ResString(IDS_START_HELP
), ICID_INFO
, false, IDC_START_HELP
);
1698 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1699 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORUN
))
1701 if (IS_VALUE_ZERO(hkey
, _T("NoRun")))
1703 AddButton(ResString(IDS_LAUNCH
), ICID_ACTION
, false, IDC_LAUNCH
);
1709 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1710 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCLOSE
))
1712 if (IS_VALUE_NOT_ZERO(hkeyAdv
, _T("StartMenuLogoff")))
1714 AddButton(ResString(IDS_LOGOFF
), ICID_LOGOFF
, false, IDC_LOGOFF
);
1717 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1718 if (!g_Globals
._SHRestricted
|| SHRestricted(REST_STARTMENULOGOFF
) != 1)
1720 if (IS_VALUE_ZERO(hkey
, _T("NoClose")))
1722 AddButton(ResString(IDS_SHUTDOWN
), ICID_LOGOFF
, false, IDC_SHUTDOWN
);
1725 AddButton(ResString(IDS_TERMINATE
), ICID_LOGOFF
, false, IDC_TERMINATE
);
1729 RegCloseKey(hkeyAdv
);
1734 #ifdef _LIGHT_STARTMENU
1735 // set the window size to fit all buttons
1743 void StartMenuRoot::AddEntries()
1745 super::AddEntries();
1747 AddButton(ResString(IDS_EXPLORE
), ICID_EXPLORER
, false, IDC_EXPLORE
);
1751 LRESULT
StartMenuRoot::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1755 PaintCanvas
canvas(_hwnd
);
1760 return super::WndProc(nmsg
, wparam
, lparam
);
1766 void StartMenuRoot::Paint(PaintCanvas
& canvas
)
1769 {WindowCanvas
dc(_hwnd
); clr_bits
=GetDeviceCaps(dc
, BITSPIXEL
);}
1772 ResBitmap
bmp(clr_bits
<=8? clr_bits
<=4? IDB_LOGOV16
: IDB_LOGOV256
: IDB_LOGOV
);
1773 BitmapSelection
sel(mem_dc
, bmp
);
1775 ClientRect
clnt(_hwnd
);
1776 int h
= min(_logo_size
.cy
, clnt
.bottom
);
1778 RECT rect
= {0, 0, _logo_size
.cx
, clnt
.bottom
-h
};
1779 HBRUSH hbr
= CreateSolidBrush(GetPixel(mem_dc
, 0, 0));
1780 FillRect(canvas
, &rect
, hbr
);
1783 PatBlt(canvas
, _logo_size
.cx
, 0, 1, clnt
.bottom
, WHITENESS
);
1785 BitBlt(canvas
, 0, clnt
.bottom
-h
, _logo_size
.cx
, h
, mem_dc
, 0, 0, SRCCOPY
);
1787 super::Paint(canvas
);
1791 void StartMenuRoot::CloseStartMenu(int id
)
1796 ShowWindow(_hwnd
, SW_HIDE
);
1799 void StartMenuRoot::ProcessKey(int vk
)
1804 CloseOtherSubmenus();
1805 // don't close start menu root
1809 super::ProcessKey(vk
);
1814 int StartMenuHandler::Command(int id
, int code
)
1821 CreateSubmenu(id
, CSIDL_COMMON_PROGRAMS
, CSIDL_PROGRAMS
, ResString(IDS_PROGRAMS
));
1826 explorer_show_frame(SW_SHOWNORMAL
);
1831 ShowLaunchDialog(g_Globals
._hwndDesktopBar
);
1835 CreateSubmenu(id
, CSIDL_PERSONAL
, ResString(IDS_DOCUMENTS
));
1839 CreateSubmenu(id
, CSIDL_RECENT
, ResString(IDS_RECENT
), STARTMENU_CREATOR(RecentStartMenu
));
1843 #ifndef _SHELL32_FAVORITES
1844 CreateSubmenu(id
, ResString(IDS_FAVORITES
), STARTMENU_CREATOR(FavoritesMenu
), &static_cast<BookmarkList
&>(g_Globals
._favorites
));
1846 CreateSubmenu(id
, CSIDL_COMMON_FAVORITES
, CSIDL_FAVORITES
, ResString(IDS_FAVORITES
));
1851 CreateSubmenu(id
, ResString(IDS_BROWSE
), STARTMENU_CREATOR(BrowseMenu
));
1855 CreateSubmenu(id
, ResString(IDS_SETTINGS
), STARTMENU_CREATOR(SettingsMenu
));
1859 CreateSubmenu(id
, ResString(IDS_SEARCH
), STARTMENU_CREATOR(SearchMenu
));
1862 case IDC_START_HELP
:
1864 MessageBox(g_Globals
._hwndDesktopBar
, TEXT("Help not yet implemented"), ResString(IDS_TITLE
), MB_OK
);
1869 ShowLogoffDialog(g_Globals
._hwndDesktopBar
);
1873 DestroyWindow(GetParent(_hwnd
));
1878 ShowExitWindowsDialog(g_Globals
._hwndDesktopBar
);
1884 case ID_DESKTOPBAR_SETTINGS
:
1886 ExplorerPropertySheet(g_Globals
._hwndDesktopBar
);
1889 case IDC_CONTROL_PANEL
: {
1893 XMLPos explorer_options
= g_Globals
.get_cfg("general/explorer");
1894 bool mdi
= XMLBool(explorer_options
, "mdi", true);
1897 MDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
1900 SDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
1902 launch_file(_hwnd
, SHELLPATH_CONTROL_PANEL
);
1906 case IDC_SETTINGS_MENU
:
1907 CreateSubmenu(id
, CSIDL_CONTROLS
, ResString(IDS_SETTINGS_MENU
));
1910 case IDC_PRINTERS
: {
1914 #ifdef _ROS_ // to be removed when printer folder will be implemented
1915 MessageBox(0, TEXT("printer folder not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1918 XMLPos explorer_options
= g_Globals
.get_cfg("general/explorer");
1919 bool mdi
= XMLBool(explorer_options
, "mdi", true);
1922 MDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}"), 0);
1925 SDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}"), 0);
1928 launch_file(_hwnd
, SHELLPATH_PRINTERS
);
1932 case IDC_PRINTERS_MENU
:
1933 CreateSubmenu(id
, CSIDL_PRINTERS
, CSIDL_PRINTHOOD
, ResString(IDS_PRINTERS
));
1934 /* StartMenuFolders new_folders;
1937 new_folders.push_back(ShellPath(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}")));
1938 } catch(COMException&) {
1941 CreateSubmenu(id, new_folders, ResString(IDS_PRINTERS));*/
1946 CreateSubmenu(id
, CSIDL_COMMON_ADMINTOOLS
, CSIDL_ADMINTOOLS
, ResString(IDS_ADMIN
));
1947 //CloseStartMenu(id);
1948 //MainFrame::Create(SpecialFolderPath(CSIDL_COMMON_ADMINTOOLS, _hwnd), OWM_PIDL);
1950 launch_file(_hwnd
, SpecialFolderFSPath(CSIDL_COMMON_ADMINTOOLS
, _hwnd
));
1954 case IDC_CONNECTIONS
:
1956 #ifdef _ROS_ // to be removed when RAS will be implemented
1957 MessageBox(0, TEXT("RAS folder not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1959 CreateSubmenu(id
, CSIDL_CONNECTIONS
, ResString(IDS_CONNECTIONS
));
1960 //CloseStartMenu(id);
1961 //MainFrame::Create(SpecialFolderPath(CSIDL_CONNECTIONS, _hwnd), OWM_PIDL);
1964 launch_file(_hwnd
, SHELLPATH_NET_CONNECTIONS
);
1972 #ifdef _ROS_ // to be removed when network will be implemented
1973 MessageBox(0, TEXT("network not yet implemented"), ResString(IDS_TITLE
), MB_OK
);
1975 CreateSubmenu(id
, CSIDL_NETWORK
, ResString(IDS_NETWORK
));
1980 ///@todo exclude removable drives
1981 CreateSubmenu(id
, CSIDL_DRIVES
, ResString(IDS_DRIVES
));
1987 case IDC_SEARCH_PROGRAM
:
1989 Dialog::DoModal(IDD_SEARCH_PROGRAM
, WINDOW_CREATOR(FindProgramDlg
));
1992 case IDC_SEARCH_FILES
:
1997 case IDC_SEARCH_COMPUTER
:
1999 ShowSearchComputer();
2004 return super::Command(id
, code
);
2011 void StartMenuHandler::ShowSearchDialog()
2013 static DynamicFct
<SHFINDFILES
> SHFindFiles(TEXT("SHELL32"), 90);
2016 (*SHFindFiles
)(NULL
, NULL
);
2018 MessageBox(0, TEXT("SHFindFiles() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2021 void StartMenuHandler::ShowSearchComputer()
2023 static DynamicFct
<SHFINDCOMPUTER
> SHFindComputer(TEXT("SHELL32"), 91);
2026 (*SHFindComputer
)(NULL
, NULL
);
2028 MessageBox(0, TEXT("SHFindComputer() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2031 void StartMenuHandler::ShowLaunchDialog(HWND hwndOwner
)
2033 ///@todo All text phrases should be put into the resources.
2034 static LPCSTR szTitle
= "Run";
2035 static LPCSTR szText
= "Type the name of a program, folder, document, or Internet resource, and Explorer will open it for you.";
2037 static DynamicFct
<RUNFILEDLG
> RunFileDlg(TEXT("SHELL32"), 61);
2039 // Show "Run..." dialog
2041 #ifndef _ROS_ /* FIXME: our shell32 always expects Ansi strings */
2042 if ((HIWORD(GetVersion())>>14) == W_VER_NT
) {
2043 WCHAR wTitle
[40], wText
[256];
2045 MultiByteToWideChar(CP_ACP
, 0, szTitle
, -1, wTitle
, 40);
2046 MultiByteToWideChar(CP_ACP
, 0, szText
, -1, wText
, 256);
2048 (*RunFileDlg
)(hwndOwner
, 0, NULL
, (LPCSTR
)wTitle
, (LPCSTR
)wText
, RFF_CALCDIRECTORY
);
2052 (*RunFileDlg
)(hwndOwner
, 0, NULL
, szTitle
, szText
, RFF_CALCDIRECTORY
);
2056 void StartMenuHandler::ShowLogoffDialog(HWND hwndOwner
)
2058 static DynamicFct
<LOGOFFWINDOWSDIALOG
> LogoffWindowsDialog(TEXT("SHELL32"), 54);
2059 // static DynamicFct<RESTARTWINDOWSDLG> RestartDialog(TEXT("SHELL32"), 59);
2061 if (LogoffWindowsDialog
)
2062 (*LogoffWindowsDialog
)(0);
2063 /* The RestartDialog function prompts about some system setting change. This is not what we want to display here.
2064 else if (RestartDialog)
2065 return (*RestartDialog)(hwndOwner, (LPWSTR)L"You selected <Log Off>.\n\n", EWX_LOGOFF) == 1; ///@todo ANSI string conversion if needed
2068 MessageBox(hwndOwner
, TEXT("LogoffWindowsDialog() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2071 void ShowExitWindowsDialog(HWND hwndOwner
)
2073 static DynamicFct
<EXITWINDOWSDLG
> ExitWindowsDialog(TEXT("SHELL32"), 60);
2075 if (ExitWindowsDialog
)
2076 (*ExitWindowsDialog
)(hwndOwner
);
2078 MessageBox(hwndOwner
, TEXT("ExitWindowsDialog() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2082 void SettingsMenu::AddEntries()
2084 super::AddEntries();
2086 #if defined(ROSSHELL) || defined(_ROS_) // _ROS_ to be removed when printer/network will be implemented
2087 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, false, IDC_PRINTERS_MENU
);
2088 AddButton(ResString(IDS_CONNECTIONS
), ICID_NETWORK
, false, IDC_CONNECTIONS
);
2090 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, true, IDC_PRINTERS_MENU
);
2091 AddButton(ResString(IDS_CONNECTIONS
), ICID_NETWORK
, true, IDC_CONNECTIONS
);
2093 AddButton(ResString(IDS_ADMIN
), ICID_CONFIG
, true, IDC_ADMIN
);
2095 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2096 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
2098 AddButton(ResString(IDS_SETTINGS_MENU
), ICID_CONFIG
, true, IDC_SETTINGS_MENU
);
2100 AddButton(ResString(IDS_DESKTOPBAR_SETTINGS
), ICID_CONFIG
, false, ID_DESKTOPBAR_SETTINGS
);
2102 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, false, IDC_PRINTERS
);
2104 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2105 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
2107 AddButton(ResString(IDS_CONTROL_PANEL
), ICID_CONFIG
, false, IDC_CONTROL_PANEL
);
2110 void BrowseMenu::AddEntries()
2112 super::AddEntries();
2114 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2115 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NONETHOOD
)) // or REST_NOENTIRENETWORK ?
2117 #if defined(ROSSHELL) || defined(_ROS_) // _ROS_ to be removed when printer/network will be implemented
2118 AddButton(ResString(IDS_NETWORK
), ICID_NETWORK
, false, IDC_NETWORK
);
2120 AddButton(ResString(IDS_NETWORK
), ICID_NETWORK
, true, IDC_NETWORK
);
2123 AddButton(ResString(IDS_DRIVES
), ICID_FOLDER
, true, IDC_DRIVES
);
2126 void SearchMenu::AddEntries()
2128 super::AddEntries();
2130 AddButton(ResString(IDS_SEARCH_FILES
), ICID_SEARCH_DOC
, false, IDC_SEARCH_FILES
);
2132 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2133 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_HASFINDCOMPUTERS
))
2135 AddButton(ResString(IDS_SEARCH_COMPUTER
),ICID_COMPUTER
, false, IDC_SEARCH_COMPUTER
);
2137 AddButton(ResString(IDS_SEARCH_PRG
), ICID_APPS
, false, IDC_SEARCH_PROGRAM
);
2141 void RecentStartMenu::AddEntries()
2143 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
2144 StartMenuDirectory
& smd
= *it
;
2145 ShellDirectory
& dir
= smd
._dir
;
2147 if (!dir
._scanned
) {
2150 #ifdef _LAZY_ICONEXTRACT
2151 dir
.smart_scan(SORT_NAME
, SCAN_FILESYSTEM
);
2153 dir
.smart_scan(SORT_NAME
, SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
2157 dir
.sort_directory(SORT_DATE
);
2158 AddShellEntries(dir
, RECENT_DOCS_COUNT
, smd
._ignore
); ///@todo read max. count of entries from registry
2163 #ifndef _SHELL32_FAVORITES
2165 void FavoritesMenu::AddEntries()
2167 super::AddEntries();
2169 for(BookmarkList::iterator it
=_bookmarks
.begin(); it
!=_bookmarks
.end(); ++it
) {
2170 BookmarkNode
& node
= *it
;
2172 int id
= ++_next_id
;
2174 _entries
[id
] = node
;
2176 if (node
._type
== BookmarkNode::BMNT_FOLDER
) {
2177 BookmarkFolder
& folder
= *node
._pfolder
;
2179 AddButton(folder
._name
, ICID_FOLDER
, true, id
);
2180 } else if (node
._type
== BookmarkNode::BMNT_BOOKMARK
) {
2181 Bookmark
& bookmark
= *node
._pbookmark
;
2183 ICON_ID icon
= ICID_NONE
;
2185 if (!bookmark
._icon_path
.empty())
2186 icon
= g_Globals
._icon_cache
.extract(bookmark
._icon_path
, bookmark
._icon_idx
);
2188 AddButton(bookmark
._name
, icon
!=ICID_NONE
?icon
:ICID_BOOKMARK
, false, id
);
2193 int FavoritesMenu::Command(int id
, int code
)
2195 BookmarkMap::iterator found
= _entries
.find(id
);
2197 if (found
!= _entries
.end()) {
2198 BookmarkNode
& node
= found
->second
;
2200 if (node
._type
== BookmarkNode::BMNT_FOLDER
) {
2201 BookmarkFolder
& folder
= *node
._pfolder
;
2203 if (CloseOtherSubmenus(id
))
2204 CreateSubmenu(id
, folder
._name
, STARTMENU_CREATOR(FavoritesMenu
), &static_cast<BookmarkList
&>(folder
._bookmarks
));
2205 } else if (node
._type
== BookmarkNode::BMNT_BOOKMARK
) {
2206 Bookmark
& bookmark
= *node
._pbookmark
;
2208 String url
= bookmark
._url
;
2209 HWND hparent
= GetParent(_hwnd
);
2213 launch_file(hparent
, url
, SW_SHOWNORMAL
);
2219 return super::Command(id
, code
);