wxPropertyGrid: added wxPG_NO_INTERNAL_BORDER, wxPG_EX_NO_TOOLBAR_DIVIDER
authorJulian Smart <julian@anthemion.co.uk>
Fri, 11 Sep 2009 11:49:03 +0000 (11:49 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Fri, 11 Sep 2009 11:49:03 +0000 (11:49 +0000)
and wxPG_EX_TOOLBAR_SEPARATOR styles for finer control over borders.
Borders around property grid are now native for consistency.
Some strange VC6 compiler errors fixed, plus size assertion in
sample.

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

docs/changes.txt
include/wx/propgrid/propgrid.h
interface/wx/propgrid/propgrid.h
samples/propgrid/propgrid.cpp
src/propgrid/manager.cpp
src/propgrid/property.cpp
src/propgrid/propgrid.cpp

index 395e1a2105426e808d7935e15d43ea0424552d87..33d547c1b15921c2d44a49c95fb7a27f88d81b5d 100644 (file)
@@ -403,6 +403,9 @@ All (GUI):
 - Fixed wxOwnerDrawComboCtrl popup size on Mac (scrollbars were always shown).
 - Fixed wxOwnerDrawComboCtrl focus problem on Mac (first-time popup
   dismissed immediately as text control grabbed the focus).
+- wxPropertyGrid: added wxPG_NO_INTERNAL_BORDER, wxPG_EX_NO_TOOLBAR_DIVIDER
+  and wxPG_EX_TOOLBAR_SEPARATOR styles for finer control over borders.
+  Borders around property grid are now native for consistency.
 
 GTK:
 
index da4d269e1d527b6facb4f6d7fb08edfab56fe25a..0bcd775d78b9bacf34f0d690b6deb8280b1d7185 100644 (file)
@@ -181,8 +181,11 @@ wxPG_TOOLBAR                        = 0x00001000,
 /** wxPropertyGridManager only: Show adjustable text box showing description
     or help text, if available, for currently selected property.
 */
-wxPG_DESCRIPTION                    = 0x00002000
+wxPG_DESCRIPTION                    = 0x00002000,
 
+/** wxPropertyGridManager only: don't show an internal border around the property grid
+*/
+wxPG_NO_INTERNAL_BORDER             = 0x00004000
 };
 
 enum wxPG_EX_WINDOW_STYLES
@@ -273,7 +276,15 @@ wxPG_EX_MULTIPLE_SELECTION              = 0x02000000,
              wxPropertyGrid's top-level parent window on its own, then you
              are recommended to enable this style.
 */
-wxPG_EX_ENABLE_TLP_TRACKING             = 0x04000000
+wxPG_EX_ENABLE_TLP_TRACKING             = 0x04000000,
+
+/** Don't show divider above toolbar, on Windows.
+*/
+wxPG_EX_NO_TOOLBAR_DIVIDER              = 0x04000000,
+
+/** Show a separator below the toolbar.
+*/
+wxPG_EX_TOOLBAR_SEPARATOR               = 0x08000000
 
 };
 
index c65a6d86be9be87779e0b9883eadec738402aeaf..665674620b535771bd83cc9d09342da486a9d500 100644 (file)
@@ -89,7 +89,11 @@ wxPG_TOOLBAR                        = 0x00001000,
     wxPropertyGridManager only: Show adjustable text box showing description
     or help text, if available, for currently selected property.
 */
-wxPG_DESCRIPTION                    = 0x00002000
+wxPG_DESCRIPTION                    = 0x00002000,
+
+/** wxPropertyGridManager only: don't show an internal border around the property grid
+*/
+wxPG_NO_INTERNAL_BORDER             = 0x00004000
 
 };
 
@@ -178,7 +182,15 @@ wxPG_EX_MULTIPLE_SELECTION              = 0x02000000,
              wxPropertyGrid's top-level parent window on its own, then you
              are recommended to enable this style.
 */
-wxPG_EX_ENABLE_TLP_TRACKING             = 0x04000000
+wxPG_EX_ENABLE_TLP_TRACKING             = 0x04000000,
+
+/** Don't show divider above toolbar, on Windows.
+*/
+wxPG_EX_NO_TOOLBAR_DIVIDER              = 0x04000000,
+
+/** Show a separator below the toolbar.
+*/
+wxPG_EX_TOOLBAR_SEPARATOR               = 0x08000000
 
 };
 
index d31328837ab0898975118108cb78d2c9d53ff17f..74742446d12690bc8d2d26fbdddfc02d0d0801f0 100644 (file)
@@ -2091,7 +2091,10 @@ void FormMain::CreateGrid( int style, int extraStyle )
                                   // event handling will obviously be broken.
                                   PGID, /*wxID_ANY*/
                                   wxDefaultPosition,
-                                  wxDefaultSize,
+                                  wxSize(100, 100), // FIXME: wxDefaultSize gives assertion in propgrid.
+                                                    // But calling SetInitialSize in manager changes the code
+                                                    // order to the grid gets created immediately, before SetExtraStyle
+                                                    // is called.
                                   style );
 
     m_propGrid = pgman->GetGrid();
