]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/datavcmn.cpp
Brazilian Portuguese translations update from Felipe.
[wxWidgets.git] / src / common / datavcmn.cpp
index b7ee97b28e21a64cc21db08f56081e2f6342c863..ae7dcd404327a6c6b74fbe7081f0b4948eb2c0c5 100644 (file)
@@ -26,6 +26,7 @@
     #include "wx/crt.h"
 #endif
 
+#include "wx/datectrl.h"
 #include "wx/spinctrl.h"
 #include "wx/choice.h"
 #include "wx/imaglist.h"
@@ -450,15 +451,12 @@ void wxDataViewIndexListModel::RowDeleted( unsigned int row )
     m_ordered = false;
 
     wxDataViewItem item( m_hash[row] );
-    /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item );
     m_hash.RemoveAt( row );
+    /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item );
 }
 
 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt &rows )
 {
-    wxArrayInt sorted = rows;
-    sorted.Sort( my_sort );
-
     m_ordered = false;
 
     wxDataViewItemArray array;
@@ -468,10 +466,13 @@ void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt &rows )
             wxDataViewItem item( m_hash[rows[i]] );
             array.Add( item );
     }
-    /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array );
 
+    wxArrayInt sorted = rows;
+    sorted.Sort( my_sort );
     for (i = 0; i < sorted.GetCount(); i++)
            m_hash.RemoveAt( sorted[i] );
+
+    /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array );
 }
 
 void wxDataViewIndexListModel::RowChanged( unsigned int row )
@@ -671,6 +672,8 @@ wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype,
 
 wxDataViewRendererBase::~wxDataViewRendererBase()
 {
+    if ( m_editorCtrl )
+        DestroyEditControl();
 }
 
 wxDataViewCtrl* wxDataViewRendererBase::GetView() const
@@ -759,10 +762,10 @@ bool wxDataViewRendererBase::FinishEditing()
 
     wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
 
-    dv_ctrl->GetMainWindow()->SetFocus();
-
     DestroyEditControl();
 
+    dv_ctrl->GetMainWindow()->SetFocus();
+
     bool isValid = Validate(value);
     unsigned int col = GetOwner()->GetModelColumn();
 
@@ -806,6 +809,31 @@ void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model,
 // wxDataViewCustomRendererBase
 // ----------------------------------------------------------------------------
 
+bool wxDataViewCustomRendererBase::ActivateCell(const wxRect& cell,
+                                                wxDataViewModel *model,
+                                                const wxDataViewItem & item,
+                                                unsigned int col,
+                                                const wxMouseEvent* mouseEvent)
+{
+    // Compatibility code
+    if ( mouseEvent )
+        return LeftClick(mouseEvent->GetPosition(), cell, model, item, col);
+    else
+        return Activate(cell, model, item, col);
+}
+
+void wxDataViewCustomRendererBase::RenderBackground(wxDC* dc, const wxRect& rect)
+{
+    if ( !m_attr.HasBackgroundColour() )
+        return;
+
+    const wxColour& colour = m_attr.GetBackgroundColour();
+    wxDCPenChanger changePen(*dc, colour);
+    wxDCBrushChanger changeBrush(*dc, colour);
+
+    dc->DrawRectangle(rect);
+}
+
 void
 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell, wxDC *dc, int state)
 {
@@ -1609,6 +1637,64 @@ bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant &value ) const
 
 #endif
 
+// ---------------------------------------------------------
+// wxDataViewDateRenderer
+// ---------------------------------------------------------
+
+#if (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
+
+wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString& varianttype,
+                                              wxDataViewCellMode mode, int align)
+    : wxDataViewCustomRenderer(varianttype, mode, align)
+{
+}
+
+wxWindow *
+wxDataViewDateRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value)
+{
+    return new wxDatePickerCtrl
+               (
+                   parent,
+                   wxID_ANY,
+                   value.GetDateTime(),
+                   labelRect.GetTopLeft(),
+                   labelRect.GetSize()
+               );
+}
+
+bool wxDataViewDateRenderer::GetValueFromEditorCtrl(wxWindow *editor, wxVariant& value)
+{
+    wxDatePickerCtrl *ctrl = static_cast<wxDatePickerCtrl*>(editor);
+    value = ctrl->GetValue();
+    return true;
+}
+
+bool wxDataViewDateRenderer::SetValue(const wxVariant& value)
+{
+    m_date = value.GetDateTime();
+    return true;
+}
+
+bool wxDataViewDateRenderer::GetValue(wxVariant& value) const
+{
+    value = m_date;
+    return true;
+}
+
+bool wxDataViewDateRenderer::Render(wxRect cell, wxDC* dc, int state)
+{
+    wxString tmp = m_date.FormatDate();
+    RenderText( tmp, 0, cell, dc, state );
+    return true;
+}
+
+wxSize wxDataViewDateRenderer::GetSize() const
+{
+    return GetTextExtent(m_date.FormatDate());
+}
+
+#endif // (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
+
 //-----------------------------------------------------------------------------
 // wxDataViewListStore
 //-----------------------------------------------------------------------------