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 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1134 int width
= m_marginWidth
;
1135 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1137 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1140 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1146 // -----------------------------------------------------------------------
1148 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1150 if ( newTLP
== m_tlp
)
1153 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1156 // Parent changed so let's redetermine and re-hook the
1157 // correct top-level window.
1160 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1161 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1163 m_tlpClosed
= m_tlp
;
1164 m_tlpClosedTime
= currentTime
;
1169 // Only accept new tlp if same one was not just dismissed.
1170 if ( newTLP
!= m_tlpClosed
||
1171 m_tlpClosedTime
+250 < currentTime
)
1173 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1174 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1187 // -----------------------------------------------------------------------
1189 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1191 // ClearSelection forces value validation/commit.
1192 if ( event
.CanVeto() && !DoClearSelection() )
1198 // Ok, it can close, set tlp pointer to NULL. Some other event
1199 // handler can of course veto the close, but our OnIdle() should
1200 // then be able to regain the tlp pointer.
1201 OnTLPChanging(NULL
);
1206 // -----------------------------------------------------------------------
1208 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1210 OnTLPChanging((wxWindow
*)newParent
);
1212 bool res
= wxScrolledWindow::Reparent(newParent
);
1217 // -----------------------------------------------------------------------
1218 // wxPropertyGrid Font and Colour Methods
1219 // -----------------------------------------------------------------------
1221 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1225 m_captionFont
= wxScrolledWindow::GetFont();
1227 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1228 m_subgroup_extramargin
= x
+ (x
/2);
1231 #if wxPG_USE_RENDERER_NATIVE
1232 m_iconWidth
= wxPG_ICON_WIDTH
;
1233 #elif wxPG_ICON_WIDTH
1235 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1236 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1237 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1241 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1242 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1243 m_gutterWidth
= wxPG_GUTTER_MIN
;
1246 if ( vspacing
<= 1 ) vdiv
= 12;
1247 else if ( vspacing
>= 3 ) vdiv
= 3;
1249 m_spacingy
= m_fontHeight
/ vdiv
;
1250 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1251 m_spacingy
= wxPG_YSPACING_MIN
;
1254 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1255 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1257 m_captionFont
.SetWeight(wxBOLD
);
1258 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1260 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1263 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1264 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1267 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1269 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1270 RecalculateVirtualSize();
1272 InvalidateBestSize();
1275 // -----------------------------------------------------------------------
1277 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1283 // -----------------------------------------------------------------------
1285 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1286 int ga
= 1000, int ba
= 1000,
1287 bool forceDifferent
= false)
1294 // Recursion guard (allow 2 max)
1295 static int isinside
= 0;
1297 wxCHECK_MSG( isinside
< 3,
1299 wxT("wxPGAdjustColour should not be recursively called more than once") );
1304 int g
= src
.Green();
1307 if ( r2
>255 ) r2
= 255;
1308 else if ( r2
<0) r2
= 0;
1310 if ( g2
>255 ) g2
= 255;
1311 else if ( g2
<0) g2
= 0;
1313 if ( b2
>255 ) b2
= 255;
1314 else if ( b2
<0) b2
= 0;
1316 // Make sure they are somewhat different
1317 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1318 dst
= wxPGAdjustColour(src
,-(ra
*2));
1320 dst
= wxColour(r2
,g2
,b2
);
1322 // Recursion guard (allow 2 max)
1329 static int wxPGGetColAvg( const wxColour
& col
)
1331 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1335 void wxPropertyGrid::RegainColours()
1337 if ( !(m_coloursCustomized
& 0x0002) )
1339 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1341 // Make sure colour is dark enough
1343 int colDec
= wxPGGetColAvg(col
) - 230;
1345 int colDec
= wxPGGetColAvg(col
) - 200;
1348 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1351 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1354 if ( !(m_coloursCustomized
& 0x0001) )
1355 m_colMargin
= m_colCapBack
;
1357 if ( !(m_coloursCustomized
& 0x0004) )
1364 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1365 m_colCapFore
= capForeCol
;
1366 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1369 if ( !(m_coloursCustomized
& 0x0008) )
1371 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1372 m_colPropBack
= bgCol
;
1373 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1376 if ( !(m_coloursCustomized
& 0x0010) )
1378 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1379 m_colPropFore
= fgCol
;
1380 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1383 if ( !(m_coloursCustomized
& 0x0020) )
1384 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1386 if ( !(m_coloursCustomized
& 0x0040) )
1387 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1389 if ( !(m_coloursCustomized
& 0x0080) )
1390 m_colLine
= m_colCapBack
;
1392 if ( !(m_coloursCustomized
& 0x0100) )
1393 m_colDisPropFore
= m_colCapFore
;
1395 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1398 // -----------------------------------------------------------------------
1400 void wxPropertyGrid::ResetColours()
1402 m_coloursCustomized
= 0;
1409 // -----------------------------------------------------------------------
1411 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1413 // Must disable active editor.
1416 bool res
= wxScrolledWindow::SetFont( font
);
1417 if ( res
&& GetParent()) // may not have been Create()ed yet
1419 CalculateFontAndBitmapStuff( m_vspacing
);
1426 // -----------------------------------------------------------------------
1428 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1431 m_coloursCustomized
|= 0x80;
1435 // -----------------------------------------------------------------------
1437 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1440 m_coloursCustomized
|= 0x01;
1444 // -----------------------------------------------------------------------
1446 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1448 m_colPropBack
= col
;
1449 m_coloursCustomized
|= 0x08;
1451 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1456 // -----------------------------------------------------------------------
1458 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1460 m_colPropFore
= col
;
1461 m_coloursCustomized
|= 0x10;
1463 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1468 // -----------------------------------------------------------------------
1470 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1472 m_colEmptySpace
= col
;
1477 // -----------------------------------------------------------------------
1479 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1481 m_colDisPropFore
= col
;
1482 m_coloursCustomized
|= 0x100;
1486 // -----------------------------------------------------------------------
1488 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1491 m_coloursCustomized
|= 0x20;
1495 // -----------------------------------------------------------------------
1497 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1500 m_coloursCustomized
|= 0x40;
1504 // -----------------------------------------------------------------------
1506 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1509 m_coloursCustomized
|= 0x02;
1511 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1516 // -----------------------------------------------------------------------
1518 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1521 m_coloursCustomized
|= 0x04;
1523 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1528 // -----------------------------------------------------------------------
1529 // wxPropertyGrid property adding and removal
1530 // -----------------------------------------------------------------------
1532 void wxPropertyGrid::PrepareAfterItemsAdded()
1534 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1536 m_pState
->m_itemsAdded
= 0;
1538 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1539 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1541 RecalculateVirtualSize();
1544 // -----------------------------------------------------------------------
1545 // wxPropertyGrid property operations
1546 // -----------------------------------------------------------------------
1548 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1550 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1554 bool changed
= false;
1556 // Is it inside collapsed section?
1557 if ( !p
->IsVisible() )
1560 wxPGProperty
* parent
= p
->GetParent();
1561 wxPGProperty
* grandparent
= parent
->GetParent();
1563 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1564 Expand( grandparent
);
1572 GetViewStart(&vx
,&vy
);
1573 vy
*=wxPG_PIXELS_PER_UNIT
;
1579 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1580 m_iFlags
|= wxPG_FL_SCROLLED
;
1583 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1585 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1586 m_iFlags
|= wxPG_FL_SCROLLED
;
1596 // -----------------------------------------------------------------------
1597 // wxPropertyGrid helper methods called by properties
1598 // -----------------------------------------------------------------------
1600 // Control font changer helper.
1601 void wxPropertyGrid::SetCurControlBoldFont()
1603 wxASSERT( m_wndEditor
);
1604 m_wndEditor
->SetFont( m_captionFont
);
1607 // -----------------------------------------------------------------------
1609 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1612 #if wxPG_SMALL_SCREEN
1613 // On small-screen devices, always show dialogs with default position and size.
1614 return wxDefaultPosition
;
1616 int splitterX
= GetSplitterPosition();
1620 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1622 ImprovedClientToScreen( &x
, &y
);
1624 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1625 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1632 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1642 new_y
= y
+ m_lineHeight
;
1644 return wxPoint(new_x
,new_y
);
1648 // -----------------------------------------------------------------------
1650 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1652 if ( src_str
.length() == 0 )
1658 bool prev_is_slash
= false;
1660 wxString::const_iterator i
= src_str
.begin();
1664 for ( ; i
!= src_str
.end(); ++i
)
1668 if ( a
!= wxS('\\') )
1670 if ( !prev_is_slash
)
1676 if ( a
== wxS('n') )
1679 dst_str
<< wxS('\n');
1681 dst_str
<< wxS('\n');
1684 else if ( a
== wxS('t') )
1685 dst_str
<< wxS('\t');
1689 prev_is_slash
= false;
1693 if ( prev_is_slash
)
1695 dst_str
<< wxS('\\');
1696 prev_is_slash
= false;
1700 prev_is_slash
= true;
1707 // -----------------------------------------------------------------------
1709 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1711 if ( src_str
.length() == 0 )
1717 wxString::const_iterator i
= src_str
.begin();
1718 wxUniChar prev_a
= wxS('\0');
1722 for ( ; i
!= src_str
.end(); ++i
)
1726 if ( a
>= wxS(' ') )
1728 // This surely is not something that requires an escape sequence.
1733 // This might need...
1734 if ( a
== wxS('\r') )
1736 // DOS style line end.
1737 // Already taken care below
1739 else if ( a
== wxS('\n') )
1740 // UNIX style line end.
1741 dst_str
<< wxS("\\n");
1742 else if ( a
== wxS('\t') )
1744 dst_str
<< wxS('\t');
1747 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1757 // -----------------------------------------------------------------------
1759 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1766 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1769 // -----------------------------------------------------------------------
1770 // wxPropertyGrid graphics related methods
1771 // -----------------------------------------------------------------------
1773 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1777 // Update everything inside the box
1778 wxRect r
= GetUpdateRegion().GetBox();
1780 dc
.SetPen(m_colEmptySpace
);
1781 dc
.SetBrush(m_colEmptySpace
);
1782 dc
.DrawRectangle(r
);
1785 // -----------------------------------------------------------------------
1787 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1788 wxPGProperty
* property
) const
1790 // Prepare rectangle to be used
1792 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1793 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1795 #if (wxPG_USE_RENDERER_NATIVE)
1797 #elif wxPG_ICON_WIDTH
1798 // Drawing expand/collapse button manually
1799 dc
.SetPen(m_colPropFore
);
1800 if ( property
->IsCategory() )
1801 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1803 dc
.SetBrush(m_colPropBack
);
1805 dc
.DrawRectangle( r
);
1806 int _y
= r
.y
+(m_iconWidth
/2);
1807 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1812 if ( property
->IsExpanded() )
1814 // wxRenderer functions are non-mutating in nature, so it
1815 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1816 // Hopefully this does not cause problems.
1817 #if (wxPG_USE_RENDERER_NATIVE)
1818 wxRendererNative::Get().DrawTreeItemButton(
1824 #elif wxPG_ICON_WIDTH
1833 #if (wxPG_USE_RENDERER_NATIVE)
1834 wxRendererNative::Get().DrawTreeItemButton(
1840 #elif wxPG_ICON_WIDTH
1841 int _x
= r
.x
+(m_iconWidth
/2);
1842 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1848 #if (wxPG_USE_RENDERER_NATIVE)
1850 #elif wxPG_ICON_WIDTH
1853 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1857 // -----------------------------------------------------------------------
1860 // This is the one called by OnPaint event handler and others.
1861 // topy and bottomy are already unscrolled (ie. physical)
1863 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1865 unsigned int bottomy
,
1866 const wxRect
* clipRect
)
1868 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1870 m_pState
->EnsureVirtualHeight();
1872 wxRect tempClipRect
;
1875 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1876 clipRect
= &tempClipRect
;
1879 // items added check
1880 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1882 int paintFinishY
= 0;
1884 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1887 bool isBuffered
= false;
1889 #if wxPG_DOUBLE_BUFFER
1890 wxMemoryDC
* bufferDC
= NULL
;
1892 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1894 if ( !m_doubleBuffer
)
1896 paintFinishY
= clipRect
->y
;
1901 bufferDC
= new wxMemoryDC();
1903 // If nothing was changed, then just copy from double-buffer
1904 bufferDC
->SelectObject( *m_doubleBuffer
);
1914 dc
.SetClippingRegion( *clipRect
);
1915 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1918 #if wxPG_DOUBLE_BUFFER
1921 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1922 bufferDC
, 0, 0, wxCOPY
);
1923 dc
.DestroyClippingRegion(); // Is this really necessary?
1929 // Clear area beyond bottomY?
1930 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1932 dc
.SetPen(m_colEmptySpace
);
1933 dc
.SetBrush(m_colEmptySpace
);
1934 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1938 // -----------------------------------------------------------------------
1940 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1941 const wxRect
* clipRect
,
1942 bool isBuffered
) const
1944 const wxPGProperty
* firstItem
;
1945 const wxPGProperty
* lastItem
;
1947 firstItem
= DoGetItemAtY(clipRect
->y
);
1948 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1951 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1953 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1956 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1957 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1959 int lh
= m_lineHeight
;
1962 int lastItemBottomY
;
1964 firstItemTopY
= clipRect
->y
;
1965 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1967 // Align y coordinates to item boundaries
1968 firstItemTopY
-= firstItemTopY
% lh
;
1969 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1970 lastItemBottomY
-= 1;
1972 // Entire range outside scrolled, visible area?
1973 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1976 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1980 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1981 firstItem->GetLabel().c_str(),
1982 lastItem->GetLabel().c_str(),
1983 (int)(lastItemBottomY - firstItemTopY),
1985 (unsigned long)clipRect );
1990 long windowStyle
= m_windowStyle
;
1996 // With wxPG_DOUBLE_BUFFER, do double buffering
1997 // - buffer's y = 0, so align cliprect and coordinates to that
1999 #if wxPG_DOUBLE_BUFFER
2005 xRelMod
= clipRect
->x
;
2006 yRelMod
= clipRect
->y
;
2009 // clipRect conversion
2014 firstItemTopY
-= yRelMod
;
2015 lastItemBottomY
-= yRelMod
;
2018 wxUnusedVar(isBuffered
);
2021 int x
= m_marginWidth
- xRelMod
;
2023 wxFont normalFont
= GetFont();
2025 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2027 bool isPgEnabled
= IsEnabled();
2030 // Prepare some pens and brushes that are often changed to.
2033 wxBrush
marginBrush(m_colMargin
);
2034 wxPen
marginPen(m_colMargin
);
2035 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2036 wxPen
linepen(m_colLine
,1,wxSOLID
);
2038 wxColour selBackCol
;
2040 selBackCol
= m_colSelBack
;
2042 selBackCol
= m_colMargin
;
2044 // pen that has same colour as text
2045 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2048 // Clear margin with background colour
2050 dc
.SetBrush( marginBrush
);
2051 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2053 dc
.SetPen( *wxTRANSPARENT_PEN
);
2054 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2057 const wxPGProperty
* firstSelected
= GetSelection();
2058 const wxPropertyGridPageState
* state
= m_pState
;
2060 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2061 bool wasSelectedPainted
= false;
2064 // TODO: Only render columns that are within clipping region.
2066 dc
.SetFont(normalFont
);
2068 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2069 int endScanBottomY
= lastItemBottomY
+ lh
;
2070 int y
= firstItemTopY
;
2073 // Pregenerate list of visible properties.
2074 wxArrayPGProperty visPropArray
;
2075 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2077 for ( ; !it
.AtEnd(); it
.Next() )
2079 const wxPGProperty
* p
= *it
;
2081 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2083 visPropArray
.push_back((wxPGProperty
*)p
);
2085 if ( y
> endScanBottomY
)
2092 visPropArray
.push_back(NULL
);
2094 wxPGProperty
* nextP
= visPropArray
[0];
2096 int gridWidth
= state
->m_width
;
2099 for ( unsigned int arrInd
=1;
2100 nextP
&& y
<= lastItemBottomY
;
2103 wxPGProperty
* p
= nextP
;
2104 nextP
= visPropArray
[arrInd
];
2106 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2107 int textMarginHere
= x
;
2108 int renderFlags
= 0;
2110 int greyDepth
= m_marginWidth
;
2111 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2112 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2114 int greyDepthX
= greyDepth
- xRelMod
;
2116 // Use basic depth if in non-categoric mode and parent is base array.
2117 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2119 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2122 // Paint margin area
2123 dc
.SetBrush(marginBrush
);
2124 dc
.SetPen(marginPen
);
2125 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2127 dc
.SetPen( linepen
);
2132 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2138 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2140 sx
+= state
->m_colWidths
[si
];
2141 dc
.DrawLine( sx
, y
, sx
, y2
);
2144 // Horizontal Line, below
2145 // (not if both this and next is category caption)
2146 if ( p
->IsCategory() &&
2147 nextP
&& nextP
->IsCategory() )
2148 dc
.SetPen(m_colCapBack
);
2150 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2153 // Need to override row colours?
2157 bool isSelected
= state
->DoIsPropertySelected(p
);
2161 // Disabled may get different colour.
2162 if ( !p
->IsEnabled() )
2164 renderFlags
|= wxPGCellRenderer::Disabled
|
2165 wxPGCellRenderer::DontUseCellFgCol
;
2166 rowFgCol
= m_colDisPropFore
;
2171 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2172 if ( p
== firstSelected
)
2173 wasSelectedPainted
= true;
2176 renderFlags
|= wxPGCellRenderer::Selected
;
2178 if ( !p
->IsCategory() )
2180 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2181 wxPGCellRenderer::DontUseCellBgCol
;
2183 if ( reallyFocused
&& p
== firstSelected
)
2185 rowFgCol
= m_colSelFore
;
2186 rowBgCol
= selBackCol
;
2188 else if ( isPgEnabled
)
2190 rowFgCol
= m_colPropFore
;
2191 if ( p
== firstSelected
)
2192 rowBgCol
= m_colMargin
;
2194 rowBgCol
= selBackCol
;
2198 rowFgCol
= m_colDisPropFore
;
2199 rowBgCol
= selBackCol
;
2206 if ( rowBgCol
.IsOk() )
2207 rowBgBrush
= wxBrush(rowBgCol
);
2209 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2210 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2213 // Fill additional margin area with background colour of first cell
2214 if ( greyDepthX
< textMarginHere
)
2216 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2218 wxPGCell
& cell
= p
->GetCell(0);
2219 rowBgCol
= cell
.GetBgCol();
2220 rowBgBrush
= wxBrush(rowBgCol
);
2222 dc
.SetBrush(rowBgBrush
);
2223 dc
.SetPen(rowBgCol
);
2224 dc
.DrawRectangle(greyDepthX
+1, y
,
2225 textMarginHere
-greyDepthX
, lh
-1);
2228 bool fontChanged
= false;
2230 // Expander button rectangle
2231 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2236 if ( p
->IsCategory() )
2238 // Captions have their cell areas merged as one
2239 dc
.SetFont(m_captionFont
);
2241 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2243 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2245 dc
.SetBrush(rowBgBrush
);
2246 dc
.SetPen(rowBgCol
);
2249 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2251 dc
.SetTextForeground(rowFgCol
);
2254 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2255 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2258 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2259 DrawExpanderButton( dc
, butRect
, p
);
2263 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2265 dc
.SetFont(m_captionFont
);
2271 int nextCellWidth
= state
->m_colWidths
[0] -
2272 (greyDepthX
- m_marginWidth
);
2273 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2274 int textXAdd
= textMarginHere
- greyDepthX
;
2276 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2278 cellRect
.width
= nextCellWidth
- 1;
2280 wxWindow
* cellEditor
= NULL
;
2281 int cellRenderFlags
= renderFlags
;
2283 // Tree Item Button (must be drawn before clipping is set up)
2284 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2285 DrawExpanderButton( dc
, butRect
, p
);
2288 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2290 if ( p
== firstSelected
)
2292 if ( ci
== 1 && m_wndEditor
)
2293 cellEditor
= m_wndEditor
;
2294 else if ( ci
== m_selColumn
&& m_labelEditor
)
2295 cellEditor
= m_labelEditor
;
2300 wxColour editorBgCol
=
2301 cellEditor
->GetBackgroundColour();
2302 dc
.SetBrush(editorBgCol
);
2303 dc
.SetPen(editorBgCol
);
2304 dc
.SetTextForeground(m_colPropFore
);
2305 dc
.DrawRectangle(cellRect
);
2307 if ( m_dragStatus
!= 0 ||
2308 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2313 dc
.SetBrush(m_colPropBack
);
2314 dc
.SetPen(m_colPropBack
);
2315 dc
.SetTextForeground(m_colDisPropFore
);
2316 if ( p
->IsEnabled() )
2317 dc
.SetTextForeground(rowFgCol
);
2319 dc
.SetTextForeground(m_colDisPropFore
);
2324 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2326 dc
.SetBrush(rowBgBrush
);
2327 dc
.SetPen(rowBgCol
);
2330 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2332 dc
.SetTextForeground(rowFgCol
);
2336 dc
.SetClippingRegion(cellRect
);
2338 cellRect
.x
+= textXAdd
;
2339 cellRect
.width
-= textXAdd
;
2344 wxPGCellRenderer
* renderer
;
2345 int cmnVal
= p
->GetCommonValue();
2346 if ( cmnVal
== -1 || ci
!= 1 )
2348 renderer
= p
->GetCellRenderer(ci
);
2349 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2354 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2355 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2360 cellX
+= state
->m_colWidths
[ci
];
2361 if ( ci
< (state
->m_colWidths
.size()-1) )
2362 nextCellWidth
= state
->m_colWidths
[ci
+1];
2364 dc
.DestroyClippingRegion(); // Is this really necessary?
2370 dc
.SetFont(normalFont
);
2375 // Refresh editor controls (seems not needed on msw)
2376 // NOTE: This code is mandatory for GTK!
2377 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2378 if ( wasSelectedPainted
)
2381 m_wndEditor
->Refresh();
2383 m_wndEditor2
->Refresh();
2390 // -----------------------------------------------------------------------
2392 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2396 if ( m_width
< 10 || m_height
< 10 ||
2397 !m_pState
->m_properties
->GetChildCount() ||
2399 return wxRect(0,0,0,0);
2404 // Return rect which encloses the given property range
2406 int visTop
= p1
->GetY();
2409 visBottom
= p2
->GetY() + m_lineHeight
;
2411 visBottom
= m_height
+ visTop
;
2413 // If seleced property is inside the range, we'll extend the range to include
2415 wxPGProperty
* selected
= GetSelection();
2418 int selectedY
= selected
->GetY();
2419 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2421 wxWindow
* editor
= GetEditorControl();
2424 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2425 if ( visBottom2
> visBottom
)
2426 visBottom
= visBottom2
;
2431 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2434 // -----------------------------------------------------------------------
2436 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2441 if ( m_pState
->m_itemsAdded
)
2442 PrepareAfterItemsAdded();
2444 wxRect r
= GetPropertyRect(p1
, p2
);
2447 m_canvas
->RefreshRect(r
);
2451 // -----------------------------------------------------------------------
2453 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2455 if ( m_pState
->DoIsPropertySelected(p
) )
2457 // NB: We must copy the selection.
2458 wxArrayPGProperty selection
= m_pState
->m_selection
;
2459 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2462 DrawItemAndChildren(p
);
2465 // -----------------------------------------------------------------------
2467 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2472 // Draw item, children, and parent too, if it is not category
2473 wxPGProperty
* parent
= p
->GetParent();
2476 !parent
->IsCategory() &&
2477 parent
->GetParent() )
2480 parent
= parent
->GetParent();
2483 DrawItemAndChildren(p
);
2486 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2488 wxCHECK_RET( p
, wxT("invalid property id") );
2490 // Do not draw if in non-visible page
2491 if ( p
->GetParentState() != m_pState
)
2494 // do not draw a single item if multiple pending
2495 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2498 // Update child control.
2499 wxPGProperty
* selected
= GetSelection();
2500 if ( selected
&& selected
->GetParent() == p
)
2503 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2505 DrawItems(p
, lastDrawn
);
2508 // -----------------------------------------------------------------------
2510 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2511 const wxRect
*rect
)
2513 PrepareAfterItemsAdded();
2515 wxWindow::Refresh(false);
2517 // TODO: Coordinate translation
2518 m_canvas
->Refresh(false, rect
);
2520 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2521 // I think this really helps only GTK+1.2
2522 if ( m_wndEditor
) m_wndEditor
->Refresh();
2523 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2527 // -----------------------------------------------------------------------
2528 // wxPropertyGrid global operations
2529 // -----------------------------------------------------------------------
2531 void wxPropertyGrid::Clear()
2533 m_pState
->DoClear();
2539 RecalculateVirtualSize();
2541 // Need to clear some area at the end
2543 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2546 // -----------------------------------------------------------------------
2548 bool wxPropertyGrid::EnableCategories( bool enable
)
2555 // Enable categories
2558 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2563 // Disable categories
2565 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2568 if ( !m_pState
->EnableCategories(enable
) )
2573 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2575 m_pState
->m_itemsAdded
= 1; // force
2576 PrepareAfterItemsAdded();
2580 m_pState
->m_itemsAdded
= 1;
2582 // No need for RecalculateVirtualSize() here - it is already called in
2583 // wxPropertyGridPageState method above.
2590 // -----------------------------------------------------------------------
2592 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2594 wxASSERT( pNewState
);
2595 wxASSERT( pNewState
->GetGrid() );
2597 if ( pNewState
== m_pState
)
2600 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2602 // Call ClearSelection() instead of DoClearSelection()
2603 // so that selection clear events are not sent.
2606 m_pState
->m_selection
= oldSelection
;
2608 bool orig_mode
= m_pState
->IsInNonCatMode();
2609 bool new_state_mode
= pNewState
->IsInNonCatMode();
2611 m_pState
= pNewState
;
2614 int pgWidth
= GetClientSize().x
;
2615 if ( HasVirtualWidth() )
2617 int minWidth
= pgWidth
;
2618 if ( pNewState
->m_width
< minWidth
)
2620 pNewState
->m_width
= minWidth
;
2621 pNewState
->CheckColumnWidths();
2627 // Just in case, fully re-center splitter
2628 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2629 pNewState
->m_fSplitterX
= -1.0;
2631 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2636 // If necessary, convert state to correct mode.
2637 if ( orig_mode
!= new_state_mode
)
2639 // This should refresh as well.
2640 EnableCategories( orig_mode
?false:true );
2642 else if ( !m_frozen
)
2644 // Refresh, if not frozen.
2645 m_pState
->PrepareAfterItemsAdded();
2647 // Reselect (Use SetSelection() instead of Do-variant so that
2648 // events won't be sent).
2649 SetSelection(m_pState
->m_selection
);
2651 RecalculateVirtualSize(0);
2655 m_pState
->m_itemsAdded
= 1;
2658 // -----------------------------------------------------------------------
2660 // Call to SetSplitterPosition will always disable splitter auto-centering
2661 // if parent window is shown.
2662 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2664 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2667 wxPropertyGridPageState
* state
= m_pState
;
2669 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2673 if ( GetSelection() )
2674 CorrectEditorWidgetSizeX();
2680 // -----------------------------------------------------------------------
2682 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2684 SetSplitterPosition( m_width
/2, true );
2685 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2686 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2689 // -----------------------------------------------------------------------
2690 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2691 // -----------------------------------------------------------------------
2693 // Returns nearest paint visible property (such that will be painted unless
2694 // window is scrolled or resized). If given property is paint visible, then
2695 // it itself will be returned
2696 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2698 int vx
,vy1
;// Top left corner of client
2699 GetViewStart(&vx
,&vy1
);
2700 vy1
*= wxPG_PIXELS_PER_UNIT
;
2702 int vy2
= vy1
+ m_height
;
2703 int propY
= p
->GetY2(m_lineHeight
);
2705 if ( (propY
+ m_lineHeight
) < vy1
)
2708 return DoGetItemAtY( vy1
);
2710 else if ( propY
> vy2
)
2713 return DoGetItemAtY( vy2
);
2716 // Itself paint visible
2721 // -----------------------------------------------------------------------
2722 // Methods related to change in value, value modification and sending events
2723 // -----------------------------------------------------------------------
2725 // commits any changes in editor of selected property
2726 // return true if validation did not fail
2727 // flags are same as with DoSelectProperty
2728 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2730 // Committing already?
2731 if ( m_inCommitChangesFromEditor
)
2734 // Don't do this if already processing editor event. It might
2735 // induce recursive dialogs and crap like that.
2736 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2738 if ( m_inDoPropertyChanged
)
2744 wxPGProperty
* selected
= GetSelection();
2747 IsEditorsValueModified() &&
2748 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2751 m_inCommitChangesFromEditor
= 1;
2753 wxVariant
variant(selected
->GetValueRef());
2754 bool valueIsPending
= false;
2756 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2757 // due to another window getting focus
2758 wxWindow
* oldFocus
= m_curFocused
;
2760 bool validationFailure
= false;
2761 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2763 m_chgInfo_changedProperty
= NULL
;
2765 // If truly modified, schedule value as pending.
2766 if ( selected
->GetEditorClass()->
2767 GetValueFromControl( variant
,
2769 GetEditorControl() ) )
2771 if ( DoEditorValidate() &&
2772 PerformValidation(selected
, variant
) )
2774 valueIsPending
= true;
2778 validationFailure
= true;
2783 EditorsValueWasNotModified();
2788 m_inCommitChangesFromEditor
= 0;
2790 if ( validationFailure
&& !forceSuccess
)
2794 oldFocus
->SetFocus();
2795 m_curFocused
= oldFocus
;
2798 res
= OnValidationFailure(selected
, variant
);
2800 // Now prevent further validation failure messages
2803 EditorsValueWasNotModified();
2804 OnValidationFailureReset(selected
);
2807 else if ( valueIsPending
)
2809 DoPropertyChanged( selected
, flags
);
2810 EditorsValueWasNotModified();
2819 // -----------------------------------------------------------------------
2821 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2825 // Runs all validation functionality.
2826 // Returns true if value passes all tests.
2829 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2831 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2833 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2838 // Adapt list to child values, if necessary
2839 wxVariant listValue
= pendingValue
;
2840 wxVariant
* pPendingValue
= &pendingValue
;
2841 wxVariant
* pList
= NULL
;
2843 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2844 // string value, then we need treat as it was changed instead
2845 // (or, in addition, as is the case with composite string parent).
2846 // This includes creating list variant for child values.
2848 wxPGProperty
* pwc
= p
->GetParent();
2849 wxPGProperty
* changedProperty
= p
;
2850 wxPGProperty
* baseChangedProperty
= changedProperty
;
2851 wxVariant bcpPendingList
;
2853 listValue
= pendingValue
;
2854 listValue
.SetName(p
->GetBaseName());
2857 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2859 wxVariantList tempList
;
2860 wxVariant
lv(tempList
, pwc
->GetBaseName());
2861 lv
.Append(listValue
);
2863 pPendingValue
= &listValue
;
2865 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2867 baseChangedProperty
= pwc
;
2868 bcpPendingList
= lv
;
2871 changedProperty
= pwc
;
2872 pwc
= pwc
->GetParent();
2876 wxPGProperty
* evtChangingProperty
= changedProperty
;
2878 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2880 value
= *pPendingValue
;
2884 // Convert list to child values
2885 pList
= pPendingValue
;
2886 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2889 wxVariant evtChangingValue
= value
;
2891 if ( flags
& SendEvtChanging
)
2893 // FIXME: After proper ValueToString()s added, remove
2894 // this. It is just a temporary fix, as evt_changing
2895 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2896 // (unless it is selected, and textctrl editor is open).
2897 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2899 evtChangingProperty
= baseChangedProperty
;
2900 if ( evtChangingProperty
!= p
)
2902 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2906 evtChangingValue
= pendingValue
;
2910 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2912 if ( changedProperty
== GetSelection() )
2914 wxWindow
* editor
= GetEditorControl();
2915 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2916 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2920 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2925 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2926 m_chgInfo_changedProperty
= changedProperty
;
2927 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2928 m_chgInfo_pendingValue
= value
;
2931 m_chgInfo_valueList
= *pList
;
2933 m_chgInfo_valueList
.MakeNull();
2935 // If changedProperty is not property which value was edited,
2936 // then call wxPGProperty::ValidateValue() for that as well.
2937 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2939 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2943 if ( flags
& SendEvtChanging
)
2945 // SendEvent returns true if event was vetoed
2946 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
2947 &evtChangingValue
) )
2951 if ( flags
& IsStandaloneValidation
)
2953 // If called in 'generic' context, we need to reset
2954 // m_chgInfo_changedProperty and write back translated value.
2955 m_chgInfo_changedProperty
= NULL
;
2956 pendingValue
= value
;
2962 // -----------------------------------------------------------------------
2964 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2966 if ( !msg
.length() )
2970 if ( !wxPGGlobalVars
->m_offline
)
2972 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2975 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2978 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2981 pStatusBar
->SetStatusText(msg
);
2989 ::wxMessageBox(msg
, wxT("Property Error"));
2992 // -----------------------------------------------------------------------
2994 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2995 wxVariant
& invalidValue
)
2997 wxWindow
* editor
= GetEditorControl();
2999 // First call property's handler
3000 property
->OnValidationFailure(invalidValue
);
3002 bool res
= DoOnValidationFailure(property
, invalidValue
);
3005 // For non-wxTextCtrl editors, we do need to revert the value
3006 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3007 property
== GetSelection() )
3009 property
->GetEditorClass()->UpdateControl(property
, editor
);
3012 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3017 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3019 int vfb
= m_validationInfo
.m_failureBehavior
;
3021 if ( vfb
& wxPG_VFB_BEEP
)
3024 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3025 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3027 unsigned int colCount
= m_pState
->GetColumnCount();
3029 // We need backup marked property's cells
3030 m_propCellsBackup
= property
->m_cells
;
3032 wxColour vfbFg
= *wxWHITE
;
3033 wxColour vfbBg
= *wxRED
;
3035 property
->EnsureCells(colCount
);
3037 for ( unsigned int i
=0; i
<colCount
; i
++ )
3039 wxPGCell
& cell
= property
->m_cells
[i
];
3040 cell
.SetFgCol(vfbFg
);
3041 cell
.SetBgCol(vfbBg
);
3044 DrawItemAndChildren(property
);
3046 if ( property
== GetSelection() )
3048 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3050 wxWindow
* editor
= GetEditorControl();
3053 editor
->SetForegroundColour(vfbFg
);
3054 editor
->SetBackgroundColour(vfbBg
);
3059 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3061 wxString msg
= m_validationInfo
.m_failureMessage
;
3063 if ( !msg
.length() )
3064 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
3066 DoShowPropertyError(property
, msg
);
3069 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3072 // -----------------------------------------------------------------------
3074 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3076 int vfb
= m_validationInfo
.m_failureBehavior
;
3078 if ( vfb
& wxPG_VFB_MARK_CELL
)
3081 property
->m_cells
= m_propCellsBackup
;
3083 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3085 if ( property
== GetSelection() && GetEditorControl() )
3087 // Calling this will recreate the control, thus resetting its colour
3088 RefreshProperty(property
);
3092 DrawItemAndChildren(property
);
3097 // -----------------------------------------------------------------------
3099 // flags are same as with DoSelectProperty
3100 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3102 if ( m_inDoPropertyChanged
)
3105 wxWindow
* editor
= GetEditorControl();
3106 wxPGProperty
* selected
= GetSelection();
3108 m_pState
->m_anyModified
= 1;
3110 m_inDoPropertyChanged
= 1;
3112 // Maybe need to update control
3113 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3115 // These values were calculated in PerformValidation()
3116 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3117 wxVariant value
= m_chgInfo_pendingValue
;
3119 wxPGProperty
* topPaintedProperty
= changedProperty
;
3121 while ( !topPaintedProperty
->IsCategory() &&
3122 !topPaintedProperty
->IsRoot() )
3124 topPaintedProperty
= topPaintedProperty
->GetParent();
3127 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3129 // Set as Modified (not if dragging just began)
3130 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3132 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3133 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3136 SetCurControlBoldFont();
3142 // Propagate updates to parent(s)
3144 wxPGProperty
* prevPwc
= NULL
;
3146 while ( prevPwc
!= topPaintedProperty
)
3148 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3150 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3153 SetCurControlBoldFont();
3157 pwc
= pwc
->GetParent();
3160 // Draw the actual property
3161 DrawItemAndChildren( topPaintedProperty
);
3164 // If value was set by wxPGProperty::OnEvent, then update the editor
3166 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3172 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3173 if ( m_wndEditor
) m_wndEditor
->Refresh();
3174 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3179 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3181 // If top parent has composite string value, then send to child parents,
3182 // starting from baseChangedProperty.
3183 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3185 pwc
= m_chgInfo_baseChangedProperty
;
3187 while ( pwc
!= changedProperty
)
3189 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3190 pwc
= pwc
->GetParent();
3194 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3196 m_inDoPropertyChanged
= 0;
3201 // -----------------------------------------------------------------------
3203 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3205 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3207 m_chgInfo_changedProperty
= NULL
;
3209 if ( PerformValidation(p
, newValue
) )
3211 DoPropertyChanged(p
);
3216 OnValidationFailure(p
, newValue
);
3222 // -----------------------------------------------------------------------
3224 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3226 wxPGProperty
* prop
= GetSelectedProperty();
3229 return wxNullVariant
;
3231 wxTextCtrl
* tc
= GetEditorTextCtrl();
3232 wxVariant value
= prop
->GetValue();
3234 if ( !tc
|| !IsEditorsValueModified() )
3237 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3240 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3241 return prop
->GetValue();
3246 // -----------------------------------------------------------------------
3248 // Runs wxValidator for the selected property
3249 bool wxPropertyGrid::DoEditorValidate()
3254 // -----------------------------------------------------------------------
3256 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3258 wxPGProperty
* selected
= GetSelection();
3260 // Somehow, event is handled after property has been deselected.
3261 // Possibly, but very rare.
3262 if ( !selected
|| selected
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3265 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3268 wxVariant
pendingValue(selected
->GetValueRef());
3269 wxWindow
* wnd
= GetEditorControl();
3270 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3272 bool wasUnspecified
= selected
->IsValueUnspecified();
3273 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3274 bool valueIsPending
= false;
3276 m_chgInfo_changedProperty
= NULL
;
3278 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3281 // Filter out excess wxTextCtrl modified events
3282 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3284 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3286 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3288 wxString newTcValue
= tc
->GetValue();
3289 if ( m_prevTcValue
== newTcValue
)
3292 m_prevTcValue
= newTcValue
;
3295 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3297 bool validationFailure
= false;
3298 bool buttonWasHandled
= false;
3301 // Try common button handling
3302 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3304 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3308 buttonWasHandled
= true;
3309 // Store as res2, as previously (and still currently alternatively)
3310 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3311 // in wxPGProperty::OnEvent().
3312 adapter
->ShowDialog( this, selected
);
3317 if ( !buttonWasHandled
)
3319 if ( wnd
|| m_wndEditor2
)
3321 // First call editor class' event handler.
3322 const wxPGEditor
* editor
= selected
->GetEditorClass();
3324 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3326 // If changes, validate them
3327 if ( DoEditorValidate() )
3329 if ( editor
->GetValueFromControl( pendingValue
,
3332 valueIsPending
= true;
3336 validationFailure
= true;
3341 // Then the property's custom handler (must be always called, unless
3342 // validation failed).
3343 if ( !validationFailure
)
3344 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3347 // SetValueInEvent(), as called in one of the functions referred above
3348 // overrides editor's value.
3349 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3351 valueIsPending
= true;
3352 pendingValue
= m_changeInEventValue
;
3353 selFlags
|= wxPG_SEL_DIALOGVAL
;
3356 if ( !validationFailure
&& valueIsPending
)
3357 if ( !PerformValidation(selected
, pendingValue
) )
3358 validationFailure
= true;
3360 if ( validationFailure
)
3362 OnValidationFailure(selected
, pendingValue
);
3364 else if ( valueIsPending
)
3366 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3368 DoPropertyChanged(selected
, selFlags
);
3369 EditorsValueWasNotModified();
3371 // Regardless of editor type, unfocus editor on
3372 // text-editing related enter press.
3373 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3380 // No value after all
3382 // Regardless of editor type, unfocus editor on
3383 // text-editing related enter press.
3384 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3389 // Let unhandled button click events go to the parent
3390 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3392 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3393 GetEventHandler()->AddPendingEvent(evt
);
3397 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3400 // -----------------------------------------------------------------------
3401 // wxPropertyGrid editor control helper methods
3402 // -----------------------------------------------------------------------
3404 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3406 int itemy
= p
->GetY2(m_lineHeight
);
3408 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3409 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3410 int imageOffset
= 0;
3412 // TODO: If custom image detection changes from current, change this.
3413 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3415 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3416 int iw
= p
->OnMeasureImage().x
;
3418 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3419 imageOffset
= p
->GetImageOffset(iw
);
3424 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3426 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3431 // -----------------------------------------------------------------------
3433 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3435 wxSize sz
= GetImageSize(p
, item
);
3436 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3437 wxPG_CUSTOM_IMAGE_SPACINGY
,
3442 // return size of custom paint image
3443 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3445 // If called with NULL property, then return default image
3446 // size for properties that use image.
3448 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3450 wxSize cis
= p
->OnMeasureImage(item
);
3452 int choiceCount
= p
->m_choices
.GetCount();
3453 int comVals
= p
->GetDisplayedCommonValueCount();
3454 if ( item
>= choiceCount
&& comVals
> 0 )
3456 unsigned int cvi
= item
-choiceCount
;
3457 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3459 else if ( item
>= 0 && choiceCount
== 0 )
3460 return wxSize(0, 0);
3465 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3470 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3477 // -----------------------------------------------------------------------
3479 // takes scrolling into account
3480 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3483 GetViewStart(&vx
,&vy
);
3484 vy
*=wxPG_PIXELS_PER_UNIT
;
3485 vx
*=wxPG_PIXELS_PER_UNIT
;
3488 ClientToScreen( px
, py
);
3491 // -----------------------------------------------------------------------
3493 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3496 GetViewStart(&pt2
.x
,&pt2
.y
);
3497 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3498 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3502 return m_pState
->HitTest(pt2
);
3505 // -----------------------------------------------------------------------
3507 // custom set cursor
3508 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3510 if ( type
== m_curcursor
&& !override
) return;
3512 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3514 if ( type
== wxCURSOR_SIZEWE
)
3515 cursor
= m_cursorSizeWE
;
3517 m_canvas
->SetCursor( *cursor
);
3522 // -----------------------------------------------------------------------
3523 // wxPropertyGrid property selection, editor creation
3524 // -----------------------------------------------------------------------
3527 // This class forwards events from property editor controls to wxPropertyGrid.
3528 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3531 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3532 : wxEvtHandler(), m_propGrid(propGrid
)
3536 virtual ~wxPropertyGridEditorEventForwarder()
3541 bool ProcessEvent( wxEvent
& event
)
3546 m_propGrid
->HandleCustomEditorEvent(event
);
3548 return wxEvtHandler::ProcessEvent(event
);
3551 wxPropertyGrid
* m_propGrid
;
3554 // Setups event handling for child control
3555 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3557 wxWindowID id
= argWnd
->GetId();
3559 if ( argWnd
== m_wndEditor
)
3561 argWnd
->Connect(id
, wxEVT_MOTION
,
3562 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3564 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3565 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3567 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3568 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3570 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3571 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3573 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3574 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3576 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3577 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3581 wxPropertyGridEditorEventForwarder
* forwarder
;
3582 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3583 argWnd
->PushEventHandler(forwarder
);
3585 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3586 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3590 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3597 // Do not free editors immediately (for sake of processing events)
3598 wxPendingDelete
.Append(wnd
);
3601 void wxPropertyGrid::FreeEditors()
3604 // Return focus back to canvas from children (this is required at least for
3605 // GTK+, which, unlike Windows, clears focus when control is destroyed
3606 // instead of moving it to closest parent).
3607 wxWindow
* focus
= wxWindow::FindFocus();
3610 wxWindow
* parent
= focus
->GetParent();
3613 if ( parent
== m_canvas
)
3618 parent
= parent
->GetParent();
3622 // Do not free editors immediately if processing events
3625 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3626 m_wndEditor2
->Hide();
3627 wxPendingDelete
.Append( handler
);
3628 DestroyEditorWnd(m_wndEditor2
);
3629 m_wndEditor2
= NULL
;
3634 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3635 m_wndEditor
->Hide();
3636 wxPendingDelete
.Append( handler
);
3637 DestroyEditorWnd(m_wndEditor
);
3642 // Call with NULL to de-select property
3643 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3648 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3649 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3653 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3657 if ( m_inDoSelectProperty
)
3660 m_inDoSelectProperty
= 1;
3664 m_inDoSelectProperty
= 0;
3668 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3669 wxPGProperty
* prevFirstSel
;
3671 if ( prevSelection
.size() > 0 )
3672 prevFirstSel
= prevSelection
[0];
3674 prevFirstSel
= NULL
;
3676 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3677 prevFirstSel
= NULL
;
3679 // Always send event, as this is indirect call
3680 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
3684 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3686 wxPrintf( "None selected\n" );
3689 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3691 wxPrintf( "P = NULL\n" );
3694 // If we are frozen, then just set the values.
3697 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3698 m_editorFocused
= 0;
3699 m_pState
->DoSetSelection(p
);
3701 // If frozen, always free controls. But don't worry, as Thaw will
3702 // recall SelectProperty to recreate them.
3705 // Prevent any further selection measures in this call
3711 if ( prevFirstSel
== p
&&
3712 prevSelection
.size() <= 1 &&
3713 !(flags
& wxPG_SEL_FORCE
) )
3715 // Only set focus if not deselecting
3718 if ( flags
& wxPG_SEL_FOCUS
)
3722 m_wndEditor
->SetFocus();
3723 m_editorFocused
= 1;
3732 m_inDoSelectProperty
= 0;
3737 // First, deactivate previous
3740 OnValidationFailureReset(prevFirstSel
);
3742 // Must double-check if this is an selected in case of forceswitch
3743 if ( p
!= prevFirstSel
)
3745 if ( !CommitChangesFromEditor(flags
) )
3747 // Validation has failed, so we can't exit the previous editor
3748 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3749 // _("Invalid Value"),wxOK|wxICON_ERROR);
3750 m_inDoSelectProperty
= 0;
3757 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3758 EditorsValueWasNotModified();
3761 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3763 m_pState
->DoSetSelection(p
);
3765 // Redraw unselected
3766 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
3768 DrawItem(prevSelection
[i
]);
3772 // Then, activate the one given.
3775 int propY
= p
->GetY2(m_lineHeight
);
3777 int splitterX
= GetSplitterPosition();
3778 m_editorFocused
= 0;
3779 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3780 if ( p
!= prevFirstSel
)
3781 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3783 wxASSERT( m_wndEditor
== NULL
);
3786 // Only create editor for non-disabled non-caption
3787 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3789 // do this for non-caption items
3793 // Do we need to paint the custom image, if any?
3794 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3795 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3796 !p
->GetEditorClass()->CanContainCustomImage()
3798 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3800 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3801 wxPoint goodPos
= grect
.GetPosition();
3803 const wxPGEditor
* editor
= p
->GetEditorClass();
3804 wxCHECK_MSG(editor
, false,
3805 wxT("NULL editor class not allowed"));
3807 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3809 wxPGWindowList wndList
= editor
->CreateControls(this,
3814 m_wndEditor
= wndList
.m_primary
;
3815 m_wndEditor2
= wndList
.m_secondary
;
3816 wxWindow
* primaryCtrl
= GetEditorControl();
3819 // Essentially, primaryCtrl == m_wndEditor
3822 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3823 // value is drawn as normal, and m_wndEditor2 is assumed
3824 // to be a right-aligned button that triggers a separate editorCtrl
3829 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3830 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3832 // Set validator, if any
3833 #if wxUSE_VALIDATORS
3834 wxValidator
* validator
= p
->GetValidator();
3836 primaryCtrl
->SetValidator(*validator
);
3839 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3840 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3842 // If it has modified status, use bold font
3843 // (must be done before capturing m_ctrlXAdjust)
3844 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3845 SetCurControlBoldFont();
3848 // Fix TextCtrl indentation
3849 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3850 wxTextCtrl
* tc
= NULL
;
3851 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3852 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3854 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3856 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3859 // Store x relative to splitter (we'll need it).
3860 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3862 // Check if background clear is not necessary
3863 wxPoint pos
= m_wndEditor
->GetPosition();
3864 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3866 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3869 m_wndEditor
->SetSizeHints(3, 3);
3871 SetupChildEventHandling(primaryCtrl
);
3873 // Focus and select all (wxTextCtrl, wxComboBox etc)
3874 if ( flags
& wxPG_SEL_FOCUS
)
3876 primaryCtrl
->SetFocus();
3878 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3884 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3885 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3887 // Get proper id for wndSecondary
3888 m_wndSecId
= m_wndEditor2
->GetId();
3889 wxWindowList children
= m_wndEditor2
->GetChildren();
3890 wxWindowList::iterator node
= children
.begin();
3891 if ( node
!= children
.end() )
3892 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3894 m_wndEditor2
->SetSizeHints(3,3);
3896 m_wndEditor2
->Show();
3898 SetupChildEventHandling(m_wndEditor2
);
3900 // If no primary editor, focus to button to allow
3901 // it to interprete ENTER etc.
3902 // NOTE: Due to problems focusing away from it, this
3903 // has been disabled.
3905 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3906 m_wndEditor2->SetFocus();
3910 if ( flags
& wxPG_SEL_FOCUS
)
3911 m_editorFocused
= 1;
3916 // Make sure focus is in grid canvas (important for wxGTK, at least)
3920 EditorsValueWasNotModified();
3922 // If it's inside collapsed section, expand parent, scroll, etc.
3923 // Also, if it was partially visible, scroll it into view.
3924 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3929 m_wndEditor
->Show(true);
3932 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
3937 // Make sure focus is in grid canvas
3941 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3947 // Show help text in status bar.
3948 // (if found and grid not embedded in manager with help box and
3949 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3952 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3954 wxStatusBar
* statusbar
= NULL
;
3955 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3957 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3959 statusbar
= frame
->GetStatusBar();
3964 const wxString
* pHelpString
= (const wxString
*) NULL
;
3968 pHelpString
= &p
->GetHelpString();
3969 if ( pHelpString
->length() )
3971 // Set help box text.
3972 statusbar
->SetStatusText( *pHelpString
);
3973 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3977 if ( (!pHelpString
|| !pHelpString
->length()) &&
3978 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3980 // Clear help box - but only if it was written
3981 // by us at previous time.
3982 statusbar
->SetStatusText( m_emptyString
);
3983 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3989 m_inDoSelectProperty
= 0;
3991 // call wx event handler (here so that it also occurs on deselection)
3992 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
3993 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
3998 // -----------------------------------------------------------------------
4000 bool wxPropertyGrid::UnfocusEditor()
4002 wxPGProperty
* selected
= GetSelection();
4004 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4007 if ( !CommitChangesFromEditor(0) )
4016 // -----------------------------------------------------------------------
4018 void wxPropertyGrid::RefreshEditor()
4020 wxPGProperty
* p
= GetSelection();
4024 wxWindow
* wnd
= GetEditorControl();
4028 // Set editor font boldness - must do this before
4029 // calling UpdateControl().
4030 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4032 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4033 wnd
->SetFont(GetCaptionFont());
4035 wnd
->SetFont(GetFont());
4038 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4040 editorClass
->UpdateControl(p
, wnd
);
4042 if ( p
->IsValueUnspecified() )
4043 editorClass
->SetValueToUnspecified(p
, wnd
);
4046 // -----------------------------------------------------------------------
4048 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4050 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4052 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4054 flags
|= wxPG_SEL_FOCUS
;
4056 return DoSelectProperty(p
, flags
);
4059 // -----------------------------------------------------------------------
4060 // wxPropertyGrid expand/collapse state
4061 // -----------------------------------------------------------------------
4063 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4065 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4066 wxPGProperty
* selected
= GetSelection();
4068 // If active editor was inside collapsed section, then disable it
4069 if ( selected
&& selected
->IsSomeParent(p
) )
4074 // Store dont-center-splitter flag 'cause we need to temporarily set it
4075 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
4076 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4078 bool res
= m_pState
->DoCollapse(pwc
);
4083 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4085 RecalculateVirtualSize();
4087 // Redraw etc. only if collapsed was visible.
4088 if (pwc
->IsVisible() &&
4090 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
4092 // When item is collapsed so that scrollbar would move,
4093 // graphics mess is about (unless we redraw everything).
4098 // Clear dont-center-splitter flag if it wasn't set
4099 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4104 // -----------------------------------------------------------------------
4106 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4108 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4110 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4112 // Store dont-center-splitter flag 'cause we need to temporarily set it
4113 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
4114 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4116 bool res
= m_pState
->DoExpand(pwc
);
4121 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4123 RecalculateVirtualSize();
4125 // Redraw etc. only if expanded was visible.
4126 if ( pwc
->IsVisible() && !m_frozen
&&
4127 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
4131 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4134 DrawItems(pwc
, NULL
);
4139 // Clear dont-center-splitter flag if it wasn't set
4140 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4145 // -----------------------------------------------------------------------
4147 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4150 return m_pState
->DoHideProperty(p
, hide
, flags
);
4152 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4153 int selRemoveCount
= 0;
4154 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4156 wxPGProperty
* selected
= selection
[i
];
4157 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4159 if ( !DoRemoveFromSelection(p
, flags
) )
4161 selRemoveCount
+= 1;
4165 m_pState
->DoHideProperty(p
, hide
, flags
);
4167 RecalculateVirtualSize();
4174 // -----------------------------------------------------------------------
4175 // wxPropertyGrid size related methods
4176 // -----------------------------------------------------------------------
4178 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4180 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4184 // If virtual height was changed, then recalculate editor control position(s)
4185 if ( m_pState
->m_vhCalcPending
)
4186 CorrectEditorWidgetPosY();
4188 m_pState
->EnsureVirtualHeight();
4190 wxASSERT_LEVEL_2_MSG(
4191 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4192 "VirtualHeight and ActualVirtualHeight should match"
4195 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4197 int x
= m_pState
->m_width
;
4198 int y
= m_pState
->m_virtualHeight
;
4201 GetClientSize(&width
,&height
);
4203 // Now adjust virtual size.
4204 SetVirtualSize(x
, y
);
4210 // Adjust scrollbars
4211 if ( HasVirtualWidth() )
4213 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4214 xPos
= GetScrollPos( wxHORIZONTAL
);
4217 if ( forceXPos
!= -1 )
4220 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4223 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4224 int yPos
= GetScrollPos( wxVERTICAL
);
4226 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4227 xAmount
, yAmount
, xPos
, yPos
, true );
4229 // Must re-get size now
4230 GetClientSize(&width
,&height
);
4232 if ( !HasVirtualWidth() )
4234 m_pState
->SetVirtualWidth(width
);
4241 m_canvas
->SetSize( x
, y
);
4243 m_pState
->CheckColumnWidths();
4245 if ( GetSelection() )
4246 CorrectEditorWidgetSizeX();
4248 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4251 // -----------------------------------------------------------------------
4253 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4255 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4259 GetClientSize(&width
,&height
);
4264 #if wxPG_DOUBLE_BUFFER
4265 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4267 int dblh
= (m_lineHeight
*2);
4268 if ( !m_doubleBuffer
)
4270 // Create double buffer bitmap to draw on, if none
4271 int w
= (width
>250)?width
:250;
4272 int h
= height
+ dblh
;
4274 m_doubleBuffer
= new wxBitmap( w
, h
);
4278 int w
= m_doubleBuffer
->GetWidth();
4279 int h
= m_doubleBuffer
->GetHeight();
4281 // Double buffer must be large enough
4282 if ( w
< width
|| h
< (height
+dblh
) )
4284 if ( w
< width
) w
= width
;
4285 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4286 delete m_doubleBuffer
;
4287 m_doubleBuffer
= new wxBitmap( w
, h
);
4294 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4295 m_ncWidth
= event
.GetSize().x
;
4299 if ( m_pState
->m_itemsAdded
)
4300 PrepareAfterItemsAdded();
4302 // Without this, virtual size (atleast under wxGTK) will be skewed
4303 RecalculateVirtualSize();
4309 // -----------------------------------------------------------------------
4311 void wxPropertyGrid::SetVirtualWidth( int width
)
4315 // Disable virtual width
4316 width
= GetClientSize().x
;
4317 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4321 // Enable virtual width
4322 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4324 m_pState
->SetVirtualWidth( width
);
4327 void wxPropertyGrid::SetFocusOnCanvas()
4329 m_canvas
->SetFocusIgnoringChildren();
4330 m_editorFocused
= 0;
4333 // -----------------------------------------------------------------------
4334 // wxPropertyGrid mouse event handling
4335 // -----------------------------------------------------------------------
4337 // selFlags uses same values DoSelectProperty's flags
4338 // Returns true if event was vetoed.
4339 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4341 unsigned int selFlags
,
4342 unsigned int column
)
4344 // Send property grid event of specific type and with specific property
4345 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4346 evt
.SetPropertyGrid(this);
4347 evt
.SetEventObject(m_eventObject
);
4349 evt
.SetColumn(column
);
4352 evt
.SetCanVeto(true);
4353 evt
.SetupValidationInfo();
4354 m_validationInfo
.m_pValue
= pValue
;
4356 else if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4358 evt
.SetCanVeto(true);
4361 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4363 evtHandler
->ProcessEvent(evt
);
4365 return evt
.WasVetoed();
4368 // -----------------------------------------------------------------------
4370 // Return false if should be skipped
4371 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4375 // Need to set focus?
4376 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4381 wxPropertyGridPageState
* state
= m_pState
;
4383 int splitterHitOffset
;
4384 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4386 wxPGProperty
* p
= DoGetItemAtY(y
);
4390 int depth
= (int)p
->GetDepth() - 1;
4392 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4394 if ( x
>= marginEnds
)
4398 if ( p
->IsCategory() )
4400 // This is category.
4401 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4403 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4405 // Expand, collapse, activate etc. if click on text or left of splitter.
4408 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4413 if ( !AddToSelectionFromInputEvent( p
,
4418 // On double-click, expand/collapse.
4419 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4421 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4422 else DoExpand( p
, true );
4426 else if ( splitterHit
== -1 )
4429 unsigned int selFlag
= 0;
4430 if ( columnHit
== 1 )
4432 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4433 selFlag
= wxPG_SEL_FOCUS
;
4435 if ( !AddToSelectionFromInputEvent( p
,
4441 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4443 if ( p
->GetChildCount() && !p
->IsCategory() )
4444 // On double-click, expand/collapse.
4445 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4447 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4448 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4449 else DoExpand( p
, true );
4456 // click on splitter
4457 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4459 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4461 // Double-clicking the splitter causes auto-centering
4462 CenterSplitter( true );
4464 else if ( m_dragStatus
== 0 )
4467 // Begin draggin the splitter
4471 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4475 // Changes must be committed here or the
4476 // value won't be drawn correctly
4477 if ( !CommitChangesFromEditor() )
4480 m_wndEditor
->Show ( false );
4483 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4485 m_canvas
->CaptureMouse();
4486 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4490 m_draggedSplitter
= splitterHit
;
4491 m_dragOffset
= splitterHitOffset
;
4493 wxClientDC
dc(m_canvas
);
4495 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4496 // Fixes button disappearance bug
4498 m_wndEditor2
->Show ( false );
4501 m_startingSplitterX
= x
- splitterHitOffset
;
4509 if ( p
->GetChildCount() )
4511 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4513 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4515 int y2
= y
% m_lineHeight
;
4516 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4518 // On click on expander button, expand/collapse
4519 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4520 DoCollapse( p
, true );
4522 DoExpand( p
, true );
4531 // -----------------------------------------------------------------------
4533 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4534 unsigned int WXUNUSED(y
),
4535 wxMouseEvent
& event
)
4539 // Select property here as well
4540 wxPGProperty
* p
= m_propHover
;
4541 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4543 // Send right click event.
4544 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4551 // -----------------------------------------------------------------------
4553 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4554 unsigned int WXUNUSED(y
),
4555 wxMouseEvent
& event
)
4559 // Select property here as well
4560 wxPGProperty
* p
= m_propHover
;
4562 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4564 // Send double-click event.
4565 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4572 // -----------------------------------------------------------------------
4574 #if wxPG_SUPPORT_TOOLTIPS
4576 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4578 if ( tipString
.length() )
4580 m_canvas
->SetToolTip(tipString
);
4584 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4585 m_canvas
->SetToolTip( m_emptyString
);
4587 m_canvas
->SetToolTip( NULL
);
4592 #endif // #if wxPG_SUPPORT_TOOLTIPS
4594 // -----------------------------------------------------------------------
4596 // Return false if should be skipped
4597 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4599 // Safety check (needed because mouse capturing may
4600 // otherwise freeze the control)
4601 if ( m_dragStatus
> 0 && !event
.Dragging() )
4603 HandleMouseUp(x
,y
,event
);
4606 wxPropertyGridPageState
* state
= m_pState
;
4608 int splitterHitOffset
;
4609 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4610 int splitterX
= x
- splitterHitOffset
;
4612 m_colHover
= columnHit
;
4614 if ( m_dragStatus
> 0 )
4616 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4617 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4620 int newSplitterX
= x
- m_dragOffset
;
4621 int splitterX
= x
- splitterHitOffset
;
4623 // Splitter redraw required?
4624 if ( newSplitterX
!= splitterX
)
4627 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4628 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4629 state
->m_fSplitterX
= (float) newSplitterX
;
4631 if ( GetSelection() )
4632 CorrectEditorWidgetSizeX();
4646 int ih
= m_lineHeight
;
4649 #if wxPG_SUPPORT_TOOLTIPS
4650 wxPGProperty
* prevHover
= m_propHover
;
4651 unsigned char prevSide
= m_mouseSide
;
4653 int curPropHoverY
= y
- (y
% ih
);
4655 // On which item it hovers
4658 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4661 // Mouse moves on another property
4663 m_propHover
= DoGetItemAtY(y
);
4664 m_propHoverY
= curPropHoverY
;
4667 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4670 #if wxPG_SUPPORT_TOOLTIPS
4671 // Store which side we are on
4673 if ( columnHit
== 1 )
4675 else if ( columnHit
== 0 )
4679 // If tooltips are enabled, show label or value as a tip
4680 // in case it doesn't otherwise show in full length.
4682 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4684 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4686 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4688 if ( m_propHover
&& !m_propHover
->IsCategory() )
4691 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4693 // Show help string as a tooltip
4694 wxString tipString
= m_propHover
->GetHelpString();
4696 SetToolTip(tipString
);
4700 // Show cropped value string as a tooltip
4704 if ( m_mouseSide
== 1 )
4706 tipString
= m_propHover
->m_label
;
4707 space
= splitterX
-m_marginWidth
-3;
4709 else if ( m_mouseSide
== 2 )
4711 tipString
= m_propHover
->GetDisplayedString();
4713 space
= m_width
- splitterX
;
4714 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4715 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4721 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4724 SetToolTip( tipString
);
4731 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4732 m_canvas
->SetToolTip( m_emptyString
);
4734 m_canvas
->SetToolTip( NULL
);
4745 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4746 m_canvas
->SetToolTip( m_emptyString
);
4748 m_canvas
->SetToolTip( NULL
);
4756 if ( splitterHit
== -1 ||
4758 HasFlag(wxPG_STATIC_SPLITTER
) )
4760 // hovering on something else
4761 if ( m_curcursor
!= wxCURSOR_ARROW
)
4762 CustomSetCursor( wxCURSOR_ARROW
);
4766 // Do not allow splitter cursor on caption items.
4767 // (also not if we were dragging and its started
4768 // outside the splitter region)
4770 if ( !m_propHover
->IsCategory() &&
4774 // hovering on splitter
4776 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4777 // reliably detected.
4778 //if ( m_curcursor != wxCURSOR_SIZEWE )
4779 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4785 // hovering on something else
4786 if ( m_curcursor
!= wxCURSOR_ARROW
)
4787 CustomSetCursor( wxCURSOR_ARROW
);
4792 // Multi select by dragging
4794 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
&&
4795 event
.LeftIsDown() &&
4798 !state
->DoIsPropertySelected(m_propHover
) )
4800 DoAddToSelection(m_propHover
);
4806 // -----------------------------------------------------------------------
4808 // Also handles Leaving event
4809 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4810 wxMouseEvent
&WXUNUSED(event
) )
4812 wxPropertyGridPageState
* state
= m_pState
;
4816 int splitterHitOffset
;
4817 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4819 // No event type check - basicly calling this method should
4820 // just stop dragging.
4821 // Left up after dragged?
4822 if ( m_dragStatus
>= 1 )
4825 // End Splitter Dragging
4827 // DO NOT ENABLE FOLLOWING LINE!
4828 // (it is only here as a reminder to not to do it)
4831 // Disable splitter auto-centering
4832 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4834 // This is necessary to return cursor
4835 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4837 m_canvas
->ReleaseMouse();
4838 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4841 // Set back the default cursor, if necessary
4842 if ( splitterHit
== -1 ||
4845 CustomSetCursor( wxCURSOR_ARROW
);
4850 // Control background needs to be cleared
4851 wxPGProperty
* selected
= GetSelection();
4852 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
4853 DrawItem( selected
);
4857 m_wndEditor
->Show ( true );
4860 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4861 // Fixes button disappearance bug
4863 m_wndEditor2
->Show ( true );
4866 // This clears the focus.
4867 m_editorFocused
= 0;
4873 // -----------------------------------------------------------------------
4875 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4877 int splitterX
= GetSplitterPosition();
4880 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4884 wxWindow
* wnd
= GetEditorControl();
4886 // Hide popup on clicks
4887 if ( event
.GetEventType() != wxEVT_MOTION
)
4888 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4890 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4896 if ( wnd
== NULL
|| m_dragStatus
||
4898 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4899 ux
>= (r
.x
+r
.width
) ||
4901 event
.m_y
>= (r
.y
+r
.height
)
4911 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4916 // -----------------------------------------------------------------------
4918 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4921 if ( OnMouseCommon( event
, &x
, &y
) )
4923 HandleMouseClick(x
,y
,event
);
4928 // -----------------------------------------------------------------------
4930 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4933 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4934 HandleMouseRightClick(x
,y
,event
);
4938 // -----------------------------------------------------------------------
4940 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4942 // Always run standard mouse-down handler as well
4943 OnMouseClick(event
);
4946 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4947 HandleMouseDoubleClick(x
,y
,event
);
4951 // -----------------------------------------------------------------------
4953 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4956 if ( OnMouseCommon( event
, &x
, &y
) )
4958 HandleMouseMove(x
,y
,event
);
4963 // -----------------------------------------------------------------------
4965 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4967 // Called when mouse moves in the empty space below the properties.
4968 CustomSetCursor( wxCURSOR_ARROW
);
4971 // -----------------------------------------------------------------------
4973 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4976 if ( OnMouseCommon( event
, &x
, &y
) )
4978 HandleMouseUp(x
,y
,event
);
4983 // -----------------------------------------------------------------------
4985 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4987 // This may get called from child control as well, so event's
4988 // mouse position cannot be relied on.
4990 if ( event
.Entering() )
4992 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4994 // TODO: Fix this (detect parent and only do
4995 // cursor trick if it is a manager).
4996 wxASSERT( GetParent() );
4997 GetParent()->SetCursor(wxNullCursor
);
4999 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5002 GetParent()->SetCursor(wxNullCursor
);
5004 else if ( event
.Leaving() )
5006 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5007 m_canvas
->SetCursor( wxNullCursor
);
5009 // Get real cursor position
5010 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5012 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5015 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5017 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5021 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5029 // -----------------------------------------------------------------------
5031 // Common code used by various OnMouseXXXChild methods.
5032 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5034 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5035 wxASSERT( topCtrlWnd
);
5037 event
.GetPosition(&x
,&y
);
5039 int splitterX
= GetSplitterPosition();
5041 wxRect r
= topCtrlWnd
->GetRect();
5042 if ( !m_dragStatus
&&
5043 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5044 y
>= 0 && y
< r
.height \
5047 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5052 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5059 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5062 if ( OnMouseChildCommon(event
,&x
,&y
) )
5064 bool res
= HandleMouseClick(x
,y
,event
);
5065 if ( !res
) event
.Skip();
5069 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5072 wxASSERT( m_wndEditor
);
5073 // These coords may not be exact (about +-2),
5074 // but that should not matter (right click is about item, not position).
5075 wxPoint pt
= m_wndEditor
->GetPosition();
5076 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5078 // FIXME: Used to set m_propHover to selection here. Was it really
5081 bool res
= HandleMouseRightClick(x
,y
,event
);
5082 if ( !res
) event
.Skip();
5085 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5088 if ( OnMouseChildCommon(event
,&x
,&y
) )
5090 bool res
= HandleMouseMove(x
,y
,event
);
5091 if ( !res
) event
.Skip();
5095 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5098 if ( OnMouseChildCommon(event
,&x
,&y
) )
5100 bool res
= HandleMouseUp(x
,y
,event
);
5101 if ( !res
) event
.Skip();
5105 // -----------------------------------------------------------------------
5106 // wxPropertyGrid keyboard event handling
5107 // -----------------------------------------------------------------------
5109 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5111 // Translates wxKeyEvent to wxPG_ACTION_XXX
5113 int keycode
= event
.GetKeyCode();
5114 int modifiers
= event
.GetModifiers();
5116 wxASSERT( !(modifiers
&~(0xFFFF)) );
5118 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5120 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5122 if ( it
== m_actionTriggers
.end() )
5127 int second
= (it
->second
>>16) & 0xFFFF;
5131 return (it
->second
& 0xFFFF);
5134 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5136 wxASSERT( !(modifiers
&~(0xFFFF)) );
5138 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5140 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5142 if ( it
!= m_actionTriggers
.end() )
5144 // This key combination is already used
5146 // Can add secondary?
5147 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5148 wxT("You can only add up to two separate actions per key combination.") );
5150 action
= it
->second
| (action
<<16);
5153 m_actionTriggers
[hashMapKey
] = action
;
5156 void wxPropertyGrid::ClearActionTriggers( int action
)
5158 wxPGHashMapI2I::iterator it
;
5160 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
5162 if ( it
->second
== action
)
5164 m_actionTriggers
.erase(it
);
5169 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5172 // Handles key event when editor control is not focused.
5175 wxCHECK2(!m_frozen
, return);
5177 // Travelsal between items, collapsing/expanding, etc.
5178 wxPGProperty
* selected
= GetSelection();
5179 int keycode
= event
.GetKeyCode();
5180 bool editorFocused
= IsEditorFocused();
5182 if ( keycode
== WXK_TAB
)
5184 wxWindow
* mainControl
;
5186 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5187 mainControl
= GetParent();
5191 if ( !event
.ShiftDown() )
5193 if ( !editorFocused
&& m_wndEditor
)
5195 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5199 // Tab traversal workaround for platforms on which
5200 // wxWindow::Navigate() may navigate into first child
5201 // instead of next sibling. Does not work perfectly
5202 // in every scenario (for instance, when property grid
5203 // is either first or last control).
5204 #if defined(__WXGTK__)
5205 wxWindow
* sibling
= mainControl
->GetNextSibling();
5207 sibling
->SetFocusFromKbd();
5209 Navigate(wxNavigationKeyEvent::IsForward
);
5215 if ( editorFocused
)
5221 #if defined(__WXGTK__)
5222 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5224 sibling
->SetFocusFromKbd();
5226 Navigate(wxNavigationKeyEvent::IsBackward
);
5234 // Ignore Alt and Control when they are down alone
5235 if ( keycode
== WXK_ALT
||
5236 keycode
== WXK_CONTROL
)
5243 int action
= KeyEventToActions(event
, &secondAction
);
5245 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5248 // Esc cancels any changes
5249 if ( IsEditorsValueModified() )
5251 EditorsValueWasNotModified();
5253 // Update the control as well
5254 selected
->GetEditorClass()->
5255 SetControlStringValue( selected
,
5257 selected
->GetDisplayedString() );
5260 OnValidationFailureReset(selected
);
5266 // Except for TAB and ESC, handle child control events in child control
5269 // Only propagate event if it had modifiers
5270 if ( !event
.HasModifiers() )
5272 event
.StopPropagation();
5278 bool wasHandled
= false;
5283 if ( ButtonTriggerKeyTest(action
, event
) )
5286 wxPGProperty
* p
= selected
;
5288 // Travel and expand/collapse
5291 if ( p
->GetChildCount() )
5293 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5295 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5298 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5300 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5307 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5311 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5317 if ( selectDir
>= -1 )
5319 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5321 DoSelectProperty(p
);
5327 // If nothing was selected, select the first item now
5328 // (or navigate out of tab).
5329 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5331 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5332 if ( p
) DoSelectProperty(p
);
5341 // -----------------------------------------------------------------------
5343 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5345 // If there was editor open and focused, then this event should not
5346 // really be processed here.
5347 if ( IsEditorFocused() )
5349 // However, if event had modifiers, it is probably still best
5351 if ( event
.HasModifiers() )
5354 event
.StopPropagation();
5358 HandleKeyEvent(event
, false);
5361 // -----------------------------------------------------------------------
5363 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5368 action
= KeyEventToActions(event
, &secondAction
);
5371 // Does the keycode trigger button?
5372 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5375 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5376 GetEventHandler()->AddPendingEvent(evt
);
5383 // -----------------------------------------------------------------------
5385 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5387 HandleKeyEvent(event
, true);
5390 // -----------------------------------------------------------------------
5391 // wxPropertyGrid miscellaneous event handling
5392 // -----------------------------------------------------------------------
5394 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5397 // Check if the focus is in this control or one of its children
5398 wxWindow
* newFocused
= wxWindow::FindFocus();
5400 if ( newFocused
!= m_curFocused
)
5401 HandleFocusChange( newFocused
);
5404 // Check if top-level parent has changed
5405 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5407 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5413 bool wxPropertyGrid::IsEditorFocused() const
5415 wxWindow
* focus
= wxWindow::FindFocus();
5417 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5418 focus
== GetEditorControl() )
5424 // Called by focus event handlers. newFocused is the window that becomes focused.
5425 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5427 unsigned int oldFlags
= m_iFlags
;
5429 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5431 wxWindow
* parent
= newFocused
;
5433 // This must be one of nextFocus' parents.
5436 // Use m_eventObject, which is either wxPropertyGrid or
5437 // wxPropertyGridManager, as appropriate.
5438 if ( parent
== m_eventObject
)
5440 m_iFlags
|= wxPG_FL_FOCUSED
;
5443 parent
= parent
->GetParent();
5446 m_curFocused
= newFocused
;
5448 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5449 (oldFlags
& wxPG_FL_FOCUSED
) )
5451 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5453 // Need to store changed value
5454 CommitChangesFromEditor();
5460 // Preliminary code for tab-order respecting
5461 // tab-traversal (but should be moved to
5464 wxWindow* prevFocus = event.GetWindow();
5465 wxWindow* useThis = this;
5466 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5467 useThis = GetParent();
5470 prevFocus->GetParent() == useThis->GetParent() )
5472 wxList& children = useThis->GetParent()->GetChildren();
5474 wxNode* node = children.Find(prevFocus);
5476 if ( node->GetNext() &&
5477 useThis == node->GetNext()->GetData() )
5478 DoSelectProperty(GetFirst());
5479 else if ( node->GetPrevious () &&
5480 useThis == node->GetPrevious()->GetData() )
5481 DoSelectProperty(GetLastProperty());
5488 wxPGProperty
* selected
= GetSelection();
5489 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5490 DrawItem( selected
);
5494 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5496 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5497 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5498 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5499 //else if ( event.GetWindow() )
5501 HandleFocusChange(event
.GetWindow());
5506 // -----------------------------------------------------------------------
5508 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5510 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5514 // -----------------------------------------------------------------------
5516 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5518 m_iFlags
|= wxPG_FL_SCROLLED
;
5523 // -----------------------------------------------------------------------
5525 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5527 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5529 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5533 // -----------------------------------------------------------------------
5534 // Property editor related functions
5535 // -----------------------------------------------------------------------
5537 // noDefCheck = true prevents infinite recursion.
5538 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5539 const wxString
& editorName
,
5542 wxASSERT( editorClass
);
5544 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5545 RegisterDefaultEditors();
5547 wxString name
= editorName
;
5548 if ( name
.length() == 0 )
5549 name
= editorClass
->GetName();
5551 // Existing editor under this name?
5552 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5554 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5556 // If this name was already used, try class name.
5557 name
= editorClass
->GetClassInfo()->GetClassName();
5558 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5561 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5562 (wxPGEditor
*) vt_it
->second
,
5563 "Editor with given name was already registered" );
5565 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5570 // Use this in RegisterDefaultEditors.
5571 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5572 if ( wxPGEditor_##EDITOR == NULL ) \
5574 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5575 new wxPG##EDITOR##Editor, true ); \
5578 // Registers all default editor classes
5579 void wxPropertyGrid::RegisterDefaultEditors()
5581 wxPGRegisterDefaultEditorClass( TextCtrl
);
5582 wxPGRegisterDefaultEditorClass( Choice
);
5583 wxPGRegisterDefaultEditorClass( ComboBox
);
5584 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5585 #if wxPG_INCLUDE_CHECKBOX
5586 wxPGRegisterDefaultEditorClass( CheckBox
);
5588 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5590 // Register SpinCtrl etc. editors before use
5591 RegisterAdditionalEditors();
5594 // -----------------------------------------------------------------------
5595 // wxPGStringTokenizer
5596 // Needed to handle C-style string lists (e.g. "str1" "str2")
5597 // -----------------------------------------------------------------------
5599 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5600 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5604 wxPGStringTokenizer::~wxPGStringTokenizer()
5608 bool wxPGStringTokenizer::HasMoreTokens()
5610 const wxString
& str
= *m_str
;
5612 wxString::const_iterator i
= m_curPos
;
5614 wxUniChar delim
= m_delimeter
;
5616 wxUniChar prev_a
= wxT('\0');
5618 bool inToken
= false;
5620 while ( i
!= str
.end() )
5629 m_readyToken
.clear();
5634 if ( prev_a
!= wxT('\\') )
5638 if ( a
!= wxT('\\') )
5658 m_curPos
= str
.end();
5666 wxString
wxPGStringTokenizer::GetNextToken()
5668 return m_readyToken
;
5671 // -----------------------------------------------------------------------
5673 // -----------------------------------------------------------------------
5675 wxPGChoiceEntry::wxPGChoiceEntry()
5676 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5680 // -----------------------------------------------------------------------
5682 // -----------------------------------------------------------------------
5684 wxPGChoicesData::wxPGChoicesData()
5688 wxPGChoicesData::~wxPGChoicesData()
5693 void wxPGChoicesData::Clear()
5698 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5700 wxASSERT( m_items
.size() == 0 );
5702 m_items
= data
->m_items
;
5705 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5706 const wxPGChoiceEntry
& item
)
5708 wxVector
<wxPGChoiceEntry
>::iterator it
;
5712 index
= (int) m_items
.size();
5716 it
= m_items
.begin() + index
;
5719 m_items
.insert(it
, item
);
5721 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5723 // Need to fix value?
5724 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5725 ownEntry
.SetValue(index
);
5730 // -----------------------------------------------------------------------
5731 // wxPropertyGridEvent
5732 // -----------------------------------------------------------------------
5734 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5737 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5738 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5739 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5740 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5741 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5742 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5743 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5744 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5745 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5746 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
5747 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
5749 // -----------------------------------------------------------------------
5751 void wxPropertyGridEvent::Init()
5753 m_validationInfo
= NULL
;
5756 m_wasVetoed
= false;
5759 // -----------------------------------------------------------------------
5761 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5762 : wxCommandEvent(commandType
,id
)
5768 // -----------------------------------------------------------------------
5770 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5771 : wxCommandEvent(event
)
5773 m_eventType
= event
.GetEventType();
5774 m_eventObject
= event
.m_eventObject
;
5776 m_property
= event
.m_property
;
5777 m_validationInfo
= event
.m_validationInfo
;
5778 m_canVeto
= event
.m_canVeto
;
5779 m_wasVetoed
= event
.m_wasVetoed
;
5782 // -----------------------------------------------------------------------
5784 wxPropertyGridEvent::~wxPropertyGridEvent()
5788 // -----------------------------------------------------------------------
5790 wxEvent
* wxPropertyGridEvent::Clone() const
5792 return new wxPropertyGridEvent( *this );
5795 // -----------------------------------------------------------------------
5796 // wxPropertyGridPopulator
5797 // -----------------------------------------------------------------------
5799 wxPropertyGridPopulator::wxPropertyGridPopulator()
5803 wxPGGlobalVars
->m_offline
++;
5806 // -----------------------------------------------------------------------
5808 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5811 m_propHierarchy
.clear();
5814 // -----------------------------------------------------------------------
5816 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5822 // -----------------------------------------------------------------------
5824 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5827 // Free unused sets of choices
5828 wxPGHashMapS2P::iterator it
;
5830 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5832 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5839 m_pg
->GetPanel()->Refresh();
5841 wxPGGlobalVars
->m_offline
--;
5844 // -----------------------------------------------------------------------
5846 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5847 const wxString
& propLabel
,
5848 const wxString
& propName
,
5849 const wxString
* propValue
,
5850 wxPGChoices
* pChoices
)
5852 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5853 wxPGProperty
* parent
= GetCurParent();
5855 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5857 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5861 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5863 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5867 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5869 property
->SetLabel(propLabel
);
5870 property
->DoSetName(propName
);
5872 if ( pChoices
&& pChoices
->IsOk() )
5873 property
->SetChoices(*pChoices
);
5875 m_state
->DoInsert(parent
, -1, property
);
5878 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5879 wxPG_PROGRAMMATIC_VALUE
);
5884 // -----------------------------------------------------------------------
5886 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5888 m_propHierarchy
.push_back(property
);
5889 DoScanForChildren();
5890 m_propHierarchy
.pop_back();
5893 // -----------------------------------------------------------------------
5895 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5896 const wxString
& idString
)
5898 wxPGChoices choices
;
5901 if ( choicesString
[0] == wxT('@') )
5903 wxString ids
= choicesString
.substr(1);
5904 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5905 if ( it
== m_dictIdChoices
.end() )
5906 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5908 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5913 if ( idString
.length() )
5915 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5916 if ( it
!= m_dictIdChoices
.end() )
5918 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5925 // Parse choices string
5926 wxString::const_iterator it
= choicesString
.begin();
5930 bool labelValid
= false;
5932 for ( ; it
!= choicesString
.end(); ++it
)
5938 if ( c
== wxT('"') )
5943 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5944 choices
.Add(label
, l
);
5947 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5952 else if ( c
== wxT('=') )
5959 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5966 if ( c
== wxT('"') )
5979 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5980 choices
.Add(label
, l
);
5983 if ( !choices
.IsOk() )
5985 choices
.EnsureData();
5989 if ( idString
.length() )
5990 m_dictIdChoices
[idString
] = choices
.GetData();
5997 // -----------------------------------------------------------------------
5999 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6001 if ( s
.Last() == wxT('%') )
6003 wxString s2
= s
.substr(0,s
.length()-1);
6005 if ( s2
.ToLong(&val
, 10) )
6007 *pval
= (val
*max
)/100;
6013 return s
.ToLong(pval
, 10);
6016 // -----------------------------------------------------------------------
6018 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6019 const wxString
& type
,
6020 const wxString
& value
)
6022 int l
= m_propHierarchy
.size();
6026 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6027 wxString valuel
= value
.Lower();
6030 if ( type
.length() == 0 )
6035 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6037 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6039 else if ( value
.ToLong(&v
, 0) )
6046 if ( type
== wxT("string") )
6050 else if ( type
== wxT("int") )
6053 value
.ToLong(&v
, 0);
6056 else if ( type
== wxT("bool") )
6058 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6065 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6070 p
->SetAttribute( name
, variant
);
6075 // -----------------------------------------------------------------------
6077 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6079 wxLogError(_("Error in resource: %s"),msg
.c_str());
6082 // -----------------------------------------------------------------------
6084 #endif // wxUSE_PROPGRID