00001 00002 // Name: ax_menu_toggle.h 00003 // Purpose: Toggle menu classes 00004 // Author: Julian Smart 00005 // Modified by: 00006 // Created: 2009-03-20 00007 // RCS-ID: 00008 // Copyright: (c) Julian Smart 00009 // Licence: New BSD License 00011 00012 #ifndef _AX_MENU_TOGGLE_H_ 00013 #define _AX_MENU_TOGGLE_H_ 00014 00015 /* 00016 * Includes 00017 */ 00018 00019 #include "ax/ax_menu.h" 00020 #include "ax/ax_activator.h" 00021 #include "ax/ax_validator.h" 00022 00037 class AxToggleMenuItem: public AxMenuItem 00038 { 00039 DECLARE_DYNAMIC_CLASS( AxToggleMenuItem ) 00040 00041 public: 00042 // Constructors 00043 00044 AxToggleMenuItem(const AxToggleMenuItem& item) { Copy(item); } 00045 AxToggleMenuItem() {} 00046 AxToggleMenuItem(const wxString& uncheckedLabel, 00047 const wxString& checkedLabel, 00048 const wxString& description, 00049 const wxString& id = wxEmptyString, 00050 bool value = false); 00051 00052 void Copy(const AxToggleMenuItem& item) 00053 { 00054 AxMenuItem::Copy(item); 00055 00056 m_checked = item.m_checked; 00057 m_uncheckedLabel = item.m_uncheckedLabel; 00058 m_checkedLabel = item.m_checkedLabel; 00059 } 00060 00061 virtual AxMenuItem* Clone() { return new AxToggleMenuItem(* this); } 00062 00063 bool IsChecked() const { return m_checked; } 00064 virtual bool Check(bool checked); 00065 00066 void UpdateToggleLabel(); 00067 00068 void SendToggleUpdate(bool value); 00069 00070 void SetUncheckedLabel(const wxString& label) { m_uncheckedLabel = label; } 00071 const wxString& GetUncheckedLabel() const { return m_uncheckedLabel; } 00072 00073 void SetCheckedLabel(const wxString& label) { m_checkedLabel = label; } 00074 const wxString& GetCheckedLabel() const { return m_checkedLabel; } 00075 00076 protected: 00077 00078 bool m_checked; 00079 wxString m_uncheckedLabel; 00080 wxString m_checkedLabel; 00081 }; 00082 00091 class AxToggleActivator: public AxActivator 00092 { 00093 DECLARE_DYNAMIC_CLASS( AxToggleActivator ) 00094 00095 public: 00096 // Constructors 00097 00098 AxToggleActivator() { Init(); } 00099 AxToggleActivator(const AxToggleActivator& activator) { Init(); Copy(activator); } 00100 00101 ~AxToggleActivator() {} 00102 00103 // Operations 00104 00105 void Init() { } 00106 00107 virtual AxActivator* Clone() const { return new AxToggleActivator(*this); } 00108 00109 void Copy(const AxToggleActivator& activator); 00110 00112 virtual AxMenu* Activate(AxMenuController* controller, AxMenuItem* item); 00113 00115 virtual bool BeforeDisplay(AxMenuController* controller, AxMenuItem* item); 00116 00118 virtual bool UpdateUI(AxMenuController* controller, AxMenuItem* item); 00119 00120 AxToggleMenuItem* GetToggleMenuItem() const; 00121 00122 protected: 00123 }; 00124 00129 class AxToggleValidator: public AxValidator 00130 { 00131 DECLARE_DYNAMIC_CLASS( AxToggleValidator ) 00132 00133 public: 00134 // Constructors 00135 00136 AxToggleValidator(const AxToggleValidator& validator) { Init(); Copy(validator); } 00137 AxToggleValidator(bool* ptr) { Init(); m_boolPtr = ptr; } 00138 AxToggleValidator() { Init(); } 00139 ~AxToggleValidator() {} 00140 00141 // Operations 00142 00143 void Copy(const AxToggleValidator& validator) 00144 { 00145 AxValidator::Copy(validator); 00146 00147 m_boolPtr = validator.m_boolPtr; 00148 } 00149 00150 virtual AxValidator* Clone() const { return new AxToggleValidator(*this); } 00151 00153 virtual bool TransferDataFromMenu(); 00154 00156 virtual bool TransferDataToMenu(); 00157 00159 void Init() { m_boolPtr = NULL; } 00160 00161 protected: 00162 bool* m_boolPtr; 00163 }; 00164 00165 #endif 00166 // _AX_MENU_TOGGLE_H_