1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
22 #include "wx/object.h"
24 #include "wx/string.h"
27 #include "wx/window.h"
30 #include "wx/dcmemory.h"
31 #include "wx/button.h"
34 #include "wx/cursor.h"
35 #include "wx/dialog.h"
36 #include "wx/settings.h"
37 #include "wx/msgdlg.h"
38 #include "wx/choice.h"
39 #include "wx/stattext.h"
40 #include "wx/scrolwin.h"
41 #include "wx/dirdlg.h"
43 #include "wx/textdlg.h"
44 #include "wx/filedlg.h"
45 #include "wx/statusbr.h"
51 // This define is necessary to prevent macro clearing
52 #define __wxPG_SOURCE_FILE__
54 #include "wx/propgrid/propgrid.h"
55 #include "wx/propgrid/editors.h"
57 #if wxPG_USE_RENDERER_NATIVE
58 #include "wx/renderer.h"
61 #include "wx/odcombo.h"
64 #include "wx/dcbuffer.h"
65 #include "wx/scopeguard.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() { wxDELETE(wxPGGlobalVars
); }
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
;
161 wxModule::RegisterModule(module);
162 wxModule::InitializeModules();
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 // Make sure the global pointers have been reset
238 wxASSERT(wxPG_EDITOR(TextCtrl
) == NULL
);
239 wxASSERT(wxPG_EDITOR(ChoiceAndButton
) == NULL
);
241 delete wxPGProperty::sm_wxPG_LABEL
;
244 void wxPropertyGridInitGlobalsIfNeeded()
248 // -----------------------------------------------------------------------
250 // -----------------------------------------------------------------------
252 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxControl
)
254 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxControl
)
255 EVT_IDLE(wxPropertyGrid::OnIdle
)
256 EVT_PAINT(wxPropertyGrid::OnPaint
)
257 EVT_SIZE(wxPropertyGrid::OnResize
)
258 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
259 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
260 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
261 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
262 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
263 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
264 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
265 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
266 EVT_MOTION(wxPropertyGrid::OnMouseMove
)
267 EVT_LEFT_DOWN(wxPropertyGrid::OnMouseClick
)
268 EVT_LEFT_UP(wxPropertyGrid::OnMouseUp
)
269 EVT_RIGHT_UP(wxPropertyGrid::OnMouseRightClick
)
270 EVT_LEFT_DCLICK(wxPropertyGrid::OnMouseDoubleClick
)
271 EVT_KEY_DOWN(wxPropertyGrid::OnKey
)
274 // -----------------------------------------------------------------------
276 wxPropertyGrid::wxPropertyGrid()
277 : wxControl(), wxScrollHelper(this)
282 // -----------------------------------------------------------------------
284 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
289 const wxString
& name
)
290 : wxControl(), wxScrollHelper(this)
293 Create(parent
,id
,pos
,size
,style
,name
);
296 // -----------------------------------------------------------------------
298 bool wxPropertyGrid::Create( wxWindow
*parent
,
303 const wxString
& name
)
306 if (!(style
&wxBORDER_MASK
))
308 style
|= wxBORDER_THEME
;
313 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
314 style
&= ~(wxTAB_TRAVERSAL
);
315 style
|= wxWANTS_CHARS
;
317 wxControl::Create(parent
, id
, pos
, size
,
318 style
| wxScrolledWindowStyle
,
327 // -----------------------------------------------------------------------
330 // Initialize values to defaults
332 void wxPropertyGrid::Init1()
334 // Register editor classes, if necessary.
335 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
336 wxPropertyGrid::RegisterDefaultEditors();
338 m_validatingEditor
= 0;
341 m_wndEditor
= m_wndEditor2
= NULL
;
345 m_labelEditor
= NULL
;
346 m_labelEditorProperty
= NULL
;
347 m_eventObject
= this;
349 m_processedEvent
= NULL
;
351 m_sortFunction
= NULL
;
352 m_inDoPropertyChanged
= false;
353 m_inCommitChangesFromEditor
= false;
354 m_inDoSelectProperty
= false;
355 m_inOnValidationFailure
= false;
356 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
361 // Set up default unspecified value 'colour'
362 m_unspecifiedAppearance
.SetFgCol(*wxLIGHT_GREY
);
365 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
366 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
367 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
368 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
369 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
370 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
371 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
372 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
373 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
375 m_coloursCustomized
= 0;
378 m_doubleBuffer
= NULL
;
380 #ifndef wxPG_ICON_WIDTH
386 m_iconWidth
= wxPG_ICON_WIDTH
;
391 m_gutterWidth
= wxPG_GUTTER_MIN
;
392 m_subgroup_extramargin
= 10;
396 m_width
= m_height
= 0;
398 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
401 m_chgInfo_changedProperty
= NULL
;
404 // -----------------------------------------------------------------------
407 // Initialize after parent etc. set
409 void wxPropertyGrid::Init2()
411 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
414 // Smaller controls on Mac
415 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
418 // Now create state, if one didn't exist already
419 // (wxPropertyGridManager might have created it for us).
422 m_pState
= CreateState();
423 m_pState
->m_pPropGrid
= this;
424 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
427 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
428 m_pState
->m_dontCenterSplitter
= true;
430 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
432 m_pState
->InitNonCatMode();
434 m_pState
->m_properties
= m_pState
->m_abcArray
;
437 GetClientSize(&m_width
,&m_height
);
439 #ifndef wxPG_ICON_WIDTH
440 // create two bitmap nodes for drawing
441 m_expandbmp
= new wxBitmap(expand_xpm
);
442 m_collbmp
= new wxBitmap(collapse_xpm
);
444 // calculate average font height for bitmap centering
446 m_iconWidth
= m_expandbmp
->GetWidth();
447 m_iconHeight
= m_expandbmp
->GetHeight();
450 m_curcursor
= wxCURSOR_ARROW
;
451 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
453 // adjust bitmap icon y position so they are centered
454 m_vspacing
= wxPG_DEFAULT_VSPACING
;
456 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
458 // Allocate cell datas
459 m_propertyDefaultCell
.SetEmptyData();
460 m_categoryDefaultCell
.SetEmptyData();
464 // This helps with flicker
465 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
467 // Hook the top-level parent
471 // set virtual size to this window size
472 wxSize wndsize
= GetSize();
473 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
475 m_timeCreated
= ::wxGetLocalTimeMillis();
477 m_iFlags
|= wxPG_FL_INITIALIZED
;
479 m_ncWidth
= wndsize
.GetWidth();
481 // Need to call OnResize handler or size given in constructor/Create
483 wxSizeEvent
sizeEvent(wndsize
,0);
487 // -----------------------------------------------------------------------
489 wxPropertyGrid::~wxPropertyGrid()
494 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
498 // Remove grid and property pointers from live wxPropertyGridEvents.
499 for ( i
=0; i
<m_liveEvents
.size(); i
++ )
501 wxPropertyGridEvent
* evt
= m_liveEvents
[i
];
502 evt
->SetPropertyGrid(NULL
);
503 evt
->SetProperty(NULL
);
505 m_liveEvents
.clear();
507 if ( m_processedEvent
)
509 // All right... we are being deleted while wxPropertyGrid event
510 // is being sent. Make sure that event propagates as little
511 // as possible (although usually this is not enough to prevent
513 m_processedEvent
->Skip(false);
514 m_processedEvent
->StopPropagation();
516 // Let's use wxMessageBox to make the message appear more
517 // reliably (and *before* the crash can happen).
518 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
519 "generated by it. This usually leads to a crash "
520 "so it is recommended to destroy the control "
521 "at idle time instead.");
524 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
526 // This should do prevent things from going too badly wrong
527 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
529 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
532 // Call with NULL to disconnect event handling
533 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
537 wxASSERT_MSG( !IsEditorsValueModified(),
538 wxS("Most recent change in property editor was ")
539 wxS("lost!!! (if you don't want this to happen, ")
540 wxS("close your frames and dialogs using ")
541 wxS("Close(false).)") );
544 if ( m_doubleBuffer
)
545 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 wxControl::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
) )
637 wxControl::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()
660 // -----------------------------------------------------------------------
662 void wxPropertyGrid::Thaw()
669 RecalculateVirtualSize();
672 // Force property re-selection
673 // NB: We must copy the selection.
674 wxArrayPGProperty selection
= m_pState
->m_selection
;
675 DoSetSelection(selection
, wxPG_SEL_FORCE
| wxPG_SEL_NONVISIBLE
);
679 // -----------------------------------------------------------------------
681 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
683 wxCHECK( prop
, false );
685 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
686 return DoSelectProperty(prop
, selFlags
);
688 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
690 if ( !selection
.size() )
692 return DoSelectProperty(prop
, selFlags
);
696 // For categories, only one can be selected at a time
697 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
700 selection
.push_back(prop
);
702 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
704 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
713 // -----------------------------------------------------------------------
715 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
717 wxCHECK( prop
, false );
720 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
721 if ( selection
.size() <= 1 )
723 res
= DoSelectProperty(NULL
, selFlags
);
727 m_pState
->DoRemoveFromSelection(prop
);
735 // -----------------------------------------------------------------------
737 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
738 unsigned int colIndex
,
739 unsigned int selFlags
)
742 // NB: Enable following if label editor background colour is
743 // ever changed to any other than m_colSelBack.
745 // We use this workaround to prevent visible flicker when editing
746 // a cell. Atleast on wxMSW, there is a difficult to find
747 // (and perhaps prevent) redraw somewhere between making property
748 // selected and enabling label editing.
750 //wxColour prevColSelBack = m_colSelBack;
751 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
757 res
= DoSelectProperty(prop
, selFlags
);
762 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
764 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
766 res
= DoAddToSelection(prop
, selFlags
);
770 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
772 DoBeginLabelEdit(colIndex
, selFlags
);
776 //m_colSelBack = prevColSelBack;
780 // -----------------------------------------------------------------------
782 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
783 unsigned int colIndex
,
784 wxMouseEvent
* mouseEvent
,
787 const wxArrayPGProperty
& selection
= GetSelectedProperties();
788 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
791 // Set to 2 if also add all items in between
792 int addToExistingSelection
= 0;
794 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
798 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
799 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
801 // Allow right-click for context menu without
802 // disturbing the selection.
803 if ( GetSelectedProperties().size() <= 1 ||
805 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
810 if ( mouseEvent
->ControlDown() )
812 addToExistingSelection
= 1;
814 else if ( mouseEvent
->ShiftDown() )
816 if ( selection
.size() > 0 && !prop
->IsCategory() )
817 addToExistingSelection
= 2;
819 addToExistingSelection
= 1;
825 if ( addToExistingSelection
== 1 )
828 if ( !alreadySelected
)
830 res
= DoAddToSelection(prop
, selFlags
);
832 else if ( GetSelectedProperties().size() > 1 )
834 res
= DoRemoveFromSelection(prop
, selFlags
);
837 else if ( addToExistingSelection
== 2 )
839 // Add this, and all in between
841 // Find top selected property
842 wxPGProperty
* topSelProp
= selection
[0];
843 int topSelPropY
= topSelProp
->GetY();
844 for ( unsigned int i
=1; i
<selection
.size(); i
++ )
846 wxPGProperty
* p
= selection
[i
];
848 if ( y
< topSelPropY
)
855 wxPGProperty
* startFrom
;
856 wxPGProperty
* stopAt
;
858 if ( prop
->GetY() <= topSelPropY
)
860 // Property is above selection (or same)
866 // Property is below selection
867 startFrom
= topSelProp
;
871 // Iterate through properties in-between, and select them
872 wxPropertyGridIterator it
;
874 for ( it
= GetIterator(wxPG_ITERATE_VISIBLE
, startFrom
);
878 wxPGProperty
* p
= *it
;
880 if ( !p
->IsCategory() &&
881 !m_pState
->DoIsPropertySelected(p
) )
883 DoAddToSelection(p
, selFlags
);
892 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
898 // -----------------------------------------------------------------------
900 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
903 if ( newSelection
.size() > 0 )
905 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
910 DoClearSelection(false, selFlags
);
913 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
915 DoAddToSelection(newSelection
[i
], selFlags
);
921 // -----------------------------------------------------------------------
923 void wxPropertyGrid::MakeColumnEditable( unsigned int column
,
926 wxASSERT( column
!= 1 );
928 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
932 cols
.push_back(column
);
936 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
938 if ( cols
[i
] == (int)column
)
939 cols
.erase( cols
.begin() + i
);
944 // -----------------------------------------------------------------------
946 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
949 wxPGProperty
* selected
= GetSelection();
950 wxCHECK_RET(selected
, wxT("No property selected"));
951 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
953 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
955 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
962 const wxPGCell
* cell
= NULL
;
963 if ( selected
->HasCell(colIndex
) )
965 cell
= &selected
->GetCell(colIndex
);
966 if ( !cell
->HasText() && colIndex
== 0 )
967 text
= selected
->GetLabel();
973 text
= selected
->GetLabel();
975 cell
= &selected
->GetOrCreateCell(colIndex
);
978 if ( cell
&& cell
->HasText() )
979 text
= cell
->GetText();
981 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
983 m_selColumn
= colIndex
;
985 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
987 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
995 wxWindowID id
= tc
->GetId();
996 tc
->Connect(id
, wxEVT_TEXT_ENTER
,
997 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
999 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1000 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
1005 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1006 m_labelEditorProperty
= selected
;
1009 // -----------------------------------------------------------------------
1012 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1014 DoEndLabelEdit(true);
1017 // -----------------------------------------------------------------------
1019 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1021 int keycode
= event
.GetKeyCode();
1023 if ( keycode
== WXK_ESCAPE
)
1025 DoEndLabelEdit(false);
1029 HandleKeyEvent(event
, true);
1033 // -----------------------------------------------------------------------
1035 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1037 if ( !m_labelEditor
)
1040 wxPGProperty
* prop
= m_labelEditorProperty
;
1045 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1047 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1048 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1049 prop
, NULL
, selFlags
,
1054 wxString text
= m_labelEditor
->GetValue();
1055 wxPGCell
* cell
= NULL
;
1056 if ( prop
->HasCell(m_selColumn
) )
1058 cell
= &prop
->GetCell(m_selColumn
);
1062 if ( m_selColumn
== 0 )
1063 prop
->SetLabel(text
);
1065 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1069 cell
->SetText(text
);
1073 int wasFocused
= m_iFlags
& wxPG_FL_FOCUSED
;
1075 DestroyEditorWnd(m_labelEditor
);
1077 m_labelEditor
= NULL
;
1078 m_labelEditorProperty
= NULL
;
1080 // Fix focus (needed at least on wxGTK)
1087 // -----------------------------------------------------------------------
1089 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1091 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1092 OnTLPChanging(::wxGetTopLevelParent(this));
1094 OnTLPChanging(NULL
);
1096 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1098 #if defined(__WXMSW__)
1101 // Don't use WS_EX_COMPOSITED just now.
1104 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1105 hWnd = (HWND)GetParent()->GetHWND();
1107 hWnd = (HWND)GetHWND();
1109 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1110 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1113 //#elif defined(__WXGTK20__)
1115 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1116 // truly was double-buffered.
1117 if ( !this->IsDoubleBuffered() )
1119 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1123 wxDELETE(m_doubleBuffer
);
1127 wxControl::SetExtraStyle( exStyle
);
1129 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1130 m_pState
->InitNonCatMode();
1132 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1133 m_windowStyle
|= wxPG_TOOLTIPS
;
1136 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1139 // -----------------------------------------------------------------------
1141 // returns the best acceptable minimal size
1142 wxSize
wxPropertyGrid::DoGetBestSize() const
1144 int lineHeight
= wxMax(15, m_lineHeight
);
1146 // don't make the grid too tall (limit height to 10 items) but don't
1147 // make it too small neither
1148 int numLines
= wxMin
1150 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1154 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1155 int width
= m_marginWidth
;
1156 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1158 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1161 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1167 // -----------------------------------------------------------------------
1169 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1171 if ( newTLP
== m_tlp
)
1174 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1177 // Parent changed so let's redetermine and re-hook the
1178 // correct top-level window.
1181 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1182 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1184 m_tlpClosed
= m_tlp
;
1185 m_tlpClosedTime
= currentTime
;
1190 // Only accept new tlp if same one was not just dismissed.
1191 if ( newTLP
!= m_tlpClosed
||
1192 m_tlpClosedTime
+250 < currentTime
)
1194 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1195 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1208 // -----------------------------------------------------------------------
1210 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1212 // ClearSelection forces value validation/commit.
1213 if ( event
.CanVeto() && !DoClearSelection() )
1219 // Ok, it can close, set tlp pointer to NULL. Some other event
1220 // handler can of course veto the close, but our OnIdle() should
1221 // then be able to regain the tlp pointer.
1222 OnTLPChanging(NULL
);
1227 // -----------------------------------------------------------------------
1229 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1231 OnTLPChanging((wxWindow
*)newParent
);
1233 bool res
= wxControl::Reparent(newParent
);
1238 // -----------------------------------------------------------------------
1239 // wxPropertyGrid Font and Colour Methods
1240 // -----------------------------------------------------------------------
1242 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1246 m_captionFont
= wxControl::GetFont();
1248 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1249 m_subgroup_extramargin
= x
+ (x
/2);
1252 #if wxPG_USE_RENDERER_NATIVE
1253 m_iconWidth
= wxPG_ICON_WIDTH
;
1254 #elif wxPG_ICON_WIDTH
1256 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1257 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1258 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1262 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1263 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1264 m_gutterWidth
= wxPG_GUTTER_MIN
;
1267 if ( vspacing
<= 1 ) vdiv
= 12;
1268 else if ( vspacing
>= 3 ) vdiv
= 3;
1270 m_spacingy
= m_fontHeight
/ vdiv
;
1271 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1272 m_spacingy
= wxPG_YSPACING_MIN
;
1275 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1276 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1278 m_captionFont
.SetWeight(wxBOLD
);
1279 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1281 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1284 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1285 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1288 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1290 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1291 RecalculateVirtualSize();
1293 InvalidateBestSize();
1296 // -----------------------------------------------------------------------
1298 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1304 // -----------------------------------------------------------------------
1306 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1307 int ga
= 1000, int ba
= 1000,
1308 bool forceDifferent
= false)
1315 // Recursion guard (allow 2 max)
1316 static int isinside
= 0;
1318 wxCHECK_MSG( isinside
< 3,
1320 wxT("wxPGAdjustColour should not be recursively called more than once") );
1325 int g
= src
.Green();
1328 if ( r2
>255 ) r2
= 255;
1329 else if ( r2
<0) r2
= 0;
1331 if ( g2
>255 ) g2
= 255;
1332 else if ( g2
<0) g2
= 0;
1334 if ( b2
>255 ) b2
= 255;
1335 else if ( b2
<0) b2
= 0;
1337 // Make sure they are somewhat different
1338 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1339 dst
= wxPGAdjustColour(src
,-(ra
*2));
1341 dst
= wxColour(r2
,g2
,b2
);
1343 // Recursion guard (allow 2 max)
1350 static int wxPGGetColAvg( const wxColour
& col
)
1352 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1356 void wxPropertyGrid::RegainColours()
1358 if ( !(m_coloursCustomized
& 0x0002) )
1360 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1362 // Make sure colour is dark enough
1364 int colDec
= wxPGGetColAvg(col
) - 230;
1366 int colDec
= wxPGGetColAvg(col
) - 200;
1369 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1372 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1375 if ( !(m_coloursCustomized
& 0x0001) )
1376 m_colMargin
= m_colCapBack
;
1378 if ( !(m_coloursCustomized
& 0x0004) )
1385 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1386 m_colCapFore
= capForeCol
;
1387 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1390 if ( !(m_coloursCustomized
& 0x0008) )
1392 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1393 m_colPropBack
= bgCol
;
1394 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1395 if ( !m_unspecifiedAppearance
.GetBgCol().IsOk() )
1396 m_unspecifiedAppearance
.SetBgCol(bgCol
);
1399 if ( !(m_coloursCustomized
& 0x0010) )
1401 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1402 m_colPropFore
= fgCol
;
1403 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1404 if ( !m_unspecifiedAppearance
.GetFgCol().IsOk() )
1405 m_unspecifiedAppearance
.SetFgCol(fgCol
);
1408 if ( !(m_coloursCustomized
& 0x0020) )
1409 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1411 if ( !(m_coloursCustomized
& 0x0040) )
1412 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1414 if ( !(m_coloursCustomized
& 0x0080) )
1415 m_colLine
= m_colCapBack
;
1417 if ( !(m_coloursCustomized
& 0x0100) )
1418 m_colDisPropFore
= m_colCapFore
;
1420 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1423 // -----------------------------------------------------------------------
1425 void wxPropertyGrid::ResetColours()
1427 m_coloursCustomized
= 0;
1434 // -----------------------------------------------------------------------
1436 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1438 // Must disable active editor.
1441 bool res
= wxControl::SetFont( font
);
1442 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1444 CalculateFontAndBitmapStuff( m_vspacing
);
1451 // -----------------------------------------------------------------------
1453 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1456 m_coloursCustomized
|= 0x80;
1460 // -----------------------------------------------------------------------
1462 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1465 m_coloursCustomized
|= 0x01;
1469 // -----------------------------------------------------------------------
1471 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1473 m_colPropBack
= col
;
1474 m_coloursCustomized
|= 0x08;
1476 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1477 m_unspecifiedAppearance
.SetBgCol(col
);
1482 // -----------------------------------------------------------------------
1484 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1486 m_colPropFore
= col
;
1487 m_coloursCustomized
|= 0x10;
1489 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1490 m_unspecifiedAppearance
.SetFgCol(col
);
1495 // -----------------------------------------------------------------------
1497 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1499 m_colEmptySpace
= col
;
1504 // -----------------------------------------------------------------------
1506 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1508 m_colDisPropFore
= col
;
1509 m_coloursCustomized
|= 0x100;
1513 // -----------------------------------------------------------------------
1515 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1518 m_coloursCustomized
|= 0x20;
1522 // -----------------------------------------------------------------------
1524 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1527 m_coloursCustomized
|= 0x40;
1531 // -----------------------------------------------------------------------
1533 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1536 m_coloursCustomized
|= 0x02;
1538 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1543 // -----------------------------------------------------------------------
1545 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1548 m_coloursCustomized
|= 0x04;
1550 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1555 // -----------------------------------------------------------------------
1556 // wxPropertyGrid property adding and removal
1557 // -----------------------------------------------------------------------
1559 void wxPropertyGrid::PrepareAfterItemsAdded()
1561 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1563 m_pState
->m_itemsAdded
= 0;
1565 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1566 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1568 RecalculateVirtualSize();
1570 // Fix editor position
1571 CorrectEditorWidgetPosY();
1574 // -----------------------------------------------------------------------
1575 // wxPropertyGrid property operations
1576 // -----------------------------------------------------------------------
1578 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1580 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1584 bool changed
= false;
1586 // Is it inside collapsed section?
1587 if ( !p
->IsVisible() )
1590 wxPGProperty
* parent
= p
->GetParent();
1591 wxPGProperty
* grandparent
= parent
->GetParent();
1593 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1594 Expand( grandparent
);
1602 GetViewStart(&vx
,&vy
);
1603 vy
*=wxPG_PIXELS_PER_UNIT
;
1609 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1610 m_iFlags
|= wxPG_FL_SCROLLED
;
1613 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1615 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1616 m_iFlags
|= wxPG_FL_SCROLLED
;
1626 // -----------------------------------------------------------------------
1627 // wxPropertyGrid helper methods called by properties
1628 // -----------------------------------------------------------------------
1630 // Control font changer helper.
1631 void wxPropertyGrid::SetCurControlBoldFont()
1633 wxWindow
* editor
= GetEditorControl();
1634 editor
->SetFont( m_captionFont
);
1637 // -----------------------------------------------------------------------
1639 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1642 #if wxPG_SMALL_SCREEN
1643 // On small-screen devices, always show dialogs with default position and size.
1644 return wxDefaultPosition
;
1646 int splitterX
= GetSplitterPosition();
1650 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1652 ImprovedClientToScreen( &x
, &y
);
1654 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1655 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1662 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1672 new_y
= y
+ m_lineHeight
;
1674 return wxPoint(new_x
,new_y
);
1678 // -----------------------------------------------------------------------
1680 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1682 if ( src_str
.empty() )
1688 bool prev_is_slash
= false;
1690 wxString::const_iterator i
= src_str
.begin();
1694 for ( ; i
!= src_str
.end(); ++i
)
1698 if ( a
!= wxS('\\') )
1700 if ( !prev_is_slash
)
1706 if ( a
== wxS('n') )
1709 dst_str
<< wxS('\n');
1711 dst_str
<< wxS('\n');
1714 else if ( a
== wxS('t') )
1715 dst_str
<< wxS('\t');
1719 prev_is_slash
= false;
1723 if ( prev_is_slash
)
1725 dst_str
<< wxS('\\');
1726 prev_is_slash
= false;
1730 prev_is_slash
= true;
1737 // -----------------------------------------------------------------------
1739 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1741 if ( src_str
.empty() )
1747 wxString::const_iterator i
= src_str
.begin();
1748 wxUniChar prev_a
= wxS('\0');
1752 for ( ; i
!= src_str
.end(); ++i
)
1756 if ( a
>= wxS(' ') )
1758 // This surely is not something that requires an escape sequence.
1763 // This might need...
1764 if ( a
== wxS('\r') )
1766 // DOS style line end.
1767 // Already taken care below
1769 else if ( a
== wxS('\n') )
1770 // UNIX style line end.
1771 dst_str
<< wxS("\\n");
1772 else if ( a
== wxS('\t') )
1774 dst_str
<< wxS('\t');
1777 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1787 // -----------------------------------------------------------------------
1789 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1796 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1799 // -----------------------------------------------------------------------
1800 // wxPropertyGrid graphics related methods
1801 // -----------------------------------------------------------------------
1803 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1808 // Don't paint after destruction has begun
1809 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1812 // Find out where the window is scrolled to
1813 int vx
,vy
; // Top left corner of client
1814 GetViewStart(&vx
,&vy
);
1815 vy
*= wxPG_PIXELS_PER_UNIT
;
1817 // Update everything inside the box
1818 wxRect r
= GetUpdateRegion().GetBox();
1822 // FIXME: This is just a workaround for a bug that causes splitters not
1823 // to paint when other windows are being dragged over the grid.
1825 r
.width
= GetClientSize().x
;
1828 r
.height
= GetClientSize().y
;
1830 // Repaint this rectangle
1831 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1833 // We assume that the size set when grid is shown
1834 // is what is desired.
1835 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1838 // -----------------------------------------------------------------------
1840 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1841 wxPGProperty
* property
) const
1843 // Prepare rectangle to be used
1845 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1846 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1848 #if (wxPG_USE_RENDERER_NATIVE)
1850 #elif wxPG_ICON_WIDTH
1851 // Drawing expand/collapse button manually
1852 dc
.SetPen(m_colPropFore
);
1853 if ( property
->IsCategory() )
1854 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1856 dc
.SetBrush(m_colPropBack
);
1858 dc
.DrawRectangle( r
);
1859 int _y
= r
.y
+(m_iconWidth
/2);
1860 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1865 if ( property
->IsExpanded() )
1867 // wxRenderer functions are non-mutating in nature, so it
1868 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1869 // Hopefully this does not cause problems.
1870 #if (wxPG_USE_RENDERER_NATIVE)
1871 wxRendererNative::Get().DrawTreeItemButton(
1877 #elif wxPG_ICON_WIDTH
1886 #if (wxPG_USE_RENDERER_NATIVE)
1887 wxRendererNative::Get().DrawTreeItemButton(
1893 #elif wxPG_ICON_WIDTH
1894 int _x
= r
.x
+(m_iconWidth
/2);
1895 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1901 #if (wxPG_USE_RENDERER_NATIVE)
1903 #elif wxPG_ICON_WIDTH
1906 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1910 // -----------------------------------------------------------------------
1913 // This is the one called by OnPaint event handler and others.
1914 // topy and bottomy are already unscrolled (ie. physical)
1916 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1917 unsigned int topItemY
,
1918 unsigned int bottomItemY
,
1919 const wxRect
* itemsRect
)
1923 bottomItemY
< topItemY
||
1927 m_pState
->EnsureVirtualHeight();
1929 wxRect tempItemsRect
;
1932 tempItemsRect
= wxRect(0, topItemY
,
1935 itemsRect
= &tempItemsRect
;
1939 GetViewStart(&vx
, &vy
);
1940 vx
*= wxPG_PIXELS_PER_UNIT
;
1941 vy
*= wxPG_PIXELS_PER_UNIT
;
1943 // itemRect is in virtual grid space
1944 wxRect
drawRect(itemsRect
->x
- vx
,
1949 // items added check
1950 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1952 int paintFinishY
= 0;
1954 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1957 bool isBuffered
= false;
1959 wxMemoryDC
* bufferDC
= NULL
;
1961 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1963 if ( !m_doubleBuffer
)
1965 paintFinishY
= itemsRect
->y
;
1970 bufferDC
= new wxMemoryDC();
1972 // If nothing was changed, then just copy from double-buffer
1973 bufferDC
->SelectObject( *m_doubleBuffer
);
1982 // paintFinishY and drawBottomY are in buffer/physical space
1983 paintFinishY
= DoDrawItems( *dcPtr
, itemsRect
, isBuffered
);
1984 int drawBottomY
= itemsRect
->y
+ itemsRect
->height
- vy
;
1986 // Clear area beyond last painted property
1987 if ( paintFinishY
< drawBottomY
)
1989 dcPtr
->SetPen(m_colEmptySpace
);
1990 dcPtr
->SetBrush(m_colEmptySpace
);
1991 dcPtr
->DrawRectangle(0, paintFinishY
,
1999 dc
.Blit( drawRect
.x
, drawRect
.y
, drawRect
.width
,
2001 bufferDC
, 0, 0, wxCOPY
);
2007 // Just clear the area
2008 dc
.SetPen(m_colEmptySpace
);
2009 dc
.SetBrush(m_colEmptySpace
);
2010 dc
.DrawRectangle(drawRect
);
2014 // -----------------------------------------------------------------------
2016 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
2017 const wxRect
* itemsRect
,
2018 bool isBuffered
) const
2020 const wxPGProperty
* firstItem
;
2021 const wxPGProperty
* lastItem
;
2023 firstItem
= DoGetItemAtY(itemsRect
->y
);
2024 lastItem
= DoGetItemAtY(itemsRect
->y
+itemsRect
->height
-1);
2027 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
2029 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
2030 return itemsRect
->y
;
2032 wxCHECK_MSG( !m_pState
->m_itemsAdded
, itemsRect
->y
,
2034 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2036 int lh
= m_lineHeight
;
2039 int lastItemBottomY
;
2041 firstItemTopY
= itemsRect
->y
;
2042 lastItemBottomY
= itemsRect
->y
+ itemsRect
->height
;
2044 // Align y coordinates to item boundaries
2045 firstItemTopY
-= firstItemTopY
% lh
;
2046 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2047 lastItemBottomY
-= 1;
2049 // Entire range outside scrolled, visible area?
2050 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
2051 lastItemBottomY
<= 0 )
2052 return itemsRect
->y
;
2054 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
2056 "invalid y values" );
2059 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
2060 "height=%i (ch=%i), itemsRect = 0x%lX )",
2061 firstItem->GetLabel().c_str(),
2062 lastItem->GetLabel().c_str(),
2063 (int)(lastItemBottomY - firstItemTopY),
2065 (unsigned long)&itemsRect );
2070 long windowStyle
= m_windowStyle
;
2075 // For now, do some manual calculation for double buffering
2076 // - buffer's y = 0, so align itemsRect and coordinates to that
2078 // TODO: In future use wxAutoBufferedPaintDC (for example)
2086 xRelMod
= itemsRect
->x
;
2087 yRelMod
= itemsRect
->y
;
2090 // itemsRect conversion
2095 firstItemTopY
-= yRelMod
;
2096 lastItemBottomY
-= yRelMod
;
2099 int x
= m_marginWidth
- xRelMod
;
2101 wxFont normalFont
= GetFont();
2103 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2105 bool isPgEnabled
= IsEnabled();
2108 // Prepare some pens and brushes that are often changed to.
2111 wxBrush
marginBrush(m_colMargin
);
2112 wxPen
marginPen(m_colMargin
);
2113 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2114 wxPen
linepen(m_colLine
,1,wxSOLID
);
2116 wxColour selBackCol
;
2118 selBackCol
= m_colSelBack
;
2120 selBackCol
= m_colMargin
;
2122 // pen that has same colour as text
2123 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2126 // Clear margin with background colour
2128 dc
.SetBrush( marginBrush
);
2129 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2131 dc
.SetPen( *wxTRANSPARENT_PEN
);
2132 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2135 const wxPGProperty
* firstSelected
= GetSelection();
2136 const wxPropertyGridPageState
* state
= m_pState
;
2137 const wxArrayInt
& colWidths
= state
->m_colWidths
;
2139 // TODO: Only render columns that are within clipping region.
2141 dc
.SetFont(normalFont
);
2143 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2144 int endScanBottomY
= lastItemBottomY
+ lh
;
2145 int y
= firstItemTopY
;
2148 // Pregenerate list of visible properties.
2149 wxArrayPGProperty visPropArray
;
2150 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2152 for ( ; !it
.AtEnd(); it
.Next() )
2154 const wxPGProperty
* p
= *it
;
2156 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2158 visPropArray
.push_back((wxPGProperty
*)p
);
2160 if ( y
> endScanBottomY
)
2167 visPropArray
.push_back(NULL
);
2169 wxPGProperty
* nextP
= visPropArray
[0];
2171 int gridWidth
= state
->m_width
;
2174 for ( unsigned int arrInd
=1;
2175 nextP
&& y
<= lastItemBottomY
;
2178 wxPGProperty
* p
= nextP
;
2179 nextP
= visPropArray
[arrInd
];
2181 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2182 int textMarginHere
= x
;
2183 int renderFlags
= 0;
2185 int greyDepth
= m_marginWidth
;
2186 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2187 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2189 int greyDepthX
= greyDepth
- xRelMod
;
2191 // Use basic depth if in non-categoric mode and parent is base array.
2192 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2194 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2197 // Paint margin area
2198 dc
.SetBrush(marginBrush
);
2199 dc
.SetPen(marginPen
);
2200 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2202 dc
.SetPen( linepen
);
2208 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2209 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2210 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2212 // Is this or its parent themed?
2213 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2214 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2215 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2217 bool suppressMarginEdge
= false;
2219 if (!suppressMarginEdge
)
2220 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2223 // Blank out the margin edge
2224 dc
.SetPen(wxPen(GetBackgroundColour()));
2225 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2226 dc
.SetPen( linepen
);
2233 for ( si
=0; si
<colWidths
.size(); si
++ )
2235 sx
+= colWidths
[si
];
2236 dc
.DrawLine( sx
, y
, sx
, y2
);
2239 // Horizontal Line, below
2240 // (not if both this and next is category caption)
2241 if ( p
->IsCategory() &&
2242 nextP
&& nextP
->IsCategory() )
2243 dc
.SetPen(m_colCapBack
);
2245 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2248 // Need to override row colours?
2252 bool isSelected
= state
->DoIsPropertySelected(p
);
2256 // Disabled may get different colour.
2257 if ( !p
->IsEnabled() )
2259 renderFlags
|= wxPGCellRenderer::Disabled
|
2260 wxPGCellRenderer::DontUseCellFgCol
;
2261 rowFgCol
= m_colDisPropFore
;
2266 renderFlags
|= wxPGCellRenderer::Selected
;
2268 if ( !p
->IsCategory() )
2270 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2271 wxPGCellRenderer::DontUseCellBgCol
;
2273 if ( reallyFocused
&& p
== firstSelected
)
2275 rowFgCol
= m_colSelFore
;
2276 rowBgCol
= selBackCol
;
2278 else if ( isPgEnabled
)
2280 rowFgCol
= m_colPropFore
;
2281 if ( p
== firstSelected
)
2282 rowBgCol
= m_colMargin
;
2284 rowBgCol
= selBackCol
;
2288 rowFgCol
= m_colDisPropFore
;
2289 rowBgCol
= selBackCol
;
2296 if ( rowBgCol
.IsOk() )
2297 rowBgBrush
= wxBrush(rowBgCol
);
2299 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2300 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2303 // Fill additional margin area with background colour of first cell
2304 if ( greyDepthX
< textMarginHere
)
2306 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2308 wxPGCell
& cell
= p
->GetCell(0);
2309 rowBgCol
= cell
.GetBgCol();
2310 rowBgBrush
= wxBrush(rowBgCol
);
2312 dc
.SetBrush(rowBgBrush
);
2313 dc
.SetPen(rowBgCol
);
2314 dc
.DrawRectangle(greyDepthX
+1, y
,
2315 textMarginHere
-greyDepthX
, lh
-1);
2318 bool fontChanged
= false;
2320 // Expander button rectangle
2321 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2326 // Default cell rect fill the entire row
2327 wxRect
cellRect(greyDepthX
, y
,
2328 gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2330 bool isCategory
= p
->IsCategory();
2334 dc
.SetFont(m_captionFont
);
2337 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2339 dc
.SetBrush(rowBgBrush
);
2340 dc
.SetPen(rowBgCol
);
2343 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2345 dc
.SetTextForeground(rowFgCol
);
2350 // Fine tune button rectangle to actually fit the cell
2351 if ( butRect
.x
> 0 )
2352 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2354 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&&
2355 (windowStyle
& wxPG_BOLD_MODIFIED
) )
2357 dc
.SetFont(m_captionFont
);
2361 // Magic fine-tuning for non-category rows
2365 int firstCellWidth
= colWidths
[0] - (greyDepthX
- m_marginWidth
);
2366 int firstCellX
= cellRect
.x
;
2368 // Calculate cellRect.x for the last cell
2369 unsigned int ci
= 0;
2371 for ( ci
=0; ci
<colWidths
.size(); ci
++ )
2372 cellX
+= colWidths
[ci
];
2375 // Draw cells from back to front so that we can easily tell if the
2376 // cell on the right was empty from text
2377 bool prevFilled
= true;
2378 ci
= colWidths
.size();
2387 textXAdd
= textMarginHere
- greyDepthX
;
2388 cellRect
.width
= firstCellWidth
;
2389 cellRect
.x
= firstCellX
;
2393 int colWidth
= colWidths
[ci
];
2394 cellRect
.width
= colWidth
;
2395 cellRect
.x
-= colWidth
;
2398 // Merge with column to the right?
2399 if ( !prevFilled
&& isCategory
)
2401 cellRect
.width
+= colWidths
[ci
+1];
2405 cellRect
.width
-= 1;
2407 wxWindow
* cellEditor
= NULL
;
2408 int cellRenderFlags
= renderFlags
;
2410 // Tree Item Button (must be drawn before clipping is set up)
2411 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2412 DrawExpanderButton( dc
, butRect
, p
);
2415 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2417 if ( p
== firstSelected
)
2419 if ( ci
== 1 && m_wndEditor
)
2420 cellEditor
= m_wndEditor
;
2421 else if ( ci
== m_selColumn
&& m_labelEditor
)
2422 cellEditor
= m_labelEditor
;
2427 wxColour editorBgCol
=
2428 cellEditor
->GetBackgroundColour();
2429 dc
.SetBrush(editorBgCol
);
2430 dc
.SetPen(editorBgCol
);
2431 dc
.SetTextForeground(m_colPropFore
);
2432 dc
.DrawRectangle(cellRect
);
2434 if ( m_dragStatus
!= 0 ||
2435 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2440 dc
.SetBrush(m_colPropBack
);
2441 dc
.SetPen(m_colPropBack
);
2442 if ( p
->IsEnabled() )
2443 dc
.SetTextForeground(m_colPropFore
);
2445 dc
.SetTextForeground(m_colDisPropFore
);
2450 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2452 dc
.SetBrush(rowBgBrush
);
2453 dc
.SetPen(rowBgCol
);
2456 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2458 dc
.SetTextForeground(rowFgCol
);
2462 dc
.SetClippingRegion(cellRect
);
2464 cellRect
.x
+= textXAdd
;
2465 cellRect
.width
-= textXAdd
;
2470 wxPGCellRenderer
* renderer
;
2471 int cmnVal
= p
->GetCommonValue();
2472 if ( cmnVal
== -1 || ci
!= 1 )
2474 renderer
= p
->GetCellRenderer(ci
);
2475 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2481 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2482 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2492 dc
.DestroyClippingRegion(); // Is this really necessary?
2497 dc
.SetFont(normalFont
);
2505 // -----------------------------------------------------------------------
2507 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2511 if ( m_width
< 10 || m_height
< 10 ||
2512 !m_pState
->m_properties
->GetChildCount() ||
2514 return wxRect(0,0,0,0);
2519 // Return rect which encloses the given property range
2520 // (in logical grid coordinates)
2523 int visTop
= p1
->GetY();
2526 visBottom
= p2
->GetY() + m_lineHeight
;
2528 visBottom
= m_height
+ visTop
;
2530 // If seleced property is inside the range, we'll extend the range to include
2532 wxPGProperty
* selected
= GetSelection();
2535 int selectedY
= selected
->GetY();
2536 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2538 wxWindow
* editor
= GetEditorControl();
2541 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2542 if ( visBottom2
> visBottom
)
2543 visBottom
= visBottom2
;
2548 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2551 // -----------------------------------------------------------------------
2553 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2558 if ( m_pState
->m_itemsAdded
)
2559 PrepareAfterItemsAdded();
2561 wxRect r
= GetPropertyRect(p1
, p2
);
2564 // Convert rectangle from logical grid coordinates to physical ones
2566 GetViewStart(&vx
, &vy
);
2567 vx
*= wxPG_PIXELS_PER_UNIT
;
2568 vy
*= wxPG_PIXELS_PER_UNIT
;
2575 // -----------------------------------------------------------------------
2577 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2579 if ( m_pState
->DoIsPropertySelected(p
) || p
->IsChildSelected(true) )
2581 // NB: We must copy the selection.
2582 wxArrayPGProperty selection
= m_pState
->m_selection
;
2583 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2586 DrawItemAndChildren(p
);
2589 // -----------------------------------------------------------------------
2591 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2596 // Draw item, children, and parent too, if it is not category
2597 wxPGProperty
* parent
= p
->GetParent();
2600 !parent
->IsCategory() &&
2601 parent
->GetParent() )
2604 parent
= parent
->GetParent();
2607 DrawItemAndChildren(p
);
2610 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2612 wxCHECK_RET( p
, wxT("invalid property id") );
2614 // Do not draw if in non-visible page
2615 if ( p
->GetParentState() != m_pState
)
2618 // do not draw a single item if multiple pending
2619 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2622 // Update child control.
2623 wxPGProperty
* selected
= GetSelection();
2624 if ( selected
&& selected
->GetParent() == p
)
2627 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2629 DrawItems(p
, lastDrawn
);
2632 // -----------------------------------------------------------------------
2634 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2635 const wxRect
*rect
)
2637 PrepareAfterItemsAdded();
2639 wxWindow::Refresh(false, rect
);
2641 #if wxPG_REFRESH_CONTROLS
2642 // I think this really helps only GTK+1.2
2643 if ( m_wndEditor
) m_wndEditor
->Refresh();
2644 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2648 // -----------------------------------------------------------------------
2649 // wxPropertyGrid global operations
2650 // -----------------------------------------------------------------------
2652 void wxPropertyGrid::Clear()
2654 m_pState
->DoClear();
2660 RecalculateVirtualSize();
2662 // Need to clear some area at the end
2664 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2667 // -----------------------------------------------------------------------
2669 bool wxPropertyGrid::EnableCategories( bool enable
)
2676 // Enable categories
2679 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2684 // Disable categories
2686 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2689 if ( !m_pState
->EnableCategories(enable
) )
2694 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2696 m_pState
->m_itemsAdded
= 1; // force
2697 PrepareAfterItemsAdded();
2701 m_pState
->m_itemsAdded
= 1;
2703 // No need for RecalculateVirtualSize() here - it is already called in
2704 // wxPropertyGridPageState method above.
2711 // -----------------------------------------------------------------------
2713 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2715 wxASSERT( pNewState
);
2716 wxASSERT( pNewState
->GetGrid() );
2718 if ( pNewState
== m_pState
)
2721 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2723 // Call ClearSelection() instead of DoClearSelection()
2724 // so that selection clear events are not sent.
2727 m_pState
->m_selection
= oldSelection
;
2729 bool orig_mode
= m_pState
->IsInNonCatMode();
2730 bool new_state_mode
= pNewState
->IsInNonCatMode();
2732 m_pState
= pNewState
;
2735 int pgWidth
= GetClientSize().x
;
2736 if ( HasVirtualWidth() )
2738 int minWidth
= pgWidth
;
2739 if ( pNewState
->m_width
< minWidth
)
2741 pNewState
->m_width
= minWidth
;
2742 pNewState
->CheckColumnWidths();
2748 // Just in case, fully re-center splitter
2749 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2750 // pNewState->m_fSplitterX = -1.0;
2752 pNewState
->OnClientWidthChange(pgWidth
,
2753 pgWidth
- pNewState
->m_width
);
2758 // If necessary, convert state to correct mode.
2759 if ( orig_mode
!= new_state_mode
)
2761 // This should refresh as well.
2762 EnableCategories( orig_mode
?false:true );
2764 else if ( !m_frozen
)
2766 // Refresh, if not frozen.
2767 m_pState
->PrepareAfterItemsAdded();
2769 // Reselect (Use SetSelection() instead of Do-variant so that
2770 // events won't be sent).
2771 SetSelection(m_pState
->m_selection
);
2773 RecalculateVirtualSize(0);
2777 m_pState
->m_itemsAdded
= 1;
2780 // -----------------------------------------------------------------------
2782 // Call to SetSplitterPosition will always disable splitter auto-centering
2783 // if parent window is shown.
2784 void wxPropertyGrid::DoSetSplitterPosition( int newxpos
,
2788 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2791 wxPropertyGridPageState
* state
= m_pState
;
2793 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2794 state
->m_dontCenterSplitter
= true;
2796 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2798 if ( flags
& wxPG_SPLITTER_REFRESH
)
2800 if ( GetSelection() )
2801 CorrectEditorWidgetSizeX();
2809 // -----------------------------------------------------------------------
2811 void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing
)
2813 wxPropertyGridPageState
* state
= m_pState
;
2815 state
->ResetColumnSizes(0);
2817 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2818 m_pState
->m_dontCenterSplitter
= false;
2821 // -----------------------------------------------------------------------
2823 void wxPropertyGrid::CenterSplitter( bool enableAutoResizing
)
2825 SetSplitterPosition( m_width
/2 );
2826 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2827 m_pState
->m_dontCenterSplitter
= false;
2830 // -----------------------------------------------------------------------
2831 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2832 // -----------------------------------------------------------------------
2834 // Returns nearest paint visible property (such that will be painted unless
2835 // window is scrolled or resized). If given property is paint visible, then
2836 // it itself will be returned
2837 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2839 int vx
,vy1
;// Top left corner of client
2840 GetViewStart(&vx
,&vy1
);
2841 vy1
*= wxPG_PIXELS_PER_UNIT
;
2843 int vy2
= vy1
+ m_height
;
2844 int propY
= p
->GetY2(m_lineHeight
);
2846 if ( (propY
+ m_lineHeight
) < vy1
)
2849 return DoGetItemAtY( vy1
);
2851 else if ( propY
> vy2
)
2854 return DoGetItemAtY( vy2
);
2857 // Itself paint visible
2862 // -----------------------------------------------------------------------
2863 // Methods related to change in value, value modification and sending events
2864 // -----------------------------------------------------------------------
2866 // commits any changes in editor of selected property
2867 // return true if validation did not fail
2868 // flags are same as with DoSelectProperty
2869 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2871 // Committing already?
2872 if ( m_inCommitChangesFromEditor
)
2875 // Don't do this if already processing editor event. It might
2876 // induce recursive dialogs and crap like that.
2877 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2879 if ( m_inDoPropertyChanged
)
2885 wxPGProperty
* selected
= GetSelection();
2888 IsEditorsValueModified() &&
2889 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2892 m_inCommitChangesFromEditor
= true;
2894 wxVariant
variant(selected
->GetValueRef());
2895 bool valueIsPending
= false;
2897 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2898 // due to another window getting focus
2899 wxWindow
* oldFocus
= m_curFocused
;
2901 bool validationFailure
= false;
2902 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2904 m_chgInfo_changedProperty
= NULL
;
2906 // If truly modified, schedule value as pending.
2907 if ( selected
->GetEditorClass()->
2908 GetValueFromControl( variant
,
2910 GetEditorControl() ) )
2912 if ( DoEditorValidate() &&
2913 PerformValidation(selected
, variant
) )
2915 valueIsPending
= true;
2919 validationFailure
= true;
2924 EditorsValueWasNotModified();
2927 m_inCommitChangesFromEditor
= false;
2931 if ( validationFailure
&& !forceSuccess
)
2935 oldFocus
->SetFocus();
2936 m_curFocused
= oldFocus
;
2939 res
= OnValidationFailure(selected
, variant
);
2941 // Now prevent further validation failure messages
2944 EditorsValueWasNotModified();
2945 OnValidationFailureReset(selected
);
2948 else if ( valueIsPending
)
2950 DoPropertyChanged( selected
, flags
);
2951 EditorsValueWasNotModified();
2960 // -----------------------------------------------------------------------
2962 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2966 // Runs all validation functionality.
2967 // Returns true if value passes all tests.
2970 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2971 m_validationInfo
.m_isFailing
= true;
2974 // Variant list a special value that cannot be validated
2976 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2978 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2983 // Adapt list to child values, if necessary
2984 wxVariant listValue
= pendingValue
;
2985 wxVariant
* pPendingValue
= &pendingValue
;
2986 wxVariant
* pList
= NULL
;
2988 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2989 // string value, then we need treat as it was changed instead
2990 // (or, in addition, as is the case with composite string parent).
2991 // This includes creating list variant for child values.
2993 wxPGProperty
* pwc
= p
->GetParent();
2994 wxPGProperty
* changedProperty
= p
;
2995 wxPGProperty
* baseChangedProperty
= changedProperty
;
2996 wxVariant bcpPendingList
;
2998 listValue
= pendingValue
;
2999 listValue
.SetName(p
->GetBaseName());
3002 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
3004 wxVariantList tempList
;
3005 wxVariant
lv(tempList
, pwc
->GetBaseName());
3006 lv
.Append(listValue
);
3008 pPendingValue
= &listValue
;
3010 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
3012 baseChangedProperty
= pwc
;
3013 bcpPendingList
= lv
;
3016 changedProperty
= pwc
;
3017 pwc
= pwc
->GetParent();
3021 wxPGProperty
* evtChangingProperty
= changedProperty
;
3023 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
3025 value
= *pPendingValue
;
3029 // Convert list to child values
3030 pList
= pPendingValue
;
3031 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
3034 wxVariant evtChangingValue
= value
;
3036 if ( flags
& SendEvtChanging
)
3038 // FIXME: After proper ValueToString()s added, remove
3039 // this. It is just a temporary fix, as evt_changing
3040 // will simply not work for wxPG_PROP_COMPOSED_VALUE
3041 // (unless it is selected, and textctrl editor is open).
3042 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3044 evtChangingProperty
= baseChangedProperty
;
3045 if ( evtChangingProperty
!= p
)
3047 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
3051 evtChangingValue
= pendingValue
;
3055 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3057 if ( changedProperty
== GetSelection() )
3059 wxWindow
* editor
= GetEditorControl();
3060 wxASSERT( wxDynamicCast(editor
, wxTextCtrl
) );
3061 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
3065 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
3070 wxASSERT( m_chgInfo_changedProperty
== NULL
);
3071 m_chgInfo_changedProperty
= changedProperty
;
3072 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
3073 m_chgInfo_pendingValue
= value
;
3076 m_chgInfo_valueList
= *pList
;
3078 m_chgInfo_valueList
.MakeNull();
3080 // If changedProperty is not property which value was edited,
3081 // then call wxPGProperty::ValidateValue() for that as well.
3082 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3084 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3088 if ( flags
& SendEvtChanging
)
3090 // SendEvent returns true if event was vetoed
3091 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3092 &evtChangingValue
) )
3096 if ( flags
& IsStandaloneValidation
)
3098 // If called in 'generic' context, we need to reset
3099 // m_chgInfo_changedProperty and write back translated value.
3100 m_chgInfo_changedProperty
= NULL
;
3101 pendingValue
= value
;
3104 m_validationInfo
.m_isFailing
= false;
3109 // -----------------------------------------------------------------------
3112 wxStatusBar
* wxPropertyGrid::GetStatusBar()
3114 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3115 if ( wxDynamicCast(topWnd
, wxFrame
) )
3117 wxFrame
* pFrame
= wxStaticCast(topWnd
, wxFrame
);
3119 return pFrame
->GetStatusBar();
3125 // -----------------------------------------------------------------------
3127 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3133 if ( !wxPGGlobalVars
->m_offline
)
3135 wxStatusBar
* pStatusBar
= GetStatusBar();
3138 pStatusBar
->SetStatusText(msg
);
3144 ::wxMessageBox(msg
, _("Property Error"));
3147 // -----------------------------------------------------------------------
3149 void wxPropertyGrid::DoHidePropertyError( wxPGProperty
* WXUNUSED(property
) )
3152 if ( !wxPGGlobalVars
->m_offline
)
3154 wxStatusBar
* pStatusBar
= GetStatusBar();
3157 pStatusBar
->SetStatusText(wxEmptyString
);
3164 // -----------------------------------------------------------------------
3166 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3167 wxVariant
& invalidValue
)
3169 if ( m_inOnValidationFailure
)
3172 m_inOnValidationFailure
= true;
3173 wxON_BLOCK_EXIT_SET(m_inOnValidationFailure
, false);
3175 wxWindow
* editor
= GetEditorControl();
3176 int vfb
= m_validationInfo
.m_failureBehavior
;
3178 if ( m_inDoSelectProperty
)
3180 // When property selection is being changed, do not display any
3181 // messages, if some were already shown for this property.
3182 if ( property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3184 m_validationInfo
.m_failureBehavior
=
3185 vfb
& ~(wxPG_VFB_SHOW_MESSAGE
|
3186 wxPG_VFB_SHOW_MESSAGEBOX
|
3187 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
);
3191 // First call property's handler
3192 property
->OnValidationFailure(invalidValue
);
3194 bool res
= DoOnValidationFailure(property
, invalidValue
);
3197 // For non-wxTextCtrl editors, we do need to revert the value
3198 if ( !wxDynamicCast(editor
, wxTextCtrl
) &&
3199 property
== GetSelection() )
3201 property
->GetEditorClass()->UpdateControl(property
, editor
);
3204 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3209 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3211 int vfb
= m_validationInfo
.m_failureBehavior
;
3213 if ( vfb
& wxPG_VFB_BEEP
)
3216 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3217 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3219 unsigned int colCount
= m_pState
->GetColumnCount();
3221 // We need backup marked property's cells
3222 m_propCellsBackup
= property
->m_cells
;
3224 wxColour vfbFg
= *wxWHITE
;
3225 wxColour vfbBg
= *wxRED
;
3227 property
->EnsureCells(colCount
);
3229 for ( unsigned int i
=0; i
<colCount
; i
++ )
3231 wxPGCell
& cell
= property
->m_cells
[i
];
3232 cell
.SetFgCol(vfbFg
);
3233 cell
.SetBgCol(vfbBg
);
3236 DrawItemAndChildren(property
);
3238 if ( property
== GetSelection() )
3240 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3242 wxWindow
* editor
= GetEditorControl();
3245 editor
->SetForegroundColour(vfbFg
);
3246 editor
->SetBackgroundColour(vfbBg
);
3251 if ( vfb
& (wxPG_VFB_SHOW_MESSAGE
|
3252 wxPG_VFB_SHOW_MESSAGEBOX
|
3253 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
) )
3255 wxString msg
= m_validationInfo
.m_failureMessage
;
3258 msg
= _("You have entered invalid value. Press ESC to cancel editing.");
3261 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3263 if ( !wxPGGlobalVars
->m_offline
)
3265 wxStatusBar
* pStatusBar
= GetStatusBar();
3267 pStatusBar
->SetStatusText(msg
);
3272 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3273 DoShowPropertyError(property
, msg
);
3275 if ( vfb
& wxPG_VFB_SHOW_MESSAGEBOX
)
3276 ::wxMessageBox(msg
, _("Property Error"));
3279 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3282 // -----------------------------------------------------------------------
3284 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3286 int vfb
= m_validationInfo
.m_failureBehavior
;
3288 if ( vfb
& wxPG_VFB_MARK_CELL
)
3291 property
->m_cells
= m_propCellsBackup
;
3293 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3295 if ( property
== GetSelection() && GetEditorControl() )
3297 // Calling this will recreate the control, thus resetting its colour
3298 RefreshProperty(property
);
3302 DrawItemAndChildren(property
);
3307 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3309 if ( !wxPGGlobalVars
->m_offline
)
3311 wxStatusBar
* pStatusBar
= GetStatusBar();
3313 pStatusBar
->SetStatusText(wxEmptyString
);
3318 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3320 DoHidePropertyError(property
);
3323 m_validationInfo
.m_isFailing
= false;
3326 // -----------------------------------------------------------------------
3328 // flags are same as with DoSelectProperty
3329 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3331 if ( m_inDoPropertyChanged
)
3334 m_inDoPropertyChanged
= true;
3335 wxON_BLOCK_EXIT_SET(m_inDoPropertyChanged
, false);
3337 wxPGProperty
* selected
= GetSelection();
3339 m_pState
->m_anyModified
= 1;
3341 // If property's value is being changed, assume it is valid
3342 OnValidationFailureReset(selected
);
3344 // Maybe need to update control
3345 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3347 // These values were calculated in PerformValidation()
3348 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3349 wxVariant value
= m_chgInfo_pendingValue
;
3351 wxPGProperty
* topPaintedProperty
= changedProperty
;
3353 while ( !topPaintedProperty
->IsCategory() &&
3354 !topPaintedProperty
->IsRoot() )
3356 topPaintedProperty
= topPaintedProperty
->GetParent();
3359 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3361 // NB: Call GetEditorControl() as late as possible, because OnSetValue()
3362 // and perhaps other user-defined virtual functions may change it.
3363 wxWindow
* editor
= GetEditorControl();
3365 // Set as Modified (not if dragging just began)
3366 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3368 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3369 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3372 SetCurControlBoldFont();
3378 // Propagate updates to parent(s)
3380 wxPGProperty
* prevPwc
= NULL
;
3382 while ( prevPwc
!= topPaintedProperty
)
3384 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3386 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3389 SetCurControlBoldFont();
3393 pwc
= pwc
->GetParent();
3396 // Draw the actual property
3397 DrawItemAndChildren( topPaintedProperty
);
3400 // If value was set by wxPGProperty::OnEvent, then update the editor
3402 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3408 #if wxPG_REFRESH_CONTROLS
3409 if ( m_wndEditor
) m_wndEditor
->Refresh();
3410 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3415 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3417 // If top parent has composite string value, then send to child parents,
3418 // starting from baseChangedProperty.
3419 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3421 pwc
= m_chgInfo_baseChangedProperty
;
3423 while ( pwc
!= changedProperty
)
3425 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3426 pwc
= pwc
->GetParent();
3430 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3435 // -----------------------------------------------------------------------
3437 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3439 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3441 m_chgInfo_changedProperty
= NULL
;
3443 if ( PerformValidation(p
, newValue
) )
3445 DoPropertyChanged(p
);
3450 OnValidationFailure(p
, newValue
);
3456 // -----------------------------------------------------------------------
3458 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3460 wxPGProperty
* prop
= GetSelectedProperty();
3463 return wxNullVariant
;
3465 wxTextCtrl
* tc
= GetEditorTextCtrl();
3466 wxVariant value
= prop
->GetValue();
3468 if ( !tc
|| !IsEditorsValueModified() )
3471 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3474 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3475 return prop
->GetValue();
3480 // -----------------------------------------------------------------------
3482 // Runs wxValidator for the selected property
3483 bool wxPropertyGrid::DoEditorValidate()
3485 #if wxUSE_VALIDATORS
3486 wxRecursionGuard
guard(m_validatingEditor
);
3487 if ( guard
.IsInside() )
3490 wxPGProperty
* selected
= GetSelection();
3493 wxWindow
* wnd
= GetEditorControl();
3495 wxValidator
* validator
= selected
->GetValidator();
3496 if ( validator
&& wnd
)
3498 validator
->SetWindow(wnd
);
3499 if ( !validator
->Validate(this) )
3507 // -----------------------------------------------------------------------
3509 bool wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3512 // NB: We should return true if the event was recognized as
3513 // a dedicated wxPropertyGrid event, and as such was
3514 // either properly handled or ignored.
3517 // It is possible that this handler receives event even before
3518 // the control has been properly initialized. Let's skip the
3519 // event handling in that case.
3523 // Don't care about the event if it originated from the
3524 // 'label editor'. In this function we only care about the
3525 // property value editor.
3526 if ( m_labelEditor
&& event
.GetId() == m_labelEditor
->GetId() )
3532 wxPGProperty
* selected
= GetSelection();
3534 // Somehow, event is handled after property has been deselected.
3535 // Possibly, but very rare.
3537 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3538 m_inOnValidationFailure
||
3539 // Also don't handle editor event if wxEVT_PG_CHANGED or
3540 // similar is currently doing something (showing a
3541 // message box, for instance).
3545 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3548 wxVariant
pendingValue(selected
->GetValueRef());
3549 wxWindow
* wnd
= GetEditorControl();
3550 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3552 bool wasUnspecified
= selected
->IsValueUnspecified();
3553 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3554 bool valueIsPending
= false;
3556 m_chgInfo_changedProperty
= NULL
;
3558 m_iFlags
&= ~wxPG_FL_VALUE_CHANGE_IN_EVENT
;
3561 // Filter out excess wxTextCtrl modified events
3562 if ( event
.GetEventType() == wxEVT_TEXT
&& wnd
)
3564 if ( wxDynamicCast(wnd
, wxTextCtrl
) )
3566 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3568 wxString newTcValue
= tc
->GetValue();
3569 if ( m_prevTcValue
== newTcValue
)
3571 m_prevTcValue
= newTcValue
;
3573 else if ( wxDynamicCast(wnd
, wxComboCtrl
) )
3575 // In some cases we might stumble unintentionally on
3576 // wxComboCtrl's embedded wxTextCtrl's events. Let's
3578 if ( wxDynamicCast(editorWnd
, wxTextCtrl
) )
3581 wxComboCtrl
* cc
= (wxComboCtrl
*) wnd
;
3583 wxString newTcValue
= cc
->GetTextCtrl()->GetValue();
3584 if ( m_prevTcValue
== newTcValue
)
3586 m_prevTcValue
= newTcValue
;
3590 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3592 bool validationFailure
= false;
3593 bool buttonWasHandled
= false;
3594 bool result
= false;
3597 // Try common button handling
3598 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_BUTTON
)
3600 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3604 buttonWasHandled
= true;
3605 // Store as res2, as previously (and still currently alternatively)
3606 // dialogs can be shown by handling wxEVT_BUTTON
3607 // in wxPGProperty::OnEvent().
3608 adapter
->ShowDialog( this, selected
);
3613 if ( !buttonWasHandled
)
3615 if ( wnd
|| m_wndEditor2
)
3617 // First call editor class' event handler.
3618 const wxPGEditor
* editor
= selected
->GetEditorClass();
3620 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3624 // If changes, validate them
3625 if ( DoEditorValidate() )
3627 if ( editor
->GetValueFromControl( pendingValue
,
3630 valueIsPending
= true;
3632 // Mark value always as pending if validation is currently
3633 // failing and value was not unspecified
3634 if ( !valueIsPending
&&
3635 !pendingValue
.IsNull() &&
3636 m_validationInfo
.m_isFailing
)
3637 valueIsPending
= true;
3641 validationFailure
= true;
3646 // Then the property's custom handler (must be always called, unless
3647 // validation failed).
3648 if ( !validationFailure
)
3649 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3652 // SetValueInEvent(), as called in one of the functions referred above
3653 // overrides editor's value.
3654 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3656 valueIsPending
= true;
3657 pendingValue
= m_changeInEventValue
;
3658 selFlags
|= wxPG_SEL_DIALOGVAL
;
3661 if ( !validationFailure
&& valueIsPending
)
3662 if ( !PerformValidation(selected
, pendingValue
) )
3663 validationFailure
= true;
3665 if ( validationFailure
)
3667 OnValidationFailure(selected
, pendingValue
);
3669 else if ( valueIsPending
)
3671 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3673 DoPropertyChanged(selected
, selFlags
);
3674 EditorsValueWasNotModified();
3676 // Regardless of editor type, unfocus editor on
3677 // text-editing related enter press.
3678 if ( event
.GetEventType() == wxEVT_TEXT_ENTER
)
3685 // No value after all
3687 // Regardless of editor type, unfocus editor on
3688 // text-editing related enter press.
3689 if ( event
.GetEventType() == wxEVT_TEXT_ENTER
)
3694 // Let unhandled button click events go to the parent
3695 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_BUTTON
)
3698 wxCommandEvent
evt(wxEVT_BUTTON
,GetId());
3699 GetEventHandler()->AddPendingEvent(evt
);
3703 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3708 // -----------------------------------------------------------------------
3709 // wxPropertyGrid editor control helper methods
3710 // -----------------------------------------------------------------------
3712 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3714 int itemy
= p
->GetY2(m_lineHeight
);
3715 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3716 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3717 int imageOffset
= 0;
3719 int vx
, vy
; // Top left corner of client
3720 GetViewStart(&vx
, &vy
);
3721 vy
*= wxPG_PIXELS_PER_UNIT
;
3725 // TODO: If custom image detection changes from current, change this.
3726 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3728 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3729 int iw
= p
->OnMeasureImage().x
;
3731 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3732 imageOffset
= p
->GetImageOffset(iw
);
3735 else if ( column
== 0 )
3737 splitterX
+= (p
->m_depth
- 1) * m_subgroup_extramargin
;
3742 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3744 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3749 // -----------------------------------------------------------------------
3751 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3753 wxSize sz
= GetImageSize(p
, item
);
3754 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3755 wxPG_CUSTOM_IMAGE_SPACINGY
,
3760 // return size of custom paint image
3761 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3763 // If called with NULL property, then return default image
3764 // size for properties that use image.
3766 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3768 wxSize cis
= p
->OnMeasureImage(item
);
3770 int choiceCount
= p
->m_choices
.GetCount();
3771 int comVals
= p
->GetDisplayedCommonValueCount();
3772 if ( item
>= choiceCount
&& comVals
> 0 )
3774 unsigned int cvi
= item
-choiceCount
;
3775 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3777 else if ( item
>= 0 && choiceCount
== 0 )
3778 return wxSize(0, 0);
3783 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3788 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3795 // -----------------------------------------------------------------------
3797 // takes scrolling into account
3798 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3801 GetViewStart(&vx
,&vy
);
3802 vy
*=wxPG_PIXELS_PER_UNIT
;
3803 vx
*=wxPG_PIXELS_PER_UNIT
;
3806 ClientToScreen( px
, py
);
3809 // -----------------------------------------------------------------------
3811 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3814 GetViewStart(&pt2
.x
,&pt2
.y
);
3815 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3816 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3820 return m_pState
->HitTest(pt2
);
3823 // -----------------------------------------------------------------------
3825 // custom set cursor
3826 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3828 if ( type
== m_curcursor
&& !override
) return;
3830 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3832 if ( type
== wxCURSOR_SIZEWE
)
3833 cursor
= m_cursorSizeWE
;
3835 SetCursor( *cursor
);
3840 // -----------------------------------------------------------------------
3843 wxPropertyGrid::GetUnspecifiedValueText( int argFlags
) const
3845 const wxPGCell
& ua
= GetUnspecifiedValueAppearance();
3847 if ( ua
.HasText() &&
3848 !(argFlags
& wxPG_FULL_VALUE
) &&
3849 !(argFlags
& wxPG_EDITABLE_VALUE
) )
3850 return ua
.GetText();
3852 return wxEmptyString
;
3855 // -----------------------------------------------------------------------
3856 // wxPropertyGrid property selection, editor creation
3857 // -----------------------------------------------------------------------
3860 // This class forwards events from property editor controls to wxPropertyGrid.
3861 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3864 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3865 : wxEvtHandler(), m_propGrid(propGrid
)
3869 virtual ~wxPropertyGridEditorEventForwarder()
3874 bool ProcessEvent( wxEvent
& event
)
3879 m_propGrid
->HandleCustomEditorEvent(event
);
3882 // NB: We should return true if the event was recognized as
3883 // a dedicated wxPropertyGrid event, and as such was
3884 // either properly handled or ignored.
3886 if ( m_propGrid
->IsMainButtonEvent(event
) )
3890 // NB: On wxMSW, a wxTextCtrl with wxTE_PROCESS_ENTER
3891 // may beep annoyingly if that event is skipped
3892 // and passed to parent event handler.
3893 if ( event
.GetEventType() == wxEVT_TEXT_ENTER
)
3896 return wxEvtHandler::ProcessEvent(event
);
3899 wxPropertyGrid
* m_propGrid
;
3902 // Setups event handling for child control
3903 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3905 wxWindowID id
= argWnd
->GetId();
3907 if ( argWnd
== m_wndEditor
)
3909 argWnd
->Connect(id
, wxEVT_MOTION
,
3910 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3912 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3913 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3915 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3916 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3918 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3919 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3921 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3922 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3924 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3925 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3929 wxPropertyGridEditorEventForwarder
* forwarder
;
3930 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3931 argWnd
->PushEventHandler(forwarder
);
3933 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3934 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3938 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3945 // Do not free editors immediately (for sake of processing events)
3946 wxPendingDelete
.Append(wnd
);
3949 void wxPropertyGrid::FreeEditors()
3952 // Return focus back to canvas from children (this is required at least for
3953 // GTK+, which, unlike Windows, clears focus when control is destroyed
3954 // instead of moving it to closest parent).
3957 // Do not free editors immediately if processing events
3960 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3961 m_wndEditor2
->Hide();
3962 wxPendingDelete
.Append( handler
);
3963 DestroyEditorWnd(m_wndEditor2
);
3964 m_wndEditor2
= NULL
;
3969 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3970 m_wndEditor
->Hide();
3971 wxPendingDelete
.Append( handler
);
3972 DestroyEditorWnd(m_wndEditor
);
3977 // Call with NULL to de-select property
3978 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3983 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3984 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3988 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3992 if ( m_inDoSelectProperty
)
3995 m_inDoSelectProperty
= true;
3996 wxON_BLOCK_EXIT_SET(m_inDoSelectProperty
, false);
4001 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
4002 wxPGProperty
* prevFirstSel
;
4004 if ( prevSelection
.size() > 0 )
4005 prevFirstSel
= prevSelection
[0];
4007 prevFirstSel
= NULL
;
4009 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
4010 prevFirstSel
= NULL
;
4012 // Always send event, as this is indirect call
4013 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4017 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
4019 wxPrintf( "None selected\n" );
4022 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
4024 wxPrintf( "P = NULL\n" );
4027 wxWindow
* primaryCtrl
= NULL
;
4029 // If we are frozen, then just set the values.
4032 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4033 m_editorFocused
= 0;
4034 m_pState
->DoSetSelection(p
);
4036 // If frozen, always free controls. But don't worry, as Thaw will
4037 // recall SelectProperty to recreate them.
4040 // Prevent any further selection measures in this call
4046 if ( prevFirstSel
== p
&&
4047 prevSelection
.size() <= 1 &&
4048 !(flags
& wxPG_SEL_FORCE
) )
4050 // Only set focus if not deselecting
4053 if ( flags
& wxPG_SEL_FOCUS
)
4057 m_wndEditor
->SetFocus();
4058 m_editorFocused
= 1;
4071 // First, deactivate previous
4074 // Must double-check if this is an selected in case of forceswitch
4075 if ( p
!= prevFirstSel
)
4077 if ( !CommitChangesFromEditor(flags
) )
4079 // Validation has failed, so we can't exit the previous editor
4080 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
4081 // _("Invalid Value"),wxOK|wxICON_ERROR);
4086 // This should be called after CommitChangesFromEditor(), so that
4087 // OnValidationFailure() still has information on property's
4088 // validation state.
4089 OnValidationFailureReset(prevFirstSel
);
4093 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4094 EditorsValueWasNotModified();
4097 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4099 m_pState
->DoSetSelection(p
);
4101 // Redraw unselected
4102 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
4104 DrawItem(prevSelection
[i
]);
4108 // Then, activate the one given.
4111 int propY
= p
->GetY2(m_lineHeight
);
4113 int splitterX
= GetSplitterPosition();
4114 m_editorFocused
= 0;
4115 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
4117 wxASSERT( m_wndEditor
== NULL
);
4120 // Only create editor for non-disabled non-caption
4121 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
4123 // do this for non-caption items
4127 // Do we need to paint the custom image, if any?
4128 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
4129 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
4130 !p
->GetEditorClass()->CanContainCustomImage()
4132 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
4134 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
4135 wxPoint goodPos
= grect
.GetPosition();
4137 // Editor appearance can now be considered clear
4138 m_editorAppearance
.SetEmptyData();
4140 const wxPGEditor
* editor
= p
->GetEditorClass();
4141 wxCHECK_MSG(editor
, false,
4142 wxT("NULL editor class not allowed"));
4144 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
4146 wxPGWindowList wndList
=
4147 editor
->CreateControls(this,
4152 m_wndEditor
= wndList
.m_primary
;
4153 m_wndEditor2
= wndList
.m_secondary
;
4154 primaryCtrl
= GetEditorControl();
4157 // Essentially, primaryCtrl == m_wndEditor
4160 // NOTE: It is allowed for m_wndEditor to be NULL - in this
4161 // case value is drawn as normal, and m_wndEditor2 is
4162 // assumed to be a right-aligned button that triggers
4163 // a separate editorCtrl window.
4167 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
4168 "CreateControls must use result of "
4169 "wxPropertyGrid::GetPanel() as parent "
4172 // Set validator, if any
4173 #if wxUSE_VALIDATORS
4174 wxValidator
* validator
= p
->GetValidator();
4176 primaryCtrl
->SetValidator(*validator
);
4179 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
4180 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
4182 // If it has modified status, use bold font
4183 // (must be done before capturing m_ctrlXAdjust)
4184 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
4185 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
4186 SetCurControlBoldFont();
4188 // Store x relative to splitter (we'll need it).
4189 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
4191 // Check if background clear is not necessary
4192 wxPoint pos
= m_wndEditor
->GetPosition();
4193 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
4195 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
4198 m_wndEditor
->SetSizeHints(3, 3);
4200 SetupChildEventHandling(primaryCtrl
);
4202 // Focus and select all (wxTextCtrl, wxComboBox etc)
4203 if ( flags
& wxPG_SEL_FOCUS
)
4205 primaryCtrl
->SetFocus();
4207 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
4211 if ( p
->IsValueUnspecified() )
4212 SetEditorAppearance(m_unspecifiedAppearance
,
4219 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
4220 "CreateControls must use result of "
4221 "wxPropertyGrid::GetPanel() as parent "
4224 // Get proper id for wndSecondary
4225 m_wndSecId
= m_wndEditor2
->GetId();
4226 wxWindowList children
= m_wndEditor2
->GetChildren();
4227 wxWindowList::iterator node
= children
.begin();
4228 if ( node
!= children
.end() )
4229 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
4231 m_wndEditor2
->SetSizeHints(3,3);
4233 m_wndEditor2
->Show();
4235 SetupChildEventHandling(m_wndEditor2
);
4237 // If no primary editor, focus to button to allow
4238 // it to interprete ENTER etc.
4239 // NOTE: Due to problems focusing away from it, this
4240 // has been disabled.
4242 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
4243 m_wndEditor2->SetFocus();
4247 if ( flags
& wxPG_SEL_FOCUS
)
4248 m_editorFocused
= 1;
4253 // Make sure focus is in grid canvas (important for wxGTK,
4258 EditorsValueWasNotModified();
4260 // If it's inside collapsed section, expand parent, scroll, etc.
4261 // Also, if it was partially visible, scroll it into view.
4262 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
4267 m_wndEditor
->Show(true);
4270 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
4275 // Make sure focus is in grid canvas
4279 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4282 const wxString
* pHelpString
= NULL
;
4285 pHelpString
= &p
->GetHelpString();
4287 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4292 // Show help text in status bar.
4293 // (if found and grid not embedded in manager with help box and
4294 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4296 wxStatusBar
* statusbar
= GetStatusBar();
4299 if ( pHelpString
&& !pHelpString
->empty() )
4301 // Set help box text.
4302 statusbar
->SetStatusText( *pHelpString
);
4303 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4305 else if ( m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
)
4307 // Clear help box - but only if it was written
4308 // by us at previous time.
4309 statusbar
->SetStatusText( m_emptyString
);
4310 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4317 #if wxPG_SUPPORT_TOOLTIPS
4319 // Show help as a tool tip on the editor control.
4321 if ( pHelpString
&& !pHelpString
->empty() &&
4324 primaryCtrl
->SetToolTip(*pHelpString
);
4329 // call wx event handler (here so that it also occurs on deselection)
4330 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4331 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4336 // -----------------------------------------------------------------------
4338 bool wxPropertyGrid::UnfocusEditor()
4340 wxPGProperty
* selected
= GetSelection();
4342 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4345 if ( !CommitChangesFromEditor(0) )
4354 // -----------------------------------------------------------------------
4356 void wxPropertyGrid::RefreshEditor()
4358 wxPGProperty
* p
= GetSelection();
4362 wxWindow
* wnd
= GetEditorControl();
4366 // Set editor font boldness - must do this before
4367 // calling UpdateControl().
4368 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4370 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4371 wnd
->SetFont(GetCaptionFont());
4373 wnd
->SetFont(GetFont());
4376 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4378 editorClass
->UpdateControl(p
, wnd
);
4380 if ( p
->IsValueUnspecified() )
4381 SetEditorAppearance(m_unspecifiedAppearance
, true);
4384 // -----------------------------------------------------------------------
4386 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4388 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4390 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4392 flags
|= wxPG_SEL_FOCUS
;
4394 return DoSelectProperty(p
, flags
);
4397 // -----------------------------------------------------------------------
4398 // wxPropertyGrid expand/collapse state
4399 // -----------------------------------------------------------------------
4401 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4403 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4404 wxPGProperty
* selected
= GetSelection();
4406 // If active editor was inside collapsed section, then disable it
4407 if ( selected
&& selected
->IsSomeParent(p
) )
4412 // Store dont-center-splitter flag 'cause we need to temporarily set it
4413 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4414 m_pState
->m_dontCenterSplitter
= true;
4416 bool res
= m_pState
->DoCollapse(pwc
);
4421 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4423 RecalculateVirtualSize();
4427 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4432 // -----------------------------------------------------------------------
4434 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4436 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4438 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4440 // Store dont-center-splitter flag 'cause we need to temporarily set it
4441 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4442 m_pState
->m_dontCenterSplitter
= true;
4444 bool res
= m_pState
->DoExpand(pwc
);
4449 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4451 RecalculateVirtualSize();
4455 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4460 // -----------------------------------------------------------------------
4462 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4465 return m_pState
->DoHideProperty(p
, hide
, flags
);
4467 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4468 int selRemoveCount
= 0;
4469 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4471 wxPGProperty
* selected
= selection
[i
];
4472 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4474 if ( !DoRemoveFromSelection(p
, flags
) )
4476 selRemoveCount
+= 1;
4480 m_pState
->DoHideProperty(p
, hide
, flags
);
4482 RecalculateVirtualSize();
4489 // -----------------------------------------------------------------------
4490 // wxPropertyGrid size related methods
4491 // -----------------------------------------------------------------------
4493 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4495 // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise
4496 // virtual size calculation may go wrong.
4497 if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4503 // If virtual height was changed, then recalculate editor control position(s)
4504 if ( m_pState
->m_vhCalcPending
)
4505 CorrectEditorWidgetPosY();
4507 m_pState
->EnsureVirtualHeight();
4509 wxASSERT_LEVEL_2_MSG(
4510 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4511 "VirtualHeight and ActualVirtualHeight should match"
4514 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4516 int x
= m_pState
->m_width
;
4517 int y
= m_pState
->m_virtualHeight
;
4520 GetClientSize(&width
,&height
);
4522 // Now adjust virtual size.
4523 SetVirtualSize(x
, y
);
4529 // Adjust scrollbars
4530 if ( HasVirtualWidth() )
4532 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4533 xPos
= GetScrollPos( wxHORIZONTAL
);
4536 if ( forceXPos
!= -1 )
4539 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4542 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4543 int yPos
= GetScrollPos( wxVERTICAL
);
4545 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4546 xAmount
, yAmount
, xPos
, yPos
, true );
4548 // This may be needed in addition to calling SetScrollbars()
4549 // when class inherits from wxScrollHelper instead of
4550 // actual wxScrolled<T>.
4553 // Must re-get size now
4554 GetClientSize(&width
,&height
);
4556 if ( !HasVirtualWidth() )
4558 m_pState
->SetVirtualWidth(width
);
4564 m_pState
->CheckColumnWidths();
4566 if ( GetSelection() )
4567 CorrectEditorWidgetSizeX();
4569 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4572 // -----------------------------------------------------------------------
4574 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4576 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4580 GetClientSize(&width
, &height
);
4585 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4587 int dblh
= (m_lineHeight
*2);
4588 if ( !m_doubleBuffer
)
4590 // Create double buffer bitmap to draw on, if none
4591 int w
= (width
>250)?width
:250;
4592 int h
= height
+ dblh
;
4594 m_doubleBuffer
= new wxBitmap( w
, h
);
4598 int w
= m_doubleBuffer
->GetWidth();
4599 int h
= m_doubleBuffer
->GetHeight();
4601 // Double buffer must be large enough
4602 if ( w
< width
|| h
< (height
+dblh
) )
4604 if ( w
< width
) w
= width
;
4605 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4606 delete m_doubleBuffer
;
4607 m_doubleBuffer
= new wxBitmap( w
, h
);
4612 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4613 m_ncWidth
= event
.GetSize().x
;
4617 if ( m_pState
->m_itemsAdded
)
4618 PrepareAfterItemsAdded();
4620 // Without this, virtual size (atleast under wxGTK) will be skewed
4621 RecalculateVirtualSize();
4627 // -----------------------------------------------------------------------
4629 void wxPropertyGrid::SetVirtualWidth( int width
)
4633 // Disable virtual width
4634 width
= GetClientSize().x
;
4635 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4639 // Enable virtual width
4640 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4642 m_pState
->SetVirtualWidth( width
);
4645 void wxPropertyGrid::SetFocusOnCanvas()
4647 // To prevent wxPropertyGrid from stealing focus from other controls,
4648 // only move focus to the grid if it was already in one if its child
4650 wxWindow
* focus
= wxWindow::FindFocus();
4653 wxWindow
* parent
= focus
->GetParent();
4656 if ( parent
== this )
4661 parent
= parent
->GetParent();
4665 m_editorFocused
= 0;
4668 // -----------------------------------------------------------------------
4669 // wxPropertyGrid mouse event handling
4670 // -----------------------------------------------------------------------
4672 // selFlags uses same values DoSelectProperty's flags
4673 // Returns true if event was vetoed.
4674 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4676 unsigned int selFlags
,
4677 unsigned int column
)
4679 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4682 // Send property grid event of specific type and with specific property
4683 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4684 evt
.SetPropertyGrid(this);
4685 evt
.SetEventObject(m_eventObject
);
4687 evt
.SetColumn(column
);
4688 if ( eventType
== wxEVT_PG_CHANGING
)
4691 evt
.SetCanVeto(true);
4692 m_validationInfo
.m_pValue
= pValue
;
4693 evt
.SetupValidationInfo();
4698 evt
.SetPropertyValue(p
->GetValue());
4700 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4701 evt
.SetCanVeto(true);
4704 wxPropertyGridEvent
* prevProcessedEvent
= m_processedEvent
;
4705 m_processedEvent
= &evt
;
4706 m_eventObject
->HandleWindowEvent(evt
);
4707 m_processedEvent
= prevProcessedEvent
;
4709 return evt
.WasVetoed();
4712 // -----------------------------------------------------------------------
4714 // Return false if should be skipped
4715 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4719 // Need to set focus?
4720 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4725 wxPropertyGridPageState
* state
= m_pState
;
4727 int splitterHitOffset
;
4728 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4730 wxPGProperty
* p
= DoGetItemAtY(y
);
4734 int depth
= (int)p
->GetDepth() - 1;
4736 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4738 if ( x
>= marginEnds
)
4742 if ( p
->IsCategory() )
4744 // This is category.
4745 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4747 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4749 // Expand, collapse, activate etc. if click on text or left of splitter.
4752 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4757 if ( !AddToSelectionFromInputEvent( p
,
4762 // On double-click, expand/collapse.
4763 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4765 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4766 else DoExpand( p
, true );
4770 else if ( splitterHit
== -1 )
4773 unsigned int selFlag
= 0;
4774 if ( columnHit
== 1 )
4776 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4777 selFlag
= wxPG_SEL_FOCUS
;
4779 if ( !AddToSelectionFromInputEvent( p
,
4785 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4787 if ( p
->GetChildCount() && !p
->IsCategory() )
4788 // On double-click, expand/collapse.
4789 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4791 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4792 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4793 else DoExpand( p
, true );
4796 // Do not Skip() the event after selection has been made.
4797 // Otherwise default event handling behaviour kicks in
4798 // and may revert focus back to the main canvas.
4803 // click on splitter
4804 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4806 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4808 // Double-clicking the splitter causes auto-centering
4809 if ( m_pState
->GetColumnCount() <= 2 )
4811 ResetColumnSizes( true );
4813 SendEvent(wxEVT_PG_COL_DRAGGING
,
4816 wxPG_SEL_NOVALIDATE
,
4817 (unsigned int)m_draggedSplitter
);
4820 else if ( m_dragStatus
== 0 )
4823 // Begin draggin the splitter
4827 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4829 // Allow application to veto dragging
4830 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4832 (unsigned int)splitterHit
) )
4836 // Changes must be committed here or the
4837 // value won't be drawn correctly
4838 if ( !CommitChangesFromEditor() )
4841 m_wndEditor
->Show ( false );
4844 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4847 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4851 m_draggedSplitter
= splitterHit
;
4852 m_dragOffset
= splitterHitOffset
;
4854 #if wxPG_REFRESH_CONTROLS
4855 // Fixes button disappearance bug
4857 m_wndEditor2
->Show ( false );
4860 m_startingSplitterX
= x
- splitterHitOffset
;
4869 if ( p
->GetChildCount() )
4871 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4873 // Fine tune cell button x
4874 if ( !p
->IsCategory() )
4875 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4877 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4879 int y2
= y
% m_lineHeight
;
4880 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4882 // On click on expander button, expand/collapse
4883 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4884 DoCollapse( p
, true );
4886 DoExpand( p
, true );
4895 // -----------------------------------------------------------------------
4897 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4898 unsigned int WXUNUSED(y
),
4899 wxMouseEvent
& event
)
4903 // Select property here as well
4904 wxPGProperty
* p
= m_propHover
;
4905 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4907 // Send right click event.
4908 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4915 // -----------------------------------------------------------------------
4917 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4918 unsigned int WXUNUSED(y
),
4919 wxMouseEvent
& event
)
4923 // Select property here as well
4924 wxPGProperty
* p
= m_propHover
;
4926 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4928 // Send double-click event.
4929 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4936 // -----------------------------------------------------------------------
4938 // Return false if should be skipped
4939 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
,
4940 wxMouseEvent
&event
)
4942 // Safety check (needed because mouse capturing may
4943 // otherwise freeze the control)
4944 if ( m_dragStatus
> 0 && !event
.Dragging() )
4946 HandleMouseUp(x
, y
, event
);
4949 wxPropertyGridPageState
* state
= m_pState
;
4951 int splitterHitOffset
;
4952 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4953 int splitterX
= x
- splitterHitOffset
;
4955 m_colHover
= columnHit
;
4957 if ( m_dragStatus
> 0 )
4959 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4960 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4963 int newSplitterX
= x
- m_dragOffset
;
4965 // Splitter redraw required?
4966 if ( newSplitterX
!= splitterX
)
4969 DoSetSplitterPosition(newSplitterX
,
4971 wxPG_SPLITTER_REFRESH
|
4972 wxPG_SPLITTER_FROM_EVENT
);
4974 SendEvent(wxEVT_PG_COL_DRAGGING
,
4977 wxPG_SEL_NOVALIDATE
,
4978 (unsigned int)m_draggedSplitter
);
4989 int ih
= m_lineHeight
;
4992 #if wxPG_SUPPORT_TOOLTIPS
4993 wxPGProperty
* prevHover
= m_propHover
;
4994 unsigned char prevSide
= m_mouseSide
;
4996 int curPropHoverY
= y
- (y
% ih
);
4998 // On which item it hovers
5001 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
5004 // Mouse moves on another property
5006 m_propHover
= DoGetItemAtY(y
);
5007 m_propHoverY
= curPropHoverY
;
5010 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
5013 #if wxPG_SUPPORT_TOOLTIPS
5014 // Store which side we are on
5016 if ( columnHit
== 1 )
5018 else if ( columnHit
== 0 )
5022 // If tooltips are enabled, show label or value as a tip
5023 // in case it doesn't otherwise show in full length.
5025 if ( m_windowStyle
& wxPG_TOOLTIPS
)
5027 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
5029 if ( m_propHover
&& !m_propHover
->IsCategory() )
5032 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
5034 // Show help string as a tooltip
5035 wxString tipString
= m_propHover
->GetHelpString();
5037 SetToolTip(tipString
);
5041 // Show cropped value string as a tooltip
5045 if ( m_mouseSide
== 1 )
5047 tipString
= m_propHover
->m_label
;
5048 space
= splitterX
-m_marginWidth
-3;
5050 else if ( m_mouseSide
== 2 )
5052 tipString
= m_propHover
->GetDisplayedString();
5054 space
= m_width
- splitterX
;
5055 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
5056 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+
5057 wxCC_CUSTOM_IMAGE_MARGIN1
+
5058 wxCC_CUSTOM_IMAGE_MARGIN2
;
5064 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
5066 SetToolTip( tipString
);
5070 SetToolTip( m_emptyString
);
5077 SetToolTip( m_emptyString
);
5083 if ( splitterHit
== -1 ||
5085 HasFlag(wxPG_STATIC_SPLITTER
) )
5087 // hovering on something else
5088 if ( m_curcursor
!= wxCURSOR_ARROW
)
5089 CustomSetCursor( wxCURSOR_ARROW
);
5093 // Do not allow splitter cursor on caption items.
5094 // (also not if we were dragging and its started
5095 // outside the splitter region)
5097 if ( !m_propHover
->IsCategory() &&
5101 // hovering on splitter
5103 // NB: Condition disabled since MouseLeave event (from the
5104 // editor control) cannot be reliably detected.
5105 //if ( m_curcursor != wxCURSOR_SIZEWE )
5106 CustomSetCursor( wxCURSOR_SIZEWE
, true );
5112 // hovering on something else
5113 if ( m_curcursor
!= wxCURSOR_ARROW
)
5114 CustomSetCursor( wxCURSOR_ARROW
);
5119 // Multi select by dragging
5121 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
5122 event
.LeftIsDown() &&
5126 !state
->DoIsPropertySelected(m_propHover
) )
5128 // Additional requirement is that the hovered property
5129 // is adjacent to edges of selection.
5130 const wxArrayPGProperty
& selection
= GetSelectedProperties();
5132 // Since categories cannot be selected along with 'other'
5133 // properties, exclude them from iterator flags.
5134 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
5136 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
5138 // TODO: This could be optimized by keeping track of
5139 // which properties are at the edges of selection.
5140 wxPGProperty
* selProp
= selection
[i
];
5141 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
5144 DoAddToSelection(m_propHover
);
5153 // -----------------------------------------------------------------------
5155 // Also handles Leaving event
5156 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
5157 wxMouseEvent
&WXUNUSED(event
) )
5159 wxPropertyGridPageState
* state
= m_pState
;
5163 int splitterHitOffset
;
5164 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
5166 // No event type check - basically calling this method should
5167 // just stop dragging.
5168 // Left up after dragged?
5169 if ( m_dragStatus
>= 1 )
5172 // End Splitter Dragging
5174 // DO NOT ENABLE FOLLOWING LINE!
5175 // (it is only here as a reminder to not to do it)
5178 SendEvent(wxEVT_PG_COL_END_DRAG
,
5181 wxPG_SEL_NOVALIDATE
,
5182 (unsigned int)m_draggedSplitter
);
5184 // Disable splitter auto-centering (but only if moved any -
5185 // otherwise we end up disabling auto-center even after a
5186 // recentering double-click).
5187 int posDiff
= abs(m_startingSplitterX
-
5188 GetSplitterPosition(m_draggedSplitter
));
5191 state
->m_dontCenterSplitter
= true;
5193 // This is necessary to return cursor
5194 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5197 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5200 // Set back the default cursor, if necessary
5201 if ( splitterHit
== -1 ||
5204 CustomSetCursor( wxCURSOR_ARROW
);
5209 // Control background needs to be cleared
5210 wxPGProperty
* selected
= GetSelection();
5211 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
5212 DrawItem( selected
);
5216 m_wndEditor
->Show ( true );
5219 #if wxPG_REFRESH_CONTROLS
5220 // Fixes button disappearance bug
5222 m_wndEditor2
->Show ( true );
5225 // This clears the focus.
5226 m_editorFocused
= 0;
5232 // -----------------------------------------------------------------------
5234 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
5236 int splitterX
= GetSplitterPosition();
5239 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
5241 wxWindow
* wnd
= GetEditorControl();
5243 // Hide popup on clicks
5244 if ( event
.GetEventType() != wxEVT_MOTION
)
5245 if ( wxDynamicCast(wnd
, wxOwnerDrawnComboBox
) )
5247 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
5253 if ( wnd
== NULL
|| m_dragStatus
||
5255 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
5256 ux
>= (r
.x
+r
.width
) ||
5258 event
.m_y
>= (r
.y
+r
.height
)
5268 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5273 // -----------------------------------------------------------------------
5275 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
5278 if ( OnMouseCommon( event
, &x
, &y
) )
5280 if ( !HandleMouseClick(x
, y
, event
) )
5289 // -----------------------------------------------------------------------
5291 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5294 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5295 HandleMouseRightClick(x
,y
,event
);
5299 // -----------------------------------------------------------------------
5301 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5303 // Always run standard mouse-down handler as well
5304 OnMouseClick(event
);
5307 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5308 HandleMouseDoubleClick(x
,y
,event
);
5310 // Do not Skip() event here - OnMouseClick() call above
5311 // should have already taken care of it.
5314 // -----------------------------------------------------------------------
5316 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5319 if ( OnMouseCommon( event
, &x
, &y
) )
5321 HandleMouseMove(x
,y
,event
);
5326 // -----------------------------------------------------------------------
5328 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5331 if ( OnMouseCommon( event
, &x
, &y
) )
5333 if ( !HandleMouseUp(x
, y
, event
) )
5342 // -----------------------------------------------------------------------
5344 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5346 // This may get called from child control as well, so event's
5347 // mouse position cannot be relied on.
5349 if ( event
.Entering() )
5351 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5353 // TODO: Fix this (detect parent and only do
5354 // cursor trick if it is a manager).
5355 wxASSERT( GetParent() );
5356 GetParent()->SetCursor(wxNullCursor
);
5358 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5361 GetParent()->SetCursor(wxNullCursor
);
5363 else if ( event
.Leaving() )
5365 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5366 SetCursor( wxNullCursor
);
5368 // Get real cursor position
5369 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5371 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5374 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5376 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5380 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5388 // -----------------------------------------------------------------------
5390 // Common code used by various OnMouseXXXChild methods.
5391 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5393 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5394 wxASSERT( topCtrlWnd
);
5396 event
.GetPosition(&x
,&y
);
5398 int splitterX
= GetSplitterPosition();
5400 wxRect r
= topCtrlWnd
->GetRect();
5401 if ( !m_dragStatus
&&
5402 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5403 y
>= 0 && y
< r
.height \
5406 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5411 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5418 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5421 if ( OnMouseChildCommon(event
,&x
,&y
) )
5423 bool res
= HandleMouseClick(x
,y
,event
);
5424 if ( !res
) event
.Skip();
5428 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5431 wxASSERT( m_wndEditor
);
5432 // These coords may not be exact (about +-2),
5433 // but that should not matter (right click is about item, not position).
5434 wxPoint pt
= m_wndEditor
->GetPosition();
5435 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5437 // FIXME: Used to set m_propHover to selection here. Was it really
5440 bool res
= HandleMouseRightClick(x
,y
,event
);
5441 if ( !res
) event
.Skip();
5444 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5447 if ( OnMouseChildCommon(event
,&x
,&y
) )
5449 bool res
= HandleMouseMove(x
,y
,event
);
5450 if ( !res
) event
.Skip();
5454 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5457 if ( OnMouseChildCommon(event
,&x
,&y
) )
5459 bool res
= HandleMouseUp(x
,y
,event
);
5460 if ( !res
) event
.Skip();
5464 // -----------------------------------------------------------------------
5465 // wxPropertyGrid keyboard event handling
5466 // -----------------------------------------------------------------------
5468 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5470 // Translates wxKeyEvent to wxPG_ACTION_XXX
5472 int keycode
= event
.GetKeyCode();
5473 int modifiers
= event
.GetModifiers();
5475 wxASSERT( !(modifiers
&~(0xFFFF)) );
5477 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5479 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5481 if ( it
== m_actionTriggers
.end() )
5486 int second
= (it
->second
>>16) & 0xFFFF;
5490 return (it
->second
& 0xFFFF);
5493 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5495 wxASSERT( !(modifiers
&~(0xFFFF)) );
5497 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5499 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5501 if ( it
!= m_actionTriggers
.end() )
5503 // This key combination is already used
5505 // Can add secondary?
5506 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5507 wxT("You can only add up to two separate actions per key combination.") );
5509 action
= it
->second
| (action
<<16);
5512 m_actionTriggers
[hashMapKey
] = action
;
5515 void wxPropertyGrid::ClearActionTriggers( int action
)
5517 wxPGHashMapI2I::iterator it
;
5522 didSomething
= false;
5524 for ( it
= m_actionTriggers
.begin();
5525 it
!= m_actionTriggers
.end();
5528 if ( it
->second
== action
)
5530 m_actionTriggers
.erase(it
);
5531 didSomething
= true;
5536 while ( didSomething
);
5539 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5542 // Handles key event when editor control is not focused.
5545 wxCHECK2(!m_frozen
, return);
5547 // Travelsal between items, collapsing/expanding, etc.
5548 wxPGProperty
* selected
= GetSelection();
5549 int keycode
= event
.GetKeyCode();
5550 bool editorFocused
= IsEditorFocused();
5552 if ( keycode
== WXK_TAB
)
5554 #if defined(__WXGTK__)
5555 wxWindow
* mainControl
;
5557 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5558 mainControl
= GetParent();
5563 if ( !event
.ShiftDown() )
5565 if ( !editorFocused
&& m_wndEditor
)
5567 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5571 // Tab traversal workaround for platforms on which
5572 // wxWindow::Navigate() may navigate into first child
5573 // instead of next sibling. Does not work perfectly
5574 // in every scenario (for instance, when property grid
5575 // is either first or last control).
5576 #if defined(__WXGTK__)
5577 wxWindow
* sibling
= mainControl
->GetNextSibling();
5579 sibling
->SetFocusFromKbd();
5581 Navigate(wxNavigationKeyEvent::IsForward
);
5587 if ( editorFocused
)
5593 #if defined(__WXGTK__)
5594 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5596 sibling
->SetFocusFromKbd();
5598 Navigate(wxNavigationKeyEvent::IsBackward
);
5606 // Ignore Alt and Control when they are down alone
5607 if ( keycode
== WXK_ALT
||
5608 keycode
== WXK_CONTROL
)
5615 int action
= KeyEventToActions(event
, &secondAction
);
5617 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5620 // Esc cancels any changes
5621 if ( IsEditorsValueModified() )
5623 EditorsValueWasNotModified();
5625 // Update the control as well
5626 selected
->GetEditorClass()->
5627 SetControlStringValue( selected
,
5629 selected
->GetDisplayedString() );
5632 OnValidationFailureReset(selected
);
5638 // Except for TAB, ESC, and any keys specifically dedicated to
5639 // wxPropertyGrid itself, handle child control events in child control.
5641 wxPGFindInVector(m_dedicatedKeys
, keycode
) == wxNOT_FOUND
)
5643 // Only propagate event if it had modifiers
5644 if ( !event
.HasModifiers() )
5646 event
.StopPropagation();
5652 bool wasHandled
= false;
5657 if ( ButtonTriggerKeyTest(action
, event
) )
5660 wxPGProperty
* p
= selected
;
5662 if ( action
== wxPG_ACTION_EDIT
&& !editorFocused
)
5664 DoSelectProperty( p
, wxPG_SEL_FOCUS
);
5668 // Travel and expand/collapse
5671 if ( p
->GetChildCount() )
5673 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5675 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5678 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5680 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5687 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5691 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5697 if ( selectDir
>= -1 )
5699 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5703 int reopenLabelEditorCol
= -1;
5705 if ( editorFocused
)
5707 // If editor was focused, then make the next editor
5709 selFlags
|= wxPG_SEL_FOCUS
;
5713 // Also maintain the same label editor focus state
5714 if ( m_labelEditor
)
5715 reopenLabelEditorCol
= m_selColumn
;
5718 DoSelectProperty(p
, selFlags
);
5720 if ( reopenLabelEditorCol
>= 0 )
5721 DoBeginLabelEdit(reopenLabelEditorCol
);
5728 // If nothing was selected, select the first item now
5729 // (or navigate out of tab).
5730 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5732 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5733 if ( p
) DoSelectProperty(p
);
5742 // -----------------------------------------------------------------------
5744 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5746 // If there was editor open and focused, then this event should not
5747 // really be processed here.
5748 if ( IsEditorFocused() )
5750 // However, if event had modifiers, it is probably still best
5752 if ( event
.HasModifiers() )
5755 event
.StopPropagation();
5759 HandleKeyEvent(event
, false);
5762 // -----------------------------------------------------------------------
5764 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5769 action
= KeyEventToActions(event
, &secondAction
);
5772 // Does the keycode trigger button?
5773 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5776 wxCommandEvent
evt(wxEVT_BUTTON
, m_wndEditor2
->GetId());
5777 GetEventHandler()->AddPendingEvent(evt
);
5784 // -----------------------------------------------------------------------
5786 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5788 HandleKeyEvent(event
, true);
5791 // -----------------------------------------------------------------------
5792 // wxPropertyGrid miscellaneous event handling
5793 // -----------------------------------------------------------------------
5795 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5798 // Check if the focus is in this control or one of its children
5799 wxWindow
* newFocused
= wxWindow::FindFocus();
5801 if ( newFocused
!= m_curFocused
)
5802 HandleFocusChange( newFocused
);
5805 // Check if top-level parent has changed
5806 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5808 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5814 // Resolve pending property removals
5815 if ( m_deletedProperties
.size() > 0 )
5817 wxArrayPGProperty
& arr
= m_deletedProperties
;
5818 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5820 DeleteProperty(arr
[i
]);
5824 if ( m_removedProperties
.size() > 0 )
5826 wxArrayPGProperty
& arr
= m_removedProperties
;
5827 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5829 RemoveProperty(arr
[i
]);
5835 bool wxPropertyGrid::IsEditorFocused() const
5837 wxWindow
* focus
= wxWindow::FindFocus();
5839 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5840 focus
== GetEditorControl() )
5846 // Called by focus event handlers. newFocused is the window that becomes focused.
5847 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5850 // Never allow focus to be changed when handling editor event.
5851 // Especially because they may be displaing a dialog which
5852 // could cause all kinds of weird (native) focus changes.
5853 if ( HasInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
5856 unsigned int oldFlags
= m_iFlags
;
5857 bool wasEditorFocused
= false;
5858 wxWindow
* wndEditor
= m_wndEditor
;
5860 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5862 wxWindow
* parent
= newFocused
;
5864 // This must be one of nextFocus' parents.
5867 if ( parent
== wndEditor
)
5869 wasEditorFocused
= true;
5871 // Use m_eventObject, which is either wxPropertyGrid or
5872 // wxPropertyGridManager, as appropriate.
5873 else if ( parent
== m_eventObject
)
5875 m_iFlags
|= wxPG_FL_FOCUSED
;
5878 parent
= parent
->GetParent();
5881 // Notify editor control when it receives a focus
5882 if ( wasEditorFocused
&& m_curFocused
!= newFocused
)
5884 wxPGProperty
* p
= GetSelection();
5887 const wxPGEditor
* editor
= p
->GetEditorClass();
5888 ResetEditorAppearance();
5889 editor
->OnFocus(p
, GetEditorControl());
5893 m_curFocused
= newFocused
;
5895 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5896 (oldFlags
& wxPG_FL_FOCUSED
) )
5898 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5900 // Need to store changed value
5901 CommitChangesFromEditor();
5907 // Preliminary code for tab-order respecting
5908 // tab-traversal (but should be moved to
5911 wxWindow* prevFocus = event.GetWindow();
5912 wxWindow* useThis = this;
5913 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5914 useThis = GetParent();
5917 prevFocus->GetParent() == useThis->GetParent() )
5919 wxList& children = useThis->GetParent()->GetChildren();
5921 wxNode* node = children.Find(prevFocus);
5923 if ( node->GetNext() &&
5924 useThis == node->GetNext()->GetData() )
5925 DoSelectProperty(GetFirst());
5926 else if ( node->GetPrevious () &&
5927 useThis == node->GetPrevious()->GetData() )
5928 DoSelectProperty(GetLastProperty());
5935 wxPGProperty
* selected
= GetSelection();
5936 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5937 DrawItem( selected
);
5941 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5943 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5944 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5945 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5946 //else if ( event.GetWindow() )
5948 HandleFocusChange(event
.GetWindow());
5953 // -----------------------------------------------------------------------
5955 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5957 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5961 // -----------------------------------------------------------------------
5963 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5965 m_iFlags
|= wxPG_FL_SCROLLED
;
5970 // -----------------------------------------------------------------------
5972 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5974 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5976 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5980 // -----------------------------------------------------------------------
5981 // Property editor related functions
5982 // -----------------------------------------------------------------------
5984 // noDefCheck = true prevents infinite recursion.
5985 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5986 const wxString
& editorName
,
5989 wxASSERT( editorClass
);
5991 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5992 RegisterDefaultEditors();
5994 wxString name
= editorName
;
5996 name
= editorClass
->GetName();
5998 // Existing editor under this name?
5999 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
6001 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
6003 // If this name was already used, try class name.
6004 name
= editorClass
->GetClassInfo()->GetClassName();
6005 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
6008 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
6009 (wxPGEditor
*) vt_it
->second
,
6010 "Editor with given name was already registered" );
6012 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
6017 // Use this in RegisterDefaultEditors.
6018 #define wxPGRegisterDefaultEditorClass(EDITOR) \
6019 if ( wxPGEditor_##EDITOR == NULL ) \
6021 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
6022 new wxPG##EDITOR##Editor, true ); \
6025 // Registers all default editor classes
6026 void wxPropertyGrid::RegisterDefaultEditors()
6028 wxPGRegisterDefaultEditorClass( TextCtrl
);
6029 wxPGRegisterDefaultEditorClass( Choice
);
6030 wxPGRegisterDefaultEditorClass( ComboBox
);
6031 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
6032 #if wxPG_INCLUDE_CHECKBOX
6033 wxPGRegisterDefaultEditorClass( CheckBox
);
6035 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
6037 // Register SpinCtrl etc. editors before use
6038 RegisterAdditionalEditors();
6041 // -----------------------------------------------------------------------
6042 // wxPGStringTokenizer
6043 // Needed to handle C-style string lists (e.g. "str1" "str2")
6044 // -----------------------------------------------------------------------
6046 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
6047 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
6051 wxPGStringTokenizer::~wxPGStringTokenizer()
6055 bool wxPGStringTokenizer::HasMoreTokens()
6057 const wxString
& str
= *m_str
;
6059 wxString::const_iterator i
= m_curPos
;
6061 wxUniChar delim
= m_delimeter
;
6063 wxUniChar prev_a
= wxT('\0');
6065 bool inToken
= false;
6067 while ( i
!= str
.end() )
6076 m_readyToken
.clear();
6081 if ( prev_a
!= wxT('\\') )
6085 if ( a
!= wxT('\\') )
6105 m_curPos
= str
.end();
6113 wxString
wxPGStringTokenizer::GetNextToken()
6115 return m_readyToken
;
6118 // -----------------------------------------------------------------------
6120 // -----------------------------------------------------------------------
6122 wxPGChoiceEntry::wxPGChoiceEntry()
6123 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
6127 // -----------------------------------------------------------------------
6129 // -----------------------------------------------------------------------
6131 wxPGChoicesData::wxPGChoicesData()
6135 wxPGChoicesData::~wxPGChoicesData()
6140 void wxPGChoicesData::Clear()
6145 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
6147 wxASSERT( m_items
.size() == 0 );
6149 m_items
= data
->m_items
;
6152 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
6153 const wxPGChoiceEntry
& item
)
6155 wxVector
<wxPGChoiceEntry
>::iterator it
;
6159 index
= (int) m_items
.size();
6163 it
= m_items
.begin() + index
;
6166 m_items
.insert(it
, item
);
6168 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
6170 // Need to fix value?
6171 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
6172 ownEntry
.SetValue(index
);
6177 // -----------------------------------------------------------------------
6178 // wxPropertyGridEvent
6179 // -----------------------------------------------------------------------
6181 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
6184 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
6185 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
6186 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
6187 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
6188 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
6189 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
6190 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
6191 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
6192 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
6193 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
6194 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
6195 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
6196 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
6197 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
6199 // -----------------------------------------------------------------------
6201 void wxPropertyGridEvent::Init()
6203 m_validationInfo
= NULL
;
6206 m_wasVetoed
= false;
6210 // -----------------------------------------------------------------------
6212 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6213 : wxCommandEvent(commandType
,id
)
6219 // -----------------------------------------------------------------------
6221 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6222 : wxCommandEvent(event
)
6224 m_eventType
= event
.GetEventType();
6225 m_eventObject
= event
.m_eventObject
;
6227 OnPropertyGridSet();
6228 m_property
= event
.m_property
;
6229 m_validationInfo
= event
.m_validationInfo
;
6230 m_canVeto
= event
.m_canVeto
;
6231 m_wasVetoed
= event
.m_wasVetoed
;
6234 // -----------------------------------------------------------------------
6236 void wxPropertyGridEvent::OnPropertyGridSet()
6242 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6244 m_pg
->m_liveEvents
.push_back(this);
6247 // -----------------------------------------------------------------------
6249 wxPropertyGridEvent::~wxPropertyGridEvent()
6254 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6257 // Use iterate from the back since it is more likely that the event
6258 // being desroyed is at the end of the array.
6259 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
6261 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
6263 if ( liveEvents
[i
] == this )
6265 liveEvents
.erase(liveEvents
.begin() + i
);
6272 // -----------------------------------------------------------------------
6274 wxEvent
* wxPropertyGridEvent::Clone() const
6276 return new wxPropertyGridEvent( *this );
6279 // -----------------------------------------------------------------------
6280 // wxPropertyGridPopulator
6281 // -----------------------------------------------------------------------
6283 wxPropertyGridPopulator::wxPropertyGridPopulator()
6287 wxPGGlobalVars
->m_offline
++;
6290 // -----------------------------------------------------------------------
6292 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6295 m_propHierarchy
.clear();
6298 // -----------------------------------------------------------------------
6300 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6306 // -----------------------------------------------------------------------
6308 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6311 // Free unused sets of choices
6312 wxPGHashMapS2P::iterator it
;
6314 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6316 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6323 m_pg
->GetPanel()->Refresh();
6325 wxPGGlobalVars
->m_offline
--;
6328 // -----------------------------------------------------------------------
6330 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6331 const wxString
& propLabel
,
6332 const wxString
& propName
,
6333 const wxString
* propValue
,
6334 wxPGChoices
* pChoices
)
6336 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6337 wxPGProperty
* parent
= GetCurParent();
6339 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6341 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6345 if ( !classInfo
|| !classInfo
->IsKindOf(wxCLASSINFO(wxPGProperty
)) )
6347 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6351 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6353 property
->SetLabel(propLabel
);
6354 property
->DoSetName(propName
);
6356 if ( pChoices
&& pChoices
->IsOk() )
6357 property
->SetChoices(*pChoices
);
6359 m_state
->DoInsert(parent
, -1, property
);
6362 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
6363 wxPG_PROGRAMMATIC_VALUE
);
6368 // -----------------------------------------------------------------------
6370 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6372 m_propHierarchy
.push_back(property
);
6373 DoScanForChildren();
6374 m_propHierarchy
.pop_back();
6377 // -----------------------------------------------------------------------
6379 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6380 const wxString
& idString
)
6382 wxPGChoices choices
;
6385 if ( choicesString
[0] == wxT('@') )
6387 wxString ids
= choicesString
.substr(1);
6388 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6389 if ( it
== m_dictIdChoices
.end() )
6390 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6392 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6397 if ( !idString
.empty() )
6399 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6400 if ( it
!= m_dictIdChoices
.end() )
6402 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6409 // Parse choices string
6410 wxString::const_iterator it
= choicesString
.begin();
6414 bool labelValid
= false;
6416 for ( ; it
!= choicesString
.end(); ++it
)
6422 if ( c
== wxT('"') )
6427 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6428 choices
.Add(label
, l
);
6431 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6436 else if ( c
== wxT('=') )
6443 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6450 if ( c
== wxT('"') )
6463 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6464 choices
.Add(label
, l
);
6467 if ( !choices
.IsOk() )
6469 choices
.EnsureData();
6473 if ( !idString
.empty() )
6474 m_dictIdChoices
[idString
] = choices
.GetData();
6481 // -----------------------------------------------------------------------
6483 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6485 if ( s
.Last() == wxT('%') )
6487 wxString s2
= s
.substr(0,s
.length()-1);
6489 if ( s2
.ToLong(&val
, 10) )
6491 *pval
= (val
*max
)/100;
6497 return s
.ToLong(pval
, 10);
6500 // -----------------------------------------------------------------------
6502 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6503 const wxString
& type
,
6504 const wxString
& value
)
6506 int l
= m_propHierarchy
.size();
6510 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6511 wxString valuel
= value
.Lower();
6519 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6521 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6523 else if ( value
.ToLong(&v
, 0) )
6530 if ( type
== wxT("string") )
6534 else if ( type
== wxT("int") )
6537 value
.ToLong(&v
, 0);
6540 else if ( type
== wxT("bool") )
6542 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6549 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6554 p
->SetAttribute( name
, variant
);
6559 // -----------------------------------------------------------------------
6561 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6563 wxLogError(_("Error in resource: %s"),msg
.c_str());
6566 // -----------------------------------------------------------------------
6568 #endif // wxUSE_PROPGRID