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