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