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
21 // Explorer clone, lean version
25 // Explorer start menu
27 // Martin Fuchs, 19.08.2003
29 // Credits: Thanks to Everaldo (http://www.everaldo.com) for his nice looking icons.
33 #include "../utility/utility.h"
35 #include "../explorer.h"
36 #include "../globals.h"
37 #include "../externals.h"
38 #include "../explorer_intres.h"
40 #include "desktopbar.h"
41 #include "startmenu.h"
43 #include "../dialogs/settings.h"
46 StartMenu::StartMenu(HWND hwnd
)
49 _next_id
= IDC_FIRST_MENU
;
54 _bottom_max
= INT_MAX
;
56 _floating_btn
= false;
58 _scroll_mode
= SCROLL_NOT
;
62 _last_pos
= WindowRect(hwnd
).pos();
63 #ifdef _LIGHT_STARTMENU
69 StartMenu::StartMenu(HWND hwnd
, const StartMenuCreateInfo
& create_info
)
71 _create_info(create_info
)
73 for(StartMenuFolders::const_iterator it
=create_info
._folders
.begin(); it
!=create_info
._folders
.end(); ++it
)
75 _dirs
.push_back(ShellDirectory(GetDesktopFolder(), *it
, _hwnd
));
77 _next_id
= IDC_FIRST_MENU
;
81 _border_top
= create_info
._border_top
;
82 _bottom_max
= INT_MAX
;
84 _floating_btn
= create_info
._border_top
? true: false;
86 _scroll_mode
= SCROLL_NOT
;
90 _last_pos
= WindowRect(hwnd
).pos();
91 #ifdef _LIGHT_STARTMENU
97 StartMenu::~StartMenu()
99 SendParent(PM_STARTMENU_CLOSED
);
103 // We need this wrapper function for s_wcStartMenu, it calls the WIN32 API,
104 // though static C++ initializers are not allowed for Winelib applications.
105 BtnWindowClass
& StartMenu::GetWndClasss()
107 static BtnWindowClass
s_wcStartMenu(CLASSNAME_STARTMENU
);
109 return s_wcStartMenu
;
113 Window::CREATORFUNC_INFO
StartMenu::s_def_creator
= STARTMENU_CREATOR(StartMenu
);
115 HWND
StartMenu::Create(int x
, int y
, const StartMenuFolders
& folders
, HWND hwndParent
, LPCTSTR title
, CREATORFUNC_INFO creator
)
117 UINT style
, ex_style
;
121 style
= WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
;
123 top_height
= STARTMENU_TOP_BTN_SPACE
;
125 style
= WS_POPUP
|WS_CAPTION
|WS_SYSMENU
|WS_CLIPCHILDREN
|WS_VISIBLE
;
126 ex_style
= WS_EX_TOOLWINDOW
;
130 RECT rect
= {x
, y
-STARTMENU_LINE_HEIGHT
-top_height
, x
+STARTMENU_WIDTH_MIN
, y
};
132 #ifndef _LIGHT_STARTMENU
133 rect
.top
+= STARTMENU_LINE_HEIGHT
;
136 AdjustWindowRectEx(&rect
, style
, FALSE
, ex_style
);
138 StartMenuCreateInfo create_info
;
140 create_info
._folders
= folders
;
141 create_info
._border_top
= top_height
;
142 create_info
._creator
= creator
;
145 create_info
._title
= title
;
147 HWND hwnd
= Window::Create(creator
, &create_info
, ex_style
, GetWndClasss(), title
,
148 style
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndParent
);
150 // make sure the window is not off the screen
157 LRESULT
StartMenu::Init(LPCREATESTRUCT pcs
)
162 if (super::Init(pcs
))
165 // create buttons for registered entries in _entries
166 for(ShellEntryMap::const_iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
167 const StartMenuEntry
& sme
= it
->second
;
168 bool hasSubmenu
= false;
170 for(ShellEntrySet::const_iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
)
171 if ((*it
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
174 #ifdef _LIGHT_STARTMENU
175 _buttons
.push_back(SMBtnInfo(sme
, it
->first
, hasSubmenu
));
177 AddButton(sme
._title
, sme
._hIcon
, hasSubmenu
, it
->first
);
181 #ifdef _LIGHT_STARTMENU
182 if (_buttons
.empty())
184 if (!GetWindow(_hwnd
, GW_CHILD
))
186 AddButton(ResString(IDS_EMPTY
), ICID_NONE
, false, 0, false);
188 #ifdef _LIGHT_STARTMENU
192 #ifdef _LAZY_ICONEXTRACT
193 PostMessage(_hwnd
, PM_UPDATE_ICONS
, 0, 0);
195 } catch(COMException
& e
) {
196 HandleException(e
, pcs
->hwndParent
); // destroys the start menu window while switching focus
202 void StartMenu::AddEntries()
204 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
205 StartMenuDirectory
& smd
= *it
;
206 ShellDirectory
& dir
= smd
._dir
;
211 #ifdef _LAZY_ICONEXTRACT
212 dir
.smart_scan(SCAN_FILESYSTEM
); // lazy icon extraction, try to read directly from filesystem
214 dir
.smart_scan(SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
218 AddShellEntries(dir
, -1, smd
._subfolders
);
223 void StartMenu::AddShellEntries(const ShellDirectory
& dir
, int max
, bool subfolders
)
227 for(Entry
*entry
=dir
._down
; entry
; entry
=entry
->_next
) {
228 // hide files like "desktop.ini"
229 if (entry
->_shell_attribs
& SFGAO_HIDDEN
)
230 //not appropriate for drive roots: if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
233 // hide subfolders if requested
235 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
238 // only 'max' entries shall be added.
242 if (entry
->_etype
== ET_SHELL
)
243 AddEntry(dir
._folder
, static_cast<ShellEntry
*>(entry
));
245 AddEntry(dir
._folder
, entry
);
250 LRESULT
StartMenu::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
254 PaintCanvas
canvas(_hwnd
);
259 ResizeButtons(LOWORD(lparam
)-_border_left
);
263 POINTS
& pos
= MAKEPOINTS(lparam
);
265 // move open submenus of floating menus
267 int dx
= pos
.x
- _last_pos
.x
;
268 int dy
= pos
.y
- _last_pos
.y
;
271 WindowRect
rt(_submenu
);
272 SetWindowPos(_submenu
, 0, rt
.left
+dx
, rt
.top
+dy
, 0, 0, SWP_NOSIZE
|SWP_NOACTIVATE
);
273 //MoveVisible(_submenu);
282 LRESULT res
= super::WndProc(nmsg
, wparam
, lparam
);
284 if (res
>=HTSIZEFIRST
&& res
<=HTSIZELAST
)
285 return HTCLIENT
; // disable window resizing
289 case WM_LBUTTONDOWN
: {
292 // check mouse cursor for coordinates of floating button
293 GetFloatingButtonRect(&rect
);
295 if (PtInRect(&rect
, Point(lparam
))) {
296 // create a floating copy of the current start menu
297 WindowRect
pos(_hwnd
);
299 ///@todo do something similar to StartMenuRoot::TrackStartmenu() in order to automatically close submenus when clicking on the desktop background
300 StartMenu::Create(pos
.left
+3, pos
.bottom
-3, _create_info
._folders
, 0, _create_info
._title
, _create_info
._creator
);
304 #ifdef _LIGHT_STARTMENU
305 int id
= ButtonHitTest(Point(lparam
));
308 Command(id
, BN_CLICKED
);
313 if ((wparam
&0xFFF0) == SC_SIZE
)
314 return 0; // disable window resizing
318 // close start menu when activating another application
321 break; // don't call super::WndProc in case "this" has been deleted
326 #ifdef _LIGHT_STARTMENU
327 if (_scroll_mode
!= SCROLL_NOT
) {
334 #ifdef _LIGHT_STARTMENU
336 // automatically set the focus to startmenu entries when moving the mouse over them
337 if (lparam
!= _last_mouse_pos
) { // don't process WM_MOUSEMOVE when opening submenus using keyboard navigation
341 RECT rect_up
, rect_down
;
343 GetArrowButtonRects(&rect_up
, &rect_down
);
345 SCROLL_MODE scroll_mode
= SCROLL_NOT
;
347 if (PtInRect(&rect_up
, pt
))
348 scroll_mode
= SCROLL_UP
;
349 else if (PtInRect(&rect_down
, pt
))
350 scroll_mode
= SCROLL_DOWN
;
352 if (scroll_mode
!= _scroll_mode
) {
353 if (scroll_mode
== SCROLL_NOT
) {
358 SetTimer(_hwnd
, 0, 150, NULL
); // 150 ms scroll interval
362 _scroll_mode
= scroll_mode
;
366 int new_id
= ButtonHitTest(pt
);
368 if (new_id
!= _selected_id
)
369 SelectButton(new_id
);
371 _last_mouse_pos
= lparam
;
376 if (_scroll_mode
== SCROLL_UP
) {
377 if (_scroll_pos
> 0) {
379 InvalidateRect(_hwnd
, NULL
, TRUE
);
382 if (_scroll_pos
<= _invisible_lines
) {
384 InvalidateRect(_hwnd
, NULL
, TRUE
);
393 case PM_STARTENTRY_FOCUSED
: { ///@todo use TrackMouseEvent() and WM_MOUSEHOVER to wait a bit before opening submenus
394 BOOL hasSubmenu
= wparam
;
395 HWND hctrl
= (HWND
)lparam
;
397 // automatically open submenus
399 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
400 //SendMessage(_hwnd, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hctrl),BN_CLICKED), (LPARAM)hctrl);
401 Command(GetDlgCtrlID(hctrl
), BN_CLICKED
);
403 // close any open submenu
404 CloseOtherSubmenus();
409 #ifdef _LAZY_ICONEXTRACT
410 case PM_UPDATE_ICONS
:
411 UpdateIcons(/*wparam*/);
415 case PM_STARTENTRY_LAUNCHED
:
416 if (GetWindowStyle(_hwnd
) & WS_CAPTION
) // don't automatically close floating menus
419 // route message to the parent menu and close menus after launching an entry
420 if (!SendParent(nmsg
, wparam
, lparam
))
422 return 1; // signal that we have received and processed the message
424 case PM_STARTMENU_CLOSED
:
428 case PM_SELECT_ENTRY
:
429 SelectButtonIndex(0, wparam
?true:false);
433 return super::WndProc(nmsg
, wparam
, lparam
);
440 #ifdef _LIGHT_STARTMENU
442 int StartMenu::ButtonHitTest(POINT pt
)
444 ClientRect
clnt(_hwnd
);
445 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
447 if (pt
.x
<rect
.left
|| pt
.x
>rect
.right
)
450 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
451 const SMBtnInfo
& info
= *it
;
456 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
458 if (rect
.bottom
> _bottom_max
)
461 if (pt
.y
< rect
.bottom
) // PtInRect(&rect, pt)
464 rect
.top
= rect
.bottom
;
470 void StartMenu::InvalidateSelection()
475 ClientRect
clnt(_hwnd
);
476 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
478 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
479 const SMBtnInfo
& info
= *it
;
481 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
483 if (info
._id
== _selected_id
) {
484 InvalidateRect(_hwnd
, &rect
, TRUE
);
488 rect
.top
= rect
.bottom
;
492 const SMBtnInfo
* StartMenu::GetButtonInfo(int id
) const
494 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
)
501 bool StartMenu::SelectButton(int id
, bool open_sub
)
506 if (id
== _selected_id
)
509 InvalidateSelection();
511 const SMBtnInfo
* btn
= GetButtonInfo(id
);
513 if (btn
&& btn
->_enabled
) {
516 InvalidateSelection();
518 // automatically open submenus
519 if (btn
->_hasSubmenu
) {
523 CloseOtherSubmenus(); // close any open submenu
532 bool StartMenu::OpenSubmenu(bool select_first
)
534 if (_selected_id
== -1)
537 InvalidateSelection();
539 const SMBtnInfo
* btn
= GetButtonInfo(_selected_id
);
541 // automatically open submenus
542 if (btn
->_hasSubmenu
) {
543 //@@ allows destroying of startmenu when processing PM_UPDATE_ICONS -> GPF
544 UpdateWindow(_hwnd
); // draw focused button before waiting on submenu creation
545 Command(_selected_id
, BN_CLICKED
);
547 if (select_first
&& _submenu
)
548 SendMessage(_submenu
, PM_SELECT_ENTRY
, (WPARAM
)false, 0);
556 int StartMenu::GetSelectionIndex()
558 if (_selected_id
== -1)
561 for(int i
=0; i
<(int)_buttons
.size(); ++i
)
562 if (_buttons
[i
]._id
== _selected_id
)
568 bool StartMenu::SelectButtonIndex(int idx
, bool open_sub
)
570 if (idx
>=0 && idx
<(int)_buttons
.size())
571 return SelectButton(_buttons
[idx
]._id
, open_sub
);
576 void StartMenu::ProcessKey(int vk
)
581 Command(_selected_id
, BN_CLICKED
);
593 SelectButtonIndex(0, false);
597 SelectButtonIndex(_buttons
.size()-1, false);
602 CloseOtherSubmenus();
603 else if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) // don't automatically close floating menus
604 DestroyWindow(_hwnd
);
616 if (vk
>='0' && vk
<='Z')
617 JumpToNextShortcut(vk
);
621 bool StartMenu::Navigate(int step
)
623 int idx
= GetSelectionIndex();
629 idx
= _buttons
.size() - step
;
634 if (idx
<0 || idx
>(int)_buttons
.size())
637 if (SelectButtonIndex(idx
, false))
644 bool StartMenu::JumpToNextShortcut(char c
)
646 int cur_idx
= GetSelectionIndex();
654 SMBtnVector::const_iterator cur_it
= _buttons
.begin();
655 cur_it
+= cur_idx
+ 1;
657 // first search down from current item...
658 SMBtnVector::const_iterator it
= cur_it
;
659 for(; it
!=_buttons
.end(); ++it
) {
660 const SMBtnInfo
& btn
= *it
;
662 if (!btn
._title
.empty() && toupper((TBYTE
)btn
._title
.at(0)) == c
) {
664 first_found
= btn
._id
;
670 // ...now search from top to the current item
671 it
= _buttons
.begin();
672 for(; it
!=_buttons
.end() && it
!=cur_it
; ++it
) {
673 const SMBtnInfo
& btn
= *it
;
675 if (!btn
._title
.empty() && toupper((TBYTE
)btn
._title
.at(0)) == c
) {
677 first_found
= btn
._id
;
684 SelectButton(first_found
);
687 Command(first_found
, BN_CLICKED
);
694 #endif // _LIGHT_STARTMENU
697 bool StartMenu::GetButtonRect(int id
, PRECT prect
) const
699 #ifdef _LIGHT_STARTMENU
700 ClientRect
clnt(_hwnd
);
701 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
703 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
704 const SMBtnInfo
& info
= *it
;
706 rect
.bottom
= rect
.top
+ (info
._id
==-1? STARTMENU_SEP_HEIGHT
: STARTMENU_LINE_HEIGHT
);
708 if (info
._id
== id
) {
713 rect
.top
= rect
.bottom
;
718 HWND btn
= GetDlgItem(_hwnd
, id
);
721 GetWindowRect(btn
, prect
);
722 ScreenToClient(_hwnd
, prect
);
731 void StartMenu::DrawFloatingButton(HDC hdc
)
733 static ResIconEx
floatingIcon(IDI_FLOATING
, 8, 4);
735 ClientRect
clnt(_hwnd
);
737 DrawIconEx(hdc
, clnt
.right
-12, 0, floatingIcon
, 8, 4, 0, 0, DI_NORMAL
);
740 void StartMenu::GetFloatingButtonRect(LPRECT prect
)
742 GetClientRect(_hwnd
, prect
);
745 prect
->left
= prect
->right
- 8;
750 void StartMenu::DrawArrows(HDC hdc
)
752 static ResIconEx
arrowUpIcon(IDI_ARROW_UP
, 8, 4);
753 static ResIconEx
arrowDownIcon(IDI_ARROW_DOWN
, 8, 4);
755 ClientRect
clnt(_hwnd
);
757 DrawIconEx(hdc
, clnt
.right
/2-4, _floating_btn
?3:1, arrowUpIcon
, 8, 4, 0, 0, DI_NORMAL
);
758 DrawIconEx(hdc
, clnt
.right
/2-4, clnt
.bottom
-5, arrowDownIcon
, 8, 4, 0, 0, DI_NORMAL
);
761 void StartMenu::GetArrowButtonRects(LPRECT prect_up
, LPRECT prect_down
)
763 GetClientRect(_hwnd
, prect_up
);
764 *prect_down
= *prect_up
;
766 // prect_up->left = prect_up->right/2 - 4;
767 // prect_up->right = prect_up->left + 8;
768 prect_up
->right
-= 8;
769 prect_up
->top
= _floating_btn
? 3: 1;
770 prect_up
->bottom
= prect_up
->top
+ 4;
772 // prect_down->left = prect_down->right/2 - 4;
773 // prect_down->right = prect_down->left + 8;
774 prect_down
->right
-= 8;
775 prect_down
->top
= prect_down
->bottom
- 5;
779 void StartMenu::Paint(PaintCanvas
& canvas
)
782 DrawFloatingButton(canvas
);
784 #ifdef _LIGHT_STARTMENU
788 ClientRect
clnt(_hwnd
);
789 RECT rect
= {_border_left
, _border_top
, clnt
.right
, STARTMENU_LINE_HEIGHT
};
791 int sep_width
= rect
.right
-rect
.left
- 4;
793 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
794 BkMode
bk_mode(canvas
, TRANSPARENT
);
796 for(SMBtnVector::const_iterator it
=_buttons
.begin()+_scroll_pos
; it
!=_buttons
.end(); ++it
) {
797 const SMBtnInfo
& btn
= *it
;
799 if (rect
.top
> canvas
.rcPaint
.bottom
)
802 if (btn
._id
== -1) { // a separator?
803 rect
.bottom
= rect
.top
+ STARTMENU_SEP_HEIGHT
;
805 if (rect
.bottom
> _bottom_max
)
808 BrushSelection
brush_sel(canvas
, GetSysColorBrush(COLOR_BTNSHADOW
));
809 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2-1, sep_width
, 1, PATCOPY
);
811 SelectBrush(canvas
, GetSysColorBrush(COLOR_BTNHIGHLIGHT
));
812 PatBlt(canvas
, rect
.left
+2, rect
.top
+STARTMENU_SEP_HEIGHT
/2, sep_width
, 1, PATCOPY
);
814 rect
.bottom
= rect
.top
+ STARTMENU_LINE_HEIGHT
;
816 if (rect
.bottom
> _bottom_max
)
819 if (rect
.top
>= canvas
.rcPaint
.top
)
820 DrawStartMenuButton(canvas
, rect
, btn
._title
, btn
, btn
._id
==_selected_id
, false);
823 rect
.top
= rect
.bottom
;
828 #ifdef _LAZY_ICONEXTRACT
829 void StartMenu::UpdateIcons(/*int idx*/)
833 #ifdef _SINGLE_ICONEXTRACT
836 int idx
= _scroll_pos
;
838 for(; idx
<(int)_buttons
.size(); ++idx
) {
839 SMBtnInfo
& btn
= _buttons
[idx
];
841 if (btn
._icon_id
==ICID_UNKNOWN
&& btn
._id
>0) {
842 StartMenuEntry
& sme
= _entries
[btn
._id
];
844 btn
._icon_id
= ICID_NONE
;
846 for(ShellEntrySet::iterator it
=sme
._entries
.begin(); it
!=sme
._entries
.end(); ++it
) {
849 if (entry
->_icon_id
== ICID_UNKNOWN
)
851 entry
->extract_icon();
852 } catch(COMException
&) {
853 // ignore unexpected exceptions while extracting icons
856 if (entry
->_icon_id
> ICID_NONE
) {
857 btn
._icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
861 GetButtonRect(btn
._id
, &rect
);
863 if (rect
.bottom
> _bottom_max
)
866 WindowCanvas
canvas(_hwnd
);
867 DrawStartMenuButton(canvas
, rect
, NULL
, btn
, btn
._id
==_selected_id
, false);
869 //InvalidateRect(_hwnd, &rect, FALSE);
870 //UpdateWindow(_hwnd);
879 // if (++idx < (int)_buttons.size())
880 // PostMessage(_hwnd, PM_UPDATE_ICONS, idx, 0);
884 int icons_extracted
= 0;
885 int icons_updated
= 0;
887 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
888 ShellDirectory
& dir
= it
->_dir
;
890 icons_extracted
+= dir
.extract_icons();
893 if (icons_extracted
) {
894 for(ShellEntryMap::iterator it1
=_entries
.begin(); it1
!=_entries
.end(); ++it1
) {
895 StartMenuEntry
& sme
= it1
->second
;
898 sme
._hIcon
= (HICON
)-1;
900 for(ShellEntrySet::const_iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
901 const Entry
* sm_entry
= *it2
;
903 if (sm_entry
->_hIcon
) {
904 sme
._hIcon
= sm_entry
->_hIcon
;
911 for(SMBtnVector::iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
912 SMBtnInfo
& info
= *it
;
914 if (info
._id
>0 && !info
._hIcon
) {
915 info
._hIcon
= _entries
[info
._id
]._hIcon
;
922 InvalidateRect(_hwnd
, NULL
, FALSE
);
930 // resize child button controls to accomodate for new window size
931 void StartMenu::ResizeButtons(int cx
)
933 HDWP hdwp
= BeginDeferWindowPos(10);
935 for(HWND ctrl
=GetWindow(_hwnd
,GW_CHILD
); ctrl
; ctrl
=GetNextWindow(ctrl
,GW_HWNDNEXT
)) {
938 if (rt
.right
!= cx
) {
939 int height
= rt
.bottom
- rt
.top
;
941 // special handling for separator controls
942 if (!height
&& (GetWindowStyle(ctrl
)&SS_TYPEMASK
)==SS_ETCHEDHORZ
)
945 hdwp
= DeferWindowPos(hdwp
, ctrl
, 0, 0, 0, cx
, height
, SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
);
949 EndDeferWindowPos(hdwp
);
953 int StartMenu::Command(int id
, int code
)
955 #ifndef _LIGHT_STARTMENU
963 ShellEntryMap::iterator found
= _entries
.find(id
);
965 if (found
!= _entries
.end()) {
966 ActivateEntry(id
, found
->second
._entries
);
970 return super::Command(id
, code
);
971 #ifndef _LIGHT_STARTMENU
980 StartMenuEntry
& StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, Entry
* entry
)
982 // search for an already existing subdirectory entry with the same name
983 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
984 for(ShellEntryMap::iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
985 StartMenuEntry
& sme
= it
->second
;
987 if (sme
._title
== title
) ///@todo speed up by using a map indexed by name
988 for(ShellEntrySet::iterator it2
=sme
._entries
.begin(); it2
!=sme
._entries
.end(); ++it2
) {
989 if ((*it2
)->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
990 // merge the new shell entry with the existing of the same name
991 sme
._entries
.insert(entry
);
997 StartMenuEntry
& sme
= AddEntry(title
, icon_id
);
999 sme
._entries
.insert(entry
);
1004 StartMenuEntry
& StartMenu::AddEntry(const String
& title
, ICON_ID icon_id
, int id
)
1009 StartMenuEntry
& sme
= _entries
[id
];
1012 sme
._icon_id
= icon_id
;
1017 StartMenuEntry
& StartMenu::AddEntry(const ShellFolder folder
, ShellEntry
* entry
)
1021 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1022 icon_id
= ICID_FOLDER
;
1024 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
1026 return AddEntry(folder
.get_name(entry
->_pidl
), icon_id
, entry
);
1029 StartMenuEntry
& StartMenu::AddEntry(const ShellFolder folder
, Entry
* entry
)
1033 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1034 icon_id
= ICID_FOLDER
;
1036 icon_id
= (ICON_ID
)/*@@*/ entry
->_icon_id
;
1038 return AddEntry(entry
->_display_name
, icon_id
, entry
);
1042 void StartMenu::AddButton(LPCTSTR title
, ICON_ID icon_id
, bool hasSubmenu
, int id
, bool enabled
)
1044 #ifdef _LIGHT_STARTMENU
1045 _buttons
.push_back(SMBtnInfo(title
, icon_id
, id
, hasSubmenu
, enabled
));
1047 DWORD style
= enabled
? WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
: WS_VISIBLE
|WS_CHILD
|BS_OWNERDRAW
|WS_DISABLED
;
1049 WindowRect
rect(_hwnd
);
1050 ClientRect
clnt(_hwnd
);
1052 // increase window height to make room for the new button
1053 rect
.top
-= STARTMENU_LINE_HEIGHT
;
1055 // move down if we are too high now
1057 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1058 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1061 WindowCanvas
canvas(_hwnd
);
1062 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1064 // widen window, if it is too small
1065 int text_width
= GetStartMenuBtnTextWidth(canvas
, title
, _hwnd
) + 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1067 int cx
= clnt
.right
- _border_left
;
1068 if (text_width
> cx
)
1069 rect
.right
+= text_width
-cx
;
1071 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1073 StartMenuCtrl(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
,
1074 title
, id
, g_Globals
._icon_cache
.get_icon(icon_id
)._hIcon
, hasSubmenu
, style
);
1078 void StartMenu::AddSeparator()
1080 #ifdef _LIGHT_STARTMENU
1081 _buttons
.push_back(SMBtnInfo(NULL
, ICID_NONE
, -1, false));
1083 WindowRect
rect(_hwnd
);
1084 ClientRect
clnt(_hwnd
);
1086 // increase window height to make room for the new separator
1087 rect
.top
-= STARTMENU_SEP_HEIGHT
;
1089 // move down if we are too high now
1091 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1092 rect
.bottom
+= STARTMENU_LINE_HEIGHT
;
1095 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1097 StartMenuSeparator(_hwnd
, _border_left
, clnt
.bottom
, rect
.right
-rect
.left
-_border_left
);
1102 bool StartMenu::CloseOtherSubmenus(int id
)
1105 if (IsWindow(_submenu
)) {
1106 if (_submenu_id
== id
)
1110 DestroyWindow(_submenu
);
1111 // _submenu should be reset automatically by PM_STARTMENU_CLOSED, but safety first...
1122 void StartMenu::CreateSubmenu(int id
, LPCTSTR title
, CREATORFUNC_INFO creator
)
1124 CreateSubmenu(id
, StartMenuFolders(), title
, creator
);
1127 bool StartMenu::CreateSubmenu(int id
, int folder_id
, LPCTSTR title
, CREATORFUNC_INFO creator
)
1130 SpecialFolderPath
folder(folder_id
, _hwnd
);
1132 StartMenuFolders new_folders
;
1133 new_folders
.push_back(folder
);
1135 CreateSubmenu(id
, new_folders
, title
, creator
);
1138 } catch(COMException
&) {
1139 // ignore Exception and don't display anything
1140 CloseOtherSubmenus(id
);
1141 _buttons
[GetSelectionIndex()]._enabled
= false; // disable entries for non-existing folders
1146 bool StartMenu::CreateSubmenu(int id
, int folder_id1
, int folder_id2
, LPCTSTR title
, CREATORFUNC_INFO creator
)
1148 StartMenuFolders new_folders
;
1151 new_folders
.push_back(SpecialFolderPath(folder_id1
, _hwnd
));
1152 } catch(COMException
&) {
1156 new_folders
.push_back(SpecialFolderPath(folder_id2
, _hwnd
));
1157 } catch(COMException
&) {
1160 if (!new_folders
.empty()) {
1161 CreateSubmenu(id
, new_folders
, title
, creator
);
1164 CloseOtherSubmenus(id
);
1165 _buttons
[GetSelectionIndex()]._enabled
= false; // disable entries for non-existing folders
1170 void StartMenu::CreateSubmenu(int id
, const StartMenuFolders
& new_folders
, LPCTSTR title
, CREATORFUNC_INFO creator
)
1172 // Only open one submenu at a time.
1173 if (!CloseOtherSubmenus(id
))
1179 if (GetButtonRect(id
, &rect
)) {
1180 ClientToScreen(_hwnd
, &rect
);
1182 x
= rect
.right
; // Submenus should overlap their parent a bit.
1183 y
= rect
.top
+STARTMENU_LINE_HEIGHT
+_border_top
/*own border*/ -STARTMENU_TOP_BTN_SPACE
/*border of new submenu*/;
1185 WindowRect
pos(_hwnd
);
1192 _submenu
= StartMenu::Create(x
, y
, new_folders
, _hwnd
, title
, creator
);
1196 void StartMenu::ActivateEntry(int id
, const ShellEntrySet
& entries
)
1198 StartMenuFolders new_folders
;
1201 for(ShellEntrySet::const_iterator it
=entries
.begin(); it
!=entries
.end(); ++it
) {
1202 Entry
* entry
= const_cast<Entry
*>(*it
);
1204 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1206 ///@todo If the user explicitly clicked on a submenu, display this folder as floating start menu.
1208 if (entry
->_etype
== ET_SHELL
)
1209 new_folders
.push_back(entry
->create_absolute_pidl());
1211 TCHAR path
[MAX_PATH
];
1213 if (entry
->get_path(path
))
1214 new_folders
.push_back(path
);
1218 title
= entry
->_display_name
;
1220 // The entry is no subdirectory, so there can only be one shell entry.
1221 assert(entries
.size()==1);
1223 HWND hparent
= GetParent(_hwnd
);
1224 ShellPath shell_path
= entry
->create_absolute_pidl();
1226 // close start menus after launching the selected entry
1229 ///@todo launch in the background; specify correct HWND for error message box titles
1230 SHELLEXECUTEINFO shexinfo
;
1232 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
1233 shexinfo
.fMask
= SEE_MASK_INVOKEIDLIST
; // SEE_MASK_IDLIST is also possible.
1234 shexinfo
.hwnd
= hparent
;
1235 shexinfo
.lpVerb
= NULL
;
1236 shexinfo
.lpFile
= NULL
;
1237 shexinfo
.lpParameters
= NULL
;
1238 shexinfo
.lpDirectory
= NULL
;
1239 shexinfo
.nShow
= SW_SHOWNORMAL
;
1241 shexinfo
.lpIDList
= &*shell_path
;
1243 // add PIDL to the recent file list
1244 SHAddToRecentDocs(SHARD_PIDL
, shexinfo
.lpIDList
);
1246 if (!ShellExecuteEx(&shexinfo
))
1247 display_error(hparent
, GetLastError());
1249 // we may have deleted 'this' - ensure we leave the loop and function
1254 if (!new_folders
.empty()) {
1255 // Only open one submenu at a time.
1256 if (!CloseOtherSubmenus(id
))
1259 CreateSubmenu(id
, new_folders
, title
);
1264 /// close all windows of the start menu popup
1265 void StartMenu::CloseStartMenu(int id
)
1267 if (!(GetWindowStyle(_hwnd
) & WS_CAPTION
)) { // don't automatically close floating menus
1268 if (!SendParent(PM_STARTENTRY_LAUNCHED
, id
, (LPARAM
)_hwnd
))
1269 DestroyWindow(_hwnd
);
1270 } else if (_submenu
) // instead close submenus of floating parent menus
1275 int GetStartMenuBtnTextWidth(HDC hdc
, LPCTSTR title
, HWND hwnd
)
1277 RECT rect
= {0, 0, 0, 0};
1278 DrawText(hdc
, title
, -1, &rect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_CALCRECT
);
1280 return rect
.right
-rect
.left
;
1283 #ifdef _LIGHT_STARTMENU
1284 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, const SMBtnInfo
& btn
, bool has_focus
, bool pushed
)
1286 void DrawStartMenuButton(HDC hdc
, const RECT
& rect
, LPCTSTR title
, HICON hIcon
,
1287 bool hasSubmenu
, bool enabled
, bool has_focus
, bool pushed
);
1290 UINT style
= DFCS_BUTTONPUSH
;
1293 style
|= DFCS_INACTIVE
;
1295 POINT iconPos
= {rect
.left
+2, (rect
.top
+rect
.bottom
-16)/2};
1296 RECT textRect
= {rect
.left
+16+4, rect
.top
+2, rect
.right
-4, rect
.bottom
-4};
1299 style
|= DFCS_PUSHED
;
1300 ++iconPos
.x
; ++iconPos
.y
;
1301 ++textRect
.left
; ++textRect
.top
;
1302 ++textRect
.right
; ++textRect
.bottom
;
1305 int bk_color_idx
= COLOR_BTNFACE
;
1306 int text_color_idx
= COLOR_BTNTEXT
;
1309 bk_color_idx
= COLOR_HIGHLIGHT
;
1310 text_color_idx
= COLOR_HIGHLIGHTTEXT
;
1313 COLORREF bk_color
= GetSysColor(bk_color_idx
);
1314 HBRUSH bk_brush
= GetSysColorBrush(bk_color_idx
);
1317 FillRect(hdc
, &rect
, bk_brush
);
1319 if (btn
._icon_id
> ICID_NONE
)
1320 g_Globals
._icon_cache
.get_icon(btn
._icon_id
).draw(hdc
, iconPos
.x
, iconPos
.y
, 16, 16, bk_color
, bk_brush
);
1322 // draw submenu arrow at the right
1323 if (btn
._hasSubmenu
) {
1324 static SmallIcon
arrowIcon(IDI_ARROW
);
1325 static SmallIcon
selArrowIcon(IDI_ARROW_SELECTED
);
1327 DrawIconEx(hdc
, rect
.right
-16, iconPos
.y
,
1328 has_focus
? selArrowIcon
: arrowIcon
,
1329 16, 16, 0, bk_brush
, DI_NORMAL
);
1333 BkMode
bk_mode(hdc
, TRANSPARENT
);
1335 if (!btn
._enabled
) // dis->itemState & (ODS_DISABLED|ODS_GRAYED)
1336 DrawGrayText(hdc
, &textRect
, title
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1338 TextColor
lcColor(hdc
, GetSysColor(text_color_idx
));
1339 DrawText(hdc
, title
, -1, &textRect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_VCENTER
);
1345 #ifdef _LIGHT_STARTMENU
1347 void StartMenu::ResizeToButtons()
1349 WindowRect
rect(_hwnd
);
1351 WindowCanvas
canvas(_hwnd
);
1352 FontSelection
font(canvas
, GetStockFont(DEFAULT_GUI_FONT
));
1354 int max_width
= STARTMENU_WIDTH_MIN
;
1357 for(SMBtnVector::const_iterator it
=_buttons
.begin(); it
!=_buttons
.end(); ++it
) {
1358 int w
= GetStartMenuBtnTextWidth(canvas
, it
->_title
, _hwnd
);
1364 height
+= STARTMENU_SEP_HEIGHT
;
1366 height
+= STARTMENU_LINE_HEIGHT
;
1369 // calculate new window size
1370 int text_width
= max_width
+ 16/*icon*/ + 10/*placeholder*/ + 16/*arrow*/;
1372 RECT rt_hgt
= {rect
.left
, rect
.bottom
-_border_top
-height
, rect
.left
+_border_left
+text_width
, rect
.bottom
};
1373 AdjustWindowRectEx(&rt_hgt
, GetWindowStyle(_hwnd
), FALSE
, GetWindowExStyle(_hwnd
));
1375 // ignore movement, only look at the size change
1376 rect
.right
= rect
.left
+ (rt_hgt
.right
-rt_hgt
.left
);
1377 rect
.top
= rect
.bottom
- (rt_hgt
.bottom
-rt_hgt
.top
);
1379 // move down if we are too high
1386 // enable scroll mode for long start menus, which span more than the whole screen height
1387 int cyscreen
= GetSystemMetrics(SM_CYSCREEN
);
1390 if (rect
.bottom
> cyscreen
) {
1393 _invisible_lines
= (rect
.bottom
-cyscreen
+(STARTMENU_LINE_HEIGHT
-1))/STARTMENU_LINE_HEIGHT
+ 1;
1394 rect
.bottom
-= _invisible_lines
* STARTMENU_LINE_HEIGHT
;
1396 bottom_max
= rect
.bottom
;
1399 rect
.bottom
+= 6; // lower scroll arrow
1401 _border_top
+= 6; // upper scroll arrow
1402 rect
.bottom
+= 2*6; // upper+lower scroll arrow
1406 MoveWindow(_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1409 POINT pt
= {0, bottom_max
};
1411 ScreenToClient(_hwnd
, &pt
);
1417 #else // _LIGHT_STARTMENU
1419 LRESULT
StartMenuButton::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1423 // automatically set the focus to startmenu entries when moving the mouse over them
1424 if (GetFocus()!=_hwnd
&& !(GetWindowStyle(_hwnd
)&WS_DISABLED
))
1429 PostParent(PM_STARTENTRY_FOCUSED
, _hasSubmenu
, (LPARAM
)_hwnd
);
1433 // route WM_CANCELMODE to the startmenu window
1434 return SendParent(nmsg
, wparam
, lparam
);
1437 return super::WndProc(nmsg
, wparam
, lparam
);
1443 void StartMenuButton::DrawItem(LPDRAWITEMSTRUCT dis
)
1445 TCHAR title
[BUFFER_LEN
];
1447 GetWindowText(_hwnd
, title
, BUFFER_LEN
);
1449 DrawStartMenuButton(dis
->hDC
, dis
->rcItem
, title
, _hIcon
,
1451 !(dis
->itemState
& ODS_DISABLED
),
1452 dis
->itemState
&ODS_FOCUS
? true: false,
1453 dis
->itemState
&ODS_SELECTED
? true: false);
1459 StartMenuRoot::StartMenuRoot(HWND hwnd
)
1462 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1463 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCOMMONGROUPS
))
1466 // insert directory "All Users\Start Menu"
1467 ShellDirectory
cmn_startmenu(GetDesktopFolder(), SpecialFolderPath(CSIDL_COMMON_STARTMENU
, _hwnd
), _hwnd
);
1468 _dirs
.push_back(StartMenuDirectory(cmn_startmenu
, false)); // don't add subfolders
1469 } catch(COMException
&) {
1470 // ignore exception and don't show additional shortcuts
1474 // insert directory "<user name>\Start Menu"
1476 ShellDirectory
usr_startmenu(GetDesktopFolder(), SpecialFolderPath(CSIDL_STARTMENU
, _hwnd
), _hwnd
);
1477 _dirs
.push_back(StartMenuDirectory(usr_startmenu
, false)); // don't add subfolders
1478 } catch(COMException
&) {
1479 // ignore exception and don't show additional shortcuts
1482 // read size of logo bitmap
1484 GetObject(ResBitmap(IDB_LOGOV
), sizeof(BITMAP
), &bmp_hdr
);
1485 _logo_size
.cx
= bmp_hdr
.bmWidth
;
1486 _logo_size
.cy
= bmp_hdr
.bmHeight
;
1488 _border_left
= _logo_size
.cx
+ 1;
1492 HWND
StartMenuRoot::Create(HWND hwndOwner
)
1494 WindowRect
pos(hwndOwner
);
1496 RECT rect
= {pos
.left
, pos
.top
-STARTMENU_LINE_HEIGHT
-4, pos
.left
+STARTMENU_WIDTH_MIN
, pos
.top
};
1498 #ifndef _LIGHT_STARTMENU
1499 rect
.top
+= STARTMENU_LINE_HEIGHT
;
1502 AdjustWindowRectEx(&rect
, WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
|WS_VISIBLE
, FALSE
, 0);
1504 return Window::Create(WINDOW_CREATOR(StartMenuRoot
), 0, GetWndClasss(), TITLE_STARTMENU
,
1505 WS_POPUP
|WS_THICKFRAME
|WS_CLIPCHILDREN
,
1506 rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, hwndOwner
);
1510 void StartMenuRoot::TrackStartmenu()
1515 #ifdef _LIGHT_STARTMENU
1519 // show previously hidden start menu
1520 ShowWindow(hwnd
, SW_SHOW
);
1521 SetForegroundWindow(hwnd
);
1523 while(IsWindow(hwnd
)) {
1524 if (!GetMessage(&msg
, 0, 0, 0)) {
1525 PostQuitMessage(msg
.wParam
);
1529 // Check for a mouse click on any window, which is not part of the start menu
1530 if (msg
.message
==WM_LBUTTONDOWN
|| msg
.message
==WM_MBUTTONDOWN
|| msg
.message
==WM_RBUTTONDOWN
) {
1531 StartMenu
* menu_wnd
= NULL
;
1533 for(HWND hwnd
=msg
.hwnd
; hwnd
; hwnd
=GetParent(hwnd
)) {
1534 menu_wnd
= WINDOW_DYNAMIC_CAST(StartMenu
, hwnd
);
1547 if (pretranslate_msg(&msg
))
1550 if (dispatch_dialog_msg(&msg
))
1553 TranslateMessage(&msg
);
1556 DispatchMessage(&msg
);
1557 } catch(COMException
& e
) {
1558 HandleException(e
, _hwnd
);
1560 } catch(COMException
& e
) {
1561 HandleException(e
, _hwnd
);
1567 LRESULT
StartMenuRoot::Init(LPCREATESTRUCT pcs
)
1569 // add buttons for entries in _entries
1570 if (super::Init(pcs
))
1580 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"), &hkey
))
1583 if (RegOpenKey(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), &hkeyAdv
))
1586 #define IS_VALUE_ZERO(hk, name) \
1587 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || !value))
1589 #define IS_VALUE_NOT_ZERO(hk, name) \
1590 (!hk || (len=sizeof(value),RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE)&value, &len) || value>0))
1594 // insert hard coded start entries
1595 AddButton(ResString(IDS_PROGRAMS
), ICID_APPS
, true, IDC_PROGRAMS
);
1597 AddButton(ResString(IDS_DOCUMENTS
), ICID_DOCUMENTS
, true, IDC_DOCUMENTS
);
1599 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1600 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORECENTDOCSMENU
))
1602 if (IS_VALUE_ZERO(hkey
, _T("NoRecentDocsMenu")))
1604 AddButton(ResString(IDS_RECENT
), ICID_DOCUMENTS
, true, IDC_RECENT
);
1606 AddButton(ResString(IDS_FAVORITES
), ICID_FAVORITES
, true, IDC_FAVORITES
);
1608 AddButton(ResString(IDS_SETTINGS
), ICID_CONFIG
, true, IDC_SETTINGS
);
1610 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1611 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOFIND
))
1613 if (IS_VALUE_ZERO(hkey
, _T("NoFind")))
1615 AddButton(ResString(IDS_SEARCH
), ICID_SEARCH
, true, IDC_SEARCH
);
1617 AddButton(ResString(IDS_START_HELP
), ICID_INFO
, false, IDC_START_HELP
);
1619 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1620 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NORUN
))
1622 if (IS_VALUE_ZERO(hkey
, _T("NoRun")))
1624 AddButton(ResString(IDS_LAUNCH
), ICID_ACTION
, false, IDC_LAUNCH
);
1630 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1631 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCLOSE
))
1633 if (IS_VALUE_NOT_ZERO(hkeyAdv
, _T("StartMenuLogoff")))
1635 AddButton(ResString(IDS_LOGOFF
), ICID_LOGOFF
, false, IDC_LOGOFF
);
1638 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1639 if (!g_Globals
._SHRestricted
|| SHRestricted(REST_STARTMENULOGOFF
) != 1)
1641 if (IS_VALUE_ZERO(hkey
, _T("NoClose")))
1643 AddButton(ResString(IDS_SHUTDOWN
), ICID_LOGOFF
, false, IDC_SHUTDOWN
);
1647 RegCloseKey(hkeyAdv
);
1652 #ifdef _LIGHT_STARTMENU
1653 // set the window size to fit all buttons
1661 void StartMenuRoot::AddEntries()
1663 super::AddEntries();
1665 AddButton(ResString(IDS_EXPLORE
), ICID_EXPLORER
, false, IDC_EXPLORE
);
1669 LRESULT
StartMenuRoot::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1673 PaintCanvas
canvas(_hwnd
);
1678 return super::WndProc(nmsg
, wparam
, lparam
);
1684 void StartMenuRoot::Paint(PaintCanvas
& canvas
)
1687 {WindowCanvas
dc(_hwnd
); clr_bits
=GetDeviceCaps(dc
, BITSPIXEL
);}
1690 ResBitmap
bmp(clr_bits
<=8? clr_bits
<=4? IDB_LOGOV16
: IDB_LOGOV256
: IDB_LOGOV
);
1691 BitmapSelection
sel(mem_dc
, bmp
);
1693 ClientRect
clnt(_hwnd
);
1694 int h
= min(_logo_size
.cy
, clnt
.bottom
);
1696 RECT rect
= {0, 0, _logo_size
.cx
, clnt
.bottom
-h
};
1697 HBRUSH hbr
= CreateSolidBrush(GetPixel(mem_dc
, 0, 0));
1698 FillRect(canvas
, &rect
, hbr
);
1701 PatBlt(canvas
, _logo_size
.cx
, 0, 1, clnt
.bottom
, WHITENESS
);
1703 BitBlt(canvas
, 0, clnt
.bottom
-h
, _logo_size
.cx
, h
, mem_dc
, 0, 0, SRCCOPY
);
1705 super::Paint(canvas
);
1709 void StartMenuRoot::CloseStartMenu(int id
)
1714 ShowWindow(_hwnd
, SW_HIDE
);
1717 void StartMenuRoot::ProcessKey(int vk
)
1722 CloseOtherSubmenus();
1723 // don't close start menu root
1727 super::ProcessKey(vk
);
1732 int StartMenuHandler::Command(int id
, int code
)
1739 CreateSubmenu(id
, CSIDL_COMMON_PROGRAMS
, CSIDL_PROGRAMS
, ResString(IDS_PROGRAMS
));
1744 explorer_show_frame(SW_SHOWNORMAL
);
1749 ShowLaunchDialog(g_Globals
._hwndDesktopBar
);
1753 CreateSubmenu(id
, CSIDL_PERSONAL
, ResString(IDS_DOCUMENTS
));
1757 CreateSubmenu(id
, CSIDL_RECENT
, ResString(IDS_RECENT
), STARTMENU_CREATOR(RecentStartMenu
));
1761 CreateSubmenu(id
, CSIDL_FAVORITES
, ResString(IDS_FAVORITES
));
1765 CreateSubmenu(id
, ResString(IDS_SETTINGS
), STARTMENU_CREATOR(SettingsMenu
));
1769 CreateSubmenu(id
, ResString(IDS_SEARCH
), STARTMENU_CREATOR(SearchMenu
));
1772 case IDC_START_HELP
:
1774 MessageBox(g_Globals
._hwndDesktopBar
, TEXT("Help not yet implemented"), ResString(IDS_TITLE
), MB_OK
);
1778 /* The shell32 Dialog prompts about some system setting change. This is not what we want to display here.
1780 ShowRestartDialog(g_Globals._hwndDesktopBar, EWX_LOGOFF);*/
1781 DestroyWindow(GetParent(_hwnd
));
1786 ShowExitWindowsDialog(g_Globals
._hwndDesktopBar
);
1792 case ID_DESKTOPBAR_SETTINGS
:
1794 ExplorerPropertySheet(g_Globals
._hwndDesktopBar
);
1799 MainFrame::Create(SpecialFolderPath(CSIDL_PRINTERS
, _hwnd
), OWM_PIDL
);
1802 case IDC_CONTROL_PANEL
:
1804 MainFrame::Create(TEXT("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"), 0);
1809 MainFrame::Create(SpecialFolderPath(CSIDL_COMMON_ADMINTOOLS
, _hwnd
), OWM_PIDL
);
1812 case IDC_CONNECTIONS
:
1814 MainFrame::Create(SpecialFolderPath(CSIDL_CONNECTIONS
, _hwnd
), OWM_PIDL
);
1820 case IDC_SEARCH_FILES
:
1825 case IDC_SEARCH_COMPUTER
:
1827 ShowSearchComputer();
1832 return super::Command(id
, code
);
1839 void StartMenuHandler::ShowSearchDialog()
1841 static DynamicFct
<SHFINDFILES
> SHFindFiles(TEXT("SHELL32"), 90);
1844 (*SHFindFiles
)(NULL
, NULL
);
1846 MessageBox(0, TEXT("SHFindFiles() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1849 void StartMenuHandler::ShowSearchComputer()
1851 static DynamicFct
<SHFINDCOMPUTER
> SHFindComputer(TEXT("SHELL32"), 91);
1854 (*SHFindComputer
)(NULL
, NULL
);
1856 MessageBox(0, TEXT("SHFindComputer() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1859 void StartMenuHandler::ShowLaunchDialog(HWND hwndOwner
)
1861 ///@todo All text phrases should be put into the resources.
1862 static LPCSTR szTitle
= "Run";
1863 static LPCSTR szText
= "Type the name of a program, folder, document, or Internet resource, and Explorer will open it for you.";
1865 static DynamicFct
<RUNFILEDLG
> RunFileDlg(TEXT("SHELL32"), 61);
1867 // Show "Run..." dialog
1869 #ifndef _ROS_ /* FIXME: our shell32 always expects Ansi strings */
1871 if ((HIWORD(GetVersion())>>14) == W_VER_NT
) {
1872 WCHAR wTitle
[40], wText
[256];
1874 MultiByteToWideChar(CP_ACP
, 0, szTitle
, -1, wTitle
, 40);
1875 MultiByteToWideChar(CP_ACP
, 0, szText
, -1, wText
, 256);
1877 (*RunFileDlg
)(hwndOwner
, 0, NULL
, (LPCSTR
)wTitle
, (LPCSTR
)wText
, RFF_CALCDIRECTORY
);
1881 (*RunFileDlg
)(hwndOwner
, 0, NULL
, szTitle
, szText
, RFF_CALCDIRECTORY
);
1885 void StartMenuHandler::ShowRestartDialog(HWND hwndOwner
, UINT flags
)
1887 static DynamicFct
<RESTARTWINDOWSDLG
> RestartDlg(TEXT("SHELL32"), 59);
1890 (*RestartDlg
)(hwndOwner
, (LPWSTR
)L
"You selected <Log Off>.\n\n", flags
); ///@todo ANSI string conversion if needed
1892 MessageBox(hwndOwner
, TEXT("RestartDlg() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1895 void ShowExitWindowsDialog(HWND hwndOwner
)
1897 static DynamicFct
<EXITWINDOWSDLG
> ExitWindowsDlg(TEXT("SHELL32"), 60);
1900 (*ExitWindowsDlg
)(hwndOwner
);
1902 MessageBox(hwndOwner
, TEXT("ExitWindowsDlg() not yet implemented in SHELL32"), ResString(IDS_TITLE
), MB_OK
);
1906 void SettingsMenu::AddEntries()
1908 super::AddEntries();
1910 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1911 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_NOCONTROLPANEL
))
1913 AddButton(ResString(IDS_CONTROL_PANEL
), ICID_CONFIG
, false, IDC_CONTROL_PANEL
);
1915 AddButton(ResString(IDS_PRINTERS
), ICID_PRINTER
, false, IDC_PRINTERS
);
1916 AddButton(ResString(IDS_CONNECTIONS
), ICID_NETWORK
, false, IDC_CONNECTIONS
);
1917 AddButton(ResString(IDS_ADMIN
), ICID_CONFIG
, false, IDC_ADMIN
);
1919 AddButton(ResString(IDS_DESKTOPBAR_SETTINGS
), ICID_CONFIG
, false, ID_DESKTOPBAR_SETTINGS
);
1922 void SearchMenu::AddEntries()
1924 super::AddEntries();
1926 AddButton(ResString(IDS_SEARCH_FILES
), ICID_SEARCH_DOC
, false, IDC_SEARCH_FILES
);
1928 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
1929 if (!g_Globals
._SHRestricted
|| !SHRestricted(REST_HASFINDCOMPUTERS
))
1931 AddButton(ResString(IDS_SEARCH_COMPUTER
), ICID_COMPUTER
, false, IDC_SEARCH_COMPUTER
);
1935 void RecentStartMenu::AddEntries()
1937 for(StartMenuShellDirs::iterator it
=_dirs
.begin(); it
!=_dirs
.end(); ++it
) {
1938 StartMenuDirectory
& smd
= *it
;
1939 ShellDirectory
& dir
= smd
._dir
;
1941 if (!dir
._scanned
) {
1944 #ifdef _LAZY_ICONEXTRACT
1945 dir
.smart_scan(SCAN_FILESYSTEM
);
1947 dir
.smart_scan(SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
1951 dir
.sort_directory(SORT_DATE
);
1952 AddShellEntries(dir
, RECENT_DOCS_COUNT
, smd
._subfolders
); ///@todo read max. count of entries from registry