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"
42 #include "../dialogs/searchprogram.h"
45 StartMenu::StartMenu(HWND hwnd
)
48 _next_id
= IDC_FIRST_MENU
;
52 _last_pos
= WindowRect(hwnd
).pos();
53 #ifdef _LIGHT_STARTMENU
59 StartMenu::StartMenu(HWND hwnd
, const StartMenuCreateInfo
& create_info
)
61 _create_info(create_info
)
63 for(StartMenuFolders::const_iterator it
=create_info
._folders
.begin(); it
!=create_info
._folders
.end(); ++it
)
65 _dirs
.push_back(ShellDirectory(Desktop(), *it
, _hwnd
));
67 _next_id
= IDC_FIRST_MENU
;
70 _border_top
= create_info
._border_top
;
71 _last_pos
= WindowRect(hwnd
).pos();
72 #ifdef _LIGHT_STARTMENU
78 StartMenu::~StartMenu()
80 SendParent(PM_STARTMENU_CLOSED
);
84 // We need this wrapper function for s_wcStartMenu, it calls the WIN32 API,
85 // though static C++ initializers are not allowed for Winelib applications.
86 BtnWindowClass
& StartMenu::GetWndClasss()
88 static BtnWindowClass
s_wcStartMenu(CLASSNAME_STARTMENU
);
94 Window::CREATORFUNC
StartMenu::s_def_creator
= STARTMENU_CREATOR(StartMenu
);
96 HWND
StartMenu::Create(int x
, int y
, const StartMenuFolders
& folders
, HWND hwndParent
, LPCTSTR title
, CREATORFUNC creator
)
102 style
= WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
;
104 top_height
= STARTMENU_TOP_BTN_SPACE
;
106 style
= WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|WS_CLIPCHILDREN
|WS_VISIBLE
;
107 ex_style
= WS_EX_TOOLWINDOW
;
111 RECT rect
= {x
, y
-STARTMENU_LINE_HEIGHT
-top_height
, x
+STARTMENU_WIDTH_MIN
, y
};
113 #ifndef _LIGHT_STARTMENU
114 rect
.top
+= STARTMENU_LINE_HEIGHT
;
117 AdjustWindowRectEx(&rect
, style
, FALSE
, ex_style
);
119 StartMenuCreateInfo create_info
;
121 create_info
._folders
= folders
;
122 create_info
._border_top
= top_height
;
123 create_info
._creator
= creator
;
126 create_info
._title
= title
;
128 HWND hwnd
= Window::Create(creator
, &create_info
, ex_style
, GetWndClasss(), title
,
129 style
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndParent
);
131 // make sure the window is not off the screen
138 LRESULT
StartMenu::Init(LPCREATESTRUCT pcs
)
143 if (super::Init(pcs
))
146 // create buttons for registered entries in _entries
147 for(ShellEntryMap::const_iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
148 const StartMenuEntry
& sme
= it
->second
;
149 bool hasSubmenu
= false;
151 for(ShellEntrySet::const_iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
)
152 if ((*it
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
155 #ifdef _LIGHT_STARTMENU
156 _buttons
.push_back(SMBtnInfo(sme
, it
->first
, hasSubmenu
));
158 AddButton(sme
._title
, sme
._hIcon
, hasSubmenu
, it
->first
);
162 #ifdef _LIGHT_STARTMENU
163 if (_buttons
.empty())
165 if (!GetWindow(_hwnd
, GW_CHILD
))
167 AddButton(ResString(IDS_EMPTY
), ICID_NONE
, false, 0, false);
169 #ifdef _LIGHT_STARTMENU
173 #ifdef _LAZY_ICONEXTRACT
174 PostMessage(_hwnd
, PM_UPDATE_ICONS
, 0, 0);
176 } catch(COMException
& e
) {
177 HandleException(e
, pcs
->hwndParent
); // destroys the start menu window while switching focus
183 void StartMenu::AddEntries()
185 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
186 StartMenuDirectory
& smd
= *it
;
187 ShellDirectory
& dir
= smd
._dir
;
192 #ifdef _LAZY_ICONEXTRACT
193 dir
.smart_scan(SCAN_FILESYSTEM
); // lazy icon extraction, try to read directly from filesystem
195 dir
.smart_scan(SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
199 AddShellEntries(dir
, -1, smd
._subfolders
);
204 void StartMenu::AddShellEntries(const ShellDirectory
& dir
, int max
, bool subfolders
)
208 for(Entry
*entry
=dir
._down
; entry
; entry
=entry
->_next
) {
209 // hide files like "desktop.ini"
210 if (entry
->_shell_attribs
& SFGAO_HIDDEN
)
211 //not appropriate for drive roots: if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
214 // hide subfolders if requested
216 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
219 // only 'max' entries shall be added.
223 if (entry
->_etype
== ET_SHELL
)
224 AddEntry(dir
._folder
, static_cast<ShellEntry
*>(entry
));
226 AddEntry(dir
._folder
, entry
);
231 LRESULT
StartMenu::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
235 PaintCanvas
canvas(_hwnd
);
240 ResizeButtons(LOWORD(lparam
)-_border_left
);
244 POINTS
& pos
= MAKEPOINTS(lparam
);
246 // move open submenus of floating menus
248 int dx
= pos
.x
- _last_pos
.x
;
249 int dy
= pos
.y
- _last_pos
.y
;
252 WindowRect
rt(_submenu
);
253 SetWindowPos(_submenu
, 0, rt
.left
+dx
, rt
.top
+dy
, 0, 0, SWP_NOSIZE
|SWP_NOACTIVATE
);
254 //MoveVisible(_submenu);
263 LRESULT res
= super::WndProc(nmsg
, wparam
, lparam
);
265 if (res
>=HTSIZEFIRST
&& res
<=HTSIZELAST
)
266 return HTCLIENT
; // disable window resizing
270 case WM_LBUTTONDOWN
: {
273 // check mouse cursor for coordinates of floating button
274 GetFloatingButtonRect(&rect
);
276 if (PtInRect(&rect
, Point(lparam
))) {
277 // create a floating copy of the current start menu
278 WindowRect
pos(_hwnd
);
280 ///@todo do something similar to StartMenuRoot::TrackStartmenu() in order to automatically close submenus when clicking on the desktop background
281 StartMenu::Create(pos
.left
+3, pos
.bottom
-3, _create_info
._folders
, 0, _create_info
._title
, _create_info
._creator
);
285 #ifdef _LIGHT_STARTMENU
286 int id
= ButtonHitTest(Point(lparam
));
289 Command(id
, BN_CLICKED
);
294 if ((wparam
&0xFFF0) == SC_SIZE
)
295 return 0; // disable window resizing
299 // close start menu when activating another application
302 break; // don't call super::WndProc in case "this" has been deleted
308 #ifdef _LIGHT_STARTMENU
310 // automatically set the focus to startmenu entries when moving the mouse over them
311 if (lparam
!= _last_mouse_pos
) { // don't process WM_MOUSEMOVE when opening submenus using keyboard navigation
312 int new_id
= ButtonHitTest(Point(lparam
));
314 if (new_id
!= _selected_id
)
315 SelectButton(new_id
);
317 _last_mouse_pos
= lparam
;
325 case PM_STARTENTRY_FOCUSED
: { ///@todo use TrackMouseEvent() and WM_MOUSEHOVER to wait a bit before opening submenus
326 BOOL hasSubmenu
= wparam
;
327 HWND hctrl
= (HWND
)lparam
;
329 // automatically open submenus
331 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
332 //SendMessage(_hwnd, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hctrl),BN_CLICKED), (LPARAM)hctrl);
333 Command(GetDlgCtrlID(hctrl
), BN_CLICKED
);
335 // close any open submenu
336 CloseOtherSubmenus();
341 #ifdef _LAZY_ICONEXTRACT
342 case PM_UPDATE_ICONS
:
343 UpdateIcons(/*wparam*/);
347 case PM_STARTENTRY_LAUNCHED
:
348 if (GetWindowStyle(_hwnd
) & WS_CAPTION
) // don't automatically close floating menus
351 // route message to the parent menu and close menus after launching an entry
352 if (!SendParent(nmsg
, wparam
, lparam
))
354 return 1; // signal that we have received and processed the message
356 case PM_STARTMENU_CLOSED
:
360 case PM_SELECT_ENTRY
:
361 SelectButtonIndex(0, wparam
?true:false);
365 return super::WndProc(nmsg
, wparam
, lparam
);
372 #ifdef _LIGHT_STARTMENU
374 int StartMenu::ButtonHitTest(POINT pt
)
376 ClientRect
clnt(_hwnd
);
377 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
379 if (pt
.x
<rect
.left
|| pt
.x
>rect
.right
)
382 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
383 const SMBtnInfo
& info
= *it
;
388 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
390 if (pt
.y
< rect
.bottom
) // PtInRect(&rect, pt)
393 rect
.top
= rect
.bottom
;
399 void StartMenu::InvalidateSelection()
404 ClientRect
clnt(_hwnd
);
405 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
407 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
408 const SMBtnInfo
& info
= *it
;
410 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
412 if (info
._id
== _selected_id
) {
413 InvalidateRect(_hwnd
, &rect
, TRUE
);
417 rect
.top
= rect
.bottom
;
421 const SMBtnInfo
* StartMenu::GetButtonInfo(int id
) const
423 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
)
430 bool StartMenu::SelectButton(int id
, bool open_sub
)
435 if (id
== _selected_id
)
438 InvalidateSelection();
440 const SMBtnInfo
* btn
= GetButtonInfo(id
);
442 if (btn
&& btn
->_enabled
) {
445 InvalidateSelection();
447 // automatically open submenus
448 if (btn
->_hasSubmenu
) {
452 CloseOtherSubmenus(); // close any open submenu
461 bool StartMenu::OpenSubmenu(bool select_first
)
463 if (_selected_id
== -1)
466 InvalidateSelection();
468 const SMBtnInfo
* btn
= GetButtonInfo(_selected_id
);
470 // automatically open submenus
471 if (btn
->_hasSubmenu
) {
472 //@@ allows destroying of startmenu when processing PM_UPDATE_ICONS -> GPF
473 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
474 Command(_selected_id
, BN_CLICKED
);
476 if (select_first
&& _submenu
)
477 SendMessage(_submenu
, PM_SELECT_ENTRY
, (WPARAM
)false, 0);
485 int StartMenu::GetSelectionIndex()
487 if (_selected_id
== -1)
490 for(int i
=0; i
<(int)_buttons
.size(); ++i
)
491 if (_buttons
[i
]._id
== _selected_id
)
497 bool StartMenu::SelectButtonIndex(int idx
, bool open_sub
)
499 if (idx
>=0 && idx
<(int)_buttons
.size())
500 return SelectButton(_buttons
[idx
]._id
, open_sub
);
505 void StartMenu::ProcessKey(int vk
)
510 Command(_selected_id
, BN_CLICKED
);
522 SelectButtonIndex(0, false);
526 SelectButtonIndex(_buttons
.size()-1, false);
531 CloseOtherSubmenus();
532 else if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) // don't automatically close floating menus
533 DestroyWindow(_hwnd
);
546 bool StartMenu::Navigate(int step
)
548 int idx
= GetSelectionIndex();
554 idx
= _buttons
.size() - step
;
559 if (idx
<0 || idx
>(int)_buttons
.size())
562 if (SelectButtonIndex(idx
, false))
569 #endif // _LIGHT_STARTMENU
572 bool StartMenu::GetButtonRect(int id
, PRECT prect
) const
574 #ifdef _LIGHT_STARTMENU
575 ClientRect
clnt(_hwnd
);
576 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
578 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
579 const SMBtnInfo
& info
= *it
;
581 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
583 if (info
._id
== id
) {
588 rect
.top
= rect
.bottom
;
593 HWND btn
= GetDlgItem(_hwnd
, id
);
596 GetWindowRect(btn
, prect
);
597 ScreenToClient(_hwnd
, prect
);
606 void StartMenu::DrawFloatingButton(HDC hdc
)
608 static ResIconEx
floatingIcon(IDI_FLOATING
, 8, 4);
610 ClientRect
clnt(_hwnd
);
612 DrawIconEx(hdc
, clnt
.right
-12, 0, floatingIcon
, 8, 4, 0, 0, DI_NORMAL
);
615 void StartMenu::GetFloatingButtonRect(LPRECT prect
)
617 GetClientRect(_hwnd
, prect
);
620 prect
->left
= prect
->right
- 8;
625 void StartMenu::Paint(PaintCanvas
& canvas
)
628 DrawFloatingButton(canvas
);
630 #ifdef _LIGHT_STARTMENU
631 ClientRect
clnt(_hwnd
);
632 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
634 int sep_width
= rect
.right
-rect
.left
- 4;
636 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
637 BkMode
bk_mode(canvas
, TRANSPARENT
);
639 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
640 const SMBtnInfo
& btn
= *it
;
642 if (rect
.top
> canvas
.rcPaint
.bottom
)
645 if (btn
._id
== -1) { // a separator?
646 rect
.bottom
= rect
.top
+ STARTMENU_SEP_HEIGHT
;
648 BrushSelection
brush_sel(canvas
, GetSysColorBrush(COLOR_BTNSHADOW
));
649 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2-1, sep_width
, 1, PATCOPY
);
651 SelectBrush(canvas
, GetSysColorBrush(COLOR_BTNHIGHLIGHT
));
652 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2, sep_width
, 1, PATCOPY
);
654 rect
.bottom
= rect
.top
+ STARTMENU_LINE_HEIGHT
;
656 if (rect
.top
>= canvas
.rcPaint
.top
)
657 DrawStartMenuButton(canvas
, rect
, btn
._title
, btn
, btn
._id
==_selected_id
, false);
660 rect
.top
= rect
.bottom
;
665 #ifdef _LAZY_ICONEXTRACT
666 void StartMenu::UpdateIcons(/*int idx*/)
670 #ifdef _SINGLE_ICONEXTRACT
675 for(; idx
<(int)_buttons
.size(); ++idx
) {
676 SMBtnInfo
& btn
= _buttons
[idx
];
678 if (btn
._icon_id
==ICID_UNKNOWN
&& btn
._id
>0) {
679 StartMenuEntry
& sme
= _entries
[btn
._id
];
681 btn
._icon_id
= ICID_NONE
;
683 for(ShellEntrySet::iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
) {
686 if (entry
->_icon_id
== ICID_UNKNOWN
)
687 entry
->extract_icon();
689 if (entry
->_icon_id
> ICID_NONE
) {
690 btn
._icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
694 GetButtonRect(btn
._id
, &rect
);
695 WindowCanvas
canvas(_hwnd
);
696 DrawStartMenuButton(canvas
, rect
, NULL
, btn
, btn
._id
==_selected_id
, false);
698 //InvalidateRect(_hwnd, &rect, FALSE);
699 //UpdateWindow(_hwnd);
708 // if (++idx < (int)_buttons.size())
709 // PostMessage(_hwnd, PM_UPDATE_ICONS, idx, 0);
713 int icons_extracted
= 0;
714 int icons_updated
= 0;
716 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
717 ShellDirectory
& dir
= it
->_dir
;
719 icons_extracted
+= dir
.extract_icons();
722 if (icons_extracted
) {
723 for(ShellEntryMap::iterator it1
=_entries
.begin(); it1
!=_entries
.end(); ++it1
) {
724 StartMenuEntry
& sme
= it1
->second
;
727 sme
._hIcon
= (HICON
)-1;
729 for(ShellEntrySet::const_iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
730 const Entry
* sm_entry
= *it2
;
732 if (sm_entry
->_hIcon
) {
733 sme
._hIcon
= sm_entry
->_hIcon
;
740 for(SMBtnVector::iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
741 SMBtnInfo
& info
= *it
;
743 if (info
._id
>0 && !info
._hIcon
) {
744 info
._hIcon
= _entries
[info
._id
]._hIcon
;
751 InvalidateRect(_hwnd
, NULL
, FALSE
);
759 // resize child button controls to accomodate for new window size
760 void StartMenu::ResizeButtons(int cx
)
762 HDWP hdwp
= BeginDeferWindowPos(10);
764 for(HWND ctrl
=GetWindow(_hwnd
,GW_CHILD
); ctrl
; ctrl
=GetNextWindow(ctrl
,GW_HWNDNEXT
)) {
767 if (rt
.right
!= cx
) {
768 int height
= rt
.bottom
- rt
.top
;
770 // special handling for separator controls
771 if (!height
&& (GetWindowStyle(ctrl
)&SS_TYPEMASK
)==SS_ETCHEDHORZ
)
774 hdwp
= DeferWindowPos(hdwp
, ctrl
, 0, 0, 0, cx
, height
, SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
);
778 EndDeferWindowPos(hdwp
);
782 int StartMenu::Command(int id
, int code
)
784 #ifndef _LIGHT_STARTMENU
792 ShellEntryMap::iterator found
= _entries
.find(id
);
794 if (found
!= _entries
.end()) {
795 ActivateEntry(id
, found
->second
._entries
);
799 return super::Command(id
, code
);
800 #ifndef _LIGHT_STARTMENU
809 StartMenuEntry
& StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, Entry
* entry
)
811 // search for an already existing subdirectory entry with the same name
812 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
813 for(ShellEntryMap::iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
814 StartMenuEntry
& sme
= it
->second
;
816 if (sme
._title
== title
) ///@todo speed up by using a map indexed by name
817 for(ShellEntrySet::iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
818 if ((*it2
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
819 // merge the new shell entry with the existing of the same name
820 sme
._entries
.insert(entry
);
826 StartMenuEntry
& sme
= AddEntry(title
, icon_id
);
828 sme
._entries
.insert(entry
);
833 StartMenuEntry
& StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, int id
)
838 StartMenuEntry
& sme
= _entries
[id
];
841 sme
._icon_id
= icon_id
;
846 StartMenuEntry
& StartMenu::AddEntry(const ShellFolder folder
, ShellEntry
* entry
)
850 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
851 icon_id
= ICID_FOLDER
;
853 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
855 return AddEntry(folder
.get_name(entry
->_pidl
), icon_id
, entry
);
858 StartMenuEntry
& StartMenu::AddEntry(const ShellFolder folder
, Entry
* entry
)
862 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
863 icon_id
= ICID_FOLDER
;
865 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
867 return AddEntry(entry
->_display_name
, icon_id
, entry
);
871 void StartMenu::AddButton(LPCTSTR title
, ICON_ID icon_id
, bool hasSubmenu
, int id
, bool enabled
)
873 #ifdef _LIGHT_STARTMENU
874 _buttons
.push_back(SMBtnInfo(title
, icon_id
, id
, hasSubmenu
, enabled
));
876 DWORD style
= enabled
? WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
: WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
|WS_DISABLED
;
878 WindowRect
rect(_hwnd
);
879 ClientRect
clnt(_hwnd
);
881 // increase window height to make room for the new button
882 rect
.top
-= STARTMENU_LINE_HEIGHT
;
884 // move down if we are too high now
886 rect
.top
+= STARTMENU_LINE_HEIGHT
;
887 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
890 WindowCanvas
canvas(_hwnd
);
891 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
893 // widen window, if it is too small
894 int text_width
= GetStartMenuBtnTextWidth(canvas
, title
, _hwnd
) + 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
896 int cx
= clnt
.right
- _border_left
;
898 rect
.right
+= text_width
-cx
;
900 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
902 StartMenuCtrl(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
,
903 title
, id
, g_Globals
._icon_cache
.get_icon(icon_id
)._hIcon
, hasSubmenu
, style
);
907 void StartMenu::AddSeparator()
909 #ifdef _LIGHT_STARTMENU
910 _buttons
.push_back(SMBtnInfo(NULL
, ICID_NONE
, -1, false));
912 WindowRect
rect(_hwnd
);
913 ClientRect
clnt(_hwnd
);
915 // increase window height to make room for the new separator
916 rect
.top
-= STARTMENU_SEP_HEIGHT
;
918 // move down if we are too high now
920 rect
.top
+= STARTMENU_LINE_HEIGHT
;
921 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
924 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
926 StartMenuSeparator(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
);
931 bool StartMenu::CloseOtherSubmenus(int id
)
934 if (IsWindow(_submenu
)) {
935 if (_submenu_id
== id
)
939 DestroyWindow(_submenu
);
940 // _submenu should be reset automatically by PM_STARTMENU_CLOSED, but safety first...
951 void StartMenu::CreateSubmenu(int id
, LPCTSTR title
, CREATORFUNC creator
)
953 CreateSubmenu(id
, StartMenuFolders(), title
, creator
);
956 void StartMenu::CreateSubmenu(int id
, int folder_id
, LPCTSTR title
, CREATORFUNC creator
)
959 SpecialFolderPath
folder(folder_id
, _hwnd
);
961 StartMenuFolders new_folders
;
962 new_folders
.push_back(folder
);
964 CreateSubmenu(id
, new_folders
, title
, creator
);
965 } catch(COMException
&) {
966 // ignore Exception and don't display anything
970 void StartMenu::CreateSubmenu(int id
, int folder_id1
, int folder_id2
, LPCTSTR title
, CREATORFUNC creator
)
972 StartMenuFolders new_folders
;
975 new_folders
.push_back(SpecialFolderPath(folder_id1
, _hwnd
));
976 } catch(COMException
&) {
980 new_folders
.push_back(SpecialFolderPath(folder_id2
, _hwnd
));
981 } catch(COMException
&) {
984 if (!new_folders
.empty())
985 CreateSubmenu(id
, new_folders
, title
, creator
);
988 void StartMenu::CreateSubmenu(int id
, const StartMenuFolders
& new_folders
, LPCTSTR title
, CREATORFUNC creator
)
990 // Only open one submenu at a time.
991 if (!CloseOtherSubmenus(id
))
997 if (GetButtonRect(id
, &rect
)) {
998 ClientToScreen(_hwnd
, &rect
);
1000 x
= rect
.right
; // Submenus should overlap their parent a bit.
1001 y
= rect
.top
+STARTMENU_LINE_HEIGHT
-_border_top
;
1003 WindowRect
pos(_hwnd
);
1010 _submenu
= StartMenu::Create(x
, y
, new_folders
, _hwnd
, title
, creator
);
1014 void StartMenu::ActivateEntry(int id
, const ShellEntrySet
& entries
)
1016 StartMenuFolders new_folders
;
1019 for(ShellEntrySet::const_iterator it
=entries
.begin(); it
!=entries
.end(); ++it
) {
1020 Entry
* entry
= const_cast<Entry
*>(*it
);
1022 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1024 ///@todo If the user explicitly clicked on a submenu, display this folder as floating start menu.
1026 if (entry
->_etype
== ET_SHELL
)
1027 new_folders
.push_back(entry
->create_absolute_pidl());
1029 TCHAR path
[MAX_PATH
];
1031 if (entry
->get_path(path
))
1032 new_folders
.push_back(path
);
1036 title
= entry
->_display_name
;
1038 // If the entry is no subdirectory, there can only be one shell entry.
1039 assert(entries
.size()==1);
1041 HWND hparent
= GetParent(_hwnd
);
1042 ShellPath shell_path
= entry
->create_absolute_pidl();
1044 // close start menus after launching the selected entry
1047 ///@todo launch in the background; specify correct HWND for error message box titles
1048 SHELLEXECUTEINFO shexinfo
;
1050 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
1051 shexinfo
.fMask
= SEE_MASK_INVOKEIDLIST
; // SEE_MASK_IDLIST is also possible.
1052 shexinfo
.hwnd
= hparent
;
1053 shexinfo
.lpVerb
= NULL
;
1054 shexinfo
.lpFile
= NULL
;
1055 shexinfo
.lpParameters
= NULL
;
1056 shexinfo
.lpDirectory
= NULL
;
1057 shexinfo
.nShow
= SW_SHOWNORMAL
;
1059 shexinfo
.lpIDList
= &*shell_path
;
1061 if (!ShellExecuteEx(&shexinfo
))
1062 display_error(hparent
, GetLastError());
1064 // we may have deleted 'this' - ensure we leave the loop and function
1069 if (!new_folders
.empty()) {
1070 // Only open one submenu at a time.
1071 if (!CloseOtherSubmenus(id
))
1074 CreateSubmenu(id
, new_folders
, title
);
1079 /// close all windows of the start menu popup
1080 void StartMenu::CloseStartMenu(int id
)
1082 if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) { // don't automatically close floating menus
1083 if (!SendParent(PM_STARTENTRY_LAUNCHED
, id
, (LPARAM
)_hwnd
))
1084 DestroyWindow(_hwnd
);
1085 } else if (_submenu
) // instead close submenus of floating parent menus
1090 int GetStartMenuBtnTextWidth(HDC hdc
, LPCTSTR title
, HWND hwnd
)
1092 RECT rect
= {0, 0, 0, 0};
1093 DrawText(hdc
, title
, -1, &rect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_CALCRECT
);
1095 return rect
.right
-rect
.left
;
1098 #ifdef _LIGHT_STARTMENU
1099 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, const SMBtnInfo
& btn
, bool has_focus
, bool pushed
)
1101 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, HICON hIcon
,
1102 bool hasSubmenu
, bool enabled
, bool has_focus
, bool pushed
);
1105 UINT style
= DFCS_BUTTONPUSH
;
1108 style
|= DFCS_INACTIVE
;
1110 POINT iconPos
= {rect
.left
+2, (rect
.top
+rect
.bottom
-16)/2};
1111 RECT textRect
= {rect
.left
+16+4, rect
.top
+2, rect
.right
-4, rect
.bottom
-4};
1114 style
|= DFCS_PUSHED
;
1115 ++iconPos
.x
; ++iconPos
.y
;
1116 ++textRect
.left
; ++textRect
.top
;
1117 ++textRect
.right
; ++textRect
.bottom
;
1120 int bk_color_idx
= COLOR_BTNFACE
;
1121 int text_color_idx
= COLOR_BTNTEXT
;
1124 bk_color_idx
= COLOR_HIGHLIGHT
;
1125 text_color_idx
= COLOR_HIGHLIGHTTEXT
;
1128 COLORREF bk_color
= GetSysColor(bk_color_idx
);
1129 HBRUSH bk_brush
= GetSysColorBrush(bk_color_idx
);
1132 FillRect(hdc
, &rect
, bk_brush
);
1134 if (btn
._icon_id
> ICID_NONE
)
1135 g_Globals
._icon_cache
.get_icon(btn
._icon_id
).draw(hdc
, iconPos
.x
, iconPos
.y
, 16, 16, bk_color
, bk_brush
);
1137 // draw submenu arrow at the right
1138 if (btn
._hasSubmenu
) {
1139 static SmallIcon
arrowIcon(IDI_ARROW
);
1140 static SmallIcon
selArrowIcon(IDI_ARROW_SELECTED
);
1142 DrawIconEx(hdc
, rect
.right
-16, iconPos
.y
,
1143 has_focus
? selArrowIcon
: arrowIcon
,
1144 16, 16, 0, bk_brush
, DI_NORMAL
);
1148 BkMode
bk_mode(hdc
, TRANSPARENT
);
1150 if (!btn
._enabled
) // dis->itemState & (ODS_DISABLED|ODS_GRAYED)
1151 DrawGrayText(hdc
, &textRect
, title
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1153 TextColor
lcColor(hdc
, GetSysColor(text_color_idx
));
1154 DrawText(hdc
, title
, -1, &textRect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1160 #ifdef _LIGHT_STARTMENU
1162 void StartMenu::ResizeToButtons()
1164 WindowRect
rect(_hwnd
);
1166 WindowCanvas
canvas(_hwnd
);
1167 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1169 int max_width
= STARTMENU_WIDTH_MIN
;
1172 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
1173 int w
= GetStartMenuBtnTextWidth(canvas
, it
->_title
, _hwnd
);
1179 height
+= STARTMENU_SEP_HEIGHT
;
1181 height
+= STARTMENU_LINE_HEIGHT
;
1184 // calculate new window size
1185 int text_width
= max_width
+ 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1187 RECT rt_hgt
= {rect
.left
, rect
.bottom
-_border_top
-height
, rect
.left
+_border_left
+text_width
, rect
.bottom
};
1188 AdjustWindowRectEx(&rt_hgt
, GetWindowStyle(_hwnd
), FALSE
, GetWindowExStyle(_hwnd
));
1190 // ignore movement, only look at the size change
1191 rect
.right
= rect
.left
+ (rt_hgt
.right
-rt_hgt
.left
);
1192 rect
.top
= rect
.bottom
- (rt_hgt
.bottom
-rt_hgt
.top
);
1194 // move down if we are too high
1196 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1197 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1200 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1203 #else // _LIGHT_STARTMENU
1205 LRESULT
StartMenuButton::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1209 // automatically set the focus to startmenu entries when moving the mouse over them
1210 if (GetFocus()!=_hwnd
&& !(GetWindowStyle(_hwnd
)&WS_DISABLED
))
1215 PostParent(PM_STARTENTRY_FOCUSED
, _hasSubmenu
, (LPARAM
)_hwnd
);
1219 // route WM_CANCELMODE to the startmenu window
1220 return SendParent(nmsg
, wparam
, lparam
);
1223 return super::WndProc(nmsg
, wparam
, lparam
);
1229 void StartMenuButton::DrawItem(LPDRAWITEMSTRUCT dis
)
1231 TCHAR title
[BUFFER_LEN
];
1233 GetWindowText(_hwnd
, title
, BUFFER_LEN
);
1235 DrawStartMenuButton(dis
->hDC
, dis
->rcItem
, title
, _hIcon
,
1237 !(dis
->itemState
& ODS_DISABLED
),
1238 dis
->itemState
&ODS_FOCUS
? true: false,
1239 dis
->itemState
&ODS_SELECTED
? true: false);
1245 StartMenuRoot::StartMenuRoot(HWND hwnd
)
1248 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1249 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCOMMONGROUPS
))
1252 // insert directory "All Users\Start Menu"
1253 ShellDirectory
cmn_startmenu(Desktop(), SpecialFolderPath(CSIDL_COMMON_STARTMENU
, _hwnd
), _hwnd
);
1254 _dirs
.push_back(StartMenuDirectory(cmn_startmenu
, false)); // don't add subfolders
1255 } catch(COMException
&) {
1256 // ignore exception and don't show additional shortcuts
1260 // insert directory "<user name>\Start Menu"
1261 ShellDirectory
usr_startmenu(Desktop(), SpecialFolderPath(CSIDL_STARTMENU
, _hwnd
), _hwnd
);
1262 _dirs
.push_back(StartMenuDirectory(usr_startmenu
, false)); // don't add subfolders
1263 } catch(COMException
&) {
1264 // ignore exception and don't show additional shortcuts
1267 // read size of logo bitmap
1269 GetObject(ResBitmap(IDB_LOGOV
), sizeof(BITMAP
), &bmp_hdr
);
1270 _logo_size
.cx
= bmp_hdr
.bmWidth
;
1271 _logo_size
.cy
= bmp_hdr
.bmHeight
;
1273 _border_left
= _logo_size
.cx
;
1277 HWND
StartMenuRoot::Create(HWND hwndDesktopBar
)
1279 WindowRect
pos(hwndDesktopBar
);
1281 RECT rect
= {pos
.left
, pos
.top
-STARTMENU_LINE_HEIGHT
-4, pos
.left
+STARTMENU_WIDTH_MIN
, pos
.top
};
1283 #ifndef _LIGHT_STARTMENU
1284 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1287 AdjustWindowRectEx(&rect
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
, FALSE
, 0);
1289 return Window::Create(WINDOW_CREATOR(StartMenuRoot
), 0, GetWndClasss(), TITLE_STARTMENU
,
1290 WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
,
1291 rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndDesktopBar
);
1295 void StartMenuRoot::TrackStartmenu()
1300 #ifdef _LIGHT_STARTMENU
1304 // show previously hidden start menu
1305 ShowWindow(hwnd
, SW_SHOW
);
1307 while(IsWindow(hwnd
)) {
1308 if (!GetMessage(&msg
, 0, 0, 0)) {
1309 PostQuitMessage(msg
.wParam
);
1313 // Check for a mouse click on any window, which is not part of the start menu
1314 if (msg
.message
==WM_LBUTTONDOWN
|| msg
.message
==WM_MBUTTONDOWN
|| msg
.message
==WM_RBUTTONDOWN
) {
1315 StartMenu
* menu_wnd
= NULL
;
1317 for(HWND hwnd
=msg
.hwnd
; hwnd
; hwnd
=GetParent(hwnd
)) {
1318 menu_wnd
= WINDOW_DYNAMIC_CAST(StartMenu
, hwnd
);
1331 if (pretranslate_msg(&msg
))
1334 if (dispatch_dialog_msg(&msg
))
1337 TranslateMessage(&msg
);
1340 DispatchMessage(&msg
);
1341 } catch(COMException
& e
) {
1342 HandleException(e
, _hwnd
);
1344 } catch(COMException
& e
) {
1345 HandleException(e
, _hwnd
);
1351 LRESULT
StartMenuRoot::Init(LPCREATESTRUCT pcs
)
1353 // add buttons for entries in _entries
1354 if (super::Init(pcs
))
1364 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"), &hkey
))
1367 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), &hkeyAdv
))
1370 #define IS_VALUE_ZERO(hk, name) \
1371 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || !value))
1373 #define IS_VALUE_NOT_ZERO(hk, name) \
1374 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || value>0))
1378 // insert hard coded start entries
1379 AddButton(ResString(IDS_PROGRAMS
), ICID_APPS
, true, IDC_PROGRAMS
);
1381 AddButton(ResString(IDS_DOCUMENTS
), ICID_DOCUMENTS
, true, IDC_DOCUMENTS
);
1383 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1384 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORECENTDOCSMENU
))
1386 if (IS_VALUE_ZERO(hkey
, _T("NoRecentDocsMenu")))
1388 AddButton(ResString(IDS_RECENT
), ICID_DOCUMENTS
, true, IDC_RECENT
);
1390 AddButton(ResString(IDS_FAVORITES
), ICID_FAVORITES
, true, IDC_FAVORITES
);
1392 AddButton(ResString(IDS_SETTINGS
), ICID_CONFIG
, true, IDC_SETTINGS
);
1394 AddButton(ResString(IDS_BROWSE
), ICID_FOLDER
, true, IDC_BROWSE
);
1396 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1397 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOFIND
))
1399 if (IS_VALUE_ZERO(hkey
, _T("NoFind")))
1401 AddButton(ResString(IDS_SEARCH
), ICID_SEARCH
, true, IDC_SEARCH
);
1403 AddButton(ResString(IDS_START_HELP
), ICID_INFO
, false, IDC_START_HELP
);
1405 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1406 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORUN
))
1408 if (IS_VALUE_ZERO(hkey
, _T("NoRun")))
1410 AddButton(ResString(IDS_LAUNCH
), ICID_ACTION
, false, IDC_LAUNCH
);
1416 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1417 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCLOSE
))
1419 if (IS_VALUE_NOT_ZERO(hkeyAdv
, _T("StartMenuLogoff")))
1421 AddButton(ResString(IDS_LOGOFF
), ICID_LOGOFF
, false, IDC_LOGOFF
);
1424 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1425 if (!g_Globals
._SHRestricted
|| SHRestricted(REST_STARTMENULOGOFF
) != 1)
1427 if (IS_VALUE_ZERO(hkey
, _T("NoClose")))
1429 AddButton(ResString(IDS_SHUTDOWN
), ICID_LOGOFF
, false, IDC_SHUTDOWN
);
1433 RegCloseKey(hkeyAdv
);
1438 #ifdef _LIGHT_STARTMENU
1439 // set the window size to fit all buttons
1447 void StartMenuRoot::AddEntries()
1449 super::AddEntries();
1451 AddButton(ResString(IDS_EXPLORE
), ICID_EXPLORER
, false, IDC_EXPLORE
);
1455 LRESULT
StartMenuRoot::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1459 PaintCanvas
canvas(_hwnd
);
1464 return super::WndProc(nmsg
, wparam
, lparam
);
1470 void StartMenuRoot::Paint(PaintCanvas
& canvas
)
1473 {WindowCanvas
dc(_hwnd
); clr_bits
=GetDeviceCaps(dc
, BITSPIXEL
);}
1474 bool logo256
= clr_bits
<=8;
1477 ResBitmap
bmp(logo256
? IDB_LOGOV256
: IDB_LOGOV
);
1478 BitmapSelection
sel(mem_dc
, bmp
);
1480 ClientRect
clnt(_hwnd
);
1481 int h
= min(_logo_size
.cy
, clnt
.bottom
);
1483 RECT rect
= {0, 0, _logo_size
.cx
-1, clnt
.bottom
-h
};
1484 HBRUSH hbr
= CreateSolidBrush(logo256
? RGB(166,202,240): RGB(255,255,255)); // same color as the background color in the logo bitmap
1485 FillRect(canvas
, &rect
, hbr
);
1487 //PatBlt(canvas, _logo_size.cx-1, 0, 1, clnt.bottom-h, WHITENESS);
1488 PatBlt(canvas
, _logo_size
.cx
-1, 0, 1, clnt
.bottom
-h
, WHITENESS
);
1490 BitBlt(canvas
, 0, clnt
.bottom
-h
, _logo_size
.cx
, h
, mem_dc
, 0, 0, SRCCOPY
);
1493 rect
.left
= rect
.right
++;
1494 rect
.bottom
= clnt
.bottom
;
1495 HBRUSH hbr_border
= GetStockBrush(GRAY_BRUSH
); //CreateSolidBrush(RGB(71,88,85));
1496 FillRect(canvas
, &rect
, hbr_border
);
1497 //DeleteObject(hbr_border);
1500 super::Paint(canvas
);
1504 void StartMenuRoot::CloseStartMenu(int id
)
1509 ShowWindow(_hwnd
, SW_HIDE
);
1512 void StartMenuRoot::ProcessKey(int vk
)
1517 CloseOtherSubmenus();
1518 // don't close start menu root
1522 super::ProcessKey(vk
);
1527 int StartMenuHandler::Command(int id
, int code
)
1534 CreateSubmenu(id
, CSIDL_COMMON_PROGRAMS
, CSIDL_PROGRAMS
, ResString(IDS_PROGRAMS
));
1539 explorer_show_frame(_hwnd
, SW_SHOWNORMAL
);
1543 HWND hwndDesktopBar
= GetWindow(_hwnd
, GW_OWNER
);
1545 ShowLaunchDialog(hwndDesktopBar
);
1549 CreateSubmenu(id
, CSIDL_PERSONAL
, ResString(IDS_DOCUMENTS
));
1553 CreateSubmenu(id
, CSIDL_RECENT
, ResString(IDS_RECENT
), STARTMENU_CREATOR(RecentStartMenu
));
1557 CreateSubmenu(id
, CSIDL_FAVORITES
, ResString(IDS_FAVORITES
));
1561 CreateSubmenu(id
, ResString(IDS_BROWSE
), STARTMENU_CREATOR(BrowseMenu
));
1565 CreateSubmenu(id
, ResString(IDS_SETTINGS
), STARTMENU_CREATOR(SettingsMenu
));
1569 CreateSubmenu(id
, ResString(IDS_SEARCH
), STARTMENU_CREATOR(SearchMenu
));
1572 case IDC_START_HELP
: {
1573 HWND hwndDesktopBar
= GetWindow(_hwnd
, GW_OWNER
);
1575 MessageBox(hwndDesktopBar
, TEXT("Help not yet implemented"), ResString(IDS_TITLE
), MB_OK
);
1579 /* The shell32 Dialog prompts about some system setting change. This is not what we want to display here.
1580 HWND hwndDesktopBar = GetWindow(_hwnd, GW_OWNER);
1582 ShowRestartDialog(hwndDesktopBar, EWX_LOGOFF);*/
1583 DestroyWindow(GetParent(_hwnd
));
1586 case IDC_SHUTDOWN
: {
1587 HWND hwndDesktopBar
= GetWindow(_hwnd
, GW_OWNER
);
1589 ShowExitWindowsDialog(hwndDesktopBar
);
1595 case IDC_SETTINGS_MENU
:
1596 CreateSubmenu(id
, CSIDL_CONTROLS
, ResString(IDS_SETTINGS_MENU
));
1600 CreateSubmenu(id
, CSIDL_PRINTERS
, CSIDL_PRINTHOOD
, ResString(IDS_PRINTERS
));
1603 case IDC_CONTROL_PANEL
:
1605 MainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), FALSE
);
1609 CreateSubmenu(id
, CSIDL_COMMON_ADMINTOOLS
, CSIDL_ADMINTOOLS
, ResString(IDS_ADMIN
));
1612 case IDC_CONNECTIONS
:
1613 CreateSubmenu(id
, CSIDL_CONNECTIONS
, ResString(IDS_CONNECTIONS
));
1620 CreateSubmenu(id
, CSIDL_NETWORK
, ResString(IDS_NETWORK
));
1624 ///@todo exclude removeable drives
1625 CreateSubmenu(id
, CSIDL_DRIVES
, ResString(IDS_DRIVES
));
1631 case IDC_SEARCH_PROGRAM
:
1633 Dialog::DoModal(IDD_SEARCH_PROGRAM
, WINDOW_CREATOR(FindProgramDlg
));
1636 case IDC_SEARCH_FILES
:
1641 case IDC_SEARCH_COMPUTER
:
1643 ShowSearchComputer();
1648 return super::Command(id
, code
);
1655 void StartMenuHandler::ShowSearchDialog()
1657 static DynamicFct
<SHFINDFILES
> SHFindFiles(TEXT("SHELL32"), 90);
1660 (*SHFindFiles
)(NULL
, NULL
);
1662 MessageBox(0, TEXT("SHFindFiles() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1665 void StartMenuHandler::ShowSearchComputer()
1667 static DynamicFct
<SHFINDCOMPUTER
> SHFindComputer(TEXT("SHELL32"), 91);
1670 (*SHFindComputer
)(NULL
, NULL
);
1672 MessageBox(0, TEXT("SHFindComputer() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1675 void StartMenuHandler::ShowLaunchDialog(HWND hwndDesktopBar
)
1677 ///@todo All text phrases should be put into the resources.
1678 static LPCSTR szTitle
= "Create New Task";
1679 static LPCSTR szText
= "Type the name of a program, folder, document, or Internet resource, and Task Manager will open it for you.";
1681 static DynamicFct
<RUNFILEDLG
> RunFileDlg(TEXT("SHELL32"), 61);
1683 // Show "Run..." dialog
1686 if ((HIWORD(GetVersion())>>14) == W_VER_NT
) {
1687 WCHAR wTitle
[40], wText
[256];
1689 MultiByteToWideChar(CP_ACP
, 0, szTitle
, -1, wTitle
, 40);
1690 MultiByteToWideChar(CP_ACP
, 0, szText
, -1, wText
, 256);
1692 (*RunFileDlg
)(hwndDesktopBar
, 0, NULL
, (LPCSTR
)wTitle
, (LPCSTR
)wText
, RFF_CALCDIRECTORY
);
1695 (*RunFileDlg
)(hwndDesktopBar
, 0, NULL
, szTitle
, szText
, RFF_CALCDIRECTORY
);
1699 void StartMenuHandler::ShowRestartDialog(HWND hwndOwner
, UINT flags
)
1701 static DynamicFct
<RESTARTWINDOWSDLG
> RestartDlg(TEXT("SHELL32"), 59);
1704 (*RestartDlg
)(hwndOwner
, (LPWSTR
)L
"You selected <Log Off>.\n\n", flags
); ///@todo ANSI string conversion if needed
1706 MessageBox(hwndOwner
, TEXT("RestartDlg() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1709 void ShowExitWindowsDialog(HWND hwndOwner
)
1711 static DynamicFct
<EXITWINDOWSDLG
> ExitWindowsDlg(TEXT("SHELL32"), 60);
1714 (*ExitWindowsDlg
)(hwndOwner
);
1716 MessageBox(hwndOwner
, TEXT("ExitWindowsDlg() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1720 void SettingsMenu::AddEntries()
1722 super::AddEntries();
1724 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1725 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
1727 AddButton(ResString(IDS_CONTROL_PANEL
), ICID_CONFIG
, false, IDC_CONTROL_PANEL
);
1729 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, true, IDC_PRINTERS
);
1730 AddButton(ResString(IDS_CONNECTIONS
), ICID_NETWORK
, true, IDC_CONNECTIONS
);
1731 AddButton(ResString(IDS_ADMIN
), ICID_CONFIG
, true, IDC_ADMIN
);
1733 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1734 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
1736 AddButton(ResString(IDS_SETTINGS_MENU
), ICID_CONFIG
, true, IDC_SETTINGS_MENU
);
1739 void BrowseMenu::AddEntries()
1741 super::AddEntries();
1743 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1744 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NONETHOOD
)) // or REST_NOENTIRENETWORK ?
1746 AddButton(ResString(IDS_NETWORK
), ICID_NETWORK
, true, IDC_NETWORK
);
1748 AddButton(ResString(IDS_DRIVES
), ICID_FOLDER
, true, IDC_DRIVES
);
1751 void SearchMenu::AddEntries()
1753 super::AddEntries();
1755 AddButton(ResString(IDS_SEARCH_PRG
), ICID_APPS
, false, IDC_SEARCH_PROGRAM
);
1757 AddButton(ResString(IDS_SEARCH_FILES
), ICID_SEARCH_DOC
, false, IDC_SEARCH_FILES
);
1759 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1760 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_HASFINDCOMPUTERS
))
1762 AddButton(ResString(IDS_SEARCH_COMPUTER
), ICID_COMPUTER
, false, IDC_SEARCH_COMPUTER
);
1766 void RecentStartMenu::AddEntries()
1768 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
1769 StartMenuDirectory
& smd
= *it
;
1770 ShellDirectory
& dir
= smd
._dir
;
1772 if (!dir
._scanned
) {
1775 #ifdef _LAZY_ICONEXTRACT
1776 dir
.smart_scan(SCAN_FILESYSTEM
);
1778 dir
.smart_scan(SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
1782 dir
.sort_directory(SORT_DATE
);
1783 AddShellEntries(dir
, 16, smd
._subfolders
); ///@todo read max. count of entries from registry