]> git.saurik.com Git - wxWidgets.git/commitdiff
Support renderer::LeftClick() in generic code, removed unsupported RightClick(),...
authorRobert Roebling <robert@roebling.de>
Sat, 5 Apr 2008 12:09:15 +0000 (12:09 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 5 Apr 2008 12:09:15 +0000 (12:09 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53020 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/dataview.h
interface/dataview.h
samples/dataview/dataview.cpp
src/generic/datavgen.cpp
src/gtk/dataview.cpp

index d20ee24a770c1814b1eacfc8b1b1b95c1024381d..4859f9dea3ecc4fe40f12d2ea82d55b8feb94a61 100644 (file)
@@ -150,9 +150,6 @@ public:
     virtual bool LeftClick( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), 
                            wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )   
                            { return false; }
-    virtual bool RightClick( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
-                           wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )   
-                           { return false; }
     virtual bool StartDrag( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), 
                            wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )   
                            { return false; }
index e32f513867a027cfb310ca5a9528a6c72b632ca9..339b1bfaa9464da4ea9224e642455548402216cc 100644 (file)
@@ -580,7 +580,8 @@ public:
     ~wxDataViewCustomRenderer();
 
     /**
-        Override this to react to double clicks or ENTER.
+        Override this to react to double clicks or ENTER. This method will
+        only be called in wxDATAVIEW_CELL_ACTIVATABLE mode.
     */
     virtual bool Activate( wxRect cell,
                            wxDataViewModel* model,
@@ -621,7 +622,8 @@ public:
     virtual bool HasEditorCtrl();
 
     /**
-        Overrride this to react to a left click.
+        Overrride this to react to a left click. This method will
+        only be called in wxDATAVIEW_CELL_ACTIVATABLE mode.
     */
     virtual bool LeftClick( wxPoint cursor,
                             wxRect cell,
@@ -646,16 +648,8 @@ public:
                     wxDC* dc, int state);
 
     /**
-        Overrride this to react to a right click.
-    */
-    virtual bool RightClick(wxPoint cursor,
-                            wxRect cell,
-                            wxDataViewModel* model,
-                            const wxDataViewItem & item,
-                            unsigned int col);
-
-    /**
-        Overrride this to start a drag operation.
+        Overrride this to start a drag operation. Not yet
+        supported
     */
     virtual bool StartDrag(wxPoint cursor, wxRect cell,
                            wxDataViewModel* model,
index 5f9c879d28a6065ca85be572769b1e27a60e4513..d287fef76436e7f61f1a761fdd07c68b56a1d5ed 100644 (file)
@@ -562,6 +562,50 @@ public:
     int              m_virtualItems;
 };
 
+// -------------------------------------
+// MyCustomRenderer
+// -------------------------------------
+
+class MyCustomRenderer: public wxDataViewCustomRenderer
+{
+public:
+    MyCustomRenderer( wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
+//    MyCustomRenderer( wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
+                      int alignment = wxDVR_DEFAULT_ALIGNMENT ) :
+       wxDataViewCustomRenderer( wxString("long"), mode, alignment ) { }
+       
+    virtual bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) )
+    {
+        dc->SetBrush( *wxRED_BRUSH );
+        dc->SetPen( *wxTRANSPARENT_PEN );
+        dc->DrawRectangle( rect );
+        return true;
+    }
+
+
+    virtual bool Activate( wxRect WXUNUSED(cell),
+                           wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )   
+    { 
+        wxLogMessage( wxT("MyCustomRenderer Activate()") );
+        return false;
+    }
+
+    virtual bool LeftClick( wxPoint cursor, wxRect WXUNUSED(cell), 
+                           wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )   
+    { 
+        wxLogMessage( wxT("MyCustomRenderer LeftClick( %d, %d )"), cursor.x, cursor.y );
+        return false;
+    }
+    
+    virtual wxSize GetSize() const
+    { 
+        return wxSize(40,20); 
+    }
+    
+    virtual bool SetValue( const wxVariant &WXUNUSED(value) ) { return true; }
+    virtual bool GetValue( wxVariant &WXUNUSED(value) ) const { return true; }
+};
+
 // -------------------------------------
 // MyApp
 // -------------------------------------
