Factor out common owner drawn code from wx{Check,Radio}Box.
Create wxMSWOwnerDrawnButton class which contains all of this code. Currently the methods of this class are (still) implemented in src/msw/control.cpp. See #10137. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76459 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -11,8 +11,10 @@
|
||||
#ifndef _WX_CHECKBOX_H_
|
||||
#define _WX_CHECKBOX_H_
|
||||
|
||||
#include "wx/msw/ownerdrawnbutton.h"
|
||||
|
||||
// Checkbox item (single checkbox)
|
||||
class WXDLLIMPEXP_CORE wxCheckBox : public wxCheckBoxBase
|
||||
class WXDLLIMPEXP_CORE wxCheckBox : public wxMSWOwnerDrawnButton<wxCheckBoxBase>
|
||||
{
|
||||
public:
|
||||
wxCheckBox() { }
|
||||
@@ -45,15 +47,10 @@ public:
|
||||
|
||||
virtual bool MSWCommand(WXUINT param, WXWORD id);
|
||||
virtual void Command(wxCommandEvent& event);
|
||||
virtual bool SetForegroundColour(const wxColour& colour);
|
||||
virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
|
||||
|
||||
// returns true if the platform should explicitly apply a theme border
|
||||
virtual bool CanApplyThemeBorder() const { return false; }
|
||||
|
||||
// make the checkbox owner drawn or reset it to normal style
|
||||
void MSWMakeOwnerDrawn(bool ownerDrawn);
|
||||
|
||||
// implementation only from now on
|
||||
virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle = NULL) const;
|
||||
|
||||
@@ -62,32 +59,21 @@ protected:
|
||||
|
||||
virtual void DoSet3StateValue(wxCheckBoxState value);
|
||||
virtual wxCheckBoxState DoGet3StateValue() const;
|
||||
virtual void MSWDrawButtonBitmap(wxWindow *win, wxDC& dc,
|
||||
const wxRect& rect, int flags);
|
||||
|
||||
// return true if this checkbox is owner drawn
|
||||
bool IsOwnerDrawn() const;
|
||||
// Implement wxMSWOwnerDrawnButtonBase methods.
|
||||
virtual int MSWGetButtonStyle() const wxOVERRIDE;
|
||||
virtual void MSWOnButtonResetOwnerDrawn() wxOVERRIDE;
|
||||
virtual int MSWGetButtonCheckedFlag() const wxOVERRIDE;
|
||||
virtual void
|
||||
MSWDrawButtonBitmap(wxDC& dc, const wxRect& rect, int flags) wxOVERRIDE;
|
||||
|
||||
private:
|
||||
// common part of all ctors
|
||||
void Init();
|
||||
|
||||
// event handlers used by owner-drawn checkbox
|
||||
void OnMouseEnterOrLeave(wxMouseEvent& event);
|
||||
void OnMouseLeft(wxMouseEvent& event);
|
||||
void OnFocus(wxFocusEvent& event);
|
||||
|
||||
|
||||
// current state of the checkbox
|
||||
wxCheckBoxState m_state;
|
||||
|
||||
// true if the checkbox is currently pressed
|
||||
bool m_isPressed;
|
||||
|
||||
// true if mouse is currently over the control
|
||||
bool m_isHot;
|
||||
|
||||
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxCheckBox)
|
||||
};
|
||||
|
||||
|
@@ -124,10 +124,6 @@ protected:
|
||||
// Look in our GetSubcontrols() for the windows with the given ID.
|
||||
virtual wxWindow *MSWFindItem(long id, WXHWND hWnd) const;
|
||||
|
||||
// For ownerdraw buttons
|
||||
virtual bool MSWOwnerDrawnButton(const DRAWITEMSTRUCT *dis, int flags, bool isFocused);
|
||||
virtual void MSWDrawButtonBitmap(wxWindow *WXUNUSED(win), wxDC& WXUNUSED(dc),
|
||||
const wxRect& WXUNUSED(rect), int WXUNUSED(flags)) {}
|
||||
|
||||
// for controls like radiobuttons which are really composite this array
|
||||
// holds the ids (not HWNDs!) of the sub controls
|
||||
|
122
include/wx/msw/ownerdrawnbutton.h
Normal file
122
include/wx/msw/ownerdrawnbutton.h
Normal file
@@ -0,0 +1,122 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/msw/ownerdrawnbutton.h
|
||||
// Purpose: Common base class for wxCheckBox and wxRadioButton
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2014-05-04
|
||||
// Copyright: (c) 2014 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_MSW_OWNERDRAWNBUTTON_H_
|
||||
#define _WX_MSW_OWNERDRAWNBUTTON_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMSWOwnerDrawnButton: base class for any kind of Windows buttons
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// This class contains the type-independent part of wxMSWOwnerDrawnButton and
|
||||
// is implemented in src/msw/control.cpp.
|
||||
//
|
||||
// Notice that it is intentionally not exported, it is internal implementation
|
||||
// detail only.
|
||||
class wxMSWOwnerDrawnButtonBase
|
||||
{
|
||||
protected:
|
||||
// Ctor takes the back pointer to the real window, must be non-NULL.
|
||||
wxMSWOwnerDrawnButtonBase(wxWindow* win) :
|
||||
m_win(win)
|
||||
{
|
||||
m_isPressed =
|
||||
m_isHot = false;
|
||||
}
|
||||
|
||||
// Make the control owner drawn if necessary to implement support for the
|
||||
// given foreground colour.
|
||||
void MSWMakeOwnerDrawnIfNecessary(const wxColour& colFg);
|
||||
|
||||
// Return true if the control is currently owner drawn.
|
||||
bool MSWIsOwnerDrawn() const;
|
||||
|
||||
// Draw the button if the message information about which is provided in
|
||||
// the given DRAWITEMSTRUCT asks us to do it, otherwise just return false.
|
||||
bool MSWDrawButton(WXDRAWITEMSTRUCT *item);
|
||||
|
||||
|
||||
// Methods which must be overridden in the derived concrete class.
|
||||
|
||||
// Return the style to use for the non-owner-drawn button.
|
||||
virtual int MSWGetButtonStyle() const = 0;
|
||||
|
||||
// Called after reverting button to non-owner drawn state, provides a hook
|
||||
// for wxCheckBox-specific hack.
|
||||
virtual void MSWOnButtonResetOwnerDrawn() { }
|
||||
|
||||
// Return the flags (such as wxCONTROL_CHECKED) to use for the control when
|
||||
// drawing it. Notice that this class already takes care of the common
|
||||
// logic and sets the other wxCONTROL_XXX flags on its own, this method
|
||||
// really only needs to return the flags depending on the checked state.
|
||||
virtual int MSWGetButtonCheckedFlag() const = 0;
|
||||
|
||||
// Actually draw the check or radio bitmap, typically just by using the
|
||||
// appropriate wxRendererNative method.
|
||||
virtual void
|
||||
MSWDrawButtonBitmap(wxDC& dc, const wxRect& rect, int flags) = 0;
|
||||
|
||||
|
||||
private:
|
||||
// Make the control owner drawn or reset it to normal style.
|
||||
void MSWMakeOwnerDrawn(bool ownerDrawn);
|
||||
|
||||
// Event handlers used to update the appearance of owner drawn button.
|
||||
void OnMouseEnterOrLeave(wxMouseEvent& event);
|
||||
void OnMouseLeft(wxMouseEvent& event);
|
||||
void OnFocus(wxFocusEvent& event);
|
||||
|
||||
|
||||
// The real window.
|
||||
wxWindow* const m_win;
|
||||
|
||||
// true if the checkbox is currently pressed
|
||||
bool m_isPressed;
|
||||
|
||||
// true if mouse is currently over the control
|
||||
bool m_isHot;
|
||||
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxMSWOwnerDrawnButtonBase);
|
||||
};
|
||||
|
||||
// This class uses a weak version of CRTP, i.e. it's a template class taking
|
||||
// the base class that the class deriving from it would normally derive from.
|
||||
template <class T>
|
||||
class wxMSWOwnerDrawnButton : public T,
|
||||
private wxMSWOwnerDrawnButtonBase
|
||||
{
|
||||
private:
|
||||
typedef T Base;
|
||||
|
||||
public:
|
||||
wxMSWOwnerDrawnButton() : wxMSWOwnerDrawnButtonBase(this)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool SetForegroundColour(const wxColour& colour) wxOVERRIDE
|
||||
{
|
||||
if ( !Base::SetForegroundColour(colour) )
|
||||
return false;
|
||||
|
||||
MSWMakeOwnerDrawnIfNecessary(colour);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item) wxOVERRIDE
|
||||
{
|
||||
return MSWDrawButton(item) || Base::MSWOnDraw(item);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool IsOwnerDrawn() const { return MSWIsOwnerDrawn(); }
|
||||
};
|
||||
|
||||
#endif // _WX_MSW_OWNERDRAWNBUTTON_H_
|
@@ -11,7 +11,9 @@
|
||||
#ifndef _WX_RADIOBUT_H_
|
||||
#define _WX_RADIOBUT_H_
|
||||
|
||||
class WXDLLIMPEXP_CORE wxRadioButton: public wxControl
|
||||
#include "wx/msw/ownerdrawnbutton.h"
|
||||
|
||||
class WXDLLIMPEXP_CORE wxRadioButton : public wxMSWOwnerDrawnButton<wxControl>
|
||||
{
|
||||
public:
|
||||
// ctors and creation functions
|
||||
@@ -47,36 +49,26 @@ public:
|
||||
// implementation only from now on
|
||||
virtual bool MSWCommand(WXUINT param, WXWORD id);
|
||||
virtual void Command(wxCommandEvent& event);
|
||||
virtual bool SetForegroundColour(const wxColour& colour);
|
||||
virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
|
||||
|
||||
virtual bool HasTransparentBackground() { return true; }
|
||||
|
||||
// make the radiobutton owner drawn or reset it to normal style
|
||||
void MSWMakeOwnerDrawn(bool ownerDrawn);
|
||||
|
||||
virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
|
||||
|
||||
protected:
|
||||
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
virtual void MSWDrawButtonBitmap(wxWindow *win, wxDC& dc,
|
||||
const wxRect& rect, int flags);
|
||||
|
||||
// return true if this checkbox is owner drawn
|
||||
bool IsOwnerDrawn() const;
|
||||
// Implement wxMSWOwnerDrawnButtonBase methods.
|
||||
virtual int MSWGetButtonStyle() const wxOVERRIDE;
|
||||
virtual int MSWGetButtonCheckedFlag() const wxOVERRIDE;
|
||||
virtual void
|
||||
MSWDrawButtonBitmap(wxDC& dc, const wxRect& rect, int flags) wxOVERRIDE;
|
||||
|
||||
|
||||
private:
|
||||
// common part of all ctors
|
||||
void Init();
|
||||
|
||||
// event handlers used by owner-drawn radiobutton
|
||||
void OnMouseEnterOrLeave(wxMouseEvent& event);
|
||||
void OnMouseLeft(wxMouseEvent& event);
|
||||
void OnFocus(wxFocusEvent& event);
|
||||
|
||||
// true if the radio button is currently pressed
|
||||
bool m_isPressed;
|
||||
|
||||
// we need to store the state internally as the result of GetValue()
|
||||
// sometimes gets out of sync in WM_COMMAND handler
|
||||
|
Reference in New Issue
Block a user