1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include <wx/propgrid/propgrid.h>
56 #include <wx/propgrid/editors.h>
58 #if wxPG_USE_RENDERER_NATIVE
59 #include <wx/renderer.h>
62 #include <wx/odcombo.h>
65 #include "wx/dcbuffer.h"
66 #include <wx/clipbrd.h>
67 #include <wx/dataobj.h>
70 #include <wx/msw/private.h>
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 #define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 #define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 #define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 #define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 #define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const wxChar
*wxPropertyGridNameStr
= wxT("wxPropertyGrid");
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include <wx/module.h>
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
160 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
162 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
164 m_boolChoices
.Add(_("False"));
165 m_boolChoices
.Add(_("True"));
167 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
169 m_defaultRenderer
= new wxPGDefaultRenderer();
171 m_autoGetTranslation
= false;
179 // Prepare some shared variants
180 m_vEmptyString
= wxString();
182 m_vMinusOne
= (long) -1;
186 // Prepare cached string constants
187 m_strstring
= wxS("string");
188 m_strlong
= wxS("long");
189 m_strbool
= wxS("bool");
190 m_strlist
= wxS("list");
191 m_strMin
= wxS("Min");
192 m_strMax
= wxS("Max");
193 m_strUnits
= wxS("Units");
194 m_strInlineHelp
= wxS("InlineHelp");
202 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
206 delete m_defaultRenderer
;
208 // This will always have one ref
209 delete m_fontFamilyChoices
;
212 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
213 delete ((wxValidator
*)m_arrValidators
[i
]);
217 // Destroy value type class instances.
218 wxPGHashMapS2P::iterator vt_it
;
220 // Destroy editor class instances.
221 // iterate over all the elements in the class
222 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
224 delete ((wxPGEditor
*)vt_it
->second
);
227 delete wxPGProperty::sm_wxPG_LABEL
;
230 void wxPropertyGridInitGlobalsIfNeeded()
234 // -----------------------------------------------------------------------
236 // -----------------------------------------------------------------------
239 // This class is a wxBrush derivative used in the background colour
240 // brush cache. It adds wxPG-type colour-in-long to the class.
241 // JMS: Yes I know wxBrush doesn't actually hold the value (refcounted
242 // object does), but this is simpler implementation and equally
246 class wxPGBrush
: public wxBrush
249 wxPGBrush( const wxColour
& colour
);
251 virtual ~wxPGBrush() { }
252 void SetColour2( const wxColour
& colour
);
253 inline long GetColourAsLong() const { return m_colAsLong
; }
259 void wxPGBrush::SetColour2( const wxColour
& colour
)
261 wxBrush::SetColour(colour
);
262 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
266 wxPGBrush::wxPGBrush() : wxBrush()
272 wxPGBrush::wxPGBrush( const wxColour
& colour
) : wxBrush(colour
)
274 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
278 // -----------------------------------------------------------------------
280 // -----------------------------------------------------------------------
283 // Same as wxPGBrush, but for wxColour instead.
286 class wxPGColour
: public wxColour
289 wxPGColour( const wxColour
& colour
);
291 virtual ~wxPGColour() { }
292 void SetColour2( const wxColour
& colour
);
293 inline long GetColourAsLong() const { return m_colAsLong
; }
299 void wxPGColour::SetColour2( const wxColour
& colour
)
302 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
306 wxPGColour::wxPGColour() : wxColour()
312 wxPGColour::wxPGColour( const wxColour
& colour
) : wxColour(colour
)
314 m_colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
318 // -----------------------------------------------------------------------
320 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
321 // and tries to commit property value.
322 // -----------------------------------------------------------------------
324 class wxPGTLWHandler
: public wxEvtHandler
328 wxPGTLWHandler( wxPropertyGrid
* pg
)
336 void OnClose( wxCloseEvent
& event
)
338 // ClearSelection forces value validation/commit.
339 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
349 wxPropertyGrid
* m_pg
;
351 DECLARE_EVENT_TABLE()
354 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
355 EVT_CLOSE(wxPGTLWHandler::OnClose
)
358 // -----------------------------------------------------------------------
360 // -----------------------------------------------------------------------
363 // wxPGCanvas acts as a graphics sub-window of the
364 // wxScrolledWindow that wxPropertyGrid is.
366 class wxPGCanvas
: public wxPanel
369 wxPGCanvas() : wxPanel()
372 virtual ~wxPGCanvas() { }
375 void OnMouseMove( wxMouseEvent
&event
)
377 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
378 pg
->OnMouseMove( event
);
381 void OnMouseClick( wxMouseEvent
&event
)
383 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
384 pg
->OnMouseClick( event
);
387 void OnMouseUp( wxMouseEvent
&event
)
389 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
390 pg
->OnMouseUp( event
);
393 void OnMouseRightClick( wxMouseEvent
&event
)
395 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
396 pg
->OnMouseRightClick( event
);
399 void OnMouseDoubleClick( wxMouseEvent
&event
)
401 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
402 pg
->OnMouseDoubleClick( event
);
405 void OnKey( wxKeyEvent
& event
)
407 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
411 void OnKeyUp( wxKeyEvent
& event
)
413 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
414 pg
->OnKeyUp( event
);
417 void OnNavigationKey( wxNavigationKeyEvent
& event
)
419 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
420 pg
->OnNavigationKey( event
);
423 void OnPaint( wxPaintEvent
& event
);
425 // Always be focussable, even with child windows
426 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
427 { wxPanel::SetCanFocus(true); }
431 DECLARE_EVENT_TABLE()
432 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
436 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
438 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
439 EVT_MOTION(wxPGCanvas::OnMouseMove
)
440 EVT_PAINT(wxPGCanvas::OnPaint
)
441 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
442 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
443 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
444 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
445 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
446 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
447 EVT_CHAR(wxPGCanvas::OnKey
)
448 EVT_NAVIGATION_KEY(wxPGCanvas::OnNavigationKey
)
452 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
454 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
455 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
459 // Don't paint after destruction has begun
460 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
463 // Update everything inside the box
464 wxRect r
= GetUpdateRegion().GetBox();
466 // Repaint this rectangle
467 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
469 // We assume that the size set when grid is shown
470 // is what is desired.
471 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
474 // -----------------------------------------------------------------------
476 // -----------------------------------------------------------------------
478 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
480 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
481 EVT_IDLE(wxPropertyGrid::OnIdle
)
482 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
483 EVT_PAINT(wxPropertyGrid::OnPaint
)
484 EVT_SIZE(wxPropertyGrid::OnResize
)
485 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
486 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
487 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
488 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
489 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
490 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
491 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
492 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
496 // -----------------------------------------------------------------------
498 wxPropertyGrid::wxPropertyGrid()
504 // -----------------------------------------------------------------------
506 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
515 Create(parent
,id
,pos
,size
,style
,name
);
518 // -----------------------------------------------------------------------
520 bool wxPropertyGrid::Create( wxWindow
*parent
,
528 if ( !(style
&wxBORDER_MASK
) )
529 style
|= wxSIMPLE_BORDER
;
534 // This prevents crash under Win2K, but still
535 // enables keyboard navigation
536 if ( style
& wxTAB_TRAVERSAL
)
538 style
&= ~(wxTAB_TRAVERSAL
);
539 style
|= wxWANTS_CHARS
;
542 if ( style
& wxTAB_TRAVERSAL
)
543 style
|= wxWANTS_CHARS
;
546 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
553 // -----------------------------------------------------------------------
556 // Initialize values to defaults
558 void wxPropertyGrid::Init1()
560 // Register editor classes, if necessary.
561 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
562 wxPropertyGrid::RegisterDefaultEditors();
565 m_pState
= (wxPropertyGridPageState
*) NULL
;
566 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
567 m_selected
= (wxPGProperty
*) NULL
;
569 m_propHover
= (wxPGProperty
*) NULL
;
570 m_eventObject
= this;
571 m_curFocused
= (wxWindow
*) NULL
;
573 m_inDoPropertyChanged
= 0;
574 m_inCommitChangesFromEditor
= 0;
575 m_inDoSelectProperty
= 0;
576 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
582 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
583 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
584 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
585 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
586 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
587 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
588 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
589 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
590 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
591 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
592 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
593 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
594 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
596 m_coloursCustomized
= 0;
601 #if wxPG_DOUBLE_BUFFER
602 m_doubleBuffer
= (wxBitmap
*) NULL
;
605 #ifndef wxPG_ICON_WIDTH
611 m_iconWidth
= wxPG_ICON_WIDTH
;
616 m_gutterWidth
= wxPG_GUTTER_MIN
;
617 m_subgroup_extramargin
= 10;
621 m_width
= m_height
= 0;
623 SetButtonShortcut(0);
625 m_keyComboConsumed
= 0;
627 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
630 m_chgInfo_changedProperty
= NULL
;
633 // -----------------------------------------------------------------------
636 // Initialize after parent etc. set
638 void wxPropertyGrid::Init2()
640 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
643 // Smaller controls on Mac
644 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
647 // Now create state, if one didn't exist already
648 // (wxPropertyGridManager might have created it for us).
651 m_pState
= CreateState();
652 m_pState
->m_pPropGrid
= this;
653 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
656 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
657 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
659 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
661 m_pState
->InitNonCatMode();
663 m_pState
->m_properties
= m_pState
->m_abcArray
;
666 GetClientSize(&m_width
,&m_height
);
668 #ifndef wxPG_ICON_WIDTH
669 // create two bitmap nodes for drawing
670 m_expandbmp
= new wxBitmap(expand_xpm
);
671 m_collbmp
= new wxBitmap(collapse_xpm
);
673 // calculate average font height for bitmap centering
675 m_iconWidth
= m_expandbmp
->GetWidth();
676 m_iconHeight
= m_expandbmp
->GetHeight();
679 m_curcursor
= wxCURSOR_ARROW
;
680 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
682 // adjust bitmap icon y position so they are centered
683 m_vspacing
= wxPG_DEFAULT_VSPACING
;
687 wxFont useFont
= wxScrolledWindow::GetFont();
688 wxScrolledWindow::SetOwnFont( useFont
);
691 // This should be otherwise called by SetOwnFont
692 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
694 // Add base brush item
695 m_arrBgBrushes
.Add((void*)new wxPGBrush());
697 // Add base colour items
698 m_arrFgCols
.Add((void*)new wxPGColour());
699 m_arrFgCols
.Add((void*)new wxPGColour());
703 // This helps with flicker
704 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
707 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
708 m_tlp
= ::wxGetTopLevelParent(this);
709 m_tlwHandler
= handler
;
710 m_tlp
->PushEventHandler(handler
);
712 // set virtual size to this window size
713 wxSize wndsize
= GetSize();
714 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
716 m_timeCreated
= ::wxGetLocalTimeMillis();
718 m_canvas
= new wxPGCanvas();
719 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
720 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
721 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
723 m_iFlags
|= wxPG_FL_INITIALIZED
;
725 m_ncWidth
= wndsize
.GetWidth();
727 // Need to call OnResize handler or size given in constructor/Create
729 wxSizeEvent
sizeEvent(wndsize
,0);
733 // -----------------------------------------------------------------------
735 wxPropertyGrid::~wxPropertyGrid()
739 DoSelectProperty(NULL
);
741 // This should do prevent things from going too badly wrong
742 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
744 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
745 m_canvas
->ReleaseMouse();
747 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
748 m_tlp
->RemoveEventHandler(handler
);
752 if ( IsEditorsValueModified() )
753 ::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).)"),
754 wxS("wxPropertyGrid Debug Warning") );
757 #if wxPG_DOUBLE_BUFFER
758 if ( m_doubleBuffer
)
759 delete m_doubleBuffer
;
762 //m_selected = (wxPGProperty*) NULL;
764 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
767 delete m_cursorSizeWE
;
769 #ifndef wxPG_ICON_WIDTH
774 // Delete cached text colours.
775 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
777 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
780 // Delete cached brushes.
781 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
783 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
786 // Delete common value records
787 for ( i
=0; i
<m_commonValues
.size(); i
++ )
789 delete GetCommonValue(i
);
793 // -----------------------------------------------------------------------
795 bool wxPropertyGrid::Destroy()
797 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
798 m_canvas
->ReleaseMouse();
800 return wxScrolledWindow::Destroy();
803 // -----------------------------------------------------------------------
805 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
807 return new wxPropertyGridPageState();
810 // -----------------------------------------------------------------------
811 // wxPropertyGrid overridden wxWindow methods
812 // -----------------------------------------------------------------------
814 void wxPropertyGrid::SetWindowStyleFlag( long style
)
816 long old_style
= m_windowStyle
;
818 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
820 wxASSERT( m_pState
);
822 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
825 EnableCategories( true );
827 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
829 // Disable categories
830 EnableCategories( false );
832 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
838 PrepareAfterItemsAdded();
840 m_pState
->m_itemsAdded
= 1;
842 #if wxPG_SUPPORT_TOOLTIPS
843 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
849 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
850 SetToolTip ( tooltip );
851 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
854 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
859 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
864 wxScrolledWindow::SetWindowStyleFlag ( style
);
866 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
868 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
870 CalculateFontAndBitmapStuff( m_vspacing
);
876 // -----------------------------------------------------------------------
878 void wxPropertyGrid::Freeze()
882 wxScrolledWindow::Freeze();
887 // -----------------------------------------------------------------------
889 void wxPropertyGrid::Thaw()
895 wxScrolledWindow::Thaw();
896 RecalculateVirtualSize();
897 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
901 // Force property re-selection
903 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
907 // -----------------------------------------------------------------------
909 void wxPropertyGrid::SetExtraStyle( long exStyle
)
911 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
913 #if defined(__WXMSW__)
916 // Don't use WS_EX_COMPOSITED just now.
919 if ( m_iFlags & wxPG_FL_IN_MANAGER )
920 hWnd = (HWND)GetParent()->GetHWND();
922 hWnd = (HWND)GetHWND();
924 ::SetWindowLong( hWnd, GWL_EXSTYLE,
925 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
928 //#elif defined(__WXGTK20__)
930 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
931 // truly was double-buffered.
932 if ( !this->IsDoubleBuffered() )
934 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
938 #if wxPG_DOUBLE_BUFFER
939 delete m_doubleBuffer
;
940 m_doubleBuffer
= NULL
;
945 wxScrolledWindow::SetExtraStyle( exStyle
);
947 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
948 m_pState
->InitNonCatMode();
950 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
951 m_windowStyle
|= wxPG_TOOLTIPS
;
954 wxPGGlobalVars
->m_extraStyle
= exStyle
;
957 // -----------------------------------------------------------------------
959 // returns the best acceptable minimal size
960 wxSize
wxPropertyGrid::DoGetBestSize() const
963 if ( m_lineHeight
> hei
)
965 wxSize sz
= wxSize( 60, hei
+40 );
971 // -----------------------------------------------------------------------
972 // wxPropertyGrid Font and Colour Methods
973 // -----------------------------------------------------------------------
975 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
979 m_captionFont
= wxScrolledWindow::GetFont();
981 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
982 m_subgroup_extramargin
= x
+ (x
/2);
985 #if wxPG_USE_RENDERER_NATIVE
986 m_iconWidth
= wxPG_ICON_WIDTH
;
987 #elif wxPG_ICON_WIDTH
989 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
990 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
991 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
995 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
996 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
997 m_gutterWidth
= wxPG_GUTTER_MIN
;
1000 if ( vspacing
<= 1 ) vdiv
= 12;
1001 else if ( vspacing
>= 3 ) vdiv
= 3;
1003 m_spacingy
= m_fontHeight
/ vdiv
;
1004 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1005 m_spacingy
= wxPG_YSPACING_MIN
;
1008 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1009 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1011 m_captionFont
.SetWeight(wxBOLD
);
1012 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1014 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1017 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1018 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1021 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1023 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1024 RecalculateVirtualSize();
1026 InvalidateBestSize();
1029 // -----------------------------------------------------------------------
1031 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1037 // -----------------------------------------------------------------------
1039 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1040 int ga
= 1000, int ba
= 1000,
1041 bool forceDifferent
= false)
1048 // Recursion guard (allow 2 max)
1049 static int isinside
= 0;
1051 wxCHECK_MSG( isinside
< 3,
1053 wxT("wxPGAdjustColour should not be recursively called more than once") );
1058 int g
= src
.Green();
1061 if ( r2
>255 ) r2
= 255;
1062 else if ( r2
<0) r2
= 0;
1064 if ( g2
>255 ) g2
= 255;
1065 else if ( g2
<0) g2
= 0;
1067 if ( b2
>255 ) b2
= 255;
1068 else if ( b2
<0) b2
= 0;
1070 // Make sure they are somewhat different
1071 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1072 dst
= wxPGAdjustColour(src
,-(ra
*2));
1074 dst
= wxColour(r2
,g2
,b2
);
1076 // Recursion guard (allow 2 max)
1083 static int wxPGGetColAvg( const wxColour
& col
)
1085 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1089 void wxPropertyGrid::RegainColours()
1091 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1093 if ( !(m_coloursCustomized
& 0x0002) )
1095 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1097 // Make sure colour is dark enough
1099 int colDec
= wxPGGetColAvg(col
) - 230;
1101 int colDec
= wxPGGetColAvg(col
) - 200;
1104 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1109 if ( !(m_coloursCustomized
& 0x0001) )
1110 m_colMargin
= m_colCapBack
;
1112 if ( !(m_coloursCustomized
& 0x0004) )
1119 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1120 m_colCapFore
= capForeCol
;
1122 // Set the cached colour as well.
1123 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1126 if ( !(m_coloursCustomized
& 0x0008) )
1128 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1129 m_colPropBack
= bgCol
;
1131 // Set the cached brush as well.
1132 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1135 if ( !(m_coloursCustomized
& 0x0010) )
1137 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1138 m_colPropFore
= fgCol
;
1140 // Set the cached colour as well.
1141 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1144 if ( !(m_coloursCustomized
& 0x0020) )
1145 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1147 if ( !(m_coloursCustomized
& 0x0040) )
1148 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1150 if ( !(m_coloursCustomized
& 0x0080) )
1151 m_colLine
= m_colCapBack
;
1153 if ( !(m_coloursCustomized
& 0x0100) )
1154 m_colDisPropFore
= m_colCapFore
;
1156 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1159 // -----------------------------------------------------------------------
1161 void wxPropertyGrid::ResetColours()
1163 m_coloursCustomized
= 0;
1170 // -----------------------------------------------------------------------
1172 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1174 // Must disable active editor.
1177 bool selRes
= ClearSelection();
1178 wxPG_CHECK_MSG_DBG( selRes
,
1180 wxT("failed to deselect a property (editor probably had invalid value)") );
1183 // TODO: Following code is disabled with wxMac because
1184 // it is reported to fail. I (JMS) cannot debug it
1185 // personally right now.
1186 #if !defined(__WXMAC__)
1187 bool res
= wxScrolledWindow::SetFont( font
);
1190 CalculateFontAndBitmapStuff( m_vspacing
);
1193 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1201 // TODO: Remove after SetFont crash fixed.
1202 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1204 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."));
1210 // -----------------------------------------------------------------------
1212 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1215 m_coloursCustomized
|= 0x80;
1219 // -----------------------------------------------------------------------
1221 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1224 m_coloursCustomized
|= 0x01;
1228 // -----------------------------------------------------------------------
1230 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1232 m_colPropBack
= col
;
1233 m_coloursCustomized
|= 0x08;
1235 // Set the cached brush as well.
1236 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1241 // -----------------------------------------------------------------------
1243 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1245 m_colPropFore
= col
;
1246 m_coloursCustomized
|= 0x10;
1248 // Set the cached colour as well.
1249 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1254 // -----------------------------------------------------------------------
1256 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1258 m_colEmptySpace
= col
;
1263 // -----------------------------------------------------------------------
1265 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1267 m_colDisPropFore
= col
;
1268 m_coloursCustomized
|= 0x100;
1272 // -----------------------------------------------------------------------
1274 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1277 m_coloursCustomized
|= 0x20;
1281 // -----------------------------------------------------------------------
1283 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1286 m_coloursCustomized
|= 0x40;
1290 // -----------------------------------------------------------------------
1292 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1295 m_coloursCustomized
|= 0x02;
1299 // -----------------------------------------------------------------------
1301 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1304 m_coloursCustomized
|= 0x04;
1306 // Set the cached colour as well.
1307 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1312 // -----------------------------------------------------------------------
1314 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1316 unsigned char ind
= index
;
1318 p
->m_bgColIndex
= ind
;
1321 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1322 SetBackgroundColourIndex(p
->Item(i
),index
);
1325 // -----------------------------------------------------------------------
1327 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1329 wxPG_PROP_ARG_CALL_PROLOG()
1334 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1336 // As it is most likely that the previous colour is used, start comparison
1338 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1340 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1349 colInd
= m_arrBgBrushes
.size();
1350 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1351 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1355 SetBackgroundColourIndex(p
,colInd
);
1357 // If this was on a visible grid, then draw it.
1358 DrawItemAndChildren(p
);
1361 // -----------------------------------------------------------------------
1363 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1365 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1367 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1370 // -----------------------------------------------------------------------
1372 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1374 unsigned char ind
= index
;
1376 p
->m_fgColIndex
= ind
;
1378 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1381 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1382 SetTextColourIndex( p
->Item(i
), index
, flags
);
1386 // -----------------------------------------------------------------------
1388 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1393 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1395 // As it is most likely that the previous colour is used, start comparison
1397 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1399 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1408 colInd
= m_arrFgCols
.size();
1409 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1410 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1416 // -----------------------------------------------------------------------
1418 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1421 wxPG_PROP_ARG_CALL_PROLOG()
1423 if ( p
->IsCategory() )
1425 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1426 cat
->SetTextColIndex(CacheColour(colour
));
1432 flags
|= wxPG_RECURSE
;
1433 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1435 DrawItemAndChildren(p
);
1438 // -----------------------------------------------------------------------
1440 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1442 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1444 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1447 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1449 wxPG_PROP_ARG_CALL_PROLOG()
1451 SetBackgroundColourIndex( p
, 0 );
1452 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1454 if ( p
->IsCategory() )
1456 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1457 cat
->SetTextColIndex(1);
1461 // -----------------------------------------------------------------------
1462 // wxPropertyGrid property adding and removal
1463 // -----------------------------------------------------------------------
1465 void wxPropertyGrid::PrepareAfterItemsAdded()
1467 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1469 m_pState
->m_itemsAdded
= 0;
1471 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1474 RecalculateVirtualSize();
1477 // -----------------------------------------------------------------------
1478 // wxPropertyGrid property value setting and getting
1479 // -----------------------------------------------------------------------
1481 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1483 m_pState
->DoSetPropertyValueUnspecified(p
);
1484 DrawItemAndChildren(p
);
1486 wxPGProperty
* parent
= p
->GetParent();
1487 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1490 parent
= parent
->GetParent();
1494 // -----------------------------------------------------------------------
1495 // wxPropertyGrid property operations
1496 // -----------------------------------------------------------------------
1498 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1500 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1504 bool changed
= false;
1506 // Is it inside collapsed section?
1507 if ( !p
->IsVisible() )
1510 wxPGProperty
* parent
= p
->GetParent();
1511 wxPGProperty
* grandparent
= parent
->GetParent();
1513 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1514 Expand( grandparent
);
1522 GetViewStart(&vx
,&vy
);
1523 vy
*=wxPG_PIXELS_PER_UNIT
;
1529 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1530 m_iFlags
|= wxPG_FL_SCROLLED
;
1533 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1535 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1536 m_iFlags
|= wxPG_FL_SCROLLED
;
1546 // -----------------------------------------------------------------------
1547 // wxPropertyGrid helper methods called by properties
1548 // -----------------------------------------------------------------------
1550 // Control font changer helper.
1551 void wxPropertyGrid::SetCurControlBoldFont()
1553 wxASSERT( m_wndEditor
);
1554 m_wndEditor
->SetFont( m_captionFont
);
1557 // -----------------------------------------------------------------------
1559 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1562 #if wxPG_SMALL_SCREEN
1563 // On small-screen devices, always show dialogs with default position and size.
1564 return wxDefaultPosition
;
1566 int splitterX
= GetSplitterPosition();
1570 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1572 ImprovedClientToScreen( &x
, &y
);
1574 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1575 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1582 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1592 new_y
= y
+ m_lineHeight
;
1594 return wxPoint(new_x
,new_y
);
1598 // -----------------------------------------------------------------------
1600 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1602 if ( src_str
.length() == 0 )
1608 bool prev_is_slash
= false;
1610 wxString::const_iterator i
= src_str
.begin();
1614 for ( ; i
!= src_str
.end(); i
++ )
1618 if ( a
!= wxS('\\') )
1620 if ( !prev_is_slash
)
1626 if ( a
== wxS('n') )
1629 dst_str
<< wxS('\n');
1631 dst_str
<< wxS('\n');
1634 else if ( a
== wxS('t') )
1635 dst_str
<< wxS('\t');
1639 prev_is_slash
= false;
1643 if ( prev_is_slash
)
1645 dst_str
<< wxS('\\');
1646 prev_is_slash
= false;
1650 prev_is_slash
= true;
1657 // -----------------------------------------------------------------------
1659 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1661 if ( src_str
.length() == 0 )
1667 wxString::const_iterator i
= src_str
.begin();
1668 wxUniChar prev_a
= wxS('\0');
1672 for ( ; i
!= src_str
.end(); i
++ )
1676 if ( a
>= wxS(' ') )
1678 // This surely is not something that requires an escape sequence.
1683 // This might need...
1684 if ( a
== wxS('\r') )
1686 // DOS style line end.
1687 // Already taken care below
1689 else if ( a
== wxS('\n') )
1690 // UNIX style line end.
1691 dst_str
<< wxS("\\n");
1692 else if ( a
== wxS('\t') )
1694 dst_str
<< wxS('\t');
1697 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1707 // -----------------------------------------------------------------------
1709 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1713 return (wxPGProperty
*) NULL
;
1716 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1719 // -----------------------------------------------------------------------
1720 // wxPropertyGrid graphics related methods
1721 // -----------------------------------------------------------------------
1723 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1727 // Update everything inside the box
1728 wxRect r
= GetUpdateRegion().GetBox();
1730 dc
.SetPen(m_colEmptySpace
);
1731 dc
.SetBrush(m_colEmptySpace
);
1732 dc
.DrawRectangle(r
);
1735 // -----------------------------------------------------------------------
1737 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1738 wxPGProperty
* property
) const
1740 // Prepare rectangle to be used
1742 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1743 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1745 #if (wxPG_USE_RENDERER_NATIVE)
1747 #elif wxPG_ICON_WIDTH
1748 // Drawing expand/collapse button manually
1749 dc
.SetPen(m_colPropFore
);
1750 if ( property
->IsCategory() )
1751 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1753 dc
.SetBrush(m_colPropBack
);
1755 dc
.DrawRectangle( r
);
1756 int _y
= r
.y
+(m_iconWidth
/2);
1757 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1762 if ( property
->IsExpanded() )
1764 // wxRenderer functions are non-mutating in nature, so it
1765 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1766 // Hopefully this does not cause problems.
1767 #if (wxPG_USE_RENDERER_NATIVE)
1768 wxRendererNative::Get().DrawTreeItemButton(
1774 #elif wxPG_ICON_WIDTH
1783 #if (wxPG_USE_RENDERER_NATIVE)
1784 wxRendererNative::Get().DrawTreeItemButton(
1790 #elif wxPG_ICON_WIDTH
1791 int _x
= r
.x
+(m_iconWidth
/2);
1792 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1798 #if (wxPG_USE_RENDERER_NATIVE)
1800 #elif wxPG_ICON_WIDTH
1803 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1807 // -----------------------------------------------------------------------
1810 // This is the one called by OnPaint event handler and others.
1811 // topy and bottomy are already unscrolled (ie. physical)
1813 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1815 unsigned int bottomy
,
1816 const wxRect
* clipRect
)
1818 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1820 m_pState
->EnsureVirtualHeight();
1822 wxRect tempClipRect
;
1825 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1826 clipRect
= &tempClipRect
;
1829 // items added check
1830 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1832 int paintFinishY
= 0;
1834 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1837 bool isBuffered
= false;
1839 #if wxPG_DOUBLE_BUFFER
1840 wxMemoryDC
* bufferDC
= NULL
;
1842 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1844 if ( !m_doubleBuffer
)
1846 paintFinishY
= clipRect
->y
;
1851 bufferDC
= new wxMemoryDC();
1853 // If nothing was changed, then just copy from double-buffer
1854 bufferDC
->SelectObject( *m_doubleBuffer
);
1864 dc
.SetClippingRegion( *clipRect
);
1865 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1868 #if wxPG_DOUBLE_BUFFER
1871 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1872 bufferDC
, 0, 0, wxCOPY
);
1873 dc
.DestroyClippingRegion(); // Is this really necessary?
1879 // Clear area beyond bottomY?
1880 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1882 dc
.SetPen(m_colEmptySpace
);
1883 dc
.SetBrush(m_colEmptySpace
);
1884 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1888 // -----------------------------------------------------------------------
1890 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1891 const wxPGProperty
* firstItem
,
1892 const wxPGProperty
* lastItem
,
1893 const wxRect
* clipRect
,
1894 bool isBuffered
) const
1896 // TODO: This should somehow be eliminated.
1897 wxRect tempClipRect
;
1900 wxASSERT(firstItem
);
1902 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1903 clipRect
= &tempClipRect
;
1907 firstItem
= DoGetItemAtY(clipRect
->y
);
1911 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1913 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1916 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1919 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1920 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1922 int lh
= m_lineHeight
;
1925 int lastItemBottomY
;
1927 firstItemTopY
= clipRect
->y
;
1928 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1930 // Align y coordinates to item boundaries
1931 firstItemTopY
-= firstItemTopY
% lh
;
1932 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1933 lastItemBottomY
-= 1;
1935 // Entire range outside scrolled, visible area?
1936 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1939 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1943 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1944 firstItem->GetLabel().c_str(),
1945 lastItem->GetLabel().c_str(),
1946 (int)(lastItemBottomY - firstItemTopY),
1948 (unsigned long)clipRect );
1953 long windowStyle
= m_windowStyle
;
1959 // With wxPG_DOUBLE_BUFFER, do double buffering
1960 // - buffer's y = 0, so align cliprect and coordinates to that
1962 #if wxPG_DOUBLE_BUFFER
1968 xRelMod
= clipRect
->x
;
1969 yRelMod
= clipRect
->y
;
1972 // clipRect conversion
1980 firstItemTopY
-= yRelMod
;
1981 lastItemBottomY
-= yRelMod
;
1984 wxUnusedVar(isBuffered
);
1987 int x
= m_marginWidth
- xRelMod
;
1989 const wxFont
& normalfont
= m_font
;
1991 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1993 bool isEnabled
= IsEnabled();
1996 // Prepare some pens and brushes that are often changed to.
1999 wxBrush
marginBrush(m_colMargin
);
2000 wxPen
marginPen(m_colMargin
);
2001 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2002 wxPen
linepen(m_colLine
,1,wxSOLID
);
2004 // pen that has same colour as text
2005 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2008 // Clear margin with background colour
2010 dc
.SetBrush( marginBrush
);
2011 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2013 dc
.SetPen( *wxTRANSPARENT_PEN
);
2014 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2017 const wxPGProperty
* selected
= m_selected
;
2018 const wxPropertyGridPageState
* state
= m_pState
;
2020 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2021 bool wasSelectedPainted
= false;
2024 // TODO: Only render columns that are within clipping region.
2026 dc
.SetFont(normalfont
);
2028 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2029 int endScanBottomY
= lastItemBottomY
+ lh
;
2030 int y
= firstItemTopY
;
2033 // Pregenerate list of visible properties.
2034 wxArrayPGProperty visPropArray
;
2035 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2037 for ( ; !it
.AtEnd(); it
.Next() )
2039 const wxPGProperty
* p
= *it
;
2041 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2043 visPropArray
.push_back((wxPGProperty
*)p
);
2045 if ( y
> endScanBottomY
)
2052 visPropArray
.push_back(NULL
);
2054 wxPGProperty
* nextP
= visPropArray
[0];
2056 int gridWidth
= state
->m_width
;
2059 for ( unsigned int arrInd
=1;
2060 nextP
&& y
<= lastItemBottomY
;
2063 wxPGProperty
* p
= nextP
;
2064 nextP
= visPropArray
[arrInd
];
2066 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2067 int textMarginHere
= x
;
2068 int renderFlags
= wxPGCellRenderer::Control
;
2070 int greyDepth
= m_marginWidth
;
2071 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2072 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2074 int greyDepthX
= greyDepth
- xRelMod
;
2076 // Use basic depth if in non-categoric mode and parent is base array.
2077 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2079 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2082 // Paint margin area
2083 dc
.SetBrush(marginBrush
);
2084 dc
.SetPen(marginPen
);
2085 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2087 dc
.SetPen( linepen
);
2092 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2098 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2100 sx
+= state
->m_colWidths
[si
];
2101 dc
.DrawLine( sx
, y
, sx
, y2
);
2104 // Horizontal Line, below
2105 // (not if both this and next is category caption)
2106 if ( p
->IsCategory() &&
2107 nextP
&& nextP
->IsCategory() )
2108 dc
.SetPen(m_colCapBack
);
2110 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2112 if ( p
== selected
)
2114 renderFlags
|= wxPGCellRenderer::Selected
;
2115 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2116 wasSelectedPainted
= true;
2124 if ( p
->IsCategory() )
2126 if ( p
->m_fgColIndex
== 0 )
2127 rowFgCol
= m_colCapFore
;
2129 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2130 rowBgBrush
= wxBrush(m_colCapBack
);
2132 else if ( p
!= selected
)
2134 // Disabled may get different colour.
2135 if ( !p
->IsEnabled() )
2136 rowFgCol
= m_colDisPropFore
;
2138 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2140 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2144 // Selected gets different colour.
2145 if ( reallyFocused
)
2147 rowFgCol
= m_colSelFore
;
2148 rowBgBrush
= wxBrush(m_colSelBack
);
2150 else if ( isEnabled
)
2152 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2153 rowBgBrush
= marginBrush
;
2157 rowFgCol
= m_colDisPropFore
;
2158 rowBgBrush
= wxBrush(m_colSelBack
);
2162 bool fontChanged
= false;
2164 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2169 if ( p
->IsCategory() )
2171 // Captions are all cells merged as one
2172 dc
.SetFont(m_captionFont
);
2174 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2176 dc
.SetBrush(rowBgBrush
);
2177 dc
.SetPen(rowBgBrush
.GetColour());
2178 dc
.SetTextForeground(rowFgCol
);
2180 dc
.DrawRectangle(cellRect
);
2183 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2184 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2187 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2188 DrawExpanderButton( dc
, butRect
, p
);
2192 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2194 dc
.SetFont(m_captionFont
);
2200 int nextCellWidth
= state
->m_colWidths
[0];
2201 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2202 int textXAdd
= textMarginHere
- greyDepthX
;
2204 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2206 cellRect
.width
= nextCellWidth
- 1;
2208 bool ctrlCell
= false;
2211 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2213 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2214 dc
.SetBrush(editorBgCol
);
2215 dc
.SetPen(editorBgCol
);
2216 dc
.SetTextForeground(m_colPropFore
);
2218 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2223 dc
.SetBrush(rowBgBrush
);
2224 dc
.SetPen(rowBgBrush
.GetColour());
2225 dc
.SetTextForeground(rowFgCol
);
2228 dc
.DrawRectangle(cellRect
);
2231 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2232 DrawExpanderButton( dc
, butRect
, p
);
2234 dc
.SetClippingRegion(cellRect
);
2236 cellRect
.x
+= textXAdd
;
2237 cellRect
.width
-= textXAdd
;
2242 wxPGCellRenderer
* renderer
;
2243 int cmnVal
= p
->GetCommonValue();
2244 if ( cmnVal
== -1 || ci
!= 1 )
2246 renderer
= p
->GetCellRenderer(ci
);
2247 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2251 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2252 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2256 cellX
+= state
->m_colWidths
[ci
];
2257 if ( ci
< (state
->m_colWidths
.size()-1) )
2258 nextCellWidth
= state
->m_colWidths
[ci
+1];
2260 dc
.DestroyClippingRegion(); // Is this really necessary?
2266 dc
.SetFont(normalfont
);
2271 // Refresh editor controls (seems not needed on msw)
2272 // NOTE: This code is mandatory for GTK!
2273 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2274 if ( wasSelectedPainted
)
2277 m_wndEditor
->Refresh();
2279 m_wndEditor2
->Refresh();
2286 // -----------------------------------------------------------------------
2288 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2292 if ( m_width
< 10 || m_height
< 10 ||
2293 !m_pState
->m_properties
->GetChildCount() ||
2294 p1
== (wxPGProperty
*) NULL
)
2295 return wxRect(0,0,0,0);
2300 // Return rect which encloses the given property range
2302 int visTop
= p1
->GetY();
2305 visBottom
= p2
->GetY() + m_lineHeight
;
2307 visBottom
= m_height
+ visTop
;
2309 // If seleced property is inside the range, we'll extend the range to include
2311 wxPGProperty
* selected
= m_selected
;
2314 int selectedY
= selected
->GetY();
2315 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2317 wxWindow
* editor
= GetEditorControl();
2320 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2321 if ( visBottom2
> visBottom
)
2322 visBottom
= visBottom2
;
2327 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2330 // -----------------------------------------------------------------------
2332 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2337 if ( m_pState
->m_itemsAdded
)
2338 PrepareAfterItemsAdded();
2340 wxRect r
= GetPropertyRect(p1
, p2
);
2343 m_canvas
->RefreshRect(r
);
2347 // -----------------------------------------------------------------------
2349 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2351 if ( p
== m_selected
)
2352 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2354 DrawItemAndChildren(p
);
2357 // -----------------------------------------------------------------------
2359 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2364 // Draw item, children, and parent too, if it is not category
2365 wxPGProperty
* parent
= p
->GetParent();
2368 !parent
->IsCategory() &&
2369 parent
->GetParent() )
2372 parent
= parent
->GetParent();
2375 DrawItemAndChildren(p
);
2378 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2380 wxCHECK_RET( p
, wxT("invalid property id") );
2382 // Do not draw if in non-visible page
2383 if ( p
->GetParentState() != m_pState
)
2386 // do not draw a single item if multiple pending
2387 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2390 wxWindow
* wndPrimary
= GetEditorControl();
2392 // Update child control.
2393 if ( m_selected
&& m_selected
->GetParent() == p
)
2394 m_selected
->UpdateControl(wndPrimary
);
2396 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2398 DrawItems(p
, lastDrawn
);
2401 // -----------------------------------------------------------------------
2403 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2404 const wxRect
*rect
)
2406 PrepareAfterItemsAdded();
2408 wxWindow::Refresh(false);
2410 // TODO: Coordinate translation
2411 m_canvas
->Refresh(false, rect
);
2413 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2414 // I think this really helps only GTK+1.2
2415 if ( m_wndEditor
) m_wndEditor
->Refresh();
2416 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2420 // -----------------------------------------------------------------------
2421 // wxPropertyGrid global operations
2422 // -----------------------------------------------------------------------
2424 void wxPropertyGrid::Clear()
2428 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2429 wxPG_CHECK_RET_DBG( selRes
,
2430 wxT("failed to deselect a property (editor probably had invalid value)") );
2433 m_pState
->DoClear();
2439 RecalculateVirtualSize();
2441 // Need to clear some area at the end
2443 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2446 // -----------------------------------------------------------------------
2448 bool wxPropertyGrid::EnableCategories( bool enable
)
2450 if ( !ClearSelection() )
2456 // Enable categories
2459 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2464 // Disable categories
2466 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2469 if ( !m_pState
->EnableCategories(enable
) )
2474 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2476 m_pState
->m_itemsAdded
= 1; // force
2477 PrepareAfterItemsAdded();
2481 m_pState
->m_itemsAdded
= 1;
2483 // No need for RecalculateVirtualSize() here - it is already called in
2484 // wxPropertyGridPageState method above.
2491 // -----------------------------------------------------------------------
2493 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2495 wxASSERT( pNewState
);
2496 wxASSERT( pNewState
->GetGrid() );
2498 if ( pNewState
== m_pState
)
2501 wxPGProperty
* oldSelection
= m_selected
;
2506 bool selRes
= ClearSelection();
2507 wxPG_CHECK_RET_DBG( selRes
,
2508 wxT("failed to deselect a property (editor probably had invalid value)") );
2511 m_pState
->m_selected
= oldSelection
;
2513 bool orig_mode
= m_pState
->IsInNonCatMode();
2514 bool new_state_mode
= pNewState
->IsInNonCatMode();
2516 m_pState
= pNewState
;
2519 int pgWidth
= GetClientSize().x
;
2520 if ( HasVirtualWidth() )
2522 int minWidth
= pgWidth
;
2523 if ( pNewState
->m_width
< minWidth
)
2525 pNewState
->m_width
= minWidth
;
2526 pNewState
->CheckColumnWidths();
2532 // Just in case, fully re-center splitter
2533 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2534 pNewState
->m_fSplitterX
= -1.0;
2536 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2539 m_propHover
= (wxPGProperty
*) NULL
;
2541 // If necessary, convert state to correct mode.
2542 if ( orig_mode
!= new_state_mode
)
2544 // This should refresh as well.
2545 EnableCategories( orig_mode
?false:true );
2547 else if ( !m_frozen
)
2549 // Refresh, if not frozen.
2550 if ( m_pState
->m_itemsAdded
)
2551 PrepareAfterItemsAdded();
2554 if ( m_pState
->m_selected
)
2555 DoSelectProperty( m_pState
->m_selected
);
2557 RecalculateVirtualSize(0);
2561 m_pState
->m_itemsAdded
= 1;
2564 // -----------------------------------------------------------------------
2566 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2568 wxPG_PROP_ARG_CALL_PROLOG()
2570 m_pState
->SortChildren( p
);
2573 // -----------------------------------------------------------------------
2575 void wxPropertyGrid::Sort()
2577 bool selRes
= ClearSelection(); // This must be before state clear
2578 wxPG_CHECK_RET_DBG( selRes
,
2579 wxT("failed to deselect a property (editor probably had invalid value)") );
2584 // -----------------------------------------------------------------------
2586 // Call to SetSplitterPosition will always disable splitter auto-centering
2587 // if parent window is shown.
2588 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2590 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2593 wxPropertyGridPageState
* state
= m_pState
;
2595 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2600 CorrectEditorWidgetSizeX();
2606 // -----------------------------------------------------------------------
2608 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2610 SetSplitterPosition( m_width
/2, true );
2611 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2612 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2615 // -----------------------------------------------------------------------
2616 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2617 // -----------------------------------------------------------------------
2619 // Returns nearest paint visible property (such that will be painted unless
2620 // window is scrolled or resized). If given property is paint visible, then
2621 // it itself will be returned
2622 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2624 int vx
,vy1
;// Top left corner of client
2625 GetViewStart(&vx
,&vy1
);
2626 vy1
*= wxPG_PIXELS_PER_UNIT
;
2628 int vy2
= vy1
+ m_height
;
2629 int propY
= p
->GetY2(m_lineHeight
);
2631 if ( (propY
+ m_lineHeight
) < vy1
)
2634 return DoGetItemAtY( vy1
);
2636 else if ( propY
> vy2
)
2639 return DoGetItemAtY( vy2
);
2642 // Itself paint visible
2647 // -----------------------------------------------------------------------
2649 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2653 m_pushButKeyCode
= keycode
;
2654 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2655 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2659 m_pushButKeyCode
= WXK_DOWN
;
2660 m_pushButKeyCodeNeedsCtrl
= 0;
2661 m_pushButKeyCodeNeedsAlt
= 1;
2665 // -----------------------------------------------------------------------
2666 // Methods related to change in value, value modification and sending events
2667 // -----------------------------------------------------------------------
2669 // commits any changes in editor of selected property
2670 // return true if validation did not fail
2671 // flags are same as with DoSelectProperty
2672 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2674 // Committing already?
2675 if ( m_inCommitChangesFromEditor
)
2678 // Don't do this if already processing editor event. It might
2679 // induce recursive dialogs and crap like that.
2680 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2682 if ( m_inDoPropertyChanged
)
2689 IsEditorsValueModified() &&
2690 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2693 m_inCommitChangesFromEditor
= 1;
2695 wxVariant
variant(m_selected
->GetValueRef());
2696 bool valueIsPending
= false;
2698 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2699 // due to another window getting focus
2700 wxWindow
* oldFocus
= m_curFocused
;
2702 bool validationFailure
= false;
2703 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2705 m_chgInfo_changedProperty
= NULL
;
2707 // If truly modified, schedule value as pending.
2708 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2710 if ( DoEditorValidate() &&
2711 PerformValidation(m_selected
, variant
) )
2713 valueIsPending
= true;
2717 validationFailure
= true;
2722 EditorsValueWasNotModified();
2727 m_inCommitChangesFromEditor
= 0;
2729 if ( validationFailure
&& !forceSuccess
)
2733 oldFocus
->SetFocus();
2734 m_curFocused
= oldFocus
;
2737 res
= OnValidationFailure(m_selected
, variant
);
2739 // Now prevent further validation failure messages
2742 EditorsValueWasNotModified();
2743 OnValidationFailureReset(m_selected
);
2746 else if ( valueIsPending
)
2748 DoPropertyChanged( m_selected
, flags
);
2749 EditorsValueWasNotModified();
2758 // -----------------------------------------------------------------------
2760 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2763 // Runs all validation functionality.
2764 // Returns true if value passes all tests.
2767 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2769 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2771 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2776 // Adapt list to child values, if necessary
2777 wxVariant listValue
= pendingValue
;
2778 wxVariant
* pPendingValue
= &pendingValue
;
2779 wxVariant
* pList
= NULL
;
2781 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2782 // string value, then we need treat as it was changed instead
2783 // (or, in addition, as is the case with composite string parent).
2784 // This includes creating list variant for child values.
2786 wxPGProperty
* pwc
= p
->GetParent();
2787 wxPGProperty
* changedProperty
= p
;
2788 wxPGProperty
* baseChangedProperty
= changedProperty
;
2789 wxVariant bcpPendingList
;
2791 listValue
= pendingValue
;
2792 listValue
.SetName(p
->GetBaseName());
2795 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2797 wxVariantList tempList
;
2798 wxVariant
lv(tempList
, pwc
->GetBaseName());
2799 lv
.Append(listValue
);
2801 pPendingValue
= &listValue
;
2803 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2805 baseChangedProperty
= pwc
;
2806 bcpPendingList
= lv
;
2809 changedProperty
= pwc
;
2810 pwc
= pwc
->GetParent();
2814 wxPGProperty
* evtChangingProperty
= changedProperty
;
2816 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2818 value
= *pPendingValue
;
2822 // Convert list to child values
2823 pList
= pPendingValue
;
2824 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2827 wxVariant evtChangingValue
= value
;
2829 // FIXME: After proper ValueToString()s added, remove
2830 // this. It is just a temporary fix, as evt_changing
2831 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2832 // (unless it is selected, and textctrl editor is open).
2833 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2835 evtChangingProperty
= baseChangedProperty
;
2836 if ( evtChangingProperty
!= p
)
2838 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2842 evtChangingValue
= pendingValue
;
2846 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2848 if ( changedProperty
== m_selected
)
2850 wxWindow
* editor
= GetEditorControl();
2851 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2852 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2856 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2860 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2861 m_chgInfo_changedProperty
= changedProperty
;
2862 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2863 m_chgInfo_pendingValue
= value
;
2866 m_chgInfo_valueList
= *pList
;
2868 m_chgInfo_valueList
.MakeNull();
2870 // If changedProperty is not property which value was edited,
2871 // then call wxPGProperty::ValidateValue() for that as well.
2872 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2874 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2878 // SendEvent returns true if event was vetoed
2879 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2885 // -----------------------------------------------------------------------
2887 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2889 if ( !msg
.length() )
2893 if ( !wxPGGlobalVars
->m_offline
)
2895 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2898 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2901 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2904 pStatusBar
->SetStatusText(msg
);
2912 ::wxMessageBox(msg
, _T("Property Error"));
2915 // -----------------------------------------------------------------------
2917 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2919 int vfb
= m_validationInfo
.m_failureBehavior
;
2921 if ( vfb
& wxPG_VFB_BEEP
)
2924 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2925 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2927 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2928 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2930 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2932 wxColour vfbFg
= *wxWHITE
;
2933 wxColour vfbBg
= *wxRED
;
2934 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2935 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2937 DrawItemAndChildren(property
);
2939 if ( property
== m_selected
)
2941 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2943 wxWindow
* editor
= GetEditorControl();
2946 editor
->SetForegroundColour(vfbFg
);
2947 editor
->SetBackgroundColour(vfbBg
);
2953 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2955 wxString msg
= m_validationInfo
.m_failureMessage
;
2957 if ( !msg
.length() )
2958 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2960 DoShowPropertyError(property
, msg
);
2963 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2966 // -----------------------------------------------------------------------
2968 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2970 int vfb
= m_validationInfo
.m_failureBehavior
;
2972 if ( vfb
& wxPG_VFB_MARK_CELL
)
2974 property
->SetCell(0, NULL
);
2975 property
->SetCell(1, NULL
);
2977 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2979 if ( property
== m_selected
&& GetEditorControl() )
2981 // Calling this will recreate the control, thus resetting its colour
2982 RefreshProperty(property
);
2986 DrawItemAndChildren(property
);
2991 // -----------------------------------------------------------------------
2993 // flags are same as with DoSelectProperty
2994 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2996 if ( m_inDoPropertyChanged
)
2999 wxWindow
* editor
= GetEditorControl();
3001 m_pState
->m_anyModified
= 1;
3003 m_inDoPropertyChanged
= 1;
3005 // Maybe need to update control
3006 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3008 // These values were calculated in PerformValidation()
3009 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3010 wxVariant value
= m_chgInfo_pendingValue
;
3012 wxPGProperty
* topPaintedProperty
= changedProperty
;
3014 while ( !topPaintedProperty
->IsCategory() &&
3015 !topPaintedProperty
->IsRoot() )
3017 topPaintedProperty
= topPaintedProperty
->GetParent();
3020 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3022 // Set as Modified (not if dragging just began)
3023 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3025 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3026 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3029 SetCurControlBoldFont();
3035 // Propagate updates to parent(s)
3037 wxPGProperty
* prevPwc
= NULL
;
3039 while ( prevPwc
!= topPaintedProperty
)
3041 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3043 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3046 SetCurControlBoldFont();
3050 pwc
= pwc
->GetParent();
3053 // Draw the actual property
3054 DrawItemAndChildren( topPaintedProperty
);
3057 // If value was set by wxPGProperty::OnEvent, then update the editor
3059 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3062 p
->GetEditorClass()->UpdateControl(p
, editor
);
3066 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3067 if ( m_wndEditor
) m_wndEditor
->Refresh();
3068 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3073 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3075 // If top parent has composite string value, then send to child parents,
3076 // starting from baseChangedProperty.
3077 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3079 pwc
= m_chgInfo_baseChangedProperty
;
3081 while ( pwc
!= changedProperty
)
3083 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3084 pwc
= pwc
->GetParent();
3088 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3090 m_inDoPropertyChanged
= 0;
3095 // -----------------------------------------------------------------------
3097 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3099 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3101 m_chgInfo_changedProperty
= NULL
;
3103 if ( PerformValidation(p
, newValue
) )
3105 DoPropertyChanged(p
);
3110 OnValidationFailure(p
, newValue
);
3116 // -----------------------------------------------------------------------
3118 // Runs wxValidator for the selected property
3119 bool wxPropertyGrid::DoEditorValidate()
3124 // -----------------------------------------------------------------------
3126 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3128 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3129 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3131 wxWindow
* parent
= wnd
->GetParent();
3134 (parent
== m_canvas
||
3135 parent
->GetParent() == m_canvas
) )
3137 OnCustomEditorEvent((wxCommandEvent
&)event
);
3141 return wxPanel::ProcessEvent(event
);
3144 // -----------------------------------------------------------------------
3146 // NB: It may really not be wxCommandEvent - must check if necessary
3148 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3150 wxPGProperty
* selected
= m_selected
;
3153 // Somehow, event is handled after property has been deselected.
3154 // Possibly, but very rare.
3158 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3161 wxVariant
pendingValue(selected
->GetValueRef());
3162 wxWindow
* wnd
= GetEditorControl();
3164 bool wasUnspecified
= selected
->IsValueUnspecified();
3165 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3167 bool valueIsPending
= false;
3169 m_chgInfo_changedProperty
= NULL
;
3171 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3174 // Filter out excess wxTextCtrl modified events
3175 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3177 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3179 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3181 wxString newTcValue
= tc
->GetValue();
3182 if ( m_prevTcValue
== newTcValue
)
3185 m_prevTcValue
= newTcValue
;
3188 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3190 bool validationFailure
= false;
3191 bool buttonWasHandled
= false;
3194 // Try common button handling
3195 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3197 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3201 buttonWasHandled
= true;
3202 // Store as res2, as previously (and still currently alternatively)
3203 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3204 // in wxPGProperty::OnEvent().
3205 adapter
->ShowDialog( this, selected
);
3210 if ( !buttonWasHandled
)
3214 // First call editor class' event handler.
3215 const wxPGEditor
* editor
= selected
->GetEditorClass();
3217 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3219 // If changes, validate them
3220 if ( DoEditorValidate() )
3222 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3223 valueIsPending
= true;
3227 validationFailure
= true;
3232 // Then the property's custom handler (must be always called, unless
3233 // validation failed).
3234 if ( !validationFailure
)
3235 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3238 // SetValueInEvent(), as called in one of the functions referred above
3239 // overrides editor's value.
3240 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3242 valueIsPending
= true;
3243 pendingValue
= m_changeInEventValue
;
3244 selFlags
|= wxPG_SEL_DIALOGVAL
;
3247 if ( !validationFailure
&& valueIsPending
)
3248 if ( !PerformValidation(m_selected
, pendingValue
) )
3249 validationFailure
= true;
3251 if ( validationFailure
)
3253 OnValidationFailure(selected
, pendingValue
);
3255 else if ( valueIsPending
)
3257 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3259 DoPropertyChanged(selected
, selFlags
);
3260 EditorsValueWasNotModified();
3263 // Regardless of editor type, unfocus editor on
3264 // text-editing related enter press.
3265 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3272 // No value after all
3274 // Let unhandled button click events go to the parent
3275 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3277 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3278 GetEventHandler()->AddPendingEvent(evt
);
3282 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3285 // -----------------------------------------------------------------------
3286 // wxPropertyGrid editor control helper methods
3287 // -----------------------------------------------------------------------
3289 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3291 int itemy
= p
->GetY2(m_lineHeight
);
3293 int cust_img_space
= 0;
3294 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3295 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3297 // TODO: If custom image detection changes from current, change this.
3298 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3300 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3301 int imwid
= p
->OnMeasureImage().x
;
3302 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3303 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3308 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3310 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3315 // -----------------------------------------------------------------------
3317 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3319 wxSize sz
= GetImageSize(p
, item
);
3320 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3321 wxPG_CUSTOM_IMAGE_SPACINGY
,
3326 // return size of custom paint image
3327 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3329 // If called with NULL property, then return default image
3330 // size for properties that use image.
3332 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3334 wxSize cis
= p
->OnMeasureImage(item
);
3336 int choiceCount
= p
->m_choices
.GetCount();
3337 int comVals
= p
->GetDisplayedCommonValueCount();
3338 if ( item
>= choiceCount
&& comVals
> 0 )
3340 unsigned int cvi
= item
-choiceCount
;
3341 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3343 else if ( item
>= 0 && choiceCount
== 0 )
3344 return wxSize(0, 0);
3349 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3354 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3361 // -----------------------------------------------------------------------
3363 // takes scrolling into account
3364 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3367 GetViewStart(&vx
,&vy
);
3368 vy
*=wxPG_PIXELS_PER_UNIT
;
3369 vx
*=wxPG_PIXELS_PER_UNIT
;
3372 ClientToScreen( px
, py
);
3375 // -----------------------------------------------------------------------
3377 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3380 GetViewStart(&pt2
.x
,&pt2
.y
);
3381 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3382 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3386 return m_pState
->HitTest(pt2
);
3389 // -----------------------------------------------------------------------
3391 // custom set cursor
3392 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3394 if ( type
== m_curcursor
&& !override
) return;
3396 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3398 if ( type
== wxCURSOR_SIZEWE
)
3399 cursor
= m_cursorSizeWE
;
3401 m_canvas
->SetCursor( *cursor
);
3406 // -----------------------------------------------------------------------
3407 // wxPropertyGrid property selection
3408 // -----------------------------------------------------------------------
3410 // Setups event handling for child control
3411 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3413 wxWindowID id
= argWnd
->GetId();
3415 if ( argWnd
== m_wndEditor
)
3417 argWnd
->Connect(id
, wxEVT_MOTION
,
3418 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3420 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3421 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3423 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3424 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3426 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3427 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3429 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3430 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3432 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3433 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3438 argWnd
->Connect(id
, wxEVT_NAVIGATION_KEY
,
3439 wxNavigationKeyEventHandler(wxPropertyGrid::OnNavigationKey
));
3442 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3443 wxKeyEventHandler(wxPropertyGrid::OnChildKeyDown
),
3445 argWnd
->Connect(id
, wxEVT_KEY_UP
,
3446 wxKeyEventHandler(wxPropertyGrid::OnChildKeyUp
),
3448 argWnd
->Connect(id
, wxEVT_KILL_FOCUS
,
3449 wxFocusEventHandler(wxPropertyGrid::OnFocusEvent
),
3453 void wxPropertyGrid::FreeEditors()
3455 // Do not free editors immediately if processing events
3458 m_wndEditor2
->Hide();
3459 wxPendingDelete
.Append( m_wndEditor2
);
3460 m_wndEditor2
= (wxWindow
*) NULL
;
3465 m_wndEditor
->Hide();
3466 wxPendingDelete
.Append( m_wndEditor
);
3467 m_wndEditor
= (wxWindow
*) NULL
;
3471 // Call with NULL to de-select property
3472 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3474 wxPanel
* canvas
= GetPanel();
3478 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3479 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3481 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3484 if ( m_inDoSelectProperty
)
3487 m_inDoSelectProperty
= 1;
3489 wxPGProperty
* prev
= m_selected
;
3493 m_inDoSelectProperty
= 0;
3498 // If we are frozen, then just set the values.
3501 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3502 m_editorFocused
= 0;
3505 m_pState
->m_selected
= p
;
3507 // If frozen, always free controls. But don't worry, as Thaw will
3508 // recall SelectProperty to recreate them.
3511 // Prevent any further selection measures in this call
3512 p
= (wxPGProperty
*) NULL
;
3517 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3519 // Only set focus if not deselecting
3522 if ( flags
& wxPG_SEL_FOCUS
)
3526 m_wndEditor
->SetFocus();
3527 m_editorFocused
= 1;
3536 m_inDoSelectProperty
= 0;
3541 // First, deactivate previous
3545 OnValidationFailureReset(m_selected
);
3547 // Must double-check if this is an selected in case of forceswitch
3550 if ( !CommitChangesFromEditor(flags
) )
3552 // Validation has failed, so we can't exit the previous editor
3553 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3554 // _("Invalid Value"),wxOK|wxICON_ERROR);
3555 m_inDoSelectProperty
= 0;
3563 m_selected
= (wxPGProperty
*) NULL
;
3564 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3566 // We need to always fully refresh the grid here
3569 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3570 EditorsValueWasNotModified();
3573 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3576 // Then, activate the one given.
3579 int propY
= p
->GetY2(m_lineHeight
);
3581 int splitterX
= GetSplitterPosition();
3582 m_editorFocused
= 0;
3584 m_pState
->m_selected
= p
;
3585 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3587 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3589 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3591 // Do we need OnMeasureCalls?
3592 wxSize imsz
= p
->OnMeasureImage();
3595 // Only create editor for non-disabled non-caption
3596 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3598 // do this for non-caption items
3602 // Do we need to paint the custom image, if any?
3603 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3604 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3605 !p
->GetEditorClass()->CanContainCustomImage()
3607 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3609 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3610 wxPoint goodPos
= grect
.GetPosition();
3611 #if wxPG_CREATE_CONTROLS_HIDDEN
3612 int coord_adjust
= m_height
- goodPos
.y
;
3613 goodPos
.y
+= coord_adjust
;
3616 const wxPGEditor
* editor
= p
->GetEditorClass();
3617 wxCHECK_MSG(editor
, false,
3618 wxT("NULL editor class not allowed"));
3620 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3622 wxPGWindowList wndList
= editor
->CreateControls(this,
3628 // Below, bear in mind the difference between primaryCtrl and m_wndEditor:
3629 // m_wndEditor is the actual wxWindow on canvas, and primaryCtrl is
3630 // the actual editor control. They may different if wxPGClipperWindow is
3631 // used for this editor.
3633 m_wndEditor
= wndList
.m_primary
;
3634 m_wndEditor2
= wndList
.m_secondary
;
3635 wxWindow
* primaryCtrl
= GetEditorControl();
3637 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3638 // value is drawn as normal, and m_wndEditor2 is assumed
3639 // to be a right-aligned button that triggers a separate editorCtrl
3644 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3645 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3647 // Set validator, if any
3648 #if wxUSE_VALIDATORS
3649 wxValidator
* validator
= p
->GetValidator();
3651 primaryCtrl
->SetValidator(*validator
);
3654 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3655 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3657 // If it has modified status, use bold font
3658 // (must be done before capturing m_ctrlXAdjust)
3659 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3660 SetCurControlBoldFont();
3663 // Fix TextCtrl indentation
3664 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3665 wxTextCtrl
* tc
= NULL
;
3666 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3667 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3669 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3671 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3674 // Store x relative to splitter (we'll need it).
3675 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3677 // Check if background clear is not necessary
3678 wxPoint pos
= m_wndEditor
->GetPosition();
3679 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3681 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3684 m_wndEditor
->SetSizeHints(3, 3);
3685 if ( m_wndEditor
!= primaryCtrl
)
3686 primaryCtrl
->SetSizeHints(3, 3);
3688 #if wxPG_CREATE_CONTROLS_HIDDEN
3689 m_wndEditor
->Show(false);
3690 m_wndEditor
->Freeze();
3692 goodPos
= m_wndEditor
->GetPosition();
3693 goodPos
.y
-= coord_adjust
;
3694 m_wndEditor
->Move( goodPos
);
3697 SetupChildEventHandling(primaryCtrl
);
3699 // Focus and select all (wxTextCtrl, wxComboBox etc)
3700 if ( flags
& wxPG_SEL_FOCUS
)
3702 primaryCtrl
->SetFocus();
3704 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3710 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3711 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3713 // Get proper id for wndSecondary
3714 m_wndSecId
= m_wndEditor2
->GetId();
3715 wxWindowList children
= m_wndEditor2
->GetChildren();
3716 wxWindowList::iterator node
= children
.begin();
3717 if ( node
!= children
.end() )
3718 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3720 m_wndEditor2
->SetSizeHints(3,3);
3722 #if wxPG_CREATE_CONTROLS_HIDDEN
3723 wxRect sec_rect
= m_wndEditor2
->GetRect();
3724 sec_rect
.y
-= coord_adjust
;
3726 // Fine tuning required to fix "oversized"
3727 // button disappearance bug.
3728 if ( sec_rect
.y
< 0 )
3730 sec_rect
.height
+= sec_rect
.y
;
3733 m_wndEditor2
->SetSize( sec_rect
);
3735 m_wndEditor2
->Show();
3737 SetupChildEventHandling(m_wndEditor2
);
3739 // If no primary editor, focus to button to allow
3740 // it to interprete ENTER etc.
3741 // NOTE: Due to problems focusing away from it, this
3742 // has been disabled.
3744 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3745 m_wndEditor2->SetFocus();
3749 if ( flags
& wxPG_SEL_FOCUS
)
3750 m_editorFocused
= 1;
3755 // Make sure focus is in grid canvas (important for wxGTK, at least)
3759 EditorsValueWasNotModified();
3761 // If it's inside collapsed section, expand parent, scroll, etc.
3762 // Also, if it was partially visible, scroll it into view.
3763 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3768 #if wxPG_CREATE_CONTROLS_HIDDEN
3769 m_wndEditor
->Thaw();
3771 m_wndEditor
->Show(true);
3778 // Make sure focus is in grid canvas
3782 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3788 // Show help text in status bar.
3789 // (if found and grid not embedded in manager with help box and
3790 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3793 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3795 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3796 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3798 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3800 statusbar
= frame
->GetStatusBar();
3805 const wxString
* pHelpString
= (const wxString
*) NULL
;
3809 pHelpString
= &p
->GetHelpString();
3810 if ( pHelpString
->length() )
3812 // Set help box text.
3813 statusbar
->SetStatusText( *pHelpString
);
3814 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3818 if ( (!pHelpString
|| !pHelpString
->length()) &&
3819 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3821 // Clear help box - but only if it was written
3822 // by us at previous time.
3823 statusbar
->SetStatusText( m_emptyString
);
3824 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3830 m_inDoSelectProperty
= 0;
3832 // call wx event handler (here so that it also occurs on deselection)
3833 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3838 // -----------------------------------------------------------------------
3840 bool wxPropertyGrid::UnfocusEditor()
3842 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3845 if ( !CommitChangesFromEditor(0) )
3849 DrawItem(m_selected
);
3854 // -----------------------------------------------------------------------
3856 // This method is not inline because it called dozens of times
3857 // (i.e. two-arg function calls create smaller code size).
3858 bool wxPropertyGrid::DoClearSelection()
3860 return DoSelectProperty((wxPGProperty
*)NULL
);
3863 // -----------------------------------------------------------------------
3864 // wxPropertyGrid expand/collapse state
3865 // -----------------------------------------------------------------------
3867 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3869 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3871 // If active editor was inside collapsed section, then disable it
3872 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3874 if ( !ClearSelection() )
3878 // Store dont-center-splitter flag 'cause we need to temporarily set it
3879 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3880 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3882 bool res
= m_pState
->DoCollapse(pwc
);
3887 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3889 RecalculateVirtualSize();
3891 // Redraw etc. only if collapsed was visible.
3892 if (pwc
->IsVisible() &&
3894 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3896 // When item is collapsed so that scrollbar would move,
3897 // graphics mess is about (unless we redraw everything).
3902 // Clear dont-center-splitter flag if it wasn't set
3903 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3908 // -----------------------------------------------------------------------
3910 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3912 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3914 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3916 // Store dont-center-splitter flag 'cause we need to temporarily set it
3917 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3918 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3920 bool res
= m_pState
->DoExpand(pwc
);
3925 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3927 RecalculateVirtualSize();
3929 // Redraw etc. only if expanded was visible.
3930 if ( pwc
->IsVisible() && !m_frozen
&&
3931 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3935 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3938 DrawItems(pwc
, NULL
);
3943 // Clear dont-center-splitter flag if it wasn't set
3944 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3949 // -----------------------------------------------------------------------
3951 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3954 return m_pState
->DoHideProperty(p
, hide
, flags
);
3957 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3960 if ( !ClearSelection() )
3964 m_pState
->DoHideProperty(p
, hide
, flags
);
3966 RecalculateVirtualSize();
3973 // -----------------------------------------------------------------------
3974 // wxPropertyGrid size related methods
3975 // -----------------------------------------------------------------------
3977 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3979 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3983 // If virtual height was changed, then recalculate editor control position(s)
3984 if ( m_pState
->m_vhCalcPending
)
3985 CorrectEditorWidgetPosY();
3987 m_pState
->EnsureVirtualHeight();
3990 int by1
= m_pState
->GetVirtualHeight();
3991 int by2
= m_pState
->GetActualVirtualHeight();
3994 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3995 wxASSERT_MSG( false,
4001 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4003 int x
= m_pState
->m_width
;
4004 int y
= m_pState
->m_virtualHeight
;
4007 GetClientSize(&width
,&height
);
4009 // Now adjust virtual size.
4010 SetVirtualSize(x
, y
);
4016 // Adjust scrollbars
4017 if ( HasVirtualWidth() )
4019 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4020 xPos
= GetScrollPos( wxHORIZONTAL
);
4023 if ( forceXPos
!= -1 )
4026 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4029 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4030 int yPos
= GetScrollPos( wxVERTICAL
);
4032 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4033 xAmount
, yAmount
, xPos
, yPos
, true );
4035 // Must re-get size now
4036 GetClientSize(&width
,&height
);
4038 if ( !HasVirtualWidth() )
4040 m_pState
->SetVirtualWidth(width
);
4047 m_canvas
->SetSize( x
, y
);
4049 m_pState
->CheckColumnWidths();
4052 CorrectEditorWidgetSizeX();
4054 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4057 // -----------------------------------------------------------------------
4059 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4061 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4065 GetClientSize(&width
,&height
);
4070 #if wxPG_DOUBLE_BUFFER
4071 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4073 int dblh
= (m_lineHeight
*2);
4074 if ( !m_doubleBuffer
)
4076 // Create double buffer bitmap to draw on, if none
4077 int w
= (width
>250)?width
:250;
4078 int h
= height
+ dblh
;
4080 m_doubleBuffer
= new wxBitmap( w
, h
);
4084 int w
= m_doubleBuffer
->GetWidth();
4085 int h
= m_doubleBuffer
->GetHeight();
4087 // Double buffer must be large enough
4088 if ( w
< width
|| h
< (height
+dblh
) )
4090 if ( w
< width
) w
= width
;
4091 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4092 delete m_doubleBuffer
;
4093 m_doubleBuffer
= new wxBitmap( w
, h
);
4100 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4101 m_ncWidth
= event
.GetSize().x
;
4105 if ( m_pState
->m_itemsAdded
)
4106 PrepareAfterItemsAdded();
4108 // Without this, virtual size (atleast under wxGTK) will be skewed
4109 RecalculateVirtualSize();
4115 // -----------------------------------------------------------------------
4117 void wxPropertyGrid::SetVirtualWidth( int width
)
4121 // Disable virtual width
4122 width
= GetClientSize().x
;
4123 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4127 // Enable virtual width
4128 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4130 m_pState
->SetVirtualWidth( width
);
4133 void wxPropertyGrid::SetFocusOnCanvas()
4135 m_canvas
->SetFocusIgnoringChildren();
4136 m_editorFocused
= 0;
4139 // -----------------------------------------------------------------------
4140 // wxPropertyGrid mouse event handling
4141 // -----------------------------------------------------------------------
4143 // selFlags uses same values DoSelectProperty's flags
4144 // Returns true if event was vetoed.
4145 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4147 // Send property grid event of specific type and with specific property
4148 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4149 evt
.SetPropertyGrid(this);
4150 evt
.SetEventObject(m_eventObject
);
4154 evt
.SetCanVeto(true);
4155 evt
.SetupValidationInfo();
4156 m_validationInfo
.m_pValue
= pValue
;
4158 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4160 evtHandler
->ProcessEvent(evt
);
4162 return evt
.WasVetoed();
4165 // -----------------------------------------------------------------------
4167 // Return false if should be skipped
4168 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4172 // Need to set focus?
4173 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4178 wxPropertyGridPageState
* state
= m_pState
;
4180 int splitterHitOffset
;
4181 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4183 wxPGProperty
* p
= DoGetItemAtY(y
);
4187 int depth
= (int)p
->GetDepth() - 1;
4189 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4191 if ( x
>= marginEnds
)
4195 if ( p
->IsCategory() )
4197 // This is category.
4198 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4200 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4202 // Expand, collapse, activate etc. if click on text or left of splitter.
4205 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4210 if ( !DoSelectProperty( p
) )
4213 // On double-click, expand/collapse.
4214 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4216 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4217 else DoExpand( p
, true );
4221 else if ( splitterHit
== -1 )
4224 unsigned int selFlag
= 0;
4225 if ( columnHit
== 1 )
4227 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4228 selFlag
= wxPG_SEL_FOCUS
;
4230 if ( !DoSelectProperty( p
, selFlag
) )
4233 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4235 if ( p
->GetChildCount() && !p
->IsCategory() )
4236 // On double-click, expand/collapse.
4237 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4239 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4240 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4241 else DoExpand( p
, true );
4248 // click on splitter
4249 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4251 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4253 // Double-clicking the splitter causes auto-centering
4254 CenterSplitter( true );
4256 else if ( m_dragStatus
== 0 )
4259 // Begin draggin the splitter
4263 // Changes must be committed here or the
4264 // value won't be drawn correctly
4265 if ( !CommitChangesFromEditor() )
4268 m_wndEditor
->Show ( false );
4271 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4273 m_canvas
->CaptureMouse();
4274 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4278 m_draggedSplitter
= splitterHit
;
4279 m_dragOffset
= splitterHitOffset
;
4281 wxClientDC
dc(m_canvas
);
4283 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4284 // Fixes button disappearance bug
4286 m_wndEditor2
->Show ( false );
4289 m_startingSplitterX
= x
- splitterHitOffset
;
4297 if ( p
->GetChildCount() )
4299 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4301 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4303 int y2
= y
% m_lineHeight
;
4304 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4306 // On click on expander button, expand/collapse
4307 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4308 DoCollapse( p
, true );
4310 DoExpand( p
, true );
4319 // -----------------------------------------------------------------------
4321 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4322 wxMouseEvent
& WXUNUSED(event
) )
4326 // Select property here as well
4327 wxPGProperty
* p
= m_propHover
;
4328 if ( p
!= m_selected
)
4329 DoSelectProperty( p
);
4331 // Send right click event.
4332 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4339 // -----------------------------------------------------------------------
4341 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4342 wxMouseEvent
& WXUNUSED(event
) )
4346 // Select property here as well
4347 wxPGProperty
* p
= m_propHover
;
4349 if ( p
!= m_selected
)
4350 DoSelectProperty( p
);
4352 // Send double-click event.
4353 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4360 // -----------------------------------------------------------------------
4362 #if wxPG_SUPPORT_TOOLTIPS
4364 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4366 if ( tipString
.length() )
4368 m_canvas
->SetToolTip(tipString
);
4372 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4373 m_canvas
->SetToolTip( m_emptyString
);
4375 m_canvas
->SetToolTip( NULL
);
4380 #endif // #if wxPG_SUPPORT_TOOLTIPS
4382 // -----------------------------------------------------------------------
4384 // Return false if should be skipped
4385 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4387 // Safety check (needed because mouse capturing may
4388 // otherwise freeze the control)
4389 if ( m_dragStatus
> 0 && !event
.Dragging() )
4391 HandleMouseUp(x
,y
,event
);
4394 wxPropertyGridPageState
* state
= m_pState
;
4396 int splitterHitOffset
;
4397 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4398 int splitterX
= x
- splitterHitOffset
;
4400 if ( m_dragStatus
> 0 )
4402 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4403 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4406 int newSplitterX
= x
- m_dragOffset
;
4407 int splitterX
= x
- splitterHitOffset
;
4409 // Splitter redraw required?
4410 if ( newSplitterX
!= splitterX
)
4413 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4414 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4415 state
->m_fSplitterX
= (float) newSplitterX
;
4418 CorrectEditorWidgetSizeX();
4432 int ih
= m_lineHeight
;
4435 #if wxPG_SUPPORT_TOOLTIPS
4436 wxPGProperty
* prevHover
= m_propHover
;
4437 unsigned char prevSide
= m_mouseSide
;
4439 int curPropHoverY
= y
- (y
% ih
);
4441 // On which item it hovers
4442 if ( ( !m_propHover
)
4444 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4447 // Mouse moves on another property
4449 m_propHover
= DoGetItemAtY(y
);
4450 m_propHoverY
= curPropHoverY
;
4453 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4456 #if wxPG_SUPPORT_TOOLTIPS
4457 // Store which side we are on
4459 if ( columnHit
== 1 )
4461 else if ( columnHit
== 0 )
4465 // If tooltips are enabled, show label or value as a tip
4466 // in case it doesn't otherwise show in full length.
4468 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4470 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4472 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4474 if ( m_propHover
&& !m_propHover
->IsCategory() )
4477 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4479 // Show help string as a tooltip
4480 wxString tipString
= m_propHover
->GetHelpString();
4482 SetToolTip(tipString
);
4486 // Show cropped value string as a tooltip
4490 if ( m_mouseSide
== 1 )
4492 tipString
= m_propHover
->m_label
;
4493 space
= splitterX
-m_marginWidth
-3;
4495 else if ( m_mouseSide
== 2 )
4497 tipString
= m_propHover
->GetDisplayedString();
4499 space
= m_width
- splitterX
;
4500 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4501 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4507 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4510 SetToolTip( tipString
);
4517 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4518 m_canvas
->SetToolTip( m_emptyString
);
4520 m_canvas
->SetToolTip( NULL
);
4531 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4532 m_canvas
->SetToolTip( m_emptyString
);
4534 m_canvas
->SetToolTip( NULL
);
4542 if ( splitterHit
== -1 ||
4544 HasFlag(wxPG_STATIC_SPLITTER
) )
4546 // hovering on something else
4547 if ( m_curcursor
!= wxCURSOR_ARROW
)
4548 CustomSetCursor( wxCURSOR_ARROW
);
4552 // Do not allow splitter cursor on caption items.
4553 // (also not if we were dragging and its started
4554 // outside the splitter region)
4557 !m_propHover
->IsCategory() &&
4561 // hovering on splitter
4563 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4564 // reliably detected.
4565 //if ( m_curcursor != wxCURSOR_SIZEWE )
4566 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4572 // hovering on something else
4573 if ( m_curcursor
!= wxCURSOR_ARROW
)
4574 CustomSetCursor( wxCURSOR_ARROW
);
4581 // -----------------------------------------------------------------------
4583 // Also handles Leaving event
4584 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4585 wxMouseEvent
&WXUNUSED(event
) )
4587 wxPropertyGridPageState
* state
= m_pState
;
4591 int splitterHitOffset
;
4592 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4594 // No event type check - basicly calling this method should
4595 // just stop dragging.
4596 // Left up after dragged?
4597 if ( m_dragStatus
>= 1 )
4600 // End Splitter Dragging
4602 // DO NOT ENABLE FOLLOWING LINE!
4603 // (it is only here as a reminder to not to do it)
4606 // Disable splitter auto-centering
4607 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4609 // This is necessary to return cursor
4610 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4612 m_canvas
->ReleaseMouse();
4613 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4616 // Set back the default cursor, if necessary
4617 if ( splitterHit
== -1 ||
4620 CustomSetCursor( wxCURSOR_ARROW
);
4625 // Control background needs to be cleared
4626 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4627 DrawItem( m_selected
);
4631 m_wndEditor
->Show ( true );
4634 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4635 // Fixes button disappearance bug
4637 m_wndEditor2
->Show ( true );
4640 // This clears the focus.
4641 m_editorFocused
= 0;
4647 // -----------------------------------------------------------------------
4649 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4651 int splitterX
= GetSplitterPosition();
4654 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4658 wxWindow
* wnd
= GetEditorControl();
4660 // Hide popup on clicks
4661 if ( event
.GetEventType() != wxEVT_MOTION
)
4662 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4664 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4670 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4672 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4673 ux
>= (r
.x
+r
.width
) ||
4675 event
.m_y
>= (r
.y
+r
.height
)
4685 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4690 // -----------------------------------------------------------------------
4692 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4695 if ( OnMouseCommon( event
, &x
, &y
) )
4697 HandleMouseClick(x
,y
,event
);
4702 // -----------------------------------------------------------------------
4704 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4707 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4708 HandleMouseRightClick(x
,y
,event
);
4712 // -----------------------------------------------------------------------
4714 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4716 // Always run standard mouse-down handler as well
4717 OnMouseClick(event
);
4720 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4721 HandleMouseDoubleClick(x
,y
,event
);
4725 // -----------------------------------------------------------------------
4727 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4730 if ( OnMouseCommon( event
, &x
, &y
) )
4732 HandleMouseMove(x
,y
,event
);
4737 // -----------------------------------------------------------------------
4739 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4741 // Called when mouse moves in the empty space below the properties.
4742 CustomSetCursor( wxCURSOR_ARROW
);
4745 // -----------------------------------------------------------------------
4747 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4750 if ( OnMouseCommon( event
, &x
, &y
) )
4752 HandleMouseUp(x
,y
,event
);
4757 // -----------------------------------------------------------------------
4759 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4761 // This may get called from child control as well, so event's
4762 // mouse position cannot be relied on.
4764 if ( event
.Entering() )
4766 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4768 // TODO: Fix this (detect parent and only do
4769 // cursor trick if it is a manager).
4770 wxASSERT( GetParent() );
4771 GetParent()->SetCursor(wxNullCursor
);
4773 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4776 GetParent()->SetCursor(wxNullCursor
);
4778 else if ( event
.Leaving() )
4780 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4781 m_canvas
->SetCursor( wxNullCursor
);
4783 // Get real cursor position
4784 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4786 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4789 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4791 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4795 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4803 // -----------------------------------------------------------------------
4805 // Common code used by various OnMouseXXXChild methods.
4806 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4808 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4809 wxASSERT( topCtrlWnd
);
4811 event
.GetPosition(&x
,&y
);
4813 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4815 int splitterX
= GetSplitterPosition();
4817 wxRect r
= topCtrlWnd
->GetRect();
4818 if ( !m_dragStatus
&&
4819 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4820 y
>= 0 && y
< r
.height \
4823 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4828 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4835 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4838 if ( OnMouseChildCommon(event
,&x
,&y
) )
4840 bool res
= HandleMouseClick(x
,y
,event
);
4841 if ( !res
) event
.Skip();
4845 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4848 wxASSERT( m_wndEditor
);
4849 // These coords may not be exact (about +-2),
4850 // but that should not matter (right click is about item, not position).
4851 wxPoint pt
= m_wndEditor
->GetPosition();
4852 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4853 wxASSERT( m_selected
);
4854 m_propHover
= m_selected
;
4855 bool res
= HandleMouseRightClick(x
,y
,event
);
4856 if ( !res
) event
.Skip();
4859 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4862 if ( OnMouseChildCommon(event
,&x
,&y
) )
4864 bool res
= HandleMouseMove(x
,y
,event
);
4865 if ( !res
) event
.Skip();
4869 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4872 if ( OnMouseChildCommon(event
,&x
,&y
) )
4874 bool res
= HandleMouseUp(x
,y
,event
);
4875 if ( !res
) event
.Skip();
4879 // -----------------------------------------------------------------------
4880 // wxPropertyGrid keyboard event handling
4881 // -----------------------------------------------------------------------
4883 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4885 wxNavigationKeyEvent evt
;
4886 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4887 (dir
?wxNavigationKeyEvent::IsForward
:
4888 wxNavigationKeyEvent::IsBackward
));
4889 evt
.SetEventObject(this);
4890 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4894 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4896 // Translates wxKeyEvent to wxPG_ACTION_XXX
4898 int keycode
= event
.GetKeyCode();
4899 int modifiers
= event
.GetModifiers();
4901 wxASSERT( !(modifiers
&~(0xFFFF)) );
4903 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4905 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4907 if ( it
== m_actionTriggers
.end() )
4912 int second
= (it
->second
>>16) & 0xFFFF;
4916 return (it
->second
& 0xFFFF);
4919 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4921 wxASSERT( !(modifiers
&~(0xFFFF)) );
4923 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4925 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4927 if ( it
!= m_actionTriggers
.end() )
4929 // This key combination is already used
4931 // Can add secondary?
4932 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4933 wxT("You can only add up to two separate actions per key combination.") );
4935 action
= it
->second
| (action
<<16);
4938 m_actionTriggers
[hashMapKey
] = action
;
4941 void wxPropertyGrid::ClearActionTriggers( int action
)
4943 wxPGHashMapI2I::iterator it
;
4945 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4947 if ( it
->second
== action
)
4949 m_actionTriggers
.erase(it
);
4954 static void CopyTextToClipboard( const wxString
& text
)
4956 if ( wxTheClipboard
->Open() )
4958 // This data objects are held by the clipboard,
4959 // so do not delete them in the app.
4960 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
4961 wxTheClipboard
->Close();
4965 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
4968 // Handles key event when editor control is not focused.
4971 wxASSERT( !m_frozen
);
4975 // Travelsal between items, collapsing/expanding, etc.
4976 int keycode
= event
.GetKeyCode();
4978 if ( keycode
== WXK_TAB
)
4980 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
4984 // Ignore Alt and Control when they are down alone
4985 if ( keycode
== WXK_ALT
||
4986 keycode
== WXK_CONTROL
)
4993 int action
= KeyEventToActions(event
, &secondAction
);
4999 if ( ButtonTriggerKeyTest(event
) )
5002 wxPGProperty
* p
= m_selected
;
5004 if ( action
== wxPG_ACTION_COPY
)
5006 CopyTextToClipboard(p
->GetDisplayedString());
5010 // Travel and expand/collapse
5013 if ( p
->GetChildCount() &&
5014 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5017 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5019 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5022 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5024 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5031 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5035 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5046 if ( selectDir
>= -1 )
5048 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5050 DoSelectProperty(p
);
5056 // If nothing was selected, select the first item now
5057 // (or navigate out of tab).
5058 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5060 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5061 if ( p
) DoSelectProperty(p
);
5066 // -----------------------------------------------------------------------
5068 // Potentially handles a keyboard event for editor controls.
5069 // Returns false if event should *not* be skipped (on true it can
5070 // be optionally skipped).
5071 // Basicly, false means that SelectProperty was called (or was about
5072 // to be called, if canDestroy was false).
5073 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5077 if ( !m_selected
|| !m_wndEditor
)
5082 int action
= KeyEventToAction(event
);
5085 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5088 // Esc cancels any changes
5089 if ( IsEditorsValueModified() )
5091 EditorsValueWasNotModified();
5093 // Update the control as well
5094 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5096 m_selected
->GetDisplayedString() );
5099 OnValidationFailureReset(m_selected
);
5105 else if ( action
== wxPG_ACTION_COPY
)
5107 // NB: There is some problem with getting native cut-copy-paste keys to go through
5108 // for embedded editor wxTextCtrl. This is why we emulate.
5110 wxTextCtrl
* tc
= GetEditorTextCtrl();
5113 wxString sel
= tc
->GetStringSelection();
5115 CopyTextToClipboard(sel
);
5119 CopyTextToClipboard(m_selected
->GetDisplayedString());
5122 else if ( action
== wxPG_ACTION_CUT
)
5124 wxTextCtrl
* tc
= GetEditorTextCtrl();
5128 tc
->GetSelection(&from
, &to
);
5131 CopyTextToClipboard(tc
->GetStringSelection());
5132 tc
->Remove(from
, to
);
5136 else if ( action
== wxPG_ACTION_PASTE
)
5138 wxTextCtrl
* tc
= GetEditorTextCtrl();
5141 if (wxTheClipboard
->Open())
5143 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5145 wxTextDataObject data
;
5146 wxTheClipboard
->GetData( data
);
5148 tc
->GetSelection(&from
, &to
);
5151 tc
->Remove(from
, to
);
5152 tc
->WriteText(data
.GetText());
5156 tc
->WriteText(data
.GetText());
5159 wxTheClipboard
->Close();
5167 // -----------------------------------------------------------------------
5169 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5173 // Events to editor controls should get relayed here.
5175 wxWindow
* focused
= wxWindow::FindFocus();
5177 wxWindow
* primaryCtrl
= GetEditorControl();
5180 (focused
==primaryCtrl
5181 || m_editorFocused
) )
5183 // Child key must be processed here, since it can
5184 // destroy the control which is referred by its own
5186 HandleChildKey( event
);
5189 HandleKeyEvent( event
);
5192 // -----------------------------------------------------------------------
5194 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5196 m_keyComboConsumed
= 0;
5201 // -----------------------------------------------------------------------
5203 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5205 // Ignore events that occur very close to focus set
5206 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5208 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5213 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5215 int dir
= event
.GetDirection()?1:-1;
5219 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5221 wxWindow
* focused
= wxWindow::FindFocus();
5223 wxWindow
* wndToCheck
= GetEditorControl();
5225 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5226 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5228 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5229 if ( comboTextCtrl
)
5230 wndToCheck
= comboTextCtrl
;
5234 // Because of problems navigating from wxButton, do not go to it.
5237 // No primary, use secondary
5238 wndToCheck = m_wndEditor2;
5240 // If it has editor button, focus to it after the primary editor.
5241 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5242 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5243 // have somewhat debugged in window.cpp itself).
5244 else if ( focused == wndToCheck &&
5246 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5248 wndToCheck = m_wndEditor2;
5249 wxLogDebug(wxT("Exp1"));
5253 if ( focused
!= wndToCheck
&&
5256 wndToCheck
->SetFocus();
5258 // Select all text in wxTextCtrl etc.
5259 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5260 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5262 m_editorFocused
= 1;
5269 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5273 // This allows preventing NavigateOut to occur
5274 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5283 // -----------------------------------------------------------------------
5285 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5287 int keycode
= event
.GetKeyCode();
5289 // Does the keycode trigger button?
5290 if ( keycode
== m_pushButKeyCode
&&
5292 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5293 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5295 m_keyComboConsumed
= 1;
5297 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5298 GetEventHandler()->AddPendingEvent(evt
);
5305 // -----------------------------------------------------------------------
5307 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5309 int keycode
= event
.GetKeyCode();
5311 // Ignore Alt and Control when they are down alone
5312 if ( keycode
== WXK_ALT
||
5313 keycode
== WXK_CONTROL
)
5319 if ( ButtonTriggerKeyTest(event
) )
5322 if ( HandleChildKey(event
) == true )
5325 GetEventHandler()->AddPendingEvent(event
);
5328 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5330 m_keyComboConsumed
= 0;
5332 GetEventHandler()->AddPendingEvent(event
);
5337 // -----------------------------------------------------------------------
5338 // wxPropertyGrid miscellaneous event handling
5339 // -----------------------------------------------------------------------
5341 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5344 // Check if the focus is in this control or one of its children
5345 wxWindow
* newFocused
= wxWindow::FindFocus();
5347 if ( newFocused
!= m_curFocused
)
5348 HandleFocusChange( newFocused
);
5351 // Called by focus event handlers. newFocused is the window that becomes focused.
5352 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5354 unsigned int oldFlags
= m_iFlags
;
5356 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5358 wxWindow
* parent
= newFocused
;
5360 // This must be one of nextFocus' parents.
5363 // Use m_eventObject, which is either wxPropertyGrid or
5364 // wxPropertyGridManager, as appropriate.
5365 if ( parent
== m_eventObject
)
5367 m_iFlags
|= wxPG_FL_FOCUSED
;
5370 parent
= parent
->GetParent();
5373 m_curFocused
= newFocused
;
5375 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5376 (oldFlags
& wxPG_FL_FOCUSED
) )
5378 // On each focus kill, mark the next nav key event
5379 // to be ignored (can't do on set focus since the
5380 // event would occur before it).
5381 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5383 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5385 // Need to store changed value
5386 CommitChangesFromEditor();
5392 // Preliminary code for tab-order respecting
5393 // tab-traversal (but should be moved to
5396 wxWindow* prevFocus = event.GetWindow();
5397 wxWindow* useThis = this;
5398 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5399 useThis = GetParent();
5402 prevFocus->GetParent() == useThis->GetParent() )
5404 wxList& children = useThis->GetParent()->GetChildren();
5406 wxNode* node = children.Find(prevFocus);
5408 if ( node->GetNext() &&
5409 useThis == node->GetNext()->GetData() )
5410 DoSelectProperty(GetFirst());
5411 else if ( node->GetPrevious () &&
5412 useThis == node->GetPrevious()->GetData() )
5413 DoSelectProperty(GetLastProperty());
5418 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5422 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5423 DrawItem( m_selected
);
5427 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5429 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5430 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5431 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5432 //else if ( event.GetWindow() )
5434 HandleFocusChange(event
.GetWindow());
5439 // -----------------------------------------------------------------------
5441 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5443 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5446 // event.Skip() being commented out is aworkaround for bug reported
5447 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5451 // -----------------------------------------------------------------------
5453 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5455 m_iFlags
|= wxPG_FL_SCROLLED
;
5460 // -----------------------------------------------------------------------
5462 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5464 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5466 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5470 // -----------------------------------------------------------------------
5471 // Property editor related functions
5472 // -----------------------------------------------------------------------
5474 // noDefCheck = true prevents infinite recursion.
5475 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5478 wxASSERT( editorClass
);
5480 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5481 RegisterDefaultEditors();
5483 wxString name
= editorClass
->GetName();
5485 // Existing editor under this name?
5486 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5488 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5489 (wxPGEditor
*) vt_it
->second
,
5490 "Editor with given name was already registered" );
5492 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5497 // Registers all default editor classes
5498 void wxPropertyGrid::RegisterDefaultEditors()
5500 wxPGRegisterDefaultEditorClass( TextCtrl
);
5501 wxPGRegisterDefaultEditorClass( Choice
);
5502 wxPGRegisterDefaultEditorClass( ComboBox
);
5503 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5504 #if wxPG_INCLUDE_CHECKBOX
5505 wxPGRegisterDefaultEditorClass( CheckBox
);
5507 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5509 // Register SpinCtrl etc. editors before use
5510 RegisterAdditionalEditors();
5513 // -----------------------------------------------------------------------
5514 // wxPGStringTokenizer
5515 // Needed to handle C-style string lists (e.g. "str1" "str2")
5516 // -----------------------------------------------------------------------
5518 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5519 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5523 wxPGStringTokenizer::~wxPGStringTokenizer()
5527 bool wxPGStringTokenizer::HasMoreTokens()
5529 const wxString
& str
= *m_str
;
5531 wxString::const_iterator i
= m_curPos
;
5533 wxUniChar delim
= m_delimeter
;
5535 wxUniChar prev_a
= wxT('\0');
5537 bool inToken
= false;
5539 while ( i
!= str
.end() )
5548 m_readyToken
.clear();
5553 if ( prev_a
!= wxT('\\') )
5557 if ( a
!= wxT('\\') )
5577 m_curPos
= str
.end();
5585 wxString
wxPGStringTokenizer::GetNextToken()
5587 return m_readyToken
;
5590 // -----------------------------------------------------------------------
5592 // -----------------------------------------------------------------------
5594 wxPGChoiceEntry::wxPGChoiceEntry()
5595 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5599 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5600 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5601 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5605 // -----------------------------------------------------------------------
5607 // -----------------------------------------------------------------------
5609 wxPGChoicesData::wxPGChoicesData()
5614 wxPGChoicesData::~wxPGChoicesData()
5619 void wxPGChoicesData::Clear()
5623 for ( i
=0; i
<m_items
.size(); i
++ )
5631 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5633 wxASSERT( m_items
.size() == 0 );
5637 for ( i
=0; i
<data
->GetCount(); i
++ )
5638 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5641 // -----------------------------------------------------------------------
5643 // -----------------------------------------------------------------------
5645 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5649 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5650 m_data
->Insert( -1, p
);
5654 // -----------------------------------------------------------------------
5656 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5660 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5661 p
->SetBitmap(bitmap
);
5662 m_data
->Insert( -1, p
);
5666 // -----------------------------------------------------------------------
5668 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5672 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5673 m_data
->Insert(index
, p
);
5677 // -----------------------------------------------------------------------
5679 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5683 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5684 m_data
->Insert( index
, p
);
5688 // -----------------------------------------------------------------------
5690 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5696 while ( index
< GetCount() )
5698 int cmpRes
= GetLabel(index
).Cmp(label
);
5704 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5705 m_data
->Insert( index
, p
);
5709 // -----------------------------------------------------------------------
5711 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5715 unsigned int itemcount
= 0;
5716 const wxChar
** p
= &labels
[0];
5717 while ( *p
) { p
++; itemcount
++; }
5720 for ( i
= 0; i
< itemcount
; i
++ )
5722 int value
= wxPG_INVALID_VALUE
;
5725 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5729 // -----------------------------------------------------------------------
5731 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5736 unsigned int itemcount
= arr
.size();
5738 for ( i
= 0; i
< itemcount
; i
++ )
5740 int value
= wxPG_INVALID_VALUE
;
5743 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5747 // -----------------------------------------------------------------------
5749 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5754 unsigned int itemcount
= arr
.size();
5756 for ( i
= 0; i
< itemcount
; i
++ )
5758 int value
= wxPG_INVALID_VALUE
;
5759 if ( &arrint
&& arrint
.size() )
5761 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5765 // -----------------------------------------------------------------------
5767 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5769 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5771 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5772 delete m_data
->Item(i
);
5773 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5774 m_data
->m_items
.begin()+nIndex
+count
-1);
5777 // -----------------------------------------------------------------------
5779 int wxPGChoices::Index( const wxString
& str
) const
5784 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5786 if ( m_data
->Item(i
)->GetText() == str
)
5793 // -----------------------------------------------------------------------
5795 int wxPGChoices::Index( int val
) const
5800 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5802 if ( m_data
->Item(i
)->GetValue() == val
)
5809 // -----------------------------------------------------------------------
5811 wxArrayString
wxPGChoices::GetLabels() const
5816 if ( this && IsOk() )
5817 for ( i
=0; i
<GetCount(); i
++ )
5818 arr
.push_back(GetLabel(i
));
5823 // -----------------------------------------------------------------------
5825 bool wxPGChoices::HasValues() const
5830 // -----------------------------------------------------------------------
5832 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5839 for ( i
=0; i
< strings
.size(); i
++ )
5841 int index
= Index(strings
[i
]);
5843 arr
.Add(GetValue(index
));
5845 arr
.Add(wxPG_INVALID_VALUE
);
5852 // -----------------------------------------------------------------------
5854 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5855 wxArrayString
* unmatched
) const
5862 for ( i
=0; i
< strings
.size(); i
++ )
5864 const wxString
& str
= strings
[i
];
5865 int index
= Index(str
);
5868 else if ( unmatched
)
5869 unmatched
->Add(str
);
5876 // -----------------------------------------------------------------------
5878 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5882 if ( data
!= wxPGChoicesEmptyData
)
5889 // -----------------------------------------------------------------------
5891 void wxPGChoices::Init()
5893 m_data
= wxPGChoicesEmptyData
;
5896 // -----------------------------------------------------------------------
5898 void wxPGChoices::Free()
5900 if ( m_data
!= wxPGChoicesEmptyData
)
5903 m_data
= wxPGChoicesEmptyData
;
5907 // -----------------------------------------------------------------------
5908 // wxPropertyGridEvent
5909 // -----------------------------------------------------------------------
5911 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5914 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5915 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5916 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5917 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5918 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5919 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5920 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5921 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5922 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5925 // -----------------------------------------------------------------------
5927 void wxPropertyGridEvent::Init()
5929 m_validationInfo
= NULL
;
5931 m_wasVetoed
= false;
5934 // -----------------------------------------------------------------------
5936 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5937 : wxCommandEvent(commandType
,id
)
5943 // -----------------------------------------------------------------------
5945 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5946 : wxCommandEvent(event
)
5948 m_eventType
= event
.GetEventType();
5949 m_eventObject
= event
.m_eventObject
;
5951 m_property
= event
.m_property
;
5952 m_validationInfo
= event
.m_validationInfo
;
5953 m_canVeto
= event
.m_canVeto
;
5954 m_wasVetoed
= event
.m_wasVetoed
;
5957 // -----------------------------------------------------------------------
5959 wxPropertyGridEvent::~wxPropertyGridEvent()
5963 // -----------------------------------------------------------------------
5965 wxEvent
* wxPropertyGridEvent::Clone() const
5967 return new wxPropertyGridEvent( *this );
5970 // -----------------------------------------------------------------------
5971 // wxPropertyGridPopulator
5972 // -----------------------------------------------------------------------
5974 wxPropertyGridPopulator::wxPropertyGridPopulator()
5978 wxPGGlobalVars
->m_offline
++;
5981 // -----------------------------------------------------------------------
5983 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5986 m_propHierarchy
.clear();
5989 // -----------------------------------------------------------------------
5991 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5997 // -----------------------------------------------------------------------
5999 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6002 // Free unused sets of choices
6003 wxPGHashMapS2P::iterator it
;
6005 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6007 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6014 m_pg
->GetPanel()->Refresh();
6016 wxPGGlobalVars
->m_offline
--;
6019 // -----------------------------------------------------------------------
6021 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6022 const wxString
& propLabel
,
6023 const wxString
& propName
,
6024 const wxString
* propValue
,
6025 wxPGChoices
* pChoices
)
6027 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6028 wxPGProperty
* parent
= GetCurParent();
6030 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6032 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6036 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6038 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6042 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6044 property
->SetLabel(propLabel
);
6045 property
->DoSetName(propName
);
6047 if ( pChoices
&& pChoices
->IsOk() )
6048 property
->SetChoices(*pChoices
);
6050 m_state
->DoInsert(parent
, -1, property
);
6053 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6058 // -----------------------------------------------------------------------
6060 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6062 m_propHierarchy
.push_back(property
);
6063 DoScanForChildren();
6064 m_propHierarchy
.pop_back();
6067 // -----------------------------------------------------------------------
6069 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6070 const wxString
& idString
)
6072 wxPGChoices choices
;
6075 if ( choicesString
[0] == wxT('@') )
6077 wxString ids
= choicesString
.substr(1);
6078 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6079 if ( it
== m_dictIdChoices
.end() )
6080 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6082 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6087 if ( idString
.length() )
6089 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6090 if ( it
!= m_dictIdChoices
.end() )
6092 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6099 // Parse choices string
6100 wxString::const_iterator it
= choicesString
.begin();
6104 bool labelValid
= false;
6106 for ( ; it
!= choicesString
.end(); it
++ )
6112 if ( c
== wxT('"') )
6117 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6118 choices
.Add(label
, l
);
6121 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6126 else if ( c
== wxT('=') )
6133 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6140 if ( c
== wxT('"') )
6153 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6154 choices
.Add(label
, l
);
6157 if ( !choices
.IsOk() )
6159 choices
.EnsureData();
6163 if ( idString
.length() )
6164 m_dictIdChoices
[idString
] = choices
.GetData();
6171 // -----------------------------------------------------------------------
6173 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6175 if ( s
.Last() == wxT('%') )
6177 wxString s2
= s
.substr(0,s
.length()-1);
6179 if ( s2
.ToLong(&val
, 10) )
6181 *pval
= (val
*max
)/100;
6187 return s
.ToLong(pval
, 10);
6190 // -----------------------------------------------------------------------
6192 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6193 const wxString
& type
,
6194 const wxString
& value
)
6196 int l
= m_propHierarchy
.size();
6200 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6201 wxString valuel
= value
.Lower();
6204 if ( type
.length() == 0 )
6209 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6211 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6213 else if ( value
.ToLong(&v
, 0) )
6220 if ( type
== wxT("string") )
6224 else if ( type
== wxT("int") )
6227 value
.ToLong(&v
, 0);
6230 else if ( type
== wxT("bool") )
6232 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6239 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6244 p
->SetAttribute( name
, variant
);
6249 // -----------------------------------------------------------------------
6251 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6253 wxLogError(_("Error in resource: %s"),msg
.c_str());
6256 // -----------------------------------------------------------------------
6258 #endif // wxUSE_PROPGRID