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 wxWindow
* wnd
= argWnd
;
3478 if ( argWnd
== m_wndEditor
)
3480 this->Connect(id
, wxEVT_MOTION
,
3481 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
));
3482 this->Connect(id
, wxEVT_LEFT_UP
,
3483 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
));
3484 this->Connect(id
, wxEVT_LEFT_DOWN
,
3485 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
));
3486 this->Connect(id
, wxEVT_RIGHT_UP
,
3487 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
));
3488 this->Connect(id
, wxEVT_ENTER_WINDOW
,
3489 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3490 this->Connect(id
, wxEVT_LEAVE_WINDOW
,
3491 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3495 this->Connect(id
, wxEVT_NAVIGATION_KEY
,
3496 wxNavigationKeyEventHandler(wxPropertyGrid::OnNavigationKey
));
3499 this->Connect(id
, wxEVT_KEY_DOWN
,
3500 wxKeyEventHandler(wxPropertyGrid::OnChildKeyDown
));
3501 this->Connect(id
, wxEVT_KEY_UP
,
3502 wxKeyEventHandler(wxPropertyGrid::OnChildKeyUp
));
3503 this->Connect(id
, wxEVT_KILL_FOCUS
,
3504 wxFocusEventHandler(wxPropertyGrid::OnFocusEvent
));
3507 void wxPropertyGrid::FreeEditors()
3509 // Do not free editors immediately if processing events
3510 if ( !m_windowsToDelete
)
3511 m_windowsToDelete
= new wxArrayPtrVoid
;
3515 m_windowsToDelete
->push_back(m_wndEditor2
);
3516 m_wndEditor2
->Hide();
3517 m_wndEditor2
= (wxWindow
*) NULL
;
3522 m_windowsToDelete
->push_back(m_wndEditor
);
3523 m_wndEditor
->Hide();
3524 m_wndEditor
= (wxWindow
*) NULL
;
3528 // Call with NULL to de-select property
3529 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3531 wxPanel
* canvas
= GetPanel();
3535 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3536 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3538 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3541 if ( m_inDoSelectProperty
)
3544 m_inDoSelectProperty
= 1;
3546 wxPGProperty
* prev
= m_selected
;
3549 // Delete windows pending for deletion
3550 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3554 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3555 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3557 m_windowsToDelete
->clear();
3562 m_inDoSelectProperty
= 0;
3567 // If we are frozen, then just set the values.
3570 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3571 m_editorFocused
= 0;
3574 m_pState
->m_selected
= p
;
3576 // If frozen, always free controls. But don't worry, as Thaw will
3577 // recall SelectProperty to recreate them.
3580 // Prevent any further selection measures in this call
3581 p
= (wxPGProperty
*) NULL
;
3586 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3588 // Only set focus if not deselecting
3591 if ( flags
& wxPG_SEL_FOCUS
)
3595 m_wndEditor
->SetFocus();
3596 m_editorFocused
= 1;
3605 m_inDoSelectProperty
= 0;
3610 // First, deactivate previous
3614 OnValidationFailureReset(m_selected
);
3616 // Must double-check if this is an selected in case of forceswitch
3619 if ( !CommitChangesFromEditor(flags
) )
3621 // Validation has failed, so we can't exit the previous editor
3622 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3623 // _("Invalid Value"),wxOK|wxICON_ERROR);
3624 m_inDoSelectProperty
= 0;
3632 m_selected
= (wxPGProperty
*) NULL
;
3633 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3635 // We need to always fully refresh the grid here
3638 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3639 EditorsValueWasNotModified();
3642 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3645 // Then, activate the one given.
3648 int propY
= p
->GetY2(m_lineHeight
);
3650 int splitterX
= GetSplitterPosition();
3651 m_editorFocused
= 0;
3653 m_pState
->m_selected
= p
;
3654 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3656 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3658 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3660 // Do we need OnMeasureCalls?
3661 wxSize imsz
= p
->OnMeasureImage();
3664 // Only create editor for non-disabled non-caption
3665 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3667 // do this for non-caption items
3671 // Do we need to paint the custom image, if any?
3672 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3673 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3674 !p
->GetEditorClass()->CanContainCustomImage()
3676 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3678 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3679 wxPoint goodPos
= grect
.GetPosition();
3680 #if wxPG_CREATE_CONTROLS_HIDDEN
3681 int coord_adjust
= m_height
- goodPos
.y
;
3682 goodPos
.y
+= coord_adjust
;
3685 const wxPGEditor
* editor
= p
->GetEditorClass();
3686 wxCHECK_MSG(editor
, false,
3687 wxT("NULL editor class not allowed"));
3689 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3691 wxPGWindowList wndList
= editor
->CreateControls(this,
3696 m_wndEditor
= wndList
.m_primary
;
3697 m_wndEditor2
= wndList
.m_secondary
;
3699 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3700 // value is drawn as normal, and m_wndEditor2 is assumed
3701 // to be a right-aligned button that triggers a separate editor
3706 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3707 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3709 // Set validator, if any
3710 #if wxUSE_VALIDATORS
3711 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3713 wxValidator
* validator
= p
->GetValidator();
3715 m_wndEditor
->SetValidator(*validator
);
3719 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3720 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3722 // If it has modified status, use bold font
3723 // (must be done before capturing m_ctrlXAdjust)
3724 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3725 SetCurControlBoldFont();
3728 // Fix TextCtrl indentation
3729 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3730 wxTextCtrl
* tc
= NULL
;
3731 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3732 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3734 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3736 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3739 // Store x relative to splitter (we'll need it).
3740 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3742 // Check if background clear is not necessary
3743 wxPoint pos
= m_wndEditor
->GetPosition();
3744 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3746 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3749 m_wndEditor
->SetSizeHints(3, 3);
3751 #if wxPG_CREATE_CONTROLS_HIDDEN
3752 m_wndEditor
->Show(false);
3753 m_wndEditor
->Freeze();
3755 goodPos
= m_wndEditor
->GetPosition();
3756 goodPos
.y
-= coord_adjust
;
3757 m_wndEditor
->Move( goodPos
);
3760 wxWindow
* primaryCtrl
= GetEditorControl();
3761 SetupChildEventHandling(primaryCtrl
, wxPG_SUBID1
);
3763 // Focus and select all (wxTextCtrl, wxComboBox etc)
3764 if ( flags
& wxPG_SEL_FOCUS
)
3766 primaryCtrl
->SetFocus();
3768 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3774 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3775 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3777 // Get proper id for wndSecondary
3778 m_wndSecId
= m_wndEditor2
->GetId();
3779 wxWindowList children
= m_wndEditor2
->GetChildren();
3780 wxWindowList::iterator node
= children
.begin();
3781 if ( node
!= children
.end() )
3782 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3784 m_wndEditor2
->SetSizeHints(3,3);
3786 #if wxPG_CREATE_CONTROLS_HIDDEN
3787 wxRect sec_rect
= m_wndEditor2
->GetRect();
3788 sec_rect
.y
-= coord_adjust
;
3790 // Fine tuning required to fix "oversized"
3791 // button disappearance bug.
3792 if ( sec_rect
.y
< 0 )
3794 sec_rect
.height
+= sec_rect
.y
;
3797 m_wndEditor2
->SetSize( sec_rect
);
3799 m_wndEditor2
->Show();
3801 SetupChildEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3803 // If no primary editor, focus to button to allow
3804 // it to interprete ENTER etc.
3805 // NOTE: Due to problems focusing away from it, this
3806 // has been disabled.
3808 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3809 m_wndEditor2->SetFocus();
3813 if ( flags
& wxPG_SEL_FOCUS
)
3814 m_editorFocused
= 1;
3819 // Make sure focus is in grid canvas (important for wxGTK, at least)
3823 EditorsValueWasNotModified();
3825 // If it's inside collapsed section, expand parent, scroll, etc.
3826 // Also, if it was partially visible, scroll it into view.
3827 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3832 #if wxPG_CREATE_CONTROLS_HIDDEN
3833 m_wndEditor
->Thaw();
3835 m_wndEditor
->Show(true);
3842 // Make sure focus is in grid canvas
3846 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3852 // Show help text in status bar.
3853 // (if found and grid not embedded in manager with help box and
3854 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3857 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3859 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3860 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3862 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3864 statusbar
= frame
->GetStatusBar();
3869 const wxString
* pHelpString
= (const wxString
*) NULL
;
3873 pHelpString
= &p
->GetHelpString();
3874 if ( pHelpString
->length() )
3876 // Set help box text.
3877 statusbar
->SetStatusText( *pHelpString
);
3878 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3882 if ( (!pHelpString
|| !pHelpString
->length()) &&
3883 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3885 // Clear help box - but only if it was written
3886 // by us at previous time.
3887 statusbar
->SetStatusText( m_emptyString
);
3888 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3894 m_inDoSelectProperty
= 0;
3896 // call wx event handler (here so that it also occurs on deselection)
3897 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3902 // -----------------------------------------------------------------------
3904 bool wxPropertyGrid::UnfocusEditor()
3906 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3909 if ( !CommitChangesFromEditor(0) )
3913 DrawItem(m_selected
);
3918 // -----------------------------------------------------------------------
3920 // This method is not inline because it called dozens of times
3921 // (i.e. two-arg function calls create smaller code size).
3922 bool wxPropertyGrid::DoClearSelection()
3924 return DoSelectProperty((wxPGProperty
*)NULL
);
3927 // -----------------------------------------------------------------------
3928 // wxPropertyGrid expand/collapse state
3929 // -----------------------------------------------------------------------
3931 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3933 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3935 // If active editor was inside collapsed section, then disable it
3936 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3938 if ( !ClearSelection() )
3942 // Store dont-center-splitter flag 'cause we need to temporarily set it
3943 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3944 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3946 bool res
= m_pState
->DoCollapse(pwc
);
3951 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3953 RecalculateVirtualSize();
3955 // Redraw etc. only if collapsed was visible.
3956 if (pwc
->IsVisible() &&
3958 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3960 // When item is collapsed so that scrollbar would move,
3961 // graphics mess is about (unless we redraw everything).
3966 // Clear dont-center-splitter flag if it wasn't set
3967 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3972 // -----------------------------------------------------------------------
3974 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3976 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3978 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3980 // Store dont-center-splitter flag 'cause we need to temporarily set it
3981 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3982 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3984 bool res
= m_pState
->DoExpand(pwc
);
3989 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3991 RecalculateVirtualSize();
3993 // Redraw etc. only if expanded was visible.
3994 if ( pwc
->IsVisible() && !m_frozen
&&
3995 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3999 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4002 DrawItems(pwc
, NULL
);
4007 // Clear dont-center-splitter flag if it wasn't set
4008 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4013 // -----------------------------------------------------------------------
4015 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4018 return m_pState
->DoHideProperty(p
, hide
, flags
);
4021 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
4024 if ( !ClearSelection() )
4028 m_pState
->DoHideProperty(p
, hide
, flags
);
4030 RecalculateVirtualSize();
4037 // -----------------------------------------------------------------------
4038 // wxPropertyGrid size related methods
4039 // -----------------------------------------------------------------------
4041 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4043 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4047 // If virtual height was changed, then recalculate editor control position(s)
4048 if ( m_pState
->m_vhCalcPending
)
4049 CorrectEditorWidgetPosY();
4051 m_pState
->EnsureVirtualHeight();
4054 int by1
= m_pState
->GetVirtualHeight();
4055 int by2
= m_pState
->GetActualVirtualHeight();
4058 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4059 wxASSERT_MSG( false,
4065 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4067 int x
= m_pState
->m_width
;
4068 int y
= m_pState
->m_virtualHeight
;
4071 GetClientSize(&width
,&height
);
4073 // Now adjust virtual size.
4074 SetVirtualSize(x
, y
);
4080 // Adjust scrollbars
4081 if ( HasVirtualWidth() )
4083 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4084 xPos
= GetScrollPos( wxHORIZONTAL
);
4087 if ( forceXPos
!= -1 )
4090 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4093 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4094 int yPos
= GetScrollPos( wxVERTICAL
);
4096 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4097 xAmount
, yAmount
, xPos
, yPos
, true );
4099 // Must re-get size now
4100 GetClientSize(&width
,&height
);
4102 if ( !HasVirtualWidth() )
4104 m_pState
->SetVirtualWidth(width
);
4111 m_canvas
->SetSize( x
, y
);
4113 m_pState
->CheckColumnWidths();
4116 CorrectEditorWidgetSizeX();
4118 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4121 // -----------------------------------------------------------------------
4123 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4125 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4129 GetClientSize(&width
,&height
);
4134 #if wxPG_DOUBLE_BUFFER
4135 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4137 int dblh
= (m_lineHeight
*2);
4138 if ( !m_doubleBuffer
)
4140 // Create double buffer bitmap to draw on, if none
4141 int w
= (width
>250)?width
:250;
4142 int h
= height
+ dblh
;
4144 m_doubleBuffer
= new wxBitmap( w
, h
);
4148 int w
= m_doubleBuffer
->GetWidth();
4149 int h
= m_doubleBuffer
->GetHeight();
4151 // Double buffer must be large enough
4152 if ( w
< width
|| h
< (height
+dblh
) )
4154 if ( w
< width
) w
= width
;
4155 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4156 delete m_doubleBuffer
;
4157 m_doubleBuffer
= new wxBitmap( w
, h
);
4164 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4165 m_ncWidth
= event
.GetSize().x
;
4169 if ( m_pState
->m_itemsAdded
)
4170 PrepareAfterItemsAdded();
4172 // Without this, virtual size (atleast under wxGTK) will be skewed
4173 RecalculateVirtualSize();
4179 // -----------------------------------------------------------------------
4181 void wxPropertyGrid::SetVirtualWidth( int width
)
4185 // Disable virtual width
4186 width
= GetClientSize().x
;
4187 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4191 // Enable virtual width
4192 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4194 m_pState
->SetVirtualWidth( width
);
4197 // -----------------------------------------------------------------------
4198 // wxPropertyGrid mouse event handling
4199 // -----------------------------------------------------------------------
4201 // selFlags uses same values DoSelectProperty's flags
4202 // Returns true if event was vetoed.
4203 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4205 // Send property grid event of specific type and with specific property
4206 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4207 evt
.SetPropertyGrid(this);
4208 evt
.SetEventObject(m_eventObject
);
4212 evt
.SetCanVeto(true);
4213 evt
.SetupValidationInfo();
4214 m_validationInfo
.m_pValue
= pValue
;
4216 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4218 evtHandler
->ProcessEvent(evt
);
4220 return evt
.WasVetoed();
4223 // -----------------------------------------------------------------------
4225 // Return false if should be skipped
4226 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4230 // Need to set focus?
4231 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4236 wxPropertyGridPageState
* state
= m_pState
;
4238 int splitterHitOffset
;
4239 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4241 wxPGProperty
* p
= DoGetItemAtY(y
);
4245 int depth
= (int)p
->GetDepth() - 1;
4247 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4249 if ( x
>= marginEnds
)
4253 if ( p
->IsCategory() )
4255 // This is category.
4256 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4258 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4260 // Expand, collapse, activate etc. if click on text or left of splitter.
4263 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4268 if ( !DoSelectProperty( p
) )
4271 // On double-click, expand/collapse.
4272 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4274 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4275 else DoExpand( p
, true );
4279 else if ( splitterHit
== -1 )
4282 unsigned int selFlag
= 0;
4283 if ( columnHit
== 1 )
4285 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4286 selFlag
= wxPG_SEL_FOCUS
;
4288 if ( !DoSelectProperty( p
, selFlag
) )
4291 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4293 if ( p
->GetChildCount() && !p
->IsCategory() )
4294 // On double-click, expand/collapse.
4295 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4297 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4298 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4299 else DoExpand( p
, true );
4306 // click on splitter
4307 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4309 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4311 // Double-clicking the splitter causes auto-centering
4312 CenterSplitter( true );
4314 else if ( m_dragStatus
== 0 )
4317 // Begin draggin the splitter
4321 // Changes must be committed here or the
4322 // value won't be drawn correctly
4323 if ( !CommitChangesFromEditor() )
4326 m_wndEditor
->Show ( false );
4329 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4331 m_canvas
->CaptureMouse();
4332 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4336 m_draggedSplitter
= splitterHit
;
4337 m_dragOffset
= splitterHitOffset
;
4339 wxClientDC
dc(m_canvas
);
4341 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4342 // Fixes button disappearance bug
4344 m_wndEditor2
->Show ( false );
4347 m_startingSplitterX
= x
- splitterHitOffset
;
4355 if ( p
->GetChildCount() )
4357 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4359 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4361 int y2
= y
% m_lineHeight
;
4362 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4364 // On click on expander button, expand/collapse
4365 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4366 DoCollapse( p
, true );
4368 DoExpand( p
, true );
4377 // -----------------------------------------------------------------------
4379 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4380 wxMouseEvent
& WXUNUSED(event
) )
4384 // Select property here as well
4385 wxPGProperty
* p
= m_propHover
;
4386 if ( p
!= m_selected
)
4387 DoSelectProperty( p
);
4389 // Send right click event.
4390 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4397 // -----------------------------------------------------------------------
4399 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4400 wxMouseEvent
& WXUNUSED(event
) )
4404 // Select property here as well
4405 wxPGProperty
* p
= m_propHover
;
4407 if ( p
!= m_selected
)
4408 DoSelectProperty( p
);
4410 // Send double-click event.
4411 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4418 // -----------------------------------------------------------------------
4420 #if wxPG_SUPPORT_TOOLTIPS
4422 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4424 if ( tipString
.length() )
4426 m_canvas
->SetToolTip(tipString
);
4430 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4431 m_canvas
->SetToolTip( m_emptyString
);
4433 m_canvas
->SetToolTip( NULL
);
4438 #endif // #if wxPG_SUPPORT_TOOLTIPS
4440 // -----------------------------------------------------------------------
4442 // Return false if should be skipped
4443 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4445 // Safety check (needed because mouse capturing may
4446 // otherwise freeze the control)
4447 if ( m_dragStatus
> 0 && !event
.Dragging() )
4449 HandleMouseUp(x
,y
,event
);
4452 wxPropertyGridPageState
* state
= m_pState
;
4454 int splitterHitOffset
;
4455 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4456 int splitterX
= x
- splitterHitOffset
;
4458 if ( m_dragStatus
> 0 )
4460 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4461 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4464 int newSplitterX
= x
- m_dragOffset
;
4465 int splitterX
= x
- splitterHitOffset
;
4467 // Splitter redraw required?
4468 if ( newSplitterX
!= splitterX
)
4471 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4472 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4473 state
->m_fSplitterX
= (float) newSplitterX
;
4476 CorrectEditorWidgetSizeX();
4490 int ih
= m_lineHeight
;
4493 #if wxPG_SUPPORT_TOOLTIPS
4494 wxPGProperty
* prevHover
= m_propHover
;
4495 unsigned char prevSide
= m_mouseSide
;
4497 int curPropHoverY
= y
- (y
% ih
);
4499 // On which item it hovers
4500 if ( ( !m_propHover
)
4502 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4505 // Mouse moves on another property
4507 m_propHover
= DoGetItemAtY(y
);
4508 m_propHoverY
= curPropHoverY
;
4511 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4514 #if wxPG_SUPPORT_TOOLTIPS
4515 // Store which side we are on
4517 if ( columnHit
== 1 )
4519 else if ( columnHit
== 0 )
4523 // If tooltips are enabled, show label or value as a tip
4524 // in case it doesn't otherwise show in full length.
4526 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4528 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4530 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4532 if ( m_propHover
&& !m_propHover
->IsCategory() )
4535 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4537 // Show help string as a tooltip
4538 wxString tipString
= m_propHover
->GetHelpString();
4540 SetToolTip(tipString
);
4544 // Show cropped value string as a tooltip
4548 if ( m_mouseSide
== 1 )
4550 tipString
= m_propHover
->m_label
;
4551 space
= splitterX
-m_marginWidth
-3;
4553 else if ( m_mouseSide
== 2 )
4555 tipString
= m_propHover
->GetDisplayedString();
4557 space
= m_width
- splitterX
;
4558 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4559 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4565 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4568 SetToolTip( tipString
);
4575 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4576 m_canvas
->SetToolTip( m_emptyString
);
4578 m_canvas
->SetToolTip( NULL
);
4589 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4590 m_canvas
->SetToolTip( m_emptyString
);
4592 m_canvas
->SetToolTip( NULL
);
4600 if ( splitterHit
== -1 ||
4602 HasFlag(wxPG_STATIC_SPLITTER
) )
4604 // hovering on something else
4605 if ( m_curcursor
!= wxCURSOR_ARROW
)
4606 CustomSetCursor( wxCURSOR_ARROW
);
4610 // Do not allow splitter cursor on caption items.
4611 // (also not if we were dragging and its started
4612 // outside the splitter region)
4615 !m_propHover
->IsCategory() &&
4619 // hovering on splitter
4621 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4622 // reliably detected.
4623 //if ( m_curcursor != wxCURSOR_SIZEWE )
4624 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4630 // hovering on something else
4631 if ( m_curcursor
!= wxCURSOR_ARROW
)
4632 CustomSetCursor( wxCURSOR_ARROW
);
4639 // -----------------------------------------------------------------------
4641 // Also handles Leaving event
4642 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4643 wxMouseEvent
&WXUNUSED(event
) )
4645 wxPropertyGridPageState
* state
= m_pState
;
4649 int splitterHitOffset
;
4650 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4652 // No event type check - basicly calling this method should
4653 // just stop dragging.
4654 // Left up after dragged?
4655 if ( m_dragStatus
>= 1 )
4658 // End Splitter Dragging
4660 // DO NOT ENABLE FOLLOWING LINE!
4661 // (it is only here as a reminder to not to do it)
4664 // Disable splitter auto-centering
4665 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4667 // This is necessary to return cursor
4668 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4670 m_canvas
->ReleaseMouse();
4671 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4674 // Set back the default cursor, if necessary
4675 if ( splitterHit
== -1 ||
4678 CustomSetCursor( wxCURSOR_ARROW
);
4683 // Control background needs to be cleared
4684 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4685 DrawItem( m_selected
);
4689 m_wndEditor
->Show ( true );
4692 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4693 // Fixes button disappearance bug
4695 m_wndEditor2
->Show ( true );
4698 // This clears the focus.
4699 m_editorFocused
= 0;
4705 // -----------------------------------------------------------------------
4707 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4709 int splitterX
= GetSplitterPosition();
4712 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4716 wxWindow
* wnd
= m_wndEditor
;
4718 // Hide popup on clicks
4719 if ( event
.GetEventType() != wxEVT_MOTION
)
4720 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4722 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4728 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4730 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4731 ux
>= (r
.x
+r
.width
) ||
4733 event
.m_y
>= (r
.y
+r
.height
)
4743 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4748 // -----------------------------------------------------------------------
4750 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4753 if ( OnMouseCommon( event
, &x
, &y
) )
4755 HandleMouseClick(x
,y
,event
);
4760 // -----------------------------------------------------------------------
4762 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4765 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4766 HandleMouseRightClick(x
,y
,event
);
4770 // -----------------------------------------------------------------------
4772 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4774 // Always run standard mouse-down handler as well
4775 OnMouseClick(event
);
4778 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4779 HandleMouseDoubleClick(x
,y
,event
);
4783 // -----------------------------------------------------------------------
4785 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4788 if ( OnMouseCommon( event
, &x
, &y
) )
4790 HandleMouseMove(x
,y
,event
);
4795 // -----------------------------------------------------------------------
4797 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4799 // Called when mouse moves in the empty space below the properties.
4800 CustomSetCursor( wxCURSOR_ARROW
);
4803 // -----------------------------------------------------------------------
4805 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4808 if ( OnMouseCommon( event
, &x
, &y
) )
4810 HandleMouseUp(x
,y
,event
);
4815 // -----------------------------------------------------------------------
4817 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4819 // This may get called from child control as well, so event's
4820 // mouse position cannot be relied on.
4822 if ( event
.Entering() )
4824 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4826 // TODO: Fix this (detect parent and only do
4827 // cursor trick if it is a manager).
4828 wxASSERT( GetParent() );
4829 GetParent()->SetCursor(wxNullCursor
);
4831 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4834 GetParent()->SetCursor(wxNullCursor
);
4836 else if ( event
.Leaving() )
4838 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4839 m_canvas
->SetCursor( wxNullCursor
);
4841 // Get real cursor position
4842 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4844 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4847 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4849 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4853 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4861 // -----------------------------------------------------------------------
4863 // Common code used by various OnMouseXXXChild methods.
4864 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4866 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4867 wxASSERT( topCtrlWnd
);
4869 event
.GetPosition(&x
,&y
);
4871 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4873 int splitterX
= GetSplitterPosition();
4875 wxRect r
= topCtrlWnd
->GetRect();
4876 if ( !m_dragStatus
&&
4877 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4878 y
>= 0 && y
< r
.height \
4881 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4886 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4893 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4896 if ( OnMouseChildCommon(event
,&x
,&y
) )
4898 bool res
= HandleMouseClick(x
,y
,event
);
4899 if ( !res
) event
.Skip();
4903 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4906 wxASSERT( m_wndEditor
);
4907 // These coords may not be exact (about +-2),
4908 // but that should not matter (right click is about item, not position).
4909 wxPoint pt
= m_wndEditor
->GetPosition();
4910 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4911 wxASSERT( m_selected
);
4912 m_propHover
= m_selected
;
4913 bool res
= HandleMouseRightClick(x
,y
,event
);
4914 if ( !res
) event
.Skip();
4917 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4920 if ( OnMouseChildCommon(event
,&x
,&y
) )
4922 bool res
= HandleMouseMove(x
,y
,event
);
4923 if ( !res
) event
.Skip();
4927 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4930 if ( OnMouseChildCommon(event
,&x
,&y
) )
4932 bool res
= HandleMouseUp(x
,y
,event
);
4933 if ( !res
) event
.Skip();
4937 // -----------------------------------------------------------------------
4938 // wxPropertyGrid keyboard event handling
4939 // -----------------------------------------------------------------------
4941 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4943 wxNavigationKeyEvent evt
;
4944 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4945 (dir
?wxNavigationKeyEvent::IsForward
:
4946 wxNavigationKeyEvent::IsBackward
));
4947 evt
.SetEventObject(this);
4948 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4952 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4954 // Translates wxKeyEvent to wxPG_ACTION_XXX
4956 int keycode
= event
.GetKeyCode();
4957 int modifiers
= event
.GetModifiers();
4959 wxASSERT( !(modifiers
&~(0xFFFF)) );
4961 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4963 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4965 if ( it
== m_actionTriggers
.end() )
4970 int second
= (it
->second
>>16) & 0xFFFF;
4974 return (it
->second
& 0xFFFF);
4977 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4979 wxASSERT( !(modifiers
&~(0xFFFF)) );
4981 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4983 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4985 if ( it
!= m_actionTriggers
.end() )
4987 // This key combination is already used
4989 // Can add secondary?
4990 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4991 wxT("You can only add up to two separate actions per key combination.") );
4993 action
= it
->second
| (action
<<16);
4996 m_actionTriggers
[hashMapKey
] = action
;
4999 void wxPropertyGrid::ClearActionTriggers( int action
)
5001 wxPGHashMapI2I::iterator it
;
5003 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
5005 if ( it
->second
== action
)
5007 m_actionTriggers
.erase(it
);
5012 static void CopyTextToClipboard( const wxString
& text
)
5014 if ( wxTheClipboard
->Open() )
5016 // This data objects are held by the clipboard,
5017 // so do not delete them in the app.
5018 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
5019 wxTheClipboard
->Close();
5023 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5026 // Handles key event when editor control is not focused.
5029 wxASSERT( !m_frozen
);
5033 // Travelsal between items, collapsing/expanding, etc.
5034 int keycode
= event
.GetKeyCode();
5036 if ( keycode
== WXK_TAB
)
5038 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5042 // Ignore Alt and Control when they are down alone
5043 if ( keycode
== WXK_ALT
||
5044 keycode
== WXK_CONTROL
)
5051 int action
= KeyEventToActions(event
, &secondAction
);
5057 if ( ButtonTriggerKeyTest(event
) )
5060 wxPGProperty
* p
= m_selected
;
5062 if ( action
== wxPG_ACTION_COPY
)
5064 CopyTextToClipboard(p
->GetDisplayedString());
5068 // Travel and expand/collapse
5071 if ( p
->GetChildCount() &&
5072 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5075 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5077 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5080 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5082 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5089 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5093 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5104 if ( selectDir
>= -1 )
5106 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5108 DoSelectProperty(p
);
5114 // If nothing was selected, select the first item now
5115 // (or navigate out of tab).
5116 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5118 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5119 if ( p
) DoSelectProperty(p
);
5124 // -----------------------------------------------------------------------
5126 // Potentially handles a keyboard event for editor controls.
5127 // Returns false if event should *not* be skipped (on true it can
5128 // be optionally skipped).
5129 // Basicly, false means that SelectProperty was called (or was about
5130 // to be called, if canDestroy was false).
5131 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5135 if ( !m_selected
|| !m_wndEditor
)
5140 int action
= KeyEventToAction(event
);
5143 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5146 // Esc cancels any changes
5147 if ( IsEditorsValueModified() )
5149 EditorsValueWasNotModified();
5151 // Update the control as well
5152 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5154 m_selected
->GetDisplayedString() );
5157 OnValidationFailureReset(m_selected
);
5163 else if ( action
== wxPG_ACTION_COPY
)
5165 // NB: There is some problem with getting native cut-copy-paste keys to go through
5166 // for embedded editor wxTextCtrl. This is why we emulate.
5168 wxTextCtrl
* tc
= GetEditorTextCtrl();
5171 wxString sel
= tc
->GetStringSelection();
5173 CopyTextToClipboard(sel
);
5177 CopyTextToClipboard(m_selected
->GetDisplayedString());
5180 else if ( action
== wxPG_ACTION_CUT
)
5182 wxTextCtrl
* tc
= GetEditorTextCtrl();
5186 tc
->GetSelection(&from
, &to
);
5189 CopyTextToClipboard(tc
->GetStringSelection());
5190 tc
->Remove(from
, to
);
5194 else if ( action
== wxPG_ACTION_PASTE
)
5196 wxTextCtrl
* tc
= GetEditorTextCtrl();
5199 if (wxTheClipboard
->Open())
5201 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5203 wxTextDataObject data
;
5204 wxTheClipboard
->GetData( data
);
5206 tc
->GetSelection(&from
, &to
);
5209 tc
->Remove(from
, to
);
5210 tc
->WriteText(data
.GetText());
5214 tc
->WriteText(data
.GetText());
5217 wxTheClipboard
->Close();
5225 // -----------------------------------------------------------------------
5227 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5231 // Events to editor controls should get relayed here.
5233 wxWindow
* focused
= wxWindow::FindFocus();
5235 wxWindow
* primaryCtrl
= GetEditorControl();
5238 (focused
==primaryCtrl
5239 || m_editorFocused
) )
5241 // Child key must be processed here, since it can
5242 // destroy the control which is referred by its own
5244 HandleChildKey( event
);
5247 HandleKeyEvent( event
);
5250 // -----------------------------------------------------------------------
5252 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5254 m_keyComboConsumed
= 0;
5259 // -----------------------------------------------------------------------
5261 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5263 // Ignore events that occur very close to focus set
5264 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5266 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5271 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5273 int dir
= event
.GetDirection()?1:-1;
5277 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5279 wxWindow
* focused
= wxWindow::FindFocus();
5281 wxWindow
* wndToCheck
= GetEditorControl();
5283 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5284 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5286 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5287 if ( comboTextCtrl
)
5288 wndToCheck
= comboTextCtrl
;
5292 // Because of problems navigating from wxButton, do not go to it.
5295 // No primary, use secondary
5296 wndToCheck = m_wndEditor2;
5298 // If it has editor button, focus to it after the primary editor.
5299 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5300 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5301 // have somewhat debugged in window.cpp itself).
5302 else if ( focused == wndToCheck &&
5304 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5306 wndToCheck = m_wndEditor2;
5307 wxLogDebug(wxT("Exp1"));
5311 if ( focused
!= wndToCheck
&&
5314 wndToCheck
->SetFocus();
5316 // Select all text in wxTextCtrl etc.
5317 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5318 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5320 m_editorFocused
= 1;
5327 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5331 // This allows preventing NavigateOut to occur
5332 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5341 // -----------------------------------------------------------------------
5343 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5345 int keycode
= event
.GetKeyCode();
5347 // Does the keycode trigger button?
5348 if ( keycode
== m_pushButKeyCode
&&
5350 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5351 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5353 m_keyComboConsumed
= 1;
5355 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5356 GetEventHandler()->AddPendingEvent(evt
);
5363 // -----------------------------------------------------------------------
5365 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5367 int keycode
= event
.GetKeyCode();
5369 // Ignore Alt and Control when they are down alone
5370 if ( keycode
== WXK_ALT
||
5371 keycode
== WXK_CONTROL
)
5377 if ( ButtonTriggerKeyTest(event
) )
5380 if ( HandleChildKey(event
) == true )
5383 GetEventHandler()->AddPendingEvent(event
);
5386 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5388 m_keyComboConsumed
= 0;
5390 GetEventHandler()->AddPendingEvent(event
);
5395 // -----------------------------------------------------------------------
5396 // wxPropertyGrid miscellaneous event handling
5397 // -----------------------------------------------------------------------
5399 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5402 // Check if the focus is in this control or one of its children
5403 wxWindow
* newFocused
= wxWindow::FindFocus();
5405 if ( newFocused
!= m_curFocused
)
5406 HandleFocusChange( newFocused
);
5409 // Called by focus event handlers. newFocused is the window that becomes focused.
5410 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5412 unsigned int oldFlags
= m_iFlags
;
5414 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5416 wxWindow
* parent
= newFocused
;
5418 // This must be one of nextFocus' parents.
5421 // Use m_eventObject, which is either wxPropertyGrid or
5422 // wxPropertyGridManager, as appropriate.
5423 if ( parent
== m_eventObject
)
5425 m_iFlags
|= wxPG_FL_FOCUSED
;
5428 parent
= parent
->GetParent();
5431 m_curFocused
= newFocused
;
5433 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5434 (oldFlags
& wxPG_FL_FOCUSED
) )
5436 // On each focus kill, mark the next nav key event
5437 // to be ignored (can't do on set focus since the
5438 // event would occur before it).
5439 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5441 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5443 // Need to store changed value
5444 CommitChangesFromEditor();
5450 // Preliminary code for tab-order respecting
5451 // tab-traversal (but should be moved to
5454 wxWindow* prevFocus = event.GetWindow();
5455 wxWindow* useThis = this;
5456 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5457 useThis = GetParent();
5460 prevFocus->GetParent() == useThis->GetParent() )
5462 wxList& children = useThis->GetParent()->GetChildren();
5464 wxNode* node = children.Find(prevFocus);
5466 if ( node->GetNext() &&
5467 useThis == node->GetNext()->GetData() )
5468 DoSelectProperty(GetFirst());
5469 else if ( node->GetPrevious () &&
5470 useThis == node->GetPrevious()->GetData() )
5471 DoSelectProperty(GetLastProperty());
5476 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5480 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5481 DrawItem( m_selected
);
5485 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5487 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5488 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5489 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5490 //else if ( event.GetWindow() )
5492 HandleFocusChange(event
.GetWindow());
5497 // -----------------------------------------------------------------------
5499 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5501 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5504 // event.Skip() being commented out is aworkaround for bug reported
5505 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5509 // -----------------------------------------------------------------------
5511 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5513 m_iFlags
|= wxPG_FL_SCROLLED
;
5518 // -----------------------------------------------------------------------
5520 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5522 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5524 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5528 // -----------------------------------------------------------------------
5529 // Property editor related functions
5530 // -----------------------------------------------------------------------
5532 // noDefCheck = true prevents infinite recursion.
5533 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorclass
,
5534 const wxString
& name
,
5537 wxASSERT( editorclass
);
5539 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5540 RegisterDefaultEditors();
5542 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorclass
;
5547 // Registers all default editor classes
5548 void wxPropertyGrid::RegisterDefaultEditors()
5550 wxPGRegisterDefaultEditorClass( TextCtrl
);
5551 wxPGRegisterDefaultEditorClass( Choice
);
5552 wxPGRegisterDefaultEditorClass( ComboBox
);
5553 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5554 #if wxPG_INCLUDE_CHECKBOX
5555 wxPGRegisterDefaultEditorClass( CheckBox
);
5557 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5559 // Register SpinCtrl etc. editors before use
5560 RegisterAdditionalEditors();
5563 // -----------------------------------------------------------------------
5564 // wxPGStringTokenizer
5565 // Needed to handle C-style string lists (e.g. "str1" "str2")
5566 // -----------------------------------------------------------------------
5568 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5569 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5573 wxPGStringTokenizer::~wxPGStringTokenizer()
5577 bool wxPGStringTokenizer::HasMoreTokens()
5579 const wxString
& str
= *m_str
;
5581 wxString::const_iterator i
= m_curPos
;
5583 wxUniChar delim
= m_delimeter
;
5585 wxUniChar prev_a
= wxT('\0');
5587 bool inToken
= false;
5589 while ( i
!= str
.end() )
5598 m_readyToken
.clear();
5603 if ( prev_a
!= wxT('\\') )
5607 if ( a
!= wxT('\\') )
5627 m_curPos
= str
.end();
5635 wxString
wxPGStringTokenizer::GetNextToken()
5637 return m_readyToken
;
5640 // -----------------------------------------------------------------------
5642 // -----------------------------------------------------------------------
5644 wxPGChoiceEntry::wxPGChoiceEntry()
5645 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5649 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5650 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5651 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5655 // -----------------------------------------------------------------------
5657 // -----------------------------------------------------------------------
5659 wxPGChoicesData::wxPGChoicesData()
5664 wxPGChoicesData::~wxPGChoicesData()
5669 void wxPGChoicesData::Clear()
5673 for ( i
=0; i
<m_items
.size(); i
++ )
5685 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5687 wxASSERT( m_items
.size() == 0 );
5691 for ( i
=0; i
<data
->GetCount(); i
++ )
5692 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5695 // -----------------------------------------------------------------------
5697 // -----------------------------------------------------------------------
5699 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5703 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5704 m_data
->Insert( -1, p
);
5708 // -----------------------------------------------------------------------
5710 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5714 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5715 p
->SetBitmap(bitmap
);
5716 m_data
->Insert( -1, p
);
5720 // -----------------------------------------------------------------------
5722 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5726 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5727 m_data
->Insert(index
, p
);
5731 // -----------------------------------------------------------------------
5733 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5737 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5738 m_data
->Insert( index
, p
);
5742 // -----------------------------------------------------------------------
5744 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5750 while ( index
< GetCount() )
5752 int cmpRes
= GetLabel(index
).Cmp(label
);
5758 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5759 m_data
->Insert( index
, p
);
5763 // -----------------------------------------------------------------------
5765 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5769 unsigned int itemcount
= 0;
5770 const wxChar
** p
= &labels
[0];
5771 while ( *p
) { p
++; itemcount
++; }
5774 for ( i
= 0; i
< itemcount
; i
++ )
5776 int value
= wxPG_INVALID_VALUE
;
5779 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5783 // -----------------------------------------------------------------------
5785 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5790 unsigned int itemcount
= arr
.size();
5792 for ( i
= 0; i
< itemcount
; i
++ )
5794 int value
= wxPG_INVALID_VALUE
;
5797 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5801 // -----------------------------------------------------------------------
5803 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5808 unsigned int itemcount
= arr
.size();
5810 for ( i
= 0; i
< itemcount
; i
++ )
5812 int value
= wxPG_INVALID_VALUE
;
5813 if ( &arrint
&& arrint
.size() )
5815 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5819 // -----------------------------------------------------------------------
5821 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5823 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5825 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5826 delete m_data
->Item(i
);
5827 m_data
->m_items
.RemoveAt(nIndex
, count
);
5830 // -----------------------------------------------------------------------
5832 int wxPGChoices::Index( const wxString
& str
) const
5837 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5839 if ( m_data
->Item(i
)->GetText() == str
)
5846 // -----------------------------------------------------------------------
5848 int wxPGChoices::Index( int val
) const
5853 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5855 if ( m_data
->Item(i
)->GetValue() == val
)
5862 // -----------------------------------------------------------------------
5864 wxArrayString
wxPGChoices::GetLabels() const
5869 if ( this && IsOk() )
5870 for ( i
=0; i
<GetCount(); i
++ )
5871 arr
.push_back(GetLabel(i
));
5876 // -----------------------------------------------------------------------
5878 bool wxPGChoices::HasValues() const
5883 // -----------------------------------------------------------------------
5885 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5892 for ( i
=0; i
< strings
.size(); i
++ )
5894 int index
= Index(strings
[i
]);
5896 arr
.Add(GetValue(index
));
5898 arr
.Add(wxPG_INVALID_VALUE
);
5905 // -----------------------------------------------------------------------
5907 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5908 wxArrayString
* unmatched
) const
5915 for ( i
=0; i
< strings
.size(); i
++ )
5917 const wxString
& str
= strings
[i
];
5918 int index
= Index(str
);
5921 else if ( unmatched
)
5922 unmatched
->Add(str
);
5929 // -----------------------------------------------------------------------
5931 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5935 if ( data
!= wxPGChoicesEmptyData
)
5942 // -----------------------------------------------------------------------
5944 void wxPGChoices::Init()
5946 m_data
= wxPGChoicesEmptyData
;
5949 // -----------------------------------------------------------------------
5951 void wxPGChoices::Free()
5953 if ( m_data
!= wxPGChoicesEmptyData
)
5956 m_data
= wxPGChoicesEmptyData
;
5960 // -----------------------------------------------------------------------
5961 // wxPropertyGridEvent
5962 // -----------------------------------------------------------------------
5964 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5967 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5968 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5969 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5970 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5971 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5972 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5973 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5974 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5975 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5978 // -----------------------------------------------------------------------
5980 void wxPropertyGridEvent::Init()
5982 m_validationInfo
= NULL
;
5984 m_wasVetoed
= false;
5987 // -----------------------------------------------------------------------
5989 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5990 : wxCommandEvent(commandType
,id
)
5996 // -----------------------------------------------------------------------
5998 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5999 : wxCommandEvent(event
)
6001 m_eventType
= event
.GetEventType();
6002 m_eventObject
= event
.m_eventObject
;
6004 m_property
= event
.m_property
;
6005 m_validationInfo
= event
.m_validationInfo
;
6006 m_canVeto
= event
.m_canVeto
;
6007 m_wasVetoed
= event
.m_wasVetoed
;
6010 // -----------------------------------------------------------------------
6012 wxPropertyGridEvent::~wxPropertyGridEvent()
6016 // -----------------------------------------------------------------------
6018 wxEvent
* wxPropertyGridEvent::Clone() const
6020 return new wxPropertyGridEvent( *this );
6023 // -----------------------------------------------------------------------
6024 // wxPropertyGridPopulator
6025 // -----------------------------------------------------------------------
6027 wxPropertyGridPopulator::wxPropertyGridPopulator()
6031 wxPGGlobalVars
->m_offline
++;
6034 // -----------------------------------------------------------------------
6036 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6039 m_propHierarchy
.clear();
6042 // -----------------------------------------------------------------------
6044 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6050 // -----------------------------------------------------------------------
6052 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6055 // Free unused sets of choices
6056 wxPGHashMapS2P::iterator it
;
6058 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6060 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6067 m_pg
->GetPanel()->Refresh();
6069 wxPGGlobalVars
->m_offline
--;
6072 // -----------------------------------------------------------------------
6074 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6075 const wxString
& propLabel
,
6076 const wxString
& propName
,
6077 const wxString
* propValue
,
6078 wxPGChoices
* pChoices
)
6080 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6081 wxPGProperty
* parent
= GetCurParent();
6083 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6085 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6089 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6091 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6095 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6097 property
->SetLabel(propLabel
);
6098 property
->DoSetName(propName
);
6100 if ( pChoices
&& pChoices
->IsOk() )
6101 property
->SetChoices(*pChoices
);
6103 m_state
->DoInsert(parent
, -1, property
);
6106 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6111 // -----------------------------------------------------------------------
6113 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6115 m_propHierarchy
.push_back(property
);
6116 DoScanForChildren();
6117 m_propHierarchy
.pop_back();
6120 // -----------------------------------------------------------------------
6122 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6123 const wxString
& idString
)
6125 wxPGChoices choices
;
6128 if ( choicesString
[0] == wxT('@') )
6130 wxString ids
= choicesString
.substr(1);
6131 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6132 if ( it
== m_dictIdChoices
.end() )
6133 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6135 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6140 if ( idString
.length() )
6142 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6143 if ( it
!= m_dictIdChoices
.end() )
6145 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6152 // Parse choices string
6153 wxString::const_iterator it
= choicesString
.begin();
6157 bool labelValid
= false;
6159 for ( ; it
!= choicesString
.end(); it
++ )
6165 if ( c
== wxT('"') )
6170 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6171 choices
.Add(label
, l
);
6174 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6179 else if ( c
== wxT('=') )
6186 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6193 if ( c
== wxT('"') )
6206 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6207 choices
.Add(label
, l
);
6210 if ( !choices
.IsOk() )
6212 choices
.EnsureData();
6216 if ( idString
.length() )
6217 m_dictIdChoices
[idString
] = choices
.GetData();
6224 // -----------------------------------------------------------------------
6226 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6228 if ( s
.Last() == wxT('%') )
6230 wxString s2
= s
.substr(0,s
.length()-1);
6232 if ( s2
.ToLong(&val
, 10) )
6234 *pval
= (val
*max
)/100;
6240 return s
.ToLong(pval
, 10);
6243 // -----------------------------------------------------------------------
6245 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6246 const wxString
& type
,
6247 const wxString
& value
)
6249 int l
= m_propHierarchy
.size();
6253 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6254 wxString valuel
= value
.Lower();
6257 if ( type
.length() == 0 )
6262 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6264 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6266 else if ( value
.ToLong(&v
, 0) )
6273 if ( type
== wxT("string") )
6277 else if ( type
== wxT("int") )
6280 value
.ToLong(&v
, 0);
6283 else if ( type
== wxT("bool") )
6285 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6292 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6297 p
->SetAttribute( name
, variant
);
6302 // -----------------------------------------------------------------------
6304 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6306 wxLogError(_("Error in resource: %s"),msg
.c_str());
6309 // -----------------------------------------------------------------------
6311 #endif // wxUSE_PROPGRID