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 void wxPropertyGrid::DoSetPropertyName( wxPGProperty
* p
, const wxString
& newname
)
1496 wxCHECK_RET( p
, wxT("invalid property id") );
1498 if ( p
->GetBaseName().Len() ) m_pState
->m_dictName
.erase( p
->GetBaseName() );
1499 if ( newname
.Len() ) m_pState
->m_dictName
[newname
] = (void*) p
;
1501 p
->DoSetName(newname
);
1504 // -----------------------------------------------------------------------
1506 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1508 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1512 bool changed
= false;
1514 // Is it inside collapsed section?
1515 if ( !p
->IsVisible() )
1518 wxPGProperty
* parent
= p
->GetParent();
1519 wxPGProperty
* grandparent
= parent
->GetParent();
1521 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1522 Expand( grandparent
);
1530 GetViewStart(&vx
,&vy
);
1531 vy
*=wxPG_PIXELS_PER_UNIT
;
1537 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1538 m_iFlags
|= wxPG_FL_SCROLLED
;
1541 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1543 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1544 m_iFlags
|= wxPG_FL_SCROLLED
;
1554 // -----------------------------------------------------------------------
1555 // wxPropertyGrid helper methods called by properties
1556 // -----------------------------------------------------------------------
1558 // Control font changer helper.
1559 void wxPropertyGrid::SetCurControlBoldFont()
1561 wxASSERT( m_wndEditor
);
1562 m_wndEditor
->SetFont( m_captionFont
);
1565 // -----------------------------------------------------------------------
1567 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1570 #if wxPG_SMALL_SCREEN
1571 // On small-screen devices, always show dialogs with default position and size.
1572 return wxDefaultPosition
;
1574 int splitterX
= GetSplitterPosition();
1578 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1580 ImprovedClientToScreen( &x
, &y
);
1582 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1583 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1590 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1600 new_y
= y
+ m_lineHeight
;
1602 return wxPoint(new_x
,new_y
);
1606 // -----------------------------------------------------------------------
1608 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1610 if ( src_str
.length() == 0 )
1616 bool prev_is_slash
= false;
1618 wxString::const_iterator i
= src_str
.begin();
1622 for ( ; i
!= src_str
.end(); i
++ )
1626 if ( a
!= wxS('\\') )
1628 if ( !prev_is_slash
)
1634 if ( a
== wxS('n') )
1637 dst_str
<< wxS('\n');
1639 dst_str
<< wxS('\n');
1642 else if ( a
== wxS('t') )
1643 dst_str
<< wxS('\t');
1647 prev_is_slash
= false;
1651 if ( prev_is_slash
)
1653 dst_str
<< wxS('\\');
1654 prev_is_slash
= false;
1658 prev_is_slash
= true;
1665 // -----------------------------------------------------------------------
1667 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1669 if ( src_str
.length() == 0 )
1675 wxString::const_iterator i
= src_str
.begin();
1676 wxUniChar prev_a
= wxS('\0');
1680 for ( ; i
!= src_str
.end(); i
++ )
1684 if ( a
>= wxS(' ') )
1686 // This surely is not something that requires an escape sequence.
1691 // This might need...
1692 if ( a
== wxS('\r') )
1694 // DOS style line end.
1695 // Already taken care below
1697 else if ( a
== wxS('\n') )
1698 // UNIX style line end.
1699 dst_str
<< wxS("\\n");
1700 else if ( a
== wxS('\t') )
1702 dst_str
<< wxS('\t');
1705 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1715 // -----------------------------------------------------------------------
1717 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1721 return (wxPGProperty
*) NULL
;
1724 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1727 // -----------------------------------------------------------------------
1728 // wxPropertyGrid graphics related methods
1729 // -----------------------------------------------------------------------
1731 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1735 // Update everything inside the box
1736 wxRect r
= GetUpdateRegion().GetBox();
1738 dc
.SetPen(m_colEmptySpace
);
1739 dc
.SetBrush(m_colEmptySpace
);
1740 dc
.DrawRectangle(r
);
1743 // -----------------------------------------------------------------------
1745 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1746 wxPGProperty
* property
) const
1748 // Prepare rectangle to be used
1750 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1751 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1753 #if (wxPG_USE_RENDERER_NATIVE)
1755 #elif wxPG_ICON_WIDTH
1756 // Drawing expand/collapse button manually
1757 dc
.SetPen(m_colPropFore
);
1758 if ( property
->IsCategory() )
1759 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1761 dc
.SetBrush(m_colPropBack
);
1763 dc
.DrawRectangle( r
);
1764 int _y
= r
.y
+(m_iconWidth
/2);
1765 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1770 if ( property
->IsExpanded() )
1772 // wxRenderer functions are non-mutating in nature, so it
1773 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1774 // Hopefully this does not cause problems.
1775 #if (wxPG_USE_RENDERER_NATIVE)
1776 wxRendererNative::Get().DrawTreeItemButton(
1782 #elif wxPG_ICON_WIDTH
1791 #if (wxPG_USE_RENDERER_NATIVE)
1792 wxRendererNative::Get().DrawTreeItemButton(
1798 #elif wxPG_ICON_WIDTH
1799 int _x
= r
.x
+(m_iconWidth
/2);
1800 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1806 #if (wxPG_USE_RENDERER_NATIVE)
1808 #elif wxPG_ICON_WIDTH
1811 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1815 // -----------------------------------------------------------------------
1818 // This is the one called by OnPaint event handler and others.
1819 // topy and bottomy are already unscrolled (ie. physical)
1821 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1823 unsigned int bottomy
,
1824 const wxRect
* clipRect
)
1826 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1828 m_pState
->EnsureVirtualHeight();
1830 wxRect tempClipRect
;
1833 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1834 clipRect
= &tempClipRect
;
1837 // items added check
1838 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1840 int paintFinishY
= 0;
1842 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1845 bool isBuffered
= false;
1847 #if wxPG_DOUBLE_BUFFER
1848 wxMemoryDC
* bufferDC
= NULL
;
1850 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1852 if ( !m_doubleBuffer
)
1854 paintFinishY
= clipRect
->y
;
1859 bufferDC
= new wxMemoryDC();
1861 // If nothing was changed, then just copy from double-buffer
1862 bufferDC
->SelectObject( *m_doubleBuffer
);
1872 dc
.SetClippingRegion( *clipRect
);
1873 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1876 #if wxPG_DOUBLE_BUFFER
1879 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1880 bufferDC
, 0, 0, wxCOPY
);
1881 dc
.DestroyClippingRegion(); // Is this really necessary?
1887 // Clear area beyond bottomY?
1888 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1890 dc
.SetPen(m_colEmptySpace
);
1891 dc
.SetBrush(m_colEmptySpace
);
1892 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1896 // -----------------------------------------------------------------------
1898 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1899 const wxPGProperty
* firstItem
,
1900 const wxPGProperty
* lastItem
,
1901 const wxRect
* clipRect
,
1902 bool isBuffered
) const
1904 // TODO: This should somehow be eliminated.
1905 wxRect tempClipRect
;
1908 wxASSERT(firstItem
);
1910 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1911 clipRect
= &tempClipRect
;
1915 firstItem
= DoGetItemAtY(clipRect
->y
);
1919 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1921 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1924 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1927 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1928 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1930 int lh
= m_lineHeight
;
1933 int lastItemBottomY
;
1935 firstItemTopY
= clipRect
->y
;
1936 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1938 // Align y coordinates to item boundaries
1939 firstItemTopY
-= firstItemTopY
% lh
;
1940 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1941 lastItemBottomY
-= 1;
1943 // Entire range outside scrolled, visible area?
1944 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1947 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1951 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1952 firstItem->GetLabel().c_str(),
1953 lastItem->GetLabel().c_str(),
1954 (int)(lastItemBottomY - firstItemTopY),
1956 (unsigned long)clipRect );
1961 long windowStyle
= m_windowStyle
;
1967 // With wxPG_DOUBLE_BUFFER, do double buffering
1968 // - buffer's y = 0, so align cliprect and coordinates to that
1970 #if wxPG_DOUBLE_BUFFER
1976 xRelMod
= clipRect
->x
;
1977 yRelMod
= clipRect
->y
;
1980 // clipRect conversion
1988 firstItemTopY
-= yRelMod
;
1989 lastItemBottomY
-= yRelMod
;
1992 wxUnusedVar(isBuffered
);
1995 int x
= m_marginWidth
- xRelMod
;
1997 const wxFont
& normalfont
= m_font
;
1999 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
2001 bool isEnabled
= IsEnabled();
2004 // Prepare some pens and brushes that are often changed to.
2007 wxBrush
marginBrush(m_colMargin
);
2008 wxPen
marginPen(m_colMargin
);
2009 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
2010 wxPen
linepen(m_colLine
,1,wxSOLID
);
2012 // pen that has same colour as text
2013 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
2016 // Clear margin with background colour
2018 dc
.SetBrush( marginBrush
);
2019 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
2021 dc
.SetPen( *wxTRANSPARENT_PEN
);
2022 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
2025 const wxPGProperty
* selected
= m_selected
;
2026 const wxPropertyGridPageState
* state
= m_pState
;
2028 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2029 bool wasSelectedPainted
= false;
2032 // TODO: Only render columns that are within clipping region.
2034 dc
.SetFont(normalfont
);
2036 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
2037 int endScanBottomY
= lastItemBottomY
+ lh
;
2038 int y
= firstItemTopY
;
2041 // Pregenerate list of visible properties.
2042 wxArrayPGProperty visPropArray
;
2043 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
2045 for ( ; !it
.AtEnd(); it
.Next() )
2047 const wxPGProperty
* p
= *it
;
2049 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
2051 visPropArray
.push_back((wxPGProperty
*)p
);
2053 if ( y
> endScanBottomY
)
2060 visPropArray
.push_back(NULL
);
2062 wxPGProperty
* nextP
= visPropArray
[0];
2064 int gridWidth
= state
->m_width
;
2067 for ( unsigned int arrInd
=1;
2068 nextP
&& y
<= lastItemBottomY
;
2071 wxPGProperty
* p
= nextP
;
2072 nextP
= visPropArray
[arrInd
];
2074 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
2075 int textMarginHere
= x
;
2076 int renderFlags
= wxPGCellRenderer::Control
;
2078 int greyDepth
= m_marginWidth
;
2079 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
2080 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
2082 int greyDepthX
= greyDepth
- xRelMod
;
2084 // Use basic depth if in non-categoric mode and parent is base array.
2085 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
2087 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
2090 // Paint margin area
2091 dc
.SetBrush(marginBrush
);
2092 dc
.SetPen(marginPen
);
2093 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
2095 dc
.SetPen( linepen
);
2100 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
2106 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
2108 sx
+= state
->m_colWidths
[si
];
2109 dc
.DrawLine( sx
, y
, sx
, y2
);
2112 // Horizontal Line, below
2113 // (not if both this and next is category caption)
2114 if ( p
->IsCategory() &&
2115 nextP
&& nextP
->IsCategory() )
2116 dc
.SetPen(m_colCapBack
);
2118 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
2120 if ( p
== selected
)
2122 renderFlags
|= wxPGCellRenderer::Selected
;
2123 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2124 wasSelectedPainted
= true;
2132 if ( p
->IsCategory() )
2134 if ( p
->m_fgColIndex
== 0 )
2135 rowFgCol
= m_colCapFore
;
2137 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2138 rowBgBrush
= wxBrush(m_colCapBack
);
2140 else if ( p
!= selected
)
2142 // Disabled may get different colour.
2143 if ( !p
->IsEnabled() )
2144 rowFgCol
= m_colDisPropFore
;
2146 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2148 rowBgBrush
= *(wxPGBrush
*)m_arrBgBrushes
[p
->m_bgColIndex
];
2152 // Selected gets different colour.
2153 if ( reallyFocused
)
2155 rowFgCol
= m_colSelFore
;
2156 rowBgBrush
= wxBrush(m_colSelBack
);
2158 else if ( isEnabled
)
2160 rowFgCol
= *(wxPGColour
*)m_arrFgCols
[p
->m_fgColIndex
];
2161 rowBgBrush
= marginBrush
;
2165 rowFgCol
= m_colDisPropFore
;
2166 rowBgBrush
= wxBrush(m_colSelBack
);
2170 bool fontChanged
= false;
2172 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
2177 if ( p
->IsCategory() )
2179 // Captions are all cells merged as one
2180 dc
.SetFont(m_captionFont
);
2182 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
2184 dc
.SetBrush(rowBgBrush
);
2185 dc
.SetPen(rowBgBrush
.GetColour());
2186 dc
.SetTextForeground(rowFgCol
);
2188 dc
.DrawRectangle(cellRect
);
2191 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
2192 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
2195 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2196 DrawExpanderButton( dc
, butRect
, p
);
2200 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
2202 dc
.SetFont(m_captionFont
);
2208 int nextCellWidth
= state
->m_colWidths
[0];
2209 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
2210 int textXAdd
= textMarginHere
- greyDepthX
;
2212 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
2214 cellRect
.width
= nextCellWidth
- 1;
2216 bool ctrlCell
= false;
2219 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2221 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2222 dc
.SetBrush(editorBgCol
);
2223 dc
.SetPen(editorBgCol
);
2224 dc
.SetTextForeground(m_colPropFore
);
2226 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2231 dc
.SetBrush(rowBgBrush
);
2232 dc
.SetPen(rowBgBrush
.GetColour());
2233 dc
.SetTextForeground(rowFgCol
);
2236 dc
.DrawRectangle(cellRect
);
2239 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2240 DrawExpanderButton( dc
, butRect
, p
);
2242 dc
.SetClippingRegion(cellRect
);
2244 cellRect
.x
+= textXAdd
;
2245 cellRect
.width
-= textXAdd
;
2250 wxPGCellRenderer
* renderer
;
2251 int cmnVal
= p
->GetCommonValue();
2252 if ( cmnVal
== -1 || ci
!= 1 )
2254 renderer
= p
->GetCellRenderer(ci
);
2255 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2259 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2260 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1, renderFlags
);
2264 cellX
+= state
->m_colWidths
[ci
];
2265 if ( ci
< (state
->m_colWidths
.size()-1) )
2266 nextCellWidth
= state
->m_colWidths
[ci
+1];
2268 dc
.DestroyClippingRegion(); // Is this really necessary?
2274 dc
.SetFont(normalfont
);
2279 // Refresh editor controls (seems not needed on msw)
2280 // NOTE: This code is mandatory for GTK!
2281 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2282 if ( wasSelectedPainted
)
2285 m_wndEditor
->Refresh();
2287 m_wndEditor2
->Refresh();
2294 // -----------------------------------------------------------------------
2296 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2300 if ( m_width
< 10 || m_height
< 10 ||
2301 !m_pState
->m_properties
->GetChildCount() ||
2302 p1
== (wxPGProperty
*) NULL
)
2303 return wxRect(0,0,0,0);
2308 // Return rect which encloses the given property range
2310 int visTop
= p1
->GetY();
2313 visBottom
= p2
->GetY() + m_lineHeight
;
2315 visBottom
= m_height
+ visTop
;
2317 // If seleced property is inside the range, we'll extend the range to include
2319 wxPGProperty
* selected
= m_selected
;
2322 int selectedY
= selected
->GetY();
2323 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2325 wxWindow
* editor
= GetEditorControl();
2328 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2329 if ( visBottom2
> visBottom
)
2330 visBottom
= visBottom2
;
2335 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2338 // -----------------------------------------------------------------------
2340 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2345 if ( m_pState
->m_itemsAdded
)
2346 PrepareAfterItemsAdded();
2348 wxRect r
= GetPropertyRect(p1
, p2
);
2351 m_canvas
->RefreshRect(r
);
2355 // -----------------------------------------------------------------------
2357 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2359 if ( p
== m_selected
)
2360 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2362 DrawItemAndChildren(p
);
2365 // -----------------------------------------------------------------------
2367 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2372 // Draw item, children, and parent too, if it is not category
2373 wxPGProperty
* parent
= p
->GetParent();
2376 !parent
->IsCategory() &&
2377 parent
->GetParent() )
2380 parent
= parent
->GetParent();
2383 DrawItemAndChildren(p
);
2386 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2388 wxCHECK_RET( p
, wxT("invalid property id") );
2390 // Do not draw if in non-visible page
2391 if ( p
->GetParentState() != m_pState
)
2394 // do not draw a single item if multiple pending
2395 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2398 wxWindow
* wndPrimary
= GetEditorControl();
2400 // Update child control.
2401 if ( m_selected
&& m_selected
->GetParent() == p
)
2402 m_selected
->UpdateControl(wndPrimary
);
2404 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2406 DrawItems(p
, lastDrawn
);
2409 // -----------------------------------------------------------------------
2411 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2412 const wxRect
*rect
)
2414 PrepareAfterItemsAdded();
2416 wxWindow::Refresh(false);
2418 // TODO: Coordinate translation
2419 m_canvas
->Refresh(false, rect
);
2421 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2422 // I think this really helps only GTK+1.2
2423 if ( m_wndEditor
) m_wndEditor
->Refresh();
2424 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2428 // -----------------------------------------------------------------------
2429 // wxPropertyGrid global operations
2430 // -----------------------------------------------------------------------
2432 void wxPropertyGrid::Clear()
2436 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2437 wxPG_CHECK_RET_DBG( selRes
,
2438 wxT("failed to deselect a property (editor probably had invalid value)") );
2441 m_pState
->DoClear();
2447 RecalculateVirtualSize();
2449 // Need to clear some area at the end
2451 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2454 // -----------------------------------------------------------------------
2456 bool wxPropertyGrid::EnableCategories( bool enable
)
2458 if ( !ClearSelection() )
2464 // Enable categories
2467 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2472 // Disable categories
2474 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2477 if ( !m_pState
->EnableCategories(enable
) )
2482 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2484 m_pState
->m_itemsAdded
= 1; // force
2485 PrepareAfterItemsAdded();
2489 m_pState
->m_itemsAdded
= 1;
2491 // No need for RecalculateVirtualSize() here - it is already called in
2492 // wxPropertyGridPageState method above.
2499 // -----------------------------------------------------------------------
2501 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2503 wxASSERT( pNewState
);
2504 wxASSERT( pNewState
->GetGrid() );
2506 if ( pNewState
== m_pState
)
2509 wxPGProperty
* oldSelection
= m_selected
;
2514 bool selRes
= ClearSelection();
2515 wxPG_CHECK_RET_DBG( selRes
,
2516 wxT("failed to deselect a property (editor probably had invalid value)") );
2519 m_pState
->m_selected
= oldSelection
;
2521 bool orig_mode
= m_pState
->IsInNonCatMode();
2522 bool new_state_mode
= pNewState
->IsInNonCatMode();
2524 m_pState
= pNewState
;
2527 int pgWidth
= GetClientSize().x
;
2528 if ( HasVirtualWidth() )
2530 int minWidth
= pgWidth
;
2531 if ( pNewState
->m_width
< minWidth
)
2533 pNewState
->m_width
= minWidth
;
2534 pNewState
->CheckColumnWidths();
2540 // Just in case, fully re-center splitter
2541 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2542 pNewState
->m_fSplitterX
= -1.0;
2544 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2547 m_propHover
= (wxPGProperty
*) NULL
;
2549 // If necessary, convert state to correct mode.
2550 if ( orig_mode
!= new_state_mode
)
2552 // This should refresh as well.
2553 EnableCategories( orig_mode
?false:true );
2555 else if ( !m_frozen
)
2557 // Refresh, if not frozen.
2558 if ( m_pState
->m_itemsAdded
)
2559 PrepareAfterItemsAdded();
2562 if ( m_pState
->m_selected
)
2563 DoSelectProperty( m_pState
->m_selected
);
2565 RecalculateVirtualSize(0);
2569 m_pState
->m_itemsAdded
= 1;
2572 // -----------------------------------------------------------------------
2574 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2576 wxPG_PROP_ARG_CALL_PROLOG()
2578 m_pState
->SortChildren( p
);
2581 // -----------------------------------------------------------------------
2583 void wxPropertyGrid::Sort()
2585 bool selRes
= ClearSelection(); // This must be before state clear
2586 wxPG_CHECK_RET_DBG( selRes
,
2587 wxT("failed to deselect a property (editor probably had invalid value)") );
2592 // -----------------------------------------------------------------------
2594 // Call to SetSplitterPosition will always disable splitter auto-centering
2595 // if parent window is shown.
2596 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2598 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2601 wxPropertyGridPageState
* state
= m_pState
;
2603 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2608 CorrectEditorWidgetSizeX();
2614 // -----------------------------------------------------------------------
2616 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2618 SetSplitterPosition( m_width
/2, true );
2619 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2620 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2623 // -----------------------------------------------------------------------
2624 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2625 // -----------------------------------------------------------------------
2627 // Returns nearest paint visible property (such that will be painted unless
2628 // window is scrolled or resized). If given property is paint visible, then
2629 // it itself will be returned
2630 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2632 int vx
,vy1
;// Top left corner of client
2633 GetViewStart(&vx
,&vy1
);
2634 vy1
*= wxPG_PIXELS_PER_UNIT
;
2636 int vy2
= vy1
+ m_height
;
2637 int propY
= p
->GetY2(m_lineHeight
);
2639 if ( (propY
+ m_lineHeight
) < vy1
)
2642 return DoGetItemAtY( vy1
);
2644 else if ( propY
> vy2
)
2647 return DoGetItemAtY( vy2
);
2650 // Itself paint visible
2655 // -----------------------------------------------------------------------
2657 void wxPropertyGrid::SetButtonShortcut( int keycode
, bool ctrlDown
, bool altDown
)
2661 m_pushButKeyCode
= keycode
;
2662 m_pushButKeyCodeNeedsCtrl
= ctrlDown
? 1 : 0;
2663 m_pushButKeyCodeNeedsAlt
= altDown
? 1 : 0;
2667 m_pushButKeyCode
= WXK_DOWN
;
2668 m_pushButKeyCodeNeedsCtrl
= 0;
2669 m_pushButKeyCodeNeedsAlt
= 1;
2673 // -----------------------------------------------------------------------
2674 // Methods related to change in value, value modification and sending events
2675 // -----------------------------------------------------------------------
2677 // commits any changes in editor of selected property
2678 // return true if validation did not fail
2679 // flags are same as with DoSelectProperty
2680 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2682 // Committing already?
2683 if ( m_inCommitChangesFromEditor
)
2686 // Don't do this if already processing editor event. It might
2687 // induce recursive dialogs and crap like that.
2688 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2690 if ( m_inDoPropertyChanged
)
2697 IsEditorsValueModified() &&
2698 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2701 m_inCommitChangesFromEditor
= 1;
2703 wxVariant
variant(m_selected
->GetValueRef());
2704 bool valueIsPending
= false;
2706 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2707 // due to another window getting focus
2708 wxWindow
* oldFocus
= m_curFocused
;
2710 bool validationFailure
= false;
2711 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2713 m_chgInfo_changedProperty
= NULL
;
2715 // If truly modified, schedule value as pending.
2716 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2718 if ( DoEditorValidate() &&
2719 PerformValidation(m_selected
, variant
) )
2721 valueIsPending
= true;
2725 validationFailure
= true;
2730 EditorsValueWasNotModified();
2735 m_inCommitChangesFromEditor
= 0;
2737 if ( validationFailure
&& !forceSuccess
)
2741 oldFocus
->SetFocus();
2742 m_curFocused
= oldFocus
;
2745 res
= OnValidationFailure(m_selected
, variant
);
2747 // Now prevent further validation failure messages
2750 EditorsValueWasNotModified();
2751 OnValidationFailureReset(m_selected
);
2754 else if ( valueIsPending
)
2756 DoPropertyChanged( m_selected
, flags
);
2757 EditorsValueWasNotModified();
2766 // -----------------------------------------------------------------------
2768 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
)
2771 // Runs all validation functionality.
2772 // Returns true if value passes all tests.
2775 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2777 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2779 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2784 // Adapt list to child values, if necessary
2785 wxVariant listValue
= pendingValue
;
2786 wxVariant
* pPendingValue
= &pendingValue
;
2787 wxVariant
* pList
= NULL
;
2789 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2790 // string value, then we need treat as it was changed instead
2791 // (or, in addition, as is the case with composite string parent).
2792 // This includes creating list variant for child values.
2794 wxPGProperty
* pwc
= p
->GetParent();
2795 wxPGProperty
* changedProperty
= p
;
2796 wxPGProperty
* baseChangedProperty
= changedProperty
;
2797 wxVariant bcpPendingList
;
2799 listValue
= pendingValue
;
2800 listValue
.SetName(p
->GetBaseName());
2803 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2805 wxVariantList tempList
;
2806 wxVariant
lv(tempList
, pwc
->GetBaseName());
2807 lv
.Append(listValue
);
2809 pPendingValue
= &listValue
;
2811 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2813 baseChangedProperty
= pwc
;
2814 bcpPendingList
= lv
;
2817 changedProperty
= pwc
;
2818 pwc
= pwc
->GetParent();
2822 wxPGProperty
* evtChangingProperty
= changedProperty
;
2824 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2826 value
= *pPendingValue
;
2830 // Convert list to child values
2831 pList
= pPendingValue
;
2832 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2835 wxVariant evtChangingValue
= value
;
2837 // FIXME: After proper ValueToString()s added, remove
2838 // this. It is just a temporary fix, as evt_changing
2839 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2840 // (unless it is selected, and textctrl editor is open).
2841 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2843 evtChangingProperty
= baseChangedProperty
;
2844 if ( evtChangingProperty
!= p
)
2846 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2850 evtChangingValue
= pendingValue
;
2854 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2856 if ( changedProperty
== m_selected
)
2858 wxASSERT( m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2859 evtChangingValue
= ((wxTextCtrl
*)m_wndEditor
)->GetValue();
2863 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2867 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2868 m_chgInfo_changedProperty
= changedProperty
;
2869 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2870 m_chgInfo_pendingValue
= value
;
2873 m_chgInfo_valueList
= *pList
;
2875 m_chgInfo_valueList
.MakeNull();
2877 // If changedProperty is not property which value was edited,
2878 // then call wxPGProperty::ValidateValue() for that as well.
2879 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2881 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2885 // SendEvent returns true if event was vetoed
2886 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2892 // -----------------------------------------------------------------------
2894 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2896 if ( !msg
.length() )
2900 if ( !wxPGGlobalVars
->m_offline
)
2902 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2905 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2908 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2911 pStatusBar
->SetStatusText(msg
);
2919 ::wxMessageBox(msg
, _T("Property Error"));
2922 // -----------------------------------------------------------------------
2924 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2926 int vfb
= m_validationInfo
.m_failureBehavior
;
2928 if ( vfb
& wxPG_VFB_BEEP
)
2931 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2932 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2934 wxASSERT_MSG( !property
->GetCell(0) && !property
->GetCell(1),
2935 wxT("Currently wxPG_VFB_MARK_CELL only works with properties with standard first two cells") );
2937 if ( !property
->GetCell(0) && !property
->GetCell(1) )
2939 wxColour vfbFg
= *wxWHITE
;
2940 wxColour vfbBg
= *wxRED
;
2941 property
->SetCell(0, new wxPGCell(property
->GetLabel(), wxNullBitmap
, vfbFg
, vfbBg
));
2942 property
->SetCell(1, new wxPGCell(property
->GetDisplayedString(), wxNullBitmap
, vfbFg
, vfbBg
));
2944 DrawItemAndChildren(property
);
2946 if ( property
== m_selected
)
2948 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2950 wxWindow
* editor
= GetEditorControl();
2953 editor
->SetForegroundColour(vfbFg
);
2954 editor
->SetBackgroundColour(vfbBg
);
2960 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2962 wxString msg
= m_validationInfo
.m_failureMessage
;
2964 if ( !msg
.length() )
2965 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2967 DoShowPropertyError(property
, msg
);
2970 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2973 // -----------------------------------------------------------------------
2975 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2977 int vfb
= m_validationInfo
.m_failureBehavior
;
2979 if ( vfb
& wxPG_VFB_MARK_CELL
)
2981 property
->SetCell(0, NULL
);
2982 property
->SetCell(1, NULL
);
2984 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2986 if ( property
== m_selected
&& GetEditorControl() )
2988 // Calling this will recreate the control, thus resetting its colour
2989 RefreshProperty(property
);
2993 DrawItemAndChildren(property
);
2998 // -----------------------------------------------------------------------
3000 // flags are same as with DoSelectProperty
3001 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
3003 if ( m_inDoPropertyChanged
)
3006 wxWindow
* editor
= GetEditorControl();
3008 m_pState
->m_anyModified
= 1;
3010 m_inDoPropertyChanged
= 1;
3012 // Maybe need to update control
3013 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
3015 // These values were calculated in PerformValidation()
3016 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
3017 wxVariant value
= m_chgInfo_pendingValue
;
3019 wxPGProperty
* topPaintedProperty
= changedProperty
;
3021 while ( !topPaintedProperty
->IsCategory() &&
3022 !topPaintedProperty
->IsRoot() )
3024 topPaintedProperty
= topPaintedProperty
->GetParent();
3027 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
3029 // Set as Modified (not if dragging just began)
3030 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
3032 p
->m_flags
|= wxPG_PROP_MODIFIED
;
3033 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3036 SetCurControlBoldFont();
3042 // Propagate updates to parent(s)
3044 wxPGProperty
* prevPwc
= NULL
;
3046 while ( prevPwc
!= topPaintedProperty
)
3048 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
3050 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3053 SetCurControlBoldFont();
3057 pwc
= pwc
->GetParent();
3060 // Draw the actual property
3061 DrawItemAndChildren( topPaintedProperty
);
3064 // If value was set by wxPGProperty::OnEvent, then update the editor
3066 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
3069 p
->GetEditorClass()->UpdateControl(p
, editor
);
3073 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3074 if ( m_wndEditor
) m_wndEditor
->Refresh();
3075 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
3080 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
3082 // If top parent has composite string value, then send to child parents,
3083 // starting from baseChangedProperty.
3084 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
3086 pwc
= m_chgInfo_baseChangedProperty
;
3088 while ( pwc
!= changedProperty
)
3090 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
3091 pwc
= pwc
->GetParent();
3095 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
3097 m_inDoPropertyChanged
= 0;
3102 // -----------------------------------------------------------------------
3104 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
3106 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3108 m_chgInfo_changedProperty
= NULL
;
3110 if ( PerformValidation(p
, newValue
) )
3112 DoPropertyChanged(p
);
3117 OnValidationFailure(p
, newValue
);
3123 // -----------------------------------------------------------------------
3125 // Runs wxValidator for the selected property
3126 bool wxPropertyGrid::DoEditorValidate()
3128 #if wxUSE_VALIDATORS
3129 // With traditional validator style, we dont need to more
3130 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3133 if ( m_iFlags
& wxPG_FL_VALIDATION_FAILED
)
3138 wxWindow
* wnd
= GetEditorControl();
3140 wxValidator
* validator
= m_selected
->GetValidator();
3141 if ( validator
&& wnd
)
3143 // Use TextCtrl of ODComboBox instead
3144 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3146 wnd
= ((wxOwnerDrawnComboBox
*)wnd
)->GetTextCtrl();
3152 validator
->SetWindow(wnd
);
3154 // Instead setting the flag after the failure, we set
3155 // it before checking and then clear afterwards if things
3156 // went fine. This trick is necessary since focus events
3157 // may be triggered while in Validate.
3158 m_iFlags
|= wxPG_FL_VALIDATION_FAILED
;
3159 if ( !validator
->Validate(this) )
3161 // If you dpm't want to display message multiple times per change,
3162 // comment the following line.
3163 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3166 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3172 // -----------------------------------------------------------------------
3174 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3176 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3177 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3179 wxWindow
* parent
= wnd
->GetParent();
3182 (parent
== m_canvas
||
3183 parent
->GetParent() == m_canvas
) )
3185 OnCustomEditorEvent((wxCommandEvent
&)event
);
3189 return wxPanel::ProcessEvent(event
);
3192 // -----------------------------------------------------------------------
3194 // NB: It may really not be wxCommandEvent - must check if necessary
3196 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3198 wxPGProperty
* selected
= m_selected
;
3201 // Somehow, event is handled after property has been deselected.
3202 // Possibly, but very rare.
3206 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3209 wxVariant
pendingValue(selected
->GetValueRef());
3210 wxWindow
* wnd
= GetEditorControl();
3212 bool wasUnspecified
= selected
->IsValueUnspecified();
3213 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3215 bool valueIsPending
= false;
3217 m_chgInfo_changedProperty
= NULL
;
3219 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3222 // Filter out excess wxTextCtrl modified events
3223 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3225 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3227 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3229 wxString newTcValue
= tc
->GetValue();
3230 if ( m_prevTcValue
== newTcValue
)
3233 m_prevTcValue
= newTcValue
;
3236 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3238 bool validationFailure
= false;
3239 bool buttonWasHandled
= false;
3242 // Try common button handling
3243 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3245 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3249 buttonWasHandled
= true;
3250 // Store as res2, as previously (and still currently alternatively)
3251 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3252 // in wxPGProperty::OnEvent().
3253 adapter
->ShowDialog( this, selected
);
3258 if ( !buttonWasHandled
)
3262 // First call editor class' event handler.
3263 const wxPGEditor
* editor
= selected
->GetEditorClass();
3265 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3267 // If changes, validate them
3268 if ( DoEditorValidate() )
3270 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3271 valueIsPending
= true;
3275 validationFailure
= true;
3280 // Then the property's custom handler (must be always called, unless
3281 // validation failed).
3282 if ( !validationFailure
)
3283 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3286 // SetValueInEvent(), as called in one of the functions referred above
3287 // overrides editor's value.
3288 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3290 valueIsPending
= true;
3291 pendingValue
= m_changeInEventValue
;
3292 selFlags
|= wxPG_SEL_DIALOGVAL
;
3295 if ( !validationFailure
&& valueIsPending
)
3296 if ( !PerformValidation(m_selected
, pendingValue
) )
3297 validationFailure
= true;
3299 if ( validationFailure
)
3301 OnValidationFailure(selected
, pendingValue
);
3303 else if ( valueIsPending
)
3305 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3307 DoPropertyChanged(selected
, selFlags
);
3308 EditorsValueWasNotModified();
3312 // No value after all
3314 // Let unhandled button click events go to the parent
3315 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3317 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3318 GetEventHandler()->AddPendingEvent(evt
);
3322 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3325 // -----------------------------------------------------------------------
3326 // wxPropertyGrid editor control helper methods
3327 // -----------------------------------------------------------------------
3329 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3331 int itemy
= p
->GetY2(m_lineHeight
);
3333 int cust_img_space
= 0;
3334 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3335 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3337 // TODO: If custom image detection changes from current, change this.
3338 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3340 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3341 int imwid
= p
->OnMeasureImage().x
;
3342 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3343 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3348 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3350 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3355 // -----------------------------------------------------------------------
3357 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3359 wxSize sz
= GetImageSize(p
, item
);
3360 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3361 wxPG_CUSTOM_IMAGE_SPACINGY
,
3366 // return size of custom paint image
3367 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3369 // If called with NULL property, then return default image
3370 // size for properties that use image.
3372 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3374 wxSize cis
= p
->OnMeasureImage(item
);
3376 int choiceCount
= p
->m_choices
.GetCount();
3377 int comVals
= p
->GetDisplayedCommonValueCount();
3378 if ( item
>= choiceCount
&& comVals
> 0 )
3380 unsigned int cvi
= item
-choiceCount
;
3381 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3383 else if ( item
>= 0 && choiceCount
== 0 )
3384 return wxSize(0, 0);
3389 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3394 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3401 // -----------------------------------------------------------------------
3403 // takes scrolling into account
3404 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3407 GetViewStart(&vx
,&vy
);
3408 vy
*=wxPG_PIXELS_PER_UNIT
;
3409 vx
*=wxPG_PIXELS_PER_UNIT
;
3412 ClientToScreen( px
, py
);
3415 // -----------------------------------------------------------------------
3417 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3420 GetViewStart(&pt2
.x
,&pt2
.y
);
3421 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3422 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3426 return m_pState
->HitTest(pt2
);
3429 // -----------------------------------------------------------------------
3431 // custom set cursor
3432 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3434 if ( type
== m_curcursor
&& !override
) return;
3436 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3438 if ( type
== wxCURSOR_SIZEWE
)
3439 cursor
= m_cursorSizeWE
;
3441 m_canvas
->SetCursor( *cursor
);
3446 // -----------------------------------------------------------------------
3447 // wxPropertyGrid property selection
3448 // -----------------------------------------------------------------------
3450 // Setups event handling for child control
3451 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
, int id
)
3453 if ( argWnd
== m_wndEditor
)
3455 this->Connect(id
, wxEVT_MOTION
,
3456 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
));
3457 this->Connect(id
, wxEVT_LEFT_UP
,
3458 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
));
3459 this->Connect(id
, wxEVT_LEFT_DOWN
,
3460 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
));
3461 this->Connect(id
, wxEVT_RIGHT_UP
,
3462 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
));
3463 this->Connect(id
, wxEVT_ENTER_WINDOW
,
3464 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3465 this->Connect(id
, wxEVT_LEAVE_WINDOW
,
3466 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3470 this->Connect(id
, wxEVT_NAVIGATION_KEY
,
3471 wxNavigationKeyEventHandler(wxPropertyGrid::OnNavigationKey
));
3474 this->Connect(id
, wxEVT_KEY_DOWN
,
3475 wxKeyEventHandler(wxPropertyGrid::OnChildKeyDown
));
3476 this->Connect(id
, wxEVT_KEY_UP
,
3477 wxKeyEventHandler(wxPropertyGrid::OnChildKeyUp
));
3478 this->Connect(id
, wxEVT_KILL_FOCUS
,
3479 wxFocusEventHandler(wxPropertyGrid::OnFocusEvent
));
3482 void wxPropertyGrid::FreeEditors()
3484 // Do not free editors immediately if processing events
3485 if ( !m_windowsToDelete
)
3486 m_windowsToDelete
= new wxArrayPtrVoid
;
3490 m_windowsToDelete
->push_back(m_wndEditor2
);
3491 m_wndEditor2
->Hide();
3492 m_wndEditor2
= (wxWindow
*) NULL
;
3497 m_windowsToDelete
->push_back(m_wndEditor
);
3498 m_wndEditor
->Hide();
3499 m_wndEditor
= (wxWindow
*) NULL
;
3503 // Call with NULL to de-select property
3504 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3506 wxPanel
* canvas
= GetPanel();
3510 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3511 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3513 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3516 if ( m_inDoSelectProperty
)
3519 m_inDoSelectProperty
= 1;
3521 wxPGProperty
* prev
= m_selected
;
3524 // Delete windows pending for deletion
3525 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3529 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3530 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3532 m_windowsToDelete
->clear();
3537 m_inDoSelectProperty
= 0;
3542 // If we are frozen, then just set the values.
3545 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3546 m_editorFocused
= 0;
3549 m_pState
->m_selected
= p
;
3551 // If frozen, always free controls. But don't worry, as Thaw will
3552 // recall SelectProperty to recreate them.
3555 // Prevent any further selection measures in this call
3556 p
= (wxPGProperty
*) NULL
;
3561 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3563 // Only set focus if not deselecting
3566 if ( flags
& wxPG_SEL_FOCUS
)
3570 m_wndEditor
->SetFocus();
3571 m_editorFocused
= 1;
3580 m_inDoSelectProperty
= 0;
3585 // First, deactivate previous
3589 OnValidationFailureReset(m_selected
);
3591 // Must double-check if this is an selected in case of forceswitch
3594 if ( !CommitChangesFromEditor(flags
) )
3596 // Validation has failed, so we can't exit the previous editor
3597 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3598 // _("Invalid Value"),wxOK|wxICON_ERROR);
3599 m_inDoSelectProperty
= 0;
3607 m_selected
= (wxPGProperty
*) NULL
;
3608 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3610 // We need to always fully refresh the grid here
3613 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3614 EditorsValueWasNotModified();
3617 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3620 // Then, activate the one given.
3623 int propY
= p
->GetY2(m_lineHeight
);
3625 int splitterX
= GetSplitterPosition();
3626 m_editorFocused
= 0;
3628 m_pState
->m_selected
= p
;
3629 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3631 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3633 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3635 // Do we need OnMeasureCalls?
3636 wxSize imsz
= p
->OnMeasureImage();
3639 // Only create editor for non-disabled non-caption
3640 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3642 // do this for non-caption items
3646 // Do we need to paint the custom image, if any?
3647 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3648 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3649 !p
->GetEditorClass()->CanContainCustomImage()
3651 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3653 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3654 wxPoint goodPos
= grect
.GetPosition();
3655 #if wxPG_CREATE_CONTROLS_HIDDEN
3656 int coord_adjust
= m_height
- goodPos
.y
;
3657 goodPos
.y
+= coord_adjust
;
3660 const wxPGEditor
* editor
= p
->GetEditorClass();
3661 wxCHECK_MSG(editor
, false,
3662 wxT("NULL editor class not allowed"));
3664 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3666 wxPGWindowList wndList
= editor
->CreateControls(this,
3671 m_wndEditor
= wndList
.m_primary
;
3672 m_wndEditor2
= wndList
.m_secondary
;
3674 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3675 // value is drawn as normal, and m_wndEditor2 is assumed
3676 // to be a right-aligned button that triggers a separate editor
3681 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3682 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3684 // Set validator, if any
3685 #if wxUSE_VALIDATORS
3686 if ( !(GetExtraStyle() & wxPG_EX_LEGACY_VALIDATORS
) )
3688 wxValidator
* validator
= p
->GetValidator();
3690 m_wndEditor
->SetValidator(*validator
);
3694 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3695 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3697 // If it has modified status, use bold font
3698 // (must be done before capturing m_ctrlXAdjust)
3699 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3700 SetCurControlBoldFont();
3703 // Fix TextCtrl indentation
3704 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3705 wxTextCtrl
* tc
= NULL
;
3706 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3707 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3709 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3711 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3714 // Store x relative to splitter (we'll need it).
3715 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3717 // Check if background clear is not necessary
3718 wxPoint pos
= m_wndEditor
->GetPosition();
3719 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3721 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3724 m_wndEditor
->SetSizeHints(3, 3);
3726 #if wxPG_CREATE_CONTROLS_HIDDEN
3727 m_wndEditor
->Show(false);
3728 m_wndEditor
->Freeze();
3730 goodPos
= m_wndEditor
->GetPosition();
3731 goodPos
.y
-= coord_adjust
;
3732 m_wndEditor
->Move( goodPos
);
3735 wxWindow
* primaryCtrl
= GetEditorControl();
3736 SetupChildEventHandling(primaryCtrl
, wxPG_SUBID1
);
3738 // Focus and select all (wxTextCtrl, wxComboBox etc)
3739 if ( flags
& wxPG_SEL_FOCUS
)
3741 primaryCtrl
->SetFocus();
3743 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3749 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3750 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3752 // Get proper id for wndSecondary
3753 m_wndSecId
= m_wndEditor2
->GetId();
3754 wxWindowList children
= m_wndEditor2
->GetChildren();
3755 wxWindowList::iterator node
= children
.begin();
3756 if ( node
!= children
.end() )
3757 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3759 m_wndEditor2
->SetSizeHints(3,3);
3761 #if wxPG_CREATE_CONTROLS_HIDDEN
3762 wxRect sec_rect
= m_wndEditor2
->GetRect();
3763 sec_rect
.y
-= coord_adjust
;
3765 // Fine tuning required to fix "oversized"
3766 // button disappearance bug.
3767 if ( sec_rect
.y
< 0 )
3769 sec_rect
.height
+= sec_rect
.y
;
3772 m_wndEditor2
->SetSize( sec_rect
);
3774 m_wndEditor2
->Show();
3776 SetupChildEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3778 // If no primary editor, focus to button to allow
3779 // it to interprete ENTER etc.
3780 // NOTE: Due to problems focusing away from it, this
3781 // has been disabled.
3783 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3784 m_wndEditor2->SetFocus();
3788 if ( flags
& wxPG_SEL_FOCUS
)
3789 m_editorFocused
= 1;
3794 // Make sure focus is in grid canvas (important for wxGTK, at least)
3798 EditorsValueWasNotModified();
3800 // If it's inside collapsed section, expand parent, scroll, etc.
3801 // Also, if it was partially visible, scroll it into view.
3802 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3807 #if wxPG_CREATE_CONTROLS_HIDDEN
3808 m_wndEditor
->Thaw();
3810 m_wndEditor
->Show(true);
3817 // Make sure focus is in grid canvas
3821 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3827 // Show help text in status bar.
3828 // (if found and grid not embedded in manager with help box and
3829 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3832 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3834 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3835 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3837 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3839 statusbar
= frame
->GetStatusBar();
3844 const wxString
* pHelpString
= (const wxString
*) NULL
;
3848 pHelpString
= &p
->GetHelpString();
3849 if ( pHelpString
->length() )
3851 // Set help box text.
3852 statusbar
->SetStatusText( *pHelpString
);
3853 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3857 if ( (!pHelpString
|| !pHelpString
->length()) &&
3858 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3860 // Clear help box - but only if it was written
3861 // by us at previous time.
3862 statusbar
->SetStatusText( m_emptyString
);
3863 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3869 m_inDoSelectProperty
= 0;
3871 // call wx event handler (here so that it also occurs on deselection)
3872 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3877 // -----------------------------------------------------------------------
3879 bool wxPropertyGrid::UnfocusEditor()
3881 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3884 if ( !CommitChangesFromEditor(0) )
3888 DrawItem(m_selected
);
3893 // -----------------------------------------------------------------------
3895 // This method is not inline because it called dozens of times
3896 // (i.e. two-arg function calls create smaller code size).
3897 bool wxPropertyGrid::DoClearSelection()
3899 return DoSelectProperty((wxPGProperty
*)NULL
);
3902 // -----------------------------------------------------------------------
3903 // wxPropertyGrid expand/collapse state
3904 // -----------------------------------------------------------------------
3906 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3908 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3910 // If active editor was inside collapsed section, then disable it
3911 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3913 if ( !ClearSelection() )
3917 // Store dont-center-splitter flag 'cause we need to temporarily set it
3918 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3919 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3921 bool res
= m_pState
->DoCollapse(pwc
);
3926 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3928 RecalculateVirtualSize();
3930 // Redraw etc. only if collapsed was visible.
3931 if (pwc
->IsVisible() &&
3933 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3935 // When item is collapsed so that scrollbar would move,
3936 // graphics mess is about (unless we redraw everything).
3941 // Clear dont-center-splitter flag if it wasn't set
3942 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3947 // -----------------------------------------------------------------------
3949 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3951 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3953 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3955 // Store dont-center-splitter flag 'cause we need to temporarily set it
3956 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3957 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3959 bool res
= m_pState
->DoExpand(pwc
);
3964 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3966 RecalculateVirtualSize();
3968 // Redraw etc. only if expanded was visible.
3969 if ( pwc
->IsVisible() && !m_frozen
&&
3970 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3974 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3977 DrawItems(pwc
, NULL
);
3982 // Clear dont-center-splitter flag if it wasn't set
3983 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3988 // -----------------------------------------------------------------------
3990 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3993 return m_pState
->DoHideProperty(p
, hide
, flags
);
3996 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3999 if ( !ClearSelection() )
4003 m_pState
->DoHideProperty(p
, hide
, flags
);
4005 RecalculateVirtualSize();
4012 // -----------------------------------------------------------------------
4013 // wxPropertyGrid size related methods
4014 // -----------------------------------------------------------------------
4016 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
4018 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
4022 // If virtual height was changed, then recalculate editor control position(s)
4023 if ( m_pState
->m_vhCalcPending
)
4024 CorrectEditorWidgetPosY();
4026 m_pState
->EnsureVirtualHeight();
4029 int by1
= m_pState
->GetVirtualHeight();
4030 int by2
= m_pState
->GetActualVirtualHeight();
4033 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
4034 wxASSERT_MSG( false,
4040 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4042 int x
= m_pState
->m_width
;
4043 int y
= m_pState
->m_virtualHeight
;
4046 GetClientSize(&width
,&height
);
4048 // Now adjust virtual size.
4049 SetVirtualSize(x
, y
);
4055 // Adjust scrollbars
4056 if ( HasVirtualWidth() )
4058 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4059 xPos
= GetScrollPos( wxHORIZONTAL
);
4062 if ( forceXPos
!= -1 )
4065 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4068 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4069 int yPos
= GetScrollPos( wxVERTICAL
);
4071 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4072 xAmount
, yAmount
, xPos
, yPos
, true );
4074 // Must re-get size now
4075 GetClientSize(&width
,&height
);
4077 if ( !HasVirtualWidth() )
4079 m_pState
->SetVirtualWidth(width
);
4086 m_canvas
->SetSize( x
, y
);
4088 m_pState
->CheckColumnWidths();
4091 CorrectEditorWidgetSizeX();
4093 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4096 // -----------------------------------------------------------------------
4098 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4100 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4104 GetClientSize(&width
,&height
);
4109 #if wxPG_DOUBLE_BUFFER
4110 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4112 int dblh
= (m_lineHeight
*2);
4113 if ( !m_doubleBuffer
)
4115 // Create double buffer bitmap to draw on, if none
4116 int w
= (width
>250)?width
:250;
4117 int h
= height
+ dblh
;
4119 m_doubleBuffer
= new wxBitmap( w
, h
);
4123 int w
= m_doubleBuffer
->GetWidth();
4124 int h
= m_doubleBuffer
->GetHeight();
4126 // Double buffer must be large enough
4127 if ( w
< width
|| h
< (height
+dblh
) )
4129 if ( w
< width
) w
= width
;
4130 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4131 delete m_doubleBuffer
;
4132 m_doubleBuffer
= new wxBitmap( w
, h
);
4139 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4140 m_ncWidth
= event
.GetSize().x
;
4144 if ( m_pState
->m_itemsAdded
)
4145 PrepareAfterItemsAdded();
4147 // Without this, virtual size (atleast under wxGTK) will be skewed
4148 RecalculateVirtualSize();
4154 // -----------------------------------------------------------------------
4156 void wxPropertyGrid::SetVirtualWidth( int width
)
4160 // Disable virtual width
4161 width
= GetClientSize().x
;
4162 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4166 // Enable virtual width
4167 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4169 m_pState
->SetVirtualWidth( width
);
4172 // -----------------------------------------------------------------------
4173 // wxPropertyGrid mouse event handling
4174 // -----------------------------------------------------------------------
4176 // selFlags uses same values DoSelectProperty's flags
4177 // Returns true if event was vetoed.
4178 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4180 // Send property grid event of specific type and with specific property
4181 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4182 evt
.SetPropertyGrid(this);
4183 evt
.SetEventObject(m_eventObject
);
4187 evt
.SetCanVeto(true);
4188 evt
.SetupValidationInfo();
4189 m_validationInfo
.m_pValue
= pValue
;
4191 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4193 evtHandler
->ProcessEvent(evt
);
4195 return evt
.WasVetoed();
4198 // -----------------------------------------------------------------------
4200 // Return false if should be skipped
4201 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4205 // Need to set focus?
4206 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4211 wxPropertyGridPageState
* state
= m_pState
;
4213 int splitterHitOffset
;
4214 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4216 wxPGProperty
* p
= DoGetItemAtY(y
);
4220 int depth
= (int)p
->GetDepth() - 1;
4222 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4224 if ( x
>= marginEnds
)
4228 if ( p
->IsCategory() )
4230 // This is category.
4231 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4233 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4235 // Expand, collapse, activate etc. if click on text or left of splitter.
4238 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4243 if ( !DoSelectProperty( p
) )
4246 // On double-click, expand/collapse.
4247 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4249 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4250 else DoExpand( p
, true );
4254 else if ( splitterHit
== -1 )
4257 unsigned int selFlag
= 0;
4258 if ( columnHit
== 1 )
4260 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4261 selFlag
= wxPG_SEL_FOCUS
;
4263 if ( !DoSelectProperty( p
, selFlag
) )
4266 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4268 if ( p
->GetChildCount() && !p
->IsCategory() )
4269 // On double-click, expand/collapse.
4270 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4272 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4273 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4274 else DoExpand( p
, true );
4281 // click on splitter
4282 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4284 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4286 // Double-clicking the splitter causes auto-centering
4287 CenterSplitter( true );
4289 else if ( m_dragStatus
== 0 )
4292 // Begin draggin the splitter
4296 // Changes must be committed here or the
4297 // value won't be drawn correctly
4298 if ( !CommitChangesFromEditor() )
4301 m_wndEditor
->Show ( false );
4304 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4306 m_canvas
->CaptureMouse();
4307 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4311 m_draggedSplitter
= splitterHit
;
4312 m_dragOffset
= splitterHitOffset
;
4314 wxClientDC
dc(m_canvas
);
4316 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4317 // Fixes button disappearance bug
4319 m_wndEditor2
->Show ( false );
4322 m_startingSplitterX
= x
- splitterHitOffset
;
4330 if ( p
->GetChildCount() )
4332 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4334 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4336 int y2
= y
% m_lineHeight
;
4337 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4339 // On click on expander button, expand/collapse
4340 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4341 DoCollapse( p
, true );
4343 DoExpand( p
, true );
4352 // -----------------------------------------------------------------------
4354 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4355 wxMouseEvent
& WXUNUSED(event
) )
4359 // Select property here as well
4360 wxPGProperty
* p
= m_propHover
;
4361 if ( p
!= m_selected
)
4362 DoSelectProperty( p
);
4364 // Send right click event.
4365 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4372 // -----------------------------------------------------------------------
4374 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4375 wxMouseEvent
& WXUNUSED(event
) )
4379 // Select property here as well
4380 wxPGProperty
* p
= m_propHover
;
4382 if ( p
!= m_selected
)
4383 DoSelectProperty( p
);
4385 // Send double-click event.
4386 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4393 // -----------------------------------------------------------------------
4395 #if wxPG_SUPPORT_TOOLTIPS
4397 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4399 if ( tipString
.length() )
4401 m_canvas
->SetToolTip(tipString
);
4405 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4406 m_canvas
->SetToolTip( m_emptyString
);
4408 m_canvas
->SetToolTip( NULL
);
4413 #endif // #if wxPG_SUPPORT_TOOLTIPS
4415 // -----------------------------------------------------------------------
4417 // Return false if should be skipped
4418 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4420 // Safety check (needed because mouse capturing may
4421 // otherwise freeze the control)
4422 if ( m_dragStatus
> 0 && !event
.Dragging() )
4424 HandleMouseUp(x
,y
,event
);
4427 wxPropertyGridPageState
* state
= m_pState
;
4429 int splitterHitOffset
;
4430 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4431 int splitterX
= x
- splitterHitOffset
;
4433 if ( m_dragStatus
> 0 )
4435 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4436 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4439 int newSplitterX
= x
- m_dragOffset
;
4440 int splitterX
= x
- splitterHitOffset
;
4442 // Splitter redraw required?
4443 if ( newSplitterX
!= splitterX
)
4446 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4447 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4448 state
->m_fSplitterX
= (float) newSplitterX
;
4451 CorrectEditorWidgetSizeX();
4465 int ih
= m_lineHeight
;
4468 #if wxPG_SUPPORT_TOOLTIPS
4469 wxPGProperty
* prevHover
= m_propHover
;
4470 unsigned char prevSide
= m_mouseSide
;
4472 int curPropHoverY
= y
- (y
% ih
);
4474 // On which item it hovers
4475 if ( ( !m_propHover
)
4477 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4480 // Mouse moves on another property
4482 m_propHover
= DoGetItemAtY(y
);
4483 m_propHoverY
= curPropHoverY
;
4486 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4489 #if wxPG_SUPPORT_TOOLTIPS
4490 // Store which side we are on
4492 if ( columnHit
== 1 )
4494 else if ( columnHit
== 0 )
4498 // If tooltips are enabled, show label or value as a tip
4499 // in case it doesn't otherwise show in full length.
4501 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4503 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4505 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4507 if ( m_propHover
&& !m_propHover
->IsCategory() )
4510 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4512 // Show help string as a tooltip
4513 wxString tipString
= m_propHover
->GetHelpString();
4515 SetToolTip(tipString
);
4519 // Show cropped value string as a tooltip
4523 if ( m_mouseSide
== 1 )
4525 tipString
= m_propHover
->m_label
;
4526 space
= splitterX
-m_marginWidth
-3;
4528 else if ( m_mouseSide
== 2 )
4530 tipString
= m_propHover
->GetDisplayedString();
4532 space
= m_width
- splitterX
;
4533 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4534 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4540 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4543 SetToolTip( tipString
);
4550 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4551 m_canvas
->SetToolTip( m_emptyString
);
4553 m_canvas
->SetToolTip( NULL
);
4564 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4565 m_canvas
->SetToolTip( m_emptyString
);
4567 m_canvas
->SetToolTip( NULL
);
4575 if ( splitterHit
== -1 ||
4577 HasFlag(wxPG_STATIC_SPLITTER
) )
4579 // hovering on something else
4580 if ( m_curcursor
!= wxCURSOR_ARROW
)
4581 CustomSetCursor( wxCURSOR_ARROW
);
4585 // Do not allow splitter cursor on caption items.
4586 // (also not if we were dragging and its started
4587 // outside the splitter region)
4590 !m_propHover
->IsCategory() &&
4594 // hovering on splitter
4596 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4597 // reliably detected.
4598 //if ( m_curcursor != wxCURSOR_SIZEWE )
4599 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4605 // hovering on something else
4606 if ( m_curcursor
!= wxCURSOR_ARROW
)
4607 CustomSetCursor( wxCURSOR_ARROW
);
4614 // -----------------------------------------------------------------------
4616 // Also handles Leaving event
4617 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4618 wxMouseEvent
&WXUNUSED(event
) )
4620 wxPropertyGridPageState
* state
= m_pState
;
4624 int splitterHitOffset
;
4625 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4627 // No event type check - basicly calling this method should
4628 // just stop dragging.
4629 // Left up after dragged?
4630 if ( m_dragStatus
>= 1 )
4633 // End Splitter Dragging
4635 // DO NOT ENABLE FOLLOWING LINE!
4636 // (it is only here as a reminder to not to do it)
4639 // Disable splitter auto-centering
4640 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4642 // This is necessary to return cursor
4643 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4645 m_canvas
->ReleaseMouse();
4646 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4649 // Set back the default cursor, if necessary
4650 if ( splitterHit
== -1 ||
4653 CustomSetCursor( wxCURSOR_ARROW
);
4658 // Control background needs to be cleared
4659 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4660 DrawItem( m_selected
);
4664 m_wndEditor
->Show ( true );
4667 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4668 // Fixes button disappearance bug
4670 m_wndEditor2
->Show ( true );
4673 // This clears the focus.
4674 m_editorFocused
= 0;
4680 // -----------------------------------------------------------------------
4682 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4684 int splitterX
= GetSplitterPosition();
4687 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4691 wxWindow
* wnd
= m_wndEditor
;
4693 // Hide popup on clicks
4694 if ( event
.GetEventType() != wxEVT_MOTION
)
4695 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4697 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4703 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4705 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4706 ux
>= (r
.x
+r
.width
) ||
4708 event
.m_y
>= (r
.y
+r
.height
)
4718 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4723 // -----------------------------------------------------------------------
4725 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4728 if ( OnMouseCommon( event
, &x
, &y
) )
4730 HandleMouseClick(x
,y
,event
);
4735 // -----------------------------------------------------------------------
4737 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4740 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4741 HandleMouseRightClick(x
,y
,event
);
4745 // -----------------------------------------------------------------------
4747 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4749 // Always run standard mouse-down handler as well
4750 OnMouseClick(event
);
4753 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4754 HandleMouseDoubleClick(x
,y
,event
);
4758 // -----------------------------------------------------------------------
4760 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4763 if ( OnMouseCommon( event
, &x
, &y
) )
4765 HandleMouseMove(x
,y
,event
);
4770 // -----------------------------------------------------------------------
4772 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4774 // Called when mouse moves in the empty space below the properties.
4775 CustomSetCursor( wxCURSOR_ARROW
);
4778 // -----------------------------------------------------------------------
4780 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4783 if ( OnMouseCommon( event
, &x
, &y
) )
4785 HandleMouseUp(x
,y
,event
);
4790 // -----------------------------------------------------------------------
4792 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4794 // This may get called from child control as well, so event's
4795 // mouse position cannot be relied on.
4797 if ( event
.Entering() )
4799 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4801 // TODO: Fix this (detect parent and only do
4802 // cursor trick if it is a manager).
4803 wxASSERT( GetParent() );
4804 GetParent()->SetCursor(wxNullCursor
);
4806 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4809 GetParent()->SetCursor(wxNullCursor
);
4811 else if ( event
.Leaving() )
4813 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4814 m_canvas
->SetCursor( wxNullCursor
);
4816 // Get real cursor position
4817 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4819 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4822 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4824 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4828 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4836 // -----------------------------------------------------------------------
4838 // Common code used by various OnMouseXXXChild methods.
4839 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4841 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4842 wxASSERT( topCtrlWnd
);
4844 event
.GetPosition(&x
,&y
);
4846 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4848 int splitterX
= GetSplitterPosition();
4850 wxRect r
= topCtrlWnd
->GetRect();
4851 if ( !m_dragStatus
&&
4852 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4853 y
>= 0 && y
< r
.height \
4856 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4861 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4868 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4871 if ( OnMouseChildCommon(event
,&x
,&y
) )
4873 bool res
= HandleMouseClick(x
,y
,event
);
4874 if ( !res
) event
.Skip();
4878 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4881 wxASSERT( m_wndEditor
);
4882 // These coords may not be exact (about +-2),
4883 // but that should not matter (right click is about item, not position).
4884 wxPoint pt
= m_wndEditor
->GetPosition();
4885 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4886 wxASSERT( m_selected
);
4887 m_propHover
= m_selected
;
4888 bool res
= HandleMouseRightClick(x
,y
,event
);
4889 if ( !res
) event
.Skip();
4892 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4895 if ( OnMouseChildCommon(event
,&x
,&y
) )
4897 bool res
= HandleMouseMove(x
,y
,event
);
4898 if ( !res
) event
.Skip();
4902 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4905 if ( OnMouseChildCommon(event
,&x
,&y
) )
4907 bool res
= HandleMouseUp(x
,y
,event
);
4908 if ( !res
) event
.Skip();
4912 // -----------------------------------------------------------------------
4913 // wxPropertyGrid keyboard event handling
4914 // -----------------------------------------------------------------------
4916 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4918 wxNavigationKeyEvent evt
;
4919 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4920 (dir
?wxNavigationKeyEvent::IsForward
:
4921 wxNavigationKeyEvent::IsBackward
));
4922 evt
.SetEventObject(this);
4923 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4927 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4929 // Translates wxKeyEvent to wxPG_ACTION_XXX
4931 int keycode
= event
.GetKeyCode();
4932 int modifiers
= event
.GetModifiers();
4934 wxASSERT( !(modifiers
&~(0xFFFF)) );
4936 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4938 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4940 if ( it
== m_actionTriggers
.end() )
4945 int second
= (it
->second
>>16) & 0xFFFF;
4949 return (it
->second
& 0xFFFF);
4952 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4954 wxASSERT( !(modifiers
&~(0xFFFF)) );
4956 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4958 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4960 if ( it
!= m_actionTriggers
.end() )
4962 // This key combination is already used
4964 // Can add secondary?
4965 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4966 wxT("You can only add up to two separate actions per key combination.") );
4968 action
= it
->second
| (action
<<16);
4971 m_actionTriggers
[hashMapKey
] = action
;
4974 void wxPropertyGrid::ClearActionTriggers( int action
)
4976 wxPGHashMapI2I::iterator it
;
4978 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4980 if ( it
->second
== action
)
4982 m_actionTriggers
.erase(it
);
4987 static void CopyTextToClipboard( const wxString
& text
)
4989 if ( wxTheClipboard
->Open() )
4991 // This data objects are held by the clipboard,
4992 // so do not delete them in the app.
4993 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
4994 wxTheClipboard
->Close();
4998 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
5001 // Handles key event when editor control is not focused.
5004 wxASSERT( !m_frozen
);
5008 // Travelsal between items, collapsing/expanding, etc.
5009 int keycode
= event
.GetKeyCode();
5011 if ( keycode
== WXK_TAB
)
5013 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
5017 // Ignore Alt and Control when they are down alone
5018 if ( keycode
== WXK_ALT
||
5019 keycode
== WXK_CONTROL
)
5026 int action
= KeyEventToActions(event
, &secondAction
);
5032 if ( ButtonTriggerKeyTest(event
) )
5035 wxPGProperty
* p
= m_selected
;
5037 if ( action
== wxPG_ACTION_COPY
)
5039 CopyTextToClipboard(p
->GetDisplayedString());
5043 // Travel and expand/collapse
5046 if ( p
->GetChildCount() &&
5047 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5050 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5052 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5055 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5057 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5064 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5068 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5079 if ( selectDir
>= -1 )
5081 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5083 DoSelectProperty(p
);
5089 // If nothing was selected, select the first item now
5090 // (or navigate out of tab).
5091 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5093 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5094 if ( p
) DoSelectProperty(p
);
5099 // -----------------------------------------------------------------------
5101 // Potentially handles a keyboard event for editor controls.
5102 // Returns false if event should *not* be skipped (on true it can
5103 // be optionally skipped).
5104 // Basicly, false means that SelectProperty was called (or was about
5105 // to be called, if canDestroy was false).
5106 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5110 if ( !m_selected
|| !m_wndEditor
)
5115 int action
= KeyEventToAction(event
);
5118 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5121 // Esc cancels any changes
5122 if ( IsEditorsValueModified() )
5124 EditorsValueWasNotModified();
5126 // Update the control as well
5127 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5129 m_selected
->GetDisplayedString() );
5132 OnValidationFailureReset(m_selected
);
5138 else if ( action
== wxPG_ACTION_COPY
)
5140 // NB: There is some problem with getting native cut-copy-paste keys to go through
5141 // for embedded editor wxTextCtrl. This is why we emulate.
5143 wxTextCtrl
* tc
= GetEditorTextCtrl();
5146 wxString sel
= tc
->GetStringSelection();
5148 CopyTextToClipboard(sel
);
5152 CopyTextToClipboard(m_selected
->GetDisplayedString());
5155 else if ( action
== wxPG_ACTION_CUT
)
5157 wxTextCtrl
* tc
= GetEditorTextCtrl();
5161 tc
->GetSelection(&from
, &to
);
5164 CopyTextToClipboard(tc
->GetStringSelection());
5165 tc
->Remove(from
, to
);
5169 else if ( action
== wxPG_ACTION_PASTE
)
5171 wxTextCtrl
* tc
= GetEditorTextCtrl();
5174 if (wxTheClipboard
->Open())
5176 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5178 wxTextDataObject data
;
5179 wxTheClipboard
->GetData( data
);
5181 tc
->GetSelection(&from
, &to
);
5184 tc
->Remove(from
, to
);
5185 tc
->WriteText(data
.GetText());
5189 tc
->WriteText(data
.GetText());
5192 wxTheClipboard
->Close();
5200 // -----------------------------------------------------------------------
5202 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5206 // Events to editor controls should get relayed here.
5208 wxWindow
* focused
= wxWindow::FindFocus();
5210 wxWindow
* primaryCtrl
= GetEditorControl();
5213 (focused
==primaryCtrl
5214 || m_editorFocused
) )
5216 // Child key must be processed here, since it can
5217 // destroy the control which is referred by its own
5219 HandleChildKey( event
);
5222 HandleKeyEvent( event
);
5225 // -----------------------------------------------------------------------
5227 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5229 m_keyComboConsumed
= 0;
5234 // -----------------------------------------------------------------------
5236 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5238 // Ignore events that occur very close to focus set
5239 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5241 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5246 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5248 int dir
= event
.GetDirection()?1:-1;
5252 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5254 wxWindow
* focused
= wxWindow::FindFocus();
5256 wxWindow
* wndToCheck
= GetEditorControl();
5258 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5259 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5261 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5262 if ( comboTextCtrl
)
5263 wndToCheck
= comboTextCtrl
;
5267 // Because of problems navigating from wxButton, do not go to it.
5270 // No primary, use secondary
5271 wndToCheck = m_wndEditor2;
5273 // If it has editor button, focus to it after the primary editor.
5274 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5275 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5276 // have somewhat debugged in window.cpp itself).
5277 else if ( focused == wndToCheck &&
5279 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5281 wndToCheck = m_wndEditor2;
5282 wxLogDebug(wxT("Exp1"));
5286 if ( focused
!= wndToCheck
&&
5289 wndToCheck
->SetFocus();
5291 // Select all text in wxTextCtrl etc.
5292 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5293 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5295 m_editorFocused
= 1;
5302 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5306 // This allows preventing NavigateOut to occur
5307 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5316 // -----------------------------------------------------------------------
5318 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5320 int keycode
= event
.GetKeyCode();
5322 // Does the keycode trigger button?
5323 if ( keycode
== m_pushButKeyCode
&&
5325 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5326 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5328 m_keyComboConsumed
= 1;
5330 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5331 GetEventHandler()->AddPendingEvent(evt
);
5338 // -----------------------------------------------------------------------
5340 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5342 int keycode
= event
.GetKeyCode();
5344 // Ignore Alt and Control when they are down alone
5345 if ( keycode
== WXK_ALT
||
5346 keycode
== WXK_CONTROL
)
5352 if ( ButtonTriggerKeyTest(event
) )
5355 if ( HandleChildKey(event
) == true )
5358 GetEventHandler()->AddPendingEvent(event
);
5361 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5363 m_keyComboConsumed
= 0;
5365 GetEventHandler()->AddPendingEvent(event
);
5370 // -----------------------------------------------------------------------
5371 // wxPropertyGrid miscellaneous event handling
5372 // -----------------------------------------------------------------------
5374 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5377 // Check if the focus is in this control or one of its children
5378 wxWindow
* newFocused
= wxWindow::FindFocus();
5380 if ( newFocused
!= m_curFocused
)
5381 HandleFocusChange( newFocused
);
5384 // Called by focus event handlers. newFocused is the window that becomes focused.
5385 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5387 unsigned int oldFlags
= m_iFlags
;
5389 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5391 wxWindow
* parent
= newFocused
;
5393 // This must be one of nextFocus' parents.
5396 // Use m_eventObject, which is either wxPropertyGrid or
5397 // wxPropertyGridManager, as appropriate.
5398 if ( parent
== m_eventObject
)
5400 m_iFlags
|= wxPG_FL_FOCUSED
;
5403 parent
= parent
->GetParent();
5406 m_curFocused
= newFocused
;
5408 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5409 (oldFlags
& wxPG_FL_FOCUSED
) )
5411 // On each focus kill, mark the next nav key event
5412 // to be ignored (can't do on set focus since the
5413 // event would occur before it).
5414 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5416 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5418 // Need to store changed value
5419 CommitChangesFromEditor();
5425 // Preliminary code for tab-order respecting
5426 // tab-traversal (but should be moved to
5429 wxWindow* prevFocus = event.GetWindow();
5430 wxWindow* useThis = this;
5431 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5432 useThis = GetParent();
5435 prevFocus->GetParent() == useThis->GetParent() )
5437 wxList& children = useThis->GetParent()->GetChildren();
5439 wxNode* node = children.Find(prevFocus);
5441 if ( node->GetNext() &&
5442 useThis == node->GetNext()->GetData() )
5443 DoSelectProperty(GetFirst());
5444 else if ( node->GetPrevious () &&
5445 useThis == node->GetPrevious()->GetData() )
5446 DoSelectProperty(GetLastProperty());
5451 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5455 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5456 DrawItem( m_selected
);
5460 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5462 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5463 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5464 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5465 //else if ( event.GetWindow() )
5467 HandleFocusChange(event
.GetWindow());
5472 // -----------------------------------------------------------------------
5474 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5476 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5479 // event.Skip() being commented out is aworkaround for bug reported
5480 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5484 // -----------------------------------------------------------------------
5486 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5488 m_iFlags
|= wxPG_FL_SCROLLED
;
5493 // -----------------------------------------------------------------------
5495 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5497 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5499 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5503 // -----------------------------------------------------------------------
5504 // Property editor related functions
5505 // -----------------------------------------------------------------------
5507 // noDefCheck = true prevents infinite recursion.
5508 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5511 wxASSERT( editorClass
);
5513 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5514 RegisterDefaultEditors();
5516 wxString name
= editorClass
->GetName();
5518 // Existing editor under this name?
5519 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5521 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5522 (wxPGEditor
*) vt_it
->second
,
5523 "Editor with given name was already registered" );
5525 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5530 // Registers all default editor classes
5531 void wxPropertyGrid::RegisterDefaultEditors()
5533 wxPGRegisterDefaultEditorClass( TextCtrl
);
5534 wxPGRegisterDefaultEditorClass( Choice
);
5535 wxPGRegisterDefaultEditorClass( ComboBox
);
5536 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5537 #if wxPG_INCLUDE_CHECKBOX
5538 wxPGRegisterDefaultEditorClass( CheckBox
);
5540 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5542 // Register SpinCtrl etc. editors before use
5543 RegisterAdditionalEditors();
5546 // -----------------------------------------------------------------------
5547 // wxPGStringTokenizer
5548 // Needed to handle C-style string lists (e.g. "str1" "str2")
5549 // -----------------------------------------------------------------------
5551 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5552 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5556 wxPGStringTokenizer::~wxPGStringTokenizer()
5560 bool wxPGStringTokenizer::HasMoreTokens()
5562 const wxString
& str
= *m_str
;
5564 wxString::const_iterator i
= m_curPos
;
5566 wxUniChar delim
= m_delimeter
;
5568 wxUniChar prev_a
= wxT('\0');
5570 bool inToken
= false;
5572 while ( i
!= str
.end() )
5581 m_readyToken
.clear();
5586 if ( prev_a
!= wxT('\\') )
5590 if ( a
!= wxT('\\') )
5610 m_curPos
= str
.end();
5618 wxString
wxPGStringTokenizer::GetNextToken()
5620 return m_readyToken
;
5623 // -----------------------------------------------------------------------
5625 // -----------------------------------------------------------------------
5627 wxPGChoiceEntry::wxPGChoiceEntry()
5628 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5632 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5633 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5634 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5638 // -----------------------------------------------------------------------
5640 // -----------------------------------------------------------------------
5642 wxPGChoicesData::wxPGChoicesData()
5647 wxPGChoicesData::~wxPGChoicesData()
5652 void wxPGChoicesData::Clear()
5656 for ( i
=0; i
<m_items
.size(); i
++ )
5668 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5670 wxASSERT( m_items
.size() == 0 );
5674 for ( i
=0; i
<data
->GetCount(); i
++ )
5675 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5678 // -----------------------------------------------------------------------
5680 // -----------------------------------------------------------------------
5682 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5686 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5687 m_data
->Insert( -1, p
);
5691 // -----------------------------------------------------------------------
5693 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5697 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5698 p
->SetBitmap(bitmap
);
5699 m_data
->Insert( -1, p
);
5703 // -----------------------------------------------------------------------
5705 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5709 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5710 m_data
->Insert(index
, p
);
5714 // -----------------------------------------------------------------------
5716 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5720 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5721 m_data
->Insert( index
, p
);
5725 // -----------------------------------------------------------------------
5727 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5733 while ( index
< GetCount() )
5735 int cmpRes
= GetLabel(index
).Cmp(label
);
5741 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5742 m_data
->Insert( index
, p
);
5746 // -----------------------------------------------------------------------
5748 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5752 unsigned int itemcount
= 0;
5753 const wxChar
** p
= &labels
[0];
5754 while ( *p
) { p
++; itemcount
++; }
5757 for ( i
= 0; i
< itemcount
; i
++ )
5759 int value
= wxPG_INVALID_VALUE
;
5762 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5766 // -----------------------------------------------------------------------
5768 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5773 unsigned int itemcount
= arr
.size();
5775 for ( i
= 0; i
< itemcount
; i
++ )
5777 int value
= wxPG_INVALID_VALUE
;
5780 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5784 // -----------------------------------------------------------------------
5786 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5791 unsigned int itemcount
= arr
.size();
5793 for ( i
= 0; i
< itemcount
; i
++ )
5795 int value
= wxPG_INVALID_VALUE
;
5796 if ( &arrint
&& arrint
.size() )
5798 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5802 // -----------------------------------------------------------------------
5804 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5806 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5808 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5809 delete m_data
->Item(i
);
5810 m_data
->m_items
.RemoveAt(nIndex
, count
);
5813 // -----------------------------------------------------------------------
5815 int wxPGChoices::Index( const wxString
& str
) const
5820 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5822 if ( m_data
->Item(i
)->GetText() == str
)
5829 // -----------------------------------------------------------------------
5831 int wxPGChoices::Index( int val
) const
5836 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5838 if ( m_data
->Item(i
)->GetValue() == val
)
5845 // -----------------------------------------------------------------------
5847 wxArrayString
wxPGChoices::GetLabels() const
5852 if ( this && IsOk() )
5853 for ( i
=0; i
<GetCount(); i
++ )
5854 arr
.push_back(GetLabel(i
));
5859 // -----------------------------------------------------------------------
5861 bool wxPGChoices::HasValues() const
5866 // -----------------------------------------------------------------------
5868 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5875 for ( i
=0; i
< strings
.size(); i
++ )
5877 int index
= Index(strings
[i
]);
5879 arr
.Add(GetValue(index
));
5881 arr
.Add(wxPG_INVALID_VALUE
);
5888 // -----------------------------------------------------------------------
5890 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5891 wxArrayString
* unmatched
) const
5898 for ( i
=0; i
< strings
.size(); i
++ )
5900 const wxString
& str
= strings
[i
];
5901 int index
= Index(str
);
5904 else if ( unmatched
)
5905 unmatched
->Add(str
);
5912 // -----------------------------------------------------------------------
5914 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5918 if ( data
!= wxPGChoicesEmptyData
)
5925 // -----------------------------------------------------------------------
5927 void wxPGChoices::Init()
5929 m_data
= wxPGChoicesEmptyData
;
5932 // -----------------------------------------------------------------------
5934 void wxPGChoices::Free()
5936 if ( m_data
!= wxPGChoicesEmptyData
)
5939 m_data
= wxPGChoicesEmptyData
;
5943 // -----------------------------------------------------------------------
5944 // wxPropertyGridEvent
5945 // -----------------------------------------------------------------------
5947 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5950 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5951 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5952 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5953 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5954 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5955 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5956 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5957 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5958 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5961 // -----------------------------------------------------------------------
5963 void wxPropertyGridEvent::Init()
5965 m_validationInfo
= NULL
;
5967 m_wasVetoed
= false;
5970 // -----------------------------------------------------------------------
5972 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5973 : wxCommandEvent(commandType
,id
)
5979 // -----------------------------------------------------------------------
5981 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5982 : wxCommandEvent(event
)
5984 m_eventType
= event
.GetEventType();
5985 m_eventObject
= event
.m_eventObject
;
5987 m_property
= event
.m_property
;
5988 m_validationInfo
= event
.m_validationInfo
;
5989 m_canVeto
= event
.m_canVeto
;
5990 m_wasVetoed
= event
.m_wasVetoed
;
5993 // -----------------------------------------------------------------------
5995 wxPropertyGridEvent::~wxPropertyGridEvent()
5999 // -----------------------------------------------------------------------
6001 wxEvent
* wxPropertyGridEvent::Clone() const
6003 return new wxPropertyGridEvent( *this );
6006 // -----------------------------------------------------------------------
6007 // wxPropertyGridPopulator
6008 // -----------------------------------------------------------------------
6010 wxPropertyGridPopulator::wxPropertyGridPopulator()
6014 wxPGGlobalVars
->m_offline
++;
6017 // -----------------------------------------------------------------------
6019 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
6022 m_propHierarchy
.clear();
6025 // -----------------------------------------------------------------------
6027 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
6033 // -----------------------------------------------------------------------
6035 wxPropertyGridPopulator::~wxPropertyGridPopulator()
6038 // Free unused sets of choices
6039 wxPGHashMapS2P::iterator it
;
6041 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
6043 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6050 m_pg
->GetPanel()->Refresh();
6052 wxPGGlobalVars
->m_offline
--;
6055 // -----------------------------------------------------------------------
6057 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6058 const wxString
& propLabel
,
6059 const wxString
& propName
,
6060 const wxString
* propValue
,
6061 wxPGChoices
* pChoices
)
6063 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6064 wxPGProperty
* parent
= GetCurParent();
6066 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6068 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6072 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6074 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6078 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6080 property
->SetLabel(propLabel
);
6081 property
->DoSetName(propName
);
6083 if ( pChoices
&& pChoices
->IsOk() )
6084 property
->SetChoices(*pChoices
);
6086 m_state
->DoInsert(parent
, -1, property
);
6089 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6094 // -----------------------------------------------------------------------
6096 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6098 m_propHierarchy
.push_back(property
);
6099 DoScanForChildren();
6100 m_propHierarchy
.pop_back();
6103 // -----------------------------------------------------------------------
6105 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6106 const wxString
& idString
)
6108 wxPGChoices choices
;
6111 if ( choicesString
[0] == wxT('@') )
6113 wxString ids
= choicesString
.substr(1);
6114 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6115 if ( it
== m_dictIdChoices
.end() )
6116 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6118 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6123 if ( idString
.length() )
6125 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6126 if ( it
!= m_dictIdChoices
.end() )
6128 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6135 // Parse choices string
6136 wxString::const_iterator it
= choicesString
.begin();
6140 bool labelValid
= false;
6142 for ( ; it
!= choicesString
.end(); it
++ )
6148 if ( c
== wxT('"') )
6153 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6154 choices
.Add(label
, l
);
6157 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6162 else if ( c
== wxT('=') )
6169 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6176 if ( c
== wxT('"') )
6189 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6190 choices
.Add(label
, l
);
6193 if ( !choices
.IsOk() )
6195 choices
.EnsureData();
6199 if ( idString
.length() )
6200 m_dictIdChoices
[idString
] = choices
.GetData();
6207 // -----------------------------------------------------------------------
6209 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6211 if ( s
.Last() == wxT('%') )
6213 wxString s2
= s
.substr(0,s
.length()-1);
6215 if ( s2
.ToLong(&val
, 10) )
6217 *pval
= (val
*max
)/100;
6223 return s
.ToLong(pval
, 10);
6226 // -----------------------------------------------------------------------
6228 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6229 const wxString
& type
,
6230 const wxString
& value
)
6232 int l
= m_propHierarchy
.size();
6236 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6237 wxString valuel
= value
.Lower();
6240 if ( type
.length() == 0 )
6245 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6247 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6249 else if ( value
.ToLong(&v
, 0) )
6256 if ( type
== wxT("string") )
6260 else if ( type
== wxT("int") )
6263 value
.ToLong(&v
, 0);
6266 else if ( type
== wxT("bool") )
6268 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6275 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6280 p
->SetAttribute( name
, variant
);
6285 // -----------------------------------------------------------------------
6287 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6289 wxLogError(_("Error in resource: %s"),msg
.c_str());
6292 // -----------------------------------------------------------------------
6294 #endif // wxUSE_PROPGRID