]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxRenderer method for drawing selection
authorRobert Roebling <robert@roebling.de>
Wed, 26 Apr 2006 10:48:52 +0000 (10:48 +0000)
committerRobert Roebling <robert@roebling.de>
Wed, 26 Apr 2006 10:48:52 +0000 (10:48 +0000)
    rect if an item in a list has ben selected.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38921 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/renderer.h
src/generic/datavgen.cpp
src/generic/renderg.cpp
src/gtk/dataview.cpp
src/gtk/renderer.cpp

index 9d21e8db1d5759c2b55d57548be90e7910b4ffa7..95538a40170108d2e6e71f0cf072be41524dba06 100644 (file)
@@ -186,6 +186,18 @@ public:
                                 const wxRect& rect,
                                 int flags = 0) = 0;
 
+    // draw rectangle indicating that an item in e.g. a list control
+    // has been selected or focused
+    //
+    // flags may use 
+    // wxCONTROL_SELECTED (item is selected, e.g. draw background)
+    // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
+    // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
+    virtual void DrawItemSelectionRect(wxWindow *win,
+                                       wxDC& dc,
+                                       const wxRect& rect,
+                                       int flags = 0) = 0;
+
     // geometry functions
     // ------------------
 
@@ -300,6 +312,12 @@ public:
                                 int flags = 0 )
         { m_rendererNative.DrawPushButton( win, dc, rect, flags ); }
 
+    virtual void DrawItemSelectionRect(wxWindow *win,
+                                       wxDC& dc,
+                                       const wxRect& rect,
+                                       int flags = 0 )
+        { m_rendererNative.DrawItemSelectionRect( win, dc, rect, flags ); }
+
     virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
         { return m_rendererNative.GetSplitterParams(win); }
 
index f02cef988e1b7f7c49bb9997819ddc52fccc1ba8..372151b4a40816c4ae92940e32cd7cccaf30326d 100644 (file)
@@ -202,8 +202,6 @@ private:
     wxDataViewTextCtrlWrapper  *m_textctrlWrapper;
     bool                        m_lastOnSame;
 
-    wxBrush                    *m_highlightBrush,
-                               *m_highlightUnfocusedBrush;
     bool                        m_hasFocus;
 
     int                         m_dragCount;
@@ -876,24 +874,6 @@ wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID i
     m_lineBeforeLastClicked = (size_t) -1;
     m_lineSelectSingleOnUp = (size_t) -1;
     
-    m_highlightBrush = new wxBrush
-                           (
-                            wxSystemSettings::GetColour
-                            (
-                                wxSYS_COLOUR_HIGHLIGHT
-                            ),
-                            wxSOLID
-                           );
-
-    m_highlightUnfocusedBrush = new wxBrush
-                                    (
-                                       wxSystemSettings::GetColour
-                                       (
-                                           wxSYS_COLOUR_BTNSHADOW
-                                       ),
-                                       wxSOLID
-                                    );
-    
     m_hasFocus = false;
 
     SetBackgroundColour( *wxWHITE );
@@ -904,8 +884,6 @@ wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID i
 wxDataViewMainWindow::~wxDataViewMainWindow()
 {
     delete m_renameTimer;
-    delete m_highlightBrush;
-    delete m_highlightUnfocusedBrush;
 }
 
 void wxDataViewMainWindow::OnRenameTimer()
@@ -1054,31 +1032,47 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
     size_t item_count = wxMin( (int)(((update.y + update.height) / m_lineHeight) - item_start + 1), 
                                (int)(model->GetNumberOfRows()-item_start) );
 
+    
 
-    if (m_hasFocus)
-        dc.SetBrush( *m_highlightBrush );
-    else
-        dc.SetBrush( *m_highlightUnfocusedBrush );
-    dc.SetPen( *wxTRANSPARENT_PEN );
-            
     size_t item;
     for (item = item_start; item < item_start+item_count; item++)
     {
         if (m_selection.Index( item ) != wxNOT_FOUND)
         {
+            int flags = wxCONTROL_SELECTED;
+            if (item == m_currentRow)
+                flags |= wxCONTROL_CURRENT;
+            if (m_hasFocus)
+                flags |= wxCONTROL_FOCUSED;
             wxRect rect( 0, item*m_lineHeight+1, GetEndOfLastCol(), m_lineHeight-2 );
-            dc.DrawRectangle( rect );
+            wxRendererNative::Get().DrawItemSelectionRect
+                                (
+                                    this,
+                                    dc,
+                                    rect,
+                                    flags
+                                );
+        }
+        else
+        {
+            if (item == m_currentRow)
+            {
+                int flags = wxCONTROL_CURRENT;
+                if (m_hasFocus)
+                    flags |= wxCONTROL_FOCUSED;  // should have no effect
+                wxRect rect( 0, item*m_lineHeight+1, GetEndOfLastCol(), m_lineHeight-2 );
+                wxRendererNative::Get().DrawItemSelectionRect
+                                (
+                                    this,
+                                    dc,
+                                    rect,
+                                    flags
+                                );
+                
+            }
         }
     }
     
