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"
43 #include "wx/layout.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
47 #include "wx/statusbr.h"
53 // This define is necessary to prevent macro clearing
54 #define __wxPG_SOURCE_FILE__
56 #include <wx/propgrid/propgrid.h>
57 #include <wx/propgrid/editors.h>
59 #if wxPG_USE_RENDERER_NATIVE
60 #include <wx/renderer.h>
63 #include <wx/odcombo.h>
66 #include "wx/dcbuffer.h"
67 #include <wx/clipbrd.h>
68 #include <wx/dataobj.h>
71 #include <wx/msw/private.h>
76 // Two pics for the expand / collapse buttons.
77 // Files are not supplied with this project (since it is
78 // recommended to use either custom or native rendering).
79 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
80 // and copy xpm files from archive to wxPropertyGrid src directory
81 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
82 // and set wxPG_USE_RENDERER_NATIVE to 0).
83 #ifndef wxPG_ICON_WIDTH
84 #if defined(__WXMAC__)
85 #include "mac_collapse.xpm"
86 #include "mac_expand.xpm"
87 #elif defined(__WXGTK__)
88 #include "linux_collapse.xpm"
89 #include "linux_expand.xpm"
91 #include "default_collapse.xpm"
92 #include "default_expand.xpm"
97 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
98 #define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
99 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
100 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
101 #define wxPG_YSPACING_MIN 1
102 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
103 // but causes normal combobox to spill out under MSW
105 #define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
107 #define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
108 // Must be larger than largest control border
112 #define wxPG_DEFAULT_CURSOR wxNullCursor
115 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
117 #define wxPG_HIDER_BUTTON_HEIGHT 25
119 #define wxPG_PIXELS_PER_UNIT m_lineHeight
121 #ifdef wxPG_ICON_WIDTH
122 #define m_iconHeight m_iconWidth
125 #define wxPG_TOOLTIP_DELAY 1000
127 // -----------------------------------------------------------------------
130 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
132 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
135 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
138 // -----------------------------------------------------------------------
140 const wxChar
*wxPropertyGridNameStr
= wxT("wxPropertyGrid");
142 // -----------------------------------------------------------------------
143 // Statics in one class for easy destruction.
144 // NB: We prefer to use wxModule, as it offers more consistent behavior
145 // across platforms. However, for those rare problem situations, we
146 // also need to offer option to use simpler approach.
147 // -----------------------------------------------------------------------
149 #ifndef wxPG_USE_WXMODULE
150 #define wxPG_USE_WXMODULE 1
153 #if wxPG_USE_WXMODULE
155 #include <wx/module.h>
157 class wxPGGlobalVarsClassManager
: public wxModule
159 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
161 wxPGGlobalVarsClassManager() {}
162 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
163 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
166 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
168 #else // !wxPG_USE_WXMODULE
170 class wxPGGlobalVarsClassManager
173 wxPGGlobalVarsClassManager() {}
174 ~wxPGGlobalVarsClassManager() { delete wxPGGlobalVars
; }
177 static wxPGGlobalVarsClassManager gs_pgGlobalVarsClassManager
;
182 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
185 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
187 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
189 m_boolChoices
.Add(_("False"));
190 m_boolChoices
.Add(_("True"));
192 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
194 m_defaultRenderer
= new wxPGDefaultRenderer();
196 m_autoGetTranslation
= false;
204 // Prepare some shared variants
205 m_vEmptyString
= wxString();
207 m_vMinusOne
= (long) -1;
211 // Prepare cached string constants
212 m_strstring
= wxS("string");
213 m_strlong
= wxS("long");
214 m_strbool
= wxS("bool");
215 m_strlist
= wxS("list");
216 m_strMin
= wxS("Min");
217 m_strMax
= wxS("Max");
218 m_strUnits
= wxS("Units");
219 m_strInlineHelp
= wxS("InlineHelp");
227 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
231 delete m_defaultRenderer
;
233 // This will always have one ref
234 delete m_fontFamilyChoices
;
237 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
238 delete ((wxValidator
*)m_arrValidators
[i
]);
242 // Destroy value type class instances.
243 wxPGHashMapS2P::iterator vt_it
;
245 // Destroy editor class instances.
246 // iterate over all the elements in the class
247 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
249 delete ((wxPGEditor
*)vt_it
->second
);
252 delete wxPGProperty::sm_wxPG_LABEL
;
255 // -----------------------------------------------------------------------
257 // -----------------------------------------------------------------------
260 // This class is a wxBrush derivative used in the background colour
261 // brush cache. It adds wxPG-type colour-in-long to the class.
262 // JMS: Yes I know wxBrush doesn't actually hold the value (refcounted
263 // object does), but this is simpler implementation and equally
267 class wxPGBrush
: public wxBrush
270 wxPGBrush( const wxColour
& colour
);
272 virtual ~wxPGBrush() { }
273 void SetColour2( const wxColour
& colour
);
274 inline long GetColourAsLong() const { return m_colAsLong
; }
280 void wxPGBrush::SetColour2( const wxColour
& colour
)
282 wxBrush::SetColour(colour
);
283 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
287 wxPGBrush::wxPGBrush() : wxBrush()
293 wxPGBrush::wxPGBrush( const wxColour
& colour
) : wxBrush(colour
)
295 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
299 // -----------------------------------------------------------------------
301 // -----------------------------------------------------------------------
304 // Same as wxPGBrush, but for wxColour instead.
307 class wxPGColour
: public wxColour
310 wxPGColour( const wxColour
& colour
);
312 virtual ~wxPGColour() { }
313 void SetColour2( const wxColour
& colour
);
314 inline long GetColourAsLong() const { return m_colAsLong
; }
320 void wxPGColour::SetColour2( const wxColour
& colour
)
323 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
327 wxPGColour::wxPGColour() : wxColour()
333 wxPGColour::wxPGColour( const wxColour
& colour
) : wxColour(colour
)
335 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
339 // -----------------------------------------------------------------------
341 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
342 // and tries to commit property value.
343 // -----------------------------------------------------------------------
345 class wxPGTLWHandler
: public wxEvtHandler
349 wxPGTLWHandler( wxPropertyGrid
* pg
)
357 void OnClose( wxCloseEvent
& event
)
359 // ClearSelection forces value validation/commit.
360 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
370 wxPropertyGrid
* m_pg
;
372 DECLARE_EVENT_TABLE()
375 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
376 EVT_CLOSE(wxPGTLWHandler::OnClose
)
379 // -----------------------------------------------------------------------
381 // -----------------------------------------------------------------------
384 // wxPGCanvas acts as a graphics sub-window of the
385 // wxScrolledWindow that wxPropertyGrid is.
387 class wxPGCanvas
: public wxPanel
390 wxPGCanvas() : wxPanel()
393 virtual ~wxPGCanvas() { }
396 void OnMouseMove( wxMouseEvent
&event
)
398 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
399 pg
->OnMouseMove( event
);
402 void OnMouseClick( wxMouseEvent
&event
)
404 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
405 pg
->OnMouseClick( event
);
408 void OnMouseUp( wxMouseEvent
&event
)
410 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
411 pg
->OnMouseUp( event
);
414 void OnMouseRightClick( wxMouseEvent
&event
)
416 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
417 pg
->OnMouseRightClick( event
);
420 void OnMouseDoubleClick( wxMouseEvent
&event
)
422 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
423 pg
->OnMouseDoubleClick( event
);
426 void OnKey( wxKeyEvent
& event
)
428 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
432 void OnKeyUp( wxKeyEvent
& event
)
434 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
435 pg
->OnKeyUp( event
);
438 void OnNavigationKey( wxNavigationKeyEvent
& event
)
440 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
441 pg
->OnNavigationKey( event
);
444 void OnPaint( wxPaintEvent
& event
);
447 DECLARE_EVENT_TABLE()
451 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
452 EVT_MOTION(wxPGCanvas::OnMouseMove
)
453 EVT_PAINT(wxPGCanvas::OnPaint
)
454 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
455 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
456 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
457 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
458 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
459 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
460 EVT_CHAR(wxPGCanvas::OnKey
)
461 EVT_NAVIGATION_KEY(wxPGCanvas::OnNavigationKey
)
465 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
467 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
468 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
472 // Don't paint after destruction has begun
473 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
476 // Update everything inside the box
477 wxRect r
= GetUpdateRegion().GetBox();
479 // Repaint this rectangle
480 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
482 // We assume that the size set when grid is shown
483 // is what is desired.
484 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
487 // -----------------------------------------------------------------------
489 // -----------------------------------------------------------------------
491 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
493 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
494 EVT_IDLE(wxPropertyGrid::OnIdle
)
495 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
496 EVT_PAINT(wxPropertyGrid::OnPaint
)
497 EVT_SIZE(wxPropertyGrid::OnResize
)
498 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
499 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
500 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
501 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
502 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
503 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
504 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
505 EVT_TEXT_ENTER(wxPG_SUBID1
,wxPropertyGrid::OnCustomEditorEvent
)
506 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
510 // -----------------------------------------------------------------------
512 wxPropertyGrid::wxPropertyGrid()
518 // -----------------------------------------------------------------------
520 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
529 Create(parent
,id
,pos
,size
,style
,name
);
532 // -----------------------------------------------------------------------
534 bool wxPropertyGrid::Create( wxWindow
*parent
,
542 if ( !(style
&wxBORDER_MASK
) )
543 style
|= wxSIMPLE_BORDER
;
548 // This prevents crash under Win2K, but still
549 // enables keyboard navigation
550 if ( style
& wxTAB_TRAVERSAL
)
552 style
&= ~(wxTAB_TRAVERSAL
);
553 style
|= wxWANTS_CHARS
;
556 if ( style
& wxTAB_TRAVERSAL
)
557 style
|= wxWANTS_CHARS
;
560 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
567 // -----------------------------------------------------------------------
570 // Initialize values to defaults
572 void wxPropertyGrid::Init1()
574 #if !wxPG_USE_WXMODULE
575 if ( !wxPGGlobalVars
)
576 wxPGGlobalVars
= new wxPGGlobalVarsClass();
579 // Register editor classes, if necessary.
580 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
581 RegisterDefaultEditors();
584 m_pState
= (wxPropertyGridPageState
*) NULL
;
585 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
586 m_selected
= (wxPGProperty
*) NULL
;
588 m_propHover
= (wxPGProperty
*) NULL
;
589 m_eventObject
= this;
590 m_curFocused
= (wxWindow
*) NULL
;
592 m_inDoPropertyChanged
= 0;
593 m_inCommitChangesFromEditor
= 0;
594 m_inDoSelectProperty
= 0;
595 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
601 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
602 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
603 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
604 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
605 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
606 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
607 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
608 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
609 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
610 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
611 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
612 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
613 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
615 m_coloursCustomized
= 0;
620 #if wxPG_DOUBLE_BUFFER
621 m_doubleBuffer
= (wxBitmap
*) NULL
;
624 m_windowsToDelete
= NULL
;
626 #ifndef wxPG_ICON_WIDTH
632 m_iconWidth
= wxPG_ICON_WIDTH
;
637 m_gutterWidth
= wxPG_GUTTER_MIN
;
638 m_subgroup_extramargin
= 10;
642 m_width
= m_height
= 0;
644 SetButtonShortcut(0);
646 m_keyComboConsumed
= 0;
648 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
651 m_chgInfo_changedProperty
= NULL
;
654 // -----------------------------------------------------------------------
657 // Initialize after parent etc. set
659 void wxPropertyGrid::Init2()
661 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
664 // Smaller controls on Mac
665 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
668 // Now create state, if one didn't exist already
669 // (wxPropertyGridManager might have created it for us).
672 m_pState
= CreateState();
673 m_pState
->m_pPropGrid
= this;
674 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
677 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
678 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
680 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
682 m_pState
->InitNonCatMode();
684 m_pState
->m_properties
= m_pState
->m_abcArray
;
687 GetClientSize(&m_width
,&m_height
);
689 #ifndef wxPG_ICON_WIDTH
690 // create two bitmap nodes for drawing
691 m_expandbmp
= new wxBitmap(expand_xpm
);
692 m_collbmp
= new wxBitmap(collapse_xpm
);
694 // calculate average font height for bitmap centering
696 m_iconWidth
= m_expandbmp
->GetWidth();
697 m_iconHeight
= m_expandbmp
->GetHeight();
700 m_curcursor
= wxCURSOR_ARROW
;
701 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
703 // adjust bitmap icon y position so they are centered
704 m_vspacing
= wxPG_DEFAULT_VSPACING
;
708 wxFont useFont
= wxScrolledWindow::GetFont();
709 wxScrolledWindow::SetOwnFont( useFont
);
712 // This should be otherwise called by SetOwnFont
713 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
715 // Add base brush item
716 m_arrBgBrushes
.Add((void*)new wxPGBrush());
718 // Add base colour items
719 m_arrFgCols
.Add((void*)new wxPGColour());
720 m_arrFgCols
.Add((void*)new wxPGColour());
724 // This helps with flicker
725 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
728 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
729 m_tlp
= ::wxGetTopLevelParent(this);
730 m_tlwHandler
= handler
;
731 m_tlp
->PushEventHandler(handler
);
733 // set virtual size to this window size
734 wxSize wndsize
= GetSize();
735 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
737 m_timeCreated
= ::wxGetLocalTimeMillis();
739 m_canvas
= new wxPGCanvas();
740 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
741 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
742 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
744 m_iFlags
|= wxPG_FL_INITIALIZED
;
746 m_ncWidth
= wndsize
.GetWidth();
748 // Need to call OnResize handler or size given in constructor/Create
750 wxSizeEvent
sizeEvent(wndsize
,0);
754 // -----------------------------------------------------------------------
756 wxPropertyGrid::~wxPropertyGrid()
760 DoSelectProperty(NULL
);
762 // This should do prevent things from going too badly wrong
763 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
765 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
766 m_canvas
->ReleaseMouse();
768 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
769 m_tlp
->RemoveEventHandler(handler
);
773 if ( IsEditorsValueModified() )
774 ::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).)"),
775 wxS("wxPropertyGrid Debug Warning") );
778 #if wxPG_DOUBLE_BUFFER
779 if ( m_doubleBuffer
)
780 delete m_doubleBuffer
;
783 delete m_windowsToDelete
;
785 //m_selected = (wxPGProperty*) NULL;
787 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
790 delete m_cursorSizeWE
;
792 #ifndef wxPG_ICON_WIDTH
797 // Delete cached text colours.
798 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
800 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
803 // Delete cached brushes.
804 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
806 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
809 // Delete common value records
810 for ( i
=0; i
<m_commonValues
.size(); i
++ )
812 delete GetCommonValue(i
);
816 // -----------------------------------------------------------------------
818 bool wxPropertyGrid::Destroy()
820 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
821 m_canvas
->ReleaseMouse();
823 return wxScrolledWindow::Destroy();
826 // -----------------------------------------------------------------------
828 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
830 return new wxPropertyGridPageState();
833 // -----------------------------------------------------------------------
834 // wxPropertyGrid overridden wxWindow methods
835 // -----------------------------------------------------------------------
837 void wxPropertyGrid::SetWindowStyleFlag( long style
)
839 long old_style
= m_windowStyle
;
841 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
843 wxASSERT( m_pState
);
845 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
848 EnableCategories( true );
850 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
852 // Disable categories
853 EnableCategories( false );
855 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
861 PrepareAfterItemsAdded();
863 m_pState
->m_itemsAdded
= 1;
865 #if wxPG_SUPPORT_TOOLTIPS
866 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
872 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
873 SetToolTip ( tooltip );
874 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
877 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
882 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
887 wxScrolledWindow::SetWindowStyleFlag ( style
);
889 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
891 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
893 CalculateFontAndBitmapStuff( m_vspacing
);
899 // -----------------------------------------------------------------------
901 void wxPropertyGrid::Freeze()
905 wxScrolledWindow::Freeze();
910 // -----------------------------------------------------------------------
912 void wxPropertyGrid::Thaw()
918 wxScrolledWindow::Thaw();
919 RecalculateVirtualSize();
920 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
924 // Force property re-selection
926 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
930 // -----------------------------------------------------------------------
932 void wxPropertyGrid::SetExtraStyle( long exStyle
)
934 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
936 #if defined(__WXMSW__)
939 // Don't use WS_EX_COMPOSITED just now.
942 if ( m_iFlags & wxPG_FL_IN_MANAGER )
943 hWnd = (HWND)GetParent()->GetHWND();
945 hWnd = (HWND)GetHWND();
947 ::SetWindowLong( hWnd, GWL_EXSTYLE,
948 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
951 //#elif defined(__WXGTK20__)
953 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
954 // truly was double-buffered.
955 if ( !this->IsDoubleBuffered() )
957 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
961 #if wxPG_DOUBLE_BUFFER
962 delete m_doubleBuffer
;
963 m_doubleBuffer
= NULL
;
968 wxScrolledWindow::SetExtraStyle( exStyle
);
970 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
971 m_pState
->InitNonCatMode();
973 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
974 m_windowStyle
|= wxPG_TOOLTIPS
;
977 wxPGGlobalVars
->m_extraStyle
= exStyle
;
980 // -----------------------------------------------------------------------
982 // returns the best acceptable minimal size
983 wxSize
wxPropertyGrid::DoGetBestSize() const
986 if ( m_lineHeight
> hei
)
988 wxSize sz
= wxSize( 60, hei
+40 );
994 // -----------------------------------------------------------------------
995 // wxPropertyGrid Font and Colour Methods
996 // -----------------------------------------------------------------------
998 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1002 m_captionFont
= wxScrolledWindow::GetFont();
1004 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1005 m_subgroup_extramargin
= x
+ (x
/2);
1008 #if wxPG_USE_RENDERER_NATIVE
1009 m_iconWidth
= wxPG_ICON_WIDTH
;
1010 #elif wxPG_ICON_WIDTH
1012 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1013 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1014 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1018 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1019 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1020 m_gutterWidth
= wxPG_GUTTER_MIN
;
1023 if ( vspacing
<= 1 ) vdiv
= 12;
1024 else if ( vspacing
>= 3 ) vdiv
= 3;
1026 m_spacingy
= m_fontHeight
/ vdiv
;
1027 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1028 m_spacingy
= wxPG_YSPACING_MIN
;
1031 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1032 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1034 m_captionFont
.SetWeight(wxBOLD
);
1035 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1037 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1040 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1041 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1044 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1046 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1047 RecalculateVirtualSize();
1049 InvalidateBestSize();
1052 // -----------------------------------------------------------------------
1054 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1060 // -----------------------------------------------------------------------
1062 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1063 int ga
= 1000, int ba
= 1000,
1064 bool forceDifferent
= false)
1071 // Recursion guard (allow 2 max)
1072 static int isinside
= 0;
1074 wxCHECK_MSG( isinside
< 3,
1076 wxT("wxPGAdjustColour should not be recursively called more than once") );
1081 int g
= src
.Green();
1084 if ( r2
>255 ) r2
= 255;
1085 else if ( r2
<0) r2
= 0;
1087 if ( g2
>255 ) g2
= 255;
1088 else if ( g2
<0) g2
= 0;
1090 if ( b2
>255 ) b2
= 255;
1091 else if ( b2
<0) b2
= 0;
1093 // Make sure they are somewhat different
1094 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1095 dst
= wxPGAdjustColour(src
,-(ra
*2));
1097 dst
= wxColour(r2
,g2
,b2
);
1099 // Recursion guard (allow 2 max)
1106 static int wxPGGetColAvg( const wxColour
& col
)
1108 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1112 void wxPropertyGrid::RegainColours()
1114 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1116 if ( !(m_coloursCustomized
& 0x0002) )
1118 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1120 // Make sure colour is dark enough
1122 int colDec
= wxPGGetColAvg(col
) - 230;
1124 int colDec
= wxPGGetColAvg(col
) - 200;
1127 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1132 if ( !(m_coloursCustomized
& 0x0001) )
1133 m_colMargin
= m_colCapBack
;
1135 if ( !(m_coloursCustomized
& 0x0004) )
1142 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1143 m_colCapFore
= capForeCol
;
1145 // Set the cached colour as well.
1146 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1149 if ( !(m_coloursCustomized
& 0x0008) )
1151 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1152 m_colPropBack
= bgCol
;
1154 // Set the cached brush as well.
1155 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1158 if ( !(m_coloursCustomized
& 0x0010) )
1160 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1161 m_colPropFore
= fgCol
;
1163 // Set the cached colour as well.
1164 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1167 if ( !(m_coloursCustomized
& 0x0020) )
1168 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1170 if ( !(m_coloursCustomized
& 0x0040) )
1171 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1173 if ( !(m_coloursCustomized
& 0x0080) )
1174 m_colLine
= m_colCapBack
;
1176 if ( !(m_coloursCustomized
& 0x0100) )
1177 m_colDisPropFore
= m_colCapFore
;
1179 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1182 // -----------------------------------------------------------------------
1184 void wxPropertyGrid::ResetColours()
1186 m_coloursCustomized
= 0;
1193 // -----------------------------------------------------------------------
1195 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1197 // Must disable active editor.
1200 bool selRes
= ClearSelection();
1201 wxPG_CHECK_MSG_DBG( selRes
,
1203 wxT("failed to deselect a property (editor probably had invalid value)") );
1206 // TODO: Following code is disabled with wxMac because
1207 // it is reported to fail. I (JMS) cannot debug it
1208 // personally right now.
1209 #if !defined(__WXMAC__)
1210 bool res
= wxScrolledWindow::SetFont( font
);
1213 CalculateFontAndBitmapStuff( m_vspacing
);
1216 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1224 // TODO: Remove after SetFont crash fixed.
1225 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1227 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."));
1233 // -----------------------------------------------------------------------
1235 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1238 m_coloursCustomized
|= 0x80;
1242 // -----------------------------------------------------------------------
1244 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1247 m_coloursCustomized
|= 0x01;
1251 // -----------------------------------------------------------------------
1253 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1255 m_colPropBack
= col
;
1256 m_coloursCustomized
|= 0x08;
1258 // Set the cached brush as well.
1259 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1264 // -----------------------------------------------------------------------
1266 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1268 m_colPropFore
= col
;
1269 m_coloursCustomized
|= 0x10;
1271 // Set the cached colour as well.
1272 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1277 // -----------------------------------------------------------------------
1279 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1281 m_colEmptySpace
= col
;
1286 // -----------------------------------------------------------------------
1288 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1290 m_colDisPropFore
= col
;
1291 m_coloursCustomized
|= 0x100;
1295 // -----------------------------------------------------------------------
1297 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1300 m_coloursCustomized
|= 0x20;
1304 // -----------------------------------------------------------------------
1306 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1309 m_coloursCustomized
|= 0x40;
1313 // -----------------------------------------------------------------------
1315 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1318 m_coloursCustomized
|= 0x02;
1322 // -----------------------------------------------------------------------
1324 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1327 m_coloursCustomized
|= 0x04;
1329 // Set the cached colour as well.
1330 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1335 // -----------------------------------------------------------------------
1337 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1339 unsigned char ind
= index
;
1341 p
->m_bgColIndex
= ind
;
1344 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1345 SetBackgroundColourIndex(p
->Item(i
),index
);
1348 // -----------------------------------------------------------------------
1350 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1352 wxPG_PROP_ARG_CALL_PROLOG()
1357 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1359 // As it is most likely that the previous colour is used, start comparison
1361 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1363 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1372 colInd
= m_arrBgBrushes
.size();
1373 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1374 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1378 SetBackgroundColourIndex(p
,colInd
);
1380 // If this was on a visible grid, then draw it.
1381 DrawItemAndChildren(p
);
1384 // -----------------------------------------------------------------------
1386 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1388 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1390 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1393 // -----------------------------------------------------------------------
1395 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1397 unsigned char ind
= index
;
1399 p
->m_fgColIndex
= ind
;
1401 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1404 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1405 SetTextColourIndex( p
->Item(i
), index
, flags
);
1409 // -----------------------------------------------------------------------
1411 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1416 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1418 // As it is most likely that the previous colour is used, start comparison
1420 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1422 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1431 colInd
= m_arrFgCols
.size();
1432 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1433 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1439 // -----------------------------------------------------------------------
1441 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1444 wxPG_PROP_ARG_CALL_PROLOG()
1446 if ( p
->IsCategory() )
1448 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1449 cat
->SetTextColIndex(CacheColour(colour
));
1455 flags
|= wxPG_RECURSE
;
1456 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1458 DrawItemAndChildren(p
);
1461 // -----------------------------------------------------------------------
1463 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1465 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1467 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1470 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1472 wxPG_PROP_ARG_CALL_PROLOG()
1474 SetBackgroundColourIndex( p
, 0 );
1475 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1477 if ( p
->IsCategory() )
1479 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1480 cat
->SetTextColIndex(1);
1484 // -----------------------------------------------------------------------
1485 // wxPropertyGrid property adding and removal
1486 // -----------------------------------------------------------------------
1488 void wxPropertyGrid::PrepareAfterItemsAdded()
1490 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1492 m_pState
->m_itemsAdded
= 0;
1494 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1497 RecalculateVirtualSize();
1500 // -----------------------------------------------------------------------
1501 // wxPropertyGrid property value setting and getting
1502 // -----------------------------------------------------------------------
1504 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1506 m_pState
->DoSetPropertyValueUnspecified(p
);
1507 DrawItemAndChildren(p
);
1509 wxPGProperty
* parent
= p
->GetParent();
1510 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1513 parent
= parent
->GetParent();
1517 // -----------------------------------------------------------------------
1518 // wxPropertyGrid property operations
1519 // -----------------------------------------------------------------------
1521 void wxPropertyGrid::DoSetPropertyName( wxPGProperty
* p
, const wxString
& newname
)
1523 wxCHECK_RET( p
, wxT("invalid property id") );
1525 if ( p
->GetBaseName().Len() ) m_pState
->m_dictName
.erase( p
->GetBaseName() );
1526 if ( newname
.Len() ) m_pState
->m_dictName
[newname
] = (void*) p
;
1528 p
->DoSetName(newname
);
1531 // -----------------------------------------------------------------------
1533 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1535 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1539 bool changed
= false;
1541 // Is it inside collapsed section?
1542 if ( !p
->IsVisible() )
1545 wxPGProperty
* parent
= p
->GetParent();
1546 wxPGProperty
* grandparent
= parent
->GetParent();
1548 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1549 Expand( grandparent
);
1557 GetViewStart(&vx
,&vy
);
1558 vy
*=wxPG_PIXELS_PER_UNIT
;
1564 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1565 m_iFlags
|= wxPG_FL_SCROLLED
;
1568 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1570 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1571 m_iFlags
|= wxPG_FL_SCROLLED
;
1581 // -----------------------------------------------------------------------
1582 // wxPropertyGrid helper methods called by properties
1583 // -----------------------------------------------------------------------
1585 // Control font changer helper.
1586 void wxPropertyGrid::SetCurControlBoldFont()
1588 wxASSERT( m_wndEditor
);
1589 m_wndEditor
->SetFont( m_captionFont
);
1592 // -----------------------------------------------------------------------
1594 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1597 #if wxPG_SMALL_SCREEN
1598 // On small-screen devices, always show dialogs with default position and size.
1599 return wxDefaultPosition
;
1601 int splitterX
= GetSplitterPosition();
1605 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1607 ImprovedClientToScreen( &x
, &y
);
1609 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1610 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1617 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1627 new_y
= y
+ m_lineHeight
;
1629 return wxPoint(new_x
,new_y
);
1633 // -----------------------------------------------------------------------
1635 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1637 if ( src_str
.length() == 0 )
1643 bool prev_is_slash
= false;
1645 wxString::const_iterator i
= src_str
.begin();
1649 for ( ; i
!= src_str
.end(); i
++ )
1653 if ( a
!= wxS('\\') )
1655 if ( !prev_is_slash
)
1661 if ( a
== wxS('n') )
1664 dst_str
<< wxS('\n');
1666 dst_str
<< wxS('\n');
1669 else if ( a
== wxS('t') )
1670 dst_str
<< wxS('\t');
1674 prev_is_slash
= false;
1678 if ( prev_is_slash
)
1680 dst_str
<< wxS('\\');
1681 prev_is_slash
= false;
1685 prev_is_slash
= true;
1692 // -----------------------------------------------------------------------
1694 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1696 if ( src_str
.length() == 0 )
1702 wxString::const_iterator i
= src_str
.begin();
1703 wxUniChar prev_a
= wxS('\0');
1707 for ( ; i
!= src_str
.end(); i
++ )
1711 if ( a
>= wxS(' ') )
1713 // This surely is not something that requires an escape sequence.
1718 // This might need...
1719 if ( a
== wxS('\r') )
1721 // DOS style line end.
1722 // Already taken care below
1724 else if ( a
== wxS('\n') )
1725 // UNIX style line end.
1726 dst_str
<< wxS("\\n");
1727 else if ( a
== wxS('\t') )
1729 dst_str
<< wxS('\t');
1732 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1742 // -----------------------------------------------------------------------
1744 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1748 return (wxPGProperty
*) NULL
;
1751 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1754 // -----------------------------------------------------------------------
1755 // wxPropertyGrid graphics related methods
1756 // -----------------------------------------------------------------------
1758 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1762 // Update everything inside the box
1763 wxRect r
= GetUpdateRegion().GetBox();
1765 dc
.SetPen(m_colEmptySpace
);
1766 dc
.SetBrush(m_colEmptySpace
);
1767 dc
.DrawRectangle(r
);
1770 // -----------------------------------------------------------------------
1772 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1773 wxPGProperty
* property
) const
1775 // Prepare rectangle to be used
1777 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1778 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1780 #if (wxPG_USE_RENDERER_NATIVE)
1782 #elif wxPG_ICON_WIDTH
1783 // Drawing expand/collapse button manually
1784 dc
.SetPen(m_colPropFore
);
1785 if ( property
->IsCategory() )
1786 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1788 dc
.SetBrush(m_colPropBack
);
1790 dc
.DrawRectangle( r
);
1791 int _y
= r
.y
+(m_iconWidth
/2);
1792 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1797 if ( property
->IsExpanded() )
1799 // wxRenderer functions are non-mutating in nature, so it
1800 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1801 // Hopefully this does not cause problems.
1802 #if (wxPG_USE_RENDERER_NATIVE)
1803 wxRendererNative::Get().DrawTreeItemButton(
1809 #elif wxPG_ICON_WIDTH
1818 #if (wxPG_USE_RENDERER_NATIVE)
1819 wxRendererNative::Get().DrawTreeItemButton(
1825 #elif wxPG_ICON_WIDTH
1826 int _x
= r
.x
+(m_iconWidth
/2);
1827 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1833 #if (wxPG_USE_RENDERER_NATIVE)
1835 #elif wxPG_ICON_WIDTH
1838 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1842 // -----------------------------------------------------------------------
1845 // This is the one called by OnPaint event handler and others.
1846 // topy and bottomy are already unscrolled (ie. physical)
1848 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1850 unsigned int bottomy
,
1851 const wxRect
* clipRect
)
1853 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1855 m_pState
->EnsureVirtualHeight();
1857 wxRect tempClipRect
;
1860 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1861 clipRect
= &tempClipRect
;
1864 // items added check
1865 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1867 int paintFinishY
= 0;
1869 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1872 bool isBuffered
= false;
1874 #if wxPG_DOUBLE_BUFFER
1875 wxMemoryDC
* bufferDC
= NULL
;
1877 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1879 if ( !m_doubleBuffer
)
1881 paintFinishY
= clipRect
->y
;
1886 bufferDC
= new wxMemoryDC();
1888 // If nothing was changed, then just copy from double-buffer
1889 bufferDC
->SelectObject( *m_doubleBuffer
);
1899 dc
.SetClippingRegion( *clipRect
);
1900 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1903 #if wxPG_DOUBLE_BUFFER
1906 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1907 bufferDC
, 0, 0, wxCOPY
);
1908 dc
.DestroyClippingRegion(); // Is this really necessary?
1914 // Clear area beyond bottomY?
1915 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1917 dc
.SetPen(m_colEmptySpace
);
1918 dc
.SetBrush(m_colEmptySpace
);
1919 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1923 // -----------------------------------------------------------------------
1925 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1926 const wxPGProperty
* firstItem
,
1927 const wxPGProperty
* lastItem
,
1928 const wxRect
* clipRect
,
1929 bool isBuffered
) const
1931 // TODO: This should somehow be eliminated.
1932 wxRect tempClipRect
;
1935 wxASSERT(firstItem
);
1937 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1938 clipRect
= &tempClipRect
;
1942 firstItem
= DoGetItemAtY(clipRect
->y
);
1946 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1948 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1951 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1954 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1955 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1957 int lh
= m_lineHeight
;
1960 int lastItemBottomY
;
1962 firstItemTopY
= clipRect
->y
;
1963 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1965 // Align y coordinates to item boundaries
1966 firstItemTopY
-= firstItemTopY
% lh
;
1967 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1968 lastItemBottomY
-= 1;
1970 // Entire range outside scrolled, visible area?
1971 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1974 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1978 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1979 firstItem->GetLabel().c_str(),
1980 lastItem->GetLabel().c_str(),
1981 (int)(lastItemBottomY - firstItemTopY),
1983 (unsigned long)clipRect );
1988 long windowStyle
= m_windowStyle
;
1994 // With wxPG_DOUBLE_BUFFER, do double buffering
1995 // - buffer's y = 0, so align cliprect and coordinates to that
1997 #if wxPG_DOUBLE_BUFFER
2003 xRelMod
= clipRect
->x
;
2004 yRelMod
= clipRect
->y
;
2007 // clipRect conversion
2015 firstItemTopY
-= yRelMod
;
2016 lastItemBottomY
-= yRelMod
;
2019 wxUnusedVar(isBuffered
);
2022 int x
= m_marginWidth
- xRelMod
;
2024 const wxFont
& normalfont
= m_font
;
2026 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
2028 bool isEnabled
= IsEnabled();
2031 // Prepare some pens and brushes that are often changed to.
2034 wxBrush
marginBrush(m_colMargin
);
2035 wxPen
marginPen(m_colMargin
);
2036 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2037 wxPen
linepen(m_colLine
,1,wxSOLID
);
2039 // pen that has same colour as text
2040 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2043 // Clear margin with background colour
2045 dc
.SetBrush( marginBrush
);
2046 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2048 dc
.SetPen( *wxTRANSPARENT_PEN
);
2049 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2052 const wxPGProperty
* selected
= m_selected
;
2053 const wxPropertyGridPageState
* state
= m_pState
;
2055 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2056 bool wasSelectedPainted
= false;
2059 // TODO: Only render columns that are within clipping region.
2061 dc
.SetFont(normalfont
);
2063 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2064 int endScanBottomY
= lastItemBottomY
+ lh
;
2065 int y
= firstItemTopY
;
2068 // Pregenerate list of visible properties.
2069 wxArrayPGProperty visPropArray
;
2070 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2072 for ( ; !it
.AtEnd(); it
.Next() )
2074 const wxPGProperty
* p
= *it
;
2076 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2078 visPropArray
.push_back((wxPGProperty
*)p
);
2080 if ( y
> endScanBottomY
)
2087 visPropArray
.push_back(NULL
);
2089 wxPGProperty
* nextP
= visPropArray
[0];
2091 int gridWidth
= state
->m_width
;
2094 for ( unsigned int arrInd
=1;
2095 nextP
&& y
<= lastItemBottomY
;
2098 wxPGProperty
* p
= nextP
;
2099 nextP
= visPropArray
[arrInd
];
2101 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2102 int textMarginHere
= x
;
2103 int renderFlags
= wxPGCellRenderer::Control
;
2105 int greyDepth
= m_marginWidth
;
2106 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2107 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2109 int greyDepthX
= greyDepth
- xRelMod
;
2111 // Use basic depth if in non-categoric mode and parent is base array.
2112 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2114 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2117 // Paint margin area
2118 dc
.SetBrush(marginBrush
);
2119 dc
.SetPen(marginPen
);
2120 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2122 dc
.SetPen( linepen
);
2127 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2133 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2135 sx
+= state
->m_colWidths
[si
];
2136 dc
.DrawLine( sx
, y
, sx
, y2
);
2139 // Horizontal Line, below
2140 // (not if both this and next is category caption)
2141 if ( p
->IsCategory() &&
2142 nextP
&& nextP
->IsCategory() )
2143 dc
.SetPen(m_colCapBack
);
2145 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2147 if ( p
== selected
)
2149 renderFlags
|= wxPGCellRenderer::Selected
;
2150 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2151 wasSelectedPainted
= true;
2159 if ( p
->IsCategory() )
2161 if ( p
->m_fgColIndex
== 0 )
2162 rowFgCol
= m_colCapFore
;
2164 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2165 rowBgBrush
= wxBrush(m_colCapBack
);
2167 else if ( p
!= selected
)
2169 // Disabled may get different colour.
2170 if ( !p
->IsEnabled() )
2171 rowFgCol
= m_colDisPropFore
;
2173 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2175 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2179 // Selected gets different colour.
2180 if ( reallyFocused
)
2182 rowFgCol
= m_colSelFore
;
2183 rowBgBrush
= wxBrush(m_colSelBack
);
2185 else if ( isEnabled
)
2187 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2188 rowBgBrush
= marginBrush
;
2192 rowFgCol
= m_colDisPropFore
;
2193 rowBgBrush
= wxBrush(m_colSelBack
);
2197 bool fontChanged
= false;
2199 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2204 if ( p
->IsCategory() )
2206 // Captions are all cells merged as one
2207 dc
.SetFont(m_captionFont
);
2209 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2211 dc
.SetBrush(rowBgBrush
);
2212 dc
.SetPen(rowBgBrush
.GetColour());
2213 dc
.SetTextForeground(rowFgCol
);
2215 dc
.DrawRectangle(cellRect
);
2218 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2219 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2222 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2223 DrawExpanderButton( dc
, butRect
, p
);
2227 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2229 dc
.SetFont(m_captionFont
);
2235 int nextCellWidth
= state
->m_colWidths
[0];
2236 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2237 int textXAdd
= textMarginHere
- greyDepthX
;
2239 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2241 cellRect
.width
= nextCellWidth
- 1;
2243 bool ctrlCell
= false;
2246 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2248 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2249 dc
.SetBrush(editorBgCol
);
2250 dc
.SetPen(editorBgCol
);
2251 dc
.SetTextForeground(m_colPropFore
);
2253 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2258 dc
.SetBrush(rowBgBrush
);
2259 dc
.SetPen(rowBgBrush
.GetColour());
2260 dc
.SetTextForeground(rowFgCol
);
2263 dc
.DrawRectangle(cellRect
);
2266 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2267 DrawExpanderButton( dc
, butRect
, p
);
2269 dc
.SetClippingRegion(cellRect
);
2271 cellRect
.x
+= textXAdd
;
2272 cellRect
.width
-= textXAdd
;
2277 wxPGCellRenderer
* renderer
;
2278 int cmnVal
= p
->GetCommonValue();
2279 if ( cmnVal
== -1 || ci
!= 1 )
2281 renderer
= p
->GetCellRenderer(ci
);
2282 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2286 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2287 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2291 cellX
+= state
->m_colWidths
[ci
];
2292 if ( ci
< (state
->m_colWidths
.size()-1) )
2293 nextCellWidth
= state
->m_colWidths
[ci
+1];
2295 dc
.DestroyClippingRegion(); // Is this really necessary?
2301 dc
.SetFont(normalfont
);
2306 // Refresh editor controls (seems not needed on msw)
2307 // NOTE: This code is mandatory for GTK!
2308 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2309 if ( wasSelectedPainted
)
2312 m_wndEditor
->Refresh();
2314 m_wndEditor2
->Refresh();
2321 // -----------------------------------------------------------------------
2323 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2327 if ( m_width
< 10 || m_height
< 10 ||
2328 !m_pState
->m_properties
->GetChildCount() ||
2329 p1
== (wxPGProperty
*) NULL
)
2330 return wxRect(0,0,0,0);
2335 // Return rect which encloses the given property range
2337 int visTop
= p1
->GetY();
2340 visBottom
= p2
->GetY() + m_lineHeight
;
2342 visBottom
= m_height
+ visTop
;
2344 // If seleced property is inside the range, we'll extend the range to include
2346 wxPGProperty
* selected
= m_selected
;
2349 int selectedY
= selected
->GetY();
2350 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2352 wxWindow
* editor
= GetEditorControl();
2355 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2356 if ( visBottom2
> visBottom
)
2357 visBottom
= visBottom2
;
2362 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2365 // -----------------------------------------------------------------------
2367 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2372 if ( m_pState
->m_itemsAdded
)
2373 PrepareAfterItemsAdded();
2375 wxRect r
= GetPropertyRect(p1
, p2
);
2378 m_canvas
->RefreshRect(r
);
2382 // -----------------------------------------------------------------------
2384 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2386 if ( p
== m_selected
)
2387 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2389 DrawItemAndChildren(p
);
2392 // -----------------------------------------------------------------------
2394 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2399 // Draw item, children, and parent too, if it is not category
2400 wxPGProperty
* parent
= p
->GetParent();
2403 !parent
->IsCategory() &&
2404 parent
->GetParent() )
2407 parent
= parent
->GetParent();
2410 DrawItemAndChildren(p
);
2413 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2415 wxCHECK_RET( p
, wxT("invalid property id") );
2417 // Do not draw if in non-visible page
2418 if ( p
->GetParentState() != m_pState
)
2421 // do not draw a single item if multiple pending
2422 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2425 wxWindow
* wndPrimary
= GetEditorControl();
2427 // Update child control.
2428 if ( m_selected
&& m_selected
->GetParent() == p
)
2429 m_selected
->UpdateControl(wndPrimary
);
2431 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2433 DrawItems(p
, lastDrawn
);
2436 // -----------------------------------------------------------------------
2438 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2439 const wxRect
*rect
)
2441 PrepareAfterItemsAdded();
2443 wxWindow::Refresh(false);
2445 // TODO: Coordinate translation
2446 m_canvas
->Refresh(false, rect
);
2448 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2449 // I think this really helps only GTK+1.2
2450 if ( m_wndEditor
) m_wndEditor
->Refresh();
2451 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2455 // -----------------------------------------------------------------------
2456 // wxPropertyGrid global operations
2457 // -----------------------------------------------------------------------
2459 void wxPropertyGrid::Clear()
2463 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2464 wxPG_CHECK_RET_DBG( selRes
,
2465 wxT("failed to deselect a property (editor probably had invalid value)") );
2468 m_pState
->DoClear();
2474 RecalculateVirtualSize();
2476 // Need to clear some area at the end
2478 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2481 // -----------------------------------------------------------------------
2483 bool wxPropertyGrid::EnableCategories( bool enable
)
2485 if ( !ClearSelection() )
2491 // Enable categories
2494 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2499 // Disable categories
2501 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2504 if ( !m_pState
->EnableCategories(enable
) )
2509 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2511 m_pState
->m_itemsAdded
= 1; // force
2512 PrepareAfterItemsAdded();
2516 m_pState
->m_itemsAdded
= 1;
2518 // No need for RecalculateVirtualSize() here - it is already called in
2519 // wxPropertyGridPageState method above.
2526 // -----------------------------------------------------------------------
2528 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2530 wxASSERT( pNewState
);
2531 wxASSERT( pNewState
->GetGrid() );
2533 if ( pNewState
== m_pState
)
2536 wxPGProperty
* oldSelection
= m_selected
;
2541 bool selRes
= ClearSelection();
2542 wxPG_CHECK_RET_DBG( selRes
,
2543 wxT("failed to deselect a property (editor probably had invalid value)") );
2546 m_pState
->m_selected
= oldSelection
;
2548 bool orig_mode
= m_pState
->IsInNonCatMode();
2549 bool new_state_mode
= pNewState
->IsInNonCatMode();
2551 m_pState
= pNewState
;
2554 int pgWidth
= GetClientSize().x
;
2555 if ( HasVirtualWidth() )
2557 int minWidth
= pgWidth
;
2558 if ( pNewState
->m_width
< minWidth
)
2560 pNewState
->m_width
= minWidth
;
2561 pNewState
->CheckColumnWidths();
2567 // Just in case, fully re-center splitter
2568 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2569 pNewState
->m_fSplitterX
= -1.0;
2571 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2574 m_propHover
= (wxPGProperty
*) NULL
;
2576 // If necessary, convert state to correct mode.
2577 if ( orig_mode
!= new_state_mode
)
2579 // This should refresh as well.
2580 EnableCategories( orig_mode
?false:true );
2582 else if ( !m_frozen
)
2584 // Refresh, if not frozen.
2585 if ( m_pState
->m_itemsAdded
)
2586 PrepareAfterItemsAdded();
2589 if ( m_pState
->m_selected
)
2590 DoSelectProperty( m_pState
->m_selected
);
2592 RecalculateVirtualSize(0);
2596 m_pState
->m_itemsAdded
= 1;
2599 // -----------------------------------------------------------------------
2601 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2603 wxPG_PROP_ARG_CALL_PROLOG()
2605 m_pState
->SortChildren( p
);
2608 // -----------------------------------------------------------------------
2610 void wxPropertyGrid::Sort()
2612 bool selRes
= ClearSelection(); // This must be before state clear
2613 wxPG_CHECK_RET_DBG( selRes
,
2614 wxT("failed to deselect a property (editor probably had invalid value)") );
2619 // -----------------------------------------------------------------------
2621 // Call to SetSplitterPosition will always disable splitter auto-centering
2622 // if parent window is shown.
2623 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2625 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2628 wxPropertyGridPageState
* state
= m_pState
;
2630 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2635 CorrectEditorWidgetSizeX();
2641 // -----------------------------------------------------------------------
2643 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2645 SetSplitterPosition( m_width
/2, true );
2646 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2647 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2650 // -----------------------------------------------------------------------
2651 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2652 // -----------------------------------------------------------------------
2654 // Returns nearest paint visible property (such that will be painted unless
2655 // window is scrolled or resized). If given property is paint visible, then
2656 // it itself will be returned
2657 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2659 int vx
,vy1
;// Top left corner of client
2660 GetViewStart(&vx
,&vy1
);
2661 vy1
*= wxPG_PIXELS_PER_UNIT
;
2663 int vy2
= vy1
+ m_height
;
2664 int propY
= p
->GetY2(m_lineHeight
);
2666 if ( (propY
+ m_lineHeight
) < vy1
)
2669 return DoGetItemAtY( vy1
);
2671 else if ( propY
> vy2
)
2674 return DoGetItemAtY( vy2
);
2677 // Itself paint visible
2682 // -----------------------------------------------------------------------
2684 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2688 m_pushButKeyCode
= keycode
;
2689 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2690 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2694 m_pushButKeyCode
= WXK_DOWN
;
2695 m_pushButKeyCodeNeedsCtrl
= 0;
2696 m_pushButKeyCodeNeedsAlt
= 1;
2700 // -----------------------------------------------------------------------
2701 // Methods related to change in value, value modification and sending events
2702 // -----------------------------------------------------------------------
2704 // commits any changes in editor of selected property
2705 // return true if validation did not fail
2706 // flags are same as with DoSelectProperty
2707 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2709 // Committing already?
2710 if ( m_inCommitChangesFromEditor
)
2713 // Don't do this if already processing editor event. It might
2714 // induce recursive dialogs and crap like that.
2715 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2717 if ( m_inDoPropertyChanged
)
2724 IsEditorsValueModified() &&
2725 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2728 m_inCommitChangesFromEditor
= 1;
2730 wxVariant
variant(m_selected
->GetValueRef());
2731 bool valueIsPending
= false;
2733 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2734 // due to another window getting focus
2735 wxWindow
* oldFocus
= m_curFocused
;
2737 bool validationFailure
= false;
2738 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2740 m_chgInfo_changedProperty
= NULL
;
2742 // If truly modified, schedule value as pending.
2743 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2745 if ( DoEditorValidate() &&
2746 PerformValidation(m_selected
, variant
) )
2748 valueIsPending
= true;
2752 validationFailure
= true;
2757 EditorsValueWasNotModified();
2762 m_inCommitChangesFromEditor
= 0;
2764 if ( validationFailure
&& !forceSuccess
)
2768 oldFocus
->SetFocus();
2769 m_curFocused
= oldFocus
;
2772 res
= OnValidationFailure(m_selected
, variant
);
2774 // Now prevent further validation failure messages
2777 EditorsValueWasNotModified();
2778 OnValidationFailureReset(m_selected
);
2781 else if ( valueIsPending
)
2783 DoPropertyChanged( m_selected
, flags
);
2784 EditorsValueWasNotModified();
2793 // -----------------------------------------------------------------------
2795 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2798 // Runs all validation functionality.
2799 // Returns true if value passes all tests.
2802 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2804 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2806 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2811 // Adapt list to child values, if necessary
2812 wxVariant listValue
= pendingValue
;
2813 wxVariant
* pPendingValue
= &pendingValue
;
2814 wxVariant
* pList
= NULL
;
2816 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2817 // string value, then we need treat as it was changed instead
2818 // (or, in addition, as is the case with composite string parent).
2819 // This includes creating list variant for child values.
2821 wxPGProperty
* pwc
= p
->GetParent();
2822 wxPGProperty
* changedProperty
= p
;
2823 wxPGProperty
* baseChangedProperty
= changedProperty
;
2824 wxVariant bcpPendingList
;
2826 listValue
= pendingValue
;
2827 listValue
.SetName(p
->GetBaseName());
2830 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2832 wxVariantList tempList
;
2833 wxVariant
lv(tempList
, pwc
->GetBaseName());
2834 lv
.Append(listValue
);
2836 pPendingValue
= &listValue
;
2838 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2840 baseChangedProperty
= pwc
;
2841 bcpPendingList
= lv
;
2844 changedProperty
= pwc
;
2845 pwc
= pwc
->GetParent();
2849 wxPGProperty
* evtChangingProperty
= changedProperty
;
2851 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2853 value
= *pPendingValue
;
2857 // Convert list to child values
2858 pList
= pPendingValue
;
2859 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2862 wxVariant evtChangingValue
= value
;
2864 // FIXME: After proper ValueToString()s added, remove
2865 // this. It is just a temporary fix, as evt_changing
2866 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2867 // (unless it is selected, and textctrl editor is open).
2868 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2870 evtChangingProperty
= baseChangedProperty
;
2871 if ( evtChangingProperty
!= p
)
2873 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2877 evtChangingValue
= pendingValue
;
2881 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2883 if ( changedProperty
== m_selected
)
2885 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2886 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2890 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2894 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2895 m_chgInfo_changedProperty
= changedProperty
;
2896 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2897 m_chgInfo_pendingValue
= value
;
2900 m_chgInfo_valueList
= *pList
;
2902 m_chgInfo_valueList
.MakeNull();
2904 // If changedProperty is not property which value was edited,
2905 // then call wxPGProperty::ValidateValue() for that as well.
2906 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2908 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2912 // SendEvent returns true if event was vetoed
2913 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2919 // -----------------------------------------------------------------------
2921 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2923 if ( !msg
.length() )
2927 if ( !wxPGGlobalVars
->m_offline
)
2929 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2932 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2935 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2938 pStatusBar
->SetStatusText(msg
);
2946 ::wxMessageBox(msg
, _T("Property Error"));
2949 // -----------------------------------------------------------------------
2951 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2953 int vfb
= m_validationInfo
.m_failureBehavior
;
2955 if ( vfb
& wxPG_VFB_BEEP
)
2958 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2959 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2961 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2962 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2964 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2966 wxColour vfbFg
= *wxWHITE
;
2967 wxColour vfbBg
= *wxRED
;
2968 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2969 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2971 DrawItemAndChildren(property
);
2973 if ( property
== m_selected
)
2975 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2977 wxWindow
* editor
= GetEditorControl();
2980 editor
->SetForegroundColour(vfbFg
);
2981 editor
->SetBackgroundColour(vfbBg
);
2987 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2989 wxString msg
= m_validationInfo
.m_failureMessage
;
2991 if ( !msg
.length() )
2992 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2994 DoShowPropertyError(property
, msg
);
2997 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3000 // -----------------------------------------------------------------------
3002 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3004 int vfb
= m_validationInfo
.m_failureBehavior
;
3006 if ( vfb
& wxPG_VFB_MARK_CELL
)
3008 property
->SetCell(0, NULL
);
3009 property
->SetCell(1, NULL
);
3011 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3013 if ( property
== m_selected
&& GetEditorControl() )
3015 // Calling this will recreate the control, thus resetting its colour
3016 RefreshProperty(property
);
3020 DrawItemAndChildren(property
);
3025 // -----------------------------------------------------------------------
3027 // flags are same as with DoSelectProperty
3028 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3030 if ( m_inDoPropertyChanged
)
3033 wxWindow
* editor
= GetEditorControl();
3035 m_pState
->m_anyModified
= 1;
3037 m_inDoPropertyChanged
= 1;
3039 // Maybe need to update control
3040 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3042 // These values were calculated in PerformValidation()
3043 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3044 wxVariant value
= m_chgInfo_pendingValue
;
3046 wxPGProperty
* topPaintedProperty
= changedProperty
;
3048 while ( !topPaintedProperty
->IsCategory() &&
3049 !topPaintedProperty
->IsRoot() )
3051 topPaintedProperty
= topPaintedProperty
->GetParent();
3054 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3056 // Set as Modified (not if dragging just began)
3057 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3059 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3060 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3063 SetCurControlBoldFont();
3069 // Propagate updates to parent(s)
3071 wxPGProperty
* prevPwc
= NULL
;
3073 while ( prevPwc
!= topPaintedProperty
)
3075 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3077 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3080 SetCurControlBoldFont();
3084 pwc
= pwc
->GetParent();
3087 // Draw the actual property
3088 DrawItemAndChildren( topPaintedProperty
);
3091 // If value was set by wxPGProperty::OnEvent, then update the editor
3093 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3096 p
->GetEditorClass()->UpdateControl(p
, editor
);
3100 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3101 if ( m_wndEditor
) m_wndEditor
->Refresh();
3102 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3107 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3109 // If top parent has composite string value, then send to child parents,
3110 // starting from baseChangedProperty.
3111 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3113 pwc
= m_chgInfo_baseChangedProperty
;
3115 while ( pwc
!= changedProperty
)
3117 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3118 pwc
= pwc
->GetParent();
3122 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3124 m_inDoPropertyChanged
= 0;
3129 // -----------------------------------------------------------------------
3131 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3133 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3135 m_chgInfo_changedProperty
= NULL
;
3137 if ( PerformValidation(p
, newValue
) )
3139 DoPropertyChanged(p
);
3144 OnValidationFailure(p
, newValue
);
3150 // -----------------------------------------------------------------------
3152 // Runs wxValidator for the selected property
3153 bool wxPropertyGrid::DoEditorValidate()
3155 #if wxUSE_VALIDATORS
3156 // With traditional validator style, we dont need to more
3157 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3160 if ( m_iFlags
& wxPG_FL_VALIDATION_FAILED
)
3165 wxWindow
* wnd
= GetEditorControl();
3167 wxValidator
* validator
= m_selected
->GetValidator();
3168 if ( validator
&& wnd
)
3170 // Use TextCtrl of ODComboBox instead
3171 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3173 wnd
= ((wxOwnerDrawnComboBox
*)wnd
)->GetTextCtrl();
3179 validator
->SetWindow(wnd
);
3181 // Instead setting the flag after the failure, we set
3182 // it before checking and then clear afterwards if things
3183 // went fine. This trick is necessary since focus events
3184 // may be triggered while in Validate.
3185 m_iFlags
|= wxPG_FL_VALIDATION_FAILED
;
3186 if ( !validator
->Validate(this) )
3188 // If you dpm't want to display message multiple times per change,
3189 // comment the following line.
3190 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3193 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3199 // -----------------------------------------------------------------------
3201 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3203 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3204 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3206 wxWindow
* parent
= wnd
->GetParent();
3209 (parent
== m_canvas
||
3210 parent
->GetParent() == m_canvas
) )
3212 OnCustomEditorEvent((wxCommandEvent
&)event
);
3216 return wxPanel::ProcessEvent(event
);
3219 // -----------------------------------------------------------------------
3221 // NB: It may really not be wxCommandEvent - must check if necessary
3223 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3225 wxPGProperty
* selected
= m_selected
;
3228 // Somehow, event is handled after property has been deselected.
3229 // Possibly, but very rare.
3233 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3236 wxVariant
pendingValue(selected
->GetValueRef());
3237 wxWindow
* wnd
= GetEditorControl();
3239 bool wasUnspecified
= selected
->IsValueUnspecified();
3240 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3242 bool valueIsPending
= false;
3244 m_chgInfo_changedProperty
= NULL
;
3246 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3249 // Filter out excess wxTextCtrl modified events
3250 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3252 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3254 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3256 wxString newTcValue
= tc
->GetValue();
3257 if ( m_prevTcValue
== newTcValue
)
3260 m_prevTcValue
= newTcValue
;
3263 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3265 bool validationFailure
= false;
3266 bool buttonWasHandled
= false;
3269 // Try common button handling
3270 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3272 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3276 buttonWasHandled
= true;
3277 // Store as res2, as previously (and still currently alternatively)
3278 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3279 // in wxPGProperty::OnEvent().
3280 adapter
->ShowDialog( this, selected
);
3285 if ( wnd
&& !buttonWasHandled
)
3287 // First call editor class' event handler.
3288 const wxPGEditor
* editor
= selected
->GetEditorClass();
3290 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3292 // If changes, validate them
3293 if ( DoEditorValidate() )
3295 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3296 valueIsPending
= true;
3300 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
->GetChoiceCount();
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
)
3529 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3530 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3532 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3535 if ( m_inDoSelectProperty
)
3538 m_inDoSelectProperty
= 1;
3540 wxPGProperty
* prev
= m_selected
;
3543 // Delete windows pending for deletion
3544 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3548 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3549 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3551 m_windowsToDelete
->clear();
3556 m_inDoSelectProperty
= 0;
3561 // If we are frozen, then just set the values.
3564 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3565 m_editorFocused
= 0;
3568 m_pState
->m_selected
= p
;
3570 // If frozen, always free controls. But don't worry, as Thaw will
3571 // recall SelectProperty to recreate them.
3574 // Prevent any further selection measures in this call
3575 p
= (wxPGProperty
*) NULL
;
3580 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3582 // Only set focus if not deselecting
3585 if ( flags
& wxPG_SEL_FOCUS
)
3589 m_wndEditor
->SetFocus();
3590 m_editorFocused
= 1;
3595 wxScrolledWindow::SetFocus();
3596 m_editorFocused
= 0;
3600 m_inDoSelectProperty
= 0;
3605 // First, deactivate previous
3609 OnValidationFailureReset(m_selected
);
3611 // Must double-check if this is an selected in case of forceswitch
3614 if ( !CommitChangesFromEditor(flags
) )
3616 // Validation has failed, so we can't exit the previous editor
3617 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3618 // _("Invalid Value"),wxOK|wxICON_ERROR);
3619 m_inDoSelectProperty
= 0;
3627 m_selected
= (wxPGProperty
*) NULL
;
3628 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3630 // We need to always fully refresh the grid here
3633 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3634 EditorsValueWasNotModified();
3637 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3640 // Then, activate the one given.
3643 int propY
= p
->GetY2(m_lineHeight
);
3645 int splitterX
= GetSplitterPosition();
3646 m_editorFocused
= 0;
3648 m_pState
->m_selected
= p
;
3649 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3651 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3653 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3655 // Do we need OnMeasureCalls?
3656 wxSize imsz
= p
->OnMeasureImage();
3659 // Only create editor for non-disabled non-caption
3660 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3662 // do this for non-caption items
3666 // Do we need to paint the custom image, if any?
3667 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3668 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3669 !p
->GetEditorClass()->CanContainCustomImage()
3671 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3673 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3674 wxPoint goodPos
= grect
.GetPosition();
3675 #if wxPG_CREATE_CONTROLS_HIDDEN
3676 int coord_adjust
= m_height
- goodPos
.y
;
3677 goodPos
.y
+= coord_adjust
;
3680 const wxPGEditor
* editor
= p
->GetEditorClass();
3681 wxCHECK_MSG(editor
, false,
3682 wxT("NULL editor class not allowed"));
3684 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3686 wxPGWindowList wndList
= editor
->CreateControls(this,
3691 m_wndEditor
= wndList
.m_primary
;
3692 m_wndEditor2
= wndList
.m_secondary
;
3694 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3695 // value is drawn as normal, and m_wndEditor2 is assumed
3696 // to be a right-aligned button that triggers a separate editor
3701 wxASSERT_MSG( m_wndEditor
->GetParent() == m_canvas
,
3702 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3704 // Set validator, if any
3705 #if wxUSE_VALIDATORS
3706 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3708 wxValidator
* validator
= p
->GetValidator();
3710 m_wndEditor
->SetValidator(*validator
);
3714 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3715 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3717 // If it has modified status, use bold font
3718 // (must be done before capturing m_ctrlXAdjust)
3719 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3720 SetCurControlBoldFont();
3723 // Fix TextCtrl indentation
3724 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3725 wxTextCtrl
* tc
= NULL
;
3726 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3727 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3729 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3731 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3734 // Store x relative to splitter (we'll need it).
3735 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3737 // Check if background clear is not necessary
3738 wxPoint pos
= m_wndEditor
->GetPosition();
3739 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3741 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3744 m_wndEditor
->SetSizeHints(3, 3);
3746 #if wxPG_CREATE_CONTROLS_HIDDEN
3747 m_wndEditor
->Show(false);
3748 m_wndEditor
->Freeze();
3750 goodPos
= m_wndEditor
->GetPosition();
3751 goodPos
.y
-= coord_adjust
;
3752 m_wndEditor
->Move( goodPos
);
3755 wxWindow
* primaryCtrl
= GetEditorControl();
3756 SetupEventHandling(primaryCtrl
, wxPG_SUBID1
);
3758 // Focus and select all (wxTextCtrl, wxComboBox etc)
3759 if ( flags
& wxPG_SEL_FOCUS
)
3761 primaryCtrl
->SetFocus();
3763 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3769 wxASSERT_MSG( m_wndEditor2
->GetParent() == m_canvas
,
3770 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3772 // Get proper id for wndSecondary
3773 m_wndSecId
= m_wndEditor2
->GetId();
3774 wxWindowList children
= m_wndEditor2
->GetChildren();
3775 wxWindowList::iterator node
= children
.begin();
3776 if ( node
!= children
.end() )
3777 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3779 m_wndEditor2
->SetSizeHints(3,3);
3781 #if wxPG_CREATE_CONTROLS_HIDDEN
3782 wxRect sec_rect
= m_wndEditor2
->GetRect();
3783 sec_rect
.y
-= coord_adjust
;
3785 // Fine tuning required to fix "oversized"
3786 // button disappearance bug.
3787 if ( sec_rect
.y
< 0 )
3789 sec_rect
.height
+= sec_rect
.y
;
3792 m_wndEditor2
->SetSize( sec_rect
);
3794 m_wndEditor2
->Show();
3796 SetupEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3798 // If no primary editor, focus to button to allow
3799 // it to interprete ENTER etc.
3800 // NOTE: Due to problems focusing away from it, this
3801 // has been disabled.
3803 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3804 m_wndEditor2->SetFocus();
3808 if ( flags
& wxPG_SEL_FOCUS
)
3809 m_editorFocused
= 1;
3814 // wxGTK atleast seems to need this (wxMSW not)
3818 EditorsValueWasNotModified();
3820 // If it's inside collapsed section, expand parent, scroll, etc.
3821 // Also, if it was partially visible, scroll it into view.
3822 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3827 #if wxPG_CREATE_CONTROLS_HIDDEN
3828 m_wndEditor
->Thaw();
3830 m_wndEditor
->Show(true);
3836 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3842 // Show help text in status bar.
3843 // (if found and grid not embedded in manager with help box and
3844 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3847 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3849 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3850 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3852 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3854 statusbar
= frame
->GetStatusBar();
3859 const wxString
* pHelpString
= (const wxString
*) NULL
;
3863 pHelpString
= &p
->GetHelpString();
3864 if ( pHelpString
->length() )
3866 // Set help box text.
3867 statusbar
->SetStatusText( *pHelpString
);
3868 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3872 if ( (!pHelpString
|| !pHelpString
->length()) &&
3873 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3875 // Clear help box - but only if it was written
3876 // by us at previous time.
3877 statusbar
->SetStatusText( m_emptyString
);
3878 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3884 m_inDoSelectProperty
= 0;
3886 // call wx event handler (here so that it also occurs on deselection)
3887 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3892 // -----------------------------------------------------------------------
3894 bool wxPropertyGrid::UnfocusEditor()
3896 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3899 if ( !CommitChangesFromEditor(0) )
3902 m_canvas
->SetFocusIgnoringChildren();
3903 DrawItem(m_selected
);
3908 // -----------------------------------------------------------------------
3910 // This method is not inline because it called dozens of times
3911 // (i.e. two-arg function calls create smaller code size).
3912 bool wxPropertyGrid::DoClearSelection()
3914 return DoSelectProperty((wxPGProperty
*)NULL
);
3917 // -----------------------------------------------------------------------
3918 // wxPropertyGrid expand/collapse state
3919 // -----------------------------------------------------------------------
3921 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3923 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3925 // If active editor was inside collapsed section, then disable it
3926 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3928 if ( !ClearSelection() )
3932 // Store dont-center-splitter flag 'cause we need to temporarily set it
3933 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3934 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3936 bool res
= m_pState
->DoCollapse(pwc
);
3941 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3943 RecalculateVirtualSize();
3945 // Redraw etc. only if collapsed was visible.
3946 if (pwc
->IsVisible() &&
3948 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3950 // When item is collapsed so that scrollbar would move,
3951 // graphics mess is about (unless we redraw everything).
3956 // Clear dont-center-splitter flag if it wasn't set
3957 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3962 // -----------------------------------------------------------------------
3964 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3966 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3968 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3970 // Store dont-center-splitter flag 'cause we need to temporarily set it
3971 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3972 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3974 bool res
= m_pState
->DoExpand(pwc
);
3979 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3981 RecalculateVirtualSize();
3983 // Redraw etc. only if expanded was visible.
3984 if ( pwc
->IsVisible() && !m_frozen
&&
3985 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3989 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3992 DrawItems(pwc
, NULL
);
3997 // Clear dont-center-splitter flag if it wasn't set
3998 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4003 // -----------------------------------------------------------------------
4005 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4008 return m_pState
->DoHideProperty(p
, hide
, flags
);
4011 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
4014 if ( !ClearSelection() )
4018 m_pState
->DoHideProperty(p
, hide
, flags
);
4020 RecalculateVirtualSize();
4027 // -----------------------------------------------------------------------
4028 // wxPropertyGrid size related methods
4029 // -----------------------------------------------------------------------
4031 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4033 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4037 // If virtual height was changed, then recalculate editor control position(s)
4038 if ( m_pState
->m_vhCalcPending
)
4039 CorrectEditorWidgetPosY();
4041 m_pState
->EnsureVirtualHeight();
4044 int by1
= m_pState
->GetVirtualHeight();
4045 int by2
= m_pState
->GetActualVirtualHeight();
4048 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4049 wxASSERT_MSG( false,
4055 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4057 int x
= m_pState
->m_width
;
4058 int y
= m_pState
->m_virtualHeight
;
4061 GetClientSize(&width
,&height
);
4063 // Now adjust virtual size.
4064 SetVirtualSize(x
, y
);
4070 // Adjust scrollbars
4071 if ( HasVirtualWidth() )
4073 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4074 xPos
= GetScrollPos( wxHORIZONTAL
);
4077 if ( forceXPos
!= -1 )
4080 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4083 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4084 int yPos
= GetScrollPos( wxVERTICAL
);
4086 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4087 xAmount
, yAmount
, xPos
, yPos
, true );
4089 // Must re-get size now
4090 GetClientSize(&width
,&height
);
4092 if ( !HasVirtualWidth() )
4094 m_pState
->SetVirtualWidth(width
);
4101 m_canvas
->SetSize( x
, y
);
4103 m_pState
->CheckColumnWidths();
4106 CorrectEditorWidgetSizeX();
4108 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4111 // -----------------------------------------------------------------------
4113 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4115 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4119 GetClientSize(&width
,&height
);
4124 #if wxPG_DOUBLE_BUFFER
4125 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4127 int dblh
= (m_lineHeight
*2);
4128 if ( !m_doubleBuffer
)
4130 // Create double buffer bitmap to draw on, if none
4131 int w
= (width
>250)?width
:250;
4132 int h
= height
+ dblh
;
4134 m_doubleBuffer
= new wxBitmap( w
, h
);
4138 int w
= m_doubleBuffer
->GetWidth();
4139 int h
= m_doubleBuffer
->GetHeight();
4141 // Double buffer must be large enough
4142 if ( w
< width
|| h
< (height
+dblh
) )
4144 if ( w
< width
) w
= width
;
4145 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4146 delete m_doubleBuffer
;
4147 m_doubleBuffer
= new wxBitmap( w
, h
);
4154 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4155 m_ncWidth
= event
.GetSize().x
;
4159 if ( m_pState
->m_itemsAdded
)
4160 PrepareAfterItemsAdded();
4162 // Without this, virtual size (atleast under wxGTK) will be skewed
4163 RecalculateVirtualSize();
4169 // -----------------------------------------------------------------------
4171 void wxPropertyGrid::SetVirtualWidth( int width
)
4175 // Disable virtual width
4176 width
= GetClientSize().x
;
4177 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4181 // Enable virtual width
4182 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4184 m_pState
->SetVirtualWidth( width
);
4187 // -----------------------------------------------------------------------
4188 // wxPropertyGrid mouse event handling
4189 // -----------------------------------------------------------------------
4191 // selFlags uses same values DoSelectProperty's flags
4192 // Returns true if event was vetoed.
4193 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4195 // Send property grid event of specific type and with specific property
4196 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4197 evt
.SetPropertyGrid(this);
4198 evt
.SetEventObject(m_eventObject
);
4202 evt
.SetCanVeto(true);
4203 evt
.SetupValidationInfo();
4204 m_validationInfo
.m_pValue
= pValue
;
4206 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4208 evtHandler
->ProcessEvent(evt
);
4210 return evt
.WasVetoed();
4213 // -----------------------------------------------------------------------
4215 // Return false if should be skipped
4216 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4220 // Need to set focus?
4221 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4223 m_canvas
->SetFocus();
4226 wxPropertyGridPageState
* state
= m_pState
;
4228 int splitterHitOffset
;
4229 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4231 wxPGProperty
* p
= DoGetItemAtY(y
);
4235 int depth
= (int)p
->GetDepth() - 1;
4237 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4239 if ( x
>= marginEnds
)
4243 if ( p
->IsCategory() )
4245 // This is category.
4246 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4248 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4250 // Expand, collapse, activate etc. if click on text or left of splitter.
4253 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4258 if ( !DoSelectProperty( p
) )
4261 // On double-click, expand/collapse.
4262 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4264 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4265 else DoExpand( p
, true );
4269 else if ( splitterHit
== -1 )
4272 unsigned int selFlag
= 0;
4273 if ( columnHit
== 1 )
4275 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4276 selFlag
= wxPG_SEL_FOCUS
;
4278 if ( !DoSelectProperty( p
, selFlag
) )
4281 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4283 if ( p
->GetChildCount() && !p
->IsCategory() )
4284 // On double-click, expand/collapse.
4285 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4287 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4288 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4289 else DoExpand( p
, true );
4296 // click on splitter
4297 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4299 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4301 // Double-clicking the splitter causes auto-centering
4302 CenterSplitter( true );
4304 else if ( m_dragStatus
== 0 )
4307 // Begin draggin the splitter
4311 // Changes must be committed here or the
4312 // value won't be drawn correctly
4313 if ( !CommitChangesFromEditor() )
4316 m_wndEditor
->Show ( false );
4319 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4321 m_canvas
->CaptureMouse();
4322 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4326 m_draggedSplitter
= splitterHit
;
4327 m_dragOffset
= splitterHitOffset
;
4329 wxClientDC
dc(m_canvas
);
4331 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4332 // Fixes button disappearance bug
4334 m_wndEditor2
->Show ( false );
4337 m_startingSplitterX
= x
- splitterHitOffset
;
4345 if ( p
->GetChildCount() )
4347 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4349 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4351 int y2
= y
% m_lineHeight
;
4352 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4354 // On click on expander button, expand/collapse
4355 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4356 DoCollapse( p
, true );
4358 DoExpand( p
, true );
4367 // -----------------------------------------------------------------------
4369 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4370 wxMouseEvent
& WXUNUSED(event
) )
4374 // Select property here as well
4375 wxPGProperty
* p
= m_propHover
;
4376 if ( p
!= m_selected
)
4377 DoSelectProperty( p
);
4379 // Send right click event.
4380 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4387 // -----------------------------------------------------------------------
4389 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4390 wxMouseEvent
& WXUNUSED(event
) )
4394 // Select property here as well
4395 wxPGProperty
* p
= m_propHover
;
4397 if ( p
!= m_selected
)
4398 DoSelectProperty( p
);
4400 // Send double-click event.
4401 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4408 // -----------------------------------------------------------------------
4410 #if wxPG_SUPPORT_TOOLTIPS
4412 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4414 if ( tipString
.length() )
4416 m_canvas
->SetToolTip(tipString
);
4420 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4421 m_canvas
->SetToolTip( m_emptyString
);
4423 m_canvas
->SetToolTip( NULL
);
4428 #endif // #if wxPG_SUPPORT_TOOLTIPS
4430 // -----------------------------------------------------------------------
4432 // Return false if should be skipped
4433 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4435 // Safety check (needed because mouse capturing may
4436 // otherwise freeze the control)
4437 if ( m_dragStatus
> 0 && !event
.Dragging() )
4439 HandleMouseUp(x
,y
,event
);
4442 wxPropertyGridPageState
* state
= m_pState
;
4444 int splitterHitOffset
;
4445 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4446 int splitterX
= x
- splitterHitOffset
;
4448 if ( m_dragStatus
> 0 )
4450 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4451 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4454 int newSplitterX
= x
- m_dragOffset
;
4455 int splitterX
= x
- splitterHitOffset
;
4457 // Splitter redraw required?
4458 if ( newSplitterX
!= splitterX
)
4461 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4462 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4463 state
->m_fSplitterX
= (float) newSplitterX
;
4466 CorrectEditorWidgetSizeX();
4480 int ih
= m_lineHeight
;
4483 #if wxPG_SUPPORT_TOOLTIPS
4484 wxPGProperty
* prevHover
= m_propHover
;
4485 unsigned char prevSide
= m_mouseSide
;
4487 int curPropHoverY
= y
- (y
% ih
);
4489 // On which item it hovers
4490 if ( ( !m_propHover
)
4492 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4495 // Mouse moves on another property
4497 m_propHover
= DoGetItemAtY(y
);
4498 m_propHoverY
= curPropHoverY
;
4501 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4504 #if wxPG_SUPPORT_TOOLTIPS
4505 // Store which side we are on
4507 if ( columnHit
== 1 )
4509 else if ( columnHit
== 0 )
4513 // If tooltips are enabled, show label or value as a tip
4514 // in case it doesn't otherwise show in full length.
4516 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4518 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4520 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4522 if ( m_propHover
&& !m_propHover
->IsCategory() )
4525 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4527 // Show help string as a tooltip
4528 wxString tipString
= m_propHover
->GetHelpString();
4530 SetToolTip(tipString
);
4534 // Show cropped value string as a tooltip
4538 if ( m_mouseSide
== 1 )
4540 tipString
= m_propHover
->m_label
;
4541 space
= splitterX
-m_marginWidth
-3;
4543 else if ( m_mouseSide
== 2 )
4545 tipString
= m_propHover
->GetDisplayedString();
4547 space
= m_width
- splitterX
;
4548 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4549 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4555 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4558 SetToolTip( tipString
);
4565 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4566 m_canvas
->SetToolTip( m_emptyString
);
4568 m_canvas
->SetToolTip( NULL
);
4579 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4580 m_canvas
->SetToolTip( m_emptyString
);
4582 m_canvas
->SetToolTip( NULL
);
4590 if ( splitterHit
== -1 ||
4592 HasFlag(wxPG_STATIC_SPLITTER
) )
4594 // hovering on something else
4595 if ( m_curcursor
!= wxCURSOR_ARROW
)
4596 CustomSetCursor( wxCURSOR_ARROW
);
4600 // Do not allow splitter cursor on caption items.
4601 // (also not if we were dragging and its started
4602 // outside the splitter region)
4605 !m_propHover
->IsCategory() &&
4609 // hovering on splitter
4611 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4612 // reliably detected.
4613 //if ( m_curcursor != wxCURSOR_SIZEWE )
4614 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4620 // hovering on something else
4621 if ( m_curcursor
!= wxCURSOR_ARROW
)
4622 CustomSetCursor( wxCURSOR_ARROW
);
4629 // -----------------------------------------------------------------------
4631 // Also handles Leaving event
4632 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4633 wxMouseEvent
&WXUNUSED(event
) )
4635 wxPropertyGridPageState
* state
= m_pState
;
4639 int splitterHitOffset
;
4640 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4642 // No event type check - basicly calling this method should
4643 // just stop dragging.
4644 // Left up after dragged?
4645 if ( m_dragStatus
>= 1 )
4648 // End Splitter Dragging
4650 // DO NOT ENABLE FOLLOWING LINE!
4651 // (it is only here as a reminder to not to do it)
4654 // Disable splitter auto-centering
4655 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4657 // This is necessary to return cursor
4658 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4660 m_canvas
->ReleaseMouse();
4661 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4664 // Set back the default cursor, if necessary
4665 if ( splitterHit
== -1 ||
4668 CustomSetCursor( wxCURSOR_ARROW
);
4673 // Control background needs to be cleared
4674 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4675 DrawItem( m_selected
);
4679 m_wndEditor
->Show ( true );
4682 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4683 // Fixes button disappearance bug
4685 m_wndEditor2
->Show ( true );
4688 // This clears the focus.
4689 m_editorFocused
= 0;
4695 // -----------------------------------------------------------------------
4697 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4699 int splitterX
= GetSplitterPosition();
4702 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4706 wxWindow
* wnd
= m_wndEditor
;
4708 // Hide popup on clicks
4709 if ( event
.GetEventType() != wxEVT_MOTION
)
4710 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4712 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4718 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4720 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4721 ux
>= (r
.x
+r
.width
) ||
4723 event
.m_y
>= (r
.y
+r
.height
)
4733 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4738 // -----------------------------------------------------------------------
4740 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4743 if ( OnMouseCommon( event
, &x
, &y
) )
4745 HandleMouseClick(x
,y
,event
);
4750 // -----------------------------------------------------------------------
4752 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4755 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4756 HandleMouseRightClick(x
,y
,event
);
4760 // -----------------------------------------------------------------------
4762 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4764 // Always run standard mouse-down handler as well
4765 OnMouseClick(event
);
4768 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4769 HandleMouseDoubleClick(x
,y
,event
);
4773 // -----------------------------------------------------------------------
4775 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4778 if ( OnMouseCommon( event
, &x
, &y
) )
4780 HandleMouseMove(x
,y
,event
);
4785 // -----------------------------------------------------------------------
4787 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4789 // Called when mouse moves in the empty space below the properties.
4790 CustomSetCursor( wxCURSOR_ARROW
);
4793 // -----------------------------------------------------------------------
4795 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4798 if ( OnMouseCommon( event
, &x
, &y
) )
4800 HandleMouseUp(x
,y
,event
);
4805 // -----------------------------------------------------------------------
4807 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4809 // This may get called from child control as well, so event's
4810 // mouse position cannot be relied on.
4812 if ( event
.Entering() )
4814 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4816 // TODO: Fix this (detect parent and only do
4817 // cursor trick if it is a manager).
4818 wxASSERT( GetParent() );
4819 GetParent()->SetCursor(wxNullCursor
);
4821 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4824 GetParent()->SetCursor(wxNullCursor
);
4826 else if ( event
.Leaving() )
4828 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4829 m_canvas
->SetCursor( wxNullCursor
);
4831 // Get real cursor position
4832 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4834 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4837 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4839 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4843 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4851 // -----------------------------------------------------------------------
4853 // Common code used by various OnMouseXXXChild methods.
4854 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4856 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4857 wxASSERT( topCtrlWnd
);
4859 event
.GetPosition(&x
,&y
);
4861 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4863 int splitterX
= GetSplitterPosition();
4865 wxRect r
= topCtrlWnd
->GetRect();
4866 if ( !m_dragStatus
&&
4867 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4868 y
>= 0 && y
< r
.height \
4871 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4876 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4883 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4886 if ( OnMouseChildCommon(event
,&x
,&y
) )
4888 bool res
= HandleMouseClick(x
,y
,event
);
4889 if ( !res
) event
.Skip();
4893 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4896 wxASSERT( m_wndEditor
);
4897 // These coords may not be exact (about +-2),
4898 // but that should not matter (right click is about item, not position).
4899 wxPoint pt
= m_wndEditor
->GetPosition();
4900 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4901 wxASSERT( m_selected
);
4902 m_propHover
= m_selected
;
4903 bool res
= HandleMouseRightClick(x
,y
,event
);
4904 if ( !res
) event
.Skip();
4907 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4910 if ( OnMouseChildCommon(event
,&x
,&y
) )
4912 bool res
= HandleMouseMove(x
,y
,event
);
4913 if ( !res
) event
.Skip();
4917 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4920 if ( OnMouseChildCommon(event
,&x
,&y
) )
4922 bool res
= HandleMouseUp(x
,y
,event
);
4923 if ( !res
) event
.Skip();
4927 // -----------------------------------------------------------------------
4928 // wxPropertyGrid keyboard event handling
4929 // -----------------------------------------------------------------------
4931 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4933 wxNavigationKeyEvent evt
;
4934 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4935 (dir
?wxNavigationKeyEvent::IsForward
:
4936 wxNavigationKeyEvent::IsBackward
));
4937 evt
.SetEventObject(this);
4938 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4942 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4944 // Translates wxKeyEvent to wxPG_ACTION_XXX
4946 int keycode
= event
.GetKeyCode();
4947 int modifiers
= event
.GetModifiers();
4949 wxASSERT( !(modifiers
&~(0xFFFF)) );
4951 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4953 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4955 if ( it
== m_actionTriggers
.end() )
4960 int second
= (it
->second
>>16) & 0xFFFF;
4964 return (it
->second
& 0xFFFF);
4967 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4969 wxASSERT( !(modifiers
&~(0xFFFF)) );
4971 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4973 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4975 if ( it
!= m_actionTriggers
.end() )
4977 // This key combination is already used
4979 // Can add secondary?
4980 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4981 wxT("You can only add up to two separate actions per key combination.") );
4983 action
= it
->second
| (action
<<16);
4986 m_actionTriggers
[hashMapKey
] = action
;
4989 void wxPropertyGrid::ClearActionTriggers( int action
)
4991 wxPGHashMapI2I::iterator it
;
4993 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4995 if ( it
->second
== action
)
4997 m_actionTriggers
.erase(it
);
5002 static void CopyTextToClipboard( const wxString
& text
)
5004 if ( wxTheClipboard
->Open() )
5006 // This data objects are held by the clipboard,
5007 // so do not delete them in the app.
5008 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
5009 wxTheClipboard
->Close();
5013 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5016 // Handles key event when editor control is not focused.
5019 wxASSERT( !m_frozen
);
5023 // Travelsal between items, collapsing/expanding, etc.
5024 int keycode
= event
.GetKeyCode();
5026 if ( keycode
== WXK_TAB
)
5028 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5032 // Ignore Alt and Control when they are down alone
5033 if ( keycode
== WXK_ALT
||
5034 keycode
== WXK_CONTROL
)
5041 int action
= KeyEventToActions(event
, &secondAction
);
5047 if ( ButtonTriggerKeyTest(event
) )
5050 wxPGProperty
* p
= m_selected
;
5052 if ( action
== wxPG_ACTION_COPY
)
5054 CopyTextToClipboard(p
->GetDisplayedString());
5058 // Travel and expand/collapse
5061 if ( p
->GetChildCount() &&
5062 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5065 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5067 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5070 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5072 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5079 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5083 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5094 if ( selectDir
>= -1 )
5096 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5098 DoSelectProperty(p
);
5104 // If nothing was selected, select the first item now
5105 // (or navigate out of tab).
5106 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5108 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5109 if ( p
) DoSelectProperty(p
);
5114 // -----------------------------------------------------------------------
5116 // Potentially handles a keyboard event for editor controls.
5117 // Returns false if event should *not* be skipped (on true it can
5118 // be optionally skipped).
5119 // Basicly, false means that SelectProperty was called (or was about
5120 // to be called, if canDestroy was false).
5121 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5125 if ( !m_selected
|| !m_wndEditor
)
5130 int action
= KeyEventToAction(event
);
5133 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5136 // Esc cancels any changes
5137 if ( IsEditorsValueModified() )
5139 EditorsValueWasNotModified();
5141 // Update the control as well
5142 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5144 m_selected
->GetDisplayedString() );
5147 OnValidationFailureReset(m_selected
);
5153 else if ( action
== wxPG_ACTION_COPY
)
5155 // NB: There is some problem with getting native cut-copy-paste keys to go through
5156 // for embedded editor wxTextCtrl. This is why we emulate.
5158 wxTextCtrl
* tc
= GetEditorTextCtrl();
5161 wxString sel
= tc
->GetStringSelection();
5163 CopyTextToClipboard(sel
);
5167 CopyTextToClipboard(m_selected
->GetDisplayedString());
5170 else if ( action
== wxPG_ACTION_CUT
)
5172 wxTextCtrl
* tc
= GetEditorTextCtrl();
5176 tc
->GetSelection(&from
, &to
);
5179 CopyTextToClipboard(tc
->GetStringSelection());
5180 tc
->Remove(from
, to
);
5184 else if ( action
== wxPG_ACTION_PASTE
)
5186 wxTextCtrl
* tc
= GetEditorTextCtrl();
5189 if (wxTheClipboard
->Open())
5191 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5193 wxTextDataObject data
;
5194 wxTheClipboard
->GetData( data
);
5196 tc
->GetSelection(&from
, &to
);
5199 tc
->Remove(from
, to
);
5200 tc
->WriteText(data
.GetText());
5204 tc
->WriteText(data
.GetText());
5207 wxTheClipboard
->Close();
5215 // -----------------------------------------------------------------------
5217 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5221 // Events to editor controls should get relayed here.
5223 wxWindow
* focused
= wxWindow::FindFocus();
5225 wxWindow
* primaryCtrl
= GetEditorControl();
5228 (focused
==primaryCtrl
5229 || m_editorFocused
) )
5231 // Child key must be processed here, since it can
5232 // destroy the control which is referred by its own
5234 HandleChildKey( event
);
5237 HandleKeyEvent( event
);
5240 // -----------------------------------------------------------------------
5242 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5244 m_keyComboConsumed
= 0;
5249 // -----------------------------------------------------------------------
5251 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5253 // Ignore events that occur very close to focus set
5254 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5256 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5261 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5263 int dir
= event
.GetDirection()?1:-1;
5267 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5269 wxWindow
* focused
= wxWindow::FindFocus();
5271 wxWindow
* wndToCheck
= GetEditorControl();
5273 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5274 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5276 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5277 if ( comboTextCtrl
)
5278 wndToCheck
= comboTextCtrl
;
5282 // Because of problems navigating from wxButton, do not go to it.
5285 // No primary, use secondary
5286 wndToCheck = m_wndEditor2;
5288 // If it has editor button, focus to it after the primary editor.
5289 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5290 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5291 // have somewhat debugged in window.cpp itself).
5292 else if ( focused == wndToCheck &&
5294 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5296 wndToCheck = m_wndEditor2;
5297 wxLogDebug(wxT("Exp1"));
5301 if ( focused
!= wndToCheck
&&
5304 wndToCheck
->SetFocus();
5306 // Select all text in wxTextCtrl etc.
5307 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5308 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5310 m_editorFocused
= 1;
5317 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5321 // This allows preventing NavigateOut to occur
5322 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5331 // -----------------------------------------------------------------------
5333 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5335 int keycode
= event
.GetKeyCode();
5337 // Does the keycode trigger button?
5338 if ( keycode
== m_pushButKeyCode
&&
5340 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5341 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5343 m_keyComboConsumed
= 1;
5345 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5346 GetEventHandler()->AddPendingEvent(evt
);
5353 // -----------------------------------------------------------------------
5355 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5357 int keycode
= event
.GetKeyCode();
5359 // Ignore Alt and Control when they are down alone
5360 if ( keycode
== WXK_ALT
||
5361 keycode
== WXK_CONTROL
)
5367 if ( ButtonTriggerKeyTest(event
) )
5370 if ( HandleChildKey(event
) == true )
5373 GetEventHandler()->AddPendingEvent(event
);
5376 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5378 m_keyComboConsumed
= 0;
5380 GetEventHandler()->AddPendingEvent(event
);
5385 // -----------------------------------------------------------------------
5386 // wxPropertyGrid miscellaneous event handling
5387 // -----------------------------------------------------------------------
5389 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5392 // Check if the focus is in this control or one of its children
5393 wxWindow
* newFocused
= wxWindow::FindFocus();
5395 if ( newFocused
!= m_curFocused
)
5396 HandleFocusChange( newFocused
);
5399 // Called by focus event handlers. newFocused is the window that becomes focused.
5400 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5402 unsigned int oldFlags
= m_iFlags
;
5404 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5406 wxWindow
* parent
= newFocused
;
5408 // This must be one of nextFocus' parents.
5411 // Use m_eventObject, which is either wxPropertyGrid or
5412 // wxPropertyGridManager, as appropriate.
5413 if ( parent
== m_eventObject
)
5415 m_iFlags
|= wxPG_FL_FOCUSED
;
5418 parent
= parent
->GetParent();
5421 m_curFocused
= newFocused
;
5423 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5424 (oldFlags
& wxPG_FL_FOCUSED
) )
5426 // On each focus kill, mark the next nav key event
5427 // to be ignored (can't do on set focus since the
5428 // event would occur before it).
5429 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5431 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5433 // Need to store changed value
5434 CommitChangesFromEditor();
5440 // Preliminary code for tab-order respecting
5441 // tab-traversal (but should be moved to
5444 wxWindow* prevFocus = event.GetWindow();
5445 wxWindow* useThis = this;
5446 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5447 useThis = GetParent();
5450 prevFocus->GetParent() == useThis->GetParent() )
5452 wxList& children = useThis->GetParent()->GetChildren();
5454 wxNode* node = children.Find(prevFocus);
5456 if ( node->GetNext() &&
5457 useThis == node->GetNext()->GetData() )
5458 DoSelectProperty(GetFirst());
5459 else if ( node->GetPrevious () &&
5460 useThis == node->GetPrevious()->GetData() )
5461 DoSelectProperty(GetLastProperty());
5466 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5470 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5471 DrawItem( m_selected
);
5475 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5477 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5478 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5479 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5480 //else if ( event.GetWindow() )
5482 HandleFocusChange(event
.GetWindow());
5487 // -----------------------------------------------------------------------
5489 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5491 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5494 // event.Skip() being commented out is aworkaround for bug reported
5495 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5499 // -----------------------------------------------------------------------
5501 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5503 m_iFlags
|= wxPG_FL_SCROLLED
;
5508 // -----------------------------------------------------------------------
5510 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5512 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5514 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5518 // -----------------------------------------------------------------------
5519 // Property editor related functions
5520 // -----------------------------------------------------------------------
5522 // noDefCheck = true prevents infinite recursion.
5523 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorclass
,
5524 const wxString
& name
,
5527 wxASSERT( editorclass
);
5529 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5530 RegisterDefaultEditors();
5532 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorclass
;
5537 // Registers all default editor classes
5538 void wxPropertyGrid::RegisterDefaultEditors()
5540 wxPGRegisterDefaultEditorClass( TextCtrl
);
5541 wxPGRegisterDefaultEditorClass( Choice
);
5542 wxPGRegisterDefaultEditorClass( ComboBox
);
5543 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5544 #if wxPG_INCLUDE_CHECKBOX
5545 wxPGRegisterDefaultEditorClass( CheckBox
);
5547 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5549 // Register SpinCtrl etc. editors before use
5550 RegisterAdditionalEditors();
5553 // -----------------------------------------------------------------------
5554 // wxPGStringTokenizer
5555 // Needed to handle C-style string lists (e.g. "str1" "str2")
5556 // -----------------------------------------------------------------------
5558 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5559 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5563 wxPGStringTokenizer::~wxPGStringTokenizer()
5567 bool wxPGStringTokenizer::HasMoreTokens()
5569 const wxString
& str
= *m_str
;
5571 wxString::const_iterator i
= m_curPos
;
5573 wxUniChar delim
= m_delimeter
;
5575 wxUniChar prev_a
= wxT('\0');
5577 bool inToken
= false;
5579 while ( i
!= str
.end() )
5588 m_readyToken
.clear();
5593 if ( prev_a
!= wxT('\\') )
5597 if ( a
!= wxT('\\') )
5617 m_curPos
= str
.end();
5625 wxString
wxPGStringTokenizer::GetNextToken()
5627 return m_readyToken
;
5630 // -----------------------------------------------------------------------
5632 // -----------------------------------------------------------------------
5634 wxPGChoiceEntry::wxPGChoiceEntry()
5635 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5639 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5640 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5641 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5645 // -----------------------------------------------------------------------
5647 // -----------------------------------------------------------------------
5649 wxPGChoicesData::wxPGChoicesData()
5654 wxPGChoicesData::~wxPGChoicesData()
5659 void wxPGChoicesData::Clear()
5663 for ( i
=0; i
<m_items
.size(); i
++ )
5675 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5677 wxASSERT( m_items
.size() == 0 );
5681 for ( i
=0; i
<data
->GetCount(); i
++ )
5682 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5685 // -----------------------------------------------------------------------
5687 // -----------------------------------------------------------------------
5689 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5693 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5694 m_data
->Insert( -1, p
);
5698 // -----------------------------------------------------------------------
5700 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5704 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5705 p
->SetBitmap(bitmap
);
5706 m_data
->Insert( -1, p
);
5710 // -----------------------------------------------------------------------
5712 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5716 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5717 m_data
->Insert(index
, p
);
5721 // -----------------------------------------------------------------------
5723 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5727 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5728 m_data
->Insert( index
, p
);
5732 // -----------------------------------------------------------------------
5734 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5740 while ( index
< GetCount() )
5742 int cmpRes
= GetLabel(index
).Cmp(label
);
5748 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5749 m_data
->Insert( index
, p
);
5753 // -----------------------------------------------------------------------
5755 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5759 unsigned int itemcount
= 0;
5760 const wxChar
** p
= &labels
[0];
5761 while ( *p
) { p
++; itemcount
++; }
5764 for ( i
= 0; i
< itemcount
; i
++ )
5766 int value
= wxPG_INVALID_VALUE
;
5769 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5773 // -----------------------------------------------------------------------
5775 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5780 unsigned int itemcount
= arr
.size();
5782 for ( i
= 0; i
< itemcount
; i
++ )
5784 int value
= wxPG_INVALID_VALUE
;
5787 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5791 // -----------------------------------------------------------------------
5793 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5798 unsigned int itemcount
= arr
.size();
5800 for ( i
= 0; i
< itemcount
; i
++ )
5802 int value
= wxPG_INVALID_VALUE
;
5803 if ( &arrint
&& arrint
.size() )
5805 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5809 // -----------------------------------------------------------------------
5811 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5813 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5815 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5816 delete m_data
->Item(i
);
5817 m_data
->m_items
.RemoveAt(nIndex
, count
);
5820 // -----------------------------------------------------------------------
5822 int wxPGChoices::Index( const wxString
& str
) const
5827 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5829 if ( m_data
->Item(i
)->GetText() == str
)
5836 // -----------------------------------------------------------------------
5838 int wxPGChoices::Index( int val
) const
5843 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5845 if ( m_data
->Item(i
)->GetValue() == val
)
5852 // -----------------------------------------------------------------------
5854 wxArrayString
wxPGChoices::GetLabels() const
5859 if ( this && IsOk() )
5860 for ( i
=0; i
<GetCount(); i
++ )
5861 arr
.push_back(GetLabel(i
));
5866 // -----------------------------------------------------------------------
5868 bool wxPGChoices::HasValues() const
5873 // -----------------------------------------------------------------------
5875 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5882 for ( i
=0; i
< strings
.size(); i
++ )
5884 int index
= Index(strings
[i
]);
5886 arr
.Add(GetValue(index
));
5888 arr
.Add(wxPG_INVALID_VALUE
);
5895 // -----------------------------------------------------------------------
5897 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5898 wxArrayString
* unmatched
) const
5905 for ( i
=0; i
< strings
.size(); i
++ )
5907 const wxString
& str
= strings
[i
];
5908 int index
= Index(str
);
5911 else if ( unmatched
)
5912 unmatched
->Add(str
);
5919 // -----------------------------------------------------------------------
5921 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5925 if ( data
!= wxPGChoicesEmptyData
)
5932 // -----------------------------------------------------------------------
5934 void wxPGChoices::Init()
5936 m_data
= wxPGChoicesEmptyData
;
5939 // -----------------------------------------------------------------------
5941 void wxPGChoices::Free()
5943 if ( m_data
!= wxPGChoicesEmptyData
)
5946 m_data
= wxPGChoicesEmptyData
;
5950 // -----------------------------------------------------------------------
5951 // wxPropertyGridEvent
5952 // -----------------------------------------------------------------------
5954 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5957 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5958 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5959 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5960 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5961 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5962 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5963 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5964 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5965 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5968 // -----------------------------------------------------------------------
5970 void wxPropertyGridEvent::Init()
5972 m_validationInfo
= NULL
;
5974 m_wasVetoed
= false;
5977 // -----------------------------------------------------------------------
5979 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5980 : wxCommandEvent(commandType
,id
)
5986 // -----------------------------------------------------------------------
5988 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5989 : wxCommandEvent(event
)
5991 m_eventType
= event
.GetEventType();
5992 m_eventObject
= event
.m_eventObject
;
5994 m_property
= event
.m_property
;
5995 m_validationInfo
= event
.m_validationInfo
;
5996 m_canVeto
= event
.m_canVeto
;
5997 m_wasVetoed
= event
.m_wasVetoed
;
6000 // -----------------------------------------------------------------------
6002 wxPropertyGridEvent::~wxPropertyGridEvent()
6006 // -----------------------------------------------------------------------
6008 wxEvent
* wxPropertyGridEvent::Clone() const
6010 return new wxPropertyGridEvent( *this );
6013 void wxPropertyGrid::SetPropertyAttributeAll( const wxString
& attrName
, wxVariant value
)
6015 DoSetPropertyAttribute(GetRoot(), attrName
, value
, wxPG_RECURSE
);
6018 // -----------------------------------------------------------------------
6019 // wxPropertyGridPopulator
6020 // -----------------------------------------------------------------------
6022 wxPropertyGridPopulator::wxPropertyGridPopulator()
6026 wxPGGlobalVars
->m_offline
++;
6029 // -----------------------------------------------------------------------
6031 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6034 m_propHierarchy
.clear();
6037 // -----------------------------------------------------------------------
6039 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6045 // -----------------------------------------------------------------------
6047 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6050 // Free unused sets of choices
6051 wxPGHashMapS2P::iterator it
;
6053 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6055 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6062 m_pg
->GetPanel()->Refresh();
6064 wxPGGlobalVars
->m_offline
--;
6067 // -----------------------------------------------------------------------
6069 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6070 const wxString
& propLabel
,
6071 const wxString
& propName
,
6072 const wxString
* propValue
,
6073 wxPGChoices
* pChoices
)
6075 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6076 wxPGProperty
* parent
= GetCurParent();
6078 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6080 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6084 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6086 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6090 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6092 property
->SetLabel(propLabel
);
6093 property
->DoSetName(propName
);
6095 if ( pChoices
&& pChoices
->IsOk() )
6096 property
->SetChoices(*pChoices
);
6098 m_state
->DoInsert(parent
, -1, property
);
6101 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6106 // -----------------------------------------------------------------------
6108 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6110 m_propHierarchy
.push_back(property
);
6111 DoScanForChildren();
6112 m_propHierarchy
.pop_back();
6115 // -----------------------------------------------------------------------
6117 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6118 const wxString
& idString
)
6120 wxPGChoices choices
;
6123 if ( choicesString
[0] == wxT('@') )
6125 wxString ids
= choicesString
.substr(1);
6126 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6127 if ( it
== m_dictIdChoices
.end() )
6128 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6130 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6135 if ( idString
.length() )
6137 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6138 if ( it
!= m_dictIdChoices
.end() )
6140 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6147 // Parse choices string
6148 wxString::const_iterator it
= choicesString
.begin();
6152 bool labelValid
= false;
6154 for ( ; it
!= choicesString
.end(); it
++ )
6160 if ( c
== wxT('"') )
6165 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6166 choices
.Add(label
, l
);
6169 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6174 else if ( c
== wxT('=') )
6181 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6188 if ( c
== wxT('"') )
6201 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6202 choices
.Add(label
, l
);
6205 if ( !choices
.IsOk() )
6207 choices
.EnsureData();
6211 if ( idString
.length() )
6212 m_dictIdChoices
[idString
] = choices
.GetData();
6219 // -----------------------------------------------------------------------
6221 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6223 if ( s
.Last() == wxT('%') )
6225 wxString s2
= s
.substr(0,s
.length()-1);
6227 if ( s2
.ToLong(&val
, 10) )
6229 *pval
= (val
*max
)/100;
6235 return s
.ToLong(pval
, 10);
6238 // -----------------------------------------------------------------------
6240 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6241 const wxString
& type
,
6242 const wxString
& value
)
6244 int l
= m_propHierarchy
.size();
6248 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6249 wxString valuel
= value
.Lower();
6252 if ( type
.length() == 0 )
6257 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6259 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6261 else if ( value
.ToLong(&v
, 0) )
6268 if ( type
== wxT("string") )
6272 else if ( type
== wxT("int") )
6275 value
.ToLong(&v
, 0);
6278 else if ( type
== wxT("bool") )
6280 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6287 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6292 p
->SetAttribute( name
, variant
);
6297 // -----------------------------------------------------------------------
6299 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6301 wxLogError(_("Error in resource: %s"),msg
.c_str());
6304 // -----------------------------------------------------------------------
6306 #endif // wxUSE_PROPGRID