1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
66 #include "wx/scopeguard.h"
68 // Two pics for the expand / collapse buttons.
69 // Files are not supplied with this project (since it is
70 // recommended to use either custom or native rendering).
71 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
72 // and copy xpm files from archive to wxPropertyGrid src directory
73 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
74 // and set wxPG_USE_RENDERER_NATIVE to 0).
75 #ifndef wxPG_ICON_WIDTH
76 #if defined(__WXMAC__)
77 #include "mac_collapse.xpm"
78 #include "mac_expand.xpm"
79 #elif defined(__WXGTK__)
80 #include "linux_collapse.xpm"
81 #include "linux_expand.xpm"
83 #include "default_collapse.xpm"
84 #include "default_expand.xpm"
89 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
90 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
91 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
92 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
93 #define wxPG_YSPACING_MIN 1
94 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
95 // but causes normal combobox to spill out under MSW
97 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
99 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
100 // Must be larger than largest control border
104 #define wxPG_DEFAULT_CURSOR wxNullCursor
107 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
109 //#define wxPG_HIDER_BUTTON_HEIGHT 25
111 #define wxPG_PIXELS_PER_UNIT m_lineHeight
113 #ifdef wxPG_ICON_WIDTH
114 #define m_iconHeight m_iconWidth
117 //#define wxPG_TOOLTIP_DELAY 1000
119 // This is the number of pixels the expander button inside
120 // property cells (i.e. not in the grey margin area are
122 #define IN_CELL_EXPANDER_BUTTON_X_ADJUST 2
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include "wx/module.h"
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { wxDELETE(wxPGGlobalVars
); }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 // When wxPG is loaded dynamically after the application is already running
158 // then the built-in module system won't pick this one up. Add it manually.
159 void wxPGInitResourceModule()
161 wxModule
* module = new wxPGGlobalVarsClassManager
;
163 wxModule::RegisterModule(module);
166 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
169 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
171 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
173 m_boolChoices
.Add(_("False"));
174 m_boolChoices
.Add(_("True"));
176 m_fontFamilyChoices
= NULL
;
178 m_defaultRenderer
= new wxPGDefaultRenderer();
180 m_autoGetTranslation
= false;
188 // Prepare some shared variants
189 m_vEmptyString
= wxString();
191 m_vMinusOne
= (long) -1;
195 // Prepare cached string constants
196 m_strstring
= wxS("string");
197 m_strlong
= wxS("long");
198 m_strbool
= wxS("bool");
199 m_strlist
= wxS("list");
200 m_strDefaultValue
= wxS("DefaultValue");
201 m_strMin
= wxS("Min");
202 m_strMax
= wxS("Max");
203 m_strUnits
= wxS("Units");
204 m_strHint
= wxS("Hint");
205 #if wxPG_COMPATIBILITY_1_4
206 m_strInlineHelp
= wxS("InlineHelp");
213 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
217 delete m_defaultRenderer
;
219 // This will always have one ref
220 delete m_fontFamilyChoices
;
223 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
224 delete ((wxValidator
*)m_arrValidators
[i
]);
228 // Destroy value type class instances.
229 wxPGHashMapS2P::iterator vt_it
;
231 // Destroy editor class instances.
232 // iterate over all the elements in the class
233 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
235 delete ((wxPGEditor
*)vt_it
->second
);
238 delete wxPGProperty::sm_wxPG_LABEL
;
241 void wxPropertyGridInitGlobalsIfNeeded()
245 // -----------------------------------------------------------------------
247 // -----------------------------------------------------------------------
249 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
251 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
252 EVT_IDLE(wxPropertyGrid::OnIdle
)
253 EVT_PAINT(wxPropertyGrid::OnPaint
)
254 EVT_SIZE(wxPropertyGrid::OnResize
)
255 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
256 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
257 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
258 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
259 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
260 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
261 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
262 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
263 EVT_MOTION(wxPropertyGrid::OnMouseMove
)
264 EVT_LEFT_DOWN(wxPropertyGrid::OnMouseClick
)
265 EVT_LEFT_UP(wxPropertyGrid::OnMouseUp
)
266 EVT_RIGHT_UP(wxPropertyGrid::OnMouseRightClick
)
267 EVT_LEFT_DCLICK(wxPropertyGrid::OnMouseDoubleClick
)
268 EVT_KEY_DOWN(wxPropertyGrid::OnKey
)
271 // -----------------------------------------------------------------------
273 wxPropertyGrid::wxPropertyGrid()
279 // -----------------------------------------------------------------------
281 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
286 const wxString
& name
)
290 Create(parent
,id
,pos
,size
,style
,name
);
293 // -----------------------------------------------------------------------
295 bool wxPropertyGrid::Create( wxWindow
*parent
,
300 const wxString
& name
)
303 if (!(style
&wxBORDER_MASK
))
305 style
|= wxBORDER_THEME
;
310 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
311 style
&= ~(wxTAB_TRAVERSAL
);
312 style
|= wxWANTS_CHARS
;
314 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
321 // -----------------------------------------------------------------------
324 // Initialize values to defaults
326 void wxPropertyGrid::Init1()
328 // Register editor classes, if necessary.
329 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
330 wxPropertyGrid::RegisterDefaultEditors();
332 m_validatingEditor
= 0;
335 m_wndEditor
= m_wndEditor2
= NULL
;
339 m_labelEditor
= NULL
;
340 m_labelEditorProperty
= NULL
;
341 m_eventObject
= this;
343 m_processedEvent
= NULL
;
344 m_sortFunction
= NULL
;
345 m_inDoPropertyChanged
= false;
346 m_inCommitChangesFromEditor
= false;
347 m_inDoSelectProperty
= false;
348 m_inOnValidationFailure
= false;
349 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
354 // Set up default unspecified value 'colour'
355 m_unspecifiedAppearance
.SetFgCol(*wxLIGHT_GREY
);
358 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
359 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
360 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
361 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
362 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
363 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
364 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
365 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
366 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
368 m_coloursCustomized
= 0;
371 #if wxPG_DOUBLE_BUFFER
372 m_doubleBuffer
= NULL
;
375 #ifndef wxPG_ICON_WIDTH
381 m_iconWidth
= wxPG_ICON_WIDTH
;
386 m_gutterWidth
= wxPG_GUTTER_MIN
;
387 m_subgroup_extramargin
= 10;
391 m_width
= m_height
= 0;
393 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
396 m_chgInfo_changedProperty
= NULL
;
399 // -----------------------------------------------------------------------
402 // Initialize after parent etc. set
404 void wxPropertyGrid::Init2()
406 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
409 // Smaller controls on Mac
410 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
413 // Now create state, if one didn't exist already
414 // (wxPropertyGridManager might have created it for us).
417 m_pState
= CreateState();
418 m_pState
->m_pPropGrid
= this;
419 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
422 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
423 m_pState
->m_dontCenterSplitter
= true;
425 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
427 m_pState
->InitNonCatMode();
429 m_pState
->m_properties
= m_pState
->m_abcArray
;
432 GetClientSize(&m_width
,&m_height
);
434 #ifndef wxPG_ICON_WIDTH
435 // create two bitmap nodes for drawing
436 m_expandbmp
= new wxBitmap(expand_xpm
);
437 m_collbmp
= new wxBitmap(collapse_xpm
);
439 // calculate average font height for bitmap centering
441 m_iconWidth
= m_expandbmp
->GetWidth();
442 m_iconHeight
= m_expandbmp
->GetHeight();
445 m_curcursor
= wxCURSOR_ARROW
;
446 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
448 // adjust bitmap icon y position so they are centered
449 m_vspacing
= wxPG_DEFAULT_VSPACING
;
451 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
453 // Allocate cell datas
454 m_propertyDefaultCell
.SetEmptyData();
455 m_categoryDefaultCell
.SetEmptyData();
459 // This helps with flicker
460 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
462 // Hook the top-level parent
467 // set virtual size to this window size
468 wxSize wndsize
= GetSize();
469 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
471 m_timeCreated
= ::wxGetLocalTimeMillis();
473 //m_canvas->Create(this, wxID_ANY, wxPoint(0, 0), GetClientSize(),
474 // wxWANTS_CHARS | wxCLIP_CHILDREN);
475 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
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 wxPG_DOUBLE_BUFFER
545 if ( m_doubleBuffer
)
546 delete m_doubleBuffer
;
549 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
552 delete m_cursorSizeWE
;
554 #ifndef wxPG_ICON_WIDTH
559 // Delete common value records
560 for ( i
=0; i
<m_commonValues
.size(); i
++ )
562 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
563 wxPGCommonValue
* value
= m_commonValues
[i
];
568 // -----------------------------------------------------------------------
570 bool wxPropertyGrid::Destroy()
572 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
575 return wxScrolledWindow::Destroy();
578 // -----------------------------------------------------------------------
580 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
582 return new wxPropertyGridPageState();
585 // -----------------------------------------------------------------------
586 // wxPropertyGrid overridden wxWindow methods
587 // -----------------------------------------------------------------------
589 void wxPropertyGrid::SetWindowStyleFlag( long style
)
591 long old_style
= m_windowStyle
;
593 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
595 wxASSERT( m_pState
);
597 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
600 EnableCategories( true );
602 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
604 // Disable categories
605 EnableCategories( false );
607 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
613 PrepareAfterItemsAdded();
615 m_pState
->m_itemsAdded
= 1;
617 #if wxPG_SUPPORT_TOOLTIPS
618 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
624 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
625 SetToolTip ( tooltip );
626 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
629 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
634 wxScrolledWindow::SetToolTip( NULL
);
639 wxScrolledWindow::SetWindowStyleFlag ( style
);
641 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
643 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
645 CalculateFontAndBitmapStuff( m_vspacing
);
651 // -----------------------------------------------------------------------
653 void wxPropertyGrid::Freeze()
657 wxScrolledWindow::Freeze();
662 // -----------------------------------------------------------------------
664 void wxPropertyGrid::Thaw()
670 wxScrolledWindow::Thaw();
671 RecalculateVirtualSize();
672 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
676 // Force property re-selection
677 // NB: We must copy the selection.
678 wxArrayPGProperty selection
= m_pState
->m_selection
;
679 DoSetSelection(selection
, wxPG_SEL_FORCE
| wxPG_SEL_NONVISIBLE
);
683 // -----------------------------------------------------------------------
685 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
687 wxCHECK( prop
, false );
689 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
690 return DoSelectProperty(prop
, selFlags
);
692 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
694 if ( !selection
.size() )
696 return DoSelectProperty(prop
, selFlags
);
700 // For categories, only one can be selected at a time
701 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
704 selection
.push_back(prop
);
706 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
708 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
717 // -----------------------------------------------------------------------
719 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
721 wxCHECK( prop
, false );
724 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
725 if ( selection
.size() <= 1 )
727 res
= DoSelectProperty(NULL
, selFlags
);
731 m_pState
->DoRemoveFromSelection(prop
);
739 // -----------------------------------------------------------------------
741 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
742 unsigned int colIndex
,
743 unsigned int selFlags
)
746 // NB: Enable following if label editor background colour is
747 // ever changed to any other than m_colSelBack.
749 // We use this workaround to prevent visible flicker when editing
750 // a cell. Atleast on wxMSW, there is a difficult to find
751 // (and perhaps prevent) redraw somewhere between making property
752 // selected and enabling label editing.
754 //wxColour prevColSelBack = m_colSelBack;
755 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
761 res
= DoSelectProperty(prop
, selFlags
);
766 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
768 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
770 res
= DoAddToSelection(prop
, selFlags
);
774 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
776 DoBeginLabelEdit(colIndex
, selFlags
);
780 //m_colSelBack = prevColSelBack;
784 // -----------------------------------------------------------------------
786 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
787 unsigned int colIndex
,
788 wxMouseEvent
* mouseEvent
,
791 const wxArrayPGProperty
& selection
= GetSelectedProperties();
792 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
795 // Set to 2 if also add all items in between
796 int addToExistingSelection
= 0;
798 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
802 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
803 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
805 // Allow right-click for context menu without
806 // disturbing the selection.
807 if ( GetSelectedProperties().size() <= 1 ||
809 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
814 if ( mouseEvent
->ControlDown() )
816 addToExistingSelection
= 1;
818 else if ( mouseEvent
->ShiftDown() )
820 if ( selection
.size() > 0 && !prop
->IsCategory() )
821 addToExistingSelection
= 2;
823 addToExistingSelection
= 1;
829 if ( addToExistingSelection
== 1 )
832 if ( !alreadySelected
)
834 res
= DoAddToSelection(prop
, selFlags
);
836 else if ( GetSelectedProperties().size() > 1 )
838 res
= DoRemoveFromSelection(prop
, selFlags
);
841 else if ( addToExistingSelection
== 2 )
843 // Add this, and all in between
845 // Find top selected property
846 wxPGProperty
* topSelProp
= selection
[0];
847 int topSelPropY
= topSelProp
->GetY();
848 for ( unsigned int i
=1; i
<selection
.size(); i
++ )
850 wxPGProperty
* p
= selection
[i
];
852 if ( y
< topSelPropY
)
859 wxPGProperty
* startFrom
;
860 wxPGProperty
* stopAt
;
862 if ( prop
->GetY() <= topSelPropY
)
864 // Property is above selection (or same)
870 // Property is below selection
871 startFrom
= topSelProp
;
875 // Iterate through properties in-between, and select them
876 wxPropertyGridIterator it
;
878 for ( it
= GetIterator(wxPG_ITERATE_VISIBLE
, startFrom
);
882 wxPGProperty
* p
= *it
;
884 if ( !p
->IsCategory() &&
885 !m_pState
->DoIsPropertySelected(p
) )
887 DoAddToSelection(p
, selFlags
);
896 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
902 // -----------------------------------------------------------------------
904 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
907 if ( newSelection
.size() > 0 )
909 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
914 DoClearSelection(false, selFlags
);
917 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
919 DoAddToSelection(newSelection
[i
], selFlags
);
925 // -----------------------------------------------------------------------
927 void wxPropertyGrid::MakeColumnEditable( unsigned int column
,
930 wxASSERT( column
!= 1 );
932 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
936 cols
.push_back(column
);
940 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
942 if ( cols
[i
] == (int)column
)
943 cols
.erase( cols
.begin() + i
);
948 // -----------------------------------------------------------------------
950 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
953 wxPGProperty
* selected
= GetSelection();
954 wxCHECK_RET(selected
, wxT("No property selected"));
955 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
957 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
959 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
966 const wxPGCell
* cell
= NULL
;
967 if ( selected
->HasCell(colIndex
) )
969 cell
= &selected
->GetCell(colIndex
);
970 if ( !cell
->HasText() && colIndex
== 0 )
971 text
= selected
->GetLabel();
977 text
= selected
->GetLabel();
979 cell
= &selected
->GetOrCreateCell(colIndex
);
982 if ( cell
&& cell
->HasText() )
983 text
= cell
->GetText();
985 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
987 m_selColumn
= colIndex
;
989 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
991 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
999 wxWindowID id
= tc
->GetId();
1000 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1001 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
1003 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1004 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
1009 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1010 m_labelEditorProperty
= selected
;
1013 // -----------------------------------------------------------------------
1016 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1018 DoEndLabelEdit(true);
1021 // -----------------------------------------------------------------------
1023 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1025 int keycode
= event
.GetKeyCode();
1027 if ( keycode
== WXK_ESCAPE
)
1029 DoEndLabelEdit(false);
1033 HandleKeyEvent(event
, true);
1037 // -----------------------------------------------------------------------
1039 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1041 if ( !m_labelEditor
)
1044 wxPGProperty
* prop
= m_labelEditorProperty
;
1049 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1051 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1052 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1053 prop
, NULL
, selFlags
,
1058 wxString text
= m_labelEditor
->GetValue();
1059 wxPGCell
* cell
= NULL
;
1060 if ( prop
->HasCell(m_selColumn
) )
1062 cell
= &prop
->GetCell(m_selColumn
);
1066 if ( m_selColumn
== 0 )
1067 prop
->SetLabel(text
);
1069 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1073 cell
->SetText(text
);
1077 int wasFocused
= m_iFlags
& wxPG_FL_FOCUSED
;
1079 DestroyEditorWnd(m_labelEditor
);
1081 m_labelEditor
= NULL
;
1082 m_labelEditorProperty
= NULL
;
1084 // Fix focus (needed at least on wxGTK)
1091 // -----------------------------------------------------------------------
1093 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1095 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1096 OnTLPChanging(::wxGetTopLevelParent(this));
1098 OnTLPChanging(NULL
);
1100 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1102 #if defined(__WXMSW__)
1105 // Don't use WS_EX_COMPOSITED just now.
1108 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1109 hWnd = (HWND)GetParent()->GetHWND();
1111 hWnd = (HWND)GetHWND();
1113 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1114 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1117 //#elif defined(__WXGTK20__)
1119 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1120 // truly was double-buffered.
1121 if ( !this->IsDoubleBuffered() )
1123 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1127 #if wxPG_DOUBLE_BUFFER
1128 wxDELETE(m_doubleBuffer
);
1133 wxScrolledWindow::SetExtraStyle( exStyle
);
1135 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1136 m_pState
->InitNonCatMode();
1138 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1139 m_windowStyle
|= wxPG_TOOLTIPS
;
1142 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1145 // -----------------------------------------------------------------------
1147 // returns the best acceptable minimal size
1148 wxSize
wxPropertyGrid::DoGetBestSize() const
1150 int lineHeight
= wxMax(15, m_lineHeight
);
1152 // don't make the grid too tall (limit height to 10 items) but don't
1153 // make it too small neither
1154 int numLines
= wxMin
1156 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1160 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1161 int width
= m_marginWidth
;
1162 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1164 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1167 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1173 // -----------------------------------------------------------------------
1175 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1177 if ( newTLP
== m_tlp
)
1180 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1183 // Parent changed so let's redetermine and re-hook the
1184 // correct top-level window.
1187 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1188 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1190 m_tlpClosed
= m_tlp
;
1191 m_tlpClosedTime
= currentTime
;
1196 // Only accept new tlp if same one was not just dismissed.
1197 if ( newTLP
!= m_tlpClosed
||
1198 m_tlpClosedTime
+250 < currentTime
)
1200 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1201 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1214 // -----------------------------------------------------------------------
1216 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1218 // ClearSelection forces value validation/commit.
1219 if ( event
.CanVeto() && !DoClearSelection() )
1225 // Ok, it can close, set tlp pointer to NULL. Some other event
1226 // handler can of course veto the close, but our OnIdle() should
1227 // then be able to regain the tlp pointer.
1228 OnTLPChanging(NULL
);
1233 // -----------------------------------------------------------------------
1235 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1237 OnTLPChanging((wxWindow
*)newParent
);
1239 bool res
= wxScrolledWindow::Reparent(newParent
);
1244 // -----------------------------------------------------------------------
1245 // wxPropertyGrid Font and Colour Methods
1246 // -----------------------------------------------------------------------
1248 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1252 m_captionFont
= wxScrolledWindow::GetFont();
1254 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1255 m_subgroup_extramargin
= x
+ (x
/2);
1258 #if wxPG_USE_RENDERER_NATIVE
1259 m_iconWidth
= wxPG_ICON_WIDTH
;
1260 #elif wxPG_ICON_WIDTH
1262 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1263 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1264 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1268 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1269 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1270 m_gutterWidth
= wxPG_GUTTER_MIN
;
1273 if ( vspacing
<= 1 ) vdiv
= 12;
1274 else if ( vspacing
>= 3 ) vdiv
= 3;
1276 m_spacingy
= m_fontHeight
/ vdiv
;
1277 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1278 m_spacingy
= wxPG_YSPACING_MIN
;
1281 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1282 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1284 m_captionFont
.SetWeight(wxBOLD
);
1285 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1287 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1290 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1291 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1294 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1296 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1297 RecalculateVirtualSize();
1299 InvalidateBestSize();
1302 // -----------------------------------------------------------------------
1304 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1310 // -----------------------------------------------------------------------
1312 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1313 int ga
= 1000, int ba
= 1000,
1314 bool forceDifferent
= false)
1321 // Recursion guard (allow 2 max)
1322 static int isinside
= 0;
1324 wxCHECK_MSG( isinside
< 3,
1326 wxT("wxPGAdjustColour should not be recursively called more than once") );
1331 int g
= src
.Green();
1334 if ( r2
>255 ) r2
= 255;
1335 else if ( r2
<0) r2
= 0;
1337 if ( g2
>255 ) g2
= 255;
1338 else if ( g2
<0) g2
= 0;
1340 if ( b2
>255 ) b2
= 255;
1341 else if ( b2
<0) b2
= 0;
1343 // Make sure they are somewhat different
1344 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1345 dst
= wxPGAdjustColour(src
,-(ra
*2));
1347 dst
= wxColour(r2
,g2
,b2
);
1349 // Recursion guard (allow 2 max)
1356 static int wxPGGetColAvg( const wxColour
& col
)
1358 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1362 void wxPropertyGrid::RegainColours()
1364 if ( !(m_coloursCustomized
& 0x0002) )
1366 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1368 // Make sure colour is dark enough
1370 int colDec
= wxPGGetColAvg(col
) - 230;
1372 int colDec
= wxPGGetColAvg(col
) - 200;
1375 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1378 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1381 if ( !(m_coloursCustomized
& 0x0001) )
1382 m_colMargin
= m_colCapBack
;
1384 if ( !(m_coloursCustomized
& 0x0004) )
1391 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1392 m_colCapFore
= capForeCol
;
1393 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1396 if ( !(m_coloursCustomized
& 0x0008) )
1398 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1399 m_colPropBack
= bgCol
;
1400 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1401 if ( !m_unspecifiedAppearance
.GetBgCol().IsOk() )
1402 m_unspecifiedAppearance
.SetBgCol(bgCol
);
1405 if ( !(m_coloursCustomized
& 0x0010) )
1407 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1408 m_colPropFore
= fgCol
;
1409 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1410 if ( !m_unspecifiedAppearance
.GetFgCol().IsOk() )
1411 m_unspecifiedAppearance
.SetFgCol(fgCol
);
1414 if ( !(m_coloursCustomized
& 0x0020) )
1415 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1417 if ( !(m_coloursCustomized
& 0x0040) )
1418 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1420 if ( !(m_coloursCustomized
& 0x0080) )
1421 m_colLine
= m_colCapBack
;
1423 if ( !(m_coloursCustomized
& 0x0100) )
1424 m_colDisPropFore
= m_colCapFore
;
1426 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1429 // -----------------------------------------------------------------------
1431 void wxPropertyGrid::ResetColours()
1433 m_coloursCustomized
= 0;
1440 // -----------------------------------------------------------------------
1442 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1444 // Must disable active editor.
1447 bool res
= wxScrolledWindow::SetFont( font
);
1448 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1450 CalculateFontAndBitmapStuff( m_vspacing
);
1457 // -----------------------------------------------------------------------
1459 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1462 m_coloursCustomized
|= 0x80;
1466 // -----------------------------------------------------------------------
1468 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1471 m_coloursCustomized
|= 0x01;
1475 // -----------------------------------------------------------------------
1477 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1479 m_colPropBack
= col
;
1480 m_coloursCustomized
|= 0x08;
1482 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1483 m_unspecifiedAppearance
.SetBgCol(col
);
1488 // -----------------------------------------------------------------------
1490 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1492 m_colPropFore
= col
;
1493 m_coloursCustomized
|= 0x10;
1495 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1496 m_unspecifiedAppearance
.SetFgCol(col
);
1501 // -----------------------------------------------------------------------
1503 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1505 m_colEmptySpace
= col
;
1510 // -----------------------------------------------------------------------
1512 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1514 m_colDisPropFore
= col
;
1515 m_coloursCustomized
|= 0x100;
1519 // -----------------------------------------------------------------------
1521 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1524 m_coloursCustomized
|= 0x20;
1528 // -----------------------------------------------------------------------
1530 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1533 m_coloursCustomized
|= 0x40;
1537 // -----------------------------------------------------------------------
1539 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1542 m_coloursCustomized
|= 0x02;
1544 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1549 // -----------------------------------------------------------------------
1551 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1554 m_coloursCustomized
|= 0x04;
1556 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1561 // -----------------------------------------------------------------------
1562 // wxPropertyGrid property adding and removal
1563 // -----------------------------------------------------------------------
1565 void wxPropertyGrid::PrepareAfterItemsAdded()
1567 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1569 m_pState
->m_itemsAdded
= 0;
1571 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1572 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1574 RecalculateVirtualSize();
1576 // Fix editor position
1577 CorrectEditorWidgetPosY();
1580 // -----------------------------------------------------------------------
1581 // wxPropertyGrid property operations
1582 // -----------------------------------------------------------------------
1584 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1586 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1590 bool changed
= false;
1592 // Is it inside collapsed section?
1593 if ( !p
->IsVisible() )
1596 wxPGProperty
* parent
= p
->GetParent();
1597 wxPGProperty
* grandparent
= parent
->GetParent();
1599 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1600 Expand( grandparent
);
1608 GetViewStart(&vx
,&vy
);
1609 vy
*=wxPG_PIXELS_PER_UNIT
;
1615 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1616 m_iFlags
|= wxPG_FL_SCROLLED
;
1619 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1621 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1622 m_iFlags
|= wxPG_FL_SCROLLED
;
1632 // -----------------------------------------------------------------------
1633 // wxPropertyGrid helper methods called by properties
1634 // -----------------------------------------------------------------------
1636 // Control font changer helper.
1637 void wxPropertyGrid::SetCurControlBoldFont()
1639 wxWindow
* editor
= GetEditorControl();
1640 editor
->SetFont( m_captionFont
);
1643 // -----------------------------------------------------------------------
1645 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1648 #if wxPG_SMALL_SCREEN
1649 // On small-screen devices, always show dialogs with default position and size.
1650 return wxDefaultPosition
;
1652 int splitterX
= GetSplitterPosition();
1656 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1658 ImprovedClientToScreen( &x
, &y
);
1660 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1661 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1668 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1678 new_y
= y
+ m_lineHeight
;
1680 return wxPoint(new_x
,new_y
);
1684 // -----------------------------------------------------------------------
1686 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1688 if ( src_str
.length() == 0 )
1694 bool prev_is_slash
= false;
1696 wxString::const_iterator i
= src_str
.begin();
1700 for ( ; i
!= src_str
.end(); ++i
)
1704 if ( a
!= wxS('\\') )
1706 if ( !prev_is_slash
)
1712 if ( a
== wxS('n') )
1715 dst_str
<< wxS('\n');
1717 dst_str
<< wxS('\n');
1720 else if ( a
== wxS('t') )
1721 dst_str
<< wxS('\t');
1725 prev_is_slash
= false;
1729 if ( prev_is_slash
)
1731 dst_str
<< wxS('\\');
1732 prev_is_slash
= false;
1736 prev_is_slash
= true;
1743 // -----------------------------------------------------------------------
1745 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1747 if ( src_str
.length() == 0 )
1753 wxString::const_iterator i
= src_str
.begin();
1754 wxUniChar prev_a
= wxS('\0');
1758 for ( ; i
!= src_str
.end(); ++i
)
1762 if ( a
>= wxS(' ') )
1764 // This surely is not something that requires an escape sequence.
1769 // This might need...
1770 if ( a
== wxS('\r') )
1772 // DOS style line end.
1773 // Already taken care below
1775 else if ( a
== wxS('\n') )
1776 // UNIX style line end.
1777 dst_str
<< wxS("\\n");
1778 else if ( a
== wxS('\t') )
1780 dst_str
<< wxS('\t');
1783 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1793 // -----------------------------------------------------------------------
1795 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1802 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1805 // -----------------------------------------------------------------------
1806 // wxPropertyGrid graphics related methods
1807 // -----------------------------------------------------------------------
1809 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1814 // Don't paint after destruction has begun
1815 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1818 // Find out where the window is scrolled to
1819 int vx
,vy
; // Top left corner of client
1820 GetViewStart(&vx
,&vy
);
1821 vy
*= wxPG_PIXELS_PER_UNIT
;
1823 // Update everything inside the box
1824 wxRect r
= GetUpdateRegion().GetBox();
1828 // FIXME: This is just a workaround for a bug that causes splitters not
1829 // to paint when other windows are being dragged over the grid.
1831 r
.width
= GetClientSize().x
;
1833 // Repaint this rectangle
1834 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1836 // We assume that the size set when grid is shown
1837 // is what is desired.
1838 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1841 // -----------------------------------------------------------------------
1843 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1844 wxPGProperty
* property
) const
1846 // Prepare rectangle to be used
1848 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1849 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1851 #if (wxPG_USE_RENDERER_NATIVE)
1853 #elif wxPG_ICON_WIDTH
1854 // Drawing expand/collapse button manually
1855 dc
.SetPen(m_colPropFore
);
1856 if ( property
->IsCategory() )
1857 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1859 dc
.SetBrush(m_colPropBack
);
1861 dc
.DrawRectangle( r
);
1862 int _y
= r
.y
+(m_iconWidth
/2);
1863 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1868 if ( property
->IsExpanded() )
1870 // wxRenderer functions are non-mutating in nature, so it
1871 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1872 // Hopefully this does not cause problems.
1873 #if (wxPG_USE_RENDERER_NATIVE)
1874 wxRendererNative::Get().DrawTreeItemButton(
1880 #elif wxPG_ICON_WIDTH
1889 #if (wxPG_USE_RENDERER_NATIVE)
1890 wxRendererNative::Get().DrawTreeItemButton(
1896 #elif wxPG_ICON_WIDTH
1897 int _x
= r
.x
+(m_iconWidth
/2);
1898 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1904 #if (wxPG_USE_RENDERER_NATIVE)
1906 #elif wxPG_ICON_WIDTH
1909 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1913 // -----------------------------------------------------------------------
1916 // This is the one called by OnPaint event handler and others.
1917 // topy and bottomy are already unscrolled (ie. physical)
1919 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1920 unsigned int topItemY
,
1921 unsigned int bottomItemY
,
1922 const wxRect
* drawRect
)
1926 bottomItemY
< topItemY
||
1930 m_pState
->EnsureVirtualHeight();
1932 wxRect tempDrawRect
;
1935 tempDrawRect
= wxRect(0, topItemY
,
1938 drawRect
= &tempDrawRect
;
1941 // items added check
1942 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1944 int paintFinishY
= 0;
1946 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1949 bool isBuffered
= false;
1951 #if wxPG_DOUBLE_BUFFER
1952 wxMemoryDC
* bufferDC
= NULL
;
1954 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1956 if ( !m_doubleBuffer
)
1958 paintFinishY
= drawRect
->y
;
1963 bufferDC
= new wxMemoryDC();
1965 // If nothing was changed, then just copy from double-buffer
1966 bufferDC
->SelectObject( *m_doubleBuffer
);
1976 dc
.SetClippingRegion( *drawRect
);
1977 paintFinishY
= DoDrawItems( *dcPtr
, drawRect
, isBuffered
);
1978 int drawBottomY
= drawRect
->y
+ drawRect
->height
;
1980 // Clear area beyond last painted property
1981 if ( paintFinishY
< drawBottomY
)
1983 dcPtr
->SetPen(m_colEmptySpace
);
1984 dcPtr
->SetBrush(m_colEmptySpace
);
1985 dcPtr
->DrawRectangle(0, paintFinishY
,
1990 dc
.DestroyClippingRegion();
1993 #if wxPG_DOUBLE_BUFFER
1996 dc
.Blit( drawRect
->x
, drawRect
->y
, drawRect
->width
,
1998 bufferDC
, 0, 0, wxCOPY
);
2005 // Just clear the area
2006 dc
.SetPen(m_colEmptySpace
);
2007 dc
.SetBrush(m_colEmptySpace
);
2008 dc
.DrawRectangle(*drawRect
);
2012 // -----------------------------------------------------------------------
2014 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
2015 const wxRect
* drawRect
,
2016 bool isBuffered
) const
2018 const wxPGProperty
* firstItem
;
2019 const wxPGProperty
* lastItem
;
2021 firstItem
= DoGetItemAtY(drawRect
->y
);
2022 lastItem
= DoGetItemAtY(drawRect
->y
+drawRect
->height
-1);
2025 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
2027 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
2030 wxCHECK_MSG( !m_pState
->m_itemsAdded
, drawRect
->y
,
2032 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2034 int lh
= m_lineHeight
;
2037 int lastItemBottomY
;
2039 firstItemTopY
= drawRect
->y
;
2040 lastItemBottomY
= drawRect
->y
+ drawRect
->height
;
2042 // Align y coordinates to item boundaries
2043 firstItemTopY
-= firstItemTopY
% lh
;
2044 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2045 lastItemBottomY
-= 1;
2047 // Entire range outside scrolled, visible area?
2048 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
2049 lastItemBottomY
<= 0 )
2052 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
2054 "invalid y values" );
2057 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
2058 "height=%i (ch=%i), drawRect = 0x%lX )",
2059 firstItem->GetLabel().c_str(),
2060 lastItem->GetLabel().c_str(),
2061 (int)(lastItemBottomY - firstItemTopY),
2063 (unsigned long)drawRect );
2068 long windowStyle
= m_windowStyle
;
2073 // With wxPG_DOUBLE_BUFFER, do double buffering
2074 // - buffer's y = 0, so align drawRect and coordinates to that
2076 #if wxPG_DOUBLE_BUFFER
2083 xRelMod
= drawRect
->x
;
2084 yRelMod
= drawRect
->y
;
2087 // drawRect conversion
2092 firstItemTopY
-= yRelMod
;
2093 lastItemBottomY
-= yRelMod
;
2096 wxUnusedVar(isBuffered
);
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 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2140 bool wasSelectedPainted
= false;
2143 // TODO: Only render columns that are within clipping region.
2145 dc
.SetFont(normalFont
);
2147 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2148 int endScanBottomY
= lastItemBottomY
+ lh
;
2149 int y
= firstItemTopY
;
2152 // Pregenerate list of visible properties.
2153 wxArrayPGProperty visPropArray
;
2154 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2156 for ( ; !it
.AtEnd(); it
.Next() )
2158 const wxPGProperty
* p
= *it
;
2160 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2162 visPropArray
.push_back((wxPGProperty
*)p
);
2164 if ( y
> endScanBottomY
)
2171 visPropArray
.push_back(NULL
);
2173 wxPGProperty
* nextP
= visPropArray
[0];
2175 int gridWidth
= state
->m_width
;
2178 for ( unsigned int arrInd
=1;
2179 nextP
&& y
<= lastItemBottomY
;
2182 wxPGProperty
* p
= nextP
;
2183 nextP
= visPropArray
[arrInd
];
2185 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2186 int textMarginHere
= x
;
2187 int renderFlags
= 0;
2189 int greyDepth
= m_marginWidth
;
2190 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2191 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2193 int greyDepthX
= greyDepth
- xRelMod
;
2195 // Use basic depth if in non-categoric mode and parent is base array.
2196 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2198 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2201 // Paint margin area
2202 dc
.SetBrush(marginBrush
);
2203 dc
.SetPen(marginPen
);
2204 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2206 dc
.SetPen( linepen
);
2212 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2213 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2214 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2216 // Is this or its parent themed?
2217 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2218 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2219 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2221 bool suppressMarginEdge
= false;
2223 if (!suppressMarginEdge
)
2224 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2227 // Blank out the margin edge
2228 dc
.SetPen(wxPen(GetBackgroundColour()));
2229 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2230 dc
.SetPen( linepen
);
2237 for ( si
=0; si
<colWidths
.size(); si
++ )
2239 sx
+= colWidths
[si
];
2240 dc
.DrawLine( sx
, y
, sx
, y2
);
2243 // Horizontal Line, below
2244 // (not if both this and next is category caption)
2245 if ( p
->IsCategory() &&
2246 nextP
&& nextP
->IsCategory() )
2247 dc
.SetPen(m_colCapBack
);
2249 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2252 // Need to override row colours?
2256 bool isSelected
= state
->DoIsPropertySelected(p
);
2260 // Disabled may get different colour.
2261 if ( !p
->IsEnabled() )
2263 renderFlags
|= wxPGCellRenderer::Disabled
|
2264 wxPGCellRenderer::DontUseCellFgCol
;
2265 rowFgCol
= m_colDisPropFore
;
2270 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2271 if ( p
== firstSelected
)
2272 wasSelectedPainted
= true;
2275 renderFlags
|= wxPGCellRenderer::Selected
;
2277 if ( !p
->IsCategory() )
2279 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2280 wxPGCellRenderer::DontUseCellBgCol
;
2282 if ( reallyFocused
&& p
== firstSelected
)
2284 rowFgCol
= m_colSelFore
;
2285 rowBgCol
= selBackCol
;
2287 else if ( isPgEnabled
)
2289 rowFgCol
= m_colPropFore
;
2290 if ( p
== firstSelected
)
2291 rowBgCol
= m_colMargin
;
2293 rowBgCol
= selBackCol
;
2297 rowFgCol
= m_colDisPropFore
;
2298 rowBgCol
= selBackCol
;
2305 if ( rowBgCol
.IsOk() )
2306 rowBgBrush
= wxBrush(rowBgCol
);
2308 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2309 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2312 // Fill additional margin area with background colour of first cell
2313 if ( greyDepthX
< textMarginHere
)
2315 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2317 wxPGCell
& cell
= p
->GetCell(0);
2318 rowBgCol
= cell
.GetBgCol();
2319 rowBgBrush
= wxBrush(rowBgCol
);
2321 dc
.SetBrush(rowBgBrush
);
2322 dc
.SetPen(rowBgCol
);
2323 dc
.DrawRectangle(greyDepthX
+1, y
,
2324 textMarginHere
-greyDepthX
, lh
-1);
2327 bool fontChanged
= false;
2329 // Expander button rectangle
2330 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2335 // Default cell rect fill the entire row
2336 wxRect
cellRect(greyDepthX
, y
,
2337 gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2339 bool isCategory
= p
->IsCategory();
2343 dc
.SetFont(m_captionFont
);
2346 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2348 dc
.SetBrush(rowBgBrush
);
2349 dc
.SetPen(rowBgCol
);
2352 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2354 dc
.SetTextForeground(rowFgCol
);
2359 // Fine tune button rectangle to actually fit the cell
2360 if ( butRect
.x
> 0 )
2361 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2363 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&&
2364 (windowStyle
& wxPG_BOLD_MODIFIED
) )
2366 dc
.SetFont(m_captionFont
);
2370 // Magic fine-tuning for non-category rows
2374 int firstCellWidth
= colWidths
[0] - (greyDepthX
- m_marginWidth
);
2375 int firstCellX
= cellRect
.x
;
2377 // Calculate cellRect.x for the last cell
2378 unsigned int ci
= 0;
2380 for ( ci
=0; ci
<colWidths
.size(); ci
++ )
2381 cellX
+= colWidths
[ci
];
2384 // Draw cells from back to front so that we can easily tell if the
2385 // cell on the right was empty from text
2386 bool prevFilled
= true;
2387 ci
= colWidths
.size();
2396 textXAdd
= textMarginHere
- greyDepthX
;
2397 cellRect
.width
= firstCellWidth
;
2398 cellRect
.x
= firstCellX
;
2402 int colWidth
= colWidths
[ci
];
2403 cellRect
.width
= colWidth
;
2404 cellRect
.x
-= colWidth
;
2407 // Merge with column to the right?
2408 if ( !prevFilled
&& isCategory
)
2410 cellRect
.width
+= colWidths
[ci
+1];
2414 cellRect
.width
-= 1;
2416 wxWindow
* cellEditor
= NULL
;
2417 int cellRenderFlags
= renderFlags
;
2419 // Tree Item Button (must be drawn before clipping is set up)
2420 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2421 DrawExpanderButton( dc
, butRect
, p
);
2424 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2426 if ( p
== firstSelected
)
2428 if ( ci
== 1 && m_wndEditor
)
2429 cellEditor
= m_wndEditor
;
2430 else if ( ci
== m_selColumn
&& m_labelEditor
)
2431 cellEditor
= m_labelEditor
;
2436 wxColour editorBgCol
=
2437 cellEditor
->GetBackgroundColour();
2438 dc
.SetBrush(editorBgCol
);
2439 dc
.SetPen(editorBgCol
);
2440 dc
.SetTextForeground(m_colPropFore
);
2441 dc
.DrawRectangle(cellRect
);
2443 if ( m_dragStatus
!= 0 ||
2444 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2449 dc
.SetBrush(m_colPropBack
);
2450 dc
.SetPen(m_colPropBack
);
2451 if ( p
->IsEnabled() )
2452 dc
.SetTextForeground(m_colPropFore
);
2454 dc
.SetTextForeground(m_colDisPropFore
);
2459 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2461 dc
.SetBrush(rowBgBrush
);
2462 dc
.SetPen(rowBgCol
);
2465 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2467 dc
.SetTextForeground(rowFgCol
);
2471 dc
.SetClippingRegion(cellRect
);
2473 cellRect
.x
+= textXAdd
;
2474 cellRect
.width
-= textXAdd
;
2479 wxPGCellRenderer
* renderer
;
2480 int cmnVal
= p
->GetCommonValue();
2481 if ( cmnVal
== -1 || ci
!= 1 )
2483 renderer
= p
->GetCellRenderer(ci
);
2484 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2490 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2491 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2501 dc
.DestroyClippingRegion(); // Is this really necessary?
2506 dc
.SetFont(normalFont
);
2511 // Refresh editor controls (seems not needed on msw)
2512 // NOTE: This code is mandatory for GTK!
2513 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2514 if ( wasSelectedPainted
)
2517 m_wndEditor
->Refresh();
2519 m_wndEditor2
->Refresh();
2526 // -----------------------------------------------------------------------
2528 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2532 if ( m_width
< 10 || m_height
< 10 ||
2533 !m_pState
->m_properties
->GetChildCount() ||
2535 return wxRect(0,0,0,0);
2540 // Return rect which encloses the given property range
2541 // (in logical grid coordinates)
2544 int visTop
= p1
->GetY();
2547 visBottom
= p2
->GetY() + m_lineHeight
;
2549 visBottom
= m_height
+ visTop
;
2551 // If seleced property is inside the range, we'll extend the range to include
2553 wxPGProperty
* selected
= GetSelection();
2556 int selectedY
= selected
->GetY();
2557 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2559 wxWindow
* editor
= GetEditorControl();
2562 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2563 if ( visBottom2
> visBottom
)
2564 visBottom
= visBottom2
;
2569 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2572 // -----------------------------------------------------------------------
2574 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2579 if ( m_pState
->m_itemsAdded
)
2580 PrepareAfterItemsAdded();
2582 wxRect r
= GetPropertyRect(p1
, p2
);
2585 // Convert rectangle from logical grid coordinates to physical ones
2587 GetViewStart(&vx
, &vy
);
2588 vx
*= wxPG_PIXELS_PER_UNIT
;
2589 vy
*= wxPG_PIXELS_PER_UNIT
;
2596 // -----------------------------------------------------------------------
2598 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2600 if ( m_pState
->DoIsPropertySelected(p
) )
2602 // NB: We must copy the selection.
2603 wxArrayPGProperty selection
= m_pState
->m_selection
;
2604 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2607 DrawItemAndChildren(p
);
2610 // -----------------------------------------------------------------------
2612 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2617 // Draw item, children, and parent too, if it is not category
2618 wxPGProperty
* parent
= p
->GetParent();
2621 !parent
->IsCategory() &&
2622 parent
->GetParent() )
2625 parent
= parent
->GetParent();
2628 DrawItemAndChildren(p
);
2631 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2633 wxCHECK_RET( p
, wxT("invalid property id") );
2635 // Do not draw if in non-visible page
2636 if ( p
->GetParentState() != m_pState
)
2639 // do not draw a single item if multiple pending
2640 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2643 // Update child control.
2644 wxPGProperty
* selected
= GetSelection();
2645 if ( selected
&& selected
->GetParent() == p
)
2648 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2650 DrawItems(p
, lastDrawn
);
2653 // -----------------------------------------------------------------------
2655 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2656 const wxRect
*rect
)
2658 PrepareAfterItemsAdded();
2660 wxWindow::Refresh(false, rect
);
2662 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2663 // I think this really helps only GTK+1.2
2664 if ( m_wndEditor
) m_wndEditor
->Refresh();
2665 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2669 // -----------------------------------------------------------------------
2670 // wxPropertyGrid global operations
2671 // -----------------------------------------------------------------------
2673 void wxPropertyGrid::Clear()
2675 m_pState
->DoClear();
2681 RecalculateVirtualSize();
2683 // Need to clear some area at the end
2685 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2688 // -----------------------------------------------------------------------
2690 bool wxPropertyGrid::EnableCategories( bool enable
)
2697 // Enable categories
2700 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2705 // Disable categories
2707 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2710 if ( !m_pState
->EnableCategories(enable
) )
2715 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2717 m_pState
->m_itemsAdded
= 1; // force
2718 PrepareAfterItemsAdded();
2722 m_pState
->m_itemsAdded
= 1;
2724 // No need for RecalculateVirtualSize() here - it is already called in
2725 // wxPropertyGridPageState method above.
2732 // -----------------------------------------------------------------------
2734 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2736 wxASSERT( pNewState
);
2737 wxASSERT( pNewState
->GetGrid() );
2739 if ( pNewState
== m_pState
)
2742 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2744 // Call ClearSelection() instead of DoClearSelection()
2745 // so that selection clear events are not sent.
2748 m_pState
->m_selection
= oldSelection
;
2750 bool orig_mode
= m_pState
->IsInNonCatMode();
2751 bool new_state_mode
= pNewState
->IsInNonCatMode();
2753 m_pState
= pNewState
;
2756 int pgWidth
= GetClientSize().x
;
2757 if ( HasVirtualWidth() )
2759 int minWidth
= pgWidth
;
2760 if ( pNewState
->m_width
< minWidth
)
2762 pNewState
->m_width
= minWidth
;
2763 pNewState
->CheckColumnWidths();
2769 // Just in case, fully re-center splitter
2770 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2771 // pNewState->m_fSplitterX = -1.0;
2773 pNewState
->OnClientWidthChange(pgWidth
,
2774 pgWidth
- pNewState
->m_width
);
2779 // If necessary, convert state to correct mode.
2780 if ( orig_mode
!= new_state_mode
)
2782 // This should refresh as well.
2783 EnableCategories( orig_mode
?false:true );
2785 else if ( !m_frozen
)
2787 // Refresh, if not frozen.
2788 m_pState
->PrepareAfterItemsAdded();
2790 // Reselect (Use SetSelection() instead of Do-variant so that
2791 // events won't be sent).
2792 SetSelection(m_pState
->m_selection
);
2794 RecalculateVirtualSize(0);
2798 m_pState
->m_itemsAdded
= 1;
2801 // -----------------------------------------------------------------------
2803 // Call to SetSplitterPosition will always disable splitter auto-centering
2804 // if parent window is shown.
2805 void wxPropertyGrid::DoSetSplitterPosition( int newxpos
,
2809 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2812 wxPropertyGridPageState
* state
= m_pState
;
2814 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2815 state
->m_dontCenterSplitter
= true;
2817 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2819 if ( flags
& wxPG_SPLITTER_REFRESH
)
2821 if ( GetSelection() )
2822 CorrectEditorWidgetSizeX();
2830 // -----------------------------------------------------------------------
2832 void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing
)
2834 wxPropertyGridPageState
* state
= m_pState
;
2836 state
->ResetColumnSizes(0);
2838 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2839 m_pState
->m_dontCenterSplitter
= false;
2842 // -----------------------------------------------------------------------
2844 void wxPropertyGrid::CenterSplitter( bool enableAutoResizing
)
2846 SetSplitterPosition( m_width
/2 );
2847 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2848 m_pState
->m_dontCenterSplitter
= false;
2851 // -----------------------------------------------------------------------
2852 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2853 // -----------------------------------------------------------------------
2855 // Returns nearest paint visible property (such that will be painted unless
2856 // window is scrolled or resized). If given property is paint visible, then
2857 // it itself will be returned
2858 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2860 int vx
,vy1
;// Top left corner of client
2861 GetViewStart(&vx
,&vy1
);
2862 vy1
*= wxPG_PIXELS_PER_UNIT
;
2864 int vy2
= vy1
+ m_height
;
2865 int propY
= p
->GetY2(m_lineHeight
);
2867 if ( (propY
+ m_lineHeight
) < vy1
)
2870 return DoGetItemAtY( vy1
);
2872 else if ( propY
> vy2
)
2875 return DoGetItemAtY( vy2
);
2878 // Itself paint visible
2883 // -----------------------------------------------------------------------
2884 // Methods related to change in value, value modification and sending events
2885 // -----------------------------------------------------------------------
2887 // commits any changes in editor of selected property
2888 // return true if validation did not fail
2889 // flags are same as with DoSelectProperty
2890 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2892 // Committing already?
2893 if ( m_inCommitChangesFromEditor
)
2896 // Don't do this if already processing editor event. It might
2897 // induce recursive dialogs and crap like that.
2898 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2900 if ( m_inDoPropertyChanged
)
2906 wxPGProperty
* selected
= GetSelection();
2909 IsEditorsValueModified() &&
2910 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2913 m_inCommitChangesFromEditor
= true;
2915 wxVariant
variant(selected
->GetValueRef());
2916 bool valueIsPending
= false;
2918 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2919 // due to another window getting focus
2920 wxWindow
* oldFocus
= m_curFocused
;
2922 bool validationFailure
= false;
2923 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2925 m_chgInfo_changedProperty
= NULL
;
2927 // If truly modified, schedule value as pending.
2928 if ( selected
->GetEditorClass()->
2929 GetValueFromControl( variant
,
2931 GetEditorControl() ) )
2933 if ( DoEditorValidate() &&
2934 PerformValidation(selected
, variant
) )
2936 valueIsPending
= true;
2940 validationFailure
= true;
2945 EditorsValueWasNotModified();
2948 m_inCommitChangesFromEditor
= false;
2952 if ( validationFailure
&& !forceSuccess
)
2956 oldFocus
->SetFocus();
2957 m_curFocused
= oldFocus
;
2960 res
= OnValidationFailure(selected
, variant
);
2962 // Now prevent further validation failure messages
2965 EditorsValueWasNotModified();
2966 OnValidationFailureReset(selected
);
2969 else if ( valueIsPending
)
2971 DoPropertyChanged( selected
, flags
);
2972 EditorsValueWasNotModified();
2981 // -----------------------------------------------------------------------
2983 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2987 // Runs all validation functionality.
2988 // Returns true if value passes all tests.
2991 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2992 m_validationInfo
.m_isFailing
= true;
2995 // Variant list a special value that cannot be validated
2997 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2999 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
3004 // Adapt list to child values, if necessary
3005 wxVariant listValue
= pendingValue
;
3006 wxVariant
* pPendingValue
= &pendingValue
;
3007 wxVariant
* pList
= NULL
;
3009 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
3010 // string value, then we need treat as it was changed instead
3011 // (or, in addition, as is the case with composite string parent).
3012 // This includes creating list variant for child values.
3014 wxPGProperty
* pwc
= p
->GetParent();
3015 wxPGProperty
* changedProperty
= p
;
3016 wxPGProperty
* baseChangedProperty
= changedProperty
;
3017 wxVariant bcpPendingList
;
3019 listValue
= pendingValue
;
3020 listValue
.SetName(p
->GetBaseName());
3023 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
3025 wxVariantList tempList
;
3026 wxVariant
lv(tempList
, pwc
->GetBaseName());
3027 lv
.Append(listValue
);
3029 pPendingValue
= &listValue
;
3031 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
3033 baseChangedProperty
= pwc
;
3034 bcpPendingList
= lv
;
3037 changedProperty
= pwc
;
3038 pwc
= pwc
->GetParent();
3042 wxPGProperty
* evtChangingProperty
= changedProperty
;
3044 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
3046 value
= *pPendingValue
;
3050 // Convert list to child values
3051 pList
= pPendingValue
;
3052 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
3055 wxVariant evtChangingValue
= value
;
3057 if ( flags
& SendEvtChanging
)
3059 // FIXME: After proper ValueToString()s added, remove
3060 // this. It is just a temporary fix, as evt_changing
3061 // will simply not work for wxPG_PROP_COMPOSED_VALUE
3062 // (unless it is selected, and textctrl editor is open).
3063 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3065 evtChangingProperty
= baseChangedProperty
;
3066 if ( evtChangingProperty
!= p
)
3068 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
3072 evtChangingValue
= pendingValue
;
3076 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3078 if ( changedProperty
== GetSelection() )
3080 wxWindow
* editor
= GetEditorControl();
3081 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
3082 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
3086 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
3091 wxASSERT( m_chgInfo_changedProperty
== NULL
);
3092 m_chgInfo_changedProperty
= changedProperty
;
3093 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
3094 m_chgInfo_pendingValue
= value
;
3097 m_chgInfo_valueList
= *pList
;
3099 m_chgInfo_valueList
.MakeNull();
3101 // If changedProperty is not property which value was edited,
3102 // then call wxPGProperty::ValidateValue() for that as well.
3103 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3105 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3109 if ( flags
& SendEvtChanging
)
3111 // SendEvent returns true if event was vetoed
3112 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3113 &evtChangingValue
) )
3117 if ( flags
& IsStandaloneValidation
)
3119 // If called in 'generic' context, we need to reset
3120 // m_chgInfo_changedProperty and write back translated value.
3121 m_chgInfo_changedProperty
= NULL
;
3122 pendingValue
= value
;
3125 m_validationInfo
.m_isFailing
= false;
3130 // -----------------------------------------------------------------------
3133 wxStatusBar
* wxPropertyGrid::GetStatusBar()
3135 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3136 if ( topWnd
&& topWnd
->IsKindOf(CLASSINFO(wxFrame
)) )
3138 wxFrame
* pFrame
= wxStaticCast(topWnd
, wxFrame
);
3140 return pFrame
->GetStatusBar();
3146 // -----------------------------------------------------------------------
3148 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3150 if ( !msg
.length() )
3154 if ( !wxPGGlobalVars
->m_offline
)
3156 wxStatusBar
* pStatusBar
= GetStatusBar();
3159 pStatusBar
->SetStatusText(msg
);
3165 ::wxMessageBox(msg
, _("Property Error"));
3168 // -----------------------------------------------------------------------
3170 void wxPropertyGrid::DoHidePropertyError( wxPGProperty
* WXUNUSED(property
) )
3173 if ( !wxPGGlobalVars
->m_offline
)
3175 wxStatusBar
* pStatusBar
= GetStatusBar();
3178 pStatusBar
->SetStatusText(wxEmptyString
);
3185 // -----------------------------------------------------------------------
3187 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3188 wxVariant
& invalidValue
)
3190 if ( m_inOnValidationFailure
)
3193 m_inOnValidationFailure
= true;
3194 wxON_BLOCK_EXIT_SET(m_inOnValidationFailure
, false);
3196 wxWindow
* editor
= GetEditorControl();
3197 int vfb
= m_validationInfo
.m_failureBehavior
;
3199 if ( m_inDoSelectProperty
)
3201 // When property selection is being changed, do not display any
3202 // messages, if some were already shown for this property.
3203 if ( property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3205 m_validationInfo
.m_failureBehavior
=
3206 vfb
& ~(wxPG_VFB_SHOW_MESSAGE
|
3207 wxPG_VFB_SHOW_MESSAGEBOX
|
3208 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
);
3212 // First call property's handler
3213 property
->OnValidationFailure(invalidValue
);
3215 bool res
= DoOnValidationFailure(property
, invalidValue
);
3218 // For non-wxTextCtrl editors, we do need to revert the value
3219 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3220 property
== GetSelection() )
3222 property
->GetEditorClass()->UpdateControl(property
, editor
);
3225 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3230 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3232 int vfb
= m_validationInfo
.m_failureBehavior
;
3234 if ( vfb
& wxPG_VFB_BEEP
)
3237 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3238 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3240 unsigned int colCount
= m_pState
->GetColumnCount();
3242 // We need backup marked property's cells
3243 m_propCellsBackup
= property
->m_cells
;
3245 wxColour vfbFg
= *wxWHITE
;
3246 wxColour vfbBg
= *wxRED
;
3248 property
->EnsureCells(colCount
);
3250 for ( unsigned int i
=0; i
<colCount
; i
++ )
3252 wxPGCell
& cell
= property
->m_cells
[i
];
3253 cell
.SetFgCol(vfbFg
);
3254 cell
.SetBgCol(vfbBg
);
3257 DrawItemAndChildren(property
);
3259 if ( property
== GetSelection() )
3261 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3263 wxWindow
* editor
= GetEditorControl();
3266 editor
->SetForegroundColour(vfbFg
);
3267 editor
->SetBackgroundColour(vfbBg
);
3272 if ( vfb
& (wxPG_VFB_SHOW_MESSAGE
|
3273 wxPG_VFB_SHOW_MESSAGEBOX
|
3274 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
) )
3276 wxString msg
= m_validationInfo
.m_failureMessage
;
3278 if ( !msg
.length() )
3279 msg
= _("You have entered invalid value. Press ESC to cancel editing.");
3282 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3284 if ( !wxPGGlobalVars
->m_offline
)
3286 wxStatusBar
* pStatusBar
= GetStatusBar();
3288 pStatusBar
->SetStatusText(msg
);
3293 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3294 DoShowPropertyError(property
, msg
);
3296 if ( vfb
& wxPG_VFB_SHOW_MESSAGEBOX
)
3297 ::wxMessageBox(msg
, _("Property Error"));
3300 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3303 // -----------------------------------------------------------------------
3305 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3307 int vfb
= m_validationInfo
.m_failureBehavior
;
3309 if ( vfb
& wxPG_VFB_MARK_CELL
)
3312 property
->m_cells
= m_propCellsBackup
;
3314 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3316 if ( property
== GetSelection() && GetEditorControl() )
3318 // Calling this will recreate the control, thus resetting its colour
3319 RefreshProperty(property
);
3323 DrawItemAndChildren(property
);
3328 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3330 if ( !wxPGGlobalVars
->m_offline
)
3332 wxStatusBar
* pStatusBar
= GetStatusBar();
3334 pStatusBar
->SetStatusText(wxEmptyString
);
3339 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3341 DoHidePropertyError(property
);
3344 m_validationInfo
.m_isFailing
= false;
3347 // -----------------------------------------------------------------------
3349 // flags are same as with DoSelectProperty
3350 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3352 if ( m_inDoPropertyChanged
)
3355 m_inDoPropertyChanged
= true;
3356 wxON_BLOCK_EXIT_SET(m_inDoPropertyChanged
, false);
3358 wxPGProperty
* selected
= GetSelection();
3360 m_pState
->m_anyModified
= 1;
3362 // If property's value is being changed, assume it is valid
3363 OnValidationFailureReset(selected
);
3365 // Maybe need to update control
3366 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3368 // These values were calculated in PerformValidation()
3369 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3370 wxVariant value
= m_chgInfo_pendingValue
;
3372 wxPGProperty
* topPaintedProperty
= changedProperty
;
3374 while ( !topPaintedProperty
->IsCategory() &&
3375 !topPaintedProperty
->IsRoot() )
3377 topPaintedProperty
= topPaintedProperty
->GetParent();
3380 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3382 // NB: Call GetEditorControl() as late as possible, because OnSetValue()
3383 // and perhaps other user-defined virtual functions may change it.
3384 wxWindow
* editor
= GetEditorControl();
3386 // Set as Modified (not if dragging just began)
3387 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3389 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3390 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3393 SetCurControlBoldFont();
3399 // Propagate updates to parent(s)
3401 wxPGProperty
* prevPwc
= NULL
;
3403 while ( prevPwc
!= topPaintedProperty
)
3405 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3407 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3410 SetCurControlBoldFont();
3414 pwc
= pwc
->GetParent();
3417 // Draw the actual property
3418 DrawItemAndChildren( topPaintedProperty
);
3421 // If value was set by wxPGProperty::OnEvent, then update the editor
3423 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3429 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3430 if ( m_wndEditor
) m_wndEditor
->Refresh();
3431 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3436 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3438 // If top parent has composite string value, then send to child parents,
3439 // starting from baseChangedProperty.
3440 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3442 pwc
= m_chgInfo_baseChangedProperty
;
3444 while ( pwc
!= changedProperty
)
3446 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3447 pwc
= pwc
->GetParent();
3451 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3456 // -----------------------------------------------------------------------
3458 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3460 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3462 m_chgInfo_changedProperty
= NULL
;
3464 if ( PerformValidation(p
, newValue
) )
3466 DoPropertyChanged(p
);
3471 OnValidationFailure(p
, newValue
);
3477 // -----------------------------------------------------------------------
3479 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3481 wxPGProperty
* prop
= GetSelectedProperty();
3484 return wxNullVariant
;
3486 wxTextCtrl
* tc
= GetEditorTextCtrl();
3487 wxVariant value
= prop
->GetValue();
3489 if ( !tc
|| !IsEditorsValueModified() )
3492 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3495 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3496 return prop
->GetValue();
3501 // -----------------------------------------------------------------------
3503 // Runs wxValidator for the selected property
3504 bool wxPropertyGrid::DoEditorValidate()
3506 #if wxUSE_VALIDATORS
3507 wxRecursionGuard
guard(m_validatingEditor
);
3508 if ( guard
.IsInside() )
3511 wxPGProperty
* selected
= GetSelection();
3514 wxWindow
* wnd
= GetEditorControl();
3516 wxValidator
* validator
= selected
->GetValidator();
3517 if ( validator
&& wnd
)
3519 validator
->SetWindow(wnd
);
3520 if ( !validator
->Validate(this) )
3528 // -----------------------------------------------------------------------
3530 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3532 // It is possible that this handler receives event even before
3533 // the control has been properly initialized. Let's skip the
3534 // event handling in that case.
3538 // Don't care about the event if it originated from the
3539 // 'label editor'. In this function we only care about the
3540 // property value editor.
3541 if ( m_labelEditor
&& event
.GetId() == m_labelEditor
->GetId() )
3547 wxPGProperty
* selected
= GetSelection();
3549 // Somehow, event is handled after property has been deselected.
3550 // Possibly, but very rare.
3552 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3553 m_inOnValidationFailure
||
3554 // Also don't handle editor event if wxEVT_PG_CHANGED or
3555 // similar is currently doing something (showing a
3556 // message box, for instance).
3560 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3563 wxVariant
pendingValue(selected
->GetValueRef());
3564 wxWindow
* wnd
= GetEditorControl();
3565 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3567 bool wasUnspecified
= selected
->IsValueUnspecified();
3568 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3569 bool valueIsPending
= false;
3571 m_chgInfo_changedProperty
= NULL
;
3573 m_iFlags
&= ~wxPG_FL_VALUE_CHANGE_IN_EVENT
;
3576 // Filter out excess wxTextCtrl modified events
3577 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&& wnd
)
3579 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3581 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3583 wxString newTcValue
= tc
->GetValue();
3584 if ( m_prevTcValue
== newTcValue
)
3586 m_prevTcValue
= newTcValue
;
3588 else if ( wnd
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
3590 wxComboCtrl
* cc
= (wxComboCtrl
*) wnd
;
3592 wxString newTcValue
= cc
->GetTextCtrl()->GetValue();
3593 if ( m_prevTcValue
== newTcValue
)
3595 m_prevTcValue
= newTcValue
;
3599 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3601 bool validationFailure
= false;
3602 bool buttonWasHandled
= false;
3605 // Try common button handling
3606 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3608 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3612 buttonWasHandled
= true;
3613 // Store as res2, as previously (and still currently alternatively)
3614 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3615 // in wxPGProperty::OnEvent().
3616 adapter
->ShowDialog( this, selected
);
3621 if ( !buttonWasHandled
)
3623 if ( wnd
|| m_wndEditor2
)
3625 // First call editor class' event handler.
3626 const wxPGEditor
* editor
= selected
->GetEditorClass();
3628 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3630 // If changes, validate them
3631 if ( DoEditorValidate() )
3633 if ( editor
->GetValueFromControl( pendingValue
,
3636 valueIsPending
= true;
3638 // Mark value always as pending if validation is currently
3639 // failing and value was not unspecified
3640 if ( !valueIsPending
&&
3641 !pendingValue
.IsNull() &&
3642 m_validationInfo
.m_isFailing
)
3643 valueIsPending
= true;
3647 validationFailure
= true;
3652 // Then the property's custom handler (must be always called, unless
3653 // validation failed).
3654 if ( !validationFailure
)
3655 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3658 // SetValueInEvent(), as called in one of the functions referred above
3659 // overrides editor's value.
3660 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3662 valueIsPending
= true;
3663 pendingValue
= m_changeInEventValue
;
3664 selFlags
|= wxPG_SEL_DIALOGVAL
;
3667 if ( !validationFailure
&& valueIsPending
)
3668 if ( !PerformValidation(selected
, pendingValue
) )
3669 validationFailure
= true;
3671 if ( validationFailure
)
3673 OnValidationFailure(selected
, pendingValue
);
3675 else if ( valueIsPending
)
3677 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3679 DoPropertyChanged(selected
, selFlags
);
3680 EditorsValueWasNotModified();
3682 // Regardless of editor type, unfocus editor on
3683 // text-editing related enter press.
3684 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3691 // No value after all
3693 // Regardless of editor type, unfocus editor on
3694 // text-editing related enter press.
3695 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3700 // Let unhandled button click events go to the parent
3701 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3703 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3704 GetEventHandler()->AddPendingEvent(evt
);
3708 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3711 // -----------------------------------------------------------------------
3712 // wxPropertyGrid editor control helper methods
3713 // -----------------------------------------------------------------------
3715 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3717 int itemy
= p
->GetY2(m_lineHeight
);
3718 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3719 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3720 int imageOffset
= 0;
3722 int vx
, vy
; // Top left corner of client
3723 GetViewStart(&vx
, &vy
);
3724 vy
*= wxPG_PIXELS_PER_UNIT
;
3728 // TODO: If custom image detection changes from current, change this.
3729 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3731 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3732 int iw
= p
->OnMeasureImage().x
;
3734 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3735 imageOffset
= p
->GetImageOffset(iw
);
3738 else if ( column
== 0 )
3740 splitterX
+= (p
->m_depth
- 1) * m_subgroup_extramargin
;
3745 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3747 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3752 // -----------------------------------------------------------------------
3754 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3756 wxSize sz
= GetImageSize(p
, item
);
3757 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3758 wxPG_CUSTOM_IMAGE_SPACINGY
,
3763 // return size of custom paint image
3764 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3766 // If called with NULL property, then return default image
3767 // size for properties that use image.
3769 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3771 wxSize cis
= p
->OnMeasureImage(item
);
3773 int choiceCount
= p
->m_choices
.GetCount();
3774 int comVals
= p
->GetDisplayedCommonValueCount();
3775 if ( item
>= choiceCount
&& comVals
> 0 )
3777 unsigned int cvi
= item
-choiceCount
;
3778 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3780 else if ( item
>= 0 && choiceCount
== 0 )
3781 return wxSize(0, 0);
3786 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3791 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3798 // -----------------------------------------------------------------------
3800 // takes scrolling into account
3801 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3804 GetViewStart(&vx
,&vy
);
3805 vy
*=wxPG_PIXELS_PER_UNIT
;
3806 vx
*=wxPG_PIXELS_PER_UNIT
;
3809 ClientToScreen( px
, py
);
3812 // -----------------------------------------------------------------------
3814 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3817 GetViewStart(&pt2
.x
,&pt2
.y
);
3818 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3819 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3823 return m_pState
->HitTest(pt2
);
3826 // -----------------------------------------------------------------------
3828 // custom set cursor
3829 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3831 if ( type
== m_curcursor
&& !override
) return;
3833 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3835 if ( type
== wxCURSOR_SIZEWE
)
3836 cursor
= m_cursorSizeWE
;
3838 SetCursor( *cursor
);
3843 // -----------------------------------------------------------------------
3846 wxPropertyGrid::GetUnspecifiedValueText( int argFlags
) const
3848 const wxPGCell
& ua
= GetUnspecifiedValueAppearance();
3850 if ( ua
.HasText() &&
3851 !(argFlags
& wxPG_FULL_VALUE
) &&
3852 !(argFlags
& wxPG_EDITABLE_VALUE
) )
3853 return ua
.GetText();
3855 return wxEmptyString
;
3858 // -----------------------------------------------------------------------
3859 // wxPropertyGrid property selection, editor creation
3860 // -----------------------------------------------------------------------
3863 // This class forwards events from property editor controls to wxPropertyGrid.
3864 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3867 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3868 : wxEvtHandler(), m_propGrid(propGrid
)
3872 virtual ~wxPropertyGridEditorEventForwarder()
3877 bool ProcessEvent( wxEvent
& event
)
3882 m_propGrid
->HandleCustomEditorEvent(event
);
3885 // NB: On wxMSW, a wxTextCtrl with wxTE_PROCESS_ENTER
3886 // may beep annoyingly if that event is skipped
3887 // and passed to parent event handler.
3888 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3891 return wxEvtHandler::ProcessEvent(event
);
3894 wxPropertyGrid
* m_propGrid
;
3897 // Setups event handling for child control
3898 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3900 wxWindowID id
= argWnd
->GetId();
3902 if ( argWnd
== m_wndEditor
)
3904 argWnd
->Connect(id
, wxEVT_MOTION
,
3905 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3907 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3908 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3910 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3911 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3913 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3914 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3916 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3917 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3919 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3920 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3924 wxPropertyGridEditorEventForwarder
* forwarder
;
3925 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3926 argWnd
->PushEventHandler(forwarder
);
3928 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3929 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3933 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3940 // Do not free editors immediately (for sake of processing events)
3941 wxPendingDelete
.Append(wnd
);
3944 void wxPropertyGrid::FreeEditors()
3947 // Return focus back to canvas from children (this is required at least for
3948 // GTK+, which, unlike Windows, clears focus when control is destroyed
3949 // instead of moving it to closest parent).
3950 wxWindow
* focus
= wxWindow::FindFocus();
3953 wxWindow
* parent
= focus
->GetParent();
3956 if ( parent
== this )
3961 parent
= parent
->GetParent();
3965 // Do not free editors immediately if processing events
3968 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3969 m_wndEditor2
->Hide();
3970 wxPendingDelete
.Append( handler
);
3971 DestroyEditorWnd(m_wndEditor2
);
3972 m_wndEditor2
= NULL
;
3977 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3978 m_wndEditor
->Hide();
3979 wxPendingDelete
.Append( handler
);
3980 DestroyEditorWnd(m_wndEditor
);
3985 // Call with NULL to de-select property
3986 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3991 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3992 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3996 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
4000 if ( m_inDoSelectProperty
)
4003 m_inDoSelectProperty
= true;
4004 wxON_BLOCK_EXIT_SET(m_inDoSelectProperty
, false);
4009 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
4010 wxPGProperty
* prevFirstSel
;
4012 if ( prevSelection
.size() > 0 )
4013 prevFirstSel
= prevSelection
[0];
4015 prevFirstSel
= NULL
;
4017 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
4018 prevFirstSel
= NULL
;
4020 // Always send event, as this is indirect call
4021 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4025 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
4027 wxPrintf( "None selected\n" );
4030 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
4032 wxPrintf( "P = NULL\n" );
4035 // If we are frozen, then just set the values.
4038 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4039 m_editorFocused
= 0;
4040 m_pState
->DoSetSelection(p
);
4042 // If frozen, always free controls. But don't worry, as Thaw will
4043 // recall SelectProperty to recreate them.
4046 // Prevent any further selection measures in this call
4052 if ( prevFirstSel
== p
&&
4053 prevSelection
.size() <= 1 &&
4054 !(flags
& wxPG_SEL_FORCE
) )
4056 // Only set focus if not deselecting
4059 if ( flags
& wxPG_SEL_FOCUS
)
4063 m_wndEditor
->SetFocus();
4064 m_editorFocused
= 1;
4077 // First, deactivate previous
4080 // Must double-check if this is an selected in case of forceswitch
4081 if ( p
!= prevFirstSel
)
4083 if ( !CommitChangesFromEditor(flags
) )
4085 // Validation has failed, so we can't exit the previous editor
4086 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
4087 // _("Invalid Value"),wxOK|wxICON_ERROR);
4092 // This should be called after CommitChangesFromEditor(), so that
4093 // OnValidationFailure() still has information on property's
4094 // validation state.
4095 OnValidationFailureReset(prevFirstSel
);
4099 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4100 EditorsValueWasNotModified();
4103 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4105 m_pState
->DoSetSelection(p
);
4107 // Redraw unselected
4108 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
4110 DrawItem(prevSelection
[i
]);
4114 // Then, activate the one given.
4117 int propY
= p
->GetY2(m_lineHeight
);
4119 int splitterX
= GetSplitterPosition();
4120 m_editorFocused
= 0;
4121 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
4123 wxASSERT( m_wndEditor
== NULL
);
4126 // Only create editor for non-disabled non-caption
4127 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
4129 // do this for non-caption items
4133 // Do we need to paint the custom image, if any?
4134 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
4135 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
4136 !p
->GetEditorClass()->CanContainCustomImage()
4138 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
4140 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
4141 wxPoint goodPos
= grect
.GetPosition();
4143 // Editor appearance can now be considered clear
4144 m_editorAppearance
.SetEmptyData();
4146 const wxPGEditor
* editor
= p
->GetEditorClass();
4147 wxCHECK_MSG(editor
, false,
4148 wxT("NULL editor class not allowed"));
4150 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
4152 wxPGWindowList wndList
=
4153 editor
->CreateControls(this,
4158 m_wndEditor
= wndList
.m_primary
;
4159 m_wndEditor2
= wndList
.m_secondary
;
4160 wxWindow
* primaryCtrl
= GetEditorControl();
4163 // Essentially, primaryCtrl == m_wndEditor
4166 // NOTE: It is allowed for m_wndEditor to be NULL - in this
4167 // case value is drawn as normal, and m_wndEditor2 is
4168 // assumed to be a right-aligned button that triggers
4169 // a separate editorCtrl window.
4173 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
4174 "CreateControls must use result of "
4175 "wxPropertyGrid::GetPanel() as parent "
4178 // Set validator, if any
4179 #if wxUSE_VALIDATORS
4180 wxValidator
* validator
= p
->GetValidator();
4182 primaryCtrl
->SetValidator(*validator
);
4185 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
4186 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
4188 // If it has modified status, use bold font
4189 // (must be done before capturing m_ctrlXAdjust)
4190 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
4191 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
4192 SetCurControlBoldFont();
4194 // Store x relative to splitter (we'll need it).
4195 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
4197 // Check if background clear is not necessary
4198 wxPoint pos
= m_wndEditor
->GetPosition();
4199 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
4201 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
4204 m_wndEditor
->SetSizeHints(3, 3);
4206 SetupChildEventHandling(primaryCtrl
);
4208 // Focus and select all (wxTextCtrl, wxComboBox etc)
4209 if ( flags
& wxPG_SEL_FOCUS
)
4211 primaryCtrl
->SetFocus();
4213 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
4217 if ( p
->IsValueUnspecified() )
4218 SetEditorAppearance(m_unspecifiedAppearance
,
4225 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
4226 "CreateControls must use result of "
4227 "wxPropertyGrid::GetPanel() as parent "
4230 // Get proper id for wndSecondary
4231 m_wndSecId
= m_wndEditor2
->GetId();
4232 wxWindowList children
= m_wndEditor2
->GetChildren();
4233 wxWindowList::iterator node
= children
.begin();
4234 if ( node
!= children
.end() )
4235 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
4237 m_wndEditor2
->SetSizeHints(3,3);
4239 m_wndEditor2
->Show();
4241 SetupChildEventHandling(m_wndEditor2
);
4243 // If no primary editor, focus to button to allow
4244 // it to interprete ENTER etc.
4245 // NOTE: Due to problems focusing away from it, this
4246 // has been disabled.
4248 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
4249 m_wndEditor2->SetFocus();
4253 if ( flags
& wxPG_SEL_FOCUS
)
4254 m_editorFocused
= 1;
4259 // Make sure focus is in grid canvas (important for wxGTK,
4264 EditorsValueWasNotModified();
4266 // If it's inside collapsed section, expand parent, scroll, etc.
4267 // Also, if it was partially visible, scroll it into view.
4268 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
4273 m_wndEditor
->Show(true);
4276 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
4281 // Make sure focus is in grid canvas
4285 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4291 // Show help text in status bar.
4292 // (if found and grid not embedded in manager with help box and
4293 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4296 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4298 wxStatusBar
* statusbar
= GetStatusBar();
4301 const wxString
* pHelpString
= (const wxString
*) NULL
;
4305 pHelpString
= &p
->GetHelpString();
4306 if ( pHelpString
->length() )
4308 // Set help box text.
4309 statusbar
->SetStatusText( *pHelpString
);
4310 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4314 if ( (!pHelpString
|| !pHelpString
->length()) &&
4315 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
4317 // Clear help box - but only if it was written
4318 // by us at previous time.
4319 statusbar
->SetStatusText( m_emptyString
);
4320 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4326 // call wx event handler (here so that it also occurs on deselection)
4327 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4328 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4333 // -----------------------------------------------------------------------
4335 bool wxPropertyGrid::UnfocusEditor()
4337 wxPGProperty
* selected
= GetSelection();
4339 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4342 if ( !CommitChangesFromEditor(0) )
4351 // -----------------------------------------------------------------------
4353 void wxPropertyGrid::RefreshEditor()
4355 wxPGProperty
* p
= GetSelection();
4359 wxWindow
* wnd
= GetEditorControl();
4363 // Set editor font boldness - must do this before
4364 // calling UpdateControl().
4365 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4367 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4368 wnd
->SetFont(GetCaptionFont());
4370 wnd
->SetFont(GetFont());
4373 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4375 editorClass
->UpdateControl(p
, wnd
);
4377 if ( p
->IsValueUnspecified() )
4378 SetEditorAppearance(m_unspecifiedAppearance
, true);
4381 // -----------------------------------------------------------------------
4383 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4385 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4387 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4389 flags
|= wxPG_SEL_FOCUS
;
4391 return DoSelectProperty(p
, flags
);
4394 // -----------------------------------------------------------------------
4395 // wxPropertyGrid expand/collapse state
4396 // -----------------------------------------------------------------------
4398 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4400 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4401 wxPGProperty
* selected
= GetSelection();
4403 // If active editor was inside collapsed section, then disable it
4404 if ( selected
&& selected
->IsSomeParent(p
) )
4409 // Store dont-center-splitter flag 'cause we need to temporarily set it
4410 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4411 m_pState
->m_dontCenterSplitter
= true;
4413 bool res
= m_pState
->DoCollapse(pwc
);
4418 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4420 RecalculateVirtualSize();
4424 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4429 // -----------------------------------------------------------------------
4431 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4433 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4435 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4437 // Store dont-center-splitter flag 'cause we need to temporarily set it
4438 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4439 m_pState
->m_dontCenterSplitter
= true;
4441 bool res
= m_pState
->DoExpand(pwc
);
4446 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4448 RecalculateVirtualSize();
4452 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4457 // -----------------------------------------------------------------------
4459 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4462 return m_pState
->DoHideProperty(p
, hide
, flags
);
4464 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4465 int selRemoveCount
= 0;
4466 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4468 wxPGProperty
* selected
= selection
[i
];
4469 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4471 if ( !DoRemoveFromSelection(p
, flags
) )
4473 selRemoveCount
+= 1;
4477 m_pState
->DoHideProperty(p
, hide
, flags
);
4479 RecalculateVirtualSize();
4486 // -----------------------------------------------------------------------
4487 // wxPropertyGrid size related methods
4488 // -----------------------------------------------------------------------
4490 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4492 // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise
4493 // virtual size calculation may go wrong.
4494 if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4500 // If virtual height was changed, then recalculate editor control position(s)
4501 if ( m_pState
->m_vhCalcPending
)
4502 CorrectEditorWidgetPosY();
4504 m_pState
->EnsureVirtualHeight();
4506 wxASSERT_LEVEL_2_MSG(
4507 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4508 "VirtualHeight and ActualVirtualHeight should match"
4511 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4513 int x
= m_pState
->m_width
;
4514 int y
= m_pState
->m_virtualHeight
;
4517 GetClientSize(&width
,&height
);
4519 // Now adjust virtual size.
4520 SetVirtualSize(x
, y
);
4526 // Adjust scrollbars
4527 if ( HasVirtualWidth() )
4529 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4530 xPos
= GetScrollPos( wxHORIZONTAL
);
4533 if ( forceXPos
!= -1 )
4536 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4539 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4540 int yPos
= GetScrollPos( wxVERTICAL
);
4542 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4543 xAmount
, yAmount
, xPos
, yPos
, true );
4545 // Must re-get size now
4546 GetClientSize(&width
,&height
);
4548 if ( !HasVirtualWidth() )
4550 m_pState
->SetVirtualWidth(width
);
4557 m_pState
->CheckColumnWidths();
4559 if ( GetSelection() )
4560 CorrectEditorWidgetSizeX();
4562 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4565 // -----------------------------------------------------------------------
4567 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4569 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4573 GetClientSize(&width
, &height
);
4578 #if wxPG_DOUBLE_BUFFER
4579 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4581 int dblh
= (m_lineHeight
*2);
4582 if ( !m_doubleBuffer
)
4584 // Create double buffer bitmap to draw on, if none
4585 int w
= (width
>250)?width
:250;
4586 int h
= height
+ dblh
;
4588 m_doubleBuffer
= new wxBitmap( w
, h
);
4592 int w
= m_doubleBuffer
->GetWidth();
4593 int h
= m_doubleBuffer
->GetHeight();
4595 // Double buffer must be large enough
4596 if ( w
< width
|| h
< (height
+dblh
) )
4598 if ( w
< width
) w
= width
;
4599 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4600 delete m_doubleBuffer
;
4601 m_doubleBuffer
= new wxBitmap( w
, h
);
4608 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4609 m_ncWidth
= event
.GetSize().x
;
4613 if ( m_pState
->m_itemsAdded
)
4614 PrepareAfterItemsAdded();
4616 // Without this, virtual size (atleast under wxGTK) will be skewed
4617 RecalculateVirtualSize();
4623 // -----------------------------------------------------------------------
4625 void wxPropertyGrid::SetVirtualWidth( int width
)
4629 // Disable virtual width
4630 width
= GetClientSize().x
;
4631 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4635 // Enable virtual width
4636 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4638 m_pState
->SetVirtualWidth( width
);
4641 void wxPropertyGrid::SetFocusOnCanvas()
4643 SetFocusIgnoringChildren();
4644 m_editorFocused
= 0;
4647 // -----------------------------------------------------------------------
4648 // wxPropertyGrid mouse event handling
4649 // -----------------------------------------------------------------------
4651 // selFlags uses same values DoSelectProperty's flags
4652 // Returns true if event was vetoed.
4653 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4655 unsigned int selFlags
,
4656 unsigned int column
)
4658 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4661 // Send property grid event of specific type and with specific property
4662 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4663 evt
.SetPropertyGrid(this);
4664 evt
.SetEventObject(m_eventObject
);
4666 evt
.SetColumn(column
);
4667 if ( eventType
== wxEVT_PG_CHANGING
)
4670 evt
.SetCanVeto(true);
4671 m_validationInfo
.m_pValue
= pValue
;
4672 evt
.SetupValidationInfo();
4677 evt
.SetPropertyValue(p
->GetValue());
4679 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4680 evt
.SetCanVeto(true);
4683 wxPropertyGridEvent
* prevProcessedEvent
= m_processedEvent
;
4684 m_processedEvent
= &evt
;
4685 m_eventObject
->HandleWindowEvent(evt
);
4686 m_processedEvent
= prevProcessedEvent
;
4688 return evt
.WasVetoed();
4691 // -----------------------------------------------------------------------
4693 // Return false if should be skipped
4694 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4698 // Need to set focus?
4699 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4704 wxPropertyGridPageState
* state
= m_pState
;
4706 int splitterHitOffset
;
4707 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4709 wxPGProperty
* p
= DoGetItemAtY(y
);
4713 int depth
= (int)p
->GetDepth() - 1;
4715 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4717 if ( x
>= marginEnds
)
4721 if ( p
->IsCategory() )
4723 // This is category.
4724 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4726 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4728 // Expand, collapse, activate etc. if click on text or left of splitter.
4731 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4736 if ( !AddToSelectionFromInputEvent( p
,
4741 // On double-click, expand/collapse.
4742 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4744 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4745 else DoExpand( p
, true );
4749 else if ( splitterHit
== -1 )
4752 unsigned int selFlag
= 0;
4753 if ( columnHit
== 1 )
4755 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4756 selFlag
= wxPG_SEL_FOCUS
;
4758 if ( !AddToSelectionFromInputEvent( p
,
4764 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4766 if ( p
->GetChildCount() && !p
->IsCategory() )
4767 // On double-click, expand/collapse.
4768 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4770 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4771 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4772 else DoExpand( p
, true );
4779 // click on splitter
4780 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4782 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4784 // Double-clicking the splitter causes auto-centering
4785 if ( m_pState
->GetColumnCount() <= 2 )
4787 ResetColumnSizes( true );
4789 SendEvent(wxEVT_PG_COL_DRAGGING
,
4792 wxPG_SEL_NOVALIDATE
,
4793 (unsigned int)m_draggedSplitter
);
4796 else if ( m_dragStatus
== 0 )
4799 // Begin draggin the splitter
4803 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4805 // Allow application to veto dragging
4806 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4808 (unsigned int)splitterHit
) )
4812 // Changes must be committed here or the
4813 // value won't be drawn correctly
4814 if ( !CommitChangesFromEditor() )
4817 m_wndEditor
->Show ( false );
4820 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4823 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4827 m_draggedSplitter
= splitterHit
;
4828 m_dragOffset
= splitterHitOffset
;
4830 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4831 // Fixes button disappearance bug
4833 m_wndEditor2
->Show ( false );
4836 m_startingSplitterX
= x
- splitterHitOffset
;
4845 if ( p
->GetChildCount() )
4847 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4849 // Fine tune cell button x
4850 if ( !p
->IsCategory() )
4851 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4853 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4855 int y2
= y
% m_lineHeight
;
4856 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4858 // On click on expander button, expand/collapse
4859 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4860 DoCollapse( p
, true );
4862 DoExpand( p
, true );
4871 // -----------------------------------------------------------------------
4873 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4874 unsigned int WXUNUSED(y
),
4875 wxMouseEvent
& event
)
4879 // Select property here as well
4880 wxPGProperty
* p
= m_propHover
;
4881 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4883 // Send right click event.
4884 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4891 // -----------------------------------------------------------------------
4893 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4894 unsigned int WXUNUSED(y
),
4895 wxMouseEvent
& event
)
4899 // Select property here as well
4900 wxPGProperty
* p
= m_propHover
;
4902 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4904 // Send double-click event.
4905 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4912 // -----------------------------------------------------------------------
4914 #if wxPG_SUPPORT_TOOLTIPS
4916 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4918 if ( tipString
.length() )
4920 wxScrolledWindow::SetToolTip(tipString
);
4924 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4925 wxScrolledWindow::SetToolTip( m_emptyString
);
4927 wxScrolledWindow::SetToolTip( NULL
);
4932 #endif // #if wxPG_SUPPORT_TOOLTIPS
4934 // -----------------------------------------------------------------------
4936 // Return false if should be skipped
4937 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
,
4938 wxMouseEvent
&event
)
4940 // Safety check (needed because mouse capturing may
4941 // otherwise freeze the control)
4942 if ( m_dragStatus
> 0 && !event
.Dragging() )
4944 HandleMouseUp(x
, y
, event
);
4947 wxPropertyGridPageState
* state
= m_pState
;
4949 int splitterHitOffset
;
4950 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4951 int splitterX
= x
- splitterHitOffset
;
4953 m_colHover
= columnHit
;
4955 if ( m_dragStatus
> 0 )
4957 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4958 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4961 int newSplitterX
= x
- m_dragOffset
;
4963 // Splitter redraw required?
4964 if ( newSplitterX
!= splitterX
)
4967 DoSetSplitterPosition(newSplitterX
,
4969 wxPG_SPLITTER_REFRESH
|
4970 wxPG_SPLITTER_FROM_EVENT
);
4972 SendEvent(wxEVT_PG_COL_DRAGGING
,
4975 wxPG_SEL_NOVALIDATE
,
4976 (unsigned int)m_draggedSplitter
);
4987 int ih
= m_lineHeight
;
4990 #if wxPG_SUPPORT_TOOLTIPS
4991 wxPGProperty
* prevHover
= m_propHover
;
4992 unsigned char prevSide
= m_mouseSide
;
4994 int curPropHoverY
= y
- (y
% ih
);
4996 // On which item it hovers
4999 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
5002 // Mouse moves on another property
5004 m_propHover
= DoGetItemAtY(y
);
5005 m_propHoverY
= curPropHoverY
;
5008 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
5011 #if wxPG_SUPPORT_TOOLTIPS
5012 // Store which side we are on
5014 if ( columnHit
== 1 )
5016 else if ( columnHit
== 0 )
5020 // If tooltips are enabled, show label or value as a tip
5021 // in case it doesn't otherwise show in full length.
5023 if ( m_windowStyle
& wxPG_TOOLTIPS
)
5025 wxToolTip
* tooltip
= GetToolTip();
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 );
5067 SetToolTip( tipString
);
5074 #if wxPG_ALLOW_EMPTY_TOOLTIPS
5075 SetToolTip( m_emptyString
);
5077 wxScrolledWindow::SetToolTip( NULL
);
5088 #if wxPG_ALLOW_EMPTY_TOOLTIPS
5089 SetToolTip( m_emptyString
);
5091 wxScrolledWindow::SetToolTip( NULL
);
5099 if ( splitterHit
== -1 ||
5101 HasFlag(wxPG_STATIC_SPLITTER
) )
5103 // hovering on something else
5104 if ( m_curcursor
!= wxCURSOR_ARROW
)
5105 CustomSetCursor( wxCURSOR_ARROW
);
5109 // Do not allow splitter cursor on caption items.
5110 // (also not if we were dragging and its started
5111 // outside the splitter region)
5113 if ( !m_propHover
->IsCategory() &&
5117 // hovering on splitter
5119 // NB: Condition disabled since MouseLeave event (from the
5120 // editor control) cannot be reliably detected.
5121 //if ( m_curcursor != wxCURSOR_SIZEWE )
5122 CustomSetCursor( wxCURSOR_SIZEWE
, true );
5128 // hovering on something else
5129 if ( m_curcursor
!= wxCURSOR_ARROW
)
5130 CustomSetCursor( wxCURSOR_ARROW
);
5135 // Multi select by dragging
5137 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
5138 event
.LeftIsDown() &&
5142 !state
->DoIsPropertySelected(m_propHover
) )
5144 // Additional requirement is that the hovered property
5145 // is adjacent to edges of selection.
5146 const wxArrayPGProperty
& selection
= GetSelectedProperties();
5148 // Since categories cannot be selected along with 'other'
5149 // properties, exclude them from iterator flags.
5150 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
5152 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
5154 // TODO: This could be optimized by keeping track of
5155 // which properties are at the edges of selection.
5156 wxPGProperty
* selProp
= selection
[i
];
5157 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
5160 DoAddToSelection(m_propHover
);
5169 // -----------------------------------------------------------------------
5171 // Also handles Leaving event
5172 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
5173 wxMouseEvent
&WXUNUSED(event
) )
5175 wxPropertyGridPageState
* state
= m_pState
;
5179 int splitterHitOffset
;
5180 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
5182 // No event type check - basicly calling this method should
5183 // just stop dragging.
5184 // Left up after dragged?
5185 if ( m_dragStatus
>= 1 )
5188 // End Splitter Dragging
5190 // DO NOT ENABLE FOLLOWING LINE!
5191 // (it is only here as a reminder to not to do it)
5194 SendEvent(wxEVT_PG_COL_END_DRAG
,
5197 wxPG_SEL_NOVALIDATE
,
5198 (unsigned int)m_draggedSplitter
);
5200 // Disable splitter auto-centering (but only if moved any -
5201 // otherwise we end up disabling auto-center even after a
5202 // recentering double-click).
5203 int posDiff
= abs(m_startingSplitterX
-
5204 GetSplitterPosition(m_draggedSplitter
));
5207 state
->m_dontCenterSplitter
= true;
5209 // This is necessary to return cursor
5210 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5213 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5216 // Set back the default cursor, if necessary
5217 if ( splitterHit
== -1 ||
5220 CustomSetCursor( wxCURSOR_ARROW
);
5225 // Control background needs to be cleared
5226 wxPGProperty
* selected
= GetSelection();
5227 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
5228 DrawItem( selected
);
5232 m_wndEditor
->Show ( true );
5235 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
5236 // Fixes button disappearance bug
5238 m_wndEditor2
->Show ( true );
5241 // This clears the focus.
5242 m_editorFocused
= 0;
5248 // -----------------------------------------------------------------------
5250 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
5252 int splitterX
= GetSplitterPosition();
5255 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
5257 wxWindow
* wnd
= GetEditorControl();
5259 // Hide popup on clicks
5260 if ( event
.GetEventType() != wxEVT_MOTION
)
5261 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5263 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
5269 if ( wnd
== NULL
|| m_dragStatus
||
5271 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
5272 ux
>= (r
.x
+r
.width
) ||
5274 event
.m_y
>= (r
.y
+r
.height
)
5284 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5289 // -----------------------------------------------------------------------
5291 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
5294 if ( OnMouseCommon( event
, &x
, &y
) )
5296 HandleMouseClick(x
,y
,event
);
5301 // -----------------------------------------------------------------------
5303 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5306 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5307 HandleMouseRightClick(x
,y
,event
);
5311 // -----------------------------------------------------------------------
5313 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5315 // Always run standard mouse-down handler as well
5316 OnMouseClick(event
);
5319 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5320 HandleMouseDoubleClick(x
,y
,event
);
5324 // -----------------------------------------------------------------------
5326 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5329 if ( OnMouseCommon( event
, &x
, &y
) )
5331 HandleMouseMove(x
,y
,event
);
5336 // -----------------------------------------------------------------------
5338 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5341 if ( OnMouseCommon( event
, &x
, &y
) )
5343 HandleMouseUp(x
,y
,event
);
5348 // -----------------------------------------------------------------------
5350 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5352 // This may get called from child control as well, so event's
5353 // mouse position cannot be relied on.
5355 if ( event
.Entering() )
5357 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5359 // TODO: Fix this (detect parent and only do
5360 // cursor trick if it is a manager).
5361 wxASSERT( GetParent() );
5362 GetParent()->SetCursor(wxNullCursor
);
5364 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5367 GetParent()->SetCursor(wxNullCursor
);
5369 else if ( event
.Leaving() )
5371 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5372 SetCursor( wxNullCursor
);
5374 // Get real cursor position
5375 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5377 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5380 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5382 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5386 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5394 // -----------------------------------------------------------------------
5396 // Common code used by various OnMouseXXXChild methods.
5397 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5399 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5400 wxASSERT( topCtrlWnd
);
5402 event
.GetPosition(&x
,&y
);
5404 int splitterX
= GetSplitterPosition();
5406 wxRect r
= topCtrlWnd
->GetRect();
5407 if ( !m_dragStatus
&&
5408 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5409 y
>= 0 && y
< r
.height \
5412 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5417 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5424 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5427 if ( OnMouseChildCommon(event
,&x
,&y
) )
5429 bool res
= HandleMouseClick(x
,y
,event
);
5430 if ( !res
) event
.Skip();
5434 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5437 wxASSERT( m_wndEditor
);
5438 // These coords may not be exact (about +-2),
5439 // but that should not matter (right click is about item, not position).
5440 wxPoint pt
= m_wndEditor
->GetPosition();
5441 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5443 // FIXME: Used to set m_propHover to selection here. Was it really
5446 bool res
= HandleMouseRightClick(x
,y
,event
);
5447 if ( !res
) event
.Skip();
5450 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5453 if ( OnMouseChildCommon(event
,&x
,&y
) )
5455 bool res
= HandleMouseMove(x
,y
,event
);
5456 if ( !res
) event
.Skip();
5460 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5463 if ( OnMouseChildCommon(event
,&x
,&y
) )
5465 bool res
= HandleMouseUp(x
,y
,event
);
5466 if ( !res
) event
.Skip();
5470 // -----------------------------------------------------------------------
5471 // wxPropertyGrid keyboard event handling
5472 // -----------------------------------------------------------------------
5474 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5476 // Translates wxKeyEvent to wxPG_ACTION_XXX
5478 int keycode
= event
.GetKeyCode();
5479 int modifiers
= event
.GetModifiers();
5481 wxASSERT( !(modifiers
&~(0xFFFF)) );
5483 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5485 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5487 if ( it
== m_actionTriggers
.end() )
5492 int second
= (it
->second
>>16) & 0xFFFF;
5496 return (it
->second
& 0xFFFF);
5499 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5501 wxASSERT( !(modifiers
&~(0xFFFF)) );
5503 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5505 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5507 if ( it
!= m_actionTriggers
.end() )
5509 // This key combination is already used
5511 // Can add secondary?
5512 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5513 wxT("You can only add up to two separate actions per key combination.") );
5515 action
= it
->second
| (action
<<16);
5518 m_actionTriggers
[hashMapKey
] = action
;
5521 void wxPropertyGrid::ClearActionTriggers( int action
)
5523 wxPGHashMapI2I::iterator it
;
5528 didSomething
= false;
5530 for ( it
= m_actionTriggers
.begin();
5531 it
!= m_actionTriggers
.end();
5534 if ( it
->second
== action
)
5536 m_actionTriggers
.erase(it
);
5537 didSomething
= true;
5542 while ( didSomething
);
5545 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5548 // Handles key event when editor control is not focused.
5551 wxCHECK2(!m_frozen
, return);
5553 // Travelsal between items, collapsing/expanding, etc.
5554 wxPGProperty
* selected
= GetSelection();
5555 int keycode
= event
.GetKeyCode();
5556 bool editorFocused
= IsEditorFocused();
5558 if ( keycode
== WXK_TAB
)
5560 wxWindow
* mainControl
;
5562 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5563 mainControl
= GetParent();
5567 if ( !event
.ShiftDown() )
5569 if ( !editorFocused
&& m_wndEditor
)
5571 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5575 // Tab traversal workaround for platforms on which
5576 // wxWindow::Navigate() may navigate into first child
5577 // instead of next sibling. Does not work perfectly
5578 // in every scenario (for instance, when property grid
5579 // is either first or last control).
5580 #if defined(__WXGTK__)
5581 wxWindow
* sibling
= mainControl
->GetNextSibling();
5583 sibling
->SetFocusFromKbd();
5585 Navigate(wxNavigationKeyEvent::IsForward
);
5591 if ( editorFocused
)
5597 #if defined(__WXGTK__)
5598 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5600 sibling
->SetFocusFromKbd();
5602 Navigate(wxNavigationKeyEvent::IsBackward
);
5610 // Ignore Alt and Control when they are down alone
5611 if ( keycode
== WXK_ALT
||
5612 keycode
== WXK_CONTROL
)
5619 int action
= KeyEventToActions(event
, &secondAction
);
5621 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5624 // Esc cancels any changes
5625 if ( IsEditorsValueModified() )
5627 EditorsValueWasNotModified();
5629 // Update the control as well
5630 selected
->GetEditorClass()->
5631 SetControlStringValue( selected
,
5633 selected
->GetDisplayedString() );
5636 OnValidationFailureReset(selected
);
5642 // Except for TAB, ESC, and any keys specifically dedicated to
5643 // wxPropertyGrid itself, handle child control events in child control.
5645 wxPGFindInVector(m_dedicatedKeys
, keycode
) == wxNOT_FOUND
)
5647 // Only propagate event if it had modifiers
5648 if ( !event
.HasModifiers() )
5650 event
.StopPropagation();
5656 bool wasHandled
= false;
5661 if ( ButtonTriggerKeyTest(action
, event
) )
5664 wxPGProperty
* p
= selected
;
5666 // Travel and expand/collapse
5669 if ( p
->GetChildCount() )
5671 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5673 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5676 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5678 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5685 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5689 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5695 if ( selectDir
>= -1 )
5697 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5701 int reopenLabelEditorCol
= -1;
5703 if ( editorFocused
)
5705 // If editor was focused, then make the next editor
5707 selFlags
|= wxPG_SEL_FOCUS
;
5711 // Also maintain the same label editor focus state
5712 if ( m_labelEditor
)
5713 reopenLabelEditorCol
= m_selColumn
;
5716 DoSelectProperty(p
, selFlags
);
5718 if ( reopenLabelEditorCol
>= 0 )
5719 DoBeginLabelEdit(reopenLabelEditorCol
);
5726 // If nothing was selected, select the first item now
5727 // (or navigate out of tab).
5728 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5730 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5731 if ( p
) DoSelectProperty(p
);
5740 // -----------------------------------------------------------------------
5742 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5744 // If there was editor open and focused, then this event should not
5745 // really be processed here.
5746 if ( IsEditorFocused() )
5748 // However, if event had modifiers, it is probably still best
5750 if ( event
.HasModifiers() )
5753 event
.StopPropagation();
5757 HandleKeyEvent(event
, false);
5760 // -----------------------------------------------------------------------
5762 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5767 action
= KeyEventToActions(event
, &secondAction
);
5770 // Does the keycode trigger button?
5771 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5774 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5775 GetEventHandler()->AddPendingEvent(evt
);
5782 // -----------------------------------------------------------------------
5784 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5786 HandleKeyEvent(event
, true);
5789 // -----------------------------------------------------------------------
5790 // wxPropertyGrid miscellaneous event handling
5791 // -----------------------------------------------------------------------
5793 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5796 // Check if the focus is in this control or one of its children
5797 wxWindow
* newFocused
= wxWindow::FindFocus();
5799 if ( newFocused
!= m_curFocused
)
5800 HandleFocusChange( newFocused
);
5803 // Check if top-level parent has changed
5804 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5806 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5812 // Resolve pending property removals
5813 if ( m_deletedProperties
.size() > 0 )
5815 wxArrayPGProperty
& arr
= m_deletedProperties
;
5816 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5818 DeleteProperty(arr
[i
]);
5822 if ( m_removedProperties
.size() > 0 )
5824 wxArrayPGProperty
& arr
= m_removedProperties
;
5825 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5827 RemoveProperty(arr
[i
]);
5833 bool wxPropertyGrid::IsEditorFocused() const
5835 wxWindow
* focus
= wxWindow::FindFocus();
5837 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5838 focus
== GetEditorControl() )
5844 // Called by focus event handlers. newFocused is the window that becomes focused.
5845 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5848 // Never allow focus to be changed when handling editor event.
5849 // Especially because they may be displaing a dialog which
5850 // could cause all kinds of weird (native) focus changes.
5851 if ( HasInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
5854 unsigned int oldFlags
= m_iFlags
;
5855 bool wasEditorFocused
= false;
5856 wxWindow
* wndEditor
= m_wndEditor
;
5858 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5860 wxWindow
* parent
= newFocused
;
5862 // This must be one of nextFocus' parents.
5865 if ( parent
== wndEditor
)
5867 wasEditorFocused
= true;
5869 // Use m_eventObject, which is either wxPropertyGrid or
5870 // wxPropertyGridManager, as appropriate.
5871 else if ( parent
== m_eventObject
)
5873 m_iFlags
|= wxPG_FL_FOCUSED
;
5876 parent
= parent
->GetParent();
5879 // Notify editor control when it receives a focus
5880 if ( wasEditorFocused
&& m_curFocused
!= newFocused
)
5882 wxPGProperty
* p
= GetSelection();
5885 const wxPGEditor
* editor
= p
->GetEditorClass();
5886 ResetEditorAppearance();
5887 editor
->OnFocus(p
, GetEditorControl());
5891 m_curFocused
= newFocused
;
5893 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5894 (oldFlags
& wxPG_FL_FOCUSED
) )
5896 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5898 // Need to store changed value
5899 CommitChangesFromEditor();
5905 // Preliminary code for tab-order respecting
5906 // tab-traversal (but should be moved to
5909 wxWindow* prevFocus = event.GetWindow();
5910 wxWindow* useThis = this;
5911 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5912 useThis = GetParent();
5915 prevFocus->GetParent() == useThis->GetParent() )
5917 wxList& children = useThis->GetParent()->GetChildren();
5919 wxNode* node = children.Find(prevFocus);
5921 if ( node->GetNext() &&
5922 useThis == node->GetNext()->GetData() )
5923 DoSelectProperty(GetFirst());
5924 else if ( node->GetPrevious () &&
5925 useThis == node->GetPrevious()->GetData() )
5926 DoSelectProperty(GetLastProperty());
5933 wxPGProperty
* selected
= GetSelection();
5934 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5935 DrawItem( selected
);
5939 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5941 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5942 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5943 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5944 //else if ( event.GetWindow() )
5946 HandleFocusChange(event
.GetWindow());
5951 // -----------------------------------------------------------------------
5953 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5955 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5959 // -----------------------------------------------------------------------
5961 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5963 m_iFlags
|= wxPG_FL_SCROLLED
;
5968 // -----------------------------------------------------------------------
5970 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5972 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5974 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5978 // -----------------------------------------------------------------------
5979 // Property editor related functions
5980 // -----------------------------------------------------------------------
5982 // noDefCheck = true prevents infinite recursion.
5983 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5984 const wxString
& editorName
,
5987 wxASSERT( editorClass
);
5989 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5990 RegisterDefaultEditors();
5992 wxString name
= editorName
;
5993 if ( name
.length() == 0 )
5994 name
= editorClass
->GetName();
5996 // Existing editor under this name?
5997 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5999 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
6001 // If this name was already used, try class name.
6002 name
= editorClass
->GetClassInfo()->GetClassName();
6003 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
6006 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
6007 (wxPGEditor
*) vt_it
->second
,
6008 "Editor with given name was already registered" );
6010 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
6015 // Use this in RegisterDefaultEditors.
6016 #define wxPGRegisterDefaultEditorClass(EDITOR) \
6017 if ( wxPGEditor_##EDITOR == NULL ) \
6019 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
6020 new wxPG##EDITOR##Editor, true ); \
6023 // Registers all default editor classes
6024 void wxPropertyGrid::RegisterDefaultEditors()
6026 wxPGRegisterDefaultEditorClass( TextCtrl
);
6027 wxPGRegisterDefaultEditorClass( Choice
);
6028 wxPGRegisterDefaultEditorClass( ComboBox
);
6029 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
6030 #if wxPG_INCLUDE_CHECKBOX
6031 wxPGRegisterDefaultEditorClass( CheckBox
);
6033 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
6035 // Register SpinCtrl etc. editors before use
6036 RegisterAdditionalEditors();
6039 // -----------------------------------------------------------------------
6040 // wxPGStringTokenizer
6041 // Needed to handle C-style string lists (e.g. "str1" "str2")
6042 // -----------------------------------------------------------------------
6044 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
6045 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
6049 wxPGStringTokenizer::~wxPGStringTokenizer()
6053 bool wxPGStringTokenizer::HasMoreTokens()
6055 const wxString
& str
= *m_str
;
6057 wxString::const_iterator i
= m_curPos
;
6059 wxUniChar delim
= m_delimeter
;
6061 wxUniChar prev_a
= wxT('\0');
6063 bool inToken
= false;
6065 while ( i
!= str
.end() )
6074 m_readyToken
.clear();
6079 if ( prev_a
!= wxT('\\') )
6083 if ( a
!= wxT('\\') )
6103 m_curPos
= str
.end();
6111 wxString
wxPGStringTokenizer::GetNextToken()
6113 return m_readyToken
;
6116 // -----------------------------------------------------------------------
6118 // -----------------------------------------------------------------------
6120 wxPGChoiceEntry::wxPGChoiceEntry()
6121 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
6125 // -----------------------------------------------------------------------
6127 // -----------------------------------------------------------------------
6129 wxPGChoicesData::wxPGChoicesData()
6133 wxPGChoicesData::~wxPGChoicesData()
6138 void wxPGChoicesData::Clear()
6143 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
6145 wxASSERT( m_items
.size() == 0 );
6147 m_items
= data
->m_items
;
6150 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
6151 const wxPGChoiceEntry
& item
)
6153 wxVector
<wxPGChoiceEntry
>::iterator it
;
6157 index
= (int) m_items
.size();
6161 it
= m_items
.begin() + index
;
6164 m_items
.insert(it
, item
);
6166 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
6168 // Need to fix value?
6169 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
6170 ownEntry
.SetValue(index
);
6175 // -----------------------------------------------------------------------
6176 // wxPropertyGridEvent
6177 // -----------------------------------------------------------------------
6179 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
6182 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
6183 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
6184 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
6185 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
6186 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
6187 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
6188 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
6189 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
6190 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
6191 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
6192 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
6193 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
6194 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
6195 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
6197 // -----------------------------------------------------------------------
6199 void wxPropertyGridEvent::Init()
6201 m_validationInfo
= NULL
;
6204 m_wasVetoed
= false;
6207 // -----------------------------------------------------------------------
6209 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6210 : wxCommandEvent(commandType
,id
)
6216 // -----------------------------------------------------------------------
6218 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6219 : wxCommandEvent(event
)
6221 m_eventType
= event
.GetEventType();
6222 m_eventObject
= event
.m_eventObject
;
6224 OnPropertyGridSet();
6225 m_property
= event
.m_property
;
6226 m_validationInfo
= event
.m_validationInfo
;
6227 m_canVeto
= event
.m_canVeto
;
6228 m_wasVetoed
= event
.m_wasVetoed
;
6231 // -----------------------------------------------------------------------
6233 void wxPropertyGridEvent::OnPropertyGridSet()
6239 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6241 m_pg
->m_liveEvents
.push_back(this);
6244 // -----------------------------------------------------------------------
6246 wxPropertyGridEvent::~wxPropertyGridEvent()
6251 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6254 // Use iterate from the back since it is more likely that the event
6255 // being desroyed is at the end of the array.
6256 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
6258 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
6260 if ( liveEvents
[i
] == this )
6262 liveEvents
.erase(liveEvents
.begin() + i
);
6269 // -----------------------------------------------------------------------
6271 wxEvent
* wxPropertyGridEvent::Clone() const
6273 return new wxPropertyGridEvent( *this );
6276 // -----------------------------------------------------------------------
6277 // wxPropertyGridPopulator
6278 // -----------------------------------------------------------------------
6280 wxPropertyGridPopulator::wxPropertyGridPopulator()
6284 wxPGGlobalVars
->m_offline
++;
6287 // -----------------------------------------------------------------------
6289 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6292 m_propHierarchy
.clear();
6295 // -----------------------------------------------------------------------
6297 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6303 // -----------------------------------------------------------------------
6305 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6308 // Free unused sets of choices
6309 wxPGHashMapS2P::iterator it
;
6311 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6313 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6320 m_pg
->GetPanel()->Refresh();
6322 wxPGGlobalVars
->m_offline
--;
6325 // -----------------------------------------------------------------------
6327 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6328 const wxString
& propLabel
,
6329 const wxString
& propName
,
6330 const wxString
* propValue
,
6331 wxPGChoices
* pChoices
)
6333 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6334 wxPGProperty
* parent
= GetCurParent();
6336 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6338 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6342 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6344 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6348 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6350 property
->SetLabel(propLabel
);
6351 property
->DoSetName(propName
);
6353 if ( pChoices
&& pChoices
->IsOk() )
6354 property
->SetChoices(*pChoices
);
6356 m_state
->DoInsert(parent
, -1, property
);
6359 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
6360 wxPG_PROGRAMMATIC_VALUE
);
6365 // -----------------------------------------------------------------------
6367 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6369 m_propHierarchy
.push_back(property
);
6370 DoScanForChildren();
6371 m_propHierarchy
.pop_back();
6374 // -----------------------------------------------------------------------
6376 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6377 const wxString
& idString
)
6379 wxPGChoices choices
;
6382 if ( choicesString
[0] == wxT('@') )
6384 wxString ids
= choicesString
.substr(1);
6385 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6386 if ( it
== m_dictIdChoices
.end() )
6387 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6389 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6394 if ( idString
.length() )
6396 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6397 if ( it
!= m_dictIdChoices
.end() )
6399 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6406 // Parse choices string
6407 wxString::const_iterator it
= choicesString
.begin();
6411 bool labelValid
= false;
6413 for ( ; it
!= choicesString
.end(); ++it
)
6419 if ( c
== wxT('"') )
6424 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6425 choices
.Add(label
, l
);
6428 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6433 else if ( c
== wxT('=') )
6440 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6447 if ( c
== wxT('"') )
6460 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6461 choices
.Add(label
, l
);
6464 if ( !choices
.IsOk() )
6466 choices
.EnsureData();
6470 if ( idString
.length() )
6471 m_dictIdChoices
[idString
] = choices
.GetData();
6478 // -----------------------------------------------------------------------
6480 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6482 if ( s
.Last() == wxT('%') )
6484 wxString s2
= s
.substr(0,s
.length()-1);
6486 if ( s2
.ToLong(&val
, 10) )
6488 *pval
= (val
*max
)/100;
6494 return s
.ToLong(pval
, 10);
6497 // -----------------------------------------------------------------------
6499 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6500 const wxString
& type
,
6501 const wxString
& value
)
6503 int l
= m_propHierarchy
.size();
6507 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6508 wxString valuel
= value
.Lower();
6511 if ( type
.length() == 0 )
6516 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6518 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6520 else if ( value
.ToLong(&v
, 0) )
6527 if ( type
== wxT("string") )
6531 else if ( type
== wxT("int") )
6534 value
.ToLong(&v
, 0);
6537 else if ( type
== wxT("bool") )
6539 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6546 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6551 p
->SetAttribute( name
, variant
);
6556 // -----------------------------------------------------------------------
6558 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6560 wxLogError(_("Error in resource: %s"),msg
.c_str());
6563 // -----------------------------------------------------------------------
6565 #endif // wxUSE_PROPGRID