-    dc.SetBrush( *wxTRANSPARENT_BRUSH );
-    dc.SetPen( *wxBLACK_PEN );
-    if (HasCurrentRow())
-    {
-        wxRect rect( 0, m_currentRow*m_lineHeight+1, GetEndOfLastCol(), m_lineHeight-2 );
-        dc.DrawRectangle( rect );
-    }
-
     wxRect cell_rect;
     cell_rect.x = 0;
     cell_rect.height = m_lineHeight;
index 41a5bd65ff46901502d2fc2c4b465480699848ea..2c07be9d820ed1c87bf29455df38d3d1d907fd94 100644 (file)
@@ -88,6 +88,11 @@ public:
                                 const wxRect& rect,
                                 int flags = 0);
 
+    virtual void DrawItemSelectionRect(wxWindow *win,
+                                       wxDC& dc,
+                                       const wxRect& rect,
+                                       int flags = 0);
+                                       
     virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
 
     virtual wxRendererVersion GetVersion() const
@@ -428,6 +433,52 @@ wxRendererGeneric::DrawPushButton(wxWindow *win,
     dc.DrawRectangle(rect);
 }
 
+void 
+wxRendererGeneric::DrawItemSelectionRect(wxWindow *win,
+                                       wxDC& dc,
+                                       const wxRect& rect,
+                                       int flags )
+{
+    if (flags & wxCONTROL_SELECTED)
+    {
+        if (flags & wxCONTROL_FOCUSED)
+        {
+            wxBrush brush( 
+                            wxSystemSettings::GetColour
+                            (
+                                wxSYS_COLOUR_HIGHLIGHT
+                            ),
+                            wxSOLID
+                        );
+            dc.SetBrush( brush );
+        }
+        else
+        {
+            wxBrush brush( 
+                            wxSystemSettings::GetColour
+                            (
+                                wxSYS_COLOUR_BTNSHADOW
+                            ),
+                            wxSOLID
+                        );
+            dc.SetBrush( brush );
+        }
+    }
+    else
+    {
+        dc.SetBrush( *wxTRANSPARENT_BRUSH );
+    }
+    
+    
+    if (flags & wxCONTROL_CURRENT)
+        dc.SetPen( *wxBLACK_PEN );
+    else
+        dc.SetPen( *wxTRANSPARENT_PEN );
+        
+    dc.DrawRectangle( rect );    
+}
+
+
 // ----------------------------------------------------------------------------
 // A module to allow cleanup of generic renderer.
 // ----------------------------------------------------------------------------
index 76be4d0a35cba5401d27e1dc721eb38abad029de..a679ac635a49f6025186981ddb571939bc2a82b9 100644 (file)
@@ -1437,6 +1437,12 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
 
     m_treeview = gtk_tree_view_new();
     gtk_container_add (GTK_CONTAINER (m_widget), m_treeview);
+    
+    if (style & wxDV_MULTIPLE)
+    {
+        GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+        gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
+    }
 
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget),
         GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
index e5e20f03b13cbc2a9b5ea83491e83d2826090d2f..facd0d59cb077fa54ab07e3cfb3e23ff1be51eb4 100644 (file)
@@ -88,6 +88,11 @@ public:
                                 const wxRect& rect,
                                 int flags = 0);
 
+    virtual void DrawItemSelectionRect(wxWindow *win,
+                                       wxDC& dc,
+                                       const wxRect& rect,
+                                       int flags = 0);
+                                       
     virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
 
 private:
@@ -505,3 +510,43 @@ wxRendererGTK::DrawPushButton(wxWindow *win,
         rect.x, rect.y, rect.width, rect.height
     );
 }
+
+void 
+wxRendererGTK::DrawItemSelectionRect(wxWindow *win,
+                                       wxDC& dc,
+                                       const wxRect& rect,
+                                       int flags )
+{
+    // for reason why we do this, see DrawDropArrow
+    wxWindowDC& wdc = (wxWindowDC&)dc;
+    wxASSERT ( wdc.IsKindOf(CLASSINFO(wxWindowDC)) );
+
+    GtkStateType state;
+       if (flags & wxCONTROL_SELECTED)
+    {
+        if (flags & wxCONTROL_FOCUSED)
+           state = GTK_STATE_SELECTED;
+        else
+           state = GTK_STATE_INSENSITIVE;
+
+        gtk_paint_flat_box( win->m_wxwindow->style,
+                        GTK_PIZZA(win->m_wxwindow)->bin_window,
+                        state,
+                        GTK_SHADOW_NONE,
+                        NULL, 
+                        win->m_wxwindow,
+                        "treeview",
+                        dc.LogicalToDeviceX(rect.x),
+                        dc.LogicalToDeviceY(rect.y),
+                        rect.width,
+                        rect.height );
+    }
+    
+    if (flags & wxCONTROL_CURRENT)
+    {
+        dc.SetPen( *wxBLACK_PEN );
+        dc.SetBrush( *wxTRANSPARENT_BRUSH );
+        dc.DrawRectangle( rect );
+    }
+}
+