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;
1065 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1066 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1069 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1071 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1072 RecalculateVirtualSize();
1074 InvalidateBestSize();
1077 // -----------------------------------------------------------------------
1079 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1085 // -----------------------------------------------------------------------
1087 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1088 int ga
= 1000, int ba
= 1000,
1089 bool forceDifferent
= false)
1096 // Recursion guard (allow 2 max)
1097 static int isinside
= 0;
1099 wxCHECK_MSG( isinside
< 3,
1101 wxT("wxPGAdjustColour should not be recursively called more than once") );
1106 int g
= src
.Green();
1109 if ( r2
>255 ) r2
= 255;
1110 else if ( r2
<0) r2
= 0;
1112 if ( g2
>255 ) g2
= 255;
1113 else if ( g2
<0) g2
= 0;
1115 if ( b2
>255 ) b2
= 255;
1116 else if ( b2
<0) b2
= 0;
1118 // Make sure they are somewhat different
1119 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1120 dst
= wxPGAdjustColour(src
,-(ra
*2));
1122 dst
= wxColour(r2
,g2
,b2
);
1124 // Recursion guard (allow 2 max)
1131 static int wxPGGetColAvg( const wxColour
& col
)
1133 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1137 void wxPropertyGrid::RegainColours()
1139 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1141 if ( !(m_coloursCustomized
& 0x0002) )
1143 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1145 // Make sure colour is dark enough
1147 int colDec
= wxPGGetColAvg(col
) - 230;
1149 int colDec
= wxPGGetColAvg(col
) - 200;
1152 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1157 if ( !(m_coloursCustomized
& 0x0001) )
1158 m_colMargin
= m_colCapBack
;
1160 if ( !(m_coloursCustomized
& 0x0004) )
1167 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1168 m_colCapFore
= capForeCol
;
1170 // Set the cached colour as well.
1171 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1174 if ( !(m_coloursCustomized
& 0x0008) )
1176 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1177 m_colPropBack
= bgCol
;
1179 // Set the cached brush as well.
1180 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1183 if ( !(m_coloursCustomized
& 0x0010) )
1185 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1186 m_colPropFore
= fgCol
;
1188 // Set the cached colour as well.
1189 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1192 if ( !(m_coloursCustomized
& 0x0020) )
1193 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1195 if ( !(m_coloursCustomized
& 0x0040) )
1196 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1198 if ( !(m_coloursCustomized
& 0x0080) )
1199 m_colLine
= m_colCapBack
;
1201 if ( !(m_coloursCustomized
& 0x0100) )
1202 m_colDisPropFore
= m_colCapFore
;
1204 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1207 // -----------------------------------------------------------------------
1209 void wxPropertyGrid::ResetColours()
1211 m_coloursCustomized
= 0;
1218 // -----------------------------------------------------------------------
1220 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1222 // Must disable active editor.
1225 bool selRes
= ClearSelection();
1226 wxPG_CHECK_MSG_DBG( selRes
,
1228 wxT("failed to deselect a property (editor probably had invalid value)") );
1231 // TODO: Following code is disabled with wxMac because
1232 // it is reported to fail. I (JMS) cannot debug it
1233 // personally right now.
1234 #if !defined(__WXMAC__)
1235 bool res
= wxScrolledWindow::SetFont( font
);
1238 CalculateFontAndBitmapStuff( m_vspacing
);
1241 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1249 // TODO: Remove after SetFont crash fixed.
1250 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1252 wxLogDebug(wxT("WARNING: propGrid.cpp: wxPropertyGrid::SetFont has been disabled on wxMac since there has been crash reported in it. If you are willing to debug the cause, replace line '#if !defined(__WXMAC__)' with line '#if 1' in wxPropertyGrid::SetFont."));
1258 // -----------------------------------------------------------------------
1260 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1263 m_coloursCustomized
|= 0x80;
1267 // -----------------------------------------------------------------------
1269 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1272 m_coloursCustomized
|= 0x01;
1276 // -----------------------------------------------------------------------
1278 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1280 m_colPropBack
= col
;
1281 m_coloursCustomized
|= 0x08;
1283 // Set the cached brush as well.
1284 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1289 // -----------------------------------------------------------------------
1291 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1293 m_colPropFore
= col
;
1294 m_coloursCustomized
|= 0x10;
1296 // Set the cached colour as well.
1297 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1302 // -----------------------------------------------------------------------
1304 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1306 m_colEmptySpace
= col
;
1311 // -----------------------------------------------------------------------
1313 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1315 m_colDisPropFore
= col
;
1316 m_coloursCustomized
|= 0x100;
1320 // -----------------------------------------------------------------------
1322 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1325 m_coloursCustomized
|= 0x20;
1329 // -----------------------------------------------------------------------
1331 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1334 m_coloursCustomized
|= 0x40;
1338 // -----------------------------------------------------------------------
1340 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1343 m_coloursCustomized
|= 0x02;
1347 // -----------------------------------------------------------------------
1349 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1352 m_coloursCustomized
|= 0x04;
1354 // Set the cached colour as well.
1355 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1360 // -----------------------------------------------------------------------
1362 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1364 unsigned char ind
= index
;
1366 p
->m_bgColIndex
= ind
;
1369 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1370 SetBackgroundColourIndex(p
->Item(i
),index
);
1373 // -----------------------------------------------------------------------
1375 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1377 wxPG_PROP_ARG_CALL_PROLOG()
1382 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1384 // As it is most likely that the previous colour is used, start comparison
1386 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1388 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1397 colInd
= m_arrBgBrushes
.size();
1398 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1399 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1403 SetBackgroundColourIndex(p
,colInd
);
1405 // If this was on a visible grid, then draw it.
1406 DrawItemAndChildren(p
);
1409 // -----------------------------------------------------------------------
1411 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1413 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1415 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1418 // -----------------------------------------------------------------------
1420 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1422 unsigned char ind
= index
;
1424 p
->m_fgColIndex
= ind
;
1426 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1429 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1430 SetTextColourIndex( p
->Item(i
), index
, flags
);
1434 // -----------------------------------------------------------------------
1436 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1441 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1443 // As it is most likely that the previous colour is used, start comparison
1445 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1447 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1456 colInd
= m_arrFgCols
.size();
1457 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1458 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1464 // -----------------------------------------------------------------------
1466 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1469 wxPG_PROP_ARG_CALL_PROLOG()
1471 if ( p
->IsCategory() )
1473 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1474 cat
->SetTextColIndex(CacheColour(colour
));
1480 flags
|= wxPG_RECURSE
;
1481 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1483 DrawItemAndChildren(p
);
1486 // -----------------------------------------------------------------------
1488 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1490 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1492 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1495 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1497 wxPG_PROP_ARG_CALL_PROLOG()
1499 SetBackgroundColourIndex( p
, 0 );
1500 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1502 if ( p
->IsCategory() )
1504 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1505 cat
->SetTextColIndex(1);
1509 // -----------------------------------------------------------------------
1510 // wxPropertyGrid property adding and removal
1511 // -----------------------------------------------------------------------
1513 void wxPropertyGrid::PrepareAfterItemsAdded()
1515 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1517 m_pState
->m_itemsAdded
= 0;
1519 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1522 RecalculateVirtualSize();
1525 // -----------------------------------------------------------------------
1526 // wxPropertyGrid property value setting and getting
1527 // -----------------------------------------------------------------------
1529 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1531 m_pState
->DoSetPropertyValueUnspecified(p
);
1532 DrawItemAndChildren(p
);
1534 wxPGProperty
* parent
= p
->GetParent();
1535 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1538 parent
= parent
->GetParent();
1542 // -----------------------------------------------------------------------
1543 // wxPropertyGrid property operations
1544 // -----------------------------------------------------------------------
1546 void wxPropertyGrid::DoSetPropertyName( wxPGProperty
* p
, const wxString
& newname
)
1548 wxCHECK_RET( p
, wxT("invalid property id") );
1550 if ( p
->GetBaseName().Len() ) m_pState
->m_dictName
.erase( p
->GetBaseName() );
1551 if ( newname
.Len() ) m_pState
->m_dictName
[newname
] = (void*) p
;
1553 p
->DoSetName(newname
);
1556 // -----------------------------------------------------------------------
1558 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1560 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1564 bool changed
= false;
1566 // Is it inside collapsed section?
1567 if ( !p
->IsVisible() )
1570 wxPGProperty
* parent
= p
->GetParent();
1571 wxPGProperty
* grandparent
= parent
->GetParent();
1573 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1574 Expand( grandparent
);
1582 GetViewStart(&vx
,&vy
);
1583 vy
*=wxPG_PIXELS_PER_UNIT
;
1589 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1590 m_iFlags
|= wxPG_FL_SCROLLED
;
1593 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1595 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1596 m_iFlags
|= wxPG_FL_SCROLLED
;
1606 // -----------------------------------------------------------------------
1607 // wxPropertyGrid helper methods called by properties
1608 // -----------------------------------------------------------------------
1610 // Control font changer helper.
1611 void wxPropertyGrid::SetCurControlBoldFont()
1613 wxASSERT( m_wndEditor
);
1614 m_wndEditor
->SetFont( m_captionFont
);
1617 // -----------------------------------------------------------------------
1619 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1622 #if wxPG_SMALL_SCREEN
1623 // On small-screen devices, always show dialogs with default position and size.
1624 return wxDefaultPosition
;
1626 int splitterX
= GetSplitterPosition();
1630 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1632 ImprovedClientToScreen( &x
, &y
);
1634 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1635 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1642 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1652 new_y
= y
+ m_lineHeight
;
1654 return wxPoint(new_x
,new_y
);
1658 // -----------------------------------------------------------------------
1660 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1662 if ( src_str
.length() == 0 )
1668 bool prev_is_slash
= false;
1670 wxString::const_iterator i
= src_str
.begin();
1674 for ( ; i
!= src_str
.end(); i
++ )
1678 if ( a
!= wxS('\\') )
1680 if ( !prev_is_slash
)
1686 if ( a
== wxS('n') )
1689 dst_str
<< wxS('\n');
1691 dst_str
<< wxS('\n');
1694 else if ( a
== wxS('t') )
1695 dst_str
<< wxS('\t');
1699 prev_is_slash
= false;
1703 if ( prev_is_slash
)
1705 dst_str
<< wxS('\\');
1706 prev_is_slash
= false;
1710 prev_is_slash
= true;
1717 // -----------------------------------------------------------------------
1719 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1721 if ( src_str
.length() == 0 )
1727 wxString::const_iterator i
= src_str
.begin();
1728 wxUniChar prev_a
= wxS('\0');
1732 for ( ; i
!= src_str
.end(); i
++ )
1736 if ( a
>= wxS(' ') )
1738 // This surely is not something that requires an escape sequence.
1743 // This might need...
1744 if ( a
== wxS('\r') )
1746 // DOS style line end.
1747 // Already taken care below
1749 else if ( a
== wxS('\n') )
1750 // UNIX style line end.
1751 dst_str
<< wxS("\\n");
1752 else if ( a
== wxS('\t') )
1754 dst_str
<< wxS('\t');
1757 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1767 // -----------------------------------------------------------------------
1769 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1773 return (wxPGProperty
*) NULL
;
1776 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1779 // -----------------------------------------------------------------------
1780 // wxPropertyGrid graphics related methods
1781 // -----------------------------------------------------------------------
1783 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1787 // Update everything inside the box
1788 wxRect r
= GetUpdateRegion().GetBox();
1790 dc
.SetPen(m_colEmptySpace
);
1791 dc
.SetBrush(m_colEmptySpace
);
1792 dc
.DrawRectangle(r
);
1795 // -----------------------------------------------------------------------
1797 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1798 wxPGProperty
* property
) const
1800 // Prepare rectangle to be used
1802 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1803 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1805 #if (wxPG_USE_RENDERER_NATIVE)
1807 #elif wxPG_ICON_WIDTH
1808 // Drawing expand/collapse button manually
1809 dc
.SetPen(m_colPropFore
);
1810 if ( property
->IsCategory() )
1811 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1813 dc
.SetBrush(m_colPropBack
);
1815 dc
.DrawRectangle( r
);
1816 int _y
= r
.y
+(m_iconWidth
/2);
1817 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1822 if ( property
->IsExpanded() )
1824 // wxRenderer functions are non-mutating in nature, so it
1825 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1826 // Hopefully this does not cause problems.
1827 #if (wxPG_USE_RENDERER_NATIVE)
1828 wxRendererNative::Get().DrawTreeItemButton(
1834 #elif wxPG_ICON_WIDTH
1843 #if (wxPG_USE_RENDERER_NATIVE)
1844 wxRendererNative::Get().DrawTreeItemButton(
1850 #elif wxPG_ICON_WIDTH
1851 int _x
= r
.x
+(m_iconWidth
/2);
1852 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1858 #if (wxPG_USE_RENDERER_NATIVE)
1860 #elif wxPG_ICON_WIDTH
1863 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1867 // -----------------------------------------------------------------------
1870 // This is the one called by OnPaint event handler and others.
1871 // topy and bottomy are already unscrolled (ie. physical)
1873 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1875 unsigned int bottomy
,
1876 const wxRect
* clipRect
)
1878 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1880 m_pState
->EnsureVirtualHeight();
1882 wxRect tempClipRect
;
1885 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1886 clipRect
= &tempClipRect
;
1889 // items added check
1890 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1892 int paintFinishY
= 0;
1894 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1897 bool isBuffered
= false;
1899 #if wxPG_DOUBLE_BUFFER
1900 wxMemoryDC
* bufferDC
= NULL
;
1902 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1904 if ( !m_doubleBuffer
)
1906 paintFinishY
= clipRect
->y
;
1911 bufferDC
= new wxMemoryDC();
1913 // If nothing was changed, then just copy from double-buffer
1914 bufferDC
->SelectObject( *m_doubleBuffer
);
1924 dc
.SetClippingRegion( *clipRect
);
1925 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1928 #if wxPG_DOUBLE_BUFFER
1931 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1932 bufferDC
, 0, 0, wxCOPY
);
1933 dc
.DestroyClippingRegion(); // Is this really necessary?
1939 // Clear area beyond bottomY?
1940 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1942 dc
.SetPen(m_colEmptySpace
);
1943 dc
.SetBrush(m_colEmptySpace
);
1944 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1948 // -----------------------------------------------------------------------
1950 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1951 const wxPGProperty
* firstItem
,
1952 const wxPGProperty
* lastItem
,
1953 const wxRect
* clipRect
,
1954 bool isBuffered
) const
1956 // TODO: This should somehow be eliminated.
1957 wxRect tempClipRect
;
1960 wxASSERT(firstItem
);
1962 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1963 clipRect
= &tempClipRect
;
1967 firstItem
= DoGetItemAtY(clipRect
->y
);
1971 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1973 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1976 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1979 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1980 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1982 int lh
= m_lineHeight
;
1985 int lastItemBottomY
;
1987 firstItemTopY
= clipRect
->y
;
1988 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1990 // Align y coordinates to item boundaries
1991 firstItemTopY
-= firstItemTopY
% lh
;
1992 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1993 lastItemBottomY
-= 1;
1995 // Entire range outside scrolled, visible area?
1996 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1999 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
2003 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
2004 firstItem->GetLabel().c_str(),
2005 lastItem->GetLabel().c_str(),
2006 (int)(lastItemBottomY - firstItemTopY),
2008 (unsigned long)clipRect );
2013 long windowStyle
= m_windowStyle
;
2019 // With wxPG_DOUBLE_BUFFER, do double buffering
2020 // - buffer's y = 0, so align cliprect and coordinates to that
2022 #if wxPG_DOUBLE_BUFFER
2028 xRelMod
= clipRect
->x
;
2029 yRelMod
= clipRect
->y
;
2032 // clipRect conversion
2040 firstItemTopY
-= yRelMod
;
2041 lastItemBottomY
-= yRelMod
;
2044 wxUnusedVar(isBuffered
);
2047 int x
= m_marginWidth
- xRelMod
;
2049 const wxFont
& normalfont
= m_font
;
2051 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
2053 bool isEnabled
= IsEnabled();
2056 // Prepare some pens and brushes that are often changed to.
2059 wxBrush
marginBrush(m_colMargin
);
2060 wxPen
marginPen(m_colMargin
);
2061 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2062 wxPen
linepen(m_colLine
,1,wxSOLID
);
2064 // pen that has same colour as text
2065 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2068 // Clear margin with background colour
2070 dc
.SetBrush( marginBrush
);
2071 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2073 dc
.SetPen( *wxTRANSPARENT_PEN
);
2074 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2077 const wxPGProperty
* selected
= m_selected
;
2078 const wxPropertyGridPageState
* state
= m_pState
;
2080 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2081 bool wasSelectedPainted
= false;
2084 // TODO: Only render columns that are within clipping region.
2086 dc
.SetFont(normalfont
);
2088 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2089 int endScanBottomY
= lastItemBottomY
+ lh
;
2090 int y
= firstItemTopY
;
2093 // Pregenerate list of visible properties.
2094 wxArrayPGProperty visPropArray
;
2095 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2097 for ( ; !it
.AtEnd(); it
.Next() )
2099 const wxPGProperty
* p
= *it
;
2101 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2103 visPropArray
.push_back((wxPGProperty
*)p
);
2105 if ( y
> endScanBottomY
)
2112 visPropArray
.push_back(NULL
);
2114 wxPGProperty
* nextP
= visPropArray
[0];
2116 int gridWidth
= state
->m_width
;
2119 for ( unsigned int arrInd
=1;
2120 nextP
&& y
<= lastItemBottomY
;
2123 wxPGProperty
* p
= nextP
;
2124 nextP
= visPropArray
[arrInd
];
2126 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2127 int textMarginHere
= x
;
2128 int renderFlags
= wxPGCellRenderer::Control
;
2130 int greyDepth
= m_marginWidth
;
2131 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2132 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2134 int greyDepthX
= greyDepth
- xRelMod
;
2136 // Use basic depth if in non-categoric mode and parent is base array.
2137 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2139 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2142 // Paint margin area
2143 dc
.SetBrush(marginBrush
);
2144 dc
.SetPen(marginPen
);
2145 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2147 dc
.SetPen( linepen
);
2152 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2158 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2160 sx
+= state
->m_colWidths
[si
];
2161 dc
.DrawLine( sx
, y
, sx
, y2
);
2164 // Horizontal Line, below
2165 // (not if both this and next is category caption)
2166 if ( p
->IsCategory() &&
2167 nextP
&& nextP
->IsCategory() )
2168 dc
.SetPen(m_colCapBack
);
2170 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2172 if ( p
== selected
)
2174 renderFlags
|= wxPGCellRenderer::Selected
;
2175 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2176 wasSelectedPainted
= true;
2184 if ( p
->IsCategory() )
2186 if ( p
->m_fgColIndex
== 0 )
2187 rowFgCol
= m_colCapFore
;
2189 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2190 rowBgBrush
= wxBrush(m_colCapBack
);
2192 else if ( p
!= selected
)
2194 // Disabled may get different colour.
2195 if ( !p
->IsEnabled() )
2196 rowFgCol
= m_colDisPropFore
;
2198 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2200 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2204 // Selected gets different colour.
2205 if ( reallyFocused
)
2207 rowFgCol
= m_colSelFore
;
2208 rowBgBrush
= wxBrush(m_colSelBack
);
2210 else if ( isEnabled
)
2212 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2213 rowBgBrush
= marginBrush
;
2217 rowFgCol
= m_colDisPropFore
;
2218 rowBgBrush
= wxBrush(m_colSelBack
);
2222 bool fontChanged
= false;
2224 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2229 if ( p
->IsCategory() )
2231 // Captions are all cells merged as one
2232 dc
.SetFont(m_captionFont
);
2234 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2236 dc
.SetBrush(rowBgBrush
);
2237 dc
.SetPen(rowBgBrush
.GetColour());
2238 dc
.SetTextForeground(rowFgCol
);
2240 dc
.DrawRectangle(cellRect
);
2243 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2244 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2247 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2248 DrawExpanderButton( dc
, butRect
, p
);
2252 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2254 dc
.SetFont(m_captionFont
);
2260 int nextCellWidth
= state
->m_colWidths
[0];
2261 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2262 int textXAdd
= textMarginHere
- greyDepthX
;
2264 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2266 cellRect
.width
= nextCellWidth
- 1;
2268 bool ctrlCell
= false;
2271 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2273 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2274 dc
.SetBrush(editorBgCol
);
2275 dc
.SetPen(editorBgCol
);
2276 dc
.SetTextForeground(m_colPropFore
);
2278 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2283 dc
.SetBrush(rowBgBrush
);
2284 dc
.SetPen(rowBgBrush
.GetColour());
2285 dc
.SetTextForeground(rowFgCol
);
2288 dc
.DrawRectangle(cellRect
);
2291 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2292 DrawExpanderButton( dc
, butRect
, p
);
2294 dc
.SetClippingRegion(cellRect
);
2296 cellRect
.x
+= textXAdd
;
2297 cellRect
.width
-= textXAdd
;
2302 wxPGCellRenderer
* renderer
;
2303 int cmnVal
= p
->GetCommonValue();
2304 if ( cmnVal
== -1 || ci
!= 1 )
2306 renderer
= p
->GetCellRenderer(ci
);
2307 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2311 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2312 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2316 cellX
+= state
->m_colWidths
[ci
];
2317 if ( ci
< (state
->m_colWidths
.size()-1) )
2318 nextCellWidth
= state
->m_colWidths
[ci
+1];
2320 dc
.DestroyClippingRegion(); // Is this really necessary?
2326 dc
.SetFont(normalfont
);
2331 // Refresh editor controls (seems not needed on msw)
2332 // NOTE: This code is mandatory for GTK!
2333 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2334 if ( wasSelectedPainted
)
2337 m_wndEditor
->Refresh();
2339 m_wndEditor2
->Refresh();
2346 // -----------------------------------------------------------------------
2348 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2352 if ( m_width
< 10 || m_height
< 10 ||
2353 !m_pState
->m_properties
->GetChildCount() ||
2354 p1
== (wxPGProperty
*) NULL
)
2355 return wxRect(0,0,0,0);
2360 // Return rect which encloses the given property range
2362 int visTop
= p1
->GetY();
2365 visBottom
= p2
->GetY() + m_lineHeight
;
2367 visBottom
= m_height
+ visTop
;
2369 // If seleced property is inside the range, we'll extend the range to include
2371 wxPGProperty
* selected
= m_selected
;
2374 int selectedY
= selected
->GetY();
2375 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2377 wxWindow
* editor
= GetEditorControl();
2380 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2381 if ( visBottom2
> visBottom
)
2382 visBottom
= visBottom2
;
2387 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2390 // -----------------------------------------------------------------------
2392 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2397 if ( m_pState
->m_itemsAdded
)
2398 PrepareAfterItemsAdded();
2400 wxRect r
= GetPropertyRect(p1
, p2
);
2403 m_canvas
->RefreshRect(r
);
2407 // -----------------------------------------------------------------------
2409 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2411 if ( p
== m_selected
)
2412 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2414 DrawItemAndChildren(p
);
2417 // -----------------------------------------------------------------------
2419 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2424 // Draw item, children, and parent too, if it is not category
2425 wxPGProperty
* parent
= p
->GetParent();
2428 !parent
->IsCategory() &&
2429 parent
->GetParent() )
2432 parent
= parent
->GetParent();
2435 DrawItemAndChildren(p
);
2438 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2440 wxCHECK_RET( p
, wxT("invalid property id") );
2442 // Do not draw if in non-visible page
2443 if ( p
->GetParentState() != m_pState
)
2446 // do not draw a single item if multiple pending
2447 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2450 wxWindow
* wndPrimary
= GetEditorControl();
2452 // Update child control.
2453 if ( m_selected
&& m_selected
->GetParent() == p
)
2454 m_selected
->UpdateControl(wndPrimary
);
2456 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2458 DrawItems(p
, lastDrawn
);
2461 // -----------------------------------------------------------------------
2463 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2464 const wxRect
*rect
)
2466 PrepareAfterItemsAdded();
2468 wxWindow::Refresh(false);
2470 // TODO: Coordinate translation
2471 m_canvas
->Refresh(false, rect
);
2473 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2474 // I think this really helps only GTK+1.2
2475 if ( m_wndEditor
) m_wndEditor
->Refresh();
2476 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2480 // -----------------------------------------------------------------------
2481 // wxPropertyGrid global operations
2482 // -----------------------------------------------------------------------
2484 void wxPropertyGrid::Clear()
2488 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2489 wxPG_CHECK_RET_DBG( selRes
,
2490 wxT("failed to deselect a property (editor probably had invalid value)") );
2493 m_pState
->DoClear();
2499 RecalculateVirtualSize();
2501 // Need to clear some area at the end
2503 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2506 // -----------------------------------------------------------------------
2508 bool wxPropertyGrid::EnableCategories( bool enable
)
2510 if ( !ClearSelection() )
2516 // Enable categories
2519 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2524 // Disable categories
2526 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2529 if ( !m_pState
->EnableCategories(enable
) )
2534 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2536 m_pState
->m_itemsAdded
= 1; // force
2537 PrepareAfterItemsAdded();
2541 m_pState
->m_itemsAdded
= 1;
2543 // No need for RecalculateVirtualSize() here - it is already called in
2544 // wxPropertyGridPageState method above.
2551 // -----------------------------------------------------------------------
2553 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2555 wxASSERT( pNewState
);
2556 wxASSERT( pNewState
->GetGrid() );
2558 if ( pNewState
== m_pState
)
2561 wxPGProperty
* oldSelection
= m_selected
;
2566 bool selRes
= ClearSelection();
2567 wxPG_CHECK_RET_DBG( selRes
,
2568 wxT("failed to deselect a property (editor probably had invalid value)") );
2571 m_pState
->m_selected
= oldSelection
;
2573 bool orig_mode
= m_pState
->IsInNonCatMode();
2574 bool new_state_mode
= pNewState
->IsInNonCatMode();
2576 m_pState
= pNewState
;
2579 int pgWidth
= GetClientSize().x
;
2580 if ( HasVirtualWidth() )
2582 int minWidth
= pgWidth
;
2583 if ( pNewState
->m_width
< minWidth
)
2585 pNewState
->m_width
= minWidth
;
2586 pNewState
->CheckColumnWidths();
2592 // Just in case, fully re-center splitter
2593 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2594 pNewState
->m_fSplitterX
= -1.0;
2596 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2599 m_propHover
= (wxPGProperty
*) NULL
;
2601 // If necessary, convert state to correct mode.
2602 if ( orig_mode
!= new_state_mode
)
2604 // This should refresh as well.
2605 EnableCategories( orig_mode
?false:true );
2607 else if ( !m_frozen
)
2609 // Refresh, if not frozen.
2610 if ( m_pState
->m_itemsAdded
)
2611 PrepareAfterItemsAdded();
2614 if ( m_pState
->m_selected
)
2615 DoSelectProperty( m_pState
->m_selected
);
2617 RecalculateVirtualSize(0);
2621 m_pState
->m_itemsAdded
= 1;
2624 // -----------------------------------------------------------------------
2626 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2628 wxPG_PROP_ARG_CALL_PROLOG()
2630 m_pState
->SortChildren( p
);
2633 // -----------------------------------------------------------------------
2635 void wxPropertyGrid::Sort()
2637 bool selRes
= ClearSelection(); // This must be before state clear
2638 wxPG_CHECK_RET_DBG( selRes
,
2639 wxT("failed to deselect a property (editor probably had invalid value)") );
2644 // -----------------------------------------------------------------------
2646 // Call to SetSplitterPosition will always disable splitter auto-centering
2647 // if parent window is shown.
2648 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2650 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2653 wxPropertyGridPageState
* state
= m_pState
;
2655 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2660 CorrectEditorWidgetSizeX();
2666 // -----------------------------------------------------------------------
2668 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2670 SetSplitterPosition( m_width
/2, true );
2671 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2672 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2675 // -----------------------------------------------------------------------
2676 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2677 // -----------------------------------------------------------------------
2679 // Returns nearest paint visible property (such that will be painted unless
2680 // window is scrolled or resized). If given property is paint visible, then
2681 // it itself will be returned
2682 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2684 int vx
,vy1
;// Top left corner of client
2685 GetViewStart(&vx
,&vy1
);
2686 vy1
*= wxPG_PIXELS_PER_UNIT
;
2688 int vy2
= vy1
+ m_height
;
2689 int propY
= p
->GetY2(m_lineHeight
);
2691 if ( (propY
+ m_lineHeight
) < vy1
)
2694 return DoGetItemAtY( vy1
);
2696 else if ( propY
> vy2
)
2699 return DoGetItemAtY( vy2
);
2702 // Itself paint visible
2707 // -----------------------------------------------------------------------
2709 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2713 m_pushButKeyCode
= keycode
;
2714 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2715 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2719 m_pushButKeyCode
= WXK_DOWN
;
2720 m_pushButKeyCodeNeedsCtrl
= 0;
2721 m_pushButKeyCodeNeedsAlt
= 1;
2725 // -----------------------------------------------------------------------
2726 // Methods related to change in value, value modification and sending events
2727 // -----------------------------------------------------------------------
2729 // commits any changes in editor of selected property
2730 // return true if validation did not fail
2731 // flags are same as with DoSelectProperty
2732 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2734 // Committing already?
2735 if ( m_inCommitChangesFromEditor
)
2738 // Don't do this if already processing editor event. It might
2739 // induce recursive dialogs and crap like that.
2740 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2742 if ( m_inDoPropertyChanged
)
2749 IsEditorsValueModified() &&
2750 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2753 m_inCommitChangesFromEditor
= 1;
2755 wxVariant
variant(m_selected
->GetValueRef());
2756 bool valueIsPending
= false;
2758 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2759 // due to another window getting focus
2760 wxWindow
* oldFocus
= m_curFocused
;
2762 bool validationFailure
= false;
2763 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2765 m_chgInfo_changedProperty
= NULL
;
2767 // If truly modified, schedule value as pending.
2768 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2770 if ( DoEditorValidate() &&
2771 PerformValidation(m_selected
, variant
) )
2773 valueIsPending
= true;
2777 validationFailure
= true;
2782 EditorsValueWasNotModified();
2787 m_inCommitChangesFromEditor
= 0;
2789 if ( validationFailure
&& !forceSuccess
)
2793 oldFocus
->SetFocus();
2794 m_curFocused
= oldFocus
;
2797 res
= OnValidationFailure(m_selected
, variant
);
2799 // Now prevent further validation failure messages
2802 EditorsValueWasNotModified();
2803 OnValidationFailureReset(m_selected
);
2806 else if ( valueIsPending
)
2808 DoPropertyChanged( m_selected
, flags
);
2809 EditorsValueWasNotModified();
2818 // -----------------------------------------------------------------------
2820 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2823 // Runs all validation functionality.
2824 // Returns true if value passes all tests.
2827 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2829 if ( !wxPGIsVariantType(pendingValue
, list
) )
2831 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2836 // Adapt list to child values, if necessary
2837 wxVariant listValue
= pendingValue
;
2838 wxVariant
* pPendingValue
= &pendingValue
;
2839 wxVariant
* pList
= NULL
;
2841 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2842 // string value, then we need treat as it was changed instead
2843 // (or, in addition, as is the case with composite string parent).
2844 // This includes creating list variant for child values.
2846 wxPGProperty
* pwc
= p
->GetParent();
2847 wxPGProperty
* changedProperty
= p
;
2848 wxPGProperty
* baseChangedProperty
= changedProperty
;
2849 wxVariant bcpPendingList
;
2851 listValue
= pendingValue
;
2852 listValue
.SetName(p
->GetLabel());
2855 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2857 wxVariantList tempList
;
2858 wxVariant
lv(tempList
, pwc
->GetLabel());
2859 lv
.Append(listValue
);
2861 pPendingValue
= &listValue
;
2863 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2865 baseChangedProperty
= pwc
;
2866 bcpPendingList
= lv
;
2869 changedProperty
= pwc
;
2870 pwc
= pwc
->GetParent();
2874 wxPGProperty
* evtChangingProperty
= changedProperty
;
2876 if ( !wxPGIsVariantType(*pPendingValue
, list
) )
2878 value
= *pPendingValue
;
2882 // Convert list to child values
2883 pList
= pPendingValue
;
2884 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2887 wxVariant evtChangingValue
= value
;
2889 // FIXME: After proper ValueToString()s added, remove
2890 // this. It is just a temporary fix, as evt_changing
2891 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2892 // (unless it is selected, and textctrl editor is open).
2893 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2895 evtChangingProperty
= baseChangedProperty
;
2896 if ( evtChangingProperty
!= p
)
2898 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2902 evtChangingValue
= pendingValue
;
2906 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2908 if ( changedProperty
== m_selected
)
2910 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2911 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2915 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2919 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2920 m_chgInfo_changedProperty
= changedProperty
;
2921 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2922 m_chgInfo_pendingValue
= value
;
2925 m_chgInfo_valueList
= *pList
;
2927 m_chgInfo_valueList
.MakeNull();
2929 // If changedProperty is not property which value was edited,
2930 // then call wxPGProperty::ValidateValue() for that as well.
2931 if ( p
!= changedProperty
&& !wxPGIsVariantType(value
, list
) )
2933 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2937 // SendEvent returns true if event was vetoed
2938 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2944 // -----------------------------------------------------------------------
2946 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2948 if ( !msg
.length() )
2952 if ( !wxPGGlobalVars
->m_offline
)
2954 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2957 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2960 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2963 pStatusBar
->SetStatusText(msg
);
2971 ::wxMessageBox(msg
, _T("Property Error"));
2974 // -----------------------------------------------------------------------
2976 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2978 int vfb
= m_validationInfo
.m_failureBehavior
;
2980 if ( vfb
& wxPG_VFB_BEEP
)
2983 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2984 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2986 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2987 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2989 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2991 wxColour vfbFg
= *wxWHITE
;
2992 wxColour vfbBg
= *wxRED
;
2993 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2994 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2996 DrawItemAndChildren(property
);
2998 if ( property
== m_selected
)
3000 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3002 wxWindow
* editor
= GetEditorControl();
3005 editor
->SetForegroundColour(vfbFg
);
3006 editor
->SetBackgroundColour(vfbBg
);
3012 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
3014 wxString msg
= m_validationInfo
.m_failureMessage
;
3016 if ( !msg
.length() )
3017 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
3019 DoShowPropertyError(property
, msg
);
3022 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
3025 // -----------------------------------------------------------------------
3027 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
3029 int vfb
= m_validationInfo
.m_failureBehavior
;
3031 if ( vfb
& wxPG_VFB_MARK_CELL
)
3033 property
->SetCell(0, NULL
);
3034 property
->SetCell(1, NULL
);
3036 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
3038 if ( property
== m_selected
&& GetEditorControl() )
3040 // Calling this will recreate the control, thus resetting its colour
3041 RefreshProperty(property
);
3045 DrawItemAndChildren(property
);
3050 // -----------------------------------------------------------------------
3052 // flags are same as with DoSelectProperty
3053 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3055 if ( m_inDoPropertyChanged
)
3058 m_pState
->m_anyModified
= 1;
3060 m_inDoPropertyChanged
= 1;
3062 // Maybe need to update control
3063 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3065 // These values were calculated in PerformValidation()
3066 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3067 wxVariant value
= m_chgInfo_pendingValue
;
3069 wxPGProperty
* topPaintedProperty
= changedProperty
;
3071 while ( !topPaintedProperty
->IsCategory() &&
3072 !topPaintedProperty
->IsRoot() )
3074 topPaintedProperty
= topPaintedProperty
->GetParent();
3077 changedProperty
->SetValue(value
, &m_chgInfo_valueList
);
3079 // Set as Modified (not if dragging just began)
3080 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3082 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3083 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3086 SetCurControlBoldFont();
3092 // Propagate updates to parent(s)
3094 wxPGProperty
* prevPwc
= NULL
;
3096 while ( prevPwc
!= topPaintedProperty
)
3098 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3100 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3103 SetCurControlBoldFont();
3107 pwc
= pwc
->GetParent();
3110 // Draw the actual property
3111 DrawItemAndChildren( topPaintedProperty
);
3114 // If value was set by wxPGProperty::OnEvent, then update the editor
3116 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3119 p
->GetEditorClass()->UpdateControl(p
, m_wndEditor
);
3123 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3124 if ( m_wndEditor
) m_wndEditor
->Refresh();
3125 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3130 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3132 // If top parent has composite string value, then send to child parents,
3133 // starting from baseChangedProperty.
3134 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3136 pwc
= m_chgInfo_baseChangedProperty
;
3138 while ( pwc
!= changedProperty
)
3140 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3141 pwc
= pwc
->GetParent();
3145 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3147 m_inDoPropertyChanged
= 0;
3152 // -----------------------------------------------------------------------
3154 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3156 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3158 m_chgInfo_changedProperty
= NULL
;
3160 if ( PerformValidation(p
, newValue
) )
3162 DoPropertyChanged(p
);
3167 OnValidationFailure(p
, newValue
);
3173 // -----------------------------------------------------------------------
3175 // Runs wxValidator for the selected property
3176 bool wxPropertyGrid::DoEditorValidate()
3178 #if wxUSE_VALIDATORS
3179 // With traditional validator style, we dont need to more
3180 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3183 if ( m_iFlags
& wxPG_FL_VALIDATION_FAILED
)
3188 wxWindow
* wnd
= GetEditorControl();
3190 wxValidator
* validator
= m_selected
->GetValidator();
3191 if ( validator
&& wnd
)
3193 // Use TextCtrl of ODComboBox instead
3194 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3196 wnd
= ((wxOwnerDrawnComboBox
*)wnd
)->GetTextCtrl();
3202 validator
->SetWindow(wnd
);
3204 // Instead setting the flag after the failure, we set
3205 // it before checking and then clear afterwards if things
3206 // went fine. This trick is necessary since focus events
3207 // may be triggered while in Validate.
3208 m_iFlags
|= wxPG_FL_VALIDATION_FAILED
;
3209 if ( !validator
->Validate(this) )
3211 // If you dpm't want to display message multiple times per change,
3212 // comment the following line.
3213 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3216 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3222 // -----------------------------------------------------------------------
3224 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3226 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3227 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3229 wxWindow
* parent
= wnd
->GetParent();
3232 (parent
== m_canvas
||
3233 parent
->GetParent() == m_canvas
) )
3235 OnCustomEditorEvent((wxCommandEvent
&)event
);
3239 return wxPanel::ProcessEvent(event
);
3242 // -----------------------------------------------------------------------
3244 // NB: It may really not be wxCommandEvent - must check if necessary
3246 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3248 wxPGProperty
* selected
= m_selected
;
3251 // Somehow, event is handled after property has been deselected.
3252 // Possibly, but very rare.
3256 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3259 wxVariant
pendingValue(selected
->GetValueRef());
3260 wxWindow
* wnd
= GetEditorControl();
3262 bool wasUnspecified
= selected
->IsValueUnspecified();
3263 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3265 bool valueIsPending
= false;
3267 m_chgInfo_changedProperty
= NULL
;
3269 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3272 // Filter out excess wxTextCtrl modified events
3273 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3275 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3277 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3279 wxString newTcValue
= tc
->GetValue();
3280 if ( m_prevTcValue
== newTcValue
)
3283 m_prevTcValue
= newTcValue
;
3286 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3288 bool validationFailure
= false;
3289 bool buttonWasHandled
= false;
3292 // Try common button handling
3293 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3295 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3299 buttonWasHandled
= true;
3300 // Store as res2, as previously (and still currently alternatively)
3301 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3302 // in wxPGProperty::OnEvent().
3303 adapter
->ShowDialog( this, selected
);
3308 if ( !buttonWasHandled
)
3310 // First call editor class' event handler.
3311 const wxPGEditor
* editor
= selected
->GetEditorClass();
3313 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3315 // If changes, validate them
3316 if ( DoEditorValidate() )
3318 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3319 valueIsPending
= true;
3323 validationFailure
= true;
3327 // Then the property's custom handler (must be always called, unless
3328 // validation failed).
3329 if ( !validationFailure
)
3330 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3333 // SetValueInEvent(), as called in one of the functions referred above
3334 // overrides editor's value.
3335 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3337 valueIsPending
= true;
3338 pendingValue
= m_changeInEventValue
;
3339 selFlags
|= wxPG_SEL_DIALOGVAL
;
3342 if ( !validationFailure
&& valueIsPending
)
3343 if ( !PerformValidation(m_selected
, pendingValue
) )
3344 validationFailure
= true;
3346 if ( validationFailure
)
3348 OnValidationFailure(selected
, pendingValue
);
3350 else if ( valueIsPending
)
3352 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3354 DoPropertyChanged(selected
, selFlags
);
3355 EditorsValueWasNotModified();
3359 // No value after all
3361 // Let unhandled button click events go to the parent
3362 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3364 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3365 GetEventHandler()->AddPendingEvent(evt
);
3369 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3372 // -----------------------------------------------------------------------
3373 // wxPropertyGrid editor control helper methods
3374 // -----------------------------------------------------------------------
3376 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3378 int itemy
= p
->GetY2(m_lineHeight
);
3380 int cust_img_space
= 0;
3381 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3382 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3384 // TODO: If custom image detection changes from current, change this.
3385 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3387 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3388 int imwid
= p
->OnMeasureImage().x
;
3389 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3390 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3395 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3397 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3402 // -----------------------------------------------------------------------
3404 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3406 wxSize sz
= GetImageSize(p
, item
);
3407 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3408 wxPG_CUSTOM_IMAGE_SPACINGY
,
3413 // return size of custom paint image
3414 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3416 // If called with NULL property, then return default image
3417 // size for properties that use image.
3419 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3421 wxSize cis
= p
->OnMeasureImage(item
);
3423 int choiceCount
= p
->GetChoiceCount();
3424 int comVals
= p
->GetDisplayedCommonValueCount();
3425 if ( item
>= choiceCount
&& comVals
> 0 )
3427 unsigned int cvi
= item
-choiceCount
;
3428 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3430 else if ( item
>= 0 && choiceCount
== 0 )
3431 return wxSize(0, 0);
3436 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3441 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3448 // -----------------------------------------------------------------------
3450 // takes scrolling into account
3451 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3454 GetViewStart(&vx
,&vy
);
3455 vy
*=wxPG_PIXELS_PER_UNIT
;
3456 vx
*=wxPG_PIXELS_PER_UNIT
;
3459 ClientToScreen( px
, py
);
3462 // -----------------------------------------------------------------------
3464 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3467 GetViewStart(&pt2
.x
,&pt2
.y
);
3468 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3469 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3473 return m_pState
->HitTest(pt2
);
3476 // -----------------------------------------------------------------------
3478 // custom set cursor
3479 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3481 if ( type
== m_curcursor
&& !override
) return;
3483 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3485 if ( type
== wxCURSOR_SIZEWE
)
3486 cursor
= m_cursorSizeWE
;
3488 m_canvas
->SetCursor( *cursor
);
3493 // -----------------------------------------------------------------------
3494 // wxPropertyGrid property selection
3495 // -----------------------------------------------------------------------
3497 #define CONNECT_CHILD(EVT,FUNCTYPE,FUNC) \
3498 wnd->Connect(id, EVT, \
3499 (wxObjectEventFunction) (wxEventFunction) \
3500 FUNCTYPE (&wxPropertyGrid::FUNC), \
3503 // Setups event handling for child control
3504 void wxPropertyGrid::SetupEventHandling( wxWindow
* argWnd
, int id
)
3506 wxWindow
* wnd
= argWnd
;
3508 if ( argWnd
== m_wndEditor
)
3510 CONNECT_CHILD(wxEVT_MOTION
,(wxMouseEventFunction
),OnMouseMoveChild
)
3511 CONNECT_CHILD(wxEVT_LEFT_UP
,(wxMouseEventFunction
),OnMouseUpChild
)
3512 CONNECT_CHILD(wxEVT_LEFT_DOWN
,(wxMouseEventFunction
),OnMouseClickChild
)
3513 CONNECT_CHILD(wxEVT_RIGHT_UP
,(wxMouseEventFunction
),OnMouseRightClickChild
)
3514 CONNECT_CHILD(wxEVT_ENTER_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3515 CONNECT_CHILD(wxEVT_LEAVE_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3519 CONNECT_CHILD(wxEVT_NAVIGATION_KEY
,(wxNavigationKeyEventFunction
),OnNavigationKey
)
3521 CONNECT_CHILD(wxEVT_KEY_DOWN
,(wxCharEventFunction
),OnChildKeyDown
)
3522 CONNECT_CHILD(wxEVT_KEY_UP
,(wxCharEventFunction
),OnChildKeyUp
)
3523 CONNECT_CHILD(wxEVT_KILL_FOCUS
,(wxFocusEventFunction
),OnFocusEvent
)
3526 void wxPropertyGrid::FreeEditors()
3528 // Do not free editors immediately if processing events
3529 if ( !m_windowsToDelete
)
3530 m_windowsToDelete
= new wxArrayPtrVoid
;
3534 m_windowsToDelete
->push_back(m_wndEditor2
);
3535 m_wndEditor2
->Hide();
3536 m_wndEditor2
= (wxWindow
*) NULL
;
3541 m_windowsToDelete
->push_back(m_wndEditor
);
3542 m_wndEditor
->Hide();
3543 m_wndEditor
= (wxWindow
*) NULL
;
3547 // Call with NULL to de-select property
3548 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3552 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3553 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3555 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3558 if ( m_inDoSelectProperty
)
3561 m_inDoSelectProperty
= 1;
3563 wxPGProperty
* prev
= m_selected
;
3566 // Delete windows pending for deletion
3567 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3571 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3572 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3574 m_windowsToDelete
->clear();
3579 m_inDoSelectProperty
= 0;
3584 // If we are frozen, then just set the values.
3587 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3588 m_editorFocused
= 0;
3591 m_pState
->m_selected
= p
;
3593 // If frozen, always free controls. But don't worry, as Thaw will
3594 // recall SelectProperty to recreate them.
3597 // Prevent any further selection measures in this call
3598 p
= (wxPGProperty
*) NULL
;
3603 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3605 // Only set focus if not deselecting
3608 if ( flags
& wxPG_SEL_FOCUS
)
3612 m_wndEditor
->SetFocus();
3613 m_editorFocused
= 1;
3618 wxScrolledWindow::SetFocus();
3619 m_editorFocused
= 0;
3623 m_inDoSelectProperty
= 0;
3628 // First, deactivate previous
3632 OnValidationFailureReset(m_selected
);
3634 // Must double-check if this is an selected in case of forceswitch
3637 if ( !CommitChangesFromEditor(flags
) )
3639 // Validation has failed, so we can't exit the previous editor
3640 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3641 // _("Invalid Value"),wxOK|wxICON_ERROR);
3642 m_inDoSelectProperty
= 0;
3650 m_selected
= (wxPGProperty
*) NULL
;
3651 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3653 // We need to always fully refresh the grid here
3656 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3657 EditorsValueWasNotModified();
3660 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3663 // Then, activate the one given.
3666 int propY
= p
->GetY2(m_lineHeight
);
3668 int splitterX
= GetSplitterPosition();
3669 m_editorFocused
= 0;
3671 m_pState
->m_selected
= p
;
3672 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3674 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3676 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3678 // Do we need OnMeasureCalls?
3679 wxSize imsz
= p
->OnMeasureImage();
3682 // Only create editor for non-disabled non-caption
3683 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3685 // do this for non-caption items
3689 // Do we need to paint the custom image, if any?
3690 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3691 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3692 !p
->GetEditorClass()->CanContainCustomImage()
3694 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3696 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3697 wxPoint goodPos
= grect
.GetPosition();
3698 #if wxPG_CREATE_CONTROLS_HIDDEN
3699 int coord_adjust
= m_height
- goodPos
.y
;
3700 goodPos
.y
+= coord_adjust
;
3703 const wxPGEditor
* editor
= p
->GetEditorClass();
3704 wxCHECK_MSG(editor
, false,
3705 wxT("NULL editor class not allowed"));
3707 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3709 wxPGWindowList wndList
= editor
->CreateControls(this,
3714 m_wndEditor
= wndList
.m_primary
;
3715 m_wndEditor2
= wndList
.m_secondary
;
3717 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3718 // value is drawn as normal, and m_wndEditor2 is assumed
3719 // to be a right-aligned button that triggers a separate editor
3724 wxASSERT_MSG( m_wndEditor
->GetParent() == m_canvas
,
3725 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3727 // Set validator, if any
3728 #if wxUSE_VALIDATORS
3729 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3731 wxValidator
* validator
= p
->GetValidator();
3733 m_wndEditor
->SetValidator(*validator
);
3737 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3738 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3740 // If it has modified status, use bold font
3741 // (must be done before capturing m_ctrlXAdjust)
3742 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3743 SetCurControlBoldFont();
3746 // Fix TextCtrl indentation
3747 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3748 wxTextCtrl
* tc
= NULL
;
3749 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3750 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3752 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3754 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3757 // Store x relative to splitter (we'll need it).
3758 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3760 // Check if background clear is not necessary
3761 wxPoint pos
= m_wndEditor
->GetPosition();
3762 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3764 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3767 m_wndEditor
->SetSizeHints(3, 3);
3769 #if wxPG_CREATE_CONTROLS_HIDDEN
3770 m_wndEditor
->Show(false);
3771 m_wndEditor
->Freeze();
3773 goodPos
= m_wndEditor
->GetPosition();
3774 goodPos
.y
-= coord_adjust
;
3775 m_wndEditor
->Move( goodPos
);
3778 wxWindow
* primaryCtrl
= GetEditorControl();
3779 SetupEventHandling(primaryCtrl
, wxPG_SUBID1
);
3781 // Focus and select all (wxTextCtrl, wxComboBox etc)
3782 if ( flags
& wxPG_SEL_FOCUS
)
3784 primaryCtrl
->SetFocus();
3786 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3792 wxASSERT_MSG( m_wndEditor2
->GetParent() == m_canvas
,
3793 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3795 // Get proper id for wndSecondary
3796 m_wndSecId
= m_wndEditor2
->GetId();
3797 wxWindowList children
= m_wndEditor2
->GetChildren();
3798 wxWindowList::iterator node
= children
.begin();
3799 if ( node
!= children
.end() )
3800 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3802 m_wndEditor2
->SetSizeHints(3,3);
3804 #if wxPG_CREATE_CONTROLS_HIDDEN
3805 wxRect sec_rect
= m_wndEditor2
->GetRect();
3806 sec_rect
.y
-= coord_adjust
;
3808 // Fine tuning required to fix "oversized"
3809 // button disappearance bug.
3810 if ( sec_rect
.y
< 0 )
3812 sec_rect
.height
+= sec_rect
.y
;
3815 m_wndEditor2
->SetSize( sec_rect
);
3817 m_wndEditor2
->Show();
3819 SetupEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3821 // If no primary editor, focus to button to allow
3822 // it to interprete ENTER etc.
3823 // NOTE: Due to problems focusing away from it, this
3824 // has been disabled.
3826 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3827 m_wndEditor2->SetFocus();
3831 if ( flags
& wxPG_SEL_FOCUS
)
3832 m_editorFocused
= 1;
3837 // wxGTK atleast seems to need this (wxMSW not)
3841 EditorsValueWasNotModified();
3843 // If it's inside collapsed section, expand parent, scroll, etc.
3844 // Also, if it was partially visible, scroll it into view.
3845 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3850 #if wxPG_CREATE_CONTROLS_HIDDEN
3851 m_wndEditor
->Thaw();
3853 m_wndEditor
->Show(true);
3859 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3865 // Show help text in status bar.
3866 // (if found and grid not embedded in manager with help box and
3867 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3870 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3872 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3873 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3875 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3877 statusbar
= frame
->GetStatusBar();
3882 const wxString
* pHelpString
= (const wxString
*) NULL
;
3886 pHelpString
= &p
->GetHelpString();
3887 if ( pHelpString
->length() )
3889 // Set help box text.
3890 statusbar
->SetStatusText( *pHelpString
);
3891 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3895 if ( (!pHelpString
|| !pHelpString
->length()) &&
3896 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3898 // Clear help box - but only if it was written
3899 // by us at previous time.
3900 statusbar
->SetStatusText( m_emptyString
);
3901 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3907 m_inDoSelectProperty
= 0;
3909 // call wx event handler (here so that it also occurs on deselection)
3910 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3915 // -----------------------------------------------------------------------
3917 bool wxPropertyGrid::UnfocusEditor()
3919 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3922 if ( !CommitChangesFromEditor(0) )
3925 m_canvas
->SetFocusIgnoringChildren();
3926 DrawItem(m_selected
);
3931 // -----------------------------------------------------------------------
3933 // This method is not inline because it called dozens of times
3934 // (i.e. two-arg function calls create smaller code size).
3935 bool wxPropertyGrid::DoClearSelection()
3937 return DoSelectProperty((wxPGProperty
*)NULL
);
3940 // -----------------------------------------------------------------------
3941 // wxPropertyGrid expand/collapse state
3942 // -----------------------------------------------------------------------
3944 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3946 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3948 // If active editor was inside collapsed section, then disable it
3949 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3951 if ( !ClearSelection() )
3955 // Store dont-center-splitter flag 'cause we need to temporarily set it
3956 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3957 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3959 bool res
= m_pState
->DoCollapse(pwc
);
3964 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3966 RecalculateVirtualSize();
3968 // Redraw etc. only if collapsed was visible.
3969 if (pwc
->IsVisible() &&
3971 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3973 // When item is collapsed so that scrollbar would move,
3974 // graphics mess is about (unless we redraw everything).
3979 // Clear dont-center-splitter flag if it wasn't set
3980 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3985 // -----------------------------------------------------------------------
3987 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3989 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3991 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3993 // Store dont-center-splitter flag 'cause we need to temporarily set it
3994 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3995 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3997 bool res
= m_pState
->DoExpand(pwc
);
4002 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4004 RecalculateVirtualSize();
4006 // Redraw etc. only if expanded was visible.
4007 if ( pwc
->IsVisible() && !m_frozen
&&
4008 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
4012 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4015 DrawItems(pwc
, NULL
);
4020 // Clear dont-center-splitter flag if it wasn't set
4021 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4026 // -----------------------------------------------------------------------
4028 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4031 return m_pState
->DoHideProperty(p
, hide
, flags
);
4034 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
4037 if ( !ClearSelection() )
4041 m_pState
->DoHideProperty(p
, hide
, flags
);
4043 RecalculateVirtualSize();
4050 // -----------------------------------------------------------------------
4051 // wxPropertyGrid size related methods
4052 // -----------------------------------------------------------------------
4054 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4056 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4060 // If virtual height was changed, then recalculate editor control position(s)
4061 if ( m_pState
->m_vhCalcPending
)
4062 CorrectEditorWidgetPosY();
4064 m_pState
->EnsureVirtualHeight();
4067 int by1
= m_pState
->GetVirtualHeight();
4068 int by2
= m_pState
->GetActualVirtualHeight();
4071 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4072 wxASSERT_MSG( false,
4078 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4080 int x
= m_pState
->m_width
;
4081 int y
= m_pState
->m_virtualHeight
;
4084 GetClientSize(&width
,&height
);
4086 // Now adjust virtual size.
4087 SetVirtualSize(x
, y
);
4093 // Adjust scrollbars
4094 if ( HasVirtualWidth() )
4096 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4097 xPos
= GetScrollPos( wxHORIZONTAL
);
4100 if ( forceXPos
!= -1 )
4103 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4106 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4107 int yPos
= GetScrollPos( wxVERTICAL
);
4109 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4110 xAmount
, yAmount
, xPos
, yPos
, true );
4112 // Must re-get size now
4113 GetClientSize(&width
,&height
);
4115 if ( !HasVirtualWidth() )
4117 m_pState
->SetVirtualWidth(width
);
4124 m_canvas
->SetSize( x
, y
);
4126 m_pState
->CheckColumnWidths();
4129 CorrectEditorWidgetSizeX();
4131 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4134 // -----------------------------------------------------------------------
4136 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4138 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4142 GetClientSize(&width
,&height
);
4147 #if wxPG_DOUBLE_BUFFER
4148 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4150 int dblh
= (m_lineHeight
*2);
4151 if ( !m_doubleBuffer
)
4153 // Create double buffer bitmap to draw on, if none
4154 int w
= (width
>250)?width
:250;
4155 int h
= height
+ dblh
;
4157 m_doubleBuffer
= new wxBitmap( w
, h
);
4161 int w
= m_doubleBuffer
->GetWidth();
4162 int h
= m_doubleBuffer
->GetHeight();
4164 // Double buffer must be large enough
4165 if ( w
< width
|| h
< (height
+dblh
) )
4167 if ( w
< width
) w
= width
;
4168 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4169 delete m_doubleBuffer
;
4170 m_doubleBuffer
= new wxBitmap( w
, h
);
4177 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4178 m_ncWidth
= event
.GetSize().x
;
4182 if ( m_pState
->m_itemsAdded
)
4183 PrepareAfterItemsAdded();
4185 // Without this, virtual size (atleast under wxGTK) will be skewed
4186 RecalculateVirtualSize();
4192 // -----------------------------------------------------------------------
4194 void wxPropertyGrid::SetVirtualWidth( int width
)
4198 // Disable virtual width
4199 width
= GetClientSize().x
;
4200 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4204 // Enable virtual width
4205 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4207 m_pState
->SetVirtualWidth( width
);
4210 // -----------------------------------------------------------------------
4211 // wxPropertyGrid mouse event handling
4212 // -----------------------------------------------------------------------
4214 // selFlags uses same values DoSelectProperty's flags
4215 // Returns true if event was vetoed.
4216 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4218 // Send property grid event of specific type and with specific property
4219 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4220 evt
.SetPropertyGrid(this);
4221 evt
.SetEventObject(m_eventObject
);
4225 evt
.SetCanVeto(true);
4226 evt
.SetupValidationInfo();
4227 m_validationInfo
.m_pValue
= pValue
;
4229 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4231 evtHandler
->ProcessEvent(evt
);
4233 return evt
.WasVetoed();
4236 // -----------------------------------------------------------------------
4238 // Return false if should be skipped
4239 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4243 // Need to set focus?
4244 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4246 m_canvas
->SetFocus();
4249 wxPropertyGridPageState
* state
= m_pState
;
4251 int splitterHitOffset
;
4252 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4254 wxPGProperty
* p
= DoGetItemAtY(y
);
4258 int depth
= (int)p
->GetDepth() - 1;
4260 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4262 if ( x
>= marginEnds
)
4266 if ( p
->IsCategory() )
4268 // This is category.
4269 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4271 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4273 // Expand, collapse, activate etc. if click on text or left of splitter.
4276 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4281 if ( !DoSelectProperty( p
) )
4284 // On double-click, expand/collapse.
4285 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4287 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4288 else DoExpand( p
, true );
4292 else if ( splitterHit
== -1 )
4295 unsigned int selFlag
= 0;
4296 if ( columnHit
== 1 )
4298 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4299 selFlag
= wxPG_SEL_FOCUS
;
4301 if ( !DoSelectProperty( p
, selFlag
) )
4304 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4306 if ( p
->GetChildCount() && !p
->IsCategory() )
4307 // On double-click, expand/collapse.
4308 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4310 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4311 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4312 else DoExpand( p
, true );
4319 // click on splitter
4320 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4322 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4324 // Double-clicking the splitter causes auto-centering
4325 CenterSplitter( true );
4327 else if ( m_dragStatus
== 0 )
4330 // Begin draggin the splitter
4334 // Changes must be committed here or the
4335 // value won't be drawn correctly
4336 if ( !CommitChangesFromEditor() )
4339 m_wndEditor
->Show ( false );
4342 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4344 m_canvas
->CaptureMouse();
4345 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4349 m_draggedSplitter
= splitterHit
;
4350 m_dragOffset
= splitterHitOffset
;
4352 wxClientDC
dc(m_canvas
);
4354 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4355 // Fixes button disappearance bug
4357 m_wndEditor2
->Show ( false );
4360 m_startingSplitterX
= x
- splitterHitOffset
;
4368 if ( p
->GetChildCount() )
4370 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4372 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4374 int y2
= y
% m_lineHeight
;
4375 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4377 // On click on expander button, expand/collapse
4378 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4379 DoCollapse( p
, true );
4381 DoExpand( p
, true );
4390 // -----------------------------------------------------------------------
4392 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4393 wxMouseEvent
& WXUNUSED(event
) )
4397 // Select property here as well
4398 wxPGProperty
* p
= m_propHover
;
4399 if ( p
!= m_selected
)
4400 DoSelectProperty( p
);
4402 // Send right click event.
4403 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4410 // -----------------------------------------------------------------------
4412 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4413 wxMouseEvent
& WXUNUSED(event
) )
4417 // Select property here as well
4418 wxPGProperty
* p
= m_propHover
;
4420 if ( p
!= m_selected
)
4421 DoSelectProperty( p
);
4423 // Send double-click event.
4424 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4431 // -----------------------------------------------------------------------
4433 #if wxPG_SUPPORT_TOOLTIPS
4435 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4437 if ( tipString
.length() )
4439 m_canvas
->SetToolTip(tipString
);
4443 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4444 m_canvas
->SetToolTip( m_emptyString
);
4446 m_canvas
->SetToolTip( NULL
);
4451 #endif // #if wxPG_SUPPORT_TOOLTIPS
4453 // -----------------------------------------------------------------------
4455 // Return false if should be skipped
4456 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4458 // Safety check (needed because mouse capturing may
4459 // otherwise freeze the control)
4460 if ( m_dragStatus
> 0 && !event
.Dragging() )
4462 HandleMouseUp(x
,y
,event
);
4465 wxPropertyGridPageState
* state
= m_pState
;
4467 int splitterHitOffset
;
4468 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4469 int splitterX
= x
- splitterHitOffset
;
4471 if ( m_dragStatus
> 0 )
4473 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4474 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4477 int newSplitterX
= x
- m_dragOffset
;
4478 int splitterX
= x
- splitterHitOffset
;
4480 // Splitter redraw required?
4481 if ( newSplitterX
!= splitterX
)
4484 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4485 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4486 state
->m_fSplitterX
= (float) newSplitterX
;
4489 CorrectEditorWidgetSizeX();
4503 int ih
= m_lineHeight
;
4506 #if wxPG_SUPPORT_TOOLTIPS
4507 wxPGProperty
* prevHover
= m_propHover
;
4508 unsigned char prevSide
= m_mouseSide
;
4510 int curPropHoverY
= y
- (y
% ih
);
4512 // On which item it hovers
4513 if ( ( !m_propHover
)
4515 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4518 // Mouse moves on another property
4520 m_propHover
= DoGetItemAtY(y
);
4521 m_propHoverY
= curPropHoverY
;
4524 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4527 #if wxPG_SUPPORT_TOOLTIPS
4528 // Store which side we are on
4530 if ( columnHit
== 1 )
4532 else if ( columnHit
== 0 )
4536 // If tooltips are enabled, show label or value as a tip
4537 // in case it doesn't otherwise show in full length.
4539 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4541 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4543 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4545 if ( m_propHover
&& !m_propHover
->IsCategory() )
4548 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4550 // Show help string as a tooltip
4551 wxString tipString
= m_propHover
->GetHelpString();
4553 SetToolTip(tipString
);
4557 // Show cropped value string as a tooltip
4561 if ( m_mouseSide
== 1 )
4563 tipString
= m_propHover
->m_label
;
4564 space
= splitterX
-m_marginWidth
-3;
4566 else if ( m_mouseSide
== 2 )
4568 tipString
= m_propHover
->GetDisplayedString();
4570 space
= m_width
- splitterX
;
4571 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4572 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4578 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4581 SetToolTip( tipString
);
4588 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4589 m_canvas
->SetToolTip( m_emptyString
);
4591 m_canvas
->SetToolTip( NULL
);
4602 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4603 m_canvas
->SetToolTip( m_emptyString
);
4605 m_canvas
->SetToolTip( NULL
);
4613 if ( splitterHit
== -1 ||
4615 HasFlag(wxPG_STATIC_SPLITTER
) )
4617 // hovering on something else
4618 if ( m_curcursor
!= wxCURSOR_ARROW
)
4619 CustomSetCursor( wxCURSOR_ARROW
);
4623 // Do not allow splitter cursor on caption items.
4624 // (also not if we were dragging and its started
4625 // outside the splitter region)
4628 !m_propHover
->IsCategory() &&
4632 // hovering on splitter
4634 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4635 // reliably detected.
4636 //if ( m_curcursor != wxCURSOR_SIZEWE )
4637 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4643 // hovering on something else
4644 if ( m_curcursor
!= wxCURSOR_ARROW
)
4645 CustomSetCursor( wxCURSOR_ARROW
);
4652 // -----------------------------------------------------------------------
4654 // Also handles Leaving event
4655 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4656 wxMouseEvent
&WXUNUSED(event
) )
4658 wxPropertyGridPageState
* state
= m_pState
;
4662 int splitterHitOffset
;
4663 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4665 // No event type check - basicly calling this method should
4666 // just stop dragging.
4667 // Left up after dragged?
4668 if ( m_dragStatus
>= 1 )
4671 // End Splitter Dragging
4673 // DO NOT ENABLE FOLLOWING LINE!
4674 // (it is only here as a reminder to not to do it)
4677 // Disable splitter auto-centering
4678 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4680 // This is necessary to return cursor
4681 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4683 m_canvas
->ReleaseMouse();
4684 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4687 // Set back the default cursor, if necessary
4688 if ( splitterHit
== -1 ||
4691 CustomSetCursor( wxCURSOR_ARROW
);
4696 // Control background needs to be cleared
4697 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4698 DrawItem( m_selected
);
4702 m_wndEditor
->Show ( true );
4705 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4706 // Fixes button disappearance bug
4708 m_wndEditor2
->Show ( true );
4711 // This clears the focus.
4712 m_editorFocused
= 0;
4718 // -----------------------------------------------------------------------
4720 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4722 int splitterX
= GetSplitterPosition();
4725 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4729 wxWindow
* wnd
= m_wndEditor
;
4731 // Hide popup on clicks
4732 if ( event
.GetEventType() != wxEVT_MOTION
)
4733 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4735 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4741 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4743 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4744 ux
>= (r
.x
+r
.width
) ||
4746 event
.m_y
>= (r
.y
+r
.height
)
4756 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4761 // -----------------------------------------------------------------------
4763 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4766 if ( OnMouseCommon( event
, &x
, &y
) )
4768 HandleMouseClick(x
,y
,event
);
4773 // -----------------------------------------------------------------------
4775 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4778 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4779 HandleMouseRightClick(x
,y
,event
);
4783 // -----------------------------------------------------------------------
4785 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4787 // Always run standard mouse-down handler as well
4788 OnMouseClick(event
);
4791 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4792 HandleMouseDoubleClick(x
,y
,event
);
4796 // -----------------------------------------------------------------------
4798 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4801 if ( OnMouseCommon( event
, &x
, &y
) )
4803 HandleMouseMove(x
,y
,event
);
4808 // -----------------------------------------------------------------------
4810 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4812 // Called when mouse moves in the empty space below the properties.
4813 CustomSetCursor( wxCURSOR_ARROW
);
4816 // -----------------------------------------------------------------------
4818 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4821 if ( OnMouseCommon( event
, &x
, &y
) )
4823 HandleMouseUp(x
,y
,event
);
4828 // -----------------------------------------------------------------------
4830 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4832 // This may get called from child control as well, so event's
4833 // mouse position cannot be relied on.
4835 if ( event
.Entering() )
4837 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4839 // TODO: Fix this (detect parent and only do
4840 // cursor trick if it is a manager).
4841 wxASSERT( GetParent() );
4842 GetParent()->SetCursor(wxNullCursor
);
4844 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4847 GetParent()->SetCursor(wxNullCursor
);
4849 else if ( event
.Leaving() )
4851 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4852 m_canvas
->SetCursor( wxNullCursor
);
4854 // Get real cursor position
4855 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4857 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4860 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4862 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4866 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4874 // -----------------------------------------------------------------------
4876 // Common code used by various OnMouseXXXChild methods.
4877 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4879 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4880 wxASSERT( topCtrlWnd
);
4882 event
.GetPosition(&x
,&y
);
4884 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4886 int splitterX
= GetSplitterPosition();
4888 wxRect r
= topCtrlWnd
->GetRect();
4889 if ( !m_dragStatus
&&
4890 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4891 y
>= 0 && y
< r
.height \
4894 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4899 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4906 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4909 if ( OnMouseChildCommon(event
,&x
,&y
) )
4911 bool res
= HandleMouseClick(x
,y
,event
);
4912 if ( !res
) event
.Skip();
4916 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4919 wxASSERT( m_wndEditor
);
4920 // These coords may not be exact (about +-2),
4921 // but that should not matter (right click is about item, not position).
4922 wxPoint pt
= m_wndEditor
->GetPosition();
4923 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4924 wxASSERT( m_selected
);
4925 m_propHover
= m_selected
;
4926 bool res
= HandleMouseRightClick(x
,y
,event
);
4927 if ( !res
) event
.Skip();
4930 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4933 if ( OnMouseChildCommon(event
,&x
,&y
) )
4935 bool res
= HandleMouseMove(x
,y
,event
);
4936 if ( !res
) event
.Skip();
4940 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4943 if ( OnMouseChildCommon(event
,&x
,&y
) )
4945 bool res
= HandleMouseUp(x
,y
,event
);
4946 if ( !res
) event
.Skip();
4950 // -----------------------------------------------------------------------
4951 // wxPropertyGrid keyboard event handling
4952 // -----------------------------------------------------------------------
4954 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4956 wxNavigationKeyEvent evt
;
4957 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4958 (dir
?wxNavigationKeyEvent::IsForward
:
4959 wxNavigationKeyEvent::IsBackward
));
4960 evt
.SetEventObject(this);
4961 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4965 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4967 // Translates wxKeyEvent to wxPG_ACTION_XXX
4969 int keycode
= event
.GetKeyCode();
4970 int modifiers
= event
.GetModifiers();
4972 wxASSERT( !(modifiers
&~(0xFFFF)) );
4974 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4976 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4978 if ( it
== m_actionTriggers
.end() )
4983 int second
= (it
->second
>>16) & 0xFFFF;
4987 return (it
->second
& 0xFFFF);
4990 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4992 wxASSERT( !(modifiers
&~(0xFFFF)) );
4994 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4996 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4998 if ( it
!= m_actionTriggers
.end() )
5000 // This key combination is already used
5002 // Can add secondary?
5003 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5004 wxT("You can only add up to two separate actions per key combination.") );
5006 action
= it
->second
| (action
<<16);
5009 m_actionTriggers
[hashMapKey
] = action
;
5012 void wxPropertyGrid::ClearActionTriggers( int action
)
5014 wxPGHashMapI2I::iterator it
;
5016 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
5018 if ( it
->second
== action
)
5020 m_actionTriggers
.erase(it
);
5025 static void CopyTextToClipboard( const wxString
& text
)
5027 if ( wxTheClipboard
->Open() )
5029 // This data objects are held by the clipboard,
5030 // so do not delete them in the app.
5031 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
5032 wxTheClipboard
->Close();
5036 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5039 // Handles key event when editor control is not focused.
5042 wxASSERT( !m_frozen
);
5046 // Travelsal between items, collapsing/expanding, etc.
5047 int keycode
= event
.GetKeyCode();
5049 if ( keycode
== WXK_TAB
)
5051 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5055 // Ignore Alt and Control when they are down alone
5056 if ( keycode
== WXK_ALT
||
5057 keycode
== WXK_CONTROL
)
5064 int action
= KeyEventToActions(event
, &secondAction
);
5070 if ( ButtonTriggerKeyTest(event
) )
5073 wxPGProperty
* p
= m_selected
;
5075 if ( action
== wxPG_ACTION_COPY
)
5077 CopyTextToClipboard(p
->GetDisplayedString());
5081 // Travel and expand/collapse
5084 if ( p
->GetChildCount() &&
5085 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5088 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5090 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5093 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5095 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5102 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5106 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5117 if ( selectDir
>= -1 )
5119 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5121 DoSelectProperty(p
);
5127 // If nothing was selected, select the first item now
5128 // (or navigate out of tab).
5129 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5131 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5132 if ( p
) DoSelectProperty(p
);
5137 // -----------------------------------------------------------------------
5139 // Potentially handles a keyboard event for editor controls.
5140 // Returns false if event should *not* be skipped (on true it can
5141 // be optionally skipped).
5142 // Basicly, false means that SelectProperty was called (or was about
5143 // to be called, if canDestroy was false).
5144 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5148 if ( !m_selected
|| !m_wndEditor
)
5153 int action
= KeyEventToAction(event
);
5156 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5159 // Esc cancels any changes
5160 if ( IsEditorsValueModified() )
5162 EditorsValueWasNotModified();
5164 // Update the control as well
5165 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5167 m_selected
->GetDisplayedString() );
5170 OnValidationFailureReset(m_selected
);
5176 else if ( action
== wxPG_ACTION_COPY
)
5178 // NB: There is some problem with getting native cut-copy-paste keys to go through
5179 // for embedded editor wxTextCtrl. This is why we emulate.
5181 wxTextCtrl
* tc
= GetEditorTextCtrl();
5184 wxString sel
= tc
->GetStringSelection();
5186 CopyTextToClipboard(sel
);
5190 CopyTextToClipboard(m_selected
->GetDisplayedString());
5193 else if ( action
== wxPG_ACTION_CUT
)
5195 wxTextCtrl
* tc
= GetEditorTextCtrl();
5199 tc
->GetSelection(&from
, &to
);
5202 CopyTextToClipboard(tc
->GetStringSelection());
5203 tc
->Remove(from
, to
);
5207 else if ( action
== wxPG_ACTION_PASTE
)
5209 wxTextCtrl
* tc
= GetEditorTextCtrl();
5212 if (wxTheClipboard
->Open())
5214 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5216 wxTextDataObject data
;
5217 wxTheClipboard
->GetData( data
);
5219 tc
->GetSelection(&from
, &to
);
5222 tc
->Remove(from
, to
);
5223 tc
->WriteText(data
.GetText());
5227 tc
->WriteText(data
.GetText());
5230 wxTheClipboard
->Close();
5238 // -----------------------------------------------------------------------
5240 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5244 // Events to editor controls should get relayed here.
5246 wxWindow
* focused
= wxWindow::FindFocus();
5248 wxWindow
* primaryCtrl
= GetEditorControl();
5251 (focused
==primaryCtrl
5252 || m_editorFocused
) )
5254 // Child key must be processed here, since it can
5255 // destroy the control which is referred by its own
5257 HandleChildKey( event
);
5260 HandleKeyEvent( event
);
5263 // -----------------------------------------------------------------------
5265 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5267 m_keyComboConsumed
= 0;
5272 // -----------------------------------------------------------------------
5274 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5276 // Ignore events that occur very close to focus set
5277 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5279 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5284 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5286 int dir
= event
.GetDirection()?1:-1;
5290 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5292 wxWindow
* focused
= wxWindow::FindFocus();
5294 wxWindow
* wndToCheck
= GetEditorControl();
5296 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5297 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5299 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5300 if ( comboTextCtrl
)
5301 wndToCheck
= comboTextCtrl
;
5305 // Because of problems navigating from wxButton, do not go to it.
5308 // No primary, use secondary
5309 wndToCheck = m_wndEditor2;
5311 // If it has editor button, focus to it after the primary editor.
5312 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5313 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5314 // have somewhat debugged in window.cpp itself).
5315 else if ( focused == wndToCheck &&
5317 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5319 wndToCheck = m_wndEditor2;
5320 wxLogDebug(wxT("Exp1"));
5324 if ( focused
!= wndToCheck
&&
5327 wndToCheck
->SetFocus();
5329 // Select all text in wxTextCtrl etc.
5330 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5331 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5333 m_editorFocused
= 1;
5340 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5344 // This allows preventing NavigateOut to occur
5345 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5354 // -----------------------------------------------------------------------
5356 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5358 int keycode
= event
.GetKeyCode();
5360 // Does the keycode trigger button?
5361 if ( keycode
== m_pushButKeyCode
&&
5363 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5364 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5366 m_keyComboConsumed
= 1;
5368 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5369 GetEventHandler()->AddPendingEvent(evt
);
5376 // -----------------------------------------------------------------------
5378 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5380 int keycode
= event
.GetKeyCode();
5382 // Ignore Alt and Control when they are down alone
5383 if ( keycode
== WXK_ALT
||
5384 keycode
== WXK_CONTROL
)
5390 if ( ButtonTriggerKeyTest(event
) )
5393 if ( HandleChildKey(event
) == true )
5396 GetEventHandler()->AddPendingEvent(event
);
5399 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5401 m_keyComboConsumed
= 0;
5403 GetEventHandler()->AddPendingEvent(event
);
5408 // -----------------------------------------------------------------------
5409 // wxPropertyGrid miscellaneous event handling
5410 // -----------------------------------------------------------------------
5412 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5415 // Check if the focus is in this control or one of its children
5416 wxWindow
* newFocused
= wxWindow::FindFocus();
5418 if ( newFocused
!= m_curFocused
)
5419 HandleFocusChange( newFocused
);
5422 // Called by focus event handlers. newFocused is the window that becomes focused.
5423 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5425 unsigned int oldFlags
= m_iFlags
;
5427 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5429 wxWindow
* parent
= newFocused
;
5431 // This must be one of nextFocus' parents.
5434 // Use m_eventObject, which is either wxPropertyGrid or
5435 // wxPropertyGridManager, as appropriate.
5436 if ( parent
== m_eventObject
)
5438 m_iFlags
|= wxPG_FL_FOCUSED
;
5441 parent
= parent
->GetParent();
5444 m_curFocused
= newFocused
;
5446 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5447 (oldFlags
& wxPG_FL_FOCUSED
) )
5449 // On each focus kill, mark the next nav key event
5450 // to be ignored (can't do on set focus since the
5451 // event would occur before it).
5452 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5454 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5456 // Need to store changed value
5457 CommitChangesFromEditor();
5463 // Preliminary code for tab-order respecting
5464 // tab-traversal (but should be moved to
5467 wxWindow* prevFocus = event.GetWindow();
5468 wxWindow* useThis = this;
5469 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5470 useThis = GetParent();
5473 prevFocus->GetParent() == useThis->GetParent() )
5475 wxList& children = useThis->GetParent()->GetChildren();
5477 wxNode* node = children.Find(prevFocus);
5479 if ( node->GetNext() &&
5480 useThis == node->GetNext()->GetData() )
5481 DoSelectProperty(GetFirst());
5482 else if ( node->GetPrevious () &&
5483 useThis == node->GetPrevious()->GetData() )
5484 DoSelectProperty(GetLastProperty());
5489 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5493 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5494 DrawItem( m_selected
);
5498 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5500 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5501 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5502 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5503 //else if ( event.GetWindow() )
5505 HandleFocusChange(event
.GetWindow());
5510 // -----------------------------------------------------------------------
5512 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5514 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5517 // event.Skip() being commented out is aworkaround for bug reported
5518 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5522 // -----------------------------------------------------------------------
5524 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5526 m_iFlags
|= wxPG_FL_SCROLLED
;
5531 // -----------------------------------------------------------------------
5533 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5535 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5537 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5541 // -----------------------------------------------------------------------
5542 // Property editor related functions
5543 // -----------------------------------------------------------------------
5545 // noDefCheck = true prevents infinite recursion.
5546 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorclass
,
5547 const wxString
& name
,
5550 wxASSERT( editorclass
);
5552 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5553 RegisterDefaultEditors();
5555 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorclass
;
5560 // Registers all default editor classes
5561 void wxPropertyGrid::RegisterDefaultEditors()
5563 wxPGRegisterDefaultEditorClass( TextCtrl
);
5564 wxPGRegisterDefaultEditorClass( Choice
);
5565 wxPGRegisterDefaultEditorClass( ComboBox
);
5566 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5567 #if wxPG_INCLUDE_CHECKBOX
5568 wxPGRegisterDefaultEditorClass( CheckBox
);
5570 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5572 // Register SpinCtrl etc. editors before use
5573 RegisterAdditionalEditors();
5576 // -----------------------------------------------------------------------
5577 // wxPGStringTokenizer
5578 // Needed to handle C-style string lists (e.g. "str1" "str2")
5579 // -----------------------------------------------------------------------
5581 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5582 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5586 wxPGStringTokenizer::~wxPGStringTokenizer()
5590 bool wxPGStringTokenizer::HasMoreTokens()
5592 const wxString
& str
= *m_str
;
5594 wxString::const_iterator i
= m_curPos
;
5596 wxUniChar delim
= m_delimeter
;
5598 wxUniChar prev_a
= wxT('\0');
5600 bool inToken
= false;
5602 while ( i
!= str
.end() )
5611 m_readyToken
.clear();
5616 if ( prev_a
!= wxT('\\') )
5620 if ( a
!= wxT('\\') )
5640 m_curPos
= str
.end();
5648 wxString
wxPGStringTokenizer::GetNextToken()
5650 return m_readyToken
;
5653 // -----------------------------------------------------------------------
5655 // -----------------------------------------------------------------------
5657 wxPGChoiceEntry::wxPGChoiceEntry()
5658 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5662 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5663 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5664 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5668 // -----------------------------------------------------------------------
5670 // -----------------------------------------------------------------------
5672 wxPGChoicesData::wxPGChoicesData()
5677 wxPGChoicesData::~wxPGChoicesData()
5682 void wxPGChoicesData::Clear()
5686 for ( i
=0; i
<m_items
.size(); i
++ )
5698 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5700 wxASSERT( m_items
.size() == 0 );
5704 for ( i
=0; i
<data
->GetCount(); i
++ )
5705 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5708 // -----------------------------------------------------------------------
5710 // -----------------------------------------------------------------------
5712 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5716 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5717 m_data
->Insert( -1, p
);
5721 // -----------------------------------------------------------------------
5723 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5727 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5728 p
->SetBitmap(bitmap
);
5729 m_data
->Insert( -1, p
);
5733 // -----------------------------------------------------------------------
5735 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5739 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5740 m_data
->Insert(index
, p
);
5744 // -----------------------------------------------------------------------
5746 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5750 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5751 m_data
->Insert( index
, p
);
5755 // -----------------------------------------------------------------------
5757 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5763 while ( index
< GetCount() )
5765 int cmpRes
= GetLabel(index
).Cmp(label
);
5771 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5772 m_data
->Insert( index
, p
);
5776 // -----------------------------------------------------------------------
5778 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5782 unsigned int itemcount
= 0;
5783 const wxChar
** p
= &labels
[0];
5784 while ( *p
) { p
++; itemcount
++; }
5787 for ( i
= 0; i
< itemcount
; i
++ )
5789 int value
= wxPG_INVALID_VALUE
;
5792 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5796 // -----------------------------------------------------------------------
5798 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5803 unsigned int itemcount
= arr
.size();
5805 for ( i
= 0; i
< itemcount
; i
++ )
5807 int value
= wxPG_INVALID_VALUE
;
5810 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5814 // -----------------------------------------------------------------------
5816 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5821 unsigned int itemcount
= arr
.size();
5823 for ( i
= 0; i
< itemcount
; i
++ )
5825 int value
= wxPG_INVALID_VALUE
;
5826 if ( &arrint
&& arrint
.size() )
5828 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5832 // -----------------------------------------------------------------------
5834 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5836 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5838 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5839 delete m_data
->Item(i
);
5840 m_data
->m_items
.RemoveAt(nIndex
, count
);
5843 // -----------------------------------------------------------------------
5845 int wxPGChoices::Index( const wxString
& str
) const
5850 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5852 if ( m_data
->Item(i
)->GetText() == str
)
5859 // -----------------------------------------------------------------------
5861 int wxPGChoices::Index( int val
) const
5866 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5868 if ( m_data
->Item(i
)->GetValue() == val
)
5875 // -----------------------------------------------------------------------
5877 wxArrayString
wxPGChoices::GetLabels() const
5882 if ( this && IsOk() )
5883 for ( i
=0; i
<GetCount(); i
++ )
5884 arr
.push_back(GetLabel(i
));
5889 // -----------------------------------------------------------------------
5891 bool wxPGChoices::HasValues() const
5896 // -----------------------------------------------------------------------
5898 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5905 for ( i
=0; i
< strings
.size(); i
++ )
5907 int index
= Index(strings
[i
]);
5909 arr
.Add(GetValue(index
));
5911 arr
.Add(wxPG_INVALID_VALUE
);
5918 // -----------------------------------------------------------------------
5920 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5921 wxArrayString
* unmatched
) const
5928 for ( i
=0; i
< strings
.size(); i
++ )
5930 const wxString
& str
= strings
[i
];
5931 int index
= Index(str
);
5934 else if ( unmatched
)
5935 unmatched
->Add(str
);
5942 // -----------------------------------------------------------------------
5944 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5948 if ( data
!= wxPGChoicesEmptyData
)
5955 // -----------------------------------------------------------------------
5957 void wxPGChoices::Init()
5959 m_data
= wxPGChoicesEmptyData
;
5962 // -----------------------------------------------------------------------
5964 void wxPGChoices::Free()
5966 if ( m_data
!= wxPGChoicesEmptyData
)
5969 m_data
= wxPGChoicesEmptyData
;
5973 // -----------------------------------------------------------------------
5974 // wxPropertyGridEvent
5975 // -----------------------------------------------------------------------
5977 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5980 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5981 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5982 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5983 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5984 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5985 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5986 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5987 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5988 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5991 // -----------------------------------------------------------------------
5993 void wxPropertyGridEvent::Init()
5995 m_validationInfo
= NULL
;
5997 m_wasVetoed
= false;
6000 // -----------------------------------------------------------------------
6002 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6003 : wxCommandEvent(commandType
,id
)
6009 // -----------------------------------------------------------------------
6011 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6012 : wxCommandEvent(event
)
6014 m_eventType
= event
.GetEventType();
6015 m_eventObject
= event
.m_eventObject
;
6017 m_property
= event
.m_property
;
6018 m_validationInfo
= event
.m_validationInfo
;
6019 m_canVeto
= event
.m_canVeto
;
6020 m_wasVetoed
= event
.m_wasVetoed
;
6023 // -----------------------------------------------------------------------
6025 wxPropertyGridEvent::~wxPropertyGridEvent()
6029 // -----------------------------------------------------------------------
6031 wxEvent
* wxPropertyGridEvent::Clone() const
6033 return new wxPropertyGridEvent( *this );
6036 void wxPropertyGrid::SetPropertyAttributeAll( const wxString
& attrName
, wxVariant value
)
6038 DoSetPropertyAttribute(GetRoot(), attrName
, value
, wxPG_RECURSE
);
6041 // -----------------------------------------------------------------------
6042 // wxPropertyGridPopulator
6043 // -----------------------------------------------------------------------
6045 wxPropertyGridPopulator::wxPropertyGridPopulator()
6049 wxPGGlobalVars
->m_offline
++;
6052 // -----------------------------------------------------------------------
6054 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6057 m_propHierarchy
.clear();
6060 // -----------------------------------------------------------------------
6062 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6068 // -----------------------------------------------------------------------
6070 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6073 // Free unused sets of choices
6074 wxPGHashMapS2P::iterator it
;
6076 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6078 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6085 m_pg
->GetPanel()->Refresh();
6087 wxPGGlobalVars
->m_offline
--;
6090 // -----------------------------------------------------------------------
6092 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6093 const wxString
& propLabel
,
6094 const wxString
& propName
,
6095 const wxString
* propValue
,
6096 wxPGChoices
* pChoices
)
6098 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6099 wxPGProperty
* parent
= GetCurParent();
6101 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6103 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6107 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6109 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6113 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6115 property
->SetLabel(propLabel
);
6116 property
->DoSetName(propName
);
6118 if ( pChoices
&& pChoices
->IsOk() )
6119 property
->SetChoices(*pChoices
);
6121 m_state
->DoInsert(parent
, -1, property
);
6124 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6129 // -----------------------------------------------------------------------
6131 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6133 m_propHierarchy
.push_back(property
);
6134 DoScanForChildren();
6135 m_propHierarchy
.pop_back();
6138 // -----------------------------------------------------------------------
6140 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6141 const wxString
& idString
)
6143 wxPGChoices choices
;
6146 if ( choicesString
[0] == wxT('@') )
6148 wxString ids
= choicesString
.substr(1);
6149 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6150 if ( it
== m_dictIdChoices
.end() )
6151 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6153 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6158 if ( idString
.length() )
6160 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6161 if ( it
!= m_dictIdChoices
.end() )
6163 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6170 // Parse choices string
6171 wxString::const_iterator it
= choicesString
.begin();
6175 bool labelValid
= false;
6177 for ( ; it
!= choicesString
.end(); it
++ )
6183 if ( c
== wxT('"') )
6188 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6189 choices
.Add(label
, l
);
6192 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6197 else if ( c
== wxT('=') )
6204 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6211 if ( c
== wxT('"') )
6224 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6225 choices
.Add(label
, l
);
6228 if ( !choices
.IsOk() )
6230 choices
.EnsureData();
6234 if ( idString
.length() )
6235 m_dictIdChoices
[idString
] = choices
.GetData();
6242 // -----------------------------------------------------------------------
6244 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6246 if ( s
.Last() == wxT('%') )
6248 wxString s2
= s
.substr(0,s
.length()-1);
6250 if ( s2
.ToLong(&val
, 10) )
6252 *pval
= (val
*max
)/100;
6258 return s
.ToLong(pval
, 10);
6261 // -----------------------------------------------------------------------
6263 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6264 const wxString
& type
,
6265 const wxString
& value
)
6267 int l
= m_propHierarchy
.size();
6271 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6272 wxString valuel
= value
.Lower();
6275 if ( type
.length() == 0 )
6280 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6282 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6284 else if ( value
.ToLong(&v
, 0) )
6291 if ( type
== wxT("string") )
6295 else if ( type
== wxT("int") )
6298 value
.ToLong(&v
, 0);
6301 else if ( type
== wxT("bool") )
6303 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6310 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6315 p
->SetAttribute( name
, variant
);
6320 // -----------------------------------------------------------------------
6322 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6324 wxLogError(_("Error in resource: %s"),msg
.c_str());
6327 // -----------------------------------------------------------------------