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