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 // Make sure the global pointers have been reset
239 wxASSERT(wxPG_EDITOR(TextCtrl
) == NULL
);
240 wxASSERT(wxPG_EDITOR(ChoiceAndButton
) == NULL
);
242 delete wxPGProperty::sm_wxPG_LABEL
;
245 void wxPropertyGridInitGlobalsIfNeeded()
249 // -----------------------------------------------------------------------
251 // -----------------------------------------------------------------------
253 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxControl
)
255 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxControl
)
256 EVT_IDLE(wxPropertyGrid::OnIdle
)
257 EVT_PAINT(wxPropertyGrid::OnPaint
)
258 EVT_SIZE(wxPropertyGrid::OnResize
)
259 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
260 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
261 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
262 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
263 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
264 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
265 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
266 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
267 EVT_MOTION(wxPropertyGrid::OnMouseMove
)
268 EVT_LEFT_DOWN(wxPropertyGrid::OnMouseClick
)
269 EVT_LEFT_UP(wxPropertyGrid::OnMouseUp
)
270 EVT_RIGHT_UP(wxPropertyGrid::OnMouseRightClick
)
271 EVT_LEFT_DCLICK(wxPropertyGrid::OnMouseDoubleClick
)
272 EVT_KEY_DOWN(wxPropertyGrid::OnKey
)
275 // -----------------------------------------------------------------------
277 wxPropertyGrid::wxPropertyGrid()
278 : wxControl(), wxScrollHelper(this)
283 // -----------------------------------------------------------------------
285 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
290 const wxString
& name
)
291 : wxControl(), wxScrollHelper(this)
294 Create(parent
,id
,pos
,size
,style
,name
);
297 // -----------------------------------------------------------------------
299 bool wxPropertyGrid::Create( wxWindow
*parent
,
304 const wxString
& name
)
307 if (!(style
&wxBORDER_MASK
))
309 style
|= wxBORDER_THEME
;
314 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
315 style
&= ~(wxTAB_TRAVERSAL
);
316 style
|= wxWANTS_CHARS
;
318 wxControl::Create(parent
, id
, pos
, size
,
319 style
| wxScrolledWindowStyle
,
328 // -----------------------------------------------------------------------
331 // Initialize values to defaults
333 void wxPropertyGrid::Init1()
335 // Register editor classes, if necessary.
336 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
337 wxPropertyGrid::RegisterDefaultEditors();
339 m_validatingEditor
= 0;
342 m_wndEditor
= m_wndEditor2
= NULL
;
346 m_labelEditor
= NULL
;
347 m_labelEditorProperty
= NULL
;
348 m_eventObject
= this;
350 m_processedEvent
= NULL
;
351 m_sortFunction
= NULL
;
352 m_inDoPropertyChanged
= false;
353 m_inCommitChangesFromEditor
= false;
354 m_inDoSelectProperty
= false;
355 m_inOnValidationFailure
= false;
356 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
361 // Set up default unspecified value 'colour'
362 m_unspecifiedAppearance
.SetFgCol(*wxLIGHT_GREY
);
365 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
366 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
367 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
368 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
369 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
370 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
371 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
372 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
373 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
375 m_coloursCustomized
= 0;
378 m_doubleBuffer
= NULL
;
380 #ifndef wxPG_ICON_WIDTH
386 m_iconWidth
= wxPG_ICON_WIDTH
;
391 m_gutterWidth
= wxPG_GUTTER_MIN
;
392 m_subgroup_extramargin
= 10;
396 m_width
= m_height
= 0;
398 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
401 m_chgInfo_changedProperty
= NULL
;
404 // -----------------------------------------------------------------------
407 // Initialize after parent etc. set
409 void wxPropertyGrid::Init2()
411 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
414 // Smaller controls on Mac
415 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
418 // Now create state, if one didn't exist already
419 // (wxPropertyGridManager might have created it for us).
422 m_pState
= CreateState();
423 m_pState
->m_pPropGrid
= this;
424 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
427 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
428 m_pState
->m_dontCenterSplitter
= true;
430 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
432 m_pState
->InitNonCatMode();
434 m_pState
->m_properties
= m_pState
->m_abcArray
;
437 GetClientSize(&m_width
,&m_height
);
439 #ifndef wxPG_ICON_WIDTH
440 // create two bitmap nodes for drawing
441 m_expandbmp
= new wxBitmap(expand_xpm
);
442 m_collbmp
= new wxBitmap(collapse_xpm
);
444 // calculate average font height for bitmap centering
446 m_iconWidth
= m_expandbmp
->GetWidth();
447 m_iconHeight
= m_expandbmp
->GetHeight();
450 m_curcursor
= wxCURSOR_ARROW
;
451 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
453 // adjust bitmap icon y position so they are centered
454 m_vspacing
= wxPG_DEFAULT_VSPACING
;
456 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
458 // Allocate cell datas
459 m_propertyDefaultCell
.SetEmptyData();
460 m_categoryDefaultCell
.SetEmptyData();
464 // This helps with flicker
465 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
467 // Hook the top-level parent
472 // set virtual size to this window size
473 wxSize wndsize
= GetSize();
474 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
476 m_timeCreated
= ::wxGetLocalTimeMillis();
478 m_iFlags
|= wxPG_FL_INITIALIZED
;
480 m_ncWidth
= wndsize
.GetWidth();
482 // Need to call OnResize handler or size given in constructor/Create
484 wxSizeEvent
sizeEvent(wndsize
,0);
488 // -----------------------------------------------------------------------
490 wxPropertyGrid::~wxPropertyGrid()
495 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
499 // Remove grid and property pointers from live wxPropertyGridEvents.
500 for ( i
=0; i
<m_liveEvents
.size(); i
++ )
502 wxPropertyGridEvent
* evt
= m_liveEvents
[i
];
503 evt
->SetPropertyGrid(NULL
);
504 evt
->SetProperty(NULL
);
506 m_liveEvents
.clear();
508 if ( m_processedEvent
)
510 // All right... we are being deleted while wxPropertyGrid event
511 // is being sent. Make sure that event propagates as little
512 // as possible (although usually this is not enough to prevent
514 m_processedEvent
->Skip(false);
515 m_processedEvent
->StopPropagation();
517 // Let's use wxMessageBox to make the message appear more
518 // reliably (and *before* the crash can happen).
519 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
520 "generated by it. This usually leads to a crash "
521 "so it is recommended to destroy the control "
522 "at idle time instead.");
525 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
527 // This should do prevent things from going too badly wrong
528 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
530 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
533 // Call with NULL to disconnect event handling
534 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
538 wxASSERT_MSG( !IsEditorsValueModified(),
539 wxS("Most recent change in property editor was ")
540 wxS("lost!!! (if you don't want this to happen, ")
541 wxS("close your frames and dialogs using ")
542 wxS("Close(false).)") );
545 if ( m_doubleBuffer
)
546 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 wxDELETE(m_doubleBuffer
);
1130 wxControl::SetExtraStyle( exStyle
);
1132 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1133 m_pState
->InitNonCatMode();
1135 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1136 m_windowStyle
|= wxPG_TOOLTIPS
;
1139 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1142 // -----------------------------------------------------------------------
1144 // returns the best acceptable minimal size
1145 wxSize
wxPropertyGrid::DoGetBestSize() const
1147 int lineHeight
= wxMax(15, m_lineHeight
);
1149 // don't make the grid too tall (limit height to 10 items) but don't
1150 // make it too small neither
1151 int numLines
= wxMin
1153 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1157 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1158 int width
= m_marginWidth
;
1159 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1161 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1164 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1170 // -----------------------------------------------------------------------
1172 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1174 if ( newTLP
== m_tlp
)
1177 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1180 // Parent changed so let's redetermine and re-hook the
1181 // correct top-level window.
1184 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1185 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1187 m_tlpClosed
= m_tlp
;
1188 m_tlpClosedTime
= currentTime
;
1193 // Only accept new tlp if same one was not just dismissed.
1194 if ( newTLP
!= m_tlpClosed
||
1195 m_tlpClosedTime
+250 < currentTime
)
1197 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1198 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1211 // -----------------------------------------------------------------------
1213 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1215 // ClearSelection forces value validation/commit.
1216 if ( event
.CanVeto() && !DoClearSelection() )
1222 // Ok, it can close, set tlp pointer to NULL. Some other event
1223 // handler can of course veto the close, but our OnIdle() should
1224 // then be able to regain the tlp pointer.
1225 OnTLPChanging(NULL
);
1230 // -----------------------------------------------------------------------
1232 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1234 OnTLPChanging((wxWindow
*)newParent
);
1236 bool res
= wxControl::Reparent(newParent
);
1241 // -----------------------------------------------------------------------
1242 // wxPropertyGrid Font and Colour Methods
1243 // -----------------------------------------------------------------------
1245 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1249 m_captionFont
= wxControl::GetFont();
1251 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1252 m_subgroup_extramargin
= x
+ (x
/2);
1255 #if wxPG_USE_RENDERER_NATIVE
1256 m_iconWidth
= wxPG_ICON_WIDTH
;
1257 #elif wxPG_ICON_WIDTH
1259 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1260 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1261 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1265 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1266 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1267 m_gutterWidth
= wxPG_GUTTER_MIN
;
1270 if ( vspacing
<= 1 ) vdiv
= 12;
1271 else if ( vspacing
>= 3 ) vdiv
= 3;
1273 m_spacingy
= m_fontHeight
/ vdiv
;
1274 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1275 m_spacingy
= wxPG_YSPACING_MIN
;
1278 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1279 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1281 m_captionFont
.SetWeight(wxBOLD
);
1282 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1284 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1287 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1288 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1291 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1293 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1294 RecalculateVirtualSize();
1296 InvalidateBestSize();
1299 // -----------------------------------------------------------------------
1301 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1307 // -----------------------------------------------------------------------
1309 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1310 int ga
= 1000, int ba
= 1000,
1311 bool forceDifferent
= false)
1318 // Recursion guard (allow 2 max)
1319 static int isinside
= 0;
1321 wxCHECK_MSG( isinside
< 3,
1323 wxT("wxPGAdjustColour should not be recursively called more than once") );
1328 int g
= src
.Green();
1331 if ( r2
>255 ) r2
= 255;
1332 else if ( r2
<0) r2
= 0;
1334 if ( g2
>255 ) g2
= 255;
1335 else if ( g2
<0) g2
= 0;
1337 if ( b2
>255 ) b2
= 255;
1338 else if ( b2
<0) b2
= 0;
1340 // Make sure they are somewhat different
1341 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1342 dst
= wxPGAdjustColour(src
,-(ra
*2));
1344 dst
= wxColour(r2
,g2
,b2
);
1346 // Recursion guard (allow 2 max)
1353 static int wxPGGetColAvg( const wxColour
& col
)
1355 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1359 void wxPropertyGrid::RegainColours()
1361 if ( !(m_coloursCustomized
& 0x0002) )
1363 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1365 // Make sure colour is dark enough
1367 int colDec
= wxPGGetColAvg(col
) - 230;
1369 int colDec
= wxPGGetColAvg(col
) - 200;
1372 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1375 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1378 if ( !(m_coloursCustomized
& 0x0001) )
1379 m_colMargin
= m_colCapBack
;
1381 if ( !(m_coloursCustomized
& 0x0004) )
1388 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1389 m_colCapFore
= capForeCol
;
1390 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1393 if ( !(m_coloursCustomized
& 0x0008) )
1395 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1396 m_colPropBack
= bgCol
;
1397 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1398 if ( !m_unspecifiedAppearance
.GetBgCol().IsOk() )
1399 m_unspecifiedAppearance
.SetBgCol(bgCol
);
1402 if ( !(m_coloursCustomized
& 0x0010) )
1404 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1405 m_colPropFore
= fgCol
;
1406 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1407 if ( !m_unspecifiedAppearance
.GetFgCol().IsOk() )
1408 m_unspecifiedAppearance
.SetFgCol(fgCol
);
1411 if ( !(m_coloursCustomized
& 0x0020) )
1412 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1414 if ( !(m_coloursCustomized
& 0x0040) )
1415 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1417 if ( !(m_coloursCustomized
& 0x0080) )
1418 m_colLine
= m_colCapBack
;
1420 if ( !(m_coloursCustomized
& 0x0100) )
1421 m_colDisPropFore
= m_colCapFore
;
1423 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1426 // -----------------------------------------------------------------------
1428 void wxPropertyGrid::ResetColours()
1430 m_coloursCustomized
= 0;
1437 // -----------------------------------------------------------------------
1439 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1441 // Must disable active editor.
1444 bool res
= wxControl::SetFont( font
);
1445 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1447 CalculateFontAndBitmapStuff( m_vspacing
);
1454 // -----------------------------------------------------------------------
1456 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1459 m_coloursCustomized
|= 0x80;
1463 // -----------------------------------------------------------------------
1465 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1468 m_coloursCustomized
|= 0x01;
1472 // -----------------------------------------------------------------------
1474 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1476 m_colPropBack
= col
;
1477 m_coloursCustomized
|= 0x08;
1479 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1480 m_unspecifiedAppearance
.SetBgCol(col
);
1485 // -----------------------------------------------------------------------
1487 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1489 m_colPropFore
= col
;
1490 m_coloursCustomized
|= 0x10;
1492 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1493 m_unspecifiedAppearance
.SetFgCol(col
);
1498 // -----------------------------------------------------------------------
1500 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1502 m_colEmptySpace
= col
;
1507 // -----------------------------------------------------------------------
1509 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1511 m_colDisPropFore
= col
;
1512 m_coloursCustomized
|= 0x100;
1516 // -----------------------------------------------------------------------
1518 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1521 m_coloursCustomized
|= 0x20;
1525 // -----------------------------------------------------------------------
1527 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1530 m_coloursCustomized
|= 0x40;
1534 // -----------------------------------------------------------------------
1536 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1539 m_coloursCustomized
|= 0x02;
1541 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1546 // -----------------------------------------------------------------------
1548 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1551 m_coloursCustomized
|= 0x04;
1553 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1558 // -----------------------------------------------------------------------
1559 // wxPropertyGrid property adding and removal
1560 // -----------------------------------------------------------------------
1562 void wxPropertyGrid::PrepareAfterItemsAdded()
1564 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1566 m_pState
->m_itemsAdded
= 0;
1568 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1569 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1571 RecalculateVirtualSize();
1573 // Fix editor position
1574 CorrectEditorWidgetPosY();
1577 // -----------------------------------------------------------------------
1578 // wxPropertyGrid property operations
1579 // -----------------------------------------------------------------------
1581 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1583 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1587 bool changed
= false;
1589 // Is it inside collapsed section?
1590 if ( !p
->IsVisible() )
1593 wxPGProperty
* parent
= p
->GetParent();
1594 wxPGProperty
* grandparent
= parent
->GetParent();
1596 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1597 Expand( grandparent
);
1605 GetViewStart(&vx
,&vy
);
1606 vy
*=wxPG_PIXELS_PER_UNIT
;
1612 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1613 m_iFlags
|= wxPG_FL_SCROLLED
;
1616 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1618 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1619 m_iFlags
|= wxPG_FL_SCROLLED
;
1629 // -----------------------------------------------------------------------
1630 // wxPropertyGrid helper methods called by properties
1631 // -----------------------------------------------------------------------
1633 // Control font changer helper.
1634 void wxPropertyGrid::SetCurControlBoldFont()
1636 wxWindow
* editor
= GetEditorControl();
1637 editor
->SetFont( m_captionFont
);
1640 // -----------------------------------------------------------------------
1642 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1645 #if wxPG_SMALL_SCREEN
1646 // On small-screen devices, always show dialogs with default position and size.
1647 return wxDefaultPosition
;
1649 int splitterX
= GetSplitterPosition();
1653 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1655 ImprovedClientToScreen( &x
, &y
);
1657 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1658 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1665 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1675 new_y
= y
+ m_lineHeight
;
1677 return wxPoint(new_x
,new_y
);
1681 // -----------------------------------------------------------------------
1683 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1685 if ( src_str
.empty() )
1691 bool prev_is_slash
= false;
1693 wxString::const_iterator i
= src_str
.begin();
1697 for ( ; i
!= src_str
.end(); ++i
)
1701 if ( a
!= wxS('\\') )
1703 if ( !prev_is_slash
)
1709 if ( a
== wxS('n') )
1712 dst_str
<< wxS('\n');
1714 dst_str
<< wxS('\n');
1717 else if ( a
== wxS('t') )
1718 dst_str
<< wxS('\t');
1722 prev_is_slash
= false;
1726 if ( prev_is_slash
)
1728 dst_str
<< wxS('\\');
1729 prev_is_slash
= false;
1733 prev_is_slash
= true;
1740 // -----------------------------------------------------------------------
1742 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1744 if ( src_str
.empty() )
1750 wxString::const_iterator i
= src_str
.begin();
1751 wxUniChar prev_a
= wxS('\0');
1755 for ( ; i
!= src_str
.end(); ++i
)
1759 if ( a
>= wxS(' ') )
1761 // This surely is not something that requires an escape sequence.
1766 // This might need...
1767 if ( a
== wxS('\r') )
1769 // DOS style line end.
1770 // Already taken care below
1772 else if ( a
== wxS('\n') )
1773 // UNIX style line end.
1774 dst_str
<< wxS("\\n");
1775 else if ( a
== wxS('\t') )
1777 dst_str
<< wxS('\t');
1780 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1790 // -----------------------------------------------------------------------
1792 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1799 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1802 // -----------------------------------------------------------------------
1803 // wxPropertyGrid graphics related methods
1804 // -----------------------------------------------------------------------
1806 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1811 // Don't paint after destruction has begun
1812 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1815 // Find out where the window is scrolled to
1816 int vx
,vy
; // Top left corner of client
1817 GetViewStart(&vx
,&vy
);
1818 vy
*= wxPG_PIXELS_PER_UNIT
;
1820 // Update everything inside the box
1821 wxRect r
= GetUpdateRegion().GetBox();
1825 // FIXME: This is just a workaround for a bug that causes splitters not
1826 // to paint when other windows are being dragged over the grid.
1828 r
.width
= GetClientSize().x
;
1831 r
.height
= GetClientSize().y
;
1833 // Repaint this rectangle
1834 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1836 // We assume that the size set when grid is shown
1837 // is what is desired.
1838 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1841 // -----------------------------------------------------------------------
1843 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1844 wxPGProperty
* property
) const
1846 // Prepare rectangle to be used
1848 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1849 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1851 #if (wxPG_USE_RENDERER_NATIVE)
1853 #elif wxPG_ICON_WIDTH
1854 // Drawing expand/collapse button manually
1855 dc
.SetPen(m_colPropFore
);
1856 if ( property
->IsCategory() )
1857 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1859 dc
.SetBrush(m_colPropBack
);
1861 dc
.DrawRectangle( r
);
1862 int _y
= r
.y
+(m_iconWidth
/2);
1863 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1868 if ( property
->IsExpanded() )
1870 // wxRenderer functions are non-mutating in nature, so it
1871 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1872 // Hopefully this does not cause problems.
1873 #if (wxPG_USE_RENDERER_NATIVE)
1874 wxRendererNative::Get().DrawTreeItemButton(
1880 #elif wxPG_ICON_WIDTH
1889 #if (wxPG_USE_RENDERER_NATIVE)
1890 wxRendererNative::Get().DrawTreeItemButton(
1896 #elif wxPG_ICON_WIDTH
1897 int _x
= r
.x
+(m_iconWidth
/2);
1898 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1904 #if (wxPG_USE_RENDERER_NATIVE)
1906 #elif wxPG_ICON_WIDTH
1909 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1913 // -----------------------------------------------------------------------
1916 // This is the one called by OnPaint event handler and others.
1917 // topy and bottomy are already unscrolled (ie. physical)
1919 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1920 unsigned int topItemY
,
1921 unsigned int bottomItemY
,
1922 const wxRect
* itemsRect
)
1926 bottomItemY
< topItemY
||
1930 m_pState
->EnsureVirtualHeight();
1932 wxRect tempItemsRect
;
1935 tempItemsRect
= wxRect(0, topItemY
,
1938 itemsRect
= &tempItemsRect
;
1942 GetViewStart(&vx
, &vy
);
1943 vx
*= wxPG_PIXELS_PER_UNIT
;
1944 vy
*= wxPG_PIXELS_PER_UNIT
;
1946 // itemRect is in virtual grid space
1947 wxRect
drawRect(itemsRect
->x
- vx
,
1952 // items added check
1953 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1955 int paintFinishY
= 0;
1957 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1960 bool isBuffered
= false;
1962 wxMemoryDC
* bufferDC
= NULL
;
1964 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1966 if ( !m_doubleBuffer
)
1968 paintFinishY
= itemsRect
->y
;
1973 bufferDC
= new wxMemoryDC();
1975 // If nothing was changed, then just copy from double-buffer
1976 bufferDC
->SelectObject( *m_doubleBuffer
);
1985 // paintFinishY and drawBottomY are in buffer/physical space
1986 paintFinishY
= DoDrawItems( *dcPtr
, itemsRect
, isBuffered
);
1987 int drawBottomY
= itemsRect
->y
+ itemsRect
->height
- vy
;
1989 // Clear area beyond last painted property
1990 if ( paintFinishY
< drawBottomY
)
1992 dcPtr
->SetPen(m_colEmptySpace
);
1993 dcPtr
->SetBrush(m_colEmptySpace
);
1994 dcPtr
->DrawRectangle(0, paintFinishY
,
2002 dc
.Blit( drawRect
.x
, drawRect
.y
, drawRect
.width
,
2004 bufferDC
, 0, 0, wxCOPY
);
2010 // Just clear the area
2011 dc
.SetPen(m_colEmptySpace
);
2012 dc
.SetBrush(m_colEmptySpace
);
2013 dc
.DrawRectangle(drawRect
);
2017 // -----------------------------------------------------------------------
2019 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
2020 const wxRect
* itemsRect
,
2021 bool isBuffered
) const
2023 const wxPGProperty
* firstItem
;
2024 const wxPGProperty
* lastItem
;
2026 firstItem
= DoGetItemAtY(itemsRect
->y
);
2027 lastItem
= DoGetItemAtY(itemsRect
->y
+itemsRect
->height
-1);
2030 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
2032 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
2033 return itemsRect
->y
;
2035 wxCHECK_MSG( !m_pState
->m_itemsAdded
, itemsRect
->y
,
2037 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2039 int lh
= m_lineHeight
;
2042 int lastItemBottomY
;
2044 firstItemTopY
= itemsRect
->y
;
2045 lastItemBottomY
= itemsRect
->y
+ itemsRect
->height
;
2047 // Align y coordinates to item boundaries
2048 firstItemTopY
-= firstItemTopY
% lh
;
2049 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2050 lastItemBottomY
-= 1;
2052 // Entire range outside scrolled, visible area?
2053 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
2054 lastItemBottomY
<= 0 )
2055 return itemsRect
->y
;
2057 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
2059 "invalid y values" );
2062 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
2063 "height=%i (ch=%i), itemsRect = 0x%lX )",
2064 firstItem->GetLabel().c_str(),
2065 lastItem->GetLabel().c_str(),
2066 (int)(lastItemBottomY - firstItemTopY),
2068 (unsigned long)&itemsRect );
2073 long windowStyle
= m_windowStyle
;
2078 // For now, do some manual calculation for double buffering
2079 // - buffer's y = 0, so align itemsRect and coordinates to that
2081 // TODO: In future use wxAutoBufferedPaintDC (for example)
2089 xRelMod
= itemsRect
->x
;
2090 yRelMod
= itemsRect
->y
;
2093 // itemsRect conversion
2098 firstItemTopY
-= yRelMod
;
2099 lastItemBottomY
-= yRelMod
;
2102 int x
= m_marginWidth
- xRelMod
;
2104 wxFont normalFont
= GetFont();
2106 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2108 bool isPgEnabled
= IsEnabled();
2111 // Prepare some pens and brushes that are often changed to.
2114 wxBrush
marginBrush(m_colMargin
);
2115 wxPen
marginPen(m_colMargin
);
2116 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2117 wxPen
linepen(m_colLine
,1,wxSOLID
);
2119 wxColour selBackCol
;
2121 selBackCol
= m_colSelBack
;
2123 selBackCol
= m_colMargin
;
2125 // pen that has same colour as text
2126 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2129 // Clear margin with background colour
2131 dc
.SetBrush( marginBrush
);
2132 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2134 dc
.SetPen( *wxTRANSPARENT_PEN
);
2135 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2138 const wxPGProperty
* firstSelected
= GetSelection();
2139 const wxPropertyGridPageState
* state
= m_pState
;
2140 const wxArrayInt
& colWidths
= state
->m_colWidths
;
2142 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2143 bool wasSelectedPainted
= false;
2146 // TODO: Only render columns that are within clipping region.
2148 dc
.SetFont(normalFont
);
2150 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2151 int endScanBottomY
= lastItemBottomY
+ lh
;
2152 int y
= firstItemTopY
;
2155 // Pregenerate list of visible properties.
2156 wxArrayPGProperty visPropArray
;
2157 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2159 for ( ; !it
.AtEnd(); it
.Next() )
2161 const wxPGProperty
* p
= *it
;
2163 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2165 visPropArray
.push_back((wxPGProperty
*)p
);
2167 if ( y
> endScanBottomY
)
2174 visPropArray
.push_back(NULL
);
2176 wxPGProperty
* nextP
= visPropArray
[0];
2178 int gridWidth
= state
->m_width
;
2181 for ( unsigned int arrInd
=1;
2182 nextP
&& y
<= lastItemBottomY
;
2185 wxPGProperty
* p
= nextP
;
2186 nextP
= visPropArray
[arrInd
];
2188 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2189 int textMarginHere
= x
;
2190 int renderFlags
= 0;
2192 int greyDepth
= m_marginWidth
;
2193 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2194 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2196 int greyDepthX
= greyDepth
- xRelMod
;
2198 // Use basic depth if in non-categoric mode and parent is base array.
2199 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2201 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2204 // Paint margin area
2205 dc
.SetBrush(marginBrush
);
2206 dc
.SetPen(marginPen
);
2207 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2209 dc
.SetPen( linepen
);
2215 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2216 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2217 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2219 // Is this or its parent themed?
2220 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2221 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2222 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2224 bool suppressMarginEdge
= false;
2226 if (!suppressMarginEdge
)
2227 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2230 // Blank out the margin edge
2231 dc
.SetPen(wxPen(GetBackgroundColour()));
2232 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2233 dc
.SetPen( linepen
);
2240 for ( si
=0; si
<colWidths
.size(); si
++ )
2242 sx
+= colWidths
[si
];
2243 dc
.DrawLine( sx
, y
, sx
, y2
);
2246 // Horizontal Line, below
2247 // (not if both this and next is category caption)
2248 if ( p
->IsCategory() &&
2249 nextP
&& nextP
->IsCategory() )
2250 dc
.SetPen(m_colCapBack
);
2252 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2255 // Need to override row colours?
2259 bool isSelected
= state
->DoIsPropertySelected(p
);
2263 // Disabled may get different colour.
2264 if ( !p
->IsEnabled() )
2266 renderFlags
|= wxPGCellRenderer::Disabled
|
2267 wxPGCellRenderer::DontUseCellFgCol
;
2268 rowFgCol
= m_colDisPropFore
;
2273 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2274 if ( p
== firstSelected
)
2275 wasSelectedPainted
= true;
2278 renderFlags
|= wxPGCellRenderer::Selected
;
2280 if ( !p
->IsCategory() )
2282 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2283 wxPGCellRenderer::DontUseCellBgCol
;
2285 if ( reallyFocused
&& p
== firstSelected
)
2287 rowFgCol
= m_colSelFore
;
2288 rowBgCol
= selBackCol
;
2290 else if ( isPgEnabled
)
2292 rowFgCol
= m_colPropFore
;
2293 if ( p
== firstSelected
)
2294 rowBgCol
= m_colMargin
;
2296 rowBgCol
= selBackCol
;
2300 rowFgCol
= m_colDisPropFore
;
2301 rowBgCol
= selBackCol
;
2308 if ( rowBgCol
.IsOk() )
2309 rowBgBrush
= wxBrush(rowBgCol
);
2311 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2312 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2315 // Fill additional margin area with background colour of first cell
2316 if ( greyDepthX
< textMarginHere
)
2318 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2320 wxPGCell
& cell
= p
->GetCell(0);
2321 rowBgCol
= cell
.GetBgCol();
2322 rowBgBrush
= wxBrush(rowBgCol
);
2324 dc
.SetBrush(rowBgBrush
);
2325 dc
.SetPen(rowBgCol
);
2326 dc
.DrawRectangle(greyDepthX
+1, y
,
2327 textMarginHere
-greyDepthX
, lh
-1);
2330 bool fontChanged
= false;
2332 // Expander button rectangle
2333 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2338 // Default cell rect fill the entire row
2339 wxRect
cellRect(greyDepthX
, y
,
2340 gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2342 bool isCategory
= p
->IsCategory();
2346 dc
.SetFont(m_captionFont
);
2349 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2351 dc
.SetBrush(rowBgBrush
);
2352 dc
.SetPen(rowBgCol
);
2355 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2357 dc
.SetTextForeground(rowFgCol
);
2362 // Fine tune button rectangle to actually fit the cell
2363 if ( butRect
.x
> 0 )
2364 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2366 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&&
2367 (windowStyle
& wxPG_BOLD_MODIFIED
) )
2369 dc
.SetFont(m_captionFont
);
2373 // Magic fine-tuning for non-category rows
2377 int firstCellWidth
= colWidths
[0] - (greyDepthX
- m_marginWidth
);
2378 int firstCellX
= cellRect
.x
;
2380 // Calculate cellRect.x for the last cell
2381 unsigned int ci
= 0;
2383 for ( ci
=0; ci
<colWidths
.size(); ci
++ )
2384 cellX
+= colWidths
[ci
];
2387 // Draw cells from back to front so that we can easily tell if the
2388 // cell on the right was empty from text
2389 bool prevFilled
= true;
2390 ci
= colWidths
.size();
2399 textXAdd
= textMarginHere
- greyDepthX
;
2400 cellRect
.width
= firstCellWidth
;
2401 cellRect
.x
= firstCellX
;
2405 int colWidth
= colWidths
[ci
];
2406 cellRect
.width
= colWidth
;
2407 cellRect
.x
-= colWidth
;
2410 // Merge with column to the right?
2411 if ( !prevFilled
&& isCategory
)
2413 cellRect
.width
+= colWidths
[ci
+1];
2417 cellRect
.width
-= 1;
2419 wxWindow
* cellEditor
= NULL
;
2420 int cellRenderFlags
= renderFlags
;
2422 // Tree Item Button (must be drawn before clipping is set up)
2423 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2424 DrawExpanderButton( dc
, butRect
, p
);
2427 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2429 if ( p
== firstSelected
)
2431 if ( ci
== 1 && m_wndEditor
)
2432 cellEditor
= m_wndEditor
;
2433 else if ( ci
== m_selColumn
&& m_labelEditor
)
2434 cellEditor
= m_labelEditor
;
2439 wxColour editorBgCol
=
2440 cellEditor
->GetBackgroundColour();
2441 dc
.SetBrush(editorBgCol
);
2442 dc
.SetPen(editorBgCol
);
2443 dc
.SetTextForeground(m_colPropFore
);
2444 dc
.DrawRectangle(cellRect
);
2446 if ( m_dragStatus
!= 0 ||
2447 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2452 dc
.SetBrush(m_colPropBack
);
2453 dc
.SetPen(m_colPropBack
);
2454 if ( p
->IsEnabled() )
2455 dc
.SetTextForeground(m_colPropFore
);
2457 dc
.SetTextForeground(m_colDisPropFore
);
2462 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2464 dc
.SetBrush(rowBgBrush
);
2465 dc
.SetPen(rowBgCol
);
2468 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2470 dc
.SetTextForeground(rowFgCol
);
2474 dc
.SetClippingRegion(cellRect
);
2476 cellRect
.x
+= textXAdd
;
2477 cellRect
.width
-= textXAdd
;
2482 wxPGCellRenderer
* renderer
;
2483 int cmnVal
= p
->GetCommonValue();
2484 if ( cmnVal
== -1 || ci
!= 1 )
2486 renderer
= p
->GetCellRenderer(ci
);
2487 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2493 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2494 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2504 dc
.DestroyClippingRegion(); // Is this really necessary?
2509 dc
.SetFont(normalFont
);
2514 // Refresh editor controls (seems not needed on msw)
2515 // NOTE: This code is mandatory for GTK!
2516 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2517 if ( wasSelectedPainted
)
2520 m_wndEditor
->Refresh();
2522 m_wndEditor2
->Refresh();
2529 // -----------------------------------------------------------------------
2531 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2535 if ( m_width
< 10 || m_height
< 10 ||
2536 !m_pState
->m_properties
->GetChildCount() ||
2538 return wxRect(0,0,0,0);
2543 // Return rect which encloses the given property range
2544 // (in logical grid coordinates)
2547 int visTop
= p1
->GetY();
2550 visBottom
= p2
->GetY() + m_lineHeight
;
2552 visBottom
= m_height
+ visTop
;
2554 // If seleced property is inside the range, we'll extend the range to include
2556 wxPGProperty
* selected
= GetSelection();
2559 int selectedY
= selected
->GetY();
2560 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2562 wxWindow
* editor
= GetEditorControl();
2565 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2566 if ( visBottom2
> visBottom
)
2567 visBottom
= visBottom2
;
2572 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2575 // -----------------------------------------------------------------------
2577 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2582 if ( m_pState
->m_itemsAdded
)
2583 PrepareAfterItemsAdded();
2585 wxRect r
= GetPropertyRect(p1
, p2
);
2588 // Convert rectangle from logical grid coordinates to physical ones
2590 GetViewStart(&vx
, &vy
);
2591 vx
*= wxPG_PIXELS_PER_UNIT
;
2592 vy
*= wxPG_PIXELS_PER_UNIT
;
2599 // -----------------------------------------------------------------------
2601 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2603 if ( m_pState
->DoIsPropertySelected(p
) || p
->IsChildSelected(true) )
2605 // NB: We must copy the selection.
2606 wxArrayPGProperty selection
= m_pState
->m_selection
;
2607 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2610 DrawItemAndChildren(p
);
2613 // -----------------------------------------------------------------------
2615 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2620 // Draw item, children, and parent too, if it is not category
2621 wxPGProperty
* parent
= p
->GetParent();
2624 !parent
->IsCategory() &&
2625 parent
->GetParent() )
2628 parent
= parent
->GetParent();
2631 DrawItemAndChildren(p
);
2634 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2636 wxCHECK_RET( p
, wxT("invalid property id") );
2638 // Do not draw if in non-visible page
2639 if ( p
->GetParentState() != m_pState
)
2642 // do not draw a single item if multiple pending
2643 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2646 // Update child control.
2647 wxPGProperty
* selected
= GetSelection();
2648 if ( selected
&& selected
->GetParent() == p
)
2651 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2653 DrawItems(p
, lastDrawn
);
2656 // -----------------------------------------------------------------------
2658 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2659 const wxRect
*rect
)
2661 PrepareAfterItemsAdded();
2663 wxWindow::Refresh(false, rect
);
2665 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2666 // I think this really helps only GTK+1.2
2667 if ( m_wndEditor
) m_wndEditor
->Refresh();
2668 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2672 // -----------------------------------------------------------------------
2673 // wxPropertyGrid global operations
2674 // -----------------------------------------------------------------------
2676 void wxPropertyGrid::Clear()
2678 m_pState
->DoClear();
2684 RecalculateVirtualSize();
2686 // Need to clear some area at the end
2688 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2691 // -----------------------------------------------------------------------
2693 bool wxPropertyGrid::EnableCategories( bool enable
)
2700 // Enable categories
2703 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2708 // Disable categories
2710 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2713 if ( !m_pState
->EnableCategories(enable
) )
2718 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2720 m_pState
->m_itemsAdded
= 1; // force
2721 PrepareAfterItemsAdded();
2725 m_pState
->m_itemsAdded
= 1;
2727 // No need for RecalculateVirtualSize() here - it is already called in
2728 // wxPropertyGridPageState method above.
2735 // -----------------------------------------------------------------------
2737 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2739 wxASSERT( pNewState
);
2740 wxASSERT( pNewState
->GetGrid() );
2742 if ( pNewState
== m_pState
)
2745 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2747 // Call ClearSelection() instead of DoClearSelection()
2748 // so that selection clear events are not sent.
2751 m_pState
->m_selection
= oldSelection
;
2753 bool orig_mode
= m_pState
->IsInNonCatMode();
2754 bool new_state_mode
= pNewState
->IsInNonCatMode();
2756 m_pState
= pNewState
;
2759 int pgWidth
= GetClientSize().x
;
2760 if ( HasVirtualWidth() )
2762 int minWidth
= pgWidth
;
2763 if ( pNewState
->m_width
< minWidth
)
2765 pNewState
->m_width
= minWidth
;
2766 pNewState
->CheckColumnWidths();
2772 // Just in case, fully re-center splitter
2773 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2774 // pNewState->m_fSplitterX = -1.0;
2776 pNewState
->OnClientWidthChange(pgWidth
,
2777 pgWidth
- pNewState
->m_width
);
2782 // If necessary, convert state to correct mode.
2783 if ( orig_mode
!= new_state_mode
)
2785 // This should refresh as well.
2786 EnableCategories( orig_mode
?false:true );
2788 else if ( !m_frozen
)
2790 // Refresh, if not frozen.
2791 m_pState
->PrepareAfterItemsAdded();
2793 // Reselect (Use SetSelection() instead of Do-variant so that
2794 // events won't be sent).
2795 SetSelection(m_pState
->m_selection
);
2797 RecalculateVirtualSize(0);
2801 m_pState
->m_itemsAdded
= 1;
2804 // -----------------------------------------------------------------------
2806 // Call to SetSplitterPosition will always disable splitter auto-centering
2807 // if parent window is shown.
2808 void wxPropertyGrid::DoSetSplitterPosition( int newxpos
,
2812 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2815 wxPropertyGridPageState
* state
= m_pState
;
2817 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2818 state
->m_dontCenterSplitter
= true;
2820 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2822 if ( flags
& wxPG_SPLITTER_REFRESH
)
2824 if ( GetSelection() )
2825 CorrectEditorWidgetSizeX();
2833 // -----------------------------------------------------------------------
2835 void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing
)
2837 wxPropertyGridPageState
* state
= m_pState
;
2839 state
->ResetColumnSizes(0);
2841 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2842 m_pState
->m_dontCenterSplitter
= false;
2845 // -----------------------------------------------------------------------
2847 void wxPropertyGrid::CenterSplitter( bool enableAutoResizing
)
2849 SetSplitterPosition( m_width
/2 );
2850 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2851 m_pState
->m_dontCenterSplitter
= false;
2854 // -----------------------------------------------------------------------
2855 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2856 // -----------------------------------------------------------------------
2858 // Returns nearest paint visible property (such that will be painted unless
2859 // window is scrolled or resized). If given property is paint visible, then
2860 // it itself will be returned
2861 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2863 int vx
,vy1
;// Top left corner of client
2864 GetViewStart(&vx
,&vy1
);
2865 vy1
*= wxPG_PIXELS_PER_UNIT
;
2867 int vy2
= vy1
+ m_height
;
2868 int propY
= p
->GetY2(m_lineHeight
);
2870 if ( (propY
+ m_lineHeight
) < vy1
)
2873 return DoGetItemAtY( vy1
);
2875 else if ( propY
> vy2
)
2878 return DoGetItemAtY( vy2
);
2881 // Itself paint visible
2886 // -----------------------------------------------------------------------
2887 // Methods related to change in value, value modification and sending events
2888 // -----------------------------------------------------------------------
2890 // commits any changes in editor of selected property
2891 // return true if validation did not fail
2892 // flags are same as with DoSelectProperty
2893 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2895 // Committing already?
2896 if ( m_inCommitChangesFromEditor
)
2899 // Don't do this if already processing editor event. It might
2900 // induce recursive dialogs and crap like that.
2901 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2903 if ( m_inDoPropertyChanged
)
2909 wxPGProperty
* selected
= GetSelection();
2912 IsEditorsValueModified() &&
2913 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2916 m_inCommitChangesFromEditor
= true;
2918 wxVariant
variant(selected
->GetValueRef());
2919 bool valueIsPending
= false;
2921 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2922 // due to another window getting focus
2923 wxWindow
* oldFocus
= m_curFocused
;
2925 bool validationFailure
= false;
2926 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2928 m_chgInfo_changedProperty
= NULL
;
2930 // If truly modified, schedule value as pending.
2931 if ( selected
->GetEditorClass()->
2932 GetValueFromControl( variant
,
2934 GetEditorControl() ) )
2936 if ( DoEditorValidate() &&
2937 PerformValidation(selected
, variant
) )
2939 valueIsPending
= true;
2943 validationFailure
= true;
2948 EditorsValueWasNotModified();
2951 m_inCommitChangesFromEditor
= false;
2955 if ( validationFailure
&& !forceSuccess
)
2959 oldFocus
->SetFocus();
2960 m_curFocused
= oldFocus
;
2963 res
= OnValidationFailure(selected
, variant
);
2965 // Now prevent further validation failure messages
2968 EditorsValueWasNotModified();
2969 OnValidationFailureReset(selected
);
2972 else if ( valueIsPending
)
2974 DoPropertyChanged( selected
, flags
);
2975 EditorsValueWasNotModified();
2984 // -----------------------------------------------------------------------
2986 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2990 // Runs all validation functionality.
2991 // Returns true if value passes all tests.
2994 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2995 m_validationInfo
.m_isFailing
= true;
2998 // Variant list a special value that cannot be validated
3000 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3002 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
3007 // Adapt list to child values, if necessary
3008 wxVariant listValue
= pendingValue
;
3009 wxVariant
* pPendingValue
= &pendingValue
;
3010 wxVariant
* pList
= NULL
;
3012 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
3013 // string value, then we need treat as it was changed instead
3014 // (or, in addition, as is the case with composite string parent).
3015 // This includes creating list variant for child values.
3017 wxPGProperty
* pwc
= p
->GetParent();
3018 wxPGProperty
* changedProperty
= p
;
3019 wxPGProperty
* baseChangedProperty
= changedProperty
;
3020 wxVariant bcpPendingList
;
3022 listValue
= pendingValue
;
3023 listValue
.SetName(p
->GetBaseName());
3026 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
3028 wxVariantList tempList
;
3029 wxVariant
lv(tempList
, pwc
->GetBaseName());
3030 lv
.Append(listValue
);
3032 pPendingValue
= &listValue
;
3034 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
3036 baseChangedProperty
= pwc
;
3037 bcpPendingList
= lv
;
3040 changedProperty
= pwc
;
3041 pwc
= pwc
->GetParent();
3045 wxPGProperty
* evtChangingProperty
= changedProperty
;
3047 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
3049 value
= *pPendingValue
;
3053 // Convert list to child values
3054 pList
= pPendingValue
;
3055 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
3058 wxVariant evtChangingValue
= value
;
3060 if ( flags
& SendEvtChanging
)
3062 // FIXME: After proper ValueToString()s added, remove
3063 // this. It is just a temporary fix, as evt_changing
3064 // will simply not work for wxPG_PROP_COMPOSED_VALUE
3065 // (unless it is selected, and textctrl editor is open).
3066 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3068 evtChangingProperty
= baseChangedProperty
;
3069 if ( evtChangingProperty
!= p
)
3071 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
3075 evtChangingValue
= pendingValue
;
3079 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3081 if ( changedProperty
== GetSelection() )
3083 wxWindow
* editor
= GetEditorControl();
3084 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
3085 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
3089 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
3094 wxASSERT( m_chgInfo_changedProperty
== NULL
);
3095 m_chgInfo_changedProperty
= changedProperty
;
3096 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
3097 m_chgInfo_pendingValue
= value
;
3100 m_chgInfo_valueList
= *pList
;
3102 m_chgInfo_valueList
.MakeNull();
3104 // If changedProperty is not property which value was edited,
3105 // then call wxPGProperty::ValidateValue() for that as well.
3106 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3108 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3112 if ( flags
& SendEvtChanging
)
3114 // SendEvent returns true if event was vetoed
3115 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3116 &evtChangingValue
) )
3120 if ( flags
& IsStandaloneValidation
)
3122 // If called in 'generic' context, we need to reset
3123 // m_chgInfo_changedProperty and write back translated value.
3124 m_chgInfo_changedProperty
= NULL
;
3125 pendingValue
= value
;
3128 m_validationInfo
.m_isFailing
= false;
3133 // -----------------------------------------------------------------------
3136 wxStatusBar
* wxPropertyGrid::GetStatusBar()
3138 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3139 if ( topWnd
&& topWnd
->IsKindOf(CLASSINFO(wxFrame
)) )
3141 wxFrame
* pFrame
= wxStaticCast(topWnd
, wxFrame
);
3143 return pFrame
->GetStatusBar();
3149 // -----------------------------------------------------------------------
3151 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3157 if ( !wxPGGlobalVars
->m_offline
)
3159 wxStatusBar
* pStatusBar
= GetStatusBar();
3162 pStatusBar
->SetStatusText(msg
);
3168 ::wxMessageBox(msg
, _("Property Error"));
3171 // -----------------------------------------------------------------------
3173 void wxPropertyGrid::DoHidePropertyError( wxPGProperty
* WXUNUSED(property
) )
3176 if ( !wxPGGlobalVars
->m_offline
)
3178 wxStatusBar
* pStatusBar
= GetStatusBar();
3181 pStatusBar
->SetStatusText(wxEmptyString
);
3188 // -----------------------------------------------------------------------
3190 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3191 wxVariant
& invalidValue
)
3193 if ( m_inOnValidationFailure
)
3196 m_inOnValidationFailure
= true;
3197 wxON_BLOCK_EXIT_SET(m_inOnValidationFailure
, false);
3199 wxWindow
* editor
= GetEditorControl();
3200 int vfb
= m_validationInfo
.m_failureBehavior
;
3202 if ( m_inDoSelectProperty
)
3204 // When property selection is being changed, do not display any
3205 // messages, if some were already shown for this property.
3206 if ( property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3208 m_validationInfo
.m_failureBehavior
=
3209 vfb
& ~(wxPG_VFB_SHOW_MESSAGE
|
3210 wxPG_VFB_SHOW_MESSAGEBOX
|
3211 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
);
3215 // First call property's handler
3216 property
->OnValidationFailure(invalidValue
);
3218 bool res
= DoOnValidationFailure(property
, invalidValue
);
3221 // For non-wxTextCtrl editors, we do need to revert the value
3222 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3223 property
== GetSelection() )
3225 property
->GetEditorClass()->UpdateControl(property
, editor
);
3228 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3233 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3235 int vfb
= m_validationInfo
.m_failureBehavior
;
3237 if ( vfb
& wxPG_VFB_BEEP
)
3240 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3241 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3243 unsigned int colCount
= m_pState
->GetColumnCount();
3245 // We need backup marked property's cells
3246 m_propCellsBackup
= property
->m_cells
;
3248 wxColour vfbFg
= *wxWHITE
;
3249 wxColour vfbBg
= *wxRED
;
3251 property
->EnsureCells(colCount
);
3253 for ( unsigned int i
=0; i
<colCount
; i
++ )
3255 wxPGCell
& cell
= property
->m_cells
[i
];
3256 cell
.SetFgCol(vfbFg
);
3257 cell
.SetBgCol(vfbBg
);
3260 DrawItemAndChildren(property
);
3262 if ( property
== GetSelection() )
3264 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3266 wxWindow
* editor
= GetEditorControl();
3269 editor
->SetForegroundColour(vfbFg
);
3270 editor
->SetBackgroundColour(vfbBg
);
3275 if ( vfb
& (wxPG_VFB_SHOW_MESSAGE
|
3276 wxPG_VFB_SHOW_MESSAGEBOX
|
3277 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
) )
3279 wxString msg
= m_validationInfo
.m_failureMessage
;
3282 msg
= _("You have entered invalid value. Press ESC to cancel editing.");
3285 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3287 if ( !wxPGGlobalVars
->m_offline
)
3289 wxStatusBar
* pStatusBar
= GetStatusBar();
3291 pStatusBar
->SetStatusText(msg
);
3296 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3297 DoShowPropertyError(property
, msg
);
3299 if ( vfb
& wxPG_VFB_SHOW_MESSAGEBOX
)
3300 ::wxMessageBox(msg
, _("Property Error"));
3303 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3306 // -----------------------------------------------------------------------
3308 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3310 int vfb
= m_validationInfo
.m_failureBehavior
;
3312 if ( vfb
& wxPG_VFB_MARK_CELL
)
3315 property
->m_cells
= m_propCellsBackup
;
3317 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3319 if ( property
== GetSelection() && GetEditorControl() )
3321 // Calling this will recreate the control, thus resetting its colour
3322 RefreshProperty(property
);
3326 DrawItemAndChildren(property
);
3331 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3333 if ( !wxPGGlobalVars
->m_offline
)
3335 wxStatusBar
* pStatusBar
= GetStatusBar();
3337 pStatusBar
->SetStatusText(wxEmptyString
);
3342 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3344 DoHidePropertyError(property
);
3347 m_validationInfo
.m_isFailing
= false;
3350 // -----------------------------------------------------------------------
3352 // flags are same as with DoSelectProperty
3353 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3355 if ( m_inDoPropertyChanged
)
3358 m_inDoPropertyChanged
= true;
3359 wxON_BLOCK_EXIT_SET(m_inDoPropertyChanged
, false);
3361 wxPGProperty
* selected
= GetSelection();
3363 m_pState
->m_anyModified
= 1;
3365 // If property's value is being changed, assume it is valid
3366 OnValidationFailureReset(selected
);
3368 // Maybe need to update control
3369 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3371 // These values were calculated in PerformValidation()
3372 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3373 wxVariant value
= m_chgInfo_pendingValue
;
3375 wxPGProperty
* topPaintedProperty
= changedProperty
;
3377 while ( !topPaintedProperty
->IsCategory() &&
3378 !topPaintedProperty
->IsRoot() )
3380 topPaintedProperty
= topPaintedProperty
->GetParent();
3383 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3385 // NB: Call GetEditorControl() as late as possible, because OnSetValue()
3386 // and perhaps other user-defined virtual functions may change it.
3387 wxWindow
* editor
= GetEditorControl();
3389 // Set as Modified (not if dragging just began)
3390 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3392 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3393 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3396 SetCurControlBoldFont();
3402 // Propagate updates to parent(s)
3404 wxPGProperty
* prevPwc
= NULL
;
3406 while ( prevPwc
!= topPaintedProperty
)
3408 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3410 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3413 SetCurControlBoldFont();
3417 pwc
= pwc
->GetParent();
3420 // Draw the actual property
3421 DrawItemAndChildren( topPaintedProperty
);
3424 // If value was set by wxPGProperty::OnEvent, then update the editor
3426 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3432 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3433 if ( m_wndEditor
) m_wndEditor
->Refresh();
3434 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3439 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3441 // If top parent has composite string value, then send to child parents,
3442 // starting from baseChangedProperty.
3443 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3445 pwc
= m_chgInfo_baseChangedProperty
;
3447 while ( pwc
!= changedProperty
)
3449 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3450 pwc
= pwc
->GetParent();
3454 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3459 // -----------------------------------------------------------------------
3461 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3463 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3465 m_chgInfo_changedProperty
= NULL
;
3467 if ( PerformValidation(p
, newValue
) )
3469 DoPropertyChanged(p
);
3474 OnValidationFailure(p
, newValue
);
3480 // -----------------------------------------------------------------------
3482 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3484 wxPGProperty
* prop
= GetSelectedProperty();
3487 return wxNullVariant
;
3489 wxTextCtrl
* tc
= GetEditorTextCtrl();
3490 wxVariant value
= prop
->GetValue();
3492 if ( !tc
|| !IsEditorsValueModified() )
3495 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3498 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3499 return prop
->GetValue();
3504 // -----------------------------------------------------------------------
3506 // Runs wxValidator for the selected property
3507 bool wxPropertyGrid::DoEditorValidate()
3509 #if wxUSE_VALIDATORS
3510 wxRecursionGuard
guard(m_validatingEditor
);
3511 if ( guard
.IsInside() )
3514 wxPGProperty
* selected
= GetSelection();
3517 wxWindow
* wnd
= GetEditorControl();
3519 wxValidator
* validator
= selected
->GetValidator();
3520 if ( validator
&& wnd
)
3522 validator
->SetWindow(wnd
);
3523 if ( !validator
->Validate(this) )
3531 // -----------------------------------------------------------------------
3533 bool wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3536 // NB: We should return true if the event was recognized as
3537 // a dedicated wxPropertyGrid event, and as such was
3538 // either properly handled or ignored.
3541 // It is possible that this handler receives event even before
3542 // the control has been properly initialized. Let's skip the
3543 // event handling in that case.
3547 // Don't care about the event if it originated from the
3548 // 'label editor'. In this function we only care about the
3549 // property value editor.
3550 if ( m_labelEditor
&& event
.GetId() == m_labelEditor
->GetId() )
3556 wxPGProperty
* selected
= GetSelection();
3558 // Somehow, event is handled after property has been deselected.
3559 // Possibly, but very rare.
3561 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3562 m_inOnValidationFailure
||
3563 // Also don't handle editor event if wxEVT_PG_CHANGED or
3564 // similar is currently doing something (showing a
3565 // message box, for instance).
3569 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3572 wxVariant
pendingValue(selected
->GetValueRef());
3573 wxWindow
* wnd
= GetEditorControl();
3574 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3576 bool wasUnspecified
= selected
->IsValueUnspecified();
3577 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3578 bool valueIsPending
= false;
3580 m_chgInfo_changedProperty
= NULL
;
3582 m_iFlags
&= ~wxPG_FL_VALUE_CHANGE_IN_EVENT
;
3585 // Filter out excess wxTextCtrl modified events
3586 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&& wnd
)
3588 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3590 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3592 wxString newTcValue
= tc
->GetValue();
3593 if ( m_prevTcValue
== newTcValue
)
3595 m_prevTcValue
= newTcValue
;
3597 else if ( wnd
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
3599 // In some cases we might stumble unintentionally on
3600 // wxComboCtrl's embedded wxTextCtrl's events. Let's
3602 if ( editorWnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3605 wxComboCtrl
* cc
= (wxComboCtrl
*) wnd
;
3607 wxString newTcValue
= cc
->GetTextCtrl()->GetValue();
3608 if ( m_prevTcValue
== newTcValue
)
3610 m_prevTcValue
= newTcValue
;
3614 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3616 bool validationFailure
= false;
3617 bool buttonWasHandled
= false;
3618 bool result
= false;
3621 // Try common button handling
3622 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3624 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3628 buttonWasHandled
= true;
3629 // Store as res2, as previously (and still currently alternatively)
3630 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3631 // in wxPGProperty::OnEvent().
3632 adapter
->ShowDialog( this, selected
);
3637 if ( !buttonWasHandled
)
3639 if ( wnd
|| m_wndEditor2
)
3641 // First call editor class' event handler.
3642 const wxPGEditor
* editor
= selected
->GetEditorClass();
3644 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3648 // If changes, validate them
3649 if ( DoEditorValidate() )
3651 if ( editor
->GetValueFromControl( pendingValue
,
3654 valueIsPending
= true;
3656 // Mark value always as pending if validation is currently
3657 // failing and value was not unspecified
3658 if ( !valueIsPending
&&
3659 !pendingValue
.IsNull() &&
3660 m_validationInfo
.m_isFailing
)
3661 valueIsPending
= true;
3665 validationFailure
= true;
3670 // Then the property's custom handler (must be always called, unless
3671 // validation failed).
3672 if ( !validationFailure
)
3673 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3676 // SetValueInEvent(), as called in one of the functions referred above
3677 // overrides editor's value.
3678 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3680 valueIsPending
= true;
3681 pendingValue
= m_changeInEventValue
;
3682 selFlags
|= wxPG_SEL_DIALOGVAL
;
3685 if ( !validationFailure
&& valueIsPending
)
3686 if ( !PerformValidation(selected
, pendingValue
) )
3687 validationFailure
= true;
3689 if ( validationFailure
)
3691 OnValidationFailure(selected
, pendingValue
);
3693 else if ( valueIsPending
)
3695 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3697 DoPropertyChanged(selected
, selFlags
);
3698 EditorsValueWasNotModified();
3700 // Regardless of editor type, unfocus editor on
3701 // text-editing related enter press.
3702 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3709 // No value after all
3711 // Regardless of editor type, unfocus editor on
3712 // text-editing related enter press.
3713 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3718 // Let unhandled button click events go to the parent
3719 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3722 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3723 GetEventHandler()->AddPendingEvent(evt
);
3727 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3732 // -----------------------------------------------------------------------
3733 // wxPropertyGrid editor control helper methods
3734 // -----------------------------------------------------------------------
3736 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3738 int itemy
= p
->GetY2(m_lineHeight
);
3739 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3740 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3741 int imageOffset
= 0;
3743 int vx
, vy
; // Top left corner of client
3744 GetViewStart(&vx
, &vy
);
3745 vy
*= wxPG_PIXELS_PER_UNIT
;
3749 // TODO: If custom image detection changes from current, change this.
3750 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3752 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3753 int iw
= p
->OnMeasureImage().x
;
3755 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3756 imageOffset
= p
->GetImageOffset(iw
);
3759 else if ( column
== 0 )
3761 splitterX
+= (p
->m_depth
- 1) * m_subgroup_extramargin
;
3766 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3768 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3773 // -----------------------------------------------------------------------
3775 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3777 wxSize sz
= GetImageSize(p
, item
);
3778 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3779 wxPG_CUSTOM_IMAGE_SPACINGY
,
3784 // return size of custom paint image
3785 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3787 // If called with NULL property, then return default image
3788 // size for properties that use image.
3790 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3792 wxSize cis
= p
->OnMeasureImage(item
);
3794 int choiceCount
= p
->m_choices
.GetCount();
3795 int comVals
= p
->GetDisplayedCommonValueCount();
3796 if ( item
>= choiceCount
&& comVals
> 0 )
3798 unsigned int cvi
= item
-choiceCount
;
3799 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3801 else if ( item
>= 0 && choiceCount
== 0 )
3802 return wxSize(0, 0);
3807 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3812 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3819 // -----------------------------------------------------------------------
3821 // takes scrolling into account
3822 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3825 GetViewStart(&vx
,&vy
);
3826 vy
*=wxPG_PIXELS_PER_UNIT
;
3827 vx
*=wxPG_PIXELS_PER_UNIT
;
3830 ClientToScreen( px
, py
);
3833 // -----------------------------------------------------------------------
3835 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3838 GetViewStart(&pt2
.x
,&pt2
.y
);
3839 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3840 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3844 return m_pState
->HitTest(pt2
);
3847 // -----------------------------------------------------------------------
3849 // custom set cursor
3850 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3852 if ( type
== m_curcursor
&& !override
) return;
3854 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3856 if ( type
== wxCURSOR_SIZEWE
)
3857 cursor
= m_cursorSizeWE
;
3859 SetCursor( *cursor
);
3864 // -----------------------------------------------------------------------
3867 wxPropertyGrid::GetUnspecifiedValueText( int argFlags
) const
3869 const wxPGCell
& ua
= GetUnspecifiedValueAppearance();
3871 if ( ua
.HasText() &&
3872 !(argFlags
& wxPG_FULL_VALUE
) &&
3873 !(argFlags
& wxPG_EDITABLE_VALUE
) )
3874 return ua
.GetText();
3876 return wxEmptyString
;
3879 // -----------------------------------------------------------------------
3880 // wxPropertyGrid property selection, editor creation
3881 // -----------------------------------------------------------------------
3884 // This class forwards events from property editor controls to wxPropertyGrid.
3885 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3888 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3889 : wxEvtHandler(), m_propGrid(propGrid
)
3893 virtual ~wxPropertyGridEditorEventForwarder()
3898 bool ProcessEvent( wxEvent
& event
)
3903 m_propGrid
->HandleCustomEditorEvent(event
);
3906 // NB: We should return true if the event was recognized as
3907 // a dedicated wxPropertyGrid event, and as such was
3908 // either properly handled or ignored.
3910 if ( m_propGrid
->IsMainButtonEvent(event
) )
3914 // NB: On wxMSW, a wxTextCtrl with wxTE_PROCESS_ENTER
3915 // may beep annoyingly if that event is skipped
3916 // and passed to parent event handler.
3917 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3920 return wxEvtHandler::ProcessEvent(event
);
3923 wxPropertyGrid
* m_propGrid
;
3926 // Setups event handling for child control
3927 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3929 wxWindowID id
= argWnd
->GetId();
3931 if ( argWnd
== m_wndEditor
)
3933 argWnd
->Connect(id
, wxEVT_MOTION
,
3934 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3936 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3937 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3939 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3940 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3942 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3943 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3945 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3946 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3948 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3949 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3953 wxPropertyGridEditorEventForwarder
* forwarder
;
3954 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3955 argWnd
->PushEventHandler(forwarder
);
3957 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3958 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3962 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3969 // Do not free editors immediately (for sake of processing events)
3970 wxPendingDelete
.Append(wnd
);
3973 void wxPropertyGrid::FreeEditors()
3976 // Return focus back to canvas from children (this is required at least for
3977 // GTK+, which, unlike Windows, clears focus when control is destroyed
3978 // instead of moving it to closest parent).
3981 // Do not free editors immediately if processing events
3984 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3985 m_wndEditor2
->Hide();
3986 wxPendingDelete
.Append( handler
);
3987 DestroyEditorWnd(m_wndEditor2
);
3988 m_wndEditor2
= NULL
;
3993 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3994 m_wndEditor
->Hide();
3995 wxPendingDelete
.Append( handler
);
3996 DestroyEditorWnd(m_wndEditor
);
4001 // Call with NULL to de-select property
4002 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
4007 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
4008 p->m_parent->m_label.c_str(),p->GetIndexInParent());
4012 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
4016 if ( m_inDoSelectProperty
)
4019 m_inDoSelectProperty
= true;
4020 wxON_BLOCK_EXIT_SET(m_inDoSelectProperty
, false);
4025 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
4026 wxPGProperty
* prevFirstSel
;
4028 if ( prevSelection
.size() > 0 )
4029 prevFirstSel
= prevSelection
[0];
4031 prevFirstSel
= NULL
;
4033 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
4034 prevFirstSel
= NULL
;
4036 // Always send event, as this is indirect call
4037 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4041 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
4043 wxPrintf( "None selected\n" );
4046 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
4048 wxPrintf( "P = NULL\n" );
4051 wxWindow
* primaryCtrl
= NULL
;
4053 // If we are frozen, then just set the values.
4056 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4057 m_editorFocused
= 0;
4058 m_pState
->DoSetSelection(p
);
4060 // If frozen, always free controls. But don't worry, as Thaw will
4061 // recall SelectProperty to recreate them.
4064 // Prevent any further selection measures in this call
4070 if ( prevFirstSel
== p
&&
4071 prevSelection
.size() <= 1 &&
4072 !(flags
& wxPG_SEL_FORCE
) )
4074 // Only set focus if not deselecting
4077 if ( flags
& wxPG_SEL_FOCUS
)
4081 m_wndEditor
->SetFocus();
4082 m_editorFocused
= 1;
4095 // First, deactivate previous
4098 // Must double-check if this is an selected in case of forceswitch
4099 if ( p
!= prevFirstSel
)
4101 if ( !CommitChangesFromEditor(flags
) )
4103 // Validation has failed, so we can't exit the previous editor
4104 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
4105 // _("Invalid Value"),wxOK|wxICON_ERROR);
4110 // This should be called after CommitChangesFromEditor(), so that
4111 // OnValidationFailure() still has information on property's
4112 // validation state.
4113 OnValidationFailureReset(prevFirstSel
);
4117 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4118 EditorsValueWasNotModified();
4121 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4123 m_pState
->DoSetSelection(p
);
4125 // Redraw unselected
4126 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
4128 DrawItem(prevSelection
[i
]);
4132 // Then, activate the one given.
4135 int propY
= p
->GetY2(m_lineHeight
);
4137 int splitterX
= GetSplitterPosition();
4138 m_editorFocused
= 0;
4139 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
4141 wxASSERT( m_wndEditor
== NULL
);
4144 // Only create editor for non-disabled non-caption
4145 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
4147 // do this for non-caption items
4151 // Do we need to paint the custom image, if any?
4152 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
4153 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
4154 !p
->GetEditorClass()->CanContainCustomImage()
4156 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
4158 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
4159 wxPoint goodPos
= grect
.GetPosition();
4161 // Editor appearance can now be considered clear
4162 m_editorAppearance
.SetEmptyData();
4164 const wxPGEditor
* editor
= p
->GetEditorClass();
4165 wxCHECK_MSG(editor
, false,
4166 wxT("NULL editor class not allowed"));
4168 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
4170 wxPGWindowList wndList
=
4171 editor
->CreateControls(this,
4176 m_wndEditor
= wndList
.m_primary
;
4177 m_wndEditor2
= wndList
.m_secondary
;
4178 primaryCtrl
= GetEditorControl();
4181 // Essentially, primaryCtrl == m_wndEditor
4184 // NOTE: It is allowed for m_wndEditor to be NULL - in this
4185 // case value is drawn as normal, and m_wndEditor2 is
4186 // assumed to be a right-aligned button that triggers
4187 // a separate editorCtrl window.
4191 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
4192 "CreateControls must use result of "
4193 "wxPropertyGrid::GetPanel() as parent "
4196 // Set validator, if any
4197 #if wxUSE_VALIDATORS
4198 wxValidator
* validator
= p
->GetValidator();
4200 primaryCtrl
->SetValidator(*validator
);
4203 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
4204 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
4206 // If it has modified status, use bold font
4207 // (must be done before capturing m_ctrlXAdjust)
4208 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
4209 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
4210 SetCurControlBoldFont();
4212 // Store x relative to splitter (we'll need it).
4213 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
4215 // Check if background clear is not necessary
4216 wxPoint pos
= m_wndEditor
->GetPosition();
4217 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
4219 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
4222 m_wndEditor
->SetSizeHints(3, 3);
4224 SetupChildEventHandling(primaryCtrl
);
4226 // Focus and select all (wxTextCtrl, wxComboBox etc)
4227 if ( flags
& wxPG_SEL_FOCUS
)
4229 primaryCtrl
->SetFocus();
4231 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
4235 if ( p
->IsValueUnspecified() )
4236 SetEditorAppearance(m_unspecifiedAppearance
,
4243 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
4244 "CreateControls must use result of "
4245 "wxPropertyGrid::GetPanel() as parent "
4248 // Get proper id for wndSecondary
4249 m_wndSecId
= m_wndEditor2
->GetId();
4250 wxWindowList children
= m_wndEditor2
->GetChildren();
4251 wxWindowList::iterator node
= children
.begin();
4252 if ( node
!= children
.end() )
4253 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
4255 m_wndEditor2
->SetSizeHints(3,3);
4257 m_wndEditor2
->Show();
4259 SetupChildEventHandling(m_wndEditor2
);
4261 // If no primary editor, focus to button to allow
4262 // it to interprete ENTER etc.
4263 // NOTE: Due to problems focusing away from it, this
4264 // has been disabled.
4266 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
4267 m_wndEditor2->SetFocus();
4271 if ( flags
& wxPG_SEL_FOCUS
)
4272 m_editorFocused
= 1;
4277 // Make sure focus is in grid canvas (important for wxGTK,
4282 EditorsValueWasNotModified();
4284 // If it's inside collapsed section, expand parent, scroll, etc.
4285 // Also, if it was partially visible, scroll it into view.
4286 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
4291 m_wndEditor
->Show(true);
4294 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
4299 // Make sure focus is in grid canvas
4303 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4306 const wxString
* pHelpString
= NULL
;
4309 pHelpString
= &p
->GetHelpString();
4311 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4316 // Show help text in status bar.
4317 // (if found and grid not embedded in manager with help box and
4318 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4320 wxStatusBar
* statusbar
= GetStatusBar();
4323 if ( pHelpString
&& !pHelpString
->empty() )
4325 // Set help box text.
4326 statusbar
->SetStatusText( *pHelpString
);
4327 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4329 else if ( m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
)
4331 // Clear help box - but only if it was written
4332 // by us at previous time.
4333 statusbar
->SetStatusText( m_emptyString
);
4334 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4341 #if wxPG_SUPPORT_TOOLTIPS
4343 // Show help as a tool tip on the editor control.
4345 if ( pHelpString
&& !pHelpString
->empty() &&
4348 primaryCtrl
->SetToolTip(*pHelpString
);
4353 // call wx event handler (here so that it also occurs on deselection)
4354 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4355 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4360 // -----------------------------------------------------------------------
4362 bool wxPropertyGrid::UnfocusEditor()
4364 wxPGProperty
* selected
= GetSelection();
4366 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4369 if ( !CommitChangesFromEditor(0) )
4378 // -----------------------------------------------------------------------
4380 void wxPropertyGrid::RefreshEditor()
4382 wxPGProperty
* p
= GetSelection();
4386 wxWindow
* wnd
= GetEditorControl();
4390 // Set editor font boldness - must do this before
4391 // calling UpdateControl().
4392 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4394 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4395 wnd
->SetFont(GetCaptionFont());
4397 wnd
->SetFont(GetFont());
4400 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4402 editorClass
->UpdateControl(p
, wnd
);
4404 if ( p
->IsValueUnspecified() )
4405 SetEditorAppearance(m_unspecifiedAppearance
, true);
4408 // -----------------------------------------------------------------------
4410 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4412 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4414 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4416 flags
|= wxPG_SEL_FOCUS
;
4418 return DoSelectProperty(p
, flags
);
4421 // -----------------------------------------------------------------------
4422 // wxPropertyGrid expand/collapse state
4423 // -----------------------------------------------------------------------
4425 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4427 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4428 wxPGProperty
* selected
= GetSelection();
4430 // If active editor was inside collapsed section, then disable it
4431 if ( selected
&& selected
->IsSomeParent(p
) )
4436 // Store dont-center-splitter flag 'cause we need to temporarily set it
4437 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4438 m_pState
->m_dontCenterSplitter
= true;
4440 bool res
= m_pState
->DoCollapse(pwc
);
4445 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4447 RecalculateVirtualSize();
4451 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4456 // -----------------------------------------------------------------------
4458 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4460 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4462 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4464 // Store dont-center-splitter flag 'cause we need to temporarily set it
4465 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4466 m_pState
->m_dontCenterSplitter
= true;
4468 bool res
= m_pState
->DoExpand(pwc
);
4473 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4475 RecalculateVirtualSize();
4479 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4484 // -----------------------------------------------------------------------
4486 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4489 return m_pState
->DoHideProperty(p
, hide
, flags
);
4491 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4492 int selRemoveCount
= 0;
4493 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4495 wxPGProperty
* selected
= selection
[i
];
4496 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4498 if ( !DoRemoveFromSelection(p
, flags
) )
4500 selRemoveCount
+= 1;
4504 m_pState
->DoHideProperty(p
, hide
, flags
);
4506 RecalculateVirtualSize();
4513 // -----------------------------------------------------------------------
4514 // wxPropertyGrid size related methods
4515 // -----------------------------------------------------------------------
4517 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4519 // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise
4520 // virtual size calculation may go wrong.
4521 if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4527 // If virtual height was changed, then recalculate editor control position(s)
4528 if ( m_pState
->m_vhCalcPending
)
4529 CorrectEditorWidgetPosY();
4531 m_pState
->EnsureVirtualHeight();
4533 wxASSERT_LEVEL_2_MSG(
4534 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4535 "VirtualHeight and ActualVirtualHeight should match"
4538 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4540 int x
= m_pState
->m_width
;
4541 int y
= m_pState
->m_virtualHeight
;
4544 GetClientSize(&width
,&height
);
4546 // Now adjust virtual size.
4547 SetVirtualSize(x
, y
);
4553 // Adjust scrollbars
4554 if ( HasVirtualWidth() )
4556 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4557 xPos
= GetScrollPos( wxHORIZONTAL
);
4560 if ( forceXPos
!= -1 )
4563 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4566 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4567 int yPos
= GetScrollPos( wxVERTICAL
);
4569 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4570 xAmount
, yAmount
, xPos
, yPos
, true );
4572 // This may be needed in addition to calling SetScrollbars()
4573 // when class inherits from wxScrollHelper instead of
4574 // actual wxScrolled<T>.
4577 // Must re-get size now
4578 GetClientSize(&width
,&height
);
4580 if ( !HasVirtualWidth() )
4582 m_pState
->SetVirtualWidth(width
);
4589 m_pState
->CheckColumnWidths();
4591 if ( GetSelection() )
4592 CorrectEditorWidgetSizeX();
4594 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4597 // -----------------------------------------------------------------------
4599 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4601 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4605 GetClientSize(&width
, &height
);
4610 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4612 int dblh
= (m_lineHeight
*2);
4613 if ( !m_doubleBuffer
)
4615 // Create double buffer bitmap to draw on, if none
4616 int w
= (width
>250)?width
:250;
4617 int h
= height
+ dblh
;
4619 m_doubleBuffer
= new wxBitmap( w
, h
);
4623 int w
= m_doubleBuffer
->GetWidth();
4624 int h
= m_doubleBuffer
->GetHeight();
4626 // Double buffer must be large enough
4627 if ( w
< width
|| h
< (height
+dblh
) )
4629 if ( w
< width
) w
= width
;
4630 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4631 delete m_doubleBuffer
;
4632 m_doubleBuffer
= new wxBitmap( w
, h
);
4637 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4638 m_ncWidth
= event
.GetSize().x
;
4642 if ( m_pState
->m_itemsAdded
)
4643 PrepareAfterItemsAdded();
4645 // Without this, virtual size (atleast under wxGTK) will be skewed
4646 RecalculateVirtualSize();
4652 // -----------------------------------------------------------------------
4654 void wxPropertyGrid::SetVirtualWidth( int width
)
4658 // Disable virtual width
4659 width
= GetClientSize().x
;
4660 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4664 // Enable virtual width
4665 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4667 m_pState
->SetVirtualWidth( width
);
4670 void wxPropertyGrid::SetFocusOnCanvas()
4672 // To prevent wxPropertyGrid from stealing focus from other controls,
4673 // only move focus to the grid if it was already in one if its child
4675 wxWindow
* focus
= wxWindow::FindFocus();
4678 wxWindow
* parent
= focus
->GetParent();
4681 if ( parent
== this )
4686 parent
= parent
->GetParent();
4690 m_editorFocused
= 0;
4693 // -----------------------------------------------------------------------
4694 // wxPropertyGrid mouse event handling
4695 // -----------------------------------------------------------------------
4697 // selFlags uses same values DoSelectProperty's flags
4698 // Returns true if event was vetoed.
4699 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4701 unsigned int selFlags
,
4702 unsigned int column
)
4704 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4707 // Send property grid event of specific type and with specific property
4708 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4709 evt
.SetPropertyGrid(this);
4710 evt
.SetEventObject(m_eventObject
);
4712 evt
.SetColumn(column
);
4713 if ( eventType
== wxEVT_PG_CHANGING
)
4716 evt
.SetCanVeto(true);
4717 m_validationInfo
.m_pValue
= pValue
;
4718 evt
.SetupValidationInfo();
4723 evt
.SetPropertyValue(p
->GetValue());
4725 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4726 evt
.SetCanVeto(true);
4729 wxPropertyGridEvent
* prevProcessedEvent
= m_processedEvent
;
4730 m_processedEvent
= &evt
;
4731 m_eventObject
->HandleWindowEvent(evt
);
4732 m_processedEvent
= prevProcessedEvent
;
4734 return evt
.WasVetoed();
4737 // -----------------------------------------------------------------------
4739 // Return false if should be skipped
4740 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4744 // Need to set focus?
4745 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4750 wxPropertyGridPageState
* state
= m_pState
;
4752 int splitterHitOffset
;
4753 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4755 wxPGProperty
* p
= DoGetItemAtY(y
);
4759 int depth
= (int)p
->GetDepth() - 1;
4761 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4763 if ( x
>= marginEnds
)
4767 if ( p
->IsCategory() )
4769 // This is category.
4770 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4772 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4774 // Expand, collapse, activate etc. if click on text or left of splitter.
4777 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4782 if ( !AddToSelectionFromInputEvent( p
,
4787 // On double-click, expand/collapse.
4788 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4790 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4791 else DoExpand( p
, true );
4795 else if ( splitterHit
== -1 )
4798 unsigned int selFlag
= 0;
4799 if ( columnHit
== 1 )
4801 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4802 selFlag
= wxPG_SEL_FOCUS
;
4804 if ( !AddToSelectionFromInputEvent( p
,
4810 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4812 if ( p
->GetChildCount() && !p
->IsCategory() )
4813 // On double-click, expand/collapse.
4814 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4816 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4817 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4818 else DoExpand( p
, true );
4821 // Do not Skip() the event after selection has been made.
4822 // Otherwise default event handling behaviour kicks in
4823 // and may revert focus back to the main canvas.
4828 // click on splitter
4829 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4831 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4833 // Double-clicking the splitter causes auto-centering
4834 if ( m_pState
->GetColumnCount() <= 2 )
4836 ResetColumnSizes( true );
4838 SendEvent(wxEVT_PG_COL_DRAGGING
,
4841 wxPG_SEL_NOVALIDATE
,
4842 (unsigned int)m_draggedSplitter
);
4845 else if ( m_dragStatus
== 0 )
4848 // Begin draggin the splitter
4852 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4854 // Allow application to veto dragging
4855 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4857 (unsigned int)splitterHit
) )
4861 // Changes must be committed here or the
4862 // value won't be drawn correctly
4863 if ( !CommitChangesFromEditor() )
4866 m_wndEditor
->Show ( false );
4869 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4872 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4876 m_draggedSplitter
= splitterHit
;
4877 m_dragOffset
= splitterHitOffset
;
4879 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4880 // Fixes button disappearance bug
4882 m_wndEditor2
->Show ( false );
4885 m_startingSplitterX
= x
- splitterHitOffset
;
4894 if ( p
->GetChildCount() )
4896 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4898 // Fine tune cell button x
4899 if ( !p
->IsCategory() )
4900 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4902 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4904 int y2
= y
% m_lineHeight
;
4905 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4907 // On click on expander button, expand/collapse
4908 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4909 DoCollapse( p
, true );
4911 DoExpand( p
, true );
4920 // -----------------------------------------------------------------------
4922 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4923 unsigned int WXUNUSED(y
),
4924 wxMouseEvent
& event
)
4928 // Select property here as well
4929 wxPGProperty
* p
= m_propHover
;
4930 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4932 // Send right click event.
4933 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4940 // -----------------------------------------------------------------------
4942 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4943 unsigned int WXUNUSED(y
),
4944 wxMouseEvent
& event
)
4948 // Select property here as well
4949 wxPGProperty
* p
= m_propHover
;
4951 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4953 // Send double-click event.
4954 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4961 // -----------------------------------------------------------------------
4963 // Return false if should be skipped
4964 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
,
4965 wxMouseEvent
&event
)
4967 // Safety check (needed because mouse capturing may
4968 // otherwise freeze the control)
4969 if ( m_dragStatus
> 0 && !event
.Dragging() )
4971 HandleMouseUp(x
, y
, event
);
4974 wxPropertyGridPageState
* state
= m_pState
;
4976 int splitterHitOffset
;
4977 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4978 int splitterX
= x
- splitterHitOffset
;
4980 m_colHover
= columnHit
;
4982 if ( m_dragStatus
> 0 )
4984 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4985 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4988 int newSplitterX
= x
- m_dragOffset
;
4990 // Splitter redraw required?
4991 if ( newSplitterX
!= splitterX
)
4994 DoSetSplitterPosition(newSplitterX
,
4996 wxPG_SPLITTER_REFRESH
|
4997 wxPG_SPLITTER_FROM_EVENT
);
4999 SendEvent(wxEVT_PG_COL_DRAGGING
,
5002 wxPG_SEL_NOVALIDATE
,
5003 (unsigned int)m_draggedSplitter
);
5014 int ih
= m_lineHeight
;
5017 #if wxPG_SUPPORT_TOOLTIPS
5018 wxPGProperty
* prevHover
= m_propHover
;
5019 unsigned char prevSide
= m_mouseSide
;
5021 int curPropHoverY
= y
- (y
% ih
);
5023 // On which item it hovers
5026 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
5029 // Mouse moves on another property
5031 m_propHover
= DoGetItemAtY(y
);
5032 m_propHoverY
= curPropHoverY
;
5035 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
5038 #if wxPG_SUPPORT_TOOLTIPS
5039 // Store which side we are on
5041 if ( columnHit
== 1 )
5043 else if ( columnHit
== 0 )
5047 // If tooltips are enabled, show label or value as a tip
5048 // in case it doesn't otherwise show in full length.
5050 if ( m_windowStyle
& wxPG_TOOLTIPS
)
5052 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
5054 if ( m_propHover
&& !m_propHover
->IsCategory() )
5057 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
5059 // Show help string as a tooltip
5060 wxString tipString
= m_propHover
->GetHelpString();
5062 SetToolTip(tipString
);
5066 // Show cropped value string as a tooltip
5070 if ( m_mouseSide
== 1 )
5072 tipString
= m_propHover
->m_label
;
5073 space
= splitterX
-m_marginWidth
-3;
5075 else if ( m_mouseSide
== 2 )
5077 tipString
= m_propHover
->GetDisplayedString();
5079 space
= m_width
- splitterX
;
5080 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
5081 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+
5082 wxCC_CUSTOM_IMAGE_MARGIN1
+
5083 wxCC_CUSTOM_IMAGE_MARGIN2
;
5089 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
5091 SetToolTip( tipString
);
5095 SetToolTip( m_emptyString
);
5102 SetToolTip( m_emptyString
);
5108 if ( splitterHit
== -1 ||
5110 HasFlag(wxPG_STATIC_SPLITTER
) )
5112 // hovering on something else
5113 if ( m_curcursor
!= wxCURSOR_ARROW
)
5114 CustomSetCursor( wxCURSOR_ARROW
);
5118 // Do not allow splitter cursor on caption items.
5119 // (also not if we were dragging and its started
5120 // outside the splitter region)
5122 if ( !m_propHover
->IsCategory() &&
5126 // hovering on splitter
5128 // NB: Condition disabled since MouseLeave event (from the
5129 // editor control) cannot be reliably detected.
5130 //if ( m_curcursor != wxCURSOR_SIZEWE )
5131 CustomSetCursor( wxCURSOR_SIZEWE
, true );
5137 // hovering on something else
5138 if ( m_curcursor
!= wxCURSOR_ARROW
)
5139 CustomSetCursor( wxCURSOR_ARROW
);
5144 // Multi select by dragging
5146 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
5147 event
.LeftIsDown() &&
5151 !state
->DoIsPropertySelected(m_propHover
) )
5153 // Additional requirement is that the hovered property
5154 // is adjacent to edges of selection.
5155 const wxArrayPGProperty
& selection
= GetSelectedProperties();
5157 // Since categories cannot be selected along with 'other'
5158 // properties, exclude them from iterator flags.
5159 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
5161 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
5163 // TODO: This could be optimized by keeping track of
5164 // which properties are at the edges of selection.
5165 wxPGProperty
* selProp
= selection
[i
];
5166 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
5169 DoAddToSelection(m_propHover
);
5178 // -----------------------------------------------------------------------
5180 // Also handles Leaving event
5181 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
5182 wxMouseEvent
&WXUNUSED(event
) )
5184 wxPropertyGridPageState
* state
= m_pState
;
5188 int splitterHitOffset
;
5189 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
5191 // No event type check - basicly calling this method should
5192 // just stop dragging.
5193 // Left up after dragged?
5194 if ( m_dragStatus
>= 1 )
5197 // End Splitter Dragging
5199 // DO NOT ENABLE FOLLOWING LINE!
5200 // (it is only here as a reminder to not to do it)
5203 SendEvent(wxEVT_PG_COL_END_DRAG
,
5206 wxPG_SEL_NOVALIDATE
,
5207 (unsigned int)m_draggedSplitter
);
5209 // Disable splitter auto-centering (but only if moved any -
5210 // otherwise we end up disabling auto-center even after a
5211 // recentering double-click).
5212 int posDiff
= abs(m_startingSplitterX
-
5213 GetSplitterPosition(m_draggedSplitter
));
5216 state
->m_dontCenterSplitter
= true;
5218 // This is necessary to return cursor
5219 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5222 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5225 // Set back the default cursor, if necessary
5226 if ( splitterHit
== -1 ||
5229 CustomSetCursor( wxCURSOR_ARROW
);
5234 // Control background needs to be cleared
5235 wxPGProperty
* selected
= GetSelection();
5236 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
5237 DrawItem( selected
);
5241 m_wndEditor
->Show ( true );
5244 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
5245 // Fixes button disappearance bug
5247 m_wndEditor2
->Show ( true );
5250 // This clears the focus.
5251 m_editorFocused
= 0;
5257 // -----------------------------------------------------------------------
5259 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
5261 int splitterX
= GetSplitterPosition();
5264 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
5266 wxWindow
* wnd
= GetEditorControl();
5268 // Hide popup on clicks
5269 if ( event
.GetEventType() != wxEVT_MOTION
)
5270 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5272 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
5278 if ( wnd
== NULL
|| m_dragStatus
||
5280 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
5281 ux
>= (r
.x
+r
.width
) ||
5283 event
.m_y
>= (r
.y
+r
.height
)
5293 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5298 // -----------------------------------------------------------------------
5300 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
5303 if ( OnMouseCommon( event
, &x
, &y
) )
5305 if ( !HandleMouseClick(x
, y
, event
) )
5314 // -----------------------------------------------------------------------
5316 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5319 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5320 HandleMouseRightClick(x
,y
,event
);
5324 // -----------------------------------------------------------------------
5326 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5328 // Always run standard mouse-down handler as well
5329 OnMouseClick(event
);
5332 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5333 HandleMouseDoubleClick(x
,y
,event
);
5335 // Do not Skip() event here - OnMouseClick() call above
5336 // should have already taken care of it.
5339 // -----------------------------------------------------------------------
5341 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5344 if ( OnMouseCommon( event
, &x
, &y
) )
5346 HandleMouseMove(x
,y
,event
);
5351 // -----------------------------------------------------------------------
5353 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5356 if ( OnMouseCommon( event
, &x
, &y
) )
5358 if ( !HandleMouseUp(x
, y
, event
) )
5367 // -----------------------------------------------------------------------
5369 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5371 // This may get called from child control as well, so event's
5372 // mouse position cannot be relied on.
5374 if ( event
.Entering() )
5376 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5378 // TODO: Fix this (detect parent and only do
5379 // cursor trick if it is a manager).
5380 wxASSERT( GetParent() );
5381 GetParent()->SetCursor(wxNullCursor
);
5383 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5386 GetParent()->SetCursor(wxNullCursor
);
5388 else if ( event
.Leaving() )
5390 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5391 SetCursor( wxNullCursor
);
5393 // Get real cursor position
5394 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5396 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5399 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5401 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5405 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5413 // -----------------------------------------------------------------------
5415 // Common code used by various OnMouseXXXChild methods.
5416 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5418 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5419 wxASSERT( topCtrlWnd
);
5421 event
.GetPosition(&x
,&y
);
5423 int splitterX
= GetSplitterPosition();
5425 wxRect r
= topCtrlWnd
->GetRect();
5426 if ( !m_dragStatus
&&
5427 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5428 y
>= 0 && y
< r
.height \
5431 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5436 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5443 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5446 if ( OnMouseChildCommon(event
,&x
,&y
) )
5448 bool res
= HandleMouseClick(x
,y
,event
);
5449 if ( !res
) event
.Skip();
5453 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5456 wxASSERT( m_wndEditor
);
5457 // These coords may not be exact (about +-2),
5458 // but that should not matter (right click is about item, not position).
5459 wxPoint pt
= m_wndEditor
->GetPosition();
5460 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5462 // FIXME: Used to set m_propHover to selection here. Was it really
5465 bool res
= HandleMouseRightClick(x
,y
,event
);
5466 if ( !res
) event
.Skip();
5469 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5472 if ( OnMouseChildCommon(event
,&x
,&y
) )
5474 bool res
= HandleMouseMove(x
,y
,event
);
5475 if ( !res
) event
.Skip();
5479 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5482 if ( OnMouseChildCommon(event
,&x
,&y
) )
5484 bool res
= HandleMouseUp(x
,y
,event
);
5485 if ( !res
) event
.Skip();
5489 // -----------------------------------------------------------------------
5490 // wxPropertyGrid keyboard event handling
5491 // -----------------------------------------------------------------------
5493 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5495 // Translates wxKeyEvent to wxPG_ACTION_XXX
5497 int keycode
= event
.GetKeyCode();
5498 int modifiers
= event
.GetModifiers();
5500 wxASSERT( !(modifiers
&~(0xFFFF)) );
5502 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5504 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5506 if ( it
== m_actionTriggers
.end() )
5511 int second
= (it
->second
>>16) & 0xFFFF;
5515 return (it
->second
& 0xFFFF);
5518 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5520 wxASSERT( !(modifiers
&~(0xFFFF)) );
5522 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5524 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5526 if ( it
!= m_actionTriggers
.end() )
5528 // This key combination is already used
5530 // Can add secondary?
5531 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5532 wxT("You can only add up to two separate actions per key combination.") );
5534 action
= it
->second
| (action
<<16);
5537 m_actionTriggers
[hashMapKey
] = action
;
5540 void wxPropertyGrid::ClearActionTriggers( int action
)
5542 wxPGHashMapI2I::iterator it
;
5547 didSomething
= false;
5549 for ( it
= m_actionTriggers
.begin();
5550 it
!= m_actionTriggers
.end();
5553 if ( it
->second
== action
)
5555 m_actionTriggers
.erase(it
);
5556 didSomething
= true;
5561 while ( didSomething
);
5564 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5567 // Handles key event when editor control is not focused.
5570 wxCHECK2(!m_frozen
, return);
5572 // Travelsal between items, collapsing/expanding, etc.
5573 wxPGProperty
* selected
= GetSelection();
5574 int keycode
= event
.GetKeyCode();
5575 bool editorFocused
= IsEditorFocused();
5577 if ( keycode
== WXK_TAB
)
5579 wxWindow
* mainControl
;
5581 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5582 mainControl
= GetParent();
5586 if ( !event
.ShiftDown() )
5588 if ( !editorFocused
&& m_wndEditor
)
5590 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5594 // Tab traversal workaround for platforms on which
5595 // wxWindow::Navigate() may navigate into first child
5596 // instead of next sibling. Does not work perfectly
5597 // in every scenario (for instance, when property grid
5598 // is either first or last control).
5599 #if defined(__WXGTK__)
5600 wxWindow
* sibling
= mainControl
->GetNextSibling();
5602 sibling
->SetFocusFromKbd();
5604 Navigate(wxNavigationKeyEvent::IsForward
);
5610 if ( editorFocused
)
5616 #if defined(__WXGTK__)
5617 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5619 sibling
->SetFocusFromKbd();
5621 Navigate(wxNavigationKeyEvent::IsBackward
);
5629 // Ignore Alt and Control when they are down alone
5630 if ( keycode
== WXK_ALT
||
5631 keycode
== WXK_CONTROL
)
5638 int action
= KeyEventToActions(event
, &secondAction
);
5640 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5643 // Esc cancels any changes
5644 if ( IsEditorsValueModified() )
5646 EditorsValueWasNotModified();
5648 // Update the control as well
5649 selected
->GetEditorClass()->
5650 SetControlStringValue( selected
,
5652 selected
->GetDisplayedString() );
5655 OnValidationFailureReset(selected
);
5661 // Except for TAB, ESC, and any keys specifically dedicated to
5662 // wxPropertyGrid itself, handle child control events in child control.
5664 wxPGFindInVector(m_dedicatedKeys
, keycode
) == wxNOT_FOUND
)
5666 // Only propagate event if it had modifiers
5667 if ( !event
.HasModifiers() )
5669 event
.StopPropagation();
5675 bool wasHandled
= false;
5680 if ( ButtonTriggerKeyTest(action
, event
) )
5683 wxPGProperty
* p
= selected
;
5685 if ( action
== wxPG_ACTION_EDIT
&& !editorFocused
)
5687 DoSelectProperty( p
, wxPG_SEL_FOCUS
);
5691 // Travel and expand/collapse
5694 if ( p
->GetChildCount() )
5696 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5698 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5701 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5703 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5710 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5714 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5720 if ( selectDir
>= -1 )
5722 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5726 int reopenLabelEditorCol
= -1;
5728 if ( editorFocused
)
5730 // If editor was focused, then make the next editor
5732 selFlags
|= wxPG_SEL_FOCUS
;
5736 // Also maintain the same label editor focus state
5737 if ( m_labelEditor
)
5738 reopenLabelEditorCol
= m_selColumn
;
5741 DoSelectProperty(p
, selFlags
);
5743 if ( reopenLabelEditorCol
>= 0 )
5744 DoBeginLabelEdit(reopenLabelEditorCol
);
5751 // If nothing was selected, select the first item now
5752 // (or navigate out of tab).
5753 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5755 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5756 if ( p
) DoSelectProperty(p
);
5765 // -----------------------------------------------------------------------
5767 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5769 // If there was editor open and focused, then this event should not
5770 // really be processed here.
5771 if ( IsEditorFocused() )
5773 // However, if event had modifiers, it is probably still best
5775 if ( event
.HasModifiers() )
5778 event
.StopPropagation();
5782 HandleKeyEvent(event
, false);
5785 // -----------------------------------------------------------------------
5787 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5792 action
= KeyEventToActions(event
, &secondAction
);
5795 // Does the keycode trigger button?
5796 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5799 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5800 GetEventHandler()->AddPendingEvent(evt
);
5807 // -----------------------------------------------------------------------
5809 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5811 HandleKeyEvent(event
, true);
5814 // -----------------------------------------------------------------------
5815 // wxPropertyGrid miscellaneous event handling
5816 // -----------------------------------------------------------------------
5818 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5821 // Check if the focus is in this control or one of its children
5822 wxWindow
* newFocused
= wxWindow::FindFocus();
5824 if ( newFocused
!= m_curFocused
)
5825 HandleFocusChange( newFocused
);
5828 // Check if top-level parent has changed
5829 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5831 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5837 // Resolve pending property removals
5838 if ( m_deletedProperties
.size() > 0 )
5840 wxArrayPGProperty
& arr
= m_deletedProperties
;
5841 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5843 DeleteProperty(arr
[i
]);
5847 if ( m_removedProperties
.size() > 0 )
5849 wxArrayPGProperty
& arr
= m_removedProperties
;
5850 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5852 RemoveProperty(arr
[i
]);
5858 bool wxPropertyGrid::IsEditorFocused() const
5860 wxWindow
* focus
= wxWindow::FindFocus();
5862 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5863 focus
== GetEditorControl() )
5869 // Called by focus event handlers. newFocused is the window that becomes focused.
5870 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5873 // Never allow focus to be changed when handling editor event.
5874 // Especially because they may be displaing a dialog which
5875 // could cause all kinds of weird (native) focus changes.
5876 if ( HasInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
5879 unsigned int oldFlags
= m_iFlags
;
5880 bool wasEditorFocused
= false;
5881 wxWindow
* wndEditor
= m_wndEditor
;
5883 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5885 wxWindow
* parent
= newFocused
;
5887 // This must be one of nextFocus' parents.
5890 if ( parent
== wndEditor
)
5892 wasEditorFocused
= true;
5894 // Use m_eventObject, which is either wxPropertyGrid or
5895 // wxPropertyGridManager, as appropriate.
5896 else if ( parent
== m_eventObject
)
5898 m_iFlags
|= wxPG_FL_FOCUSED
;
5901 parent
= parent
->GetParent();
5904 // Notify editor control when it receives a focus
5905 if ( wasEditorFocused
&& m_curFocused
!= newFocused
)
5907 wxPGProperty
* p
= GetSelection();
5910 const wxPGEditor
* editor
= p
->GetEditorClass();
5911 ResetEditorAppearance();
5912 editor
->OnFocus(p
, GetEditorControl());
5916 m_curFocused
= newFocused
;
5918 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5919 (oldFlags
& wxPG_FL_FOCUSED
) )
5921 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5923 // Need to store changed value
5924 CommitChangesFromEditor();
5930 // Preliminary code for tab-order respecting
5931 // tab-traversal (but should be moved to
5934 wxWindow* prevFocus = event.GetWindow();
5935 wxWindow* useThis = this;
5936 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5937 useThis = GetParent();
5940 prevFocus->GetParent() == useThis->GetParent() )
5942 wxList& children = useThis->GetParent()->GetChildren();
5944 wxNode* node = children.Find(prevFocus);
5946 if ( node->GetNext() &&
5947 useThis == node->GetNext()->GetData() )
5948 DoSelectProperty(GetFirst());
5949 else if ( node->GetPrevious () &&
5950 useThis == node->GetPrevious()->GetData() )
5951 DoSelectProperty(GetLastProperty());
5958 wxPGProperty
* selected
= GetSelection();
5959 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5960 DrawItem( selected
);
5964 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5966 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5967 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5968 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5969 //else if ( event.GetWindow() )
5971 HandleFocusChange(event
.GetWindow());
5976 // -----------------------------------------------------------------------
5978 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5980 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5984 // -----------------------------------------------------------------------
5986 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5988 m_iFlags
|= wxPG_FL_SCROLLED
;
5993 // -----------------------------------------------------------------------
5995 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5997 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5999 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
6003 // -----------------------------------------------------------------------
6004 // Property editor related functions
6005 // -----------------------------------------------------------------------
6007 // noDefCheck = true prevents infinite recursion.
6008 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
6009 const wxString
& editorName
,
6012 wxASSERT( editorClass
);
6014 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
6015 RegisterDefaultEditors();
6017 wxString name
= editorName
;
6019 name
= editorClass
->GetName();
6021 // Existing editor under this name?
6022 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
6024 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
6026 // If this name was already used, try class name.
6027 name
= editorClass
->GetClassInfo()->GetClassName();
6028 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
6031 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
6032 (wxPGEditor
*) vt_it
->second
,
6033 "Editor with given name was already registered" );
6035 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
6040 // Use this in RegisterDefaultEditors.
6041 #define wxPGRegisterDefaultEditorClass(EDITOR) \
6042 if ( wxPGEditor_##EDITOR == NULL ) \
6044 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
6045 new wxPG##EDITOR##Editor, true ); \
6048 // Registers all default editor classes
6049 void wxPropertyGrid::RegisterDefaultEditors()
6051 wxPGRegisterDefaultEditorClass( TextCtrl
);
6052 wxPGRegisterDefaultEditorClass( Choice
);
6053 wxPGRegisterDefaultEditorClass( ComboBox
);
6054 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
6055 #if wxPG_INCLUDE_CHECKBOX
6056 wxPGRegisterDefaultEditorClass( CheckBox
);
6058 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
6060 // Register SpinCtrl etc. editors before use
6061 RegisterAdditionalEditors();
6064 // -----------------------------------------------------------------------
6065 // wxPGStringTokenizer
6066 // Needed to handle C-style string lists (e.g. "str1" "str2")
6067 // -----------------------------------------------------------------------
6069 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
6070 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
6074 wxPGStringTokenizer::~wxPGStringTokenizer()
6078 bool wxPGStringTokenizer::HasMoreTokens()
6080 const wxString
& str
= *m_str
;
6082 wxString::const_iterator i
= m_curPos
;
6084 wxUniChar delim
= m_delimeter
;
6086 wxUniChar prev_a
= wxT('\0');
6088 bool inToken
= false;
6090 while ( i
!= str
.end() )
6099 m_readyToken
.clear();
6104 if ( prev_a
!= wxT('\\') )
6108 if ( a
!= wxT('\\') )
6128 m_curPos
= str
.end();
6136 wxString
wxPGStringTokenizer::GetNextToken()
6138 return m_readyToken
;
6141 // -----------------------------------------------------------------------
6143 // -----------------------------------------------------------------------
6145 wxPGChoiceEntry::wxPGChoiceEntry()
6146 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
6150 // -----------------------------------------------------------------------
6152 // -----------------------------------------------------------------------
6154 wxPGChoicesData::wxPGChoicesData()
6158 wxPGChoicesData::~wxPGChoicesData()
6163 void wxPGChoicesData::Clear()
6168 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
6170 wxASSERT( m_items
.size() == 0 );
6172 m_items
= data
->m_items
;
6175 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
6176 const wxPGChoiceEntry
& item
)
6178 wxVector
<wxPGChoiceEntry
>::iterator it
;
6182 index
= (int) m_items
.size();
6186 it
= m_items
.begin() + index
;
6189 m_items
.insert(it
, item
);
6191 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
6193 // Need to fix value?
6194 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
6195 ownEntry
.SetValue(index
);
6200 // -----------------------------------------------------------------------
6201 // wxPropertyGridEvent
6202 // -----------------------------------------------------------------------
6204 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
6207 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
6208 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
6209 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
6210 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
6211 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
6212 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
6213 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
6214 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
6215 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
6216 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
6217 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
6218 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
6219 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
6220 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
6222 // -----------------------------------------------------------------------
6224 void wxPropertyGridEvent::Init()
6226 m_validationInfo
= NULL
;
6229 m_wasVetoed
= false;
6232 // -----------------------------------------------------------------------
6234 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6235 : wxCommandEvent(commandType
,id
)
6241 // -----------------------------------------------------------------------
6243 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6244 : wxCommandEvent(event
)
6246 m_eventType
= event
.GetEventType();
6247 m_eventObject
= event
.m_eventObject
;
6249 OnPropertyGridSet();
6250 m_property
= event
.m_property
;
6251 m_validationInfo
= event
.m_validationInfo
;
6252 m_canVeto
= event
.m_canVeto
;
6253 m_wasVetoed
= event
.m_wasVetoed
;
6256 // -----------------------------------------------------------------------
6258 void wxPropertyGridEvent::OnPropertyGridSet()
6264 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6266 m_pg
->m_liveEvents
.push_back(this);
6269 // -----------------------------------------------------------------------
6271 wxPropertyGridEvent::~wxPropertyGridEvent()
6276 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6279 // Use iterate from the back since it is more likely that the event
6280 // being desroyed is at the end of the array.
6281 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
6283 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
6285 if ( liveEvents
[i
] == this )
6287 liveEvents
.erase(liveEvents
.begin() + i
);
6294 // -----------------------------------------------------------------------
6296 wxEvent
* wxPropertyGridEvent::Clone() const
6298 return new wxPropertyGridEvent( *this );
6301 // -----------------------------------------------------------------------
6302 // wxPropertyGridPopulator
6303 // -----------------------------------------------------------------------
6305 wxPropertyGridPopulator::wxPropertyGridPopulator()
6309 wxPGGlobalVars
->m_offline
++;
6312 // -----------------------------------------------------------------------
6314 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6317 m_propHierarchy
.clear();
6320 // -----------------------------------------------------------------------
6322 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6328 // -----------------------------------------------------------------------
6330 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6333 // Free unused sets of choices
6334 wxPGHashMapS2P::iterator it
;
6336 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6338 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6345 m_pg
->GetPanel()->Refresh();
6347 wxPGGlobalVars
->m_offline
--;
6350 // -----------------------------------------------------------------------
6352 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6353 const wxString
& propLabel
,
6354 const wxString
& propName
,
6355 const wxString
* propValue
,
6356 wxPGChoices
* pChoices
)
6358 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6359 wxPGProperty
* parent
= GetCurParent();
6361 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6363 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6367 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6369 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6373 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6375 property
->SetLabel(propLabel
);
6376 property
->DoSetName(propName
);
6378 if ( pChoices
&& pChoices
->IsOk() )
6379 property
->SetChoices(*pChoices
);
6381 m_state
->DoInsert(parent
, -1, property
);
6384 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
6385 wxPG_PROGRAMMATIC_VALUE
);
6390 // -----------------------------------------------------------------------
6392 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6394 m_propHierarchy
.push_back(property
);
6395 DoScanForChildren();
6396 m_propHierarchy
.pop_back();
6399 // -----------------------------------------------------------------------
6401 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6402 const wxString
& idString
)
6404 wxPGChoices choices
;
6407 if ( choicesString
[0] == wxT('@') )
6409 wxString ids
= choicesString
.substr(1);
6410 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6411 if ( it
== m_dictIdChoices
.end() )
6412 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6414 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6419 if ( !idString
.empty() )
6421 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6422 if ( it
!= m_dictIdChoices
.end() )
6424 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6431 // Parse choices string
6432 wxString::const_iterator it
= choicesString
.begin();
6436 bool labelValid
= false;
6438 for ( ; it
!= choicesString
.end(); ++it
)
6444 if ( c
== wxT('"') )
6449 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6450 choices
.Add(label
, l
);
6453 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6458 else if ( c
== wxT('=') )
6465 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6472 if ( c
== wxT('"') )
6485 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6486 choices
.Add(label
, l
);
6489 if ( !choices
.IsOk() )
6491 choices
.EnsureData();
6495 if ( !idString
.empty() )
6496 m_dictIdChoices
[idString
] = choices
.GetData();
6503 // -----------------------------------------------------------------------
6505 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6507 if ( s
.Last() == wxT('%') )
6509 wxString s2
= s
.substr(0,s
.length()-1);
6511 if ( s2
.ToLong(&val
, 10) )
6513 *pval
= (val
*max
)/100;
6519 return s
.ToLong(pval
, 10);
6522 // -----------------------------------------------------------------------
6524 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6525 const wxString
& type
,
6526 const wxString
& value
)
6528 int l
= m_propHierarchy
.size();
6532 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6533 wxString valuel
= value
.Lower();
6541 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6543 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6545 else if ( value
.ToLong(&v
, 0) )
6552 if ( type
== wxT("string") )
6556 else if ( type
== wxT("int") )
6559 value
.ToLong(&v
, 0);
6562 else if ( type
== wxT("bool") )
6564 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6571 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6576 p
->SetAttribute( name
, variant
);
6581 // -----------------------------------------------------------------------
6583 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6585 wxLogError(_("Error in resource: %s"),msg
.c_str());
6588 // -----------------------------------------------------------------------
6590 #endif // wxUSE_PROPGRID