From a24652a4d78958d6ace377c1447bb822660cc5ee Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Sun, 17 Aug 2003 20:41:32 +0000 Subject: [PATCH] picture button for start menu svn path=/trunk/; revision=5623 --- .../system/explorer/desktop/desktop.cpp | 4 +- reactos/subsys/system/explorer/explorer.dsp | 4 + reactos/subsys/system/explorer/explorer.h | 14 -- .../subsys/system/explorer/explorer_intres.h | 4 +- .../subsys/system/explorer/explorer_intres.rc | 1 + .../subsys/system/explorer/res/startmenu.ico | Bin 0 -> 1406 bytes .../system/explorer/taskbar/taskbar.cpp | 5 +- .../subsys/system/explorer/taskbar/taskbar.h | 9 +- .../subsys/system/explorer/utility/utility.h | 41 +++++ .../subsys/system/explorer/utility/window.cpp | 160 ++++++++++++++++++ .../subsys/system/explorer/utility/window.h | 84 +++++++++ 11 files changed, 304 insertions(+), 22 deletions(-) create mode 100644 reactos/subsys/system/explorer/res/startmenu.ico diff --git a/reactos/subsys/system/explorer/desktop/desktop.cpp b/reactos/subsys/system/explorer/desktop/desktop.cpp index afdd2356850..e635e92ca14 100644 --- a/reactos/subsys/system/explorer/desktop/desktop.cpp +++ b/reactos/subsys/system/explorer/desktop/desktop.cpp @@ -72,9 +72,9 @@ static void draw_desktop_background(HWND hwnd, HDC hdc) rect.right = rect.left + 250; rect.bottom = rect.top + 40; - SetBkMode(hdc, TRANSPARENT); + BkMode bkMode(hdc, TRANSPARENT); - SetTextColor(hdc, RGB(128,128,192)); + TextColor textColor(hdc, RGB(128,128,192)); DrawText(hdc, BkgndText, -1, &rect, DT_RIGHT); SetTextColor(hdc, RGB(255,255,255)); diff --git a/reactos/subsys/system/explorer/explorer.dsp b/reactos/subsys/system/explorer/explorer.dsp index 00c38cfce79..023cdc8eb22 100644 --- a/reactos/subsys/system/explorer/explorer.dsp +++ b/reactos/subsys/system/explorer/explorer.dsp @@ -433,6 +433,10 @@ SOURCE=.\shell\shellfs.h # End Source File # Begin Source File +SOURCE=.\res\startmenu.bmp +# End Source File +# Begin Source File + SOURCE=.\shell\startup.c # End Source File # Begin Source File diff --git a/reactos/subsys/system/explorer/explorer.h b/reactos/subsys/system/explorer/explorer.h index 9b2d12c572d..f46919ddb4e 100644 --- a/reactos/subsys/system/explorer/explorer.h +++ b/reactos/subsys/system/explorer/explorer.h @@ -35,9 +35,6 @@ #include "utility/window.h" -#define BUFFER_LEN 1024 - - #define IDW_STATUSBAR 0x100 #define IDW_TOOLBAR 0x101 #define IDW_DRIVEBAR 0x102 @@ -61,17 +58,6 @@ #define CLASSNAME_WINEFILETREE TEXT("WFS_Tree") -struct String -#ifdef UNICODE - : public wstring -#else - : public string -#endif -{ - String& operator=(LPCTSTR s) {assign(s); return *this;} - operator LPCTSTR() const {return c_str();} -}; - struct ResString : public String { ResString(UINT nid); diff --git a/reactos/subsys/system/explorer/explorer_intres.h b/reactos/subsys/system/explorer/explorer_intres.h index fa8b7bfccd2..65e7bc92f03 100644 --- a/reactos/subsys/system/explorer/explorer_intres.h +++ b/reactos/subsys/system/explorer/explorer_intres.h @@ -14,6 +14,8 @@ #define IDM_MAINFRAME 105 #define ID_EXECUTE 105 #define IDM_WINEFILE 107 +#define IDB_STARTMENU 120 +#define IDI_STARTMENU 121 #define ID_VIEW_NAME 401 #define ID_VIEW_ALL_ATTRIBUTES 402 #define ID_VIEW_SELECTED_ATTRIBUTES 403 @@ -45,7 +47,7 @@ // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 120 +#define _APS_NEXT_RESOURCE_VALUE 122 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 101 diff --git a/reactos/subsys/system/explorer/explorer_intres.rc b/reactos/subsys/system/explorer/explorer_intres.rc index 285291f3ef3..4e506ccd03f 100644 --- a/reactos/subsys/system/explorer/explorer_intres.rc +++ b/reactos/subsys/system/explorer/explorer_intres.rc @@ -91,6 +91,7 @@ END // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDI_EXPLORER ICON DISCARDABLE "res/explorer.ico" +IDI_STARTMENU ICON DISCARDABLE "res/startmenu.ico" ///////////////////////////////////////////////////////////////////////////// // diff --git a/reactos/subsys/system/explorer/res/startmenu.ico b/reactos/subsys/system/explorer/res/startmenu.ico new file mode 100644 index 0000000000000000000000000000000000000000..60fc893823dcaacf54deec5889f3966e7af1b62a GIT binary patch literal 1406 zcma)+F-sgl7=~Yo;f`e?=N?=om{`SnDysy0K?I9y)^5lj5StWNSqB2bbQVb zRVm`s+C&Ig2;Rc2*W5t@U!Ix6q!E(co0AfyxP1M)RsV;AC_3rZ*j2z9=0xd2>hvv{6noF83 zr+9Ra?$JHEM^DQFdO!~Z0X?8ID56L7h#nClx)B?(#q8|p9sZ6)jzvzUY)|K4a4XBK}+mLnv4F-e3U@#aA27@8LPB26m3Ppww*Sfj6(cRsh?(grlSS-~3G<`Tb<2xQv-SiElfqXeic~fXA{^yv@CzGc0XJ$L^ z6-C*95ZW;86HoR-o-qrlKzM}0{v%2o|{sOc()YAu^w1y+C{r9n~gS6O?+Go;_ U4*z>k9&hPhn)B;bE@iIaZ<5l?aR2}S literal 0 HcmV?d00001 diff --git a/reactos/subsys/system/explorer/taskbar/taskbar.cpp b/reactos/subsys/system/explorer/taskbar/taskbar.cpp index 71fa67240ae..288ff1946db 100644 --- a/reactos/subsys/system/explorer/taskbar/taskbar.cpp +++ b/reactos/subsys/system/explorer/taskbar/taskbar.cpp @@ -32,6 +32,7 @@ #include "../explorer.h" #include "../globals.h" #include "../externals.h" +#include "../explorer_intres.h" #include "taskbar.h" @@ -80,7 +81,9 @@ LRESULT DesktopBar::Init(LPCREATESTRUCT pcs) super::Init(pcs); // create start button - Button(_hwnd, TEXT("Start"), 2, 2, 50, TASKBAR_HEIGHT-10, IDC_START);//BS_OWNERDRAW + new PictureButton(Button(_hwnd, TEXT("Start"), 2, 2, STARTBUTTON_WIDTH, TASKBAR_HEIGHT-10, IDC_START, + WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_OWNERDRAW), + LoadIcon(g_Globals._hInstance, MAKEINTRESOURCE(IDI_STARTMENU))); // create task bar WindowClass wcTaskBar(CLASSNAME_TASKBAR); diff --git a/reactos/subsys/system/explorer/taskbar/taskbar.h b/reactos/subsys/system/explorer/taskbar/taskbar.h index c9d84a8ea67..cfe7ea8c36e 100644 --- a/reactos/subsys/system/explorer/taskbar/taskbar.h +++ b/reactos/subsys/system/explorer/taskbar/taskbar.h @@ -32,8 +32,9 @@ #include -#define TASKBAR_HEIGHT 30 -#define TASKBAR_LEFT 60 +#define TASKBAR_HEIGHT 30 +#define STARTBUTTON_WIDTH 90 +#define TASKBAR_LEFT 100 //#define TASKBAR_AT_TOP #define WM_SHELLHOOK_NOTIFY (WM_APP+0x10) @@ -46,9 +47,9 @@ #define TITLE_TASKBAR _T("Running Applications") -struct DesktopBar : public Window +struct DesktopBar : public OwnerDrawParent { - typedef Window super; + typedef OwnerDrawParent super; DesktopBar(HWND hwnd); ~DesktopBar(); diff --git a/reactos/subsys/system/explorer/utility/utility.h b/reactos/subsys/system/explorer/utility/utility.h index 78b522585b9..20593deb95e 100644 --- a/reactos/subsys/system/explorer/utility/utility.h +++ b/reactos/subsys/system/explorer/utility/utility.h @@ -69,6 +69,9 @@ using namespace _com_util; #define for if (0) {} else for +#define BUFFER_LEN 1024 + + struct CommonControlInit { CommonControlInit(DWORD flags=ICC_LISTVIEW_CLASSES) @@ -106,6 +109,32 @@ struct ClientRect : public RECT }; +struct TextColor +{ + TextColor(HDC hdc, COLORREF color) + : _hdc(hdc), _old_color(SetTextColor(hdc, color)) {} + + ~TextColor() {SetTextColor(_hdc, _old_color);} + +protected: + HDC _hdc; + COLORREF _old_color; +}; + + +struct BkMode +{ + BkMode(HDC hdc, int bkmode) + : _hdc(hdc), _old_bkmode(SetBkMode(hdc, bkmode)) {} + + ~BkMode() {SetBkMode(_hdc, _old_bkmode);} + +protected: + HDC _hdc; + COLORREF _old_bkmode; +}; + + struct FullScreenParameters { FullScreenParameters() : _mode(FALSE) @@ -118,6 +147,18 @@ struct FullScreenParameters { }; +struct String +#ifdef UNICODE + : public wstring +#else + : public string +#endif +{ + String& operator=(LPCTSTR s) {assign(s); return *this;} + operator LPCTSTR() const {return c_str();} +}; + + #endif // __cplusplus diff --git a/reactos/subsys/system/explorer/utility/window.cpp b/reactos/subsys/system/explorer/utility/window.cpp index 9cae142343f..8bd727c752a 100644 --- a/reactos/subsys/system/explorer/utility/window.cpp +++ b/reactos/subsys/system/explorer/utility/window.cpp @@ -193,6 +193,9 @@ SubclassedWindow::SubclassedWindow(HWND hwnd) : Window(hwnd) { _orgWndProc = SubclassWindow(_hwnd, WindowWndProc); + + if (!_orgWndProc) + delete this; } LRESULT SubclassedWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) @@ -359,3 +362,160 @@ Button::Button(HWND parent, LPCTSTR text, int left, int top, int width, int heig _hwnd = CreateWindowEx(ex_flags, TEXT("BUTTON"), text, flags, left, top, width, height, parent, (HMENU)id, g_Globals._hInstance, 0); } + + +static RECT s_MyDrawText_Rect = {0, 0}; + +static BOOL CALLBACK MyDrawText(HDC hdc, LPARAM data, int cnt) +{ + ::DrawText(hdc, (LPCTSTR)data, cnt, &s_MyDrawText_Rect, DT_SINGLELINE); + return TRUE; +} + + +LRESULT ColorButton::WndProc(UINT message, WPARAM wparam, LPARAM lparam) +{ + if (message == WM_DISPATCH_DRAWITEM) { + LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT) lparam; + UINT style = DFCS_BUTTONPUSH; + + if (dis->itemState & ODS_DISABLED) + style |= DFCS_INACTIVE; + + RECT textRect = {dis->rcItem.left+2, dis->rcItem.top+2, dis->rcItem.right-4, dis->rcItem.bottom-4}; + + if (dis->itemState & ODS_SELECTED) { + style |= DFCS_PUSHED; + ++textRect.left; ++textRect.top; + ++textRect.right; ++textRect.bottom; + } + + DrawFrameControl(dis->hDC, &dis->rcItem, DFC_BUTTON, style); + + TCHAR text[BUFFER_LEN]; + GetWindowText(_hwnd, text, BUFFER_LEN); + + if (dis->itemState & (ODS_DISABLED|ODS_GRAYED)) { + COLORREF gray = GetSysColor(COLOR_GRAYTEXT); + + if (gray) { + { + TextColor lcColor(dis->hDC, GetSysColor(COLOR_BTNHIGHLIGHT)); + RECT shadowRect = {textRect.left+1, textRect.top+1, textRect.right+1, textRect.bottom+1}; + DrawText(dis->hDC, text, -1, &shadowRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER); + } + + BkMode mode(dis->hDC, TRANSPARENT); + TextColor lcColor(dis->hDC, gray); + DrawText(dis->hDC, text, -1, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER); + } else { + int old_r = textRect.right; + int old_b = textRect.bottom; + DrawText(dis->hDC, text, -1, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER|DT_CALCRECT); + int x = textRect.left + (old_r-textRect.right)/2; + int y = textRect.top + (old_b-textRect.bottom)/2; + int w = textRect.right-textRect.left; + int h = textRect.bottom-textRect.top; + s_MyDrawText_Rect.right = w; + s_MyDrawText_Rect.bottom = h; + GrayString(dis->hDC, GetSysColorBrush(COLOR_GRAYTEXT), MyDrawText, (LPARAM)text, -1, x, y, w, h); + } + } else { + TextColor lcColor(dis->hDC, _textColor); + DrawText(dis->hDC, text, -1, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER); + } + + if (dis->itemState & ODS_FOCUS) { + RECT rect = { + dis->rcItem.left+3, dis->rcItem.top+3, + dis->rcItem.right-dis->rcItem.left-4, dis->rcItem.bottom-dis->rcItem.top-4 + }; + if (dis->itemState & ODS_SELECTED) { + ++rect.left; ++rect.top; + ++rect.right; ++rect.bottom; + } + DrawFocusRect(dis->hDC, &rect); + } + + return TRUE; + } else + return super::WndProc(message, wparam, lparam); +} + + +LRESULT PictureButton::WndProc(UINT message, WPARAM wparam, LPARAM lparam) +{ + if (message == WM_DISPATCH_DRAWITEM) { + LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT) lparam; + UINT style = DFCS_BUTTONPUSH; + + if (dis->itemState & ODS_DISABLED) + style |= DFCS_INACTIVE; + + POINT iconPos = {dis->rcItem.left+2, dis->rcItem.top+2}; + RECT textRect = {dis->rcItem.left+2, dis->rcItem.top+2, dis->rcItem.right-4, dis->rcItem.bottom-4}; + + if (dis->itemState & ODS_SELECTED) { + style |= DFCS_PUSHED; + ++iconPos.x; ++iconPos.y; + ++textRect.left; ++textRect.top; + ++textRect.right; ++textRect.bottom; + } + +/*@@ if (_flat) { + if (GetWindowStyle(_hwnd) & BS_FLAT) // Nur wenn zusätzlich BS_FLAT gesetzt ist, wird ohne Highlight ein Rahmen gezeichnet. + DrawEdge(dis->hDC, &dis->rcItem, EDGE_RAISED, BF_RECT|BF_FLAT); + } else*/ + DrawFrameControl(dis->hDC, &dis->rcItem, DFC_BUTTON, style); + + DrawIconEx(dis->hDC, iconPos.x, iconPos.y, _hicon, 16, 16, 0, GetSysColorBrush(COLOR_BTNFACE), DI_NORMAL); + + TCHAR text[BUFFER_LEN]; + GetWindowText(_hwnd, text, BUFFER_LEN); + + if (dis->itemState & (ODS_DISABLED|ODS_GRAYED)) { + COLORREF gray = GetSysColor(COLOR_GRAYTEXT); + + if (gray) { + { + TextColor lcColor(dis->hDC, GetSysColor(COLOR_BTNHIGHLIGHT)); + RECT shadowRect = {textRect.left+1, textRect.top+1, textRect.right+1, textRect.bottom+1}; + DrawText(dis->hDC, text, -1, &shadowRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER); + } + + BkMode mode(dis->hDC, TRANSPARENT); + TextColor lcColor(dis->hDC, gray); + DrawText(dis->hDC, text, -1, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER); + } else { + int old_r = textRect.right; + int old_b = textRect.bottom; + DrawText(dis->hDC, text, -1, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER|DT_CALCRECT); + int x = textRect.left + (old_r-textRect.right)/2; + int y = textRect.top + (old_b-textRect.bottom)/2; + int w = textRect.right-textRect.left; + int h = textRect.bottom-textRect.top; + s_MyDrawText_Rect.right = w; + s_MyDrawText_Rect.bottom = h; + GrayString(dis->hDC, GetSysColorBrush(COLOR_GRAYTEXT), MyDrawText, (LPARAM)text, -1, x, y, w, h); + } + } else { + //TextColor lcColor(dis->hDC, _textColor); + DrawText(dis->hDC, text, -1, &textRect, DT_SINGLELINE|DT_VCENTER|DT_CENTER); + } + + if (dis->itemState & ODS_FOCUS) { + RECT rect = { + dis->rcItem.left+3, dis->rcItem.top+3, + dis->rcItem.right-dis->rcItem.left-4, dis->rcItem.bottom-dis->rcItem.top-4 + }; + if (dis->itemState & ODS_SELECTED) { + ++rect.left; ++rect.top; + ++rect.right; ++rect.bottom; + } + DrawFocusRect(dis->hDC, &rect); + } + + return TRUE; + } else + return super::WndProc(message, wparam, lparam); +} diff --git a/reactos/subsys/system/explorer/utility/window.h b/reactos/subsys/system/explorer/utility/window.h index 18af1eb14b9..76c2a788ab8 100644 --- a/reactos/subsys/system/explorer/utility/window.h +++ b/reactos/subsys/system/explorer/utility/window.h @@ -181,3 +181,87 @@ struct Button protected: HWND _hwnd; }; + + + // control message routing for colloered and owner drawn controls +#define WM_DISPATCH_CTLCOLOR (WM_APP+0x07) +#define WM_DISPATCH_DRAWITEM (WM_APP+0x08) + +template struct CtlColorParent : public BASE +{ + typedef BASE super; + + CtlColorParent(HWND hwnd) + : super(hwnd) {} + + LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) + { + switch(message) { + case WM_CTLCOLOR: + case WM_CTLCOLORBTN: + case WM_CTLCOLORDLG: + case WM_CTLCOLORSCROLLBAR: + case WM_CTLCOLORSTATIC: { + HWND hctl = (HWND) lparam; + return SendMessage(hctl, WM_DISPATCH_CTLCOLOR, wparam, message); + } + + default: + return super::WndProc(message, wparam, lparam); + } + } +}; + + // for ColorButton and PictureButton +template struct OwnerDrawParent : public BASE +{ + typedef BASE super; + + OwnerDrawParent(HWND hwnd) + : super(hwnd) {} + + LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) + { + switch(message) { + case WM_DRAWITEM: + if (wparam) { // ein Control? + HWND hctl = GetDlgItem(_hwnd, wparam); + + if (hctl) + return SendMessage(hctl, WM_DISPATCH_DRAWITEM, wparam, lparam); + } /*else // oder ein Menüeintrag? + ; */ + + return 0; + + default: + return super::WndProc(message, wparam, lparam); + } + } +}; + +struct ColorButton : public SubclassedWindow +{ + typedef SubclassedWindow super; + + ColorButton(HWND hwnd, COLORREF textColor) + : super(hwnd), _textColor(textColor) {} + +protected: + LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam); + + COLORREF _textColor; +}; + +struct PictureButton : public SubclassedWindow +{ + typedef SubclassedWindow super; + + PictureButton(HWND hwnd, HICON hicon) + : super(hwnd), _hicon(hicon) {} + +protected: + LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam); + + HICON _hicon; +};