2 * Copyright 2003 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.
33 #include "../utility/utility.h"
35 #include "../explorer.h"
36 #include "../globals.h"
37 #include "../externals.h"
38 #include "../explorer_intres.h"
40 #include "desktopbar.h"
41 #include "startmenu.h"
43 #include "../dialogs/settings.h"
46 StartMenu::StartMenu(HWND hwnd
)
49 _next_id
= IDC_FIRST_MENU
;
53 _last_pos
= WindowRect(hwnd
).pos();
54 #ifdef _LIGHT_STARTMENU
60 StartMenu::StartMenu(HWND hwnd
, const StartMenuCreateInfo
& create_info
)
62 _create_info(create_info
)
64 for(StartMenuFolders::const_iterator it
=create_info
._folders
.begin(); it
!=create_info
._folders
.end(); ++it
)
66 _dirs
.push_back(ShellDirectory(GetDesktopFolder(), *it
, _hwnd
));
68 _next_id
= IDC_FIRST_MENU
;
71 _border_top
= create_info
._border_top
;
72 _last_pos
= WindowRect(hwnd
).pos();
73 #ifdef _LIGHT_STARTMENU
79 StartMenu::~StartMenu()
81 SendParent(PM_STARTMENU_CLOSED
);
85 // We need this wrapper function for s_wcStartMenu, it calls the WIN32 API,
86 // though static C++ initializers are not allowed for Winelib applications.
87 BtnWindowClass
& StartMenu::GetWndClasss()
89 static BtnWindowClass
s_wcStartMenu(CLASSNAME_STARTMENU
);
95 Window::CREATORFUNC_INFO
StartMenu::s_def_creator
= STARTMENU_CREATOR(StartMenu
);
97 HWND
StartMenu::Create(int x
, int y
, const StartMenuFolders
& folders
, HWND hwndParent
, LPCTSTR title
, CREATORFUNC_INFO creator
)
103 style
= WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
;
105 top_height
= STARTMENU_TOP_BTN_SPACE
;
107 style
= WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|WS_CLIPCHILDREN
|WS_VISIBLE
;
108 ex_style
= WS_EX_TOOLWINDOW
;
112 RECT rect
= {x
, y
-STARTMENU_LINE_HEIGHT
-top_height
, x
+STARTMENU_WIDTH_MIN
, y
};
114 #ifndef _LIGHT_STARTMENU
115 rect
.top
+= STARTMENU_LINE_HEIGHT
;
118 AdjustWindowRectEx(&rect
, style
, FALSE
, ex_style
);
120 StartMenuCreateInfo create_info
;
122 create_info
._folders
= folders
;
123 create_info
._border_top
= top_height
;
124 create_info
._creator
= creator
;
127 create_info
._title
= title
;
129 HWND hwnd
= Window::Create(creator
, &create_info
, ex_style
, GetWndClasss(), title
,
130 style
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndParent
);
132 // make sure the window is not off the screen
139 LRESULT
StartMenu::Init(LPCREATESTRUCT pcs
)
144 if (super::Init(pcs
))
147 // create buttons for registered entries in _entries
148 for(ShellEntryMap::const_iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
149 const StartMenuEntry
& sme
= it
->second
;
150 bool hasSubmenu
= false;
152 for(ShellEntrySet::const_iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
)
153 if ((*it
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
156 #ifdef _LIGHT_STARTMENU
157 _buttons
.push_back(SMBtnInfo(sme
, it
->first
, hasSubmenu
));
159 AddButton(sme
._title
, sme
._hIcon
, hasSubmenu
, it
->first
);
163 #ifdef _LIGHT_STARTMENU
164 if (_buttons
.empty())
166 if (!GetWindow(_hwnd
, GW_CHILD
))
168 AddButton(ResString(IDS_EMPTY
), ICID_NONE
, false, 0, false);
170 #ifdef _LIGHT_STARTMENU
174 #ifdef _LAZY_ICONEXTRACT
175 PostMessage(_hwnd
, PM_UPDATE_ICONS
, 0, 0);
177 } catch(COMException
& e
) {
178 HandleException(e
, pcs
->hwndParent
); // destroys the start menu window while switching focus
184 void StartMenu::AddEntries()
186 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
187 StartMenuDirectory
& smd
= *it
;
188 ShellDirectory
& dir
= smd
._dir
;
193 #ifdef _LAZY_ICONEXTRACT
194 dir
.smart_scan(SCAN_FILESYSTEM
); // lazy icon extraction, try to read directly from filesystem
196 dir
.smart_scan(SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
200 AddShellEntries(dir
, -1, smd
._subfolders
);
205 void StartMenu::AddShellEntries(const ShellDirectory
& dir
, int max
, bool subfolders
)
209 for(Entry
*entry
=dir
._down
; entry
; entry
=entry
->_next
) {
210 // hide files like "desktop.ini"
211 if (entry
->_shell_attribs
& SFGAO_HIDDEN
)
212 //not appropriate for drive roots: if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
215 // hide subfolders if requested
217 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
220 // only 'max' entries shall be added.
224 if (entry
->_etype
== ET_SHELL
)
225 AddEntry(dir
._folder
, static_cast<ShellEntry
*>(entry
));
227 AddEntry(dir
._folder
, entry
);
232 LRESULT
StartMenu::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
236 PaintCanvas
canvas(_hwnd
);
241 ResizeButtons(LOWORD(lparam
)-_border_left
);
245 POINTS
& pos
= MAKEPOINTS(lparam
);
247 // move open submenus of floating menus
249 int dx
= pos
.x
- _last_pos
.x
;
250 int dy
= pos
.y
- _last_pos
.y
;
253 WindowRect
rt(_submenu
);
254 SetWindowPos(_submenu
, 0, rt
.left
+dx
, rt
.top
+dy
, 0, 0, SWP_NOSIZE
|SWP_NOACTIVATE
);
255 //MoveVisible(_submenu);
264 LRESULT res
= super::WndProc(nmsg
, wparam
, lparam
);
266 if (res
>=HTSIZEFIRST
&& res
<=HTSIZELAST
)
267 return HTCLIENT
; // disable window resizing
271 case WM_LBUTTONDOWN
: {
274 // check mouse cursor for coordinates of floating button
275 GetFloatingButtonRect(&rect
);
277 if (PtInRect(&rect
, Point(lparam
))) {
278 // create a floating copy of the current start menu
279 WindowRect
pos(_hwnd
);
281 ///@todo do something similar to StartMenuRoot::TrackStartmenu() in order to automatically close submenus when clicking on the desktop background
282 StartMenu::Create(pos
.left
+3, pos
.bottom
-3, _create_info
._folders
, 0, _create_info
._title
, _create_info
._creator
);
286 #ifdef _LIGHT_STARTMENU
287 int id
= ButtonHitTest(Point(lparam
));
290 Command(id
, BN_CLICKED
);
295 if ((wparam
&0xFFF0) == SC_SIZE
)
296 return 0; // disable window resizing
300 // close start menu when activating another application
303 break; // don't call super::WndProc in case "this" has been deleted
309 #ifdef _LIGHT_STARTMENU
311 // automatically set the focus to startmenu entries when moving the mouse over them
312 if (lparam
!= _last_mouse_pos
) { // don't process WM_MOUSEMOVE when opening submenus using keyboard navigation
313 int new_id
= ButtonHitTest(Point(lparam
));
315 if (new_id
!= _selected_id
)
316 SelectButton(new_id
);
318 _last_mouse_pos
= lparam
;
326 case PM_STARTENTRY_FOCUSED
: { ///@todo use TrackMouseEvent() and WM_MOUSEHOVER to wait a bit before opening submenus
327 BOOL hasSubmenu
= wparam
;
328 HWND hctrl
= (HWND
)lparam
;
330 // automatically open submenus
332 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
333 //SendMessage(_hwnd, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hctrl),BN_CLICKED), (LPARAM)hctrl);
334 Command(GetDlgCtrlID(hctrl
), BN_CLICKED
);
336 // close any open submenu
337 CloseOtherSubmenus();
342 #ifdef _LAZY_ICONEXTRACT
343 case PM_UPDATE_ICONS
:
344 UpdateIcons(/*wparam*/);
348 case PM_STARTENTRY_LAUNCHED
:
349 if (GetWindowStyle(_hwnd
) & WS_CAPTION
) // don't automatically close floating menus
352 // route message to the parent menu and close menus after launching an entry
353 if (!SendParent(nmsg
, wparam
, lparam
))
355 return 1; // signal that we have received and processed the message
357 case PM_STARTMENU_CLOSED
:
361 case PM_SELECT_ENTRY
:
362 SelectButtonIndex(0, wparam
?true:false);
366 return super::WndProc(nmsg
, wparam
, lparam
);
373 #ifdef _LIGHT_STARTMENU
375 int StartMenu::ButtonHitTest(POINT pt
)
377 ClientRect
clnt(_hwnd
);
378 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
380 if (pt
.x
<rect
.left
|| pt
.x
>rect
.right
)
383 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
384 const SMBtnInfo
& info
= *it
;
389 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
391 if (pt
.y
< rect
.bottom
) // PtInRect(&rect, pt)
394 rect
.top
= rect
.bottom
;
400 void StartMenu::InvalidateSelection()
405 ClientRect
clnt(_hwnd
);
406 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
408 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
409 const SMBtnInfo
& info
= *it
;
411 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
413 if (info
._id
== _selected_id
) {
414 InvalidateRect(_hwnd
, &rect
, TRUE
);
418 rect
.top
= rect
.bottom
;
422 const SMBtnInfo
* StartMenu::GetButtonInfo(int id
) const
424 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
)
431 bool StartMenu::SelectButton(int id
, bool open_sub
)
436 if (id
== _selected_id
)
439 InvalidateSelection();
441 const SMBtnInfo
* btn
= GetButtonInfo(id
);
443 if (btn
&& btn
->_enabled
) {
446 InvalidateSelection();
448 // automatically open submenus
449 if (btn
->_hasSubmenu
) {
453 CloseOtherSubmenus(); // close any open submenu
462 bool StartMenu::OpenSubmenu(bool select_first
)
464 if (_selected_id
== -1)
467 InvalidateSelection();
469 const SMBtnInfo
* btn
= GetButtonInfo(_selected_id
);
471 // automatically open submenus
472 if (btn
->_hasSubmenu
) {
473 //@@ allows destroying of startmenu when processing PM_UPDATE_ICONS -> GPF
474 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
475 Command(_selected_id
, BN_CLICKED
);
477 if (select_first
&& _submenu
)
478 SendMessage(_submenu
, PM_SELECT_ENTRY
, (WPARAM
)false, 0);
486 int StartMenu::GetSelectionIndex()
488 if (_selected_id
== -1)
491 for(int i
=0; i
<(int)_buttons
.size(); ++i
)
492 if (_buttons
[i
]._id
== _selected_id
)
498 bool StartMenu::SelectButtonIndex(int idx
, bool open_sub
)
500 if (idx
>=0 && idx
<(int)_buttons
.size())
501 return SelectButton(_buttons
[idx
]._id
, open_sub
);
506 void StartMenu::ProcessKey(int vk
)
511 Command(_selected_id
, BN_CLICKED
);
523 SelectButtonIndex(0, false);
527 SelectButtonIndex(_buttons
.size()-1, false);
532 CloseOtherSubmenus();
533 else if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) // don't automatically close floating menus
534 DestroyWindow(_hwnd
);
546 if (vk
>='0' && vk
<='Z')
547 JumpToNextShortcut(vk
);
551 bool StartMenu::Navigate(int step
)
553 int idx
= GetSelectionIndex();
559 idx
= _buttons
.size() - step
;
564 if (idx
<0 || idx
>(int)_buttons
.size())
567 if (SelectButtonIndex(idx
, false))
574 bool StartMenu::JumpToNextShortcut(char c
)
576 int cur_idx
= GetSelectionIndex();
584 SMBtnVector::const_iterator cur_it
= _buttons
.begin();
585 cur_it
+= cur_idx
+ 1;
587 // first search down from current item...
588 SMBtnVector::const_iterator it
= cur_it
;
589 for(; it
!=_buttons
.end(); ++it
) {
590 const SMBtnInfo
& btn
= *it
;
592 if (!btn
._title
.empty() && toupper((TBYTE
)btn
._title
.at(0)) == c
) {
594 first_found
= btn
._id
;
600 // ...now search from top to the current item
601 it
= _buttons
.begin();
602 for(; it
!=_buttons
.end() && it
!=cur_it
; ++it
) {
603 const SMBtnInfo
& btn
= *it
;
605 if (!btn
._title
.empty() && toupper((TBYTE
)btn
._title
.at(0)) == c
) {
607 first_found
= btn
._id
;
614 SelectButton(first_found
);
617 Command(first_found
, BN_CLICKED
);
624 #endif // _LIGHT_STARTMENU
627 bool StartMenu::GetButtonRect(int id
, PRECT prect
) const
629 #ifdef _LIGHT_STARTMENU
630 ClientRect
clnt(_hwnd
);
631 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
633 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
634 const SMBtnInfo
& info
= *it
;
636 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
638 if (info
._id
== id
) {
643 rect
.top
= rect
.bottom
;
648 HWND btn
= GetDlgItem(_hwnd
, id
);
651 GetWindowRect(btn
, prect
);
652 ScreenToClient(_hwnd
, prect
);
661 void StartMenu::DrawFloatingButton(HDC hdc
)
663 static ResIconEx
floatingIcon(IDI_FLOATING
, 8, 4);
665 ClientRect
clnt(_hwnd
);
667 DrawIconEx(hdc
, clnt
.right
-12, 0, floatingIcon
, 8, 4, 0, 0, DI_NORMAL
);
670 void StartMenu::GetFloatingButtonRect(LPRECT prect
)
672 GetClientRect(_hwnd
, prect
);
675 prect
->left
= prect
->right
- 8;
680 void StartMenu::Paint(PaintCanvas
& canvas
)
683 DrawFloatingButton(canvas
);
685 #ifdef _LIGHT_STARTMENU
686 ClientRect
clnt(_hwnd
);
687 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
689 int sep_width
= rect
.right
-rect
.left
- 4;
691 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
692 BkMode
bk_mode(canvas
, TRANSPARENT
);
694 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
695 const SMBtnInfo
& btn
= *it
;
697 if (rect
.top
> canvas
.rcPaint
.bottom
)
700 if (btn
._id
== -1) { // a separator?
701 rect
.bottom
= rect
.top
+ STARTMENU_SEP_HEIGHT
;
703 BrushSelection
brush_sel(canvas
, GetSysColorBrush(COLOR_BTNSHADOW
));
704 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2-1, sep_width
, 1, PATCOPY
);
706 SelectBrush(canvas
, GetSysColorBrush(COLOR_BTNHIGHLIGHT
));
707 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2, sep_width
, 1, PATCOPY
);
709 rect
.bottom
= rect
.top
+ STARTMENU_LINE_HEIGHT
;
711 if (rect
.top
>= canvas
.rcPaint
.top
)
712 DrawStartMenuButton(canvas
, rect
, btn
._title
, btn
, btn
._id
==_selected_id
, false);
715 rect
.top
= rect
.bottom
;
720 #ifdef _LAZY_ICONEXTRACT
721 void StartMenu::UpdateIcons(/*int idx*/)
725 #ifdef _SINGLE_ICONEXTRACT
730 for(; idx
<(int)_buttons
.size(); ++idx
) {
731 SMBtnInfo
& btn
= _buttons
[idx
];
733 if (btn
._icon_id
==ICID_UNKNOWN
&& btn
._id
>0) {
734 StartMenuEntry
& sme
= _entries
[btn
._id
];
736 btn
._icon_id
= ICID_NONE
;
738 for(ShellEntrySet::iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
) {
741 if (entry
->_icon_id
== ICID_UNKNOWN
)
742 entry
->extract_icon();
744 if (entry
->_icon_id
> ICID_NONE
) {
745 btn
._icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
749 GetButtonRect(btn
._id
, &rect
);
750 WindowCanvas
canvas(_hwnd
);
751 DrawStartMenuButton(canvas
, rect
, NULL
, btn
, btn
._id
==_selected_id
, false);
753 //InvalidateRect(_hwnd, &rect, FALSE);
754 //UpdateWindow(_hwnd);
763 // if (++idx < (int)_buttons.size())
764 // PostMessage(_hwnd, PM_UPDATE_ICONS, idx, 0);
768 int icons_extracted
= 0;
769 int icons_updated
= 0;
771 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
772 ShellDirectory
& dir
= it
->_dir
;
774 icons_extracted
+= dir
.extract_icons();
777 if (icons_extracted
) {
778 for(ShellEntryMap::iterator it1
=_entries
.begin(); it1
!=_entries
.end(); ++it1
) {
779 StartMenuEntry
& sme
= it1
->second
;
782 sme
._hIcon
= (HICON
)-1;
784 for(ShellEntrySet::const_iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
785 const Entry
* sm_entry
= *it2
;
787 if (sm_entry
->_hIcon
) {
788 sme
._hIcon
= sm_entry
->_hIcon
;
795 for(SMBtnVector::iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
796 SMBtnInfo
& info
= *it
;
798 if (info
._id
>0 && !info
._hIcon
) {
799 info
._hIcon
= _entries
[info
._id
]._hIcon
;
806 InvalidateRect(_hwnd
, NULL
, FALSE
);
814 // resize child button controls to accomodate for new window size
815 void StartMenu::ResizeButtons(int cx
)
817 HDWP hdwp
= BeginDeferWindowPos(10);
819 for(HWND ctrl
=GetWindow(_hwnd
,GW_CHILD
); ctrl
; ctrl
=GetNextWindow(ctrl
,GW_HWNDNEXT
)) {
822 if (rt
.right
!= cx
) {
823 int height
= rt
.bottom
- rt
.top
;
825 // special handling for separator controls
826 if (!height
&& (GetWindowStyle(ctrl
)&SS_TYPEMASK
)==SS_ETCHEDHORZ
)
829 hdwp
= DeferWindowPos(hdwp
, ctrl
, 0, 0, 0, cx
, height
, SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
);
833 EndDeferWindowPos(hdwp
);
837 int StartMenu::Command(int id
, int code
)
839 #ifndef _LIGHT_STARTMENU
847 ShellEntryMap::iterator found
= _entries
.find(id
);
849 if (found
!= _entries
.end()) {
850 ActivateEntry(id
, found
->second
._entries
);
854 return super::Command(id
, code
);
855 #ifndef _LIGHT_STARTMENU
864 StartMenuEntry
& StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, Entry
* entry
)
866 // search for an already existing subdirectory entry with the same name
867 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
868 for(ShellEntryMap::iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
869 StartMenuEntry
& sme
= it
->second
;
871 if (sme
._title
== title
) ///@todo speed up by using a map indexed by name
872 for(ShellEntrySet::iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
873 if ((*it2
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
874 // merge the new shell entry with the existing of the same name
875 sme
._entries
.insert(entry
);
881 StartMenuEntry
& sme
= AddEntry(title
, icon_id
);
883 sme
._entries
.insert(entry
);
888 StartMenuEntry
& StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, int id
)
893 StartMenuEntry
& sme
= _entries
[id
];
896 sme
._icon_id
= icon_id
;
901 StartMenuEntry
& StartMenu::AddEntry(const ShellFolder folder
, ShellEntry
* entry
)
905 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
906 icon_id
= ICID_FOLDER
;
908 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
910 return AddEntry(folder
.get_name(entry
->_pidl
), icon_id
, entry
);
913 StartMenuEntry
& StartMenu::AddEntry(const ShellFolder folder
, Entry
* entry
)
917 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
918 icon_id
= ICID_FOLDER
;
920 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
922 return AddEntry(entry
->_display_name
, icon_id
, entry
);
926 void StartMenu::AddButton(LPCTSTR title
, ICON_ID icon_id
, bool hasSubmenu
, int id
, bool enabled
)
928 #ifdef _LIGHT_STARTMENU
929 _buttons
.push_back(SMBtnInfo(title
, icon_id
, id
, hasSubmenu
, enabled
));
931 DWORD style
= enabled
? WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
: WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
|WS_DISABLED
;
933 WindowRect
rect(_hwnd
);
934 ClientRect
clnt(_hwnd
);
936 // increase window height to make room for the new button
937 rect
.top
-= STARTMENU_LINE_HEIGHT
;
939 // move down if we are too high now
941 rect
.top
+= STARTMENU_LINE_HEIGHT
;
942 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
945 WindowCanvas
canvas(_hwnd
);
946 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
948 // widen window, if it is too small
949 int text_width
= GetStartMenuBtnTextWidth(canvas
, title
, _hwnd
) + 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
951 int cx
= clnt
.right
- _border_left
;
953 rect
.right
+= text_width
-cx
;
955 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
957 StartMenuCtrl(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
,
958 title
, id
, g_Globals
._icon_cache
.get_icon(icon_id
)._hIcon
, hasSubmenu
, style
);
962 void StartMenu::AddSeparator()
964 #ifdef _LIGHT_STARTMENU
965 _buttons
.push_back(SMBtnInfo(NULL
, ICID_NONE
, -1, false));
967 WindowRect
rect(_hwnd
);
968 ClientRect
clnt(_hwnd
);
970 // increase window height to make room for the new separator
971 rect
.top
-= STARTMENU_SEP_HEIGHT
;
973 // move down if we are too high now
975 rect
.top
+= STARTMENU_LINE_HEIGHT
;
976 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
979 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
981 StartMenuSeparator(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
);
986 bool StartMenu::CloseOtherSubmenus(int id
)
989 if (IsWindow(_submenu
)) {
990 if (_submenu_id
== id
)
994 DestroyWindow(_submenu
);
995 // _submenu should be reset automatically by PM_STARTMENU_CLOSED, but safety first...
1006 void StartMenu::CreateSubmenu(int id
, LPCTSTR title
, CREATORFUNC_INFO creator
)
1008 CreateSubmenu(id
, StartMenuFolders(), title
, creator
);
1011 void StartMenu::CreateSubmenu(int id
, int folder_id
, LPCTSTR title
, CREATORFUNC_INFO creator
)
1014 SpecialFolderPath
folder(folder_id
, _hwnd
);
1016 StartMenuFolders new_folders
;
1017 new_folders
.push_back(folder
);
1019 CreateSubmenu(id
, new_folders
, title
, creator
);
1020 } catch(COMException
&) {
1021 // ignore Exception and don't display anything
1025 void StartMenu::CreateSubmenu(int id
, int folder_id1
, int folder_id2
, LPCTSTR title
, CREATORFUNC_INFO creator
)
1027 StartMenuFolders new_folders
;
1030 new_folders
.push_back(SpecialFolderPath(folder_id1
, _hwnd
));
1031 } catch(COMException
&) {
1035 new_folders
.push_back(SpecialFolderPath(folder_id2
, _hwnd
));
1036 } catch(COMException
&) {
1039 if (!new_folders
.empty())
1040 CreateSubmenu(id
, new_folders
, title
, creator
);
1043 void StartMenu::CreateSubmenu(int id
, const StartMenuFolders
& new_folders
, LPCTSTR title
, CREATORFUNC_INFO creator
)
1045 // Only open one submenu at a time.
1046 if (!CloseOtherSubmenus(id
))
1052 if (GetButtonRect(id
, &rect
)) {
1053 ClientToScreen(_hwnd
, &rect
);
1055 x
= rect
.right
; // Submenus should overlap their parent a bit.
1056 y
= rect
.top
+STARTMENU_LINE_HEIGHT
-_border_top
;
1058 WindowRect
pos(_hwnd
);
1065 _submenu
= StartMenu::Create(x
, y
, new_folders
, _hwnd
, title
, creator
);
1069 void StartMenu::ActivateEntry(int id
, const ShellEntrySet
& entries
)
1071 StartMenuFolders new_folders
;
1074 for(ShellEntrySet::const_iterator it
=entries
.begin(); it
!=entries
.end(); ++it
) {
1075 Entry
* entry
= const_cast<Entry
*>(*it
);
1077 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1079 ///@todo If the user explicitly clicked on a submenu, display this folder as floating start menu.
1081 if (entry
->_etype
== ET_SHELL
)
1082 new_folders
.push_back(entry
->create_absolute_pidl());
1084 TCHAR path
[MAX_PATH
];
1086 if (entry
->get_path(path
))
1087 new_folders
.push_back(path
);
1091 title
= entry
->_display_name
;
1093 // If the entry is no subdirectory, there can only be one shell entry.
1094 assert(entries
.size()==1);
1096 HWND hparent
= GetParent(_hwnd
);
1097 ShellPath shell_path
= entry
->create_absolute_pidl();
1099 // close start menus after launching the selected entry
1102 ///@todo launch in the background; specify correct HWND for error message box titles
1103 SHELLEXECUTEINFO shexinfo
;
1105 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
1106 shexinfo
.fMask
= SEE_MASK_INVOKEIDLIST
; // SEE_MASK_IDLIST is also possible.
1107 shexinfo
.hwnd
= hparent
;
1108 shexinfo
.lpVerb
= NULL
;
1109 shexinfo
.lpFile
= NULL
;
1110 shexinfo
.lpParameters
= NULL
;
1111 shexinfo
.lpDirectory
= NULL
;
1112 shexinfo
.nShow
= SW_SHOWNORMAL
;
1114 shexinfo
.lpIDList
= &*shell_path
;
1116 if (!ShellExecuteEx(&shexinfo
))
1117 display_error(hparent
, GetLastError());
1119 // we may have deleted 'this' - ensure we leave the loop and function
1124 if (!new_folders
.empty()) {
1125 // Only open one submenu at a time.
1126 if (!CloseOtherSubmenus(id
))
1129 CreateSubmenu(id
, new_folders
, title
);
1134 /// close all windows of the start menu popup
1135 void StartMenu::CloseStartMenu(int id
)
1137 if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) { // don't automatically close floating menus
1138 if (!SendParent(PM_STARTENTRY_LAUNCHED
, id
, (LPARAM
)_hwnd
))
1139 DestroyWindow(_hwnd
);
1140 } else if (_submenu
) // instead close submenus of floating parent menus
1145 int GetStartMenuBtnTextWidth(HDC hdc
, LPCTSTR title
, HWND hwnd
)
1147 RECT rect
= {0, 0, 0, 0};
1148 DrawText(hdc
, title
, -1, &rect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_CALCRECT
);
1150 return rect
.right
-rect
.left
;
1153 #ifdef _LIGHT_STARTMENU
1154 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, const SMBtnInfo
& btn
, bool has_focus
, bool pushed
)
1156 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, HICON hIcon
,
1157 bool hasSubmenu
, bool enabled
, bool has_focus
, bool pushed
);
1160 UINT style
= DFCS_BUTTONPUSH
;
1163 style
|= DFCS_INACTIVE
;
1165 POINT iconPos
= {rect
.left
+2, (rect
.top
+rect
.bottom
-16)/2};
1166 RECT textRect
= {rect
.left
+16+4, rect
.top
+2, rect
.right
-4, rect
.bottom
-4};
1169 style
|= DFCS_PUSHED
;
1170 ++iconPos
.x
; ++iconPos
.y
;
1171 ++textRect
.left
; ++textRect
.top
;
1172 ++textRect
.right
; ++textRect
.bottom
;
1175 int bk_color_idx
= COLOR_BTNFACE
;
1176 int text_color_idx
= COLOR_BTNTEXT
;
1179 bk_color_idx
= COLOR_HIGHLIGHT
;
1180 text_color_idx
= COLOR_HIGHLIGHTTEXT
;
1183 COLORREF bk_color
= GetSysColor(bk_color_idx
);
1184 HBRUSH bk_brush
= GetSysColorBrush(bk_color_idx
);
1187 FillRect(hdc
, &rect
, bk_brush
);
1189 if (btn
._icon_id
> ICID_NONE
)
1190 g_Globals
._icon_cache
.get_icon(btn
._icon_id
).draw(hdc
, iconPos
.x
, iconPos
.y
, 16, 16, bk_color
, bk_brush
);
1192 // draw submenu arrow at the right
1193 if (btn
._hasSubmenu
) {
1194 static SmallIcon
arrowIcon(IDI_ARROW
);
1195 static SmallIcon
selArrowIcon(IDI_ARROW_SELECTED
);
1197 DrawIconEx(hdc
, rect
.right
-16, iconPos
.y
,
1198 has_focus
? selArrowIcon
: arrowIcon
,
1199 16, 16, 0, bk_brush
, DI_NORMAL
);
1203 BkMode
bk_mode(hdc
, TRANSPARENT
);
1205 if (!btn
._enabled
) // dis->itemState & (ODS_DISABLED|ODS_GRAYED)
1206 DrawGrayText(hdc
, &textRect
, title
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1208 TextColor
lcColor(hdc
, GetSysColor(text_color_idx
));
1209 DrawText(hdc
, title
, -1, &textRect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1215 #ifdef _LIGHT_STARTMENU
1217 void StartMenu::ResizeToButtons()
1219 WindowRect
rect(_hwnd
);
1221 WindowCanvas
canvas(_hwnd
);
1222 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1224 int max_width
= STARTMENU_WIDTH_MIN
;
1227 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
1228 int w
= GetStartMenuBtnTextWidth(canvas
, it
->_title
, _hwnd
);
1234 height
+= STARTMENU_SEP_HEIGHT
;
1236 height
+= STARTMENU_LINE_HEIGHT
;
1239 // calculate new window size
1240 int text_width
= max_width
+ 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1242 RECT rt_hgt
= {rect
.left
, rect
.bottom
-_border_top
-height
, rect
.left
+_border_left
+text_width
, rect
.bottom
};
1243 AdjustWindowRectEx(&rt_hgt
, GetWindowStyle(_hwnd
), FALSE
, GetWindowExStyle(_hwnd
));
1245 // ignore movement, only look at the size change
1246 rect
.right
= rect
.left
+ (rt_hgt
.right
-rt_hgt
.left
);
1247 rect
.top
= rect
.bottom
- (rt_hgt
.bottom
-rt_hgt
.top
);
1249 // move down if we are too high
1251 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1252 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1255 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1258 #else // _LIGHT_STARTMENU
1260 LRESULT
StartMenuButton::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1264 // automatically set the focus to startmenu entries when moving the mouse over them
1265 if (GetFocus()!=_hwnd
&& !(GetWindowStyle(_hwnd
)&WS_DISABLED
))
1270 PostParent(PM_STARTENTRY_FOCUSED
, _hasSubmenu
, (LPARAM
)_hwnd
);
1274 // route WM_CANCELMODE to the startmenu window
1275 return SendParent(nmsg
, wparam
, lparam
);
1278 return super::WndProc(nmsg
, wparam
, lparam
);
1284 void StartMenuButton::DrawItem(LPDRAWITEMSTRUCT dis
)
1286 TCHAR title
[BUFFER_LEN
];
1288 GetWindowText(_hwnd
, title
, BUFFER_LEN
);
1290 DrawStartMenuButton(dis
->hDC
, dis
->rcItem
, title
, _hIcon
,
1292 !(dis
->itemState
& ODS_DISABLED
),
1293 dis
->itemState
&ODS_FOCUS
? true: false,
1294 dis
->itemState
&ODS_SELECTED
? true: false);
1300 StartMenuRoot::StartMenuRoot(HWND hwnd
)
1303 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1304 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCOMMONGROUPS
))
1307 // insert directory "All Users\Start Menu"
1308 ShellDirectory
cmn_startmenu(GetDesktopFolder(), SpecialFolderPath(CSIDL_COMMON_STARTMENU
, _hwnd
), _hwnd
);
1309 _dirs
.push_back(StartMenuDirectory(cmn_startmenu
, false)); // don't add subfolders
1310 } catch(COMException
&) {
1311 // ignore exception and don't show additional shortcuts
1315 // insert directory "<user name>\Start Menu"
1317 ShellDirectory
usr_startmenu(GetDesktopFolder(), SpecialFolderPath(CSIDL_STARTMENU
, _hwnd
), _hwnd
);
1318 _dirs
.push_back(StartMenuDirectory(usr_startmenu
, false)); // don't add subfolders
1319 } catch(COMException
&) {
1320 // ignore exception and don't show additional shortcuts
1323 // read size of logo bitmap
1325 GetObject(ResBitmap(IDB_LOGOV
), sizeof(BITMAP
), &bmp_hdr
);
1326 _logo_size
.cx
= bmp_hdr
.bmWidth
;
1327 _logo_size
.cy
= bmp_hdr
.bmHeight
;
1329 _border_left
= _logo_size
.cx
+ 1;
1333 HWND
StartMenuRoot::Create(HWND hwndOwner
)
1335 WindowRect
pos(hwndOwner
);
1337 RECT rect
= {pos
.left
, pos
.top
-STARTMENU_LINE_HEIGHT
-4, pos
.left
+STARTMENU_WIDTH_MIN
, pos
.top
};
1339 #ifndef _LIGHT_STARTMENU
1340 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1343 AdjustWindowRectEx(&rect
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
, FALSE
, 0);
1345 return Window::Create(WINDOW_CREATOR(StartMenuRoot
), 0, GetWndClasss(), TITLE_STARTMENU
,
1346 WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
,
1347 rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndOwner
);
1351 void StartMenuRoot::TrackStartmenu()
1356 #ifdef _LIGHT_STARTMENU
1360 // show previously hidden start menu
1361 ShowWindow(hwnd
, SW_SHOW
);
1362 SetForegroundWindow(hwnd
);
1364 while(IsWindow(hwnd
)) {
1365 if (!GetMessage(&msg
, 0, 0, 0)) {
1366 PostQuitMessage(msg
.wParam
);
1370 // Check for a mouse click on any window, which is not part of the start menu
1371 if (msg
.message
==WM_LBUTTONDOWN
|| msg
.message
==WM_MBUTTONDOWN
|| msg
.message
==WM_RBUTTONDOWN
) {
1372 StartMenu
* menu_wnd
= NULL
;
1374 for(HWND hwnd
=msg
.hwnd
; hwnd
; hwnd
=GetParent(hwnd
)) {
1375 menu_wnd
= WINDOW_DYNAMIC_CAST(StartMenu
, hwnd
);
1388 if (pretranslate_msg(&msg
))
1391 if (dispatch_dialog_msg(&msg
))
1394 TranslateMessage(&msg
);
1397 DispatchMessage(&msg
);
1398 } catch(COMException
& e
) {
1399 HandleException(e
, _hwnd
);
1401 } catch(COMException
& e
) {
1402 HandleException(e
, _hwnd
);
1408 LRESULT
StartMenuRoot::Init(LPCREATESTRUCT pcs
)
1410 // add buttons for entries in _entries
1411 if (super::Init(pcs
))
1421 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"), &hkey
))
1424 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), &hkeyAdv
))
1427 #define IS_VALUE_ZERO(hk, name) \
1428 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || !value))
1430 #define IS_VALUE_NOT_ZERO(hk, name) \
1431 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || value>0))
1435 // insert hard coded start entries
1436 AddButton(ResString(IDS_PROGRAMS
), ICID_APPS
, true, IDC_PROGRAMS
);
1438 AddButton(ResString(IDS_DOCUMENTS
), ICID_DOCUMENTS
, true, IDC_DOCUMENTS
);
1440 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1441 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORECENTDOCSMENU
))
1443 if (IS_VALUE_ZERO(hkey
, _T("NoRecentDocsMenu")))
1445 AddButton(ResString(IDS_RECENT
), ICID_DOCUMENTS
, true, IDC_RECENT
);
1447 AddButton(ResString(IDS_FAVORITES
), ICID_FAVORITES
, true, IDC_FAVORITES
);
1449 AddButton(ResString(IDS_SETTINGS
), ICID_CONFIG
, true, IDC_SETTINGS
);
1451 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1452 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOFIND
))
1454 if (IS_VALUE_ZERO(hkey
, _T("NoFind")))
1456 AddButton(ResString(IDS_SEARCH
), ICID_SEARCH
, true, IDC_SEARCH
);
1458 AddButton(ResString(IDS_START_HELP
), ICID_INFO
, false, IDC_START_HELP
);
1460 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1461 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORUN
))
1463 if (IS_VALUE_ZERO(hkey
, _T("NoRun")))
1465 AddButton(ResString(IDS_LAUNCH
), ICID_ACTION
, false, IDC_LAUNCH
);
1471 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1472 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCLOSE
))
1474 if (IS_VALUE_NOT_ZERO(hkeyAdv
, _T("StartMenuLogoff")))
1476 AddButton(ResString(IDS_LOGOFF
), ICID_LOGOFF
, false, IDC_LOGOFF
);
1479 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1480 if (!g_Globals
._SHRestricted
|| SHRestricted(REST_STARTMENULOGOFF
) != 1)
1482 if (IS_VALUE_ZERO(hkey
, _T("NoClose")))
1484 AddButton(ResString(IDS_SHUTDOWN
), ICID_LOGOFF
, false, IDC_SHUTDOWN
);
1488 RegCloseKey(hkeyAdv
);
1493 #ifdef _LIGHT_STARTMENU
1494 // set the window size to fit all buttons
1502 void StartMenuRoot::AddEntries()
1504 super::AddEntries();
1506 AddButton(ResString(IDS_EXPLORE
), ICID_EXPLORER
, false, IDC_EXPLORE
);
1510 LRESULT
StartMenuRoot::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1514 PaintCanvas
canvas(_hwnd
);
1519 return super::WndProc(nmsg
, wparam
, lparam
);
1525 void StartMenuRoot::Paint(PaintCanvas
& canvas
)
1528 {WindowCanvas
dc(_hwnd
); clr_bits
=GetDeviceCaps(dc
, BITSPIXEL
);}
1531 ResBitmap
bmp(clr_bits
<=8? clr_bits
<=4? IDB_LOGOV16
: IDB_LOGOV256
: IDB_LOGOV
);
1532 BitmapSelection
sel(mem_dc
, bmp
);
1534 ClientRect
clnt(_hwnd
);
1535 int h
= min(_logo_size
.cy
, clnt
.bottom
);
1537 RECT rect
= {0, 0, _logo_size
.cx
, clnt
.bottom
-h
};
1538 HBRUSH hbr
= CreateSolidBrush(GetPixel(mem_dc
, 0, 0));
1539 FillRect(canvas
, &rect
, hbr
);
1542 PatBlt(canvas
, _logo_size
.cx
, 0, 1, clnt
.bottom
, WHITENESS
);
1544 BitBlt(canvas
, 0, clnt
.bottom
-h
, _logo_size
.cx
, h
, mem_dc
, 0, 0, SRCCOPY
);
1546 super::Paint(canvas
);
1550 void StartMenuRoot::CloseStartMenu(int id
)
1555 ShowWindow(_hwnd
, SW_HIDE
);
1558 void StartMenuRoot::ProcessKey(int vk
)
1563 CloseOtherSubmenus();
1564 // don't close start menu root
1568 super::ProcessKey(vk
);
1573 int StartMenuHandler::Command(int id
, int code
)
1580 CreateSubmenu(id
, CSIDL_COMMON_PROGRAMS
, CSIDL_PROGRAMS
, ResString(IDS_PROGRAMS
));
1585 explorer_show_frame(SW_SHOWNORMAL
);
1590 ShowLaunchDialog(g_Globals
._hwndDesktopBar
);
1594 CreateSubmenu(id
, CSIDL_PERSONAL
, ResString(IDS_DOCUMENTS
));
1598 CreateSubmenu(id
, CSIDL_RECENT
, ResString(IDS_RECENT
), STARTMENU_CREATOR(RecentStartMenu
));
1602 CreateSubmenu(id
, CSIDL_FAVORITES
, ResString(IDS_FAVORITES
));
1606 CreateSubmenu(id
, ResString(IDS_SETTINGS
), STARTMENU_CREATOR(SettingsMenu
));
1610 CreateSubmenu(id
, ResString(IDS_SEARCH
), STARTMENU_CREATOR(SearchMenu
));
1613 case IDC_START_HELP
:
1615 MessageBox(g_Globals
._hwndDesktopBar
, TEXT("Help not yet implemented"), ResString(IDS_TITLE
), MB_OK
);
1619 /* The shell32 Dialog prompts about some system setting change. This is not what we want to display here.
1621 ShowRestartDialog(g_Globals._hwndDesktopBar, EWX_LOGOFF);*/
1622 DestroyWindow(GetParent(_hwnd
));
1627 ShowExitWindowsDialog(g_Globals
._hwndDesktopBar
);
1633 case ID_DESKTOPBAR_SETTINGS
:
1635 ExplorerPropertySheet(g_Globals
._hwndDesktopBar
);
1640 MainFrame::Create(SpecialFolderPath(CSIDL_PRINTERS
, _hwnd
), OWM_PIDL
);
1643 case IDC_CONTROL_PANEL
:
1645 MainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
1650 MainFrame::Create(SpecialFolderPath(CSIDL_COMMON_ADMINTOOLS
, _hwnd
), OWM_PIDL
);
1653 case IDC_CONNECTIONS
:
1655 MainFrame::Create(SpecialFolderPath(CSIDL_CONNECTIONS
, _hwnd
), OWM_PIDL
);
1661 case IDC_SEARCH_FILES
:
1666 case IDC_SEARCH_COMPUTER
:
1668 ShowSearchComputer();
1673 return super::Command(id
, code
);
1680 void StartMenuHandler::ShowSearchDialog()
1682 static DynamicFct
<SHFINDFILES
> SHFindFiles(TEXT("SHELL32"), 90);
1685 (*SHFindFiles
)(NULL
, NULL
);
1687 MessageBox(0, TEXT("SHFindFiles() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1690 void StartMenuHandler::ShowSearchComputer()
1692 static DynamicFct
<SHFINDCOMPUTER
> SHFindComputer(TEXT("SHELL32"), 91);
1695 (*SHFindComputer
)(NULL
, NULL
);
1697 MessageBox(0, TEXT("SHFindComputer() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1700 void StartMenuHandler::ShowLaunchDialog(HWND hwndOwner
)
1702 ///@todo All text phrases should be put into the resources.
1703 static LPCSTR szTitle
= "Run";
1704 static LPCSTR szText
= "Type the name of a program, folder, document, or Internet resource, and Explorer will open it for you.";
1706 static DynamicFct
<RUNFILEDLG
> RunFileDlg(TEXT("SHELL32"), 61);
1708 // Show "Run..." dialog
1710 #ifndef _ROS_ /* FIXME: our shell32 always expects Ansi strings */
1712 if ((HIWORD(GetVersion())>>14) == W_VER_NT
) {
1713 WCHAR wTitle
[40], wText
[256];
1715 MultiByteToWideChar(CP_ACP
, 0, szTitle
, -1, wTitle
, 40);
1716 MultiByteToWideChar(CP_ACP
, 0, szText
, -1, wText
, 256);
1718 (*RunFileDlg
)(hwndOwner
, 0, NULL
, (LPCSTR
)wTitle
, (LPCSTR
)wText
, RFF_CALCDIRECTORY
);
1722 (*RunFileDlg
)(hwndOwner
, 0, NULL
, szTitle
, szText
, RFF_CALCDIRECTORY
);
1726 void StartMenuHandler::ShowRestartDialog(HWND hwndOwner
, UINT flags
)
1728 static DynamicFct
<RESTARTWINDOWSDLG
> RestartDlg(TEXT("SHELL32"), 59);
1731 (*RestartDlg
)(hwndOwner
, (LPWSTR
)L
"You selected <Log Off>.\n\n", flags
); ///@todo ANSI string conversion if needed
1733 MessageBox(hwndOwner
, TEXT("RestartDlg() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1736 void ShowExitWindowsDialog(HWND hwndOwner
)
1738 static DynamicFct
<EXITWINDOWSDLG
> ExitWindowsDlg(TEXT("SHELL32"), 60);
1741 (*ExitWindowsDlg
)(hwndOwner
);
1743 MessageBox(hwndOwner
, TEXT("ExitWindowsDlg() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1747 void SettingsMenu::AddEntries()
1749 super::AddEntries();
1751 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1752 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
1754 AddButton(ResString(IDS_CONTROL_PANEL
), ICID_CONFIG
, false, IDC_CONTROL_PANEL
);
1756 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, false, IDC_PRINTERS
);
1757 AddButton(ResString(IDS_CONNECTIONS
), ICID_NETWORK
, false, IDC_CONNECTIONS
);
1758 AddButton(ResString(IDS_ADMIN
), ICID_CONFIG
, false, IDC_ADMIN
);
1760 AddButton(ResString(IDS_DESKTOPBAR_SETTINGS
), ICID_CONFIG
, false, ID_DESKTOPBAR_SETTINGS
);
1763 void SearchMenu::AddEntries()
1765 super::AddEntries();
1767 AddButton(ResString(IDS_SEARCH_FILES
), ICID_SEARCH_DOC
, false, IDC_SEARCH_FILES
);
1769 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1770 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_HASFINDCOMPUTERS
))
1772 AddButton(ResString(IDS_SEARCH_COMPUTER
), ICID_COMPUTER
, false, IDC_SEARCH_COMPUTER
);
1776 void RecentStartMenu::AddEntries()
1778 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
1779 StartMenuDirectory
& smd
= *it
;
1780 ShellDirectory
& dir
= smd
._dir
;
1782 if (!dir
._scanned
) {
1785 #ifdef _LAZY_ICONEXTRACT
1786 dir
.smart_scan(SCAN_FILESYSTEM
);
1788 dir
.smart_scan(SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
1792 dir
.sort_directory(SORT_DATE
);
1793 AddShellEntries(dir
, 16, smd
._subfolders
); ///@todo read max. count of entries from registry