From 521f1d8371b4f010e8d8c55b55720eb11ff052e6 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Fri, 11 Sep 2009 11:49:03 +0000 Subject: [PATCH] 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. 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 | 3 ++ include/wx/propgrid/propgrid.h | 15 +++++++-- interface/wx/propgrid/propgrid.h | 16 +++++++-- samples/propgrid/propgrid.cpp | 8 ++++- src/propgrid/manager.cpp | 56 ++++++++++++++++++++++++-------- src/propgrid/property.cpp | 8 +++-- src/propgrid/propgrid.cpp | 39 ++++++++++++++++++---- 7 files changed, 119 insertions(+), 26 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 395e1a2105..33d547c1b1 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index da4d269e1d..0bcd775d78 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -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 }; diff --git a/interface/wx/propgrid/propgrid.h b/interface/wx/propgrid/propgrid.h index c65a6d86be..665674620b 100644 --- a/interface/wx/propgrid/propgrid.h +++ b/interface/wx/propgrid/propgrid.h @@ -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 }; diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index d31328837a..74742446d1 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -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); diff --git a/src/propgrid/manager.cpp b/src/propgrid/manager.cpp index 158cc557ab..a0b0cd755e 100644 --- a/src/propgrid/manager.cpp +++ b/src/propgrid/manager.cpp @@ -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__) diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 325ebc094a..a1fc39bb20 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -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; diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 963279ad36..fcad2acd94 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -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; iGetWindowStyle() & 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(); -- 2.45.2