Refactor internal flags in wxPropertyGrid

Move wxPropertyGrid and wxPropertyGridManager internal flags
from global namespace to the corresponding classes.
This commit is contained in:
Artur Wieczorek 2023-01-22 20:18:39 +02:00
parent d0ed852bae
commit e7b405ec08
5 changed files with 77 additions and 93 deletions

View file

@ -529,57 +529,6 @@ enum wxPG_SET_SPLITTER_POSITION_SPLITTER_FLAGS
// -----------------------------------------------------------------------
// Internal flags
enum wxPG_INTERNAL_FLAGS
{
wxPG_FL_INITIALIZED = 0x0001,
// Set when creating editor controls if it was clicked on.
wxPG_FL_ACTIVATION_BY_CLICK = 0x0002,
wxPG_FL_DONT_CENTER_SPLITTER = 0x0004,
wxPG_FL_FOCUSED = 0x0008,
wxPG_FL_MOUSE_CAPTURED = 0x0010,
wxPG_FL_MOUSE_INSIDE = 0x0020,
wxPG_FL_VALUE_MODIFIED = 0x0040,
// don't clear background of m_wndEditor
wxPG_FL_PRIMARY_FILLS_ENTIRE = 0x0080,
// currently active editor uses custom image
wxPG_FL_CUR_USES_CUSTOM_IMAGE = 0x0100,
// cell colours override selection colours for selected cell
wxPG_FL_CELL_OVERRIDES_SEL = 0x0200,
wxPG_FL_SCROLLED = 0x0400,
// set when all added/inserted properties get hideable flag
wxPG_FL_ADDING_HIDEABLES = 0x0800,
// Disables showing help strings on statusbar.
wxPG_FL_NOSTATUSBARHELP = 0x1000,
// Marks that we created the state, so we have to destroy it too.
wxPG_FL_CREATEDSTATE = 0x2000,
// Set if wxPGMan requires redrawing of description text box.
wxPG_FL_DESC_REFRESH_REQUIRED = 0x8000,
// Set if contained in wxPropertyGridManager
wxPG_FL_IN_MANAGER = 0x00020000,
// Set after wxPropertyGrid is shown in its initial good size
wxPG_FL_GOOD_SIZE_SET = 0x00040000,
// Set when in SelectProperty.
wxPG_FL_IN_SELECT_PROPERTY = 0x00100000,
// Set when help string is shown in status bar
wxPG_FL_STRING_IN_STATUSBAR = 0x00200000,
// Auto sort is enabled (for categorized mode)
wxPG_FL_CATMODE_AUTO_SORT = 0x01000000,
// Set after page has been inserted to manager
wxPG_MAN_FL_PAGE_INSERTED = 0x02000000,
// Active editor control is abnormally large
wxPG_FL_ABNORMAL_EDITOR = 0x04000000,
// Recursion guard for HandleCustomEditorEvent
wxPG_FL_IN_HANDLECUSTOMEDITOREVENT = 0x08000000,
wxPG_FL_VALUE_CHANGE_IN_EVENT = 0x10000000,
// Editor control width should not change on resize
wxPG_FL_FIXED_WIDTH_EDITOR = 0x20000000,
// Width of panel can be different from width of grid
wxPG_FL_HAS_VIRTUAL_WIDTH = 0x40000000,
// Prevents RecalculateVirtualSize re-entrancy
wxPG_FL_RECALCULATING_VIRTUAL_SIZE = 0x80000000
};
#if !defined(__wxPG_SOURCE_FILE__)
// Reduce compile time, but still include in user app
#include "wx/propgrid/props.h"
@ -1260,6 +1209,52 @@ public:
// Mostly useful for page switching.
void SwitchState( wxPropertyGridPageState* pNewState );
// Internal flags
enum wxPG_INTERNAL_FLAGS : long
{
wxPG_FL_INITIALIZED = 0x0001,
// Set when creating editor controls if it was clicked on.
wxPG_FL_ACTIVATION_BY_CLICK = 0x0002,
wxPG_FL_FOCUSED = 0x0004,
wxPG_FL_MOUSE_CAPTURED = 0x0008,
wxPG_FL_MOUSE_INSIDE = 0x0010,
wxPG_FL_VALUE_MODIFIED = 0x0020,
// don't clear background of m_wndEditor
wxPG_FL_PRIMARY_FILLS_ENTIRE = 0x0040,
// currently active editor uses custom image
wxPG_FL_CUR_USES_CUSTOM_IMAGE = 0x0080,
// cell colours override selection colours for selected cell
wxPG_FL_CELL_OVERRIDES_SEL = 0x0100,
wxPG_FL_SCROLLED = 0x0200,
// set when all added/inserted properties get hideable flag
wxPG_FL_ADDING_HIDEABLES = 0x0400,
// Disables showing help strings on statusbar.
wxPG_FL_NOSTATUSBARHELP = 0x0800,
// Marks that we created the state, so we have to destroy it too.
wxPG_FL_CREATEDSTATE = 0x1000,
// Set if contained in wxPropertyGridManager
wxPG_FL_IN_MANAGER = 0x2000,
// Set after wxPropertyGrid is shown in its initial good size
wxPG_FL_GOOD_SIZE_SET = 0x4000,
// Set when in SelectProperty.
wxPG_FL_IN_SELECT_PROPERTY = 0x8000,
// Set when help string is shown in status bar
wxPG_FL_STRING_IN_STATUSBAR = 0x00010000,
// Auto sort is enabled (for categorized mode)
wxPG_FL_CATMODE_AUTO_SORT = 0x00020000,
// Active editor control is abnormally large
wxPG_FL_ABNORMAL_EDITOR = 0x00040000,
// Recursion guard for HandleCustomEditorEvent
wxPG_FL_IN_HANDLECUSTOMEDITOREVENT = 0x00080000,
wxPG_FL_VALUE_CHANGE_IN_EVENT = 0x00100000,
// Editor control width should not change on resize
wxPG_FL_FIXED_WIDTH_EDITOR = 0x00200000,
// Width of panel can be different from width of grid
wxPG_FL_HAS_VIRTUAL_WIDTH = 0x00400000,
// Prevents RecalculateVirtualSize re-entrancy
wxPG_FL_RECALCULATING_VIRTUAL_SIZE = 0x00800000
};
long GetInternalFlags() const { return m_iFlags; }
bool HasInternalFlag( long flag ) const
{ return (m_iFlags & flag) != 0; }
@ -2224,28 +2219,6 @@ protected:
// -----------------------------------------------------------------------
//
// Undefine macros that are not needed outside propertygrid sources
//
#ifndef __wxPG_SOURCE_FILE__
#undef wxPG_FL_DESC_REFRESH_REQUIRED
#undef wxPG_FL_CREATEDSTATE
#undef wxPG_FL_NOSTATUSBARHELP
#undef wxPG_FL_SCROLLED
#undef wxPG_FL_CUR_USES_CUSTOM_IMAGE
#undef wxPG_FL_PRIMARY_FILLS_ENTIRE
#undef wxPG_FL_VALUE_MODIFIED
#undef wxPG_FL_MOUSE_INSIDE
#undef wxPG_FL_FOCUSED
#undef wxPG_FL_MOUSE_CAPTURED
#undef wxPG_FL_INITIALIZED
#undef wxPG_FL_ACTIVATION_BY_CLICK
#undef wxPG_ICON_WIDTH
#undef wxPG_USE_RENDERER_NATIVE
#endif
// -----------------------------------------------------------------------
#endif
#endif // _WX_PROPGRID_PROPGRID_H_

