]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/checklst.cpp
create stock GDI objects on demand; use const with GDI objects appropriately (patch...
[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"
584ad2a3 20#include "wx/arrstr.h"
b698c8e9 21
dbfc5b97 22#include "wx/mac/uma.h"
c18353e5 23
768c6e8b 24#ifndef __DARWIN__
7f0c3a63 25#include <Appearance.h>
768c6e8b 26#endif
dbfc5b97 27
dbfc5b97
SC
28IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
29
d058c153
SC
30BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
31END_EVENT_TABLE()
dbfc5b97 32
dbfc5b97
SC
33void wxCheckListBox::Init()
34{
35}
36
c18353e5
DS
37bool wxCheckListBox::Create(
38 wxWindow *parent,
39 wxWindowID id,
40 const wxPoint &pos,
41 const wxSize &size,
42 const wxArrayString& choices,
43 long style,
44 const wxValidator& validator,
45 const wxString &name )
584ad2a3 46{
c18353e5 47 wxCArrayString chs( choices );
584ad2a3 48
c18353e5 49 return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
584ad2a3
MB
50}
51
c18353e5
DS
52bool wxCheckListBox::Create(
53 wxWindow *parent,
54 wxWindowID id,
55 const wxPoint& pos,
56 const wxSize& size,
57 int n,
58 const wxString choices[],
59 long style,
60 const wxValidator& validator,
61 const wxString& name )
dbfc5b97 62{
c18353e5 63 m_macIsUserPane = false;
d058c153
SC
64
65 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
c18353e5 66 wxT("only one of listbox selection modes can be specified") );
3dee36ae 67
c18353e5 68 if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
b45ed7a2
VZ
69 return false;
70
c18353e5
DS
71 // this will be increased by our Append command
72 m_noItems = 0;
facd6764 73
b4726a58 74 m_peer = (wxMacControl*) CreateMacListControl(pos , size , style );
dbfc5b97 75
b4726a58 76 MacPostControlCreate(pos,size);
3dee36ae 77
b4726a58 78 InsertItems( n , choices , 0 );
dbfc5b97 79
c18353e5
DS
80 // Needed because it is a wxControlWithItems
81 SetBestSize( size );
3dee36ae
WS
82
83 return true;
dbfc5b97 84}
e9576ca5
SC
85
86// ----------------------------------------------------------------------------
dbfc5b97 87// wxCheckListBox functions
e9576ca5
SC
88// ----------------------------------------------------------------------------
89
aa61d352 90bool wxCheckListBox::IsChecked(unsigned int item) const
dbfc5b97 91{
aa61d352 92 wxCHECK_MSG( IsValid(item), false,
c18353e5 93 wxT("invalid index in wxCheckListBox::IsChecked") );
dbfc5b97
SC
94
95 return m_checks[item] != 0;
96}
97
aa61d352 98void wxCheckListBox::Check(unsigned int item, bool check)
dbfc5b97 99{
aa61d352 100 wxCHECK_RET( IsValid(item),
c18353e5 101 wxT("invalid index in wxCheckListBox::Check") );
dbfc5b97 102
dbfc5b97
SC
103 bool isChecked = m_checks[item] != 0;
104 if ( check != isChecked )
105 {
106 m_checks[item] = check;
b4726a58 107 MacUpdateLine( item );
dbfc5b97
SC
108 }
109}
110
111// ----------------------------------------------------------------------------
d058c153 112// methods forwarded to wxCheckListBox
dbfc5b97
SC
113// ----------------------------------------------------------------------------
114
aa61d352 115void wxCheckListBox::Delete(unsigned int n)
dbfc5b97 116{
aa61d352 117 wxCHECK_RET( IsValid(n), wxT("invalid index in wxCheckListBox::Delete") );
e9576ca5 118
c18353e5
DS
119 wxListBox::Delete( n );
120 m_checks.RemoveAt( n );
dbfc5b97
SC
121}
122
123int wxCheckListBox::DoAppend(const wxString& item)
e9576ca5 124{
c18353e5 125 int pos = wxListBox::DoAppend( item );
dbfc5b97
SC
126
127 // the item is initially unchecked
c18353e5 128 m_checks.Insert( false, pos );
dbfc5b97
SC
129
130 return pos;
e9576ca5
SC
131}
132
aa61d352 133void wxCheckListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
e9576ca5 134{
c18353e5 135 wxListBox::DoInsertItems( items, pos );
dbfc5b97 136
aa61d352
VZ
137 unsigned int count = items.GetCount();
138 for ( unsigned int n = 0; n < count; n++ )
dbfc5b97 139 {
c18353e5 140 m_checks.Insert( false, pos + n );
dbfc5b97 141 }
e9576ca5
SC
142}
143
dbfc5b97
SC
144void wxCheckListBox::DoSetItems(const wxArrayString& items, void **clientData)
145{
146 // call it first as it does DoClear()
c18353e5 147 wxListBox::DoSetItems( items, clientData );
dbfc5b97 148
aa61d352
VZ
149 unsigned int count = items.GetCount();
150 for ( unsigned int n = 0; n < count; n++ )
dbfc5b97 151 {
c18353e5 152 m_checks.Add( false );
dbfc5b97
SC
153 }
154}
e9576ca5 155
dbfc5b97 156void wxCheckListBox::DoClear()
e9576ca5 157{
dbfc5b97 158 m_checks.Empty();
e9576ca5
SC
159}
160
dbfc5b97 161#endif // wxUSE_CHECKLISTBOX