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_TEXT_ENTER(wxPG_SUBID1
,wxPropertyGrid::OnCustomEditorEvent
)
503 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
507 // -----------------------------------------------------------------------
509 wxPropertyGrid::wxPropertyGrid()
515 // -----------------------------------------------------------------------
517 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
526 Create(parent
,id
,pos
,size
,style
,name
);
529 // -----------------------------------------------------------------------
531 bool wxPropertyGrid::Create( wxWindow
*parent
,
539 if ( !(style
&wxBORDER_MASK
) )
540 style
|= wxSIMPLE_BORDER
;
545 // This prevents crash under Win2K, but still
546 // enables keyboard navigation
547 if ( style
& wxTAB_TRAVERSAL
)
549 style
&= ~(wxTAB_TRAVERSAL
);
550 style
|= wxWANTS_CHARS
;
553 if ( style
& wxTAB_TRAVERSAL
)
554 style
|= wxWANTS_CHARS
;
557 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
564 // -----------------------------------------------------------------------
567 // Initialize values to defaults
569 void wxPropertyGrid::Init1()
571 #if !wxPG_USE_WXMODULE
572 if ( !wxPGGlobalVars
)
573 wxPGGlobalVars
= new wxPGGlobalVarsClass();
576 // Register editor classes, if necessary.
577 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
578 RegisterDefaultEditors();
581 m_pState
= (wxPropertyGridPageState
*) NULL
;
582 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
583 m_selected
= (wxPGProperty
*) NULL
;
585 m_propHover
= (wxPGProperty
*) NULL
;
586 m_eventObject
= this;
587 m_curFocused
= (wxWindow
*) NULL
;
589 m_inDoPropertyChanged
= 0;
590 m_inCommitChangesFromEditor
= 0;
591 m_inDoSelectProperty
= 0;
592 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
598 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
599 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
600 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
601 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
602 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
603 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
604 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
605 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
606 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
607 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
608 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
609 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
610 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
612 m_coloursCustomized
= 0;
617 #if wxPG_DOUBLE_BUFFER
618 m_doubleBuffer
= (wxBitmap
*) NULL
;
621 m_windowsToDelete
= NULL
;
623 #ifndef wxPG_ICON_WIDTH
629 m_iconWidth
= wxPG_ICON_WIDTH
;
634 m_gutterWidth
= wxPG_GUTTER_MIN
;
635 m_subgroup_extramargin
= 10;
639 m_width
= m_height
= 0;
641 SetButtonShortcut(0);
643 m_keyComboConsumed
= 0;
645 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
648 m_chgInfo_changedProperty
= NULL
;
651 // -----------------------------------------------------------------------
654 // Initialize after parent etc. set
656 void wxPropertyGrid::Init2()
658 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
661 // Smaller controls on Mac
662 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
665 // Now create state, if one didn't exist already
666 // (wxPropertyGridManager might have created it for us).
669 m_pState
= CreateState();
670 m_pState
->m_pPropGrid
= this;
671 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
674 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
675 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
677 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
679 m_pState
->InitNonCatMode();
681 m_pState
->m_properties
= m_pState
->m_abcArray
;
684 GetClientSize(&m_width
,&m_height
);
686 #ifndef wxPG_ICON_WIDTH
687 // create two bitmap nodes for drawing
688 m_expandbmp
= new wxBitmap(expand_xpm
);
689 m_collbmp
= new wxBitmap(collapse_xpm
);
691 // calculate average font height for bitmap centering
693 m_iconWidth
= m_expandbmp
->GetWidth();
694 m_iconHeight
= m_expandbmp
->GetHeight();
697 m_curcursor
= wxCURSOR_ARROW
;
698 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
700 // adjust bitmap icon y position so they are centered
701 m_vspacing
= wxPG_DEFAULT_VSPACING
;
705 wxFont useFont
= wxScrolledWindow::GetFont();
706 wxScrolledWindow::SetOwnFont( useFont
);
709 // This should be otherwise called by SetOwnFont
710 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
712 // Add base brush item
713 m_arrBgBrushes
.Add((void*)new wxPGBrush());
715 // Add base colour items
716 m_arrFgCols
.Add((void*)new wxPGColour());
717 m_arrFgCols
.Add((void*)new wxPGColour());
721 // This helps with flicker
722 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
725 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
726 m_tlp
= ::wxGetTopLevelParent(this);
727 m_tlwHandler
= handler
;
728 m_tlp
->PushEventHandler(handler
);
730 // set virtual size to this window size
731 wxSize wndsize
= GetSize();
732 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
734 m_timeCreated
= ::wxGetLocalTimeMillis();
736 m_canvas
= new wxPGCanvas();
737 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
738 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
739 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
741 m_iFlags
|= wxPG_FL_INITIALIZED
;
743 m_ncWidth
= wndsize
.GetWidth();
745 // Need to call OnResize handler or size given in constructor/Create
747 wxSizeEvent
sizeEvent(wndsize
,0);
751 // -----------------------------------------------------------------------
753 wxPropertyGrid::~wxPropertyGrid()
757 DoSelectProperty(NULL
);
759 // This should do prevent things from going too badly wrong
760 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
762 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
763 m_canvas
->ReleaseMouse();
765 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
766 m_tlp
->RemoveEventHandler(handler
);
770 if ( IsEditorsValueModified() )
771 ::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).)"),
772 wxS("wxPropertyGrid Debug Warning") );
775 #if wxPG_DOUBLE_BUFFER
776 if ( m_doubleBuffer
)
777 delete m_doubleBuffer
;
780 delete m_windowsToDelete
;
782 //m_selected = (wxPGProperty*) NULL;
784 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
787 delete m_cursorSizeWE
;
789 #ifndef wxPG_ICON_WIDTH
794 // Delete cached text colours.
795 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
797 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
800 // Delete cached brushes.
801 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
803 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
806 // Delete common value records
807 for ( i
=0; i
<m_commonValues
.size(); i
++ )
809 delete GetCommonValue(i
);
813 // -----------------------------------------------------------------------
815 bool wxPropertyGrid::Destroy()
817 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
818 m_canvas
->ReleaseMouse();
820 return wxScrolledWindow::Destroy();
823 // -----------------------------------------------------------------------
825 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
827 return new wxPropertyGridPageState();
830 // -----------------------------------------------------------------------
831 // wxPropertyGrid overridden wxWindow methods
832 // -----------------------------------------------------------------------
834 void wxPropertyGrid::SetWindowStyleFlag( long style
)
836 long old_style
= m_windowStyle
;
838 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
840 wxASSERT( m_pState
);
842 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
845 EnableCategories( true );
847 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
849 // Disable categories
850 EnableCategories( false );
852 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
858 PrepareAfterItemsAdded();
860 m_pState
->m_itemsAdded
= 1;
862 #if wxPG_SUPPORT_TOOLTIPS
863 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
869 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
870 SetToolTip ( tooltip );
871 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
874 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
879 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
884 wxScrolledWindow::SetWindowStyleFlag ( style
);
886 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
888 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
890 CalculateFontAndBitmapStuff( m_vspacing
);
896 // -----------------------------------------------------------------------
898 void wxPropertyGrid::Freeze()
902 wxScrolledWindow::Freeze();
907 // -----------------------------------------------------------------------
909 void wxPropertyGrid::Thaw()
915 wxScrolledWindow::Thaw();
916 RecalculateVirtualSize();
917 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
921 // Force property re-selection
923 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
927 // -----------------------------------------------------------------------
929 void wxPropertyGrid::SetExtraStyle( long exStyle
)
931 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
933 #if defined(__WXMSW__)
936 // Don't use WS_EX_COMPOSITED just now.
939 if ( m_iFlags & wxPG_FL_IN_MANAGER )
940 hWnd = (HWND)GetParent()->GetHWND();
942 hWnd = (HWND)GetHWND();
944 ::SetWindowLong( hWnd, GWL_EXSTYLE,
945 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
948 //#elif defined(__WXGTK20__)
950 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
951 // truly was double-buffered.
952 if ( !this->IsDoubleBuffered() )
954 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
958 #if wxPG_DOUBLE_BUFFER
959 delete m_doubleBuffer
;
960 m_doubleBuffer
= NULL
;
965 wxScrolledWindow::SetExtraStyle( exStyle
);
967 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
968 m_pState
->InitNonCatMode();
970 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
971 m_windowStyle
|= wxPG_TOOLTIPS
;
974 wxPGGlobalVars
->m_extraStyle
= exStyle
;
977 // -----------------------------------------------------------------------
979 // returns the best acceptable minimal size
980 wxSize
wxPropertyGrid::DoGetBestSize() const
983 if ( m_lineHeight
> hei
)
985 wxSize sz
= wxSize( 60, hei
+40 );
991 // -----------------------------------------------------------------------
992 // wxPropertyGrid Font and Colour Methods
993 // -----------------------------------------------------------------------
995 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
999 m_captionFont
= wxScrolledWindow::GetFont();
1001 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1002 m_subgroup_extramargin
= x
+ (x
/2);
1005 #if wxPG_USE_RENDERER_NATIVE
1006 m_iconWidth
= wxPG_ICON_WIDTH
;
1007 #elif wxPG_ICON_WIDTH
1009 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1010 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1011 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1015 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1016 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1017 m_gutterWidth
= wxPG_GUTTER_MIN
;
1020 if ( vspacing
<= 1 ) vdiv
= 12;
1021 else if ( vspacing
>= 3 ) vdiv
= 3;
1023 m_spacingy
= m_fontHeight
/ vdiv
;
1024 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1025 m_spacingy
= wxPG_YSPACING_MIN
;
1028 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1029 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1031 m_captionFont
.SetWeight(wxBOLD
);
1032 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1034 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1037 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1038 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1041 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1043 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1044 RecalculateVirtualSize();
1046 InvalidateBestSize();
1049 // -----------------------------------------------------------------------
1051 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1057 // -----------------------------------------------------------------------
1059 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1060 int ga
= 1000, int ba
= 1000,
1061 bool forceDifferent
= false)
1068 // Recursion guard (allow 2 max)
1069 static int isinside
= 0;
1071 wxCHECK_MSG( isinside
< 3,
1073 wxT("wxPGAdjustColour should not be recursively called more than once") );
1078 int g
= src
.Green();
1081 if ( r2
>255 ) r2
= 255;
1082 else if ( r2
<0) r2
= 0;
1084 if ( g2
>255 ) g2
= 255;
1085 else if ( g2
<0) g2
= 0;
1087 if ( b2
>255 ) b2
= 255;
1088 else if ( b2
<0) b2
= 0;
1090 // Make sure they are somewhat different
1091 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1092 dst
= wxPGAdjustColour(src
,-(ra
*2));
1094 dst
= wxColour(r2
,g2
,b2
);
1096 // Recursion guard (allow 2 max)
1103 static int wxPGGetColAvg( const wxColour
& col
)
1105 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1109 void wxPropertyGrid::RegainColours()
1111 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1113 if ( !(m_coloursCustomized
& 0x0002) )
1115 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1117 // Make sure colour is dark enough
1119 int colDec
= wxPGGetColAvg(col
) - 230;
1121 int colDec
= wxPGGetColAvg(col
) - 200;
1124 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1129 if ( !(m_coloursCustomized
& 0x0001) )
1130 m_colMargin
= m_colCapBack
;
1132 if ( !(m_coloursCustomized
& 0x0004) )
1139 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1140 m_colCapFore
= capForeCol
;
1142 // Set the cached colour as well.
1143 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1146 if ( !(m_coloursCustomized
& 0x0008) )
1148 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1149 m_colPropBack
= bgCol
;
1151 // Set the cached brush as well.
1152 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1155 if ( !(m_coloursCustomized
& 0x0010) )
1157 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1158 m_colPropFore
= fgCol
;
1160 // Set the cached colour as well.
1161 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1164 if ( !(m_coloursCustomized
& 0x0020) )
1165 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1167 if ( !(m_coloursCustomized
& 0x0040) )
1168 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1170 if ( !(m_coloursCustomized
& 0x0080) )
1171 m_colLine
= m_colCapBack
;
1173 if ( !(m_coloursCustomized
& 0x0100) )
1174 m_colDisPropFore
= m_colCapFore
;
1176 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1179 // -----------------------------------------------------------------------
1181 void wxPropertyGrid::ResetColours()
1183 m_coloursCustomized
= 0;
1190 // -----------------------------------------------------------------------
1192 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1194 // Must disable active editor.
1197 bool selRes
= ClearSelection();
1198 wxPG_CHECK_MSG_DBG( selRes
,
1200 wxT("failed to deselect a property (editor probably had invalid value)") );
1203 // TODO: Following code is disabled with wxMac because
1204 // it is reported to fail. I (JMS) cannot debug it
1205 // personally right now.
1206 #if !defined(__WXMAC__)
1207 bool res
= wxScrolledWindow::SetFont( font
);
1210 CalculateFontAndBitmapStuff( m_vspacing
);
1213 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1221 // TODO: Remove after SetFont crash fixed.
1222 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1224 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."));
1230 // -----------------------------------------------------------------------
1232 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1235 m_coloursCustomized
|= 0x80;
1239 // -----------------------------------------------------------------------
1241 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1244 m_coloursCustomized
|= 0x01;
1248 // -----------------------------------------------------------------------
1250 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1252 m_colPropBack
= col
;
1253 m_coloursCustomized
|= 0x08;
1255 // Set the cached brush as well.
1256 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1261 // -----------------------------------------------------------------------
1263 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1265 m_colPropFore
= col
;
1266 m_coloursCustomized
|= 0x10;
1268 // Set the cached colour as well.
1269 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1274 // -----------------------------------------------------------------------
1276 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1278 m_colEmptySpace
= col
;
1283 // -----------------------------------------------------------------------
1285 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1287 m_colDisPropFore
= col
;
1288 m_coloursCustomized
|= 0x100;
1292 // -----------------------------------------------------------------------
1294 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1297 m_coloursCustomized
|= 0x20;
1301 // -----------------------------------------------------------------------
1303 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1306 m_coloursCustomized
|= 0x40;
1310 // -----------------------------------------------------------------------
1312 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1315 m_coloursCustomized
|= 0x02;
1319 // -----------------------------------------------------------------------
1321 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1324 m_coloursCustomized
|= 0x04;
1326 // Set the cached colour as well.
1327 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1332 // -----------------------------------------------------------------------
1334 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1336 unsigned char ind
= index
;
1338 p
->m_bgColIndex
= ind
;
1341 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1342 SetBackgroundColourIndex(p
->Item(i
),index
);
1345 // -----------------------------------------------------------------------
1347 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1349 wxPG_PROP_ARG_CALL_PROLOG()
1354 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1356 // As it is most likely that the previous colour is used, start comparison
1358 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1360 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1369 colInd
= m_arrBgBrushes
.size();
1370 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1371 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1375 SetBackgroundColourIndex(p
,colInd
);
1377 // If this was on a visible grid, then draw it.
1378 DrawItemAndChildren(p
);
1381 // -----------------------------------------------------------------------
1383 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1385 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1387 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1390 // -----------------------------------------------------------------------
1392 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1394 unsigned char ind
= index
;
1396 p
->m_fgColIndex
= ind
;
1398 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1401 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1402 SetTextColourIndex( p
->Item(i
), index
, flags
);
1406 // -----------------------------------------------------------------------
1408 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1413 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1415 // As it is most likely that the previous colour is used, start comparison
1417 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1419 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1428 colInd
= m_arrFgCols
.size();
1429 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1430 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1436 // -----------------------------------------------------------------------
1438 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1441 wxPG_PROP_ARG_CALL_PROLOG()
1443 if ( p
->IsCategory() )
1445 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1446 cat
->SetTextColIndex(CacheColour(colour
));
1452 flags
|= wxPG_RECURSE
;
1453 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1455 DrawItemAndChildren(p
);
1458 // -----------------------------------------------------------------------
1460 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1462 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1464 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1467 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1469 wxPG_PROP_ARG_CALL_PROLOG()
1471 SetBackgroundColourIndex( p
, 0 );
1472 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1474 if ( p
->IsCategory() )
1476 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1477 cat
->SetTextColIndex(1);
1481 // -----------------------------------------------------------------------
1482 // wxPropertyGrid property adding and removal
1483 // -----------------------------------------------------------------------
1485 void wxPropertyGrid::PrepareAfterItemsAdded()
1487 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1489 m_pState
->m_itemsAdded
= 0;
1491 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1494 RecalculateVirtualSize();
1497 // -----------------------------------------------------------------------
1498 // wxPropertyGrid property value setting and getting
1499 // -----------------------------------------------------------------------
1501 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1503 m_pState
->DoSetPropertyValueUnspecified(p
);
1504 DrawItemAndChildren(p
);
1506 wxPGProperty
* parent
= p
->GetParent();
1507 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1510 parent
= parent
->GetParent();
1514 // -----------------------------------------------------------------------
1515 // wxPropertyGrid property operations
1516 // -----------------------------------------------------------------------
1518 void wxPropertyGrid::DoSetPropertyName( wxPGProperty
* p
, const wxString
& newname
)
1520 wxCHECK_RET( p
, wxT("invalid property id") );
1522 if ( p
->GetBaseName().Len() ) m_pState
->m_dictName
.erase( p
->GetBaseName() );
1523 if ( newname
.Len() ) m_pState
->m_dictName
[newname
] = (void*) p
;
1525 p
->DoSetName(newname
);
1528 // -----------------------------------------------------------------------
1530 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1532 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1536 bool changed
= false;
1538 // Is it inside collapsed section?
1539 if ( !p
->IsVisible() )
1542 wxPGProperty
* parent
= p
->GetParent();
1543 wxPGProperty
* grandparent
= parent
->GetParent();
1545 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1546 Expand( grandparent
);
1554 GetViewStart(&vx
,&vy
);
1555 vy
*=wxPG_PIXELS_PER_UNIT
;
1561 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1562 m_iFlags
|= wxPG_FL_SCROLLED
;
1565 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1567 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1568 m_iFlags
|= wxPG_FL_SCROLLED
;
1578 // -----------------------------------------------------------------------
1579 // wxPropertyGrid helper methods called by properties
1580 // -----------------------------------------------------------------------
1582 // Control font changer helper.
1583 void wxPropertyGrid::SetCurControlBoldFont()
1585 wxASSERT( m_wndEditor
);
1586 m_wndEditor
->SetFont( m_captionFont
);
1589 // -----------------------------------------------------------------------
1591 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1594 #if wxPG_SMALL_SCREEN
1595 // On small-screen devices, always show dialogs with default position and size.
1596 return wxDefaultPosition
;
1598 int splitterX
= GetSplitterPosition();
1602 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1604 ImprovedClientToScreen( &x
, &y
);
1606 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1607 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1614 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1624 new_y
= y
+ m_lineHeight
;
1626 return wxPoint(new_x
,new_y
);
1630 // -----------------------------------------------------------------------
1632 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1634 if ( src_str
.length() == 0 )
1640 bool prev_is_slash
= false;
1642 wxString::const_iterator i
= src_str
.begin();
1646 for ( ; i
!= src_str
.end(); i
++ )
1650 if ( a
!= wxS('\\') )
1652 if ( !prev_is_slash
)
1658 if ( a
== wxS('n') )
1661 dst_str
<< wxS('\n');
1663 dst_str
<< wxS('\n');
1666 else if ( a
== wxS('t') )
1667 dst_str
<< wxS('\t');
1671 prev_is_slash
= false;
1675 if ( prev_is_slash
)
1677 dst_str
<< wxS('\\');
1678 prev_is_slash
= false;
1682 prev_is_slash
= true;
1689 // -----------------------------------------------------------------------
1691 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1693 if ( src_str
.length() == 0 )
1699 wxString::const_iterator i
= src_str
.begin();
1700 wxUniChar prev_a
= wxS('\0');
1704 for ( ; i
!= src_str
.end(); i
++ )
1708 if ( a
>= wxS(' ') )
1710 // This surely is not something that requires an escape sequence.
1715 // This might need...
1716 if ( a
== wxS('\r') )
1718 // DOS style line end.
1719 // Already taken care below
1721 else if ( a
== wxS('\n') )
1722 // UNIX style line end.
1723 dst_str
<< wxS("\\n");
1724 else if ( a
== wxS('\t') )
1726 dst_str
<< wxS('\t');
1729 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1739 // -----------------------------------------------------------------------
1741 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1745 return (wxPGProperty
*) NULL
;
1748 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1751 // -----------------------------------------------------------------------
1752 // wxPropertyGrid graphics related methods
1753 // -----------------------------------------------------------------------
1755 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1759 // Update everything inside the box
1760 wxRect r
= GetUpdateRegion().GetBox();
1762 dc
.SetPen(m_colEmptySpace
);
1763 dc
.SetBrush(m_colEmptySpace
);
1764 dc
.DrawRectangle(r
);
1767 // -----------------------------------------------------------------------
1769 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1770 wxPGProperty
* property
) const
1772 // Prepare rectangle to be used
1774 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1775 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1777 #if (wxPG_USE_RENDERER_NATIVE)
1779 #elif wxPG_ICON_WIDTH
1780 // Drawing expand/collapse button manually
1781 dc
.SetPen(m_colPropFore
);
1782 if ( property
->IsCategory() )
1783 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1785 dc
.SetBrush(m_colPropBack
);
1787 dc
.DrawRectangle( r
);
1788 int _y
= r
.y
+(m_iconWidth
/2);
1789 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1794 if ( property
->IsExpanded() )
1796 // wxRenderer functions are non-mutating in nature, so it
1797 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1798 // Hopefully this does not cause problems.
1799 #if (wxPG_USE_RENDERER_NATIVE)
1800 wxRendererNative::Get().DrawTreeItemButton(
1806 #elif wxPG_ICON_WIDTH
1815 #if (wxPG_USE_RENDERER_NATIVE)
1816 wxRendererNative::Get().DrawTreeItemButton(
1822 #elif wxPG_ICON_WIDTH
1823 int _x
= r
.x
+(m_iconWidth
/2);
1824 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1830 #if (wxPG_USE_RENDERER_NATIVE)
1832 #elif wxPG_ICON_WIDTH
1835 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1839 // -----------------------------------------------------------------------
1842 // This is the one called by OnPaint event handler and others.
1843 // topy and bottomy are already unscrolled (ie. physical)
1845 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1847 unsigned int bottomy
,
1848 const wxRect
* clipRect
)
1850 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1852 m_pState
->EnsureVirtualHeight();
1854 wxRect tempClipRect
;
1857 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1858 clipRect
= &tempClipRect
;
1861 // items added check
1862 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1864 int paintFinishY
= 0;
1866 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1869 bool isBuffered
= false;
1871 #if wxPG_DOUBLE_BUFFER
1872 wxMemoryDC
* bufferDC
= NULL
;
1874 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1876 if ( !m_doubleBuffer
)
1878 paintFinishY
= clipRect
->y
;
1883 bufferDC
= new wxMemoryDC();
1885 // If nothing was changed, then just copy from double-buffer
1886 bufferDC
->SelectObject( *m_doubleBuffer
);
1896 dc
.SetClippingRegion( *clipRect
);
1897 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1900 #if wxPG_DOUBLE_BUFFER
1903 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1904 bufferDC
, 0, 0, wxCOPY
);
1905 dc
.DestroyClippingRegion(); // Is this really necessary?
1911 // Clear area beyond bottomY?
1912 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1914 dc
.SetPen(m_colEmptySpace
);
1915 dc
.SetBrush(m_colEmptySpace
);
1916 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1920 // -----------------------------------------------------------------------
1922 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1923 const wxPGProperty
* firstItem
,
1924 const wxPGProperty
* lastItem
,
1925 const wxRect
* clipRect
,
1926 bool isBuffered
) const
1928 // TODO: This should somehow be eliminated.
1929 wxRect tempClipRect
;
1932 wxASSERT(firstItem
);
1934 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1935 clipRect
= &tempClipRect
;
1939 firstItem
= DoGetItemAtY(clipRect
->y
);
1943 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1945 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1948 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1951 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1952 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1954 int lh
= m_lineHeight
;
1957 int lastItemBottomY
;
1959 firstItemTopY
= clipRect
->y
;
1960 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1962 // Align y coordinates to item boundaries
1963 firstItemTopY
-= firstItemTopY
% lh
;
1964 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1965 lastItemBottomY
-= 1;
1967 // Entire range outside scrolled, visible area?
1968 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1971 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1975 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1976 firstItem->GetLabel().c_str(),
1977 lastItem->GetLabel().c_str(),
1978 (int)(lastItemBottomY - firstItemTopY),
1980 (unsigned long)clipRect );
1985 long windowStyle
= m_windowStyle
;
1991 // With wxPG_DOUBLE_BUFFER, do double buffering
1992 // - buffer's y = 0, so align cliprect and coordinates to that
1994 #if wxPG_DOUBLE_BUFFER
2000 xRelMod
= clipRect
->x
;
2001 yRelMod
= clipRect
->y
;
2004 // clipRect conversion
2012 firstItemTopY
-= yRelMod
;
2013 lastItemBottomY
-= yRelMod
;
2016 wxUnusedVar(isBuffered
);
2019 int x
= m_marginWidth
- xRelMod
;
2021 const wxFont
& normalfont
= m_font
;
2023 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
2025 bool isEnabled
= IsEnabled();
2028 // Prepare some pens and brushes that are often changed to.
2031 wxBrush
marginBrush(m_colMargin
);
2032 wxPen
marginPen(m_colMargin
);
2033 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2034 wxPen
linepen(m_colLine
,1,wxSOLID
);
2036 // pen that has same colour as text
2037 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2040 // Clear margin with background colour
2042 dc
.SetBrush( marginBrush
);
2043 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2045 dc
.SetPen( *wxTRANSPARENT_PEN
);
2046 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2049 const wxPGProperty
* selected
= m_selected
;
2050 const wxPropertyGridPageState
* state
= m_pState
;
2052 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2053 bool wasSelectedPainted
= false;
2056 // TODO: Only render columns that are within clipping region.
2058 dc
.SetFont(normalfont
);
2060 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2061 int endScanBottomY
= lastItemBottomY
+ lh
;
2062 int y
= firstItemTopY
;
2065 // Pregenerate list of visible properties.
2066 wxArrayPGProperty visPropArray
;
2067 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2069 for ( ; !it
.AtEnd(); it
.Next() )
2071 const wxPGProperty
* p
= *it
;
2073 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2075 visPropArray
.push_back((wxPGProperty
*)p
);
2077 if ( y
> endScanBottomY
)
2084 visPropArray
.push_back(NULL
);
2086 wxPGProperty
* nextP
= visPropArray
[0];
2088 int gridWidth
= state
->m_width
;
2091 for ( unsigned int arrInd
=1;
2092 nextP
&& y
<= lastItemBottomY
;
2095 wxPGProperty
* p
= nextP
;
2096 nextP
= visPropArray
[arrInd
];
2098 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2099 int textMarginHere
= x
;
2100 int renderFlags
= wxPGCellRenderer::Control
;
2102 int greyDepth
= m_marginWidth
;
2103 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2104 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2106 int greyDepthX
= greyDepth
- xRelMod
;
2108 // Use basic depth if in non-categoric mode and parent is base array.
2109 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2111 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2114 // Paint margin area
2115 dc
.SetBrush(marginBrush
);
2116 dc
.SetPen(marginPen
);
2117 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2119 dc
.SetPen( linepen
);
2124 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2130 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2132 sx
+= state
->m_colWidths
[si
];
2133 dc
.DrawLine( sx
, y
, sx
, y2
);
2136 // Horizontal Line, below
2137 // (not if both this and next is category caption)
2138 if ( p
->IsCategory() &&
2139 nextP
&& nextP
->IsCategory() )
2140 dc
.SetPen(m_colCapBack
);
2142 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2144 if ( p
== selected
)
2146 renderFlags
|= wxPGCellRenderer::Selected
;
2147 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2148 wasSelectedPainted
= true;
2156 if ( p
->IsCategory() )
2158 if ( p
->m_fgColIndex
== 0 )
2159 rowFgCol
= m_colCapFore
;
2161 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2162 rowBgBrush
= wxBrush(m_colCapBack
);
2164 else if ( p
!= selected
)
2166 // Disabled may get different colour.
2167 if ( !p
->IsEnabled() )
2168 rowFgCol
= m_colDisPropFore
;
2170 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2172 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2176 // Selected gets different colour.
2177 if ( reallyFocused
)
2179 rowFgCol
= m_colSelFore
;
2180 rowBgBrush
= wxBrush(m_colSelBack
);
2182 else if ( isEnabled
)
2184 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2185 rowBgBrush
= marginBrush
;
2189 rowFgCol
= m_colDisPropFore
;
2190 rowBgBrush
= wxBrush(m_colSelBack
);
2194 bool fontChanged
= false;
2196 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2201 if ( p
->IsCategory() )
2203 // Captions are all cells merged as one
2204 dc
.SetFont(m_captionFont
);
2206 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2208 dc
.SetBrush(rowBgBrush
);
2209 dc
.SetPen(rowBgBrush
.GetColour());
2210 dc
.SetTextForeground(rowFgCol
);
2212 dc
.DrawRectangle(cellRect
);
2215 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2216 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2219 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2220 DrawExpanderButton( dc
, butRect
, p
);
2224 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2226 dc
.SetFont(m_captionFont
);
2232 int nextCellWidth
= state
->m_colWidths
[0];
2233 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2234 int textXAdd
= textMarginHere
- greyDepthX
;
2236 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2238 cellRect
.width
= nextCellWidth
- 1;
2240 bool ctrlCell
= false;
2243 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2245 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2246 dc
.SetBrush(editorBgCol
);
2247 dc
.SetPen(editorBgCol
);
2248 dc
.SetTextForeground(m_colPropFore
);
2250 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2255 dc
.SetBrush(rowBgBrush
);
2256 dc
.SetPen(rowBgBrush
.GetColour());
2257 dc
.SetTextForeground(rowFgCol
);
2260 dc
.DrawRectangle(cellRect
);
2263 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2264 DrawExpanderButton( dc
, butRect
, p
);
2266 dc
.SetClippingRegion(cellRect
);
2268 cellRect
.x
+= textXAdd
;
2269 cellRect
.width
-= textXAdd
;
2274 wxPGCellRenderer
* renderer
;
2275 int cmnVal
= p
->GetCommonValue();
2276 if ( cmnVal
== -1 || ci
!= 1 )
2278 renderer
= p
->GetCellRenderer(ci
);
2279 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2283 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2284 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2288 cellX
+= state
->m_colWidths
[ci
];
2289 if ( ci
< (state
->m_colWidths
.size()-1) )
2290 nextCellWidth
= state
->m_colWidths
[ci
+1];
2292 dc
.DestroyClippingRegion(); // Is this really necessary?
2298 dc
.SetFont(normalfont
);
2303 // Refresh editor controls (seems not needed on msw)
2304 // NOTE: This code is mandatory for GTK!
2305 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2306 if ( wasSelectedPainted
)
2309 m_wndEditor
->Refresh();
2311 m_wndEditor2
->Refresh();
2318 // -----------------------------------------------------------------------
2320 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2324 if ( m_width
< 10 || m_height
< 10 ||
2325 !m_pState
->m_properties
->GetChildCount() ||
2326 p1
== (wxPGProperty
*) NULL
)
2327 return wxRect(0,0,0,0);
2332 // Return rect which encloses the given property range
2334 int visTop
= p1
->GetY();
2337 visBottom
= p2
->GetY() + m_lineHeight
;
2339 visBottom
= m_height
+ visTop
;
2341 // If seleced property is inside the range, we'll extend the range to include
2343 wxPGProperty
* selected
= m_selected
;
2346 int selectedY
= selected
->GetY();
2347 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2349 wxWindow
* editor
= GetEditorControl();
2352 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2353 if ( visBottom2
> visBottom
)
2354 visBottom
= visBottom2
;
2359 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2362 // -----------------------------------------------------------------------
2364 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2369 if ( m_pState
->m_itemsAdded
)
2370 PrepareAfterItemsAdded();
2372 wxRect r
= GetPropertyRect(p1
, p2
);
2375 m_canvas
->RefreshRect(r
);
2379 // -----------------------------------------------------------------------
2381 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2383 if ( p
== m_selected
)
2384 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2386 DrawItemAndChildren(p
);
2389 // -----------------------------------------------------------------------
2391 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2396 // Draw item, children, and parent too, if it is not category
2397 wxPGProperty
* parent
= p
->GetParent();
2400 !parent
->IsCategory() &&
2401 parent
->GetParent() )
2404 parent
= parent
->GetParent();
2407 DrawItemAndChildren(p
);
2410 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2412 wxCHECK_RET( p
, wxT("invalid property id") );
2414 // Do not draw if in non-visible page
2415 if ( p
->GetParentState() != m_pState
)
2418 // do not draw a single item if multiple pending
2419 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2422 wxWindow
* wndPrimary
= GetEditorControl();
2424 // Update child control.
2425 if ( m_selected
&& m_selected
->GetParent() == p
)
2426 m_selected
->UpdateControl(wndPrimary
);
2428 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2430 DrawItems(p
, lastDrawn
);
2433 // -----------------------------------------------------------------------
2435 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2436 const wxRect
*rect
)
2438 PrepareAfterItemsAdded();
2440 wxWindow::Refresh(false);
2442 // TODO: Coordinate translation
2443 m_canvas
->Refresh(false, rect
);
2445 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2446 // I think this really helps only GTK+1.2
2447 if ( m_wndEditor
) m_wndEditor
->Refresh();
2448 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2452 // -----------------------------------------------------------------------
2453 // wxPropertyGrid global operations
2454 // -----------------------------------------------------------------------
2456 void wxPropertyGrid::Clear()
2460 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2461 wxPG_CHECK_RET_DBG( selRes
,
2462 wxT("failed to deselect a property (editor probably had invalid value)") );
2465 m_pState
->DoClear();
2471 RecalculateVirtualSize();
2473 // Need to clear some area at the end
2475 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2478 // -----------------------------------------------------------------------
2480 bool wxPropertyGrid::EnableCategories( bool enable
)
2482 if ( !ClearSelection() )
2488 // Enable categories
2491 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2496 // Disable categories
2498 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2501 if ( !m_pState
->EnableCategories(enable
) )
2506 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2508 m_pState
->m_itemsAdded
= 1; // force
2509 PrepareAfterItemsAdded();
2513 m_pState
->m_itemsAdded
= 1;
2515 // No need for RecalculateVirtualSize() here - it is already called in
2516 // wxPropertyGridPageState method above.
2523 // -----------------------------------------------------------------------
2525 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2527 wxASSERT( pNewState
);
2528 wxASSERT( pNewState
->GetGrid() );
2530 if ( pNewState
== m_pState
)
2533 wxPGProperty
* oldSelection
= m_selected
;
2538 bool selRes
= ClearSelection();
2539 wxPG_CHECK_RET_DBG( selRes
,
2540 wxT("failed to deselect a property (editor probably had invalid value)") );
2543 m_pState
->m_selected
= oldSelection
;
2545 bool orig_mode
= m_pState
->IsInNonCatMode();
2546 bool new_state_mode
= pNewState
->IsInNonCatMode();
2548 m_pState
= pNewState
;
2551 int pgWidth
= GetClientSize().x
;
2552 if ( HasVirtualWidth() )
2554 int minWidth
= pgWidth
;
2555 if ( pNewState
->m_width
< minWidth
)
2557 pNewState
->m_width
= minWidth
;
2558 pNewState
->CheckColumnWidths();
2564 // Just in case, fully re-center splitter
2565 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2566 pNewState
->m_fSplitterX
= -1.0;
2568 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2571 m_propHover
= (wxPGProperty
*) NULL
;
2573 // If necessary, convert state to correct mode.
2574 if ( orig_mode
!= new_state_mode
)
2576 // This should refresh as well.
2577 EnableCategories( orig_mode
?false:true );
2579 else if ( !m_frozen
)
2581 // Refresh, if not frozen.
2582 if ( m_pState
->m_itemsAdded
)
2583 PrepareAfterItemsAdded();
2586 if ( m_pState
->m_selected
)
2587 DoSelectProperty( m_pState
->m_selected
);
2589 RecalculateVirtualSize(0);
2593 m_pState
->m_itemsAdded
= 1;
2596 // -----------------------------------------------------------------------
2598 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2600 wxPG_PROP_ARG_CALL_PROLOG()
2602 m_pState
->SortChildren( p
);
2605 // -----------------------------------------------------------------------
2607 void wxPropertyGrid::Sort()
2609 bool selRes
= ClearSelection(); // This must be before state clear
2610 wxPG_CHECK_RET_DBG( selRes
,
2611 wxT("failed to deselect a property (editor probably had invalid value)") );
2616 // -----------------------------------------------------------------------
2618 // Call to SetSplitterPosition will always disable splitter auto-centering
2619 // if parent window is shown.
2620 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2622 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2625 wxPropertyGridPageState
* state
= m_pState
;
2627 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2632 CorrectEditorWidgetSizeX();
2638 // -----------------------------------------------------------------------
2640 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2642 SetSplitterPosition( m_width
/2, true );
2643 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2644 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2647 // -----------------------------------------------------------------------
2648 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2649 // -----------------------------------------------------------------------
2651 // Returns nearest paint visible property (such that will be painted unless
2652 // window is scrolled or resized). If given property is paint visible, then
2653 // it itself will be returned
2654 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2656 int vx
,vy1
;// Top left corner of client
2657 GetViewStart(&vx
,&vy1
);
2658 vy1
*= wxPG_PIXELS_PER_UNIT
;
2660 int vy2
= vy1
+ m_height
;
2661 int propY
= p
->GetY2(m_lineHeight
);
2663 if ( (propY
+ m_lineHeight
) < vy1
)
2666 return DoGetItemAtY( vy1
);
2668 else if ( propY
> vy2
)
2671 return DoGetItemAtY( vy2
);
2674 // Itself paint visible
2679 // -----------------------------------------------------------------------
2681 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2685 m_pushButKeyCode
= keycode
;
2686 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2687 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2691 m_pushButKeyCode
= WXK_DOWN
;
2692 m_pushButKeyCodeNeedsCtrl
= 0;
2693 m_pushButKeyCodeNeedsAlt
= 1;
2697 // -----------------------------------------------------------------------
2698 // Methods related to change in value, value modification and sending events
2699 // -----------------------------------------------------------------------
2701 // commits any changes in editor of selected property
2702 // return true if validation did not fail
2703 // flags are same as with DoSelectProperty
2704 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2706 // Committing already?
2707 if ( m_inCommitChangesFromEditor
)
2710 // Don't do this if already processing editor event. It might
2711 // induce recursive dialogs and crap like that.
2712 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2714 if ( m_inDoPropertyChanged
)
2721 IsEditorsValueModified() &&
2722 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2725 m_inCommitChangesFromEditor
= 1;
2727 wxVariant
variant(m_selected
->GetValueRef());
2728 bool valueIsPending
= false;
2730 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2731 // due to another window getting focus
2732 wxWindow
* oldFocus
= m_curFocused
;
2734 bool validationFailure
= false;
2735 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2737 m_chgInfo_changedProperty
= NULL
;
2739 // If truly modified, schedule value as pending.
2740 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2742 if ( DoEditorValidate() &&
2743 PerformValidation(m_selected
, variant
) )
2745 valueIsPending
= true;
2749 validationFailure
= true;
2754 EditorsValueWasNotModified();
2759 m_inCommitChangesFromEditor
= 0;
2761 if ( validationFailure
&& !forceSuccess
)
2765 oldFocus
->SetFocus();
2766 m_curFocused
= oldFocus
;
2769 res
= OnValidationFailure(m_selected
, variant
);
2771 // Now prevent further validation failure messages
2774 EditorsValueWasNotModified();
2775 OnValidationFailureReset(m_selected
);
2778 else if ( valueIsPending
)
2780 DoPropertyChanged( m_selected
, flags
);
2781 EditorsValueWasNotModified();
2790 // -----------------------------------------------------------------------
2792 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2795 // Runs all validation functionality.
2796 // Returns true if value passes all tests.
2799 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2801 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2803 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2808 // Adapt list to child values, if necessary
2809 wxVariant listValue
= pendingValue
;
2810 wxVariant
* pPendingValue
= &pendingValue
;
2811 wxVariant
* pList
= NULL
;
2813 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2814 // string value, then we need treat as it was changed instead
2815 // (or, in addition, as is the case with composite string parent).
2816 // This includes creating list variant for child values.
2818 wxPGProperty
* pwc
= p
->GetParent();
2819 wxPGProperty
* changedProperty
= p
;
2820 wxPGProperty
* baseChangedProperty
= changedProperty
;
2821 wxVariant bcpPendingList
;
2823 listValue
= pendingValue
;
2824 listValue
.SetName(p
->GetBaseName());
2827 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2829 wxVariantList tempList
;
2830 wxVariant
lv(tempList
, pwc
->GetBaseName());
2831 lv
.Append(listValue
);
2833 pPendingValue
= &listValue
;
2835 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2837 baseChangedProperty
= pwc
;
2838 bcpPendingList
= lv
;
2841 changedProperty
= pwc
;
2842 pwc
= pwc
->GetParent();
2846 wxPGProperty
* evtChangingProperty
= changedProperty
;
2848 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2850 value
= *pPendingValue
;
2854 // Convert list to child values
2855 pList
= pPendingValue
;
2856 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2859 wxVariant evtChangingValue
= value
;
2861 // FIXME: After proper ValueToString()s added, remove
2862 // this. It is just a temporary fix, as evt_changing
2863 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2864 // (unless it is selected, and textctrl editor is open).
2865 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2867 evtChangingProperty
= baseChangedProperty
;
2868 if ( evtChangingProperty
!= p
)
2870 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2874 evtChangingValue
= pendingValue
;
2878 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2880 if ( changedProperty
== m_selected
)
2882 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2883 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2887 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2891 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2892 m_chgInfo_changedProperty
= changedProperty
;
2893 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2894 m_chgInfo_pendingValue
= value
;
2897 m_chgInfo_valueList
= *pList
;
2899 m_chgInfo_valueList
.MakeNull();
2901 // If changedProperty is not property which value was edited,
2902 // then call wxPGProperty::ValidateValue() for that as well.
2903 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2905 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2909 // SendEvent returns true if event was vetoed
2910 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2916 // -----------------------------------------------------------------------
2918 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2920 if ( !msg
.length() )
2924 if ( !wxPGGlobalVars
->m_offline
)
2926 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2929 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2932 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2935 pStatusBar
->SetStatusText(msg
);
2943 ::wxMessageBox(msg
, _T("Property Error"));
2946 // -----------------------------------------------------------------------
2948 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2950 int vfb
= m_validationInfo
.m_failureBehavior
;
2952 if ( vfb
& wxPG_VFB_BEEP
)
2955 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2956 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2958 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2959 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2961 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2963 wxColour vfbFg
= *wxWHITE
;
2964 wxColour vfbBg
= *wxRED
;
2965 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2966 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2968 DrawItemAndChildren(property
);
2970 if ( property
== m_selected
)
2972 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2974 wxWindow
* editor
= GetEditorControl();
2977 editor
->SetForegroundColour(vfbFg
);
2978 editor
->SetBackgroundColour(vfbBg
);
2984 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2986 wxString msg
= m_validationInfo
.m_failureMessage
;
2988 if ( !msg
.length() )
2989 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2991 DoShowPropertyError(property
, msg
);
2994 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2997 // -----------------------------------------------------------------------
2999 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3001 int vfb
= m_validationInfo
.m_failureBehavior
;
3003 if ( vfb
& wxPG_VFB_MARK_CELL
)
3005 property
->SetCell(0, NULL
);
3006 property
->SetCell(1, NULL
);
3008 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3010 if ( property
== m_selected
&& GetEditorControl() )
3012 // Calling this will recreate the control, thus resetting its colour
3013 RefreshProperty(property
);
3017 DrawItemAndChildren(property
);
3022 // -----------------------------------------------------------------------
3024 // flags are same as with DoSelectProperty
3025 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3027 if ( m_inDoPropertyChanged
)
3030 wxWindow
* editor
= GetEditorControl();
3032 m_pState
->m_anyModified
= 1;
3034 m_inDoPropertyChanged
= 1;
3036 // Maybe need to update control
3037 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3039 // These values were calculated in PerformValidation()
3040 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3041 wxVariant value
= m_chgInfo_pendingValue
;
3043 wxPGProperty
* topPaintedProperty
= changedProperty
;
3045 while ( !topPaintedProperty
->IsCategory() &&
3046 !topPaintedProperty
->IsRoot() )
3048 topPaintedProperty
= topPaintedProperty
->GetParent();
3051 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3053 // Set as Modified (not if dragging just began)
3054 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3056 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3057 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3060 SetCurControlBoldFont();
3066 // Propagate updates to parent(s)
3068 wxPGProperty
* prevPwc
= NULL
;
3070 while ( prevPwc
!= topPaintedProperty
)
3072 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3074 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3077 SetCurControlBoldFont();
3081 pwc
= pwc
->GetParent();
3084 // Draw the actual property
3085 DrawItemAndChildren( topPaintedProperty
);
3088 // If value was set by wxPGProperty::OnEvent, then update the editor
3090 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3093 p
->GetEditorClass()->UpdateControl(p
, editor
);
3097 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3098 if ( m_wndEditor
) m_wndEditor
->Refresh();
3099 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3104 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3106 // If top parent has composite string value, then send to child parents,
3107 // starting from baseChangedProperty.
3108 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3110 pwc
= m_chgInfo_baseChangedProperty
;
3112 while ( pwc
!= changedProperty
)
3114 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3115 pwc
= pwc
->GetParent();
3119 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3121 m_inDoPropertyChanged
= 0;
3126 // -----------------------------------------------------------------------
3128 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3130 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3132 m_chgInfo_changedProperty
= NULL
;
3134 if ( PerformValidation(p
, newValue
) )
3136 DoPropertyChanged(p
);
3141 OnValidationFailure(p
, newValue
);
3147 // -----------------------------------------------------------------------
3149 // Runs wxValidator for the selected property
3150 bool wxPropertyGrid::DoEditorValidate()
3152 #if wxUSE_VALIDATORS
3153 // With traditional validator style, we dont need to more
3154 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3157 if ( m_iFlags
& wxPG_FL_VALIDATION_FAILED
)
3162 wxWindow
* wnd
= GetEditorControl();
3164 wxValidator
* validator
= m_selected
->GetValidator();
3165 if ( validator
&& wnd
)
3167 // Use TextCtrl of ODComboBox instead
3168 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3170 wnd
= ((wxOwnerDrawnComboBox
*)wnd
)->GetTextCtrl();
3176 validator
->SetWindow(wnd
);
3178 // Instead setting the flag after the failure, we set
3179 // it before checking and then clear afterwards if things
3180 // went fine. This trick is necessary since focus events
3181 // may be triggered while in Validate.
3182 m_iFlags
|= wxPG_FL_VALIDATION_FAILED
;
3183 if ( !validator
->Validate(this) )
3185 // If you dpm't want to display message multiple times per change,
3186 // comment the following line.
3187 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3190 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3196 // -----------------------------------------------------------------------
3198 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3200 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3201 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3203 wxWindow
* parent
= wnd
->GetParent();
3206 (parent
== m_canvas
||
3207 parent
->GetParent() == m_canvas
) )
3209 OnCustomEditorEvent((wxCommandEvent
&)event
);
3213 return wxPanel::ProcessEvent(event
);
3216 // -----------------------------------------------------------------------
3218 // NB: It may really not be wxCommandEvent - must check if necessary
3220 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3222 wxPGProperty
* selected
= m_selected
;
3225 // Somehow, event is handled after property has been deselected.
3226 // Possibly, but very rare.
3230 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3233 wxVariant
pendingValue(selected
->GetValueRef());
3234 wxWindow
* wnd
= GetEditorControl();
3236 bool wasUnspecified
= selected
->IsValueUnspecified();
3237 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3239 bool valueIsPending
= false;
3241 m_chgInfo_changedProperty
= NULL
;
3243 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3246 // Filter out excess wxTextCtrl modified events
3247 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3249 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3251 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3253 wxString newTcValue
= tc
->GetValue();
3254 if ( m_prevTcValue
== newTcValue
)
3257 m_prevTcValue
= newTcValue
;
3260 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3262 bool validationFailure
= false;
3263 bool buttonWasHandled
= false;
3266 // Try common button handling
3267 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3269 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3273 buttonWasHandled
= true;
3274 // Store as res2, as previously (and still currently alternatively)
3275 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3276 // in wxPGProperty::OnEvent().
3277 adapter
->ShowDialog( this, selected
);
3282 if ( !buttonWasHandled
)
3286 // First call editor class' event handler.
3287 const wxPGEditor
* editor
= selected
->GetEditorClass();
3289 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3291 // If changes, validate them
3292 if ( DoEditorValidate() )
3294 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3295 valueIsPending
= true;
3299 validationFailure
= true;
3304 // Then the property's custom handler (must be always called, unless
3305 // validation failed).
3306 if ( !validationFailure
)
3307 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3310 // SetValueInEvent(), as called in one of the functions referred above
3311 // overrides editor's value.
3312 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3314 valueIsPending
= true;
3315 pendingValue
= m_changeInEventValue
;
3316 selFlags
|= wxPG_SEL_DIALOGVAL
;
3319 if ( !validationFailure
&& valueIsPending
)
3320 if ( !PerformValidation(m_selected
, pendingValue
) )
3321 validationFailure
= true;
3323 if ( validationFailure
)
3325 OnValidationFailure(selected
, pendingValue
);
3327 else if ( valueIsPending
)
3329 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3331 DoPropertyChanged(selected
, selFlags
);
3332 EditorsValueWasNotModified();
3336 // No value after all
3338 // Let unhandled button click events go to the parent
3339 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3341 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3342 GetEventHandler()->AddPendingEvent(evt
);
3346 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3349 // -----------------------------------------------------------------------
3350 // wxPropertyGrid editor control helper methods
3351 // -----------------------------------------------------------------------
3353 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3355 int itemy
= p
->GetY2(m_lineHeight
);
3357 int cust_img_space
= 0;
3358 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3359 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3361 // TODO: If custom image detection changes from current, change this.
3362 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3364 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3365 int imwid
= p
->OnMeasureImage().x
;
3366 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3367 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3372 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3374 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3379 // -----------------------------------------------------------------------
3381 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3383 wxSize sz
= GetImageSize(p
, item
);
3384 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3385 wxPG_CUSTOM_IMAGE_SPACINGY
,
3390 // return size of custom paint image
3391 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3393 // If called with NULL property, then return default image
3394 // size for properties that use image.
3396 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3398 wxSize cis
= p
->OnMeasureImage(item
);
3400 int choiceCount
= p
->m_choices
.GetCount();
3401 int comVals
= p
->GetDisplayedCommonValueCount();
3402 if ( item
>= choiceCount
&& comVals
> 0 )
3404 unsigned int cvi
= item
-choiceCount
;
3405 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3407 else if ( item
>= 0 && choiceCount
== 0 )
3408 return wxSize(0, 0);
3413 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3418 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3425 // -----------------------------------------------------------------------
3427 // takes scrolling into account
3428 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3431 GetViewStart(&vx
,&vy
);
3432 vy
*=wxPG_PIXELS_PER_UNIT
;
3433 vx
*=wxPG_PIXELS_PER_UNIT
;
3436 ClientToScreen( px
, py
);
3439 // -----------------------------------------------------------------------
3441 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3444 GetViewStart(&pt2
.x
,&pt2
.y
);
3445 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3446 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3450 return m_pState
->HitTest(pt2
);
3453 // -----------------------------------------------------------------------
3455 // custom set cursor
3456 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3458 if ( type
== m_curcursor
&& !override
) return;
3460 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3462 if ( type
== wxCURSOR_SIZEWE
)
3463 cursor
= m_cursorSizeWE
;
3465 m_canvas
->SetCursor( *cursor
);
3470 // -----------------------------------------------------------------------
3471 // wxPropertyGrid property selection
3472 // -----------------------------------------------------------------------
3474 #define CONNECT_CHILD(EVT,FUNCTYPE,FUNC) \
3475 wnd->Connect(id, EVT, \
3476 (wxObjectEventFunction) (wxEventFunction) \
3477 FUNCTYPE (&wxPropertyGrid::FUNC), \
3480 // Setups event handling for child control
3481 void wxPropertyGrid::SetupEventHandling( wxWindow
* argWnd
, int id
)
3483 wxWindow
* wnd
= argWnd
;
3485 if ( argWnd
== m_wndEditor
)
3487 CONNECT_CHILD(wxEVT_MOTION
,(wxMouseEventFunction
),OnMouseMoveChild
)
3488 CONNECT_CHILD(wxEVT_LEFT_UP
,(wxMouseEventFunction
),OnMouseUpChild
)
3489 CONNECT_CHILD(wxEVT_LEFT_DOWN
,(wxMouseEventFunction
),OnMouseClickChild
)
3490 CONNECT_CHILD(wxEVT_RIGHT_UP
,(wxMouseEventFunction
),OnMouseRightClickChild
)
3491 CONNECT_CHILD(wxEVT_ENTER_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3492 CONNECT_CHILD(wxEVT_LEAVE_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3496 CONNECT_CHILD(wxEVT_NAVIGATION_KEY
,(wxNavigationKeyEventFunction
),OnNavigationKey
)
3498 CONNECT_CHILD(wxEVT_KEY_DOWN
,(wxCharEventFunction
),OnChildKeyDown
)
3499 CONNECT_CHILD(wxEVT_KEY_UP
,(wxCharEventFunction
),OnChildKeyUp
)
3500 CONNECT_CHILD(wxEVT_KILL_FOCUS
,(wxFocusEventFunction
),OnFocusEvent
)
3503 void wxPropertyGrid::FreeEditors()
3505 // Do not free editors immediately if processing events
3506 if ( !m_windowsToDelete
)
3507 m_windowsToDelete
= new wxArrayPtrVoid
;
3511 m_windowsToDelete
->push_back(m_wndEditor2
);
3512 m_wndEditor2
->Hide();
3513 m_wndEditor2
= (wxWindow
*) NULL
;
3518 m_windowsToDelete
->push_back(m_wndEditor
);
3519 m_wndEditor
->Hide();
3520 m_wndEditor
= (wxWindow
*) NULL
;
3524 // Call with NULL to de-select property
3525 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3527 wxPanel
* canvas
= GetPanel();
3531 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3532 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3534 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3537 if ( m_inDoSelectProperty
)
3540 m_inDoSelectProperty
= 1;
3542 wxPGProperty
* prev
= m_selected
;
3545 // Delete windows pending for deletion
3546 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3550 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3551 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3553 m_windowsToDelete
->clear();
3558 m_inDoSelectProperty
= 0;
3563 // If we are frozen, then just set the values.
3566 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3567 m_editorFocused
= 0;
3570 m_pState
->m_selected
= p
;
3572 // If frozen, always free controls. But don't worry, as Thaw will
3573 // recall SelectProperty to recreate them.
3576 // Prevent any further selection measures in this call
3577 p
= (wxPGProperty
*) NULL
;
3582 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3584 // Only set focus if not deselecting
3587 if ( flags
& wxPG_SEL_FOCUS
)
3591 m_wndEditor
->SetFocus();
3592 m_editorFocused
= 1;
3601 m_inDoSelectProperty
= 0;
3606 // First, deactivate previous
3610 OnValidationFailureReset(m_selected
);
3612 // Must double-check if this is an selected in case of forceswitch
3615 if ( !CommitChangesFromEditor(flags
) )
3617 // Validation has failed, so we can't exit the previous editor
3618 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3619 // _("Invalid Value"),wxOK|wxICON_ERROR);
3620 m_inDoSelectProperty
= 0;
3628 m_selected
= (wxPGProperty
*) NULL
;
3629 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3631 // We need to always fully refresh the grid here
3634 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3635 EditorsValueWasNotModified();
3638 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3641 // Then, activate the one given.
3644 int propY
= p
->GetY2(m_lineHeight
);
3646 int splitterX
= GetSplitterPosition();
3647 m_editorFocused
= 0;
3649 m_pState
->m_selected
= p
;
3650 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3652 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3654 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3656 // Do we need OnMeasureCalls?
3657 wxSize imsz
= p
->OnMeasureImage();
3660 // Only create editor for non-disabled non-caption
3661 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3663 // do this for non-caption items
3667 // Do we need to paint the custom image, if any?
3668 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3669 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3670 !p
->GetEditorClass()->CanContainCustomImage()
3672 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3674 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3675 wxPoint goodPos
= grect
.GetPosition();
3676 #if wxPG_CREATE_CONTROLS_HIDDEN
3677 int coord_adjust
= m_height
- goodPos
.y
;
3678 goodPos
.y
+= coord_adjust
;
3681 const wxPGEditor
* editor
= p
->GetEditorClass();
3682 wxCHECK_MSG(editor
, false,
3683 wxT("NULL editor class not allowed"));
3685 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3687 wxPGWindowList wndList
= editor
->CreateControls(this,
3692 m_wndEditor
= wndList
.m_primary
;
3693 m_wndEditor2
= wndList
.m_secondary
;
3695 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3696 // value is drawn as normal, and m_wndEditor2 is assumed
3697 // to be a right-aligned button that triggers a separate editor
3702 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3703 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3705 // Set validator, if any
3706 #if wxUSE_VALIDATORS
3707 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3709 wxValidator
* validator
= p
->GetValidator();
3711 m_wndEditor
->SetValidator(*validator
);
3715 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3716 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3718 // If it has modified status, use bold font
3719 // (must be done before capturing m_ctrlXAdjust)
3720 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3721 SetCurControlBoldFont();
3724 // Fix TextCtrl indentation
3725 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3726 wxTextCtrl
* tc
= NULL
;
3727 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3728 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3730 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3732 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3735 // Store x relative to splitter (we'll need it).
3736 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3738 // Check if background clear is not necessary
3739 wxPoint pos
= m_wndEditor
->GetPosition();
3740 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3742 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3745 m_wndEditor
->SetSizeHints(3, 3);
3747 #if wxPG_CREATE_CONTROLS_HIDDEN
3748 m_wndEditor
->Show(false);
3749 m_wndEditor
->Freeze();
3751 goodPos
= m_wndEditor
->GetPosition();
3752 goodPos
.y
-= coord_adjust
;
3753 m_wndEditor
->Move( goodPos
);
3756 wxWindow
* primaryCtrl
= GetEditorControl();
3757 SetupEventHandling(primaryCtrl
, wxPG_SUBID1
);
3759 // Focus and select all (wxTextCtrl, wxComboBox etc)
3760 if ( flags
& wxPG_SEL_FOCUS
)
3762 primaryCtrl
->SetFocus();
3764 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3770 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3771 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3773 // Get proper id for wndSecondary
3774 m_wndSecId
= m_wndEditor2
->GetId();
3775 wxWindowList children
= m_wndEditor2
->GetChildren();
3776 wxWindowList::iterator node
= children
.begin();
3777 if ( node
!= children
.end() )
3778 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3780 m_wndEditor2
->SetSizeHints(3,3);
3782 #if wxPG_CREATE_CONTROLS_HIDDEN
3783 wxRect sec_rect
= m_wndEditor2
->GetRect();
3784 sec_rect
.y
-= coord_adjust
;
3786 // Fine tuning required to fix "oversized"
3787 // button disappearance bug.
3788 if ( sec_rect
.y
< 0 )
3790 sec_rect
.height
+= sec_rect
.y
;
3793 m_wndEditor2
->SetSize( sec_rect
);
3795 m_wndEditor2
->Show();
3797 SetupEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3799 // If no primary editor, focus to button to allow
3800 // it to interprete ENTER etc.
3801 // NOTE: Due to problems focusing away from it, this
3802 // has been disabled.
3804 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3805 m_wndEditor2->SetFocus();
3809 if ( flags
& wxPG_SEL_FOCUS
)
3810 m_editorFocused
= 1;
3815 // Make sure focus is in grid canvas (important for wxGTK, at least)
3819 EditorsValueWasNotModified();
3821 // If it's inside collapsed section, expand parent, scroll, etc.
3822 // Also, if it was partially visible, scroll it into view.
3823 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3828 #if wxPG_CREATE_CONTROLS_HIDDEN
3829 m_wndEditor
->Thaw();
3831 m_wndEditor
->Show(true);
3838 // Make sure focus is in grid canvas
3842 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3848 // Show help text in status bar.
3849 // (if found and grid not embedded in manager with help box and
3850 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3853 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3855 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3856 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3858 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3860 statusbar
= frame
->GetStatusBar();
3865 const wxString
* pHelpString
= (const wxString
*) NULL
;
3869 pHelpString
= &p
->GetHelpString();
3870 if ( pHelpString
->length() )
3872 // Set help box text.
3873 statusbar
->SetStatusText( *pHelpString
);
3874 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3878 if ( (!pHelpString
|| !pHelpString
->length()) &&
3879 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3881 // Clear help box - but only if it was written
3882 // by us at previous time.
3883 statusbar
->SetStatusText( m_emptyString
);
3884 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3890 m_inDoSelectProperty
= 0;
3892 // call wx event handler (here so that it also occurs on deselection)
3893 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3898 // -----------------------------------------------------------------------
3900 bool wxPropertyGrid::UnfocusEditor()
3902 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3905 if ( !CommitChangesFromEditor(0) )
3909 DrawItem(m_selected
);
3914 // -----------------------------------------------------------------------
3916 // This method is not inline because it called dozens of times
3917 // (i.e. two-arg function calls create smaller code size).
3918 bool wxPropertyGrid::DoClearSelection()
3920 return DoSelectProperty((wxPGProperty
*)NULL
);
3923 // -----------------------------------------------------------------------
3924 // wxPropertyGrid expand/collapse state
3925 // -----------------------------------------------------------------------
3927 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3929 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3931 // If active editor was inside collapsed section, then disable it
3932 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3934 if ( !ClearSelection() )
3938 // Store dont-center-splitter flag 'cause we need to temporarily set it
3939 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3940 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3942 bool res
= m_pState
->DoCollapse(pwc
);
3947 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3949 RecalculateVirtualSize();
3951 // Redraw etc. only if collapsed was visible.
3952 if (pwc
->IsVisible() &&
3954 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3956 // When item is collapsed so that scrollbar would move,
3957 // graphics mess is about (unless we redraw everything).
3962 // Clear dont-center-splitter flag if it wasn't set
3963 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3968 // -----------------------------------------------------------------------
3970 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3972 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3974 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3976 // Store dont-center-splitter flag 'cause we need to temporarily set it
3977 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3978 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3980 bool res
= m_pState
->DoExpand(pwc
);
3985 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3987 RecalculateVirtualSize();
3989 // Redraw etc. only if expanded was visible.
3990 if ( pwc
->IsVisible() && !m_frozen
&&
3991 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3995 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3998 DrawItems(pwc
, NULL
);
4003 // Clear dont-center-splitter flag if it wasn't set
4004 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4009 // -----------------------------------------------------------------------
4011 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4014 return m_pState
->DoHideProperty(p
, hide
, flags
);
4017 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
4020 if ( !ClearSelection() )
4024 m_pState
->DoHideProperty(p
, hide
, flags
);
4026 RecalculateVirtualSize();
4033 // -----------------------------------------------------------------------
4034 // wxPropertyGrid size related methods
4035 // -----------------------------------------------------------------------
4037 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4039 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4043 // If virtual height was changed, then recalculate editor control position(s)
4044 if ( m_pState
->m_vhCalcPending
)
4045 CorrectEditorWidgetPosY();
4047 m_pState
->EnsureVirtualHeight();
4050 int by1
= m_pState
->GetVirtualHeight();
4051 int by2
= m_pState
->GetActualVirtualHeight();
4054 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4055 wxASSERT_MSG( false,
4061 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4063 int x
= m_pState
->m_width
;
4064 int y
= m_pState
->m_virtualHeight
;
4067 GetClientSize(&width
,&height
);
4069 // Now adjust virtual size.
4070 SetVirtualSize(x
, y
);
4076 // Adjust scrollbars
4077 if ( HasVirtualWidth() )
4079 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4080 xPos
= GetScrollPos( wxHORIZONTAL
);
4083 if ( forceXPos
!= -1 )
4086 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4089 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4090 int yPos
= GetScrollPos( wxVERTICAL
);
4092 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4093 xAmount
, yAmount
, xPos
, yPos
, true );
4095 // Must re-get size now
4096 GetClientSize(&width
,&height
);
4098 if ( !HasVirtualWidth() )
4100 m_pState
->SetVirtualWidth(width
);
4107 m_canvas
->SetSize( x
, y
);
4109 m_pState
->CheckColumnWidths();
4112 CorrectEditorWidgetSizeX();
4114 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4117 // -----------------------------------------------------------------------
4119 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4121 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4125 GetClientSize(&width
,&height
);
4130 #if wxPG_DOUBLE_BUFFER
4131 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4133 int dblh
= (m_lineHeight
*2);
4134 if ( !m_doubleBuffer
)
4136 // Create double buffer bitmap to draw on, if none
4137 int w
= (width
>250)?width
:250;
4138 int h
= height
+ dblh
;
4140 m_doubleBuffer
= new wxBitmap( w
, h
);
4144 int w
= m_doubleBuffer
->GetWidth();
4145 int h
= m_doubleBuffer
->GetHeight();
4147 // Double buffer must be large enough
4148 if ( w
< width
|| h
< (height
+dblh
) )
4150 if ( w
< width
) w
= width
;
4151 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4152 delete m_doubleBuffer
;
4153 m_doubleBuffer
= new wxBitmap( w
, h
);
4160 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4161 m_ncWidth
= event
.GetSize().x
;
4165 if ( m_pState
->m_itemsAdded
)
4166 PrepareAfterItemsAdded();
4168 // Without this, virtual size (atleast under wxGTK) will be skewed
4169 RecalculateVirtualSize();
4175 // -----------------------------------------------------------------------
4177 void wxPropertyGrid::SetVirtualWidth( int width
)
4181 // Disable virtual width
4182 width
= GetClientSize().x
;
4183 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4187 // Enable virtual width
4188 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4190 m_pState
->SetVirtualWidth( width
);
4193 // -----------------------------------------------------------------------
4194 // wxPropertyGrid mouse event handling
4195 // -----------------------------------------------------------------------
4197 // selFlags uses same values DoSelectProperty's flags
4198 // Returns true if event was vetoed.
4199 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4201 // Send property grid event of specific type and with specific property
4202 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4203 evt
.SetPropertyGrid(this);
4204 evt
.SetEventObject(m_eventObject
);
4208 evt
.SetCanVeto(true);
4209 evt
.SetupValidationInfo();
4210 m_validationInfo
.m_pValue
= pValue
;
4212 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4214 evtHandler
->ProcessEvent(evt
);
4216 return evt
.WasVetoed();
4219 // -----------------------------------------------------------------------
4221 // Return false if should be skipped
4222 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4226 // Need to set focus?
4227 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4232 wxPropertyGridPageState
* state
= m_pState
;
4234 int splitterHitOffset
;
4235 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4237 wxPGProperty
* p
= DoGetItemAtY(y
);
4241 int depth
= (int)p
->GetDepth() - 1;
4243 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4245 if ( x
>= marginEnds
)
4249 if ( p
->IsCategory() )
4251 // This is category.
4252 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4254 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4256 // Expand, collapse, activate etc. if click on text or left of splitter.
4259 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4264 if ( !DoSelectProperty( p
) )
4267 // On double-click, expand/collapse.
4268 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4270 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4271 else DoExpand( p
, true );
4275 else if ( splitterHit
== -1 )
4278 unsigned int selFlag
= 0;
4279 if ( columnHit
== 1 )
4281 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4282 selFlag
= wxPG_SEL_FOCUS
;
4284 if ( !DoSelectProperty( p
, selFlag
) )
4287 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4289 if ( p
->GetChildCount() && !p
->IsCategory() )
4290 // On double-click, expand/collapse.
4291 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4293 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4294 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4295 else DoExpand( p
, true );
4302 // click on splitter
4303 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4305 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4307 // Double-clicking the splitter causes auto-centering
4308 CenterSplitter( true );
4310 else if ( m_dragStatus
== 0 )
4313 // Begin draggin the splitter
4317 // Changes must be committed here or the
4318 // value won't be drawn correctly
4319 if ( !CommitChangesFromEditor() )
4322 m_wndEditor
->Show ( false );
4325 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4327 m_canvas
->CaptureMouse();
4328 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4332 m_draggedSplitter
= splitterHit
;
4333 m_dragOffset
= splitterHitOffset
;
4335 wxClientDC
dc(m_canvas
);
4337 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4338 // Fixes button disappearance bug
4340 m_wndEditor2
->Show ( false );
4343 m_startingSplitterX
= x
- splitterHitOffset
;
4351 if ( p
->GetChildCount() )
4353 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4355 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4357 int y2
= y
% m_lineHeight
;
4358 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4360 // On click on expander button, expand/collapse
4361 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4362 DoCollapse( p
, true );
4364 DoExpand( p
, true );
4373 // -----------------------------------------------------------------------
4375 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4376 wxMouseEvent
& WXUNUSED(event
) )
4380 // Select property here as well
4381 wxPGProperty
* p
= m_propHover
;
4382 if ( p
!= m_selected
)
4383 DoSelectProperty( p
);
4385 // Send right click event.
4386 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4393 // -----------------------------------------------------------------------
4395 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4396 wxMouseEvent
& WXUNUSED(event
) )
4400 // Select property here as well
4401 wxPGProperty
* p
= m_propHover
;
4403 if ( p
!= m_selected
)
4404 DoSelectProperty( p
);
4406 // Send double-click event.
4407 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4414 // -----------------------------------------------------------------------
4416 #if wxPG_SUPPORT_TOOLTIPS
4418 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4420 if ( tipString
.length() )
4422 m_canvas
->SetToolTip(tipString
);
4426 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4427 m_canvas
->SetToolTip( m_emptyString
);
4429 m_canvas
->SetToolTip( NULL
);
4434 #endif // #if wxPG_SUPPORT_TOOLTIPS
4436 // -----------------------------------------------------------------------
4438 // Return false if should be skipped
4439 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4441 // Safety check (needed because mouse capturing may
4442 // otherwise freeze the control)
4443 if ( m_dragStatus
> 0 && !event
.Dragging() )
4445 HandleMouseUp(x
,y
,event
);
4448 wxPropertyGridPageState
* state
= m_pState
;
4450 int splitterHitOffset
;
4451 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4452 int splitterX
= x
- splitterHitOffset
;
4454 if ( m_dragStatus
> 0 )
4456 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4457 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4460 int newSplitterX
= x
- m_dragOffset
;
4461 int splitterX
= x
- splitterHitOffset
;
4463 // Splitter redraw required?
4464 if ( newSplitterX
!= splitterX
)
4467 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4468 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4469 state
->m_fSplitterX
= (float) newSplitterX
;
4472 CorrectEditorWidgetSizeX();
4486 int ih
= m_lineHeight
;
4489 #if wxPG_SUPPORT_TOOLTIPS
4490 wxPGProperty
* prevHover
= m_propHover
;
4491 unsigned char prevSide
= m_mouseSide
;
4493 int curPropHoverY
= y
- (y
% ih
);
4495 // On which item it hovers
4496 if ( ( !m_propHover
)
4498 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4501 // Mouse moves on another property
4503 m_propHover
= DoGetItemAtY(y
);
4504 m_propHoverY
= curPropHoverY
;
4507 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4510 #if wxPG_SUPPORT_TOOLTIPS
4511 // Store which side we are on
4513 if ( columnHit
== 1 )
4515 else if ( columnHit
== 0 )
4519 // If tooltips are enabled, show label or value as a tip
4520 // in case it doesn't otherwise show in full length.
4522 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4524 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4526 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4528 if ( m_propHover
&& !m_propHover
->IsCategory() )
4531 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4533 // Show help string as a tooltip
4534 wxString tipString
= m_propHover
->GetHelpString();
4536 SetToolTip(tipString
);
4540 // Show cropped value string as a tooltip
4544 if ( m_mouseSide
== 1 )
4546 tipString
= m_propHover
->m_label
;
4547 space
= splitterX
-m_marginWidth
-3;
4549 else if ( m_mouseSide
== 2 )
4551 tipString
= m_propHover
->GetDisplayedString();
4553 space
= m_width
- splitterX
;
4554 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4555 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4561 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4564 SetToolTip( tipString
);
4571 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4572 m_canvas
->SetToolTip( m_emptyString
);
4574 m_canvas
->SetToolTip( NULL
);
4585 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4586 m_canvas
->SetToolTip( m_emptyString
);
4588 m_canvas
->SetToolTip( NULL
);
4596 if ( splitterHit
== -1 ||
4598 HasFlag(wxPG_STATIC_SPLITTER
) )
4600 // hovering on something else
4601 if ( m_curcursor
!= wxCURSOR_ARROW
)
4602 CustomSetCursor( wxCURSOR_ARROW
);
4606 // Do not allow splitter cursor on caption items.
4607 // (also not if we were dragging and its started
4608 // outside the splitter region)
4611 !m_propHover
->IsCategory() &&
4615 // hovering on splitter
4617 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4618 // reliably detected.
4619 //if ( m_curcursor != wxCURSOR_SIZEWE )
4620 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4626 // hovering on something else
4627 if ( m_curcursor
!= wxCURSOR_ARROW
)
4628 CustomSetCursor( wxCURSOR_ARROW
);
4635 // -----------------------------------------------------------------------
4637 // Also handles Leaving event
4638 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4639 wxMouseEvent
&WXUNUSED(event
) )
4641 wxPropertyGridPageState
* state
= m_pState
;
4645 int splitterHitOffset
;
4646 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4648 // No event type check - basicly calling this method should
4649 // just stop dragging.
4650 // Left up after dragged?
4651 if ( m_dragStatus
>= 1 )
4654 // End Splitter Dragging
4656 // DO NOT ENABLE FOLLOWING LINE!
4657 // (it is only here as a reminder to not to do it)
4660 // Disable splitter auto-centering
4661 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4663 // This is necessary to return cursor
4664 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4666 m_canvas
->ReleaseMouse();
4667 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4670 // Set back the default cursor, if necessary
4671 if ( splitterHit
== -1 ||
4674 CustomSetCursor( wxCURSOR_ARROW
);
4679 // Control background needs to be cleared
4680 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4681 DrawItem( m_selected
);
4685 m_wndEditor
->Show ( true );
4688 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4689 // Fixes button disappearance bug
4691 m_wndEditor2
->Show ( true );
4694 // This clears the focus.
4695 m_editorFocused
= 0;
4701 // -----------------------------------------------------------------------
4703 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4705 int splitterX
= GetSplitterPosition();
4708 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4712 wxWindow
* wnd
= m_wndEditor
;
4714 // Hide popup on clicks
4715 if ( event
.GetEventType() != wxEVT_MOTION
)
4716 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4718 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4724 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4726 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4727 ux
>= (r
.x
+r
.width
) ||
4729 event
.m_y
>= (r
.y
+r
.height
)
4739 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4744 // -----------------------------------------------------------------------
4746 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4749 if ( OnMouseCommon( event
, &x
, &y
) )
4751 HandleMouseClick(x
,y
,event
);
4756 // -----------------------------------------------------------------------
4758 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4761 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4762 HandleMouseRightClick(x
,y
,event
);
4766 // -----------------------------------------------------------------------
4768 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4770 // Always run standard mouse-down handler as well
4771 OnMouseClick(event
);
4774 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4775 HandleMouseDoubleClick(x
,y
,event
);
4779 // -----------------------------------------------------------------------
4781 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4784 if ( OnMouseCommon( event
, &x
, &y
) )
4786 HandleMouseMove(x
,y
,event
);
4791 // -----------------------------------------------------------------------
4793 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4795 // Called when mouse moves in the empty space below the properties.
4796 CustomSetCursor( wxCURSOR_ARROW
);
4799 // -----------------------------------------------------------------------
4801 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4804 if ( OnMouseCommon( event
, &x
, &y
) )
4806 HandleMouseUp(x
,y
,event
);
4811 // -----------------------------------------------------------------------
4813 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4815 // This may get called from child control as well, so event's
4816 // mouse position cannot be relied on.
4818 if ( event
.Entering() )
4820 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4822 // TODO: Fix this (detect parent and only do
4823 // cursor trick if it is a manager).
4824 wxASSERT( GetParent() );
4825 GetParent()->SetCursor(wxNullCursor
);
4827 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4830 GetParent()->SetCursor(wxNullCursor
);
4832 else if ( event
.Leaving() )
4834 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4835 m_canvas
->SetCursor( wxNullCursor
);
4837 // Get real cursor position
4838 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4840 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4843 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4845 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4849 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4857 // -----------------------------------------------------------------------
4859 // Common code used by various OnMouseXXXChild methods.
4860 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4862 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4863 wxASSERT( topCtrlWnd
);
4865 event
.GetPosition(&x
,&y
);
4867 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4869 int splitterX
= GetSplitterPosition();
4871 wxRect r
= topCtrlWnd
->GetRect();
4872 if ( !m_dragStatus
&&
4873 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4874 y
>= 0 && y
< r
.height \
4877 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4882 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4889 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4892 if ( OnMouseChildCommon(event
,&x
,&y
) )
4894 bool res
= HandleMouseClick(x
,y
,event
);
4895 if ( !res
) event
.Skip();
4899 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4902 wxASSERT( m_wndEditor
);
4903 // These coords may not be exact (about +-2),
4904 // but that should not matter (right click is about item, not position).
4905 wxPoint pt
= m_wndEditor
->GetPosition();
4906 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4907 wxASSERT( m_selected
);
4908 m_propHover
= m_selected
;
4909 bool res
= HandleMouseRightClick(x
,y
,event
);
4910 if ( !res
) event
.Skip();
4913 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4916 if ( OnMouseChildCommon(event
,&x
,&y
) )
4918 bool res
= HandleMouseMove(x
,y
,event
);
4919 if ( !res
) event
.Skip();
4923 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4926 if ( OnMouseChildCommon(event
,&x
,&y
) )
4928 bool res
= HandleMouseUp(x
,y
,event
);
4929 if ( !res
) event
.Skip();
4933 // -----------------------------------------------------------------------
4934 // wxPropertyGrid keyboard event handling
4935 // -----------------------------------------------------------------------
4937 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4939 wxNavigationKeyEvent evt
;
4940 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4941 (dir
?wxNavigationKeyEvent::IsForward
:
4942 wxNavigationKeyEvent::IsBackward
));
4943 evt
.SetEventObject(this);
4944 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4948 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4950 // Translates wxKeyEvent to wxPG_ACTION_XXX
4952 int keycode
= event
.GetKeyCode();
4953 int modifiers
= event
.GetModifiers();
4955 wxASSERT( !(modifiers
&~(0xFFFF)) );
4957 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4959 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4961 if ( it
== m_actionTriggers
.end() )
4966 int second
= (it
->second
>>16) & 0xFFFF;
4970 return (it
->second
& 0xFFFF);
4973 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4975 wxASSERT( !(modifiers
&~(0xFFFF)) );
4977 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4979 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4981 if ( it
!= m_actionTriggers
.end() )
4983 // This key combination is already used
4985 // Can add secondary?
4986 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4987 wxT("You can only add up to two separate actions per key combination.") );
4989 action
= it
->second
| (action
<<16);
4992 m_actionTriggers
[hashMapKey
] = action
;
4995 void wxPropertyGrid::ClearActionTriggers( int action
)
4997 wxPGHashMapI2I::iterator it
;
4999 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
5001 if ( it
->second
== action
)
5003 m_actionTriggers
.erase(it
);
5008 static void CopyTextToClipboard( const wxString
& text
)
5010 if ( wxTheClipboard
->Open() )
5012 // This data objects are held by the clipboard,
5013 // so do not delete them in the app.
5014 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
5015 wxTheClipboard
->Close();
5019 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5022 // Handles key event when editor control is not focused.
5025 wxASSERT( !m_frozen
);
5029 // Travelsal between items, collapsing/expanding, etc.
5030 int keycode
= event
.GetKeyCode();
5032 if ( keycode
== WXK_TAB
)
5034 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5038 // Ignore Alt and Control when they are down alone
5039 if ( keycode
== WXK_ALT
||
5040 keycode
== WXK_CONTROL
)
5047 int action
= KeyEventToActions(event
, &secondAction
);
5053 if ( ButtonTriggerKeyTest(event
) )
5056 wxPGProperty
* p
= m_selected
;
5058 if ( action
== wxPG_ACTION_COPY
)
5060 CopyTextToClipboard(p
->GetDisplayedString());
5064 // Travel and expand/collapse
5067 if ( p
->GetChildCount() &&
5068 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5071 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5073 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5076 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5078 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5085 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5089 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5100 if ( selectDir
>= -1 )
5102 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5104 DoSelectProperty(p
);
5110 // If nothing was selected, select the first item now
5111 // (or navigate out of tab).
5112 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5114 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5115 if ( p
) DoSelectProperty(p
);
5120 // -----------------------------------------------------------------------
5122 // Potentially handles a keyboard event for editor controls.
5123 // Returns false if event should *not* be skipped (on true it can
5124 // be optionally skipped).
5125 // Basicly, false means that SelectProperty was called (or was about
5126 // to be called, if canDestroy was false).
5127 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5131 if ( !m_selected
|| !m_wndEditor
)
5136 int action
= KeyEventToAction(event
);
5139 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5142 // Esc cancels any changes
5143 if ( IsEditorsValueModified() )
5145 EditorsValueWasNotModified();
5147 // Update the control as well
5148 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5150 m_selected
->GetDisplayedString() );
5153 OnValidationFailureReset(m_selected
);
5159 else if ( action
== wxPG_ACTION_COPY
)
5161 // NB: There is some problem with getting native cut-copy-paste keys to go through
5162 // for embedded editor wxTextCtrl. This is why we emulate.
5164 wxTextCtrl
* tc
= GetEditorTextCtrl();
5167 wxString sel
= tc
->GetStringSelection();
5169 CopyTextToClipboard(sel
);
5173 CopyTextToClipboard(m_selected
->GetDisplayedString());
5176 else if ( action
== wxPG_ACTION_CUT
)
5178 wxTextCtrl
* tc
= GetEditorTextCtrl();
5182 tc
->GetSelection(&from
, &to
);
5185 CopyTextToClipboard(tc
->GetStringSelection());
5186 tc
->Remove(from
, to
);
5190 else if ( action
== wxPG_ACTION_PASTE
)
5192 wxTextCtrl
* tc
= GetEditorTextCtrl();
5195 if (wxTheClipboard
->Open())
5197 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5199 wxTextDataObject data
;
5200 wxTheClipboard
->GetData( data
);
5202 tc
->GetSelection(&from
, &to
);
5205 tc
->Remove(from
, to
);
5206 tc
->WriteText(data
.GetText());
5210 tc
->WriteText(data
.GetText());
5213 wxTheClipboard
->Close();
5221 // -----------------------------------------------------------------------
5223 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5227 // Events to editor controls should get relayed here.
5229 wxWindow
* focused
= wxWindow::FindFocus();
5231 wxWindow
* primaryCtrl
= GetEditorControl();
5234 (focused
==primaryCtrl
5235 || m_editorFocused
) )
5237 // Child key must be processed here, since it can
5238 // destroy the control which is referred by its own
5240 HandleChildKey( event
);
5243 HandleKeyEvent( event
);
5246 // -----------------------------------------------------------------------
5248 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5250 m_keyComboConsumed
= 0;
5255 // -----------------------------------------------------------------------
5257 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5259 // Ignore events that occur very close to focus set
5260 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5262 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5267 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5269 int dir
= event
.GetDirection()?1:-1;
5273 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5275 wxWindow
* focused
= wxWindow::FindFocus();
5277 wxWindow
* wndToCheck
= GetEditorControl();
5279 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5280 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5282 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5283 if ( comboTextCtrl
)
5284 wndToCheck
= comboTextCtrl
;
5288 // Because of problems navigating from wxButton, do not go to it.
5291 // No primary, use secondary
5292 wndToCheck = m_wndEditor2;
5294 // If it has editor button, focus to it after the primary editor.
5295 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5296 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5297 // have somewhat debugged in window.cpp itself).
5298 else if ( focused == wndToCheck &&
5300 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5302 wndToCheck = m_wndEditor2;
5303 wxLogDebug(wxT("Exp1"));
5307 if ( focused
!= wndToCheck
&&
5310 wndToCheck
->SetFocus();
5312 // Select all text in wxTextCtrl etc.
5313 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5314 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5316 m_editorFocused
= 1;
5323 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5327 // This allows preventing NavigateOut to occur
5328 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5337 // -----------------------------------------------------------------------
5339 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5341 int keycode
= event
.GetKeyCode();
5343 // Does the keycode trigger button?
5344 if ( keycode
== m_pushButKeyCode
&&
5346 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5347 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5349 m_keyComboConsumed
= 1;
5351 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5352 GetEventHandler()->AddPendingEvent(evt
);
5359 // -----------------------------------------------------------------------
5361 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5363 int keycode
= event
.GetKeyCode();
5365 // Ignore Alt and Control when they are down alone
5366 if ( keycode
== WXK_ALT
||
5367 keycode
== WXK_CONTROL
)
5373 if ( ButtonTriggerKeyTest(event
) )
5376 if ( HandleChildKey(event
) == true )
5379 GetEventHandler()->AddPendingEvent(event
);
5382 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5384 m_keyComboConsumed
= 0;
5386 GetEventHandler()->AddPendingEvent(event
);
5391 // -----------------------------------------------------------------------
5392 // wxPropertyGrid miscellaneous event handling
5393 // -----------------------------------------------------------------------
5395 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5398 // Check if the focus is in this control or one of its children
5399 wxWindow
* newFocused
= wxWindow::FindFocus();
5401 if ( newFocused
!= m_curFocused
)
5402 HandleFocusChange( newFocused
);
5405 // Called by focus event handlers. newFocused is the window that becomes focused.
5406 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5408 unsigned int oldFlags
= m_iFlags
;
5410 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5412 wxWindow
* parent
= newFocused
;
5414 // This must be one of nextFocus' parents.
5417 // Use m_eventObject, which is either wxPropertyGrid or
5418 // wxPropertyGridManager, as appropriate.
5419 if ( parent
== m_eventObject
)
5421 m_iFlags
|= wxPG_FL_FOCUSED
;
5424 parent
= parent
->GetParent();
5427 m_curFocused
= newFocused
;
5429 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5430 (oldFlags
& wxPG_FL_FOCUSED
) )
5432 // On each focus kill, mark the next nav key event
5433 // to be ignored (can't do on set focus since the
5434 // event would occur before it).
5435 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5437 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5439 // Need to store changed value
5440 CommitChangesFromEditor();
5446 // Preliminary code for tab-order respecting
5447 // tab-traversal (but should be moved to
5450 wxWindow* prevFocus = event.GetWindow();
5451 wxWindow* useThis = this;
5452 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5453 useThis = GetParent();
5456 prevFocus->GetParent() == useThis->GetParent() )
5458 wxList& children = useThis->GetParent()->GetChildren();
5460 wxNode* node = children.Find(prevFocus);
5462 if ( node->GetNext() &&
5463 useThis == node->GetNext()->GetData() )
5464 DoSelectProperty(GetFirst());
5465 else if ( node->GetPrevious () &&
5466 useThis == node->GetPrevious()->GetData() )
5467 DoSelectProperty(GetLastProperty());
5472 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5476 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5477 DrawItem( m_selected
);
5481 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5483 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5484 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5485 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5486 //else if ( event.GetWindow() )
5488 HandleFocusChange(event
.GetWindow());
5493 // -----------------------------------------------------------------------
5495 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5497 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5500 // event.Skip() being commented out is aworkaround for bug reported
5501 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5505 // -----------------------------------------------------------------------
5507 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5509 m_iFlags
|= wxPG_FL_SCROLLED
;
5514 // -----------------------------------------------------------------------
5516 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5518 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5520 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5524 // -----------------------------------------------------------------------
5525 // Property editor related functions
5526 // -----------------------------------------------------------------------
5528 // noDefCheck = true prevents infinite recursion.
5529 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorclass
,
5530 const wxString
& name
,
5533 wxASSERT( editorclass
);
5535 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5536 RegisterDefaultEditors();
5538 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorclass
;
5543 // Registers all default editor classes
5544 void wxPropertyGrid::RegisterDefaultEditors()
5546 wxPGRegisterDefaultEditorClass( TextCtrl
);
5547 wxPGRegisterDefaultEditorClass( Choice
);
5548 wxPGRegisterDefaultEditorClass( ComboBox
);
5549 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5550 #if wxPG_INCLUDE_CHECKBOX
5551 wxPGRegisterDefaultEditorClass( CheckBox
);
5553 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5555 // Register SpinCtrl etc. editors before use
5556 RegisterAdditionalEditors();
5559 // -----------------------------------------------------------------------
5560 // wxPGStringTokenizer
5561 // Needed to handle C-style string lists (e.g. "str1" "str2")
5562 // -----------------------------------------------------------------------
5564 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5565 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5569 wxPGStringTokenizer::~wxPGStringTokenizer()
5573 bool wxPGStringTokenizer::HasMoreTokens()
5575 const wxString
& str
= *m_str
;
5577 wxString::const_iterator i
= m_curPos
;
5579 wxUniChar delim
= m_delimeter
;
5581 wxUniChar prev_a
= wxT('\0');
5583 bool inToken
= false;
5585 while ( i
!= str
.end() )
5594 m_readyToken
.clear();
5599 if ( prev_a
!= wxT('\\') )
5603 if ( a
!= wxT('\\') )
5623 m_curPos
= str
.end();
5631 wxString
wxPGStringTokenizer::GetNextToken()
5633 return m_readyToken
;
5636 // -----------------------------------------------------------------------
5638 // -----------------------------------------------------------------------
5640 wxPGChoiceEntry::wxPGChoiceEntry()
5641 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5645 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5646 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5647 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5651 // -----------------------------------------------------------------------
5653 // -----------------------------------------------------------------------
5655 wxPGChoicesData::wxPGChoicesData()
5660 wxPGChoicesData::~wxPGChoicesData()
5665 void wxPGChoicesData::Clear()
5669 for ( i
=0; i
<m_items
.size(); i
++ )
5681 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5683 wxASSERT( m_items
.size() == 0 );
5687 for ( i
=0; i
<data
->GetCount(); i
++ )
5688 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5691 // -----------------------------------------------------------------------
5693 // -----------------------------------------------------------------------
5695 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5699 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5700 m_data
->Insert( -1, p
);
5704 // -----------------------------------------------------------------------
5706 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5710 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5711 p
->SetBitmap(bitmap
);
5712 m_data
->Insert( -1, p
);
5716 // -----------------------------------------------------------------------
5718 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5722 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5723 m_data
->Insert(index
, p
);
5727 // -----------------------------------------------------------------------
5729 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5733 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5734 m_data
->Insert( index
, p
);
5738 // -----------------------------------------------------------------------
5740 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5746 while ( index
< GetCount() )
5748 int cmpRes
= GetLabel(index
).Cmp(label
);
5754 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5755 m_data
->Insert( index
, p
);
5759 // -----------------------------------------------------------------------
5761 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5765 unsigned int itemcount
= 0;
5766 const wxChar
** p
= &labels
[0];
5767 while ( *p
) { p
++; itemcount
++; }
5770 for ( i
= 0; i
< itemcount
; i
++ )
5772 int value
= wxPG_INVALID_VALUE
;
5775 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5779 // -----------------------------------------------------------------------
5781 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5786 unsigned int itemcount
= arr
.size();
5788 for ( i
= 0; i
< itemcount
; i
++ )
5790 int value
= wxPG_INVALID_VALUE
;
5793 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5797 // -----------------------------------------------------------------------
5799 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5804 unsigned int itemcount
= arr
.size();
5806 for ( i
= 0; i
< itemcount
; i
++ )
5808 int value
= wxPG_INVALID_VALUE
;
5809 if ( &arrint
&& arrint
.size() )
5811 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5815 // -----------------------------------------------------------------------
5817 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5819 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5821 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5822 delete m_data
->Item(i
);
5823 m_data
->m_items
.RemoveAt(nIndex
, count
);
5826 // -----------------------------------------------------------------------
5828 int wxPGChoices::Index( const wxString
& str
) const
5833 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5835 if ( m_data
->Item(i
)->GetText() == str
)
5842 // -----------------------------------------------------------------------
5844 int wxPGChoices::Index( int val
) const
5849 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5851 if ( m_data
->Item(i
)->GetValue() == val
)
5858 // -----------------------------------------------------------------------
5860 wxArrayString
wxPGChoices::GetLabels() const
5865 if ( this && IsOk() )
5866 for ( i
=0; i
<GetCount(); i
++ )
5867 arr
.push_back(GetLabel(i
));
5872 // -----------------------------------------------------------------------
5874 bool wxPGChoices::HasValues() const
5879 // -----------------------------------------------------------------------
5881 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5888 for ( i
=0; i
< strings
.size(); i
++ )
5890 int index
= Index(strings
[i
]);
5892 arr
.Add(GetValue(index
));
5894 arr
.Add(wxPG_INVALID_VALUE
);
5901 // -----------------------------------------------------------------------
5903 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5904 wxArrayString
* unmatched
) const
5911 for ( i
=0; i
< strings
.size(); i
++ )
5913 const wxString
& str
= strings
[i
];
5914 int index
= Index(str
);
5917 else if ( unmatched
)
5918 unmatched
->Add(str
);
5925 // -----------------------------------------------------------------------
5927 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5931 if ( data
!= wxPGChoicesEmptyData
)
5938 // -----------------------------------------------------------------------
5940 void wxPGChoices::Init()
5942 m_data
= wxPGChoicesEmptyData
;
5945 // -----------------------------------------------------------------------
5947 void wxPGChoices::Free()
5949 if ( m_data
!= wxPGChoicesEmptyData
)
5952 m_data
= wxPGChoicesEmptyData
;
5956 // -----------------------------------------------------------------------
5957 // wxPropertyGridEvent
5958 // -----------------------------------------------------------------------
5960 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5963 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5964 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5965 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5966 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5967 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5968 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5969 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5970 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5971 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5974 // -----------------------------------------------------------------------
5976 void wxPropertyGridEvent::Init()
5978 m_validationInfo
= NULL
;
5980 m_wasVetoed
= false;
5983 // -----------------------------------------------------------------------
5985 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5986 : wxCommandEvent(commandType
,id
)
5992 // -----------------------------------------------------------------------
5994 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5995 : wxCommandEvent(event
)
5997 m_eventType
= event
.GetEventType();
5998 m_eventObject
= event
.m_eventObject
;
6000 m_property
= event
.m_property
;
6001 m_validationInfo
= event
.m_validationInfo
;
6002 m_canVeto
= event
.m_canVeto
;
6003 m_wasVetoed
= event
.m_wasVetoed
;
6006 // -----------------------------------------------------------------------
6008 wxPropertyGridEvent::~wxPropertyGridEvent()
6012 // -----------------------------------------------------------------------
6014 wxEvent
* wxPropertyGridEvent::Clone() const
6016 return new wxPropertyGridEvent( *this );
6019 // -----------------------------------------------------------------------
6020 // wxPropertyGridPopulator
6021 // -----------------------------------------------------------------------
6023 wxPropertyGridPopulator::wxPropertyGridPopulator()
6027 wxPGGlobalVars
->m_offline
++;
6030 // -----------------------------------------------------------------------
6032 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6035 m_propHierarchy
.clear();
6038 // -----------------------------------------------------------------------
6040 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6046 // -----------------------------------------------------------------------
6048 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6051 // Free unused sets of choices
6052 wxPGHashMapS2P::iterator it
;
6054 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6056 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6063 m_pg
->GetPanel()->Refresh();
6065 wxPGGlobalVars
->m_offline
--;
6068 // -----------------------------------------------------------------------
6070 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6071 const wxString
& propLabel
,
6072 const wxString
& propName
,
6073 const wxString
* propValue
,
6074 wxPGChoices
* pChoices
)
6076 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6077 wxPGProperty
* parent
= GetCurParent();
6079 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6081 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6085 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6087 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6091 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6093 property
->SetLabel(propLabel
);
6094 property
->DoSetName(propName
);
6096 if ( pChoices
&& pChoices
->IsOk() )
6097 property
->SetChoices(*pChoices
);
6099 m_state
->DoInsert(parent
, -1, property
);
6102 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6107 // -----------------------------------------------------------------------
6109 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6111 m_propHierarchy
.push_back(property
);
6112 DoScanForChildren();
6113 m_propHierarchy
.pop_back();
6116 // -----------------------------------------------------------------------
6118 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6119 const wxString
& idString
)
6121 wxPGChoices choices
;
6124 if ( choicesString
[0] == wxT('@') )
6126 wxString ids
= choicesString
.substr(1);
6127 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6128 if ( it
== m_dictIdChoices
.end() )
6129 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6131 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6136 if ( idString
.length() )
6138 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6139 if ( it
!= m_dictIdChoices
.end() )
6141 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6148 // Parse choices string
6149 wxString::const_iterator it
= choicesString
.begin();
6153 bool labelValid
= false;
6155 for ( ; it
!= choicesString
.end(); it
++ )
6161 if ( c
== wxT('"') )
6166 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6167 choices
.Add(label
, l
);
6170 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6175 else if ( c
== wxT('=') )
6182 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6189 if ( c
== wxT('"') )
6202 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6203 choices
.Add(label
, l
);
6206 if ( !choices
.IsOk() )
6208 choices
.EnsureData();
6212 if ( idString
.length() )
6213 m_dictIdChoices
[idString
] = choices
.GetData();
6220 // -----------------------------------------------------------------------
6222 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6224 if ( s
.Last() == wxT('%') )
6226 wxString s2
= s
.substr(0,s
.length()-1);
6228 if ( s2
.ToLong(&val
, 10) )
6230 *pval
= (val
*max
)/100;
6236 return s
.ToLong(pval
, 10);
6239 // -----------------------------------------------------------------------
6241 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6242 const wxString
& type
,
6243 const wxString
& value
)
6245 int l
= m_propHierarchy
.size();
6249 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6250 wxString valuel
= value
.Lower();
6253 if ( type
.length() == 0 )
6258 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6260 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6262 else if ( value
.ToLong(&v
, 0) )
6269 if ( type
== wxT("string") )
6273 else if ( type
== wxT("int") )
6276 value
.ToLong(&v
, 0);
6279 else if ( type
== wxT("bool") )
6281 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6288 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6293 p
->SetAttribute( name
, variant
);
6298 // -----------------------------------------------------------------------
6300 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6302 wxLogError(_("Error in resource: %s"),msg
.c_str());
6305 // -----------------------------------------------------------------------
6307 #endif // wxUSE_PROPGRID