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"
32 #include "../globals.h"
34 #include "quicklaunch.h"
37 QuickLaunchEntry::QuickLaunchEntry()
42 QuickLaunchMap::~QuickLaunchMap()
45 iterator it
= begin();
46 DeleteBitmap(it
->second
._hbmp
);
52 QuickLaunchBar::QuickLaunchBar(HWND hwnd
)
55 CONTEXT("QuickLaunchBar::QuickLaunchBar()");
58 _next_id
= IDC_FIRST_QUICK_ID
;
61 HWND hwndToolTip
= (HWND
) SendMessage(hwnd
, TB_GETTOOLTIPS
, 0, 0);
63 SetWindowStyle(hwndToolTip
, GetWindowStyle(hwndToolTip
)|TTS_ALWAYSTIP
);
65 // delay refresh to some time later
66 PostMessage(hwnd
, PM_REFRESH
, 0, 0);
69 QuickLaunchBar::~QuickLaunchBar()
74 HWND
QuickLaunchBar::Create(HWND hwndParent
)
76 CONTEXT("QuickLaunchBar::Create()");
78 ClientRect
clnt(hwndParent
);
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
));
86 new QuickLaunchBar(hwnd
);
91 void QuickLaunchBar::AddShortcuts()
93 CONTEXT("QuickLaunchBar::AddShortcuts()");
100 SpecialFolderFSPath
app_data(CSIDL_APPDATA
, _hwnd
); // perhaps also look into CSIDL_COMMON_APPDATA ?
102 _stprintf(path
, TEXT("%s\\")QUICKLAUNCH_FOLDER
, (LPCTSTR
)app_data
);
104 RecursiveCreateDirectory(path
);
105 _dir
= new ShellDirectory(Desktop(), path
, _hwnd
);
107 _dir
->smart_scan(SCAN_EXTRACT_ICONS
|SCAN_FILESYSTEM
);
108 } catch(COMException
&) {
113 ShellFolder desktop_folder
;
114 WindowCanvas
canvas(_hwnd
);
116 COLORREF bk_color
= GetSysColor(COLOR_BTNFACE
);
117 HBRUSH bk_brush
= GetSysColorBrush(COLOR_BTNFACE
);
119 TBBUTTON btn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
|BTNS_NOPREFIX
, {0, 0}, 0, 0};
121 for(Entry
*entry
=_dir
->_down
; entry
; entry
=entry
->_next
) {
122 // hide files like "desktop.ini"
123 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
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
);
130 TBADDBITMAP ab
= {0, (UINT_PTR
)hbmp
};
131 int bmp_idx
= SendMessage(_hwnd
, TB_ADDBITMAP
, 1, (LPARAM
)&ab
);
133 QuickLaunchEntry qle
;
138 qle
._title
= entry
->_display_name
; //entry->_etype==ET_SHELL? desktop_folder.get_name(static_cast<ShellEntry*>(entry)->_pidl): entry->_display_name
144 btn
.iBitmap
= bmp_idx
;
145 int idx
= SendMessage(_hwnd
, TB_BUTTONCOUNT
, 0, 0);
147 SendMessage(_hwnd
, TB_INSERTBUTTON
, idx
, (LPARAM
)&btn
);
151 _btn_dist
= LOWORD(SendMessage(_hwnd
, TB_GETBUTTONSIZE
, 0, 0));
152 SendMessage(GetParent(_hwnd
), PM_RESIZE_CHILDREN
, 0, 0);
155 LRESULT
QuickLaunchBar::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
163 return _entries
.size()*_btn_dist
;
166 return super::WndProc(nmsg
, wparam
, lparam
);
172 int QuickLaunchBar::Command(int id
, int code
)
174 CONTEXT("QuickLaunchBar::Command()");
176 _entries
[id
]._entry
->launch_entry(_hwnd
);
181 int QuickLaunchBar::Notify(int id
, NMHDR
* pnmh
)
184 case TTN_GETDISPINFO
: {
185 NMTTDISPINFO
* ttdi
= (NMTTDISPINFO
*) pnmh
;
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
;
194 return super::Notify(id
, pnmh
);