1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
67 // Two pics for the expand / collapse buttons.
68 // Files are not supplied with this project (since it is
69 // recommended to use either custom or native rendering).
70 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
71 // and copy xpm files from archive to wxPropertyGrid src directory
72 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
73 // and set wxPG_USE_RENDERER_NATIVE to 0).
74 #ifndef wxPG_ICON_WIDTH
75 #if defined(__WXMAC__)
76 #include "mac_collapse.xpm"
77 #include "mac_expand.xpm"
78 #elif defined(__WXGTK__)
79 #include "linux_collapse.xpm"
80 #include "linux_expand.xpm"
82 #include "default_collapse.xpm"
83 #include "default_expand.xpm"
88 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
89 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
90 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
91 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
92 #define wxPG_YSPACING_MIN 1
93 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
94 // but causes normal combobox to spill out under MSW
96 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
98 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
99 // Must be larger than largest control border
103 #define wxPG_DEFAULT_CURSOR wxNullCursor
106 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
108 //#define wxPG_HIDER_BUTTON_HEIGHT 25
110 #define wxPG_PIXELS_PER_UNIT m_lineHeight
112 #ifdef wxPG_ICON_WIDTH
113 #define m_iconHeight m_iconWidth
116 //#define wxPG_TOOLTIP_DELAY 1000
118 // This is the number of pixels the expander button inside
119 // property cells (i.e. not in the grey margin area are
121 #define IN_CELL_EXPANDER_BUTTON_X_ADJUST 2
123 // -----------------------------------------------------------------------
126 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
128 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
131 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
134 // -----------------------------------------------------------------------
136 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
138 // -----------------------------------------------------------------------
139 // Statics in one class for easy destruction.
140 // -----------------------------------------------------------------------
142 #include "wx/module.h"
144 class wxPGGlobalVarsClassManager
: public wxModule
146 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
148 wxPGGlobalVarsClassManager() {}
149 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
150 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
153 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
156 // When wxPG is loaded dynamically after the application is already running
157 // then the built-in module system won't pick this one up. Add it manually.
158 void wxPGInitResourceModule()
160 wxModule
* module = new wxPGGlobalVarsClassManager
;
162 wxModule::RegisterModule(module);
165 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
168 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
170 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
172 m_boolChoices
.Add(_("False"));
173 m_boolChoices
.Add(_("True"));
175 m_fontFamilyChoices
= NULL
;
177 m_defaultRenderer
= new wxPGDefaultRenderer();
179 m_autoGetTranslation
= false;
187 // Prepare some shared variants
188 m_vEmptyString
= wxString();
190 m_vMinusOne
= (long) -1;
194 // Prepare cached string constants
195 m_strstring
= wxS("string");
196 m_strlong
= wxS("long");
197 m_strbool
= wxS("bool");
198 m_strlist
= wxS("list");
199 m_strDefaultValue
= wxS("DefaultValue");
200 m_strMin
= wxS("Min");
201 m_strMax
= wxS("Max");
202 m_strUnits
= wxS("Units");
203 m_strHint
= wxS("Hint");
204 #if wxPG_COMPATIBILITY_1_4
205 m_strInlineHelp
= wxS("InlineHelp");
212 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
216 delete m_defaultRenderer
;
218 // This will always have one ref
219 delete m_fontFamilyChoices
;
222 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
223 delete ((wxValidator
*)m_arrValidators
[i
]);
227 // Destroy value type class instances.
228 wxPGHashMapS2P::iterator vt_it
;
230 // Destroy editor class instances.
231 // iterate over all the elements in the class
232 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
234 delete ((wxPGEditor
*)vt_it
->second
);
237 delete wxPGProperty::sm_wxPG_LABEL
;
240 void wxPropertyGridInitGlobalsIfNeeded()
244 // -----------------------------------------------------------------------
246 // -----------------------------------------------------------------------
248 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
250 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
251 EVT_IDLE(wxPropertyGrid::OnIdle
)
252 EVT_PAINT(wxPropertyGrid::OnPaint
)
253 EVT_SIZE(wxPropertyGrid::OnResize
)
254 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
255 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
256 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
257 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
258 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
259 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
260 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
261 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
262 EVT_MOTION(wxPropertyGrid::OnMouseMove
)
263 EVT_LEFT_DOWN(wxPropertyGrid::OnMouseClick
)
264 EVT_LEFT_UP(wxPropertyGrid::OnMouseUp
)
265 EVT_RIGHT_UP(wxPropertyGrid::OnMouseRightClick
)
266 EVT_LEFT_DCLICK(wxPropertyGrid::OnMouseDoubleClick
)
267 EVT_KEY_DOWN(wxPropertyGrid::OnKey
)
270 // -----------------------------------------------------------------------
272 wxPropertyGrid::wxPropertyGrid()
278 // -----------------------------------------------------------------------
280 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
285 const wxString
& name
)
289 Create(parent
,id
,pos
,size
,style
,name
);
292 // -----------------------------------------------------------------------
294 bool wxPropertyGrid::Create( wxWindow
*parent
,
299 const wxString
& name
)
302 if (!(style
&wxBORDER_MASK
))
304 style
|= wxBORDER_THEME
;
309 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
310 style
&= ~(wxTAB_TRAVERSAL
);
311 style
|= wxWANTS_CHARS
;
313 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
320 // -----------------------------------------------------------------------
323 // Initialize values to defaults
325 void wxPropertyGrid::Init1()
327 // Register editor classes, if necessary.
328 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
329 wxPropertyGrid::RegisterDefaultEditors();
333 m_wndEditor
= m_wndEditor2
= NULL
;
337 m_labelEditor
= NULL
;
338 m_labelEditorProperty
= NULL
;
339 m_eventObject
= this;
341 m_processedEvent
= NULL
;
342 m_sortFunction
= NULL
;
343 m_inDoPropertyChanged
= 0;
344 m_inCommitChangesFromEditor
= 0;
345 m_inDoSelectProperty
= 0;
346 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
351 // Set up default unspecified value 'colour'
352 m_unspecifiedAppearance
.SetFgCol(*wxLIGHT_GREY
);
355 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
356 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
357 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
358 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
359 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
360 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
361 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
362 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
363 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
365 m_coloursCustomized
= 0;
368 #if wxPG_DOUBLE_BUFFER
369 m_doubleBuffer
= NULL
;
372 #ifndef wxPG_ICON_WIDTH
378 m_iconWidth
= wxPG_ICON_WIDTH
;
383 m_gutterWidth
= wxPG_GUTTER_MIN
;
384 m_subgroup_extramargin
= 10;
388 m_width
= m_height
= 0;
390 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
393 m_chgInfo_changedProperty
= NULL
;
396 // -----------------------------------------------------------------------
399 // Initialize after parent etc. set
401 void wxPropertyGrid::Init2()
403 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
406 // Smaller controls on Mac
407 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
410 // Now create state, if one didn't exist already
411 // (wxPropertyGridManager might have created it for us).
414 m_pState
= CreateState();
415 m_pState
->m_pPropGrid
= this;
416 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
419 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
420 m_pState
->m_dontCenterSplitter
= true;
422 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
424 m_pState
->InitNonCatMode();
426 m_pState
->m_properties
= m_pState
->m_abcArray
;
429 GetClientSize(&m_width
,&m_height
);
431 #ifndef wxPG_ICON_WIDTH
432 // create two bitmap nodes for drawing
433 m_expandbmp
= new wxBitmap(expand_xpm
);
434 m_collbmp
= new wxBitmap(collapse_xpm
);
436 // calculate average font height for bitmap centering
438 m_iconWidth
= m_expandbmp
->GetWidth();
439 m_iconHeight
= m_expandbmp
->GetHeight();
442 m_curcursor
= wxCURSOR_ARROW
;
443 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
445 // adjust bitmap icon y position so they are centered
446 m_vspacing
= wxPG_DEFAULT_VSPACING
;
448 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
450 // Allocate cell datas
451 m_propertyDefaultCell
.SetEmptyData();
452 m_categoryDefaultCell
.SetEmptyData();
456 // This helps with flicker
457 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
459 // Hook the top-level parent
464 // set virtual size to this window size
465 wxSize wndsize
= GetSize();
466 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
468 m_timeCreated
= ::wxGetLocalTimeMillis();
470 //m_canvas->Create(this, wxID_ANY, wxPoint(0, 0), GetClientSize(),
471 // wxWANTS_CHARS | wxCLIP_CHILDREN);
472 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
474 m_iFlags
|= wxPG_FL_INITIALIZED
;
476 m_ncWidth
= wndsize
.GetWidth();
478 // Need to call OnResize handler or size given in constructor/Create
480 wxSizeEvent
sizeEvent(wndsize
,0);
484 // -----------------------------------------------------------------------
486 wxPropertyGrid::~wxPropertyGrid()
491 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
495 // Remove grid and property pointers from live wxPropertyGridEvents.
496 for ( i
=0; i
<m_liveEvents
.size(); i
++ )
498 wxPropertyGridEvent
* evt
= m_liveEvents
[i
];
499 evt
->SetPropertyGrid(NULL
);
500 evt
->SetProperty(NULL
);
502 m_liveEvents
.clear();
504 if ( m_processedEvent
)
506 // All right... we are being deleted while wxPropertyGrid event
507 // is being sent. Make sure that event propagates as little
508 // as possible (although usually this is not enough to prevent
510 m_processedEvent
->Skip(false);
511 m_processedEvent
->StopPropagation();
513 // Let's use wxMessageBox to make the message appear more
514 // reliably (and *before* the crash can happen).
515 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
516 "generated by it. This usually leads to a crash "
517 "so it is recommended to destroy the control "
518 "at idle time instead.");
521 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
523 // This should do prevent things from going too badly wrong
524 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
526 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
529 // Call with NULL to disconnect event handling
530 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
534 wxASSERT_MSG( !IsEditorsValueModified(),
535 wxS("Most recent change in property editor was ")
536 wxS("lost!!! (if you don't want this to happen, ")
537 wxS("close your frames and dialogs using ")
538 wxS("Close(false).)") );
541 #if wxPG_DOUBLE_BUFFER
542 if ( m_doubleBuffer
)
543 delete m_doubleBuffer
;
546 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
549 delete m_cursorSizeWE
;
551 #ifndef wxPG_ICON_WIDTH
556 // Delete common value records
557 for ( i
=0; i
<m_commonValues
.size(); i
++ )
559 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
560 wxPGCommonValue
* value
= m_commonValues
[i
];
565 // -----------------------------------------------------------------------
567 bool wxPropertyGrid::Destroy()
569 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
572 return wxScrolledWindow::Destroy();
575 // -----------------------------------------------------------------------
577 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
579 return new wxPropertyGridPageState();
582 // -----------------------------------------------------------------------
583 // wxPropertyGrid overridden wxWindow methods
584 // -----------------------------------------------------------------------
586 void wxPropertyGrid::SetWindowStyleFlag( long style
)
588 long old_style
= m_windowStyle
;
590 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
592 wxASSERT( m_pState
);
594 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
597 EnableCategories( true );
599 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
601 // Disable categories
602 EnableCategories( false );
604 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
610 PrepareAfterItemsAdded();
612 m_pState
->m_itemsAdded
= 1;
614 #if wxPG_SUPPORT_TOOLTIPS
615 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
621 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
622 SetToolTip ( tooltip );
623 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
626 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
631 wxScrolledWindow::SetToolTip( NULL
);
636 wxScrolledWindow::SetWindowStyleFlag ( style
);
638 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
640 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
642 CalculateFontAndBitmapStuff( m_vspacing
);
648 // -----------------------------------------------------------------------
650 void wxPropertyGrid::Freeze()
654 wxScrolledWindow::Freeze();
659 // -----------------------------------------------------------------------
661 void wxPropertyGrid::Thaw()
667 wxScrolledWindow::Thaw();
668 RecalculateVirtualSize();
669 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
673 // Force property re-selection
674 // NB: We must copy the selection.
675 wxArrayPGProperty selection
= m_pState
->m_selection
;
676 DoSetSelection(selection
, wxPG_SEL_FORCE
| wxPG_SEL_NONVISIBLE
);
680 // -----------------------------------------------------------------------
682 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
684 wxCHECK( prop
, false );
686 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
687 return DoSelectProperty(prop
, selFlags
);
689 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
691 if ( !selection
.size() )
693 return DoSelectProperty(prop
, selFlags
);
697 // For categories, only one can be selected at a time
698 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
701 selection
.push_back(prop
);
703 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
705 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
714 // -----------------------------------------------------------------------
716 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
718 wxCHECK( prop
, false );
721 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
722 if ( selection
.size() <= 1 )
724 res
= DoSelectProperty(NULL
, selFlags
);
728 m_pState
->DoRemoveFromSelection(prop
);
736 // -----------------------------------------------------------------------
738 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
739 unsigned int colIndex
,
740 unsigned int selFlags
)
743 // NB: Enable following if label editor background colour is
744 // ever changed to any other than m_colSelBack.
746 // We use this workaround to prevent visible flicker when editing
747 // a cell. Atleast on wxMSW, there is a difficult to find
748 // (and perhaps prevent) redraw somewhere between making property
749 // selected and enabling label editing.
751 //wxColour prevColSelBack = m_colSelBack;
752 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
758 res
= DoSelectProperty(prop
, selFlags
);
763 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
765 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
767 res
= DoAddToSelection(prop
, selFlags
);
771 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
773 DoBeginLabelEdit(colIndex
, selFlags
);
777 //m_colSelBack = prevColSelBack;
781 // -----------------------------------------------------------------------
783 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
784 unsigned int colIndex
,
785 wxMouseEvent
* mouseEvent
,
788 const wxArrayPGProperty
& selection
= GetSelectedProperties();
789 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
792 // Set to 2 if also add all items in between
793 int addToExistingSelection
= 0;
795 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
799 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
800 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
802 // Allow right-click for context menu without
803 // disturbing the selection.
804 if ( GetSelectedProperties().size() <= 1 ||
806 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
811 if ( mouseEvent
->ControlDown() )
813 addToExistingSelection
= 1;
815 else if ( mouseEvent
->ShiftDown() )
817 if ( selection
.size() > 0 && !prop
->IsCategory() )
818 addToExistingSelection
= 2;
820 addToExistingSelection
= 1;
826 if ( addToExistingSelection
== 1 )
829 if ( !alreadySelected
)
831 res
= DoAddToSelection(prop
, selFlags
);
833 else if ( GetSelectedProperties().size() > 1 )
835 res
= DoRemoveFromSelection(prop
, selFlags
);
838 else if ( addToExistingSelection
== 2 )
840 // Add this, and all in between
842 // Find top selected property
843 wxPGProperty
* topSelProp
= selection
[0];
844 int topSelPropY
= topSelProp
->GetY();
845 for ( unsigned int i
=1; i
<selection
.size(); i
++ )
847 wxPGProperty
* p
= selection
[i
];
849 if ( y
< topSelPropY
)
856 wxPGProperty
* startFrom
;
857 wxPGProperty
* stopAt
;
859 if ( prop
->GetY() <= topSelPropY
)
861 // Property is above selection (or same)
867 // Property is below selection
868 startFrom
= topSelProp
;
872 // Iterate through properties in-between, and select them
873 wxPropertyGridIterator it
;
875 for ( it
= GetIterator(wxPG_ITERATE_VISIBLE
, startFrom
);
879 wxPGProperty
* p
= *it
;
881 if ( !p
->IsCategory() &&
882 !m_pState
->DoIsPropertySelected(p
) )
884 DoAddToSelection(p
, selFlags
);
893 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
899 // -----------------------------------------------------------------------
901 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
904 if ( newSelection
.size() > 0 )
906 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
911 DoClearSelection(false, selFlags
);
914 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
916 DoAddToSelection(newSelection
[i
], selFlags
);
922 // -----------------------------------------------------------------------
924 void wxPropertyGrid::MakeColumnEditable( unsigned int column
,
927 wxASSERT( column
!= 1 );
929 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
933 cols
.push_back(column
);
937 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
939 if ( cols
[i
] == (int)column
)
940 cols
.erase( cols
.begin() + i
);
945 // -----------------------------------------------------------------------
947 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
950 wxPGProperty
* selected
= GetSelection();
951 wxCHECK_RET(selected
, wxT("No property selected"));
952 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
954 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
956 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
963 const wxPGCell
* cell
= NULL
;
964 if ( selected
->HasCell(colIndex
) )
966 cell
= &selected
->GetCell(colIndex
);
967 if ( !cell
->HasText() && colIndex
== 0 )
968 text
= selected
->GetLabel();
974 text
= selected
->GetLabel();
976 cell
= &selected
->GetOrCreateCell(colIndex
);
979 if ( cell
&& cell
->HasText() )
980 text
= cell
->GetText();
982 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
984 m_selColumn
= colIndex
;
986 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
988 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
996 wxWindowID id
= tc
->GetId();
997 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
998 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
1000 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1001 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
1006 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1007 m_labelEditorProperty
= selected
;
1010 // -----------------------------------------------------------------------
1013 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1015 DoEndLabelEdit(true);
1018 // -----------------------------------------------------------------------
1020 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1022 int keycode
= event
.GetKeyCode();
1024 if ( keycode
== WXK_ESCAPE
)
1026 DoEndLabelEdit(false);
1034 // -----------------------------------------------------------------------
1036 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1038 if ( !m_labelEditor
)
1041 wxPGProperty
* prop
= m_labelEditorProperty
;
1046 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1048 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1049 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1050 prop
, NULL
, selFlags
,
1055 wxString text
= m_labelEditor
->GetValue();
1056 wxPGCell
* cell
= NULL
;
1057 if ( prop
->HasCell(m_selColumn
) )
1059 cell
= &prop
->GetCell(m_selColumn
);
1063 if ( m_selColumn
== 0 )
1064 prop
->SetLabel(text
);
1066 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1070 cell
->SetText(text
);
1074 int wasFocused
= m_iFlags
& wxPG_FL_FOCUSED
;
1076 DestroyEditorWnd(m_labelEditor
);
1078 m_labelEditor
= NULL
;
1079 m_labelEditorProperty
= NULL
;
1081 // Fix focus (needed at least on wxGTK)
1088 // -----------------------------------------------------------------------
1090 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1092 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1093 OnTLPChanging(::wxGetTopLevelParent(this));
1095 OnTLPChanging(NULL
);
1097 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1099 #if defined(__WXMSW__)
1102 // Don't use WS_EX_COMPOSITED just now.
1105 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1106 hWnd = (HWND)GetParent()->GetHWND();
1108 hWnd = (HWND)GetHWND();
1110 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1111 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1114 //#elif defined(__WXGTK20__)
1116 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1117 // truly was double-buffered.
1118 if ( !this->IsDoubleBuffered() )
1120 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1124 #if wxPG_DOUBLE_BUFFER
1125 delete m_doubleBuffer
;
1126 m_doubleBuffer
= NULL
;
1131 wxScrolledWindow::SetExtraStyle( exStyle
);
1133 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1134 m_pState
->InitNonCatMode();
1136 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1137 m_windowStyle
|= wxPG_TOOLTIPS
;
1140 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1143 // -----------------------------------------------------------------------
1145 // returns the best acceptable minimal size
1146 wxSize
wxPropertyGrid::DoGetBestSize() const
1148 int lineHeight
= wxMax(15, m_lineHeight
);
1150 // don't make the grid too tall (limit height to 10 items) but don't
1151 // make it too small neither
1152 int numLines
= wxMin
1154 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1158 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1159 int width
= m_marginWidth
;
1160 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1162 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1165 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1171 // -----------------------------------------------------------------------
1173 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1175 if ( newTLP
== m_tlp
)
1178 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1181 // Parent changed so let's redetermine and re-hook the
1182 // correct top-level window.
1185 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1186 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1188 m_tlpClosed
= m_tlp
;
1189 m_tlpClosedTime
= currentTime
;
1194 // Only accept new tlp if same one was not just dismissed.
1195 if ( newTLP
!= m_tlpClosed
||
1196 m_tlpClosedTime
+250 < currentTime
)
1198 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1199 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1212 // -----------------------------------------------------------------------
1214 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1216 // ClearSelection forces value validation/commit.
1217 if ( event
.CanVeto() && !DoClearSelection() )
1223 // Ok, it can close, set tlp pointer to NULL. Some other event
1224 // handler can of course veto the close, but our OnIdle() should
1225 // then be able to regain the tlp pointer.
1226 OnTLPChanging(NULL
);
1231 // -----------------------------------------------------------------------
1233 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1235 OnTLPChanging((wxWindow
*)newParent
);
1237 bool res
= wxScrolledWindow::Reparent(newParent
);
1242 // -----------------------------------------------------------------------
1243 // wxPropertyGrid Font and Colour Methods
1244 // -----------------------------------------------------------------------
1246 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1250 m_captionFont
= wxScrolledWindow::GetFont();
1252 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1253 m_subgroup_extramargin
= x
+ (x
/2);
1256 #if wxPG_USE_RENDERER_NATIVE
1257 m_iconWidth
= wxPG_ICON_WIDTH
;
1258 #elif wxPG_ICON_WIDTH
1260 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1261 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1262 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1266 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1267 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1268 m_gutterWidth
= wxPG_GUTTER_MIN
;
1271 if ( vspacing
<= 1 ) vdiv
= 12;
1272 else if ( vspacing
>= 3 ) vdiv
= 3;
1274 m_spacingy
= m_fontHeight
/ vdiv
;
1275 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1276 m_spacingy
= wxPG_YSPACING_MIN
;
1279 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1280 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1282 m_captionFont
.SetWeight(wxBOLD
);
1283 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1285 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1288 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1289 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1292 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1294 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1295 RecalculateVirtualSize();
1297 InvalidateBestSize();
1300 // -----------------------------------------------------------------------
1302 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1308 // -----------------------------------------------------------------------
1310 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1311 int ga
= 1000, int ba
= 1000,
1312 bool forceDifferent
= false)
1319 // Recursion guard (allow 2 max)
1320 static int isinside
= 0;
1322 wxCHECK_MSG( isinside
< 3,
1324 wxT("wxPGAdjustColour should not be recursively called more than once") );
1329 int g
= src
.Green();
1332 if ( r2
>255 ) r2
= 255;
1333 else if ( r2
<0) r2
= 0;
1335 if ( g2
>255 ) g2
= 255;
1336 else if ( g2
<0) g2
= 0;
1338 if ( b2
>255 ) b2
= 255;
1339 else if ( b2
<0) b2
= 0;
1341 // Make sure they are somewhat different
1342 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1343 dst
= wxPGAdjustColour(src
,-(ra
*2));
1345 dst
= wxColour(r2
,g2
,b2
);
1347 // Recursion guard (allow 2 max)
1354 static int wxPGGetColAvg( const wxColour
& col
)
1356 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1360 void wxPropertyGrid::RegainColours()
1362 if ( !(m_coloursCustomized
& 0x0002) )
1364 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1366 // Make sure colour is dark enough
1368 int colDec
= wxPGGetColAvg(col
) - 230;
1370 int colDec
= wxPGGetColAvg(col
) - 200;
1373 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1376 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1379 if ( !(m_coloursCustomized
& 0x0001) )
1380 m_colMargin
= m_colCapBack
;
1382 if ( !(m_coloursCustomized
& 0x0004) )
1389 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1390 m_colCapFore
= capForeCol
;
1391 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1394 if ( !(m_coloursCustomized
& 0x0008) )
1396 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1397 m_colPropBack
= bgCol
;
1398 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1399 if ( !m_unspecifiedAppearance
.GetBgCol().IsOk() )
1400 m_unspecifiedAppearance
.SetBgCol(bgCol
);
1403 if ( !(m_coloursCustomized
& 0x0010) )
1405 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1406 m_colPropFore
= fgCol
;
1407 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1408 if ( !m_unspecifiedAppearance
.GetFgCol().IsOk() )
1409 m_unspecifiedAppearance
.SetFgCol(fgCol
);
1412 if ( !(m_coloursCustomized
& 0x0020) )
1413 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1415 if ( !(m_coloursCustomized
& 0x0040) )
1416 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1418 if ( !(m_coloursCustomized
& 0x0080) )
1419 m_colLine
= m_colCapBack
;
1421 if ( !(m_coloursCustomized
& 0x0100) )
1422 m_colDisPropFore
= m_colCapFore
;
1424 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1427 // -----------------------------------------------------------------------
1429 void wxPropertyGrid::ResetColours()
1431 m_coloursCustomized
= 0;
1438 // -----------------------------------------------------------------------
1440 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1442 // Must disable active editor.
1445 bool res
= wxScrolledWindow::SetFont( font
);
1446 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1448 CalculateFontAndBitmapStuff( m_vspacing
);
1455 // -----------------------------------------------------------------------
1457 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1460 m_coloursCustomized
|= 0x80;
1464 // -----------------------------------------------------------------------
1466 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1469 m_coloursCustomized
|= 0x01;
1473 // -----------------------------------------------------------------------
1475 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1477 m_colPropBack
= col
;
1478 m_coloursCustomized
|= 0x08;
1480 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1481 m_unspecifiedAppearance
.SetBgCol(col
);
1486 // -----------------------------------------------------------------------
1488 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1490 m_colPropFore
= col
;
1491 m_coloursCustomized
|= 0x10;
1493 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1494 m_unspecifiedAppearance
.SetFgCol(col
);
1499 // -----------------------------------------------------------------------
1501 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1503 m_colEmptySpace
= col
;
1508 // -----------------------------------------------------------------------
1510 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1512 m_colDisPropFore
= col
;
1513 m_coloursCustomized
|= 0x100;
1517 // -----------------------------------------------------------------------
1519 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1522 m_coloursCustomized
|= 0x20;
1526 // -----------------------------------------------------------------------
1528 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1531 m_coloursCustomized
|= 0x40;
1535 // -----------------------------------------------------------------------
1537 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1540 m_coloursCustomized
|= 0x02;
1542 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1547 // -----------------------------------------------------------------------
1549 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1552 m_coloursCustomized
|= 0x04;
1554 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1559 // -----------------------------------------------------------------------
1560 // wxPropertyGrid property adding and removal
1561 // -----------------------------------------------------------------------
1563 void wxPropertyGrid::PrepareAfterItemsAdded()
1565 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1567 m_pState
->m_itemsAdded
= 0;
1569 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1570 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1572 RecalculateVirtualSize();
1574 // Fix editor position
1575 CorrectEditorWidgetPosY();
1578 // -----------------------------------------------------------------------
1579 // wxPropertyGrid property operations
1580 // -----------------------------------------------------------------------
1582 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1584 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1588 bool changed
= false;
1590 // Is it inside collapsed section?
1591 if ( !p
->IsVisible() )
1594 wxPGProperty
* parent
= p
->GetParent();
1595 wxPGProperty
* grandparent
= parent
->GetParent();
1597 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1598 Expand( grandparent
);
1606 GetViewStart(&vx
,&vy
);
1607 vy
*=wxPG_PIXELS_PER_UNIT
;
1613 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1614 m_iFlags
|= wxPG_FL_SCROLLED
;
1617 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1619 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1620 m_iFlags
|= wxPG_FL_SCROLLED
;
1630 // -----------------------------------------------------------------------
1631 // wxPropertyGrid helper methods called by properties
1632 // -----------------------------------------------------------------------
1634 // Control font changer helper.
1635 void wxPropertyGrid::SetCurControlBoldFont()
1637 wxASSERT( m_wndEditor
);
1638 m_wndEditor
->SetFont( m_captionFont
);
1641 // -----------------------------------------------------------------------
1643 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1646 #if wxPG_SMALL_SCREEN
1647 // On small-screen devices, always show dialogs with default position and size.
1648 return wxDefaultPosition
;
1650 int splitterX
= GetSplitterPosition();
1654 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1656 ImprovedClientToScreen( &x
, &y
);
1658 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1659 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1666 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1676 new_y
= y
+ m_lineHeight
;
1678 return wxPoint(new_x
,new_y
);
1682 // -----------------------------------------------------------------------
1684 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1686 if ( src_str
.length() == 0 )
1692 bool prev_is_slash
= false;
1694 wxString::const_iterator i
= src_str
.begin();
1698 for ( ; i
!= src_str
.end(); ++i
)
1702 if ( a
!= wxS('\\') )
1704 if ( !prev_is_slash
)
1710 if ( a
== wxS('n') )
1713 dst_str
<< wxS('\n');
1715 dst_str
<< wxS('\n');
1718 else if ( a
== wxS('t') )
1719 dst_str
<< wxS('\t');
1723 prev_is_slash
= false;
1727 if ( prev_is_slash
)
1729 dst_str
<< wxS('\\');
1730 prev_is_slash
= false;
1734 prev_is_slash
= true;
1741 // -----------------------------------------------------------------------
1743 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1745 if ( src_str
.length() == 0 )
1751 wxString::const_iterator i
= src_str
.begin();
1752 wxUniChar prev_a
= wxS('\0');
1756 for ( ; i
!= src_str
.end(); ++i
)
1760 if ( a
>= wxS(' ') )
1762 // This surely is not something that requires an escape sequence.
1767 // This might need...
1768 if ( a
== wxS('\r') )
1770 // DOS style line end.
1771 // Already taken care below
1773 else if ( a
== wxS('\n') )
1774 // UNIX style line end.
1775 dst_str
<< wxS("\\n");
1776 else if ( a
== wxS('\t') )
1778 dst_str
<< wxS('\t');
1781 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1791 // -----------------------------------------------------------------------
1793 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1800 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1803 // -----------------------------------------------------------------------
1804 // wxPropertyGrid graphics related methods
1805 // -----------------------------------------------------------------------
1807 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1812 // Don't paint after destruction has begun
1813 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1816 // Find out where the window is scrolled to
1817 int vx
,vy
; // Top left corner of client
1818 GetViewStart(&vx
,&vy
);
1819 vy
*= wxPG_PIXELS_PER_UNIT
;
1821 // Update everything inside the box
1822 wxRect r
= GetUpdateRegion().GetBox();
1826 // FIXME: This is just a workaround for a bug that causes splitters not
1827 // to paint when other windows are being dragged over the grid.
1829 r
.width
= GetClientSize().x
;
1831 // Repaint this rectangle
1832 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1834 // We assume that the size set when grid is shown
1835 // is what is desired.
1836 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1839 // -----------------------------------------------------------------------
1841 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1842 wxPGProperty
* property
) const
1844 // Prepare rectangle to be used
1846 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1847 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1849 #if (wxPG_USE_RENDERER_NATIVE)
1851 #elif wxPG_ICON_WIDTH
1852 // Drawing expand/collapse button manually
1853 dc
.SetPen(m_colPropFore
);
1854 if ( property
->IsCategory() )
1855 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1857 dc
.SetBrush(m_colPropBack
);
1859 dc
.DrawRectangle( r
);
1860 int _y
= r
.y
+(m_iconWidth
/2);
1861 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1866 if ( property
->IsExpanded() )
1868 // wxRenderer functions are non-mutating in nature, so it
1869 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1870 // Hopefully this does not cause problems.
1871 #if (wxPG_USE_RENDERER_NATIVE)
1872 wxRendererNative::Get().DrawTreeItemButton(
1878 #elif wxPG_ICON_WIDTH
1887 #if (wxPG_USE_RENDERER_NATIVE)
1888 wxRendererNative::Get().DrawTreeItemButton(
1894 #elif wxPG_ICON_WIDTH
1895 int _x
= r
.x
+(m_iconWidth
/2);
1896 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1902 #if (wxPG_USE_RENDERER_NATIVE)
1904 #elif wxPG_ICON_WIDTH
1907 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1911 // -----------------------------------------------------------------------
1914 // This is the one called by OnPaint event handler and others.
1915 // topy and bottomy are already unscrolled (ie. physical)
1917 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1918 unsigned int topItemY
,
1919 unsigned int bottomItemY
,
1920 const wxRect
* drawRect
)
1924 bottomItemY
< topItemY
||
1928 m_pState
->EnsureVirtualHeight();
1930 wxRect tempDrawRect
;
1933 tempDrawRect
= wxRect(0, topItemY
,
1936 drawRect
= &tempDrawRect
;
1939 // items added check
1940 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1942 int paintFinishY
= 0;
1944 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1947 bool isBuffered
= false;
1949 #if wxPG_DOUBLE_BUFFER
1950 wxMemoryDC
* bufferDC
= NULL
;
1952 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1954 if ( !m_doubleBuffer
)
1956 paintFinishY
= drawRect
->y
;
1961 bufferDC
= new wxMemoryDC();
1963 // If nothing was changed, then just copy from double-buffer
1964 bufferDC
->SelectObject( *m_doubleBuffer
);
1974 dc
.SetClippingRegion( *drawRect
);
1975 paintFinishY
= DoDrawItems( *dcPtr
, drawRect
, isBuffered
);
1976 int drawBottomY
= drawRect
->y
+ drawRect
->height
;
1978 // Clear area beyond last painted property
1979 if ( paintFinishY
< drawBottomY
)
1981 dcPtr
->SetPen(m_colEmptySpace
);
1982 dcPtr
->SetBrush(m_colEmptySpace
);
1983 dcPtr
->DrawRectangle(0, paintFinishY
,
1988 dc
.DestroyClippingRegion();
1991 #if wxPG_DOUBLE_BUFFER
1994 dc
.Blit( drawRect
->x
, drawRect
->y
, drawRect
->width
,
1996 bufferDC
, 0, 0, wxCOPY
);
2003 // Just clear the area
2004 dc
.SetPen(m_colEmptySpace
);
2005 dc
.SetBrush(m_colEmptySpace
);
2006 dc
.DrawRectangle(*drawRect
);
2010 // -----------------------------------------------------------------------
2012 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
2013 const wxRect
* drawRect
,
2014 bool isBuffered
) const
2016 const wxPGProperty
* firstItem
;
2017 const wxPGProperty
* lastItem
;
2019 firstItem
= DoGetItemAtY(drawRect
->y
);
2020 lastItem
= DoGetItemAtY(drawRect
->y
+drawRect
->height
-1);
2023 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
2025 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
2028 wxCHECK_MSG( !m_pState
->m_itemsAdded
, drawRect
->y
,
2030 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2032 int lh
= m_lineHeight
;
2035 int lastItemBottomY
;
2037 firstItemTopY
= drawRect
->y
;
2038 lastItemBottomY
= drawRect
->y
+ drawRect
->height
;
2040 // Align y coordinates to item boundaries
2041 firstItemTopY
-= firstItemTopY
% lh
;
2042 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2043 lastItemBottomY
-= 1;
2045 // Entire range outside scrolled, visible area?
2046 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
2047 lastItemBottomY
<= 0 )
2050 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
2052 "invalid y values" );
2055 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
2056 "height=%i (ch=%i), drawRect = 0x%lX )",
2057 firstItem->GetLabel().c_str(),
2058 lastItem->GetLabel().c_str(),
2059 (int)(lastItemBottomY - firstItemTopY),
2061 (unsigned long)drawRect );
2066 long windowStyle
= m_windowStyle
;
2071 // With wxPG_DOUBLE_BUFFER, do double buffering
2072 // - buffer's y = 0, so align drawRect and coordinates to that
2074 #if wxPG_DOUBLE_BUFFER
2081 xRelMod
= drawRect
->x
;
2082 yRelMod
= drawRect
->y
;
2085 // drawRect conversion
2090 firstItemTopY
-= yRelMod
;
2091 lastItemBottomY
-= yRelMod
;
2094 wxUnusedVar(isBuffered
);
2097 int x
= m_marginWidth
- xRelMod
;
2099 wxFont normalFont
= GetFont();
2101 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2103 bool isPgEnabled
= IsEnabled();
2106 // Prepare some pens and brushes that are often changed to.
2109 wxBrush
marginBrush(m_colMargin
);
2110 wxPen
marginPen(m_colMargin
);
2111 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2112 wxPen
linepen(m_colLine
,1,wxSOLID
);
2114 wxColour selBackCol
;
2116 selBackCol
= m_colSelBack
;
2118 selBackCol
= m_colMargin
;
2120 // pen that has same colour as text
2121 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2124 // Clear margin with background colour
2126 dc
.SetBrush( marginBrush
);
2127 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2129 dc
.SetPen( *wxTRANSPARENT_PEN
);
2130 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2133 const wxPGProperty
* firstSelected
= GetSelection();
2134 const wxPropertyGridPageState
* state
= m_pState
;
2135 const wxArrayInt
& colWidths
= state
->m_colWidths
;
2137 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2138 bool wasSelectedPainted
= false;
2141 // TODO: Only render columns that are within clipping region.
2143 dc
.SetFont(normalFont
);
2145 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2146 int endScanBottomY
= lastItemBottomY
+ lh
;
2147 int y
= firstItemTopY
;
2150 // Pregenerate list of visible properties.
2151 wxArrayPGProperty visPropArray
;
2152 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2154 for ( ; !it
.AtEnd(); it
.Next() )
2156 const wxPGProperty
* p
= *it
;
2158 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2160 visPropArray
.push_back((wxPGProperty
*)p
);
2162 if ( y
> endScanBottomY
)
2169 visPropArray
.push_back(NULL
);
2171 wxPGProperty
* nextP
= visPropArray
[0];
2173 int gridWidth
= state
->m_width
;
2176 for ( unsigned int arrInd
=1;
2177 nextP
&& y
<= lastItemBottomY
;
2180 wxPGProperty
* p
= nextP
;
2181 nextP
= visPropArray
[arrInd
];
2183 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2184 int textMarginHere
= x
;
2185 int renderFlags
= 0;
2187 int greyDepth
= m_marginWidth
;
2188 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2189 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2191 int greyDepthX
= greyDepth
- xRelMod
;
2193 // Use basic depth if in non-categoric mode and parent is base array.
2194 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2196 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2199 // Paint margin area
2200 dc
.SetBrush(marginBrush
);
2201 dc
.SetPen(marginPen
);
2202 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2204 dc
.SetPen( linepen
);
2210 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2211 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2212 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2214 // Is this or its parent themed?
2215 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2216 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2217 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2219 bool suppressMarginEdge
= false;
2221 if (!suppressMarginEdge
)
2222 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2225 // Blank out the margin edge
2226 dc
.SetPen(wxPen(GetBackgroundColour()));
2227 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2228 dc
.SetPen( linepen
);
2235 for ( si
=0; si
<colWidths
.size(); si
++ )
2237 sx
+= colWidths
[si
];
2238 dc
.DrawLine( sx
, y
, sx
, y2
);
2241 // Horizontal Line, below
2242 // (not if both this and next is category caption)
2243 if ( p
->IsCategory() &&
2244 nextP
&& nextP
->IsCategory() )
2245 dc
.SetPen(m_colCapBack
);
2247 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2250 // Need to override row colours?
2254 bool isSelected
= state
->DoIsPropertySelected(p
);
2258 // Disabled may get different colour.
2259 if ( !p
->IsEnabled() )
2261 renderFlags
|= wxPGCellRenderer::Disabled
|
2262 wxPGCellRenderer::DontUseCellFgCol
;
2263 rowFgCol
= m_colDisPropFore
;
2268 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2269 if ( p
== firstSelected
)
2270 wasSelectedPainted
= true;
2273 renderFlags
|= wxPGCellRenderer::Selected
;
2275 if ( !p
->IsCategory() )
2277 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2278 wxPGCellRenderer::DontUseCellBgCol
;
2280 if ( reallyFocused
&& p
== firstSelected
)
2282 rowFgCol
= m_colSelFore
;
2283 rowBgCol
= selBackCol
;
2285 else if ( isPgEnabled
)
2287 rowFgCol
= m_colPropFore
;
2288 if ( p
== firstSelected
)
2289 rowBgCol
= m_colMargin
;
2291 rowBgCol
= selBackCol
;
2295 rowFgCol
= m_colDisPropFore
;
2296 rowBgCol
= selBackCol
;
2303 if ( rowBgCol
.IsOk() )
2304 rowBgBrush
= wxBrush(rowBgCol
);
2306 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2307 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2310 // Fill additional margin area with background colour of first cell
2311 if ( greyDepthX
< textMarginHere
)
2313 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2315 wxPGCell
& cell
= p
->GetCell(0);
2316 rowBgCol
= cell
.GetBgCol();
2317 rowBgBrush
= wxBrush(rowBgCol
);
2319 dc
.SetBrush(rowBgBrush
);
2320 dc
.SetPen(rowBgCol
);
2321 dc
.DrawRectangle(greyDepthX
+1, y
,
2322 textMarginHere
-greyDepthX
, lh
-1);
2325 bool fontChanged
= false;
2327 // Expander button rectangle
2328 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2333 // Default cell rect fill the entire row
2334 wxRect
cellRect(greyDepthX
, y
,
2335 gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2337 bool isCategory
= p
->IsCategory();
2341 dc
.SetFont(m_captionFont
);
2344 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2346 dc
.SetBrush(rowBgBrush
);
2347 dc
.SetPen(rowBgCol
);
2350 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2352 dc
.SetTextForeground(rowFgCol
);
2357 // Fine tune button rectangle to actually fit the cell
2358 if ( butRect
.x
> 0 )
2359 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2361 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&&
2362 (windowStyle
& wxPG_BOLD_MODIFIED
) )
2364 dc
.SetFont(m_captionFont
);
2368 // Magic fine-tuning for non-category rows
2372 int firstCellWidth
= colWidths
[0] - (greyDepthX
- m_marginWidth
);
2373 int firstCellX
= cellRect
.x
;
2375 // Calculate cellRect.x for the last cell
2376 unsigned int ci
= 0;
2378 for ( ci
=0; ci
<colWidths
.size(); ci
++ )
2379 cellX
+= colWidths
[ci
];
2382 // Draw cells from back to front so that we can easily tell if the
2383 // cell on the right was empty from text
2384 bool prevFilled
= true;
2385 ci
= colWidths
.size();
2394 textXAdd
= textMarginHere
- greyDepthX
;
2395 cellRect
.width
= firstCellWidth
;
2396 cellRect
.x
= firstCellX
;
2400 int colWidth
= colWidths
[ci
];
2401 cellRect
.width
= colWidth
;
2402 cellRect
.x
-= colWidth
;
2405 // Merge with column to the right?
2406 if ( !prevFilled
&& isCategory
)
2408 cellRect
.width
+= colWidths
[ci
+1];
2412 cellRect
.width
-= 1;
2414 wxWindow
* cellEditor
= NULL
;
2415 int cellRenderFlags
= renderFlags
;
2417 // Tree Item Button (must be drawn before clipping is set up)
2418 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2419 DrawExpanderButton( dc
, butRect
, p
);
2422 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2424 if ( p
== firstSelected
)
2426 if ( ci
== 1 && m_wndEditor
)
2427 cellEditor
= m_wndEditor
;
2428 else if ( ci
== m_selColumn
&& m_labelEditor
)
2429 cellEditor
= m_labelEditor
;
2434 wxColour editorBgCol
=
2435 cellEditor
->GetBackgroundColour();
2436 dc
.SetBrush(editorBgCol
);
2437 dc
.SetPen(editorBgCol
);
2438 dc
.SetTextForeground(m_colPropFore
);
2439 dc
.DrawRectangle(cellRect
);
2441 if ( m_dragStatus
!= 0 ||
2442 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2447 dc
.SetBrush(m_colPropBack
);
2448 dc
.SetPen(m_colPropBack
);
2449 if ( p
->IsEnabled() )
2450 dc
.SetTextForeground(m_colPropFore
);
2452 dc
.SetTextForeground(m_colDisPropFore
);
2457 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2459 dc
.SetBrush(rowBgBrush
);
2460 dc
.SetPen(rowBgCol
);
2463 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2465 dc
.SetTextForeground(rowFgCol
);
2469 dc
.SetClippingRegion(cellRect
);
2471 cellRect
.x
+= textXAdd
;
2472 cellRect
.width
-= textXAdd
;
2477 wxPGCellRenderer
* renderer
;
2478 int cmnVal
= p
->GetCommonValue();
2479 if ( cmnVal
== -1 || ci
!= 1 )
2481 renderer
= p
->GetCellRenderer(ci
);
2482 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2488 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2489 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2499 dc
.DestroyClippingRegion(); // Is this really necessary?
2504 dc
.SetFont(normalFont
);
2509 // Refresh editor controls (seems not needed on msw)
2510 // NOTE: This code is mandatory for GTK!
2511 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2512 if ( wasSelectedPainted
)
2515 m_wndEditor
->Refresh();
2517 m_wndEditor2
->Refresh();
2524 // -----------------------------------------------------------------------
2526 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2530 if ( m_width
< 10 || m_height
< 10 ||
2531 !m_pState
->m_properties
->GetChildCount() ||
2533 return wxRect(0,0,0,0);
2538 // Return rect which encloses the given property range
2539 // (in logical grid coordinates)
2542 int visTop
= p1
->GetY();
2545 visBottom
= p2
->GetY() + m_lineHeight
;
2547 visBottom
= m_height
+ visTop
;
2549 // If seleced property is inside the range, we'll extend the range to include
2551 wxPGProperty
* selected
= GetSelection();
2554 int selectedY
= selected
->GetY();
2555 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2557 wxWindow
* editor
= GetEditorControl();
2560 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2561 if ( visBottom2
> visBottom
)
2562 visBottom
= visBottom2
;
2567 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2570 // -----------------------------------------------------------------------
2572 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2577 if ( m_pState
->m_itemsAdded
)
2578 PrepareAfterItemsAdded();
2580 wxRect r
= GetPropertyRect(p1
, p2
);
2583 // Convert rectangle from logical grid coordinates to physical ones
2585 GetViewStart(&vx
, &vy
);
2586 vx
*= wxPG_PIXELS_PER_UNIT
;
2587 vy
*= wxPG_PIXELS_PER_UNIT
;
2594 // -----------------------------------------------------------------------
2596 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2598 if ( m_pState
->DoIsPropertySelected(p
) )
2600 // NB: We must copy the selection.
2601 wxArrayPGProperty selection
= m_pState
->m_selection
;
2602 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2605 DrawItemAndChildren(p
);
2608 // -----------------------------------------------------------------------
2610 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2615 // Draw item, children, and parent too, if it is not category
2616 wxPGProperty
* parent
= p
->GetParent();
2619 !parent
->IsCategory() &&
2620 parent
->GetParent() )
2623 parent
= parent
->GetParent();
2626 DrawItemAndChildren(p
);
2629 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2631 wxCHECK_RET( p
, wxT("invalid property id") );
2633 // Do not draw if in non-visible page
2634 if ( p
->GetParentState() != m_pState
)
2637 // do not draw a single item if multiple pending
2638 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2641 // Update child control.
2642 wxPGProperty
* selected
= GetSelection();
2643 if ( selected
&& selected
->GetParent() == p
)
2646 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2648 DrawItems(p
, lastDrawn
);
2651 // -----------------------------------------------------------------------
2653 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2654 const wxRect
*rect
)
2656 PrepareAfterItemsAdded();
2658 wxWindow::Refresh(false, rect
);
2660 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2661 // I think this really helps only GTK+1.2
2662 if ( m_wndEditor
) m_wndEditor
->Refresh();
2663 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2667 // -----------------------------------------------------------------------
2668 // wxPropertyGrid global operations
2669 // -----------------------------------------------------------------------
2671 void wxPropertyGrid::Clear()
2673 m_pState
->DoClear();
2679 RecalculateVirtualSize();
2681 // Need to clear some area at the end
2683 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2686 // -----------------------------------------------------------------------
2688 bool wxPropertyGrid::EnableCategories( bool enable
)
2695 // Enable categories
2698 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2703 // Disable categories
2705 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2708 if ( !m_pState
->EnableCategories(enable
) )
2713 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2715 m_pState
->m_itemsAdded
= 1; // force
2716 PrepareAfterItemsAdded();
2720 m_pState
->m_itemsAdded
= 1;
2722 // No need for RecalculateVirtualSize() here - it is already called in
2723 // wxPropertyGridPageState method above.
2730 // -----------------------------------------------------------------------
2732 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2734 wxASSERT( pNewState
);
2735 wxASSERT( pNewState
->GetGrid() );
2737 if ( pNewState
== m_pState
)
2740 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2742 // Call ClearSelection() instead of DoClearSelection()
2743 // so that selection clear events are not sent.
2746 m_pState
->m_selection
= oldSelection
;
2748 bool orig_mode
= m_pState
->IsInNonCatMode();
2749 bool new_state_mode
= pNewState
->IsInNonCatMode();
2751 m_pState
= pNewState
;
2754 int pgWidth
= GetClientSize().x
;
2755 if ( HasVirtualWidth() )
2757 int minWidth
= pgWidth
;
2758 if ( pNewState
->m_width
< minWidth
)
2760 pNewState
->m_width
= minWidth
;
2761 pNewState
->CheckColumnWidths();
2767 // Just in case, fully re-center splitter
2768 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2769 // pNewState->m_fSplitterX = -1.0;
2771 pNewState
->OnClientWidthChange(pgWidth
,
2772 pgWidth
- pNewState
->m_width
);
2777 // If necessary, convert state to correct mode.
2778 if ( orig_mode
!= new_state_mode
)
2780 // This should refresh as well.
2781 EnableCategories( orig_mode
?false:true );
2783 else if ( !m_frozen
)
2785 // Refresh, if not frozen.
2786 m_pState
->PrepareAfterItemsAdded();
2788 // Reselect (Use SetSelection() instead of Do-variant so that
2789 // events won't be sent).
2790 SetSelection(m_pState
->m_selection
);
2792 RecalculateVirtualSize(0);
2796 m_pState
->m_itemsAdded
= 1;
2799 // -----------------------------------------------------------------------
2801 // Call to SetSplitterPosition will always disable splitter auto-centering
2802 // if parent window is shown.
2803 void wxPropertyGrid::DoSetSplitterPosition( int newxpos
,
2807 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2810 wxPropertyGridPageState
* state
= m_pState
;
2812 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2813 state
->m_dontCenterSplitter
= true;
2815 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2817 if ( flags
& wxPG_SPLITTER_REFRESH
)
2819 if ( GetSelection() )
2820 CorrectEditorWidgetSizeX();
2828 // -----------------------------------------------------------------------
2830 void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing
)
2832 wxPropertyGridPageState
* state
= m_pState
;
2834 state
->ResetColumnSizes(0);
2836 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2837 m_pState
->m_dontCenterSplitter
= false;
2840 // -----------------------------------------------------------------------
2842 void wxPropertyGrid::CenterSplitter( bool enableAutoResizing
)
2844 SetSplitterPosition( m_width
/2 );
2845 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2846 m_pState
->m_dontCenterSplitter
= false;
2849 // -----------------------------------------------------------------------
2850 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2851 // -----------------------------------------------------------------------
2853 // Returns nearest paint visible property (such that will be painted unless
2854 // window is scrolled or resized). If given property is paint visible, then
2855 // it itself will be returned
2856 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2858 int vx
,vy1
;// Top left corner of client
2859 GetViewStart(&vx
,&vy1
);
2860 vy1
*= wxPG_PIXELS_PER_UNIT
;
2862 int vy2
= vy1
+ m_height
;
2863 int propY
= p
->GetY2(m_lineHeight
);
2865 if ( (propY
+ m_lineHeight
) < vy1
)
2868 return DoGetItemAtY( vy1
);
2870 else if ( propY
> vy2
)
2873 return DoGetItemAtY( vy2
);
2876 // Itself paint visible
2881 // -----------------------------------------------------------------------
2882 // Methods related to change in value, value modification and sending events
2883 // -----------------------------------------------------------------------
2885 // commits any changes in editor of selected property
2886 // return true if validation did not fail
2887 // flags are same as with DoSelectProperty
2888 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2890 // Committing already?
2891 if ( m_inCommitChangesFromEditor
)
2894 // Don't do this if already processing editor event. It might
2895 // induce recursive dialogs and crap like that.
2896 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2898 if ( m_inDoPropertyChanged
)
2904 wxPGProperty
* selected
= GetSelection();
2907 IsEditorsValueModified() &&
2908 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2911 m_inCommitChangesFromEditor
= 1;
2913 wxVariant
variant(selected
->GetValueRef());
2914 bool valueIsPending
= false;
2916 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2917 // due to another window getting focus
2918 wxWindow
* oldFocus
= m_curFocused
;
2920 bool validationFailure
= false;
2921 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2923 m_chgInfo_changedProperty
= NULL
;
2925 // If truly modified, schedule value as pending.
2926 if ( selected
->GetEditorClass()->
2927 GetValueFromControl( variant
,
2929 GetEditorControl() ) )
2931 if ( DoEditorValidate() &&
2932 PerformValidation(selected
, variant
) )
2934 valueIsPending
= true;
2938 validationFailure
= true;
2943 EditorsValueWasNotModified();
2948 m_inCommitChangesFromEditor
= 0;
2950 if ( validationFailure
&& !forceSuccess
)
2954 oldFocus
->SetFocus();
2955 m_curFocused
= oldFocus
;
2958 res
= OnValidationFailure(selected
, variant
);
2960 // Now prevent further validation failure messages
2963 EditorsValueWasNotModified();
2964 OnValidationFailureReset(selected
);
2967 else if ( valueIsPending
)
2969 DoPropertyChanged( selected
, flags
);
2970 EditorsValueWasNotModified();
2979 // -----------------------------------------------------------------------
2981 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2985 // Runs all validation functionality.
2986 // Returns true if value passes all tests.
2989 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2992 // Variant list a special value that cannot be validated
2994 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2996 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
3001 // Adapt list to child values, if necessary
3002 wxVariant listValue
= pendingValue
;
3003 wxVariant
* pPendingValue
= &pendingValue
;
3004 wxVariant
* pList
= NULL
;
3006 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
3007 // string value, then we need treat as it was changed instead
3008 // (or, in addition, as is the case with composite string parent).
3009 // This includes creating list variant for child values.
3011 wxPGProperty
* pwc
= p
->GetParent();
3012 wxPGProperty
* changedProperty
= p
;
3013 wxPGProperty
* baseChangedProperty
= changedProperty
;
3014 wxVariant bcpPendingList
;
3016 listValue
= pendingValue
;
3017 listValue
.SetName(p
->GetBaseName());
3020 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
3022 wxVariantList tempList
;
3023 wxVariant
lv(tempList
, pwc
->GetBaseName());
3024 lv
.Append(listValue
);
3026 pPendingValue
= &listValue
;
3028 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
3030 baseChangedProperty
= pwc
;
3031 bcpPendingList
= lv
;
3034 changedProperty
= pwc
;
3035 pwc
= pwc
->GetParent();
3039 wxPGProperty
* evtChangingProperty
= changedProperty
;
3041 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
3043 value
= *pPendingValue
;
3047 // Convert list to child values
3048 pList
= pPendingValue
;
3049 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
3052 wxVariant evtChangingValue
= value
;
3054 if ( flags
& SendEvtChanging
)
3056 // FIXME: After proper ValueToString()s added, remove
3057 // this. It is just a temporary fix, as evt_changing
3058 // will simply not work for wxPG_PROP_COMPOSED_VALUE
3059 // (unless it is selected, and textctrl editor is open).
3060 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3062 evtChangingProperty
= baseChangedProperty
;
3063 if ( evtChangingProperty
!= p
)
3065 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
3069 evtChangingValue
= pendingValue
;
3073 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3075 if ( changedProperty
== GetSelection() )
3077 wxWindow
* editor
= GetEditorControl();
3078 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
3079 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
3083 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
3088 wxASSERT( m_chgInfo_changedProperty
== NULL
);
3089 m_chgInfo_changedProperty
= changedProperty
;
3090 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
3091 m_chgInfo_pendingValue
= value
;
3094 m_chgInfo_valueList
= *pList
;
3096 m_chgInfo_valueList
.MakeNull();
3098 // If changedProperty is not property which value was edited,
3099 // then call wxPGProperty::ValidateValue() for that as well.
3100 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3102 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3106 if ( flags
& SendEvtChanging
)
3108 // SendEvent returns true if event was vetoed
3109 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3110 &evtChangingValue
) )
3114 if ( flags
& IsStandaloneValidation
)
3116 // If called in 'generic' context, we need to reset
3117 // m_chgInfo_changedProperty and write back translated value.
3118 m_chgInfo_changedProperty
= NULL
;
3119 pendingValue
= value
;
3125 // -----------------------------------------------------------------------
3127 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3129 if ( !msg
.length() )
3133 if ( !wxPGGlobalVars
->m_offline
)
3135 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3138 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
3141 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
3144 pStatusBar
->SetStatusText(msg
);
3152 ::wxMessageBox(msg
, wxT("Property Error"));
3155 // -----------------------------------------------------------------------
3157 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3158 wxVariant
& invalidValue
)
3160 wxWindow
* editor
= GetEditorControl();
3162 // First call property's handler
3163 property
->OnValidationFailure(invalidValue
);
3165 bool res
= DoOnValidationFailure(property
, invalidValue
);
3168 // For non-wxTextCtrl editors, we do need to revert the value
3169 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3170 property
== GetSelection() )
3172 property
->GetEditorClass()->UpdateControl(property
, editor
);
3175 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3180 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3182 int vfb
= m_validationInfo
.m_failureBehavior
;
3184 if ( vfb
& wxPG_VFB_BEEP
)
3187 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3188 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3190 unsigned int colCount
= m_pState
->GetColumnCount();
3192 // We need backup marked property's cells
3193 m_propCellsBackup
= property
->m_cells
;
3195 wxColour vfbFg
= *wxWHITE
;
3196 wxColour vfbBg
= *wxRED
;
3198 property
->EnsureCells(colCount
);
3200 for ( unsigned int i
=0; i
<colCount
; i
++ )
3202 wxPGCell
& cell
= property
->m_cells
[i
];
3203 cell
.SetFgCol(vfbFg
);
3204 cell
.SetBgCol(vfbBg
);
3207 DrawItemAndChildren(property
);
3209 if ( property
== GetSelection() )
3211 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3213 wxWindow
* editor
= GetEditorControl();
3216 editor
->SetForegroundColour(vfbFg
);
3217 editor
->SetBackgroundColour(vfbBg
);
3222 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3224 wxString msg
= m_validationInfo
.m_failureMessage
;
3226 if ( !msg
.length() )
3227 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
3229 DoShowPropertyError(property
, msg
);
3232 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3235 // -----------------------------------------------------------------------
3237 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3239 int vfb
= m_validationInfo
.m_failureBehavior
;
3241 if ( vfb
& wxPG_VFB_MARK_CELL
)
3244 property
->m_cells
= m_propCellsBackup
;
3246 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3248 if ( property
== GetSelection() && GetEditorControl() )
3250 // Calling this will recreate the control, thus resetting its colour
3251 RefreshProperty(property
);
3255 DrawItemAndChildren(property
);
3260 // -----------------------------------------------------------------------
3262 // flags are same as with DoSelectProperty
3263 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3265 if ( m_inDoPropertyChanged
)
3268 wxWindow
* editor
= GetEditorControl();
3269 wxPGProperty
* selected
= GetSelection();
3271 m_pState
->m_anyModified
= 1;
3273 m_inDoPropertyChanged
= 1;
3275 // Maybe need to update control
3276 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3278 // These values were calculated in PerformValidation()
3279 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3280 wxVariant value
= m_chgInfo_pendingValue
;
3282 wxPGProperty
* topPaintedProperty
= changedProperty
;
3284 while ( !topPaintedProperty
->IsCategory() &&
3285 !topPaintedProperty
->IsRoot() )
3287 topPaintedProperty
= topPaintedProperty
->GetParent();
3290 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3292 // Set as Modified (not if dragging just began)
3293 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3295 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3296 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3299 SetCurControlBoldFont();
3305 // Propagate updates to parent(s)
3307 wxPGProperty
* prevPwc
= NULL
;
3309 while ( prevPwc
!= topPaintedProperty
)
3311 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3313 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3316 SetCurControlBoldFont();
3320 pwc
= pwc
->GetParent();
3323 // Draw the actual property
3324 DrawItemAndChildren( topPaintedProperty
);
3327 // If value was set by wxPGProperty::OnEvent, then update the editor
3329 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3335 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3336 if ( m_wndEditor
) m_wndEditor
->Refresh();
3337 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3342 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3344 // If top parent has composite string value, then send to child parents,
3345 // starting from baseChangedProperty.
3346 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3348 pwc
= m_chgInfo_baseChangedProperty
;
3350 while ( pwc
!= changedProperty
)
3352 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3353 pwc
= pwc
->GetParent();
3357 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3359 m_inDoPropertyChanged
= 0;
3364 // -----------------------------------------------------------------------
3366 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3368 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3370 m_chgInfo_changedProperty
= NULL
;
3372 if ( PerformValidation(p
, newValue
) )
3374 DoPropertyChanged(p
);
3379 OnValidationFailure(p
, newValue
);
3385 // -----------------------------------------------------------------------
3387 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3389 wxPGProperty
* prop
= GetSelectedProperty();
3392 return wxNullVariant
;
3394 wxTextCtrl
* tc
= GetEditorTextCtrl();
3395 wxVariant value
= prop
->GetValue();
3397 if ( !tc
|| !IsEditorsValueModified() )
3400 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3403 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3404 return prop
->GetValue();
3409 // -----------------------------------------------------------------------
3411 // Runs wxValidator for the selected property
3412 bool wxPropertyGrid::DoEditorValidate()
3417 // -----------------------------------------------------------------------
3419 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3421 // It is possible that this handler receives event even before
3422 // the control has been properly initialized. Let's skip the
3423 // event handling in that case.
3427 // Don't care about the event if it originated from the
3428 // 'label editor'. In this function we only care about the
3429 // property value editor.
3430 if ( m_labelEditor
&& event
.GetId() == m_labelEditor
->GetId() )
3436 wxPGProperty
* selected
= GetSelection();
3438 // Somehow, event is handled after property has been deselected.
3439 // Possibly, but very rare.
3441 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3442 // Also don't handle editor event if wxEVT_PG_CHANGED or
3443 // similar is currently doing something (showing a
3444 // message box, for instance).
3448 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3451 wxVariant
pendingValue(selected
->GetValueRef());
3452 wxWindow
* wnd
= GetEditorControl();
3453 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3455 bool wasUnspecified
= selected
->IsValueUnspecified();
3456 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3457 bool valueIsPending
= false;
3459 m_chgInfo_changedProperty
= NULL
;
3461 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3464 // Filter out excess wxTextCtrl modified events
3465 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&& wnd
)
3467 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3469 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3471 wxString newTcValue
= tc
->GetValue();
3472 if ( m_prevTcValue
== newTcValue
)
3474 m_prevTcValue
= newTcValue
;
3476 else if ( wnd
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
3478 wxComboCtrl
* cc
= (wxComboCtrl
*) wnd
;
3480 wxString newTcValue
= cc
->GetTextCtrl()->GetValue();
3481 if ( m_prevTcValue
== newTcValue
)
3483 m_prevTcValue
= newTcValue
;
3487 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3489 bool validationFailure
= false;
3490 bool buttonWasHandled
= false;
3493 // Try common button handling
3494 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3496 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3500 buttonWasHandled
= true;
3501 // Store as res2, as previously (and still currently alternatively)
3502 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3503 // in wxPGProperty::OnEvent().
3504 adapter
->ShowDialog( this, selected
);
3509 if ( !buttonWasHandled
)
3511 if ( wnd
|| m_wndEditor2
)
3513 // First call editor class' event handler.
3514 const wxPGEditor
* editor
= selected
->GetEditorClass();
3516 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3518 // If changes, validate them
3519 if ( DoEditorValidate() )
3521 if ( editor
->GetValueFromControl( pendingValue
,
3524 valueIsPending
= true;
3528 validationFailure
= true;
3533 // Then the property's custom handler (must be always called, unless
3534 // validation failed).
3535 if ( !validationFailure
)
3536 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3539 // SetValueInEvent(), as called in one of the functions referred above
3540 // overrides editor's value.
3541 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3543 valueIsPending
= true;
3544 pendingValue
= m_changeInEventValue
;
3545 selFlags
|= wxPG_SEL_DIALOGVAL
;
3548 if ( !validationFailure
&& valueIsPending
)
3549 if ( !PerformValidation(selected
, pendingValue
) )
3550 validationFailure
= true;
3552 if ( validationFailure
)
3554 OnValidationFailure(selected
, pendingValue
);
3556 else if ( valueIsPending
)
3558 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3560 DoPropertyChanged(selected
, selFlags
);
3561 EditorsValueWasNotModified();
3563 // Regardless of editor type, unfocus editor on
3564 // text-editing related enter press.
3565 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3572 // No value after all
3574 // Regardless of editor type, unfocus editor on
3575 // text-editing related enter press.
3576 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3581 // Let unhandled button click events go to the parent
3582 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3584 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3585 GetEventHandler()->AddPendingEvent(evt
);
3589 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3592 // -----------------------------------------------------------------------
3593 // wxPropertyGrid editor control helper methods
3594 // -----------------------------------------------------------------------
3596 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3598 int itemy
= p
->GetY2(m_lineHeight
);
3599 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3600 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3601 int imageOffset
= 0;
3603 int vx
, vy
; // Top left corner of client
3604 GetViewStart(&vx
, &vy
);
3605 vy
*= wxPG_PIXELS_PER_UNIT
;
3609 // TODO: If custom image detection changes from current, change this.
3610 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3612 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3613 int iw
= p
->OnMeasureImage().x
;
3615 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3616 imageOffset
= p
->GetImageOffset(iw
);
3619 else if ( column
== 0 )
3621 splitterX
+= (p
->m_depth
- 1) * m_subgroup_extramargin
;
3626 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3628 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3633 // -----------------------------------------------------------------------
3635 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3637 wxSize sz
= GetImageSize(p
, item
);
3638 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3639 wxPG_CUSTOM_IMAGE_SPACINGY
,
3644 // return size of custom paint image
3645 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3647 // If called with NULL property, then return default image
3648 // size for properties that use image.
3650 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3652 wxSize cis
= p
->OnMeasureImage(item
);
3654 int choiceCount
= p
->m_choices
.GetCount();
3655 int comVals
= p
->GetDisplayedCommonValueCount();
3656 if ( item
>= choiceCount
&& comVals
> 0 )
3658 unsigned int cvi
= item
-choiceCount
;
3659 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3661 else if ( item
>= 0 && choiceCount
== 0 )
3662 return wxSize(0, 0);
3667 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3672 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3679 // -----------------------------------------------------------------------
3681 // takes scrolling into account
3682 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3685 GetViewStart(&vx
,&vy
);
3686 vy
*=wxPG_PIXELS_PER_UNIT
;
3687 vx
*=wxPG_PIXELS_PER_UNIT
;
3690 ClientToScreen( px
, py
);
3693 // -----------------------------------------------------------------------
3695 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3698 GetViewStart(&pt2
.x
,&pt2
.y
);
3699 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3700 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3704 return m_pState
->HitTest(pt2
);
3707 // -----------------------------------------------------------------------
3709 // custom set cursor
3710 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3712 if ( type
== m_curcursor
&& !override
) return;
3714 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3716 if ( type
== wxCURSOR_SIZEWE
)
3717 cursor
= m_cursorSizeWE
;
3719 SetCursor( *cursor
);
3724 // -----------------------------------------------------------------------
3727 wxPropertyGrid::GetUnspecifiedValueText( int argFlags
) const
3729 const wxPGCell
& ua
= GetUnspecifiedValueAppearance();
3731 if ( ua
.HasText() &&
3732 !(argFlags
& wxPG_FULL_VALUE
) &&
3733 !(argFlags
& wxPG_EDITABLE_VALUE
) )
3734 return ua
.GetText();
3736 return wxEmptyString
;
3739 // -----------------------------------------------------------------------
3740 // wxPropertyGrid property selection, editor creation
3741 // -----------------------------------------------------------------------
3744 // This class forwards events from property editor controls to wxPropertyGrid.
3745 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3748 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3749 : wxEvtHandler(), m_propGrid(propGrid
)
3753 virtual ~wxPropertyGridEditorEventForwarder()
3758 bool ProcessEvent( wxEvent
& event
)
3763 m_propGrid
->HandleCustomEditorEvent(event
);
3766 // NB: On wxMSW, a wxTextCtrl with wxTE_PROCESS_ENTER
3767 // may beep annoyingly if that event is skipped
3768 // and passed to parent event handler.
3769 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3772 return wxEvtHandler::ProcessEvent(event
);
3775 wxPropertyGrid
* m_propGrid
;
3778 // Setups event handling for child control
3779 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3781 wxWindowID id
= argWnd
->GetId();
3783 if ( argWnd
== m_wndEditor
)
3785 argWnd
->Connect(id
, wxEVT_MOTION
,
3786 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3788 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3789 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3791 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3792 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3794 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3795 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3797 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3798 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3800 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3801 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3805 wxPropertyGridEditorEventForwarder
* forwarder
;
3806 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3807 argWnd
->PushEventHandler(forwarder
);
3809 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3810 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3814 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3821 // Do not free editors immediately (for sake of processing events)
3822 wxPendingDelete
.Append(wnd
);
3825 void wxPropertyGrid::FreeEditors()
3828 // Return focus back to canvas from children (this is required at least for
3829 // GTK+, which, unlike Windows, clears focus when control is destroyed
3830 // instead of moving it to closest parent).
3831 wxWindow
* focus
= wxWindow::FindFocus();
3834 wxWindow
* parent
= focus
->GetParent();
3837 if ( parent
== this )
3842 parent
= parent
->GetParent();
3846 // Do not free editors immediately if processing events
3849 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3850 m_wndEditor2
->Hide();
3851 wxPendingDelete
.Append( handler
);
3852 DestroyEditorWnd(m_wndEditor2
);
3853 m_wndEditor2
= NULL
;
3858 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3859 m_wndEditor
->Hide();
3860 wxPendingDelete
.Append( handler
);
3861 DestroyEditorWnd(m_wndEditor
);
3866 // Call with NULL to de-select property
3867 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3872 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3873 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3877 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3881 if ( m_inDoSelectProperty
)
3884 m_inDoSelectProperty
= 1;
3888 m_inDoSelectProperty
= 0;
3892 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3893 wxPGProperty
* prevFirstSel
;
3895 if ( prevSelection
.size() > 0 )
3896 prevFirstSel
= prevSelection
[0];
3898 prevFirstSel
= NULL
;
3900 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3901 prevFirstSel
= NULL
;
3903 // Always send event, as this is indirect call
3904 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
3908 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3910 wxPrintf( "None selected\n" );
3913 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3915 wxPrintf( "P = NULL\n" );
3918 // If we are frozen, then just set the values.
3921 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3922 m_editorFocused
= 0;
3923 m_pState
->DoSetSelection(p
);
3925 // If frozen, always free controls. But don't worry, as Thaw will
3926 // recall SelectProperty to recreate them.
3929 // Prevent any further selection measures in this call
3935 if ( prevFirstSel
== p
&&
3936 prevSelection
.size() <= 1 &&
3937 !(flags
& wxPG_SEL_FORCE
) )
3939 // Only set focus if not deselecting
3942 if ( flags
& wxPG_SEL_FOCUS
)
3946 m_wndEditor
->SetFocus();
3947 m_editorFocused
= 1;
3956 m_inDoSelectProperty
= 0;
3961 // First, deactivate previous
3964 OnValidationFailureReset(prevFirstSel
);
3966 // Must double-check if this is an selected in case of forceswitch
3967 if ( p
!= prevFirstSel
)
3969 if ( !CommitChangesFromEditor(flags
) )
3971 // Validation has failed, so we can't exit the previous editor
3972 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3973 // _("Invalid Value"),wxOK|wxICON_ERROR);
3974 m_inDoSelectProperty
= 0;
3981 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3982 EditorsValueWasNotModified();
3985 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3987 m_pState
->DoSetSelection(p
);
3989 // Redraw unselected
3990 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
3992 DrawItem(prevSelection
[i
]);
3996 // Then, activate the one given.
3999 int propY
= p
->GetY2(m_lineHeight
);
4001 int splitterX
= GetSplitterPosition();
4002 m_editorFocused
= 0;
4003 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
4004 if ( p
!= prevFirstSel
)
4005 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
4007 wxASSERT( m_wndEditor
== NULL
);
4010 // Only create editor for non-disabled non-caption
4011 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
4013 // do this for non-caption items
4017 // Do we need to paint the custom image, if any?
4018 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
4019 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
4020 !p
->GetEditorClass()->CanContainCustomImage()
4022 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
4024 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
4025 wxPoint goodPos
= grect
.GetPosition();
4027 // Editor appearance can now be considered clear
4028 m_editorAppearance
.SetEmptyData();
4030 const wxPGEditor
* editor
= p
->GetEditorClass();
4031 wxCHECK_MSG(editor
, false,
4032 wxT("NULL editor class not allowed"));
4034 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
4036 wxPGWindowList wndList
=
4037 editor
->CreateControls(this,
4042 m_wndEditor
= wndList
.m_primary
;
4043 m_wndEditor2
= wndList
.m_secondary
;
4044 wxWindow
* primaryCtrl
= GetEditorControl();
4047 // Essentially, primaryCtrl == m_wndEditor
4050 // NOTE: It is allowed for m_wndEditor to be NULL - in this
4051 // case value is drawn as normal, and m_wndEditor2 is
4052 // assumed to be a right-aligned button that triggers
4053 // a separate editorCtrl window.
4057 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
4058 "CreateControls must use result of "
4059 "wxPropertyGrid::GetPanel() as parent "
4062 // Set validator, if any
4063 #if wxUSE_VALIDATORS
4064 wxValidator
* validator
= p
->GetValidator();
4066 primaryCtrl
->SetValidator(*validator
);
4069 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
4070 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
4072 // If it has modified status, use bold font
4073 // (must be done before capturing m_ctrlXAdjust)
4074 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
4075 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
4076 SetCurControlBoldFont();
4078 // Store x relative to splitter (we'll need it).
4079 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
4081 // Check if background clear is not necessary
4082 wxPoint pos
= m_wndEditor
->GetPosition();
4083 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
4085 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
4088 m_wndEditor
->SetSizeHints(3, 3);
4090 SetupChildEventHandling(primaryCtrl
);
4092 // Focus and select all (wxTextCtrl, wxComboBox etc)
4093 if ( flags
& wxPG_SEL_FOCUS
)
4095 primaryCtrl
->SetFocus();
4097 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
4101 if ( p
->IsValueUnspecified() )
4102 SetEditorAppearance(m_unspecifiedAppearance
,
4109 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
4110 "CreateControls must use result of "
4111 "wxPropertyGrid::GetPanel() as parent "
4114 // Get proper id for wndSecondary
4115 m_wndSecId
= m_wndEditor2
->GetId();
4116 wxWindowList children
= m_wndEditor2
->GetChildren();
4117 wxWindowList::iterator node
= children
.begin();
4118 if ( node
!= children
.end() )
4119 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
4121 m_wndEditor2
->SetSizeHints(3,3);
4123 m_wndEditor2
->Show();
4125 SetupChildEventHandling(m_wndEditor2
);
4127 // If no primary editor, focus to button to allow
4128 // it to interprete ENTER etc.
4129 // NOTE: Due to problems focusing away from it, this
4130 // has been disabled.
4132 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
4133 m_wndEditor2->SetFocus();
4137 if ( flags
& wxPG_SEL_FOCUS
)
4138 m_editorFocused
= 1;
4143 // Make sure focus is in grid canvas (important for wxGTK,
4148 EditorsValueWasNotModified();
4150 // If it's inside collapsed section, expand parent, scroll, etc.
4151 // Also, if it was partially visible, scroll it into view.
4152 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
4157 m_wndEditor
->Show(true);
4160 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
4165 // Make sure focus is in grid canvas
4169 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4175 // Show help text in status bar.
4176 // (if found and grid not embedded in manager with help box and
4177 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4180 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4182 wxStatusBar
* statusbar
= NULL
;
4183 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
4185 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
4187 statusbar
= frame
->GetStatusBar();
4192 const wxString
* pHelpString
= (const wxString
*) NULL
;
4196 pHelpString
= &p
->GetHelpString();
4197 if ( pHelpString
->length() )
4199 // Set help box text.
4200 statusbar
->SetStatusText( *pHelpString
);
4201 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4205 if ( (!pHelpString
|| !pHelpString
->length()) &&
4206 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
4208 // Clear help box - but only if it was written
4209 // by us at previous time.
4210 statusbar
->SetStatusText( m_emptyString
);
4211 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4217 m_inDoSelectProperty
= 0;
4219 // call wx event handler (here so that it also occurs on deselection)
4220 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4221 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4226 // -----------------------------------------------------------------------
4228 bool wxPropertyGrid::UnfocusEditor()
4230 wxPGProperty
* selected
= GetSelection();
4232 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4235 if ( !CommitChangesFromEditor(0) )
4244 // -----------------------------------------------------------------------
4246 void wxPropertyGrid::RefreshEditor()
4248 wxPGProperty
* p
= GetSelection();
4252 wxWindow
* wnd
= GetEditorControl();
4256 // Set editor font boldness - must do this before
4257 // calling UpdateControl().
4258 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4260 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4261 wnd
->SetFont(GetCaptionFont());
4263 wnd
->SetFont(GetFont());
4266 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4268 editorClass
->UpdateControl(p
, wnd
);
4270 if ( p
->IsValueUnspecified() )
4271 SetEditorAppearance(m_unspecifiedAppearance
, true);
4274 // -----------------------------------------------------------------------
4276 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4278 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4280 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4282 flags
|= wxPG_SEL_FOCUS
;
4284 return DoSelectProperty(p
, flags
);
4287 // -----------------------------------------------------------------------
4288 // wxPropertyGrid expand/collapse state
4289 // -----------------------------------------------------------------------
4291 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4293 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4294 wxPGProperty
* selected
= GetSelection();
4296 // If active editor was inside collapsed section, then disable it
4297 if ( selected
&& selected
->IsSomeParent(p
) )
4302 // Store dont-center-splitter flag 'cause we need to temporarily set it
4303 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4304 m_pState
->m_dontCenterSplitter
= true;
4306 bool res
= m_pState
->DoCollapse(pwc
);
4311 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4313 RecalculateVirtualSize();
4317 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4322 // -----------------------------------------------------------------------
4324 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4326 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4328 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4330 // Store dont-center-splitter flag 'cause we need to temporarily set it
4331 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4332 m_pState
->m_dontCenterSplitter
= true;
4334 bool res
= m_pState
->DoExpand(pwc
);
4339 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4341 RecalculateVirtualSize();
4345 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4350 // -----------------------------------------------------------------------
4352 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4355 return m_pState
->DoHideProperty(p
, hide
, flags
);
4357 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4358 int selRemoveCount
= 0;
4359 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4361 wxPGProperty
* selected
= selection
[i
];
4362 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4364 if ( !DoRemoveFromSelection(p
, flags
) )
4366 selRemoveCount
+= 1;
4370 m_pState
->DoHideProperty(p
, hide
, flags
);
4372 RecalculateVirtualSize();
4379 // -----------------------------------------------------------------------
4380 // wxPropertyGrid size related methods
4381 // -----------------------------------------------------------------------
4383 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4385 // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise
4386 // virtual size calculation may go wrong.
4387 if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4393 // If virtual height was changed, then recalculate editor control position(s)
4394 if ( m_pState
->m_vhCalcPending
)
4395 CorrectEditorWidgetPosY();
4397 m_pState
->EnsureVirtualHeight();
4399 wxASSERT_LEVEL_2_MSG(
4400 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4401 "VirtualHeight and ActualVirtualHeight should match"
4404 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4406 int x
= m_pState
->m_width
;
4407 int y
= m_pState
->m_virtualHeight
;
4410 GetClientSize(&width
,&height
);
4412 // Now adjust virtual size.
4413 SetVirtualSize(x
, y
);
4419 // Adjust scrollbars
4420 if ( HasVirtualWidth() )
4422 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4423 xPos
= GetScrollPos( wxHORIZONTAL
);
4426 if ( forceXPos
!= -1 )
4429 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4432 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4433 int yPos
= GetScrollPos( wxVERTICAL
);
4435 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4436 xAmount
, yAmount
, xPos
, yPos
, true );
4438 // Must re-get size now
4439 GetClientSize(&width
,&height
);
4441 if ( !HasVirtualWidth() )
4443 m_pState
->SetVirtualWidth(width
);
4450 m_pState
->CheckColumnWidths();
4452 if ( GetSelection() )
4453 CorrectEditorWidgetSizeX();
4455 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4458 // -----------------------------------------------------------------------
4460 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4462 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4466 GetClientSize(&width
, &height
);
4471 #if wxPG_DOUBLE_BUFFER
4472 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4474 int dblh
= (m_lineHeight
*2);
4475 if ( !m_doubleBuffer
)
4477 // Create double buffer bitmap to draw on, if none
4478 int w
= (width
>250)?width
:250;
4479 int h
= height
+ dblh
;
4481 m_doubleBuffer
= new wxBitmap( w
, h
);
4485 int w
= m_doubleBuffer
->GetWidth();
4486 int h
= m_doubleBuffer
->GetHeight();
4488 // Double buffer must be large enough
4489 if ( w
< width
|| h
< (height
+dblh
) )
4491 if ( w
< width
) w
= width
;
4492 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4493 delete m_doubleBuffer
;
4494 m_doubleBuffer
= new wxBitmap( w
, h
);
4501 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4502 m_ncWidth
= event
.GetSize().x
;
4506 if ( m_pState
->m_itemsAdded
)
4507 PrepareAfterItemsAdded();
4509 // Without this, virtual size (atleast under wxGTK) will be skewed
4510 RecalculateVirtualSize();
4516 // -----------------------------------------------------------------------
4518 void wxPropertyGrid::SetVirtualWidth( int width
)
4522 // Disable virtual width
4523 width
= GetClientSize().x
;
4524 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4528 // Enable virtual width
4529 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4531 m_pState
->SetVirtualWidth( width
);
4534 void wxPropertyGrid::SetFocusOnCanvas()
4536 SetFocusIgnoringChildren();
4537 m_editorFocused
= 0;
4540 // -----------------------------------------------------------------------
4541 // wxPropertyGrid mouse event handling
4542 // -----------------------------------------------------------------------
4544 // selFlags uses same values DoSelectProperty's flags
4545 // Returns true if event was vetoed.
4546 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4548 unsigned int selFlags
,
4549 unsigned int column
)
4551 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4554 // Send property grid event of specific type and with specific property
4555 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4556 evt
.SetPropertyGrid(this);
4557 evt
.SetEventObject(m_eventObject
);
4559 evt
.SetColumn(column
);
4560 if ( eventType
== wxEVT_PG_CHANGING
)
4563 evt
.SetCanVeto(true);
4564 m_validationInfo
.m_pValue
= pValue
;
4565 evt
.SetupValidationInfo();
4570 evt
.SetPropertyValue(p
->GetValue());
4572 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4573 evt
.SetCanVeto(true);
4576 wxPropertyGridEvent
* prevProcessedEvent
= m_processedEvent
;
4577 m_processedEvent
= &evt
;
4578 m_eventObject
->HandleWindowEvent(evt
);
4579 m_processedEvent
= prevProcessedEvent
;
4581 return evt
.WasVetoed();
4584 // -----------------------------------------------------------------------
4586 // Return false if should be skipped
4587 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4591 // Need to set focus?
4592 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4597 wxPropertyGridPageState
* state
= m_pState
;
4599 int splitterHitOffset
;
4600 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4602 wxPGProperty
* p
= DoGetItemAtY(y
);
4606 int depth
= (int)p
->GetDepth() - 1;
4608 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4610 if ( x
>= marginEnds
)
4614 if ( p
->IsCategory() )
4616 // This is category.
4617 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4619 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4621 // Expand, collapse, activate etc. if click on text or left of splitter.
4624 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4629 if ( !AddToSelectionFromInputEvent( p
,
4634 // On double-click, expand/collapse.
4635 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4637 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4638 else DoExpand( p
, true );
4642 else if ( splitterHit
== -1 )
4645 unsigned int selFlag
= 0;
4646 if ( columnHit
== 1 )
4648 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4649 selFlag
= wxPG_SEL_FOCUS
;
4651 if ( !AddToSelectionFromInputEvent( p
,
4657 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4659 if ( p
->GetChildCount() && !p
->IsCategory() )
4660 // On double-click, expand/collapse.
4661 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4663 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4664 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4665 else DoExpand( p
, true );
4672 // click on splitter
4673 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4675 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4677 // Double-clicking the splitter causes auto-centering
4678 if ( m_pState
->GetColumnCount() <= 2 )
4680 ResetColumnSizes( true );
4682 SendEvent(wxEVT_PG_COL_DRAGGING
,
4685 wxPG_SEL_NOVALIDATE
,
4686 (unsigned int)m_draggedSplitter
);
4689 else if ( m_dragStatus
== 0 )
4692 // Begin draggin the splitter
4696 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4698 // Allow application to veto dragging
4699 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4701 (unsigned int)splitterHit
) )
4705 // Changes must be committed here or the
4706 // value won't be drawn correctly
4707 if ( !CommitChangesFromEditor() )
4710 m_wndEditor
->Show ( false );
4713 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4716 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4720 m_draggedSplitter
= splitterHit
;
4721 m_dragOffset
= splitterHitOffset
;
4723 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4724 // Fixes button disappearance bug
4726 m_wndEditor2
->Show ( false );
4729 m_startingSplitterX
= x
- splitterHitOffset
;
4738 if ( p
->GetChildCount() )
4740 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4742 // Fine tune cell button x
4743 if ( !p
->IsCategory() )
4744 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4746 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4748 int y2
= y
% m_lineHeight
;
4749 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4751 // On click on expander button, expand/collapse
4752 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4753 DoCollapse( p
, true );
4755 DoExpand( p
, true );
4764 // -----------------------------------------------------------------------
4766 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4767 unsigned int WXUNUSED(y
),
4768 wxMouseEvent
& event
)
4772 // Select property here as well
4773 wxPGProperty
* p
= m_propHover
;
4774 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4776 // Send right click event.
4777 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4784 // -----------------------------------------------------------------------
4786 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4787 unsigned int WXUNUSED(y
),
4788 wxMouseEvent
& event
)
4792 // Select property here as well
4793 wxPGProperty
* p
= m_propHover
;
4795 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4797 // Send double-click event.
4798 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4805 // -----------------------------------------------------------------------
4807 #if wxPG_SUPPORT_TOOLTIPS
4809 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4811 if ( tipString
.length() )
4813 wxScrolledWindow::SetToolTip(tipString
);
4817 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4818 wxScrolledWindow::SetToolTip( m_emptyString
);
4820 wxScrolledWindow::SetToolTip( NULL
);
4825 #endif // #if wxPG_SUPPORT_TOOLTIPS
4827 // -----------------------------------------------------------------------
4829 // Return false if should be skipped
4830 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
,
4831 wxMouseEvent
&event
)
4833 // Safety check (needed because mouse capturing may
4834 // otherwise freeze the control)
4835 if ( m_dragStatus
> 0 && !event
.Dragging() )
4837 HandleMouseUp(x
, y
, event
);
4840 wxPropertyGridPageState
* state
= m_pState
;
4842 int splitterHitOffset
;
4843 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4844 int splitterX
= x
- splitterHitOffset
;
4846 m_colHover
= columnHit
;
4848 if ( m_dragStatus
> 0 )
4850 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4851 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4854 int newSplitterX
= x
- m_dragOffset
;
4856 // Splitter redraw required?
4857 if ( newSplitterX
!= splitterX
)
4860 DoSetSplitterPosition(newSplitterX
,
4862 wxPG_SPLITTER_REFRESH
|
4863 wxPG_SPLITTER_FROM_EVENT
);
4865 SendEvent(wxEVT_PG_COL_DRAGGING
,
4868 wxPG_SEL_NOVALIDATE
,
4869 (unsigned int)m_draggedSplitter
);
4880 int ih
= m_lineHeight
;
4883 #if wxPG_SUPPORT_TOOLTIPS
4884 wxPGProperty
* prevHover
= m_propHover
;
4885 unsigned char prevSide
= m_mouseSide
;
4887 int curPropHoverY
= y
- (y
% ih
);
4889 // On which item it hovers
4892 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4895 // Mouse moves on another property
4897 m_propHover
= DoGetItemAtY(y
);
4898 m_propHoverY
= curPropHoverY
;
4901 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4904 #if wxPG_SUPPORT_TOOLTIPS
4905 // Store which side we are on
4907 if ( columnHit
== 1 )
4909 else if ( columnHit
== 0 )
4913 // If tooltips are enabled, show label or value as a tip
4914 // in case it doesn't otherwise show in full length.
4916 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4918 wxToolTip
* tooltip
= GetToolTip();
4920 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4922 if ( m_propHover
&& !m_propHover
->IsCategory() )
4925 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4927 // Show help string as a tooltip
4928 wxString tipString
= m_propHover
->GetHelpString();
4930 SetToolTip(tipString
);
4934 // Show cropped value string as a tooltip
4938 if ( m_mouseSide
== 1 )
4940 tipString
= m_propHover
->m_label
;
4941 space
= splitterX
-m_marginWidth
-3;
4943 else if ( m_mouseSide
== 2 )
4945 tipString
= m_propHover
->GetDisplayedString();
4947 space
= m_width
- splitterX
;
4948 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4949 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+
4950 wxCC_CUSTOM_IMAGE_MARGIN1
+
4951 wxCC_CUSTOM_IMAGE_MARGIN2
;
4957 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4960 SetToolTip( tipString
);
4967 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4968 SetToolTip( m_emptyString
);
4970 wxScrolledWindow::SetToolTip( NULL
);
4981 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4982 SetToolTip( m_emptyString
);
4984 wxScrolledWindow::SetToolTip( NULL
);
4992 if ( splitterHit
== -1 ||
4994 HasFlag(wxPG_STATIC_SPLITTER
) )
4996 // hovering on something else
4997 if ( m_curcursor
!= wxCURSOR_ARROW
)
4998 CustomSetCursor( wxCURSOR_ARROW
);
5002 // Do not allow splitter cursor on caption items.
5003 // (also not if we were dragging and its started
5004 // outside the splitter region)
5006 if ( !m_propHover
->IsCategory() &&
5010 // hovering on splitter
5012 // NB: Condition disabled since MouseLeave event (from the
5013 // editor control) cannot be reliably detected.
5014 //if ( m_curcursor != wxCURSOR_SIZEWE )
5015 CustomSetCursor( wxCURSOR_SIZEWE
, true );
5021 // hovering on something else
5022 if ( m_curcursor
!= wxCURSOR_ARROW
)
5023 CustomSetCursor( wxCURSOR_ARROW
);
5028 // Multi select by dragging
5030 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
5031 event
.LeftIsDown() &&
5035 !state
->DoIsPropertySelected(m_propHover
) )
5037 // Additional requirement is that the hovered property
5038 // is adjacent to edges of selection.
5039 const wxArrayPGProperty
& selection
= GetSelectedProperties();
5041 // Since categories cannot be selected along with 'other'
5042 // properties, exclude them from iterator flags.
5043 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
5045 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
5047 // TODO: This could be optimized by keeping track of
5048 // which properties are at the edges of selection.
5049 wxPGProperty
* selProp
= selection
[i
];
5050 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
5053 DoAddToSelection(m_propHover
);
5062 // -----------------------------------------------------------------------
5064 // Also handles Leaving event
5065 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
5066 wxMouseEvent
&WXUNUSED(event
) )
5068 wxPropertyGridPageState
* state
= m_pState
;
5072 int splitterHitOffset
;
5073 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
5075 // No event type check - basicly calling this method should
5076 // just stop dragging.
5077 // Left up after dragged?
5078 if ( m_dragStatus
>= 1 )
5081 // End Splitter Dragging
5083 // DO NOT ENABLE FOLLOWING LINE!
5084 // (it is only here as a reminder to not to do it)
5087 SendEvent(wxEVT_PG_COL_END_DRAG
,
5090 wxPG_SEL_NOVALIDATE
,
5091 (unsigned int)m_draggedSplitter
);
5093 // Disable splitter auto-centering (but only if moved any -
5094 // otherwise we end up disabling auto-center even after a
5095 // recentering double-click).
5096 int posDiff
= abs(m_startingSplitterX
-
5097 GetSplitterPosition(m_draggedSplitter
));
5100 state
->m_dontCenterSplitter
= true;
5102 // This is necessary to return cursor
5103 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5106 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5109 // Set back the default cursor, if necessary
5110 if ( splitterHit
== -1 ||
5113 CustomSetCursor( wxCURSOR_ARROW
);
5118 // Control background needs to be cleared
5119 wxPGProperty
* selected
= GetSelection();
5120 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
5121 DrawItem( selected
);
5125 m_wndEditor
->Show ( true );
5128 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
5129 // Fixes button disappearance bug
5131 m_wndEditor2
->Show ( true );
5134 // This clears the focus.
5135 m_editorFocused
= 0;
5141 // -----------------------------------------------------------------------
5143 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
5145 int splitterX
= GetSplitterPosition();
5148 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
5150 wxWindow
* wnd
= GetEditorControl();
5152 // Hide popup on clicks
5153 if ( event
.GetEventType() != wxEVT_MOTION
)
5154 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5156 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
5162 if ( wnd
== NULL
|| m_dragStatus
||
5164 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
5165 ux
>= (r
.x
+r
.width
) ||
5167 event
.m_y
>= (r
.y
+r
.height
)
5177 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5182 // -----------------------------------------------------------------------
5184 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
5187 if ( OnMouseCommon( event
, &x
, &y
) )
5189 HandleMouseClick(x
,y
,event
);
5194 // -----------------------------------------------------------------------
5196 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5199 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5200 HandleMouseRightClick(x
,y
,event
);
5204 // -----------------------------------------------------------------------
5206 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5208 // Always run standard mouse-down handler as well
5209 OnMouseClick(event
);
5212 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5213 HandleMouseDoubleClick(x
,y
,event
);
5217 // -----------------------------------------------------------------------
5219 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5222 if ( OnMouseCommon( event
, &x
, &y
) )
5224 HandleMouseMove(x
,y
,event
);
5229 // -----------------------------------------------------------------------
5231 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5234 if ( OnMouseCommon( event
, &x
, &y
) )
5236 HandleMouseUp(x
,y
,event
);
5241 // -----------------------------------------------------------------------
5243 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5245 // This may get called from child control as well, so event's
5246 // mouse position cannot be relied on.
5248 if ( event
.Entering() )
5250 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5252 // TODO: Fix this (detect parent and only do
5253 // cursor trick if it is a manager).
5254 wxASSERT( GetParent() );
5255 GetParent()->SetCursor(wxNullCursor
);
5257 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5260 GetParent()->SetCursor(wxNullCursor
);
5262 else if ( event
.Leaving() )
5264 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5265 SetCursor( wxNullCursor
);
5267 // Get real cursor position
5268 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5270 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5273 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5275 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5279 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5287 // -----------------------------------------------------------------------
5289 // Common code used by various OnMouseXXXChild methods.
5290 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5292 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5293 wxASSERT( topCtrlWnd
);
5295 event
.GetPosition(&x
,&y
);
5297 int splitterX
= GetSplitterPosition();
5299 wxRect r
= topCtrlWnd
->GetRect();
5300 if ( !m_dragStatus
&&
5301 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5302 y
>= 0 && y
< r
.height \
5305 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5310 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5317 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5320 if ( OnMouseChildCommon(event
,&x
,&y
) )
5322 bool res
= HandleMouseClick(x
,y
,event
);
5323 if ( !res
) event
.Skip();
5327 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5330 wxASSERT( m_wndEditor
);
5331 // These coords may not be exact (about +-2),
5332 // but that should not matter (right click is about item, not position).
5333 wxPoint pt
= m_wndEditor
->GetPosition();
5334 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5336 // FIXME: Used to set m_propHover to selection here. Was it really
5339 bool res
= HandleMouseRightClick(x
,y
,event
);
5340 if ( !res
) event
.Skip();
5343 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5346 if ( OnMouseChildCommon(event
,&x
,&y
) )
5348 bool res
= HandleMouseMove(x
,y
,event
);
5349 if ( !res
) event
.Skip();
5353 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5356 if ( OnMouseChildCommon(event
,&x
,&y
) )
5358 bool res
= HandleMouseUp(x
,y
,event
);
5359 if ( !res
) event
.Skip();
5363 // -----------------------------------------------------------------------
5364 // wxPropertyGrid keyboard event handling
5365 // -----------------------------------------------------------------------
5367 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5369 // Translates wxKeyEvent to wxPG_ACTION_XXX
5371 int keycode
= event
.GetKeyCode();
5372 int modifiers
= event
.GetModifiers();
5374 wxASSERT( !(modifiers
&~(0xFFFF)) );
5376 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5378 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5380 if ( it
== m_actionTriggers
.end() )
5385 int second
= (it
->second
>>16) & 0xFFFF;
5389 return (it
->second
& 0xFFFF);
5392 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5394 wxASSERT( !(modifiers
&~(0xFFFF)) );
5396 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5398 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5400 if ( it
!= m_actionTriggers
.end() )
5402 // This key combination is already used
5404 // Can add secondary?
5405 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5406 wxT("You can only add up to two separate actions per key combination.") );
5408 action
= it
->second
| (action
<<16);
5411 m_actionTriggers
[hashMapKey
] = action
;
5414 void wxPropertyGrid::ClearActionTriggers( int action
)
5416 wxPGHashMapI2I::iterator it
;
5421 didSomething
= false;
5423 for ( it
= m_actionTriggers
.begin();
5424 it
!= m_actionTriggers
.end();
5427 if ( it
->second
== action
)
5429 m_actionTriggers
.erase(it
);
5430 didSomething
= true;
5435 while ( didSomething
);
5438 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5441 // Handles key event when editor control is not focused.
5444 wxCHECK2(!m_frozen
, return);
5446 // Travelsal between items, collapsing/expanding, etc.
5447 wxPGProperty
* selected
= GetSelection();
5448 int keycode
= event
.GetKeyCode();
5449 bool editorFocused
= IsEditorFocused();
5451 if ( keycode
== WXK_TAB
)
5453 wxWindow
* mainControl
;
5455 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5456 mainControl
= GetParent();
5460 if ( !event
.ShiftDown() )
5462 if ( !editorFocused
&& m_wndEditor
)
5464 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5468 // Tab traversal workaround for platforms on which
5469 // wxWindow::Navigate() may navigate into first child
5470 // instead of next sibling. Does not work perfectly
5471 // in every scenario (for instance, when property grid
5472 // is either first or last control).
5473 #if defined(__WXGTK__)
5474 wxWindow
* sibling
= mainControl
->GetNextSibling();
5476 sibling
->SetFocusFromKbd();
5478 Navigate(wxNavigationKeyEvent::IsForward
);
5484 if ( editorFocused
)
5490 #if defined(__WXGTK__)
5491 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5493 sibling
->SetFocusFromKbd();
5495 Navigate(wxNavigationKeyEvent::IsBackward
);
5503 // Ignore Alt and Control when they are down alone
5504 if ( keycode
== WXK_ALT
||
5505 keycode
== WXK_CONTROL
)
5512 int action
= KeyEventToActions(event
, &secondAction
);
5514 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5517 // Esc cancels any changes
5518 if ( IsEditorsValueModified() )
5520 EditorsValueWasNotModified();
5522 // Update the control as well
5523 selected
->GetEditorClass()->
5524 SetControlStringValue( selected
,
5526 selected
->GetDisplayedString() );
5529 OnValidationFailureReset(selected
);
5535 // Except for TAB and ESC, handle child control events in child control
5538 // Only propagate event if it had modifiers
5539 if ( !event
.HasModifiers() )
5541 event
.StopPropagation();
5547 bool wasHandled
= false;
5552 if ( ButtonTriggerKeyTest(action
, event
) )
5555 wxPGProperty
* p
= selected
;
5557 // Travel and expand/collapse
5560 if ( p
->GetChildCount() )
5562 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5564 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5567 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5569 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5576 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5580 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5586 if ( selectDir
>= -1 )
5588 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5590 DoSelectProperty(p
);
5596 // If nothing was selected, select the first item now
5597 // (or navigate out of tab).
5598 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5600 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5601 if ( p
) DoSelectProperty(p
);
5610 // -----------------------------------------------------------------------
5612 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5614 // If there was editor open and focused, then this event should not
5615 // really be processed here.
5616 if ( IsEditorFocused() )
5618 // However, if event had modifiers, it is probably still best
5620 if ( event
.HasModifiers() )
5623 event
.StopPropagation();
5627 HandleKeyEvent(event
, false);
5630 // -----------------------------------------------------------------------
5632 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5637 action
= KeyEventToActions(event
, &secondAction
);
5640 // Does the keycode trigger button?
5641 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5644 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5645 GetEventHandler()->AddPendingEvent(evt
);
5652 // -----------------------------------------------------------------------
5654 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5656 HandleKeyEvent(event
, true);
5659 // -----------------------------------------------------------------------
5660 // wxPropertyGrid miscellaneous event handling
5661 // -----------------------------------------------------------------------
5663 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5666 // Check if the focus is in this control or one of its children
5667 wxWindow
* newFocused
= wxWindow::FindFocus();
5669 if ( newFocused
!= m_curFocused
)
5670 HandleFocusChange( newFocused
);
5673 // Check if top-level parent has changed
5674 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5676 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5682 // Resolve pending property removals
5683 if ( m_deletedProperties
.size() > 0 )
5685 wxArrayPGProperty
& arr
= m_deletedProperties
;
5686 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5688 DeleteProperty(arr
[i
]);
5692 if ( m_removedProperties
.size() > 0 )
5694 wxArrayPGProperty
& arr
= m_removedProperties
;
5695 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5697 RemoveProperty(arr
[i
]);
5703 bool wxPropertyGrid::IsEditorFocused() const
5705 wxWindow
* focus
= wxWindow::FindFocus();
5707 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5708 focus
== GetEditorControl() )
5714 // Called by focus event handlers. newFocused is the window that becomes focused.
5715 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5717 unsigned int oldFlags
= m_iFlags
;
5718 bool wasEditorFocused
= false;
5719 wxWindow
* wndEditor
= m_wndEditor
;
5721 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5723 wxWindow
* parent
= newFocused
;
5725 // This must be one of nextFocus' parents.
5728 if ( parent
== wndEditor
)
5730 wasEditorFocused
= true;
5732 // Use m_eventObject, which is either wxPropertyGrid or
5733 // wxPropertyGridManager, as appropriate.
5734 else if ( parent
== m_eventObject
)
5736 m_iFlags
|= wxPG_FL_FOCUSED
;
5739 parent
= parent
->GetParent();
5742 // Notify editor control when it receives a focus
5743 if ( wasEditorFocused
&& m_curFocused
!= newFocused
)
5745 wxPGProperty
* p
= GetSelection();
5748 const wxPGEditor
* editor
= p
->GetEditorClass();
5749 ResetEditorAppearance();
5750 editor
->OnFocus(p
, GetEditorControl());
5754 m_curFocused
= newFocused
;
5756 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5757 (oldFlags
& wxPG_FL_FOCUSED
) )
5759 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5761 // Need to store changed value
5762 CommitChangesFromEditor();
5768 // Preliminary code for tab-order respecting
5769 // tab-traversal (but should be moved to
5772 wxWindow* prevFocus = event.GetWindow();
5773 wxWindow* useThis = this;
5774 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5775 useThis = GetParent();
5778 prevFocus->GetParent() == useThis->GetParent() )
5780 wxList& children = useThis->GetParent()->GetChildren();
5782 wxNode* node = children.Find(prevFocus);
5784 if ( node->GetNext() &&
5785 useThis == node->GetNext()->GetData() )
5786 DoSelectProperty(GetFirst());
5787 else if ( node->GetPrevious () &&
5788 useThis == node->GetPrevious()->GetData() )
5789 DoSelectProperty(GetLastProperty());
5796 wxPGProperty
* selected
= GetSelection();
5797 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5798 DrawItem( selected
);
5802 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5804 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5805 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5806 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5807 //else if ( event.GetWindow() )
5809 HandleFocusChange(event
.GetWindow());
5814 // -----------------------------------------------------------------------
5816 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5818 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5822 // -----------------------------------------------------------------------
5824 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5826 m_iFlags
|= wxPG_FL_SCROLLED
;
5831 // -----------------------------------------------------------------------
5833 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5835 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5837 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5841 // -----------------------------------------------------------------------
5842 // Property editor related functions
5843 // -----------------------------------------------------------------------
5845 // noDefCheck = true prevents infinite recursion.
5846 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5847 const wxString
& editorName
,
5850 wxASSERT( editorClass
);
5852 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5853 RegisterDefaultEditors();
5855 wxString name
= editorName
;
5856 if ( name
.length() == 0 )
5857 name
= editorClass
->GetName();
5859 // Existing editor under this name?
5860 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5862 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5864 // If this name was already used, try class name.
5865 name
= editorClass
->GetClassInfo()->GetClassName();
5866 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5869 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5870 (wxPGEditor
*) vt_it
->second
,
5871 "Editor with given name was already registered" );
5873 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5878 // Use this in RegisterDefaultEditors.
5879 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5880 if ( wxPGEditor_##EDITOR == NULL ) \
5882 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5883 new wxPG##EDITOR##Editor, true ); \
5886 // Registers all default editor classes
5887 void wxPropertyGrid::RegisterDefaultEditors()
5889 wxPGRegisterDefaultEditorClass( TextCtrl
);
5890 wxPGRegisterDefaultEditorClass( Choice
);
5891 wxPGRegisterDefaultEditorClass( ComboBox
);
5892 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5893 #if wxPG_INCLUDE_CHECKBOX
5894 wxPGRegisterDefaultEditorClass( CheckBox
);
5896 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5898 // Register SpinCtrl etc. editors before use
5899 RegisterAdditionalEditors();
5902 // -----------------------------------------------------------------------
5903 // wxPGStringTokenizer
5904 // Needed to handle C-style string lists (e.g. "str1" "str2")
5905 // -----------------------------------------------------------------------
5907 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5908 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5912 wxPGStringTokenizer::~wxPGStringTokenizer()
5916 bool wxPGStringTokenizer::HasMoreTokens()
5918 const wxString
& str
= *m_str
;
5920 wxString::const_iterator i
= m_curPos
;
5922 wxUniChar delim
= m_delimeter
;
5924 wxUniChar prev_a
= wxT('\0');
5926 bool inToken
= false;
5928 while ( i
!= str
.end() )
5937 m_readyToken
.clear();
5942 if ( prev_a
!= wxT('\\') )
5946 if ( a
!= wxT('\\') )
5966 m_curPos
= str
.end();
5974 wxString
wxPGStringTokenizer::GetNextToken()
5976 return m_readyToken
;
5979 // -----------------------------------------------------------------------
5981 // -----------------------------------------------------------------------
5983 wxPGChoiceEntry::wxPGChoiceEntry()
5984 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5988 // -----------------------------------------------------------------------
5990 // -----------------------------------------------------------------------
5992 wxPGChoicesData::wxPGChoicesData()
5996 wxPGChoicesData::~wxPGChoicesData()
6001 void wxPGChoicesData::Clear()
6006 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
6008 wxASSERT( m_items
.size() == 0 );
6010 m_items
= data
->m_items
;
6013 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
6014 const wxPGChoiceEntry
& item
)
6016 wxVector
<wxPGChoiceEntry
>::iterator it
;
6020 index
= (int) m_items
.size();
6024 it
= m_items
.begin() + index
;
6027 m_items
.insert(it
, item
);
6029 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
6031 // Need to fix value?
6032 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
6033 ownEntry
.SetValue(index
);
6038 // -----------------------------------------------------------------------
6039 // wxPropertyGridEvent
6040 // -----------------------------------------------------------------------
6042 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
6045 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
6046 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
6047 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
6048 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
6049 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
6050 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
6051 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
6052 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
6053 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
6054 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
6055 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
6056 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
6057 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
6058 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
6060 // -----------------------------------------------------------------------
6062 void wxPropertyGridEvent::Init()
6064 m_validationInfo
= NULL
;
6067 m_wasVetoed
= false;
6070 // -----------------------------------------------------------------------
6072 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6073 : wxCommandEvent(commandType
,id
)
6079 // -----------------------------------------------------------------------
6081 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6082 : wxCommandEvent(event
)
6084 m_eventType
= event
.GetEventType();
6085 m_eventObject
= event
.m_eventObject
;
6087 OnPropertyGridSet();
6088 m_property
= event
.m_property
;
6089 m_validationInfo
= event
.m_validationInfo
;
6090 m_canVeto
= event
.m_canVeto
;
6091 m_wasVetoed
= event
.m_wasVetoed
;
6094 // -----------------------------------------------------------------------
6096 void wxPropertyGridEvent::OnPropertyGridSet()
6102 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6104 m_pg
->m_liveEvents
.push_back(this);
6107 // -----------------------------------------------------------------------
6109 wxPropertyGridEvent::~wxPropertyGridEvent()
6114 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6117 // Use iterate from the back since it is more likely that the event
6118 // being desroyed is at the end of the array.
6119 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
6121 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
6123 if ( liveEvents
[i
] == this )
6125 liveEvents
.erase(liveEvents
.begin() + i
);
6132 // -----------------------------------------------------------------------
6134 wxEvent
* wxPropertyGridEvent::Clone() const
6136 return new wxPropertyGridEvent( *this );
6139 // -----------------------------------------------------------------------
6140 // wxPropertyGridPopulator
6141 // -----------------------------------------------------------------------
6143 wxPropertyGridPopulator::wxPropertyGridPopulator()
6147 wxPGGlobalVars
->m_offline
++;
6150 // -----------------------------------------------------------------------
6152 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6155 m_propHierarchy
.clear();
6158 // -----------------------------------------------------------------------
6160 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6166 // -----------------------------------------------------------------------
6168 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6171 // Free unused sets of choices
6172 wxPGHashMapS2P::iterator it
;
6174 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6176 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6183 m_pg
->GetPanel()->Refresh();
6185 wxPGGlobalVars
->m_offline
--;
6188 // -----------------------------------------------------------------------
6190 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6191 const wxString
& propLabel
,
6192 const wxString
& propName
,
6193 const wxString
* propValue
,
6194 wxPGChoices
* pChoices
)
6196 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6197 wxPGProperty
* parent
= GetCurParent();
6199 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6201 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6205 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6207 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6211 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6213 property
->SetLabel(propLabel
);
6214 property
->DoSetName(propName
);
6216 if ( pChoices
&& pChoices
->IsOk() )
6217 property
->SetChoices(*pChoices
);
6219 m_state
->DoInsert(parent
, -1, property
);
6222 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
6223 wxPG_PROGRAMMATIC_VALUE
);
6228 // -----------------------------------------------------------------------
6230 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6232 m_propHierarchy
.push_back(property
);
6233 DoScanForChildren();
6234 m_propHierarchy
.pop_back();
6237 // -----------------------------------------------------------------------
6239 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6240 const wxString
& idString
)
6242 wxPGChoices choices
;
6245 if ( choicesString
[0] == wxT('@') )
6247 wxString ids
= choicesString
.substr(1);
6248 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6249 if ( it
== m_dictIdChoices
.end() )
6250 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6252 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6257 if ( idString
.length() )
6259 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6260 if ( it
!= m_dictIdChoices
.end() )
6262 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6269 // Parse choices string
6270 wxString::const_iterator it
= choicesString
.begin();
6274 bool labelValid
= false;
6276 for ( ; it
!= choicesString
.end(); ++it
)
6282 if ( c
== wxT('"') )
6287 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6288 choices
.Add(label
, l
);
6291 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6296 else if ( c
== wxT('=') )
6303 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6310 if ( c
== wxT('"') )
6323 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6324 choices
.Add(label
, l
);
6327 if ( !choices
.IsOk() )
6329 choices
.EnsureData();
6333 if ( idString
.length() )
6334 m_dictIdChoices
[idString
] = choices
.GetData();
6341 // -----------------------------------------------------------------------
6343 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6345 if ( s
.Last() == wxT('%') )
6347 wxString s2
= s
.substr(0,s
.length()-1);
6349 if ( s2
.ToLong(&val
, 10) )
6351 *pval
= (val
*max
)/100;
6357 return s
.ToLong(pval
, 10);
6360 // -----------------------------------------------------------------------
6362 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6363 const wxString
& type
,
6364 const wxString
& value
)
6366 int l
= m_propHierarchy
.size();
6370 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6371 wxString valuel
= value
.Lower();
6374 if ( type
.length() == 0 )
6379 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6381 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6383 else if ( value
.ToLong(&v
, 0) )
6390 if ( type
== wxT("string") )
6394 else if ( type
== wxT("int") )
6397 value
.ToLong(&v
, 0);
6400 else if ( type
== wxT("bool") )
6402 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6409 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6414 p
->SetAttribute( name
, variant
);
6419 // -----------------------------------------------------------------------
6421 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6423 wxLogError(_("Error in resource: %s"),msg
.c_str());
6426 // -----------------------------------------------------------------------
6428 #endif // wxUSE_PROPGRID