1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
68 #include "wx/msw/private.h"
71 // Two pics for the expand / collapse buttons.
72 // Files are not supplied with this project (since it is
73 // recommended to use either custom or native rendering).
74 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
75 // and copy xpm files from archive to wxPropertyGrid src directory
76 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
77 // and set wxPG_USE_RENDERER_NATIVE to 0).
78 #ifndef wxPG_ICON_WIDTH
79 #if defined(__WXMAC__)
80 #include "mac_collapse.xpm"
81 #include "mac_expand.xpm"
82 #elif defined(__WXGTK__)
83 #include "linux_collapse.xpm"
84 #include "linux_expand.xpm"
86 #include "default_collapse.xpm"
87 #include "default_expand.xpm"
92 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
93 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
94 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
95 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
96 #define wxPG_YSPACING_MIN 1
97 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
98 // but causes normal combobox to spill out under MSW
100 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
102 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
103 // Must be larger than largest control border
107 #define wxPG_DEFAULT_CURSOR wxNullCursor
110 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
112 //#define wxPG_HIDER_BUTTON_HEIGHT 25
114 #define wxPG_PIXELS_PER_UNIT m_lineHeight
116 #ifdef wxPG_ICON_WIDTH
117 #define m_iconHeight m_iconWidth
120 //#define wxPG_TOOLTIP_DELAY 1000
122 // -----------------------------------------------------------------------
125 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
127 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
130 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
133 // -----------------------------------------------------------------------
135 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
137 // -----------------------------------------------------------------------
138 // Statics in one class for easy destruction.
139 // -----------------------------------------------------------------------
141 #include "wx/module.h"
143 class wxPGGlobalVarsClassManager
: public wxModule
145 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
147 wxPGGlobalVarsClassManager() {}
148 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
149 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
152 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
155 // When wxPG is loaded dynamically after the application is already running
156 // then the built-in module system won't pick this one up. Add it manually.
157 void wxPGInitResourceModule()
159 wxModule
* module = new wxPGGlobalVarsClassManager
;
161 wxModule::RegisterModule(module);
164 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
167 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
169 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
171 m_boolChoices
.Add(_("False"));
172 m_boolChoices
.Add(_("True"));
174 m_fontFamilyChoices
= NULL
;
176 m_defaultRenderer
= new wxPGDefaultRenderer();
178 m_autoGetTranslation
= false;
186 // Prepare some shared variants
187 m_vEmptyString
= wxString();
189 m_vMinusOne
= (long) -1;
193 // Prepare cached string constants
194 m_strstring
= wxS("string");
195 m_strlong
= wxS("long");
196 m_strbool
= wxS("bool");
197 m_strlist
= wxS("list");
198 m_strDefaultValue
= wxS("DefaultValue");
199 m_strMin
= wxS("Min");
200 m_strMax
= wxS("Max");
201 m_strUnits
= wxS("Units");
202 m_strInlineHelp
= wxS("InlineHelp");
208 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
212 delete m_defaultRenderer
;
214 // This will always have one ref
215 delete m_fontFamilyChoices
;
218 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
219 delete ((wxValidator
*)m_arrValidators
[i
]);
223 // Destroy value type class instances.
224 wxPGHashMapS2P::iterator vt_it
;
226 // Destroy editor class instances.
227 // iterate over all the elements in the class
228 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
230 delete ((wxPGEditor
*)vt_it
->second
);
233 delete wxPGProperty::sm_wxPG_LABEL
;
236 void wxPropertyGridInitGlobalsIfNeeded()
240 // -----------------------------------------------------------------------
242 // -----------------------------------------------------------------------
245 // wxPGCanvas acts as a graphics sub-window of the
246 // wxScrolledWindow that wxPropertyGrid is.
248 class wxPGCanvas
: public wxPanel
251 wxPGCanvas() : wxPanel()
254 virtual ~wxPGCanvas() { }
257 void OnMouseMove( wxMouseEvent
&event
)
259 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
260 pg
->OnMouseMove( event
);
263 void OnMouseClick( wxMouseEvent
&event
)
265 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
266 pg
->OnMouseClick( event
);
269 void OnMouseUp( wxMouseEvent
&event
)
271 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
272 pg
->OnMouseUp( event
);
275 void OnMouseRightClick( wxMouseEvent
&event
)
277 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
278 pg
->OnMouseRightClick( event
);
281 void OnMouseDoubleClick( wxMouseEvent
&event
)
283 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
284 pg
->OnMouseDoubleClick( event
);
287 void OnKey( wxKeyEvent
& event
)
289 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
293 void OnPaint( wxPaintEvent
& event
);
295 // Always be focussable, even with child windows
296 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
297 { wxPanel::SetCanFocus(true); }
301 DECLARE_EVENT_TABLE()
302 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
306 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
308 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
309 EVT_MOTION(wxPGCanvas::OnMouseMove
)
310 EVT_PAINT(wxPGCanvas::OnPaint
)
311 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
312 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
313 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
314 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
315 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
319 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
321 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
322 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
326 // Don't paint after destruction has begun
327 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
330 // Update everything inside the box
331 wxRect r
= GetUpdateRegion().GetBox();
333 // FIXME: This is just a workaround for a bug that causes splitters not
334 // to paint when other windows are being dragged over the grid.
335 wxRect fullRect
= GetRect();
337 r
.width
= fullRect
.width
;
339 // Repaint this rectangle
340 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
342 // We assume that the size set when grid is shown
343 // is what is desired.
344 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
347 // -----------------------------------------------------------------------
349 // -----------------------------------------------------------------------
351 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
353 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
354 EVT_IDLE(wxPropertyGrid::OnIdle
)
355 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
356 EVT_PAINT(wxPropertyGrid::OnPaint
)
357 EVT_SIZE(wxPropertyGrid::OnResize
)
358 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
359 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
360 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
361 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
362 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
363 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
364 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
365 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
369 // -----------------------------------------------------------------------
371 wxPropertyGrid::wxPropertyGrid()
377 // -----------------------------------------------------------------------
379 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
384 const wxString
& name
)
388 Create(parent
,id
,pos
,size
,style
,name
);
391 // -----------------------------------------------------------------------
393 bool wxPropertyGrid::Create( wxWindow
*parent
,
398 const wxString
& name
)
401 if ( !(style
&wxBORDER_MASK
) )
402 style
|= wxSIMPLE_BORDER
;
406 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
407 style
&= ~(wxTAB_TRAVERSAL
);
408 style
|= wxWANTS_CHARS
;
410 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
417 // -----------------------------------------------------------------------
420 // Initialize values to defaults
422 void wxPropertyGrid::Init1()
424 // Register editor classes, if necessary.
425 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
426 wxPropertyGrid::RegisterDefaultEditors();
430 m_wndEditor
= m_wndEditor2
= NULL
;
433 m_eventObject
= this;
435 m_sortFunction
= NULL
;
436 m_inDoPropertyChanged
= 0;
437 m_inCommitChangesFromEditor
= 0;
438 m_inDoSelectProperty
= 0;
439 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
445 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
446 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
447 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
448 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
449 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
450 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
451 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
452 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
453 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
455 m_coloursCustomized
= 0;
460 #if wxPG_DOUBLE_BUFFER
461 m_doubleBuffer
= NULL
;
464 #ifndef wxPG_ICON_WIDTH
470 m_iconWidth
= wxPG_ICON_WIDTH
;
475 m_gutterWidth
= wxPG_GUTTER_MIN
;
476 m_subgroup_extramargin
= 10;
480 m_width
= m_height
= 0;
482 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
485 m_chgInfo_changedProperty
= NULL
;
488 // -----------------------------------------------------------------------
491 // Initialize after parent etc. set
493 void wxPropertyGrid::Init2()
495 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
498 // Smaller controls on Mac
499 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
502 // Now create state, if one didn't exist already
503 // (wxPropertyGridManager might have created it for us).
506 m_pState
= CreateState();
507 m_pState
->m_pPropGrid
= this;
508 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
511 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
512 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
514 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
516 m_pState
->InitNonCatMode();
518 m_pState
->m_properties
= m_pState
->m_abcArray
;
521 GetClientSize(&m_width
,&m_height
);
523 #ifndef wxPG_ICON_WIDTH
524 // create two bitmap nodes for drawing
525 m_expandbmp
= new wxBitmap(expand_xpm
);
526 m_collbmp
= new wxBitmap(collapse_xpm
);
528 // calculate average font height for bitmap centering
530 m_iconWidth
= m_expandbmp
->GetWidth();
531 m_iconHeight
= m_expandbmp
->GetHeight();
534 m_curcursor
= wxCURSOR_ARROW
;
535 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
537 // adjust bitmap icon y position so they are centered
538 m_vspacing
= wxPG_DEFAULT_VSPACING
;
540 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
542 // Allocate cell datas indirectly by calling setter
543 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
544 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
548 // This helps with flicker
549 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
551 // Hook the top-level parent
555 OnTLPChanging(::wxGetTopLevelParent(this));
557 // set virtual size to this window size
558 wxSize wndsize
= GetSize();
559 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
561 m_timeCreated
= ::wxGetLocalTimeMillis();
563 m_canvas
= new wxPGCanvas();
564 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
565 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
566 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
568 m_iFlags
|= wxPG_FL_INITIALIZED
;
570 m_ncWidth
= wndsize
.GetWidth();
572 // Need to call OnResize handler or size given in constructor/Create
574 wxSizeEvent
sizeEvent(wndsize
,0);
578 // -----------------------------------------------------------------------
580 wxPropertyGrid::~wxPropertyGrid()
584 DoSelectProperty(NULL
, wxPG_SEL_NOVALIDATE
|wxPG_SEL_DONT_SEND_EVENT
);
586 // This should do prevent things from going too badly wrong
587 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
589 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
590 m_canvas
->ReleaseMouse();
592 // Call with NULL to disconnect event handling
595 wxASSERT_MSG( !IsEditorsValueModified(),
596 wxS("Most recent change in property editor was lost!!! ")
597 wxS("(if you don't want this to happen, close your frames ")
598 wxS("and dialogs using Close(false).)") );
600 #if wxPG_DOUBLE_BUFFER
601 if ( m_doubleBuffer
)
602 delete m_doubleBuffer
;
605 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
608 delete m_cursorSizeWE
;
610 #ifndef wxPG_ICON_WIDTH
615 // Delete common value records
616 for ( i
=0; i
<m_commonValues
.size(); i
++ )
618 delete GetCommonValue(i
);
622 // -----------------------------------------------------------------------
624 bool wxPropertyGrid::Destroy()
626 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
627 m_canvas
->ReleaseMouse();
629 return wxScrolledWindow::Destroy();
632 // -----------------------------------------------------------------------
634 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
636 return new wxPropertyGridPageState();
639 // -----------------------------------------------------------------------
640 // wxPropertyGrid overridden wxWindow methods
641 // -----------------------------------------------------------------------
643 void wxPropertyGrid::SetWindowStyleFlag( long style
)
645 long old_style
= m_windowStyle
;
647 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
649 wxASSERT( m_pState
);
651 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
654 EnableCategories( true );
656 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
658 // Disable categories
659 EnableCategories( false );
661 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
667 PrepareAfterItemsAdded();
669 m_pState
->m_itemsAdded
= 1;
671 #if wxPG_SUPPORT_TOOLTIPS
672 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
678 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
679 SetToolTip ( tooltip );
680 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
683 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
688 m_canvas
->SetToolTip( NULL
);
693 wxScrolledWindow::SetWindowStyleFlag ( style
);
695 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
697 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
699 CalculateFontAndBitmapStuff( m_vspacing
);
705 // -----------------------------------------------------------------------
707 void wxPropertyGrid::Freeze()
711 wxScrolledWindow::Freeze();
716 // -----------------------------------------------------------------------
718 void wxPropertyGrid::Thaw()
724 wxScrolledWindow::Thaw();
725 RecalculateVirtualSize();
726 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
730 // Force property re-selection
731 // NB: We must copy the selection.
732 wxArrayPGProperty selection
= m_pState
->m_selection
;
733 DoSetSelection(selection
, wxPG_SEL_FORCE
);
737 // -----------------------------------------------------------------------
739 bool wxPropertyGrid::DoAddToSelection( wxPGProperty
* prop
, int selFlags
)
741 wxCHECK( prop
, false );
743 if ( !(GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
) )
744 return DoSelectProperty(prop
, selFlags
);
746 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
748 if ( !selection
.size() )
750 return DoSelectProperty(prop
, selFlags
);
754 // For categories, only one can be selected at a time
755 if ( prop
->IsCategory() || selection
[0]->IsCategory() )
758 selection
.push_back(prop
);
760 if ( !(selFlags
& wxPG_SEL_DONT_SEND_EVENT
) )
762 SendEvent( wxEVT_PG_SELECTED
, prop
, NULL
, selFlags
);
765 // For some reason, if we use RefreshProperty(prop) here,
766 // we may go into infinite drawing loop.
773 // -----------------------------------------------------------------------
775 bool wxPropertyGrid::DoRemoveFromSelection( wxPGProperty
* prop
, int selFlags
)
777 wxCHECK( prop
, false );
780 wxArrayPGProperty
& selection
= m_pState
->m_selection
;
781 if ( selection
.size() <= 1 )
783 res
= DoSelectProperty(NULL
, selFlags
);
787 selection
.Remove(prop
);
788 RefreshProperty(prop
);
795 // -----------------------------------------------------------------------
797 bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty
* prop
,
798 wxMouseEvent
* mouseEvent
,
801 bool alreadySelected
= m_pState
->DoIsPropertySelected(prop
);
803 bool addToExistingSelection
;
805 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
)
809 if ( mouseEvent
->GetEventType() == wxEVT_RIGHT_DOWN
||
810 mouseEvent
->GetEventType() == wxEVT_RIGHT_UP
)
812 // Allow right-click for context menu without
813 // disturbing the selection.
814 if ( GetSelectedProperties().size() <= 1 ||
816 return DoSelectProperty(prop
, selFlags
);
821 addToExistingSelection
= mouseEvent
->ShiftDown();
826 addToExistingSelection
= false;
831 addToExistingSelection
= false;
834 if ( addToExistingSelection
)
836 if ( !alreadySelected
)
838 res
= DoAddToSelection(prop
, selFlags
);
840 else if ( GetSelectedProperties().size() > 1 )
842 res
= DoRemoveFromSelection(prop
, selFlags
);
847 res
= DoSelectProperty(prop
, selFlags
);
853 // -----------------------------------------------------------------------
855 void wxPropertyGrid::DoSetSelection( const wxArrayPGProperty
& newSelection
,
858 if ( newSelection
.size() > 0 )
860 if ( !DoSelectProperty(newSelection
[0], selFlags
) )
865 DoClearSelection(false, selFlags
);
868 for ( unsigned int i
= 1; i
< newSelection
.size(); i
++ )
870 DoAddToSelection(newSelection
[i
], selFlags
);
876 // -----------------------------------------------------------------------
878 void wxPropertyGrid::SetExtraStyle( long exStyle
)
880 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
882 #if defined(__WXMSW__)
885 // Don't use WS_EX_COMPOSITED just now.
888 if ( m_iFlags & wxPG_FL_IN_MANAGER )
889 hWnd = (HWND)GetParent()->GetHWND();
891 hWnd = (HWND)GetHWND();
893 ::SetWindowLong( hWnd, GWL_EXSTYLE,
894 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
897 //#elif defined(__WXGTK20__)
899 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
900 // truly was double-buffered.
901 if ( !this->IsDoubleBuffered() )
903 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
907 #if wxPG_DOUBLE_BUFFER
908 delete m_doubleBuffer
;
909 m_doubleBuffer
= NULL
;
914 wxScrolledWindow::SetExtraStyle( exStyle
);
916 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
917 m_pState
->InitNonCatMode();
919 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
920 m_windowStyle
|= wxPG_TOOLTIPS
;
923 wxPGGlobalVars
->m_extraStyle
= exStyle
;
926 // -----------------------------------------------------------------------
928 // returns the best acceptable minimal size
929 wxSize
wxPropertyGrid::DoGetBestSize() const
931 int lineHeight
= wxMax(15, m_lineHeight
);
933 // don't make the grid too tall (limit height to 10 items) but don't
934 // make it too small neither
937 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
941 const wxSize sz
= wxSize(60, lineHeight
*numLines
+ 40);
946 // -----------------------------------------------------------------------
948 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
950 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
953 // Parent changed so let's redetermine and re-hook the
954 // correct top-level window.
957 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
958 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
961 m_tlpClosedTime
= currentTime
;
966 // Only accept new tlp if same one was not just dismissed.
967 if ( newTLP
!= m_tlpClosed
||
968 m_tlpClosedTime
+250 < currentTime
)
970 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
971 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
984 // -----------------------------------------------------------------------
986 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
988 // ClearSelection forces value validation/commit.
989 if ( event
.CanVeto() && !DoClearSelection() )
995 // Ok, it can close, set tlp pointer to NULL. Some other event
996 // handler can of course veto the close, but our OnIdle() should
997 // then be able to regain the tlp pointer.
1003 // -----------------------------------------------------------------------
1005 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
1007 OnTLPChanging((wxWindow
*)newParent
);
1009 bool res
= wxScrolledWindow::Reparent(newParent
);
1014 // -----------------------------------------------------------------------
1015 // wxPropertyGrid Font and Colour Methods
1016 // -----------------------------------------------------------------------
1018 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1022 m_captionFont
= wxScrolledWindow::GetFont();
1024 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1025 m_subgroup_extramargin
= x
+ (x
/2);
1028 #if wxPG_USE_RENDERER_NATIVE
1029 m_iconWidth
= wxPG_ICON_WIDTH
;
1030 #elif wxPG_ICON_WIDTH
1032 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1033 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1034 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1038 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1039 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1040 m_gutterWidth
= wxPG_GUTTER_MIN
;
1043 if ( vspacing
<= 1 ) vdiv
= 12;
1044 else if ( vspacing
>= 3 ) vdiv
= 3;
1046 m_spacingy
= m_fontHeight
/ vdiv
;
1047 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1048 m_spacingy
= wxPG_YSPACING_MIN
;
1051 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1052 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1054 m_captionFont
.SetWeight(wxBOLD
);
1055 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1057 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1060 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1061 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1064 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1066 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1067 RecalculateVirtualSize();
1069 InvalidateBestSize();
1072 // -----------------------------------------------------------------------
1074 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1080 // -----------------------------------------------------------------------
1082 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1083 int ga
= 1000, int ba
= 1000,
1084 bool forceDifferent
= false)
1091 // Recursion guard (allow 2 max)
1092 static int isinside
= 0;
1094 wxCHECK_MSG( isinside
< 3,
1096 wxT("wxPGAdjustColour should not be recursively called more than once") );
1101 int g
= src
.Green();
1104 if ( r2
>255 ) r2
= 255;
1105 else if ( r2
<0) r2
= 0;
1107 if ( g2
>255 ) g2
= 255;
1108 else if ( g2
<0) g2
= 0;
1110 if ( b2
>255 ) b2
= 255;
1111 else if ( b2
<0) b2
= 0;
1113 // Make sure they are somewhat different
1114 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1115 dst
= wxPGAdjustColour(src
,-(ra
*2));
1117 dst
= wxColour(r2
,g2
,b2
);
1119 // Recursion guard (allow 2 max)
1126 static int wxPGGetColAvg( const wxColour
& col
)
1128 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1132 void wxPropertyGrid::RegainColours()
1134 if ( !(m_coloursCustomized
& 0x0002) )
1136 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1138 // Make sure colour is dark enough
1140 int colDec
= wxPGGetColAvg(col
) - 230;
1142 int colDec
= wxPGGetColAvg(col
) - 200;
1145 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1148 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1151 if ( !(m_coloursCustomized
& 0x0001) )
1152 m_colMargin
= m_colCapBack
;
1154 if ( !(m_coloursCustomized
& 0x0004) )
1161 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1162 m_colCapFore
= capForeCol
;
1163 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1166 if ( !(m_coloursCustomized
& 0x0008) )
1168 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1169 m_colPropBack
= bgCol
;
1170 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1173 if ( !(m_coloursCustomized
& 0x0010) )
1175 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1176 m_colPropFore
= fgCol
;
1177 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1180 if ( !(m_coloursCustomized
& 0x0020) )
1181 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1183 if ( !(m_coloursCustomized
& 0x0040) )
1184 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1186 if ( !(m_coloursCustomized
& 0x0080) )
1187 m_colLine
= m_colCapBack
;
1189 if ( !(m_coloursCustomized
& 0x0100) )
1190 m_colDisPropFore
= m_colCapFore
;
1192 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1195 // -----------------------------------------------------------------------
1197 void wxPropertyGrid::ResetColours()
1199 m_coloursCustomized
= 0;
1206 // -----------------------------------------------------------------------
1208 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1210 // Must disable active editor.
1213 bool res
= wxScrolledWindow::SetFont( font
);
1214 if ( res
&& GetParent()) // may not have been Create()ed yet
1216 CalculateFontAndBitmapStuff( m_vspacing
);
1223 // -----------------------------------------------------------------------
1225 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1228 m_coloursCustomized
|= 0x80;
1232 // -----------------------------------------------------------------------
1234 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1237 m_coloursCustomized
|= 0x01;
1241 // -----------------------------------------------------------------------
1243 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1245 m_colPropBack
= col
;
1246 m_coloursCustomized
|= 0x08;
1248 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1253 // -----------------------------------------------------------------------
1255 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1257 m_colPropFore
= col
;
1258 m_coloursCustomized
|= 0x10;
1260 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1265 // -----------------------------------------------------------------------
1267 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1269 m_colEmptySpace
= col
;
1274 // -----------------------------------------------------------------------
1276 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1278 m_colDisPropFore
= col
;
1279 m_coloursCustomized
|= 0x100;
1283 // -----------------------------------------------------------------------
1285 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1288 m_coloursCustomized
|= 0x20;
1292 // -----------------------------------------------------------------------
1294 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1297 m_coloursCustomized
|= 0x40;
1301 // -----------------------------------------------------------------------
1303 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1306 m_coloursCustomized
|= 0x02;
1308 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1313 // -----------------------------------------------------------------------
1315 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1318 m_coloursCustomized
|= 0x04;
1320 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1325 // -----------------------------------------------------------------------
1326 // wxPropertyGrid property adding and removal
1327 // -----------------------------------------------------------------------
1329 void wxPropertyGrid::PrepareAfterItemsAdded()
1331 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1333 m_pState
->m_itemsAdded
= 0;
1335 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1336 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1338 RecalculateVirtualSize();
1341 // -----------------------------------------------------------------------
1342 // wxPropertyGrid property operations
1343 // -----------------------------------------------------------------------
1345 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1347 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1351 bool changed
= false;
1353 // Is it inside collapsed section?
1354 if ( !p
->IsVisible() )
1357 wxPGProperty
* parent
= p
->GetParent();
1358 wxPGProperty
* grandparent
= parent
->GetParent();
1360 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1361 Expand( grandparent
);
1369 GetViewStart(&vx
,&vy
);
1370 vy
*=wxPG_PIXELS_PER_UNIT
;
1376 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1377 m_iFlags
|= wxPG_FL_SCROLLED
;
1380 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1382 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1383 m_iFlags
|= wxPG_FL_SCROLLED
;
1393 // -----------------------------------------------------------------------
1394 // wxPropertyGrid helper methods called by properties
1395 // -----------------------------------------------------------------------
1397 // Control font changer helper.
1398 void wxPropertyGrid::SetCurControlBoldFont()
1400 wxASSERT( m_wndEditor
);
1401 m_wndEditor
->SetFont( m_captionFont
);
1404 // -----------------------------------------------------------------------
1406 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1409 #if wxPG_SMALL_SCREEN
1410 // On small-screen devices, always show dialogs with default position and size.
1411 return wxDefaultPosition
;
1413 int splitterX
= GetSplitterPosition();
1417 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1419 ImprovedClientToScreen( &x
, &y
);
1421 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1422 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1429 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1439 new_y
= y
+ m_lineHeight
;
1441 return wxPoint(new_x
,new_y
);
1445 // -----------------------------------------------------------------------
1447 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1449 if ( src_str
.length() == 0 )
1455 bool prev_is_slash
= false;
1457 wxString::const_iterator i
= src_str
.begin();
1461 for ( ; i
!= src_str
.end(); ++i
)
1465 if ( a
!= wxS('\\') )
1467 if ( !prev_is_slash
)
1473 if ( a
== wxS('n') )
1476 dst_str
<< wxS('\n');
1478 dst_str
<< wxS('\n');
1481 else if ( a
== wxS('t') )
1482 dst_str
<< wxS('\t');
1486 prev_is_slash
= false;
1490 if ( prev_is_slash
)
1492 dst_str
<< wxS('\\');
1493 prev_is_slash
= false;
1497 prev_is_slash
= true;
1504 // -----------------------------------------------------------------------
1506 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1508 if ( src_str
.length() == 0 )
1514 wxString::const_iterator i
= src_str
.begin();
1515 wxUniChar prev_a
= wxS('\0');
1519 for ( ; i
!= src_str
.end(); ++i
)
1523 if ( a
>= wxS(' ') )
1525 // This surely is not something that requires an escape sequence.
1530 // This might need...
1531 if ( a
== wxS('\r') )
1533 // DOS style line end.
1534 // Already taken care below
1536 else if ( a
== wxS('\n') )
1537 // UNIX style line end.
1538 dst_str
<< wxS("\\n");
1539 else if ( a
== wxS('\t') )
1541 dst_str
<< wxS('\t');
1544 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1554 // -----------------------------------------------------------------------
1556 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1563 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1566 // -----------------------------------------------------------------------
1567 // wxPropertyGrid graphics related methods
1568 // -----------------------------------------------------------------------
1570 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1574 // Update everything inside the box
1575 wxRect r
= GetUpdateRegion().GetBox();
1577 dc
.SetPen(m_colEmptySpace
);
1578 dc
.SetBrush(m_colEmptySpace
);
1579 dc
.DrawRectangle(r
);
1582 // -----------------------------------------------------------------------
1584 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1585 wxPGProperty
* property
) const
1587 // Prepare rectangle to be used
1589 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1590 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1592 #if (wxPG_USE_RENDERER_NATIVE)
1594 #elif wxPG_ICON_WIDTH
1595 // Drawing expand/collapse button manually
1596 dc
.SetPen(m_colPropFore
);
1597 if ( property
->IsCategory() )
1598 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1600 dc
.SetBrush(m_colPropBack
);
1602 dc
.DrawRectangle( r
);
1603 int _y
= r
.y
+(m_iconWidth
/2);
1604 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1609 if ( property
->IsExpanded() )
1611 // wxRenderer functions are non-mutating in nature, so it
1612 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1613 // Hopefully this does not cause problems.
1614 #if (wxPG_USE_RENDERER_NATIVE)
1615 wxRendererNative::Get().DrawTreeItemButton(
1621 #elif wxPG_ICON_WIDTH
1630 #if (wxPG_USE_RENDERER_NATIVE)
1631 wxRendererNative::Get().DrawTreeItemButton(
1637 #elif wxPG_ICON_WIDTH
1638 int _x
= r
.x
+(m_iconWidth
/2);
1639 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1645 #if (wxPG_USE_RENDERER_NATIVE)
1647 #elif wxPG_ICON_WIDTH
1650 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1654 // -----------------------------------------------------------------------
1657 // This is the one called by OnPaint event handler and others.
1658 // topy and bottomy are already unscrolled (ie. physical)
1660 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1662 unsigned int bottomy
,
1663 const wxRect
* clipRect
)
1665 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1667 m_pState
->EnsureVirtualHeight();
1669 wxRect tempClipRect
;
1672 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1673 clipRect
= &tempClipRect
;
1676 // items added check
1677 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1679 int paintFinishY
= 0;
1681 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1684 bool isBuffered
= false;
1686 #if wxPG_DOUBLE_BUFFER
1687 wxMemoryDC
* bufferDC
= NULL
;
1689 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1691 if ( !m_doubleBuffer
)
1693 paintFinishY
= clipRect
->y
;
1698 bufferDC
= new wxMemoryDC();
1700 // If nothing was changed, then just copy from double-buffer
1701 bufferDC
->SelectObject( *m_doubleBuffer
);
1711 dc
.SetClippingRegion( *clipRect
);
1712 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1715 #if wxPG_DOUBLE_BUFFER
1718 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1719 bufferDC
, 0, 0, wxCOPY
);
1720 dc
.DestroyClippingRegion(); // Is this really necessary?
1726 // Clear area beyond bottomY?
1727 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1729 dc
.SetPen(m_colEmptySpace
);
1730 dc
.SetBrush(m_colEmptySpace
);
1731 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1735 // -----------------------------------------------------------------------
1737 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1738 const wxRect
* clipRect
,
1739 bool isBuffered
) const
1741 const wxPGProperty
* firstItem
;
1742 const wxPGProperty
* lastItem
;
1744 firstItem
= DoGetItemAtY(clipRect
->y
);
1745 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1748 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1750 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1753 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1754 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1756 int lh
= m_lineHeight
;
1759 int lastItemBottomY
;
1761 firstItemTopY
= clipRect
->y
;
1762 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1764 // Align y coordinates to item boundaries
1765 firstItemTopY
-= firstItemTopY
% lh
;
1766 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1767 lastItemBottomY
-= 1;
1769 // Entire range outside scrolled, visible area?
1770 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1773 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1777 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1778 firstItem->GetLabel().c_str(),
1779 lastItem->GetLabel().c_str(),
1780 (int)(lastItemBottomY - firstItemTopY),
1782 (unsigned long)clipRect );
1787 long windowStyle
= m_windowStyle
;
1793 // With wxPG_DOUBLE_BUFFER, do double buffering
1794 // - buffer's y = 0, so align cliprect and coordinates to that
1796 #if wxPG_DOUBLE_BUFFER
1802 xRelMod
= clipRect
->x
;
1803 yRelMod
= clipRect
->y
;
1806 // clipRect conversion
1811 firstItemTopY
-= yRelMod
;
1812 lastItemBottomY
-= yRelMod
;
1815 wxUnusedVar(isBuffered
);
1818 int x
= m_marginWidth
- xRelMod
;
1820 wxFont normalFont
= GetFont();
1822 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1824 bool isPgEnabled
= IsEnabled();
1827 // Prepare some pens and brushes that are often changed to.
1830 wxBrush
marginBrush(m_colMargin
);
1831 wxPen
marginPen(m_colMargin
);
1832 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1833 wxPen
linepen(m_colLine
,1,wxSOLID
);
1835 wxColour selBackCol
;
1837 selBackCol
= m_colSelBack
;
1839 selBackCol
= m_colMargin
;
1841 // pen that has same colour as text
1842 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1845 // Clear margin with background colour
1847 dc
.SetBrush( marginBrush
);
1848 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1850 dc
.SetPen( *wxTRANSPARENT_PEN
);
1851 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1854 const wxPGProperty
* firstSelected
= GetSelection();
1855 const wxPropertyGridPageState
* state
= m_pState
;
1857 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1858 bool wasSelectedPainted
= false;
1861 // TODO: Only render columns that are within clipping region.
1863 dc
.SetFont(normalFont
);
1865 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1866 int endScanBottomY
= lastItemBottomY
+ lh
;
1867 int y
= firstItemTopY
;
1870 // Pregenerate list of visible properties.
1871 wxArrayPGProperty visPropArray
;
1872 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1874 for ( ; !it
.AtEnd(); it
.Next() )
1876 const wxPGProperty
* p
= *it
;
1878 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1880 visPropArray
.push_back((wxPGProperty
*)p
);
1882 if ( y
> endScanBottomY
)
1889 visPropArray
.push_back(NULL
);
1891 wxPGProperty
* nextP
= visPropArray
[0];
1893 int gridWidth
= state
->m_width
;
1896 for ( unsigned int arrInd
=1;
1897 nextP
&& y
<= lastItemBottomY
;
1900 wxPGProperty
* p
= nextP
;
1901 nextP
= visPropArray
[arrInd
];
1903 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1904 int textMarginHere
= x
;
1905 int renderFlags
= 0;
1907 int greyDepth
= m_marginWidth
;
1908 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1909 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1911 int greyDepthX
= greyDepth
- xRelMod
;
1913 // Use basic depth if in non-categoric mode and parent is base array.
1914 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1916 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1919 // Paint margin area
1920 dc
.SetBrush(marginBrush
);
1921 dc
.SetPen(marginPen
);
1922 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1924 dc
.SetPen( linepen
);
1929 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1935 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1937 sx
+= state
->m_colWidths
[si
];
1938 dc
.DrawLine( sx
, y
, sx
, y2
);
1941 // Horizontal Line, below
1942 // (not if both this and next is category caption)
1943 if ( p
->IsCategory() &&
1944 nextP
&& nextP
->IsCategory() )
1945 dc
.SetPen(m_colCapBack
);
1947 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1950 // Need to override row colours?
1954 bool isSelected
= state
->DoIsPropertySelected(p
);
1958 // Disabled may get different colour.
1959 if ( !p
->IsEnabled() )
1961 renderFlags
|= wxPGCellRenderer::Disabled
|
1962 wxPGCellRenderer::DontUseCellFgCol
;
1963 rowFgCol
= m_colDisPropFore
;
1968 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1969 if ( p
== firstSelected
)
1970 wasSelectedPainted
= true;
1973 renderFlags
|= wxPGCellRenderer::Selected
;
1975 if ( !p
->IsCategory() )
1977 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1978 wxPGCellRenderer::DontUseCellBgCol
;
1980 if ( reallyFocused
&& p
== firstSelected
)
1982 rowFgCol
= m_colSelFore
;
1983 rowBgCol
= selBackCol
;
1985 else if ( isPgEnabled
)
1987 rowFgCol
= m_colPropFore
;
1988 if ( p
== firstSelected
)
1989 rowBgCol
= m_colMargin
;
1991 rowBgCol
= selBackCol
;
1995 rowFgCol
= m_colDisPropFore
;
1996 rowBgCol
= selBackCol
;
2003 if ( rowBgCol
.IsOk() )
2004 rowBgBrush
= wxBrush(rowBgCol
);
2006 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
2007 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
2010 // Fill additional margin area with background colour of first cell
2011 if ( greyDepthX
< textMarginHere
)
2013 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
2015 wxPGCell
& cell
= p
->GetCell(0);
2016 rowBgCol
= cell
.GetBgCol();
2017 rowBgBrush
= wxBrush(rowBgCol
);
2019 dc
.SetBrush(rowBgBrush
);
2020 dc
.SetPen(rowBgCol
);
2021 dc
.DrawRectangle(greyDepthX
+1, y
,
2022 textMarginHere
-greyDepthX
, lh
-1);
2025 bool fontChanged
= false;
2027 // Expander button rectangle
2028 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2033 if ( p
->IsCategory() )
2035 // Captions have their cell areas merged as one
2036 dc
.SetFont(m_captionFont
);
2038 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2040 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2042 dc
.SetBrush(rowBgBrush
);
2043 dc
.SetPen(rowBgCol
);
2046 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2048 dc
.SetTextForeground(rowFgCol
);
2051 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2052 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2055 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2056 DrawExpanderButton( dc
, butRect
, p
);
2060 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2062 dc
.SetFont(m_captionFont
);
2068 int nextCellWidth
= state
->m_colWidths
[0] -
2069 (greyDepthX
- m_marginWidth
);
2070 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2071 int textXAdd
= textMarginHere
- greyDepthX
;
2073 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2075 cellRect
.width
= nextCellWidth
- 1;
2077 bool ctrlCell
= false;
2078 int cellRenderFlags
= renderFlags
;
2081 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2082 DrawExpanderButton( dc
, butRect
, p
);
2085 if ( isSelected
&& ci
== 1 )
2087 if ( p
== firstSelected
&& m_wndEditor
)
2089 wxColour editorBgCol
=
2090 GetEditorControl()->GetBackgroundColour();
2091 dc
.SetBrush(editorBgCol
);
2092 dc
.SetPen(editorBgCol
);
2093 dc
.SetTextForeground(m_colPropFore
);
2094 dc
.DrawRectangle(cellRect
);
2096 if ( m_dragStatus
== 0 &&
2097 !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2102 dc
.SetBrush(m_colPropBack
);
2103 dc
.SetPen(m_colPropBack
);
2104 dc
.SetTextForeground(m_colDisPropFore
);
2105 if ( p
->IsEnabled() )
2106 dc
.SetTextForeground(rowFgCol
);
2108 dc
.SetTextForeground(m_colDisPropFore
);
2113 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2115 dc
.SetBrush(rowBgBrush
);
2116 dc
.SetPen(rowBgCol
);
2119 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2121 dc
.SetTextForeground(rowFgCol
);
2125 dc
.SetClippingRegion(cellRect
);
2127 cellRect
.x
+= textXAdd
;
2128 cellRect
.width
-= textXAdd
;
2133 wxPGCellRenderer
* renderer
;
2134 int cmnVal
= p
->GetCommonValue();
2135 if ( cmnVal
== -1 || ci
!= 1 )
2137 renderer
= p
->GetCellRenderer(ci
);
2138 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2143 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2144 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2149 cellX
+= state
->m_colWidths
[ci
];
2150 if ( ci
< (state
->m_colWidths
.size()-1) )
2151 nextCellWidth
= state
->m_colWidths
[ci
+1];
2153 dc
.DestroyClippingRegion(); // Is this really necessary?
2159 dc
.SetFont(normalFont
);
2164 // Refresh editor controls (seems not needed on msw)
2165 // NOTE: This code is mandatory for GTK!
2166 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2167 if ( wasSelectedPainted
)
2170 m_wndEditor
->Refresh();
2172 m_wndEditor2
->Refresh();
2179 // -----------------------------------------------------------------------
2181 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2185 if ( m_width
< 10 || m_height
< 10 ||
2186 !m_pState
->m_properties
->GetChildCount() ||
2188 return wxRect(0,0,0,0);
2193 // Return rect which encloses the given property range
2195 int visTop
= p1
->GetY();
2198 visBottom
= p2
->GetY() + m_lineHeight
;
2200 visBottom
= m_height
+ visTop
;
2202 // If seleced property is inside the range, we'll extend the range to include
2204 wxPGProperty
* selected
= GetSelection();
2207 int selectedY
= selected
->GetY();
2208 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2210 wxWindow
* editor
= GetEditorControl();
2213 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2214 if ( visBottom2
> visBottom
)
2215 visBottom
= visBottom2
;
2220 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2223 // -----------------------------------------------------------------------
2225 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2230 if ( m_pState
->m_itemsAdded
)
2231 PrepareAfterItemsAdded();
2233 wxRect r
= GetPropertyRect(p1
, p2
);
2236 m_canvas
->RefreshRect(r
);
2240 // -----------------------------------------------------------------------
2242 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2244 if ( m_pState
->DoIsPropertySelected(p
) )
2246 // NB: We must copy the selection.
2247 wxArrayPGProperty selection
= m_pState
->m_selection
;
2248 DoSetSelection(selection
, wxPG_SEL_FORCE
);
2251 DrawItemAndChildren(p
);
2254 // -----------------------------------------------------------------------
2256 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2261 // Draw item, children, and parent too, if it is not category
2262 wxPGProperty
* parent
= p
->GetParent();
2265 !parent
->IsCategory() &&
2266 parent
->GetParent() )
2269 parent
= parent
->GetParent();
2272 DrawItemAndChildren(p
);
2275 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2277 wxCHECK_RET( p
, wxT("invalid property id") );
2279 // Do not draw if in non-visible page
2280 if ( p
->GetParentState() != m_pState
)
2283 // do not draw a single item if multiple pending
2284 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2287 // Update child control.
2288 wxPGProperty
* selected
= GetSelection();
2289 if ( selected
&& selected
->GetParent() == p
)
2292 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2294 DrawItems(p
, lastDrawn
);
2297 // -----------------------------------------------------------------------
2299 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2300 const wxRect
*rect
)
2302 PrepareAfterItemsAdded();
2304 wxWindow::Refresh(false);
2306 // TODO: Coordinate translation
2307 m_canvas
->Refresh(false, rect
);
2309 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2310 // I think this really helps only GTK+1.2
2311 if ( m_wndEditor
) m_wndEditor
->Refresh();
2312 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2316 // -----------------------------------------------------------------------
2317 // wxPropertyGrid global operations
2318 // -----------------------------------------------------------------------
2320 void wxPropertyGrid::Clear()
2322 m_pState
->DoClear();
2328 RecalculateVirtualSize();
2330 // Need to clear some area at the end
2332 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2335 // -----------------------------------------------------------------------
2337 bool wxPropertyGrid::EnableCategories( bool enable
)
2344 // Enable categories
2347 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2352 // Disable categories
2354 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2357 if ( !m_pState
->EnableCategories(enable
) )
2362 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2364 m_pState
->m_itemsAdded
= 1; // force
2365 PrepareAfterItemsAdded();
2369 m_pState
->m_itemsAdded
= 1;
2371 // No need for RecalculateVirtualSize() here - it is already called in
2372 // wxPropertyGridPageState method above.
2379 // -----------------------------------------------------------------------
2381 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2383 wxASSERT( pNewState
);
2384 wxASSERT( pNewState
->GetGrid() );
2386 if ( pNewState
== m_pState
)
2389 wxArrayPGProperty oldSelection
= m_pState
->m_selection
;
2391 // Call ClearSelection() instead of DoClearSelection()
2392 // so that selection clear events are not sent.
2395 m_pState
->m_selection
= oldSelection
;
2397 bool orig_mode
= m_pState
->IsInNonCatMode();
2398 bool new_state_mode
= pNewState
->IsInNonCatMode();
2400 m_pState
= pNewState
;
2403 int pgWidth
= GetClientSize().x
;
2404 if ( HasVirtualWidth() )
2406 int minWidth
= pgWidth
;
2407 if ( pNewState
->m_width
< minWidth
)
2409 pNewState
->m_width
= minWidth
;
2410 pNewState
->CheckColumnWidths();
2416 // Just in case, fully re-center splitter
2417 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2418 pNewState
->m_fSplitterX
= -1.0;
2420 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2425 // If necessary, convert state to correct mode.
2426 if ( orig_mode
!= new_state_mode
)
2428 // This should refresh as well.
2429 EnableCategories( orig_mode
?false:true );
2431 else if ( !m_frozen
)
2433 // Refresh, if not frozen.
2434 m_pState
->PrepareAfterItemsAdded();
2436 // Reselect (Use SetSelection() instead of Do-variant so that
2437 // events won't be sent).
2438 SetSelection(m_pState
->m_selection
);
2440 RecalculateVirtualSize(0);
2444 m_pState
->m_itemsAdded
= 1;
2447 // -----------------------------------------------------------------------
2449 // Call to SetSplitterPosition will always disable splitter auto-centering
2450 // if parent window is shown.
2451 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2453 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2456 wxPropertyGridPageState
* state
= m_pState
;
2458 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2462 if ( GetSelection() )
2463 CorrectEditorWidgetSizeX();
2469 // -----------------------------------------------------------------------
2471 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2473 SetSplitterPosition( m_width
/2, true );
2474 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2475 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2478 // -----------------------------------------------------------------------
2479 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2480 // -----------------------------------------------------------------------
2482 // Returns nearest paint visible property (such that will be painted unless
2483 // window is scrolled or resized). If given property is paint visible, then
2484 // it itself will be returned
2485 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2487 int vx
,vy1
;// Top left corner of client
2488 GetViewStart(&vx
,&vy1
);
2489 vy1
*= wxPG_PIXELS_PER_UNIT
;
2491 int vy2
= vy1
+ m_height
;
2492 int propY
= p
->GetY2(m_lineHeight
);
2494 if ( (propY
+ m_lineHeight
) < vy1
)
2497 return DoGetItemAtY( vy1
);
2499 else if ( propY
> vy2
)
2502 return DoGetItemAtY( vy2
);
2505 // Itself paint visible
2510 // -----------------------------------------------------------------------
2511 // Methods related to change in value, value modification and sending events
2512 // -----------------------------------------------------------------------
2514 // commits any changes in editor of selected property
2515 // return true if validation did not fail
2516 // flags are same as with DoSelectProperty
2517 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2519 // Committing already?
2520 if ( m_inCommitChangesFromEditor
)
2523 // Don't do this if already processing editor event. It might
2524 // induce recursive dialogs and crap like that.
2525 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2527 if ( m_inDoPropertyChanged
)
2533 wxPGProperty
* selected
= GetSelection();
2536 IsEditorsValueModified() &&
2537 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2540 m_inCommitChangesFromEditor
= 1;
2542 wxVariant
variant(selected
->GetValueRef());
2543 bool valueIsPending
= false;
2545 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2546 // due to another window getting focus
2547 wxWindow
* oldFocus
= m_curFocused
;
2549 bool validationFailure
= false;
2550 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2552 m_chgInfo_changedProperty
= NULL
;
2554 // If truly modified, schedule value as pending.
2555 if ( selected
->GetEditorClass()->
2556 GetValueFromControl( variant
,
2558 GetEditorControl() ) )
2560 if ( DoEditorValidate() &&
2561 PerformValidation(selected
, variant
) )
2563 valueIsPending
= true;
2567 validationFailure
= true;
2572 EditorsValueWasNotModified();
2577 m_inCommitChangesFromEditor
= 0;
2579 if ( validationFailure
&& !forceSuccess
)
2583 oldFocus
->SetFocus();
2584 m_curFocused
= oldFocus
;
2587 res
= OnValidationFailure(selected
, variant
);
2589 // Now prevent further validation failure messages
2592 EditorsValueWasNotModified();
2593 OnValidationFailureReset(selected
);
2596 else if ( valueIsPending
)
2598 DoPropertyChanged( selected
, flags
);
2599 EditorsValueWasNotModified();
2608 // -----------------------------------------------------------------------
2610 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2614 // Runs all validation functionality.
2615 // Returns true if value passes all tests.
2618 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2620 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2622 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2627 // Adapt list to child values, if necessary
2628 wxVariant listValue
= pendingValue
;
2629 wxVariant
* pPendingValue
= &pendingValue
;
2630 wxVariant
* pList
= NULL
;
2632 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2633 // string value, then we need treat as it was changed instead
2634 // (or, in addition, as is the case with composite string parent).
2635 // This includes creating list variant for child values.
2637 wxPGProperty
* pwc
= p
->GetParent();
2638 wxPGProperty
* changedProperty
= p
;
2639 wxPGProperty
* baseChangedProperty
= changedProperty
;
2640 wxVariant bcpPendingList
;
2642 listValue
= pendingValue
;
2643 listValue
.SetName(p
->GetBaseName());
2646 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2648 wxVariantList tempList
;
2649 wxVariant
lv(tempList
, pwc
->GetBaseName());
2650 lv
.Append(listValue
);
2652 pPendingValue
= &listValue
;
2654 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2656 baseChangedProperty
= pwc
;
2657 bcpPendingList
= lv
;
2660 changedProperty
= pwc
;
2661 pwc
= pwc
->GetParent();
2665 wxPGProperty
* evtChangingProperty
= changedProperty
;
2667 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2669 value
= *pPendingValue
;
2673 // Convert list to child values
2674 pList
= pPendingValue
;
2675 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2678 wxVariant evtChangingValue
= value
;
2680 if ( flags
& SendEvtChanging
)
2682 // FIXME: After proper ValueToString()s added, remove
2683 // this. It is just a temporary fix, as evt_changing
2684 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2685 // (unless it is selected, and textctrl editor is open).
2686 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2688 evtChangingProperty
= baseChangedProperty
;
2689 if ( evtChangingProperty
!= p
)
2691 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2695 evtChangingValue
= pendingValue
;
2699 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2701 if ( changedProperty
== GetSelection() )
2703 wxWindow
* editor
= GetEditorControl();
2704 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2705 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2709 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2714 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2715 m_chgInfo_changedProperty
= changedProperty
;
2716 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2717 m_chgInfo_pendingValue
= value
;
2720 m_chgInfo_valueList
= *pList
;
2722 m_chgInfo_valueList
.MakeNull();
2724 // If changedProperty is not property which value was edited,
2725 // then call wxPGProperty::ValidateValue() for that as well.
2726 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2728 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2732 if ( flags
& SendEvtChanging
)
2734 // SendEvent returns true if event was vetoed
2735 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2739 if ( flags
& IsStandaloneValidation
)
2741 // If called in 'generic' context, we need to reset
2742 // m_chgInfo_changedProperty and write back translated value.
2743 m_chgInfo_changedProperty
= NULL
;
2744 pendingValue
= value
;
2750 // -----------------------------------------------------------------------
2752 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2754 if ( !msg
.length() )
2758 if ( !wxPGGlobalVars
->m_offline
)
2760 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2763 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2766 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2769 pStatusBar
->SetStatusText(msg
);
2777 ::wxMessageBox(msg
, wxT("Property Error"));
2780 // -----------------------------------------------------------------------
2782 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2783 wxVariant
& invalidValue
)
2785 wxWindow
* editor
= GetEditorControl();
2787 // First call property's handler
2788 property
->OnValidationFailure(invalidValue
);
2790 bool res
= DoOnValidationFailure(property
, invalidValue
);
2793 // For non-wxTextCtrl editors, we do need to revert the value
2794 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2795 property
== GetSelection() )
2797 property
->GetEditorClass()->UpdateControl(property
, editor
);
2800 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2805 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2807 int vfb
= m_validationInfo
.m_failureBehavior
;
2809 if ( vfb
& wxPG_VFB_BEEP
)
2812 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2813 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2815 unsigned int colCount
= m_pState
->GetColumnCount();
2817 // We need backup marked property's cells
2818 m_propCellsBackup
= property
->m_cells
;
2820 wxColour vfbFg
= *wxWHITE
;
2821 wxColour vfbBg
= *wxRED
;
2823 property
->EnsureCells(colCount
);
2825 for ( unsigned int i
=0; i
<colCount
; i
++ )
2827 wxPGCell
& cell
= property
->m_cells
[i
];
2828 cell
.SetFgCol(vfbFg
);
2829 cell
.SetBgCol(vfbBg
);
2832 DrawItemAndChildren(property
);
2834 if ( property
== GetSelection() )
2836 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2838 wxWindow
* editor
= GetEditorControl();
2841 editor
->SetForegroundColour(vfbFg
);
2842 editor
->SetBackgroundColour(vfbBg
);
2847 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2849 wxString msg
= m_validationInfo
.m_failureMessage
;
2851 if ( !msg
.length() )
2852 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
2854 DoShowPropertyError(property
, msg
);
2857 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2860 // -----------------------------------------------------------------------
2862 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2864 int vfb
= m_validationInfo
.m_failureBehavior
;
2866 if ( vfb
& wxPG_VFB_MARK_CELL
)
2869 property
->m_cells
= m_propCellsBackup
;
2871 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2873 if ( property
== GetSelection() && GetEditorControl() )
2875 // Calling this will recreate the control, thus resetting its colour
2876 RefreshProperty(property
);
2880 DrawItemAndChildren(property
);
2885 // -----------------------------------------------------------------------
2887 // flags are same as with DoSelectProperty
2888 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2890 if ( m_inDoPropertyChanged
)
2893 wxWindow
* editor
= GetEditorControl();
2894 wxPGProperty
* selected
= GetSelection();
2896 m_pState
->m_anyModified
= 1;
2898 m_inDoPropertyChanged
= 1;
2900 // Maybe need to update control
2901 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2903 // These values were calculated in PerformValidation()
2904 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2905 wxVariant value
= m_chgInfo_pendingValue
;
2907 wxPGProperty
* topPaintedProperty
= changedProperty
;
2909 while ( !topPaintedProperty
->IsCategory() &&
2910 !topPaintedProperty
->IsRoot() )
2912 topPaintedProperty
= topPaintedProperty
->GetParent();
2915 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2917 // Set as Modified (not if dragging just began)
2918 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2920 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2921 if ( p
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2924 SetCurControlBoldFont();
2930 // Propagate updates to parent(s)
2932 wxPGProperty
* prevPwc
= NULL
;
2934 while ( prevPwc
!= topPaintedProperty
)
2936 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2938 if ( pwc
== selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2941 SetCurControlBoldFont();
2945 pwc
= pwc
->GetParent();
2948 // Draw the actual property
2949 DrawItemAndChildren( topPaintedProperty
);
2952 // If value was set by wxPGProperty::OnEvent, then update the editor
2954 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2960 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2961 if ( m_wndEditor
) m_wndEditor
->Refresh();
2962 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2967 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2969 // If top parent has composite string value, then send to child parents,
2970 // starting from baseChangedProperty.
2971 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2973 pwc
= m_chgInfo_baseChangedProperty
;
2975 while ( pwc
!= changedProperty
)
2977 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2978 pwc
= pwc
->GetParent();
2982 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2984 m_inDoPropertyChanged
= 0;
2989 // -----------------------------------------------------------------------
2991 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2993 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2995 m_chgInfo_changedProperty
= NULL
;
2997 if ( PerformValidation(p
, newValue
) )
2999 DoPropertyChanged(p
);
3004 OnValidationFailure(p
, newValue
);
3010 // -----------------------------------------------------------------------
3012 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
3014 wxPGProperty
* prop
= GetSelectedProperty();
3017 return wxNullVariant
;
3019 wxTextCtrl
* tc
= GetEditorTextCtrl();
3020 wxVariant value
= prop
->GetValue();
3022 if ( !tc
|| !IsEditorsValueModified() )
3025 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
3028 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
3029 return prop
->GetValue();
3034 // -----------------------------------------------------------------------
3036 // Runs wxValidator for the selected property
3037 bool wxPropertyGrid::DoEditorValidate()
3042 // -----------------------------------------------------------------------
3044 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
3046 wxPGProperty
* selected
= GetSelection();
3048 // Somehow, event is handled after property has been deselected.
3049 // Possibly, but very rare.
3050 if ( !selected
|| selected
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3053 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
3056 wxVariant
pendingValue(selected
->GetValueRef());
3057 wxWindow
* wnd
= GetEditorControl();
3058 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
3060 bool wasUnspecified
= selected
->IsValueUnspecified();
3061 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3062 bool valueIsPending
= false;
3064 m_chgInfo_changedProperty
= NULL
;
3066 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3069 // Filter out excess wxTextCtrl modified events
3070 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3072 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3074 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3076 wxString newTcValue
= tc
->GetValue();
3077 if ( m_prevTcValue
== newTcValue
)
3080 m_prevTcValue
= newTcValue
;
3083 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3085 bool validationFailure
= false;
3086 bool buttonWasHandled
= false;
3089 // Try common button handling
3090 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3092 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3096 buttonWasHandled
= true;
3097 // Store as res2, as previously (and still currently alternatively)
3098 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3099 // in wxPGProperty::OnEvent().
3100 adapter
->ShowDialog( this, selected
);
3105 if ( !buttonWasHandled
)
3107 if ( wnd
|| m_wndEditor2
)
3109 // First call editor class' event handler.
3110 const wxPGEditor
* editor
= selected
->GetEditorClass();
3112 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
3114 // If changes, validate them
3115 if ( DoEditorValidate() )
3117 if ( editor
->GetValueFromControl( pendingValue
,
3120 valueIsPending
= true;
3124 validationFailure
= true;
3129 // Then the property's custom handler (must be always called, unless
3130 // validation failed).
3131 if ( !validationFailure
)
3132 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
3135 // SetValueInEvent(), as called in one of the functions referred above
3136 // overrides editor's value.
3137 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3139 valueIsPending
= true;
3140 pendingValue
= m_changeInEventValue
;
3141 selFlags
|= wxPG_SEL_DIALOGVAL
;
3144 if ( !validationFailure
&& valueIsPending
)
3145 if ( !PerformValidation(selected
, pendingValue
) )
3146 validationFailure
= true;
3148 if ( validationFailure
)
3150 OnValidationFailure(selected
, pendingValue
);
3152 else if ( valueIsPending
)
3154 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3156 DoPropertyChanged(selected
, selFlags
);
3157 EditorsValueWasNotModified();
3159 // Regardless of editor type, unfocus editor on
3160 // text-editing related enter press.
3161 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3168 // No value after all
3170 // Regardless of editor type, unfocus editor on
3171 // text-editing related enter press.
3172 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3177 // Let unhandled button click events go to the parent
3178 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3180 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3181 GetEventHandler()->AddPendingEvent(evt
);
3185 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3188 // -----------------------------------------------------------------------
3189 // wxPropertyGrid editor control helper methods
3190 // -----------------------------------------------------------------------
3192 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3194 int itemy
= p
->GetY2(m_lineHeight
);
3196 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3197 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3198 int imageOffset
= 0;
3200 // TODO: If custom image detection changes from current, change this.
3201 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3203 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3204 int iw
= p
->OnMeasureImage().x
;
3206 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3207 imageOffset
= p
->GetImageOffset(iw
);
3212 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3214 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3219 // -----------------------------------------------------------------------
3221 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3223 wxSize sz
= GetImageSize(p
, item
);
3224 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3225 wxPG_CUSTOM_IMAGE_SPACINGY
,
3230 // return size of custom paint image
3231 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3233 // If called with NULL property, then return default image
3234 // size for properties that use image.
3236 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3238 wxSize cis
= p
->OnMeasureImage(item
);
3240 int choiceCount
= p
->m_choices
.GetCount();
3241 int comVals
= p
->GetDisplayedCommonValueCount();
3242 if ( item
>= choiceCount
&& comVals
> 0 )
3244 unsigned int cvi
= item
-choiceCount
;
3245 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3247 else if ( item
>= 0 && choiceCount
== 0 )
3248 return wxSize(0, 0);
3253 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3258 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3265 // -----------------------------------------------------------------------
3267 // takes scrolling into account
3268 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3271 GetViewStart(&vx
,&vy
);
3272 vy
*=wxPG_PIXELS_PER_UNIT
;
3273 vx
*=wxPG_PIXELS_PER_UNIT
;
3276 ClientToScreen( px
, py
);
3279 // -----------------------------------------------------------------------
3281 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3284 GetViewStart(&pt2
.x
,&pt2
.y
);
3285 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3286 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3290 return m_pState
->HitTest(pt2
);
3293 // -----------------------------------------------------------------------
3295 // custom set cursor
3296 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3298 if ( type
== m_curcursor
&& !override
) return;
3300 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3302 if ( type
== wxCURSOR_SIZEWE
)
3303 cursor
= m_cursorSizeWE
;
3305 m_canvas
->SetCursor( *cursor
);
3310 // -----------------------------------------------------------------------
3311 // wxPropertyGrid property selection, editor creation
3312 // -----------------------------------------------------------------------
3315 // This class forwards events from property editor controls to wxPropertyGrid.
3316 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3319 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3320 : wxEvtHandler(), m_propGrid(propGrid
)
3324 virtual ~wxPropertyGridEditorEventForwarder()
3329 bool ProcessEvent( wxEvent
& event
)
3334 m_propGrid
->HandleCustomEditorEvent(event
);
3336 return wxEvtHandler::ProcessEvent(event
);
3339 wxPropertyGrid
* m_propGrid
;
3342 // Setups event handling for child control
3343 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3345 wxWindowID id
= argWnd
->GetId();
3347 if ( argWnd
== m_wndEditor
)
3349 argWnd
->Connect(id
, wxEVT_MOTION
,
3350 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3352 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3353 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3355 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3356 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3358 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3359 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3361 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3362 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3364 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3365 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3369 wxPropertyGridEditorEventForwarder
* forwarder
;
3370 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3371 argWnd
->PushEventHandler(forwarder
);
3373 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3374 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3378 void wxPropertyGrid::FreeEditors()
3381 // Return focus back to canvas from children (this is required at least for
3382 // GTK+, which, unlike Windows, clears focus when control is destroyed
3383 // instead of moving it to closest parent).
3384 wxWindow
* focus
= wxWindow::FindFocus();
3387 wxWindow
* parent
= focus
->GetParent();
3390 if ( parent
== m_canvas
)
3395 parent
= parent
->GetParent();
3399 // Do not free editors immediately if processing events
3402 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3403 m_wndEditor2
->Hide();
3404 wxPendingDelete
.Append( handler
);
3405 wxPendingDelete
.Append( m_wndEditor2
);
3406 m_wndEditor2
= NULL
;
3411 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3412 m_wndEditor
->Hide();
3413 wxPendingDelete
.Append( handler
);
3414 wxPendingDelete
.Append( m_wndEditor
);
3419 // Call with NULL to de-select property
3420 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3425 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3426 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3430 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3434 if ( m_inDoSelectProperty
)
3437 m_inDoSelectProperty
= 1;
3441 m_inDoSelectProperty
= 0;
3445 wxArrayPGProperty prevSelection
= m_pState
->m_selection
;
3446 wxPGProperty
* prevFirstSel
;
3448 if ( prevSelection
.size() > 0 )
3449 prevFirstSel
= prevSelection
[0];
3451 prevFirstSel
= NULL
;
3453 if ( prevFirstSel
&& prevFirstSel
->HasFlag(wxPG_PROP_BEING_DELETED
) )
3454 prevFirstSel
= NULL
;
3458 wxPrintf( "Selected %s\n", prevFirstSel->GetClassInfo()->GetClassName() );
3460 wxPrintf( "None selected\n" );
3463 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3465 wxPrintf( "P = NULL\n" );
3468 // If we are frozen, then just set the values.
3471 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3472 m_editorFocused
= 0;
3474 m_pState
->DoSetSelection(p
);
3476 // If frozen, always free controls. But don't worry, as Thaw will
3477 // recall SelectProperty to recreate them.
3480 // Prevent any further selection measures in this call
3486 if ( prevFirstSel
== p
&&
3487 prevSelection
.size() <= 1 &&
3488 !(flags
& wxPG_SEL_FORCE
) )
3490 // Only set focus if not deselecting
3493 if ( flags
& wxPG_SEL_FOCUS
)
3497 m_wndEditor
->SetFocus();
3498 m_editorFocused
= 1;
3507 m_inDoSelectProperty
= 0;
3512 // First, deactivate previous
3515 OnValidationFailureReset(prevFirstSel
);
3517 // Must double-check if this is an selected in case of forceswitch
3518 if ( p
!= prevFirstSel
)
3520 if ( !CommitChangesFromEditor(flags
) )
3522 // Validation has failed, so we can't exit the previous editor
3523 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3524 // _("Invalid Value"),wxOK|wxICON_ERROR);
3525 m_inDoSelectProperty
= 0;
3533 // We need to always fully refresh the grid here
3536 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3537 EditorsValueWasNotModified();
3540 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3542 m_pState
->DoSetSelection(p
);
3545 // Then, activate the one given.
3548 int propY
= p
->GetY2(m_lineHeight
);
3550 int splitterX
= GetSplitterPosition();
3551 m_editorFocused
= 0;
3552 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3553 if ( p
!= prevFirstSel
)
3554 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3556 wxASSERT( m_wndEditor
== NULL
);
3559 // Only create editor for non-disabled non-caption
3560 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3562 // do this for non-caption items
3566 // Do we need to paint the custom image, if any?
3567 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3568 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3569 !p
->GetEditorClass()->CanContainCustomImage()
3571 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3573 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3574 wxPoint goodPos
= grect
.GetPosition();
3575 #if wxPG_CREATE_CONTROLS_HIDDEN
3576 int coord_adjust
= m_height
- goodPos
.y
;
3577 goodPos
.y
+= coord_adjust
;
3580 const wxPGEditor
* editor
= p
->GetEditorClass();
3581 wxCHECK_MSG(editor
, false,
3582 wxT("NULL editor class not allowed"));
3584 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3586 wxPGWindowList wndList
= editor
->CreateControls(this,
3591 m_wndEditor
= wndList
.m_primary
;
3592 m_wndEditor2
= wndList
.m_secondary
;
3593 wxWindow
* primaryCtrl
= GetEditorControl();
3596 // Essentially, primaryCtrl == m_wndEditor
3599 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3600 // value is drawn as normal, and m_wndEditor2 is assumed
3601 // to be a right-aligned button that triggers a separate editorCtrl
3606 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3607 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3609 // Set validator, if any
3610 #if wxUSE_VALIDATORS
3611 wxValidator
* validator
= p
->GetValidator();
3613 primaryCtrl
->SetValidator(*validator
);
3616 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3617 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3619 // If it has modified status, use bold font
3620 // (must be done before capturing m_ctrlXAdjust)
3621 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3622 SetCurControlBoldFont();
3625 // Fix TextCtrl indentation
3626 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3627 wxTextCtrl
* tc
= NULL
;
3628 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3629 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3631 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3633 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3636 // Store x relative to splitter (we'll need it).
3637 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3639 // Check if background clear is not necessary
3640 wxPoint pos
= m_wndEditor
->GetPosition();
3641 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3643 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3646 m_wndEditor
->SetSizeHints(3, 3);
3648 #if wxPG_CREATE_CONTROLS_HIDDEN
3649 m_wndEditor
->Show(false);
3650 m_wndEditor
->Freeze();
3652 goodPos
= m_wndEditor
->GetPosition();
3653 goodPos
.y
-= coord_adjust
;
3654 m_wndEditor
->Move( goodPos
);
3657 SetupChildEventHandling(primaryCtrl
);
3659 // Focus and select all (wxTextCtrl, wxComboBox etc)
3660 if ( flags
& wxPG_SEL_FOCUS
)
3662 primaryCtrl
->SetFocus();
3664 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3670 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3671 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3673 // Get proper id for wndSecondary
3674 m_wndSecId
= m_wndEditor2
->GetId();
3675 wxWindowList children
= m_wndEditor2
->GetChildren();
3676 wxWindowList::iterator node
= children
.begin();
3677 if ( node
!= children
.end() )
3678 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3680 m_wndEditor2
->SetSizeHints(3,3);
3682 #if wxPG_CREATE_CONTROLS_HIDDEN
3683 wxRect sec_rect
= m_wndEditor2
->GetRect();
3684 sec_rect
.y
-= coord_adjust
;
3686 // Fine tuning required to fix "oversized"
3687 // button disappearance bug.
3688 if ( sec_rect
.y
< 0 )
3690 sec_rect
.height
+= sec_rect
.y
;
3693 m_wndEditor2
->SetSize( sec_rect
);
3695 m_wndEditor2
->Show();
3697 SetupChildEventHandling(m_wndEditor2
);
3699 // If no primary editor, focus to button to allow
3700 // it to interprete ENTER etc.
3701 // NOTE: Due to problems focusing away from it, this
3702 // has been disabled.
3704 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3705 m_wndEditor2->SetFocus();
3709 if ( flags
& wxPG_SEL_FOCUS
)
3710 m_editorFocused
= 1;
3715 // Make sure focus is in grid canvas (important for wxGTK, at least)
3719 EditorsValueWasNotModified();
3721 // If it's inside collapsed section, expand parent, scroll, etc.
3722 // Also, if it was partially visible, scroll it into view.
3723 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3728 #if wxPG_CREATE_CONTROLS_HIDDEN
3729 m_wndEditor
->Thaw();
3731 m_wndEditor
->Show(true);
3738 // Make sure focus is in grid canvas
3742 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3748 // Show help text in status bar.
3749 // (if found and grid not embedded in manager with help box and
3750 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3753 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3755 wxStatusBar
* statusbar
= NULL
;
3756 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3758 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3760 statusbar
= frame
->GetStatusBar();
3765 const wxString
* pHelpString
= (const wxString
*) NULL
;
3769 pHelpString
= &p
->GetHelpString();
3770 if ( pHelpString
->length() )
3772 // Set help box text.
3773 statusbar
->SetStatusText( *pHelpString
);
3774 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3778 if ( (!pHelpString
|| !pHelpString
->length()) &&
3779 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3781 // Clear help box - but only if it was written
3782 // by us at previous time.
3783 statusbar
->SetStatusText( m_emptyString
);
3784 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3790 m_inDoSelectProperty
= 0;
3792 // call wx event handler (here so that it also occurs on deselection)
3793 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
3794 SendEvent( wxEVT_PG_SELECTED
, p
, NULL
, flags
);
3799 // -----------------------------------------------------------------------
3801 bool wxPropertyGrid::UnfocusEditor()
3803 wxPGProperty
* selected
= GetSelection();
3805 if ( !selected
|| !m_wndEditor
|| m_frozen
)
3808 if ( !CommitChangesFromEditor(0) )
3817 // -----------------------------------------------------------------------
3819 void wxPropertyGrid::RefreshEditor()
3821 wxPGProperty
* p
= GetSelection();
3825 wxWindow
* wnd
= GetEditorControl();
3829 // Set editor font boldness - must do this before
3830 // calling UpdateControl().
3831 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3833 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3834 wnd
->SetFont(GetCaptionFont());
3836 wnd
->SetFont(GetFont());
3839 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3841 editorClass
->UpdateControl(p
, wnd
);
3843 if ( p
->IsValueUnspecified() )
3844 editorClass
->SetValueToUnspecified(p
, wnd
);
3847 // -----------------------------------------------------------------------
3849 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
3851 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3853 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
3855 flags
|= wxPG_SEL_FOCUS
;
3857 return DoSelectProperty(p
, flags
);
3860 // -----------------------------------------------------------------------
3861 // wxPropertyGrid expand/collapse state
3862 // -----------------------------------------------------------------------
3864 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3866 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3867 wxPGProperty
* selected
= GetSelection();
3869 // If active editor was inside collapsed section, then disable it
3870 if ( selected
&& selected
->IsSomeParent(p
) )
3875 // Store dont-center-splitter flag 'cause we need to temporarily set it
3876 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3877 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3879 bool res
= m_pState
->DoCollapse(pwc
);
3884 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3886 RecalculateVirtualSize();
3888 // Redraw etc. only if collapsed was visible.
3889 if (pwc
->IsVisible() &&
3891 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3893 // When item is collapsed so that scrollbar would move,
3894 // graphics mess is about (unless we redraw everything).
3899 // Clear dont-center-splitter flag if it wasn't set
3900 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3905 // -----------------------------------------------------------------------
3907 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3909 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3911 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3913 // Store dont-center-splitter flag 'cause we need to temporarily set it
3914 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3915 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3917 bool res
= m_pState
->DoExpand(pwc
);
3922 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3924 RecalculateVirtualSize();
3926 // Redraw etc. only if expanded was visible.
3927 if ( pwc
->IsVisible() && !m_frozen
&&
3928 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3932 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3935 DrawItems(pwc
, NULL
);
3940 // Clear dont-center-splitter flag if it wasn't set
3941 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3946 // -----------------------------------------------------------------------
3948 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3951 return m_pState
->DoHideProperty(p
, hide
, flags
);
3953 wxArrayPGProperty selection
= m_pState
->m_selection
; // Must use a copy
3954 int selRemoveCount
= 0;
3955 for ( unsigned int i
=0; i
<selection
.size(); i
++ )
3957 wxPGProperty
* selected
= selection
[i
];
3958 if ( selected
== p
|| selected
->IsSomeParent(p
) )
3960 if ( !DoRemoveFromSelection(p
, flags
) )
3962 selRemoveCount
+= 1;
3966 m_pState
->DoHideProperty(p
, hide
, flags
);
3968 RecalculateVirtualSize();
3975 // -----------------------------------------------------------------------
3976 // wxPropertyGrid size related methods
3977 // -----------------------------------------------------------------------
3979 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3981 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3985 // If virtual height was changed, then recalculate editor control position(s)
3986 if ( m_pState
->m_vhCalcPending
)
3987 CorrectEditorWidgetPosY();
3989 m_pState
->EnsureVirtualHeight();
3991 wxASSERT_LEVEL_2_MSG(
3992 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
3993 "VirtualHeight and ActualVirtualHeight should match"
3996 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3998 int x
= m_pState
->m_width
;
3999 int y
= m_pState
->m_virtualHeight
;
4002 GetClientSize(&width
,&height
);
4004 // Now adjust virtual size.
4005 SetVirtualSize(x
, y
);
4011 // Adjust scrollbars
4012 if ( HasVirtualWidth() )
4014 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4015 xPos
= GetScrollPos( wxHORIZONTAL
);
4018 if ( forceXPos
!= -1 )
4021 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4024 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
4025 int yPos
= GetScrollPos( wxVERTICAL
);
4027 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4028 xAmount
, yAmount
, xPos
, yPos
, true );
4030 // Must re-get size now
4031 GetClientSize(&width
,&height
);
4033 if ( !HasVirtualWidth() )
4035 m_pState
->SetVirtualWidth(width
);
4042 m_canvas
->SetSize( x
, y
);
4044 m_pState
->CheckColumnWidths();
4046 if ( GetSelection() )
4047 CorrectEditorWidgetSizeX();
4049 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4052 // -----------------------------------------------------------------------
4054 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4056 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4060 GetClientSize(&width
,&height
);
4065 #if wxPG_DOUBLE_BUFFER
4066 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4068 int dblh
= (m_lineHeight
*2);
4069 if ( !m_doubleBuffer
)
4071 // Create double buffer bitmap to draw on, if none
4072 int w
= (width
>250)?width
:250;
4073 int h
= height
+ dblh
;
4075 m_doubleBuffer
= new wxBitmap( w
, h
);
4079 int w
= m_doubleBuffer
->GetWidth();
4080 int h
= m_doubleBuffer
->GetHeight();
4082 // Double buffer must be large enough
4083 if ( w
< width
|| h
< (height
+dblh
) )
4085 if ( w
< width
) w
= width
;
4086 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4087 delete m_doubleBuffer
;
4088 m_doubleBuffer
= new wxBitmap( w
, h
);
4095 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4096 m_ncWidth
= event
.GetSize().x
;
4100 if ( m_pState
->m_itemsAdded
)
4101 PrepareAfterItemsAdded();
4103 // Without this, virtual size (atleast under wxGTK) will be skewed
4104 RecalculateVirtualSize();
4110 // -----------------------------------------------------------------------
4112 void wxPropertyGrid::SetVirtualWidth( int width
)
4116 // Disable virtual width
4117 width
= GetClientSize().x
;
4118 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4122 // Enable virtual width
4123 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4125 m_pState
->SetVirtualWidth( width
);
4128 void wxPropertyGrid::SetFocusOnCanvas()
4130 m_canvas
->SetFocusIgnoringChildren();
4131 m_editorFocused
= 0;
4134 // -----------------------------------------------------------------------
4135 // wxPropertyGrid mouse event handling
4136 // -----------------------------------------------------------------------
4138 // selFlags uses same values DoSelectProperty's flags
4139 // Returns true if event was vetoed.
4140 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4142 // Send property grid event of specific type and with specific property
4143 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4144 evt
.SetPropertyGrid(this);
4145 evt
.SetEventObject(m_eventObject
);
4149 evt
.SetCanVeto(true);
4150 evt
.SetupValidationInfo();
4151 m_validationInfo
.m_pValue
= pValue
;
4153 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4155 evtHandler
->ProcessEvent(evt
);
4157 return evt
.WasVetoed();
4160 // -----------------------------------------------------------------------
4162 // Return false if should be skipped
4163 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4167 // Need to set focus?
4168 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4173 wxPropertyGridPageState
* state
= m_pState
;
4175 int splitterHitOffset
;
4176 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4178 wxPGProperty
* p
= DoGetItemAtY(y
);
4182 int depth
= (int)p
->GetDepth() - 1;
4184 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4186 if ( x
>= marginEnds
)
4190 if ( p
->IsCategory() )
4192 // This is category.
4193 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4195 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4197 // Expand, collapse, activate etc. if click on text or left of splitter.
4200 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4205 if ( !AddToSelectionFromInputEvent( p
, &event
) )
4208 // On double-click, expand/collapse.
4209 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4211 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4212 else DoExpand( p
, true );
4216 else if ( splitterHit
== -1 )
4219 unsigned int selFlag
= 0;
4220 if ( columnHit
== 1 )
4222 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4223 selFlag
= wxPG_SEL_FOCUS
;
4225 if ( !AddToSelectionFromInputEvent( p
, &event
, selFlag
) )
4228 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4230 if ( p
->GetChildCount() && !p
->IsCategory() )
4231 // On double-click, expand/collapse.
4232 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4234 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4235 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4236 else DoExpand( p
, true );
4243 // click on splitter
4244 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4246 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4248 // Double-clicking the splitter causes auto-centering
4249 CenterSplitter( true );
4251 else if ( m_dragStatus
== 0 )
4254 // Begin draggin the splitter
4258 // Changes must be committed here or the
4259 // value won't be drawn correctly
4260 if ( !CommitChangesFromEditor() )
4263 m_wndEditor
->Show ( false );
4266 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4268 m_canvas
->CaptureMouse();
4269 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4273 m_draggedSplitter
= splitterHit
;
4274 m_dragOffset
= splitterHitOffset
;
4276 wxClientDC
dc(m_canvas
);
4278 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4279 // Fixes button disappearance bug
4281 m_wndEditor2
->Show ( false );
4284 m_startingSplitterX
= x
- splitterHitOffset
;
4292 if ( p
->GetChildCount() )
4294 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4296 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4298 int y2
= y
% m_lineHeight
;
4299 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4301 // On click on expander button, expand/collapse
4302 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4303 DoCollapse( p
, true );
4305 DoExpand( p
, true );
4314 // -----------------------------------------------------------------------
4316 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
),
4317 unsigned int WXUNUSED(y
),
4318 wxMouseEvent
& event
)
4322 // Select property here as well
4323 wxPGProperty
* p
= m_propHover
;
4324 AddToSelectionFromInputEvent(p
, &event
);
4326 // Send right click event.
4327 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4334 // -----------------------------------------------------------------------
4336 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
),
4337 unsigned int WXUNUSED(y
),
4338 wxMouseEvent
& event
)
4342 // Select property here as well
4343 wxPGProperty
* p
= m_propHover
;
4345 AddToSelectionFromInputEvent(p
, &event
);
4347 // Send double-click event.
4348 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4355 // -----------------------------------------------------------------------
4357 #if wxPG_SUPPORT_TOOLTIPS
4359 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4361 if ( tipString
.length() )
4363 m_canvas
->SetToolTip(tipString
);
4367 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4368 m_canvas
->SetToolTip( m_emptyString
);
4370 m_canvas
->SetToolTip( NULL
);
4375 #endif // #if wxPG_SUPPORT_TOOLTIPS
4377 // -----------------------------------------------------------------------
4379 // Return false if should be skipped
4380 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4382 // Safety check (needed because mouse capturing may
4383 // otherwise freeze the control)
4384 if ( m_dragStatus
> 0 && !event
.Dragging() )
4386 HandleMouseUp(x
,y
,event
);
4389 wxPropertyGridPageState
* state
= m_pState
;
4391 int splitterHitOffset
;
4392 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4393 int splitterX
= x
- splitterHitOffset
;
4395 if ( m_dragStatus
> 0 )
4397 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4398 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4401 int newSplitterX
= x
- m_dragOffset
;
4402 int splitterX
= x
- splitterHitOffset
;
4404 // Splitter redraw required?
4405 if ( newSplitterX
!= splitterX
)
4408 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4409 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4410 state
->m_fSplitterX
= (float) newSplitterX
;
4412 if ( GetSelection() )
4413 CorrectEditorWidgetSizeX();
4427 int ih
= m_lineHeight
;
4430 #if wxPG_SUPPORT_TOOLTIPS
4431 wxPGProperty
* prevHover
= m_propHover
;
4432 unsigned char prevSide
= m_mouseSide
;
4434 int curPropHoverY
= y
- (y
% ih
);
4436 // On which item it hovers
4439 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4442 // Mouse moves on another property
4444 m_propHover
= DoGetItemAtY(y
);
4445 m_propHoverY
= curPropHoverY
;
4448 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4451 #if wxPG_SUPPORT_TOOLTIPS
4452 // Store which side we are on
4454 if ( columnHit
== 1 )
4456 else if ( columnHit
== 0 )
4460 // If tooltips are enabled, show label or value as a tip
4461 // in case it doesn't otherwise show in full length.
4463 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4465 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4467 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4469 if ( m_propHover
&& !m_propHover
->IsCategory() )
4472 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4474 // Show help string as a tooltip
4475 wxString tipString
= m_propHover
->GetHelpString();
4477 SetToolTip(tipString
);
4481 // Show cropped value string as a tooltip
4485 if ( m_mouseSide
== 1 )
4487 tipString
= m_propHover
->m_label
;
4488 space
= splitterX
-m_marginWidth
-3;
4490 else if ( m_mouseSide
== 2 )
4492 tipString
= m_propHover
->GetDisplayedString();
4494 space
= m_width
- splitterX
;
4495 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4496 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4502 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4505 SetToolTip( tipString
);
4512 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4513 m_canvas
->SetToolTip( m_emptyString
);
4515 m_canvas
->SetToolTip( NULL
);
4526 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4527 m_canvas
->SetToolTip( m_emptyString
);
4529 m_canvas
->SetToolTip( NULL
);
4537 if ( splitterHit
== -1 ||
4539 HasFlag(wxPG_STATIC_SPLITTER
) )
4541 // hovering on something else
4542 if ( m_curcursor
!= wxCURSOR_ARROW
)
4543 CustomSetCursor( wxCURSOR_ARROW
);
4547 // Do not allow splitter cursor on caption items.
4548 // (also not if we were dragging and its started
4549 // outside the splitter region)
4551 if ( !m_propHover
->IsCategory() &&
4555 // hovering on splitter
4557 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4558 // reliably detected.
4559 //if ( m_curcursor != wxCURSOR_SIZEWE )
4560 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4566 // hovering on something else
4567 if ( m_curcursor
!= wxCURSOR_ARROW
)
4568 CustomSetCursor( wxCURSOR_ARROW
);
4573 // Multi select by dragging
4575 if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION
&&
4576 event
.LeftIsDown() &&
4579 !state
->DoIsPropertySelected(m_propHover
) )
4581 DoAddToSelection(m_propHover
);
4587 // -----------------------------------------------------------------------
4589 // Also handles Leaving event
4590 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4591 wxMouseEvent
&WXUNUSED(event
) )
4593 wxPropertyGridPageState
* state
= m_pState
;
4597 int splitterHitOffset
;
4598 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4600 // No event type check - basicly calling this method should
4601 // just stop dragging.
4602 // Left up after dragged?
4603 if ( m_dragStatus
>= 1 )
4606 // End Splitter Dragging
4608 // DO NOT ENABLE FOLLOWING LINE!
4609 // (it is only here as a reminder to not to do it)
4612 // Disable splitter auto-centering
4613 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4615 // This is necessary to return cursor
4616 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4618 m_canvas
->ReleaseMouse();
4619 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4622 // Set back the default cursor, if necessary
4623 if ( splitterHit
== -1 ||
4626 CustomSetCursor( wxCURSOR_ARROW
);
4631 // Control background needs to be cleared
4632 wxPGProperty
* selected
= GetSelection();
4633 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && selected
)
4634 DrawItem( selected
);
4638 m_wndEditor
->Show ( true );
4641 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4642 // Fixes button disappearance bug
4644 m_wndEditor2
->Show ( true );
4647 // This clears the focus.
4648 m_editorFocused
= 0;
4654 // -----------------------------------------------------------------------
4656 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4658 int splitterX
= GetSplitterPosition();
4661 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4665 wxWindow
* wnd
= GetEditorControl();
4667 // Hide popup on clicks
4668 if ( event
.GetEventType() != wxEVT_MOTION
)
4669 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4671 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4677 if ( wnd
== NULL
|| m_dragStatus
||
4679 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4680 ux
>= (r
.x
+r
.width
) ||
4682 event
.m_y
>= (r
.y
+r
.height
)
4692 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4697 // -----------------------------------------------------------------------
4699 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4702 if ( OnMouseCommon( event
, &x
, &y
) )
4704 HandleMouseClick(x
,y
,event
);
4709 // -----------------------------------------------------------------------
4711 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4714 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4715 HandleMouseRightClick(x
,y
,event
);
4719 // -----------------------------------------------------------------------
4721 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4723 // Always run standard mouse-down handler as well
4724 OnMouseClick(event
);
4727 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4728 HandleMouseDoubleClick(x
,y
,event
);
4732 // -----------------------------------------------------------------------
4734 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4737 if ( OnMouseCommon( event
, &x
, &y
) )
4739 HandleMouseMove(x
,y
,event
);
4744 // -----------------------------------------------------------------------
4746 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4748 // Called when mouse moves in the empty space below the properties.
4749 CustomSetCursor( wxCURSOR_ARROW
);
4752 // -----------------------------------------------------------------------
4754 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4757 if ( OnMouseCommon( event
, &x
, &y
) )
4759 HandleMouseUp(x
,y
,event
);
4764 // -----------------------------------------------------------------------
4766 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4768 // This may get called from child control as well, so event's
4769 // mouse position cannot be relied on.
4771 if ( event
.Entering() )
4773 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4775 // TODO: Fix this (detect parent and only do
4776 // cursor trick if it is a manager).
4777 wxASSERT( GetParent() );
4778 GetParent()->SetCursor(wxNullCursor
);
4780 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4783 GetParent()->SetCursor(wxNullCursor
);
4785 else if ( event
.Leaving() )
4787 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4788 m_canvas
->SetCursor( wxNullCursor
);
4790 // Get real cursor position
4791 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4793 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4796 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4798 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4802 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4810 // -----------------------------------------------------------------------
4812 // Common code used by various OnMouseXXXChild methods.
4813 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4815 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4816 wxASSERT( topCtrlWnd
);
4818 event
.GetPosition(&x
,&y
);
4820 int splitterX
= GetSplitterPosition();
4822 wxRect r
= topCtrlWnd
->GetRect();
4823 if ( !m_dragStatus
&&
4824 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4825 y
>= 0 && y
< r
.height \
4828 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4833 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4840 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4843 if ( OnMouseChildCommon(event
,&x
,&y
) )
4845 bool res
= HandleMouseClick(x
,y
,event
);
4846 if ( !res
) event
.Skip();
4850 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4853 wxASSERT( m_wndEditor
);
4854 // These coords may not be exact (about +-2),
4855 // but that should not matter (right click is about item, not position).
4856 wxPoint pt
= m_wndEditor
->GetPosition();
4857 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4859 // FIXME: Used to set m_propHover to selection here. Was it really
4862 bool res
= HandleMouseRightClick(x
,y
,event
);
4863 if ( !res
) event
.Skip();
4866 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4869 if ( OnMouseChildCommon(event
,&x
,&y
) )
4871 bool res
= HandleMouseMove(x
,y
,event
);
4872 if ( !res
) event
.Skip();
4876 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4879 if ( OnMouseChildCommon(event
,&x
,&y
) )
4881 bool res
= HandleMouseUp(x
,y
,event
);
4882 if ( !res
) event
.Skip();
4886 // -----------------------------------------------------------------------
4887 // wxPropertyGrid keyboard event handling
4888 // -----------------------------------------------------------------------
4890 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4892 // Translates wxKeyEvent to wxPG_ACTION_XXX
4894 int keycode
= event
.GetKeyCode();
4895 int modifiers
= event
.GetModifiers();
4897 wxASSERT( !(modifiers
&~(0xFFFF)) );
4899 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4901 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4903 if ( it
== m_actionTriggers
.end() )
4908 int second
= (it
->second
>>16) & 0xFFFF;
4912 return (it
->second
& 0xFFFF);
4915 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4917 wxASSERT( !(modifiers
&~(0xFFFF)) );
4919 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4921 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4923 if ( it
!= m_actionTriggers
.end() )
4925 // This key combination is already used
4927 // Can add secondary?
4928 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4929 wxT("You can only add up to two separate actions per key combination.") );
4931 action
= it
->second
| (action
<<16);
4934 m_actionTriggers
[hashMapKey
] = action
;
4937 void wxPropertyGrid::ClearActionTriggers( int action
)
4939 wxPGHashMapI2I::iterator it
;
4941 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4943 if ( it
->second
== action
)
4945 m_actionTriggers
.erase(it
);
4950 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4953 // Handles key event when editor control is not focused.
4956 wxCHECK2(!m_frozen
, return);
4958 // Travelsal between items, collapsing/expanding, etc.
4959 wxPGProperty
* selected
= GetSelection();
4960 int keycode
= event
.GetKeyCode();
4961 bool editorFocused
= IsEditorFocused();
4963 if ( keycode
== WXK_TAB
)
4965 wxWindow
* mainControl
;
4967 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4968 mainControl
= GetParent();
4972 if ( !event
.ShiftDown() )
4974 if ( !editorFocused
&& m_wndEditor
)
4976 DoSelectProperty( selected
, wxPG_SEL_FOCUS
);
4980 // Tab traversal workaround for platforms on which
4981 // wxWindow::Navigate() may navigate into first child
4982 // instead of next sibling. Does not work perfectly
4983 // in every scenario (for instance, when property grid
4984 // is either first or last control).
4985 #if defined(__WXGTK__)
4986 wxWindow
* sibling
= mainControl
->GetNextSibling();
4988 sibling
->SetFocusFromKbd();
4990 Navigate(wxNavigationKeyEvent::IsForward
);
4996 if ( editorFocused
)
5002 #if defined(__WXGTK__)
5003 wxWindow
* sibling
= mainControl
->GetPrevSibling();
5005 sibling
->SetFocusFromKbd();
5007 Navigate(wxNavigationKeyEvent::IsBackward
);
5015 // Ignore Alt and Control when they are down alone
5016 if ( keycode
== WXK_ALT
||
5017 keycode
== WXK_CONTROL
)
5024 int action
= KeyEventToActions(event
, &secondAction
);
5026 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
5029 // Esc cancels any changes
5030 if ( IsEditorsValueModified() )
5032 EditorsValueWasNotModified();
5034 // Update the control as well
5035 selected
->GetEditorClass()->
5036 SetControlStringValue( selected
,
5038 selected
->GetDisplayedString() );
5041 OnValidationFailureReset(selected
);
5047 // Except for TAB and ESC, handle child control events in child control
5050 // Only propagate event if it had modifiers
5051 if ( !event
.HasModifiers() )
5053 event
.StopPropagation();
5059 bool wasHandled
= false;
5064 if ( ButtonTriggerKeyTest(action
, event
) )
5067 wxPGProperty
* p
= selected
;
5069 // Travel and expand/collapse
5072 if ( p
->GetChildCount() )
5074 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5076 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5079 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5081 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5088 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5092 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5098 if ( selectDir
>= -1 )
5100 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5102 DoSelectProperty(p
);
5108 // If nothing was selected, select the first item now
5109 // (or navigate out of tab).
5110 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5112 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5113 if ( p
) DoSelectProperty(p
);
5122 // -----------------------------------------------------------------------
5124 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5126 // If there was editor open and focused, then this event should not
5127 // really be processed here.
5128 if ( IsEditorFocused() )
5130 // However, if event had modifiers, it is probably still best
5132 if ( event
.HasModifiers() )
5135 event
.StopPropagation();
5139 HandleKeyEvent(event
, false);
5142 // -----------------------------------------------------------------------
5144 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
5149 action
= KeyEventToActions(event
, &secondAction
);
5152 // Does the keycode trigger button?
5153 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
5156 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
5157 GetEventHandler()->AddPendingEvent(evt
);
5164 // -----------------------------------------------------------------------
5166 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5168 HandleKeyEvent(event
, true);
5171 // -----------------------------------------------------------------------
5172 // wxPropertyGrid miscellaneous event handling
5173 // -----------------------------------------------------------------------
5175 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5178 // Check if the focus is in this control or one of its children
5179 wxWindow
* newFocused
= wxWindow::FindFocus();
5181 if ( newFocused
!= m_curFocused
)
5182 HandleFocusChange( newFocused
);
5185 // Check if top-level parent has changed
5186 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
5193 bool wxPropertyGrid::IsEditorFocused() const
5195 wxWindow
* focus
= wxWindow::FindFocus();
5197 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5198 focus
== GetEditorControl() )
5204 // Called by focus event handlers. newFocused is the window that becomes focused.
5205 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5207 unsigned int oldFlags
= m_iFlags
;
5209 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5211 wxWindow
* parent
= newFocused
;
5213 // This must be one of nextFocus' parents.
5216 // Use m_eventObject, which is either wxPropertyGrid or
5217 // wxPropertyGridManager, as appropriate.
5218 if ( parent
== m_eventObject
)
5220 m_iFlags
|= wxPG_FL_FOCUSED
;
5223 parent
= parent
->GetParent();
5226 m_curFocused
= newFocused
;
5228 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5229 (oldFlags
& wxPG_FL_FOCUSED
) )
5231 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5233 // Need to store changed value
5234 CommitChangesFromEditor();
5240 // Preliminary code for tab-order respecting
5241 // tab-traversal (but should be moved to
5244 wxWindow* prevFocus = event.GetWindow();
5245 wxWindow* useThis = this;
5246 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5247 useThis = GetParent();
5250 prevFocus->GetParent() == useThis->GetParent() )
5252 wxList& children = useThis->GetParent()->GetChildren();
5254 wxNode* node = children.Find(prevFocus);
5256 if ( node->GetNext() &&
5257 useThis == node->GetNext()->GetData() )
5258 DoSelectProperty(GetFirst());
5259 else if ( node->GetPrevious () &&
5260 useThis == node->GetPrevious()->GetData() )
5261 DoSelectProperty(GetLastProperty());
5268 wxPGProperty
* selected
= GetSelection();
5269 if ( selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5270 DrawItem( selected
);
5274 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5276 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5277 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5278 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5279 //else if ( event.GetWindow() )
5281 HandleFocusChange(event
.GetWindow());
5286 // -----------------------------------------------------------------------
5288 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5290 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5294 // -----------------------------------------------------------------------
5296 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5298 m_iFlags
|= wxPG_FL_SCROLLED
;
5303 // -----------------------------------------------------------------------
5305 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5307 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5309 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5313 // -----------------------------------------------------------------------
5314 // Property editor related functions
5315 // -----------------------------------------------------------------------
5317 // noDefCheck = true prevents infinite recursion.
5318 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5319 const wxString
& editorName
,
5322 wxASSERT( editorClass
);
5324 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5325 RegisterDefaultEditors();
5327 wxString name
= editorName
;
5328 if ( name
.length() == 0 )
5329 name
= editorClass
->GetName();
5331 // Existing editor under this name?
5332 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5334 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5336 // If this name was already used, try class name.
5337 name
= editorClass
->GetClassInfo()->GetClassName();
5338 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5341 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5342 (wxPGEditor
*) vt_it
->second
,
5343 "Editor with given name was already registered" );
5345 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5350 // Use this in RegisterDefaultEditors.
5351 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5352 if ( wxPGEditor_##EDITOR == NULL ) \
5354 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5355 new wxPG##EDITOR##Editor, true ); \
5358 // Registers all default editor classes
5359 void wxPropertyGrid::RegisterDefaultEditors()
5361 wxPGRegisterDefaultEditorClass( TextCtrl
);
5362 wxPGRegisterDefaultEditorClass( Choice
);
5363 wxPGRegisterDefaultEditorClass( ComboBox
);
5364 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5365 #if wxPG_INCLUDE_CHECKBOX
5366 wxPGRegisterDefaultEditorClass( CheckBox
);
5368 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5370 // Register SpinCtrl etc. editors before use
5371 RegisterAdditionalEditors();
5374 // -----------------------------------------------------------------------
5375 // wxPGStringTokenizer
5376 // Needed to handle C-style string lists (e.g. "str1" "str2")
5377 // -----------------------------------------------------------------------
5379 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5380 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5384 wxPGStringTokenizer::~wxPGStringTokenizer()
5388 bool wxPGStringTokenizer::HasMoreTokens()
5390 const wxString
& str
= *m_str
;
5392 wxString::const_iterator i
= m_curPos
;
5394 wxUniChar delim
= m_delimeter
;
5396 wxUniChar prev_a
= wxT('\0');
5398 bool inToken
= false;
5400 while ( i
!= str
.end() )
5409 m_readyToken
.clear();
5414 if ( prev_a
!= wxT('\\') )
5418 if ( a
!= wxT('\\') )
5438 m_curPos
= str
.end();
5446 wxString
wxPGStringTokenizer::GetNextToken()
5448 return m_readyToken
;
5451 // -----------------------------------------------------------------------
5453 // -----------------------------------------------------------------------
5455 wxPGChoiceEntry::wxPGChoiceEntry()
5456 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5460 // -----------------------------------------------------------------------
5462 // -----------------------------------------------------------------------
5464 wxPGChoicesData::wxPGChoicesData()
5468 wxPGChoicesData::~wxPGChoicesData()
5473 void wxPGChoicesData::Clear()
5478 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5480 wxASSERT( m_items
.size() == 0 );
5482 m_items
= data
->m_items
;
5485 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5486 const wxPGChoiceEntry
& item
)
5488 wxVector
<wxPGChoiceEntry
>::iterator it
;
5492 index
= (int) m_items
.size();
5496 it
= m_items
.begin() + index
;
5499 m_items
.insert(it
, item
);
5501 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5503 // Need to fix value?
5504 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5505 ownEntry
.SetValue(index
);
5510 // -----------------------------------------------------------------------
5511 // wxPropertyGridEvent
5512 // -----------------------------------------------------------------------
5514 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5517 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5518 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5519 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5520 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5521 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5522 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5523 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5524 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5525 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5528 // -----------------------------------------------------------------------
5530 void wxPropertyGridEvent::Init()
5532 m_validationInfo
= NULL
;
5534 m_wasVetoed
= false;
5537 // -----------------------------------------------------------------------
5539 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5540 : wxCommandEvent(commandType
,id
)
5546 // -----------------------------------------------------------------------
5548 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5549 : wxCommandEvent(event
)
5551 m_eventType
= event
.GetEventType();
5552 m_eventObject
= event
.m_eventObject
;
5554 m_property
= event
.m_property
;
5555 m_validationInfo
= event
.m_validationInfo
;
5556 m_canVeto
= event
.m_canVeto
;
5557 m_wasVetoed
= event
.m_wasVetoed
;
5560 // -----------------------------------------------------------------------
5562 wxPropertyGridEvent::~wxPropertyGridEvent()
5566 // -----------------------------------------------------------------------
5568 wxEvent
* wxPropertyGridEvent::Clone() const
5570 return new wxPropertyGridEvent( *this );
5573 // -----------------------------------------------------------------------
5574 // wxPropertyGridPopulator
5575 // -----------------------------------------------------------------------
5577 wxPropertyGridPopulator::wxPropertyGridPopulator()
5581 wxPGGlobalVars
->m_offline
++;
5584 // -----------------------------------------------------------------------
5586 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5589 m_propHierarchy
.clear();
5592 // -----------------------------------------------------------------------
5594 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5600 // -----------------------------------------------------------------------
5602 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5605 // Free unused sets of choices
5606 wxPGHashMapS2P::iterator it
;
5608 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5610 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5617 m_pg
->GetPanel()->Refresh();
5619 wxPGGlobalVars
->m_offline
--;
5622 // -----------------------------------------------------------------------
5624 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5625 const wxString
& propLabel
,
5626 const wxString
& propName
,
5627 const wxString
* propValue
,
5628 wxPGChoices
* pChoices
)
5630 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5631 wxPGProperty
* parent
= GetCurParent();
5633 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5635 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5639 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5641 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5645 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5647 property
->SetLabel(propLabel
);
5648 property
->DoSetName(propName
);
5650 if ( pChoices
&& pChoices
->IsOk() )
5651 property
->SetChoices(*pChoices
);
5653 m_state
->DoInsert(parent
, -1, property
);
5656 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5657 wxPG_PROGRAMMATIC_VALUE
);
5662 // -----------------------------------------------------------------------
5664 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5666 m_propHierarchy
.push_back(property
);
5667 DoScanForChildren();
5668 m_propHierarchy
.pop_back();
5671 // -----------------------------------------------------------------------
5673 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5674 const wxString
& idString
)
5676 wxPGChoices choices
;
5679 if ( choicesString
[0] == wxT('@') )
5681 wxString ids
= choicesString
.substr(1);
5682 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5683 if ( it
== m_dictIdChoices
.end() )
5684 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5686 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5691 if ( idString
.length() )
5693 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5694 if ( it
!= m_dictIdChoices
.end() )
5696 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5703 // Parse choices string
5704 wxString::const_iterator it
= choicesString
.begin();
5708 bool labelValid
= false;
5710 for ( ; it
!= choicesString
.end(); ++it
)
5716 if ( c
== wxT('"') )
5721 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5722 choices
.Add(label
, l
);
5725 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5730 else if ( c
== wxT('=') )
5737 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5744 if ( c
== wxT('"') )
5757 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5758 choices
.Add(label
, l
);
5761 if ( !choices
.IsOk() )
5763 choices
.EnsureData();
5767 if ( idString
.length() )
5768 m_dictIdChoices
[idString
] = choices
.GetData();
5775 // -----------------------------------------------------------------------
5777 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5779 if ( s
.Last() == wxT('%') )
5781 wxString s2
= s
.substr(0,s
.length()-1);
5783 if ( s2
.ToLong(&val
, 10) )
5785 *pval
= (val
*max
)/100;
5791 return s
.ToLong(pval
, 10);
5794 // -----------------------------------------------------------------------
5796 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5797 const wxString
& type
,
5798 const wxString
& value
)
5800 int l
= m_propHierarchy
.size();
5804 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5805 wxString valuel
= value
.Lower();
5808 if ( type
.length() == 0 )
5813 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5815 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5817 else if ( value
.ToLong(&v
, 0) )
5824 if ( type
== wxT("string") )
5828 else if ( type
== wxT("int") )
5831 value
.ToLong(&v
, 0);
5834 else if ( type
== wxT("bool") )
5836 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5843 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5848 p
->SetAttribute( name
, variant
);
5853 // -----------------------------------------------------------------------
5855 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5857 wxLogError(_("Error in resource: %s"),msg
.c_str());
5860 // -----------------------------------------------------------------------
5862 #endif // wxUSE_PROPGRID