merged start menus of the same name (e.g. "All Users\Startup" with "<User>\Startup")
[reactos.git] / reactos / subsys / system / explorer / taskbar / startmenu.h
1 /*
2 * Copyright 2003 Martin Fuchs
3 *
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.
8 *
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.
13 *
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
17 */
18
19
20 //
21 // Explorer and Desktop clone
22 //
23 // startmenu.h
24 //
25 // Martin Fuchs, 16.08.2003
26 //
27
28
29 #define CLASSNAME_STARTMENU _T("ReactosStartmenuClass")
30 #define TITLE_STARTMENU _T("Start Menu")
31
32
33 #define STARTMENU_WIDTH_MIN 120
34 #define STARTMENU_LINE_HEIGHT 22
35 #define STARTMENU_SEP_HEIGHT (STARTMENU_LINE_HEIGHT/2)
36
37
38 // private message constants
39 #define PM_STARTMENU_CLOSED (WM_APP+0x11)
40 #define PM_STARTENTRY_FOCUSED (WM_APP+0x12)
41 #define PM_STARTENTRY_LAUNCHED (WM_APP+0x13)
42
43
44 struct StartMenuDirectory
45 {
46 StartMenuDirectory(const ShellDirectory& dir, bool subfolders=true)
47 : _dir(dir), _subfolders(subfolders)
48 {
49 }
50
51 ~StartMenuDirectory()
52 {
53 _dir.free_subentries();
54 }
55
56 ShellDirectory _dir;
57 bool _subfolders;
58 };
59
60 typedef list<StartMenuDirectory> StartMenuShellDirs;
61 typedef set<const ShellEntry*> ShellEntrySet;
62
63 struct StartMenuEntry
64 {
65 StartMenuEntry() : _hIcon(0) {}
66
67 String _title;
68 HICON _hIcon;
69 ShellEntrySet _entries;
70 };
71
72
73 /**
74 StartMenuButton draws to face of a StartMenuCtrl button control.
75 */
76 struct StartMenuButton : public OwnerdrawnButton
77 {
78 typedef OwnerdrawnButton super;
79
80 StartMenuButton(HWND hwnd, HICON hIcon, bool hasSubmenu)
81 : super(hwnd), _hIcon(hIcon), _hasSubmenu(hasSubmenu) {}
82
83 static int GetTextWidth(LPCTSTR title, HWND hwnd);
84
85 protected:
86 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
87 virtual void DrawItem(LPDRAWITEMSTRUCT dis);
88
89 HICON _hIcon;
90 bool _hasSubmenu;
91 };
92
93
94 /**
95 To create a Startmenu button control, construct a StartMenuCtrl object.
96 */
97 struct StartMenuCtrl : public Button
98 {
99 StartMenuCtrl(HWND parent, int x, int y, int w, LPCTSTR title,
100 UINT id, HICON hIcon=0, bool hasSubmenu=false, DWORD style=WS_VISIBLE|WS_CHILD|BS_OWNERDRAW, DWORD exStyle=0)
101 : Button(parent, title, x, y, w, STARTMENU_LINE_HEIGHT, id, style, exStyle)
102 {
103 *new StartMenuButton(_hwnd, hIcon, hasSubmenu);
104
105 SetWindowFont(_hwnd, GetStockFont(DEFAULT_GUI_FONT), FALSE);
106 }
107 };
108
109
110 struct StartMenuSeparator : public Static
111 {
112 StartMenuSeparator(HWND parent, int x, int y, int w, DWORD style=WS_VISIBLE|WS_CHILD|WS_DISABLED|SS_ETCHEDHORZ, DWORD exStyle=0)
113 : Static(parent, NULL, x, y+STARTMENU_SEP_HEIGHT/2-1, w, 2, -1, style, exStyle)
114 {
115 }
116 };
117
118
119 typedef list<ShellPath> StartMenuFolders;
120 #define STARTMENU_CREATOR(WND_CLASS) WINDOW_CREATOR_INFO(WND_CLASS, StartMenuFolders)
121
122 typedef map<UINT, StartMenuEntry> ShellEntryMap;
123
124
125 /**
126 Startmenu window
127 */
128 struct StartMenu : public OwnerDrawParent<Dialog>
129 {
130 typedef OwnerDrawParent<Dialog> super;
131
132 StartMenu(HWND hwnd);
133 StartMenu(HWND hwnd, const StartMenuFolders& info);
134 ~StartMenu();
135
136 // static HWND Create(int x, int y, HWND hwndParent=0);
137 static HWND Create(int x, int y, const StartMenuFolders&, HWND hwndParent=0, CREATORFUNC creator=s_def_creator);
138 static CREATORFUNC s_def_creator;
139
140 protected:
141 // overridden member functions
142 LRESULT Init(LPCREATESTRUCT pcs);
143 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
144 int Command(int id, int code);
145
146 // window class
147 static BtnWindowClass& GetWndClasss();
148
149 // data members
150 int _next_id;
151 ShellEntryMap _entries;
152 StartMenuShellDirs _dirs;
153
154 int _submenu_id;
155 WindowHandle _submenu;
156
157 int _border_left; // left border in pixels
158
159 // member functions
160 void ResizeButtons(int cx);
161
162 virtual void AddEntries();
163
164 StartMenuEntry& AddEntry(LPCTSTR title, HICON hIcon=0, UINT id=(UINT)-1);
165 StartMenuEntry& AddEntry(const ShellFolder folder, const ShellEntry* entry);
166
167 void AddShellEntries(const ShellDirectory& dir, int max=-1, bool subfolders=true);
168
169 void AddButton(LPCTSTR title, HICON hIcon=0, bool hasSubmenu=false, UINT id=(UINT)-1, DWORD style=WS_VISIBLE|WS_CHILD|BS_OWNERDRAW);
170 void AddSeparator();
171
172 bool CloseOtherSubmenus(int id);
173 void CreateSubmenu(int id, CREATORFUNC creator=s_def_creator);
174 void CreateSubmenu(int id, int folder, CREATORFUNC creator=s_def_creator);
175 void CreateSubmenu(int id, int folder1, int folder2, CREATORFUNC creator=s_def_creator);
176 void CreateSubmenu(int id, const StartMenuFolders& new_folders, CREATORFUNC creator=s_def_creator);
177 void ActivateEntry(int id, const ShellEntrySet& entries);
178 void CloseStartMenu(int id=0);
179 };
180
181
182 // declare shell32's "Run..." dialog export function
183 typedef void (WINAPI* RUNFILEDLG)(HWND hwndOwner, HICON hIcon, LPCSTR lpstrDirectory, LPCSTR lpstrTitle, LPCSTR lpstrDescription, UINT uFlags);
184
185 //
186 // Flags for RunFileDlg
187 //
188
189 #define RFF_NOBROWSE 0x01 // Removes the browse button.
190 #define RFF_NODEFAULT 0x02 // No default item selected.
191 #define RFF_CALCDIRECTORY 0x04 // Calculates the working directory from the file name.
192 #define RFF_NOLABEL 0x08 // Removes the edit box label.
193 #define RFF_NOSEPARATEMEM 0x20 // Removes the Separate Memory Space check box (Windows NT only).
194
195
196 // declare more undocumented shell32 functions
197 typedef void (WINAPI* EXITWINDOWSDLG)(HWND hwndOwner);
198 typedef int (WINAPI* RESTARTWINDOWSDLG)(HWND hwndOwner, LPCWSTR reason, UINT flags);
199 typedef BOOL (WINAPI* SHFINDFILES)(LPCITEMIDLIST pidlRoot, LPCITEMIDLIST pidlSavedSearch);
200 typedef BOOL (WINAPI* SHFINDCOMPUTER)(LPCITEMIDLIST pidlRoot, LPCITEMIDLIST pidlSavedSearch);
201
202
203 // Startmenu root window
204 struct StartMenuRoot : public StartMenu
205 {
206 typedef StartMenu super;
207
208 StartMenuRoot(HWND hwnd);
209
210 static HWND Create(HWND hwndDesktopBar);
211 void TrackStartmenu();
212
213 protected:
214 LRESULT Init(LPCREATESTRUCT pcs);
215 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
216
217 void AddEntries();
218 int Command(int id, int code);
219
220 static void ShowLaunchDialog(HWND hwndDesktopBar);
221 static void ShowExitWindowsDialog(HWND hwndOwner);
222 static void ShowRestartDialog(HWND hwndOwner, UINT flags);
223 static void ShowSearchDialog();
224 static void ShowSearchComputer();
225
226 SIZE _logo_size;
227 };
228
229
230 // Settings sub-start menu
231 struct SettingsMenu : public StartMenu
232 {
233 typedef StartMenu super;
234
235 SettingsMenu(HWND hwnd, const StartMenuFolders& info);
236
237 void TrackStartmenu();
238
239 protected:
240 void AddEntries();
241 int Command(int id, int code);
242 };
243
244
245 struct RecentStartMenu : public StartMenu
246 {
247 typedef StartMenu super;
248
249 RecentStartMenu(HWND hwnd, const StartMenuFolders& info);
250
251 protected:
252 virtual void AddEntries();
253 };