1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/object.h"
23 #include "wx/string.h"
26 #include "wx/window.h"
29 #include "wx/dcmemory.h"
30 #include "wx/button.h"
33 #include "wx/cursor.h"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
37 #include "wx/choice.h"
38 #include "wx/stattext.h"
39 #include "wx/scrolwin.h"
40 #include "wx/dirdlg.h"
41 #include "wx/layout.h"
43 #include "wx/textdlg.h"
44 #include "wx/filedlg.h"
45 #include "wx/statusbr.h"
51 // This define is necessary to prevent macro clearing
52 #define __wxPG_SOURCE_FILE__
54 #include <wx/propgrid/propgrid.h>
55 #include <wx/propgrid/editors.h>
57 #if wxPG_USE_RENDERER_NATIVE
58 #include <wx/renderer.h>
61 #include <wx/odcombo.h>
64 #include "wx/dcbuffer.h"
65 #include <wx/clipbrd.h>
66 #include <wx/dataobj.h>
69 #include <wx/msw/private.h>
74 // Two pics for the expand / collapse buttons.
75 // Files are not supplied with this project (since it is
76 // recommended to use either custom or native rendering).
77 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
78 // and copy xpm files from archive to wxPropertyGrid src directory
79 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
80 // and set wxPG_USE_RENDERER_NATIVE to 0).
81 #ifndef wxPG_ICON_WIDTH
82 #if defined(__WXMAC__)
83 #include "mac_collapse.xpm"
84 #include "mac_expand.xpm"
85 #elif defined(__WXGTK__)
86 #include "linux_collapse.xpm"
87 #include "linux_expand.xpm"
89 #include "default_collapse.xpm"
90 #include "default_expand.xpm"
95 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
96 #define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
97 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
98 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
99 #define wxPG_YSPACING_MIN 1
100 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
101 // but causes normal combobox to spill out under MSW
103 #define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
105 #define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
106 // Must be larger than largest control border
110 #define wxPG_DEFAULT_CURSOR wxNullCursor
113 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
115 #define wxPG_HIDER_BUTTON_HEIGHT 25
117 #define wxPG_PIXELS_PER_UNIT m_lineHeight
119 #ifdef wxPG_ICON_WIDTH
120 #define m_iconHeight m_iconWidth
123 #define wxPG_TOOLTIP_DELAY 1000
125 // -----------------------------------------------------------------------
128 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
130 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
133 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
136 // -----------------------------------------------------------------------
138 const wxChar
*wxPropertyGridNameStr
= wxT("wxPropertyGrid");
140 // -----------------------------------------------------------------------
141 // Statics in one class for easy destruction.
142 // NB: We prefer to use wxModule, as it offers more consistent behavior
143 // across platforms. However, for those rare problem situations, we
144 // also need to offer option to use simpler approach.
145 // -----------------------------------------------------------------------
147 #ifndef wxPG_USE_WXMODULE
148 #define wxPG_USE_WXMODULE 1
151 #if wxPG_USE_WXMODULE
153 #include <wx/module.h>
155 class wxPGGlobalVarsClassManager
: public wxModule
157 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
159 wxPGGlobalVarsClassManager() {}
160 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
161 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
164 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
166 #else // !wxPG_USE_WXMODULE
168 class wxPGGlobalVarsClassManager
171 wxPGGlobalVarsClassManager() {}
172 ~wxPGGlobalVarsClassManager() { delete wxPGGlobalVars
; }
175 static wxPGGlobalVarsClassManager gs_pgGlobalVarsClassManager
;
180 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
183 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
185 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
187 m_boolChoices
.Add(_("False"));
188 m_boolChoices
.Add(_("True"));
190 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
192 m_defaultRenderer
= new wxPGDefaultRenderer();
194 m_autoGetTranslation
= false;
203 wxVariantClassInfo_long
= wxPGVariantDataGetClassInfo(v
.GetData());
206 wxVariantClassInfo_string
= wxPGVariantDataGetClassInfo(v
.GetData());
209 wxVariantClassInfo_double
= wxPGVariantDataGetClassInfo(v
.GetData());
212 wxVariantClassInfo_bool
= wxPGVariantDataGetClassInfo(v
.GetData());
215 wxVariantClassInfo_arrstring
= wxPGVariantDataGetClassInfo(v
.GetData());
218 wxVariant
v2((wxObject
*)&col
);
219 wxVariantClassInfo_wxobject
= wxPGVariantDataGetClassInfo(v2
.GetData());
223 wxVariantClassInfo_list
= wxPGVariantDataGetClassInfo(v
.GetData());
226 wxVariantClassInfo_wxColour
= wxPGVariantDataGetClassInfo(v
.GetData());
229 v
= wxVariant(wxDateTime::Now());
230 wxVariantClassInfo_datetime
= wxPGVariantDataGetClassInfo(v
.GetData());
233 // Prepare some shared variants
234 m_vEmptyString
= wxString();
236 m_vMinusOne
= (long) -1;
240 // Prepare cached string constants
241 m_strMin
= wxS("Min");
242 m_strMax
= wxS("Max");
243 m_strUnits
= wxS("Units");
244 m_strInlineHelp
= wxS("InlineHelp");
252 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
256 delete m_defaultRenderer
;
258 // This will always have one ref
259 delete m_fontFamilyChoices
;
262 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
263 delete ((wxValidator
*)m_arrValidators
[i
]);
267 // Destroy value type class instances.
268 wxPGHashMapS2P::iterator vt_it
;
270 // Destroy editor class instances.
271 // iterate over all the elements in the class
272 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
274 delete ((wxPGEditor
*)vt_it
->second
);
277 delete wxPGProperty::sm_wxPG_LABEL
;
280 // -----------------------------------------------------------------------
282 // -----------------------------------------------------------------------
285 // This class is a wxBrush derivative used in the background colour
286 // brush cache. It adds wxPG-type colour-in-long to the class.
287 // JMS: Yes I know wxBrush doesn't actually hold the value (refcounted
288 // object does), but this is simpler implementation and equally
292 class wxPGBrush
: public wxBrush
295 wxPGBrush( const wxColour
& colour
);
297 virtual ~wxPGBrush() { }
298 void SetColour2( const wxColour
& colour
);
299 inline long GetColourAsLong() const { return m_colAsLong
; }
305 void wxPGBrush::SetColour2( const wxColour
& colour
)
307 wxBrush::SetColour(colour
);
308 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
312 wxPGBrush::wxPGBrush() : wxBrush()
318 wxPGBrush::wxPGBrush( const wxColour
& colour
) : wxBrush(colour
)
320 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
324 // -----------------------------------------------------------------------
326 // -----------------------------------------------------------------------
329 // Same as wxPGBrush, but for wxColour instead.
332 class wxPGColour
: public wxColour
335 wxPGColour( const wxColour
& colour
);
337 virtual ~wxPGColour() { }
338 void SetColour2( const wxColour
& colour
);
339 inline long GetColourAsLong() const { return m_colAsLong
; }
345 void wxPGColour::SetColour2( const wxColour
& colour
)
348 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
352 wxPGColour::wxPGColour() : wxColour()
358 wxPGColour::wxPGColour( const wxColour
& colour
) : wxColour(colour
)
360 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
364 // -----------------------------------------------------------------------
366 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
367 // and tries to commit property value.
368 // -----------------------------------------------------------------------
370 class wxPGTLWHandler
: public wxEvtHandler
374 wxPGTLWHandler( wxPropertyGrid
* pg
)
382 void OnClose( wxCloseEvent
& event
)
384 // ClearSelection forces value validation/commit.
385 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
395 wxPropertyGrid
* m_pg
;
397 DECLARE_EVENT_TABLE()
400 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
401 EVT_CLOSE(wxPGTLWHandler::OnClose
)
404 // -----------------------------------------------------------------------
406 // -----------------------------------------------------------------------
409 // wxPGCanvas acts as a graphics sub-window of the
410 // wxScrolledWindow that wxPropertyGrid is.
412 class wxPGCanvas
: public wxPanel
415 wxPGCanvas() : wxPanel()
418 virtual ~wxPGCanvas() { }
421 void OnMouseMove( wxMouseEvent
&event
)
423 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
424 pg
->OnMouseMove( event
);
427 void OnMouseClick( wxMouseEvent
&event
)
429 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
430 pg
->OnMouseClick( event
);
433 void OnMouseUp( wxMouseEvent
&event
)
435 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
436 pg
->OnMouseUp( event
);
439 void OnMouseRightClick( wxMouseEvent
&event
)
441 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
442 pg
->OnMouseRightClick( event
);
445 void OnMouseDoubleClick( wxMouseEvent
&event
)
447 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
448 pg
->OnMouseDoubleClick( event
);
451 void OnKey( wxKeyEvent
& event
)
453 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
457 void OnKeyUp( wxKeyEvent
& event
)
459 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
460 pg
->OnKeyUp( event
);
463 void OnNavigationKey( wxNavigationKeyEvent
& event
)
465 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
466 pg
->OnNavigationKey( event
);
469 void OnPaint( wxPaintEvent
& event
);
472 DECLARE_EVENT_TABLE()
476 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
477 EVT_MOTION(wxPGCanvas::OnMouseMove
)
478 EVT_PAINT(wxPGCanvas::OnPaint
)
479 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
480 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
481 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
482 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
483 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
484 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
485 EVT_CHAR(wxPGCanvas::OnKey
)
486 EVT_NAVIGATION_KEY(wxPGCanvas::OnNavigationKey
)
490 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
492 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
493 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
497 // Don't paint after destruction has begun
498 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
501 // Update everything inside the box
502 wxRect r
= GetUpdateRegion().GetBox();
504 // Repaint this rectangle
505 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
507 // We assume that the size set when grid is shown
508 // is what is desired.
509 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
512 // -----------------------------------------------------------------------
514 // -----------------------------------------------------------------------
516 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
518 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
519 EVT_IDLE(wxPropertyGrid::OnIdle
)
520 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
521 EVT_PAINT(wxPropertyGrid::OnPaint
)
522 EVT_SIZE(wxPropertyGrid::OnResize
)
523 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
524 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
525 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
526 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
527 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
528 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
529 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
530 EVT_TEXT_ENTER(wxPG_SUBID1
,wxPropertyGrid::OnCustomEditorEvent
)
531 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
535 // -----------------------------------------------------------------------
537 wxPropertyGrid::wxPropertyGrid()
543 // -----------------------------------------------------------------------
545 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
554 Create(parent
,id
,pos
,size
,style
,name
);
557 // -----------------------------------------------------------------------
559 bool wxPropertyGrid::Create( wxWindow
*parent
,
567 if ( !(style
&wxBORDER_MASK
) )
568 style
|= wxSIMPLE_BORDER
;
573 // This prevents crash under Win2K, but still
574 // enables keyboard navigation
575 if ( style
& wxTAB_TRAVERSAL
)
577 style
&= ~(wxTAB_TRAVERSAL
);
578 style
|= wxWANTS_CHARS
;
581 if ( style
& wxTAB_TRAVERSAL
)
582 style
|= wxWANTS_CHARS
;
585 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
592 // -----------------------------------------------------------------------
595 // Initialize values to defaults
597 void wxPropertyGrid::Init1()
599 #if !wxPG_USE_WXMODULE
600 if ( !wxPGGlobalVars
)
601 wxPGGlobalVars
= new wxPGGlobalVarsClass();
604 // Register editor classes, if necessary.
605 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
606 RegisterDefaultEditors();
609 m_pState
= (wxPropertyGridPageState
*) NULL
;
610 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
611 m_selected
= (wxPGProperty
*) NULL
;
613 m_propHover
= (wxPGProperty
*) NULL
;
614 m_eventObject
= this;
615 m_curFocused
= (wxWindow
*) NULL
;
617 m_inDoPropertyChanged
= 0;
618 m_inCommitChangesFromEditor
= 0;
619 m_inDoSelectProperty
= 0;
620 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
626 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
627 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
628 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
629 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
630 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
631 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
632 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
633 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
634 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
635 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
636 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
637 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
638 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
640 m_coloursCustomized
= 0;
645 #if wxPG_DOUBLE_BUFFER
646 m_doubleBuffer
= (wxBitmap
*) NULL
;
649 m_windowsToDelete
= NULL
;
651 #ifndef wxPG_ICON_WIDTH
657 m_iconWidth
= wxPG_ICON_WIDTH
;
662 m_gutterWidth
= wxPG_GUTTER_MIN
;
663 m_subgroup_extramargin
= 10;
667 m_width
= m_height
= 0;
669 SetButtonShortcut(0);
671 m_keyComboConsumed
= 0;
673 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
676 m_chgInfo_changedProperty
= NULL
;
679 // -----------------------------------------------------------------------
682 // Initialize after parent etc. set
684 void wxPropertyGrid::Init2()
686 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
689 // Smaller controls on Mac
690 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
693 // Now create state, if one didn't exist already
694 // (wxPropertyGridManager might have created it for us).
697 m_pState
= CreateState();
698 m_pState
->m_pPropGrid
= this;
699 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
702 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
703 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
705 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
707 m_pState
->InitNonCatMode();
709 m_pState
->m_properties
= m_pState
->m_abcArray
;
712 GetClientSize(&m_width
,&m_height
);
714 #ifndef wxPG_ICON_WIDTH
715 // create two bitmap nodes for drawing
716 m_expandbmp
= new wxBitmap(expand_xpm
);
717 m_collbmp
= new wxBitmap(collapse_xpm
);
719 // calculate average font height for bitmap centering
721 m_iconWidth
= m_expandbmp
->GetWidth();
722 m_iconHeight
= m_expandbmp
->GetHeight();
725 m_curcursor
= wxCURSOR_ARROW
;
726 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
728 // adjust bitmap icon y position so they are centered
729 m_vspacing
= wxPG_DEFAULT_VSPACING
;
733 wxFont useFont
= wxScrolledWindow::GetFont();
734 wxScrolledWindow::SetOwnFont( useFont
);
737 // This should be otherwise called by SetOwnFont
738 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
740 // Add base brush item
741 m_arrBgBrushes
.Add((void*)new wxPGBrush());
743 // Add base colour items
744 m_arrFgCols
.Add((void*)new wxPGColour());
745 m_arrFgCols
.Add((void*)new wxPGColour());
749 // This helps with flicker
750 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
753 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
754 m_tlp
= ::wxGetTopLevelParent(this);
755 m_tlwHandler
= handler
;
756 m_tlp
->PushEventHandler(handler
);
758 // set virtual size to this window size
759 wxSize wndsize
= GetSize();
760 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
762 m_timeCreated
= ::wxGetLocalTimeMillis();
764 m_canvas
= new wxPGCanvas();
765 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
766 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
767 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
769 m_iFlags
|= wxPG_FL_INITIALIZED
;
771 m_ncWidth
= wndsize
.GetWidth();
773 // Need to call OnResize handler or size given in constructor/Create
775 wxSizeEvent
sizeEvent(wndsize
,0);
779 // -----------------------------------------------------------------------
781 wxPropertyGrid::~wxPropertyGrid()
785 DoSelectProperty(NULL
);
787 // This should do prevent things from going too badly wrong
788 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
790 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
791 m_canvas
->ReleaseMouse();
793 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
794 m_tlp
->RemoveEventHandler(handler
);
798 if ( IsEditorsValueModified() )
799 ::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).)"),
800 wxS("wxPropertyGrid Debug Warning") );
803 #if wxPG_DOUBLE_BUFFER
804 if ( m_doubleBuffer
)
805 delete m_doubleBuffer
;
808 delete m_windowsToDelete
;
810 //m_selected = (wxPGProperty*) NULL;
812 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
815 delete m_cursorSizeWE
;
817 #ifndef wxPG_ICON_WIDTH
822 // Delete cached text colours.
823 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
825 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
828 // Delete cached brushes.
829 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
831 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
834 // Delete common value records
835 for ( i
=0; i
<m_commonValues
.size(); i
++ )
837 delete GetCommonValue(i
);
841 // -----------------------------------------------------------------------
843 bool wxPropertyGrid::Destroy()
845 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
846 m_canvas
->ReleaseMouse();
848 return wxScrolledWindow::Destroy();
851 // -----------------------------------------------------------------------
853 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
855 return new wxPropertyGridPageState();
858 // -----------------------------------------------------------------------
859 // wxPropertyGrid overridden wxWindow methods
860 // -----------------------------------------------------------------------
862 void wxPropertyGrid::SetWindowStyleFlag( long style
)
864 long old_style
= m_windowStyle
;
866 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
868 wxASSERT( m_pState
);
870 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
873 EnableCategories( true );
875 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
877 // Disable categories
878 EnableCategories( false );
880 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
886 PrepareAfterItemsAdded();
888 m_pState
->m_itemsAdded
= 1;
890 #if wxPG_SUPPORT_TOOLTIPS
891 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
897 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
898 SetToolTip ( tooltip );
899 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
902 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
907 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
912 wxScrolledWindow::SetWindowStyleFlag ( style
);
914 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
916 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
918 CalculateFontAndBitmapStuff( m_vspacing
);
924 // -----------------------------------------------------------------------
926 void wxPropertyGrid::Freeze()
930 wxScrolledWindow::Freeze();
935 // -----------------------------------------------------------------------
937 void wxPropertyGrid::Thaw()
943 wxScrolledWindow::Thaw();
944 RecalculateVirtualSize();
945 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
949 // Force property re-selection
951 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
955 // -----------------------------------------------------------------------
957 void wxPropertyGrid::SetExtraStyle( long exStyle
)
959 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
961 #if defined(__WXMSW__)
964 // Don't use WS_EX_COMPOSITED just now.
967 if ( m_iFlags & wxPG_FL_IN_MANAGER )
968 hWnd = (HWND)GetParent()->GetHWND();
970 hWnd = (HWND)GetHWND();
972 ::SetWindowLong( hWnd, GWL_EXSTYLE,
973 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
976 //#elif defined(__WXGTK20__)
978 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
979 // truly was double-buffered.
980 if ( !this->IsDoubleBuffered() )
982 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
986 #if wxPG_DOUBLE_BUFFER
987 delete m_doubleBuffer
;
988 m_doubleBuffer
= NULL
;
993 wxScrolledWindow::SetExtraStyle( exStyle
);
995 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
996 m_pState
->InitNonCatMode();
998 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
999 m_windowStyle
|= wxPG_TOOLTIPS
;
1002 wxPGGlobalVars
->m_extraStyle
= exStyle
;
1005 // -----------------------------------------------------------------------
1007 // returns the best acceptable minimal size
1008 wxSize
wxPropertyGrid::DoGetBestSize() const
1011 if ( m_lineHeight
> hei
)
1013 wxSize sz
= wxSize( 60, hei
+40 );
1019 // -----------------------------------------------------------------------
1020 // wxPropertyGrid Font and Colour Methods
1021 // -----------------------------------------------------------------------
1023 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
1027 m_captionFont
= wxScrolledWindow::GetFont();
1029 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1030 m_subgroup_extramargin
= x
+ (x
/2);
1033 #if wxPG_USE_RENDERER_NATIVE
1034 m_iconWidth
= wxPG_ICON_WIDTH
;
1035 #elif wxPG_ICON_WIDTH
1037 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
1038 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
1039 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
1043 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
1044 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
1045 m_gutterWidth
= wxPG_GUTTER_MIN
;
1048 if ( vspacing
<= 1 ) vdiv
= 12;
1049 else if ( vspacing
>= 3 ) vdiv
= 3;
1051 m_spacingy
= m_fontHeight
/ vdiv
;
1052 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1053 m_spacingy
= wxPG_YSPACING_MIN
;
1056 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1057 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1059 m_captionFont
.SetWeight(wxBOLD
);
1060 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1062 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1063 m_visPropArray
.SetCount((m_height
/m_lineHeight
)+10);
1066 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1067 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1070 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1072 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1073 RecalculateVirtualSize();
1075 InvalidateBestSize();
1078 // -----------------------------------------------------------------------
1080 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1086 // -----------------------------------------------------------------------
1088 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1089 int ga
= 1000, int ba
= 1000,
1090 bool forceDifferent
= false)
1097 // Recursion guard (allow 2 max)
1098 static int isinside
= 0;
1100 wxCHECK_MSG( isinside
< 3,
1102 wxT("wxPGAdjustColour should not be recursively called more than once") );
1107 int g
= src
.Green();
1110 if ( r2
>255 ) r2
= 255;
1111 else if ( r2
<0) r2
= 0;
1113 if ( g2
>255 ) g2
= 255;
1114 else if ( g2
<0) g2
= 0;
1116 if ( b2
>255 ) b2
= 255;
1117 else if ( b2
<0) b2
= 0;
1119 // Make sure they are somewhat different
1120 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1121 dst
= wxPGAdjustColour(src
,-(ra
*2));
1123 dst
= wxColour(r2
,g2
,b2
);
1125 // Recursion guard (allow 2 max)
1132 static int wxPGGetColAvg( const wxColour
& col
)
1134 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1138 void wxPropertyGrid::RegainColours()
1140 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1142 if ( !(m_coloursCustomized
& 0x0002) )
1144 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1146 // Make sure colour is dark enough
1148 int colDec
= wxPGGetColAvg(col
) - 230;
1150 int colDec
= wxPGGetColAvg(col
) - 200;
1153 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1158 if ( !(m_coloursCustomized
& 0x0001) )
1159 m_colMargin
= m_colCapBack
;
1161 if ( !(m_coloursCustomized
& 0x0004) )
1168 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1169 m_colCapFore
= capForeCol
;
1171 // Set the cached colour as well.
1172 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1175 if ( !(m_coloursCustomized
& 0x0008) )
1177 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1178 m_colPropBack
= bgCol
;
1180 // Set the cached brush as well.
1181 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1184 if ( !(m_coloursCustomized
& 0x0010) )
1186 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1187 m_colPropFore
= fgCol
;
1189 // Set the cached colour as well.
1190 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1193 if ( !(m_coloursCustomized
& 0x0020) )
1194 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1196 if ( !(m_coloursCustomized
& 0x0040) )
1197 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1199 if ( !(m_coloursCustomized
& 0x0080) )
1200 m_colLine
= m_colCapBack
;
1202 if ( !(m_coloursCustomized
& 0x0100) )
1203 m_colDisPropFore
= m_colCapFore
;
1205 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1208 // -----------------------------------------------------------------------
1210 void wxPropertyGrid::ResetColours()
1212 m_coloursCustomized
= 0;
1219 // -----------------------------------------------------------------------
1221 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1223 // Must disable active editor.
1226 bool selRes
= ClearSelection();
1227 wxPG_CHECK_MSG_DBG( selRes
,
1229 wxT("failed to deselect a property (editor probably had invalid value)") );
1232 // TODO: Following code is disabled with wxMac because
1233 // it is reported to fail. I (JMS) cannot debug it
1234 // personally right now.
1235 #if !defined(__WXMAC__)
1236 bool res
= wxScrolledWindow::SetFont( font
);
1239 CalculateFontAndBitmapStuff( m_vspacing
);
1242 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1250 // TODO: Remove after SetFont crash fixed.
1251 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1253 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."));
1259 // -----------------------------------------------------------------------
1261 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1264 m_coloursCustomized
|= 0x80;
1268 // -----------------------------------------------------------------------
1270 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1273 m_coloursCustomized
|= 0x01;
1277 // -----------------------------------------------------------------------
1279 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1281 m_colPropBack
= col
;
1282 m_coloursCustomized
|= 0x08;
1284 // Set the cached brush as well.
1285 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1290 // -----------------------------------------------------------------------
1292 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1294 m_colPropFore
= col
;
1295 m_coloursCustomized
|= 0x10;
1297 // Set the cached colour as well.
1298 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1303 // -----------------------------------------------------------------------
1305 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1307 m_colEmptySpace
= col
;
1312 // -----------------------------------------------------------------------
1314 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1316 m_colDisPropFore
= col
;
1317 m_coloursCustomized
|= 0x100;
1321 // -----------------------------------------------------------------------
1323 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1326 m_coloursCustomized
|= 0x20;
1330 // -----------------------------------------------------------------------
1332 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1335 m_coloursCustomized
|= 0x40;
1339 // -----------------------------------------------------------------------
1341 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1344 m_coloursCustomized
|= 0x02;
1348 // -----------------------------------------------------------------------
1350 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1353 m_coloursCustomized
|= 0x04;
1355 // Set the cached colour as well.
1356 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1361 // -----------------------------------------------------------------------
1363 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1365 unsigned char ind
= index
;
1367 p
->m_bgColIndex
= ind
;
1370 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1371 SetBackgroundColourIndex(p
->Item(i
),index
);
1374 // -----------------------------------------------------------------------
1376 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1378 wxPG_PROP_ARG_CALL_PROLOG()
1383 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1385 // As it is most likely that the previous colour is used, start comparison
1387 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1389 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1398 colInd
= m_arrBgBrushes
.size();
1399 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1400 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1404 SetBackgroundColourIndex(p
,colInd
);
1406 // If this was on a visible grid, then draw it.
1407 DrawItemAndChildren(p
);
1410 // -----------------------------------------------------------------------
1412 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1414 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1416 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1419 // -----------------------------------------------------------------------
1421 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1423 unsigned char ind
= index
;
1425 p
->m_fgColIndex
= ind
;
1427 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1430 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1431 SetTextColourIndex( p
->Item(i
), index
, flags
);
1435 // -----------------------------------------------------------------------
1437 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1442 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1444 // As it is most likely that the previous colour is used, start comparison
1446 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1448 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1457 colInd
= m_arrFgCols
.size();
1458 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1459 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1465 // -----------------------------------------------------------------------
1467 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1470 wxPG_PROP_ARG_CALL_PROLOG()
1472 if ( p
->IsCategory() )
1474 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1475 cat
->SetTextColIndex(CacheColour(colour
));
1481 flags
|= wxPG_RECURSE
;
1482 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1484 DrawItemAndChildren(p
);
1487 // -----------------------------------------------------------------------
1489 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1491 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1493 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1496 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1498 wxPG_PROP_ARG_CALL_PROLOG()
1500 SetBackgroundColourIndex( p
, 0 );
1501 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1503 if ( p
->IsCategory() )
1505 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1506 cat
->SetTextColIndex(1);
1510 // -----------------------------------------------------------------------
1511 // wxPropertyGrid property adding and removal
1512 // -----------------------------------------------------------------------
1514 void wxPropertyGrid::PrepareAfterItemsAdded()
1516 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1518 m_pState
->m_itemsAdded
= 0;
1520 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1523 RecalculateVirtualSize();
1526 // -----------------------------------------------------------------------
1527 // wxPropertyGrid property value setting and getting
1528 // -----------------------------------------------------------------------
1530 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1532 m_pState
->DoSetPropertyValueUnspecified(p
);
1533 DrawItemAndChildren(p
);
1535 wxPGProperty
* parent
= p
->GetParent();
1536 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1539 parent
= parent
->GetParent();
1543 // -----------------------------------------------------------------------
1544 // wxPropertyGrid property operations
1545 // -----------------------------------------------------------------------
1547 void wxPropertyGrid::DoSetPropertyName( wxPGProperty
* p
, const wxString
& newname
)
1549 wxCHECK_RET( p
, wxT("invalid property id") );
1551 if ( p
->GetBaseName().Len() ) m_pState
->m_dictName
.erase( p
->GetBaseName() );
1552 if ( newname
.Len() ) m_pState
->m_dictName
[newname
] = (void*) p
;
1554 p
->DoSetName(newname
);
1557 // -----------------------------------------------------------------------
1559 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1561 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1565 bool changed
= false;
1567 // Is it inside collapsed section?
1568 if ( !p
->IsVisible() )
1571 wxPGProperty
* parent
= p
->GetParent();
1572 wxPGProperty
* grandparent
= parent
->GetParent();
1574 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1575 Expand( grandparent
);
1583 GetViewStart(&vx
,&vy
);
1584 vy
*=wxPG_PIXELS_PER_UNIT
;
1590 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1591 m_iFlags
|= wxPG_FL_SCROLLED
;
1594 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1596 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1597 m_iFlags
|= wxPG_FL_SCROLLED
;
1607 // -----------------------------------------------------------------------
1608 // wxPropertyGrid helper methods called by properties
1609 // -----------------------------------------------------------------------
1611 // Control font changer helper.
1612 void wxPropertyGrid::SetCurControlBoldFont()
1614 wxASSERT( m_wndEditor
);
1615 m_wndEditor
->SetFont( m_captionFont
);
1618 // -----------------------------------------------------------------------
1620 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1623 #if wxPG_SMALL_SCREEN
1624 // On small-screen devices, always show dialogs with default position and size.
1625 return wxDefaultPosition
;
1627 int splitterX
= GetSplitterPosition();
1631 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1633 ImprovedClientToScreen( &x
, &y
);
1635 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1636 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1643 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1653 new_y
= y
+ m_lineHeight
;
1655 return wxPoint(new_x
,new_y
);
1659 // -----------------------------------------------------------------------
1661 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1663 if ( src_str
.length() == 0 )
1669 bool prev_is_slash
= false;
1671 wxString::const_iterator i
= src_str
.begin();
1675 for ( ; i
!= src_str
.end(); i
++ )
1679 if ( a
!= wxS('\\') )
1681 if ( !prev_is_slash
)
1687 if ( a
== wxS('n') )
1690 dst_str
<< wxS('\n');
1692 dst_str
<< wxS('\n');
1695 else if ( a
== wxS('t') )
1696 dst_str
<< wxS('\t');
1700 prev_is_slash
= false;
1704 if ( prev_is_slash
)
1706 dst_str
<< wxS('\\');
1707 prev_is_slash
= false;
1711 prev_is_slash
= true;
1718 // -----------------------------------------------------------------------
1720 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1722 if ( src_str
.length() == 0 )
1728 wxString::const_iterator i
= src_str
.begin();
1729 wxUniChar prev_a
= wxS('\0');
1733 for ( ; i
!= src_str
.end(); i
++ )
1737 if ( a
>= wxS(' ') )
1739 // This surely is not something that requires an escape sequence.
1744 // This might need...
1745 if ( a
== wxS('\r') )
1747 // DOS style line end.
1748 // Already taken care below
1750 else if ( a
== wxS('\n') )
1751 // UNIX style line end.
1752 dst_str
<< wxS("\\n");
1753 else if ( a
== wxS('\t') )
1755 dst_str
<< wxS('\t');
1758 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1768 // -----------------------------------------------------------------------
1770 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1774 return (wxPGProperty
*) NULL
;
1777 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1780 // -----------------------------------------------------------------------
1781 // wxPropertyGrid graphics related methods
1782 // -----------------------------------------------------------------------
1784 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1788 // Update everything inside the box
1789 wxRect r
= GetUpdateRegion().GetBox();
1791 dc
.SetPen(m_colEmptySpace
);
1792 dc
.SetBrush(m_colEmptySpace
);
1793 dc
.DrawRectangle(r
);
1796 // -----------------------------------------------------------------------
1798 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1799 wxPGProperty
* property
) const
1801 // Prepare rectangle to be used
1803 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1804 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1806 #if (wxPG_USE_RENDERER_NATIVE)
1808 #elif wxPG_ICON_WIDTH
1809 // Drawing expand/collapse button manually
1810 dc
.SetPen(m_colPropFore
);
1811 if ( property
->IsCategory() )
1812 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1814 dc
.SetBrush(m_colPropBack
);
1816 dc
.DrawRectangle( r
);
1817 int _y
= r
.y
+(m_iconWidth
/2);
1818 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1823 if ( property
->IsExpanded() )
1825 // wxRenderer functions are non-mutating in nature, so it
1826 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1827 // Hopefully this does not cause problems.
1828 #if (wxPG_USE_RENDERER_NATIVE)
1829 wxRendererNative::Get().DrawTreeItemButton(
1835 #elif wxPG_ICON_WIDTH
1844 #if (wxPG_USE_RENDERER_NATIVE)
1845 wxRendererNative::Get().DrawTreeItemButton(
1851 #elif wxPG_ICON_WIDTH
1852 int _x
= r
.x
+(m_iconWidth
/2);
1853 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1859 #if (wxPG_USE_RENDERER_NATIVE)
1861 #elif wxPG_ICON_WIDTH
1864 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1868 // -----------------------------------------------------------------------
1871 // This is the one called by OnPaint event handler and others.
1872 // topy and bottomy are already unscrolled (ie. physical)
1874 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1876 unsigned int bottomy
,
1877 const wxRect
* clipRect
)
1879 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1881 m_pState
->EnsureVirtualHeight();
1883 wxRect tempClipRect
;
1886 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1887 clipRect
= &tempClipRect
;
1890 // items added check
1891 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1893 int paintFinishY
= 0;
1895 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1898 bool isBuffered
= false;
1900 #if wxPG_DOUBLE_BUFFER
1901 wxMemoryDC
* bufferDC
= NULL
;
1903 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1905 if ( !m_doubleBuffer
)
1907 paintFinishY
= clipRect
->y
;
1912 bufferDC
= new wxMemoryDC();
1914 // If nothing was changed, then just copy from double-buffer
1915 bufferDC
->SelectObject( *m_doubleBuffer
);
1925 dc
.SetClippingRegion( *clipRect
);
1926 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1929 #if wxPG_DOUBLE_BUFFER
1932 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1933 bufferDC
, 0, 0, wxCOPY
);
1934 dc
.DestroyClippingRegion(); // Is this really necessary?
1940 // Clear area beyond bottomY?
1941 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1943 dc
.SetPen(m_colEmptySpace
);
1944 dc
.SetBrush(m_colEmptySpace
);
1945 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1949 // -----------------------------------------------------------------------
1951 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1952 const wxPGProperty
* firstItem
,
1953 const wxPGProperty
* lastItem
,
1954 const wxRect
* clipRect
,
1955 bool isBuffered
) const
1957 // TODO: This should somehow be eliminated.
1958 wxRect tempClipRect
;
1961 wxASSERT(firstItem
);
1963 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1964 clipRect
= &tempClipRect
;
1968 firstItem
= DoGetItemAtY(clipRect
->y
);
1972 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1974 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1977 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1980 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1981 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1983 int lh
= m_lineHeight
;
1986 int lastItemBottomY
;
1988 firstItemTopY
= clipRect
->y
;
1989 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1991 // Align y coordinates to item boundaries
1992 firstItemTopY
-= firstItemTopY
% lh
;
1993 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1994 lastItemBottomY
-= 1;
1996 // Entire range outside scrolled, visible area?
1997 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
2000 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
2004 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
2005 firstItem->GetLabel().c_str(),
2006 lastItem->GetLabel().c_str(),
2007 (int)(lastItemBottomY - firstItemTopY),
2009 (unsigned long)clipRect );
2014 long windowStyle
= m_windowStyle
;
2020 // With wxPG_DOUBLE_BUFFER, do double buffering
2021 // - buffer's y = 0, so align cliprect and coordinates to that
2023 #if wxPG_DOUBLE_BUFFER
2029 xRelMod
= clipRect
->x
;
2030 yRelMod
= clipRect
->y
;
2033 // clipRect conversion
2041 firstItemTopY
-= yRelMod
;
2042 lastItemBottomY
-= yRelMod
;
2045 wxUnusedVar(isBuffered
);
2048 int x
= m_marginWidth
- xRelMod
;
2050 const wxFont
& normalfont
= m_font
;
2052 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
2054 bool isEnabled
= IsEnabled();
2057 // Prepare some pens and brushes that are often changed to.
2060 wxBrush
marginBrush(m_colMargin
);
2061 wxPen
marginPen(m_colMargin
);
2062 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2063 wxPen
linepen(m_colLine
,1,wxSOLID
);
2065 // pen that has same colour as text
2066 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2069 // Clear margin with background colour
2071 dc
.SetBrush( marginBrush
);
2072 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2074 dc
.SetPen( *wxTRANSPARENT_PEN
);
2075 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2078 const wxPGProperty
* selected
= m_selected
;
2079 const wxPropertyGridPageState
* state
= m_pState
;
2081 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2082 bool wasSelectedPainted
= false;
2085 // TODO: Only render columns that are within clipping region.
2087 dc
.SetFont(normalfont
);
2089 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2090 int endScanBottomY
= lastItemBottomY
+ lh
;
2091 int y
= firstItemTopY
;
2092 unsigned int arrInd
= 0;
2094 for ( ; !it
.AtEnd(); it
.Next() )
2096 const wxPGProperty
* p
= *it
;
2098 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2100 m_visPropArray
[arrInd
] = (wxPGProperty
*)p
;
2103 if ( y
> endScanBottomY
)
2110 m_visPropArray
[arrInd
] = NULL
;
2112 int gridWidth
= state
->m_width
;
2116 m_visPropArray
[arrInd
] != NULL
&& y
<= lastItemBottomY
;
2119 wxPGProperty
* p
=(wxPGProperty
*) m_visPropArray
[arrInd
];
2120 wxPGProperty
* nextP
= (wxPGProperty
*) m_visPropArray
[arrInd
+1];
2122 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2123 int textMarginHere
= x
;
2124 int renderFlags
= wxPGCellRenderer::Control
;
2126 int greyDepth
= m_marginWidth
;
2127 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2128 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2130 int greyDepthX
= greyDepth
- xRelMod
;
2132 // Use basic depth if in non-categoric mode and parent is base array.
2133 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2135 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2138 // Paint margin area
2139 dc
.SetBrush(marginBrush
);
2140 dc
.SetPen(marginPen
);
2141 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2143 dc
.SetPen( linepen
);
2148 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2154 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2156 sx
+= state
->m_colWidths
[si
];
2157 dc
.DrawLine( sx
, y
, sx
, y2
);
2160 // Horizontal Line, below
2161 // (not if both this and next is category caption)
2162 if ( p
->IsCategory() &&
2163 nextP
&& nextP
->IsCategory() )
2164 dc
.SetPen(m_colCapBack
);
2166 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2168 if ( p
== selected
)
2170 renderFlags
|= wxPGCellRenderer::Selected
;
2171 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2172 wasSelectedPainted
= true;
2180 if ( p
->IsCategory() )
2182 if ( p
->m_fgColIndex
== 0 )
2183 rowFgCol
= m_colCapFore
;
2185 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2186 rowBgBrush
= wxBrush(m_colCapBack
);
2188 else if ( p
!= selected
)
2190 // Disabled may get different colour.
2191 if ( !p
->IsEnabled() )
2192 rowFgCol
= m_colDisPropFore
;
2194 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2196 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2200 // Selected gets different colour.
2201 if ( reallyFocused
)
2203 rowFgCol
= m_colSelFore
;
2204 rowBgBrush
= wxBrush(m_colSelBack
);
2206 else if ( isEnabled
)
2208 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2209 rowBgBrush
= marginBrush
;
2213 rowFgCol
= m_colDisPropFore
;
2214 rowBgBrush
= wxBrush(m_colSelBack
);
2218 bool fontChanged
= false;
2220 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2225 if ( p
->IsCategory() )
2227 // Captions are all cells merged as one
2228 dc
.SetFont(m_captionFont
);
2230 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2232 dc
.SetBrush(rowBgBrush
);
2233 dc
.SetPen(rowBgBrush
.GetColour());
2234 dc
.SetTextForeground(rowFgCol
);
2236 dc
.DrawRectangle(cellRect
);
2239 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2240 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2243 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2244 DrawExpanderButton( dc
, butRect
, p
);
2248 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2250 dc
.SetFont(m_captionFont
);
2256 int nextCellWidth
= state
->m_colWidths
[0];
2257 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2258 int textXAdd
= textMarginHere
- greyDepthX
;
2260 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2262 cellRect
.width
= nextCellWidth
- 1;
2264 bool ctrlCell
= false;
2267 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2269 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2270 dc
.SetBrush(editorBgCol
);
2271 dc
.SetPen(editorBgCol
);
2272 dc
.SetTextForeground(m_colPropFore
);
2274 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2279 dc
.SetBrush(rowBgBrush
);
2280 dc
.SetPen(rowBgBrush
.GetColour());
2281 dc
.SetTextForeground(rowFgCol
);
2284 dc
.DrawRectangle(cellRect
);
2287 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2288 DrawExpanderButton( dc
, butRect
, p
);
2290 dc
.SetClippingRegion(cellRect
);
2292 cellRect
.x
+= textXAdd
;
2293 cellRect
.width
-= textXAdd
;
2298 wxPGCellRenderer
* renderer
;
2299 int cmnVal
= p
->GetCommonValue();
2300 if ( cmnVal
== -1 || ci
!= 1 )
2302 renderer
= p
->GetCellRenderer(ci
);
2303 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2307 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2308 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2312 cellX
+= state
->m_colWidths
[ci
];
2313 if ( ci
< (state
->m_colWidths
.size()-1) )
2314 nextCellWidth
= state
->m_colWidths
[ci
+1];
2316 dc
.DestroyClippingRegion(); // Is this really necessary?
2322 dc
.SetFont(normalfont
);
2327 // Refresh editor controls (seems not needed on msw)
2328 // NOTE: This code is mandatory for GTK!
2329 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2330 if ( wasSelectedPainted
)
2333 m_wndEditor
->Refresh();
2335 m_wndEditor2
->Refresh();
2342 // -----------------------------------------------------------------------
2344 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2348 if ( m_width
< 10 || m_height
< 10 ||
2349 !m_pState
->m_properties
->GetChildCount() ||
2350 p1
== (wxPGProperty
*) NULL
)
2351 return wxRect(0,0,0,0);
2356 // Return rect which encloses the given property range
2358 int visTop
= p1
->GetY();
2361 visBottom
= p2
->GetY() + m_lineHeight
;
2363 visBottom
= m_height
+ visTop
;
2365 // If seleced property is inside the range, we'll extend the range to include
2367 wxPGProperty
* selected
= m_selected
;
2370 int selectedY
= selected
->GetY();
2371 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2373 wxWindow
* editor
= GetEditorControl();
2376 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2377 if ( visBottom2
> visBottom
)
2378 visBottom
= visBottom2
;
2383 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2386 // -----------------------------------------------------------------------
2388 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2393 if ( m_pState
->m_itemsAdded
)
2394 PrepareAfterItemsAdded();
2396 wxRect r
= GetPropertyRect(p1
, p2
);
2399 m_canvas
->RefreshRect(r
);
2403 // -----------------------------------------------------------------------
2405 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2407 if ( p
== m_selected
)
2408 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2410 DrawItemAndChildren(p
);
2413 // -----------------------------------------------------------------------
2415 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2420 // Draw item, children, and parent too, if it is not category
2421 wxPGProperty
* parent
= p
->GetParent();
2424 !parent
->IsCategory() &&
2425 parent
->GetParent() )
2428 parent
= parent
->GetParent();
2431 DrawItemAndChildren(p
);
2434 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2436 wxCHECK_RET( p
, wxT("invalid property id") );
2438 // Do not draw if in non-visible page
2439 if ( p
->GetParentState() != m_pState
)
2442 // do not draw a single item if multiple pending
2443 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2446 wxWindow
* wndPrimary
= GetEditorControl();
2448 // Update child control.
2449 if ( m_selected
&& m_selected
->GetParent() == p
)
2450 m_selected
->UpdateControl(wndPrimary
);
2452 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2454 DrawItems(p
, lastDrawn
);
2457 // -----------------------------------------------------------------------
2459 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2460 const wxRect
*rect
)
2462 PrepareAfterItemsAdded();
2464 wxWindow::Refresh(false);
2466 // TODO: Coordinate translation
2467 m_canvas
->Refresh(false, rect
);
2469 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2470 // I think this really helps only GTK+1.2
2471 if ( m_wndEditor
) m_wndEditor
->Refresh();
2472 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2476 // -----------------------------------------------------------------------
2477 // wxPropertyGrid global operations
2478 // -----------------------------------------------------------------------
2480 void wxPropertyGrid::Clear()
2484 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2485 wxPG_CHECK_RET_DBG( selRes
,
2486 wxT("failed to deselect a property (editor probably had invalid value)") );
2489 m_pState
->DoClear();
2495 RecalculateVirtualSize();
2497 // Need to clear some area at the end
2499 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2502 // -----------------------------------------------------------------------
2504 bool wxPropertyGrid::EnableCategories( bool enable
)
2506 if ( !ClearSelection() )
2512 // Enable categories
2515 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2520 // Disable categories
2522 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2525 if ( !m_pState
->EnableCategories(enable
) )
2530 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2532 m_pState
->m_itemsAdded
= 1; // force
2533 PrepareAfterItemsAdded();
2537 m_pState
->m_itemsAdded
= 1;
2539 // No need for RecalculateVirtualSize() here - it is already called in
2540 // wxPropertyGridPageState method above.
2547 // -----------------------------------------------------------------------
2549 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2551 wxASSERT( pNewState
);
2552 wxASSERT( pNewState
->GetGrid() );
2554 if ( pNewState
== m_pState
)
2557 wxPGProperty
* oldSelection
= m_selected
;
2562 bool selRes
= ClearSelection();
2563 wxPG_CHECK_RET_DBG( selRes
,
2564 wxT("failed to deselect a property (editor probably had invalid value)") );
2567 m_pState
->m_selected
= oldSelection
;
2569 bool orig_mode
= m_pState
->IsInNonCatMode();
2570 bool new_state_mode
= pNewState
->IsInNonCatMode();
2572 m_pState
= pNewState
;
2575 int pgWidth
= GetClientSize().x
;
2576 if ( HasVirtualWidth() )
2578 int minWidth
= pgWidth
;
2579 if ( pNewState
->m_width
< minWidth
)
2581 pNewState
->m_width
= minWidth
;
2582 pNewState
->CheckColumnWidths();
2588 // Just in case, fully re-center splitter
2589 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2590 pNewState
->m_fSplitterX
= -1.0;
2592 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2595 m_propHover
= (wxPGProperty
*) NULL
;
2597 // If necessary, convert state to correct mode.
2598 if ( orig_mode
!= new_state_mode
)
2600 // This should refresh as well.
2601 EnableCategories( orig_mode
?false:true );
2603 else if ( !m_frozen
)
2605 // Refresh, if not frozen.
2606 if ( m_pState
->m_itemsAdded
)
2607 PrepareAfterItemsAdded();
2610 if ( m_pState
->m_selected
)
2611 DoSelectProperty( m_pState
->m_selected
);
2613 RecalculateVirtualSize(0);
2617 m_pState
->m_itemsAdded
= 1;
2620 // -----------------------------------------------------------------------
2622 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2624 wxPG_PROP_ARG_CALL_PROLOG()
2626 m_pState
->SortChildren( p
);
2629 // -----------------------------------------------------------------------
2631 void wxPropertyGrid::Sort()
2633 bool selRes
= ClearSelection(); // This must be before state clear
2634 wxPG_CHECK_RET_DBG( selRes
,
2635 wxT("failed to deselect a property (editor probably had invalid value)") );
2640 // -----------------------------------------------------------------------
2642 // Call to SetSplitterPosition will always disable splitter auto-centering
2643 // if parent window is shown.
2644 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2646 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2649 wxPropertyGridPageState
* state
= m_pState
;
2651 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2656 CorrectEditorWidgetSizeX();
2662 // -----------------------------------------------------------------------
2664 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2666 SetSplitterPosition( m_width
/2, true );
2667 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2668 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2671 // -----------------------------------------------------------------------
2672 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2673 // -----------------------------------------------------------------------
2675 // Returns nearest paint visible property (such that will be painted unless
2676 // window is scrolled or resized). If given property is paint visible, then
2677 // it itself will be returned
2678 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2680 int vx
,vy1
;// Top left corner of client
2681 GetViewStart(&vx
,&vy1
);
2682 vy1
*= wxPG_PIXELS_PER_UNIT
;
2684 int vy2
= vy1
+ m_height
;
2685 int propY
= p
->GetY2(m_lineHeight
);
2687 if ( (propY
+ m_lineHeight
) < vy1
)
2690 return DoGetItemAtY( vy1
);
2692 else if ( propY
> vy2
)
2695 return DoGetItemAtY( vy2
);
2698 // Itself paint visible
2703 // -----------------------------------------------------------------------
2705 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2709 m_pushButKeyCode
= keycode
;
2710 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2711 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2715 m_pushButKeyCode
= WXK_DOWN
;
2716 m_pushButKeyCodeNeedsCtrl
= 0;
2717 m_pushButKeyCodeNeedsAlt
= 1;
2721 // -----------------------------------------------------------------------
2722 // Methods related to change in value, value modification and sending events
2723 // -----------------------------------------------------------------------
2725 // commits any changes in editor of selected property
2726 // return true if validation did not fail
2727 // flags are same as with DoSelectProperty
2728 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2730 // Committing already?
2731 if ( m_inCommitChangesFromEditor
)
2734 // Don't do this if already processing editor event. It might
2735 // induce recursive dialogs and crap like that.
2736 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2738 if ( m_inDoPropertyChanged
)
2745 IsEditorsValueModified() &&
2746 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2749 m_inCommitChangesFromEditor
= 1;
2751 wxVariant
variant(m_selected
->GetValueRef());
2752 bool valueIsPending
= false;
2754 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2755 // due to another window getting focus
2756 wxWindow
* oldFocus
= m_curFocused
;
2758 bool validationFailure
= false;
2759 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2761 m_chgInfo_changedProperty
= NULL
;
2763 // If truly modified, schedule value as pending.
2764 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2766 if ( DoEditorValidate() &&
2767 PerformValidation(m_selected
, variant
) )
2769 valueIsPending
= true;
2773 validationFailure
= true;
2778 EditorsValueWasNotModified();
2783 m_inCommitChangesFromEditor
= 0;
2785 if ( validationFailure
&& !forceSuccess
)
2789 oldFocus
->SetFocus();
2790 m_curFocused
= oldFocus
;
2793 res
= OnValidationFailure(m_selected
, variant
);
2795 // Now prevent further validation failure messages
2798 EditorsValueWasNotModified();
2799 OnValidationFailureReset(m_selected
);
2802 else if ( valueIsPending
)
2804 DoPropertyChanged( m_selected
, flags
);
2805 EditorsValueWasNotModified();
2814 // -----------------------------------------------------------------------
2816 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2819 // Runs all validation functionality.
2820 // Returns true if value passes all tests.
2823 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2825 if ( !wxPGIsVariantType(pendingValue
, list
) )
2827 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2832 // Adapt list to child values, if necessary
2833 wxVariant listValue
= pendingValue
;
2834 wxVariant
* pPendingValue
= &pendingValue
;
2835 wxVariant
* pList
= NULL
;
2837 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2838 // string value, then we need treat as it was changed instead
2839 // (or, in addition, as is the case with composite string parent).
2840 // This includes creating list variant for child values.
2842 wxPGProperty
* pwc
= p
->GetParent();
2843 wxPGProperty
* changedProperty
= p
;
2844 wxPGProperty
* baseChangedProperty
= changedProperty
;
2845 wxVariant bcpPendingList
;
2847 listValue
= pendingValue
;
2848 listValue
.SetName(p
->GetLabel());
2851 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2853 wxVariantList tempList
;
2854 wxVariant
lv(tempList
, pwc
->GetLabel());
2855 lv
.Append(listValue
);
2857 pPendingValue
= &listValue
;
2859 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2861 baseChangedProperty
= pwc
;
2862 bcpPendingList
= lv
;
2865 changedProperty
= pwc
;
2866 pwc
= pwc
->GetParent();
2870 wxPGProperty
* evtChangingProperty
= changedProperty
;
2872 if ( !wxPGIsVariantType(*pPendingValue
, list
) )
2874 value
= *pPendingValue
;
2878 // Convert list to child values
2879 pList
= pPendingValue
;
2880 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2883 wxVariant evtChangingValue
= value
;
2885 // FIXME: After proper ValueToString()s added, remove
2886 // this. It is just a temporary fix, as evt_changing
2887 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2888 // (unless it is selected, and textctrl editor is open).
2889 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2891 evtChangingProperty
= baseChangedProperty
;
2892 if ( evtChangingProperty
!= p
)
2894 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2898 evtChangingValue
= pendingValue
;
2902 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2904 if ( changedProperty
== m_selected
)
2906 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2907 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2911 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2915 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2916 m_chgInfo_changedProperty
= changedProperty
;
2917 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2918 m_chgInfo_pendingValue
= value
;
2921 m_chgInfo_valueList
= *pList
;
2923 m_chgInfo_valueList
.MakeNull();
2925 // If changedProperty is not property which value was edited,
2926 // then call wxPGProperty::ValidateValue() for that as well.
2927 if ( p
!= changedProperty
&& !wxPGIsVariantType(value
, list
) )
2929 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2933 // SendEvent returns true if event was vetoed
2934 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2940 // -----------------------------------------------------------------------
2942 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2944 if ( !msg
.length() )
2948 if ( !wxPGGlobalVars
->m_offline
)
2950 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2953 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2956 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2959 pStatusBar
->SetStatusText(msg
);
2967 ::wxMessageBox(msg
, _T("Property Error"));
2970 // -----------------------------------------------------------------------
2972 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2974 int vfb
= m_validationInfo
.m_failureBehavior
;
2976 if ( vfb
& wxPG_VFB_BEEP
)
2979 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2980 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2982 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2983 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2985 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2987 wxColour vfbFg
= *wxWHITE
;
2988 wxColour vfbBg
= *wxRED
;
2989 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2990 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2992 DrawItemAndChildren(property
);
2994 if ( property
== m_selected
)
2996 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2998 wxWindow
* editor
= GetEditorControl();
3001 editor
->SetForegroundColour(vfbFg
);
3002 editor
->SetBackgroundColour(vfbBg
);
3008 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3010 wxString msg
= m_validationInfo
.m_failureMessage
;
3012 if ( !msg
.length() )
3013 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
3015 DoShowPropertyError(property
, msg
);
3018 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3021 // -----------------------------------------------------------------------
3023 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3025 int vfb
= m_validationInfo
.m_failureBehavior
;
3027 if ( vfb
& wxPG_VFB_MARK_CELL
)
3029 property
->SetCell(0, NULL
);
3030 property
->SetCell(1, NULL
);
3032 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3034 if ( property
== m_selected
&& GetEditorControl() )
3036 // Calling this will recreate the control, thus resetting its colour
3037 RefreshProperty(property
);
3041 DrawItemAndChildren(property
);
3046 // -----------------------------------------------------------------------
3048 // flags are same as with DoSelectProperty
3049 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3051 if ( m_inDoPropertyChanged
)
3054 m_pState
->m_anyModified
= 1;
3056 m_inDoPropertyChanged
= 1;
3058 // Maybe need to update control
3059 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3061 // These values were calculated in PerformValidation()
3062 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3063 wxVariant value
= m_chgInfo_pendingValue
;
3065 wxPGProperty
* topPaintedProperty
= changedProperty
;
3067 while ( !topPaintedProperty
->IsCategory() &&
3068 !topPaintedProperty
->IsRoot() )
3070 topPaintedProperty
= topPaintedProperty
->GetParent();
3073 changedProperty
->SetValue(value
, &m_chgInfo_valueList
);
3075 // Set as Modified (not if dragging just began)
3076 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3078 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3079 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3082 SetCurControlBoldFont();
3088 // Propagate updates to parent(s)
3090 wxPGProperty
* prevPwc
= NULL
;
3092 while ( prevPwc
!= topPaintedProperty
)
3094 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3096 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3099 SetCurControlBoldFont();
3103 pwc
= pwc
->GetParent();
3106 // Draw the actual property
3107 DrawItemAndChildren( topPaintedProperty
);
3110 // If value was set by wxPGProperty::OnEvent, then update the editor
3112 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3115 p
->GetEditorClass()->UpdateControl(p
, m_wndEditor
);
3119 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3120 if ( m_wndEditor
) m_wndEditor
->Refresh();
3121 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3126 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3128 // If top parent has composite string value, then send to child parents,
3129 // starting from baseChangedProperty.
3130 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3132 pwc
= m_chgInfo_baseChangedProperty
;
3134 while ( pwc
!= changedProperty
)
3136 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3137 pwc
= pwc
->GetParent();
3141 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3143 m_inDoPropertyChanged
= 0;
3148 // -----------------------------------------------------------------------
3150 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3152 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3154 m_chgInfo_changedProperty
= NULL
;
3156 if ( PerformValidation(p
, newValue
) )
3158 DoPropertyChanged(p
);
3163 OnValidationFailure(p
, newValue
);
3169 // -----------------------------------------------------------------------
3171 // Runs wxValidator for the selected property
3172 bool wxPropertyGrid::DoEditorValidate()
3174 #if wxUSE_VALIDATORS
3175 // With traditional validator style, we dont need to more
3176 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3179 if ( m_iFlags
& wxPG_FL_VALIDATION_FAILED
)
3184 wxWindow
* wnd
= GetEditorControl();
3186 wxValidator
* validator
= m_selected
->GetValidator();
3187 if ( validator
&& wnd
)
3189 // Use TextCtrl of ODComboBox instead
3190 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3192 wnd
= ((wxOwnerDrawnComboBox
*)wnd
)->GetTextCtrl();
3198 validator
->SetWindow(wnd
);
3200 // Instead setting the flag after the failure, we set
3201 // it before checking and then clear afterwards if things
3202 // went fine. This trick is necessary since focus events
3203 // may be triggered while in Validate.
3204 m_iFlags
|= wxPG_FL_VALIDATION_FAILED
;
3205 if ( !validator
->Validate(this) )
3207 // If you dpm't want to display message multiple times per change,
3208 // comment the following line.
3209 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3212 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3218 // -----------------------------------------------------------------------
3220 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3222 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3223 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3225 wxWindow
* parent
= wnd
->GetParent();
3228 (parent
== m_canvas
||
3229 parent
->GetParent() == m_canvas
) )
3231 OnCustomEditorEvent((wxCommandEvent
&)event
);
3235 return wxPanel::ProcessEvent(event
);
3238 // -----------------------------------------------------------------------
3240 // NB: It may really not be wxCommandEvent - must check if necessary
3242 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3244 wxPGProperty
* selected
= m_selected
;
3247 // Somehow, event is handled after property has been deselected.
3248 // Possibly, but very rare.
3252 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3255 wxVariant
pendingValue(selected
->GetValueRef());
3256 wxWindow
* wnd
= GetEditorControl();
3258 bool wasUnspecified
= selected
->IsValueUnspecified();
3259 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3261 bool valueIsPending
= false;
3263 m_chgInfo_changedProperty
= NULL
;
3265 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3268 // Filter out excess wxTextCtrl modified events
3269 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3271 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3273 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3275 wxString newTcValue
= tc
->GetValue();
3276 if ( m_prevTcValue
== newTcValue
)
3279 m_prevTcValue
= newTcValue
;
3282 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3284 bool validationFailure
= false;
3285 bool buttonWasHandled
= false;
3288 // Try common button handling
3289 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3291 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3295 buttonWasHandled
= true;
3296 // Store as res2, as previously (and still currently alternatively)
3297 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3298 // in wxPGProperty::OnEvent().
3299 adapter
->ShowDialog( this, selected
);
3304 if ( !buttonWasHandled
)
3306 // First call editor class' event handler.
3307 const wxPGEditor
* editor
= selected
->GetEditorClass();
3309 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3311 // If changes, validate them
3312 if ( DoEditorValidate() )
3314 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3315 valueIsPending
= true;
3319 validationFailure
= true;
3323 // Then the property's custom handler (must be always called, unless
3324 // validation failed).
3325 if ( !validationFailure
)
3326 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3329 // SetValueInEvent(), as called in one of the functions referred above
3330 // overrides editor's value.
3331 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3333 valueIsPending
= true;
3334 pendingValue
= m_changeInEventValue
;
3335 selFlags
|= wxPG_SEL_DIALOGVAL
;
3338 if ( !validationFailure
&& valueIsPending
)
3339 if ( !PerformValidation(m_selected
, pendingValue
) )
3340 validationFailure
= true;
3342 if ( validationFailure
)
3344 OnValidationFailure(selected
, pendingValue
);
3346 else if ( valueIsPending
)
3348 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3350 DoPropertyChanged(selected
, selFlags
);
3351 EditorsValueWasNotModified();
3355 // No value after all
3357 // Let unhandled button click events go to the parent
3358 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3360 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3361 GetEventHandler()->AddPendingEvent(evt
);
3365 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3368 // -----------------------------------------------------------------------
3369 // wxPropertyGrid editor control helper methods
3370 // -----------------------------------------------------------------------
3372 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3374 int itemy
= p
->GetY2(m_lineHeight
);
3376 int cust_img_space
= 0;
3377 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3378 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3380 // TODO: If custom image detection changes from current, change this.
3381 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3383 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3384 int imwid
= p
->OnMeasureImage().x
;
3385 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3386 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3391 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3393 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3398 // -----------------------------------------------------------------------
3400 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3402 wxSize sz
= GetImageSize(p
, item
);
3403 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3404 wxPG_CUSTOM_IMAGE_SPACINGY
,
3409 // return size of custom paint image
3410 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3412 // If called with NULL property, then return default image
3413 // size for properties that use image.
3415 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3417 wxSize cis
= p
->OnMeasureImage(item
);
3419 int choiceCount
= p
->GetChoiceCount();
3420 int comVals
= p
->GetDisplayedCommonValueCount();
3421 if ( item
>= choiceCount
&& comVals
> 0 )
3423 unsigned int cvi
= item
-choiceCount
;
3424 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3426 else if ( item
>= 0 && choiceCount
== 0 )
3427 return wxSize(0, 0);
3432 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3437 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3444 // -----------------------------------------------------------------------
3446 // takes scrolling into account
3447 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3450 GetViewStart(&vx
,&vy
);
3451 vy
*=wxPG_PIXELS_PER_UNIT
;
3452 vx
*=wxPG_PIXELS_PER_UNIT
;
3455 ClientToScreen( px
, py
);
3458 // -----------------------------------------------------------------------
3460 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3463 GetViewStart(&pt2
.x
,&pt2
.y
);
3464 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3465 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3469 return m_pState
->HitTest(pt2
);
3472 // -----------------------------------------------------------------------
3474 // custom set cursor
3475 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3477 if ( type
== m_curcursor
&& !override
) return;
3479 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3481 if ( type
== wxCURSOR_SIZEWE
)
3482 cursor
= m_cursorSizeWE
;
3484 m_canvas
->SetCursor( *cursor
);
3489 // -----------------------------------------------------------------------
3490 // wxPropertyGrid property selection
3491 // -----------------------------------------------------------------------
3493 #define CONNECT_CHILD(EVT,FUNCTYPE,FUNC) \
3494 wnd->Connect(id, EVT, \
3495 (wxObjectEventFunction) (wxEventFunction) \
3496 FUNCTYPE (&wxPropertyGrid::FUNC), \
3499 // Setups event handling for child control
3500 void wxPropertyGrid::SetupEventHandling( wxWindow
* argWnd
, int id
)
3502 wxWindow
* wnd
= argWnd
;
3504 if ( argWnd
== m_wndEditor
)
3506 CONNECT_CHILD(wxEVT_MOTION
,(wxMouseEventFunction
),OnMouseMoveChild
)
3507 CONNECT_CHILD(wxEVT_LEFT_UP
,(wxMouseEventFunction
),OnMouseUpChild
)
3508 CONNECT_CHILD(wxEVT_LEFT_DOWN
,(wxMouseEventFunction
),OnMouseClickChild
)
3509 CONNECT_CHILD(wxEVT_RIGHT_UP
,(wxMouseEventFunction
),OnMouseRightClickChild
)
3510 CONNECT_CHILD(wxEVT_ENTER_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3511 CONNECT_CHILD(wxEVT_LEAVE_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3515 CONNECT_CHILD(wxEVT_NAVIGATION_KEY
,(wxNavigationKeyEventFunction
),OnNavigationKey
)
3517 CONNECT_CHILD(wxEVT_KEY_DOWN
,(wxCharEventFunction
),OnChildKeyDown
)
3518 CONNECT_CHILD(wxEVT_KEY_UP
,(wxCharEventFunction
),OnChildKeyUp
)
3519 CONNECT_CHILD(wxEVT_KILL_FOCUS
,(wxFocusEventFunction
),OnFocusEvent
)
3522 void wxPropertyGrid::FreeEditors()
3524 // Do not free editors immediately if processing events
3525 if ( !m_windowsToDelete
)
3526 m_windowsToDelete
= new wxArrayPtrVoid
;
3530 m_windowsToDelete
->push_back(m_wndEditor2
);
3531 m_wndEditor2
->Hide();
3532 m_wndEditor2
= (wxWindow
*) NULL
;
3537 m_windowsToDelete
->push_back(m_wndEditor
);
3538 m_wndEditor
->Hide();
3539 m_wndEditor
= (wxWindow
*) NULL
;
3543 // Call with NULL to de-select property
3544 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3548 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3549 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3551 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3554 if ( m_inDoSelectProperty
)
3557 m_inDoSelectProperty
= 1;
3559 wxPGProperty
* prev
= m_selected
;
3562 // Delete windows pending for deletion
3563 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3567 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3568 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3570 m_windowsToDelete
->clear();
3575 m_inDoSelectProperty
= 0;
3580 // If we are frozen, then just set the values.
3583 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3584 m_editorFocused
= 0;
3587 m_pState
->m_selected
= p
;
3589 // If frozen, always free controls. But don't worry, as Thaw will
3590 // recall SelectProperty to recreate them.
3593 // Prevent any further selection measures in this call
3594 p
= (wxPGProperty
*) NULL
;
3599 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3601 // Only set focus if not deselecting
3604 if ( flags
& wxPG_SEL_FOCUS
)
3608 m_wndEditor
->SetFocus();
3609 m_editorFocused
= 1;
3614 wxScrolledWindow::SetFocus();
3615 m_editorFocused
= 0;
3619 m_inDoSelectProperty
= 0;
3624 // First, deactivate previous
3628 OnValidationFailureReset(m_selected
);
3630 // Must double-check if this is an selected in case of forceswitch
3633 if ( !CommitChangesFromEditor(flags
) )
3635 // Validation has failed, so we can't exit the previous editor
3636 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3637 // _("Invalid Value"),wxOK|wxICON_ERROR);
3638 m_inDoSelectProperty
= 0;
3646 m_selected
= (wxPGProperty
*) NULL
;
3647 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3649 // We need to always fully refresh the grid here
3652 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3653 EditorsValueWasNotModified();
3656 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3659 // Then, activate the one given.
3662 int propY
= p
->GetY2(m_lineHeight
);
3664 int splitterX
= GetSplitterPosition();
3665 m_editorFocused
= 0;
3667 m_pState
->m_selected
= p
;
3668 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3670 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3672 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3674 // Do we need OnMeasureCalls?
3675 wxSize imsz
= p
->OnMeasureImage();
3678 // Only create editor for non-disabled non-caption
3679 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3681 // do this for non-caption items
3685 // Do we need to paint the custom image, if any?
3686 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3687 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3688 !p
->GetEditorClass()->CanContainCustomImage()
3690 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3692 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3693 wxPoint goodPos
= grect
.GetPosition();
3694 #if wxPG_CREATE_CONTROLS_HIDDEN
3695 int coord_adjust
= m_height
- goodPos
.y
;
3696 goodPos
.y
+= coord_adjust
;
3699 const wxPGEditor
* editor
= p
->GetEditorClass();
3700 wxCHECK_MSG(editor
, false,
3701 wxT("NULL editor class not allowed"));
3703 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3705 wxPGWindowList wndList
= editor
->CreateControls(this,
3710 m_wndEditor
= wndList
.m_primary
;
3711 m_wndEditor2
= wndList
.m_secondary
;
3713 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3714 // value is drawn as normal, and m_wndEditor2 is assumed
3715 // to be a right-aligned button that triggers a separate editor
3720 wxASSERT_MSG( m_wndEditor
->GetParent() == m_canvas
,
3721 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3723 // Set validator, if any
3724 #if wxUSE_VALIDATORS
3725 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3727 wxValidator
* validator
= p
->GetValidator();
3729 m_wndEditor
->SetValidator(*validator
);
3733 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3734 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3736 // If it has modified status, use bold font
3737 // (must be done before capturing m_ctrlXAdjust)
3738 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3739 SetCurControlBoldFont();
3742 // Fix TextCtrl indentation
3743 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3744 wxTextCtrl
* tc
= NULL
;
3745 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3746 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3748 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3750 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3753 // Store x relative to splitter (we'll need it).
3754 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3756 // Check if background clear is not necessary
3757 wxPoint pos
= m_wndEditor
->GetPosition();
3758 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3760 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3763 m_wndEditor
->SetSizeHints(3, 3);
3765 #if wxPG_CREATE_CONTROLS_HIDDEN
3766 m_wndEditor
->Show(false);
3767 m_wndEditor
->Freeze();
3769 goodPos
= m_wndEditor
->GetPosition();
3770 goodPos
.y
-= coord_adjust
;
3771 m_wndEditor
->Move( goodPos
);
3774 wxWindow
* primaryCtrl
= GetEditorControl();
3775 SetupEventHandling(primaryCtrl
, wxPG_SUBID1
);
3777 // Focus and select all (wxTextCtrl, wxComboBox etc)
3778 if ( flags
& wxPG_SEL_FOCUS
)
3780 primaryCtrl
->SetFocus();
3782 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3788 wxASSERT_MSG( m_wndEditor2
->GetParent() == m_canvas
,
3789 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3791 // Get proper id for wndSecondary
3792 m_wndSecId
= m_wndEditor2
->GetId();
3793 wxWindowList children
= m_wndEditor2
->GetChildren();
3794 wxWindowList::iterator node
= children
.begin();
3795 if ( node
!= children
.end() )
3796 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3798 m_wndEditor2
->SetSizeHints(3,3);
3800 #if wxPG_CREATE_CONTROLS_HIDDEN
3801 wxRect sec_rect
= m_wndEditor2
->GetRect();
3802 sec_rect
.y
-= coord_adjust
;
3804 // Fine tuning required to fix "oversized"
3805 // button disappearance bug.
3806 if ( sec_rect
.y
< 0 )
3808 sec_rect
.height
+= sec_rect
.y
;
3811 m_wndEditor2
->SetSize( sec_rect
);
3813 m_wndEditor2
->Show();
3815 SetupEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3817 // If no primary editor, focus to button to allow
3818 // it to interprete ENTER etc.
3819 // NOTE: Due to problems focusing away from it, this
3820 // has been disabled.
3822 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3823 m_wndEditor2->SetFocus();
3827 if ( flags
& wxPG_SEL_FOCUS
)
3828 m_editorFocused
= 1;
3833 // wxGTK atleast seems to need this (wxMSW not)
3837 EditorsValueWasNotModified();
3839 // If it's inside collapsed section, expand parent, scroll, etc.
3840 // Also, if it was partially visible, scroll it into view.
3841 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3846 #if wxPG_CREATE_CONTROLS_HIDDEN
3847 m_wndEditor
->Thaw();
3849 m_wndEditor
->Show(true);
3855 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3861 // Show help text in status bar.
3862 // (if found and grid not embedded in manager with help box and
3863 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3866 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3868 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3869 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3871 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3873 statusbar
= frame
->GetStatusBar();
3878 const wxString
* pHelpString
= (const wxString
*) NULL
;
3882 pHelpString
= &p
->GetHelpString();
3883 if ( pHelpString
->length() )
3885 // Set help box text.
3886 statusbar
->SetStatusText( *pHelpString
);
3887 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3891 if ( (!pHelpString
|| !pHelpString
->length()) &&
3892 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3894 // Clear help box - but only if it was written
3895 // by us at previous time.
3896 statusbar
->SetStatusText( m_emptyString
);
3897 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3903 m_inDoSelectProperty
= 0;
3905 // call wx event handler (here so that it also occurs on deselection)
3906 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3911 // -----------------------------------------------------------------------
3913 bool wxPropertyGrid::UnfocusEditor()
3915 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3918 if ( !CommitChangesFromEditor(0) )
3921 m_canvas
->SetFocusIgnoringChildren();
3922 DrawItem(m_selected
);
3927 // -----------------------------------------------------------------------
3929 // This method is not inline because it called dozens of times
3930 // (i.e. two-arg function calls create smaller code size).
3931 bool wxPropertyGrid::DoClearSelection()
3933 return DoSelectProperty((wxPGProperty
*)NULL
);
3936 // -----------------------------------------------------------------------
3937 // wxPropertyGrid expand/collapse state
3938 // -----------------------------------------------------------------------
3940 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3942 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3944 // If active editor was inside collapsed section, then disable it
3945 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3947 if ( !ClearSelection() )
3951 // Store dont-center-splitter flag 'cause we need to temporarily set it
3952 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3953 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3955 bool res
= m_pState
->DoCollapse(pwc
);
3960 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3962 RecalculateVirtualSize();
3964 // Redraw etc. only if collapsed was visible.
3965 if (pwc
->IsVisible() &&
3967 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3969 // When item is collapsed so that scrollbar would move,
3970 // graphics mess is about (unless we redraw everything).
3975 // Clear dont-center-splitter flag if it wasn't set
3976 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3981 // -----------------------------------------------------------------------
3983 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3985 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3987 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3989 // Store dont-center-splitter flag 'cause we need to temporarily set it
3990 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3991 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3993 bool res
= m_pState
->DoExpand(pwc
);
3998 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4000 RecalculateVirtualSize();
4002 // Redraw etc. only if expanded was visible.
4003 if ( pwc
->IsVisible() && !m_frozen
&&
4004 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
4008 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4011 DrawItems(pwc
, NULL
);
4016 // Clear dont-center-splitter flag if it wasn't set
4017 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4022 // -----------------------------------------------------------------------
4024 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4027 return m_pState
->DoHideProperty(p
, hide
, flags
);
4030 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
4033 if ( !ClearSelection() )
4037 m_pState
->DoHideProperty(p
, hide
, flags
);
4039 RecalculateVirtualSize();
4046 // -----------------------------------------------------------------------
4047 // wxPropertyGrid size related methods
4048 // -----------------------------------------------------------------------
4050 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4052 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4056 // If virtual height was changed, then recalculate editor control position(s)
4057 if ( m_pState
->m_vhCalcPending
)
4058 CorrectEditorWidgetPosY();
4060 m_pState
->EnsureVirtualHeight();
4063 int by1
= m_pState
->GetVirtualHeight();
4064 int by2
= m_pState
->GetActualVirtualHeight();
4067 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4068 wxASSERT_MSG( false,
4074 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4076 int x
= m_pState
->m_width
;
4077 int y
= m_pState
->m_virtualHeight
;
4080 GetClientSize(&width
,&height
);
4082 // Now adjust virtual size.
4083 SetVirtualSize(x
, y
);
4089 // Adjust scrollbars
4090 if ( HasVirtualWidth() )
4092 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4093 xPos
= GetScrollPos( wxHORIZONTAL
);
4096 if ( forceXPos
!= -1 )
4099 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4102 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4103 int yPos
= GetScrollPos( wxVERTICAL
);
4105 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4106 xAmount
, yAmount
, xPos
, yPos
, true );
4108 // Must re-get size now
4109 GetClientSize(&width
,&height
);
4111 if ( !HasVirtualWidth() )
4113 m_pState
->SetVirtualWidth(width
);
4120 m_canvas
->SetSize( x
, y
);
4122 m_pState
->CheckColumnWidths();
4125 CorrectEditorWidgetSizeX();
4127 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4130 // -----------------------------------------------------------------------
4132 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4134 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4138 GetClientSize(&width
,&height
);
4143 m_visPropArray
.SetCount((height
/m_lineHeight
)+10);
4145 #if wxPG_DOUBLE_BUFFER
4146 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4148 int dblh
= (m_lineHeight
*2);
4149 if ( !m_doubleBuffer
)
4151 // Create double buffer bitmap to draw on, if none
4152 int w
= (width
>250)?width
:250;
4153 int h
= height
+ dblh
;
4155 m_doubleBuffer
= new wxBitmap( w
, h
);
4159 int w
= m_doubleBuffer
->GetWidth();
4160 int h
= m_doubleBuffer
->GetHeight();
4162 // Double buffer must be large enough
4163 if ( w
< width
|| h
< (height
+dblh
) )
4165 if ( w
< width
) w
= width
;
4166 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4167 delete m_doubleBuffer
;
4168 m_doubleBuffer
= new wxBitmap( w
, h
);
4175 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4176 m_ncWidth
= event
.GetSize().x
;
4180 if ( m_pState
->m_itemsAdded
)
4181 PrepareAfterItemsAdded();
4183 // Without this, virtual size (atleast under wxGTK) will be skewed
4184 RecalculateVirtualSize();
4190 // -----------------------------------------------------------------------
4192 void wxPropertyGrid::SetVirtualWidth( int width
)
4196 // Disable virtual width
4197 width
= GetClientSize().x
;
4198 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4202 // Enable virtual width
4203 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4205 m_pState
->SetVirtualWidth( width
);
4208 // -----------------------------------------------------------------------
4209 // wxPropertyGrid mouse event handling
4210 // -----------------------------------------------------------------------
4212 // selFlags uses same values DoSelectProperty's flags
4213 // Returns true if event was vetoed.
4214 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4216 // Send property grid event of specific type and with specific property
4217 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4218 evt
.SetPropertyGrid(this);
4219 evt
.SetEventObject(m_eventObject
);
4223 evt
.SetCanVeto(true);
4224 evt
.SetupValidationInfo();
4225 m_validationInfo
.m_pValue
= pValue
;
4227 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4229 evtHandler
->ProcessEvent(evt
);
4231 return evt
.WasVetoed();
4234 // -----------------------------------------------------------------------
4236 // Return false if should be skipped
4237 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4241 // Need to set focus?
4242 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4244 m_canvas
->SetFocus();
4247 wxPropertyGridPageState
* state
= m_pState
;
4249 int splitterHitOffset
;
4250 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4252 wxPGProperty
* p
= DoGetItemAtY(y
);
4256 int depth
= (int)p
->GetDepth() - 1;
4258 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4260 if ( x
>= marginEnds
)
4264 if ( p
->IsCategory() )
4266 // This is category.
4267 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4269 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4271 // Expand, collapse, activate etc. if click on text or left of splitter.
4274 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4279 if ( !DoSelectProperty( p
) )
4282 // On double-click, expand/collapse.
4283 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4285 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4286 else DoExpand( p
, true );
4290 else if ( splitterHit
== -1 )
4293 unsigned int selFlag
= 0;
4294 if ( columnHit
== 1 )
4296 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4297 selFlag
= wxPG_SEL_FOCUS
;
4299 if ( !DoSelectProperty( p
, selFlag
) )
4302 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4304 if ( p
->GetChildCount() && !p
->IsCategory() )
4305 // On double-click, expand/collapse.
4306 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4308 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4309 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4310 else DoExpand( p
, true );
4317 // click on splitter
4318 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4320 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4322 // Double-clicking the splitter causes auto-centering
4323 CenterSplitter( true );
4325 else if ( m_dragStatus
== 0 )
4328 // Begin draggin the splitter
4332 // Changes must be committed here or the
4333 // value won't be drawn correctly
4334 if ( !CommitChangesFromEditor() )
4337 m_wndEditor
->Show ( false );
4340 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4342 m_canvas
->CaptureMouse();
4343 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4347 m_draggedSplitter
= splitterHit
;
4348 m_dragOffset
= splitterHitOffset
;
4350 wxClientDC
dc(m_canvas
);
4352 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4353 // Fixes button disappearance bug
4355 m_wndEditor2
->Show ( false );
4358 m_startingSplitterX
= x
- splitterHitOffset
;
4366 if ( p
->GetChildCount() )
4368 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4370 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4372 int y2
= y
% m_lineHeight
;
4373 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4375 // On click on expander button, expand/collapse
4376 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4377 DoCollapse( p
, true );
4379 DoExpand( p
, true );
4388 // -----------------------------------------------------------------------
4390 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4391 wxMouseEvent
& WXUNUSED(event
) )
4395 // Select property here as well
4396 wxPGProperty
* p
= m_propHover
;
4397 if ( p
!= m_selected
)
4398 DoSelectProperty( p
);
4400 // Send right click event.
4401 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4408 // -----------------------------------------------------------------------
4410 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4411 wxMouseEvent
& WXUNUSED(event
) )
4415 // Select property here as well
4416 wxPGProperty
* p
= m_propHover
;
4418 if ( p
!= m_selected
)
4419 DoSelectProperty( p
);
4421 // Send double-click event.
4422 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4429 // -----------------------------------------------------------------------
4431 #if wxPG_SUPPORT_TOOLTIPS
4433 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4435 if ( tipString
.length() )
4437 m_canvas
->SetToolTip(tipString
);
4441 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4442 m_canvas
->SetToolTip( m_emptyString
);
4444 m_canvas
->SetToolTip( NULL
);
4449 #endif // #if wxPG_SUPPORT_TOOLTIPS
4451 // -----------------------------------------------------------------------
4453 // Return false if should be skipped
4454 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4456 // Safety check (needed because mouse capturing may
4457 // otherwise freeze the control)
4458 if ( m_dragStatus
> 0 && !event
.Dragging() )
4460 HandleMouseUp(x
,y
,event
);
4463 wxPropertyGridPageState
* state
= m_pState
;
4465 int splitterHitOffset
;
4466 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4467 int splitterX
= x
- splitterHitOffset
;
4469 if ( m_dragStatus
> 0 )
4471 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4472 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4475 int newSplitterX
= x
- m_dragOffset
;
4476 int splitterX
= x
- splitterHitOffset
;
4478 // Splitter redraw required?
4479 if ( newSplitterX
!= splitterX
)
4482 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4483 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4484 state
->m_fSplitterX
= (float) newSplitterX
;
4487 CorrectEditorWidgetSizeX();
4501 int ih
= m_lineHeight
;
4504 #if wxPG_SUPPORT_TOOLTIPS
4505 wxPGProperty
* prevHover
= m_propHover
;
4506 unsigned char prevSide
= m_mouseSide
;
4508 int curPropHoverY
= y
- (y
% ih
);
4510 // On which item it hovers
4511 if ( ( !m_propHover
)
4513 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4516 // Mouse moves on another property
4518 m_propHover
= DoGetItemAtY(y
);
4519 m_propHoverY
= curPropHoverY
;
4522 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4525 #if wxPG_SUPPORT_TOOLTIPS
4526 // Store which side we are on
4528 if ( columnHit
== 1 )
4530 else if ( columnHit
== 0 )
4534 // If tooltips are enabled, show label or value as a tip
4535 // in case it doesn't otherwise show in full length.
4537 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4539 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4541 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4543 if ( m_propHover
&& !m_propHover
->IsCategory() )
4546 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4548 // Show help string as a tooltip
4549 wxString tipString
= m_propHover
->GetHelpString();
4551 SetToolTip(tipString
);
4555 // Show cropped value string as a tooltip
4559 if ( m_mouseSide
== 1 )
4561 tipString
= m_propHover
->m_label
;
4562 space
= splitterX
-m_marginWidth
-3;
4564 else if ( m_mouseSide
== 2 )
4566 tipString
= m_propHover
->GetDisplayedString();
4568 space
= m_width
- splitterX
;
4569 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4570 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4576 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4579 SetToolTip( tipString
);
4586 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4587 m_canvas
->SetToolTip( m_emptyString
);
4589 m_canvas
->SetToolTip( NULL
);
4600 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4601 m_canvas
->SetToolTip( m_emptyString
);
4603 m_canvas
->SetToolTip( NULL
);
4611 if ( splitterHit
== -1 ||
4613 HasFlag(wxPG_STATIC_SPLITTER
) )
4615 // hovering on something else
4616 if ( m_curcursor
!= wxCURSOR_ARROW
)
4617 CustomSetCursor( wxCURSOR_ARROW
);
4621 // Do not allow splitter cursor on caption items.
4622 // (also not if we were dragging and its started
4623 // outside the splitter region)
4626 !m_propHover
->IsCategory() &&
4630 // hovering on splitter
4632 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4633 // reliably detected.
4634 //if ( m_curcursor != wxCURSOR_SIZEWE )
4635 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4641 // hovering on something else
4642 if ( m_curcursor
!= wxCURSOR_ARROW
)
4643 CustomSetCursor( wxCURSOR_ARROW
);
4650 // -----------------------------------------------------------------------
4652 // Also handles Leaving event
4653 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4654 wxMouseEvent
&WXUNUSED(event
) )
4656 wxPropertyGridPageState
* state
= m_pState
;
4660 int splitterHitOffset
;
4661 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4663 // No event type check - basicly calling this method should
4664 // just stop dragging.
4665 // Left up after dragged?
4666 if ( m_dragStatus
>= 1 )
4669 // End Splitter Dragging
4671 // DO NOT ENABLE FOLLOWING LINE!
4672 // (it is only here as a reminder to not to do it)
4675 // Disable splitter auto-centering
4676 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4678 // This is necessary to return cursor
4679 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4681 m_canvas
->ReleaseMouse();
4682 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4685 // Set back the default cursor, if necessary
4686 if ( splitterHit
== -1 ||
4689 CustomSetCursor( wxCURSOR_ARROW
);
4694 // Control background needs to be cleared
4695 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4696 DrawItem( m_selected
);
4700 m_wndEditor
->Show ( true );
4703 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4704 // Fixes button disappearance bug
4706 m_wndEditor2
->Show ( true );
4709 // This clears the focus.
4710 m_editorFocused
= 0;
4716 // -----------------------------------------------------------------------
4718 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4720 int splitterX
= GetSplitterPosition();
4723 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4727 wxWindow
* wnd
= m_wndEditor
;
4729 // Hide popup on clicks
4730 if ( event
.GetEventType() != wxEVT_MOTION
)
4731 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4733 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4739 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4741 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4742 ux
>= (r
.x
+r
.width
) ||
4744 event
.m_y
>= (r
.y
+r
.height
)
4754 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4759 // -----------------------------------------------------------------------
4761 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4764 if ( OnMouseCommon( event
, &x
, &y
) )
4766 HandleMouseClick(x
,y
,event
);
4771 // -----------------------------------------------------------------------
4773 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4776 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4777 HandleMouseRightClick(x
,y
,event
);
4781 // -----------------------------------------------------------------------
4783 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4785 // Always run standard mouse-down handler as well
4786 OnMouseClick(event
);
4789 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4790 HandleMouseDoubleClick(x
,y
,event
);
4794 // -----------------------------------------------------------------------
4796 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4799 if ( OnMouseCommon( event
, &x
, &y
) )
4801 HandleMouseMove(x
,y
,event
);
4806 // -----------------------------------------------------------------------
4808 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4810 // Called when mouse moves in the empty space below the properties.
4811 CustomSetCursor( wxCURSOR_ARROW
);
4814 // -----------------------------------------------------------------------
4816 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4819 if ( OnMouseCommon( event
, &x
, &y
) )
4821 HandleMouseUp(x
,y
,event
);
4826 // -----------------------------------------------------------------------
4828 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4830 // This may get called from child control as well, so event's
4831 // mouse position cannot be relied on.
4833 if ( event
.Entering() )
4835 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4837 // TODO: Fix this (detect parent and only do
4838 // cursor trick if it is a manager).
4839 wxASSERT( GetParent() );
4840 GetParent()->SetCursor(wxNullCursor
);
4842 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4845 GetParent()->SetCursor(wxNullCursor
);
4847 else if ( event
.Leaving() )
4849 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4850 m_canvas
->SetCursor( wxNullCursor
);
4852 // Get real cursor position
4853 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4855 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4858 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4860 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4864 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4872 // -----------------------------------------------------------------------
4874 // Common code used by various OnMouseXXXChild methods.
4875 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4877 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4878 wxASSERT( topCtrlWnd
);
4880 event
.GetPosition(&x
,&y
);
4882 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4884 int splitterX
= GetSplitterPosition();
4886 wxRect r
= topCtrlWnd
->GetRect();
4887 if ( !m_dragStatus
&&
4888 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4889 y
>= 0 && y
< r
.height \
4892 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4897 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4904 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4907 if ( OnMouseChildCommon(event
,&x
,&y
) )
4909 bool res
= HandleMouseClick(x
,y
,event
);
4910 if ( !res
) event
.Skip();
4914 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4917 wxASSERT( m_wndEditor
);
4918 // These coords may not be exact (about +-2),
4919 // but that should not matter (right click is about item, not position).
4920 wxPoint pt
= m_wndEditor
->GetPosition();
4921 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4922 wxASSERT( m_selected
);
4923 m_propHover
= m_selected
;
4924 bool res
= HandleMouseRightClick(x
,y
,event
);
4925 if ( !res
) event
.Skip();
4928 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4931 if ( OnMouseChildCommon(event
,&x
,&y
) )
4933 bool res
= HandleMouseMove(x
,y
,event
);
4934 if ( !res
) event
.Skip();
4938 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4941 if ( OnMouseChildCommon(event
,&x
,&y
) )
4943 bool res
= HandleMouseUp(x
,y
,event
);
4944 if ( !res
) event
.Skip();
4948 // -----------------------------------------------------------------------
4949 // wxPropertyGrid keyboard event handling
4950 // -----------------------------------------------------------------------
4952 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4954 wxNavigationKeyEvent evt
;
4955 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4956 (dir
?wxNavigationKeyEvent::IsForward
:
4957 wxNavigationKeyEvent::IsBackward
));
4958 evt
.SetEventObject(this);
4959 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4963 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4965 // Translates wxKeyEvent to wxPG_ACTION_XXX
4967 int keycode
= event
.GetKeyCode();
4968 int modifiers
= event
.GetModifiers();
4970 wxASSERT( !(modifiers
&~(0xFFFF)) );
4972 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4974 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4976 if ( it
== m_actionTriggers
.end() )
4981 int second
= (it
->second
>>16) & 0xFFFF;
4985 return (it
->second
& 0xFFFF);
4988 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4990 wxASSERT( !(modifiers
&~(0xFFFF)) );
4992 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4994 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4996 if ( it
!= m_actionTriggers
.end() )
4998 // This key combination is already used
5000 // Can add secondary?
5001 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5002 wxT("You can only add up to two separate actions per key combination.") );
5004 action
= it
->second
| (action
<<16);
5007 m_actionTriggers
[hashMapKey
] = action
;
5010 void wxPropertyGrid::ClearActionTriggers( int action
)
5012 wxPGHashMapI2I::iterator it
;
5014 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
5016 if ( it
->second
== action
)
5018 m_actionTriggers
.erase(it
);
5023 static void CopyTextToClipboard( const wxString
& text
)
5025 if ( wxTheClipboard
->Open() )
5027 // This data objects are held by the clipboard,
5028 // so do not delete them in the app.
5029 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
5030 wxTheClipboard
->Close();
5034 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5037 // Handles key event when editor control is not focused.
5040 wxASSERT( !m_frozen
);
5044 // Travelsal between items, collapsing/expanding, etc.
5045 int keycode
= event
.GetKeyCode();
5047 if ( keycode
== WXK_TAB
)
5049 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5053 // Ignore Alt and Control when they are down alone
5054 if ( keycode
== WXK_ALT
||
5055 keycode
== WXK_CONTROL
)
5062 int action
= KeyEventToActions(event
, &secondAction
);
5068 if ( ButtonTriggerKeyTest(event
) )
5071 wxPGProperty
* p
= m_selected
;
5073 if ( action
== wxPG_ACTION_COPY
)
5075 CopyTextToClipboard(p
->GetDisplayedString());
5079 // Travel and expand/collapse
5082 if ( p
->GetChildCount() &&
5083 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5086 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5088 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5091 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5093 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5100 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5104 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5115 if ( selectDir
>= -1 )
5117 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5119 DoSelectProperty(p
);
5125 // If nothing was selected, select the first item now
5126 // (or navigate out of tab).
5127 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5129 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5130 if ( p
) DoSelectProperty(p
);
5135 // -----------------------------------------------------------------------
5137 // Potentially handles a keyboard event for editor controls.
5138 // Returns false if event should *not* be skipped (on true it can
5139 // be optionally skipped).
5140 // Basicly, false means that SelectProperty was called (or was about
5141 // to be called, if canDestroy was false).
5142 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5146 if ( !m_selected
|| !m_wndEditor
)
5151 int action
= KeyEventToAction(event
);
5154 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5157 // Esc cancels any changes
5158 if ( IsEditorsValueModified() )
5160 EditorsValueWasNotModified();
5162 // Update the control as well
5163 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5165 m_selected
->GetDisplayedString() );
5168 OnValidationFailureReset(m_selected
);
5174 else if ( action
== wxPG_ACTION_COPY
)
5176 // NB: There is some problem with getting native cut-copy-paste keys to go through
5177 // for embedded editor wxTextCtrl. This is why we emulate.
5179 wxTextCtrl
* tc
= GetEditorTextCtrl();
5182 wxString sel
= tc
->GetStringSelection();
5184 CopyTextToClipboard(sel
);
5188 CopyTextToClipboard(m_selected
->GetDisplayedString());
5191 else if ( action
== wxPG_ACTION_CUT
)
5193 wxTextCtrl
* tc
= GetEditorTextCtrl();
5197 tc
->GetSelection(&from
, &to
);
5200 CopyTextToClipboard(tc
->GetStringSelection());
5201 tc
->Remove(from
, to
);
5205 else if ( action
== wxPG_ACTION_PASTE
)
5207 wxTextCtrl
* tc
= GetEditorTextCtrl();
5210 if (wxTheClipboard
->Open())
5212 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5214 wxTextDataObject data
;
5215 wxTheClipboard
->GetData( data
);
5217 tc
->GetSelection(&from
, &to
);
5220 tc
->Remove(from
, to
);
5221 tc
->WriteText(data
.GetText());
5225 tc
->WriteText(data
.GetText());
5228 wxTheClipboard
->Close();
5236 // -----------------------------------------------------------------------
5238 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5242 // Events to editor controls should get relayed here.
5244 wxWindow
* focused
= wxWindow::FindFocus();
5246 wxWindow
* primaryCtrl
= GetEditorControl();
5249 (focused
==primaryCtrl
5250 || m_editorFocused
) )
5252 // Child key must be processed here, since it can
5253 // destroy the control which is referred by its own
5255 HandleChildKey( event
);
5258 HandleKeyEvent( event
);
5261 // -----------------------------------------------------------------------
5263 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5265 m_keyComboConsumed
= 0;
5270 // -----------------------------------------------------------------------
5272 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5274 // Ignore events that occur very close to focus set
5275 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5277 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5282 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5284 int dir
= event
.GetDirection()?1:-1;
5288 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5290 wxWindow
* focused
= wxWindow::FindFocus();
5292 wxWindow
* wndToCheck
= GetEditorControl();
5294 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5295 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5297 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5298 if ( comboTextCtrl
)
5299 wndToCheck
= comboTextCtrl
;
5303 // Because of problems navigating from wxButton, do not go to it.
5306 // No primary, use secondary
5307 wndToCheck = m_wndEditor2;
5309 // If it has editor button, focus to it after the primary editor.
5310 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5311 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5312 // have somewhat debugged in window.cpp itself).
5313 else if ( focused == wndToCheck &&
5315 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5317 wndToCheck = m_wndEditor2;
5318 wxLogDebug(wxT("Exp1"));
5322 if ( focused
!= wndToCheck
&&
5325 wndToCheck
->SetFocus();
5327 // Select all text in wxTextCtrl etc.
5328 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5329 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5331 m_editorFocused
= 1;
5338 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5342 // This allows preventing NavigateOut to occur
5343 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5352 // -----------------------------------------------------------------------
5354 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5356 int keycode
= event
.GetKeyCode();
5358 // Does the keycode trigger button?
5359 if ( keycode
== m_pushButKeyCode
&&
5361 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5362 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5364 m_keyComboConsumed
= 1;
5366 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5367 GetEventHandler()->AddPendingEvent(evt
);
5374 // -----------------------------------------------------------------------
5376 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5378 int keycode
= event
.GetKeyCode();
5380 // Ignore Alt and Control when they are down alone
5381 if ( keycode
== WXK_ALT
||
5382 keycode
== WXK_CONTROL
)
5388 if ( ButtonTriggerKeyTest(event
) )
5391 if ( HandleChildKey(event
) == true )
5394 GetEventHandler()->AddPendingEvent(event
);
5397 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5399 m_keyComboConsumed
= 0;
5401 GetEventHandler()->AddPendingEvent(event
);
5406 // -----------------------------------------------------------------------
5407 // wxPropertyGrid miscellaneous event handling
5408 // -----------------------------------------------------------------------
5410 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5413 // Check if the focus is in this control or one of its children
5414 wxWindow
* newFocused
= wxWindow::FindFocus();
5416 if ( newFocused
!= m_curFocused
)
5417 HandleFocusChange( newFocused
);
5420 // Called by focus event handlers. newFocused is the window that becomes focused.
5421 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5423 unsigned int oldFlags
= m_iFlags
;
5425 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5427 wxWindow
* parent
= newFocused
;
5429 // This must be one of nextFocus' parents.
5432 // Use m_eventObject, which is either wxPropertyGrid or
5433 // wxPropertyGridManager, as appropriate.
5434 if ( parent
== m_eventObject
)
5436 m_iFlags
|= wxPG_FL_FOCUSED
;
5439 parent
= parent
->GetParent();
5442 m_curFocused
= newFocused
;
5444 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5445 (oldFlags
& wxPG_FL_FOCUSED
) )
5447 // On each focus kill, mark the next nav key event
5448 // to be ignored (can't do on set focus since the
5449 // event would occur before it).
5450 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5452 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5454 // Need to store changed value
5455 CommitChangesFromEditor();
5461 // Preliminary code for tab-order respecting
5462 // tab-traversal (but should be moved to
5465 wxWindow* prevFocus = event.GetWindow();
5466 wxWindow* useThis = this;
5467 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5468 useThis = GetParent();
5471 prevFocus->GetParent() == useThis->GetParent() )
5473 wxList& children = useThis->GetParent()->GetChildren();
5475 wxNode* node = children.Find(prevFocus);
5477 if ( node->GetNext() &&
5478 useThis == node->GetNext()->GetData() )
5479 DoSelectProperty(GetFirst());
5480 else if ( node->GetPrevious () &&
5481 useThis == node->GetPrevious()->GetData() )
5482 DoSelectProperty(GetLastProperty());
5487 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5491 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5492 DrawItem( m_selected
);
5496 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5498 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5499 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5500 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5501 //else if ( event.GetWindow() )
5503 HandleFocusChange(event
.GetWindow());
5508 // -----------------------------------------------------------------------
5510 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5512 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5515 // event.Skip() being commented out is aworkaround for bug reported
5516 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5520 // -----------------------------------------------------------------------
5522 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5524 m_iFlags
|= wxPG_FL_SCROLLED
;
5529 // -----------------------------------------------------------------------
5531 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5533 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5535 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5539 // -----------------------------------------------------------------------
5540 // Property editor related functions
5541 // -----------------------------------------------------------------------
5543 // noDefCheck = true prevents infinite recursion.
5544 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorclass
,
5545 const wxString
& name
,
5548 wxASSERT( editorclass
);
5550 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5551 RegisterDefaultEditors();
5553 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorclass
;
5558 // Registers all default editor classes
5559 void wxPropertyGrid::RegisterDefaultEditors()
5561 wxPGRegisterDefaultEditorClass( TextCtrl
);
5562 wxPGRegisterDefaultEditorClass( Choice
);
5563 wxPGRegisterDefaultEditorClass( ComboBox
);
5564 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5565 #if wxPG_INCLUDE_CHECKBOX
5566 wxPGRegisterDefaultEditorClass( CheckBox
);
5568 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5570 // Register SpinCtrl etc. editors before use
5571 RegisterAdditionalEditors();
5574 // -----------------------------------------------------------------------
5575 // wxPGStringTokenizer
5576 // Needed to handle C-style string lists (e.g. "str1" "str2")
5577 // -----------------------------------------------------------------------
5579 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5580 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5584 wxPGStringTokenizer::~wxPGStringTokenizer()
5588 bool wxPGStringTokenizer::HasMoreTokens()
5590 const wxString
& str
= *m_str
;
5592 wxString::const_iterator i
= m_curPos
;
5594 wxUniChar delim
= m_delimeter
;
5596 wxUniChar prev_a
= wxT('\0');
5598 bool inToken
= false;
5600 while ( i
!= str
.end() )
5609 m_readyToken
.clear();
5614 if ( prev_a
!= wxT('\\') )
5618 if ( a
!= wxT('\\') )
5638 m_curPos
= str
.end();
5646 wxString
wxPGStringTokenizer::GetNextToken()
5648 return m_readyToken
;
5651 // -----------------------------------------------------------------------
5653 // -----------------------------------------------------------------------
5655 wxPGChoiceEntry::wxPGChoiceEntry()
5656 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5660 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5661 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5662 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5666 // -----------------------------------------------------------------------
5668 // -----------------------------------------------------------------------
5670 wxPGChoicesData::wxPGChoicesData()
5675 wxPGChoicesData::~wxPGChoicesData()
5680 void wxPGChoicesData::Clear()
5684 for ( i
=0; i
<m_items
.size(); i
++ )
5696 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5698 wxASSERT( m_items
.size() == 0 );
5702 for ( i
=0; i
<data
->GetCount(); i
++ )
5703 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5706 // -----------------------------------------------------------------------
5708 // -----------------------------------------------------------------------
5710 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5714 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5715 m_data
->Insert( -1, p
);
5719 // -----------------------------------------------------------------------
5721 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5725 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5726 p
->SetBitmap(bitmap
);
5727 m_data
->Insert( -1, p
);
5731 // -----------------------------------------------------------------------
5733 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5737 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5738 m_data
->Insert(index
, p
);
5742 // -----------------------------------------------------------------------
5744 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5748 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5749 m_data
->Insert( index
, p
);
5753 // -----------------------------------------------------------------------
5755 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5761 while ( index
< GetCount() )
5763 int cmpRes
= GetLabel(index
).Cmp(label
);
5769 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5770 m_data
->Insert( index
, p
);
5774 // -----------------------------------------------------------------------
5776 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5780 unsigned int itemcount
= 0;
5781 const wxChar
** p
= &labels
[0];
5782 while ( *p
) { p
++; itemcount
++; }
5785 for ( i
= 0; i
< itemcount
; i
++ )
5787 int value
= wxPG_INVALID_VALUE
;
5790 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5794 // -----------------------------------------------------------------------
5796 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5801 unsigned int itemcount
= arr
.size();
5803 for ( i
= 0; i
< itemcount
; i
++ )
5805 int value
= wxPG_INVALID_VALUE
;
5808 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5812 // -----------------------------------------------------------------------
5814 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5819 unsigned int itemcount
= arr
.size();
5821 for ( i
= 0; i
< itemcount
; i
++ )
5823 int value
= wxPG_INVALID_VALUE
;
5824 if ( &arrint
&& arrint
.size() )
5826 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5830 // -----------------------------------------------------------------------
5832 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5834 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5836 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5837 delete m_data
->Item(i
);
5838 m_data
->m_items
.RemoveAt(nIndex
, count
);
5841 // -----------------------------------------------------------------------
5843 int wxPGChoices::Index( const wxString
& str
) const
5848 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5850 if ( m_data
->Item(i
)->GetText() == str
)
5857 // -----------------------------------------------------------------------
5859 int wxPGChoices::Index( int val
) const
5864 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5866 if ( m_data
->Item(i
)->GetValue() == val
)
5873 // -----------------------------------------------------------------------
5875 wxArrayString
wxPGChoices::GetLabels() const
5880 if ( this && IsOk() )
5881 for ( i
=0; i
<GetCount(); i
++ )
5882 arr
.push_back(GetLabel(i
));
5887 // -----------------------------------------------------------------------
5889 bool wxPGChoices::HasValues() const
5894 // -----------------------------------------------------------------------
5896 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5903 for ( i
=0; i
< strings
.size(); i
++ )
5905 int index
= Index(strings
[i
]);
5907 arr
.Add(GetValue(index
));
5909 arr
.Add(wxPG_INVALID_VALUE
);
5916 // -----------------------------------------------------------------------
5918 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5919 wxArrayString
* unmatched
) const
5926 for ( i
=0; i
< strings
.size(); i
++ )
5928 const wxString
& str
= strings
[i
];
5929 int index
= Index(str
);
5932 else if ( unmatched
)
5933 unmatched
->Add(str
);
5940 // -----------------------------------------------------------------------
5942 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5946 if ( data
!= wxPGChoicesEmptyData
)
5953 // -----------------------------------------------------------------------
5955 void wxPGChoices::Init()
5957 m_data
= wxPGChoicesEmptyData
;
5960 // -----------------------------------------------------------------------
5962 void wxPGChoices::Free()
5964 if ( m_data
!= wxPGChoicesEmptyData
)
5967 m_data
= wxPGChoicesEmptyData
;
5971 // -----------------------------------------------------------------------
5972 // wxPropertyGridEvent
5973 // -----------------------------------------------------------------------
5975 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5978 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5979 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5980 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5981 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5982 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5983 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5984 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5985 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5986 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5989 // -----------------------------------------------------------------------
5991 void wxPropertyGridEvent::Init()
5993 m_validationInfo
= NULL
;
5995 m_wasVetoed
= false;
5998 // -----------------------------------------------------------------------
6000 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6001 : wxCommandEvent(commandType
,id
)
6007 // -----------------------------------------------------------------------
6009 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6010 : wxCommandEvent(event
)
6012 m_eventType
= event
.GetEventType();
6013 m_eventObject
= event
.m_eventObject
;
6015 m_property
= event
.m_property
;
6016 m_validationInfo
= event
.m_validationInfo
;
6017 m_canVeto
= event
.m_canVeto
;
6018 m_wasVetoed
= event
.m_wasVetoed
;
6021 // -----------------------------------------------------------------------
6023 wxPropertyGridEvent::~wxPropertyGridEvent()
6027 // -----------------------------------------------------------------------
6029 wxEvent
* wxPropertyGridEvent::Clone() const
6031 return new wxPropertyGridEvent( *this );
6034 void wxPropertyGrid::SetPropertyAttributeAll( const wxString
& attrName
, wxVariant value
)
6036 DoSetPropertyAttribute(GetRoot(), attrName
, value
, wxPG_RECURSE
);
6039 // -----------------------------------------------------------------------
6040 // wxPropertyGridPopulator
6041 // -----------------------------------------------------------------------
6043 wxPropertyGridPopulator::wxPropertyGridPopulator()
6047 wxPGGlobalVars
->m_offline
++;
6050 // -----------------------------------------------------------------------
6052 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6055 m_propHierarchy
.clear();
6058 // -----------------------------------------------------------------------
6060 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6066 // -----------------------------------------------------------------------
6068 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6071 // Free unused sets of choices
6072 wxPGHashMapS2P::iterator it
;
6074 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6076 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6083 m_pg
->GetPanel()->Refresh();
6085 wxPGGlobalVars
->m_offline
--;
6088 // -----------------------------------------------------------------------
6090 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6091 const wxString
& propLabel
,
6092 const wxString
& propName
,
6093 const wxString
* propValue
,
6094 wxPGChoices
* pChoices
)
6096 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6097 wxPGProperty
* parent
= GetCurParent();
6099 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6101 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6105 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6107 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6111 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6113 property
->SetLabel(propLabel
);
6114 property
->DoSetName(propName
);
6116 if ( pChoices
&& pChoices
->IsOk() )
6117 property
->SetChoices(*pChoices
);
6119 m_state
->DoInsert(parent
, -1, property
);
6122 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6127 // -----------------------------------------------------------------------
6129 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6131 m_propHierarchy
.push_back(property
);
6132 DoScanForChildren();
6133 m_propHierarchy
.pop_back();
6136 // -----------------------------------------------------------------------
6138 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6139 const wxString
& idString
)
6141 wxPGChoices choices
;
6144 if ( choicesString
[0] == wxT('@') )
6146 wxString ids
= choicesString
.substr(1);
6147 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6148 if ( it
== m_dictIdChoices
.end() )
6149 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6151 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6156 if ( idString
.length() )
6158 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6159 if ( it
!= m_dictIdChoices
.end() )
6161 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6168 // Parse choices string
6169 wxString::const_iterator it
= choicesString
.begin();
6173 bool labelValid
= false;
6175 for ( ; it
!= choicesString
.end(); it
++ )
6181 if ( c
== wxT('"') )
6186 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6187 choices
.Add(label
, l
);
6190 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6195 else if ( c
== wxT('=') )
6202 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6209 if ( c
== wxT('"') )
6222 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6223 choices
.Add(label
, l
);
6226 if ( !choices
.IsOk() )
6228 choices
.EnsureData();
6232 if ( idString
.length() )
6233 m_dictIdChoices
[idString
] = choices
.GetData();
6240 // -----------------------------------------------------------------------
6242 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6244 if ( s
.Last() == wxT('%') )
6246 wxString s2
= s
.substr(0,s
.length()-1);
6248 if ( s2
.ToLong(&val
, 10) )
6250 *pval
= (val
*max
)/100;
6256 return s
.ToLong(pval
, 10);
6259 // -----------------------------------------------------------------------
6261 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6262 const wxString
& type
,
6263 const wxString
& value
)
6265 int l
= m_propHierarchy
.size();
6269 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6270 wxString valuel
= value
.Lower();
6273 if ( type
.length() == 0 )
6278 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6280 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6282 else if ( value
.ToLong(&v
, 0) )
6289 if ( type
== wxT("string") )
6293 else if ( type
== wxT("int") )
6296 value
.ToLong(&v
, 0);
6299 else if ( type
== wxT("bool") )
6301 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6308 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6313 p
->SetAttribute( name
, variant
);
6318 // -----------------------------------------------------------------------
6320 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6322 wxLogError(_("Error in resource: %s"),msg
.c_str());
6325 // -----------------------------------------------------------------------