From eabe6af8d99699e96d7ebcac0f2319aebeb4c533 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sat, 21 Feb 2004 16:38:23 +0000 Subject: [PATCH] implementation for mac added git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25899 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/tglbtn.h | 59 ++++++++++++++++++ include/wx/tglbtn.h | 4 +- src/mac/carbon/tglbtn.cpp | 127 ++++++++++++++++++++++++++++++++++++++ src/mac/tglbtn.cpp | 127 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 315 insertions(+), 2 deletions(-) create mode 100644 include/wx/mac/tglbtn.h create mode 100644 src/mac/carbon/tglbtn.cpp create mode 100644 src/mac/tglbtn.cpp diff --git a/include/wx/mac/tglbtn.h b/include/wx/mac/tglbtn.h new file mode 100644 index 0000000000..5ab29aa84c --- /dev/null +++ b/include/wx/mac/tglbtn.h @@ -0,0 +1,59 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/mac/tglbtn.h +// Purpose: Declaration of the wxToggleButton class, which implements a +// toggle button under wxMac. +// Author: Stefan Csomor +// Modified by: +// Created: 08.02.01 +// RCS-ID: $Id$ +// Copyright: (c) 2004 Stefan Csomor +// License: wxWindows License +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_TOGGLEBUTTON_H_ +#define _WX_TOGGLEBUTTON_H_ + +WXDLLEXPORT_DATA(extern const wxChar*) wxCheckBoxNameStr; + +// Checkbox item (single checkbox) +class WXDLLEXPORT wxToggleButton : public wxControl +{ +public: + wxToggleButton() {} + wxToggleButton(wxWindow *parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxCheckBoxNameStr) + { + Create(parent, id, label, pos, size, style, validator, name); + } + + bool Create(wxWindow *parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxCheckBoxNameStr); + + virtual void SetValue(bool value); + virtual bool GetValue() const ; + + virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ; + + virtual void Command(wxCommandEvent& event); + +protected: + virtual wxSize DoGetBestSize() const; + +private: + DECLARE_DYNAMIC_CLASS_NO_COPY(wxToggleButton) +}; + +#endif // _WX_TOGGLEBUTTON_H_ + diff --git a/include/wx/tglbtn.h b/include/wx/tglbtn.h index 9a8eebf236..a69f362286 100644 --- a/include/wx/tglbtn.h +++ b/include/wx/tglbtn.h @@ -32,9 +32,9 @@ END_DECLARE_EVENT_TYPES() #include "wx/gtk/tglbtn.h" # elif defined(__WXMOTIF__) #include "wx/motif/tglbtn.h" +#elif defined(__WXMAC__) + #include "wx/mac/tglbtn.h" /* -# elif defined(__WXMAC__) -# include "wx/mac/tglbtn.h" # elif defined(__WXPM__) # include "wx/os2/tglbtn.h" */ diff --git a/src/mac/carbon/tglbtn.cpp b/src/mac/carbon/tglbtn.cpp new file mode 100644 index 0000000000..755e1d2f05 --- /dev/null +++ b/src/mac/carbon/tglbtn.cpp @@ -0,0 +1,127 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/mac/tglbtn.cpp +// Purpose: Definition of the wxToggleButton class, which implements a +// toggle button under wxMac. +// Author: Stefan Csomor +// Modified by: +// Created: 08.02.01 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Johnny C. Norris II +// License: Rocketeer license +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declatations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ +#pragma implementation "button.h" +#endif + +#include "wx/defs.h" +#include "wx/tglbtn.h" + +#if wxUSE_TOGGLEBTN + +#include "wx/mac/uma.h" +// Button + +static const int kMacOSXHorizontalBorder = 2 ; +static const int kMacOSXVerticalBorder = 4 ; + +// ---------------------------------------------------------------------------- +// macros +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxToggleButton +// ---------------------------------------------------------------------------- + +// Single check box item +bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name) +{ + if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) + return false; + + Rect bounds ; + Str255 title ; + + if ( UMAHasAquaLayout() ) + { + m_macHorizontalBorder = kMacOSXHorizontalBorder; + m_macVerticalBorder = kMacOSXVerticalBorder; + } + + MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; + + m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , kControlBehaviorToggles , 1, + kControlBevelButtonNormalBevelProc , (long) this ) ; + wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; + + MacPostControlCreate() ; + + return TRUE; +} + +wxSize wxToggleButton::DoGetBestSize() const +{ + int wBtn = 70 ; + int hBtn = 20 ; + + int lBtn = m_label.Length() * 10 + 12 ; + if (lBtn > wBtn) + wBtn = lBtn; + + if ( UMAHasAquaLayout() ) + { + wBtn += 2 * kMacOSXHorizontalBorder ; + hBtn += 2 * kMacOSXVerticalBorder ; + } + return wxSize ( wBtn , hBtn ) ; +} + +void wxToggleButton::SetValue(bool val) +{ + ::SetControl32BitValue( (ControlHandle) m_macControl , val ) ; +} + +bool wxToggleButton::GetValue() const +{ + return GetControl32BitValue( (ControlHandle) m_macControl ) ; +} + +void wxToggleButton::Command(wxCommandEvent & event) +{ + SetValue((event.GetInt() != 0)); + ProcessCommand(event); +} + +void wxToggleButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) ) +{ + if ( controlpart != kControlNoPart ) + { + wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); + event.SetInt(GetValue()); + event.SetEventObject(this); + ProcessCommand(event); + } +} + +#endif // wxUSE_TOGGLEBTN + diff --git a/src/mac/tglbtn.cpp b/src/mac/tglbtn.cpp new file mode 100644 index 0000000000..755e1d2f05 --- /dev/null +++ b/src/mac/tglbtn.cpp @@ -0,0 +1,127 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/mac/tglbtn.cpp +// Purpose: Definition of the wxToggleButton class, which implements a +// toggle button under wxMac. +// Author: Stefan Csomor +// Modified by: +// Created: 08.02.01 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Johnny C. Norris II +// License: Rocketeer license +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declatations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ +#pragma implementation "button.h" +#endif + +#include "wx/defs.h" +#include "wx/tglbtn.h" + +#if wxUSE_TOGGLEBTN + +#include "wx/mac/uma.h" +// Button + +static const int kMacOSXHorizontalBorder = 2 ; +static const int kMacOSXVerticalBorder = 4 ; + +// ---------------------------------------------------------------------------- +// macros +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxToggleButton +// ---------------------------------------------------------------------------- + +// Single check box item +bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name) +{ + if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) + return false; + + Rect bounds ; + Str255 title ; + + if ( UMAHasAquaLayout() ) + { + m_macHorizontalBorder = kMacOSXHorizontalBorder; + m_macVerticalBorder = kMacOSXVerticalBorder; + } + + MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; + + m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , kControlBehaviorToggles , 1, + kControlBevelButtonNormalBevelProc , (long) this ) ; + wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; + + MacPostControlCreate() ; + + return TRUE; +} + +wxSize wxToggleButton::DoGetBestSize() const +{ + int wBtn = 70 ; + int hBtn = 20 ; + + int lBtn = m_label.Length() * 10 + 12 ; + if (lBtn > wBtn) + wBtn = lBtn; + + if ( UMAHasAquaLayout() ) + { + wBtn += 2 * kMacOSXHorizontalBorder ; + hBtn += 2 * kMacOSXVerticalBorder ; + } + return wxSize ( wBtn , hBtn ) ; +} + +void wxToggleButton::SetValue(bool val) +{ + ::SetControl32BitValue( (ControlHandle) m_macControl , val ) ; +} + +bool wxToggleButton::GetValue() const +{ + return GetControl32BitValue( (ControlHandle) m_macControl ) ; +} + +void wxToggleButton::Command(wxCommandEvent & event) +{ + SetValue((event.GetInt() != 0)); + ProcessCommand(event); +} + +void wxToggleButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) ) +{ + if ( controlpart != kControlNoPart ) + { + wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); + event.SetInt(GetValue()); + event.SetEventObject(this); + ProcessCommand(event); + } +} + +#endif // wxUSE_TOGGLEBTN +