RecursiveCreateDirectory()
[reactos.git] / reactos / subsys / system / explorer / taskbar / quicklaunch.cpp
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 clone
22 //
23 // quicklaunch.cpp
24 //
25 // Martin Fuchs, 22.08.2003
26 //
27
28
29 #include "../utility/utility.h"
30
31 #include "../explorer.h"
32 #include "../globals.h"
33
34 #include "quicklaunch.h"
35
36
37 QuickLaunchEntry::QuickLaunchEntry()
38 {
39 _hbmp = 0;
40 }
41
42 QuickLaunchMap::~QuickLaunchMap()
43 {
44 while(!empty()) {
45 iterator it = begin();
46 DeleteBitmap(it->second._hbmp);
47 erase(it);
48 }
49 }
50
51
52 QuickLaunchBar::QuickLaunchBar(HWND hwnd)
53 : super(hwnd)
54 {
55 CONTEXT("QuickLaunchBar::QuickLaunchBar()");
56
57 _dir = NULL;
58
59 _next_id = IDC_FIRST_QUICK_ID;
60
61 HWND hwndToolTip = (HWND) SendMessage(hwnd, TB_GETTOOLTIPS, 0, 0);
62
63 SetWindowStyle(hwndToolTip, GetWindowStyle(hwndToolTip)|TTS_ALWAYSTIP);
64
65 // delay refresh to some tome later
66 PostMessage(hwnd, PM_REFRESH, 0, 0);
67 }
68
69 QuickLaunchBar::~QuickLaunchBar()
70 {
71 delete _dir;
72 }
73
74 HWND QuickLaunchBar::Create(HWND hwndParent)
75 {
76 CONTEXT("QuickLaunchBar::Create()");
77
78 ClientRect clnt(hwndParent);
79
80 HWND hwnd = CreateToolbarEx(hwndParent,
81 WS_CHILD|WS_VISIBLE|CCS_NODIVIDER|CCS_NORESIZE|
82 TBSTYLE_TOOLTIPS|TBSTYLE_WRAPABLE|TBSTYLE_FLAT,
83 IDW_QUICKLAUNCHBAR, 0, 0, 0, NULL, 0, 0, 0, 16, 16, sizeof(TBBUTTON));
84
85 if (hwnd)
86 new QuickLaunchBar(hwnd);
87
88 return hwnd;
89 }
90
91 void QuickLaunchBar::AddShortcuts()
92 {
93 CONTEXT("QuickLaunchBar::AddShortcuts()");
94
95 WaitCursor wait;
96
97 try {
98 TCHAR path[MAX_PATH];
99
100 SpecialFolderFSPath app_data(CSIDL_APPDATA, _hwnd); // perhaps also look into CSIDL_COMMON_APPDATA ?
101
102 _stprintf(path, TEXT("%s\\")QUICKLAUNCH_FOLDER, (LPCTSTR)app_data);
103
104 RecursiveCreateDirectory(path);
105 _dir = new ShellDirectory(Desktop(), path, _hwnd);
106
107 _dir->smart_scan(SCAN_EXTRACT_ICONS|SCAN_FILESYSTEM);
108 } catch(COMException&) {
109 return;
110 }
111
112
113 ShellFolder desktop_folder;
114 WindowCanvas canvas(_hwnd);
115
116 TBBUTTON btn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON|BTNS_NOPREFIX, {0, 0}, 0, 0};
117
118 for(Entry*entry=_dir->_down; entry; entry=entry->_next) {
119 // hide files like "desktop.ini"
120 if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
121 continue;
122
123 // hide subfolders
124 if (!(entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
125 HBITMAP hbmp = g_Globals._icon_cache.get_icon_bitmap(entry->_icon_id, GetSysColorBrush(COLOR_BTNFACE), canvas);
126
127 TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
128 int bmp_idx = SendMessage(_hwnd, TB_ADDBITMAP, 1, (LPARAM)&ab);
129
130 QuickLaunchEntry qle;
131
132 int id = ++_next_id;
133
134 qle._hbmp = hbmp;
135 qle._title = entry->_display_name; //entry->_etype==ET_SHELL? desktop_folder.get_name(static_cast<ShellEntry*>(entry)->_pidl): entry->_display_name
136 qle._entry = entry;
137
138 _entries[id] = qle;
139
140 btn.idCommand = id;
141 btn.iBitmap = bmp_idx;
142 int idx = SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0);
143
144 SendMessage(_hwnd, TB_INSERTBUTTON, idx, (LPARAM)&btn);
145 }
146 }
147 }
148
149 LRESULT QuickLaunchBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
150 {
151 switch(nmsg) {
152 case PM_REFRESH:
153 AddShortcuts();
154 break;
155
156 default:
157 return super::WndProc(nmsg, wparam, lparam);
158 }
159
160 return 0;
161 }
162
163 int QuickLaunchBar::Command(int id, int code)
164 {
165 CONTEXT("QuickLaunchBar::Command()");
166
167 _entries[id]._entry->launch_entry(_hwnd);
168
169 return 0;
170 }
171
172 int QuickLaunchBar::Notify(int id, NMHDR* pnmh)
173 {
174 switch(pnmh->code) {
175 case TTN_GETDISPINFO: {
176 NMTTDISPINFO* ttdi = (NMTTDISPINFO*) pnmh;
177
178 int id = ttdi->hdr.idFrom;
179 ttdi->lpszText = (LPTSTR)_entries[id]._title.c_str();
180 #ifdef TTF_DI_SETITEM
181 ttdi->uFlags |= TTF_DI_SETITEM;
182 #endif
183 break;}
184
185 return super::Notify(id, pnmh);
186 }
187
188 return 0;
189 }