1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
67 // Two pics for the expand / collapse buttons.
68 // Files are not supplied with this project (since it is
69 // recommended to use either custom or native rendering).
70 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
71 // and copy xpm files from archive to wxPropertyGrid src directory
72 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
73 // and set wxPG_USE_RENDERER_NATIVE to 0).
74 #ifndef wxPG_ICON_WIDTH
75 #if defined(__WXMAC__)
76 #include "mac_collapse.xpm"
77 #include "mac_expand.xpm"
78 #elif defined(__WXGTK__)
79 #include "linux_collapse.xpm"
80 #include "linux_expand.xpm"
82 #include "default_collapse.xpm"
83 #include "default_expand.xpm"
88 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
89 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
90 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
91 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
92 #define wxPG_YSPACING_MIN 1
93 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
94 // but causes normal combobox to spill out under MSW
96 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
98 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
99 // Must be larger than largest control border
103 #define wxPG_DEFAULT_CURSOR wxNullCursor
106 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
108 //#define wxPG_HIDER_BUTTON_HEIGHT 25
110 #define wxPG_PIXELS_PER_UNIT m_lineHeight
112 #ifdef wxPG_ICON_WIDTH
113 #define m_iconHeight m_iconWidth
116 //#define wxPG_TOOLTIP_DELAY 1000
118 // This is the number of pixels the expander button inside
119 // property cells (i.e. not in the grey margin area are
121 #define IN_CELL_EXPANDER_BUTTON_X_ADJUST 2
123 // -----------------------------------------------------------------------
126 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
128 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
131 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
134 // -----------------------------------------------------------------------
136 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
138 // -----------------------------------------------------------------------
139 // Statics in one class for easy destruction.
140 // -----------------------------------------------------------------------
142 #include "wx/module.h"
144 class wxPGGlobalVarsClassManager
: public wxModule
146 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
148 wxPGGlobalVarsClassManager() {}
149 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
150 virtual void OnExit() { wxDELETE(wxPGGlobalVars
); }
153 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
156 // When wxPG is loaded dynamically after the application is already running
157 // then the built-in module system won't pick this one up. Add it manually.
158 void wxPGInitResourceModule()
160 wxModule
* module = new wxPGGlobalVarsClassManager
;
162 wxModule::RegisterModule(module);
165 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
168 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
170 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
172 m_boolChoices
.Add(_("False"));
173 m_boolChoices
.Add(_("True"));
175 m_fontFamilyChoices
= NULL
;
177 m_defaultRenderer
= new wxPGDefaultRenderer();
179 m_autoGetTranslation
= false;
187 // Prepare some shared variants
188 m_vEmptyString
= wxString();
190 m_vMinusOne
= (long) -1;
194 // Prepare cached string constants
195 m_strstring
= wxS("string");
196 m_strlong
= wxS("long");
197 m_strbool
= wxS("bool");
198 m_strlist
= wxS("list");
199 m_strDefaultValue
= wxS("DefaultValue");
200 m_strMin
= wxS("Min");
201 m_strMax
= wxS("Max");
202 m_strUnits
= wxS("Units");
203 m_strHint
= wxS("Hint");
204 #if wxPG_COMPATIBILITY_1_4
205 m_strInlineHelp
= wxS("InlineHelp");
212 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
216 delete m_defaultRenderer
;
218 // This will always have one ref
219 delete m_fontFamilyChoices
;
222 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
223 delete ((wxValidator
*)m_arrValidators
[i
]);
227 // Destroy value type class instances.
228 wxPGHashMapS2P::iterator vt_it
;
230 // Destroy editor class instances.
231 // iterate over all the elements in the class
232 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
234 delete ((wxPGEditor
*)vt_it
->second
);
237 delete wxPGProperty::sm_wxPG_LABEL
;
240 void wxPropertyGridInitGlobalsIfNeeded()
244 // -----------------------------------------------------------------------
246 // -----------------------------------------------------------------------
248 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
250 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
251 EVT_IDLE(wxPropertyGrid::OnIdle
)
252 EVT_PAINT(wxPropertyGrid::OnPaint
)
253 EVT_SIZE(wxPropertyGrid::OnResize
)
254 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
255 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
256 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
257 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
258 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
259 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
260 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
261 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
262 EVT_MOTION(wxPropertyGrid::OnMouseMove
)
263 EVT_LEFT_DOWN(wxPropertyGrid::OnMouseClick
)
264 EVT_LEFT_UP(wxPropertyGrid::OnMouseUp
)
265 EVT_RIGHT_UP(wxPropertyGrid::OnMouseRightClick
)
266 EVT_LEFT_DCLICK(wxPropertyGrid::OnMouseDoubleClick
)
267 EVT_KEY_DOWN(wxPropertyGrid::OnKey
)
270 // -----------------------------------------------------------------------
272 wxPropertyGrid::wxPropertyGrid()
278 // -----------------------------------------------------------------------
280 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
285 const wxString
& name
)
289 Create(parent
,id
,pos
,size
,style
,name
);
292 // -----------------------------------------------------------------------
294 bool wxPropertyGrid::Create( wxWindow
*parent
,
299 const wxString
& name
)
302 if (!(style
&wxBORDER_MASK
))
304 style
|= wxBORDER_THEME
;
309 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
310 style
&= ~(wxTAB_TRAVERSAL
);
311 style
|= wxWANTS_CHARS
;
313 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
320 // -----------------------------------------------------------------------
323 // Initialize values to defaults
325 void wxPropertyGrid::Init1()
327 // Register editor classes, if necessary.
328 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
329 wxPropertyGrid::RegisterDefaultEditors();
331 m_validatingEditor
= 0;
334 m_wndEditor
= m_wndEditor2
= NULL
;
338 m_labelEditor
= NULL
;
339 m_labelEditorProperty
= NULL
;
340 m_eventObject
= this;
342 m_processedEvent
= NULL
;
343 m_sortFunction
= NULL
;
344 m_inDoPropertyChanged
= 0;
345 m_inCommitChangesFromEditor
= 0;
346 m_inDoSelectProperty
= 0;
347 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
352 // Set up default unspecified value 'colour'
353 m_unspecifiedAppearance
.SetFgCol(*wxLIGHT_GREY
);
356 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
357 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
358 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
359 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
360 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
361 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
362 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
363 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
364 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
366 m_coloursCustomized
= 0;
369 #if wxPG_DOUBLE_BUFFER
370 m_doubleBuffer
= NULL
;
373 #ifndef wxPG_ICON_WIDTH
379 m_iconWidth
= wxPG_ICON_WIDTH
;
384 m_gutterWidth
= wxPG_GUTTER_MIN
;
385 m_subgroup_extramargin
= 10;
389 m_width
= m_height
= 0;
391 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
394 m_chgInfo_changedProperty
= NULL
;
397 // -----------------------------------------------------------------------
400 // Initialize after parent etc. set
402 void wxPropertyGrid::Init2()
404 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
407 // Smaller controls on Mac
408 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
411 // Now create state, if one didn't exist already
412 // (wxPropertyGridManager might have created it for us).
415 m_pState
= CreateState();
416 m_pState
->m_pPropGrid
= this;
417 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
420 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
421 m_pState
->m_dontCenterSplitter
= true;
423 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
425 m_pState
->InitNonCatMode();
427 m_pState
->m_properties
= m_pState
->m_abcArray
;
430 GetClientSize(&m_width
,&m_height
);
432 #ifndef wxPG_ICON_WIDTH
433 // create two bitmap nodes for drawing
434 m_expandbmp
= new wxBitmap(expand_xpm
);
435 m_collbmp
= new wxBitmap(collapse_xpm
);
437 // calculate average font height for bitmap centering
439 m_iconWidth
= m_expandbmp
->GetWidth();
440 m_iconHeight
= m_expandbmp
->GetHeight();
443 m_curcursor
= wxCURSOR_ARROW
;
444 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
446 // adjust bitmap icon y position so they are centered
447 m_vspacing
= wxPG_DEFAULT_VSPACING
;
449 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
451 // Allocate cell datas
452 m_propertyDefaultCell
.SetEmptyData();
453 m_categoryDefaultCell
.SetEmptyData();
457 // This helps with flicker
458 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
460 // Hook the top-level parent
465 // set virtual size to this window size
466 wxSize wndsize
= GetSize();
467 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
469 m_timeCreated
= ::wxGetLocalTimeMillis();
471 //m_canvas->Create(this, wxID_ANY, wxPoint(0, 0), GetClientSize(),
472 // wxWANTS_CHARS | wxCLIP_CHILDREN);
473 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
475 m_iFlags
|= wxPG_FL_INITIALIZED
;
477 m_ncWidth
= wndsize
.GetWidth();
479 // Need to call OnResize handler or size given in constructor/Create
481 wxSizeEvent
sizeEvent(wndsize
,0);
485 // -----------------------------------------------------------------------
487 wxPropertyGrid::~wxPropertyGrid()
492 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
496 // Remove grid and property pointers from live wxPropertyGridEvents.
497 for ( i
=0; i
<m_liveEvents
.size(); i
++ )
499 wxPropertyGridEvent
* evt
= m_liveEvents
[i
];
500 evt
->SetPropertyGrid(NULL
);
501 evt
->SetProperty(NULL
);
503 m_liveEvents
.clear();
505 if ( m_processedEvent
)
507 // All right... we are being deleted while wxPropertyGrid event
508 // is being sent. Make sure that event propagates as little
509 // as possible (although usually this is not enough to prevent
511 m_processedEvent
->Skip(false);
512 m_processedEvent
->StopPropagation();
514 // Let's use wxMessageBox to make the message appear more
515 // reliably (and *before* the crash can happen).
516 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
517 "generated by it. This usually leads to a crash "
518 "so it is recommended to destroy the control "
519 "at idle time instead.");
522 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
524 // This should do prevent things from going too badly wrong
525 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
527 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
530 // Call with NULL to disconnect event handling
531 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
535 wxASSERT_MSG( !IsEditorsValueModified(),
536 wxS("Most recent change in property editor was ")
537 wxS("lost!!! (if you don't want this to happen, ")
538 wxS("close your frames and dialogs using ")
539 wxS("Close(false).)") );
542 #if wxPG_DOUBLE_BUFFER
543 if ( m_doubleBuffer
)
544 delete m_doubleBuffer
;
547 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
550 delete m_cursorSizeWE
;
552 #ifndef wxPG_ICON_WIDTH
557 // Delete common value records
558 for ( i
=0; i
<m_commonValues
.size(); i
++ )
560 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
561 wxPGCommonValue
* value
= m_commonValues
[i
];
566 // -----------------------------------------------------------------------
568 bool wxPropertyGrid::Destroy()
570 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
573 return wxScrolledWindow::Destroy();
576 // -----------------------------------------------------------------------
578 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
580 return new wxPropertyGridPageState();
583 // -----------------------------------------------------------------------
584 // wxPropertyGrid overridden wxWindow methods
585 // -----------------------------------------------------------------------
587 void wxPropertyGrid::SetWindowStyleFlag( long style
)
589 long old_style
= m_windowStyle
;
591 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
593 wxASSERT( m_pState
);
595 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
598 EnableCategories( true );
600 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
602 // Disable categories
603 EnableCategories( false );
605 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
611 PrepareAfterItemsAdded();
613 m_pState
->m_itemsAdded
= 1;
615 #if wxPG_SUPPORT_TOOLTIPS
616 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
622 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
623 SetToolTip ( tooltip );
624 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
627 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
632 wxScrolledWindow::SetToolTip( NULL
);
637 wxScrolledWindow::SetWindowStyleFlag ( style
);
639 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
641 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
643 CalculateFontAndBitmapStuff( m_vspacing
);
649 // -----------------------------------------------------------------------
651 void wxPropertyGrid::Freeze()
655 wxScrolledWindow::Freeze();
660 // -----------------------------------------------------------------------
662 void wxPropertyGrid::Thaw()
668 wxScrolledWindow::Thaw();
669 RecalculateVirtualSize();
670 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
674 // Force property re-selection
675 // NB: We must copy the selection.
676 wxArrayPGProperty selection
= m_pState
->m_selection
;
677 DoSetSelection(selection
, wxPG_SEL_FORCE
| wxPG_SEL_NONVISIBLE
);
681 // -----------------------------------------------------------------------
683 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
685 wxCHECK( prop
, false );
687 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
688 return DoSelectProperty(prop
, selFlags
);
690 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
692 if ( !selection
.size() )
694 return DoSelectProperty(prop
, selFlags
);
698 // For categories, only one can be selected at a time
699 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
702 selection
.push_back(prop
);
704 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
706 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
715 // -----------------------------------------------------------------------
717 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
719 wxCHECK( prop
, false );
722 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
723 if ( selection
.size() <= 1 )
725 res
= DoSelectProperty(NULL
, selFlags
);
729 m_pState
->DoRemoveFromSelection(prop
);
737 // -----------------------------------------------------------------------
739 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
740 unsigned int colIndex
,
741 unsigned int selFlags
)
744 // NB: Enable following if label editor background colour is
745 // ever changed to any other than m_colSelBack.
747 // We use this workaround to prevent visible flicker when editing
748 // a cell. Atleast on wxMSW, there is a difficult to find
749 // (and perhaps prevent) redraw somewhere between making property
750 // selected and enabling label editing.
752 //wxColour prevColSelBack = m_colSelBack;
753 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
759 res
= DoSelectProperty(prop
, selFlags
);
764 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
766 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
768 res
= DoAddToSelection(prop
, selFlags
);
772 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
774 DoBeginLabelEdit(colIndex
, selFlags
);
778 //m_colSelBack = prevColSelBack;
782 // -----------------------------------------------------------------------
784 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
785 unsigned int colIndex
,
786 wxMouseEvent
* mouseEvent
,
789 const wxArrayPGProperty
& selection
= GetSelectedProperties();
790 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
793 // Set to 2 if also add all items in between
794 int addToExistingSelection
= 0;
796 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
800 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
801 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
803 // Allow right-click for context menu without
804 // disturbing the selection.
805 if ( GetSelectedProperties().size() <= 1 ||
807 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
812 if ( mouseEvent
->ControlDown() )
814 addToExistingSelection
= 1;
816 else if ( mouseEvent
->ShiftDown() )
818 if ( selection
.size() > 0 && !prop
->IsCategory() )
819 addToExistingSelection
= 2;
821 addToExistingSelection
= 1;
827 if ( addToExistingSelection
== 1 )
830 if ( !alreadySelected
)
832 res
= DoAddToSelection(prop
, selFlags
);
834 else if ( GetSelectedProperties().size() > 1 )
836 res
= DoRemoveFromSelection(prop
, selFlags
);
839 else if ( addToExistingSelection
== 2 )
841 // Add this, and all in between
843 // Find top selected property
844 wxPGProperty
* topSelProp
= selection
[0];
845 int topSelPropY
= topSelProp
->GetY();
846 for ( unsigned int i
=1; i
<selection
.size(); i
++ )
848 wxPGProperty
* p
= selection
[i
];
850 if ( y
< topSelPropY
)
857 wxPGProperty
* startFrom
;
858 wxPGProperty
* stopAt
;
860 if ( prop
->GetY() <= topSelPropY
)
862 // Property is above selection (or same)
868 // Property is below selection
869 startFrom
= topSelProp
;
873 // Iterate through properties in-between, and select them
874 wxPropertyGridIterator it
;
876 for ( it
= GetIterator(wxPG_ITERATE_VISIBLE
, startFrom
);
880 wxPGProperty
* p
= *it
;
882 if ( !p
->IsCategory() &&
883 !m_pState
->DoIsPropertySelected(p
) )
885 DoAddToSelection(p
, selFlags
);
894 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
900 // -----------------------------------------------------------------------
902 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
905 if ( newSelection
.size() > 0 )
907 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
912 DoClearSelection(false, selFlags
);
915 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
917 DoAddToSelection(newSelection
[i
], selFlags
);
923 // -----------------------------------------------------------------------
925 void wxPropertyGrid::MakeColumnEditable( unsigned int column
,
928 wxASSERT( column
!= 1 );
930 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
934 cols
.push_back(column
);
938 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
940 if ( cols
[i
] == (int)column
)
941 cols
.erase( cols
.begin() + i
);
946 // -----------------------------------------------------------------------
948 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
951 wxPGProperty
* selected
= GetSelection();
952 wxCHECK_RET(selected
, wxT("No property selected"));
953 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
955 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
957 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
964 const wxPGCell
* cell
= NULL
;
965 if ( selected
->HasCell(colIndex
) )
967 cell
= &selected
->GetCell(colIndex
);
968 if ( !cell
->HasText() && colIndex
== 0 )
969 text
= selected
->GetLabel();
975 text
= selected
->GetLabel();
977 cell
= &selected
->GetOrCreateCell(colIndex
);
980 if ( cell
&& cell
->HasText() )
981 text
= cell
->GetText();
983 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
985 m_selColumn
= colIndex
;
987 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
989 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
997 wxWindowID id
= tc
->GetId();
998 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
999 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
1001 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1002 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
1007 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1008 m_labelEditorProperty
= selected
;
1011 // -----------------------------------------------------------------------
1014 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1016 DoEndLabelEdit(true);
1019 // -----------------------------------------------------------------------
1021 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1023 int keycode
= event
.GetKeyCode();
1025 if ( keycode
== WXK_ESCAPE
)
1027 DoEndLabelEdit(false);
1031 HandleKeyEvent(event
, true);
1035 // -----------------------------------------------------------------------
1037 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1039 if ( !m_labelEditor
)
1042 wxPGProperty
* prop
= m_labelEditorProperty
;
1047 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1049 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1050 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1051 prop
, NULL
, selFlags
,
1056 wxString text
= m_labelEditor
->GetValue();
1057 wxPGCell
* cell
= NULL
;
1058 if ( prop
->HasCell(m_selColumn
) )
1060 cell
= &prop
->GetCell(m_selColumn
);
1064 if ( m_selColumn
== 0 )
1065 prop
->SetLabel(text
);
1067 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1071 cell
->SetText(text
);
1075 int wasFocused
= m_iFlags
& wxPG_FL_FOCUSED
;
1077 DestroyEditorWnd(m_labelEditor
);
1079 m_labelEditor
= NULL
;
1080 m_labelEditorProperty
= NULL
;
1082 // Fix focus (needed at least on wxGTK)
1089 // -----------------------------------------------------------------------
1091 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1093 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1094 OnTLPChanging(::wxGetTopLevelParent(this));
1096 OnTLPChanging(NULL
);
1098 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1100 #if defined(__WXMSW__)
1103 // Don't use WS_EX_COMPOSITED just now.
1106 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1107 hWnd = (HWND)GetParent()->GetHWND();
1109 hWnd = (HWND)GetHWND();
1111 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1112 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1115 //#elif defined(__WXGTK20__)
1117 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1118 // truly was double-buffered.
1119 if ( !this->IsDoubleBuffered() )
1121 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1125 #if wxPG_DOUBLE_BUFFER
1126 wxDELETE(m_doubleBuffer
);
1131 wxScrolledWindow::SetExtraStyle( exStyle
);
1133 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1134 m_pState
->InitNonCatMode();
1136 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1137 m_windowStyle
|= wxPG_TOOLTIPS
;
1140 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1143 // -----------------------------------------------------------------------
1145 // returns the best acceptable minimal size
1146 wxSize
wxPropertyGrid::DoGetBestSize() const
1148 int lineHeight
= wxMax(15, m_lineHeight
);
1150 // don't make the grid too tall (limit height to 10 items) but don't
1151 // make it too small neither
1152 int numLines
= wxMin
1154 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1158 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1159 int width
= m_marginWidth
;
1160 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1162 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1165 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1171 // -----------------------------------------------------------------------
1173 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1175 if ( newTLP
== m_tlp
)
1178 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1181 // Parent changed so let's redetermine and re-hook the
1182 // correct top-level window.
1185 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1186 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1188 m_tlpClosed
= m_tlp
;
1189 m_tlpClosedTime
= currentTime
;
1194 // Only accept new tlp if same one was not just dismissed.
1195 if ( newTLP
!= m_tlpClosed
||
1196 m_tlpClosedTime
+250 < currentTime
)
1198 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1199 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1212 // -----------------------------------------------------------------------
1214 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1216 // ClearSelection forces value validation/commit.
1217 if ( event
.CanVeto() && !DoClearSelection() )
1223 // Ok, it can close, set tlp pointer to NULL. Some other event
1224 // handler can of course veto the close, but our OnIdle() should
1225 // then be able to regain the tlp pointer.
1226 OnTLPChanging(NULL
);
1231 // -----------------------------------------------------------------------
1233 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1235 OnTLPChanging((wxWindow
*)newParent
);
1237 bool res
= wxScrolledWindow::Reparent(newParent
);
1242 // -----------------------------------------------------------------------
1243 // wxPropertyGrid Font and Colour Methods
1244 // -----------------------------------------------------------------------
1246 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1250 m_captionFont
= wxScrolledWindow::GetFont();
1252 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1253 m_subgroup_extramargin
= x
+ (x
/2);
1256 #if wxPG_USE_RENDERER_NATIVE
1257 m_iconWidth
= wxPG_ICON_WIDTH
;
1258 #elif wxPG_ICON_WIDTH
1260 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1261 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1262 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1266 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1267 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1268 m_gutterWidth
= wxPG_GUTTER_MIN
;
1271 if ( vspacing
<= 1 ) vdiv
= 12;
1272 else if ( vspacing
>= 3 ) vdiv
= 3;
1274 m_spacingy
= m_fontHeight
/ vdiv
;
1275 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1276 m_spacingy
= wxPG_YSPACING_MIN
;
1279 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1280 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1282 m_captionFont
.SetWeight(wxBOLD
);
1283 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1285 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1288 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1289 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1292 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1294 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1295 RecalculateVirtualSize();
1297 InvalidateBestSize();
1300 // -----------------------------------------------------------------------
1302 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1308 // -----------------------------------------------------------------------
1310 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1311 int ga
= 1000, int ba
= 1000,
1312 bool forceDifferent
= false)
1319 // Recursion guard (allow 2 max)
1320 static int isinside
= 0;
1322 wxCHECK_MSG( isinside
< 3,
1324 wxT("wxPGAdjustColour should not be recursively called more than once") );
1329 int g
= src
.Green();
1332 if ( r2
>255 ) r2
= 255;
1333 else if ( r2
<0) r2
= 0;
1335 if ( g2
>255 ) g2
= 255;
1336 else if ( g2
<0) g2
= 0;
1338 if ( b2
>255 ) b2
= 255;
1339 else if ( b2
<0) b2
= 0;
1341 // Make sure they are somewhat different
1342 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1343 dst
= wxPGAdjustColour(src
,-(ra
*2));
1345 dst
= wxColour(r2
,g2
,b2
);
1347 // Recursion guard (allow 2 max)
1354 static int wxPGGetColAvg( const wxColour
& col
)
1356 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1360 void wxPropertyGrid::RegainColours()
1362 if ( !(m_coloursCustomized
& 0x0002) )
1364 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1366 // Make sure colour is dark enough
1368 int colDec
= wxPGGetColAvg(col
) - 230;
1370 int colDec
= wxPGGetColAvg(col
) - 200;
1373 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1376 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1379 if ( !(m_coloursCustomized
& 0x0001) )
1380 m_colMargin
= m_colCapBack
;
1382 if ( !(m_coloursCustomized
& 0x0004) )
1389 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1390 m_colCapFore
= capForeCol
;
1391 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1394 if ( !(m_coloursCustomized
& 0x0008) )
1396 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1397 m_colPropBack
= bgCol
;
1398 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1399 if ( !m_unspecifiedAppearance
.GetBgCol().IsOk() )
1400 m_unspecifiedAppearance
.SetBgCol(bgCol
);
1403 if ( !(m_coloursCustomized
& 0x0010) )
1405 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1406 m_colPropFore
= fgCol
;
1407 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1408 if ( !m_unspecifiedAppearance
.GetFgCol().IsOk() )
1409 m_unspecifiedAppearance
.SetFgCol(fgCol
);
1412 if ( !(m_coloursCustomized
& 0x0020) )
1413 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1415 if ( !(m_coloursCustomized
& 0x0040) )
1416 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1418 if ( !(m_coloursCustomized
& 0x0080) )
1419 m_colLine
= m_colCapBack
;
1421 if ( !(m_coloursCustomized
& 0x0100) )
1422 m_colDisPropFore
= m_colCapFore
;
1424 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1427 // -----------------------------------------------------------------------
1429 void wxPropertyGrid::ResetColours()
1431 m_coloursCustomized
= 0;
1438 // -----------------------------------------------------------------------
1440 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1442 // Must disable active editor.
1445 bool res
= wxScrolledWindow::SetFont( font
);
1446 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1448 CalculateFontAndBitmapStuff( m_vspacing
);
1455 // -----------------------------------------------------------------------
1457 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1460 m_coloursCustomized
|= 0x80;
1464 // -----------------------------------------------------------------------
1466 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1469 m_coloursCustomized
|= 0x01;
1473 // -----------------------------------------------------------------------
1475 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1477 m_colPropBack
= col
;
1478 m_coloursCustomized
|= 0x08;
1480 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1481 m_unspecifiedAppearance
.SetBgCol(col
);
1486 // -----------------------------------------------------------------------
1488 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1490 m_colPropFore
= col
;
1491 m_coloursCustomized
|= 0x10;
1493 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1494 m_unspecifiedAppearance
.SetFgCol(col
);
1499 // -----------------------------------------------------------------------
1501 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1503 m_colEmptySpace
= col
;
1508 // -----------------------------------------------------------------------
1510 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1512 m_colDisPropFore
= col
;
1513 m_coloursCustomized
|= 0x100;
1517 // -----------------------------------------------------------------------
1519 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1522 m_coloursCustomized
|= 0x20;
1526 // -----------------------------------------------------------------------
1528 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1531 m_coloursCustomized
|= 0x40;
1535 // -----------------------------------------------------------------------
1537 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1540 m_coloursCustomized
|= 0x02;
1542 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1547 // -----------------------------------------------------------------------
1549 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1552 m_coloursCustomized
|= 0x04;
1554 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1559 // -----------------------------------------------------------------------
1560 // wxPropertyGrid property adding and removal
1561 // -----------------------------------------------------------------------
1563 void wxPropertyGrid::PrepareAfterItemsAdded()
1565 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1567 m_pState
->m_itemsAdded
= 0;
1569 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1570 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1572 RecalculateVirtualSize();
1574 // Fix editor position
1575 CorrectEditorWidgetPosY();
1578 // -----------------------------------------------------------------------
1579 // wxPropertyGrid property operations
1580 // -----------------------------------------------------------------------
1582 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1584 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1588 bool changed
= false;
1590 // Is it inside collapsed section?
1591 if ( !p
->IsVisible() )
1594 wxPGProperty
* parent
= p
->GetParent();
1595 wxPGProperty
* grandparent
= parent
->GetParent();
1597 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1598 Expand( grandparent
);
1606 GetViewStart(&vx
,&vy
);
1607 vy
*=wxPG_PIXELS_PER_UNIT
;
1613 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1614 m_iFlags
|= wxPG_FL_SCROLLED
;
1617 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1619 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1620 m_iFlags
|= wxPG_FL_SCROLLED
;
1630 // -----------------------------------------------------------------------
1631 // wxPropertyGrid helper methods called by properties
1632 // -----------------------------------------------------------------------
1634 // Control font changer helper.
1635 void wxPropertyGrid::SetCurControlBoldFont()
1637 wxWindow
* editor
= GetEditorControl();
1638 editor
->SetFont( m_captionFont
);
1641 // -----------------------------------------------------------------------
1643 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1646 #if wxPG_SMALL_SCREEN
1647 // On small-screen devices, always show dialogs with default position and size.
1648 return wxDefaultPosition
;
1650 int splitterX
= GetSplitterPosition();
1654 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1656 ImprovedClientToScreen( &x
, &y
);
1658 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1659 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1666 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1676 new_y
= y
+ m_lineHeight
;
1678 return wxPoint(new_x
,new_y
);
1682 // -----------------------------------------------------------------------
1684 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1686 if ( src_str
.length() == 0 )
1692 bool prev_is_slash
= false;
1694 wxString::const_iterator i
= src_str
.begin();
1698 for ( ; i
!= src_str
.end(); ++i
)
1702 if ( a
!= wxS('\\') )
1704 if ( !prev_is_slash
)
1710 if ( a
== wxS('n') )
1713 dst_str
<< wxS('\n');
1715 dst_str
<< wxS('\n');
1718 else if ( a
== wxS('t') )
1719 dst_str
<< wxS('\t');
1723 prev_is_slash
= false;
1727 if ( prev_is_slash
)
1729 dst_str
<< wxS('\\');
1730 prev_is_slash
= false;
1734 prev_is_slash
= true;
1741 // -----------------------------------------------------------------------
1743 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1745 if ( src_str
.length() == 0 )
1751 wxString::const_iterator i
= src_str
.begin();
1752 wxUniChar prev_a
= wxS('\0');
1756 for ( ; i
!= src_str
.end(); ++i
)
1760 if ( a
>= wxS(' ') )
1762 // This surely is not something that requires an escape sequence.
1767 // This might need...
1768 if ( a
== wxS('\r') )
1770 // DOS style line end.
1771 // Already taken care below
1773 else if ( a
== wxS('\n') )
1774 // UNIX style line end.
1775 dst_str
<< wxS("\\n");
1776 else if ( a
== wxS('\t') )
1778 dst_str
<< wxS('\t');
1781 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1791 // -----------------------------------------------------------------------
1793 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1800 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1803 // -----------------------------------------------------------------------
1804 // wxPropertyGrid graphics related methods
1805 // -----------------------------------------------------------------------
1807 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1812 // Don't paint after destruction has begun
1813 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1816 // Find out where the window is scrolled to
1817 int vx
,vy
; // Top left corner of client
1818 GetViewStart(&vx
,&vy
);
1819 vy
*= wxPG_PIXELS_PER_UNIT
;
1821 // Update everything inside the box
1822 wxRect r
= GetUpdateRegion().GetBox();
1826 // FIXME: This is just a workaround for a bug that causes splitters not
1827 // to paint when other windows are being dragged over the grid.
1829 r
.width
= GetClientSize().x
;
1831 // Repaint this rectangle
1832 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1834 // We assume that the size set when grid is shown
1835 // is what is desired.
1836 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1839 // -----------------------------------------------------------------------
1841 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1842 wxPGProperty
* property
) const
1844 // Prepare rectangle to be used
1846 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1847 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1849 #if (wxPG_USE_RENDERER_NATIVE)
1851 #elif wxPG_ICON_WIDTH
1852 // Drawing expand/collapse button manually
1853 dc
.SetPen(m_colPropFore
);
1854 if ( property
->IsCategory() )
1855 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1857 dc
.SetBrush(m_colPropBack
);
1859 dc
.DrawRectangle( r
);
1860 int _y
= r
.y
+(m_iconWidth
/2);
1861 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1866 if ( property
->IsExpanded() )
1868 // wxRenderer functions are non-mutating in nature, so it
1869 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1870 // Hopefully this does not cause problems.
1871 #if (wxPG_USE_RENDERER_NATIVE)
1872 wxRendererNative::Get().DrawTreeItemButton(
1878 #elif wxPG_ICON_WIDTH
1887 #if (wxPG_USE_RENDERER_NATIVE)
1888 wxRendererNative::Get().DrawTreeItemButton(
1894 #elif wxPG_ICON_WIDTH
1895 int _x
= r
.x
+(m_iconWidth
/2);
1896 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1902 #if (wxPG_USE_RENDERER_NATIVE)
1904 #elif wxPG_ICON_WIDTH
1907 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1911 // -----------------------------------------------------------------------
1914 // This is the one called by OnPaint event handler and others.
1915 // topy and bottomy are already unscrolled (ie. physical)
1917 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1918 unsigned int topItemY
,
1919 unsigned int bottomItemY
,
1920 const wxRect
* drawRect
)
1924 bottomItemY
< topItemY
||
1928 m_pState
->EnsureVirtualHeight();
1930 wxRect tempDrawRect
;
1933 tempDrawRect
= wxRect(0, topItemY
,
1936 drawRect
= &tempDrawRect
;
1939 // items added check
1940 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1942 int paintFinishY
= 0;
1944 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1947 bool isBuffered
= false;
1949 #if wxPG_DOUBLE_BUFFER
1950 wxMemoryDC
* bufferDC
= NULL
;
1952 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1954 if ( !m_doubleBuffer
)
1956 paintFinishY
= drawRect
->y
;
1961 bufferDC
= new wxMemoryDC();
1963 // If nothing was changed, then just copy from double-buffer
1964 bufferDC
->SelectObject( *m_doubleBuffer
);
1974 dc
.SetClippingRegion( *drawRect
);
1975 paintFinishY
= DoDrawItems( *dcPtr
, drawRect
, isBuffered
);
1976 int drawBottomY
= drawRect
->y
+ drawRect
->height
;
1978 // Clear area beyond last painted property
1979 if ( paintFinishY
< drawBottomY
)
1981 dcPtr
->SetPen(m_colEmptySpace
);
1982 dcPtr
->SetBrush(m_colEmptySpace
);
1983 dcPtr
->DrawRectangle(0, paintFinishY
,
1988 dc
.DestroyClippingRegion();
1991 #if wxPG_DOUBLE_BUFFER
1994 dc
.Blit( drawRect
->x
, drawRect
->y
, drawRect
->width
,
1996 bufferDC
, 0, 0, wxCOPY
);
2003 // Just clear the area
2004 dc
.SetPen(m_colEmptySpace
);
2005 dc
.SetBrush(m_colEmptySpace
);
2006 dc
.DrawRectangle(*drawRect
);
2010 // -----------------------------------------------------------------------
2012 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
2013 const wxRect
* drawRect
,
2014 bool isBuffered
) const
2016 const wxPGProperty
* firstItem
;
2017 const wxPGProperty
* lastItem
;
2019 firstItem
= DoGetItemAtY(drawRect
->y
);
2020 lastItem
= DoGetItemAtY(drawRect
->y
+drawRect
->height
-1);
2023 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
2025 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
2028 wxCHECK_MSG( !m_pState
->m_itemsAdded
, drawRect
->y
,
2030 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2032 int lh
= m_lineHeight
;
2035 int lastItemBottomY
;
2037 firstItemTopY
= drawRect
->y
;
2038 lastItemBottomY
= drawRect
->y
+ drawRect
->height
;
2040 // Align y coordinates to item boundaries
2041 firstItemTopY
-= firstItemTopY
% lh
;
2042 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2043 lastItemBottomY
-= 1;
2045 // Entire range outside scrolled, visible area?
2046 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
2047 lastItemBottomY
<= 0 )
2050 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
2052 "invalid y values" );
2055 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
2056 "height=%i (ch=%i), drawRect = 0x%lX )",
2057 firstItem->GetLabel().c_str(),
2058 lastItem->GetLabel().c_str(),
2059 (int)(lastItemBottomY - firstItemTopY),
2061 (unsigned long)drawRect );
2066 long windowStyle
= m_windowStyle
;
2071 // With wxPG_DOUBLE_BUFFER, do double buffering
2072 // - buffer's y = 0, so align drawRect and coordinates to that
2074 #if wxPG_DOUBLE_BUFFER
2081 xRelMod
= drawRect
->x
;
2082 yRelMod
= drawRect
->y
;
2085 // drawRect conversion
2090 firstItemTopY
-= yRelMod
;
2091 lastItemBottomY
-= yRelMod
;
2094 wxUnusedVar(isBuffered
);
2097 int x
= m_marginWidth
- xRelMod
;
2099 wxFont normalFont
= GetFont();
2101 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2103 bool isPgEnabled
= IsEnabled();
2106 // Prepare some pens and brushes that are often changed to.
2109 wxBrush
marginBrush(m_colMargin
);
2110 wxPen
marginPen(m_colMargin
);
2111 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2112 wxPen
linepen(m_colLine
,1,wxSOLID
);
2114 wxColour selBackCol
;
2116 selBackCol
= m_colSelBack
;
2118 selBackCol
= m_colMargin
;
2120 // pen that has same colour as text
2121 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2124 // Clear margin with background colour
2126 dc
.SetBrush( marginBrush
);
2127 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2129 dc
.SetPen( *wxTRANSPARENT_PEN
);
2130 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2133 const wxPGProperty
* firstSelected
= GetSelection();
2134 const wxPropertyGridPageState
* state
= m_pState
;
2135 const wxArrayInt
& colWidths
= state
->m_colWidths
;
2137 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2138 bool wasSelectedPainted
= false;
2141 // TODO: Only render columns that are within clipping region.
2143 dc
.SetFont(normalFont
);
2145 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2146 int endScanBottomY
= lastItemBottomY
+ lh
;
2147 int y
= firstItemTopY
;
2150 // Pregenerate list of visible properties.
2151 wxArrayPGProperty visPropArray
;
2152 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2154 for ( ; !it
.AtEnd(); it
.Next() )
2156 const wxPGProperty
* p
= *it
;
2158 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2160 visPropArray
.push_back((wxPGProperty
*)p
);
2162 if ( y
> endScanBottomY
)
2169 visPropArray
.push_back(NULL
);
2171 wxPGProperty
* nextP
= visPropArray
[0];
2173 int gridWidth
= state
->m_width
;
2176 for ( unsigned int arrInd
=1;
2177 nextP
&& y
<= lastItemBottomY
;
2180 wxPGProperty
* p
= nextP
;
2181 nextP
= visPropArray
[arrInd
];
2183 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2184 int textMarginHere
= x
;
2185 int renderFlags
= 0;
2187 int greyDepth
= m_marginWidth
;
2188 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2189 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2191 int greyDepthX
= greyDepth
- xRelMod
;
2193 // Use basic depth if in non-categoric mode and parent is base array.
2194 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2196 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2199 // Paint margin area
2200 dc
.SetBrush(marginBrush
);
2201 dc
.SetPen(marginPen
);
2202 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2204 dc
.SetPen( linepen
);
2210 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2211 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2212 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2214 // Is this or its parent themed?
2215 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2216 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2217 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2219 bool suppressMarginEdge
= false;
2221 if (!suppressMarginEdge
)
2222 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2225 // Blank out the margin edge
2226 dc
.SetPen(wxPen(GetBackgroundColour()));
2227 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2228 dc
.SetPen( linepen
);
2235 for ( si
=0; si
<colWidths
.size(); si
++ )
2237 sx
+= colWidths
[si
];
2238 dc
.DrawLine( sx
, y
, sx
, y2
);
2241 // Horizontal Line, below
2242 // (not if both this and next is category caption)
2243 if ( p
->IsCategory() &&
2244 nextP
&& nextP
->IsCategory() )
2245 dc
.SetPen(m_colCapBack
);
2247 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2250 // Need to override row colours?
2254 bool isSelected
= state
->DoIsPropertySelected(p
);
2258 // Disabled may get different colour.
2259 if ( !p
->IsEnabled() )
2261 renderFlags
|= wxPGCellRenderer::Disabled
|
2262 wxPGCellRenderer::DontUseCellFgCol
;
2263 rowFgCol
= m_colDisPropFore
;
2268 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2269 if ( p
== firstSelected
)
2270 wasSelectedPainted
= true;
2273 renderFlags
|= wxPGCellRenderer::Selected
;
2275 if ( !p
->IsCategory() )
2277 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2278 wxPGCellRenderer::DontUseCellBgCol
;
2280 if ( reallyFocused
&& p
== firstSelected
)
2282 rowFgCol
= m_colSelFore
;
2283 rowBgCol
= selBackCol
;
2285 else if ( isPgEnabled
)
2287 rowFgCol
= m_colPropFore
;
2288 if ( p
== firstSelected
)
2289 rowBgCol
= m_colMargin
;
2291 rowBgCol
= selBackCol
;
2295 rowFgCol
= m_colDisPropFore
;
2296 rowBgCol
= selBackCol
;
2303 if ( rowBgCol
.IsOk() )
2304 rowBgBrush
= wxBrush(rowBgCol
);
2306 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2307 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2310 // Fill additional margin area with background colour of first cell
2311 if ( greyDepthX
< textMarginHere
)
2313 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2315 wxPGCell
& cell
= p
->GetCell(0);
2316 rowBgCol
= cell
.GetBgCol();
2317 rowBgBrush
= wxBrush(rowBgCol
);
2319 dc
.SetBrush(rowBgBrush
);
2320 dc
.SetPen(rowBgCol
);
2321 dc
.DrawRectangle(greyDepthX
+1, y
,
2322 textMarginHere
-greyDepthX
, lh
-1);
2325 bool fontChanged
= false;
2327 // Expander button rectangle
2328 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2333 // Default cell rect fill the entire row
2334 wxRect
cellRect(greyDepthX
, y
,
2335 gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2337 bool isCategory
= p
->IsCategory();
2341 dc
.SetFont(m_captionFont
);
2344 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2346 dc
.SetBrush(rowBgBrush
);
2347 dc
.SetPen(rowBgCol
);
2350 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2352 dc
.SetTextForeground(rowFgCol
);
2357 // Fine tune button rectangle to actually fit the cell
2358 if ( butRect
.x
> 0 )
2359 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2361 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&&
2362 (windowStyle
& wxPG_BOLD_MODIFIED
) )
2364 dc
.SetFont(m_captionFont
);
2368 // Magic fine-tuning for non-category rows
2372 int firstCellWidth
= colWidths
[0] - (greyDepthX
- m_marginWidth
);
2373 int firstCellX
= cellRect
.x
;
2375 // Calculate cellRect.x for the last cell
2376 unsigned int ci
= 0;
2378 for ( ci
=0; ci
<colWidths
.size(); ci
++ )
2379 cellX
+= colWidths
[ci
];
2382 // Draw cells from back to front so that we can easily tell if the
2383 // cell on the right was empty from text
2384 bool prevFilled
= true;
2385 ci
= colWidths
.size();
2394 textXAdd
= textMarginHere
- greyDepthX
;
2395 cellRect
.width
= firstCellWidth
;
2396 cellRect
.x
= firstCellX
;
2400 int colWidth
= colWidths
[ci
];
2401 cellRect
.width
= colWidth
;
2402 cellRect
.x
-= colWidth
;
2405 // Merge with column to the right?
2406 if ( !prevFilled
&& isCategory
)
2408 cellRect
.width
+= colWidths
[ci
+1];
2412 cellRect
.width
-= 1;
2414 wxWindow
* cellEditor
= NULL
;
2415 int cellRenderFlags
= renderFlags
;
2417 // Tree Item Button (must be drawn before clipping is set up)
2418 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2419 DrawExpanderButton( dc
, butRect
, p
);
2422 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2424 if ( p
== firstSelected
)
2426 if ( ci
== 1 && m_wndEditor
)
2427 cellEditor
= m_wndEditor
;
2428 else if ( ci
== m_selColumn
&& m_labelEditor
)
2429 cellEditor
= m_labelEditor
;
2434 wxColour editorBgCol
=
2435 cellEditor
->GetBackgroundColour();
2436 dc
.SetBrush(editorBgCol
);
2437 dc
.SetPen(editorBgCol
);
2438 dc
.SetTextForeground(m_colPropFore
);
2439 dc
.DrawRectangle(cellRect
);
2441 if ( m_dragStatus
!= 0 ||
2442 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2447 dc
.SetBrush(m_colPropBack
);
2448 dc
.SetPen(m_colPropBack
);
2449 if ( p
->IsEnabled() )
2450 dc
.SetTextForeground(m_colPropFore
);
2452 dc
.SetTextForeground(m_colDisPropFore
);
2457 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2459 dc
.SetBrush(rowBgBrush
);
2460 dc
.SetPen(rowBgCol
);
2463 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2465 dc
.SetTextForeground(rowFgCol
);
2469 dc
.SetClippingRegion(cellRect
);
2471 cellRect
.x
+= textXAdd
;
2472 cellRect
.width
-= textXAdd
;
2477 wxPGCellRenderer
* renderer
;
2478 int cmnVal
= p
->GetCommonValue();
2479 if ( cmnVal
== -1 || ci
!= 1 )
2481 renderer
= p
->GetCellRenderer(ci
);
2482 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2488 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2489 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2499 dc
.DestroyClippingRegion(); // Is this really necessary?
2504 dc
.SetFont(normalFont
);
2509 // Refresh editor controls (seems not needed on msw)
2510 // NOTE: This code is mandatory for GTK!
2511 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2512 if ( wasSelectedPainted
)
2515 m_wndEditor
->Refresh();
2517 m_wndEditor2
->Refresh();
2524 // -----------------------------------------------------------------------
2526 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2530 if ( m_width
< 10 || m_height
< 10 ||
2531 !m_pState
->m_properties
->GetChildCount() ||
2533 return wxRect(0,0,0,0);
2538 // Return rect which encloses the given property range
2539 // (in logical grid coordinates)
2542 int visTop
= p1
->GetY();
2545 visBottom
= p2
->GetY() + m_lineHeight
;
2547 visBottom
= m_height
+ visTop
;
2549 // If seleced property is inside the range, we'll extend the range to include
2551 wxPGProperty
* selected
= GetSelection();
2554 int selectedY
= selected
->GetY();
2555 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2557 wxWindow
* editor
= GetEditorControl();
2560 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2561 if ( visBottom2
> visBottom
)
2562 visBottom
= visBottom2
;
2567 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2570 // -----------------------------------------------------------------------
2572 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2577 if ( m_pState
->m_itemsAdded
)
2578 PrepareAfterItemsAdded();
2580 wxRect r
= GetPropertyRect(p1
, p2
);
2583 // Convert rectangle from logical grid coordinates to physical ones
2585 GetViewStart(&vx
, &vy
);
2586 vx
*= wxPG_PIXELS_PER_UNIT
;
2587 vy
*= wxPG_PIXELS_PER_UNIT
;
2594 // -----------------------------------------------------------------------
2596 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2598 if ( m_pState
->DoIsPropertySelected(p
) )
2600 // NB: We must copy the selection.
2601 wxArrayPGProperty selection
= m_pState
->m_selection
;
2602 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2605 DrawItemAndChildren(p
);
2608 // -----------------------------------------------------------------------
2610 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2615 // Draw item, children, and parent too, if it is not category
2616 wxPGProperty
* parent
= p
->GetParent();
2619 !parent
->IsCategory() &&
2620 parent
->GetParent() )
2623 parent
= parent
->GetParent();
2626 DrawItemAndChildren(p
);
2629 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2631 wxCHECK_RET( p
, wxT("invalid property id") );
2633 // Do not draw if in non-visible page
2634 if ( p
->GetParentState() != m_pState
)
2637 // do not draw a single item if multiple pending
2638 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2641 // Update child control.
2642 wxPGProperty
* selected
= GetSelection();
2643 if ( selected
&& selected
->GetParent() == p
)
2646 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2648 DrawItems(p
, lastDrawn
);
2651 // -----------------------------------------------------------------------
2653 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2654 const wxRect
*rect
)
2656 PrepareAfterItemsAdded();
2658 wxWindow::Refresh(false, rect
);
2660 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2661 // I think this really helps only GTK+1.2
2662 if ( m_wndEditor
) m_wndEditor
->Refresh();
2663 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2667 // -----------------------------------------------------------------------
2668 // wxPropertyGrid global operations
2669 // -----------------------------------------------------------------------
2671 void wxPropertyGrid::Clear()
2673 m_pState
->DoClear();
2679 RecalculateVirtualSize();
2681 // Need to clear some area at the end
2683 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2686 // -----------------------------------------------------------------------
2688 bool wxPropertyGrid::EnableCategories( bool enable
)
2695 // Enable categories
2698 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2703 // Disable categories
2705 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2708 if ( !m_pState
->EnableCategories(enable
) )
2713 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2715 m_pState
->m_itemsAdded
= 1; // force
2716 PrepareAfterItemsAdded();
2720 m_pState
->m_itemsAdded
= 1;
2722 // No need for RecalculateVirtualSize() here - it is already called in
2723 // wxPropertyGridPageState method above.
2730 // -----------------------------------------------------------------------
2732 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2734 wxASSERT( pNewState
);
2735 wxASSERT( pNewState
->GetGrid() );
2737 if ( pNewState
== m_pState
)
2740 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2742 // Call ClearSelection() instead of DoClearSelection()
2743 // so that selection clear events are not sent.
2746 m_pState
->m_selection
= oldSelection
;
2748 bool orig_mode
= m_pState
->IsInNonCatMode();
2749 bool new_state_mode
= pNewState
->IsInNonCatMode();
2751 m_pState
= pNewState
;
2754 int pgWidth
= GetClientSize().x
;
2755 if ( HasVirtualWidth() )
2757 int minWidth
= pgWidth
;
2758 if ( pNewState
->m_width
< minWidth
)
2760 pNewState
->m_width
= minWidth
;
2761 pNewState
->CheckColumnWidths();
2767 // Just in case, fully re-center splitter
2768 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2769 // pNewState->m_fSplitterX = -1.0;
2771 pNewState
->OnClientWidthChange(pgWidth
,
2772 pgWidth
- pNewState
->m_width
);
2777 // If necessary, convert state to correct mode.
2778 if ( orig_mode
!= new_state_mode
)
2780 // This should refresh as well.
2781 EnableCategories( orig_mode
?false:true );
2783 else if ( !m_frozen
)
2785 // Refresh, if not frozen.
2786 m_pState
->PrepareAfterItemsAdded();
2788 // Reselect (Use SetSelection() instead of Do-variant so that
2789 // events won't be sent).
2790 SetSelection(m_pState
->m_selection
);
2792 RecalculateVirtualSize(0);
2796 m_pState
->m_itemsAdded
= 1;
2799 // -----------------------------------------------------------------------
2801 // Call to SetSplitterPosition will always disable splitter auto-centering
2802 // if parent window is shown.
2803 void wxPropertyGrid::DoSetSplitterPosition( int newxpos
,
2807 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2810 wxPropertyGridPageState
* state
= m_pState
;
2812 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2813 state
->m_dontCenterSplitter
= true;
2815 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2817 if ( flags
& wxPG_SPLITTER_REFRESH
)
2819 if ( GetSelection() )
2820 CorrectEditorWidgetSizeX();
2828 // -----------------------------------------------------------------------
2830 void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing
)
2832 wxPropertyGridPageState
* state
= m_pState
;
2834 state
->ResetColumnSizes(0);
2836 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2837 m_pState
->m_dontCenterSplitter
= false;
2840 // -----------------------------------------------------------------------
2842 void wxPropertyGrid::CenterSplitter( bool enableAutoResizing
)
2844 SetSplitterPosition( m_width
/2 );
2845 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2846 m_pState
->m_dontCenterSplitter
= false;
2849 // -----------------------------------------------------------------------
2850 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2851 // -----------------------------------------------------------------------
2853 // Returns nearest paint visible property (such that will be painted unless
2854 // window is scrolled or resized). If given property is paint visible, then
2855 // it itself will be returned
2856 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2858 int vx
,vy1
;// Top left corner of client
2859 GetViewStart(&vx
,&vy1
);
2860 vy1
*= wxPG_PIXELS_PER_UNIT
;
2862 int vy2
= vy1
+ m_height
;
2863 int propY
= p
->GetY2(m_lineHeight
);
2865 if ( (propY
+ m_lineHeight
) < vy1
)
2868 return DoGetItemAtY( vy1
);
2870 else if ( propY
> vy2
)
2873 return DoGetItemAtY( vy2
);
2876 // Itself paint visible
2881 // -----------------------------------------------------------------------
2882 // Methods related to change in value, value modification and sending events
2883 // -----------------------------------------------------------------------
2885 // commits any changes in editor of selected property
2886 // return true if validation did not fail
2887 // flags are same as with DoSelectProperty
2888 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2890 // Committing already?
2891 if ( m_inCommitChangesFromEditor
)
2894 // Don't do this if already processing editor event. It might
2895 // induce recursive dialogs and crap like that.
2896 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2898 if ( m_inDoPropertyChanged
)
2904 wxPGProperty
* selected
= GetSelection();
2907 IsEditorsValueModified() &&
2908 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2911 m_inCommitChangesFromEditor
= 1;
2913 wxVariant
variant(selected
->GetValueRef());
2914 bool valueIsPending
= false;
2916 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2917 // due to another window getting focus
2918 wxWindow
* oldFocus
= m_curFocused
;
2920 bool validationFailure
= false;
2921 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2923 m_chgInfo_changedProperty
= NULL
;
2925 // If truly modified, schedule value as pending.
2926 if ( selected
->GetEditorClass()->
2927 GetValueFromControl( variant
,
2929 GetEditorControl() ) )
2931 if ( DoEditorValidate() &&
2932 PerformValidation(selected
, variant
) )
2934 valueIsPending
= true;
2938 validationFailure
= true;
2943 EditorsValueWasNotModified();
2948 m_inCommitChangesFromEditor
= 0;
2950 if ( validationFailure
&& !forceSuccess
)
2954 oldFocus
->SetFocus();
2955 m_curFocused
= oldFocus
;
2958 res
= OnValidationFailure(selected
, variant
);
2960 // Now prevent further validation failure messages
2963 EditorsValueWasNotModified();
2964 OnValidationFailureReset(selected
);
2967 else if ( valueIsPending
)
2969 DoPropertyChanged( selected
, flags
);
2970 EditorsValueWasNotModified();
2979 // -----------------------------------------------------------------------
2981 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2985 // Runs all validation functionality.
2986 // Returns true if value passes all tests.
2989 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2990 m_validationInfo
.m_isFailing
= true;
2993 // Variant list a special value that cannot be validated
2995 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2997 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
3002 // Adapt list to child values, if necessary
3003 wxVariant listValue
= pendingValue
;
3004 wxVariant
* pPendingValue
= &pendingValue
;
3005 wxVariant
* pList
= NULL
;
3007 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
3008 // string value, then we need treat as it was changed instead
3009 // (or, in addition, as is the case with composite string parent).
3010 // This includes creating list variant for child values.
3012 wxPGProperty
* pwc
= p
->GetParent();
3013 wxPGProperty
* changedProperty
= p
;
3014 wxPGProperty
* baseChangedProperty
= changedProperty
;
3015 wxVariant bcpPendingList
;
3017 listValue
= pendingValue
;
3018 listValue
.SetName(p
->GetBaseName());
3021 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
3023 wxVariantList tempList
;
3024 wxVariant
lv(tempList
, pwc
->GetBaseName());
3025 lv
.Append(listValue
);
3027 pPendingValue
= &listValue
;
3029 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
3031 baseChangedProperty
= pwc
;
3032 bcpPendingList
= lv
;
3035 changedProperty
= pwc
;
3036 pwc
= pwc
->GetParent();
3040 wxPGProperty
* evtChangingProperty
= changedProperty
;
3042 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
3044 value
= *pPendingValue
;
3048 // Convert list to child values
3049 pList
= pPendingValue
;
3050 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
3053 wxVariant evtChangingValue
= value
;
3055 if ( flags
& SendEvtChanging
)
3057 // FIXME: After proper ValueToString()s added, remove
3058 // this. It is just a temporary fix, as evt_changing
3059 // will simply not work for wxPG_PROP_COMPOSED_VALUE
3060 // (unless it is selected, and textctrl editor is open).
3061 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3063 evtChangingProperty
= baseChangedProperty
;
3064 if ( evtChangingProperty
!= p
)
3066 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
3070 evtChangingValue
= pendingValue
;
3074 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3076 if ( changedProperty
== GetSelection() )
3078 wxWindow
* editor
= GetEditorControl();
3079 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
3080 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
3084 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
3089 wxASSERT( m_chgInfo_changedProperty
== NULL
);
3090 m_chgInfo_changedProperty
= changedProperty
;
3091 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
3092 m_chgInfo_pendingValue
= value
;
3095 m_chgInfo_valueList
= *pList
;
3097 m_chgInfo_valueList
.MakeNull();
3099 // If changedProperty is not property which value was edited,
3100 // then call wxPGProperty::ValidateValue() for that as well.
3101 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3103 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3107 if ( flags
& SendEvtChanging
)
3109 // SendEvent returns true if event was vetoed
3110 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3111 &evtChangingValue
) )
3115 if ( flags
& IsStandaloneValidation
)
3117 // If called in 'generic' context, we need to reset
3118 // m_chgInfo_changedProperty and write back translated value.
3119 m_chgInfo_changedProperty
= NULL
;
3120 pendingValue
= value
;
3123 m_validationInfo
.m_isFailing
= false;
3128 // -----------------------------------------------------------------------
3131 wxStatusBar
* wxPropertyGrid::GetStatusBar()
3133 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3134 if ( topWnd
&& topWnd
->IsKindOf(CLASSINFO(wxFrame
)) )
3136 wxFrame
* pFrame
= wxStaticCast(topWnd
, wxFrame
);
3138 return pFrame
->GetStatusBar();
3144 // -----------------------------------------------------------------------
3146 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3148 if ( !msg
.length() )
3152 if ( !wxPGGlobalVars
->m_offline
)
3154 wxStatusBar
* pStatusBar
= GetStatusBar();
3157 pStatusBar
->SetStatusText(msg
);
3163 ::wxMessageBox(msg
, wxT("Property Error"));
3166 // -----------------------------------------------------------------------
3168 void wxPropertyGrid::DoHidePropertyError( wxPGProperty
* WXUNUSED(property
) )
3171 if ( !wxPGGlobalVars
->m_offline
)
3173 wxStatusBar
* pStatusBar
= GetStatusBar();
3176 pStatusBar
->SetStatusText(wxEmptyString
);
3183 // -----------------------------------------------------------------------
3185 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3186 wxVariant
& invalidValue
)
3188 wxWindow
* editor
= GetEditorControl();
3190 // First call property's handler
3191 property
->OnValidationFailure(invalidValue
);
3193 bool res
= DoOnValidationFailure(property
, invalidValue
);
3196 // For non-wxTextCtrl editors, we do need to revert the value
3197 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3198 property
== GetSelection() )
3200 property
->GetEditorClass()->UpdateControl(property
, editor
);
3203 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3208 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3210 int vfb
= m_validationInfo
.m_failureBehavior
;
3212 if ( vfb
& wxPG_VFB_BEEP
)
3215 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3216 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3218 unsigned int colCount
= m_pState
->GetColumnCount();
3220 // We need backup marked property's cells
3221 m_propCellsBackup
= property
->m_cells
;
3223 wxColour vfbFg
= *wxWHITE
;
3224 wxColour vfbBg
= *wxRED
;
3226 property
->EnsureCells(colCount
);
3228 for ( unsigned int i
=0; i
<colCount
; i
++ )
3230 wxPGCell
& cell
= property
->m_cells
[i
];
3231 cell
.SetFgCol(vfbFg
);
3232 cell
.SetBgCol(vfbBg
);
3235 DrawItemAndChildren(property
);
3237 if ( property
== GetSelection() )
3239 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3241 wxWindow
* editor
= GetEditorControl();
3244 editor
->SetForegroundColour(vfbFg
);
3245 editor
->SetBackgroundColour(vfbBg
);
3250 if ( vfb
& (wxPG_VFB_SHOW_MESSAGE
|
3251 wxPG_VFB_SHOW_MESSAGEBOX
|
3252 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
) )
3254 wxString msg
= m_validationInfo
.m_failureMessage
;
3256 if ( !msg
.length() )
3257 msg
= _("You have entered invalid value. Press ESC to cancel editing.");
3260 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3262 if ( !wxPGGlobalVars
->m_offline
)
3264 wxStatusBar
* pStatusBar
= GetStatusBar();
3266 pStatusBar
->SetStatusText(msg
);
3271 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3272 DoShowPropertyError(property
, msg
);
3274 if ( vfb
& wxPG_VFB_SHOW_MESSAGEBOX
)
3275 ::wxMessageBox(msg
, _("Property Error"));
3278 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3281 // -----------------------------------------------------------------------
3283 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3285 int vfb
= m_validationInfo
.m_failureBehavior
;
3287 if ( vfb
& wxPG_VFB_MARK_CELL
)
3290 property
->m_cells
= m_propCellsBackup
;
3292 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3294 if ( property
== GetSelection() && GetEditorControl() )
3296 // Calling this will recreate the control, thus resetting its colour
3297 RefreshProperty(property
);
3301 DrawItemAndChildren(property
);
3306 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3308 if ( !wxPGGlobalVars
->m_offline
)
3310 wxStatusBar
* pStatusBar
= GetStatusBar();
3312 pStatusBar
->SetStatusText(wxEmptyString
);
3317 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3319 DoHidePropertyError(property
);
3322 m_validationInfo
.m_isFailing
= false;
3325 // -----------------------------------------------------------------------
3327 // flags are same as with DoSelectProperty
3328 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3330 if ( m_inDoPropertyChanged
)
3333 wxPGProperty
* selected
= GetSelection();
3335 m_pState
->m_anyModified
= 1;
3337 m_inDoPropertyChanged
= 1;
3339 // If property's value is being changed, assume it is valid
3340 OnValidationFailureReset(selected
);
3342 // Maybe need to update control
3343 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3345 // These values were calculated in PerformValidation()
3346 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3347 wxVariant value
= m_chgInfo_pendingValue
;
3349 wxPGProperty
* topPaintedProperty
= changedProperty
;
3351 while ( !topPaintedProperty
->IsCategory() &&
3352 !topPaintedProperty
->IsRoot() )
3354 topPaintedProperty
= topPaintedProperty
->GetParent();
3357 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3359 // NB: Call GetEditorControl() as late as possible, because OnSetValue()
3360 // and perhaps other user-defined virtual functions may change it.
3361 wxWindow
* editor
= GetEditorControl();
3363 // Set as Modified (not if dragging just began)
3364 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3366 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3367 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3370 SetCurControlBoldFont();
3376 // Propagate updates to parent(s)
3378 wxPGProperty
* prevPwc
= NULL
;
3380 while ( prevPwc
!= topPaintedProperty
)
3382 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3384 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3387 SetCurControlBoldFont();
3391 pwc
= pwc
->GetParent();
3394 // Draw the actual property
3395 DrawItemAndChildren( topPaintedProperty
);
3398 // If value was set by wxPGProperty::OnEvent, then update the editor
3400 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3406 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3407 if ( m_wndEditor
) m_wndEditor
->Refresh();
3408 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3413 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3415 // If top parent has composite string value, then send to child parents,
3416 // starting from baseChangedProperty.
3417 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3419 pwc
= m_chgInfo_baseChangedProperty
;
3421 while ( pwc
!= changedProperty
)
3423 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3424 pwc
= pwc
->GetParent();
3428 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3430 m_inDoPropertyChanged
= 0;
3435 // -----------------------------------------------------------------------
3437 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3439 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3441 m_chgInfo_changedProperty
= NULL
;
3443 if ( PerformValidation(p
, newValue
) )
3445 DoPropertyChanged(p
);
3450 OnValidationFailure(p
, newValue
);
3456 // -----------------------------------------------------------------------
3458 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3460 wxPGProperty
* prop
= GetSelectedProperty();
3463 return wxNullVariant
;
3465 wxTextCtrl
* tc
= GetEditorTextCtrl();
3466 wxVariant value
= prop
->GetValue();
3468 if ( !tc
|| !IsEditorsValueModified() )
3471 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3474 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3475 return prop
->GetValue();
3480 // -----------------------------------------------------------------------
3482 // Runs wxValidator for the selected property
3483 bool wxPropertyGrid::DoEditorValidate()
3485 #if wxUSE_VALIDATORS
3486 wxRecursionGuard
guard(m_validatingEditor
);
3487 if ( guard
.IsInside() )
3490 wxPGProperty
* selected
= GetSelection();
3493 wxWindow
* wnd
= GetEditorControl();
3495 wxValidator
* validator
= selected
->GetValidator();
3496 if ( validator
&& wnd
)
3498 validator
->SetWindow(wnd
);
3499 if ( !validator
->Validate(this) )
3507 // -----------------------------------------------------------------------
3509 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3511 // It is possible that this handler receives event even before
3512 // the control has been properly initialized. Let's skip the
3513 // event handling in that case.
3517 // Don't care about the event if it originated from the
3518 // 'label editor'. In this function we only care about the
3519 // property value editor.
3520 if ( m_labelEditor
&& event
.GetId() == m_labelEditor
->GetId() )
3526 wxPGProperty
* selected
= GetSelection();
3528 // Somehow, event is handled after property has been deselected.
3529 // Possibly, but very rare.
3531 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3532 // Also don't handle editor event if wxEVT_PG_CHANGED or
3533 // similar is currently doing something (showing a
3534 // message box, for instance).
3538 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3541 wxVariant
pendingValue(selected
->GetValueRef());
3542 wxWindow
* wnd
= GetEditorControl();
3543 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3545 bool wasUnspecified
= selected
->IsValueUnspecified();
3546 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3547 bool valueIsPending
= false;
3549 m_chgInfo_changedProperty
= NULL
;
3551 m_iFlags
&= ~wxPG_FL_VALUE_CHANGE_IN_EVENT
;
3554 // Filter out excess wxTextCtrl modified events
3555 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&& wnd
)
3557 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3559 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3561 wxString newTcValue
= tc
->GetValue();
3562 if ( m_prevTcValue
== newTcValue
)
3564 m_prevTcValue
= newTcValue
;
3566 else if ( wnd
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
3568 wxComboCtrl
* cc
= (wxComboCtrl
*) wnd
;
3570 wxString newTcValue
= cc
->GetTextCtrl()->GetValue();
3571 if ( m_prevTcValue
== newTcValue
)
3573 m_prevTcValue
= newTcValue
;
3577 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3579 bool validationFailure
= false;
3580 bool buttonWasHandled
= false;
3583 // Try common button handling
3584 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3586 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3590 buttonWasHandled
= true;
3591 // Store as res2, as previously (and still currently alternatively)
3592 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3593 // in wxPGProperty::OnEvent().
3594 adapter
->ShowDialog( this, selected
);
3599 if ( !buttonWasHandled
)
3601 if ( wnd
|| m_wndEditor2
)
3603 // First call editor class' event handler.
3604 const wxPGEditor
* editor
= selected
->GetEditorClass();
3606 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3608 // If changes, validate them
3609 if ( DoEditorValidate() )
3611 if ( editor
->GetValueFromControl( pendingValue
,
3614 valueIsPending
= true;
3616 // Mark value always as pending if validation is currently
3617 // failing and value was not unspecified
3618 if ( !valueIsPending
&&
3619 !pendingValue
.IsNull() &&
3620 m_validationInfo
.m_isFailing
)
3621 valueIsPending
= true;
3625 validationFailure
= true;
3630 // Then the property's custom handler (must be always called, unless
3631 // validation failed).
3632 if ( !validationFailure
)
3633 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3636 // SetValueInEvent(), as called in one of the functions referred above
3637 // overrides editor's value.
3638 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3640 valueIsPending
= true;
3641 pendingValue
= m_changeInEventValue
;
3642 selFlags
|= wxPG_SEL_DIALOGVAL
;
3645 if ( !validationFailure
&& valueIsPending
)
3646 if ( !PerformValidation(selected
, pendingValue
) )
3647 validationFailure
= true;
3649 if ( validationFailure
)
3651 OnValidationFailure(selected
, pendingValue
);
3653 else if ( valueIsPending
)
3655 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3657 DoPropertyChanged(selected
, selFlags
);
3658 EditorsValueWasNotModified();
3660 // Regardless of editor type, unfocus editor on
3661 // text-editing related enter press.
3662 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3669 // No value after all
3671 // Regardless of editor type, unfocus editor on
3672 // text-editing related enter press.
3673 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3678 // Let unhandled button click events go to the parent
3679 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3681 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3682 GetEventHandler()->AddPendingEvent(evt
);
3686 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3689 // -----------------------------------------------------------------------
3690 // wxPropertyGrid editor control helper methods
3691 // -----------------------------------------------------------------------
3693 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3695 int itemy
= p
->GetY2(m_lineHeight
);
3696 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3697 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3698 int imageOffset
= 0;
3700 int vx
, vy
; // Top left corner of client
3701 GetViewStart(&vx
, &vy
);
3702 vy
*= wxPG_PIXELS_PER_UNIT
;
3706 // TODO: If custom image detection changes from current, change this.
3707 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3709 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3710 int iw
= p
->OnMeasureImage().x
;
3712 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3713 imageOffset
= p
->GetImageOffset(iw
);
3716 else if ( column
== 0 )
3718 splitterX
+= (p
->m_depth
- 1) * m_subgroup_extramargin
;
3723 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3725 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3730 // -----------------------------------------------------------------------
3732 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3734 wxSize sz
= GetImageSize(p
, item
);
3735 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3736 wxPG_CUSTOM_IMAGE_SPACINGY
,
3741 // return size of custom paint image
3742 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3744 // If called with NULL property, then return default image
3745 // size for properties that use image.
3747 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3749 wxSize cis
= p
->OnMeasureImage(item
);
3751 int choiceCount
= p
->m_choices
.GetCount();
3752 int comVals
= p
->GetDisplayedCommonValueCount();
3753 if ( item
>= choiceCount
&& comVals
> 0 )
3755 unsigned int cvi
= item
-choiceCount
;
3756 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3758 else if ( item
>= 0 && choiceCount
== 0 )
3759 return wxSize(0, 0);
3764 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3769 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3776 // -----------------------------------------------------------------------
3778 // takes scrolling into account
3779 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3782 GetViewStart(&vx
,&vy
);
3783 vy
*=wxPG_PIXELS_PER_UNIT
;
3784 vx
*=wxPG_PIXELS_PER_UNIT
;
3787 ClientToScreen( px
, py
);
3790 // -----------------------------------------------------------------------
3792 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3795 GetViewStart(&pt2
.x
,&pt2
.y
);
3796 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3797 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3801 return m_pState
->HitTest(pt2
);
3804 // -----------------------------------------------------------------------
3806 // custom set cursor
3807 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3809 if ( type
== m_curcursor
&& !override
) return;
3811 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3813 if ( type
== wxCURSOR_SIZEWE
)
3814 cursor
= m_cursorSizeWE
;
3816 SetCursor( *cursor
);
3821 // -----------------------------------------------------------------------
3824 wxPropertyGrid::GetUnspecifiedValueText( int argFlags
) const
3826 const wxPGCell
& ua
= GetUnspecifiedValueAppearance();
3828 if ( ua
.HasText() &&
3829 !(argFlags
& wxPG_FULL_VALUE
) &&
3830 !(argFlags
& wxPG_EDITABLE_VALUE
) )
3831 return ua
.GetText();
3833 return wxEmptyString
;
3836 // -----------------------------------------------------------------------
3837 // wxPropertyGrid property selection, editor creation
3838 // -----------------------------------------------------------------------
3841 // This class forwards events from property editor controls to wxPropertyGrid.
3842 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3845 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3846 : wxEvtHandler(), m_propGrid(propGrid
)
3850 virtual ~wxPropertyGridEditorEventForwarder()
3855 bool ProcessEvent( wxEvent
& event
)
3860 m_propGrid
->HandleCustomEditorEvent(event
);
3863 // NB: On wxMSW, a wxTextCtrl with wxTE_PROCESS_ENTER
3864 // may beep annoyingly if that event is skipped
3865 // and passed to parent event handler.
3866 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3869 return wxEvtHandler::ProcessEvent(event
);
3872 wxPropertyGrid
* m_propGrid
;
3875 // Setups event handling for child control
3876 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3878 wxWindowID id
= argWnd
->GetId();
3880 if ( argWnd
== m_wndEditor
)
3882 argWnd
->Connect(id
, wxEVT_MOTION
,
3883 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3885 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3886 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3888 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3889 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3891 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3892 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3894 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3895 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3897 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3898 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3902 wxPropertyGridEditorEventForwarder
* forwarder
;
3903 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3904 argWnd
->PushEventHandler(forwarder
);
3906 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3907 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3911 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3918 // Do not free editors immediately (for sake of processing events)
3919 wxPendingDelete
.Append(wnd
);
3922 void wxPropertyGrid::FreeEditors()
3925 // Return focus back to canvas from children (this is required at least for
3926 // GTK+, which, unlike Windows, clears focus when control is destroyed
3927 // instead of moving it to closest parent).
3928 wxWindow
* focus
= wxWindow::FindFocus();
3931 wxWindow
* parent
= focus
->GetParent();
3934 if ( parent
== this )
3939 parent
= parent
->GetParent();
3943 // Do not free editors immediately if processing events
3946 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3947 m_wndEditor2
->Hide();
3948 wxPendingDelete
.Append( handler
);
3949 DestroyEditorWnd(m_wndEditor2
);
3950 m_wndEditor2
= NULL
;
3955 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3956 m_wndEditor
->Hide();
3957 wxPendingDelete
.Append( handler
);
3958 DestroyEditorWnd(m_wndEditor
);
3963 // Call with NULL to de-select property
3964 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3969 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3970 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3974 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3978 if ( m_inDoSelectProperty
)
3981 m_inDoSelectProperty
= 1;
3985 m_inDoSelectProperty
= 0;
3989 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3990 wxPGProperty
* prevFirstSel
;
3992 if ( prevSelection
.size() > 0 )
3993 prevFirstSel
= prevSelection
[0];
3995 prevFirstSel
= NULL
;
3997 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3998 prevFirstSel
= NULL
;
4000 // Always send event, as this is indirect call
4001 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4005 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
4007 wxPrintf( "None selected\n" );
4010 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
4012 wxPrintf( "P = NULL\n" );
4015 // If we are frozen, then just set the values.
4018 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4019 m_editorFocused
= 0;
4020 m_pState
->DoSetSelection(p
);
4022 // If frozen, always free controls. But don't worry, as Thaw will
4023 // recall SelectProperty to recreate them.
4026 // Prevent any further selection measures in this call
4032 if ( prevFirstSel
== p
&&
4033 prevSelection
.size() <= 1 &&
4034 !(flags
& wxPG_SEL_FORCE
) )
4036 // Only set focus if not deselecting
4039 if ( flags
& wxPG_SEL_FOCUS
)
4043 m_wndEditor
->SetFocus();
4044 m_editorFocused
= 1;
4053 m_inDoSelectProperty
= 0;
4058 // First, deactivate previous
4061 OnValidationFailureReset(prevFirstSel
);
4063 // Must double-check if this is an selected in case of forceswitch
4064 if ( p
!= prevFirstSel
)
4066 if ( !CommitChangesFromEditor(flags
) )
4068 // Validation has failed, so we can't exit the previous editor
4069 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
4070 // _("Invalid Value"),wxOK|wxICON_ERROR);
4071 m_inDoSelectProperty
= 0;
4078 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4079 EditorsValueWasNotModified();
4082 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4084 m_pState
->DoSetSelection(p
);
4086 // Redraw unselected
4087 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
4089 DrawItem(prevSelection
[i
]);
4093 // Then, activate the one given.
4096 int propY
= p
->GetY2(m_lineHeight
);
4098 int splitterX
= GetSplitterPosition();
4099 m_editorFocused
= 0;
4100 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
4102 wxASSERT( m_wndEditor
== NULL
);
4105 // Only create editor for non-disabled non-caption
4106 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
4108 // do this for non-caption items
4112 // Do we need to paint the custom image, if any?
4113 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
4114 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
4115 !p
->GetEditorClass()->CanContainCustomImage()
4117 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
4119 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
4120 wxPoint goodPos
= grect
.GetPosition();
4122 // Editor appearance can now be considered clear
4123 m_editorAppearance
.SetEmptyData();
4125 const wxPGEditor
* editor
= p
->GetEditorClass();
4126 wxCHECK_MSG(editor
, false,
4127 wxT("NULL editor class not allowed"));
4129 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
4131 wxPGWindowList wndList
=
4132 editor
->CreateControls(this,
4137 m_wndEditor
= wndList
.m_primary
;
4138 m_wndEditor2
= wndList
.m_secondary
;
4139 wxWindow
* primaryCtrl
= GetEditorControl();
4142 // Essentially, primaryCtrl == m_wndEditor
4145 // NOTE: It is allowed for m_wndEditor to be NULL - in this
4146 // case value is drawn as normal, and m_wndEditor2 is
4147 // assumed to be a right-aligned button that triggers
4148 // a separate editorCtrl window.
4152 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
4153 "CreateControls must use result of "
4154 "wxPropertyGrid::GetPanel() as parent "
4157 // Set validator, if any
4158 #if wxUSE_VALIDATORS
4159 wxValidator
* validator
= p
->GetValidator();
4161 primaryCtrl
->SetValidator(*validator
);
4164 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
4165 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
4167 // If it has modified status, use bold font
4168 // (must be done before capturing m_ctrlXAdjust)
4169 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
4170 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
4171 SetCurControlBoldFont();
4173 // Store x relative to splitter (we'll need it).
4174 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
4176 // Check if background clear is not necessary
4177 wxPoint pos
= m_wndEditor
->GetPosition();
4178 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
4180 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
4183 m_wndEditor
->SetSizeHints(3, 3);
4185 SetupChildEventHandling(primaryCtrl
);
4187 // Focus and select all (wxTextCtrl, wxComboBox etc)
4188 if ( flags
& wxPG_SEL_FOCUS
)
4190 primaryCtrl
->SetFocus();
4192 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
4196 if ( p
->IsValueUnspecified() )
4197 SetEditorAppearance(m_unspecifiedAppearance
,
4204 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
4205 "CreateControls must use result of "
4206 "wxPropertyGrid::GetPanel() as parent "
4209 // Get proper id for wndSecondary
4210 m_wndSecId
= m_wndEditor2
->GetId();
4211 wxWindowList children
= m_wndEditor2
->GetChildren();
4212 wxWindowList::iterator node
= children
.begin();
4213 if ( node
!= children
.end() )
4214 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
4216 m_wndEditor2
->SetSizeHints(3,3);
4218 m_wndEditor2
->Show();
4220 SetupChildEventHandling(m_wndEditor2
);
4222 // If no primary editor, focus to button to allow
4223 // it to interprete ENTER etc.
4224 // NOTE: Due to problems focusing away from it, this
4225 // has been disabled.
4227 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
4228 m_wndEditor2->SetFocus();
4232 if ( flags
& wxPG_SEL_FOCUS
)
4233 m_editorFocused
= 1;
4238 // Make sure focus is in grid canvas (important for wxGTK,
4243 EditorsValueWasNotModified();
4245 // If it's inside collapsed section, expand parent, scroll, etc.
4246 // Also, if it was partially visible, scroll it into view.
4247 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
4252 m_wndEditor
->Show(true);
4255 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
4260 // Make sure focus is in grid canvas
4264 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4270 // Show help text in status bar.
4271 // (if found and grid not embedded in manager with help box and
4272 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4275 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4277 wxStatusBar
* statusbar
= GetStatusBar();
4280 const wxString
* pHelpString
= (const wxString
*) NULL
;
4284 pHelpString
= &p
->GetHelpString();
4285 if ( pHelpString
->length() )
4287 // Set help box text.
4288 statusbar
->SetStatusText( *pHelpString
);
4289 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4293 if ( (!pHelpString
|| !pHelpString
->length()) &&
4294 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
4296 // Clear help box - but only if it was written
4297 // by us at previous time.
4298 statusbar
->SetStatusText( m_emptyString
);
4299 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4305 m_inDoSelectProperty
= 0;
4307 // call wx event handler (here so that it also occurs on deselection)
4308 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4309 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4314 // -----------------------------------------------------------------------
4316 bool wxPropertyGrid::UnfocusEditor()
4318 wxPGProperty
* selected
= GetSelection();
4320 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4323 if ( !CommitChangesFromEditor(0) )
4332 // -----------------------------------------------------------------------
4334 void wxPropertyGrid::RefreshEditor()
4336 wxPGProperty
* p
= GetSelection();
4340 wxWindow
* wnd
= GetEditorControl();
4344 // Set editor font boldness - must do this before
4345 // calling UpdateControl().
4346 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4348 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4349 wnd
->SetFont(GetCaptionFont());
4351 wnd
->SetFont(GetFont());
4354 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4356 editorClass
->UpdateControl(p
, wnd
);
4358 if ( p
->IsValueUnspecified() )
4359 SetEditorAppearance(m_unspecifiedAppearance
, true);
4362 // -----------------------------------------------------------------------
4364 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4366 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4368 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4370 flags
|= wxPG_SEL_FOCUS
;
4372 return DoSelectProperty(p
, flags
);
4375 // -----------------------------------------------------------------------
4376 // wxPropertyGrid expand/collapse state
4377 // -----------------------------------------------------------------------
4379 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4381 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4382 wxPGProperty
* selected
= GetSelection();
4384 // If active editor was inside collapsed section, then disable it
4385 if ( selected
&& selected
->IsSomeParent(p
) )
4390 // Store dont-center-splitter flag 'cause we need to temporarily set it
4391 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4392 m_pState
->m_dontCenterSplitter
= true;
4394 bool res
= m_pState
->DoCollapse(pwc
);
4399 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4401 RecalculateVirtualSize();
4405 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4410 // -----------------------------------------------------------------------
4412 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4414 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4416 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4418 // Store dont-center-splitter flag 'cause we need to temporarily set it
4419 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4420 m_pState
->m_dontCenterSplitter
= true;
4422 bool res
= m_pState
->DoExpand(pwc
);
4427 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4429 RecalculateVirtualSize();
4433 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4438 // -----------------------------------------------------------------------
4440 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4443 return m_pState
->DoHideProperty(p
, hide
, flags
);
4445 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4446 int selRemoveCount
= 0;
4447 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4449 wxPGProperty
* selected
= selection
[i
];
4450 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4452 if ( !DoRemoveFromSelection(p
, flags
) )
4454 selRemoveCount
+= 1;
4458 m_pState
->DoHideProperty(p
, hide
, flags
);
4460 RecalculateVirtualSize();
4467 // -----------------------------------------------------------------------
4468 // wxPropertyGrid size related methods
4469 // -----------------------------------------------------------------------
4471 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4473 // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise
4474 // virtual size calculation may go wrong.
4475 if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4481 // If virtual height was changed, then recalculate editor control position(s)
4482 if ( m_pState
->m_vhCalcPending
)
4483 CorrectEditorWidgetPosY();
4485 m_pState
->EnsureVirtualHeight();
4487 wxASSERT_LEVEL_2_MSG(
4488 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4489 "VirtualHeight and ActualVirtualHeight should match"
4492 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4494 int x
= m_pState
->m_width
;
4495 int y
= m_pState
->m_virtualHeight
;
4498 GetClientSize(&width
,&height
);
4500 // Now adjust virtual size.
4501 SetVirtualSize(x
, y
);
4507 // Adjust scrollbars
4508 if ( HasVirtualWidth() )
4510 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4511 xPos
= GetScrollPos( wxHORIZONTAL
);
4514 if ( forceXPos
!= -1 )
4517 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4520 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4521 int yPos
= GetScrollPos( wxVERTICAL
);
4523 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4524 xAmount
, yAmount
, xPos
, yPos
, true );
4526 // Must re-get size now
4527 GetClientSize(&width
,&height
);
4529 if ( !HasVirtualWidth() )
4531 m_pState
->SetVirtualWidth(width
);
4538 m_pState
->CheckColumnWidths();
4540 if ( GetSelection() )
4541 CorrectEditorWidgetSizeX();
4543 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4546 // -----------------------------------------------------------------------
4548 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4550 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4554 GetClientSize(&width
, &height
);
4559 #if wxPG_DOUBLE_BUFFER
4560 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4562 int dblh
= (m_lineHeight
*2);
4563 if ( !m_doubleBuffer
)
4565 // Create double buffer bitmap to draw on, if none
4566 int w
= (width
>250)?width
:250;
4567 int h
= height
+ dblh
;
4569 m_doubleBuffer
= new wxBitmap( w
, h
);
4573 int w
= m_doubleBuffer
->GetWidth();
4574 int h
= m_doubleBuffer
->GetHeight();
4576 // Double buffer must be large enough
4577 if ( w
< width
|| h
< (height
+dblh
) )
4579 if ( w
< width
) w
= width
;
4580 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4581 delete m_doubleBuffer
;
4582 m_doubleBuffer
= new wxBitmap( w
, h
);
4589 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4590 m_ncWidth
= event
.GetSize().x
;
4594 if ( m_pState
->m_itemsAdded
)
4595 PrepareAfterItemsAdded();
4597 // Without this, virtual size (atleast under wxGTK) will be skewed
4598 RecalculateVirtualSize();
4604 // -----------------------------------------------------------------------
4606 void wxPropertyGrid::SetVirtualWidth( int width
)
4610 // Disable virtual width
4611 width
= GetClientSize().x
;
4612 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4616 // Enable virtual width
4617 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4619 m_pState
->SetVirtualWidth( width
);
4622 void wxPropertyGrid::SetFocusOnCanvas()
4624 SetFocusIgnoringChildren();
4625 m_editorFocused
= 0;
4628 // -----------------------------------------------------------------------
4629 // wxPropertyGrid mouse event handling
4630 // -----------------------------------------------------------------------
4632 // selFlags uses same values DoSelectProperty's flags
4633 // Returns true if event was vetoed.
4634 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4636 unsigned int selFlags
,
4637 unsigned int column
)
4639 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4642 // Send property grid event of specific type and with specific property
4643 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4644 evt
.SetPropertyGrid(this);
4645 evt
.SetEventObject(m_eventObject
);
4647 evt
.SetColumn(column
);
4648 if ( eventType
== wxEVT_PG_CHANGING
)
4651 evt
.SetCanVeto(true);
4652 m_validationInfo
.m_pValue
= pValue
;
4653 evt
.SetupValidationInfo();
4658 evt
.SetPropertyValue(p
->GetValue());
4660 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4661 evt
.SetCanVeto(true);
4664 wxPropertyGridEvent
* prevProcessedEvent
= m_processedEvent
;
4665 m_processedEvent
= &evt
;
4666 m_eventObject
->HandleWindowEvent(evt
);
4667 m_processedEvent
= prevProcessedEvent
;
4669 return evt
.WasVetoed();
4672 // -----------------------------------------------------------------------
4674 // Return false if should be skipped
4675 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4679 // Need to set focus?
4680 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4685 wxPropertyGridPageState
* state
= m_pState
;
4687 int splitterHitOffset
;
4688 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4690 wxPGProperty
* p
= DoGetItemAtY(y
);
4694 int depth
= (int)p
->GetDepth() - 1;
4696 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4698 if ( x
>= marginEnds
)
4702 if ( p
->IsCategory() )
4704 // This is category.
4705 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4707 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4709 // Expand, collapse, activate etc. if click on text or left of splitter.
4712 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4717 if ( !AddToSelectionFromInputEvent( p
,
4722 // On double-click, expand/collapse.
4723 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4725 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4726 else DoExpand( p
, true );
4730 else if ( splitterHit
== -1 )
4733 unsigned int selFlag
= 0;
4734 if ( columnHit
== 1 )
4736 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4737 selFlag
= wxPG_SEL_FOCUS
;
4739 if ( !AddToSelectionFromInputEvent( p
,
4745 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4747 if ( p
->GetChildCount() && !p
->IsCategory() )
4748 // On double-click, expand/collapse.
4749 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4751 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4752 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4753 else DoExpand( p
, true );
4760 // click on splitter
4761 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4763 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4765 // Double-clicking the splitter causes auto-centering
4766 if ( m_pState
->GetColumnCount() <= 2 )
4768 ResetColumnSizes( true );
4770 SendEvent(wxEVT_PG_COL_DRAGGING
,
4773 wxPG_SEL_NOVALIDATE
,
4774 (unsigned int)m_draggedSplitter
);
4777 else if ( m_dragStatus
== 0 )
4780 // Begin draggin the splitter
4784 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4786 // Allow application to veto dragging
4787 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4789 (unsigned int)splitterHit
) )
4793 // Changes must be committed here or the
4794 // value won't be drawn correctly
4795 if ( !CommitChangesFromEditor() )
4798 m_wndEditor
->Show ( false );
4801 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4804 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4808 m_draggedSplitter
= splitterHit
;
4809 m_dragOffset
= splitterHitOffset
;
4811 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4812 // Fixes button disappearance bug
4814 m_wndEditor2
->Show ( false );
4817 m_startingSplitterX
= x
- splitterHitOffset
;
4826 if ( p
->GetChildCount() )
4828 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4830 // Fine tune cell button x
4831 if ( !p
->IsCategory() )
4832 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4834 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4836 int y2
= y
% m_lineHeight
;
4837 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4839 // On click on expander button, expand/collapse
4840 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4841 DoCollapse( p
, true );
4843 DoExpand( p
, true );
4852 // -----------------------------------------------------------------------
4854 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4855 unsigned int WXUNUSED(y
),
4856 wxMouseEvent
& event
)
4860 // Select property here as well
4861 wxPGProperty
* p
= m_propHover
;
4862 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4864 // Send right click event.
4865 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4872 // -----------------------------------------------------------------------
4874 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4875 unsigned int WXUNUSED(y
),
4876 wxMouseEvent
& event
)
4880 // Select property here as well
4881 wxPGProperty
* p
= m_propHover
;
4883 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4885 // Send double-click event.
4886 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4893 // -----------------------------------------------------------------------
4895 #if wxPG_SUPPORT_TOOLTIPS
4897 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4899 if ( tipString
.length() )
4901 wxScrolledWindow::SetToolTip(tipString
);
4905 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4906 wxScrolledWindow::SetToolTip( m_emptyString
);
4908 wxScrolledWindow::SetToolTip( NULL
);
4913 #endif // #if wxPG_SUPPORT_TOOLTIPS
4915 // -----------------------------------------------------------------------
4917 // Return false if should be skipped
4918 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
,
4919 wxMouseEvent
&event
)
4921 // Safety check (needed because mouse capturing may
4922 // otherwise freeze the control)
4923 if ( m_dragStatus
> 0 && !event
.Dragging() )
4925 HandleMouseUp(x
, y
, event
);
4928 wxPropertyGridPageState
* state
= m_pState
;
4930 int splitterHitOffset
;
4931 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4932 int splitterX
= x
- splitterHitOffset
;
4934 m_colHover
= columnHit
;
4936 if ( m_dragStatus
> 0 )
4938 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4939 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4942 int newSplitterX
= x
- m_dragOffset
;
4944 // Splitter redraw required?
4945 if ( newSplitterX
!= splitterX
)
4948 DoSetSplitterPosition(newSplitterX
,
4950 wxPG_SPLITTER_REFRESH
|
4951 wxPG_SPLITTER_FROM_EVENT
);
4953 SendEvent(wxEVT_PG_COL_DRAGGING
,
4956 wxPG_SEL_NOVALIDATE
,
4957 (unsigned int)m_draggedSplitter
);
4968 int ih
= m_lineHeight
;
4971 #if wxPG_SUPPORT_TOOLTIPS
4972 wxPGProperty
* prevHover
= m_propHover
;
4973 unsigned char prevSide
= m_mouseSide
;
4975 int curPropHoverY
= y
- (y
% ih
);
4977 // On which item it hovers
4980 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4983 // Mouse moves on another property
4985 m_propHover
= DoGetItemAtY(y
);
4986 m_propHoverY
= curPropHoverY
;
4989 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4992 #if wxPG_SUPPORT_TOOLTIPS
4993 // Store which side we are on
4995 if ( columnHit
== 1 )
4997 else if ( columnHit
== 0 )
5001 // If tooltips are enabled, show label or value as a tip
5002 // in case it doesn't otherwise show in full length.
5004 if ( m_windowStyle
& wxPG_TOOLTIPS
)
5006 wxToolTip
* tooltip
= GetToolTip();
5008 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
5010 if ( m_propHover
&& !m_propHover
->IsCategory() )
5013 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
5015 // Show help string as a tooltip
5016 wxString tipString
= m_propHover
->GetHelpString();
5018 SetToolTip(tipString
);
5022 // Show cropped value string as a tooltip
5026 if ( m_mouseSide
== 1 )
5028 tipString
= m_propHover
->m_label
;
5029 space
= splitterX
-m_marginWidth
-3;
5031 else if ( m_mouseSide
== 2 )
5033 tipString
= m_propHover
->GetDisplayedString();
5035 space
= m_width
- splitterX
;
5036 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
5037 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+
5038 wxCC_CUSTOM_IMAGE_MARGIN1
+
5039 wxCC_CUSTOM_IMAGE_MARGIN2
;
5045 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
5048 SetToolTip( tipString
);
5055 #if wxPG_ALLOW_EMPTY_TOOLTIPS
5056 SetToolTip( m_emptyString
);
5058 wxScrolledWindow::SetToolTip( NULL
);
5069 #if wxPG_ALLOW_EMPTY_TOOLTIPS
5070 SetToolTip( m_emptyString
);
5072 wxScrolledWindow::SetToolTip( NULL
);
5080 if ( splitterHit
== -1 ||
5082 HasFlag(wxPG_STATIC_SPLITTER
) )
5084 // hovering on something else
5085 if ( m_curcursor
!= wxCURSOR_ARROW
)
5086 CustomSetCursor( wxCURSOR_ARROW
);
5090 // Do not allow splitter cursor on caption items.
5091 // (also not if we were dragging and its started
5092 // outside the splitter region)
5094 if ( !m_propHover
->IsCategory() &&
5098 // hovering on splitter
5100 // NB: Condition disabled since MouseLeave event (from the
5101 // editor control) cannot be reliably detected.
5102 //if ( m_curcursor != wxCURSOR_SIZEWE )
5103 CustomSetCursor( wxCURSOR_SIZEWE
, true );
5109 // hovering on something else
5110 if ( m_curcursor
!= wxCURSOR_ARROW
)
5111 CustomSetCursor( wxCURSOR_ARROW
);
5116 // Multi select by dragging
5118 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
5119 event
.LeftIsDown() &&
5123 !state
->DoIsPropertySelected(m_propHover
) )
5125 // Additional requirement is that the hovered property
5126 // is adjacent to edges of selection.
5127 const wxArrayPGProperty
& selection
= GetSelectedProperties();
5129 // Since categories cannot be selected along with 'other'
5130 // properties, exclude them from iterator flags.
5131 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
5133 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
5135 // TODO: This could be optimized by keeping track of
5136 // which properties are at the edges of selection.
5137 wxPGProperty
* selProp
= selection
[i
];
5138 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
5141 DoAddToSelection(m_propHover
);
5150 // -----------------------------------------------------------------------
5152 // Also handles Leaving event
5153 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
5154 wxMouseEvent
&WXUNUSED(event
) )
5156 wxPropertyGridPageState
* state
= m_pState
;
5160 int splitterHitOffset
;
5161 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
5163 // No event type check - basicly calling this method should
5164 // just stop dragging.
5165 // Left up after dragged?
5166 if ( m_dragStatus
>= 1 )
5169 // End Splitter Dragging
5171 // DO NOT ENABLE FOLLOWING LINE!
5172 // (it is only here as a reminder to not to do it)
5175 SendEvent(wxEVT_PG_COL_END_DRAG
,
5178 wxPG_SEL_NOVALIDATE
,
5179 (unsigned int)m_draggedSplitter
);
5181 // Disable splitter auto-centering (but only if moved any -
5182 // otherwise we end up disabling auto-center even after a
5183 // recentering double-click).
5184 int posDiff
= abs(m_startingSplitterX
-
5185 GetSplitterPosition(m_draggedSplitter
));
5188 state
->m_dontCenterSplitter
= true;
5190 // This is necessary to return cursor
5191 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5194 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5197 // Set back the default cursor, if necessary
5198 if ( splitterHit
== -1 ||
5201 CustomSetCursor( wxCURSOR_ARROW
);
5206 // Control background needs to be cleared
5207 wxPGProperty
* selected
= GetSelection();
5208 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
5209 DrawItem( selected
);
5213 m_wndEditor
->Show ( true );
5216 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
5217 // Fixes button disappearance bug
5219 m_wndEditor2
->Show ( true );
5222 // This clears the focus.
5223 m_editorFocused
= 0;
5229 // -----------------------------------------------------------------------
5231 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
5233 int splitterX
= GetSplitterPosition();
5236 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
5238 wxWindow
* wnd
= GetEditorControl();
5240 // Hide popup on clicks
5241 if ( event
.GetEventType() != wxEVT_MOTION
)
5242 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5244 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
5250 if ( wnd
== NULL
|| m_dragStatus
||
5252 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
5253 ux
>= (r
.x
+r
.width
) ||
5255 event
.m_y
>= (r
.y
+r
.height
)
5265 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5270 // -----------------------------------------------------------------------
5272 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
5275 if ( OnMouseCommon( event
, &x
, &y
) )
5277 HandleMouseClick(x
,y
,event
);
5282 // -----------------------------------------------------------------------
5284 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5287 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5288 HandleMouseRightClick(x
,y
,event
);
5292 // -----------------------------------------------------------------------
5294 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5296 // Always run standard mouse-down handler as well
5297 OnMouseClick(event
);
5300 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5301 HandleMouseDoubleClick(x
,y
,event
);
5305 // -----------------------------------------------------------------------
5307 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5310 if ( OnMouseCommon( event
, &x
, &y
) )
5312 HandleMouseMove(x
,y
,event
);
5317 // -----------------------------------------------------------------------
5319 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5322 if ( OnMouseCommon( event
, &x
, &y
) )
5324 HandleMouseUp(x
,y
,event
);
5329 // -----------------------------------------------------------------------
5331 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5333 // This may get called from child control as well, so event's
5334 // mouse position cannot be relied on.
5336 if ( event
.Entering() )
5338 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5340 // TODO: Fix this (detect parent and only do
5341 // cursor trick if it is a manager).
5342 wxASSERT( GetParent() );
5343 GetParent()->SetCursor(wxNullCursor
);
5345 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5348 GetParent()->SetCursor(wxNullCursor
);
5350 else if ( event
.Leaving() )
5352 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5353 SetCursor( wxNullCursor
);
5355 // Get real cursor position
5356 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5358 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5361 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5363 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5367 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5375 // -----------------------------------------------------------------------
5377 // Common code used by various OnMouseXXXChild methods.
5378 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5380 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5381 wxASSERT( topCtrlWnd
);
5383 event
.GetPosition(&x
,&y
);
5385 int splitterX
= GetSplitterPosition();
5387 wxRect r
= topCtrlWnd
->GetRect();
5388 if ( !m_dragStatus
&&
5389 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5390 y
>= 0 && y
< r
.height \
5393 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5398 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5405 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5408 if ( OnMouseChildCommon(event
,&x
,&y
) )
5410 bool res
= HandleMouseClick(x
,y
,event
);
5411 if ( !res
) event
.Skip();
5415 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5418 wxASSERT( m_wndEditor
);
5419 // These coords may not be exact (about +-2),
5420 // but that should not matter (right click is about item, not position).
5421 wxPoint pt
= m_wndEditor
->GetPosition();
5422 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5424 // FIXME: Used to set m_propHover to selection here. Was it really
5427 bool res
= HandleMouseRightClick(x
,y
,event
);
5428 if ( !res
) event
.Skip();
5431 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5434 if ( OnMouseChildCommon(event
,&x
,&y
) )
5436 bool res
= HandleMouseMove(x
,y
,event
);
5437 if ( !res
) event
.Skip();
5441 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5444 if ( OnMouseChildCommon(event
,&x
,&y
) )
5446 bool res
= HandleMouseUp(x
,y
,event
);
5447 if ( !res
) event
.Skip();
5451 // -----------------------------------------------------------------------
5452 // wxPropertyGrid keyboard event handling
5453 // -----------------------------------------------------------------------
5455 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5457 // Translates wxKeyEvent to wxPG_ACTION_XXX
5459 int keycode
= event
.GetKeyCode();
5460 int modifiers
= event
.GetModifiers();
5462 wxASSERT( !(modifiers
&~(0xFFFF)) );
5464 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5466 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5468 if ( it
== m_actionTriggers
.end() )
5473 int second
= (it
->second
>>16) & 0xFFFF;
5477 return (it
->second
& 0xFFFF);
5480 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5482 wxASSERT( !(modifiers
&~(0xFFFF)) );
5484 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5486 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5488 if ( it
!= m_actionTriggers
.end() )
5490 // This key combination is already used
5492 // Can add secondary?
5493 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5494 wxT("You can only add up to two separate actions per key combination.") );
5496 action
= it
->second
| (action
<<16);
5499 m_actionTriggers
[hashMapKey
] = action
;
5502 void wxPropertyGrid::ClearActionTriggers( int action
)
5504 wxPGHashMapI2I::iterator it
;
5509 didSomething
= false;
5511 for ( it
= m_actionTriggers
.begin();
5512 it
!= m_actionTriggers
.end();
5515 if ( it
->second
== action
)
5517 m_actionTriggers
.erase(it
);
5518 didSomething
= true;
5523 while ( didSomething
);
5526 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5529 // Handles key event when editor control is not focused.
5532 wxCHECK2(!m_frozen
, return);
5534 // Travelsal between items, collapsing/expanding, etc.
5535 wxPGProperty
* selected
= GetSelection();
5536 int keycode
= event
.GetKeyCode();
5537 bool editorFocused
= IsEditorFocused();
5539 if ( keycode
== WXK_TAB
)
5541 wxWindow
* mainControl
;
5543 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5544 mainControl
= GetParent();
5548 if ( !event
.ShiftDown() )
5550 if ( !editorFocused
&& m_wndEditor
)
5552 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5556 // Tab traversal workaround for platforms on which
5557 // wxWindow::Navigate() may navigate into first child
5558 // instead of next sibling. Does not work perfectly
5559 // in every scenario (for instance, when property grid
5560 // is either first or last control).
5561 #if defined(__WXGTK__)
5562 wxWindow
* sibling
= mainControl
->GetNextSibling();
5564 sibling
->SetFocusFromKbd();
5566 Navigate(wxNavigationKeyEvent::IsForward
);
5572 if ( editorFocused
)
5578 #if defined(__WXGTK__)
5579 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5581 sibling
->SetFocusFromKbd();
5583 Navigate(wxNavigationKeyEvent::IsBackward
);
5591 // Ignore Alt and Control when they are down alone
5592 if ( keycode
== WXK_ALT
||
5593 keycode
== WXK_CONTROL
)
5600 int action
= KeyEventToActions(event
, &secondAction
);
5602 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5605 // Esc cancels any changes
5606 if ( IsEditorsValueModified() )
5608 EditorsValueWasNotModified();
5610 // Update the control as well
5611 selected
->GetEditorClass()->
5612 SetControlStringValue( selected
,
5614 selected
->GetDisplayedString() );
5617 OnValidationFailureReset(selected
);
5623 // Except for TAB, ESC, and any keys specifically dedicated to
5624 // wxPropertyGrid itself, handle child control events in child control.
5626 wxPGFindInVector(m_dedicatedKeys
, keycode
) == wxNOT_FOUND
)
5628 // Only propagate event if it had modifiers
5629 if ( !event
.HasModifiers() )
5631 event
.StopPropagation();
5637 bool wasHandled
= false;
5642 if ( ButtonTriggerKeyTest(action
, event
) )
5645 wxPGProperty
* p
= selected
;
5647 // Travel and expand/collapse
5650 if ( p
->GetChildCount() )
5652 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5654 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5657 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5659 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5666 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5670 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5676 if ( selectDir
>= -1 )
5678 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5682 int reopenLabelEditorCol
= -1;
5684 if ( editorFocused
)
5686 // If editor was focused, then make the next editor
5688 selFlags
|= wxPG_SEL_FOCUS
;
5692 // Also maintain the same label editor focus state
5693 if ( m_labelEditor
)
5694 reopenLabelEditorCol
= m_selColumn
;
5697 DoSelectProperty(p
, selFlags
);
5699 if ( reopenLabelEditorCol
>= 0 )
5700 DoBeginLabelEdit(reopenLabelEditorCol
);
5707 // If nothing was selected, select the first item now
5708 // (or navigate out of tab).
5709 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5711 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5712 if ( p
) DoSelectProperty(p
);
5721 // -----------------------------------------------------------------------
5723 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5725 // If there was editor open and focused, then this event should not
5726 // really be processed here.
5727 if ( IsEditorFocused() )
5729 // However, if event had modifiers, it is probably still best
5731 if ( event
.HasModifiers() )
5734 event
.StopPropagation();
5738 HandleKeyEvent(event
, false);
5741 // -----------------------------------------------------------------------
5743 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5748 action
= KeyEventToActions(event
, &secondAction
);
5751 // Does the keycode trigger button?
5752 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5755 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5756 GetEventHandler()->AddPendingEvent(evt
);
5763 // -----------------------------------------------------------------------
5765 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5767 HandleKeyEvent(event
, true);
5770 // -----------------------------------------------------------------------
5771 // wxPropertyGrid miscellaneous event handling
5772 // -----------------------------------------------------------------------
5774 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5777 // Check if the focus is in this control or one of its children
5778 wxWindow
* newFocused
= wxWindow::FindFocus();
5780 if ( newFocused
!= m_curFocused
)
5781 HandleFocusChange( newFocused
);
5784 // Check if top-level parent has changed
5785 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5787 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5793 // Resolve pending property removals
5794 if ( m_deletedProperties
.size() > 0 )
5796 wxArrayPGProperty
& arr
= m_deletedProperties
;
5797 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5799 DeleteProperty(arr
[i
]);
5803 if ( m_removedProperties
.size() > 0 )
5805 wxArrayPGProperty
& arr
= m_removedProperties
;
5806 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5808 RemoveProperty(arr
[i
]);
5814 bool wxPropertyGrid::IsEditorFocused() const
5816 wxWindow
* focus
= wxWindow::FindFocus();
5818 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5819 focus
== GetEditorControl() )
5825 // Called by focus event handlers. newFocused is the window that becomes focused.
5826 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5828 unsigned int oldFlags
= m_iFlags
;
5829 bool wasEditorFocused
= false;
5830 wxWindow
* wndEditor
= m_wndEditor
;
5832 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5834 wxWindow
* parent
= newFocused
;
5836 // This must be one of nextFocus' parents.
5839 if ( parent
== wndEditor
)
5841 wasEditorFocused
= true;
5843 // Use m_eventObject, which is either wxPropertyGrid or
5844 // wxPropertyGridManager, as appropriate.
5845 else if ( parent
== m_eventObject
)
5847 m_iFlags
|= wxPG_FL_FOCUSED
;
5850 parent
= parent
->GetParent();
5853 // Notify editor control when it receives a focus
5854 if ( wasEditorFocused
&& m_curFocused
!= newFocused
)
5856 wxPGProperty
* p
= GetSelection();
5859 const wxPGEditor
* editor
= p
->GetEditorClass();
5860 ResetEditorAppearance();
5861 editor
->OnFocus(p
, GetEditorControl());
5865 m_curFocused
= newFocused
;
5867 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5868 (oldFlags
& wxPG_FL_FOCUSED
) )
5870 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5872 // Need to store changed value
5873 CommitChangesFromEditor();
5879 // Preliminary code for tab-order respecting
5880 // tab-traversal (but should be moved to
5883 wxWindow* prevFocus = event.GetWindow();
5884 wxWindow* useThis = this;
5885 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5886 useThis = GetParent();
5889 prevFocus->GetParent() == useThis->GetParent() )
5891 wxList& children = useThis->GetParent()->GetChildren();
5893 wxNode* node = children.Find(prevFocus);
5895 if ( node->GetNext() &&
5896 useThis == node->GetNext()->GetData() )
5897 DoSelectProperty(GetFirst());
5898 else if ( node->GetPrevious () &&
5899 useThis == node->GetPrevious()->GetData() )
5900 DoSelectProperty(GetLastProperty());
5907 wxPGProperty
* selected
= GetSelection();
5908 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5909 DrawItem( selected
);
5913 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5915 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5916 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5917 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5918 //else if ( event.GetWindow() )
5920 HandleFocusChange(event
.GetWindow());
5925 // -----------------------------------------------------------------------
5927 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5929 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5933 // -----------------------------------------------------------------------
5935 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5937 m_iFlags
|= wxPG_FL_SCROLLED
;
5942 // -----------------------------------------------------------------------
5944 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5946 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5948 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5952 // -----------------------------------------------------------------------
5953 // Property editor related functions
5954 // -----------------------------------------------------------------------
5956 // noDefCheck = true prevents infinite recursion.
5957 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5958 const wxString
& editorName
,
5961 wxASSERT( editorClass
);
5963 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5964 RegisterDefaultEditors();
5966 wxString name
= editorName
;
5967 if ( name
.length() == 0 )
5968 name
= editorClass
->GetName();
5970 // Existing editor under this name?
5971 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5973 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5975 // If this name was already used, try class name.
5976 name
= editorClass
->GetClassInfo()->GetClassName();
5977 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5980 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5981 (wxPGEditor
*) vt_it
->second
,
5982 "Editor with given name was already registered" );
5984 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5989 // Use this in RegisterDefaultEditors.
5990 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5991 if ( wxPGEditor_##EDITOR == NULL ) \
5993 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5994 new wxPG##EDITOR##Editor, true ); \
5997 // Registers all default editor classes
5998 void wxPropertyGrid::RegisterDefaultEditors()
6000 wxPGRegisterDefaultEditorClass( TextCtrl
);
6001 wxPGRegisterDefaultEditorClass( Choice
);
6002 wxPGRegisterDefaultEditorClass( ComboBox
);
6003 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
6004 #if wxPG_INCLUDE_CHECKBOX
6005 wxPGRegisterDefaultEditorClass( CheckBox
);
6007 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
6009 // Register SpinCtrl etc. editors before use
6010 RegisterAdditionalEditors();
6013 // -----------------------------------------------------------------------
6014 // wxPGStringTokenizer
6015 // Needed to handle C-style string lists (e.g. "str1" "str2")
6016 // -----------------------------------------------------------------------
6018 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
6019 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
6023 wxPGStringTokenizer::~wxPGStringTokenizer()
6027 bool wxPGStringTokenizer::HasMoreTokens()
6029 const wxString
& str
= *m_str
;
6031 wxString::const_iterator i
= m_curPos
;
6033 wxUniChar delim
= m_delimeter
;
6035 wxUniChar prev_a
= wxT('\0');
6037 bool inToken
= false;
6039 while ( i
!= str
.end() )
6048 m_readyToken
.clear();
6053 if ( prev_a
!= wxT('\\') )
6057 if ( a
!= wxT('\\') )
6077 m_curPos
= str
.end();
6085 wxString
wxPGStringTokenizer::GetNextToken()
6087 return m_readyToken
;
6090 // -----------------------------------------------------------------------
6092 // -----------------------------------------------------------------------
6094 wxPGChoiceEntry::wxPGChoiceEntry()
6095 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
6099 // -----------------------------------------------------------------------
6101 // -----------------------------------------------------------------------
6103 wxPGChoicesData::wxPGChoicesData()
6107 wxPGChoicesData::~wxPGChoicesData()
6112 void wxPGChoicesData::Clear()
6117 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
6119 wxASSERT( m_items
.size() == 0 );
6121 m_items
= data
->m_items
;
6124 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
6125 const wxPGChoiceEntry
& item
)
6127 wxVector
<wxPGChoiceEntry
>::iterator it
;
6131 index
= (int) m_items
.size();
6135 it
= m_items
.begin() + index
;
6138 m_items
.insert(it
, item
);
6140 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
6142 // Need to fix value?
6143 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
6144 ownEntry
.SetValue(index
);
6149 // -----------------------------------------------------------------------
6150 // wxPropertyGridEvent
6151 // -----------------------------------------------------------------------
6153 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
6156 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
6157 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
6158 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
6159 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
6160 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
6161 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
6162 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
6163 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
6164 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
6165 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
6166 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
6167 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
6168 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
6169 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
6171 // -----------------------------------------------------------------------
6173 void wxPropertyGridEvent::Init()
6175 m_validationInfo
= NULL
;
6178 m_wasVetoed
= false;
6181 // -----------------------------------------------------------------------
6183 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6184 : wxCommandEvent(commandType
,id
)
6190 // -----------------------------------------------------------------------
6192 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6193 : wxCommandEvent(event
)
6195 m_eventType
= event
.GetEventType();
6196 m_eventObject
= event
.m_eventObject
;
6198 OnPropertyGridSet();
6199 m_property
= event
.m_property
;
6200 m_validationInfo
= event
.m_validationInfo
;
6201 m_canVeto
= event
.m_canVeto
;
6202 m_wasVetoed
= event
.m_wasVetoed
;
6205 // -----------------------------------------------------------------------
6207 void wxPropertyGridEvent::OnPropertyGridSet()
6213 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6215 m_pg
->m_liveEvents
.push_back(this);
6218 // -----------------------------------------------------------------------
6220 wxPropertyGridEvent::~wxPropertyGridEvent()
6225 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6228 // Use iterate from the back since it is more likely that the event
6229 // being desroyed is at the end of the array.
6230 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
6232 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
6234 if ( liveEvents
[i
] == this )
6236 liveEvents
.erase(liveEvents
.begin() + i
);
6243 // -----------------------------------------------------------------------
6245 wxEvent
* wxPropertyGridEvent::Clone() const
6247 return new wxPropertyGridEvent( *this );
6250 // -----------------------------------------------------------------------
6251 // wxPropertyGridPopulator
6252 // -----------------------------------------------------------------------
6254 wxPropertyGridPopulator::wxPropertyGridPopulator()
6258 wxPGGlobalVars
->m_offline
++;
6261 // -----------------------------------------------------------------------
6263 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6266 m_propHierarchy
.clear();
6269 // -----------------------------------------------------------------------
6271 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6277 // -----------------------------------------------------------------------
6279 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6282 // Free unused sets of choices
6283 wxPGHashMapS2P::iterator it
;
6285 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6287 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6294 m_pg
->GetPanel()->Refresh();
6296 wxPGGlobalVars
->m_offline
--;
6299 // -----------------------------------------------------------------------
6301 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6302 const wxString
& propLabel
,
6303 const wxString
& propName
,
6304 const wxString
* propValue
,
6305 wxPGChoices
* pChoices
)
6307 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6308 wxPGProperty
* parent
= GetCurParent();
6310 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6312 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6316 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6318 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6322 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6324 property
->SetLabel(propLabel
);
6325 property
->DoSetName(propName
);
6327 if ( pChoices
&& pChoices
->IsOk() )
6328 property
->SetChoices(*pChoices
);
6330 m_state
->DoInsert(parent
, -1, property
);
6333 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
6334 wxPG_PROGRAMMATIC_VALUE
);
6339 // -----------------------------------------------------------------------
6341 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6343 m_propHierarchy
.push_back(property
);
6344 DoScanForChildren();
6345 m_propHierarchy
.pop_back();
6348 // -----------------------------------------------------------------------
6350 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6351 const wxString
& idString
)
6353 wxPGChoices choices
;
6356 if ( choicesString
[0] == wxT('@') )
6358 wxString ids
= choicesString
.substr(1);
6359 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6360 if ( it
== m_dictIdChoices
.end() )
6361 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6363 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6368 if ( idString
.length() )
6370 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6371 if ( it
!= m_dictIdChoices
.end() )
6373 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6380 // Parse choices string
6381 wxString::const_iterator it
= choicesString
.begin();
6385 bool labelValid
= false;
6387 for ( ; it
!= choicesString
.end(); ++it
)
6393 if ( c
== wxT('"') )
6398 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6399 choices
.Add(label
, l
);
6402 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6407 else if ( c
== wxT('=') )
6414 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6421 if ( c
== wxT('"') )
6434 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6435 choices
.Add(label
, l
);
6438 if ( !choices
.IsOk() )
6440 choices
.EnsureData();
6444 if ( idString
.length() )
6445 m_dictIdChoices
[idString
] = choices
.GetData();
6452 // -----------------------------------------------------------------------
6454 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6456 if ( s
.Last() == wxT('%') )
6458 wxString s2
= s
.substr(0,s
.length()-1);
6460 if ( s2
.ToLong(&val
, 10) )
6462 *pval
= (val
*max
)/100;
6468 return s
.ToLong(pval
, 10);
6471 // -----------------------------------------------------------------------
6473 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6474 const wxString
& type
,
6475 const wxString
& value
)
6477 int l
= m_propHierarchy
.size();
6481 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6482 wxString valuel
= value
.Lower();
6485 if ( type
.length() == 0 )
6490 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6492 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6494 else if ( value
.ToLong(&v
, 0) )
6501 if ( type
== wxT("string") )
6505 else if ( type
== wxT("int") )
6508 value
.ToLong(&v
, 0);
6511 else if ( type
== wxT("bool") )
6513 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6520 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6525 p
->SetAttribute( name
, variant
);
6530 // -----------------------------------------------------------------------
6532 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6534 wxLogError(_("Error in resource: %s"),msg
.c_str());
6537 // -----------------------------------------------------------------------
6539 #endif // wxUSE_PROPGRID