]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/checklst.cpp
Include wx/stopwatch.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / mac / carbon / checklst.cpp
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
42 virtual wxMacListBoxItem* CreateItem();
43
44 virtual bool MacIsChecked(unsigned int n) const;
45 virtual void MacCheck(unsigned int n, bool bCheck = true);
46 };
47
48 void wxCheckListBox::Init()
49 {
50 }
51
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 )
61 {
62 wxCArrayString chs( choices );
63
64 return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
65 }
66
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 )
77 {
78 m_macIsUserPane = false;
79
80 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
81 wxT("only one of listbox selection modes can be specified") );
82
83 if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
84 return false;
85
86 // this will be increased by our Append command
87 wxMacDataBrowserCheckListControl* control = new wxMacDataBrowserCheckListControl( this, pos, size, style );
88 control->SetClientDataType( m_clientDataItemsType );
89 m_peer = control;
90
91 MacPostControlCreate(pos,size);
92
93 InsertItems( n , choices , 0 );
94
95 // Needed because it is a wxControlWithItems
96 SetBestSize( size );
97
98 return true;
99 }
100
101 // ----------------------------------------------------------------------------
102 // wxCheckListBox functions
103 // ----------------------------------------------------------------------------
104
105 bool wxCheckListBox::IsChecked(unsigned int item) const
106 {
107 wxCHECK_MSG( IsValid(item), false,
108 wxT("invalid index in wxCheckListBox::IsChecked") );
109
110 return GetPeer()->MacIsChecked( item );
111 }
112
113 void wxCheckListBox::Check(unsigned int item, bool check)
114 {
115 wxCHECK_RET( IsValid(item),
116 wxT("invalid index in wxCheckListBox::Check") );
117
118 bool isChecked = GetPeer()->MacIsChecked( item );
119 if ( check != isChecked )
120 {
121 GetPeer()->MacCheck( item , check );
122 }
123 }
124
125 wxMacCheckListControl* wxCheckListBox::GetPeer() const
126 {
127 return dynamic_cast<wxMacCheckListControl*>(m_peer);
128 }
129
130 const short kCheckboxColumnId = 1026;
131
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;
159
160 err = AddColumn( &columnDesc, 0 );
161 verify_noerr( err );
162 }
163
164 wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl()
165 {
166
167 }
168
169 class wxMacCheckListBoxItem : public wxMacListBoxItem
170 {
171 public :
172 wxMacCheckListBoxItem()
173 {
174 m_isChecked = false;
175 }
176
177 ~wxMacCheckListBoxItem()
178 {
179 }
180
181 virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner ,
182 DataBrowserPropertyID property,
183 DataBrowserItemDataRef itemData,
184 bool changeValue )
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 );
224 checklist->GetEventHandler()->ProcessEvent( event );
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 }
238
239 void Check( bool check )
240 {
241 m_isChecked = check;
242 }
243 bool IsChecked() const
244 {
245 return m_isChecked;
246 }
247
248 protected :
249 bool m_isChecked;
250 };
251
252 wxMacListBoxItem* wxMacDataBrowserCheckListControl::CreateItem()
253 {
254 return new wxMacCheckListBoxItem();
255 }
256
257 void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n, bool bCheck)
258 {
259 wxMacCheckListBoxItem* item = dynamic_cast<wxMacCheckListBoxItem*>( GetItemFromLine( n) );
260 item->Check( bCheck);
261 UpdateItem(wxMacDataBrowserRootContainer, item , kCheckboxColumnId);
262 }
263
264 bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n) const
265 {
266 wxMacCheckListBoxItem * item = dynamic_cast<wxMacCheckListBoxItem*>( GetItemFromLine( n ) );
267 return item->IsChecked();
268 }
269
270
271
272 #endif // wxUSE_CHECKLISTBOX