1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/pickerbase.h 3 // Purpose: wxPickerBase definition 4 // Author: Francesco Montorsi (based on Vadim Zeitlin's code) 5 // Modified by: 6 // Created: 14/4/2006 7 // Copyright: (c) Vadim Zeitlin, Francesco Montorsi 8 // RCS-ID: $Id: pickerbase.h 49804 2007-11-10 01:09:42Z VZ $ 9 // Licence: wxWindows Licence 10 ///////////////////////////////////////////////////////////////////////////// 11 12 #ifndef _WX_PICKERBASE_H_BASE_ 13 #define _WX_PICKERBASE_H_BASE_ 14 15 #include "wx/control.h" 16 #include "wx/sizer.h" 17 #include "wx/containr.h" 18 19 class WXDLLIMPEXP_FWD_CORE wxTextCtrl; 20 class WXDLLIMPEXP_FWD_CORE wxToolTip; 21 22 extern WXDLLEXPORT_DATA(const wxChar) wxButtonNameStr[]; 23 24 // ---------------------------------------------------------------------------- 25 // wxPickerBase is the base class for the picker controls which support 26 // a wxPB_USE_TEXTCTRL style; i.e. for those pickers which can use an auxiliary 27 // text control next to the 'real' picker. 28 // 29 // The wxTextPickerHelper class manages enabled/disabled state of the text control, 30 // its sizing and positioning. 31 // ---------------------------------------------------------------------------- 32 33 #define wxPB_USE_TEXTCTRL 0x0002 34 35 class WXDLLIMPEXP_CORE wxPickerBase : public wxControl 36 { 37 public: 38 // ctor: text is the associated text control wxPickerBase()39 wxPickerBase() : m_text(NULL), m_picker(NULL), m_sizer(NULL) 40 { m_container.SetContainerWindow(this); } ~wxPickerBase()41 virtual ~wxPickerBase() {} 42 43 44 // if present, intercepts wxPB_USE_TEXTCTRL style and creates the text control 45 // The 3rd argument is the initial wxString to display in the text control 46 bool CreateBase(wxWindow *parent, 47 wxWindowID id, 48 const wxString& text = wxEmptyString, 49 const wxPoint& pos = wxDefaultPosition, 50 const wxSize& size = wxDefaultSize, 51 long style = 0, 52 const wxValidator& validator = wxDefaultValidator, 53 const wxString& name = wxButtonNameStr); 54 55 public: // public API 56 57 // margin between the text control and the picker SetInternalMargin(int newmargin)58 void SetInternalMargin(int newmargin) 59 { GetTextCtrlItem()->SetBorder(newmargin); m_sizer->Layout(); } GetInternalMargin()60 int GetInternalMargin() const 61 { return GetTextCtrlItem()->GetBorder(); } 62 63 // proportion of the text control SetTextCtrlProportion(int prop)64 void SetTextCtrlProportion(int prop) 65 { GetTextCtrlItem()->SetProportion(prop); m_sizer->Layout(); } GetTextCtrlProportion()66 int GetTextCtrlProportion() const 67 { return GetTextCtrlItem()->GetProportion(); } 68 69 // proportion of the picker control SetPickerCtrlProportion(int prop)70 void SetPickerCtrlProportion(int prop) 71 { GetPickerCtrlItem()->SetProportion(prop); m_sizer->Layout(); } GetPickerCtrlProportion()72 int GetPickerCtrlProportion() const 73 { return GetPickerCtrlItem()->GetProportion(); } 74 IsTextCtrlGrowable()75 bool IsTextCtrlGrowable() const 76 { return (GetTextCtrlItem()->GetFlag() & wxGROW) != 0; } 77 void SetTextCtrlGrowable(bool grow = true) 78 { 79 int f = GetDefaultTextCtrlFlag(); 80 if ( grow ) 81 f |= wxGROW; 82 else 83 f &= ~wxGROW; 84 85 GetTextCtrlItem()->SetFlag(f); 86 } 87 IsPickerCtrlGrowable()88 bool IsPickerCtrlGrowable() const 89 { return (GetPickerCtrlItem()->GetFlag() & wxGROW) != 0; } 90 void SetPickerCtrlGrowable(bool grow = true) 91 { 92 int f = GetDefaultPickerCtrlFlag(); 93 if ( grow ) 94 f |= wxGROW; 95 else 96 f &= ~wxGROW; 97 98 GetPickerCtrlItem()->SetFlag(f); 99 } 100 HasTextCtrl()101 bool HasTextCtrl() const 102 { return m_text != NULL; } GetTextCtrl()103 wxTextCtrl *GetTextCtrl() 104 { return m_text; } GetPickerCtrl()105 wxControl *GetPickerCtrl() 106 { return m_picker; } 107 108 // methods that derived class must/may override 109 virtual void UpdatePickerFromTextCtrl() = 0; 110 virtual void UpdateTextCtrlFromPicker() = 0; 111 112 protected: 113 // overridden base class methods 114 #if wxUSE_TOOLTIPS 115 virtual void DoSetToolTip(wxToolTip *tip); 116 #endif // wxUSE_TOOLTIPS 117 118 119 // event handlers 120 void OnTextCtrlDelete(wxWindowDestroyEvent &); 121 void OnTextCtrlUpdate(wxCommandEvent &); 122 void OnTextCtrlKillFocus(wxFocusEvent &); 123 124 void OnSize(wxSizeEvent &); 125 126 // returns the set of styles for the attached wxTextCtrl 127 // from given wxPickerBase's styles GetTextCtrlStyle(long style)128 virtual long GetTextCtrlStyle(long style) const 129 { return (style & wxWINDOW_STYLE_MASK); } 130 131 // returns the set of styles for the m_picker GetPickerStyle(long style)132 virtual long GetPickerStyle(long style) const 133 { return (style & wxWINDOW_STYLE_MASK); } 134 135 GetPickerCtrlItem()136 wxSizerItem *GetPickerCtrlItem() const 137 { 138 if (this->HasTextCtrl()) 139 return m_sizer->GetItem((size_t)1); 140 return m_sizer->GetItem((size_t)0); 141 } 142 GetTextCtrlItem()143 wxSizerItem *GetTextCtrlItem() const 144 { 145 wxASSERT(this->HasTextCtrl()); 146 return m_sizer->GetItem((size_t)0); 147 } 148 GetDefaultPickerCtrlFlag()149 int GetDefaultPickerCtrlFlag() const 150 { 151 // on macintosh, without additional borders 152 // there's not enough space for focus rect 153 return wxALIGN_CENTER_VERTICAL|wxGROW 154 #ifdef __WXMAC__ 155 | wxTOP | wxRIGHT | wxBOTTOM 156 #endif 157 ; 158 } 159 GetDefaultTextCtrlFlag()160 int GetDefaultTextCtrlFlag() const 161 { 162 // on macintosh, without wxALL there's not enough space for focus rect 163 return wxALIGN_CENTER_VERTICAL 164 #ifdef __WXMAC__ 165 | wxALL 166 #else 167 | wxRIGHT 168 #endif 169 ; 170 } 171 172 void PostCreation(); 173 174 protected: 175 wxTextCtrl *m_text; // can be NULL 176 wxControl *m_picker; 177 wxBoxSizer *m_sizer; 178 179 private: 180 DECLARE_ABSTRACT_CLASS(wxPickerBase) 181 DECLARE_EVENT_TABLE() 182 183 // This class must be something just like a panel... 184 WX_DECLARE_CONTROL_CONTAINER(); 185 }; 186 187 188 #endif 189 // _WX_PICKERBASE_H_BASE_ 190