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::MakeColumnEditable( unsigned int column
,
931 wxASSERT( column
!= 1 );
933 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
937 cols
.push_back(column
);
941 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
943 if ( cols
[i
] == (int)column
)
944 cols
.erase( cols
.begin() + i
);
949 // -----------------------------------------------------------------------
951 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
954 wxPGProperty
* selected
= GetSelection();
955 wxCHECK_RET(selected
, wxT("No property selected"));
956 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
958 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
960 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
967 const wxPGCell
* cell
= NULL
;
968 if ( selected
->HasCell(colIndex
) )
970 cell
= &selected
->GetCell(colIndex
);
971 if ( !cell
->HasText() && colIndex
== 0 )
972 text
= selected
->GetLabel();
978 text
= selected
->GetLabel();
980 cell
= &selected
->GetOrCreateCell(colIndex
);
983 if ( cell
&& cell
->HasText() )
984 text
= cell
->GetText();
986 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
988 m_selColumn
= colIndex
;
990 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
992 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
1000 wxWindowID id
= tc
->GetId();
1001 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1002 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
1004 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1005 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
1010 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1011 m_labelEditorProperty
= selected
;
1014 // -----------------------------------------------------------------------
1017 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1019 DoEndLabelEdit(true);
1022 // -----------------------------------------------------------------------
1024 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1026 int keycode
= event
.GetKeyCode();
1028 if ( keycode
== WXK_ESCAPE
)
1030 DoEndLabelEdit(false);
1038 // -----------------------------------------------------------------------
1040 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1042 if ( !m_labelEditor
)
1045 wxPGProperty
* prop
= m_labelEditorProperty
;
1050 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1052 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1053 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1054 prop
, NULL
, selFlags
,
1059 wxString text
= m_labelEditor
->GetValue();
1060 wxPGCell
* cell
= NULL
;
1061 if ( prop
->HasCell(m_selColumn
) )
1063 cell
= &prop
->GetCell(m_selColumn
);
1067 if ( m_selColumn
== 0 )
1068 prop
->SetLabel(text
);
1070 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1074 cell
->SetText(text
);
1079 DestroyEditorWnd(m_labelEditor
);
1080 m_labelEditor
= NULL
;
1081 m_labelEditorProperty
= NULL
;
1086 // -----------------------------------------------------------------------
1088 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1090 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1091 OnTLPChanging(::wxGetTopLevelParent(this));
1093 OnTLPChanging(NULL
);
1095 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1097 #if defined(__WXMSW__)
1100 // Don't use WS_EX_COMPOSITED just now.
1103 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1104 hWnd = (HWND)GetParent()->GetHWND();
1106 hWnd = (HWND)GetHWND();
1108 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1109 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1112 //#elif defined(__WXGTK20__)
1114 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1115 // truly was double-buffered.
1116 if ( !this->IsDoubleBuffered() )
1118 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1122 #if wxPG_DOUBLE_BUFFER
1123 delete m_doubleBuffer
;
1124 m_doubleBuffer
= NULL
;
1129 wxScrolledWindow::SetExtraStyle( exStyle
);
1131 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1132 m_pState
->InitNonCatMode();
1134 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1135 m_windowStyle
|= wxPG_TOOLTIPS
;
1138 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1141 // -----------------------------------------------------------------------
1143 // returns the best acceptable minimal size
1144 wxSize
wxPropertyGrid::DoGetBestSize() const
1146 int lineHeight
= wxMax(15, m_lineHeight
);
1148 // don't make the grid too tall (limit height to 10 items) but don't
1149 // make it too small neither
1150 int numLines
= wxMin
1152 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1156 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1157 int width
= m_marginWidth
;
1158 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1160 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1163 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1169 // -----------------------------------------------------------------------
1171 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1173 if ( newTLP
== m_tlp
)
1176 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1179 // Parent changed so let's redetermine and re-hook the
1180 // correct top-level window.
1183 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1184 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1186 m_tlpClosed
= m_tlp
;
1187 m_tlpClosedTime
= currentTime
;
1192 // Only accept new tlp if same one was not just dismissed.
1193 if ( newTLP
!= m_tlpClosed
||
1194 m_tlpClosedTime
+250 < currentTime
)
1196 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1197 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1210 // -----------------------------------------------------------------------
1212 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1214 // ClearSelection forces value validation/commit.
1215 if ( event
.CanVeto() && !DoClearSelection() )
1221 // Ok, it can close, set tlp pointer to NULL. Some other event
1222 // handler can of course veto the close, but our OnIdle() should
1223 // then be able to regain the tlp pointer.
1224 OnTLPChanging(NULL
);
1229 // -----------------------------------------------------------------------
1231 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1233 OnTLPChanging((wxWindow
*)newParent
);
1235 bool res
= wxScrolledWindow::Reparent(newParent
);
1240 // -----------------------------------------------------------------------
1241 // wxPropertyGrid Font and Colour Methods
1242 // -----------------------------------------------------------------------
1244 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1248 m_captionFont
= wxScrolledWindow::GetFont();
1250 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1251 m_subgroup_extramargin
= x
+ (x
/2);
1254 #if wxPG_USE_RENDERER_NATIVE
1255 m_iconWidth
= wxPG_ICON_WIDTH
;
1256 #elif wxPG_ICON_WIDTH
1258 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1259 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1260 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1264 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1265 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1266 m_gutterWidth
= wxPG_GUTTER_MIN
;
1269 if ( vspacing
<= 1 ) vdiv
= 12;
1270 else if ( vspacing
>= 3 ) vdiv
= 3;
1272 m_spacingy
= m_fontHeight
/ vdiv
;
1273 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1274 m_spacingy
= wxPG_YSPACING_MIN
;
1277 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1278 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1280 m_captionFont
.SetWeight(wxBOLD
);
1281 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1283 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1286 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1287 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1290 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1292 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1293 RecalculateVirtualSize();
1295 InvalidateBestSize();
1298 // -----------------------------------------------------------------------
1300 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1306 // -----------------------------------------------------------------------
1308 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1309 int ga
= 1000, int ba
= 1000,
1310 bool forceDifferent
= false)
1317 // Recursion guard (allow 2 max)
1318 static int isinside
= 0;
1320 wxCHECK_MSG( isinside
< 3,
1322 wxT("wxPGAdjustColour should not be recursively called more than once") );
1327 int g
= src
.Green();
1330 if ( r2
>255 ) r2
= 255;
1331 else if ( r2
<0) r2
= 0;
1333 if ( g2
>255 ) g2
= 255;
1334 else if ( g2
<0) g2
= 0;
1336 if ( b2
>255 ) b2
= 255;
1337 else if ( b2
<0) b2
= 0;
1339 // Make sure they are somewhat different
1340 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1341 dst
= wxPGAdjustColour(src
,-(ra
*2));
1343 dst
= wxColour(r2
,g2
,b2
);
1345 // Recursion guard (allow 2 max)
1352 static int wxPGGetColAvg( const wxColour
& col
)
1354 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1358 void wxPropertyGrid::RegainColours()
1360 if ( !(m_coloursCustomized
& 0x0002) )
1362 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1364 // Make sure colour is dark enough
1366 int colDec
= wxPGGetColAvg(col
) - 230;
1368 int colDec
= wxPGGetColAvg(col
) - 200;
1371 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1374 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1377 if ( !(m_coloursCustomized
& 0x0001) )
1378 m_colMargin
= m_colCapBack
;
1380 if ( !(m_coloursCustomized
& 0x0004) )
1387 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1388 m_colCapFore
= capForeCol
;
1389 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1392 if ( !(m_coloursCustomized
& 0x0008) )
1394 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1395 m_colPropBack
= bgCol
;
1396 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1399 if ( !(m_coloursCustomized
& 0x0010) )
1401 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1402 m_colPropFore
= fgCol
;
1403 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1406 if ( !(m_coloursCustomized
& 0x0020) )
1407 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1409 if ( !(m_coloursCustomized
& 0x0040) )
1410 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1412 if ( !(m_coloursCustomized
& 0x0080) )
1413 m_colLine
= m_colCapBack
;
1415 if ( !(m_coloursCustomized
& 0x0100) )
1416 m_colDisPropFore
= m_colCapFore
;
1418 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1421 // -----------------------------------------------------------------------
1423 void wxPropertyGrid::ResetColours()
1425 m_coloursCustomized
= 0;
1432 // -----------------------------------------------------------------------
1434 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1436 // Must disable active editor.
1439 bool res
= wxScrolledWindow::SetFont( font
);
1440 if ( res
&& GetParent()) // may not have been Create()ed yet
1442 CalculateFontAndBitmapStuff( m_vspacing
);
1449 // -----------------------------------------------------------------------
1451 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1454 m_coloursCustomized
|= 0x80;
1458 // -----------------------------------------------------------------------
1460 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1463 m_coloursCustomized
|= 0x01;
1467 // -----------------------------------------------------------------------
1469 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1471 m_colPropBack
= col
;
1472 m_coloursCustomized
|= 0x08;
1474 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1479 // -----------------------------------------------------------------------
1481 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1483 m_colPropFore
= col
;
1484 m_coloursCustomized
|= 0x10;
1486 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1491 // -----------------------------------------------------------------------
1493 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1495 m_colEmptySpace
= col
;
1500 // -----------------------------------------------------------------------
1502 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1504 m_colDisPropFore
= col
;
1505 m_coloursCustomized
|= 0x100;
1509 // -----------------------------------------------------------------------
1511 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1514 m_coloursCustomized
|= 0x20;
1518 // -----------------------------------------------------------------------
1520 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1523 m_coloursCustomized
|= 0x40;
1527 // -----------------------------------------------------------------------
1529 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1532 m_coloursCustomized
|= 0x02;
1534 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1539 // -----------------------------------------------------------------------
1541 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1544 m_coloursCustomized
|= 0x04;
1546 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1551 // -----------------------------------------------------------------------
1552 // wxPropertyGrid property adding and removal
1553 // -----------------------------------------------------------------------
1555 void wxPropertyGrid::PrepareAfterItemsAdded()
1557 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1559 m_pState
->m_itemsAdded
= 0;
1561 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1562 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1564 RecalculateVirtualSize();
1567 // -----------------------------------------------------------------------
1568 // wxPropertyGrid property operations
1569 // -----------------------------------------------------------------------
1571 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1573 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1577 bool changed
= false;
1579 // Is it inside collapsed section?
1580 if ( !p
->IsVisible() )
1583 wxPGProperty
* parent
= p
->GetParent();
1584 wxPGProperty
* grandparent
= parent
->GetParent();
1586 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1587 Expand( grandparent
);
1595 GetViewStart(&vx
,&vy
);
1596 vy
*=wxPG_PIXELS_PER_UNIT
;
1602 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1603 m_iFlags
|= wxPG_FL_SCROLLED
;
1606 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1608 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1609 m_iFlags
|= wxPG_FL_SCROLLED
;
1619 // -----------------------------------------------------------------------
1620 // wxPropertyGrid helper methods called by properties
1621 // -----------------------------------------------------------------------
1623 // Control font changer helper.
1624 void wxPropertyGrid::SetCurControlBoldFont()
1626 wxASSERT( m_wndEditor
);
1627 m_wndEditor
->SetFont( m_captionFont
);
1630 // -----------------------------------------------------------------------
1632 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1635 #if wxPG_SMALL_SCREEN
1636 // On small-screen devices, always show dialogs with default position and size.
1637 return wxDefaultPosition
;
1639 int splitterX
= GetSplitterPosition();
1643 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1645 ImprovedClientToScreen( &x
, &y
);
1647 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1648 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1655 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1665 new_y
= y
+ m_lineHeight
;
1667 return wxPoint(new_x
,new_y
);
1671 // -----------------------------------------------------------------------
1673 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1675 if ( src_str
.length() == 0 )
1681 bool prev_is_slash
= false;
1683 wxString::const_iterator i
= src_str
.begin();
1687 for ( ; i
!= src_str
.end(); ++i
)
1691 if ( a
!= wxS('\\') )
1693 if ( !prev_is_slash
)
1699 if ( a
== wxS('n') )
1702 dst_str
<< wxS('\n');
1704 dst_str
<< wxS('\n');
1707 else if ( a
== wxS('t') )
1708 dst_str
<< wxS('\t');
1712 prev_is_slash
= false;
1716 if ( prev_is_slash
)
1718 dst_str
<< wxS('\\');
1719 prev_is_slash
= false;
1723 prev_is_slash
= true;
1730 // -----------------------------------------------------------------------
1732 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1734 if ( src_str
.length() == 0 )
1740 wxString::const_iterator i
= src_str
.begin();
1741 wxUniChar prev_a
= wxS('\0');
1745 for ( ; i
!= src_str
.end(); ++i
)
1749 if ( a
>= wxS(' ') )
1751 // This surely is not something that requires an escape sequence.
1756 // This might need...
1757 if ( a
== wxS('\r') )
1759 // DOS style line end.
1760 // Already taken care below
1762 else if ( a
== wxS('\n') )
1763 // UNIX style line end.
1764 dst_str
<< wxS("\\n");
1765 else if ( a
== wxS('\t') )
1767 dst_str
<< wxS('\t');
1770 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1780 // -----------------------------------------------------------------------
1782 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1789 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1792 // -----------------------------------------------------------------------
1793 // wxPropertyGrid graphics related methods
1794 // -----------------------------------------------------------------------
1796 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1800 // Update everything inside the box
1801 wxRect r
= GetUpdateRegion().GetBox();
1803 dc
.SetPen(m_colEmptySpace
);
1804 dc
.SetBrush(m_colEmptySpace
);
1805 dc
.DrawRectangle(r
);
1808 // -----------------------------------------------------------------------
1810 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1811 wxPGProperty
* property
) const
1813 // Prepare rectangle to be used
1815 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1816 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1818 #if (wxPG_USE_RENDERER_NATIVE)
1820 #elif wxPG_ICON_WIDTH
1821 // Drawing expand/collapse button manually
1822 dc
.SetPen(m_colPropFore
);
1823 if ( property
->IsCategory() )
1824 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1826 dc
.SetBrush(m_colPropBack
);
1828 dc
.DrawRectangle( r
);
1829 int _y
= r
.y
+(m_iconWidth
/2);
1830 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1835 if ( property
->IsExpanded() )
1837 // wxRenderer functions are non-mutating in nature, so it
1838 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1839 // Hopefully this does not cause problems.
1840 #if (wxPG_USE_RENDERER_NATIVE)
1841 wxRendererNative::Get().DrawTreeItemButton(
1847 #elif wxPG_ICON_WIDTH
1856 #if (wxPG_USE_RENDERER_NATIVE)
1857 wxRendererNative::Get().DrawTreeItemButton(
1863 #elif wxPG_ICON_WIDTH
1864 int _x
= r
.x
+(m_iconWidth
/2);
1865 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1871 #if (wxPG_USE_RENDERER_NATIVE)
1873 #elif wxPG_ICON_WIDTH
1876 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1880 // -----------------------------------------------------------------------
1883 // This is the one called by OnPaint event handler and others.
1884 // topy and bottomy are already unscrolled (ie. physical)
1886 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1888 unsigned int bottomy
,
1889 const wxRect
* clipRect
)
1891 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1893 m_pState
->EnsureVirtualHeight();
1895 wxRect tempClipRect
;
1898 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1899 clipRect
= &tempClipRect
;
1902 // items added check
1903 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1905 int paintFinishY
= 0;
1907 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1910 bool isBuffered
= false;
1912 #if wxPG_DOUBLE_BUFFER
1913 wxMemoryDC
* bufferDC
= NULL
;
1915 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1917 if ( !m_doubleBuffer
)
1919 paintFinishY
= clipRect
->y
;
1924 bufferDC
= new wxMemoryDC();
1926 // If nothing was changed, then just copy from double-buffer
1927 bufferDC
->SelectObject( *m_doubleBuffer
);
1937 dc
.SetClippingRegion( *clipRect
);
1938 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1941 #if wxPG_DOUBLE_BUFFER
1944 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1945 bufferDC
, 0, 0, wxCOPY
);
1946 dc
.DestroyClippingRegion(); // Is this really necessary?
1952 // Clear area beyond bottomY?
1953 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1955 dc
.SetPen(m_colEmptySpace
);
1956 dc
.SetBrush(m_colEmptySpace
);
1957 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1961 // -----------------------------------------------------------------------
1963 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1964 const wxRect
* clipRect
,
1965 bool isBuffered
) const
1967 const wxPGProperty
* firstItem
;
1968 const wxPGProperty
* lastItem
;
1970 firstItem
= DoGetItemAtY(clipRect
->y
);
1971 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1974 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1976 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1979 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1980 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1982 int lh
= m_lineHeight
;
1985 int lastItemBottomY
;
1987 firstItemTopY
= clipRect
->y
;
1988 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1990 // Align y coordinates to item boundaries
1991 firstItemTopY
-= firstItemTopY
% lh
;
1992 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1993 lastItemBottomY
-= 1;
1995 // Entire range outside scrolled, visible area?
1996 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1999 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
2003 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
2004 firstItem->GetLabel().c_str(),
2005 lastItem->GetLabel().c_str(),
2006 (int)(lastItemBottomY - firstItemTopY),
2008 (unsigned long)clipRect );
2013 long windowStyle
= m_windowStyle
;
2019 // With wxPG_DOUBLE_BUFFER, do double buffering
2020 // - buffer's y = 0, so align cliprect and coordinates to that
2022 #if wxPG_DOUBLE_BUFFER
2028 xRelMod
= clipRect
->x
;
2029 yRelMod
= clipRect
->y
;
2032 // clipRect conversion
2037 firstItemTopY
-= yRelMod
;
2038 lastItemBottomY
-= yRelMod
;
2041 wxUnusedVar(isBuffered
);
2044 int x
= m_marginWidth
- xRelMod
;
2046 wxFont normalFont
= GetFont();
2048 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2050 bool isPgEnabled
= IsEnabled();
2053 // Prepare some pens and brushes that are often changed to.
2056 wxBrush
marginBrush(m_colMargin
);
2057 wxPen
marginPen(m_colMargin
);
2058 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2059 wxPen
linepen(m_colLine
,1,wxSOLID
);
2061 wxColour selBackCol
;
2063 selBackCol
= m_colSelBack
;
2065 selBackCol
= m_colMargin
;
2067 // pen that has same colour as text
2068 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2071 // Clear margin with background colour
2073 dc
.SetBrush( marginBrush
);
2074 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2076 dc
.SetPen( *wxTRANSPARENT_PEN
);
2077 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2080 const wxPGProperty
* firstSelected
= GetSelection();
2081 const wxPropertyGridPageState
* state
= m_pState
;
2083 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2084 bool wasSelectedPainted
= false;
2087 // TODO: Only render columns that are within clipping region.
2089 dc
.SetFont(normalFont
);
2091 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2092 int endScanBottomY
= lastItemBottomY
+ lh
;
2093 int y
= firstItemTopY
;
2096 // Pregenerate list of visible properties.
2097 wxArrayPGProperty visPropArray
;
2098 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2100 for ( ; !it
.AtEnd(); it
.Next() )
2102 const wxPGProperty
* p
= *it
;
2104 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2106 visPropArray
.push_back((wxPGProperty
*)p
);
2108 if ( y
> endScanBottomY
)
2115 visPropArray
.push_back(NULL
);
2117 wxPGProperty
* nextP
= visPropArray
[0];
2119 int gridWidth
= state
->m_width
;
2122 for ( unsigned int arrInd
=1;
2123 nextP
&& y
<= lastItemBottomY
;
2126 wxPGProperty
* p
= nextP
;
2127 nextP
= visPropArray
[arrInd
];
2129 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2130 int textMarginHere
= x
;
2131 int renderFlags
= 0;
2133 int greyDepth
= m_marginWidth
;
2134 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2135 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2137 int greyDepthX
= greyDepth
- xRelMod
;
2139 // Use basic depth if in non-categoric mode and parent is base array.
2140 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2142 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2145 // Paint margin area
2146 dc
.SetBrush(marginBrush
);
2147 dc
.SetPen(marginPen
);
2148 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2150 dc
.SetPen( linepen
);
2155 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2161 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2163 sx
+= state
->m_colWidths
[si
];
2164 dc
.DrawLine( sx
, y
, sx
, y2
);
2167 // Horizontal Line, below
2168 // (not if both this and next is category caption)
2169 if ( p
->IsCategory() &&
2170 nextP
&& nextP
->IsCategory() )
2171 dc
.SetPen(m_colCapBack
);
2173 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2176 // Need to override row colours?
2180 bool isSelected
= state
->DoIsPropertySelected(p
);
2184 // Disabled may get different colour.
2185 if ( !p
->IsEnabled() )
2187 renderFlags
|= wxPGCellRenderer::Disabled
|
2188 wxPGCellRenderer::DontUseCellFgCol
;
2189 rowFgCol
= m_colDisPropFore
;
2194 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2195 if ( p
== firstSelected
)
2196 wasSelectedPainted
= true;
2199 renderFlags
|= wxPGCellRenderer::Selected
;
2201 if ( !p
->IsCategory() )
2203 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2204 wxPGCellRenderer::DontUseCellBgCol
;
2206 if ( reallyFocused
&& p
== firstSelected
)
2208 rowFgCol
= m_colSelFore
;
2209 rowBgCol
= selBackCol
;
2211 else if ( isPgEnabled
)
2213 rowFgCol
= m_colPropFore
;
2214 if ( p
== firstSelected
)
2215 rowBgCol
= m_colMargin
;
2217 rowBgCol
= selBackCol
;
2221 rowFgCol
= m_colDisPropFore
;
2222 rowBgCol
= selBackCol
;
2229 if ( rowBgCol
.IsOk() )
2230 rowBgBrush
= wxBrush(rowBgCol
);
2232 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2233 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2236 // Fill additional margin area with background colour of first cell
2237 if ( greyDepthX
< textMarginHere
)
2239 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2241 wxPGCell
& cell
= p
->GetCell(0);
2242 rowBgCol
= cell
.GetBgCol();
2243 rowBgBrush
= wxBrush(rowBgCol
);
2245 dc
.SetBrush(rowBgBrush
);
2246 dc
.SetPen(rowBgCol
);
2247 dc
.DrawRectangle(greyDepthX
+1, y
,
2248 textMarginHere
-greyDepthX
, lh
-1);
2251 bool fontChanged
= false;
2253 // Expander button rectangle
2254 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2259 if ( p
->IsCategory() )
2261 // Captions have their cell areas merged as one
2262 dc
.SetFont(m_captionFont
);
2264 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2266 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2268 dc
.SetBrush(rowBgBrush
);
2269 dc
.SetPen(rowBgCol
);
2272 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2274 dc
.SetTextForeground(rowFgCol
);
2277 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2278 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2281 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2282 DrawExpanderButton( dc
, butRect
, p
);
2286 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2288 dc
.SetFont(m_captionFont
);
2294 int nextCellWidth
= state
->m_colWidths
[0] -
2295 (greyDepthX
- m_marginWidth
);
2296 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2297 int textXAdd
= textMarginHere
- greyDepthX
;
2299 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2301 cellRect
.width
= nextCellWidth
- 1;
2303 wxWindow
* cellEditor
= NULL
;
2304 int cellRenderFlags
= renderFlags
;
2306 // Tree Item Button (must be drawn before clipping is set up)
2307 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2308 DrawExpanderButton( dc
, butRect
, p
);
2311 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2313 if ( p
== firstSelected
)
2315 if ( ci
== 1 && m_wndEditor
)
2316 cellEditor
= m_wndEditor
;
2317 else if ( ci
== m_selColumn
&& m_labelEditor
)
2318 cellEditor
= m_labelEditor
;
2323 wxColour editorBgCol
=
2324 cellEditor
->GetBackgroundColour();
2325 dc
.SetBrush(editorBgCol
);
2326 dc
.SetPen(editorBgCol
);
2327 dc
.SetTextForeground(m_colPropFore
);
2328 dc
.DrawRectangle(cellRect
);
2330 if ( m_dragStatus
!= 0 ||
2331 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2336 dc
.SetBrush(m_colPropBack
);
2337 dc
.SetPen(m_colPropBack
);
2338 dc
.SetTextForeground(m_colDisPropFore
);
2339 if ( p
->IsEnabled() )
2340 dc
.SetTextForeground(rowFgCol
);
2342 dc
.SetTextForeground(m_colDisPropFore
);
2347 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2349 dc
.SetBrush(rowBgBrush
);
2350 dc
.SetPen(rowBgCol
);
2353 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2355 dc
.SetTextForeground(rowFgCol
);
2359 dc
.SetClippingRegion(cellRect
);
2361 cellRect
.x
+= textXAdd
;
2362 cellRect
.width
-= textXAdd
;
2367 wxPGCellRenderer
* renderer
;
2368 int cmnVal
= p
->GetCommonValue();
2369 if ( cmnVal
== -1 || ci
!= 1 )
2371 renderer
= p
->GetCellRenderer(ci
);
2372 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2377 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2378 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2383 cellX
+= state
->m_colWidths
[ci
];
2384 if ( ci
< (state
->m_colWidths
.size()-1) )
2385 nextCellWidth
= state
->m_colWidths
[ci
+1];
2387 dc
.DestroyClippingRegion(); // Is this really necessary?
2393 dc
.SetFont(normalFont
);
2398 // Refresh editor controls (seems not needed on msw)
2399 // NOTE: This code is mandatory for GTK!
2400 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2401 if ( wasSelectedPainted
)
2404 m_wndEditor
->Refresh();
2406 m_wndEditor2
->Refresh();
2413 // -----------------------------------------------------------------------
2415 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2419 if ( m_width
< 10 || m_height
< 10 ||
2420 !m_pState
->m_properties
->GetChildCount() ||
2422 return wxRect(0,0,0,0);
2427 // Return rect which encloses the given property range
2429 int visTop
= p1
->GetY();
2432 visBottom
= p2
->GetY() + m_lineHeight
;
2434 visBottom
= m_height
+ visTop
;
2436 // If seleced property is inside the range, we'll extend the range to include
2438 wxPGProperty
* selected
= GetSelection();
2441 int selectedY
= selected
->GetY();
2442 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2444 wxWindow
* editor
= GetEditorControl();
2447 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2448 if ( visBottom2
> visBottom
)
2449 visBottom
= visBottom2
;
2454 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2457 // -----------------------------------------------------------------------
2459 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2464 if ( m_pState
->m_itemsAdded
)
2465 PrepareAfterItemsAdded();
2467 wxRect r
= GetPropertyRect(p1
, p2
);
2470 m_canvas
->RefreshRect(r
);
2474 // -----------------------------------------------------------------------
2476 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2478 if ( m_pState
->DoIsPropertySelected(p
) )
2480 // NB: We must copy the selection.
2481 wxArrayPGProperty selection
= m_pState
->m_selection
;
2482 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2485 DrawItemAndChildren(p
);
2488 // -----------------------------------------------------------------------
2490 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2495 // Draw item, children, and parent too, if it is not category
2496 wxPGProperty
* parent
= p
->GetParent();
2499 !parent
->IsCategory() &&
2500 parent
->GetParent() )
2503 parent
= parent
->GetParent();
2506 DrawItemAndChildren(p
);
2509 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2511 wxCHECK_RET( p
, wxT("invalid property id") );
2513 // Do not draw if in non-visible page
2514 if ( p
->GetParentState() != m_pState
)
2517 // do not draw a single item if multiple pending
2518 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2521 // Update child control.
2522 wxPGProperty
* selected
= GetSelection();
2523 if ( selected
&& selected
->GetParent() == p
)
2526 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2528 DrawItems(p
, lastDrawn
);
2531 // -----------------------------------------------------------------------
2533 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2534 const wxRect
*rect
)
2536 PrepareAfterItemsAdded();
2538 wxWindow::Refresh(false);
2540 // TODO: Coordinate translation
2541 m_canvas
->Refresh(false, rect
);
2543 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2544 // I think this really helps only GTK+1.2
2545 if ( m_wndEditor
) m_wndEditor
->Refresh();
2546 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2550 // -----------------------------------------------------------------------
2551 // wxPropertyGrid global operations
2552 // -----------------------------------------------------------------------
2554 void wxPropertyGrid::Clear()
2556 m_pState
->DoClear();
2562 RecalculateVirtualSize();
2564 // Need to clear some area at the end
2566 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2569 // -----------------------------------------------------------------------
2571 bool wxPropertyGrid::EnableCategories( bool enable
)
2578 // Enable categories
2581 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2586 // Disable categories
2588 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2591 if ( !m_pState
->EnableCategories(enable
) )
2596 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2598 m_pState
->m_itemsAdded
= 1; // force
2599 PrepareAfterItemsAdded();
2603 m_pState
->m_itemsAdded
= 1;
2605 // No need for RecalculateVirtualSize() here - it is already called in
2606 // wxPropertyGridPageState method above.
2613 // -----------------------------------------------------------------------
2615 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2617 wxASSERT( pNewState
);
2618 wxASSERT( pNewState
->GetGrid() );
2620 if ( pNewState
== m_pState
)
2623 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2625 // Call ClearSelection() instead of DoClearSelection()
2626 // so that selection clear events are not sent.
2629 m_pState
->m_selection
= oldSelection
;
2631 bool orig_mode
= m_pState
->IsInNonCatMode();
2632 bool new_state_mode
= pNewState
->IsInNonCatMode();
2634 m_pState
= pNewState
;
2637 int pgWidth
= GetClientSize().x
;
2638 if ( HasVirtualWidth() )
2640 int minWidth
= pgWidth
;
2641 if ( pNewState
->m_width
< minWidth
)
2643 pNewState
->m_width
= minWidth
;
2644 pNewState
->CheckColumnWidths();
2650 // Just in case, fully re-center splitter
2651 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2652 pNewState
->m_fSplitterX
= -1.0;
2654 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2659 // If necessary, convert state to correct mode.
2660 if ( orig_mode
!= new_state_mode
)
2662 // This should refresh as well.
2663 EnableCategories( orig_mode
?false:true );
2665 else if ( !m_frozen
)
2667 // Refresh, if not frozen.
2668 m_pState
->PrepareAfterItemsAdded();
2670 // Reselect (Use SetSelection() instead of Do-variant so that
2671 // events won't be sent).
2672 SetSelection(m_pState
->m_selection
);
2674 RecalculateVirtualSize(0);
2678 m_pState
->m_itemsAdded
= 1;
2681 // -----------------------------------------------------------------------
2683 // Call to SetSplitterPosition will always disable splitter auto-centering
2684 // if parent window is shown.
2685 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2687 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2690 wxPropertyGridPageState
* state
= m_pState
;
2692 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2696 if ( GetSelection() )
2697 CorrectEditorWidgetSizeX();
2703 // -----------------------------------------------------------------------
2705 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2707 SetSplitterPosition( m_width
/2, true );
2708 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2709 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2712 // -----------------------------------------------------------------------
2713 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2714 // -----------------------------------------------------------------------
2716 // Returns nearest paint visible property (such that will be painted unless
2717 // window is scrolled or resized). If given property is paint visible, then
2718 // it itself will be returned
2719 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2721 int vx
,vy1
;// Top left corner of client
2722 GetViewStart(&vx
,&vy1
);
2723 vy1
*= wxPG_PIXELS_PER_UNIT
;
2725 int vy2
= vy1
+ m_height
;
2726 int propY
= p
->GetY2(m_lineHeight
);
2728 if ( (propY
+ m_lineHeight
) < vy1
)
2731 return DoGetItemAtY( vy1
);
2733 else if ( propY
> vy2
)
2736 return DoGetItemAtY( vy2
);
2739 // Itself paint visible
2744 // -----------------------------------------------------------------------
2745 // Methods related to change in value, value modification and sending events
2746 // -----------------------------------------------------------------------
2748 // commits any changes in editor of selected property
2749 // return true if validation did not fail
2750 // flags are same as with DoSelectProperty
2751 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2753 // Committing already?
2754 if ( m_inCommitChangesFromEditor
)
2757 // Don't do this if already processing editor event. It might
2758 // induce recursive dialogs and crap like that.
2759 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2761 if ( m_inDoPropertyChanged
)
2767 wxPGProperty
* selected
= GetSelection();
2770 IsEditorsValueModified() &&
2771 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2774 m_inCommitChangesFromEditor
= 1;
2776 wxVariant
variant(selected
->GetValueRef());
2777 bool valueIsPending
= false;
2779 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2780 // due to another window getting focus
2781 wxWindow
* oldFocus
= m_curFocused
;
2783 bool validationFailure
= false;
2784 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2786 m_chgInfo_changedProperty
= NULL
;
2788 // If truly modified, schedule value as pending.
2789 if ( selected
->GetEditorClass()->
2790 GetValueFromControl( variant
,
2792 GetEditorControl() ) )
2794 if ( DoEditorValidate() &&
2795 PerformValidation(selected
, variant
) )
2797 valueIsPending
= true;
2801 validationFailure
= true;
2806 EditorsValueWasNotModified();
2811 m_inCommitChangesFromEditor
= 0;
2813 if ( validationFailure
&& !forceSuccess
)
2817 oldFocus
->SetFocus();
2818 m_curFocused
= oldFocus
;
2821 res
= OnValidationFailure(selected
, variant
);
2823 // Now prevent further validation failure messages
2826 EditorsValueWasNotModified();
2827 OnValidationFailureReset(selected
);
2830 else if ( valueIsPending
)
2832 DoPropertyChanged( selected
, flags
);
2833 EditorsValueWasNotModified();
2842 // -----------------------------------------------------------------------
2844 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2848 // Runs all validation functionality.
2849 // Returns true if value passes all tests.
2852 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2854 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2856 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2861 // Adapt list to child values, if necessary
2862 wxVariant listValue
= pendingValue
;
2863 wxVariant
* pPendingValue
= &pendingValue
;
2864 wxVariant
* pList
= NULL
;
2866 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2867 // string value, then we need treat as it was changed instead
2868 // (or, in addition, as is the case with composite string parent).
2869 // This includes creating list variant for child values.
2871 wxPGProperty
* pwc
= p
->GetParent();
2872 wxPGProperty
* changedProperty
= p
;
2873 wxPGProperty
* baseChangedProperty
= changedProperty
;
2874 wxVariant bcpPendingList
;
2876 listValue
= pendingValue
;
2877 listValue
.SetName(p
->GetBaseName());
2880 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2882 wxVariantList tempList
;
2883 wxVariant
lv(tempList
, pwc
->GetBaseName());
2884 lv
.Append(listValue
);
2886 pPendingValue
= &listValue
;
2888 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2890 baseChangedProperty
= pwc
;
2891 bcpPendingList
= lv
;
2894 changedProperty
= pwc
;
2895 pwc
= pwc
->GetParent();
2899 wxPGProperty
* evtChangingProperty
= changedProperty
;
2901 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2903 value
= *pPendingValue
;
2907 // Convert list to child values
2908 pList
= pPendingValue
;
2909 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2912 wxVariant evtChangingValue
= value
;
2914 if ( flags
& SendEvtChanging
)
2916 // FIXME: After proper ValueToString()s added, remove
2917 // this. It is just a temporary fix, as evt_changing
2918 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2919 // (unless it is selected, and textctrl editor is open).
2920 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2922 evtChangingProperty
= baseChangedProperty
;
2923 if ( evtChangingProperty
!= p
)
2925 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2929 evtChangingValue
= pendingValue
;
2933 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2935 if ( changedProperty
== GetSelection() )
2937 wxWindow
* editor
= GetEditorControl();
2938 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2939 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2943 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2948 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2949 m_chgInfo_changedProperty
= changedProperty
;
2950 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2951 m_chgInfo_pendingValue
= value
;
2954 m_chgInfo_valueList
= *pList
;
2956 m_chgInfo_valueList
.MakeNull();
2958 // If changedProperty is not property which value was edited,
2959 // then call wxPGProperty::ValidateValue() for that as well.
2960 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2962 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2966 if ( flags
& SendEvtChanging
)
2968 // SendEvent returns true if event was vetoed
2969 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
2970 &evtChangingValue
) )
2974 if ( flags
& IsStandaloneValidation
)
2976 // If called in 'generic' context, we need to reset
2977 // m_chgInfo_changedProperty and write back translated value.
2978 m_chgInfo_changedProperty
= NULL
;
2979 pendingValue
= value
;
2985 // -----------------------------------------------------------------------
2987 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2989 if ( !msg
.length() )
2993 if ( !wxPGGlobalVars
->m_offline
)
2995 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2998 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
3001 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
3004 pStatusBar
->SetStatusText(msg
);
3012 ::wxMessageBox(msg
, wxT("Property Error"));
3015 // -----------------------------------------------------------------------
3017 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3018 wxVariant
& invalidValue
)
3020 wxWindow
* editor
= GetEditorControl();
3022 // First call property's handler
3023 property
->OnValidationFailure(invalidValue
);
3025 bool res
= DoOnValidationFailure(property
, invalidValue
);
3028 // For non-wxTextCtrl editors, we do need to revert the value
3029 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3030 property
== GetSelection() )
3032 property
->GetEditorClass()->UpdateControl(property
, editor
);
3035 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3040 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3042 int vfb
= m_validationInfo
.m_failureBehavior
;
3044 if ( vfb
& wxPG_VFB_BEEP
)
3047 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3048 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3050 unsigned int colCount
= m_pState
->GetColumnCount();
3052 // We need backup marked property's cells
3053 m_propCellsBackup
= property
->m_cells
;
3055 wxColour vfbFg
= *wxWHITE
;
3056 wxColour vfbBg
= *wxRED
;
3058 property
->EnsureCells(colCount
);
3060 for ( unsigned int i
=0; i
<colCount
; i
++ )
3062 wxPGCell
& cell
= property
->m_cells
[i
];
3063 cell
.SetFgCol(vfbFg
);
3064 cell
.SetBgCol(vfbBg
);
3067 DrawItemAndChildren(property
);
3069 if ( property
== GetSelection() )
3071 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3073 wxWindow
* editor
= GetEditorControl();
3076 editor
->SetForegroundColour(vfbFg
);
3077 editor
->SetBackgroundColour(vfbBg
);
3082 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3084 wxString msg
= m_validationInfo
.m_failureMessage
;
3086 if ( !msg
.length() )
3087 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
3089 DoShowPropertyError(property
, msg
);
3092 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3095 // -----------------------------------------------------------------------
3097 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3099 int vfb
= m_validationInfo
.m_failureBehavior
;
3101 if ( vfb
& wxPG_VFB_MARK_CELL
)
3104 property
->m_cells
= m_propCellsBackup
;
3106 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3108 if ( property
== GetSelection() && GetEditorControl() )
3110 // Calling this will recreate the control, thus resetting its colour
3111 RefreshProperty(property
);
3115 DrawItemAndChildren(property
);
3120 // -----------------------------------------------------------------------
3122 // flags are same as with DoSelectProperty
3123 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3125 if ( m_inDoPropertyChanged
)
3128 wxWindow
* editor
= GetEditorControl();
3129 wxPGProperty
* selected
= GetSelection();
3131 m_pState
->m_anyModified
= 1;
3133 m_inDoPropertyChanged
= 1;
3135 // Maybe need to update control
3136 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3138 // These values were calculated in PerformValidation()
3139 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3140 wxVariant value
= m_chgInfo_pendingValue
;
3142 wxPGProperty
* topPaintedProperty
= changedProperty
;
3144 while ( !topPaintedProperty
->IsCategory() &&
3145 !topPaintedProperty
->IsRoot() )
3147 topPaintedProperty
= topPaintedProperty
->GetParent();
3150 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3152 // Set as Modified (not if dragging just began)
3153 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3155 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3156 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3159 SetCurControlBoldFont();
3165 // Propagate updates to parent(s)
3167 wxPGProperty
* prevPwc
= NULL
;
3169 while ( prevPwc
!= topPaintedProperty
)
3171 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3173 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3176 SetCurControlBoldFont();
3180 pwc
= pwc
->GetParent();
3183 // Draw the actual property
3184 DrawItemAndChildren( topPaintedProperty
);
3187 // If value was set by wxPGProperty::OnEvent, then update the editor
3189 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3195 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3196 if ( m_wndEditor
) m_wndEditor
->Refresh();
3197 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3202 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3204 // If top parent has composite string value, then send to child parents,
3205 // starting from baseChangedProperty.
3206 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3208 pwc
= m_chgInfo_baseChangedProperty
;
3210 while ( pwc
!= changedProperty
)
3212 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3213 pwc
= pwc
->GetParent();
3217 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3219 m_inDoPropertyChanged
= 0;
3224 // -----------------------------------------------------------------------
3226 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3228 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3230 m_chgInfo_changedProperty
= NULL
;
3232 if ( PerformValidation(p
, newValue
) )
3234 DoPropertyChanged(p
);
3239 OnValidationFailure(p
, newValue
);
3245 // -----------------------------------------------------------------------
3247 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3249 wxPGProperty
* prop
= GetSelectedProperty();
3252 return wxNullVariant
;
3254 wxTextCtrl
* tc
= GetEditorTextCtrl();
3255 wxVariant value
= prop
->GetValue();
3257 if ( !tc
|| !IsEditorsValueModified() )
3260 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3263 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3264 return prop
->GetValue();
3269 // -----------------------------------------------------------------------
3271 // Runs wxValidator for the selected property
3272 bool wxPropertyGrid::DoEditorValidate()
3277 // -----------------------------------------------------------------------
3279 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3281 wxPGProperty
* selected
= GetSelection();
3283 // Somehow, event is handled after property has been deselected.
3284 // Possibly, but very rare.
3285 if ( !selected
|| selected
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3288 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3291 wxVariant
pendingValue(selected
->GetValueRef());
3292 wxWindow
* wnd
= GetEditorControl();
3293 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3295 bool wasUnspecified
= selected
->IsValueUnspecified();
3296 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3297 bool valueIsPending
= false;
3299 m_chgInfo_changedProperty
= NULL
;
3301 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3304 // Filter out excess wxTextCtrl modified events
3305 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3307 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3309 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3311 wxString newTcValue
= tc
->GetValue();
3312 if ( m_prevTcValue
== newTcValue
)
3315 m_prevTcValue
= newTcValue
;
3318 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3320 bool validationFailure
= false;
3321 bool buttonWasHandled
= false;
3324 // Try common button handling
3325 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3327 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3331 buttonWasHandled
= true;
3332 // Store as res2, as previously (and still currently alternatively)
3333 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3334 // in wxPGProperty::OnEvent().
3335 adapter
->ShowDialog( this, selected
);
3340 if ( !buttonWasHandled
)
3342 if ( wnd
|| m_wndEditor2
)
3344 // First call editor class' event handler.
3345 const wxPGEditor
* editor
= selected
->GetEditorClass();
3347 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3349 // If changes, validate them
3350 if ( DoEditorValidate() )
3352 if ( editor
->GetValueFromControl( pendingValue
,
3355 valueIsPending
= true;
3359 validationFailure
= true;
3364 // Then the property's custom handler (must be always called, unless
3365 // validation failed).
3366 if ( !validationFailure
)
3367 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3370 // SetValueInEvent(), as called in one of the functions referred above
3371 // overrides editor's value.
3372 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3374 valueIsPending
= true;
3375 pendingValue
= m_changeInEventValue
;
3376 selFlags
|= wxPG_SEL_DIALOGVAL
;
3379 if ( !validationFailure
&& valueIsPending
)
3380 if ( !PerformValidation(selected
, pendingValue
) )
3381 validationFailure
= true;
3383 if ( validationFailure
)
3385 OnValidationFailure(selected
, pendingValue
);
3387 else if ( valueIsPending
)
3389 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3391 DoPropertyChanged(selected
, selFlags
);
3392 EditorsValueWasNotModified();
3394 // Regardless of editor type, unfocus editor on
3395 // text-editing related enter press.
3396 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3403 // No value after all
3405 // Regardless of editor type, unfocus editor on
3406 // text-editing related enter press.
3407 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3412 // Let unhandled button click events go to the parent
3413 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3415 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3416 GetEventHandler()->AddPendingEvent(evt
);
3420 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3423 // -----------------------------------------------------------------------
3424 // wxPropertyGrid editor control helper methods
3425 // -----------------------------------------------------------------------
3427 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3429 int itemy
= p
->GetY2(m_lineHeight
);
3431 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3432 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3433 int imageOffset
= 0;
3435 // TODO: If custom image detection changes from current, change this.
3436 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3438 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3439 int iw
= p
->OnMeasureImage().x
;
3441 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3442 imageOffset
= p
->GetImageOffset(iw
);
3447 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3449 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3454 // -----------------------------------------------------------------------
3456 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3458 wxSize sz
= GetImageSize(p
, item
);
3459 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3460 wxPG_CUSTOM_IMAGE_SPACINGY
,
3465 // return size of custom paint image
3466 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3468 // If called with NULL property, then return default image
3469 // size for properties that use image.
3471 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3473 wxSize cis
= p
->OnMeasureImage(item
);
3475 int choiceCount
= p
->m_choices
.GetCount();
3476 int comVals
= p
->GetDisplayedCommonValueCount();
3477 if ( item
>= choiceCount
&& comVals
> 0 )
3479 unsigned int cvi
= item
-choiceCount
;
3480 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3482 else if ( item
>= 0 && choiceCount
== 0 )
3483 return wxSize(0, 0);
3488 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3493 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3500 // -----------------------------------------------------------------------
3502 // takes scrolling into account
3503 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3506 GetViewStart(&vx
,&vy
);
3507 vy
*=wxPG_PIXELS_PER_UNIT
;
3508 vx
*=wxPG_PIXELS_PER_UNIT
;
3511 ClientToScreen( px
, py
);
3514 // -----------------------------------------------------------------------
3516 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3519 GetViewStart(&pt2
.x
,&pt2
.y
);
3520 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3521 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3525 return m_pState
->HitTest(pt2
);
3528 // -----------------------------------------------------------------------
3530 // custom set cursor
3531 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3533 if ( type
== m_curcursor
&& !override
) return;
3535 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3537 if ( type
== wxCURSOR_SIZEWE
)
3538 cursor
= m_cursorSizeWE
;
3540 m_canvas
->SetCursor( *cursor
);
3545 // -----------------------------------------------------------------------
3546 // wxPropertyGrid property selection, editor creation
3547 // -----------------------------------------------------------------------
3550 // This class forwards events from property editor controls to wxPropertyGrid.
3551 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3554 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3555 : wxEvtHandler(), m_propGrid(propGrid
)
3559 virtual ~wxPropertyGridEditorEventForwarder()
3564 bool ProcessEvent( wxEvent
& event
)
3569 m_propGrid
->HandleCustomEditorEvent(event
);
3571 return wxEvtHandler::ProcessEvent(event
);
3574 wxPropertyGrid
* m_propGrid
;
3577 // Setups event handling for child control
3578 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3580 wxWindowID id
= argWnd
->GetId();
3582 if ( argWnd
== m_wndEditor
)
3584 argWnd
->Connect(id
, wxEVT_MOTION
,
3585 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3587 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3588 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3590 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3591 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3593 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3594 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3596 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3597 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3599 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3600 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3604 wxPropertyGridEditorEventForwarder
* forwarder
;
3605 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3606 argWnd
->PushEventHandler(forwarder
);
3608 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3609 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3613 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3620 // Do not free editors immediately (for sake of processing events)
3621 wxPendingDelete
.Append(wnd
);
3624 void wxPropertyGrid::FreeEditors()
3627 // Return focus back to canvas from children (this is required at least for
3628 // GTK+, which, unlike Windows, clears focus when control is destroyed
3629 // instead of moving it to closest parent).
3630 wxWindow
* focus
= wxWindow::FindFocus();
3633 wxWindow
* parent
= focus
->GetParent();
3636 if ( parent
== m_canvas
)
3641 parent
= parent
->GetParent();
3645 // Do not free editors immediately if processing events
3648 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3649 m_wndEditor2
->Hide();
3650 wxPendingDelete
.Append( handler
);
3651 DestroyEditorWnd(m_wndEditor2
);
3652 m_wndEditor2
= NULL
;
3657 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3658 m_wndEditor
->Hide();
3659 wxPendingDelete
.Append( handler
);
3660 DestroyEditorWnd(m_wndEditor
);
3665 // Call with NULL to de-select property
3666 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3671 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3672 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3676 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3680 if ( m_inDoSelectProperty
)
3683 m_inDoSelectProperty
= 1;
3687 m_inDoSelectProperty
= 0;
3691 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3692 wxPGProperty
* prevFirstSel
;
3694 if ( prevSelection
.size() > 0 )
3695 prevFirstSel
= prevSelection
[0];
3697 prevFirstSel
= NULL
;
3699 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3700 prevFirstSel
= NULL
;
3702 // Always send event, as this is indirect call
3703 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
3707 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3709 wxPrintf( "None selected\n" );
3712 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3714 wxPrintf( "P = NULL\n" );
3717 // If we are frozen, then just set the values.
3720 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3721 m_editorFocused
= 0;
3722 m_pState
->DoSetSelection(p
);
3724 // If frozen, always free controls. But don't worry, as Thaw will
3725 // recall SelectProperty to recreate them.
3728 // Prevent any further selection measures in this call
3734 if ( prevFirstSel
== p
&&
3735 prevSelection
.size() <= 1 &&
3736 !(flags
& wxPG_SEL_FORCE
) )
3738 // Only set focus if not deselecting
3741 if ( flags
& wxPG_SEL_FOCUS
)
3745 m_wndEditor
->SetFocus();
3746 m_editorFocused
= 1;
3755 m_inDoSelectProperty
= 0;
3760 // First, deactivate previous
3763 OnValidationFailureReset(prevFirstSel
);
3765 // Must double-check if this is an selected in case of forceswitch
3766 if ( p
!= prevFirstSel
)
3768 if ( !CommitChangesFromEditor(flags
) )
3770 // Validation has failed, so we can't exit the previous editor
3771 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3772 // _("Invalid Value"),wxOK|wxICON_ERROR);
3773 m_inDoSelectProperty
= 0;
3780 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3781 EditorsValueWasNotModified();
3784 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3786 m_pState
->DoSetSelection(p
);
3788 // Redraw unselected
3789 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
3791 DrawItem(prevSelection
[i
]);
3795 // Then, activate the one given.
3798 int propY
= p
->GetY2(m_lineHeight
);
3800 int splitterX
= GetSplitterPosition();
3801 m_editorFocused
= 0;
3802 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3803 if ( p
!= prevFirstSel
)
3804 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3806 wxASSERT( m_wndEditor
== NULL
);
3809 // Only create editor for non-disabled non-caption
3810 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3812 // do this for non-caption items
3816 // Do we need to paint the custom image, if any?
3817 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3818 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3819 !p
->GetEditorClass()->CanContainCustomImage()
3821 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3823 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3824 wxPoint goodPos
= grect
.GetPosition();
3826 const wxPGEditor
* editor
= p
->GetEditorClass();
3827 wxCHECK_MSG(editor
, false,
3828 wxT("NULL editor class not allowed"));
3830 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3832 wxPGWindowList wndList
= editor
->CreateControls(this,
3837 m_wndEditor
= wndList
.m_primary
;
3838 m_wndEditor2
= wndList
.m_secondary
;
3839 wxWindow
* primaryCtrl
= GetEditorControl();
3842 // Essentially, primaryCtrl == m_wndEditor
3845 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3846 // value is drawn as normal, and m_wndEditor2 is assumed
3847 // to be a right-aligned button that triggers a separate editorCtrl
3852 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3853 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3855 // Set validator, if any
3856 #if wxUSE_VALIDATORS
3857 wxValidator
* validator
= p
->GetValidator();
3859 primaryCtrl
->SetValidator(*validator
);
3862 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3863 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3865 // If it has modified status, use bold font
3866 // (must be done before capturing m_ctrlXAdjust)
3867 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3868 SetCurControlBoldFont();
3871 // Fix TextCtrl indentation
3872 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3873 wxTextCtrl
* tc
= NULL
;
3874 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3875 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3877 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3879 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3882 // Store x relative to splitter (we'll need it).
3883 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3885 // Check if background clear is not necessary
3886 wxPoint pos
= m_wndEditor
->GetPosition();
3887 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3889 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3892 m_wndEditor
->SetSizeHints(3, 3);
3894 SetupChildEventHandling(primaryCtrl
);
3896 // Focus and select all (wxTextCtrl, wxComboBox etc)
3897 if ( flags
& wxPG_SEL_FOCUS
)
3899 primaryCtrl
->SetFocus();
3901 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3907 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3908 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3910 // Get proper id for wndSecondary
3911 m_wndSecId
= m_wndEditor2
->GetId();
3912 wxWindowList children
= m_wndEditor2
->GetChildren();
3913 wxWindowList::iterator node
= children
.begin();
3914 if ( node
!= children
.end() )
3915 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3917 m_wndEditor2
->SetSizeHints(3,3);
3919 m_wndEditor2
->Show();
3921 SetupChildEventHandling(m_wndEditor2
);
3923 // If no primary editor, focus to button to allow
3924 // it to interprete ENTER etc.
3925 // NOTE: Due to problems focusing away from it, this
3926 // has been disabled.
3928 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3929 m_wndEditor2->SetFocus();
3933 if ( flags
& wxPG_SEL_FOCUS
)
3934 m_editorFocused
= 1;
3939 // Make sure focus is in grid canvas (important for wxGTK, at least)
3943 EditorsValueWasNotModified();
3945 // If it's inside collapsed section, expand parent, scroll, etc.
3946 // Also, if it was partially visible, scroll it into view.
3947 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3952 m_wndEditor
->Show(true);
3955 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
3960 // Make sure focus is in grid canvas
3964 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3970 // Show help text in status bar.
3971 // (if found and grid not embedded in manager with help box and
3972 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3975 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3977 wxStatusBar
* statusbar
= NULL
;
3978 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3980 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3982 statusbar
= frame
->GetStatusBar();
3987 const wxString
* pHelpString
= (const wxString
*) NULL
;
3991 pHelpString
= &p
->GetHelpString();
3992 if ( pHelpString
->length() )
3994 // Set help box text.
3995 statusbar
->SetStatusText( *pHelpString
);
3996 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4000 if ( (!pHelpString
|| !pHelpString
->length()) &&
4001 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
4003 // Clear help box - but only if it was written
4004 // by us at previous time.
4005 statusbar
->SetStatusText( m_emptyString
);
4006 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4012 m_inDoSelectProperty
= 0;
4014 // call wx event handler (here so that it also occurs on deselection)
4015 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4016 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4021 // -----------------------------------------------------------------------
4023 bool wxPropertyGrid::UnfocusEditor()
4025 wxPGProperty
* selected
= GetSelection();
4027 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4030 if ( !CommitChangesFromEditor(0) )
4039 // -----------------------------------------------------------------------
4041 void wxPropertyGrid::RefreshEditor()
4043 wxPGProperty
* p
= GetSelection();
4047 wxWindow
* wnd
= GetEditorControl();
4051 // Set editor font boldness - must do this before
4052 // calling UpdateControl().
4053 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4055 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4056 wnd
->SetFont(GetCaptionFont());
4058 wnd
->SetFont(GetFont());
4061 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4063 editorClass
->UpdateControl(p
, wnd
);
4065 if ( p
->IsValueUnspecified() )
4066 editorClass
->SetValueToUnspecified(p
, wnd
);
4069 // -----------------------------------------------------------------------
4071 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4073 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4075 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4077 flags
|= wxPG_SEL_FOCUS
;
4079 return DoSelectProperty(p
, flags
);
4082 // -----------------------------------------------------------------------
4083 // wxPropertyGrid expand/collapse state
4084 // -----------------------------------------------------------------------
4086 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4088 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4089 wxPGProperty
* selected
= GetSelection();
4091 // If active editor was inside collapsed section, then disable it
4092 if ( selected
&& selected
->IsSomeParent(p
) )
4097 // Store dont-center-splitter flag 'cause we need to temporarily set it
4098 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
4099 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4101 bool res
= m_pState
->DoCollapse(pwc
);
4106 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4108 RecalculateVirtualSize();
4110 // Redraw etc. only if collapsed was visible.
4111 if (pwc
->IsVisible() &&
4113 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
4115 // When item is collapsed so that scrollbar would move,
4116 // graphics mess is about (unless we redraw everything).
4121 // Clear dont-center-splitter flag if it wasn't set
4122 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4127 // -----------------------------------------------------------------------
4129 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4131 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4133 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4135 // Store dont-center-splitter flag 'cause we need to temporarily set it
4136 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
4137 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4139 bool res
= m_pState
->DoExpand(pwc
);
4144 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4146 RecalculateVirtualSize();
4148 // Redraw etc. only if expanded was visible.
4149 if ( pwc
->IsVisible() && !m_frozen
&&
4150 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
4154 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4157 DrawItems(pwc
, NULL
);
4162 // Clear dont-center-splitter flag if it wasn't set
4163 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4168 // -----------------------------------------------------------------------
4170 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4173 return m_pState
->DoHideProperty(p
, hide
, flags
);
4175 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4176 int selRemoveCount
= 0;
4177 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4179 wxPGProperty
* selected
= selection
[i
];
4180 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4182 if ( !DoRemoveFromSelection(p
, flags
) )
4184 selRemoveCount
+= 1;
4188 m_pState
->DoHideProperty(p
, hide
, flags
);
4190 RecalculateVirtualSize();
4197 // -----------------------------------------------------------------------
4198 // wxPropertyGrid size related methods
4199 // -----------------------------------------------------------------------
4201 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4203 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4207 // If virtual height was changed, then recalculate editor control position(s)
4208 if ( m_pState
->m_vhCalcPending
)
4209 CorrectEditorWidgetPosY();
4211 m_pState
->EnsureVirtualHeight();
4213 wxASSERT_LEVEL_2_MSG(
4214 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4215 "VirtualHeight and ActualVirtualHeight should match"
4218 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4220 int x
= m_pState
->m_width
;
4221 int y
= m_pState
->m_virtualHeight
;
4224 GetClientSize(&width
,&height
);
4226 // Now adjust virtual size.
4227 SetVirtualSize(x
, y
);
4233 // Adjust scrollbars
4234 if ( HasVirtualWidth() )
4236 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4237 xPos
= GetScrollPos( wxHORIZONTAL
);
4240 if ( forceXPos
!= -1 )
4243 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4246 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4247 int yPos
= GetScrollPos( wxVERTICAL
);
4249 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4250 xAmount
, yAmount
, xPos
, yPos
, true );
4252 // Must re-get size now
4253 GetClientSize(&width
,&height
);
4255 if ( !HasVirtualWidth() )
4257 m_pState
->SetVirtualWidth(width
);
4264 m_canvas
->SetSize( x
, y
);
4266 m_pState
->CheckColumnWidths();
4268 if ( GetSelection() )
4269 CorrectEditorWidgetSizeX();
4271 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4274 // -----------------------------------------------------------------------
4276 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4278 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4282 GetClientSize(&width
,&height
);
4287 #if wxPG_DOUBLE_BUFFER
4288 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4290 int dblh
= (m_lineHeight
*2);
4291 if ( !m_doubleBuffer
)
4293 // Create double buffer bitmap to draw on, if none
4294 int w
= (width
>250)?width
:250;
4295 int h
= height
+ dblh
;
4297 m_doubleBuffer
= new wxBitmap( w
, h
);
4301 int w
= m_doubleBuffer
->GetWidth();
4302 int h
= m_doubleBuffer
->GetHeight();
4304 // Double buffer must be large enough
4305 if ( w
< width
|| h
< (height
+dblh
) )
4307 if ( w
< width
) w
= width
;
4308 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4309 delete m_doubleBuffer
;
4310 m_doubleBuffer
= new wxBitmap( w
, h
);
4317 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4318 m_ncWidth
= event
.GetSize().x
;
4322 if ( m_pState
->m_itemsAdded
)
4323 PrepareAfterItemsAdded();
4325 // Without this, virtual size (atleast under wxGTK) will be skewed
4326 RecalculateVirtualSize();
4332 // -----------------------------------------------------------------------
4334 void wxPropertyGrid::SetVirtualWidth( int width
)
4338 // Disable virtual width
4339 width
= GetClientSize().x
;
4340 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4344 // Enable virtual width
4345 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4347 m_pState
->SetVirtualWidth( width
);
4350 void wxPropertyGrid::SetFocusOnCanvas()
4352 m_canvas
->SetFocusIgnoringChildren();
4353 m_editorFocused
= 0;
4356 // -----------------------------------------------------------------------
4357 // wxPropertyGrid mouse event handling
4358 // -----------------------------------------------------------------------
4360 // selFlags uses same values DoSelectProperty's flags
4361 // Returns true if event was vetoed.
4362 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4364 unsigned int selFlags
,
4365 unsigned int column
)
4367 // Send property grid event of specific type and with specific property
4368 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4369 evt
.SetPropertyGrid(this);
4370 evt
.SetEventObject(m_eventObject
);
4372 evt
.SetColumn(column
);
4375 evt
.SetCanVeto(true);
4376 evt
.SetupValidationInfo();
4377 m_validationInfo
.m_pValue
= pValue
;
4379 else if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4381 evt
.SetCanVeto(true);
4384 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4386 evtHandler
->ProcessEvent(evt
);
4388 return evt
.WasVetoed();
4391 // -----------------------------------------------------------------------
4393 // Return false if should be skipped
4394 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4398 // Need to set focus?
4399 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4404 wxPropertyGridPageState
* state
= m_pState
;
4406 int splitterHitOffset
;
4407 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4409 wxPGProperty
* p
= DoGetItemAtY(y
);
4413 int depth
= (int)p
->GetDepth() - 1;
4415 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4417 if ( x
>= marginEnds
)
4421 if ( p
->IsCategory() )
4423 // This is category.
4424 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4426 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4428 // Expand, collapse, activate etc. if click on text or left of splitter.
4431 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4436 if ( !AddToSelectionFromInputEvent( p
,
4441 // On double-click, expand/collapse.
4442 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4444 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4445 else DoExpand( p
, true );
4449 else if ( splitterHit
== -1 )
4452 unsigned int selFlag
= 0;
4453 if ( columnHit
== 1 )
4455 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4456 selFlag
= wxPG_SEL_FOCUS
;
4458 if ( !AddToSelectionFromInputEvent( p
,
4464 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4466 if ( p
->GetChildCount() && !p
->IsCategory() )
4467 // On double-click, expand/collapse.
4468 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4470 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4471 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4472 else DoExpand( p
, true );
4479 // click on splitter
4480 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4482 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4484 // Double-clicking the splitter causes auto-centering
4485 CenterSplitter( true );
4487 else if ( m_dragStatus
== 0 )
4490 // Begin draggin the splitter
4494 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4498 // Changes must be committed here or the
4499 // value won't be drawn correctly
4500 if ( !CommitChangesFromEditor() )
4503 m_wndEditor
->Show ( false );
4506 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4508 m_canvas
->CaptureMouse();
4509 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4513 m_draggedSplitter
= splitterHit
;
4514 m_dragOffset
= splitterHitOffset
;
4516 wxClientDC
dc(m_canvas
);
4518 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4519 // Fixes button disappearance bug
4521 m_wndEditor2
->Show ( false );
4524 m_startingSplitterX
= x
- splitterHitOffset
;
4532 if ( p
->GetChildCount() )
4534 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4536 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4538 int y2
= y
% m_lineHeight
;
4539 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4541 // On click on expander button, expand/collapse
4542 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4543 DoCollapse( p
, true );
4545 DoExpand( p
, true );
4554 // -----------------------------------------------------------------------
4556 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4557 unsigned int WXUNUSED(y
),
4558 wxMouseEvent
& event
)
4562 // Select property here as well
4563 wxPGProperty
* p
= m_propHover
;
4564 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4566 // Send right click event.
4567 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4574 // -----------------------------------------------------------------------
4576 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4577 unsigned int WXUNUSED(y
),
4578 wxMouseEvent
& event
)
4582 // Select property here as well
4583 wxPGProperty
* p
= m_propHover
;
4585 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4587 // Send double-click event.
4588 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4595 // -----------------------------------------------------------------------
4597 #if wxPG_SUPPORT_TOOLTIPS
4599 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4601 if ( tipString
.length() )
4603 m_canvas
->SetToolTip(tipString
);
4607 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4608 m_canvas
->SetToolTip( m_emptyString
);
4610 m_canvas
->SetToolTip( NULL
);
4615 #endif // #if wxPG_SUPPORT_TOOLTIPS
4617 // -----------------------------------------------------------------------
4619 // Return false if should be skipped
4620 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4622 // Safety check (needed because mouse capturing may
4623 // otherwise freeze the control)
4624 if ( m_dragStatus
> 0 && !event
.Dragging() )
4626 HandleMouseUp(x
,y
,event
);
4629 wxPropertyGridPageState
* state
= m_pState
;
4631 int splitterHitOffset
;
4632 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4633 int splitterX
= x
- splitterHitOffset
;
4635 m_colHover
= columnHit
;
4637 if ( m_dragStatus
> 0 )
4639 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4640 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4643 int newSplitterX
= x
- m_dragOffset
;
4644 int splitterX
= x
- splitterHitOffset
;
4646 // Splitter redraw required?
4647 if ( newSplitterX
!= splitterX
)
4650 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4651 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4652 state
->m_fSplitterX
= (float) newSplitterX
;
4654 if ( GetSelection() )
4655 CorrectEditorWidgetSizeX();
4669 int ih
= m_lineHeight
;
4672 #if wxPG_SUPPORT_TOOLTIPS
4673 wxPGProperty
* prevHover
= m_propHover
;
4674 unsigned char prevSide
= m_mouseSide
;
4676 int curPropHoverY
= y
- (y
% ih
);
4678 // On which item it hovers
4681 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4684 // Mouse moves on another property
4686 m_propHover
= DoGetItemAtY(y
);
4687 m_propHoverY
= curPropHoverY
;
4690 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4693 #if wxPG_SUPPORT_TOOLTIPS
4694 // Store which side we are on
4696 if ( columnHit
== 1 )
4698 else if ( columnHit
== 0 )
4702 // If tooltips are enabled, show label or value as a tip
4703 // in case it doesn't otherwise show in full length.
4705 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4707 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4709 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4711 if ( m_propHover
&& !m_propHover
->IsCategory() )
4714 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4716 // Show help string as a tooltip
4717 wxString tipString
= m_propHover
->GetHelpString();
4719 SetToolTip(tipString
);
4723 // Show cropped value string as a tooltip
4727 if ( m_mouseSide
== 1 )
4729 tipString
= m_propHover
->m_label
;
4730 space
= splitterX
-m_marginWidth
-3;
4732 else if ( m_mouseSide
== 2 )
4734 tipString
= m_propHover
->GetDisplayedString();
4736 space
= m_width
- splitterX
;
4737 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4738 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4744 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4747 SetToolTip( tipString
);
4754 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4755 m_canvas
->SetToolTip( m_emptyString
);
4757 m_canvas
->SetToolTip( NULL
);
4768 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4769 m_canvas
->SetToolTip( m_emptyString
);
4771 m_canvas
->SetToolTip( NULL
);
4779 if ( splitterHit
== -1 ||
4781 HasFlag(wxPG_STATIC_SPLITTER
) )
4783 // hovering on something else
4784 if ( m_curcursor
!= wxCURSOR_ARROW
)
4785 CustomSetCursor( wxCURSOR_ARROW
);
4789 // Do not allow splitter cursor on caption items.
4790 // (also not if we were dragging and its started
4791 // outside the splitter region)
4793 if ( !m_propHover
->IsCategory() &&
4797 // hovering on splitter
4799 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4800 // reliably detected.
4801 //if ( m_curcursor != wxCURSOR_SIZEWE )
4802 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4808 // hovering on something else
4809 if ( m_curcursor
!= wxCURSOR_ARROW
)
4810 CustomSetCursor( wxCURSOR_ARROW
);
4815 // Multi select by dragging
4817 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
&&
4818 event
.LeftIsDown() &&
4821 !state
->DoIsPropertySelected(m_propHover
) )
4823 DoAddToSelection(m_propHover
);
4829 // -----------------------------------------------------------------------
4831 // Also handles Leaving event
4832 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4833 wxMouseEvent
&WXUNUSED(event
) )
4835 wxPropertyGridPageState
* state
= m_pState
;
4839 int splitterHitOffset
;
4840 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4842 // No event type check - basicly calling this method should
4843 // just stop dragging.
4844 // Left up after dragged?
4845 if ( m_dragStatus
>= 1 )
4848 // End Splitter Dragging
4850 // DO NOT ENABLE FOLLOWING LINE!
4851 // (it is only here as a reminder to not to do it)
4854 // Disable splitter auto-centering
4855 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4857 // This is necessary to return cursor
4858 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4860 m_canvas
->ReleaseMouse();
4861 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4864 // Set back the default cursor, if necessary
4865 if ( splitterHit
== -1 ||
4868 CustomSetCursor( wxCURSOR_ARROW
);
4873 // Control background needs to be cleared
4874 wxPGProperty
* selected
= GetSelection();
4875 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
4876 DrawItem( selected
);
4880 m_wndEditor
->Show ( true );
4883 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4884 // Fixes button disappearance bug
4886 m_wndEditor2
->Show ( true );
4889 // This clears the focus.
4890 m_editorFocused
= 0;
4896 // -----------------------------------------------------------------------
4898 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4900 int splitterX
= GetSplitterPosition();
4903 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4907 wxWindow
* wnd
= GetEditorControl();
4909 // Hide popup on clicks
4910 if ( event
.GetEventType() != wxEVT_MOTION
)
4911 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4913 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4919 if ( wnd
== NULL
|| m_dragStatus
||
4921 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4922 ux
>= (r
.x
+r
.width
) ||
4924 event
.m_y
>= (r
.y
+r
.height
)
4934 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4939 // -----------------------------------------------------------------------
4941 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4944 if ( OnMouseCommon( event
, &x
, &y
) )
4946 HandleMouseClick(x
,y
,event
);
4951 // -----------------------------------------------------------------------
4953 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4956 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4957 HandleMouseRightClick(x
,y
,event
);
4961 // -----------------------------------------------------------------------
4963 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4965 // Always run standard mouse-down handler as well
4966 OnMouseClick(event
);
4969 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4970 HandleMouseDoubleClick(x
,y
,event
);
4974 // -----------------------------------------------------------------------
4976 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4979 if ( OnMouseCommon( event
, &x
, &y
) )
4981 HandleMouseMove(x
,y
,event
);
4986 // -----------------------------------------------------------------------
4988 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4990 // Called when mouse moves in the empty space below the properties.
4991 CustomSetCursor( wxCURSOR_ARROW
);
4994 // -----------------------------------------------------------------------
4996 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4999 if ( OnMouseCommon( event
, &x
, &y
) )
5001 HandleMouseUp(x
,y
,event
);
5006 // -----------------------------------------------------------------------
5008 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5010 // This may get called from child control as well, so event's
5011 // mouse position cannot be relied on.
5013 if ( event
.Entering() )
5015 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5017 // TODO: Fix this (detect parent and only do
5018 // cursor trick if it is a manager).
5019 wxASSERT( GetParent() );
5020 GetParent()->SetCursor(wxNullCursor
);
5022 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5025 GetParent()->SetCursor(wxNullCursor
);
5027 else if ( event
.Leaving() )
5029 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5030 m_canvas
->SetCursor( wxNullCursor
);
5032 // Get real cursor position
5033 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5035 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5038 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5040 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5044 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5052 // -----------------------------------------------------------------------
5054 // Common code used by various OnMouseXXXChild methods.
5055 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5057 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5058 wxASSERT( topCtrlWnd
);
5060 event
.GetPosition(&x
,&y
);
5062 int splitterX
= GetSplitterPosition();
5064 wxRect r
= topCtrlWnd
->GetRect();
5065 if ( !m_dragStatus
&&
5066 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5067 y
>= 0 && y
< r
.height \
5070 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5075 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5082 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5085 if ( OnMouseChildCommon(event
,&x
,&y
) )
5087 bool res
= HandleMouseClick(x
,y
,event
);
5088 if ( !res
) event
.Skip();
5092 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5095 wxASSERT( m_wndEditor
);
5096 // These coords may not be exact (about +-2),
5097 // but that should not matter (right click is about item, not position).
5098 wxPoint pt
= m_wndEditor
->GetPosition();
5099 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5101 // FIXME: Used to set m_propHover to selection here. Was it really
5104 bool res
= HandleMouseRightClick(x
,y
,event
);
5105 if ( !res
) event
.Skip();
5108 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5111 if ( OnMouseChildCommon(event
,&x
,&y
) )
5113 bool res
= HandleMouseMove(x
,y
,event
);
5114 if ( !res
) event
.Skip();
5118 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5121 if ( OnMouseChildCommon(event
,&x
,&y
) )
5123 bool res
= HandleMouseUp(x
,y
,event
);
5124 if ( !res
) event
.Skip();
5128 // -----------------------------------------------------------------------
5129 // wxPropertyGrid keyboard event handling
5130 // -----------------------------------------------------------------------
5132 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5134 // Translates wxKeyEvent to wxPG_ACTION_XXX
5136 int keycode
= event
.GetKeyCode();
5137 int modifiers
= event
.GetModifiers();
5139 wxASSERT( !(modifiers
&~(0xFFFF)) );
5141 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5143 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5145 if ( it
== m_actionTriggers
.end() )
5150 int second
= (it
->second
>>16) & 0xFFFF;
5154 return (it
->second
& 0xFFFF);
5157 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5159 wxASSERT( !(modifiers
&~(0xFFFF)) );
5161 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5163 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5165 if ( it
!= m_actionTriggers
.end() )
5167 // This key combination is already used
5169 // Can add secondary?
5170 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5171 wxT("You can only add up to two separate actions per key combination.") );
5173 action
= it
->second
| (action
<<16);
5176 m_actionTriggers
[hashMapKey
] = action
;
5179 void wxPropertyGrid::ClearActionTriggers( int action
)
5181 wxPGHashMapI2I::iterator it
;
5183 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
5185 if ( it
->second
== action
)
5187 m_actionTriggers
.erase(it
);
5192 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5195 // Handles key event when editor control is not focused.
5198 wxCHECK2(!m_frozen
, return);
5200 // Travelsal between items, collapsing/expanding, etc.
5201 wxPGProperty
* selected
= GetSelection();
5202 int keycode
= event
.GetKeyCode();
5203 bool editorFocused
= IsEditorFocused();
5205 if ( keycode
== WXK_TAB
)
5207 wxWindow
* mainControl
;
5209 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5210 mainControl
= GetParent();
5214 if ( !event
.ShiftDown() )
5216 if ( !editorFocused
&& m_wndEditor
)
5218 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5222 // Tab traversal workaround for platforms on which
5223 // wxWindow::Navigate() may navigate into first child
5224 // instead of next sibling. Does not work perfectly
5225 // in every scenario (for instance, when property grid
5226 // is either first or last control).
5227 #if defined(__WXGTK__)
5228 wxWindow
* sibling
= mainControl
->GetNextSibling();
5230 sibling
->SetFocusFromKbd();
5232 Navigate(wxNavigationKeyEvent::IsForward
);
5238 if ( editorFocused
)
5244 #if defined(__WXGTK__)
5245 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5247 sibling
->SetFocusFromKbd();
5249 Navigate(wxNavigationKeyEvent::IsBackward
);
5257 // Ignore Alt and Control when they are down alone
5258 if ( keycode
== WXK_ALT
||
5259 keycode
== WXK_CONTROL
)
5266 int action
= KeyEventToActions(event
, &secondAction
);
5268 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5271 // Esc cancels any changes
5272 if ( IsEditorsValueModified() )
5274 EditorsValueWasNotModified();
5276 // Update the control as well
5277 selected
->GetEditorClass()->
5278 SetControlStringValue( selected
,
5280 selected
->GetDisplayedString() );
5283 OnValidationFailureReset(selected
);
5289 // Except for TAB and ESC, handle child control events in child control
5292 // Only propagate event if it had modifiers
5293 if ( !event
.HasModifiers() )
5295 event
.StopPropagation();
5301 bool wasHandled
= false;
5306 if ( ButtonTriggerKeyTest(action
, event
) )
5309 wxPGProperty
* p
= selected
;
5311 // Travel and expand/collapse
5314 if ( p
->GetChildCount() )
5316 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5318 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5321 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5323 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5330 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5334 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5340 if ( selectDir
>= -1 )
5342 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5344 DoSelectProperty(p
);
5350 // If nothing was selected, select the first item now
5351 // (or navigate out of tab).
5352 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5354 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5355 if ( p
) DoSelectProperty(p
);
5364 // -----------------------------------------------------------------------
5366 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5368 // If there was editor open and focused, then this event should not
5369 // really be processed here.
5370 if ( IsEditorFocused() )
5372 // However, if event had modifiers, it is probably still best
5374 if ( event
.HasModifiers() )
5377 event
.StopPropagation();
5381 HandleKeyEvent(event
, false);
5384 // -----------------------------------------------------------------------
5386 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5391 action
= KeyEventToActions(event
, &secondAction
);
5394 // Does the keycode trigger button?
5395 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5398 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5399 GetEventHandler()->AddPendingEvent(evt
);
5406 // -----------------------------------------------------------------------
5408 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5410 HandleKeyEvent(event
, true);
5413 // -----------------------------------------------------------------------
5414 // wxPropertyGrid miscellaneous event handling
5415 // -----------------------------------------------------------------------
5417 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5420 // Check if the focus is in this control or one of its children
5421 wxWindow
* newFocused
= wxWindow::FindFocus();
5423 if ( newFocused
!= m_curFocused
)
5424 HandleFocusChange( newFocused
);
5427 // Check if top-level parent has changed
5428 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5430 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5436 bool wxPropertyGrid::IsEditorFocused() const
5438 wxWindow
* focus
= wxWindow::FindFocus();
5440 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5441 focus
== GetEditorControl() )
5447 // Called by focus event handlers. newFocused is the window that becomes focused.
5448 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5450 unsigned int oldFlags
= m_iFlags
;
5452 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5454 wxWindow
* parent
= newFocused
;
5456 // This must be one of nextFocus' parents.
5459 // Use m_eventObject, which is either wxPropertyGrid or
5460 // wxPropertyGridManager, as appropriate.
5461 if ( parent
== m_eventObject
)
5463 m_iFlags
|= wxPG_FL_FOCUSED
;
5466 parent
= parent
->GetParent();
5469 m_curFocused
= newFocused
;
5471 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5472 (oldFlags
& wxPG_FL_FOCUSED
) )
5474 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5476 // Need to store changed value
5477 CommitChangesFromEditor();
5483 // Preliminary code for tab-order respecting
5484 // tab-traversal (but should be moved to
5487 wxWindow* prevFocus = event.GetWindow();
5488 wxWindow* useThis = this;
5489 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5490 useThis = GetParent();
5493 prevFocus->GetParent() == useThis->GetParent() )
5495 wxList& children = useThis->GetParent()->GetChildren();
5497 wxNode* node = children.Find(prevFocus);
5499 if ( node->GetNext() &&
5500 useThis == node->GetNext()->GetData() )
5501 DoSelectProperty(GetFirst());
5502 else if ( node->GetPrevious () &&
5503 useThis == node->GetPrevious()->GetData() )
5504 DoSelectProperty(GetLastProperty());
5511 wxPGProperty
* selected
= GetSelection();
5512 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5513 DrawItem( selected
);
5517 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5519 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5520 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5521 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5522 //else if ( event.GetWindow() )
5524 HandleFocusChange(event
.GetWindow());
5529 // -----------------------------------------------------------------------
5531 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5533 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5537 // -----------------------------------------------------------------------
5539 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5541 m_iFlags
|= wxPG_FL_SCROLLED
;
5546 // -----------------------------------------------------------------------
5548 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5550 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5552 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5556 // -----------------------------------------------------------------------
5557 // Property editor related functions
5558 // -----------------------------------------------------------------------
5560 // noDefCheck = true prevents infinite recursion.
5561 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5562 const wxString
& editorName
,
5565 wxASSERT( editorClass
);
5567 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5568 RegisterDefaultEditors();
5570 wxString name
= editorName
;
5571 if ( name
.length() == 0 )
5572 name
= editorClass
->GetName();
5574 // Existing editor under this name?
5575 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5577 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5579 // If this name was already used, try class name.
5580 name
= editorClass
->GetClassInfo()->GetClassName();
5581 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5584 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5585 (wxPGEditor
*) vt_it
->second
,
5586 "Editor with given name was already registered" );
5588 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5593 // Use this in RegisterDefaultEditors.
5594 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5595 if ( wxPGEditor_##EDITOR == NULL ) \
5597 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5598 new wxPG##EDITOR##Editor, true ); \
5601 // Registers all default editor classes
5602 void wxPropertyGrid::RegisterDefaultEditors()
5604 wxPGRegisterDefaultEditorClass( TextCtrl
);
5605 wxPGRegisterDefaultEditorClass( Choice
);
5606 wxPGRegisterDefaultEditorClass( ComboBox
);
5607 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5608 #if wxPG_INCLUDE_CHECKBOX
5609 wxPGRegisterDefaultEditorClass( CheckBox
);
5611 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5613 // Register SpinCtrl etc. editors before use
5614 RegisterAdditionalEditors();
5617 // -----------------------------------------------------------------------
5618 // wxPGStringTokenizer
5619 // Needed to handle C-style string lists (e.g. "str1" "str2")
5620 // -----------------------------------------------------------------------
5622 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5623 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5627 wxPGStringTokenizer::~wxPGStringTokenizer()
5631 bool wxPGStringTokenizer::HasMoreTokens()
5633 const wxString
& str
= *m_str
;
5635 wxString::const_iterator i
= m_curPos
;
5637 wxUniChar delim
= m_delimeter
;
5639 wxUniChar prev_a
= wxT('\0');
5641 bool inToken
= false;
5643 while ( i
!= str
.end() )
5652 m_readyToken
.clear();
5657 if ( prev_a
!= wxT('\\') )
5661 if ( a
!= wxT('\\') )
5681 m_curPos
= str
.end();
5689 wxString
wxPGStringTokenizer::GetNextToken()
5691 return m_readyToken
;
5694 // -----------------------------------------------------------------------
5696 // -----------------------------------------------------------------------
5698 wxPGChoiceEntry::wxPGChoiceEntry()
5699 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5703 // -----------------------------------------------------------------------
5705 // -----------------------------------------------------------------------
5707 wxPGChoicesData::wxPGChoicesData()
5711 wxPGChoicesData::~wxPGChoicesData()
5716 void wxPGChoicesData::Clear()
5721 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5723 wxASSERT( m_items
.size() == 0 );
5725 m_items
= data
->m_items
;
5728 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5729 const wxPGChoiceEntry
& item
)
5731 wxVector
<wxPGChoiceEntry
>::iterator it
;
5735 index
= (int) m_items
.size();
5739 it
= m_items
.begin() + index
;
5742 m_items
.insert(it
, item
);
5744 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5746 // Need to fix value?
5747 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5748 ownEntry
.SetValue(index
);
5753 // -----------------------------------------------------------------------
5754 // wxPropertyGridEvent
5755 // -----------------------------------------------------------------------
5757 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5760 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5761 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5762 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5763 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5764 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5765 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5766 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5767 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5768 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5769 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
5770 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
5772 // -----------------------------------------------------------------------
5774 void wxPropertyGridEvent::Init()
5776 m_validationInfo
= NULL
;
5779 m_wasVetoed
= false;
5782 // -----------------------------------------------------------------------
5784 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5785 : wxCommandEvent(commandType
,id
)
5791 // -----------------------------------------------------------------------
5793 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5794 : wxCommandEvent(event
)
5796 m_eventType
= event
.GetEventType();
5797 m_eventObject
= event
.m_eventObject
;
5799 m_property
= event
.m_property
;
5800 m_validationInfo
= event
.m_validationInfo
;
5801 m_canVeto
= event
.m_canVeto
;
5802 m_wasVetoed
= event
.m_wasVetoed
;
5805 // -----------------------------------------------------------------------
5807 wxPropertyGridEvent::~wxPropertyGridEvent()
5811 // -----------------------------------------------------------------------
5813 wxEvent
* wxPropertyGridEvent::Clone() const
5815 return new wxPropertyGridEvent( *this );
5818 // -----------------------------------------------------------------------
5819 // wxPropertyGridPopulator
5820 // -----------------------------------------------------------------------
5822 wxPropertyGridPopulator::wxPropertyGridPopulator()
5826 wxPGGlobalVars
->m_offline
++;
5829 // -----------------------------------------------------------------------
5831 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5834 m_propHierarchy
.clear();
5837 // -----------------------------------------------------------------------
5839 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5845 // -----------------------------------------------------------------------
5847 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5850 // Free unused sets of choices
5851 wxPGHashMapS2P::iterator it
;
5853 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5855 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5862 m_pg
->GetPanel()->Refresh();
5864 wxPGGlobalVars
->m_offline
--;
5867 // -----------------------------------------------------------------------
5869 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5870 const wxString
& propLabel
,
5871 const wxString
& propName
,
5872 const wxString
* propValue
,
5873 wxPGChoices
* pChoices
)
5875 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5876 wxPGProperty
* parent
= GetCurParent();
5878 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5880 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5884 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5886 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5890 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5892 property
->SetLabel(propLabel
);
5893 property
->DoSetName(propName
);
5895 if ( pChoices
&& pChoices
->IsOk() )
5896 property
->SetChoices(*pChoices
);
5898 m_state
->DoInsert(parent
, -1, property
);
5901 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5902 wxPG_PROGRAMMATIC_VALUE
);
5907 // -----------------------------------------------------------------------
5909 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5911 m_propHierarchy
.push_back(property
);
5912 DoScanForChildren();
5913 m_propHierarchy
.pop_back();
5916 // -----------------------------------------------------------------------
5918 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5919 const wxString
& idString
)
5921 wxPGChoices choices
;
5924 if ( choicesString
[0] == wxT('@') )
5926 wxString ids
= choicesString
.substr(1);
5927 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5928 if ( it
== m_dictIdChoices
.end() )
5929 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5931 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5936 if ( idString
.length() )
5938 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5939 if ( it
!= m_dictIdChoices
.end() )
5941 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5948 // Parse choices string
5949 wxString::const_iterator it
= choicesString
.begin();
5953 bool labelValid
= false;
5955 for ( ; it
!= choicesString
.end(); ++it
)
5961 if ( c
== wxT('"') )
5966 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5967 choices
.Add(label
, l
);
5970 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5975 else if ( c
== wxT('=') )
5982 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5989 if ( c
== wxT('"') )
6002 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6003 choices
.Add(label
, l
);
6006 if ( !choices
.IsOk() )
6008 choices
.EnsureData();
6012 if ( idString
.length() )
6013 m_dictIdChoices
[idString
] = choices
.GetData();
6020 // -----------------------------------------------------------------------
6022 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6024 if ( s
.Last() == wxT('%') )
6026 wxString s2
= s
.substr(0,s
.length()-1);
6028 if ( s2
.ToLong(&val
, 10) )
6030 *pval
= (val
*max
)/100;
6036 return s
.ToLong(pval
, 10);
6039 // -----------------------------------------------------------------------
6041 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6042 const wxString
& type
,
6043 const wxString
& value
)
6045 int l
= m_propHierarchy
.size();
6049 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6050 wxString valuel
= value
.Lower();
6053 if ( type
.length() == 0 )
6058 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6060 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6062 else if ( value
.ToLong(&v
, 0) )
6069 if ( type
== wxT("string") )
6073 else if ( type
== wxT("int") )
6076 value
.ToLong(&v
, 0);
6079 else if ( type
== wxT("bool") )
6081 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6088 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6093 p
->SetAttribute( name
, variant
);
6098 // -----------------------------------------------------------------------
6100 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6102 wxLogError(_("Error in resource: %s"),msg
.c_str());
6105 // -----------------------------------------------------------------------
6107 #endif // wxUSE_PROPGRID