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"
21 #include "wx/object.h"
23 #include "wx/string.h"
26 #include "wx/window.h"
29 #include "wx/dcmemory.h"
30 #include "wx/button.h"
33 #include "wx/cursor.h"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
37 #include "wx/choice.h"
38 #include "wx/stattext.h"
39 #include "wx/scrolwin.h"
40 #include "wx/dirdlg.h"
41 #include "wx/layout.h"
43 #include "wx/textdlg.h"
44 #include "wx/filedlg.h"
45 #include "wx/statusbr.h"
51 // This define is necessary to prevent macro clearing
52 #define __wxPG_SOURCE_FILE__
54 #include <wx/propgrid/propgrid.h>
55 #include <wx/propgrid/editors.h>
57 #if wxPG_USE_RENDERER_NATIVE
58 #include <wx/renderer.h>
61 #include <wx/odcombo.h>
64 #include "wx/dcbuffer.h"
65 #include <wx/clipbrd.h>
66 #include <wx/dataobj.h>
69 #include <wx/msw/private.h>
74 // Two pics for the expand / collapse buttons.
75 // Files are not supplied with this project (since it is
76 // recommended to use either custom or native rendering).
77 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
78 // and copy xpm files from archive to wxPropertyGrid src directory
79 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
80 // and set wxPG_USE_RENDERER_NATIVE to 0).
81 #ifndef wxPG_ICON_WIDTH
82 #if defined(__WXMAC__)
83 #include "mac_collapse.xpm"
84 #include "mac_expand.xpm"
85 #elif defined(__WXGTK__)
86 #include "linux_collapse.xpm"
87 #include "linux_expand.xpm"
89 #include "default_collapse.xpm"
90 #include "default_expand.xpm"
95 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
96 #define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
97 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
98 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
99 #define wxPG_YSPACING_MIN 1
100 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
101 // but causes normal combobox to spill out under MSW
103 #define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
105 #define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
106 // Must be larger than largest control border
110 #define wxPG_DEFAULT_CURSOR wxNullCursor
113 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
115 #define wxPG_HIDER_BUTTON_HEIGHT 25
117 #define wxPG_PIXELS_PER_UNIT m_lineHeight
119 #ifdef wxPG_ICON_WIDTH
120 #define m_iconHeight m_iconWidth
123 #define wxPG_TOOLTIP_DELAY 1000
125 // -----------------------------------------------------------------------
128 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
130 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
133 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
136 // -----------------------------------------------------------------------
138 const wxChar
*wxPropertyGridNameStr
= wxT("wxPropertyGrid");
140 // -----------------------------------------------------------------------
141 // Statics in one class for easy destruction.
142 // NB: We prefer to use wxModule, as it offers more consistent behavior
143 // across platforms. However, for those rare problem situations, we
144 // also need to offer option to use simpler approach.
145 // -----------------------------------------------------------------------
147 #ifndef wxPG_USE_WXMODULE
148 #define wxPG_USE_WXMODULE 1
151 #if wxPG_USE_WXMODULE
153 #include <wx/module.h>
155 class wxPGGlobalVarsClassManager
: public wxModule
157 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
159 wxPGGlobalVarsClassManager() {}
160 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
161 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
164 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
166 #else // !wxPG_USE_WXMODULE
168 class wxPGGlobalVarsClassManager
171 wxPGGlobalVarsClassManager() {}
172 ~wxPGGlobalVarsClassManager() { delete wxPGGlobalVars
; }
175 static wxPGGlobalVarsClassManager gs_pgGlobalVarsClassManager
;
180 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
183 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
185 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
187 m_boolChoices
.Add(_("False"));
188 m_boolChoices
.Add(_("True"));
190 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
192 m_defaultRenderer
= new wxPGDefaultRenderer();
194 m_autoGetTranslation
= false;
202 // Prepare some shared variants
203 m_vEmptyString
= wxString();
205 m_vMinusOne
= (long) -1;
209 // Prepare cached string constants
210 m_strstring
= wxS("string");
211 m_strlong
= wxS("long");
212 m_strbool
= wxS("bool");
213 m_strlist
= wxS("list");
214 m_strMin
= wxS("Min");
215 m_strMax
= wxS("Max");
216 m_strUnits
= wxS("Units");
217 m_strInlineHelp
= wxS("InlineHelp");
225 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
229 delete m_defaultRenderer
;
231 // This will always have one ref
232 delete m_fontFamilyChoices
;
235 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
236 delete ((wxValidator
*)m_arrValidators
[i
]);
240 // Destroy value type class instances.
241 wxPGHashMapS2P::iterator vt_it
;
243 // Destroy editor class instances.
244 // iterate over all the elements in the class
245 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
247 delete ((wxPGEditor
*)vt_it
->second
);
250 delete wxPGProperty::sm_wxPG_LABEL
;
253 // -----------------------------------------------------------------------
255 // -----------------------------------------------------------------------
258 // This class is a wxBrush derivative used in the background colour
259 // brush cache. It adds wxPG-type colour-in-long to the class.
260 // JMS: Yes I know wxBrush doesn't actually hold the value (refcounted
261 // object does), but this is simpler implementation and equally
265 class wxPGBrush
: public wxBrush
268 wxPGBrush( const wxColour
& colour
);
270 virtual ~wxPGBrush() { }
271 void SetColour2( const wxColour
& colour
);
272 inline long GetColourAsLong() const { return m_colAsLong
; }
278 void wxPGBrush::SetColour2( const wxColour
& colour
)
280 wxBrush::SetColour(colour
);
281 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
285 wxPGBrush::wxPGBrush() : wxBrush()
291 wxPGBrush::wxPGBrush( const wxColour
& colour
) : wxBrush(colour
)
293 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
297 // -----------------------------------------------------------------------
299 // -----------------------------------------------------------------------
302 // Same as wxPGBrush, but for wxColour instead.
305 class wxPGColour
: public wxColour
308 wxPGColour( const wxColour
& colour
);
310 virtual ~wxPGColour() { }
311 void SetColour2( const wxColour
& colour
);
312 inline long GetColourAsLong() const { return m_colAsLong
; }
318 void wxPGColour::SetColour2( const wxColour
& colour
)
321 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
325 wxPGColour::wxPGColour() : wxColour()
331 wxPGColour::wxPGColour( const wxColour
& colour
) : wxColour(colour
)
333 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
337 // -----------------------------------------------------------------------
339 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
340 // and tries to commit property value.
341 // -----------------------------------------------------------------------
343 class wxPGTLWHandler
: public wxEvtHandler
347 wxPGTLWHandler( wxPropertyGrid
* pg
)
355 void OnClose( wxCloseEvent
& event
)
357 // ClearSelection forces value validation/commit.
358 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
368 wxPropertyGrid
* m_pg
;
370 DECLARE_EVENT_TABLE()
373 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
374 EVT_CLOSE(wxPGTLWHandler::OnClose
)
377 // -----------------------------------------------------------------------
379 // -----------------------------------------------------------------------
382 // wxPGCanvas acts as a graphics sub-window of the
383 // wxScrolledWindow that wxPropertyGrid is.
385 class wxPGCanvas
: public wxPanel
388 wxPGCanvas() : wxPanel()
391 virtual ~wxPGCanvas() { }
394 void OnMouseMove( wxMouseEvent
&event
)
396 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
397 pg
->OnMouseMove( event
);
400 void OnMouseClick( wxMouseEvent
&event
)
402 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
403 pg
->OnMouseClick( event
);
406 void OnMouseUp( wxMouseEvent
&event
)
408 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
409 pg
->OnMouseUp( event
);
412 void OnMouseRightClick( wxMouseEvent
&event
)
414 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
415 pg
->OnMouseRightClick( event
);
418 void OnMouseDoubleClick( wxMouseEvent
&event
)
420 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
421 pg
->OnMouseDoubleClick( event
);
424 void OnKey( wxKeyEvent
& event
)
426 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
430 void OnKeyUp( wxKeyEvent
& event
)
432 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
433 pg
->OnKeyUp( event
);
436 void OnNavigationKey( wxNavigationKeyEvent
& event
)
438 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
439 pg
->OnNavigationKey( event
);
442 void OnPaint( wxPaintEvent
& event
);
445 DECLARE_EVENT_TABLE()
449 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
450 EVT_MOTION(wxPGCanvas::OnMouseMove
)
451 EVT_PAINT(wxPGCanvas::OnPaint
)
452 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
453 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
454 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
455 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
456 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
457 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
458 EVT_CHAR(wxPGCanvas::OnKey
)
459 EVT_NAVIGATION_KEY(wxPGCanvas::OnNavigationKey
)
463 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
465 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
466 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
470 // Don't paint after destruction has begun
471 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
474 // Update everything inside the box
475 wxRect r
= GetUpdateRegion().GetBox();
477 // Repaint this rectangle
478 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
480 // We assume that the size set when grid is shown
481 // is what is desired.
482 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
485 // -----------------------------------------------------------------------
487 // -----------------------------------------------------------------------
489 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
491 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
492 EVT_IDLE(wxPropertyGrid::OnIdle
)
493 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
494 EVT_PAINT(wxPropertyGrid::OnPaint
)
495 EVT_SIZE(wxPropertyGrid::OnResize
)
496 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
497 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
498 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
499 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
500 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
501 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
502 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
503 EVT_TEXT_ENTER(wxPG_SUBID1
,wxPropertyGrid::OnCustomEditorEvent
)
504 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
508 // -----------------------------------------------------------------------
510 wxPropertyGrid::wxPropertyGrid()
516 // -----------------------------------------------------------------------
518 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
527 Create(parent
,id
,pos
,size
,style
,name
);
530 // -----------------------------------------------------------------------
532 bool wxPropertyGrid::Create( wxWindow
*parent
,
540 if ( !(style
&wxBORDER_MASK
) )
541 style
|= wxSIMPLE_BORDER
;
546 // This prevents crash under Win2K, but still
547 // enables keyboard navigation
548 if ( style
& wxTAB_TRAVERSAL
)
550 style
&= ~(wxTAB_TRAVERSAL
);
551 style
|= wxWANTS_CHARS
;
554 if ( style
& wxTAB_TRAVERSAL
)
555 style
|= wxWANTS_CHARS
;
558 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
565 // -----------------------------------------------------------------------
568 // Initialize values to defaults
570 void wxPropertyGrid::Init1()
572 #if !wxPG_USE_WXMODULE
573 if ( !wxPGGlobalVars
)
574 wxPGGlobalVars
= new wxPGGlobalVarsClass();
577 // Register editor classes, if necessary.
578 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
579 RegisterDefaultEditors();
582 m_pState
= (wxPropertyGridPageState
*) NULL
;
583 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
584 m_selected
= (wxPGProperty
*) NULL
;
586 m_propHover
= (wxPGProperty
*) NULL
;
587 m_eventObject
= this;
588 m_curFocused
= (wxWindow
*) NULL
;
590 m_inDoPropertyChanged
= 0;
591 m_inCommitChangesFromEditor
= 0;
592 m_inDoSelectProperty
= 0;
593 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
599 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
600 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
601 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
602 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
603 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
604 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
605 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
606 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
607 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
608 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
609 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
610 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
611 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
613 m_coloursCustomized
= 0;
618 #if wxPG_DOUBLE_BUFFER
619 m_doubleBuffer
= (wxBitmap
*) NULL
;
622 m_windowsToDelete
= NULL
;
624 #ifndef wxPG_ICON_WIDTH
630 m_iconWidth
= wxPG_ICON_WIDTH
;
635 m_gutterWidth
= wxPG_GUTTER_MIN
;
636 m_subgroup_extramargin
= 10;
640 m_width
= m_height
= 0;
642 SetButtonShortcut(0);
644 m_keyComboConsumed
= 0;
646 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
649 m_chgInfo_changedProperty
= NULL
;
652 // -----------------------------------------------------------------------
655 // Initialize after parent etc. set
657 void wxPropertyGrid::Init2()
659 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
662 // Smaller controls on Mac
663 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
666 // Now create state, if one didn't exist already
667 // (wxPropertyGridManager might have created it for us).
670 m_pState
= CreateState();
671 m_pState
->m_pPropGrid
= this;
672 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
675 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
676 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
678 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
680 m_pState
->InitNonCatMode();
682 m_pState
->m_properties
= m_pState
->m_abcArray
;
685 GetClientSize(&m_width
,&m_height
);
687 #ifndef wxPG_ICON_WIDTH
688 // create two bitmap nodes for drawing
689 m_expandbmp
= new wxBitmap(expand_xpm
);
690 m_collbmp
= new wxBitmap(collapse_xpm
);
692 // calculate average font height for bitmap centering
694 m_iconWidth
= m_expandbmp
->GetWidth();
695 m_iconHeight
= m_expandbmp
->GetHeight();
698 m_curcursor
= wxCURSOR_ARROW
;
699 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
701 // adjust bitmap icon y position so they are centered
702 m_vspacing
= wxPG_DEFAULT_VSPACING
;
706 wxFont useFont
= wxScrolledWindow::GetFont();
707 wxScrolledWindow::SetOwnFont( useFont
);
710 // This should be otherwise called by SetOwnFont
711 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
713 // Add base brush item
714 m_arrBgBrushes
.Add((void*)new wxPGBrush());
716 // Add base colour items
717 m_arrFgCols
.Add((void*)new wxPGColour());
718 m_arrFgCols
.Add((void*)new wxPGColour());
722 // This helps with flicker
723 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
726 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
727 m_tlp
= ::wxGetTopLevelParent(this);
728 m_tlwHandler
= handler
;
729 m_tlp
->PushEventHandler(handler
);
731 // set virtual size to this window size
732 wxSize wndsize
= GetSize();
733 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
735 m_timeCreated
= ::wxGetLocalTimeMillis();
737 m_canvas
= new wxPGCanvas();
738 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
739 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
740 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
742 m_iFlags
|= wxPG_FL_INITIALIZED
;
744 m_ncWidth
= wndsize
.GetWidth();
746 // Need to call OnResize handler or size given in constructor/Create
748 wxSizeEvent
sizeEvent(wndsize
,0);
752 // -----------------------------------------------------------------------
754 wxPropertyGrid::~wxPropertyGrid()
758 DoSelectProperty(NULL
);
760 // This should do prevent things from going too badly wrong
761 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
763 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
764 m_canvas
->ReleaseMouse();
766 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
767 m_tlp
->RemoveEventHandler(handler
);
771 if ( IsEditorsValueModified() )
772 ::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).)"),
773 wxS("wxPropertyGrid Debug Warning") );
776 #if wxPG_DOUBLE_BUFFER
777 if ( m_doubleBuffer
)
778 delete m_doubleBuffer
;
781 delete m_windowsToDelete
;
783 //m_selected = (wxPGProperty*) NULL;
785 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
788 delete m_cursorSizeWE
;
790 #ifndef wxPG_ICON_WIDTH
795 // Delete cached text colours.
796 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
798 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
801 // Delete cached brushes.
802 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
804 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
807 // Delete common value records
808 for ( i
=0; i
<m_commonValues
.size(); i
++ )
810 delete GetCommonValue(i
);
814 // -----------------------------------------------------------------------
816 bool wxPropertyGrid::Destroy()
818 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
819 m_canvas
->ReleaseMouse();
821 return wxScrolledWindow::Destroy();
824 // -----------------------------------------------------------------------
826 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
828 return new wxPropertyGridPageState();
831 // -----------------------------------------------------------------------
832 // wxPropertyGrid overridden wxWindow methods
833 // -----------------------------------------------------------------------
835 void wxPropertyGrid::SetWindowStyleFlag( long style
)
837 long old_style
= m_windowStyle
;
839 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
841 wxASSERT( m_pState
);
843 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
846 EnableCategories( true );
848 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
850 // Disable categories
851 EnableCategories( false );
853 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
859 PrepareAfterItemsAdded();
861 m_pState
->m_itemsAdded
= 1;
863 #if wxPG_SUPPORT_TOOLTIPS
864 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
870 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
871 SetToolTip ( tooltip );
872 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
875 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
880 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
885 wxScrolledWindow::SetWindowStyleFlag ( style
);
887 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
889 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
891 CalculateFontAndBitmapStuff( m_vspacing
);
897 // -----------------------------------------------------------------------
899 void wxPropertyGrid::Freeze()
903 wxScrolledWindow::Freeze();
908 // -----------------------------------------------------------------------
910 void wxPropertyGrid::Thaw()
916 wxScrolledWindow::Thaw();
917 RecalculateVirtualSize();
918 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
922 // Force property re-selection
924 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
928 // -----------------------------------------------------------------------
930 void wxPropertyGrid::SetExtraStyle( long exStyle
)
932 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
934 #if defined(__WXMSW__)
937 // Don't use WS_EX_COMPOSITED just now.
940 if ( m_iFlags & wxPG_FL_IN_MANAGER )
941 hWnd = (HWND)GetParent()->GetHWND();
943 hWnd = (HWND)GetHWND();
945 ::SetWindowLong( hWnd, GWL_EXSTYLE,
946 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
949 //#elif defined(__WXGTK20__)
951 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
952 // truly was double-buffered.
953 if ( !this->IsDoubleBuffered() )
955 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
959 #if wxPG_DOUBLE_BUFFER
960 delete m_doubleBuffer
;
961 m_doubleBuffer
= NULL
;
966 wxScrolledWindow::SetExtraStyle( exStyle
);
968 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
969 m_pState
->InitNonCatMode();
971 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
972 m_windowStyle
|= wxPG_TOOLTIPS
;
975 wxPGGlobalVars
->m_extraStyle
= exStyle
;
978 // -----------------------------------------------------------------------
980 // returns the best acceptable minimal size
981 wxSize
wxPropertyGrid::DoGetBestSize() const
984 if ( m_lineHeight
> hei
)
986 wxSize sz
= wxSize( 60, hei
+40 );
992 // -----------------------------------------------------------------------
993 // wxPropertyGrid Font and Colour Methods
994 // -----------------------------------------------------------------------
996 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1000 m_captionFont
= wxScrolledWindow::GetFont();
1002 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1003 m_subgroup_extramargin
= x
+ (x
/2);
1006 #if wxPG_USE_RENDERER_NATIVE
1007 m_iconWidth
= wxPG_ICON_WIDTH
;
1008 #elif wxPG_ICON_WIDTH
1010 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1011 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1012 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1016 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1017 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1018 m_gutterWidth
= wxPG_GUTTER_MIN
;
1021 if ( vspacing
<= 1 ) vdiv
= 12;
1022 else if ( vspacing
>= 3 ) vdiv
= 3;
1024 m_spacingy
= m_fontHeight
/ vdiv
;
1025 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1026 m_spacingy
= wxPG_YSPACING_MIN
;
1029 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1030 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1032 m_captionFont
.SetWeight(wxBOLD
);
1033 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1035 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1038 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1039 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1042 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1044 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1045 RecalculateVirtualSize();
1047 InvalidateBestSize();
1050 // -----------------------------------------------------------------------
1052 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1058 // -----------------------------------------------------------------------
1060 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1061 int ga
= 1000, int ba
= 1000,
1062 bool forceDifferent
= false)
1069 // Recursion guard (allow 2 max)
1070 static int isinside
= 0;
1072 wxCHECK_MSG( isinside
< 3,
1074 wxT("wxPGAdjustColour should not be recursively called more than once") );
1079 int g
= src
.Green();
1082 if ( r2
>255 ) r2
= 255;
1083 else if ( r2
<0) r2
= 0;
1085 if ( g2
>255 ) g2
= 255;
1086 else if ( g2
<0) g2
= 0;
1088 if ( b2
>255 ) b2
= 255;
1089 else if ( b2
<0) b2
= 0;
1091 // Make sure they are somewhat different
1092 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1093 dst
= wxPGAdjustColour(src
,-(ra
*2));
1095 dst
= wxColour(r2
,g2
,b2
);
1097 // Recursion guard (allow 2 max)
1104 static int wxPGGetColAvg( const wxColour
& col
)
1106 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1110 void wxPropertyGrid::RegainColours()
1112 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1114 if ( !(m_coloursCustomized
& 0x0002) )
1116 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1118 // Make sure colour is dark enough
1120 int colDec
= wxPGGetColAvg(col
) - 230;
1122 int colDec
= wxPGGetColAvg(col
) - 200;
1125 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1130 if ( !(m_coloursCustomized
& 0x0001) )
1131 m_colMargin
= m_colCapBack
;
1133 if ( !(m_coloursCustomized
& 0x0004) )
1140 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1141 m_colCapFore
= capForeCol
;
1143 // Set the cached colour as well.
1144 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1147 if ( !(m_coloursCustomized
& 0x0008) )
1149 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1150 m_colPropBack
= bgCol
;
1152 // Set the cached brush as well.
1153 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1156 if ( !(m_coloursCustomized
& 0x0010) )
1158 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1159 m_colPropFore
= fgCol
;
1161 // Set the cached colour as well.
1162 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1165 if ( !(m_coloursCustomized
& 0x0020) )
1166 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1168 if ( !(m_coloursCustomized
& 0x0040) )
1169 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1171 if ( !(m_coloursCustomized
& 0x0080) )
1172 m_colLine
= m_colCapBack
;
1174 if ( !(m_coloursCustomized
& 0x0100) )
1175 m_colDisPropFore
= m_colCapFore
;
1177 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1180 // -----------------------------------------------------------------------
1182 void wxPropertyGrid::ResetColours()
1184 m_coloursCustomized
= 0;
1191 // -----------------------------------------------------------------------
1193 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1195 // Must disable active editor.
1198 bool selRes
= ClearSelection();
1199 wxPG_CHECK_MSG_DBG( selRes
,
1201 wxT("failed to deselect a property (editor probably had invalid value)") );
1204 // TODO: Following code is disabled with wxMac because
1205 // it is reported to fail. I (JMS) cannot debug it
1206 // personally right now.
1207 #if !defined(__WXMAC__)
1208 bool res
= wxScrolledWindow::SetFont( font
);
1211 CalculateFontAndBitmapStuff( m_vspacing
);
1214 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1222 // TODO: Remove after SetFont crash fixed.
1223 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1225 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."));
1231 // -----------------------------------------------------------------------
1233 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1236 m_coloursCustomized
|= 0x80;
1240 // -----------------------------------------------------------------------
1242 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1245 m_coloursCustomized
|= 0x01;
1249 // -----------------------------------------------------------------------
1251 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1253 m_colPropBack
= col
;
1254 m_coloursCustomized
|= 0x08;
1256 // Set the cached brush as well.
1257 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1262 // -----------------------------------------------------------------------
1264 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1266 m_colPropFore
= col
;
1267 m_coloursCustomized
|= 0x10;
1269 // Set the cached colour as well.
1270 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1275 // -----------------------------------------------------------------------
1277 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1279 m_colEmptySpace
= col
;
1284 // -----------------------------------------------------------------------
1286 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1288 m_colDisPropFore
= col
;
1289 m_coloursCustomized
|= 0x100;
1293 // -----------------------------------------------------------------------
1295 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1298 m_coloursCustomized
|= 0x20;
1302 // -----------------------------------------------------------------------
1304 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1307 m_coloursCustomized
|= 0x40;
1311 // -----------------------------------------------------------------------
1313 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1316 m_coloursCustomized
|= 0x02;
1320 // -----------------------------------------------------------------------
1322 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1325 m_coloursCustomized
|= 0x04;
1327 // Set the cached colour as well.
1328 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1333 // -----------------------------------------------------------------------
1335 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1337 unsigned char ind
= index
;
1339 p
->m_bgColIndex
= ind
;
1342 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1343 SetBackgroundColourIndex(p
->Item(i
),index
);
1346 // -----------------------------------------------------------------------
1348 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1350 wxPG_PROP_ARG_CALL_PROLOG()
1355 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1357 // As it is most likely that the previous colour is used, start comparison
1359 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1361 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1370 colInd
= m_arrBgBrushes
.size();
1371 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1372 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1376 SetBackgroundColourIndex(p
,colInd
);
1378 // If this was on a visible grid, then draw it.
1379 DrawItemAndChildren(p
);
1382 // -----------------------------------------------------------------------
1384 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1386 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1388 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1391 // -----------------------------------------------------------------------
1393 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1395 unsigned char ind
= index
;
1397 p
->m_fgColIndex
= ind
;
1399 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1402 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1403 SetTextColourIndex( p
->Item(i
), index
, flags
);
1407 // -----------------------------------------------------------------------
1409 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1414 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1416 // As it is most likely that the previous colour is used, start comparison
1418 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1420 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1429 colInd
= m_arrFgCols
.size();
1430 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1431 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1437 // -----------------------------------------------------------------------
1439 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1442 wxPG_PROP_ARG_CALL_PROLOG()
1444 if ( p
->IsCategory() )
1446 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1447 cat
->SetTextColIndex(CacheColour(colour
));
1453 flags
|= wxPG_RECURSE
;
1454 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1456 DrawItemAndChildren(p
);
1459 // -----------------------------------------------------------------------
1461 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1463 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1465 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1468 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1470 wxPG_PROP_ARG_CALL_PROLOG()
1472 SetBackgroundColourIndex( p
, 0 );
1473 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1475 if ( p
->IsCategory() )
1477 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1478 cat
->SetTextColIndex(1);
1482 // -----------------------------------------------------------------------
1483 // wxPropertyGrid property adding and removal
1484 // -----------------------------------------------------------------------
1486 void wxPropertyGrid::PrepareAfterItemsAdded()
1488 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1490 m_pState
->m_itemsAdded
= 0;
1492 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1495 RecalculateVirtualSize();
1498 // -----------------------------------------------------------------------
1499 // wxPropertyGrid property value setting and getting
1500 // -----------------------------------------------------------------------
1502 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1504 m_pState
->DoSetPropertyValueUnspecified(p
);
1505 DrawItemAndChildren(p
);
1507 wxPGProperty
* parent
= p
->GetParent();
1508 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1511 parent
= parent
->GetParent();
1515 // -----------------------------------------------------------------------
1516 // wxPropertyGrid property operations
1517 // -----------------------------------------------------------------------
1519 void wxPropertyGrid::DoSetPropertyName( wxPGProperty
* p
, const wxString
& newname
)
1521 wxCHECK_RET( p
, wxT("invalid property id") );
1523 if ( p
->GetBaseName().Len() ) m_pState
->m_dictName
.erase( p
->GetBaseName() );
1524 if ( newname
.Len() ) m_pState
->m_dictName
[newname
] = (void*) p
;
1526 p
->DoSetName(newname
);
1529 // -----------------------------------------------------------------------
1531 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1533 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1537 bool changed
= false;
1539 // Is it inside collapsed section?
1540 if ( !p
->IsVisible() )
1543 wxPGProperty
* parent
= p
->GetParent();
1544 wxPGProperty
* grandparent
= parent
->GetParent();
1546 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1547 Expand( grandparent
);
1555 GetViewStart(&vx
,&vy
);
1556 vy
*=wxPG_PIXELS_PER_UNIT
;
1562 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1563 m_iFlags
|= wxPG_FL_SCROLLED
;
1566 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1568 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1569 m_iFlags
|= wxPG_FL_SCROLLED
;
1579 // -----------------------------------------------------------------------
1580 // wxPropertyGrid helper methods called by properties
1581 // -----------------------------------------------------------------------
1583 // Control font changer helper.
1584 void wxPropertyGrid::SetCurControlBoldFont()
1586 wxASSERT( m_wndEditor
);
1587 m_wndEditor
->SetFont( m_captionFont
);
1590 // -----------------------------------------------------------------------
1592 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1595 #if wxPG_SMALL_SCREEN
1596 // On small-screen devices, always show dialogs with default position and size.
1597 return wxDefaultPosition
;
1599 int splitterX
= GetSplitterPosition();
1603 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1605 ImprovedClientToScreen( &x
, &y
);
1607 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1608 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1615 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1625 new_y
= y
+ m_lineHeight
;
1627 return wxPoint(new_x
,new_y
);
1631 // -----------------------------------------------------------------------
1633 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1635 if ( src_str
.length() == 0 )
1641 bool prev_is_slash
= false;
1643 wxString::const_iterator i
= src_str
.begin();
1647 for ( ; i
!= src_str
.end(); i
++ )
1651 if ( a
!= wxS('\\') )
1653 if ( !prev_is_slash
)
1659 if ( a
== wxS('n') )
1662 dst_str
<< wxS('\n');
1664 dst_str
<< wxS('\n');
1667 else if ( a
== wxS('t') )
1668 dst_str
<< wxS('\t');
1672 prev_is_slash
= false;
1676 if ( prev_is_slash
)
1678 dst_str
<< wxS('\\');
1679 prev_is_slash
= false;
1683 prev_is_slash
= true;
1690 // -----------------------------------------------------------------------
1692 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1694 if ( src_str
.length() == 0 )
1700 wxString::const_iterator i
= src_str
.begin();
1701 wxUniChar prev_a
= wxS('\0');
1705 for ( ; i
!= src_str
.end(); i
++ )
1709 if ( a
>= wxS(' ') )
1711 // This surely is not something that requires an escape sequence.
1716 // This might need...
1717 if ( a
== wxS('\r') )
1719 // DOS style line end.
1720 // Already taken care below
1722 else if ( a
== wxS('\n') )
1723 // UNIX style line end.
1724 dst_str
<< wxS("\\n");
1725 else if ( a
== wxS('\t') )
1727 dst_str
<< wxS('\t');
1730 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1740 // -----------------------------------------------------------------------
1742 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1746 return (wxPGProperty
*) NULL
;
1749 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1752 // -----------------------------------------------------------------------
1753 // wxPropertyGrid graphics related methods
1754 // -----------------------------------------------------------------------
1756 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1760 // Update everything inside the box
1761 wxRect r
= GetUpdateRegion().GetBox();
1763 dc
.SetPen(m_colEmptySpace
);
1764 dc
.SetBrush(m_colEmptySpace
);
1765 dc
.DrawRectangle(r
);
1768 // -----------------------------------------------------------------------
1770 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1771 wxPGProperty
* property
) const
1773 // Prepare rectangle to be used
1775 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1776 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1778 #if (wxPG_USE_RENDERER_NATIVE)
1780 #elif wxPG_ICON_WIDTH
1781 // Drawing expand/collapse button manually
1782 dc
.SetPen(m_colPropFore
);
1783 if ( property
->IsCategory() )
1784 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1786 dc
.SetBrush(m_colPropBack
);
1788 dc
.DrawRectangle( r
);
1789 int _y
= r
.y
+(m_iconWidth
/2);
1790 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1795 if ( property
->IsExpanded() )
1797 // wxRenderer functions are non-mutating in nature, so it
1798 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1799 // Hopefully this does not cause problems.
1800 #if (wxPG_USE_RENDERER_NATIVE)
1801 wxRendererNative::Get().DrawTreeItemButton(
1807 #elif wxPG_ICON_WIDTH
1816 #if (wxPG_USE_RENDERER_NATIVE)
1817 wxRendererNative::Get().DrawTreeItemButton(
1823 #elif wxPG_ICON_WIDTH
1824 int _x
= r
.x
+(m_iconWidth
/2);
1825 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1831 #if (wxPG_USE_RENDERER_NATIVE)
1833 #elif wxPG_ICON_WIDTH
1836 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1840 // -----------------------------------------------------------------------
1843 // This is the one called by OnPaint event handler and others.
1844 // topy and bottomy are already unscrolled (ie. physical)
1846 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1848 unsigned int bottomy
,
1849 const wxRect
* clipRect
)
1851 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1853 m_pState
->EnsureVirtualHeight();
1855 wxRect tempClipRect
;
1858 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1859 clipRect
= &tempClipRect
;
1862 // items added check
1863 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1865 int paintFinishY
= 0;
1867 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1870 bool isBuffered
= false;
1872 #if wxPG_DOUBLE_BUFFER
1873 wxMemoryDC
* bufferDC
= NULL
;
1875 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1877 if ( !m_doubleBuffer
)
1879 paintFinishY
= clipRect
->y
;
1884 bufferDC
= new wxMemoryDC();
1886 // If nothing was changed, then just copy from double-buffer
1887 bufferDC
->SelectObject( *m_doubleBuffer
);
1897 dc
.SetClippingRegion( *clipRect
);
1898 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1901 #if wxPG_DOUBLE_BUFFER
1904 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1905 bufferDC
, 0, 0, wxCOPY
);
1906 dc
.DestroyClippingRegion(); // Is this really necessary?
1912 // Clear area beyond bottomY?
1913 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1915 dc
.SetPen(m_colEmptySpace
);
1916 dc
.SetBrush(m_colEmptySpace
);
1917 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1921 // -----------------------------------------------------------------------
1923 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1924 const wxPGProperty
* firstItem
,
1925 const wxPGProperty
* lastItem
,
1926 const wxRect
* clipRect
,
1927 bool isBuffered
) const
1929 // TODO: This should somehow be eliminated.
1930 wxRect tempClipRect
;
1933 wxASSERT(firstItem
);
1935 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1936 clipRect
= &tempClipRect
;
1940 firstItem
= DoGetItemAtY(clipRect
->y
);
1944 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1946 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1949 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1952 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1953 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1955 int lh
= m_lineHeight
;
1958 int lastItemBottomY
;
1960 firstItemTopY
= clipRect
->y
;
1961 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1963 // Align y coordinates to item boundaries
1964 firstItemTopY
-= firstItemTopY
% lh
;
1965 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1966 lastItemBottomY
-= 1;
1968 // Entire range outside scrolled, visible area?
1969 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1972 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1976 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1977 firstItem->GetLabel().c_str(),
1978 lastItem->GetLabel().c_str(),
1979 (int)(lastItemBottomY - firstItemTopY),
1981 (unsigned long)clipRect );
1986 long windowStyle
= m_windowStyle
;
1992 // With wxPG_DOUBLE_BUFFER, do double buffering
1993 // - buffer's y = 0, so align cliprect and coordinates to that
1995 #if wxPG_DOUBLE_BUFFER
2001 xRelMod
= clipRect
->x
;
2002 yRelMod
= clipRect
->y
;
2005 // clipRect conversion
2013 firstItemTopY
-= yRelMod
;
2014 lastItemBottomY
-= yRelMod
;
2017 wxUnusedVar(isBuffered
);
2020 int x
= m_marginWidth
- xRelMod
;
2022 const wxFont
& normalfont
= m_font
;
2024 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
2026 bool isEnabled
= IsEnabled();
2029 // Prepare some pens and brushes that are often changed to.
2032 wxBrush
marginBrush(m_colMargin
);
2033 wxPen
marginPen(m_colMargin
);
2034 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2035 wxPen
linepen(m_colLine
,1,wxSOLID
);
2037 // pen that has same colour as text
2038 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2041 // Clear margin with background colour
2043 dc
.SetBrush( marginBrush
);
2044 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2046 dc
.SetPen( *wxTRANSPARENT_PEN
);
2047 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2050 const wxPGProperty
* selected
= m_selected
;
2051 const wxPropertyGridPageState
* state
= m_pState
;
2053 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2054 bool wasSelectedPainted
= false;
2057 // TODO: Only render columns that are within clipping region.
2059 dc
.SetFont(normalfont
);
2061 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2062 int endScanBottomY
= lastItemBottomY
+ lh
;
2063 int y
= firstItemTopY
;
2066 // Pregenerate list of visible properties.
2067 wxArrayPGProperty visPropArray
;
2068 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2070 for ( ; !it
.AtEnd(); it
.Next() )
2072 const wxPGProperty
* p
= *it
;
2074 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2076 visPropArray
.push_back((wxPGProperty
*)p
);
2078 if ( y
> endScanBottomY
)
2085 visPropArray
.push_back(NULL
);
2087 wxPGProperty
* nextP
= visPropArray
[0];
2089 int gridWidth
= state
->m_width
;
2092 for ( unsigned int arrInd
=1;
2093 nextP
&& y
<= lastItemBottomY
;
2096 wxPGProperty
* p
= nextP
;
2097 nextP
= visPropArray
[arrInd
];
2099 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2100 int textMarginHere
= x
;
2101 int renderFlags
= wxPGCellRenderer::Control
;
2103 int greyDepth
= m_marginWidth
;
2104 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2105 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2107 int greyDepthX
= greyDepth
- xRelMod
;
2109 // Use basic depth if in non-categoric mode and parent is base array.
2110 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2112 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2115 // Paint margin area
2116 dc
.SetBrush(marginBrush
);
2117 dc
.SetPen(marginPen
);
2118 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2120 dc
.SetPen( linepen
);
2125 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2131 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2133 sx
+= state
->m_colWidths
[si
];
2134 dc
.DrawLine( sx
, y
, sx
, y2
);
2137 // Horizontal Line, below
2138 // (not if both this and next is category caption)
2139 if ( p
->IsCategory() &&
2140 nextP
&& nextP
->IsCategory() )
2141 dc
.SetPen(m_colCapBack
);
2143 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2145 if ( p
== selected
)
2147 renderFlags
|= wxPGCellRenderer::Selected
;
2148 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2149 wasSelectedPainted
= true;
2157 if ( p
->IsCategory() )
2159 if ( p
->m_fgColIndex
== 0 )
2160 rowFgCol
= m_colCapFore
;
2162 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2163 rowBgBrush
= wxBrush(m_colCapBack
);
2165 else if ( p
!= selected
)
2167 // Disabled may get different colour.
2168 if ( !p
->IsEnabled() )
2169 rowFgCol
= m_colDisPropFore
;
2171 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2173 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2177 // Selected gets different colour.
2178 if ( reallyFocused
)
2180 rowFgCol
= m_colSelFore
;
2181 rowBgBrush
= wxBrush(m_colSelBack
);
2183 else if ( isEnabled
)
2185 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2186 rowBgBrush
= marginBrush
;
2190 rowFgCol
= m_colDisPropFore
;
2191 rowBgBrush
= wxBrush(m_colSelBack
);
2195 bool fontChanged
= false;
2197 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2202 if ( p
->IsCategory() )
2204 // Captions are all cells merged as one
2205 dc
.SetFont(m_captionFont
);
2207 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2209 dc
.SetBrush(rowBgBrush
);
2210 dc
.SetPen(rowBgBrush
.GetColour());
2211 dc
.SetTextForeground(rowFgCol
);
2213 dc
.DrawRectangle(cellRect
);
2216 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2217 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2220 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2221 DrawExpanderButton( dc
, butRect
, p
);
2225 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2227 dc
.SetFont(m_captionFont
);
2233 int nextCellWidth
= state
->m_colWidths
[0];
2234 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2235 int textXAdd
= textMarginHere
- greyDepthX
;
2237 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2239 cellRect
.width
= nextCellWidth
- 1;
2241 bool ctrlCell
= false;
2244 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2246 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2247 dc
.SetBrush(editorBgCol
);
2248 dc
.SetPen(editorBgCol
);
2249 dc
.SetTextForeground(m_colPropFore
);
2251 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2256 dc
.SetBrush(rowBgBrush
);
2257 dc
.SetPen(rowBgBrush
.GetColour());
2258 dc
.SetTextForeground(rowFgCol
);
2261 dc
.DrawRectangle(cellRect
);
2264 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2265 DrawExpanderButton( dc
, butRect
, p
);
2267 dc
.SetClippingRegion(cellRect
);
2269 cellRect
.x
+= textXAdd
;
2270 cellRect
.width
-= textXAdd
;
2275 wxPGCellRenderer
* renderer
;
2276 int cmnVal
= p
->GetCommonValue();
2277 if ( cmnVal
== -1 || ci
!= 1 )
2279 renderer
= p
->GetCellRenderer(ci
);
2280 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2284 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2285 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2289 cellX
+= state
->m_colWidths
[ci
];
2290 if ( ci
< (state
->m_colWidths
.size()-1) )
2291 nextCellWidth
= state
->m_colWidths
[ci
+1];
2293 dc
.DestroyClippingRegion(); // Is this really necessary?
2299 dc
.SetFont(normalfont
);
2304 // Refresh editor controls (seems not needed on msw)
2305 // NOTE: This code is mandatory for GTK!
2306 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2307 if ( wasSelectedPainted
)
2310 m_wndEditor
->Refresh();
2312 m_wndEditor2
->Refresh();
2319 // -----------------------------------------------------------------------
2321 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2325 if ( m_width
< 10 || m_height
< 10 ||
2326 !m_pState
->m_properties
->GetChildCount() ||
2327 p1
== (wxPGProperty
*) NULL
)
2328 return wxRect(0,0,0,0);
2333 // Return rect which encloses the given property range
2335 int visTop
= p1
->GetY();
2338 visBottom
= p2
->GetY() + m_lineHeight
;
2340 visBottom
= m_height
+ visTop
;
2342 // If seleced property is inside the range, we'll extend the range to include
2344 wxPGProperty
* selected
= m_selected
;
2347 int selectedY
= selected
->GetY();
2348 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2350 wxWindow
* editor
= GetEditorControl();
2353 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2354 if ( visBottom2
> visBottom
)
2355 visBottom
= visBottom2
;
2360 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2363 // -----------------------------------------------------------------------
2365 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2370 if ( m_pState
->m_itemsAdded
)
2371 PrepareAfterItemsAdded();
2373 wxRect r
= GetPropertyRect(p1
, p2
);
2376 m_canvas
->RefreshRect(r
);
2380 // -----------------------------------------------------------------------
2382 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2384 if ( p
== m_selected
)
2385 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2387 DrawItemAndChildren(p
);
2390 // -----------------------------------------------------------------------
2392 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2397 // Draw item, children, and parent too, if it is not category
2398 wxPGProperty
* parent
= p
->GetParent();
2401 !parent
->IsCategory() &&
2402 parent
->GetParent() )
2405 parent
= parent
->GetParent();
2408 DrawItemAndChildren(p
);
2411 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2413 wxCHECK_RET( p
, wxT("invalid property id") );
2415 // Do not draw if in non-visible page
2416 if ( p
->GetParentState() != m_pState
)
2419 // do not draw a single item if multiple pending
2420 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2423 wxWindow
* wndPrimary
= GetEditorControl();
2425 // Update child control.
2426 if ( m_selected
&& m_selected
->GetParent() == p
)
2427 m_selected
->UpdateControl(wndPrimary
);
2429 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2431 DrawItems(p
, lastDrawn
);
2434 // -----------------------------------------------------------------------
2436 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2437 const wxRect
*rect
)
2439 PrepareAfterItemsAdded();
2441 wxWindow::Refresh(false);
2443 // TODO: Coordinate translation
2444 m_canvas
->Refresh(false, rect
);
2446 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2447 // I think this really helps only GTK+1.2
2448 if ( m_wndEditor
) m_wndEditor
->Refresh();
2449 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2453 // -----------------------------------------------------------------------
2454 // wxPropertyGrid global operations
2455 // -----------------------------------------------------------------------
2457 void wxPropertyGrid::Clear()
2461 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2462 wxPG_CHECK_RET_DBG( selRes
,
2463 wxT("failed to deselect a property (editor probably had invalid value)") );
2466 m_pState
->DoClear();
2472 RecalculateVirtualSize();
2474 // Need to clear some area at the end
2476 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2479 // -----------------------------------------------------------------------
2481 bool wxPropertyGrid::EnableCategories( bool enable
)
2483 if ( !ClearSelection() )
2489 // Enable categories
2492 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2497 // Disable categories
2499 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2502 if ( !m_pState
->EnableCategories(enable
) )
2507 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2509 m_pState
->m_itemsAdded
= 1; // force
2510 PrepareAfterItemsAdded();
2514 m_pState
->m_itemsAdded
= 1;
2516 // No need for RecalculateVirtualSize() here - it is already called in
2517 // wxPropertyGridPageState method above.
2524 // -----------------------------------------------------------------------
2526 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2528 wxASSERT( pNewState
);
2529 wxASSERT( pNewState
->GetGrid() );
2531 if ( pNewState
== m_pState
)
2534 wxPGProperty
* oldSelection
= m_selected
;
2539 bool selRes
= ClearSelection();
2540 wxPG_CHECK_RET_DBG( selRes
,
2541 wxT("failed to deselect a property (editor probably had invalid value)") );
2544 m_pState
->m_selected
= oldSelection
;
2546 bool orig_mode
= m_pState
->IsInNonCatMode();
2547 bool new_state_mode
= pNewState
->IsInNonCatMode();
2549 m_pState
= pNewState
;
2552 int pgWidth
= GetClientSize().x
;
2553 if ( HasVirtualWidth() )
2555 int minWidth
= pgWidth
;
2556 if ( pNewState
->m_width
< minWidth
)
2558 pNewState
->m_width
= minWidth
;
2559 pNewState
->CheckColumnWidths();
2565 // Just in case, fully re-center splitter
2566 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2567 pNewState
->m_fSplitterX
= -1.0;
2569 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2572 m_propHover
= (wxPGProperty
*) NULL
;
2574 // If necessary, convert state to correct mode.
2575 if ( orig_mode
!= new_state_mode
)
2577 // This should refresh as well.
2578 EnableCategories( orig_mode
?false:true );
2580 else if ( !m_frozen
)
2582 // Refresh, if not frozen.
2583 if ( m_pState
->m_itemsAdded
)
2584 PrepareAfterItemsAdded();
2587 if ( m_pState
->m_selected
)
2588 DoSelectProperty( m_pState
->m_selected
);
2590 RecalculateVirtualSize(0);
2594 m_pState
->m_itemsAdded
= 1;
2597 // -----------------------------------------------------------------------
2599 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2601 wxPG_PROP_ARG_CALL_PROLOG()
2603 m_pState
->SortChildren( p
);
2606 // -----------------------------------------------------------------------
2608 void wxPropertyGrid::Sort()
2610 bool selRes
= ClearSelection(); // This must be before state clear
2611 wxPG_CHECK_RET_DBG( selRes
,
2612 wxT("failed to deselect a property (editor probably had invalid value)") );
2617 // -----------------------------------------------------------------------
2619 // Call to SetSplitterPosition will always disable splitter auto-centering
2620 // if parent window is shown.
2621 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2623 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2626 wxPropertyGridPageState
* state
= m_pState
;
2628 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2633 CorrectEditorWidgetSizeX();
2639 // -----------------------------------------------------------------------
2641 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2643 SetSplitterPosition( m_width
/2, true );
2644 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2645 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2648 // -----------------------------------------------------------------------
2649 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2650 // -----------------------------------------------------------------------
2652 // Returns nearest paint visible property (such that will be painted unless
2653 // window is scrolled or resized). If given property is paint visible, then
2654 // it itself will be returned
2655 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2657 int vx
,vy1
;// Top left corner of client
2658 GetViewStart(&vx
,&vy1
);
2659 vy1
*= wxPG_PIXELS_PER_UNIT
;
2661 int vy2
= vy1
+ m_height
;
2662 int propY
= p
->GetY2(m_lineHeight
);
2664 if ( (propY
+ m_lineHeight
) < vy1
)
2667 return DoGetItemAtY( vy1
);
2669 else if ( propY
> vy2
)
2672 return DoGetItemAtY( vy2
);
2675 // Itself paint visible
2680 // -----------------------------------------------------------------------
2682 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2686 m_pushButKeyCode
= keycode
;
2687 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2688 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2692 m_pushButKeyCode
= WXK_DOWN
;
2693 m_pushButKeyCodeNeedsCtrl
= 0;
2694 m_pushButKeyCodeNeedsAlt
= 1;
2698 // -----------------------------------------------------------------------
2699 // Methods related to change in value, value modification and sending events
2700 // -----------------------------------------------------------------------
2702 // commits any changes in editor of selected property
2703 // return true if validation did not fail
2704 // flags are same as with DoSelectProperty
2705 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2707 // Committing already?
2708 if ( m_inCommitChangesFromEditor
)
2711 // Don't do this if already processing editor event. It might
2712 // induce recursive dialogs and crap like that.
2713 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2715 if ( m_inDoPropertyChanged
)
2722 IsEditorsValueModified() &&
2723 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2726 m_inCommitChangesFromEditor
= 1;
2728 wxVariant
variant(m_selected
->GetValueRef());
2729 bool valueIsPending
= false;
2731 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2732 // due to another window getting focus
2733 wxWindow
* oldFocus
= m_curFocused
;
2735 bool validationFailure
= false;
2736 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2738 m_chgInfo_changedProperty
= NULL
;
2740 // If truly modified, schedule value as pending.
2741 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2743 if ( DoEditorValidate() &&
2744 PerformValidation(m_selected
, variant
) )
2746 valueIsPending
= true;
2750 validationFailure
= true;
2755 EditorsValueWasNotModified();
2760 m_inCommitChangesFromEditor
= 0;
2762 if ( validationFailure
&& !forceSuccess
)
2766 oldFocus
->SetFocus();
2767 m_curFocused
= oldFocus
;
2770 res
= OnValidationFailure(m_selected
, variant
);
2772 // Now prevent further validation failure messages
2775 EditorsValueWasNotModified();
2776 OnValidationFailureReset(m_selected
);
2779 else if ( valueIsPending
)
2781 DoPropertyChanged( m_selected
, flags
);
2782 EditorsValueWasNotModified();
2791 // -----------------------------------------------------------------------
2793 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2796 // Runs all validation functionality.
2797 // Returns true if value passes all tests.
2800 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2802 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2804 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2809 // Adapt list to child values, if necessary
2810 wxVariant listValue
= pendingValue
;
2811 wxVariant
* pPendingValue
= &pendingValue
;
2812 wxVariant
* pList
= NULL
;
2814 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2815 // string value, then we need treat as it was changed instead
2816 // (or, in addition, as is the case with composite string parent).
2817 // This includes creating list variant for child values.
2819 wxPGProperty
* pwc
= p
->GetParent();
2820 wxPGProperty
* changedProperty
= p
;
2821 wxPGProperty
* baseChangedProperty
= changedProperty
;
2822 wxVariant bcpPendingList
;
2824 listValue
= pendingValue
;
2825 listValue
.SetName(p
->GetBaseName());
2828 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2830 wxVariantList tempList
;
2831 wxVariant
lv(tempList
, pwc
->GetBaseName());
2832 lv
.Append(listValue
);
2834 pPendingValue
= &listValue
;
2836 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2838 baseChangedProperty
= pwc
;
2839 bcpPendingList
= lv
;
2842 changedProperty
= pwc
;
2843 pwc
= pwc
->GetParent();
2847 wxPGProperty
* evtChangingProperty
= changedProperty
;
2849 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2851 value
= *pPendingValue
;
2855 // Convert list to child values
2856 pList
= pPendingValue
;
2857 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2860 wxVariant evtChangingValue
= value
;
2862 // FIXME: After proper ValueToString()s added, remove
2863 // this. It is just a temporary fix, as evt_changing
2864 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2865 // (unless it is selected, and textctrl editor is open).
2866 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2868 evtChangingProperty
= baseChangedProperty
;
2869 if ( evtChangingProperty
!= p
)
2871 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2875 evtChangingValue
= pendingValue
;
2879 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2881 if ( changedProperty
== m_selected
)
2883 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2884 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2888 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2892 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2893 m_chgInfo_changedProperty
= changedProperty
;
2894 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2895 m_chgInfo_pendingValue
= value
;
2898 m_chgInfo_valueList
= *pList
;
2900 m_chgInfo_valueList
.MakeNull();
2902 // If changedProperty is not property which value was edited,
2903 // then call wxPGProperty::ValidateValue() for that as well.
2904 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2906 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2910 // SendEvent returns true if event was vetoed
2911 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2917 // -----------------------------------------------------------------------
2919 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2921 if ( !msg
.length() )
2925 if ( !wxPGGlobalVars
->m_offline
)
2927 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2930 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2933 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2936 pStatusBar
->SetStatusText(msg
);
2944 ::wxMessageBox(msg
, _T("Property Error"));
2947 // -----------------------------------------------------------------------
2949 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2951 int vfb
= m_validationInfo
.m_failureBehavior
;
2953 if ( vfb
& wxPG_VFB_BEEP
)
2956 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2957 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2959 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2960 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2962 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2964 wxColour vfbFg
= *wxWHITE
;
2965 wxColour vfbBg
= *wxRED
;
2966 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2967 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2969 DrawItemAndChildren(property
);
2971 if ( property
== m_selected
)
2973 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2975 wxWindow
* editor
= GetEditorControl();
2978 editor
->SetForegroundColour(vfbFg
);
2979 editor
->SetBackgroundColour(vfbBg
);
2985 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2987 wxString msg
= m_validationInfo
.m_failureMessage
;
2989 if ( !msg
.length() )
2990 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2992 DoShowPropertyError(property
, msg
);
2995 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2998 // -----------------------------------------------------------------------
3000 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3002 int vfb
= m_validationInfo
.m_failureBehavior
;
3004 if ( vfb
& wxPG_VFB_MARK_CELL
)
3006 property
->SetCell(0, NULL
);
3007 property
->SetCell(1, NULL
);
3009 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3011 if ( property
== m_selected
&& GetEditorControl() )
3013 // Calling this will recreate the control, thus resetting its colour
3014 RefreshProperty(property
);
3018 DrawItemAndChildren(property
);
3023 // -----------------------------------------------------------------------
3025 // flags are same as with DoSelectProperty
3026 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3028 if ( m_inDoPropertyChanged
)
3031 wxWindow
* editor
= GetEditorControl();
3033 m_pState
->m_anyModified
= 1;
3035 m_inDoPropertyChanged
= 1;
3037 // Maybe need to update control
3038 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3040 // These values were calculated in PerformValidation()
3041 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3042 wxVariant value
= m_chgInfo_pendingValue
;
3044 wxPGProperty
* topPaintedProperty
= changedProperty
;
3046 while ( !topPaintedProperty
->IsCategory() &&
3047 !topPaintedProperty
->IsRoot() )
3049 topPaintedProperty
= topPaintedProperty
->GetParent();
3052 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3054 // Set as Modified (not if dragging just began)
3055 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3057 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3058 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3061 SetCurControlBoldFont();
3067 // Propagate updates to parent(s)
3069 wxPGProperty
* prevPwc
= NULL
;
3071 while ( prevPwc
!= topPaintedProperty
)
3073 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3075 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3078 SetCurControlBoldFont();
3082 pwc
= pwc
->GetParent();
3085 // Draw the actual property
3086 DrawItemAndChildren( topPaintedProperty
);
3089 // If value was set by wxPGProperty::OnEvent, then update the editor
3091 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3094 p
->GetEditorClass()->UpdateControl(p
, editor
);
3098 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3099 if ( m_wndEditor
) m_wndEditor
->Refresh();
3100 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3105 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3107 // If top parent has composite string value, then send to child parents,
3108 // starting from baseChangedProperty.
3109 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3111 pwc
= m_chgInfo_baseChangedProperty
;
3113 while ( pwc
!= changedProperty
)
3115 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3116 pwc
= pwc
->GetParent();
3120 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3122 m_inDoPropertyChanged
= 0;
3127 // -----------------------------------------------------------------------
3129 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3131 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3133 m_chgInfo_changedProperty
= NULL
;
3135 if ( PerformValidation(p
, newValue
) )
3137 DoPropertyChanged(p
);
3142 OnValidationFailure(p
, newValue
);
3148 // -----------------------------------------------------------------------
3150 // Runs wxValidator for the selected property
3151 bool wxPropertyGrid::DoEditorValidate()
3153 #if wxUSE_VALIDATORS
3154 // With traditional validator style, we dont need to more
3155 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3158 if ( m_iFlags
& wxPG_FL_VALIDATION_FAILED
)
3163 wxWindow
* wnd
= GetEditorControl();
3165 wxValidator
* validator
= m_selected
->GetValidator();
3166 if ( validator
&& wnd
)
3168 // Use TextCtrl of ODComboBox instead
3169 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3171 wnd
= ((wxOwnerDrawnComboBox
*)wnd
)->GetTextCtrl();
3177 validator
->SetWindow(wnd
);
3179 // Instead setting the flag after the failure, we set
3180 // it before checking and then clear afterwards if things
3181 // went fine. This trick is necessary since focus events
3182 // may be triggered while in Validate.
3183 m_iFlags
|= wxPG_FL_VALIDATION_FAILED
;
3184 if ( !validator
->Validate(this) )
3186 // If you dpm't want to display message multiple times per change,
3187 // comment the following line.
3188 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3191 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3197 // -----------------------------------------------------------------------
3199 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3201 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3202 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3204 wxWindow
* parent
= wnd
->GetParent();
3207 (parent
== m_canvas
||
3208 parent
->GetParent() == m_canvas
) )
3210 OnCustomEditorEvent((wxCommandEvent
&)event
);
3214 return wxPanel::ProcessEvent(event
);
3217 // -----------------------------------------------------------------------
3219 // NB: It may really not be wxCommandEvent - must check if necessary
3221 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3223 wxPGProperty
* selected
= m_selected
;
3226 // Somehow, event is handled after property has been deselected.
3227 // Possibly, but very rare.
3231 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3234 wxVariant
pendingValue(selected
->GetValueRef());
3235 wxWindow
* wnd
= GetEditorControl();
3237 bool wasUnspecified
= selected
->IsValueUnspecified();
3238 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3240 bool valueIsPending
= false;
3242 m_chgInfo_changedProperty
= NULL
;
3244 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3247 // Filter out excess wxTextCtrl modified events
3248 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3250 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3252 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3254 wxString newTcValue
= tc
->GetValue();
3255 if ( m_prevTcValue
== newTcValue
)
3258 m_prevTcValue
= newTcValue
;
3261 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3263 bool validationFailure
= false;
3264 bool buttonWasHandled
= false;
3267 // Try common button handling
3268 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3270 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3274 buttonWasHandled
= true;
3275 // Store as res2, as previously (and still currently alternatively)
3276 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3277 // in wxPGProperty::OnEvent().
3278 adapter
->ShowDialog( this, selected
);
3283 if ( wnd
&& !buttonWasHandled
)
3285 // First call editor class' event handler.
3286 const wxPGEditor
* editor
= selected
->GetEditorClass();
3288 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3290 // If changes, validate them
3291 if ( DoEditorValidate() )
3293 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3294 valueIsPending
= true;
3298 validationFailure
= true;
3302 // Then the property's custom handler (must be always called, unless
3303 // validation failed).
3304 if ( !validationFailure
)
3305 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3308 // SetValueInEvent(), as called in one of the functions referred above
3309 // overrides editor's value.
3310 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3312 valueIsPending
= true;
3313 pendingValue
= m_changeInEventValue
;
3314 selFlags
|= wxPG_SEL_DIALOGVAL
;
3317 if ( !validationFailure
&& valueIsPending
)
3318 if ( !PerformValidation(m_selected
, pendingValue
) )
3319 validationFailure
= true;
3321 if ( validationFailure
)
3323 OnValidationFailure(selected
, pendingValue
);
3325 else if ( valueIsPending
)
3327 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3329 DoPropertyChanged(selected
, selFlags
);
3330 EditorsValueWasNotModified();
3334 // No value after all
3336 // Let unhandled button click events go to the parent
3337 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3339 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3340 GetEventHandler()->AddPendingEvent(evt
);
3344 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3347 // -----------------------------------------------------------------------
3348 // wxPropertyGrid editor control helper methods
3349 // -----------------------------------------------------------------------
3351 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3353 int itemy
= p
->GetY2(m_lineHeight
);
3355 int cust_img_space
= 0;
3356 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3357 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3359 // TODO: If custom image detection changes from current, change this.
3360 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3362 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3363 int imwid
= p
->OnMeasureImage().x
;
3364 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3365 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3370 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3372 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3377 // -----------------------------------------------------------------------
3379 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3381 wxSize sz
= GetImageSize(p
, item
);
3382 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3383 wxPG_CUSTOM_IMAGE_SPACINGY
,
3388 // return size of custom paint image
3389 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3391 // If called with NULL property, then return default image
3392 // size for properties that use image.
3394 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3396 wxSize cis
= p
->OnMeasureImage(item
);
3398 int choiceCount
= p
->GetChoiceCount();
3399 int comVals
= p
->GetDisplayedCommonValueCount();
3400 if ( item
>= choiceCount
&& comVals
> 0 )
3402 unsigned int cvi
= item
-choiceCount
;
3403 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3405 else if ( item
>= 0 && choiceCount
== 0 )
3406 return wxSize(0, 0);
3411 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3416 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3423 // -----------------------------------------------------------------------
3425 // takes scrolling into account
3426 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3429 GetViewStart(&vx
,&vy
);
3430 vy
*=wxPG_PIXELS_PER_UNIT
;
3431 vx
*=wxPG_PIXELS_PER_UNIT
;
3434 ClientToScreen( px
, py
);
3437 // -----------------------------------------------------------------------
3439 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3442 GetViewStart(&pt2
.x
,&pt2
.y
);
3443 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3444 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3448 return m_pState
->HitTest(pt2
);
3451 // -----------------------------------------------------------------------
3453 // custom set cursor
3454 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3456 if ( type
== m_curcursor
&& !override
) return;
3458 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3460 if ( type
== wxCURSOR_SIZEWE
)
3461 cursor
= m_cursorSizeWE
;
3463 m_canvas
->SetCursor( *cursor
);
3468 // -----------------------------------------------------------------------
3469 // wxPropertyGrid property selection
3470 // -----------------------------------------------------------------------
3472 #define CONNECT_CHILD(EVT,FUNCTYPE,FUNC) \
3473 wnd->Connect(id, EVT, \
3474 (wxObjectEventFunction) (wxEventFunction) \
3475 FUNCTYPE (&wxPropertyGrid::FUNC), \
3478 // Setups event handling for child control
3479 void wxPropertyGrid::SetupEventHandling( wxWindow
* argWnd
, int id
)
3481 wxWindow
* wnd
= argWnd
;
3483 if ( argWnd
== m_wndEditor
)
3485 CONNECT_CHILD(wxEVT_MOTION
,(wxMouseEventFunction
),OnMouseMoveChild
)
3486 CONNECT_CHILD(wxEVT_LEFT_UP
,(wxMouseEventFunction
),OnMouseUpChild
)
3487 CONNECT_CHILD(wxEVT_LEFT_DOWN
,(wxMouseEventFunction
),OnMouseClickChild
)
3488 CONNECT_CHILD(wxEVT_RIGHT_UP
,(wxMouseEventFunction
),OnMouseRightClickChild
)
3489 CONNECT_CHILD(wxEVT_ENTER_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3490 CONNECT_CHILD(wxEVT_LEAVE_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3494 CONNECT_CHILD(wxEVT_NAVIGATION_KEY
,(wxNavigationKeyEventFunction
),OnNavigationKey
)
3496 CONNECT_CHILD(wxEVT_KEY_DOWN
,(wxCharEventFunction
),OnChildKeyDown
)
3497 CONNECT_CHILD(wxEVT_KEY_UP
,(wxCharEventFunction
),OnChildKeyUp
)
3498 CONNECT_CHILD(wxEVT_KILL_FOCUS
,(wxFocusEventFunction
),OnFocusEvent
)
3501 void wxPropertyGrid::FreeEditors()
3503 // Do not free editors immediately if processing events
3504 if ( !m_windowsToDelete
)
3505 m_windowsToDelete
= new wxArrayPtrVoid
;
3509 m_windowsToDelete
->push_back(m_wndEditor2
);
3510 m_wndEditor2
->Hide();
3511 m_wndEditor2
= (wxWindow
*) NULL
;
3516 m_windowsToDelete
->push_back(m_wndEditor
);
3517 m_wndEditor
->Hide();
3518 m_wndEditor
= (wxWindow
*) NULL
;
3522 // Call with NULL to de-select property
3523 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3527 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3528 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3530 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3533 if ( m_inDoSelectProperty
)
3536 m_inDoSelectProperty
= 1;
3538 wxPGProperty
* prev
= m_selected
;
3541 // Delete windows pending for deletion
3542 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3546 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3547 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3549 m_windowsToDelete
->clear();
3554 m_inDoSelectProperty
= 0;
3559 // If we are frozen, then just set the values.
3562 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3563 m_editorFocused
= 0;
3566 m_pState
->m_selected
= p
;
3568 // If frozen, always free controls. But don't worry, as Thaw will
3569 // recall SelectProperty to recreate them.
3572 // Prevent any further selection measures in this call
3573 p
= (wxPGProperty
*) NULL
;
3578 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3580 // Only set focus if not deselecting
3583 if ( flags
& wxPG_SEL_FOCUS
)
3587 m_wndEditor
->SetFocus();
3588 m_editorFocused
= 1;
3593 wxScrolledWindow::SetFocus();
3594 m_editorFocused
= 0;
3598 m_inDoSelectProperty
= 0;
3603 // First, deactivate previous
3607 OnValidationFailureReset(m_selected
);
3609 // Must double-check if this is an selected in case of forceswitch
3612 if ( !CommitChangesFromEditor(flags
) )
3614 // Validation has failed, so we can't exit the previous editor
3615 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3616 // _("Invalid Value"),wxOK|wxICON_ERROR);
3617 m_inDoSelectProperty
= 0;
3625 m_selected
= (wxPGProperty
*) NULL
;
3626 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3628 // We need to always fully refresh the grid here
3631 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3632 EditorsValueWasNotModified();
3635 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3638 // Then, activate the one given.
3641 int propY
= p
->GetY2(m_lineHeight
);
3643 int splitterX
= GetSplitterPosition();
3644 m_editorFocused
= 0;
3646 m_pState
->m_selected
= p
;
3647 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3649 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3651 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3653 // Do we need OnMeasureCalls?
3654 wxSize imsz
= p
->OnMeasureImage();
3657 // Only create editor for non-disabled non-caption
3658 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3660 // do this for non-caption items
3664 // Do we need to paint the custom image, if any?
3665 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3666 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3667 !p
->GetEditorClass()->CanContainCustomImage()
3669 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3671 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3672 wxPoint goodPos
= grect
.GetPosition();
3673 #if wxPG_CREATE_CONTROLS_HIDDEN
3674 int coord_adjust
= m_height
- goodPos
.y
;
3675 goodPos
.y
+= coord_adjust
;
3678 const wxPGEditor
* editor
= p
->GetEditorClass();
3679 wxCHECK_MSG(editor
, false,
3680 wxT("NULL editor class not allowed"));
3682 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3684 wxPGWindowList wndList
= editor
->CreateControls(this,
3689 m_wndEditor
= wndList
.m_primary
;
3690 m_wndEditor2
= wndList
.m_secondary
;
3692 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3693 // value is drawn as normal, and m_wndEditor2 is assumed
3694 // to be a right-aligned button that triggers a separate editor
3699 wxASSERT_MSG( m_wndEditor
->GetParent() == m_canvas
,
3700 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3702 // Set validator, if any
3703 #if wxUSE_VALIDATORS
3704 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3706 wxValidator
* validator
= p
->GetValidator();
3708 m_wndEditor
->SetValidator(*validator
);
3712 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3713 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3715 // If it has modified status, use bold font
3716 // (must be done before capturing m_ctrlXAdjust)
3717 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3718 SetCurControlBoldFont();
3721 // Fix TextCtrl indentation
3722 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3723 wxTextCtrl
* tc
= NULL
;
3724 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3725 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3727 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3729 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3732 // Store x relative to splitter (we'll need it).
3733 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3735 // Check if background clear is not necessary
3736 wxPoint pos
= m_wndEditor
->GetPosition();
3737 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3739 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3742 m_wndEditor
->SetSizeHints(3, 3);
3744 #if wxPG_CREATE_CONTROLS_HIDDEN
3745 m_wndEditor
->Show(false);
3746 m_wndEditor
->Freeze();
3748 goodPos
= m_wndEditor
->GetPosition();
3749 goodPos
.y
-= coord_adjust
;
3750 m_wndEditor
->Move( goodPos
);
3753 wxWindow
* primaryCtrl
= GetEditorControl();
3754 SetupEventHandling(primaryCtrl
, wxPG_SUBID1
);
3756 // Focus and select all (wxTextCtrl, wxComboBox etc)
3757 if ( flags
& wxPG_SEL_FOCUS
)
3759 primaryCtrl
->SetFocus();
3761 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3767 wxASSERT_MSG( m_wndEditor2
->GetParent() == m_canvas
,
3768 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3770 // Get proper id for wndSecondary
3771 m_wndSecId
= m_wndEditor2
->GetId();
3772 wxWindowList children
= m_wndEditor2
->GetChildren();
3773 wxWindowList::iterator node
= children
.begin();
3774 if ( node
!= children
.end() )
3775 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3777 m_wndEditor2
->SetSizeHints(3,3);
3779 #if wxPG_CREATE_CONTROLS_HIDDEN
3780 wxRect sec_rect
= m_wndEditor2
->GetRect();
3781 sec_rect
.y
-= coord_adjust
;
3783 // Fine tuning required to fix "oversized"
3784 // button disappearance bug.
3785 if ( sec_rect
.y
< 0 )
3787 sec_rect
.height
+= sec_rect
.y
;
3790 m_wndEditor2
->SetSize( sec_rect
);
3792 m_wndEditor2
->Show();
3794 SetupEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3796 // If no primary editor, focus to button to allow
3797 // it to interprete ENTER etc.
3798 // NOTE: Due to problems focusing away from it, this
3799 // has been disabled.
3801 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3802 m_wndEditor2->SetFocus();
3806 if ( flags
& wxPG_SEL_FOCUS
)
3807 m_editorFocused
= 1;
3812 // wxGTK atleast seems to need this (wxMSW not)
3816 EditorsValueWasNotModified();
3818 // If it's inside collapsed section, expand parent, scroll, etc.
3819 // Also, if it was partially visible, scroll it into view.
3820 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3825 #if wxPG_CREATE_CONTROLS_HIDDEN
3826 m_wndEditor
->Thaw();
3828 m_wndEditor
->Show(true);
3834 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3840 // Show help text in status bar.
3841 // (if found and grid not embedded in manager with help box and
3842 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3845 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3847 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3848 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3850 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3852 statusbar
= frame
->GetStatusBar();
3857 const wxString
* pHelpString
= (const wxString
*) NULL
;
3861 pHelpString
= &p
->GetHelpString();
3862 if ( pHelpString
->length() )
3864 // Set help box text.
3865 statusbar
->SetStatusText( *pHelpString
);
3866 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3870 if ( (!pHelpString
|| !pHelpString
->length()) &&
3871 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3873 // Clear help box - but only if it was written
3874 // by us at previous time.
3875 statusbar
->SetStatusText( m_emptyString
);
3876 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3882 m_inDoSelectProperty
= 0;
3884 // call wx event handler (here so that it also occurs on deselection)
3885 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3890 // -----------------------------------------------------------------------
3892 bool wxPropertyGrid::UnfocusEditor()
3894 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3897 if ( !CommitChangesFromEditor(0) )
3900 m_canvas
->SetFocusIgnoringChildren();
3901 DrawItem(m_selected
);
3906 // -----------------------------------------------------------------------
3908 // This method is not inline because it called dozens of times
3909 // (i.e. two-arg function calls create smaller code size).
3910 bool wxPropertyGrid::DoClearSelection()
3912 return DoSelectProperty((wxPGProperty
*)NULL
);
3915 // -----------------------------------------------------------------------
3916 // wxPropertyGrid expand/collapse state
3917 // -----------------------------------------------------------------------
3919 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3921 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3923 // If active editor was inside collapsed section, then disable it
3924 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3926 if ( !ClearSelection() )
3930 // Store dont-center-splitter flag 'cause we need to temporarily set it
3931 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3932 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3934 bool res
= m_pState
->DoCollapse(pwc
);
3939 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3941 RecalculateVirtualSize();
3943 // Redraw etc. only if collapsed was visible.
3944 if (pwc
->IsVisible() &&
3946 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3948 // When item is collapsed so that scrollbar would move,
3949 // graphics mess is about (unless we redraw everything).
3954 // Clear dont-center-splitter flag if it wasn't set
3955 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3960 // -----------------------------------------------------------------------
3962 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3964 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3966 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3968 // Store dont-center-splitter flag 'cause we need to temporarily set it
3969 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3970 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3972 bool res
= m_pState
->DoExpand(pwc
);
3977 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3979 RecalculateVirtualSize();
3981 // Redraw etc. only if expanded was visible.
3982 if ( pwc
->IsVisible() && !m_frozen
&&
3983 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3987 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3990 DrawItems(pwc
, NULL
);
3995 // Clear dont-center-splitter flag if it wasn't set
3996 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4001 // -----------------------------------------------------------------------
4003 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4006 return m_pState
->DoHideProperty(p
, hide
, flags
);
4009 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
4012 if ( !ClearSelection() )
4016 m_pState
->DoHideProperty(p
, hide
, flags
);
4018 RecalculateVirtualSize();
4025 // -----------------------------------------------------------------------
4026 // wxPropertyGrid size related methods
4027 // -----------------------------------------------------------------------
4029 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4031 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4035 // If virtual height was changed, then recalculate editor control position(s)
4036 if ( m_pState
->m_vhCalcPending
)
4037 CorrectEditorWidgetPosY();
4039 m_pState
->EnsureVirtualHeight();
4042 int by1
= m_pState
->GetVirtualHeight();
4043 int by2
= m_pState
->GetActualVirtualHeight();
4046 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4047 wxASSERT_MSG( false,
4053 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4055 int x
= m_pState
->m_width
;
4056 int y
= m_pState
->m_virtualHeight
;
4059 GetClientSize(&width
,&height
);
4061 // Now adjust virtual size.
4062 SetVirtualSize(x
, y
);
4068 // Adjust scrollbars
4069 if ( HasVirtualWidth() )
4071 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4072 xPos
= GetScrollPos( wxHORIZONTAL
);
4075 if ( forceXPos
!= -1 )
4078 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4081 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4082 int yPos
= GetScrollPos( wxVERTICAL
);
4084 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4085 xAmount
, yAmount
, xPos
, yPos
, true );
4087 // Must re-get size now
4088 GetClientSize(&width
,&height
);
4090 if ( !HasVirtualWidth() )
4092 m_pState
->SetVirtualWidth(width
);
4099 m_canvas
->SetSize( x
, y
);
4101 m_pState
->CheckColumnWidths();
4104 CorrectEditorWidgetSizeX();
4106 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4109 // -----------------------------------------------------------------------
4111 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4113 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4117 GetClientSize(&width
,&height
);
4122 #if wxPG_DOUBLE_BUFFER
4123 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4125 int dblh
= (m_lineHeight
*2);
4126 if ( !m_doubleBuffer
)
4128 // Create double buffer bitmap to draw on, if none
4129 int w
= (width
>250)?width
:250;
4130 int h
= height
+ dblh
;
4132 m_doubleBuffer
= new wxBitmap( w
, h
);
4136 int w
= m_doubleBuffer
->GetWidth();
4137 int h
= m_doubleBuffer
->GetHeight();
4139 // Double buffer must be large enough
4140 if ( w
< width
|| h
< (height
+dblh
) )
4142 if ( w
< width
) w
= width
;
4143 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4144 delete m_doubleBuffer
;
4145 m_doubleBuffer
= new wxBitmap( w
, h
);
4152 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4153 m_ncWidth
= event
.GetSize().x
;
4157 if ( m_pState
->m_itemsAdded
)
4158 PrepareAfterItemsAdded();
4160 // Without this, virtual size (atleast under wxGTK) will be skewed
4161 RecalculateVirtualSize();
4167 // -----------------------------------------------------------------------
4169 void wxPropertyGrid::SetVirtualWidth( int width
)
4173 // Disable virtual width
4174 width
= GetClientSize().x
;
4175 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4179 // Enable virtual width
4180 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4182 m_pState
->SetVirtualWidth( width
);
4185 // -----------------------------------------------------------------------
4186 // wxPropertyGrid mouse event handling
4187 // -----------------------------------------------------------------------
4189 // selFlags uses same values DoSelectProperty's flags
4190 // Returns true if event was vetoed.
4191 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4193 // Send property grid event of specific type and with specific property
4194 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4195 evt
.SetPropertyGrid(this);
4196 evt
.SetEventObject(m_eventObject
);
4200 evt
.SetCanVeto(true);
4201 evt
.SetupValidationInfo();
4202 m_validationInfo
.m_pValue
= pValue
;
4204 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4206 evtHandler
->ProcessEvent(evt
);
4208 return evt
.WasVetoed();
4211 // -----------------------------------------------------------------------
4213 // Return false if should be skipped
4214 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4218 // Need to set focus?
4219 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4221 m_canvas
->SetFocus();
4224 wxPropertyGridPageState
* state
= m_pState
;
4226 int splitterHitOffset
;
4227 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4229 wxPGProperty
* p
= DoGetItemAtY(y
);
4233 int depth
= (int)p
->GetDepth() - 1;
4235 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4237 if ( x
>= marginEnds
)
4241 if ( p
->IsCategory() )
4243 // This is category.
4244 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4246 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4248 // Expand, collapse, activate etc. if click on text or left of splitter.
4251 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4256 if ( !DoSelectProperty( p
) )
4259 // On double-click, expand/collapse.
4260 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4262 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4263 else DoExpand( p
, true );
4267 else if ( splitterHit
== -1 )
4270 unsigned int selFlag
= 0;
4271 if ( columnHit
== 1 )
4273 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4274 selFlag
= wxPG_SEL_FOCUS
;
4276 if ( !DoSelectProperty( p
, selFlag
) )
4279 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4281 if ( p
->GetChildCount() && !p
->IsCategory() )
4282 // On double-click, expand/collapse.
4283 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4285 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4286 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4287 else DoExpand( p
, true );
4294 // click on splitter
4295 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4297 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4299 // Double-clicking the splitter causes auto-centering
4300 CenterSplitter( true );
4302 else if ( m_dragStatus
== 0 )
4305 // Begin draggin the splitter
4309 // Changes must be committed here or the
4310 // value won't be drawn correctly
4311 if ( !CommitChangesFromEditor() )
4314 m_wndEditor
->Show ( false );
4317 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4319 m_canvas
->CaptureMouse();
4320 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4324 m_draggedSplitter
= splitterHit
;
4325 m_dragOffset
= splitterHitOffset
;
4327 wxClientDC
dc(m_canvas
);
4329 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4330 // Fixes button disappearance bug
4332 m_wndEditor2
->Show ( false );
4335 m_startingSplitterX
= x
- splitterHitOffset
;
4343 if ( p
->GetChildCount() )
4345 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4347 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4349 int y2
= y
% m_lineHeight
;
4350 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4352 // On click on expander button, expand/collapse
4353 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4354 DoCollapse( p
, true );
4356 DoExpand( p
, true );
4365 // -----------------------------------------------------------------------
4367 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4368 wxMouseEvent
& WXUNUSED(event
) )
4372 // Select property here as well
4373 wxPGProperty
* p
= m_propHover
;
4374 if ( p
!= m_selected
)
4375 DoSelectProperty( p
);
4377 // Send right click event.
4378 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4385 // -----------------------------------------------------------------------
4387 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4388 wxMouseEvent
& WXUNUSED(event
) )
4392 // Select property here as well
4393 wxPGProperty
* p
= m_propHover
;
4395 if ( p
!= m_selected
)
4396 DoSelectProperty( p
);
4398 // Send double-click event.
4399 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4406 // -----------------------------------------------------------------------
4408 #if wxPG_SUPPORT_TOOLTIPS
4410 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4412 if ( tipString
.length() )
4414 m_canvas
->SetToolTip(tipString
);
4418 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4419 m_canvas
->SetToolTip( m_emptyString
);
4421 m_canvas
->SetToolTip( NULL
);
4426 #endif // #if wxPG_SUPPORT_TOOLTIPS
4428 // -----------------------------------------------------------------------
4430 // Return false if should be skipped
4431 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4433 // Safety check (needed because mouse capturing may
4434 // otherwise freeze the control)
4435 if ( m_dragStatus
> 0 && !event
.Dragging() )
4437 HandleMouseUp(x
,y
,event
);
4440 wxPropertyGridPageState
* state
= m_pState
;
4442 int splitterHitOffset
;
4443 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4444 int splitterX
= x
- splitterHitOffset
;
4446 if ( m_dragStatus
> 0 )
4448 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4449 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4452 int newSplitterX
= x
- m_dragOffset
;
4453 int splitterX
= x
- splitterHitOffset
;
4455 // Splitter redraw required?
4456 if ( newSplitterX
!= splitterX
)
4459 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4460 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4461 state
->m_fSplitterX
= (float) newSplitterX
;
4464 CorrectEditorWidgetSizeX();
4478 int ih
= m_lineHeight
;
4481 #if wxPG_SUPPORT_TOOLTIPS
4482 wxPGProperty
* prevHover
= m_propHover
;
4483 unsigned char prevSide
= m_mouseSide
;
4485 int curPropHoverY
= y
- (y
% ih
);
4487 // On which item it hovers
4488 if ( ( !m_propHover
)
4490 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4493 // Mouse moves on another property
4495 m_propHover
= DoGetItemAtY(y
);
4496 m_propHoverY
= curPropHoverY
;
4499 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4502 #if wxPG_SUPPORT_TOOLTIPS
4503 // Store which side we are on
4505 if ( columnHit
== 1 )
4507 else if ( columnHit
== 0 )
4511 // If tooltips are enabled, show label or value as a tip
4512 // in case it doesn't otherwise show in full length.
4514 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4516 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4518 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4520 if ( m_propHover
&& !m_propHover
->IsCategory() )
4523 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4525 // Show help string as a tooltip
4526 wxString tipString
= m_propHover
->GetHelpString();
4528 SetToolTip(tipString
);
4532 // Show cropped value string as a tooltip
4536 if ( m_mouseSide
== 1 )
4538 tipString
= m_propHover
->m_label
;
4539 space
= splitterX
-m_marginWidth
-3;
4541 else if ( m_mouseSide
== 2 )
4543 tipString
= m_propHover
->GetDisplayedString();
4545 space
= m_width
- splitterX
;
4546 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4547 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4553 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4556 SetToolTip( tipString
);
4563 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4564 m_canvas
->SetToolTip( m_emptyString
);
4566 m_canvas
->SetToolTip( NULL
);
4577 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4578 m_canvas
->SetToolTip( m_emptyString
);
4580 m_canvas
->SetToolTip( NULL
);
4588 if ( splitterHit
== -1 ||
4590 HasFlag(wxPG_STATIC_SPLITTER
) )
4592 // hovering on something else
4593 if ( m_curcursor
!= wxCURSOR_ARROW
)
4594 CustomSetCursor( wxCURSOR_ARROW
);
4598 // Do not allow splitter cursor on caption items.
4599 // (also not if we were dragging and its started
4600 // outside the splitter region)
4603 !m_propHover
->IsCategory() &&
4607 // hovering on splitter
4609 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4610 // reliably detected.
4611 //if ( m_curcursor != wxCURSOR_SIZEWE )
4612 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4618 // hovering on something else
4619 if ( m_curcursor
!= wxCURSOR_ARROW
)
4620 CustomSetCursor( wxCURSOR_ARROW
);
4627 // -----------------------------------------------------------------------
4629 // Also handles Leaving event
4630 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4631 wxMouseEvent
&WXUNUSED(event
) )
4633 wxPropertyGridPageState
* state
= m_pState
;
4637 int splitterHitOffset
;
4638 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4640 // No event type check - basicly calling this method should
4641 // just stop dragging.
4642 // Left up after dragged?
4643 if ( m_dragStatus
>= 1 )
4646 // End Splitter Dragging
4648 // DO NOT ENABLE FOLLOWING LINE!
4649 // (it is only here as a reminder to not to do it)
4652 // Disable splitter auto-centering
4653 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4655 // This is necessary to return cursor
4656 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4658 m_canvas
->ReleaseMouse();
4659 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4662 // Set back the default cursor, if necessary
4663 if ( splitterHit
== -1 ||
4666 CustomSetCursor( wxCURSOR_ARROW
);
4671 // Control background needs to be cleared
4672 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4673 DrawItem( m_selected
);
4677 m_wndEditor
->Show ( true );
4680 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4681 // Fixes button disappearance bug
4683 m_wndEditor2
->Show ( true );
4686 // This clears the focus.
4687 m_editorFocused
= 0;
4693 // -----------------------------------------------------------------------
4695 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4697 int splitterX
= GetSplitterPosition();
4700 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4704 wxWindow
* wnd
= m_wndEditor
;
4706 // Hide popup on clicks
4707 if ( event
.GetEventType() != wxEVT_MOTION
)
4708 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4710 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4716 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4718 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4719 ux
>= (r
.x
+r
.width
) ||
4721 event
.m_y
>= (r
.y
+r
.height
)
4731 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4736 // -----------------------------------------------------------------------
4738 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4741 if ( OnMouseCommon( event
, &x
, &y
) )
4743 HandleMouseClick(x
,y
,event
);
4748 // -----------------------------------------------------------------------
4750 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4753 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4754 HandleMouseRightClick(x
,y
,event
);
4758 // -----------------------------------------------------------------------
4760 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4762 // Always run standard mouse-down handler as well
4763 OnMouseClick(event
);
4766 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4767 HandleMouseDoubleClick(x
,y
,event
);
4771 // -----------------------------------------------------------------------
4773 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4776 if ( OnMouseCommon( event
, &x
, &y
) )
4778 HandleMouseMove(x
,y
,event
);
4783 // -----------------------------------------------------------------------
4785 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4787 // Called when mouse moves in the empty space below the properties.
4788 CustomSetCursor( wxCURSOR_ARROW
);
4791 // -----------------------------------------------------------------------
4793 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4796 if ( OnMouseCommon( event
, &x
, &y
) )
4798 HandleMouseUp(x
,y
,event
);
4803 // -----------------------------------------------------------------------
4805 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4807 // This may get called from child control as well, so event's
4808 // mouse position cannot be relied on.
4810 if ( event
.Entering() )
4812 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4814 // TODO: Fix this (detect parent and only do
4815 // cursor trick if it is a manager).
4816 wxASSERT( GetParent() );
4817 GetParent()->SetCursor(wxNullCursor
);
4819 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4822 GetParent()->SetCursor(wxNullCursor
);
4824 else if ( event
.Leaving() )
4826 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4827 m_canvas
->SetCursor( wxNullCursor
);
4829 // Get real cursor position
4830 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4832 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4835 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4837 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4841 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4849 // -----------------------------------------------------------------------
4851 // Common code used by various OnMouseXXXChild methods.
4852 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4854 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4855 wxASSERT( topCtrlWnd
);
4857 event
.GetPosition(&x
,&y
);
4859 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4861 int splitterX
= GetSplitterPosition();
4863 wxRect r
= topCtrlWnd
->GetRect();
4864 if ( !m_dragStatus
&&
4865 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4866 y
>= 0 && y
< r
.height \
4869 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4874 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4881 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4884 if ( OnMouseChildCommon(event
,&x
,&y
) )
4886 bool res
= HandleMouseClick(x
,y
,event
);
4887 if ( !res
) event
.Skip();
4891 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4894 wxASSERT( m_wndEditor
);
4895 // These coords may not be exact (about +-2),
4896 // but that should not matter (right click is about item, not position).
4897 wxPoint pt
= m_wndEditor
->GetPosition();
4898 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4899 wxASSERT( m_selected
);
4900 m_propHover
= m_selected
;
4901 bool res
= HandleMouseRightClick(x
,y
,event
);
4902 if ( !res
) event
.Skip();
4905 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4908 if ( OnMouseChildCommon(event
,&x
,&y
) )
4910 bool res
= HandleMouseMove(x
,y
,event
);
4911 if ( !res
) event
.Skip();
4915 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4918 if ( OnMouseChildCommon(event
,&x
,&y
) )
4920 bool res
= HandleMouseUp(x
,y
,event
);
4921 if ( !res
) event
.Skip();
4925 // -----------------------------------------------------------------------
4926 // wxPropertyGrid keyboard event handling
4927 // -----------------------------------------------------------------------
4929 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4931 wxNavigationKeyEvent evt
;
4932 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4933 (dir
?wxNavigationKeyEvent::IsForward
:
4934 wxNavigationKeyEvent::IsBackward
));
4935 evt
.SetEventObject(this);
4936 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4940 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4942 // Translates wxKeyEvent to wxPG_ACTION_XXX
4944 int keycode
= event
.GetKeyCode();
4945 int modifiers
= event
.GetModifiers();
4947 wxASSERT( !(modifiers
&~(0xFFFF)) );
4949 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4951 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4953 if ( it
== m_actionTriggers
.end() )
4958 int second
= (it
->second
>>16) & 0xFFFF;
4962 return (it
->second
& 0xFFFF);
4965 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4967 wxASSERT( !(modifiers
&~(0xFFFF)) );
4969 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4971 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4973 if ( it
!= m_actionTriggers
.end() )
4975 // This key combination is already used
4977 // Can add secondary?
4978 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4979 wxT("You can only add up to two separate actions per key combination.") );
4981 action
= it
->second
| (action
<<16);
4984 m_actionTriggers
[hashMapKey
] = action
;
4987 void wxPropertyGrid::ClearActionTriggers( int action
)
4989 wxPGHashMapI2I::iterator it
;
4991 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4993 if ( it
->second
== action
)
4995 m_actionTriggers
.erase(it
);
5000 static void CopyTextToClipboard( const wxString
& text
)
5002 if ( wxTheClipboard
->Open() )
5004 // This data objects are held by the clipboard,
5005 // so do not delete them in the app.
5006 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
5007 wxTheClipboard
->Close();
5011 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5014 // Handles key event when editor control is not focused.
5017 wxASSERT( !m_frozen
);
5021 // Travelsal between items, collapsing/expanding, etc.
5022 int keycode
= event
.GetKeyCode();
5024 if ( keycode
== WXK_TAB
)
5026 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5030 // Ignore Alt and Control when they are down alone
5031 if ( keycode
== WXK_ALT
||
5032 keycode
== WXK_CONTROL
)
5039 int action
= KeyEventToActions(event
, &secondAction
);
5045 if ( ButtonTriggerKeyTest(event
) )
5048 wxPGProperty
* p
= m_selected
;
5050 if ( action
== wxPG_ACTION_COPY
)
5052 CopyTextToClipboard(p
->GetDisplayedString());
5056 // Travel and expand/collapse
5059 if ( p
->GetChildCount() &&
5060 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5063 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5065 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5068 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5070 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5077 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5081 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5092 if ( selectDir
>= -1 )
5094 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5096 DoSelectProperty(p
);
5102 // If nothing was selected, select the first item now
5103 // (or navigate out of tab).
5104 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5106 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5107 if ( p
) DoSelectProperty(p
);
5112 // -----------------------------------------------------------------------
5114 // Potentially handles a keyboard event for editor controls.
5115 // Returns false if event should *not* be skipped (on true it can
5116 // be optionally skipped).
5117 // Basicly, false means that SelectProperty was called (or was about
5118 // to be called, if canDestroy was false).
5119 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5123 if ( !m_selected
|| !m_wndEditor
)
5128 int action
= KeyEventToAction(event
);
5131 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5134 // Esc cancels any changes
5135 if ( IsEditorsValueModified() )
5137 EditorsValueWasNotModified();
5139 // Update the control as well
5140 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5142 m_selected
->GetDisplayedString() );
5145 OnValidationFailureReset(m_selected
);
5151 else if ( action
== wxPG_ACTION_COPY
)
5153 // NB: There is some problem with getting native cut-copy-paste keys to go through
5154 // for embedded editor wxTextCtrl. This is why we emulate.
5156 wxTextCtrl
* tc
= GetEditorTextCtrl();
5159 wxString sel
= tc
->GetStringSelection();
5161 CopyTextToClipboard(sel
);
5165 CopyTextToClipboard(m_selected
->GetDisplayedString());
5168 else if ( action
== wxPG_ACTION_CUT
)
5170 wxTextCtrl
* tc
= GetEditorTextCtrl();
5174 tc
->GetSelection(&from
, &to
);
5177 CopyTextToClipboard(tc
->GetStringSelection());
5178 tc
->Remove(from
, to
);
5182 else if ( action
== wxPG_ACTION_PASTE
)
5184 wxTextCtrl
* tc
= GetEditorTextCtrl();
5187 if (wxTheClipboard
->Open())
5189 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5191 wxTextDataObject data
;
5192 wxTheClipboard
->GetData( data
);
5194 tc
->GetSelection(&from
, &to
);
5197 tc
->Remove(from
, to
);
5198 tc
->WriteText(data
.GetText());
5202 tc
->WriteText(data
.GetText());
5205 wxTheClipboard
->Close();
5213 // -----------------------------------------------------------------------
5215 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5219 // Events to editor controls should get relayed here.
5221 wxWindow
* focused
= wxWindow::FindFocus();
5223 wxWindow
* primaryCtrl
= GetEditorControl();
5226 (focused
==primaryCtrl
5227 || m_editorFocused
) )
5229 // Child key must be processed here, since it can
5230 // destroy the control which is referred by its own
5232 HandleChildKey( event
);
5235 HandleKeyEvent( event
);
5238 // -----------------------------------------------------------------------
5240 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5242 m_keyComboConsumed
= 0;
5247 // -----------------------------------------------------------------------
5249 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5251 // Ignore events that occur very close to focus set
5252 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5254 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5259 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5261 int dir
= event
.GetDirection()?1:-1;
5265 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5267 wxWindow
* focused
= wxWindow::FindFocus();
5269 wxWindow
* wndToCheck
= GetEditorControl();
5271 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5272 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5274 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5275 if ( comboTextCtrl
)
5276 wndToCheck
= comboTextCtrl
;
5280 // Because of problems navigating from wxButton, do not go to it.
5283 // No primary, use secondary
5284 wndToCheck = m_wndEditor2;
5286 // If it has editor button, focus to it after the primary editor.
5287 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5288 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5289 // have somewhat debugged in window.cpp itself).
5290 else if ( focused == wndToCheck &&
5292 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5294 wndToCheck = m_wndEditor2;
5295 wxLogDebug(wxT("Exp1"));
5299 if ( focused
!= wndToCheck
&&
5302 wndToCheck
->SetFocus();
5304 // Select all text in wxTextCtrl etc.
5305 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5306 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5308 m_editorFocused
= 1;
5315 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5319 // This allows preventing NavigateOut to occur
5320 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5329 // -----------------------------------------------------------------------
5331 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5333 int keycode
= event
.GetKeyCode();
5335 // Does the keycode trigger button?
5336 if ( keycode
== m_pushButKeyCode
&&
5338 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5339 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5341 m_keyComboConsumed
= 1;
5343 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5344 GetEventHandler()->AddPendingEvent(evt
);
5351 // -----------------------------------------------------------------------
5353 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5355 int keycode
= event
.GetKeyCode();
5357 // Ignore Alt and Control when they are down alone
5358 if ( keycode
== WXK_ALT
||
5359 keycode
== WXK_CONTROL
)
5365 if ( ButtonTriggerKeyTest(event
) )
5368 if ( HandleChildKey(event
) == true )
5371 GetEventHandler()->AddPendingEvent(event
);
5374 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5376 m_keyComboConsumed
= 0;
5378 GetEventHandler()->AddPendingEvent(event
);
5383 // -----------------------------------------------------------------------
5384 // wxPropertyGrid miscellaneous event handling
5385 // -----------------------------------------------------------------------
5387 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5390 // Check if the focus is in this control or one of its children
5391 wxWindow
* newFocused
= wxWindow::FindFocus();
5393 if ( newFocused
!= m_curFocused
)
5394 HandleFocusChange( newFocused
);
5397 // Called by focus event handlers. newFocused is the window that becomes focused.
5398 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5400 unsigned int oldFlags
= m_iFlags
;
5402 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5404 wxWindow
* parent
= newFocused
;
5406 // This must be one of nextFocus' parents.
5409 // Use m_eventObject, which is either wxPropertyGrid or
5410 // wxPropertyGridManager, as appropriate.
5411 if ( parent
== m_eventObject
)
5413 m_iFlags
|= wxPG_FL_FOCUSED
;
5416 parent
= parent
->GetParent();
5419 m_curFocused
= newFocused
;
5421 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5422 (oldFlags
& wxPG_FL_FOCUSED
) )
5424 // On each focus kill, mark the next nav key event
5425 // to be ignored (can't do on set focus since the
5426 // event would occur before it).
5427 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5429 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5431 // Need to store changed value
5432 CommitChangesFromEditor();
5438 // Preliminary code for tab-order respecting
5439 // tab-traversal (but should be moved to
5442 wxWindow* prevFocus = event.GetWindow();
5443 wxWindow* useThis = this;
5444 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5445 useThis = GetParent();
5448 prevFocus->GetParent() == useThis->GetParent() )
5450 wxList& children = useThis->GetParent()->GetChildren();
5452 wxNode* node = children.Find(prevFocus);
5454 if ( node->GetNext() &&
5455 useThis == node->GetNext()->GetData() )
5456 DoSelectProperty(GetFirst());
5457 else if ( node->GetPrevious () &&
5458 useThis == node->GetPrevious()->GetData() )
5459 DoSelectProperty(GetLastProperty());
5464 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5468 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5469 DrawItem( m_selected
);
5473 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5475 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5476 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5477 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5478 //else if ( event.GetWindow() )
5480 HandleFocusChange(event
.GetWindow());
5485 // -----------------------------------------------------------------------
5487 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5489 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5492 // event.Skip() being commented out is aworkaround for bug reported
5493 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5497 // -----------------------------------------------------------------------
5499 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5501 m_iFlags
|= wxPG_FL_SCROLLED
;
5506 // -----------------------------------------------------------------------
5508 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5510 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5512 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5516 // -----------------------------------------------------------------------
5517 // Property editor related functions
5518 // -----------------------------------------------------------------------
5520 // noDefCheck = true prevents infinite recursion.
5521 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorclass
,
5522 const wxString
& name
,
5525 wxASSERT( editorclass
);
5527 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5528 RegisterDefaultEditors();
5530 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorclass
;
5535 // Registers all default editor classes
5536 void wxPropertyGrid::RegisterDefaultEditors()
5538 wxPGRegisterDefaultEditorClass( TextCtrl
);
5539 wxPGRegisterDefaultEditorClass( Choice
);
5540 wxPGRegisterDefaultEditorClass( ComboBox
);
5541 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5542 #if wxPG_INCLUDE_CHECKBOX
5543 wxPGRegisterDefaultEditorClass( CheckBox
);
5545 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5547 // Register SpinCtrl etc. editors before use
5548 RegisterAdditionalEditors();
5551 // -----------------------------------------------------------------------
5552 // wxPGStringTokenizer
5553 // Needed to handle C-style string lists (e.g. "str1" "str2")
5554 // -----------------------------------------------------------------------
5556 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5557 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5561 wxPGStringTokenizer::~wxPGStringTokenizer()
5565 bool wxPGStringTokenizer::HasMoreTokens()
5567 const wxString
& str
= *m_str
;
5569 wxString::const_iterator i
= m_curPos
;
5571 wxUniChar delim
= m_delimeter
;
5573 wxUniChar prev_a
= wxT('\0');
5575 bool inToken
= false;
5577 while ( i
!= str
.end() )
5586 m_readyToken
.clear();
5591 if ( prev_a
!= wxT('\\') )
5595 if ( a
!= wxT('\\') )
5615 m_curPos
= str
.end();
5623 wxString
wxPGStringTokenizer::GetNextToken()
5625 return m_readyToken
;
5628 // -----------------------------------------------------------------------
5630 // -----------------------------------------------------------------------
5632 wxPGChoiceEntry::wxPGChoiceEntry()
5633 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5637 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5638 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5639 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5643 // -----------------------------------------------------------------------
5645 // -----------------------------------------------------------------------
5647 wxPGChoicesData::wxPGChoicesData()
5652 wxPGChoicesData::~wxPGChoicesData()
5657 void wxPGChoicesData::Clear()
5661 for ( i
=0; i
<m_items
.size(); i
++ )
5673 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5675 wxASSERT( m_items
.size() == 0 );
5679 for ( i
=0; i
<data
->GetCount(); i
++ )
5680 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5683 // -----------------------------------------------------------------------
5685 // -----------------------------------------------------------------------
5687 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5691 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5692 m_data
->Insert( -1, p
);
5696 // -----------------------------------------------------------------------
5698 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5702 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5703 p
->SetBitmap(bitmap
);
5704 m_data
->Insert( -1, p
);
5708 // -----------------------------------------------------------------------
5710 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5714 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5715 m_data
->Insert(index
, p
);
5719 // -----------------------------------------------------------------------
5721 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5725 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5726 m_data
->Insert( index
, p
);
5730 // -----------------------------------------------------------------------
5732 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5738 while ( index
< GetCount() )
5740 int cmpRes
= GetLabel(index
).Cmp(label
);
5746 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5747 m_data
->Insert( index
, p
);
5751 // -----------------------------------------------------------------------
5753 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5757 unsigned int itemcount
= 0;
5758 const wxChar
** p
= &labels
[0];
5759 while ( *p
) { p
++; itemcount
++; }
5762 for ( i
= 0; i
< itemcount
; i
++ )
5764 int value
= wxPG_INVALID_VALUE
;
5767 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5771 // -----------------------------------------------------------------------
5773 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5778 unsigned int itemcount
= arr
.size();
5780 for ( i
= 0; i
< itemcount
; i
++ )
5782 int value
= wxPG_INVALID_VALUE
;
5785 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5789 // -----------------------------------------------------------------------
5791 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5796 unsigned int itemcount
= arr
.size();
5798 for ( i
= 0; i
< itemcount
; i
++ )
5800 int value
= wxPG_INVALID_VALUE
;
5801 if ( &arrint
&& arrint
.size() )
5803 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5807 // -----------------------------------------------------------------------
5809 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5811 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5813 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5814 delete m_data
->Item(i
);
5815 m_data
->m_items
.RemoveAt(nIndex
, count
);
5818 // -----------------------------------------------------------------------
5820 int wxPGChoices::Index( const wxString
& str
) const
5825 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5827 if ( m_data
->Item(i
)->GetText() == str
)
5834 // -----------------------------------------------------------------------
5836 int wxPGChoices::Index( int val
) const
5841 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5843 if ( m_data
->Item(i
)->GetValue() == val
)
5850 // -----------------------------------------------------------------------
5852 wxArrayString
wxPGChoices::GetLabels() const
5857 if ( this && IsOk() )
5858 for ( i
=0; i
<GetCount(); i
++ )
5859 arr
.push_back(GetLabel(i
));
5864 // -----------------------------------------------------------------------
5866 bool wxPGChoices::HasValues() const
5871 // -----------------------------------------------------------------------
5873 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5880 for ( i
=0; i
< strings
.size(); i
++ )
5882 int index
= Index(strings
[i
]);
5884 arr
.Add(GetValue(index
));
5886 arr
.Add(wxPG_INVALID_VALUE
);
5893 // -----------------------------------------------------------------------
5895 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5896 wxArrayString
* unmatched
) const
5903 for ( i
=0; i
< strings
.size(); i
++ )
5905 const wxString
& str
= strings
[i
];
5906 int index
= Index(str
);
5909 else if ( unmatched
)
5910 unmatched
->Add(str
);
5917 // -----------------------------------------------------------------------
5919 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5923 if ( data
!= wxPGChoicesEmptyData
)
5930 // -----------------------------------------------------------------------
5932 void wxPGChoices::Init()
5934 m_data
= wxPGChoicesEmptyData
;
5937 // -----------------------------------------------------------------------
5939 void wxPGChoices::Free()
5941 if ( m_data
!= wxPGChoicesEmptyData
)
5944 m_data
= wxPGChoicesEmptyData
;
5948 // -----------------------------------------------------------------------
5949 // wxPropertyGridEvent
5950 // -----------------------------------------------------------------------
5952 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5955 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5956 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5957 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5958 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5959 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5960 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5961 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5962 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5963 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5966 // -----------------------------------------------------------------------
5968 void wxPropertyGridEvent::Init()
5970 m_validationInfo
= NULL
;
5972 m_wasVetoed
= false;
5975 // -----------------------------------------------------------------------
5977 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5978 : wxCommandEvent(commandType
,id
)
5984 // -----------------------------------------------------------------------
5986 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5987 : wxCommandEvent(event
)
5989 m_eventType
= event
.GetEventType();
5990 m_eventObject
= event
.m_eventObject
;
5992 m_property
= event
.m_property
;
5993 m_validationInfo
= event
.m_validationInfo
;
5994 m_canVeto
= event
.m_canVeto
;
5995 m_wasVetoed
= event
.m_wasVetoed
;
5998 // -----------------------------------------------------------------------
6000 wxPropertyGridEvent::~wxPropertyGridEvent()
6004 // -----------------------------------------------------------------------
6006 wxEvent
* wxPropertyGridEvent::Clone() const
6008 return new wxPropertyGridEvent( *this );
6011 void wxPropertyGrid::SetPropertyAttributeAll( const wxString
& attrName
, wxVariant value
)
6013 DoSetPropertyAttribute(GetRoot(), attrName
, value
, wxPG_RECURSE
);
6016 // -----------------------------------------------------------------------
6017 // wxPropertyGridPopulator
6018 // -----------------------------------------------------------------------
6020 wxPropertyGridPopulator::wxPropertyGridPopulator()
6024 wxPGGlobalVars
->m_offline
++;
6027 // -----------------------------------------------------------------------
6029 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6032 m_propHierarchy
.clear();
6035 // -----------------------------------------------------------------------
6037 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6043 // -----------------------------------------------------------------------
6045 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6048 // Free unused sets of choices
6049 wxPGHashMapS2P::iterator it
;
6051 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6053 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6060 m_pg
->GetPanel()->Refresh();
6062 wxPGGlobalVars
->m_offline
--;
6065 // -----------------------------------------------------------------------
6067 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6068 const wxString
& propLabel
,
6069 const wxString
& propName
,
6070 const wxString
* propValue
,
6071 wxPGChoices
* pChoices
)
6073 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6074 wxPGProperty
* parent
= GetCurParent();
6076 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6078 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6082 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6084 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6088 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6090 property
->SetLabel(propLabel
);
6091 property
->DoSetName(propName
);
6093 if ( pChoices
&& pChoices
->IsOk() )
6094 property
->SetChoices(*pChoices
);
6096 m_state
->DoInsert(parent
, -1, property
);
6099 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6104 // -----------------------------------------------------------------------
6106 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6108 m_propHierarchy
.push_back(property
);
6109 DoScanForChildren();
6110 m_propHierarchy
.pop_back();
6113 // -----------------------------------------------------------------------
6115 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6116 const wxString
& idString
)
6118 wxPGChoices choices
;
6121 if ( choicesString
[0] == wxT('@') )
6123 wxString ids
= choicesString
.substr(1);
6124 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6125 if ( it
== m_dictIdChoices
.end() )
6126 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6128 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6133 if ( idString
.length() )
6135 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6136 if ( it
!= m_dictIdChoices
.end() )
6138 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6145 // Parse choices string
6146 wxString::const_iterator it
= choicesString
.begin();
6150 bool labelValid
= false;
6152 for ( ; it
!= choicesString
.end(); it
++ )
6158 if ( c
== wxT('"') )
6163 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6164 choices
.Add(label
, l
);
6167 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6172 else if ( c
== wxT('=') )
6179 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6186 if ( c
== wxT('"') )
6199 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6200 choices
.Add(label
, l
);
6203 if ( !choices
.IsOk() )
6205 choices
.EnsureData();
6209 if ( idString
.length() )
6210 m_dictIdChoices
[idString
] = choices
.GetData();
6217 // -----------------------------------------------------------------------
6219 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6221 if ( s
.Last() == wxT('%') )
6223 wxString s2
= s
.substr(0,s
.length()-1);
6225 if ( s2
.ToLong(&val
, 10) )
6227 *pval
= (val
*max
)/100;
6233 return s
.ToLong(pval
, 10);
6236 // -----------------------------------------------------------------------
6238 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6239 const wxString
& type
,
6240 const wxString
& value
)
6242 int l
= m_propHierarchy
.size();
6246 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6247 wxString valuel
= value
.Lower();
6250 if ( type
.length() == 0 )
6255 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6257 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6259 else if ( value
.ToLong(&v
, 0) )
6266 if ( type
== wxT("string") )
6270 else if ( type
== wxT("int") )
6273 value
.ToLong(&v
, 0);
6276 else if ( type
== wxT("bool") )
6278 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6285 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6290 p
->SetAttribute( name
, variant
);
6295 // -----------------------------------------------------------------------
6297 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6299 wxLogError(_("Error in resource: %s"),msg
.c_str());
6302 // -----------------------------------------------------------------------