]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/datavcmn.cpp
extract setters from wxHeaderColumnBase into a separate wxSettableHeaderColumn class...
[wxWidgets.git] / src / common / datavcmn.cpp
index 1a7dcf453a885f6f5390b8b958f0e9f1d60a2136..34e2123b6c3ac89411baf6c2c50c3b341d0ddaa2 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "wx/dataview.h"
 #include "wx/spinctrl.h"
+#include "wx/choice.h"
 
 #include "wx/weakref.h"
 
@@ -30,7 +31,7 @@
     #include "wx/crt.h"
 #endif
 
-const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl");
+const char wxDataViewCtrlNameStr[] = "dataviewCtrl";
 
 
 bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
@@ -721,7 +722,7 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la
 void wxDataViewRendererBase::CancelEditing()
 {
     if (!m_editorCtrl) return;
-    
+
     GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
 
     m_editorCtrl->Hide();
@@ -831,64 +832,18 @@ void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
 // wxDataViewColumnBase
 // ---------------------------------------------------------
 
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
-
-wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title),
-                                           wxDataViewRenderer *renderer,
-                                           unsigned int model_column,
-                                           int WXUNUSED(width),
-                                           wxAlignment WXUNUSED(align),
-                                           int WXUNUSED(flags))
+void wxDataViewColumnBase::Init(wxDataViewRenderer *renderer,
+                                unsigned int model_column)
 {
     m_renderer = renderer;
     m_model_column = model_column;
     m_owner = NULL;
     m_renderer->SetOwner( (wxDataViewColumn*) this );
-
-    // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
-    //       parameters inside the native control!
-}
-
-wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap,
-                                           wxDataViewRenderer *renderer,
-                                           unsigned int model_column,
-                                           int WXUNUSED(width),
-                                           wxAlignment WXUNUSED(align),
-                                           int WXUNUSED(flags) )
-{
-    m_renderer = renderer;
-    m_model_column = model_column;
-    m_bitmap = bitmap;
-    m_owner = NULL;
-    m_renderer->SetOwner( (wxDataViewColumn*) this );
 }
 
 wxDataViewColumnBase::~wxDataViewColumnBase()
 {
-    if (m_renderer)
-        delete m_renderer;
-}
-
-int wxDataViewColumnBase::GetFlags() const
-{
-    int ret = 0;
-
-    if (IsSortable())
-        ret |= wxDATAVIEW_COL_SORTABLE;
-    if (IsResizeable())
-        ret |= wxDATAVIEW_COL_RESIZABLE;
-    if (IsHidden())
-        ret |= wxDATAVIEW_COL_HIDDEN;
-
-    return ret;
-}
-
-void wxDataViewColumnBase::SetFlags(int flags)
-{
-    SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0);
-    SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
-    SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0);
-    SetReorderable((flags & wxDATAVIEW_COL_REORDERABLE) != 0);
+    delete m_renderer;
 }
 
 // ---------------------------------------------------------
@@ -1220,7 +1175,7 @@ wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col )
     return true;
 }
 
-bool 
+bool
 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos), wxDataViewColumn *col )
 {
     col->SetOwner( (wxDataViewCtrl*) this );
@@ -1316,6 +1271,64 @@ bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
     return true;
 }
 
+// -------------------------------------
+// wxDataViewChoiceRenderer
+// -------------------------------------
+
+#ifndef __WXGTK20__
+
+wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString& choices, wxDataViewCellMode mode, int alignment ) :
+   wxDataViewCustomRenderer(wxT("string"), mode, alignment )
+{
+    m_choices = choices;
+}
+
+wxControl* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
+{
+    wxString s = value;
+    wxSize size = labelRect.GetSize();
+#ifdef __WXMAC__
+    size = wxSize( wxMax(70,labelRect.width ), -1 );
+#endif
+    wxChoice *c = new wxChoice( parent, wxID_ANY, labelRect.GetTopLeft(), size, m_choices );
+    c->SetStringSelection( value.GetString() );
+
+    return c;
+}
+
+bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
+{
+    wxChoice *c = (wxChoice*) editor;
+    wxString s = c->GetStringSelection();
+    value = s;
+    return true;
+}
+
+bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state )
+{
+    RenderText( m_data, 0, rect, dc, state );
+    return true;
+}
+
+wxSize wxDataViewChoiceRenderer::GetSize() const
+{
+    return wxSize(80,16);
+}
+
+bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )
+{
+    m_data = value.GetString();
+    return true;
+}
+
+bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
+{
+    value = m_data;
+    return true;
+}
+
+#endif
+
 //-----------------------------------------------------------------------------
 // wxDataViewTreeStore
 //-----------------------------------------------------------------------------
@@ -1874,10 +1887,12 @@ void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event )
 void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event )
 {
 #if defined(wxUSE_GENERICDATAVIEWCTRL)
-    wxSize size = GetClientSize();
-    wxDataViewColumn *col = GetColumn( 0 );
-    if (col)
-       col->SetWidth( size.x );
+    // automatically resize our only column to take the entire control width
+    if ( GetColumnCount() )
+    {
+        wxSize size = GetClientSize();
+        GetColumn(0)->SetWidth(size.x);
+    }
 #endif
     event.Skip( true );
 }