2 * Copyright 2003 Martin Fuchs
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.
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.
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
25 // Martin Fuchs, 22.08.2003
29 #include "../utility/utility.h"
31 #include "../explorer.h"
33 #include "quicklaunch.h"
36 QuickLaunchEntry::QuickLaunchEntry()
41 QuickLaunchMap::~QuickLaunchMap()
44 iterator it = begin();
45 DeleteBitmap(it->second._hbmp);
51 QuickLaunchBar::QuickLaunchBar(HWND hwnd)
54 _next_id = IDC_FIRST_QUICK_ID;
56 HWND hwndToolTip = (HWND) SendMessage(hwnd, TB_GETTOOLTIPS, 0, 0);
58 SetWindowStyle(hwndToolTip, GetWindowStyle(hwndToolTip)|TTS_ALWAYSTIP);
60 // delay refresh to some tome later
61 PostMessage(hwnd, PM_REFRESH, 0, 0);
64 QuickLaunchBar::~QuickLaunchBar()
69 HWND QuickLaunchBar::Create(HWND hwndParent)
71 ClientRect clnt(hwndParent);
73 HWND hwnd = CreateToolbarEx(hwndParent,
74 WS_CHILD|WS_VISIBLE|CCS_NODIVIDER|CCS_NORESIZE|
75 TBSTYLE_TOOLTIPS|TBSTYLE_WRAPABLE|TBSTYLE_FLAT,
76 IDW_QUICKLAUNCHBAR, 0, 0, 0, NULL, 0, 0, 0, 16, 16, sizeof(TBBUTTON));
79 new QuickLaunchBar(hwnd);
84 void QuickLaunchBar::AddShortcuts()
89 TCHAR path[_MAX_PATH];
91 SpecialFolderFSPath app_data(CSIDL_APPDATA, _hwnd);
93 _stprintf(path, _T("%s\\")QUICKLAUNCH_FOLDER, (LPCTSTR)app_data);
95 _dir = new ShellDirectory(Desktop(), path, _hwnd);
96 } catch(COMException&) {
102 ShellFolder desktop_folder;
103 WindowCanvas canvas(_hwnd);
105 TBBUTTON btn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON|BTNS_NOPREFIX, {0, 0}, 0, 0};
107 for(Entry*entry=_dir->_down; entry; entry=entry->_next) {
108 // hide files like "desktop.ini"
109 if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
113 if (!(entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
114 ShellEntry* shell_entry = static_cast<ShellEntry*>(entry);
116 const String& entry_name = desktop_folder.get_name(shell_entry->_pidl);
117 HBITMAP hbmp = create_bitmap_from_icon(shell_entry->_hIcon, GetSysColorBrush(COLOR_BTNFACE), canvas);
119 TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
120 int bmp_idx = SendMessage(_hwnd, TB_ADDBITMAP, 1, (LPARAM)&ab);
122 QuickLaunchEntry qle;
127 qle._title = entry_name;
128 qle._entry = shell_entry;
133 btn.iBitmap = bmp_idx;
134 int idx = SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0);
136 SendMessage(_hwnd, TB_INSERTBUTTON, idx, (LPARAM)&btn);
141 LRESULT QuickLaunchBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
149 return super::WndProc(nmsg, wparam, lparam);
155 int QuickLaunchBar::Command(int id, int code)
157 _entries[id]._entry->launch_entry(_hwnd);
162 int QuickLaunchBar::Notify(int id, NMHDR* pnmh)
165 case TTN_GETDISPINFO: {
166 NMTTDISPINFO* ttdi = (NMTTDISPINFO*) pnmh;
168 int id = ttdi->hdr.idFrom;
169 ttdi->lpszText = (LPTSTR)_entries[id]._title.c_str();
170 #ifdef TTF_DI_SETITEM
171 ttdi->uFlags |= TTF_DI_SETITEM;
175 return super::Notify(id, pnmh);