2 * Copyright 2003, 2004 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
21 // Explorer clone, lean version
25 // Martin Fuchs, 22.08.2003
31 #include "../explorer_intres.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 CONTEXT("QuickLaunchBar::QuickLaunchBar()");
57 _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
); ///@todo perhaps also look into CSIDL_COMMON_APPDATA ?
102 _stprintf(path
, TEXT("%s\\")QUICKLAUNCH_FOLDER
, (LPCTSTR
)app_data
);
104 RecursiveCreateDirectory(path
);
105 _dir
= new ShellDirectory(GetDesktopFolder(), 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 AddButton(ID_MINIMIZE_ALL
, g_Globals
._icon_cache
.get_icon(ICID_LOGOFF
/*@@*/).create_bitmap(bk_color
, bk_brush
, canvas
), ResString(IDS_MINIMIZE_ALL
), NULL
);
120 AddButton(ID_EXPLORE
, g_Globals
._icon_cache
.get_icon(ICID_EXPLORER
).create_bitmap(bk_color
, bk_brush
, canvas
), ResString(IDS_TITLE
), NULL
);
122 TBBUTTON sep
= {0, -1, TBSTATE_ENABLED
, BTNS_SEP
, {0, 0}, 0, 0};
123 SendMessage(_hwnd
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&sep
);
125 int cur_desktop
= g_Globals
._desktops
._current_desktop
;
126 ResString
desktop_fmt(IDS_DESKTOP_NUM
);
128 HDC hdc
= CreateCompatibleDC(canvas
);
129 DWORD size
= SendMessage(_hwnd
, TB_GETBUTTONSIZE
, 0, 0);
130 int cx
= LOWORD(size
);
131 int cy
= HIWORD(size
);
132 RECT rect
= {0, 0, cx
, cy
};
133 RECT textRect
= {0, 0, cx
-7, cy
-7};
134 for(int i
=0; i
<DESKTOP_COUNT
; ++i
) {
135 HBITMAP hbmp
= CreateCompatibleBitmap(canvas
, cx
, cy
);
136 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
138 FmtString
num_txt(TEXT("%d"), i
+1);
139 TextColor
color(hdc
, RGB(64,64,64));
140 BkMode
mode(hdc
, TRANSPARENT
);
141 FillRect(hdc
, &rect
, GetSysColorBrush(COLOR_BTNFACE
));
142 DrawText(hdc
, num_txt
, num_txt
.length(), &textRect
, DT_CENTER
|DT_VCENTER
|DT_SINGLELINE
);
144 SelectBitmap(hdc
, hbmp_old
);
146 AddButton(ID_SWITCH_DESKTOP_1
+i
, hbmp
, FmtString(desktop_fmt
, i
+1), NULL
, cur_desktop
==i
?TBSTATE_ENABLED
|TBSTATE_CHECKED
:TBSTATE_ENABLED
);
150 SendMessage(_hwnd
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&sep
);
152 for(Entry
*entry
=_dir
->_down
; entry
; entry
=entry
->_next
) {
153 // hide files like "desktop.ini"
154 if (entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
158 if (!(entry
->_data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
159 HBITMAP hbmp
= g_Globals
._icon_cache
.get_icon(entry
->_icon_id
).create_bitmap(bk_color
, bk_brush
, canvas
);
161 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 _btn_dist
= LOWORD(SendMessage(_hwnd
, TB_GETBUTTONSIZE
, 0, 0));
166 _size
= _entries
.size() * _btn_dist
;
168 SendMessage(GetParent(_hwnd
), PM_RESIZE_CHILDREN
, 0, 0);
171 void QuickLaunchBar::AddButton(int id
, HBITMAP hbmp
, LPCTSTR name
, Entry
* entry
, int flags
)
173 TBADDBITMAP ab
= {0, (UINT_PTR
)hbmp
};
174 int bmp_idx
= SendMessage(_hwnd
, TB_ADDBITMAP
, 1, (LPARAM
)&ab
);
176 QuickLaunchEntry qle
;
184 TBBUTTON btn
= {0, 0, flags
, BTNS_BUTTON
|BTNS_NOPREFIX
, {0, 0}, 0, 0};
187 btn
.iBitmap
= bmp_idx
;
189 SendMessage(_hwnd
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&btn
);
192 void QuickLaunchBar::UpdateDesktopButtons(int desktop_idx
)
194 for(int i
=0; i
<DESKTOP_COUNT
; ++i
) {
195 TBBUTTONINFO tbi
= {sizeof(TBBUTTONINFO
), TBIF_STATE
, 0, 0, desktop_idx
==i
? TBSTATE_ENABLED
|TBSTATE_CHECKED
: TBSTATE_ENABLED
};
197 SendMessage(_hwnd
, TB_SETBUTTONINFO
, ID_SWITCH_DESKTOP_1
+i
, (LPARAM
)&tbi
);
201 LRESULT
QuickLaunchBar::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
209 // take line wrapping into account
210 int btns
= SendMessage(_hwnd
, TB_BUTTONCOUNT
, 0, 0);
211 int rows
= SendMessage(_hwnd
, TB_GETROWS
, 0, 0);
213 if (rows
<2 || rows
==btns
)
219 for(QuickLaunchMap::const_iterator it
=_entries
.begin(); it
!=_entries
.end(); ++it
) {
220 SendMessage(_hwnd
, TB_GETRECT
, it
->first
, (LPARAM
)&rect
);
222 if (rect
.right
> max_cx
)
228 case PM_UPDATE_DESKTOP
:
229 UpdateDesktopButtons(wparam
);
233 return super::WndProc(nmsg
, wparam
, lparam
);
239 int QuickLaunchBar::Command(int id
, int code
)
241 CONTEXT("QuickLaunchBar::Command()");
243 if ((id
&~0xFF) == IDC_FIRST_QUICK_ID
) {
244 QuickLaunchEntry
& qle
= _entries
[id
];
247 qle
._entry
->launch_entry(_hwnd
);
255 int QuickLaunchBar::Notify(int id
, NMHDR
* pnmh
)
258 case TTN_GETDISPINFO
: {
259 NMTTDISPINFO
* ttdi
= (NMTTDISPINFO
*) pnmh
;
261 int id
= ttdi
->hdr
.idFrom
;
262 ttdi
->lpszText
= (LPTSTR
)_entries
[id
]._title
.c_str();
263 #ifdef TTF_DI_SETITEM
264 ttdi
->uFlags
|= TTF_DI_SETITEM
;
268 return super::Notify(id
, pnmh
);