automatically adjusted size of notification area and quicklaunch bar in desktop bar
[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 _next_id = IDC_FIRST_QUICK_ID;
59 _btn_dist = 20;
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 time 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 COLORREF bk_color = GetSysColor(COLOR_BTNFACE);
117 HBRUSH bk_brush = GetSysColorBrush(COLOR_BTNFACE);
118
119 TBBUTTON btn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON|BTNS_NOPREFIX, {0, 0}, 0, 0};
120
121 for(Entry*entry=_dir->_down; entry; entry=entry->_next) {
122 // hide files like "desktop.ini"
123 if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
124 continue;
125
126 // hide subfolders
127 if (!(entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
128 HBITMAP hbmp = g_Globals._icon_cache.get_icon(entry->_icon_id).create_bitmap(bk_color, bk_brush, canvas);
129
130 TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
131 int bmp_idx = SendMessage(_hwnd, TB_ADDBITMAP, 1, (LPARAM)&ab);
132
133 QuickLaunchEntry qle;
134
135 int id = ++_next_id;
136
137 qle._hbmp = hbmp;
138 qle._title = entry->_display_name; //entry->_etype==ET_SHELL? desktop_folder.get_name(static_cast<ShellEntry*>(entry)->_pidl): entry->_display_name
139 qle._entry = entry;
140
141 _entries[id] = qle;
142
143 btn.idCommand = id;
144 btn.iBitmap = bmp_idx;
145 int idx = SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0);
146
147 SendMessage(_hwnd, TB_INSERTBUTTON, idx, (LPARAM)&btn);
148 }
149 }
150
151 _btn_dist = LOWORD(SendMessage(_hwnd, TB_GETBUTTONSIZE, 0, 0));
152 SendMessage(GetParent(_hwnd), PM_RESIZE_CHILDREN, 0, 0);
153 }
154
155 LRESULT QuickLaunchBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
156 {
157 switch(nmsg) {
158 case PM_REFRESH:
159 AddShortcuts();
160 break;
161
162 case PM_GET_WIDTH:
163 return _entries.size()*_btn_dist;
164
165 default:
166 return super::WndProc(nmsg, wparam, lparam);
167 }
168
169 return 0;
170 }
171
172 int QuickLaunchBar::Command(int id, int code)
173 {
174 CONTEXT("QuickLaunchBar::Command()");
175
176 _entries[id]._entry->launch_entry(_hwnd);
177
178 return 0;
179 }
180
181 int QuickLaunchBar::Notify(int id, NMHDR* pnmh)
182 {
183 switch(pnmh->code) {
184 case TTN_GETDISPINFO: {
185 NMTTDISPINFO* ttdi = (NMTTDISPINFO*) pnmh;
186
187 int id = ttdi->hdr.idFrom;
188 ttdi->lpszText = (LPTSTR)_entries[id]._title.c_str();
189 #ifdef TTF_DI_SETITEM
190 ttdi->uFlags |= TTF_DI_SETITEM;
191 #endif
192 break;}
193
194 return super::Notify(id, pnmh);
195 }
196
197 return 0;
198 }