@@ -645,7 +689,7 @@ bool MyApp::OnInit(void)
 
     // build the first frame
     MyFrame *frame = 
-        new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 40, 40, 800, 540);
+        new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 40, 40, 1000, 540);
     frame->Show(true);
 
     SetTopWindow(frame);
@@ -748,19 +792,26 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
 #if 0 
     // Call this and sorting is enabled
     // immediatly upon start up.                                    
-    wxDataViewColumn *col = m_musicCtrl->AppendTextColumn( wxT("Title"), 0, wxDATAVIEW_CELL_INERT, 200, 
-                                     DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE);
+    wxDataViewColumn *col = m_musicCtrl->AppendTextColumn( wxT("Title"), 0, wxDATAVIEW_CELL_INERT, 200, DEFAULT_ALIGN, 
+               wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE);
     col->SetSortOrder( true );
 #else
-    m_musicCtrl->AppendTextColumn(wxT("Title"),0,wxDATAVIEW_CELL_INERT,200,DEFAULT_ALIGN,wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE);
+    m_musicCtrl->AppendTextColumn( wxT("Title"), 0, wxDATAVIEW_CELL_INERT, 200, DEFAULT_ALIGN,
+               wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE);
 #endif
     
-    m_musicCtrl->AppendTextColumn( wxT("Artist"), 1, wxDATAVIEW_CELL_EDITABLE, 150,
-                                     DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE);
+    m_musicCtrl->AppendTextColumn( wxT("Artist"), 1, wxDATAVIEW_CELL_EDITABLE, 150, DEFAULT_ALIGN, 
+               wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE  | wxDATAVIEW_COL_RESIZABLE);
 
     wxDataViewSpinRenderer *sr = new wxDataViewSpinRenderer( 0, 2010 );
-    wxDataViewColumn *column = new wxDataViewColumn( wxT("year"), sr, 2, -1, wxALIGN_CENTRE, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE);
-    m_musicCtrl->AppendColumn( column );
+    wxDataViewColumn *column1 = new wxDataViewColumn( wxT("year"), sr, 2, -1, wxALIGN_CENTRE, 
+        wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
+    m_musicCtrl->AppendColumn( column1 );
+
+    MyCustomRenderer *cr = new MyCustomRenderer;
+    wxDataViewColumn *column2 = new wxDataViewColumn( wxT("custom"), cr, 2, -1, wxALIGN_CENTRE, 
+        wxDATAVIEW_COL_RESIZABLE );
+    m_musicCtrl->AppendColumn( column2 );
 
     data_sizer->Add( m_musicCtrl, 3, wxGROW );
     
@@ -778,8 +829,8 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
     m_listCtrl->AppendIconTextColumn(wxT("icon"),            1, wxDATAVIEW_CELL_INERT,     60 );
     
     wxDataViewTextRendererAttr *ra = new wxDataViewTextRendererAttr;
-    column = new wxDataViewColumn(wxT("attributes"), ra, 2 );
-    m_listCtrl->AppendColumn( column );
+    wxDataViewColumn *column3 = new wxDataViewColumn(wxT("attributes"), ra, 2 );
+    m_listCtrl->AppendColumn( column3 );
     
     data_sizer->Add( m_listCtrl, 2, wxGROW );
  
@@ -823,7 +874,8 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
     treectrl->AssociateModel( store );
     store->DecRef();
 
-    treectrl->AppendIconTextColumn(wxT("no label"), 0, wxDATAVIEW_CELL_INERT, -1 );
+    treectrl->AppendIconTextColumn( wxT("no label"), 0, wxDATAVIEW_CELL_INERT, -1, (wxAlignment) 0, 
+        wxDATAVIEW_COL_RESIZABLE );
 
     bottom_sizer->Add( treectrl, 1 );
 
@@ -983,6 +1035,7 @@ void MyFrame::OnContextMenu( wxDataViewEvent &event )
     
     wxString title = m_music_model->GetTitle( event.GetItem() );
     wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s"),title.GetData());
+//    wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s Value: %s"),title.GetData(), event.GetValue().GetString());
 }
 
 void MyFrame::OnHeaderClick( wxDataViewEvent &event )
