]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/checklst.cpp
always return wxString from wxGetUserHome() instead of char */wxWCharBuffer depending...
[wxWidgets.git] / src / mac / carbon / checklst.cpp
CommitLineData
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
31IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
32
d058c153
SC
33BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
34END_EVENT_TABLE()
dbfc5b97 35
6cce68ea
SC
36class wxMacDataBrowserCheckListControl : public wxMacDataBrowserListControl , public wxMacCheckListControl
37{
38public:
39 wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style );
bf9a1615 40 wxMacDataBrowserCheckListControl() {}
d3c7fc99 41 virtual ~wxMacDataBrowserCheckListControl();
6cce68ea 42
9ce05df4 43 virtual wxMacDataItem* CreateItem();
aaa6d89a 44
6cce68ea
SC
45 virtual bool MacIsChecked(unsigned int n) const;
46 virtual void MacCheck(unsigned int n, bool bCheck = true);
bf9a1615 47 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserCheckListControl)
6cce68ea
SC
48};
49
bf9a1615
SC
50IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserCheckListControl , wxMacDataBrowserListControl )
51
dbfc5b97
SC
52void wxCheckListBox::Init()
53{
54}
55
c18353e5
DS
56bool 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 )
584ad2a3 65{
c18353e5 66 wxCArrayString chs( choices );
584ad2a3 67
c18353e5 68 return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
584ad2a3
MB
69}
70
c18353e5
DS
71bool 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 )
dbfc5b97 81{
c18353e5 82 m_macIsUserPane = false;
d058c153
SC
83
84 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
c18353e5 85 wxT("only one of listbox selection modes can be specified") );
3dee36ae 86
c18353e5 87 if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
b45ed7a2
VZ
88 return false;
89
c18353e5 90 // this will be increased by our Append command
6cce68ea 91 wxMacDataBrowserCheckListControl* control = new wxMacDataBrowserCheckListControl( this, pos, size, style );
6cce68ea 92 m_peer = control;
dbfc5b97 93
b4726a58 94 MacPostControlCreate(pos,size);
3dee36ae 95
aaa6d89a 96 InsertItems( n , choices , 0 );
dbfc5b97 97
c18353e5 98 // Needed because it is a wxControlWithItems
170acdc9 99 SetInitialSize( size );
3dee36ae
WS
100
101 return true;
dbfc5b97 102}
e9576ca5
SC
103
104// ----------------------------------------------------------------------------
dbfc5b97 105// wxCheckListBox functions
e9576ca5
SC
106// ----------------------------------------------------------------------------
107
aa61d352 108bool wxCheckListBox::IsChecked(unsigned int item) const
dbfc5b97 109{
aa61d352 110 wxCHECK_MSG( IsValid(item), false,
c18353e5 111 wxT("invalid index in wxCheckListBox::IsChecked") );
dbfc5b97 112
6cce68ea 113 return GetPeer()->MacIsChecked( item );
dbfc5b97
SC
114}
115
aa61d352 116void wxCheckListBox::Check(unsigned int item, bool check)
dbfc5b97 117{
aa61d352 118 wxCHECK_RET( IsValid(item),
c18353e5 119 wxT("invalid index in wxCheckListBox::Check") );
dbfc5b97 120
6cce68ea 121 bool isChecked = GetPeer()->MacIsChecked( item );
dbfc5b97
SC
122 if ( check != isChecked )
123 {
6cce68ea 124 GetPeer()->MacCheck( item , check );
dbfc5b97
SC
125 }
126}
127
aaa6d89a
WS
128wxMacCheckListControl* wxCheckListBox::GetPeer() const
129{
bf9a1615
SC
130 wxMacDataBrowserCheckListControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserCheckListControl);
131 return lb ? wx_static_cast(wxMacCheckListControl*,lb) : 0 ;
6cce68ea 132}
dbfc5b97 133
6cce68ea 134const short kCheckboxColumnId = 1026;
e9576ca5 135
6cce68ea
SC
136wxMacDataBrowserCheckListControl::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;
aaa6d89a 163
6cce68ea
SC
164 err = AddColumn( &columnDesc, 0 );
165 verify_noerr( err );
dbfc5b97
SC
166}
167
6cce68ea 168wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl()
e9576ca5 169{
aaa6d89a 170
e9576ca5
SC
171}
172
6cce68ea 173class wxMacCheckListBoxItem : public wxMacListBoxItem
e9576ca5 174{
6cce68ea
SC
175public :
176 wxMacCheckListBoxItem()
177 {
178 m_isChecked = false;
179 }
aaa6d89a 180
d3c7fc99 181 virtual ~wxMacCheckListBoxItem()
6cce68ea
SC
182 {
183 }
aaa6d89a 184
6cce68ea
SC
185 virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner ,
186 DataBrowserPropertyID property,
187 DataBrowserItemDataRef itemData,
aaa6d89a 188 bool changeValue )
6cce68ea
SC
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 );
aaa6d89a 228 checklist->GetEventHandler()->ProcessEvent( event );
6cce68ea
SC
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 }
dbfc5b97 242
aaa6d89a 243 void Check( bool check )
dbfc5b97 244 {
6cce68ea 245 m_isChecked = check;
dbfc5b97 246 }
aaa6d89a 247 bool IsChecked() const
6cce68ea 248 {
aaa6d89a 249 return m_isChecked;
6cce68ea
SC
250 }
251
252protected :
253 bool m_isChecked;
254};
e9576ca5 255
9ce05df4 256wxMacDataItem* wxMacDataBrowserCheckListControl::CreateItem()
dbfc5b97 257{
6cce68ea
SC
258 return new wxMacCheckListBoxItem();
259}
dbfc5b97 260
aaa6d89a 261void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n, bool bCheck)
6cce68ea 262{
bf9a1615 263 wxMacCheckListBoxItem* item = wx_static_cast(wxMacCheckListBoxItem*, GetItemFromLine( n) );
6cce68ea
SC
264 item->Check( bCheck);
265 UpdateItem(wxMacDataBrowserRootContainer, item , kCheckboxColumnId);
dbfc5b97 266}
e9576ca5 267
aaa6d89a 268bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n) const
e9576ca5 269{
bf9a1615 270 wxMacCheckListBoxItem * item = wx_static_cast( wxMacCheckListBoxItem*, GetItemFromLine( n ) );
aaa6d89a 271 return item->IsChecked();
e9576ca5
SC
272}
273
6cce68ea
SC
274
275
dbfc5b97 276#endif // wxUSE_CHECKLISTBOX