1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
67 // Two pics for the expand / collapse buttons.
68 // Files are not supplied with this project (since it is
69 // recommended to use either custom or native rendering).
70 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
71 // and copy xpm files from archive to wxPropertyGrid src directory
72 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
73 // and set wxPG_USE_RENDERER_NATIVE to 0).
74 #ifndef wxPG_ICON_WIDTH
75 #if defined(__WXMAC__)
76 #include "mac_collapse.xpm"
77 #include "mac_expand.xpm"
78 #elif defined(__WXGTK__)
79 #include "linux_collapse.xpm"
80 #include "linux_expand.xpm"
82 #include "default_collapse.xpm"
83 #include "default_expand.xpm"
88 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
89 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
90 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
91 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
92 #define wxPG_YSPACING_MIN 1
93 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
94 // but causes normal combobox to spill out under MSW
96 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
98 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
99 // Must be larger than largest control border
103 #define wxPG_DEFAULT_CURSOR wxNullCursor
106 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
108 //#define wxPG_HIDER_BUTTON_HEIGHT 25
110 #define wxPG_PIXELS_PER_UNIT m_lineHeight
112 #ifdef wxPG_ICON_WIDTH
113 #define m_iconHeight m_iconWidth
116 //#define wxPG_TOOLTIP_DELAY 1000
118 // This is the number of pixels the expander button inside
119 // property cells (i.e. not in the grey margin area are
121 #define IN_CELL_EXPANDER_BUTTON_X_ADJUST 2
123 // -----------------------------------------------------------------------
126 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
128 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
131 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
134 // -----------------------------------------------------------------------
136 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
138 // -----------------------------------------------------------------------
139 // Statics in one class for easy destruction.
140 // -----------------------------------------------------------------------
142 #include "wx/module.h"
144 class wxPGGlobalVarsClassManager
: public wxModule
146 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
148 wxPGGlobalVarsClassManager() {}
149 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
150 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
153 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
156 // When wxPG is loaded dynamically after the application is already running
157 // then the built-in module system won't pick this one up. Add it manually.
158 void wxPGInitResourceModule()
160 wxModule
* module = new wxPGGlobalVarsClassManager
;
162 wxModule::RegisterModule(module);
165 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
168 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
170 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
172 m_boolChoices
.Add(_("False"));
173 m_boolChoices
.Add(_("True"));
175 m_fontFamilyChoices
= NULL
;
177 m_defaultRenderer
= new wxPGDefaultRenderer();
179 m_autoGetTranslation
= false;
187 // Prepare some shared variants
188 m_vEmptyString
= wxString();
190 m_vMinusOne
= (long) -1;
194 // Prepare cached string constants
195 m_strstring
= wxS("string");
196 m_strlong
= wxS("long");
197 m_strbool
= wxS("bool");
198 m_strlist
= wxS("list");
199 m_strDefaultValue
= wxS("DefaultValue");
200 m_strMin
= wxS("Min");
201 m_strMax
= wxS("Max");
202 m_strUnits
= wxS("Units");
203 m_strInlineHelp
= wxS("InlineHelp");
209 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
213 delete m_defaultRenderer
;
215 // This will always have one ref
216 delete m_fontFamilyChoices
;
219 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
220 delete ((wxValidator
*)m_arrValidators
[i
]);
224 // Destroy value type class instances.
225 wxPGHashMapS2P::iterator vt_it
;
227 // Destroy editor class instances.
228 // iterate over all the elements in the class
229 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
231 delete ((wxPGEditor
*)vt_it
->second
);
234 delete wxPGProperty::sm_wxPG_LABEL
;
237 void wxPropertyGridInitGlobalsIfNeeded()
241 // -----------------------------------------------------------------------
243 // -----------------------------------------------------------------------
245 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
247 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
248 EVT_IDLE(wxPropertyGrid::OnIdle
)
249 EVT_PAINT(wxPropertyGrid::OnPaint
)
250 EVT_SIZE(wxPropertyGrid::OnResize
)
251 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
252 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
253 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
254 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
255 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
256 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
257 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
258 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
259 EVT_MOTION(wxPropertyGrid::OnMouseMove
)
260 EVT_LEFT_DOWN(wxPropertyGrid::OnMouseClick
)
261 EVT_LEFT_UP(wxPropertyGrid::OnMouseUp
)
262 EVT_RIGHT_UP(wxPropertyGrid::OnMouseRightClick
)
263 EVT_LEFT_DCLICK(wxPropertyGrid::OnMouseDoubleClick
)
264 EVT_KEY_DOWN(wxPropertyGrid::OnKey
)
267 // -----------------------------------------------------------------------
269 wxPropertyGrid::wxPropertyGrid()
275 // -----------------------------------------------------------------------
277 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
282 const wxString
& name
)
286 Create(parent
,id
,pos
,size
,style
,name
);
289 // -----------------------------------------------------------------------
291 bool wxPropertyGrid::Create( wxWindow
*parent
,
296 const wxString
& name
)
299 if (!(style
&wxBORDER_MASK
))
301 style
|= wxBORDER_THEME
;
306 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
307 style
&= ~(wxTAB_TRAVERSAL
);
308 style
|= wxWANTS_CHARS
;
310 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
317 // -----------------------------------------------------------------------
320 // Initialize values to defaults
322 void wxPropertyGrid::Init1()
324 // Register editor classes, if necessary.
325 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
326 wxPropertyGrid::RegisterDefaultEditors();
330 m_wndEditor
= m_wndEditor2
= NULL
;
334 m_labelEditor
= NULL
;
335 m_labelEditorProperty
= NULL
;
336 m_eventObject
= this;
338 m_processedEvent
= NULL
;
339 m_sortFunction
= NULL
;
340 m_inDoPropertyChanged
= 0;
341 m_inCommitChangesFromEditor
= 0;
342 m_inDoSelectProperty
= 0;
343 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
349 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
350 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
351 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
352 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
353 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
354 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
355 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
356 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
357 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
359 m_coloursCustomized
= 0;
362 #if wxPG_DOUBLE_BUFFER
363 m_doubleBuffer
= NULL
;
366 #ifndef wxPG_ICON_WIDTH
372 m_iconWidth
= wxPG_ICON_WIDTH
;
377 m_gutterWidth
= wxPG_GUTTER_MIN
;
378 m_subgroup_extramargin
= 10;
382 m_width
= m_height
= 0;
384 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
387 m_chgInfo_changedProperty
= NULL
;
390 // -----------------------------------------------------------------------
393 // Initialize after parent etc. set
395 void wxPropertyGrid::Init2()
397 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
400 // Smaller controls on Mac
401 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
404 // Now create state, if one didn't exist already
405 // (wxPropertyGridManager might have created it for us).
408 m_pState
= CreateState();
409 m_pState
->m_pPropGrid
= this;
410 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
413 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
414 m_pState
->m_dontCenterSplitter
= true;
416 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
418 m_pState
->InitNonCatMode();
420 m_pState
->m_properties
= m_pState
->m_abcArray
;
423 GetClientSize(&m_width
,&m_height
);
425 #ifndef wxPG_ICON_WIDTH
426 // create two bitmap nodes for drawing
427 m_expandbmp
= new wxBitmap(expand_xpm
);
428 m_collbmp
= new wxBitmap(collapse_xpm
);
430 // calculate average font height for bitmap centering
432 m_iconWidth
= m_expandbmp
->GetWidth();
433 m_iconHeight
= m_expandbmp
->GetHeight();
436 m_curcursor
= wxCURSOR_ARROW
;
437 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
439 // adjust bitmap icon y position so they are centered
440 m_vspacing
= wxPG_DEFAULT_VSPACING
;
442 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
444 // Allocate cell datas indirectly by calling setter
445 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
446 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
450 // This helps with flicker
451 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
453 // Hook the top-level parent
458 // set virtual size to this window size
459 wxSize wndsize
= GetSize();
460 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
462 m_timeCreated
= ::wxGetLocalTimeMillis();
464 //m_canvas->Create(this, wxID_ANY, wxPoint(0, 0), GetClientSize(),
465 // wxWANTS_CHARS | wxCLIP_CHILDREN);
466 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
468 m_iFlags
|= wxPG_FL_INITIALIZED
;
470 m_ncWidth
= wndsize
.GetWidth();
472 // Need to call OnResize handler or size given in constructor/Create
474 wxSizeEvent
sizeEvent(wndsize
,0);
478 // -----------------------------------------------------------------------
480 wxPropertyGrid::~wxPropertyGrid()
485 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
489 // Remove grid and property pointers from live wxPropertyGridEvents.
490 for ( i
=0; i
<m_liveEvents
.size(); i
++ )
492 wxPropertyGridEvent
* evt
= m_liveEvents
[i
];
493 evt
->SetPropertyGrid(NULL
);
494 evt
->SetProperty(NULL
);
496 m_liveEvents
.clear();
498 if ( m_processedEvent
)
500 // All right... we are being deleted while wxPropertyGrid event
501 // is being sent. Make sure that event propagates as little
502 // as possible (although usually this is not enough to prevent
504 m_processedEvent
->Skip(false);
505 m_processedEvent
->StopPropagation();
507 // Let's use wxMessageBox to make the message appear more
508 // reliably (and *before* the crash can happen).
509 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
510 "generated by it. This usually leads to a crash "
511 "so it is recommended to destroy the control "
512 "at idle time instead.");
515 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
517 // This should do prevent things from going too badly wrong
518 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
520 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
523 // Call with NULL to disconnect event handling
524 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
528 wxASSERT_MSG( !IsEditorsValueModified(),
529 wxS("Most recent change in property editor was ")
530 wxS("lost!!! (if you don't want this to happen, ")
531 wxS("close your frames and dialogs using ")
532 wxS("Close(false).)") );
535 #if wxPG_DOUBLE_BUFFER
536 if ( m_doubleBuffer
)
537 delete m_doubleBuffer
;
540 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
543 delete m_cursorSizeWE
;
545 #ifndef wxPG_ICON_WIDTH
550 // Delete common value records
551 for ( i
=0; i
<m_commonValues
.size(); i
++ )
553 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
554 wxPGCommonValue
* value
= m_commonValues
[i
];
559 // -----------------------------------------------------------------------
561 bool wxPropertyGrid::Destroy()
563 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
566 return wxScrolledWindow::Destroy();
569 // -----------------------------------------------------------------------
571 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
573 return new wxPropertyGridPageState();
576 // -----------------------------------------------------------------------
577 // wxPropertyGrid overridden wxWindow methods
578 // -----------------------------------------------------------------------
580 void wxPropertyGrid::SetWindowStyleFlag( long style
)
582 long old_style
= m_windowStyle
;
584 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
586 wxASSERT( m_pState
);
588 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
591 EnableCategories( true );
593 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
595 // Disable categories
596 EnableCategories( false );
598 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
604 PrepareAfterItemsAdded();
606 m_pState
->m_itemsAdded
= 1;
608 #if wxPG_SUPPORT_TOOLTIPS
609 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
615 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
616 SetToolTip ( tooltip );
617 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
620 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
625 wxScrolledWindow::SetToolTip( NULL
);
630 wxScrolledWindow::SetWindowStyleFlag ( style
);
632 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
634 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
636 CalculateFontAndBitmapStuff( m_vspacing
);
642 // -----------------------------------------------------------------------
644 void wxPropertyGrid::Freeze()
648 wxScrolledWindow::Freeze();
653 // -----------------------------------------------------------------------
655 void wxPropertyGrid::Thaw()
661 wxScrolledWindow::Thaw();
662 RecalculateVirtualSize();
663 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
667 // Force property re-selection
668 // NB: We must copy the selection.
669 wxArrayPGProperty selection
= m_pState
->m_selection
;
670 DoSetSelection(selection
, wxPG_SEL_FORCE
| wxPG_SEL_NONVISIBLE
);
674 // -----------------------------------------------------------------------
676 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
678 wxCHECK( prop
, false );
680 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
681 return DoSelectProperty(prop
, selFlags
);
683 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
685 if ( !selection
.size() )
687 return DoSelectProperty(prop
, selFlags
);
691 // For categories, only one can be selected at a time
692 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
695 selection
.push_back(prop
);
697 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
699 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
708 // -----------------------------------------------------------------------
710 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
712 wxCHECK( prop
, false );
715 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
716 if ( selection
.size() <= 1 )
718 res
= DoSelectProperty(NULL
, selFlags
);
722 m_pState
->DoRemoveFromSelection(prop
);
730 // -----------------------------------------------------------------------
732 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
733 unsigned int colIndex
,
734 unsigned int selFlags
)
737 // NB: Enable following if label editor background colour is
738 // ever changed to any other than m_colSelBack.
740 // We use this workaround to prevent visible flicker when editing
741 // a cell. Atleast on wxMSW, there is a difficult to find
742 // (and perhaps prevent) redraw somewhere between making property
743 // selected and enabling label editing.
745 //wxColour prevColSelBack = m_colSelBack;
746 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
752 res
= DoSelectProperty(prop
, selFlags
);
757 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
759 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
761 res
= DoAddToSelection(prop
, selFlags
);
765 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
767 DoBeginLabelEdit(colIndex
, selFlags
);
771 //m_colSelBack = prevColSelBack;
775 // -----------------------------------------------------------------------
777 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
778 unsigned int colIndex
,
779 wxMouseEvent
* mouseEvent
,
782 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
784 bool addToExistingSelection
;
786 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
790 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
791 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
793 // Allow right-click for context menu without
794 // disturbing the selection.
795 if ( GetSelectedProperties().size() <= 1 ||
797 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
802 addToExistingSelection
= mouseEvent
->ShiftDown();
807 addToExistingSelection
= false;
812 addToExistingSelection
= false;
815 if ( addToExistingSelection
)
817 if ( !alreadySelected
)
819 res
= DoAddToSelection(prop
, selFlags
);
821 else if ( GetSelectedProperties().size() > 1 )
823 res
= DoRemoveFromSelection(prop
, selFlags
);
828 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
834 // -----------------------------------------------------------------------
836 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
839 if ( newSelection
.size() > 0 )
841 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
846 DoClearSelection(false, selFlags
);
849 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
851 DoAddToSelection(newSelection
[i
], selFlags
);
857 // -----------------------------------------------------------------------
859 void wxPropertyGrid::MakeColumnEditable( unsigned int column
,
862 wxASSERT( column
!= 1 );
864 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
868 cols
.push_back(column
);
872 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
874 if ( cols
[i
] == (int)column
)
875 cols
.erase( cols
.begin() + i
);
880 // -----------------------------------------------------------------------
882 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
885 wxPGProperty
* selected
= GetSelection();
886 wxCHECK_RET(selected
, wxT("No property selected"));
887 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
889 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
891 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
898 const wxPGCell
* cell
= NULL
;
899 if ( selected
->HasCell(colIndex
) )
901 cell
= &selected
->GetCell(colIndex
);
902 if ( !cell
->HasText() && colIndex
== 0 )
903 text
= selected
->GetLabel();
909 text
= selected
->GetLabel();
911 cell
= &selected
->GetOrCreateCell(colIndex
);
914 if ( cell
&& cell
->HasText() )
915 text
= cell
->GetText();
917 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
919 m_selColumn
= colIndex
;
921 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
923 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
931 wxWindowID id
= tc
->GetId();
932 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
933 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
935 tc
->Connect(id
, wxEVT_KEY_DOWN
,
936 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
941 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
942 m_labelEditorProperty
= selected
;
945 // -----------------------------------------------------------------------
948 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
950 DoEndLabelEdit(true);
953 // -----------------------------------------------------------------------
955 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
957 int keycode
= event
.GetKeyCode();
959 if ( keycode
== WXK_ESCAPE
)
961 DoEndLabelEdit(false);
969 // -----------------------------------------------------------------------
971 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
973 if ( !m_labelEditor
)
976 wxPGProperty
* prop
= m_labelEditorProperty
;
981 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
983 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
984 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
985 prop
, NULL
, selFlags
,
990 wxString text
= m_labelEditor
->GetValue();
991 wxPGCell
* cell
= NULL
;
992 if ( prop
->HasCell(m_selColumn
) )
994 cell
= &prop
->GetCell(m_selColumn
);
998 if ( m_selColumn
== 0 )
999 prop
->SetLabel(text
);
1001 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1005 cell
->SetText(text
);
1010 DestroyEditorWnd(m_labelEditor
);
1011 m_labelEditor
= NULL
;
1012 m_labelEditorProperty
= NULL
;
1017 // -----------------------------------------------------------------------
1019 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1021 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1022 OnTLPChanging(::wxGetTopLevelParent(this));
1024 OnTLPChanging(NULL
);
1026 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1028 #if defined(__WXMSW__)
1031 // Don't use WS_EX_COMPOSITED just now.
1034 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1035 hWnd = (HWND)GetParent()->GetHWND();
1037 hWnd = (HWND)GetHWND();
1039 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1040 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1043 //#elif defined(__WXGTK20__)
1045 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1046 // truly was double-buffered.
1047 if ( !this->IsDoubleBuffered() )
1049 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1053 #if wxPG_DOUBLE_BUFFER
1054 delete m_doubleBuffer
;
1055 m_doubleBuffer
= NULL
;
1060 wxScrolledWindow::SetExtraStyle( exStyle
);
1062 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1063 m_pState
->InitNonCatMode();
1065 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1066 m_windowStyle
|= wxPG_TOOLTIPS
;
1069 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1072 // -----------------------------------------------------------------------
1074 // returns the best acceptable minimal size
1075 wxSize
wxPropertyGrid::DoGetBestSize() const
1077 int lineHeight
= wxMax(15, m_lineHeight
);
1079 // don't make the grid too tall (limit height to 10 items) but don't
1080 // make it too small neither
1081 int numLines
= wxMin
1083 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1087 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1088 int width
= m_marginWidth
;
1089 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1091 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1094 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1100 // -----------------------------------------------------------------------
1102 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1104 if ( newTLP
== m_tlp
)
1107 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1110 // Parent changed so let's redetermine and re-hook the
1111 // correct top-level window.
1114 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1115 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1117 m_tlpClosed
= m_tlp
;
1118 m_tlpClosedTime
= currentTime
;
1123 // Only accept new tlp if same one was not just dismissed.
1124 if ( newTLP
!= m_tlpClosed
||
1125 m_tlpClosedTime
+250 < currentTime
)
1127 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1128 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1141 // -----------------------------------------------------------------------
1143 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1145 // ClearSelection forces value validation/commit.
1146 if ( event
.CanVeto() && !DoClearSelection() )
1152 // Ok, it can close, set tlp pointer to NULL. Some other event
1153 // handler can of course veto the close, but our OnIdle() should
1154 // then be able to regain the tlp pointer.
1155 OnTLPChanging(NULL
);
1160 // -----------------------------------------------------------------------
1162 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1164 OnTLPChanging((wxWindow
*)newParent
);
1166 bool res
= wxScrolledWindow::Reparent(newParent
);
1171 // -----------------------------------------------------------------------
1172 // wxPropertyGrid Font and Colour Methods
1173 // -----------------------------------------------------------------------
1175 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1179 m_captionFont
= wxScrolledWindow::GetFont();
1181 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1182 m_subgroup_extramargin
= x
+ (x
/2);
1185 #if wxPG_USE_RENDERER_NATIVE
1186 m_iconWidth
= wxPG_ICON_WIDTH
;
1187 #elif wxPG_ICON_WIDTH
1189 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1190 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1191 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1195 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1196 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1197 m_gutterWidth
= wxPG_GUTTER_MIN
;
1200 if ( vspacing
<= 1 ) vdiv
= 12;
1201 else if ( vspacing
>= 3 ) vdiv
= 3;
1203 m_spacingy
= m_fontHeight
/ vdiv
;
1204 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1205 m_spacingy
= wxPG_YSPACING_MIN
;
1208 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1209 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1211 m_captionFont
.SetWeight(wxBOLD
);
1212 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1214 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1217 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1218 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1221 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1223 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1224 RecalculateVirtualSize();
1226 InvalidateBestSize();
1229 // -----------------------------------------------------------------------
1231 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1237 // -----------------------------------------------------------------------
1239 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1240 int ga
= 1000, int ba
= 1000,
1241 bool forceDifferent
= false)
1248 // Recursion guard (allow 2 max)
1249 static int isinside
= 0;
1251 wxCHECK_MSG( isinside
< 3,
1253 wxT("wxPGAdjustColour should not be recursively called more than once") );
1258 int g
= src
.Green();
1261 if ( r2
>255 ) r2
= 255;
1262 else if ( r2
<0) r2
= 0;
1264 if ( g2
>255 ) g2
= 255;
1265 else if ( g2
<0) g2
= 0;
1267 if ( b2
>255 ) b2
= 255;
1268 else if ( b2
<0) b2
= 0;
1270 // Make sure they are somewhat different
1271 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1272 dst
= wxPGAdjustColour(src
,-(ra
*2));
1274 dst
= wxColour(r2
,g2
,b2
);
1276 // Recursion guard (allow 2 max)
1283 static int wxPGGetColAvg( const wxColour
& col
)
1285 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1289 void wxPropertyGrid::RegainColours()
1291 if ( !(m_coloursCustomized
& 0x0002) )
1293 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1295 // Make sure colour is dark enough
1297 int colDec
= wxPGGetColAvg(col
) - 230;
1299 int colDec
= wxPGGetColAvg(col
) - 200;
1302 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1305 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1308 if ( !(m_coloursCustomized
& 0x0001) )
1309 m_colMargin
= m_colCapBack
;
1311 if ( !(m_coloursCustomized
& 0x0004) )
1318 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1319 m_colCapFore
= capForeCol
;
1320 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1323 if ( !(m_coloursCustomized
& 0x0008) )
1325 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1326 m_colPropBack
= bgCol
;
1327 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1330 if ( !(m_coloursCustomized
& 0x0010) )
1332 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1333 m_colPropFore
= fgCol
;
1334 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1337 if ( !(m_coloursCustomized
& 0x0020) )
1338 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1340 if ( !(m_coloursCustomized
& 0x0040) )
1341 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1343 if ( !(m_coloursCustomized
& 0x0080) )
1344 m_colLine
= m_colCapBack
;
1346 if ( !(m_coloursCustomized
& 0x0100) )
1347 m_colDisPropFore
= m_colCapFore
;
1349 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1352 // -----------------------------------------------------------------------
1354 void wxPropertyGrid::ResetColours()
1356 m_coloursCustomized
= 0;
1363 // -----------------------------------------------------------------------
1365 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1367 // Must disable active editor.
1370 bool res
= wxScrolledWindow::SetFont( font
);
1371 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1373 CalculateFontAndBitmapStuff( m_vspacing
);
1380 // -----------------------------------------------------------------------
1382 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1385 m_coloursCustomized
|= 0x80;
1389 // -----------------------------------------------------------------------
1391 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1394 m_coloursCustomized
|= 0x01;
1398 // -----------------------------------------------------------------------
1400 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1402 m_colPropBack
= col
;
1403 m_coloursCustomized
|= 0x08;
1405 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1410 // -----------------------------------------------------------------------
1412 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1414 m_colPropFore
= col
;
1415 m_coloursCustomized
|= 0x10;
1417 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1422 // -----------------------------------------------------------------------
1424 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1426 m_colEmptySpace
= col
;
1431 // -----------------------------------------------------------------------
1433 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1435 m_colDisPropFore
= col
;
1436 m_coloursCustomized
|= 0x100;
1440 // -----------------------------------------------------------------------
1442 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1445 m_coloursCustomized
|= 0x20;
1449 // -----------------------------------------------------------------------
1451 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1454 m_coloursCustomized
|= 0x40;
1458 // -----------------------------------------------------------------------
1460 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1463 m_coloursCustomized
|= 0x02;
1465 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1470 // -----------------------------------------------------------------------
1472 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1475 m_coloursCustomized
|= 0x04;
1477 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1482 // -----------------------------------------------------------------------
1483 // wxPropertyGrid property adding and removal
1484 // -----------------------------------------------------------------------
1486 void wxPropertyGrid::PrepareAfterItemsAdded()
1488 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1490 m_pState
->m_itemsAdded
= 0;
1492 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1493 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1495 RecalculateVirtualSize();
1498 // -----------------------------------------------------------------------
1499 // wxPropertyGrid property operations
1500 // -----------------------------------------------------------------------
1502 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1504 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1508 bool changed
= false;
1510 // Is it inside collapsed section?
1511 if ( !p
->IsVisible() )
1514 wxPGProperty
* parent
= p
->GetParent();
1515 wxPGProperty
* grandparent
= parent
->GetParent();
1517 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1518 Expand( grandparent
);
1526 GetViewStart(&vx
,&vy
);
1527 vy
*=wxPG_PIXELS_PER_UNIT
;
1533 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1534 m_iFlags
|= wxPG_FL_SCROLLED
;
1537 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1539 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1540 m_iFlags
|= wxPG_FL_SCROLLED
;
1550 // -----------------------------------------------------------------------
1551 // wxPropertyGrid helper methods called by properties
1552 // -----------------------------------------------------------------------
1554 // Control font changer helper.
1555 void wxPropertyGrid::SetCurControlBoldFont()
1557 wxASSERT( m_wndEditor
);
1558 m_wndEditor
->SetFont( m_captionFont
);
1561 // -----------------------------------------------------------------------
1563 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1566 #if wxPG_SMALL_SCREEN
1567 // On small-screen devices, always show dialogs with default position and size.
1568 return wxDefaultPosition
;
1570 int splitterX
= GetSplitterPosition();
1574 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1576 ImprovedClientToScreen( &x
, &y
);
1578 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1579 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1586 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1596 new_y
= y
+ m_lineHeight
;
1598 return wxPoint(new_x
,new_y
);
1602 // -----------------------------------------------------------------------
1604 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1606 if ( src_str
.length() == 0 )
1612 bool prev_is_slash
= false;
1614 wxString::const_iterator i
= src_str
.begin();
1618 for ( ; i
!= src_str
.end(); ++i
)
1622 if ( a
!= wxS('\\') )
1624 if ( !prev_is_slash
)
1630 if ( a
== wxS('n') )
1633 dst_str
<< wxS('\n');
1635 dst_str
<< wxS('\n');
1638 else if ( a
== wxS('t') )
1639 dst_str
<< wxS('\t');
1643 prev_is_slash
= false;
1647 if ( prev_is_slash
)
1649 dst_str
<< wxS('\\');
1650 prev_is_slash
= false;
1654 prev_is_slash
= true;
1661 // -----------------------------------------------------------------------
1663 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1665 if ( src_str
.length() == 0 )
1671 wxString::const_iterator i
= src_str
.begin();
1672 wxUniChar prev_a
= wxS('\0');
1676 for ( ; i
!= src_str
.end(); ++i
)
1680 if ( a
>= wxS(' ') )
1682 // This surely is not something that requires an escape sequence.
1687 // This might need...
1688 if ( a
== wxS('\r') )
1690 // DOS style line end.
1691 // Already taken care below
1693 else if ( a
== wxS('\n') )
1694 // UNIX style line end.
1695 dst_str
<< wxS("\\n");
1696 else if ( a
== wxS('\t') )
1698 dst_str
<< wxS('\t');
1701 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1711 // -----------------------------------------------------------------------
1713 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1720 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1723 // -----------------------------------------------------------------------
1724 // wxPropertyGrid graphics related methods
1725 // -----------------------------------------------------------------------
1727 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1732 // Don't paint after destruction has begun
1733 if ( !HasInternalFlag(wxPG_FL_INITIALIZED
) )
1736 // Find out where the window is scrolled to
1737 int vx
,vy
; // Top left corner of client
1738 GetViewStart(&vx
,&vy
);
1739 vy
*= wxPG_PIXELS_PER_UNIT
;
1741 // Update everything inside the box
1742 wxRect r
= GetUpdateRegion().GetBox();
1746 // FIXME: This is just a workaround for a bug that causes splitters not
1747 // to paint when other windows are being dragged over the grid.
1749 r
.width
= GetClientSize().x
;
1751 // Repaint this rectangle
1752 DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
1754 // We assume that the size set when grid is shown
1755 // is what is desired.
1756 SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
1759 // -----------------------------------------------------------------------
1761 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1762 wxPGProperty
* property
) const
1764 // Prepare rectangle to be used
1766 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1767 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1769 #if (wxPG_USE_RENDERER_NATIVE)
1771 #elif wxPG_ICON_WIDTH
1772 // Drawing expand/collapse button manually
1773 dc
.SetPen(m_colPropFore
);
1774 if ( property
->IsCategory() )
1775 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1777 dc
.SetBrush(m_colPropBack
);
1779 dc
.DrawRectangle( r
);
1780 int _y
= r
.y
+(m_iconWidth
/2);
1781 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1786 if ( property
->IsExpanded() )
1788 // wxRenderer functions are non-mutating in nature, so it
1789 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1790 // Hopefully this does not cause problems.
1791 #if (wxPG_USE_RENDERER_NATIVE)
1792 wxRendererNative::Get().DrawTreeItemButton(
1798 #elif wxPG_ICON_WIDTH
1807 #if (wxPG_USE_RENDERER_NATIVE)
1808 wxRendererNative::Get().DrawTreeItemButton(
1814 #elif wxPG_ICON_WIDTH
1815 int _x
= r
.x
+(m_iconWidth
/2);
1816 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1822 #if (wxPG_USE_RENDERER_NATIVE)
1824 #elif wxPG_ICON_WIDTH
1827 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1831 // -----------------------------------------------------------------------
1834 // This is the one called by OnPaint event handler and others.
1835 // topy and bottomy are already unscrolled (ie. physical)
1837 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1838 unsigned int topItemY
,
1839 unsigned int bottomItemY
,
1840 const wxRect
* drawRect
)
1844 bottomItemY
< topItemY
||
1848 m_pState
->EnsureVirtualHeight();
1850 wxRect tempDrawRect
;
1853 tempDrawRect
= wxRect(0, topItemY
,
1856 drawRect
= &tempDrawRect
;
1859 // items added check
1860 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1862 int paintFinishY
= 0;
1864 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1867 bool isBuffered
= false;
1869 #if wxPG_DOUBLE_BUFFER
1870 wxMemoryDC
* bufferDC
= NULL
;
1872 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1874 if ( !m_doubleBuffer
)
1876 paintFinishY
= drawRect
->y
;
1881 bufferDC
= new wxMemoryDC();
1883 // If nothing was changed, then just copy from double-buffer
1884 bufferDC
->SelectObject( *m_doubleBuffer
);
1894 dc
.SetClippingRegion( *drawRect
);
1895 paintFinishY
= DoDrawItems( *dcPtr
, drawRect
, isBuffered
);
1896 int drawBottomY
= drawRect
->y
+ drawRect
->height
;
1898 // Clear area beyond last painted property
1899 if ( paintFinishY
< drawBottomY
)
1901 dcPtr
->SetPen(m_colEmptySpace
);
1902 dcPtr
->SetBrush(m_colEmptySpace
);
1903 dcPtr
->DrawRectangle(0, paintFinishY
,
1908 dc
.DestroyClippingRegion();
1911 #if wxPG_DOUBLE_BUFFER
1914 dc
.Blit( drawRect
->x
, drawRect
->y
, drawRect
->width
,
1916 bufferDC
, 0, 0, wxCOPY
);
1923 // Just clear the area
1924 dc
.SetPen(m_colEmptySpace
);
1925 dc
.SetBrush(m_colEmptySpace
);
1926 dc
.DrawRectangle(*drawRect
);
1930 // -----------------------------------------------------------------------
1932 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1933 const wxRect
* drawRect
,
1934 bool isBuffered
) const
1936 const wxPGProperty
* firstItem
;
1937 const wxPGProperty
* lastItem
;
1939 firstItem
= DoGetItemAtY(drawRect
->y
);
1940 lastItem
= DoGetItemAtY(drawRect
->y
+drawRect
->height
-1);
1943 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1945 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1948 wxCHECK_MSG( !m_pState
->m_itemsAdded
, drawRect
->y
,
1950 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1952 int lh
= m_lineHeight
;
1955 int lastItemBottomY
;
1957 firstItemTopY
= drawRect
->y
;
1958 lastItemBottomY
= drawRect
->y
+ drawRect
->height
;
1960 // Align y coordinates to item boundaries
1961 firstItemTopY
-= firstItemTopY
% lh
;
1962 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1963 lastItemBottomY
-= 1;
1965 // Entire range outside scrolled, visible area?
1966 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() ||
1967 lastItemBottomY
<= 0 )
1970 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
,
1972 "invalid y values" );
1975 wxLogDebug(" -> DoDrawItems ( \"%s\" -> \"%s\"
1976 "height=%i (ch=%i), drawRect = 0x%lX )",
1977 firstItem->GetLabel().c_str(),
1978 lastItem->GetLabel().c_str(),
1979 (int)(lastItemBottomY - firstItemTopY),
1981 (unsigned long)drawRect );
1986 long windowStyle
= m_windowStyle
;
1991 // With wxPG_DOUBLE_BUFFER, do double buffering
1992 // - buffer's y = 0, so align drawRect and coordinates to that
1994 #if wxPG_DOUBLE_BUFFER
2001 xRelMod
= drawRect
->x
;
2002 yRelMod
= drawRect
->y
;
2005 // drawRect conversion
2010 firstItemTopY
-= yRelMod
;
2011 lastItemBottomY
-= yRelMod
;
2014 wxUnusedVar(isBuffered
);
2017 int x
= m_marginWidth
- xRelMod
;
2019 wxFont normalFont
= GetFont();
2021 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2023 bool isPgEnabled
= IsEnabled();
2026 // Prepare some pens and brushes that are often changed to.
2029 wxBrush
marginBrush(m_colMargin
);
2030 wxPen
marginPen(m_colMargin
);
2031 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2032 wxPen
linepen(m_colLine
,1,wxSOLID
);
2034 wxColour selBackCol
;
2036 selBackCol
= m_colSelBack
;
2038 selBackCol
= m_colMargin
;
2040 // pen that has same colour as text
2041 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2044 // Clear margin with background colour
2046 dc
.SetBrush( marginBrush
);
2047 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2049 dc
.SetPen( *wxTRANSPARENT_PEN
);
2050 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2053 const wxPGProperty
* firstSelected
= GetSelection();
2054 const wxPropertyGridPageState
* state
= m_pState
;
2056 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2057 bool wasSelectedPainted
= false;
2060 // TODO: Only render columns that are within clipping region.
2062 dc
.SetFont(normalFont
);
2064 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2065 int endScanBottomY
= lastItemBottomY
+ lh
;
2066 int y
= firstItemTopY
;
2069 // Pregenerate list of visible properties.
2070 wxArrayPGProperty visPropArray
;
2071 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2073 for ( ; !it
.AtEnd(); it
.Next() )
2075 const wxPGProperty
* p
= *it
;
2077 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2079 visPropArray
.push_back((wxPGProperty
*)p
);
2081 if ( y
> endScanBottomY
)
2088 visPropArray
.push_back(NULL
);
2090 wxPGProperty
* nextP
= visPropArray
[0];
2092 int gridWidth
= state
->m_width
;
2095 for ( unsigned int arrInd
=1;
2096 nextP
&& y
<= lastItemBottomY
;
2099 wxPGProperty
* p
= nextP
;
2100 nextP
= visPropArray
[arrInd
];
2102 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2103 int textMarginHere
= x
;
2104 int renderFlags
= 0;
2106 int greyDepth
= m_marginWidth
;
2107 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2108 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2110 int greyDepthX
= greyDepth
- xRelMod
;
2112 // Use basic depth if in non-categoric mode and parent is base array.
2113 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2115 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2118 // Paint margin area
2119 dc
.SetBrush(marginBrush
);
2120 dc
.SetPen(marginPen
);
2121 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2123 dc
.SetPen( linepen
);
2129 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2130 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2131 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2133 // Is this or its parent themed?
2134 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2135 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2136 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2138 bool suppressMarginEdge
= false;
2140 if (!suppressMarginEdge
)
2141 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2144 // Blank out the margin edge
2145 dc
.SetPen(wxPen(GetBackgroundColour()));
2146 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2147 dc
.SetPen( linepen
);
2154 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2156 sx
+= state
->m_colWidths
[si
];
2157 dc
.DrawLine( sx
, y
, sx
, y2
);
2160 // Horizontal Line, below
2161 // (not if both this and next is category caption)
2162 if ( p
->IsCategory() &&
2163 nextP
&& nextP
->IsCategory() )
2164 dc
.SetPen(m_colCapBack
);
2166 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2169 // Need to override row colours?
2173 bool isSelected
= state
->DoIsPropertySelected(p
);
2177 // Disabled may get different colour.
2178 if ( !p
->IsEnabled() )
2180 renderFlags
|= wxPGCellRenderer::Disabled
|
2181 wxPGCellRenderer::DontUseCellFgCol
;
2182 rowFgCol
= m_colDisPropFore
;
2187 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2188 if ( p
== firstSelected
)
2189 wasSelectedPainted
= true;
2192 renderFlags
|= wxPGCellRenderer::Selected
;
2194 if ( !p
->IsCategory() )
2196 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2197 wxPGCellRenderer::DontUseCellBgCol
;
2199 if ( reallyFocused
&& p
== firstSelected
)
2201 rowFgCol
= m_colSelFore
;
2202 rowBgCol
= selBackCol
;
2204 else if ( isPgEnabled
)
2206 rowFgCol
= m_colPropFore
;
2207 if ( p
== firstSelected
)
2208 rowBgCol
= m_colMargin
;
2210 rowBgCol
= selBackCol
;
2214 rowFgCol
= m_colDisPropFore
;
2215 rowBgCol
= selBackCol
;
2222 if ( rowBgCol
.IsOk() )
2223 rowBgBrush
= wxBrush(rowBgCol
);
2225 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2226 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2229 // Fill additional margin area with background colour of first cell
2230 if ( greyDepthX
< textMarginHere
)
2232 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2234 wxPGCell
& cell
= p
->GetCell(0);
2235 rowBgCol
= cell
.GetBgCol();
2236 rowBgBrush
= wxBrush(rowBgCol
);
2238 dc
.SetBrush(rowBgBrush
);
2239 dc
.SetPen(rowBgCol
);
2240 dc
.DrawRectangle(greyDepthX
+1, y
,
2241 textMarginHere
-greyDepthX
, lh
-1);
2244 bool fontChanged
= false;
2246 // Expander button rectangle
2247 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2252 if ( p
->IsCategory() )
2254 // Captions have their cell areas merged as one
2255 dc
.SetFont(m_captionFont
);
2257 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2259 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2261 dc
.SetBrush(rowBgBrush
);
2262 dc
.SetPen(rowBgCol
);
2265 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2267 dc
.SetTextForeground(rowFgCol
);
2270 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2271 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2274 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2275 DrawExpanderButton( dc
, butRect
, p
);
2279 // Fine tune button rectangle to actually fit the cell
2280 if ( butRect
.x
> 0 )
2281 butRect
.x
+= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
2283 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2285 dc
.SetFont(m_captionFont
);
2291 int nextCellWidth
= state
->m_colWidths
[0] -
2292 (greyDepthX
- m_marginWidth
);
2293 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2294 int textXAdd
= textMarginHere
- greyDepthX
;
2296 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2298 cellRect
.width
= nextCellWidth
- 1;
2300 wxWindow
* cellEditor
= NULL
;
2301 int cellRenderFlags
= renderFlags
;
2303 // Tree Item Button (must be drawn before clipping is set up)
2304 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2305 DrawExpanderButton( dc
, butRect
, p
);
2308 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2310 if ( p
== firstSelected
)
2312 if ( ci
== 1 && m_wndEditor
)
2313 cellEditor
= m_wndEditor
;
2314 else if ( ci
== m_selColumn
&& m_labelEditor
)
2315 cellEditor
= m_labelEditor
;
2320 wxColour editorBgCol
=
2321 cellEditor
->GetBackgroundColour();
2322 dc
.SetBrush(editorBgCol
);
2323 dc
.SetPen(editorBgCol
);
2324 dc
.SetTextForeground(m_colPropFore
);
2325 dc
.DrawRectangle(cellRect
);
2327 if ( m_dragStatus
!= 0 ||
2328 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2333 dc
.SetBrush(m_colPropBack
);
2334 dc
.SetPen(m_colPropBack
);
2335 dc
.SetTextForeground(m_colDisPropFore
);
2336 if ( p
->IsEnabled() )
2337 dc
.SetTextForeground(rowFgCol
);
2339 dc
.SetTextForeground(m_colDisPropFore
);
2344 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2346 dc
.SetBrush(rowBgBrush
);
2347 dc
.SetPen(rowBgCol
);
2350 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2352 dc
.SetTextForeground(rowFgCol
);
2356 dc
.SetClippingRegion(cellRect
);
2358 cellRect
.x
+= textXAdd
;
2359 cellRect
.width
-= textXAdd
;
2364 wxPGCellRenderer
* renderer
;
2365 int cmnVal
= p
->GetCommonValue();
2366 if ( cmnVal
== -1 || ci
!= 1 )
2368 renderer
= p
->GetCellRenderer(ci
);
2369 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2374 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2375 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2380 cellX
+= state
->m_colWidths
[ci
];
2381 if ( ci
< (state
->m_colWidths
.size()-1) )
2382 nextCellWidth
= state
->m_colWidths
[ci
+1];
2384 dc
.DestroyClippingRegion(); // Is this really necessary?
2390 dc
.SetFont(normalFont
);
2395 // Refresh editor controls (seems not needed on msw)
2396 // NOTE: This code is mandatory for GTK!
2397 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2398 if ( wasSelectedPainted
)
2401 m_wndEditor
->Refresh();
2403 m_wndEditor2
->Refresh();
2410 // -----------------------------------------------------------------------
2412 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2416 if ( m_width
< 10 || m_height
< 10 ||
2417 !m_pState
->m_properties
->GetChildCount() ||
2419 return wxRect(0,0,0,0);
2424 // Return rect which encloses the given property range
2426 int visTop
= p1
->GetY();
2429 visBottom
= p2
->GetY() + m_lineHeight
;
2431 visBottom
= m_height
+ visTop
;
2433 // If seleced property is inside the range, we'll extend the range to include
2435 wxPGProperty
* selected
= GetSelection();
2438 int selectedY
= selected
->GetY();
2439 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2441 wxWindow
* editor
= GetEditorControl();
2444 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2445 if ( visBottom2
> visBottom
)
2446 visBottom
= visBottom2
;
2451 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2454 // -----------------------------------------------------------------------
2456 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2461 if ( m_pState
->m_itemsAdded
)
2462 PrepareAfterItemsAdded();
2464 wxRect r
= GetPropertyRect(p1
, p2
);
2471 // -----------------------------------------------------------------------
2473 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2475 if ( m_pState
->DoIsPropertySelected(p
) )
2477 // NB: We must copy the selection.
2478 wxArrayPGProperty selection
= m_pState
->m_selection
;
2479 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2482 DrawItemAndChildren(p
);
2485 // -----------------------------------------------------------------------
2487 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2492 // Draw item, children, and parent too, if it is not category
2493 wxPGProperty
* parent
= p
->GetParent();
2496 !parent
->IsCategory() &&
2497 parent
->GetParent() )
2500 parent
= parent
->GetParent();
2503 DrawItemAndChildren(p
);
2506 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2508 wxCHECK_RET( p
, wxT("invalid property id") );
2510 // Do not draw if in non-visible page
2511 if ( p
->GetParentState() != m_pState
)
2514 // do not draw a single item if multiple pending
2515 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2518 // Update child control.
2519 wxPGProperty
* selected
= GetSelection();
2520 if ( selected
&& selected
->GetParent() == p
)
2523 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2525 DrawItems(p
, lastDrawn
);
2528 // -----------------------------------------------------------------------
2530 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2531 const wxRect
*rect
)
2533 PrepareAfterItemsAdded();
2535 wxWindow::Refresh(false, rect
);
2537 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2538 // I think this really helps only GTK+1.2
2539 if ( m_wndEditor
) m_wndEditor
->Refresh();
2540 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2544 // -----------------------------------------------------------------------
2545 // wxPropertyGrid global operations
2546 // -----------------------------------------------------------------------
2548 void wxPropertyGrid::Clear()
2550 m_pState
->DoClear();
2556 RecalculateVirtualSize();
2558 // Need to clear some area at the end
2560 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2563 // -----------------------------------------------------------------------
2565 bool wxPropertyGrid::EnableCategories( bool enable
)
2572 // Enable categories
2575 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2580 // Disable categories
2582 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2585 if ( !m_pState
->EnableCategories(enable
) )
2590 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2592 m_pState
->m_itemsAdded
= 1; // force
2593 PrepareAfterItemsAdded();
2597 m_pState
->m_itemsAdded
= 1;
2599 // No need for RecalculateVirtualSize() here - it is already called in
2600 // wxPropertyGridPageState method above.
2607 // -----------------------------------------------------------------------
2609 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2611 wxASSERT( pNewState
);
2612 wxASSERT( pNewState
->GetGrid() );
2614 if ( pNewState
== m_pState
)
2617 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2619 // Call ClearSelection() instead of DoClearSelection()
2620 // so that selection clear events are not sent.
2623 m_pState
->m_selection
= oldSelection
;
2625 bool orig_mode
= m_pState
->IsInNonCatMode();
2626 bool new_state_mode
= pNewState
->IsInNonCatMode();
2628 m_pState
= pNewState
;
2631 int pgWidth
= GetClientSize().x
;
2632 if ( HasVirtualWidth() )
2634 int minWidth
= pgWidth
;
2635 if ( pNewState
->m_width
< minWidth
)
2637 pNewState
->m_width
= minWidth
;
2638 pNewState
->CheckColumnWidths();
2644 // Just in case, fully re-center splitter
2645 //if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2646 // pNewState->m_fSplitterX = -1.0;
2648 pNewState
->OnClientWidthChange(pgWidth
,
2649 pgWidth
- pNewState
->m_width
);
2654 // If necessary, convert state to correct mode.
2655 if ( orig_mode
!= new_state_mode
)
2657 // This should refresh as well.
2658 EnableCategories( orig_mode
?false:true );
2660 else if ( !m_frozen
)
2662 // Refresh, if not frozen.
2663 m_pState
->PrepareAfterItemsAdded();
2665 // Reselect (Use SetSelection() instead of Do-variant so that
2666 // events won't be sent).
2667 SetSelection(m_pState
->m_selection
);
2669 RecalculateVirtualSize(0);
2673 m_pState
->m_itemsAdded
= 1;
2676 // -----------------------------------------------------------------------
2678 // Call to SetSplitterPosition will always disable splitter auto-centering
2679 // if parent window is shown.
2680 void wxPropertyGrid::DoSetSplitterPosition( int newxpos
,
2684 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2687 wxPropertyGridPageState
* state
= m_pState
;
2689 if ( flags
& wxPG_SPLITTER_FROM_EVENT
)
2690 state
->m_dontCenterSplitter
= true;
2692 state
->DoSetSplitterPosition(newxpos
, splitterIndex
, flags
);
2694 if ( flags
& wxPG_SPLITTER_REFRESH
)
2696 if ( GetSelection() )
2697 CorrectEditorWidgetSizeX();
2705 // -----------------------------------------------------------------------
2707 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2709 SetSplitterPosition( m_width
/2 );
2710 if ( enableAutoCentering
&& HasFlag(wxPG_SPLITTER_AUTO_CENTER
) )
2711 m_pState
->m_dontCenterSplitter
= false;
2714 // -----------------------------------------------------------------------
2715 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2716 // -----------------------------------------------------------------------
2718 // Returns nearest paint visible property (such that will be painted unless
2719 // window is scrolled or resized). If given property is paint visible, then
2720 // it itself will be returned
2721 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2723 int vx
,vy1
;// Top left corner of client
2724 GetViewStart(&vx
,&vy1
);
2725 vy1
*= wxPG_PIXELS_PER_UNIT
;
2727 int vy2
= vy1
+ m_height
;
2728 int propY
= p
->GetY2(m_lineHeight
);
2730 if ( (propY
+ m_lineHeight
) < vy1
)
2733 return DoGetItemAtY( vy1
);
2735 else if ( propY
> vy2
)
2738 return DoGetItemAtY( vy2
);
2741 // Itself paint visible
2746 // -----------------------------------------------------------------------
2747 // Methods related to change in value, value modification and sending events
2748 // -----------------------------------------------------------------------
2750 // commits any changes in editor of selected property
2751 // return true if validation did not fail
2752 // flags are same as with DoSelectProperty
2753 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2755 // Committing already?
2756 if ( m_inCommitChangesFromEditor
)
2759 // Don't do this if already processing editor event. It might
2760 // induce recursive dialogs and crap like that.
2761 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2763 if ( m_inDoPropertyChanged
)
2769 wxPGProperty
* selected
= GetSelection();
2772 IsEditorsValueModified() &&
2773 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2776 m_inCommitChangesFromEditor
= 1;
2778 wxVariant
variant(selected
->GetValueRef());
2779 bool valueIsPending
= false;
2781 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2782 // due to another window getting focus
2783 wxWindow
* oldFocus
= m_curFocused
;
2785 bool validationFailure
= false;
2786 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2788 m_chgInfo_changedProperty
= NULL
;
2790 // If truly modified, schedule value as pending.
2791 if ( selected
->GetEditorClass()->
2792 GetValueFromControl( variant
,
2794 GetEditorControl() ) )
2796 if ( DoEditorValidate() &&
2797 PerformValidation(selected
, variant
) )
2799 valueIsPending
= true;
2803 validationFailure
= true;
2808 EditorsValueWasNotModified();
2813 m_inCommitChangesFromEditor
= 0;
2815 if ( validationFailure
&& !forceSuccess
)
2819 oldFocus
->SetFocus();
2820 m_curFocused
= oldFocus
;
2823 res
= OnValidationFailure(selected
, variant
);
2825 // Now prevent further validation failure messages
2828 EditorsValueWasNotModified();
2829 OnValidationFailureReset(selected
);
2832 else if ( valueIsPending
)
2834 DoPropertyChanged( selected
, flags
);
2835 EditorsValueWasNotModified();
2844 // -----------------------------------------------------------------------
2846 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2850 // Runs all validation functionality.
2851 // Returns true if value passes all tests.
2854 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2857 // Variant list a special value that cannot be validated
2859 if ( pendingValue
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2861 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2866 // Adapt list to child values, if necessary
2867 wxVariant listValue
= pendingValue
;
2868 wxVariant
* pPendingValue
= &pendingValue
;
2869 wxVariant
* pList
= NULL
;
2871 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2872 // string value, then we need treat as it was changed instead
2873 // (or, in addition, as is the case with composite string parent).
2874 // This includes creating list variant for child values.
2876 wxPGProperty
* pwc
= p
->GetParent();
2877 wxPGProperty
* changedProperty
= p
;
2878 wxPGProperty
* baseChangedProperty
= changedProperty
;
2879 wxVariant bcpPendingList
;
2881 listValue
= pendingValue
;
2882 listValue
.SetName(p
->GetBaseName());
2885 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2887 wxVariantList tempList
;
2888 wxVariant
lv(tempList
, pwc
->GetBaseName());
2889 lv
.Append(listValue
);
2891 pPendingValue
= &listValue
;
2893 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2895 baseChangedProperty
= pwc
;
2896 bcpPendingList
= lv
;
2899 changedProperty
= pwc
;
2900 pwc
= pwc
->GetParent();
2904 wxPGProperty
* evtChangingProperty
= changedProperty
;
2906 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2908 value
= *pPendingValue
;
2912 // Convert list to child values
2913 pList
= pPendingValue
;
2914 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2917 wxVariant evtChangingValue
= value
;
2919 if ( flags
& SendEvtChanging
)
2921 // FIXME: After proper ValueToString()s added, remove
2922 // this. It is just a temporary fix, as evt_changing
2923 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2924 // (unless it is selected, and textctrl editor is open).
2925 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2927 evtChangingProperty
= baseChangedProperty
;
2928 if ( evtChangingProperty
!= p
)
2930 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2934 evtChangingValue
= pendingValue
;
2938 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2940 if ( changedProperty
== GetSelection() )
2942 wxWindow
* editor
= GetEditorControl();
2943 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2944 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2948 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2953 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2954 m_chgInfo_changedProperty
= changedProperty
;
2955 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2956 m_chgInfo_pendingValue
= value
;
2959 m_chgInfo_valueList
= *pList
;
2961 m_chgInfo_valueList
.MakeNull();
2963 // If changedProperty is not property which value was edited,
2964 // then call wxPGProperty::ValidateValue() for that as well.
2965 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2967 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2971 if ( flags
& SendEvtChanging
)
2973 // SendEvent returns true if event was vetoed
2974 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
2975 &evtChangingValue
) )
2979 if ( flags
& IsStandaloneValidation
)
2981 // If called in 'generic' context, we need to reset
2982 // m_chgInfo_changedProperty and write back translated value.
2983 m_chgInfo_changedProperty
= NULL
;
2984 pendingValue
= value
;
2990 // -----------------------------------------------------------------------
2992 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2994 if ( !msg
.length() )
2998 if ( !wxPGGlobalVars
->m_offline
)
3000 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3003 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
3006 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
3009 pStatusBar
->SetStatusText(msg
);
3017 ::wxMessageBox(msg
, wxT("Property Error"));
3020 // -----------------------------------------------------------------------
3022 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3023 wxVariant
& invalidValue
)
3025 wxWindow
* editor
= GetEditorControl();
3027 // First call property's handler
3028 property
->OnValidationFailure(invalidValue
);
3030 bool res
= DoOnValidationFailure(property
, invalidValue
);
3033 // For non-wxTextCtrl editors, we do need to revert the value
3034 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3035 property
== GetSelection() )
3037 property
->GetEditorClass()->UpdateControl(property
, editor
);
3040 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3045 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3047 int vfb
= m_validationInfo
.m_failureBehavior
;
3049 if ( vfb
& wxPG_VFB_BEEP
)
3052 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3053 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3055 unsigned int colCount
= m_pState
->GetColumnCount();
3057 // We need backup marked property's cells
3058 m_propCellsBackup
= property
->m_cells
;
3060 wxColour vfbFg
= *wxWHITE
;
3061 wxColour vfbBg
= *wxRED
;
3063 property
->EnsureCells(colCount
);
3065 for ( unsigned int i
=0; i
<colCount
; i
++ )
3067 wxPGCell
& cell
= property
->m_cells
[i
];
3068 cell
.SetFgCol(vfbFg
);
3069 cell
.SetBgCol(vfbBg
);
3072 DrawItemAndChildren(property
);
3074 if ( property
== GetSelection() )
3076 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3078 wxWindow
* editor
= GetEditorControl();
3081 editor
->SetForegroundColour(vfbFg
);
3082 editor
->SetBackgroundColour(vfbBg
);
3087 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3089 wxString msg
= m_validationInfo
.m_failureMessage
;
3091 if ( !msg
.length() )
3092 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
3094 DoShowPropertyError(property
, msg
);
3097 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3100 // -----------------------------------------------------------------------
3102 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3104 int vfb
= m_validationInfo
.m_failureBehavior
;
3106 if ( vfb
& wxPG_VFB_MARK_CELL
)
3109 property
->m_cells
= m_propCellsBackup
;
3111 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3113 if ( property
== GetSelection() && GetEditorControl() )
3115 // Calling this will recreate the control, thus resetting its colour
3116 RefreshProperty(property
);
3120 DrawItemAndChildren(property
);
3125 // -----------------------------------------------------------------------
3127 // flags are same as with DoSelectProperty
3128 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3130 if ( m_inDoPropertyChanged
)
3133 wxWindow
* editor
= GetEditorControl();
3134 wxPGProperty
* selected
= GetSelection();
3136 m_pState
->m_anyModified
= 1;
3138 m_inDoPropertyChanged
= 1;
3140 // Maybe need to update control
3141 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3143 // These values were calculated in PerformValidation()
3144 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3145 wxVariant value
= m_chgInfo_pendingValue
;
3147 wxPGProperty
* topPaintedProperty
= changedProperty
;
3149 while ( !topPaintedProperty
->IsCategory() &&
3150 !topPaintedProperty
->IsRoot() )
3152 topPaintedProperty
= topPaintedProperty
->GetParent();
3155 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3157 // Set as Modified (not if dragging just began)
3158 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3160 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3161 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3164 SetCurControlBoldFont();
3170 // Propagate updates to parent(s)
3172 wxPGProperty
* prevPwc
= NULL
;
3174 while ( prevPwc
!= topPaintedProperty
)
3176 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3178 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3181 SetCurControlBoldFont();
3185 pwc
= pwc
->GetParent();
3188 // Draw the actual property
3189 DrawItemAndChildren( topPaintedProperty
);
3192 // If value was set by wxPGProperty::OnEvent, then update the editor
3194 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3200 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3201 if ( m_wndEditor
) m_wndEditor
->Refresh();
3202 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3207 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3209 // If top parent has composite string value, then send to child parents,
3210 // starting from baseChangedProperty.
3211 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3213 pwc
= m_chgInfo_baseChangedProperty
;
3215 while ( pwc
!= changedProperty
)
3217 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3218 pwc
= pwc
->GetParent();
3222 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3224 m_inDoPropertyChanged
= 0;
3229 // -----------------------------------------------------------------------
3231 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3233 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3235 m_chgInfo_changedProperty
= NULL
;
3237 if ( PerformValidation(p
, newValue
) )
3239 DoPropertyChanged(p
);
3244 OnValidationFailure(p
, newValue
);
3250 // -----------------------------------------------------------------------
3252 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3254 wxPGProperty
* prop
= GetSelectedProperty();
3257 return wxNullVariant
;
3259 wxTextCtrl
* tc
= GetEditorTextCtrl();
3260 wxVariant value
= prop
->GetValue();
3262 if ( !tc
|| !IsEditorsValueModified() )
3265 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3268 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3269 return prop
->GetValue();
3274 // -----------------------------------------------------------------------
3276 // Runs wxValidator for the selected property
3277 bool wxPropertyGrid::DoEditorValidate()
3282 // -----------------------------------------------------------------------
3284 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3286 // It is possible that this handler receives event even before
3287 // the control has been properly initialized. Let's skip the
3288 // event handling in that case.
3292 wxPGProperty
* selected
= GetSelection();
3294 // Somehow, event is handled after property has been deselected.
3295 // Possibly, but very rare.
3297 selected
->HasFlag(wxPG_PROP_BEING_DELETED
) ||
3298 // Also don't handle editor event if wxEVT_PG_CHANGED or
3299 // similar is currently doing something (showing a
3300 // message box, for instance).
3304 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3307 wxVariant
pendingValue(selected
->GetValueRef());
3308 wxWindow
* wnd
= GetEditorControl();
3309 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3311 bool wasUnspecified
= selected
->IsValueUnspecified();
3312 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3313 bool valueIsPending
= false;
3315 m_chgInfo_changedProperty
= NULL
;
3317 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3320 // Filter out excess wxTextCtrl modified events
3321 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3323 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3325 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3327 wxString newTcValue
= tc
->GetValue();
3328 if ( m_prevTcValue
== newTcValue
)
3331 m_prevTcValue
= newTcValue
;
3334 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3336 bool validationFailure
= false;
3337 bool buttonWasHandled
= false;
3340 // Try common button handling
3341 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3343 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3347 buttonWasHandled
= true;
3348 // Store as res2, as previously (and still currently alternatively)
3349 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3350 // in wxPGProperty::OnEvent().
3351 adapter
->ShowDialog( this, selected
);
3356 if ( !buttonWasHandled
)
3358 if ( wnd
|| m_wndEditor2
)
3360 // First call editor class' event handler.
3361 const wxPGEditor
* editor
= selected
->GetEditorClass();
3363 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3365 // If changes, validate them
3366 if ( DoEditorValidate() )
3368 if ( editor
->GetValueFromControl( pendingValue
,
3371 valueIsPending
= true;
3375 validationFailure
= true;
3380 // Then the property's custom handler (must be always called, unless
3381 // validation failed).
3382 if ( !validationFailure
)
3383 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3386 // SetValueInEvent(), as called in one of the functions referred above
3387 // overrides editor's value.
3388 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3390 valueIsPending
= true;
3391 pendingValue
= m_changeInEventValue
;
3392 selFlags
|= wxPG_SEL_DIALOGVAL
;
3395 if ( !validationFailure
&& valueIsPending
)
3396 if ( !PerformValidation(selected
, pendingValue
) )
3397 validationFailure
= true;
3399 if ( validationFailure
)
3401 OnValidationFailure(selected
, pendingValue
);
3403 else if ( valueIsPending
)
3405 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3407 DoPropertyChanged(selected
, selFlags
);
3408 EditorsValueWasNotModified();
3410 // Regardless of editor type, unfocus editor on
3411 // text-editing related enter press.
3412 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3419 // No value after all
3421 // Regardless of editor type, unfocus editor on
3422 // text-editing related enter press.
3423 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3428 // Let unhandled button click events go to the parent
3429 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3431 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3432 GetEventHandler()->AddPendingEvent(evt
);
3436 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3439 // -----------------------------------------------------------------------
3440 // wxPropertyGrid editor control helper methods
3441 // -----------------------------------------------------------------------
3443 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3445 int itemy
= p
->GetY2(m_lineHeight
);
3446 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3447 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3448 int imageOffset
= 0;
3450 int vx
, vy
; // Top left corner of client
3451 GetViewStart(&vx
, &vy
);
3452 vy
*= wxPG_PIXELS_PER_UNIT
;
3454 // TODO: If custom image detection changes from current, change this.
3455 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3457 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3458 int iw
= p
->OnMeasureImage().x
;
3460 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3461 imageOffset
= p
->GetImageOffset(iw
);
3466 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3468 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3473 // -----------------------------------------------------------------------
3475 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3477 wxSize sz
= GetImageSize(p
, item
);
3478 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3479 wxPG_CUSTOM_IMAGE_SPACINGY
,
3484 // return size of custom paint image
3485 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3487 // If called with NULL property, then return default image
3488 // size for properties that use image.
3490 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3492 wxSize cis
= p
->OnMeasureImage(item
);
3494 int choiceCount
= p
->m_choices
.GetCount();
3495 int comVals
= p
->GetDisplayedCommonValueCount();
3496 if ( item
>= choiceCount
&& comVals
> 0 )
3498 unsigned int cvi
= item
-choiceCount
;
3499 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3501 else if ( item
>= 0 && choiceCount
== 0 )
3502 return wxSize(0, 0);
3507 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3512 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3519 // -----------------------------------------------------------------------
3521 // takes scrolling into account
3522 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3525 GetViewStart(&vx
,&vy
);
3526 vy
*=wxPG_PIXELS_PER_UNIT
;
3527 vx
*=wxPG_PIXELS_PER_UNIT
;
3530 ClientToScreen( px
, py
);
3533 // -----------------------------------------------------------------------
3535 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3538 GetViewStart(&pt2
.x
,&pt2
.y
);
3539 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3540 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3544 return m_pState
->HitTest(pt2
);
3547 // -----------------------------------------------------------------------
3549 // custom set cursor
3550 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3552 if ( type
== m_curcursor
&& !override
) return;
3554 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3556 if ( type
== wxCURSOR_SIZEWE
)
3557 cursor
= m_cursorSizeWE
;
3559 SetCursor( *cursor
);
3564 // -----------------------------------------------------------------------
3565 // wxPropertyGrid property selection, editor creation
3566 // -----------------------------------------------------------------------
3569 // This class forwards events from property editor controls to wxPropertyGrid.
3570 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3573 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3574 : wxEvtHandler(), m_propGrid(propGrid
)
3578 virtual ~wxPropertyGridEditorEventForwarder()
3583 bool ProcessEvent( wxEvent
& event
)
3588 m_propGrid
->HandleCustomEditorEvent(event
);
3590 return wxEvtHandler::ProcessEvent(event
);
3593 wxPropertyGrid
* m_propGrid
;
3596 // Setups event handling for child control
3597 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3599 wxWindowID id
= argWnd
->GetId();
3601 if ( argWnd
== m_wndEditor
)
3603 argWnd
->Connect(id
, wxEVT_MOTION
,
3604 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3606 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3607 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3609 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3610 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3612 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3613 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3615 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3616 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3618 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3619 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3623 wxPropertyGridEditorEventForwarder
* forwarder
;
3624 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3625 argWnd
->PushEventHandler(forwarder
);
3627 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3628 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3632 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3639 // Do not free editors immediately (for sake of processing events)
3640 wxPendingDelete
.Append(wnd
);
3643 void wxPropertyGrid::FreeEditors()
3646 // Return focus back to canvas from children (this is required at least for
3647 // GTK+, which, unlike Windows, clears focus when control is destroyed
3648 // instead of moving it to closest parent).
3649 wxWindow
* focus
= wxWindow::FindFocus();
3652 wxWindow
* parent
= focus
->GetParent();
3655 if ( parent
== this )
3660 parent
= parent
->GetParent();
3664 // Do not free editors immediately if processing events
3667 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3668 m_wndEditor2
->Hide();
3669 wxPendingDelete
.Append( handler
);
3670 DestroyEditorWnd(m_wndEditor2
);
3671 m_wndEditor2
= NULL
;
3676 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3677 m_wndEditor
->Hide();
3678 wxPendingDelete
.Append( handler
);
3679 DestroyEditorWnd(m_wndEditor
);
3684 // Call with NULL to de-select property
3685 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3690 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3691 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3695 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3699 if ( m_inDoSelectProperty
)
3702 m_inDoSelectProperty
= 1;
3706 m_inDoSelectProperty
= 0;
3710 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3711 wxPGProperty
* prevFirstSel
;
3713 if ( prevSelection
.size() > 0 )
3714 prevFirstSel
= prevSelection
[0];
3716 prevFirstSel
= NULL
;
3718 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3719 prevFirstSel
= NULL
;
3721 // Always send event, as this is indirect call
3722 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
3726 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3728 wxPrintf( "None selected\n" );
3731 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3733 wxPrintf( "P = NULL\n" );
3736 // If we are frozen, then just set the values.
3739 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3740 m_editorFocused
= 0;
3741 m_pState
->DoSetSelection(p
);
3743 // If frozen, always free controls. But don't worry, as Thaw will
3744 // recall SelectProperty to recreate them.
3747 // Prevent any further selection measures in this call
3753 if ( prevFirstSel
== p
&&
3754 prevSelection
.size() <= 1 &&
3755 !(flags
& wxPG_SEL_FORCE
) )
3757 // Only set focus if not deselecting
3760 if ( flags
& wxPG_SEL_FOCUS
)
3764 m_wndEditor
->SetFocus();
3765 m_editorFocused
= 1;
3774 m_inDoSelectProperty
= 0;
3779 // First, deactivate previous
3782 OnValidationFailureReset(prevFirstSel
);
3784 // Must double-check if this is an selected in case of forceswitch
3785 if ( p
!= prevFirstSel
)
3787 if ( !CommitChangesFromEditor(flags
) )
3789 // Validation has failed, so we can't exit the previous editor
3790 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3791 // _("Invalid Value"),wxOK|wxICON_ERROR);
3792 m_inDoSelectProperty
= 0;
3799 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3800 EditorsValueWasNotModified();
3803 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3805 m_pState
->DoSetSelection(p
);
3807 // Redraw unselected
3808 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
3810 DrawItem(prevSelection
[i
]);
3814 // Then, activate the one given.
3817 int propY
= p
->GetY2(m_lineHeight
);
3819 int splitterX
= GetSplitterPosition();
3820 m_editorFocused
= 0;
3821 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3822 if ( p
!= prevFirstSel
)
3823 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3825 wxASSERT( m_wndEditor
== NULL
);
3828 // Only create editor for non-disabled non-caption
3829 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3831 // do this for non-caption items
3835 // Do we need to paint the custom image, if any?
3836 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3837 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3838 !p
->GetEditorClass()->CanContainCustomImage()
3840 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3842 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3843 wxPoint goodPos
= grect
.GetPosition();
3845 const wxPGEditor
* editor
= p
->GetEditorClass();
3846 wxCHECK_MSG(editor
, false,
3847 wxT("NULL editor class not allowed"));
3849 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3851 wxPGWindowList wndList
=
3852 editor
->CreateControls(this,
3857 m_wndEditor
= wndList
.m_primary
;
3858 m_wndEditor2
= wndList
.m_secondary
;
3859 wxWindow
* primaryCtrl
= GetEditorControl();
3862 // Essentially, primaryCtrl == m_wndEditor
3865 // NOTE: It is allowed for m_wndEditor to be NULL - in this
3866 // case value is drawn as normal, and m_wndEditor2 is
3867 // assumed to be a right-aligned button that triggers
3868 // a separate editorCtrl window.
3872 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3873 "CreateControls must use result of "
3874 "wxPropertyGrid::GetPanel() as parent "
3877 // Set validator, if any
3878 #if wxUSE_VALIDATORS
3879 wxValidator
* validator
= p
->GetValidator();
3881 primaryCtrl
->SetValidator(*validator
);
3884 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3885 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3887 // If it has modified status, use bold font
3888 // (must be done before capturing m_ctrlXAdjust)
3889 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) &&
3890 (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3891 SetCurControlBoldFont();
3893 // Store x relative to splitter (we'll need it).
3894 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3896 // Check if background clear is not necessary
3897 wxPoint pos
= m_wndEditor
->GetPosition();
3898 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3900 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3903 m_wndEditor
->SetSizeHints(3, 3);
3905 SetupChildEventHandling(primaryCtrl
);
3907 // Focus and select all (wxTextCtrl, wxComboBox etc)
3908 if ( flags
& wxPG_SEL_FOCUS
)
3910 primaryCtrl
->SetFocus();
3912 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3918 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3919 "CreateControls must use result of "
3920 "wxPropertyGrid::GetPanel() as parent "
3923 // Get proper id for wndSecondary
3924 m_wndSecId
= m_wndEditor2
->GetId();
3925 wxWindowList children
= m_wndEditor2
->GetChildren();
3926 wxWindowList::iterator node
= children
.begin();
3927 if ( node
!= children
.end() )
3928 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3930 m_wndEditor2
->SetSizeHints(3,3);
3932 m_wndEditor2
->Show();
3934 SetupChildEventHandling(m_wndEditor2
);
3936 // If no primary editor, focus to button to allow
3937 // it to interprete ENTER etc.
3938 // NOTE: Due to problems focusing away from it, this
3939 // has been disabled.
3941 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3942 m_wndEditor2->SetFocus();
3946 if ( flags
& wxPG_SEL_FOCUS
)
3947 m_editorFocused
= 1;
3952 // Make sure focus is in grid canvas (important for wxGTK,
3957 EditorsValueWasNotModified();
3959 // If it's inside collapsed section, expand parent, scroll, etc.
3960 // Also, if it was partially visible, scroll it into view.
3961 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3966 m_wndEditor
->Show(true);
3969 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
3974 // Make sure focus is in grid canvas
3978 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3984 // Show help text in status bar.
3985 // (if found and grid not embedded in manager with help box and
3986 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3989 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3991 wxStatusBar
* statusbar
= NULL
;
3992 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3994 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3996 statusbar
= frame
->GetStatusBar();
4001 const wxString
* pHelpString
= (const wxString
*) NULL
;
4005 pHelpString
= &p
->GetHelpString();
4006 if ( pHelpString
->length() )
4008 // Set help box text.
4009 statusbar
->SetStatusText( *pHelpString
);
4010 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4014 if ( (!pHelpString
|| !pHelpString
->length()) &&
4015 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
4017 // Clear help box - but only if it was written
4018 // by us at previous time.
4019 statusbar
->SetStatusText( m_emptyString
);
4020 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4026 m_inDoSelectProperty
= 0;
4028 // call wx event handler (here so that it also occurs on deselection)
4029 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4030 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4035 // -----------------------------------------------------------------------
4037 bool wxPropertyGrid::UnfocusEditor()
4039 wxPGProperty
* selected
= GetSelection();
4041 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4044 if ( !CommitChangesFromEditor(0) )
4053 // -----------------------------------------------------------------------
4055 void wxPropertyGrid::RefreshEditor()
4057 wxPGProperty
* p
= GetSelection();
4061 wxWindow
* wnd
= GetEditorControl();
4065 // Set editor font boldness - must do this before
4066 // calling UpdateControl().
4067 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4069 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4070 wnd
->SetFont(GetCaptionFont());
4072 wnd
->SetFont(GetFont());
4075 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4077 editorClass
->UpdateControl(p
, wnd
);
4079 if ( p
->IsValueUnspecified() )
4080 editorClass
->SetValueToUnspecified(p
, wnd
);
4083 // -----------------------------------------------------------------------
4085 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4087 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4089 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4091 flags
|= wxPG_SEL_FOCUS
;
4093 return DoSelectProperty(p
, flags
);
4096 // -----------------------------------------------------------------------
4097 // wxPropertyGrid expand/collapse state
4098 // -----------------------------------------------------------------------
4100 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4102 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4103 wxPGProperty
* selected
= GetSelection();
4105 // If active editor was inside collapsed section, then disable it
4106 if ( selected
&& selected
->IsSomeParent(p
) )
4111 // Store dont-center-splitter flag 'cause we need to temporarily set it
4112 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4113 m_pState
->m_dontCenterSplitter
= true;
4115 bool res
= m_pState
->DoCollapse(pwc
);
4120 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4122 RecalculateVirtualSize();
4126 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4131 // -----------------------------------------------------------------------
4133 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4135 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4137 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4139 // Store dont-center-splitter flag 'cause we need to temporarily set it
4140 bool prevDontCenterSplitter
= m_pState
->m_dontCenterSplitter
;
4141 m_pState
->m_dontCenterSplitter
= true;
4143 bool res
= m_pState
->DoExpand(pwc
);
4148 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4150 RecalculateVirtualSize();
4154 m_pState
->m_dontCenterSplitter
= prevDontCenterSplitter
;
4159 // -----------------------------------------------------------------------
4161 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4164 return m_pState
->DoHideProperty(p
, hide
, flags
);
4166 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4167 int selRemoveCount
= 0;
4168 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4170 wxPGProperty
* selected
= selection
[i
];
4171 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4173 if ( !DoRemoveFromSelection(p
, flags
) )
4175 selRemoveCount
+= 1;
4179 m_pState
->DoHideProperty(p
, hide
, flags
);
4181 RecalculateVirtualSize();
4188 // -----------------------------------------------------------------------
4189 // wxPropertyGrid size related methods
4190 // -----------------------------------------------------------------------
4192 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4194 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) ||
4200 // If virtual height was changed, then recalculate editor control position(s)
4201 if ( m_pState
->m_vhCalcPending
)
4202 CorrectEditorWidgetPosY();
4204 m_pState
->EnsureVirtualHeight();
4206 wxASSERT_LEVEL_2_MSG(
4207 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4208 "VirtualHeight and ActualVirtualHeight should match"
4211 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4213 int x
= m_pState
->m_width
;
4214 int y
= m_pState
->m_virtualHeight
;
4217 GetClientSize(&width
,&height
);
4219 // Now adjust virtual size.
4220 SetVirtualSize(x
, y
);
4226 // Adjust scrollbars
4227 if ( HasVirtualWidth() )
4229 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4230 xPos
= GetScrollPos( wxHORIZONTAL
);
4233 if ( forceXPos
!= -1 )
4236 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4239 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4240 int yPos
= GetScrollPos( wxVERTICAL
);
4242 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4243 xAmount
, yAmount
, xPos
, yPos
, true );
4245 // Must re-get size now
4246 GetClientSize(&width
,&height
);
4248 if ( !HasVirtualWidth() )
4250 m_pState
->SetVirtualWidth(width
);
4257 m_pState
->CheckColumnWidths();
4259 if ( GetSelection() )
4260 CorrectEditorWidgetSizeX();
4262 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4265 // -----------------------------------------------------------------------
4267 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4269 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4273 GetClientSize(&width
, &height
);
4278 #if wxPG_DOUBLE_BUFFER
4279 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4281 int dblh
= (m_lineHeight
*2);
4282 if ( !m_doubleBuffer
)
4284 // Create double buffer bitmap to draw on, if none
4285 int w
= (width
>250)?width
:250;
4286 int h
= height
+ dblh
;
4288 m_doubleBuffer
= new wxBitmap( w
, h
);
4292 int w
= m_doubleBuffer
->GetWidth();
4293 int h
= m_doubleBuffer
->GetHeight();
4295 // Double buffer must be large enough
4296 if ( w
< width
|| h
< (height
+dblh
) )
4298 if ( w
< width
) w
= width
;
4299 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4300 delete m_doubleBuffer
;
4301 m_doubleBuffer
= new wxBitmap( w
, h
);
4308 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4309 m_ncWidth
= event
.GetSize().x
;
4313 if ( m_pState
->m_itemsAdded
)
4314 PrepareAfterItemsAdded();
4316 // Without this, virtual size (atleast under wxGTK) will be skewed
4317 RecalculateVirtualSize();
4323 // -----------------------------------------------------------------------
4325 void wxPropertyGrid::SetVirtualWidth( int width
)
4329 // Disable virtual width
4330 width
= GetClientSize().x
;
4331 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4335 // Enable virtual width
4336 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4338 m_pState
->SetVirtualWidth( width
);
4341 void wxPropertyGrid::SetFocusOnCanvas()
4343 SetFocusIgnoringChildren();
4344 m_editorFocused
= 0;
4347 // -----------------------------------------------------------------------
4348 // wxPropertyGrid mouse event handling
4349 // -----------------------------------------------------------------------
4351 // selFlags uses same values DoSelectProperty's flags
4352 // Returns true if event was vetoed.
4353 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4355 unsigned int selFlags
,
4356 unsigned int column
)
4358 // selFlags should have wxPG_SEL_NOVALIDATE if event is not
4361 // Send property grid event of specific type and with specific property
4362 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4363 evt
.SetPropertyGrid(this);
4364 evt
.SetEventObject(m_eventObject
);
4366 evt
.SetColumn(column
);
4367 if ( eventType
== wxEVT_PG_CHANGING
)
4370 evt
.SetCanVeto(true);
4371 m_validationInfo
.m_pValue
= pValue
;
4372 evt
.SetupValidationInfo();
4377 evt
.SetPropertyValue(p
->GetValue());
4379 if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4380 evt
.SetCanVeto(true);
4383 m_processedEvent
= &evt
;
4384 m_eventObject
->HandleWindowEvent(evt
);
4385 m_processedEvent
= NULL
;
4387 return evt
.WasVetoed();
4390 // -----------------------------------------------------------------------
4392 // Return false if should be skipped
4393 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4397 // Need to set focus?
4398 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4403 wxPropertyGridPageState
* state
= m_pState
;
4405 int splitterHitOffset
;
4406 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4408 wxPGProperty
* p
= DoGetItemAtY(y
);
4412 int depth
= (int)p
->GetDepth() - 1;
4414 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4416 if ( x
>= marginEnds
)
4420 if ( p
->IsCategory() )
4422 // This is category.
4423 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4425 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4427 // Expand, collapse, activate etc. if click on text or left of splitter.
4430 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4435 if ( !AddToSelectionFromInputEvent( p
,
4440 // On double-click, expand/collapse.
4441 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4443 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4444 else DoExpand( p
, true );
4448 else if ( splitterHit
== -1 )
4451 unsigned int selFlag
= 0;
4452 if ( columnHit
== 1 )
4454 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4455 selFlag
= wxPG_SEL_FOCUS
;
4457 if ( !AddToSelectionFromInputEvent( p
,
4463 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4465 if ( p
->GetChildCount() && !p
->IsCategory() )
4466 // On double-click, expand/collapse.
4467 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4469 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4470 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4471 else DoExpand( p
, true );
4478 // click on splitter
4479 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4481 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4483 // Double-clicking the splitter causes auto-centering
4484 if ( m_pState
->GetColumnCount() <= 2 )
4486 CenterSplitter( true );
4488 SendEvent(wxEVT_PG_COL_DRAGGING
,
4491 wxPG_SEL_NOVALIDATE
,
4492 (unsigned int)m_draggedSplitter
);
4495 else if ( m_dragStatus
== 0 )
4498 // Begin draggin the splitter
4502 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4504 // Allow application to veto dragging
4505 if ( !SendEvent(wxEVT_PG_COL_BEGIN_DRAG
,
4507 (unsigned int)splitterHit
) )
4511 // Changes must be committed here or the
4512 // value won't be drawn correctly
4513 if ( !CommitChangesFromEditor() )
4516 m_wndEditor
->Show ( false );
4519 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4522 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4526 m_draggedSplitter
= splitterHit
;
4527 m_dragOffset
= splitterHitOffset
;
4529 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4530 // Fixes button disappearance bug
4532 m_wndEditor2
->Show ( false );
4535 m_startingSplitterX
= x
- splitterHitOffset
;
4544 if ( p
->GetChildCount() )
4546 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4548 // Fine tune cell button x
4549 if ( !p
->IsCategory() )
4550 nx
-= IN_CELL_EXPANDER_BUTTON_X_ADJUST
;
4552 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4554 int y2
= y
% m_lineHeight
;
4555 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4557 // On click on expander button, expand/collapse
4558 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4559 DoCollapse( p
, true );
4561 DoExpand( p
, true );
4570 // -----------------------------------------------------------------------
4572 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4573 unsigned int WXUNUSED(y
),
4574 wxMouseEvent
& event
)
4578 // Select property here as well
4579 wxPGProperty
* p
= m_propHover
;
4580 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4582 // Send right click event.
4583 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4590 // -----------------------------------------------------------------------
4592 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4593 unsigned int WXUNUSED(y
),
4594 wxMouseEvent
& event
)
4598 // Select property here as well
4599 wxPGProperty
* p
= m_propHover
;
4601 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4603 // Send double-click event.
4604 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4611 // -----------------------------------------------------------------------
4613 #if wxPG_SUPPORT_TOOLTIPS
4615 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4617 if ( tipString
.length() )
4619 wxScrolledWindow::SetToolTip(tipString
);
4623 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4624 wxScrolledWindow::SetToolTip( m_emptyString
);
4626 wxScrolledWindow::SetToolTip( NULL
);
4631 #endif // #if wxPG_SUPPORT_TOOLTIPS
4633 // -----------------------------------------------------------------------
4635 // Return false if should be skipped
4636 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
,
4637 wxMouseEvent
&event
)
4639 // Safety check (needed because mouse capturing may
4640 // otherwise freeze the control)
4641 if ( m_dragStatus
> 0 && !event
.Dragging() )
4643 HandleMouseUp(x
, y
, event
);
4646 wxPropertyGridPageState
* state
= m_pState
;
4648 int splitterHitOffset
;
4649 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4650 int splitterX
= x
- splitterHitOffset
;
4652 m_colHover
= columnHit
;
4654 if ( m_dragStatus
> 0 )
4656 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4657 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4660 int newSplitterX
= x
- m_dragOffset
;
4661 int splitterX
= x
- splitterHitOffset
;
4663 // Splitter redraw required?
4664 if ( newSplitterX
!= splitterX
)
4667 DoSetSplitterPosition(newSplitterX
,
4669 wxPG_SPLITTER_REFRESH
|
4670 wxPG_SPLITTER_FROM_EVENT
);
4672 SendEvent(wxEVT_PG_COL_DRAGGING
,
4675 wxPG_SEL_NOVALIDATE
,
4676 (unsigned int)m_draggedSplitter
);
4687 int ih
= m_lineHeight
;
4690 #if wxPG_SUPPORT_TOOLTIPS
4691 wxPGProperty
* prevHover
= m_propHover
;
4692 unsigned char prevSide
= m_mouseSide
;
4694 int curPropHoverY
= y
- (y
% ih
);
4696 // On which item it hovers
4699 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4702 // Mouse moves on another property
4704 m_propHover
= DoGetItemAtY(y
);
4705 m_propHoverY
= curPropHoverY
;
4708 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4711 #if wxPG_SUPPORT_TOOLTIPS
4712 // Store which side we are on
4714 if ( columnHit
== 1 )
4716 else if ( columnHit
== 0 )
4720 // If tooltips are enabled, show label or value as a tip
4721 // in case it doesn't otherwise show in full length.
4723 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4725 wxToolTip
* tooltip
= GetToolTip();
4727 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4729 if ( m_propHover
&& !m_propHover
->IsCategory() )
4732 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4734 // Show help string as a tooltip
4735 wxString tipString
= m_propHover
->GetHelpString();
4737 SetToolTip(tipString
);
4741 // Show cropped value string as a tooltip
4745 if ( m_mouseSide
== 1 )
4747 tipString
= m_propHover
->m_label
;
4748 space
= splitterX
-m_marginWidth
-3;
4750 else if ( m_mouseSide
== 2 )
4752 tipString
= m_propHover
->GetDisplayedString();
4754 space
= m_width
- splitterX
;
4755 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4756 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+
4757 wxCC_CUSTOM_IMAGE_MARGIN1
+
4758 wxCC_CUSTOM_IMAGE_MARGIN2
;
4764 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4767 SetToolTip( tipString
);
4774 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4775 SetToolTip( m_emptyString
);
4777 wxScrolledWindow::SetToolTip( NULL
);
4788 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4789 SetToolTip( m_emptyString
);
4791 wxScrolledWindow::SetToolTip( NULL
);
4799 if ( splitterHit
== -1 ||
4801 HasFlag(wxPG_STATIC_SPLITTER
) )
4803 // hovering on something else
4804 if ( m_curcursor
!= wxCURSOR_ARROW
)
4805 CustomSetCursor( wxCURSOR_ARROW
);
4809 // Do not allow splitter cursor on caption items.
4810 // (also not if we were dragging and its started
4811 // outside the splitter region)
4813 if ( !m_propHover
->IsCategory() &&
4817 // hovering on splitter
4819 // NB: Condition disabled since MouseLeave event (from the
4820 // editor control) cannot be reliably detected.
4821 //if ( m_curcursor != wxCURSOR_SIZEWE )
4822 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4828 // hovering on something else
4829 if ( m_curcursor
!= wxCURSOR_ARROW
)
4830 CustomSetCursor( wxCURSOR_ARROW
);
4835 // Multi select by dragging
4837 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
4838 event
.LeftIsDown() &&
4842 !state
->DoIsPropertySelected(m_propHover
) )
4844 // Additional requirement is that the hovered property
4845 // is adjacent to edges of selection.
4846 const wxArrayPGProperty
& selection
= GetSelectedProperties();
4848 // Since categories cannot be selected along with 'other'
4849 // properties, exclude them from iterator flags.
4850 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
4852 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
4854 // TODO: This could be optimized by keeping track of
4855 // which properties are at the edges of selection.
4856 wxPGProperty
* selProp
= selection
[i
];
4857 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
4860 DoAddToSelection(m_propHover
);
4869 // -----------------------------------------------------------------------
4871 // Also handles Leaving event
4872 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4873 wxMouseEvent
&WXUNUSED(event
) )
4875 wxPropertyGridPageState
* state
= m_pState
;
4879 int splitterHitOffset
;
4880 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4882 // No event type check - basicly calling this method should
4883 // just stop dragging.
4884 // Left up after dragged?
4885 if ( m_dragStatus
>= 1 )
4888 // End Splitter Dragging
4890 // DO NOT ENABLE FOLLOWING LINE!
4891 // (it is only here as a reminder to not to do it)
4894 SendEvent(wxEVT_PG_COL_END_DRAG
,
4897 wxPG_SEL_NOVALIDATE
,
4898 (unsigned int)m_draggedSplitter
);
4900 // Disable splitter auto-centering
4901 state
->m_dontCenterSplitter
= true;
4903 // This is necessary to return cursor
4904 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4907 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4910 // Set back the default cursor, if necessary
4911 if ( splitterHit
== -1 ||
4914 CustomSetCursor( wxCURSOR_ARROW
);
4919 // Control background needs to be cleared
4920 wxPGProperty
* selected
= GetSelection();
4921 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
4922 DrawItem( selected
);
4926 m_wndEditor
->Show ( true );
4929 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4930 // Fixes button disappearance bug
4932 m_wndEditor2
->Show ( true );
4935 // This clears the focus.
4936 m_editorFocused
= 0;
4942 // -----------------------------------------------------------------------
4944 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4946 int splitterX
= GetSplitterPosition();
4949 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &ux
, &uy
);
4951 wxWindow
* wnd
= GetEditorControl();
4953 // Hide popup on clicks
4954 if ( event
.GetEventType() != wxEVT_MOTION
)
4955 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4957 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4963 if ( wnd
== NULL
|| m_dragStatus
||
4965 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4966 ux
>= (r
.x
+r
.width
) ||
4968 event
.m_y
>= (r
.y
+r
.height
)
4978 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4983 // -----------------------------------------------------------------------
4985 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4988 if ( OnMouseCommon( event
, &x
, &y
) )
4990 HandleMouseClick(x
,y
,event
);
4995 // -----------------------------------------------------------------------
4997 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5000 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5001 HandleMouseRightClick(x
,y
,event
);
5005 // -----------------------------------------------------------------------
5007 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5009 // Always run standard mouse-down handler as well
5010 OnMouseClick(event
);
5013 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5014 HandleMouseDoubleClick(x
,y
,event
);
5018 // -----------------------------------------------------------------------
5020 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5023 if ( OnMouseCommon( event
, &x
, &y
) )
5025 HandleMouseMove(x
,y
,event
);
5030 // -----------------------------------------------------------------------
5032 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5035 if ( OnMouseCommon( event
, &x
, &y
) )
5037 HandleMouseUp(x
,y
,event
);
5042 // -----------------------------------------------------------------------
5044 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5046 // This may get called from child control as well, so event's
5047 // mouse position cannot be relied on.
5049 if ( event
.Entering() )
5051 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5053 // TODO: Fix this (detect parent and only do
5054 // cursor trick if it is a manager).
5055 wxASSERT( GetParent() );
5056 GetParent()->SetCursor(wxNullCursor
);
5058 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5061 GetParent()->SetCursor(wxNullCursor
);
5063 else if ( event
.Leaving() )
5065 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5066 SetCursor( wxNullCursor
);
5068 // Get real cursor position
5069 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5071 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5074 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5076 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5080 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5088 // -----------------------------------------------------------------------
5090 // Common code used by various OnMouseXXXChild methods.
5091 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5093 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5094 wxASSERT( topCtrlWnd
);
5096 event
.GetPosition(&x
,&y
);
5098 int splitterX
= GetSplitterPosition();
5100 wxRect r
= topCtrlWnd
->GetRect();
5101 if ( !m_dragStatus
&&
5102 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5103 y
>= 0 && y
< r
.height \
5106 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5111 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5118 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5121 if ( OnMouseChildCommon(event
,&x
,&y
) )
5123 bool res
= HandleMouseClick(x
,y
,event
);
5124 if ( !res
) event
.Skip();
5128 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5131 wxASSERT( m_wndEditor
);
5132 // These coords may not be exact (about +-2),
5133 // but that should not matter (right click is about item, not position).
5134 wxPoint pt
= m_wndEditor
->GetPosition();
5135 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5137 // FIXME: Used to set m_propHover to selection here. Was it really
5140 bool res
= HandleMouseRightClick(x
,y
,event
);
5141 if ( !res
) event
.Skip();
5144 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5147 if ( OnMouseChildCommon(event
,&x
,&y
) )
5149 bool res
= HandleMouseMove(x
,y
,event
);
5150 if ( !res
) event
.Skip();
5154 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5157 if ( OnMouseChildCommon(event
,&x
,&y
) )
5159 bool res
= HandleMouseUp(x
,y
,event
);
5160 if ( !res
) event
.Skip();
5164 // -----------------------------------------------------------------------
5165 // wxPropertyGrid keyboard event handling
5166 // -----------------------------------------------------------------------
5168 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5170 // Translates wxKeyEvent to wxPG_ACTION_XXX
5172 int keycode
= event
.GetKeyCode();
5173 int modifiers
= event
.GetModifiers();
5175 wxASSERT( !(modifiers
&~(0xFFFF)) );
5177 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5179 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5181 if ( it
== m_actionTriggers
.end() )
5186 int second
= (it
->second
>>16) & 0xFFFF;
5190 return (it
->second
& 0xFFFF);
5193 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5195 wxASSERT( !(modifiers
&~(0xFFFF)) );
5197 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5199 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5201 if ( it
!= m_actionTriggers
.end() )
5203 // This key combination is already used
5205 // Can add secondary?
5206 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5207 wxT("You can only add up to two separate actions per key combination.") );
5209 action
= it
->second
| (action
<<16);
5212 m_actionTriggers
[hashMapKey
] = action
;
5215 void wxPropertyGrid::ClearActionTriggers( int action
)
5217 wxPGHashMapI2I::iterator it
;
5222 didSomething
= false;
5224 for ( it
= m_actionTriggers
.begin();
5225 it
!= m_actionTriggers
.end();
5228 if ( it
->second
== action
)
5230 m_actionTriggers
.erase(it
);
5231 didSomething
= true;
5236 while ( didSomething
);
5239 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5242 // Handles key event when editor control is not focused.
5245 wxCHECK2(!m_frozen
, return);
5247 // Travelsal between items, collapsing/expanding, etc.
5248 wxPGProperty
* selected
= GetSelection();
5249 int keycode
= event
.GetKeyCode();
5250 bool editorFocused
= IsEditorFocused();
5252 if ( keycode
== WXK_TAB
)
5254 wxWindow
* mainControl
;
5256 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5257 mainControl
= GetParent();
5261 if ( !event
.ShiftDown() )
5263 if ( !editorFocused
&& m_wndEditor
)
5265 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5269 // Tab traversal workaround for platforms on which
5270 // wxWindow::Navigate() may navigate into first child
5271 // instead of next sibling. Does not work perfectly
5272 // in every scenario (for instance, when property grid
5273 // is either first or last control).
5274 #if defined(__WXGTK__)
5275 wxWindow
* sibling
= mainControl
->GetNextSibling();
5277 sibling
->SetFocusFromKbd();
5279 Navigate(wxNavigationKeyEvent::IsForward
);
5285 if ( editorFocused
)
5291 #if defined(__WXGTK__)
5292 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5294 sibling
->SetFocusFromKbd();
5296 Navigate(wxNavigationKeyEvent::IsBackward
);
5304 // Ignore Alt and Control when they are down alone
5305 if ( keycode
== WXK_ALT
||
5306 keycode
== WXK_CONTROL
)
5313 int action
= KeyEventToActions(event
, &secondAction
);
5315 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5318 // Esc cancels any changes
5319 if ( IsEditorsValueModified() )
5321 EditorsValueWasNotModified();
5323 // Update the control as well
5324 selected
->GetEditorClass()->
5325 SetControlStringValue( selected
,
5327 selected
->GetDisplayedString() );
5330 OnValidationFailureReset(selected
);
5336 // Except for TAB and ESC, handle child control events in child control
5339 // Only propagate event if it had modifiers
5340 if ( !event
.HasModifiers() )
5342 event
.StopPropagation();
5348 bool wasHandled
= false;
5353 if ( ButtonTriggerKeyTest(action
, event
) )
5356 wxPGProperty
* p
= selected
;
5358 // Travel and expand/collapse
5361 if ( p
->GetChildCount() )
5363 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5365 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5368 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5370 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5377 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5381 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5387 if ( selectDir
>= -1 )
5389 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5391 DoSelectProperty(p
);
5397 // If nothing was selected, select the first item now
5398 // (or navigate out of tab).
5399 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5401 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5402 if ( p
) DoSelectProperty(p
);
5411 // -----------------------------------------------------------------------
5413 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5415 // If there was editor open and focused, then this event should not
5416 // really be processed here.
5417 if ( IsEditorFocused() )
5419 // However, if event had modifiers, it is probably still best
5421 if ( event
.HasModifiers() )
5424 event
.StopPropagation();
5428 HandleKeyEvent(event
, false);
5431 // -----------------------------------------------------------------------
5433 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5438 action
= KeyEventToActions(event
, &secondAction
);
5441 // Does the keycode trigger button?
5442 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5445 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5446 GetEventHandler()->AddPendingEvent(evt
);
5453 // -----------------------------------------------------------------------
5455 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5457 HandleKeyEvent(event
, true);
5460 // -----------------------------------------------------------------------
5461 // wxPropertyGrid miscellaneous event handling
5462 // -----------------------------------------------------------------------
5464 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5467 // Check if the focus is in this control or one of its children
5468 wxWindow
* newFocused
= wxWindow::FindFocus();
5470 if ( newFocused
!= m_curFocused
)
5471 HandleFocusChange( newFocused
);
5474 // Check if top-level parent has changed
5475 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5477 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5483 bool wxPropertyGrid::IsEditorFocused() const
5485 wxWindow
* focus
= wxWindow::FindFocus();
5487 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5488 focus
== GetEditorControl() )
5494 // Called by focus event handlers. newFocused is the window that becomes focused.
5495 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5497 unsigned int oldFlags
= m_iFlags
;
5499 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5501 wxWindow
* parent
= newFocused
;
5503 // This must be one of nextFocus' parents.
5506 // Use m_eventObject, which is either wxPropertyGrid or
5507 // wxPropertyGridManager, as appropriate.
5508 if ( parent
== m_eventObject
)
5510 m_iFlags
|= wxPG_FL_FOCUSED
;
5513 parent
= parent
->GetParent();
5516 m_curFocused
= newFocused
;
5518 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5519 (oldFlags
& wxPG_FL_FOCUSED
) )
5521 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5523 // Need to store changed value
5524 CommitChangesFromEditor();
5530 // Preliminary code for tab-order respecting
5531 // tab-traversal (but should be moved to
5534 wxWindow* prevFocus = event.GetWindow();
5535 wxWindow* useThis = this;
5536 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5537 useThis = GetParent();
5540 prevFocus->GetParent() == useThis->GetParent() )
5542 wxList& children = useThis->GetParent()->GetChildren();
5544 wxNode* node = children.Find(prevFocus);
5546 if ( node->GetNext() &&
5547 useThis == node->GetNext()->GetData() )
5548 DoSelectProperty(GetFirst());
5549 else if ( node->GetPrevious () &&
5550 useThis == node->GetPrevious()->GetData() )
5551 DoSelectProperty(GetLastProperty());
5558 wxPGProperty
* selected
= GetSelection();
5559 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5560 DrawItem( selected
);
5564 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5566 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5567 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5568 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5569 //else if ( event.GetWindow() )
5571 HandleFocusChange(event
.GetWindow());
5576 // -----------------------------------------------------------------------
5578 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5580 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5584 // -----------------------------------------------------------------------
5586 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5588 m_iFlags
|= wxPG_FL_SCROLLED
;
5593 // -----------------------------------------------------------------------
5595 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5597 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5599 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5603 // -----------------------------------------------------------------------
5604 // Property editor related functions
5605 // -----------------------------------------------------------------------
5607 // noDefCheck = true prevents infinite recursion.
5608 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5609 const wxString
& editorName
,
5612 wxASSERT( editorClass
);
5614 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5615 RegisterDefaultEditors();
5617 wxString name
= editorName
;
5618 if ( name
.length() == 0 )
5619 name
= editorClass
->GetName();
5621 // Existing editor under this name?
5622 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5624 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5626 // If this name was already used, try class name.
5627 name
= editorClass
->GetClassInfo()->GetClassName();
5628 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5631 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5632 (wxPGEditor
*) vt_it
->second
,
5633 "Editor with given name was already registered" );
5635 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5640 // Use this in RegisterDefaultEditors.
5641 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5642 if ( wxPGEditor_##EDITOR == NULL ) \
5644 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5645 new wxPG##EDITOR##Editor, true ); \
5648 // Registers all default editor classes
5649 void wxPropertyGrid::RegisterDefaultEditors()
5651 wxPGRegisterDefaultEditorClass( TextCtrl
);
5652 wxPGRegisterDefaultEditorClass( Choice
);
5653 wxPGRegisterDefaultEditorClass( ComboBox
);
5654 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5655 #if wxPG_INCLUDE_CHECKBOX
5656 wxPGRegisterDefaultEditorClass( CheckBox
);
5658 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5660 // Register SpinCtrl etc. editors before use
5661 RegisterAdditionalEditors();
5664 // -----------------------------------------------------------------------
5665 // wxPGStringTokenizer
5666 // Needed to handle C-style string lists (e.g. "str1" "str2")
5667 // -----------------------------------------------------------------------
5669 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5670 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5674 wxPGStringTokenizer::~wxPGStringTokenizer()
5678 bool wxPGStringTokenizer::HasMoreTokens()
5680 const wxString
& str
= *m_str
;
5682 wxString::const_iterator i
= m_curPos
;
5684 wxUniChar delim
= m_delimeter
;
5686 wxUniChar prev_a
= wxT('\0');
5688 bool inToken
= false;
5690 while ( i
!= str
.end() )
5699 m_readyToken
.clear();
5704 if ( prev_a
!= wxT('\\') )
5708 if ( a
!= wxT('\\') )
5728 m_curPos
= str
.end();
5736 wxString
wxPGStringTokenizer::GetNextToken()
5738 return m_readyToken
;
5741 // -----------------------------------------------------------------------
5743 // -----------------------------------------------------------------------
5745 wxPGChoiceEntry::wxPGChoiceEntry()
5746 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5750 // -----------------------------------------------------------------------
5752 // -----------------------------------------------------------------------
5754 wxPGChoicesData::wxPGChoicesData()
5758 wxPGChoicesData::~wxPGChoicesData()
5763 void wxPGChoicesData::Clear()
5768 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5770 wxASSERT( m_items
.size() == 0 );
5772 m_items
= data
->m_items
;
5775 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5776 const wxPGChoiceEntry
& item
)
5778 wxVector
<wxPGChoiceEntry
>::iterator it
;
5782 index
= (int) m_items
.size();
5786 it
= m_items
.begin() + index
;
5789 m_items
.insert(it
, item
);
5791 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5793 // Need to fix value?
5794 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5795 ownEntry
.SetValue(index
);
5800 // -----------------------------------------------------------------------
5801 // wxPropertyGridEvent
5802 // -----------------------------------------------------------------------
5804 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5807 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5808 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5809 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5810 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5811 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5812 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5813 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5814 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5815 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5816 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
5817 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
5818 wxDEFINE_EVENT( wxEVT_PG_COL_BEGIN_DRAG
, wxPropertyGridEvent
);
5819 wxDEFINE_EVENT( wxEVT_PG_COL_DRAGGING
, wxPropertyGridEvent
);
5820 wxDEFINE_EVENT( wxEVT_PG_COL_END_DRAG
, wxPropertyGridEvent
);
5822 // -----------------------------------------------------------------------
5824 void wxPropertyGridEvent::Init()
5826 m_validationInfo
= NULL
;
5829 m_wasVetoed
= false;
5832 // -----------------------------------------------------------------------
5834 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5835 : wxCommandEvent(commandType
,id
)
5841 // -----------------------------------------------------------------------
5843 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5844 : wxCommandEvent(event
)
5846 m_eventType
= event
.GetEventType();
5847 m_eventObject
= event
.m_eventObject
;
5849 OnPropertyGridSet();
5850 m_property
= event
.m_property
;
5851 m_validationInfo
= event
.m_validationInfo
;
5852 m_canVeto
= event
.m_canVeto
;
5853 m_wasVetoed
= event
.m_wasVetoed
;
5856 // -----------------------------------------------------------------------
5858 void wxPropertyGridEvent::OnPropertyGridSet()
5864 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
5866 m_pg
->m_liveEvents
.push_back(this);
5869 // -----------------------------------------------------------------------
5871 wxPropertyGridEvent::~wxPropertyGridEvent()
5876 wxCriticalSectionLocker(wxPGGlobalVars
->m_critSect
);
5879 // Use iterate from the back since it is more likely that the event
5880 // being desroyed is at the end of the array.
5881 wxVector
<wxPropertyGridEvent
*>& liveEvents
= m_pg
->m_liveEvents
;
5883 for ( int i
= liveEvents
.size()-1; i
>= 0; i
-- )
5885 if ( liveEvents
[i
] == this )
5887 liveEvents
.erase(liveEvents
.begin() + i
);
5894 // -----------------------------------------------------------------------
5896 wxEvent
* wxPropertyGridEvent::Clone() const
5898 return new wxPropertyGridEvent( *this );
5901 // -----------------------------------------------------------------------
5902 // wxPropertyGridPopulator
5903 // -----------------------------------------------------------------------
5905 wxPropertyGridPopulator::wxPropertyGridPopulator()
5909 wxPGGlobalVars
->m_offline
++;
5912 // -----------------------------------------------------------------------
5914 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5917 m_propHierarchy
.clear();
5920 // -----------------------------------------------------------------------
5922 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5928 // -----------------------------------------------------------------------
5930 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5933 // Free unused sets of choices
5934 wxPGHashMapS2P::iterator it
;
5936 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5938 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5945 m_pg
->GetPanel()->Refresh();
5947 wxPGGlobalVars
->m_offline
--;
5950 // -----------------------------------------------------------------------
5952 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5953 const wxString
& propLabel
,
5954 const wxString
& propName
,
5955 const wxString
* propValue
,
5956 wxPGChoices
* pChoices
)
5958 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5959 wxPGProperty
* parent
= GetCurParent();
5961 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5963 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5967 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5969 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5973 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5975 property
->SetLabel(propLabel
);
5976 property
->DoSetName(propName
);
5978 if ( pChoices
&& pChoices
->IsOk() )
5979 property
->SetChoices(*pChoices
);
5981 m_state
->DoInsert(parent
, -1, property
);
5984 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5985 wxPG_PROGRAMMATIC_VALUE
);
5990 // -----------------------------------------------------------------------
5992 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5994 m_propHierarchy
.push_back(property
);
5995 DoScanForChildren();
5996 m_propHierarchy
.pop_back();
5999 // -----------------------------------------------------------------------
6001 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6002 const wxString
& idString
)
6004 wxPGChoices choices
;
6007 if ( choicesString
[0] == wxT('@') )
6009 wxString ids
= choicesString
.substr(1);
6010 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6011 if ( it
== m_dictIdChoices
.end() )
6012 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6014 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6019 if ( idString
.length() )
6021 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6022 if ( it
!= m_dictIdChoices
.end() )
6024 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6031 // Parse choices string
6032 wxString::const_iterator it
= choicesString
.begin();
6036 bool labelValid
= false;
6038 for ( ; it
!= choicesString
.end(); ++it
)
6044 if ( c
== wxT('"') )
6049 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6050 choices
.Add(label
, l
);
6053 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6058 else if ( c
== wxT('=') )
6065 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6072 if ( c
== wxT('"') )
6085 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6086 choices
.Add(label
, l
);
6089 if ( !choices
.IsOk() )
6091 choices
.EnsureData();
6095 if ( idString
.length() )
6096 m_dictIdChoices
[idString
] = choices
.GetData();
6103 // -----------------------------------------------------------------------
6105 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6107 if ( s
.Last() == wxT('%') )
6109 wxString s2
= s
.substr(0,s
.length()-1);
6111 if ( s2
.ToLong(&val
, 10) )
6113 *pval
= (val
*max
)/100;
6119 return s
.ToLong(pval
, 10);
6122 // -----------------------------------------------------------------------
6124 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6125 const wxString
& type
,
6126 const wxString
& value
)
6128 int l
= m_propHierarchy
.size();
6132 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6133 wxString valuel
= value
.Lower();
6136 if ( type
.length() == 0 )
6141 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6143 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6145 else if ( value
.ToLong(&v
, 0) )
6152 if ( type
== wxT("string") )
6156 else if ( type
== wxT("int") )
6159 value
.ToLong(&v
, 0);
6162 else if ( type
== wxT("bool") )
6164 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6171 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6176 p
->SetAttribute( name
, variant
);
6181 // -----------------------------------------------------------------------
6183 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6185 wxLogError(_("Error in resource: %s"),msg
.c_str());
6188 // -----------------------------------------------------------------------
6190 #endif // wxUSE_PROPGRID