@@ -2936,6 +2939,7 @@ void FormMain::OnSelectStyle( wxCommandEvent& WXUNUSED(event) )
         ADD_FLAG(wxPG_LIMITED_EDITING)
         ADD_FLAG(wxPG_TOOLBAR)
         ADD_FLAG(wxPG_DESCRIPTION)
+        ADD_FLAG(wxPG_NO_INTERNAL_BORDER)
         wxMultiChoiceDialog dlg( this, wxT("Select window styles to use"),
                                  wxT("wxPropertyGrid Window Style"), chs );
         dlg.SetSelections(sel);
@@ -2966,6 +2970,8 @@ void FormMain::OnSelectStyle( wxCommandEvent& WXUNUSED(event) )
         ADD_FLAG(wxPG_EX_HIDE_PAGE_BUTTONS)
         ADD_FLAG(wxPG_EX_MULTIPLE_SELECTION)
         ADD_FLAG(wxPG_EX_ENABLE_TLP_TRACKING)
+        ADD_FLAG(wxPG_EX_NO_TOOLBAR_DIVIDER)
+        ADD_FLAG(wxPG_EX_TOOLBAR_SEPARATOR)
         wxMultiChoiceDialog dlg( this, wxT("Select extra window styles to use"),
                                  wxT("wxPropertyGrid Extra Style"), chs );
         dlg.SetSelections(sel);
index 158cc557ab61b6ab5d7e1e0da1d1c74b03d03231..a0b0cd755ee6521c39ec3e931d1c3852c5cc31da 100644 (file)
@@ -289,6 +289,11 @@ bool wxPropertyGridManager::Create( wxWindow *parent,
                                 name );
     Init2(style);
 
+    // FIXME: this changes call ordering so wxPropertyGrid is created
+    // immediately, before SetExtraStyle has a chance to be called. However,
+    // without it, we may get assertions if size is wxDefaultSize.
+    //SetInitialSize(size);
+
     return res;
 }
 
@@ -329,15 +334,9 @@ void wxPropertyGridManager::Init1()
 // -----------------------------------------------------------------------
 
 // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager.
-#ifndef __WXMAC__
-  #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxSIMPLE_BORDER| \
-                                          wxNO_FULL_REPAINT_ON_RESIZE| \
-                                          wxCLIP_CHILDREN)
-#else
-  #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxNO_BORDER| \
+#define wxPG_MAN_PROPGRID_FORCED_FLAGS (  wxBORDER_THEME | \
                                           wxNO_FULL_REPAINT_ON_RESIZE| \
                                           wxCLIP_CHILDREN)
-#endif
 
 // Which flags can be passed to underlying wxPropertyGrid.
 #define wxPG_MAN_PASS_FLAGS_MASK       (0xFFF0|wxTAB_TRAVERSAL)
@@ -380,10 +379,23 @@ void wxPropertyGridManager::Init2( int style )
    SetWindowVariant(wxWINDOW_VARIANT_SMALL);
 #endif
 
+   long propGridFlags = (m_windowStyle&wxPG_MAN_PASS_FLAGS_MASK)
+                        |wxPG_MAN_PROPGRID_FORCED_FLAGS;
+
+   propGridFlags &= ~wxBORDER_MASK;
+
+   if ((style & wxPG_NO_INTERNAL_BORDER) == 0)
+   {
+       propGridFlags |= wxBORDER_THEME;
+   }
+   else
+   {
+       propGridFlags |= wxBORDER_NONE;
+       wxWindow::SetExtraStyle(wxPG_EX_TOOLBAR_SEPARATOR);
+   }
+
     // Create propertygrid.
-    m_pPropGrid->Create(this,baseId,wxPoint(0,0),csz,
-                        (m_windowStyle&wxPG_MAN_PASS_FLAGS_MASK)
-                            |wxPG_MAN_PROPGRID_FORCED_FLAGS);
+    m_pPropGrid->Create(this,baseId,wxPoint(0,0),csz, propGridFlags);
 
     m_pPropGrid->m_eventObject = this;
 
@@ -1089,6 +1101,9 @@ void wxPropertyGridManager::RecalculatePositions( int width, int height )
     {
         m_pToolbar->SetSize(0, 0, width, -1);
         propgridY += m_pToolbar->GetSize().y;
+
+        if (GetExtraStyle() & wxPG_EX_TOOLBAR_SEPARATOR)
+            propgridY += 1;
     }
 #endif
 
@@ -1169,8 +1184,20 @@ void wxPropertyGridManager::OnPaint( wxPaintEvent& WXUNUSED(event) )
     // Update everything inside the box
     wxRect r = GetUpdateRegion().GetBox();
 
+    if (GetExtraStyle() & wxPG_EX_TOOLBAR_SEPARATOR)
+    {
+        if (m_pToolbar && m_pPropGrid)
+        {
+            wxPen marginPen(m_pPropGrid->GetMarginColour());
+            dc.SetPen(marginPen);
+
+            int y = m_pPropGrid->GetPosition().y-1;
+            dc.DrawLine(0, y, GetClientSize().x, y);
+        }
+    }
+
     // Repaint splitter and any other description box decorations