index d23b3c54ee00f3f62b7096304cf751f6c829087d..4c04bb7fb1aae2e3c53e701de7fae7d1097a050f 100644 (file)
@@ -3671,7 +3671,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         if (m_lastOnSame && !expander && !ignore_other_columns)
         {
             if ((col == m_currentCol) && (current == m_currentRow) &&
-                (cell->GetMode() == wxDATAVIEW_CELL_EDITABLE) )
+                (cell->GetMode() & wxDATAVIEW_CELL_EDITABLE) )
             {
                 m_renameTimer->Start( 100, true );
             }
@@ -3704,28 +3704,18 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
             SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
         }
 
-        // notify cell about right click
         wxVariant value;
         model->GetValue( value, item, col->GetModelColumn() );
-        cell->SetValue( value );
-        wxRect cell_rect( xpos, current * m_lineHeight,
-                          col->GetWidth(), m_lineHeight );
-        if (!cell->RightClick( event.GetPosition(), cell_rect, model, item, col->GetModelColumn()))
-        {
-            wxWindow *parent = GetParent();
-            wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId());
-            le.SetItem( item );
-            le.SetEventObject(parent);
-            le.SetModel(GetOwner()->GetModel());
-            le.SetValue(value);
-
-            parent->GetEventHandler()->ProcessEvent(le);
-        }
+        wxWindow *parent = GetParent();
+        wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId());
+        le.SetItem( item );
+        le.SetEventObject(parent);
+        le.SetModel(GetOwner()->GetModel());
+        le.SetValue(value);
+        parent->GetEventHandler()->ProcessEvent(le);
     }
     else if (event.MiddleDown())
     {
-        // notify cell about middle click
-        // cell->...
     }
     if (event.LeftDown() || forceClick)
     {
@@ -3783,7 +3773,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
                 wxFAIL_MSG( _T("how did we get here?") );
             }
         }
-
+        
         if (m_currentRow != oldCurrentRow)
             RefreshRow( oldCurrentRow );
 
@@ -3794,6 +3784,18 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
 
         m_lastOnSame = !forceClick && ((col == oldCurrentCol) &&
                         (current == oldCurrentRow)) && oldWasSelected;
+
+        // Call LeftClick after everything else as under GTK+
+        if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE)
+        {
+            // notify cell about right click
+            wxVariant value;
+            model->GetValue( value, item, col->GetModelColumn() );
+            cell->SetValue( value );
+            wxRect cell_rect( xpos, current * m_lineHeight,
+                          col->GetWidth(), m_lineHeight );
+            /* ignore ret */ cell->LeftClick( event.GetPosition(), cell_rect, model, item, col->GetModelColumn());
+        }
     }
 }
 
index 2d31f41a6a356c896d685b3bea7125f1a66798bc..673814770e0de1bfcce5b04adb0a95f02e0acc9b 100644 (file)
@@ -1172,12 +1172,6 @@ gtk_wx_cell_renderer_activate(
                 if (cell->Activate( renderrect, model, item, model_col ))
                     ret = true;
         }
-        if (button_event->button == 3)
-        {
-            if (cell->RightClick( pt, renderrect, model, item, model_col ))
-                ret = true;
-        }
-
         wxrenderer->last_click = button_event->time;
 
         return ret;