2 * Copyright 2003, 2004 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 // Explorer start menu
27 // Martin Fuchs, 19.08.2003
29 // Credits: Thanks to Everaldo (http://www.everaldo.com) for his nice looking icons.
35 #include "../explorer_intres.h"
37 #include "desktopbar.h"
38 #include "startmenu.h"
40 #include "../dialogs/searchprogram.h"
41 #include "../dialogs/settings.h"
44 #define SHELLPATH_CONTROL_PANEL TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}")
45 #define SHELLPATH_PRINTERS TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}")
46 #define SHELLPATH_NET_CONNECTIONS TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}")
49 StartMenu::StartMenu(HWND hwnd
)
52 _next_id
= IDC_FIRST_MENU
;
57 _bottom_max
= INT_MAX
;
59 _floating_btn
= false;
61 _scroll_mode
= SCROLL_NOT
;
65 _last_pos
= WindowRect(hwnd
).pos();
66 #ifdef _LIGHT_STARTMENU
72 StartMenu::StartMenu(HWND hwnd
, const StartMenuCreateInfo
& create_info
)
74 _create_info(create_info
)
76 for(StartMenuFolders::const_iterator it
=create_info
._folders
.begin(); it
!=create_info
._folders
.end(); ++it
)
78 _dirs
.push_back(ShellDirectory(GetDesktopFolder(), *it
, _hwnd
));
80 _next_id
= IDC_FIRST_MENU
;
84 _border_top
= create_info
._border_top
;
85 _bottom_max
= INT_MAX
;
87 _floating_btn
= create_info
._border_top
? true: false;
89 _scroll_mode
= SCROLL_NOT
;
93 _last_pos
= WindowRect(hwnd
).pos();
94 #ifdef _LIGHT_STARTMENU
100 StartMenu::~StartMenu()
102 SendParent(PM_STARTMENU_CLOSED
);
106 // We need this wrapper function for s_wcStartMenu, it calls the WIN32 API,
107 // though static C++ initializers are not allowed for Winelib applications.
108 BtnWindowClass
& StartMenu::GetWndClasss()
110 static BtnWindowClass
s_wcStartMenu(CLASSNAME_STARTMENU
);
112 return s_wcStartMenu
;
116 Window::CREATORFUNC_INFO
StartMenu::s_def_creator
= STARTMENU_CREATOR(StartMenu
);
118 HWND
StartMenu::Create(int x
, int y
, const StartMenuFolders
& folders
, HWND hwndParent
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
120 UINT style
, ex_style
;
124 style
= WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
;
126 top_height
= STARTMENU_TOP_BTN_SPACE
;
128 style
= WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|WS_CLIPCHILDREN
|WS_VISIBLE
;
129 ex_style
= WS_EX_TOOLWINDOW
;
133 RECT rect
= {x
, y
-STARTMENU_LINE_HEIGHT
-top_height
, x
+STARTMENU_WIDTH_MIN
, y
};
135 #ifndef _LIGHT_STARTMENU
136 rect
.top
+= STARTMENU_LINE_HEIGHT
;
139 AdjustWindowRectEx(&rect
, style
, FALSE
, ex_style
);
141 StartMenuCreateInfo create_info
;
143 create_info
._folders
= folders
;
144 create_info
._border_top
= top_height
;
145 create_info
._creator
= creator
;
146 create_info
._info
= info
;
149 create_info
._title
= title
;
151 HWND hwnd
= Window::Create(creator
, &create_info
, ex_style
, GetWndClasss(), title
,
152 style
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndParent
);
154 // make sure the window is not off the screen
161 LRESULT
StartMenu::Init(LPCREATESTRUCT pcs
)
166 if (super::Init(pcs
))
169 // create buttons for registered entries in _entries
170 for(ShellEntryMap::const_iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
171 const StartMenuEntry
& sme
= it
->second
;
172 bool hasSubmenu
= false;
174 for(ShellEntrySet::const_iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
)
175 if ((*it
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
178 #ifdef _LIGHT_STARTMENU
179 _buttons
.push_back(SMBtnInfo(sme
, it
->first
, hasSubmenu
));
181 AddButton(sme
._title
, sme
._hIcon
, hasSubmenu
, it
->first
);
185 #ifdef _LIGHT_STARTMENU
186 if (_buttons
.empty())
188 if (!GetWindow(_hwnd
, GW_CHILD
))
190 AddButton(ResString(IDS_EMPTY
), ICID_NONE
, false, 0, false);
192 #ifdef _LIGHT_STARTMENU
196 #ifdef _LAZY_ICONEXTRACT
197 PostMessage(_hwnd
, PM_UPDATE_ICONS
, 0, 0);
199 } catch(COMException
& e
) {
200 HandleException(e
, pcs
->hwndParent
); // destroys the start menu window while switching focus
206 void StartMenu::AddEntries()
208 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
209 StartMenuDirectory
& smd
= *it
;
210 ShellDirectory
& dir
= smd
._dir
;
215 #ifdef _LAZY_ICONEXTRACT
216 dir
.smart_scan(SORT_NAME
, SCAN_FILESYSTEM
); // lazy icon extraction, try to read directly from filesystem
218 dir
.smart_scan(SORT_NAME
, SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
222 AddShellEntries(dir
, -1, smd
._subfolders
);
227 void StartMenu::AddShellEntries(const ShellDirectory
& dir
, int max
, bool subfolders
)
231 for(Entry
*entry
=dir
._down
; entry
; entry
=entry
->_next
) {
232 // hide files like "desktop.ini"
233 if (entry
->_shell_attribs
& SFGAO_HIDDEN
)
234 //not appropriate for drive roots: if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
237 // hide subfolders if requested
239 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
242 // only 'max' entries shall be added.
246 if (entry
->_etype
== ET_SHELL
)
247 AddEntry(dir
._folder
, static_cast<ShellEntry
*>(entry
));
249 AddEntry(dir
._folder
, entry
);
254 LRESULT
StartMenu::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
258 PaintCanvas
canvas(_hwnd
);
263 ResizeButtons(LOWORD(lparam
)-_border_left
);
267 POINTS
& pos
= MAKEPOINTS(lparam
);
269 // move open submenus of floating menus
271 int dx
= pos
.x
- _last_pos
.x
;
272 int dy
= pos
.y
- _last_pos
.y
;
275 WindowRect
rt(_submenu
);
276 SetWindowPos(_submenu
, 0, rt
.left
+dx
, rt
.top
+dy
, 0, 0, SWP_NOSIZE
|SWP_NOACTIVATE
);
277 //MoveVisible(_submenu);
286 LRESULT res
= super::WndProc(nmsg
, wparam
, lparam
);
288 if (res
>=HTSIZEFIRST
&& res
<=HTSIZELAST
)
289 return HTCLIENT
; // disable window resizing
293 case WM_LBUTTONDOWN
: {
296 // check mouse cursor for coordinates of floating button
297 GetFloatingButtonRect(&rect
);
299 if (PtInRect(&rect
, Point(lparam
))) {
300 // create a floating copy of the current start menu
301 WindowRect
pos(_hwnd
);
303 ///@todo do something similar to StartMenuRoot::TrackStartmenu() in order to automatically close submenus when clicking on the desktop background
304 StartMenu::Create(pos
.left
+3, pos
.bottom
-3, _create_info
._folders
, 0, _create_info
._title
, _create_info
._creator
, _create_info
._info
);
308 #ifdef _LIGHT_STARTMENU
309 int id
= ButtonHitTest(Point(lparam
));
312 Command(id
, BN_CLICKED
);
317 if ((wparam
&0xFFF0) == SC_SIZE
)
318 return 0; // disable window resizing
322 // close start menu when activating another application
325 break; // don't call super::WndProc in case "this" has been deleted
330 #ifdef _LIGHT_STARTMENU
331 if (_scroll_mode
!= SCROLL_NOT
) {
338 #ifdef _LIGHT_STARTMENU
340 // automatically set the focus to startmenu entries when moving the mouse over them
341 if (lparam
!= _last_mouse_pos
) { // don't process WM_MOUSEMOVE when opening submenus using keyboard navigation
345 RECT rect_up
, rect_down
;
347 GetArrowButtonRects(&rect_up
, &rect_down
);
349 SCROLL_MODE scroll_mode
= SCROLL_NOT
;
351 if (PtInRect(&rect_up
, pt
))
352 scroll_mode
= SCROLL_UP
;
353 else if (PtInRect(&rect_down
, pt
))
354 scroll_mode
= SCROLL_DOWN
;
356 if (scroll_mode
!= _scroll_mode
) {
357 if (scroll_mode
== SCROLL_NOT
) {
362 SetTimer(_hwnd
, 0, 150, NULL
); // 150 ms scroll interval
366 _scroll_mode
= scroll_mode
;
370 int new_id
= ButtonHitTest(pt
);
372 if (new_id
> 0 && new_id
!= _selected_id
)
373 SelectButton(new_id
);
375 _last_mouse_pos
= lparam
;
380 if (_scroll_mode
== SCROLL_UP
) {
381 if (_scroll_pos
> 0) {
383 InvalidateRect(_hwnd
, NULL
, TRUE
);
386 if (_scroll_pos
<= _invisible_lines
) {
388 InvalidateRect(_hwnd
, NULL
, TRUE
);
397 case PM_STARTENTRY_FOCUSED
: { ///@todo use TrackMouseEvent() and WM_MOUSEHOVER to wait a bit before opening submenus
398 BOOL hasSubmenu
= wparam
;
399 HWND hctrl
= (HWND
)lparam
;
401 // automatically open submenus
403 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
404 //SendMessage(_hwnd, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hctrl),BN_CLICKED), (LPARAM)hctrl);
405 Command(GetDlgCtrlID(hctrl
), BN_CLICKED
);
407 // close any open submenu
408 CloseOtherSubmenus();
413 #ifdef _LAZY_ICONEXTRACT
414 case PM_UPDATE_ICONS
:
415 UpdateIcons(/*wparam*/);
419 case PM_STARTENTRY_LAUNCHED
:
420 if (GetWindowStyle(_hwnd
) & WS_CAPTION
) // don't automatically close floating menus
423 // route message to the parent menu and close menus after launching an entry
424 if (!SendParent(nmsg
, wparam
, lparam
))
426 return 1; // signal that we have received and processed the message
428 case PM_STARTMENU_CLOSED
:
432 case PM_SELECT_ENTRY
:
433 SelectButtonIndex(0, wparam
!=0);
436 #ifdef _LIGHT_STARTMENU
437 case WM_CONTEXTMENU
: {
438 Point
screen_pt(lparam
), clnt_pt
=screen_pt
;
439 ScreenToClient(_hwnd
, &clnt_pt
);
441 int id
= ButtonHitTest(clnt_pt
);
444 StartMenuEntry
& sme
= _entries
[id
];
446 for(ShellEntrySet::iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
) {
450 CHECKERROR(entry
->do_context_menu(_hwnd
, screen_pt
, _cm_ifs
)); // may close start menu because of focus loss
451 break; ///@todo handle context menu for more than one entry
459 return super::WndProc(nmsg
, wparam
, lparam
);
466 #ifdef _LIGHT_STARTMENU
468 int StartMenu::ButtonHitTest(POINT pt
)
470 ClientRect
clnt(_hwnd
);
471 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
473 if (pt
.x
<rect
.left
|| pt
.x
>rect
.right
)
476 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
477 const SMBtnInfo
& info
= *it
;
482 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
484 if (rect
.bottom
> _bottom_max
)
487 if (pt
.y
< rect
.bottom
) // PtInRect(&rect, pt)
490 rect
.top
= rect
.bottom
;
496 void StartMenu::InvalidateSelection()
498 if (_selected_id
<= 0)
501 ClientRect
clnt(_hwnd
);
502 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
504 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
505 const SMBtnInfo
& info
= *it
;
507 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
509 if (info
._id
== _selected_id
) {
510 InvalidateRect(_hwnd
, &rect
, TRUE
);
514 rect
.top
= rect
.bottom
;
518 const SMBtnInfo
* StartMenu::GetButtonInfo(int id
) const
520 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
)
527 bool StartMenu::SelectButton(int id
, bool open_sub
)
532 if (id
== _selected_id
)
535 InvalidateSelection();
537 const SMBtnInfo
* btn
= GetButtonInfo(id
);
539 if (btn
&& btn
->_enabled
) {
542 InvalidateSelection();
544 // automatically open submenus
545 if (btn
->_hasSubmenu
) {
549 CloseOtherSubmenus(); // close any open submenu
558 bool StartMenu::OpenSubmenu(bool select_first
)
560 if (_selected_id
== -1)
563 InvalidateSelection();
565 const SMBtnInfo
* btn
= GetButtonInfo(_selected_id
);
567 // automatically open submenus
568 if (btn
->_hasSubmenu
) {
569 //@@ allows destroying of startmenu when processing PM_UPDATE_ICONS -> GPF
570 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
571 Command(_selected_id
, BN_CLICKED
);
573 if (select_first
&& _submenu
)
574 SendMessage(_submenu
, PM_SELECT_ENTRY
, (WPARAM
)false, 0);
582 int StartMenu::GetSelectionIndex()
584 if (_selected_id
== -1)
587 for(int i
=0; i
<(int)_buttons
.size(); ++i
)
588 if (_buttons
[i
]._id
== _selected_id
)
594 bool StartMenu::SelectButtonIndex(int idx
, bool open_sub
)
596 if (idx
>=0 && idx
<(int)_buttons
.size())
597 return SelectButton(_buttons
[idx
]._id
, open_sub
);
602 void StartMenu::ProcessKey(int vk
)
607 Command(_selected_id
, BN_CLICKED
);
619 SelectButtonIndex(0, false);
623 SelectButtonIndex(_buttons
.size()-1, false);
628 CloseOtherSubmenus();
629 else if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) // don't automatically close floating menus
630 DestroyWindow(_hwnd
);
642 if (vk
>='0' && vk
<='Z')
643 JumpToNextShortcut(vk
);
647 bool StartMenu::Navigate(int step
)
649 int idx
= GetSelectionIndex();
655 idx
= _buttons
.size() - step
;
660 if (idx
<0 || idx
>(int)_buttons
.size())
663 if (SelectButtonIndex(idx
, false))
670 bool StartMenu::JumpToNextShortcut(char c
)
672 int cur_idx
= GetSelectionIndex();
680 SMBtnVector::const_iterator cur_it
= _buttons
.begin();
681 cur_it
+= cur_idx
+ 1;
683 // first search down from current item...
684 SMBtnVector::const_iterator it
= cur_it
;
685 for(; it
!=_buttons
.end(); ++it
) {
686 const SMBtnInfo
& btn
= *it
;
688 if (!btn
._title
.empty() && toupper((TBYTE
)btn
._title
.at(0)) == c
) {
690 first_found
= btn
._id
;
696 // ...now search from top to the current item
697 it
= _buttons
.begin();
698 for(; it
!=_buttons
.end() && it
!=cur_it
; ++it
) {
699 const SMBtnInfo
& btn
= *it
;
701 if (!btn
._title
.empty() && toupper((TBYTE
)btn
._title
.at(0)) == c
) {
703 first_found
= btn
._id
;
710 SelectButton(first_found
);
713 Command(first_found
, BN_CLICKED
);
720 #endif // _LIGHT_STARTMENU
723 bool StartMenu::GetButtonRect(int id
, PRECT prect
) const
725 #ifdef _LIGHT_STARTMENU
726 ClientRect
clnt(_hwnd
);
727 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
729 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
730 const SMBtnInfo
& info
= *it
;
732 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
734 if (info
._id
== id
) {
739 rect
.top
= rect
.bottom
;
744 HWND btn
= GetDlgItem(_hwnd
, id
);
747 GetWindowRect(btn
, prect
);
748 ScreenToClient(_hwnd
, prect
);
757 void StartMenu::DrawFloatingButton(HDC hdc
)
759 static ResIconEx
floatingIcon(IDI_FLOATING
, 8, 4);
761 ClientRect
clnt(_hwnd
);
763 DrawIconEx(hdc
, clnt
.right
-12, 0, floatingIcon
, 8, 4, 0, 0, DI_NORMAL
);
766 void StartMenu::GetFloatingButtonRect(LPRECT prect
)
768 GetClientRect(_hwnd
, prect
);
771 prect
->left
= prect
->right
- 8;
776 void StartMenu::DrawArrows(HDC hdc
)
778 static ResIconEx
arrowUpIcon(IDI_ARROW_UP
, 8, 4);
779 static ResIconEx
arrowDownIcon(IDI_ARROW_DOWN
, 8, 4);
781 ClientRect
clnt(_hwnd
);
783 DrawIconEx(hdc
, clnt
.right
/2-4, _floating_btn
?3:1, arrowUpIcon
, 8, 4, 0, 0, DI_NORMAL
);
784 DrawIconEx(hdc
, clnt
.right
/2-4, clnt
.bottom
-5, arrowDownIcon
, 8, 4, 0, 0, DI_NORMAL
);
787 void StartMenu::GetArrowButtonRects(LPRECT prect_up
, LPRECT prect_down
)
789 GetClientRect(_hwnd
, prect_up
);
790 *prect_down
= *prect_up
;
792 // prect_up->left = prect_up->right/2 - 4;
793 // prect_up->right = prect_up->left + 8;
794 prect_up
->right
-= 8;
795 prect_up
->top
= _floating_btn
? 3: 1;
796 prect_up
->bottom
= prect_up
->top
+ 4;
798 // prect_down->left = prect_down->right/2 - 4;
799 // prect_down->right = prect_down->left + 8;
800 prect_down
->right
-= 8;
801 prect_down
->top
= prect_down
->bottom
- 5;
805 void StartMenu::Paint(PaintCanvas
& canvas
)
808 DrawFloatingButton(canvas
);
810 #ifdef _LIGHT_STARTMENU
814 ClientRect
clnt(_hwnd
);
815 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
817 int sep_width
= rect
.right
-rect
.left
- 4;
819 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
820 BkMode
bk_mode(canvas
, TRANSPARENT
);
822 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
823 const SMBtnInfo
& btn
= *it
;
825 if (rect
.top
> canvas
.rcPaint
.bottom
)
828 if (btn
._id
== -1) { // a separator?
829 rect
.bottom
= rect
.top
+ STARTMENU_SEP_HEIGHT
;
831 if (rect
.bottom
> _bottom_max
)
834 BrushSelection
brush_sel(canvas
, GetSysColorBrush(COLOR_BTNSHADOW
));
835 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2-1, sep_width
, 1, PATCOPY
);
837 SelectBrush(canvas
, GetSysColorBrush(COLOR_BTNHIGHLIGHT
));
838 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2, sep_width
, 1, PATCOPY
);
840 rect
.bottom
= rect
.top
+ STARTMENU_LINE_HEIGHT
;
842 if (rect
.bottom
> _bottom_max
)
845 if (rect
.top
>= canvas
.rcPaint
.top
)
846 DrawStartMenuButton(canvas
, rect
, btn
._title
, btn
, btn
._id
==_selected_id
, false);
849 rect
.top
= rect
.bottom
;
854 #ifdef _LAZY_ICONEXTRACT
855 void StartMenu::UpdateIcons(/*int idx*/)
859 #ifdef _SINGLE_ICONEXTRACT
862 int idx
= _scroll_pos
;
864 for(; idx
<(int)_buttons
.size(); ++idx
) {
865 SMBtnInfo
& btn
= _buttons
[idx
];
867 if (btn
._icon_id
==ICID_UNKNOWN
&& btn
._id
>0) {
868 StartMenuEntry
& sme
= _entries
[btn
._id
];
870 btn
._icon_id
= ICID_NONE
;
872 for(ShellEntrySet::iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
) {
875 if (entry
->_icon_id
== ICID_UNKNOWN
)
877 entry
->extract_icon();
878 } catch(COMException
&) {
879 // ignore unexpected exceptions while extracting icons
882 if (entry
->_icon_id
> ICID_NONE
) {
883 btn
._icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
887 GetButtonRect(btn
._id
, &rect
);
889 if (rect
.bottom
> _bottom_max
)
892 WindowCanvas
canvas(_hwnd
);
893 DrawStartMenuButton(canvas
, rect
, NULL
, btn
, btn
._id
==_selected_id
, false);
895 //InvalidateRect(_hwnd, &rect, FALSE);
896 //UpdateWindow(_hwnd);
905 // if (++idx < (int)_buttons.size())
906 // PostMessage(_hwnd, PM_UPDATE_ICONS, idx, 0);
910 int icons_extracted
= 0;
911 int icons_updated
= 0;
913 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
914 ShellDirectory
& dir
= it
->_dir
;
916 icons_extracted
+= dir
.extract_icons();
919 if (icons_extracted
) {
920 for(ShellEntryMap::iterator it1
=_entries
.begin(); it1
!=_entries
.end(); ++it1
) {
921 StartMenuEntry
& sme
= it1
->second
;
924 sme
._hIcon
= (HICON
)-1;
926 for(ShellEntrySet::const_iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
927 const Entry
* sm_entry
= *it2
;
929 if (sm_entry
->_hIcon
) {
930 sme
._hIcon
= sm_entry
->_hIcon
;
937 for(SMBtnVector::iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
938 SMBtnInfo
& info
= *it
;
940 if (info
._id
>0 && !info
._hIcon
) {
941 info
._hIcon
= _entries
[info
._id
]._hIcon
;
948 InvalidateRect(_hwnd
, NULL
, FALSE
);
956 // resize child button controls to accomodate for new window size
957 void StartMenu::ResizeButtons(int cx
)
959 HDWP hdwp
= BeginDeferWindowPos(10);
961 for(HWND ctrl
=GetWindow(_hwnd
,GW_CHILD
); ctrl
; ctrl
=GetNextWindow(ctrl
,GW_HWNDNEXT
)) {
964 if (rt
.right
!= cx
) {
965 int height
= rt
.bottom
- rt
.top
;
967 // special handling for separator controls
968 if (!height
&& (GetWindowStyle(ctrl
)&SS_TYPEMASK
)==SS_ETCHEDHORZ
)
971 hdwp
= DeferWindowPos(hdwp
, ctrl
, 0, 0, 0, cx
, height
, SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
);
975 EndDeferWindowPos(hdwp
);
979 int StartMenu::Command(int id
, int code
)
981 #ifndef _LIGHT_STARTMENU
989 ShellEntryMap::iterator found
= _entries
.find(id
);
991 if (found
!= _entries
.end()) {
992 ActivateEntry(id
, found
->second
._entries
);
996 return super::Command(id
, code
);
997 #ifndef _LIGHT_STARTMENU
1006 ShellEntryMap::iterator
StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, Entry
* entry
)
1008 // search for an already existing subdirectory entry with the same name
1009 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1010 for(ShellEntryMap::iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
1011 StartMenuEntry
& sme
= it
->second
;
1013 if (!_tcsicmp(sme
._title
, title
)) ///@todo speed up by using a map indexed by name
1014 for(ShellEntrySet::iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
1015 if ((*it2
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1016 // merge the new shell entry with the existing of the same name
1017 sme
._entries
.insert(entry
);
1024 ShellEntryMap::iterator sme
= AddEntry(title
, icon_id
);
1026 sme
->second
._entries
.insert(entry
);
1031 ShellEntryMap::iterator
StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, int id
)
1039 sme
._icon_id
= icon_id
;
1041 ShellEntryMap::iterator it
= _entries
.insert(make_pair(id
, sme
)).first
;
1046 ShellEntryMap::iterator
StartMenu::AddEntry(const ShellFolder folder
, ShellEntry
* entry
)
1050 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1051 icon_id
= ICID_FOLDER
;
1053 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
1055 return AddEntry(folder
.get_name(entry
->_pidl
), icon_id
, entry
);
1058 ShellEntryMap::iterator
StartMenu::AddEntry(const ShellFolder folder
, Entry
* entry
)
1062 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1063 icon_id
= ICID_FOLDER
;
1065 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
1067 return AddEntry(entry
->_display_name
, icon_id
, entry
);
1071 void StartMenu::AddButton(LPCTSTR title
, ICON_ID icon_id
, bool hasSubmenu
, int id
, bool enabled
)
1073 #ifdef _LIGHT_STARTMENU
1074 _buttons
.push_back(SMBtnInfo(title
, icon_id
, id
, hasSubmenu
, enabled
));
1076 DWORD style
= enabled
? WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
: WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
|WS_DISABLED
;
1078 WindowRect
rect(_hwnd
);
1079 ClientRect
clnt(_hwnd
);
1081 // increase window height to make room for the new button
1082 rect
.top
-= STARTMENU_LINE_HEIGHT
;
1084 // move down if we are too high now
1086 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1087 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1090 WindowCanvas
canvas(_hwnd
);
1091 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1093 // widen window, if it is too small
1094 int text_width
= GetStartMenuBtnTextWidth(canvas
, title
, _hwnd
) + 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1096 int cx
= clnt
.right
- _border_left
;
1097 if (text_width
> cx
)
1098 rect
.right
+= text_width
-cx
;
1100 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1102 StartMenuCtrl(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
,
1103 title
, id
, g_Globals
._icon_cache
.get_icon(icon_id
)._hIcon
, hasSubmenu
, style
);
1107 void StartMenu::AddSeparator()
1109 #ifdef _LIGHT_STARTMENU
1110 _buttons
.push_back(SMBtnInfo(NULL
, ICID_NONE
, -1, false));
1112 WindowRect
rect(_hwnd
);
1113 ClientRect
clnt(_hwnd
);
1115 // increase window height to make room for the new separator
1116 rect
.top
-= STARTMENU_SEP_HEIGHT
;
1118 // move down if we are too high now
1120 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1121 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1124 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1126 StartMenuSeparator(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
);
1131 bool StartMenu::CloseOtherSubmenus(int id
)
1134 if (IsWindow(_submenu
)) {
1135 if (_submenu_id
== id
)
1139 DestroyWindow(_submenu
);
1140 // _submenu should be reset automatically by PM_STARTMENU_CLOSED, but safety first...
1151 void StartMenu::CreateSubmenu(int id
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1153 CreateSubmenu(id
, StartMenuFolders(), title
, creator
, info
);
1156 bool StartMenu::CreateSubmenu(int id
, int folder_id
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1159 SpecialFolderPath
folder(folder_id
, _hwnd
);
1161 StartMenuFolders new_folders
;
1162 new_folders
.push_back(folder
);
1164 CreateSubmenu(id
, new_folders
, title
, creator
, info
);
1167 } catch(COMException
&) {
1168 // ignore Exception and don't display anything
1169 CloseOtherSubmenus(id
);
1170 _buttons
[GetSelectionIndex()]._enabled
= false; // disable entries for non-existing folders
1175 bool StartMenu::CreateSubmenu(int id
, int folder_id1
, int folder_id2
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1177 StartMenuFolders new_folders
;
1180 new_folders
.push_back(SpecialFolderPath(folder_id1
, _hwnd
));
1181 } catch(COMException
&) {
1185 new_folders
.push_back(SpecialFolderPath(folder_id2
, _hwnd
));
1186 } catch(COMException
&) {
1189 if (!new_folders
.empty()) {
1190 CreateSubmenu(id
, new_folders
, title
, creator
, info
);
1193 CloseOtherSubmenus(id
);
1194 _buttons
[GetSelectionIndex()]._enabled
= false; // disable entries for non-existing folders
1199 void StartMenu::CreateSubmenu(int id
, const StartMenuFolders
& new_folders
, LPCTSTR title
, CREATORFUNC_INFO creator
, void* info
)
1201 // Only open one submenu at a time.
1202 if (!CloseOtherSubmenus(id
))
1208 if (GetButtonRect(id
, &rect
)) {
1209 ClientToScreen(_hwnd
, &rect
);
1211 x
= rect
.right
; // Submenus should overlap their parent a bit.
1212 y
= rect
.top
+STARTMENU_LINE_HEIGHT
+_border_top
/*own border*/ -STARTMENU_TOP_BTN_SPACE
/*border of new submenu*/;
1214 WindowRect
pos(_hwnd
);
1221 _submenu
= StartMenu::Create(x
, y
, new_folders
, _hwnd
, title
, creator
, info
);
1225 void StartMenu::ActivateEntry(int id
, const ShellEntrySet
& entries
)
1227 StartMenuFolders new_folders
;
1230 for(ShellEntrySet::const_iterator it
=entries
.begin(); it
!=entries
.end(); ++it
) {
1231 Entry
* entry
= const_cast<Entry
*>(*it
);
1233 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1235 ///@todo If the user explicitly clicked on a submenu, display this folder as floating start menu.
1237 if (entry
->_etype
== ET_SHELL
)
1238 new_folders
.push_back(entry
->create_absolute_pidl());
1240 TCHAR path
[MAX_PATH
];
1242 if (entry
->get_path(path
))
1243 new_folders
.push_back(path
);
1247 title
= entry
->_display_name
;
1249 // The entry is no subdirectory, so there can only be one shell entry.
1250 assert(entries
.size()==1);
1252 HWND hparent
= GetParent(_hwnd
);
1253 ShellPath shell_path
= entry
->create_absolute_pidl();
1255 // close start menus when launching the selected entry
1258 ///@todo launch in the background; specify correct HWND for error message box titles
1259 SHELLEXECUTEINFO shexinfo
;
1261 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
1262 shexinfo
.fMask
= SEE_MASK_IDLIST
; // SEE_MASK_INVOKEIDLIST is also possible.
1263 shexinfo
.hwnd
= hparent
;
1264 shexinfo
.lpVerb
= NULL
;
1265 shexinfo
.lpFile
= NULL
;
1266 shexinfo
.lpParameters
= NULL
;
1267 shexinfo
.lpDirectory
= NULL
;
1268 shexinfo
.nShow
= SW_SHOWNORMAL
;
1270 shexinfo
.lpIDList
= &*shell_path
;
1272 // add PIDL to the recent file list
1273 SHAddToRecentDocs(SHARD_PIDL
, shexinfo
.lpIDList
);
1275 if (!ShellExecuteEx(&shexinfo
))
1276 display_error(hparent
, GetLastError());
1278 // we may have deleted 'this' - ensure we leave the loop and function
1283 if (!new_folders
.empty()) {
1284 // Only open one submenu at a time.
1285 if (!CloseOtherSubmenus(id
))
1288 CreateSubmenu(id
, new_folders
, title
);
1293 /// close all windows of the start menu popup
1294 void StartMenu::CloseStartMenu(int id
)
1296 if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) { // don't automatically close floating menus
1297 if (!SendParent(PM_STARTENTRY_LAUNCHED
, id
, (LPARAM
)_hwnd
))
1298 DestroyWindow(_hwnd
);
1299 } else if (_submenu
) // instead close submenus of floating parent menus
1304 int GetStartMenuBtnTextWidth(HDC hdc
, LPCTSTR title
, HWND hwnd
)
1306 RECT rect
= {0, 0, 0, 0};
1307 DrawText(hdc
, title
, -1, &rect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_CALCRECT
);
1309 return rect
.right
-rect
.left
;
1312 #ifdef _LIGHT_STARTMENU
1313 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, const SMBtnInfo
& btn
, bool has_focus
, bool pushed
)
1315 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, HICON hIcon
,
1316 bool hasSubmenu
, bool enabled
, bool has_focus
, bool pushed
);
1319 UINT style
= DFCS_BUTTONPUSH
;
1322 style
|= DFCS_INACTIVE
;
1324 POINT iconPos
= {rect
.left
+2, (rect
.top
+rect
.bottom
-16)/2};
1325 RECT textRect
= {rect
.left
+16+4, rect
.top
+2, rect
.right
-4, rect
.bottom
-4};
1328 style
|= DFCS_PUSHED
;
1329 ++iconPos
.x
; ++iconPos
.y
;
1330 ++textRect
.left
; ++textRect
.top
;
1331 ++textRect
.right
; ++textRect
.bottom
;
1334 int bk_color_idx
= COLOR_BTNFACE
;
1335 int text_color_idx
= COLOR_BTNTEXT
;
1338 bk_color_idx
= COLOR_HIGHLIGHT
;
1339 text_color_idx
= COLOR_HIGHLIGHTTEXT
;
1342 COLORREF bk_color
= GetSysColor(bk_color_idx
);
1343 HBRUSH bk_brush
= GetSysColorBrush(bk_color_idx
);
1346 FillRect(hdc
, &rect
, bk_brush
);
1348 if (btn
._icon_id
> ICID_NONE
)
1349 g_Globals
._icon_cache
.get_icon(btn
._icon_id
).draw(hdc
, iconPos
.x
, iconPos
.y
, 16, 16, bk_color
, bk_brush
);
1351 // draw submenu arrow at the right
1352 if (btn
._hasSubmenu
) {
1353 static SmallIcon
arrowIcon(IDI_ARROW
);
1354 static SmallIcon
selArrowIcon(IDI_ARROW_SELECTED
);
1356 DrawIconEx(hdc
, rect
.right
-16, iconPos
.y
,
1357 has_focus
? selArrowIcon
: arrowIcon
,
1358 16, 16, 0, bk_brush
, DI_NORMAL
);
1362 BkMode
bk_mode(hdc
, TRANSPARENT
);
1364 if (!btn
._enabled
) // dis->itemState & (ODS_DISABLED|ODS_GRAYED)
1365 DrawGrayText(hdc
, &textRect
, title
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1367 TextColor
lcColor(hdc
, GetSysColor(text_color_idx
));
1368 DrawText(hdc
, title
, -1, &textRect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1374 #ifdef _LIGHT_STARTMENU
1376 void StartMenu::ResizeToButtons()
1378 WindowRect
rect(_hwnd
);
1380 WindowCanvas
canvas(_hwnd
);
1381 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1383 int max_width
= STARTMENU_WIDTH_MIN
;
1386 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
1387 int w
= GetStartMenuBtnTextWidth(canvas
, it
->_title
, _hwnd
);
1393 height
+= STARTMENU_SEP_HEIGHT
;
1395 height
+= STARTMENU_LINE_HEIGHT
;
1398 // calculate new window size
1399 int text_width
= max_width
+ 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1401 RECT rt_hgt
= {rect
.left
, rect
.bottom
-_border_top
-height
, rect
.left
+_border_left
+text_width
, rect
.bottom
};
1402 AdjustWindowRectEx(&rt_hgt
, GetWindowStyle(_hwnd
), FALSE
, GetWindowExStyle(_hwnd
));
1404 // ignore movement, only look at the size change
1405 rect
.right
= rect
.left
+ (rt_hgt
.right
-rt_hgt
.left
);
1406 rect
.top
= rect
.bottom
- (rt_hgt
.bottom
-rt_hgt
.top
);
1408 // move down if we are too high
1415 // enable scroll mode for long start menus, which span more than the whole screen height
1416 int cyscreen
= GetSystemMetrics(SM_CYSCREEN
);
1419 if (rect
.bottom
> cyscreen
) {
1422 _invisible_lines
= (rect
.bottom
-cyscreen
+(STARTMENU_LINE_HEIGHT
-1))/STARTMENU_LINE_HEIGHT
+ 1;
1423 rect
.bottom
-= _invisible_lines
* STARTMENU_LINE_HEIGHT
;
1425 bottom_max
= rect
.bottom
;
1428 rect
.bottom
+= 6; // lower scroll arrow
1430 _border_top
+= 6; // upper scroll arrow
1431 rect
.bottom
+= 2*6; // upper+lower scroll arrow
1435 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1438 POINT pt
= {0, bottom_max
};
1440 ScreenToClient(_hwnd
, &pt
);
1446 #else // _LIGHT_STARTMENU
1448 LRESULT
StartMenuButton::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1452 // automatically set the focus to startmenu entries when moving the mouse over them
1453 if (GetFocus()!=_hwnd
&& !(GetWindowStyle(_hwnd
)&WS_DISABLED
))
1458 PostParent(PM_STARTENTRY_FOCUSED
, _hasSubmenu
, (LPARAM
)_hwnd
);
1462 // route WM_CANCELMODE to the startmenu window
1463 return SendParent(nmsg
, wparam
, lparam
);
1466 return super::WndProc(nmsg
, wparam
, lparam
);
1472 void StartMenuButton::DrawItem(LPDRAWITEMSTRUCT dis
)
1474 TCHAR title
[BUFFER_LEN
];
1476 GetWindowText(_hwnd
, title
, BUFFER_LEN
);
1478 DrawStartMenuButton(dis
->hDC
, dis
->rcItem
, title
, _hIcon
,
1480 !(dis
->itemState
& ODS_DISABLED
),
1481 dis
->itemState
&ODS_FOCUS
? true: false,
1482 dis
->itemState
&ODS_SELECTED
? true: false);
1488 StartMenuRoot::StartMenuRoot(HWND hwnd
)
1491 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1492 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCOMMONGROUPS
))
1495 // insert directory "All Users\Start Menu"
1496 ShellDirectory
cmn_startmenu(GetDesktopFolder(), SpecialFolderPath(CSIDL_COMMON_STARTMENU
, _hwnd
), _hwnd
);
1497 _dirs
.push_back(StartMenuDirectory(cmn_startmenu
, false)); // don't add subfolders
1498 } catch(COMException
&) {
1499 // ignore exception and don't show additional shortcuts
1503 // insert directory "<user name>\Start Menu"
1505 ShellDirectory
usr_startmenu(GetDesktopFolder(), SpecialFolderPath(CSIDL_STARTMENU
, _hwnd
), _hwnd
);
1506 _dirs
.push_back(StartMenuDirectory(usr_startmenu
, false)); // don't add subfolders
1507 } catch(COMException
&) {
1508 // ignore exception and don't show additional shortcuts
1511 // read size of logo bitmap
1513 GetObject(ResBitmap(IDB_LOGOV
), sizeof(BITMAP
), &bmp_hdr
);
1514 _logo_size
.cx
= bmp_hdr
.bmWidth
;
1515 _logo_size
.cy
= bmp_hdr
.bmHeight
;
1517 _border_left
= _logo_size
.cx
+ 1;
1521 static void CalculateStartPos(HWND hwndOwner
, RECT
& rect
)
1523 WindowRect
pos(hwndOwner
);
1525 rect
.left
= pos
.left
;
1526 rect
.top
= pos
.top
-STARTMENU_LINE_HEIGHT
-4;
1527 rect
.right
= pos
.left
+STARTMENU_WIDTH_MIN
;
1528 rect
.bottom
= pos
.top
;
1530 #ifndef _LIGHT_STARTMENU
1531 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1534 AdjustWindowRectEx(&rect
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
, FALSE
, 0);
1537 HWND
StartMenuRoot::Create(HWND hwndOwner
)
1541 CalculateStartPos(hwndOwner
, rect
);
1543 return Window::Create(WINDOW_CREATOR(StartMenuRoot
), 0, GetWndClasss(), TITLE_STARTMENU
,
1544 WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
,
1545 rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndOwner
);
1549 void StartMenuRoot::TrackStartmenu()
1554 #ifdef _LIGHT_STARTMENU
1558 #ifdef _LIGHT_STARTMENU
1559 // recalculate start menu root position
1562 CalculateStartPos(GetParent(hwnd
), rect
);
1564 SetWindowPos(hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, 0);
1569 // show previously hidden start menu
1570 ShowWindow(hwnd
, SW_SHOW
);
1571 SetForegroundWindow(hwnd
);
1573 while(IsWindow(hwnd
)) {
1574 if (!GetMessage(&msg
, 0, 0, 0)) {
1575 PostQuitMessage(msg
.wParam
);
1579 // Check for a mouse click on any window, which is not part of the start menu
1580 if (msg
.message
==WM_LBUTTONDOWN
|| msg
.message
==WM_MBUTTONDOWN
|| msg
.message
==WM_RBUTTONDOWN
) {
1581 StartMenu
* menu_wnd
= NULL
;
1583 for(HWND hwnd
=msg
.hwnd
; hwnd
; hwnd
=GetParent(hwnd
)) {
1584 menu_wnd
= WINDOW_DYNAMIC_CAST(StartMenu
, hwnd
);
1597 if (pretranslate_msg(&msg
))
1600 if (dispatch_dialog_msg(&msg
))
1603 TranslateMessage(&msg
);
1606 DispatchMessage(&msg
);
1607 } catch(COMException
& e
) {
1608 HandleException(e
, _hwnd
);
1610 } catch(COMException
& e
) {
1611 HandleException(e
, _hwnd
);
1617 LRESULT
StartMenuRoot::Init(LPCREATESTRUCT pcs
)
1619 // add buttons for entries in _entries
1620 if (super::Init(pcs
))
1630 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"), &hkey
))
1633 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), &hkeyAdv
))
1636 #define IS_VALUE_ZERO(hk, name) \
1637 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || !value))
1639 #define IS_VALUE_NOT_ZERO(hk, name) \
1640 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || value>0))
1644 // insert hard coded start entries
1645 AddButton(ResString(IDS_PROGRAMS
), ICID_APPS
, true, IDC_PROGRAMS
);
1647 AddButton(ResString(IDS_DOCUMENTS
), ICID_DOCUMENTS
, true, IDC_DOCUMENTS
);
1649 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1650 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORECENTDOCSMENU
))
1652 if (IS_VALUE_ZERO(hkey
, _T("NoRecentDocsMenu")))
1654 AddButton(ResString(IDS_RECENT
), ICID_DOCUMENTS
, true, IDC_RECENT
);
1656 AddButton(ResString(IDS_FAVORITES
), ICID_FAVORITES
, true, IDC_FAVORITES
);
1658 AddButton(ResString(IDS_SETTINGS
), ICID_CONFIG
, true, IDC_SETTINGS
);
1660 AddButton(ResString(IDS_BROWSE
), ICID_FOLDER
, true, IDC_BROWSE
);
1662 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1663 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOFIND
))
1665 if (IS_VALUE_ZERO(hkey
, _T("NoFind")))
1667 AddButton(ResString(IDS_SEARCH
), ICID_SEARCH
, true, IDC_SEARCH
);
1669 AddButton(ResString(IDS_START_HELP
), ICID_INFO
, false, IDC_START_HELP
);
1671 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1672 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORUN
))
1674 if (IS_VALUE_ZERO(hkey
, _T("NoRun")))
1676 AddButton(ResString(IDS_LAUNCH
), ICID_ACTION
, false, IDC_LAUNCH
);
1682 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1683 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCLOSE
))
1685 if (IS_VALUE_NOT_ZERO(hkeyAdv
, _T("StartMenuLogoff")))
1687 AddButton(ResString(IDS_LOGOFF
), ICID_LOGOFF
, false, IDC_LOGOFF
);
1690 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1691 if (!g_Globals
._SHRestricted
|| SHRestricted(REST_STARTMENULOGOFF
) != 1)
1693 if (IS_VALUE_ZERO(hkey
, _T("NoClose")))
1695 AddButton(ResString(IDS_SHUTDOWN
), ICID_LOGOFF
, false, IDC_SHUTDOWN
);
1698 AddButton(ResString(IDS_TERMINATE
), ICID_LOGOFF
, false, IDC_TERMINATE
);
1702 RegCloseKey(hkeyAdv
);
1707 #ifdef _LIGHT_STARTMENU
1708 // set the window size to fit all buttons
1716 void StartMenuRoot::AddEntries()
1718 super::AddEntries();
1720 AddButton(ResString(IDS_EXPLORE
), ICID_EXPLORER
, false, IDC_EXPLORE
);
1724 LRESULT
StartMenuRoot::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1728 PaintCanvas
canvas(_hwnd
);
1733 return super::WndProc(nmsg
, wparam
, lparam
);
1739 void StartMenuRoot::Paint(PaintCanvas
& canvas
)
1742 {WindowCanvas
dc(_hwnd
); clr_bits
=GetDeviceCaps(dc
, BITSPIXEL
);}
1745 ResBitmap
bmp(clr_bits
<=8? clr_bits
<=4? IDB_LOGOV16
: IDB_LOGOV256
: IDB_LOGOV
);
1746 BitmapSelection
sel(mem_dc
, bmp
);
1748 ClientRect
clnt(_hwnd
);
1749 int h
= min(_logo_size
.cy
, clnt
.bottom
);
1751 RECT rect
= {0, 0, _logo_size
.cx
, clnt
.bottom
-h
};
1752 HBRUSH hbr
= CreateSolidBrush(GetPixel(mem_dc
, 0, 0));
1753 FillRect(canvas
, &rect
, hbr
);
1756 PatBlt(canvas
, _logo_size
.cx
, 0, 1, clnt
.bottom
, WHITENESS
);
1758 BitBlt(canvas
, 0, clnt
.bottom
-h
, _logo_size
.cx
, h
, mem_dc
, 0, 0, SRCCOPY
);
1760 super::Paint(canvas
);
1764 void StartMenuRoot::CloseStartMenu(int id
)
1769 ShowWindow(_hwnd
, SW_HIDE
);
1772 void StartMenuRoot::ProcessKey(int vk
)
1777 CloseOtherSubmenus();
1778 // don't close start menu root
1782 super::ProcessKey(vk
);
1787 int StartMenuHandler::Command(int id
, int code
)
1794 CreateSubmenu(id
, CSIDL_COMMON_PROGRAMS
, CSIDL_PROGRAMS
, ResString(IDS_PROGRAMS
));
1799 explorer_show_frame(SW_SHOWNORMAL
);
1804 ShowLaunchDialog(g_Globals
._hwndDesktopBar
);
1808 CreateSubmenu(id
, CSIDL_PERSONAL
, ResString(IDS_DOCUMENTS
));
1812 CreateSubmenu(id
, CSIDL_RECENT
, ResString(IDS_RECENT
), STARTMENU_CREATOR(RecentStartMenu
));
1816 #ifndef _SHELL32_FAVORITES
1817 CreateSubmenu(id
, ResString(IDS_FAVORITES
), STARTMENU_CREATOR(FavoritesMenu
), &static_cast<BookmarkList
&>(g_Globals
._favorites
));
1819 CreateSubmenu(id
, CSIDL_COMMON_FAVORITES
, CSIDL_FAVORITES
, ResString(IDS_FAVORITES
));
1824 CreateSubmenu(id
, ResString(IDS_BROWSE
), STARTMENU_CREATOR(BrowseMenu
));
1828 CreateSubmenu(id
, ResString(IDS_SETTINGS
), STARTMENU_CREATOR(SettingsMenu
));
1832 CreateSubmenu(id
, ResString(IDS_SEARCH
), STARTMENU_CREATOR(SearchMenu
));
1835 case IDC_START_HELP
:
1837 MessageBox(g_Globals
._hwndDesktopBar
, TEXT("Help not yet implemented"), ResString(IDS_TITLE
), MB_OK
);
1842 ShowLogoffDialog(g_Globals
._hwndDesktopBar
);
1846 DestroyWindow(GetParent(_hwnd
));
1851 ShowExitWindowsDialog(g_Globals
._hwndDesktopBar
);
1857 case ID_DESKTOPBAR_SETTINGS
:
1859 ExplorerPropertySheet(g_Globals
._hwndDesktopBar
);
1862 case IDC_CONTROL_PANEL
: {
1866 XMLPos explorer_options
= g_Globals
.get_cfg("general/explorer");
1867 bool mdi
= XMLBool(explorer_options
, "mdi", true);
1870 MDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
1873 SDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
1875 launch_file(_hwnd
, SHELLPATH_CONTROL_PANEL
);
1879 case IDC_SETTINGS_MENU
:
1880 CreateSubmenu(id
, CSIDL_CONTROLS
, ResString(IDS_SETTINGS_MENU
));
1883 case IDC_PRINTERS
: {
1887 #ifdef _ROS_ // to be removed when printer folder will be implemented
1888 MessageBox(0, TEXT("printer folder not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1891 XMLPos explorer_options
= g_Globals
.get_cfg("general/explorer");
1892 bool mdi
= XMLBool(explorer_options
, "mdi", true);
1895 MDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}"), 0);
1898 SDIMainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}"), 0);
1901 launch_file(_hwnd
, SHELLPATH_PRINTERS
);
1905 case IDC_PRINTERS_MENU
:
1906 CreateSubmenu(id
, CSIDL_PRINTERS
, CSIDL_PRINTHOOD
, ResString(IDS_PRINTERS
));
1907 /* StartMenuFolders new_folders;
1910 new_folders.push_back(ShellPath(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}")));
1911 } catch(COMException&) {
1914 CreateSubmenu(id, new_folders, ResString(IDS_PRINTERS));*/
1919 CreateSubmenu(id
, CSIDL_COMMON_ADMINTOOLS
, CSIDL_ADMINTOOLS
, ResString(IDS_ADMIN
));
1920 //CloseStartMenu(id);
1921 //MainFrame::Create(SpecialFolderPath(CSIDL_COMMON_ADMINTOOLS, _hwnd), OWM_PIDL);
1923 launch_file(_hwnd
, SpecialFolderFSPath(CSIDL_COMMON_ADMINTOOLS
, _hwnd
));
1927 case IDC_CONNECTIONS
:
1929 #ifdef _ROS_ // to be removed when RAS will be implemented
1930 MessageBox(0, TEXT("RAS folder not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1932 CreateSubmenu(id
, CSIDL_CONNECTIONS
, ResString(IDS_CONNECTIONS
));
1933 //CloseStartMenu(id);
1934 //MainFrame::Create(SpecialFolderPath(CSIDL_CONNECTIONS, _hwnd), OWM_PIDL);
1937 launch_file(_hwnd
, SHELLPATH_NET_CONNECTIONS
);
1945 #ifdef _ROS_ // to be removed when network will be implemented
1946 MessageBox(0, TEXT("network not yet implemented"), ResString(IDS_TITLE
), MB_OK
);
1948 CreateSubmenu(id
, CSIDL_NETWORK
, ResString(IDS_NETWORK
));
1953 ///@todo exclude removable drives
1954 CreateSubmenu(id
, CSIDL_DRIVES
, ResString(IDS_DRIVES
));
1960 case IDC_SEARCH_PROGRAM
:
1962 Dialog::DoModal(IDD_SEARCH_PROGRAM
, WINDOW_CREATOR(FindProgramDlg
));
1965 case IDC_SEARCH_FILES
:
1970 case IDC_SEARCH_COMPUTER
:
1972 ShowSearchComputer();
1977 return super::Command(id
, code
);
1984 void StartMenuHandler::ShowSearchDialog()
1986 static DynamicFct
<SHFINDFILES
> SHFindFiles(TEXT("SHELL32"), 90);
1989 (*SHFindFiles
)(NULL
, NULL
);
1991 MessageBox(0, TEXT("SHFindFiles() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1994 void StartMenuHandler::ShowSearchComputer()
1996 static DynamicFct
<SHFINDCOMPUTER
> SHFindComputer(TEXT("SHELL32"), 91);
1999 (*SHFindComputer
)(NULL
, NULL
);
2001 MessageBox(0, TEXT("SHFindComputer() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2004 void StartMenuHandler::ShowLaunchDialog(HWND hwndOwner
)
2006 ///@todo All text phrases should be put into the resources.
2007 static LPCSTR szTitle
= "Run";
2008 static LPCSTR szText
= "Type the name of a program, folder, document, or Internet resource, and Explorer will open it for you.";
2010 static DynamicFct
<RUNFILEDLG
> RunFileDlg(TEXT("SHELL32"), 61);
2012 // Show "Run..." dialog
2014 #ifndef _ROS_ /* FIXME: our shell32 always expects Ansi strings */
2015 if ((HIWORD(GetVersion())>>14) == W_VER_NT
) {
2016 WCHAR wTitle
[40], wText
[256];
2018 MultiByteToWideChar(CP_ACP
, 0, szTitle
, -1, wTitle
, 40);
2019 MultiByteToWideChar(CP_ACP
, 0, szText
, -1, wText
, 256);
2021 (*RunFileDlg
)(hwndOwner
, 0, NULL
, (LPCSTR
)wTitle
, (LPCSTR
)wText
, RFF_CALCDIRECTORY
);
2025 (*RunFileDlg
)(hwndOwner
, 0, NULL
, szTitle
, szText
, RFF_CALCDIRECTORY
);
2029 void StartMenuHandler::ShowLogoffDialog(HWND hwndOwner
)
2031 static DynamicFct
<LOGOFFWINDOWSDIALOG
> LogoffWindowsDialog(TEXT("SHELL32"), 54);
2032 // static DynamicFct<RESTARTWINDOWSDLG> RestartDialog(TEXT("SHELL32"), 59);
2034 if (LogoffWindowsDialog
)
2035 (*LogoffWindowsDialog
)(0);
2036 /* The RestartDialog function prompts about some system setting change. This is not what we want to display here.
2037 else if (RestartDialog)
2038 return (*RestartDialog)(hwndOwner, (LPWSTR)L"You selected <Log Off>.\n\n", EWX_LOGOFF) == 1; ///@todo ANSI string conversion if needed
2041 MessageBox(hwndOwner
, TEXT("LogoffWindowsDialog() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2044 void ShowExitWindowsDialog(HWND hwndOwner
)
2046 static DynamicFct
<EXITWINDOWSDLG
> ExitWindowsDialog(TEXT("SHELL32"), 60);
2048 if (ExitWindowsDialog
)
2049 (*ExitWindowsDialog
)(hwndOwner
);
2051 MessageBox(hwndOwner
, TEXT("ExitWindowsDialog() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
2055 void SettingsMenu::AddEntries()
2057 super::AddEntries();
2059 #ifdef _ROS_ // to be removed when printer/network will be implemented
2060 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, false, IDC_PRINTERS_MENU
);
2061 AddButton(ResString(IDS_CONNECTIONS
), ICID_NETWORK
, false, IDC_CONNECTIONS
);
2063 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, true, IDC_PRINTERS_MENU
);
2064 AddButton(ResString(IDS_CONNECTIONS
), ICID_NETWORK
, true, IDC_CONNECTIONS
);
2066 AddButton(ResString(IDS_ADMIN
), ICID_CONFIG
, true, IDC_ADMIN
);
2068 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2069 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
2071 AddButton(ResString(IDS_SETTINGS_MENU
), ICID_CONFIG
, true, IDC_SETTINGS_MENU
);
2073 AddButton(ResString(IDS_DESKTOPBAR_SETTINGS
), ICID_CONFIG
, false, ID_DESKTOPBAR_SETTINGS
);
2075 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, false, IDC_PRINTERS
);
2077 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2078 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
2080 AddButton(ResString(IDS_CONTROL_PANEL
), ICID_CONFIG
, false, IDC_CONTROL_PANEL
);
2083 void BrowseMenu::AddEntries()
2085 super::AddEntries();
2087 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2088 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NONETHOOD
)) // or REST_NOENTIRENETWORK ?
2090 #ifdef _ROS_ // to be removed when printer/network will be implemented
2091 AddButton(ResString(IDS_NETWORK
), ICID_NETWORK
, false, IDC_NETWORK
);
2093 AddButton(ResString(IDS_NETWORK
), ICID_NETWORK
, true, IDC_NETWORK
);
2096 AddButton(ResString(IDS_DRIVES
), ICID_FOLDER
, true, IDC_DRIVES
);
2099 void SearchMenu::AddEntries()
2101 super::AddEntries();
2103 AddButton(ResString(IDS_SEARCH_FILES
), ICID_SEARCH_DOC
, false, IDC_SEARCH_FILES
);
2105 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
2106 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_HASFINDCOMPUTERS
))
2108 AddButton(ResString(IDS_SEARCH_COMPUTER
),ICID_COMPUTER
, false, IDC_SEARCH_COMPUTER
);
2110 AddButton(ResString(IDS_SEARCH_PRG
), ICID_APPS
, false, IDC_SEARCH_PROGRAM
);
2114 void RecentStartMenu::AddEntries()
2116 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
2117 StartMenuDirectory
& smd
= *it
;
2118 ShellDirectory
& dir
= smd
._dir
;
2120 if (!dir
._scanned
) {
2123 #ifdef _LAZY_ICONEXTRACT
2124 dir
.smart_scan(SORT_NAME
, SCAN_FILESYSTEM
);
2126 dir
.smart_scan(SORT_NAME
, SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
2130 dir
.sort_directory(SORT_DATE
);
2131 AddShellEntries(dir
, RECENT_DOCS_COUNT
, smd
._subfolders
);
2136 #ifndef _SHELL32_FAVORITES
2138 void FavoritesMenu::AddEntries()
2140 super::AddEntries();
2142 for(BookmarkList::iterator it
=_bookmarks
.begin(); it
!=_bookmarks
.end(); ++it
) {
2143 BookmarkNode
& node
= *it
;
2145 int id
= ++_next_id
;
2147 _entries
[id
] = node
;
2149 if (node
._type
== BookmarkNode::BMNT_FOLDER
) {
2150 BookmarkFolder
& folder
= *node
._pfolder
;
2152 AddButton(folder
._name
, ICID_FOLDER
, true, id
);
2153 } else if (node
._type
== BookmarkNode::BMNT_BOOKMARK
) {
2154 Bookmark
& bookmark
= *node
._pbookmark
;
2156 ICON_ID icon
= ICID_NONE
;
2158 if (!bookmark
._icon_path
.empty())
2159 icon
= g_Globals
._icon_cache
.extract(bookmark
._icon_path
, bookmark
._icon_idx
);
2161 AddButton(bookmark
._name
, icon
!=ICID_NONE
?icon
:ICID_BOOKMARK
, false, id
);
2166 int FavoritesMenu::Command(int id
, int code
)
2168 BookmarkMap::iterator found
= _entries
.find(id
);
2170 if (found
!= _entries
.end()) {
2171 BookmarkNode
& node
= found
->second
;
2173 if (node
._type
== BookmarkNode::BMNT_FOLDER
) {
2174 BookmarkFolder
& folder
= *node
._pfolder
;
2176 if (CloseOtherSubmenus(id
))
2177 CreateSubmenu(id
, folder
._name
, STARTMENU_CREATOR(FavoritesMenu
), &static_cast<BookmarkList
&>(folder
._bookmarks
));
2178 } else if (node
._type
== BookmarkNode::BMNT_BOOKMARK
) {
2179 Bookmark
& bookmark
= *node
._pbookmark
;
2181 String url
= bookmark
._url
;
2182 HWND hparent
= GetParent(_hwnd
);
2186 launch_file(hparent
, url
, SW_SHOWNORMAL
);
2192 return super::Command(id
, code
);