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 wxWindow
* editor
= GetEditorControl();
3060 m_pState
->m_anyModified
= 1;
3062 m_inDoPropertyChanged
= 1;
3064 // Maybe need to update control
3065 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3067 // These values were calculated in PerformValidation()
3068 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3069 wxVariant value
= m_chgInfo_pendingValue
;
3071 wxPGProperty
* topPaintedProperty
= changedProperty
;
3073 while ( !topPaintedProperty
->IsCategory() &&
3074 !topPaintedProperty
->IsRoot() )
3076 topPaintedProperty
= topPaintedProperty
->GetParent();
3079 changedProperty
->SetValue(value
, &m_chgInfo_valueList
);
3081 // Set as Modified (not if dragging just began)
3082 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3084 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3085 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3088 SetCurControlBoldFont();
3094 // Propagate updates to parent(s)
3096 wxPGProperty
* prevPwc
= NULL
;
3098 while ( prevPwc
!= topPaintedProperty
)
3100 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3102 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3105 SetCurControlBoldFont();
3109 pwc
= pwc
->GetParent();
3112 // Draw the actual property
3113 DrawItemAndChildren( topPaintedProperty
);
3116 // If value was set by wxPGProperty::OnEvent, then update the editor
3118 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3121 p
->GetEditorClass()->UpdateControl(p
, editor
);
3125 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3126 if ( m_wndEditor
) m_wndEditor
->Refresh();
3127 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3132 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3134 // If top parent has composite string value, then send to child parents,
3135 // starting from baseChangedProperty.
3136 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3138 pwc
= m_chgInfo_baseChangedProperty
;
3140 while ( pwc
!= changedProperty
)
3142 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3143 pwc
= pwc
->GetParent();
3147 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3149 m_inDoPropertyChanged
= 0;
3154 // -----------------------------------------------------------------------
3156 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3158 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3160 m_chgInfo_changedProperty
= NULL
;
3162 if ( PerformValidation(p
, newValue
) )
3164 DoPropertyChanged(p
);
3169 OnValidationFailure(p
, newValue
);
3175 // -----------------------------------------------------------------------
3177 // Runs wxValidator for the selected property
3178 bool wxPropertyGrid::DoEditorValidate()
3180 #if wxUSE_VALIDATORS
3181 // With traditional validator style, we dont need to more
3182 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3185 if ( m_iFlags
& wxPG_FL_VALIDATION_FAILED
)
3190 wxWindow
* wnd
= GetEditorControl();
3192 wxValidator
* validator
= m_selected
->GetValidator();
3193 if ( validator
&& wnd
)
3195 // Use TextCtrl of ODComboBox instead
3196 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3198 wnd
= ((wxOwnerDrawnComboBox
*)wnd
)->GetTextCtrl();
3204 validator
->SetWindow(wnd
);
3206 // Instead setting the flag after the failure, we set
3207 // it before checking and then clear afterwards if things
3208 // went fine. This trick is necessary since focus events
3209 // may be triggered while in Validate.
3210 m_iFlags
|= wxPG_FL_VALIDATION_FAILED
;
3211 if ( !validator
->Validate(this) )
3213 // If you dpm't want to display message multiple times per change,
3214 // comment the following line.
3215 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3218 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3224 // -----------------------------------------------------------------------
3226 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3228 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3229 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3231 wxWindow
* parent
= wnd
->GetParent();
3234 (parent
== m_canvas
||
3235 parent
->GetParent() == m_canvas
) )
3237 OnCustomEditorEvent((wxCommandEvent
&)event
);
3241 return wxPanel::ProcessEvent(event
);
3244 // -----------------------------------------------------------------------
3246 // NB: It may really not be wxCommandEvent - must check if necessary
3248 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3250 wxPGProperty
* selected
= m_selected
;
3253 // Somehow, event is handled after property has been deselected.
3254 // Possibly, but very rare.
3258 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3261 wxVariant
pendingValue(selected
->GetValueRef());
3262 wxWindow
* wnd
= GetEditorControl();
3264 bool wasUnspecified
= selected
->IsValueUnspecified();
3265 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3267 bool valueIsPending
= false;
3269 m_chgInfo_changedProperty
= NULL
;
3271 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3274 // Filter out excess wxTextCtrl modified events
3275 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3277 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3279 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3281 wxString newTcValue
= tc
->GetValue();
3282 if ( m_prevTcValue
== newTcValue
)
3285 m_prevTcValue
= newTcValue
;
3288 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3290 bool validationFailure
= false;
3291 bool buttonWasHandled
= false;
3294 // Try common button handling
3295 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3297 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3301 buttonWasHandled
= true;
3302 // Store as res2, as previously (and still currently alternatively)
3303 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3304 // in wxPGProperty::OnEvent().
3305 adapter
->ShowDialog( this, selected
);
3310 if ( !buttonWasHandled
)
3312 // First call editor class' event handler.
3313 const wxPGEditor
* editor
= selected
->GetEditorClass();
3315 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3317 // If changes, validate them
3318 if ( DoEditorValidate() )
3320 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3321 valueIsPending
= true;
3325 validationFailure
= true;
3329 // Then the property's custom handler (must be always called, unless
3330 // validation failed).
3331 if ( !validationFailure
)
3332 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3335 // SetValueInEvent(), as called in one of the functions referred above
3336 // overrides editor's value.
3337 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3339 valueIsPending
= true;
3340 pendingValue
= m_changeInEventValue
;
3341 selFlags
|= wxPG_SEL_DIALOGVAL
;
3344 if ( !validationFailure
&& valueIsPending
)
3345 if ( !PerformValidation(m_selected
, pendingValue
) )
3346 validationFailure
= true;
3348 if ( validationFailure
)
3350 OnValidationFailure(selected
, pendingValue
);
3352 else if ( valueIsPending
)
3354 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3356 DoPropertyChanged(selected
, selFlags
);
3357 EditorsValueWasNotModified();
3361 // No value after all
3363 // Let unhandled button click events go to the parent
3364 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3366 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3367 GetEventHandler()->AddPendingEvent(evt
);
3371 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3374 // -----------------------------------------------------------------------
3375 // wxPropertyGrid editor control helper methods
3376 // -----------------------------------------------------------------------
3378 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3380 int itemy
= p
->GetY2(m_lineHeight
);
3382 int cust_img_space
= 0;
3383 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3384 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3386 // TODO: If custom image detection changes from current, change this.
3387 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3389 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3390 int imwid
= p
->OnMeasureImage().x
;
3391 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3392 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3397 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3399 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3404 // -----------------------------------------------------------------------
3406 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3408 wxSize sz
= GetImageSize(p
, item
);
3409 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3410 wxPG_CUSTOM_IMAGE_SPACINGY
,
3415 // return size of custom paint image
3416 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3418 // If called with NULL property, then return default image
3419 // size for properties that use image.
3421 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3423 wxSize cis
= p
->OnMeasureImage(item
);
3425 int choiceCount
= p
->GetChoiceCount();
3426 int comVals
= p
->GetDisplayedCommonValueCount();
3427 if ( item
>= choiceCount
&& comVals
> 0 )
3429 unsigned int cvi
= item
-choiceCount
;
3430 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3432 else if ( item
>= 0 && choiceCount
== 0 )
3433 return wxSize(0, 0);
3438 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3443 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3450 // -----------------------------------------------------------------------
3452 // takes scrolling into account
3453 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3456 GetViewStart(&vx
,&vy
);
3457 vy
*=wxPG_PIXELS_PER_UNIT
;
3458 vx
*=wxPG_PIXELS_PER_UNIT
;
3461 ClientToScreen( px
, py
);
3464 // -----------------------------------------------------------------------
3466 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3469 GetViewStart(&pt2
.x
,&pt2
.y
);
3470 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3471 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3475 return m_pState
->HitTest(pt2
);
3478 // -----------------------------------------------------------------------
3480 // custom set cursor
3481 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3483 if ( type
== m_curcursor
&& !override
) return;
3485 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3487 if ( type
== wxCURSOR_SIZEWE
)
3488 cursor
= m_cursorSizeWE
;
3490 m_canvas
->SetCursor( *cursor
);
3495 // -----------------------------------------------------------------------
3496 // wxPropertyGrid property selection
3497 // -----------------------------------------------------------------------
3499 #define CONNECT_CHILD(EVT,FUNCTYPE,FUNC) \
3500 wnd->Connect(id, EVT, \
3501 (wxObjectEventFunction) (wxEventFunction) \
3502 FUNCTYPE (&wxPropertyGrid::FUNC), \
3505 // Setups event handling for child control
3506 void wxPropertyGrid::SetupEventHandling( wxWindow
* argWnd
, int id
)
3508 wxWindow
* wnd
= argWnd
;
3510 if ( argWnd
== m_wndEditor
)
3512 CONNECT_CHILD(wxEVT_MOTION
,(wxMouseEventFunction
),OnMouseMoveChild
)
3513 CONNECT_CHILD(wxEVT_LEFT_UP
,(wxMouseEventFunction
),OnMouseUpChild
)
3514 CONNECT_CHILD(wxEVT_LEFT_DOWN
,(wxMouseEventFunction
),OnMouseClickChild
)
3515 CONNECT_CHILD(wxEVT_RIGHT_UP
,(wxMouseEventFunction
),OnMouseRightClickChild
)
3516 CONNECT_CHILD(wxEVT_ENTER_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3517 CONNECT_CHILD(wxEVT_LEAVE_WINDOW
,(wxMouseEventFunction
),OnMouseEntry
)
3521 CONNECT_CHILD(wxEVT_NAVIGATION_KEY
,(wxNavigationKeyEventFunction
),OnNavigationKey
)
3523 CONNECT_CHILD(wxEVT_KEY_DOWN
,(wxCharEventFunction
),OnChildKeyDown
)
3524 CONNECT_CHILD(wxEVT_KEY_UP
,(wxCharEventFunction
),OnChildKeyUp
)
3525 CONNECT_CHILD(wxEVT_KILL_FOCUS
,(wxFocusEventFunction
),OnFocusEvent
)
3528 void wxPropertyGrid::FreeEditors()
3530 // Do not free editors immediately if processing events
3531 if ( !m_windowsToDelete
)
3532 m_windowsToDelete
= new wxArrayPtrVoid
;
3536 m_windowsToDelete
->push_back(m_wndEditor2
);
3537 m_wndEditor2
->Hide();
3538 m_wndEditor2
= (wxWindow
*) NULL
;
3543 m_windowsToDelete
->push_back(m_wndEditor
);
3544 m_wndEditor
->Hide();
3545 m_wndEditor
= (wxWindow
*) NULL
;
3549 // Call with NULL to de-select property
3550 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3554 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3555 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3557 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3560 if ( m_inDoSelectProperty
)
3563 m_inDoSelectProperty
= 1;
3565 wxPGProperty
* prev
= m_selected
;
3568 // Delete windows pending for deletion
3569 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3573 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3574 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3576 m_windowsToDelete
->clear();
3581 m_inDoSelectProperty
= 0;
3586 // If we are frozen, then just set the values.
3589 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3590 m_editorFocused
= 0;
3593 m_pState
->m_selected
= p
;
3595 // If frozen, always free controls. But don't worry, as Thaw will
3596 // recall SelectProperty to recreate them.
3599 // Prevent any further selection measures in this call
3600 p
= (wxPGProperty
*) NULL
;
3605 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3607 // Only set focus if not deselecting
3610 if ( flags
& wxPG_SEL_FOCUS
)
3614 m_wndEditor
->SetFocus();
3615 m_editorFocused
= 1;
3620 wxScrolledWindow::SetFocus();
3621 m_editorFocused
= 0;
3625 m_inDoSelectProperty
= 0;
3630 // First, deactivate previous
3634 OnValidationFailureReset(m_selected
);
3636 // Must double-check if this is an selected in case of forceswitch
3639 if ( !CommitChangesFromEditor(flags
) )
3641 // Validation has failed, so we can't exit the previous editor
3642 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3643 // _("Invalid Value"),wxOK|wxICON_ERROR);
3644 m_inDoSelectProperty
= 0;
3652 m_selected
= (wxPGProperty
*) NULL
;
3653 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3655 // We need to always fully refresh the grid here
3658 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3659 EditorsValueWasNotModified();
3662 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3665 // Then, activate the one given.
3668 int propY
= p
->GetY2(m_lineHeight
);
3670 int splitterX
= GetSplitterPosition();
3671 m_editorFocused
= 0;
3673 m_pState
->m_selected
= p
;
3674 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3676 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3678 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3680 // Do we need OnMeasureCalls?
3681 wxSize imsz
= p
->OnMeasureImage();
3684 // Only create editor for non-disabled non-caption
3685 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3687 // do this for non-caption items
3691 // Do we need to paint the custom image, if any?
3692 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3693 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3694 !p
->GetEditorClass()->CanContainCustomImage()
3696 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3698 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3699 wxPoint goodPos
= grect
.GetPosition();
3700 #if wxPG_CREATE_CONTROLS_HIDDEN
3701 int coord_adjust
= m_height
- goodPos
.y
;
3702 goodPos
.y
+= coord_adjust
;
3705 const wxPGEditor
* editor
= p
->GetEditorClass();
3706 wxCHECK_MSG(editor
, false,
3707 wxT("NULL editor class not allowed"));
3709 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3711 wxPGWindowList wndList
= editor
->CreateControls(this,
3716 m_wndEditor
= wndList
.m_primary
;
3717 m_wndEditor2
= wndList
.m_secondary
;
3719 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3720 // value is drawn as normal, and m_wndEditor2 is assumed
3721 // to be a right-aligned button that triggers a separate editor
3726 wxASSERT_MSG( m_wndEditor
->GetParent() == m_canvas
,
3727 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3729 // Set validator, if any
3730 #if wxUSE_VALIDATORS
3731 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3733 wxValidator
* validator
= p
->GetValidator();
3735 m_wndEditor
->SetValidator(*validator
);
3739 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3740 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3742 // If it has modified status, use bold font
3743 // (must be done before capturing m_ctrlXAdjust)
3744 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3745 SetCurControlBoldFont();
3748 // Fix TextCtrl indentation
3749 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3750 wxTextCtrl
* tc
= NULL
;
3751 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3752 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3754 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3756 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3759 // Store x relative to splitter (we'll need it).
3760 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3762 // Check if background clear is not necessary
3763 wxPoint pos
= m_wndEditor
->GetPosition();
3764 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3766 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3769 m_wndEditor
->SetSizeHints(3, 3);
3771 #if wxPG_CREATE_CONTROLS_HIDDEN
3772 m_wndEditor
->Show(false);
3773 m_wndEditor
->Freeze();
3775 goodPos
= m_wndEditor
->GetPosition();
3776 goodPos
.y
-= coord_adjust
;
3777 m_wndEditor
->Move( goodPos
);
3780 wxWindow
* primaryCtrl
= GetEditorControl();
3781 SetupEventHandling(primaryCtrl
, wxPG_SUBID1
);
3783 // Focus and select all (wxTextCtrl, wxComboBox etc)
3784 if ( flags
& wxPG_SEL_FOCUS
)
3786 primaryCtrl
->SetFocus();
3788 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3794 wxASSERT_MSG( m_wndEditor2
->GetParent() == m_canvas
,
3795 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3797 // Get proper id for wndSecondary
3798 m_wndSecId
= m_wndEditor2
->GetId();
3799 wxWindowList children
= m_wndEditor2
->GetChildren();
3800 wxWindowList::iterator node
= children
.begin();
3801 if ( node
!= children
.end() )
3802 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3804 m_wndEditor2
->SetSizeHints(3,3);
3806 #if wxPG_CREATE_CONTROLS_HIDDEN
3807 wxRect sec_rect
= m_wndEditor2
->GetRect();
3808 sec_rect
.y
-= coord_adjust
;
3810 // Fine tuning required to fix "oversized"
3811 // button disappearance bug.
3812 if ( sec_rect
.y
< 0 )
3814 sec_rect
.height
+= sec_rect
.y
;
3817 m_wndEditor2
->SetSize( sec_rect
);
3819 m_wndEditor2
->Show();
3821 SetupEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3823 // If no primary editor, focus to button to allow
3824 // it to interprete ENTER etc.
3825 // NOTE: Due to problems focusing away from it, this
3826 // has been disabled.
3828 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3829 m_wndEditor2->SetFocus();
3833 if ( flags
& wxPG_SEL_FOCUS
)
3834 m_editorFocused
= 1;
3839 // wxGTK atleast seems to need this (wxMSW not)
3843 EditorsValueWasNotModified();
3845 // If it's inside collapsed section, expand parent, scroll, etc.
3846 // Also, if it was partially visible, scroll it into view.
3847 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3852 #if wxPG_CREATE_CONTROLS_HIDDEN
3853 m_wndEditor
->Thaw();
3855 m_wndEditor
->Show(true);
3861 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3867 // Show help text in status bar.
3868 // (if found and grid not embedded in manager with help box and
3869 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3872 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3874 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3875 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3877 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3879 statusbar
= frame
->GetStatusBar();
3884 const wxString
* pHelpString
= (const wxString
*) NULL
;
3888 pHelpString
= &p
->GetHelpString();
3889 if ( pHelpString
->length() )
3891 // Set help box text.
3892 statusbar
->SetStatusText( *pHelpString
);
3893 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3897 if ( (!pHelpString
|| !pHelpString
->length()) &&
3898 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3900 // Clear help box - but only if it was written
3901 // by us at previous time.
3902 statusbar
->SetStatusText( m_emptyString
);
3903 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3909 m_inDoSelectProperty
= 0;
3911 // call wx event handler (here so that it also occurs on deselection)
3912 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3917 // -----------------------------------------------------------------------
3919 bool wxPropertyGrid::UnfocusEditor()
3921 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3924 if ( !CommitChangesFromEditor(0) )
3927 m_canvas
->SetFocusIgnoringChildren();
3928 DrawItem(m_selected
);
3933 // -----------------------------------------------------------------------
3935 // This method is not inline because it called dozens of times
3936 // (i.e. two-arg function calls create smaller code size).
3937 bool wxPropertyGrid::DoClearSelection()
3939 return DoSelectProperty((wxPGProperty
*)NULL
);
3942 // -----------------------------------------------------------------------
3943 // wxPropertyGrid expand/collapse state
3944 // -----------------------------------------------------------------------
3946 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3948 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3950 // If active editor was inside collapsed section, then disable it
3951 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3953 if ( !ClearSelection() )
3957 // Store dont-center-splitter flag 'cause we need to temporarily set it
3958 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3959 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3961 bool res
= m_pState
->DoCollapse(pwc
);
3966 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3968 RecalculateVirtualSize();
3970 // Redraw etc. only if collapsed was visible.
3971 if (pwc
->IsVisible() &&
3973 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3975 // When item is collapsed so that scrollbar would move,
3976 // graphics mess is about (unless we redraw everything).
3981 // Clear dont-center-splitter flag if it wasn't set
3982 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3987 // -----------------------------------------------------------------------
3989 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3991 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3993 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3995 // Store dont-center-splitter flag 'cause we need to temporarily set it
3996 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3997 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3999 bool res
= m_pState
->DoExpand(pwc
);
4004 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
4006 RecalculateVirtualSize();
4008 // Redraw etc. only if expanded was visible.
4009 if ( pwc
->IsVisible() && !m_frozen
&&
4010 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
4014 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4017 DrawItems(pwc
, NULL
);
4022 // Clear dont-center-splitter flag if it wasn't set
4023 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
4028 // -----------------------------------------------------------------------
4030 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
4033 return m_pState
->DoHideProperty(p
, hide
, flags
);
4036 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
4039 if ( !ClearSelection() )
4043 m_pState
->DoHideProperty(p
, hide
, flags
);
4045 RecalculateVirtualSize();
4052 // -----------------------------------------------------------------------
4053 // wxPropertyGrid size related methods
4054 // -----------------------------------------------------------------------
4056 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4058 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4062 // If virtual height was changed, then recalculate editor control position(s)
4063 if ( m_pState
->m_vhCalcPending
)
4064 CorrectEditorWidgetPosY();
4066 m_pState
->EnsureVirtualHeight();
4069 int by1
= m_pState
->GetVirtualHeight();
4070 int by2
= m_pState
->GetActualVirtualHeight();
4073 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4074 wxASSERT_MSG( false,
4080 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4082 int x
= m_pState
->m_width
;
4083 int y
= m_pState
->m_virtualHeight
;
4086 GetClientSize(&width
,&height
);
4088 // Now adjust virtual size.
4089 SetVirtualSize(x
, y
);
4095 // Adjust scrollbars
4096 if ( HasVirtualWidth() )
4098 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4099 xPos
= GetScrollPos( wxHORIZONTAL
);
4102 if ( forceXPos
!= -1 )
4105 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4108 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4109 int yPos
= GetScrollPos( wxVERTICAL
);
4111 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4112 xAmount
, yAmount
, xPos
, yPos
, true );
4114 // Must re-get size now
4115 GetClientSize(&width
,&height
);
4117 if ( !HasVirtualWidth() )
4119 m_pState
->SetVirtualWidth(width
);
4126 m_canvas
->SetSize( x
, y
);
4128 m_pState
->CheckColumnWidths();
4131 CorrectEditorWidgetSizeX();
4133 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4136 // -----------------------------------------------------------------------
4138 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4140 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4144 GetClientSize(&width
,&height
);
4149 #if wxPG_DOUBLE_BUFFER
4150 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4152 int dblh
= (m_lineHeight
*2);
4153 if ( !m_doubleBuffer
)
4155 // Create double buffer bitmap to draw on, if none
4156 int w
= (width
>250)?width
:250;
4157 int h
= height
+ dblh
;
4159 m_doubleBuffer
= new wxBitmap( w
, h
);
4163 int w
= m_doubleBuffer
->GetWidth();
4164 int h
= m_doubleBuffer
->GetHeight();
4166 // Double buffer must be large enough
4167 if ( w
< width
|| h
< (height
+dblh
) )
4169 if ( w
< width
) w
= width
;
4170 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4171 delete m_doubleBuffer
;
4172 m_doubleBuffer
= new wxBitmap( w
, h
);
4179 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4180 m_ncWidth
= event
.GetSize().x
;
4184 if ( m_pState
->m_itemsAdded
)
4185 PrepareAfterItemsAdded();
4187 // Without this, virtual size (atleast under wxGTK) will be skewed
4188 RecalculateVirtualSize();
4194 // -----------------------------------------------------------------------
4196 void wxPropertyGrid::SetVirtualWidth( int width
)
4200 // Disable virtual width
4201 width
= GetClientSize().x
;
4202 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4206 // Enable virtual width
4207 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4209 m_pState
->SetVirtualWidth( width
);
4212 // -----------------------------------------------------------------------
4213 // wxPropertyGrid mouse event handling
4214 // -----------------------------------------------------------------------
4216 // selFlags uses same values DoSelectProperty's flags
4217 // Returns true if event was vetoed.
4218 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4220 // Send property grid event of specific type and with specific property
4221 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4222 evt
.SetPropertyGrid(this);
4223 evt
.SetEventObject(m_eventObject
);
4227 evt
.SetCanVeto(true);
4228 evt
.SetupValidationInfo();
4229 m_validationInfo
.m_pValue
= pValue
;
4231 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4233 evtHandler
->ProcessEvent(evt
);
4235 return evt
.WasVetoed();
4238 // -----------------------------------------------------------------------
4240 // Return false if should be skipped
4241 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4245 // Need to set focus?
4246 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4248 m_canvas
->SetFocus();
4251 wxPropertyGridPageState
* state
= m_pState
;
4253 int splitterHitOffset
;
4254 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4256 wxPGProperty
* p
= DoGetItemAtY(y
);
4260 int depth
= (int)p
->GetDepth() - 1;
4262 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4264 if ( x
>= marginEnds
)
4268 if ( p
->IsCategory() )
4270 // This is category.
4271 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4273 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4275 // Expand, collapse, activate etc. if click on text or left of splitter.
4278 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4283 if ( !DoSelectProperty( p
) )
4286 // On double-click, expand/collapse.
4287 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4289 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4290 else DoExpand( p
, true );
4294 else if ( splitterHit
== -1 )
4297 unsigned int selFlag
= 0;
4298 if ( columnHit
== 1 )
4300 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4301 selFlag
= wxPG_SEL_FOCUS
;
4303 if ( !DoSelectProperty( p
, selFlag
) )
4306 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4308 if ( p
->GetChildCount() && !p
->IsCategory() )
4309 // On double-click, expand/collapse.
4310 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4312 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4313 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4314 else DoExpand( p
, true );
4321 // click on splitter
4322 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4324 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4326 // Double-clicking the splitter causes auto-centering
4327 CenterSplitter( true );
4329 else if ( m_dragStatus
== 0 )
4332 // Begin draggin the splitter
4336 // Changes must be committed here or the
4337 // value won't be drawn correctly
4338 if ( !CommitChangesFromEditor() )
4341 m_wndEditor
->Show ( false );
4344 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4346 m_canvas
->CaptureMouse();
4347 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4351 m_draggedSplitter
= splitterHit
;
4352 m_dragOffset
= splitterHitOffset
;
4354 wxClientDC
dc(m_canvas
);
4356 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4357 // Fixes button disappearance bug
4359 m_wndEditor2
->Show ( false );
4362 m_startingSplitterX
= x
- splitterHitOffset
;
4370 if ( p
->GetChildCount() )
4372 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4374 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4376 int y2
= y
% m_lineHeight
;
4377 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4379 // On click on expander button, expand/collapse
4380 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4381 DoCollapse( p
, true );
4383 DoExpand( p
, true );
4392 // -----------------------------------------------------------------------
4394 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4395 wxMouseEvent
& WXUNUSED(event
) )
4399 // Select property here as well
4400 wxPGProperty
* p
= m_propHover
;
4401 if ( p
!= m_selected
)
4402 DoSelectProperty( p
);
4404 // Send right click event.
4405 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4412 // -----------------------------------------------------------------------
4414 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4415 wxMouseEvent
& WXUNUSED(event
) )
4419 // Select property here as well
4420 wxPGProperty
* p
= m_propHover
;
4422 if ( p
!= m_selected
)
4423 DoSelectProperty( p
);
4425 // Send double-click event.
4426 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4433 // -----------------------------------------------------------------------
4435 #if wxPG_SUPPORT_TOOLTIPS
4437 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4439 if ( tipString
.length() )
4441 m_canvas
->SetToolTip(tipString
);
4445 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4446 m_canvas
->SetToolTip( m_emptyString
);
4448 m_canvas
->SetToolTip( NULL
);
4453 #endif // #if wxPG_SUPPORT_TOOLTIPS
4455 // -----------------------------------------------------------------------
4457 // Return false if should be skipped
4458 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4460 // Safety check (needed because mouse capturing may
4461 // otherwise freeze the control)
4462 if ( m_dragStatus
> 0 && !event
.Dragging() )
4464 HandleMouseUp(x
,y
,event
);
4467 wxPropertyGridPageState
* state
= m_pState
;
4469 int splitterHitOffset
;
4470 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4471 int splitterX
= x
- splitterHitOffset
;
4473 if ( m_dragStatus
> 0 )
4475 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4476 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4479 int newSplitterX
= x
- m_dragOffset
;
4480 int splitterX
= x
- splitterHitOffset
;
4482 // Splitter redraw required?
4483 if ( newSplitterX
!= splitterX
)
4486 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4487 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4488 state
->m_fSplitterX
= (float) newSplitterX
;
4491 CorrectEditorWidgetSizeX();
4505 int ih
= m_lineHeight
;
4508 #if wxPG_SUPPORT_TOOLTIPS
4509 wxPGProperty
* prevHover
= m_propHover
;
4510 unsigned char prevSide
= m_mouseSide
;
4512 int curPropHoverY
= y
- (y
% ih
);
4514 // On which item it hovers
4515 if ( ( !m_propHover
)
4517 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4520 // Mouse moves on another property
4522 m_propHover
= DoGetItemAtY(y
);
4523 m_propHoverY
= curPropHoverY
;
4526 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4529 #if wxPG_SUPPORT_TOOLTIPS
4530 // Store which side we are on
4532 if ( columnHit
== 1 )
4534 else if ( columnHit
== 0 )
4538 // If tooltips are enabled, show label or value as a tip
4539 // in case it doesn't otherwise show in full length.
4541 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4543 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4545 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4547 if ( m_propHover
&& !m_propHover
->IsCategory() )
4550 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4552 // Show help string as a tooltip
4553 wxString tipString
= m_propHover
->GetHelpString();
4555 SetToolTip(tipString
);
4559 // Show cropped value string as a tooltip
4563 if ( m_mouseSide
== 1 )
4565 tipString
= m_propHover
->m_label
;
4566 space
= splitterX
-m_marginWidth
-3;
4568 else if ( m_mouseSide
== 2 )
4570 tipString
= m_propHover
->GetDisplayedString();
4572 space
= m_width
- splitterX
;
4573 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4574 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4580 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4583 SetToolTip( tipString
);
4590 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4591 m_canvas
->SetToolTip( m_emptyString
);
4593 m_canvas
->SetToolTip( NULL
);
4604 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4605 m_canvas
->SetToolTip( m_emptyString
);
4607 m_canvas
->SetToolTip( NULL
);
4615 if ( splitterHit
== -1 ||
4617 HasFlag(wxPG_STATIC_SPLITTER
) )
4619 // hovering on something else
4620 if ( m_curcursor
!= wxCURSOR_ARROW
)
4621 CustomSetCursor( wxCURSOR_ARROW
);
4625 // Do not allow splitter cursor on caption items.
4626 // (also not if we were dragging and its started
4627 // outside the splitter region)
4630 !m_propHover
->IsCategory() &&
4634 // hovering on splitter
4636 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4637 // reliably detected.
4638 //if ( m_curcursor != wxCURSOR_SIZEWE )
4639 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4645 // hovering on something else
4646 if ( m_curcursor
!= wxCURSOR_ARROW
)
4647 CustomSetCursor( wxCURSOR_ARROW
);
4654 // -----------------------------------------------------------------------
4656 // Also handles Leaving event
4657 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4658 wxMouseEvent
&WXUNUSED(event
) )
4660 wxPropertyGridPageState
* state
= m_pState
;
4664 int splitterHitOffset
;
4665 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4667 // No event type check - basicly calling this method should
4668 // just stop dragging.
4669 // Left up after dragged?
4670 if ( m_dragStatus
>= 1 )
4673 // End Splitter Dragging
4675 // DO NOT ENABLE FOLLOWING LINE!
4676 // (it is only here as a reminder to not to do it)
4679 // Disable splitter auto-centering
4680 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4682 // This is necessary to return cursor
4683 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4685 m_canvas
->ReleaseMouse();
4686 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4689 // Set back the default cursor, if necessary
4690 if ( splitterHit
== -1 ||
4693 CustomSetCursor( wxCURSOR_ARROW
);
4698 // Control background needs to be cleared
4699 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4700 DrawItem( m_selected
);
4704 m_wndEditor
->Show ( true );
4707 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4708 // Fixes button disappearance bug
4710 m_wndEditor2
->Show ( true );
4713 // This clears the focus.
4714 m_editorFocused
= 0;
4720 // -----------------------------------------------------------------------
4722 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4724 int splitterX
= GetSplitterPosition();
4727 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4731 wxWindow
* wnd
= m_wndEditor
;
4733 // Hide popup on clicks
4734 if ( event
.GetEventType() != wxEVT_MOTION
)
4735 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4737 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4743 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4745 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4746 ux
>= (r
.x
+r
.width
) ||
4748 event
.m_y
>= (r
.y
+r
.height
)
4758 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4763 // -----------------------------------------------------------------------
4765 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4768 if ( OnMouseCommon( event
, &x
, &y
) )
4770 HandleMouseClick(x
,y
,event
);
4775 // -----------------------------------------------------------------------
4777 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4780 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4781 HandleMouseRightClick(x
,y
,event
);
4785 // -----------------------------------------------------------------------
4787 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4789 // Always run standard mouse-down handler as well
4790 OnMouseClick(event
);
4793 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4794 HandleMouseDoubleClick(x
,y
,event
);
4798 // -----------------------------------------------------------------------
4800 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4803 if ( OnMouseCommon( event
, &x
, &y
) )
4805 HandleMouseMove(x
,y
,event
);
4810 // -----------------------------------------------------------------------
4812 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4814 // Called when mouse moves in the empty space below the properties.
4815 CustomSetCursor( wxCURSOR_ARROW
);
4818 // -----------------------------------------------------------------------
4820 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4823 if ( OnMouseCommon( event
, &x
, &y
) )
4825 HandleMouseUp(x
,y
,event
);
4830 // -----------------------------------------------------------------------
4832 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4834 // This may get called from child control as well, so event's
4835 // mouse position cannot be relied on.
4837 if ( event
.Entering() )
4839 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4841 // TODO: Fix this (detect parent and only do
4842 // cursor trick if it is a manager).
4843 wxASSERT( GetParent() );
4844 GetParent()->SetCursor(wxNullCursor
);
4846 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4849 GetParent()->SetCursor(wxNullCursor
);
4851 else if ( event
.Leaving() )
4853 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4854 m_canvas
->SetCursor( wxNullCursor
);
4856 // Get real cursor position
4857 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4859 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4862 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4864 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4868 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4876 // -----------------------------------------------------------------------
4878 // Common code used by various OnMouseXXXChild methods.
4879 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4881 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4882 wxASSERT( topCtrlWnd
);
4884 event
.GetPosition(&x
,&y
);
4886 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4888 int splitterX
= GetSplitterPosition();
4890 wxRect r
= topCtrlWnd
->GetRect();
4891 if ( !m_dragStatus
&&
4892 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4893 y
>= 0 && y
< r
.height \
4896 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4901 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4908 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4911 if ( OnMouseChildCommon(event
,&x
,&y
) )
4913 bool res
= HandleMouseClick(x
,y
,event
);
4914 if ( !res
) event
.Skip();
4918 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4921 wxASSERT( m_wndEditor
);
4922 // These coords may not be exact (about +-2),
4923 // but that should not matter (right click is about item, not position).
4924 wxPoint pt
= m_wndEditor
->GetPosition();
4925 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4926 wxASSERT( m_selected
);
4927 m_propHover
= m_selected
;
4928 bool res
= HandleMouseRightClick(x
,y
,event
);
4929 if ( !res
) event
.Skip();
4932 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4935 if ( OnMouseChildCommon(event
,&x
,&y
) )
4937 bool res
= HandleMouseMove(x
,y
,event
);
4938 if ( !res
) event
.Skip();
4942 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4945 if ( OnMouseChildCommon(event
,&x
,&y
) )
4947 bool res
= HandleMouseUp(x
,y
,event
);
4948 if ( !res
) event
.Skip();
4952 // -----------------------------------------------------------------------
4953 // wxPropertyGrid keyboard event handling
4954 // -----------------------------------------------------------------------
4956 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4958 wxNavigationKeyEvent evt
;
4959 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4960 (dir
?wxNavigationKeyEvent::IsForward
:
4961 wxNavigationKeyEvent::IsBackward
));
4962 evt
.SetEventObject(this);
4963 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4967 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4969 // Translates wxKeyEvent to wxPG_ACTION_XXX
4971 int keycode
= event
.GetKeyCode();
4972 int modifiers
= event
.GetModifiers();
4974 wxASSERT( !(modifiers
&~(0xFFFF)) );
4976 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4978 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4980 if ( it
== m_actionTriggers
.end() )
4985 int second
= (it
->second
>>16) & 0xFFFF;
4989 return (it
->second
& 0xFFFF);
4992 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4994 wxASSERT( !(modifiers
&~(0xFFFF)) );
4996 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4998 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
5000 if ( it
!= m_actionTriggers
.end() )
5002 // This key combination is already used
5004 // Can add secondary?
5005 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
5006 wxT("You can only add up to two separate actions per key combination.") );
5008 action
= it
->second
| (action
<<16);
5011 m_actionTriggers
[hashMapKey
] = action
;
5014 void wxPropertyGrid::ClearActionTriggers( int action
)
5016 wxPGHashMapI2I::iterator it
;
5018 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
5020 if ( it
->second
== action
)
5022 m_actionTriggers
.erase(it
);
5027 static void CopyTextToClipboard( const wxString
& text
)
5029 if ( wxTheClipboard
->Open() )
5031 // This data objects are held by the clipboard,
5032 // so do not delete them in the app.
5033 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
5034 wxTheClipboard
->Close();
5038 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5041 // Handles key event when editor control is not focused.
5044 wxASSERT( !m_frozen
);
5048 // Travelsal between items, collapsing/expanding, etc.
5049 int keycode
= event
.GetKeyCode();
5051 if ( keycode
== WXK_TAB
)
5053 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5057 // Ignore Alt and Control when they are down alone
5058 if ( keycode
== WXK_ALT
||
5059 keycode
== WXK_CONTROL
)
5066 int action
= KeyEventToActions(event
, &secondAction
);
5072 if ( ButtonTriggerKeyTest(event
) )
5075 wxPGProperty
* p
= m_selected
;
5077 if ( action
== wxPG_ACTION_COPY
)
5079 CopyTextToClipboard(p
->GetDisplayedString());
5083 // Travel and expand/collapse
5086 if ( p
->GetChildCount() &&
5087 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5090 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5092 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5095 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5097 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5104 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5108 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5119 if ( selectDir
>= -1 )
5121 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5123 DoSelectProperty(p
);
5129 // If nothing was selected, select the first item now
5130 // (or navigate out of tab).
5131 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5133 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5134 if ( p
) DoSelectProperty(p
);
5139 // -----------------------------------------------------------------------
5141 // Potentially handles a keyboard event for editor controls.
5142 // Returns false if event should *not* be skipped (on true it can
5143 // be optionally skipped).
5144 // Basicly, false means that SelectProperty was called (or was about
5145 // to be called, if canDestroy was false).
5146 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5150 if ( !m_selected
|| !m_wndEditor
)
5155 int action
= KeyEventToAction(event
);
5158 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5161 // Esc cancels any changes
5162 if ( IsEditorsValueModified() )
5164 EditorsValueWasNotModified();
5166 // Update the control as well
5167 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5169 m_selected
->GetDisplayedString() );
5172 OnValidationFailureReset(m_selected
);
5178 else if ( action
== wxPG_ACTION_COPY
)
5180 // NB: There is some problem with getting native cut-copy-paste keys to go through
5181 // for embedded editor wxTextCtrl. This is why we emulate.
5183 wxTextCtrl
* tc
= GetEditorTextCtrl();
5186 wxString sel
= tc
->GetStringSelection();
5188 CopyTextToClipboard(sel
);
5192 CopyTextToClipboard(m_selected
->GetDisplayedString());
5195 else if ( action
== wxPG_ACTION_CUT
)
5197 wxTextCtrl
* tc
= GetEditorTextCtrl();
5201 tc
->GetSelection(&from
, &to
);
5204 CopyTextToClipboard(tc
->GetStringSelection());
5205 tc
->Remove(from
, to
);
5209 else if ( action
== wxPG_ACTION_PASTE
)
5211 wxTextCtrl
* tc
= GetEditorTextCtrl();
5214 if (wxTheClipboard
->Open())
5216 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5218 wxTextDataObject data
;
5219 wxTheClipboard
->GetData( data
);
5221 tc
->GetSelection(&from
, &to
);
5224 tc
->Remove(from
, to
);
5225 tc
->WriteText(data
.GetText());
5229 tc
->WriteText(data
.GetText());
5232 wxTheClipboard
->Close();
5240 // -----------------------------------------------------------------------
5242 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5246 // Events to editor controls should get relayed here.
5248 wxWindow
* focused
= wxWindow::FindFocus();
5250 wxWindow
* primaryCtrl
= GetEditorControl();
5253 (focused
==primaryCtrl
5254 || m_editorFocused
) )
5256 // Child key must be processed here, since it can
5257 // destroy the control which is referred by its own
5259 HandleChildKey( event
);
5262 HandleKeyEvent( event
);
5265 // -----------------------------------------------------------------------
5267 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5269 m_keyComboConsumed
= 0;
5274 // -----------------------------------------------------------------------
5276 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5278 // Ignore events that occur very close to focus set
5279 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5281 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5286 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5288 int dir
= event
.GetDirection()?1:-1;
5292 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5294 wxWindow
* focused
= wxWindow::FindFocus();
5296 wxWindow
* wndToCheck
= GetEditorControl();
5298 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5299 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5301 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5302 if ( comboTextCtrl
)
5303 wndToCheck
= comboTextCtrl
;
5307 // Because of problems navigating from wxButton, do not go to it.
5310 // No primary, use secondary
5311 wndToCheck = m_wndEditor2;
5313 // If it has editor button, focus to it after the primary editor.
5314 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5315 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5316 // have somewhat debugged in window.cpp itself).
5317 else if ( focused == wndToCheck &&
5319 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5321 wndToCheck = m_wndEditor2;
5322 wxLogDebug(wxT("Exp1"));
5326 if ( focused
!= wndToCheck
&&
5329 wndToCheck
->SetFocus();
5331 // Select all text in wxTextCtrl etc.
5332 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5333 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5335 m_editorFocused
= 1;
5342 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5346 // This allows preventing NavigateOut to occur
5347 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5356 // -----------------------------------------------------------------------
5358 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5360 int keycode
= event
.GetKeyCode();
5362 // Does the keycode trigger button?
5363 if ( keycode
== m_pushButKeyCode
&&
5365 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5366 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5368 m_keyComboConsumed
= 1;
5370 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5371 GetEventHandler()->AddPendingEvent(evt
);
5378 // -----------------------------------------------------------------------
5380 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5382 int keycode
= event
.GetKeyCode();
5384 // Ignore Alt and Control when they are down alone
5385 if ( keycode
== WXK_ALT
||
5386 keycode
== WXK_CONTROL
)
5392 if ( ButtonTriggerKeyTest(event
) )
5395 if ( HandleChildKey(event
) == true )
5398 GetEventHandler()->AddPendingEvent(event
);
5401 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5403 m_keyComboConsumed
= 0;
5405 GetEventHandler()->AddPendingEvent(event
);
5410 // -----------------------------------------------------------------------
5411 // wxPropertyGrid miscellaneous event handling
5412 // -----------------------------------------------------------------------
5414 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5417 // Check if the focus is in this control or one of its children
5418 wxWindow
* newFocused
= wxWindow::FindFocus();
5420 if ( newFocused
!= m_curFocused
)
5421 HandleFocusChange( newFocused
);
5424 // Called by focus event handlers. newFocused is the window that becomes focused.
5425 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5427 unsigned int oldFlags
= m_iFlags
;
5429 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5431 wxWindow
* parent
= newFocused
;
5433 // This must be one of nextFocus' parents.
5436 // Use m_eventObject, which is either wxPropertyGrid or
5437 // wxPropertyGridManager, as appropriate.
5438 if ( parent
== m_eventObject
)
5440 m_iFlags
|= wxPG_FL_FOCUSED
;
5443 parent
= parent
->GetParent();
5446 m_curFocused
= newFocused
;
5448 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5449 (oldFlags
& wxPG_FL_FOCUSED
) )
5451 // On each focus kill, mark the next nav key event
5452 // to be ignored (can't do on set focus since the
5453 // event would occur before it).
5454 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5456 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5458 // Need to store changed value
5459 CommitChangesFromEditor();
5465 // Preliminary code for tab-order respecting
5466 // tab-traversal (but should be moved to
5469 wxWindow* prevFocus = event.GetWindow();
5470 wxWindow* useThis = this;
5471 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5472 useThis = GetParent();
5475 prevFocus->GetParent() == useThis->GetParent() )
5477 wxList& children = useThis->GetParent()->GetChildren();
5479 wxNode* node = children.Find(prevFocus);
5481 if ( node->GetNext() &&
5482 useThis == node->GetNext()->GetData() )
5483 DoSelectProperty(GetFirst());
5484 else if ( node->GetPrevious () &&
5485 useThis == node->GetPrevious()->GetData() )
5486 DoSelectProperty(GetLastProperty());
5491 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5495 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5496 DrawItem( m_selected
);
5500 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5502 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5503 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5504 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5505 //else if ( event.GetWindow() )
5507 HandleFocusChange(event
.GetWindow());
5512 // -----------------------------------------------------------------------
5514 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5516 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5519 // event.Skip() being commented out is aworkaround for bug reported
5520 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5524 // -----------------------------------------------------------------------
5526 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5528 m_iFlags
|= wxPG_FL_SCROLLED
;
5533 // -----------------------------------------------------------------------
5535 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5537 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5539 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5543 // -----------------------------------------------------------------------
5544 // Property editor related functions
5545 // -----------------------------------------------------------------------
5547 // noDefCheck = true prevents infinite recursion.
5548 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorclass
,
5549 const wxString
& name
,
5552 wxASSERT( editorclass
);
5554 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5555 RegisterDefaultEditors();
5557 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorclass
;
5562 // Registers all default editor classes
5563 void wxPropertyGrid::RegisterDefaultEditors()
5565 wxPGRegisterDefaultEditorClass( TextCtrl
);
5566 wxPGRegisterDefaultEditorClass( Choice
);
5567 wxPGRegisterDefaultEditorClass( ComboBox
);
5568 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5569 #if wxPG_INCLUDE_CHECKBOX
5570 wxPGRegisterDefaultEditorClass( CheckBox
);
5572 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5574 // Register SpinCtrl etc. editors before use
5575 RegisterAdditionalEditors();
5578 // -----------------------------------------------------------------------
5579 // wxPGStringTokenizer
5580 // Needed to handle C-style string lists (e.g. "str1" "str2")
5581 // -----------------------------------------------------------------------
5583 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5584 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5588 wxPGStringTokenizer::~wxPGStringTokenizer()
5592 bool wxPGStringTokenizer::HasMoreTokens()
5594 const wxString
& str
= *m_str
;
5596 wxString::const_iterator i
= m_curPos
;
5598 wxUniChar delim
= m_delimeter
;
5600 wxUniChar prev_a
= wxT('\0');
5602 bool inToken
= false;
5604 while ( i
!= str
.end() )
5613 m_readyToken
.clear();
5618 if ( prev_a
!= wxT('\\') )
5622 if ( a
!= wxT('\\') )
5642 m_curPos
= str
.end();
5650 wxString
wxPGStringTokenizer::GetNextToken()
5652 return m_readyToken
;
5655 // -----------------------------------------------------------------------
5657 // -----------------------------------------------------------------------
5659 wxPGChoiceEntry::wxPGChoiceEntry()
5660 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5664 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5665 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5666 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5670 // -----------------------------------------------------------------------
5672 // -----------------------------------------------------------------------
5674 wxPGChoicesData::wxPGChoicesData()
5679 wxPGChoicesData::~wxPGChoicesData()
5684 void wxPGChoicesData::Clear()
5688 for ( i
=0; i
<m_items
.size(); i
++ )
5700 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5702 wxASSERT( m_items
.size() == 0 );
5706 for ( i
=0; i
<data
->GetCount(); i
++ )
5707 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5710 // -----------------------------------------------------------------------
5712 // -----------------------------------------------------------------------
5714 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5718 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5719 m_data
->Insert( -1, p
);
5723 // -----------------------------------------------------------------------
5725 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5729 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5730 p
->SetBitmap(bitmap
);
5731 m_data
->Insert( -1, p
);
5735 // -----------------------------------------------------------------------
5737 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5741 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5742 m_data
->Insert(index
, p
);
5746 // -----------------------------------------------------------------------
5748 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5752 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5753 m_data
->Insert( index
, p
);
5757 // -----------------------------------------------------------------------
5759 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5765 while ( index
< GetCount() )
5767 int cmpRes
= GetLabel(index
).Cmp(label
);
5773 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5774 m_data
->Insert( index
, p
);
5778 // -----------------------------------------------------------------------
5780 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5784 unsigned int itemcount
= 0;
5785 const wxChar
** p
= &labels
[0];
5786 while ( *p
) { p
++; itemcount
++; }
5789 for ( i
= 0; i
< itemcount
; i
++ )
5791 int value
= wxPG_INVALID_VALUE
;
5794 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5798 // -----------------------------------------------------------------------
5800 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5805 unsigned int itemcount
= arr
.size();
5807 for ( i
= 0; i
< itemcount
; i
++ )
5809 int value
= wxPG_INVALID_VALUE
;
5812 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5816 // -----------------------------------------------------------------------
5818 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5823 unsigned int itemcount
= arr
.size();
5825 for ( i
= 0; i
< itemcount
; i
++ )
5827 int value
= wxPG_INVALID_VALUE
;
5828 if ( &arrint
&& arrint
.size() )
5830 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5834 // -----------------------------------------------------------------------
5836 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5838 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5840 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5841 delete m_data
->Item(i
);
5842 m_data
->m_items
.RemoveAt(nIndex
, count
);
5845 // -----------------------------------------------------------------------
5847 int wxPGChoices::Index( const wxString
& str
) const
5852 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5854 if ( m_data
->Item(i
)->GetText() == str
)
5861 // -----------------------------------------------------------------------
5863 int wxPGChoices::Index( int val
) const
5868 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5870 if ( m_data
->Item(i
)->GetValue() == val
)
5877 // -----------------------------------------------------------------------
5879 wxArrayString
wxPGChoices::GetLabels() const
5884 if ( this && IsOk() )
5885 for ( i
=0; i
<GetCount(); i
++ )
5886 arr
.push_back(GetLabel(i
));
5891 // -----------------------------------------------------------------------
5893 bool wxPGChoices::HasValues() const
5898 // -----------------------------------------------------------------------
5900 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5907 for ( i
=0; i
< strings
.size(); i
++ )
5909 int index
= Index(strings
[i
]);
5911 arr
.Add(GetValue(index
));
5913 arr
.Add(wxPG_INVALID_VALUE
);
5920 // -----------------------------------------------------------------------
5922 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5923 wxArrayString
* unmatched
) const
5930 for ( i
=0; i
< strings
.size(); i
++ )
5932 const wxString
& str
= strings
[i
];
5933 int index
= Index(str
);
5936 else if ( unmatched
)
5937 unmatched
->Add(str
);
5944 // -----------------------------------------------------------------------
5946 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5950 if ( data
!= wxPGChoicesEmptyData
)
5957 // -----------------------------------------------------------------------
5959 void wxPGChoices::Init()
5961 m_data
= wxPGChoicesEmptyData
;
5964 // -----------------------------------------------------------------------
5966 void wxPGChoices::Free()
5968 if ( m_data
!= wxPGChoicesEmptyData
)
5971 m_data
= wxPGChoicesEmptyData
;
5975 // -----------------------------------------------------------------------
5976 // wxPropertyGridEvent
5977 // -----------------------------------------------------------------------
5979 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5982 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5983 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5984 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5985 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5986 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5987 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5988 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5989 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5990 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5993 // -----------------------------------------------------------------------
5995 void wxPropertyGridEvent::Init()
5997 m_validationInfo
= NULL
;
5999 m_wasVetoed
= false;
6002 // -----------------------------------------------------------------------
6004 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
6005 : wxCommandEvent(commandType
,id
)
6011 // -----------------------------------------------------------------------
6013 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
6014 : wxCommandEvent(event
)
6016 m_eventType
= event
.GetEventType();
6017 m_eventObject
= event
.m_eventObject
;
6019 m_property
= event
.m_property
;
6020 m_validationInfo
= event
.m_validationInfo
;
6021 m_canVeto
= event
.m_canVeto
;
6022 m_wasVetoed
= event
.m_wasVetoed
;
6025 // -----------------------------------------------------------------------
6027 wxPropertyGridEvent::~wxPropertyGridEvent()
6031 // -----------------------------------------------------------------------
6033 wxEvent
* wxPropertyGridEvent::Clone() const
6035 return new wxPropertyGridEvent( *this );
6038 void wxPropertyGrid::SetPropertyAttributeAll( const wxString
& attrName
, wxVariant value
)
6040 DoSetPropertyAttribute(GetRoot(), attrName
, value
, wxPG_RECURSE
);
6043 // -----------------------------------------------------------------------
6044 // wxPropertyGridPopulator
6045 // -----------------------------------------------------------------------
6047 wxPropertyGridPopulator::wxPropertyGridPopulator()
6051 wxPGGlobalVars
->m_offline
++;
6054 // -----------------------------------------------------------------------
6056 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6059 m_propHierarchy
.clear();
6062 // -----------------------------------------------------------------------
6064 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6070 // -----------------------------------------------------------------------
6072 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6075 // Free unused sets of choices
6076 wxPGHashMapS2P::iterator it
;
6078 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6080 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6087 m_pg
->GetPanel()->Refresh();
6089 wxPGGlobalVars
->m_offline
--;
6092 // -----------------------------------------------------------------------
6094 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6095 const wxString
& propLabel
,
6096 const wxString
& propName
,
6097 const wxString
* propValue
,
6098 wxPGChoices
* pChoices
)
6100 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6101 wxPGProperty
* parent
= GetCurParent();
6103 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6105 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6109 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6111 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6115 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6117 property
->SetLabel(propLabel
);
6118 property
->DoSetName(propName
);
6120 if ( pChoices
&& pChoices
->IsOk() )
6121 property
->SetChoices(*pChoices
);
6123 m_state
->DoInsert(parent
, -1, property
);
6126 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6131 // -----------------------------------------------------------------------
6133 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6135 m_propHierarchy
.push_back(property
);
6136 DoScanForChildren();
6137 m_propHierarchy
.pop_back();
6140 // -----------------------------------------------------------------------
6142 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6143 const wxString
& idString
)
6145 wxPGChoices choices
;
6148 if ( choicesString
[0] == wxT('@') )
6150 wxString ids
= choicesString
.substr(1);
6151 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6152 if ( it
== m_dictIdChoices
.end() )
6153 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6155 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6160 if ( idString
.length() )
6162 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6163 if ( it
!= m_dictIdChoices
.end() )
6165 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6172 // Parse choices string
6173 wxString::const_iterator it
= choicesString
.begin();
6177 bool labelValid
= false;
6179 for ( ; it
!= choicesString
.end(); it
++ )
6185 if ( c
== wxT('"') )
6190 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6191 choices
.Add(label
, l
);
6194 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6199 else if ( c
== wxT('=') )
6206 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6213 if ( c
== wxT('"') )
6226 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6227 choices
.Add(label
, l
);
6230 if ( !choices
.IsOk() )
6232 choices
.EnsureData();
6236 if ( idString
.length() )
6237 m_dictIdChoices
[idString
] = choices
.GetData();
6244 // -----------------------------------------------------------------------
6246 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6248 if ( s
.Last() == wxT('%') )
6250 wxString s2
= s
.substr(0,s
.length()-1);
6252 if ( s2
.ToLong(&val
, 10) )
6254 *pval
= (val
*max
)/100;
6260 return s
.ToLong(pval
, 10);
6263 // -----------------------------------------------------------------------
6265 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6266 const wxString
& type
,
6267 const wxString
& value
)
6269 int l
= m_propHierarchy
.size();
6273 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6274 wxString valuel
= value
.Lower();
6277 if ( type
.length() == 0 )
6282 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6284 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6286 else if ( value
.ToLong(&v
, 0) )
6293 if ( type
== wxT("string") )
6297 else if ( type
== wxT("int") )
6300 value
.ToLong(&v
, 0);
6303 else if ( type
== wxT("bool") )
6305 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6312 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6317 p
->SetAttribute( name
, variant
);
6322 // -----------------------------------------------------------------------
6324 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6326 wxLogError(_("Error in resource: %s"),msg
.c_str());
6329 // -----------------------------------------------------------------------