moved plugin source from taskbar directory to winefile/plugins
[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
33 #include "quicklaunch.h"
34
35
36 QuickLaunchEntry::QuickLaunchEntry()
37 {
38 _hbmp = 0;
39 }
40
41 QuickLaunchMap::~QuickLaunchMap()
42 {
43 while(!empty()) {
44 iterator it = begin();
45 DeleteBitmap(it->second._hbmp);
46 erase(it);
47 }
48 }
49
50
51 QuickLaunchBar::QuickLaunchBar(HWND hwnd)
52 : super(hwnd)
53 {
54 _next_id = IDC_FIRST_QUICK_ID;
55
56 // delay refresh to some tome later
57 PostMessage(hwnd, PM_REFRESH, 0, 0);
58 }
59
60 QuickLaunchBar::~QuickLaunchBar()
61 {
62 delete _dir;
63 }
64
65 HWND QuickLaunchBar::Create(HWND hwndParent)
66 {
67 ClientRect clnt(hwndParent);
68
69 HWND hwnd = CreateToolbarEx(hwndParent,
70 WS_CHILD|WS_VISIBLE|CCS_NODIVIDER|CCS_NORESIZE|
71 TBSTYLE_TOOLTIPS|TBSTYLE_WRAPABLE|TBSTYLE_FLAT,
72 IDW_QUICKLAUNCHBAR, 0, 0, 0, NULL, 0, 0, 0, 16, 16, sizeof(TBBUTTON));
73
74 if (hwnd)
75 new QuickLaunchBar(hwnd);
76
77 return hwnd;
78 }
79
80 void QuickLaunchBar::AddShortcuts()
81 {
82 WaitCursor wait;
83
84 try {
85 TCHAR path[_MAX_PATH];
86
87 SpecialFolderFSPath app_data(CSIDL_APPDATA, _hwnd);
88
89 _stprintf(path, _T("%s\\")QUICKLAUNCH_FOLDER, (LPCTSTR)app_data);
90
91 _dir = new ShellDirectory(Desktop(), path, _hwnd);
92 } catch(COMException&) {
93 return;
94 }
95
96 _dir->smart_scan();
97
98 ShellFolder desktop_folder;
99 WindowCanvas canvas(_hwnd);
100
101 TBBUTTON btn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON|BTNS_NOPREFIX, {0, 0}, 0, 0};
102
103 for(Entry*entry=_dir->_down; entry; entry=entry->_next) {
104 // hide files like "desktop.ini"
105 if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
106 continue;
107
108 // hide subfolders
109 if (!(entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
110 ShellEntry* shell_entry = static_cast<ShellEntry*>(entry);
111
112 const String& entry_name = desktop_folder.get_name(shell_entry->_pidl);
113 HBITMAP hbmp = create_bitmap_from_icon(shell_entry->_hIcon, GetSysColorBrush(COLOR_BTNFACE), canvas);
114
115 TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
116 int bmp_idx = SendMessage(_hwnd, TB_ADDBITMAP, 1, (LPARAM)&ab);
117
118 QuickLaunchEntry qle;
119
120 int id = ++_next_id;
121
122 qle._hbmp = hbmp;
123 qle._title = entry_name;
124 qle._entry = shell_entry;
125
126 _entries[id] = qle;
127
128 btn.idCommand = id;
129 btn.iBitmap = bmp_idx;
130 int idx = SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0);
131
132 SendMessage(_hwnd, TB_INSERTBUTTON, idx, (LPARAM)&btn);
133 }
134 }
135 }
136
137 LRESULT QuickLaunchBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
138 {
139 switch(nmsg) {
140 case PM_REFRESH:
141 AddShortcuts();
142 break;
143
144 default:
145 return super::WndProc(nmsg, wparam, lparam);
146 }
147
148 return 0;
149 }
150
151 int QuickLaunchBar::Command(int id, int code)
152 {
153 _entries[id]._entry->launch_entry(_hwnd);
154
155 return 0;
156 }
157
158 int QuickLaunchBar::Notify(int id, NMHDR* pnmh)
159 {
160 switch(pnmh->code) {
161 case TTN_GETDISPINFO: { //TODO: TTN_GETDISPINFO is only received, if desktop bar window has the focus?!
162 NMTTDISPINFO* ttdi = (NMTTDISPINFO*) pnmh;
163
164 int id = ttdi->hdr.idFrom;
165 ttdi->lpszText = (LPTSTR)_entries[id]._title.c_str();
166 #ifdef TTF_DI_SETITEM
167 ttdi->uFlags |= TTF_DI_SETITEM;
168 #endif
169 break;}
170
171 return super::Notify(id, pnmh);
172 }
173
174 return 0;
175 }