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();
331 m_validatingEditor
= 0;
334 m_wndEditor
= m_wndEditor2
= NULL
;
338 m_labelEditor
= NULL
;
339 m_labelEditorProperty
= NULL
;
340 m_eventObject
= this;
342 m_processedEvent
= NULL
;
343 m_sortFunction
= NULL
;
344 m_inDoPropertyChanged
= 0;
345 m_inCommitChangesFromEditor
= 0;
346 m_inDoSelectProperty
= 0;
347 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
352 // Set up default unspecified value 'colour'
353 m_unspecifiedAppearance
.SetFgCol(*wxLIGHT_GREY
);
356 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
357 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
358 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
359 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
360 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
361 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
362 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
363 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
364 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
366 m_coloursCustomized
= 0;
369 #if wxPG_DOUBLE_BUFFER
370 m_doubleBuffer
= NULL
;
373 #ifndef wxPG_ICON_WIDTH
379 m_iconWidth
= wxPG_ICON_WIDTH
;
384 m_gutterWidth
= wxPG_GUTTER_MIN
;
385 m_subgroup_extramargin
= 10;
389 m_width
= m_height
= 0;
391 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
394 m_chgInfo_changedProperty
= NULL
;
397 // -----------------------------------------------------------------------
400 // Initialize after parent etc. set
402 void wxPropertyGrid::Init2()
404 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
407 // Smaller controls on Mac
408 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
411 // Now create state, if one didn't exist already
412 // (wxPropertyGridManager might have created it for us).
415 m_pState
= CreateState();
416 m_pState
->m_pPropGrid
= this;
417 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
420 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
421 m_pState
->m_dontCenterSplitter
= true;
423 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
425 m_pState
->InitNonCatMode();
427 m_pState
->m_properties
= m_pState
->m_abcArray
;
430 GetClientSize(&m_width
,&m_height
);
432 #ifndef wxPG_ICON_WIDTH
433 // create two bitmap nodes for drawing
434 m_expandbmp
= new wxBitmap(expand_xpm
);
435 m_collbmp
= new wxBitmap(collapse_xpm
);
437 // calculate average font height for bitmap centering
439 m_iconWidth
= m_expandbmp
->GetWidth();
440 m_iconHeight
= m_expandbmp
->GetHeight();
443 m_curcursor
= wxCURSOR_ARROW
;
444 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
446 // adjust bitmap icon y position so they are centered
447 m_vspacing
= wxPG_DEFAULT_VSPACING
;
449 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
451 // Allocate cell datas
452 m_propertyDefaultCell
.SetEmptyData();
453 m_categoryDefaultCell
.SetEmptyData();
457 // This helps with flicker
458 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
460 // Hook the top-level parent
465 // set virtual size to this window size
466 wxSize wndsize
= GetSize();
467 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
469 m_timeCreated
= ::wxGetLocalTimeMillis();
471 //m_canvas->Create(this, wxID_ANY, wxPoint(0, 0), GetClientSize(),
472 // wxWANTS_CHARS | wxCLIP_CHILDREN);
473 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
475 m_iFlags
|= wxPG_FL_INITIALIZED
;
477 m_ncWidth
= wndsize
.GetWidth();
479 // Need to call OnResize handler or size given in constructor/Create
481 wxSizeEvent
sizeEvent(wndsize
,0);
485 // -----------------------------------------------------------------------
487 wxPropertyGrid::~wxPropertyGrid()
492 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
496 // Remove grid and property pointers from live wxPropertyGridEvents.
497 for ( i
=0; i
<m_liveEvents
.size(); i
++ )
499 wxPropertyGridEvent
* evt
= m_liveEvents
[i
];
500 evt
->SetPropertyGrid(NULL
);
501 evt
->SetProperty(NULL
);
503 m_liveEvents
.clear();
505 if ( m_processedEvent
)
507 // All right... we are being deleted while wxPropertyGrid event
508 // is being sent. Make sure that event propagates as little
509 // as possible (although usually this is not enough to prevent
511 m_processedEvent
->Skip(false);
512 m_processedEvent
->StopPropagation();
514 // Let's use wxMessageBox to make the message appear more
515 // reliably (and *before* the crash can happen).
516 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
517 "generated by it. This usually leads to a crash "
518 "so it is recommended to destroy the control "
519 "at idle time instead.");
522 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
524 // This should do prevent things from going too badly wrong
525 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
527 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
530 // Call with NULL to disconnect event handling
531 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
535 wxASSERT_MSG( !IsEditorsValueModified(),
536 wxS("Most recent change in property editor was ")
537 wxS("lost!!! (if you don't want this to happen, ")
538 wxS("close your frames and dialogs using ")
539 wxS("Close(false).)") );
542 #if wxPG_DOUBLE_BUFFER
543 if ( m_doubleBuffer
)
544 delete m_doubleBuffer
;
547 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
550 delete m_cursorSizeWE
;
552 #ifndef wxPG_ICON_WIDTH
557 // Delete common value records
558 for ( i
=0; i
<m_commonValues
.size(); i
++ )
560 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
561 wxPGCommonValue
* value
= m_commonValues
[i
];
566 // -----------------------------------------------------------------------
568 bool wxPropertyGrid::Destroy()
570 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
573 return wxScrolledWindow::Destroy();
576 // -----------------------------------------------------------------------
578 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
580 return new wxPropertyGridPageState();
583 // -----------------------------------------------------------------------
584 // wxPropertyGrid overridden wxWindow methods
585 // -----------------------------------------------------------------------
587 void wxPropertyGrid::SetWindowStyleFlag( long style
)
589 long old_style
= m_windowStyle
;
591 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
593 wxASSERT( m_pState
);
595 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
598 EnableCategories( true );
600 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
602 // Disable categories
603 EnableCategories( false );
605 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
611 PrepareAfterItemsAdded();
613 m_pState
->m_itemsAdded
= 1;
615 #if wxPG_SUPPORT_TOOLTIPS
616 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
622 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
623 SetToolTip ( tooltip );
624 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
627 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
632 wxScrolledWindow::SetToolTip( NULL
);
637 wxScrolledWindow::SetWindowStyleFlag ( style
);
639 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
641 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
643 CalculateFontAndBitmapStuff( m_vspacing
);
649 // -----------------------------------------------------------------------
651 void wxPropertyGrid::Freeze()
655 wxScrolledWindow::Freeze();
660 // -----------------------------------------------------------------------
662 void wxPropertyGrid::Thaw()
668 wxScrolledWindow::Thaw();
669 RecalculateVirtualSize();
670 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
674 // Force property re-selection
675 // NB: We must copy the selection.
676 wxArrayPGProperty selection
= m_pState
->m_selection
;
677 DoSetSelection(selection
, wxPG_SEL_FORCE
| wxPG_SEL_NONVISIBLE
);
681 // -----------------------------------------------------------------------
683 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
685 wxCHECK( prop
, false );
687 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
688 return DoSelectProperty(prop
, selFlags
);
690 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
692 if ( !selection
.size() )
694 return DoSelectProperty(prop
, selFlags
);
698 // For categories, only one can be selected at a time
699 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
702 selection
.push_back(prop
);
704 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
706 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
715 // -----------------------------------------------------------------------
717 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
719 wxCHECK( prop
, false );
722 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
723 if ( selection
.size() <= 1 )
725 res
= DoSelectProperty(NULL
, selFlags
);
729 m_pState
->DoRemoveFromSelection(prop
);
737 // -----------------------------------------------------------------------
739 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
740 unsigned int colIndex
,
741 unsigned int selFlags
)
744 // NB: Enable following if label editor background colour is
745 // ever changed to any other than m_colSelBack.
747 // We use this workaround to prevent visible flicker when editing
748 // a cell. Atleast on wxMSW, there is a difficult to find
749 // (and perhaps prevent) redraw somewhere between making property
750 // selected and enabling label editing.
752 //wxColour prevColSelBack = m_colSelBack;
753 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
759 res
= DoSelectProperty(prop
, selFlags
);
764 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
766 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
768 res
= DoAddToSelection(prop
, selFlags
);
772 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
774 DoBeginLabelEdit(colIndex
, selFlags
);
778 //m_colSelBack = prevColSelBack;
782 // -----------------------------------------------------------------------
784 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
785 unsigned int colIndex
,
786 wxMouseEvent
* mouseEvent
,
789 const wxArrayPGProperty
& selection
= GetSelectedProperties();
790 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
793 // Set to 2 if also add all items in between
794 int addToExistingSelection
= 0;
796 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
800 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
801 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
803 // Allow right-click for context menu without
804 // disturbing the selection.
805 if ( GetSelectedProperties().size() <= 1 ||
807 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
812 if ( mouseEvent
->ControlDown() )
814 addToExistingSelection
= 1;
816 else if ( mouseEvent
->ShiftDown() )
818 if ( selection
.size() > 0 && !prop
->IsCategory() )
819 addToExistingSelection
= 2;
821 addToExistingSelection
= 1;
827 if ( addToExistingSelection
== 1 )
830 if ( !alreadySelected
)
832 res
= DoAddToSelection(prop
, selFlags
);
834 else if ( GetSelectedProperties().size() > 1 )
836 res
= DoRemoveFromSelection(prop
, selFlags
);
839 else if ( addToExistingSelection
== 2 )
841 // Add this, and all in between
843 // Find top selected property
844 wxPGProperty
* topSelProp
= selection
[0];
845 int topSelPropY
= topSelProp
->GetY();
846 for ( unsigned int i
=1; i
<selection
.size(); i
++ )
848 wxPGProperty
* p
= selection
[i
];
850 if ( y
< topSelPropY
)
857 wxPGProperty
* startFrom
;
858 wxPGProperty
* stopAt
;
860 if ( prop
->GetY() <= topSelPropY
)
862 // Property is above selection (or same)
868 // Property is below selection
869 startFrom
= topSelProp
;
873 // Iterate through properties in-between, and select them
874 wxPropertyGridIterator it
;
876 for ( it
= GetIterator(wxPG_ITERATE_VISIBLE
, startFrom
);
880 wxPGProperty
* p
= *it
;
882 if ( !p
->IsCategory() &&
883 !m_pState
->DoIsPropertySelected(p
) )
885 DoAddToSelection(p
, selFlags
);
894 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
900 // -----------------------------------------------------------------------
902 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
905 if ( newSelection
.size() > 0 )
907 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
912 DoClearSelection(false, selFlags
);
915 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
917 DoAddToSelection(newSelection
[i
], selFlags
);
923 // -----------------------------------------------------------------------
925 void wxPropertyGrid::MakeColumnEditable( unsigned int column
,
928 wxASSERT( column
!= 1 );
930 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
934 cols
.push_back(column
);
938 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
940 if ( cols
[i
] == (int)column
)
941 cols
.erase( cols
.begin() + i
);
946 // -----------------------------------------------------------------------
948 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
951 wxPGProperty
* selected
= GetSelection();
952 wxCHECK_RET(selected
, wxT("No property selected"));
953 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
955 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
957 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
964 const wxPGCell
* cell
= NULL
;
965 if ( selected
->HasCell(colIndex
) )
967 cell
= &selected
->GetCell(colIndex
);
968 if ( !cell
->HasText() && colIndex
== 0 )
969 text
= selected
->GetLabel();
975 text
= selected
->GetLabel();
977 cell
= &selected
->GetOrCreateCell(colIndex
);
980 if ( cell
&& cell
->HasText() )
981 text
= cell
->GetText();
983 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
985 m_selColumn
= colIndex
;
987 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
989 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
997 wxWindowID id
= tc
->GetId();
998 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
999 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
1001 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1002 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
1007 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1008 m_labelEditorProperty
= selected
;
1011 // -----------------------------------------------------------------------
1014 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1016 DoEndLabelEdit(true);
1019 // -----------------------------------------------------------------------
1021 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1023 int keycode
= event
.GetKeyCode();
1025 if ( keycode
== WXK_ESCAPE
)
1027 DoEndLabelEdit(false);
1031 HandleKeyEvent(event
, true);
1035 // -----------------------------------------------------------------------
1037 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1039 if ( !m_labelEditor
)
1042 wxPGProperty
* prop
= m_labelEditorProperty
;
1047 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1049 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1050 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1051 prop
, NULL
, selFlags
,
1056 wxString text
= m_labelEditor
->GetValue();
1057 wxPGCell
* cell
= NULL
;
1058 if ( prop
->HasCell(m_selColumn
) )
1060 cell
= &prop
->GetCell(m_selColumn
);
1064 if ( m_selColumn
== 0 )
1065 prop
->SetLabel(text
);
1067 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1071 cell
->SetText(text
);
1075 int wasFocused
= m_iFlags
& wxPG_FL_FOCUSED
;
1077 DestroyEditorWnd(m_labelEditor
);
1079 m_labelEditor
= NULL
;
1080 m_labelEditorProperty
= NULL
;
1082 // Fix focus (needed at least on wxGTK)
1089 // -----------------------------------------------------------------------
1091 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1093 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1094 OnTLPChanging(::wxGetTopLevelParent(this));
1096 OnTLPChanging(NULL
);
1098 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1100 #if defined(__WXMSW__)
1103 // Don't use WS_EX_COMPOSITED just now.
1106 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1107 hWnd = (HWND)GetParent()->GetHWND();
1109 hWnd = (HWND)GetHWND();
1111 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1112 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1115 //#elif defined(__WXGTK20__)
1117 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1118 // truly was double-buffered.
1119 if ( !this->IsDoubleBuffered() )
1121 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1125 #if wxPG_DOUBLE_BUFFER
1126 delete m_doubleBuffer
;
1127 m_doubleBuffer
= NULL
;
1132 wxScrolledWindow::SetExtraStyle( exStyle
);
1134 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1135 m_pState
->InitNonCatMode();
1137 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1138 m_windowStyle
|= wxPG_TOOLTIPS
;
1141 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1144 // -----------------------------------------------------------------------
1146 // returns the best acceptable minimal size
1147 wxSize
wxPropertyGrid::DoGetBestSize() const
1149 int lineHeight
= wxMax(15, m_lineHeight
);
1151 // don't make the grid too tall (limit height to 10 items) but don't
1152 // make it too small neither
1153 int numLines
= wxMin
1155 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1159 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1160 int width
= m_marginWidth
;
1161 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1163 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1166 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1172 // -----------------------------------------------------------------------
1174 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1176 if ( newTLP
== m_tlp
)
1179 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1182 // Parent changed so let's redetermine and re-hook the
1183 // correct top-level window.
1186 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1187 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1189 m_tlpClosed
= m_tlp
;
1190 m_tlpClosedTime
= currentTime
;
1195 // Only accept new tlp if same one was not just dismissed.
1196 if ( newTLP
!= m_tlpClosed
||
1197 m_tlpClosedTime
+250 < currentTime
)
1199 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1200 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1213 // -----------------------------------------------------------------------
1215 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1217 // ClearSelection forces value validation/commit.
1218 if ( event
.CanVeto() && !DoClearSelection() )
1224 // Ok, it can close, set tlp pointer to NULL. Some other event
1225 // handler can of course veto the close, but our OnIdle() should
1226 // then be able to regain the tlp pointer.
1227 OnTLPChanging(NULL
);
1232 // -----------------------------------------------------------------------
1234 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1236 OnTLPChanging((wxWindow
*)newParent
);
1238 bool res
= wxScrolledWindow::Reparent(newParent
);
1243 // -----------------------------------------------------------------------
1244 // wxPropertyGrid Font and Colour Methods
1245 // -----------------------------------------------------------------------
1247 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1251 m_captionFont
= wxScrolledWindow::GetFont();
1253 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1254 m_subgroup_extramargin
= x
+ (x
/2);
1257 #if wxPG_USE_RENDERER_NATIVE
1258 m_iconWidth
= wxPG_ICON_WIDTH
;
1259 #elif wxPG_ICON_WIDTH
1261 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1262 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1263 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1267 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1268 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1269 m_gutterWidth
= wxPG_GUTTER_MIN
;
1272 if ( vspacing
<= 1 ) vdiv
= 12;
1273 else if ( vspacing
>= 3 ) vdiv
= 3;
1275 m_spacingy
= m_fontHeight
/ vdiv
;
1276 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1277 m_spacingy
= wxPG_YSPACING_MIN
;
1280 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1281 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1283 m_captionFont
.SetWeight(wxBOLD
);
1284 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1286 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1289 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1290 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1293 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1295 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1296 RecalculateVirtualSize();
1298 InvalidateBestSize();
1301 // -----------------------------------------------------------------------
1303 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1309 // -----------------------------------------------------------------------
1311 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1312 int ga
= 1000, int ba
= 1000,
1313 bool forceDifferent
= false)
1320 // Recursion guard (allow 2 max)
1321 static int isinside
= 0;
1323 wxCHECK_MSG( isinside
< 3,
1325 wxT("wxPGAdjustColour should not be recursively called more than once") );
1330 int g
= src
.Green();
1333 if ( r2
>255 ) r2
= 255;
1334 else if ( r2
<0) r2
= 0;
1336 if ( g2
>255 ) g2
= 255;
1337 else if ( g2
<0) g2
= 0;
1339 if ( b2
>255 ) b2
= 255;
1340 else if ( b2
<0) b2
= 0;
1342 // Make sure they are somewhat different
1343 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1344 dst
= wxPGAdjustColour(src
,-(ra
*2));
1346 dst
= wxColour(r2
,g2
,b2
);
1348 // Recursion guard (allow 2 max)
1355 static int wxPGGetColAvg( const wxColour
& col
)
1357 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1361 void wxPropertyGrid::RegainColours()
1363 if ( !(m_coloursCustomized
& 0x0002) )
1365 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1367 // Make sure colour is dark enough
1369 int colDec
= wxPGGetColAvg(col
) - 230;
1371 int colDec
= wxPGGetColAvg(col
) - 200;
1374 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1377 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1380 if ( !(m_coloursCustomized
& 0x0001) )
1381 m_colMargin
= m_colCapBack
;
1383 if ( !(m_coloursCustomized
& 0x0004) )
1390 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1391 m_colCapFore
= capForeCol
;
1392 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1395 if ( !(m_coloursCustomized
& 0x0008) )
1397 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1398 m_colPropBack
= bgCol
;
1399 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1400 if ( !m_unspecifiedAppearance
.GetBgCol().IsOk() )
1401 m_unspecifiedAppearance
.SetBgCol(bgCol
);
1404 if ( !(m_coloursCustomized
& 0x0010) )
1406 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1407 m_colPropFore
= fgCol
;
1408 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1409 if ( !m_unspecifiedAppearance
.GetFgCol().IsOk() )
1410 m_unspecifiedAppearance
.SetFgCol(fgCol
);
1413 if ( !(m_coloursCustomized
& 0x0020) )
1414 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1416 if ( !(m_coloursCustomized
& 0x0040) )
1417 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1419 if ( !(m_coloursCustomized
& 0x0080) )
1420 m_colLine
= m_colCapBack
;
1422 if ( !(m_coloursCustomized
& 0x0100) )
1423 m_colDisPropFore
= m_colCapFore
;
1425 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1428 // -----------------------------------------------------------------------
1430 void wxPropertyGrid::ResetColours()
1432 m_coloursCustomized
= 0;
1439 // -----------------------------------------------------------------------
1441 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1443 // Must disable active editor.
1446 bool res
= wxScrolledWindow::SetFont( font
);
1447 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1449 CalculateFontAndBitmapStuff( m_vspacing
);
1456 // -----------------------------------------------------------------------
1458 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1461 m_coloursCustomized
|= 0x80;
1465 // -----------------------------------------------------------------------
1467 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1470 m_coloursCustomized
|= 0x01;
1474 // -----------------------------------------------------------------------
1476 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1478 m_colPropBack
= col
;
1479 m_coloursCustomized
|= 0x08;
1481 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1482 m_unspecifiedAppearance
.SetBgCol(col
);
1487 // -----------------------------------------------------------------------
1489 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1491 m_colPropFore
= col
;
1492 m_coloursCustomized
|= 0x10;
1494 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1495 m_unspecifiedAppearance
.SetFgCol(col
);
1500 // -----------------------------------------------------------------------
1502 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1504 m_colEmptySpace
= col
;
1509 // -----------------------------------------------------------------------
1511 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1513 m_colDisPropFore
= col
;
1514 m_coloursCustomized
|= 0x100;
1518 // -----------------------------------------------------------------------
1520 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1523 m_coloursCustomized
|= 0x20;
1527 // -----------------------------------------------------------------------
1529 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1532 m_coloursCustomized
|= 0x40;
1536 // -----------------------------------------------------------------------
1538 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1541 m_coloursCustomized
|= 0x02;
1543 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1548 // -----------------------------------------------------------------------
1550 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1553 m_coloursCustomized
|= 0x04;
1555 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1560 // -----------------------------------------------------------------------
1561 // wxPropertyGrid property adding and removal
1562 // -----------------------------------------------------------------------
1564 void wxPropertyGrid::PrepareAfterItemsAdded()
1566 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1568 m_pState
->m_itemsAdded
= 0;
1570 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1571 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1573 RecalculateVirtualSize();
1575 // Fix editor position
1576 CorrectEditorWidgetPosY();
1579 // -----------------------------------------------------------------------
1580 // wxPropertyGrid property operations
1581 // -----------------------------------------------------------------------
1583 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1585 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1589 bool changed
= false;
1591 // Is it inside collapsed section?
1592 if ( !p
->IsVisible() )
1595 wxPGProperty
* parent
= p
->GetParent();
1596 wxPGProperty
* grandparent
= parent
->GetParent();
1598 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1599 Expand( grandparent
);
1607 GetViewStart(&vx
,&vy
);
1608 vy
*=wxPG_PIXELS_PER_UNIT
;
1614 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1615 m_iFlags
|= wxPG_FL_SCROLLED
;
1618 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1620 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1621 m_iFlags
|= wxPG_FL_SCROLLED
;
1631 // -----------------------------------------------------------------------
1632 // wxPropertyGrid helper methods called by properties
1633 // -----------------------------------------------------------------------
1635 // Control font changer helper.
1636 void wxPropertyGrid::SetCurControlBoldFont()
1638 wxWindow
* editor
= GetEditorControl();
1639 editor
->SetFont( m_captionFont
);
1642 // -----------------------------------------------------------------------
1644 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1647 #if wxPG_SMALL_SCREEN
1648 // On small-screen devices, always show dialogs with default position and size.
1649 return wxDefaultPosition
;
1651 int splitterX
= GetSplitterPosition();
1655 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1657 ImprovedClientToScreen( &x
, &y
);
1659 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1660 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1667 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1677 new_y
= y
+ m_lineHeight
;
1679 return wxPoint(new_x
,new_y
);
1683 // -----------------------------------------------------------------------
1685 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1687 if ( src_str
.length() == 0 )
1693 bool prev_is_slash
= false;
1695 wxString::const_iterator i
= src_str
.begin();
1699 for ( ; i
!= src_str
.end(); ++i
)
1703 if ( a
!= wxS('\\') )
1705 if ( !prev_is_slash
)
1711 if ( a
== wxS('n') )
1714 dst_str
<< wxS('\n');
1716 dst_str
<< wxS('\n');
1719 else if ( a
== wxS('t') )
1720 dst_str
<< wxS('\t');
1724 prev_is_slash
= false;
1728 if ( prev_is_slash
)
1730 dst_str
<< wxS('\\');
1731 prev_is_slash
= false;
1735 prev_is_slash
= true;
1742 // -----------------------------------------------------------------------
1744 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1746 if ( src_str
.length() == 0 )
1752 wxString::const_iterator i
= src_str
.begin();
1753 wxUniChar prev_a
= wxS('\0');
1757 for ( ; i
!= src_str
.end(); ++i
)
1761 if ( a
>= wxS(' ') )
1763 // This surely is not something that requires an escape sequence.
1768 // This might need...
1769 if ( a
== wxS('\r') )
1771 // DOS style line end.
1772 // Already taken care below
1774 else if ( a
== wxS('\n') )
1775 // UNIX style line end.
1776 dst_str
<< wxS("\\n");
1777 else if ( a
== wxS('\t') )
1779 dst_str
<< wxS('\t');
1782 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1792 // -----------------------------------------------------------------------
1794 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1801 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1804 // -----------------------------------------------------------------------
1805 // wxPropertyGrid graphics related methods
1806 // -----------------------------------------------------------------------
1808 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1813 // Don't paint after destruction has begun
1814 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1817 // Find out where the window is scrolled to
1818 int vx
,vy
; // Top left corner of client
1819 GetViewStart(&vx
,&vy
);
1820 vy
*= wxPG_PIXELS_PER_UNIT
;
1822 // Update everything inside the box
1823 wxRect r
= GetUpdateRegion().GetBox();
1827 // FIXME: This is just a workaround for a bug that causes splitters not
1828 // to paint when other windows are being dragged over the grid.
1830 r
.width
= GetClientSize().x
;
1832 // Repaint this rectangle
1833 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1835 // We assume that the size set when grid is shown
1836 // is what is desired.
1837 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1840 // -----------------------------------------------------------------------
1842 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1843 wxPGProperty
* property
) const
1845 // Prepare rectangle to be used
1847 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1848 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1850 #if (wxPG_USE_RENDERER_NATIVE)
1852 #elif wxPG_ICON_WIDTH
1853 // Drawing expand/collapse button manually
1854 dc
.SetPen(m_colPropFore
);
1855 if ( property
->IsCategory() )
1856 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1858 dc
.SetBrush(m_colPropBack
);
1860 dc
.DrawRectangle( r
);
1861 int _y
= r
.y
+(m_iconWidth
/2);
1862 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1867 if ( property
->IsExpanded() )
1869 // wxRenderer functions are non-mutating in nature, so it
1870 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1871 // Hopefully this does not cause problems.
1872 #if (wxPG_USE_RENDERER_NATIVE)
1873 wxRendererNative::Get().DrawTreeItemButton(
1879 #elif wxPG_ICON_WIDTH
1888 #if (wxPG_USE_RENDERER_NATIVE)
1889 wxRendererNative::Get().DrawTreeItemButton(
1895 #elif wxPG_ICON_WIDTH
1896 int _x
= r
.x
+(m_iconWidth
/2);
1897 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1903 #if (wxPG_USE_RENDERER_NATIVE)
1905 #elif wxPG_ICON_WIDTH
1908 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1912 // -----------------------------------------------------------------------
1915 // This is the one called by OnPaint event handler and others.
1916 // topy and bottomy are already unscrolled (ie. physical)
1918 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1919 unsigned int topItemY
,
1920 unsigned int bottomItemY
,
1921 const wxRect
* drawRect
)
1925 bottomItemY
< topItemY
||
1929 m_pState
->EnsureVirtualHeight();
1931 wxRect tempDrawRect
;
1934 tempDrawRect
= wxRect(0, topItemY
,
1937 drawRect
= &tempDrawRect
;
1940 // items added check
1941 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1943 int paintFinishY
= 0;
1945 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1948 bool isBuffered
= false;
1950 #if wxPG_DOUBLE_BUFFER
1951 wxMemoryDC
* bufferDC
= NULL
;
1953 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1955 if ( !m_doubleBuffer
)
1957 paintFinishY
= drawRect
->y
;
1962 bufferDC
= new wxMemoryDC();
1964 // If nothing was changed, then just copy from double-buffer
1965 bufferDC
->SelectObject( *m_doubleBuffer
);
1975 dc
.SetClippingRegion( *drawRect
);
1976 paintFinishY
= DoDrawItems( *dcPtr
, drawRect
, isBuffered
);
1977 int drawBottomY
= drawRect
->y
+ drawRect
->height
;
1979 // Clear area beyond last painted property
1980 if ( paintFinishY
< drawBottomY
)
1982 dcPtr
->SetPen(m_colEmptySpace
);
1983 dcPtr
->SetBrush(m_colEmptySpace
);
1984 dcPtr
->DrawRectangle(0, paintFinishY
,
1989 dc
.DestroyClippingRegion();
1992 #if wxPG_DOUBLE_BUFFER
1995 dc
.Blit( drawRect
->x
, drawRect
->y
, drawRect
->width
,
1997 bufferDC
, 0, 0, wxCOPY
);
2004 // Just clear the area
2005 dc
.SetPen(m_colEmptySpace
);
2006 dc
.SetBrush(m_colEmptySpace
);
2007 dc
.DrawRectangle(*drawRect
);
2011 // -----------------------------------------------------------------------
2013 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
2014 const wxRect
* drawRect
,
2015 bool isBuffered
) const
2017 const wxPGProperty
* firstItem
;
2018 const wxPGProperty
* lastItem
;
2020 firstItem
= DoGetItemAtY(drawRect
->y
);
2021 lastItem
= DoGetItemAtY(drawRect
->y
+drawRect
->height
-1);
2024 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
2026 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
2029 wxCHECK_MSG( !m_pState
->m_itemsAdded
, drawRect
->y
,
2031 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2033 int lh
= m_lineHeight
;
2036 int lastItemBottomY
;
2038 firstItemTopY
= drawRect
->y
;
2039 lastItemBottomY
= drawRect
->y
+ drawRect
->height
;
2041 // Align y coordinates to item boundaries
2042 firstItemTopY
-= firstItemTopY
% lh
;
2043 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2044 lastItemBottomY
-= 1;
2046 // Entire range outside scrolled, visible area?
2047 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
2048 lastItemBottomY
<= 0 )
2051 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
2053 "invalid y values" );
2056 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
2057 "height=%i (ch=%i), drawRect = 0x%lX )",
2058 firstItem->GetLabel().c_str(),
2059 lastItem->GetLabel().c_str(),
2060 (int)(lastItemBottomY - firstItemTopY),
2062 (unsigned long)drawRect );
2067 long windowStyle
= m_windowStyle
;
2072 // With wxPG_DOUBLE_BUFFER, do double buffering
2073 // - buffer's y = 0, so align drawRect and coordinates to that
2075 #if wxPG_DOUBLE_BUFFER
2082 xRelMod
= drawRect
->x
;
2083 yRelMod
= drawRect
->y
;
2086 // drawRect conversion
2091 firstItemTopY
-= yRelMod
;
2092 lastItemBottomY
-= yRelMod
;
2095 wxUnusedVar(isBuffered
);
2098 int x
= m_marginWidth
- xRelMod
;
2100 wxFont normalFont
= GetFont();
2102 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2104 bool isPgEnabled
= IsEnabled();
2107 // Prepare some pens and brushes that are often changed to.
2110 wxBrush
marginBrush(m_colMargin
);
2111 wxPen
marginPen(m_colMargin
);
2112 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2113 wxPen
linepen(m_colLine
,1,wxSOLID
);
2115 wxColour selBackCol
;
2117 selBackCol
= m_colSelBack
;
2119 selBackCol
= m_colMargin
;
2121 // pen that has same colour as text
2122 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2125 // Clear margin with background colour
2127 dc
.SetBrush( marginBrush
);
2128 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2130 dc
.SetPen( *wxTRANSPARENT_PEN
);
2131 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2134 const wxPGProperty
* firstSelected
= GetSelection();
2135 const wxPropertyGridPageState
* state
= m_pState
;
2136 const wxArrayInt
& colWidths
= state
->m_colWidths
;
2138 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2139 bool wasSelectedPainted
= false;
2142 // TODO: Only render columns that are within clipping region.
2144 dc
.SetFont(normalFont
);
2146 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2147 int endScanBottomY
= lastItemBottomY
+ lh
;
2148 int y
= firstItemTopY
;
2151 // Pregenerate list of visible properties.
2152 wxArrayPGProperty visPropArray
;
2153 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2155 for ( ; !it
.AtEnd(); it
.Next() )
2157 const wxPGProperty
* p
= *it
;
2159 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2161 visPropArray
.push_back((wxPGProperty
*)p
);
2163 if ( y
> endScanBottomY
)
2170 visPropArray
.push_back(NULL
);
2172 wxPGProperty
* nextP
= visPropArray
[0];
2174 int gridWidth
= state
->m_width
;
2177 for ( unsigned int arrInd
=1;
2178 nextP
&& y
<= lastItemBottomY
;
2181 wxPGProperty
* p
= nextP
;
2182 nextP
= visPropArray
[arrInd
];
2184 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2185 int textMarginHere
= x
;
2186 int renderFlags
= 0;
2188 int greyDepth
= m_marginWidth
;
2189 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2190 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2192 int greyDepthX
= greyDepth
- xRelMod
;
2194 // Use basic depth if in non-categoric mode and parent is base array.
2195 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2197 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2200 // Paint margin area
2201 dc
.SetBrush(marginBrush
);
2202 dc
.SetPen(marginPen
);
2203 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2205 dc
.SetPen( linepen
);
2211 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2212 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2213 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2215 // Is this or its parent themed?
2216 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2217 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2218 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2220 bool suppressMarginEdge
= false;
2222 if (!suppressMarginEdge
)
2223 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2226 // Blank out the margin edge
2227 dc
.SetPen(wxPen(GetBackgroundColour()));
2228 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2229 dc
.SetPen( linepen
);
2236 for ( si
=0; si
<colWidths
.size(); si
++ )
2238 sx
+= colWidths
[si
];
2239 dc
.DrawLine( sx
, y
, sx
, y2
);
2242 // Horizontal Line, below
2243 // (not if both this and next is category caption)
2244 if ( p
->IsCategory() &&
2245 nextP
&& nextP
->IsCategory() )
2246 dc
.SetPen(m_colCapBack
);
2248 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2251 // Need to override row colours?
2255 bool isSelected
= state
->DoIsPropertySelected(p
);
2259 // Disabled may get different colour.
2260 if ( !p
->IsEnabled() )
2262 renderFlags
|= wxPGCellRenderer::Disabled
|
2263 wxPGCellRenderer::DontUseCellFgCol
;
2264 rowFgCol
= m_colDisPropFore
;
2269 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2270 if ( p
== firstSelected
)
2271 wasSelectedPainted
= true;
2274 renderFlags
|= wxPGCellRenderer::Selected
;
2276 if ( !p
->IsCategory() )
2278 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2279 wxPGCellRenderer::DontUseCellBgCol
;
2281 if ( reallyFocused
&& p
== firstSelected
)
2283 rowFgCol
= m_colSelFore
;
2284 rowBgCol
= selBackCol
;
2286 else if ( isPgEnabled
)
2288 rowFgCol
= m_colPropFore
;
2289 if ( p
== firstSelected
)
2290 rowBgCol
= m_colMargin
;
2292 rowBgCol
= selBackCol
;
2296 rowFgCol
= m_colDisPropFore
;
2297 rowBgCol
= selBackCol
;
2304 if ( rowBgCol
.IsOk() )
2305 rowBgBrush
= wxBrush(rowBgCol
);
2307 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2308 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2311 // Fill additional margin area with background colour of first cell
2312 if ( greyDepthX
< textMarginHere
)
2314 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2316 wxPGCell
& cell
= p
->GetCell(0);
2317 rowBgCol
= cell
.GetBgCol();
2318 rowBgBrush
= wxBrush(rowBgCol
);
2320 dc
.SetBrush(rowBgBrush
);
2321 dc
.SetPen(rowBgCol
);
2322 dc
.DrawRectangle(greyDepthX
+1, y
,
2323 textMarginHere
-greyDepthX
, lh
-1);
2326 bool fontChanged
= false;
2328 // Expander button rectangle
2329 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2334 // Default cell rect fill the entire row
2335 wxRect
cellRect(greyDepthX
, y
,
2336 gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2338 bool isCategory
= p
->IsCategory();
2342 dc
.SetFont(m_captionFont
);
2345 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2347 dc
.SetBrush(rowBgBrush
);
2348 dc
.SetPen(rowBgCol
);
2351 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2353 dc
.SetTextForeground(rowFgCol
);
2358 // Fine tune button rectangle to actually fit the cell
2359 if ( butRect
.x
> 0 )
2360 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2362 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&&
2363 (windowStyle
& wxPG_BOLD_MODIFIED
) )
2365 dc
.SetFont(m_captionFont
);
2369 // Magic fine-tuning for non-category rows
2373 int firstCellWidth
= colWidths
[0] - (greyDepthX
- m_marginWidth
);
2374 int firstCellX
= cellRect
.x
;
2376 // Calculate cellRect.x for the last cell
2377 unsigned int ci
= 0;
2379 for ( ci
=0; ci
<colWidths
.size(); ci
++ )
2380 cellX
+= colWidths
[ci
];
2383 // Draw cells from back to front so that we can easily tell if the
2384 // cell on the right was empty from text
2385 bool prevFilled
= true;
2386 ci
= colWidths
.size();
2395 textXAdd
= textMarginHere
- greyDepthX
;
2396 cellRect
.width
= firstCellWidth
;
2397 cellRect
.x
= firstCellX
;
2401 int colWidth
= colWidths
[ci
];
2402 cellRect
.width
= colWidth
;
2403 cellRect
.x
-= colWidth
;
2406 // Merge with column to the right?
2407 if ( !prevFilled
&& isCategory
)
2409 cellRect
.width
+= colWidths
[ci
+1];
2413 cellRect
.width
-= 1;
2415 wxWindow
* cellEditor
= NULL
;
2416 int cellRenderFlags
= renderFlags
;
2418 // Tree Item Button (must be drawn before clipping is set up)
2419 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2420 DrawExpanderButton( dc
, butRect
, p
);
2423 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2425 if ( p
== firstSelected
)
2427 if ( ci
== 1 && m_wndEditor
)
2428 cellEditor
= m_wndEditor
;
2429 else if ( ci
== m_selColumn
&& m_labelEditor
)
2430 cellEditor
= m_labelEditor
;
2435 wxColour editorBgCol
=
2436 cellEditor
->GetBackgroundColour();
2437 dc
.SetBrush(editorBgCol
);
2438 dc
.SetPen(editorBgCol
);
2439 dc
.SetTextForeground(m_colPropFore
);
2440 dc
.DrawRectangle(cellRect
);
2442 if ( m_dragStatus
!= 0 ||
2443 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2448 dc
.SetBrush(m_colPropBack
);
2449 dc
.SetPen(m_colPropBack
);
2450 if ( p
->IsEnabled() )
2451 dc
.SetTextForeground(m_colPropFore
);
2453 dc
.SetTextForeground(m_colDisPropFore
);
2458 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2460 dc
.SetBrush(rowBgBrush
);
2461 dc
.SetPen(rowBgCol
);
2464 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2466 dc
.SetTextForeground(rowFgCol
);
2470 dc
.SetClippingRegion(cellRect
);
2472 cellRect
.x
+= textXAdd
;
2473 cellRect
.width
-= textXAdd
;
2478 wxPGCellRenderer
* renderer
;
2479 int cmnVal
= p
->GetCommonValue();
2480 if ( cmnVal
== -1 || ci
!= 1 )
2482 renderer
= p
->GetCellRenderer(ci
);
2483 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2489 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2490 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2500 dc
.DestroyClippingRegion(); // Is this really necessary?
2505 dc
.SetFont(normalFont
);
2510 // Refresh editor controls (seems not needed on msw)
2511 // NOTE: This code is mandatory for GTK!
2512 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2513 if ( wasSelectedPainted
)
2516 m_wndEditor
->Refresh();
2518 m_wndEditor2
->Refresh();
2525 // -----------------------------------------------------------------------
2527 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2531 if ( m_width
< 10 || m_height
< 10 ||
2532 !m_pState
->m_properties
->GetChildCount() ||
2534 return wxRect(0,0,0,0);
2539 // Return rect which encloses the given property range
2540 // (in logical grid coordinates)
2543 int visTop
= p1
->GetY();
2546 visBottom
= p2
->GetY() + m_lineHeight
;
2548 visBottom
= m_height
+ visTop
;
2550 // If seleced property is inside the range, we'll extend the range to include
2552 wxPGProperty
* selected
= GetSelection();
2555 int selectedY
= selected
->GetY();
2556 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2558 wxWindow
* editor
= GetEditorControl();
2561 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2562 if ( visBottom2
> visBottom
)
2563 visBottom
= visBottom2
;
2568 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2571 // -----------------------------------------------------------------------
2573 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2578 if ( m_pState
->m_itemsAdded
)
2579 PrepareAfterItemsAdded();
2581 wxRect r
= GetPropertyRect(p1
, p2
);
2584 // Convert rectangle from logical grid coordinates to physical ones
2586 GetViewStart(&vx
, &vy
);
2587 vx
*= wxPG_PIXELS_PER_UNIT
;
2588 vy
*= wxPG_PIXELS_PER_UNIT
;
2595 // -----------------------------------------------------------------------
2597 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2599 if ( m_pState
->DoIsPropertySelected(p
) )
2601 // NB: We must copy the selection.
2602 wxArrayPGProperty selection
= m_pState
->m_selection
;
2603 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2606 DrawItemAndChildren(p
);
2609 // -----------------------------------------------------------------------
2611 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2616 // Draw item, children, and parent too, if it is not category
2617 wxPGProperty
* parent
= p
->GetParent();
2620 !parent
->IsCategory() &&
2621 parent
->GetParent() )
2624 parent
= parent
->GetParent();
2627 DrawItemAndChildren(p
);
2630 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2632 wxCHECK_RET( p
, wxT("invalid property id") );
2634 // Do not draw if in non-visible page
2635 if ( p
->GetParentState() != m_pState
)
2638 // do not draw a single item if multiple pending
2639 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2642 // Update child control.
2643 wxPGProperty
* selected
= GetSelection();
2644 if ( selected
&& selected
->GetParent() == p
)
2647 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2649 DrawItems(p
, lastDrawn
);
2652 // -----------------------------------------------------------------------
2654 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2655 const wxRect
*rect
)
2657 PrepareAfterItemsAdded();
2659 wxWindow::Refresh(false, rect
);
2661 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2662 // I think this really helps only GTK+1.2
2663 if ( m_wndEditor
) m_wndEditor
->Refresh();
2664 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2668 // -----------------------------------------------------------------------
2669 // wxPropertyGrid global operations
2670 // -----------------------------------------------------------------------
2672 void wxPropertyGrid::Clear()
2674 m_pState
->DoClear();
2680 RecalculateVirtualSize();
2682 // Need to clear some area at the end
2684 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2687 // -----------------------------------------------------------------------
2689 bool wxPropertyGrid::EnableCategories( bool enable
)
2696 // Enable categories
2699 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2704 // Disable categories
2706 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2709 if ( !m_pState
->EnableCategories(enable
) )
2714 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2716 m_pState
->m_itemsAdded
= 1; // force
2717 PrepareAfterItemsAdded();
2721 m_pState
->m_itemsAdded
= 1;
2723 // No need for RecalculateVirtualSize() here - it is already called in
2724 // wxPropertyGridPageState method above.
2731 // -----------------------------------------------------------------------
2733 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2735 wxASSERT( pNewState
);
2736 wxASSERT( pNewState
->GetGrid() );
2738 if ( pNewState
== m_pState
)
2741 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2743 // Call ClearSelection() instead of DoClearSelection()
2744 // so that selection clear events are not sent.
2747 m_pState
->m_selection
= oldSelection
;
2749 bool orig_mode
= m_pState
->IsInNonCatMode();
2750 bool new_state_mode
= pNewState
->IsInNonCatMode();
2752 m_pState
= pNewState
;
2755 int pgWidth
= GetClientSize().x
;
2756 if ( HasVirtualWidth() )
2758 int minWidth
= pgWidth
;
2759 if ( pNewState
->m_width
< minWidth
)
2761 pNewState
->m_width
= minWidth
;
2762 pNewState
->CheckColumnWidths();
2768 // Just in case, fully re-center splitter
2769 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2770 // pNewState->m_fSplitterX = -1.0;
2772 pNewState
->OnClientWidthChange(pgWidth
,
2773 pgWidth
- pNewState
->m_width
);
2778 // If necessary, convert state to correct mode.
2779 if ( orig_mode
!= new_state_mode
)
2781 // This should refresh as well.
2782 EnableCategories( orig_mode
?false:true );
2784 else if ( !m_frozen
)
2786 // Refresh, if not frozen.
2787 m_pState
->PrepareAfterItemsAdded();
2789 // Reselect (Use SetSelection() instead of Do-variant so that
2790 // events won't be sent).
2791 SetSelection(m_pState
->m_selection
);
2793 RecalculateVirtualSize(0);
2797 m_pState
->m_itemsAdded
= 1;
2800 // -----------------------------------------------------------------------
2802 // Call to SetSplitterPosition will always disable splitter auto-centering
2803 // if parent window is shown.
2804 void wxPropertyGrid::DoSetSplitterPosition( int newxpos
,
2808 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2811 wxPropertyGridPageState
* state
= m_pState
;
2813 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2814 state
->m_dontCenterSplitter
= true;
2816 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2818 if ( flags
& wxPG_SPLITTER_REFRESH
)
2820 if ( GetSelection() )
2821 CorrectEditorWidgetSizeX();
2829 // -----------------------------------------------------------------------
2831 void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing
)
2833 wxPropertyGridPageState
* state
= m_pState
;
2835 state
->ResetColumnSizes(0);
2837 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2838 m_pState
->m_dontCenterSplitter
= false;
2841 // -----------------------------------------------------------------------
2843 void wxPropertyGrid::CenterSplitter( bool enableAutoResizing
)
2845 SetSplitterPosition( m_width
/2 );
2846 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2847 m_pState
->m_dontCenterSplitter
= false;
2850 // -----------------------------------------------------------------------
2851 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2852 // -----------------------------------------------------------------------
2854 // Returns nearest paint visible property (such that will be painted unless
2855 // window is scrolled or resized). If given property is paint visible, then
2856 // it itself will be returned
2857 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2859 int vx
,vy1
;// Top left corner of client
2860 GetViewStart(&vx
,&vy1
);
2861 vy1
*= wxPG_PIXELS_PER_UNIT
;
2863 int vy2
= vy1
+ m_height
;
2864 int propY
= p
->GetY2(m_lineHeight
);
2866 if ( (propY
+ m_lineHeight
) < vy1
)
2869 return DoGetItemAtY( vy1
);
2871 else if ( propY
> vy2
)
2874 return DoGetItemAtY( vy2
);
2877 // Itself paint visible
2882 // -----------------------------------------------------------------------
2883 // Methods related to change in value, value modification and sending events
2884 // -----------------------------------------------------------------------
2886 // commits any changes in editor of selected property
2887 // return true if validation did not fail
2888 // flags are same as with DoSelectProperty
2889 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2891 // Committing already?
2892 if ( m_inCommitChangesFromEditor
)
2895 // Don't do this if already processing editor event. It might
2896 // induce recursive dialogs and crap like that.
2897 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2899 if ( m_inDoPropertyChanged
)
2905 wxPGProperty
* selected
= GetSelection();
2908 IsEditorsValueModified() &&
2909 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2912 m_inCommitChangesFromEditor
= 1;
2914 wxVariant
variant(selected
->GetValueRef());
2915 bool valueIsPending
= false;
2917 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2918 // due to another window getting focus
2919 wxWindow
* oldFocus
= m_curFocused
;
2921 bool validationFailure
= false;
2922 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2924 m_chgInfo_changedProperty
= NULL
;
2926 // If truly modified, schedule value as pending.
2927 if ( selected
->GetEditorClass()->
2928 GetValueFromControl( variant
,
2930 GetEditorControl() ) )
2932 if ( DoEditorValidate() &&
2933 PerformValidation(selected
, variant
) )
2935 valueIsPending
= true;
2939 validationFailure
= true;
2944 EditorsValueWasNotModified();
2949 m_inCommitChangesFromEditor
= 0;
2951 if ( validationFailure
&& !forceSuccess
)
2955 oldFocus
->SetFocus();
2956 m_curFocused
= oldFocus
;
2959 res
= OnValidationFailure(selected
, variant
);
2961 // Now prevent further validation failure messages
2964 EditorsValueWasNotModified();
2965 OnValidationFailureReset(selected
);
2968 else if ( valueIsPending
)
2970 DoPropertyChanged( selected
, flags
);
2971 EditorsValueWasNotModified();
2980 // -----------------------------------------------------------------------
2982 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2986 // Runs all validation functionality.
2987 // Returns true if value passes all tests.
2990 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2993 // Variant list a special value that cannot be validated
2995 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2997 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
3002 // Adapt list to child values, if necessary
3003 wxVariant listValue
= pendingValue
;
3004 wxVariant
* pPendingValue
= &pendingValue
;
3005 wxVariant
* pList
= NULL
;
3007 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
3008 // string value, then we need treat as it was changed instead
3009 // (or, in addition, as is the case with composite string parent).
3010 // This includes creating list variant for child values.
3012 wxPGProperty
* pwc
= p
->GetParent();
3013 wxPGProperty
* changedProperty
= p
;
3014 wxPGProperty
* baseChangedProperty
= changedProperty
;
3015 wxVariant bcpPendingList
;
3017 listValue
= pendingValue
;
3018 listValue
.SetName(p
->GetBaseName());
3021 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
3023 wxVariantList tempList
;
3024 wxVariant
lv(tempList
, pwc
->GetBaseName());
3025 lv
.Append(listValue
);
3027 pPendingValue
= &listValue
;
3029 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
3031 baseChangedProperty
= pwc
;
3032 bcpPendingList
= lv
;
3035 changedProperty
= pwc
;
3036 pwc
= pwc
->GetParent();
3040 wxPGProperty
* evtChangingProperty
= changedProperty
;
3042 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
3044 value
= *pPendingValue
;
3048 // Convert list to child values
3049 pList
= pPendingValue
;
3050 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
3053 wxVariant evtChangingValue
= value
;
3055 if ( flags
& SendEvtChanging
)
3057 // FIXME: After proper ValueToString()s added, remove
3058 // this. It is just a temporary fix, as evt_changing
3059 // will simply not work for wxPG_PROP_COMPOSED_VALUE
3060 // (unless it is selected, and textctrl editor is open).
3061 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3063 evtChangingProperty
= baseChangedProperty
;
3064 if ( evtChangingProperty
!= p
)
3066 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
3070 evtChangingValue
= pendingValue
;
3074 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3076 if ( changedProperty
== GetSelection() )
3078 wxWindow
* editor
= GetEditorControl();
3079 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
3080 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
3084 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
3089 wxASSERT( m_chgInfo_changedProperty
== NULL
);
3090 m_chgInfo_changedProperty
= changedProperty
;
3091 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
3092 m_chgInfo_pendingValue
= value
;
3095 m_chgInfo_valueList
= *pList
;
3097 m_chgInfo_valueList
.MakeNull();
3099 // If changedProperty is not property which value was edited,
3100 // then call wxPGProperty::ValidateValue() for that as well.
3101 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3103 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3107 if ( flags
& SendEvtChanging
)
3109 // SendEvent returns true if event was vetoed
3110 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3111 &evtChangingValue
) )
3115 if ( flags
& IsStandaloneValidation
)
3117 // If called in 'generic' context, we need to reset
3118 // m_chgInfo_changedProperty and write back translated value.
3119 m_chgInfo_changedProperty
= NULL
;
3120 pendingValue
= value
;
3126 // -----------------------------------------------------------------------
3128 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3130 if ( !msg
.length() )
3134 if ( !wxPGGlobalVars
->m_offline
)
3136 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3139 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
3142 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
3145 pStatusBar
->SetStatusText(msg
);
3153 ::wxMessageBox(msg
, wxT("Property Error"));
3156 // -----------------------------------------------------------------------
3158 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3159 wxVariant
& invalidValue
)
3161 wxWindow
* editor
= GetEditorControl();
3163 // First call property's handler
3164 property
->OnValidationFailure(invalidValue
);
3166 bool res
= DoOnValidationFailure(property
, invalidValue
);
3169 // For non-wxTextCtrl editors, we do need to revert the value
3170 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3171 property
== GetSelection() )
3173 property
->GetEditorClass()->UpdateControl(property
, editor
);
3176 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3181 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3183 int vfb
= m_validationInfo
.m_failureBehavior
;
3185 if ( vfb
& wxPG_VFB_BEEP
)
3188 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3189 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3191 unsigned int colCount
= m_pState
->GetColumnCount();
3193 // We need backup marked property's cells
3194 m_propCellsBackup
= property
->m_cells
;
3196 wxColour vfbFg
= *wxWHITE
;
3197 wxColour vfbBg
= *wxRED
;
3199 property
->EnsureCells(colCount
);
3201 for ( unsigned int i
=0; i
<colCount
; i
++ )
3203 wxPGCell
& cell
= property
->m_cells
[i
];
3204 cell
.SetFgCol(vfbFg
);
3205 cell
.SetBgCol(vfbBg
);
3208 DrawItemAndChildren(property
);
3210 if ( property
== GetSelection() )
3212 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3214 wxWindow
* editor
= GetEditorControl();
3217 editor
->SetForegroundColour(vfbFg
);
3218 editor
->SetBackgroundColour(vfbBg
);
3223 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3225 wxString msg
= m_validationInfo
.m_failureMessage
;
3227 if ( !msg
.length() )
3228 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
3230 DoShowPropertyError(property
, msg
);
3233 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3236 // -----------------------------------------------------------------------
3238 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3240 int vfb
= m_validationInfo
.m_failureBehavior
;
3242 if ( vfb
& wxPG_VFB_MARK_CELL
)
3245 property
->m_cells
= m_propCellsBackup
;
3247 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3249 if ( property
== GetSelection() && GetEditorControl() )
3251 // Calling this will recreate the control, thus resetting its colour
3252 RefreshProperty(property
);
3256 DrawItemAndChildren(property
);
3261 // -----------------------------------------------------------------------
3263 // flags are same as with DoSelectProperty
3264 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3266 if ( m_inDoPropertyChanged
)
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 // NB: Call GetEditorControl() as late as possible, because OnSetValue()
3293 // and perhaps other user-defined virtual functions may change it.
3294 wxWindow
* editor
= GetEditorControl();
3296 // Set as Modified (not if dragging just began)
3297 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3299 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3300 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3303 SetCurControlBoldFont();
3309 // Propagate updates to parent(s)
3311 wxPGProperty
* prevPwc
= NULL
;
3313 while ( prevPwc
!= topPaintedProperty
)
3315 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3317 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3320 SetCurControlBoldFont();
3324 pwc
= pwc
->GetParent();
3327 // Draw the actual property
3328 DrawItemAndChildren( topPaintedProperty
);
3331 // If value was set by wxPGProperty::OnEvent, then update the editor
3333 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3339 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3340 if ( m_wndEditor
) m_wndEditor
->Refresh();
3341 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3346 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3348 // If top parent has composite string value, then send to child parents,
3349 // starting from baseChangedProperty.
3350 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3352 pwc
= m_chgInfo_baseChangedProperty
;
3354 while ( pwc
!= changedProperty
)
3356 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3357 pwc
= pwc
->GetParent();
3361 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3363 m_inDoPropertyChanged
= 0;
3368 // -----------------------------------------------------------------------
3370 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3372 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3374 m_chgInfo_changedProperty
= NULL
;
3376 if ( PerformValidation(p
, newValue
) )
3378 DoPropertyChanged(p
);
3383 OnValidationFailure(p
, newValue
);
3389 // -----------------------------------------------------------------------
3391 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3393 wxPGProperty
* prop
= GetSelectedProperty();
3396 return wxNullVariant
;
3398 wxTextCtrl
* tc
= GetEditorTextCtrl();
3399 wxVariant value
= prop
->GetValue();
3401 if ( !tc
|| !IsEditorsValueModified() )
3404 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3407 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3408 return prop
->GetValue();
3413 // -----------------------------------------------------------------------
3415 // Runs wxValidator for the selected property
3416 bool wxPropertyGrid::DoEditorValidate()
3418 #if wxUSE_VALIDATORS
3419 wxRecursionGuard
guard(m_validatingEditor
);
3420 if ( guard
.IsInside() )
3423 wxPGProperty
* selected
= GetSelection();
3426 wxWindow
* wnd
= GetEditorControl();
3428 wxValidator
* validator
= selected
->GetValidator();
3429 if ( validator
&& wnd
)
3431 validator
->SetWindow(wnd
);
3432 if ( !validator
->Validate(this) )
3440 // -----------------------------------------------------------------------
3442 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3444 // It is possible that this handler receives event even before
3445 // the control has been properly initialized. Let's skip the
3446 // event handling in that case.
3450 // Don't care about the event if it originated from the
3451 // 'label editor'. In this function we only care about the
3452 // property value editor.
3453 if ( m_labelEditor
&& event
.GetId() == m_labelEditor
->GetId() )
3459 wxPGProperty
* selected
= GetSelection();
3461 // Somehow, event is handled after property has been deselected.
3462 // Possibly, but very rare.
3464 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3465 // Also don't handle editor event if wxEVT_PG_CHANGED or
3466 // similar is currently doing something (showing a
3467 // message box, for instance).
3471 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3474 wxVariant
pendingValue(selected
->GetValueRef());
3475 wxWindow
* wnd
= GetEditorControl();
3476 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3478 bool wasUnspecified
= selected
->IsValueUnspecified();
3479 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3480 bool valueIsPending
= false;
3482 m_chgInfo_changedProperty
= NULL
;
3484 m_iFlags
&= ~wxPG_FL_VALUE_CHANGE_IN_EVENT
;
3487 // Filter out excess wxTextCtrl modified events
3488 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&& wnd
)
3490 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3492 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3494 wxString newTcValue
= tc
->GetValue();
3495 if ( m_prevTcValue
== newTcValue
)
3497 m_prevTcValue
= newTcValue
;
3499 else if ( wnd
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
3501 wxComboCtrl
* cc
= (wxComboCtrl
*) wnd
;
3503 wxString newTcValue
= cc
->GetTextCtrl()->GetValue();
3504 if ( m_prevTcValue
== newTcValue
)
3506 m_prevTcValue
= newTcValue
;
3510 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3512 bool validationFailure
= false;
3513 bool buttonWasHandled
= false;
3516 // Try common button handling
3517 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3519 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3523 buttonWasHandled
= true;
3524 // Store as res2, as previously (and still currently alternatively)
3525 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3526 // in wxPGProperty::OnEvent().
3527 adapter
->ShowDialog( this, selected
);
3532 if ( !buttonWasHandled
)
3534 if ( wnd
|| m_wndEditor2
)
3536 // First call editor class' event handler.
3537 const wxPGEditor
* editor
= selected
->GetEditorClass();
3539 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3541 // If changes, validate them
3542 if ( DoEditorValidate() )
3544 if ( editor
->GetValueFromControl( pendingValue
,
3547 valueIsPending
= true;
3551 validationFailure
= true;
3556 // Then the property's custom handler (must be always called, unless
3557 // validation failed).
3558 if ( !validationFailure
)
3559 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3562 // SetValueInEvent(), as called in one of the functions referred above
3563 // overrides editor's value.
3564 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3566 valueIsPending
= true;
3567 pendingValue
= m_changeInEventValue
;
3568 selFlags
|= wxPG_SEL_DIALOGVAL
;
3571 if ( !validationFailure
&& valueIsPending
)
3572 if ( !PerformValidation(selected
, pendingValue
) )
3573 validationFailure
= true;
3575 if ( validationFailure
)
3577 OnValidationFailure(selected
, pendingValue
);
3579 else if ( valueIsPending
)
3581 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3583 DoPropertyChanged(selected
, selFlags
);
3584 EditorsValueWasNotModified();
3586 // Regardless of editor type, unfocus editor on
3587 // text-editing related enter press.
3588 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3595 // No value after all
3597 // Regardless of editor type, unfocus editor on
3598 // text-editing related enter press.
3599 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3604 // Let unhandled button click events go to the parent
3605 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3607 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3608 GetEventHandler()->AddPendingEvent(evt
);
3612 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3615 // -----------------------------------------------------------------------
3616 // wxPropertyGrid editor control helper methods
3617 // -----------------------------------------------------------------------
3619 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3621 int itemy
= p
->GetY2(m_lineHeight
);
3622 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3623 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3624 int imageOffset
= 0;
3626 int vx
, vy
; // Top left corner of client
3627 GetViewStart(&vx
, &vy
);
3628 vy
*= wxPG_PIXELS_PER_UNIT
;
3632 // TODO: If custom image detection changes from current, change this.
3633 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3635 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3636 int iw
= p
->OnMeasureImage().x
;
3638 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3639 imageOffset
= p
->GetImageOffset(iw
);
3642 else if ( column
== 0 )
3644 splitterX
+= (p
->m_depth
- 1) * m_subgroup_extramargin
;
3649 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3651 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3656 // -----------------------------------------------------------------------
3658 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3660 wxSize sz
= GetImageSize(p
, item
);
3661 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3662 wxPG_CUSTOM_IMAGE_SPACINGY
,
3667 // return size of custom paint image
3668 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3670 // If called with NULL property, then return default image
3671 // size for properties that use image.
3673 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3675 wxSize cis
= p
->OnMeasureImage(item
);
3677 int choiceCount
= p
->m_choices
.GetCount();
3678 int comVals
= p
->GetDisplayedCommonValueCount();
3679 if ( item
>= choiceCount
&& comVals
> 0 )
3681 unsigned int cvi
= item
-choiceCount
;
3682 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3684 else if ( item
>= 0 && choiceCount
== 0 )
3685 return wxSize(0, 0);
3690 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3695 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3702 // -----------------------------------------------------------------------
3704 // takes scrolling into account
3705 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3708 GetViewStart(&vx
,&vy
);
3709 vy
*=wxPG_PIXELS_PER_UNIT
;
3710 vx
*=wxPG_PIXELS_PER_UNIT
;
3713 ClientToScreen( px
, py
);
3716 // -----------------------------------------------------------------------
3718 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3721 GetViewStart(&pt2
.x
,&pt2
.y
);
3722 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3723 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3727 return m_pState
->HitTest(pt2
);
3730 // -----------------------------------------------------------------------
3732 // custom set cursor
3733 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3735 if ( type
== m_curcursor
&& !override
) return;
3737 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3739 if ( type
== wxCURSOR_SIZEWE
)
3740 cursor
= m_cursorSizeWE
;
3742 SetCursor( *cursor
);
3747 // -----------------------------------------------------------------------
3750 wxPropertyGrid::GetUnspecifiedValueText( int argFlags
) const
3752 const wxPGCell
& ua
= GetUnspecifiedValueAppearance();
3754 if ( ua
.HasText() &&
3755 !(argFlags
& wxPG_FULL_VALUE
) &&
3756 !(argFlags
& wxPG_EDITABLE_VALUE
) )
3757 return ua
.GetText();
3759 return wxEmptyString
;
3762 // -----------------------------------------------------------------------
3763 // wxPropertyGrid property selection, editor creation
3764 // -----------------------------------------------------------------------
3767 // This class forwards events from property editor controls to wxPropertyGrid.
3768 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3771 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3772 : wxEvtHandler(), m_propGrid(propGrid
)
3776 virtual ~wxPropertyGridEditorEventForwarder()
3781 bool ProcessEvent( wxEvent
& event
)
3786 m_propGrid
->HandleCustomEditorEvent(event
);
3789 // NB: On wxMSW, a wxTextCtrl with wxTE_PROCESS_ENTER
3790 // may beep annoyingly if that event is skipped
3791 // and passed to parent event handler.
3792 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3795 return wxEvtHandler::ProcessEvent(event
);
3798 wxPropertyGrid
* m_propGrid
;
3801 // Setups event handling for child control
3802 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3804 wxWindowID id
= argWnd
->GetId();
3806 if ( argWnd
== m_wndEditor
)
3808 argWnd
->Connect(id
, wxEVT_MOTION
,
3809 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3811 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3812 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3814 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3815 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3817 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3818 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3820 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3821 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3823 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3824 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3828 wxPropertyGridEditorEventForwarder
* forwarder
;
3829 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3830 argWnd
->PushEventHandler(forwarder
);
3832 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3833 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3837 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3844 // Do not free editors immediately (for sake of processing events)
3845 wxPendingDelete
.Append(wnd
);
3848 void wxPropertyGrid::FreeEditors()
3851 // Return focus back to canvas from children (this is required at least for
3852 // GTK+, which, unlike Windows, clears focus when control is destroyed
3853 // instead of moving it to closest parent).
3854 wxWindow
* focus
= wxWindow::FindFocus();
3857 wxWindow
* parent
= focus
->GetParent();
3860 if ( parent
== this )
3865 parent
= parent
->GetParent();
3869 // Do not free editors immediately if processing events
3872 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3873 m_wndEditor2
->Hide();
3874 wxPendingDelete
.Append( handler
);
3875 DestroyEditorWnd(m_wndEditor2
);
3876 m_wndEditor2
= NULL
;
3881 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3882 m_wndEditor
->Hide();
3883 wxPendingDelete
.Append( handler
);
3884 DestroyEditorWnd(m_wndEditor
);
3889 // Call with NULL to de-select property
3890 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3895 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3896 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3900 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3904 if ( m_inDoSelectProperty
)
3907 m_inDoSelectProperty
= 1;
3911 m_inDoSelectProperty
= 0;
3915 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3916 wxPGProperty
* prevFirstSel
;
3918 if ( prevSelection
.size() > 0 )
3919 prevFirstSel
= prevSelection
[0];
3921 prevFirstSel
= NULL
;
3923 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3924 prevFirstSel
= NULL
;
3926 // Always send event, as this is indirect call
3927 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
3931 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3933 wxPrintf( "None selected\n" );
3936 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3938 wxPrintf( "P = NULL\n" );
3941 // If we are frozen, then just set the values.
3944 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3945 m_editorFocused
= 0;
3946 m_pState
->DoSetSelection(p
);
3948 // If frozen, always free controls. But don't worry, as Thaw will
3949 // recall SelectProperty to recreate them.
3952 // Prevent any further selection measures in this call
3958 if ( prevFirstSel
== p
&&
3959 prevSelection
.size() <= 1 &&
3960 !(flags
& wxPG_SEL_FORCE
) )
3962 // Only set focus if not deselecting
3965 if ( flags
& wxPG_SEL_FOCUS
)
3969 m_wndEditor
->SetFocus();
3970 m_editorFocused
= 1;
3979 m_inDoSelectProperty
= 0;
3984 // First, deactivate previous
3987 OnValidationFailureReset(prevFirstSel
);
3989 // Must double-check if this is an selected in case of forceswitch
3990 if ( p
!= prevFirstSel
)
3992 if ( !CommitChangesFromEditor(flags
) )
3994 // Validation has failed, so we can't exit the previous editor
3995 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3996 // _("Invalid Value"),wxOK|wxICON_ERROR);
3997 m_inDoSelectProperty
= 0;
4004 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4005 EditorsValueWasNotModified();
4008 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4010 m_pState
->DoSetSelection(p
);
4012 // Redraw unselected
4013 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
4015 DrawItem(prevSelection
[i
]);
4019 // Then, activate the one given.
4022 int propY
= p
->GetY2(m_lineHeight
);
4024 int splitterX
= GetSplitterPosition();
4025 m_editorFocused
= 0;
4026 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
4028 wxASSERT( m_wndEditor
== NULL
);
4031 // Only create editor for non-disabled non-caption
4032 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
4034 // do this for non-caption items
4038 // Do we need to paint the custom image, if any?
4039 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
4040 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
4041 !p
->GetEditorClass()->CanContainCustomImage()
4043 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
4045 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
4046 wxPoint goodPos
= grect
.GetPosition();
4048 // Editor appearance can now be considered clear
4049 m_editorAppearance
.SetEmptyData();
4051 const wxPGEditor
* editor
= p
->GetEditorClass();
4052 wxCHECK_MSG(editor
, false,
4053 wxT("NULL editor class not allowed"));
4055 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
4057 wxPGWindowList wndList
=
4058 editor
->CreateControls(this,
4063 m_wndEditor
= wndList
.m_primary
;
4064 m_wndEditor2
= wndList
.m_secondary
;
4065 wxWindow
* primaryCtrl
= GetEditorControl();
4068 // Essentially, primaryCtrl == m_wndEditor
4071 // NOTE: It is allowed for m_wndEditor to be NULL - in this
4072 // case value is drawn as normal, and m_wndEditor2 is
4073 // assumed to be a right-aligned button that triggers
4074 // a separate editorCtrl window.
4078 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
4079 "CreateControls must use result of "
4080 "wxPropertyGrid::GetPanel() as parent "
4083 // Set validator, if any
4084 #if wxUSE_VALIDATORS
4085 wxValidator
* validator
= p
->GetValidator();
4087 primaryCtrl
->SetValidator(*validator
);
4090 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
4091 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
4093 // If it has modified status, use bold font
4094 // (must be done before capturing m_ctrlXAdjust)
4095 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
4096 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
4097 SetCurControlBoldFont();
4099 // Store x relative to splitter (we'll need it).
4100 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
4102 // Check if background clear is not necessary
4103 wxPoint pos
= m_wndEditor
->GetPosition();
4104 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
4106 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
4109 m_wndEditor
->SetSizeHints(3, 3);
4111 SetupChildEventHandling(primaryCtrl
);
4113 // Focus and select all (wxTextCtrl, wxComboBox etc)
4114 if ( flags
& wxPG_SEL_FOCUS
)
4116 primaryCtrl
->SetFocus();
4118 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
4122 if ( p
->IsValueUnspecified() )
4123 SetEditorAppearance(m_unspecifiedAppearance
,
4130 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
4131 "CreateControls must use result of "
4132 "wxPropertyGrid::GetPanel() as parent "
4135 // Get proper id for wndSecondary
4136 m_wndSecId
= m_wndEditor2
->GetId();
4137 wxWindowList children
= m_wndEditor2
->GetChildren();
4138 wxWindowList::iterator node
= children
.begin();
4139 if ( node
!= children
.end() )
4140 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
4142 m_wndEditor2
->SetSizeHints(3,3);
4144 m_wndEditor2
->Show();
4146 SetupChildEventHandling(m_wndEditor2
);
4148 // If no primary editor, focus to button to allow
4149 // it to interprete ENTER etc.
4150 // NOTE: Due to problems focusing away from it, this
4151 // has been disabled.
4153 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
4154 m_wndEditor2->SetFocus();
4158 if ( flags
& wxPG_SEL_FOCUS
)
4159 m_editorFocused
= 1;
4164 // Make sure focus is in grid canvas (important for wxGTK,
4169 EditorsValueWasNotModified();
4171 // If it's inside collapsed section, expand parent, scroll, etc.
4172 // Also, if it was partially visible, scroll it into view.
4173 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
4178 m_wndEditor
->Show(true);
4181 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
4186 // Make sure focus is in grid canvas
4190 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4196 // Show help text in status bar.
4197 // (if found and grid not embedded in manager with help box and
4198 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4201 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4203 wxStatusBar
* statusbar
= NULL
;
4204 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
4206 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
4208 statusbar
= frame
->GetStatusBar();
4213 const wxString
* pHelpString
= (const wxString
*) NULL
;
4217 pHelpString
= &p
->GetHelpString();
4218 if ( pHelpString
->length() )
4220 // Set help box text.
4221 statusbar
->SetStatusText( *pHelpString
);
4222 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4226 if ( (!pHelpString
|| !pHelpString
->length()) &&
4227 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
4229 // Clear help box - but only if it was written
4230 // by us at previous time.
4231 statusbar
->SetStatusText( m_emptyString
);
4232 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4238 m_inDoSelectProperty
= 0;
4240 // call wx event handler (here so that it also occurs on deselection)
4241 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4242 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4247 // -----------------------------------------------------------------------
4249 bool wxPropertyGrid::UnfocusEditor()
4251 wxPGProperty
* selected
= GetSelection();
4253 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4256 if ( !CommitChangesFromEditor(0) )
4265 // -----------------------------------------------------------------------
4267 void wxPropertyGrid::RefreshEditor()
4269 wxPGProperty
* p
= GetSelection();
4273 wxWindow
* wnd
= GetEditorControl();
4277 // Set editor font boldness - must do this before
4278 // calling UpdateControl().
4279 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4281 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4282 wnd
->SetFont(GetCaptionFont());
4284 wnd
->SetFont(GetFont());
4287 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4289 editorClass
->UpdateControl(p
, wnd
);
4291 if ( p
->IsValueUnspecified() )
4292 SetEditorAppearance(m_unspecifiedAppearance
, true);
4295 // -----------------------------------------------------------------------
4297 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4299 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4301 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4303 flags
|= wxPG_SEL_FOCUS
;
4305 return DoSelectProperty(p
, flags
);
4308 // -----------------------------------------------------------------------
4309 // wxPropertyGrid expand/collapse state
4310 // -----------------------------------------------------------------------
4312 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4314 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4315 wxPGProperty
* selected
= GetSelection();
4317 // If active editor was inside collapsed section, then disable it
4318 if ( selected
&& selected
->IsSomeParent(p
) )
4323 // Store dont-center-splitter flag 'cause we need to temporarily set it
4324 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4325 m_pState
->m_dontCenterSplitter
= true;
4327 bool res
= m_pState
->DoCollapse(pwc
);
4332 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4334 RecalculateVirtualSize();
4338 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4343 // -----------------------------------------------------------------------
4345 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4347 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4349 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4351 // Store dont-center-splitter flag 'cause we need to temporarily set it
4352 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4353 m_pState
->m_dontCenterSplitter
= true;
4355 bool res
= m_pState
->DoExpand(pwc
);
4360 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4362 RecalculateVirtualSize();
4366 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4371 // -----------------------------------------------------------------------
4373 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4376 return m_pState
->DoHideProperty(p
, hide
, flags
);
4378 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4379 int selRemoveCount
= 0;
4380 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4382 wxPGProperty
* selected
= selection
[i
];
4383 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4385 if ( !DoRemoveFromSelection(p
, flags
) )
4387 selRemoveCount
+= 1;
4391 m_pState
->DoHideProperty(p
, hide
, flags
);
4393 RecalculateVirtualSize();
4400 // -----------------------------------------------------------------------
4401 // wxPropertyGrid size related methods
4402 // -----------------------------------------------------------------------
4404 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4406 // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise
4407 // virtual size calculation may go wrong.
4408 if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4414 // If virtual height was changed, then recalculate editor control position(s)
4415 if ( m_pState
->m_vhCalcPending
)
4416 CorrectEditorWidgetPosY();
4418 m_pState
->EnsureVirtualHeight();
4420 wxASSERT_LEVEL_2_MSG(
4421 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4422 "VirtualHeight and ActualVirtualHeight should match"
4425 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4427 int x
= m_pState
->m_width
;
4428 int y
= m_pState
->m_virtualHeight
;
4431 GetClientSize(&width
,&height
);
4433 // Now adjust virtual size.
4434 SetVirtualSize(x
, y
);
4440 // Adjust scrollbars
4441 if ( HasVirtualWidth() )
4443 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4444 xPos
= GetScrollPos( wxHORIZONTAL
);
4447 if ( forceXPos
!= -1 )
4450 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4453 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4454 int yPos
= GetScrollPos( wxVERTICAL
);
4456 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4457 xAmount
, yAmount
, xPos
, yPos
, true );
4459 // Must re-get size now
4460 GetClientSize(&width
,&height
);
4462 if ( !HasVirtualWidth() )
4464 m_pState
->SetVirtualWidth(width
);
4471 m_pState
->CheckColumnWidths();
4473 if ( GetSelection() )
4474 CorrectEditorWidgetSizeX();
4476 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4479 // -----------------------------------------------------------------------
4481 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4483 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4487 GetClientSize(&width
, &height
);
4492 #if wxPG_DOUBLE_BUFFER
4493 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4495 int dblh
= (m_lineHeight
*2);
4496 if ( !m_doubleBuffer
)
4498 // Create double buffer bitmap to draw on, if none
4499 int w
= (width
>250)?width
:250;
4500 int h
= height
+ dblh
;
4502 m_doubleBuffer
= new wxBitmap( w
, h
);
4506 int w
= m_doubleBuffer
->GetWidth();
4507 int h
= m_doubleBuffer
->GetHeight();
4509 // Double buffer must be large enough
4510 if ( w
< width
|| h
< (height
+dblh
) )
4512 if ( w
< width
) w
= width
;
4513 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4514 delete m_doubleBuffer
;
4515 m_doubleBuffer
= new wxBitmap( w
, h
);
4522 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4523 m_ncWidth
= event
.GetSize().x
;
4527 if ( m_pState
->m_itemsAdded
)
4528 PrepareAfterItemsAdded();
4530 // Without this, virtual size (atleast under wxGTK) will be skewed
4531 RecalculateVirtualSize();
4537 // -----------------------------------------------------------------------
4539 void wxPropertyGrid::SetVirtualWidth( int width
)
4543 // Disable virtual width
4544 width
= GetClientSize().x
;
4545 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4549 // Enable virtual width
4550 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4552 m_pState
->SetVirtualWidth( width
);
4555 void wxPropertyGrid::SetFocusOnCanvas()
4557 SetFocusIgnoringChildren();
4558 m_editorFocused
= 0;
4561 // -----------------------------------------------------------------------
4562 // wxPropertyGrid mouse event handling
4563 // -----------------------------------------------------------------------
4565 // selFlags uses same values DoSelectProperty's flags
4566 // Returns true if event was vetoed.
4567 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4569 unsigned int selFlags
,
4570 unsigned int column
)
4572 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4575 // Send property grid event of specific type and with specific property
4576 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4577 evt
.SetPropertyGrid(this);
4578 evt
.SetEventObject(m_eventObject
);
4580 evt
.SetColumn(column
);
4581 if ( eventType
== wxEVT_PG_CHANGING
)
4584 evt
.SetCanVeto(true);
4585 m_validationInfo
.m_pValue
= pValue
;
4586 evt
.SetupValidationInfo();
4591 evt
.SetPropertyValue(p
->GetValue());
4593 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4594 evt
.SetCanVeto(true);
4597 wxPropertyGridEvent
* prevProcessedEvent
= m_processedEvent
;
4598 m_processedEvent
= &evt
;
4599 m_eventObject
->HandleWindowEvent(evt
);
4600 m_processedEvent
= prevProcessedEvent
;
4602 return evt
.WasVetoed();
4605 // -----------------------------------------------------------------------
4607 // Return false if should be skipped
4608 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4612 // Need to set focus?
4613 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4618 wxPropertyGridPageState
* state
= m_pState
;
4620 int splitterHitOffset
;
4621 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4623 wxPGProperty
* p
= DoGetItemAtY(y
);
4627 int depth
= (int)p
->GetDepth() - 1;
4629 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4631 if ( x
>= marginEnds
)
4635 if ( p
->IsCategory() )
4637 // This is category.
4638 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4640 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4642 // Expand, collapse, activate etc. if click on text or left of splitter.
4645 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4650 if ( !AddToSelectionFromInputEvent( p
,
4655 // On double-click, expand/collapse.
4656 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4658 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4659 else DoExpand( p
, true );
4663 else if ( splitterHit
== -1 )
4666 unsigned int selFlag
= 0;
4667 if ( columnHit
== 1 )
4669 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4670 selFlag
= wxPG_SEL_FOCUS
;
4672 if ( !AddToSelectionFromInputEvent( p
,
4678 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4680 if ( p
->GetChildCount() && !p
->IsCategory() )
4681 // On double-click, expand/collapse.
4682 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4684 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4685 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4686 else DoExpand( p
, true );
4693 // click on splitter
4694 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4696 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4698 // Double-clicking the splitter causes auto-centering
4699 if ( m_pState
->GetColumnCount() <= 2 )
4701 ResetColumnSizes( true );
4703 SendEvent(wxEVT_PG_COL_DRAGGING
,
4706 wxPG_SEL_NOVALIDATE
,
4707 (unsigned int)m_draggedSplitter
);
4710 else if ( m_dragStatus
== 0 )
4713 // Begin draggin the splitter
4717 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4719 // Allow application to veto dragging
4720 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4722 (unsigned int)splitterHit
) )
4726 // Changes must be committed here or the
4727 // value won't be drawn correctly
4728 if ( !CommitChangesFromEditor() )
4731 m_wndEditor
->Show ( false );
4734 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4737 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4741 m_draggedSplitter
= splitterHit
;
4742 m_dragOffset
= splitterHitOffset
;
4744 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4745 // Fixes button disappearance bug
4747 m_wndEditor2
->Show ( false );
4750 m_startingSplitterX
= x
- splitterHitOffset
;
4759 if ( p
->GetChildCount() )
4761 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4763 // Fine tune cell button x
4764 if ( !p
->IsCategory() )
4765 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4767 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4769 int y2
= y
% m_lineHeight
;
4770 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4772 // On click on expander button, expand/collapse
4773 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4774 DoCollapse( p
, true );
4776 DoExpand( p
, true );
4785 // -----------------------------------------------------------------------
4787 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4788 unsigned int WXUNUSED(y
),
4789 wxMouseEvent
& event
)
4793 // Select property here as well
4794 wxPGProperty
* p
= m_propHover
;
4795 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4797 // Send right click event.
4798 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4805 // -----------------------------------------------------------------------
4807 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4808 unsigned int WXUNUSED(y
),
4809 wxMouseEvent
& event
)
4813 // Select property here as well
4814 wxPGProperty
* p
= m_propHover
;
4816 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4818 // Send double-click event.
4819 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4826 // -----------------------------------------------------------------------
4828 #if wxPG_SUPPORT_TOOLTIPS
4830 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4832 if ( tipString
.length() )
4834 wxScrolledWindow::SetToolTip(tipString
);
4838 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4839 wxScrolledWindow::SetToolTip( m_emptyString
);
4841 wxScrolledWindow::SetToolTip( NULL
);
4846 #endif // #if wxPG_SUPPORT_TOOLTIPS
4848 // -----------------------------------------------------------------------
4850 // Return false if should be skipped
4851 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
,
4852 wxMouseEvent
&event
)
4854 // Safety check (needed because mouse capturing may
4855 // otherwise freeze the control)
4856 if ( m_dragStatus
> 0 && !event
.Dragging() )
4858 HandleMouseUp(x
, y
, event
);
4861 wxPropertyGridPageState
* state
= m_pState
;
4863 int splitterHitOffset
;
4864 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4865 int splitterX
= x
- splitterHitOffset
;
4867 m_colHover
= columnHit
;
4869 if ( m_dragStatus
> 0 )
4871 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4872 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4875 int newSplitterX
= x
- m_dragOffset
;
4877 // Splitter redraw required?
4878 if ( newSplitterX
!= splitterX
)
4881 DoSetSplitterPosition(newSplitterX
,
4883 wxPG_SPLITTER_REFRESH
|
4884 wxPG_SPLITTER_FROM_EVENT
);
4886 SendEvent(wxEVT_PG_COL_DRAGGING
,
4889 wxPG_SEL_NOVALIDATE
,
4890 (unsigned int)m_draggedSplitter
);
4901 int ih
= m_lineHeight
;
4904 #if wxPG_SUPPORT_TOOLTIPS
4905 wxPGProperty
* prevHover
= m_propHover
;
4906 unsigned char prevSide
= m_mouseSide
;
4908 int curPropHoverY
= y
- (y
% ih
);
4910 // On which item it hovers
4913 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4916 // Mouse moves on another property
4918 m_propHover
= DoGetItemAtY(y
);
4919 m_propHoverY
= curPropHoverY
;
4922 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4925 #if wxPG_SUPPORT_TOOLTIPS
4926 // Store which side we are on
4928 if ( columnHit
== 1 )
4930 else if ( columnHit
== 0 )
4934 // If tooltips are enabled, show label or value as a tip
4935 // in case it doesn't otherwise show in full length.
4937 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4939 wxToolTip
* tooltip
= GetToolTip();
4941 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4943 if ( m_propHover
&& !m_propHover
->IsCategory() )
4946 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4948 // Show help string as a tooltip
4949 wxString tipString
= m_propHover
->GetHelpString();
4951 SetToolTip(tipString
);
4955 // Show cropped value string as a tooltip
4959 if ( m_mouseSide
== 1 )
4961 tipString
= m_propHover
->m_label
;
4962 space
= splitterX
-m_marginWidth
-3;
4964 else if ( m_mouseSide
== 2 )
4966 tipString
= m_propHover
->GetDisplayedString();
4968 space
= m_width
- splitterX
;
4969 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4970 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+
4971 wxCC_CUSTOM_IMAGE_MARGIN1
+
4972 wxCC_CUSTOM_IMAGE_MARGIN2
;
4978 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4981 SetToolTip( tipString
);
4988 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4989 SetToolTip( m_emptyString
);
4991 wxScrolledWindow::SetToolTip( NULL
);
5002 #if wxPG_ALLOW_EMPTY_TOOLTIPS
5003 SetToolTip( m_emptyString
);
5005 wxScrolledWindow::SetToolTip( NULL
);
5013 if ( splitterHit
== -1 ||
5015 HasFlag(wxPG_STATIC_SPLITTER
) )
5017 // hovering on something else
5018 if ( m_curcursor
!= wxCURSOR_ARROW
)
5019 CustomSetCursor( wxCURSOR_ARROW
);
5023 // Do not allow splitter cursor on caption items.
5024 // (also not if we were dragging and its started
5025 // outside the splitter region)
5027 if ( !m_propHover
->IsCategory() &&
5031 // hovering on splitter
5033 // NB: Condition disabled since MouseLeave event (from the
5034 // editor control) cannot be reliably detected.
5035 //if ( m_curcursor != wxCURSOR_SIZEWE )
5036 CustomSetCursor( wxCURSOR_SIZEWE
, true );
5042 // hovering on something else
5043 if ( m_curcursor
!= wxCURSOR_ARROW
)
5044 CustomSetCursor( wxCURSOR_ARROW
);
5049 // Multi select by dragging
5051 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
5052 event
.LeftIsDown() &&
5056 !state
->DoIsPropertySelected(m_propHover
) )
5058 // Additional requirement is that the hovered property
5059 // is adjacent to edges of selection.
5060 const wxArrayPGProperty
& selection
= GetSelectedProperties();
5062 // Since categories cannot be selected along with 'other'
5063 // properties, exclude them from iterator flags.
5064 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
5066 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
5068 // TODO: This could be optimized by keeping track of
5069 // which properties are at the edges of selection.
5070 wxPGProperty
* selProp
= selection
[i
];
5071 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
5074 DoAddToSelection(m_propHover
);
5083 // -----------------------------------------------------------------------
5085 // Also handles Leaving event
5086 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
5087 wxMouseEvent
&WXUNUSED(event
) )
5089 wxPropertyGridPageState
* state
= m_pState
;
5093 int splitterHitOffset
;
5094 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
5096 // No event type check - basicly calling this method should
5097 // just stop dragging.
5098 // Left up after dragged?
5099 if ( m_dragStatus
>= 1 )
5102 // End Splitter Dragging
5104 // DO NOT ENABLE FOLLOWING LINE!
5105 // (it is only here as a reminder to not to do it)
5108 SendEvent(wxEVT_PG_COL_END_DRAG
,
5111 wxPG_SEL_NOVALIDATE
,
5112 (unsigned int)m_draggedSplitter
);
5114 // Disable splitter auto-centering (but only if moved any -
5115 // otherwise we end up disabling auto-center even after a
5116 // recentering double-click).
5117 int posDiff
= abs(m_startingSplitterX
-
5118 GetSplitterPosition(m_draggedSplitter
));
5121 state
->m_dontCenterSplitter
= true;
5123 // This is necessary to return cursor
5124 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5127 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5130 // Set back the default cursor, if necessary
5131 if ( splitterHit
== -1 ||
5134 CustomSetCursor( wxCURSOR_ARROW
);
5139 // Control background needs to be cleared
5140 wxPGProperty
* selected
= GetSelection();
5141 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
5142 DrawItem( selected
);
5146 m_wndEditor
->Show ( true );
5149 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
5150 // Fixes button disappearance bug
5152 m_wndEditor2
->Show ( true );
5155 // This clears the focus.
5156 m_editorFocused
= 0;
5162 // -----------------------------------------------------------------------
5164 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
5166 int splitterX
= GetSplitterPosition();
5169 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
5171 wxWindow
* wnd
= GetEditorControl();
5173 // Hide popup on clicks
5174 if ( event
.GetEventType() != wxEVT_MOTION
)
5175 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5177 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
5183 if ( wnd
== NULL
|| m_dragStatus
||
5185 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
5186 ux
>= (r
.x
+r
.width
) ||
5188 event
.m_y
>= (r
.y
+r
.height
)
5198 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5203 // -----------------------------------------------------------------------
5205 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
5208 if ( OnMouseCommon( event
, &x
, &y
) )
5210 HandleMouseClick(x
,y
,event
);
5215 // -----------------------------------------------------------------------
5217 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5220 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5221 HandleMouseRightClick(x
,y
,event
);
5225 // -----------------------------------------------------------------------
5227 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5229 // Always run standard mouse-down handler as well
5230 OnMouseClick(event
);
5233 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5234 HandleMouseDoubleClick(x
,y
,event
);
5238 // -----------------------------------------------------------------------
5240 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5243 if ( OnMouseCommon( event
, &x
, &y
) )
5245 HandleMouseMove(x
,y
,event
);
5250 // -----------------------------------------------------------------------
5252 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5255 if ( OnMouseCommon( event
, &x
, &y
) )
5257 HandleMouseUp(x
,y
,event
);
5262 // -----------------------------------------------------------------------
5264 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5266 // This may get called from child control as well, so event's
5267 // mouse position cannot be relied on.
5269 if ( event
.Entering() )
5271 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5273 // TODO: Fix this (detect parent and only do
5274 // cursor trick if it is a manager).
5275 wxASSERT( GetParent() );
5276 GetParent()->SetCursor(wxNullCursor
);
5278 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5281 GetParent()->SetCursor(wxNullCursor
);
5283 else if ( event
.Leaving() )
5285 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5286 SetCursor( wxNullCursor
);
5288 // Get real cursor position
5289 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5291 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5294 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5296 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5300 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5308 // -----------------------------------------------------------------------
5310 // Common code used by various OnMouseXXXChild methods.
5311 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5313 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5314 wxASSERT( topCtrlWnd
);
5316 event
.GetPosition(&x
,&y
);
5318 int splitterX
= GetSplitterPosition();
5320 wxRect r
= topCtrlWnd
->GetRect();
5321 if ( !m_dragStatus
&&
5322 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5323 y
>= 0 && y
< r
.height \
5326 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5331 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5338 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5341 if ( OnMouseChildCommon(event
,&x
,&y
) )
5343 bool res
= HandleMouseClick(x
,y
,event
);
5344 if ( !res
) event
.Skip();
5348 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5351 wxASSERT( m_wndEditor
);
5352 // These coords may not be exact (about +-2),
5353 // but that should not matter (right click is about item, not position).
5354 wxPoint pt
= m_wndEditor
->GetPosition();
5355 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5357 // FIXME: Used to set m_propHover to selection here. Was it really
5360 bool res
= HandleMouseRightClick(x
,y
,event
);
5361 if ( !res
) event
.Skip();
5364 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5367 if ( OnMouseChildCommon(event
,&x
,&y
) )
5369 bool res
= HandleMouseMove(x
,y
,event
);
5370 if ( !res
) event
.Skip();
5374 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5377 if ( OnMouseChildCommon(event
,&x
,&y
) )
5379 bool res
= HandleMouseUp(x
,y
,event
);
5380 if ( !res
) event
.Skip();
5384 // -----------------------------------------------------------------------
5385 // wxPropertyGrid keyboard event handling
5386 // -----------------------------------------------------------------------
5388 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5390 // Translates wxKeyEvent to wxPG_ACTION_XXX
5392 int keycode
= event
.GetKeyCode();
5393 int modifiers
= event
.GetModifiers();
5395 wxASSERT( !(modifiers
&~(0xFFFF)) );
5397 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5399 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5401 if ( it
== m_actionTriggers
.end() )
5406 int second
= (it
->second
>>16) & 0xFFFF;
5410 return (it
->second
& 0xFFFF);
5413 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5415 wxASSERT( !(modifiers
&~(0xFFFF)) );
5417 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5419 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5421 if ( it
!= m_actionTriggers
.end() )
5423 // This key combination is already used
5425 // Can add secondary?
5426 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5427 wxT("You can only add up to two separate actions per key combination.") );
5429 action
= it
->second
| (action
<<16);
5432 m_actionTriggers
[hashMapKey
] = action
;
5435 void wxPropertyGrid::ClearActionTriggers( int action
)
5437 wxPGHashMapI2I::iterator it
;
5442 didSomething
= false;
5444 for ( it
= m_actionTriggers
.begin();
5445 it
!= m_actionTriggers
.end();
5448 if ( it
->second
== action
)
5450 m_actionTriggers
.erase(it
);
5451 didSomething
= true;
5456 while ( didSomething
);
5459 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5462 // Handles key event when editor control is not focused.
5465 wxCHECK2(!m_frozen
, return);
5467 // Travelsal between items, collapsing/expanding, etc.
5468 wxPGProperty
* selected
= GetSelection();
5469 int keycode
= event
.GetKeyCode();
5470 bool editorFocused
= IsEditorFocused();
5472 if ( keycode
== WXK_TAB
)
5474 wxWindow
* mainControl
;
5476 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5477 mainControl
= GetParent();
5481 if ( !event
.ShiftDown() )
5483 if ( !editorFocused
&& m_wndEditor
)
5485 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5489 // Tab traversal workaround for platforms on which
5490 // wxWindow::Navigate() may navigate into first child
5491 // instead of next sibling. Does not work perfectly
5492 // in every scenario (for instance, when property grid
5493 // is either first or last control).
5494 #if defined(__WXGTK__)
5495 wxWindow
* sibling
= mainControl
->GetNextSibling();
5497 sibling
->SetFocusFromKbd();
5499 Navigate(wxNavigationKeyEvent::IsForward
);
5505 if ( editorFocused
)
5511 #if defined(__WXGTK__)
5512 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5514 sibling
->SetFocusFromKbd();
5516 Navigate(wxNavigationKeyEvent::IsBackward
);
5524 // Ignore Alt and Control when they are down alone
5525 if ( keycode
== WXK_ALT
||
5526 keycode
== WXK_CONTROL
)
5533 int action
= KeyEventToActions(event
, &secondAction
);
5535 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5538 // Esc cancels any changes
5539 if ( IsEditorsValueModified() )
5541 EditorsValueWasNotModified();
5543 // Update the control as well
5544 selected
->GetEditorClass()->
5545 SetControlStringValue( selected
,
5547 selected
->GetDisplayedString() );
5550 OnValidationFailureReset(selected
);
5556 // Except for TAB, ESC, and any keys specifically dedicated to
5557 // wxPropertyGrid itself, handle child control events in child control.
5559 wxPGFindInVector(m_dedicatedKeys
, keycode
) == wxNOT_FOUND
)
5561 // Only propagate event if it had modifiers
5562 if ( !event
.HasModifiers() )
5564 event
.StopPropagation();
5570 bool wasHandled
= false;
5575 if ( ButtonTriggerKeyTest(action
, event
) )
5578 wxPGProperty
* p
= selected
;
5580 // Travel and expand/collapse
5583 if ( p
->GetChildCount() )
5585 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5587 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5590 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5592 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5599 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5603 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5609 if ( selectDir
>= -1 )
5611 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5615 int reopenLabelEditorCol
= -1;
5617 if ( editorFocused
)
5619 // If editor was focused, then make the next editor
5621 selFlags
|= wxPG_SEL_FOCUS
;
5625 // Also maintain the same label editor focus state
5626 if ( m_labelEditor
)
5627 reopenLabelEditorCol
= m_selColumn
;
5630 DoSelectProperty(p
, selFlags
);
5632 if ( reopenLabelEditorCol
>= 0 )
5633 DoBeginLabelEdit(reopenLabelEditorCol
);
5640 // If nothing was selected, select the first item now
5641 // (or navigate out of tab).
5642 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5644 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5645 if ( p
) DoSelectProperty(p
);
5654 // -----------------------------------------------------------------------
5656 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5658 // If there was editor open and focused, then this event should not
5659 // really be processed here.
5660 if ( IsEditorFocused() )
5662 // However, if event had modifiers, it is probably still best
5664 if ( event
.HasModifiers() )
5667 event
.StopPropagation();
5671 HandleKeyEvent(event
, false);
5674 // -----------------------------------------------------------------------
5676 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5681 action
= KeyEventToActions(event
, &secondAction
);
5684 // Does the keycode trigger button?
5685 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5688 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5689 GetEventHandler()->AddPendingEvent(evt
);
5696 // -----------------------------------------------------------------------
5698 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5700 HandleKeyEvent(event
, true);
5703 // -----------------------------------------------------------------------
5704 // wxPropertyGrid miscellaneous event handling
5705 // -----------------------------------------------------------------------
5707 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5710 // Check if the focus is in this control or one of its children
5711 wxWindow
* newFocused
= wxWindow::FindFocus();
5713 if ( newFocused
!= m_curFocused
)
5714 HandleFocusChange( newFocused
);
5717 // Check if top-level parent has changed
5718 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5720 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5726 // Resolve pending property removals
5727 if ( m_deletedProperties
.size() > 0 )
5729 wxArrayPGProperty
& arr
= m_deletedProperties
;
5730 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5732 DeleteProperty(arr
[i
]);
5736 if ( m_removedProperties
.size() > 0 )
5738 wxArrayPGProperty
& arr
= m_removedProperties
;
5739 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5741 RemoveProperty(arr
[i
]);
5747 bool wxPropertyGrid::IsEditorFocused() const
5749 wxWindow
* focus
= wxWindow::FindFocus();
5751 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5752 focus
== GetEditorControl() )
5758 // Called by focus event handlers. newFocused is the window that becomes focused.
5759 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5761 unsigned int oldFlags
= m_iFlags
;
5762 bool wasEditorFocused
= false;
5763 wxWindow
* wndEditor
= m_wndEditor
;
5765 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5767 wxWindow
* parent
= newFocused
;
5769 // This must be one of nextFocus' parents.
5772 if ( parent
== wndEditor
)
5774 wasEditorFocused
= true;
5776 // Use m_eventObject, which is either wxPropertyGrid or
5777 // wxPropertyGridManager, as appropriate.
5778 else if ( parent
== m_eventObject
)
5780 m_iFlags
|= wxPG_FL_FOCUSED
;
5783 parent
= parent
->GetParent();
5786 // Notify editor control when it receives a focus
5787 if ( wasEditorFocused
&& m_curFocused
!= newFocused
)
5789 wxPGProperty
* p
= GetSelection();
5792 const wxPGEditor
* editor
= p
->GetEditorClass();
5793 ResetEditorAppearance();
5794 editor
->OnFocus(p
, GetEditorControl());
5798 m_curFocused
= newFocused
;
5800 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5801 (oldFlags
& wxPG_FL_FOCUSED
) )
5803 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5805 // Need to store changed value
5806 CommitChangesFromEditor();
5812 // Preliminary code for tab-order respecting
5813 // tab-traversal (but should be moved to
5816 wxWindow* prevFocus = event.GetWindow();
5817 wxWindow* useThis = this;
5818 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5819 useThis = GetParent();
5822 prevFocus->GetParent() == useThis->GetParent() )
5824 wxList& children = useThis->GetParent()->GetChildren();
5826 wxNode* node = children.Find(prevFocus);
5828 if ( node->GetNext() &&
5829 useThis == node->GetNext()->GetData() )
5830 DoSelectProperty(GetFirst());
5831 else if ( node->GetPrevious () &&
5832 useThis == node->GetPrevious()->GetData() )
5833 DoSelectProperty(GetLastProperty());
5840 wxPGProperty
* selected
= GetSelection();
5841 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5842 DrawItem( selected
);
5846 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5848 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5849 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5850 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5851 //else if ( event.GetWindow() )
5853 HandleFocusChange(event
.GetWindow());
5858 // -----------------------------------------------------------------------
5860 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5862 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5866 // -----------------------------------------------------------------------
5868 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5870 m_iFlags
|= wxPG_FL_SCROLLED
;
5875 // -----------------------------------------------------------------------
5877 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5879 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5881 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5885 // -----------------------------------------------------------------------
5886 // Property editor related functions
5887 // -----------------------------------------------------------------------
5889 // noDefCheck = true prevents infinite recursion.
5890 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5891 const wxString
& editorName
,
5894 wxASSERT( editorClass
);
5896 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5897 RegisterDefaultEditors();
5899 wxString name
= editorName
;
5900 if ( name
.length() == 0 )
5901 name
= editorClass
->GetName();
5903 // Existing editor under this name?
5904 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5906 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5908 // If this name was already used, try class name.
5909 name
= editorClass
->GetClassInfo()->GetClassName();
5910 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5913 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5914 (wxPGEditor
*) vt_it
->second
,
5915 "Editor with given name was already registered" );
5917 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5922 // Use this in RegisterDefaultEditors.
5923 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5924 if ( wxPGEditor_##EDITOR == NULL ) \
5926 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5927 new wxPG##EDITOR##Editor, true ); \
5930 // Registers all default editor classes
5931 void wxPropertyGrid::RegisterDefaultEditors()
5933 wxPGRegisterDefaultEditorClass( TextCtrl
);
5934 wxPGRegisterDefaultEditorClass( Choice
);
5935 wxPGRegisterDefaultEditorClass( ComboBox
);
5936 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5937 #if wxPG_INCLUDE_CHECKBOX
5938 wxPGRegisterDefaultEditorClass( CheckBox
);
5940 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5942 // Register SpinCtrl etc. editors before use
5943 RegisterAdditionalEditors();
5946 // -----------------------------------------------------------------------
5947 // wxPGStringTokenizer
5948 // Needed to handle C-style string lists (e.g. "str1" "str2")
5949 // -----------------------------------------------------------------------
5951 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5952 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5956 wxPGStringTokenizer::~wxPGStringTokenizer()
5960 bool wxPGStringTokenizer::HasMoreTokens()
5962 const wxString
& str
= *m_str
;
5964 wxString::const_iterator i
= m_curPos
;
5966 wxUniChar delim
= m_delimeter
;
5968 wxUniChar prev_a
= wxT('\0');
5970 bool inToken
= false;
5972 while ( i
!= str
.end() )
5981 m_readyToken
.clear();
5986 if ( prev_a
!= wxT('\\') )
5990 if ( a
!= wxT('\\') )
6010 m_curPos
= str
.end();
6018 wxString
wxPGStringTokenizer::GetNextToken()
6020 return m_readyToken
;
6023 // -----------------------------------------------------------------------
6025 // -----------------------------------------------------------------------
6027 wxPGChoiceEntry::wxPGChoiceEntry()
6028 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
6032 // -----------------------------------------------------------------------
6034 // -----------------------------------------------------------------------
6036 wxPGChoicesData::wxPGChoicesData()
6040 wxPGChoicesData::~wxPGChoicesData()
6045 void wxPGChoicesData::Clear()
6050 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
6052 wxASSERT( m_items
.size() == 0 );
6054 m_items
= data
->m_items
;
6057 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
6058 const wxPGChoiceEntry
& item
)
6060 wxVector
<wxPGChoiceEntry
>::iterator it
;
6064 index
= (int) m_items
.size();
6068 it
= m_items
.begin() + index
;
6071 m_items
.insert(it
, item
);
6073 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
6075 // Need to fix value?
6076 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
6077 ownEntry
.SetValue(index
);
6082 // -----------------------------------------------------------------------
6083 // wxPropertyGridEvent
6084 // -----------------------------------------------------------------------
6086 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
6089 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
6090 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
6091 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
6092 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
6093 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
6094 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
6095 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
6096 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
6097 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
6098 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
6099 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
6100 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
6101 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
6102 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
6104 // -----------------------------------------------------------------------
6106 void wxPropertyGridEvent::Init()
6108 m_validationInfo
= NULL
;
6111 m_wasVetoed
= false;
6114 // -----------------------------------------------------------------------
6116 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6117 : wxCommandEvent(commandType
,id
)
6123 // -----------------------------------------------------------------------
6125 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6126 : wxCommandEvent(event
)
6128 m_eventType
= event
.GetEventType();
6129 m_eventObject
= event
.m_eventObject
;
6131 OnPropertyGridSet();
6132 m_property
= event
.m_property
;
6133 m_validationInfo
= event
.m_validationInfo
;
6134 m_canVeto
= event
.m_canVeto
;
6135 m_wasVetoed
= event
.m_wasVetoed
;
6138 // -----------------------------------------------------------------------
6140 void wxPropertyGridEvent::OnPropertyGridSet()
6146 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6148 m_pg
->m_liveEvents
.push_back(this);
6151 // -----------------------------------------------------------------------
6153 wxPropertyGridEvent::~wxPropertyGridEvent()
6158 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6161 // Use iterate from the back since it is more likely that the event
6162 // being desroyed is at the end of the array.
6163 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
6165 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
6167 if ( liveEvents
[i
] == this )
6169 liveEvents
.erase(liveEvents
.begin() + i
);
6176 // -----------------------------------------------------------------------
6178 wxEvent
* wxPropertyGridEvent::Clone() const
6180 return new wxPropertyGridEvent( *this );
6183 // -----------------------------------------------------------------------
6184 // wxPropertyGridPopulator
6185 // -----------------------------------------------------------------------
6187 wxPropertyGridPopulator::wxPropertyGridPopulator()
6191 wxPGGlobalVars
->m_offline
++;
6194 // -----------------------------------------------------------------------
6196 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6199 m_propHierarchy
.clear();
6202 // -----------------------------------------------------------------------
6204 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6210 // -----------------------------------------------------------------------
6212 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6215 // Free unused sets of choices
6216 wxPGHashMapS2P::iterator it
;
6218 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6220 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6227 m_pg
->GetPanel()->Refresh();
6229 wxPGGlobalVars
->m_offline
--;
6232 // -----------------------------------------------------------------------
6234 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6235 const wxString
& propLabel
,
6236 const wxString
& propName
,
6237 const wxString
* propValue
,
6238 wxPGChoices
* pChoices
)
6240 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6241 wxPGProperty
* parent
= GetCurParent();
6243 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6245 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6249 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6251 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6255 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6257 property
->SetLabel(propLabel
);
6258 property
->DoSetName(propName
);
6260 if ( pChoices
&& pChoices
->IsOk() )
6261 property
->SetChoices(*pChoices
);
6263 m_state
->DoInsert(parent
, -1, property
);
6266 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
6267 wxPG_PROGRAMMATIC_VALUE
);
6272 // -----------------------------------------------------------------------
6274 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6276 m_propHierarchy
.push_back(property
);
6277 DoScanForChildren();
6278 m_propHierarchy
.pop_back();
6281 // -----------------------------------------------------------------------
6283 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6284 const wxString
& idString
)
6286 wxPGChoices choices
;
6289 if ( choicesString
[0] == wxT('@') )
6291 wxString ids
= choicesString
.substr(1);
6292 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6293 if ( it
== m_dictIdChoices
.end() )
6294 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6296 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6301 if ( idString
.length() )
6303 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6304 if ( it
!= m_dictIdChoices
.end() )
6306 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6313 // Parse choices string
6314 wxString::const_iterator it
= choicesString
.begin();
6318 bool labelValid
= false;
6320 for ( ; it
!= choicesString
.end(); ++it
)
6326 if ( c
== wxT('"') )
6331 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6332 choices
.Add(label
, l
);
6335 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6340 else if ( c
== wxT('=') )
6347 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6354 if ( c
== wxT('"') )
6367 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6368 choices
.Add(label
, l
);
6371 if ( !choices
.IsOk() )
6373 choices
.EnsureData();
6377 if ( idString
.length() )
6378 m_dictIdChoices
[idString
] = choices
.GetData();
6385 // -----------------------------------------------------------------------
6387 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6389 if ( s
.Last() == wxT('%') )
6391 wxString s2
= s
.substr(0,s
.length()-1);
6393 if ( s2
.ToLong(&val
, 10) )
6395 *pval
= (val
*max
)/100;
6401 return s
.ToLong(pval
, 10);
6404 // -----------------------------------------------------------------------
6406 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6407 const wxString
& type
,
6408 const wxString
& value
)
6410 int l
= m_propHierarchy
.size();
6414 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6415 wxString valuel
= value
.Lower();
6418 if ( type
.length() == 0 )
6423 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6425 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6427 else if ( value
.ToLong(&v
, 0) )
6434 if ( type
== wxT("string") )
6438 else if ( type
== wxT("int") )
6441 value
.ToLong(&v
, 0);
6444 else if ( type
== wxT("bool") )
6446 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6453 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6458 p
->SetAttribute( name
, variant
);
6463 // -----------------------------------------------------------------------
6465 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6467 wxLogError(_("Error in resource: %s"),msg
.c_str());
6470 // -----------------------------------------------------------------------
6472 #endif // wxUSE_PROPGRID