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 // -----------------------------------------------------------------------
121 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
123 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
126 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
129 // -----------------------------------------------------------------------
131 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
133 // -----------------------------------------------------------------------
134 // Statics in one class for easy destruction.
135 // -----------------------------------------------------------------------
137 #include "wx/module.h"
139 class wxPGGlobalVarsClassManager
: public wxModule
141 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
143 wxPGGlobalVarsClassManager() {}
144 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
145 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
148 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
151 // When wxPG is loaded dynamically after the application is already running
152 // then the built-in module system won't pick this one up. Add it manually.
153 void wxPGInitResourceModule()
155 wxModule
* module = new wxPGGlobalVarsClassManager
;
157 wxModule::RegisterModule(module);
160 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
163 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
165 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
167 m_boolChoices
.Add(_("False"));
168 m_boolChoices
.Add(_("True"));
170 m_fontFamilyChoices
= NULL
;
172 m_defaultRenderer
= new wxPGDefaultRenderer();
174 m_autoGetTranslation
= false;
182 // Prepare some shared variants
183 m_vEmptyString
= wxString();
185 m_vMinusOne
= (long) -1;
189 // Prepare cached string constants
190 m_strstring
= wxS("string");
191 m_strlong
= wxS("long");
192 m_strbool
= wxS("bool");
193 m_strlist
= wxS("list");
194 m_strDefaultValue
= wxS("DefaultValue");
195 m_strMin
= wxS("Min");
196 m_strMax
= wxS("Max");
197 m_strUnits
= wxS("Units");
198 m_strInlineHelp
= wxS("InlineHelp");
204 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
208 delete m_defaultRenderer
;
210 // This will always have one ref
211 delete m_fontFamilyChoices
;
214 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
215 delete ((wxValidator
*)m_arrValidators
[i
]);
219 // Destroy value type class instances.
220 wxPGHashMapS2P::iterator vt_it
;
222 // Destroy editor class instances.
223 // iterate over all the elements in the class
224 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
226 delete ((wxPGEditor
*)vt_it
->second
);
229 delete wxPGProperty::sm_wxPG_LABEL
;
232 void wxPropertyGridInitGlobalsIfNeeded()
236 // -----------------------------------------------------------------------
238 // -----------------------------------------------------------------------
241 // wxPGCanvas acts as a graphics sub-window of the
242 // wxScrolledWindow that wxPropertyGrid is.
244 class wxPGCanvas
: public wxPanel
247 wxPGCanvas() : wxPanel()
250 virtual ~wxPGCanvas() { }
253 void OnMouseMove( wxMouseEvent
&event
)
255 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
256 pg
->OnMouseMove( event
);
259 void OnMouseClick( wxMouseEvent
&event
)
261 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
262 pg
->OnMouseClick( event
);
265 void OnMouseUp( wxMouseEvent
&event
)
267 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
268 pg
->OnMouseUp( event
);
271 void OnMouseRightClick( wxMouseEvent
&event
)
273 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
274 pg
->OnMouseRightClick( event
);
277 void OnMouseDoubleClick( wxMouseEvent
&event
)
279 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
280 pg
->OnMouseDoubleClick( event
);
283 void OnKey( wxKeyEvent
& event
)
285 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
289 void OnPaint( wxPaintEvent
& event
);
291 // Always be focussable, even with child windows
292 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
293 { wxPanel::SetCanFocus(true); }
297 DECLARE_EVENT_TABLE()
298 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
302 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
304 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
305 EVT_MOTION(wxPGCanvas::OnMouseMove
)
306 EVT_PAINT(wxPGCanvas::OnPaint
)
307 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
308 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
309 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
310 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
311 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
315 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
317 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
318 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
322 // Don't paint after destruction has begun
323 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
326 // Update everything inside the box
327 wxRect r
= GetUpdateRegion().GetBox();
329 // FIXME: This is just a workaround for a bug that causes splitters not
330 // to paint when other windows are being dragged over the grid.
331 wxRect fullRect
= GetRect();
333 r
.width
= fullRect
.width
;
335 // Repaint this rectangle
336 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
338 // We assume that the size set when grid is shown
339 // is what is desired.
340 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
343 // -----------------------------------------------------------------------
345 // -----------------------------------------------------------------------
347 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
349 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
350 EVT_IDLE(wxPropertyGrid::OnIdle
)
351 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
352 EVT_PAINT(wxPropertyGrid::OnPaint
)
353 EVT_SIZE(wxPropertyGrid::OnResize
)
354 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
355 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
356 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
357 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
358 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
359 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
360 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
361 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
365 // -----------------------------------------------------------------------
367 wxPropertyGrid::wxPropertyGrid()
373 // -----------------------------------------------------------------------
375 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
380 const wxString
& name
)
384 Create(parent
,id
,pos
,size
,style
,name
);
387 // -----------------------------------------------------------------------
389 bool wxPropertyGrid::Create( wxWindow
*parent
,
394 const wxString
& name
)
397 if (!(style
&wxBORDER_MASK
))
399 style
|= wxBORDER_THEME
;
404 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
405 style
&= ~(wxTAB_TRAVERSAL
);
406 style
|= wxWANTS_CHARS
;
408 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
415 // -----------------------------------------------------------------------
418 // Initialize values to defaults
420 void wxPropertyGrid::Init1()
422 // Register editor classes, if necessary.
423 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
424 wxPropertyGrid::RegisterDefaultEditors();
428 m_wndEditor
= m_wndEditor2
= NULL
;
432 m_labelEditor
= NULL
;
433 m_labelEditorProperty
= NULL
;
434 m_eventObject
= this;
436 m_processedEvent
= NULL
;
437 m_sortFunction
= NULL
;
438 m_inDoPropertyChanged
= 0;
439 m_inCommitChangesFromEditor
= 0;
440 m_inDoSelectProperty
= 0;
441 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
447 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
448 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
449 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
450 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
451 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
452 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
453 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
454 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
455 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
457 m_coloursCustomized
= 0;
462 #if wxPG_DOUBLE_BUFFER
463 m_doubleBuffer
= NULL
;
466 #ifndef wxPG_ICON_WIDTH
472 m_iconWidth
= wxPG_ICON_WIDTH
;
477 m_gutterWidth
= wxPG_GUTTER_MIN
;
478 m_subgroup_extramargin
= 10;
482 m_width
= m_height
= 0;
484 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
487 m_chgInfo_changedProperty
= NULL
;
490 // -----------------------------------------------------------------------
493 // Initialize after parent etc. set
495 void wxPropertyGrid::Init2()
497 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
500 // Smaller controls on Mac
501 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
504 // Now create state, if one didn't exist already
505 // (wxPropertyGridManager might have created it for us).
508 m_pState
= CreateState();
509 m_pState
->m_pPropGrid
= this;
510 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
513 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
514 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
516 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
518 m_pState
->InitNonCatMode();
520 m_pState
->m_properties
= m_pState
->m_abcArray
;
523 GetClientSize(&m_width
,&m_height
);
525 #ifndef wxPG_ICON_WIDTH
526 // create two bitmap nodes for drawing
527 m_expandbmp
= new wxBitmap(expand_xpm
);
528 m_collbmp
= new wxBitmap(collapse_xpm
);
530 // calculate average font height for bitmap centering
532 m_iconWidth
= m_expandbmp
->GetWidth();
533 m_iconHeight
= m_expandbmp
->GetHeight();
536 m_curcursor
= wxCURSOR_ARROW
;
537 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
539 // adjust bitmap icon y position so they are centered
540 m_vspacing
= wxPG_DEFAULT_VSPACING
;
542 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
544 // Allocate cell datas indirectly by calling setter
545 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
546 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
550 // This helps with flicker
551 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
553 // Hook the top-level parent
558 // set virtual size to this window size
559 wxSize wndsize
= GetSize();
560 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
562 m_timeCreated
= ::wxGetLocalTimeMillis();
564 m_canvas
= new wxPGCanvas();
565 m_canvas
->Create(this, wxID_ANY
, wxPoint(0, 0), GetClientSize(),
566 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
567 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
569 m_iFlags
|= wxPG_FL_INITIALIZED
;
571 m_ncWidth
= wndsize
.GetWidth();
573 // Need to call OnResize handler or size given in constructor/Create
575 wxSizeEvent
sizeEvent(wndsize
,0);
579 // -----------------------------------------------------------------------
581 wxPropertyGrid::~wxPropertyGrid()
585 if ( m_processedEvent
)
587 // All right... we are being deleted while wxPropertyGrid event
588 // is being sent. Make sure that event propagates as little
589 // as possible (although usually this is not enough to prevent
591 m_processedEvent
->Skip(false);
592 m_processedEvent
->StopPropagation();
594 // Let's use wxMessageBox to make the message appear more
595 // reliably (and *before* the crash can happend).
596 ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
597 "generated by it. This usually leads to a crash "
598 "so it is recommended to destroy the control "
599 "at idle time instead.");
602 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
604 // This should do prevent things from going too badly wrong
605 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
607 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
608 m_canvas
->ReleaseMouse();
610 // Call with NULL to disconnect event handling
611 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
615 wxASSERT_MSG( !IsEditorsValueModified(),
616 wxS("Most recent change in property editor was ")
617 wxS("lost!!! (if you don't want this to happen, ")
618 wxS("close your frames and dialogs using ")
619 wxS("Close(false).)") );
622 #if wxPG_DOUBLE_BUFFER
623 if ( m_doubleBuffer
)
624 delete m_doubleBuffer
;
627 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
630 delete m_cursorSizeWE
;
632 #ifndef wxPG_ICON_WIDTH
637 // Delete common value records
638 for ( i
=0; i
<m_commonValues
.size(); i
++ )
640 // Use temporary variable to work around possible strange VC6 (asserts because m_size is zero)
641 wxPGCommonValue
* value
= m_commonValues
[i
];
646 // -----------------------------------------------------------------------
648 bool wxPropertyGrid::Destroy()
650 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
651 m_canvas
->ReleaseMouse();
653 return wxScrolledWindow::Destroy();
656 // -----------------------------------------------------------------------
658 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
660 return new wxPropertyGridPageState();
663 // -----------------------------------------------------------------------
664 // wxPropertyGrid overridden wxWindow methods
665 // -----------------------------------------------------------------------
667 void wxPropertyGrid::SetWindowStyleFlag( long style
)
669 long old_style
= m_windowStyle
;
671 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
673 wxASSERT( m_pState
);
675 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
678 EnableCategories( true );
680 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
682 // Disable categories
683 EnableCategories( false );
685 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
691 PrepareAfterItemsAdded();
693 m_pState
->m_itemsAdded
= 1;
695 #if wxPG_SUPPORT_TOOLTIPS
696 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
702 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
703 SetToolTip ( tooltip );
704 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
707 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
712 m_canvas
->SetToolTip( NULL
);
717 wxScrolledWindow::SetWindowStyleFlag ( style
);
719 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
721 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
723 CalculateFontAndBitmapStuff( m_vspacing
);
729 // -----------------------------------------------------------------------
731 void wxPropertyGrid::Freeze()
735 wxScrolledWindow::Freeze();
740 // -----------------------------------------------------------------------
742 void wxPropertyGrid::Thaw()
748 wxScrolledWindow::Thaw();
749 RecalculateVirtualSize();
750 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
754 // Force property re-selection
755 // NB: We must copy the selection.
756 wxArrayPGProperty selection
= m_pState
->m_selection
;
757 DoSetSelection(selection
, wxPG_SEL_FORCE
);
761 // -----------------------------------------------------------------------
763 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
765 wxCHECK( prop
, false );
767 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
768 return DoSelectProperty(prop
, selFlags
);
770 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
772 if ( !selection
.size() )
774 return DoSelectProperty(prop
, selFlags
);
778 // For categories, only one can be selected at a time
779 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
782 selection
.push_back(prop
);
784 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
786 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
);
795 // -----------------------------------------------------------------------
797 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
799 wxCHECK( prop
, false );
802 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
803 if ( selection
.size() <= 1 )
805 res
= DoSelectProperty(NULL
, selFlags
);
809 m_pState
->DoRemoveFromSelection(prop
);
817 // -----------------------------------------------------------------------
819 bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty
* prop
,
820 unsigned int colIndex
,
821 unsigned int selFlags
)
824 // NB: Enable following if label editor background colour is
825 // ever changed to any other than m_colSelBack.
827 // We use this workaround to prevent visible flicker when editing
828 // a cell. Atleast on wxMSW, there is a difficult to find
829 // (and perhaps prevent) redraw somewhere between making property
830 // selected and enabling label editing.
832 //wxColour prevColSelBack = m_colSelBack;
833 //m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
839 res
= DoSelectProperty(prop
, selFlags
);
844 DoClearSelection(false, wxPG_SEL_NO_REFRESH
);
846 if ( m_pState
->m_editableColumns
.Index(colIndex
) == wxNOT_FOUND
)
848 res
= DoAddToSelection(prop
, selFlags
);
852 res
= DoAddToSelection(prop
, selFlags
|wxPG_SEL_NO_REFRESH
);
854 DoBeginLabelEdit(colIndex
, selFlags
);
858 //m_colSelBack = prevColSelBack;
862 // -----------------------------------------------------------------------
864 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
865 unsigned int colIndex
,
866 wxMouseEvent
* mouseEvent
,
869 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
871 bool addToExistingSelection
;
873 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
877 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
878 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
880 // Allow right-click for context menu without
881 // disturbing the selection.
882 if ( GetSelectedProperties().size() <= 1 ||
884 return DoSelectAndEdit(prop
, colIndex
, selFlags
);
889 addToExistingSelection
= mouseEvent
->ShiftDown();
894 addToExistingSelection
= false;
899 addToExistingSelection
= false;
902 if ( addToExistingSelection
)
904 if ( !alreadySelected
)
906 res
= DoAddToSelection(prop
, selFlags
);
908 else if ( GetSelectedProperties().size() > 1 )
910 res
= DoRemoveFromSelection(prop
, selFlags
);
915 res
= DoSelectAndEdit(prop
, colIndex
, selFlags
);
921 // -----------------------------------------------------------------------
923 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
926 if ( newSelection
.size() > 0 )
928 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
933 DoClearSelection(false, selFlags
);
936 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
938 DoAddToSelection(newSelection
[i
], selFlags
);
944 // -----------------------------------------------------------------------
946 void wxPropertyGrid::MakeColumnEditable( unsigned int column
,
949 wxASSERT( column
!= 1 );
951 wxArrayInt
& cols
= m_pState
->m_editableColumns
;
955 cols
.push_back(column
);
959 for ( int i
= cols
.size() - 1; i
> 0; i
-- )
961 if ( cols
[i
] == (int)column
)
962 cols
.erase( cols
.begin() + i
);
967 // -----------------------------------------------------------------------
969 void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex
,
972 wxPGProperty
* selected
= GetSelection();
973 wxCHECK_RET(selected
, wxT("No property selected"));
974 wxCHECK_RET(colIndex
!= 1, wxT("Do not use this for column 1"));
976 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
978 if ( SendEvent( wxEVT_PG_LABEL_EDIT_BEGIN
,
985 const wxPGCell
* cell
= NULL
;
986 if ( selected
->HasCell(colIndex
) )
988 cell
= &selected
->GetCell(colIndex
);
989 if ( !cell
->HasText() && colIndex
== 0 )
990 text
= selected
->GetLabel();
996 text
= selected
->GetLabel();
998 cell
= &selected
->GetOrCreateCell(colIndex
);
1001 if ( cell
&& cell
->HasText() )
1002 text
= cell
->GetText();
1004 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
); // send event
1006 m_selColumn
= colIndex
;
1008 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
1010 wxWindow
* tc
= GenerateEditorTextCtrl(r
.GetPosition(),
1018 wxWindowID id
= tc
->GetId();
1019 tc
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1020 wxCommandEventHandler(wxPropertyGrid::OnLabelEditorEnterPress
),
1022 tc
->Connect(id
, wxEVT_KEY_DOWN
,
1023 wxKeyEventHandler(wxPropertyGrid::OnLabelEditorKeyPress
),
1028 m_labelEditor
= wxStaticCast(tc
, wxTextCtrl
);
1029 m_labelEditorProperty
= selected
;
1032 // -----------------------------------------------------------------------
1035 wxPropertyGrid::OnLabelEditorEnterPress( wxCommandEvent
& WXUNUSED(event
) )
1037 DoEndLabelEdit(true);
1040 // -----------------------------------------------------------------------
1042 void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent
& event
)
1044 int keycode
= event
.GetKeyCode();
1046 if ( keycode
== WXK_ESCAPE
)
1048 DoEndLabelEdit(false);
1056 // -----------------------------------------------------------------------
1058 void wxPropertyGrid::DoEndLabelEdit( bool commit
, int selFlags
)
1060 if ( !m_labelEditor
)
1063 wxPGProperty
* prop
= m_labelEditorProperty
;
1068 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
1070 // wxPG_SEL_NOVALIDATE is passed correctly in selFlags
1071 if ( SendEvent( wxEVT_PG_LABEL_EDIT_ENDING
,
1072 prop
, NULL
, selFlags
,
1077 wxString text
= m_labelEditor
->GetValue();
1078 wxPGCell
* cell
= NULL
;
1079 if ( prop
->HasCell(m_selColumn
) )
1081 cell
= &prop
->GetCell(m_selColumn
);
1085 if ( m_selColumn
== 0 )
1086 prop
->SetLabel(text
);
1088 cell
= &prop
->GetOrCreateCell(m_selColumn
);
1092 cell
->SetText(text
);
1097 DestroyEditorWnd(m_labelEditor
);
1098 m_labelEditor
= NULL
;
1099 m_labelEditorProperty
= NULL
;
1104 // -----------------------------------------------------------------------
1106 void wxPropertyGrid::SetExtraStyle( long exStyle
)
1108 if ( exStyle
& wxPG_EX_ENABLE_TLP_TRACKING
)
1109 OnTLPChanging(::wxGetTopLevelParent(this));
1111 OnTLPChanging(NULL
);
1113 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
1115 #if defined(__WXMSW__)
1118 // Don't use WS_EX_COMPOSITED just now.
1121 if ( m_iFlags & wxPG_FL_IN_MANAGER )
1122 hWnd = (HWND)GetParent()->GetHWND();
1124 hWnd = (HWND)GetHWND();
1126 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1127 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1130 //#elif defined(__WXGTK20__)
1132 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
1133 // truly was double-buffered.
1134 if ( !this->IsDoubleBuffered() )
1136 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
1140 #if wxPG_DOUBLE_BUFFER
1141 delete m_doubleBuffer
;
1142 m_doubleBuffer
= NULL
;
1147 wxScrolledWindow::SetExtraStyle( exStyle
);
1149 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
1150 m_pState
->InitNonCatMode();
1152 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
1153 m_windowStyle
|= wxPG_TOOLTIPS
;
1156 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1159 // -----------------------------------------------------------------------
1161 // returns the best acceptable minimal size
1162 wxSize
wxPropertyGrid::DoGetBestSize() const
1164 int lineHeight
= wxMax(15, m_lineHeight
);
1166 // don't make the grid too tall (limit height to 10 items) but don't
1167 // make it too small neither
1168 int numLines
= wxMin
1170 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
1174 wxClientDC
dc(const_cast<wxPropertyGrid
*>(this));
1175 int width
= m_marginWidth
;
1176 for ( unsigned int i
= 0; i
< m_pState
->m_colWidths
.size(); i
++ )
1178 width
+= m_pState
->GetColumnFitWidth(dc
, m_pState
->DoGetRoot(), i
, true);
1181 const wxSize sz
= wxSize(width
, lineHeight
*numLines
+ 40);
1187 // -----------------------------------------------------------------------
1189 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
1191 if ( newTLP
== m_tlp
)
1194 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
1197 // Parent changed so let's redetermine and re-hook the
1198 // correct top-level window.
1201 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
1202 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1204 m_tlpClosed
= m_tlp
;
1205 m_tlpClosedTime
= currentTime
;
1210 // Only accept new tlp if same one was not just dismissed.
1211 if ( newTLP
!= m_tlpClosed
||
1212 m_tlpClosedTime
+250 < currentTime
)
1214 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
1215 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
1228 // -----------------------------------------------------------------------
1230 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
1232 // ClearSelection forces value validation/commit.
1233 if ( event
.CanVeto() && !DoClearSelection() )
1239 // Ok, it can close, set tlp pointer to NULL. Some other event
1240 // handler can of course veto the close, but our OnIdle() should
1241 // then be able to regain the tlp pointer.
1242 OnTLPChanging(NULL
);
1247 // -----------------------------------------------------------------------
1249 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1251 OnTLPChanging((wxWindow
*)newParent
);
1253 bool res
= wxScrolledWindow::Reparent(newParent
);
1258 // -----------------------------------------------------------------------
1259 // wxPropertyGrid Font and Colour Methods
1260 // -----------------------------------------------------------------------
1262 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1266 m_captionFont
= wxScrolledWindow::GetFont();
1268 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1269 m_subgroup_extramargin
= x
+ (x
/2);
1272 #if wxPG_USE_RENDERER_NATIVE
1273 m_iconWidth
= wxPG_ICON_WIDTH
;
1274 #elif wxPG_ICON_WIDTH
1276 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1277 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1278 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1282 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1283 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1284 m_gutterWidth
= wxPG_GUTTER_MIN
;
1287 if ( vspacing
<= 1 ) vdiv
= 12;
1288 else if ( vspacing
>= 3 ) vdiv
= 3;
1290 m_spacingy
= m_fontHeight
/ vdiv
;
1291 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1292 m_spacingy
= wxPG_YSPACING_MIN
;
1295 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1296 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1298 m_captionFont
.SetWeight(wxBOLD
);
1299 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1301 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1304 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1305 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1308 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1310 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1311 RecalculateVirtualSize();
1313 InvalidateBestSize();
1316 // -----------------------------------------------------------------------
1318 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1324 // -----------------------------------------------------------------------
1326 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1327 int ga
= 1000, int ba
= 1000,
1328 bool forceDifferent
= false)
1335 // Recursion guard (allow 2 max)
1336 static int isinside
= 0;
1338 wxCHECK_MSG( isinside
< 3,
1340 wxT("wxPGAdjustColour should not be recursively called more than once") );
1345 int g
= src
.Green();
1348 if ( r2
>255 ) r2
= 255;
1349 else if ( r2
<0) r2
= 0;
1351 if ( g2
>255 ) g2
= 255;
1352 else if ( g2
<0) g2
= 0;
1354 if ( b2
>255 ) b2
= 255;
1355 else if ( b2
<0) b2
= 0;
1357 // Make sure they are somewhat different
1358 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1359 dst
= wxPGAdjustColour(src
,-(ra
*2));
1361 dst
= wxColour(r2
,g2
,b2
);
1363 // Recursion guard (allow 2 max)
1370 static int wxPGGetColAvg( const wxColour
& col
)
1372 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1376 void wxPropertyGrid::RegainColours()
1378 if ( !(m_coloursCustomized
& 0x0002) )
1380 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1382 // Make sure colour is dark enough
1384 int colDec
= wxPGGetColAvg(col
) - 230;
1386 int colDec
= wxPGGetColAvg(col
) - 200;
1389 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1392 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1395 if ( !(m_coloursCustomized
& 0x0001) )
1396 m_colMargin
= m_colCapBack
;
1398 if ( !(m_coloursCustomized
& 0x0004) )
1405 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1406 m_colCapFore
= capForeCol
;
1407 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1410 if ( !(m_coloursCustomized
& 0x0008) )
1412 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1413 m_colPropBack
= bgCol
;
1414 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1417 if ( !(m_coloursCustomized
& 0x0010) )
1419 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1420 m_colPropFore
= fgCol
;
1421 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1424 if ( !(m_coloursCustomized
& 0x0020) )
1425 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1427 if ( !(m_coloursCustomized
& 0x0040) )
1428 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1430 if ( !(m_coloursCustomized
& 0x0080) )
1431 m_colLine
= m_colCapBack
;
1433 if ( !(m_coloursCustomized
& 0x0100) )
1434 m_colDisPropFore
= m_colCapFore
;
1436 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1439 // -----------------------------------------------------------------------
1441 void wxPropertyGrid::ResetColours()
1443 m_coloursCustomized
= 0;
1450 // -----------------------------------------------------------------------
1452 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1454 // Must disable active editor.
1457 bool res
= wxScrolledWindow::SetFont( font
);
1458 if ( res
&& GetParent()) // may not have been Create()ed yet if SetFont called from SetWindowVariant
1460 CalculateFontAndBitmapStuff( m_vspacing
);
1467 // -----------------------------------------------------------------------
1469 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1472 m_coloursCustomized
|= 0x80;
1476 // -----------------------------------------------------------------------
1478 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1481 m_coloursCustomized
|= 0x01;
1485 // -----------------------------------------------------------------------
1487 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1489 m_colPropBack
= col
;
1490 m_coloursCustomized
|= 0x08;
1492 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1497 // -----------------------------------------------------------------------
1499 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1501 m_colPropFore
= col
;
1502 m_coloursCustomized
|= 0x10;
1504 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1509 // -----------------------------------------------------------------------
1511 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1513 m_colEmptySpace
= col
;
1518 // -----------------------------------------------------------------------
1520 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1522 m_colDisPropFore
= col
;
1523 m_coloursCustomized
|= 0x100;
1527 // -----------------------------------------------------------------------
1529 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1532 m_coloursCustomized
|= 0x20;
1536 // -----------------------------------------------------------------------
1538 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1541 m_coloursCustomized
|= 0x40;
1545 // -----------------------------------------------------------------------
1547 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1550 m_coloursCustomized
|= 0x02;
1552 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1557 // -----------------------------------------------------------------------
1559 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1562 m_coloursCustomized
|= 0x04;
1564 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1569 // -----------------------------------------------------------------------
1570 // wxPropertyGrid property adding and removal
1571 // -----------------------------------------------------------------------
1573 void wxPropertyGrid::PrepareAfterItemsAdded()
1575 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1577 m_pState
->m_itemsAdded
= 0;
1579 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1580 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1582 RecalculateVirtualSize();
1585 // -----------------------------------------------------------------------
1586 // wxPropertyGrid property operations
1587 // -----------------------------------------------------------------------
1589 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1591 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1595 bool changed
= false;
1597 // Is it inside collapsed section?
1598 if ( !p
->IsVisible() )
1601 wxPGProperty
* parent
= p
->GetParent();
1602 wxPGProperty
* grandparent
= parent
->GetParent();
1604 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1605 Expand( grandparent
);
1613 GetViewStart(&vx
,&vy
);
1614 vy
*=wxPG_PIXELS_PER_UNIT
;
1620 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1621 m_iFlags
|= wxPG_FL_SCROLLED
;
1624 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1626 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1627 m_iFlags
|= wxPG_FL_SCROLLED
;
1637 // -----------------------------------------------------------------------
1638 // wxPropertyGrid helper methods called by properties
1639 // -----------------------------------------------------------------------
1641 // Control font changer helper.
1642 void wxPropertyGrid::SetCurControlBoldFont()
1644 wxASSERT( m_wndEditor
);
1645 m_wndEditor
->SetFont( m_captionFont
);
1648 // -----------------------------------------------------------------------
1650 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1653 #if wxPG_SMALL_SCREEN
1654 // On small-screen devices, always show dialogs with default position and size.
1655 return wxDefaultPosition
;
1657 int splitterX
= GetSplitterPosition();
1661 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1663 ImprovedClientToScreen( &x
, &y
);
1665 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1666 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1673 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1683 new_y
= y
+ m_lineHeight
;
1685 return wxPoint(new_x
,new_y
);
1689 // -----------------------------------------------------------------------
1691 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1693 if ( src_str
.length() == 0 )
1699 bool prev_is_slash
= false;
1701 wxString::const_iterator i
= src_str
.begin();
1705 for ( ; i
!= src_str
.end(); ++i
)
1709 if ( a
!= wxS('\\') )
1711 if ( !prev_is_slash
)
1717 if ( a
== wxS('n') )
1720 dst_str
<< wxS('\n');
1722 dst_str
<< wxS('\n');
1725 else if ( a
== wxS('t') )
1726 dst_str
<< wxS('\t');
1730 prev_is_slash
= false;
1734 if ( prev_is_slash
)
1736 dst_str
<< wxS('\\');
1737 prev_is_slash
= false;
1741 prev_is_slash
= true;
1748 // -----------------------------------------------------------------------
1750 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1752 if ( src_str
.length() == 0 )
1758 wxString::const_iterator i
= src_str
.begin();
1759 wxUniChar prev_a
= wxS('\0');
1763 for ( ; i
!= src_str
.end(); ++i
)
1767 if ( a
>= wxS(' ') )
1769 // This surely is not something that requires an escape sequence.
1774 // This might need...
1775 if ( a
== wxS('\r') )
1777 // DOS style line end.
1778 // Already taken care below
1780 else if ( a
== wxS('\n') )
1781 // UNIX style line end.
1782 dst_str
<< wxS("\\n");
1783 else if ( a
== wxS('\t') )
1785 dst_str
<< wxS('\t');
1788 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1798 // -----------------------------------------------------------------------
1800 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1807 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1810 // -----------------------------------------------------------------------
1811 // wxPropertyGrid graphics related methods
1812 // -----------------------------------------------------------------------
1814 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1818 // Update everything inside the box
1819 wxRect r
= GetUpdateRegion().GetBox();
1821 dc
.SetPen(m_colEmptySpace
);
1822 dc
.SetBrush(m_colEmptySpace
);
1823 dc
.DrawRectangle(r
);
1826 // -----------------------------------------------------------------------
1828 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1829 wxPGProperty
* property
) const
1831 // Prepare rectangle to be used
1833 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1834 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1836 #if (wxPG_USE_RENDERER_NATIVE)
1838 #elif wxPG_ICON_WIDTH
1839 // Drawing expand/collapse button manually
1840 dc
.SetPen(m_colPropFore
);
1841 if ( property
->IsCategory() )
1842 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1844 dc
.SetBrush(m_colPropBack
);
1846 dc
.DrawRectangle( r
);
1847 int _y
= r
.y
+(m_iconWidth
/2);
1848 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1853 if ( property
->IsExpanded() )
1855 // wxRenderer functions are non-mutating in nature, so it
1856 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1857 // Hopefully this does not cause problems.
1858 #if (wxPG_USE_RENDERER_NATIVE)
1859 wxRendererNative::Get().DrawTreeItemButton(
1865 #elif wxPG_ICON_WIDTH
1874 #if (wxPG_USE_RENDERER_NATIVE)
1875 wxRendererNative::Get().DrawTreeItemButton(
1881 #elif wxPG_ICON_WIDTH
1882 int _x
= r
.x
+(m_iconWidth
/2);
1883 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1889 #if (wxPG_USE_RENDERER_NATIVE)
1891 #elif wxPG_ICON_WIDTH
1894 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1898 // -----------------------------------------------------------------------
1901 // This is the one called by OnPaint event handler and others.
1902 // topy and bottomy are already unscrolled (ie. physical)
1904 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1906 unsigned int bottomy
,
1907 const wxRect
* clipRect
)
1909 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1911 m_pState
->EnsureVirtualHeight();
1913 wxRect tempClipRect
;
1916 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1917 clipRect
= &tempClipRect
;
1920 // items added check
1921 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1923 int paintFinishY
= 0;
1925 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1928 bool isBuffered
= false;
1930 #if wxPG_DOUBLE_BUFFER
1931 wxMemoryDC
* bufferDC
= NULL
;
1933 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1935 if ( !m_doubleBuffer
)
1937 paintFinishY
= clipRect
->y
;
1942 bufferDC
= new wxMemoryDC();
1944 // If nothing was changed, then just copy from double-buffer
1945 bufferDC
->SelectObject( *m_doubleBuffer
);
1955 dc
.SetClippingRegion( *clipRect
);
1956 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1959 #if wxPG_DOUBLE_BUFFER
1962 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1963 bufferDC
, 0, 0, wxCOPY
);
1964 dc
.DestroyClippingRegion(); // Is this really necessary?
1970 // Clear area beyond bottomY?
1971 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1973 dc
.SetPen(m_colEmptySpace
);
1974 dc
.SetBrush(m_colEmptySpace
);
1975 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1979 // -----------------------------------------------------------------------
1981 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1982 const wxRect
* clipRect
,
1983 bool isBuffered
) const
1985 const wxPGProperty
* firstItem
;
1986 const wxPGProperty
* lastItem
;
1988 firstItem
= DoGetItemAtY(clipRect
->y
);
1989 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1992 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1994 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1997 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1998 wxASSERT( m_pState
->m_properties
->GetChildCount() );
2000 int lh
= m_lineHeight
;
2003 int lastItemBottomY
;
2005 firstItemTopY
= clipRect
->y
;
2006 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
2008 // Align y coordinates to item boundaries
2009 firstItemTopY
-= firstItemTopY
% lh
;
2010 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
2011 lastItemBottomY
-= 1;
2013 // Entire range outside scrolled, visible area?
2014 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
2017 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
2021 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
2022 firstItem->GetLabel().c_str(),
2023 lastItem->GetLabel().c_str(),
2024 (int)(lastItemBottomY - firstItemTopY),
2026 (unsigned long)clipRect );
2031 long windowStyle
= m_windowStyle
;
2037 // With wxPG_DOUBLE_BUFFER, do double buffering
2038 // - buffer's y = 0, so align cliprect and coordinates to that
2040 #if wxPG_DOUBLE_BUFFER
2046 xRelMod
= clipRect
->x
;
2047 yRelMod
= clipRect
->y
;
2050 // clipRect conversion
2055 firstItemTopY
-= yRelMod
;
2056 lastItemBottomY
-= yRelMod
;
2059 wxUnusedVar(isBuffered
);
2062 int x
= m_marginWidth
- xRelMod
;
2064 wxFont normalFont
= GetFont();
2066 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
2068 bool isPgEnabled
= IsEnabled();
2071 // Prepare some pens and brushes that are often changed to.
2074 wxBrush
marginBrush(m_colMargin
);
2075 wxPen
marginPen(m_colMargin
);
2076 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2077 wxPen
linepen(m_colLine
,1,wxSOLID
);
2079 wxColour selBackCol
;
2081 selBackCol
= m_colSelBack
;
2083 selBackCol
= m_colMargin
;
2085 // pen that has same colour as text
2086 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2089 // Clear margin with background colour
2091 dc
.SetBrush( marginBrush
);
2092 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2094 dc
.SetPen( *wxTRANSPARENT_PEN
);
2095 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2098 const wxPGProperty
* firstSelected
= GetSelection();
2099 const wxPropertyGridPageState
* state
= m_pState
;
2101 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2102 bool wasSelectedPainted
= false;
2105 // TODO: Only render columns that are within clipping region.
2107 dc
.SetFont(normalFont
);
2109 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2110 int endScanBottomY
= lastItemBottomY
+ lh
;
2111 int y
= firstItemTopY
;
2114 // Pregenerate list of visible properties.
2115 wxArrayPGProperty visPropArray
;
2116 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2118 for ( ; !it
.AtEnd(); it
.Next() )
2120 const wxPGProperty
* p
= *it
;
2122 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2124 visPropArray
.push_back((wxPGProperty
*)p
);
2126 if ( y
> endScanBottomY
)
2133 visPropArray
.push_back(NULL
);
2135 wxPGProperty
* nextP
= visPropArray
[0];
2137 int gridWidth
= state
->m_width
;
2140 for ( unsigned int arrInd
=1;
2141 nextP
&& y
<= lastItemBottomY
;
2144 wxPGProperty
* p
= nextP
;
2145 nextP
= visPropArray
[arrInd
];
2147 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2148 int textMarginHere
= x
;
2149 int renderFlags
= 0;
2151 int greyDepth
= m_marginWidth
;
2152 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2153 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2155 int greyDepthX
= greyDepth
- xRelMod
;
2157 // Use basic depth if in non-categoric mode and parent is base array.
2158 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2160 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2163 // Paint margin area
2164 dc
.SetBrush(marginBrush
);
2165 dc
.SetPen(marginPen
);
2166 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2168 dc
.SetPen( linepen
);
2174 // Modified by JACS to not draw a margin if wxPG_HIDE_MARGIN is specified, since it
2175 // looks better, at least under Windows when we have a themed border (the themed-window-specific
2176 // whitespace between the real border and the propgrid margin exacerbates the double-border look).
2178 // Is this or its parent themed?
2179 bool suppressMarginEdge
= (GetWindowStyle() & wxPG_HIDE_MARGIN
) &&
2180 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
) ||
2181 (((GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_NONE
) && ((GetParent()->GetWindowStyle() & wxBORDER_MASK
) == wxBORDER_THEME
)));
2183 bool suppressMarginEdge
= false;
2185 if (!suppressMarginEdge
)
2186 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2189 // Blank out the margin edge
2190 dc
.SetPen(wxPen(GetBackgroundColour()));
2191 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2192 dc
.SetPen( linepen
);
2199 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2201 sx
+= state
->m_colWidths
[si
];
2202 dc
.DrawLine( sx
, y
, sx
, y2
);
2205 // Horizontal Line, below
2206 // (not if both this and next is category caption)
2207 if ( p
->IsCategory() &&
2208 nextP
&& nextP
->IsCategory() )
2209 dc
.SetPen(m_colCapBack
);
2211 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2214 // Need to override row colours?
2218 bool isSelected
= state
->DoIsPropertySelected(p
);
2222 // Disabled may get different colour.
2223 if ( !p
->IsEnabled() )
2225 renderFlags
|= wxPGCellRenderer::Disabled
|
2226 wxPGCellRenderer::DontUseCellFgCol
;
2227 rowFgCol
= m_colDisPropFore
;
2232 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2233 if ( p
== firstSelected
)
2234 wasSelectedPainted
= true;
2237 renderFlags
|= wxPGCellRenderer::Selected
;
2239 if ( !p
->IsCategory() )
2241 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
2242 wxPGCellRenderer::DontUseCellBgCol
;
2244 if ( reallyFocused
&& p
== firstSelected
)
2246 rowFgCol
= m_colSelFore
;
2247 rowBgCol
= selBackCol
;
2249 else if ( isPgEnabled
)
2251 rowFgCol
= m_colPropFore
;
2252 if ( p
== firstSelected
)
2253 rowBgCol
= m_colMargin
;
2255 rowBgCol
= selBackCol
;
2259 rowFgCol
= m_colDisPropFore
;
2260 rowBgCol
= selBackCol
;
2267 if ( rowBgCol
.IsOk() )
2268 rowBgBrush
= wxBrush(rowBgCol
);
2270 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2271 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2274 // Fill additional margin area with background colour of first cell
2275 if ( greyDepthX
< textMarginHere
)
2277 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2279 wxPGCell
& cell
= p
->GetCell(0);
2280 rowBgCol
= cell
.GetBgCol();
2281 rowBgBrush
= wxBrush(rowBgCol
);
2283 dc
.SetBrush(rowBgBrush
);
2284 dc
.SetPen(rowBgCol
);
2285 dc
.DrawRectangle(greyDepthX
+1, y
,
2286 textMarginHere
-greyDepthX
, lh
-1);
2289 bool fontChanged
= false;
2291 // Expander button rectangle
2292 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2297 if ( p
->IsCategory() )
2299 // Captions have their cell areas merged as one
2300 dc
.SetFont(m_captionFont
);
2302 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2304 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2306 dc
.SetBrush(rowBgBrush
);
2307 dc
.SetPen(rowBgCol
);
2310 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2312 dc
.SetTextForeground(rowFgCol
);
2315 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2316 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2319 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2320 DrawExpanderButton( dc
, butRect
, p
);
2324 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2326 dc
.SetFont(m_captionFont
);
2332 int nextCellWidth
= state
->m_colWidths
[0] -
2333 (greyDepthX
- m_marginWidth
);
2334 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2335 int textXAdd
= textMarginHere
- greyDepthX
;
2337 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2339 cellRect
.width
= nextCellWidth
- 1;
2341 wxWindow
* cellEditor
= NULL
;
2342 int cellRenderFlags
= renderFlags
;
2344 // Tree Item Button (must be drawn before clipping is set up)
2345 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2346 DrawExpanderButton( dc
, butRect
, p
);
2349 if ( isSelected
&& (ci
== 1 || ci
== m_selColumn
) )
2351 if ( p
== firstSelected
)
2353 if ( ci
== 1 && m_wndEditor
)
2354 cellEditor
= m_wndEditor
;
2355 else if ( ci
== m_selColumn
&& m_labelEditor
)
2356 cellEditor
= m_labelEditor
;
2361 wxColour editorBgCol
=
2362 cellEditor
->GetBackgroundColour();
2363 dc
.SetBrush(editorBgCol
);
2364 dc
.SetPen(editorBgCol
);
2365 dc
.SetTextForeground(m_colPropFore
);
2366 dc
.DrawRectangle(cellRect
);
2368 if ( m_dragStatus
!= 0 ||
2369 (m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2374 dc
.SetBrush(m_colPropBack
);
2375 dc
.SetPen(m_colPropBack
);
2376 dc
.SetTextForeground(m_colDisPropFore
);
2377 if ( p
->IsEnabled() )
2378 dc
.SetTextForeground(rowFgCol
);
2380 dc
.SetTextForeground(m_colDisPropFore
);
2385 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2387 dc
.SetBrush(rowBgBrush
);
2388 dc
.SetPen(rowBgCol
);
2391 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2393 dc
.SetTextForeground(rowFgCol
);
2397 dc
.SetClippingRegion(cellRect
);
2399 cellRect
.x
+= textXAdd
;
2400 cellRect
.width
-= textXAdd
;
2405 wxPGCellRenderer
* renderer
;
2406 int cmnVal
= p
->GetCommonValue();
2407 if ( cmnVal
== -1 || ci
!= 1 )
2409 renderer
= p
->GetCellRenderer(ci
);
2410 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2415 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2416 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2421 cellX
+= state
->m_colWidths
[ci
];
2422 if ( ci
< (state
->m_colWidths
.size()-1) )
2423 nextCellWidth
= state
->m_colWidths
[ci
+1];
2425 dc
.DestroyClippingRegion(); // Is this really necessary?
2431 dc
.SetFont(normalFont
);
2436 // Refresh editor controls (seems not needed on msw)
2437 // NOTE: This code is mandatory for GTK!
2438 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2439 if ( wasSelectedPainted
)
2442 m_wndEditor
->Refresh();
2444 m_wndEditor2
->Refresh();
2451 // -----------------------------------------------------------------------
2453 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2457 if ( m_width
< 10 || m_height
< 10 ||
2458 !m_pState
->m_properties
->GetChildCount() ||
2460 return wxRect(0,0,0,0);
2465 // Return rect which encloses the given property range
2467 int visTop
= p1
->GetY();
2470 visBottom
= p2
->GetY() + m_lineHeight
;
2472 visBottom
= m_height
+ visTop
;
2474 // If seleced property is inside the range, we'll extend the range to include
2476 wxPGProperty
* selected
= GetSelection();
2479 int selectedY
= selected
->GetY();
2480 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2482 wxWindow
* editor
= GetEditorControl();
2485 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2486 if ( visBottom2
> visBottom
)
2487 visBottom
= visBottom2
;
2492 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2495 // -----------------------------------------------------------------------
2497 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2502 if ( m_pState
->m_itemsAdded
)
2503 PrepareAfterItemsAdded();
2505 wxRect r
= GetPropertyRect(p1
, p2
);
2508 m_canvas
->RefreshRect(r
);
2512 // -----------------------------------------------------------------------
2514 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2516 if ( m_pState
->DoIsPropertySelected(p
) )
2518 // NB: We must copy the selection.
2519 wxArrayPGProperty selection
= m_pState
->m_selection
;
2520 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2523 DrawItemAndChildren(p
);
2526 // -----------------------------------------------------------------------
2528 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2533 // Draw item, children, and parent too, if it is not category
2534 wxPGProperty
* parent
= p
->GetParent();
2537 !parent
->IsCategory() &&
2538 parent
->GetParent() )
2541 parent
= parent
->GetParent();
2544 DrawItemAndChildren(p
);
2547 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2549 wxCHECK_RET( p
, wxT("invalid property id") );
2551 // Do not draw if in non-visible page
2552 if ( p
->GetParentState() != m_pState
)
2555 // do not draw a single item if multiple pending
2556 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2559 // Update child control.
2560 wxPGProperty
* selected
= GetSelection();
2561 if ( selected
&& selected
->GetParent() == p
)
2564 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2566 DrawItems(p
, lastDrawn
);
2569 // -----------------------------------------------------------------------
2571 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2572 const wxRect
*rect
)
2574 PrepareAfterItemsAdded();
2576 wxWindow::Refresh(false);
2578 // TODO: Coordinate translation
2579 m_canvas
->Refresh(false, rect
);
2581 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2582 // I think this really helps only GTK+1.2
2583 if ( m_wndEditor
) m_wndEditor
->Refresh();
2584 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2588 // -----------------------------------------------------------------------
2589 // wxPropertyGrid global operations
2590 // -----------------------------------------------------------------------
2592 void wxPropertyGrid::Clear()
2594 m_pState
->DoClear();
2600 RecalculateVirtualSize();
2602 // Need to clear some area at the end
2604 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2607 // -----------------------------------------------------------------------
2609 bool wxPropertyGrid::EnableCategories( bool enable
)
2616 // Enable categories
2619 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2624 // Disable categories
2626 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2629 if ( !m_pState
->EnableCategories(enable
) )
2634 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2636 m_pState
->m_itemsAdded
= 1; // force
2637 PrepareAfterItemsAdded();
2641 m_pState
->m_itemsAdded
= 1;
2643 // No need for RecalculateVirtualSize() here - it is already called in
2644 // wxPropertyGridPageState method above.
2651 // -----------------------------------------------------------------------
2653 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2655 wxASSERT( pNewState
);
2656 wxASSERT( pNewState
->GetGrid() );
2658 if ( pNewState
== m_pState
)
2661 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2663 // Call ClearSelection() instead of DoClearSelection()
2664 // so that selection clear events are not sent.
2667 m_pState
->m_selection
= oldSelection
;
2669 bool orig_mode
= m_pState
->IsInNonCatMode();
2670 bool new_state_mode
= pNewState
->IsInNonCatMode();
2672 m_pState
= pNewState
;
2675 int pgWidth
= GetClientSize().x
;
2676 if ( HasVirtualWidth() )
2678 int minWidth
= pgWidth
;
2679 if ( pNewState
->m_width
< minWidth
)
2681 pNewState
->m_width
= minWidth
;
2682 pNewState
->CheckColumnWidths();
2688 // Just in case, fully re-center splitter
2689 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2690 pNewState
->m_fSplitterX
= -1.0;
2692 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2697 // If necessary, convert state to correct mode.
2698 if ( orig_mode
!= new_state_mode
)
2700 // This should refresh as well.
2701 EnableCategories( orig_mode
?false:true );
2703 else if ( !m_frozen
)
2705 // Refresh, if not frozen.
2706 m_pState
->PrepareAfterItemsAdded();
2708 // Reselect (Use SetSelection() instead of Do-variant so that
2709 // events won't be sent).
2710 SetSelection(m_pState
->m_selection
);
2712 RecalculateVirtualSize(0);
2716 m_pState
->m_itemsAdded
= 1;
2719 // -----------------------------------------------------------------------
2721 // Call to SetSplitterPosition will always disable splitter auto-centering
2722 // if parent window is shown.
2723 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2725 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2728 wxPropertyGridPageState
* state
= m_pState
;
2730 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2734 if ( GetSelection() )
2735 CorrectEditorWidgetSizeX();
2741 // -----------------------------------------------------------------------
2743 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2745 SetSplitterPosition( m_width
/2, true );
2746 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2747 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2750 // -----------------------------------------------------------------------
2751 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2752 // -----------------------------------------------------------------------
2754 // Returns nearest paint visible property (such that will be painted unless
2755 // window is scrolled or resized). If given property is paint visible, then
2756 // it itself will be returned
2757 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2759 int vx
,vy1
;// Top left corner of client
2760 GetViewStart(&vx
,&vy1
);
2761 vy1
*= wxPG_PIXELS_PER_UNIT
;
2763 int vy2
= vy1
+ m_height
;
2764 int propY
= p
->GetY2(m_lineHeight
);
2766 if ( (propY
+ m_lineHeight
) < vy1
)
2769 return DoGetItemAtY( vy1
);
2771 else if ( propY
> vy2
)
2774 return DoGetItemAtY( vy2
);
2777 // Itself paint visible
2782 // -----------------------------------------------------------------------
2783 // Methods related to change in value, value modification and sending events
2784 // -----------------------------------------------------------------------
2786 // commits any changes in editor of selected property
2787 // return true if validation did not fail
2788 // flags are same as with DoSelectProperty
2789 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2791 // Committing already?
2792 if ( m_inCommitChangesFromEditor
)
2795 // Don't do this if already processing editor event. It might
2796 // induce recursive dialogs and crap like that.
2797 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2799 if ( m_inDoPropertyChanged
)
2805 wxPGProperty
* selected
= GetSelection();
2808 IsEditorsValueModified() &&
2809 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2812 m_inCommitChangesFromEditor
= 1;
2814 wxVariant
variant(selected
->GetValueRef());
2815 bool valueIsPending
= false;
2817 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2818 // due to another window getting focus
2819 wxWindow
* oldFocus
= m_curFocused
;
2821 bool validationFailure
= false;
2822 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2824 m_chgInfo_changedProperty
= NULL
;
2826 // If truly modified, schedule value as pending.
2827 if ( selected
->GetEditorClass()->
2828 GetValueFromControl( variant
,
2830 GetEditorControl() ) )
2832 if ( DoEditorValidate() &&
2833 PerformValidation(selected
, variant
) )
2835 valueIsPending
= true;
2839 validationFailure
= true;
2844 EditorsValueWasNotModified();
2849 m_inCommitChangesFromEditor
= 0;
2851 if ( validationFailure
&& !forceSuccess
)
2855 oldFocus
->SetFocus();
2856 m_curFocused
= oldFocus
;
2859 res
= OnValidationFailure(selected
, variant
);
2861 // Now prevent further validation failure messages
2864 EditorsValueWasNotModified();
2865 OnValidationFailureReset(selected
);
2868 else if ( valueIsPending
)
2870 DoPropertyChanged( selected
, flags
);
2871 EditorsValueWasNotModified();
2880 // -----------------------------------------------------------------------
2882 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2886 // Runs all validation functionality.
2887 // Returns true if value passes all tests.
2890 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2892 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2894 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2899 // Adapt list to child values, if necessary
2900 wxVariant listValue
= pendingValue
;
2901 wxVariant
* pPendingValue
= &pendingValue
;
2902 wxVariant
* pList
= NULL
;
2904 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2905 // string value, then we need treat as it was changed instead
2906 // (or, in addition, as is the case with composite string parent).
2907 // This includes creating list variant for child values.
2909 wxPGProperty
* pwc
= p
->GetParent();
2910 wxPGProperty
* changedProperty
= p
;
2911 wxPGProperty
* baseChangedProperty
= changedProperty
;
2912 wxVariant bcpPendingList
;
2914 listValue
= pendingValue
;
2915 listValue
.SetName(p
->GetBaseName());
2918 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2920 wxVariantList tempList
;
2921 wxVariant
lv(tempList
, pwc
->GetBaseName());
2922 lv
.Append(listValue
);
2924 pPendingValue
= &listValue
;
2926 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2928 baseChangedProperty
= pwc
;
2929 bcpPendingList
= lv
;
2932 changedProperty
= pwc
;
2933 pwc
= pwc
->GetParent();
2937 wxPGProperty
* evtChangingProperty
= changedProperty
;
2939 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2941 value
= *pPendingValue
;
2945 // Convert list to child values
2946 pList
= pPendingValue
;
2947 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2950 wxVariant evtChangingValue
= value
;
2952 if ( flags
& SendEvtChanging
)
2954 // FIXME: After proper ValueToString()s added, remove
2955 // this. It is just a temporary fix, as evt_changing
2956 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2957 // (unless it is selected, and textctrl editor is open).
2958 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2960 evtChangingProperty
= baseChangedProperty
;
2961 if ( evtChangingProperty
!= p
)
2963 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2967 evtChangingValue
= pendingValue
;
2971 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2973 if ( changedProperty
== GetSelection() )
2975 wxWindow
* editor
= GetEditorControl();
2976 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2977 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2981 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2986 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2987 m_chgInfo_changedProperty
= changedProperty
;
2988 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2989 m_chgInfo_pendingValue
= value
;
2992 m_chgInfo_valueList
= *pList
;
2994 m_chgInfo_valueList
.MakeNull();
2996 // If changedProperty is not property which value was edited,
2997 // then call wxPGProperty::ValidateValue() for that as well.
2998 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
3000 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
3004 if ( flags
& SendEvtChanging
)
3006 // SendEvent returns true if event was vetoed
3007 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
,
3008 &evtChangingValue
) )
3012 if ( flags
& IsStandaloneValidation
)
3014 // If called in 'generic' context, we need to reset
3015 // m_chgInfo_changedProperty and write back translated value.
3016 m_chgInfo_changedProperty
= NULL
;
3017 pendingValue
= value
;
3023 // -----------------------------------------------------------------------
3025 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
3027 if ( !msg
.length() )
3031 if ( !wxPGGlobalVars
->m_offline
)
3033 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
3036 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
3039 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
3042 pStatusBar
->SetStatusText(msg
);
3050 ::wxMessageBox(msg
, wxT("Property Error"));
3053 // -----------------------------------------------------------------------
3055 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
3056 wxVariant
& invalidValue
)
3058 wxWindow
* editor
= GetEditorControl();
3060 // First call property's handler
3061 property
->OnValidationFailure(invalidValue
);
3063 bool res
= DoOnValidationFailure(property
, invalidValue
);
3066 // For non-wxTextCtrl editors, we do need to revert the value
3067 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
3068 property
== GetSelection() )
3070 property
->GetEditorClass()->UpdateControl(property
, editor
);
3073 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
3078 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
3080 int vfb
= m_validationInfo
.m_failureBehavior
;
3082 if ( vfb
& wxPG_VFB_BEEP
)
3085 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
3086 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
3088 unsigned int colCount
= m_pState
->GetColumnCount();
3090 // We need backup marked property's cells
3091 m_propCellsBackup
= property
->m_cells
;
3093 wxColour vfbFg
= *wxWHITE
;
3094 wxColour vfbBg
= *wxRED
;
3096 property
->EnsureCells(colCount
);
3098 for ( unsigned int i
=0; i
<colCount
; i
++ )
3100 wxPGCell
& cell
= property
->m_cells
[i
];
3101 cell
.SetFgCol(vfbFg
);
3102 cell
.SetBgCol(vfbBg
);
3105 DrawItemAndChildren(property
);
3107 if ( property
== GetSelection() )
3109 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3111 wxWindow
* editor
= GetEditorControl();
3114 editor
->SetForegroundColour(vfbFg
);
3115 editor
->SetBackgroundColour(vfbBg
);
3120 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3122 wxString msg
= m_validationInfo
.m_failureMessage
;
3124 if ( !msg
.length() )
3125 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
3127 DoShowPropertyError(property
, msg
);
3130 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3133 // -----------------------------------------------------------------------
3135 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3137 int vfb
= m_validationInfo
.m_failureBehavior
;
3139 if ( vfb
& wxPG_VFB_MARK_CELL
)
3142 property
->m_cells
= m_propCellsBackup
;
3144 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3146 if ( property
== GetSelection() && GetEditorControl() )
3148 // Calling this will recreate the control, thus resetting its colour
3149 RefreshProperty(property
);
3153 DrawItemAndChildren(property
);
3158 // -----------------------------------------------------------------------
3160 // flags are same as with DoSelectProperty
3161 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3163 if ( m_inDoPropertyChanged
)
3166 wxWindow
* editor
= GetEditorControl();
3167 wxPGProperty
* selected
= GetSelection();
3169 m_pState
->m_anyModified
= 1;
3171 m_inDoPropertyChanged
= 1;
3173 // Maybe need to update control
3174 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3176 // These values were calculated in PerformValidation()
3177 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3178 wxVariant value
= m_chgInfo_pendingValue
;
3180 wxPGProperty
* topPaintedProperty
= changedProperty
;
3182 while ( !topPaintedProperty
->IsCategory() &&
3183 !topPaintedProperty
->IsRoot() )
3185 topPaintedProperty
= topPaintedProperty
->GetParent();
3188 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3190 // Set as Modified (not if dragging just began)
3191 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3193 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3194 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3197 SetCurControlBoldFont();
3203 // Propagate updates to parent(s)
3205 wxPGProperty
* prevPwc
= NULL
;
3207 while ( prevPwc
!= topPaintedProperty
)
3209 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3211 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3214 SetCurControlBoldFont();
3218 pwc
= pwc
->GetParent();
3221 // Draw the actual property
3222 DrawItemAndChildren( topPaintedProperty
);
3225 // If value was set by wxPGProperty::OnEvent, then update the editor
3227 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3233 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3234 if ( m_wndEditor
) m_wndEditor
->Refresh();
3235 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3240 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3242 // If top parent has composite string value, then send to child parents,
3243 // starting from baseChangedProperty.
3244 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3246 pwc
= m_chgInfo_baseChangedProperty
;
3248 while ( pwc
!= changedProperty
)
3250 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
);
3251 pwc
= pwc
->GetParent();
3255 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
);
3257 m_inDoPropertyChanged
= 0;
3262 // -----------------------------------------------------------------------
3264 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3266 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3268 m_chgInfo_changedProperty
= NULL
;
3270 if ( PerformValidation(p
, newValue
) )
3272 DoPropertyChanged(p
);
3277 OnValidationFailure(p
, newValue
);
3283 // -----------------------------------------------------------------------
3285 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3287 wxPGProperty
* prop
= GetSelectedProperty();
3290 return wxNullVariant
;
3292 wxTextCtrl
* tc
= GetEditorTextCtrl();
3293 wxVariant value
= prop
->GetValue();
3295 if ( !tc
|| !IsEditorsValueModified() )
3298 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3301 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3302 return prop
->GetValue();
3307 // -----------------------------------------------------------------------
3309 // Runs wxValidator for the selected property
3310 bool wxPropertyGrid::DoEditorValidate()
3315 // -----------------------------------------------------------------------
3317 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3319 wxPGProperty
* selected
= GetSelection();
3321 // Somehow, event is handled after property has been deselected.
3322 // Possibly, but very rare.
3323 if ( !selected
|| selected
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3326 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3329 wxVariant
pendingValue(selected
->GetValueRef());
3330 wxWindow
* wnd
= GetEditorControl();
3331 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3333 bool wasUnspecified
= selected
->IsValueUnspecified();
3334 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3335 bool valueIsPending
= false;
3337 m_chgInfo_changedProperty
= NULL
;
3339 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3342 // Filter out excess wxTextCtrl modified events
3343 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3345 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3347 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3349 wxString newTcValue
= tc
->GetValue();
3350 if ( m_prevTcValue
== newTcValue
)
3353 m_prevTcValue
= newTcValue
;
3356 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3358 bool validationFailure
= false;
3359 bool buttonWasHandled
= false;
3362 // Try common button handling
3363 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3365 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3369 buttonWasHandled
= true;
3370 // Store as res2, as previously (and still currently alternatively)
3371 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3372 // in wxPGProperty::OnEvent().
3373 adapter
->ShowDialog( this, selected
);
3378 if ( !buttonWasHandled
)
3380 if ( wnd
|| m_wndEditor2
)
3382 // First call editor class' event handler.
3383 const wxPGEditor
* editor
= selected
->GetEditorClass();
3385 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3387 // If changes, validate them
3388 if ( DoEditorValidate() )
3390 if ( editor
->GetValueFromControl( pendingValue
,
3393 valueIsPending
= true;
3397 validationFailure
= true;
3402 // Then the property's custom handler (must be always called, unless
3403 // validation failed).
3404 if ( !validationFailure
)
3405 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3408 // SetValueInEvent(), as called in one of the functions referred above
3409 // overrides editor's value.
3410 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3412 valueIsPending
= true;
3413 pendingValue
= m_changeInEventValue
;
3414 selFlags
|= wxPG_SEL_DIALOGVAL
;
3417 if ( !validationFailure
&& valueIsPending
)
3418 if ( !PerformValidation(selected
, pendingValue
) )
3419 validationFailure
= true;
3421 if ( validationFailure
)
3423 OnValidationFailure(selected
, pendingValue
);
3425 else if ( valueIsPending
)
3427 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3429 DoPropertyChanged(selected
, selFlags
);
3430 EditorsValueWasNotModified();
3432 // Regardless of editor type, unfocus editor on
3433 // text-editing related enter press.
3434 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3441 // No value after all
3443 // Regardless of editor type, unfocus editor on
3444 // text-editing related enter press.
3445 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3450 // Let unhandled button click events go to the parent
3451 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3453 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3454 GetEventHandler()->AddPendingEvent(evt
);
3458 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3461 // -----------------------------------------------------------------------
3462 // wxPropertyGrid editor control helper methods
3463 // -----------------------------------------------------------------------
3465 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3467 int itemy
= p
->GetY2(m_lineHeight
);
3469 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3470 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3471 int imageOffset
= 0;
3473 // TODO: If custom image detection changes from current, change this.
3474 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3476 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3477 int iw
= p
->OnMeasureImage().x
;
3479 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3480 imageOffset
= p
->GetImageOffset(iw
);
3485 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3487 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3492 // -----------------------------------------------------------------------
3494 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3496 wxSize sz
= GetImageSize(p
, item
);
3497 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3498 wxPG_CUSTOM_IMAGE_SPACINGY
,
3503 // return size of custom paint image
3504 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3506 // If called with NULL property, then return default image
3507 // size for properties that use image.
3509 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3511 wxSize cis
= p
->OnMeasureImage(item
);
3513 int choiceCount
= p
->m_choices
.GetCount();
3514 int comVals
= p
->GetDisplayedCommonValueCount();
3515 if ( item
>= choiceCount
&& comVals
> 0 )
3517 unsigned int cvi
= item
-choiceCount
;
3518 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3520 else if ( item
>= 0 && choiceCount
== 0 )
3521 return wxSize(0, 0);
3526 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3531 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3538 // -----------------------------------------------------------------------
3540 // takes scrolling into account
3541 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3544 GetViewStart(&vx
,&vy
);
3545 vy
*=wxPG_PIXELS_PER_UNIT
;
3546 vx
*=wxPG_PIXELS_PER_UNIT
;
3549 ClientToScreen( px
, py
);
3552 // -----------------------------------------------------------------------
3554 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3557 GetViewStart(&pt2
.x
,&pt2
.y
);
3558 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3559 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3563 return m_pState
->HitTest(pt2
);
3566 // -----------------------------------------------------------------------
3568 // custom set cursor
3569 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3571 if ( type
== m_curcursor
&& !override
) return;
3573 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3575 if ( type
== wxCURSOR_SIZEWE
)
3576 cursor
= m_cursorSizeWE
;
3578 m_canvas
->SetCursor( *cursor
);
3583 // -----------------------------------------------------------------------
3584 // wxPropertyGrid property selection, editor creation
3585 // -----------------------------------------------------------------------
3588 // This class forwards events from property editor controls to wxPropertyGrid.
3589 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3592 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3593 : wxEvtHandler(), m_propGrid(propGrid
)
3597 virtual ~wxPropertyGridEditorEventForwarder()
3602 bool ProcessEvent( wxEvent
& event
)
3607 m_propGrid
->HandleCustomEditorEvent(event
);
3609 return wxEvtHandler::ProcessEvent(event
);
3612 wxPropertyGrid
* m_propGrid
;
3615 // Setups event handling for child control
3616 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3618 wxWindowID id
= argWnd
->GetId();
3620 if ( argWnd
== m_wndEditor
)
3622 argWnd
->Connect(id
, wxEVT_MOTION
,
3623 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3625 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3626 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3628 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3629 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3631 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3632 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3634 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3635 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3637 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3638 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3642 wxPropertyGridEditorEventForwarder
* forwarder
;
3643 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3644 argWnd
->PushEventHandler(forwarder
);
3646 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3647 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3651 void wxPropertyGrid::DestroyEditorWnd( wxWindow
* wnd
)
3658 // Do not free editors immediately (for sake of processing events)
3659 wxPendingDelete
.Append(wnd
);
3662 void wxPropertyGrid::FreeEditors()
3665 // Return focus back to canvas from children (this is required at least for
3666 // GTK+, which, unlike Windows, clears focus when control is destroyed
3667 // instead of moving it to closest parent).
3668 wxWindow
* focus
= wxWindow::FindFocus();
3671 wxWindow
* parent
= focus
->GetParent();
3674 if ( parent
== m_canvas
)
3679 parent
= parent
->GetParent();
3683 // Do not free editors immediately if processing events
3686 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3687 m_wndEditor2
->Hide();
3688 wxPendingDelete
.Append( handler
);
3689 DestroyEditorWnd(m_wndEditor2
);
3690 m_wndEditor2
= NULL
;
3695 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3696 m_wndEditor
->Hide();
3697 wxPendingDelete
.Append( handler
);
3698 DestroyEditorWnd(m_wndEditor
);
3703 // Call with NULL to de-select property
3704 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3709 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3710 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3714 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3718 if ( m_inDoSelectProperty
)
3721 m_inDoSelectProperty
= 1;
3725 m_inDoSelectProperty
= 0;
3729 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3730 wxPGProperty
* prevFirstSel
;
3732 if ( prevSelection
.size() > 0 )
3733 prevFirstSel
= prevSelection
[0];
3735 prevFirstSel
= NULL
;
3737 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3738 prevFirstSel
= NULL
;
3740 // Always send event, as this is indirect call
3741 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
3745 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3747 wxPrintf( "None selected\n" );
3750 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3752 wxPrintf( "P = NULL\n" );
3755 // If we are frozen, then just set the values.
3758 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3759 m_editorFocused
= 0;
3760 m_pState
->DoSetSelection(p
);
3762 // If frozen, always free controls. But don't worry, as Thaw will
3763 // recall SelectProperty to recreate them.
3766 // Prevent any further selection measures in this call
3772 if ( prevFirstSel
== p
&&
3773 prevSelection
.size() <= 1 &&
3774 !(flags
& wxPG_SEL_FORCE
) )
3776 // Only set focus if not deselecting
3779 if ( flags
& wxPG_SEL_FOCUS
)
3783 m_wndEditor
->SetFocus();
3784 m_editorFocused
= 1;
3793 m_inDoSelectProperty
= 0;
3798 // First, deactivate previous
3801 OnValidationFailureReset(prevFirstSel
);
3803 // Must double-check if this is an selected in case of forceswitch
3804 if ( p
!= prevFirstSel
)
3806 if ( !CommitChangesFromEditor(flags
) )
3808 // Validation has failed, so we can't exit the previous editor
3809 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3810 // _("Invalid Value"),wxOK|wxICON_ERROR);
3811 m_inDoSelectProperty
= 0;
3818 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3819 EditorsValueWasNotModified();
3822 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3824 m_pState
->DoSetSelection(p
);
3826 // Redraw unselected
3827 for ( unsigned int i
=0; i
<prevSelection
.size(); i
++ )
3829 DrawItem(prevSelection
[i
]);
3833 // Then, activate the one given.
3836 int propY
= p
->GetY2(m_lineHeight
);
3838 int splitterX
= GetSplitterPosition();
3839 m_editorFocused
= 0;
3840 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3841 if ( p
!= prevFirstSel
)
3842 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3844 wxASSERT( m_wndEditor
== NULL
);
3847 // Only create editor for non-disabled non-caption
3848 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3850 // do this for non-caption items
3854 // Do we need to paint the custom image, if any?
3855 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3856 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3857 !p
->GetEditorClass()->CanContainCustomImage()
3859 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3861 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3862 wxPoint goodPos
= grect
.GetPosition();
3864 const wxPGEditor
* editor
= p
->GetEditorClass();
3865 wxCHECK_MSG(editor
, false,
3866 wxT("NULL editor class not allowed"));
3868 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3870 wxPGWindowList wndList
= editor
->CreateControls(this,
3875 m_wndEditor
= wndList
.m_primary
;
3876 m_wndEditor2
= wndList
.m_secondary
;
3877 wxWindow
* primaryCtrl
= GetEditorControl();
3880 // Essentially, primaryCtrl == m_wndEditor
3883 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3884 // value is drawn as normal, and m_wndEditor2 is assumed
3885 // to be a right-aligned button that triggers a separate editorCtrl
3890 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3891 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3893 // Set validator, if any
3894 #if wxUSE_VALIDATORS
3895 wxValidator
* validator
= p
->GetValidator();
3897 primaryCtrl
->SetValidator(*validator
);
3900 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3901 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3903 // If it has modified status, use bold font
3904 // (must be done before capturing m_ctrlXAdjust)
3905 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3906 SetCurControlBoldFont();
3908 // Store x relative to splitter (we'll need it).
3909 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3911 // Check if background clear is not necessary
3912 wxPoint pos
= m_wndEditor
->GetPosition();
3913 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3915 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3918 m_wndEditor
->SetSizeHints(3, 3);
3920 SetupChildEventHandling(primaryCtrl
);
3922 // Focus and select all (wxTextCtrl, wxComboBox etc)
3923 if ( flags
& wxPG_SEL_FOCUS
)
3925 primaryCtrl
->SetFocus();
3927 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3933 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3934 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3936 // Get proper id for wndSecondary
3937 m_wndSecId
= m_wndEditor2
->GetId();
3938 wxWindowList children
= m_wndEditor2
->GetChildren();
3939 wxWindowList::iterator node
= children
.begin();
3940 if ( node
!= children
.end() )
3941 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3943 m_wndEditor2
->SetSizeHints(3,3);
3945 m_wndEditor2
->Show();
3947 SetupChildEventHandling(m_wndEditor2
);
3949 // If no primary editor, focus to button to allow
3950 // it to interprete ENTER etc.
3951 // NOTE: Due to problems focusing away from it, this
3952 // has been disabled.
3954 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3955 m_wndEditor2->SetFocus();
3959 if ( flags
& wxPG_SEL_FOCUS
)
3960 m_editorFocused
= 1;
3965 // Make sure focus is in grid canvas (important for wxGTK, at least)
3969 EditorsValueWasNotModified();
3971 // If it's inside collapsed section, expand parent, scroll, etc.
3972 // Also, if it was partially visible, scroll it into view.
3973 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3978 m_wndEditor
->Show(true);
3981 if ( !(flags
& wxPG_SEL_NO_REFRESH
) )
3986 // Make sure focus is in grid canvas
3990 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3996 // Show help text in status bar.
3997 // (if found and grid not embedded in manager with help box and
3998 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
4001 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
4003 wxStatusBar
* statusbar
= NULL
;
4004 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
4006 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
4008 statusbar
= frame
->GetStatusBar();
4013 const wxString
* pHelpString
= (const wxString
*) NULL
;
4017 pHelpString
= &p
->GetHelpString();
4018 if ( pHelpString
->length() )
4020 // Set help box text.
4021 statusbar
->SetStatusText( *pHelpString
);
4022 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
4026 if ( (!pHelpString
|| !pHelpString
->length()) &&
4027 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
4029 // Clear help box - but only if it was written
4030 // by us at previous time.
4031 statusbar
->SetStatusText( m_emptyString
);
4032 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
4038 m_inDoSelectProperty
= 0;
4040 // call wx event handler (here so that it also occurs on deselection)
4041 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
4042 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
);
4047 // -----------------------------------------------------------------------
4049 bool wxPropertyGrid::UnfocusEditor()
4051 wxPGProperty
* selected
= GetSelection();
4053 if ( !selected
|| !m_wndEditor
|| m_frozen
)
4056 if ( !CommitChangesFromEditor(0) )
4065 // -----------------------------------------------------------------------
4067 void wxPropertyGrid::RefreshEditor()
4069 wxPGProperty
* p
= GetSelection();
4073 wxWindow
* wnd
= GetEditorControl();
4077 // Set editor font boldness - must do this before
4078 // calling UpdateControl().
4079 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
4081 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
4082 wnd
->SetFont(GetCaptionFont());
4084 wnd
->SetFont(GetFont());
4087 const wxPGEditor
* editorClass
= p
->GetEditorClass();
4089 editorClass
->UpdateControl(p
, wnd
);
4091 if ( p
->IsValueUnspecified() )
4092 editorClass
->SetValueToUnspecified(p
, wnd
);
4095 // -----------------------------------------------------------------------
4097 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
4099 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
4101 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
4103 flags
|= wxPG_SEL_FOCUS
;
4105 return DoSelectProperty(p
, flags
);
4108 // -----------------------------------------------------------------------
4109 // wxPropertyGrid expand/collapse state
4110 // -----------------------------------------------------------------------
4112 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
4114 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
4115 wxPGProperty
* selected
= GetSelection();
4117 // If active editor was inside collapsed section, then disable it
4118 if ( selected
&& selected
->IsSomeParent(p
) )
4123 // Store dont-center-splitter flag 'cause we need to temporarily set it
4124 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
4125 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4127 bool res
= m_pState
->DoCollapse(pwc
);
4132 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
4134 RecalculateVirtualSize();
4136 // Redraw etc. only if collapsed was visible.
4137 if (pwc
->IsVisible() &&
4139 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
4141 // When item is collapsed so that scrollbar would move,
4142 // graphics mess is about (unless we redraw everything).
4147 // Clear dont-center-splitter flag if it wasn't set
4148 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4153 // -----------------------------------------------------------------------
4155 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
4157 wxCHECK_MSG( p
, false, wxT("invalid property id") );
4159 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4161 // Store dont-center-splitter flag 'cause we need to temporarily set it
4162 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
4163 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4165 bool res
= m_pState
->DoExpand(pwc
);
4170 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4172 RecalculateVirtualSize();
4174 // Redraw etc. only if expanded was visible.
4175 if ( pwc
->IsVisible() && !m_frozen
&&
4176 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
4180 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4183 DrawItems(pwc
, NULL
);
4188 // Clear dont-center-splitter flag if it wasn't set
4189 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4194 // -----------------------------------------------------------------------
4196 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4199 return m_pState
->DoHideProperty(p
, hide
, flags
);
4201 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
4202 int selRemoveCount
= 0;
4203 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
4205 wxPGProperty
* selected
= selection
[i
];
4206 if ( selected
== p
|| selected
->IsSomeParent(p
) )
4208 if ( !DoRemoveFromSelection(p
, flags
) )
4210 selRemoveCount
+= 1;
4214 m_pState
->DoHideProperty(p
, hide
, flags
);
4216 RecalculateVirtualSize();
4223 // -----------------------------------------------------------------------
4224 // wxPropertyGrid size related methods
4225 // -----------------------------------------------------------------------
4227 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4229 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4233 // If virtual height was changed, then recalculate editor control position(s)
4234 if ( m_pState
->m_vhCalcPending
)
4235 CorrectEditorWidgetPosY();
4237 m_pState
->EnsureVirtualHeight();
4239 wxASSERT_LEVEL_2_MSG(
4240 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
4241 "VirtualHeight and ActualVirtualHeight should match"
4244 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4246 int x
= m_pState
->m_width
;
4247 int y
= m_pState
->m_virtualHeight
;
4250 GetClientSize(&width
,&height
);
4252 // Now adjust virtual size.
4253 SetVirtualSize(x
, y
);
4259 // Adjust scrollbars
4260 if ( HasVirtualWidth() )
4262 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4263 xPos
= GetScrollPos( wxHORIZONTAL
);
4266 if ( forceXPos
!= -1 )
4269 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4272 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4273 int yPos
= GetScrollPos( wxVERTICAL
);
4275 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4276 xAmount
, yAmount
, xPos
, yPos
, true );
4278 // Must re-get size now
4279 GetClientSize(&width
,&height
);
4281 if ( !HasVirtualWidth() )
4283 m_pState
->SetVirtualWidth(width
);
4290 // Explicitly pass the position - works around a bug in wxWidgets when the property grid
4291 // has a native XP border and a contained window creeps up-and-left when size is set without
4293 m_canvas
->SetSize( 0, 0, x
, y
);
4295 m_pState
->CheckColumnWidths();
4297 if ( GetSelection() )
4298 CorrectEditorWidgetSizeX();
4300 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4303 // -----------------------------------------------------------------------
4305 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4307 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4311 GetClientSize(&width
,&height
);
4316 #if wxPG_DOUBLE_BUFFER
4317 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4319 int dblh
= (m_lineHeight
*2);
4320 if ( !m_doubleBuffer
)
4322 // Create double buffer bitmap to draw on, if none
4323 int w
= (width
>250)?width
:250;
4324 int h
= height
+ dblh
;
4326 m_doubleBuffer
= new wxBitmap( w
, h
);
4330 int w
= m_doubleBuffer
->GetWidth();
4331 int h
= m_doubleBuffer
->GetHeight();
4333 // Double buffer must be large enough
4334 if ( w
< width
|| h
< (height
+dblh
) )
4336 if ( w
< width
) w
= width
;
4337 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4338 delete m_doubleBuffer
;
4339 m_doubleBuffer
= new wxBitmap( w
, h
);
4346 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4347 m_ncWidth
= event
.GetSize().x
;
4351 if ( m_pState
->m_itemsAdded
)
4352 PrepareAfterItemsAdded();
4354 // Without this, virtual size (atleast under wxGTK) will be skewed
4355 RecalculateVirtualSize();
4361 // -----------------------------------------------------------------------
4363 void wxPropertyGrid::SetVirtualWidth( int width
)
4367 // Disable virtual width
4368 width
= GetClientSize().x
;
4369 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4373 // Enable virtual width
4374 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4376 m_pState
->SetVirtualWidth( width
);
4379 void wxPropertyGrid::SetFocusOnCanvas()
4381 m_canvas
->SetFocusIgnoringChildren();
4382 m_editorFocused
= 0;
4385 // -----------------------------------------------------------------------
4386 // wxPropertyGrid mouse event handling
4387 // -----------------------------------------------------------------------
4389 // selFlags uses same values DoSelectProperty's flags
4390 // Returns true if event was vetoed.
4391 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
,
4393 unsigned int selFlags
,
4394 unsigned int column
)
4396 // Send property grid event of specific type and with specific property
4397 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4398 evt
.SetPropertyGrid(this);
4399 evt
.SetEventObject(m_eventObject
);
4401 evt
.SetColumn(column
);
4404 evt
.SetCanVeto(true);
4405 evt
.SetupValidationInfo();
4406 m_validationInfo
.m_pValue
= pValue
;
4408 else if ( !(selFlags
& wxPG_SEL_NOVALIDATE
) )
4410 evt
.SetCanVeto(true);
4413 m_processedEvent
= &evt
;
4415 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4417 m_processedEvent
= NULL
;
4419 evtHandler
->ProcessEvent(evt
);
4421 return evt
.WasVetoed();
4424 // -----------------------------------------------------------------------
4426 // Return false if should be skipped
4427 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4431 // Need to set focus?
4432 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4437 wxPropertyGridPageState
* state
= m_pState
;
4439 int splitterHitOffset
;
4440 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4442 wxPGProperty
* p
= DoGetItemAtY(y
);
4446 int depth
= (int)p
->GetDepth() - 1;
4448 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4450 if ( x
>= marginEnds
)
4454 if ( p
->IsCategory() )
4456 // This is category.
4457 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4459 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4461 // Expand, collapse, activate etc. if click on text or left of splitter.
4464 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4469 if ( !AddToSelectionFromInputEvent( p
,
4474 // On double-click, expand/collapse.
4475 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4477 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4478 else DoExpand( p
, true );
4482 else if ( splitterHit
== -1 )
4485 unsigned int selFlag
= 0;
4486 if ( columnHit
== 1 )
4488 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4489 selFlag
= wxPG_SEL_FOCUS
;
4491 if ( !AddToSelectionFromInputEvent( p
,
4497 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4499 if ( p
->GetChildCount() && !p
->IsCategory() )
4500 // On double-click, expand/collapse.
4501 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4503 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4504 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4505 else DoExpand( p
, true );
4512 // click on splitter
4513 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4515 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4517 // Double-clicking the splitter causes auto-centering
4518 CenterSplitter( true );
4520 else if ( m_dragStatus
== 0 )
4523 // Begin draggin the splitter
4527 DoEndLabelEdit(true, wxPG_SEL_NOVALIDATE
);
4531 // Changes must be committed here or the
4532 // value won't be drawn correctly
4533 if ( !CommitChangesFromEditor() )
4536 m_wndEditor
->Show ( false );
4539 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4541 m_canvas
->CaptureMouse();
4542 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4546 m_draggedSplitter
= splitterHit
;
4547 m_dragOffset
= splitterHitOffset
;
4549 wxClientDC
dc(m_canvas
);
4551 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4552 // Fixes button disappearance bug
4554 m_wndEditor2
->Show ( false );
4557 m_startingSplitterX
= x
- splitterHitOffset
;
4565 if ( p
->GetChildCount() )
4567 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4569 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4571 int y2
= y
% m_lineHeight
;
4572 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4574 // On click on expander button, expand/collapse
4575 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4576 DoCollapse( p
, true );
4578 DoExpand( p
, true );
4587 // -----------------------------------------------------------------------
4589 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4590 unsigned int WXUNUSED(y
),
4591 wxMouseEvent
& event
)
4595 // Select property here as well
4596 wxPGProperty
* p
= m_propHover
;
4597 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4599 // Send right click event.
4600 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4607 // -----------------------------------------------------------------------
4609 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4610 unsigned int WXUNUSED(y
),
4611 wxMouseEvent
& event
)
4615 // Select property here as well
4616 wxPGProperty
* p
= m_propHover
;
4618 AddToSelectionFromInputEvent(p
, m_colHover
, &event
);
4620 // Send double-click event.
4621 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4628 // -----------------------------------------------------------------------
4630 #if wxPG_SUPPORT_TOOLTIPS
4632 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4634 if ( tipString
.length() )
4636 m_canvas
->SetToolTip(tipString
);
4640 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4641 m_canvas
->SetToolTip( m_emptyString
);
4643 m_canvas
->SetToolTip( NULL
);
4648 #endif // #if wxPG_SUPPORT_TOOLTIPS
4650 // -----------------------------------------------------------------------
4652 // Return false if should be skipped
4653 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4655 // Safety check (needed because mouse capturing may
4656 // otherwise freeze the control)
4657 if ( m_dragStatus
> 0 && !event
.Dragging() )
4659 HandleMouseUp(x
,y
,event
);
4662 wxPropertyGridPageState
* state
= m_pState
;
4664 int splitterHitOffset
;
4665 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4666 int splitterX
= x
- splitterHitOffset
;
4668 m_colHover
= columnHit
;
4670 if ( m_dragStatus
> 0 )
4672 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4673 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4676 int newSplitterX
= x
- m_dragOffset
;
4677 int splitterX
= x
- splitterHitOffset
;
4679 // Splitter redraw required?
4680 if ( newSplitterX
!= splitterX
)
4683 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4684 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4685 state
->m_fSplitterX
= (float) newSplitterX
;
4687 if ( GetSelection() )
4688 CorrectEditorWidgetSizeX();
4702 int ih
= m_lineHeight
;
4705 #if wxPG_SUPPORT_TOOLTIPS
4706 wxPGProperty
* prevHover
= m_propHover
;
4707 unsigned char prevSide
= m_mouseSide
;
4709 int curPropHoverY
= y
- (y
% ih
);
4711 // On which item it hovers
4714 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4717 // Mouse moves on another property
4719 m_propHover
= DoGetItemAtY(y
);
4720 m_propHoverY
= curPropHoverY
;
4723 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4726 #if wxPG_SUPPORT_TOOLTIPS
4727 // Store which side we are on
4729 if ( columnHit
== 1 )
4731 else if ( columnHit
== 0 )
4735 // If tooltips are enabled, show label or value as a tip
4736 // in case it doesn't otherwise show in full length.
4738 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4740 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4742 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4744 if ( m_propHover
&& !m_propHover
->IsCategory() )
4747 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4749 // Show help string as a tooltip
4750 wxString tipString
= m_propHover
->GetHelpString();
4752 SetToolTip(tipString
);
4756 // Show cropped value string as a tooltip
4760 if ( m_mouseSide
== 1 )
4762 tipString
= m_propHover
->m_label
;
4763 space
= splitterX
-m_marginWidth
-3;
4765 else if ( m_mouseSide
== 2 )
4767 tipString
= m_propHover
->GetDisplayedString();
4769 space
= m_width
- splitterX
;
4770 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4771 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4777 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4780 SetToolTip( tipString
);
4787 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4788 m_canvas
->SetToolTip( m_emptyString
);
4790 m_canvas
->SetToolTip( NULL
);
4801 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4802 m_canvas
->SetToolTip( m_emptyString
);
4804 m_canvas
->SetToolTip( NULL
);
4812 if ( splitterHit
== -1 ||
4814 HasFlag(wxPG_STATIC_SPLITTER
) )
4816 // hovering on something else
4817 if ( m_curcursor
!= wxCURSOR_ARROW
)
4818 CustomSetCursor( wxCURSOR_ARROW
);
4822 // Do not allow splitter cursor on caption items.
4823 // (also not if we were dragging and its started
4824 // outside the splitter region)
4826 if ( !m_propHover
->IsCategory() &&
4830 // hovering on splitter
4832 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4833 // reliably detected.
4834 //if ( m_curcursor != wxCURSOR_SIZEWE )
4835 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4841 // hovering on something else
4842 if ( m_curcursor
!= wxCURSOR_ARROW
)
4843 CustomSetCursor( wxCURSOR_ARROW
);
4848 // Multi select by dragging
4850 if ( (GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) &&
4851 event
.LeftIsDown() &&
4855 !state
->DoIsPropertySelected(m_propHover
) )
4857 // Additional requirement is that the hovered property
4858 // is adjacent to edges of selection.
4859 const wxArrayPGProperty
& selection
= GetSelectedProperties();
4861 // Since categories cannot be selected along with 'other'
4862 // properties, exclude them from iterator flags.
4863 int iterFlags
= wxPG_ITERATE_VISIBLE
& (~wxPG_PROP_CATEGORY
);
4865 for ( int i
=(selection
.size()-1); i
>=0; i
-- )
4867 // TODO: This could be optimized by keeping track of
4868 // which properties are at the edges of selection.
4869 wxPGProperty
* selProp
= selection
[i
];
4870 if ( state
->ArePropertiesAdjacent(m_propHover
, selProp
,
4873 DoAddToSelection(m_propHover
);
4882 // -----------------------------------------------------------------------
4884 // Also handles Leaving event
4885 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4886 wxMouseEvent
&WXUNUSED(event
) )
4888 wxPropertyGridPageState
* state
= m_pState
;
4892 int splitterHitOffset
;
4893 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4895 // No event type check - basicly calling this method should
4896 // just stop dragging.
4897 // Left up after dragged?
4898 if ( m_dragStatus
>= 1 )
4901 // End Splitter Dragging
4903 // DO NOT ENABLE FOLLOWING LINE!
4904 // (it is only here as a reminder to not to do it)
4907 // Disable splitter auto-centering
4908 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4910 // This is necessary to return cursor
4911 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4913 m_canvas
->ReleaseMouse();
4914 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4917 // Set back the default cursor, if necessary
4918 if ( splitterHit
== -1 ||
4921 CustomSetCursor( wxCURSOR_ARROW
);
4926 // Control background needs to be cleared
4927 wxPGProperty
* selected
= GetSelection();
4928 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
4929 DrawItem( selected
);
4933 m_wndEditor
->Show ( true );
4936 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4937 // Fixes button disappearance bug
4939 m_wndEditor2
->Show ( true );
4942 // This clears the focus.
4943 m_editorFocused
= 0;
4949 // -----------------------------------------------------------------------
4951 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4953 int splitterX
= GetSplitterPosition();
4956 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4960 wxWindow
* wnd
= GetEditorControl();
4962 // Hide popup on clicks
4963 if ( event
.GetEventType() != wxEVT_MOTION
)
4964 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4966 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4972 if ( wnd
== NULL
|| m_dragStatus
||
4974 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4975 ux
>= (r
.x
+r
.width
) ||
4977 event
.m_y
>= (r
.y
+r
.height
)
4987 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4992 // -----------------------------------------------------------------------
4994 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4997 if ( OnMouseCommon( event
, &x
, &y
) )
4999 HandleMouseClick(x
,y
,event
);
5004 // -----------------------------------------------------------------------
5006 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
5009 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5010 HandleMouseRightClick(x
,y
,event
);
5014 // -----------------------------------------------------------------------
5016 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
5018 // Always run standard mouse-down handler as well
5019 OnMouseClick(event
);
5022 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
5023 HandleMouseDoubleClick(x
,y
,event
);
5027 // -----------------------------------------------------------------------
5029 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
5032 if ( OnMouseCommon( event
, &x
, &y
) )
5034 HandleMouseMove(x
,y
,event
);
5039 // -----------------------------------------------------------------------
5041 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
5043 // Called when mouse moves in the empty space below the properties.
5044 CustomSetCursor( wxCURSOR_ARROW
);
5047 // -----------------------------------------------------------------------
5049 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
5052 if ( OnMouseCommon( event
, &x
, &y
) )
5054 HandleMouseUp(x
,y
,event
);
5059 // -----------------------------------------------------------------------
5061 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
5063 // This may get called from child control as well, so event's
5064 // mouse position cannot be relied on.
5066 if ( event
.Entering() )
5068 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5070 // TODO: Fix this (detect parent and only do
5071 // cursor trick if it is a manager).
5072 wxASSERT( GetParent() );
5073 GetParent()->SetCursor(wxNullCursor
);
5075 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
5078 GetParent()->SetCursor(wxNullCursor
);
5080 else if ( event
.Leaving() )
5082 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
5083 m_canvas
->SetCursor( wxNullCursor
);
5085 // Get real cursor position
5086 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
5088 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
5091 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
5093 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
5097 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
5105 // -----------------------------------------------------------------------
5107 // Common code used by various OnMouseXXXChild methods.
5108 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
5110 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
5111 wxASSERT( topCtrlWnd
);
5113 event
.GetPosition(&x
,&y
);
5115 int splitterX
= GetSplitterPosition();
5117 wxRect r
= topCtrlWnd
->GetRect();
5118 if ( !m_dragStatus
&&
5119 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
5120 y
>= 0 && y
< r
.height \
5123 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
5128 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
5135 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
5138 if ( OnMouseChildCommon(event
,&x
,&y
) )
5140 bool res
= HandleMouseClick(x
,y
,event
);
5141 if ( !res
) event
.Skip();
5145 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
5148 wxASSERT( m_wndEditor
);
5149 // These coords may not be exact (about +-2),
5150 // but that should not matter (right click is about item, not position).
5151 wxPoint pt
= m_wndEditor
->GetPosition();
5152 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
5154 // FIXME: Used to set m_propHover to selection here. Was it really
5157 bool res
= HandleMouseRightClick(x
,y
,event
);
5158 if ( !res
) event
.Skip();
5161 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
5164 if ( OnMouseChildCommon(event
,&x
,&y
) )
5166 bool res
= HandleMouseMove(x
,y
,event
);
5167 if ( !res
) event
.Skip();
5171 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
5174 if ( OnMouseChildCommon(event
,&x
,&y
) )
5176 bool res
= HandleMouseUp(x
,y
,event
);
5177 if ( !res
) event
.Skip();
5181 // -----------------------------------------------------------------------
5182 // wxPropertyGrid keyboard event handling
5183 // -----------------------------------------------------------------------
5185 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
5187 // Translates wxKeyEvent to wxPG_ACTION_XXX
5189 int keycode
= event
.GetKeyCode();
5190 int modifiers
= event
.GetModifiers();
5192 wxASSERT( !(modifiers
&~(0xFFFF)) );
5194 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5196 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
5198 if ( it
== m_actionTriggers
.end() )
5203 int second
= (it
->second
>>16) & 0xFFFF;
5207 return (it
->second
& 0xFFFF);
5210 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
5212 wxASSERT( !(modifiers
&~(0xFFFF)) );
5214 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
5216 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5218 if ( it
!= m_actionTriggers
.end() )
5220 // This key combination is already used
5222 // Can add secondary?
5223 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5224 wxT("You can only add up to two separate actions per key combination.") );
5226 action
= it
->second
| (action
<<16);
5229 m_actionTriggers
[hashMapKey
] = action
;
5232 void wxPropertyGrid::ClearActionTriggers( int action
)
5234 wxPGHashMapI2I::iterator it
;
5239 didSomething
= false;
5241 for ( it
= m_actionTriggers
.begin();
5242 it
!= m_actionTriggers
.end();
5245 if ( it
->second
== action
)
5247 m_actionTriggers
.erase(it
);
5248 didSomething
= true;
5253 while ( didSomething
);
5256 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
5259 // Handles key event when editor control is not focused.
5262 wxCHECK2(!m_frozen
, return);
5264 // Travelsal between items, collapsing/expanding, etc.
5265 wxPGProperty
* selected
= GetSelection();
5266 int keycode
= event
.GetKeyCode();
5267 bool editorFocused
= IsEditorFocused();
5269 if ( keycode
== WXK_TAB
)
5271 wxWindow
* mainControl
;
5273 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
5274 mainControl
= GetParent();
5278 if ( !event
.ShiftDown() )
5280 if ( !editorFocused
&& m_wndEditor
)
5282 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
5286 // Tab traversal workaround for platforms on which
5287 // wxWindow::Navigate() may navigate into first child
5288 // instead of next sibling. Does not work perfectly
5289 // in every scenario (for instance, when property grid
5290 // is either first or last control).
5291 #if defined(__WXGTK__)
5292 wxWindow
* sibling
= mainControl
->GetNextSibling();
5294 sibling
->SetFocusFromKbd();
5296 Navigate(wxNavigationKeyEvent::IsForward
);
5302 if ( editorFocused
)
5308 #if defined(__WXGTK__)
5309 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5311 sibling
->SetFocusFromKbd();
5313 Navigate(wxNavigationKeyEvent::IsBackward
);
5321 // Ignore Alt and Control when they are down alone
5322 if ( keycode
== WXK_ALT
||
5323 keycode
== WXK_CONTROL
)
5330 int action
= KeyEventToActions(event
, &secondAction
);
5332 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5335 // Esc cancels any changes
5336 if ( IsEditorsValueModified() )
5338 EditorsValueWasNotModified();
5340 // Update the control as well
5341 selected
->GetEditorClass()->
5342 SetControlStringValue( selected
,
5344 selected
->GetDisplayedString() );
5347 OnValidationFailureReset(selected
);
5353 // Except for TAB and ESC, handle child control events in child control
5356 // Only propagate event if it had modifiers
5357 if ( !event
.HasModifiers() )
5359 event
.StopPropagation();
5365 bool wasHandled
= false;
5370 if ( ButtonTriggerKeyTest(action
, event
) )
5373 wxPGProperty
* p
= selected
;
5375 // Travel and expand/collapse
5378 if ( p
->GetChildCount() )
5380 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5382 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5385 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5387 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5394 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5398 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5404 if ( selectDir
>= -1 )
5406 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5408 DoSelectProperty(p
);
5414 // If nothing was selected, select the first item now
5415 // (or navigate out of tab).
5416 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5418 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5419 if ( p
) DoSelectProperty(p
);
5428 // -----------------------------------------------------------------------
5430 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5432 // If there was editor open and focused, then this event should not
5433 // really be processed here.
5434 if ( IsEditorFocused() )
5436 // However, if event had modifiers, it is probably still best
5438 if ( event
.HasModifiers() )
5441 event
.StopPropagation();
5445 HandleKeyEvent(event
, false);
5448 // -----------------------------------------------------------------------
5450 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5455 action
= KeyEventToActions(event
, &secondAction
);
5458 // Does the keycode trigger button?
5459 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5462 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5463 GetEventHandler()->AddPendingEvent(evt
);
5470 // -----------------------------------------------------------------------
5472 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5474 HandleKeyEvent(event
, true);
5477 // -----------------------------------------------------------------------
5478 // wxPropertyGrid miscellaneous event handling
5479 // -----------------------------------------------------------------------
5481 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5484 // Check if the focus is in this control or one of its children
5485 wxWindow
* newFocused
= wxWindow::FindFocus();
5487 if ( newFocused
!= m_curFocused
)
5488 HandleFocusChange( newFocused
);
5491 // Check if top-level parent has changed
5492 if ( GetExtraStyle() & wxPG_EX_ENABLE_TLP_TRACKING
)
5494 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5500 bool wxPropertyGrid::IsEditorFocused() const
5502 wxWindow
* focus
= wxWindow::FindFocus();
5504 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5505 focus
== GetEditorControl() )
5511 // Called by focus event handlers. newFocused is the window that becomes focused.
5512 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5514 unsigned int oldFlags
= m_iFlags
;
5516 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5518 wxWindow
* parent
= newFocused
;
5520 // This must be one of nextFocus' parents.
5523 // Use m_eventObject, which is either wxPropertyGrid or
5524 // wxPropertyGridManager, as appropriate.
5525 if ( parent
== m_eventObject
)
5527 m_iFlags
|= wxPG_FL_FOCUSED
;
5530 parent
= parent
->GetParent();
5533 m_curFocused
= newFocused
;
5535 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5536 (oldFlags
& wxPG_FL_FOCUSED
) )
5538 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5540 // Need to store changed value
5541 CommitChangesFromEditor();
5547 // Preliminary code for tab-order respecting
5548 // tab-traversal (but should be moved to
5551 wxWindow* prevFocus = event.GetWindow();
5552 wxWindow* useThis = this;
5553 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5554 useThis = GetParent();
5557 prevFocus->GetParent() == useThis->GetParent() )
5559 wxList& children = useThis->GetParent()->GetChildren();
5561 wxNode* node = children.Find(prevFocus);
5563 if ( node->GetNext() &&
5564 useThis == node->GetNext()->GetData() )
5565 DoSelectProperty(GetFirst());
5566 else if ( node->GetPrevious () &&
5567 useThis == node->GetPrevious()->GetData() )
5568 DoSelectProperty(GetLastProperty());
5575 wxPGProperty
* selected
= GetSelection();
5576 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5577 DrawItem( selected
);
5581 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5583 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5584 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5585 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5586 //else if ( event.GetWindow() )
5588 HandleFocusChange(event
.GetWindow());
5593 // -----------------------------------------------------------------------
5595 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5597 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5601 // -----------------------------------------------------------------------
5603 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5605 m_iFlags
|= wxPG_FL_SCROLLED
;
5610 // -----------------------------------------------------------------------
5612 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5614 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5616 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5620 // -----------------------------------------------------------------------
5621 // Property editor related functions
5622 // -----------------------------------------------------------------------
5624 // noDefCheck = true prevents infinite recursion.
5625 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5626 const wxString
& editorName
,
5629 wxASSERT( editorClass
);
5631 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5632 RegisterDefaultEditors();
5634 wxString name
= editorName
;
5635 if ( name
.length() == 0 )
5636 name
= editorClass
->GetName();
5638 // Existing editor under this name?
5639 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5641 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5643 // If this name was already used, try class name.
5644 name
= editorClass
->GetClassInfo()->GetClassName();
5645 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5648 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5649 (wxPGEditor
*) vt_it
->second
,
5650 "Editor with given name was already registered" );
5652 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5657 // Use this in RegisterDefaultEditors.
5658 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5659 if ( wxPGEditor_##EDITOR == NULL ) \
5661 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5662 new wxPG##EDITOR##Editor, true ); \
5665 // Registers all default editor classes
5666 void wxPropertyGrid::RegisterDefaultEditors()
5668 wxPGRegisterDefaultEditorClass( TextCtrl
);
5669 wxPGRegisterDefaultEditorClass( Choice
);
5670 wxPGRegisterDefaultEditorClass( ComboBox
);
5671 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5672 #if wxPG_INCLUDE_CHECKBOX
5673 wxPGRegisterDefaultEditorClass( CheckBox
);
5675 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5677 // Register SpinCtrl etc. editors before use
5678 RegisterAdditionalEditors();
5681 // -----------------------------------------------------------------------
5682 // wxPGStringTokenizer
5683 // Needed to handle C-style string lists (e.g. "str1" "str2")
5684 // -----------------------------------------------------------------------
5686 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5687 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5691 wxPGStringTokenizer::~wxPGStringTokenizer()
5695 bool wxPGStringTokenizer::HasMoreTokens()
5697 const wxString
& str
= *m_str
;
5699 wxString::const_iterator i
= m_curPos
;
5701 wxUniChar delim
= m_delimeter
;
5703 wxUniChar prev_a
= wxT('\0');
5705 bool inToken
= false;
5707 while ( i
!= str
.end() )
5716 m_readyToken
.clear();
5721 if ( prev_a
!= wxT('\\') )
5725 if ( a
!= wxT('\\') )
5745 m_curPos
= str
.end();
5753 wxString
wxPGStringTokenizer::GetNextToken()
5755 return m_readyToken
;
5758 // -----------------------------------------------------------------------
5760 // -----------------------------------------------------------------------
5762 wxPGChoiceEntry::wxPGChoiceEntry()
5763 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5767 // -----------------------------------------------------------------------
5769 // -----------------------------------------------------------------------
5771 wxPGChoicesData::wxPGChoicesData()
5775 wxPGChoicesData::~wxPGChoicesData()
5780 void wxPGChoicesData::Clear()
5785 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5787 wxASSERT( m_items
.size() == 0 );
5789 m_items
= data
->m_items
;
5792 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5793 const wxPGChoiceEntry
& item
)
5795 wxVector
<wxPGChoiceEntry
>::iterator it
;
5799 index
= (int) m_items
.size();
5803 it
= m_items
.begin() + index
;
5806 m_items
.insert(it
, item
);
5808 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5810 // Need to fix value?
5811 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5812 ownEntry
.SetValue(index
);
5817 // -----------------------------------------------------------------------
5818 // wxPropertyGridEvent
5819 // -----------------------------------------------------------------------
5821 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5824 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5825 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5826 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5827 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5828 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5829 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5830 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5831 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5832 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5833 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_BEGIN
, wxPropertyGridEvent
);
5834 wxDEFINE_EVENT( wxEVT_PG_LABEL_EDIT_ENDING
, wxPropertyGridEvent
);
5836 // -----------------------------------------------------------------------
5838 void wxPropertyGridEvent::Init()
5840 m_validationInfo
= NULL
;
5843 m_wasVetoed
= false;
5846 // -----------------------------------------------------------------------
5848 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5849 : wxCommandEvent(commandType
,id
)
5855 // -----------------------------------------------------------------------
5857 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5858 : wxCommandEvent(event
)
5860 m_eventType
= event
.GetEventType();
5861 m_eventObject
= event
.m_eventObject
;
5863 m_property
= event
.m_property
;
5864 m_validationInfo
= event
.m_validationInfo
;
5865 m_canVeto
= event
.m_canVeto
;
5866 m_wasVetoed
= event
.m_wasVetoed
;
5869 // -----------------------------------------------------------------------
5871 wxPropertyGridEvent::~wxPropertyGridEvent()
5875 // -----------------------------------------------------------------------
5877 wxEvent
* wxPropertyGridEvent::Clone() const
5879 return new wxPropertyGridEvent( *this );
5882 // -----------------------------------------------------------------------
5883 // wxPropertyGridPopulator
5884 // -----------------------------------------------------------------------
5886 wxPropertyGridPopulator::wxPropertyGridPopulator()
5890 wxPGGlobalVars
->m_offline
++;
5893 // -----------------------------------------------------------------------
5895 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5898 m_propHierarchy
.clear();
5901 // -----------------------------------------------------------------------
5903 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5909 // -----------------------------------------------------------------------
5911 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5914 // Free unused sets of choices
5915 wxPGHashMapS2P::iterator it
;
5917 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5919 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5926 m_pg
->GetPanel()->Refresh();
5928 wxPGGlobalVars
->m_offline
--;
5931 // -----------------------------------------------------------------------
5933 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5934 const wxString
& propLabel
,
5935 const wxString
& propName
,
5936 const wxString
* propValue
,
5937 wxPGChoices
* pChoices
)
5939 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5940 wxPGProperty
* parent
= GetCurParent();
5942 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5944 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5948 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5950 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5954 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5956 property
->SetLabel(propLabel
);
5957 property
->DoSetName(propName
);
5959 if ( pChoices
&& pChoices
->IsOk() )
5960 property
->SetChoices(*pChoices
);
5962 m_state
->DoInsert(parent
, -1, property
);
5965 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5966 wxPG_PROGRAMMATIC_VALUE
);
5971 // -----------------------------------------------------------------------
5973 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5975 m_propHierarchy
.push_back(property
);
5976 DoScanForChildren();
5977 m_propHierarchy
.pop_back();
5980 // -----------------------------------------------------------------------
5982 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5983 const wxString
& idString
)
5985 wxPGChoices choices
;
5988 if ( choicesString
[0] == wxT('@') )
5990 wxString ids
= choicesString
.substr(1);
5991 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5992 if ( it
== m_dictIdChoices
.end() )
5993 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5995 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6000 if ( idString
.length() )
6002 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6003 if ( it
!= m_dictIdChoices
.end() )
6005 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6012 // Parse choices string
6013 wxString::const_iterator it
= choicesString
.begin();
6017 bool labelValid
= false;
6019 for ( ; it
!= choicesString
.end(); ++it
)
6025 if ( c
== wxT('"') )
6030 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6031 choices
.Add(label
, l
);
6034 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6039 else if ( c
== wxT('=') )
6046 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6053 if ( c
== wxT('"') )
6066 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6067 choices
.Add(label
, l
);
6070 if ( !choices
.IsOk() )
6072 choices
.EnsureData();
6076 if ( idString
.length() )
6077 m_dictIdChoices
[idString
] = choices
.GetData();
6084 // -----------------------------------------------------------------------
6086 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6088 if ( s
.Last() == wxT('%') )
6090 wxString s2
= s
.substr(0,s
.length()-1);
6092 if ( s2
.ToLong(&val
, 10) )
6094 *pval
= (val
*max
)/100;
6100 return s
.ToLong(pval
, 10);
6103 // -----------------------------------------------------------------------
6105 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6106 const wxString
& type
,
6107 const wxString
& value
)
6109 int l
= m_propHierarchy
.size();
6113 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6114 wxString valuel
= value
.Lower();
6117 if ( type
.length() == 0 )
6122 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6124 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6126 else if ( value
.ToLong(&v
, 0) )
6133 if ( type
== wxT("string") )
6137 else if ( type
== wxT("int") )
6140 value
.ToLong(&v
, 0);
6143 else if ( type
== wxT("bool") )
6145 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6152 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6157 p
->SetAttribute( name
, variant
);
6162 // -----------------------------------------------------------------------
6164 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6166 wxLogError(_("Error in resource: %s"),msg
.c_str());
6169 // -----------------------------------------------------------------------
6171 #endif // wxUSE_PROPGRID