1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
43 #include "wx/layout.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
47 #include "wx/statusbr.h"
53 // This define is necessary to prevent macro clearing
54 #define __wxPG_SOURCE_FILE__
56 #include <wx/propgrid/propgrid.h>
57 #include <wx/propgrid/editors.h>
59 #if wxPG_USE_RENDERER_NATIVE
60 #include <wx/renderer.h>
63 #include <wx/odcombo.h>
66 #include "wx/dcbuffer.h"
67 #include <wx/clipbrd.h>
68 #include <wx/dataobj.h>
71 #include <wx/msw/private.h>
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
->m_choices
.GetCount();
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
)
3525 wxPanel
* canvas
= GetPanel();
3529 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3530 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3532 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3535 if ( m_inDoSelectProperty
)
3538 m_inDoSelectProperty
= 1;
3540 wxPGProperty
* prev
= m_selected
;
3543 // Delete windows pending for deletion
3544 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3548 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3549 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3551 m_windowsToDelete
->clear();
3556 m_inDoSelectProperty
= 0;
3561 // If we are frozen, then just set the values.
3564 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3565 m_editorFocused
= 0;
3568 m_pState
->m_selected
= p
;
3570 // If frozen, always free controls. But don't worry, as Thaw will
3571 // recall SelectProperty to recreate them.
3574 // Prevent any further selection measures in this call
3575 p
= (wxPGProperty
*) NULL
;
3580 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3582 // Only set focus if not deselecting
3585 if ( flags
& wxPG_SEL_FOCUS
)
3589 m_wndEditor
->SetFocus();
3590 m_editorFocused
= 1;
3599 m_inDoSelectProperty
= 0;
3604 // First, deactivate previous
3608 OnValidationFailureReset(m_selected
);
3610 // Must double-check if this is an selected in case of forceswitch
3613 if ( !CommitChangesFromEditor(flags
) )
3615 // Validation has failed, so we can't exit the previous editor
3616 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3617 // _("Invalid Value"),wxOK|wxICON_ERROR);
3618 m_inDoSelectProperty
= 0;
3626 m_selected
= (wxPGProperty
*) NULL
;
3627 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3629 // We need to always fully refresh the grid here
3632 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3633 EditorsValueWasNotModified();
3636 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3639 // Then, activate the one given.
3642 int propY
= p
->GetY2(m_lineHeight
);
3644 int splitterX
= GetSplitterPosition();
3645 m_editorFocused
= 0;
3647 m_pState
->m_selected
= p
;
3648 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3650 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3652 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3654 // Do we need OnMeasureCalls?
3655 wxSize imsz
= p
->OnMeasureImage();
3658 // Only create editor for non-disabled non-caption
3659 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3661 // do this for non-caption items
3665 // Do we need to paint the custom image, if any?
3666 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3667 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3668 !p
->GetEditorClass()->CanContainCustomImage()
3670 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3672 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3673 wxPoint goodPos
= grect
.GetPosition();
3674 #if wxPG_CREATE_CONTROLS_HIDDEN
3675 int coord_adjust
= m_height
- goodPos
.y
;
3676 goodPos
.y
+= coord_adjust
;
3679 const wxPGEditor
* editor
= p
->GetEditorClass();
3680 wxCHECK_MSG(editor
, false,
3681 wxT("NULL editor class not allowed"));
3683 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3685 wxPGWindowList wndList
= editor
->CreateControls(this,
3690 m_wndEditor
= wndList
.m_primary
;
3691 m_wndEditor2
= wndList
.m_secondary
;
3693 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3694 // value is drawn as normal, and m_wndEditor2 is assumed
3695 // to be a right-aligned button that triggers a separate editor
3700 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3701 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3703 // Set validator, if any
3704 #if wxUSE_VALIDATORS
3705 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3707 wxValidator
* validator
= p
->GetValidator();
3709 m_wndEditor
->SetValidator(*validator
);
3713 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3714 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3716 // If it has modified status, use bold font
3717 // (must be done before capturing m_ctrlXAdjust)
3718 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3719 SetCurControlBoldFont();
3722 // Fix TextCtrl indentation
3723 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3724 wxTextCtrl
* tc
= NULL
;
3725 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3726 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3728 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3730 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3733 // Store x relative to splitter (we'll need it).
3734 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3736 // Check if background clear is not necessary
3737 wxPoint pos
= m_wndEditor
->GetPosition();
3738 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3740 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3743 m_wndEditor
->SetSizeHints(3, 3);
3745 #if wxPG_CREATE_CONTROLS_HIDDEN
3746 m_wndEditor
->Show(false);
3747 m_wndEditor
->Freeze();
3749 goodPos
= m_wndEditor
->GetPosition();
3750 goodPos
.y
-= coord_adjust
;
3751 m_wndEditor
->Move( goodPos
);
3754 wxWindow
* primaryCtrl
= GetEditorControl();
3755 SetupEventHandling(primaryCtrl
, wxPG_SUBID1
);
3757 // Focus and select all (wxTextCtrl, wxComboBox etc)
3758 if ( flags
& wxPG_SEL_FOCUS
)
3760 primaryCtrl
->SetFocus();
3762 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3768 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3769 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3771 // Get proper id for wndSecondary
3772 m_wndSecId
= m_wndEditor2
->GetId();
3773 wxWindowList children
= m_wndEditor2
->GetChildren();
3774 wxWindowList::iterator node
= children
.begin();
3775 if ( node
!= children
.end() )
3776 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3778 m_wndEditor2
->SetSizeHints(3,3);
3780 #if wxPG_CREATE_CONTROLS_HIDDEN
3781 wxRect sec_rect
= m_wndEditor2
->GetRect();
3782 sec_rect
.y
-= coord_adjust
;
3784 // Fine tuning required to fix "oversized"
3785 // button disappearance bug.
3786 if ( sec_rect
.y
< 0 )
3788 sec_rect
.height
+= sec_rect
.y
;
3791 m_wndEditor2
->SetSize( sec_rect
);
3793 m_wndEditor2
->Show();
3795 SetupEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3797 // If no primary editor, focus to button to allow
3798 // it to interprete ENTER etc.
3799 // NOTE: Due to problems focusing away from it, this
3800 // has been disabled.
3802 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3803 m_wndEditor2->SetFocus();
3807 if ( flags
& wxPG_SEL_FOCUS
)
3808 m_editorFocused
= 1;
3813 // Make sure focus is in grid canvas (important for wxGTK, at least)
3817 EditorsValueWasNotModified();
3819 // If it's inside collapsed section, expand parent, scroll, etc.
3820 // Also, if it was partially visible, scroll it into view.
3821 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3826 #if wxPG_CREATE_CONTROLS_HIDDEN
3827 m_wndEditor
->Thaw();
3829 m_wndEditor
->Show(true);
3836 // Make sure focus is in grid canvas
3840 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3846 // Show help text in status bar.
3847 // (if found and grid not embedded in manager with help box and
3848 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3851 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3853 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3854 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3856 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3858 statusbar
= frame
->GetStatusBar();
3863 const wxString
* pHelpString
= (const wxString
*) NULL
;
3867 pHelpString
= &p
->GetHelpString();
3868 if ( pHelpString
->length() )
3870 // Set help box text.
3871 statusbar
->SetStatusText( *pHelpString
);
3872 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3876 if ( (!pHelpString
|| !pHelpString
->length()) &&
3877 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3879 // Clear help box - but only if it was written
3880 // by us at previous time.
3881 statusbar
->SetStatusText( m_emptyString
);
3882 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3888 m_inDoSelectProperty
= 0;
3890 // call wx event handler (here so that it also occurs on deselection)
3891 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3896 // -----------------------------------------------------------------------
3898 bool wxPropertyGrid::UnfocusEditor()
3900 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3903 if ( !CommitChangesFromEditor(0) )
3907 DrawItem(m_selected
);
3912 // -----------------------------------------------------------------------
3914 // This method is not inline because it called dozens of times
3915 // (i.e. two-arg function calls create smaller code size).
3916 bool wxPropertyGrid::DoClearSelection()
3918 return DoSelectProperty((wxPGProperty
*)NULL
);
3921 // -----------------------------------------------------------------------
3922 // wxPropertyGrid expand/collapse state
3923 // -----------------------------------------------------------------------
3925 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3927 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3929 // If active editor was inside collapsed section, then disable it
3930 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3932 if ( !ClearSelection() )
3936 // Store dont-center-splitter flag 'cause we need to temporarily set it
3937 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3938 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3940 bool res
= m_pState
->DoCollapse(pwc
);
3945 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3947 RecalculateVirtualSize();
3949 // Redraw etc. only if collapsed was visible.
3950 if (pwc
->IsVisible() &&
3952 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3954 // When item is collapsed so that scrollbar would move,
3955 // graphics mess is about (unless we redraw everything).
3960 // Clear dont-center-splitter flag if it wasn't set
3961 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3966 // -----------------------------------------------------------------------
3968 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3970 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3972 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3974 // Store dont-center-splitter flag 'cause we need to temporarily set it
3975 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3976 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3978 bool res
= m_pState
->DoExpand(pwc
);
3983 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3985 RecalculateVirtualSize();
3987 // Redraw etc. only if expanded was visible.
3988 if ( pwc
->IsVisible() && !m_frozen
&&
3989 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3993 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3996 DrawItems(pwc
, NULL
);
4001 // Clear dont-center-splitter flag if it wasn't set
4002 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4007 // -----------------------------------------------------------------------
4009 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4012 return m_pState
->DoHideProperty(p
, hide
, flags
);
4015 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
4018 if ( !ClearSelection() )
4022 m_pState
->DoHideProperty(p
, hide
, flags
);
4024 RecalculateVirtualSize();
4031 // -----------------------------------------------------------------------
4032 // wxPropertyGrid size related methods
4033 // -----------------------------------------------------------------------
4035 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4037 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4041 // If virtual height was changed, then recalculate editor control position(s)
4042 if ( m_pState
->m_vhCalcPending
)
4043 CorrectEditorWidgetPosY();
4045 m_pState
->EnsureVirtualHeight();
4048 int by1
= m_pState
->GetVirtualHeight();
4049 int by2
= m_pState
->GetActualVirtualHeight();
4052 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4053 wxASSERT_MSG( false,
4059 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4061 int x
= m_pState
->m_width
;
4062 int y
= m_pState
->m_virtualHeight
;
4065 GetClientSize(&width
,&height
);
4067 // Now adjust virtual size.
4068 SetVirtualSize(x
, y
);
4074 // Adjust scrollbars
4075 if ( HasVirtualWidth() )
4077 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4078 xPos
= GetScrollPos( wxHORIZONTAL
);
4081 if ( forceXPos
!= -1 )
4084 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4087 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4088 int yPos
= GetScrollPos( wxVERTICAL
);
4090 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4091 xAmount
, yAmount
, xPos
, yPos
, true );
4093 // Must re-get size now
4094 GetClientSize(&width
,&height
);
4096 if ( !HasVirtualWidth() )
4098 m_pState
->SetVirtualWidth(width
);
4105 m_canvas
->SetSize( x
, y
);
4107 m_pState
->CheckColumnWidths();
4110 CorrectEditorWidgetSizeX();
4112 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4115 // -----------------------------------------------------------------------
4117 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4119 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4123 GetClientSize(&width
,&height
);
4128 #if wxPG_DOUBLE_BUFFER
4129 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4131 int dblh
= (m_lineHeight
*2);
4132 if ( !m_doubleBuffer
)
4134 // Create double buffer bitmap to draw on, if none
4135 int w
= (width
>250)?width
:250;
4136 int h
= height
+ dblh
;
4138 m_doubleBuffer
= new wxBitmap( w
, h
);
4142 int w
= m_doubleBuffer
->GetWidth();
4143 int h
= m_doubleBuffer
->GetHeight();
4145 // Double buffer must be large enough
4146 if ( w
< width
|| h
< (height
+dblh
) )
4148 if ( w
< width
) w
= width
;
4149 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4150 delete m_doubleBuffer
;
4151 m_doubleBuffer
= new wxBitmap( w
, h
);
4158 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4159 m_ncWidth
= event
.GetSize().x
;
4163 if ( m_pState
->m_itemsAdded
)
4164 PrepareAfterItemsAdded();
4166 // Without this, virtual size (atleast under wxGTK) will be skewed
4167 RecalculateVirtualSize();
4173 // -----------------------------------------------------------------------
4175 void wxPropertyGrid::SetVirtualWidth( int width
)
4179 // Disable virtual width
4180 width
= GetClientSize().x
;
4181 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4185 // Enable virtual width
4186 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4188 m_pState
->SetVirtualWidth( width
);
4191 // -----------------------------------------------------------------------
4192 // wxPropertyGrid mouse event handling
4193 // -----------------------------------------------------------------------
4195 // selFlags uses same values DoSelectProperty's flags
4196 // Returns true if event was vetoed.
4197 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4199 // Send property grid event of specific type and with specific property
4200 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4201 evt
.SetPropertyGrid(this);
4202 evt
.SetEventObject(m_eventObject
);
4206 evt
.SetCanVeto(true);
4207 evt
.SetupValidationInfo();
4208 m_validationInfo
.m_pValue
= pValue
;
4210 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4212 evtHandler
->ProcessEvent(evt
);
4214 return evt
.WasVetoed();
4217 // -----------------------------------------------------------------------
4219 // Return false if should be skipped
4220 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4224 // Need to set focus?
4225 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4230 wxPropertyGridPageState
* state
= m_pState
;
4232 int splitterHitOffset
;
4233 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4235 wxPGProperty
* p
= DoGetItemAtY(y
);
4239 int depth
= (int)p
->GetDepth() - 1;
4241 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4243 if ( x
>= marginEnds
)
4247 if ( p
->IsCategory() )
4249 // This is category.
4250 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4252 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4254 // Expand, collapse, activate etc. if click on text or left of splitter.
4257 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4262 if ( !DoSelectProperty( p
) )
4265 // On double-click, expand/collapse.
4266 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4268 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4269 else DoExpand( p
, true );
4273 else if ( splitterHit
== -1 )
4276 unsigned int selFlag
= 0;
4277 if ( columnHit
== 1 )
4279 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4280 selFlag
= wxPG_SEL_FOCUS
;
4282 if ( !DoSelectProperty( p
, selFlag
) )
4285 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4287 if ( p
->GetChildCount() && !p
->IsCategory() )
4288 // On double-click, expand/collapse.
4289 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4291 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4292 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4293 else DoExpand( p
, true );
4300 // click on splitter
4301 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4303 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4305 // Double-clicking the splitter causes auto-centering
4306 CenterSplitter( true );
4308 else if ( m_dragStatus
== 0 )
4311 // Begin draggin the splitter
4315 // Changes must be committed here or the
4316 // value won't be drawn correctly
4317 if ( !CommitChangesFromEditor() )
4320 m_wndEditor
->Show ( false );
4323 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4325 m_canvas
->CaptureMouse();
4326 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4330 m_draggedSplitter
= splitterHit
;
4331 m_dragOffset
= splitterHitOffset
;
4333 wxClientDC
dc(m_canvas
);
4335 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4336 // Fixes button disappearance bug
4338 m_wndEditor2
->Show ( false );
4341 m_startingSplitterX
= x
- splitterHitOffset
;
4349 if ( p
->GetChildCount() )
4351 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4353 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4355 int y2
= y
% m_lineHeight
;
4356 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4358 // On click on expander button, expand/collapse
4359 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4360 DoCollapse( p
, true );
4362 DoExpand( p
, true );
4371 // -----------------------------------------------------------------------
4373 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4374 wxMouseEvent
& WXUNUSED(event
) )
4378 // Select property here as well
4379 wxPGProperty
* p
= m_propHover
;
4380 if ( p
!= m_selected
)
4381 DoSelectProperty( p
);
4383 // Send right click event.
4384 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4391 // -----------------------------------------------------------------------
4393 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4394 wxMouseEvent
& WXUNUSED(event
) )
4398 // Select property here as well
4399 wxPGProperty
* p
= m_propHover
;
4401 if ( p
!= m_selected
)
4402 DoSelectProperty( p
);
4404 // Send double-click event.
4405 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4412 // -----------------------------------------------------------------------
4414 #if wxPG_SUPPORT_TOOLTIPS
4416 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4418 if ( tipString
.length() )
4420 m_canvas
->SetToolTip(tipString
);
4424 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4425 m_canvas
->SetToolTip( m_emptyString
);
4427 m_canvas
->SetToolTip( NULL
);
4432 #endif // #if wxPG_SUPPORT_TOOLTIPS
4434 // -----------------------------------------------------------------------
4436 // Return false if should be skipped
4437 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4439 // Safety check (needed because mouse capturing may
4440 // otherwise freeze the control)
4441 if ( m_dragStatus
> 0 && !event
.Dragging() )
4443 HandleMouseUp(x
,y
,event
);
4446 wxPropertyGridPageState
* state
= m_pState
;
4448 int splitterHitOffset
;
4449 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4450 int splitterX
= x
- splitterHitOffset
;
4452 if ( m_dragStatus
> 0 )
4454 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4455 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4458 int newSplitterX
= x
- m_dragOffset
;
4459 int splitterX
= x
- splitterHitOffset
;
4461 // Splitter redraw required?
4462 if ( newSplitterX
!= splitterX
)
4465 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4466 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4467 state
->m_fSplitterX
= (float) newSplitterX
;
4470 CorrectEditorWidgetSizeX();
4484 int ih
= m_lineHeight
;
4487 #if wxPG_SUPPORT_TOOLTIPS
4488 wxPGProperty
* prevHover
= m_propHover
;
4489 unsigned char prevSide
= m_mouseSide
;
4491 int curPropHoverY
= y
- (y
% ih
);
4493 // On which item it hovers
4494 if ( ( !m_propHover
)
4496 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4499 // Mouse moves on another property
4501 m_propHover
= DoGetItemAtY(y
);
4502 m_propHoverY
= curPropHoverY
;
4505 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4508 #if wxPG_SUPPORT_TOOLTIPS
4509 // Store which side we are on
4511 if ( columnHit
== 1 )
4513 else if ( columnHit
== 0 )
4517 // If tooltips are enabled, show label or value as a tip
4518 // in case it doesn't otherwise show in full length.
4520 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4522 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4524 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4526 if ( m_propHover
&& !m_propHover
->IsCategory() )
4529 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4531 // Show help string as a tooltip
4532 wxString tipString
= m_propHover
->GetHelpString();
4534 SetToolTip(tipString
);
4538 // Show cropped value string as a tooltip
4542 if ( m_mouseSide
== 1 )
4544 tipString
= m_propHover
->m_label
;
4545 space
= splitterX
-m_marginWidth
-3;
4547 else if ( m_mouseSide
== 2 )
4549 tipString
= m_propHover
->GetDisplayedString();
4551 space
= m_width
- splitterX
;
4552 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4553 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4559 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4562 SetToolTip( tipString
);
4569 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4570 m_canvas
->SetToolTip( m_emptyString
);
4572 m_canvas
->SetToolTip( NULL
);
4583 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4584 m_canvas
->SetToolTip( m_emptyString
);
4586 m_canvas
->SetToolTip( NULL
);
4594 if ( splitterHit
== -1 ||
4596 HasFlag(wxPG_STATIC_SPLITTER
) )
4598 // hovering on something else
4599 if ( m_curcursor
!= wxCURSOR_ARROW
)
4600 CustomSetCursor( wxCURSOR_ARROW
);
4604 // Do not allow splitter cursor on caption items.
4605 // (also not if we were dragging and its started
4606 // outside the splitter region)
4609 !m_propHover
->IsCategory() &&
4613 // hovering on splitter
4615 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4616 // reliably detected.
4617 //if ( m_curcursor != wxCURSOR_SIZEWE )
4618 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4624 // hovering on something else
4625 if ( m_curcursor
!= wxCURSOR_ARROW
)
4626 CustomSetCursor( wxCURSOR_ARROW
);
4633 // -----------------------------------------------------------------------
4635 // Also handles Leaving event
4636 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4637 wxMouseEvent
&WXUNUSED(event
) )
4639 wxPropertyGridPageState
* state
= m_pState
;
4643 int splitterHitOffset
;
4644 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4646 // No event type check - basicly calling this method should
4647 // just stop dragging.
4648 // Left up after dragged?
4649 if ( m_dragStatus
>= 1 )
4652 // End Splitter Dragging
4654 // DO NOT ENABLE FOLLOWING LINE!
4655 // (it is only here as a reminder to not to do it)
4658 // Disable splitter auto-centering
4659 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4661 // This is necessary to return cursor
4662 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4664 m_canvas
->ReleaseMouse();
4665 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4668 // Set back the default cursor, if necessary
4669 if ( splitterHit
== -1 ||
4672 CustomSetCursor( wxCURSOR_ARROW
);
4677 // Control background needs to be cleared
4678 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4679 DrawItem( m_selected
);
4683 m_wndEditor
->Show ( true );
4686 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4687 // Fixes button disappearance bug
4689 m_wndEditor2
->Show ( true );
4692 // This clears the focus.
4693 m_editorFocused
= 0;
4699 // -----------------------------------------------------------------------
4701 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4703 int splitterX
= GetSplitterPosition();
4706 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4710 wxWindow
* wnd
= m_wndEditor
;
4712 // Hide popup on clicks
4713 if ( event
.GetEventType() != wxEVT_MOTION
)
4714 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4716 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4722 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4724 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4725 ux
>= (r
.x
+r
.width
) ||
4727 event
.m_y
>= (r
.y
+r
.height
)
4737 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4742 // -----------------------------------------------------------------------
4744 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4747 if ( OnMouseCommon( event
, &x
, &y
) )
4749 HandleMouseClick(x
,y
,event
);
4754 // -----------------------------------------------------------------------
4756 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4759 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4760 HandleMouseRightClick(x
,y
,event
);
4764 // -----------------------------------------------------------------------
4766 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4768 // Always run standard mouse-down handler as well
4769 OnMouseClick(event
);
4772 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4773 HandleMouseDoubleClick(x
,y
,event
);
4777 // -----------------------------------------------------------------------
4779 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4782 if ( OnMouseCommon( event
, &x
, &y
) )
4784 HandleMouseMove(x
,y
,event
);
4789 // -----------------------------------------------------------------------
4791 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4793 // Called when mouse moves in the empty space below the properties.
4794 CustomSetCursor( wxCURSOR_ARROW
);
4797 // -----------------------------------------------------------------------
4799 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4802 if ( OnMouseCommon( event
, &x
, &y
) )
4804 HandleMouseUp(x
,y
,event
);
4809 // -----------------------------------------------------------------------
4811 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4813 // This may get called from child control as well, so event's
4814 // mouse position cannot be relied on.
4816 if ( event
.Entering() )
4818 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4820 // TODO: Fix this (detect parent and only do
4821 // cursor trick if it is a manager).
4822 wxASSERT( GetParent() );
4823 GetParent()->SetCursor(wxNullCursor
);
4825 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4828 GetParent()->SetCursor(wxNullCursor
);
4830 else if ( event
.Leaving() )
4832 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4833 m_canvas
->SetCursor( wxNullCursor
);
4835 // Get real cursor position
4836 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4838 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4841 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4843 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4847 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4855 // -----------------------------------------------------------------------
4857 // Common code used by various OnMouseXXXChild methods.
4858 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4860 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4861 wxASSERT( topCtrlWnd
);
4863 event
.GetPosition(&x
,&y
);
4865 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4867 int splitterX
= GetSplitterPosition();
4869 wxRect r
= topCtrlWnd
->GetRect();
4870 if ( !m_dragStatus
&&
4871 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4872 y
>= 0 && y
< r
.height \
4875 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4880 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4887 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4890 if ( OnMouseChildCommon(event
,&x
,&y
) )
4892 bool res
= HandleMouseClick(x
,y
,event
);
4893 if ( !res
) event
.Skip();
4897 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4900 wxASSERT( m_wndEditor
);
4901 // These coords may not be exact (about +-2),
4902 // but that should not matter (right click is about item, not position).
4903 wxPoint pt
= m_wndEditor
->GetPosition();
4904 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4905 wxASSERT( m_selected
);
4906 m_propHover
= m_selected
;
4907 bool res
= HandleMouseRightClick(x
,y
,event
);
4908 if ( !res
) event
.Skip();
4911 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4914 if ( OnMouseChildCommon(event
,&x
,&y
) )
4916 bool res
= HandleMouseMove(x
,y
,event
);
4917 if ( !res
) event
.Skip();
4921 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4924 if ( OnMouseChildCommon(event
,&x
,&y
) )
4926 bool res
= HandleMouseUp(x
,y
,event
);
4927 if ( !res
) event
.Skip();
4931 // -----------------------------------------------------------------------
4932 // wxPropertyGrid keyboard event handling
4933 // -----------------------------------------------------------------------
4935 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4937 wxNavigationKeyEvent evt
;
4938 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4939 (dir
?wxNavigationKeyEvent::IsForward
:
4940 wxNavigationKeyEvent::IsBackward
));
4941 evt
.SetEventObject(this);
4942 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4946 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4948 // Translates wxKeyEvent to wxPG_ACTION_XXX
4950 int keycode
= event
.GetKeyCode();
4951 int modifiers
= event
.GetModifiers();
4953 wxASSERT( !(modifiers
&~(0xFFFF)) );
4955 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4957 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4959 if ( it
== m_actionTriggers
.end() )
4964 int second
= (it
->second
>>16) & 0xFFFF;
4968 return (it
->second
& 0xFFFF);
4971 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4973 wxASSERT( !(modifiers
&~(0xFFFF)) );
4975 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4977 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4979 if ( it
!= m_actionTriggers
.end() )
4981 // This key combination is already used
4983 // Can add secondary?
4984 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4985 wxT("You can only add up to two separate actions per key combination.") );
4987 action
= it
->second
| (action
<<16);
4990 m_actionTriggers
[hashMapKey
] = action
;
4993 void wxPropertyGrid::ClearActionTriggers( int action
)
4995 wxPGHashMapI2I::iterator it
;
4997 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4999 if ( it
->second
== action
)
5001 m_actionTriggers
.erase(it
);
5006 static void CopyTextToClipboard( const wxString
& text
)
5008 if ( wxTheClipboard
->Open() )
5010 // This data objects are held by the clipboard,
5011 // so do not delete them in the app.
5012 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
5013 wxTheClipboard
->Close();
5017 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5020 // Handles key event when editor control is not focused.
5023 wxASSERT( !m_frozen
);
5027 // Travelsal between items, collapsing/expanding, etc.
5028 int keycode
= event
.GetKeyCode();
5030 if ( keycode
== WXK_TAB
)
5032 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5036 // Ignore Alt and Control when they are down alone
5037 if ( keycode
== WXK_ALT
||
5038 keycode
== WXK_CONTROL
)
5045 int action
= KeyEventToActions(event
, &secondAction
);
5051 if ( ButtonTriggerKeyTest(event
) )
5054 wxPGProperty
* p
= m_selected
;
5056 if ( action
== wxPG_ACTION_COPY
)
5058 CopyTextToClipboard(p
->GetDisplayedString());
5062 // Travel and expand/collapse
5065 if ( p
->GetChildCount() &&
5066 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5069 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5071 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5074 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5076 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5083 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5087 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5098 if ( selectDir
>= -1 )
5100 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5102 DoSelectProperty(p
);
5108 // If nothing was selected, select the first item now
5109 // (or navigate out of tab).
5110 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5112 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5113 if ( p
) DoSelectProperty(p
);
5118 // -----------------------------------------------------------------------
5120 // Potentially handles a keyboard event for editor controls.
5121 // Returns false if event should *not* be skipped (on true it can
5122 // be optionally skipped).
5123 // Basicly, false means that SelectProperty was called (or was about
5124 // to be called, if canDestroy was false).
5125 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5129 if ( !m_selected
|| !m_wndEditor
)
5134 int action
= KeyEventToAction(event
);
5137 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5140 // Esc cancels any changes
5141 if ( IsEditorsValueModified() )
5143 EditorsValueWasNotModified();
5145 // Update the control as well
5146 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5148 m_selected
->GetDisplayedString() );
5151 OnValidationFailureReset(m_selected
);
5157 else if ( action
== wxPG_ACTION_COPY
)
5159 // NB: There is some problem with getting native cut-copy-paste keys to go through
5160 // for embedded editor wxTextCtrl. This is why we emulate.
5162 wxTextCtrl
* tc
= GetEditorTextCtrl();
5165 wxString sel
= tc
->GetStringSelection();
5167 CopyTextToClipboard(sel
);
5171 CopyTextToClipboard(m_selected
->GetDisplayedString());
5174 else if ( action
== wxPG_ACTION_CUT
)
5176 wxTextCtrl
* tc
= GetEditorTextCtrl();
5180 tc
->GetSelection(&from
, &to
);
5183 CopyTextToClipboard(tc
->GetStringSelection());
5184 tc
->Remove(from
, to
);
5188 else if ( action
== wxPG_ACTION_PASTE
)
5190 wxTextCtrl
* tc
= GetEditorTextCtrl();
5193 if (wxTheClipboard
->Open())
5195 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5197 wxTextDataObject data
;
5198 wxTheClipboard
->GetData( data
);
5200 tc
->GetSelection(&from
, &to
);
5203 tc
->Remove(from
, to
);
5204 tc
->WriteText(data
.GetText());
5208 tc
->WriteText(data
.GetText());
5211 wxTheClipboard
->Close();
5219 // -----------------------------------------------------------------------
5221 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5225 // Events to editor controls should get relayed here.
5227 wxWindow
* focused
= wxWindow::FindFocus();
5229 wxWindow
* primaryCtrl
= GetEditorControl();
5232 (focused
==primaryCtrl
5233 || m_editorFocused
) )
5235 // Child key must be processed here, since it can
5236 // destroy the control which is referred by its own
5238 HandleChildKey( event
);
5241 HandleKeyEvent( event
);
5244 // -----------------------------------------------------------------------
5246 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5248 m_keyComboConsumed
= 0;
5253 // -----------------------------------------------------------------------
5255 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5257 // Ignore events that occur very close to focus set
5258 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5260 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5265 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5267 int dir
= event
.GetDirection()?1:-1;
5271 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5273 wxWindow
* focused
= wxWindow::FindFocus();
5275 wxWindow
* wndToCheck
= GetEditorControl();
5277 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5278 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5280 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5281 if ( comboTextCtrl
)
5282 wndToCheck
= comboTextCtrl
;
5286 // Because of problems navigating from wxButton, do not go to it.
5289 // No primary, use secondary
5290 wndToCheck = m_wndEditor2;
5292 // If it has editor button, focus to it after the primary editor.
5293 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5294 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5295 // have somewhat debugged in window.cpp itself).
5296 else if ( focused == wndToCheck &&
5298 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5300 wndToCheck = m_wndEditor2;
5301 wxLogDebug(wxT("Exp1"));
5305 if ( focused
!= wndToCheck
&&
5308 wndToCheck
->SetFocus();
5310 // Select all text in wxTextCtrl etc.
5311 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5312 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5314 m_editorFocused
= 1;
5321 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5325 // This allows preventing NavigateOut to occur
5326 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5335 // -----------------------------------------------------------------------
5337 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5339 int keycode
= event
.GetKeyCode();
5341 // Does the keycode trigger button?
5342 if ( keycode
== m_pushButKeyCode
&&
5344 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5345 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5347 m_keyComboConsumed
= 1;
5349 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5350 GetEventHandler()->AddPendingEvent(evt
);
5357 // -----------------------------------------------------------------------
5359 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5361 int keycode
= event
.GetKeyCode();
5363 // Ignore Alt and Control when they are down alone
5364 if ( keycode
== WXK_ALT
||
5365 keycode
== WXK_CONTROL
)
5371 if ( ButtonTriggerKeyTest(event
) )
5374 if ( HandleChildKey(event
) == true )
5377 GetEventHandler()->AddPendingEvent(event
);
5380 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5382 m_keyComboConsumed
= 0;
5384 GetEventHandler()->AddPendingEvent(event
);
5389 // -----------------------------------------------------------------------
5390 // wxPropertyGrid miscellaneous event handling
5391 // -----------------------------------------------------------------------
5393 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5396 // Check if the focus is in this control or one of its children
5397 wxWindow
* newFocused
= wxWindow::FindFocus();
5399 if ( newFocused
!= m_curFocused
)
5400 HandleFocusChange( newFocused
);
5403 // Called by focus event handlers. newFocused is the window that becomes focused.
5404 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5406 unsigned int oldFlags
= m_iFlags
;
5408 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5410 wxWindow
* parent
= newFocused
;
5412 // This must be one of nextFocus' parents.
5415 // Use m_eventObject, which is either wxPropertyGrid or
5416 // wxPropertyGridManager, as appropriate.
5417 if ( parent
== m_eventObject
)
5419 m_iFlags
|= wxPG_FL_FOCUSED
;
5422 parent
= parent
->GetParent();
5425 m_curFocused
= newFocused
;
5427 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5428 (oldFlags
& wxPG_FL_FOCUSED
) )
5430 // On each focus kill, mark the next nav key event
5431 // to be ignored (can't do on set focus since the
5432 // event would occur before it).
5433 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5435 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5437 // Need to store changed value
5438 CommitChangesFromEditor();
5444 // Preliminary code for tab-order respecting
5445 // tab-traversal (but should be moved to
5448 wxWindow* prevFocus = event.GetWindow();
5449 wxWindow* useThis = this;
5450 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5451 useThis = GetParent();
5454 prevFocus->GetParent() == useThis->GetParent() )
5456 wxList& children = useThis->GetParent()->GetChildren();
5458 wxNode* node = children.Find(prevFocus);
5460 if ( node->GetNext() &&
5461 useThis == node->GetNext()->GetData() )
5462 DoSelectProperty(GetFirst());
5463 else if ( node->GetPrevious () &&
5464 useThis == node->GetPrevious()->GetData() )
5465 DoSelectProperty(GetLastProperty());
5470 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5474 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5475 DrawItem( m_selected
);
5479 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5481 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5482 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5483 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5484 //else if ( event.GetWindow() )
5486 HandleFocusChange(event
.GetWindow());
5491 // -----------------------------------------------------------------------
5493 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5495 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5498 // event.Skip() being commented out is aworkaround for bug reported
5499 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5503 // -----------------------------------------------------------------------
5505 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5507 m_iFlags
|= wxPG_FL_SCROLLED
;
5512 // -----------------------------------------------------------------------
5514 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5516 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5518 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5522 // -----------------------------------------------------------------------
5523 // Property editor related functions
5524 // -----------------------------------------------------------------------
5526 // noDefCheck = true prevents infinite recursion.
5527 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorclass
,
5528 const wxString
& name
,
5531 wxASSERT( editorclass
);
5533 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5534 RegisterDefaultEditors();
5536 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorclass
;
5541 // Registers all default editor classes
5542 void wxPropertyGrid::RegisterDefaultEditors()
5544 wxPGRegisterDefaultEditorClass( TextCtrl
);
5545 wxPGRegisterDefaultEditorClass( Choice
);
5546 wxPGRegisterDefaultEditorClass( ComboBox
);
5547 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5548 #if wxPG_INCLUDE_CHECKBOX
5549 wxPGRegisterDefaultEditorClass( CheckBox
);
5551 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5553 // Register SpinCtrl etc. editors before use
5554 RegisterAdditionalEditors();
5557 // -----------------------------------------------------------------------
5558 // wxPGStringTokenizer
5559 // Needed to handle C-style string lists (e.g. "str1" "str2")
5560 // -----------------------------------------------------------------------
5562 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5563 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5567 wxPGStringTokenizer::~wxPGStringTokenizer()
5571 bool wxPGStringTokenizer::HasMoreTokens()
5573 const wxString
& str
= *m_str
;
5575 wxString::const_iterator i
= m_curPos
;
5577 wxUniChar delim
= m_delimeter
;
5579 wxUniChar prev_a
= wxT('\0');
5581 bool inToken
= false;
5583 while ( i
!= str
.end() )
5592 m_readyToken
.clear();
5597 if ( prev_a
!= wxT('\\') )
5601 if ( a
!= wxT('\\') )
5621 m_curPos
= str
.end();
5629 wxString
wxPGStringTokenizer::GetNextToken()
5631 return m_readyToken
;
5634 // -----------------------------------------------------------------------
5636 // -----------------------------------------------------------------------
5638 wxPGChoiceEntry::wxPGChoiceEntry()
5639 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5643 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5644 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5645 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5649 // -----------------------------------------------------------------------
5651 // -----------------------------------------------------------------------
5653 wxPGChoicesData::wxPGChoicesData()
5658 wxPGChoicesData::~wxPGChoicesData()
5663 void wxPGChoicesData::Clear()
5667 for ( i
=0; i
<m_items
.size(); i
++ )
5679 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5681 wxASSERT( m_items
.size() == 0 );
5685 for ( i
=0; i
<data
->GetCount(); i
++ )
5686 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5689 // -----------------------------------------------------------------------
5691 // -----------------------------------------------------------------------
5693 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5697 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5698 m_data
->Insert( -1, p
);
5702 // -----------------------------------------------------------------------
5704 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5708 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5709 p
->SetBitmap(bitmap
);
5710 m_data
->Insert( -1, p
);
5714 // -----------------------------------------------------------------------
5716 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5720 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5721 m_data
->Insert(index
, p
);
5725 // -----------------------------------------------------------------------
5727 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5731 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5732 m_data
->Insert( index
, p
);
5736 // -----------------------------------------------------------------------
5738 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5744 while ( index
< GetCount() )
5746 int cmpRes
= GetLabel(index
).Cmp(label
);
5752 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5753 m_data
->Insert( index
, p
);
5757 // -----------------------------------------------------------------------
5759 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5763 unsigned int itemcount
= 0;
5764 const wxChar
** p
= &labels
[0];
5765 while ( *p
) { p
++; itemcount
++; }
5768 for ( i
= 0; i
< itemcount
; i
++ )
5770 int value
= wxPG_INVALID_VALUE
;
5773 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5777 // -----------------------------------------------------------------------
5779 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5784 unsigned int itemcount
= arr
.size();
5786 for ( i
= 0; i
< itemcount
; i
++ )
5788 int value
= wxPG_INVALID_VALUE
;
5791 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5795 // -----------------------------------------------------------------------
5797 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5802 unsigned int itemcount
= arr
.size();
5804 for ( i
= 0; i
< itemcount
; i
++ )
5806 int value
= wxPG_INVALID_VALUE
;
5807 if ( &arrint
&& arrint
.size() )
5809 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5813 // -----------------------------------------------------------------------
5815 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5817 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5819 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5820 delete m_data
->Item(i
);
5821 m_data
->m_items
.RemoveAt(nIndex
, count
);
5824 // -----------------------------------------------------------------------
5826 int wxPGChoices::Index( const wxString
& str
) const
5831 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5833 if ( m_data
->Item(i
)->GetText() == str
)
5840 // -----------------------------------------------------------------------
5842 int wxPGChoices::Index( int val
) const
5847 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5849 if ( m_data
->Item(i
)->GetValue() == val
)
5856 // -----------------------------------------------------------------------
5858 wxArrayString
wxPGChoices::GetLabels() const
5863 if ( this && IsOk() )
5864 for ( i
=0; i
<GetCount(); i
++ )
5865 arr
.push_back(GetLabel(i
));
5870 // -----------------------------------------------------------------------
5872 bool wxPGChoices::HasValues() const
5877 // -----------------------------------------------------------------------
5879 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5886 for ( i
=0; i
< strings
.size(); i
++ )
5888 int index
= Index(strings
[i
]);
5890 arr
.Add(GetValue(index
));
5892 arr
.Add(wxPG_INVALID_VALUE
);
5899 // -----------------------------------------------------------------------
5901 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5902 wxArrayString
* unmatched
) const
5909 for ( i
=0; i
< strings
.size(); i
++ )
5911 const wxString
& str
= strings
[i
];
5912 int index
= Index(str
);
5915 else if ( unmatched
)
5916 unmatched
->Add(str
);
5923 // -----------------------------------------------------------------------
5925 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5929 if ( data
!= wxPGChoicesEmptyData
)
5936 // -----------------------------------------------------------------------
5938 void wxPGChoices::Init()
5940 m_data
= wxPGChoicesEmptyData
;
5943 // -----------------------------------------------------------------------
5945 void wxPGChoices::Free()
5947 if ( m_data
!= wxPGChoicesEmptyData
)
5950 m_data
= wxPGChoicesEmptyData
;
5954 // -----------------------------------------------------------------------
5955 // wxPropertyGridEvent
5956 // -----------------------------------------------------------------------
5958 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5961 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5962 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5963 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5964 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5965 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5966 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5967 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5968 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5969 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5972 // -----------------------------------------------------------------------
5974 void wxPropertyGridEvent::Init()
5976 m_validationInfo
= NULL
;
5978 m_wasVetoed
= false;
5981 // -----------------------------------------------------------------------
5983 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5984 : wxCommandEvent(commandType
,id
)
5990 // -----------------------------------------------------------------------
5992 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5993 : wxCommandEvent(event
)
5995 m_eventType
= event
.GetEventType();
5996 m_eventObject
= event
.m_eventObject
;
5998 m_property
= event
.m_property
;
5999 m_validationInfo
= event
.m_validationInfo
;
6000 m_canVeto
= event
.m_canVeto
;
6001 m_wasVetoed
= event
.m_wasVetoed
;
6004 // -----------------------------------------------------------------------
6006 wxPropertyGridEvent::~wxPropertyGridEvent()
6010 // -----------------------------------------------------------------------
6012 wxEvent
* wxPropertyGridEvent::Clone() const
6014 return new wxPropertyGridEvent( *this );
6017 // -----------------------------------------------------------------------
6018 // wxPropertyGridPopulator
6019 // -----------------------------------------------------------------------
6021 wxPropertyGridPopulator::wxPropertyGridPopulator()
6025 wxPGGlobalVars
->m_offline
++;
6028 // -----------------------------------------------------------------------
6030 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6033 m_propHierarchy
.clear();
6036 // -----------------------------------------------------------------------
6038 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6044 // -----------------------------------------------------------------------
6046 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6049 // Free unused sets of choices
6050 wxPGHashMapS2P::iterator it
;
6052 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6054 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6061 m_pg
->GetPanel()->Refresh();
6063 wxPGGlobalVars
->m_offline
--;
6066 // -----------------------------------------------------------------------
6068 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6069 const wxString
& propLabel
,
6070 const wxString
& propName
,
6071 const wxString
* propValue
,
6072 wxPGChoices
* pChoices
)
6074 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6075 wxPGProperty
* parent
= GetCurParent();
6077 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6079 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6083 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6085 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6089 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6091 property
->SetLabel(propLabel
);
6092 property
->DoSetName(propName
);
6094 if ( pChoices
&& pChoices
->IsOk() )
6095 property
->SetChoices(*pChoices
);
6097 m_state
->DoInsert(parent
, -1, property
);
6100 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6105 // -----------------------------------------------------------------------
6107 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6109 m_propHierarchy
.push_back(property
);
6110 DoScanForChildren();
6111 m_propHierarchy
.pop_back();
6114 // -----------------------------------------------------------------------
6116 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6117 const wxString
& idString
)
6119 wxPGChoices choices
;
6122 if ( choicesString
[0] == wxT('@') )
6124 wxString ids
= choicesString
.substr(1);
6125 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6126 if ( it
== m_dictIdChoices
.end() )
6127 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6129 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6134 if ( idString
.length() )
6136 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6137 if ( it
!= m_dictIdChoices
.end() )
6139 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6146 // Parse choices string
6147 wxString::const_iterator it
= choicesString
.begin();
6151 bool labelValid
= false;
6153 for ( ; it
!= choicesString
.end(); it
++ )
6159 if ( c
== wxT('"') )
6164 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6165 choices
.Add(label
, l
);
6168 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6173 else if ( c
== wxT('=') )
6180 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6187 if ( c
== wxT('"') )
6200 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6201 choices
.Add(label
, l
);
6204 if ( !choices
.IsOk() )
6206 choices
.EnsureData();
6210 if ( idString
.length() )
6211 m_dictIdChoices
[idString
] = choices
.GetData();
6218 // -----------------------------------------------------------------------
6220 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6222 if ( s
.Last() == wxT('%') )
6224 wxString s2
= s
.substr(0,s
.length()-1);
6226 if ( s2
.ToLong(&val
, 10) )
6228 *pval
= (val
*max
)/100;
6234 return s
.ToLong(pval
, 10);
6237 // -----------------------------------------------------------------------
6239 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6240 const wxString
& type
,
6241 const wxString
& value
)
6243 int l
= m_propHierarchy
.size();
6247 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6248 wxString valuel
= value
.Lower();
6251 if ( type
.length() == 0 )
6256 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6258 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6260 else if ( value
.ToLong(&v
, 0) )
6267 if ( type
== wxT("string") )
6271 else if ( type
== wxT("int") )
6274 value
.ToLong(&v
, 0);
6277 else if ( type
== wxT("bool") )
6279 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6286 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6291 p
->SetAttribute( name
, variant
);
6296 // -----------------------------------------------------------------------
6298 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6300 wxLogError(_("Error in resource: %s"),msg
.c_str());
6303 // -----------------------------------------------------------------------
6305 #endif // wxUSE_PROPGRID