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()
3131 // -----------------------------------------------------------------------
3133 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
3135 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
3136 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
3138 wxWindow
* parent
= wnd
->GetParent();
3141 (parent
== m_canvas
||
3142 parent
->GetParent() == m_canvas
) )
3144 OnCustomEditorEvent((wxCommandEvent
&)event
);
3148 return wxPanel::ProcessEvent(event
);
3151 // -----------------------------------------------------------------------
3153 // NB: It may really not be wxCommandEvent - must check if necessary
3155 void wxPropertyGrid::OnCustomEditorEvent( wxCommandEvent
&event
)
3157 wxPGProperty
* selected
= m_selected
;
3160 // Somehow, event is handled after property has been deselected.
3161 // Possibly, but very rare.
3165 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
3168 wxVariant
pendingValue(selected
->GetValueRef());
3169 wxWindow
* wnd
= GetEditorControl();
3171 bool wasUnspecified
= selected
->IsValueUnspecified();
3172 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
3174 bool valueIsPending
= false;
3176 m_chgInfo_changedProperty
= NULL
;
3178 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3181 // Filter out excess wxTextCtrl modified events
3182 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3184 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3186 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3188 wxString newTcValue
= tc
->GetValue();
3189 if ( m_prevTcValue
== newTcValue
)
3192 m_prevTcValue
= newTcValue
;
3195 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3197 bool validationFailure
= false;
3198 bool buttonWasHandled
= false;
3201 // Try common button handling
3202 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3204 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3208 buttonWasHandled
= true;
3209 // Store as res2, as previously (and still currently alternatively)
3210 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3211 // in wxPGProperty::OnEvent().
3212 adapter
->ShowDialog( this, selected
);
3217 if ( !buttonWasHandled
)
3221 // First call editor class' event handler.
3222 const wxPGEditor
* editor
= selected
->GetEditorClass();
3224 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3226 // If changes, validate them
3227 if ( DoEditorValidate() )
3229 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3230 valueIsPending
= true;
3234 validationFailure
= true;
3239 // Then the property's custom handler (must be always called, unless
3240 // validation failed).
3241 if ( !validationFailure
)
3242 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3245 // SetValueInEvent(), as called in one of the functions referred above
3246 // overrides editor's value.
3247 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3249 valueIsPending
= true;
3250 pendingValue
= m_changeInEventValue
;
3251 selFlags
|= wxPG_SEL_DIALOGVAL
;
3254 if ( !validationFailure
&& valueIsPending
)
3255 if ( !PerformValidation(m_selected
, pendingValue
) )
3256 validationFailure
= true;
3258 if ( validationFailure
)
3260 OnValidationFailure(selected
, pendingValue
);
3262 else if ( valueIsPending
)
3264 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3266 DoPropertyChanged(selected
, selFlags
);
3267 EditorsValueWasNotModified();
3271 // No value after all
3273 // Let unhandled button click events go to the parent
3274 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3276 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3277 GetEventHandler()->AddPendingEvent(evt
);
3281 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3284 // -----------------------------------------------------------------------
3285 // wxPropertyGrid editor control helper methods
3286 // -----------------------------------------------------------------------
3288 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3290 int itemy
= p
->GetY2(m_lineHeight
);
3292 int cust_img_space
= 0;
3293 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3294 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3296 // TODO: If custom image detection changes from current, change this.
3297 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3299 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3300 int imwid
= p
->OnMeasureImage().x
;
3301 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3302 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3307 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3309 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3314 // -----------------------------------------------------------------------
3316 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3318 wxSize sz
= GetImageSize(p
, item
);
3319 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3320 wxPG_CUSTOM_IMAGE_SPACINGY
,
3325 // return size of custom paint image
3326 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3328 // If called with NULL property, then return default image
3329 // size for properties that use image.
3331 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3333 wxSize cis
= p
->OnMeasureImage(item
);
3335 int choiceCount
= p
->m_choices
.GetCount();
3336 int comVals
= p
->GetDisplayedCommonValueCount();
3337 if ( item
>= choiceCount
&& comVals
> 0 )
3339 unsigned int cvi
= item
-choiceCount
;
3340 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3342 else if ( item
>= 0 && choiceCount
== 0 )
3343 return wxSize(0, 0);
3348 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3353 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3360 // -----------------------------------------------------------------------
3362 // takes scrolling into account
3363 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3366 GetViewStart(&vx
,&vy
);
3367 vy
*=wxPG_PIXELS_PER_UNIT
;
3368 vx
*=wxPG_PIXELS_PER_UNIT
;
3371 ClientToScreen( px
, py
);
3374 // -----------------------------------------------------------------------
3376 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3379 GetViewStart(&pt2
.x
,&pt2
.y
);
3380 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3381 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3385 return m_pState
->HitTest(pt2
);
3388 // -----------------------------------------------------------------------
3390 // custom set cursor
3391 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3393 if ( type
== m_curcursor
&& !override
) return;
3395 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3397 if ( type
== wxCURSOR_SIZEWE
)
3398 cursor
= m_cursorSizeWE
;
3400 m_canvas
->SetCursor( *cursor
);
3405 // -----------------------------------------------------------------------
3406 // wxPropertyGrid property selection
3407 // -----------------------------------------------------------------------
3409 // Setups event handling for child control
3410 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
, int id
)
3412 if ( argWnd
== m_wndEditor
)
3414 this->Connect(id
, wxEVT_MOTION
,
3415 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
));
3416 this->Connect(id
, wxEVT_LEFT_UP
,
3417 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
));
3418 this->Connect(id
, wxEVT_LEFT_DOWN
,
3419 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
));
3420 this->Connect(id
, wxEVT_RIGHT_UP
,
3421 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
));
3422 this->Connect(id
, wxEVT_ENTER_WINDOW
,
3423 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3424 this->Connect(id
, wxEVT_LEAVE_WINDOW
,
3425 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
));
3429 this->Connect(id
, wxEVT_NAVIGATION_KEY
,
3430 wxNavigationKeyEventHandler(wxPropertyGrid::OnNavigationKey
));
3433 this->Connect(id
, wxEVT_KEY_DOWN
,
3434 wxKeyEventHandler(wxPropertyGrid::OnChildKeyDown
));
3435 this->Connect(id
, wxEVT_KEY_UP
,
3436 wxKeyEventHandler(wxPropertyGrid::OnChildKeyUp
));
3437 this->Connect(id
, wxEVT_KILL_FOCUS
,
3438 wxFocusEventHandler(wxPropertyGrid::OnFocusEvent
));
3441 void wxPropertyGrid::FreeEditors()
3443 // Do not free editors immediately if processing events
3444 if ( !m_windowsToDelete
)
3445 m_windowsToDelete
= new wxArrayPtrVoid
;
3449 m_windowsToDelete
->push_back(m_wndEditor2
);
3450 m_wndEditor2
->Hide();
3451 m_wndEditor2
= (wxWindow
*) NULL
;
3456 m_windowsToDelete
->push_back(m_wndEditor
);
3457 m_wndEditor
->Hide();
3458 m_wndEditor
= (wxWindow
*) NULL
;
3462 // Call with NULL to de-select property
3463 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3465 wxPanel
* canvas
= GetPanel();
3469 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3470 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3472 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3475 if ( m_inDoSelectProperty
)
3478 m_inDoSelectProperty
= 1;
3480 wxPGProperty
* prev
= m_selected
;
3483 // Delete windows pending for deletion
3484 if ( m_windowsToDelete
&& !m_inDoPropertyChanged
&& m_windowsToDelete
->size() )
3488 for ( i
=0; i
<m_windowsToDelete
->size(); i
++ )
3489 delete ((wxWindow
*)((*m_windowsToDelete
)[i
]));
3491 m_windowsToDelete
->clear();
3496 m_inDoSelectProperty
= 0;
3501 // If we are frozen, then just set the values.
3504 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3505 m_editorFocused
= 0;
3508 m_pState
->m_selected
= p
;
3510 // If frozen, always free controls. But don't worry, as Thaw will
3511 // recall SelectProperty to recreate them.
3514 // Prevent any further selection measures in this call
3515 p
= (wxPGProperty
*) NULL
;
3520 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3522 // Only set focus if not deselecting
3525 if ( flags
& wxPG_SEL_FOCUS
)
3529 m_wndEditor
->SetFocus();
3530 m_editorFocused
= 1;
3539 m_inDoSelectProperty
= 0;
3544 // First, deactivate previous
3548 OnValidationFailureReset(m_selected
);
3550 // Must double-check if this is an selected in case of forceswitch
3553 if ( !CommitChangesFromEditor(flags
) )
3555 // Validation has failed, so we can't exit the previous editor
3556 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3557 // _("Invalid Value"),wxOK|wxICON_ERROR);
3558 m_inDoSelectProperty
= 0;
3566 m_selected
= (wxPGProperty
*) NULL
;
3567 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3569 // We need to always fully refresh the grid here
3572 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3573 EditorsValueWasNotModified();
3576 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3579 // Then, activate the one given.
3582 int propY
= p
->GetY2(m_lineHeight
);
3584 int splitterX
= GetSplitterPosition();
3585 m_editorFocused
= 0;
3587 m_pState
->m_selected
= p
;
3588 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3590 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3592 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3594 // Do we need OnMeasureCalls?
3595 wxSize imsz
= p
->OnMeasureImage();
3598 // Only create editor for non-disabled non-caption
3599 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3601 // do this for non-caption items
3605 // Do we need to paint the custom image, if any?
3606 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3607 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3608 !p
->GetEditorClass()->CanContainCustomImage()
3610 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3612 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3613 wxPoint goodPos
= grect
.GetPosition();
3614 #if wxPG_CREATE_CONTROLS_HIDDEN
3615 int coord_adjust
= m_height
- goodPos
.y
;
3616 goodPos
.y
+= coord_adjust
;
3619 const wxPGEditor
* editor
= p
->GetEditorClass();
3620 wxCHECK_MSG(editor
, false,
3621 wxT("NULL editor class not allowed"));
3623 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3625 wxPGWindowList wndList
= editor
->CreateControls(this,
3630 m_wndEditor
= wndList
.m_primary
;
3631 m_wndEditor2
= wndList
.m_secondary
;
3633 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3634 // value is drawn as normal, and m_wndEditor2 is assumed
3635 // to be a right-aligned button that triggers a separate editor
3640 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3641 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3643 // Set validator, if any
3644 #if wxUSE_VALIDATORS
3645 wxValidator
* validator
= p
->GetValidator();
3647 m_wndEditor
->SetValidator(*validator
);
3650 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3651 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3653 // If it has modified status, use bold font
3654 // (must be done before capturing m_ctrlXAdjust)
3655 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3656 SetCurControlBoldFont();
3659 // Fix TextCtrl indentation
3660 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3661 wxTextCtrl
* tc
= NULL
;
3662 if ( m_wndEditor
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3663 tc
= ((wxOwnerDrawnComboBox
*)m_wndEditor
)->GetTextCtrl();
3665 tc
= wxDynamicCast(m_wndEditor
, wxTextCtrl
);
3667 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3670 // Store x relative to splitter (we'll need it).
3671 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3673 // Check if background clear is not necessary
3674 wxPoint pos
= m_wndEditor
->GetPosition();
3675 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3677 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3680 m_wndEditor
->SetSizeHints(3, 3);
3682 #if wxPG_CREATE_CONTROLS_HIDDEN
3683 m_wndEditor
->Show(false);
3684 m_wndEditor
->Freeze();
3686 goodPos
= m_wndEditor
->GetPosition();
3687 goodPos
.y
-= coord_adjust
;
3688 m_wndEditor
->Move( goodPos
);
3691 wxWindow
* primaryCtrl
= GetEditorControl();
3692 SetupChildEventHandling(primaryCtrl
, wxPG_SUBID1
);
3694 // Focus and select all (wxTextCtrl, wxComboBox etc)
3695 if ( flags
& wxPG_SEL_FOCUS
)
3697 primaryCtrl
->SetFocus();
3699 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3705 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3706 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3708 // Get proper id for wndSecondary
3709 m_wndSecId
= m_wndEditor2
->GetId();
3710 wxWindowList children
= m_wndEditor2
->GetChildren();
3711 wxWindowList::iterator node
= children
.begin();
3712 if ( node
!= children
.end() )
3713 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3715 m_wndEditor2
->SetSizeHints(3,3);
3717 #if wxPG_CREATE_CONTROLS_HIDDEN
3718 wxRect sec_rect
= m_wndEditor2
->GetRect();
3719 sec_rect
.y
-= coord_adjust
;
3721 // Fine tuning required to fix "oversized"
3722 // button disappearance bug.
3723 if ( sec_rect
.y
< 0 )
3725 sec_rect
.height
+= sec_rect
.y
;
3728 m_wndEditor2
->SetSize( sec_rect
);
3730 m_wndEditor2
->Show();
3732 SetupChildEventHandling(m_wndEditor2
,wxPG_SUBID2
);
3734 // If no primary editor, focus to button to allow
3735 // it to interprete ENTER etc.
3736 // NOTE: Due to problems focusing away from it, this
3737 // has been disabled.
3739 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3740 m_wndEditor2->SetFocus();
3744 if ( flags
& wxPG_SEL_FOCUS
)
3745 m_editorFocused
= 1;
3750 // Make sure focus is in grid canvas (important for wxGTK, at least)
3754 EditorsValueWasNotModified();
3756 // If it's inside collapsed section, expand parent, scroll, etc.
3757 // Also, if it was partially visible, scroll it into view.
3758 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3763 #if wxPG_CREATE_CONTROLS_HIDDEN
3764 m_wndEditor
->Thaw();
3766 m_wndEditor
->Show(true);
3773 // Make sure focus is in grid canvas
3777 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3783 // Show help text in status bar.
3784 // (if found and grid not embedded in manager with help box and
3785 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3788 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3790 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3791 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3793 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3795 statusbar
= frame
->GetStatusBar();
3800 const wxString
* pHelpString
= (const wxString
*) NULL
;
3804 pHelpString
= &p
->GetHelpString();
3805 if ( pHelpString
->length() )
3807 // Set help box text.
3808 statusbar
->SetStatusText( *pHelpString
);
3809 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3813 if ( (!pHelpString
|| !pHelpString
->length()) &&
3814 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3816 // Clear help box - but only if it was written
3817 // by us at previous time.
3818 statusbar
->SetStatusText( m_emptyString
);
3819 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3825 m_inDoSelectProperty
= 0;
3827 // call wx event handler (here so that it also occurs on deselection)
3828 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3833 // -----------------------------------------------------------------------
3835 bool wxPropertyGrid::UnfocusEditor()
3837 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3840 if ( !CommitChangesFromEditor(0) )
3844 DrawItem(m_selected
);
3849 // -----------------------------------------------------------------------
3851 // This method is not inline because it called dozens of times
3852 // (i.e. two-arg function calls create smaller code size).
3853 bool wxPropertyGrid::DoClearSelection()
3855 return DoSelectProperty((wxPGProperty
*)NULL
);
3858 // -----------------------------------------------------------------------
3859 // wxPropertyGrid expand/collapse state
3860 // -----------------------------------------------------------------------
3862 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3864 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3866 // If active editor was inside collapsed section, then disable it
3867 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3869 if ( !ClearSelection() )
3873 // Store dont-center-splitter flag 'cause we need to temporarily set it
3874 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3875 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3877 bool res
= m_pState
->DoCollapse(pwc
);
3882 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3884 RecalculateVirtualSize();
3886 // Redraw etc. only if collapsed was visible.
3887 if (pwc
->IsVisible() &&
3889 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3891 // When item is collapsed so that scrollbar would move,
3892 // graphics mess is about (unless we redraw everything).
3897 // Clear dont-center-splitter flag if it wasn't set
3898 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3903 // -----------------------------------------------------------------------
3905 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3907 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3909 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3911 // Store dont-center-splitter flag 'cause we need to temporarily set it
3912 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3913 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3915 bool res
= m_pState
->DoExpand(pwc
);
3920 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3922 RecalculateVirtualSize();
3924 // Redraw etc. only if expanded was visible.
3925 if ( pwc
->IsVisible() && !m_frozen
&&
3926 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3930 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3933 DrawItems(pwc
, NULL
);
3938 // Clear dont-center-splitter flag if it wasn't set
3939 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3944 // -----------------------------------------------------------------------
3946 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3949 return m_pState
->DoHideProperty(p
, hide
, flags
);
3952 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3955 if ( !ClearSelection() )
3959 m_pState
->DoHideProperty(p
, hide
, flags
);
3961 RecalculateVirtualSize();
3968 // -----------------------------------------------------------------------
3969 // wxPropertyGrid size related methods
3970 // -----------------------------------------------------------------------
3972 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3974 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3978 // If virtual height was changed, then recalculate editor control position(s)
3979 if ( m_pState
->m_vhCalcPending
)
3980 CorrectEditorWidgetPosY();
3982 m_pState
->EnsureVirtualHeight();
3985 int by1
= m_pState
->GetVirtualHeight();
3986 int by2
= m_pState
->GetActualVirtualHeight();
3989 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3990 wxASSERT_MSG( false,
3996 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3998 int x
= m_pState
->m_width
;
3999 int y
= m_pState
->m_virtualHeight
;
4002 GetClientSize(&width
,&height
);
4004 // Now adjust virtual size.
4005 SetVirtualSize(x
, y
);
4011 // Adjust scrollbars
4012 if ( HasVirtualWidth() )
4014 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
4015 xPos
= GetScrollPos( wxHORIZONTAL
);
4018 if ( forceXPos
!= -1 )
4021 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
4024 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
4025 int yPos
= GetScrollPos( wxVERTICAL
);
4027 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
4028 xAmount
, yAmount
, xPos
, yPos
, true );
4030 // Must re-get size now
4031 GetClientSize(&width
,&height
);
4033 if ( !HasVirtualWidth() )
4035 m_pState
->SetVirtualWidth(width
);
4042 m_canvas
->SetSize( x
, y
);
4044 m_pState
->CheckColumnWidths();
4047 CorrectEditorWidgetSizeX();
4049 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
4052 // -----------------------------------------------------------------------
4054 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
4056 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
4060 GetClientSize(&width
,&height
);
4065 #if wxPG_DOUBLE_BUFFER
4066 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
4068 int dblh
= (m_lineHeight
*2);
4069 if ( !m_doubleBuffer
)
4071 // Create double buffer bitmap to draw on, if none
4072 int w
= (width
>250)?width
:250;
4073 int h
= height
+ dblh
;
4075 m_doubleBuffer
= new wxBitmap( w
, h
);
4079 int w
= m_doubleBuffer
->GetWidth();
4080 int h
= m_doubleBuffer
->GetHeight();
4082 // Double buffer must be large enough
4083 if ( w
< width
|| h
< (height
+dblh
) )
4085 if ( w
< width
) w
= width
;
4086 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
4087 delete m_doubleBuffer
;
4088 m_doubleBuffer
= new wxBitmap( w
, h
);
4095 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
4096 m_ncWidth
= event
.GetSize().x
;
4100 if ( m_pState
->m_itemsAdded
)
4101 PrepareAfterItemsAdded();
4103 // Without this, virtual size (atleast under wxGTK) will be skewed
4104 RecalculateVirtualSize();
4110 // -----------------------------------------------------------------------
4112 void wxPropertyGrid::SetVirtualWidth( int width
)
4116 // Disable virtual width
4117 width
= GetClientSize().x
;
4118 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4122 // Enable virtual width
4123 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
4125 m_pState
->SetVirtualWidth( width
);
4128 // -----------------------------------------------------------------------
4129 // wxPropertyGrid mouse event handling
4130 // -----------------------------------------------------------------------
4132 // selFlags uses same values DoSelectProperty's flags
4133 // Returns true if event was vetoed.
4134 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
4136 // Send property grid event of specific type and with specific property
4137 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
4138 evt
.SetPropertyGrid(this);
4139 evt
.SetEventObject(m_eventObject
);
4143 evt
.SetCanVeto(true);
4144 evt
.SetupValidationInfo();
4145 m_validationInfo
.m_pValue
= pValue
;
4147 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4149 evtHandler
->ProcessEvent(evt
);
4151 return evt
.WasVetoed();
4154 // -----------------------------------------------------------------------
4156 // Return false if should be skipped
4157 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4161 // Need to set focus?
4162 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4167 wxPropertyGridPageState
* state
= m_pState
;
4169 int splitterHitOffset
;
4170 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4172 wxPGProperty
* p
= DoGetItemAtY(y
);
4176 int depth
= (int)p
->GetDepth() - 1;
4178 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4180 if ( x
>= marginEnds
)
4184 if ( p
->IsCategory() )
4186 // This is category.
4187 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4189 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4191 // Expand, collapse, activate etc. if click on text or left of splitter.
4194 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4199 if ( !DoSelectProperty( p
) )
4202 // On double-click, expand/collapse.
4203 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4205 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4206 else DoExpand( p
, true );
4210 else if ( splitterHit
== -1 )
4213 unsigned int selFlag
= 0;
4214 if ( columnHit
== 1 )
4216 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4217 selFlag
= wxPG_SEL_FOCUS
;
4219 if ( !DoSelectProperty( p
, selFlag
) )
4222 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4224 if ( p
->GetChildCount() && !p
->IsCategory() )
4225 // On double-click, expand/collapse.
4226 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4228 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4229 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4230 else DoExpand( p
, true );
4237 // click on splitter
4238 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4240 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4242 // Double-clicking the splitter causes auto-centering
4243 CenterSplitter( true );
4245 else if ( m_dragStatus
== 0 )
4248 // Begin draggin the splitter
4252 // Changes must be committed here or the
4253 // value won't be drawn correctly
4254 if ( !CommitChangesFromEditor() )
4257 m_wndEditor
->Show ( false );
4260 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4262 m_canvas
->CaptureMouse();
4263 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4267 m_draggedSplitter
= splitterHit
;
4268 m_dragOffset
= splitterHitOffset
;
4270 wxClientDC
dc(m_canvas
);
4272 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4273 // Fixes button disappearance bug
4275 m_wndEditor2
->Show ( false );
4278 m_startingSplitterX
= x
- splitterHitOffset
;
4286 if ( p
->GetChildCount() )
4288 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4290 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4292 int y2
= y
% m_lineHeight
;
4293 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4295 // On click on expander button, expand/collapse
4296 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4297 DoCollapse( p
, true );
4299 DoExpand( p
, true );
4308 // -----------------------------------------------------------------------
4310 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4311 wxMouseEvent
& WXUNUSED(event
) )
4315 // Select property here as well
4316 wxPGProperty
* p
= m_propHover
;
4317 if ( p
!= m_selected
)
4318 DoSelectProperty( p
);
4320 // Send right click event.
4321 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4328 // -----------------------------------------------------------------------
4330 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4331 wxMouseEvent
& WXUNUSED(event
) )
4335 // Select property here as well
4336 wxPGProperty
* p
= m_propHover
;
4338 if ( p
!= m_selected
)
4339 DoSelectProperty( p
);
4341 // Send double-click event.
4342 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4349 // -----------------------------------------------------------------------
4351 #if wxPG_SUPPORT_TOOLTIPS
4353 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4355 if ( tipString
.length() )
4357 m_canvas
->SetToolTip(tipString
);
4361 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4362 m_canvas
->SetToolTip( m_emptyString
);
4364 m_canvas
->SetToolTip( NULL
);
4369 #endif // #if wxPG_SUPPORT_TOOLTIPS
4371 // -----------------------------------------------------------------------
4373 // Return false if should be skipped
4374 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4376 // Safety check (needed because mouse capturing may
4377 // otherwise freeze the control)
4378 if ( m_dragStatus
> 0 && !event
.Dragging() )
4380 HandleMouseUp(x
,y
,event
);
4383 wxPropertyGridPageState
* state
= m_pState
;
4385 int splitterHitOffset
;
4386 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4387 int splitterX
= x
- splitterHitOffset
;
4389 if ( m_dragStatus
> 0 )
4391 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4392 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4395 int newSplitterX
= x
- m_dragOffset
;
4396 int splitterX
= x
- splitterHitOffset
;
4398 // Splitter redraw required?
4399 if ( newSplitterX
!= splitterX
)
4402 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4403 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4404 state
->m_fSplitterX
= (float) newSplitterX
;
4407 CorrectEditorWidgetSizeX();
4421 int ih
= m_lineHeight
;
4424 #if wxPG_SUPPORT_TOOLTIPS
4425 wxPGProperty
* prevHover
= m_propHover
;
4426 unsigned char prevSide
= m_mouseSide
;
4428 int curPropHoverY
= y
- (y
% ih
);
4430 // On which item it hovers
4431 if ( ( !m_propHover
)
4433 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4436 // Mouse moves on another property
4438 m_propHover
= DoGetItemAtY(y
);
4439 m_propHoverY
= curPropHoverY
;
4442 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4445 #if wxPG_SUPPORT_TOOLTIPS
4446 // Store which side we are on
4448 if ( columnHit
== 1 )
4450 else if ( columnHit
== 0 )
4454 // If tooltips are enabled, show label or value as a tip
4455 // in case it doesn't otherwise show in full length.
4457 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4459 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4461 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4463 if ( m_propHover
&& !m_propHover
->IsCategory() )
4466 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4468 // Show help string as a tooltip
4469 wxString tipString
= m_propHover
->GetHelpString();
4471 SetToolTip(tipString
);
4475 // Show cropped value string as a tooltip
4479 if ( m_mouseSide
== 1 )
4481 tipString
= m_propHover
->m_label
;
4482 space
= splitterX
-m_marginWidth
-3;
4484 else if ( m_mouseSide
== 2 )
4486 tipString
= m_propHover
->GetDisplayedString();
4488 space
= m_width
- splitterX
;
4489 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4490 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4496 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4499 SetToolTip( tipString
);
4506 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4507 m_canvas
->SetToolTip( m_emptyString
);
4509 m_canvas
->SetToolTip( NULL
);
4520 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4521 m_canvas
->SetToolTip( m_emptyString
);
4523 m_canvas
->SetToolTip( NULL
);
4531 if ( splitterHit
== -1 ||
4533 HasFlag(wxPG_STATIC_SPLITTER
) )
4535 // hovering on something else
4536 if ( m_curcursor
!= wxCURSOR_ARROW
)
4537 CustomSetCursor( wxCURSOR_ARROW
);
4541 // Do not allow splitter cursor on caption items.
4542 // (also not if we were dragging and its started
4543 // outside the splitter region)
4546 !m_propHover
->IsCategory() &&
4550 // hovering on splitter
4552 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4553 // reliably detected.
4554 //if ( m_curcursor != wxCURSOR_SIZEWE )
4555 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4561 // hovering on something else
4562 if ( m_curcursor
!= wxCURSOR_ARROW
)
4563 CustomSetCursor( wxCURSOR_ARROW
);
4570 // -----------------------------------------------------------------------
4572 // Also handles Leaving event
4573 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4574 wxMouseEvent
&WXUNUSED(event
) )
4576 wxPropertyGridPageState
* state
= m_pState
;
4580 int splitterHitOffset
;
4581 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4583 // No event type check - basicly calling this method should
4584 // just stop dragging.
4585 // Left up after dragged?
4586 if ( m_dragStatus
>= 1 )
4589 // End Splitter Dragging
4591 // DO NOT ENABLE FOLLOWING LINE!
4592 // (it is only here as a reminder to not to do it)
4595 // Disable splitter auto-centering
4596 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4598 // This is necessary to return cursor
4599 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4601 m_canvas
->ReleaseMouse();
4602 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4605 // Set back the default cursor, if necessary
4606 if ( splitterHit
== -1 ||
4609 CustomSetCursor( wxCURSOR_ARROW
);
4614 // Control background needs to be cleared
4615 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4616 DrawItem( m_selected
);
4620 m_wndEditor
->Show ( true );
4623 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4624 // Fixes button disappearance bug
4626 m_wndEditor2
->Show ( true );
4629 // This clears the focus.
4630 m_editorFocused
= 0;
4636 // -----------------------------------------------------------------------
4638 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4640 int splitterX
= GetSplitterPosition();
4643 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4647 wxWindow
* wnd
= m_wndEditor
;
4649 // Hide popup on clicks
4650 if ( event
.GetEventType() != wxEVT_MOTION
)
4651 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4653 ((wxOwnerDrawnComboBox
*)m_wndEditor
)->HidePopup();
4659 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4661 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4662 ux
>= (r
.x
+r
.width
) ||
4664 event
.m_y
>= (r
.y
+r
.height
)
4674 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4679 // -----------------------------------------------------------------------
4681 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4684 if ( OnMouseCommon( event
, &x
, &y
) )
4686 HandleMouseClick(x
,y
,event
);
4691 // -----------------------------------------------------------------------
4693 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4696 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4697 HandleMouseRightClick(x
,y
,event
);
4701 // -----------------------------------------------------------------------
4703 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4705 // Always run standard mouse-down handler as well
4706 OnMouseClick(event
);
4709 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4710 HandleMouseDoubleClick(x
,y
,event
);
4714 // -----------------------------------------------------------------------
4716 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4719 if ( OnMouseCommon( event
, &x
, &y
) )
4721 HandleMouseMove(x
,y
,event
);
4726 // -----------------------------------------------------------------------
4728 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4730 // Called when mouse moves in the empty space below the properties.
4731 CustomSetCursor( wxCURSOR_ARROW
);
4734 // -----------------------------------------------------------------------
4736 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4739 if ( OnMouseCommon( event
, &x
, &y
) )
4741 HandleMouseUp(x
,y
,event
);
4746 // -----------------------------------------------------------------------
4748 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4750 // This may get called from child control as well, so event's
4751 // mouse position cannot be relied on.
4753 if ( event
.Entering() )
4755 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4757 // TODO: Fix this (detect parent and only do
4758 // cursor trick if it is a manager).
4759 wxASSERT( GetParent() );
4760 GetParent()->SetCursor(wxNullCursor
);
4762 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4765 GetParent()->SetCursor(wxNullCursor
);
4767 else if ( event
.Leaving() )
4769 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4770 m_canvas
->SetCursor( wxNullCursor
);
4772 // Get real cursor position
4773 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4775 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4778 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4780 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4784 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4792 // -----------------------------------------------------------------------
4794 // Common code used by various OnMouseXXXChild methods.
4795 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4797 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4798 wxASSERT( topCtrlWnd
);
4800 event
.GetPosition(&x
,&y
);
4802 AdjustPosForClipperWindow( topCtrlWnd
, &x
, &y
);
4804 int splitterX
= GetSplitterPosition();
4806 wxRect r
= topCtrlWnd
->GetRect();
4807 if ( !m_dragStatus
&&
4808 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4809 y
>= 0 && y
< r
.height \
4812 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4817 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4824 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4827 if ( OnMouseChildCommon(event
,&x
,&y
) )
4829 bool res
= HandleMouseClick(x
,y
,event
);
4830 if ( !res
) event
.Skip();
4834 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4837 wxASSERT( m_wndEditor
);
4838 // These coords may not be exact (about +-2),
4839 // but that should not matter (right click is about item, not position).
4840 wxPoint pt
= m_wndEditor
->GetPosition();
4841 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4842 wxASSERT( m_selected
);
4843 m_propHover
= m_selected
;
4844 bool res
= HandleMouseRightClick(x
,y
,event
);
4845 if ( !res
) event
.Skip();
4848 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4851 if ( OnMouseChildCommon(event
,&x
,&y
) )
4853 bool res
= HandleMouseMove(x
,y
,event
);
4854 if ( !res
) event
.Skip();
4858 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4861 if ( OnMouseChildCommon(event
,&x
,&y
) )
4863 bool res
= HandleMouseUp(x
,y
,event
);
4864 if ( !res
) event
.Skip();
4868 // -----------------------------------------------------------------------
4869 // wxPropertyGrid keyboard event handling
4870 // -----------------------------------------------------------------------
4872 void wxPropertyGrid::SendNavigationKeyEvent( int dir
)
4874 wxNavigationKeyEvent evt
;
4875 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
4876 (dir
?wxNavigationKeyEvent::IsForward
:
4877 wxNavigationKeyEvent::IsBackward
));
4878 evt
.SetEventObject(this);
4879 m_canvas
->GetEventHandler()->AddPendingEvent(evt
);
4883 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4885 // Translates wxKeyEvent to wxPG_ACTION_XXX
4887 int keycode
= event
.GetKeyCode();
4888 int modifiers
= event
.GetModifiers();
4890 wxASSERT( !(modifiers
&~(0xFFFF)) );
4892 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4894 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4896 if ( it
== m_actionTriggers
.end() )
4901 int second
= (it
->second
>>16) & 0xFFFF;
4905 return (it
->second
& 0xFFFF);
4908 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4910 wxASSERT( !(modifiers
&~(0xFFFF)) );
4912 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4914 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4916 if ( it
!= m_actionTriggers
.end() )
4918 // This key combination is already used
4920 // Can add secondary?
4921 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4922 wxT("You can only add up to two separate actions per key combination.") );
4924 action
= it
->second
| (action
<<16);
4927 m_actionTriggers
[hashMapKey
] = action
;
4930 void wxPropertyGrid::ClearActionTriggers( int action
)
4932 wxPGHashMapI2I::iterator it
;
4934 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4936 if ( it
->second
== action
)
4938 m_actionTriggers
.erase(it
);
4943 static void CopyTextToClipboard( const wxString
& text
)
4945 if ( wxTheClipboard
->Open() )
4947 // This data objects are held by the clipboard,
4948 // so do not delete them in the app.
4949 wxTheClipboard
->SetData( new wxTextDataObject(text
) );
4950 wxTheClipboard
->Close();
4954 void wxPropertyGrid::HandleKeyEvent(wxKeyEvent
&event
)
4957 // Handles key event when editor control is not focused.
4960 wxASSERT( !m_frozen
);
4964 // Travelsal between items, collapsing/expanding, etc.
4965 int keycode
= event
.GetKeyCode();
4967 if ( keycode
== WXK_TAB
)
4969 SendNavigationKeyEvent( event
.ShiftDown()?0:1 );
4973 // Ignore Alt and Control when they are down alone
4974 if ( keycode
== WXK_ALT
||
4975 keycode
== WXK_CONTROL
)
4982 int action
= KeyEventToActions(event
, &secondAction
);
4988 if ( ButtonTriggerKeyTest(event
) )
4991 wxPGProperty
* p
= m_selected
;
4993 if ( action
== wxPG_ACTION_COPY
)
4995 CopyTextToClipboard(p
->GetDisplayedString());
4999 // Travel and expand/collapse
5002 if ( p
->GetChildCount() &&
5003 !(p
->m_flags
& wxPG_PROP_DISABLED
)
5006 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
5008 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
5011 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
5013 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
5020 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
5024 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
5035 if ( selectDir
>= -1 )
5037 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
5039 DoSelectProperty(p
);
5045 // If nothing was selected, select the first item now
5046 // (or navigate out of tab).
5047 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
5049 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
5050 if ( p
) DoSelectProperty(p
);
5055 // -----------------------------------------------------------------------
5057 // Potentially handles a keyboard event for editor controls.
5058 // Returns false if event should *not* be skipped (on true it can
5059 // be optionally skipped).
5060 // Basicly, false means that SelectProperty was called (or was about
5061 // to be called, if canDestroy was false).
5062 bool wxPropertyGrid::HandleChildKey( wxKeyEvent
& event
)
5066 if ( !m_selected
|| !m_wndEditor
)
5071 int action
= KeyEventToAction(event
);
5074 if ( action
== wxPG_ACTION_CANCEL_EDIT
)
5077 // Esc cancels any changes
5078 if ( IsEditorsValueModified() )
5080 EditorsValueWasNotModified();
5082 // Update the control as well
5083 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
5085 m_selected
->GetDisplayedString() );
5088 OnValidationFailureReset(m_selected
);
5094 else if ( action
== wxPG_ACTION_COPY
)
5096 // NB: There is some problem with getting native cut-copy-paste keys to go through
5097 // for embedded editor wxTextCtrl. This is why we emulate.
5099 wxTextCtrl
* tc
= GetEditorTextCtrl();
5102 wxString sel
= tc
->GetStringSelection();
5104 CopyTextToClipboard(sel
);
5108 CopyTextToClipboard(m_selected
->GetDisplayedString());
5111 else if ( action
== wxPG_ACTION_CUT
)
5113 wxTextCtrl
* tc
= GetEditorTextCtrl();
5117 tc
->GetSelection(&from
, &to
);
5120 CopyTextToClipboard(tc
->GetStringSelection());
5121 tc
->Remove(from
, to
);
5125 else if ( action
== wxPG_ACTION_PASTE
)
5127 wxTextCtrl
* tc
= GetEditorTextCtrl();
5130 if (wxTheClipboard
->Open())
5132 if (wxTheClipboard
->IsSupported( wxDF_TEXT
))
5134 wxTextDataObject data
;
5135 wxTheClipboard
->GetData( data
);
5137 tc
->GetSelection(&from
, &to
);
5140 tc
->Remove(from
, to
);
5141 tc
->WriteText(data
.GetText());
5145 tc
->WriteText(data
.GetText());
5148 wxTheClipboard
->Close();
5156 // -----------------------------------------------------------------------
5158 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
5162 // Events to editor controls should get relayed here.
5164 wxWindow
* focused
= wxWindow::FindFocus();
5166 wxWindow
* primaryCtrl
= GetEditorControl();
5169 (focused
==primaryCtrl
5170 || m_editorFocused
) )
5172 // Child key must be processed here, since it can
5173 // destroy the control which is referred by its own
5175 HandleChildKey( event
);
5178 HandleKeyEvent( event
);
5181 // -----------------------------------------------------------------------
5183 void wxPropertyGrid::OnKeyUp(wxKeyEvent
&event
)
5185 m_keyComboConsumed
= 0;
5190 // -----------------------------------------------------------------------
5192 void wxPropertyGrid::OnNavigationKey( wxNavigationKeyEvent
& event
)
5194 // Ignore events that occur very close to focus set
5195 if ( m_iFlags
& wxPG_FL_IGNORE_NEXT_NAVKEY
)
5197 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5202 wxPGProperty
* next
= (wxPGProperty
*) NULL
;
5204 int dir
= event
.GetDirection()?1:-1;
5208 if ( dir
== 1 && (m_wndEditor
|| m_wndEditor2
) )
5210 wxWindow
* focused
= wxWindow::FindFocus();
5212 wxWindow
* wndToCheck
= GetEditorControl();
5214 // ODComboBox focus goes to its text ctrl, so we need to use it instead
5215 if ( wndToCheck
&& wndToCheck
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
5217 wxTextCtrl
* comboTextCtrl
= ((wxOwnerDrawnComboBox
*)wndToCheck
)->GetTextCtrl();
5218 if ( comboTextCtrl
)
5219 wndToCheck
= comboTextCtrl
;
5223 // Because of problems navigating from wxButton, do not go to it.
5226 // No primary, use secondary
5227 wndToCheck = m_wndEditor2;
5229 // If it has editor button, focus to it after the primary editor.
5230 // NB: Doesn't work since wxButton on wxMSW doesn't seem to propagate
5231 // key events (yes, I'm using wxWANTS_CHARS with it, and yes I
5232 // have somewhat debugged in window.cpp itself).
5233 else if ( focused == wndToCheck &&
5235 !(GetExtraStyle() & wxPG_EX_NO_TAB_TO_BUTTON) )
5237 wndToCheck = m_wndEditor2;
5238 wxLogDebug(wxT("Exp1"));
5242 if ( focused
!= wndToCheck
&&
5245 wndToCheck
->SetFocus();
5247 // Select all text in wxTextCtrl etc.
5248 if ( m_wndEditor
&& wndToCheck
== m_wndEditor
)
5249 m_selected
->GetEditorClass()->OnFocus(m_selected
,wndToCheck
);
5251 m_editorFocused
= 1;
5258 next
= wxPropertyGridIterator::OneStep(m_pState
, wxPG_ITERATE_VISIBLE
, m_selected
, dir
);
5262 // This allows preventing NavigateOut to occur
5263 DoSelectProperty( next
, wxPG_SEL_FOCUS
);
5272 // -----------------------------------------------------------------------
5274 bool wxPropertyGrid::ButtonTriggerKeyTest( wxKeyEvent
&event
)
5276 int keycode
= event
.GetKeyCode();
5278 // Does the keycode trigger button?
5279 if ( keycode
== m_pushButKeyCode
&&
5281 (!m_pushButKeyCodeNeedsAlt
|| event
.AltDown()) &&
5282 (!m_pushButKeyCodeNeedsCtrl
|| event
.ControlDown()) )
5284 m_keyComboConsumed
= 1;
5286 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,m_wndEditor2
->GetId());
5287 GetEventHandler()->AddPendingEvent(evt
);
5294 // -----------------------------------------------------------------------
5296 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
5298 int keycode
= event
.GetKeyCode();
5300 // Ignore Alt and Control when they are down alone
5301 if ( keycode
== WXK_ALT
||
5302 keycode
== WXK_CONTROL
)
5308 if ( ButtonTriggerKeyTest(event
) )
5311 if ( HandleChildKey(event
) == true )
5314 GetEventHandler()->AddPendingEvent(event
);
5317 void wxPropertyGrid::OnChildKeyUp( wxKeyEvent
&event
)
5319 m_keyComboConsumed
= 0;
5321 GetEventHandler()->AddPendingEvent(event
);
5326 // -----------------------------------------------------------------------
5327 // wxPropertyGrid miscellaneous event handling
5328 // -----------------------------------------------------------------------
5330 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5333 // Check if the focus is in this control or one of its children
5334 wxWindow
* newFocused
= wxWindow::FindFocus();
5336 if ( newFocused
!= m_curFocused
)
5337 HandleFocusChange( newFocused
);
5340 // Called by focus event handlers. newFocused is the window that becomes focused.
5341 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5343 unsigned int oldFlags
= m_iFlags
;
5345 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5347 wxWindow
* parent
= newFocused
;
5349 // This must be one of nextFocus' parents.
5352 // Use m_eventObject, which is either wxPropertyGrid or
5353 // wxPropertyGridManager, as appropriate.
5354 if ( parent
== m_eventObject
)
5356 m_iFlags
|= wxPG_FL_FOCUSED
;
5359 parent
= parent
->GetParent();
5362 m_curFocused
= newFocused
;
5364 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5365 (oldFlags
& wxPG_FL_FOCUSED
) )
5367 // On each focus kill, mark the next nav key event
5368 // to be ignored (can't do on set focus since the
5369 // event would occur before it).
5370 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5372 m_iFlags
|= wxPG_FL_IGNORE_NEXT_NAVKEY
;
5374 // Need to store changed value
5375 CommitChangesFromEditor();
5381 // Preliminary code for tab-order respecting
5382 // tab-traversal (but should be moved to
5385 wxWindow* prevFocus = event.GetWindow();
5386 wxWindow* useThis = this;
5387 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5388 useThis = GetParent();
5391 prevFocus->GetParent() == useThis->GetParent() )
5393 wxList& children = useThis->GetParent()->GetChildren();
5395 wxNode* node = children.Find(prevFocus);
5397 if ( node->GetNext() &&
5398 useThis == node->GetNext()->GetData() )
5399 DoSelectProperty(GetFirst());
5400 else if ( node->GetPrevious () &&
5401 useThis == node->GetPrevious()->GetData() )
5402 DoSelectProperty(GetLastProperty());
5407 m_iFlags
&= ~(wxPG_FL_IGNORE_NEXT_NAVKEY
);
5411 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5412 DrawItem( m_selected
);
5416 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5418 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5419 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5420 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5421 //else if ( event.GetWindow() )
5423 HandleFocusChange(event
.GetWindow());
5428 // -----------------------------------------------------------------------
5430 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5432 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5435 // event.Skip() being commented out is aworkaround for bug reported
5436 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5440 // -----------------------------------------------------------------------
5442 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5444 m_iFlags
|= wxPG_FL_SCROLLED
;
5449 // -----------------------------------------------------------------------
5451 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5453 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5455 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5459 // -----------------------------------------------------------------------
5460 // Property editor related functions
5461 // -----------------------------------------------------------------------
5463 // noDefCheck = true prevents infinite recursion.
5464 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5467 wxASSERT( editorClass
);
5469 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5470 RegisterDefaultEditors();
5472 wxString name
= editorClass
->GetName();
5474 // Existing editor under this name?
5475 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5477 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5478 (wxPGEditor
*) vt_it
->second
,
5479 "Editor with given name was already registered" );
5481 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5486 // Registers all default editor classes
5487 void wxPropertyGrid::RegisterDefaultEditors()
5489 wxPGRegisterDefaultEditorClass( TextCtrl
);
5490 wxPGRegisterDefaultEditorClass( Choice
);
5491 wxPGRegisterDefaultEditorClass( ComboBox
);
5492 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5493 #if wxPG_INCLUDE_CHECKBOX
5494 wxPGRegisterDefaultEditorClass( CheckBox
);
5496 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5498 // Register SpinCtrl etc. editors before use
5499 RegisterAdditionalEditors();
5502 // -----------------------------------------------------------------------
5503 // wxPGStringTokenizer
5504 // Needed to handle C-style string lists (e.g. "str1" "str2")
5505 // -----------------------------------------------------------------------
5507 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5508 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5512 wxPGStringTokenizer::~wxPGStringTokenizer()
5516 bool wxPGStringTokenizer::HasMoreTokens()
5518 const wxString
& str
= *m_str
;
5520 wxString::const_iterator i
= m_curPos
;
5522 wxUniChar delim
= m_delimeter
;
5524 wxUniChar prev_a
= wxT('\0');
5526 bool inToken
= false;
5528 while ( i
!= str
.end() )
5537 m_readyToken
.clear();
5542 if ( prev_a
!= wxT('\\') )
5546 if ( a
!= wxT('\\') )
5566 m_curPos
= str
.end();
5574 wxString
wxPGStringTokenizer::GetNextToken()
5576 return m_readyToken
;
5579 // -----------------------------------------------------------------------
5581 // -----------------------------------------------------------------------
5583 wxPGChoiceEntry::wxPGChoiceEntry()
5584 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5588 wxPGChoiceEntry::wxPGChoiceEntry( const wxPGChoiceEntry
& entry
)
5589 : wxPGCell( entry
.GetText(), entry
.GetBitmap(),
5590 entry
.GetFgCol(), entry
.GetBgCol() ), m_value(entry
.GetValue())
5594 // -----------------------------------------------------------------------
5596 // -----------------------------------------------------------------------
5598 wxPGChoicesData::wxPGChoicesData()
5603 wxPGChoicesData::~wxPGChoicesData()
5608 void wxPGChoicesData::Clear()
5612 for ( i
=0; i
<m_items
.size(); i
++ )
5624 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5626 wxASSERT( m_items
.size() == 0 );
5630 for ( i
=0; i
<data
->GetCount(); i
++ )
5631 m_items
.push_back( new wxPGChoiceEntry(*data
->Item(i
)) );
5634 // -----------------------------------------------------------------------
5636 // -----------------------------------------------------------------------
5638 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5642 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5643 m_data
->Insert( -1, p
);
5647 // -----------------------------------------------------------------------
5649 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5653 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5654 p
->SetBitmap(bitmap
);
5655 m_data
->Insert( -1, p
);
5659 // -----------------------------------------------------------------------
5661 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5665 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(entry
);
5666 m_data
->Insert(index
, p
);
5670 // -----------------------------------------------------------------------
5672 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5676 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5677 m_data
->Insert( index
, p
);
5681 // -----------------------------------------------------------------------
5683 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5689 while ( index
< GetCount() )
5691 int cmpRes
= GetLabel(index
).Cmp(label
);
5697 wxPGChoiceEntry
* p
= new wxPGChoiceEntry(label
, value
);
5698 m_data
->Insert( index
, p
);
5702 // -----------------------------------------------------------------------
5704 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5708 unsigned int itemcount
= 0;
5709 const wxChar
** p
= &labels
[0];
5710 while ( *p
) { p
++; itemcount
++; }
5713 for ( i
= 0; i
< itemcount
; i
++ )
5715 int value
= wxPG_INVALID_VALUE
;
5718 m_data
->Insert( -1, new wxPGChoiceEntry(labels
[i
], value
) );
5722 // -----------------------------------------------------------------------
5724 void wxPGChoices::Add( const wxArrayString
& arr
, const ValArrItem
* values
)
5729 unsigned int itemcount
= arr
.size();
5731 for ( i
= 0; i
< itemcount
; i
++ )
5733 int value
= wxPG_INVALID_VALUE
;
5736 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5740 // -----------------------------------------------------------------------
5742 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5747 unsigned int itemcount
= arr
.size();
5749 for ( i
= 0; i
< itemcount
; i
++ )
5751 int value
= wxPG_INVALID_VALUE
;
5752 if ( &arrint
&& arrint
.size() )
5754 m_data
->Insert( -1, new wxPGChoiceEntry(arr
[i
], value
) );
5758 // -----------------------------------------------------------------------
5760 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5762 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5764 for ( i
=nIndex
; i
<(nIndex
+count
); i
++)
5765 delete m_data
->Item(i
);
5766 m_data
->m_items
.RemoveAt(nIndex
, count
);
5769 // -----------------------------------------------------------------------
5771 int wxPGChoices::Index( const wxString
& str
) const
5776 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5778 if ( m_data
->Item(i
)->GetText() == str
)
5785 // -----------------------------------------------------------------------
5787 int wxPGChoices::Index( int val
) const
5792 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5794 if ( m_data
->Item(i
)->GetValue() == val
)
5801 // -----------------------------------------------------------------------
5803 wxArrayString
wxPGChoices::GetLabels() const
5808 if ( this && IsOk() )
5809 for ( i
=0; i
<GetCount(); i
++ )
5810 arr
.push_back(GetLabel(i
));
5815 // -----------------------------------------------------------------------
5817 bool wxPGChoices::HasValues() const
5822 // -----------------------------------------------------------------------
5824 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5831 for ( i
=0; i
< strings
.size(); i
++ )
5833 int index
= Index(strings
[i
]);
5835 arr
.Add(GetValue(index
));
5837 arr
.Add(wxPG_INVALID_VALUE
);
5844 // -----------------------------------------------------------------------
5846 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5847 wxArrayString
* unmatched
) const
5854 for ( i
=0; i
< strings
.size(); i
++ )
5856 const wxString
& str
= strings
[i
];
5857 int index
= Index(str
);
5860 else if ( unmatched
)
5861 unmatched
->Add(str
);
5868 // -----------------------------------------------------------------------
5870 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5874 if ( data
!= wxPGChoicesEmptyData
)
5881 // -----------------------------------------------------------------------
5883 void wxPGChoices::Init()
5885 m_data
= wxPGChoicesEmptyData
;
5888 // -----------------------------------------------------------------------
5890 void wxPGChoices::Free()
5892 if ( m_data
!= wxPGChoicesEmptyData
)
5895 m_data
= wxPGChoicesEmptyData
;
5899 // -----------------------------------------------------------------------
5900 // wxPropertyGridEvent
5901 // -----------------------------------------------------------------------
5903 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5906 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5907 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5908 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5909 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5910 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5911 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5912 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5913 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5914 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5917 // -----------------------------------------------------------------------
5919 void wxPropertyGridEvent::Init()
5921 m_validationInfo
= NULL
;
5923 m_wasVetoed
= false;
5926 // -----------------------------------------------------------------------
5928 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5929 : wxCommandEvent(commandType
,id
)
5935 // -----------------------------------------------------------------------
5937 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5938 : wxCommandEvent(event
)
5940 m_eventType
= event
.GetEventType();
5941 m_eventObject
= event
.m_eventObject
;
5943 m_property
= event
.m_property
;
5944 m_validationInfo
= event
.m_validationInfo
;
5945 m_canVeto
= event
.m_canVeto
;
5946 m_wasVetoed
= event
.m_wasVetoed
;
5949 // -----------------------------------------------------------------------
5951 wxPropertyGridEvent::~wxPropertyGridEvent()
5955 // -----------------------------------------------------------------------
5957 wxEvent
* wxPropertyGridEvent::Clone() const
5959 return new wxPropertyGridEvent( *this );
5962 // -----------------------------------------------------------------------
5963 // wxPropertyGridPopulator
5964 // -----------------------------------------------------------------------
5966 wxPropertyGridPopulator::wxPropertyGridPopulator()
5970 wxPGGlobalVars
->m_offline
++;
5973 // -----------------------------------------------------------------------
5975 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5978 m_propHierarchy
.clear();
5981 // -----------------------------------------------------------------------
5983 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5989 // -----------------------------------------------------------------------
5991 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5994 // Free unused sets of choices
5995 wxPGHashMapS2P::iterator it
;
5997 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5999 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
6006 m_pg
->GetPanel()->Refresh();
6008 wxPGGlobalVars
->m_offline
--;
6011 // -----------------------------------------------------------------------
6013 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
6014 const wxString
& propLabel
,
6015 const wxString
& propName
,
6016 const wxString
* propValue
,
6017 wxPGChoices
* pChoices
)
6019 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
6020 wxPGProperty
* parent
= GetCurParent();
6022 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
6024 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
6028 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
6030 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
6034 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
6036 property
->SetLabel(propLabel
);
6037 property
->DoSetName(propName
);
6039 if ( pChoices
&& pChoices
->IsOk() )
6040 property
->SetChoices(*pChoices
);
6042 m_state
->DoInsert(parent
, -1, property
);
6045 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
);
6050 // -----------------------------------------------------------------------
6052 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
6054 m_propHierarchy
.push_back(property
);
6055 DoScanForChildren();
6056 m_propHierarchy
.pop_back();
6059 // -----------------------------------------------------------------------
6061 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
6062 const wxString
& idString
)
6064 wxPGChoices choices
;
6067 if ( choicesString
[0] == wxT('@') )
6069 wxString ids
= choicesString
.substr(1);
6070 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
6071 if ( it
== m_dictIdChoices
.end() )
6072 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
6074 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6079 if ( idString
.length() )
6081 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
6082 if ( it
!= m_dictIdChoices
.end() )
6084 choices
.AssignData((wxPGChoicesData
*)it
->second
);
6091 // Parse choices string
6092 wxString::const_iterator it
= choicesString
.begin();
6096 bool labelValid
= false;
6098 for ( ; it
!= choicesString
.end(); it
++ )
6104 if ( c
== wxT('"') )
6109 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6110 choices
.Add(label
, l
);
6113 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
6118 else if ( c
== wxT('=') )
6125 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
6132 if ( c
== wxT('"') )
6145 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
6146 choices
.Add(label
, l
);
6149 if ( !choices
.IsOk() )
6151 choices
.EnsureData();
6155 if ( idString
.length() )
6156 m_dictIdChoices
[idString
] = choices
.GetData();
6163 // -----------------------------------------------------------------------
6165 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
6167 if ( s
.Last() == wxT('%') )
6169 wxString s2
= s
.substr(0,s
.length()-1);
6171 if ( s2
.ToLong(&val
, 10) )
6173 *pval
= (val
*max
)/100;
6179 return s
.ToLong(pval
, 10);
6182 // -----------------------------------------------------------------------
6184 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
6185 const wxString
& type
,
6186 const wxString
& value
)
6188 int l
= m_propHierarchy
.size();
6192 wxPGProperty
* p
= m_propHierarchy
[l
-1];
6193 wxString valuel
= value
.Lower();
6196 if ( type
.length() == 0 )
6201 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6203 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
6205 else if ( value
.ToLong(&v
, 0) )
6212 if ( type
== wxT("string") )
6216 else if ( type
== wxT("int") )
6219 value
.ToLong(&v
, 0);
6222 else if ( type
== wxT("bool") )
6224 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
6231 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
6236 p
->SetAttribute( name
, variant
);
6241 // -----------------------------------------------------------------------
6243 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
6245 wxLogError(_("Error in resource: %s"),msg
.c_str());
6248 // -----------------------------------------------------------------------
6250 #endif // wxUSE_PROPGRID