]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/checklst_osx.cpp
Renames to avoid object files with duplicate filenames. (Should we just make everythi...
[wxWidgets.git] / src / osx / checklst_osx.cpp
diff --git a/src/osx/checklst_osx.cpp b/src/osx/checklst_osx.cpp
new file mode 100644 (file)
index 0000000..574d9ec
--- /dev/null
@@ -0,0 +1,152 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        src/osx/checklst.cpp
+// Purpose:     implementation of wxCheckListBox class
+// Author:      Stefan Csomor
+// Modified by:
+// Created:     1998-01-01
+// RCS-ID:      $Id$
+// Copyright:   (c) Stefan Csomor
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+//
+// new DataBrowser-based version
+
+
+#include "wx/wxprec.h"
+
+#if wxUSE_CHECKLISTBOX
+
+#include "wx/checklst.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/arrstr.h"
+#endif
+
+#include "wx/osx/private.h"
+
+IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
+
+BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
+END_EVENT_TABLE()
+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 ( !wxCheckListBoxBase::Create( parent, id, pos, size, n, choices, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
+        return false;
+
+    int colwidth = 30;
+    // TODO adapt the width according to the window variant
+    m_checkColumn = GetListPeer()->InsertCheckColumn(0, wxEmptyString, true, wxALIGN_CENTER, colwidth);
+
+    return true;
+}
+
+// ----------------------------------------------------------------------------
+// wxCheckListBox functions
+// ----------------------------------------------------------------------------
+
+// ----------------------------------------------------------------------------
+// wxCheckListBox functions
+// ----------------------------------------------------------------------------
+
+bool wxCheckListBox::IsChecked(unsigned int n) const
+{
+    wxCHECK_MSG( IsValid(n), false,
+                 _T("invalid index in wxCheckListBox::IsChecked") );
+
+    return m_checks[n] != 0;
+}
+
+void wxCheckListBox::Check(unsigned int n, bool check)
+{
+    wxCHECK_RET( IsValid(n),
+                 _T("invalid index in wxCheckListBox::Check") );
+
+    // intermediate var is needed to avoid compiler warning with VC++
+    bool isChecked = m_checks[n] != 0;
+    if ( check != isChecked )
+    {
+        m_checks[n] = check;
+
+        GetListPeer()->UpdateLine(n);
+    }
+}
+
+void wxCheckListBox::GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value )
+{
+    if ( col == m_checkColumn )
+        value.Set( IsChecked( n ) );
+    else
+        wxListBox::GetValueCallback( n, col, value );
+}
+
+void wxCheckListBox::SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value )
+{
+    if ( col == m_checkColumn )
+    {
+        Check( n, value.GetIntValue() );
+        
+        wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, GetId() );
+        event.SetInt( n );
+        event.SetEventObject( this );
+        HandleWindowEvent( event );
+    }
+}
+
+
+
+// ----------------------------------------------------------------------------
+// methods forwarded to wxListBox
+// ----------------------------------------------------------------------------
+
+void wxCheckListBox::OnItemInserted(unsigned int pos)
+{
+    m_checks.Insert(false, pos );
+}
+
+void wxCheckListBox::DoDeleteOneItem(unsigned int n)
+{
+    wxListBox::DoDeleteOneItem(n);
+
+    m_checks.RemoveAt(n);
+}
+
+void wxCheckListBox::DoClear()
+{
+    m_checks.Empty();
+}
+
+#endif // wxUSE_CHECKLISTBOX