]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/checklst.cpp
Add middle-item click support.
[wxWidgets.git] / src / mac / carbon / checklst.cpp
... / ...
CommitLineData
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
31IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
32
33BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
34END_EVENT_TABLE()
35
36class wxMacDataBrowserCheckListControl : public wxMacDataBrowserListControl , public wxMacCheckListControl
37{
38public:
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
50IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserCheckListControl , wxMacDataBrowserListControl )
51
52void wxCheckListBox::Init()
53{
54}
55
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 )
65{
66 wxCArrayString chs( choices );
67
68 return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
69}
70
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 )
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 control->SetClientDataType( m_clientDataItemsType );
93 m_peer = control;
94
95 MacPostControlCreate(pos,size);
96
97 InsertItems( n , choices , 0 );
98
99 // Needed because it is a wxControlWithItems
100 SetInitialSize( size );
101
102 return true;
103}
104
105// ----------------------------------------------------------------------------
106// wxCheckListBox functions
107// ----------------------------------------------------------------------------
108
109bool wxCheckListBox::IsChecked(unsigned int item) const
110{
111 wxCHECK_MSG( IsValid(item), false,
112 wxT("invalid index in wxCheckListBox::IsChecked") );
113
114 return GetPeer()->MacIsChecked( item );
115}
116
117void wxCheckListBox::Check(unsigned int item, bool check)
118{
119 wxCHECK_RET( IsValid(item),
120 wxT("invalid index in wxCheckListBox::Check") );
121
122 bool isChecked = GetPeer()->MacIsChecked( item );
123 if ( check != isChecked )
124 {
125 GetPeer()->MacCheck( item , check );
126 }
127}
128
129wxMacCheckListControl* wxCheckListBox::GetPeer() const
130{
131 wxMacDataBrowserCheckListControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserCheckListControl);
132 return lb ? wx_static_cast(wxMacCheckListControl*,lb) : 0 ;
133}
134
135const short kCheckboxColumnId = 1026;
136
137wxMacDataBrowserCheckListControl::wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style)
138 : wxMacDataBrowserListControl( peer, pos, size, style )
139{
140 OSStatus err = noErr;
141
142 DataBrowserListViewColumnDesc columnDesc;
143 columnDesc.headerBtnDesc.titleOffset = 0;
144 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
145
146 columnDesc.headerBtnDesc.btnFontStyle.flags =
147 kControlUseFontMask | kControlUseJustMask;
148
149 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent;
150 columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault;
151 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
152 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
153 columnDesc.headerBtnDesc.titleString = NULL;
154
155 columnDesc.headerBtnDesc.minimumWidth = 30;
156 columnDesc.headerBtnDesc.maximumWidth = 30;
157
158 columnDesc.propertyDesc.propertyID = kCheckboxColumnId;
159 columnDesc.propertyDesc.propertyType = kDataBrowserCheckboxType;
160 columnDesc.propertyDesc.propertyFlags =
161 kDataBrowserPropertyIsMutable
162 | kDataBrowserTableViewSelectionColumn
163 | kDataBrowserDefaultPropertyFlags;
164
165 err = AddColumn( &columnDesc, 0 );
166 verify_noerr( err );
167}
168
169wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl()
170{
171
172}
173
174class wxMacCheckListBoxItem : public wxMacListBoxItem
175{
176public :
177 wxMacCheckListBoxItem()
178 {
179 m_isChecked = false;
180 }
181
182 virtual ~wxMacCheckListBoxItem()
183 {
184 }
185
186 virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner ,
187 DataBrowserPropertyID property,
188 DataBrowserItemDataRef itemData,
189 bool changeValue )
190 {
191 OSStatus err = errDataBrowserPropertyNotSupported;
192
193 wxCheckListBox *checklist = wxDynamicCast( owner->GetPeer() , wxCheckListBox );
194 wxCHECK_MSG( checklist != NULL , errDataBrowserPropertyNotSupported , wxT("wxCheckListBox expected"));
195
196 if ( !changeValue )
197 {
198 switch (property)
199 {
200 case kCheckboxColumnId:
201 verify_noerr(SetDataBrowserItemDataButtonValue( itemData, m_isChecked ? kThemeButtonOn : kThemeButtonOff ));
202 err = noErr;
203 break;
204
205 case kDataBrowserItemIsEditableProperty:
206 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
207 err = noErr;
208 break;
209
210 default:
211 break;
212 }
213 }
214 else
215 {
216 switch (property)
217 {
218 case kCheckboxColumnId:
219 {
220 // we have to change this behind the back, since Check() would be triggering another update round
221 bool newVal = !m_isChecked;
222 verify_noerr(SetDataBrowserItemDataButtonValue( itemData, newVal ? kThemeButtonOn : kThemeButtonOff ));
223 m_isChecked = newVal;
224 err = noErr;
225
226 wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, checklist->GetId() );
227 event.SetInt( owner->GetLineFromItem( this ) );
228 event.SetEventObject( checklist );
229 checklist->GetEventHandler()->ProcessEvent( event );
230 }
231 break;
232
233 default:
234 break;
235 }
236 }
237
238 if ( err == errDataBrowserPropertyNotSupported )
239 err = wxMacListBoxItem::GetSetData( owner , property, itemData , changeValue);
240
241 return err;
242 }
243
244 void Check( bool check )
245 {
246 m_isChecked = check;
247 }
248 bool IsChecked() const
249 {
250 return m_isChecked;
251 }
252
253protected :
254 bool m_isChecked;
255};
256
257wxMacDataItem* wxMacDataBrowserCheckListControl::CreateItem()
258{
259 return new wxMacCheckListBoxItem();
260}
261
262void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n, bool bCheck)
263{
264 wxMacCheckListBoxItem* item = wx_static_cast(wxMacCheckListBoxItem*, GetItemFromLine( n) );
265 item->Check( bCheck);
266 UpdateItem(wxMacDataBrowserRootContainer, item , kCheckboxColumnId);
267}
268
269bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n) const
270{
271 wxMacCheckListBoxItem * item = wx_static_cast( wxMacCheckListBoxItem*, GetItemFromLine( n ) );
272 return item->IsChecked();
273}
274
275
276
277#endif // wxUSE_CHECKLISTBOX