-bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
- const wxBitmap& bitmap,
- const wxPoint& pos,
- const wxSize& size, long style,
- const wxValidator& wxVALIDATOR_PARAM(validator),
- const wxString& name)
-{
- m_bmpNormal = bitmap;
- SetName(name);
-
-#if wxUSE_VALIDATORS
- SetValidator(validator);
-#endif // wxUSE_VALIDATORS
-
- parent->AddChild(this);
-
- m_windowStyle = style;
-
- if ( style & wxBU_AUTODRAW )
- {
- m_marginX =
- m_marginY = 4;
- }
-
- if (id == wxID_ANY)
- m_windowId = NewControlId();
- else
- m_windowId = id;
-
- long msStyle = WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_OWNERDRAW ;
-
- if ( m_windowStyle & wxCLIP_SIBLINGS )
- msStyle |= WS_CLIPSIBLINGS;
-
-#ifdef __WIN32__
- if(m_windowStyle & wxBU_LEFT)
- msStyle |= BS_LEFT;
- if(m_windowStyle & wxBU_RIGHT)
- msStyle |= BS_RIGHT;
- if(m_windowStyle & wxBU_TOP)
- msStyle |= BS_TOP;
- if(m_windowStyle & wxBU_BOTTOM)
- msStyle |= BS_BOTTOM;
-#endif
-
- m_hWnd = (WXHWND) CreateWindowEx(
- 0,
- wxT("BUTTON"),
- wxEmptyString,
- msStyle,
- 0, 0, 0, 0,
- GetWinHwnd(parent),
- (HMENU)m_windowId,
- wxGetInstance(),
- NULL
- );
-
- // Subclass again for purposes of dialog editing mode
- SubclassWin(m_hWnd);
-
- SetPosition(pos);
- SetBestSize(size);
-
- return true;
-}
-
-bool wxBitmapButton::SetBackgroundColour(const wxColour& colour)
-{
- if ( !wxBitmapButtonBase::SetBackgroundColour(colour) )
- {
- // didn't change
- return false;
- }
-
- // invalidate the brush, it will be recreated the next time it's needed
- m_brushDisabled = wxNullBrush;
-
- return true;
-}
-
-void wxBitmapButton::OnSysColourChanged(wxSysColourChangedEvent& event)
-{
- m_brushDisabled = wxNullBrush;
-
- if ( !IsEnabled() )
- {
- // this change affects our current state
- Refresh();
- }
-
- event.Skip();
-}
-
-void wxBitmapButton::OnMouseEnterOrLeave(wxMouseEvent& event)
-{
- if ( IsEnabled() && m_bmpHover.Ok() )
- Refresh();
-
- event.Skip();
-}
-
-void wxBitmapButton::OnSetBitmap()
-{
- // if the focus bitmap is specified but hover one isn't, use the focus
- // bitmap for hovering as well if this is consistent with the current
- // Windows version look and feel
- //
- // rationale: this is compatible with the old wxGTK behaviour and also
- // makes it much easier to do "the right thing" for all platforms (some of
- // them, such as Windows XP, have "hot" buttons while others don't)
- if ( !m_bmpHover.Ok() &&
- m_bmpFocus.Ok() &&
- wxUxThemeEngine::GetIfActive() )
- {
- m_bmpHover = m_bmpFocus;
- }
-
- // this will redraw us
- wxBitmapButtonBase::OnSetBitmap();
-}
-
-#if wxUSE_UXTHEME
-static
-void MSWDrawXPBackground(wxButton *button, WXDRAWITEMSTRUCT *wxdis)
-{
- LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT)wxdis;
- HDC hdc = lpDIS->hDC;
- UINT state = lpDIS->itemState;
- RECT rectBtn;
- CopyRect(&rectBtn, &lpDIS->rcItem);
-
- wxUxThemeHandle theme(button, L"BUTTON");
- int iState;
-
- if ( state & ODS_SELECTED )
- {
- iState = PBS_PRESSED;
- }
- else if ( button->HasCapture() || button->IsMouseInWindow() )
- {
- iState = PBS_HOT;
- }
- else if ( state & ODS_FOCUS )
- {
- iState = PBS_DEFAULTED;
- }
- else if ( state & ODS_DISABLED )
- {
- iState = PBS_DISABLED;
- }
- else
- {
- iState = PBS_NORMAL;
- }
-
- // draw parent background if needed
- if ( wxUxThemeEngine::Get()->IsThemeBackgroundPartiallyTransparent(theme,
- BP_PUSHBUTTON,
- iState) )
- {
- wxUxThemeEngine::Get()->DrawThemeParentBackground(GetHwndOf(button), hdc, &rectBtn);
- }
-
- // draw background
- wxUxThemeEngine::Get()->DrawThemeBackground(theme, hdc, BP_PUSHBUTTON, iState,
- &rectBtn, NULL);
-
- // calculate content area margins
- MARGINS margins;
- wxUxThemeEngine::Get()->GetThemeMargins(theme, hdc, BP_PUSHBUTTON, iState,
- TMT_CONTENTMARGINS, &rectBtn, &margins);
- RECT rectClient;
- ::CopyRect(&rectClient, &rectBtn);
- ::InflateRect(&rectClient, -margins.cxLeftWidth, -margins.cyTopHeight);
-
- // if focused and !nofocus rect
- if ( (state & ODS_FOCUS) && !(state & ODS_NOFOCUSRECT) )
- {
- DrawFocusRect(hdc, &rectClient);
- }
-
- if ( button->UseBgCol() )
- {
- COLORREF colBg = wxColourToRGB(button->GetBackgroundColour());
- HBRUSH hbrushBackground = ::CreateSolidBrush(colBg);
-
- // don't overwrite the focus rect
- ::InflateRect(&rectClient, -1, -1);
- FillRect(hdc, &rectClient, hbrushBackground);
- ::DeleteObject(hbrushBackground);
- }
-}
-#endif // wxUSE_UXTHEME
-
-// VZ: should be at the very least less than wxDEFAULT_BUTTON_MARGIN
-#define FOCUS_MARGIN 3
-
-bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item)