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
);
426 DECLARE_EVENT_TABLE()
430 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
431 EVT_MOTION(wxPGCanvas::OnMouseMove
)
432 EVT_PAINT(wxPGCanvas::OnPaint
)
433 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
434 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
435 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
436 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
437 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
438 EVT_KEY_UP(wxPGCanvas::OnKeyUp
)
439 EVT_CHAR(wxPGCanvas::OnKey
)
440 EVT_NAVIGATION_KEY(wxPGCanvas::OnNavigationKey
)
444 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
446 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
447 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
451 // Don't paint after destruction has begun
452 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
455 // Update everything inside the box
456 wxRect r
= GetUpdateRegion().GetBox();
458 // Repaint this rectangle
459 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
461 // We assume that the size set when grid is shown
462 // is what is desired.
463 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
466 // -----------------------------------------------------------------------
468 // -----------------------------------------------------------------------
470 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
472 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
473 EVT_IDLE(wxPropertyGrid::OnIdle
)
474 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
475 EVT_PAINT(wxPropertyGrid::OnPaint
)
476 EVT_SIZE(wxPropertyGrid::OnResize
)
477 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
478 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
479 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
480 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
481 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
482 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
483 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
484 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
488 // -----------------------------------------------------------------------
490 wxPropertyGrid::wxPropertyGrid()
496 // -----------------------------------------------------------------------
498 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
507 Create(parent
,id
,pos
,size
,style
,name
);
510 // -----------------------------------------------------------------------
512 bool wxPropertyGrid::Create( wxWindow
*parent
,
520 if ( !(style
&wxBORDER_MASK
) )
521 style
|= wxSIMPLE_BORDER
;
526 // This prevents crash under Win2K, but still
527 // enables keyboard navigation
528 if ( style
& wxTAB_TRAVERSAL
)
530 style
&= ~(wxTAB_TRAVERSAL
);
531 style
|= wxWANTS_CHARS
;
534 if ( style
& wxTAB_TRAVERSAL
)
535 style
|= wxWANTS_CHARS
;
538 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
545 // -----------------------------------------------------------------------
548 // Initialize values to defaults
550 void wxPropertyGrid::Init1()
552 // Register editor classes, if necessary.
553 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
554 wxPropertyGrid::RegisterDefaultEditors();
557 m_pState
= (wxPropertyGridPageState
*) NULL
;
558 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
559 m_selected
= (wxPGProperty
*) NULL
;
561 m_propHover
= (wxPGProperty
*) NULL
;
562 m_eventObject
= this;
563 m_curFocused
= (wxWindow
*) NULL
;
565 m_inDoPropertyChanged
= 0;
566 m_inCommitChangesFromEditor
= 0;
567 m_inDoSelectProperty
= 0;
568 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
574 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
575 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
576 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
577 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
578 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
579 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
580 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
581 AddActionTrigger( wxPG_ACTION_CUT
, 'X', wxMOD_CONTROL
);
582 AddActionTrigger( wxPG_ACTION_CUT
, WXK_DELETE
, wxMOD_SHIFT
);
583 AddActionTrigger( wxPG_ACTION_COPY
, 'C', wxMOD_CONTROL
);
584 AddActionTrigger( wxPG_ACTION_COPY
, WXK_INSERT
, wxMOD_CONTROL
);
585 AddActionTrigger( wxPG_ACTION_PASTE
, 'V', wxMOD_CONTROL
);
586 AddActionTrigger( wxPG_ACTION_PASTE
, WXK_INSERT
, wxMOD_SHIFT
);
588 m_coloursCustomized
= 0;
593 #if wxPG_DOUBLE_BUFFER
594 m_doubleBuffer
= (wxBitmap
*) NULL
;
597 m_windowsToDelete
= NULL
;
599 #ifndef wxPG_ICON_WIDTH
605 m_iconWidth
= wxPG_ICON_WIDTH
;
610 m_gutterWidth
= wxPG_GUTTER_MIN
;
611 m_subgroup_extramargin
= 10;
615 m_width
= m_height
= 0;
617 SetButtonShortcut(0);
619 m_keyComboConsumed
= 0;
621 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
624 m_chgInfo_changedProperty
= NULL
;
627 // -----------------------------------------------------------------------
630 // Initialize after parent etc. set
632 void wxPropertyGrid::Init2()
634 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
637 // Smaller controls on Mac
638 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
641 // Now create state, if one didn't exist already
642 // (wxPropertyGridManager might have created it for us).
645 m_pState
= CreateState();
646 m_pState
->m_pPropGrid
= this;
647 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
650 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
651 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
653 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
655 m_pState
->InitNonCatMode();
657 m_pState
->m_properties
= m_pState
->m_abcArray
;
660 GetClientSize(&m_width
,&m_height
);
662 #ifndef wxPG_ICON_WIDTH
663 // create two bitmap nodes for drawing
664 m_expandbmp
= new wxBitmap(expand_xpm
);
665 m_collbmp
= new wxBitmap(collapse_xpm
);
667 // calculate average font height for bitmap centering
669 m_iconWidth
= m_expandbmp
->GetWidth();
670 m_iconHeight
= m_expandbmp
->GetHeight();
673 m_curcursor
= wxCURSOR_ARROW
;
674 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
676 // adjust bitmap icon y position so they are centered
677 m_vspacing
= wxPG_DEFAULT_VSPACING
;
681 wxFont useFont
= wxScrolledWindow::GetFont();
682 wxScrolledWindow::SetOwnFont( useFont
);
685 // This should be otherwise called by SetOwnFont
686 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
688 // Add base brush item
689 m_arrBgBrushes
.Add((void*)new wxPGBrush());
691 // Add base colour items
692 m_arrFgCols
.Add((void*)new wxPGColour());
693 m_arrFgCols
.Add((void*)new wxPGColour());
697 // This helps with flicker
698 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
701 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
702 m_tlp
= ::wxGetTopLevelParent(this);
703 m_tlwHandler
= handler
;
704 m_tlp
->PushEventHandler(handler
);
706 // set virtual size to this window size
707 wxSize wndsize
= GetSize();
708 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
710 m_timeCreated
= ::wxGetLocalTimeMillis();
712 m_canvas
= new wxPGCanvas();
713 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
714 (GetWindowStyle() & wxTAB_TRAVERSAL
) | wxWANTS_CHARS
| wxCLIP_CHILDREN
);
715 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
717 m_iFlags
|= wxPG_FL_INITIALIZED
;
719 m_ncWidth
= wndsize
.GetWidth();
721 // Need to call OnResize handler or size given in constructor/Create
723 wxSizeEvent
sizeEvent(wndsize
,0);
727 // -----------------------------------------------------------------------
729 wxPropertyGrid::~wxPropertyGrid()
733 DoSelectProperty(NULL
);
735 // This should do prevent things from going too badly wrong
736 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
738 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
739 m_canvas
->ReleaseMouse();
741 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
742 m_tlp
->RemoveEventHandler(handler
);
746 if ( IsEditorsValueModified() )
747 ::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).)"),
748 wxS("wxPropertyGrid Debug Warning") );
751 #if wxPG_DOUBLE_BUFFER
752 if ( m_doubleBuffer
)
753 delete m_doubleBuffer
;
756 delete m_windowsToDelete
;
758 //m_selected = (wxPGProperty*) NULL;
760 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
763 delete m_cursorSizeWE
;
765 #ifndef wxPG_ICON_WIDTH
770 // Delete cached text colours.
771 for ( i
=0; i
<m_arrFgCols
.size(); i
++ )
773 delete (wxPGColour
*)m_arrFgCols
.Item(i
);
776 // Delete cached brushes.
777 for ( i
=0; i
<m_arrBgBrushes
.size(); i
++ )
779 delete (wxPGBrush
*)m_arrBgBrushes
.Item(i
);
782 // Delete common value records
783 for ( i
=0; i
<m_commonValues
.size(); i
++ )
785 delete GetCommonValue(i
);
789 // -----------------------------------------------------------------------
791 bool wxPropertyGrid::Destroy()
793 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
794 m_canvas
->ReleaseMouse();
796 return wxScrolledWindow::Destroy();
799 // -----------------------------------------------------------------------
801 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
803 return new wxPropertyGridPageState();
806 // -----------------------------------------------------------------------
807 // wxPropertyGrid overridden wxWindow methods
808 // -----------------------------------------------------------------------
810 void wxPropertyGrid::SetWindowStyleFlag( long style
)
812 long old_style
= m_windowStyle
;
814 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
816 wxASSERT( m_pState
);
818 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
821 EnableCategories( true );
823 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
825 // Disable categories
826 EnableCategories( false );
828 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
834 PrepareAfterItemsAdded();
836 m_pState
->m_itemsAdded
= 1;
838 #if wxPG_SUPPORT_TOOLTIPS
839 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
845 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
846 SetToolTip ( tooltip );
847 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
850 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
855 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
860 wxScrolledWindow::SetWindowStyleFlag ( style
);
862 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
864 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
866 CalculateFontAndBitmapStuff( m_vspacing
);
872 // -----------------------------------------------------------------------
874 void wxPropertyGrid::Freeze()
878 wxScrolledWindow::Freeze();
883 // -----------------------------------------------------------------------
885 void wxPropertyGrid::Thaw()
891 wxScrolledWindow::Thaw();
892 RecalculateVirtualSize();
893 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
897 // Force property re-selection
899 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
903 // -----------------------------------------------------------------------
905 void wxPropertyGrid::SetExtraStyle( long exStyle
)
907 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
909 #if defined(__WXMSW__)
912 // Don't use WS_EX_COMPOSITED just now.
915 if ( m_iFlags & wxPG_FL_IN_MANAGER )
916 hWnd = (HWND)GetParent()->GetHWND();
918 hWnd = (HWND)GetHWND();
920 ::SetWindowLong( hWnd, GWL_EXSTYLE,
921 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
924 //#elif defined(__WXGTK20__)
926 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
927 // truly was double-buffered.
928 if ( !this->IsDoubleBuffered() )
930 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
934 #if wxPG_DOUBLE_BUFFER
935 delete m_doubleBuffer
;
936 m_doubleBuffer
= NULL
;
941 wxScrolledWindow::SetExtraStyle( exStyle
);
943 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
944 m_pState
->InitNonCatMode();
946 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
947 m_windowStyle
|= wxPG_TOOLTIPS
;
950 wxPGGlobalVars
->m_extraStyle
= exStyle
;
953 // -----------------------------------------------------------------------
955 // returns the best acceptable minimal size
956 wxSize
wxPropertyGrid::DoGetBestSize() const
959 if ( m_lineHeight
> hei
)
961 wxSize sz
= wxSize( 60, hei
+40 );
967 // -----------------------------------------------------------------------
968 // wxPropertyGrid Font and Colour Methods
969 // -----------------------------------------------------------------------
971 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
975 m_captionFont
= wxScrolledWindow::GetFont();
977 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
978 m_subgroup_extramargin
= x
+ (x
/2);
981 #if wxPG_USE_RENDERER_NATIVE
982 m_iconWidth
= wxPG_ICON_WIDTH
;
983 #elif wxPG_ICON_WIDTH
985 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
986 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
987 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
991 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
992 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
993 m_gutterWidth
= wxPG_GUTTER_MIN
;
996 if ( vspacing
<= 1 ) vdiv
= 12;
997 else if ( vspacing
>= 3 ) vdiv
= 3;
999 m_spacingy
= m_fontHeight
/ vdiv
;
1000 if ( m_spacingy
< wxPG_YSPACING_MIN
)
1001 m_spacingy
= wxPG_YSPACING_MIN
;
1004 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
1005 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
1007 m_captionFont
.SetWeight(wxBOLD
);
1008 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
1010 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
1013 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
1014 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
1017 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
1019 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1020 RecalculateVirtualSize();
1022 InvalidateBestSize();
1025 // -----------------------------------------------------------------------
1027 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
1033 // -----------------------------------------------------------------------
1035 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
1036 int ga
= 1000, int ba
= 1000,
1037 bool forceDifferent
= false)
1044 // Recursion guard (allow 2 max)
1045 static int isinside
= 0;
1047 wxCHECK_MSG( isinside
< 3,
1049 wxT("wxPGAdjustColour should not be recursively called more than once") );
1054 int g
= src
.Green();
1057 if ( r2
>255 ) r2
= 255;
1058 else if ( r2
<0) r2
= 0;
1060 if ( g2
>255 ) g2
= 255;
1061 else if ( g2
<0) g2
= 0;
1063 if ( b2
>255 ) b2
= 255;
1064 else if ( b2
<0) b2
= 0;
1066 // Make sure they are somewhat different
1067 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
1068 dst
= wxPGAdjustColour(src
,-(ra
*2));
1070 dst
= wxColour(r2
,g2
,b2
);
1072 // Recursion guard (allow 2 max)
1079 static int wxPGGetColAvg( const wxColour
& col
)
1081 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
1085 void wxPropertyGrid::RegainColours()
1087 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1089 if ( !(m_coloursCustomized
& 0x0002) )
1091 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1093 // Make sure colour is dark enough
1095 int colDec
= wxPGGetColAvg(col
) - 230;
1097 int colDec
= wxPGGetColAvg(col
) - 200;
1100 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1105 if ( !(m_coloursCustomized
& 0x0001) )
1106 m_colMargin
= m_colCapBack
;
1108 if ( !(m_coloursCustomized
& 0x0004) )
1115 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1116 m_colCapFore
= capForeCol
;
1118 // Set the cached colour as well.
1119 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(capForeCol
);
1122 if ( !(m_coloursCustomized
& 0x0008) )
1124 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1125 m_colPropBack
= bgCol
;
1127 // Set the cached brush as well.
1128 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(bgCol
);
1131 if ( !(m_coloursCustomized
& 0x0010) )
1133 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1134 m_colPropFore
= fgCol
;
1136 // Set the cached colour as well.
1137 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(fgCol
);
1140 if ( !(m_coloursCustomized
& 0x0020) )
1141 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1143 if ( !(m_coloursCustomized
& 0x0040) )
1144 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1146 if ( !(m_coloursCustomized
& 0x0080) )
1147 m_colLine
= m_colCapBack
;
1149 if ( !(m_coloursCustomized
& 0x0100) )
1150 m_colDisPropFore
= m_colCapFore
;
1152 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1155 // -----------------------------------------------------------------------
1157 void wxPropertyGrid::ResetColours()
1159 m_coloursCustomized
= 0;
1166 // -----------------------------------------------------------------------
1168 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1170 // Must disable active editor.
1173 bool selRes
= ClearSelection();
1174 wxPG_CHECK_MSG_DBG( selRes
,
1176 wxT("failed to deselect a property (editor probably had invalid value)") );
1179 // TODO: Following code is disabled with wxMac because
1180 // it is reported to fail. I (JMS) cannot debug it
1181 // personally right now.
1182 #if !defined(__WXMAC__)
1183 bool res
= wxScrolledWindow::SetFont( font
);
1186 CalculateFontAndBitmapStuff( m_vspacing
);
1189 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1197 // TODO: Remove after SetFont crash fixed.
1198 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1200 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."));
1206 // -----------------------------------------------------------------------
1208 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1211 m_coloursCustomized
|= 0x80;
1215 // -----------------------------------------------------------------------
1217 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1220 m_coloursCustomized
|= 0x01;
1224 // -----------------------------------------------------------------------
1226 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1228 m_colPropBack
= col
;
1229 m_coloursCustomized
|= 0x08;
1231 // Set the cached brush as well.
1232 ((wxPGBrush
*)m_arrBgBrushes
.Item(0))->SetColour2(col
);
1237 // -----------------------------------------------------------------------
1239 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1241 m_colPropFore
= col
;
1242 m_coloursCustomized
|= 0x10;
1244 // Set the cached colour as well.
1245 ((wxPGColour
*)m_arrFgCols
.Item(0))->SetColour2(col
);
1250 // -----------------------------------------------------------------------
1252 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1254 m_colEmptySpace
= col
;
1259 // -----------------------------------------------------------------------
1261 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1263 m_colDisPropFore
= col
;
1264 m_coloursCustomized
|= 0x100;
1268 // -----------------------------------------------------------------------
1270 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1273 m_coloursCustomized
|= 0x20;
1277 // -----------------------------------------------------------------------
1279 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1282 m_coloursCustomized
|= 0x40;
1286 // -----------------------------------------------------------------------
1288 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1291 m_coloursCustomized
|= 0x02;
1295 // -----------------------------------------------------------------------
1297 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1300 m_coloursCustomized
|= 0x04;
1302 // Set the cached colour as well.
1303 ((wxPGColour
*)m_arrFgCols
.Item(1))->SetColour2(col
);
1308 // -----------------------------------------------------------------------
1310 void wxPropertyGrid::SetBackgroundColourIndex( wxPGProperty
* p
, int index
)
1312 unsigned char ind
= index
;
1314 p
->m_bgColIndex
= ind
;
1317 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1318 SetBackgroundColourIndex(p
->Item(i
),index
);
1321 // -----------------------------------------------------------------------
1323 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
, const wxColour
& colour
)
1325 wxPG_PROP_ARG_CALL_PROLOG()
1330 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1332 // As it is most likely that the previous colour is used, start comparison
1334 for ( i
=(m_arrBgBrushes
.size()-1); i
>0; i
-- )
1336 if ( ((wxPGBrush
*)m_arrBgBrushes
.Item(i
))->GetColourAsLong() == colAsLong
)
1345 colInd
= m_arrBgBrushes
.size();
1346 wxCHECK_RET( colInd
< 256, wxT("wxPropertyGrid: Warning - Only 255 different property background colours allowed.") );
1347 m_arrBgBrushes
.Add( (void*)new wxPGBrush(colour
) );
1351 SetBackgroundColourIndex(p
,colInd
);
1353 // If this was on a visible grid, then draw it.
1354 DrawItemAndChildren(p
);
1357 // -----------------------------------------------------------------------
1359 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1361 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1363 return ((wxPGBrush
*)m_arrBgBrushes
.Item(p
->m_bgColIndex
))->GetColour();
1366 // -----------------------------------------------------------------------
1368 void wxPropertyGrid::SetTextColourIndex( wxPGProperty
* p
, int index
, int flags
)
1370 unsigned char ind
= index
;
1372 p
->m_fgColIndex
= ind
;
1374 if ( p
->GetChildCount() && (flags
& wxPG_RECURSE
) )
1377 for ( i
=0; i
<p
->GetChildCount(); i
++ )
1378 SetTextColourIndex( p
->Item(i
), index
, flags
);
1382 // -----------------------------------------------------------------------
1384 int wxPropertyGrid::CacheColour( const wxColour
& colour
)
1389 long colAsLong
= wxPG_COLOUR(colour
.Red(),colour
.Green(),colour
.Blue());
1391 // As it is most likely that the previous colour is used, start comparison
1393 for ( i
=(m_arrFgCols
.size()-1); i
>0; i
-- )
1395 if ( ((wxPGColour
*)m_arrFgCols
.Item(i
))->GetColourAsLong() == colAsLong
)
1404 colInd
= m_arrFgCols
.size();
1405 wxCHECK_MSG( colInd
< 256, 0, wxT("wxPropertyGrid: Warning - Only 255 different property foreground colours allowed.") );
1406 m_arrFgCols
.Add( (void*)new wxPGColour(colour
) );
1412 // -----------------------------------------------------------------------
1414 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1417 wxPG_PROP_ARG_CALL_PROLOG()
1419 if ( p
->IsCategory() )
1421 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1422 cat
->SetTextColIndex(CacheColour(colour
));
1428 flags
|= wxPG_RECURSE
;
1429 SetTextColourIndex(p
, CacheColour(colour
), flags
);
1431 DrawItemAndChildren(p
);
1434 // -----------------------------------------------------------------------
1436 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1438 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1440 return wxColour(*((wxPGColour
*)m_arrFgCols
.Item(p
->m_fgColIndex
)));
1443 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1445 wxPG_PROP_ARG_CALL_PROLOG()
1447 SetBackgroundColourIndex( p
, 0 );
1448 SetTextColourIndex( p
, 0, wxPG_RECURSE
);
1450 if ( p
->IsCategory() )
1452 wxPropertyCategory
* cat
= (wxPropertyCategory
*) p
;
1453 cat
->SetTextColIndex(1);
1457 // -----------------------------------------------------------------------
1458 // wxPropertyGrid property adding and removal
1459 // -----------------------------------------------------------------------
1461 void wxPropertyGrid::PrepareAfterItemsAdded()
1463 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1465 m_pState
->m_itemsAdded
= 0;
1467 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1470 RecalculateVirtualSize();
1473 // -----------------------------------------------------------------------
1474 // wxPropertyGrid property value setting and getting
1475 // -----------------------------------------------------------------------
1477 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1479 m_pState
->DoSetPropertyValueUnspecified(p
);
1480 DrawItemAndChildren(p
);
1482 wxPGProperty
* parent
= p
->GetParent();
1483 while ( (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1486 parent
= parent
->GetParent();
1490 // -----------------------------------------------------------------------
1491 // wxPropertyGrid property operations
1492 // -----------------------------------------------------------------------
1494 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1496 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1500 bool changed
= false;
1502 // Is it inside collapsed section?
1503 if ( !p
->IsVisible() )
1506 wxPGProperty
* parent
= p
->GetParent();
1507 wxPGProperty
* grandparent
= parent
->GetParent();
1509 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1510 Expand( grandparent
);
1518 GetViewStart(&vx
,&vy
);
1519 vy
*=wxPG_PIXELS_PER_UNIT
;
1525 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1526 m_iFlags
|= wxPG_FL_SCROLLED
;
1529 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1531 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1532 m_iFlags
|= wxPG_FL_SCROLLED
;
1542 // -----------------------------------------------------------------------
1543 // wxPropertyGrid helper methods called by properties
1544 // -----------------------------------------------------------------------
1546 // Control font changer helper.
1547 void wxPropertyGrid::SetCurControlBoldFont()
1549 wxASSERT( m_wndEditor
);
1550 m_wndEditor
->SetFont( m_captionFont
);
1553 // -----------------------------------------------------------------------
1555 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1558 #if wxPG_SMALL_SCREEN
1559 // On small-screen devices, always show dialogs with default position and size.
1560 return wxDefaultPosition
;
1562 int splitterX
= GetSplitterPosition();
1566 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1568 ImprovedClientToScreen( &x
, &y
);
1570 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1571 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1578 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1588 new_y
= y
+ m_lineHeight
;
1590 return wxPoint(new_x
,new_y
);
1594 // -----------------------------------------------------------------------
1596 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1598 if ( src_str
.length() == 0 )
1604 bool prev_is_slash
= false;
1606 wxString::const_iterator i
= src_str
.begin();
1610 for ( ; i
!= src_str
.end(); i
++ )
1614 if ( a
!= wxS('\\') )
1616 if ( !prev_is_slash
)
1622 if ( a
== wxS('n') )
1625 dst_str
<< wxS('\n');
1627 dst_str
<< wxS('\n');
1630 else if ( a
== wxS('t') )
1631 dst_str
<< wxS('\t');
1635 prev_is_slash
= false;
1639 if ( prev_is_slash
)
1641 dst_str
<< wxS('\\');
1642 prev_is_slash
= false;
1646 prev_is_slash
= true;
1653 // -----------------------------------------------------------------------
1655 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1657 if ( src_str
.length() == 0 )
1663 wxString::const_iterator i
= src_str
.begin();
1664 wxUniChar prev_a
= wxS('\0');
1668 for ( ; i
!= src_str
.end(); i
++ )
1672 if ( a
>= wxS(' ') )
1674 // This surely is not something that requires an escape sequence.
1679 // This might need...
1680 if ( a
== wxS('\r') )
1682 // DOS style line end.
1683 // Already taken care below
1685 else if ( a
== wxS('\n') )
1686 // UNIX style line end.
1687 dst_str
<< wxS("\\n");
1688 else if ( a
== wxS('\t') )
1690 dst_str
<< wxS('\t');
1693 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1703 // -----------------------------------------------------------------------
1705 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1709 return (wxPGProperty
*) NULL
;
1712 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1715 // -----------------------------------------------------------------------
1716 // wxPropertyGrid graphics related methods
1717 // -----------------------------------------------------------------------
1719 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1723 // Update everything inside the box
1724 wxRect r
= GetUpdateRegion().GetBox();
1726 dc
.SetPen(m_colEmptySpace
);
1727 dc
.SetBrush(m_colEmptySpace
);
1728 dc
.DrawRectangle(r
);
1731 // -----------------------------------------------------------------------
1733 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1734 wxPGProperty
* property
) const
1736 // Prepare rectangle to be used
1738 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1739 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1741 #if (wxPG_USE_RENDERER_NATIVE)
1743 #elif wxPG_ICON_WIDTH
1744 // Drawing expand/collapse button manually
1745 dc
.SetPen(m_colPropFore
);
1746 if ( property
->IsCategory() )
1747 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1749 dc
.SetBrush(m_colPropBack
);
1751 dc
.DrawRectangle( r
);
1752 int _y
= r
.y
+(m_iconWidth
/2);
1753 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1758 if ( property
->IsExpanded() )
1760 // wxRenderer functions are non-mutating in nature, so it
1761 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1762 // Hopefully this does not cause problems.
1763 #if (wxPG_USE_RENDERER_NATIVE)
1764 wxRendererNative::Get().DrawTreeItemButton(
1770 #elif wxPG_ICON_WIDTH
1779 #if (wxPG_USE_RENDERER_NATIVE)
1780 wxRendererNative::Get().DrawTreeItemButton(
1786 #elif wxPG_ICON_WIDTH
1787 int _x
= r
.x
+(m_iconWidth
/2);
1788 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1794 #if (wxPG_USE_RENDERER_NATIVE)
1796 #elif wxPG_ICON_WIDTH
1799 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1803 // -----------------------------------------------------------------------
1806 // This is the one called by OnPaint event handler and others.
1807 // topy and bottomy are already unscrolled (ie. physical)
1809 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1811 unsigned int bottomy
,
1812 const wxRect
* clipRect
)
1814 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1816 m_pState
->EnsureVirtualHeight();
1818 wxRect tempClipRect
;
1821 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1822 clipRect
= &tempClipRect
;
1825 // items added check
1826 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1828 int paintFinishY
= 0;
1830 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1833 bool isBuffered
= false;
1835 #if wxPG_DOUBLE_BUFFER
1836 wxMemoryDC
* bufferDC
= NULL
;
1838 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1840 if ( !m_doubleBuffer
)
1842 paintFinishY
= clipRect
->y
;
1847 bufferDC
= new wxMemoryDC();
1849 // If nothing was changed, then just copy from double-buffer
1850 bufferDC
->SelectObject( *m_doubleBuffer
);
1860 dc
.SetClippingRegion( *clipRect
);
1861 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1864 #if wxPG_DOUBLE_BUFFER
1867 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1868 bufferDC
, 0, 0, wxCOPY
);
1869 dc
.DestroyClippingRegion(); // Is this really necessary?
1875 // Clear area beyond bottomY?
1876 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1878 dc
.SetPen(m_colEmptySpace
);
1879 dc
.SetBrush(m_colEmptySpace
);
1880 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1884 // -----------------------------------------------------------------------
1886 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1887 const wxPGProperty
* firstItem
,
1888 const wxPGProperty
* lastItem
,
1889 const wxRect
* clipRect
,
1890 bool isBuffered
) const
1892 // TODO: This should somehow be eliminated.
1893 wxRect tempClipRect
;
1896 wxASSERT(firstItem
);
1898 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1899 clipRect
= &tempClipRect
;
1903 firstItem
= DoGetItemAtY(clipRect
->y
);
1907 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1909 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1912 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1915 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1916 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1918 int lh
= m_lineHeight
;
1921 int lastItemBottomY
;
1923 firstItemTopY
= clipRect
->y
;
1924 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1926 // Align y coordinates to item boundaries
1927 firstItemTopY
-= firstItemTopY
% lh
;
1928 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1929 lastItemBottomY
-= 1;
1931 // Entire range outside scrolled, visible area?
1932 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1935 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1939 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1940 firstItem->GetLabel().c_str(),
1941 lastItem->GetLabel().c_str(),
1942 (int)(lastItemBottomY - firstItemTopY),
1944 (unsigned long)clipRect );
1949 long windowStyle
= m_windowStyle
;
1955 // With wxPG_DOUBLE_BUFFER, do double buffering
1956 // - buffer's y = 0, so align cliprect and coordinates to that
1958 #if wxPG_DOUBLE_BUFFER
1964 xRelMod
= clipRect
->x
;
1965 yRelMod
= clipRect
->y
;
1968 // clipRect conversion
1976 firstItemTopY
-= yRelMod
;
1977 lastItemBottomY
-= yRelMod
;
1980 wxUnusedVar(isBuffered
);
1983 int x
= m_marginWidth
- xRelMod
;
1985 const wxFont
& normalfont
= m_font
;
1987 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1989 bool isEnabled
= IsEnabled();
1992 // Prepare some pens and brushes that are often changed to.
1995 wxBrush
marginBrush(m_colMargin
);
1996 wxPen
marginPen(m_colMargin
);
1997 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1998 wxPen
linepen(m_colLine
,1,wxSOLID
);
2000 // pen that has same colour as text
2001 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2004 // Clear margin with background colour
2006 dc
.SetBrush( marginBrush
);
2007 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2009 dc
.SetPen( *wxTRANSPARENT_PEN
);
2010 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2013 const wxPGProperty
* selected
= m_selected
;
2014 const wxPropertyGridPageState
* state
= m_pState
;
2016 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2017 bool wasSelectedPainted
= false;
2020 // TODO: Only render columns that are within clipping region.
2022 dc
.SetFont(normalfont
);
2024 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2025 int endScanBottomY
= lastItemBottomY
+ lh
;
2026 int y
= firstItemTopY
;
2029 // Pregenerate list of visible properties.
2030 wxArrayPGProperty visPropArray
;
2031 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2033 for ( ; !it
.AtEnd(); it
.Next() )
2035 const wxPGProperty
* p
= *it
;
2037 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2039 visPropArray
.push_back((wxPGProperty
*)p
);
2041 if ( y
> endScanBottomY
)
2048 visPropArray
.push_back(NULL
);
2050 wxPGProperty
* nextP
= visPropArray
[0];
2052 int gridWidth
= state
->m_width
;
2055 for ( unsigned int arrInd
=1;
2056 nextP
&& y
<= lastItemBottomY
;
2059 wxPGProperty
* p
= nextP
;
2060 nextP
= visPropArray
[arrInd
];
2062 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2063 int textMarginHere
= x
;
2064 int renderFlags
= wxPGCellRenderer::Control
;
2066 int greyDepth
= m_marginWidth
;
2067 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2068 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2070 int greyDepthX
= greyDepth
- xRelMod
;
2072 // Use basic depth if in non-categoric mode and parent is base array.
2073 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2075 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2078 // Paint margin area
2079 dc
.SetBrush(marginBrush
);
2080 dc
.SetPen(marginPen
);
2081 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2083 dc
.SetPen( linepen
);
2088 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2094 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2096 sx
+= state
->m_colWidths
[si
];
2097 dc
.DrawLine( sx
, y
, sx
, y2
);
2100 // Horizontal Line, below
2101 // (not if both this and next is category caption)
2102 if ( p
->IsCategory() &&
2103 nextP
&& nextP
->IsCategory() )
2104 dc
.SetPen(m_colCapBack
);
2106 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2108 if ( p
== selected
)
2110 renderFlags
|= wxPGCellRenderer::Selected
;
2111 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2112 wasSelectedPainted
= true;
2120 if ( p
->IsCategory() )
2122 if ( p
->m_fgColIndex
== 0 )
2123 rowFgCol
= m_colCapFore
;
2125 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2126 rowBgBrush
= wxBrush(m_colCapBack
);
2128 else if ( p
!= selected
)
2130 // Disabled may get different colour.
2131 if ( !p
->IsEnabled() )
2132 rowFgCol
= m_colDisPropFore
;
2134 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2136 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2140 // Selected gets different colour.
2141 if ( reallyFocused
)
2143 rowFgCol
= m_colSelFore
;
2144 rowBgBrush
= wxBrush(m_colSelBack
);
2146 else if ( isEnabled
)
2148 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2149 rowBgBrush
= marginBrush
;
2153 rowFgCol
= m_colDisPropFore
;
2154 rowBgBrush
= wxBrush(m_colSelBack
);
2158 bool fontChanged
= false;
2160 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2165 if ( p
->IsCategory() )
2167 // Captions are all cells merged as one
2168 dc
.SetFont(m_captionFont
);
2170 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2172 dc
.SetBrush(rowBgBrush
);
2173 dc
.SetPen(rowBgBrush
.GetColour());
2174 dc
.SetTextForeground(rowFgCol
);
2176 dc
.DrawRectangle(cellRect
);
2179 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2180 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2183 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2184 DrawExpanderButton( dc
, butRect
, p
);
2188 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2190 dc
.SetFont(m_captionFont
);
2196 int nextCellWidth
= state
->m_colWidths
[0];
2197 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2198 int textXAdd
= textMarginHere
- greyDepthX
;
2200 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2202 cellRect
.width
= nextCellWidth
- 1;
2204 bool ctrlCell
= false;
2207 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2209 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2210 dc
.SetBrush(editorBgCol
);
2211 dc
.SetPen(editorBgCol
);
2212 dc
.SetTextForeground(m_colPropFore
);
2214 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2219 dc
.SetBrush(rowBgBrush
);
2220 dc
.SetPen(rowBgBrush
.GetColour());
2221 dc
.SetTextForeground(rowFgCol
);
2224 dc
.DrawRectangle(cellRect
);
2227 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2228 DrawExpanderButton( dc
, butRect
, p
);
2230 dc
.SetClippingRegion(cellRect
);
2232 cellRect
.x
+= textXAdd
;
2233 cellRect
.width
-= textXAdd
;
2238 wxPGCellRenderer
* renderer
;
2239 int cmnVal
= p
->GetCommonValue();
2240 if ( cmnVal
== -1 || ci
!= 1 )
2242 renderer
= p
->GetCellRenderer(ci
);
2243 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2247 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2248 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2252 cellX
+= state
->m_colWidths
[ci
];
2253 if ( ci
< (state
->m_colWidths
.size()-1) )
2254 nextCellWidth
= state
->m_colWidths
[ci
+1];
2256 dc
.DestroyClippingRegion(); // Is this really necessary?
2262 dc
.SetFont(normalfont
);
2267 // Refresh editor controls (seems not needed on msw)
2268 // NOTE: This code is mandatory for GTK!
2269 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2270 if ( wasSelectedPainted
)
2273 m_wndEditor
->Refresh();
2275 m_wndEditor2
->Refresh();
2282 // -----------------------------------------------------------------------
2284 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2288 if ( m_width
< 10 || m_height
< 10 ||
2289 !m_pState
->m_properties
->GetChildCount() ||
2290 p1
== (wxPGProperty
*) NULL
)
2291 return wxRect(0,0,0,0);
2296 // Return rect which encloses the given property range
2298 int visTop
= p1
->GetY();
2301 visBottom
= p2
->GetY() + m_lineHeight
;
2303 visBottom
= m_height
+ visTop
;
2305 // If seleced property is inside the range, we'll extend the range to include
2307 wxPGProperty
* selected
= m_selected
;
2310 int selectedY
= selected
->GetY();
2311 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2313 wxWindow
* editor
= GetEditorControl();
2316 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2317 if ( visBottom2
> visBottom
)
2318 visBottom
= visBottom2
;
2323 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2326 // -----------------------------------------------------------------------
2328 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2333 if ( m_pState
->m_itemsAdded
)
2334 PrepareAfterItemsAdded();
2336 wxRect r
= GetPropertyRect(p1
, p2
);
2339 m_canvas
->RefreshRect(r
);
2343 // -----------------------------------------------------------------------
2345 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2347 if ( p
== m_selected
)
2348 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2350 DrawItemAndChildren(p
);
2353 // -----------------------------------------------------------------------
2355 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2360 // Draw item, children, and parent too, if it is not category
2361 wxPGProperty
* parent
= p
->GetParent();
2364 !parent
->IsCategory() &&
2365 parent
->GetParent() )
2368 parent
= parent
->GetParent();
2371 DrawItemAndChildren(p
);
2374 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2376 wxCHECK_RET( p
, wxT("invalid property id") );
2378 // Do not draw if in non-visible page
2379 if ( p
->GetParentState() != m_pState
)
2382 // do not draw a single item if multiple pending
2383 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2386 wxWindow
* wndPrimary
= GetEditorControl();
2388 // Update child control.
2389 if ( m_selected
&& m_selected
->GetParent() == p
)
2390 m_selected
->UpdateControl(wndPrimary
);
2392 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2394 DrawItems(p
, lastDrawn
);
2397 // -----------------------------------------------------------------------
2399 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2400 const wxRect
*rect
)
2402 PrepareAfterItemsAdded();
2404 wxWindow::Refresh(false);
2406 // TODO: Coordinate translation
2407 m_canvas
->Refresh(false, rect
);
2409 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2410 // I think this really helps only GTK+1.2
2411 if ( m_wndEditor
) m_wndEditor
->Refresh();
2412 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2416 // -----------------------------------------------------------------------
2417 // wxPropertyGrid global operations
2418 // -----------------------------------------------------------------------
2420 void wxPropertyGrid::Clear()
2424 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2425 wxPG_CHECK_RET_DBG( selRes
,
2426 wxT("failed to deselect a property (editor probably had invalid value)") );
2429 m_pState
->DoClear();
2435 RecalculateVirtualSize();
2437 // Need to clear some area at the end
2439 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2442 // -----------------------------------------------------------------------
2444 bool wxPropertyGrid::EnableCategories( bool enable
)
2446 if ( !ClearSelection() )
2452 // Enable categories
2455 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2460 // Disable categories
2462 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2465 if ( !m_pState
->EnableCategories(enable
) )
2470 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2472 m_pState
->m_itemsAdded
= 1; // force
2473 PrepareAfterItemsAdded();
2477 m_pState
->m_itemsAdded
= 1;
2479 // No need for RecalculateVirtualSize() here - it is already called in
2480 // wxPropertyGridPageState method above.
2487 // -----------------------------------------------------------------------
2489 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2491 wxASSERT( pNewState
);
2492 wxASSERT( pNewState
->GetGrid() );
2494 if ( pNewState
== m_pState
)
2497 wxPGProperty
* oldSelection
= m_selected
;
2502 bool selRes
= ClearSelection();
2503 wxPG_CHECK_RET_DBG( selRes
,
2504 wxT("failed to deselect a property (editor probably had invalid value)") );
2507 m_pState
->m_selected
= oldSelection
;
2509 bool orig_mode
= m_pState
->IsInNonCatMode();
2510 bool new_state_mode
= pNewState
->IsInNonCatMode();
2512 m_pState
= pNewState
;
2515 int pgWidth
= GetClientSize().x
;
2516 if ( HasVirtualWidth() )
2518 int minWidth
= pgWidth
;
2519 if ( pNewState
->m_width
< minWidth
)
2521 pNewState
->m_width
= minWidth
;
2522 pNewState
->CheckColumnWidths();
2528 // Just in case, fully re-center splitter
2529 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2530 pNewState
->m_fSplitterX
= -1.0;
2532 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2535 m_propHover
= (wxPGProperty
*) NULL
;
2537 // If necessary, convert state to correct mode.
2538 if ( orig_mode
!= new_state_mode
)
2540 // This should refresh as well.
2541 EnableCategories( orig_mode
?false:true );
2543 else if ( !m_frozen
)
2545 // Refresh, if not frozen.
2546 if ( m_pState
->m_itemsAdded
)
2547 PrepareAfterItemsAdded();
2550 if ( m_pState
->m_selected
)
2551 DoSelectProperty( m_pState
->m_selected
);
2553 RecalculateVirtualSize(0);
2557 m_pState
->m_itemsAdded
= 1;
2560 // -----------------------------------------------------------------------
2562 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2564 wxPG_PROP_ARG_CALL_PROLOG()
2566 m_pState
->SortChildren( p
);
2569 // -----------------------------------------------------------------------
2571 void wxPropertyGrid::Sort()
2573 bool selRes
= ClearSelection(); // This must be before state clear
2574 wxPG_CHECK_RET_DBG( selRes
,
2575 wxT("failed to deselect a property (editor probably had invalid value)") );
2580 // -----------------------------------------------------------------------
2582 // Call to SetSplitterPosition will always disable splitter auto-centering
2583 // if parent window is shown.
2584 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2586 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2589 wxPropertyGridPageState
* state
= m_pState
;
2591 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2596 CorrectEditorWidgetSizeX();
2602 // -----------------------------------------------------------------------
2604 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2606 SetSplitterPosition( m_width
/2, true );
2607 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2608 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2611 // -----------------------------------------------------------------------
2612 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2613 // -----------------------------------------------------------------------
2615 // Returns nearest paint visible property (such that will be painted unless
2616 // window is scrolled or resized). If given property is paint visible, then
2617 // it itself will be returned
2618 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2620 int vx
,vy1
;// Top left corner of client
2621 GetViewStart(&vx
,&vy1
);
2622 vy1
*= wxPG_PIXELS_PER_UNIT
;
2624 int vy2
= vy1
+ m_height
;
2625 int propY
= p
->GetY2(m_lineHeight
);
2627 if ( (propY
+ m_lineHeight
) < vy1
)
2630 return DoGetItemAtY( vy1
);
2632 else if ( propY
> vy2
)
2635 return DoGetItemAtY( vy2
);
2638 // Itself paint visible
2643 // -----------------------------------------------------------------------
2645 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2649 m_pushButKeyCode
= keycode
;
2650 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2651 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2655 m_pushButKeyCode
= WXK_DOWN
;
2656 m_pushButKeyCodeNeedsCtrl
= 0;
2657 m_pushButKeyCodeNeedsAlt
= 1;
2661 // -----------------------------------------------------------------------
2662 // Methods related to change in value, value modification and sending events
2663 // -----------------------------------------------------------------------
2665 // commits any changes in editor of selected property
2666 // return true if validation did not fail
2667 // flags are same as with DoSelectProperty
2668 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2670 // Committing already?
2671 if ( m_inCommitChangesFromEditor
)
2674 // Don't do this if already processing editor event. It might
2675 // induce recursive dialogs and crap like that.
2676 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2678 if ( m_inDoPropertyChanged
)
2685 IsEditorsValueModified() &&
2686 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2689 m_inCommitChangesFromEditor
= 1;
2691 wxVariant
variant(m_selected
->GetValueRef());
2692 bool valueIsPending
= false;
2694 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2695 // due to another window getting focus
2696 wxWindow
* oldFocus
= m_curFocused
;
2698 bool validationFailure
= false;
2699 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2701 m_chgInfo_changedProperty
= NULL
;
2703 // If truly modified, schedule value as pending.
2704 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2706 if ( DoEditorValidate() &&
2707 PerformValidation(m_selected
, variant
) )
2709 valueIsPending
= true;
2713 validationFailure
= true;
2718 EditorsValueWasNotModified();
2723 m_inCommitChangesFromEditor
= 0;
2725 if ( validationFailure
&& !forceSuccess
)
2729 oldFocus
->SetFocus();
2730 m_curFocused
= oldFocus
;
2733 res
= OnValidationFailure(m_selected
, variant
);
2735 // Now prevent further validation failure messages
2738 EditorsValueWasNotModified();
2739 OnValidationFailureReset(m_selected
);
2742 else if ( valueIsPending
)
2744 DoPropertyChanged( m_selected
, flags
);
2745 EditorsValueWasNotModified();
2754 // -----------------------------------------------------------------------
2756 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2759 // Runs all validation functionality.
2760 // Returns true if value passes all tests.
2763 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2765 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2767 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2772 // Adapt list to child values, if necessary
2773 wxVariant listValue
= pendingValue
;
2774 wxVariant
* pPendingValue
= &pendingValue
;
2775 wxVariant
* pList
= NULL
;
2777 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2778 // string value, then we need treat as it was changed instead
2779 // (or, in addition, as is the case with composite string parent).
2780 // This includes creating list variant for child values.
2782 wxPGProperty
* pwc
= p
->GetParent();
2783 wxPGProperty
* changedProperty
= p
;
2784 wxPGProperty
* baseChangedProperty
= changedProperty
;
2785 wxVariant bcpPendingList
;
2787 listValue
= pendingValue
;
2788 listValue
.SetName(p
->GetBaseName());
2791 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2793 wxVariantList tempList
;
2794 wxVariant
lv(tempList
, pwc
->GetBaseName());
2795 lv
.Append(listValue
);
2797 pPendingValue
= &listValue
;
2799 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2801 baseChangedProperty
= pwc
;
2802 bcpPendingList
= lv
;
2805 changedProperty
= pwc
;
2806 pwc
= pwc
->GetParent();
2810 wxPGProperty
* evtChangingProperty
= changedProperty
;
2812 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2814 value
= *pPendingValue
;
2818 // Convert list to child values
2819 pList
= pPendingValue
;
2820 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2823 wxVariant evtChangingValue
= value
;
2825 // FIXME: After proper ValueToString()s added, remove
2826 // this. It is just a temporary fix, as evt_changing
2827 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2828 // (unless it is selected, and textctrl editor is open).
2829 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2831 evtChangingProperty
= baseChangedProperty
;
2832 if ( evtChangingProperty
!= p
)
2834 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2838 evtChangingValue
= pendingValue
;
2842 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2844 if ( changedProperty
== m_selected
)
2846 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2847 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2851 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2855 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2856 m_chgInfo_changedProperty
= changedProperty
;
2857 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2858 m_chgInfo_pendingValue
= value
;
2861 m_chgInfo_valueList
= *pList
;
2863 m_chgInfo_valueList
.MakeNull();
2865 // If changedProperty is not property which value was edited,
2866 // then call wxPGProperty::ValidateValue() for that as well.
2867 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2869 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2873 // SendEvent returns true if event was vetoed
2874 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2880 // -----------------------------------------------------------------------
2882 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2884 if ( !msg
.length() )
2888 if ( !wxPGGlobalVars
->m_offline
)
2890 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2893 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2896 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2899 pStatusBar
->SetStatusText(msg
);
2907 ::wxMessageBox(msg
, _T("Property Error"));
2910 // -----------------------------------------------------------------------
2912 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2914 int vfb
= m_validationInfo
.m_failureBehavior
;
2916 if ( vfb
& wxPG_VFB_BEEP
)
2919 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2920 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2922 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2923 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2925 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2927 wxColour vfbFg
= *wxWHITE
;
2928 wxColour vfbBg
= *wxRED
;
2929 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2930 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2932 DrawItemAndChildren(property
);
2934 if ( property
== m_selected
)
2936 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2938 wxWindow
* editor
= GetEditorControl();
2941 editor
->SetForegroundColour(vfbFg
);
2942 editor
->SetBackgroundColour(vfbBg
);
2948 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2950 wxString msg
= m_validationInfo
.m_failureMessage
;
2952 if ( !msg
.length() )
2953 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2955 DoShowPropertyError(property
, msg
);
2958 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2961 // -----------------------------------------------------------------------
2963 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2965 int vfb
= m_validationInfo
.m_failureBehavior
;
2967 if ( vfb
& wxPG_VFB_MARK_CELL
)
2969 property
->SetCell(0, NULL
);
2970 property
->SetCell(1, NULL
);
2972 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2974 if ( property
== m_selected
&& GetEditorControl() )
2976 // Calling this will recreate the control, thus resetting its colour
2977 RefreshProperty(property
);
2981 DrawItemAndChildren(property
);
2986 // -----------------------------------------------------------------------
2988 // flags are same as with DoSelectProperty
2989 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2991 if ( m_inDoPropertyChanged
)
2994 wxWindow
* editor
= GetEditorControl();
2996 m_pState
->m_anyModified
= 1;
2998 m_inDoPropertyChanged
= 1;
3000 // Maybe need to update control
3001 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3003 // These values were calculated in PerformValidation()
3004 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3005 wxVariant value
= m_chgInfo_pendingValue
;
3007 wxPGProperty
* topPaintedProperty
= changedProperty
;
3009 while ( !topPaintedProperty
->IsCategory() &&
3010 !topPaintedProperty
->IsRoot() )
3012 topPaintedProperty
= topPaintedProperty
->GetParent();
3015 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3017 // Set as Modified (not if dragging just began)
3018 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3020 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3021 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3024 SetCurControlBoldFont();
3030 // Propagate updates to parent(s)
3032 wxPGProperty
* prevPwc
= NULL
;
3034 while ( prevPwc
!= topPaintedProperty
)
3036 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3038 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3041 SetCurControlBoldFont();
3045 pwc
= pwc
->GetParent();
3048 // Draw the actual property
3049 DrawItemAndChildren( topPaintedProperty
);
3052 // If value was set by wxPGProperty::OnEvent, then update the editor
3054 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3057 p
->GetEditorClass()->UpdateControl(p
, editor
);
3061 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3062 if ( m_wndEditor
) m_wndEditor
->Refresh();
3063 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3068 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3070 // If top parent has composite string value, then send to child parents,
3071 // starting from baseChangedProperty.
3072 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3074 pwc
= m_chgInfo_baseChangedProperty
;
3076 while ( pwc
!= changedProperty
)
3078 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3079 pwc
= pwc
->GetParent();
3083 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3085 m_inDoPropertyChanged
= 0;
3090 // -----------------------------------------------------------------------
3092 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3094 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3096 m_chgInfo_changedProperty
= NULL
;
3098 if ( PerformValidation(p
, newValue
) )
3100 DoPropertyChanged(p
);
3105 OnValidationFailure(p
, newValue
);
3111 // -----------------------------------------------------------------------
3113 // Runs wxValidator for the selected property
3114 bool wxPropertyGrid::DoEditorValidate()
3119 // -----------------------------------------------------------------------
3121 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3123 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3124 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3126 wxWindow
* parent
= wnd
->GetParent();
3129 (parent
== m_canvas
||
3130 parent
->GetParent() == m_canvas
) )
3132 OnCustomEditorEvent((wxCommandEvent
&)event
);
3136 return wxPanel::ProcessEvent(event
);
3139 // -----------------------------------------------------------------------
3141 // NB: It may really not be wxCommandEvent - must check if necessary
3143 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3145 wxPGProperty
* selected
= m_selected
;
3148 // Somehow, event is handled after property has been deselected.
3149 // Possibly, but very rare.
3153 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3156 wxVariant
pendingValue(selected
->GetValueRef());
3157 wxWindow
* wnd
= GetEditorControl();
3159 bool wasUnspecified
= selected
->IsValueUnspecified();
3160 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3162 bool valueIsPending
= false;
3164 m_chgInfo_changedProperty
= NULL
;
3166 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3169 // Filter out excess wxTextCtrl modified events
3170 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3172 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3174 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3176 wxString newTcValue
= tc
->GetValue();
3177 if ( m_prevTcValue
== newTcValue
)
3180 m_prevTcValue
= newTcValue
;
3183 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3185 bool validationFailure
= false;
3186 bool buttonWasHandled
= false;
3189 // Try common button handling
3190 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3192 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3196 buttonWasHandled
= true;
3197 // Store as res2, as previously (and still currently alternatively)
3198 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3199 // in wxPGProperty::OnEvent().
3200 adapter
->ShowDialog( this, selected
);
3205 if ( !buttonWasHandled
)
3209 // First call editor class' event handler.
3210 const wxPGEditor
* editor
= selected
->GetEditorClass();
3212 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3214 // If changes, validate them
3215 if ( DoEditorValidate() )
3217 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3218 valueIsPending
= true;
3222 validationFailure
= true;
3227 // Then the property's custom handler (must be always called, unless
3228 // validation failed).
3229 if ( !validationFailure
)
3230 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3233 // SetValueInEvent(), as called in one of the functions referred above
3234 // overrides editor's value.
3235 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3237 valueIsPending
= true;
3238 pendingValue
= m_changeInEventValue
;
3239 selFlags
|= wxPG_SEL_DIALOGVAL
;
3242 if ( !validationFailure
&& valueIsPending
)
3243 if ( !PerformValidation(m_selected
, pendingValue
) )
3244 validationFailure
= true;
3246 if ( validationFailure
)
3248 OnValidationFailure(selected
, pendingValue
);
3250 else if ( valueIsPending
)
3252 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3254 DoPropertyChanged(selected
, selFlags
);
3255 EditorsValueWasNotModified();
3259 // No value after all
3261 // Let unhandled button click events go to the parent
3262 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3264 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3265 GetEventHandler()->AddPendingEvent(evt
);
3269 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3272 // -----------------------------------------------------------------------
3273 // wxPropertyGrid editor control helper methods
3274 // -----------------------------------------------------------------------
3276 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3278 int itemy
= p
->GetY2(m_lineHeight
);
3280 int cust_img_space
= 0;
3281 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3282 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3284 // TODO: If custom image detection changes from current, change this.
3285 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3287 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3288 int imwid
= p
->OnMeasureImage().x
;
3289 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3290 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3295 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3297 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3302 // -----------------------------------------------------------------------
3304 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3306 wxSize sz
= GetImageSize(p
, item
);
3307 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3308 wxPG_CUSTOM_IMAGE_SPACINGY
,
3313 // return size of custom paint image
3314 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3316 // If called with NULL property, then return default image
3317 // size for properties that use image.
3319 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3321 wxSize cis
= p
->OnMeasureImage(item
);
3323 int choiceCount
= p
->m_choices
.GetCount();
3324 int comVals
= p
->GetDisplayedCommonValueCount();
3325 if ( item
>= choiceCount
&& comVals
> 0 )
3327 unsigned int cvi
= item
-choiceCount
;
3328 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3330 else if ( item
>= 0 && choiceCount
== 0 )
3331 return wxSize(0, 0);
3336 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3341 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3348 // -----------------------------------------------------------------------
3350 // takes scrolling into account
3351 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3354 GetViewStart(&vx
,&vy
);
3355 vy
*=wxPG_PIXELS_PER_UNIT
;
3356 vx
*=wxPG_PIXELS_PER_UNIT
;
3359 ClientToScreen( px
, py
);
3362 // -----------------------------------------------------------------------
3364 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3367 GetViewStart(&pt2
.x
,&pt2
.y
);
3368 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3369 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3373 return m_pState
->HitTest(pt2
);
3376 // -----------------------------------------------------------------------
3378 // custom set cursor
3379 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3381 if ( type
== m_curcursor
&& !override
) return;
3383 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3385 if ( type
== wxCURSOR_SIZEWE
)
3386 cursor
= m_cursorSizeWE
;
3388 m_canvas
->SetCursor( *cursor
);
3393 // -----------------------------------------------------------------------
3394 // wxPropertyGrid property selection
3395 // -----------------------------------------------------------------------
3397 // Setups event handling for child control
3398 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
, int id
)
3400 if ( argWnd
== m_wndEditor
)
3402 this->Connect(id
, wxEVT_MOTION
,
3403 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
));
3404 this->Connect(id
, wxEVT_LEFT_UP
,
3405 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
));
3406 this->Connect(id
, wxEVT_LEFT_DOWN
,
3407 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
));
3408 this->Connect(id
, wxEVT_RIGHT_UP
,
3409 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
));
3410 this->Connect(id
, wxEVT_ENTER_WINDOW
,
3411 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3412 this->Connect(id
, wxEVT_LEAVE_WINDOW
,
3413 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3417 this->Connect(id
, wxEVT_NAVIGATION_KEY
,
3418 wxNavigationKeyEventHandler(wxPropertyGrid::OnNavigationKey
));
3421 this->Connect(id
, wxEVT_KEY_DOWN
,
3422 wxKeyEventHandler(wxPropertyGrid::OnChildKeyDown
));
3423 this->Connect(id
, wxEVT_KEY_UP
,
3424 wxKeyEventHandler(wxPropertyGrid::OnChildKeyUp
));
3425 this->Connect(id
, wxEVT_KILL_FOCUS
,
3426 wxFocusEventHandler(wxPropertyGrid::OnFocusEvent
));
3429 void wxPropertyGrid::FreeEditors()
3431 // Do not free editors immediately if processing events
3432 if ( !m_windowsToDelete
)
3433 m_windowsToDelete
= new wxArrayPtrVoid
;
3437 m_windowsToDelete
->push_back(m_wndEditor2
);
3438 m_wndEditor2
->Hide();
3439 m_wndEditor2
= (wxWindow
*) NULL
;
3444 m_windowsToDelete
->push_back(m_wndEditor
);
3445 m_wndEditor
->Hide();
3446 m_wndEditor
= (wxWindow
*) NULL
;
3450 // Call with NULL to de-select property
3451 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3453 wxPanel
* canvas
= GetPanel();
3457 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3458 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3460 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3463 if ( m_inDoSelectProperty
)
3466 m_inDoSelectProperty
= 1;
3468 wxPGProperty
* prev
= m_selected
;
3471 // Delete windows pending for deletion
3472 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3476 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3477 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3479 m_windowsToDelete
->clear();
3484 m_inDoSelectProperty
= 0;
3489 // If we are frozen, then just set the values.
3492 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3493 m_editorFocused
= 0;
3496 m_pState
->m_selected
= p
;
3498 // If frozen, always free controls. But don't worry, as Thaw will
3499 // recall SelectProperty to recreate them.
3502 // Prevent any further selection measures in this call
3503 p
= (wxPGProperty
*) NULL
;
3508 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3510 // Only set focus if not deselecting
3513 if ( flags
& wxPG_SEL_FOCUS
)
3517 m_wndEditor
->SetFocus();
3518 m_editorFocused
= 1;
3527 m_inDoSelectProperty
= 0;
3532 // First, deactivate previous
3536 OnValidationFailureReset(m_selected
);
3538 // Must double-check if this is an selected in case of forceswitch
3541 if ( !CommitChangesFromEditor(flags
) )
3543 // Validation has failed, so we can't exit the previous editor
3544 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3545 // _("Invalid Value"),wxOK|wxICON_ERROR);
3546 m_inDoSelectProperty
= 0;
3554 m_selected
= (wxPGProperty
*) NULL
;
3555 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3557 // We need to always fully refresh the grid here
3560 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3561 EditorsValueWasNotModified();
3564 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3567 // Then, activate the one given.
3570 int propY
= p
->GetY2(m_lineHeight
);
3572 int splitterX
= GetSplitterPosition();
3573 m_editorFocused
= 0;
3575 m_pState
->m_selected
= p
;
3576 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3578 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3580 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3582 // Do we need OnMeasureCalls?
3583 wxSize imsz
= p
->OnMeasureImage();
3586 // Only create editor for non-disabled non-caption
3587 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3589 // do this for non-caption items
3593 // Do we need to paint the custom image, if any?
3594 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3595 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3596 !p
->GetEditorClass()->CanContainCustomImage()
3598 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3600 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3601 wxPoint goodPos
= grect
.GetPosition();
3602 #if wxPG_CREATE_CONTROLS_HIDDEN
3603 int coord_adjust
= m_height
- goodPos
.y
;
3604 goodPos
.y
+= coord_adjust
;
3607 const wxPGEditor
* editor
= p
->GetEditorClass();
3608 wxCHECK_MSG(editor
, false,
3609 wxT("NULL editor class not allowed"));
3611 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3613 wxPGWindowList wndList
= editor
->CreateControls(this,
3618 m_wndEditor
= wndList
.m_primary
;
3619 m_wndEditor2
= wndList
.m_secondary
;
3621 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3622 // value is drawn as normal, and m_wndEditor2 is assumed
3623 // to be a right-aligned button that triggers a separate editor
3628 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3629 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3631 // Set validator, if any
3632 #if wxUSE_VALIDATORS
3633 wxValidator
* validator
= p
->GetValidator();
3635 m_wndEditor
->SetValidator(*validator
);
3638 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3639 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3641 // If it has modified status, use bold font
3642 // (must be done before capturing m_ctrlXAdjust)
3643 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3644 SetCurControlBoldFont();
3647 // Fix TextCtrl indentation
3648 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3649 wxTextCtrl
* tc
= NULL
;
3650 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3651 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3653 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3655 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3658 // Store x relative to splitter (we'll need it).
3659 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3661 // Check if background clear is not necessary
3662 wxPoint pos
= m_wndEditor
->GetPosition();
3663 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3665 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3668 m_wndEditor
->SetSizeHints(3, 3);
3670 #if wxPG_CREATE_CONTROLS_HIDDEN
3671 m_wndEditor
->Show(false);
3672 m_wndEditor
->Freeze();
3674 goodPos
= m_wndEditor
->GetPosition();
3675 goodPos
.y
-= coord_adjust
;
3676 m_wndEditor
->Move( goodPos
);
3679 wxWindow
* primaryCtrl
= GetEditorControl();
3680 SetupChildEventHandling(primaryCtrl
, wxPG_SUBID1
);
3682 // Focus and select all (wxTextCtrl, wxComboBox etc)
3683 if ( flags
& wxPG_SEL_FOCUS
)
3685 primaryCtrl
->SetFocus();
3687 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3693 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3694 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3696 // Get proper id for wndSecondary
3697 m_wndSecId
= m_wndEditor2
->GetId();
3698 wxWindowList children
= m_wndEditor2
->GetChildren();
3699 wxWindowList::iterator node
= children
.begin();
3700 if ( node
!= children
.end() )
3701 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3703 m_wndEditor2
->SetSizeHints(3,3);
3705 #if wxPG_CREATE_CONTROLS_HIDDEN
3706 wxRect sec_rect
= m_wndEditor2
->GetRect();
3707 sec_rect
.y
-= coord_adjust
;
3709 // Fine tuning required to fix "oversized"
3710 // button disappearance bug.
3711 if ( sec_rect
.y
< 0 )
3713 sec_rect
.height
+= sec_rect
.y
;
3716 m_wndEditor2
->SetSize( sec_rect
);
3718 m_wndEditor2
->Show();
3720 SetupChildEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3722 // If no primary editor, focus to button to allow
3723 // it to interprete ENTER etc.
3724 // NOTE: Due to problems focusing away from it, this
3725 // has been disabled.
3727 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3728 m_wndEditor2->SetFocus();
3732 if ( flags
& wxPG_SEL_FOCUS
)
3733 m_editorFocused
= 1;
3738 // Make sure focus is in grid canvas (important for wxGTK, at least)
3742 EditorsValueWasNotModified();
3744 // If it's inside collapsed section, expand parent, scroll, etc.
3745 // Also, if it was partially visible, scroll it into view.
3746 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3751 #if wxPG_CREATE_CONTROLS_HIDDEN
3752 m_wndEditor
->Thaw();
3754 m_wndEditor
->Show(true);
3761 // Make sure focus is in grid canvas
3765 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3771 // Show help text in status bar.
3772 // (if found and grid not embedded in manager with help box and
3773 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3776 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3778 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3779 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3781 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3783 statusbar
= frame
->GetStatusBar();
3788 const wxString
* pHelpString
= (const wxString
*) NULL
;
3792 pHelpString
= &p
->GetHelpString();
3793 if ( pHelpString
->length() )
3795 // Set help box text.
3796 statusbar
->SetStatusText( *pHelpString
);
3797 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3801 if ( (!pHelpString
|| !pHelpString
->length()) &&
3802 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3804 // Clear help box - but only if it was written
3805 // by us at previous time.
3806 statusbar
->SetStatusText( m_emptyString
);
3807 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3813 m_inDoSelectProperty
= 0;
3815 // call wx event handler (here so that it also occurs on deselection)
3816 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3821 // -----------------------------------------------------------------------
3823 bool wxPropertyGrid::UnfocusEditor()
3825 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3828 if ( !CommitChangesFromEditor(0) )
3832 DrawItem(m_selected
);
3837 // -----------------------------------------------------------------------
3839 // This method is not inline because it called dozens of times
3840 // (i.e. two-arg function calls create smaller code size).
3841 bool wxPropertyGrid::DoClearSelection()
3843 return DoSelectProperty((wxPGProperty
*)NULL
);
3846 // -----------------------------------------------------------------------
3847 // wxPropertyGrid expand/collapse state
3848 // -----------------------------------------------------------------------
3850 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3852 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3854 // If active editor was inside collapsed section, then disable it
3855 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3857 if ( !ClearSelection() )
3861 // Store dont-center-splitter flag 'cause we need to temporarily set it
3862 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3863 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3865 bool res
= m_pState
->DoCollapse(pwc
);
3870 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3872 RecalculateVirtualSize();
3874 // Redraw etc. only if collapsed was visible.
3875 if (pwc
->IsVisible() &&
3877 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3879 // When item is collapsed so that scrollbar would move,
3880 // graphics mess is about (unless we redraw everything).
3885 // Clear dont-center-splitter flag if it wasn't set
3886 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3891 // -----------------------------------------------------------------------
3893 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3895 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3897 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3899 // Store dont-center-splitter flag 'cause we need to temporarily set it
3900 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3901 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3903 bool res
= m_pState
->DoExpand(pwc
);
3908 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3910 RecalculateVirtualSize();
3912 // Redraw etc. only if expanded was visible.
3913 if ( pwc
->IsVisible() && !m_frozen
&&
3914 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3918 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3921 DrawItems(pwc
, NULL
);
3926 // Clear dont-center-splitter flag if it wasn't set
3927 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3932 // -----------------------------------------------------------------------
3934 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3937 return m_pState
->DoHideProperty(p
, hide
, flags
);
3940 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3943 if ( !ClearSelection() )
3947 m_pState
->DoHideProperty(p
, hide
, flags
);
3949 RecalculateVirtualSize();
3956 // -----------------------------------------------------------------------
3957 // wxPropertyGrid size related methods
3958 // -----------------------------------------------------------------------
3960 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3962 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3966 // If virtual height was changed, then recalculate editor control position(s)
3967 if ( m_pState
->m_vhCalcPending
)
3968 CorrectEditorWidgetPosY();
3970 m_pState
->EnsureVirtualHeight();
3973 int by1
= m_pState
->GetVirtualHeight();
3974 int by2
= m_pState
->GetActualVirtualHeight();
3977 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3978 wxASSERT_MSG( false,
3984 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3986 int x
= m_pState
->m_width
;
3987 int y
= m_pState
->m_virtualHeight
;
3990 GetClientSize(&width
,&height
);
3992 // Now adjust virtual size.
3993 SetVirtualSize(x
, y
);
3999 // Adjust scrollbars
4000 if ( HasVirtualWidth() )
4002 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4003 xPos
= GetScrollPos( wxHORIZONTAL
);
4006 if ( forceXPos
!= -1 )
4009 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4012 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4013 int yPos
= GetScrollPos( wxVERTICAL
);
4015 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4016 xAmount
, yAmount
, xPos
, yPos
, true );
4018 // Must re-get size now
4019 GetClientSize(&width
,&height
);
4021 if ( !HasVirtualWidth() )
4023 m_pState
->SetVirtualWidth(width
);
4030 m_canvas
->SetSize( x
, y
);
4032 m_pState
->CheckColumnWidths();
4035 CorrectEditorWidgetSizeX();
4037 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4040 // -----------------------------------------------------------------------
4042 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4044 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4048 GetClientSize(&width
,&height
);
4053 #if wxPG_DOUBLE_BUFFER
4054 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4056 int dblh
= (m_lineHeight
*2);
4057 if ( !m_doubleBuffer
)
4059 // Create double buffer bitmap to draw on, if none
4060 int w
= (width
>250)?width
:250;
4061 int h
= height
+ dblh
;
4063 m_doubleBuffer
= new wxBitmap( w
, h
);
4067 int w
= m_doubleBuffer
->GetWidth();
4068 int h
= m_doubleBuffer
->GetHeight();
4070 // Double buffer must be large enough
4071 if ( w
< width
|| h
< (height
+dblh
) )
4073 if ( w
< width
) w
= width
;
4074 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4075 delete m_doubleBuffer
;
4076 m_doubleBuffer
= new wxBitmap( w
, h
);
4083 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4084 m_ncWidth
= event
.GetSize().x
;
4088 if ( m_pState
->m_itemsAdded
)
4089 PrepareAfterItemsAdded();
4091 // Without this, virtual size (atleast under wxGTK) will be skewed
4092 RecalculateVirtualSize();
4098 // -----------------------------------------------------------------------
4100 void wxPropertyGrid::SetVirtualWidth( int width
)
4104 // Disable virtual width
4105 width
= GetClientSize().x
;
4106 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4110 // Enable virtual width
4111 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4113 m_pState
->SetVirtualWidth( width
);
4116 void wxPropertyGrid::SetFocusOnCanvas()
4118 m_canvas
->SetFocusIgnoringChildren();
4119 m_editorFocused
= 0;
4122 // -----------------------------------------------------------------------
4123 // wxPropertyGrid mouse event handling
4124 // -----------------------------------------------------------------------
4126 // selFlags uses same values DoSelectProperty's flags
4127 // Returns true if event was vetoed.
4128 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4130 // Send property grid event of specific type and with specific property
4131 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4132 evt
.SetPropertyGrid(this);
4133 evt
.SetEventObject(m_eventObject
);
4137 evt
.SetCanVeto(true);
4138 evt
.SetupValidationInfo();
4139 m_validationInfo
.m_pValue
= pValue
;
4141 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4143 evtHandler
->ProcessEvent(evt
);
4145 return evt
.WasVetoed();
4148 // -----------------------------------------------------------------------
4150 // Return false if should be skipped
4151 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4155 // Need to set focus?
4156 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4161 wxPropertyGridPageState
* state
= m_pState
;
4163 int splitterHitOffset
;
4164 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4166 wxPGProperty
* p
= DoGetItemAtY(y
);
4170 int depth
= (int)p
->GetDepth() - 1;
4172 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4174 if ( x
>= marginEnds
)
4178 if ( p
->IsCategory() )
4180 // This is category.
4181 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4183 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4185 // Expand, collapse, activate etc. if click on text or left of splitter.
4188 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4193 if ( !DoSelectProperty( p
) )
4196 // On double-click, expand/collapse.
4197 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4199 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4200 else DoExpand( p
, true );
4204 else if ( splitterHit
== -1 )
4207 unsigned int selFlag
= 0;
4208 if ( columnHit
== 1 )
4210 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4211 selFlag
= wxPG_SEL_FOCUS
;
4213 if ( !DoSelectProperty( p
, selFlag
) )
4216 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4218 if ( p
->GetChildCount() && !p
->IsCategory() )
4219 // On double-click, expand/collapse.
4220 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4222 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4223 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4224 else DoExpand( p
, true );
4231 // click on splitter
4232 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4234 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4236 // Double-clicking the splitter causes auto-centering
4237 CenterSplitter( true );
4239 else if ( m_dragStatus
== 0 )
4242 // Begin draggin the splitter
4246 // Changes must be committed here or the
4247 // value won't be drawn correctly
4248 if ( !CommitChangesFromEditor() )
4251 m_wndEditor
->Show ( false );
4254 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4256 m_canvas
->CaptureMouse();
4257 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4261 m_draggedSplitter
= splitterHit
;
4262 m_dragOffset
= splitterHitOffset
;
4264 wxClientDC
dc(m_canvas
);
4266 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4267 // Fixes button disappearance bug
4269 m_wndEditor2
->Show ( false );
4272 m_startingSplitterX
= x
- splitterHitOffset
;
4280 if ( p
->GetChildCount() )
4282 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4284 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4286 int y2
= y
% m_lineHeight
;
4287 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4289 // On click on expander button, expand/collapse
4290 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4291 DoCollapse( p
, true );
4293 DoExpand( p
, true );
4302 // -----------------------------------------------------------------------
4304 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4305 wxMouseEvent
& WXUNUSED(event
) )
4309 // Select property here as well
4310 wxPGProperty
* p
= m_propHover
;
4311 if ( p
!= m_selected
)
4312 DoSelectProperty( p
);
4314 // Send right click event.
4315 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4322 // -----------------------------------------------------------------------
4324 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4325 wxMouseEvent
& WXUNUSED(event
) )
4329 // Select property here as well
4330 wxPGProperty
* p
= m_propHover
;
4332 if ( p
!= m_selected
)
4333 DoSelectProperty( p
);
4335 // Send double-click event.
4336 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4343 // -----------------------------------------------------------------------
4345 #if wxPG_SUPPORT_TOOLTIPS
4347 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4349 if ( tipString
.length() )
4351 m_canvas
->SetToolTip(tipString
);
4355 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4356 m_canvas
->SetToolTip( m_emptyString
);
4358 m_canvas
->SetToolTip( NULL
);
4363 #endif // #if wxPG_SUPPORT_TOOLTIPS
4365 // -----------------------------------------------------------------------
4367 // Return false if should be skipped
4368 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4370 // Safety check (needed because mouse capturing may
4371 // otherwise freeze the control)
4372 if ( m_dragStatus
> 0 && !event
.Dragging() )
4374 HandleMouseUp(x
,y
,event
);
4377 wxPropertyGridPageState
* state
= m_pState
;
4379 int splitterHitOffset
;
4380 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4381 int splitterX
= x
- splitterHitOffset
;
4383 if ( m_dragStatus
> 0 )
4385 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4386 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4389 int newSplitterX
= x
- m_dragOffset
;
4390 int splitterX
= x
- splitterHitOffset
;
4392 // Splitter redraw required?
4393 if ( newSplitterX
!= splitterX
)
4396 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4397 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4398 state
->m_fSplitterX
= (float) newSplitterX
;
4401 CorrectEditorWidgetSizeX();
4415 int ih
= m_lineHeight
;
4418 #if wxPG_SUPPORT_TOOLTIPS
4419 wxPGProperty
* prevHover
= m_propHover
;
4420 unsigned char prevSide
= m_mouseSide
;
4422 int curPropHoverY
= y
- (y
% ih
);
4424 // On which item it hovers
4425 if ( ( !m_propHover
)
4427 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4430 // Mouse moves on another property
4432 m_propHover
= DoGetItemAtY(y
);
4433 m_propHoverY
= curPropHoverY
;
4436 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4439 #if wxPG_SUPPORT_TOOLTIPS
4440 // Store which side we are on
4442 if ( columnHit
== 1 )
4444 else if ( columnHit
== 0 )
4448 // If tooltips are enabled, show label or value as a tip
4449 // in case it doesn't otherwise show in full length.
4451 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4453 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4455 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4457 if ( m_propHover
&& !m_propHover
->IsCategory() )
4460 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4462 // Show help string as a tooltip
4463 wxString tipString
= m_propHover
->GetHelpString();
4465 SetToolTip(tipString
);
4469 // Show cropped value string as a tooltip
4473 if ( m_mouseSide
== 1 )
4475 tipString
= m_propHover
->m_label
;
4476 space
= splitterX
-m_marginWidth
-3;
4478 else if ( m_mouseSide
== 2 )
4480 tipString
= m_propHover
->GetDisplayedString();
4482 space
= m_width
- splitterX
;
4483 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4484 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4490 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4493 SetToolTip( tipString
);
4500 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4501 m_canvas
->SetToolTip( m_emptyString
);
4503 m_canvas
->SetToolTip( NULL
);
4514 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4515 m_canvas
->SetToolTip( m_emptyString
);
4517 m_canvas
->SetToolTip( NULL
);
4525 if ( splitterHit
== -1 ||
4527 HasFlag(wxPG_STATIC_SPLITTER
) )
4529 // hovering on something else
4530 if ( m_curcursor
!= wxCURSOR_ARROW
)
4531 CustomSetCursor( wxCURSOR_ARROW
);
4535 // Do not allow splitter cursor on caption items.
4536 // (also not if we were dragging and its started
4537 // outside the splitter region)
4540 !m_propHover
->IsCategory() &&
4544 // hovering on splitter
4546 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4547 // reliably detected.
4548 //if ( m_curcursor != wxCURSOR_SIZEWE )
4549 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4555 // hovering on something else
4556 if ( m_curcursor
!= wxCURSOR_ARROW
)
4557 CustomSetCursor( wxCURSOR_ARROW
);
4564 // -----------------------------------------------------------------------
4566 // Also handles Leaving event
4567 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4568 wxMouseEvent
&WXUNUSED(event
) )
4570 wxPropertyGridPageState
* state
= m_pState
;
4574 int splitterHitOffset
;
4575 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4577 // No event type check - basicly calling this method should
4578 // just stop dragging.
4579 // Left up after dragged?
4580 if ( m_dragStatus
>= 1 )
4583 // End Splitter Dragging
4585 // DO NOT ENABLE FOLLOWING LINE!
4586 // (it is only here as a reminder to not to do it)
4589 // Disable splitter auto-centering
4590 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4592 // This is necessary to return cursor
4593 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4595 m_canvas
->ReleaseMouse();
4596 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4599 // Set back the default cursor, if necessary
4600 if ( splitterHit
== -1 ||
4603 CustomSetCursor( wxCURSOR_ARROW
);
4608 // Control background needs to be cleared
4609 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4610 DrawItem( m_selected
);
4614 m_wndEditor
->Show ( true );
4617 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4618 // Fixes button disappearance bug
4620 m_wndEditor2
->Show ( true );
4623 // This clears the focus.
4624 m_editorFocused
= 0;
4630 // -----------------------------------------------------------------------
4632 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4634 int splitterX
= GetSplitterPosition();
4637 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4641 wxWindow
* wnd
= m_wndEditor
;
4643 // Hide popup on clicks
4644 if ( event
.GetEventType() != wxEVT_MOTION
)
4645 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4647 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4653 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4655 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4656 ux
>= (r
.x
+r
.width
) ||
4658 event
.m_y
>= (r
.y
+r
.height
)
4668 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4673 // -----------------------------------------------------------------------
4675 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4678 if ( OnMouseCommon( event
, &x
, &y
) )
4680 HandleMouseClick(x
,y
,event
);
4685 // -----------------------------------------------------------------------
4687 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4690 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4691 HandleMouseRightClick(x
,y
,event
);
4695 // -----------------------------------------------------------------------
4697 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4699 // Always run standard mouse-down handler as well
4700 OnMouseClick(event
);
4703 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4704 HandleMouseDoubleClick(x
,y
,event
);
4708 // -----------------------------------------------------------------------
4710 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4713 if ( OnMouseCommon( event
, &x
, &y
) )
4715 HandleMouseMove(x
,y
,event
);
4720 // -----------------------------------------------------------------------
4722 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4724 // Called when mouse moves in the empty space below the properties.
4725 CustomSetCursor( wxCURSOR_ARROW
);
4728 // -----------------------------------------------------------------------
4730 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4733 if ( OnMouseCommon( event
, &x
, &y
) )
4735 HandleMouseUp(x
,y
,event
);
4740 // -----------------------------------------------------------------------
4742 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4744 // This may get called from child control as well, so event's
4745 // mouse position cannot be relied on.
4747 if ( event
.Entering() )
4749 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4751 // TODO: Fix this (detect parent and only do
4752 // cursor trick if it is a manager).
4753 wxASSERT( GetParent() );
4754 GetParent()->SetCursor(wxNullCursor
);
4756 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4759 GetParent()->SetCursor(wxNullCursor
);
4761 else if ( event
.Leaving() )
4763 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4764 m_canvas
->SetCursor( wxNullCursor
);
4766 // Get real cursor position
4767 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4769 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4772 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4774 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4778 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4786 // -----------------------------------------------------------------------
4788 // Common code used by various OnMouseXXXChild methods.
4789 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4791 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4792 wxASSERT( topCtrlWnd
);
4794 event
.GetPosition(&x
,&y
);
4796 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4798 int splitterX
= GetSplitterPosition();
4800 wxRect r
= topCtrlWnd
->GetRect();
4801 if ( !m_dragStatus
&&
4802 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4803 y
>= 0 && y
< r
.height \
4806 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4811 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4818 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4821 if ( OnMouseChildCommon(event
,&x
,&y
) )
4823 bool res
= HandleMouseClick(x
,y
,event
);
4824 if ( !res
) event
.Skip();
4828 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4831 wxASSERT( m_wndEditor
);
4832 // These coords may not be exact (about +-2),
4833 // but that should not matter (right click is about item, not position).
4834 wxPoint pt
= m_wndEditor
->GetPosition();
4835 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4836 wxASSERT( m_selected
);
4837 m_propHover
= m_selected
;
4838 bool res
= HandleMouseRightClick(x
,y
,event
);
4839 if ( !res
) event
.Skip();
4842 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4845 if ( OnMouseChildCommon(event
,&x
,&y
) )
4847 bool res
= HandleMouseMove(x
,y
,event
);
4848 if ( !res
) event
.Skip();
4852 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4855 if ( OnMouseChildCommon(event
,&x
,&y
) )
4857 bool res
= HandleMouseUp(x
,y
,event
);
4858 if ( !res
) event
.Skip();
4862 // -----------------------------------------------------------------------
4863 // wxPropertyGrid keyboard event handling
4864 // -----------------------------------------------------------------------
4866 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4868 wxNavigationKeyEvent evt
;
4869 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4870 (dir
?wxNavigationKeyEvent::IsForward
:
4871 wxNavigationKeyEvent::IsBackward
));
4872 evt
.SetEventObject(this);
4873 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4877 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4879 // Translates wxKeyEvent to wxPG_ACTION_XXX
4881 int keycode
= event
.GetKeyCode();
4882 int modifiers
= event
.GetModifiers();
4884 wxASSERT( !(modifiers
&~(0xFFFF)) );
4886 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4888 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4890 if ( it
== m_actionTriggers
.end() )
4895 int second
= (it
->second
>>16) & 0xFFFF;
4899 return (it
->second
& 0xFFFF);
4902 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4904 wxASSERT( !(modifiers
&~(0xFFFF)) );
4906 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4908 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4910 if ( it
!= m_actionTriggers
.end() )
4912 // This key combination is already used
4914 // Can add secondary?
4915 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4916 wxT("You can only add up to two separate actions per key combination.") );
4918 action
= it
->second
| (action
<<16);
4921 m_actionTriggers
[hashMapKey
] = action
;
4924 void wxPropertyGrid::ClearActionTriggers( int action
)
4926 wxPGHashMapI2I::iterator it
;
4928 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4930 if ( it
->second
== action
)
4932 m_actionTriggers
.erase(it
);
4937 static void CopyTextToClipboard( const wxString
& text
)
4939 if ( wxTheClipboard
->Open() )
4941 // This data objects are held by the clipboard,
4942 // so do not delete them in the app.
4943 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
4944 wxTheClipboard
->Close();
4948 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
4951 // Handles key event when editor control is not focused.
4954 wxASSERT( !m_frozen
);
4958 // Travelsal between items, collapsing/expanding, etc.
4959 int keycode
= event
.GetKeyCode();
4961 if ( keycode
== WXK_TAB
)
4963 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
4967 // Ignore Alt and Control when they are down alone
4968 if ( keycode
== WXK_ALT
||
4969 keycode
== WXK_CONTROL
)
4976 int action
= KeyEventToActions(event
, &secondAction
);
4982 if ( ButtonTriggerKeyTest(event
) )
4985 wxPGProperty
* p
= m_selected
;
4987 if ( action
== wxPG_ACTION_COPY
)
4989 CopyTextToClipboard(p
->GetDisplayedString());
4993 // Travel and expand/collapse
4996 if ( p
->GetChildCount() &&
4997 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5000 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5002 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5005 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5007 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5014 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5018 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5029 if ( selectDir
>= -1 )
5031 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5033 DoSelectProperty(p
);
5039 // If nothing was selected, select the first item now
5040 // (or navigate out of tab).
5041 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5043 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5044 if ( p
) DoSelectProperty(p
);
5049 // -----------------------------------------------------------------------
5051 // Potentially handles a keyboard event for editor controls.
5052 // Returns false if event should *not* be skipped (on true it can
5053 // be optionally skipped).
5054 // Basicly, false means that SelectProperty was called (or was about
5055 // to be called, if canDestroy was false).
5056 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5060 if ( !m_selected
|| !m_wndEditor
)
5065 int action
= KeyEventToAction(event
);
5068 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5071 // Esc cancels any changes
5072 if ( IsEditorsValueModified() )
5074 EditorsValueWasNotModified();
5076 // Update the control as well
5077 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5079 m_selected
->GetDisplayedString() );
5082 OnValidationFailureReset(m_selected
);
5088 else if ( action
== wxPG_ACTION_COPY
)
5090 // NB: There is some problem with getting native cut-copy-paste keys to go through
5091 // for embedded editor wxTextCtrl. This is why we emulate.
5093 wxTextCtrl
* tc
= GetEditorTextCtrl();
5096 wxString sel
= tc
->GetStringSelection();
5098 CopyTextToClipboard(sel
);
5102 CopyTextToClipboard(m_selected
->GetDisplayedString());
5105 else if ( action
== wxPG_ACTION_CUT
)
5107 wxTextCtrl
* tc
= GetEditorTextCtrl();
5111 tc
->GetSelection(&from
, &to
);
5114 CopyTextToClipboard(tc
->GetStringSelection());
5115 tc
->Remove(from
, to
);
5119 else if ( action
== wxPG_ACTION_PASTE
)
5121 wxTextCtrl
* tc
= GetEditorTextCtrl();
5124 if (wxTheClipboard
->Open())
5126 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5128 wxTextDataObject data
;
5129 wxTheClipboard
->GetData( data
);
5131 tc
->GetSelection(&from
, &to
);
5134 tc
->Remove(from
, to
);
5135 tc
->WriteText(data
.GetText());
5139 tc
->WriteText(data
.GetText());
5142 wxTheClipboard
->Close();
5150 // -----------------------------------------------------------------------
5152 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5156 // Events to editor controls should get relayed here.
5158 wxWindow
* focused
= wxWindow::FindFocus();
5160 wxWindow
* primaryCtrl
= GetEditorControl();
5163 (focused
==primaryCtrl
5164 || m_editorFocused
) )
5166 // Child key must be processed here, since it can
5167 // destroy the control which is referred by its own
5169 HandleChildKey( event
);
5172 HandleKeyEvent( event
);
5175 // -----------------------------------------------------------------------
5177 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5179 m_keyComboConsumed
= 0;
5184 // -----------------------------------------------------------------------
5186 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5188 // Ignore events that occur very close to focus set
5189 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5191 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5196 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5198 int dir
= event
.GetDirection()?1:-1;
5202 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5204 wxWindow
* focused
= wxWindow::FindFocus();
5206 wxWindow
* wndToCheck
= GetEditorControl();
5208 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5209 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5211 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5212 if ( comboTextCtrl
)
5213 wndToCheck
= comboTextCtrl
;
5217 // Because of problems navigating from wxButton, do not go to it.
5220 // No primary, use secondary
5221 wndToCheck = m_wndEditor2;
5223 // If it has editor button, focus to it after the primary editor.
5224 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5225 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5226 // have somewhat debugged in window.cpp itself).
5227 else if ( focused == wndToCheck &&
5229 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5231 wndToCheck = m_wndEditor2;
5232 wxLogDebug(wxT("Exp1"));
5236 if ( focused
!= wndToCheck
&&
5239 wndToCheck
->SetFocus();
5241 // Select all text in wxTextCtrl etc.
5242 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5243 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5245 m_editorFocused
= 1;
5252 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5256 // This allows preventing NavigateOut to occur
5257 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5266 // -----------------------------------------------------------------------
5268 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5270 int keycode
= event
.GetKeyCode();
5272 // Does the keycode trigger button?
5273 if ( keycode
== m_pushButKeyCode
&&
5275 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5276 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5278 m_keyComboConsumed
= 1;
5280 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5281 GetEventHandler()->AddPendingEvent(evt
);
5288 // -----------------------------------------------------------------------
5290 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5292 int keycode
= event
.GetKeyCode();
5294 // Ignore Alt and Control when they are down alone
5295 if ( keycode
== WXK_ALT
||
5296 keycode
== WXK_CONTROL
)
5302 if ( ButtonTriggerKeyTest(event
) )
5305 if ( HandleChildKey(event
) == true )
5308 GetEventHandler()->AddPendingEvent(event
);
5311 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5313 m_keyComboConsumed
= 0;
5315 GetEventHandler()->AddPendingEvent(event
);
5320 // -----------------------------------------------------------------------
5321 // wxPropertyGrid miscellaneous event handling
5322 // -----------------------------------------------------------------------
5324 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5327 // Check if the focus is in this control or one of its children
5328 wxWindow
* newFocused
= wxWindow::FindFocus();
5330 if ( newFocused
!= m_curFocused
)
5331 HandleFocusChange( newFocused
);
5334 // Called by focus event handlers. newFocused is the window that becomes focused.
5335 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5337 unsigned int oldFlags
= m_iFlags
;
5339 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5341 wxWindow
* parent
= newFocused
;
5343 // This must be one of nextFocus' parents.
5346 // Use m_eventObject, which is either wxPropertyGrid or
5347 // wxPropertyGridManager, as appropriate.
5348 if ( parent
== m_eventObject
)
5350 m_iFlags
|= wxPG_FL_FOCUSED
;
5353 parent
= parent
->GetParent();
5356 m_curFocused
= newFocused
;
5358 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5359 (oldFlags
& wxPG_FL_FOCUSED
) )
5361 // On each focus kill, mark the next nav key event
5362 // to be ignored (can't do on set focus since the
5363 // event would occur before it).
5364 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5366 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5368 // Need to store changed value
5369 CommitChangesFromEditor();
5375 // Preliminary code for tab-order respecting
5376 // tab-traversal (but should be moved to
5379 wxWindow* prevFocus = event.GetWindow();
5380 wxWindow* useThis = this;
5381 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5382 useThis = GetParent();
5385 prevFocus->GetParent() == useThis->GetParent() )
5387 wxList& children = useThis->GetParent()->GetChildren();
5389 wxNode* node = children.Find(prevFocus);
5391 if ( node->GetNext() &&
5392 useThis == node->GetNext()->GetData() )
5393 DoSelectProperty(GetFirst());
5394 else if ( node->GetPrevious () &&
5395 useThis == node->GetPrevious()->GetData() )
5396 DoSelectProperty(GetLastProperty());
5401 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5405 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5406 DrawItem( m_selected
);
5410 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5412 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5413 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5414 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5415 //else if ( event.GetWindow() )
5417 HandleFocusChange(event
.GetWindow());
5422 // -----------------------------------------------------------------------
5424 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5426 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5429 // event.Skip() being commented out is aworkaround for bug reported
5430 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5434 // -----------------------------------------------------------------------
5436 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5438 m_iFlags
|= wxPG_FL_SCROLLED
;
5443 // -----------------------------------------------------------------------
5445 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5447 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5449 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5453 // -----------------------------------------------------------------------
5454 // Property editor related functions
5455 // -----------------------------------------------------------------------
5457 // noDefCheck = true prevents infinite recursion.
5458 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5461 wxASSERT( editorClass
);
5463 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5464 RegisterDefaultEditors();
5466 wxString name
= editorClass
->GetName();
5468 // Existing editor under this name?
5469 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5471 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5472 (wxPGEditor
*) vt_it
->second
,
5473 "Editor with given name was already registered" );
5475 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5480 // Registers all default editor classes
5481 void wxPropertyGrid::RegisterDefaultEditors()
5483 wxPGRegisterDefaultEditorClass( TextCtrl
);
5484 wxPGRegisterDefaultEditorClass( Choice
);
5485 wxPGRegisterDefaultEditorClass( ComboBox
);
5486 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5487 #if wxPG_INCLUDE_CHECKBOX
5488 wxPGRegisterDefaultEditorClass( CheckBox
);
5490 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5492 // Register SpinCtrl etc. editors before use
5493 RegisterAdditionalEditors();
5496 // -----------------------------------------------------------------------
5497 // wxPGStringTokenizer
5498 // Needed to handle C-style string lists (e.g. "str1" "str2")
5499 // -----------------------------------------------------------------------
5501 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5502 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5506 wxPGStringTokenizer::~wxPGStringTokenizer()
5510 bool wxPGStringTokenizer::HasMoreTokens()
5512 const wxString
& str
= *m_str
;
5514 wxString::const_iterator i
= m_curPos
;
5516 wxUniChar delim
= m_delimeter
;
5518 wxUniChar prev_a
= wxT('\0');
5520 bool inToken
= false;
5522 while ( i
!= str
.end() )
5531 m_readyToken
.clear();
5536 if ( prev_a
!= wxT('\\') )
5540 if ( a
!= wxT('\\') )
5560 m_curPos
= str
.end();
5568 wxString
wxPGStringTokenizer::GetNextToken()
5570 return m_readyToken
;
5573 // -----------------------------------------------------------------------
5575 // -----------------------------------------------------------------------
5577 wxPGChoiceEntry::wxPGChoiceEntry()
5578 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5582 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5583 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5584 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5588 // -----------------------------------------------------------------------
5590 // -----------------------------------------------------------------------
5592 wxPGChoicesData::wxPGChoicesData()
5597 wxPGChoicesData::~wxPGChoicesData()
5602 void wxPGChoicesData::Clear()
5606 for ( i
=0; i
<m_items
.size(); i
++ )
5618 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5620 wxASSERT( m_items
.size() == 0 );
5624 for ( i
=0; i
<data
->GetCount(); i
++ )
5625 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5628 // -----------------------------------------------------------------------
5630 // -----------------------------------------------------------------------
5632 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5636 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5637 m_data
->Insert( -1, p
);
5641 // -----------------------------------------------------------------------
5643 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5647 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5648 p
->SetBitmap(bitmap
);
5649 m_data
->Insert( -1, p
);
5653 // -----------------------------------------------------------------------
5655 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5659 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5660 m_data
->Insert(index
, p
);
5664 // -----------------------------------------------------------------------
5666 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5670 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5671 m_data
->Insert( index
, p
);
5675 // -----------------------------------------------------------------------
5677 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5683 while ( index
< GetCount() )
5685 int cmpRes
= GetLabel(index
).Cmp(label
);
5691 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5692 m_data
->Insert( index
, p
);
5696 // -----------------------------------------------------------------------
5698 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5702 unsigned int itemcount
= 0;
5703 const wxChar
** p
= &labels
[0];
5704 while ( *p
) { p
++; itemcount
++; }
5707 for ( i
= 0; i
< itemcount
; i
++ )
5709 int value
= wxPG_INVALID_VALUE
;
5712 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5716 // -----------------------------------------------------------------------
5718 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5723 unsigned int itemcount
= arr
.size();
5725 for ( i
= 0; i
< itemcount
; i
++ )
5727 int value
= wxPG_INVALID_VALUE
;
5730 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5734 // -----------------------------------------------------------------------
5736 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5741 unsigned int itemcount
= arr
.size();
5743 for ( i
= 0; i
< itemcount
; i
++ )
5745 int value
= wxPG_INVALID_VALUE
;
5746 if ( &arrint
&& arrint
.size() )
5748 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5752 // -----------------------------------------------------------------------
5754 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5756 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5758 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5759 delete m_data
->Item(i
);
5760 m_data
->m_items
.RemoveAt(nIndex
, count
);
5763 // -----------------------------------------------------------------------
5765 int wxPGChoices::Index( const wxString
& str
) const
5770 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5772 if ( m_data
->Item(i
)->GetText() == str
)
5779 // -----------------------------------------------------------------------
5781 int wxPGChoices::Index( int val
) const
5786 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5788 if ( m_data
->Item(i
)->GetValue() == val
)
5795 // -----------------------------------------------------------------------
5797 wxArrayString
wxPGChoices::GetLabels() const
5802 if ( this && IsOk() )
5803 for ( i
=0; i
<GetCount(); i
++ )
5804 arr
.push_back(GetLabel(i
));
5809 // -----------------------------------------------------------------------
5811 bool wxPGChoices::HasValues() const
5816 // -----------------------------------------------------------------------
5818 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5825 for ( i
=0; i
< strings
.size(); i
++ )
5827 int index
= Index(strings
[i
]);
5829 arr
.Add(GetValue(index
));
5831 arr
.Add(wxPG_INVALID_VALUE
);
5838 // -----------------------------------------------------------------------
5840 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5841 wxArrayString
* unmatched
) const
5848 for ( i
=0; i
< strings
.size(); i
++ )
5850 const wxString
& str
= strings
[i
];
5851 int index
= Index(str
);
5854 else if ( unmatched
)
5855 unmatched
->Add(str
);
5862 // -----------------------------------------------------------------------
5864 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5868 if ( data
!= wxPGChoicesEmptyData
)
5875 // -----------------------------------------------------------------------
5877 void wxPGChoices::Init()
5879 m_data
= wxPGChoicesEmptyData
;
5882 // -----------------------------------------------------------------------
5884 void wxPGChoices::Free()
5886 if ( m_data
!= wxPGChoicesEmptyData
)
5889 m_data
= wxPGChoicesEmptyData
;
5893 // -----------------------------------------------------------------------
5894 // wxPropertyGridEvent
5895 // -----------------------------------------------------------------------
5897 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5900 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5901 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5902 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5903 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5904 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5905 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5906 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5907 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5908 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5911 // -----------------------------------------------------------------------
5913 void wxPropertyGridEvent::Init()
5915 m_validationInfo
= NULL
;
5917 m_wasVetoed
= false;
5920 // -----------------------------------------------------------------------
5922 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5923 : wxCommandEvent(commandType
,id
)
5929 // -----------------------------------------------------------------------
5931 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5932 : wxCommandEvent(event
)
5934 m_eventType
= event
.GetEventType();
5935 m_eventObject
= event
.m_eventObject
;
5937 m_property
= event
.m_property
;
5938 m_validationInfo
= event
.m_validationInfo
;
5939 m_canVeto
= event
.m_canVeto
;
5940 m_wasVetoed
= event
.m_wasVetoed
;
5943 // -----------------------------------------------------------------------
5945 wxPropertyGridEvent::~wxPropertyGridEvent()
5949 // -----------------------------------------------------------------------
5951 wxEvent
* wxPropertyGridEvent::Clone() const
5953 return new wxPropertyGridEvent( *this );
5956 // -----------------------------------------------------------------------
5957 // wxPropertyGridPopulator
5958 // -----------------------------------------------------------------------
5960 wxPropertyGridPopulator::wxPropertyGridPopulator()
5964 wxPGGlobalVars
->m_offline
++;
5967 // -----------------------------------------------------------------------
5969 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5972 m_propHierarchy
.clear();
5975 // -----------------------------------------------------------------------
5977 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5983 // -----------------------------------------------------------------------
5985 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5988 // Free unused sets of choices
5989 wxPGHashMapS2P::iterator it
;
5991 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5993 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6000 m_pg
->GetPanel()->Refresh();
6002 wxPGGlobalVars
->m_offline
--;
6005 // -----------------------------------------------------------------------
6007 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6008 const wxString
& propLabel
,
6009 const wxString
& propName
,
6010 const wxString
* propValue
,
6011 wxPGChoices
* pChoices
)
6013 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6014 wxPGProperty
* parent
= GetCurParent();
6016 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6018 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6022 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6024 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6028 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6030 property
->SetLabel(propLabel
);
6031 property
->DoSetName(propName
);
6033 if ( pChoices
&& pChoices
->IsOk() )
6034 property
->SetChoices(*pChoices
);
6036 m_state
->DoInsert(parent
, -1, property
);
6039 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6044 // -----------------------------------------------------------------------
6046 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6048 m_propHierarchy
.push_back(property
);
6049 DoScanForChildren();
6050 m_propHierarchy
.pop_back();
6053 // -----------------------------------------------------------------------
6055 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6056 const wxString
& idString
)
6058 wxPGChoices choices
;
6061 if ( choicesString
[0] == wxT('@') )
6063 wxString ids
= choicesString
.substr(1);
6064 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6065 if ( it
== m_dictIdChoices
.end() )
6066 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6068 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6073 if ( idString
.length() )
6075 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6076 if ( it
!= m_dictIdChoices
.end() )
6078 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6085 // Parse choices string
6086 wxString::const_iterator it
= choicesString
.begin();
6090 bool labelValid
= false;
6092 for ( ; it
!= choicesString
.end(); it
++ )
6098 if ( c
== wxT('"') )
6103 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6104 choices
.Add(label
, l
);
6107 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6112 else if ( c
== wxT('=') )
6119 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6126 if ( c
== wxT('"') )
6139 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6140 choices
.Add(label
, l
);
6143 if ( !choices
.IsOk() )
6145 choices
.EnsureData();
6149 if ( idString
.length() )
6150 m_dictIdChoices
[idString
] = choices
.GetData();
6157 // -----------------------------------------------------------------------
6159 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6161 if ( s
.Last() == wxT('%') )
6163 wxString s2
= s
.substr(0,s
.length()-1);
6165 if ( s2
.ToLong(&val
, 10) )
6167 *pval
= (val
*max
)/100;
6173 return s
.ToLong(pval
, 10);
6176 // -----------------------------------------------------------------------
6178 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6179 const wxString
& type
,
6180 const wxString
& value
)
6182 int l
= m_propHierarchy
.size();
6186 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6187 wxString valuel
= value
.Lower();
6190 if ( type
.length() == 0 )
6195 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6197 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6199 else if ( value
.ToLong(&v
, 0) )
6206 if ( type
== wxT("string") )
6210 else if ( type
== wxT("int") )
6213 value
.ToLong(&v
, 0);
6216 else if ( type
== wxT("bool") )
6218 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6225 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6230 p
->SetAttribute( name
, variant
);
6235 // -----------------------------------------------------------------------
6237 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6239 wxLogError(_("Error in resource: %s"),msg
.c_str());
6242 // -----------------------------------------------------------------------
6244 #endif // wxUSE_PROPGRID