1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
68 #include "wx/msw/private.h"
71 // Two pics for the expand / collapse buttons.
72 // Files are not supplied with this project (since it is
73 // recommended to use either custom or native rendering).
74 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
75 // and copy xpm files from archive to wxPropertyGrid src directory
76 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
77 // and set wxPG_USE_RENDERER_NATIVE to 0).
78 #ifndef wxPG_ICON_WIDTH
79 #if defined(__WXMAC__)
80 #include "mac_collapse.xpm"
81 #include "mac_expand.xpm"
82 #elif defined(__WXGTK__)
83 #include "linux_collapse.xpm"
84 #include "linux_expand.xpm"
86 #include "default_collapse.xpm"
87 #include "default_expand.xpm"
92 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
93 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
94 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
95 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
96 #define wxPG_YSPACING_MIN 1
97 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
98 // but causes normal combobox to spill out under MSW
100 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
102 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
103 // Must be larger than largest control border
107 #define wxPG_DEFAULT_CURSOR wxNullCursor
110 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
112 //#define wxPG_HIDER_BUTTON_HEIGHT 25
114 #define wxPG_PIXELS_PER_UNIT m_lineHeight
116 #ifdef wxPG_ICON_WIDTH
117 #define m_iconHeight m_iconWidth
120 //#define wxPG_TOOLTIP_DELAY 1000
122 // -----------------------------------------------------------------------
125 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
127 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
130 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
133 // -----------------------------------------------------------------------
135 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
137 // -----------------------------------------------------------------------
138 // Statics in one class for easy destruction.
139 // -----------------------------------------------------------------------
141 #include "wx/module.h"
143 class wxPGGlobalVarsClassManager
: public wxModule
145 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
147 wxPGGlobalVarsClassManager() {}
148 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
149 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
152 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
155 // When wxPG is loaded dynamically after the application is already running
156 // then the built-in module system won't pick this one up. Add it manually.
157 void wxPGInitResourceModule()
159 wxModule
* module = new wxPGGlobalVarsClassManager
;
161 wxModule::RegisterModule(module);
164 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
167 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
169 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
171 m_boolChoices
.Add(_("False"));
172 m_boolChoices
.Add(_("True"));
174 m_fontFamilyChoices
= NULL
;
176 m_defaultRenderer
= new wxPGDefaultRenderer();
178 m_autoGetTranslation
= false;
186 // Prepare some shared variants
187 m_vEmptyString
= wxString();
189 m_vMinusOne
= (long) -1;
193 // Prepare cached string constants
194 m_strstring
= wxS("string");
195 m_strlong
= wxS("long");
196 m_strbool
= wxS("bool");
197 m_strlist
= wxS("list");
198 m_strDefaultValue
= wxS("DefaultValue");
199 m_strMin
= wxS("Min");
200 m_strMax
= wxS("Max");
201 m_strUnits
= wxS("Units");
202 m_strInlineHelp
= wxS("InlineHelp");
208 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
212 delete m_defaultRenderer
;
214 // This will always have one ref
215 delete m_fontFamilyChoices
;
218 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
219 delete ((wxValidator
*)m_arrValidators
[i
]);
223 // Destroy value type class instances.
224 wxPGHashMapS2P::iterator vt_it
;
226 // Destroy editor class instances.
227 // iterate over all the elements in the class
228 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
230 delete ((wxPGEditor
*)vt_it
->second
);
233 delete wxPGProperty::sm_wxPG_LABEL
;
236 void wxPropertyGridInitGlobalsIfNeeded()
240 // -----------------------------------------------------------------------
242 // -----------------------------------------------------------------------
245 // wxPGCanvas acts as a graphics sub-window of the
246 // wxScrolledWindow that wxPropertyGrid is.
248 class wxPGCanvas
: public wxPanel
251 wxPGCanvas() : wxPanel()
254 virtual ~wxPGCanvas() { }
257 void OnMouseMove( wxMouseEvent
&event
)
259 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
260 pg
->OnMouseMove( event
);
263 void OnMouseClick( wxMouseEvent
&event
)
265 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
266 pg
->OnMouseClick( event
);
269 void OnMouseUp( wxMouseEvent
&event
)
271 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
272 pg
->OnMouseUp( event
);
275 void OnMouseRightClick( wxMouseEvent
&event
)
277 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
278 pg
->OnMouseRightClick( event
);
281 void OnMouseDoubleClick( wxMouseEvent
&event
)
283 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
284 pg
->OnMouseDoubleClick( event
);
287 void OnKey( wxKeyEvent
& event
)
289 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
293 void OnPaint( wxPaintEvent
& event
);
295 // Always be focussable, even with child windows
296 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
297 { wxPanel::SetCanFocus(true); }
301 DECLARE_EVENT_TABLE()
302 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
306 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
308 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
309 EVT_MOTION(wxPGCanvas::OnMouseMove
)
310 EVT_PAINT(wxPGCanvas::OnPaint
)
311 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
312 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
313 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
314 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
315 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
319 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
321 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
322 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
326 // Don't paint after destruction has begun
327 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
330 // Update everything inside the box
331 wxRect r
= GetUpdateRegion().GetBox();
333 // FIXME: This is just a workaround for a bug that causes splitters not
334 // to paint when other windows are being dragged over the grid.
335 wxRect fullRect
= GetRect();
337 r
.width
= fullRect
.width
;
339 // Repaint this rectangle
340 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
342 // We assume that the size set when grid is shown
343 // is what is desired.
344 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
347 // -----------------------------------------------------------------------
349 // -----------------------------------------------------------------------
351 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
353 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
354 EVT_IDLE(wxPropertyGrid::OnIdle
)
355 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
356 EVT_PAINT(wxPropertyGrid::OnPaint
)
357 EVT_SIZE(wxPropertyGrid::OnResize
)
358 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
359 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
360 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
361 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
362 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
363 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
364 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
365 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
369 // -----------------------------------------------------------------------
371 wxPropertyGrid::wxPropertyGrid()
377 // -----------------------------------------------------------------------
379 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
384 const wxString
& name
)
388 Create(parent
,id
,pos
,size
,style
,name
);
391 // -----------------------------------------------------------------------
393 bool wxPropertyGrid::Create( wxWindow
*parent
,
398 const wxString
& name
)
401 if ( !(style
&wxBORDER_MASK
) )
402 style
|= wxSIMPLE_BORDER
;
406 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
407 style
&= ~(wxTAB_TRAVERSAL
);
408 style
|= wxWANTS_CHARS
;
410 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
417 // -----------------------------------------------------------------------
420 // Initialize values to defaults
422 void wxPropertyGrid::Init1()
424 // Register editor classes, if necessary.
425 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
426 wxPropertyGrid::RegisterDefaultEditors();
430 m_wndEditor
= m_wndEditor2
= NULL
;
434 m_labelEditor
= NULL
;
435 m_labelEditorProperty
= NULL
;
436 m_eventObject
= this;
438 m_sortFunction
= NULL
;
439 m_inDoPropertyChanged
= 0;
440 m_inCommitChangesFromEditor
= 0;
441 m_inDoSelectProperty
= 0;
442 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
448 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
449 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
450 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
451 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
452 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
453 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
454 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
455 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
456 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
458 m_coloursCustomized
= 0;
463 #if wxPG_DOUBLE_BUFFER
464 m_doubleBuffer
= NULL
;
467 #ifndef wxPG_ICON_WIDTH
473 m_iconWidth
= wxPG_ICON_WIDTH
;
478 m_gutterWidth
= wxPG_GUTTER_MIN
;
479 m_subgroup_extramargin
= 10;
483 m_width
= m_height
= 0;
485 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
488 m_chgInfo_changedProperty
= NULL
;
491 // -----------------------------------------------------------------------
494 // Initialize after parent etc. set
496 void wxPropertyGrid::Init2()
498 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
501 // Smaller controls on Mac
502 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
505 // Now create state, if one didn't exist already
506 // (wxPropertyGridManager might have created it for us).
509 m_pState
= CreateState();
510 m_pState
->m_pPropGrid
= this;
511 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
514 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
515 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
517 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
519 m_pState
->InitNonCatMode();
521 m_pState
->m_properties
= m_pState
->m_abcArray
;
524 GetClientSize(&m_width
,&m_height
);
526 #ifndef wxPG_ICON_WIDTH
527 // create two bitmap nodes for drawing
528 m_expandbmp
= new wxBitmap(expand_xpm
);
529 m_collbmp
= new wxBitmap(collapse_xpm
);
531 // calculate average font height for bitmap centering
533 m_iconWidth
= m_expandbmp
->GetWidth();
534 m_iconHeight
= m_expandbmp
->GetHeight();
537 m_curcursor
= wxCURSOR_ARROW
;
538 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
540 // adjust bitmap icon y position so they are centered
541 m_vspacing
= wxPG_DEFAULT_VSPACING
;
543 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
545 // Allocate cell datas indirectly by calling setter
546 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
547 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
551 // This helps with flicker
552 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
554 // Hook the top-level parent
559 // set virtual size to this window size
560 wxSize wndsize
= GetSize();
561 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
563 m_timeCreated
= ::wxGetLocalTimeMillis();
565 m_canvas
= new wxPGCanvas();
566 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
567 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
568 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
570 m_iFlags
|= wxPG_FL_INITIALIZED
;
572 m_ncWidth
= wndsize
.GetWidth();
574 // Need to call OnResize handler or size given in constructor/Create
576 wxSizeEvent
sizeEvent(wndsize
,0);
580 // -----------------------------------------------------------------------
582 wxPropertyGrid::~wxPropertyGrid()
586 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
588 // This should do prevent things from going too badly wrong
589 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
591 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
592 m_canvas
->ReleaseMouse();
594 // Call with NULL to disconnect event handling
595 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
599 wxASSERT_MSG( !IsEditorsValueModified(),
600 wxS("Most recent change in property editor was ")
601 wxS("lost!!! (if you don't want this to happen, ")
602 wxS("close your frames and dialogs using ")
603 wxS("Close(false).)") );
606 #if wxPG_DOUBLE_BUFFER
607 if ( m_doubleBuffer
)
608 delete m_doubleBuffer
;
611 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
614 delete m_cursorSizeWE
;
616 #ifndef wxPG_ICON_WIDTH
621 // Delete common value records
622 for ( i
=0; i
<m_commonValues
.size(); i
++ )
624 delete GetCommonValue(i
);
628 // -----------------------------------------------------------------------
630 bool wxPropertyGrid::Destroy()
632 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
633 m_canvas
->ReleaseMouse();
635 return wxScrolledWindow::Destroy();
638 // -----------------------------------------------------------------------
640 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
642 return new wxPropertyGridPageState();
645 // -----------------------------------------------------------------------
646 // wxPropertyGrid overridden wxWindow methods
647 // -----------------------------------------------------------------------
649 void wxPropertyGrid::SetWindowStyleFlag( long style
)
651 long old_style
= m_windowStyle
;
653 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
655 wxASSERT( m_pState
);
657 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
660 EnableCategories( true );
662 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
664 // Disable categories
665 EnableCategories( false );
667 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
673 PrepareAfterItemsAdded();
675 m_pState
->m_itemsAdded
= 1;
677 #if wxPG_SUPPORT_TOOLTIPS
678 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
684 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
685 SetToolTip ( tooltip );
686 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
689 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
694 m_canvas
->SetToolTip( NULL
);
699 wxScrolledWindow::SetWindowStyleFlag ( style
);
701 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
703 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
705 CalculateFontAndBitmapStuff( m_vspacing
);
711 // -----------------------------------------------------------------------
713 void wxPropertyGrid::Freeze()
717 wxScrolledWindow::Freeze();
722 // -----------------------------------------------------------------------
724 void wxPropertyGrid::Thaw()
730 wxScrolledWindow::Thaw();
731 RecalculateVirtualSize();
732 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
736 // Force property re-selection
737 // NB: We must copy the selection.
738 wxArrayPGProperty selection
= m_pState
->m_selection
;
739 DoSetSelection(selection
, wxPG_SEL_FORCE
);
743 // -----------------------------------------------------------------------
745 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
747 wxCHECK( prop
, false );
749 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
750 return DoSelectProperty(prop
, selFlags
);
752 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
754 if ( !selection
.size() )
756 return DoSelectProperty(prop
, selFlags
);
760 // For categories, only one can be selected at a time
761 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
764 selection
.push_back(prop
);
766 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
768 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
777 // -----------------------------------------------------------------------
779 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
781 wxCHECK( prop
, false );
784 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
785 if ( selection
.size() <= 1 )
787 res
= DoSelectProperty(NULL
, selFlags
);
791 m_pState
->DoRemoveFromSelection(prop
);
799 // -----------------------------------------------------------------------
801 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
802 unsigned int colIndex
,
803 unsigned int selFlags
)
806 // NB: Enable following if label editor background colour is
807 // ever changed to any other than m_colSelBack.
809 // We use this workaround to prevent visible flicker when editing
810 // a cell. Atleast on wxMSW, there is a difficult to find
811 // (and perhaps prevent) redraw somewhere between making property
812 // selected and enabling label editing.
814 //wxColour prevColSelBack = m_colSelBack;
815 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
821 res
= DoSelectProperty(prop
, selFlags
);
826 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
828 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
830 res
= DoAddToSelection(prop
, selFlags
);
834 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
836 DoBeginLabelEdit(colIndex
, selFlags
);
840 //m_colSelBack = prevColSelBack;
844 // -----------------------------------------------------------------------
846 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
847 unsigned int colIndex
,
848 wxMouseEvent
* mouseEvent
,
851 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
853 bool addToExistingSelection
;
855 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
859 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
860 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
862 // Allow right-click for context menu without
863 // disturbing the selection.
864 if ( GetSelectedProperties().size() <= 1 ||
866 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
871 addToExistingSelection
= mouseEvent
->ShiftDown();
876 addToExistingSelection
= false;
881 addToExistingSelection
= false;
884 if ( addToExistingSelection
)
886 if ( !alreadySelected
)
888 res
= DoAddToSelection(prop
, selFlags
);
890 else if ( GetSelectedProperties().size() > 1 )
892 res
= DoRemoveFromSelection(prop
, selFlags
);
897 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
903 // -----------------------------------------------------------------------
905 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
908 if ( newSelection
.size() > 0 )
910 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
915 DoClearSelection(false, selFlags
);
918 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
920 DoAddToSelection(newSelection
[i
], selFlags
);
926 // -----------------------------------------------------------------------
928 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
931 wxPGProperty
* selected
= GetSelection();
932 wxCHECK_RET(selected
, wxT("No property selected"));
933 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
935 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
937 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
944 const wxPGCell
* cell
= NULL
;
945 if ( selected
->HasCell(colIndex
) )
947 cell
= &selected
->GetCell(colIndex
);
948 if ( !cell
->HasText() && colIndex
== 0 )
949 text
= selected
->GetLabel();
955 text
= selected
->GetLabel();
957 cell
= &selected
->GetOrCreateCell(colIndex
);
960 if ( cell
&& cell
->HasText() )
961 text
= cell
->GetText();
963 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
965 m_selColumn
= colIndex
;
967 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
969 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
977 wxWindowID id
= tc
->GetId();
978 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
979 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
981 tc
->Connect(id
, wxEVT_KEY_DOWN
,
982 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
987 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
988 m_labelEditorProperty
= selected
;
991 // -----------------------------------------------------------------------
994 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
996 DoEndLabelEdit(true);
999 // -----------------------------------------------------------------------
1001 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1003 int keycode
= event
.GetKeyCode();
1005 if ( keycode
== WXK_ESCAPE
)
1007 DoEndLabelEdit(false);
1015 // -----------------------------------------------------------------------
1017 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1019 if ( !m_labelEditor
)
1022 wxPGProperty
* prop
= m_labelEditorProperty
;
1027 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1029 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1030 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1031 prop
, NULL
, selFlags
,
1036 wxString text
= m_labelEditor
->GetValue();
1037 wxPGCell
* cell
= NULL
;
1038 if ( prop
->HasCell(m_selColumn
) )
1040 cell
= &prop
->GetCell(m_selColumn
);
1044 if ( m_selColumn
== 0 )
1045 prop
->SetLabel(text
);
1047 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1051 cell
->SetText(text
);
1056 DestroyEditorWnd(m_labelEditor
);
1057 m_labelEditor
= NULL
;
1058 m_labelEditorProperty
= NULL
;
1063 // -----------------------------------------------------------------------
1065 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1067 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1068 OnTLPChanging(::wxGetTopLevelParent(this));
1070 OnTLPChanging(NULL
);
1072 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1074 #if defined(__WXMSW__)
1077 // Don't use WS_EX_COMPOSITED just now.
1080 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1081 hWnd = (HWND)GetParent()->GetHWND();
1083 hWnd = (HWND)GetHWND();
1085 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1086 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1089 //#elif defined(__WXGTK20__)
1091 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1092 // truly was double-buffered.
1093 if ( !this->IsDoubleBuffered() )
1095 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1099 #if wxPG_DOUBLE_BUFFER
1100 delete m_doubleBuffer
;
1101 m_doubleBuffer
= NULL
;
1106 wxScrolledWindow::SetExtraStyle( exStyle
);
1108 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1109 m_pState
->InitNonCatMode();
1111 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1112 m_windowStyle
|= wxPG_TOOLTIPS
;
1115 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1118 // -----------------------------------------------------------------------
1120 // returns the best acceptable minimal size
1121 wxSize
wxPropertyGrid::DoGetBestSize() const
1123 int lineHeight
= wxMax(15, m_lineHeight
);
1125 // don't make the grid too tall (limit height to 10 items) but don't
1126 // make it too small neither
1127 int numLines
= wxMin
1129 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1133 const wxSize sz
= wxSize(60, lineHeight
*numLines
+ 40);
1138 // -----------------------------------------------------------------------
1140 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1142 if ( newTLP
== m_tlp
)
1145 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1148 // Parent changed so let's redetermine and re-hook the
1149 // correct top-level window.
1152 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1153 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1155 m_tlpClosed
= m_tlp
;
1156 m_tlpClosedTime
= currentTime
;
1161 // Only accept new tlp if same one was not just dismissed.
1162 if ( newTLP
!= m_tlpClosed
||
1163 m_tlpClosedTime
+250 < currentTime
)
1165 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1166 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1179 // -----------------------------------------------------------------------
1181 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1183 // ClearSelection forces value validation/commit.
1184 if ( event
.CanVeto() && !DoClearSelection() )
1190 // Ok, it can close, set tlp pointer to NULL. Some other event
1191 // handler can of course veto the close, but our OnIdle() should
1192 // then be able to regain the tlp pointer.
1193 OnTLPChanging(NULL
);
1198 // -----------------------------------------------------------------------
1200 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1202 OnTLPChanging((wxWindow
*)newParent
);
1204 bool res
= wxScrolledWindow::Reparent(newParent
);
1209 // -----------------------------------------------------------------------
1210 // wxPropertyGrid Font and Colour Methods
1211 // -----------------------------------------------------------------------
1213 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1217 m_captionFont
= wxScrolledWindow::GetFont();
1219 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1220 m_subgroup_extramargin
= x
+ (x
/2);
1223 #if wxPG_USE_RENDERER_NATIVE
1224 m_iconWidth
= wxPG_ICON_WIDTH
;
1225 #elif wxPG_ICON_WIDTH
1227 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1228 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1229 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1233 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1234 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1235 m_gutterWidth
= wxPG_GUTTER_MIN
;
1238 if ( vspacing
<= 1 ) vdiv
= 12;
1239 else if ( vspacing
>= 3 ) vdiv
= 3;
1241 m_spacingy
= m_fontHeight
/ vdiv
;
1242 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1243 m_spacingy
= wxPG_YSPACING_MIN
;
1246 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1247 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1249 m_captionFont
.SetWeight(wxBOLD
);
1250 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1252 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1255 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1256 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1259 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1261 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1262 RecalculateVirtualSize();
1264 InvalidateBestSize();
1267 // -----------------------------------------------------------------------
1269 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1275 // -----------------------------------------------------------------------
1277 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1278 int ga
= 1000, int ba
= 1000,
1279 bool forceDifferent
= false)
1286 // Recursion guard (allow 2 max)
1287 static int isinside
= 0;
1289 wxCHECK_MSG( isinside
< 3,
1291 wxT("wxPGAdjustColour should not be recursively called more than once") );
1296 int g
= src
.Green();
1299 if ( r2
>255 ) r2
= 255;
1300 else if ( r2
<0) r2
= 0;
1302 if ( g2
>255 ) g2
= 255;
1303 else if ( g2
<0) g2
= 0;
1305 if ( b2
>255 ) b2
= 255;
1306 else if ( b2
<0) b2
= 0;
1308 // Make sure they are somewhat different
1309 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1310 dst
= wxPGAdjustColour(src
,-(ra
*2));
1312 dst
= wxColour(r2
,g2
,b2
);
1314 // Recursion guard (allow 2 max)
1321 static int wxPGGetColAvg( const wxColour
& col
)
1323 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1327 void wxPropertyGrid::RegainColours()
1329 if ( !(m_coloursCustomized
& 0x0002) )
1331 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1333 // Make sure colour is dark enough
1335 int colDec
= wxPGGetColAvg(col
) - 230;
1337 int colDec
= wxPGGetColAvg(col
) - 200;
1340 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1343 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1346 if ( !(m_coloursCustomized
& 0x0001) )
1347 m_colMargin
= m_colCapBack
;
1349 if ( !(m_coloursCustomized
& 0x0004) )
1356 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1357 m_colCapFore
= capForeCol
;
1358 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1361 if ( !(m_coloursCustomized
& 0x0008) )
1363 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1364 m_colPropBack
= bgCol
;
1365 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1368 if ( !(m_coloursCustomized
& 0x0010) )
1370 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1371 m_colPropFore
= fgCol
;
1372 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1375 if ( !(m_coloursCustomized
& 0x0020) )
1376 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1378 if ( !(m_coloursCustomized
& 0x0040) )
1379 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1381 if ( !(m_coloursCustomized
& 0x0080) )
1382 m_colLine
= m_colCapBack
;
1384 if ( !(m_coloursCustomized
& 0x0100) )
1385 m_colDisPropFore
= m_colCapFore
;
1387 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1390 // -----------------------------------------------------------------------
1392 void wxPropertyGrid::ResetColours()
1394 m_coloursCustomized
= 0;
1401 // -----------------------------------------------------------------------
1403 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1405 // Must disable active editor.
1408 bool res
= wxScrolledWindow::SetFont( font
);
1409 if ( res
&& GetParent()) // may not have been Create()ed yet
1411 CalculateFontAndBitmapStuff( m_vspacing
);
1418 // -----------------------------------------------------------------------
1420 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1423 m_coloursCustomized
|= 0x80;
1427 // -----------------------------------------------------------------------
1429 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1432 m_coloursCustomized
|= 0x01;
1436 // -----------------------------------------------------------------------
1438 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1440 m_colPropBack
= col
;
1441 m_coloursCustomized
|= 0x08;
1443 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1448 // -----------------------------------------------------------------------
1450 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1452 m_colPropFore
= col
;
1453 m_coloursCustomized
|= 0x10;
1455 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1460 // -----------------------------------------------------------------------
1462 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1464 m_colEmptySpace
= col
;
1469 // -----------------------------------------------------------------------
1471 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1473 m_colDisPropFore
= col
;
1474 m_coloursCustomized
|= 0x100;
1478 // -----------------------------------------------------------------------
1480 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1483 m_coloursCustomized
|= 0x20;
1487 // -----------------------------------------------------------------------
1489 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1492 m_coloursCustomized
|= 0x40;
1496 // -----------------------------------------------------------------------
1498 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1501 m_coloursCustomized
|= 0x02;
1503 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1508 // -----------------------------------------------------------------------
1510 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1513 m_coloursCustomized
|= 0x04;
1515 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1520 // -----------------------------------------------------------------------
1521 // wxPropertyGrid property adding and removal
1522 // -----------------------------------------------------------------------
1524 void wxPropertyGrid::PrepareAfterItemsAdded()
1526 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1528 m_pState
->m_itemsAdded
= 0;
1530 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1531 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1533 RecalculateVirtualSize();
1536 // -----------------------------------------------------------------------
1537 // wxPropertyGrid property operations
1538 // -----------------------------------------------------------------------
1540 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1542 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1546 bool changed
= false;
1548 // Is it inside collapsed section?
1549 if ( !p
->IsVisible() )
1552 wxPGProperty
* parent
= p
->GetParent();
1553 wxPGProperty
* grandparent
= parent
->GetParent();
1555 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1556 Expand( grandparent
);
1564 GetViewStart(&vx
,&vy
);
1565 vy
*=wxPG_PIXELS_PER_UNIT
;
1571 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1572 m_iFlags
|= wxPG_FL_SCROLLED
;
1575 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1577 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1578 m_iFlags
|= wxPG_FL_SCROLLED
;
1588 // -----------------------------------------------------------------------
1589 // wxPropertyGrid helper methods called by properties
1590 // -----------------------------------------------------------------------
1592 // Control font changer helper.
1593 void wxPropertyGrid::SetCurControlBoldFont()
1595 wxASSERT( m_wndEditor
);
1596 m_wndEditor
->SetFont( m_captionFont
);
1599 // -----------------------------------------------------------------------
1601 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1604 #if wxPG_SMALL_SCREEN
1605 // On small-screen devices, always show dialogs with default position and size.
1606 return wxDefaultPosition
;
1608 int splitterX
= GetSplitterPosition();
1612 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1614 ImprovedClientToScreen( &x
, &y
);
1616 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1617 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1624 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1634 new_y
= y
+ m_lineHeight
;
1636 return wxPoint(new_x
,new_y
);
1640 // -----------------------------------------------------------------------
1642 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1644 if ( src_str
.length() == 0 )
1650 bool prev_is_slash
= false;
1652 wxString::const_iterator i
= src_str
.begin();
1656 for ( ; i
!= src_str
.end(); ++i
)
1660 if ( a
!= wxS('\\') )
1662 if ( !prev_is_slash
)
1668 if ( a
== wxS('n') )
1671 dst_str
<< wxS('\n');
1673 dst_str
<< wxS('\n');
1676 else if ( a
== wxS('t') )
1677 dst_str
<< wxS('\t');
1681 prev_is_slash
= false;
1685 if ( prev_is_slash
)
1687 dst_str
<< wxS('\\');
1688 prev_is_slash
= false;
1692 prev_is_slash
= true;
1699 // -----------------------------------------------------------------------
1701 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1703 if ( src_str
.length() == 0 )
1709 wxString::const_iterator i
= src_str
.begin();
1710 wxUniChar prev_a
= wxS('\0');
1714 for ( ; i
!= src_str
.end(); ++i
)
1718 if ( a
>= wxS(' ') )
1720 // This surely is not something that requires an escape sequence.
1725 // This might need...
1726 if ( a
== wxS('\r') )
1728 // DOS style line end.
1729 // Already taken care below
1731 else if ( a
== wxS('\n') )
1732 // UNIX style line end.
1733 dst_str
<< wxS("\\n");
1734 else if ( a
== wxS('\t') )
1736 dst_str
<< wxS('\t');
1739 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1749 // -----------------------------------------------------------------------
1751 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1758 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1761 // -----------------------------------------------------------------------
1762 // wxPropertyGrid graphics related methods
1763 // -----------------------------------------------------------------------
1765 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1769 // Update everything inside the box
1770 wxRect r
= GetUpdateRegion().GetBox();
1772 dc
.SetPen(m_colEmptySpace
);
1773 dc
.SetBrush(m_colEmptySpace
);
1774 dc
.DrawRectangle(r
);
1777 // -----------------------------------------------------------------------
1779 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1780 wxPGProperty
* property
) const
1782 // Prepare rectangle to be used
1784 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1785 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1787 #if (wxPG_USE_RENDERER_NATIVE)
1789 #elif wxPG_ICON_WIDTH
1790 // Drawing expand/collapse button manually
1791 dc
.SetPen(m_colPropFore
);
1792 if ( property
->IsCategory() )
1793 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1795 dc
.SetBrush(m_colPropBack
);
1797 dc
.DrawRectangle( r
);
1798 int _y
= r
.y
+(m_iconWidth
/2);
1799 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1804 if ( property
->IsExpanded() )
1806 // wxRenderer functions are non-mutating in nature, so it
1807 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1808 // Hopefully this does not cause problems.
1809 #if (wxPG_USE_RENDERER_NATIVE)
1810 wxRendererNative::Get().DrawTreeItemButton(
1816 #elif wxPG_ICON_WIDTH
1825 #if (wxPG_USE_RENDERER_NATIVE)
1826 wxRendererNative::Get().DrawTreeItemButton(
1832 #elif wxPG_ICON_WIDTH
1833 int _x
= r
.x
+(m_iconWidth
/2);
1834 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1840 #if (wxPG_USE_RENDERER_NATIVE)
1842 #elif wxPG_ICON_WIDTH
1845 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1849 // -----------------------------------------------------------------------
1852 // This is the one called by OnPaint event handler and others.
1853 // topy and bottomy are already unscrolled (ie. physical)
1855 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1857 unsigned int bottomy
,
1858 const wxRect
* clipRect
)
1860 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1862 m_pState
->EnsureVirtualHeight();
1864 wxRect tempClipRect
;
1867 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1868 clipRect
= &tempClipRect
;
1871 // items added check
1872 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1874 int paintFinishY
= 0;
1876 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1879 bool isBuffered
= false;
1881 #if wxPG_DOUBLE_BUFFER
1882 wxMemoryDC
* bufferDC
= NULL
;
1884 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1886 if ( !m_doubleBuffer
)
1888 paintFinishY
= clipRect
->y
;
1893 bufferDC
= new wxMemoryDC();
1895 // If nothing was changed, then just copy from double-buffer
1896 bufferDC
->SelectObject( *m_doubleBuffer
);
1906 dc
.SetClippingRegion( *clipRect
);
1907 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1910 #if wxPG_DOUBLE_BUFFER
1913 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1914 bufferDC
, 0, 0, wxCOPY
);
1915 dc
.DestroyClippingRegion(); // Is this really necessary?
1921 // Clear area beyond bottomY?
1922 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1924 dc
.SetPen(m_colEmptySpace
);
1925 dc
.SetBrush(m_colEmptySpace
);
1926 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1930 // -----------------------------------------------------------------------
1932 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1933 const wxRect
* clipRect
,
1934 bool isBuffered
) const
1936 const wxPGProperty
* firstItem
;
1937 const wxPGProperty
* lastItem
;
1939 firstItem
= DoGetItemAtY(clipRect
->y
);
1940 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1943 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1945 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1948 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1949 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1951 int lh
= m_lineHeight
;
1954 int lastItemBottomY
;
1956 firstItemTopY
= clipRect
->y
;
1957 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1959 // Align y coordinates to item boundaries
1960 firstItemTopY
-= firstItemTopY
% lh
;
1961 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1962 lastItemBottomY
-= 1;
1964 // Entire range outside scrolled, visible area?
1965 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1968 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1972 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1973 firstItem->GetLabel().c_str(),
1974 lastItem->GetLabel().c_str(),
1975 (int)(lastItemBottomY - firstItemTopY),
1977 (unsigned long)clipRect );
1982 long windowStyle
= m_windowStyle
;
1988 // With wxPG_DOUBLE_BUFFER, do double buffering
1989 // - buffer's y = 0, so align cliprect and coordinates to that
1991 #if wxPG_DOUBLE_BUFFER
1997 xRelMod
= clipRect
->x
;
1998 yRelMod
= clipRect
->y
;
2001 // clipRect conversion
2006 firstItemTopY
-= yRelMod
;
2007 lastItemBottomY
-= yRelMod
;
2010 wxUnusedVar(isBuffered
);
2013 int x
= m_marginWidth
- xRelMod
;
2015 wxFont normalFont
= GetFont();
2017 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2019 bool isPgEnabled
= IsEnabled();
2022 // Prepare some pens and brushes that are often changed to.
2025 wxBrush
marginBrush(m_colMargin
);
2026 wxPen
marginPen(m_colMargin
);
2027 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2028 wxPen
linepen(m_colLine
,1,wxSOLID
);
2030 wxColour selBackCol
;
2032 selBackCol
= m_colSelBack
;
2034 selBackCol
= m_colMargin
;
2036 // pen that has same colour as text
2037 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2040 // Clear margin with background colour
2042 dc
.SetBrush( marginBrush
);
2043 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2045 dc
.SetPen( *wxTRANSPARENT_PEN
);
2046 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2049 const wxPGProperty
* firstSelected
= GetSelection();
2050 const wxPropertyGridPageState
* state
= m_pState
;
2052 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2053 bool wasSelectedPainted
= false;
2056 // TODO: Only render columns that are within clipping region.
2058 dc
.SetFont(normalFont
);
2060 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2061 int endScanBottomY
= lastItemBottomY
+ lh
;
2062 int y
= firstItemTopY
;
2065 // Pregenerate list of visible properties.
2066 wxArrayPGProperty visPropArray
;
2067 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2069 for ( ; !it
.AtEnd(); it
.Next() )
2071 const wxPGProperty
* p
= *it
;
2073 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2075 visPropArray
.push_back((wxPGProperty
*)p
);
2077 if ( y
> endScanBottomY
)
2084 visPropArray
.push_back(NULL
);
2086 wxPGProperty
* nextP
= visPropArray
[0];
2088 int gridWidth
= state
->m_width
;
2091 for ( unsigned int arrInd
=1;
2092 nextP
&& y
<= lastItemBottomY
;
2095 wxPGProperty
* p
= nextP
;
2096 nextP
= visPropArray
[arrInd
];
2098 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2099 int textMarginHere
= x
;
2100 int renderFlags
= 0;
2102 int greyDepth
= m_marginWidth
;
2103 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2104 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2106 int greyDepthX
= greyDepth
- xRelMod
;
2108 // Use basic depth if in non-categoric mode and parent is base array.
2109 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2111 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2114 // Paint margin area
2115 dc
.SetBrush(marginBrush
);
2116 dc
.SetPen(marginPen
);
2117 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2119 dc
.SetPen( linepen
);
2124 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2130 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2132 sx
+= state
->m_colWidths
[si
];
2133 dc
.DrawLine( sx
, y
, sx
, y2
);
2136 // Horizontal Line, below
2137 // (not if both this and next is category caption)
2138 if ( p
->IsCategory() &&
2139 nextP
&& nextP
->IsCategory() )
2140 dc
.SetPen(m_colCapBack
);
2142 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2145 // Need to override row colours?
2149 bool isSelected
= state
->DoIsPropertySelected(p
);
2153 // Disabled may get different colour.
2154 if ( !p
->IsEnabled() )
2156 renderFlags
|= wxPGCellRenderer::Disabled
|
2157 wxPGCellRenderer::DontUseCellFgCol
;
2158 rowFgCol
= m_colDisPropFore
;
2163 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2164 if ( p
== firstSelected
)
2165 wasSelectedPainted
= true;
2168 renderFlags
|= wxPGCellRenderer::Selected
;
2170 if ( !p
->IsCategory() )
2172 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2173 wxPGCellRenderer::DontUseCellBgCol
;
2175 if ( reallyFocused
&& p
== firstSelected
)
2177 rowFgCol
= m_colSelFore
;
2178 rowBgCol
= selBackCol
;
2180 else if ( isPgEnabled
)
2182 rowFgCol
= m_colPropFore
;
2183 if ( p
== firstSelected
)
2184 rowBgCol
= m_colMargin
;
2186 rowBgCol
= selBackCol
;
2190 rowFgCol
= m_colDisPropFore
;
2191 rowBgCol
= selBackCol
;
2198 if ( rowBgCol
.IsOk() )
2199 rowBgBrush
= wxBrush(rowBgCol
);
2201 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2202 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2205 // Fill additional margin area with background colour of first cell
2206 if ( greyDepthX
< textMarginHere
)
2208 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2210 wxPGCell
& cell
= p
->GetCell(0);
2211 rowBgCol
= cell
.GetBgCol();
2212 rowBgBrush
= wxBrush(rowBgCol
);
2214 dc
.SetBrush(rowBgBrush
);
2215 dc
.SetPen(rowBgCol
);
2216 dc
.DrawRectangle(greyDepthX
+1, y
,
2217 textMarginHere
-greyDepthX
, lh
-1);
2220 bool fontChanged
= false;
2222 // Expander button rectangle
2223 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2228 if ( p
->IsCategory() )
2230 // Captions have their cell areas merged as one
2231 dc
.SetFont(m_captionFont
);
2233 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2235 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2237 dc
.SetBrush(rowBgBrush
);
2238 dc
.SetPen(rowBgCol
);
2241 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2243 dc
.SetTextForeground(rowFgCol
);
2246 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2247 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2250 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2251 DrawExpanderButton( dc
, butRect
, p
);
2255 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2257 dc
.SetFont(m_captionFont
);
2263 int nextCellWidth
= state
->m_colWidths
[0] -
2264 (greyDepthX
- m_marginWidth
);
2265 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2266 int textXAdd
= textMarginHere
- greyDepthX
;
2268 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2270 cellRect
.width
= nextCellWidth
- 1;
2272 wxWindow
* cellEditor
= NULL
;
2273 int cellRenderFlags
= renderFlags
;
2275 // Tree Item Button (must be drawn before clipping is set up)
2276 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2277 DrawExpanderButton( dc
, butRect
, p
);
2280 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2282 if ( p
== firstSelected
)
2284 if ( ci
== 1 && m_wndEditor
)
2285 cellEditor
= m_wndEditor
;
2286 else if ( ci
== m_selColumn
&& m_labelEditor
)
2287 cellEditor
= m_labelEditor
;
2292 wxColour editorBgCol
=
2293 cellEditor
->GetBackgroundColour();
2294 dc
.SetBrush(editorBgCol
);
2295 dc
.SetPen(editorBgCol
);
2296 dc
.SetTextForeground(m_colPropFore
);
2297 dc
.DrawRectangle(cellRect
);
2299 if ( m_dragStatus
!= 0 ||
2300 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2305 dc
.SetBrush(m_colPropBack
);
2306 dc
.SetPen(m_colPropBack
);
2307 dc
.SetTextForeground(m_colDisPropFore
);
2308 if ( p
->IsEnabled() )
2309 dc
.SetTextForeground(rowFgCol
);
2311 dc
.SetTextForeground(m_colDisPropFore
);
2316 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2318 dc
.SetBrush(rowBgBrush
);
2319 dc
.SetPen(rowBgCol
);
2322 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2324 dc
.SetTextForeground(rowFgCol
);
2328 dc
.SetClippingRegion(cellRect
);
2330 cellRect
.x
+= textXAdd
;
2331 cellRect
.width
-= textXAdd
;
2336 wxPGCellRenderer
* renderer
;
2337 int cmnVal
= p
->GetCommonValue();
2338 if ( cmnVal
== -1 || ci
!= 1 )
2340 renderer
= p
->GetCellRenderer(ci
);
2341 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2346 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2347 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2352 cellX
+= state
->m_colWidths
[ci
];
2353 if ( ci
< (state
->m_colWidths
.size()-1) )
2354 nextCellWidth
= state
->m_colWidths
[ci
+1];
2356 dc
.DestroyClippingRegion(); // Is this really necessary?
2362 dc
.SetFont(normalFont
);
2367 // Refresh editor controls (seems not needed on msw)
2368 // NOTE: This code is mandatory for GTK!
2369 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2370 if ( wasSelectedPainted
)
2373 m_wndEditor
->Refresh();
2375 m_wndEditor2
->Refresh();
2382 // -----------------------------------------------------------------------
2384 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2388 if ( m_width
< 10 || m_height
< 10 ||
2389 !m_pState
->m_properties
->GetChildCount() ||
2391 return wxRect(0,0,0,0);
2396 // Return rect which encloses the given property range
2398 int visTop
= p1
->GetY();
2401 visBottom
= p2
->GetY() + m_lineHeight
;
2403 visBottom
= m_height
+ visTop
;
2405 // If seleced property is inside the range, we'll extend the range to include
2407 wxPGProperty
* selected
= GetSelection();
2410 int selectedY
= selected
->GetY();
2411 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2413 wxWindow
* editor
= GetEditorControl();
2416 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2417 if ( visBottom2
> visBottom
)
2418 visBottom
= visBottom2
;
2423 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2426 // -----------------------------------------------------------------------
2428 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2433 if ( m_pState
->m_itemsAdded
)
2434 PrepareAfterItemsAdded();
2436 wxRect r
= GetPropertyRect(p1
, p2
);
2439 m_canvas
->RefreshRect(r
);
2443 // -----------------------------------------------------------------------
2445 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2447 if ( m_pState
->DoIsPropertySelected(p
) )
2449 // NB: We must copy the selection.
2450 wxArrayPGProperty selection
= m_pState
->m_selection
;
2451 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2454 DrawItemAndChildren(p
);
2457 // -----------------------------------------------------------------------
2459 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2464 // Draw item, children, and parent too, if it is not category
2465 wxPGProperty
* parent
= p
->GetParent();
2468 !parent
->IsCategory() &&
2469 parent
->GetParent() )
2472 parent
= parent
->GetParent();
2475 DrawItemAndChildren(p
);
2478 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2480 wxCHECK_RET( p
, wxT("invalid property id") );
2482 // Do not draw if in non-visible page
2483 if ( p
->GetParentState() != m_pState
)
2486 // do not draw a single item if multiple pending
2487 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2490 // Update child control.
2491 wxPGProperty
* selected
= GetSelection();
2492 if ( selected
&& selected
->GetParent() == p
)
2495 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2497 DrawItems(p
, lastDrawn
);
2500 // -----------------------------------------------------------------------
2502 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2503 const wxRect
*rect
)
2505 PrepareAfterItemsAdded();
2507 wxWindow::Refresh(false);
2509 // TODO: Coordinate translation
2510 m_canvas
->Refresh(false, rect
);
2512 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2513 // I think this really helps only GTK+1.2
2514 if ( m_wndEditor
) m_wndEditor
->Refresh();
2515 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2519 // -----------------------------------------------------------------------
2520 // wxPropertyGrid global operations
2521 // -----------------------------------------------------------------------
2523 void wxPropertyGrid::Clear()
2525 m_pState
->DoClear();
2531 RecalculateVirtualSize();
2533 // Need to clear some area at the end
2535 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2538 // -----------------------------------------------------------------------
2540 bool wxPropertyGrid::EnableCategories( bool enable
)
2547 // Enable categories
2550 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2555 // Disable categories
2557 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2560 if ( !m_pState
->EnableCategories(enable
) )
2565 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2567 m_pState
->m_itemsAdded
= 1; // force
2568 PrepareAfterItemsAdded();
2572 m_pState
->m_itemsAdded
= 1;
2574 // No need for RecalculateVirtualSize() here - it is already called in
2575 // wxPropertyGridPageState method above.
2582 // -----------------------------------------------------------------------
2584 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2586 wxASSERT( pNewState
);
2587 wxASSERT( pNewState
->GetGrid() );
2589 if ( pNewState
== m_pState
)
2592 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2594 // Call ClearSelection() instead of DoClearSelection()
2595 // so that selection clear events are not sent.
2598 m_pState
->m_selection
= oldSelection
;
2600 bool orig_mode
= m_pState
->IsInNonCatMode();
2601 bool new_state_mode
= pNewState
->IsInNonCatMode();
2603 m_pState
= pNewState
;
2606 int pgWidth
= GetClientSize().x
;
2607 if ( HasVirtualWidth() )
2609 int minWidth
= pgWidth
;
2610 if ( pNewState
->m_width
< minWidth
)
2612 pNewState
->m_width
= minWidth
;
2613 pNewState
->CheckColumnWidths();
2619 // Just in case, fully re-center splitter
2620 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2621 pNewState
->m_fSplitterX
= -1.0;
2623 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2628 // If necessary, convert state to correct mode.
2629 if ( orig_mode
!= new_state_mode
)
2631 // This should refresh as well.
2632 EnableCategories( orig_mode
?false:true );
2634 else if ( !m_frozen
)
2636 // Refresh, if not frozen.
2637 m_pState
->PrepareAfterItemsAdded();
2639 // Reselect (Use SetSelection() instead of Do-variant so that
2640 // events won't be sent).
2641 SetSelection(m_pState
->m_selection
);
2643 RecalculateVirtualSize(0);
2647 m_pState
->m_itemsAdded
= 1;
2650 // -----------------------------------------------------------------------
2652 // Call to SetSplitterPosition will always disable splitter auto-centering
2653 // if parent window is shown.
2654 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2656 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2659 wxPropertyGridPageState
* state
= m_pState
;
2661 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2665 if ( GetSelection() )
2666 CorrectEditorWidgetSizeX();
2672 // -----------------------------------------------------------------------
2674 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2676 SetSplitterPosition( m_width
/2, true );
2677 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2678 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2681 // -----------------------------------------------------------------------
2682 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2683 // -----------------------------------------------------------------------
2685 // Returns nearest paint visible property (such that will be painted unless
2686 // window is scrolled or resized). If given property is paint visible, then
2687 // it itself will be returned
2688 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2690 int vx
,vy1
;// Top left corner of client
2691 GetViewStart(&vx
,&vy1
);
2692 vy1
*= wxPG_PIXELS_PER_UNIT
;
2694 int vy2
= vy1
+ m_height
;
2695 int propY
= p
->GetY2(m_lineHeight
);
2697 if ( (propY
+ m_lineHeight
) < vy1
)
2700 return DoGetItemAtY( vy1
);
2702 else if ( propY
> vy2
)
2705 return DoGetItemAtY( vy2
);
2708 // Itself paint visible
2713 // -----------------------------------------------------------------------
2714 // Methods related to change in value, value modification and sending events
2715 // -----------------------------------------------------------------------
2717 // commits any changes in editor of selected property
2718 // return true if validation did not fail
2719 // flags are same as with DoSelectProperty
2720 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2722 // Committing already?
2723 if ( m_inCommitChangesFromEditor
)
2726 // Don't do this if already processing editor event. It might
2727 // induce recursive dialogs and crap like that.
2728 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2730 if ( m_inDoPropertyChanged
)
2736 wxPGProperty
* selected
= GetSelection();
2739 IsEditorsValueModified() &&
2740 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2743 m_inCommitChangesFromEditor
= 1;
2745 wxVariant
variant(selected
->GetValueRef());
2746 bool valueIsPending
= false;
2748 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2749 // due to another window getting focus
2750 wxWindow
* oldFocus
= m_curFocused
;
2752 bool validationFailure
= false;
2753 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2755 m_chgInfo_changedProperty
= NULL
;
2757 // If truly modified, schedule value as pending.
2758 if ( selected
->GetEditorClass()->
2759 GetValueFromControl( variant
,
2761 GetEditorControl() ) )
2763 if ( DoEditorValidate() &&
2764 PerformValidation(selected
, variant
) )
2766 valueIsPending
= true;
2770 validationFailure
= true;
2775 EditorsValueWasNotModified();
2780 m_inCommitChangesFromEditor
= 0;
2782 if ( validationFailure
&& !forceSuccess
)
2786 oldFocus
->SetFocus();
2787 m_curFocused
= oldFocus
;
2790 res
= OnValidationFailure(selected
, variant
);
2792 // Now prevent further validation failure messages
2795 EditorsValueWasNotModified();
2796 OnValidationFailureReset(selected
);
2799 else if ( valueIsPending
)
2801 DoPropertyChanged( selected
, flags
);
2802 EditorsValueWasNotModified();
2811 // -----------------------------------------------------------------------
2813 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2817 // Runs all validation functionality.
2818 // Returns true if value passes all tests.
2821 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2823 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2825 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2830 // Adapt list to child values, if necessary
2831 wxVariant listValue
= pendingValue
;
2832 wxVariant
* pPendingValue
= &pendingValue
;
2833 wxVariant
* pList
= NULL
;
2835 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2836 // string value, then we need treat as it was changed instead
2837 // (or, in addition, as is the case with composite string parent).
2838 // This includes creating list variant for child values.
2840 wxPGProperty
* pwc
= p
->GetParent();
2841 wxPGProperty
* changedProperty
= p
;
2842 wxPGProperty
* baseChangedProperty
= changedProperty
;
2843 wxVariant bcpPendingList
;
2845 listValue
= pendingValue
;
2846 listValue
.SetName(p
->GetBaseName());
2849 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2851 wxVariantList tempList
;
2852 wxVariant
lv(tempList
, pwc
->GetBaseName());
2853 lv
.Append(listValue
);
2855 pPendingValue
= &listValue
;
2857 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2859 baseChangedProperty
= pwc
;
2860 bcpPendingList
= lv
;
2863 changedProperty
= pwc
;
2864 pwc
= pwc
->GetParent();
2868 wxPGProperty
* evtChangingProperty
= changedProperty
;
2870 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2872 value
= *pPendingValue
;
2876 // Convert list to child values
2877 pList
= pPendingValue
;
2878 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2881 wxVariant evtChangingValue
= value
;
2883 if ( flags
& SendEvtChanging
)
2885 // FIXME: After proper ValueToString()s added, remove
2886 // this. It is just a temporary fix, as evt_changing
2887 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2888 // (unless it is selected, and textctrl editor is open).
2889 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2891 evtChangingProperty
= baseChangedProperty
;
2892 if ( evtChangingProperty
!= p
)
2894 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2898 evtChangingValue
= pendingValue
;
2902 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2904 if ( changedProperty
== GetSelection() )
2906 wxWindow
* editor
= GetEditorControl();
2907 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2908 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2912 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2917 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2918 m_chgInfo_changedProperty
= changedProperty
;
2919 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2920 m_chgInfo_pendingValue
= value
;
2923 m_chgInfo_valueList
= *pList
;
2925 m_chgInfo_valueList
.MakeNull();
2927 // If changedProperty is not property which value was edited,
2928 // then call wxPGProperty::ValidateValue() for that as well.
2929 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2931 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2935 if ( flags
& SendEvtChanging
)
2937 // SendEvent returns true if event was vetoed
2938 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
2939 &evtChangingValue
) )
2943 if ( flags
& IsStandaloneValidation
)
2945 // If called in 'generic' context, we need to reset
2946 // m_chgInfo_changedProperty and write back translated value.
2947 m_chgInfo_changedProperty
= NULL
;
2948 pendingValue
= value
;
2954 // -----------------------------------------------------------------------
2956 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2958 if ( !msg
.length() )
2962 if ( !wxPGGlobalVars
->m_offline
)
2964 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2967 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2970 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2973 pStatusBar
->SetStatusText(msg
);
2981 ::wxMessageBox(msg
, wxT("Property Error"));
2984 // -----------------------------------------------------------------------
2986 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2987 wxVariant
& invalidValue
)
2989 wxWindow
* editor
= GetEditorControl();
2991 // First call property's handler
2992 property
->OnValidationFailure(invalidValue
);
2994 bool res
= DoOnValidationFailure(property
, invalidValue
);
2997 // For non-wxTextCtrl editors, we do need to revert the value
2998 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2999 property
== GetSelection() )
3001 property
->GetEditorClass()->UpdateControl(property
, editor
);
3004 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3009 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3011 int vfb
= m_validationInfo
.m_failureBehavior
;
3013 if ( vfb
& wxPG_VFB_BEEP
)
3016 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3017 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3019 unsigned int colCount
= m_pState
->GetColumnCount();
3021 // We need backup marked property's cells
3022 m_propCellsBackup
= property
->m_cells
;
3024 wxColour vfbFg
= *wxWHITE
;
3025 wxColour vfbBg
= *wxRED
;
3027 property
->EnsureCells(colCount
);
3029 for ( unsigned int i
=0; i
<colCount
; i
++ )
3031 wxPGCell
& cell
= property
->m_cells
[i
];
3032 cell
.SetFgCol(vfbFg
);
3033 cell
.SetBgCol(vfbBg
);
3036 DrawItemAndChildren(property
);
3038 if ( property
== GetSelection() )
3040 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3042 wxWindow
* editor
= GetEditorControl();
3045 editor
->SetForegroundColour(vfbFg
);
3046 editor
->SetBackgroundColour(vfbBg
);
3051 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3053 wxString msg
= m_validationInfo
.m_failureMessage
;
3055 if ( !msg
.length() )
3056 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
3058 DoShowPropertyError(property
, msg
);
3061 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3064 // -----------------------------------------------------------------------
3066 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3068 int vfb
= m_validationInfo
.m_failureBehavior
;
3070 if ( vfb
& wxPG_VFB_MARK_CELL
)
3073 property
->m_cells
= m_propCellsBackup
;
3075 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3077 if ( property
== GetSelection() && GetEditorControl() )
3079 // Calling this will recreate the control, thus resetting its colour
3080 RefreshProperty(property
);
3084 DrawItemAndChildren(property
);
3089 // -----------------------------------------------------------------------
3091 // flags are same as with DoSelectProperty
3092 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3094 if ( m_inDoPropertyChanged
)
3097 wxWindow
* editor
= GetEditorControl();
3098 wxPGProperty
* selected
= GetSelection();
3100 m_pState
->m_anyModified
= 1;
3102 m_inDoPropertyChanged
= 1;
3104 // Maybe need to update control
3105 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3107 // These values were calculated in PerformValidation()
3108 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3109 wxVariant value
= m_chgInfo_pendingValue
;
3111 wxPGProperty
* topPaintedProperty
= changedProperty
;
3113 while ( !topPaintedProperty
->IsCategory() &&
3114 !topPaintedProperty
->IsRoot() )
3116 topPaintedProperty
= topPaintedProperty
->GetParent();
3119 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3121 // Set as Modified (not if dragging just began)
3122 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3124 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3125 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3128 SetCurControlBoldFont();
3134 // Propagate updates to parent(s)
3136 wxPGProperty
* prevPwc
= NULL
;
3138 while ( prevPwc
!= topPaintedProperty
)
3140 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3142 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3145 SetCurControlBoldFont();
3149 pwc
= pwc
->GetParent();
3152 // Draw the actual property
3153 DrawItemAndChildren( topPaintedProperty
);
3156 // If value was set by wxPGProperty::OnEvent, then update the editor
3158 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3164 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3165 if ( m_wndEditor
) m_wndEditor
->Refresh();
3166 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3171 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3173 // If top parent has composite string value, then send to child parents,
3174 // starting from baseChangedProperty.
3175 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3177 pwc
= m_chgInfo_baseChangedProperty
;
3179 while ( pwc
!= changedProperty
)
3181 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3182 pwc
= pwc
->GetParent();
3186 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3188 m_inDoPropertyChanged
= 0;
3193 // -----------------------------------------------------------------------
3195 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3197 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3199 m_chgInfo_changedProperty
= NULL
;
3201 if ( PerformValidation(p
, newValue
) )
3203 DoPropertyChanged(p
);
3208 OnValidationFailure(p
, newValue
);
3214 // -----------------------------------------------------------------------
3216 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3218 wxPGProperty
* prop
= GetSelectedProperty();
3221 return wxNullVariant
;
3223 wxTextCtrl
* tc
= GetEditorTextCtrl();
3224 wxVariant value
= prop
->GetValue();
3226 if ( !tc
|| !IsEditorsValueModified() )
3229 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3232 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3233 return prop
->GetValue();
3238 // -----------------------------------------------------------------------
3240 // Runs wxValidator for the selected property
3241 bool wxPropertyGrid::DoEditorValidate()
3246 // -----------------------------------------------------------------------
3248 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3250 wxPGProperty
* selected
= GetSelection();
3252 // Somehow, event is handled after property has been deselected.
3253 // Possibly, but very rare.
3254 if ( !selected
|| selected
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3257 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3260 wxVariant
pendingValue(selected
->GetValueRef());
3261 wxWindow
* wnd
= GetEditorControl();
3262 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3264 bool wasUnspecified
= selected
->IsValueUnspecified();
3265 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3266 bool valueIsPending
= false;
3268 m_chgInfo_changedProperty
= NULL
;
3270 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3273 // Filter out excess wxTextCtrl modified events
3274 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3276 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3278 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3280 wxString newTcValue
= tc
->GetValue();
3281 if ( m_prevTcValue
== newTcValue
)
3284 m_prevTcValue
= newTcValue
;
3287 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3289 bool validationFailure
= false;
3290 bool buttonWasHandled
= false;
3293 // Try common button handling
3294 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3296 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3300 buttonWasHandled
= true;
3301 // Store as res2, as previously (and still currently alternatively)
3302 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3303 // in wxPGProperty::OnEvent().
3304 adapter
->ShowDialog( this, selected
);
3309 if ( !buttonWasHandled
)
3311 if ( wnd
|| m_wndEditor2
)
3313 // First call editor class' event handler.
3314 const wxPGEditor
* editor
= selected
->GetEditorClass();
3316 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3318 // If changes, validate them
3319 if ( DoEditorValidate() )
3321 if ( editor
->GetValueFromControl( pendingValue
,
3324 valueIsPending
= true;
3328 validationFailure
= true;
3333 // Then the property's custom handler (must be always called, unless
3334 // validation failed).
3335 if ( !validationFailure
)
3336 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3339 // SetValueInEvent(), as called in one of the functions referred above
3340 // overrides editor's value.
3341 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3343 valueIsPending
= true;
3344 pendingValue
= m_changeInEventValue
;
3345 selFlags
|= wxPG_SEL_DIALOGVAL
;
3348 if ( !validationFailure
&& valueIsPending
)
3349 if ( !PerformValidation(selected
, pendingValue
) )
3350 validationFailure
= true;
3352 if ( validationFailure
)
3354 OnValidationFailure(selected
, pendingValue
);
3356 else if ( valueIsPending
)
3358 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3360 DoPropertyChanged(selected
, selFlags
);
3361 EditorsValueWasNotModified();
3363 // Regardless of editor type, unfocus editor on
3364 // text-editing related enter press.
3365 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3372 // No value after all
3374 // Regardless of editor type, unfocus editor on
3375 // text-editing related enter press.
3376 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3381 // Let unhandled button click events go to the parent
3382 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3384 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3385 GetEventHandler()->AddPendingEvent(evt
);
3389 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3392 // -----------------------------------------------------------------------
3393 // wxPropertyGrid editor control helper methods
3394 // -----------------------------------------------------------------------
3396 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3398 int itemy
= p
->GetY2(m_lineHeight
);
3400 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3401 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3402 int imageOffset
= 0;
3404 // TODO: If custom image detection changes from current, change this.
3405 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3407 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3408 int iw
= p
->OnMeasureImage().x
;
3410 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3411 imageOffset
= p
->GetImageOffset(iw
);
3416 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3418 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3423 // -----------------------------------------------------------------------
3425 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3427 wxSize sz
= GetImageSize(p
, item
);
3428 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3429 wxPG_CUSTOM_IMAGE_SPACINGY
,
3434 // return size of custom paint image
3435 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3437 // If called with NULL property, then return default image
3438 // size for properties that use image.
3440 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3442 wxSize cis
= p
->OnMeasureImage(item
);
3444 int choiceCount
= p
->m_choices
.GetCount();
3445 int comVals
= p
->GetDisplayedCommonValueCount();
3446 if ( item
>= choiceCount
&& comVals
> 0 )
3448 unsigned int cvi
= item
-choiceCount
;
3449 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3451 else if ( item
>= 0 && choiceCount
== 0 )
3452 return wxSize(0, 0);
3457 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3462 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3469 // -----------------------------------------------------------------------
3471 // takes scrolling into account
3472 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3475 GetViewStart(&vx
,&vy
);
3476 vy
*=wxPG_PIXELS_PER_UNIT
;
3477 vx
*=wxPG_PIXELS_PER_UNIT
;
3480 ClientToScreen( px
, py
);
3483 // -----------------------------------------------------------------------
3485 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3488 GetViewStart(&pt2
.x
,&pt2
.y
);
3489 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3490 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3494 return m_pState
->HitTest(pt2
);
3497 // -----------------------------------------------------------------------
3499 // custom set cursor
3500 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3502 if ( type
== m_curcursor
&& !override
) return;
3504 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3506 if ( type
== wxCURSOR_SIZEWE
)
3507 cursor
= m_cursorSizeWE
;
3509 m_canvas
->SetCursor( *cursor
);
3514 // -----------------------------------------------------------------------
3515 // wxPropertyGrid property selection, editor creation
3516 // -----------------------------------------------------------------------
3519 // This class forwards events from property editor controls to wxPropertyGrid.
3520 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3523 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3524 : wxEvtHandler(), m_propGrid(propGrid
)
3528 virtual ~wxPropertyGridEditorEventForwarder()
3533 bool ProcessEvent( wxEvent
& event
)
3538 m_propGrid
->HandleCustomEditorEvent(event
);
3540 return wxEvtHandler::ProcessEvent(event
);
3543 wxPropertyGrid
* m_propGrid
;
3546 // Setups event handling for child control
3547 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3549 wxWindowID id
= argWnd
->GetId();
3551 if ( argWnd
== m_wndEditor
)
3553 argWnd
->Connect(id
, wxEVT_MOTION
,
3554 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3556 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3557 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3559 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3560 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3562 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3563 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3565 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3566 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3568 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3569 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3573 wxPropertyGridEditorEventForwarder
* forwarder
;
3574 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3575 argWnd
->PushEventHandler(forwarder
);
3577 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3578 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3582 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3589 // Do not free editors immediately (for sake of processing events)
3590 wxPendingDelete
.Append(wnd
);
3593 void wxPropertyGrid::FreeEditors()
3596 // Return focus back to canvas from children (this is required at least for
3597 // GTK+, which, unlike Windows, clears focus when control is destroyed
3598 // instead of moving it to closest parent).
3599 wxWindow
* focus
= wxWindow::FindFocus();
3602 wxWindow
* parent
= focus
->GetParent();
3605 if ( parent
== m_canvas
)
3610 parent
= parent
->GetParent();
3614 // Do not free editors immediately if processing events
3617 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3618 m_wndEditor2
->Hide();
3619 wxPendingDelete
.Append( handler
);
3620 DestroyEditorWnd(m_wndEditor2
);
3621 m_wndEditor2
= NULL
;
3626 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3627 m_wndEditor
->Hide();
3628 wxPendingDelete
.Append( handler
);
3629 DestroyEditorWnd(m_wndEditor
);
3634 // Call with NULL to de-select property
3635 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3640 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3641 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3645 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3649 if ( m_inDoSelectProperty
)
3652 m_inDoSelectProperty
= 1;
3656 m_inDoSelectProperty
= 0;
3660 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3661 wxPGProperty
* prevFirstSel
;
3663 if ( prevSelection
.size() > 0 )
3664 prevFirstSel
= prevSelection
[0];
3666 prevFirstSel
= NULL
;
3668 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3669 prevFirstSel
= NULL
;
3671 // Always send event, as this is indirect call
3672 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
3676 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3678 wxPrintf( "None selected\n" );
3681 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3683 wxPrintf( "P = NULL\n" );
3686 // If we are frozen, then just set the values.
3689 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3690 m_editorFocused
= 0;
3691 m_pState
->DoSetSelection(p
);
3693 // If frozen, always free controls. But don't worry, as Thaw will
3694 // recall SelectProperty to recreate them.
3697 // Prevent any further selection measures in this call
3703 if ( prevFirstSel
== p
&&
3704 prevSelection
.size() <= 1 &&
3705 !(flags
& wxPG_SEL_FORCE
) )
3707 // Only set focus if not deselecting
3710 if ( flags
& wxPG_SEL_FOCUS
)
3714 m_wndEditor
->SetFocus();
3715 m_editorFocused
= 1;
3724 m_inDoSelectProperty
= 0;
3729 // First, deactivate previous
3732 OnValidationFailureReset(prevFirstSel
);
3734 // Must double-check if this is an selected in case of forceswitch
3735 if ( p
!= prevFirstSel
)
3737 if ( !CommitChangesFromEditor(flags
) )
3739 // Validation has failed, so we can't exit the previous editor
3740 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3741 // _("Invalid Value"),wxOK|wxICON_ERROR);
3742 m_inDoSelectProperty
= 0;
3749 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3750 EditorsValueWasNotModified();
3753 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3755 m_pState
->DoSetSelection(p
);
3757 // Redraw unselected
3758 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
3760 DrawItem(prevSelection
[i
]);
3764 // Then, activate the one given.
3767 int propY
= p
->GetY2(m_lineHeight
);
3769 int splitterX
= GetSplitterPosition();
3770 m_editorFocused
= 0;
3771 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3772 if ( p
!= prevFirstSel
)
3773 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3775 wxASSERT( m_wndEditor
== NULL
);
3778 // Only create editor for non-disabled non-caption
3779 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3781 // do this for non-caption items
3785 // Do we need to paint the custom image, if any?
3786 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3787 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3788 !p
->GetEditorClass()->CanContainCustomImage()
3790 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3792 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3793 wxPoint goodPos
= grect
.GetPosition();
3795 const wxPGEditor
* editor
= p
->GetEditorClass();
3796 wxCHECK_MSG(editor
, false,
3797 wxT("NULL editor class not allowed"));
3799 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3801 wxPGWindowList wndList
= editor
->CreateControls(this,
3806 m_wndEditor
= wndList
.m_primary
;
3807 m_wndEditor2
= wndList
.m_secondary
;
3808 wxWindow
* primaryCtrl
= GetEditorControl();
3811 // Essentially, primaryCtrl == m_wndEditor
3814 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3815 // value is drawn as normal, and m_wndEditor2 is assumed
3816 // to be a right-aligned button that triggers a separate editorCtrl
3821 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3822 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3824 // Set validator, if any
3825 #if wxUSE_VALIDATORS
3826 wxValidator
* validator
= p
->GetValidator();
3828 primaryCtrl
->SetValidator(*validator
);
3831 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3832 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3834 // If it has modified status, use bold font
3835 // (must be done before capturing m_ctrlXAdjust)
3836 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3837 SetCurControlBoldFont();
3840 // Fix TextCtrl indentation
3841 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3842 wxTextCtrl
* tc
= NULL
;
3843 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3844 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3846 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3848 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3851 // Store x relative to splitter (we'll need it).
3852 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3854 // Check if background clear is not necessary
3855 wxPoint pos
= m_wndEditor
->GetPosition();
3856 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3858 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3861 m_wndEditor
->SetSizeHints(3, 3);
3863 SetupChildEventHandling(primaryCtrl
);
3865 // Focus and select all (wxTextCtrl, wxComboBox etc)
3866 if ( flags
& wxPG_SEL_FOCUS
)
3868 primaryCtrl
->SetFocus();
3870 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3876 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3877 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3879 // Get proper id for wndSecondary
3880 m_wndSecId
= m_wndEditor2
->GetId();
3881 wxWindowList children
= m_wndEditor2
->GetChildren();
3882 wxWindowList::iterator node
= children
.begin();
3883 if ( node
!= children
.end() )
3884 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3886 m_wndEditor2
->SetSizeHints(3,3);
3888 m_wndEditor2
->Show();
3890 SetupChildEventHandling(m_wndEditor2
);
3892 // If no primary editor, focus to button to allow
3893 // it to interprete ENTER etc.
3894 // NOTE: Due to problems focusing away from it, this
3895 // has been disabled.
3897 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3898 m_wndEditor2->SetFocus();
3902 if ( flags
& wxPG_SEL_FOCUS
)
3903 m_editorFocused
= 1;
3908 // Make sure focus is in grid canvas (important for wxGTK, at least)
3912 EditorsValueWasNotModified();
3914 // If it's inside collapsed section, expand parent, scroll, etc.
3915 // Also, if it was partially visible, scroll it into view.
3916 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3921 m_wndEditor
->Show(true);
3924 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
3929 // Make sure focus is in grid canvas
3933 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3939 // Show help text in status bar.
3940 // (if found and grid not embedded in manager with help box and
3941 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3944 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3946 wxStatusBar
* statusbar
= NULL
;
3947 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3949 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3951 statusbar
= frame
->GetStatusBar();
3956 const wxString
* pHelpString
= (const wxString
*) NULL
;
3960 pHelpString
= &p
->GetHelpString();
3961 if ( pHelpString
->length() )
3963 // Set help box text.
3964 statusbar
->SetStatusText( *pHelpString
);
3965 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3969 if ( (!pHelpString
|| !pHelpString
->length()) &&
3970 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3972 // Clear help box - but only if it was written
3973 // by us at previous time.
3974 statusbar
->SetStatusText( m_emptyString
);
3975 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3981 m_inDoSelectProperty
= 0;
3983 // call wx event handler (here so that it also occurs on deselection)
3984 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
3985 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
3990 // -----------------------------------------------------------------------
3992 bool wxPropertyGrid::UnfocusEditor()
3994 wxPGProperty
* selected
= GetSelection();
3996 if ( !selected
|| !m_wndEditor
|| m_frozen
)
3999 if ( !CommitChangesFromEditor(0) )
4008 // -----------------------------------------------------------------------
4010 void wxPropertyGrid::RefreshEditor()
4012 wxPGProperty
* p
= GetSelection();
4016 wxWindow
* wnd
= GetEditorControl();
4020 // Set editor font boldness - must do this before
4021 // calling UpdateControl().
4022 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4024 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4025 wnd
->SetFont(GetCaptionFont());
4027 wnd
->SetFont(GetFont());
4030 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4032 editorClass
->UpdateControl(p
, wnd
);
4034 if ( p
->IsValueUnspecified() )
4035 editorClass
->SetValueToUnspecified(p
, wnd
);
4038 // -----------------------------------------------------------------------
4040 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4042 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4044 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4046 flags
|= wxPG_SEL_FOCUS
;
4048 return DoSelectProperty(p
, flags
);
4051 // -----------------------------------------------------------------------
4052 // wxPropertyGrid expand/collapse state
4053 // -----------------------------------------------------------------------
4055 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4057 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4058 wxPGProperty
* selected
= GetSelection();
4060 // If active editor was inside collapsed section, then disable it
4061 if ( selected
&& selected
->IsSomeParent(p
) )
4066 // Store dont-center-splitter flag 'cause we need to temporarily set it
4067 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
4068 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4070 bool res
= m_pState
->DoCollapse(pwc
);
4075 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4077 RecalculateVirtualSize();
4079 // Redraw etc. only if collapsed was visible.
4080 if (pwc
->IsVisible() &&
4082 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
4084 // When item is collapsed so that scrollbar would move,
4085 // graphics mess is about (unless we redraw everything).
4090 // Clear dont-center-splitter flag if it wasn't set
4091 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4096 // -----------------------------------------------------------------------
4098 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4100 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4102 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4104 // Store dont-center-splitter flag 'cause we need to temporarily set it
4105 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
4106 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4108 bool res
= m_pState
->DoExpand(pwc
);
4113 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4115 RecalculateVirtualSize();
4117 // Redraw etc. only if expanded was visible.
4118 if ( pwc
->IsVisible() && !m_frozen
&&
4119 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
4123 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4126 DrawItems(pwc
, NULL
);
4131 // Clear dont-center-splitter flag if it wasn't set
4132 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4137 // -----------------------------------------------------------------------
4139 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4142 return m_pState
->DoHideProperty(p
, hide
, flags
);
4144 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4145 int selRemoveCount
= 0;
4146 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4148 wxPGProperty
* selected
= selection
[i
];
4149 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4151 if ( !DoRemoveFromSelection(p
, flags
) )
4153 selRemoveCount
+= 1;
4157 m_pState
->DoHideProperty(p
, hide
, flags
);
4159 RecalculateVirtualSize();
4166 // -----------------------------------------------------------------------
4167 // wxPropertyGrid size related methods
4168 // -----------------------------------------------------------------------
4170 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4172 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4176 // If virtual height was changed, then recalculate editor control position(s)
4177 if ( m_pState
->m_vhCalcPending
)
4178 CorrectEditorWidgetPosY();
4180 m_pState
->EnsureVirtualHeight();
4182 wxASSERT_LEVEL_2_MSG(
4183 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4184 "VirtualHeight and ActualVirtualHeight should match"
4187 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4189 int x
= m_pState
->m_width
;
4190 int y
= m_pState
->m_virtualHeight
;
4193 GetClientSize(&width
,&height
);
4195 // Now adjust virtual size.
4196 SetVirtualSize(x
, y
);
4202 // Adjust scrollbars
4203 if ( HasVirtualWidth() )
4205 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4206 xPos
= GetScrollPos( wxHORIZONTAL
);
4209 if ( forceXPos
!= -1 )
4212 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4215 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4216 int yPos
= GetScrollPos( wxVERTICAL
);
4218 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4219 xAmount
, yAmount
, xPos
, yPos
, true );
4221 // Must re-get size now
4222 GetClientSize(&width
,&height
);
4224 if ( !HasVirtualWidth() )
4226 m_pState
->SetVirtualWidth(width
);
4233 m_canvas
->SetSize( x
, y
);
4235 m_pState
->CheckColumnWidths();
4237 if ( GetSelection() )
4238 CorrectEditorWidgetSizeX();
4240 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4243 // -----------------------------------------------------------------------
4245 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4247 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4251 GetClientSize(&width
,&height
);
4256 #if wxPG_DOUBLE_BUFFER
4257 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4259 int dblh
= (m_lineHeight
*2);
4260 if ( !m_doubleBuffer
)
4262 // Create double buffer bitmap to draw on, if none
4263 int w
= (width
>250)?width
:250;
4264 int h
= height
+ dblh
;
4266 m_doubleBuffer
= new wxBitmap( w
, h
);
4270 int w
= m_doubleBuffer
->GetWidth();
4271 int h
= m_doubleBuffer
->GetHeight();
4273 // Double buffer must be large enough
4274 if ( w
< width
|| h
< (height
+dblh
) )
4276 if ( w
< width
) w
= width
;
4277 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4278 delete m_doubleBuffer
;
4279 m_doubleBuffer
= new wxBitmap( w
, h
);
4286 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4287 m_ncWidth
= event
.GetSize().x
;
4291 if ( m_pState
->m_itemsAdded
)
4292 PrepareAfterItemsAdded();
4294 // Without this, virtual size (atleast under wxGTK) will be skewed
4295 RecalculateVirtualSize();
4301 // -----------------------------------------------------------------------
4303 void wxPropertyGrid::SetVirtualWidth( int width
)
4307 // Disable virtual width
4308 width
= GetClientSize().x
;
4309 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4313 // Enable virtual width
4314 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4316 m_pState
->SetVirtualWidth( width
);
4319 void wxPropertyGrid::SetFocusOnCanvas()
4321 m_canvas
->SetFocusIgnoringChildren();
4322 m_editorFocused
= 0;
4325 // -----------------------------------------------------------------------
4326 // wxPropertyGrid mouse event handling
4327 // -----------------------------------------------------------------------
4329 // selFlags uses same values DoSelectProperty's flags
4330 // Returns true if event was vetoed.
4331 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4333 unsigned int selFlags
,
4334 unsigned int column
)
4336 // Send property grid event of specific type and with specific property
4337 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4338 evt
.SetPropertyGrid(this);
4339 evt
.SetEventObject(m_eventObject
);
4341 evt
.SetColumn(column
);
4344 evt
.SetCanVeto(true);
4345 evt
.SetupValidationInfo();
4346 m_validationInfo
.m_pValue
= pValue
;
4348 else if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4350 evt
.SetCanVeto(true);
4353 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4355 evtHandler
->ProcessEvent(evt
);
4357 return evt
.WasVetoed();
4360 // -----------------------------------------------------------------------
4362 // Return false if should be skipped
4363 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4367 // Need to set focus?
4368 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4373 wxPropertyGridPageState
* state
= m_pState
;
4375 int splitterHitOffset
;
4376 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4378 wxPGProperty
* p
= DoGetItemAtY(y
);
4382 int depth
= (int)p
->GetDepth() - 1;
4384 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4386 if ( x
>= marginEnds
)
4390 if ( p
->IsCategory() )
4392 // This is category.
4393 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4395 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4397 // Expand, collapse, activate etc. if click on text or left of splitter.
4400 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4405 if ( !AddToSelectionFromInputEvent( p
,
4410 // On double-click, expand/collapse.
4411 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4413 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4414 else DoExpand( p
, true );
4418 else if ( splitterHit
== -1 )
4421 unsigned int selFlag
= 0;
4422 if ( columnHit
== 1 )
4424 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4425 selFlag
= wxPG_SEL_FOCUS
;
4427 if ( !AddToSelectionFromInputEvent( p
,
4433 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4435 if ( p
->GetChildCount() && !p
->IsCategory() )
4436 // On double-click, expand/collapse.
4437 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4439 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4440 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4441 else DoExpand( p
, true );
4448 // click on splitter
4449 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4451 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4453 // Double-clicking the splitter causes auto-centering
4454 CenterSplitter( true );
4456 else if ( m_dragStatus
== 0 )
4459 // Begin draggin the splitter
4463 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4467 // Changes must be committed here or the
4468 // value won't be drawn correctly
4469 if ( !CommitChangesFromEditor() )
4472 m_wndEditor
->Show ( false );
4475 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4477 m_canvas
->CaptureMouse();
4478 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4482 m_draggedSplitter
= splitterHit
;
4483 m_dragOffset
= splitterHitOffset
;
4485 wxClientDC
dc(m_canvas
);
4487 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4488 // Fixes button disappearance bug
4490 m_wndEditor2
->Show ( false );
4493 m_startingSplitterX
= x
- splitterHitOffset
;
4501 if ( p
->GetChildCount() )
4503 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4505 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4507 int y2
= y
% m_lineHeight
;
4508 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4510 // On click on expander button, expand/collapse
4511 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4512 DoCollapse( p
, true );
4514 DoExpand( p
, true );
4523 // -----------------------------------------------------------------------
4525 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4526 unsigned int WXUNUSED(y
),
4527 wxMouseEvent
& event
)
4531 // Select property here as well
4532 wxPGProperty
* p
= m_propHover
;
4533 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4535 // Send right click event.
4536 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4543 // -----------------------------------------------------------------------
4545 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4546 unsigned int WXUNUSED(y
),
4547 wxMouseEvent
& event
)
4551 // Select property here as well
4552 wxPGProperty
* p
= m_propHover
;
4554 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4556 // Send double-click event.
4557 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4564 // -----------------------------------------------------------------------
4566 #if wxPG_SUPPORT_TOOLTIPS
4568 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4570 if ( tipString
.length() )
4572 m_canvas
->SetToolTip(tipString
);
4576 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4577 m_canvas
->SetToolTip( m_emptyString
);
4579 m_canvas
->SetToolTip( NULL
);
4584 #endif // #if wxPG_SUPPORT_TOOLTIPS
4586 // -----------------------------------------------------------------------
4588 // Return false if should be skipped
4589 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4591 // Safety check (needed because mouse capturing may
4592 // otherwise freeze the control)
4593 if ( m_dragStatus
> 0 && !event
.Dragging() )
4595 HandleMouseUp(x
,y
,event
);
4598 wxPropertyGridPageState
* state
= m_pState
;
4600 int splitterHitOffset
;
4601 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4602 int splitterX
= x
- splitterHitOffset
;
4604 m_colHover
= columnHit
;
4606 if ( m_dragStatus
> 0 )
4608 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4609 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4612 int newSplitterX
= x
- m_dragOffset
;
4613 int splitterX
= x
- splitterHitOffset
;
4615 // Splitter redraw required?
4616 if ( newSplitterX
!= splitterX
)
4619 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4620 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4621 state
->m_fSplitterX
= (float) newSplitterX
;
4623 if ( GetSelection() )
4624 CorrectEditorWidgetSizeX();
4638 int ih
= m_lineHeight
;
4641 #if wxPG_SUPPORT_TOOLTIPS
4642 wxPGProperty
* prevHover
= m_propHover
;
4643 unsigned char prevSide
= m_mouseSide
;
4645 int curPropHoverY
= y
- (y
% ih
);
4647 // On which item it hovers
4650 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4653 // Mouse moves on another property
4655 m_propHover
= DoGetItemAtY(y
);
4656 m_propHoverY
= curPropHoverY
;
4659 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4662 #if wxPG_SUPPORT_TOOLTIPS
4663 // Store which side we are on
4665 if ( columnHit
== 1 )
4667 else if ( columnHit
== 0 )
4671 // If tooltips are enabled, show label or value as a tip
4672 // in case it doesn't otherwise show in full length.
4674 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4676 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4678 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4680 if ( m_propHover
&& !m_propHover
->IsCategory() )
4683 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4685 // Show help string as a tooltip
4686 wxString tipString
= m_propHover
->GetHelpString();
4688 SetToolTip(tipString
);
4692 // Show cropped value string as a tooltip
4696 if ( m_mouseSide
== 1 )
4698 tipString
= m_propHover
->m_label
;
4699 space
= splitterX
-m_marginWidth
-3;
4701 else if ( m_mouseSide
== 2 )
4703 tipString
= m_propHover
->GetDisplayedString();
4705 space
= m_width
- splitterX
;
4706 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4707 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4713 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4716 SetToolTip( tipString
);
4723 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4724 m_canvas
->SetToolTip( m_emptyString
);
4726 m_canvas
->SetToolTip( NULL
);
4737 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4738 m_canvas
->SetToolTip( m_emptyString
);
4740 m_canvas
->SetToolTip( NULL
);
4748 if ( splitterHit
== -1 ||
4750 HasFlag(wxPG_STATIC_SPLITTER
) )
4752 // hovering on something else
4753 if ( m_curcursor
!= wxCURSOR_ARROW
)
4754 CustomSetCursor( wxCURSOR_ARROW
);
4758 // Do not allow splitter cursor on caption items.
4759 // (also not if we were dragging and its started
4760 // outside the splitter region)
4762 if ( !m_propHover
->IsCategory() &&
4766 // hovering on splitter
4768 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4769 // reliably detected.
4770 //if ( m_curcursor != wxCURSOR_SIZEWE )
4771 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4777 // hovering on something else
4778 if ( m_curcursor
!= wxCURSOR_ARROW
)
4779 CustomSetCursor( wxCURSOR_ARROW
);
4784 // Multi select by dragging
4786 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
&&
4787 event
.LeftIsDown() &&
4790 !state
->DoIsPropertySelected(m_propHover
) )
4792 DoAddToSelection(m_propHover
);
4798 // -----------------------------------------------------------------------
4800 // Also handles Leaving event
4801 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4802 wxMouseEvent
&WXUNUSED(event
) )
4804 wxPropertyGridPageState
* state
= m_pState
;
4808 int splitterHitOffset
;
4809 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4811 // No event type check - basicly calling this method should
4812 // just stop dragging.
4813 // Left up after dragged?
4814 if ( m_dragStatus
>= 1 )
4817 // End Splitter Dragging
4819 // DO NOT ENABLE FOLLOWING LINE!
4820 // (it is only here as a reminder to not to do it)
4823 // Disable splitter auto-centering
4824 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4826 // This is necessary to return cursor
4827 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4829 m_canvas
->ReleaseMouse();
4830 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4833 // Set back the default cursor, if necessary
4834 if ( splitterHit
== -1 ||
4837 CustomSetCursor( wxCURSOR_ARROW
);
4842 // Control background needs to be cleared
4843 wxPGProperty
* selected
= GetSelection();
4844 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
4845 DrawItem( selected
);
4849 m_wndEditor
->Show ( true );
4852 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4853 // Fixes button disappearance bug
4855 m_wndEditor2
->Show ( true );
4858 // This clears the focus.
4859 m_editorFocused
= 0;
4865 // -----------------------------------------------------------------------
4867 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4869 int splitterX
= GetSplitterPosition();
4872 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4876 wxWindow
* wnd
= GetEditorControl();
4878 // Hide popup on clicks
4879 if ( event
.GetEventType() != wxEVT_MOTION
)
4880 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4882 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4888 if ( wnd
== NULL
|| m_dragStatus
||
4890 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4891 ux
>= (r
.x
+r
.width
) ||
4893 event
.m_y
>= (r
.y
+r
.height
)
4903 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4908 // -----------------------------------------------------------------------
4910 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4913 if ( OnMouseCommon( event
, &x
, &y
) )
4915 HandleMouseClick(x
,y
,event
);
4920 // -----------------------------------------------------------------------
4922 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4925 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4926 HandleMouseRightClick(x
,y
,event
);
4930 // -----------------------------------------------------------------------
4932 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4934 // Always run standard mouse-down handler as well
4935 OnMouseClick(event
);
4938 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4939 HandleMouseDoubleClick(x
,y
,event
);
4943 // -----------------------------------------------------------------------
4945 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4948 if ( OnMouseCommon( event
, &x
, &y
) )
4950 HandleMouseMove(x
,y
,event
);
4955 // -----------------------------------------------------------------------
4957 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4959 // Called when mouse moves in the empty space below the properties.
4960 CustomSetCursor( wxCURSOR_ARROW
);
4963 // -----------------------------------------------------------------------
4965 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4968 if ( OnMouseCommon( event
, &x
, &y
) )
4970 HandleMouseUp(x
,y
,event
);
4975 // -----------------------------------------------------------------------
4977 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4979 // This may get called from child control as well, so event's
4980 // mouse position cannot be relied on.
4982 if ( event
.Entering() )
4984 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4986 // TODO: Fix this (detect parent and only do
4987 // cursor trick if it is a manager).
4988 wxASSERT( GetParent() );
4989 GetParent()->SetCursor(wxNullCursor
);
4991 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4994 GetParent()->SetCursor(wxNullCursor
);
4996 else if ( event
.Leaving() )
4998 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4999 m_canvas
->SetCursor( wxNullCursor
);
5001 // Get real cursor position
5002 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5004 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5007 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5009 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5013 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5021 // -----------------------------------------------------------------------
5023 // Common code used by various OnMouseXXXChild methods.
5024 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5026 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5027 wxASSERT( topCtrlWnd
);
5029 event
.GetPosition(&x
,&y
);
5031 int splitterX
= GetSplitterPosition();
5033 wxRect r
= topCtrlWnd
->GetRect();
5034 if ( !m_dragStatus
&&
5035 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5036 y
>= 0 && y
< r
.height \
5039 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5044 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5051 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5054 if ( OnMouseChildCommon(event
,&x
,&y
) )
5056 bool res
= HandleMouseClick(x
,y
,event
);
5057 if ( !res
) event
.Skip();
5061 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5064 wxASSERT( m_wndEditor
);
5065 // These coords may not be exact (about +-2),
5066 // but that should not matter (right click is about item, not position).
5067 wxPoint pt
= m_wndEditor
->GetPosition();
5068 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5070 // FIXME: Used to set m_propHover to selection here. Was it really
5073 bool res
= HandleMouseRightClick(x
,y
,event
);
5074 if ( !res
) event
.Skip();
5077 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5080 if ( OnMouseChildCommon(event
,&x
,&y
) )
5082 bool res
= HandleMouseMove(x
,y
,event
);
5083 if ( !res
) event
.Skip();
5087 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5090 if ( OnMouseChildCommon(event
,&x
,&y
) )
5092 bool res
= HandleMouseUp(x
,y
,event
);
5093 if ( !res
) event
.Skip();
5097 // -----------------------------------------------------------------------
5098 // wxPropertyGrid keyboard event handling
5099 // -----------------------------------------------------------------------
5101 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5103 // Translates wxKeyEvent to wxPG_ACTION_XXX
5105 int keycode
= event
.GetKeyCode();
5106 int modifiers
= event
.GetModifiers();
5108 wxASSERT( !(modifiers
&~(0xFFFF)) );
5110 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5112 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5114 if ( it
== m_actionTriggers
.end() )
5119 int second
= (it
->second
>>16) & 0xFFFF;
5123 return (it
->second
& 0xFFFF);
5126 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5128 wxASSERT( !(modifiers
&~(0xFFFF)) );
5130 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5132 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5134 if ( it
!= m_actionTriggers
.end() )
5136 // This key combination is already used
5138 // Can add secondary?
5139 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5140 wxT("You can only add up to two separate actions per key combination.") );
5142 action
= it
->second
| (action
<<16);
5145 m_actionTriggers
[hashMapKey
] = action
;
5148 void wxPropertyGrid::ClearActionTriggers( int action
)
5150 wxPGHashMapI2I::iterator it
;
5152 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
5154 if ( it
->second
== action
)
5156 m_actionTriggers
.erase(it
);
5161 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5164 // Handles key event when editor control is not focused.
5167 wxCHECK2(!m_frozen
, return);
5169 // Travelsal between items, collapsing/expanding, etc.
5170 wxPGProperty
* selected
= GetSelection();
5171 int keycode
= event
.GetKeyCode();
5172 bool editorFocused
= IsEditorFocused();
5174 if ( keycode
== WXK_TAB
)
5176 wxWindow
* mainControl
;
5178 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5179 mainControl
= GetParent();
5183 if ( !event
.ShiftDown() )
5185 if ( !editorFocused
&& m_wndEditor
)
5187 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5191 // Tab traversal workaround for platforms on which
5192 // wxWindow::Navigate() may navigate into first child
5193 // instead of next sibling. Does not work perfectly
5194 // in every scenario (for instance, when property grid
5195 // is either first or last control).
5196 #if defined(__WXGTK__)
5197 wxWindow
* sibling
= mainControl
->GetNextSibling();
5199 sibling
->SetFocusFromKbd();
5201 Navigate(wxNavigationKeyEvent::IsForward
);
5207 if ( editorFocused
)
5213 #if defined(__WXGTK__)
5214 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5216 sibling
->SetFocusFromKbd();
5218 Navigate(wxNavigationKeyEvent::IsBackward
);
5226 // Ignore Alt and Control when they are down alone
5227 if ( keycode
== WXK_ALT
||
5228 keycode
== WXK_CONTROL
)
5235 int action
= KeyEventToActions(event
, &secondAction
);
5237 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5240 // Esc cancels any changes
5241 if ( IsEditorsValueModified() )
5243 EditorsValueWasNotModified();
5245 // Update the control as well
5246 selected
->GetEditorClass()->
5247 SetControlStringValue( selected
,
5249 selected
->GetDisplayedString() );
5252 OnValidationFailureReset(selected
);
5258 // Except for TAB and ESC, handle child control events in child control
5261 // Only propagate event if it had modifiers
5262 if ( !event
.HasModifiers() )
5264 event
.StopPropagation();
5270 bool wasHandled
= false;
5275 if ( ButtonTriggerKeyTest(action
, event
) )
5278 wxPGProperty
* p
= selected
;
5280 // Travel and expand/collapse
5283 if ( p
->GetChildCount() )
5285 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5287 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5290 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5292 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5299 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5303 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5309 if ( selectDir
>= -1 )
5311 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5313 DoSelectProperty(p
);
5319 // If nothing was selected, select the first item now
5320 // (or navigate out of tab).
5321 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5323 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5324 if ( p
) DoSelectProperty(p
);
5333 // -----------------------------------------------------------------------
5335 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5337 // If there was editor open and focused, then this event should not
5338 // really be processed here.
5339 if ( IsEditorFocused() )
5341 // However, if event had modifiers, it is probably still best
5343 if ( event
.HasModifiers() )
5346 event
.StopPropagation();
5350 HandleKeyEvent(event
, false);
5353 // -----------------------------------------------------------------------
5355 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5360 action
= KeyEventToActions(event
, &secondAction
);
5363 // Does the keycode trigger button?
5364 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5367 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5368 GetEventHandler()->AddPendingEvent(evt
);
5375 // -----------------------------------------------------------------------
5377 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5379 HandleKeyEvent(event
, true);
5382 // -----------------------------------------------------------------------
5383 // wxPropertyGrid miscellaneous event handling
5384 // -----------------------------------------------------------------------
5386 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5389 // Check if the focus is in this control or one of its children
5390 wxWindow
* newFocused
= wxWindow::FindFocus();
5392 if ( newFocused
!= m_curFocused
)
5393 HandleFocusChange( newFocused
);
5396 // Check if top-level parent has changed
5397 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5399 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5405 bool wxPropertyGrid::IsEditorFocused() const
5407 wxWindow
* focus
= wxWindow::FindFocus();
5409 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5410 focus
== GetEditorControl() )
5416 // Called by focus event handlers. newFocused is the window that becomes focused.
5417 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5419 unsigned int oldFlags
= m_iFlags
;
5421 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5423 wxWindow
* parent
= newFocused
;
5425 // This must be one of nextFocus' parents.
5428 // Use m_eventObject, which is either wxPropertyGrid or
5429 // wxPropertyGridManager, as appropriate.
5430 if ( parent
== m_eventObject
)
5432 m_iFlags
|= wxPG_FL_FOCUSED
;
5435 parent
= parent
->GetParent();
5438 m_curFocused
= newFocused
;
5440 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5441 (oldFlags
& wxPG_FL_FOCUSED
) )
5443 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5445 // Need to store changed value
5446 CommitChangesFromEditor();
5452 // Preliminary code for tab-order respecting
5453 // tab-traversal (but should be moved to
5456 wxWindow* prevFocus = event.GetWindow();
5457 wxWindow* useThis = this;
5458 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5459 useThis = GetParent();
5462 prevFocus->GetParent() == useThis->GetParent() )
5464 wxList& children = useThis->GetParent()->GetChildren();
5466 wxNode* node = children.Find(prevFocus);
5468 if ( node->GetNext() &&
5469 useThis == node->GetNext()->GetData() )
5470 DoSelectProperty(GetFirst());
5471 else if ( node->GetPrevious () &&
5472 useThis == node->GetPrevious()->GetData() )
5473 DoSelectProperty(GetLastProperty());
5480 wxPGProperty
* selected
= GetSelection();
5481 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5482 DrawItem( selected
);
5486 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5488 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5489 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5490 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5491 //else if ( event.GetWindow() )
5493 HandleFocusChange(event
.GetWindow());
5498 // -----------------------------------------------------------------------
5500 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5502 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5506 // -----------------------------------------------------------------------
5508 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5510 m_iFlags
|= wxPG_FL_SCROLLED
;
5515 // -----------------------------------------------------------------------
5517 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5519 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5521 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5525 // -----------------------------------------------------------------------
5526 // Property editor related functions
5527 // -----------------------------------------------------------------------
5529 // noDefCheck = true prevents infinite recursion.
5530 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5531 const wxString
& editorName
,
5534 wxASSERT( editorClass
);
5536 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5537 RegisterDefaultEditors();
5539 wxString name
= editorName
;
5540 if ( name
.length() == 0 )
5541 name
= editorClass
->GetName();
5543 // Existing editor under this name?
5544 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5546 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5548 // If this name was already used, try class name.
5549 name
= editorClass
->GetClassInfo()->GetClassName();
5550 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5553 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5554 (wxPGEditor
*) vt_it
->second
,
5555 "Editor with given name was already registered" );
5557 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5562 // Use this in RegisterDefaultEditors.
5563 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5564 if ( wxPGEditor_##EDITOR == NULL ) \
5566 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5567 new wxPG##EDITOR##Editor, true ); \
5570 // Registers all default editor classes
5571 void wxPropertyGrid::RegisterDefaultEditors()
5573 wxPGRegisterDefaultEditorClass( TextCtrl
);
5574 wxPGRegisterDefaultEditorClass( Choice
);
5575 wxPGRegisterDefaultEditorClass( ComboBox
);
5576 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5577 #if wxPG_INCLUDE_CHECKBOX
5578 wxPGRegisterDefaultEditorClass( CheckBox
);
5580 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5582 // Register SpinCtrl etc. editors before use
5583 RegisterAdditionalEditors();
5586 // -----------------------------------------------------------------------
5587 // wxPGStringTokenizer
5588 // Needed to handle C-style string lists (e.g. "str1" "str2")
5589 // -----------------------------------------------------------------------
5591 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5592 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5596 wxPGStringTokenizer::~wxPGStringTokenizer()
5600 bool wxPGStringTokenizer::HasMoreTokens()
5602 const wxString
& str
= *m_str
;
5604 wxString::const_iterator i
= m_curPos
;
5606 wxUniChar delim
= m_delimeter
;
5608 wxUniChar prev_a
= wxT('\0');
5610 bool inToken
= false;
5612 while ( i
!= str
.end() )
5621 m_readyToken
.clear();
5626 if ( prev_a
!= wxT('\\') )
5630 if ( a
!= wxT('\\') )
5650 m_curPos
= str
.end();
5658 wxString
wxPGStringTokenizer::GetNextToken()
5660 return m_readyToken
;
5663 // -----------------------------------------------------------------------
5665 // -----------------------------------------------------------------------
5667 wxPGChoiceEntry::wxPGChoiceEntry()
5668 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5672 // -----------------------------------------------------------------------
5674 // -----------------------------------------------------------------------
5676 wxPGChoicesData::wxPGChoicesData()
5680 wxPGChoicesData::~wxPGChoicesData()
5685 void wxPGChoicesData::Clear()
5690 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5692 wxASSERT( m_items
.size() == 0 );
5694 m_items
= data
->m_items
;
5697 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5698 const wxPGChoiceEntry
& item
)
5700 wxVector
<wxPGChoiceEntry
>::iterator it
;
5704 index
= (int) m_items
.size();
5708 it
= m_items
.begin() + index
;
5711 m_items
.insert(it
, item
);
5713 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5715 // Need to fix value?
5716 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5717 ownEntry
.SetValue(index
);
5722 // -----------------------------------------------------------------------
5723 // wxPropertyGridEvent
5724 // -----------------------------------------------------------------------
5726 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5729 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5730 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5731 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5732 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5733 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5734 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5735 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5736 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5737 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5738 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
5739 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
5741 // -----------------------------------------------------------------------
5743 void wxPropertyGridEvent::Init()
5745 m_validationInfo
= NULL
;
5748 m_wasVetoed
= false;
5751 // -----------------------------------------------------------------------
5753 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5754 : wxCommandEvent(commandType
,id
)
5760 // -----------------------------------------------------------------------
5762 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5763 : wxCommandEvent(event
)
5765 m_eventType
= event
.GetEventType();
5766 m_eventObject
= event
.m_eventObject
;
5768 m_property
= event
.m_property
;
5769 m_validationInfo
= event
.m_validationInfo
;
5770 m_canVeto
= event
.m_canVeto
;
5771 m_wasVetoed
= event
.m_wasVetoed
;
5774 // -----------------------------------------------------------------------
5776 wxPropertyGridEvent::~wxPropertyGridEvent()
5780 // -----------------------------------------------------------------------
5782 wxEvent
* wxPropertyGridEvent::Clone() const
5784 return new wxPropertyGridEvent( *this );
5787 // -----------------------------------------------------------------------
5788 // wxPropertyGridPopulator
5789 // -----------------------------------------------------------------------
5791 wxPropertyGridPopulator::wxPropertyGridPopulator()
5795 wxPGGlobalVars
->m_offline
++;
5798 // -----------------------------------------------------------------------
5800 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5803 m_propHierarchy
.clear();
5806 // -----------------------------------------------------------------------
5808 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5814 // -----------------------------------------------------------------------
5816 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5819 // Free unused sets of choices
5820 wxPGHashMapS2P::iterator it
;
5822 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5824 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5831 m_pg
->GetPanel()->Refresh();
5833 wxPGGlobalVars
->m_offline
--;
5836 // -----------------------------------------------------------------------
5838 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5839 const wxString
& propLabel
,
5840 const wxString
& propName
,
5841 const wxString
* propValue
,
5842 wxPGChoices
* pChoices
)
5844 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5845 wxPGProperty
* parent
= GetCurParent();
5847 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5849 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5853 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5855 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5859 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5861 property
->SetLabel(propLabel
);
5862 property
->DoSetName(propName
);
5864 if ( pChoices
&& pChoices
->IsOk() )
5865 property
->SetChoices(*pChoices
);
5867 m_state
->DoInsert(parent
, -1, property
);
5870 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5871 wxPG_PROGRAMMATIC_VALUE
);
5876 // -----------------------------------------------------------------------
5878 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5880 m_propHierarchy
.push_back(property
);
5881 DoScanForChildren();
5882 m_propHierarchy
.pop_back();
5885 // -----------------------------------------------------------------------
5887 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5888 const wxString
& idString
)
5890 wxPGChoices choices
;
5893 if ( choicesString
[0] == wxT('@') )
5895 wxString ids
= choicesString
.substr(1);
5896 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5897 if ( it
== m_dictIdChoices
.end() )
5898 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5900 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5905 if ( idString
.length() )
5907 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5908 if ( it
!= m_dictIdChoices
.end() )
5910 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5917 // Parse choices string
5918 wxString::const_iterator it
= choicesString
.begin();
5922 bool labelValid
= false;
5924 for ( ; it
!= choicesString
.end(); ++it
)
5930 if ( c
== wxT('"') )
5935 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5936 choices
.Add(label
, l
);
5939 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5944 else if ( c
== wxT('=') )
5951 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5958 if ( c
== wxT('"') )
5971 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5972 choices
.Add(label
, l
);
5975 if ( !choices
.IsOk() )
5977 choices
.EnsureData();
5981 if ( idString
.length() )
5982 m_dictIdChoices
[idString
] = choices
.GetData();
5989 // -----------------------------------------------------------------------
5991 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5993 if ( s
.Last() == wxT('%') )
5995 wxString s2
= s
.substr(0,s
.length()-1);
5997 if ( s2
.ToLong(&val
, 10) )
5999 *pval
= (val
*max
)/100;
6005 return s
.ToLong(pval
, 10);
6008 // -----------------------------------------------------------------------
6010 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6011 const wxString
& type
,
6012 const wxString
& value
)
6014 int l
= m_propHierarchy
.size();
6018 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6019 wxString valuel
= value
.Lower();
6022 if ( type
.length() == 0 )
6027 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6029 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6031 else if ( value
.ToLong(&v
, 0) )
6038 if ( type
== wxT("string") )
6042 else if ( type
== wxT("int") )
6045 value
.ToLong(&v
, 0);
6048 else if ( type
== wxT("bool") )
6050 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6057 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6062 p
->SetAttribute( name
, variant
);
6067 // -----------------------------------------------------------------------
6069 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6071 wxLogError(_("Error in resource: %s"),msg
.c_str());
6074 // -----------------------------------------------------------------------
6076 #endif // wxUSE_PROPGRID