X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e58989615283771efcaa9e798568772ef5fcfb0c..020707bba9c960c155f4257d9a027d6aecdae5b8:/src/msw/tbar95.cpp diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index a1d6e9d484..de0cc3ffaa 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "tbar95.h" #endif @@ -39,42 +39,23 @@ #include "wx/control.h" #endif -#if wxUSE_TOOLBAR && defined(__WIN95__) && wxUSE_TOOLBAR_NATIVE +#if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))) #include "wx/toolbar.h" - -#if !defined(__GNUWIN32__) && !defined(__SALFORDC__) - #include "malloc.h" -#endif +#include "wx/sysopt.h" #include "wx/msw/private.h" -#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)) - #include -#else - #include "wx/msw/gnuwin32/extra.h" -#endif - -#include "wx/msw/missing.h" +// include "properly" +#include "wx/msw/wrapcctl.h" #include "wx/app.h" // for GetComCtl32Version -#if defined(__MWERKS__) && defined(__WXMSW__) -// including for max definition doesn't seem -// to work using CodeWarrior 6 Windows. So we define it -// here. (Otherwise we get a undefined identifier 'max' -// later on in this file.) (Added by dimitri@shortcut.nl) -# ifndef max -# define max(a,b) (((a) > (b)) ? (a) : (b)) -# endif - -#endif - // ---------------------------------------------------------------------------- // conditional compilation // ---------------------------------------------------------------------------- -// wxWindows previously always considered that toolbar buttons have light grey +// wxWidgets previously always considered that toolbar buttons have light grey // (0xc0c0c0) background and so ignored any bitmap masks - however, this // doesn't work with XPMs which then appear to have black background. To make // this work, we must respect the bitmap masks - which we do now. This should @@ -123,7 +104,26 @@ // wxWin macros // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) +IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) + +/* + TOOLBAR PROPERTIES + tool + bitmap + bitmap2 + tooltip + longhelp + radio (bool) + toggle (bool) + separator + style ( wxNO_BORDER | wxTB_HORIZONTAL) + bitmapsize + margins + packing + separation + + dontattachtoframe +*/ BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent) @@ -178,6 +178,8 @@ public: private: size_t m_nSepCount; + + DECLARE_NO_COPY_CLASS(wxToolBarTool) }; @@ -238,6 +240,8 @@ bool wxToolBar::Create(wxWindow *parent, if ( !MSWCreateToolbar(pos, size) ) return FALSE; + wxSetCCUnicodeFormat(GetHwnd()); + // set up the colors and fonts SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR)); SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); @@ -384,6 +388,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) // Realize() later tool->Attach(this); + InvalidateBestSize(); return TRUE; } @@ -461,6 +466,7 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) } } + InvalidateBestSize(); return TRUE; } @@ -538,6 +544,22 @@ bool wxToolBar::Realize() MemoryHDC memoryDC2; #endif // USE_BITMAP_MASKS/!USE_BITMAP_MASKS + if (wxSystemOptions::HasOption(wxT("msw.remap")) && wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 0) + { +#if USE_BITMAP_MASKS + dcAllButtons.SelectObject(wxNullBitmap); +#endif + + // Even if we're not remapping the bitmap + // content, we still have to remap the background. + hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap, + totalBitmapWidth, totalBitmapHeight); + +#if USE_BITMAP_MASKS + dcAllButtons.SelectObject(bitmap); +#endif + } + // the button position wxCoord x = 0; @@ -552,13 +574,15 @@ bool wxToolBar::Realize() const wxBitmap& bmp = tool->GetNormalBitmap(); if ( bmp.Ok() ) { + int xOffset = wxMax(0, (m_defaultWidth - bmp.GetWidth())/2); + int yOffset = wxMax(0, (m_defaultHeight - bmp.GetHeight())/2); #if USE_BITMAP_MASKS // notice the last parameter: do use mask - dcAllButtons.DrawBitmap(bmp, x, 0, TRUE); + dcAllButtons.DrawBitmap(bmp, x+xOffset, yOffset, TRUE); #else // !USE_BITMAP_MASKS SelectInHDC hdcSelector2(memoryDC2, GetHbitmapOf(bmp)); if ( !BitBlt(memoryDC, - x, 0, m_defaultWidth, m_defaultHeight, + x+xOffset, yOffset, m_defaultWidth, m_defaultHeight, memoryDC2, 0, 0, SRCCOPY) ) { @@ -586,9 +610,12 @@ bool wxToolBar::Realize() bitmap.SetHBITMAP(0); #endif // USE_BITMAP_MASKS/!USE_BITMAP_MASKS - // Map to system colours - hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap, - totalBitmapWidth, totalBitmapHeight); + if (!wxSystemOptions::HasOption(wxT("msw.remap")) || wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 1) + { + // Map to system colours + hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap, + totalBitmapWidth, totalBitmapHeight); + } bool addBitmap = TRUE; @@ -794,7 +821,7 @@ bool wxToolBar::Realize() int left = -1; // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+ -#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 ) +#ifdef TB_SETBUTTONINFO // available in headers, now check whether it is available now // (during run-time) if ( wxTheApp->GetComCtl32Version() >= 471 ) @@ -897,6 +924,7 @@ bool wxToolBar::Realize() } } + InvalidateBestSize(); return TRUE; } @@ -910,28 +938,30 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id) if ( !tool ) return FALSE; + bool toggled = false; // just to suppress warnings + if ( tool->CanBeToggled() ) { LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0); - tool->Toggle((state & TBSTATE_CHECKED) != 0); - } + toggled = (state & TBSTATE_CHECKED) != 0; - bool toggled = tool->IsToggled(); + // ignore the event when a radio button is released, as this doesn't seem to + // happen at all, and is handled otherwise + if ( tool->GetKind() == wxITEM_RADIO && !toggled ) + return TRUE; - // avoid sending the event when a radio button is released, this is not - // interesting - if ( !tool->CanBeToggled() || tool->GetKind() != wxITEM_RADIO || toggled ) + tool->Toggle(toggled); + UnToggleRadioGroup(tool); + } + + // OnLeftClick() can veto the button state change - for buttons which + // may be toggled only, of couse + if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) { - // OnLeftClick() can veto the button state change - for buttons which - // may be toggled only, of couse - if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) - { - // revert back - toggled = !toggled; - tool->SetToggle(toggled); + // revert back + tool->Toggle(!toggled); - ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0)); - } + ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0)); } return TRUE; @@ -1004,7 +1034,8 @@ wxSize wxToolBar::GetToolSize() const { // TB_GETBUTTONSIZE is supported from version 4.70 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \ - && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) + && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) \ + && !defined (__DIGITALMARS__) if ( wxTheApp->GetComCtl32Version() >= 470 ) { DWORD dw = ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE, 0, 0); @@ -1175,7 +1206,7 @@ void wxToolBar::OnMouseEvent(wxMouseEvent& event) } } -bool wxToolBar::HandleSize(WXWPARAM wParam, WXLPARAM lParam) +bool wxToolBar::HandleSize(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam) { // calculate our minor dimension ourselves - we're confusing the standard // logic (TB_AUTOSIZE) with our horizontal toolbars and other hacks @@ -1309,6 +1340,10 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam) { // yes, do erase it! dc.DrawRectangle(rectItem); + + // Necessary in case we use a no-paint-on-size + // style in the parent: the controls can disappear + control->Refresh(FALSE); } } } @@ -1317,7 +1352,7 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam) return TRUE; } -void wxToolBar::HandleMouseMove(WXWPARAM wParam, WXLPARAM lParam) +void wxToolBar::HandleMouseMove(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam) { wxCoord x = GET_X_LPARAM(lParam), y = GET_Y_LPARAM(lParam); @@ -1338,7 +1373,7 @@ void wxToolBar::HandleMouseMove(WXWPARAM wParam, WXLPARAM lParam) } } -long wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) +WXLRESULT wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { switch ( nMsg ) {