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"
66 #include <wx/clipbrd.h>
67 #include <wx/dataobj.h>
70 #include <wx/msw/private.h>
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 #define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 #define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 #define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 #define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 #define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const wxChar
*wxPropertyGridNameStr
= wxT("wxPropertyGrid");
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // NB: We prefer to use wxModule, as it offers more consistent behavior
142 // across platforms. However, for those rare problem situations, we
143 // also need to offer option to use simpler approach.
144 // -----------------------------------------------------------------------
146 #ifndef wxPG_USE_WXMODULE
147 #define wxPG_USE_WXMODULE 1
150 #if wxPG_USE_WXMODULE
152 #include <wx/module.h>
154 class wxPGGlobalVarsClassManager
: public wxModule
156 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
158 wxPGGlobalVarsClassManager() {}
159 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
160 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
163 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
165 #else // !wxPG_USE_WXMODULE
167 class wxPGGlobalVarsClassManager
170 wxPGGlobalVarsClassManager() {}
171 ~wxPGGlobalVarsClassManager() { delete wxPGGlobalVars
; }
174 static wxPGGlobalVarsClassManager gs_pgGlobalVarsClassManager
;
179 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
182 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
184 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
186 m_boolChoices
.Add(_("False"));
187 m_boolChoices
.Add(_("True"));
189 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
191 m_defaultRenderer
= new wxPGDefaultRenderer();
193 m_autoGetTranslation
= false;
201 // Prepare some shared variants
202 m_vEmptyString
= wxString();
204 m_vMinusOne
= (long) -1;
208 // Prepare cached string constants
209 m_strstring
= wxS("string");
210 m_strlong
= wxS("long");
211 m_strbool
= wxS("bool");
212 m_strlist
= wxS("list");
213 m_strMin
= wxS("Min");
214 m_strMax
= wxS("Max");
215 m_strUnits
= wxS("Units");
216 m_strInlineHelp
= wxS("InlineHelp");
224 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
228 delete m_defaultRenderer
;
230 // This will always have one ref
231 delete m_fontFamilyChoices
;
234 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
235 delete ((wxValidator
*)m_arrValidators
[i
]);
239 // Destroy value type class instances.
240 wxPGHashMapS2P::iterator vt_it
;
242 // Destroy editor class instances.
243 // iterate over all the elements in the class
244 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
246 delete ((wxPGEditor
*)vt_it
->second
);
249 delete wxPGProperty::sm_wxPG_LABEL
;
252 // -----------------------------------------------------------------------
254 // -----------------------------------------------------------------------
257 // This class is a wxBrush derivative used in the background colour
258 // brush cache. It adds wxPG-type colour-in-long to the class.
259 // JMS: Yes I know wxBrush doesn't actually hold the value (refcounted
260 // object does), but this is simpler implementation and equally
264 class wxPGBrush
: public wxBrush
267 wxPGBrush( const wxColour
& colour
);
269 virtual ~wxPGBrush() { }
270 void SetColour2( const wxColour
& colour
);
271 inline long GetColourAsLong() const { return m_colAsLong
; }
277 void wxPGBrush::SetColour2( const wxColour
& colour
)
279 wxBrush::SetColour(colour
);
280 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
284 wxPGBrush::wxPGBrush() : wxBrush()
290 wxPGBrush::wxPGBrush( const wxColour
& colour
) : wxBrush(colour
)
292 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
296 // -----------------------------------------------------------------------
298 // -----------------------------------------------------------------------
301 // Same as wxPGBrush, but for wxColour instead.
304 class wxPGColour
: public wxColour
307 wxPGColour( const wxColour
& colour
);
309 virtual ~wxPGColour() { }
310 void SetColour2( const wxColour
& colour
);
311 inline long GetColourAsLong() const { return m_colAsLong
; }
317 void wxPGColour::SetColour2( const wxColour
& colour
)
320 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
324 wxPGColour::wxPGColour() : wxColour()
330 wxPGColour::wxPGColour( const wxColour
& colour
) : wxColour(colour
)
332 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
336 // -----------------------------------------------------------------------
338 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
339 // and tries to commit property value.
340 // -----------------------------------------------------------------------
342 class wxPGTLWHandler
: public wxEvtHandler
346 wxPGTLWHandler( wxPropertyGrid
* pg
)
354 void OnClose( wxCloseEvent
& event
)
356 // ClearSelection forces value validation/commit.
357 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
367 wxPropertyGrid
* m_pg
;
369 DECLARE_EVENT_TABLE()
372 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
373 EVT_CLOSE(wxPGTLWHandler::OnClose
)
376 // -----------------------------------------------------------------------
378 // -----------------------------------------------------------------------
381 // wxPGCanvas acts as a graphics sub-window of the
382 // wxScrolledWindow that wxPropertyGrid is.
384 class wxPGCanvas
: public wxPanel
387 wxPGCanvas() : wxPanel()
390 virtual ~wxPGCanvas() { }
393 void OnMouseMove( wxMouseEvent
&event
)
395 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
396 pg
->OnMouseMove( event
);
399 void OnMouseClick( wxMouseEvent
&event
)
401 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
402 pg
->OnMouseClick( event
);
405 void OnMouseUp( wxMouseEvent
&event
)
407 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
408 pg
->OnMouseUp( event
);
411 void OnMouseRightClick( wxMouseEvent
&event
)
413 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
414 pg
->OnMouseRightClick( event
);
417 void OnMouseDoubleClick( wxMouseEvent
&event
)
419 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
420 pg
->OnMouseDoubleClick( event
);
423 void OnKey( wxKeyEvent
& event
)
425 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
429 void OnKeyUp( wxKeyEvent
& event
)
431 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
432 pg
->OnKeyUp( event
);
435 void OnNavigationKey( wxNavigationKeyEvent
& event
)
437 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
438 pg
->OnNavigationKey( event
);
441 void OnPaint( wxPaintEvent
& event
);
444 DECLARE_EVENT_TABLE()
448 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
449 EVT_MOTION(wxPGCanvas::OnMouseMove
)
450 EVT_PAINT(wxPGCanvas::OnPaint
)
451 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
452 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
453 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
454 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
455 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
456 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
457 EVT_CHAR(wxPGCanvas::OnKey
)
458 EVT_NAVIGATION_KEY(wxPGCanvas::OnNavigationKey
)
462 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
464 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
465 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
469 // Don't paint after destruction has begun
470 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
473 // Update everything inside the box
474 wxRect r
= GetUpdateRegion().GetBox();
476 // Repaint this rectangle
477 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
479 // We assume that the size set when grid is shown
480 // is what is desired.
481 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
484 // -----------------------------------------------------------------------
486 // -----------------------------------------------------------------------
488 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
490 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
491 EVT_IDLE(wxPropertyGrid::OnIdle
)
492 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
493 EVT_PAINT(wxPropertyGrid::OnPaint
)
494 EVT_SIZE(wxPropertyGrid::OnResize
)
495 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
496 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
497 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
498 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
499 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
500 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
501 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
502 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
506 // -----------------------------------------------------------------------
508 wxPropertyGrid::wxPropertyGrid()
514 // -----------------------------------------------------------------------
516 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
525 Create(parent
,id
,pos
,size
,style
,name
);
528 // -----------------------------------------------------------------------
530 bool wxPropertyGrid::Create( wxWindow
*parent
,
538 if ( !(style
&wxBORDER_MASK
) )
539 style
|= wxSIMPLE_BORDER
;
544 // This prevents crash under Win2K, but still
545 // enables keyboard navigation
546 if ( style
& wxTAB_TRAVERSAL
)
548 style
&= ~(wxTAB_TRAVERSAL
);
549 style
|= wxWANTS_CHARS
;
552 if ( style
& wxTAB_TRAVERSAL
)
553 style
|= wxWANTS_CHARS
;
556 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
563 // -----------------------------------------------------------------------
566 // Initialize values to defaults
568 void wxPropertyGrid::Init1()
570 #if !wxPG_USE_WXMODULE
571 if ( !wxPGGlobalVars
)
572 wxPGGlobalVars
= new wxPGGlobalVarsClass();
575 // Register editor classes, if necessary.
576 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
577 RegisterDefaultEditors();
580 m_pState
= (wxPropertyGridPageState
*) NULL
;
581 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
582 m_selected
= (wxPGProperty
*) NULL
;
584 m_propHover
= (wxPGProperty
*) NULL
;
585 m_eventObject
= this;
586 m_curFocused
= (wxWindow
*) NULL
;
588 m_inDoPropertyChanged
= 0;
589 m_inCommitChangesFromEditor
= 0;
590 m_inDoSelectProperty
= 0;
591 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
597 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
598 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
599 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
600 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
601 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
602 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
603 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
604 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
605 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
606 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
607 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
608 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
609 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
611 m_coloursCustomized
= 0;
616 #if wxPG_DOUBLE_BUFFER
617 m_doubleBuffer
= (wxBitmap
*) NULL
;
620 m_windowsToDelete
= NULL
;
622 #ifndef wxPG_ICON_WIDTH
628 m_iconWidth
= wxPG_ICON_WIDTH
;
633 m_gutterWidth
= wxPG_GUTTER_MIN
;
634 m_subgroup_extramargin
= 10;
638 m_width
= m_height
= 0;
640 SetButtonShortcut(0);
642 m_keyComboConsumed
= 0;
644 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
647 m_chgInfo_changedProperty
= NULL
;
650 // -----------------------------------------------------------------------
653 // Initialize after parent etc. set
655 void wxPropertyGrid::Init2()
657 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
660 // Smaller controls on Mac
661 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
664 // Now create state, if one didn't exist already
665 // (wxPropertyGridManager might have created it for us).
668 m_pState
= CreateState();
669 m_pState
->m_pPropGrid
= this;
670 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
673 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
674 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
676 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
678 m_pState
->InitNonCatMode();
680 m_pState
->m_properties
= m_pState
->m_abcArray
;
683 GetClientSize(&m_width
,&m_height
);
685 #ifndef wxPG_ICON_WIDTH
686 // create two bitmap nodes for drawing
687 m_expandbmp
= new wxBitmap(expand_xpm
);
688 m_collbmp
= new wxBitmap(collapse_xpm
);
690 // calculate average font height for bitmap centering
692 m_iconWidth
= m_expandbmp
->GetWidth();
693 m_iconHeight
= m_expandbmp
->GetHeight();
696 m_curcursor
= wxCURSOR_ARROW
;
697 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
699 // adjust bitmap icon y position so they are centered
700 m_vspacing
= wxPG_DEFAULT_VSPACING
;
704 wxFont useFont
= wxScrolledWindow::GetFont();
705 wxScrolledWindow::SetOwnFont( useFont
);
708 // This should be otherwise called by SetOwnFont
709 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
711 // Add base brush item
712 m_arrBgBrushes
.Add((void*)new wxPGBrush());
714 // Add base colour items
715 m_arrFgCols
.Add((void*)new wxPGColour());
716 m_arrFgCols
.Add((void*)new wxPGColour());
720 // This helps with flicker
721 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
724 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
725 m_tlp
= ::wxGetTopLevelParent(this);
726 m_tlwHandler
= handler
;
727 m_tlp
->PushEventHandler(handler
);
729 // set virtual size to this window size
730 wxSize wndsize
= GetSize();
731 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
733 m_timeCreated
= ::wxGetLocalTimeMillis();
735 m_canvas
= new wxPGCanvas();
736 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
737 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
738 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
740 m_iFlags
|= wxPG_FL_INITIALIZED
;
742 m_ncWidth
= wndsize
.GetWidth();
744 // Need to call OnResize handler or size given in constructor/Create
746 wxSizeEvent
sizeEvent(wndsize
,0);
750 // -----------------------------------------------------------------------
752 wxPropertyGrid::~wxPropertyGrid()
756 DoSelectProperty(NULL
);
758 // This should do prevent things from going too badly wrong
759 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
761 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
762 m_canvas
->ReleaseMouse();
764 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
765 m_tlp
->RemoveEventHandler(handler
);
769 if ( IsEditorsValueModified() )
770 ::wxMessageBox(wxS("Most recent change in property editor was lost!!!\n\n(if you don't want this to happen, close your frames and dialogs using Close(false).)"),
771 wxS("wxPropertyGrid Debug Warning") );
774 #if wxPG_DOUBLE_BUFFER
775 if ( m_doubleBuffer
)
776 delete m_doubleBuffer
;
779 delete m_windowsToDelete
;
781 //m_selected = (wxPGProperty*) NULL;
783 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
786 delete m_cursorSizeWE
;
788 #ifndef wxPG_ICON_WIDTH
793 // Delete cached text colours.
794 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
796 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
799 // Delete cached brushes.
800 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
802 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
805 // Delete common value records
806 for ( i
=0; i
<m_commonValues
.size(); i
++ )
808 delete GetCommonValue(i
);
812 // -----------------------------------------------------------------------
814 bool wxPropertyGrid::Destroy()
816 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
817 m_canvas
->ReleaseMouse();
819 return wxScrolledWindow::Destroy();
822 // -----------------------------------------------------------------------
824 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
826 return new wxPropertyGridPageState();
829 // -----------------------------------------------------------------------
830 // wxPropertyGrid overridden wxWindow methods
831 // -----------------------------------------------------------------------
833 void wxPropertyGrid::SetWindowStyleFlag( long style
)
835 long old_style
= m_windowStyle
;
837 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
839 wxASSERT( m_pState
);
841 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
844 EnableCategories( true );
846 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
848 // Disable categories
849 EnableCategories( false );
851 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
857 PrepareAfterItemsAdded();
859 m_pState
->m_itemsAdded
= 1;
861 #if wxPG_SUPPORT_TOOLTIPS
862 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
868 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
869 SetToolTip ( tooltip );
870 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
873 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
878 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
883 wxScrolledWindow::SetWindowStyleFlag ( style
);
885 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
887 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
889 CalculateFontAndBitmapStuff( m_vspacing
);
895 // -----------------------------------------------------------------------
897 void wxPropertyGrid::Freeze()
901 wxScrolledWindow::Freeze();
906 // -----------------------------------------------------------------------
908 void wxPropertyGrid::Thaw()
914 wxScrolledWindow::Thaw();
915 RecalculateVirtualSize();
916 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
920 // Force property re-selection
922 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
926 // -----------------------------------------------------------------------
928 void wxPropertyGrid::SetExtraStyle( long exStyle
)
930 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
932 #if defined(__WXMSW__)
935 // Don't use WS_EX_COMPOSITED just now.
938 if ( m_iFlags & wxPG_FL_IN_MANAGER )
939 hWnd = (HWND)GetParent()->GetHWND();
941 hWnd = (HWND)GetHWND();
943 ::SetWindowLong( hWnd, GWL_EXSTYLE,
944 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
947 //#elif defined(__WXGTK20__)
949 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
950 // truly was double-buffered.
951 if ( !this->IsDoubleBuffered() )
953 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
957 #if wxPG_DOUBLE_BUFFER
958 delete m_doubleBuffer
;
959 m_doubleBuffer
= NULL
;
964 wxScrolledWindow::SetExtraStyle( exStyle
);
966 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
967 m_pState
->InitNonCatMode();
969 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
970 m_windowStyle
|= wxPG_TOOLTIPS
;
973 wxPGGlobalVars
->m_extraStyle
= exStyle
;
976 // -----------------------------------------------------------------------
978 // returns the best acceptable minimal size
979 wxSize
wxPropertyGrid::DoGetBestSize() const
982 if ( m_lineHeight
> hei
)
984 wxSize sz
= wxSize( 60, hei
+40 );
990 // -----------------------------------------------------------------------
991 // wxPropertyGrid Font and Colour Methods
992 // -----------------------------------------------------------------------
994 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
998 m_captionFont
= wxScrolledWindow::GetFont();
1000 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1001 m_subgroup_extramargin
= x
+ (x
/2);
1004 #if wxPG_USE_RENDERER_NATIVE
1005 m_iconWidth
= wxPG_ICON_WIDTH
;
1006 #elif wxPG_ICON_WIDTH
1008 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1009 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1010 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1014 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1015 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1016 m_gutterWidth
= wxPG_GUTTER_MIN
;
1019 if ( vspacing
<= 1 ) vdiv
= 12;
1020 else if ( vspacing
>= 3 ) vdiv
= 3;
1022 m_spacingy
= m_fontHeight
/ vdiv
;
1023 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1024 m_spacingy
= wxPG_YSPACING_MIN
;
1027 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1028 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1030 m_captionFont
.SetWeight(wxBOLD
);
1031 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1033 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1036 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1037 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1040 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1042 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1043 RecalculateVirtualSize();
1045 InvalidateBestSize();
1048 // -----------------------------------------------------------------------
1050 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1056 // -----------------------------------------------------------------------
1058 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1059 int ga
= 1000, int ba
= 1000,
1060 bool forceDifferent
= false)
1067 // Recursion guard (allow 2 max)
1068 static int isinside
= 0;
1070 wxCHECK_MSG( isinside
< 3,
1072 wxT("wxPGAdjustColour should not be recursively called more than once") );
1077 int g
= src
.Green();
1080 if ( r2
>255 ) r2
= 255;
1081 else if ( r2
<0) r2
= 0;
1083 if ( g2
>255 ) g2
= 255;
1084 else if ( g2
<0) g2
= 0;
1086 if ( b2
>255 ) b2
= 255;
1087 else if ( b2
<0) b2
= 0;
1089 // Make sure they are somewhat different
1090 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1091 dst
= wxPGAdjustColour(src
,-(ra
*2));
1093 dst
= wxColour(r2
,g2
,b2
);
1095 // Recursion guard (allow 2 max)
1102 static int wxPGGetColAvg( const wxColour
& col
)
1104 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1108 void wxPropertyGrid::RegainColours()
1110 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1112 if ( !(m_coloursCustomized
& 0x0002) )
1114 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1116 // Make sure colour is dark enough
1118 int colDec
= wxPGGetColAvg(col
) - 230;
1120 int colDec
= wxPGGetColAvg(col
) - 200;
1123 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1128 if ( !(m_coloursCustomized
& 0x0001) )
1129 m_colMargin
= m_colCapBack
;
1131 if ( !(m_coloursCustomized
& 0x0004) )
1138 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1139 m_colCapFore
= capForeCol
;
1141 // Set the cached colour as well.
1142 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1145 if ( !(m_coloursCustomized
& 0x0008) )
1147 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1148 m_colPropBack
= bgCol
;
1150 // Set the cached brush as well.
1151 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1154 if ( !(m_coloursCustomized
& 0x0010) )
1156 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1157 m_colPropFore
= fgCol
;
1159 // Set the cached colour as well.
1160 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1163 if ( !(m_coloursCustomized
& 0x0020) )
1164 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1166 if ( !(m_coloursCustomized
& 0x0040) )
1167 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1169 if ( !(m_coloursCustomized
& 0x0080) )
1170 m_colLine
= m_colCapBack
;
1172 if ( !(m_coloursCustomized
& 0x0100) )
1173 m_colDisPropFore
= m_colCapFore
;
1175 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1178 // -----------------------------------------------------------------------
1180 void wxPropertyGrid::ResetColours()
1182 m_coloursCustomized
= 0;
1189 // -----------------------------------------------------------------------
1191 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1193 // Must disable active editor.
1196 bool selRes
= ClearSelection();
1197 wxPG_CHECK_MSG_DBG( selRes
,
1199 wxT("failed to deselect a property (editor probably had invalid value)") );
1202 // TODO: Following code is disabled with wxMac because
1203 // it is reported to fail. I (JMS) cannot debug it
1204 // personally right now.
1205 #if !defined(__WXMAC__)
1206 bool res
= wxScrolledWindow::SetFont( font
);
1209 CalculateFontAndBitmapStuff( m_vspacing
);
1212 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1220 // TODO: Remove after SetFont crash fixed.
1221 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1223 wxLogDebug(wxT("WARNING: propGrid.cpp: wxPropertyGrid::SetFont has been disabled on wxMac since there has been crash reported in it. If you are willing to debug the cause, replace line '#if !defined(__WXMAC__)' with line '#if 1' in wxPropertyGrid::SetFont."));
1229 // -----------------------------------------------------------------------
1231 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1234 m_coloursCustomized
|= 0x80;
1238 // -----------------------------------------------------------------------
1240 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1243 m_coloursCustomized
|= 0x01;
1247 // -----------------------------------------------------------------------
1249 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1251 m_colPropBack
= col
;
1252 m_coloursCustomized
|= 0x08;
1254 // Set the cached brush as well.
1255 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1260 // -----------------------------------------------------------------------
1262 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1264 m_colPropFore
= col
;
1265 m_coloursCustomized
|= 0x10;
1267 // Set the cached colour as well.
1268 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1273 // -----------------------------------------------------------------------
1275 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1277 m_colEmptySpace
= col
;
1282 // -----------------------------------------------------------------------
1284 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1286 m_colDisPropFore
= col
;
1287 m_coloursCustomized
|= 0x100;
1291 // -----------------------------------------------------------------------
1293 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1296 m_coloursCustomized
|= 0x20;
1300 // -----------------------------------------------------------------------
1302 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1305 m_coloursCustomized
|= 0x40;
1309 // -----------------------------------------------------------------------
1311 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1314 m_coloursCustomized
|= 0x02;
1318 // -----------------------------------------------------------------------
1320 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1323 m_coloursCustomized
|= 0x04;
1325 // Set the cached colour as well.
1326 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1331 // -----------------------------------------------------------------------
1333 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1335 unsigned char ind
= index
;
1337 p
->m_bgColIndex
= ind
;
1340 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1341 SetBackgroundColourIndex(p
->Item(i
),index
);
1344 // -----------------------------------------------------------------------
1346 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1348 wxPG_PROP_ARG_CALL_PROLOG()
1353 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1355 // As it is most likely that the previous colour is used, start comparison
1357 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1359 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1368 colInd
= m_arrBgBrushes
.size();
1369 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1370 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1374 SetBackgroundColourIndex(p
,colInd
);
1376 // If this was on a visible grid, then draw it.
1377 DrawItemAndChildren(p
);
1380 // -----------------------------------------------------------------------
1382 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1384 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1386 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1389 // -----------------------------------------------------------------------
1391 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1393 unsigned char ind
= index
;
1395 p
->m_fgColIndex
= ind
;
1397 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1400 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1401 SetTextColourIndex( p
->Item(i
), index
, flags
);
1405 // -----------------------------------------------------------------------
1407 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1412 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1414 // As it is most likely that the previous colour is used, start comparison
1416 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1418 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1427 colInd
= m_arrFgCols
.size();
1428 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1429 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1435 // -----------------------------------------------------------------------
1437 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1440 wxPG_PROP_ARG_CALL_PROLOG()
1442 if ( p
->IsCategory() )
1444 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1445 cat
->SetTextColIndex(CacheColour(colour
));
1451 flags
|= wxPG_RECURSE
;
1452 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1454 DrawItemAndChildren(p
);
1457 // -----------------------------------------------------------------------
1459 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1461 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1463 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1466 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1468 wxPG_PROP_ARG_CALL_PROLOG()
1470 SetBackgroundColourIndex( p
, 0 );
1471 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1473 if ( p
->IsCategory() )
1475 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1476 cat
->SetTextColIndex(1);
1480 // -----------------------------------------------------------------------
1481 // wxPropertyGrid property adding and removal
1482 // -----------------------------------------------------------------------
1484 void wxPropertyGrid::PrepareAfterItemsAdded()
1486 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1488 m_pState
->m_itemsAdded
= 0;
1490 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1493 RecalculateVirtualSize();
1496 // -----------------------------------------------------------------------
1497 // wxPropertyGrid property value setting and getting
1498 // -----------------------------------------------------------------------
1500 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1502 m_pState
->DoSetPropertyValueUnspecified(p
);
1503 DrawItemAndChildren(p
);
1505 wxPGProperty
* parent
= p
->GetParent();
1506 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1509 parent
= parent
->GetParent();
1513 // -----------------------------------------------------------------------
1514 // wxPropertyGrid property operations
1515 // -----------------------------------------------------------------------
1517 void wxPropertyGrid::DoSetPropertyName( wxPGProperty
* p
, const wxString
& newname
)
1519 wxCHECK_RET( p
, wxT("invalid property id") );
1521 if ( p
->GetBaseName().Len() ) m_pState
->m_dictName
.erase( p
->GetBaseName() );
1522 if ( newname
.Len() ) m_pState
->m_dictName
[newname
] = (void*) p
;
1524 p
->DoSetName(newname
);
1527 // -----------------------------------------------------------------------
1529 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1531 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1535 bool changed
= false;
1537 // Is it inside collapsed section?
1538 if ( !p
->IsVisible() )
1541 wxPGProperty
* parent
= p
->GetParent();
1542 wxPGProperty
* grandparent
= parent
->GetParent();
1544 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1545 Expand( grandparent
);
1553 GetViewStart(&vx
,&vy
);
1554 vy
*=wxPG_PIXELS_PER_UNIT
;
1560 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1561 m_iFlags
|= wxPG_FL_SCROLLED
;
1564 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1566 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1567 m_iFlags
|= wxPG_FL_SCROLLED
;
1577 // -----------------------------------------------------------------------
1578 // wxPropertyGrid helper methods called by properties
1579 // -----------------------------------------------------------------------
1581 // Control font changer helper.
1582 void wxPropertyGrid::SetCurControlBoldFont()
1584 wxASSERT( m_wndEditor
);
1585 m_wndEditor
->SetFont( m_captionFont
);
1588 // -----------------------------------------------------------------------
1590 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1593 #if wxPG_SMALL_SCREEN
1594 // On small-screen devices, always show dialogs with default position and size.
1595 return wxDefaultPosition
;
1597 int splitterX
= GetSplitterPosition();
1601 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1603 ImprovedClientToScreen( &x
, &y
);
1605 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1606 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1613 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1623 new_y
= y
+ m_lineHeight
;
1625 return wxPoint(new_x
,new_y
);
1629 // -----------------------------------------------------------------------
1631 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1633 if ( src_str
.length() == 0 )
1639 bool prev_is_slash
= false;
1641 wxString::const_iterator i
= src_str
.begin();
1645 for ( ; i
!= src_str
.end(); i
++ )
1649 if ( a
!= wxS('\\') )
1651 if ( !prev_is_slash
)
1657 if ( a
== wxS('n') )
1660 dst_str
<< wxS('\n');
1662 dst_str
<< wxS('\n');
1665 else if ( a
== wxS('t') )
1666 dst_str
<< wxS('\t');
1670 prev_is_slash
= false;
1674 if ( prev_is_slash
)
1676 dst_str
<< wxS('\\');
1677 prev_is_slash
= false;
1681 prev_is_slash
= true;
1688 // -----------------------------------------------------------------------
1690 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1692 if ( src_str
.length() == 0 )
1698 wxString::const_iterator i
= src_str
.begin();
1699 wxUniChar prev_a
= wxS('\0');
1703 for ( ; i
!= src_str
.end(); i
++ )
1707 if ( a
>= wxS(' ') )
1709 // This surely is not something that requires an escape sequence.
1714 // This might need...
1715 if ( a
== wxS('\r') )
1717 // DOS style line end.
1718 // Already taken care below
1720 else if ( a
== wxS('\n') )
1721 // UNIX style line end.
1722 dst_str
<< wxS("\\n");
1723 else if ( a
== wxS('\t') )
1725 dst_str
<< wxS('\t');
1728 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1738 // -----------------------------------------------------------------------
1740 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1744 return (wxPGProperty
*) NULL
;
1747 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1750 // -----------------------------------------------------------------------
1751 // wxPropertyGrid graphics related methods
1752 // -----------------------------------------------------------------------
1754 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1758 // Update everything inside the box
1759 wxRect r
= GetUpdateRegion().GetBox();
1761 dc
.SetPen(m_colEmptySpace
);
1762 dc
.SetBrush(m_colEmptySpace
);
1763 dc
.DrawRectangle(r
);
1766 // -----------------------------------------------------------------------
1768 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1769 wxPGProperty
* property
) const
1771 // Prepare rectangle to be used
1773 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1774 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1776 #if (wxPG_USE_RENDERER_NATIVE)
1778 #elif wxPG_ICON_WIDTH
1779 // Drawing expand/collapse button manually
1780 dc
.SetPen(m_colPropFore
);
1781 if ( property
->IsCategory() )
1782 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1784 dc
.SetBrush(m_colPropBack
);
1786 dc
.DrawRectangle( r
);
1787 int _y
= r
.y
+(m_iconWidth
/2);
1788 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1793 if ( property
->IsExpanded() )
1795 // wxRenderer functions are non-mutating in nature, so it
1796 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1797 // Hopefully this does not cause problems.
1798 #if (wxPG_USE_RENDERER_NATIVE)
1799 wxRendererNative::Get().DrawTreeItemButton(
1805 #elif wxPG_ICON_WIDTH
1814 #if (wxPG_USE_RENDERER_NATIVE)
1815 wxRendererNative::Get().DrawTreeItemButton(
1821 #elif wxPG_ICON_WIDTH
1822 int _x
= r
.x
+(m_iconWidth
/2);
1823 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1829 #if (wxPG_USE_RENDERER_NATIVE)
1831 #elif wxPG_ICON_WIDTH
1834 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1838 // -----------------------------------------------------------------------
1841 // This is the one called by OnPaint event handler and others.
1842 // topy and bottomy are already unscrolled (ie. physical)
1844 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1846 unsigned int bottomy
,
1847 const wxRect
* clipRect
)
1849 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1851 m_pState
->EnsureVirtualHeight();
1853 wxRect tempClipRect
;
1856 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1857 clipRect
= &tempClipRect
;
1860 // items added check
1861 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1863 int paintFinishY
= 0;
1865 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1868 bool isBuffered
= false;
1870 #if wxPG_DOUBLE_BUFFER
1871 wxMemoryDC
* bufferDC
= NULL
;
1873 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1875 if ( !m_doubleBuffer
)
1877 paintFinishY
= clipRect
->y
;
1882 bufferDC
= new wxMemoryDC();
1884 // If nothing was changed, then just copy from double-buffer
1885 bufferDC
->SelectObject( *m_doubleBuffer
);
1895 dc
.SetClippingRegion( *clipRect
);
1896 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1899 #if wxPG_DOUBLE_BUFFER
1902 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1903 bufferDC
, 0, 0, wxCOPY
);
1904 dc
.DestroyClippingRegion(); // Is this really necessary?
1910 // Clear area beyond bottomY?
1911 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1913 dc
.SetPen(m_colEmptySpace
);
1914 dc
.SetBrush(m_colEmptySpace
);
1915 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1919 // -----------------------------------------------------------------------
1921 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1922 const wxPGProperty
* firstItem
,
1923 const wxPGProperty
* lastItem
,
1924 const wxRect
* clipRect
,
1925 bool isBuffered
) const
1927 // TODO: This should somehow be eliminated.
1928 wxRect tempClipRect
;
1931 wxASSERT(firstItem
);
1933 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1934 clipRect
= &tempClipRect
;
1938 firstItem
= DoGetItemAtY(clipRect
->y
);
1942 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1944 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1947 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1950 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1951 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1953 int lh
= m_lineHeight
;
1956 int lastItemBottomY
;
1958 firstItemTopY
= clipRect
->y
;
1959 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1961 // Align y coordinates to item boundaries
1962 firstItemTopY
-= firstItemTopY
% lh
;
1963 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1964 lastItemBottomY
-= 1;
1966 // Entire range outside scrolled, visible area?
1967 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1970 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1974 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1975 firstItem->GetLabel().c_str(),
1976 lastItem->GetLabel().c_str(),
1977 (int)(lastItemBottomY - firstItemTopY),
1979 (unsigned long)clipRect );
1984 long windowStyle
= m_windowStyle
;
1990 // With wxPG_DOUBLE_BUFFER, do double buffering
1991 // - buffer's y = 0, so align cliprect and coordinates to that
1993 #if wxPG_DOUBLE_BUFFER
1999 xRelMod
= clipRect
->x
;
2000 yRelMod
= clipRect
->y
;
2003 // clipRect conversion
2011 firstItemTopY
-= yRelMod
;
2012 lastItemBottomY
-= yRelMod
;
2015 wxUnusedVar(isBuffered
);
2018 int x
= m_marginWidth
- xRelMod
;
2020 const wxFont
& normalfont
= m_font
;
2022 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
2024 bool isEnabled
= IsEnabled();
2027 // Prepare some pens and brushes that are often changed to.
2030 wxBrush
marginBrush(m_colMargin
);
2031 wxPen
marginPen(m_colMargin
);
2032 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2033 wxPen
linepen(m_colLine
,1,wxSOLID
);
2035 // pen that has same colour as text
2036 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2039 // Clear margin with background colour
2041 dc
.SetBrush( marginBrush
);
2042 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2044 dc
.SetPen( *wxTRANSPARENT_PEN
);
2045 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2048 const wxPGProperty
* selected
= m_selected
;
2049 const wxPropertyGridPageState
* state
= m_pState
;
2051 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2052 bool wasSelectedPainted
= false;
2055 // TODO: Only render columns that are within clipping region.
2057 dc
.SetFont(normalfont
);
2059 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2060 int endScanBottomY
= lastItemBottomY
+ lh
;
2061 int y
= firstItemTopY
;
2064 // Pregenerate list of visible properties.
2065 wxArrayPGProperty visPropArray
;
2066 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2068 for ( ; !it
.AtEnd(); it
.Next() )
2070 const wxPGProperty
* p
= *it
;
2072 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2074 visPropArray
.push_back((wxPGProperty
*)p
);
2076 if ( y
> endScanBottomY
)
2083 visPropArray
.push_back(NULL
);
2085 wxPGProperty
* nextP
= visPropArray
[0];
2087 int gridWidth
= state
->m_width
;
2090 for ( unsigned int arrInd
=1;
2091 nextP
&& y
<= lastItemBottomY
;
2094 wxPGProperty
* p
= nextP
;
2095 nextP
= visPropArray
[arrInd
];
2097 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2098 int textMarginHere
= x
;
2099 int renderFlags
= wxPGCellRenderer::Control
;
2101 int greyDepth
= m_marginWidth
;
2102 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2103 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2105 int greyDepthX
= greyDepth
- xRelMod
;
2107 // Use basic depth if in non-categoric mode and parent is base array.
2108 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2110 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2113 // Paint margin area
2114 dc
.SetBrush(marginBrush
);
2115 dc
.SetPen(marginPen
);
2116 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2118 dc
.SetPen( linepen
);
2123 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2129 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2131 sx
+= state
->m_colWidths
[si
];
2132 dc
.DrawLine( sx
, y
, sx
, y2
);
2135 // Horizontal Line, below
2136 // (not if both this and next is category caption)
2137 if ( p
->IsCategory() &&
2138 nextP
&& nextP
->IsCategory() )
2139 dc
.SetPen(m_colCapBack
);
2141 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2143 if ( p
== selected
)
2145 renderFlags
|= wxPGCellRenderer::Selected
;
2146 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2147 wasSelectedPainted
= true;
2155 if ( p
->IsCategory() )
2157 if ( p
->m_fgColIndex
== 0 )
2158 rowFgCol
= m_colCapFore
;
2160 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2161 rowBgBrush
= wxBrush(m_colCapBack
);
2163 else if ( p
!= selected
)
2165 // Disabled may get different colour.
2166 if ( !p
->IsEnabled() )
2167 rowFgCol
= m_colDisPropFore
;
2169 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2171 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2175 // Selected gets different colour.
2176 if ( reallyFocused
)
2178 rowFgCol
= m_colSelFore
;
2179 rowBgBrush
= wxBrush(m_colSelBack
);
2181 else if ( isEnabled
)
2183 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2184 rowBgBrush
= marginBrush
;
2188 rowFgCol
= m_colDisPropFore
;
2189 rowBgBrush
= wxBrush(m_colSelBack
);
2193 bool fontChanged
= false;
2195 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2200 if ( p
->IsCategory() )
2202 // Captions are all cells merged as one
2203 dc
.SetFont(m_captionFont
);
2205 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2207 dc
.SetBrush(rowBgBrush
);
2208 dc
.SetPen(rowBgBrush
.GetColour());
2209 dc
.SetTextForeground(rowFgCol
);
2211 dc
.DrawRectangle(cellRect
);
2214 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2215 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2218 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2219 DrawExpanderButton( dc
, butRect
, p
);
2223 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2225 dc
.SetFont(m_captionFont
);
2231 int nextCellWidth
= state
->m_colWidths
[0];
2232 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2233 int textXAdd
= textMarginHere
- greyDepthX
;
2235 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2237 cellRect
.width
= nextCellWidth
- 1;
2239 bool ctrlCell
= false;
2242 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2244 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2245 dc
.SetBrush(editorBgCol
);
2246 dc
.SetPen(editorBgCol
);
2247 dc
.SetTextForeground(m_colPropFore
);
2249 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2254 dc
.SetBrush(rowBgBrush
);
2255 dc
.SetPen(rowBgBrush
.GetColour());
2256 dc
.SetTextForeground(rowFgCol
);
2259 dc
.DrawRectangle(cellRect
);
2262 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2263 DrawExpanderButton( dc
, butRect
, p
);
2265 dc
.SetClippingRegion(cellRect
);
2267 cellRect
.x
+= textXAdd
;
2268 cellRect
.width
-= textXAdd
;
2273 wxPGCellRenderer
* renderer
;
2274 int cmnVal
= p
->GetCommonValue();
2275 if ( cmnVal
== -1 || ci
!= 1 )
2277 renderer
= p
->GetCellRenderer(ci
);
2278 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2282 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2283 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2287 cellX
+= state
->m_colWidths
[ci
];
2288 if ( ci
< (state
->m_colWidths
.size()-1) )
2289 nextCellWidth
= state
->m_colWidths
[ci
+1];
2291 dc
.DestroyClippingRegion(); // Is this really necessary?
2297 dc
.SetFont(normalfont
);
2302 // Refresh editor controls (seems not needed on msw)
2303 // NOTE: This code is mandatory for GTK!
2304 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2305 if ( wasSelectedPainted
)
2308 m_wndEditor
->Refresh();
2310 m_wndEditor2
->Refresh();
2317 // -----------------------------------------------------------------------
2319 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2323 if ( m_width
< 10 || m_height
< 10 ||
2324 !m_pState
->m_properties
->GetChildCount() ||
2325 p1
== (wxPGProperty
*) NULL
)
2326 return wxRect(0,0,0,0);
2331 // Return rect which encloses the given property range
2333 int visTop
= p1
->GetY();
2336 visBottom
= p2
->GetY() + m_lineHeight
;
2338 visBottom
= m_height
+ visTop
;
2340 // If seleced property is inside the range, we'll extend the range to include
2342 wxPGProperty
* selected
= m_selected
;
2345 int selectedY
= selected
->GetY();
2346 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2348 wxWindow
* editor
= GetEditorControl();
2351 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2352 if ( visBottom2
> visBottom
)
2353 visBottom
= visBottom2
;
2358 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2361 // -----------------------------------------------------------------------
2363 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2368 if ( m_pState
->m_itemsAdded
)
2369 PrepareAfterItemsAdded();
2371 wxRect r
= GetPropertyRect(p1
, p2
);
2374 m_canvas
->RefreshRect(r
);
2378 // -----------------------------------------------------------------------
2380 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2382 if ( p
== m_selected
)
2383 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2385 DrawItemAndChildren(p
);
2388 // -----------------------------------------------------------------------
2390 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2395 // Draw item, children, and parent too, if it is not category
2396 wxPGProperty
* parent
= p
->GetParent();
2399 !parent
->IsCategory() &&
2400 parent
->GetParent() )
2403 parent
= parent
->GetParent();
2406 DrawItemAndChildren(p
);
2409 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2411 wxCHECK_RET( p
, wxT("invalid property id") );
2413 // Do not draw if in non-visible page
2414 if ( p
->GetParentState() != m_pState
)
2417 // do not draw a single item if multiple pending
2418 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2421 wxWindow
* wndPrimary
= GetEditorControl();
2423 // Update child control.
2424 if ( m_selected
&& m_selected
->GetParent() == p
)
2425 m_selected
->UpdateControl(wndPrimary
);
2427 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2429 DrawItems(p
, lastDrawn
);
2432 // -----------------------------------------------------------------------
2434 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2435 const wxRect
*rect
)
2437 PrepareAfterItemsAdded();
2439 wxWindow::Refresh(false);
2441 // TODO: Coordinate translation
2442 m_canvas
->Refresh(false, rect
);
2444 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2445 // I think this really helps only GTK+1.2
2446 if ( m_wndEditor
) m_wndEditor
->Refresh();
2447 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2451 // -----------------------------------------------------------------------
2452 // wxPropertyGrid global operations
2453 // -----------------------------------------------------------------------
2455 void wxPropertyGrid::Clear()
2459 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2460 wxPG_CHECK_RET_DBG( selRes
,
2461 wxT("failed to deselect a property (editor probably had invalid value)") );
2464 m_pState
->DoClear();
2470 RecalculateVirtualSize();
2472 // Need to clear some area at the end
2474 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2477 // -----------------------------------------------------------------------
2479 bool wxPropertyGrid::EnableCategories( bool enable
)
2481 if ( !ClearSelection() )
2487 // Enable categories
2490 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2495 // Disable categories
2497 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2500 if ( !m_pState
->EnableCategories(enable
) )
2505 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2507 m_pState
->m_itemsAdded
= 1; // force
2508 PrepareAfterItemsAdded();
2512 m_pState
->m_itemsAdded
= 1;
2514 // No need for RecalculateVirtualSize() here - it is already called in
2515 // wxPropertyGridPageState method above.
2522 // -----------------------------------------------------------------------
2524 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2526 wxASSERT( pNewState
);
2527 wxASSERT( pNewState
->GetGrid() );
2529 if ( pNewState
== m_pState
)
2532 wxPGProperty
* oldSelection
= m_selected
;
2537 bool selRes
= ClearSelection();
2538 wxPG_CHECK_RET_DBG( selRes
,
2539 wxT("failed to deselect a property (editor probably had invalid value)") );
2542 m_pState
->m_selected
= oldSelection
;
2544 bool orig_mode
= m_pState
->IsInNonCatMode();
2545 bool new_state_mode
= pNewState
->IsInNonCatMode();
2547 m_pState
= pNewState
;
2550 int pgWidth
= GetClientSize().x
;
2551 if ( HasVirtualWidth() )
2553 int minWidth
= pgWidth
;
2554 if ( pNewState
->m_width
< minWidth
)
2556 pNewState
->m_width
= minWidth
;
2557 pNewState
->CheckColumnWidths();
2563 // Just in case, fully re-center splitter
2564 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2565 pNewState
->m_fSplitterX
= -1.0;
2567 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2570 m_propHover
= (wxPGProperty
*) NULL
;
2572 // If necessary, convert state to correct mode.
2573 if ( orig_mode
!= new_state_mode
)
2575 // This should refresh as well.
2576 EnableCategories( orig_mode
?false:true );
2578 else if ( !m_frozen
)
2580 // Refresh, if not frozen.
2581 if ( m_pState
->m_itemsAdded
)
2582 PrepareAfterItemsAdded();
2585 if ( m_pState
->m_selected
)
2586 DoSelectProperty( m_pState
->m_selected
);
2588 RecalculateVirtualSize(0);
2592 m_pState
->m_itemsAdded
= 1;
2595 // -----------------------------------------------------------------------
2597 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2599 wxPG_PROP_ARG_CALL_PROLOG()
2601 m_pState
->SortChildren( p
);
2604 // -----------------------------------------------------------------------
2606 void wxPropertyGrid::Sort()
2608 bool selRes
= ClearSelection(); // This must be before state clear
2609 wxPG_CHECK_RET_DBG( selRes
,
2610 wxT("failed to deselect a property (editor probably had invalid value)") );
2615 // -----------------------------------------------------------------------
2617 // Call to SetSplitterPosition will always disable splitter auto-centering
2618 // if parent window is shown.
2619 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2621 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2624 wxPropertyGridPageState
* state
= m_pState
;
2626 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2631 CorrectEditorWidgetSizeX();
2637 // -----------------------------------------------------------------------
2639 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2641 SetSplitterPosition( m_width
/2, true );
2642 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2643 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2646 // -----------------------------------------------------------------------
2647 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2648 // -----------------------------------------------------------------------
2650 // Returns nearest paint visible property (such that will be painted unless
2651 // window is scrolled or resized). If given property is paint visible, then
2652 // it itself will be returned
2653 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2655 int vx
,vy1
;// Top left corner of client
2656 GetViewStart(&vx
,&vy1
);
2657 vy1
*= wxPG_PIXELS_PER_UNIT
;
2659 int vy2
= vy1
+ m_height
;
2660 int propY
= p
->GetY2(m_lineHeight
);
2662 if ( (propY
+ m_lineHeight
) < vy1
)
2665 return DoGetItemAtY( vy1
);
2667 else if ( propY
> vy2
)
2670 return DoGetItemAtY( vy2
);
2673 // Itself paint visible
2678 // -----------------------------------------------------------------------
2680 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2684 m_pushButKeyCode
= keycode
;
2685 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2686 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2690 m_pushButKeyCode
= WXK_DOWN
;
2691 m_pushButKeyCodeNeedsCtrl
= 0;
2692 m_pushButKeyCodeNeedsAlt
= 1;
2696 // -----------------------------------------------------------------------
2697 // Methods related to change in value, value modification and sending events
2698 // -----------------------------------------------------------------------
2700 // commits any changes in editor of selected property
2701 // return true if validation did not fail
2702 // flags are same as with DoSelectProperty
2703 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2705 // Committing already?
2706 if ( m_inCommitChangesFromEditor
)
2709 // Don't do this if already processing editor event. It might
2710 // induce recursive dialogs and crap like that.
2711 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2713 if ( m_inDoPropertyChanged
)
2720 IsEditorsValueModified() &&
2721 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2724 m_inCommitChangesFromEditor
= 1;
2726 wxVariant
variant(m_selected
->GetValueRef());
2727 bool valueIsPending
= false;
2729 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2730 // due to another window getting focus
2731 wxWindow
* oldFocus
= m_curFocused
;
2733 bool validationFailure
= false;
2734 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2736 m_chgInfo_changedProperty
= NULL
;
2738 // If truly modified, schedule value as pending.
2739 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2741 if ( DoEditorValidate() &&
2742 PerformValidation(m_selected
, variant
) )
2744 valueIsPending
= true;
2748 validationFailure
= true;
2753 EditorsValueWasNotModified();
2758 m_inCommitChangesFromEditor
= 0;
2760 if ( validationFailure
&& !forceSuccess
)
2764 oldFocus
->SetFocus();
2765 m_curFocused
= oldFocus
;
2768 res
= OnValidationFailure(m_selected
, variant
);
2770 // Now prevent further validation failure messages
2773 EditorsValueWasNotModified();
2774 OnValidationFailureReset(m_selected
);
2777 else if ( valueIsPending
)
2779 DoPropertyChanged( m_selected
, flags
);
2780 EditorsValueWasNotModified();
2789 // -----------------------------------------------------------------------
2791 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2794 // Runs all validation functionality.
2795 // Returns true if value passes all tests.
2798 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2800 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2802 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2807 // Adapt list to child values, if necessary
2808 wxVariant listValue
= pendingValue
;
2809 wxVariant
* pPendingValue
= &pendingValue
;
2810 wxVariant
* pList
= NULL
;
2812 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2813 // string value, then we need treat as it was changed instead
2814 // (or, in addition, as is the case with composite string parent).
2815 // This includes creating list variant for child values.
2817 wxPGProperty
* pwc
= p
->GetParent();
2818 wxPGProperty
* changedProperty
= p
;
2819 wxPGProperty
* baseChangedProperty
= changedProperty
;
2820 wxVariant bcpPendingList
;
2822 listValue
= pendingValue
;
2823 listValue
.SetName(p
->GetBaseName());
2826 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2828 wxVariantList tempList
;
2829 wxVariant
lv(tempList
, pwc
->GetBaseName());
2830 lv
.Append(listValue
);
2832 pPendingValue
= &listValue
;
2834 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2836 baseChangedProperty
= pwc
;
2837 bcpPendingList
= lv
;
2840 changedProperty
= pwc
;
2841 pwc
= pwc
->GetParent();
2845 wxPGProperty
* evtChangingProperty
= changedProperty
;
2847 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2849 value
= *pPendingValue
;
2853 // Convert list to child values
2854 pList
= pPendingValue
;
2855 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2858 wxVariant evtChangingValue
= value
;
2860 // FIXME: After proper ValueToString()s added, remove
2861 // this. It is just a temporary fix, as evt_changing
2862 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2863 // (unless it is selected, and textctrl editor is open).
2864 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2866 evtChangingProperty
= baseChangedProperty
;
2867 if ( evtChangingProperty
!= p
)
2869 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2873 evtChangingValue
= pendingValue
;
2877 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2879 if ( changedProperty
== m_selected
)
2881 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2882 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2886 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2890 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2891 m_chgInfo_changedProperty
= changedProperty
;
2892 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2893 m_chgInfo_pendingValue
= value
;
2896 m_chgInfo_valueList
= *pList
;
2898 m_chgInfo_valueList
.MakeNull();
2900 // If changedProperty is not property which value was edited,
2901 // then call wxPGProperty::ValidateValue() for that as well.
2902 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2904 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2908 // SendEvent returns true if event was vetoed
2909 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2915 // -----------------------------------------------------------------------
2917 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2919 if ( !msg
.length() )
2923 if ( !wxPGGlobalVars
->m_offline
)
2925 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2928 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2931 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2934 pStatusBar
->SetStatusText(msg
);
2942 ::wxMessageBox(msg
, _T("Property Error"));
2945 // -----------------------------------------------------------------------
2947 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2949 int vfb
= m_validationInfo
.m_failureBehavior
;
2951 if ( vfb
& wxPG_VFB_BEEP
)
2954 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2955 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2957 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2958 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2960 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2962 wxColour vfbFg
= *wxWHITE
;
2963 wxColour vfbBg
= *wxRED
;
2964 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2965 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2967 DrawItemAndChildren(property
);
2969 if ( property
== m_selected
)
2971 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2973 wxWindow
* editor
= GetEditorControl();
2976 editor
->SetForegroundColour(vfbFg
);
2977 editor
->SetBackgroundColour(vfbBg
);
2983 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2985 wxString msg
= m_validationInfo
.m_failureMessage
;
2987 if ( !msg
.length() )
2988 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2990 DoShowPropertyError(property
, msg
);
2993 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2996 // -----------------------------------------------------------------------
2998 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3000 int vfb
= m_validationInfo
.m_failureBehavior
;
3002 if ( vfb
& wxPG_VFB_MARK_CELL
)
3004 property
->SetCell(0, NULL
);
3005 property
->SetCell(1, NULL
);
3007 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3009 if ( property
== m_selected
&& GetEditorControl() )
3011 // Calling this will recreate the control, thus resetting its colour
3012 RefreshProperty(property
);
3016 DrawItemAndChildren(property
);
3021 // -----------------------------------------------------------------------
3023 // flags are same as with DoSelectProperty
3024 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3026 if ( m_inDoPropertyChanged
)
3029 wxWindow
* editor
= GetEditorControl();
3031 m_pState
->m_anyModified
= 1;
3033 m_inDoPropertyChanged
= 1;
3035 // Maybe need to update control
3036 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3038 // These values were calculated in PerformValidation()
3039 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3040 wxVariant value
= m_chgInfo_pendingValue
;
3042 wxPGProperty
* topPaintedProperty
= changedProperty
;
3044 while ( !topPaintedProperty
->IsCategory() &&
3045 !topPaintedProperty
->IsRoot() )
3047 topPaintedProperty
= topPaintedProperty
->GetParent();
3050 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3052 // Set as Modified (not if dragging just began)
3053 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3055 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3056 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3059 SetCurControlBoldFont();
3065 // Propagate updates to parent(s)
3067 wxPGProperty
* prevPwc
= NULL
;
3069 while ( prevPwc
!= topPaintedProperty
)
3071 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3073 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3076 SetCurControlBoldFont();
3080 pwc
= pwc
->GetParent();
3083 // Draw the actual property
3084 DrawItemAndChildren( topPaintedProperty
);
3087 // If value was set by wxPGProperty::OnEvent, then update the editor
3089 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3092 p
->GetEditorClass()->UpdateControl(p
, editor
);
3096 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3097 if ( m_wndEditor
) m_wndEditor
->Refresh();
3098 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3103 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3105 // If top parent has composite string value, then send to child parents,
3106 // starting from baseChangedProperty.
3107 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3109 pwc
= m_chgInfo_baseChangedProperty
;
3111 while ( pwc
!= changedProperty
)
3113 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3114 pwc
= pwc
->GetParent();
3118 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3120 m_inDoPropertyChanged
= 0;
3125 // -----------------------------------------------------------------------
3127 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3129 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3131 m_chgInfo_changedProperty
= NULL
;
3133 if ( PerformValidation(p
, newValue
) )
3135 DoPropertyChanged(p
);
3140 OnValidationFailure(p
, newValue
);
3146 // -----------------------------------------------------------------------
3148 // Runs wxValidator for the selected property
3149 bool wxPropertyGrid::DoEditorValidate()
3151 #if wxUSE_VALIDATORS
3152 // With traditional validator style, we dont need to more
3153 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3156 if ( m_iFlags
& wxPG_FL_VALIDATION_FAILED
)
3161 wxWindow
* wnd
= GetEditorControl();
3163 wxValidator
* validator
= m_selected
->GetValidator();
3164 if ( validator
&& wnd
)
3166 // Use TextCtrl of ODComboBox instead
3167 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3169 wnd
= ((wxOwnerDrawnComboBox
*)wnd
)->GetTextCtrl();
3175 validator
->SetWindow(wnd
);
3177 // Instead setting the flag after the failure, we set
3178 // it before checking and then clear afterwards if things
3179 // went fine. This trick is necessary since focus events
3180 // may be triggered while in Validate.
3181 m_iFlags
|= wxPG_FL_VALIDATION_FAILED
;
3182 if ( !validator
->Validate(this) )
3184 // If you dpm't want to display message multiple times per change,
3185 // comment the following line.
3186 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3189 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3195 // -----------------------------------------------------------------------
3197 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3199 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3200 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3202 wxWindow
* parent
= wnd
->GetParent();
3205 (parent
== m_canvas
||
3206 parent
->GetParent() == m_canvas
) )
3208 OnCustomEditorEvent((wxCommandEvent
&)event
);
3212 return wxPanel::ProcessEvent(event
);
3215 // -----------------------------------------------------------------------
3217 // NB: It may really not be wxCommandEvent - must check if necessary
3219 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3221 wxPGProperty
* selected
= m_selected
;
3224 // Somehow, event is handled after property has been deselected.
3225 // Possibly, but very rare.
3229 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3232 wxVariant
pendingValue(selected
->GetValueRef());
3233 wxWindow
* wnd
= GetEditorControl();
3235 bool wasUnspecified
= selected
->IsValueUnspecified();
3236 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3238 bool valueIsPending
= false;
3240 m_chgInfo_changedProperty
= NULL
;
3242 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3245 // Filter out excess wxTextCtrl modified events
3246 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3248 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3250 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3252 wxString newTcValue
= tc
->GetValue();
3253 if ( m_prevTcValue
== newTcValue
)
3256 m_prevTcValue
= newTcValue
;
3259 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3261 bool validationFailure
= false;
3262 bool buttonWasHandled
= false;
3265 // Try common button handling
3266 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3268 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3272 buttonWasHandled
= true;
3273 // Store as res2, as previously (and still currently alternatively)
3274 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3275 // in wxPGProperty::OnEvent().
3276 adapter
->ShowDialog( this, selected
);
3281 if ( !buttonWasHandled
)
3285 // First call editor class' event handler.
3286 const wxPGEditor
* editor
= selected
->GetEditorClass();
3288 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3290 // If changes, validate them
3291 if ( DoEditorValidate() )
3293 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3294 valueIsPending
= true;
3298 validationFailure
= true;
3303 // Then the property's custom handler (must be always called, unless
3304 // validation failed).
3305 if ( !validationFailure
)
3306 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3309 // SetValueInEvent(), as called in one of the functions referred above
3310 // overrides editor's value.
3311 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3313 valueIsPending
= true;
3314 pendingValue
= m_changeInEventValue
;
3315 selFlags
|= wxPG_SEL_DIALOGVAL
;
3318 if ( !validationFailure
&& valueIsPending
)
3319 if ( !PerformValidation(m_selected
, pendingValue
) )
3320 validationFailure
= true;
3322 if ( validationFailure
)
3324 OnValidationFailure(selected
, pendingValue
);
3326 else if ( valueIsPending
)
3328 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3330 DoPropertyChanged(selected
, selFlags
);
3331 EditorsValueWasNotModified();
3335 // No value after all
3337 // Let unhandled button click events go to the parent
3338 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3340 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3341 GetEventHandler()->AddPendingEvent(evt
);
3345 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3348 // -----------------------------------------------------------------------
3349 // wxPropertyGrid editor control helper methods
3350 // -----------------------------------------------------------------------
3352 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3354 int itemy
= p
->GetY2(m_lineHeight
);
3356 int cust_img_space
= 0;
3357 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3358 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3360 // TODO: If custom image detection changes from current, change this.
3361 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3363 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3364 int imwid
= p
->OnMeasureImage().x
;
3365 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3366 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3371 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3373 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3378 // -----------------------------------------------------------------------
3380 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3382 wxSize sz
= GetImageSize(p
, item
);
3383 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3384 wxPG_CUSTOM_IMAGE_SPACINGY
,
3389 // return size of custom paint image
3390 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3392 // If called with NULL property, then return default image
3393 // size for properties that use image.
3395 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3397 wxSize cis
= p
->OnMeasureImage(item
);
3399 int choiceCount
= p
->m_choices
.GetCount();
3400 int comVals
= p
->GetDisplayedCommonValueCount();
3401 if ( item
>= choiceCount
&& comVals
> 0 )
3403 unsigned int cvi
= item
-choiceCount
;
3404 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3406 else if ( item
>= 0 && choiceCount
== 0 )
3407 return wxSize(0, 0);
3412 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3417 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3424 // -----------------------------------------------------------------------
3426 // takes scrolling into account
3427 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3430 GetViewStart(&vx
,&vy
);
3431 vy
*=wxPG_PIXELS_PER_UNIT
;
3432 vx
*=wxPG_PIXELS_PER_UNIT
;
3435 ClientToScreen( px
, py
);
3438 // -----------------------------------------------------------------------
3440 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3443 GetViewStart(&pt2
.x
,&pt2
.y
);
3444 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3445 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3449 return m_pState
->HitTest(pt2
);
3452 // -----------------------------------------------------------------------
3454 // custom set cursor
3455 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3457 if ( type
== m_curcursor
&& !override
) return;
3459 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3461 if ( type
== wxCURSOR_SIZEWE
)
3462 cursor
= m_cursorSizeWE
;
3464 m_canvas
->SetCursor( *cursor
);
3469 // -----------------------------------------------------------------------
3470 // wxPropertyGrid property selection
3471 // -----------------------------------------------------------------------
3473 // Setups event handling for child control
3474 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
, int id
)
3476 if ( argWnd
== m_wndEditor
)
3478 this->Connect(id
, wxEVT_MOTION
,
3479 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
));
3480 this->Connect(id
, wxEVT_LEFT_UP
,
3481 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
));
3482 this->Connect(id
, wxEVT_LEFT_DOWN
,
3483 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
));
3484 this->Connect(id
, wxEVT_RIGHT_UP
,
3485 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
));
3486 this->Connect(id
, wxEVT_ENTER_WINDOW
,
3487 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3488 this->Connect(id
, wxEVT_LEAVE_WINDOW
,
3489 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3493 this->Connect(id
, wxEVT_NAVIGATION_KEY
,
3494 wxNavigationKeyEventHandler(wxPropertyGrid::OnNavigationKey
));
3497 this->Connect(id
, wxEVT_KEY_DOWN
,
3498 wxKeyEventHandler(wxPropertyGrid::OnChildKeyDown
));
3499 this->Connect(id
, wxEVT_KEY_UP
,
3500 wxKeyEventHandler(wxPropertyGrid::OnChildKeyUp
));
3501 this->Connect(id
, wxEVT_KILL_FOCUS
,
3502 wxFocusEventHandler(wxPropertyGrid::OnFocusEvent
));
3505 void wxPropertyGrid::FreeEditors()
3507 // Do not free editors immediately if processing events
3508 if ( !m_windowsToDelete
)
3509 m_windowsToDelete
= new wxArrayPtrVoid
;
3513 m_windowsToDelete
->push_back(m_wndEditor2
);
3514 m_wndEditor2
->Hide();
3515 m_wndEditor2
= (wxWindow
*) NULL
;
3520 m_windowsToDelete
->push_back(m_wndEditor
);
3521 m_wndEditor
->Hide();
3522 m_wndEditor
= (wxWindow
*) NULL
;
3526 // Call with NULL to de-select property
3527 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3529 wxPanel
* canvas
= GetPanel();
3533 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3534 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3536 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3539 if ( m_inDoSelectProperty
)
3542 m_inDoSelectProperty
= 1;
3544 wxPGProperty
* prev
= m_selected
;
3547 // Delete windows pending for deletion
3548 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3552 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3553 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3555 m_windowsToDelete
->clear();
3560 m_inDoSelectProperty
= 0;
3565 // If we are frozen, then just set the values.
3568 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3569 m_editorFocused
= 0;
3572 m_pState
->m_selected
= p
;
3574 // If frozen, always free controls. But don't worry, as Thaw will
3575 // recall SelectProperty to recreate them.
3578 // Prevent any further selection measures in this call
3579 p
= (wxPGProperty
*) NULL
;
3584 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3586 // Only set focus if not deselecting
3589 if ( flags
& wxPG_SEL_FOCUS
)
3593 m_wndEditor
->SetFocus();
3594 m_editorFocused
= 1;
3603 m_inDoSelectProperty
= 0;
3608 // First, deactivate previous
3612 OnValidationFailureReset(m_selected
);
3614 // Must double-check if this is an selected in case of forceswitch
3617 if ( !CommitChangesFromEditor(flags
) )
3619 // Validation has failed, so we can't exit the previous editor
3620 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3621 // _("Invalid Value"),wxOK|wxICON_ERROR);
3622 m_inDoSelectProperty
= 0;
3630 m_selected
= (wxPGProperty
*) NULL
;
3631 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3633 // We need to always fully refresh the grid here
3636 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3637 EditorsValueWasNotModified();
3640 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3643 // Then, activate the one given.
3646 int propY
= p
->GetY2(m_lineHeight
);
3648 int splitterX
= GetSplitterPosition();
3649 m_editorFocused
= 0;
3651 m_pState
->m_selected
= p
;
3652 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3654 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3656 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3658 // Do we need OnMeasureCalls?
3659 wxSize imsz
= p
->OnMeasureImage();
3662 // Only create editor for non-disabled non-caption
3663 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3665 // do this for non-caption items
3669 // Do we need to paint the custom image, if any?
3670 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3671 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3672 !p
->GetEditorClass()->CanContainCustomImage()
3674 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3676 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3677 wxPoint goodPos
= grect
.GetPosition();
3678 #if wxPG_CREATE_CONTROLS_HIDDEN
3679 int coord_adjust
= m_height
- goodPos
.y
;
3680 goodPos
.y
+= coord_adjust
;
3683 const wxPGEditor
* editor
= p
->GetEditorClass();
3684 wxCHECK_MSG(editor
, false,
3685 wxT("NULL editor class not allowed"));
3687 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3689 wxPGWindowList wndList
= editor
->CreateControls(this,
3694 m_wndEditor
= wndList
.m_primary
;
3695 m_wndEditor2
= wndList
.m_secondary
;
3697 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3698 // value is drawn as normal, and m_wndEditor2 is assumed
3699 // to be a right-aligned button that triggers a separate editor
3704 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3705 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3707 // Set validator, if any
3708 #if wxUSE_VALIDATORS
3709 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3711 wxValidator
* validator
= p
->GetValidator();
3713 m_wndEditor
->SetValidator(*validator
);
3717 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3718 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3720 // If it has modified status, use bold font
3721 // (must be done before capturing m_ctrlXAdjust)
3722 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3723 SetCurControlBoldFont();
3726 // Fix TextCtrl indentation
3727 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3728 wxTextCtrl
* tc
= NULL
;
3729 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3730 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3732 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3734 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3737 // Store x relative to splitter (we'll need it).
3738 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3740 // Check if background clear is not necessary
3741 wxPoint pos
= m_wndEditor
->GetPosition();
3742 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3744 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3747 m_wndEditor
->SetSizeHints(3, 3);
3749 #if wxPG_CREATE_CONTROLS_HIDDEN
3750 m_wndEditor
->Show(false);
3751 m_wndEditor
->Freeze();
3753 goodPos
= m_wndEditor
->GetPosition();
3754 goodPos
.y
-= coord_adjust
;
3755 m_wndEditor
->Move( goodPos
);
3758 wxWindow
* primaryCtrl
= GetEditorControl();
3759 SetupChildEventHandling(primaryCtrl
, wxPG_SUBID1
);
3761 // Focus and select all (wxTextCtrl, wxComboBox etc)
3762 if ( flags
& wxPG_SEL_FOCUS
)
3764 primaryCtrl
->SetFocus();
3766 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3772 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3773 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3775 // Get proper id for wndSecondary
3776 m_wndSecId
= m_wndEditor2
->GetId();
3777 wxWindowList children
= m_wndEditor2
->GetChildren();
3778 wxWindowList::iterator node
= children
.begin();
3779 if ( node
!= children
.end() )
3780 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3782 m_wndEditor2
->SetSizeHints(3,3);
3784 #if wxPG_CREATE_CONTROLS_HIDDEN
3785 wxRect sec_rect
= m_wndEditor2
->GetRect();
3786 sec_rect
.y
-= coord_adjust
;
3788 // Fine tuning required to fix "oversized"
3789 // button disappearance bug.
3790 if ( sec_rect
.y
< 0 )
3792 sec_rect
.height
+= sec_rect
.y
;
3795 m_wndEditor2
->SetSize( sec_rect
);
3797 m_wndEditor2
->Show();
3799 SetupChildEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3801 // If no primary editor, focus to button to allow
3802 // it to interprete ENTER etc.
3803 // NOTE: Due to problems focusing away from it, this
3804 // has been disabled.
3806 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3807 m_wndEditor2->SetFocus();
3811 if ( flags
& wxPG_SEL_FOCUS
)
3812 m_editorFocused
= 1;
3817 // Make sure focus is in grid canvas (important for wxGTK, at least)
3821 EditorsValueWasNotModified();
3823 // If it's inside collapsed section, expand parent, scroll, etc.
3824 // Also, if it was partially visible, scroll it into view.
3825 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3830 #if wxPG_CREATE_CONTROLS_HIDDEN
3831 m_wndEditor
->Thaw();
3833 m_wndEditor
->Show(true);
3840 // Make sure focus is in grid canvas
3844 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3850 // Show help text in status bar.
3851 // (if found and grid not embedded in manager with help box and
3852 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3855 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3857 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3858 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3860 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3862 statusbar
= frame
->GetStatusBar();
3867 const wxString
* pHelpString
= (const wxString
*) NULL
;
3871 pHelpString
= &p
->GetHelpString();
3872 if ( pHelpString
->length() )
3874 // Set help box text.
3875 statusbar
->SetStatusText( *pHelpString
);
3876 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3880 if ( (!pHelpString
|| !pHelpString
->length()) &&
3881 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3883 // Clear help box - but only if it was written
3884 // by us at previous time.
3885 statusbar
->SetStatusText( m_emptyString
);
3886 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3892 m_inDoSelectProperty
= 0;
3894 // call wx event handler (here so that it also occurs on deselection)
3895 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3900 // -----------------------------------------------------------------------
3902 bool wxPropertyGrid::UnfocusEditor()
3904 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3907 if ( !CommitChangesFromEditor(0) )
3911 DrawItem(m_selected
);
3916 // -----------------------------------------------------------------------
3918 // This method is not inline because it called dozens of times
3919 // (i.e. two-arg function calls create smaller code size).
3920 bool wxPropertyGrid::DoClearSelection()
3922 return DoSelectProperty((wxPGProperty
*)NULL
);
3925 // -----------------------------------------------------------------------
3926 // wxPropertyGrid expand/collapse state
3927 // -----------------------------------------------------------------------
3929 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3931 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3933 // If active editor was inside collapsed section, then disable it
3934 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3936 if ( !ClearSelection() )
3940 // Store dont-center-splitter flag 'cause we need to temporarily set it
3941 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3942 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3944 bool res
= m_pState
->DoCollapse(pwc
);
3949 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3951 RecalculateVirtualSize();
3953 // Redraw etc. only if collapsed was visible.
3954 if (pwc
->IsVisible() &&
3956 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3958 // When item is collapsed so that scrollbar would move,
3959 // graphics mess is about (unless we redraw everything).
3964 // Clear dont-center-splitter flag if it wasn't set
3965 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3970 // -----------------------------------------------------------------------
3972 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3974 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3976 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3978 // Store dont-center-splitter flag 'cause we need to temporarily set it
3979 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3980 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3982 bool res
= m_pState
->DoExpand(pwc
);
3987 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3989 RecalculateVirtualSize();
3991 // Redraw etc. only if expanded was visible.
3992 if ( pwc
->IsVisible() && !m_frozen
&&
3993 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3997 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4000 DrawItems(pwc
, NULL
);
4005 // Clear dont-center-splitter flag if it wasn't set
4006 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4011 // -----------------------------------------------------------------------
4013 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4016 return m_pState
->DoHideProperty(p
, hide
, flags
);
4019 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
4022 if ( !ClearSelection() )
4026 m_pState
->DoHideProperty(p
, hide
, flags
);
4028 RecalculateVirtualSize();
4035 // -----------------------------------------------------------------------
4036 // wxPropertyGrid size related methods
4037 // -----------------------------------------------------------------------
4039 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4041 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4045 // If virtual height was changed, then recalculate editor control position(s)
4046 if ( m_pState
->m_vhCalcPending
)
4047 CorrectEditorWidgetPosY();
4049 m_pState
->EnsureVirtualHeight();
4052 int by1
= m_pState
->GetVirtualHeight();
4053 int by2
= m_pState
->GetActualVirtualHeight();
4056 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4057 wxASSERT_MSG( false,
4063 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4065 int x
= m_pState
->m_width
;
4066 int y
= m_pState
->m_virtualHeight
;
4069 GetClientSize(&width
,&height
);
4071 // Now adjust virtual size.
4072 SetVirtualSize(x
, y
);
4078 // Adjust scrollbars
4079 if ( HasVirtualWidth() )
4081 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4082 xPos
= GetScrollPos( wxHORIZONTAL
);
4085 if ( forceXPos
!= -1 )
4088 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4091 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4092 int yPos
= GetScrollPos( wxVERTICAL
);
4094 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4095 xAmount
, yAmount
, xPos
, yPos
, true );
4097 // Must re-get size now
4098 GetClientSize(&width
,&height
);
4100 if ( !HasVirtualWidth() )
4102 m_pState
->SetVirtualWidth(width
);
4109 m_canvas
->SetSize( x
, y
);
4111 m_pState
->CheckColumnWidths();
4114 CorrectEditorWidgetSizeX();
4116 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4119 // -----------------------------------------------------------------------
4121 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4123 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4127 GetClientSize(&width
,&height
);
4132 #if wxPG_DOUBLE_BUFFER
4133 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4135 int dblh
= (m_lineHeight
*2);
4136 if ( !m_doubleBuffer
)
4138 // Create double buffer bitmap to draw on, if none
4139 int w
= (width
>250)?width
:250;
4140 int h
= height
+ dblh
;
4142 m_doubleBuffer
= new wxBitmap( w
, h
);
4146 int w
= m_doubleBuffer
->GetWidth();
4147 int h
= m_doubleBuffer
->GetHeight();
4149 // Double buffer must be large enough
4150 if ( w
< width
|| h
< (height
+dblh
) )
4152 if ( w
< width
) w
= width
;
4153 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4154 delete m_doubleBuffer
;
4155 m_doubleBuffer
= new wxBitmap( w
, h
);
4162 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4163 m_ncWidth
= event
.GetSize().x
;
4167 if ( m_pState
->m_itemsAdded
)
4168 PrepareAfterItemsAdded();
4170 // Without this, virtual size (atleast under wxGTK) will be skewed
4171 RecalculateVirtualSize();
4177 // -----------------------------------------------------------------------
4179 void wxPropertyGrid::SetVirtualWidth( int width
)
4183 // Disable virtual width
4184 width
= GetClientSize().x
;
4185 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4189 // Enable virtual width
4190 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4192 m_pState
->SetVirtualWidth( width
);
4195 // -----------------------------------------------------------------------
4196 // wxPropertyGrid mouse event handling
4197 // -----------------------------------------------------------------------
4199 // selFlags uses same values DoSelectProperty's flags
4200 // Returns true if event was vetoed.
4201 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4203 // Send property grid event of specific type and with specific property
4204 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4205 evt
.SetPropertyGrid(this);
4206 evt
.SetEventObject(m_eventObject
);
4210 evt
.SetCanVeto(true);
4211 evt
.SetupValidationInfo();
4212 m_validationInfo
.m_pValue
= pValue
;
4214 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4216 evtHandler
->ProcessEvent(evt
);
4218 return evt
.WasVetoed();
4221 // -----------------------------------------------------------------------
4223 // Return false if should be skipped
4224 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4228 // Need to set focus?
4229 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4234 wxPropertyGridPageState
* state
= m_pState
;
4236 int splitterHitOffset
;
4237 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4239 wxPGProperty
* p
= DoGetItemAtY(y
);
4243 int depth
= (int)p
->GetDepth() - 1;
4245 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4247 if ( x
>= marginEnds
)
4251 if ( p
->IsCategory() )
4253 // This is category.
4254 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4256 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4258 // Expand, collapse, activate etc. if click on text or left of splitter.
4261 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4266 if ( !DoSelectProperty( p
) )
4269 // On double-click, expand/collapse.
4270 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4272 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4273 else DoExpand( p
, true );
4277 else if ( splitterHit
== -1 )
4280 unsigned int selFlag
= 0;
4281 if ( columnHit
== 1 )
4283 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4284 selFlag
= wxPG_SEL_FOCUS
;
4286 if ( !DoSelectProperty( p
, selFlag
) )
4289 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4291 if ( p
->GetChildCount() && !p
->IsCategory() )
4292 // On double-click, expand/collapse.
4293 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4295 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4296 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4297 else DoExpand( p
, true );
4304 // click on splitter
4305 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4307 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4309 // Double-clicking the splitter causes auto-centering
4310 CenterSplitter( true );
4312 else if ( m_dragStatus
== 0 )
4315 // Begin draggin the splitter
4319 // Changes must be committed here or the
4320 // value won't be drawn correctly
4321 if ( !CommitChangesFromEditor() )
4324 m_wndEditor
->Show ( false );
4327 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4329 m_canvas
->CaptureMouse();
4330 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4334 m_draggedSplitter
= splitterHit
;
4335 m_dragOffset
= splitterHitOffset
;
4337 wxClientDC
dc(m_canvas
);
4339 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4340 // Fixes button disappearance bug
4342 m_wndEditor2
->Show ( false );
4345 m_startingSplitterX
= x
- splitterHitOffset
;
4353 if ( p
->GetChildCount() )
4355 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4357 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4359 int y2
= y
% m_lineHeight
;
4360 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4362 // On click on expander button, expand/collapse
4363 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4364 DoCollapse( p
, true );
4366 DoExpand( p
, true );
4375 // -----------------------------------------------------------------------
4377 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4378 wxMouseEvent
& WXUNUSED(event
) )
4382 // Select property here as well
4383 wxPGProperty
* p
= m_propHover
;
4384 if ( p
!= m_selected
)
4385 DoSelectProperty( p
);
4387 // Send right click event.
4388 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4395 // -----------------------------------------------------------------------
4397 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4398 wxMouseEvent
& WXUNUSED(event
) )
4402 // Select property here as well
4403 wxPGProperty
* p
= m_propHover
;
4405 if ( p
!= m_selected
)
4406 DoSelectProperty( p
);
4408 // Send double-click event.
4409 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4416 // -----------------------------------------------------------------------
4418 #if wxPG_SUPPORT_TOOLTIPS
4420 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4422 if ( tipString
.length() )
4424 m_canvas
->SetToolTip(tipString
);
4428 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4429 m_canvas
->SetToolTip( m_emptyString
);
4431 m_canvas
->SetToolTip( NULL
);
4436 #endif // #if wxPG_SUPPORT_TOOLTIPS
4438 // -----------------------------------------------------------------------
4440 // Return false if should be skipped
4441 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4443 // Safety check (needed because mouse capturing may
4444 // otherwise freeze the control)
4445 if ( m_dragStatus
> 0 && !event
.Dragging() )
4447 HandleMouseUp(x
,y
,event
);
4450 wxPropertyGridPageState
* state
= m_pState
;
4452 int splitterHitOffset
;
4453 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4454 int splitterX
= x
- splitterHitOffset
;
4456 if ( m_dragStatus
> 0 )
4458 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4459 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4462 int newSplitterX
= x
- m_dragOffset
;
4463 int splitterX
= x
- splitterHitOffset
;
4465 // Splitter redraw required?
4466 if ( newSplitterX
!= splitterX
)
4469 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4470 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4471 state
->m_fSplitterX
= (float) newSplitterX
;
4474 CorrectEditorWidgetSizeX();
4488 int ih
= m_lineHeight
;
4491 #if wxPG_SUPPORT_TOOLTIPS
4492 wxPGProperty
* prevHover
= m_propHover
;
4493 unsigned char prevSide
= m_mouseSide
;
4495 int curPropHoverY
= y
- (y
% ih
);
4497 // On which item it hovers
4498 if ( ( !m_propHover
)
4500 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4503 // Mouse moves on another property
4505 m_propHover
= DoGetItemAtY(y
);
4506 m_propHoverY
= curPropHoverY
;
4509 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4512 #if wxPG_SUPPORT_TOOLTIPS
4513 // Store which side we are on
4515 if ( columnHit
== 1 )
4517 else if ( columnHit
== 0 )
4521 // If tooltips are enabled, show label or value as a tip
4522 // in case it doesn't otherwise show in full length.
4524 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4526 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4528 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4530 if ( m_propHover
&& !m_propHover
->IsCategory() )
4533 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4535 // Show help string as a tooltip
4536 wxString tipString
= m_propHover
->GetHelpString();
4538 SetToolTip(tipString
);
4542 // Show cropped value string as a tooltip
4546 if ( m_mouseSide
== 1 )
4548 tipString
= m_propHover
->m_label
;
4549 space
= splitterX
-m_marginWidth
-3;
4551 else if ( m_mouseSide
== 2 )
4553 tipString
= m_propHover
->GetDisplayedString();
4555 space
= m_width
- splitterX
;
4556 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4557 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4563 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4566 SetToolTip( tipString
);
4573 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4574 m_canvas
->SetToolTip( m_emptyString
);
4576 m_canvas
->SetToolTip( NULL
);
4587 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4588 m_canvas
->SetToolTip( m_emptyString
);
4590 m_canvas
->SetToolTip( NULL
);
4598 if ( splitterHit
== -1 ||
4600 HasFlag(wxPG_STATIC_SPLITTER
) )
4602 // hovering on something else
4603 if ( m_curcursor
!= wxCURSOR_ARROW
)
4604 CustomSetCursor( wxCURSOR_ARROW
);
4608 // Do not allow splitter cursor on caption items.
4609 // (also not if we were dragging and its started
4610 // outside the splitter region)
4613 !m_propHover
->IsCategory() &&
4617 // hovering on splitter
4619 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4620 // reliably detected.
4621 //if ( m_curcursor != wxCURSOR_SIZEWE )
4622 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4628 // hovering on something else
4629 if ( m_curcursor
!= wxCURSOR_ARROW
)
4630 CustomSetCursor( wxCURSOR_ARROW
);
4637 // -----------------------------------------------------------------------
4639 // Also handles Leaving event
4640 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4641 wxMouseEvent
&WXUNUSED(event
) )
4643 wxPropertyGridPageState
* state
= m_pState
;
4647 int splitterHitOffset
;
4648 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4650 // No event type check - basicly calling this method should
4651 // just stop dragging.
4652 // Left up after dragged?
4653 if ( m_dragStatus
>= 1 )
4656 // End Splitter Dragging
4658 // DO NOT ENABLE FOLLOWING LINE!
4659 // (it is only here as a reminder to not to do it)
4662 // Disable splitter auto-centering
4663 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4665 // This is necessary to return cursor
4666 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4668 m_canvas
->ReleaseMouse();
4669 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4672 // Set back the default cursor, if necessary
4673 if ( splitterHit
== -1 ||
4676 CustomSetCursor( wxCURSOR_ARROW
);
4681 // Control background needs to be cleared
4682 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4683 DrawItem( m_selected
);
4687 m_wndEditor
->Show ( true );
4690 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4691 // Fixes button disappearance bug
4693 m_wndEditor2
->Show ( true );
4696 // This clears the focus.
4697 m_editorFocused
= 0;
4703 // -----------------------------------------------------------------------
4705 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4707 int splitterX
= GetSplitterPosition();
4710 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4714 wxWindow
* wnd
= m_wndEditor
;
4716 // Hide popup on clicks
4717 if ( event
.GetEventType() != wxEVT_MOTION
)
4718 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4720 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4726 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4728 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4729 ux
>= (r
.x
+r
.width
) ||
4731 event
.m_y
>= (r
.y
+r
.height
)
4741 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4746 // -----------------------------------------------------------------------
4748 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4751 if ( OnMouseCommon( event
, &x
, &y
) )
4753 HandleMouseClick(x
,y
,event
);
4758 // -----------------------------------------------------------------------
4760 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4763 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4764 HandleMouseRightClick(x
,y
,event
);
4768 // -----------------------------------------------------------------------
4770 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4772 // Always run standard mouse-down handler as well
4773 OnMouseClick(event
);
4776 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4777 HandleMouseDoubleClick(x
,y
,event
);
4781 // -----------------------------------------------------------------------
4783 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4786 if ( OnMouseCommon( event
, &x
, &y
) )
4788 HandleMouseMove(x
,y
,event
);
4793 // -----------------------------------------------------------------------
4795 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4797 // Called when mouse moves in the empty space below the properties.
4798 CustomSetCursor( wxCURSOR_ARROW
);
4801 // -----------------------------------------------------------------------
4803 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4806 if ( OnMouseCommon( event
, &x
, &y
) )
4808 HandleMouseUp(x
,y
,event
);
4813 // -----------------------------------------------------------------------
4815 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4817 // This may get called from child control as well, so event's
4818 // mouse position cannot be relied on.
4820 if ( event
.Entering() )
4822 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4824 // TODO: Fix this (detect parent and only do
4825 // cursor trick if it is a manager).
4826 wxASSERT( GetParent() );
4827 GetParent()->SetCursor(wxNullCursor
);
4829 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4832 GetParent()->SetCursor(wxNullCursor
);
4834 else if ( event
.Leaving() )
4836 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4837 m_canvas
->SetCursor( wxNullCursor
);
4839 // Get real cursor position
4840 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4842 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4845 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4847 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4851 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4859 // -----------------------------------------------------------------------
4861 // Common code used by various OnMouseXXXChild methods.
4862 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4864 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4865 wxASSERT( topCtrlWnd
);
4867 event
.GetPosition(&x
,&y
);
4869 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4871 int splitterX
= GetSplitterPosition();
4873 wxRect r
= topCtrlWnd
->GetRect();
4874 if ( !m_dragStatus
&&
4875 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4876 y
>= 0 && y
< r
.height \
4879 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4884 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4891 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4894 if ( OnMouseChildCommon(event
,&x
,&y
) )
4896 bool res
= HandleMouseClick(x
,y
,event
);
4897 if ( !res
) event
.Skip();
4901 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4904 wxASSERT( m_wndEditor
);
4905 // These coords may not be exact (about +-2),
4906 // but that should not matter (right click is about item, not position).
4907 wxPoint pt
= m_wndEditor
->GetPosition();
4908 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4909 wxASSERT( m_selected
);
4910 m_propHover
= m_selected
;
4911 bool res
= HandleMouseRightClick(x
,y
,event
);
4912 if ( !res
) event
.Skip();
4915 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4918 if ( OnMouseChildCommon(event
,&x
,&y
) )
4920 bool res
= HandleMouseMove(x
,y
,event
);
4921 if ( !res
) event
.Skip();
4925 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4928 if ( OnMouseChildCommon(event
,&x
,&y
) )
4930 bool res
= HandleMouseUp(x
,y
,event
);
4931 if ( !res
) event
.Skip();
4935 // -----------------------------------------------------------------------
4936 // wxPropertyGrid keyboard event handling
4937 // -----------------------------------------------------------------------
4939 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4941 wxNavigationKeyEvent evt
;
4942 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4943 (dir
?wxNavigationKeyEvent::IsForward
:
4944 wxNavigationKeyEvent::IsBackward
));
4945 evt
.SetEventObject(this);
4946 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4950 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4952 // Translates wxKeyEvent to wxPG_ACTION_XXX
4954 int keycode
= event
.GetKeyCode();
4955 int modifiers
= event
.GetModifiers();
4957 wxASSERT( !(modifiers
&~(0xFFFF)) );
4959 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4961 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4963 if ( it
== m_actionTriggers
.end() )
4968 int second
= (it
->second
>>16) & 0xFFFF;
4972 return (it
->second
& 0xFFFF);
4975 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4977 wxASSERT( !(modifiers
&~(0xFFFF)) );
4979 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4981 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4983 if ( it
!= m_actionTriggers
.end() )
4985 // This key combination is already used
4987 // Can add secondary?
4988 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4989 wxT("You can only add up to two separate actions per key combination.") );
4991 action
= it
->second
| (action
<<16);
4994 m_actionTriggers
[hashMapKey
] = action
;
4997 void wxPropertyGrid::ClearActionTriggers( int action
)
4999 wxPGHashMapI2I::iterator it
;
5001 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
5003 if ( it
->second
== action
)
5005 m_actionTriggers
.erase(it
);
5010 static void CopyTextToClipboard( const wxString
& text
)
5012 if ( wxTheClipboard
->Open() )
5014 // This data objects are held by the clipboard,
5015 // so do not delete them in the app.
5016 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
5017 wxTheClipboard
->Close();
5021 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5024 // Handles key event when editor control is not focused.
5027 wxASSERT( !m_frozen
);
5031 // Travelsal between items, collapsing/expanding, etc.
5032 int keycode
= event
.GetKeyCode();
5034 if ( keycode
== WXK_TAB
)
5036 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5040 // Ignore Alt and Control when they are down alone
5041 if ( keycode
== WXK_ALT
||
5042 keycode
== WXK_CONTROL
)
5049 int action
= KeyEventToActions(event
, &secondAction
);
5055 if ( ButtonTriggerKeyTest(event
) )
5058 wxPGProperty
* p
= m_selected
;
5060 if ( action
== wxPG_ACTION_COPY
)
5062 CopyTextToClipboard(p
->GetDisplayedString());
5066 // Travel and expand/collapse
5069 if ( p
->GetChildCount() &&
5070 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5073 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5075 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5078 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5080 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5087 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5091 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5102 if ( selectDir
>= -1 )
5104 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5106 DoSelectProperty(p
);
5112 // If nothing was selected, select the first item now
5113 // (or navigate out of tab).
5114 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5116 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5117 if ( p
) DoSelectProperty(p
);
5122 // -----------------------------------------------------------------------
5124 // Potentially handles a keyboard event for editor controls.
5125 // Returns false if event should *not* be skipped (on true it can
5126 // be optionally skipped).
5127 // Basicly, false means that SelectProperty was called (or was about
5128 // to be called, if canDestroy was false).
5129 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5133 if ( !m_selected
|| !m_wndEditor
)
5138 int action
= KeyEventToAction(event
);
5141 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5144 // Esc cancels any changes
5145 if ( IsEditorsValueModified() )
5147 EditorsValueWasNotModified();
5149 // Update the control as well
5150 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5152 m_selected
->GetDisplayedString() );
5155 OnValidationFailureReset(m_selected
);
5161 else if ( action
== wxPG_ACTION_COPY
)
5163 // NB: There is some problem with getting native cut-copy-paste keys to go through
5164 // for embedded editor wxTextCtrl. This is why we emulate.
5166 wxTextCtrl
* tc
= GetEditorTextCtrl();
5169 wxString sel
= tc
->GetStringSelection();
5171 CopyTextToClipboard(sel
);
5175 CopyTextToClipboard(m_selected
->GetDisplayedString());
5178 else if ( action
== wxPG_ACTION_CUT
)
5180 wxTextCtrl
* tc
= GetEditorTextCtrl();
5184 tc
->GetSelection(&from
, &to
);
5187 CopyTextToClipboard(tc
->GetStringSelection());
5188 tc
->Remove(from
, to
);
5192 else if ( action
== wxPG_ACTION_PASTE
)
5194 wxTextCtrl
* tc
= GetEditorTextCtrl();
5197 if (wxTheClipboard
->Open())
5199 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5201 wxTextDataObject data
;
5202 wxTheClipboard
->GetData( data
);
5204 tc
->GetSelection(&from
, &to
);
5207 tc
->Remove(from
, to
);
5208 tc
->WriteText(data
.GetText());
5212 tc
->WriteText(data
.GetText());
5215 wxTheClipboard
->Close();
5223 // -----------------------------------------------------------------------
5225 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5229 // Events to editor controls should get relayed here.
5231 wxWindow
* focused
= wxWindow::FindFocus();
5233 wxWindow
* primaryCtrl
= GetEditorControl();
5236 (focused
==primaryCtrl
5237 || m_editorFocused
) )
5239 // Child key must be processed here, since it can
5240 // destroy the control which is referred by its own
5242 HandleChildKey( event
);
5245 HandleKeyEvent( event
);
5248 // -----------------------------------------------------------------------
5250 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5252 m_keyComboConsumed
= 0;
5257 // -----------------------------------------------------------------------
5259 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5261 // Ignore events that occur very close to focus set
5262 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5264 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5269 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5271 int dir
= event
.GetDirection()?1:-1;
5275 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5277 wxWindow
* focused
= wxWindow::FindFocus();
5279 wxWindow
* wndToCheck
= GetEditorControl();
5281 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5282 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5284 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5285 if ( comboTextCtrl
)
5286 wndToCheck
= comboTextCtrl
;
5290 // Because of problems navigating from wxButton, do not go to it.
5293 // No primary, use secondary
5294 wndToCheck = m_wndEditor2;
5296 // If it has editor button, focus to it after the primary editor.
5297 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5298 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5299 // have somewhat debugged in window.cpp itself).
5300 else if ( focused == wndToCheck &&
5302 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5304 wndToCheck = m_wndEditor2;
5305 wxLogDebug(wxT("Exp1"));
5309 if ( focused
!= wndToCheck
&&
5312 wndToCheck
->SetFocus();
5314 // Select all text in wxTextCtrl etc.
5315 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5316 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5318 m_editorFocused
= 1;
5325 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5329 // This allows preventing NavigateOut to occur
5330 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5339 // -----------------------------------------------------------------------
5341 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5343 int keycode
= event
.GetKeyCode();
5345 // Does the keycode trigger button?
5346 if ( keycode
== m_pushButKeyCode
&&
5348 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5349 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5351 m_keyComboConsumed
= 1;
5353 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5354 GetEventHandler()->AddPendingEvent(evt
);
5361 // -----------------------------------------------------------------------
5363 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5365 int keycode
= event
.GetKeyCode();
5367 // Ignore Alt and Control when they are down alone
5368 if ( keycode
== WXK_ALT
||
5369 keycode
== WXK_CONTROL
)
5375 if ( ButtonTriggerKeyTest(event
) )
5378 if ( HandleChildKey(event
) == true )
5381 GetEventHandler()->AddPendingEvent(event
);
5384 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5386 m_keyComboConsumed
= 0;
5388 GetEventHandler()->AddPendingEvent(event
);
5393 // -----------------------------------------------------------------------
5394 // wxPropertyGrid miscellaneous event handling
5395 // -----------------------------------------------------------------------
5397 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5400 // Check if the focus is in this control or one of its children
5401 wxWindow
* newFocused
= wxWindow::FindFocus();
5403 if ( newFocused
!= m_curFocused
)
5404 HandleFocusChange( newFocused
);
5407 // Called by focus event handlers. newFocused is the window that becomes focused.
5408 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5410 unsigned int oldFlags
= m_iFlags
;
5412 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5414 wxWindow
* parent
= newFocused
;
5416 // This must be one of nextFocus' parents.
5419 // Use m_eventObject, which is either wxPropertyGrid or
5420 // wxPropertyGridManager, as appropriate.
5421 if ( parent
== m_eventObject
)
5423 m_iFlags
|= wxPG_FL_FOCUSED
;
5426 parent
= parent
->GetParent();
5429 m_curFocused
= newFocused
;
5431 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5432 (oldFlags
& wxPG_FL_FOCUSED
) )
5434 // On each focus kill, mark the next nav key event
5435 // to be ignored (can't do on set focus since the
5436 // event would occur before it).
5437 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5439 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5441 // Need to store changed value
5442 CommitChangesFromEditor();
5448 // Preliminary code for tab-order respecting
5449 // tab-traversal (but should be moved to
5452 wxWindow* prevFocus = event.GetWindow();
5453 wxWindow* useThis = this;
5454 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5455 useThis = GetParent();
5458 prevFocus->GetParent() == useThis->GetParent() )
5460 wxList& children = useThis->GetParent()->GetChildren();
5462 wxNode* node = children.Find(prevFocus);
5464 if ( node->GetNext() &&
5465 useThis == node->GetNext()->GetData() )
5466 DoSelectProperty(GetFirst());
5467 else if ( node->GetPrevious () &&
5468 useThis == node->GetPrevious()->GetData() )
5469 DoSelectProperty(GetLastProperty());
5474 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5478 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5479 DrawItem( m_selected
);
5483 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5485 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5486 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5487 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5488 //else if ( event.GetWindow() )
5490 HandleFocusChange(event
.GetWindow());
5495 // -----------------------------------------------------------------------
5497 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5499 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5502 // event.Skip() being commented out is aworkaround for bug reported
5503 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5507 // -----------------------------------------------------------------------
5509 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5511 m_iFlags
|= wxPG_FL_SCROLLED
;
5516 // -----------------------------------------------------------------------
5518 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5520 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5522 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5526 // -----------------------------------------------------------------------
5527 // Property editor related functions
5528 // -----------------------------------------------------------------------
5530 // noDefCheck = true prevents infinite recursion.
5531 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorclass
,
5532 const wxString
& name
,
5535 wxASSERT( editorclass
);
5537 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5538 RegisterDefaultEditors();
5540 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorclass
;
5545 // Registers all default editor classes
5546 void wxPropertyGrid::RegisterDefaultEditors()
5548 wxPGRegisterDefaultEditorClass( TextCtrl
);
5549 wxPGRegisterDefaultEditorClass( Choice
);
5550 wxPGRegisterDefaultEditorClass( ComboBox
);
5551 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5552 #if wxPG_INCLUDE_CHECKBOX
5553 wxPGRegisterDefaultEditorClass( CheckBox
);
5555 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5557 // Register SpinCtrl etc. editors before use
5558 RegisterAdditionalEditors();
5561 // -----------------------------------------------------------------------
5562 // wxPGStringTokenizer
5563 // Needed to handle C-style string lists (e.g. "str1" "str2")
5564 // -----------------------------------------------------------------------
5566 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5567 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5571 wxPGStringTokenizer::~wxPGStringTokenizer()
5575 bool wxPGStringTokenizer::HasMoreTokens()
5577 const wxString
& str
= *m_str
;
5579 wxString::const_iterator i
= m_curPos
;
5581 wxUniChar delim
= m_delimeter
;
5583 wxUniChar prev_a
= wxT('\0');
5585 bool inToken
= false;
5587 while ( i
!= str
.end() )
5596 m_readyToken
.clear();
5601 if ( prev_a
!= wxT('\\') )
5605 if ( a
!= wxT('\\') )
5625 m_curPos
= str
.end();
5633 wxString
wxPGStringTokenizer::GetNextToken()
5635 return m_readyToken
;
5638 // -----------------------------------------------------------------------
5640 // -----------------------------------------------------------------------
5642 wxPGChoiceEntry::wxPGChoiceEntry()
5643 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5647 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5648 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5649 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5653 // -----------------------------------------------------------------------
5655 // -----------------------------------------------------------------------
5657 wxPGChoicesData::wxPGChoicesData()
5662 wxPGChoicesData::~wxPGChoicesData()
5667 void wxPGChoicesData::Clear()
5671 for ( i
=0; i
<m_items
.size(); i
++ )
5683 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5685 wxASSERT( m_items
.size() == 0 );
5689 for ( i
=0; i
<data
->GetCount(); i
++ )
5690 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5693 // -----------------------------------------------------------------------
5695 // -----------------------------------------------------------------------
5697 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5701 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5702 m_data
->Insert( -1, p
);
5706 // -----------------------------------------------------------------------
5708 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5712 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5713 p
->SetBitmap(bitmap
);
5714 m_data
->Insert( -1, p
);
5718 // -----------------------------------------------------------------------
5720 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5724 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5725 m_data
->Insert(index
, p
);
5729 // -----------------------------------------------------------------------
5731 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5735 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5736 m_data
->Insert( index
, p
);
5740 // -----------------------------------------------------------------------
5742 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5748 while ( index
< GetCount() )
5750 int cmpRes
= GetLabel(index
).Cmp(label
);
5756 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5757 m_data
->Insert( index
, p
);
5761 // -----------------------------------------------------------------------
5763 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5767 unsigned int itemcount
= 0;
5768 const wxChar
** p
= &labels
[0];
5769 while ( *p
) { p
++; itemcount
++; }
5772 for ( i
= 0; i
< itemcount
; i
++ )
5774 int value
= wxPG_INVALID_VALUE
;
5777 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5781 // -----------------------------------------------------------------------
5783 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5788 unsigned int itemcount
= arr
.size();
5790 for ( i
= 0; i
< itemcount
; i
++ )
5792 int value
= wxPG_INVALID_VALUE
;
5795 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5799 // -----------------------------------------------------------------------
5801 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5806 unsigned int itemcount
= arr
.size();
5808 for ( i
= 0; i
< itemcount
; i
++ )
5810 int value
= wxPG_INVALID_VALUE
;
5811 if ( &arrint
&& arrint
.size() )
5813 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5817 // -----------------------------------------------------------------------
5819 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5821 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5823 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5824 delete m_data
->Item(i
);
5825 m_data
->m_items
.RemoveAt(nIndex
, count
);
5828 // -----------------------------------------------------------------------
5830 int wxPGChoices::Index( const wxString
& str
) const
5835 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5837 if ( m_data
->Item(i
)->GetText() == str
)
5844 // -----------------------------------------------------------------------
5846 int wxPGChoices::Index( int val
) const
5851 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5853 if ( m_data
->Item(i
)->GetValue() == val
)
5860 // -----------------------------------------------------------------------
5862 wxArrayString
wxPGChoices::GetLabels() const
5867 if ( this && IsOk() )
5868 for ( i
=0; i
<GetCount(); i
++ )
5869 arr
.push_back(GetLabel(i
));
5874 // -----------------------------------------------------------------------
5876 bool wxPGChoices::HasValues() const
5881 // -----------------------------------------------------------------------
5883 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5890 for ( i
=0; i
< strings
.size(); i
++ )
5892 int index
= Index(strings
[i
]);
5894 arr
.Add(GetValue(index
));
5896 arr
.Add(wxPG_INVALID_VALUE
);
5903 // -----------------------------------------------------------------------
5905 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5906 wxArrayString
* unmatched
) const
5913 for ( i
=0; i
< strings
.size(); i
++ )
5915 const wxString
& str
= strings
[i
];
5916 int index
= Index(str
);
5919 else if ( unmatched
)
5920 unmatched
->Add(str
);
5927 // -----------------------------------------------------------------------
5929 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5933 if ( data
!= wxPGChoicesEmptyData
)
5940 // -----------------------------------------------------------------------
5942 void wxPGChoices::Init()
5944 m_data
= wxPGChoicesEmptyData
;
5947 // -----------------------------------------------------------------------
5949 void wxPGChoices::Free()
5951 if ( m_data
!= wxPGChoicesEmptyData
)
5954 m_data
= wxPGChoicesEmptyData
;
5958 // -----------------------------------------------------------------------
5959 // wxPropertyGridEvent
5960 // -----------------------------------------------------------------------
5962 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5965 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5966 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5967 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5968 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5969 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5970 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5971 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5972 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5973 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5976 // -----------------------------------------------------------------------
5978 void wxPropertyGridEvent::Init()
5980 m_validationInfo
= NULL
;
5982 m_wasVetoed
= false;
5985 // -----------------------------------------------------------------------
5987 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5988 : wxCommandEvent(commandType
,id
)
5994 // -----------------------------------------------------------------------
5996 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5997 : wxCommandEvent(event
)
5999 m_eventType
= event
.GetEventType();
6000 m_eventObject
= event
.m_eventObject
;
6002 m_property
= event
.m_property
;
6003 m_validationInfo
= event
.m_validationInfo
;
6004 m_canVeto
= event
.m_canVeto
;
6005 m_wasVetoed
= event
.m_wasVetoed
;
6008 // -----------------------------------------------------------------------
6010 wxPropertyGridEvent::~wxPropertyGridEvent()
6014 // -----------------------------------------------------------------------
6016 wxEvent
* wxPropertyGridEvent::Clone() const
6018 return new wxPropertyGridEvent( *this );
6021 // -----------------------------------------------------------------------
6022 // wxPropertyGridPopulator
6023 // -----------------------------------------------------------------------
6025 wxPropertyGridPopulator::wxPropertyGridPopulator()
6029 wxPGGlobalVars
->m_offline
++;
6032 // -----------------------------------------------------------------------
6034 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6037 m_propHierarchy
.clear();
6040 // -----------------------------------------------------------------------
6042 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6048 // -----------------------------------------------------------------------
6050 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6053 // Free unused sets of choices
6054 wxPGHashMapS2P::iterator it
;
6056 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6058 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6065 m_pg
->GetPanel()->Refresh();
6067 wxPGGlobalVars
->m_offline
--;
6070 // -----------------------------------------------------------------------
6072 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6073 const wxString
& propLabel
,
6074 const wxString
& propName
,
6075 const wxString
* propValue
,
6076 wxPGChoices
* pChoices
)
6078 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6079 wxPGProperty
* parent
= GetCurParent();
6081 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6083 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6087 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6089 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6093 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6095 property
->SetLabel(propLabel
);
6096 property
->DoSetName(propName
);
6098 if ( pChoices
&& pChoices
->IsOk() )
6099 property
->SetChoices(*pChoices
);
6101 m_state
->DoInsert(parent
, -1, property
);
6104 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6109 // -----------------------------------------------------------------------
6111 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6113 m_propHierarchy
.push_back(property
);
6114 DoScanForChildren();
6115 m_propHierarchy
.pop_back();
6118 // -----------------------------------------------------------------------
6120 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6121 const wxString
& idString
)
6123 wxPGChoices choices
;
6126 if ( choicesString
[0] == wxT('@') )
6128 wxString ids
= choicesString
.substr(1);
6129 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6130 if ( it
== m_dictIdChoices
.end() )
6131 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6133 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6138 if ( idString
.length() )
6140 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6141 if ( it
!= m_dictIdChoices
.end() )
6143 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6150 // Parse choices string
6151 wxString::const_iterator it
= choicesString
.begin();
6155 bool labelValid
= false;
6157 for ( ; it
!= choicesString
.end(); it
++ )
6163 if ( c
== wxT('"') )
6168 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6169 choices
.Add(label
, l
);
6172 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6177 else if ( c
== wxT('=') )
6184 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6191 if ( c
== wxT('"') )
6204 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6205 choices
.Add(label
, l
);
6208 if ( !choices
.IsOk() )
6210 choices
.EnsureData();
6214 if ( idString
.length() )
6215 m_dictIdChoices
[idString
] = choices
.GetData();
6222 // -----------------------------------------------------------------------
6224 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6226 if ( s
.Last() == wxT('%') )
6228 wxString s2
= s
.substr(0,s
.length()-1);
6230 if ( s2
.ToLong(&val
, 10) )
6232 *pval
= (val
*max
)/100;
6238 return s
.ToLong(pval
, 10);
6241 // -----------------------------------------------------------------------
6243 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6244 const wxString
& type
,
6245 const wxString
& value
)
6247 int l
= m_propHierarchy
.size();
6251 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6252 wxString valuel
= value
.Lower();
6255 if ( type
.length() == 0 )
6260 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6262 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6264 else if ( value
.ToLong(&v
, 0) )
6271 if ( type
== wxT("string") )
6275 else if ( type
== wxT("int") )
6278 value
.ToLong(&v
, 0);
6281 else if ( type
== wxT("bool") )
6283 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6290 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6295 p
->SetAttribute( name
, variant
);
6300 // -----------------------------------------------------------------------
6302 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6304 wxLogError(_("Error in resource: %s"),msg
.c_str());
6307 // -----------------------------------------------------------------------
6309 #endif // wxUSE_PROPGRID