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
, wxControl
)
251 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxControl
)
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()
274 : wxControl(), wxScrollHelper(this)
279 // -----------------------------------------------------------------------
281 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
286 const wxString
& name
)
287 : wxControl(), wxScrollHelper(this)
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 wxControl::Create(parent
, id
, pos
, size
,
315 style
| wxScrolledWindowStyle
,
324 // -----------------------------------------------------------------------
327 // Initialize values to defaults
329 void wxPropertyGrid::Init1()
331 // Register editor classes, if necessary.
332 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
333 wxPropertyGrid::RegisterDefaultEditors();
335 m_validatingEditor
= 0;
338 m_wndEditor
= m_wndEditor2
= NULL
;
342 m_labelEditor
= NULL
;
343 m_labelEditorProperty
= NULL
;
344 m_eventObject
= this;
346 m_processedEvent
= NULL
;
347 m_sortFunction
= NULL
;
348 m_inDoPropertyChanged
= false;
349 m_inCommitChangesFromEditor
= false;
350 m_inDoSelectProperty
= false;
351 m_inOnValidationFailure
= false;
352 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
357 // Set up default unspecified value 'colour'
358 m_unspecifiedAppearance
.SetFgCol(*wxLIGHT_GREY
);
361 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
362 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
363 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
364 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
365 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
366 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
367 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
368 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
369 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
371 m_coloursCustomized
= 0;
374 #if wxPG_DOUBLE_BUFFER
375 m_doubleBuffer
= NULL
;
378 #ifndef wxPG_ICON_WIDTH
384 m_iconWidth
= wxPG_ICON_WIDTH
;
389 m_gutterWidth
= wxPG_GUTTER_MIN
;
390 m_subgroup_extramargin
= 10;
394 m_width
= m_height
= 0;
396 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
399 m_chgInfo_changedProperty
= NULL
;
402 // -----------------------------------------------------------------------
405 // Initialize after parent etc. set
407 void wxPropertyGrid::Init2()
409 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
412 // Smaller controls on Mac
413 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
416 // Now create state, if one didn't exist already
417 // (wxPropertyGridManager might have created it for us).
420 m_pState
= CreateState();
421 m_pState
->m_pPropGrid
= this;
422 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
425 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
426 m_pState
->m_dontCenterSplitter
= true;
428 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
430 m_pState
->InitNonCatMode();
432 m_pState
->m_properties
= m_pState
->m_abcArray
;
435 GetClientSize(&m_width
,&m_height
);
437 #ifndef wxPG_ICON_WIDTH
438 // create two bitmap nodes for drawing
439 m_expandbmp
= new wxBitmap(expand_xpm
);
440 m_collbmp
= new wxBitmap(collapse_xpm
);
442 // calculate average font height for bitmap centering
444 m_iconWidth
= m_expandbmp
->GetWidth();
445 m_iconHeight
= m_expandbmp
->GetHeight();
448 m_curcursor
= wxCURSOR_ARROW
;
449 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
451 // adjust bitmap icon y position so they are centered
452 m_vspacing
= wxPG_DEFAULT_VSPACING
;
454 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
456 // Allocate cell datas
457 m_propertyDefaultCell
.SetEmptyData();
458 m_categoryDefaultCell
.SetEmptyData();
462 // This helps with flicker
463 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
465 // Hook the top-level parent
470 // set virtual size to this window size
471 wxSize wndsize
= GetSize();
472 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
474 m_timeCreated
= ::wxGetLocalTimeMillis();
476 m_iFlags
|= wxPG_FL_INITIALIZED
;
478 m_ncWidth
= wndsize
.GetWidth();
480 // Need to call OnResize handler or size given in constructor/Create
482 wxSizeEvent
sizeEvent(wndsize
,0);
486 // -----------------------------------------------------------------------
488 wxPropertyGrid::~wxPropertyGrid()
493 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
497 // Remove grid and property pointers from live wxPropertyGridEvents.
498 for ( i
=0; i
<m_liveEvents
.size(); i
++ )
500 wxPropertyGridEvent
* evt
= m_liveEvents
[i
];
501 evt
->SetPropertyGrid(NULL
);
502 evt
->SetProperty(NULL
);
504 m_liveEvents
.clear();
506 if ( m_processedEvent
)
508 // All right... we are being deleted while wxPropertyGrid event
509 // is being sent. Make sure that event propagates as little
510 // as possible (although usually this is not enough to prevent
512 m_processedEvent
->Skip(false);
513 m_processedEvent
->StopPropagation();
515 // Let's use wxMessageBox to make the message appear more
516 // reliably (and *before* the crash can happen).
517 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
518 "generated by it. This usually leads to a crash "
519 "so it is recommended to destroy the control "
520 "at idle time instead.");
523 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
525 // This should do prevent things from going too badly wrong
526 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
528 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
531 // Call with NULL to disconnect event handling
532 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
536 wxASSERT_MSG( !IsEditorsValueModified(),
537 wxS("Most recent change in property editor was ")
538 wxS("lost!!! (if you don't want this to happen, ")
539 wxS("close your frames and dialogs using ")
540 wxS("Close(false).)") );
543 #if wxPG_DOUBLE_BUFFER
544 if ( m_doubleBuffer
)
545 delete m_doubleBuffer
;
548 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
551 delete m_cursorSizeWE
;
553 #ifndef wxPG_ICON_WIDTH
558 // Delete common value records
559 for ( i
=0; i
<m_commonValues
.size(); i
++ )
561 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
562 wxPGCommonValue
* value
= m_commonValues
[i
];
567 // -----------------------------------------------------------------------
569 bool wxPropertyGrid::Destroy()
571 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
574 return wxControl::Destroy();
577 // -----------------------------------------------------------------------
579 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
581 return new wxPropertyGridPageState();
584 // -----------------------------------------------------------------------
585 // wxPropertyGrid overridden wxWindow methods
586 // -----------------------------------------------------------------------
588 void wxPropertyGrid::SetWindowStyleFlag( long style
)
590 long old_style
= m_windowStyle
;
592 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
594 wxASSERT( m_pState
);
596 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
599 EnableCategories( true );
601 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
603 // Disable categories
604 EnableCategories( false );
606 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
612 PrepareAfterItemsAdded();
614 m_pState
->m_itemsAdded
= 1;
616 #if wxPG_SUPPORT_TOOLTIPS
617 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
623 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
624 SetToolTip ( tooltip );
625 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
628 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
638 wxControl::SetWindowStyleFlag ( style
);
640 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
642 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
644 CalculateFontAndBitmapStuff( m_vspacing
);
650 // -----------------------------------------------------------------------
652 void wxPropertyGrid::Freeze()
661 // -----------------------------------------------------------------------
663 void wxPropertyGrid::Thaw()
670 RecalculateVirtualSize();
671 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
675 // Force property re-selection
676 // NB: We must copy the selection.
677 wxArrayPGProperty selection
= m_pState
->m_selection
;
678 DoSetSelection(selection
, wxPG_SEL_FORCE
| wxPG_SEL_NONVISIBLE
);
682 // -----------------------------------------------------------------------
684 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
686 wxCHECK( prop
, false );
688 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
689 return DoSelectProperty(prop
, selFlags
);
691 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
693 if ( !selection
.size() )
695 return DoSelectProperty(prop
, selFlags
);
699 // For categories, only one can be selected at a time
700 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
703 selection
.push_back(prop
);
705 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
707 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
716 // -----------------------------------------------------------------------
718 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
720 wxCHECK( prop
, false );
723 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
724 if ( selection
.size() <= 1 )
726 res
= DoSelectProperty(NULL
, selFlags
);
730 m_pState
->DoRemoveFromSelection(prop
);
738 // -----------------------------------------------------------------------
740 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
741 unsigned int colIndex
,
742 unsigned int selFlags
)
745 // NB: Enable following if label editor background colour is
746 // ever changed to any other than m_colSelBack.
748 // We use this workaround to prevent visible flicker when editing
749 // a cell. Atleast on wxMSW, there is a difficult to find
750 // (and perhaps prevent) redraw somewhere between making property
751 // selected and enabling label editing.
753 //wxColour prevColSelBack = m_colSelBack;
754 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
760 res
= DoSelectProperty(prop
, selFlags
);
765 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
767 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
769 res
= DoAddToSelection(prop
, selFlags
);
773 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
775 DoBeginLabelEdit(colIndex
, selFlags
);
779 //m_colSelBack = prevColSelBack;
783 // -----------------------------------------------------------------------
785 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
786 unsigned int colIndex
,
787 wxMouseEvent
* mouseEvent
,
790 const wxArrayPGProperty
& selection
= GetSelectedProperties();
791 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
794 // Set to 2 if also add all items in between
795 int addToExistingSelection
= 0;
797 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
801 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
802 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
804 // Allow right-click for context menu without
805 // disturbing the selection.
806 if ( GetSelectedProperties().size() <= 1 ||
808 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
813 if ( mouseEvent
->ControlDown() )
815 addToExistingSelection
= 1;
817 else if ( mouseEvent
->ShiftDown() )
819 if ( selection
.size() > 0 && !prop
->IsCategory() )
820 addToExistingSelection
= 2;
822 addToExistingSelection
= 1;
828 if ( addToExistingSelection
== 1 )
831 if ( !alreadySelected
)
833 res
= DoAddToSelection(prop
, selFlags
);
835 else if ( GetSelectedProperties().size() > 1 )
837 res
= DoRemoveFromSelection(prop
, selFlags
);
840 else if ( addToExistingSelection
== 2 )
842 // Add this, and all in between
844 // Find top selected property
845 wxPGProperty
* topSelProp
= selection
[0];
846 int topSelPropY
= topSelProp
->GetY();
847 for ( unsigned int i
=1; i
<selection
.size(); i
++ )
849 wxPGProperty
* p
= selection
[i
];
851 if ( y
< topSelPropY
)
858 wxPGProperty
* startFrom
;
859 wxPGProperty
* stopAt
;
861 if ( prop
->GetY() <= topSelPropY
)
863 // Property is above selection (or same)
869 // Property is below selection
870 startFrom
= topSelProp
;
874 // Iterate through properties in-between, and select them
875 wxPropertyGridIterator it
;
877 for ( it
= GetIterator(wxPG_ITERATE_VISIBLE
, startFrom
);
881 wxPGProperty
* p
= *it
;
883 if ( !p
->IsCategory() &&
884 !m_pState
->DoIsPropertySelected(p
) )
886 DoAddToSelection(p
, selFlags
);
895 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
901 // -----------------------------------------------------------------------
903 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
906 if ( newSelection
.size() > 0 )
908 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
913 DoClearSelection(false, selFlags
);
916 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
918 DoAddToSelection(newSelection
[i
], selFlags
);
924 // -----------------------------------------------------------------------
926 void wxPropertyGrid::MakeColumnEditable( unsigned int column
,
929 wxASSERT( column
!= 1 );
931 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
935 cols
.push_back(column
);
939 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
941 if ( cols
[i
] == (int)column
)
942 cols
.erase( cols
.begin() + i
);
947 // -----------------------------------------------------------------------
949 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
952 wxPGProperty
* selected
= GetSelection();
953 wxCHECK_RET(selected
, wxT("No property selected"));
954 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
956 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
958 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
965 const wxPGCell
* cell
= NULL
;
966 if ( selected
->HasCell(colIndex
) )
968 cell
= &selected
->GetCell(colIndex
);
969 if ( !cell
->HasText() && colIndex
== 0 )
970 text
= selected
->GetLabel();
976 text
= selected
->GetLabel();
978 cell
= &selected
->GetOrCreateCell(colIndex
);
981 if ( cell
&& cell
->HasText() )
982 text
= cell
->GetText();
984 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
986 m_selColumn
= colIndex
;
988 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
990 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
998 wxWindowID id
= tc
->GetId();
999 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1000 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
1002 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1003 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
1008 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1009 m_labelEditorProperty
= selected
;
1012 // -----------------------------------------------------------------------
1015 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1017 DoEndLabelEdit(true);
1020 // -----------------------------------------------------------------------
1022 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1024 int keycode
= event
.GetKeyCode();
1026 if ( keycode
== WXK_ESCAPE
)
1028 DoEndLabelEdit(false);
1032 HandleKeyEvent(event
, true);
1036 // -----------------------------------------------------------------------
1038 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1040 if ( !m_labelEditor
)
1043 wxPGProperty
* prop
= m_labelEditorProperty
;
1048 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1050 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1051 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1052 prop
, NULL
, selFlags
,
1057 wxString text
= m_labelEditor
->GetValue();
1058 wxPGCell
* cell
= NULL
;
1059 if ( prop
->HasCell(m_selColumn
) )
1061 cell
= &prop
->GetCell(m_selColumn
);
1065 if ( m_selColumn
== 0 )
1066 prop
->SetLabel(text
);
1068 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1072 cell
->SetText(text
);
1076 int wasFocused
= m_iFlags
& wxPG_FL_FOCUSED
;
1078 DestroyEditorWnd(m_labelEditor
);
1080 m_labelEditor
= NULL
;
1081 m_labelEditorProperty
= NULL
;
1083 // Fix focus (needed at least on wxGTK)
1090 // -----------------------------------------------------------------------
1092 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1094 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1095 OnTLPChanging(::wxGetTopLevelParent(this));
1097 OnTLPChanging(NULL
);
1099 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1101 #if defined(__WXMSW__)
1104 // Don't use WS_EX_COMPOSITED just now.
1107 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1108 hWnd = (HWND)GetParent()->GetHWND();
1110 hWnd = (HWND)GetHWND();
1112 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1113 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1116 //#elif defined(__WXGTK20__)
1118 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1119 // truly was double-buffered.
1120 if ( !this->IsDoubleBuffered() )
1122 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1126 #if wxPG_DOUBLE_BUFFER
1127 wxDELETE(m_doubleBuffer
);
1132 wxControl::SetExtraStyle( exStyle
);
1134 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1135 m_pState
->InitNonCatMode();
1137 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1138 m_windowStyle
|= wxPG_TOOLTIPS
;
1141 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1144 // -----------------------------------------------------------------------
1146 // returns the best acceptable minimal size
1147 wxSize
wxPropertyGrid::DoGetBestSize() const
1149 int lineHeight
= wxMax(15, m_lineHeight
);
1151 // don't make the grid too tall (limit height to 10 items) but don't
1152 // make it too small neither
1153 int numLines
= wxMin
1155 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1159 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1160 int width
= m_marginWidth
;
1161 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1163 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1166 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1172 // -----------------------------------------------------------------------
1174 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1176 if ( newTLP
== m_tlp
)
1179 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1182 // Parent changed so let's redetermine and re-hook the
1183 // correct top-level window.
1186 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1187 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1189 m_tlpClosed
= m_tlp
;
1190 m_tlpClosedTime
= currentTime
;
1195 // Only accept new tlp if same one was not just dismissed.
1196 if ( newTLP
!= m_tlpClosed
||
1197 m_tlpClosedTime
+250 < currentTime
)
1199 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1200 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1213 // -----------------------------------------------------------------------
1215 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1217 // ClearSelection forces value validation/commit.
1218 if ( event
.CanVeto() && !DoClearSelection() )
1224 // Ok, it can close, set tlp pointer to NULL. Some other event
1225 // handler can of course veto the close, but our OnIdle() should
1226 // then be able to regain the tlp pointer.
1227 OnTLPChanging(NULL
);
1232 // -----------------------------------------------------------------------
1234 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1236 OnTLPChanging((wxWindow
*)newParent
);
1238 bool res
= wxControl::Reparent(newParent
);
1243 // -----------------------------------------------------------------------
1244 // wxPropertyGrid Font and Colour Methods
1245 // -----------------------------------------------------------------------
1247 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1251 m_captionFont
= wxControl::GetFont();
1253 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1254 m_subgroup_extramargin
= x
+ (x
/2);
1257 #if wxPG_USE_RENDERER_NATIVE
1258 m_iconWidth
= wxPG_ICON_WIDTH
;
1259 #elif wxPG_ICON_WIDTH
1261 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1262 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1263 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1267 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1268 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1269 m_gutterWidth
= wxPG_GUTTER_MIN
;
1272 if ( vspacing
<= 1 ) vdiv
= 12;
1273 else if ( vspacing
>= 3 ) vdiv
= 3;
1275 m_spacingy
= m_fontHeight
/ vdiv
;
1276 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1277 m_spacingy
= wxPG_YSPACING_MIN
;
1280 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1281 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1283 m_captionFont
.SetWeight(wxBOLD
);
1284 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1286 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1289 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1290 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1293 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1295 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1296 RecalculateVirtualSize();
1298 InvalidateBestSize();
1301 // -----------------------------------------------------------------------
1303 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1309 // -----------------------------------------------------------------------
1311 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1312 int ga
= 1000, int ba
= 1000,
1313 bool forceDifferent
= false)
1320 // Recursion guard (allow 2 max)
1321 static int isinside
= 0;
1323 wxCHECK_MSG( isinside
< 3,
1325 wxT("wxPGAdjustColour should not be recursively called more than once") );
1330 int g
= src
.Green();
1333 if ( r2
>255 ) r2
= 255;
1334 else if ( r2
<0) r2
= 0;
1336 if ( g2
>255 ) g2
= 255;
1337 else if ( g2
<0) g2
= 0;
1339 if ( b2
>255 ) b2
= 255;
1340 else if ( b2
<0) b2
= 0;
1342 // Make sure they are somewhat different
1343 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1344 dst
= wxPGAdjustColour(src
,-(ra
*2));
1346 dst
= wxColour(r2
,g2
,b2
);
1348 // Recursion guard (allow 2 max)
1355 static int wxPGGetColAvg( const wxColour
& col
)
1357 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1361 void wxPropertyGrid::RegainColours()
1363 if ( !(m_coloursCustomized
& 0x0002) )
1365 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1367 // Make sure colour is dark enough
1369 int colDec
= wxPGGetColAvg(col
) - 230;
1371 int colDec
= wxPGGetColAvg(col
) - 200;
1374 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1377 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1380 if ( !(m_coloursCustomized
& 0x0001) )
1381 m_colMargin
= m_colCapBack
;
1383 if ( !(m_coloursCustomized
& 0x0004) )
1390 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1391 m_colCapFore
= capForeCol
;
1392 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1395 if ( !(m_coloursCustomized
& 0x0008) )
1397 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1398 m_colPropBack
= bgCol
;
1399 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1400 if ( !m_unspecifiedAppearance
.GetBgCol().IsOk() )
1401 m_unspecifiedAppearance
.SetBgCol(bgCol
);
1404 if ( !(m_coloursCustomized
& 0x0010) )
1406 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1407 m_colPropFore
= fgCol
;
1408 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1409 if ( !m_unspecifiedAppearance
.GetFgCol().IsOk() )
1410 m_unspecifiedAppearance
.SetFgCol(fgCol
);
1413 if ( !(m_coloursCustomized
& 0x0020) )
1414 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1416 if ( !(m_coloursCustomized
& 0x0040) )
1417 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1419 if ( !(m_coloursCustomized
& 0x0080) )
1420 m_colLine
= m_colCapBack
;
1422 if ( !(m_coloursCustomized
& 0x0100) )
1423 m_colDisPropFore
= m_colCapFore
;
1425 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1428 // -----------------------------------------------------------------------
1430 void wxPropertyGrid::ResetColours()
1432 m_coloursCustomized
= 0;
1439 // -----------------------------------------------------------------------
1441 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1443 // Must disable active editor.
1446 bool res
= wxControl::SetFont( font
);
1447 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1449 CalculateFontAndBitmapStuff( m_vspacing
);
1456 // -----------------------------------------------------------------------
1458 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1461 m_coloursCustomized
|= 0x80;
1465 // -----------------------------------------------------------------------
1467 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1470 m_coloursCustomized
|= 0x01;
1474 // -----------------------------------------------------------------------
1476 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1478 m_colPropBack
= col
;
1479 m_coloursCustomized
|= 0x08;
1481 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1482 m_unspecifiedAppearance
.SetBgCol(col
);
1487 // -----------------------------------------------------------------------
1489 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1491 m_colPropFore
= col
;
1492 m_coloursCustomized
|= 0x10;
1494 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1495 m_unspecifiedAppearance
.SetFgCol(col
);
1500 // -----------------------------------------------------------------------
1502 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1504 m_colEmptySpace
= col
;
1509 // -----------------------------------------------------------------------
1511 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1513 m_colDisPropFore
= col
;
1514 m_coloursCustomized
|= 0x100;
1518 // -----------------------------------------------------------------------
1520 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1523 m_coloursCustomized
|= 0x20;
1527 // -----------------------------------------------------------------------
1529 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1532 m_coloursCustomized
|= 0x40;
1536 // -----------------------------------------------------------------------
1538 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1541 m_coloursCustomized
|= 0x02;
1543 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1548 // -----------------------------------------------------------------------
1550 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1553 m_coloursCustomized
|= 0x04;
1555 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1560 // -----------------------------------------------------------------------
1561 // wxPropertyGrid property adding and removal
1562 // -----------------------------------------------------------------------
1564 void wxPropertyGrid::PrepareAfterItemsAdded()
1566 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1568 m_pState
->m_itemsAdded
= 0;
1570 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1571 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1573 RecalculateVirtualSize();
1575 // Fix editor position
1576 CorrectEditorWidgetPosY();
1579 // -----------------------------------------------------------------------
1580 // wxPropertyGrid property operations
1581 // -----------------------------------------------------------------------
1583 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1585 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1589 bool changed
= false;
1591 // Is it inside collapsed section?
1592 if ( !p
->IsVisible() )
1595 wxPGProperty
* parent
= p
->GetParent();
1596 wxPGProperty
* grandparent
= parent
->GetParent();
1598 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1599 Expand( grandparent
);
1607 GetViewStart(&vx
,&vy
);
1608 vy
*=wxPG_PIXELS_PER_UNIT
;
1614 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1615 m_iFlags
|= wxPG_FL_SCROLLED
;
1618 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1620 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1621 m_iFlags
|= wxPG_FL_SCROLLED
;
1631 // -----------------------------------------------------------------------
1632 // wxPropertyGrid helper methods called by properties
1633 // -----------------------------------------------------------------------
1635 // Control font changer helper.
1636 void wxPropertyGrid::SetCurControlBoldFont()
1638 wxWindow
* editor
= GetEditorControl();
1639 editor
->SetFont( m_captionFont
);
1642 // -----------------------------------------------------------------------
1644 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1647 #if wxPG_SMALL_SCREEN
1648 // On small-screen devices, always show dialogs with default position and size.
1649 return wxDefaultPosition
;
1651 int splitterX
= GetSplitterPosition();
1655 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1657 ImprovedClientToScreen( &x
, &y
);
1659 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1660 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1667 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1677 new_y
= y
+ m_lineHeight
;
1679 return wxPoint(new_x
,new_y
);
1683 // -----------------------------------------------------------------------
1685 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1687 if ( src_str
.length() == 0 )
1693 bool prev_is_slash
= false;
1695 wxString::const_iterator i
= src_str
.begin();
1699 for ( ; i
!= src_str
.end(); ++i
)
1703 if ( a
!= wxS('\\') )
1705 if ( !prev_is_slash
)
1711 if ( a
== wxS('n') )
1714 dst_str
<< wxS('\n');
1716 dst_str
<< wxS('\n');
1719 else if ( a
== wxS('t') )
1720 dst_str
<< wxS('\t');
1724 prev_is_slash
= false;
1728 if ( prev_is_slash
)
1730 dst_str
<< wxS('\\');
1731 prev_is_slash
= false;
1735 prev_is_slash
= true;
1742 // -----------------------------------------------------------------------
1744 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1746 if ( src_str
.length() == 0 )
1752 wxString::const_iterator i
= src_str
.begin();
1753 wxUniChar prev_a
= wxS('\0');
1757 for ( ; i
!= src_str
.end(); ++i
)
1761 if ( a
>= wxS(' ') )
1763 // This surely is not something that requires an escape sequence.
1768 // This might need...
1769 if ( a
== wxS('\r') )
1771 // DOS style line end.
1772 // Already taken care below
1774 else if ( a
== wxS('\n') )
1775 // UNIX style line end.
1776 dst_str
<< wxS("\\n");
1777 else if ( a
== wxS('\t') )
1779 dst_str
<< wxS('\t');
1782 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1792 // -----------------------------------------------------------------------
1794 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1801 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1804 // -----------------------------------------------------------------------
1805 // wxPropertyGrid graphics related methods
1806 // -----------------------------------------------------------------------
1808 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1813 // Don't paint after destruction has begun
1814 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1817 // Find out where the window is scrolled to
1818 int vx
,vy
; // Top left corner of client
1819 GetViewStart(&vx
,&vy
);
1820 vy
*= wxPG_PIXELS_PER_UNIT
;
1822 // Update everything inside the box
1823 wxRect r
= GetUpdateRegion().GetBox();
1827 // FIXME: This is just a workaround for a bug that causes splitters not
1828 // to paint when other windows are being dragged over the grid.
1830 r
.width
= GetClientSize().x
;
1833 r
.height
= GetClientSize().y
;
1835 // Repaint this rectangle
1836 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1838 // We assume that the size set when grid is shown
1839 // is what is desired.
1840 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1843 // -----------------------------------------------------------------------
1845 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1846 wxPGProperty
* property
) const
1848 // Prepare rectangle to be used
1850 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1851 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1853 #if (wxPG_USE_RENDERER_NATIVE)
1855 #elif wxPG_ICON_WIDTH
1856 // Drawing expand/collapse button manually
1857 dc
.SetPen(m_colPropFore
);
1858 if ( property
->IsCategory() )
1859 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1861 dc
.SetBrush(m_colPropBack
);
1863 dc
.DrawRectangle( r
);
1864 int _y
= r
.y
+(m_iconWidth
/2);
1865 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1870 if ( property
->IsExpanded() )
1872 // wxRenderer functions are non-mutating in nature, so it
1873 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1874 // Hopefully this does not cause problems.
1875 #if (wxPG_USE_RENDERER_NATIVE)
1876 wxRendererNative::Get().DrawTreeItemButton(
1882 #elif wxPG_ICON_WIDTH
1891 #if (wxPG_USE_RENDERER_NATIVE)
1892 wxRendererNative::Get().DrawTreeItemButton(
1898 #elif wxPG_ICON_WIDTH
1899 int _x
= r
.x
+(m_iconWidth
/2);
1900 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1906 #if (wxPG_USE_RENDERER_NATIVE)
1908 #elif wxPG_ICON_WIDTH
1911 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1915 // -----------------------------------------------------------------------
1918 // This is the one called by OnPaint event handler and others.
1919 // topy and bottomy are already unscrolled (ie. physical)
1921 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1922 unsigned int topItemY
,
1923 unsigned int bottomItemY
,
1924 const wxRect
* itemsRect
)
1928 bottomItemY
< topItemY
||
1932 m_pState
->EnsureVirtualHeight();
1934 wxRect tempItemsRect
;
1937 tempItemsRect
= wxRect(0, topItemY
,
1940 itemsRect
= &tempItemsRect
;
1944 GetViewStart(&vx
, &vy
);
1945 vx
*= wxPG_PIXELS_PER_UNIT
;
1946 vy
*= wxPG_PIXELS_PER_UNIT
;
1948 // itemRect is in virtual grid space
1949 wxRect
drawRect(itemsRect
->x
- vx
,
1954 // items added check
1955 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1957 int paintFinishY
= 0;
1959 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1962 bool isBuffered
= false;
1964 #if wxPG_DOUBLE_BUFFER
1965 wxMemoryDC
* bufferDC
= NULL
;
1967 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1969 if ( !m_doubleBuffer
)
1971 paintFinishY
= itemsRect
->y
;
1976 bufferDC
= new wxMemoryDC();
1978 // If nothing was changed, then just copy from double-buffer
1979 bufferDC
->SelectObject( *m_doubleBuffer
);
1989 // paintFinishY and drawBottomY are in buffer/physical space
1990 paintFinishY
= DoDrawItems( *dcPtr
, itemsRect
, isBuffered
);
1991 int drawBottomY
= itemsRect
->y
+ itemsRect
->height
- vy
;
1993 // Clear area beyond last painted property
1994 if ( paintFinishY
< drawBottomY
)
1996 dcPtr
->SetPen(m_colEmptySpace
);
1997 dcPtr
->SetBrush(m_colEmptySpace
);
1998 dcPtr
->DrawRectangle(0, paintFinishY
,
2004 #if wxPG_DOUBLE_BUFFER
2007 dc
.Blit( drawRect
.x
, drawRect
.y
, drawRect
.width
,
2009 bufferDC
, 0, 0, wxCOPY
);
2016 // Just clear the area
2017 dc
.SetPen(m_colEmptySpace
);
2018 dc
.SetBrush(m_colEmptySpace
);
2019 dc
.DrawRectangle(drawRect
);
2023 // -----------------------------------------------------------------------
2025 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
2026 const wxRect
* itemsRect
,
2027 bool isBuffered
) const
2029 const wxPGProperty
* firstItem
;
2030 const wxPGProperty
* lastItem
;
2032 firstItem
= DoGetItemAtY(itemsRect
->y
);
2033 lastItem
= DoGetItemAtY(itemsRect
->y
+itemsRect
->height
-1);
2036 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
2038 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
2039 return itemsRect
->y
;
2041 wxCHECK_MSG( !m_pState
->m_itemsAdded
, itemsRect
->y
,
2043 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2045 int lh
= m_lineHeight
;
2048 int lastItemBottomY
;
2050 firstItemTopY
= itemsRect
->y
;
2051 lastItemBottomY
= itemsRect
->y
+ itemsRect
->height
;
2053 // Align y coordinates to item boundaries
2054 firstItemTopY
-= firstItemTopY
% lh
;
2055 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2056 lastItemBottomY
-= 1;
2058 // Entire range outside scrolled, visible area?
2059 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
2060 lastItemBottomY
<= 0 )
2061 return itemsRect
->y
;
2063 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
2065 "invalid y values" );
2068 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
2069 "height=%i (ch=%i), itemsRect = 0x%lX )",
2070 firstItem->GetLabel().c_str(),
2071 lastItem->GetLabel().c_str(),
2072 (int)(lastItemBottomY - firstItemTopY),
2074 (unsigned long)&itemsRect );
2079 long windowStyle
= m_windowStyle
;
2084 // With wxPG_DOUBLE_BUFFER, do double buffering
2085 // - buffer's y = 0, so align itemsRect and coordinates to that
2087 #if wxPG_DOUBLE_BUFFER
2094 xRelMod
= itemsRect
->x
;
2095 yRelMod
= itemsRect
->y
;
2098 // itemsRect conversion
2103 firstItemTopY
-= yRelMod
;
2104 lastItemBottomY
-= yRelMod
;
2107 wxUnusedVar(isBuffered
);
2110 int x
= m_marginWidth
- xRelMod
;
2112 wxFont normalFont
= GetFont();
2114 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2116 bool isPgEnabled
= IsEnabled();
2119 // Prepare some pens and brushes that are often changed to.
2122 wxBrush
marginBrush(m_colMargin
);
2123 wxPen
marginPen(m_colMargin
);
2124 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2125 wxPen
linepen(m_colLine
,1,wxSOLID
);
2127 wxColour selBackCol
;
2129 selBackCol
= m_colSelBack
;
2131 selBackCol
= m_colMargin
;
2133 // pen that has same colour as text
2134 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2137 // Clear margin with background colour
2139 dc
.SetBrush( marginBrush
);
2140 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2142 dc
.SetPen( *wxTRANSPARENT_PEN
);
2143 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2146 const wxPGProperty
* firstSelected
= GetSelection();
2147 const wxPropertyGridPageState
* state
= m_pState
;
2148 const wxArrayInt
& colWidths
= state
->m_colWidths
;
2150 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2151 bool wasSelectedPainted
= false;
2154 // TODO: Only render columns that are within clipping region.
2156 dc
.SetFont(normalFont
);
2158 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2159 int endScanBottomY
= lastItemBottomY
+ lh
;
2160 int y
= firstItemTopY
;
2163 // Pregenerate list of visible properties.
2164 wxArrayPGProperty visPropArray
;
2165 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2167 for ( ; !it
.AtEnd(); it
.Next() )
2169 const wxPGProperty
* p
= *it
;
2171 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2173 visPropArray
.push_back((wxPGProperty
*)p
);
2175 if ( y
> endScanBottomY
)
2182 visPropArray
.push_back(NULL
);
2184 wxPGProperty
* nextP
= visPropArray
[0];
2186 int gridWidth
= state
->m_width
;
2189 for ( unsigned int arrInd
=1;
2190 nextP
&& y
<= lastItemBottomY
;
2193 wxPGProperty
* p
= nextP
;
2194 nextP
= visPropArray
[arrInd
];
2196 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2197 int textMarginHere
= x
;
2198 int renderFlags
= 0;
2200 int greyDepth
= m_marginWidth
;
2201 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2202 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2204 int greyDepthX
= greyDepth
- xRelMod
;
2206 // Use basic depth if in non-categoric mode and parent is base array.
2207 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2209 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2212 // Paint margin area
2213 dc
.SetBrush(marginBrush
);
2214 dc
.SetPen(marginPen
);
2215 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2217 dc
.SetPen( linepen
);
2223 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2224 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2225 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2227 // Is this or its parent themed?
2228 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2229 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2230 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2232 bool suppressMarginEdge
= false;
2234 if (!suppressMarginEdge
)
2235 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2238 // Blank out the margin edge
2239 dc
.SetPen(wxPen(GetBackgroundColour()));
2240 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2241 dc
.SetPen( linepen
);
2248 for ( si
=0; si
<colWidths
.size(); si
++ )
2250 sx
+= colWidths
[si
];
2251 dc
.DrawLine( sx
, y
, sx
, y2
);
2254 // Horizontal Line, below
2255 // (not if both this and next is category caption)
2256 if ( p
->IsCategory() &&
2257 nextP
&& nextP
->IsCategory() )
2258 dc
.SetPen(m_colCapBack
);
2260 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2263 // Need to override row colours?
2267 bool isSelected
= state
->DoIsPropertySelected(p
);
2271 // Disabled may get different colour.
2272 if ( !p
->IsEnabled() )
2274 renderFlags
|= wxPGCellRenderer::Disabled
|
2275 wxPGCellRenderer::DontUseCellFgCol
;
2276 rowFgCol
= m_colDisPropFore
;
2281 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2282 if ( p
== firstSelected
)
2283 wasSelectedPainted
= true;
2286 renderFlags
|= wxPGCellRenderer::Selected
;
2288 if ( !p
->IsCategory() )
2290 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2291 wxPGCellRenderer::DontUseCellBgCol
;
2293 if ( reallyFocused
&& p
== firstSelected
)
2295 rowFgCol
= m_colSelFore
;
2296 rowBgCol
= selBackCol
;
2298 else if ( isPgEnabled
)
2300 rowFgCol
= m_colPropFore
;
2301 if ( p
== firstSelected
)
2302 rowBgCol
= m_colMargin
;
2304 rowBgCol
= selBackCol
;
2308 rowFgCol
= m_colDisPropFore
;
2309 rowBgCol
= selBackCol
;
2316 if ( rowBgCol
.IsOk() )
2317 rowBgBrush
= wxBrush(rowBgCol
);
2319 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2320 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2323 // Fill additional margin area with background colour of first cell
2324 if ( greyDepthX
< textMarginHere
)
2326 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2328 wxPGCell
& cell
= p
->GetCell(0);
2329 rowBgCol
= cell
.GetBgCol();
2330 rowBgBrush
= wxBrush(rowBgCol
);
2332 dc
.SetBrush(rowBgBrush
);
2333 dc
.SetPen(rowBgCol
);
2334 dc
.DrawRectangle(greyDepthX
+1, y
,
2335 textMarginHere
-greyDepthX
, lh
-1);
2338 bool fontChanged
= false;
2340 // Expander button rectangle
2341 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2346 // Default cell rect fill the entire row
2347 wxRect
cellRect(greyDepthX
, y
,
2348 gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2350 bool isCategory
= p
->IsCategory();
2354 dc
.SetFont(m_captionFont
);
2357 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2359 dc
.SetBrush(rowBgBrush
);
2360 dc
.SetPen(rowBgCol
);
2363 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2365 dc
.SetTextForeground(rowFgCol
);
2370 // Fine tune button rectangle to actually fit the cell
2371 if ( butRect
.x
> 0 )
2372 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2374 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&&
2375 (windowStyle
& wxPG_BOLD_MODIFIED
) )
2377 dc
.SetFont(m_captionFont
);
2381 // Magic fine-tuning for non-category rows
2385 int firstCellWidth
= colWidths
[0] - (greyDepthX
- m_marginWidth
);
2386 int firstCellX
= cellRect
.x
;
2388 // Calculate cellRect.x for the last cell
2389 unsigned int ci
= 0;
2391 for ( ci
=0; ci
<colWidths
.size(); ci
++ )
2392 cellX
+= colWidths
[ci
];
2395 // Draw cells from back to front so that we can easily tell if the
2396 // cell on the right was empty from text
2397 bool prevFilled
= true;
2398 ci
= colWidths
.size();
2407 textXAdd
= textMarginHere
- greyDepthX
;
2408 cellRect
.width
= firstCellWidth
;
2409 cellRect
.x
= firstCellX
;
2413 int colWidth
= colWidths
[ci
];
2414 cellRect
.width
= colWidth
;
2415 cellRect
.x
-= colWidth
;
2418 // Merge with column to the right?
2419 if ( !prevFilled
&& isCategory
)
2421 cellRect
.width
+= colWidths
[ci
+1];
2425 cellRect
.width
-= 1;
2427 wxWindow
* cellEditor
= NULL
;
2428 int cellRenderFlags
= renderFlags
;
2430 // Tree Item Button (must be drawn before clipping is set up)
2431 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2432 DrawExpanderButton( dc
, butRect
, p
);
2435 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2437 if ( p
== firstSelected
)
2439 if ( ci
== 1 && m_wndEditor
)
2440 cellEditor
= m_wndEditor
;
2441 else if ( ci
== m_selColumn
&& m_labelEditor
)
2442 cellEditor
= m_labelEditor
;
2447 wxColour editorBgCol
=
2448 cellEditor
->GetBackgroundColour();
2449 dc
.SetBrush(editorBgCol
);
2450 dc
.SetPen(editorBgCol
);
2451 dc
.SetTextForeground(m_colPropFore
);
2452 dc
.DrawRectangle(cellRect
);
2454 if ( m_dragStatus
!= 0 ||
2455 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2460 dc
.SetBrush(m_colPropBack
);
2461 dc
.SetPen(m_colPropBack
);
2462 if ( p
->IsEnabled() )
2463 dc
.SetTextForeground(m_colPropFore
);
2465 dc
.SetTextForeground(m_colDisPropFore
);
2470 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2472 dc
.SetBrush(rowBgBrush
);
2473 dc
.SetPen(rowBgCol
);
2476 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2478 dc
.SetTextForeground(rowFgCol
);
2482 dc
.SetClippingRegion(cellRect
);
2484 cellRect
.x
+= textXAdd
;
2485 cellRect
.width
-= textXAdd
;
2490 wxPGCellRenderer
* renderer
;
2491 int cmnVal
= p
->GetCommonValue();
2492 if ( cmnVal
== -1 || ci
!= 1 )
2494 renderer
= p
->GetCellRenderer(ci
);
2495 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2501 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2502 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2512 dc
.DestroyClippingRegion(); // Is this really necessary?
2517 dc
.SetFont(normalFont
);
2522 // Refresh editor controls (seems not needed on msw)
2523 // NOTE: This code is mandatory for GTK!
2524 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2525 if ( wasSelectedPainted
)
2528 m_wndEditor
->Refresh();
2530 m_wndEditor2
->Refresh();
2537 // -----------------------------------------------------------------------
2539 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2543 if ( m_width
< 10 || m_height
< 10 ||
2544 !m_pState
->m_properties
->GetChildCount() ||
2546 return wxRect(0,0,0,0);
2551 // Return rect which encloses the given property range
2552 // (in logical grid coordinates)
2555 int visTop
= p1
->GetY();
2558 visBottom
= p2
->GetY() + m_lineHeight
;
2560 visBottom
= m_height
+ visTop
;
2562 // If seleced property is inside the range, we'll extend the range to include
2564 wxPGProperty
* selected
= GetSelection();
2567 int selectedY
= selected
->GetY();
2568 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2570 wxWindow
* editor
= GetEditorControl();
2573 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2574 if ( visBottom2
> visBottom
)
2575 visBottom
= visBottom2
;
2580 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2583 // -----------------------------------------------------------------------
2585 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2590 if ( m_pState
->m_itemsAdded
)
2591 PrepareAfterItemsAdded();
2593 wxRect r
= GetPropertyRect(p1
, p2
);
2596 // Convert rectangle from logical grid coordinates to physical ones
2598 GetViewStart(&vx
, &vy
);
2599 vx
*= wxPG_PIXELS_PER_UNIT
;
2600 vy
*= wxPG_PIXELS_PER_UNIT
;
2607 // -----------------------------------------------------------------------
2609 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2611 if ( m_pState
->DoIsPropertySelected(p
) )
2613 // NB: We must copy the selection.
2614 wxArrayPGProperty selection
= m_pState
->m_selection
;
2615 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2618 DrawItemAndChildren(p
);
2621 // -----------------------------------------------------------------------
2623 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2628 // Draw item, children, and parent too, if it is not category
2629 wxPGProperty
* parent
= p
->GetParent();
2632 !parent
->IsCategory() &&
2633 parent
->GetParent() )
2636 parent
= parent
->GetParent();
2639 DrawItemAndChildren(p
);
2642 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2644 wxCHECK_RET( p
, wxT("invalid property id") );
2646 // Do not draw if in non-visible page
2647 if ( p
->GetParentState() != m_pState
)
2650 // do not draw a single item if multiple pending
2651 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2654 // Update child control.
2655 wxPGProperty
* selected
= GetSelection();
2656 if ( selected
&& selected
->GetParent() == p
)
2659 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2661 DrawItems(p
, lastDrawn
);
2664 // -----------------------------------------------------------------------
2666 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2667 const wxRect
*rect
)
2669 PrepareAfterItemsAdded();
2671 wxWindow::Refresh(false, rect
);
2673 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2674 // I think this really helps only GTK+1.2
2675 if ( m_wndEditor
) m_wndEditor
->Refresh();
2676 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2680 // -----------------------------------------------------------------------
2681 // wxPropertyGrid global operations
2682 // -----------------------------------------------------------------------
2684 void wxPropertyGrid::Clear()
2686 m_pState
->DoClear();
2692 RecalculateVirtualSize();
2694 // Need to clear some area at the end
2696 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2699 // -----------------------------------------------------------------------
2701 bool wxPropertyGrid::EnableCategories( bool enable
)
2708 // Enable categories
2711 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2716 // Disable categories
2718 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2721 if ( !m_pState
->EnableCategories(enable
) )
2726 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2728 m_pState
->m_itemsAdded
= 1; // force
2729 PrepareAfterItemsAdded();
2733 m_pState
->m_itemsAdded
= 1;
2735 // No need for RecalculateVirtualSize() here - it is already called in
2736 // wxPropertyGridPageState method above.
2743 // -----------------------------------------------------------------------
2745 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2747 wxASSERT( pNewState
);
2748 wxASSERT( pNewState
->GetGrid() );
2750 if ( pNewState
== m_pState
)
2753 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2755 // Call ClearSelection() instead of DoClearSelection()
2756 // so that selection clear events are not sent.
2759 m_pState
->m_selection
= oldSelection
;
2761 bool orig_mode
= m_pState
->IsInNonCatMode();
2762 bool new_state_mode
= pNewState
->IsInNonCatMode();
2764 m_pState
= pNewState
;
2767 int pgWidth
= GetClientSize().x
;
2768 if ( HasVirtualWidth() )
2770 int minWidth
= pgWidth
;
2771 if ( pNewState
->m_width
< minWidth
)
2773 pNewState
->m_width
= minWidth
;
2774 pNewState
->CheckColumnWidths();
2780 // Just in case, fully re-center splitter
2781 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2782 // pNewState->m_fSplitterX = -1.0;
2784 pNewState
->OnClientWidthChange(pgWidth
,
2785 pgWidth
- pNewState
->m_width
);
2790 // If necessary, convert state to correct mode.
2791 if ( orig_mode
!= new_state_mode
)
2793 // This should refresh as well.
2794 EnableCategories( orig_mode
?false:true );
2796 else if ( !m_frozen
)
2798 // Refresh, if not frozen.
2799 m_pState
->PrepareAfterItemsAdded();
2801 // Reselect (Use SetSelection() instead of Do-variant so that
2802 // events won't be sent).
2803 SetSelection(m_pState
->m_selection
);
2805 RecalculateVirtualSize(0);
2809 m_pState
->m_itemsAdded
= 1;
2812 // -----------------------------------------------------------------------
2814 // Call to SetSplitterPosition will always disable splitter auto-centering
2815 // if parent window is shown.
2816 void wxPropertyGrid::DoSetSplitterPosition( int newxpos
,
2820 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2823 wxPropertyGridPageState
* state
= m_pState
;
2825 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2826 state
->m_dontCenterSplitter
= true;
2828 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2830 if ( flags
& wxPG_SPLITTER_REFRESH
)
2832 if ( GetSelection() )
2833 CorrectEditorWidgetSizeX();
2841 // -----------------------------------------------------------------------
2843 void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing
)
2845 wxPropertyGridPageState
* state
= m_pState
;
2847 state
->ResetColumnSizes(0);
2849 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2850 m_pState
->m_dontCenterSplitter
= false;
2853 // -----------------------------------------------------------------------
2855 void wxPropertyGrid::CenterSplitter( bool enableAutoResizing
)
2857 SetSplitterPosition( m_width
/2 );
2858 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2859 m_pState
->m_dontCenterSplitter
= false;
2862 // -----------------------------------------------------------------------
2863 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2864 // -----------------------------------------------------------------------
2866 // Returns nearest paint visible property (such that will be painted unless
2867 // window is scrolled or resized). If given property is paint visible, then
2868 // it itself will be returned
2869 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2871 int vx
,vy1
;// Top left corner of client
2872 GetViewStart(&vx
,&vy1
);
2873 vy1
*= wxPG_PIXELS_PER_UNIT
;
2875 int vy2
= vy1
+ m_height
;
2876 int propY
= p
->GetY2(m_lineHeight
);
2878 if ( (propY
+ m_lineHeight
) < vy1
)
2881 return DoGetItemAtY( vy1
);
2883 else if ( propY
> vy2
)
2886 return DoGetItemAtY( vy2
);
2889 // Itself paint visible
2894 // -----------------------------------------------------------------------
2895 // Methods related to change in value, value modification and sending events
2896 // -----------------------------------------------------------------------
2898 // commits any changes in editor of selected property
2899 // return true if validation did not fail
2900 // flags are same as with DoSelectProperty
2901 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2903 // Committing already?
2904 if ( m_inCommitChangesFromEditor
)
2907 // Don't do this if already processing editor event. It might
2908 // induce recursive dialogs and crap like that.
2909 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2911 if ( m_inDoPropertyChanged
)
2917 wxPGProperty
* selected
= GetSelection();
2920 IsEditorsValueModified() &&
2921 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2924 m_inCommitChangesFromEditor
= true;
2926 wxVariant
variant(selected
->GetValueRef());
2927 bool valueIsPending
= false;
2929 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2930 // due to another window getting focus
2931 wxWindow
* oldFocus
= m_curFocused
;
2933 bool validationFailure
= false;
2934 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2936 m_chgInfo_changedProperty
= NULL
;
2938 // If truly modified, schedule value as pending.
2939 if ( selected
->GetEditorClass()->
2940 GetValueFromControl( variant
,
2942 GetEditorControl() ) )
2944 if ( DoEditorValidate() &&
2945 PerformValidation(selected
, variant
) )
2947 valueIsPending
= true;
2951 validationFailure
= true;
2956 EditorsValueWasNotModified();
2959 m_inCommitChangesFromEditor
= false;
2963 if ( validationFailure
&& !forceSuccess
)
2967 oldFocus
->SetFocus();
2968 m_curFocused
= oldFocus
;
2971 res
= OnValidationFailure(selected
, variant
);
2973 // Now prevent further validation failure messages
2976 EditorsValueWasNotModified();
2977 OnValidationFailureReset(selected
);
2980 else if ( valueIsPending
)
2982 DoPropertyChanged( selected
, flags
);
2983 EditorsValueWasNotModified();
2992 // -----------------------------------------------------------------------
2994 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2998 // Runs all validation functionality.
2999 // Returns true if value passes all tests.
3002 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
3003 m_validationInfo
.m_isFailing
= true;
3006 // Variant list a special value that cannot be validated
3008 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3010 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
3015 // Adapt list to child values, if necessary
3016 wxVariant listValue
= pendingValue
;
3017 wxVariant
* pPendingValue
= &pendingValue
;
3018 wxVariant
* pList
= NULL
;
3020 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
3021 // string value, then we need treat as it was changed instead
3022 // (or, in addition, as is the case with composite string parent).
3023 // This includes creating list variant for child values.
3025 wxPGProperty
* pwc
= p
->GetParent();
3026 wxPGProperty
* changedProperty
= p
;
3027 wxPGProperty
* baseChangedProperty
= changedProperty
;
3028 wxVariant bcpPendingList
;
3030 listValue
= pendingValue
;
3031 listValue
.SetName(p
->GetBaseName());
3034 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
3036 wxVariantList tempList
;
3037 wxVariant
lv(tempList
, pwc
->GetBaseName());
3038 lv
.Append(listValue
);
3040 pPendingValue
= &listValue
;
3042 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
3044 baseChangedProperty
= pwc
;
3045 bcpPendingList
= lv
;
3048 changedProperty
= pwc
;
3049 pwc
= pwc
->GetParent();
3053 wxPGProperty
* evtChangingProperty
= changedProperty
;
3055 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
3057 value
= *pPendingValue
;
3061 // Convert list to child values
3062 pList
= pPendingValue
;
3063 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
3066 wxVariant evtChangingValue
= value
;
3068 if ( flags
& SendEvtChanging
)
3070 // FIXME: After proper ValueToString()s added, remove
3071 // this. It is just a temporary fix, as evt_changing
3072 // will simply not work for wxPG_PROP_COMPOSED_VALUE
3073 // (unless it is selected, and textctrl editor is open).
3074 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3076 evtChangingProperty
= baseChangedProperty
;
3077 if ( evtChangingProperty
!= p
)
3079 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
3083 evtChangingValue
= pendingValue
;
3087 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3089 if ( changedProperty
== GetSelection() )
3091 wxWindow
* editor
= GetEditorControl();
3092 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
3093 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
3097 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
3102 wxASSERT( m_chgInfo_changedProperty
== NULL
);
3103 m_chgInfo_changedProperty
= changedProperty
;
3104 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
3105 m_chgInfo_pendingValue
= value
;
3108 m_chgInfo_valueList
= *pList
;
3110 m_chgInfo_valueList
.MakeNull();
3112 // If changedProperty is not property which value was edited,
3113 // then call wxPGProperty::ValidateValue() for that as well.
3114 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3116 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3120 if ( flags
& SendEvtChanging
)
3122 // SendEvent returns true if event was vetoed
3123 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3124 &evtChangingValue
) )
3128 if ( flags
& IsStandaloneValidation
)
3130 // If called in 'generic' context, we need to reset
3131 // m_chgInfo_changedProperty and write back translated value.
3132 m_chgInfo_changedProperty
= NULL
;
3133 pendingValue
= value
;
3136 m_validationInfo
.m_isFailing
= false;
3141 // -----------------------------------------------------------------------
3144 wxStatusBar
* wxPropertyGrid::GetStatusBar()
3146 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3147 if ( topWnd
&& topWnd
->IsKindOf(CLASSINFO(wxFrame
)) )
3149 wxFrame
* pFrame
= wxStaticCast(topWnd
, wxFrame
);
3151 return pFrame
->GetStatusBar();
3157 // -----------------------------------------------------------------------
3159 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3161 if ( !msg
.length() )
3165 if ( !wxPGGlobalVars
->m_offline
)
3167 wxStatusBar
* pStatusBar
= GetStatusBar();
3170 pStatusBar
->SetStatusText(msg
);
3176 ::wxMessageBox(msg
, _("Property Error"));
3179 // -----------------------------------------------------------------------
3181 void wxPropertyGrid::DoHidePropertyError( wxPGProperty
* WXUNUSED(property
) )
3184 if ( !wxPGGlobalVars
->m_offline
)
3186 wxStatusBar
* pStatusBar
= GetStatusBar();
3189 pStatusBar
->SetStatusText(wxEmptyString
);
3196 // -----------------------------------------------------------------------
3198 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3199 wxVariant
& invalidValue
)
3201 if ( m_inOnValidationFailure
)
3204 m_inOnValidationFailure
= true;
3205 wxON_BLOCK_EXIT_SET(m_inOnValidationFailure
, false);
3207 wxWindow
* editor
= GetEditorControl();
3208 int vfb
= m_validationInfo
.m_failureBehavior
;
3210 if ( m_inDoSelectProperty
)
3212 // When property selection is being changed, do not display any
3213 // messages, if some were already shown for this property.
3214 if ( property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3216 m_validationInfo
.m_failureBehavior
=
3217 vfb
& ~(wxPG_VFB_SHOW_MESSAGE
|
3218 wxPG_VFB_SHOW_MESSAGEBOX
|
3219 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
);
3223 // First call property's handler
3224 property
->OnValidationFailure(invalidValue
);
3226 bool res
= DoOnValidationFailure(property
, invalidValue
);
3229 // For non-wxTextCtrl editors, we do need to revert the value
3230 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3231 property
== GetSelection() )
3233 property
->GetEditorClass()->UpdateControl(property
, editor
);
3236 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3241 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3243 int vfb
= m_validationInfo
.m_failureBehavior
;
3245 if ( vfb
& wxPG_VFB_BEEP
)
3248 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3249 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3251 unsigned int colCount
= m_pState
->GetColumnCount();
3253 // We need backup marked property's cells
3254 m_propCellsBackup
= property
->m_cells
;
3256 wxColour vfbFg
= *wxWHITE
;
3257 wxColour vfbBg
= *wxRED
;
3259 property
->EnsureCells(colCount
);
3261 for ( unsigned int i
=0; i
<colCount
; i
++ )
3263 wxPGCell
& cell
= property
->m_cells
[i
];
3264 cell
.SetFgCol(vfbFg
);
3265 cell
.SetBgCol(vfbBg
);
3268 DrawItemAndChildren(property
);
3270 if ( property
== GetSelection() )
3272 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3274 wxWindow
* editor
= GetEditorControl();
3277 editor
->SetForegroundColour(vfbFg
);
3278 editor
->SetBackgroundColour(vfbBg
);
3283 if ( vfb
& (wxPG_VFB_SHOW_MESSAGE
|
3284 wxPG_VFB_SHOW_MESSAGEBOX
|
3285 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
) )
3287 wxString msg
= m_validationInfo
.m_failureMessage
;
3289 if ( !msg
.length() )
3290 msg
= _("You have entered invalid value. Press ESC to cancel editing.");
3293 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3295 if ( !wxPGGlobalVars
->m_offline
)
3297 wxStatusBar
* pStatusBar
= GetStatusBar();
3299 pStatusBar
->SetStatusText(msg
);
3304 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3305 DoShowPropertyError(property
, msg
);
3307 if ( vfb
& wxPG_VFB_SHOW_MESSAGEBOX
)
3308 ::wxMessageBox(msg
, _("Property Error"));
3311 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3314 // -----------------------------------------------------------------------
3316 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3318 int vfb
= m_validationInfo
.m_failureBehavior
;
3320 if ( vfb
& wxPG_VFB_MARK_CELL
)
3323 property
->m_cells
= m_propCellsBackup
;
3325 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3327 if ( property
== GetSelection() && GetEditorControl() )
3329 // Calling this will recreate the control, thus resetting its colour
3330 RefreshProperty(property
);
3334 DrawItemAndChildren(property
);
3339 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3341 if ( !wxPGGlobalVars
->m_offline
)
3343 wxStatusBar
* pStatusBar
= GetStatusBar();
3345 pStatusBar
->SetStatusText(wxEmptyString
);
3350 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3352 DoHidePropertyError(property
);
3355 m_validationInfo
.m_isFailing
= false;
3358 // -----------------------------------------------------------------------
3360 // flags are same as with DoSelectProperty
3361 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3363 if ( m_inDoPropertyChanged
)
3366 m_inDoPropertyChanged
= true;
3367 wxON_BLOCK_EXIT_SET(m_inDoPropertyChanged
, false);
3369 wxPGProperty
* selected
= GetSelection();
3371 m_pState
->m_anyModified
= 1;
3373 // If property's value is being changed, assume it is valid
3374 OnValidationFailureReset(selected
);
3376 // Maybe need to update control
3377 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3379 // These values were calculated in PerformValidation()
3380 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3381 wxVariant value
= m_chgInfo_pendingValue
;
3383 wxPGProperty
* topPaintedProperty
= changedProperty
;
3385 while ( !topPaintedProperty
->IsCategory() &&
3386 !topPaintedProperty
->IsRoot() )
3388 topPaintedProperty
= topPaintedProperty
->GetParent();
3391 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3393 // NB: Call GetEditorControl() as late as possible, because OnSetValue()
3394 // and perhaps other user-defined virtual functions may change it.
3395 wxWindow
* editor
= GetEditorControl();
3397 // Set as Modified (not if dragging just began)
3398 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3400 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3401 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3404 SetCurControlBoldFont();
3410 // Propagate updates to parent(s)
3412 wxPGProperty
* prevPwc
= NULL
;
3414 while ( prevPwc
!= topPaintedProperty
)
3416 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3418 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3421 SetCurControlBoldFont();
3425 pwc
= pwc
->GetParent();
3428 // Draw the actual property
3429 DrawItemAndChildren( topPaintedProperty
);
3432 // If value was set by wxPGProperty::OnEvent, then update the editor
3434 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3440 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3441 if ( m_wndEditor
) m_wndEditor
->Refresh();
3442 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3447 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3449 // If top parent has composite string value, then send to child parents,
3450 // starting from baseChangedProperty.
3451 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3453 pwc
= m_chgInfo_baseChangedProperty
;
3455 while ( pwc
!= changedProperty
)
3457 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3458 pwc
= pwc
->GetParent();
3462 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3467 // -----------------------------------------------------------------------
3469 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3471 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3473 m_chgInfo_changedProperty
= NULL
;
3475 if ( PerformValidation(p
, newValue
) )
3477 DoPropertyChanged(p
);
3482 OnValidationFailure(p
, newValue
);
3488 // -----------------------------------------------------------------------
3490 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3492 wxPGProperty
* prop
= GetSelectedProperty();
3495 return wxNullVariant
;
3497 wxTextCtrl
* tc
= GetEditorTextCtrl();
3498 wxVariant value
= prop
->GetValue();
3500 if ( !tc
|| !IsEditorsValueModified() )
3503 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3506 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3507 return prop
->GetValue();
3512 // -----------------------------------------------------------------------
3514 // Runs wxValidator for the selected property
3515 bool wxPropertyGrid::DoEditorValidate()
3517 #if wxUSE_VALIDATORS
3518 wxRecursionGuard
guard(m_validatingEditor
);
3519 if ( guard
.IsInside() )
3522 wxPGProperty
* selected
= GetSelection();
3525 wxWindow
* wnd
= GetEditorControl();
3527 wxValidator
* validator
= selected
->GetValidator();
3528 if ( validator
&& wnd
)
3530 validator
->SetWindow(wnd
);
3531 if ( !validator
->Validate(this) )
3539 // -----------------------------------------------------------------------
3541 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3543 // It is possible that this handler receives event even before
3544 // the control has been properly initialized. Let's skip the
3545 // event handling in that case.
3549 // Don't care about the event if it originated from the
3550 // 'label editor'. In this function we only care about the
3551 // property value editor.
3552 if ( m_labelEditor
&& event
.GetId() == m_labelEditor
->GetId() )
3558 wxPGProperty
* selected
= GetSelection();
3560 // Somehow, event is handled after property has been deselected.
3561 // Possibly, but very rare.
3563 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3564 m_inOnValidationFailure
||
3565 // Also don't handle editor event if wxEVT_PG_CHANGED or
3566 // similar is currently doing something (showing a
3567 // message box, for instance).
3571 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3574 wxVariant
pendingValue(selected
->GetValueRef());
3575 wxWindow
* wnd
= GetEditorControl();
3576 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3578 bool wasUnspecified
= selected
->IsValueUnspecified();
3579 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3580 bool valueIsPending
= false;
3582 m_chgInfo_changedProperty
= NULL
;
3584 m_iFlags
&= ~wxPG_FL_VALUE_CHANGE_IN_EVENT
;
3587 // Filter out excess wxTextCtrl modified events
3588 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&& wnd
)
3590 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3592 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3594 wxString newTcValue
= tc
->GetValue();
3595 if ( m_prevTcValue
== newTcValue
)
3597 m_prevTcValue
= newTcValue
;
3599 else if ( wnd
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
3601 wxComboCtrl
* cc
= (wxComboCtrl
*) wnd
;
3603 wxString newTcValue
= cc
->GetTextCtrl()->GetValue();
3604 if ( m_prevTcValue
== newTcValue
)
3606 m_prevTcValue
= newTcValue
;
3610 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3612 bool validationFailure
= false;
3613 bool buttonWasHandled
= false;
3616 // Try common button handling
3617 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3619 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3623 buttonWasHandled
= true;
3624 // Store as res2, as previously (and still currently alternatively)
3625 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3626 // in wxPGProperty::OnEvent().
3627 adapter
->ShowDialog( this, selected
);
3632 if ( !buttonWasHandled
)
3634 if ( wnd
|| m_wndEditor2
)
3636 // First call editor class' event handler.
3637 const wxPGEditor
* editor
= selected
->GetEditorClass();
3639 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3641 // If changes, validate them
3642 if ( DoEditorValidate() )
3644 if ( editor
->GetValueFromControl( pendingValue
,
3647 valueIsPending
= true;
3649 // Mark value always as pending if validation is currently
3650 // failing and value was not unspecified
3651 if ( !valueIsPending
&&
3652 !pendingValue
.IsNull() &&
3653 m_validationInfo
.m_isFailing
)
3654 valueIsPending
= true;
3658 validationFailure
= true;
3663 // Then the property's custom handler (must be always called, unless
3664 // validation failed).
3665 if ( !validationFailure
)
3666 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3669 // SetValueInEvent(), as called in one of the functions referred above
3670 // overrides editor's value.
3671 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3673 valueIsPending
= true;
3674 pendingValue
= m_changeInEventValue
;
3675 selFlags
|= wxPG_SEL_DIALOGVAL
;
3678 if ( !validationFailure
&& valueIsPending
)
3679 if ( !PerformValidation(selected
, pendingValue
) )
3680 validationFailure
= true;
3682 if ( validationFailure
)
3684 OnValidationFailure(selected
, pendingValue
);
3686 else if ( valueIsPending
)
3688 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3690 DoPropertyChanged(selected
, selFlags
);
3691 EditorsValueWasNotModified();
3693 // Regardless of editor type, unfocus editor on
3694 // text-editing related enter press.
3695 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3702 // No value after all
3704 // Regardless of editor type, unfocus editor on
3705 // text-editing related enter press.
3706 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3711 // Let unhandled button click events go to the parent
3712 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3714 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3715 GetEventHandler()->AddPendingEvent(evt
);
3719 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3722 // -----------------------------------------------------------------------
3723 // wxPropertyGrid editor control helper methods
3724 // -----------------------------------------------------------------------
3726 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3728 int itemy
= p
->GetY2(m_lineHeight
);
3729 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3730 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3731 int imageOffset
= 0;
3733 int vx
, vy
; // Top left corner of client
3734 GetViewStart(&vx
, &vy
);
3735 vy
*= wxPG_PIXELS_PER_UNIT
;
3739 // TODO: If custom image detection changes from current, change this.
3740 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3742 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3743 int iw
= p
->OnMeasureImage().x
;
3745 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3746 imageOffset
= p
->GetImageOffset(iw
);
3749 else if ( column
== 0 )
3751 splitterX
+= (p
->m_depth
- 1) * m_subgroup_extramargin
;
3756 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3758 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3763 // -----------------------------------------------------------------------
3765 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3767 wxSize sz
= GetImageSize(p
, item
);
3768 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3769 wxPG_CUSTOM_IMAGE_SPACINGY
,
3774 // return size of custom paint image
3775 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3777 // If called with NULL property, then return default image
3778 // size for properties that use image.
3780 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3782 wxSize cis
= p
->OnMeasureImage(item
);
3784 int choiceCount
= p
->m_choices
.GetCount();
3785 int comVals
= p
->GetDisplayedCommonValueCount();
3786 if ( item
>= choiceCount
&& comVals
> 0 )
3788 unsigned int cvi
= item
-choiceCount
;
3789 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3791 else if ( item
>= 0 && choiceCount
== 0 )
3792 return wxSize(0, 0);
3797 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3802 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3809 // -----------------------------------------------------------------------
3811 // takes scrolling into account
3812 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3815 GetViewStart(&vx
,&vy
);
3816 vy
*=wxPG_PIXELS_PER_UNIT
;
3817 vx
*=wxPG_PIXELS_PER_UNIT
;
3820 ClientToScreen( px
, py
);
3823 // -----------------------------------------------------------------------
3825 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3828 GetViewStart(&pt2
.x
,&pt2
.y
);
3829 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3830 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3834 return m_pState
->HitTest(pt2
);
3837 // -----------------------------------------------------------------------
3839 // custom set cursor
3840 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3842 if ( type
== m_curcursor
&& !override
) return;
3844 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3846 if ( type
== wxCURSOR_SIZEWE
)
3847 cursor
= m_cursorSizeWE
;
3849 SetCursor( *cursor
);
3854 // -----------------------------------------------------------------------
3857 wxPropertyGrid::GetUnspecifiedValueText( int argFlags
) const
3859 const wxPGCell
& ua
= GetUnspecifiedValueAppearance();
3861 if ( ua
.HasText() &&
3862 !(argFlags
& wxPG_FULL_VALUE
) &&
3863 !(argFlags
& wxPG_EDITABLE_VALUE
) )
3864 return ua
.GetText();
3866 return wxEmptyString
;
3869 // -----------------------------------------------------------------------
3870 // wxPropertyGrid property selection, editor creation
3871 // -----------------------------------------------------------------------
3874 // This class forwards events from property editor controls to wxPropertyGrid.
3875 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3878 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3879 : wxEvtHandler(), m_propGrid(propGrid
)
3883 virtual ~wxPropertyGridEditorEventForwarder()
3888 bool ProcessEvent( wxEvent
& event
)
3893 m_propGrid
->HandleCustomEditorEvent(event
);
3896 // NB: On wxMSW, a wxTextCtrl with wxTE_PROCESS_ENTER
3897 // may beep annoyingly if that event is skipped
3898 // and passed to parent event handler.
3899 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3902 return wxEvtHandler::ProcessEvent(event
);
3905 wxPropertyGrid
* m_propGrid
;
3908 // Setups event handling for child control
3909 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3911 wxWindowID id
= argWnd
->GetId();
3913 if ( argWnd
== m_wndEditor
)
3915 argWnd
->Connect(id
, wxEVT_MOTION
,
3916 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3918 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3919 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3921 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3922 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3924 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3925 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3927 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3928 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3930 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3931 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3935 wxPropertyGridEditorEventForwarder
* forwarder
;
3936 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3937 argWnd
->PushEventHandler(forwarder
);
3939 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3940 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3944 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3951 // Do not free editors immediately (for sake of processing events)
3952 wxPendingDelete
.Append(wnd
);
3955 void wxPropertyGrid::FreeEditors()
3958 // Return focus back to canvas from children (this is required at least for
3959 // GTK+, which, unlike Windows, clears focus when control is destroyed
3960 // instead of moving it to closest parent).
3961 wxWindow
* focus
= wxWindow::FindFocus();
3964 wxWindow
* parent
= focus
->GetParent();
3967 if ( parent
== this )
3972 parent
= parent
->GetParent();
3976 // Do not free editors immediately if processing events
3979 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3980 m_wndEditor2
->Hide();
3981 wxPendingDelete
.Append( handler
);
3982 DestroyEditorWnd(m_wndEditor2
);
3983 m_wndEditor2
= NULL
;
3988 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3989 m_wndEditor
->Hide();
3990 wxPendingDelete
.Append( handler
);
3991 DestroyEditorWnd(m_wndEditor
);
3996 // Call with NULL to de-select property
3997 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
4002 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
4003 p->m_parent->m_label.c_str(),p->GetIndexInParent());
4007 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
4011 if ( m_inDoSelectProperty
)
4014 m_inDoSelectProperty
= true;
4015 wxON_BLOCK_EXIT_SET(m_inDoSelectProperty
, false);
4020 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
4021 wxPGProperty
* prevFirstSel
;
4023 if ( prevSelection
.size() > 0 )
4024 prevFirstSel
= prevSelection
[0];
4026 prevFirstSel
= NULL
;
4028 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
4029 prevFirstSel
= NULL
;
4031 // Always send event, as this is indirect call
4032 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4036 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
4038 wxPrintf( "None selected\n" );
4041 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
4043 wxPrintf( "P = NULL\n" );
4046 wxWindow
* primaryCtrl
= NULL
;
4048 // If we are frozen, then just set the values.
4051 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4052 m_editorFocused
= 0;
4053 m_pState
->DoSetSelection(p
);
4055 // If frozen, always free controls. But don't worry, as Thaw will
4056 // recall SelectProperty to recreate them.
4059 // Prevent any further selection measures in this call
4065 if ( prevFirstSel
== p
&&
4066 prevSelection
.size() <= 1 &&
4067 !(flags
& wxPG_SEL_FORCE
) )
4069 // Only set focus if not deselecting
4072 if ( flags
& wxPG_SEL_FOCUS
)
4076 m_wndEditor
->SetFocus();
4077 m_editorFocused
= 1;
4090 // First, deactivate previous
4093 // Must double-check if this is an selected in case of forceswitch
4094 if ( p
!= prevFirstSel
)
4096 if ( !CommitChangesFromEditor(flags
) )
4098 // Validation has failed, so we can't exit the previous editor
4099 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
4100 // _("Invalid Value"),wxOK|wxICON_ERROR);
4105 // This should be called after CommitChangesFromEditor(), so that
4106 // OnValidationFailure() still has information on property's
4107 // validation state.
4108 OnValidationFailureReset(prevFirstSel
);
4112 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4113 EditorsValueWasNotModified();
4116 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4118 m_pState
->DoSetSelection(p
);
4120 // Redraw unselected
4121 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
4123 DrawItem(prevSelection
[i
]);
4127 // Then, activate the one given.
4130 int propY
= p
->GetY2(m_lineHeight
);
4132 int splitterX
= GetSplitterPosition();
4133 m_editorFocused
= 0;
4134 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
4136 wxASSERT( m_wndEditor
== NULL
);
4139 // Only create editor for non-disabled non-caption
4140 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
4142 // do this for non-caption items
4146 // Do we need to paint the custom image, if any?
4147 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
4148 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
4149 !p
->GetEditorClass()->CanContainCustomImage()
4151 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
4153 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
4154 wxPoint goodPos
= grect
.GetPosition();
4156 // Editor appearance can now be considered clear
4157 m_editorAppearance
.SetEmptyData();
4159 const wxPGEditor
* editor
= p
->GetEditorClass();
4160 wxCHECK_MSG(editor
, false,
4161 wxT("NULL editor class not allowed"));
4163 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
4165 wxPGWindowList wndList
=
4166 editor
->CreateControls(this,
4171 m_wndEditor
= wndList
.m_primary
;
4172 m_wndEditor2
= wndList
.m_secondary
;
4173 primaryCtrl
= GetEditorControl();
4176 // Essentially, primaryCtrl == m_wndEditor
4179 // NOTE: It is allowed for m_wndEditor to be NULL - in this
4180 // case value is drawn as normal, and m_wndEditor2 is
4181 // assumed to be a right-aligned button that triggers
4182 // a separate editorCtrl window.
4186 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
4187 "CreateControls must use result of "
4188 "wxPropertyGrid::GetPanel() as parent "
4191 // Set validator, if any
4192 #if wxUSE_VALIDATORS
4193 wxValidator
* validator
= p
->GetValidator();
4195 primaryCtrl
->SetValidator(*validator
);
4198 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
4199 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
4201 // If it has modified status, use bold font
4202 // (must be done before capturing m_ctrlXAdjust)
4203 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
4204 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
4205 SetCurControlBoldFont();
4207 // Store x relative to splitter (we'll need it).
4208 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
4210 // Check if background clear is not necessary
4211 wxPoint pos
= m_wndEditor
->GetPosition();
4212 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
4214 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
4217 m_wndEditor
->SetSizeHints(3, 3);
4219 SetupChildEventHandling(primaryCtrl
);
4221 // Focus and select all (wxTextCtrl, wxComboBox etc)
4222 if ( flags
& wxPG_SEL_FOCUS
)
4224 primaryCtrl
->SetFocus();
4226 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
4230 if ( p
->IsValueUnspecified() )
4231 SetEditorAppearance(m_unspecifiedAppearance
,
4238 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
4239 "CreateControls must use result of "
4240 "wxPropertyGrid::GetPanel() as parent "
4243 // Get proper id for wndSecondary
4244 m_wndSecId
= m_wndEditor2
->GetId();
4245 wxWindowList children
= m_wndEditor2
->GetChildren();
4246 wxWindowList::iterator node
= children
.begin();
4247 if ( node
!= children
.end() )
4248 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
4250 m_wndEditor2
->SetSizeHints(3,3);
4252 m_wndEditor2
->Show();
4254 SetupChildEventHandling(m_wndEditor2
);
4256 // If no primary editor, focus to button to allow
4257 // it to interprete ENTER etc.
4258 // NOTE: Due to problems focusing away from it, this
4259 // has been disabled.
4261 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
4262 m_wndEditor2->SetFocus();
4266 if ( flags
& wxPG_SEL_FOCUS
)
4267 m_editorFocused
= 1;
4272 // Make sure focus is in grid canvas (important for wxGTK,
4277 EditorsValueWasNotModified();
4279 // If it's inside collapsed section, expand parent, scroll, etc.
4280 // Also, if it was partially visible, scroll it into view.
4281 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
4286 m_wndEditor
->Show(true);
4289 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
4294 // Make sure focus is in grid canvas
4298 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4301 const wxString
* pHelpString
= NULL
;
4304 pHelpString
= &p
->GetHelpString();
4306 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4311 // Show help text in status bar.
4312 // (if found and grid not embedded in manager with help box and
4313 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4315 wxStatusBar
* statusbar
= GetStatusBar();
4318 if ( pHelpString
&& pHelpString
->length() )
4320 // Set help box text.
4321 statusbar
->SetStatusText( *pHelpString
);
4322 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4324 else if ( m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
)
4326 // Clear help box - but only if it was written
4327 // by us at previous time.
4328 statusbar
->SetStatusText( m_emptyString
);
4329 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4336 #if wxPG_SUPPORT_TOOLTIPS
4338 // Show help as a tool tip on the editor control.
4340 if ( pHelpString
&& pHelpString
->length() &&
4343 primaryCtrl
->SetToolTip(*pHelpString
);
4348 // call wx event handler (here so that it also occurs on deselection)
4349 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4350 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4355 // -----------------------------------------------------------------------
4357 bool wxPropertyGrid::UnfocusEditor()
4359 wxPGProperty
* selected
= GetSelection();
4361 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4364 if ( !CommitChangesFromEditor(0) )
4373 // -----------------------------------------------------------------------
4375 void wxPropertyGrid::RefreshEditor()
4377 wxPGProperty
* p
= GetSelection();
4381 wxWindow
* wnd
= GetEditorControl();
4385 // Set editor font boldness - must do this before
4386 // calling UpdateControl().
4387 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4389 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4390 wnd
->SetFont(GetCaptionFont());
4392 wnd
->SetFont(GetFont());
4395 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4397 editorClass
->UpdateControl(p
, wnd
);
4399 if ( p
->IsValueUnspecified() )
4400 SetEditorAppearance(m_unspecifiedAppearance
, true);
4403 // -----------------------------------------------------------------------
4405 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4407 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4409 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4411 flags
|= wxPG_SEL_FOCUS
;
4413 return DoSelectProperty(p
, flags
);
4416 // -----------------------------------------------------------------------
4417 // wxPropertyGrid expand/collapse state
4418 // -----------------------------------------------------------------------
4420 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4422 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4423 wxPGProperty
* selected
= GetSelection();
4425 // If active editor was inside collapsed section, then disable it
4426 if ( selected
&& selected
->IsSomeParent(p
) )
4431 // Store dont-center-splitter flag 'cause we need to temporarily set it
4432 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4433 m_pState
->m_dontCenterSplitter
= true;
4435 bool res
= m_pState
->DoCollapse(pwc
);
4440 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4442 RecalculateVirtualSize();
4446 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4451 // -----------------------------------------------------------------------
4453 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4455 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4457 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4459 // Store dont-center-splitter flag 'cause we need to temporarily set it
4460 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4461 m_pState
->m_dontCenterSplitter
= true;
4463 bool res
= m_pState
->DoExpand(pwc
);
4468 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4470 RecalculateVirtualSize();
4474 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4479 // -----------------------------------------------------------------------
4481 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4484 return m_pState
->DoHideProperty(p
, hide
, flags
);
4486 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4487 int selRemoveCount
= 0;
4488 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4490 wxPGProperty
* selected
= selection
[i
];
4491 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4493 if ( !DoRemoveFromSelection(p
, flags
) )
4495 selRemoveCount
+= 1;
4499 m_pState
->DoHideProperty(p
, hide
, flags
);
4501 RecalculateVirtualSize();
4508 // -----------------------------------------------------------------------
4509 // wxPropertyGrid size related methods
4510 // -----------------------------------------------------------------------
4512 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4514 // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise
4515 // virtual size calculation may go wrong.
4516 if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4522 // If virtual height was changed, then recalculate editor control position(s)
4523 if ( m_pState
->m_vhCalcPending
)
4524 CorrectEditorWidgetPosY();
4526 m_pState
->EnsureVirtualHeight();
4528 wxASSERT_LEVEL_2_MSG(
4529 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4530 "VirtualHeight and ActualVirtualHeight should match"
4533 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4535 int x
= m_pState
->m_width
;
4536 int y
= m_pState
->m_virtualHeight
;
4539 GetClientSize(&width
,&height
);
4541 // Now adjust virtual size.
4542 SetVirtualSize(x
, y
);
4548 // Adjust scrollbars
4549 if ( HasVirtualWidth() )
4551 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4552 xPos
= GetScrollPos( wxHORIZONTAL
);
4555 if ( forceXPos
!= -1 )
4558 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4561 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4562 int yPos
= GetScrollPos( wxVERTICAL
);
4564 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4565 xAmount
, yAmount
, xPos
, yPos
, true );
4567 // Must re-get size now
4568 GetClientSize(&width
,&height
);
4570 if ( !HasVirtualWidth() )
4572 m_pState
->SetVirtualWidth(width
);
4579 m_pState
->CheckColumnWidths();
4581 if ( GetSelection() )
4582 CorrectEditorWidgetSizeX();
4584 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4587 // -----------------------------------------------------------------------
4589 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4591 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4595 GetClientSize(&width
, &height
);
4600 #if wxPG_DOUBLE_BUFFER
4601 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4603 int dblh
= (m_lineHeight
*2);
4604 if ( !m_doubleBuffer
)
4606 // Create double buffer bitmap to draw on, if none
4607 int w
= (width
>250)?width
:250;
4608 int h
= height
+ dblh
;
4610 m_doubleBuffer
= new wxBitmap( w
, h
);
4614 int w
= m_doubleBuffer
->GetWidth();
4615 int h
= m_doubleBuffer
->GetHeight();
4617 // Double buffer must be large enough
4618 if ( w
< width
|| h
< (height
+dblh
) )
4620 if ( w
< width
) w
= width
;
4621 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4622 delete m_doubleBuffer
;
4623 m_doubleBuffer
= new wxBitmap( w
, h
);
4630 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4631 m_ncWidth
= event
.GetSize().x
;
4635 if ( m_pState
->m_itemsAdded
)
4636 PrepareAfterItemsAdded();
4638 // Without this, virtual size (atleast under wxGTK) will be skewed
4639 RecalculateVirtualSize();
4645 // -----------------------------------------------------------------------
4647 void wxPropertyGrid::SetVirtualWidth( int width
)
4651 // Disable virtual width
4652 width
= GetClientSize().x
;
4653 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4657 // Enable virtual width
4658 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4660 m_pState
->SetVirtualWidth( width
);
4663 void wxPropertyGrid::SetFocusOnCanvas()
4666 m_editorFocused
= 0;
4669 // -----------------------------------------------------------------------
4670 // wxPropertyGrid mouse event handling
4671 // -----------------------------------------------------------------------
4673 // selFlags uses same values DoSelectProperty's flags
4674 // Returns true if event was vetoed.
4675 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4677 unsigned int selFlags
,
4678 unsigned int column
)
4680 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4683 // Send property grid event of specific type and with specific property
4684 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4685 evt
.SetPropertyGrid(this);
4686 evt
.SetEventObject(m_eventObject
);
4688 evt
.SetColumn(column
);
4689 if ( eventType
== wxEVT_PG_CHANGING
)
4692 evt
.SetCanVeto(true);
4693 m_validationInfo
.m_pValue
= pValue
;
4694 evt
.SetupValidationInfo();
4699 evt
.SetPropertyValue(p
->GetValue());
4701 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4702 evt
.SetCanVeto(true);
4705 wxPropertyGridEvent
* prevProcessedEvent
= m_processedEvent
;
4706 m_processedEvent
= &evt
;
4707 m_eventObject
->HandleWindowEvent(evt
);
4708 m_processedEvent
= prevProcessedEvent
;
4710 return evt
.WasVetoed();
4713 // -----------------------------------------------------------------------
4715 // Return false if should be skipped
4716 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4720 // Need to set focus?
4721 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4726 wxPropertyGridPageState
* state
= m_pState
;
4728 int splitterHitOffset
;
4729 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4731 wxPGProperty
* p
= DoGetItemAtY(y
);
4735 int depth
= (int)p
->GetDepth() - 1;
4737 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4739 if ( x
>= marginEnds
)
4743 if ( p
->IsCategory() )
4745 // This is category.
4746 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4748 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4750 // Expand, collapse, activate etc. if click on text or left of splitter.
4753 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4758 if ( !AddToSelectionFromInputEvent( p
,
4763 // On double-click, expand/collapse.
4764 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4766 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4767 else DoExpand( p
, true );
4771 else if ( splitterHit
== -1 )
4774 unsigned int selFlag
= 0;
4775 if ( columnHit
== 1 )
4777 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4778 selFlag
= wxPG_SEL_FOCUS
;
4780 if ( !AddToSelectionFromInputEvent( p
,
4786 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4788 if ( p
->GetChildCount() && !p
->IsCategory() )
4789 // On double-click, expand/collapse.
4790 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4792 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4793 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4794 else DoExpand( p
, true );
4797 // Do not Skip() the event after selection has been made.
4798 // Otherwise default event handling behavior kicks in
4799 // and may revert focus back to the main canvas.
4804 // click on splitter
4805 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4807 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4809 // Double-clicking the splitter causes auto-centering
4810 if ( m_pState
->GetColumnCount() <= 2 )
4812 ResetColumnSizes( true );
4814 SendEvent(wxEVT_PG_COL_DRAGGING
,
4817 wxPG_SEL_NOVALIDATE
,
4818 (unsigned int)m_draggedSplitter
);
4821 else if ( m_dragStatus
== 0 )
4824 // Begin draggin the splitter
4828 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4830 // Allow application to veto dragging
4831 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4833 (unsigned int)splitterHit
) )
4837 // Changes must be committed here or the
4838 // value won't be drawn correctly
4839 if ( !CommitChangesFromEditor() )
4842 m_wndEditor
->Show ( false );
4845 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4848 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4852 m_draggedSplitter
= splitterHit
;
4853 m_dragOffset
= splitterHitOffset
;
4855 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4856 // Fixes button disappearance bug
4858 m_wndEditor2
->Show ( false );
4861 m_startingSplitterX
= x
- splitterHitOffset
;
4870 if ( p
->GetChildCount() )
4872 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4874 // Fine tune cell button x
4875 if ( !p
->IsCategory() )
4876 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4878 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4880 int y2
= y
% m_lineHeight
;
4881 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4883 // On click on expander button, expand/collapse
4884 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4885 DoCollapse( p
, true );
4887 DoExpand( p
, true );
4896 // -----------------------------------------------------------------------
4898 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4899 unsigned int WXUNUSED(y
),
4900 wxMouseEvent
& event
)
4904 // Select property here as well
4905 wxPGProperty
* p
= m_propHover
;
4906 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4908 // Send right click event.
4909 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4916 // -----------------------------------------------------------------------
4918 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4919 unsigned int WXUNUSED(y
),
4920 wxMouseEvent
& event
)
4924 // Select property here as well
4925 wxPGProperty
* p
= m_propHover
;
4927 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4929 // Send double-click event.
4930 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4937 // -----------------------------------------------------------------------
4939 // Return false if should be skipped
4940 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
,
4941 wxMouseEvent
&event
)
4943 // Safety check (needed because mouse capturing may
4944 // otherwise freeze the control)
4945 if ( m_dragStatus
> 0 && !event
.Dragging() )
4947 HandleMouseUp(x
, y
, event
);
4950 wxPropertyGridPageState
* state
= m_pState
;
4952 int splitterHitOffset
;
4953 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4954 int splitterX
= x
- splitterHitOffset
;
4956 m_colHover
= columnHit
;
4958 if ( m_dragStatus
> 0 )
4960 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4961 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4964 int newSplitterX
= x
- m_dragOffset
;
4966 // Splitter redraw required?
4967 if ( newSplitterX
!= splitterX
)
4970 DoSetSplitterPosition(newSplitterX
,
4972 wxPG_SPLITTER_REFRESH
|
4973 wxPG_SPLITTER_FROM_EVENT
);
4975 SendEvent(wxEVT_PG_COL_DRAGGING
,
4978 wxPG_SEL_NOVALIDATE
,
4979 (unsigned int)m_draggedSplitter
);
4990 int ih
= m_lineHeight
;
4993 #if wxPG_SUPPORT_TOOLTIPS
4994 wxPGProperty
* prevHover
= m_propHover
;
4995 unsigned char prevSide
= m_mouseSide
;
4997 int curPropHoverY
= y
- (y
% ih
);
4999 // On which item it hovers
5002 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
5005 // Mouse moves on another property
5007 m_propHover
= DoGetItemAtY(y
);
5008 m_propHoverY
= curPropHoverY
;
5011 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
5014 #if wxPG_SUPPORT_TOOLTIPS
5015 // Store which side we are on
5017 if ( columnHit
== 1 )
5019 else if ( columnHit
== 0 )
5023 // If tooltips are enabled, show label or value as a tip
5024 // in case it doesn't otherwise show in full length.
5026 if ( m_windowStyle
& wxPG_TOOLTIPS
)
5028 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
5030 if ( m_propHover
&& !m_propHover
->IsCategory() )
5033 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
5035 // Show help string as a tooltip
5036 wxString tipString
= m_propHover
->GetHelpString();
5038 SetToolTip(tipString
);
5042 // Show cropped value string as a tooltip
5046 if ( m_mouseSide
== 1 )
5048 tipString
= m_propHover
->m_label
;
5049 space
= splitterX
-m_marginWidth
-3;
5051 else if ( m_mouseSide
== 2 )
5053 tipString
= m_propHover
->GetDisplayedString();
5055 space
= m_width
- splitterX
;
5056 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
5057 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+
5058 wxCC_CUSTOM_IMAGE_MARGIN1
+
5059 wxCC_CUSTOM_IMAGE_MARGIN2
;
5065 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
5067 SetToolTip( tipString
);
5071 SetToolTip( m_emptyString
);
5078 SetToolTip( m_emptyString
);
5084 if ( splitterHit
== -1 ||
5086 HasFlag(wxPG_STATIC_SPLITTER
) )
5088 // hovering on something else
5089 if ( m_curcursor
!= wxCURSOR_ARROW
)
5090 CustomSetCursor( wxCURSOR_ARROW
);
5094 // Do not allow splitter cursor on caption items.
5095 // (also not if we were dragging and its started
5096 // outside the splitter region)
5098 if ( !m_propHover
->IsCategory() &&
5102 // hovering on splitter
5104 // NB: Condition disabled since MouseLeave event (from the
5105 // editor control) cannot be reliably detected.
5106 //if ( m_curcursor != wxCURSOR_SIZEWE )
5107 CustomSetCursor( wxCURSOR_SIZEWE
, true );
5113 // hovering on something else
5114 if ( m_curcursor
!= wxCURSOR_ARROW
)
5115 CustomSetCursor( wxCURSOR_ARROW
);
5120 // Multi select by dragging
5122 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
5123 event
.LeftIsDown() &&
5127 !state
->DoIsPropertySelected(m_propHover
) )
5129 // Additional requirement is that the hovered property
5130 // is adjacent to edges of selection.
5131 const wxArrayPGProperty
& selection
= GetSelectedProperties();
5133 // Since categories cannot be selected along with 'other'
5134 // properties, exclude them from iterator flags.
5135 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
5137 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
5139 // TODO: This could be optimized by keeping track of
5140 // which properties are at the edges of selection.
5141 wxPGProperty
* selProp
= selection
[i
];
5142 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
5145 DoAddToSelection(m_propHover
);
5154 // -----------------------------------------------------------------------
5156 // Also handles Leaving event
5157 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
5158 wxMouseEvent
&WXUNUSED(event
) )
5160 wxPropertyGridPageState
* state
= m_pState
;
5164 int splitterHitOffset
;
5165 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
5167 // No event type check - basicly calling this method should
5168 // just stop dragging.
5169 // Left up after dragged?
5170 if ( m_dragStatus
>= 1 )
5173 // End Splitter Dragging
5175 // DO NOT ENABLE FOLLOWING LINE!
5176 // (it is only here as a reminder to not to do it)
5179 SendEvent(wxEVT_PG_COL_END_DRAG
,
5182 wxPG_SEL_NOVALIDATE
,
5183 (unsigned int)m_draggedSplitter
);
5185 // Disable splitter auto-centering (but only if moved any -
5186 // otherwise we end up disabling auto-center even after a
5187 // recentering double-click).
5188 int posDiff
= abs(m_startingSplitterX
-
5189 GetSplitterPosition(m_draggedSplitter
));
5192 state
->m_dontCenterSplitter
= true;
5194 // This is necessary to return cursor
5195 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5198 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5201 // Set back the default cursor, if necessary
5202 if ( splitterHit
== -1 ||
5205 CustomSetCursor( wxCURSOR_ARROW
);
5210 // Control background needs to be cleared
5211 wxPGProperty
* selected
= GetSelection();
5212 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
5213 DrawItem( selected
);
5217 m_wndEditor
->Show ( true );
5220 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
5221 // Fixes button disappearance bug
5223 m_wndEditor2
->Show ( true );
5226 // This clears the focus.
5227 m_editorFocused
= 0;
5233 // -----------------------------------------------------------------------
5235 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
5237 int splitterX
= GetSplitterPosition();
5240 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
5242 wxWindow
* wnd
= GetEditorControl();
5244 // Hide popup on clicks
5245 if ( event
.GetEventType() != wxEVT_MOTION
)
5246 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5248 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
5254 if ( wnd
== NULL
|| m_dragStatus
||
5256 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
5257 ux
>= (r
.x
+r
.width
) ||
5259 event
.m_y
>= (r
.y
+r
.height
)
5269 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5274 // -----------------------------------------------------------------------
5276 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
5279 if ( OnMouseCommon( event
, &x
, &y
) )
5281 if ( !HandleMouseClick(x
, y
, event
) )
5290 // -----------------------------------------------------------------------
5292 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5295 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5296 HandleMouseRightClick(x
,y
,event
);
5300 // -----------------------------------------------------------------------
5302 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5304 // Always run standard mouse-down handler as well
5305 OnMouseClick(event
);
5308 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5309 HandleMouseDoubleClick(x
,y
,event
);
5311 // Do not Skip() event here - OnMouseClick() call above
5312 // should have already taken care of it.
5315 // -----------------------------------------------------------------------
5317 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5320 if ( OnMouseCommon( event
, &x
, &y
) )
5322 HandleMouseMove(x
,y
,event
);
5327 // -----------------------------------------------------------------------
5329 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5332 if ( OnMouseCommon( event
, &x
, &y
) )
5334 if ( !HandleMouseUp(x
, y
, event
) )
5343 // -----------------------------------------------------------------------
5345 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5347 // This may get called from child control as well, so event's
5348 // mouse position cannot be relied on.
5350 if ( event
.Entering() )
5352 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5354 // TODO: Fix this (detect parent and only do
5355 // cursor trick if it is a manager).
5356 wxASSERT( GetParent() );
5357 GetParent()->SetCursor(wxNullCursor
);
5359 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5362 GetParent()->SetCursor(wxNullCursor
);
5364 else if ( event
.Leaving() )
5366 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5367 SetCursor( wxNullCursor
);
5369 // Get real cursor position
5370 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5372 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5375 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5377 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5381 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5389 // -----------------------------------------------------------------------
5391 // Common code used by various OnMouseXXXChild methods.
5392 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5394 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5395 wxASSERT( topCtrlWnd
);
5397 event
.GetPosition(&x
,&y
);
5399 int splitterX
= GetSplitterPosition();
5401 wxRect r
= topCtrlWnd
->GetRect();
5402 if ( !m_dragStatus
&&
5403 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5404 y
>= 0 && y
< r
.height \
5407 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5412 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5419 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5422 if ( OnMouseChildCommon(event
,&x
,&y
) )
5424 bool res
= HandleMouseClick(x
,y
,event
);
5425 if ( !res
) event
.Skip();
5429 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5432 wxASSERT( m_wndEditor
);
5433 // These coords may not be exact (about +-2),
5434 // but that should not matter (right click is about item, not position).
5435 wxPoint pt
= m_wndEditor
->GetPosition();
5436 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5438 // FIXME: Used to set m_propHover to selection here. Was it really
5441 bool res
= HandleMouseRightClick(x
,y
,event
);
5442 if ( !res
) event
.Skip();
5445 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5448 if ( OnMouseChildCommon(event
,&x
,&y
) )
5450 bool res
= HandleMouseMove(x
,y
,event
);
5451 if ( !res
) event
.Skip();
5455 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5458 if ( OnMouseChildCommon(event
,&x
,&y
) )
5460 bool res
= HandleMouseUp(x
,y
,event
);
5461 if ( !res
) event
.Skip();
5465 // -----------------------------------------------------------------------
5466 // wxPropertyGrid keyboard event handling
5467 // -----------------------------------------------------------------------
5469 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5471 // Translates wxKeyEvent to wxPG_ACTION_XXX
5473 int keycode
= event
.GetKeyCode();
5474 int modifiers
= event
.GetModifiers();
5476 wxASSERT( !(modifiers
&~(0xFFFF)) );
5478 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5480 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5482 if ( it
== m_actionTriggers
.end() )
5487 int second
= (it
->second
>>16) & 0xFFFF;
5491 return (it
->second
& 0xFFFF);
5494 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5496 wxASSERT( !(modifiers
&~(0xFFFF)) );
5498 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5500 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5502 if ( it
!= m_actionTriggers
.end() )
5504 // This key combination is already used
5506 // Can add secondary?
5507 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5508 wxT("You can only add up to two separate actions per key combination.") );
5510 action
= it
->second
| (action
<<16);
5513 m_actionTriggers
[hashMapKey
] = action
;
5516 void wxPropertyGrid::ClearActionTriggers( int action
)
5518 wxPGHashMapI2I::iterator it
;
5523 didSomething
= false;
5525 for ( it
= m_actionTriggers
.begin();
5526 it
!= m_actionTriggers
.end();
5529 if ( it
->second
== action
)
5531 m_actionTriggers
.erase(it
);
5532 didSomething
= true;
5537 while ( didSomething
);
5540 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5543 // Handles key event when editor control is not focused.
5546 wxCHECK2(!m_frozen
, return);
5548 // Travelsal between items, collapsing/expanding, etc.
5549 wxPGProperty
* selected
= GetSelection();
5550 int keycode
= event
.GetKeyCode();
5551 bool editorFocused
= IsEditorFocused();
5553 if ( keycode
== WXK_TAB
)
5555 wxWindow
* mainControl
;
5557 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5558 mainControl
= GetParent();
5562 if ( !event
.ShiftDown() )
5564 if ( !editorFocused
&& m_wndEditor
)
5566 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5570 // Tab traversal workaround for platforms on which
5571 // wxWindow::Navigate() may navigate into first child
5572 // instead of next sibling. Does not work perfectly
5573 // in every scenario (for instance, when property grid
5574 // is either first or last control).
5575 #if defined(__WXGTK__)
5576 wxWindow
* sibling
= mainControl
->GetNextSibling();
5578 sibling
->SetFocusFromKbd();
5580 Navigate(wxNavigationKeyEvent::IsForward
);
5586 if ( editorFocused
)
5592 #if defined(__WXGTK__)
5593 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5595 sibling
->SetFocusFromKbd();
5597 Navigate(wxNavigationKeyEvent::IsBackward
);
5605 // Ignore Alt and Control when they are down alone
5606 if ( keycode
== WXK_ALT
||
5607 keycode
== WXK_CONTROL
)
5614 int action
= KeyEventToActions(event
, &secondAction
);
5616 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5619 // Esc cancels any changes
5620 if ( IsEditorsValueModified() )
5622 EditorsValueWasNotModified();
5624 // Update the control as well
5625 selected
->GetEditorClass()->
5626 SetControlStringValue( selected
,
5628 selected
->GetDisplayedString() );
5631 OnValidationFailureReset(selected
);
5637 // Except for TAB, ESC, and any keys specifically dedicated to
5638 // wxPropertyGrid itself, handle child control events in child control.
5640 wxPGFindInVector(m_dedicatedKeys
, keycode
) == wxNOT_FOUND
)
5642 // Only propagate event if it had modifiers
5643 if ( !event
.HasModifiers() )
5645 event
.StopPropagation();
5651 bool wasHandled
= false;
5656 if ( ButtonTriggerKeyTest(action
, event
) )
5659 wxPGProperty
* p
= selected
;
5661 // Travel and expand/collapse
5664 if ( p
->GetChildCount() )
5666 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5668 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5671 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5673 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5680 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5684 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5690 if ( selectDir
>= -1 )
5692 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5696 int reopenLabelEditorCol
= -1;
5698 if ( editorFocused
)
5700 // If editor was focused, then make the next editor
5702 selFlags
|= wxPG_SEL_FOCUS
;
5706 // Also maintain the same label editor focus state
5707 if ( m_labelEditor
)
5708 reopenLabelEditorCol
= m_selColumn
;
5711 DoSelectProperty(p
, selFlags
);
5713 if ( reopenLabelEditorCol
>= 0 )
5714 DoBeginLabelEdit(reopenLabelEditorCol
);
5721 // If nothing was selected, select the first item now
5722 // (or navigate out of tab).
5723 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5725 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5726 if ( p
) DoSelectProperty(p
);
5735 // -----------------------------------------------------------------------
5737 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5739 // If there was editor open and focused, then this event should not
5740 // really be processed here.
5741 if ( IsEditorFocused() )
5743 // However, if event had modifiers, it is probably still best
5745 if ( event
.HasModifiers() )
5748 event
.StopPropagation();
5752 HandleKeyEvent(event
, false);
5755 // -----------------------------------------------------------------------
5757 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5762 action
= KeyEventToActions(event
, &secondAction
);
5765 // Does the keycode trigger button?
5766 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5769 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5770 GetEventHandler()->AddPendingEvent(evt
);
5777 // -----------------------------------------------------------------------
5779 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5781 HandleKeyEvent(event
, true);
5784 // -----------------------------------------------------------------------
5785 // wxPropertyGrid miscellaneous event handling
5786 // -----------------------------------------------------------------------
5788 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5791 // Check if the focus is in this control or one of its children
5792 wxWindow
* newFocused
= wxWindow::FindFocus();
5794 if ( newFocused
!= m_curFocused
)
5795 HandleFocusChange( newFocused
);
5798 // Check if top-level parent has changed
5799 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5801 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5807 // Resolve pending property removals
5808 if ( m_deletedProperties
.size() > 0 )
5810 wxArrayPGProperty
& arr
= m_deletedProperties
;
5811 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5813 DeleteProperty(arr
[i
]);
5817 if ( m_removedProperties
.size() > 0 )
5819 wxArrayPGProperty
& arr
= m_removedProperties
;
5820 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5822 RemoveProperty(arr
[i
]);
5828 bool wxPropertyGrid::IsEditorFocused() const
5830 wxWindow
* focus
= wxWindow::FindFocus();
5832 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5833 focus
== GetEditorControl() )
5839 // Called by focus event handlers. newFocused is the window that becomes focused.
5840 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5843 // Never allow focus to be changed when handling editor event.
5844 // Especially because they may be displaing a dialog which
5845 // could cause all kinds of weird (native) focus changes.
5846 if ( HasInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
5849 unsigned int oldFlags
= m_iFlags
;
5850 bool wasEditorFocused
= false;
5851 wxWindow
* wndEditor
= m_wndEditor
;
5853 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5855 wxWindow
* parent
= newFocused
;
5857 // This must be one of nextFocus' parents.
5860 if ( parent
== wndEditor
)
5862 wasEditorFocused
= true;
5864 // Use m_eventObject, which is either wxPropertyGrid or
5865 // wxPropertyGridManager, as appropriate.
5866 else if ( parent
== m_eventObject
)
5868 m_iFlags
|= wxPG_FL_FOCUSED
;
5871 parent
= parent
->GetParent();
5874 // Notify editor control when it receives a focus
5875 if ( wasEditorFocused
&& m_curFocused
!= newFocused
)
5877 wxPGProperty
* p
= GetSelection();
5880 const wxPGEditor
* editor
= p
->GetEditorClass();
5881 ResetEditorAppearance();
5882 editor
->OnFocus(p
, GetEditorControl());
5886 m_curFocused
= newFocused
;
5888 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5889 (oldFlags
& wxPG_FL_FOCUSED
) )
5891 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5893 // Need to store changed value
5894 CommitChangesFromEditor();
5900 // Preliminary code for tab-order respecting
5901 // tab-traversal (but should be moved to
5904 wxWindow* prevFocus = event.GetWindow();
5905 wxWindow* useThis = this;
5906 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5907 useThis = GetParent();
5910 prevFocus->GetParent() == useThis->GetParent() )
5912 wxList& children = useThis->GetParent()->GetChildren();
5914 wxNode* node = children.Find(prevFocus);
5916 if ( node->GetNext() &&
5917 useThis == node->GetNext()->GetData() )
5918 DoSelectProperty(GetFirst());
5919 else if ( node->GetPrevious () &&
5920 useThis == node->GetPrevious()->GetData() )
5921 DoSelectProperty(GetLastProperty());
5928 wxPGProperty
* selected
= GetSelection();
5929 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5930 DrawItem( selected
);
5934 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5936 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5937 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5938 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5939 //else if ( event.GetWindow() )
5941 HandleFocusChange(event
.GetWindow());
5946 // -----------------------------------------------------------------------
5948 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5950 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5954 // -----------------------------------------------------------------------
5956 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5958 m_iFlags
|= wxPG_FL_SCROLLED
;
5963 // -----------------------------------------------------------------------
5965 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5967 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5969 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5973 // -----------------------------------------------------------------------
5974 // Property editor related functions
5975 // -----------------------------------------------------------------------
5977 // noDefCheck = true prevents infinite recursion.
5978 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5979 const wxString
& editorName
,
5982 wxASSERT( editorClass
);
5984 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5985 RegisterDefaultEditors();
5987 wxString name
= editorName
;
5988 if ( name
.length() == 0 )
5989 name
= editorClass
->GetName();
5991 // Existing editor under this name?
5992 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5994 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5996 // If this name was already used, try class name.
5997 name
= editorClass
->GetClassInfo()->GetClassName();
5998 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
6001 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
6002 (wxPGEditor
*) vt_it
->second
,
6003 "Editor with given name was already registered" );
6005 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
6010 // Use this in RegisterDefaultEditors.
6011 #define wxPGRegisterDefaultEditorClass(EDITOR) \
6012 if ( wxPGEditor_##EDITOR == NULL ) \
6014 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
6015 new wxPG##EDITOR##Editor, true ); \
6018 // Registers all default editor classes
6019 void wxPropertyGrid::RegisterDefaultEditors()
6021 wxPGRegisterDefaultEditorClass( TextCtrl
);
6022 wxPGRegisterDefaultEditorClass( Choice
);
6023 wxPGRegisterDefaultEditorClass( ComboBox
);
6024 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
6025 #if wxPG_INCLUDE_CHECKBOX
6026 wxPGRegisterDefaultEditorClass( CheckBox
);
6028 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
6030 // Register SpinCtrl etc. editors before use
6031 RegisterAdditionalEditors();
6034 // -----------------------------------------------------------------------
6035 // wxPGStringTokenizer
6036 // Needed to handle C-style string lists (e.g. "str1" "str2")
6037 // -----------------------------------------------------------------------
6039 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
6040 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
6044 wxPGStringTokenizer::~wxPGStringTokenizer()
6048 bool wxPGStringTokenizer::HasMoreTokens()
6050 const wxString
& str
= *m_str
;
6052 wxString::const_iterator i
= m_curPos
;
6054 wxUniChar delim
= m_delimeter
;
6056 wxUniChar prev_a
= wxT('\0');
6058 bool inToken
= false;
6060 while ( i
!= str
.end() )
6069 m_readyToken
.clear();
6074 if ( prev_a
!= wxT('\\') )
6078 if ( a
!= wxT('\\') )
6098 m_curPos
= str
.end();
6106 wxString
wxPGStringTokenizer::GetNextToken()
6108 return m_readyToken
;
6111 // -----------------------------------------------------------------------
6113 // -----------------------------------------------------------------------
6115 wxPGChoiceEntry::wxPGChoiceEntry()
6116 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
6120 // -----------------------------------------------------------------------
6122 // -----------------------------------------------------------------------
6124 wxPGChoicesData::wxPGChoicesData()
6128 wxPGChoicesData::~wxPGChoicesData()
6133 void wxPGChoicesData::Clear()
6138 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
6140 wxASSERT( m_items
.size() == 0 );
6142 m_items
= data
->m_items
;
6145 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
6146 const wxPGChoiceEntry
& item
)
6148 wxVector
<wxPGChoiceEntry
>::iterator it
;
6152 index
= (int) m_items
.size();
6156 it
= m_items
.begin() + index
;
6159 m_items
.insert(it
, item
);
6161 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
6163 // Need to fix value?
6164 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
6165 ownEntry
.SetValue(index
);
6170 // -----------------------------------------------------------------------
6171 // wxPropertyGridEvent
6172 // -----------------------------------------------------------------------
6174 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
6177 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
6178 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
6179 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
6180 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
6181 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
6182 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
6183 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
6184 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
6185 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
6186 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
6187 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
6188 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
6189 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
6190 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
6192 // -----------------------------------------------------------------------
6194 void wxPropertyGridEvent::Init()
6196 m_validationInfo
= NULL
;
6199 m_wasVetoed
= false;
6202 // -----------------------------------------------------------------------
6204 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6205 : wxCommandEvent(commandType
,id
)
6211 // -----------------------------------------------------------------------
6213 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6214 : wxCommandEvent(event
)
6216 m_eventType
= event
.GetEventType();
6217 m_eventObject
= event
.m_eventObject
;
6219 OnPropertyGridSet();
6220 m_property
= event
.m_property
;
6221 m_validationInfo
= event
.m_validationInfo
;
6222 m_canVeto
= event
.m_canVeto
;
6223 m_wasVetoed
= event
.m_wasVetoed
;
6226 // -----------------------------------------------------------------------
6228 void wxPropertyGridEvent::OnPropertyGridSet()
6234 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6236 m_pg
->m_liveEvents
.push_back(this);
6239 // -----------------------------------------------------------------------
6241 wxPropertyGridEvent::~wxPropertyGridEvent()
6246 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6249 // Use iterate from the back since it is more likely that the event
6250 // being desroyed is at the end of the array.
6251 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
6253 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
6255 if ( liveEvents
[i
] == this )
6257 liveEvents
.erase(liveEvents
.begin() + i
);
6264 // -----------------------------------------------------------------------
6266 wxEvent
* wxPropertyGridEvent::Clone() const
6268 return new wxPropertyGridEvent( *this );
6271 // -----------------------------------------------------------------------
6272 // wxPropertyGridPopulator
6273 // -----------------------------------------------------------------------
6275 wxPropertyGridPopulator::wxPropertyGridPopulator()
6279 wxPGGlobalVars
->m_offline
++;
6282 // -----------------------------------------------------------------------
6284 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6287 m_propHierarchy
.clear();
6290 // -----------------------------------------------------------------------
6292 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6298 // -----------------------------------------------------------------------
6300 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6303 // Free unused sets of choices
6304 wxPGHashMapS2P::iterator it
;
6306 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6308 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6315 m_pg
->GetPanel()->Refresh();
6317 wxPGGlobalVars
->m_offline
--;
6320 // -----------------------------------------------------------------------
6322 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6323 const wxString
& propLabel
,
6324 const wxString
& propName
,
6325 const wxString
* propValue
,
6326 wxPGChoices
* pChoices
)
6328 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6329 wxPGProperty
* parent
= GetCurParent();
6331 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6333 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6337 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6339 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6343 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6345 property
->SetLabel(propLabel
);
6346 property
->DoSetName(propName
);
6348 if ( pChoices
&& pChoices
->IsOk() )
6349 property
->SetChoices(*pChoices
);
6351 m_state
->DoInsert(parent
, -1, property
);
6354 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
6355 wxPG_PROGRAMMATIC_VALUE
);
6360 // -----------------------------------------------------------------------
6362 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6364 m_propHierarchy
.push_back(property
);
6365 DoScanForChildren();
6366 m_propHierarchy
.pop_back();
6369 // -----------------------------------------------------------------------
6371 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6372 const wxString
& idString
)
6374 wxPGChoices choices
;
6377 if ( choicesString
[0] == wxT('@') )
6379 wxString ids
= choicesString
.substr(1);
6380 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6381 if ( it
== m_dictIdChoices
.end() )
6382 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6384 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6389 if ( idString
.length() )
6391 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6392 if ( it
!= m_dictIdChoices
.end() )
6394 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6401 // Parse choices string
6402 wxString::const_iterator it
= choicesString
.begin();
6406 bool labelValid
= false;
6408 for ( ; it
!= choicesString
.end(); ++it
)
6414 if ( c
== wxT('"') )
6419 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6420 choices
.Add(label
, l
);
6423 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6428 else if ( c
== wxT('=') )
6435 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6442 if ( c
== wxT('"') )
6455 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6456 choices
.Add(label
, l
);
6459 if ( !choices
.IsOk() )
6461 choices
.EnsureData();
6465 if ( idString
.length() )
6466 m_dictIdChoices
[idString
] = choices
.GetData();
6473 // -----------------------------------------------------------------------
6475 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6477 if ( s
.Last() == wxT('%') )
6479 wxString s2
= s
.substr(0,s
.length()-1);
6481 if ( s2
.ToLong(&val
, 10) )
6483 *pval
= (val
*max
)/100;
6489 return s
.ToLong(pval
, 10);
6492 // -----------------------------------------------------------------------
6494 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6495 const wxString
& type
,
6496 const wxString
& value
)
6498 int l
= m_propHierarchy
.size();
6502 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6503 wxString valuel
= value
.Lower();
6506 if ( type
.length() == 0 )
6511 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6513 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6515 else if ( value
.ToLong(&v
, 0) )
6522 if ( type
== wxT("string") )
6526 else if ( type
== wxT("int") )
6529 value
.ToLong(&v
, 0);
6532 else if ( type
== wxT("bool") )
6534 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6541 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6546 p
->SetAttribute( name
, variant
);
6551 // -----------------------------------------------------------------------
6553 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6555 wxLogError(_("Error in resource: %s"),msg
.c_str());
6558 // -----------------------------------------------------------------------
6560 #endif // wxUSE_PROPGRID