Refactor: create src/univ/anybutton.cpp.

Extract and pull the common functions from wxButton and wxToggleButton to
wxAnyButton in wxUniv too.

Also make wxToggleButton inherit from wxToggleButtonBase correctly

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77759 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-09-23 17:38:47 +00:00
parent 16601713a4
commit 43c99ef613
12 changed files with 497 additions and 386 deletions

View File

@@ -9,7 +9,7 @@
#ifndef _WX_UNIV_ANYBUTTON_H_
#define _WX_UNIV_ANYBUTTON_H_
#include "wx/univ/inphand.h"
// ----------------------------------------------------------------------------
// Common button functionality
// ----------------------------------------------------------------------------
@@ -21,12 +21,69 @@ public:
virtual ~wxAnyButton() {}
// wxAnyButton actions
virtual void Toggle();
virtual void Press();
virtual void Release();
virtual void Click(){}
virtual bool PerformAction(const wxControlAction& action,
long numArg = -1,
const wxString& strArg = wxEmptyString) wxOVERRIDE;
static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef) wxOVERRIDE
{
return GetStdInputHandler(handlerDef);
}
protected:
// choose the default border for this window
virtual wxBorder GetDefaultBorder() const wxOVERRIDE { return wxBORDER_STATIC; }
virtual wxSize DoGetBestClientSize() const wxOVERRIDE;
virtual bool DoDrawBackground(wxDC& dc) wxOVERRIDE;
virtual void DoDraw(wxControlRenderer *renderer) wxOVERRIDE;
// current state
bool m_isPressed,
m_isDefault;
// the (optional) image to show and the margins around it
wxBitmap m_bitmap;
wxCoord m_marginBmpX,
m_marginBmpY;
private:
wxDECLARE_NO_COPY_CLASS(wxAnyButton);
};
// ----------------------------------------------------------------------------
// wxStdAnyButtonInputHandler: translates SPACE and ENTER keys and the left mouse
// click into button press/release actions
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxStdAnyButtonInputHandler : public wxStdInputHandler
{
public:
wxStdAnyButtonInputHandler(wxInputHandler *inphand);
virtual bool HandleKey(wxInputConsumer *consumer,
const wxKeyEvent& event,
bool pressed) wxOVERRIDE;
virtual bool HandleMouse(wxInputConsumer *consumer,
const wxMouseEvent& event) wxOVERRIDE;
virtual bool HandleMouseMove(wxInputConsumer *consumer,
const wxMouseEvent& event) wxOVERRIDE;
virtual bool HandleFocus(wxInputConsumer *consumer,
const wxFocusEvent& event) wxOVERRIDE;
virtual bool HandleActivation(wxInputConsumer *consumer, bool activated) wxOVERRIDE;
private:
// the window (button) which has capture or NULL and the flag telling if
// the mouse is inside the button which captured it or not
wxWindow *m_winCapture;
bool m_winHasMouse;
};
#endif // _WX_UNIV_ANYBUTTON_H_

View File

@@ -11,14 +11,12 @@
#ifndef _WX_UNIV_BUTTON_H_
#define _WX_UNIV_BUTTON_H_
class WXDLLIMPEXP_FWD_CORE wxInputHandler;
#include "wx/bitmap.h"
// ----------------------------------------------------------------------------
// the actions supported by this control
// ----------------------------------------------------------------------------
//checkbox.cpp needed it, so not move it to anybutton.h
#define wxACTION_BUTTON_TOGGLE wxT("toggle") // press/release the button
#define wxACTION_BUTTON_PRESS wxT("press") // press the button
#define wxACTION_BUTTON_RELEASE wxT("release") // release the button
@@ -92,45 +90,19 @@ public:
virtual bool IsDefault() const wxOVERRIDE { return m_isDefault; }
// wxButton actions
virtual void Toggle();
virtual void Press();
virtual void Release();
virtual void Click();
virtual bool PerformAction(const wxControlAction& action,
long numArg = -1,
const wxString& strArg = wxEmptyString) wxOVERRIDE;
virtual void Click() wxOVERRIDE;
virtual bool CanBeHighlighted() const wxOVERRIDE { return true; }
static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef) wxOVERRIDE
{
return GetStdInputHandler(handlerDef);
}
protected:
virtual wxSize DoGetBestClientSize() const wxOVERRIDE;
virtual bool DoDrawBackground(wxDC& dc) wxOVERRIDE;
virtual void DoDraw(wxControlRenderer *renderer) wxOVERRIDE;
virtual void DoSetBitmap(const wxBitmap& bitmap, State which) wxOVERRIDE;
virtual void DoSetBitmapMargins(wxCoord x, wxCoord y) wxOVERRIDE;
// common part of all ctors
void Init();
// current state
bool m_isPressed,
m_isDefault;
// the (optional) image to show and the margins around it
wxBitmap m_bitmap;
wxCoord m_marginBmpX,
m_marginBmpY;
private:
DECLARE_DYNAMIC_CLASS(wxButton)
};

View File

@@ -11,20 +11,17 @@
#ifndef _WX_UNIV_TGLBTN_H_
#define _WX_UNIV_TGLBTN_H_
#include "wx/button.h"
// ----------------------------------------------------------------------------
// wxToggleButton: a push button
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxToggleButton: public wxButton
class WXDLLIMPEXP_CORE wxToggleButton: public wxToggleButtonBase
{
public:
wxToggleButton();
wxToggleButton(wxWindow *parent,
wxWindowID id,
const wxBitmap& bitmap,
const wxString& label = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
@@ -32,16 +29,15 @@ public:
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxCheckBoxNameStr);
wxToggleButton(wxWindow *parent,
wxWindowID id,
const wxString& label = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxCheckBoxNameStr);
virtual ~wxToggleButton();
// Create the control
bool Create(wxWindow *parent,
wxWindowID id,
const wxString& lbl = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxCheckBoxNameStr);
virtual bool IsPressed() const wxOVERRIDE { return m_isPressed || m_value; }