- Use a separate icon for minimizing windows.
[reactos.git] / reactos / subsys / system / explorer / taskbar / quicklaunch.cpp
index 727aaf9..8214d93 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003 Martin Fuchs
+ * Copyright 2003, 2004, 2005 Martin Fuchs
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  //
 
 
-#include "../utility/utility.h"
+#include <precomp.h>
 
-#include "../explorer.h"
-#include "../globals.h"
-#include "../externals.h"
-#include "../explorer_intres.h"
+#include "../resource.h"
 
 #include "quicklaunch.h"
 
@@ -59,6 +56,7 @@ QuickLaunchBar::QuickLaunchBar(HWND hwnd)
        _dir = NULL;
        _next_id = IDC_FIRST_QUICK_ID;
        _btn_dist = 20;
+       _size = 0;
 
        HWND hwndToolTip = (HWND) SendMessage(hwnd, TB_GETTOOLTIPS, 0, 0);
 
@@ -80,7 +78,8 @@ HWND QuickLaunchBar::Create(HWND hwndParent)
        ClientRect clnt(hwndParent);
 
        HWND hwnd = CreateToolbarEx(hwndParent,
-                                                               WS_CHILD|WS_VISIBLE|CCS_NODIVIDER|CCS_NORESIZE|
+                                                               WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|
+                                                               CCS_TOP|CCS_NODIVIDER|CCS_NOPARENTALIGN|CCS_NORESIZE|
                                                                TBSTYLE_TOOLTIPS|TBSTYLE_WRAPABLE|TBSTYLE_FLAT,
                                                                IDW_QUICKLAUNCHBAR, 0, 0, 0, NULL, 0, 0, 0, 16, 16, sizeof(TBBUTTON));
 
@@ -106,7 +105,11 @@ void QuickLaunchBar::AddShortcuts()
                RecursiveCreateDirectory(path);
                _dir = new ShellDirectory(GetDesktopFolder(), path, _hwnd);
 
-               _dir->smart_scan(SCAN_EXTRACT_ICONS|SCAN_FILESYSTEM);
+               _dir->smart_scan(SORT_NAME, /*SCAN_EXTRACT_ICONS|*/SCAN_FILESYSTEM);
+
+                // immediatelly extract the shortcut icons
+               for(Entry*entry=_dir->_down; entry; entry=entry->_next)
+                       entry->_icon_id = entry->safe_extract_icon(ICF_NORMAL);
        } catch(COMException&) {
                return;
        }
@@ -118,7 +121,7 @@ void QuickLaunchBar::AddShortcuts()
        COLORREF bk_color = GetSysColor(COLOR_BTNFACE);
        HBRUSH bk_brush = GetSysColorBrush(COLOR_BTNFACE);
 
-       AddButton(ID_MINIMIZE_ALL, g_Globals._icon_cache.get_icon(ICID_LOGOFF/*@@*/).create_bitmap(bk_color, bk_brush, canvas), ResString(IDS_MINIMIZE_ALL), NULL);
+       AddButton(ID_MINIMIZE_ALL, g_Globals._icon_cache.get_icon(ICID_MINIMIZE/*@@*/).create_bitmap(bk_color, bk_brush, canvas), ResString(IDS_MINIMIZE_ALL), NULL);
        AddButton(ID_EXPLORE, g_Globals._icon_cache.get_icon(ICID_EXPLORER).create_bitmap(bk_color, bk_brush, canvas), ResString(IDS_TITLE), NULL);
 
        TBBUTTON sep = {0, -1, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
@@ -133,6 +136,7 @@ void QuickLaunchBar::AddShortcuts()
        int cy = HIWORD(size);
        RECT rect = {0, 0, cx, cy};
        RECT textRect = {0, 0, cx-7, cy-7};
+
        for(int i=0; i<DESKTOP_COUNT; ++i) {
                HBITMAP hbmp = CreateCompatibleBitmap(canvas, cx, cy);
                HBITMAP hbmp_old = SelectBitmap(hdc, hbmp);
@@ -165,6 +169,8 @@ void QuickLaunchBar::AddShortcuts()
        }
 
        _btn_dist = LOWORD(SendMessage(_hwnd, TB_GETBUTTONSIZE, 0, 0));
+       _size = _entries.size() * _btn_dist;
+
        SendMessage(GetParent(_hwnd), PM_RESIZE_CHILDREN, 0, 0);
 }
 
@@ -205,14 +211,52 @@ LRESULT QuickLaunchBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
                AddShortcuts();
                break;
 
-         case PM_GET_WIDTH:
-               return _entries.size()*_btn_dist;
+         case PM_GET_WIDTH: {
+                // take line wrapping into account 
+               int btns = SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0);
+               int rows = SendMessage(_hwnd, TB_GETROWS, 0, 0);
+
+               if (rows<2 || rows==btns)
+                       return _size;
+
+               RECT rect;
+               int max_cx = 0;
+
+               for(QuickLaunchMap::const_iterator it=_entries.begin(); it!=_entries.end(); ++it) {
+                       SendMessage(_hwnd, TB_GETRECT, it->first, (LPARAM)&rect);
+
+                       if (rect.right > max_cx)
+                               max_cx = rect.right;
+               }
+
+               return max_cx;}
 
          case PM_UPDATE_DESKTOP:
                UpdateDesktopButtons(wparam);
                break;
 
-         default:
+         case WM_CONTEXTMENU: {
+               TBBUTTON btn;
+               QuickLaunchMap::iterator it;
+               Point screen_pt(lparam), clnt_pt=screen_pt;
+               ScreenToClient(_hwnd, &clnt_pt);
+
+               Entry* entry = NULL;
+               int idx = SendMessage(_hwnd, TB_HITTEST, 0, (LPARAM)&clnt_pt);
+
+               if (idx>=0 &&
+                       SendMessage(_hwnd, TB_GETBUTTON, idx, (LPARAM)&btn)!=-1 &&
+                       (it=_entries.find(btn.idCommand))!=_entries.end()) {
+                       entry = it->second._entry;
+               }
+
+               if (entry)      // entry is NULL for desktop switch buttons
+                       CHECKERROR(entry->do_context_menu(_hwnd, screen_pt, _cm_ifs));
+               else
+                       goto def;
+               break;}
+
+         default: def:
                return super::WndProc(nmsg, wparam, lparam);
        }
 
@@ -232,7 +276,7 @@ int QuickLaunchBar::Command(int id, int code)
                }
        }
 
-       return 1;
+       return 0; // Don't return 1 to avoid recursion with DesktopBar::Command()
 }
 
 int QuickLaunchBar::Notify(int id, NMHDR* pnmh)
@@ -242,10 +286,14 @@ int QuickLaunchBar::Notify(int id, NMHDR* pnmh)
                NMTTDISPINFO* ttdi = (NMTTDISPINFO*) pnmh;
 
                int id = ttdi->hdr.idFrom;
-               ttdi->lpszText = (LPTSTR)_entries[id]._title.c_str();
+               ttdi->lpszText = _entries[id]._title.str();
 #ifdef TTF_DI_SETITEM
                ttdi->uFlags |= TTF_DI_SETITEM;
 #endif
+
+                // enable multiline tooltips (break at CR/LF and for very long one-line strings)
+               SendMessage(pnmh->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 400);
+
                break;}
 
                return super::Notify(id, pnmh);