]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | /////////////////////////////////////////////////////////////////////////////// |
c18353e5 | 2 | // Name: src/mac/carbon/checklst.cpp |
e9576ca5 | 3 | // Purpose: implementation of wxCheckListBox class |
a31a5f85 | 4 | // Author: Stefan Csomor |
3dee36ae | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 | 10 | /////////////////////////////////////////////////////////////////////////////// |
c18353e5 DS |
11 | // |
12 | // new DataBrowser-based version | |
e9576ca5 | 13 | |
e9576ca5 | 14 | |
a8e9860d | 15 | #include "wx/wxprec.h" |
e9576ca5 | 16 | |
55d60746 GD |
17 | #if wxUSE_CHECKLISTBOX |
18 | ||
b698c8e9 | 19 | #include "wx/checklst.h" |
aaa6d89a WS |
20 | |
21 | #ifndef WX_PRECOMP | |
22 | #include "wx/arrstr.h" | |
23 | #endif | |
b698c8e9 | 24 | |
dbfc5b97 | 25 | #include "wx/mac/uma.h" |
c18353e5 | 26 | |
768c6e8b | 27 | #ifndef __DARWIN__ |
7f0c3a63 | 28 | #include <Appearance.h> |
768c6e8b | 29 | #endif |
dbfc5b97 | 30 | |
dbfc5b97 SC |
31 | IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) |
32 | ||
d058c153 SC |
33 | BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox) |
34 | END_EVENT_TABLE() | |
dbfc5b97 | 35 | |
6cce68ea SC |
36 | class wxMacDataBrowserCheckListControl : public wxMacDataBrowserListControl , public wxMacCheckListControl |
37 | { | |
38 | public: | |
39 | wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style ); | |
d3c7fc99 | 40 | virtual ~wxMacDataBrowserCheckListControl(); |
6cce68ea | 41 | |
9ce05df4 | 42 | virtual wxMacDataItem* CreateItem(); |
aaa6d89a | 43 | |
6cce68ea SC |
44 | virtual bool MacIsChecked(unsigned int n) const; |
45 | virtual void MacCheck(unsigned int n, bool bCheck = true); | |
46 | }; | |
47 | ||
dbfc5b97 SC |
48 | void wxCheckListBox::Init() |
49 | { | |
50 | } | |
51 | ||
c18353e5 DS |
52 | bool wxCheckListBox::Create( |
53 | wxWindow *parent, | |
54 | wxWindowID id, | |
55 | const wxPoint &pos, | |
56 | const wxSize &size, | |
57 | const wxArrayString& choices, | |
58 | long style, | |
59 | const wxValidator& validator, | |
60 | const wxString &name ) | |
584ad2a3 | 61 | { |
c18353e5 | 62 | wxCArrayString chs( choices ); |
584ad2a3 | 63 | |
c18353e5 | 64 | return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name ); |
584ad2a3 MB |
65 | } |
66 | ||
c18353e5 DS |
67 | bool wxCheckListBox::Create( |
68 | wxWindow *parent, | |
69 | wxWindowID id, | |
70 | const wxPoint& pos, | |
71 | const wxSize& size, | |
72 | int n, | |
73 | const wxString choices[], | |
74 | long style, | |
75 | const wxValidator& validator, | |
76 | const wxString& name ) | |
dbfc5b97 | 77 | { |
c18353e5 | 78 | m_macIsUserPane = false; |
d058c153 SC |
79 | |
80 | wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), | |
c18353e5 | 81 | wxT("only one of listbox selection modes can be specified") ); |
3dee36ae | 82 | |
c18353e5 | 83 | if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) |
b45ed7a2 VZ |
84 | return false; |
85 | ||
c18353e5 | 86 | // this will be increased by our Append command |
6cce68ea SC |
87 | wxMacDataBrowserCheckListControl* control = new wxMacDataBrowserCheckListControl( this, pos, size, style ); |
88 | control->SetClientDataType( m_clientDataItemsType ); | |
89 | m_peer = control; | |
dbfc5b97 | 90 | |
b4726a58 | 91 | MacPostControlCreate(pos,size); |
3dee36ae | 92 | |
aaa6d89a | 93 | InsertItems( n , choices , 0 ); |
dbfc5b97 | 94 | |
c18353e5 DS |
95 | // Needed because it is a wxControlWithItems |
96 | SetBestSize( size ); | |
3dee36ae WS |
97 | |
98 | return true; | |
dbfc5b97 | 99 | } |
e9576ca5 SC |
100 | |
101 | // ---------------------------------------------------------------------------- | |
dbfc5b97 | 102 | // wxCheckListBox functions |
e9576ca5 SC |
103 | // ---------------------------------------------------------------------------- |
104 | ||
aa61d352 | 105 | bool wxCheckListBox::IsChecked(unsigned int item) const |
dbfc5b97 | 106 | { |
aa61d352 | 107 | wxCHECK_MSG( IsValid(item), false, |
c18353e5 | 108 | wxT("invalid index in wxCheckListBox::IsChecked") ); |
dbfc5b97 | 109 | |
6cce68ea | 110 | return GetPeer()->MacIsChecked( item ); |
dbfc5b97 SC |
111 | } |
112 | ||
aa61d352 | 113 | void wxCheckListBox::Check(unsigned int item, bool check) |
dbfc5b97 | 114 | { |
aa61d352 | 115 | wxCHECK_RET( IsValid(item), |
c18353e5 | 116 | wxT("invalid index in wxCheckListBox::Check") ); |
dbfc5b97 | 117 | |
6cce68ea | 118 | bool isChecked = GetPeer()->MacIsChecked( item ); |
dbfc5b97 SC |
119 | if ( check != isChecked ) |
120 | { | |
6cce68ea | 121 | GetPeer()->MacCheck( item , check ); |
dbfc5b97 SC |
122 | } |
123 | } | |
124 | ||
aaa6d89a WS |
125 | wxMacCheckListControl* wxCheckListBox::GetPeer() const |
126 | { | |
127 | return dynamic_cast<wxMacCheckListControl*>(m_peer); | |
6cce68ea | 128 | } |
dbfc5b97 | 129 | |
6cce68ea | 130 | const short kCheckboxColumnId = 1026; |
e9576ca5 | 131 | |
6cce68ea SC |
132 | wxMacDataBrowserCheckListControl::wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style) |
133 | : wxMacDataBrowserListControl( peer, pos, size, style ) | |
134 | { | |
135 | OSStatus err = noErr; | |
136 | ||
137 | DataBrowserListViewColumnDesc columnDesc; | |
138 | columnDesc.headerBtnDesc.titleOffset = 0; | |
139 | columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; | |
140 | ||
141 | columnDesc.headerBtnDesc.btnFontStyle.flags = | |
142 | kControlUseFontMask | kControlUseJustMask; | |
143 | ||
144 | columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent; | |
145 | columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault; | |
146 | columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; | |
147 | columnDesc.headerBtnDesc.btnFontStyle.style = normal; | |
148 | columnDesc.headerBtnDesc.titleString = NULL; | |
149 | ||
150 | columnDesc.headerBtnDesc.minimumWidth = 30; | |
151 | columnDesc.headerBtnDesc.maximumWidth = 30; | |
152 | ||
153 | columnDesc.propertyDesc.propertyID = kCheckboxColumnId; | |
154 | columnDesc.propertyDesc.propertyType = kDataBrowserCheckboxType; | |
155 | columnDesc.propertyDesc.propertyFlags = | |
156 | kDataBrowserPropertyIsMutable | |
157 | | kDataBrowserTableViewSelectionColumn | |
158 | | kDataBrowserDefaultPropertyFlags; | |
aaa6d89a | 159 | |
6cce68ea SC |
160 | err = AddColumn( &columnDesc, 0 ); |
161 | verify_noerr( err ); | |
dbfc5b97 SC |
162 | } |
163 | ||
6cce68ea | 164 | wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl() |
e9576ca5 | 165 | { |
aaa6d89a | 166 | |
e9576ca5 SC |
167 | } |
168 | ||
6cce68ea | 169 | class wxMacCheckListBoxItem : public wxMacListBoxItem |
e9576ca5 | 170 | { |
6cce68ea SC |
171 | public : |
172 | wxMacCheckListBoxItem() | |
173 | { | |
174 | m_isChecked = false; | |
175 | } | |
aaa6d89a | 176 | |
d3c7fc99 | 177 | virtual ~wxMacCheckListBoxItem() |
6cce68ea SC |
178 | { |
179 | } | |
aaa6d89a | 180 | |
6cce68ea SC |
181 | virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner , |
182 | DataBrowserPropertyID property, | |
183 | DataBrowserItemDataRef itemData, | |
aaa6d89a | 184 | bool changeValue ) |
6cce68ea SC |
185 | { |
186 | OSStatus err = errDataBrowserPropertyNotSupported; | |
187 | ||
188 | wxCheckListBox *checklist = wxDynamicCast( owner->GetPeer() , wxCheckListBox ); | |
189 | wxCHECK_MSG( checklist != NULL , errDataBrowserPropertyNotSupported , wxT("wxCheckListBox expected")); | |
190 | ||
191 | if ( !changeValue ) | |
192 | { | |
193 | switch (property) | |
194 | { | |
195 | case kCheckboxColumnId: | |
196 | verify_noerr(SetDataBrowserItemDataButtonValue( itemData, m_isChecked ? kThemeButtonOn : kThemeButtonOff )); | |
197 | err = noErr; | |
198 | break; | |
199 | ||
200 | case kDataBrowserItemIsEditableProperty: | |
201 | verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true )); | |
202 | err = noErr; | |
203 | break; | |
204 | ||
205 | default: | |
206 | break; | |
207 | } | |
208 | } | |
209 | else | |
210 | { | |
211 | switch (property) | |
212 | { | |
213 | case kCheckboxColumnId: | |
214 | { | |
215 | // we have to change this behind the back, since Check() would be triggering another update round | |
216 | bool newVal = !m_isChecked; | |
217 | verify_noerr(SetDataBrowserItemDataButtonValue( itemData, newVal ? kThemeButtonOn : kThemeButtonOff )); | |
218 | m_isChecked = newVal; | |
219 | err = noErr; | |
220 | ||
221 | wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, checklist->GetId() ); | |
222 | event.SetInt( owner->GetLineFromItem( this ) ); | |
223 | event.SetEventObject( checklist ); | |
aaa6d89a | 224 | checklist->GetEventHandler()->ProcessEvent( event ); |
6cce68ea SC |
225 | } |
226 | break; | |
227 | ||
228 | default: | |
229 | break; | |
230 | } | |
231 | } | |
232 | ||
233 | if ( err == errDataBrowserPropertyNotSupported ) | |
234 | err = wxMacListBoxItem::GetSetData( owner , property, itemData , changeValue); | |
235 | ||
236 | return err; | |
237 | } | |
dbfc5b97 | 238 | |
aaa6d89a | 239 | void Check( bool check ) |
dbfc5b97 | 240 | { |
6cce68ea | 241 | m_isChecked = check; |
dbfc5b97 | 242 | } |
aaa6d89a | 243 | bool IsChecked() const |
6cce68ea | 244 | { |
aaa6d89a | 245 | return m_isChecked; |
6cce68ea SC |
246 | } |
247 | ||
248 | protected : | |
249 | bool m_isChecked; | |
250 | }; | |
e9576ca5 | 251 | |
9ce05df4 | 252 | wxMacDataItem* wxMacDataBrowserCheckListControl::CreateItem() |
dbfc5b97 | 253 | { |
6cce68ea SC |
254 | return new wxMacCheckListBoxItem(); |
255 | } | |
dbfc5b97 | 256 | |
aaa6d89a | 257 | void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n, bool bCheck) |
6cce68ea SC |
258 | { |
259 | wxMacCheckListBoxItem* item = dynamic_cast<wxMacCheckListBoxItem*>( GetItemFromLine( n) ); | |
260 | item->Check( bCheck); | |
261 | UpdateItem(wxMacDataBrowserRootContainer, item , kCheckboxColumnId); | |
dbfc5b97 | 262 | } |
e9576ca5 | 263 | |
aaa6d89a | 264 | bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n) const |
e9576ca5 | 265 | { |
6cce68ea | 266 | wxMacCheckListBoxItem * item = dynamic_cast<wxMacCheckListBoxItem*>( GetItemFromLine( n ) ); |
aaa6d89a | 267 | return item->IsChecked(); |
e9576ca5 SC |
268 | } |
269 | ||
6cce68ea SC |
270 | |
271 | ||
dbfc5b97 | 272 | #endif // wxUSE_CHECKLISTBOX |