View file

@ -1139,7 +1139,7 @@ bool wxSystemColourProperty::QueryColourFromUser( wxVariant& variant ) const
wxASSERT( propgrid );
// Must only occur when user triggers event
if ( !propgrid->HasInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT) )
if ( !propgrid->HasInternalFlag(wxPropertyGrid::wxPG_FL_IN_HANDLECUSTOMEDITOREVENT) )
return res;
wxColourPropertyValue val = GetVal();

View file

@ -1107,7 +1107,7 @@ bool wxPGChoiceEditor::OnEvent( wxPropertyGrid* propGrid, wxPGProperty* property
if ( propGrid->GetUnspecifiedCommonValue() == cmnValIndex )
{
if ( !property->IsValueUnspecified() )
propGrid->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT);
propGrid->SetInternalFlag(wxPropertyGrid::wxPG_FL_VALUE_CHANGE_IN_EVENT);
property->SetValueToUnspecified();
if ( !cb->HasFlag(wxCB_READONLY) )
{
@ -1616,7 +1616,7 @@ wxPGWindowList wxPGCheckBoxEditor::CreateControls( wxPropertyGrid* propGrid,
if ( !property->IsValueUnspecified() )
{
if ( propGrid->HasInternalFlag(wxPG_FL_ACTIVATION_BY_CLICK) )
if ( propGrid->HasInternalFlag(wxPropertyGrid::wxPG_FL_ACTIVATION_BY_CLICK) )
{
// Send the event to toggle the value (if mouse cursor is on the item)
wxPoint point = cb->ScreenToClient(::wxGetMousePosition());
@ -1628,7 +1628,7 @@ wxPGWindowList wxPGCheckBoxEditor::CreateControls( wxPropertyGrid* propGrid,
}
}
propGrid->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR );
propGrid->SetInternalFlag(wxPropertyGrid::wxPG_FL_FIXED_WIDTH_EDITOR);
return cb;
}

View file

@ -39,17 +39,17 @@
// when using custom controls
#define BEGIN_MOUSE_CAPTURE \
if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) ) \
if ( !(m_iFlags & wxPG_MAN_FL_MOUSE_CAPTURED) ) \
{ \
CaptureMouse(); \
m_iFlags |= wxPG_FL_MOUSE_CAPTURED; \
m_iFlags |= wxPG_MAN_FL_MOUSE_CAPTURED; \
}
#define END_MOUSE_CAPTURE \
if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) \
if ( m_iFlags & wxPG_MAN_FL_MOUSE_CAPTURED ) \
{ \
ReleaseMouse(); \
m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED); \
m_iFlags &= ~(wxPG_MAN_FL_MOUSE_CAPTURED); \
}
// -----------------------------------------------------------------------
@ -571,6 +571,17 @@ private:
// wxPropertyGridManager
// -----------------------------------------------------------------------
// Internal flags
enum wxPGMAN_INTERNAL_FLAGS : long
{
wxPG_MAN_FL_INITIALIZED = 0x0001,
wxPG_MAN_FL_MOUSE_CAPTURED = 0x0002,
// Set if wxPGMan requires redrawing of description text box.
wxPG_MAN_FL_DESC_REFRESH_REQUIRED = 0x0004,
// Set after page has been inserted to manager
wxPG_MAN_FL_PAGE_INSERTED = 0x0008
};
// Final default splitter y is client height minus this.
#define wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y 100
@ -689,7 +700,7 @@ constexpr long wxPG_MAN_PASS_FLAGS_MASK = wxPG_WINDOW_STYLE_MASK | wxTAB_TRAVERS
void wxPropertyGridManager::Init2( int style )
{
if ( m_iFlags & wxPG_FL_INITIALIZED )
if ( m_iFlags & wxPG_MAN_FL_INITIALIZED )
return;
m_windowStyle |= (style & wxPG_WINDOW_STYLE_MASK);
@ -742,7 +753,7 @@ void wxPropertyGridManager::Init2( int style )
m_pPropGrid->SetId(useId);
m_pPropGrid->SetInternalFlag(wxPG_FL_IN_MANAGER);
m_pPropGrid->SetInternalFlag(wxPropertyGrid::wxPG_FL_IN_MANAGER);
m_pState = m_pPropGrid->m_pState;
@ -762,7 +773,7 @@ void wxPropertyGridManager::Init2( int style )
// Optional initial controls.
m_width = -12345;
m_iFlags |= wxPG_FL_INITIALIZED;
m_iFlags |= wxPG_MAN_FL_INITIALIZED;
}
@ -935,7 +946,7 @@ bool wxPropertyGridManager::DoSelectPage( int index )
nextPage = m_emptyPage;
}
m_iFlags |= wxPG_FL_DESC_REFRESH_REQUIRED;
m_iFlags |= wxPG_MAN_FL_DESC_REFRESH_REQUIRED;
m_pPropGrid->SwitchState( nextPage->GetStatePtr() );
@ -1491,7 +1502,7 @@ void wxPropertyGridManager::UpdateDescriptionBox( int new_splittery, int new_wid
m_splitterY = new_splittery;
m_iFlags &= ~(wxPG_FL_DESC_REFRESH_REQUIRED);
m_iFlags &= ~(wxPG_MAN_FL_DESC_REFRESH_REQUIRED);
}
// -----------------------------------------------------------------------
@ -1558,7 +1569,7 @@ void wxPropertyGridManager::RecalculatePositions( int width, int height )
UpdateDescriptionBox( new_splittery, width, height );
}
if ( m_iFlags & wxPG_FL_INITIALIZED )
if ( m_iFlags & wxPG_MAN_FL_INITIALIZED )
{
int pgh = propgridBottomY - propgridY;
if ( pgh < 0 )
@ -1833,7 +1844,7 @@ void wxPropertyGridManager::RecreateControls()
if ( m_windowStyle & wxPG_DESCRIPTION )
{
// Has help box.
m_pPropGrid->SetInternalFlag(wxPG_FL_NOSTATUSBARHELP);
m_pPropGrid->SetInternalFlag(wxPropertyGrid::wxPG_FL_NOSTATUSBARHELP);
if ( !m_pTxtHelpCaption )
{
@ -1862,7 +1873,7 @@ void wxPropertyGridManager::RecreateControls()
else
{
// No help box.
m_pPropGrid->ClearInternalFlag(wxPG_FL_NOSTATUSBARHELP);
m_pPropGrid->ClearInternalFlag(wxPropertyGrid::wxPG_FL_NOSTATUSBARHELP);
if ( m_pTxtHelpCaption )
m_pTxtHelpCaption->Destroy();
@ -1928,7 +1939,7 @@ void wxPropertyGridManager::OnToolbarClick( wxCommandEvent &event )
// Categorized mode.
if ( m_pPropGrid->HasFlag(wxPG_HIDE_CATEGORIES) )
{
if ( !m_pPropGrid->HasInternalFlag(wxPG_FL_CATMODE_AUTO_SORT) )
if ( !m_pPropGrid->HasInternalFlag(wxPropertyGrid::wxPG_FL_CATMODE_AUTO_SORT) )
m_pPropGrid->m_windowStyle &= ~wxPG_AUTO_SORT;
m_pPropGrid->EnableCategories( true );
}
@ -1939,9 +1950,9 @@ void wxPropertyGridManager::OnToolbarClick( wxCommandEvent &event )
if ( !m_pPropGrid->HasFlag(wxPG_HIDE_CATEGORIES) )
{
if ( m_pPropGrid->HasFlag(wxPG_AUTO_SORT) )
m_pPropGrid->SetInternalFlag(wxPG_FL_CATMODE_AUTO_SORT);
m_pPropGrid->SetInternalFlag(wxPropertyGrid::wxPG_FL_CATMODE_AUTO_SORT);
else
m_pPropGrid->ClearInternalFlag(wxPG_FL_CATMODE_AUTO_SORT);
m_pPropGrid->ClearInternalFlag(wxPropertyGrid::wxPG_FL_CATMODE_AUTO_SORT);
m_pPropGrid->m_windowStyle |= wxPG_AUTO_SORT;
m_pPropGrid->EnableCategories( false );

View file

@ -604,7 +604,7 @@ void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState,
// make this one hideable.
if (
( !parentIsRoot && parent->HasFlag(wxPG_PROP_HIDDEN) ) ||
( propgrid && (propgrid->HasInternalFlag(wxPG_FL_ADDING_HIDEABLES)) )
( propgrid && (propgrid->HasInternalFlag(wxPropertyGrid::wxPG_FL_ADDING_HIDEABLES)) )
)
SetFlag( wxPG_PROP_HIDDEN );