]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/datavcmn.cpp
make code dealing with wxUSE_IDLEMENUUPDATES a bit more clear and avoid warning due...
[wxWidgets.git] / src / common / datavcmn.cpp
index 5edb1147bd3d748e180d94ca9321d9ca4669632b..c0850cbf163c28450a63bf34dfe1197640556394 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "wx/dataview.h"
 #include "wx/spinctrl.h"
 
 #include "wx/dataview.h"
 #include "wx/spinctrl.h"
+#include "wx/choice.h"
 
 #include "wx/weakref.h"
 
 
 #include "wx/weakref.h"
 
@@ -30,7 +31,7 @@
     #include "wx/crt.h"
 #endif
 
     #include "wx/crt.h"
 #endif
 
-const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl");
+const char wxDataViewCtrlNameStr[] = "dataviewCtrl";
 
 
 bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
 
 
 bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
@@ -41,7 +42,7 @@ bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
 #ifdef __WXDEBUG__
 void wxDataViewItem::Print(const wxString& text) const
 {
 #ifdef __WXDEBUG__
 void wxDataViewItem::Print(const wxString& text) const
 {
-    wxPrintf(wxT("item %s: %l\n"), text.GetData(), (long)m_id);
+    wxPrintf(wxT("item %s: %lu\n"), text.GetData(), wxPtrToUInt(m_id));
 }
 #endif
 
 }
 #endif
 
@@ -671,7 +672,7 @@ wxDataViewRendererBase::~wxDataViewRendererBase()
 
 const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
 {
 
 const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
 {
-    return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner();
+    return const_cast<wxDataViewRendererBase*>(this)->GetOwner()->GetOwner();
 }
 
 class wxKillRef: public wxWindowRef
 }
 
 class wxKillRef: public wxWindowRef
@@ -720,6 +721,8 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la
 
 void wxDataViewRendererBase::CancelEditing()
 {
 
 void wxDataViewRendererBase::CancelEditing()
 {
+    if (!m_editorCtrl) return;
+
     GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
 
     m_editorCtrl->Hide();
     GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
 
     m_editorCtrl->Hide();
@@ -728,6 +731,8 @@ void wxDataViewRendererBase::CancelEditing()
 
 bool wxDataViewRendererBase::FinishEditing()
 {
 
 bool wxDataViewRendererBase::FinishEditing()
 {
+    if (!m_editorCtrl) return true;
+
     wxVariant value;
     GetValueFromEditorCtrl( m_editorCtrl, value );
 
     wxVariant value;
     GetValueFromEditorCtrl( m_editorCtrl, value );
 
@@ -761,6 +766,7 @@ BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
     EVT_CHAR           (wxDataViewEditorCtrlEvtHandler::OnChar)
     EVT_KILL_FOCUS     (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
     EVT_IDLE           (wxDataViewEditorCtrlEvtHandler::OnIdle)
     EVT_CHAR           (wxDataViewEditorCtrlEvtHandler::OnChar)
     EVT_KILL_FOCUS     (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
     EVT_IDLE           (wxDataViewEditorCtrlEvtHandler::OnIdle)
+    EVT_TEXT_ENTER     (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter)
 END_EVENT_TABLE()
 
 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
 END_EVENT_TABLE()
 
 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
@@ -785,6 +791,12 @@ void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
     event.Skip();
 }
 
     event.Skip();
 }
 
+void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent &WXUNUSED(event) )
+{
+    m_finished = true;
+    m_owner->FinishEditing();
+}
+
 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
 {
     switch ( event.m_keyCode )
 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
 {
     switch ( event.m_keyCode )
@@ -795,10 +807,11 @@ void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
             break;
 
         case WXK_ESCAPE:
             break;
 
         case WXK_ESCAPE:
+        {
             m_finished = true;
             m_owner->CancelEditing();
             break;
             m_finished = true;
             m_owner->CancelEditing();
             break;
-
+        }
         default:
             event.Skip();
     }
         default:
             event.Skip();
     }
@@ -1208,7 +1221,7 @@ wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col )
     return true;
 }
 
     return true;
 }
 
-bool 
+bool
 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos), wxDataViewColumn *col )
 {
     col->SetOwner( (wxDataViewCtrl*) this );
 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos), wxDataViewColumn *col )
 {
     col->SetOwner( (wxDataViewCtrl*) this );
@@ -1261,7 +1274,7 @@ wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect la
     wxString str;
     str.Printf( wxT("%d"), (int) l );
     wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str,
     wxString str;
     str.Printf( wxT("%d"), (int) l );
     wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str,
-               labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS, m_min, m_max, l );
+               labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS|wxTE_PROCESS_ENTER, m_min, m_max, l );
 #ifdef __WXMAC__
     size = sc->GetSize();
     wxPoint pt = sc->GetPosition();
 #ifdef __WXMAC__
     size = sc->GetSize();
     wxPoint pt = sc->GetPosition();
@@ -1304,6 +1317,64 @@ bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
     return true;
 }
 
     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
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // wxDataViewTreeStore
 //-----------------------------------------------------------------------------