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_