X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ad81651f00edc6f489d9b6a0839d316a964fd521..0e05227246cc99b2f8133ae639f38c508351afa0:/src/mac/carbon/checklst.cpp diff --git a/src/mac/carbon/checklst.cpp b/src/mac/carbon/checklst.cpp index 7387e3e471..14f7a76bd7 100644 --- a/src/mac/carbon/checklst.cpp +++ b/src/mac/carbon/checklst.cpp @@ -1,72 +1,161 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: checklst.cpp +// Name: src/mac/carbon/checklst.cpp // Purpose: implementation of wxCheckListBox class -// Author: AUTHOR -// Modified by: -// Created: ??/??/98 +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 // RCS-ID: $Id$ -// Copyright: (c) AUTHOR +// Copyright: (c) Stefan Csomor // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// +// +// new DataBrowser-based version -// ============================================================================ -// headers & declarations -// ============================================================================ -#ifdef __GNUG__ -#pragma implementation "checklst.h" -#endif +#include "wx/wxprec.h" + +#if wxUSE_CHECKLISTBOX #include "wx/checklst.h" +#include "wx/arrstr.h" -// ============================================================================ -// implementation -// ============================================================================ +#include "wx/mac/uma.h" - IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) +#ifndef __DARWIN__ +#include +#endif -// ---------------------------------------------------------------------------- -// implementation of wxCheckListBox class -// ---------------------------------------------------------------------------- +IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) -// define event table -// ------------------ BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox) END_EVENT_TABLE() -// control creation -// ---------------- +void wxCheckListBox::Init() +{ +} + +bool wxCheckListBox::Create( + wxWindow *parent, + wxWindowID id, + const wxPoint &pos, + const wxSize &size, + const wxArrayString& choices, + long style, + const wxValidator& validator, + const wxString &name ) +{ + wxCArrayString chs( choices ); + + return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name ); +} + +bool wxCheckListBox::Create( + wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + int n, + const wxString choices[], + long style, + const wxValidator& validator, + const wxString& name ) +{ + m_macIsUserPane = false; + + wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), + wxT("only one of listbox selection modes can be specified") ); + + if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) + return false; + + // this will be increased by our Append command + m_noItems = 0; + + m_peer = (wxMacControl*) CreateMacListControl(pos , size , style ); + + MacPostControlCreate(pos,size); + + InsertItems( n , choices , 0 ); + + // Needed because it is a wxControlWithItems + SetBestSize( size ); + + return true; +} + +// ---------------------------------------------------------------------------- +// wxCheckListBox functions +// ---------------------------------------------------------------------------- -// def ctor: use Create() to really create the control -wxCheckListBox::wxCheckListBox() : wxListBox() +bool wxCheckListBox::IsChecked(unsigned int item) const { + wxCHECK_MSG( IsValid(item), false, + wxT("invalid index in wxCheckListBox::IsChecked") ); + + return m_checks[item] != 0; } -// ctor which creates the associated control -wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id, - const wxPoint& pos, const wxSize& size, - int nStrings, const wxString choices[], - long style, const wxValidator& val, - const wxString& name) - : wxListBox() +void wxCheckListBox::Check(unsigned int item, bool check) { - // TODO: you'll probably need a separate Create instead of using - // the wxListBox one as here. - Create(parent, id, pos, size, nStrings, choices, style|wxLB_OWNERDRAW, val, name); + wxCHECK_RET( IsValid(item), + wxT("invalid index in wxCheckListBox::Check") ); + + bool isChecked = m_checks[item] != 0; + if ( check != isChecked ) + { + m_checks[item] = check; + MacUpdateLine( item ); + } } -// check items -// ----------- +// ---------------------------------------------------------------------------- +// methods forwarded to wxCheckListBox +// ---------------------------------------------------------------------------- -bool wxCheckListBox::IsChecked(size_t uiIndex) const +void wxCheckListBox::Delete(unsigned int n) { - // TODO - return FALSE; + wxCHECK_RET( IsValid(n), wxT("invalid index in wxCheckListBox::Delete") ); + + wxListBox::Delete( n ); + m_checks.RemoveAt( n ); } -void wxCheckListBox::Check(size_t uiIndex, bool bCheck) +int wxCheckListBox::DoAppend(const wxString& item) { - // TODO + int pos = wxListBox::DoAppend( item ); + + // the item is initially unchecked + m_checks.Insert( false, pos ); + + return pos; } +void wxCheckListBox::DoInsertItems(const wxArrayString& items, unsigned int pos) +{ + wxListBox::DoInsertItems( items, pos ); + + unsigned int count = items.GetCount(); + for ( unsigned int n = 0; n < count; n++ ) + { + m_checks.Insert( false, pos + n ); + } +} + +void wxCheckListBox::DoSetItems(const wxArrayString& items, void **clientData) +{ + // call it first as it does DoClear() + wxListBox::DoSetItems( items, clientData ); + + unsigned int count = items.GetCount(); + for ( unsigned int n = 0; n < count; n++ ) + { + m_checks.Add( false ); + } +} + +void wxCheckListBox::DoClear() +{ + m_checks.Empty(); +} +#endif // wxUSE_CHECKLISTBOX