ReactOS 0.4.15-dev-7788-g1ad9096
quicklaunch.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2003, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19
20 //
21 // Explorer clone
22 //
23 // quicklaunch.cpp
24 //
25 // Martin Fuchs, 22.08.2003
26 //
27
28
29#include <precomp.h>
30
31#include "quicklaunch.h"
32
33
35{
36 _hbmp = 0;
37}
38
40{
41 while(!empty()) {
42 iterator it = begin();
43 DeleteBitmap(it->second._hbmp);
44 erase(it);
45 }
46}
47
48
50 : super(hwnd)
51{
52 CONTEXT("QuickLaunchBar::QuickLaunchBar()");
53
54 _dir = NULL;
56 _btn_dist = 20;
57 _size = 0;
58
59 HWND hwndToolTip = (HWND) SendMessage(hwnd, TB_GETTOOLTIPS, 0, 0);
60
61 SetWindowStyle(hwndToolTip, GetWindowStyle(hwndToolTip)|TTS_ALWAYSTIP);
62
63 // delay refresh to some time later
65}
66
68{
69 delete _dir;
70}
71
73{
74 CONTEXT("QuickLaunchBar::Create()");
75
76 ClientRect clnt(hwndParent);
77
82 IDW_QUICKLAUNCHBAR, 0, 0, 0, NULL, 0, 0, 0, 16, 16, sizeof(TBBUTTON));
83
84 if (hwnd)
86
87 return hwnd;
88}
89
91{
92 CONTEXT("QuickLaunchBar::AddShortcuts()");
93
94 WaitCursor wait;
95
96 try {
98
99 SpecialFolderFSPath app_data(CSIDL_APPDATA, _hwnd);
100
101 _stprintf(path, TEXT("%s\\")QUICKLAUNCH_FOLDER, (LPCTSTR)app_data);
102
104 _dir = new ShellDirectory(GetDesktopFolder(), path, _hwnd);
105
107
108 // immediatelly extract the shortcut icons
109 for(Entry*entry=_dir->_down; entry; entry=entry->_next)
110 entry->_icon_id = entry->safe_extract_icon(ICF_NORMAL);
111 } catch(COMException&) {
112 return;
113 }
114
115
116 ShellFolder desktop_folder;
117 WindowCanvas canvas(_hwnd);
118
121
124
125 TBBUTTON sep = {0, -1, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
127
128 int cur_desktop = g_Globals._desktops._current_desktop;
129 ResString desktop_fmt(IDS_DESKTOP_NUM);
130
131 HDC hdc = CreateCompatibleDC(canvas);
132 DWORD size = SendMessage(_hwnd, TB_GETBUTTONSIZE, 0, 0);
133 int cx = LOWORD(size);
134 int cy = HIWORD(size);
135 RECT rect = {0, 0, cx, cy};
136 RECT textRect = {0, 0, cx-7, cy-7};
137
138 for(int i=0; i<DESKTOP_COUNT; ++i) {
140 HBITMAP hbmp_old = SelectBitmap(hdc, hbmp);
141
142 FontSelection font(hdc, GetStockFont(ANSI_VAR_FONT));
143 FmtString num_txt(TEXT("%d"), i+1);
144 TextColor color(hdc, RGB(64,64,64));
145 BkMode mode(hdc, TRANSPARENT);
147 DrawText(hdc, num_txt, num_txt.length(), &textRect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
148
149 SelectBitmap(hdc, hbmp_old);
150
151 AddButton(ID_SWITCH_DESKTOP_1+i, hbmp, FmtString(desktop_fmt, i+1), NULL, cur_desktop==i?TBSTATE_ENABLED|TBSTATE_PRESSED:TBSTATE_ENABLED);
152 }
153 DeleteDC(hdc);
154
155 for(Entry*entry=_dir->_down; entry; entry=entry->_next) {
156 // hide files like "desktop.ini"
157 if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
158 continue;
159
160 // hide subfolders
161 if (!(entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
163
164 AddButton(_next_id++, hbmp, entry->_display_name, entry); //entry->_etype==ET_SHELL? desktop_folder.get_name(static_cast<ShellEntry*>(entry)->_pidl): entry->_display_name);
165 }
166 }
167
170
172}
173
175{
176 TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
177 int bmp_idx = SendMessage(_hwnd, TB_ADDBITMAP, 1, (LPARAM)&ab);
178
180
181 qle._hbmp = hbmp;
182 qle._title = name;
183 qle._entry = entry;
184
185 _entries[id] = qle;
186
187 TBBUTTON btn = {0, 0, (BYTE)flags, BTNS_BUTTON|BTNS_NOPREFIX, {0, 0}, 0, 0};
188
189 btn.idCommand = id;
190 btn.iBitmap = bmp_idx;
191
193}
194
196{
197 for(int i=0; i<DESKTOP_COUNT; ++i) {
199
201 }
202}
203
205{
206 switch(nmsg) {
207 case PM_REFRESH:
208 AddShortcuts();
209 break;
210
211 case PM_GET_WIDTH: {
212 // take line wrapping into account
213 int btns = SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0);
214 int rows = SendMessage(_hwnd, TB_GETROWS, 0, 0);
215
216 if (rows<2 || rows==btns)
217 return _size;
218
219 RECT rect;
220 int max_cx = 0;
221
223 SendMessage(_hwnd, TB_GETRECT, it->first, (LPARAM)&rect);
224
225 if (rect.right > max_cx)
226 max_cx = rect.right;
227 }
228
229 return max_cx;}
230
233 break;
234
235 case WM_CONTEXTMENU: {
236 TBBUTTON btn;
238 Point screen_pt(lparam), clnt_pt=screen_pt;
239 ScreenToClient(_hwnd, &clnt_pt);
240
241 Entry* entry = NULL;
242 int idx = SendMessage(_hwnd, TB_HITTEST, 0, (LPARAM)&clnt_pt);
243
244 if (idx>=0 &&
245 SendMessage(_hwnd, TB_GETBUTTON, idx, (LPARAM)&btn)!=-1 &&
246 (it=_entries.find(btn.idCommand))!=_entries.end()) {
247 entry = it->second._entry;
248 }
249
250 if (entry) { // entry is NULL for desktop switch buttons
251 HRESULT hr = entry->do_context_menu(_hwnd, screen_pt, _cm_ifs);
252
253 if (!SUCCEEDED(hr))
254 CHECKERROR(hr);
255 } else
256 goto def;
257 break;}
258
259 default: def:
260 return super::WndProc(nmsg, wparam, lparam);
261 }
262
263 return 0;
264}
265
267{
268 CONTEXT("QuickLaunchBar::Command()");
269
270 if ((id&~0xFF) == IDC_FIRST_QUICK_ID) {
272
273 if (qle._entry) {
274 qle._entry->launch_entry(_hwnd);
275 return 0;
276 }
277 }
278
279 return 0; // Don't return 1 to avoid recursion with DesktopBar::Command()
280}
281
283{
284 switch(pnmh->code) {
285 case TTN_GETDISPINFO: {
286 NMTTDISPINFO* ttdi = (NMTTDISPINFO*) pnmh;
287
288 int id = ttdi->hdr.idFrom;
289 ttdi->lpszText = _entries[id]._title.str();
290#ifdef TTF_DI_SETITEM
291 ttdi->uFlags |= TTF_DI_SETITEM;
292#endif
293
294 // enable multiline tooltips (break at CR/LF and for very long one-line strings)
296
297 break;}
298
299 return super::Notify(id, pnmh);
300 }
301
302 return 0;
303}
@ lparam
Definition: SystemMenu.c:31
@ wparam
Definition: SystemMenu.c:30
#define IDS_TITLE
Definition: resource.h:30
VOID WaitCursor(BOOL bBegin)
Definition: dialog.c:114
HBITMAP hbmp
_STLP_TEMPLATE_FOR_CONT_EXT iterator find(const _KT &__x)
Definition: _map.h:210
iterator end()
Definition: _map.h:165
_Rep_type::iterator iterator
Definition: _map.h:85
size_type size() const
Definition: _map.h:172
bool empty() const
Definition: _map.h:171
void erase(iterator __pos)
Definition: _map.h:203
_Rep_type::const_iterator const_iterator
Definition: _map.h:86
HWND WINAPI CreateToolbarEx(HWND hwnd, DWORD style, UINT wID, INT nBitmaps, HINSTANCE hBMInst, UINT_PTR wBMID, LPCTBBUTTON lpButtons, INT iNumButtons, INT dxButton, INT dyButton, INT dxBitmap, INT dyBitmap, UINT uStructSize)
Definition: commctrl.c:929
static HWND hwndParent
Definition: cryptui.c:300
#define NULL
Definition: types.h:112
unsigned int idx
Definition: utils.c:41
HANDLE HWND
Definition: compat.h:19
#define MAX_PATH
Definition: compat.h:34
#define RGB(r, g, b)
Definition: precomp.h:62
@ ICF_NORMAL
Definition: entries.h:67
#define PM_RESIZE_CHILDREN
Definition: explorer.h:66
#define PM_REFRESH
Definition: explorer.h:69
#define PM_GET_WIDTH
Definition: explorer.h:67
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLuint color
Definition: glext.h:6243
GLenum mode
Definition: glext.h:6217
GLbitfield flags
Definition: glext.h:7161
GLuint id
Definition: glext.h:5910
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define INT_MAX
Definition: limits.h:40
#define SUCCEEDED(hr)
Definition: intsafe.h:50
uint32_t entry
Definition: isohybrid.c:63
#define TEXT(s)
Definition: k32.h:26
ExplorerGlobals g_Globals
Definition: explorer.cpp:52
@ ICID_EXPLORER
Definition: globals.h:69
@ ICID_MINIMIZE
Definition: globals.h:86
#define DESKTOP_COUNT
Definition: globals.h:238
#define IDS_DESKTOP_NUM
Definition: resource.h:38
#define ID_MINIMIZE_ALL
Definition: resource.h:212
#define IDS_MINIMIZE_ALL
Definition: resource.h:37
#define ID_EXPLORE
Definition: resource.h:213
#define ID_SWITCH_DESKTOP_1
Definition: resource.h:225
BOOL RecursiveCreateDirectory(LPCTSTR path_in)
Definition: utility.cpp:394
#define SetWindowStyle(hwnd, val)
Definition: utility.h:153
#define _stprintf
Definition: utility.h:124
HDC hdc
Definition: main.c:9
UCHAR ab[sizeof("Hello World!") -1]
Definition: fdi.c:106
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
Definition: mk_font.cpp:20
unsigned int UINT
Definition: ndis.h:50
struct _CONTEXT CONTEXT
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define TB_GETTOOLTIPS
Definition: commctrl.h:1138
#define TB_INSERTBUTTON
Definition: commctrl.h:1270
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
#define BTNS_BUTTON
Definition: commctrl.h:998
#define NMTTDISPINFO
Definition: commctrl.h:1914
#define TBSTATE_PRESSED
Definition: commctrl.h:973
#define TBSTYLE_TOOLTIPS
Definition: commctrl.h:989
#define TBBUTTONINFO
Definition: commctrl.h:1254
#define BTNS_SEP
Definition: commctrl.h:999
#define TTF_DI_SETITEM
Definition: commctrl.h:1772
#define TB_GETBUTTONSIZE
Definition: commctrl.h:1160
_Out_opt_ int * cx
Definition: commctrl.h:585
#define TTN_GETDISPINFO
Definition: commctrl.h:1878
#define TB_GETRECT
Definition: commctrl.h:1153
#define TB_GETBUTTON
Definition: commctrl.h:1109
#define CCS_NODIVIDER
Definition: commctrl.h:2248
#define CCS_TOP
Definition: commctrl.h:2242
#define TTS_ALWAYSTIP
Definition: commctrl.h:1757
#define TBSTATE_ENABLED
Definition: commctrl.h:974
#define TBSTYLE_FLAT
Definition: commctrl.h:992
#define CCS_NOPARENTALIGN
Definition: commctrl.h:2246
#define CCS_NORESIZE
Definition: commctrl.h:2245
#define TB_SETBUTTONINFO
Definition: commctrl.h:1263
#define TB_HITTEST
Definition: commctrl.h:1268
#define TBSTYLE_WRAPABLE
Definition: commctrl.h:990
#define TB_GETROWS
Definition: commctrl.h:1142
#define BTNS_NOPREFIX
Definition: commctrl.h:1005
#define TB_BUTTONCOUNT
Definition: commctrl.h:1110
#define TB_ADDBITMAP
Definition: commctrl.h:1056
#define TBIF_STATE
Definition: commctrl.h:1221
#define TTM_SETMAXTIPWIDTH
Definition: commctrl.h:1819
#define PM_UPDATE_DESKTOP
Definition: quicklaunch.h:34
#define IDW_QUICKLAUNCHBAR
Definition: quicklaunch.h:32
#define IDC_FIRST_QUICK_ID
Definition: quicklaunch.h:36
#define QUICKLAUNCH_FOLDER
Definition: quicklaunch.h:39
#define WM_CONTEXTMENU
Definition: richedit.h:64
ShellFolder & GetDesktopFolder()
#define CHECKERROR(hr)
Definition: shellclasses.h:162
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_APPDATA
Definition: shlobj.h:2183
RECT textRect
Definition: startmenu.cpp:1392
& rect
Definition: startmenu.cpp:1413
COLORREF bk_color
Definition: startmenu.cpp:1409
HBRUSH bk_brush
Definition: startmenu.cpp:1410
Exception with context information.
Definition: shellclasses.h:114
int _current_desktop
Definition: globals.h:253
base of all file and directory entries
Definition: entries.h:83
virtual BOOL launch_entry(HWND hwnd, UINT nCmdShow=SW_SHOWNORMAL)
Definition: entries.cpp:443
Entry * _down
Definition: entries.h:93
void smart_scan(SORT_ORDER sortOrder=SORT_NAME, int scan_flags=0)
Definition: entries.cpp:353
IconCache _icon_cache
Definition: globals.h:285
Desktops _desktops
Definition: globals.h:291
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
const Icon & get_icon(int icon_id)
Definition: explorer.cpp:625
HBITMAP create_bitmap(COLORREF bk_color, HBRUSH hbrBkgnd, HDC hdc_wnd) const
Definition: explorer.cpp:285
quick launch bar window
Definition: quicklaunch.h:61
QuickLaunchBar(HWND hwnd)
Definition: quicklaunch.cpp:49
void AddShortcuts()
Definition: quicklaunch.cpp:90
static HWND Create(HWND hwndParent)
Definition: quicklaunch.cpp:72
void UpdateDesktopButtons(int desktop_idx)
ShellDirectory * _dir
Definition: quicklaunch.h:74
int Notify(int id, NMHDR *pnmh)
QuickLaunchMap _entries
Definition: quicklaunch.h:77
void AddButton(int id, HBITMAP hbmp, LPCTSTR name, Entry *entry, int flags=TBSTATE_ENABLED)
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
int Command(int id, int code)
quick launch bar shortcut
Definition: quicklaunch.h:44
convenient loading of string resources
Definition: globals.h:304
shell folder entry
Definition: shellfs.h:54
IShellFolder smart pointer.
Definition: shellclasses.h:594
file system path of special folder
virtual int Notify(int id, NMHDR *pnmh)
Definition: window.cpp:290
int idCommand
Definition: commctrl.h:950
int iBitmap
Definition: commctrl.h:949
Definition: inflate.c:139
Definition: name.c:39
UINT_PTR idFrom
Definition: winuser.h:3158
UINT code
Definition: winuser.h:3159
HWND hwndFrom
Definition: winuser.h:3157
#define HIWORD(l)
Definition: typedefs.h:247
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
DWORD COLORREF
Definition: windef.h:300
#define DeleteBitmap(hbm)
Definition: windowsx.h:76
#define SelectBitmap(hdc, hbm)
Definition: windowsx.h:514
#define GetStockFont(i)
Definition: windowsx.h:308
#define GetWindowStyle(hwnd)
Definition: windowsx.h:315
#define ANSI_VAR_FONT
Definition: wingdi.h:907
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define TRANSPARENT
Definition: wingdi.h:950
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
BOOL WINAPI DeleteDC(_In_ HDC)
DWORD WINAPI GetSysColor(_In_ int)
#define DT_CENTER
Definition: winuser.h:527
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define DT_SINGLELINE
Definition: winuser.h:540
#define DrawText
Definition: winuser.h:5771
#define SendMessage
Definition: winuser.h:5843
#define DT_VCENTER
Definition: winuser.h:543
#define PostMessage
Definition: winuser.h:5832
HWND WINAPI GetParent(_In_ HWND)
#define COLOR_BTNFACE
Definition: winuser.h:928
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)
char TCHAR
Definition: xmlstorage.h:189
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define SORT_NAME
Definition: xpath.c:439
unsigned char BYTE
Definition: xxhash.c:193