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/searchprogram.h"
44 #include "../dialogs/settings.h"
47 StartMenu::StartMenu(HWND hwnd
)
50 _next_id
= IDC_FIRST_MENU
;
54 _last_pos
= WindowRect(hwnd
).pos();
55 #ifdef _LIGHT_STARTMENU
61 StartMenu::StartMenu(HWND hwnd
, const StartMenuCreateInfo
& create_info
)
63 _create_info(create_info
)
65 for(StartMenuFolders::const_iterator it
=create_info
._folders
.begin(); it
!=create_info
._folders
.end(); ++it
)
67 _dirs
.push_back(ShellDirectory(Desktop(), *it
, _hwnd
));
69 _next_id
= IDC_FIRST_MENU
;
72 _border_top
= create_info
._border_top
;
73 _last_pos
= WindowRect(hwnd
).pos();
74 #ifdef _LIGHT_STARTMENU
80 StartMenu::~StartMenu()
82 SendParent(PM_STARTMENU_CLOSED
);
86 // We need this wrapper function for s_wcStartMenu, it calls the WIN32 API,
87 // though static C++ initializers are not allowed for Winelib applications.
88 BtnWindowClass
& StartMenu::GetWndClasss()
90 static BtnWindowClass
s_wcStartMenu(CLASSNAME_STARTMENU
);
96 Window::CREATORFUNC_INFO
StartMenu::s_def_creator
= STARTMENU_CREATOR(StartMenu
);
98 HWND
StartMenu::Create(int x
, int y
, const StartMenuFolders
& folders
, HWND hwndParent
, LPCTSTR title
, CREATORFUNC_INFO creator
)
100 UINT style
, ex_style
;
104 style
= WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
;
106 top_height
= STARTMENU_TOP_BTN_SPACE
;
108 style
= WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|WS_CLIPCHILDREN
|WS_VISIBLE
;
109 ex_style
= WS_EX_TOOLWINDOW
;
113 RECT rect
= {x
, y
-STARTMENU_LINE_HEIGHT
-top_height
, x
+STARTMENU_WIDTH_MIN
, y
};
115 #ifndef _LIGHT_STARTMENU
116 rect
.top
+= STARTMENU_LINE_HEIGHT
;
119 AdjustWindowRectEx(&rect
, style
, FALSE
, ex_style
);
121 StartMenuCreateInfo create_info
;
123 create_info
._folders
= folders
;
124 create_info
._border_top
= top_height
;
125 create_info
._creator
= creator
;
128 create_info
._title
= title
;
130 HWND hwnd
= Window::Create(creator
, &create_info
, ex_style
, GetWndClasss(), title
,
131 style
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndParent
);
133 // make sure the window is not off the screen
140 LRESULT
StartMenu::Init(LPCREATESTRUCT pcs
)
145 if (super::Init(pcs
))
148 // create buttons for registered entries in _entries
149 for(ShellEntryMap::const_iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
150 const StartMenuEntry
& sme
= it
->second
;
151 bool hasSubmenu
= false;
153 for(ShellEntrySet::const_iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
)
154 if ((*it
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
157 #ifdef _LIGHT_STARTMENU
158 _buttons
.push_back(SMBtnInfo(sme
, it
->first
, hasSubmenu
));
160 AddButton(sme
._title
, sme
._hIcon
, hasSubmenu
, it
->first
);
164 #ifdef _LIGHT_STARTMENU
165 if (_buttons
.empty())
167 if (!GetWindow(_hwnd
, GW_CHILD
))
169 AddButton(ResString(IDS_EMPTY
), ICID_NONE
, false, 0, false);
171 #ifdef _LIGHT_STARTMENU
175 #ifdef _LAZY_ICONEXTRACT
176 PostMessage(_hwnd
, PM_UPDATE_ICONS
, 0, 0);
178 } catch(COMException
& e
) {
179 HandleException(e
, pcs
->hwndParent
); // destroys the start menu window while switching focus
185 void StartMenu::AddEntries()
187 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
188 StartMenuDirectory
& smd
= *it
;
189 ShellDirectory
& dir
= smd
._dir
;
194 #ifdef _LAZY_ICONEXTRACT
195 dir
.smart_scan(SCAN_FILESYSTEM
); // lazy icon extraction, try to read directly from filesystem
197 dir
.smart_scan(SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
201 AddShellEntries(dir
, -1, smd
._subfolders
);
206 void StartMenu::AddShellEntries(const ShellDirectory
& dir
, int max
, bool subfolders
)
210 for(Entry
*entry
=dir
._down
; entry
; entry
=entry
->_next
) {
211 // hide files like "desktop.ini"
212 if (entry
->_shell_attribs
& SFGAO_HIDDEN
)
213 //not appropriate for drive roots: if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
216 // hide subfolders if requested
218 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
221 // only 'max' entries shall be added.
225 if (entry
->_etype
== ET_SHELL
)
226 AddEntry(dir
._folder
, static_cast<ShellEntry
*>(entry
));
228 AddEntry(dir
._folder
, entry
);
233 LRESULT
StartMenu::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
237 PaintCanvas
canvas(_hwnd
);
242 ResizeButtons(LOWORD(lparam
)-_border_left
);
246 POINTS
& pos
= MAKEPOINTS(lparam
);
248 // move open submenus of floating menus
250 int dx
= pos
.x
- _last_pos
.x
;
251 int dy
= pos
.y
- _last_pos
.y
;
254 WindowRect
rt(_submenu
);
255 SetWindowPos(_submenu
, 0, rt
.left
+dx
, rt
.top
+dy
, 0, 0, SWP_NOSIZE
|SWP_NOACTIVATE
);
256 //MoveVisible(_submenu);
265 LRESULT res
= super::WndProc(nmsg
, wparam
, lparam
);
267 if (res
>=HTSIZEFIRST
&& res
<=HTSIZELAST
)
268 return HTCLIENT
; // disable window resizing
272 case WM_LBUTTONDOWN
: {
275 // check mouse cursor for coordinates of floating button
276 GetFloatingButtonRect(&rect
);
278 if (PtInRect(&rect
, Point(lparam
))) {
279 // create a floating copy of the current start menu
280 WindowRect
pos(_hwnd
);
282 ///@todo do something similar to StartMenuRoot::TrackStartmenu() in order to automatically close submenus when clicking on the desktop background
283 StartMenu::Create(pos
.left
+3, pos
.bottom
-3, _create_info
._folders
, 0, _create_info
._title
, _create_info
._creator
);
287 #ifdef _LIGHT_STARTMENU
288 int id
= ButtonHitTest(Point(lparam
));
291 Command(id
, BN_CLICKED
);
296 if ((wparam
&0xFFF0) == SC_SIZE
)
297 return 0; // disable window resizing
301 // close start menu when activating another application
304 break; // don't call super::WndProc in case "this" has been deleted
310 #ifdef _LIGHT_STARTMENU
312 // automatically set the focus to startmenu entries when moving the mouse over them
313 if (lparam
!= _last_mouse_pos
) { // don't process WM_MOUSEMOVE when opening submenus using keyboard navigation
314 int new_id
= ButtonHitTest(Point(lparam
));
316 if (new_id
!= _selected_id
)
317 SelectButton(new_id
);
319 _last_mouse_pos
= lparam
;
327 case PM_STARTENTRY_FOCUSED
: { ///@todo use TrackMouseEvent() and WM_MOUSEHOVER to wait a bit before opening submenus
328 BOOL hasSubmenu
= wparam
;
329 HWND hctrl
= (HWND
)lparam
;
331 // automatically open submenus
333 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
334 //SendMessage(_hwnd, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hctrl),BN_CLICKED), (LPARAM)hctrl);
335 Command(GetDlgCtrlID(hctrl
), BN_CLICKED
);
337 // close any open submenu
338 CloseOtherSubmenus();
343 #ifdef _LAZY_ICONEXTRACT
344 case PM_UPDATE_ICONS
:
345 UpdateIcons(/*wparam*/);
349 case PM_STARTENTRY_LAUNCHED
:
350 if (GetWindowStyle(_hwnd
) & WS_CAPTION
) // don't automatically close floating menus
353 // route message to the parent menu and close menus after launching an entry
354 if (!SendParent(nmsg
, wparam
, lparam
))
356 return 1; // signal that we have received and processed the message
358 case PM_STARTMENU_CLOSED
:
362 case PM_SELECT_ENTRY
:
363 SelectButtonIndex(0, wparam
?true:false);
367 return super::WndProc(nmsg
, wparam
, lparam
);
374 #ifdef _LIGHT_STARTMENU
376 int StartMenu::ButtonHitTest(POINT pt
)
378 ClientRect
clnt(_hwnd
);
379 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
381 if (pt
.x
<rect
.left
|| pt
.x
>rect
.right
)
384 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
385 const SMBtnInfo
& info
= *it
;
390 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
392 if (pt
.y
< rect
.bottom
) // PtInRect(&rect, pt)
395 rect
.top
= rect
.bottom
;
401 void StartMenu::InvalidateSelection()
406 ClientRect
clnt(_hwnd
);
407 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
409 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
410 const SMBtnInfo
& info
= *it
;
412 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
414 if (info
._id
== _selected_id
) {
415 InvalidateRect(_hwnd
, &rect
, TRUE
);
419 rect
.top
= rect
.bottom
;
423 const SMBtnInfo
* StartMenu::GetButtonInfo(int id
) const
425 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
)
432 bool StartMenu::SelectButton(int id
, bool open_sub
)
437 if (id
== _selected_id
)
440 InvalidateSelection();
442 const SMBtnInfo
* btn
= GetButtonInfo(id
);
444 if (btn
&& btn
->_enabled
) {
447 InvalidateSelection();
449 // automatically open submenus
450 if (btn
->_hasSubmenu
) {
454 CloseOtherSubmenus(); // close any open submenu
463 bool StartMenu::OpenSubmenu(bool select_first
)
465 if (_selected_id
== -1)
468 InvalidateSelection();
470 const SMBtnInfo
* btn
= GetButtonInfo(_selected_id
);
472 // automatically open submenus
473 if (btn
->_hasSubmenu
) {
474 //@@ allows destroying of startmenu when processing PM_UPDATE_ICONS -> GPF
475 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
476 Command(_selected_id
, BN_CLICKED
);
478 if (select_first
&& _submenu
)
479 SendMessage(_submenu
, PM_SELECT_ENTRY
, (WPARAM
)false, 0);
487 int StartMenu::GetSelectionIndex()
489 if (_selected_id
== -1)
492 for(int i
=0; i
<(int)_buttons
.size(); ++i
)
493 if (_buttons
[i
]._id
== _selected_id
)
499 bool StartMenu::SelectButtonIndex(int idx
, bool open_sub
)
501 if (idx
>=0 && idx
<(int)_buttons
.size())
502 return SelectButton(_buttons
[idx
]._id
, open_sub
);
507 void StartMenu::ProcessKey(int vk
)
512 Command(_selected_id
, BN_CLICKED
);
524 SelectButtonIndex(0, false);
528 SelectButtonIndex(_buttons
.size()-1, false);
533 CloseOtherSubmenus();
534 else if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) // don't automatically close floating menus
535 DestroyWindow(_hwnd
);
548 bool StartMenu::Navigate(int step
)
550 int idx
= GetSelectionIndex();
556 idx
= _buttons
.size() - step
;
561 if (idx
<0 || idx
>(int)_buttons
.size())
564 if (SelectButtonIndex(idx
, false))
571 #endif // _LIGHT_STARTMENU
574 bool StartMenu::GetButtonRect(int id
, PRECT prect
) const
576 #ifdef _LIGHT_STARTMENU
577 ClientRect
clnt(_hwnd
);
578 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
580 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
581 const SMBtnInfo
& info
= *it
;
583 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
585 if (info
._id
== id
) {
590 rect
.top
= rect
.bottom
;
595 HWND btn
= GetDlgItem(_hwnd
, id
);
598 GetWindowRect(btn
, prect
);
599 ScreenToClient(_hwnd
, prect
);
608 void StartMenu::DrawFloatingButton(HDC hdc
)
610 static ResIconEx
floatingIcon(IDI_FLOATING
, 8, 4);
612 ClientRect
clnt(_hwnd
);
614 DrawIconEx(hdc
, clnt
.right
-12, 0, floatingIcon
, 8, 4, 0, 0, DI_NORMAL
);
617 void StartMenu::GetFloatingButtonRect(LPRECT prect
)
619 GetClientRect(_hwnd
, prect
);
622 prect
->left
= prect
->right
- 8;
627 void StartMenu::Paint(PaintCanvas
& canvas
)
630 DrawFloatingButton(canvas
);
632 #ifdef _LIGHT_STARTMENU
633 ClientRect
clnt(_hwnd
);
634 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
636 int sep_width
= rect
.right
-rect
.left
- 4;
638 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
639 BkMode
bk_mode(canvas
, TRANSPARENT
);
641 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
642 const SMBtnInfo
& btn
= *it
;
644 if (rect
.top
> canvas
.rcPaint
.bottom
)
647 if (btn
._id
== -1) { // a separator?
648 rect
.bottom
= rect
.top
+ STARTMENU_SEP_HEIGHT
;
650 BrushSelection
brush_sel(canvas
, GetSysColorBrush(COLOR_BTNSHADOW
));
651 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2-1, sep_width
, 1, PATCOPY
);
653 SelectBrush(canvas
, GetSysColorBrush(COLOR_BTNHIGHLIGHT
));
654 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2, sep_width
, 1, PATCOPY
);
656 rect
.bottom
= rect
.top
+ STARTMENU_LINE_HEIGHT
;
658 if (rect
.top
>= canvas
.rcPaint
.top
)
659 DrawStartMenuButton(canvas
, rect
, btn
._title
, btn
, btn
._id
==_selected_id
, false);
662 rect
.top
= rect
.bottom
;
667 #ifdef _LAZY_ICONEXTRACT
668 void StartMenu::UpdateIcons(/*int idx*/)
672 #ifdef _SINGLE_ICONEXTRACT
677 for(; idx
<(int)_buttons
.size(); ++idx
) {
678 SMBtnInfo
& btn
= _buttons
[idx
];
680 if (btn
._icon_id
==ICID_UNKNOWN
&& btn
._id
>0) {
681 StartMenuEntry
& sme
= _entries
[btn
._id
];
683 btn
._icon_id
= ICID_NONE
;
685 for(ShellEntrySet::iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
) {
688 if (entry
->_icon_id
== ICID_UNKNOWN
)
689 entry
->extract_icon();
691 if (entry
->_icon_id
> ICID_NONE
) {
692 btn
._icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
696 GetButtonRect(btn
._id
, &rect
);
697 WindowCanvas
canvas(_hwnd
);
698 DrawStartMenuButton(canvas
, rect
, NULL
, btn
, btn
._id
==_selected_id
, false);
700 //InvalidateRect(_hwnd, &rect, FALSE);
701 //UpdateWindow(_hwnd);
710 // if (++idx < (int)_buttons.size())
711 // PostMessage(_hwnd, PM_UPDATE_ICONS, idx, 0);
715 int icons_extracted
= 0;
716 int icons_updated
= 0;
718 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
719 ShellDirectory
& dir
= it
->_dir
;
721 icons_extracted
+= dir
.extract_icons();
724 if (icons_extracted
) {
725 for(ShellEntryMap::iterator it1
=_entries
.begin(); it1
!=_entries
.end(); ++it1
) {
726 StartMenuEntry
& sme
= it1
->second
;
729 sme
._hIcon
= (HICON
)-1;
731 for(ShellEntrySet::const_iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
732 const Entry
* sm_entry
= *it2
;
734 if (sm_entry
->_hIcon
) {
735 sme
._hIcon
= sm_entry
->_hIcon
;
742 for(SMBtnVector::iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
743 SMBtnInfo
& info
= *it
;
745 if (info
._id
>0 && !info
._hIcon
) {
746 info
._hIcon
= _entries
[info
._id
]._hIcon
;
753 InvalidateRect(_hwnd
, NULL
, FALSE
);
761 // resize child button controls to accomodate for new window size
762 void StartMenu::ResizeButtons(int cx
)
764 HDWP hdwp
= BeginDeferWindowPos(10);
766 for(HWND ctrl
=GetWindow(_hwnd
,GW_CHILD
); ctrl
; ctrl
=GetNextWindow(ctrl
,GW_HWNDNEXT
)) {
769 if (rt
.right
!= cx
) {
770 int height
= rt
.bottom
- rt
.top
;
772 // special handling for separator controls
773 if (!height
&& (GetWindowStyle(ctrl
)&SS_TYPEMASK
)==SS_ETCHEDHORZ
)
776 hdwp
= DeferWindowPos(hdwp
, ctrl
, 0, 0, 0, cx
, height
, SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
);
780 EndDeferWindowPos(hdwp
);
784 int StartMenu::Command(int id
, int code
)
786 #ifndef _LIGHT_STARTMENU
794 ShellEntryMap::iterator found
= _entries
.find(id
);
796 if (found
!= _entries
.end()) {
797 ActivateEntry(id
, found
->second
._entries
);
801 return super::Command(id
, code
);
802 #ifndef _LIGHT_STARTMENU
811 StartMenuEntry
& StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, Entry
* entry
)
813 // search for an already existing subdirectory entry with the same name
814 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
815 for(ShellEntryMap::iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
816 StartMenuEntry
& sme
= it
->second
;
818 if (sme
._title
== title
) ///@todo speed up by using a map indexed by name
819 for(ShellEntrySet::iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
820 if ((*it2
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
821 // merge the new shell entry with the existing of the same name
822 sme
._entries
.insert(entry
);
828 StartMenuEntry
& sme
= AddEntry(title
, icon_id
);
830 sme
._entries
.insert(entry
);
835 StartMenuEntry
& StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, int id
)
840 StartMenuEntry
& sme
= _entries
[id
];
843 sme
._icon_id
= icon_id
;
848 StartMenuEntry
& StartMenu::AddEntry(const ShellFolder folder
, ShellEntry
* entry
)
852 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
853 icon_id
= ICID_FOLDER
;
855 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
857 return AddEntry(folder
.get_name(entry
->_pidl
), icon_id
, entry
);
860 StartMenuEntry
& StartMenu::AddEntry(const ShellFolder folder
, Entry
* entry
)
864 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
865 icon_id
= ICID_FOLDER
;
867 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
869 return AddEntry(entry
->_display_name
, icon_id
, entry
);
873 void StartMenu::AddButton(LPCTSTR title
, ICON_ID icon_id
, bool hasSubmenu
, int id
, bool enabled
)
875 #ifdef _LIGHT_STARTMENU
876 _buttons
.push_back(SMBtnInfo(title
, icon_id
, id
, hasSubmenu
, enabled
));
878 DWORD style
= enabled
? WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
: WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
|WS_DISABLED
;
880 WindowRect
rect(_hwnd
);
881 ClientRect
clnt(_hwnd
);
883 // increase window height to make room for the new button
884 rect
.top
-= STARTMENU_LINE_HEIGHT
;
886 // move down if we are too high now
888 rect
.top
+= STARTMENU_LINE_HEIGHT
;
889 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
892 WindowCanvas
canvas(_hwnd
);
893 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
895 // widen window, if it is too small
896 int text_width
= GetStartMenuBtnTextWidth(canvas
, title
, _hwnd
) + 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
898 int cx
= clnt
.right
- _border_left
;
900 rect
.right
+= text_width
-cx
;
902 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
904 StartMenuCtrl(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
,
905 title
, id
, g_Globals
._icon_cache
.get_icon(icon_id
)._hIcon
, hasSubmenu
, style
);
909 void StartMenu::AddSeparator()
911 #ifdef _LIGHT_STARTMENU
912 _buttons
.push_back(SMBtnInfo(NULL
, ICID_NONE
, -1, false));
914 WindowRect
rect(_hwnd
);
915 ClientRect
clnt(_hwnd
);
917 // increase window height to make room for the new separator
918 rect
.top
-= STARTMENU_SEP_HEIGHT
;
920 // move down if we are too high now
922 rect
.top
+= STARTMENU_LINE_HEIGHT
;
923 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
926 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
928 StartMenuSeparator(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
);
933 bool StartMenu::CloseOtherSubmenus(int id
)
936 if (IsWindow(_submenu
)) {
937 if (_submenu_id
== id
)
941 DestroyWindow(_submenu
);
942 // _submenu should be reset automatically by PM_STARTMENU_CLOSED, but safety first...
953 void StartMenu::CreateSubmenu(int id
, LPCTSTR title
, CREATORFUNC_INFO creator
)
955 CreateSubmenu(id
, StartMenuFolders(), title
, creator
);
958 void StartMenu::CreateSubmenu(int id
, int folder_id
, LPCTSTR title
, CREATORFUNC_INFO creator
)
961 SpecialFolderPath
folder(folder_id
, _hwnd
);
963 StartMenuFolders new_folders
;
964 new_folders
.push_back(folder
);
966 CreateSubmenu(id
, new_folders
, title
, creator
);
967 } catch(COMException
&) {
968 // ignore Exception and don't display anything
972 void StartMenu::CreateSubmenu(int id
, int folder_id1
, int folder_id2
, LPCTSTR title
, CREATORFUNC_INFO creator
)
974 StartMenuFolders new_folders
;
977 new_folders
.push_back(SpecialFolderPath(folder_id1
, _hwnd
));
978 } catch(COMException
&) {
982 new_folders
.push_back(SpecialFolderPath(folder_id2
, _hwnd
));
983 } catch(COMException
&) {
986 if (!new_folders
.empty())
987 CreateSubmenu(id
, new_folders
, title
, creator
);
990 void StartMenu::CreateSubmenu(int id
, const StartMenuFolders
& new_folders
, LPCTSTR title
, CREATORFUNC_INFO creator
)
992 // Only open one submenu at a time.
993 if (!CloseOtherSubmenus(id
))
999 if (GetButtonRect(id
, &rect
)) {
1000 ClientToScreen(_hwnd
, &rect
);
1002 x
= rect
.right
; // Submenus should overlap their parent a bit.
1003 y
= rect
.top
+STARTMENU_LINE_HEIGHT
-_border_top
;
1005 WindowRect
pos(_hwnd
);
1012 _submenu
= StartMenu::Create(x
, y
, new_folders
, _hwnd
, title
, creator
);
1016 void StartMenu::ActivateEntry(int id
, const ShellEntrySet
& entries
)
1018 StartMenuFolders new_folders
;
1021 for(ShellEntrySet::const_iterator it
=entries
.begin(); it
!=entries
.end(); ++it
) {
1022 Entry
* entry
= const_cast<Entry
*>(*it
);
1024 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1026 ///@todo If the user explicitly clicked on a submenu, display this folder as floating start menu.
1028 if (entry
->_etype
== ET_SHELL
)
1029 new_folders
.push_back(entry
->create_absolute_pidl());
1031 TCHAR path
[MAX_PATH
];
1033 if (entry
->get_path(path
))
1034 new_folders
.push_back(path
);
1038 title
= entry
->_display_name
;
1040 // If the entry is no subdirectory, there can only be one shell entry.
1041 assert(entries
.size()==1);
1043 HWND hparent
= GetParent(_hwnd
);
1044 ShellPath shell_path
= entry
->create_absolute_pidl();
1046 // close start menus after launching the selected entry
1049 ///@todo launch in the background; specify correct HWND for error message box titles
1050 SHELLEXECUTEINFO shexinfo
;
1052 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
1053 shexinfo
.fMask
= SEE_MASK_INVOKEIDLIST
; // SEE_MASK_IDLIST is also possible.
1054 shexinfo
.hwnd
= hparent
;
1055 shexinfo
.lpVerb
= NULL
;
1056 shexinfo
.lpFile
= NULL
;
1057 shexinfo
.lpParameters
= NULL
;
1058 shexinfo
.lpDirectory
= NULL
;
1059 shexinfo
.nShow
= SW_SHOWNORMAL
;
1061 shexinfo
.lpIDList
= &*shell_path
;
1063 if (!ShellExecuteEx(&shexinfo
))
1064 display_error(hparent
, GetLastError());
1066 // we may have deleted 'this' - ensure we leave the loop and function
1071 if (!new_folders
.empty()) {
1072 // Only open one submenu at a time.
1073 if (!CloseOtherSubmenus(id
))
1076 CreateSubmenu(id
, new_folders
, title
);
1081 /// close all windows of the start menu popup
1082 void StartMenu::CloseStartMenu(int id
)
1084 if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) { // don't automatically close floating menus
1085 if (!SendParent(PM_STARTENTRY_LAUNCHED
, id
, (LPARAM
)_hwnd
))
1086 DestroyWindow(_hwnd
);
1087 } else if (_submenu
) // instead close submenus of floating parent menus
1092 int GetStartMenuBtnTextWidth(HDC hdc
, LPCTSTR title
, HWND hwnd
)
1094 RECT rect
= {0, 0, 0, 0};
1095 DrawText(hdc
, title
, -1, &rect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_CALCRECT
);
1097 return rect
.right
-rect
.left
;
1100 #ifdef _LIGHT_STARTMENU
1101 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, const SMBtnInfo
& btn
, bool has_focus
, bool pushed
)
1103 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, HICON hIcon
,
1104 bool hasSubmenu
, bool enabled
, bool has_focus
, bool pushed
);
1107 UINT style
= DFCS_BUTTONPUSH
;
1110 style
|= DFCS_INACTIVE
;
1112 POINT iconPos
= {rect
.left
+2, (rect
.top
+rect
.bottom
-16)/2};
1113 RECT textRect
= {rect
.left
+16+4, rect
.top
+2, rect
.right
-4, rect
.bottom
-4};
1116 style
|= DFCS_PUSHED
;
1117 ++iconPos
.x
; ++iconPos
.y
;
1118 ++textRect
.left
; ++textRect
.top
;
1119 ++textRect
.right
; ++textRect
.bottom
;
1122 int bk_color_idx
= COLOR_BTNFACE
;
1123 int text_color_idx
= COLOR_BTNTEXT
;
1126 bk_color_idx
= COLOR_HIGHLIGHT
;
1127 text_color_idx
= COLOR_HIGHLIGHTTEXT
;
1130 COLORREF bk_color
= GetSysColor(bk_color_idx
);
1131 HBRUSH bk_brush
= GetSysColorBrush(bk_color_idx
);
1134 FillRect(hdc
, &rect
, bk_brush
);
1136 if (btn
._icon_id
> ICID_NONE
)
1137 g_Globals
._icon_cache
.get_icon(btn
._icon_id
).draw(hdc
, iconPos
.x
, iconPos
.y
, 16, 16, bk_color
, bk_brush
);
1139 // draw submenu arrow at the right
1140 if (btn
._hasSubmenu
) {
1141 static SmallIcon
arrowIcon(IDI_ARROW
);
1142 static SmallIcon
selArrowIcon(IDI_ARROW_SELECTED
);
1144 DrawIconEx(hdc
, rect
.right
-16, iconPos
.y
,
1145 has_focus
? selArrowIcon
: arrowIcon
,
1146 16, 16, 0, bk_brush
, DI_NORMAL
);
1150 BkMode
bk_mode(hdc
, TRANSPARENT
);
1152 if (!btn
._enabled
) // dis->itemState & (ODS_DISABLED|ODS_GRAYED)
1153 DrawGrayText(hdc
, &textRect
, title
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1155 TextColor
lcColor(hdc
, GetSysColor(text_color_idx
));
1156 DrawText(hdc
, title
, -1, &textRect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1162 #ifdef _LIGHT_STARTMENU
1164 void StartMenu::ResizeToButtons()
1166 WindowRect
rect(_hwnd
);
1168 WindowCanvas
canvas(_hwnd
);
1169 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1171 int max_width
= STARTMENU_WIDTH_MIN
;
1174 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
1175 int w
= GetStartMenuBtnTextWidth(canvas
, it
->_title
, _hwnd
);
1181 height
+= STARTMENU_SEP_HEIGHT
;
1183 height
+= STARTMENU_LINE_HEIGHT
;
1186 // calculate new window size
1187 int text_width
= max_width
+ 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1189 RECT rt_hgt
= {rect
.left
, rect
.bottom
-_border_top
-height
, rect
.left
+_border_left
+text_width
, rect
.bottom
};
1190 AdjustWindowRectEx(&rt_hgt
, GetWindowStyle(_hwnd
), FALSE
, GetWindowExStyle(_hwnd
));
1192 // ignore movement, only look at the size change
1193 rect
.right
= rect
.left
+ (rt_hgt
.right
-rt_hgt
.left
);
1194 rect
.top
= rect
.bottom
- (rt_hgt
.bottom
-rt_hgt
.top
);
1196 // move down if we are too high
1198 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1199 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1202 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1205 #else // _LIGHT_STARTMENU
1207 LRESULT
StartMenuButton::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1211 // automatically set the focus to startmenu entries when moving the mouse over them
1212 if (GetFocus()!=_hwnd
&& !(GetWindowStyle(_hwnd
)&WS_DISABLED
))
1217 PostParent(PM_STARTENTRY_FOCUSED
, _hasSubmenu
, (LPARAM
)_hwnd
);
1221 // route WM_CANCELMODE to the startmenu window
1222 return SendParent(nmsg
, wparam
, lparam
);
1225 return super::WndProc(nmsg
, wparam
, lparam
);
1231 void StartMenuButton::DrawItem(LPDRAWITEMSTRUCT dis
)
1233 TCHAR title
[BUFFER_LEN
];
1235 GetWindowText(_hwnd
, title
, BUFFER_LEN
);
1237 DrawStartMenuButton(dis
->hDC
, dis
->rcItem
, title
, _hIcon
,
1239 !(dis
->itemState
& ODS_DISABLED
),
1240 dis
->itemState
&ODS_FOCUS
? true: false,
1241 dis
->itemState
&ODS_SELECTED
? true: false);
1247 StartMenuRoot::StartMenuRoot(HWND hwnd
)
1250 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1251 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCOMMONGROUPS
))
1254 // insert directory "All Users\Start Menu"
1255 ShellDirectory
cmn_startmenu(Desktop(), SpecialFolderPath(CSIDL_COMMON_STARTMENU
, _hwnd
), _hwnd
);
1256 _dirs
.push_back(StartMenuDirectory(cmn_startmenu
, false)); // don't add subfolders
1257 } catch(COMException
&) {
1258 // ignore exception and don't show additional shortcuts
1262 // insert directory "<user name>\Start Menu"
1263 ShellDirectory
usr_startmenu(Desktop(), SpecialFolderPath(CSIDL_STARTMENU
, _hwnd
), _hwnd
);
1264 _dirs
.push_back(StartMenuDirectory(usr_startmenu
, false)); // don't add subfolders
1265 } catch(COMException
&) {
1266 // ignore exception and don't show additional shortcuts
1269 // read size of logo bitmap
1271 GetObject(ResBitmap(IDB_LOGOV
), sizeof(BITMAP
), &bmp_hdr
);
1272 _logo_size
.cx
= bmp_hdr
.bmWidth
;
1273 _logo_size
.cy
= bmp_hdr
.bmHeight
;
1275 _border_left
= _logo_size
.cx
;
1279 HWND
StartMenuRoot::Create(HWND hwndOwner
)
1281 WindowRect
pos(hwndOwner
);
1283 RECT rect
= {pos
.left
, pos
.top
-STARTMENU_LINE_HEIGHT
-4, pos
.left
+STARTMENU_WIDTH_MIN
, pos
.top
};
1285 #ifndef _LIGHT_STARTMENU
1286 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1289 AdjustWindowRectEx(&rect
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
, FALSE
, 0);
1291 return Window::Create(WINDOW_CREATOR(StartMenuRoot
), 0, GetWndClasss(), TITLE_STARTMENU
,
1292 WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
,
1293 rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndOwner
);
1297 void StartMenuRoot::TrackStartmenu()
1302 #ifdef _LIGHT_STARTMENU
1306 // show previously hidden start menu
1307 ShowWindow(hwnd
, SW_SHOW
);
1309 while(IsWindow(hwnd
)) {
1310 if (!GetMessage(&msg
, 0, 0, 0)) {
1311 PostQuitMessage(msg
.wParam
);
1315 // Check for a mouse click on any window, which is not part of the start menu
1316 if (msg
.message
==WM_LBUTTONDOWN
|| msg
.message
==WM_MBUTTONDOWN
|| msg
.message
==WM_RBUTTONDOWN
) {
1317 StartMenu
* menu_wnd
= NULL
;
1319 for(HWND hwnd
=msg
.hwnd
; hwnd
; hwnd
=GetParent(hwnd
)) {
1320 menu_wnd
= WINDOW_DYNAMIC_CAST(StartMenu
, hwnd
);
1333 if (pretranslate_msg(&msg
))
1336 if (dispatch_dialog_msg(&msg
))
1339 TranslateMessage(&msg
);
1342 DispatchMessage(&msg
);
1343 } catch(COMException
& e
) {
1344 HandleException(e
, _hwnd
);
1346 } catch(COMException
& e
) {
1347 HandleException(e
, _hwnd
);
1353 LRESULT
StartMenuRoot::Init(LPCREATESTRUCT pcs
)
1355 // add buttons for entries in _entries
1356 if (super::Init(pcs
))
1366 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"), &hkey
))
1369 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), &hkeyAdv
))
1372 #define IS_VALUE_ZERO(hk, name) \
1373 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || !value))
1375 #define IS_VALUE_NOT_ZERO(hk, name) \
1376 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || value>0))
1380 // insert hard coded start entries
1381 AddButton(ResString(IDS_PROGRAMS
), ICID_APPS
, true, IDC_PROGRAMS
);
1383 AddButton(ResString(IDS_DOCUMENTS
), ICID_DOCUMENTS
, true, IDC_DOCUMENTS
);
1385 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1386 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORECENTDOCSMENU
))
1388 if (IS_VALUE_ZERO(hkey
, _T("NoRecentDocsMenu")))
1390 AddButton(ResString(IDS_RECENT
), ICID_DOCUMENTS
, true, IDC_RECENT
);
1392 AddButton(ResString(IDS_FAVORITES
), ICID_FAVORITES
, true, IDC_FAVORITES
);
1394 AddButton(ResString(IDS_SETTINGS
), ICID_CONFIG
, true, IDC_SETTINGS
);
1396 AddButton(ResString(IDS_BROWSE
), ICID_FOLDER
, true, IDC_BROWSE
);
1398 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1399 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOFIND
))
1401 if (IS_VALUE_ZERO(hkey
, _T("NoFind")))
1403 AddButton(ResString(IDS_SEARCH
), ICID_SEARCH
, true, IDC_SEARCH
);
1405 AddButton(ResString(IDS_START_HELP
), ICID_INFO
, false, IDC_START_HELP
);
1407 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1408 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORUN
))
1410 if (IS_VALUE_ZERO(hkey
, _T("NoRun")))
1412 AddButton(ResString(IDS_LAUNCH
), ICID_ACTION
, false, IDC_LAUNCH
);
1418 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1419 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCLOSE
))
1421 if (IS_VALUE_NOT_ZERO(hkeyAdv
, _T("StartMenuLogoff")))
1423 AddButton(ResString(IDS_LOGOFF
), ICID_LOGOFF
, false, IDC_LOGOFF
);
1426 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1427 if (!g_Globals
._SHRestricted
|| SHRestricted(REST_STARTMENULOGOFF
) != 1)
1429 if (IS_VALUE_ZERO(hkey
, _T("NoClose")))
1431 AddButton(ResString(IDS_SHUTDOWN
), ICID_LOGOFF
, false, IDC_SHUTDOWN
);
1435 RegCloseKey(hkeyAdv
);
1440 #ifdef _LIGHT_STARTMENU
1441 // set the window size to fit all buttons
1449 void StartMenuRoot::AddEntries()
1451 super::AddEntries();
1453 AddButton(ResString(IDS_EXPLORE
), ICID_EXPLORER
, false, IDC_EXPLORE
);
1457 LRESULT
StartMenuRoot::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1461 PaintCanvas
canvas(_hwnd
);
1466 return super::WndProc(nmsg
, wparam
, lparam
);
1472 void StartMenuRoot::Paint(PaintCanvas
& canvas
)
1475 {WindowCanvas
dc(_hwnd
); clr_bits
=GetDeviceCaps(dc
, BITSPIXEL
);}
1476 bool logo256
= clr_bits
<=8;
1479 ResBitmap
bmp(logo256
? IDB_LOGOV256
: IDB_LOGOV
);
1480 BitmapSelection
sel(mem_dc
, bmp
);
1482 ClientRect
clnt(_hwnd
);
1483 int h
= min(_logo_size
.cy
, clnt
.bottom
);
1485 RECT rect
= {0, 0, _logo_size
.cx
-1, clnt
.bottom
-h
};
1486 HBRUSH hbr
= CreateSolidBrush(logo256
? RGB(166,202,240): RGB(255,255,255)); // same color as the background color in the logo bitmap
1487 FillRect(canvas
, &rect
, hbr
);
1489 //PatBlt(canvas, _logo_size.cx-1, 0, 1, clnt.bottom-h, WHITENESS);
1490 PatBlt(canvas
, _logo_size
.cx
-1, 0, 1, clnt
.bottom
-h
, WHITENESS
);
1492 BitBlt(canvas
, 0, clnt
.bottom
-h
, _logo_size
.cx
, h
, mem_dc
, 0, 0, SRCCOPY
);
1495 rect
.left
= rect
.right
++;
1496 rect
.bottom
= clnt
.bottom
;
1497 HBRUSH hbr_border
= GetStockBrush(GRAY_BRUSH
); //CreateSolidBrush(RGB(71,88,85));
1498 FillRect(canvas
, &rect
, hbr_border
);
1499 //DeleteObject(hbr_border);
1502 super::Paint(canvas
);
1506 void StartMenuRoot::CloseStartMenu(int id
)
1511 ShowWindow(_hwnd
, SW_HIDE
);
1514 void StartMenuRoot::ProcessKey(int vk
)
1519 CloseOtherSubmenus();
1520 // don't close start menu root
1524 super::ProcessKey(vk
);
1529 int StartMenuHandler::Command(int id
, int code
)
1536 CreateSubmenu(id
, CSIDL_COMMON_PROGRAMS
, CSIDL_PROGRAMS
, ResString(IDS_PROGRAMS
));
1541 explorer_show_frame(_hwnd
, SW_SHOWNORMAL
);
1546 ShowLaunchDialog(g_Globals
._hwndDesktopBar
);
1550 CreateSubmenu(id
, CSIDL_PERSONAL
, ResString(IDS_DOCUMENTS
));
1554 CreateSubmenu(id
, CSIDL_RECENT
, ResString(IDS_RECENT
), STARTMENU_CREATOR(RecentStartMenu
));
1558 CreateSubmenu(id
, CSIDL_FAVORITES
, ResString(IDS_FAVORITES
));
1562 CreateSubmenu(id
, ResString(IDS_BROWSE
), STARTMENU_CREATOR(BrowseMenu
));
1566 CreateSubmenu(id
, ResString(IDS_SETTINGS
), STARTMENU_CREATOR(SettingsMenu
));
1570 CreateSubmenu(id
, ResString(IDS_SEARCH
), STARTMENU_CREATOR(SearchMenu
));
1573 case IDC_START_HELP
:
1575 MessageBox(g_Globals
._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.
1581 ShowRestartDialog(g_Globals._hwndDesktopBar, EWX_LOGOFF);*/
1582 DestroyWindow(GetParent(_hwnd
));
1587 ShowExitWindowsDialog(g_Globals
._hwndDesktopBar
);
1593 case ID_DESKTOPBAR_SETTINGS
:
1595 ExplorerPropertySheet(g_Globals
._hwndDesktopBar
);
1598 case IDC_SETTINGS_MENU
:
1599 CreateSubmenu(id
, CSIDL_CONTROLS
, ResString(IDS_SETTINGS_MENU
));
1603 CreateSubmenu(id
, CSIDL_PRINTERS
, CSIDL_PRINTHOOD
, ResString(IDS_PRINTERS
));
1606 case IDC_CONTROL_PANEL
:
1608 MainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), FALSE
);
1612 CreateSubmenu(id
, CSIDL_COMMON_ADMINTOOLS
, CSIDL_ADMINTOOLS
, ResString(IDS_ADMIN
));
1615 case IDC_CONNECTIONS
:
1616 CreateSubmenu(id
, CSIDL_CONNECTIONS
, ResString(IDS_CONNECTIONS
));
1623 CreateSubmenu(id
, CSIDL_NETWORK
, ResString(IDS_NETWORK
));
1627 ///@todo exclude removeable drives
1628 CreateSubmenu(id
, CSIDL_DRIVES
, ResString(IDS_DRIVES
));
1634 case IDC_SEARCH_PROGRAM
:
1636 Dialog::DoModal(IDD_SEARCH_PROGRAM
, WINDOW_CREATOR(FindProgramDlg
));
1639 case IDC_SEARCH_FILES
:
1644 case IDC_SEARCH_COMPUTER
:
1646 ShowSearchComputer();
1651 return super::Command(id
, code
);
1658 void StartMenuHandler::ShowSearchDialog()
1660 static DynamicFct
<SHFINDFILES
> SHFindFiles(TEXT("SHELL32"), 90);
1663 (*SHFindFiles
)(NULL
, NULL
);
1665 MessageBox(0, TEXT("SHFindFiles() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1668 void StartMenuHandler::ShowSearchComputer()
1670 static DynamicFct
<SHFINDCOMPUTER
> SHFindComputer(TEXT("SHELL32"), 91);
1673 (*SHFindComputer
)(NULL
, NULL
);
1675 MessageBox(0, TEXT("SHFindComputer() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1678 void StartMenuHandler::ShowLaunchDialog(HWND hwndOwner
)
1680 ///@todo All text phrases should be put into the resources.
1681 static LPCSTR szTitle
= "Create New Task";
1682 static LPCSTR szText
= "Type the name of a program, folder, document, or Internet resource, and Task Manager will open it for you.";
1684 static DynamicFct
<RUNFILEDLG
> RunFileDlg(TEXT("SHELL32"), 61);
1686 // Show "Run..." dialog
1689 if ((HIWORD(GetVersion())>>14) == W_VER_NT
) {
1690 WCHAR wTitle
[40], wText
[256];
1692 MultiByteToWideChar(CP_ACP
, 0, szTitle
, -1, wTitle
, 40);
1693 MultiByteToWideChar(CP_ACP
, 0, szText
, -1, wText
, 256);
1695 (*RunFileDlg
)(hwndOwner
, 0, NULL
, (LPCSTR
)wTitle
, (LPCSTR
)wText
, RFF_CALCDIRECTORY
);
1698 (*RunFileDlg
)(hwndOwner
, 0, NULL
, szTitle
, szText
, RFF_CALCDIRECTORY
);
1702 void StartMenuHandler::ShowRestartDialog(HWND hwndOwner
, UINT flags
)
1704 static DynamicFct
<RESTARTWINDOWSDLG
> RestartDlg(TEXT("SHELL32"), 59);
1707 (*RestartDlg
)(hwndOwner
, (LPWSTR
)L
"You selected <Log Off>.\n\n", flags
); ///@todo ANSI string conversion if needed
1709 MessageBox(hwndOwner
, TEXT("RestartDlg() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1712 void ShowExitWindowsDialog(HWND hwndOwner
)
1714 static DynamicFct
<EXITWINDOWSDLG
> ExitWindowsDlg(TEXT("SHELL32"), 60);
1717 (*ExitWindowsDlg
)(hwndOwner
);
1719 MessageBox(hwndOwner
, TEXT("ExitWindowsDlg() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1723 void SettingsMenu::AddEntries()
1725 super::AddEntries();
1727 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1728 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
1730 AddButton(ResString(IDS_CONTROL_PANEL
), ICID_CONFIG
, false, IDC_CONTROL_PANEL
);
1732 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, true, IDC_PRINTERS
);
1733 AddButton(ResString(IDS_CONNECTIONS
), ICID_NETWORK
, true, IDC_CONNECTIONS
);
1734 AddButton(ResString(IDS_ADMIN
), ICID_CONFIG
, true, IDC_ADMIN
);
1736 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1737 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
1739 AddButton(ResString(IDS_SETTINGS_MENU
), ICID_CONFIG
, true, IDC_SETTINGS_MENU
);
1741 AddButton(ResString(IDS_DESKTOPBAR_SETTINGS
), ICID_CONFIG
, false, ID_DESKTOPBAR_SETTINGS
);
1744 void BrowseMenu::AddEntries()
1746 super::AddEntries();
1748 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1749 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NONETHOOD
)) // or REST_NOENTIRENETWORK ?
1751 AddButton(ResString(IDS_NETWORK
), ICID_NETWORK
, true, IDC_NETWORK
);
1753 AddButton(ResString(IDS_DRIVES
), ICID_FOLDER
, true, IDC_DRIVES
);
1756 void SearchMenu::AddEntries()
1758 super::AddEntries();
1760 AddButton(ResString(IDS_SEARCH_PRG
), ICID_APPS
, false, IDC_SEARCH_PROGRAM
);
1762 AddButton(ResString(IDS_SEARCH_FILES
), ICID_SEARCH_DOC
, false, IDC_SEARCH_FILES
);
1764 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1765 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_HASFINDCOMPUTERS
))
1767 AddButton(ResString(IDS_SEARCH_COMPUTER
), ICID_COMPUTER
, false, IDC_SEARCH_COMPUTER
);
1771 void RecentStartMenu::AddEntries()
1773 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
1774 StartMenuDirectory
& smd
= *it
;
1775 ShellDirectory
& dir
= smd
._dir
;
1777 if (!dir
._scanned
) {
1780 #ifdef _LAZY_ICONEXTRACT
1781 dir
.smart_scan(SCAN_FILESYSTEM
);
1783 dir
.smart_scan(SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
1787 dir
.sort_directory(SORT_DATE
);
1788 AddShellEntries(dir
, 16, smd
._subfolders
); ///@todo read max. count of entries from registry