]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/checklst.cpp
Include wx/msgdlg.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 #include "wx/arrstr.h"
21
22 #include "wx/mac/uma.h"
23
24 #ifndef __DARWIN__
25 #include <Appearance.h>
26 #endif
27
28 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
29
30 BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
31 END_EVENT_TABLE()
32
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
45 void wxCheckListBox::Init()
46 {
47 }
48
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 )
58 {
59 wxCArrayString chs( choices );
60
61 return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
62 }
63
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 )
74 {
75 m_macIsUserPane = false;
76
77 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
78 wxT("only one of listbox selection modes can be specified") );
79
80 if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
81 return false;
82
83 // this will be increased by our Append command
84 wxMacDataBrowserCheckListControl* control = new wxMacDataBrowserCheckListControl( this, pos, size, style );
85 control->SetClientDataType( m_clientDataItemsType );
86 m_peer = control;
87
88 MacPostControlCreate(pos,size);
89
90 InsertItems( n , choices , 0 );
91
92 // Needed because it is a wxControlWithItems
93 SetBestSize( size );
94
95 return true;
96 }
97
98 // ----------------------------------------------------------------------------
99 // wxCheckListBox functions
100 // ----------------------------------------------------------------------------
101
102 bool wxCheckListBox::IsChecked(unsigned int item) const
103 {
104 wxCHECK_MSG( IsValid(item), false,
105 wxT("invalid index in wxCheckListBox::IsChecked") );
106
107 return GetPeer()->MacIsChecked( item );
108 }
109
110 void wxCheckListBox::Check(unsigned int item, bool check)
111 {
112 wxCHECK_RET( IsValid(item),
113 wxT("invalid index in wxCheckListBox::Check") );
114
115 bool isChecked = GetPeer()->MacIsChecked( item );
116 if ( check != isChecked )
117 {
118 GetPeer()->MacCheck( item , check );
119 }
120 }
121
122 wxMacCheckListControl* wxCheckListBox::GetPeer() const
123 {
124 return dynamic_cast<wxMacCheckListControl*>(m_peer);
125 }
126
127 const short kCheckboxColumnId = 1026;
128
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 );
159 }
160
161 wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl()
162 {
163
164 }
165
166 class wxMacCheckListBoxItem : public wxMacListBoxItem
167 {
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 }
235
236 void Check( bool check )
237 {
238 m_isChecked = check;
239 }
240 bool IsChecked() const
241 {
242 return m_isChecked;
243 }
244
245 protected :
246 bool m_isChecked;
247 };
248
249 wxMacListBoxItem* wxMacDataBrowserCheckListControl::CreateItem()
250 {
251 return new wxMacCheckListBoxItem();
252 }
253
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);
259 }
260
261 bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n) const
262 {
263 wxMacCheckListBoxItem * item = dynamic_cast<wxMacCheckListBoxItem*>( GetItemFromLine( n ) );
264 return item->IsChecked();
265 }
266
267
268
269 #endif // wxUSE_CHECKLISTBOX