-    if ( (r.y + r.height) >= m_splitterY )
+    if ( (r.y + r.height) >= m_splitterY && m_splitterY != -1)
         RepaintDescBoxDecorations( dc, m_splitterY, m_width, m_height );
 }
 
@@ -1211,10 +1238,13 @@ void wxPropertyGridManager::RecreateControls()
         // Has toolbar.
         if ( !m_pToolbar )
         {
+            long toolBarFlags = ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR)?0:wxTB_FLAT);
+            if (GetExtraStyle() & wxPG_EX_NO_TOOLBAR_DIVIDER)
+                toolBarFlags |= wxTB_NODIVIDER;
+
             m_pToolbar = new wxToolBar(this,baseId+ID_ADVTOOLBAR_OFFSET,
                                        wxDefaultPosition,wxDefaultSize,
-                                       ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR)?0:wxTB_FLAT)
-                                        /*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
+                                       toolBarFlags);
             m_pToolbar->SetToolBitmapSize(wxSize(16, 15));
 
         #if defined(__WXMSW__)
index 325ebc094a7c8d1e9eed66aea7110f64c9acd41b..a1fc39bb206d40391e81eb85606642d99337b66e 100644 (file)
@@ -1430,10 +1430,14 @@ void wxPGProperty::EnsureCells( unsigned int column )
         wxPropertyGrid* pg = GetGrid();
         wxPGCell defaultCell;
 
+        // Work around possible VC6 bug by using intermediate variables
+        const wxPGCell& propDefCell = pg->GetPropertyDefaultCell();
+        const wxPGCell& catDefCell = pg->GetCategoryDefaultCell();
+
         if ( !HasFlag(wxPG_PROP_CATEGORY) )
-            defaultCell = pg->GetPropertyDefaultCell();
+            defaultCell = propDefCell;
         else
-            defaultCell = pg->GetCategoryDefaultCell();
+            defaultCell = catDefCell;
 
         // TODO: Replace with resize() call
         unsigned int cellCountMax = column+1;
index 963279ad367b3ed3e182fc6cfc7d62fcbc357fa0..fcad2acd940222c707b26d7e33b66dd933c2079f 100644 (file)
@@ -394,8 +394,10 @@ bool wxPropertyGrid::Create( wxWindow *parent,
                              const wxString& name )
 {
 
-    if ( !(style&wxBORDER_MASK) )
-        style |= wxSIMPLE_BORDER;
+    if (!(style&wxBORDER_MASK))
+    {
+        style |= wxBORDER_THEME;
+    }
 
     style |= wxVSCROLL;
 
@@ -635,7 +637,9 @@ wxPropertyGrid::~wxPropertyGrid()
     // Delete common value records
     for ( i=0; i<m_commonValues.size(); i++ )
     {
-        delete GetCommonValue(i);
+        // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
+        wxPGCommonValue* value = m_commonValues[i];
+        delete value;
     }
 }
 
@@ -1451,7 +1455,7 @@ bool wxPropertyGrid::SetFont( const wxFont& font )
     DoClearSelection();
 
     bool res = wxScrolledWindow::SetFont( font );
-    if ( res && GetParent()) // may not have been Create()ed yet
+    if ( res && GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
     {
         CalculateFontAndBitmapStuff( m_vspacing );
         Refresh();
@@ -2165,8 +2169,28 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc,
 
         int y2 = y + lh;
 
+#ifdef __WXMSW__
         // Margin Edge
-        dc.DrawLine( greyDepthX, y, greyDepthX, y2 );
+        // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
+        // looks better, at least under Windows when we have a themed border (the themed-window-specific
+        // whitespace between the real border and the propgrid margin exacerbates the double-border look).
+
+        // Is this or its parent themed?
+        bool suppressMarginEdge = (GetWindowStyle() & wxPG_HIDE_MARGIN) &&
+            (((GetWindowStyle() & wxBORDER_MASK) == wxBORDER_THEME) ||
+            (((GetWindowStyle() & wxBORDER_MASK) == wxBORDER_NONE) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK) == wxBORDER_THEME)));
+#else
+        bool suppressMarginEdge = false;
+#endif
+        if (!suppressMarginEdge)
+            dc.DrawLine( greyDepthX, y, greyDepthX, y2 );
+        else
+        {
+            // Blank out the margin edge
+            dc.SetPen(wxPen(GetBackgroundColour()));
+            dc.DrawLine( greyDepthX, y, greyDepthX, y2 );
+            dc.SetPen( linepen );
+        }
 
         // Splitters
         unsigned int si;
@@ -4263,7 +4287,10 @@ void wxPropertyGrid::RecalculateVirtualSize( int forceXPos )
     m_width = width;
     m_height = height;
 
-    m_canvas->SetSize( x, y );
+    // Explicitly pass the position - works around a bug in wxWidgets when the property grid
+    // has a native XP border and a contained window creeps up-and-left when size is set without
+    // the position.
+    m_canvas->SetSize( 0, 0, x, y );
 
     m_pState->CheckColumnWidths();