ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

quicklaunch.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2003, 2004, 2005 Martin Fuchs
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 
00020  //
00021  // Explorer clone
00022  //
00023  // quicklaunch.cpp
00024  //
00025  // Martin Fuchs, 22.08.2003
00026  //
00027 
00028 
00029 #include <precomp.h>
00030 
00031 #include "../resource.h"
00032 
00033 #include "quicklaunch.h"
00034 
00035 
00036 QuickLaunchEntry::QuickLaunchEntry()
00037 {
00038     _hbmp = 0;
00039 }
00040 
00041 QuickLaunchMap::~QuickLaunchMap()
00042 {
00043     while(!empty()) {
00044         iterator it = begin();
00045         DeleteBitmap(it->second._hbmp);
00046         erase(it);
00047     }
00048 }
00049 
00050 
00051 QuickLaunchBar::QuickLaunchBar(HWND hwnd)
00052  :  super(hwnd)
00053 {
00054     CONTEXT("QuickLaunchBar::QuickLaunchBar()");
00055 
00056     _dir = NULL;
00057     _next_id = IDC_FIRST_QUICK_ID;
00058     _btn_dist = 20;
00059     _size = 0;
00060 
00061     HWND hwndToolTip = (HWND) SendMessage(hwnd, TB_GETTOOLTIPS, 0, 0);
00062 
00063     SetWindowStyle(hwndToolTip, GetWindowStyle(hwndToolTip)|TTS_ALWAYSTIP);
00064 
00065      // delay refresh to some time later
00066     PostMessage(hwnd, PM_REFRESH, 0, 0);
00067 }
00068 
00069 QuickLaunchBar::~QuickLaunchBar()
00070 {
00071     delete _dir;
00072 }
00073 
00074 HWND QuickLaunchBar::Create(HWND hwndParent)
00075 {
00076     CONTEXT("QuickLaunchBar::Create()");
00077 
00078     ClientRect clnt(hwndParent);
00079 
00080     HWND hwnd = CreateToolbarEx(hwndParent,
00081                                 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|
00082                                 CCS_TOP|CCS_NODIVIDER|CCS_NOPARENTALIGN|CCS_NORESIZE|
00083                                 TBSTYLE_TOOLTIPS|TBSTYLE_WRAPABLE|TBSTYLE_FLAT,
00084                                 IDW_QUICKLAUNCHBAR, 0, 0, 0, NULL, 0, 0, 0, 16, 16, sizeof(TBBUTTON));
00085 
00086     if (hwnd)
00087         new QuickLaunchBar(hwnd);
00088 
00089     return hwnd;
00090 }
00091 
00092 void QuickLaunchBar::AddShortcuts()
00093 {
00094     CONTEXT("QuickLaunchBar::AddShortcuts()");
00095 
00096     WaitCursor wait;
00097 
00098     try {
00099         TCHAR path[MAX_PATH];
00100 
00101         SpecialFolderFSPath app_data(CSIDL_APPDATA, _hwnd); 
00102 
00103         _stprintf(path, TEXT("%s\\")QUICKLAUNCH_FOLDER, (LPCTSTR)app_data);
00104 
00105         RecursiveCreateDirectory(path);
00106         _dir = new ShellDirectory(GetDesktopFolder(), path, _hwnd);
00107 
00108         _dir->smart_scan(SORT_NAME);
00109 
00110          // immediatelly extract the shortcut icons
00111         for(Entry*entry=_dir->_down; entry; entry=entry->_next)
00112             entry->_icon_id = entry->safe_extract_icon(ICF_NORMAL);
00113     } catch(COMException&) {
00114         return;
00115     }
00116 
00117 
00118     ShellFolder desktop_folder;
00119     WindowCanvas canvas(_hwnd);
00120 
00121     COLORREF bk_color = GetSysColor(COLOR_BTNFACE);
00122     HBRUSH bk_brush = GetSysColorBrush(COLOR_BTNFACE);
00123 
00124     AddButton(ID_MINIMIZE_ALL, g_Globals._icon_cache.get_icon(ICID_MINIMIZE).create_bitmap(bk_color, bk_brush, canvas), ResString(IDS_MINIMIZE_ALL), NULL);
00125     AddButton(ID_EXPLORE, g_Globals._icon_cache.get_icon(ICID_EXPLORER).create_bitmap(bk_color, bk_brush, canvas), ResString(IDS_TITLE), NULL);
00126 
00127     TBBUTTON sep = {0, -1, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
00128     SendMessage(_hwnd, TB_INSERTBUTTON, INT_MAX, (LPARAM)&sep);
00129 
00130     int cur_desktop = g_Globals._desktops._current_desktop;
00131     ResString desktop_fmt(IDS_DESKTOP_NUM);
00132 
00133     HDC hdc = CreateCompatibleDC(canvas);
00134     DWORD size = SendMessage(_hwnd, TB_GETBUTTONSIZE, 0, 0);
00135     int cx = LOWORD(size);
00136     int cy = HIWORD(size);
00137     RECT rect = {0, 0, cx, cy};
00138     RECT textRect = {0, 0, cx-7, cy-7};
00139 
00140     for(int i=0; i<DESKTOP_COUNT; ++i) {
00141         HBITMAP hbmp = CreateCompatibleBitmap(canvas, cx, cy);
00142         HBITMAP hbmp_old = SelectBitmap(hdc, hbmp);
00143 
00144         FontSelection font(hdc, GetStockFont(ANSI_VAR_FONT));
00145         FmtString num_txt(TEXT("%d"), i+1);
00146         TextColor color(hdc, RGB(64,64,64));
00147         BkMode mode(hdc, TRANSPARENT);
00148         FillRect(hdc, &rect, GetSysColorBrush(COLOR_BTNFACE));
00149         DrawText(hdc, num_txt, num_txt.length(), &textRect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
00150 
00151         SelectBitmap(hdc, hbmp_old);
00152 
00153         AddButton(ID_SWITCH_DESKTOP_1+i, hbmp, FmtString(desktop_fmt, i+1), NULL, cur_desktop==i?TBSTATE_ENABLED|TBSTATE_PRESSED:TBSTATE_ENABLED);
00154     }
00155     DeleteDC(hdc);
00156 
00157     for(Entry*entry=_dir->_down; entry; entry=entry->_next) {
00158          // hide files like "desktop.ini"
00159         if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
00160             continue;
00161 
00162          // hide subfolders
00163         if (!(entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
00164             HBITMAP hbmp = g_Globals._icon_cache.get_icon(entry->_icon_id).create_bitmap(bk_color, bk_brush, canvas);
00165 
00166             AddButton(_next_id++, hbmp, entry->_display_name, entry);   //entry->_etype==ET_SHELL? desktop_folder.get_name(static_cast<ShellEntry*>(entry)->_pidl): entry->_display_name);
00167         }
00168     }
00169 
00170     _btn_dist = LOWORD(SendMessage(_hwnd, TB_GETBUTTONSIZE, 0, 0));
00171     _size = _entries.size() * _btn_dist;
00172 
00173     SendMessage(GetParent(_hwnd), PM_RESIZE_CHILDREN, 0, 0);
00174 }
00175 
00176 void QuickLaunchBar::AddButton(int id, HBITMAP hbmp, LPCTSTR name, Entry* entry, int flags)
00177 {
00178     TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
00179     int bmp_idx = SendMessage(_hwnd, TB_ADDBITMAP, 1, (LPARAM)&ab);
00180 
00181     QuickLaunchEntry qle;
00182 
00183     qle._hbmp = hbmp;
00184     qle._title = name;
00185     qle._entry = entry;
00186 
00187     _entries[id] = qle;
00188 
00189     TBBUTTON btn = {0, 0, flags, BTNS_BUTTON|BTNS_NOPREFIX, {0, 0}, 0, 0};
00190 
00191     btn.idCommand = id;
00192     btn.iBitmap = bmp_idx;
00193 
00194     SendMessage(_hwnd, TB_INSERTBUTTON, INT_MAX, (LPARAM)&btn);
00195 }
00196 
00197 void QuickLaunchBar::UpdateDesktopButtons(int desktop_idx)
00198 {
00199     for(int i=0; i<DESKTOP_COUNT; ++i) {
00200         TBBUTTONINFO tbi = {sizeof(TBBUTTONINFO), TBIF_STATE, 0, 0, desktop_idx==i? TBSTATE_ENABLED|TBSTATE_PRESSED: TBSTATE_ENABLED};
00201 
00202         SendMessage(_hwnd, TB_SETBUTTONINFO, ID_SWITCH_DESKTOP_1+i, (LPARAM)&tbi);
00203     }
00204 }
00205 
00206 LRESULT QuickLaunchBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
00207 {
00208     switch(nmsg) {
00209       case PM_REFRESH:
00210         AddShortcuts();
00211         break;
00212 
00213       case PM_GET_WIDTH: {
00214          // take line wrapping into account
00215         int btns = SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0);
00216         int rows = SendMessage(_hwnd, TB_GETROWS, 0, 0);
00217 
00218         if (rows<2 || rows==btns)
00219             return _size;
00220 
00221         RECT rect;
00222         int max_cx = 0;
00223 
00224         for(QuickLaunchMap::const_iterator it=_entries.begin(); it!=_entries.end(); ++it) {
00225             SendMessage(_hwnd, TB_GETRECT, it->first, (LPARAM)&rect);
00226 
00227             if (rect.right > max_cx)
00228                 max_cx = rect.right;
00229         }
00230 
00231         return max_cx;}
00232 
00233       case PM_UPDATE_DESKTOP:
00234         UpdateDesktopButtons(wparam);
00235         break;
00236 
00237       case WM_CONTEXTMENU: {
00238         TBBUTTON btn;
00239         QuickLaunchMap::iterator it;
00240         Point screen_pt(lparam), clnt_pt=screen_pt;
00241         ScreenToClient(_hwnd, &clnt_pt);
00242 
00243         Entry* entry = NULL;
00244         int idx = SendMessage(_hwnd, TB_HITTEST, 0, (LPARAM)&clnt_pt);
00245 
00246         if (idx>=0 &&
00247             SendMessage(_hwnd, TB_GETBUTTON, idx, (LPARAM)&btn)!=-1 &&
00248             (it=_entries.find(btn.idCommand))!=_entries.end()) {
00249             entry = it->second._entry;
00250         }
00251 
00252         if (entry) {    // entry is NULL for desktop switch buttons
00253             HRESULT hr = entry->do_context_menu(_hwnd, screen_pt, _cm_ifs);
00254 
00255             if (!SUCCEEDED(hr))
00256                 CHECKERROR(hr);
00257         } else
00258             goto def;
00259         break;}
00260 
00261       default: def:
00262         return super::WndProc(nmsg, wparam, lparam);
00263     }
00264 
00265     return 0;
00266 }
00267 
00268 int QuickLaunchBar::Command(int id, int code)
00269 {
00270     CONTEXT("QuickLaunchBar::Command()");
00271 
00272     if ((id&~0xFF) == IDC_FIRST_QUICK_ID) {
00273         QuickLaunchEntry& qle = _entries[id];
00274 
00275         if (qle._entry) {
00276             qle._entry->launch_entry(_hwnd);
00277             return 0;
00278         }
00279     }
00280 
00281     return 0; // Don't return 1 to avoid recursion with DesktopBar::Command()
00282 }
00283 
00284 int QuickLaunchBar::Notify(int id, NMHDR* pnmh)
00285 {
00286     switch(pnmh->code) {
00287       case TTN_GETDISPINFO: {
00288         NMTTDISPINFO* ttdi = (NMTTDISPINFO*) pnmh;
00289 
00290         int id = ttdi->hdr.idFrom;
00291         ttdi->lpszText = _entries[id]._title.str();
00292 #ifdef TTF_DI_SETITEM
00293         ttdi->uFlags |= TTF_DI_SETITEM;
00294 #endif
00295 
00296          // enable multiline tooltips (break at CR/LF and for very long one-line strings)
00297         SendMessage(pnmh->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 400);
00298 
00299         break;}
00300 
00301         return super::Notify(id, pnmh);
00302     }
00303 
00304     return 0;
00305 }

Generated on Sat May 26 2012 04:17:33 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.