1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/object.h"
23 #include "wx/string.h"
26 #include "wx/window.h"
29 #include "wx/dcmemory.h"
30 #include "wx/button.h"
33 #include "wx/cursor.h"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
37 #include "wx/choice.h"
38 #include "wx/stattext.h"
39 #include "wx/scrolwin.h"
40 #include "wx/dirdlg.h"
41 #include "wx/layout.h"
43 #include "wx/textdlg.h"
44 #include "wx/filedlg.h"
45 #include "wx/statusbr.h"
51 // This define is necessary to prevent macro clearing
52 #define __wxPG_SOURCE_FILE__
54 #include <wx/propgrid/propgrid.h>
55 #include <wx/propgrid/editors.h>
57 #if wxPG_USE_RENDERER_NATIVE
58 #include <wx/renderer.h>
61 #include <wx/odcombo.h>
64 #include "wx/dcbuffer.h"
65 #include <wx/clipbrd.h>
66 #include <wx/dataobj.h>
69 #include <wx/msw/private.h>
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 #define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 #define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 #define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 #define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 #define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const wxChar
*wxPropertyGridNameStr
= wxT("wxPropertyGrid");
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // NB: We prefer to use wxModule, as it offers more consistent behavior
142 // across platforms. However, for those rare problem situations, we
143 // also need to offer option to use simpler approach.
144 // -----------------------------------------------------------------------
146 #ifndef wxPG_USE_WXMODULE
147 #define wxPG_USE_WXMODULE 1
150 #if wxPG_USE_WXMODULE
152 #include <wx/module.h>
154 class wxPGGlobalVarsClassManager
: public wxModule
156 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
158 wxPGGlobalVarsClassManager() {}
159 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
160 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
163 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
165 #else // !wxPG_USE_WXMODULE
167 class wxPGGlobalVarsClassManager
170 wxPGGlobalVarsClassManager() {}
171 ~wxPGGlobalVarsClassManager() { delete wxPGGlobalVars
; }
174 static wxPGGlobalVarsClassManager gs_pgGlobalVarsClassManager
;
179 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
182 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
184 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
186 m_boolChoices
.Add(_("False"));
187 m_boolChoices
.Add(_("True"));
189 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
191 m_defaultRenderer
= new wxPGDefaultRenderer();
193 m_autoGetTranslation
= false;
202 wxVariantClassInfo_long
= wxPGVariantDataGetClassInfo(v
.GetData());
205 wxVariantClassInfo_string
= wxPGVariantDataGetClassInfo(v
.GetData());
208 wxVariantClassInfo_double
= wxPGVariantDataGetClassInfo(v
.GetData());
211 wxVariantClassInfo_bool
= wxPGVariantDataGetClassInfo(v
.GetData());
214 wxVariantClassInfo_arrstring
= wxPGVariantDataGetClassInfo(v
.GetData());
217 wxVariant
v2((wxObject
*)&col
);
218 wxVariantClassInfo_wxobject
= wxPGVariantDataGetClassInfo(v2
.GetData());
222 wxVariantClassInfo_list
= wxPGVariantDataGetClassInfo(v
.GetData());
225 wxVariantClassInfo_wxColour
= wxPGVariantDataGetClassInfo(v
.GetData());
228 v
= wxVariant(wxDateTime::Now());
229 wxVariantClassInfo_datetime
= wxPGVariantDataGetClassInfo(v
.GetData());
232 // Prepare some shared variants
233 m_vEmptyString
= wxString();
235 m_vMinusOne
= (long) -1;
239 // Prepare cached string constants
240 m_strMin
= wxS("Min");
241 m_strMax
= wxS("Max");
242 m_strUnits
= wxS("Units");
243 m_strInlineHelp
= wxS("InlineHelp");
251 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
255 delete m_defaultRenderer
;
257 // This will always have one ref
258 delete m_fontFamilyChoices
;
261 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
262 delete ((wxValidator
*)m_arrValidators
[i
]);
266 // Destroy value type class instances.
267 wxPGHashMapS2P::iterator vt_it
;
269 // Destroy editor class instances.
270 // iterate over all the elements in the class
271 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
273 delete ((wxPGEditor
*)vt_it
->second
);
276 delete wxPGProperty::sm_wxPG_LABEL
;
279 // -----------------------------------------------------------------------
281 // -----------------------------------------------------------------------
284 // This class is a wxBrush derivative used in the background colour
285 // brush cache. It adds wxPG-type colour-in-long to the class.
286 // JMS: Yes I know wxBrush doesn't actually hold the value (refcounted
287 // object does), but this is simpler implementation and equally
291 class wxPGBrush
: public wxBrush
294 wxPGBrush( const wxColour
& colour
);
296 virtual ~wxPGBrush() { }
297 void SetColour2( const wxColour
& colour
);
298 inline long GetColourAsLong() const { return m_colAsLong
; }
304 void wxPGBrush::SetColour2( const wxColour
& colour
)
306 wxBrush::SetColour(colour
);
307 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
311 wxPGBrush::wxPGBrush() : wxBrush()
317 wxPGBrush::wxPGBrush( const wxColour
& colour
) : wxBrush(colour
)
319 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
323 // -----------------------------------------------------------------------
325 // -----------------------------------------------------------------------
328 // Same as wxPGBrush, but for wxColour instead.
331 class wxPGColour
: public wxColour
334 wxPGColour( const wxColour
& colour
);
336 virtual ~wxPGColour() { }
337 void SetColour2( const wxColour
& colour
);
338 inline long GetColourAsLong() const { return m_colAsLong
; }
344 void wxPGColour::SetColour2( const wxColour
& colour
)
347 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
351 wxPGColour::wxPGColour() : wxColour()
357 wxPGColour::wxPGColour( const wxColour
& colour
) : wxColour(colour
)
359 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
363 // -----------------------------------------------------------------------
365 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
366 // and tries to commit property value.
367 // -----------------------------------------------------------------------
369 class wxPGTLWHandler
: public wxEvtHandler
373 wxPGTLWHandler( wxPropertyGrid
* pg
)
381 void OnClose( wxCloseEvent
& event
)
383 // ClearSelection forces value validation/commit.
384 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
394 wxPropertyGrid
* m_pg
;
396 DECLARE_EVENT_TABLE()
399 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
400 EVT_CLOSE(wxPGTLWHandler::OnClose
)
403 // -----------------------------------------------------------------------
405 // -----------------------------------------------------------------------
408 // wxPGCanvas acts as a graphics sub-window of the
409 // wxScrolledWindow that wxPropertyGrid is.
411 class wxPGCanvas
: public wxPanel
414 wxPGCanvas() : wxPanel()
417 virtual ~wxPGCanvas() { }
420 void OnMouseMove( wxMouseEvent
&event
)
422 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
423 pg
->OnMouseMove( event
);
426 void OnMouseClick( wxMouseEvent
&event
)
428 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
429 pg
->OnMouseClick( event
);
432 void OnMouseUp( wxMouseEvent
&event
)
434 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
435 pg
->OnMouseUp( event
);
438 void OnMouseRightClick( wxMouseEvent
&event
)
440 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
441 pg
->OnMouseRightClick( event
);
444 void OnMouseDoubleClick( wxMouseEvent
&event
)
446 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
447 pg
->OnMouseDoubleClick( event
);
450 void OnKey( wxKeyEvent
& event
)
452 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
456 void OnKeyUp( wxKeyEvent
& event
)
458 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
459 pg
->OnKeyUp( event
);
462 void OnNavigationKey( wxNavigationKeyEvent
& event
)
464 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
465 pg
->OnNavigationKey( event
);
468 void OnPaint( wxPaintEvent
& event
);
471 DECLARE_EVENT_TABLE()
475 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
476 EVT_MOTION(wxPGCanvas::OnMouseMove
)
477 EVT_PAINT(wxPGCanvas::OnPaint
)
478 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
479 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
480 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
481 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
482 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
483 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
484 EVT_CHAR(wxPGCanvas::OnKey
)
485 EVT_NAVIGATION_KEY(wxPGCanvas::OnNavigationKey
)
489 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
491 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
492 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
496 // Don't paint after destruction has begun
497 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
500 // Update everything inside the box
501 wxRect r
= GetUpdateRegion().GetBox();
503 // Repaint this rectangle
504 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
506 // We assume that the size set when grid is shown
507 // is what is desired.
508 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
511 // -----------------------------------------------------------------------
513 // -----------------------------------------------------------------------
515 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
517 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
518 EVT_IDLE(wxPropertyGrid::OnIdle
)
519 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
520 EVT_PAINT(wxPropertyGrid::OnPaint
)
521 EVT_SIZE(wxPropertyGrid::OnResize
)
522 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
523 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
524 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
525 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
526 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
527 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
528 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
529 EVT_TEXT_ENTER(wxPG_SUBID1
,wxPropertyGrid::OnCustomEditorEvent
)
530 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
534 // -----------------------------------------------------------------------
536 wxPropertyGrid::wxPropertyGrid()
542 // -----------------------------------------------------------------------
544 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
553 Create(parent
,id
,pos
,size
,style
,name
);
556 // -----------------------------------------------------------------------
558 bool wxPropertyGrid::Create( wxWindow
*parent
,
566 if ( !(style
&wxBORDER_MASK
) )
567 style
|= wxSIMPLE_BORDER
;
572 // This prevents crash under Win2K, but still
573 // enables keyboard navigation
574 if ( style
& wxTAB_TRAVERSAL
)
576 style
&= ~(wxTAB_TRAVERSAL
);
577 style
|= wxWANTS_CHARS
;
580 if ( style
& wxTAB_TRAVERSAL
)
581 style
|= wxWANTS_CHARS
;
584 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
591 // -----------------------------------------------------------------------
594 // Initialize values to defaults
596 void wxPropertyGrid::Init1()
598 #if !wxPG_USE_WXMODULE
599 if ( !wxPGGlobalVars
)
600 wxPGGlobalVars
= new wxPGGlobalVarsClass();
603 // Register editor classes, if necessary.
604 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
605 RegisterDefaultEditors();
608 m_pState
= (wxPropertyGridPageState
*) NULL
;
609 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
610 m_selected
= (wxPGProperty
*) NULL
;
612 m_propHover
= (wxPGProperty
*) NULL
;
613 m_eventObject
= this;
614 m_curFocused
= (wxWindow
*) NULL
;
616 m_inDoPropertyChanged
= 0;
617 m_inCommitChangesFromEditor
= 0;
618 m_inDoSelectProperty
= 0;
619 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
625 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
626 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
627 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
628 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
629 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
630 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
631 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
632 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
633 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
634 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
635 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
636 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
637 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
639 m_coloursCustomized
= 0;
644 #if wxPG_DOUBLE_BUFFER
645 m_doubleBuffer
= (wxBitmap
*) NULL
;
648 m_windowsToDelete
= NULL
;
650 #ifndef wxPG_ICON_WIDTH
656 m_iconWidth
= wxPG_ICON_WIDTH
;
661 m_gutterWidth
= wxPG_GUTTER_MIN
;
662 m_subgroup_extramargin
= 10;
666 m_width
= m_height
= 0;
668 SetButtonShortcut(0);
670 m_keyComboConsumed
= 0;
672 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
675 m_chgInfo_changedProperty
= NULL
;
678 // -----------------------------------------------------------------------
681 // Initialize after parent etc. set
683 void wxPropertyGrid::Init2()
685 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
688 // Smaller controls on Mac
689 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
692 // Now create state, if one didn't exist already
693 // (wxPropertyGridManager might have created it for us).
696 m_pState
= CreateState();
697 m_pState
->m_pPropGrid
= this;
698 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
701 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
702 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
704 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
706 m_pState
->InitNonCatMode();
708 m_pState
->m_properties
= m_pState
->m_abcArray
;
711 GetClientSize(&m_width
,&m_height
);
713 #ifndef wxPG_ICON_WIDTH
714 // create two bitmap nodes for drawing
715 m_expandbmp
= new wxBitmap(expand_xpm
);
716 m_collbmp
= new wxBitmap(collapse_xpm
);
718 // calculate average font height for bitmap centering
720 m_iconWidth
= m_expandbmp
->GetWidth();
721 m_iconHeight
= m_expandbmp
->GetHeight();
724 m_curcursor
= wxCURSOR_ARROW
;
725 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
727 // adjust bitmap icon y position so they are centered
728 m_vspacing
= wxPG_DEFAULT_VSPACING
;
732 wxFont useFont
= wxScrolledWindow::GetFont();
733 wxScrolledWindow::SetOwnFont( useFont
);
736 // This should be otherwise called by SetOwnFont
737 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
739 // Add base brush item
740 m_arrBgBrushes
.Add((void*)new wxPGBrush());
742 // Add base colour items
743 m_arrFgCols
.Add((void*)new wxPGColour());
744 m_arrFgCols
.Add((void*)new wxPGColour());
748 // This helps with flicker
749 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
752 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
753 m_tlp
= ::wxGetTopLevelParent(this);
754 m_tlwHandler
= handler
;
755 m_tlp
->PushEventHandler(handler
);
757 // set virtual size to this window size
758 wxSize wndsize
= GetSize();
759 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
761 m_timeCreated
= ::wxGetLocalTimeMillis();
763 m_canvas
= new wxPGCanvas();
764 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
765 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
766 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
768 m_iFlags
|= wxPG_FL_INITIALIZED
;
770 m_ncWidth
= wndsize
.GetWidth();
772 // Need to call OnResize handler or size given in constructor/Create
774 wxSizeEvent
sizeEvent(wndsize
,0);
778 // -----------------------------------------------------------------------
780 wxPropertyGrid::~wxPropertyGrid()
784 DoSelectProperty(NULL
);
786 // This should do prevent things from going too badly wrong
787 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
789 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
790 m_canvas
->ReleaseMouse();
792 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
793 m_tlp
->RemoveEventHandler(handler
);
797 if ( IsEditorsValueModified() )
798 ::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).)"),
799 wxS("wxPropertyGrid Debug Warning") );
802 #if wxPG_DOUBLE_BUFFER
803 if ( m_doubleBuffer
)
804 delete m_doubleBuffer
;
807 delete m_windowsToDelete
;
809 //m_selected = (wxPGProperty*) NULL;
811 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
814 delete m_cursorSizeWE
;
816 #ifndef wxPG_ICON_WIDTH
821 // Delete cached text colours.
822 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
824 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
827 // Delete cached brushes.
828 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
830 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
833 // Delete common value records
834 for ( i
=0; i
<m_commonValues
.size(); i
++ )
836 delete GetCommonValue(i
);
840 // -----------------------------------------------------------------------
842 bool wxPropertyGrid::Destroy()
844 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
845 m_canvas
->ReleaseMouse();
847 return wxScrolledWindow::Destroy();
850 // -----------------------------------------------------------------------
852 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
854 return new wxPropertyGridPageState();
857 // -----------------------------------------------------------------------
858 // wxPropertyGrid overridden wxWindow methods
859 // -----------------------------------------------------------------------
861 void wxPropertyGrid::SetWindowStyleFlag( long style
)
863 long old_style
= m_windowStyle
;
865 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
867 wxASSERT( m_pState
);
869 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
872 EnableCategories( true );
874 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
876 // Disable categories
877 EnableCategories( false );
879 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
885 PrepareAfterItemsAdded();
887 m_pState
->m_itemsAdded
= 1;
889 #if wxPG_SUPPORT_TOOLTIPS
890 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
896 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
897 SetToolTip ( tooltip );
898 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
901 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
906 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
911 wxScrolledWindow::SetWindowStyleFlag ( style
);
913 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
915 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
917 CalculateFontAndBitmapStuff( m_vspacing
);
923 // -----------------------------------------------------------------------
925 void wxPropertyGrid::Freeze()
929 wxScrolledWindow::Freeze();
934 // -----------------------------------------------------------------------
936 void wxPropertyGrid::Thaw()
942 wxScrolledWindow::Thaw();
943 RecalculateVirtualSize();
944 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
948 // Force property re-selection
950 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
954 // -----------------------------------------------------------------------
956 void wxPropertyGrid::SetExtraStyle( long exStyle
)
958 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
960 #if defined(__WXMSW__)
963 // Don't use WS_EX_COMPOSITED just now.
966 if ( m_iFlags & wxPG_FL_IN_MANAGER )
967 hWnd = (HWND)GetParent()->GetHWND();
969 hWnd = (HWND)GetHWND();
971 ::SetWindowLong( hWnd, GWL_EXSTYLE,
972 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
975 //#elif defined(__WXGTK20__)
977 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
978 // truly was double-buffered.
979 if ( !this->IsDoubleBuffered() )
981 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
985 #if wxPG_DOUBLE_BUFFER
986 delete m_doubleBuffer
;
987 m_doubleBuffer
= NULL
;
992 wxScrolledWindow::SetExtraStyle( exStyle
);
994 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
995 m_pState
->InitNonCatMode();
997 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
998 m_windowStyle
|= wxPG_TOOLTIPS
;
1001 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1004 // -----------------------------------------------------------------------
1006 // returns the best acceptable minimal size
1007 wxSize
wxPropertyGrid::DoGetBestSize() const
1010 if ( m_lineHeight
> hei
)
1012 wxSize sz
= wxSize( 60, hei
+40 );
1018 // -----------------------------------------------------------------------
1019 // wxPropertyGrid Font and Colour Methods
1020 // -----------------------------------------------------------------------
1022 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1026 m_captionFont
= wxScrolledWindow::GetFont();
1028 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1029 m_subgroup_extramargin
= x
+ (x
/2);
1032 #if wxPG_USE_RENDERER_NATIVE
1033 m_iconWidth
= wxPG_ICON_WIDTH
;
1034 #elif wxPG_ICON_WIDTH
1036 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1037 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1038 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1042 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1043 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1044 m_gutterWidth
= wxPG_GUTTER_MIN
;
1047 if ( vspacing
<= 1 ) vdiv
= 12;
1048 else if ( vspacing
>= 3 ) vdiv
= 3;
1050 m_spacingy
= m_fontHeight
/ vdiv
;
1051 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1052 m_spacingy
= wxPG_YSPACING_MIN
;
1055 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1056 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1058 m_captionFont
.SetWeight(wxBOLD
);
1059 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1061 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1062 m_visPropArray
.SetCount((m_height
/m_lineHeight
)+10);
1065 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1066 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1069 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1071 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1072 RecalculateVirtualSize();
1074 InvalidateBestSize();
1077 // -----------------------------------------------------------------------
1079 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1085 // -----------------------------------------------------------------------
1087 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1088 int ga
= 1000, int ba
= 1000,
1089 bool forceDifferent
= false)
1096 // Recursion guard (allow 2 max)
1097 static int isinside
= 0;
1099 wxCHECK_MSG( isinside
< 3,
1101 wxT("wxPGAdjustColour should not be recursively called more than once") );
1106 int g
= src
.Green();
1109 if ( r2
>255 ) r2
= 255;
1110 else if ( r2
<0) r2
= 0;
1112 if ( g2
>255 ) g2
= 255;
1113 else if ( g2
<0) g2
= 0;
1115 if ( b2
>255 ) b2
= 255;
1116 else if ( b2
<0) b2
= 0;
1118 // Make sure they are somewhat different
1119 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1120 dst
= wxPGAdjustColour(src
,-(ra
*2));
1122 dst
= wxColour(r2
,g2
,b2
);
1124 // Recursion guard (allow 2 max)
1131 static int wxPGGetColAvg( const wxColour
& col
)
1133 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1137 void wxPropertyGrid::RegainColours()
1139 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1141 if ( !(m_coloursCustomized
& 0x0002) )
1143 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1145 // Make sure colour is dark enough
1147 int colDec
= wxPGGetColAvg(col
) - 230;
1149 int colDec
= wxPGGetColAvg(col
) - 200;
1152 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1157 if ( !(m_coloursCustomized
& 0x0001) )
1158 m_colMargin
= m_colCapBack
;
1160 if ( !(m_coloursCustomized
& 0x0004) )
1167 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1168 m_colCapFore
= capForeCol
;
1170 // Set the cached colour as well.
1171 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1174 if ( !(m_coloursCustomized
& 0x0008) )
1176 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1177 m_colPropBack
= bgCol
;
1179 // Set the cached brush as well.
1180 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1183 if ( !(m_coloursCustomized
& 0x0010) )
1185 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1186 m_colPropFore
= fgCol
;
1188 // Set the cached colour as well.
1189 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1192 if ( !(m_coloursCustomized
& 0x0020) )
1193 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1195 if ( !(m_coloursCustomized
& 0x0040) )
1196 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1198 if ( !(m_coloursCustomized
& 0x0080) )
1199 m_colLine
= m_colCapBack
;
1201 if ( !(m_coloursCustomized
& 0x0100) )
1202 m_colDisPropFore
= m_colCapFore
;
1204 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1207 // -----------------------------------------------------------------------
1209 void wxPropertyGrid::ResetColours()
1211 m_coloursCustomized
= 0;
1218 // -----------------------------------------------------------------------
1220 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1222 // Must disable active editor.
1225 bool selRes
= ClearSelection();
1226 wxPG_CHECK_MSG_DBG( selRes
,
1228 wxT("failed to deselect a property (editor probably had invalid value)") );
1231 // TODO: Following code is disabled with wxMac because
1232 // it is reported to fail. I (JMS) cannot debug it
1233 // personally right now.
1234 #if !defined(__WXMAC__)
1235 bool res
= wxScrolledWindow::SetFont( font
);
1238 CalculateFontAndBitmapStuff( m_vspacing
);
1241 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1249 // TODO: Remove after SetFont crash fixed.
1250 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1252 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."));
1258 // -----------------------------------------------------------------------
1260 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1263 m_coloursCustomized
|= 0x80;
1267 // -----------------------------------------------------------------------
1269 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1272 m_coloursCustomized
|= 0x01;
1276 // -----------------------------------------------------------------------
1278 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1280 m_colPropBack
= col
;
1281 m_coloursCustomized
|= 0x08;
1283 // Set the cached brush as well.
1284 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1289 // -----------------------------------------------------------------------
1291 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1293 m_colPropFore
= col
;
1294 m_coloursCustomized
|= 0x10;
1296 // Set the cached colour as well.
1297 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1302 // -----------------------------------------------------------------------
1304 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1306 m_colEmptySpace
= col
;
1311 // -----------------------------------------------------------------------
1313 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1315 m_colDisPropFore
= col
;
1316 m_coloursCustomized
|= 0x100;
1320 // -----------------------------------------------------------------------
1322 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1325 m_coloursCustomized
|= 0x20;
1329 // -----------------------------------------------------------------------
1331 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1334 m_coloursCustomized
|= 0x40;
1338 // -----------------------------------------------------------------------
1340 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1343 m_coloursCustomized
|= 0x02;
1347 // -----------------------------------------------------------------------
1349 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1352 m_coloursCustomized
|= 0x04;
1354 // Set the cached colour as well.
1355 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1360 // -----------------------------------------------------------------------
1362 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1364 unsigned char ind
= index
;
1366 p
->m_bgColIndex
= ind
;
1369 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1370 SetBackgroundColourIndex(p
->Item(i
),index
);
1373 // -----------------------------------------------------------------------
1375 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1377 wxPG_PROP_ARG_CALL_PROLOG()
1382 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1384 // As it is most likely that the previous colour is used, start comparison
1386 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1388 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1397 colInd
= m_arrBgBrushes
.size();
1398 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1399 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1403 SetBackgroundColourIndex(p
,colInd
);
1405 // If this was on a visible grid, then draw it.
1406 DrawItemAndChildren(p
);
1409 // -----------------------------------------------------------------------
1411 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1413 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1415 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1418 // -----------------------------------------------------------------------
1420 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1422 unsigned char ind
= index
;
1424 p
->m_fgColIndex
= ind
;
1426 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1429 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1430 SetTextColourIndex( p
->Item(i
), index
, flags
);
1434 // -----------------------------------------------------------------------
1436 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1441 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1443 // As it is most likely that the previous colour is used, start comparison
1445 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1447 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1456 colInd
= m_arrFgCols
.size();
1457 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1458 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1464 // -----------------------------------------------------------------------
1466 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1469 wxPG_PROP_ARG_CALL_PROLOG()
1471 if ( p
->IsCategory() )
1473 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1474 cat
->SetTextColIndex(CacheColour(colour
));
1480 flags
|= wxPG_RECURSE
;
1481 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1483 DrawItemAndChildren(p
);
1486 // -----------------------------------------------------------------------
1488 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1490 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1492 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1495 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1497 wxPG_PROP_ARG_CALL_PROLOG()
1499 SetBackgroundColourIndex( p
, 0 );
1500 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1502 if ( p
->IsCategory() )
1504 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1505 cat
->SetTextColIndex(1);
1509 // -----------------------------------------------------------------------
1510 // wxPropertyGrid property adding and removal
1511 // -----------------------------------------------------------------------
1513 void wxPropertyGrid::PrepareAfterItemsAdded()
1515 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1517 m_pState
->m_itemsAdded
= 0;
1519 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1522 RecalculateVirtualSize();
1525 // -----------------------------------------------------------------------
1526 // wxPropertyGrid property value setting and getting
1527 // -----------------------------------------------------------------------
1529 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1531 m_pState
->DoSetPropertyValueUnspecified(p
);
1532 DrawItemAndChildren(p
);
1534 wxPGProperty
* parent
= p
->GetParent();
1535 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1538 parent
= parent
->GetParent();
1542 // -----------------------------------------------------------------------
1543 // wxPropertyGrid property operations
1544 // -----------------------------------------------------------------------
1546 void wxPropertyGrid::DoSetPropertyName( wxPGProperty
* p
, const wxString
& newname
)
1548 wxCHECK_RET( p
, wxT("invalid property id") );
1550 if ( p
->GetBaseName().Len() ) m_pState
->m_dictName
.erase( p
->GetBaseName() );
1551 if ( newname
.Len() ) m_pState
->m_dictName
[newname
] = (void*) p
;
1553 p
->DoSetName(newname
);
1556 // -----------------------------------------------------------------------
1558 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1560 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1564 bool changed
= false;
1566 // Is it inside collapsed section?
1567 if ( !p
->IsVisible() )
1570 wxPGProperty
* parent
= p
->GetParent();
1571 wxPGProperty
* grandparent
= parent
->GetParent();
1573 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1574 Expand( grandparent
);
1582 GetViewStart(&vx
,&vy
);
1583 vy
*=wxPG_PIXELS_PER_UNIT
;
1589 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1590 m_iFlags
|= wxPG_FL_SCROLLED
;
1593 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1595 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1596 m_iFlags
|= wxPG_FL_SCROLLED
;
1606 // -----------------------------------------------------------------------
1607 // wxPropertyGrid helper methods called by properties
1608 // -----------------------------------------------------------------------
1610 // Control font changer helper.
1611 void wxPropertyGrid::SetCurControlBoldFont()
1613 wxASSERT( m_wndEditor
);
1614 m_wndEditor
->SetFont( m_captionFont
);
1617 // -----------------------------------------------------------------------
1619 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1622 #if wxPG_SMALL_SCREEN
1623 // On small-screen devices, always show dialogs with default position and size.
1624 return wxDefaultPosition
;
1626 int splitterX
= GetSplitterPosition();
1630 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1632 ImprovedClientToScreen( &x
, &y
);
1634 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1635 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1642 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1652 new_y
= y
+ m_lineHeight
;
1654 return wxPoint(new_x
,new_y
);
1658 // -----------------------------------------------------------------------
1660 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1662 if ( src_str
.length() == 0 )
1668 bool prev_is_slash
= false;
1670 wxString::const_iterator i
= src_str
.begin();
1674 for ( ; i
!= src_str
.end(); i
++ )
1678 if ( a
!= wxS('\\') )
1680 if ( !prev_is_slash
)
1686 if ( a
== wxS('n') )
1689 dst_str
<< wxS('\n');
1691 dst_str
<< wxS('\n');
1694 else if ( a
== wxS('t') )
1695 dst_str
<< wxS('\t');
1699 prev_is_slash
= false;
1703 if ( prev_is_slash
)
1705 dst_str
<< wxS('\\');
1706 prev_is_slash
= false;
1710 prev_is_slash
= true;
1717 // -----------------------------------------------------------------------
1719 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1721 if ( src_str
.length() == 0 )
1727 wxString::const_iterator i
= src_str
.begin();
1728 wxUniChar prev_a
= wxS('\0');
1732 for ( ; i
!= src_str
.end(); i
++ )
1736 if ( a
>= wxS(' ') )
1738 // This surely is not something that requires an escape sequence.
1743 // This might need...
1744 if ( a
== wxS('\r') )
1746 // DOS style line end.
1747 // Already taken care below
1749 else if ( a
== wxS('\n') )
1750 // UNIX style line end.
1751 dst_str
<< wxS("\\n");
1752 else if ( a
== wxS('\t') )
1754 dst_str
<< wxS('\t');
1757 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1767 // -----------------------------------------------------------------------
1769 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1773 return (wxPGProperty
*) NULL
;
1776 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1779 // -----------------------------------------------------------------------
1780 // wxPropertyGrid graphics related methods
1781 // -----------------------------------------------------------------------
1783 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1787 // Update everything inside the box
1788 wxRect r
= GetUpdateRegion().GetBox();
1790 dc
.SetPen(m_colEmptySpace
);
1791 dc
.SetBrush(m_colEmptySpace
);
1792 dc
.DrawRectangle(r
);
1795 // -----------------------------------------------------------------------
1797 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1798 wxPGProperty
* property
) const
1800 // Prepare rectangle to be used
1802 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1803 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1805 #if (wxPG_USE_RENDERER_NATIVE)
1807 #elif wxPG_ICON_WIDTH
1808 // Drawing expand/collapse button manually
1809 dc
.SetPen(m_colPropFore
);
1810 if ( property
->IsCategory() )
1811 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1813 dc
.SetBrush(m_colPropBack
);
1815 dc
.DrawRectangle( r
);
1816 int _y
= r
.y
+(m_iconWidth
/2);
1817 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1822 if ( property
->IsExpanded() )
1824 // wxRenderer functions are non-mutating in nature, so it
1825 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1826 // Hopefully this does not cause problems.
1827 #if (wxPG_USE_RENDERER_NATIVE)
1828 wxRendererNative::Get().DrawTreeItemButton(
1834 #elif wxPG_ICON_WIDTH
1843 #if (wxPG_USE_RENDERER_NATIVE)
1844 wxRendererNative::Get().DrawTreeItemButton(
1850 #elif wxPG_ICON_WIDTH
1851 int _x
= r
.x
+(m_iconWidth
/2);
1852 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1858 #if (wxPG_USE_RENDERER_NATIVE)
1860 #elif wxPG_ICON_WIDTH
1863 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1867 // -----------------------------------------------------------------------
1870 // This is the one called by OnPaint event handler and others.
1871 // topy and bottomy are already unscrolled (ie. physical)
1873 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1875 unsigned int bottomy
,
1876 const wxRect
* clipRect
)
1878 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1880 m_pState
->EnsureVirtualHeight();
1882 wxRect tempClipRect
;
1885 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1886 clipRect
= &tempClipRect
;
1889 // items added check
1890 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1892 int paintFinishY
= 0;
1894 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1897 bool isBuffered
= false;
1899 #if wxPG_DOUBLE_BUFFER
1900 wxMemoryDC
* bufferDC
= NULL
;
1902 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1904 if ( !m_doubleBuffer
)
1906 paintFinishY
= clipRect
->y
;
1911 bufferDC
= new wxMemoryDC();
1913 // If nothing was changed, then just copy from double-buffer
1914 bufferDC
->SelectObject( *m_doubleBuffer
);
1924 dc
.SetClippingRegion( *clipRect
);
1925 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1928 #if wxPG_DOUBLE_BUFFER
1931 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1932 bufferDC
, 0, 0, wxCOPY
);
1933 dc
.DestroyClippingRegion(); // Is this really necessary?
1939 // Clear area beyond bottomY?
1940 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1942 dc
.SetPen(m_colEmptySpace
);
1943 dc
.SetBrush(m_colEmptySpace
);
1944 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1948 // -----------------------------------------------------------------------
1950 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1951 const wxPGProperty
* firstItem
,
1952 const wxPGProperty
* lastItem
,
1953 const wxRect
* clipRect
,
1954 bool isBuffered
) const
1956 // TODO: This should somehow be eliminated.
1957 wxRect tempClipRect
;
1960 wxASSERT(firstItem
);
1962 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1963 clipRect
= &tempClipRect
;
1967 firstItem
= DoGetItemAtY(clipRect
->y
);
1971 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1973 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1976 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1979 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1980 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1982 int lh
= m_lineHeight
;
1985 int lastItemBottomY
;
1987 firstItemTopY
= clipRect
->y
;
1988 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1990 // Align y coordinates to item boundaries
1991 firstItemTopY
-= firstItemTopY
% lh
;
1992 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1993 lastItemBottomY
-= 1;
1995 // Entire range outside scrolled, visible area?
1996 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1999 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
2003 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
2004 firstItem->GetLabel().c_str(),
2005 lastItem->GetLabel().c_str(),
2006 (int)(lastItemBottomY - firstItemTopY),
2008 (unsigned long)clipRect );
2013 long windowStyle
= m_windowStyle
;
2019 // With wxPG_DOUBLE_BUFFER, do double buffering
2020 // - buffer's y = 0, so align cliprect and coordinates to that
2022 #if wxPG_DOUBLE_BUFFER
2028 xRelMod
= clipRect
->x
;
2029 yRelMod
= clipRect
->y
;
2032 // clipRect conversion
2040 firstItemTopY
-= yRelMod
;
2041 lastItemBottomY
-= yRelMod
;
2044 wxUnusedVar(isBuffered
);
2047 int x
= m_marginWidth
- xRelMod
;
2049 const wxFont
& normalfont
= m_font
;
2051 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
2053 bool isEnabled
= IsEnabled();
2056 // Prepare some pens and brushes that are often changed to.
2059 wxBrush
marginBrush(m_colMargin
);
2060 wxPen
marginPen(m_colMargin
);
2061 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2062 wxPen
linepen(m_colLine
,1,wxSOLID
);
2064 // pen that has same colour as text
2065 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2068 // Clear margin with background colour
2070 dc
.SetBrush( marginBrush
);
2071 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2073 dc
.SetPen( *wxTRANSPARENT_PEN
);
2074 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2077 const wxPGProperty
* selected
= m_selected
;
2078 const wxPropertyGridPageState
* state
= m_pState
;
2080 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2081 bool wasSelectedPainted
= false;
2084 // TODO: Only render columns that are within clipping region.
2086 dc
.SetFont(normalfont
);
2088 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2089 int endScanBottomY
= lastItemBottomY
+ lh
;
2090 int y
= firstItemTopY
;
2091 unsigned int arrInd
= 0;
2093 for ( ; !it
.AtEnd(); it
.Next() )
2095 const wxPGProperty
* p
= *it
;
2097 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2099 m_visPropArray
[arrInd
] = (wxPGProperty
*)p
;
2102 if ( y
> endScanBottomY
)
2109 m_visPropArray
[arrInd
] = NULL
;
2111 int gridWidth
= state
->m_width
;
2115 m_visPropArray
[arrInd
] != NULL
&& y
<= lastItemBottomY
;
2118 wxPGProperty
* p
=(wxPGProperty
*) m_visPropArray
[arrInd
];
2119 wxPGProperty
* nextP
= (wxPGProperty
*) m_visPropArray
[arrInd
+1];
2121 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2122 int textMarginHere
= x
;
2123 int renderFlags
= wxPGCellRenderer::Control
;
2125 int greyDepth
= m_marginWidth
;
2126 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2127 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2129 int greyDepthX
= greyDepth
- xRelMod
;
2131 // Use basic depth if in non-categoric mode and parent is base array.
2132 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2134 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2137 // Paint margin area
2138 dc
.SetBrush(marginBrush
);
2139 dc
.SetPen(marginPen
);
2140 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2142 dc
.SetPen( linepen
);
2147 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2153 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2155 sx
+= state
->m_colWidths
[si
];
2156 dc
.DrawLine( sx
, y
, sx
, y2
);
2159 // Horizontal Line, below
2160 // (not if both this and next is category caption)
2161 if ( p
->IsCategory() &&
2162 nextP
&& nextP
->IsCategory() )
2163 dc
.SetPen(m_colCapBack
);
2165 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2167 if ( p
== selected
)
2169 renderFlags
|= wxPGCellRenderer::Selected
;
2170 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2171 wasSelectedPainted
= true;
2179 if ( p
->IsCategory() )
2181 if ( p
->m_fgColIndex
== 0 )
2182 rowFgCol
= m_colCapFore
;
2184 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2185 rowBgBrush
= wxBrush(m_colCapBack
);
2187 else if ( p
!= selected
)
2189 // Disabled may get different colour.
2190 if ( !p
->IsEnabled() )
2191 rowFgCol
= m_colDisPropFore
;
2193 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2195 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2199 // Selected gets different colour.
2200 if ( reallyFocused
)
2202 rowFgCol
= m_colSelFore
;
2203 rowBgBrush
= wxBrush(m_colSelBack
);
2205 else if ( isEnabled
)
2207 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2208 rowBgBrush
= marginBrush
;
2212 rowFgCol
= m_colDisPropFore
;
2213 rowBgBrush
= wxBrush(m_colSelBack
);
2217 bool fontChanged
= false;
2219 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2224 if ( p
->IsCategory() )
2226 // Captions are all cells merged as one
2227 dc
.SetFont(m_captionFont
);
2229 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2231 dc
.SetBrush(rowBgBrush
);
2232 dc
.SetPen(rowBgBrush
.GetColour());
2233 dc
.SetTextForeground(rowFgCol
);
2235 dc
.DrawRectangle(cellRect
);
2238 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2239 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2242 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2243 DrawExpanderButton( dc
, butRect
, p
);
2247 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2249 dc
.SetFont(m_captionFont
);
2255 int nextCellWidth
= state
->m_colWidths
[0];
2256 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2257 int textXAdd
= textMarginHere
- greyDepthX
;
2259 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2261 cellRect
.width
= nextCellWidth
- 1;
2263 bool ctrlCell
= false;
2266 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2268 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2269 dc
.SetBrush(editorBgCol
);
2270 dc
.SetPen(editorBgCol
);
2271 dc
.SetTextForeground(m_colPropFore
);
2273 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2278 dc
.SetBrush(rowBgBrush
);
2279 dc
.SetPen(rowBgBrush
.GetColour());
2280 dc
.SetTextForeground(rowFgCol
);
2283 dc
.DrawRectangle(cellRect
);
2286 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2287 DrawExpanderButton( dc
, butRect
, p
);
2289 dc
.SetClippingRegion(cellRect
);
2291 cellRect
.x
+= textXAdd
;
2292 cellRect
.width
-= textXAdd
;
2297 wxPGCellRenderer
* renderer
;
2298 int cmnVal
= p
->GetCommonValue();
2299 if ( cmnVal
== -1 || ci
!= 1 )
2301 renderer
= p
->GetCellRenderer(ci
);
2302 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2306 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2307 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2311 cellX
+= state
->m_colWidths
[ci
];
2312 if ( ci
< (state
->m_colWidths
.size()-1) )
2313 nextCellWidth
= state
->m_colWidths
[ci
+1];
2315 dc
.DestroyClippingRegion(); // Is this really necessary?
2321 dc
.SetFont(normalfont
);
2326 // Refresh editor controls (seems not needed on msw)
2327 // NOTE: This code is mandatory for GTK!
2328 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2329 if ( wasSelectedPainted
)
2332 m_wndEditor
->Refresh();
2334 m_wndEditor2
->Refresh();
2341 // -----------------------------------------------------------------------
2343 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2347 if ( m_width
< 10 || m_height
< 10 ||
2348 !m_pState
->m_properties
->GetChildCount() ||
2349 p1
== (wxPGProperty
*) NULL
)
2350 return wxRect(0,0,0,0);
2355 // Return rect which encloses the given property range
2357 int visTop
= p1
->GetY();
2360 visBottom
= p2
->GetY() + m_lineHeight
;
2362 visBottom
= m_height
+ visTop
;
2364 // If seleced property is inside the range, we'll extend the range to include
2366 wxPGProperty
* selected
= m_selected
;
2369 int selectedY
= selected
->GetY();
2370 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2372 wxWindow
* editor
= GetEditorControl();
2375 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2376 if ( visBottom2
> visBottom
)
2377 visBottom
= visBottom2
;
2382 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2385 // -----------------------------------------------------------------------
2387 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2392 if ( m_pState
->m_itemsAdded
)
2393 PrepareAfterItemsAdded();
2395 wxRect r
= GetPropertyRect(p1
, p2
);
2398 m_canvas
->RefreshRect(r
);
2402 // -----------------------------------------------------------------------
2404 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2406 if ( p
== m_selected
)
2407 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2409 DrawItemAndChildren(p
);
2412 // -----------------------------------------------------------------------
2414 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2419 // Draw item, children, and parent too, if it is not category
2420 wxPGProperty
* parent
= p
->GetParent();
2423 !parent
->IsCategory() &&
2424 parent
->GetParent() )
2427 parent
= parent
->GetParent();
2430 DrawItemAndChildren(p
);
2433 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2435 wxCHECK_RET( p
, wxT("invalid property id") );
2437 // Do not draw if in non-visible page
2438 if ( p
->GetParentState() != m_pState
)
2441 // do not draw a single item if multiple pending
2442 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2445 wxWindow
* wndPrimary
= GetEditorControl();
2447 // Update child control.
2448 if ( m_selected
&& m_selected
->GetParent() == p
)
2449 m_selected
->UpdateControl(wndPrimary
);
2451 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2453 DrawItems(p
, lastDrawn
);
2456 // -----------------------------------------------------------------------
2458 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2459 const wxRect
*rect
)
2461 PrepareAfterItemsAdded();
2463 wxWindow::Refresh(false);
2465 // TODO: Coordinate translation
2466 m_canvas
->Refresh(false, rect
);
2468 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2469 // I think this really helps only GTK+1.2
2470 if ( m_wndEditor
) m_wndEditor
->Refresh();
2471 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2475 // -----------------------------------------------------------------------
2476 // wxPropertyGrid global operations
2477 // -----------------------------------------------------------------------
2479 void wxPropertyGrid::Clear()
2483 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2484 wxPG_CHECK_RET_DBG( selRes
,
2485 wxT("failed to deselect a property (editor probably had invalid value)") );
2488 m_pState
->DoClear();
2494 RecalculateVirtualSize();
2496 // Need to clear some area at the end
2498 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2501 // -----------------------------------------------------------------------
2503 bool wxPropertyGrid::EnableCategories( bool enable
)
2505 if ( !ClearSelection() )
2511 // Enable categories
2514 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2519 // Disable categories
2521 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2524 if ( !m_pState
->EnableCategories(enable
) )
2529 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2531 m_pState
->m_itemsAdded
= 1; // force
2532 PrepareAfterItemsAdded();
2536 m_pState
->m_itemsAdded
= 1;
2538 // No need for RecalculateVirtualSize() here - it is already called in
2539 // wxPropertyGridPageState method above.
2546 // -----------------------------------------------------------------------
2548 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2550 wxASSERT( pNewState
);
2551 wxASSERT( pNewState
->GetGrid() );
2553 if ( pNewState
== m_pState
)
2556 wxPGProperty
* oldSelection
= m_selected
;
2561 bool selRes
= ClearSelection();
2562 wxPG_CHECK_RET_DBG( selRes
,
2563 wxT("failed to deselect a property (editor probably had invalid value)") );
2566 m_pState
->m_selected
= oldSelection
;
2568 bool orig_mode
= m_pState
->IsInNonCatMode();
2569 bool new_state_mode
= pNewState
->IsInNonCatMode();
2571 m_pState
= pNewState
;
2574 int pgWidth
= GetClientSize().x
;
2575 if ( HasVirtualWidth() )
2577 int minWidth
= pgWidth
;
2578 if ( pNewState
->m_width
< minWidth
)
2580 pNewState
->m_width
= minWidth
;
2581 pNewState
->CheckColumnWidths();
2587 // Just in case, fully re-center splitter
2588 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2589 pNewState
->m_fSplitterX
= -1.0;
2591 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2594 m_propHover
= (wxPGProperty
*) NULL
;
2596 // If necessary, convert state to correct mode.
2597 if ( orig_mode
!= new_state_mode
)
2599 // This should refresh as well.
2600 EnableCategories( orig_mode
?false:true );
2602 else if ( !m_frozen
)
2604 // Refresh, if not frozen.
2605 if ( m_pState
->m_itemsAdded
)
2606 PrepareAfterItemsAdded();
2609 if ( m_pState
->m_selected
)
2610 DoSelectProperty( m_pState
->m_selected
);
2612 RecalculateVirtualSize(0);
2616 m_pState
->m_itemsAdded
= 1;
2619 // -----------------------------------------------------------------------
2621 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2623 wxPG_PROP_ARG_CALL_PROLOG()
2625 m_pState
->SortChildren( p
);
2628 // -----------------------------------------------------------------------
2630 void wxPropertyGrid::Sort()
2632 bool selRes
= ClearSelection(); // This must be before state clear
2633 wxPG_CHECK_RET_DBG( selRes
,
2634 wxT("failed to deselect a property (editor probably had invalid value)") );
2639 // -----------------------------------------------------------------------
2641 // Call to SetSplitterPosition will always disable splitter auto-centering
2642 // if parent window is shown.
2643 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2645 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2648 wxPropertyGridPageState
* state
= m_pState
;
2650 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2655 CorrectEditorWidgetSizeX();
2661 // -----------------------------------------------------------------------
2663 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2665 SetSplitterPosition( m_width
/2, true );
2666 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2667 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2670 // -----------------------------------------------------------------------
2671 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2672 // -----------------------------------------------------------------------
2674 // Returns nearest paint visible property (such that will be painted unless
2675 // window is scrolled or resized). If given property is paint visible, then
2676 // it itself will be returned
2677 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2679 int vx
,vy1
;// Top left corner of client
2680 GetViewStart(&vx
,&vy1
);
2681 vy1
*= wxPG_PIXELS_PER_UNIT
;
2683 int vy2
= vy1
+ m_height
;
2684 int propY
= p
->GetY2(m_lineHeight
);
2686 if ( (propY
+ m_lineHeight
) < vy1
)
2689 return DoGetItemAtY( vy1
);
2691 else if ( propY
> vy2
)
2694 return DoGetItemAtY( vy2
);
2697 // Itself paint visible
2702 // -----------------------------------------------------------------------
2704 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2708 m_pushButKeyCode
= keycode
;
2709 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2710 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2714 m_pushButKeyCode
= WXK_DOWN
;
2715 m_pushButKeyCodeNeedsCtrl
= 0;
2716 m_pushButKeyCodeNeedsAlt
= 1;
2720 // -----------------------------------------------------------------------
2721 // Methods related to change in value, value modification and sending events
2722 // -----------------------------------------------------------------------
2724 // commits any changes in editor of selected property
2725 // return true if validation did not fail
2726 // flags are same as with DoSelectProperty
2727 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2729 // Committing already?
2730 if ( m_inCommitChangesFromEditor
)
2733 // Don't do this if already processing editor event. It might
2734 // induce recursive dialogs and crap like that.
2735 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2737 if ( m_inDoPropertyChanged
)
2744 IsEditorsValueModified() &&
2745 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2748 m_inCommitChangesFromEditor
= 1;
2750 wxVariant
variant(m_selected
->GetValueRef());
2751 bool valueIsPending
= false;
2753 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2754 // due to another window getting focus
2755 wxWindow
* oldFocus
= m_curFocused
;
2757 bool validationFailure
= false;
2758 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2760 m_chgInfo_changedProperty
= NULL
;
2762 // If truly modified, schedule value as pending.
2763 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2765 if ( DoEditorValidate() &&
2766 PerformValidation(m_selected
, variant
) )
2768 valueIsPending
= true;
2772 validationFailure
= true;
2777 EditorsValueWasNotModified();
2782 m_inCommitChangesFromEditor
= 0;
2784 if ( validationFailure
&& !forceSuccess
)
2788 oldFocus
->SetFocus();
2789 m_curFocused
= oldFocus
;
2792 res
= OnValidationFailure(m_selected
, variant
);
2794 // Now prevent further validation failure messages
2797 EditorsValueWasNotModified();
2798 OnValidationFailureReset(m_selected
);
2801 else if ( valueIsPending
)
2803 DoPropertyChanged( m_selected
, flags
);
2804 EditorsValueWasNotModified();
2813 // -----------------------------------------------------------------------
2815 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2818 // Runs all validation functionality.
2819 // Returns true if value passes all tests.
2822 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2824 if ( !wxPGIsVariantType(pendingValue
, list
) )
2826 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2831 // Adapt list to child values, if necessary
2832 wxVariant listValue
= pendingValue
;
2833 wxVariant
* pPendingValue
= &pendingValue
;
2834 wxVariant
* pList
= NULL
;
2836 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2837 // string value, then we need treat as it was changed instead
2838 // (or, in addition, as is the case with composite string parent).
2839 // This includes creating list variant for child values.
2841 wxPGProperty
* pwc
= p
->GetParent();
2842 wxPGProperty
* changedProperty
= p
;
2843 wxPGProperty
* baseChangedProperty
= changedProperty
;
2844 wxVariant bcpPendingList
;
2846 listValue
= pendingValue
;
2847 listValue
.SetName(p
->GetLabel());
2850 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2852 wxVariantList tempList
;
2853 wxVariant
lv(tempList
, pwc
->GetLabel());
2854 lv
.Append(listValue
);
2856 pPendingValue
= &listValue
;
2858 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2860 baseChangedProperty
= pwc
;
2861 bcpPendingList
= lv
;
2864 changedProperty
= pwc
;
2865 pwc
= pwc
->GetParent();
2869 wxPGProperty
* evtChangingProperty
= changedProperty
;
2871 if ( !wxPGIsVariantType(*pPendingValue
, list
) )
2873 value
= *pPendingValue
;
2877 // Convert list to child values
2878 pList
= pPendingValue
;
2879 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2882 wxVariant evtChangingValue
= value
;
2884 // FIXME: After proper ValueToString()s added, remove
2885 // this. It is just a temporary fix, as evt_changing
2886 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2887 // (unless it is selected, and textctrl editor is open).
2888 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2890 evtChangingProperty
= baseChangedProperty
;
2891 if ( evtChangingProperty
!= p
)
2893 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2897 evtChangingValue
= pendingValue
;
2901 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2903 if ( changedProperty
== m_selected
)
2905 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2906 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2910 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2914 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2915 m_chgInfo_changedProperty
= changedProperty
;
2916 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2917 m_chgInfo_pendingValue
= value
;
2920 m_chgInfo_valueList
= *pList
;
2922 m_chgInfo_valueList
.MakeNull();
2924 // If changedProperty is not property which value was edited,
2925 // then call wxPGProperty::ValidateValue() for that as well.
2926 if ( p
!= changedProperty
&& !wxPGIsVariantType(value
, list
) )
2928 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2932 // SendEvent returns true if event was vetoed
2933 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2939 // -----------------------------------------------------------------------
2941 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2943 if ( !msg
.length() )
2947 if ( !wxPGGlobalVars
->m_offline
)
2949 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2952 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2955 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2958 pStatusBar
->SetStatusText(msg
);
2966 ::wxMessageBox(msg
, _T("Property Error"));
2969 // -----------------------------------------------------------------------
2971 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2973 int vfb
= m_validationInfo
.m_failureBehavior
;
2975 if ( vfb
& wxPG_VFB_BEEP
)
2978 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2979 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2981 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2982 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2984 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2986 wxColour vfbFg
= *wxWHITE
;
2987 wxColour vfbBg
= *wxRED
;
2988 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2989 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2991 DrawItemAndChildren(property
);
2993 if ( property
== m_selected
)
2995 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2997 wxWindow
* editor
= GetEditorControl();
3000 editor
->SetForegroundColour(vfbFg
);
3001 editor
->SetBackgroundColour(vfbBg
);
3007 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3009 wxString msg
= m_validationInfo
.m_failureMessage
;
3011 if ( !msg
.length() )
3012 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
3014 DoShowPropertyError(property
, msg
);
3017 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3020 // -----------------------------------------------------------------------
3022 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3024 int vfb
= m_validationInfo
.m_failureBehavior
;
3026 if ( vfb
& wxPG_VFB_MARK_CELL
)
3028 property
->SetCell(0, NULL
);
3029 property
->SetCell(1, NULL
);
3031 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3033 if ( property
== m_selected
&& GetEditorControl() )
3035 // Calling this will recreate the control, thus resetting its colour
3036 RefreshProperty(property
);
3040 DrawItemAndChildren(property
);
3045 // -----------------------------------------------------------------------
3047 // flags are same as with DoSelectProperty
3048 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3050 if ( m_inDoPropertyChanged
)
3053 m_pState
->m_anyModified
= 1;
3055 m_inDoPropertyChanged
= 1;
3057 // Maybe need to update control
3058 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3060 // These values were calculated in PerformValidation()
3061 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3062 wxVariant value
= m_chgInfo_pendingValue
;
3064 wxPGProperty
* topPaintedProperty
= changedProperty
;
3066 while ( !topPaintedProperty
->IsCategory() &&
3067 !topPaintedProperty
->IsRoot() )
3069 topPaintedProperty
= topPaintedProperty
->GetParent();
3072 changedProperty
->SetValue(value
, &m_chgInfo_valueList
);
3074 // Set as Modified (not if dragging just began)
3075 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3077 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3078 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3081 SetCurControlBoldFont();
3087 // Propagate updates to parent(s)
3089 wxPGProperty
* prevPwc
= NULL
;
3091 while ( prevPwc
!= topPaintedProperty
)
3093 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3095 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3098 SetCurControlBoldFont();
3102 pwc
= pwc
->GetParent();
3105 // Draw the actual property
3106 DrawItemAndChildren( topPaintedProperty
);
3109 // If value was set by wxPGProperty::OnEvent, then update the editor
3111 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3114 p
->GetEditorClass()->UpdateControl(p
, m_wndEditor
);
3118 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3119 if ( m_wndEditor
) m_wndEditor
->Refresh();
3120 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3125 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3127 // If top parent has composite string value, then send to child parents,
3128 // starting from baseChangedProperty.
3129 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3131 pwc
= m_chgInfo_baseChangedProperty
;
3133 while ( pwc
!= changedProperty
)
3135 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3136 pwc
= pwc
->GetParent();
3140 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3142 m_inDoPropertyChanged
= 0;
3147 // -----------------------------------------------------------------------
3149 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3151 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3153 m_chgInfo_changedProperty
= NULL
;
3155 if ( PerformValidation(p
, newValue
) )
3157 DoPropertyChanged(p
);
3162 OnValidationFailure(p
, newValue
);
3168 // -----------------------------------------------------------------------
3170 // Runs wxValidator for the selected property
3171 bool wxPropertyGrid::DoEditorValidate()
3173 #if wxUSE_VALIDATORS
3174 // With traditional validator style, we dont need to more
3175 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3178 if ( m_iFlags
& wxPG_FL_VALIDATION_FAILED
)
3183 wxWindow
* wnd
= GetEditorControl();
3185 wxValidator
* validator
= m_selected
->GetValidator();
3186 if ( validator
&& wnd
)
3188 // Use TextCtrl of ODComboBox instead
3189 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3191 wnd
= ((wxOwnerDrawnComboBox
*)wnd
)->GetTextCtrl();
3197 validator
->SetWindow(wnd
);
3199 // Instead setting the flag after the failure, we set
3200 // it before checking and then clear afterwards if things
3201 // went fine. This trick is necessary since focus events
3202 // may be triggered while in Validate.
3203 m_iFlags
|= wxPG_FL_VALIDATION_FAILED
;
3204 if ( !validator
->Validate(this) )
3206 // If you dpm't want to display message multiple times per change,
3207 // comment the following line.
3208 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3211 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3217 // -----------------------------------------------------------------------
3219 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3221 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3222 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3224 wxWindow
* parent
= wnd
->GetParent();
3227 (parent
== m_canvas
||
3228 parent
->GetParent() == m_canvas
) )
3230 OnCustomEditorEvent((wxCommandEvent
&)event
);
3234 return wxPanel::ProcessEvent(event
);
3237 // -----------------------------------------------------------------------
3239 // NB: It may really not be wxCommandEvent - must check if necessary
3241 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3243 wxPGProperty
* selected
= m_selected
;
3246 // Somehow, event is handled after property has been deselected.
3247 // Possibly, but very rare.
3251 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3254 wxVariant
pendingValue(selected
->GetValueRef());
3255 wxWindow
* wnd
= GetEditorControl();
3257 bool wasUnspecified
= selected
->IsValueUnspecified();
3258 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3260 bool valueIsPending
= false;
3262 m_chgInfo_changedProperty
= NULL
;
3264 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3267 // Filter out excess wxTextCtrl modified events
3268 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3270 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3272 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3274 wxString newTcValue
= tc
->GetValue();
3275 if ( m_prevTcValue
== newTcValue
)
3278 m_prevTcValue
= newTcValue
;
3281 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3283 bool validationFailure
= false;
3284 bool buttonWasHandled
= false;
3287 // Try common button handling
3288 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3290 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3294 buttonWasHandled
= true;
3295 // Store as res2, as previously (and still currently alternatively)
3296 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3297 // in wxPGProperty::OnEvent().
3298 adapter
->ShowDialog( this, selected
);
3303 if ( !buttonWasHandled
)
3305 // First call editor class' event handler.
3306 const wxPGEditor
* editor
= selected
->GetEditorClass();
3308 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3310 // If changes, validate them
3311 if ( DoEditorValidate() )
3313 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3314 valueIsPending
= true;
3318 validationFailure
= true;
3322 // Then the property's custom handler (must be always called, unless
3323 // validation failed).
3324 if ( !validationFailure
)
3325 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3328 // SetValueInEvent(), as called in one of the functions referred above
3329 // overrides editor's value.
3330 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3332 valueIsPending
= true;
3333 pendingValue
= m_changeInEventValue
;
3334 selFlags
|= wxPG_SEL_DIALOGVAL
;
3337 if ( !validationFailure
&& valueIsPending
)
3338 if ( !PerformValidation(m_selected
, pendingValue
) )
3339 validationFailure
= true;
3341 if ( validationFailure
)
3343 OnValidationFailure(selected
, pendingValue
);
3345 else if ( valueIsPending
)
3347 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3349 DoPropertyChanged(selected
, selFlags
);
3350 EditorsValueWasNotModified();
3354 // No value after all
3356 // Let unhandled button click events go to the parent
3357 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3359 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3360 GetEventHandler()->AddPendingEvent(evt
);
3364 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3367 // -----------------------------------------------------------------------
3368 // wxPropertyGrid editor control helper methods
3369 // -----------------------------------------------------------------------
3371 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3373 int itemy
= p
->GetY2(m_lineHeight
);
3375 int cust_img_space
= 0;
3376 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3377 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3379 // TODO: If custom image detection changes from current, change this.
3380 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3382 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3383 int imwid
= p
->OnMeasureImage().x
;
3384 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3385 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3390 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3392 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3397 // -----------------------------------------------------------------------
3399 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3401 wxSize sz
= GetImageSize(p
, item
);
3402 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3403 wxPG_CUSTOM_IMAGE_SPACINGY
,
3408 // return size of custom paint image
3409 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3411 // If called with NULL property, then return default image
3412 // size for properties that use image.
3414 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3416 wxSize cis
= p
->OnMeasureImage(item
);
3418 int choiceCount
= p
->GetChoiceCount();
3419 int comVals
= p
->GetDisplayedCommonValueCount();
3420 if ( item
>= choiceCount
&& comVals
> 0 )
3422 unsigned int cvi
= item
-choiceCount
;
3423 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3425 else if ( item
>= 0 && choiceCount
== 0 )
3426 return wxSize(0, 0);
3431 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3436 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3443 // -----------------------------------------------------------------------
3445 // takes scrolling into account
3446 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3449 GetViewStart(&vx
,&vy
);
3450 vy
*=wxPG_PIXELS_PER_UNIT
;
3451 vx
*=wxPG_PIXELS_PER_UNIT
;
3454 ClientToScreen( px
, py
);
3457 // -----------------------------------------------------------------------
3459 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3462 GetViewStart(&pt2
.x
,&pt2
.y
);
3463 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3464 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3468 return m_pState
->HitTest(pt2
);
3471 // -----------------------------------------------------------------------
3473 // custom set cursor
3474 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3476 if ( type
== m_curcursor
&& !override
) return;
3478 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3480 if ( type
== wxCURSOR_SIZEWE
)
3481 cursor
= m_cursorSizeWE
;
3483 m_canvas
->SetCursor( *cursor
);
3488 // -----------------------------------------------------------------------
3489 // wxPropertyGrid property selection
3490 // -----------------------------------------------------------------------
3492 #define CONNECT_CHILD(EVT,FUNCTYPE,FUNC) \
3493 wnd->Connect(id, EVT, \
3494 (wxObjectEventFunction) (wxEventFunction) \
3495 FUNCTYPE (&wxPropertyGrid::FUNC), \
3498 // Setups event handling for child control
3499 void wxPropertyGrid::SetupEventHandling( wxWindow
* argWnd
, int id
)
3501 wxWindow
* wnd
= argWnd
;
3503 if ( argWnd
== m_wndEditor
)
3505 CONNECT_CHILD(wxEVT_MOTION
,(wxMouseEventFunction
),OnMouseMoveChild
)
3506 CONNECT_CHILD(wxEVT_LEFT_UP
,(wxMouseEventFunction
),OnMouseUpChild
)
3507 CONNECT_CHILD(wxEVT_LEFT_DOWN
,(wxMouseEventFunction
),OnMouseClickChild
)
3508 CONNECT_CHILD(wxEVT_RIGHT_UP
,(wxMouseEventFunction
),OnMouseRightClickChild
)
3509 CONNECT_CHILD(wxEVT_ENTER_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3510 CONNECT_CHILD(wxEVT_LEAVE_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3514 CONNECT_CHILD(wxEVT_NAVIGATION_KEY
,(wxNavigationKeyEventFunction
),OnNavigationKey
)
3516 CONNECT_CHILD(wxEVT_KEY_DOWN
,(wxCharEventFunction
),OnChildKeyDown
)
3517 CONNECT_CHILD(wxEVT_KEY_UP
,(wxCharEventFunction
),OnChildKeyUp
)
3518 CONNECT_CHILD(wxEVT_KILL_FOCUS
,(wxFocusEventFunction
),OnFocusEvent
)
3521 void wxPropertyGrid::FreeEditors()
3523 // Do not free editors immediately if processing events
3524 if ( !m_windowsToDelete
)
3525 m_windowsToDelete
= new wxArrayPtrVoid
;
3529 m_windowsToDelete
->push_back(m_wndEditor2
);
3530 m_wndEditor2
->Hide();
3531 m_wndEditor2
= (wxWindow
*) NULL
;
3536 m_windowsToDelete
->push_back(m_wndEditor
);
3537 m_wndEditor
->Hide();
3538 m_wndEditor
= (wxWindow
*) NULL
;
3542 // Call with NULL to de-select property
3543 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3547 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3548 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3550 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3553 if ( m_inDoSelectProperty
)
3556 m_inDoSelectProperty
= 1;
3558 wxPGProperty
* prev
= m_selected
;
3561 // Delete windows pending for deletion
3562 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3566 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3567 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3569 m_windowsToDelete
->clear();
3574 m_inDoSelectProperty
= 0;
3579 // If we are frozen, then just set the values.
3582 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3583 m_editorFocused
= 0;
3586 m_pState
->m_selected
= p
;
3588 // If frozen, always free controls. But don't worry, as Thaw will
3589 // recall SelectProperty to recreate them.
3592 // Prevent any further selection measures in this call
3593 p
= (wxPGProperty
*) NULL
;
3598 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3600 // Only set focus if not deselecting
3603 if ( flags
& wxPG_SEL_FOCUS
)
3607 m_wndEditor
->SetFocus();
3608 m_editorFocused
= 1;
3613 wxScrolledWindow::SetFocus();
3614 m_editorFocused
= 0;
3618 m_inDoSelectProperty
= 0;
3623 // First, deactivate previous
3627 OnValidationFailureReset(m_selected
);
3629 // Must double-check if this is an selected in case of forceswitch
3632 if ( !CommitChangesFromEditor(flags
) )
3634 // Validation has failed, so we can't exit the previous editor
3635 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3636 // _("Invalid Value"),wxOK|wxICON_ERROR);
3637 m_inDoSelectProperty
= 0;
3645 m_selected
= (wxPGProperty
*) NULL
;
3646 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3648 // We need to always fully refresh the grid here
3651 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3652 EditorsValueWasNotModified();
3655 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3658 // Then, activate the one given.
3661 int propY
= p
->GetY2(m_lineHeight
);
3663 int splitterX
= GetSplitterPosition();
3664 m_editorFocused
= 0;
3666 m_pState
->m_selected
= p
;
3667 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3669 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3671 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3673 // Do we need OnMeasureCalls?
3674 wxSize imsz
= p
->OnMeasureImage();
3677 // Only create editor for non-disabled non-caption
3678 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3680 // do this for non-caption items
3684 // Do we need to paint the custom image, if any?
3685 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3686 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3687 !p
->GetEditorClass()->CanContainCustomImage()
3689 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3691 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3692 wxPoint goodPos
= grect
.GetPosition();
3693 #if wxPG_CREATE_CONTROLS_HIDDEN
3694 int coord_adjust
= m_height
- goodPos
.y
;
3695 goodPos
.y
+= coord_adjust
;
3698 const wxPGEditor
* editor
= p
->GetEditorClass();
3699 wxCHECK_MSG(editor
, false,
3700 wxT("NULL editor class not allowed"));
3702 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3704 wxPGWindowList wndList
= editor
->CreateControls(this,
3709 m_wndEditor
= wndList
.m_primary
;
3710 m_wndEditor2
= wndList
.m_secondary
;
3712 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3713 // value is drawn as normal, and m_wndEditor2 is assumed
3714 // to be a right-aligned button that triggers a separate editor
3719 wxASSERT_MSG( m_wndEditor
->GetParent() == m_canvas
,
3720 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3722 // Set validator, if any
3723 #if wxUSE_VALIDATORS
3724 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3726 wxValidator
* validator
= p
->GetValidator();
3728 m_wndEditor
->SetValidator(*validator
);
3732 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3733 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3735 // If it has modified status, use bold font
3736 // (must be done before capturing m_ctrlXAdjust)
3737 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3738 SetCurControlBoldFont();
3741 // Fix TextCtrl indentation
3742 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3743 wxTextCtrl
* tc
= NULL
;
3744 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3745 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3747 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3749 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3752 // Store x relative to splitter (we'll need it).
3753 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3755 // Check if background clear is not necessary
3756 wxPoint pos
= m_wndEditor
->GetPosition();
3757 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3759 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3762 m_wndEditor
->SetSizeHints(3, 3);
3764 #if wxPG_CREATE_CONTROLS_HIDDEN
3765 m_wndEditor
->Show(false);
3766 m_wndEditor
->Freeze();
3768 goodPos
= m_wndEditor
->GetPosition();
3769 goodPos
.y
-= coord_adjust
;
3770 m_wndEditor
->Move( goodPos
);
3773 wxWindow
* primaryCtrl
= GetEditorControl();
3774 SetupEventHandling(primaryCtrl
, wxPG_SUBID1
);
3776 // Focus and select all (wxTextCtrl, wxComboBox etc)
3777 if ( flags
& wxPG_SEL_FOCUS
)
3779 primaryCtrl
->SetFocus();
3781 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3787 wxASSERT_MSG( m_wndEditor2
->GetParent() == m_canvas
,
3788 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3790 // Get proper id for wndSecondary
3791 m_wndSecId
= m_wndEditor2
->GetId();
3792 wxWindowList children
= m_wndEditor2
->GetChildren();
3793 wxWindowList::iterator node
= children
.begin();
3794 if ( node
!= children
.end() )
3795 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3797 m_wndEditor2
->SetSizeHints(3,3);
3799 #if wxPG_CREATE_CONTROLS_HIDDEN
3800 wxRect sec_rect
= m_wndEditor2
->GetRect();
3801 sec_rect
.y
-= coord_adjust
;
3803 // Fine tuning required to fix "oversized"
3804 // button disappearance bug.
3805 if ( sec_rect
.y
< 0 )
3807 sec_rect
.height
+= sec_rect
.y
;
3810 m_wndEditor2
->SetSize( sec_rect
);
3812 m_wndEditor2
->Show();
3814 SetupEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3816 // If no primary editor, focus to button to allow
3817 // it to interprete ENTER etc.
3818 // NOTE: Due to problems focusing away from it, this
3819 // has been disabled.
3821 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3822 m_wndEditor2->SetFocus();
3826 if ( flags
& wxPG_SEL_FOCUS
)
3827 m_editorFocused
= 1;
3832 // wxGTK atleast seems to need this (wxMSW not)
3836 EditorsValueWasNotModified();
3838 // If it's inside collapsed section, expand parent, scroll, etc.
3839 // Also, if it was partially visible, scroll it into view.
3840 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3845 #if wxPG_CREATE_CONTROLS_HIDDEN
3846 m_wndEditor
->Thaw();
3848 m_wndEditor
->Show(true);
3854 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3860 // Show help text in status bar.
3861 // (if found and grid not embedded in manager with help box and
3862 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3865 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3867 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3868 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3870 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3872 statusbar
= frame
->GetStatusBar();
3877 const wxString
* pHelpString
= (const wxString
*) NULL
;
3881 pHelpString
= &p
->GetHelpString();
3882 if ( pHelpString
->length() )
3884 // Set help box text.
3885 statusbar
->SetStatusText( *pHelpString
);
3886 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3890 if ( (!pHelpString
|| !pHelpString
->length()) &&
3891 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3893 // Clear help box - but only if it was written
3894 // by us at previous time.
3895 statusbar
->SetStatusText( m_emptyString
);
3896 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3902 m_inDoSelectProperty
= 0;
3904 // call wx event handler (here so that it also occurs on deselection)
3905 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3910 // -----------------------------------------------------------------------
3912 bool wxPropertyGrid::UnfocusEditor()
3914 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3917 if ( !CommitChangesFromEditor(0) )
3920 m_canvas
->SetFocusIgnoringChildren();
3921 DrawItem(m_selected
);
3926 // -----------------------------------------------------------------------
3928 // This method is not inline because it called dozens of times
3929 // (i.e. two-arg function calls create smaller code size).
3930 bool wxPropertyGrid::DoClearSelection()
3932 return DoSelectProperty((wxPGProperty
*)NULL
);
3935 // -----------------------------------------------------------------------
3936 // wxPropertyGrid expand/collapse state
3937 // -----------------------------------------------------------------------
3939 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3941 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3943 // If active editor was inside collapsed section, then disable it
3944 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3946 if ( !ClearSelection() )
3950 // Store dont-center-splitter flag 'cause we need to temporarily set it
3951 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3952 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3954 bool res
= m_pState
->DoCollapse(pwc
);
3959 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3961 RecalculateVirtualSize();
3963 // Redraw etc. only if collapsed was visible.
3964 if (pwc
->IsVisible() &&
3966 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3968 // When item is collapsed so that scrollbar would move,
3969 // graphics mess is about (unless we redraw everything).
3974 // Clear dont-center-splitter flag if it wasn't set
3975 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3980 // -----------------------------------------------------------------------
3982 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3984 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3986 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3988 // Store dont-center-splitter flag 'cause we need to temporarily set it
3989 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3990 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3992 bool res
= m_pState
->DoExpand(pwc
);
3997 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3999 RecalculateVirtualSize();
4001 // Redraw etc. only if expanded was visible.
4002 if ( pwc
->IsVisible() && !m_frozen
&&
4003 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
4007 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4010 DrawItems(pwc
, NULL
);
4015 // Clear dont-center-splitter flag if it wasn't set
4016 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4021 // -----------------------------------------------------------------------
4023 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4026 return m_pState
->DoHideProperty(p
, hide
, flags
);
4029 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
4032 if ( !ClearSelection() )
4036 m_pState
->DoHideProperty(p
, hide
, flags
);
4038 RecalculateVirtualSize();
4045 // -----------------------------------------------------------------------
4046 // wxPropertyGrid size related methods
4047 // -----------------------------------------------------------------------
4049 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4051 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4055 // If virtual height was changed, then recalculate editor control position(s)
4056 if ( m_pState
->m_vhCalcPending
)
4057 CorrectEditorWidgetPosY();
4059 m_pState
->EnsureVirtualHeight();
4062 int by1
= m_pState
->GetVirtualHeight();
4063 int by2
= m_pState
->GetActualVirtualHeight();
4066 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4067 wxASSERT_MSG( false,
4073 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4075 int x
= m_pState
->m_width
;
4076 int y
= m_pState
->m_virtualHeight
;
4079 GetClientSize(&width
,&height
);
4081 // Now adjust virtual size.
4082 SetVirtualSize(x
, y
);
4088 // Adjust scrollbars
4089 if ( HasVirtualWidth() )
4091 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4092 xPos
= GetScrollPos( wxHORIZONTAL
);
4095 if ( forceXPos
!= -1 )
4098 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4101 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4102 int yPos
= GetScrollPos( wxVERTICAL
);
4104 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4105 xAmount
, yAmount
, xPos
, yPos
, true );
4107 // Must re-get size now
4108 GetClientSize(&width
,&height
);
4110 if ( !HasVirtualWidth() )
4112 m_pState
->SetVirtualWidth(width
);
4119 m_canvas
->SetSize( x
, y
);
4121 m_pState
->CheckColumnWidths();
4124 CorrectEditorWidgetSizeX();
4126 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4129 // -----------------------------------------------------------------------
4131 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4133 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4137 GetClientSize(&width
,&height
);
4142 m_visPropArray
.SetCount((height
/m_lineHeight
)+10);
4144 #if wxPG_DOUBLE_BUFFER
4145 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4147 int dblh
= (m_lineHeight
*2);
4148 if ( !m_doubleBuffer
)
4150 // Create double buffer bitmap to draw on, if none
4151 int w
= (width
>250)?width
:250;
4152 int h
= height
+ dblh
;
4154 m_doubleBuffer
= new wxBitmap( w
, h
);
4158 int w
= m_doubleBuffer
->GetWidth();
4159 int h
= m_doubleBuffer
->GetHeight();
4161 // Double buffer must be large enough
4162 if ( w
< width
|| h
< (height
+dblh
) )
4164 if ( w
< width
) w
= width
;
4165 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4166 delete m_doubleBuffer
;
4167 m_doubleBuffer
= new wxBitmap( w
, h
);
4174 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4175 m_ncWidth
= event
.GetSize().x
;
4179 if ( m_pState
->m_itemsAdded
)
4180 PrepareAfterItemsAdded();
4182 // Without this, virtual size (atleast under wxGTK) will be skewed
4183 RecalculateVirtualSize();
4189 // -----------------------------------------------------------------------
4191 void wxPropertyGrid::SetVirtualWidth( int width
)
4195 // Disable virtual width
4196 width
= GetClientSize().x
;
4197 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4201 // Enable virtual width
4202 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4204 m_pState
->SetVirtualWidth( width
);
4207 // -----------------------------------------------------------------------
4208 // wxPropertyGrid mouse event handling
4209 // -----------------------------------------------------------------------
4211 // selFlags uses same values DoSelectProperty's flags
4212 // Returns true if event was vetoed.
4213 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4215 // Send property grid event of specific type and with specific property
4216 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4217 evt
.SetPropertyGrid(this);
4218 evt
.SetEventObject(m_eventObject
);
4222 evt
.SetCanVeto(true);
4223 evt
.SetupValidationInfo();
4224 m_validationInfo
.m_pValue
= pValue
;
4226 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4228 evtHandler
->ProcessEvent(evt
);
4230 return evt
.WasVetoed();
4233 // -----------------------------------------------------------------------
4235 // Return false if should be skipped
4236 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4240 // Need to set focus?
4241 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4243 m_canvas
->SetFocus();
4246 wxPropertyGridPageState
* state
= m_pState
;
4248 int splitterHitOffset
;
4249 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4251 wxPGProperty
* p
= DoGetItemAtY(y
);
4255 int depth
= (int)p
->GetDepth() - 1;
4257 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4259 if ( x
>= marginEnds
)
4263 if ( p
->IsCategory() )
4265 // This is category.
4266 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4268 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4270 // Expand, collapse, activate etc. if click on text or left of splitter.
4273 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4278 if ( !DoSelectProperty( p
) )
4281 // On double-click, expand/collapse.
4282 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4284 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4285 else DoExpand( p
, true );
4289 else if ( splitterHit
== -1 )
4292 unsigned int selFlag
= 0;
4293 if ( columnHit
== 1 )
4295 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4296 selFlag
= wxPG_SEL_FOCUS
;
4298 if ( !DoSelectProperty( p
, selFlag
) )
4301 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4303 if ( p
->GetChildCount() && !p
->IsCategory() )
4304 // On double-click, expand/collapse.
4305 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4307 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4308 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4309 else DoExpand( p
, true );
4316 // click on splitter
4317 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4319 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4321 // Double-clicking the splitter causes auto-centering
4322 CenterSplitter( true );
4324 else if ( m_dragStatus
== 0 )
4327 // Begin draggin the splitter
4331 // Changes must be committed here or the
4332 // value won't be drawn correctly
4333 if ( !CommitChangesFromEditor() )
4336 m_wndEditor
->Show ( false );
4339 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4341 m_canvas
->CaptureMouse();
4342 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4346 m_draggedSplitter
= splitterHit
;
4347 m_dragOffset
= splitterHitOffset
;
4349 wxClientDC
dc(m_canvas
);
4351 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4352 // Fixes button disappearance bug
4354 m_wndEditor2
->Show ( false );
4357 m_startingSplitterX
= x
- splitterHitOffset
;
4365 if ( p
->GetChildCount() )
4367 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4369 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4371 int y2
= y
% m_lineHeight
;
4372 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4374 // On click on expander button, expand/collapse
4375 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4376 DoCollapse( p
, true );
4378 DoExpand( p
, true );
4387 // -----------------------------------------------------------------------
4389 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4390 wxMouseEvent
& WXUNUSED(event
) )
4394 // Select property here as well
4395 wxPGProperty
* p
= m_propHover
;
4396 if ( p
!= m_selected
)
4397 DoSelectProperty( p
);
4399 // Send right click event.
4400 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4407 // -----------------------------------------------------------------------
4409 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4410 wxMouseEvent
& WXUNUSED(event
) )
4414 // Select property here as well
4415 wxPGProperty
* p
= m_propHover
;
4417 if ( p
!= m_selected
)
4418 DoSelectProperty( p
);
4420 // Send double-click event.
4421 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4428 // -----------------------------------------------------------------------
4430 #if wxPG_SUPPORT_TOOLTIPS
4432 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4434 if ( tipString
.length() )
4436 m_canvas
->SetToolTip(tipString
);
4440 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4441 m_canvas
->SetToolTip( m_emptyString
);
4443 m_canvas
->SetToolTip( NULL
);
4448 #endif // #if wxPG_SUPPORT_TOOLTIPS
4450 // -----------------------------------------------------------------------
4452 // Return false if should be skipped
4453 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4455 // Safety check (needed because mouse capturing may
4456 // otherwise freeze the control)
4457 if ( m_dragStatus
> 0 && !event
.Dragging() )
4459 HandleMouseUp(x
,y
,event
);
4462 wxPropertyGridPageState
* state
= m_pState
;
4464 int splitterHitOffset
;
4465 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4466 int splitterX
= x
- splitterHitOffset
;
4468 if ( m_dragStatus
> 0 )
4470 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4471 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4474 int newSplitterX
= x
- m_dragOffset
;
4475 int splitterX
= x
- splitterHitOffset
;
4477 // Splitter redraw required?
4478 if ( newSplitterX
!= splitterX
)
4481 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4482 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4483 state
->m_fSplitterX
= (float) newSplitterX
;
4486 CorrectEditorWidgetSizeX();
4500 int ih
= m_lineHeight
;
4503 #if wxPG_SUPPORT_TOOLTIPS
4504 wxPGProperty
* prevHover
= m_propHover
;
4505 unsigned char prevSide
= m_mouseSide
;
4507 int curPropHoverY
= y
- (y
% ih
);
4509 // On which item it hovers
4510 if ( ( !m_propHover
)
4512 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4515 // Mouse moves on another property
4517 m_propHover
= DoGetItemAtY(y
);
4518 m_propHoverY
= curPropHoverY
;
4521 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4524 #if wxPG_SUPPORT_TOOLTIPS
4525 // Store which side we are on
4527 if ( columnHit
== 1 )
4529 else if ( columnHit
== 0 )
4533 // If tooltips are enabled, show label or value as a tip
4534 // in case it doesn't otherwise show in full length.
4536 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4538 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4540 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4542 if ( m_propHover
&& !m_propHover
->IsCategory() )
4545 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4547 // Show help string as a tooltip
4548 wxString tipString
= m_propHover
->GetHelpString();
4550 SetToolTip(tipString
);
4554 // Show cropped value string as a tooltip
4558 if ( m_mouseSide
== 1 )
4560 tipString
= m_propHover
->m_label
;
4561 space
= splitterX
-m_marginWidth
-3;
4563 else if ( m_mouseSide
== 2 )
4565 tipString
= m_propHover
->GetDisplayedString();
4567 space
= m_width
- splitterX
;
4568 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4569 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4575 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4578 SetToolTip( tipString
);
4585 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4586 m_canvas
->SetToolTip( m_emptyString
);
4588 m_canvas
->SetToolTip( NULL
);
4599 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4600 m_canvas
->SetToolTip( m_emptyString
);
4602 m_canvas
->SetToolTip( NULL
);
4610 if ( splitterHit
== -1 ||
4612 HasFlag(wxPG_STATIC_SPLITTER
) )
4614 // hovering on something else
4615 if ( m_curcursor
!= wxCURSOR_ARROW
)
4616 CustomSetCursor( wxCURSOR_ARROW
);
4620 // Do not allow splitter cursor on caption items.
4621 // (also not if we were dragging and its started
4622 // outside the splitter region)
4625 !m_propHover
->IsCategory() &&
4629 // hovering on splitter
4631 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4632 // reliably detected.
4633 //if ( m_curcursor != wxCURSOR_SIZEWE )
4634 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4640 // hovering on something else
4641 if ( m_curcursor
!= wxCURSOR_ARROW
)
4642 CustomSetCursor( wxCURSOR_ARROW
);
4649 // -----------------------------------------------------------------------
4651 // Also handles Leaving event
4652 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4653 wxMouseEvent
&WXUNUSED(event
) )
4655 wxPropertyGridPageState
* state
= m_pState
;
4659 int splitterHitOffset
;
4660 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4662 // No event type check - basicly calling this method should
4663 // just stop dragging.
4664 // Left up after dragged?
4665 if ( m_dragStatus
>= 1 )
4668 // End Splitter Dragging
4670 // DO NOT ENABLE FOLLOWING LINE!
4671 // (it is only here as a reminder to not to do it)
4674 // Disable splitter auto-centering
4675 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4677 // This is necessary to return cursor
4678 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4680 m_canvas
->ReleaseMouse();
4681 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4684 // Set back the default cursor, if necessary
4685 if ( splitterHit
== -1 ||
4688 CustomSetCursor( wxCURSOR_ARROW
);
4693 // Control background needs to be cleared
4694 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4695 DrawItem( m_selected
);
4699 m_wndEditor
->Show ( true );
4702 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4703 // Fixes button disappearance bug
4705 m_wndEditor2
->Show ( true );
4708 // This clears the focus.
4709 m_editorFocused
= 0;
4715 // -----------------------------------------------------------------------
4717 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4719 int splitterX
= GetSplitterPosition();
4722 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4726 wxWindow
* wnd
= m_wndEditor
;
4728 // Hide popup on clicks
4729 if ( event
.GetEventType() != wxEVT_MOTION
)
4730 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4732 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4738 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4740 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4741 ux
>= (r
.x
+r
.width
) ||
4743 event
.m_y
>= (r
.y
+r
.height
)
4753 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4758 // -----------------------------------------------------------------------
4760 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4763 if ( OnMouseCommon( event
, &x
, &y
) )
4765 HandleMouseClick(x
,y
,event
);
4770 // -----------------------------------------------------------------------
4772 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4775 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4776 HandleMouseRightClick(x
,y
,event
);
4780 // -----------------------------------------------------------------------
4782 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4784 // Always run standard mouse-down handler as well
4785 OnMouseClick(event
);
4788 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4789 HandleMouseDoubleClick(x
,y
,event
);
4793 // -----------------------------------------------------------------------
4795 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4798 if ( OnMouseCommon( event
, &x
, &y
) )
4800 HandleMouseMove(x
,y
,event
);
4805 // -----------------------------------------------------------------------
4807 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4809 // Called when mouse moves in the empty space below the properties.
4810 CustomSetCursor( wxCURSOR_ARROW
);
4813 // -----------------------------------------------------------------------
4815 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4818 if ( OnMouseCommon( event
, &x
, &y
) )
4820 HandleMouseUp(x
,y
,event
);
4825 // -----------------------------------------------------------------------
4827 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4829 // This may get called from child control as well, so event's
4830 // mouse position cannot be relied on.
4832 if ( event
.Entering() )
4834 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4836 // TODO: Fix this (detect parent and only do
4837 // cursor trick if it is a manager).
4838 wxASSERT( GetParent() );
4839 GetParent()->SetCursor(wxNullCursor
);
4841 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4844 GetParent()->SetCursor(wxNullCursor
);
4846 else if ( event
.Leaving() )
4848 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4849 m_canvas
->SetCursor( wxNullCursor
);
4851 // Get real cursor position
4852 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4854 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4857 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4859 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4863 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4871 // -----------------------------------------------------------------------
4873 // Common code used by various OnMouseXXXChild methods.
4874 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4876 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4877 wxASSERT( topCtrlWnd
);
4879 event
.GetPosition(&x
,&y
);
4881 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4883 int splitterX
= GetSplitterPosition();
4885 wxRect r
= topCtrlWnd
->GetRect();
4886 if ( !m_dragStatus
&&
4887 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4888 y
>= 0 && y
< r
.height \
4891 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4896 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4903 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4906 if ( OnMouseChildCommon(event
,&x
,&y
) )
4908 bool res
= HandleMouseClick(x
,y
,event
);
4909 if ( !res
) event
.Skip();
4913 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4916 wxASSERT( m_wndEditor
);
4917 // These coords may not be exact (about +-2),
4918 // but that should not matter (right click is about item, not position).
4919 wxPoint pt
= m_wndEditor
->GetPosition();
4920 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4921 wxASSERT( m_selected
);
4922 m_propHover
= m_selected
;
4923 bool res
= HandleMouseRightClick(x
,y
,event
);
4924 if ( !res
) event
.Skip();
4927 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4930 if ( OnMouseChildCommon(event
,&x
,&y
) )
4932 bool res
= HandleMouseMove(x
,y
,event
);
4933 if ( !res
) event
.Skip();
4937 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4940 if ( OnMouseChildCommon(event
,&x
,&y
) )
4942 bool res
= HandleMouseUp(x
,y
,event
);
4943 if ( !res
) event
.Skip();
4947 // -----------------------------------------------------------------------
4948 // wxPropertyGrid keyboard event handling
4949 // -----------------------------------------------------------------------
4951 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4953 wxNavigationKeyEvent evt
;
4954 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4955 (dir
?wxNavigationKeyEvent::IsForward
:
4956 wxNavigationKeyEvent::IsBackward
));
4957 evt
.SetEventObject(this);
4958 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4962 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4964 // Translates wxKeyEvent to wxPG_ACTION_XXX
4966 int keycode
= event
.GetKeyCode();
4967 int modifiers
= event
.GetModifiers();
4969 wxASSERT( !(modifiers
&~(0xFFFF)) );
4971 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4973 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4975 if ( it
== m_actionTriggers
.end() )
4980 int second
= (it
->second
>>16) & 0xFFFF;
4984 return (it
->second
& 0xFFFF);
4987 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4989 wxASSERT( !(modifiers
&~(0xFFFF)) );
4991 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4993 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4995 if ( it
!= m_actionTriggers
.end() )
4997 // This key combination is already used
4999 // Can add secondary?
5000 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5001 wxT("You can only add up to two separate actions per key combination.") );
5003 action
= it
->second
| (action
<<16);
5006 m_actionTriggers
[hashMapKey
] = action
;
5009 void wxPropertyGrid::ClearActionTriggers( int action
)
5011 wxPGHashMapI2I::iterator it
;
5013 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
5015 if ( it
->second
== action
)
5017 m_actionTriggers
.erase(it
);
5022 static void CopyTextToClipboard( const wxString
& text
)
5024 if ( wxTheClipboard
->Open() )
5026 // This data objects are held by the clipboard,
5027 // so do not delete them in the app.
5028 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
5029 wxTheClipboard
->Close();
5033 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5036 // Handles key event when editor control is not focused.
5039 wxASSERT( !m_frozen
);
5043 // Travelsal between items, collapsing/expanding, etc.
5044 int keycode
= event
.GetKeyCode();
5046 if ( keycode
== WXK_TAB
)
5048 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5052 // Ignore Alt and Control when they are down alone
5053 if ( keycode
== WXK_ALT
||
5054 keycode
== WXK_CONTROL
)
5061 int action
= KeyEventToActions(event
, &secondAction
);
5067 if ( ButtonTriggerKeyTest(event
) )
5070 wxPGProperty
* p
= m_selected
;
5072 if ( action
== wxPG_ACTION_COPY
)
5074 CopyTextToClipboard(p
->GetDisplayedString());
5078 // Travel and expand/collapse
5081 if ( p
->GetChildCount() &&
5082 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5085 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5087 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5090 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5092 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5099 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5103 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5114 if ( selectDir
>= -1 )
5116 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5118 DoSelectProperty(p
);
5124 // If nothing was selected, select the first item now
5125 // (or navigate out of tab).
5126 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5128 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5129 if ( p
) DoSelectProperty(p
);
5134 // -----------------------------------------------------------------------
5136 // Potentially handles a keyboard event for editor controls.
5137 // Returns false if event should *not* be skipped (on true it can
5138 // be optionally skipped).
5139 // Basicly, false means that SelectProperty was called (or was about
5140 // to be called, if canDestroy was false).
5141 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5145 if ( !m_selected
|| !m_wndEditor
)
5150 int action
= KeyEventToAction(event
);
5153 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5156 // Esc cancels any changes
5157 if ( IsEditorsValueModified() )
5159 EditorsValueWasNotModified();
5161 // Update the control as well
5162 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5164 m_selected
->GetDisplayedString() );
5167 OnValidationFailureReset(m_selected
);
5173 else if ( action
== wxPG_ACTION_COPY
)
5175 // NB: There is some problem with getting native cut-copy-paste keys to go through
5176 // for embedded editor wxTextCtrl. This is why we emulate.
5178 wxTextCtrl
* tc
= GetEditorTextCtrl();
5181 wxString sel
= tc
->GetStringSelection();
5183 CopyTextToClipboard(sel
);
5187 CopyTextToClipboard(m_selected
->GetDisplayedString());
5190 else if ( action
== wxPG_ACTION_CUT
)
5192 wxTextCtrl
* tc
= GetEditorTextCtrl();
5196 tc
->GetSelection(&from
, &to
);
5199 CopyTextToClipboard(tc
->GetStringSelection());
5200 tc
->Remove(from
, to
);
5204 else if ( action
== wxPG_ACTION_PASTE
)
5206 wxTextCtrl
* tc
= GetEditorTextCtrl();
5209 if (wxTheClipboard
->Open())
5211 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5213 wxTextDataObject data
;
5214 wxTheClipboard
->GetData( data
);
5216 tc
->GetSelection(&from
, &to
);
5219 tc
->Remove(from
, to
);
5220 tc
->WriteText(data
.GetText());
5224 tc
->WriteText(data
.GetText());
5227 wxTheClipboard
->Close();
5235 // -----------------------------------------------------------------------
5237 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5241 // Events to editor controls should get relayed here.
5243 wxWindow
* focused
= wxWindow::FindFocus();
5245 wxWindow
* primaryCtrl
= GetEditorControl();
5248 (focused
==primaryCtrl
5249 || m_editorFocused
) )
5251 // Child key must be processed here, since it can
5252 // destroy the control which is referred by its own
5254 HandleChildKey( event
);
5257 HandleKeyEvent( event
);
5260 // -----------------------------------------------------------------------
5262 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5264 m_keyComboConsumed
= 0;
5269 // -----------------------------------------------------------------------
5271 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5273 // Ignore events that occur very close to focus set
5274 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5276 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5281 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5283 int dir
= event
.GetDirection()?1:-1;
5287 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5289 wxWindow
* focused
= wxWindow::FindFocus();
5291 wxWindow
* wndToCheck
= GetEditorControl();
5293 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5294 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5296 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5297 if ( comboTextCtrl
)
5298 wndToCheck
= comboTextCtrl
;
5302 // Because of problems navigating from wxButton, do not go to it.
5305 // No primary, use secondary
5306 wndToCheck = m_wndEditor2;
5308 // If it has editor button, focus to it after the primary editor.
5309 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5310 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5311 // have somewhat debugged in window.cpp itself).
5312 else if ( focused == wndToCheck &&
5314 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5316 wndToCheck = m_wndEditor2;
5317 wxLogDebug(wxT("Exp1"));
5321 if ( focused
!= wndToCheck
&&
5324 wndToCheck
->SetFocus();
5326 // Select all text in wxTextCtrl etc.
5327 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5328 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5330 m_editorFocused
= 1;
5337 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5341 // This allows preventing NavigateOut to occur
5342 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5351 // -----------------------------------------------------------------------
5353 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5355 int keycode
= event
.GetKeyCode();
5357 // Does the keycode trigger button?
5358 if ( keycode
== m_pushButKeyCode
&&
5360 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5361 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5363 m_keyComboConsumed
= 1;
5365 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5366 GetEventHandler()->AddPendingEvent(evt
);
5373 // -----------------------------------------------------------------------
5375 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5377 int keycode
= event
.GetKeyCode();
5379 // Ignore Alt and Control when they are down alone
5380 if ( keycode
== WXK_ALT
||
5381 keycode
== WXK_CONTROL
)
5387 if ( ButtonTriggerKeyTest(event
) )
5390 if ( HandleChildKey(event
) == true )
5393 GetEventHandler()->AddPendingEvent(event
);
5396 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5398 m_keyComboConsumed
= 0;
5400 GetEventHandler()->AddPendingEvent(event
);
5405 // -----------------------------------------------------------------------
5406 // wxPropertyGrid miscellaneous event handling
5407 // -----------------------------------------------------------------------
5409 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5412 // Check if the focus is in this control or one of its children
5413 wxWindow
* newFocused
= wxWindow::FindFocus();
5415 if ( newFocused
!= m_curFocused
)
5416 HandleFocusChange( newFocused
);
5419 // Called by focus event handlers. newFocused is the window that becomes focused.
5420 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5422 unsigned int oldFlags
= m_iFlags
;
5424 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5426 wxWindow
* parent
= newFocused
;
5428 // This must be one of nextFocus' parents.
5431 // Use m_eventObject, which is either wxPropertyGrid or
5432 // wxPropertyGridManager, as appropriate.
5433 if ( parent
== m_eventObject
)
5435 m_iFlags
|= wxPG_FL_FOCUSED
;
5438 parent
= parent
->GetParent();
5441 m_curFocused
= newFocused
;
5443 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5444 (oldFlags
& wxPG_FL_FOCUSED
) )
5446 // On each focus kill, mark the next nav key event
5447 // to be ignored (can't do on set focus since the
5448 // event would occur before it).
5449 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5451 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5453 // Need to store changed value
5454 CommitChangesFromEditor();
5460 // Preliminary code for tab-order respecting
5461 // tab-traversal (but should be moved to
5464 wxWindow* prevFocus = event.GetWindow();
5465 wxWindow* useThis = this;
5466 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5467 useThis = GetParent();
5470 prevFocus->GetParent() == useThis->GetParent() )
5472 wxList& children = useThis->GetParent()->GetChildren();
5474 wxNode* node = children.Find(prevFocus);
5476 if ( node->GetNext() &&
5477 useThis == node->GetNext()->GetData() )
5478 DoSelectProperty(GetFirst());
5479 else if ( node->GetPrevious () &&
5480 useThis == node->GetPrevious()->GetData() )
5481 DoSelectProperty(GetLastProperty());
5486 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5490 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5491 DrawItem( m_selected
);
5495 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5497 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5498 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5499 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5500 //else if ( event.GetWindow() )
5502 HandleFocusChange(event
.GetWindow());
5507 // -----------------------------------------------------------------------
5509 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5511 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5514 // event.Skip() being commented out is aworkaround for bug reported
5515 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5519 // -----------------------------------------------------------------------
5521 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5523 m_iFlags
|= wxPG_FL_SCROLLED
;
5528 // -----------------------------------------------------------------------
5530 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5532 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5534 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5538 // -----------------------------------------------------------------------
5539 // Property editor related functions
5540 // -----------------------------------------------------------------------
5542 // noDefCheck = true prevents infinite recursion.
5543 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorclass
,
5544 const wxString
& name
,
5547 wxASSERT( editorclass
);
5549 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5550 RegisterDefaultEditors();
5552 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorclass
;
5557 // Registers all default editor classes
5558 void wxPropertyGrid::RegisterDefaultEditors()
5560 wxPGRegisterDefaultEditorClass( TextCtrl
);
5561 wxPGRegisterDefaultEditorClass( Choice
);
5562 wxPGRegisterDefaultEditorClass( ComboBox
);
5563 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5564 #if wxPG_INCLUDE_CHECKBOX
5565 wxPGRegisterDefaultEditorClass( CheckBox
);
5567 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5569 // Register SpinCtrl etc. editors before use
5570 RegisterAdditionalEditors();
5573 // -----------------------------------------------------------------------
5574 // wxPGStringTokenizer
5575 // Needed to handle C-style string lists (e.g. "str1" "str2")
5576 // -----------------------------------------------------------------------
5578 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5579 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5583 wxPGStringTokenizer::~wxPGStringTokenizer()
5587 bool wxPGStringTokenizer::HasMoreTokens()
5589 const wxString
& str
= *m_str
;
5591 wxString::const_iterator i
= m_curPos
;
5593 wxUniChar delim
= m_delimeter
;
5595 wxUniChar prev_a
= wxT('\0');
5597 bool inToken
= false;
5599 while ( i
!= str
.end() )
5608 m_readyToken
.clear();
5613 if ( prev_a
!= wxT('\\') )
5617 if ( a
!= wxT('\\') )
5637 m_curPos
= str
.end();
5645 wxString
wxPGStringTokenizer::GetNextToken()
5647 return m_readyToken
;
5650 // -----------------------------------------------------------------------
5652 // -----------------------------------------------------------------------
5654 wxPGChoiceEntry::wxPGChoiceEntry()
5655 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5659 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5660 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5661 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5665 // -----------------------------------------------------------------------
5667 // -----------------------------------------------------------------------
5669 wxPGChoicesData::wxPGChoicesData()
5674 wxPGChoicesData::~wxPGChoicesData()
5679 void wxPGChoicesData::Clear()
5683 for ( i
=0; i
<m_items
.size(); i
++ )
5695 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5697 wxASSERT( m_items
.size() == 0 );
5701 for ( i
=0; i
<data
->GetCount(); i
++ )
5702 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5705 // -----------------------------------------------------------------------
5707 // -----------------------------------------------------------------------
5709 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5713 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5714 m_data
->Insert( -1, p
);
5718 // -----------------------------------------------------------------------
5720 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5724 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5725 p
->SetBitmap(bitmap
);
5726 m_data
->Insert( -1, p
);
5730 // -----------------------------------------------------------------------
5732 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5736 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5737 m_data
->Insert(index
, p
);
5741 // -----------------------------------------------------------------------
5743 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5747 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5748 m_data
->Insert( index
, p
);
5752 // -----------------------------------------------------------------------
5754 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5760 while ( index
< GetCount() )
5762 int cmpRes
= GetLabel(index
).Cmp(label
);
5768 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5769 m_data
->Insert( index
, p
);
5773 // -----------------------------------------------------------------------
5775 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5779 unsigned int itemcount
= 0;
5780 const wxChar
** p
= &labels
[0];
5781 while ( *p
) { p
++; itemcount
++; }
5784 for ( i
= 0; i
< itemcount
; i
++ )
5786 int value
= wxPG_INVALID_VALUE
;
5789 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5793 // -----------------------------------------------------------------------
5795 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5800 unsigned int itemcount
= arr
.size();
5802 for ( i
= 0; i
< itemcount
; i
++ )
5804 int value
= wxPG_INVALID_VALUE
;
5807 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5811 // -----------------------------------------------------------------------
5813 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5818 unsigned int itemcount
= arr
.size();
5820 for ( i
= 0; i
< itemcount
; i
++ )
5822 int value
= wxPG_INVALID_VALUE
;
5823 if ( &arrint
&& arrint
.size() )
5825 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5829 // -----------------------------------------------------------------------
5831 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5833 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5835 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5836 delete m_data
->Item(i
);
5837 m_data
->m_items
.RemoveAt(nIndex
, count
);
5840 // -----------------------------------------------------------------------
5842 int wxPGChoices::Index( const wxString
& str
) const
5847 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5849 if ( m_data
->Item(i
)->GetText() == str
)
5856 // -----------------------------------------------------------------------
5858 int wxPGChoices::Index( int val
) const
5863 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5865 if ( m_data
->Item(i
)->GetValue() == val
)
5872 // -----------------------------------------------------------------------
5874 wxArrayString
wxPGChoices::GetLabels() const
5879 if ( this && IsOk() )
5880 for ( i
=0; i
<GetCount(); i
++ )
5881 arr
.push_back(GetLabel(i
));
5886 // -----------------------------------------------------------------------
5888 bool wxPGChoices::HasValues() const
5893 // -----------------------------------------------------------------------
5895 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5902 for ( i
=0; i
< strings
.size(); i
++ )
5904 int index
= Index(strings
[i
]);
5906 arr
.Add(GetValue(index
));
5908 arr
.Add(wxPG_INVALID_VALUE
);
5915 // -----------------------------------------------------------------------
5917 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5918 wxArrayString
* unmatched
) const
5925 for ( i
=0; i
< strings
.size(); i
++ )
5927 const wxString
& str
= strings
[i
];
5928 int index
= Index(str
);
5931 else if ( unmatched
)
5932 unmatched
->Add(str
);
5939 // -----------------------------------------------------------------------
5941 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5945 if ( data
!= wxPGChoicesEmptyData
)
5952 // -----------------------------------------------------------------------
5954 void wxPGChoices::Init()
5956 m_data
= wxPGChoicesEmptyData
;
5959 // -----------------------------------------------------------------------
5961 void wxPGChoices::Free()
5963 if ( m_data
!= wxPGChoicesEmptyData
)
5966 m_data
= wxPGChoicesEmptyData
;
5970 // -----------------------------------------------------------------------
5971 // wxPropertyGridEvent
5972 // -----------------------------------------------------------------------
5974 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5977 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5978 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5979 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5980 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5981 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5982 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5983 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5984 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5985 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5988 // -----------------------------------------------------------------------
5990 void wxPropertyGridEvent::Init()
5992 m_validationInfo
= NULL
;
5994 m_wasVetoed
= false;
5997 // -----------------------------------------------------------------------
5999 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6000 : wxCommandEvent(commandType
,id
)
6006 // -----------------------------------------------------------------------
6008 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6009 : wxCommandEvent(event
)
6011 m_eventType
= event
.GetEventType();
6012 m_eventObject
= event
.m_eventObject
;
6014 m_property
= event
.m_property
;
6015 m_validationInfo
= event
.m_validationInfo
;
6016 m_canVeto
= event
.m_canVeto
;
6017 m_wasVetoed
= event
.m_wasVetoed
;
6020 // -----------------------------------------------------------------------
6022 wxPropertyGridEvent::~wxPropertyGridEvent()
6026 // -----------------------------------------------------------------------
6028 wxEvent
* wxPropertyGridEvent::Clone() const
6030 return new wxPropertyGridEvent( *this );
6033 void wxPropertyGrid::SetPropertyAttributeAll( const wxString
& attrName
, wxVariant value
)
6035 DoSetPropertyAttribute(GetRoot(), attrName
, value
, wxPG_RECURSE
);
6038 // -----------------------------------------------------------------------
6039 // wxPropertyGridPopulator
6040 // -----------------------------------------------------------------------
6042 wxPropertyGridPopulator::wxPropertyGridPopulator()
6046 wxPGGlobalVars
->m_offline
++;
6049 // -----------------------------------------------------------------------
6051 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6054 m_propHierarchy
.clear();
6057 // -----------------------------------------------------------------------
6059 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6065 // -----------------------------------------------------------------------
6067 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6070 // Free unused sets of choices
6071 wxPGHashMapS2P::iterator it
;
6073 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6075 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6082 m_pg
->GetPanel()->Refresh();
6084 wxPGGlobalVars
->m_offline
--;
6087 // -----------------------------------------------------------------------
6089 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6090 const wxString
& propLabel
,
6091 const wxString
& propName
,
6092 const wxString
* propValue
,
6093 wxPGChoices
* pChoices
)
6095 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6096 wxPGProperty
* parent
= GetCurParent();
6098 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6100 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6104 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6106 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6110 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6112 property
->SetLabel(propLabel
);
6113 property
->DoSetName(propName
);
6115 if ( pChoices
&& pChoices
->IsOk() )
6116 property
->SetChoices(*pChoices
);
6118 m_state
->DoInsert(parent
, -1, property
);
6121 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6126 // -----------------------------------------------------------------------
6128 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6130 m_propHierarchy
.push_back(property
);
6131 DoScanForChildren();
6132 m_propHierarchy
.pop_back();
6135 // -----------------------------------------------------------------------
6137 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6138 const wxString
& idString
)
6140 wxPGChoices choices
;
6143 if ( choicesString
[0] == wxT('@') )
6145 wxString ids
= choicesString
.substr(1);
6146 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6147 if ( it
== m_dictIdChoices
.end() )
6148 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6150 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6155 if ( idString
.length() )
6157 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6158 if ( it
!= m_dictIdChoices
.end() )
6160 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6167 // Parse choices string
6168 wxString::const_iterator it
= choicesString
.begin();
6172 bool labelValid
= false;
6174 for ( ; it
!= choicesString
.end(); it
++ )
6180 if ( c
== wxT('"') )
6185 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6186 choices
.Add(label
, l
);
6189 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6194 else if ( c
== wxT('=') )
6201 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6208 if ( c
== wxT('"') )
6221 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6222 choices
.Add(label
, l
);
6225 if ( !choices
.IsOk() )
6227 choices
.EnsureData();
6231 if ( idString
.length() )
6232 m_dictIdChoices
[idString
] = choices
.GetData();
6239 // -----------------------------------------------------------------------
6241 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6243 if ( s
.Last() == wxT('%') )
6245 wxString s2
= s
.substr(0,s
.length()-1);
6247 if ( s2
.ToLong(&val
, 10) )
6249 *pval
= (val
*max
)/100;
6255 return s
.ToLong(pval
, 10);
6258 // -----------------------------------------------------------------------
6260 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6261 const wxString
& type
,
6262 const wxString
& value
)
6264 int l
= m_propHierarchy
.size();
6268 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6269 wxString valuel
= value
.Lower();
6272 if ( type
.length() == 0 )
6277 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6279 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6281 else if ( value
.ToLong(&v
, 0) )
6288 if ( type
== wxT("string") )
6292 else if ( type
== wxT("int") )
6295 value
.ToLong(&v
, 0);
6298 else if ( type
== wxT("bool") )
6300 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6307 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6312 p
->SetAttribute( name
, variant
);
6317 // -----------------------------------------------------------------------
6319 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6321 wxLogError(_("Error in resource: %s"),msg
.c_str());
6324 // -----------------------------------------------------------------------