///////////////////////////////////////////////////////////////////////////////
-// 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/defs.h"
+#include "wx/wxprec.h"
#if wxUSE_CHECKLISTBOX
#include "wx/checklst.h"
+#include "wx/arrstr.h"
-// ============================================================================
-// implementation
-// ============================================================================
+#include "wx/mac/uma.h"
-#if !USE_SHARED_LIBRARY
- IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
+#ifndef __DARWIN__
+#include <Appearance.h>
#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()
+{
+}
-// def ctor: use Create() to really create the control
-wxCheckListBox::wxCheckListBox() : wxCheckListBoxBase()
+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 );
}
-// 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)
- : wxCheckListBoxBase()
+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 )
{
- // 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);
+ 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;
}
-// check items
-// -----------
+// ----------------------------------------------------------------------------
+// wxCheckListBox functions
+// ----------------------------------------------------------------------------
-bool wxCheckListBox::IsChecked(size_t uiIndex) const
+bool wxCheckListBox::IsChecked(unsigned int item) const
{
- // TODO
- return FALSE;
+ wxCHECK_MSG( IsValid(item), false,
+ wxT("invalid index in wxCheckListBox::IsChecked") );
+
+ return m_checks[item] != 0;
}
-void wxCheckListBox::Check(size_t uiIndex, bool bCheck)
+void wxCheckListBox::Check(unsigned int item, bool check)
{
- // TODO
+ 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 );
+ }
}
-#endif // wxUSE_CHECKLISTBOX
+// ----------------------------------------------------------------------------
+// methods forwarded to wxCheckListBox
+// ----------------------------------------------------------------------------
+void wxCheckListBox::Delete(unsigned int n)
+{
+ wxCHECK_RET( IsValid(n), wxT("invalid index in wxCheckListBox::Delete") );
+
+ wxListBox::Delete( n );
+ m_checks.RemoveAt( n );
+}
+
+int wxCheckListBox::DoAppend(const wxString& item)
+{
+ 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