1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
66 #include "wx/scopeguard.h"
68 // Two pics for the expand / collapse buttons.
69 // Files are not supplied with this project (since it is
70 // recommended to use either custom or native rendering).
71 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
72 // and copy xpm files from archive to wxPropertyGrid src directory
73 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
74 // and set wxPG_USE_RENDERER_NATIVE to 0).
75 #ifndef wxPG_ICON_WIDTH
76 #if defined(__WXMAC__)
77 #include "mac_collapse.xpm"
78 #include "mac_expand.xpm"
79 #elif defined(__WXGTK__)
80 #include "linux_collapse.xpm"
81 #include "linux_expand.xpm"
83 #include "default_collapse.xpm"
84 #include "default_expand.xpm"
89 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
90 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
91 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
92 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
93 #define wxPG_YSPACING_MIN 1
94 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
95 // but causes normal combobox to spill out under MSW
97 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
99 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
100 // Must be larger than largest control border
104 #define wxPG_DEFAULT_CURSOR wxNullCursor
107 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
109 //#define wxPG_HIDER_BUTTON_HEIGHT 25
111 #define wxPG_PIXELS_PER_UNIT m_lineHeight
113 #ifdef wxPG_ICON_WIDTH
114 #define m_iconHeight m_iconWidth
117 //#define wxPG_TOOLTIP_DELAY 1000
119 // This is the number of pixels the expander button inside
120 // property cells (i.e. not in the grey margin area are
122 #define IN_CELL_EXPANDER_BUTTON_X_ADJUST 2
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid
::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid
::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include "wx/module.h"
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { wxDELETE(wxPGGlobalVars
); }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 // When wxPG is loaded dynamically after the application is already running
158 // then the built-in module system won't pick this one up. Add it manually.
159 void wxPGInitResourceModule()
161 wxModule
* module
= new wxPGGlobalVarsClassManager
;
163 wxModule
::RegisterModule(module
);
166 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
169 wxPGGlobalVarsClass
::wxPGGlobalVarsClass()
171 wxPGProperty
::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
173 m_boolChoices
.Add(_("False"));
174 m_boolChoices
.Add(_("True"));
176 m_fontFamilyChoices
= NULL
;
178 m_defaultRenderer
= new wxPGDefaultRenderer();
180 m_autoGetTranslation
= false;
188 // Prepare some shared variants
189 m_vEmptyString
= wxString();
191 m_vMinusOne
= (long) -1;
195 // Prepare cached string constants
196 m_strstring
= wxS("string");
197 m_strlong
= wxS("long");
198 m_strbool
= wxS("bool");
199 m_strlist
= wxS("list");
200 m_strDefaultValue
= wxS("DefaultValue");
201 m_strMin
= wxS("Min");
202 m_strMax
= wxS("Max");
203 m_strUnits
= wxS("Units");
204 m_strHint
= wxS("Hint");
205 #if wxPG_COMPATIBILITY_1_4
206 m_strInlineHelp
= wxS("InlineHelp");
213 wxPGGlobalVarsClass
::~wxPGGlobalVarsClass()
217 delete m_defaultRenderer
;
219 // This will always have one ref
220 delete m_fontFamilyChoices
;
223 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
224 delete ((wxValidator
*)m_arrValidators
[i
]);
228 // Destroy value type class instances.
229 wxPGHashMapS2P
::iterator vt_it
;
231 // Destroy editor class instances.
232 // iterate over all the elements in the class
233 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
235 delete ((wxPGEditor
*)vt_it
->second
);
238 // Make sure the global pointers have been reset
239 wxASSERT(wxPG_EDITOR(TextCtrl
) == NULL
);
240 wxASSERT(wxPG_EDITOR(ChoiceAndButton
) == NULL
);
242 delete wxPGProperty
::sm_wxPG_LABEL
;
245 void wxPropertyGridInitGlobalsIfNeeded()
249 // -----------------------------------------------------------------------
251 // -----------------------------------------------------------------------
253 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxControl
)
255 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxControl
)
256 EVT_IDLE(wxPropertyGrid
::OnIdle
)
257 EVT_PAINT(wxPropertyGrid
::OnPaint
)
258 EVT_SIZE(wxPropertyGrid
::OnResize
)
259 EVT_ENTER_WINDOW(wxPropertyGrid
::OnMouseEntry
)
260 EVT_LEAVE_WINDOW(wxPropertyGrid
::OnMouseEntry
)
261 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid
::OnCaptureChange
)
262 EVT_SCROLLWIN(wxPropertyGrid
::OnScrollEvent
)
263 EVT_CHILD_FOCUS(wxPropertyGrid
::OnChildFocusEvent
)
264 EVT_SET_FOCUS(wxPropertyGrid
::OnFocusEvent
)
265 EVT_KILL_FOCUS(wxPropertyGrid
::OnFocusEvent
)
266 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid
::OnSysColourChanged
)
267 EVT_MOTION(wxPropertyGrid
::OnMouseMove
)
268 EVT_LEFT_DOWN(wxPropertyGrid
::OnMouseClick
)
269 EVT_LEFT_UP(wxPropertyGrid
::OnMouseUp
)
270 EVT_RIGHT_UP(wxPropertyGrid
::OnMouseRightClick
)
271 EVT_LEFT_DCLICK(wxPropertyGrid
::OnMouseDoubleClick
)
272 EVT_KEY_DOWN(wxPropertyGrid
::OnKey
)
275 // -----------------------------------------------------------------------
277 wxPropertyGrid
::wxPropertyGrid()
278 : wxControl(), wxScrollHelper(this)
283 // -----------------------------------------------------------------------
285 wxPropertyGrid
::wxPropertyGrid( wxWindow
*parent
,
290 const wxString
& name
)
291 : wxControl(), wxScrollHelper(this)
294 Create(parent
,id
,pos
,size
,style
,name
);
297 // -----------------------------------------------------------------------
299 bool wxPropertyGrid
::Create( wxWindow
*parent
,
304 const wxString
& name
)
307 if (!(style
&wxBORDER_MASK
))
309 style
|= wxBORDER_THEME
;
314 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
315 style
&= ~(wxTAB_TRAVERSAL
);
316 style
|= wxWANTS_CHARS
;
318 wxControl
::Create(parent
, id
, pos
, size
,
319 style
| wxScrolledWindowStyle
,
328 // -----------------------------------------------------------------------
331 // Initialize values to defaults
333 void wxPropertyGrid
::Init1()
335 // Register editor classes, if necessary.
336 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
337 wxPropertyGrid
::RegisterDefaultEditors();
339 m_validatingEditor
= 0;
342 m_wndEditor
= m_wndEditor2
= NULL
;
346 m_labelEditor
= NULL
;
347 m_labelEditorProperty
= NULL
;
348 m_eventObject
= this;
350 m_processedEvent
= NULL
;
351 m_sortFunction
= NULL
;
352 m_inDoPropertyChanged
= false;
353 m_inCommitChangesFromEditor
= false;
354 m_inDoSelectProperty
= false;
355 m_inOnValidationFailure
= false;
356 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
361 // Set up default unspecified value 'colour'
362 m_unspecifiedAppearance
.SetFgCol(*wxLIGHT_GREY
);
365 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
366 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
367 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
368 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
369 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
370 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
371 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
372 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
373 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
375 m_coloursCustomized
= 0;
378 #if wxPG_DOUBLE_BUFFER
379 m_doubleBuffer
= NULL
;
382 #ifndef wxPG_ICON_WIDTH
388 m_iconWidth
= wxPG_ICON_WIDTH
;
393 m_gutterWidth
= wxPG_GUTTER_MIN
;
394 m_subgroup_extramargin
= 10;
398 m_width
= m_height
= 0;
400 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
403 m_chgInfo_changedProperty
= NULL
;
406 // -----------------------------------------------------------------------
409 // Initialize after parent etc. set
411 void wxPropertyGrid
::Init2()
413 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
416 // Smaller controls on Mac
417 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
420 // Now create state, if one didn't exist already
421 // (wxPropertyGridManager might have created it for us).
424 m_pState
= CreateState();
425 m_pState
->m_pPropGrid
= this;
426 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
429 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
430 m_pState
->m_dontCenterSplitter
= true;
432 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
434 m_pState
->InitNonCatMode();
436 m_pState
->m_properties
= m_pState
->m_abcArray
;
439 GetClientSize(&m_width
,&m_height
);
441 #ifndef wxPG_ICON_WIDTH
442 // create two bitmap nodes for drawing
443 m_expandbmp
= new wxBitmap(expand_xpm
);
444 m_collbmp
= new wxBitmap(collapse_xpm
);
446 // calculate average font height for bitmap centering
448 m_iconWidth
= m_expandbmp
->GetWidth();
449 m_iconHeight
= m_expandbmp
->GetHeight();
452 m_curcursor
= wxCURSOR_ARROW
;
453 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
455 // adjust bitmap icon y position so they are centered
456 m_vspacing
= wxPG_DEFAULT_VSPACING
;
458 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
460 // Allocate cell datas
461 m_propertyDefaultCell
.SetEmptyData();
462 m_categoryDefaultCell
.SetEmptyData();
466 // This helps with flicker
467 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
469 // Hook the top-level parent
474 // set virtual size to this window size
475 wxSize wndsize
= GetSize();
476 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
478 m_timeCreated
= ::wxGetLocalTimeMillis();
480 m_iFlags
|= wxPG_FL_INITIALIZED
;
482 m_ncWidth
= wndsize
.GetWidth();
484 // Need to call OnResize handler or size given in constructor/Create
486 wxSizeEvent
sizeEvent(wndsize
,0);
490 // -----------------------------------------------------------------------
492 wxPropertyGrid
::~wxPropertyGrid()
497 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
501 // Remove grid and property pointers from live wxPropertyGridEvents.
502 for ( i
=0; i
<m_liveEvents
.size(); i
++ )
504 wxPropertyGridEvent
* evt
= m_liveEvents
[i
];
505 evt
->SetPropertyGrid(NULL
);
506 evt
->SetProperty(NULL
);
508 m_liveEvents
.clear();
510 if ( m_processedEvent
)
512 // All right... we are being deleted while wxPropertyGrid event
513 // is being sent. Make sure that event propagates as little
514 // as possible (although usually this is not enough to prevent
516 m_processedEvent
->Skip(false);
517 m_processedEvent
->StopPropagation();
519 // Let's use wxMessageBox to make the message appear more
520 // reliably (and *before* the crash can happen).
521 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
522 "generated by it. This usually leads to a crash "
523 "so it is recommended to destroy the control "
524 "at idle time instead.");
527 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
529 // This should do prevent things from going too badly wrong
530 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
532 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
535 // Call with NULL to disconnect event handling
536 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
540 wxASSERT_MSG( !IsEditorsValueModified(),
541 wxS("Most recent change in property editor was ")
542 wxS("lost!!! (if you don't want this to happen, ")
543 wxS("close your frames and dialogs using ")
544 wxS("Close(false).)") );
547 #if wxPG_DOUBLE_BUFFER
548 if ( m_doubleBuffer
)
549 delete m_doubleBuffer
;
552 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
555 delete m_cursorSizeWE
;
557 #ifndef wxPG_ICON_WIDTH
562 // Delete common value records
563 for ( i
=0; i
<m_commonValues
.size(); i
++ )
565 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
566 wxPGCommonValue
* value
= m_commonValues
[i
];
571 // -----------------------------------------------------------------------
573 bool wxPropertyGrid
::Destroy()
575 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
578 return wxControl
::Destroy();
581 // -----------------------------------------------------------------------
583 wxPropertyGridPageState
* wxPropertyGrid
::CreateState() const
585 return new wxPropertyGridPageState();
588 // -----------------------------------------------------------------------
589 // wxPropertyGrid overridden wxWindow methods
590 // -----------------------------------------------------------------------
592 void wxPropertyGrid
::SetWindowStyleFlag( long style
)
594 long old_style
= m_windowStyle
;
596 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
598 wxASSERT( m_pState
);
600 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
603 EnableCategories( true );
605 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
607 // Disable categories
608 EnableCategories( false );
610 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
616 PrepareAfterItemsAdded();
618 m_pState
->m_itemsAdded
= 1;
620 #if wxPG_SUPPORT_TOOLTIPS
621 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
627 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
628 SetToolTip ( tooltip );
629 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
632 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
642 wxControl
::SetWindowStyleFlag ( style
);
644 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
646 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
648 CalculateFontAndBitmapStuff( m_vspacing
);
654 // -----------------------------------------------------------------------
656 void wxPropertyGrid
::Freeze()
665 // -----------------------------------------------------------------------
667 void wxPropertyGrid
::Thaw()
674 RecalculateVirtualSize();
675 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
679 // Force property re-selection
680 // NB: We must copy the selection.
681 wxArrayPGProperty selection
= m_pState
->m_selection
;
682 DoSetSelection(selection
, wxPG_SEL_FORCE
| wxPG_SEL_NONVISIBLE
);
686 // -----------------------------------------------------------------------
688 bool wxPropertyGrid
::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
690 wxCHECK( prop
, false );
692 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
693 return DoSelectProperty(prop
, selFlags
);
695 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
697 if ( !selection
.size() )
699 return DoSelectProperty(prop
, selFlags
);
703 // For categories, only one can be selected at a time
704 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
707 selection
.push_back(prop
);
709 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
711 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
720 // -----------------------------------------------------------------------
722 bool wxPropertyGrid
::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
724 wxCHECK( prop
, false );
727 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
728 if ( selection
.size() <= 1 )
730 res
= DoSelectProperty(NULL
, selFlags
);
734 m_pState
->DoRemoveFromSelection(prop
);
742 // -----------------------------------------------------------------------
744 bool wxPropertyGrid
::DoSelectAndEdit( wxPGProperty
* prop
,
745 unsigned int colIndex
,
746 unsigned int selFlags
)
749 // NB: Enable following if label editor background colour is
750 // ever changed to any other than m_colSelBack.
752 // We use this workaround to prevent visible flicker when editing
753 // a cell. Atleast on wxMSW, there is a difficult to find
754 // (and perhaps prevent) redraw somewhere between making property
755 // selected and enabling label editing.
757 //wxColour prevColSelBack = m_colSelBack;
758 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
764 res
= DoSelectProperty(prop
, selFlags
);
769 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
771 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
773 res
= DoAddToSelection(prop
, selFlags
);
777 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
779 DoBeginLabelEdit(colIndex
, selFlags
);
783 //m_colSelBack = prevColSelBack;
787 // -----------------------------------------------------------------------
789 bool wxPropertyGrid
::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
790 unsigned int colIndex
,
791 wxMouseEvent
* mouseEvent
,
794 const wxArrayPGProperty
& selection
= GetSelectedProperties();
795 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
798 // Set to 2 if also add all items in between
799 int addToExistingSelection
= 0;
801 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
805 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
806 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
808 // Allow right-click for context menu without
809 // disturbing the selection.
810 if ( GetSelectedProperties().size() <= 1 ||
812 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
817 if ( mouseEvent
->ControlDown() )
819 addToExistingSelection
= 1;
821 else if ( mouseEvent
->ShiftDown() )
823 if ( selection
.size() > 0 && !prop
->IsCategory() )
824 addToExistingSelection
= 2;
826 addToExistingSelection
= 1;
832 if ( addToExistingSelection
== 1 )
835 if ( !alreadySelected
)
837 res
= DoAddToSelection(prop
, selFlags
);
839 else if ( GetSelectedProperties().size() > 1 )
841 res
= DoRemoveFromSelection(prop
, selFlags
);
844 else if ( addToExistingSelection
== 2 )
846 // Add this, and all in between
848 // Find top selected property
849 wxPGProperty
* topSelProp
= selection
[0];
850 int topSelPropY
= topSelProp
->GetY();
851 for ( unsigned int i
=1; i
<selection
.size(); i
++ )
853 wxPGProperty
* p
= selection
[i
];
855 if ( y
< topSelPropY
)
862 wxPGProperty
* startFrom
;
863 wxPGProperty
* stopAt
;
865 if ( prop
->GetY() <= topSelPropY
)
867 // Property is above selection (or same)
873 // Property is below selection
874 startFrom
= topSelProp
;
878 // Iterate through properties in-between, and select them
879 wxPropertyGridIterator it
;
881 for ( it
= GetIterator(wxPG_ITERATE_VISIBLE
, startFrom
);
885 wxPGProperty
* p
= *it
;
887 if ( !p
->IsCategory() &&
888 !m_pState
->DoIsPropertySelected(p
) )
890 DoAddToSelection(p
, selFlags
);
899 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
905 // -----------------------------------------------------------------------
907 void wxPropertyGrid
::DoSetSelection( const wxArrayPGProperty
& newSelection
,
910 if ( newSelection
.size() > 0 )
912 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
917 DoClearSelection(false, selFlags
);
920 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
922 DoAddToSelection(newSelection
[i
], selFlags
);
928 // -----------------------------------------------------------------------
930 void wxPropertyGrid
::MakeColumnEditable( unsigned int column
,
933 wxASSERT( column
!= 1 );
935 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
939 cols
.push_back(column
);
943 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
945 if ( cols
[i
] == (int)column
)
946 cols
.erase( cols
.begin() + i
);
951 // -----------------------------------------------------------------------
953 void wxPropertyGrid
::DoBeginLabelEdit( unsigned int colIndex
,
956 wxPGProperty
* selected
= GetSelection();
957 wxCHECK_RET(selected
, wxT("No property selected"));
958 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
960 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
962 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
969 const wxPGCell
* cell
= NULL
;
970 if ( selected
->HasCell(colIndex
) )
972 cell
= &selected
->GetCell(colIndex
);
973 if ( !cell
->HasText() && colIndex
== 0 )
974 text
= selected
->GetLabel();
980 text
= selected
->GetLabel();
982 cell
= &selected
->GetOrCreateCell(colIndex
);
985 if ( cell
&& cell
->HasText() )
986 text
= cell
->GetText();
988 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
990 m_selColumn
= colIndex
;
992 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
994 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
1002 wxWindowID id
= tc
->GetId();
1003 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1004 wxCommandEventHandler(wxPropertyGrid
::OnLabelEditorEnterPress
),
1006 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1007 wxKeyEventHandler(wxPropertyGrid
::OnLabelEditorKeyPress
),
1012 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1013 m_labelEditorProperty
= selected
;
1016 // -----------------------------------------------------------------------
1019 wxPropertyGrid
::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1021 DoEndLabelEdit(true);
1024 // -----------------------------------------------------------------------
1026 void wxPropertyGrid
::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1028 int keycode
= event
.GetKeyCode();
1030 if ( keycode
== WXK_ESCAPE
)
1032 DoEndLabelEdit(false);
1036 HandleKeyEvent(event
, true);
1040 // -----------------------------------------------------------------------
1042 void wxPropertyGrid
::DoEndLabelEdit( bool commit
, int selFlags
)
1044 if ( !m_labelEditor
)
1047 wxPGProperty
* prop
= m_labelEditorProperty
;
1052 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1054 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1055 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1056 prop
, NULL
, selFlags
,
1061 wxString text
= m_labelEditor
->GetValue();
1062 wxPGCell
* cell
= NULL
;
1063 if ( prop
->HasCell(m_selColumn
) )
1065 cell
= &prop
->GetCell(m_selColumn
);
1069 if ( m_selColumn
== 0 )
1070 prop
->SetLabel(text
);
1072 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1076 cell
->SetText(text
);
1080 int wasFocused
= m_iFlags
& wxPG_FL_FOCUSED
;
1082 DestroyEditorWnd(m_labelEditor
);
1084 m_labelEditor
= NULL
;
1085 m_labelEditorProperty
= NULL
;
1087 // Fix focus (needed at least on wxGTK)
1094 // -----------------------------------------------------------------------
1096 void wxPropertyGrid
::SetExtraStyle( long exStyle
)
1098 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1099 OnTLPChanging(::wxGetTopLevelParent(this));
1101 OnTLPChanging(NULL
);
1103 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1105 #if defined(__WXMSW__)
1108 // Don't use WS_EX_COMPOSITED just now.
1111 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1112 hWnd = (HWND)GetParent()->GetHWND();
1114 hWnd = (HWND)GetHWND();
1116 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1117 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1120 //#elif defined(__WXGTK20__)
1122 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1123 // truly was double-buffered.
1124 if ( !this->IsDoubleBuffered() )
1126 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1130 #if wxPG_DOUBLE_BUFFER
1131 wxDELETE(m_doubleBuffer
);
1136 wxControl
::SetExtraStyle( exStyle
);
1138 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1139 m_pState
->InitNonCatMode();
1141 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1142 m_windowStyle
|= wxPG_TOOLTIPS
;
1145 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1148 // -----------------------------------------------------------------------
1150 // returns the best acceptable minimal size
1151 wxSize wxPropertyGrid
::DoGetBestSize() const
1153 int lineHeight
= wxMax(15, m_lineHeight
);
1155 // don't make the grid too tall (limit height to 10 items) but don't
1156 // make it too small neither
1157 int numLines
= wxMin
1159 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1163 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1164 int width
= m_marginWidth
;
1165 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1167 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1170 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1176 // -----------------------------------------------------------------------
1178 void wxPropertyGrid
::OnTLPChanging( wxWindow
* newTLP
)
1180 if ( newTLP
== m_tlp
)
1183 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1186 // Parent changed so let's redetermine and re-hook the
1187 // correct top-level window.
1190 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1191 wxCloseEventHandler(wxPropertyGrid
::OnTLPClose
),
1193 m_tlpClosed
= m_tlp
;
1194 m_tlpClosedTime
= currentTime
;
1199 // Only accept new tlp if same one was not just dismissed.
1200 if ( newTLP
!= m_tlpClosed
||
1201 m_tlpClosedTime
+250 < currentTime
)
1203 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1204 wxCloseEventHandler(wxPropertyGrid
::OnTLPClose
),
1217 // -----------------------------------------------------------------------
1219 void wxPropertyGrid
::OnTLPClose( wxCloseEvent
& event
)
1221 // ClearSelection forces value validation/commit.
1222 if ( event
.CanVeto() && !DoClearSelection() )
1228 // Ok, it can close, set tlp pointer to NULL. Some other event
1229 // handler can of course veto the close, but our OnIdle() should
1230 // then be able to regain the tlp pointer.
1231 OnTLPChanging(NULL
);
1236 // -----------------------------------------------------------------------
1238 bool wxPropertyGrid
::Reparent( wxWindowBase
*newParent
)
1240 OnTLPChanging((wxWindow
*)newParent
);
1242 bool res
= wxControl
::Reparent(newParent
);
1247 // -----------------------------------------------------------------------
1248 // wxPropertyGrid Font and Colour Methods
1249 // -----------------------------------------------------------------------
1251 void wxPropertyGrid
::CalculateFontAndBitmapStuff( int vspacing
)
1255 m_captionFont
= wxControl
::GetFont();
1257 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1258 m_subgroup_extramargin
= x
+ (x
/2);
1261 #if wxPG_USE_RENDERER_NATIVE
1262 m_iconWidth
= wxPG_ICON_WIDTH
;
1263 #elif wxPG_ICON_WIDTH
1265 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1266 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1267 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1271 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1272 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1273 m_gutterWidth
= wxPG_GUTTER_MIN
;
1276 if ( vspacing
<= 1 ) vdiv
= 12;
1277 else if ( vspacing
>= 3 ) vdiv
= 3;
1279 m_spacingy
= m_fontHeight
/ vdiv
;
1280 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1281 m_spacingy
= wxPG_YSPACING_MIN
;
1284 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1285 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1287 m_captionFont
.SetWeight(wxBOLD
);
1288 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1290 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1293 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1294 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1297 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1299 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1300 RecalculateVirtualSize();
1302 InvalidateBestSize();
1305 // -----------------------------------------------------------------------
1307 void wxPropertyGrid
::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1313 // -----------------------------------------------------------------------
1315 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1316 int ga
= 1000, int ba
= 1000,
1317 bool forceDifferent
= false)
1324 // Recursion guard (allow 2 max)
1325 static int isinside
= 0;
1327 wxCHECK_MSG( isinside
< 3,
1329 wxT("wxPGAdjustColour should not be recursively called more than once") );
1334 int g
= src
.Green();
1337 if ( r2
>255 ) r2
= 255;
1338 else if ( r2
<0) r2
= 0;
1340 if ( g2
>255 ) g2
= 255;
1341 else if ( g2
<0) g2
= 0;
1343 if ( b2
>255 ) b2
= 255;
1344 else if ( b2
<0) b2
= 0;
1346 // Make sure they are somewhat different
1347 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1348 dst
= wxPGAdjustColour(src
,-(ra
*2));
1350 dst
= wxColour(r2
,g2
,b2
);
1352 // Recursion guard (allow 2 max)
1359 static int wxPGGetColAvg( const wxColour
& col
)
1361 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1365 void wxPropertyGrid
::RegainColours()
1367 if ( !(m_coloursCustomized
& 0x0002) )
1369 wxColour col
= wxSystemSettings
::GetColour( wxSYS_COLOUR_BTNFACE
);
1371 // Make sure colour is dark enough
1373 int colDec
= wxPGGetColAvg(col
) - 230;
1375 int colDec
= wxPGGetColAvg(col
) - 200;
1378 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1381 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1384 if ( !(m_coloursCustomized
& 0x0001) )
1385 m_colMargin
= m_colCapBack
;
1387 if ( !(m_coloursCustomized
& 0x0004) )
1394 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1395 m_colCapFore
= capForeCol
;
1396 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1399 if ( !(m_coloursCustomized
& 0x0008) )
1401 wxColour bgCol
= wxSystemSettings
::GetColour( wxSYS_COLOUR_WINDOW
);
1402 m_colPropBack
= bgCol
;
1403 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1404 if ( !m_unspecifiedAppearance
.GetBgCol().IsOk() )
1405 m_unspecifiedAppearance
.SetBgCol(bgCol
);
1408 if ( !(m_coloursCustomized
& 0x0010) )
1410 wxColour fgCol
= wxSystemSettings
::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1411 m_colPropFore
= fgCol
;
1412 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1413 if ( !m_unspecifiedAppearance
.GetFgCol().IsOk() )
1414 m_unspecifiedAppearance
.SetFgCol(fgCol
);
1417 if ( !(m_coloursCustomized
& 0x0020) )
1418 m_colSelBack
= wxSystemSettings
::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1420 if ( !(m_coloursCustomized
& 0x0040) )
1421 m_colSelFore
= wxSystemSettings
::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1423 if ( !(m_coloursCustomized
& 0x0080) )
1424 m_colLine
= m_colCapBack
;
1426 if ( !(m_coloursCustomized
& 0x0100) )
1427 m_colDisPropFore
= m_colCapFore
;
1429 m_colEmptySpace
= wxSystemSettings
::GetColour( wxSYS_COLOUR_WINDOW
);
1432 // -----------------------------------------------------------------------
1434 void wxPropertyGrid
::ResetColours()
1436 m_coloursCustomized
= 0;
1443 // -----------------------------------------------------------------------
1445 bool wxPropertyGrid
::SetFont( const wxFont
& font
)
1447 // Must disable active editor.
1450 bool res
= wxControl
::SetFont( font
);
1451 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1453 CalculateFontAndBitmapStuff( m_vspacing
);
1460 // -----------------------------------------------------------------------
1462 void wxPropertyGrid
::SetLineColour( const wxColour
& col
)
1465 m_coloursCustomized
|= 0x80;
1469 // -----------------------------------------------------------------------
1471 void wxPropertyGrid
::SetMarginColour( const wxColour
& col
)
1474 m_coloursCustomized
|= 0x01;
1478 // -----------------------------------------------------------------------
1480 void wxPropertyGrid
::SetCellBackgroundColour( const wxColour
& col
)
1482 m_colPropBack
= col
;
1483 m_coloursCustomized
|= 0x08;
1485 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1486 m_unspecifiedAppearance
.SetBgCol(col
);
1491 // -----------------------------------------------------------------------
1493 void wxPropertyGrid
::SetCellTextColour( const wxColour
& col
)
1495 m_colPropFore
= col
;
1496 m_coloursCustomized
|= 0x10;
1498 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1499 m_unspecifiedAppearance
.SetFgCol(col
);
1504 // -----------------------------------------------------------------------
1506 void wxPropertyGrid
::SetEmptySpaceColour( const wxColour
& col
)
1508 m_colEmptySpace
= col
;
1513 // -----------------------------------------------------------------------
1515 void wxPropertyGrid
::SetCellDisabledTextColour( const wxColour
& col
)
1517 m_colDisPropFore
= col
;
1518 m_coloursCustomized
|= 0x100;
1522 // -----------------------------------------------------------------------
1524 void wxPropertyGrid
::SetSelectionBackgroundColour( const wxColour
& col
)
1527 m_coloursCustomized
|= 0x20;
1531 // -----------------------------------------------------------------------
1533 void wxPropertyGrid
::SetSelectionTextColour( const wxColour
& col
)
1536 m_coloursCustomized
|= 0x40;
1540 // -----------------------------------------------------------------------
1542 void wxPropertyGrid
::SetCaptionBackgroundColour( const wxColour
& col
)
1545 m_coloursCustomized
|= 0x02;
1547 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1552 // -----------------------------------------------------------------------
1554 void wxPropertyGrid
::SetCaptionTextColour( const wxColour
& col
)
1557 m_coloursCustomized
|= 0x04;
1559 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1564 // -----------------------------------------------------------------------
1565 // wxPropertyGrid property adding and removal
1566 // -----------------------------------------------------------------------
1568 void wxPropertyGrid
::PrepareAfterItemsAdded()
1570 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1572 m_pState
->m_itemsAdded
= 0;
1574 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1575 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1577 RecalculateVirtualSize();
1579 // Fix editor position
1580 CorrectEditorWidgetPosY();
1583 // -----------------------------------------------------------------------
1584 // wxPropertyGrid property operations
1585 // -----------------------------------------------------------------------
1587 bool wxPropertyGrid
::EnsureVisible( wxPGPropArg id
)
1589 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1593 bool changed
= false;
1595 // Is it inside collapsed section?
1596 if ( !p
->IsVisible() )
1599 wxPGProperty
* parent
= p
->GetParent();
1600 wxPGProperty
* grandparent
= parent
->GetParent();
1602 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1603 Expand( grandparent
);
1611 GetViewStart(&vx
,&vy
);
1612 vy
*=wxPG_PIXELS_PER_UNIT
;
1618 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1619 m_iFlags
|= wxPG_FL_SCROLLED
;
1622 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1624 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1625 m_iFlags
|= wxPG_FL_SCROLLED
;
1635 // -----------------------------------------------------------------------
1636 // wxPropertyGrid helper methods called by properties
1637 // -----------------------------------------------------------------------
1639 // Control font changer helper.
1640 void wxPropertyGrid
::SetCurControlBoldFont()
1642 wxWindow
* editor
= GetEditorControl();
1643 editor
->SetFont( m_captionFont
);
1646 // -----------------------------------------------------------------------
1648 wxPoint wxPropertyGrid
::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1651 #if wxPG_SMALL_SCREEN
1652 // On small-screen devices, always show dialogs with default position and size.
1653 return wxDefaultPosition
;
1655 int splitterX
= GetSplitterPosition();
1659 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1661 ImprovedClientToScreen( &x
, &y
);
1663 int sw
= wxSystemSettings
::GetMetric( ::wxSYS_SCREEN_X
);
1664 int sh
= wxSystemSettings
::GetMetric( ::wxSYS_SCREEN_Y
);
1671 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1681 new_y
= y
+ m_lineHeight
;
1683 return wxPoint(new_x
,new_y
);
1687 // -----------------------------------------------------------------------
1689 wxString
& wxPropertyGrid
::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1691 if ( src_str
.empty() )
1697 bool prev_is_slash
= false;
1699 wxString
::const_iterator i
= src_str
.begin();
1703 for ( ; i
!= src_str
.end(); ++i
)
1707 if ( a
!= wxS('\\') )
1709 if ( !prev_is_slash
)
1715 if ( a
== wxS('n') )
1718 dst_str
<< wxS('\n');
1720 dst_str
<< wxS('\n');
1723 else if ( a
== wxS('t') )
1724 dst_str
<< wxS('\t');
1728 prev_is_slash
= false;
1732 if ( prev_is_slash
)
1734 dst_str
<< wxS('\\');
1735 prev_is_slash
= false;
1739 prev_is_slash
= true;
1746 // -----------------------------------------------------------------------
1748 wxString
& wxPropertyGrid
::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1750 if ( src_str
.empty() )
1756 wxString
::const_iterator i
= src_str
.begin();
1757 wxUniChar prev_a
= wxS('\0');
1761 for ( ; i
!= src_str
.end(); ++i
)
1765 if ( a
>= wxS(' ') )
1767 // This surely is not something that requires an escape sequence.
1772 // This might need...
1773 if ( a
== wxS('\r') )
1775 // DOS style line end.
1776 // Already taken care below
1778 else if ( a
== wxS('\n') )
1779 // UNIX style line end.
1780 dst_str
<< wxS("\\n");
1781 else if ( a
== wxS('\t') )
1783 dst_str
<< wxS('\t');
1786 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1796 // -----------------------------------------------------------------------
1798 wxPGProperty
* wxPropertyGrid
::DoGetItemAtY( int y
) const
1805 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1808 // -----------------------------------------------------------------------
1809 // wxPropertyGrid graphics related methods
1810 // -----------------------------------------------------------------------
1812 void wxPropertyGrid
::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1817 // Don't paint after destruction has begun
1818 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1821 // Find out where the window is scrolled to
1822 int vx
,vy
; // Top left corner of client
1823 GetViewStart(&vx
,&vy
);
1824 vy
*= wxPG_PIXELS_PER_UNIT
;
1826 // Update everything inside the box
1827 wxRect r
= GetUpdateRegion().GetBox();
1831 // FIXME: This is just a workaround for a bug that causes splitters not
1832 // to paint when other windows are being dragged over the grid.
1834 r
.width
= GetClientSize().x
;
1837 r
.height
= GetClientSize().y
;
1839 // Repaint this rectangle
1840 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1842 // We assume that the size set when grid is shown
1843 // is what is desired.
1844 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1847 // -----------------------------------------------------------------------
1849 void wxPropertyGrid
::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1850 wxPGProperty
* property
) const
1852 // Prepare rectangle to be used
1854 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1855 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1857 #if (wxPG_USE_RENDERER_NATIVE)
1859 #elif wxPG_ICON_WIDTH
1860 // Drawing expand/collapse button manually
1861 dc
.SetPen(m_colPropFore
);
1862 if ( property
->IsCategory() )
1863 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1865 dc
.SetBrush(m_colPropBack
);
1867 dc
.DrawRectangle( r
);
1868 int _y
= r
.y
+(m_iconWidth
/2);
1869 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1874 if ( property
->IsExpanded() )
1876 // wxRenderer functions are non-mutating in nature, so it
1877 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1878 // Hopefully this does not cause problems.
1879 #if (wxPG_USE_RENDERER_NATIVE)
1880 wxRendererNative
::Get().DrawTreeItemButton(
1886 #elif wxPG_ICON_WIDTH
1895 #if (wxPG_USE_RENDERER_NATIVE)
1896 wxRendererNative
::Get().DrawTreeItemButton(
1902 #elif wxPG_ICON_WIDTH
1903 int _x
= r
.x
+(m_iconWidth
/2);
1904 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1910 #if (wxPG_USE_RENDERER_NATIVE)
1912 #elif wxPG_ICON_WIDTH
1915 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1919 // -----------------------------------------------------------------------
1922 // This is the one called by OnPaint event handler and others.
1923 // topy and bottomy are already unscrolled (ie. physical)
1925 void wxPropertyGrid
::DrawItems( wxDC
& dc
,
1926 unsigned int topItemY
,
1927 unsigned int bottomItemY
,
1928 const wxRect
* itemsRect
)
1932 bottomItemY
< topItemY
||
1936 m_pState
->EnsureVirtualHeight();
1938 wxRect tempItemsRect
;
1941 tempItemsRect
= wxRect(0, topItemY
,
1944 itemsRect
= &tempItemsRect
;
1948 GetViewStart(&vx
, &vy
);
1949 vx
*= wxPG_PIXELS_PER_UNIT
;
1950 vy
*= wxPG_PIXELS_PER_UNIT
;
1952 // itemRect is in virtual grid space
1953 wxRect
drawRect(itemsRect
->x
- vx
,
1958 // items added check
1959 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1961 int paintFinishY
= 0;
1963 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1966 bool isBuffered
= false;
1968 #if wxPG_DOUBLE_BUFFER
1969 wxMemoryDC
* bufferDC
= NULL
;
1971 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1973 if ( !m_doubleBuffer
)
1975 paintFinishY
= itemsRect
->y
;
1980 bufferDC
= new wxMemoryDC();
1982 // If nothing was changed, then just copy from double-buffer
1983 bufferDC
->SelectObject( *m_doubleBuffer
);
1993 // paintFinishY and drawBottomY are in buffer/physical space
1994 paintFinishY
= DoDrawItems( *dcPtr
, itemsRect
, isBuffered
);
1995 int drawBottomY
= itemsRect
->y
+ itemsRect
->height
- vy
;
1997 // Clear area beyond last painted property
1998 if ( paintFinishY
< drawBottomY
)
2000 dcPtr
->SetPen(m_colEmptySpace
);
2001 dcPtr
->SetBrush(m_colEmptySpace
);
2002 dcPtr
->DrawRectangle(0, paintFinishY
,
2008 #if wxPG_DOUBLE_BUFFER
2011 dc
.Blit( drawRect
.x
, drawRect
.y
, drawRect
.width
,
2013 bufferDC
, 0, 0, wxCOPY
);
2020 // Just clear the area
2021 dc
.SetPen(m_colEmptySpace
);
2022 dc
.SetBrush(m_colEmptySpace
);
2023 dc
.DrawRectangle(drawRect
);
2027 // -----------------------------------------------------------------------
2029 int wxPropertyGrid
::DoDrawItems( wxDC
& dc
,
2030 const wxRect
* itemsRect
,
2031 bool isBuffered
) const
2033 const wxPGProperty
* firstItem
;
2034 const wxPGProperty
* lastItem
;
2036 firstItem
= DoGetItemAtY(itemsRect
->y
);
2037 lastItem
= DoGetItemAtY(itemsRect
->y
+itemsRect
->height
-1);
2040 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
2042 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
2043 return itemsRect
->y
;
2045 wxCHECK_MSG( !m_pState
->m_itemsAdded
, itemsRect
->y
,
2047 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2049 int lh
= m_lineHeight
;
2052 int lastItemBottomY
;
2054 firstItemTopY
= itemsRect
->y
;
2055 lastItemBottomY
= itemsRect
->y
+ itemsRect
->height
;
2057 // Align y coordinates to item boundaries
2058 firstItemTopY
-= firstItemTopY
% lh
;
2059 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2060 lastItemBottomY
-= 1;
2062 // Entire range outside scrolled, visible area?
2063 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
2064 lastItemBottomY
<= 0 )
2065 return itemsRect
->y
;
2067 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
2069 "invalid y values" );
2072 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
2073 "height=%i (ch=%i), itemsRect = 0x%lX )",
2074 firstItem->GetLabel().c_str(),
2075 lastItem->GetLabel().c_str(),
2076 (int)(lastItemBottomY - firstItemTopY),
2078 (unsigned long)&itemsRect );
2083 long windowStyle
= m_windowStyle
;
2088 // With wxPG_DOUBLE_BUFFER, do double buffering
2089 // - buffer's y = 0, so align itemsRect and coordinates to that
2091 #if wxPG_DOUBLE_BUFFER
2098 xRelMod
= itemsRect
->x
;
2099 yRelMod
= itemsRect
->y
;
2102 // itemsRect conversion
2107 firstItemTopY
-= yRelMod
;
2108 lastItemBottomY
-= yRelMod
;
2111 wxUnusedVar(isBuffered
);
2114 int x
= m_marginWidth
- xRelMod
;
2116 wxFont normalFont
= GetFont();
2118 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2120 bool isPgEnabled
= IsEnabled();
2123 // Prepare some pens and brushes that are often changed to.
2126 wxBrush
marginBrush(m_colMargin
);
2127 wxPen
marginPen(m_colMargin
);
2128 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2129 wxPen
linepen(m_colLine
,1,wxSOLID
);
2131 wxColour selBackCol
;
2133 selBackCol
= m_colSelBack
;
2135 selBackCol
= m_colMargin
;
2137 // pen that has same colour as text
2138 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2141 // Clear margin with background colour
2143 dc
.SetBrush( marginBrush
);
2144 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2146 dc
.SetPen( *wxTRANSPARENT_PEN
);
2147 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2150 const wxPGProperty
* firstSelected
= GetSelection();
2151 const wxPropertyGridPageState
* state
= m_pState
;
2152 const wxArrayInt
& colWidths
= state
->m_colWidths
;
2154 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2155 bool wasSelectedPainted
= false;
2158 // TODO: Only render columns that are within clipping region.
2160 dc
.SetFont(normalFont
);
2162 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2163 int endScanBottomY
= lastItemBottomY
+ lh
;
2164 int y
= firstItemTopY
;
2167 // Pregenerate list of visible properties.
2168 wxArrayPGProperty visPropArray
;
2169 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2171 for ( ; !it
.AtEnd(); it
.Next() )
2173 const wxPGProperty
* p
= *it
;
2175 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2177 visPropArray
.push_back((wxPGProperty
*)p
);
2179 if ( y
> endScanBottomY
)
2186 visPropArray
.push_back(NULL
);
2188 wxPGProperty
* nextP
= visPropArray
[0];
2190 int gridWidth
= state
->m_width
;
2193 for ( unsigned int arrInd
=1;
2194 nextP
&& y
<= lastItemBottomY
;
2197 wxPGProperty
* p
= nextP
;
2198 nextP
= visPropArray
[arrInd
];
2200 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2201 int textMarginHere
= x
;
2202 int renderFlags
= 0;
2204 int greyDepth
= m_marginWidth
;
2205 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2206 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2208 int greyDepthX
= greyDepth
- xRelMod
;
2210 // Use basic depth if in non-categoric mode and parent is base array.
2211 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2213 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2216 // Paint margin area
2217 dc
.SetBrush(marginBrush
);
2218 dc
.SetPen(marginPen
);
2219 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2221 dc
.SetPen( linepen
);
2227 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2228 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2229 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2231 // Is this or its parent themed?
2232 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2233 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2234 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2236 bool suppressMarginEdge
= false;
2238 if (!suppressMarginEdge
)
2239 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2242 // Blank out the margin edge
2243 dc
.SetPen(wxPen(GetBackgroundColour()));
2244 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2245 dc
.SetPen( linepen
);
2252 for ( si
=0; si
<colWidths
.size(); si
++ )
2254 sx
+= colWidths
[si
];
2255 dc
.DrawLine( sx
, y
, sx
, y2
);
2258 // Horizontal Line, below
2259 // (not if both this and next is category caption)
2260 if ( p
->IsCategory() &&
2261 nextP
&& nextP
->IsCategory() )
2262 dc
.SetPen(m_colCapBack
);
2264 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2267 // Need to override row colours?
2271 bool isSelected
= state
->DoIsPropertySelected(p
);
2275 // Disabled may get different colour.
2276 if ( !p
->IsEnabled() )
2278 renderFlags
|= wxPGCellRenderer
::Disabled
|
2279 wxPGCellRenderer
::DontUseCellFgCol
;
2280 rowFgCol
= m_colDisPropFore
;
2285 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2286 if ( p
== firstSelected
)
2287 wasSelectedPainted
= true;
2290 renderFlags
|= wxPGCellRenderer
::Selected
;
2292 if ( !p
->IsCategory() )
2294 renderFlags
|= wxPGCellRenderer
::DontUseCellFgCol
|
2295 wxPGCellRenderer
::DontUseCellBgCol
;
2297 if ( reallyFocused
&& p
== firstSelected
)
2299 rowFgCol
= m_colSelFore
;
2300 rowBgCol
= selBackCol
;
2302 else if ( isPgEnabled
)
2304 rowFgCol
= m_colPropFore
;
2305 if ( p
== firstSelected
)
2306 rowBgCol
= m_colMargin
;
2308 rowBgCol
= selBackCol
;
2312 rowFgCol
= m_colDisPropFore
;
2313 rowBgCol
= selBackCol
;
2320 if ( rowBgCol
.IsOk() )
2321 rowBgBrush
= wxBrush(rowBgCol
);
2323 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2324 renderFlags
= renderFlags
& ~wxPGCellRenderer
::DontUseCellColours
;
2327 // Fill additional margin area with background colour of first cell
2328 if ( greyDepthX
< textMarginHere
)
2330 if ( !(renderFlags
& wxPGCellRenderer
::DontUseCellBgCol
) )
2332 wxPGCell
& cell
= p
->GetCell(0);
2333 rowBgCol
= cell
.GetBgCol();
2334 rowBgBrush
= wxBrush(rowBgCol
);
2336 dc
.SetBrush(rowBgBrush
);
2337 dc
.SetPen(rowBgCol
);
2338 dc
.DrawRectangle(greyDepthX
+1, y
,
2339 textMarginHere
-greyDepthX
, lh
-1);
2342 bool fontChanged
= false;
2344 // Expander button rectangle
2345 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2350 // Default cell rect fill the entire row
2351 wxRect
cellRect(greyDepthX
, y
,
2352 gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2354 bool isCategory
= p
->IsCategory();
2358 dc
.SetFont(m_captionFont
);
2361 if ( renderFlags
& wxPGCellRenderer
::DontUseCellBgCol
)
2363 dc
.SetBrush(rowBgBrush
);
2364 dc
.SetPen(rowBgCol
);
2367 if ( renderFlags
& wxPGCellRenderer
::DontUseCellFgCol
)
2369 dc
.SetTextForeground(rowFgCol
);
2374 // Fine tune button rectangle to actually fit the cell
2375 if ( butRect
.x
> 0 )
2376 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2378 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&&
2379 (windowStyle
& wxPG_BOLD_MODIFIED
) )
2381 dc
.SetFont(m_captionFont
);
2385 // Magic fine-tuning for non-category rows
2389 int firstCellWidth
= colWidths
[0] - (greyDepthX
- m_marginWidth
);
2390 int firstCellX
= cellRect
.x
;
2392 // Calculate cellRect.x for the last cell
2393 unsigned int ci
= 0;
2395 for ( ci
=0; ci
<colWidths
.size(); ci
++ )
2396 cellX
+= colWidths
[ci
];
2399 // Draw cells from back to front so that we can easily tell if the
2400 // cell on the right was empty from text
2401 bool prevFilled
= true;
2402 ci
= colWidths
.size();
2411 textXAdd
= textMarginHere
- greyDepthX
;
2412 cellRect
.width
= firstCellWidth
;
2413 cellRect
.x
= firstCellX
;
2417 int colWidth
= colWidths
[ci
];
2418 cellRect
.width
= colWidth
;
2419 cellRect
.x
-= colWidth
;
2422 // Merge with column to the right?
2423 if ( !prevFilled
&& isCategory
)
2425 cellRect
.width
+= colWidths
[ci
+1];
2429 cellRect
.width
-= 1;
2431 wxWindow
* cellEditor
= NULL
;
2432 int cellRenderFlags
= renderFlags
;
2434 // Tree Item Button (must be drawn before clipping is set up)
2435 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2436 DrawExpanderButton( dc
, butRect
, p
);
2439 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2441 if ( p
== firstSelected
)
2443 if ( ci
== 1 && m_wndEditor
)
2444 cellEditor
= m_wndEditor
;
2445 else if ( ci
== m_selColumn
&& m_labelEditor
)
2446 cellEditor
= m_labelEditor
;
2451 wxColour editorBgCol
=
2452 cellEditor
->GetBackgroundColour();
2453 dc
.SetBrush(editorBgCol
);
2454 dc
.SetPen(editorBgCol
);
2455 dc
.SetTextForeground(m_colPropFore
);
2456 dc
.DrawRectangle(cellRect
);
2458 if ( m_dragStatus
!= 0 ||
2459 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2464 dc
.SetBrush(m_colPropBack
);
2465 dc
.SetPen(m_colPropBack
);
2466 if ( p
->IsEnabled() )
2467 dc
.SetTextForeground(m_colPropFore
);
2469 dc
.SetTextForeground(m_colDisPropFore
);
2474 if ( renderFlags
& wxPGCellRenderer
::DontUseCellBgCol
)
2476 dc
.SetBrush(rowBgBrush
);
2477 dc
.SetPen(rowBgCol
);
2480 if ( renderFlags
& wxPGCellRenderer
::DontUseCellFgCol
)
2482 dc
.SetTextForeground(rowFgCol
);
2486 dc
.SetClippingRegion(cellRect
);
2488 cellRect
.x
+= textXAdd
;
2489 cellRect
.width
-= textXAdd
;
2494 wxPGCellRenderer
* renderer
;
2495 int cmnVal
= p
->GetCommonValue();
2496 if ( cmnVal
== -1 || ci
!= 1 )
2498 renderer
= p
->GetCellRenderer(ci
);
2499 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2505 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2506 prevFilled
= renderer
->Render(dc
, cellRect
, this,
2516 dc
.DestroyClippingRegion(); // Is this really necessary?
2521 dc
.SetFont(normalFont
);
2526 // Refresh editor controls (seems not needed on msw)
2527 // NOTE: This code is mandatory for GTK!
2528 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2529 if ( wasSelectedPainted
)
2532 m_wndEditor
->Refresh();
2534 m_wndEditor2
->Refresh();
2541 // -----------------------------------------------------------------------
2543 wxRect wxPropertyGrid
::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2547 if ( m_width
< 10 || m_height
< 10 ||
2548 !m_pState
->m_properties
->GetChildCount() ||
2550 return wxRect(0,0,0,0);
2555 // Return rect which encloses the given property range
2556 // (in logical grid coordinates)
2559 int visTop
= p1
->GetY();
2562 visBottom
= p2
->GetY() + m_lineHeight
;
2564 visBottom
= m_height
+ visTop
;
2566 // If seleced property is inside the range, we'll extend the range to include
2568 wxPGProperty
* selected
= GetSelection();
2571 int selectedY
= selected
->GetY();
2572 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2574 wxWindow
* editor
= GetEditorControl();
2577 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2578 if ( visBottom2
> visBottom
)
2579 visBottom
= visBottom2
;
2584 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2587 // -----------------------------------------------------------------------
2589 void wxPropertyGrid
::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2594 if ( m_pState
->m_itemsAdded
)
2595 PrepareAfterItemsAdded();
2597 wxRect r
= GetPropertyRect(p1
, p2
);
2600 // Convert rectangle from logical grid coordinates to physical ones
2602 GetViewStart(&vx
, &vy
);
2603 vx
*= wxPG_PIXELS_PER_UNIT
;
2604 vy
*= wxPG_PIXELS_PER_UNIT
;
2611 // -----------------------------------------------------------------------
2613 void wxPropertyGrid
::RefreshProperty( wxPGProperty
* p
)
2615 if ( m_pState
->DoIsPropertySelected(p
) )
2617 // NB: We must copy the selection.
2618 wxArrayPGProperty selection
= m_pState
->m_selection
;
2619 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2622 DrawItemAndChildren(p
);
2625 // -----------------------------------------------------------------------
2627 void wxPropertyGrid
::DrawItemAndValueRelated( wxPGProperty
* p
)
2632 // Draw item, children, and parent too, if it is not category
2633 wxPGProperty
* parent
= p
->GetParent();
2636 !parent
->IsCategory() &&
2637 parent
->GetParent() )
2640 parent
= parent
->GetParent();
2643 DrawItemAndChildren(p
);
2646 void wxPropertyGrid
::DrawItemAndChildren( wxPGProperty
* p
)
2648 wxCHECK_RET( p
, wxT("invalid property id") );
2650 // Do not draw if in non-visible page
2651 if ( p
->GetParentState() != m_pState
)
2654 // do not draw a single item if multiple pending
2655 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2658 // Update child control.
2659 wxPGProperty
* selected
= GetSelection();
2660 if ( selected
&& selected
->GetParent() == p
)
2663 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2665 DrawItems(p
, lastDrawn
);
2668 // -----------------------------------------------------------------------
2670 void wxPropertyGrid
::Refresh( bool WXUNUSED(eraseBackground
),
2671 const wxRect
*rect
)
2673 PrepareAfterItemsAdded();
2675 wxWindow
::Refresh(false, rect
);
2677 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2678 // I think this really helps only GTK+1.2
2679 if ( m_wndEditor
) m_wndEditor
->Refresh();
2680 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2684 // -----------------------------------------------------------------------
2685 // wxPropertyGrid global operations
2686 // -----------------------------------------------------------------------
2688 void wxPropertyGrid
::Clear()
2690 m_pState
->DoClear();
2696 RecalculateVirtualSize();
2698 // Need to clear some area at the end
2700 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2703 // -----------------------------------------------------------------------
2705 bool wxPropertyGrid
::EnableCategories( bool enable
)
2712 // Enable categories
2715 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2720 // Disable categories
2722 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2725 if ( !m_pState
->EnableCategories(enable
) )
2730 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2732 m_pState
->m_itemsAdded
= 1; // force
2733 PrepareAfterItemsAdded();
2737 m_pState
->m_itemsAdded
= 1;
2739 // No need for RecalculateVirtualSize() here - it is already called in
2740 // wxPropertyGridPageState method above.
2747 // -----------------------------------------------------------------------
2749 void wxPropertyGrid
::SwitchState( wxPropertyGridPageState
* pNewState
)
2751 wxASSERT( pNewState
);
2752 wxASSERT( pNewState
->GetGrid() );
2754 if ( pNewState
== m_pState
)
2757 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2759 // Call ClearSelection() instead of DoClearSelection()
2760 // so that selection clear events are not sent.
2763 m_pState
->m_selection
= oldSelection
;
2765 bool orig_mode
= m_pState
->IsInNonCatMode();
2766 bool new_state_mode
= pNewState
->IsInNonCatMode();
2768 m_pState
= pNewState
;
2771 int pgWidth
= GetClientSize().x
;
2772 if ( HasVirtualWidth() )
2774 int minWidth
= pgWidth
;
2775 if ( pNewState
->m_width
< minWidth
)
2777 pNewState
->m_width
= minWidth
;
2778 pNewState
->CheckColumnWidths();
2784 // Just in case, fully re-center splitter
2785 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2786 // pNewState->m_fSplitterX = -1.0;
2788 pNewState
->OnClientWidthChange(pgWidth
,
2789 pgWidth
- pNewState
->m_width
);
2794 // If necessary, convert state to correct mode.
2795 if ( orig_mode
!= new_state_mode
)
2797 // This should refresh as well.
2798 EnableCategories( orig_mode?
false:true );
2800 else if ( !m_frozen
)
2802 // Refresh, if not frozen.
2803 m_pState
->PrepareAfterItemsAdded();
2805 // Reselect (Use SetSelection() instead of Do-variant so that
2806 // events won't be sent).
2807 SetSelection(m_pState
->m_selection
);
2809 RecalculateVirtualSize(0);
2813 m_pState
->m_itemsAdded
= 1;
2816 // -----------------------------------------------------------------------
2818 // Call to SetSplitterPosition will always disable splitter auto-centering
2819 // if parent window is shown.
2820 void wxPropertyGrid
::DoSetSplitterPosition( int newxpos
,
2824 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2827 wxPropertyGridPageState
* state
= m_pState
;
2829 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2830 state
->m_dontCenterSplitter
= true;
2832 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2834 if ( flags
& wxPG_SPLITTER_REFRESH
)
2836 if ( GetSelection() )
2837 CorrectEditorWidgetSizeX();
2845 // -----------------------------------------------------------------------
2847 void wxPropertyGrid
::ResetColumnSizes( bool enableAutoResizing
)
2849 wxPropertyGridPageState
* state
= m_pState
;
2851 state
->ResetColumnSizes(0);
2853 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2854 m_pState
->m_dontCenterSplitter
= false;
2857 // -----------------------------------------------------------------------
2859 void wxPropertyGrid
::CenterSplitter( bool enableAutoResizing
)
2861 SetSplitterPosition( m_width
/2 );
2862 if ( enableAutoResizing
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2863 m_pState
->m_dontCenterSplitter
= false;
2866 // -----------------------------------------------------------------------
2867 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2868 // -----------------------------------------------------------------------
2870 // Returns nearest paint visible property (such that will be painted unless
2871 // window is scrolled or resized). If given property is paint visible, then
2872 // it itself will be returned
2873 wxPGProperty
* wxPropertyGrid
::GetNearestPaintVisible( wxPGProperty
* p
) const
2875 int vx
,vy1
;// Top left corner of client
2876 GetViewStart(&vx
,&vy1
);
2877 vy1
*= wxPG_PIXELS_PER_UNIT
;
2879 int vy2
= vy1
+ m_height
;
2880 int propY
= p
->GetY2(m_lineHeight
);
2882 if ( (propY
+ m_lineHeight
) < vy1
)
2885 return DoGetItemAtY( vy1
);
2887 else if ( propY
> vy2
)
2890 return DoGetItemAtY( vy2
);
2893 // Itself paint visible
2898 // -----------------------------------------------------------------------
2899 // Methods related to change in value, value modification and sending events
2900 // -----------------------------------------------------------------------
2902 // commits any changes in editor of selected property
2903 // return true if validation did not fail
2904 // flags are same as with DoSelectProperty
2905 bool wxPropertyGrid
::CommitChangesFromEditor( wxUint32 flags
)
2907 // Committing already?
2908 if ( m_inCommitChangesFromEditor
)
2911 // Don't do this if already processing editor event. It might
2912 // induce recursive dialogs and crap like that.
2913 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2915 if ( m_inDoPropertyChanged
)
2921 wxPGProperty
* selected
= GetSelection();
2924 IsEditorsValueModified() &&
2925 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2928 m_inCommitChangesFromEditor
= true;
2930 wxVariant
variant(selected
->GetValueRef());
2931 bool valueIsPending
= false;
2933 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2934 // due to another window getting focus
2935 wxWindow
* oldFocus
= m_curFocused
;
2937 bool validationFailure
= false;
2938 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ?
true : false;
2940 m_chgInfo_changedProperty
= NULL
;
2942 // If truly modified, schedule value as pending.
2943 if ( selected
->GetEditorClass()->
2944 GetValueFromControl( variant
,
2946 GetEditorControl() ) )
2948 if ( DoEditorValidate() &&
2949 PerformValidation(selected
, variant
) )
2951 valueIsPending
= true;
2955 validationFailure
= true;
2960 EditorsValueWasNotModified();
2963 m_inCommitChangesFromEditor
= false;
2967 if ( validationFailure
&& !forceSuccess
)
2971 oldFocus
->SetFocus();
2972 m_curFocused
= oldFocus
;
2975 res
= OnValidationFailure(selected
, variant
);
2977 // Now prevent further validation failure messages
2980 EditorsValueWasNotModified();
2981 OnValidationFailureReset(selected
);
2984 else if ( valueIsPending
)
2986 DoPropertyChanged( selected
, flags
);
2987 EditorsValueWasNotModified();
2996 // -----------------------------------------------------------------------
2998 bool wxPropertyGrid
::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
3002 // Runs all validation functionality.
3003 // Returns true if value passes all tests.
3006 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
3007 m_validationInfo
.m_isFailing
= true;
3010 // Variant list a special value that cannot be validated
3012 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3014 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
3019 // Adapt list to child values, if necessary
3020 wxVariant listValue
= pendingValue
;
3021 wxVariant
* pPendingValue
= &pendingValue
;
3022 wxVariant
* pList
= NULL
;
3024 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
3025 // string value, then we need treat as it was changed instead
3026 // (or, in addition, as is the case with composite string parent).
3027 // This includes creating list variant for child values.
3029 wxPGProperty
* pwc
= p
->GetParent();
3030 wxPGProperty
* changedProperty
= p
;
3031 wxPGProperty
* baseChangedProperty
= changedProperty
;
3032 wxVariant bcpPendingList
;
3034 listValue
= pendingValue
;
3035 listValue
.SetName(p
->GetBaseName());
3038 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
3040 wxVariantList tempList
;
3041 wxVariant
lv(tempList
, pwc
->GetBaseName());
3042 lv
.Append(listValue
);
3044 pPendingValue
= &listValue
;
3046 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
3048 baseChangedProperty
= pwc
;
3049 bcpPendingList
= lv
;
3052 changedProperty
= pwc
;
3053 pwc
= pwc
->GetParent();
3057 wxPGProperty
* evtChangingProperty
= changedProperty
;
3059 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
3061 value
= *pPendingValue
;
3065 // Convert list to child values
3066 pList
= pPendingValue
;
3067 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
3070 wxVariant evtChangingValue
= value
;
3072 if ( flags
& SendEvtChanging
)
3074 // FIXME: After proper ValueToString()s added, remove
3075 // this. It is just a temporary fix, as evt_changing
3076 // will simply not work for wxPG_PROP_COMPOSED_VALUE
3077 // (unless it is selected, and textctrl editor is open).
3078 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3080 evtChangingProperty
= baseChangedProperty
;
3081 if ( evtChangingProperty
!= p
)
3083 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
3087 evtChangingValue
= pendingValue
;
3091 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3093 if ( changedProperty
== GetSelection() )
3095 wxWindow
* editor
= GetEditorControl();
3096 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
3097 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
3101 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
3106 wxASSERT( m_chgInfo_changedProperty
== NULL
);
3107 m_chgInfo_changedProperty
= changedProperty
;
3108 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
3109 m_chgInfo_pendingValue
= value
;
3112 m_chgInfo_valueList
= *pList
;
3114 m_chgInfo_valueList
.MakeNull();
3116 // If changedProperty is not property which value was edited,
3117 // then call wxPGProperty::ValidateValue() for that as well.
3118 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3120 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3124 if ( flags
& SendEvtChanging
)
3126 // SendEvent returns true if event was vetoed
3127 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3128 &evtChangingValue
) )
3132 if ( flags
& IsStandaloneValidation
)
3134 // If called in 'generic' context, we need to reset
3135 // m_chgInfo_changedProperty and write back translated value.
3136 m_chgInfo_changedProperty
= NULL
;
3137 pendingValue
= value
;
3140 m_validationInfo
.m_isFailing
= false;
3145 // -----------------------------------------------------------------------
3148 wxStatusBar
* wxPropertyGrid
::GetStatusBar()
3150 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3151 if ( topWnd
&& topWnd
->IsKindOf(CLASSINFO(wxFrame
)) )
3153 wxFrame
* pFrame
= wxStaticCast(topWnd
, wxFrame
);
3155 return pFrame
->GetStatusBar();
3161 // -----------------------------------------------------------------------
3163 void wxPropertyGrid
::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3169 if ( !wxPGGlobalVars
->m_offline
)
3171 wxStatusBar
* pStatusBar
= GetStatusBar();
3174 pStatusBar
->SetStatusText(msg
);
3180 ::wxMessageBox(msg
, _("Property Error"));
3183 // -----------------------------------------------------------------------
3185 void wxPropertyGrid
::DoHidePropertyError( wxPGProperty
* WXUNUSED(property
) )
3188 if ( !wxPGGlobalVars
->m_offline
)
3190 wxStatusBar
* pStatusBar
= GetStatusBar();
3193 pStatusBar
->SetStatusText(wxEmptyString
);
3200 // -----------------------------------------------------------------------
3202 bool wxPropertyGrid
::OnValidationFailure( wxPGProperty
* property
,
3203 wxVariant
& invalidValue
)
3205 if ( m_inOnValidationFailure
)
3208 m_inOnValidationFailure
= true;
3209 wxON_BLOCK_EXIT_SET(m_inOnValidationFailure
, false);
3211 wxWindow
* editor
= GetEditorControl();
3212 int vfb
= m_validationInfo
.m_failureBehavior
;
3214 if ( m_inDoSelectProperty
)
3216 // When property selection is being changed, do not display any
3217 // messages, if some were already shown for this property.
3218 if ( property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3220 m_validationInfo
.m_failureBehavior
=
3221 vfb
& ~(wxPG_VFB_SHOW_MESSAGE
|
3222 wxPG_VFB_SHOW_MESSAGEBOX
|
3223 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
);
3227 // First call property's handler
3228 property
->OnValidationFailure(invalidValue
);
3230 bool res
= DoOnValidationFailure(property
, invalidValue
);
3233 // For non-wxTextCtrl editors, we do need to revert the value
3234 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3235 property
== GetSelection() )
3237 property
->GetEditorClass()->UpdateControl(property
, editor
);
3240 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3245 bool wxPropertyGrid
::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3247 int vfb
= m_validationInfo
.m_failureBehavior
;
3249 if ( vfb
& wxPG_VFB_BEEP
)
3252 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3253 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3255 unsigned int colCount
= m_pState
->GetColumnCount();
3257 // We need backup marked property's cells
3258 m_propCellsBackup
= property
->m_cells
;
3260 wxColour vfbFg
= *wxWHITE
;
3261 wxColour vfbBg
= *wxRED
;
3263 property
->EnsureCells(colCount
);
3265 for ( unsigned int i
=0; i
<colCount
; i
++ )
3267 wxPGCell
& cell
= property
->m_cells
[i
];
3268 cell
.SetFgCol(vfbFg
);
3269 cell
.SetBgCol(vfbBg
);
3272 DrawItemAndChildren(property
);
3274 if ( property
== GetSelection() )
3276 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3278 wxWindow
* editor
= GetEditorControl();
3281 editor
->SetForegroundColour(vfbFg
);
3282 editor
->SetBackgroundColour(vfbBg
);
3287 if ( vfb
& (wxPG_VFB_SHOW_MESSAGE
|
3288 wxPG_VFB_SHOW_MESSAGEBOX
|
3289 wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
) )
3291 wxString msg
= m_validationInfo
.m_failureMessage
;
3294 msg
= _("You have entered invalid value. Press ESC to cancel editing.");
3297 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3299 if ( !wxPGGlobalVars
->m_offline
)
3301 wxStatusBar
* pStatusBar
= GetStatusBar();
3303 pStatusBar
->SetStatusText(msg
);
3308 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3309 DoShowPropertyError(property
, msg
);
3311 if ( vfb
& wxPG_VFB_SHOW_MESSAGEBOX
)
3312 ::wxMessageBox(msg
, _("Property Error"));
3315 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ?
false : true;
3318 // -----------------------------------------------------------------------
3320 void wxPropertyGrid
::DoOnValidationFailureReset( wxPGProperty
* property
)
3322 int vfb
= m_validationInfo
.m_failureBehavior
;
3324 if ( vfb
& wxPG_VFB_MARK_CELL
)
3327 property
->m_cells
= m_propCellsBackup
;
3329 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3331 if ( property
== GetSelection() && GetEditorControl() )
3333 // Calling this will recreate the control, thus resetting its colour
3334 RefreshProperty(property
);
3338 DrawItemAndChildren(property
);
3343 if ( vfb
& wxPG_VFB_SHOW_MESSAGE_ON_STATUSBAR
)
3345 if ( !wxPGGlobalVars
->m_offline
)
3347 wxStatusBar
* pStatusBar
= GetStatusBar();
3349 pStatusBar
->SetStatusText(wxEmptyString
);
3354 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3356 DoHidePropertyError(property
);
3359 m_validationInfo
.m_isFailing
= false;
3362 // -----------------------------------------------------------------------
3364 // flags are same as with DoSelectProperty
3365 bool wxPropertyGrid
::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3367 if ( m_inDoPropertyChanged
)
3370 m_inDoPropertyChanged
= true;
3371 wxON_BLOCK_EXIT_SET(m_inDoPropertyChanged
, false);
3373 wxPGProperty
* selected
= GetSelection();
3375 m_pState
->m_anyModified
= 1;
3377 // If property's value is being changed, assume it is valid
3378 OnValidationFailureReset(selected
);
3380 // Maybe need to update control
3381 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3383 // These values were calculated in PerformValidation()
3384 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3385 wxVariant value
= m_chgInfo_pendingValue
;
3387 wxPGProperty
* topPaintedProperty
= changedProperty
;
3389 while ( !topPaintedProperty
->IsCategory() &&
3390 !topPaintedProperty
->IsRoot() )
3392 topPaintedProperty
= topPaintedProperty
->GetParent();
3395 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3397 // NB: Call GetEditorControl() as late as possible, because OnSetValue()
3398 // and perhaps other user-defined virtual functions may change it.
3399 wxWindow
* editor
= GetEditorControl();
3401 // Set as Modified (not if dragging just began)
3402 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3404 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3405 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3408 SetCurControlBoldFont();
3414 // Propagate updates to parent(s)
3416 wxPGProperty
* prevPwc
= NULL
;
3418 while ( prevPwc
!= topPaintedProperty
)
3420 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3422 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3425 SetCurControlBoldFont();
3429 pwc
= pwc
->GetParent();
3432 // Draw the actual property
3433 DrawItemAndChildren( topPaintedProperty
);
3436 // If value was set by wxPGProperty::OnEvent, then update the editor
3438 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3444 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3445 if ( m_wndEditor
) m_wndEditor
->Refresh();
3446 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3451 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3453 // If top parent has composite string value, then send to child parents,
3454 // starting from baseChangedProperty.
3455 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3457 pwc
= m_chgInfo_baseChangedProperty
;
3459 while ( pwc
!= changedProperty
)
3461 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3462 pwc
= pwc
->GetParent();
3466 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3471 // -----------------------------------------------------------------------
3473 bool wxPropertyGrid
::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3475 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3477 m_chgInfo_changedProperty
= NULL
;
3479 if ( PerformValidation(p
, newValue
) )
3481 DoPropertyChanged(p
);
3486 OnValidationFailure(p
, newValue
);
3492 // -----------------------------------------------------------------------
3494 wxVariant wxPropertyGrid
::GetUncommittedPropertyValue()
3496 wxPGProperty
* prop
= GetSelectedProperty();
3499 return wxNullVariant
;
3501 wxTextCtrl
* tc
= GetEditorTextCtrl();
3502 wxVariant value
= prop
->GetValue();
3504 if ( !tc
|| !IsEditorsValueModified() )
3507 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3510 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3511 return prop
->GetValue();
3516 // -----------------------------------------------------------------------
3518 // Runs wxValidator for the selected property
3519 bool wxPropertyGrid
::DoEditorValidate()
3521 #if wxUSE_VALIDATORS
3522 wxRecursionGuard
guard(m_validatingEditor
);
3523 if ( guard
.IsInside() )
3526 wxPGProperty
* selected
= GetSelection();
3529 wxWindow
* wnd
= GetEditorControl();
3531 wxValidator
* validator
= selected
->GetValidator();
3532 if ( validator
&& wnd
)
3534 validator
->SetWindow(wnd
);
3535 if ( !validator
->Validate(this) )
3543 // -----------------------------------------------------------------------
3545 bool wxPropertyGrid
::HandleCustomEditorEvent( wxEvent
&event
)
3548 // NB: We should return true if the event was recognized as
3549 // a dedicated wxPropertyGrid event, and as such was
3550 // either properly handled or ignored.
3553 // It is possible that this handler receives event even before
3554 // the control has been properly initialized. Let's skip the
3555 // event handling in that case.
3559 // Don't care about the event if it originated from the
3560 // 'label editor'. In this function we only care about the
3561 // property value editor.
3562 if ( m_labelEditor
&& event
.GetId() == m_labelEditor
->GetId() )
3568 wxPGProperty
* selected
= GetSelection();
3570 // Somehow, event is handled after property has been deselected.
3571 // Possibly, but very rare.
3573 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3574 m_inOnValidationFailure
||
3575 // Also don't handle editor event if wxEVT_PG_CHANGED or
3576 // similar is currently doing something (showing a
3577 // message box, for instance).
3581 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3584 wxVariant
pendingValue(selected
->GetValueRef());
3585 wxWindow
* wnd
= GetEditorControl();
3586 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3588 bool wasUnspecified
= selected
->IsValueUnspecified();
3589 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3590 bool valueIsPending
= false;
3592 m_chgInfo_changedProperty
= NULL
;
3594 m_iFlags
&= ~wxPG_FL_VALUE_CHANGE_IN_EVENT
;
3597 // Filter out excess wxTextCtrl modified events
3598 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&& wnd
)
3600 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3602 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3604 wxString newTcValue
= tc
->GetValue();
3605 if ( m_prevTcValue
== newTcValue
)
3607 m_prevTcValue
= newTcValue
;
3609 else if ( wnd
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
3611 // In some cases we might stumble unintentionally on
3612 // wxComboCtrl's embedded wxTextCtrl's events. Let's
3614 if ( editorWnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3617 wxComboCtrl
* cc
= (wxComboCtrl
*) wnd
;
3619 wxString newTcValue
= cc
->GetTextCtrl()->GetValue();
3620 if ( m_prevTcValue
== newTcValue
)
3622 m_prevTcValue
= newTcValue
;
3626 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3628 bool validationFailure
= false;
3629 bool buttonWasHandled
= false;
3630 bool result
= false;
3633 // Try common button handling
3634 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3636 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3640 buttonWasHandled
= true;
3641 // Store as res2, as previously (and still currently alternatively)
3642 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3643 // in wxPGProperty::OnEvent().
3644 adapter
->ShowDialog( this, selected
);
3649 if ( !buttonWasHandled
)
3651 if ( wnd
|| m_wndEditor2
)
3653 // First call editor class' event handler.
3654 const wxPGEditor
* editor
= selected
->GetEditorClass();
3656 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3660 // If changes, validate them
3661 if ( DoEditorValidate() )
3663 if ( editor
->GetValueFromControl( pendingValue
,
3666 valueIsPending
= true;
3668 // Mark value always as pending if validation is currently
3669 // failing and value was not unspecified
3670 if ( !valueIsPending
&&
3671 !pendingValue
.IsNull() &&
3672 m_validationInfo
.m_isFailing
)
3673 valueIsPending
= true;
3677 validationFailure
= true;
3682 // Then the property's custom handler (must be always called, unless
3683 // validation failed).
3684 if ( !validationFailure
)
3685 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3688 // SetValueInEvent(), as called in one of the functions referred above
3689 // overrides editor's value.
3690 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3692 valueIsPending
= true;
3693 pendingValue
= m_changeInEventValue
;
3694 selFlags
|= wxPG_SEL_DIALOGVAL
;
3697 if ( !validationFailure
&& valueIsPending
)
3698 if ( !PerformValidation(selected
, pendingValue
) )
3699 validationFailure
= true;
3701 if ( validationFailure
)
3703 OnValidationFailure(selected
, pendingValue
);
3705 else if ( valueIsPending
)
3707 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3709 DoPropertyChanged(selected
, selFlags
);
3710 EditorsValueWasNotModified();
3712 // Regardless of editor type, unfocus editor on
3713 // text-editing related enter press.
3714 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3721 // No value after all
3723 // Regardless of editor type, unfocus editor on
3724 // text-editing related enter press.
3725 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3730 // Let unhandled button click events go to the parent
3731 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3734 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3735 GetEventHandler()->AddPendingEvent(evt
);
3739 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3744 // -----------------------------------------------------------------------
3745 // wxPropertyGrid editor control helper methods
3746 // -----------------------------------------------------------------------
3748 wxRect wxPropertyGrid
::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3750 int itemy
= p
->GetY2(m_lineHeight
);
3751 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3752 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3753 int imageOffset
= 0;
3755 int vx
, vy
; // Top left corner of client
3756 GetViewStart(&vx
, &vy
);
3757 vy
*= wxPG_PIXELS_PER_UNIT
;
3761 // TODO: If custom image detection changes from current, change this.
3762 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3764 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3765 int iw
= p
->OnMeasureImage().x
;
3767 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3768 imageOffset
= p
->GetImageOffset(iw
);
3771 else if ( column
== 0 )
3773 splitterX
+= (p
->m_depth
- 1) * m_subgroup_extramargin
;
3778 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3780 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3785 // -----------------------------------------------------------------------
3787 wxRect wxPropertyGrid
::GetImageRect( wxPGProperty
* p
, int item
) const
3789 wxSize sz
= GetImageSize(p
, item
);
3790 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3791 wxPG_CUSTOM_IMAGE_SPACINGY
,
3796 // return size of custom paint image
3797 wxSize wxPropertyGrid
::GetImageSize( wxPGProperty
* p
, int item
) const
3799 // If called with NULL property, then return default image
3800 // size for properties that use image.
3802 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3804 wxSize cis
= p
->OnMeasureImage(item
);
3806 int choiceCount
= p
->m_choices
.GetCount();
3807 int comVals
= p
->GetDisplayedCommonValueCount();
3808 if ( item
>= choiceCount
&& comVals
> 0 )
3810 unsigned int cvi
= item
-choiceCount
;
3811 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3813 else if ( item
>= 0 && choiceCount
== 0 )
3814 return wxSize(0, 0);
3819 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3824 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3831 // -----------------------------------------------------------------------
3833 // takes scrolling into account
3834 void wxPropertyGrid
::ImprovedClientToScreen( int* px
, int* py
)
3837 GetViewStart(&vx
,&vy
);
3838 vy
*=wxPG_PIXELS_PER_UNIT
;
3839 vx
*=wxPG_PIXELS_PER_UNIT
;
3842 ClientToScreen( px
, py
);
3845 // -----------------------------------------------------------------------
3847 wxPropertyGridHitTestResult wxPropertyGrid
::HitTest( const wxPoint
& pt
) const
3850 GetViewStart(&pt2
.x
,&pt2
.y
);
3851 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3852 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3856 return m_pState
->HitTest(pt2
);
3859 // -----------------------------------------------------------------------
3861 // custom set cursor
3862 void wxPropertyGrid
::CustomSetCursor( int type
, bool override
)
3864 if ( type
== m_curcursor
&& !override
) return;
3866 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3868 if ( type
== wxCURSOR_SIZEWE
)
3869 cursor
= m_cursorSizeWE
;
3871 SetCursor( *cursor
);
3876 // -----------------------------------------------------------------------
3879 wxPropertyGrid
::GetUnspecifiedValueText( int argFlags
) const
3881 const wxPGCell
& ua
= GetUnspecifiedValueAppearance();
3883 if ( ua
.HasText() &&
3884 !(argFlags
& wxPG_FULL_VALUE
) &&
3885 !(argFlags
& wxPG_EDITABLE_VALUE
) )
3886 return ua
.GetText();
3888 return wxEmptyString
;
3891 // -----------------------------------------------------------------------
3892 // wxPropertyGrid property selection, editor creation
3893 // -----------------------------------------------------------------------
3896 // This class forwards events from property editor controls to wxPropertyGrid.
3897 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3900 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3901 : wxEvtHandler(), m_propGrid(propGrid
)
3905 virtual ~wxPropertyGridEditorEventForwarder()
3910 bool ProcessEvent( wxEvent
& event
)
3915 m_propGrid
->HandleCustomEditorEvent(event
);
3918 // NB: We should return true if the event was recognized as
3919 // a dedicated wxPropertyGrid event, and as such was
3920 // either properly handled or ignored.
3922 if ( m_propGrid
->IsMainButtonEvent(event
) )
3926 // NB: On wxMSW, a wxTextCtrl with wxTE_PROCESS_ENTER
3927 // may beep annoyingly if that event is skipped
3928 // and passed to parent event handler.
3929 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3932 return wxEvtHandler
::ProcessEvent(event
);
3935 wxPropertyGrid
* m_propGrid
;
3938 // Setups event handling for child control
3939 void wxPropertyGrid
::SetupChildEventHandling( wxWindow
* argWnd
)
3941 wxWindowID id
= argWnd
->GetId();
3943 if ( argWnd
== m_wndEditor
)
3945 argWnd
->Connect(id
, wxEVT_MOTION
,
3946 wxMouseEventHandler(wxPropertyGrid
::OnMouseMoveChild
),
3948 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3949 wxMouseEventHandler(wxPropertyGrid
::OnMouseUpChild
),
3951 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3952 wxMouseEventHandler(wxPropertyGrid
::OnMouseClickChild
),
3954 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3955 wxMouseEventHandler(wxPropertyGrid
::OnMouseRightClickChild
),
3957 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3958 wxMouseEventHandler(wxPropertyGrid
::OnMouseEntry
),
3960 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3961 wxMouseEventHandler(wxPropertyGrid
::OnMouseEntry
),
3965 wxPropertyGridEditorEventForwarder
* forwarder
;
3966 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3967 argWnd
->PushEventHandler(forwarder
);
3969 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3970 wxCharEventHandler(wxPropertyGrid
::OnChildKeyDown
),
3974 void wxPropertyGrid
::DestroyEditorWnd( wxWindow
* wnd
)
3981 // Do not free editors immediately (for sake of processing events)
3982 wxPendingDelete
.Append(wnd
);
3985 void wxPropertyGrid
::FreeEditors()
3988 // Return focus back to canvas from children (this is required at least for
3989 // GTK+, which, unlike Windows, clears focus when control is destroyed
3990 // instead of moving it to closest parent).
3993 // Do not free editors immediately if processing events
3996 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3997 m_wndEditor2
->Hide();
3998 wxPendingDelete
.Append( handler
);
3999 DestroyEditorWnd(m_wndEditor2
);
4000 m_wndEditor2
= NULL
;
4005 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
4006 m_wndEditor
->Hide();
4007 wxPendingDelete
.Append( handler
);
4008 DestroyEditorWnd(m_wndEditor
);
4013 // Call with NULL to de-select property
4014 bool wxPropertyGrid
::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
4019 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
4020 p->m_parent->m_label.c_str(),p->GetIndexInParent());
4024 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
4028 if ( m_inDoSelectProperty
)
4031 m_inDoSelectProperty
= true;
4032 wxON_BLOCK_EXIT_SET(m_inDoSelectProperty
, false);
4037 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
4038 wxPGProperty
* prevFirstSel
;
4040 if ( prevSelection
.size() > 0 )
4041 prevFirstSel
= prevSelection
[0];
4043 prevFirstSel
= NULL
;
4045 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
4046 prevFirstSel
= NULL
;
4048 // Always send event, as this is indirect call
4049 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4053 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
4055 wxPrintf( "None selected\n" );
4058 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
4060 wxPrintf( "P = NULL\n" );
4063 wxWindow
* primaryCtrl
= NULL
;
4065 // If we are frozen, then just set the values.
4068 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4069 m_editorFocused
= 0;
4070 m_pState
->DoSetSelection(p
);
4072 // If frozen, always free controls. But don't worry, as Thaw will
4073 // recall SelectProperty to recreate them.
4076 // Prevent any further selection measures in this call
4082 if ( prevFirstSel
== p
&&
4083 prevSelection
.size() <= 1 &&
4084 !(flags
& wxPG_SEL_FORCE
) )
4086 // Only set focus if not deselecting
4089 if ( flags
& wxPG_SEL_FOCUS
)
4093 m_wndEditor
->SetFocus();
4094 m_editorFocused
= 1;
4107 // First, deactivate previous
4110 // Must double-check if this is an selected in case of forceswitch
4111 if ( p
!= prevFirstSel
)
4113 if ( !CommitChangesFromEditor(flags
) )
4115 // Validation has failed, so we can't exit the previous editor
4116 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
4117 // _("Invalid Value"),wxOK|wxICON_ERROR);
4122 // This should be called after CommitChangesFromEditor(), so that
4123 // OnValidationFailure() still has information on property's
4124 // validation state.
4125 OnValidationFailureReset(prevFirstSel
);
4129 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
4130 EditorsValueWasNotModified();
4133 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4135 m_pState
->DoSetSelection(p
);
4137 // Redraw unselected
4138 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
4140 DrawItem(prevSelection
[i
]);
4144 // Then, activate the one given.
4147 int propY
= p
->GetY2(m_lineHeight
);
4149 int splitterX
= GetSplitterPosition();
4150 m_editorFocused
= 0;
4151 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
4153 wxASSERT( m_wndEditor
== NULL
);
4156 // Only create editor for non-disabled non-caption
4157 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
4159 // do this for non-caption items
4163 // Do we need to paint the custom image, if any?
4164 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
4165 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
4166 !p
->GetEditorClass()->CanContainCustomImage()
4168 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
4170 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
4171 wxPoint goodPos
= grect
.GetPosition();
4173 // Editor appearance can now be considered clear
4174 m_editorAppearance
.SetEmptyData();
4176 const wxPGEditor
* editor
= p
->GetEditorClass();
4177 wxCHECK_MSG(editor
, false,
4178 wxT("NULL editor class not allowed"));
4180 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
4182 wxPGWindowList wndList
=
4183 editor
->CreateControls(this,
4188 m_wndEditor
= wndList
.m_primary
;
4189 m_wndEditor2
= wndList
.m_secondary
;
4190 primaryCtrl
= GetEditorControl();
4193 // Essentially, primaryCtrl == m_wndEditor
4196 // NOTE: It is allowed for m_wndEditor to be NULL - in this
4197 // case value is drawn as normal, and m_wndEditor2 is
4198 // assumed to be a right-aligned button that triggers
4199 // a separate editorCtrl window.
4203 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
4204 "CreateControls must use result of "
4205 "wxPropertyGrid::GetPanel() as parent "
4208 // Set validator, if any
4209 #if wxUSE_VALIDATORS
4210 wxValidator
* validator
= p
->GetValidator();
4212 primaryCtrl
->SetValidator(*validator
);
4215 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
4216 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
4218 // If it has modified status, use bold font
4219 // (must be done before capturing m_ctrlXAdjust)
4220 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
4221 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
4222 SetCurControlBoldFont();
4224 // Store x relative to splitter (we'll need it).
4225 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
4227 // Check if background clear is not necessary
4228 wxPoint pos
= m_wndEditor
->GetPosition();
4229 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
4231 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
4234 m_wndEditor
->SetSizeHints(3, 3);
4236 SetupChildEventHandling(primaryCtrl
);
4238 // Focus and select all (wxTextCtrl, wxComboBox etc)
4239 if ( flags
& wxPG_SEL_FOCUS
)
4241 primaryCtrl
->SetFocus();
4243 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
4247 if ( p
->IsValueUnspecified() )
4248 SetEditorAppearance(m_unspecifiedAppearance
,
4255 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
4256 "CreateControls must use result of "
4257 "wxPropertyGrid::GetPanel() as parent "
4260 // Get proper id for wndSecondary
4261 m_wndSecId
= m_wndEditor2
->GetId();
4262 wxWindowList children
= m_wndEditor2
->GetChildren();
4263 wxWindowList
::iterator node
= children
.begin();
4264 if ( node
!= children
.end() )
4265 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
4267 m_wndEditor2
->SetSizeHints(3,3);
4269 m_wndEditor2
->Show();
4271 SetupChildEventHandling(m_wndEditor2
);
4273 // If no primary editor, focus to button to allow
4274 // it to interprete ENTER etc.
4275 // NOTE: Due to problems focusing away from it, this
4276 // has been disabled.
4278 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
4279 m_wndEditor2->SetFocus();
4283 if ( flags
& wxPG_SEL_FOCUS
)
4284 m_editorFocused
= 1;
4289 // Make sure focus is in grid canvas (important for wxGTK,
4294 EditorsValueWasNotModified();
4296 // If it's inside collapsed section, expand parent, scroll, etc.
4297 // Also, if it was partially visible, scroll it into view.
4298 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
4303 m_wndEditor
->Show(true);
4306 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
4311 // Make sure focus is in grid canvas
4315 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
4318 const wxString
* pHelpString
= NULL
;
4321 pHelpString
= &p
->GetHelpString();
4323 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4328 // Show help text in status bar.
4329 // (if found and grid not embedded in manager with help box and
4330 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4332 wxStatusBar
* statusbar
= GetStatusBar();
4335 if ( pHelpString
&& !pHelpString
->empty() )
4337 // Set help box text.
4338 statusbar
->SetStatusText( *pHelpString
);
4339 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4341 else if ( m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
)
4343 // Clear help box - but only if it was written
4344 // by us at previous time.
4345 statusbar
->SetStatusText( m_emptyString
);
4346 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4353 #if wxPG_SUPPORT_TOOLTIPS
4355 // Show help as a tool tip on the editor control.
4357 if ( pHelpString
&& !pHelpString
->empty() &&
4360 primaryCtrl
->SetToolTip(*pHelpString
);
4365 // call wx event handler (here so that it also occurs on deselection)
4366 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4367 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4372 // -----------------------------------------------------------------------
4374 bool wxPropertyGrid
::UnfocusEditor()
4376 wxPGProperty
* selected
= GetSelection();
4378 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4381 if ( !CommitChangesFromEditor(0) )
4390 // -----------------------------------------------------------------------
4392 void wxPropertyGrid
::RefreshEditor()
4394 wxPGProperty
* p
= GetSelection();
4398 wxWindow
* wnd
= GetEditorControl();
4402 // Set editor font boldness - must do this before
4403 // calling UpdateControl().
4404 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4406 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4407 wnd
->SetFont(GetCaptionFont());
4409 wnd
->SetFont(GetFont());
4412 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4414 editorClass
->UpdateControl(p
, wnd
);
4416 if ( p
->IsValueUnspecified() )
4417 SetEditorAppearance(m_unspecifiedAppearance
, true);
4420 // -----------------------------------------------------------------------
4422 bool wxPropertyGrid
::SelectProperty( wxPGPropArg id
, bool focus
)
4424 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4426 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4428 flags
|= wxPG_SEL_FOCUS
;
4430 return DoSelectProperty(p
, flags
);
4433 // -----------------------------------------------------------------------
4434 // wxPropertyGrid expand/collapse state
4435 // -----------------------------------------------------------------------
4437 bool wxPropertyGrid
::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4439 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4440 wxPGProperty
* selected
= GetSelection();
4442 // If active editor was inside collapsed section, then disable it
4443 if ( selected
&& selected
->IsSomeParent(p
) )
4448 // Store dont-center-splitter flag 'cause we need to temporarily set it
4449 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4450 m_pState
->m_dontCenterSplitter
= true;
4452 bool res
= m_pState
->DoCollapse(pwc
);
4457 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4459 RecalculateVirtualSize();
4463 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4468 // -----------------------------------------------------------------------
4470 bool wxPropertyGrid
::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4472 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4474 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4476 // Store dont-center-splitter flag 'cause we need to temporarily set it
4477 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4478 m_pState
->m_dontCenterSplitter
= true;
4480 bool res
= m_pState
->DoExpand(pwc
);
4485 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4487 RecalculateVirtualSize();
4491 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4496 // -----------------------------------------------------------------------
4498 bool wxPropertyGrid
::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4501 return m_pState
->DoHideProperty(p
, hide
, flags
);
4503 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4504 int selRemoveCount
= 0;
4505 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4507 wxPGProperty
* selected
= selection
[i
];
4508 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4510 if ( !DoRemoveFromSelection(p
, flags
) )
4512 selRemoveCount
+= 1;
4516 m_pState
->DoHideProperty(p
, hide
, flags
);
4518 RecalculateVirtualSize();
4525 // -----------------------------------------------------------------------
4526 // wxPropertyGrid size related methods
4527 // -----------------------------------------------------------------------
4529 void wxPropertyGrid
::RecalculateVirtualSize( int forceXPos
)
4531 // Don't check for !HasInternalFlag(wxPG_FL_INITIALIZED) here. Otherwise
4532 // virtual size calculation may go wrong.
4533 if ( HasInternalFlag(wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4539 // If virtual height was changed, then recalculate editor control position(s)
4540 if ( m_pState
->m_vhCalcPending
)
4541 CorrectEditorWidgetPosY();
4543 m_pState
->EnsureVirtualHeight();
4545 wxASSERT_LEVEL_2_MSG(
4546 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4547 "VirtualHeight and ActualVirtualHeight should match"
4550 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4552 int x
= m_pState
->m_width
;
4553 int y
= m_pState
->m_virtualHeight
;
4556 GetClientSize(&width
,&height
);
4558 // Now adjust virtual size.
4559 SetVirtualSize(x
, y
);
4565 // Adjust scrollbars
4566 if ( HasVirtualWidth() )
4568 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4569 xPos
= GetScrollPos( wxHORIZONTAL
);
4572 if ( forceXPos
!= -1 )
4575 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4578 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4579 int yPos
= GetScrollPos( wxVERTICAL
);
4581 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4582 xAmount
, yAmount
, xPos
, yPos
, true );
4584 // This may be needed in addition to calling SetScrollbars()
4585 // when class inherits from wxScrollHelper instead of
4586 // actual wxScrolled<T>.
4589 // Must re-get size now
4590 GetClientSize(&width
,&height
);
4592 if ( !HasVirtualWidth() )
4594 m_pState
->SetVirtualWidth(width
);
4601 m_pState
->CheckColumnWidths();
4603 if ( GetSelection() )
4604 CorrectEditorWidgetSizeX();
4606 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4609 // -----------------------------------------------------------------------
4611 void wxPropertyGrid
::OnResize( wxSizeEvent
& event
)
4613 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4617 GetClientSize(&width
, &height
);
4622 #if wxPG_DOUBLE_BUFFER
4623 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4625 int dblh
= (m_lineHeight
*2);
4626 if ( !m_doubleBuffer
)
4628 // Create double buffer bitmap to draw on, if none
4629 int w
= (width
>250)?width
:250;
4630 int h
= height
+ dblh
;
4632 m_doubleBuffer
= new wxBitmap( w
, h
);
4636 int w
= m_doubleBuffer
->GetWidth();
4637 int h
= m_doubleBuffer
->GetHeight();
4639 // Double buffer must be large enough
4640 if ( w
< width
|| h
< (height
+dblh
) )
4642 if ( w
< width
) w
= width
;
4643 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4644 delete m_doubleBuffer
;
4645 m_doubleBuffer
= new wxBitmap( w
, h
);
4652 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4653 m_ncWidth
= event
.GetSize().x
;
4657 if ( m_pState
->m_itemsAdded
)
4658 PrepareAfterItemsAdded();
4660 // Without this, virtual size (atleast under wxGTK) will be skewed
4661 RecalculateVirtualSize();
4667 // -----------------------------------------------------------------------
4669 void wxPropertyGrid
::SetVirtualWidth( int width
)
4673 // Disable virtual width
4674 width
= GetClientSize().x
;
4675 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4679 // Enable virtual width
4680 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4682 m_pState
->SetVirtualWidth( width
);
4685 void wxPropertyGrid
::SetFocusOnCanvas()
4687 // To prevent wxPropertyGrid from stealing focus from other controls,
4688 // only move focus to the grid if it was already in one if its child
4690 wxWindow
* focus
= wxWindow
::FindFocus();
4693 wxWindow
* parent
= focus
->GetParent();
4696 if ( parent
== this )
4701 parent
= parent
->GetParent();
4705 m_editorFocused
= 0;
4708 // -----------------------------------------------------------------------
4709 // wxPropertyGrid mouse event handling
4710 // -----------------------------------------------------------------------
4712 // selFlags uses same values DoSelectProperty's flags
4713 // Returns true if event was vetoed.
4714 bool wxPropertyGrid
::SendEvent( int eventType
, wxPGProperty
* p
,
4716 unsigned int selFlags
,
4717 unsigned int column
)
4719 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4722 // Send property grid event of specific type and with specific property
4723 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4724 evt
.SetPropertyGrid(this);
4725 evt
.SetEventObject(m_eventObject
);
4727 evt
.SetColumn(column
);
4728 if ( eventType
== wxEVT_PG_CHANGING
)
4731 evt
.SetCanVeto(true);
4732 m_validationInfo
.m_pValue
= pValue
;
4733 evt
.SetupValidationInfo();
4738 evt
.SetPropertyValue(p
->GetValue());
4740 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4741 evt
.SetCanVeto(true);
4744 wxPropertyGridEvent
* prevProcessedEvent
= m_processedEvent
;
4745 m_processedEvent
= &evt
;
4746 m_eventObject
->HandleWindowEvent(evt
);
4747 m_processedEvent
= prevProcessedEvent
;
4749 return evt
.WasVetoed();
4752 // -----------------------------------------------------------------------
4754 // Return false if should be skipped
4755 bool wxPropertyGrid
::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4759 // Need to set focus?
4760 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4765 wxPropertyGridPageState
* state
= m_pState
;
4767 int splitterHitOffset
;
4768 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4770 wxPGProperty
* p
= DoGetItemAtY(y
);
4774 int depth
= (int)p
->GetDepth() - 1;
4776 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4778 if ( x
>= marginEnds
)
4782 if ( p
->IsCategory() )
4784 // This is category.
4785 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4787 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4789 // Expand, collapse, activate etc. if click on text or left of splitter.
4792 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4797 if ( !AddToSelectionFromInputEvent( p
,
4802 // On double-click, expand/collapse.
4803 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4805 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4806 else DoExpand( p
, true );
4810 else if ( splitterHit
== -1 )
4813 unsigned int selFlag
= 0;
4814 if ( columnHit
== 1 )
4816 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4817 selFlag
= wxPG_SEL_FOCUS
;
4819 if ( !AddToSelectionFromInputEvent( p
,
4825 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4827 if ( p
->GetChildCount() && !p
->IsCategory() )
4828 // On double-click, expand/collapse.
4829 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4831 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4832 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4833 else DoExpand( p
, true );
4836 // Do not Skip() the event after selection has been made.
4837 // Otherwise default event handling behaviour kicks in
4838 // and may revert focus back to the main canvas.
4843 // click on splitter
4844 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4846 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4848 // Double-clicking the splitter causes auto-centering
4849 if ( m_pState
->GetColumnCount() <= 2 )
4851 ResetColumnSizes( true );
4853 SendEvent(wxEVT_PG_COL_DRAGGING
,
4856 wxPG_SEL_NOVALIDATE
,
4857 (unsigned int)m_draggedSplitter
);
4860 else if ( m_dragStatus
== 0 )
4863 // Begin draggin the splitter
4867 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4869 // Allow application to veto dragging
4870 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4872 (unsigned int)splitterHit
) )
4876 // Changes must be committed here or the
4877 // value won't be drawn correctly
4878 if ( !CommitChangesFromEditor() )
4881 m_wndEditor
->Show ( false );
4884 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4887 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4891 m_draggedSplitter
= splitterHit
;
4892 m_dragOffset
= splitterHitOffset
;
4894 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4895 // Fixes button disappearance bug
4897 m_wndEditor2
->Show ( false );
4900 m_startingSplitterX
= x
- splitterHitOffset
;
4909 if ( p
->GetChildCount() )
4911 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4913 // Fine tune cell button x
4914 if ( !p
->IsCategory() )
4915 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4917 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4919 int y2
= y
% m_lineHeight
;
4920 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4922 // On click on expander button, expand/collapse
4923 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4924 DoCollapse( p
, true );
4926 DoExpand( p
, true );
4935 // -----------------------------------------------------------------------
4937 bool wxPropertyGrid
::HandleMouseRightClick( int WXUNUSED(x
),
4938 unsigned int WXUNUSED(y
),
4939 wxMouseEvent
& event
)
4943 // Select property here as well
4944 wxPGProperty
* p
= m_propHover
;
4945 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4947 // Send right click event.
4948 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4955 // -----------------------------------------------------------------------
4957 bool wxPropertyGrid
::HandleMouseDoubleClick( int WXUNUSED(x
),
4958 unsigned int WXUNUSED(y
),
4959 wxMouseEvent
& event
)
4963 // Select property here as well
4964 wxPGProperty
* p
= m_propHover
;
4966 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4968 // Send double-click event.
4969 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4976 // -----------------------------------------------------------------------
4978 // Return false if should be skipped
4979 bool wxPropertyGrid
::HandleMouseMove( int x
, unsigned int y
,
4980 wxMouseEvent
&event
)
4982 // Safety check (needed because mouse capturing may
4983 // otherwise freeze the control)
4984 if ( m_dragStatus
> 0 && !event
.Dragging() )
4986 HandleMouseUp(x
, y
, event
);
4989 wxPropertyGridPageState
* state
= m_pState
;
4991 int splitterHitOffset
;
4992 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4993 int splitterX
= x
- splitterHitOffset
;
4995 m_colHover
= columnHit
;
4997 if ( m_dragStatus
> 0 )
4999 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
5000 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
5003 int newSplitterX
= x
- m_dragOffset
;
5005 // Splitter redraw required?
5006 if ( newSplitterX
!= splitterX
)
5009 DoSetSplitterPosition(newSplitterX
,
5011 wxPG_SPLITTER_REFRESH
|
5012 wxPG_SPLITTER_FROM_EVENT
);
5014 SendEvent(wxEVT_PG_COL_DRAGGING
,
5017 wxPG_SEL_NOVALIDATE
,
5018 (unsigned int)m_draggedSplitter
);
5029 int ih
= m_lineHeight
;
5032 #if wxPG_SUPPORT_TOOLTIPS
5033 wxPGProperty
* prevHover
= m_propHover
;
5034 unsigned char prevSide
= m_mouseSide
;
5036 int curPropHoverY
= y
- (y
% ih
);
5038 // On which item it hovers
5041 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
5044 // Mouse moves on another property
5046 m_propHover
= DoGetItemAtY(y
);
5047 m_propHoverY
= curPropHoverY
;
5050 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
5053 #if wxPG_SUPPORT_TOOLTIPS
5054 // Store which side we are on
5056 if ( columnHit
== 1 )
5058 else if ( columnHit
== 0 )
5062 // If tooltips are enabled, show label or value as a tip
5063 // in case it doesn't otherwise show in full length.
5065 if ( m_windowStyle
& wxPG_TOOLTIPS
)
5067 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
5069 if ( m_propHover
&& !m_propHover
->IsCategory() )
5072 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
5074 // Show help string as a tooltip
5075 wxString tipString
= m_propHover
->GetHelpString();
5077 SetToolTip(tipString
);
5081 // Show cropped value string as a tooltip
5085 if ( m_mouseSide
== 1 )
5087 tipString
= m_propHover
->m_label
;
5088 space
= splitterX
-m_marginWidth
-3;
5090 else if ( m_mouseSide
== 2 )
5092 tipString
= m_propHover
->GetDisplayedString();
5094 space
= m_width
- splitterX
;
5095 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
5096 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+
5097 wxCC_CUSTOM_IMAGE_MARGIN1
+
5098 wxCC_CUSTOM_IMAGE_MARGIN2
;
5104 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
5106 SetToolTip( tipString
);
5110 SetToolTip( m_emptyString
);
5117 SetToolTip( m_emptyString
);
5123 if ( splitterHit
== -1 ||
5125 HasFlag(wxPG_STATIC_SPLITTER
) )
5127 // hovering on something else
5128 if ( m_curcursor
!= wxCURSOR_ARROW
)
5129 CustomSetCursor( wxCURSOR_ARROW
);
5133 // Do not allow splitter cursor on caption items.
5134 // (also not if we were dragging and its started
5135 // outside the splitter region)
5137 if ( !m_propHover
->IsCategory() &&
5141 // hovering on splitter
5143 // NB: Condition disabled since MouseLeave event (from the
5144 // editor control) cannot be reliably detected.
5145 //if ( m_curcursor != wxCURSOR_SIZEWE )
5146 CustomSetCursor( wxCURSOR_SIZEWE
, true );
5152 // hovering on something else
5153 if ( m_curcursor
!= wxCURSOR_ARROW
)
5154 CustomSetCursor( wxCURSOR_ARROW
);
5159 // Multi select by dragging
5161 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
5162 event
.LeftIsDown() &&
5166 !state
->DoIsPropertySelected(m_propHover
) )
5168 // Additional requirement is that the hovered property
5169 // is adjacent to edges of selection.
5170 const wxArrayPGProperty
& selection
= GetSelectedProperties();
5172 // Since categories cannot be selected along with 'other'
5173 // properties, exclude them from iterator flags.
5174 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
5176 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
5178 // TODO: This could be optimized by keeping track of
5179 // which properties are at the edges of selection.
5180 wxPGProperty
* selProp
= selection
[i
];
5181 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
5184 DoAddToSelection(m_propHover
);
5193 // -----------------------------------------------------------------------
5195 // Also handles Leaving event
5196 bool wxPropertyGrid
::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
5197 wxMouseEvent
&WXUNUSED(event
) )
5199 wxPropertyGridPageState
* state
= m_pState
;
5203 int splitterHitOffset
;
5204 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
5206 // No event type check - basicly calling this method should
5207 // just stop dragging.
5208 // Left up after dragged?
5209 if ( m_dragStatus
>= 1 )
5212 // End Splitter Dragging
5214 // DO NOT ENABLE FOLLOWING LINE!
5215 // (it is only here as a reminder to not to do it)
5218 SendEvent(wxEVT_PG_COL_END_DRAG
,
5221 wxPG_SEL_NOVALIDATE
,
5222 (unsigned int)m_draggedSplitter
);
5224 // Disable splitter auto-centering (but only if moved any -
5225 // otherwise we end up disabling auto-center even after a
5226 // recentering double-click).
5227 int posDiff
= abs(m_startingSplitterX
-
5228 GetSplitterPosition(m_draggedSplitter
));
5231 state
->m_dontCenterSplitter
= true;
5233 // This is necessary to return cursor
5234 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5237 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5240 // Set back the default cursor, if necessary
5241 if ( splitterHit
== -1 ||
5244 CustomSetCursor( wxCURSOR_ARROW
);
5249 // Control background needs to be cleared
5250 wxPGProperty
* selected
= GetSelection();
5251 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
5252 DrawItem( selected
);
5256 m_wndEditor
->Show ( true );
5259 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
5260 // Fixes button disappearance bug
5262 m_wndEditor2
->Show ( true );
5265 // This clears the focus.
5266 m_editorFocused
= 0;
5272 // -----------------------------------------------------------------------
5274 bool wxPropertyGrid
::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
5276 int splitterX
= GetSplitterPosition();
5279 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
5281 wxWindow
* wnd
= GetEditorControl();
5283 // Hide popup on clicks
5284 if ( event
.GetEventType() != wxEVT_MOTION
)
5285 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5287 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
5293 if ( wnd
== NULL
|| m_dragStatus
||
5295 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
5296 ux
>= (r
.x
+r
.width
) ||
5298 event
.m_y
>= (r
.y
+r
.height
)
5308 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5313 // -----------------------------------------------------------------------
5315 void wxPropertyGrid
::OnMouseClick( wxMouseEvent
&event
)
5318 if ( OnMouseCommon( event
, &x
, &y
) )
5320 if ( !HandleMouseClick(x
, y
, event
) )
5329 // -----------------------------------------------------------------------
5331 void wxPropertyGrid
::OnMouseRightClick( wxMouseEvent
&event
)
5334 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5335 HandleMouseRightClick(x
,y
,event
);
5339 // -----------------------------------------------------------------------
5341 void wxPropertyGrid
::OnMouseDoubleClick( wxMouseEvent
&event
)
5343 // Always run standard mouse-down handler as well
5344 OnMouseClick(event
);
5347 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5348 HandleMouseDoubleClick(x
,y
,event
);
5350 // Do not Skip() event here - OnMouseClick() call above
5351 // should have already taken care of it.
5354 // -----------------------------------------------------------------------
5356 void wxPropertyGrid
::OnMouseMove( wxMouseEvent
&event
)
5359 if ( OnMouseCommon( event
, &x
, &y
) )
5361 HandleMouseMove(x
,y
,event
);
5366 // -----------------------------------------------------------------------
5368 void wxPropertyGrid
::OnMouseUp( wxMouseEvent
&event
)
5371 if ( OnMouseCommon( event
, &x
, &y
) )
5373 if ( !HandleMouseUp(x
, y
, event
) )
5382 // -----------------------------------------------------------------------
5384 void wxPropertyGrid
::OnMouseEntry( wxMouseEvent
&event
)
5386 // This may get called from child control as well, so event's
5387 // mouse position cannot be relied on.
5389 if ( event
.Entering() )
5391 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5393 // TODO: Fix this (detect parent and only do
5394 // cursor trick if it is a manager).
5395 wxASSERT( GetParent() );
5396 GetParent()->SetCursor(wxNullCursor
);
5398 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5401 GetParent()->SetCursor(wxNullCursor
);
5403 else if ( event
.Leaving() )
5405 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5406 SetCursor( wxNullCursor
);
5408 // Get real cursor position
5409 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5411 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5414 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5416 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5420 wxPropertyGrid
::HandleMouseUp ( -1, 10000, event
);
5428 // -----------------------------------------------------------------------
5430 // Common code used by various OnMouseXXXChild methods.
5431 bool wxPropertyGrid
::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5433 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5434 wxASSERT( topCtrlWnd
);
5436 event
.GetPosition(&x
,&y
);
5438 int splitterX
= GetSplitterPosition();
5440 wxRect r
= topCtrlWnd
->GetRect();
5441 if ( !m_dragStatus
&&
5442 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5443 y
>= 0 && y
< r
.height \
5446 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5451 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5458 void wxPropertyGrid
::OnMouseClickChild( wxMouseEvent
&event
)
5461 if ( OnMouseChildCommon(event
,&x
,&y
) )
5463 bool res
= HandleMouseClick(x
,y
,event
);
5464 if ( !res
) event
.Skip();
5468 void wxPropertyGrid
::OnMouseRightClickChild( wxMouseEvent
&event
)
5471 wxASSERT( m_wndEditor
);
5472 // These coords may not be exact (about +-2),
5473 // but that should not matter (right click is about item, not position).
5474 wxPoint pt
= m_wndEditor
->GetPosition();
5475 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5477 // FIXME: Used to set m_propHover to selection here. Was it really
5480 bool res
= HandleMouseRightClick(x
,y
,event
);
5481 if ( !res
) event
.Skip();
5484 void wxPropertyGrid
::OnMouseMoveChild( wxMouseEvent
&event
)
5487 if ( OnMouseChildCommon(event
,&x
,&y
) )
5489 bool res
= HandleMouseMove(x
,y
,event
);
5490 if ( !res
) event
.Skip();
5494 void wxPropertyGrid
::OnMouseUpChild( wxMouseEvent
&event
)
5497 if ( OnMouseChildCommon(event
,&x
,&y
) )
5499 bool res
= HandleMouseUp(x
,y
,event
);
5500 if ( !res
) event
.Skip();
5504 // -----------------------------------------------------------------------
5505 // wxPropertyGrid keyboard event handling
5506 // -----------------------------------------------------------------------
5508 int wxPropertyGrid
::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5510 // Translates wxKeyEvent to wxPG_ACTION_XXX
5512 int keycode
= event
.GetKeyCode();
5513 int modifiers
= event
.GetModifiers();
5515 wxASSERT( !(modifiers
&~(0xFFFF)) );
5517 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5519 wxPGHashMapI2I
::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5521 if ( it
== m_actionTriggers
.end() )
5526 int second
= (it
->second
>>16) & 0xFFFF;
5530 return (it
->second
& 0xFFFF);
5533 void wxPropertyGrid
::AddActionTrigger( int action
, int keycode
, int modifiers
)
5535 wxASSERT( !(modifiers
&~(0xFFFF)) );
5537 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5539 wxPGHashMapI2I
::iterator it
= m_actionTriggers
.find(hashMapKey
);
5541 if ( it
!= m_actionTriggers
.end() )
5543 // This key combination is already used
5545 // Can add secondary?
5546 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5547 wxT("You can only add up to two separate actions per key combination.") );
5549 action
= it
->second
| (action
<<16);
5552 m_actionTriggers
[hashMapKey
] = action
;
5555 void wxPropertyGrid
::ClearActionTriggers( int action
)
5557 wxPGHashMapI2I
::iterator it
;
5562 didSomething
= false;
5564 for ( it
= m_actionTriggers
.begin();
5565 it
!= m_actionTriggers
.end();
5568 if ( it
->second
== action
)
5570 m_actionTriggers
.erase(it
);
5571 didSomething
= true;
5576 while ( didSomething
);
5579 void wxPropertyGrid
::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5582 // Handles key event when editor control is not focused.
5585 wxCHECK2(!m_frozen
, return);
5587 // Travelsal between items, collapsing/expanding, etc.
5588 wxPGProperty
* selected
= GetSelection();
5589 int keycode
= event
.GetKeyCode();
5590 bool editorFocused
= IsEditorFocused();
5592 if ( keycode
== WXK_TAB
)
5594 wxWindow
* mainControl
;
5596 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5597 mainControl
= GetParent();
5601 if ( !event
.ShiftDown() )
5603 if ( !editorFocused
&& m_wndEditor
)
5605 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5609 // Tab traversal workaround for platforms on which
5610 // wxWindow::Navigate() may navigate into first child
5611 // instead of next sibling. Does not work perfectly
5612 // in every scenario (for instance, when property grid
5613 // is either first or last control).
5614 #if defined(__WXGTK__)
5615 wxWindow
* sibling
= mainControl
->GetNextSibling();
5617 sibling
->SetFocusFromKbd();
5619 Navigate(wxNavigationKeyEvent
::IsForward
);
5625 if ( editorFocused
)
5631 #if defined(__WXGTK__)
5632 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5634 sibling
->SetFocusFromKbd();
5636 Navigate(wxNavigationKeyEvent
::IsBackward
);
5644 // Ignore Alt and Control when they are down alone
5645 if ( keycode
== WXK_ALT
||
5646 keycode
== WXK_CONTROL
)
5653 int action
= KeyEventToActions(event
, &secondAction
);
5655 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5658 // Esc cancels any changes
5659 if ( IsEditorsValueModified() )
5661 EditorsValueWasNotModified();
5663 // Update the control as well
5664 selected
->GetEditorClass()->
5665 SetControlStringValue( selected
,
5667 selected
->GetDisplayedString() );
5670 OnValidationFailureReset(selected
);
5676 // Except for TAB, ESC, and any keys specifically dedicated to
5677 // wxPropertyGrid itself, handle child control events in child control.
5679 wxPGFindInVector(m_dedicatedKeys
, keycode
) == wxNOT_FOUND
)
5681 // Only propagate event if it had modifiers
5682 if ( !event
.HasModifiers() )
5684 event
.StopPropagation();
5690 bool wasHandled
= false;
5695 if ( ButtonTriggerKeyTest(action
, event
) )
5698 wxPGProperty
* p
= selected
;
5700 if ( action
== wxPG_ACTION_EDIT
&& !editorFocused
)
5702 DoSelectProperty( p
, wxPG_SEL_FOCUS
);
5706 // Travel and expand/collapse
5709 if ( p
->GetChildCount() )
5711 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5713 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5716 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5718 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5725 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5729 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5735 if ( selectDir
>= -1 )
5737 p
= wxPropertyGridIterator
::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5741 int reopenLabelEditorCol
= -1;
5743 if ( editorFocused
)
5745 // If editor was focused, then make the next editor
5747 selFlags
|= wxPG_SEL_FOCUS
;
5751 // Also maintain the same label editor focus state
5752 if ( m_labelEditor
)
5753 reopenLabelEditorCol
= m_selColumn
;
5756 DoSelectProperty(p
, selFlags
);
5758 if ( reopenLabelEditorCol
>= 0 )
5759 DoBeginLabelEdit(reopenLabelEditorCol
);
5766 // If nothing was selected, select the first item now
5767 // (or navigate out of tab).
5768 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5770 wxPGProperty
* p
= wxPropertyGridInterface
::GetFirst();
5771 if ( p
) DoSelectProperty(p
);
5780 // -----------------------------------------------------------------------
5782 void wxPropertyGrid
::OnKey( wxKeyEvent
&event
)
5784 // If there was editor open and focused, then this event should not
5785 // really be processed here.
5786 if ( IsEditorFocused() )
5788 // However, if event had modifiers, it is probably still best
5790 if ( event
.HasModifiers() )
5793 event
.StopPropagation();
5797 HandleKeyEvent(event
, false);
5800 // -----------------------------------------------------------------------
5802 bool wxPropertyGrid
::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5807 action
= KeyEventToActions(event
, &secondAction
);
5810 // Does the keycode trigger button?
5811 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5814 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5815 GetEventHandler()->AddPendingEvent(evt
);
5822 // -----------------------------------------------------------------------
5824 void wxPropertyGrid
::OnChildKeyDown( wxKeyEvent
&event
)
5826 HandleKeyEvent(event
, true);
5829 // -----------------------------------------------------------------------
5830 // wxPropertyGrid miscellaneous event handling
5831 // -----------------------------------------------------------------------
5833 void wxPropertyGrid
::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5836 // Check if the focus is in this control or one of its children
5837 wxWindow
* newFocused
= wxWindow
::FindFocus();
5839 if ( newFocused
!= m_curFocused
)
5840 HandleFocusChange( newFocused
);
5843 // Check if top-level parent has changed
5844 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5846 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5852 // Resolve pending property removals
5853 if ( m_deletedProperties
.size() > 0 )
5855 wxArrayPGProperty
& arr
= m_deletedProperties
;
5856 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5858 DeleteProperty(arr
[i
]);
5862 if ( m_removedProperties
.size() > 0 )
5864 wxArrayPGProperty
& arr
= m_removedProperties
;
5865 for ( unsigned int i
=0; i
<arr
.size(); i
++ )
5867 RemoveProperty(arr
[i
]);
5873 bool wxPropertyGrid
::IsEditorFocused() const
5875 wxWindow
* focus
= wxWindow
::FindFocus();
5877 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5878 focus
== GetEditorControl() )
5884 // Called by focus event handlers. newFocused is the window that becomes focused.
5885 void wxPropertyGrid
::HandleFocusChange( wxWindow
* newFocused
)
5888 // Never allow focus to be changed when handling editor event.
5889 // Especially because they may be displaing a dialog which
5890 // could cause all kinds of weird (native) focus changes.
5891 if ( HasInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
5894 unsigned int oldFlags
= m_iFlags
;
5895 bool wasEditorFocused
= false;
5896 wxWindow
* wndEditor
= m_wndEditor
;
5898 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5900 wxWindow
* parent
= newFocused
;
5902 // This must be one of nextFocus' parents.
5905 if ( parent
== wndEditor
)
5907 wasEditorFocused
= true;
5909 // Use m_eventObject, which is either wxPropertyGrid or
5910 // wxPropertyGridManager, as appropriate.
5911 else if ( parent
== m_eventObject
)
5913 m_iFlags
|= wxPG_FL_FOCUSED
;
5916 parent
= parent
->GetParent();
5919 // Notify editor control when it receives a focus
5920 if ( wasEditorFocused
&& m_curFocused
!= newFocused
)
5922 wxPGProperty
* p
= GetSelection();
5925 const wxPGEditor
* editor
= p
->GetEditorClass();
5926 ResetEditorAppearance();
5927 editor
->OnFocus(p
, GetEditorControl());
5931 m_curFocused
= newFocused
;
5933 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5934 (oldFlags
& wxPG_FL_FOCUSED
) )
5936 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5938 // Need to store changed value
5939 CommitChangesFromEditor();
5945 // Preliminary code for tab-order respecting
5946 // tab-traversal (but should be moved to
5949 wxWindow* prevFocus = event.GetWindow();
5950 wxWindow* useThis = this;
5951 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5952 useThis = GetParent();
5955 prevFocus->GetParent() == useThis->GetParent() )
5957 wxList& children = useThis->GetParent()->GetChildren();
5959 wxNode* node = children.Find(prevFocus);
5961 if ( node->GetNext() &&
5962 useThis == node->GetNext()->GetData() )
5963 DoSelectProperty(GetFirst());
5964 else if ( node->GetPrevious () &&
5965 useThis == node->GetPrevious()->GetData() )
5966 DoSelectProperty(GetLastProperty());
5973 wxPGProperty
* selected
= GetSelection();
5974 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5975 DrawItem( selected
);
5979 void wxPropertyGrid
::OnFocusEvent( wxFocusEvent
& event
)
5981 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5982 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5983 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5984 //else if ( event.GetWindow() )
5986 HandleFocusChange(event
.GetWindow());
5991 // -----------------------------------------------------------------------
5993 void wxPropertyGrid
::OnChildFocusEvent( wxChildFocusEvent
& event
)
5995 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5999 // -----------------------------------------------------------------------
6001 void wxPropertyGrid
::OnScrollEvent( wxScrollWinEvent
&event
)
6003 m_iFlags
|= wxPG_FL_SCROLLED
;
6008 // -----------------------------------------------------------------------
6010 void wxPropertyGrid
::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
6012 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
6014 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
6018 // -----------------------------------------------------------------------
6019 // Property editor related functions
6020 // -----------------------------------------------------------------------
6022 // noDefCheck = true prevents infinite recursion.
6023 wxPGEditor
* wxPropertyGrid
::DoRegisterEditorClass( wxPGEditor
* editorClass
,
6024 const wxString
& editorName
,
6027 wxASSERT( editorClass
);
6029 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
6030 RegisterDefaultEditors();
6032 wxString name
= editorName
;
6034 name
= editorClass
->GetName();
6036 // Existing editor under this name?
6037 wxPGHashMapS2P
::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
6039 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
6041 // If this name was already used, try class name.
6042 name
= editorClass
->GetClassInfo()->GetClassName();
6043 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
6046 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
6047 (wxPGEditor
*) vt_it
->second
,
6048 "Editor with given name was already registered" );
6050 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
6055 // Use this in RegisterDefaultEditors.
6056 #define wxPGRegisterDefaultEditorClass(EDITOR) \
6057 if ( wxPGEditor_##EDITOR == NULL ) \
6059 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
6060 new wxPG##EDITOR##Editor, true ); \
6063 // Registers all default editor classes
6064 void wxPropertyGrid
::RegisterDefaultEditors()
6066 wxPGRegisterDefaultEditorClass( TextCtrl
);
6067 wxPGRegisterDefaultEditorClass( Choice
);
6068 wxPGRegisterDefaultEditorClass( ComboBox
);
6069 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
6070 #if wxPG_INCLUDE_CHECKBOX
6071 wxPGRegisterDefaultEditorClass( CheckBox
);
6073 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
6075 // Register SpinCtrl etc. editors before use
6076 RegisterAdditionalEditors();
6079 // -----------------------------------------------------------------------
6080 // wxPGStringTokenizer
6081 // Needed to handle C-style string lists (e.g. "str1" "str2")
6082 // -----------------------------------------------------------------------
6084 wxPGStringTokenizer
::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
6085 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
6089 wxPGStringTokenizer
::~wxPGStringTokenizer()
6093 bool wxPGStringTokenizer
::HasMoreTokens()
6095 const wxString
& str
= *m_str
;
6097 wxString
::const_iterator i
= m_curPos
;
6099 wxUniChar delim
= m_delimeter
;
6101 wxUniChar prev_a
= wxT('\0');
6103 bool inToken
= false;
6105 while ( i
!= str
.end() )
6114 m_readyToken
.clear();
6119 if ( prev_a
!= wxT('\\') )
6123 if ( a
!= wxT('\\') )
6143 m_curPos
= str
.end();
6151 wxString wxPGStringTokenizer
::GetNextToken()
6153 return m_readyToken
;
6156 // -----------------------------------------------------------------------
6158 // -----------------------------------------------------------------------
6160 wxPGChoiceEntry
::wxPGChoiceEntry()
6161 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
6165 // -----------------------------------------------------------------------
6167 // -----------------------------------------------------------------------
6169 wxPGChoicesData
::wxPGChoicesData()
6173 wxPGChoicesData
::~wxPGChoicesData()
6178 void wxPGChoicesData
::Clear()
6183 void wxPGChoicesData
::CopyDataFrom( wxPGChoicesData
* data
)
6185 wxASSERT( m_items
.size() == 0 );
6187 m_items
= data
->m_items
;
6190 wxPGChoiceEntry
& wxPGChoicesData
::Insert( int index
,
6191 const wxPGChoiceEntry
& item
)
6193 wxVector
<wxPGChoiceEntry
>::iterator it
;
6197 index
= (int) m_items
.size();
6201 it
= m_items
.begin() + index
;
6204 m_items
.insert(it
, item
);
6206 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
6208 // Need to fix value?
6209 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
6210 ownEntry
.SetValue(index
);
6215 // -----------------------------------------------------------------------
6216 // wxPropertyGridEvent
6217 // -----------------------------------------------------------------------
6219 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
6222 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
6223 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
6224 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
6225 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
6226 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
6227 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
6228 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
6229 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
6230 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
6231 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
6232 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
6233 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
6234 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
6235 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
6237 // -----------------------------------------------------------------------
6239 void wxPropertyGridEvent
::Init()
6241 m_validationInfo
= NULL
;
6244 m_wasVetoed
= false;
6247 // -----------------------------------------------------------------------
6249 wxPropertyGridEvent
::wxPropertyGridEvent(wxEventType commandType
, int id
)
6250 : wxCommandEvent(commandType
,id
)
6256 // -----------------------------------------------------------------------
6258 wxPropertyGridEvent
::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6259 : wxCommandEvent(event
)
6261 m_eventType
= event
.GetEventType();
6262 m_eventObject
= event
.m_eventObject
;
6264 OnPropertyGridSet();
6265 m_property
= event
.m_property
;
6266 m_validationInfo
= event
.m_validationInfo
;
6267 m_canVeto
= event
.m_canVeto
;
6268 m_wasVetoed
= event
.m_wasVetoed
;
6271 // -----------------------------------------------------------------------
6273 void wxPropertyGridEvent
::OnPropertyGridSet()
6279 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6281 m_pg
->m_liveEvents
.push_back(this);
6284 // -----------------------------------------------------------------------
6286 wxPropertyGridEvent
::~wxPropertyGridEvent()
6291 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
6294 // Use iterate from the back since it is more likely that the event
6295 // being desroyed is at the end of the array.
6296 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
6298 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
6300 if ( liveEvents
[i
] == this )
6302 liveEvents
.erase(liveEvents
.begin() + i
);
6309 // -----------------------------------------------------------------------
6311 wxEvent
* wxPropertyGridEvent
::Clone() const
6313 return new wxPropertyGridEvent( *this );
6316 // -----------------------------------------------------------------------
6317 // wxPropertyGridPopulator
6318 // -----------------------------------------------------------------------
6320 wxPropertyGridPopulator
::wxPropertyGridPopulator()
6324 wxPGGlobalVars
->m_offline
++;
6327 // -----------------------------------------------------------------------
6329 void wxPropertyGridPopulator
::SetState( wxPropertyGridPageState
* state
)
6332 m_propHierarchy
.clear();
6335 // -----------------------------------------------------------------------
6337 void wxPropertyGridPopulator
::SetGrid( wxPropertyGrid
* pg
)
6343 // -----------------------------------------------------------------------
6345 wxPropertyGridPopulator
::~wxPropertyGridPopulator()
6348 // Free unused sets of choices
6349 wxPGHashMapS2P
::iterator it
;
6351 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6353 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6360 m_pg
->GetPanel()->Refresh();
6362 wxPGGlobalVars
->m_offline
--;
6365 // -----------------------------------------------------------------------
6367 wxPGProperty
* wxPropertyGridPopulator
::Add( const wxString
& propClass
,
6368 const wxString
& propLabel
,
6369 const wxString
& propName
,
6370 const wxString
* propValue
,
6371 wxPGChoices
* pChoices
)
6373 wxClassInfo
* classInfo
= wxClassInfo
::FindClass(propClass
);
6374 wxPGProperty
* parent
= GetCurParent();
6376 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6378 ProcessError(wxString
::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6382 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6384 ProcessError(wxString
::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6388 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6390 property
->SetLabel(propLabel
);
6391 property
->DoSetName(propName
);
6393 if ( pChoices
&& pChoices
->IsOk() )
6394 property
->SetChoices(*pChoices
);
6396 m_state
->DoInsert(parent
, -1, property
);
6399 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
6400 wxPG_PROGRAMMATIC_VALUE
);
6405 // -----------------------------------------------------------------------
6407 void wxPropertyGridPopulator
::AddChildren( wxPGProperty
* property
)
6409 m_propHierarchy
.push_back(property
);
6410 DoScanForChildren();
6411 m_propHierarchy
.pop_back();
6414 // -----------------------------------------------------------------------
6416 wxPGChoices wxPropertyGridPopulator
::ParseChoices( const wxString
& choicesString
,
6417 const wxString
& idString
)
6419 wxPGChoices choices
;
6422 if ( choicesString
[0] == wxT('@') )
6424 wxString ids
= choicesString
.substr(1);
6425 wxPGHashMapS2P
::iterator it
= m_dictIdChoices
.find(ids
);
6426 if ( it
== m_dictIdChoices
.end() )
6427 ProcessError(wxString
::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6429 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6434 if ( !idString
.empty() )
6436 wxPGHashMapS2P
::iterator it
= m_dictIdChoices
.find(idString
);
6437 if ( it
!= m_dictIdChoices
.end() )
6439 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6446 // Parse choices string
6447 wxString
::const_iterator it
= choicesString
.begin();
6451 bool labelValid
= false;
6453 for ( ; it
!= choicesString
.end(); ++it
)
6459 if ( c
== wxT('"') )
6464 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6465 choices
.Add(label
, l
);
6468 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6473 else if ( c
== wxT('=') )
6480 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6487 if ( c
== wxT('"') )
6500 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6501 choices
.Add(label
, l
);
6504 if ( !choices
.IsOk() )
6506 choices
.EnsureData();
6510 if ( !idString
.empty() )
6511 m_dictIdChoices
[idString
] = choices
.GetData();
6518 // -----------------------------------------------------------------------
6520 bool wxPropertyGridPopulator
::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6522 if ( s
.Last() == wxT('%') )
6524 wxString s2
= s
.substr(0,s
.length()-1);
6526 if ( s2
.ToLong(&val
, 10) )
6528 *pval
= (val
*max
)/100;
6534 return s
.ToLong(pval
, 10);
6537 // -----------------------------------------------------------------------
6539 bool wxPropertyGridPopulator
::AddAttribute( const wxString
& name
,
6540 const wxString
& type
,
6541 const wxString
& value
)
6543 int l
= m_propHierarchy
.size();
6547 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6548 wxString valuel
= value
.Lower();
6556 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6558 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6560 else if ( value
.ToLong(&v
, 0) )
6567 if ( type
== wxT("string") )
6571 else if ( type
== wxT("int") )
6574 value
.ToLong(&v
, 0);
6577 else if ( type
== wxT("bool") )
6579 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6586 ProcessError(wxString
::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6591 p
->SetAttribute( name
, variant
);
6596 // -----------------------------------------------------------------------
6598 void wxPropertyGridPopulator
::ProcessError( const wxString
& msg
)
6600 wxLogError(_("Error in resource: %s"),msg
.c_str());
6603 // -----------------------------------------------------------------------
6605 #endif // wxUSE_PROPGRID