ReactOS  0.4.14-dev-552-g2fad488
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
64  PostMessage(hwnd, PM_REFRESH, 0, 0);
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)
85  new QuickLaunchBar(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};
126  SendMessage(_hwnd, TB_INSERTBUTTON, INT_MAX, (LPARAM)&sep);
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 
168  _btn_dist = LOWORD(SendMessage(_hwnd, TB_GETBUTTONSIZE, 0, 0));
170 
172 }
173 
175 {
176  TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
177  int bmp_idx = SendMessage(_hwnd, TB_ADDBITMAP, 1, (LPARAM)&ab);
178 
179  QuickLaunchEntry qle;
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 
192  SendMessage(_hwnd, TB_INSERTBUTTON, INT_MAX, (LPARAM)&btn);
193 }
194 
196 {
197  for(int i=0; i<DESKTOP_COUNT; ++i) {
198  TBBUTTONINFO tbi = {sizeof(TBBUTTONINFO), TBIF_STATE, 0, 0, (BYTE)(desktop_idx==i? TBSTATE_ENABLED|TBSTATE_PRESSED: TBSTATE_ENABLED)};
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 
222  for(QuickLaunchMap::const_iterator it=_entries.begin(); it!=_entries.end(); ++it) {
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 
231  case PM_UPDATE_DESKTOP:
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) {
271  QuickLaunchEntry& qle = _entries[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 
282 int QuickLaunchBar::Notify(int id, NMHDR* pnmh)
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)
295  SendMessage(pnmh->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 400);
296 
297  break;}
298 
299  return super::Notify(id, pnmh);
300  }
301 
302  return 0;
303 }
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
QuickLaunchBar(HWND hwnd)
Definition: quicklaunch.cpp:49
unsigned __int3264 UINT_PTR
Definition: activex.cpp:275
#define BTNS_NOPREFIX
Definition: commctrl.h:1001
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TB_HITTEST
Definition: commctrl.h:1264
#define TB_BUTTONCOUNT
Definition: commctrl.h:1106
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
file system path of special folder
#define PM_UPDATE_DESKTOP
Definition: quicklaunch.h:34
#define TB_GETROWS
Definition: commctrl.h:1138
#define WM_CONTEXTMENU
Definition: richedit.h:64
#define INT_MAX
Definition: limits.h:40
HRESULT hr
Definition: shlfolder.c:183
#define GetStockFont(i)
Definition: windowsx.h:283
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
Definition: mk_font.cpp:20
int Notify(int id, NMHDR *pnmh)
#define TB_GETBUTTON
Definition: commctrl.h:1105
void AddButton(int id, HBITMAP hbmp, LPCTSTR name, Entry *entry, int flags=TBSTATE_ENABLED)
#define IDC_FIRST_QUICK_ID
Definition: quicklaunch.h:36
void AddShortcuts()
Definition: quicklaunch.cpp:90
static HDC
Definition: imagelist.c:92
HANDLE HWND
Definition: compat.h:13
shell folder entry
Definition: shellfs.h:53
IShellFolder smart pointer.
Definition: shellclasses.h:593
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define PM_GET_WIDTH
Definition: explorer.h:67
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
#define TB_GETRECT
Definition: commctrl.h:1149
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
#define TB_INSERTBUTTON
Definition: commctrl.h:1266
#define WS_CLIPCHILDREN
Definition: pedump.c:619
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
#define SetWindowStyle(hwnd, val)
Definition: utility.h:153
struct _CONTEXT CONTEXT
#define ID_MINIMIZE_ALL
Definition: resource.h:212
DWORD WINAPI GetSysColor(_In_ int)
_Rep_type::const_iterator const_iterator
Definition: _map.h:86
& rect
Definition: startmenu.cpp:1413
#define TB_SETBUTTONINFO
Definition: commctrl.h:1259
#define DrawText
Definition: winuser.h:5746
size_type size() const
Definition: _map.h:172
ShellDirectory * _dir
Definition: quicklaunch.h:74
#define GetWindowStyle(hwnd)
Definition: windowsx.h:290
Exception with context information.
Definition: shellclasses.h:113
UINT code
Definition: winuser.h:3134
#define QUICKLAUNCH_FOLDER
Definition: quicklaunch.h:39
static HWND Create(HWND hwndParent)
Definition: quicklaunch.cpp:72
#define CCS_NODIVIDER
Definition: commctrl.h:2244
#define NMTTDISPINFO
Definition: commctrl.h:1910
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 BTNS_BUTTON
Definition: commctrl.h:994
COLORREF bk_color
Definition: startmenu.cpp:1409
int _current_desktop
Definition: globals.h:253
GLuint color
Definition: glext.h:6243
#define TTS_ALWAYSTIP
Definition: commctrl.h:1753
UINT_PTR idFrom
Definition: winuser.h:3133
static UINT WPARAM LPARAM lparam
Definition: combo.c:716
#define TTN_GETDISPINFO
Definition: commctrl.h:1874
unsigned int idx
Definition: utils.c:41
#define TRANSPARENT
Definition: wingdi.h:949
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:581
RECT textRect
Definition: startmenu.cpp:1392
smooth NULL
Definition: ftsmooth.c:416
static HWND hwndParent
Definition: cryptui.c:300
LONG_PTR LPARAM
Definition: windef.h:208
#define CCS_TOP
Definition: commctrl.h:2238
#define CCS_NOPARENTALIGN
Definition: commctrl.h:2242
UCHAR ab[sizeof("Hello World!") -1]
Definition: fdi.c:106
#define DESKTOP_COUNT
Definition: globals.h:238
#define DT_VCENTER
Definition: winuser.h:543
#define CHECKERROR(hr)
Definition: shellclasses.h:162
#define IDW_QUICKLAUNCHBAR
Definition: quicklaunch.h:32
int Command(int id, int code)
int iBitmap
Definition: commctrl.h:945
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define PostMessage
Definition: winuser.h:5807
HBITMAP hbmp
#define IDS_MINIMIZE_ALL
Definition: resource.h:37
void erase(iterator __pos)
Definition: _map.h:203
#define TB_GETBUTTONSIZE
Definition: commctrl.h:1156
#define PM_RESIZE_CHILDREN
Definition: explorer.h:66
char TCHAR
Definition: xmlstorage.h:189
#define TBSTATE_PRESSED
Definition: commctrl.h:969
#define TBIF_STATE
Definition: commctrl.h:1217
#define IDS_TITLE
Definition: resource.h:30
#define TTF_DI_SETITEM
Definition: commctrl.h:1768
GLsizeiptr size
Definition: glext.h:5919
QuickLaunchMap _entries
Definition: quicklaunch.h:77
#define BTNS_SEP
Definition: commctrl.h:995
void smart_scan(SORT_ORDER sortOrder=SORT_NAME, int scan_flags=0)
Definition: entries.cpp:353
LONG HRESULT
Definition: typedefs.h:77
Entry * _down
Definition: entries.h:93
DWORD COLORREF
Definition: windef.h:300
#define CSIDL_APPDATA
Definition: shlobj.h:2028
#define RGB(r, g, b)
Definition: wingdi.h:2939
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TTM_SETMAXTIPWIDTH
Definition: commctrl.h:1815
#define TBSTYLE_TOOLTIPS
Definition: commctrl.h:985
#define TB_ADDBITMAP
Definition: commctrl.h:1052
GLbitfield flags
Definition: glext.h:7161
#define SORT_NAME
Definition: xpath.c:441
#define CCS_NORESIZE
Definition: commctrl.h:2241
#define ID_EXPLORE
Definition: resource.h:213
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
_STLP_TEMPLATE_FOR_CONT_EXT iterator find(const _KT &__x)
Definition: _map.h:210
HDC hdc
Definition: main.c:9
int idCommand
Definition: commctrl.h:946
#define COLOR_BTNFACE
Definition: winuser.h:918
#define TB_GETTOOLTIPS
Definition: commctrl.h:1134
uint32_t entry
Definition: isohybrid.c:63
ExplorerGlobals g_Globals
Definition: explorer.cpp:52
unsigned char BYTE
Definition: mem.h:68
const Icon & get_icon(int icon_id)
Definition: explorer.cpp:625
HWND hwndFrom
Definition: winuser.h:3132
GLenum mode
Definition: glext.h:6217
ShellFolder & GetDesktopFolder()
virtual BOOL launch_entry(HWND hwnd, UINT nCmdShow=SW_SHOWNORMAL)
Definition: entries.cpp:443
BOOL RecursiveCreateDirectory(LPCTSTR path_in)
Definition: utility.cpp:394
#define _stprintf
Definition: utility.h:124
HBITMAP create_bitmap(COLORREF bk_color, HBRUSH hbrBkgnd, HDC hdc_wnd) const
Definition: explorer.cpp:285
#define DT_SINGLELINE
Definition: winuser.h:540
HWND WINAPI GetParent(_In_ HWND)
#define TEXT(s)
Definition: k32.h:26
#define ANSI_VAR_FONT
Definition: wingdi.h:906
BOOL WINAPI DeleteDC(_In_ HDC)
bool empty() const
Definition: _map.h:171
#define PM_REFRESH
Definition: explorer.h:69
#define DeleteBitmap(hbm)
Definition: windowsx.h:51
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
unsigned int UINT
Definition: ndis.h:50
#define SelectBitmap(hdc, hbm)
Definition: windowsx.h:489
_Out_opt_ int * cx
Definition: commctrl.h:581
Definition: name.c:38
#define SendMessage
Definition: winuser.h:5818
#define TBSTATE_ENABLED
Definition: commctrl.h:970
#define TBSTYLE_WRAPABLE
Definition: commctrl.h:986
#define HIWORD(l)
Definition: typedefs.h:246
Desktops _desktops
Definition: globals.h:291
GLenum GLuint id
Definition: glext.h:5579
#define DT_CENTER
Definition: winuser.h:527
static HBITMAP
Definition: button.c:44
virtual int Notify(int id, NMHDR *pnmh)
Definition: window.cpp:353
HBRUSH bk_brush
Definition: startmenu.cpp:1410
convenient loading of string resources
Definition: globals.h:303
void UpdateDesktopButtons(int desktop_idx)
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)
LONG_PTR LRESULT
Definition: windef.h:209
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
#define WS_VISIBLE
Definition: pedump.c:620
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define IDS_DESKTOP_NUM
Definition: resource.h:38
#define LOWORD(l)
Definition: pedump.c:82
base of all file and directory entries
Definition: entries.h:82
#define TBSTYLE_FLAT
Definition: commctrl.h:988
#define ID_SWITCH_DESKTOP_1
Definition: resource.h:225
_Rep_type::iterator iterator
Definition: _map.h:85
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define TBBUTTONINFO
Definition: commctrl.h:1250
static UINT WPARAM wparam
Definition: combo.c:716
IconCache _icon_cache
Definition: globals.h:285
iterator end()
Definition: _map.h:165
quick launch bar shortcut
Definition: quicklaunch.h:43
GLuint const GLchar * name
Definition: glext.h:6031