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"
68 #include "wx/msw/private.h"
71 // Two pics for the expand / collapse buttons.
72 // Files are not supplied with this project (since it is
73 // recommended to use either custom or native rendering).
74 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
75 // and copy xpm files from archive to wxPropertyGrid src directory
76 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
77 // and set wxPG_USE_RENDERER_NATIVE to 0).
78 #ifndef wxPG_ICON_WIDTH
79 #if defined(__WXMAC__)
80 #include "mac_collapse.xpm"
81 #include "mac_expand.xpm"
82 #elif defined(__WXGTK__)
83 #include "linux_collapse.xpm"
84 #include "linux_expand.xpm"
86 #include "default_collapse.xpm"
87 #include "default_expand.xpm"
92 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
93 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
94 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
95 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
96 #define wxPG_YSPACING_MIN 1
97 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
98 // but causes normal combobox to spill out under MSW
100 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
102 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
103 // Must be larger than largest control border
107 #define wxPG_DEFAULT_CURSOR wxNullCursor
110 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
112 //#define wxPG_HIDER_BUTTON_HEIGHT 25
114 #define wxPG_PIXELS_PER_UNIT m_lineHeight
116 #ifdef wxPG_ICON_WIDTH
117 #define m_iconHeight m_iconWidth
120 //#define wxPG_TOOLTIP_DELAY 1000
122 // -----------------------------------------------------------------------
125 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
127 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
130 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
133 // -----------------------------------------------------------------------
135 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
137 // -----------------------------------------------------------------------
138 // Statics in one class for easy destruction.
139 // -----------------------------------------------------------------------
141 #include "wx/module.h"
143 class wxPGGlobalVarsClassManager
: public wxModule
145 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
147 wxPGGlobalVarsClassManager() {}
148 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
149 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
152 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
155 // When wxPG is loaded dynamically after the application is already running
156 // then the built-in module system won't pick this one up. Add it manually.
157 void wxPGInitResourceModule()
159 wxModule
* module = new wxPGGlobalVarsClassManager
;
161 wxModule::RegisterModule(module);
164 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
167 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
169 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
171 m_boolChoices
.Add(_("False"));
172 m_boolChoices
.Add(_("True"));
174 m_fontFamilyChoices
= NULL
;
176 m_defaultRenderer
= new wxPGDefaultRenderer();
178 m_autoGetTranslation
= false;
186 // Prepare some shared variants
187 m_vEmptyString
= wxString();
189 m_vMinusOne
= (long) -1;
193 // Prepare cached string constants
194 m_strstring
= wxS("string");
195 m_strlong
= wxS("long");
196 m_strbool
= wxS("bool");
197 m_strlist
= wxS("list");
198 m_strDefaultValue
= wxS("DefaultValue");
199 m_strMin
= wxS("Min");
200 m_strMax
= wxS("Max");
201 m_strUnits
= wxS("Units");
202 m_strInlineHelp
= wxS("InlineHelp");
208 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
212 delete m_defaultRenderer
;
214 // This will always have one ref
215 delete m_fontFamilyChoices
;
218 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
219 delete ((wxValidator
*)m_arrValidators
[i
]);
223 // Destroy value type class instances.
224 wxPGHashMapS2P::iterator vt_it
;
226 // Destroy editor class instances.
227 // iterate over all the elements in the class
228 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
230 delete ((wxPGEditor
*)vt_it
->second
);
233 delete wxPGProperty::sm_wxPG_LABEL
;
236 void wxPropertyGridInitGlobalsIfNeeded()
240 // -----------------------------------------------------------------------
242 // -----------------------------------------------------------------------
245 // wxPGCanvas acts as a graphics sub-window of the
246 // wxScrolledWindow that wxPropertyGrid is.
248 class wxPGCanvas
: public wxPanel
251 wxPGCanvas() : wxPanel()
254 virtual ~wxPGCanvas() { }
257 void OnMouseMove( wxMouseEvent
&event
)
259 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
260 pg
->OnMouseMove( event
);
263 void OnMouseClick( wxMouseEvent
&event
)
265 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
266 pg
->OnMouseClick( event
);
269 void OnMouseUp( wxMouseEvent
&event
)
271 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
272 pg
->OnMouseUp( event
);
275 void OnMouseRightClick( wxMouseEvent
&event
)
277 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
278 pg
->OnMouseRightClick( event
);
281 void OnMouseDoubleClick( wxMouseEvent
&event
)
283 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
284 pg
->OnMouseDoubleClick( event
);
287 void OnKey( wxKeyEvent
& event
)
289 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
293 void OnPaint( wxPaintEvent
& event
);
295 // Always be focussable, even with child windows
296 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
297 { wxPanel::SetCanFocus(true); }
301 DECLARE_EVENT_TABLE()
302 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
306 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
308 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
309 EVT_MOTION(wxPGCanvas::OnMouseMove
)
310 EVT_PAINT(wxPGCanvas::OnPaint
)
311 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
312 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
313 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
314 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
315 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
319 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
321 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
322 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
326 // Don't paint after destruction has begun
327 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
330 // Update everything inside the box
331 wxRect r
= GetUpdateRegion().GetBox();
333 // FIXME: This is just a workaround for a bug that causes splitters not
334 // to paint when other windows are being dragged over the grid.
335 wxRect fullRect
= GetRect();
337 r
.width
= fullRect
.width
;
339 // Repaint this rectangle
340 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
342 // We assume that the size set when grid is shown
343 // is what is desired.
344 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
347 // -----------------------------------------------------------------------
349 // -----------------------------------------------------------------------
351 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
353 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
354 EVT_IDLE(wxPropertyGrid::OnIdle
)
355 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
356 EVT_PAINT(wxPropertyGrid::OnPaint
)
357 EVT_SIZE(wxPropertyGrid::OnResize
)
358 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
359 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
360 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
361 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
362 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
363 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
364 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
365 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
369 // -----------------------------------------------------------------------
371 wxPropertyGrid::wxPropertyGrid()
377 // -----------------------------------------------------------------------
379 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
384 const wxString
& name
)
388 Create(parent
,id
,pos
,size
,style
,name
);
391 // -----------------------------------------------------------------------
393 bool wxPropertyGrid::Create( wxWindow
*parent
,
398 const wxString
& name
)
401 if ( !(style
&wxBORDER_MASK
) )
402 style
|= wxSIMPLE_BORDER
;
406 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
407 style
&= ~(wxTAB_TRAVERSAL
);
408 style
|= wxWANTS_CHARS
;
410 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
417 // -----------------------------------------------------------------------
420 // Initialize values to defaults
422 void wxPropertyGrid::Init1()
424 // Register editor classes, if necessary.
425 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
426 wxPropertyGrid::RegisterDefaultEditors();
430 m_wndEditor
= m_wndEditor2
= NULL
;
434 m_eventObject
= this;
436 m_sortFunction
= NULL
;
437 m_inDoPropertyChanged
= 0;
438 m_inCommitChangesFromEditor
= 0;
439 m_inDoSelectProperty
= 0;
440 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
446 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
447 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
448 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
449 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
450 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
451 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
452 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
453 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
454 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
456 m_coloursCustomized
= 0;
461 #if wxPG_DOUBLE_BUFFER
462 m_doubleBuffer
= NULL
;
465 #ifndef wxPG_ICON_WIDTH
471 m_iconWidth
= wxPG_ICON_WIDTH
;
476 m_gutterWidth
= wxPG_GUTTER_MIN
;
477 m_subgroup_extramargin
= 10;
481 m_width
= m_height
= 0;
483 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
486 m_chgInfo_changedProperty
= NULL
;
489 // -----------------------------------------------------------------------
492 // Initialize after parent etc. set
494 void wxPropertyGrid::Init2()
496 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
499 // Smaller controls on Mac
500 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
503 // Now create state, if one didn't exist already
504 // (wxPropertyGridManager might have created it for us).
507 m_pState
= CreateState();
508 m_pState
->m_pPropGrid
= this;
509 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
512 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
513 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
515 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
517 m_pState
->InitNonCatMode();
519 m_pState
->m_properties
= m_pState
->m_abcArray
;
522 GetClientSize(&m_width
,&m_height
);
524 #ifndef wxPG_ICON_WIDTH
525 // create two bitmap nodes for drawing
526 m_expandbmp
= new wxBitmap(expand_xpm
);
527 m_collbmp
= new wxBitmap(collapse_xpm
);
529 // calculate average font height for bitmap centering
531 m_iconWidth
= m_expandbmp
->GetWidth();
532 m_iconHeight
= m_expandbmp
->GetHeight();
535 m_curcursor
= wxCURSOR_ARROW
;
536 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
538 // adjust bitmap icon y position so they are centered
539 m_vspacing
= wxPG_DEFAULT_VSPACING
;
541 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
543 // Allocate cell datas indirectly by calling setter
544 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
545 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
549 // This helps with flicker
550 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
552 // Hook the top-level parent
556 OnTLPChanging(::wxGetTopLevelParent(this));
558 // set virtual size to this window size
559 wxSize wndsize
= GetSize();
560 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
562 m_timeCreated
= ::wxGetLocalTimeMillis();
564 m_canvas
= new wxPGCanvas();
565 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
566 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
567 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
569 m_iFlags
|= wxPG_FL_INITIALIZED
;
571 m_ncWidth
= wndsize
.GetWidth();
573 // Need to call OnResize handler or size given in constructor/Create
575 wxSizeEvent
sizeEvent(wndsize
,0);
579 // -----------------------------------------------------------------------
581 wxPropertyGrid::~wxPropertyGrid()
585 DoSelectProperty(NULL
);
587 // This should do prevent things from going too badly wrong
588 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
590 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
591 m_canvas
->ReleaseMouse();
593 // Call with NULL to disconnect event handling
596 wxASSERT_MSG( !IsEditorsValueModified(),
597 wxS("Most recent change in property editor was lost!!! ")
598 wxS("(if you don't want this to happen, close your frames ")
599 wxS("and dialogs using Close(false).)") );
601 #if wxPG_DOUBLE_BUFFER
602 if ( m_doubleBuffer
)
603 delete m_doubleBuffer
;
608 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
611 delete m_cursorSizeWE
;
613 #ifndef wxPG_ICON_WIDTH
618 // Delete common value records
619 for ( i
=0; i
<m_commonValues
.size(); i
++ )
621 delete GetCommonValue(i
);
625 // -----------------------------------------------------------------------
627 bool wxPropertyGrid::Destroy()
629 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
630 m_canvas
->ReleaseMouse();
632 return wxScrolledWindow::Destroy();
635 // -----------------------------------------------------------------------
637 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
639 return new wxPropertyGridPageState();
642 // -----------------------------------------------------------------------
643 // wxPropertyGrid overridden wxWindow methods
644 // -----------------------------------------------------------------------
646 void wxPropertyGrid::SetWindowStyleFlag( long style
)
648 long old_style
= m_windowStyle
;
650 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
652 wxASSERT( m_pState
);
654 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
657 EnableCategories( true );
659 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
661 // Disable categories
662 EnableCategories( false );
664 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
670 PrepareAfterItemsAdded();
672 m_pState
->m_itemsAdded
= 1;
674 #if wxPG_SUPPORT_TOOLTIPS
675 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
681 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
682 SetToolTip ( tooltip );
683 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
686 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
691 m_canvas
->SetToolTip( NULL
);
696 wxScrolledWindow::SetWindowStyleFlag ( style
);
698 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
700 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
702 CalculateFontAndBitmapStuff( m_vspacing
);
708 // -----------------------------------------------------------------------
710 void wxPropertyGrid::Freeze()
714 wxScrolledWindow::Freeze();
719 // -----------------------------------------------------------------------
721 void wxPropertyGrid::Thaw()
727 wxScrolledWindow::Thaw();
728 RecalculateVirtualSize();
729 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
733 // Force property re-selection
735 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
739 // -----------------------------------------------------------------------
741 void wxPropertyGrid::SetExtraStyle( long exStyle
)
743 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
745 #if defined(__WXMSW__)
748 // Don't use WS_EX_COMPOSITED just now.
751 if ( m_iFlags & wxPG_FL_IN_MANAGER )
752 hWnd = (HWND)GetParent()->GetHWND();
754 hWnd = (HWND)GetHWND();
756 ::SetWindowLong( hWnd, GWL_EXSTYLE,
757 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
760 //#elif defined(__WXGTK20__)
762 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
763 // truly was double-buffered.
764 if ( !this->IsDoubleBuffered() )
766 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
770 #if wxPG_DOUBLE_BUFFER
771 delete m_doubleBuffer
;
772 m_doubleBuffer
= NULL
;
777 wxScrolledWindow::SetExtraStyle( exStyle
);
779 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
780 m_pState
->InitNonCatMode();
782 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
783 m_windowStyle
|= wxPG_TOOLTIPS
;
786 wxPGGlobalVars
->m_extraStyle
= exStyle
;
789 // -----------------------------------------------------------------------
791 // returns the best acceptable minimal size
792 wxSize
wxPropertyGrid::DoGetBestSize() const
794 int lineHeight
= wxMax(15, m_lineHeight
);
796 // don't make the grid too tall (limit height to 10 items) but don't
797 // make it too small neither
800 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
804 const wxSize sz
= wxSize(60, lineHeight
*numLines
+ 40);
809 // -----------------------------------------------------------------------
811 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
813 wxLongLong currentTime
= ::wxGetLocalTimeMillis();
816 // Parent changed so let's redetermine and re-hook the
817 // correct top-level window.
820 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
821 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
824 m_tlpClosedTime
= currentTime
;
829 // Only accept new tlp if same one was not just dismissed.
830 if ( newTLP
!= m_tlpClosed
||
831 m_tlpClosedTime
+250 < currentTime
)
833 newTLP
->Connect( wxEVT_CLOSE_WINDOW
,
834 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
847 // -----------------------------------------------------------------------
849 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
851 // ClearSelection forces value validation/commit.
852 if ( event
.CanVeto() && !DoClearSelection() )
858 // Ok, it can close, set tlp pointer to NULL. Some other event
859 // handler can of course veto the close, but our OnIdle() should
860 // then be able to regain the tlp pointer.
866 // -----------------------------------------------------------------------
868 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
870 OnTLPChanging((wxWindow
*)newParent
);
872 bool res
= wxScrolledWindow::Reparent(newParent
);
877 // -----------------------------------------------------------------------
878 // wxPropertyGrid Font and Colour Methods
879 // -----------------------------------------------------------------------
881 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
885 m_captionFont
= wxScrolledWindow::GetFont();
887 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
888 m_subgroup_extramargin
= x
+ (x
/2);
891 #if wxPG_USE_RENDERER_NATIVE
892 m_iconWidth
= wxPG_ICON_WIDTH
;
893 #elif wxPG_ICON_WIDTH
895 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
896 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
897 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
901 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
902 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
903 m_gutterWidth
= wxPG_GUTTER_MIN
;
906 if ( vspacing
<= 1 ) vdiv
= 12;
907 else if ( vspacing
>= 3 ) vdiv
= 3;
909 m_spacingy
= m_fontHeight
/ vdiv
;
910 if ( m_spacingy
< wxPG_YSPACING_MIN
)
911 m_spacingy
= wxPG_YSPACING_MIN
;
914 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
915 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
917 m_captionFont
.SetWeight(wxBOLD
);
918 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
920 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
923 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
924 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
927 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
929 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
930 RecalculateVirtualSize();
932 InvalidateBestSize();
935 // -----------------------------------------------------------------------
937 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
943 // -----------------------------------------------------------------------
945 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
946 int ga
= 1000, int ba
= 1000,
947 bool forceDifferent
= false)
954 // Recursion guard (allow 2 max)
955 static int isinside
= 0;
957 wxCHECK_MSG( isinside
< 3,
959 wxT("wxPGAdjustColour should not be recursively called more than once") );
967 if ( r2
>255 ) r2
= 255;
968 else if ( r2
<0) r2
= 0;
970 if ( g2
>255 ) g2
= 255;
971 else if ( g2
<0) g2
= 0;
973 if ( b2
>255 ) b2
= 255;
974 else if ( b2
<0) b2
= 0;
976 // Make sure they are somewhat different
977 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
978 dst
= wxPGAdjustColour(src
,-(ra
*2));
980 dst
= wxColour(r2
,g2
,b2
);
982 // Recursion guard (allow 2 max)
989 static int wxPGGetColAvg( const wxColour
& col
)
991 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
995 void wxPropertyGrid::RegainColours()
997 if ( !(m_coloursCustomized
& 0x0002) )
999 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1001 // Make sure colour is dark enough
1003 int colDec
= wxPGGetColAvg(col
) - 230;
1005 int colDec
= wxPGGetColAvg(col
) - 200;
1008 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1011 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1014 if ( !(m_coloursCustomized
& 0x0001) )
1015 m_colMargin
= m_colCapBack
;
1017 if ( !(m_coloursCustomized
& 0x0004) )
1024 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1025 m_colCapFore
= capForeCol
;
1026 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1029 if ( !(m_coloursCustomized
& 0x0008) )
1031 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1032 m_colPropBack
= bgCol
;
1033 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1036 if ( !(m_coloursCustomized
& 0x0010) )
1038 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1039 m_colPropFore
= fgCol
;
1040 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1043 if ( !(m_coloursCustomized
& 0x0020) )
1044 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1046 if ( !(m_coloursCustomized
& 0x0040) )
1047 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1049 if ( !(m_coloursCustomized
& 0x0080) )
1050 m_colLine
= m_colCapBack
;
1052 if ( !(m_coloursCustomized
& 0x0100) )
1053 m_colDisPropFore
= m_colCapFore
;
1055 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1058 // -----------------------------------------------------------------------
1060 void wxPropertyGrid::ResetColours()
1062 m_coloursCustomized
= 0;
1069 // -----------------------------------------------------------------------
1071 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1073 // Must disable active editor.
1076 bool res
= wxScrolledWindow::SetFont( font
);
1077 if ( res
&& GetParent()) // may not have been Create()ed yet
1079 CalculateFontAndBitmapStuff( m_vspacing
);
1086 // -----------------------------------------------------------------------
1088 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1091 m_coloursCustomized
|= 0x80;
1095 // -----------------------------------------------------------------------
1097 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1100 m_coloursCustomized
|= 0x01;
1104 // -----------------------------------------------------------------------
1106 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1108 m_colPropBack
= col
;
1109 m_coloursCustomized
|= 0x08;
1111 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1116 // -----------------------------------------------------------------------
1118 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1120 m_colPropFore
= col
;
1121 m_coloursCustomized
|= 0x10;
1123 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1128 // -----------------------------------------------------------------------
1130 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1132 m_colEmptySpace
= col
;
1137 // -----------------------------------------------------------------------
1139 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1141 m_colDisPropFore
= col
;
1142 m_coloursCustomized
|= 0x100;
1146 // -----------------------------------------------------------------------
1148 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1151 m_coloursCustomized
|= 0x20;
1155 // -----------------------------------------------------------------------
1157 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1160 m_coloursCustomized
|= 0x40;
1164 // -----------------------------------------------------------------------
1166 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1169 m_coloursCustomized
|= 0x02;
1171 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1176 // -----------------------------------------------------------------------
1178 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1181 m_coloursCustomized
|= 0x04;
1183 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1188 // -----------------------------------------------------------------------
1189 // wxPropertyGrid property adding and removal
1190 // -----------------------------------------------------------------------
1192 void wxPropertyGrid::PrepareAfterItemsAdded()
1194 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1196 m_pState
->m_itemsAdded
= 0;
1198 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1199 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1201 RecalculateVirtualSize();
1204 // -----------------------------------------------------------------------
1205 // wxPropertyGrid property operations
1206 // -----------------------------------------------------------------------
1208 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1210 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1214 bool changed
= false;
1216 // Is it inside collapsed section?
1217 if ( !p
->IsVisible() )
1220 wxPGProperty
* parent
= p
->GetParent();
1221 wxPGProperty
* grandparent
= parent
->GetParent();
1223 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1224 Expand( grandparent
);
1232 GetViewStart(&vx
,&vy
);
1233 vy
*=wxPG_PIXELS_PER_UNIT
;
1239 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1240 m_iFlags
|= wxPG_FL_SCROLLED
;
1243 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1245 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1246 m_iFlags
|= wxPG_FL_SCROLLED
;
1256 // -----------------------------------------------------------------------
1257 // wxPropertyGrid helper methods called by properties
1258 // -----------------------------------------------------------------------
1260 // Control font changer helper.
1261 void wxPropertyGrid::SetCurControlBoldFont()
1263 wxASSERT( m_wndEditor
);
1264 m_wndEditor
->SetFont( m_captionFont
);
1267 // -----------------------------------------------------------------------
1269 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1272 #if wxPG_SMALL_SCREEN
1273 // On small-screen devices, always show dialogs with default position and size.
1274 return wxDefaultPosition
;
1276 int splitterX
= GetSplitterPosition();
1280 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1282 ImprovedClientToScreen( &x
, &y
);
1284 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1285 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1292 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1302 new_y
= y
+ m_lineHeight
;
1304 return wxPoint(new_x
,new_y
);
1308 // -----------------------------------------------------------------------
1310 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1312 if ( src_str
.length() == 0 )
1318 bool prev_is_slash
= false;
1320 wxString::const_iterator i
= src_str
.begin();
1324 for ( ; i
!= src_str
.end(); ++i
)
1328 if ( a
!= wxS('\\') )
1330 if ( !prev_is_slash
)
1336 if ( a
== wxS('n') )
1339 dst_str
<< wxS('\n');
1341 dst_str
<< wxS('\n');
1344 else if ( a
== wxS('t') )
1345 dst_str
<< wxS('\t');
1349 prev_is_slash
= false;
1353 if ( prev_is_slash
)
1355 dst_str
<< wxS('\\');
1356 prev_is_slash
= false;
1360 prev_is_slash
= true;
1367 // -----------------------------------------------------------------------
1369 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1371 if ( src_str
.length() == 0 )
1377 wxString::const_iterator i
= src_str
.begin();
1378 wxUniChar prev_a
= wxS('\0');
1382 for ( ; i
!= src_str
.end(); ++i
)
1386 if ( a
>= wxS(' ') )
1388 // This surely is not something that requires an escape sequence.
1393 // This might need...
1394 if ( a
== wxS('\r') )
1396 // DOS style line end.
1397 // Already taken care below
1399 else if ( a
== wxS('\n') )
1400 // UNIX style line end.
1401 dst_str
<< wxS("\\n");
1402 else if ( a
== wxS('\t') )
1404 dst_str
<< wxS('\t');
1407 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1417 // -----------------------------------------------------------------------
1419 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1426 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1429 // -----------------------------------------------------------------------
1430 // wxPropertyGrid graphics related methods
1431 // -----------------------------------------------------------------------
1433 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1437 // Update everything inside the box
1438 wxRect r
= GetUpdateRegion().GetBox();
1440 dc
.SetPen(m_colEmptySpace
);
1441 dc
.SetBrush(m_colEmptySpace
);
1442 dc
.DrawRectangle(r
);
1445 // -----------------------------------------------------------------------
1447 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1448 wxPGProperty
* property
) const
1450 // Prepare rectangle to be used
1452 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1453 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1455 #if (wxPG_USE_RENDERER_NATIVE)
1457 #elif wxPG_ICON_WIDTH
1458 // Drawing expand/collapse button manually
1459 dc
.SetPen(m_colPropFore
);
1460 if ( property
->IsCategory() )
1461 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1463 dc
.SetBrush(m_colPropBack
);
1465 dc
.DrawRectangle( r
);
1466 int _y
= r
.y
+(m_iconWidth
/2);
1467 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1472 if ( property
->IsExpanded() )
1474 // wxRenderer functions are non-mutating in nature, so it
1475 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1476 // Hopefully this does not cause problems.
1477 #if (wxPG_USE_RENDERER_NATIVE)
1478 wxRendererNative::Get().DrawTreeItemButton(
1484 #elif wxPG_ICON_WIDTH
1493 #if (wxPG_USE_RENDERER_NATIVE)
1494 wxRendererNative::Get().DrawTreeItemButton(
1500 #elif wxPG_ICON_WIDTH
1501 int _x
= r
.x
+(m_iconWidth
/2);
1502 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1508 #if (wxPG_USE_RENDERER_NATIVE)
1510 #elif wxPG_ICON_WIDTH
1513 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1517 // -----------------------------------------------------------------------
1520 // This is the one called by OnPaint event handler and others.
1521 // topy and bottomy are already unscrolled (ie. physical)
1523 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1525 unsigned int bottomy
,
1526 const wxRect
* clipRect
)
1528 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1530 m_pState
->EnsureVirtualHeight();
1532 wxRect tempClipRect
;
1535 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1536 clipRect
= &tempClipRect
;
1539 // items added check
1540 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1542 int paintFinishY
= 0;
1544 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1547 bool isBuffered
= false;
1549 #if wxPG_DOUBLE_BUFFER
1550 wxMemoryDC
* bufferDC
= NULL
;
1552 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1554 if ( !m_doubleBuffer
)
1556 paintFinishY
= clipRect
->y
;
1561 bufferDC
= new wxMemoryDC();
1563 // If nothing was changed, then just copy from double-buffer
1564 bufferDC
->SelectObject( *m_doubleBuffer
);
1574 dc
.SetClippingRegion( *clipRect
);
1575 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1578 #if wxPG_DOUBLE_BUFFER
1581 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1582 bufferDC
, 0, 0, wxCOPY
);
1583 dc
.DestroyClippingRegion(); // Is this really necessary?
1589 // Clear area beyond bottomY?
1590 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1592 dc
.SetPen(m_colEmptySpace
);
1593 dc
.SetBrush(m_colEmptySpace
);
1594 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1598 // -----------------------------------------------------------------------
1600 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1601 const wxRect
* clipRect
,
1602 bool isBuffered
) const
1604 const wxPGProperty
* firstItem
;
1605 const wxPGProperty
* lastItem
;
1607 firstItem
= DoGetItemAtY(clipRect
->y
);
1608 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1611 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1613 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1616 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1617 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1619 int lh
= m_lineHeight
;
1622 int lastItemBottomY
;
1624 firstItemTopY
= clipRect
->y
;
1625 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1627 // Align y coordinates to item boundaries
1628 firstItemTopY
-= firstItemTopY
% lh
;
1629 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1630 lastItemBottomY
-= 1;
1632 // Entire range outside scrolled, visible area?
1633 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1636 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1640 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1641 firstItem->GetLabel().c_str(),
1642 lastItem->GetLabel().c_str(),
1643 (int)(lastItemBottomY - firstItemTopY),
1645 (unsigned long)clipRect );
1650 long windowStyle
= m_windowStyle
;
1656 // With wxPG_DOUBLE_BUFFER, do double buffering
1657 // - buffer's y = 0, so align cliprect and coordinates to that
1659 #if wxPG_DOUBLE_BUFFER
1665 xRelMod
= clipRect
->x
;
1666 yRelMod
= clipRect
->y
;
1669 // clipRect conversion
1674 firstItemTopY
-= yRelMod
;
1675 lastItemBottomY
-= yRelMod
;
1678 wxUnusedVar(isBuffered
);
1681 int x
= m_marginWidth
- xRelMod
;
1683 wxFont normalFont
= GetFont();
1685 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1687 bool isEnabled
= IsEnabled();
1690 // Prepare some pens and brushes that are often changed to.
1693 wxBrush
marginBrush(m_colMargin
);
1694 wxPen
marginPen(m_colMargin
);
1695 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1696 wxPen
linepen(m_colLine
,1,wxSOLID
);
1698 // pen that has same colour as text
1699 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1702 // Clear margin with background colour
1704 dc
.SetBrush( marginBrush
);
1705 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1707 dc
.SetPen( *wxTRANSPARENT_PEN
);
1708 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1711 const wxPGProperty
* selected
= m_selected
;
1712 const wxPropertyGridPageState
* state
= m_pState
;
1714 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1715 bool wasSelectedPainted
= false;
1718 // TODO: Only render columns that are within clipping region.
1720 dc
.SetFont(normalFont
);
1722 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1723 int endScanBottomY
= lastItemBottomY
+ lh
;
1724 int y
= firstItemTopY
;
1727 // Pregenerate list of visible properties.
1728 wxArrayPGProperty visPropArray
;
1729 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1731 for ( ; !it
.AtEnd(); it
.Next() )
1733 const wxPGProperty
* p
= *it
;
1735 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1737 visPropArray
.push_back((wxPGProperty
*)p
);
1739 if ( y
> endScanBottomY
)
1746 visPropArray
.push_back(NULL
);
1748 wxPGProperty
* nextP
= visPropArray
[0];
1750 int gridWidth
= state
->m_width
;
1753 for ( unsigned int arrInd
=1;
1754 nextP
&& y
<= lastItemBottomY
;
1757 wxPGProperty
* p
= nextP
;
1758 nextP
= visPropArray
[arrInd
];
1760 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1761 int textMarginHere
= x
;
1762 int renderFlags
= 0;
1764 int greyDepth
= m_marginWidth
;
1765 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1766 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1768 int greyDepthX
= greyDepth
- xRelMod
;
1770 // Use basic depth if in non-categoric mode and parent is base array.
1771 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1773 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1776 // Paint margin area
1777 dc
.SetBrush(marginBrush
);
1778 dc
.SetPen(marginPen
);
1779 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1781 dc
.SetPen( linepen
);
1786 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1792 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1794 sx
+= state
->m_colWidths
[si
];
1795 dc
.DrawLine( sx
, y
, sx
, y2
);
1798 // Horizontal Line, below
1799 // (not if both this and next is category caption)
1800 if ( p
->IsCategory() &&
1801 nextP
&& nextP
->IsCategory() )
1802 dc
.SetPen(m_colCapBack
);
1804 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1807 // Need to override row colours?
1811 if ( p
!= selected
)
1813 // Disabled may get different colour.
1814 if ( !p
->IsEnabled() )
1816 renderFlags
|= wxPGCellRenderer::Disabled
|
1817 wxPGCellRenderer::DontUseCellFgCol
;
1818 rowFgCol
= m_colDisPropFore
;
1823 renderFlags
|= wxPGCellRenderer::Selected
;
1825 if ( !p
->IsCategory() )
1827 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1828 wxPGCellRenderer::DontUseCellBgCol
;
1830 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1831 wasSelectedPainted
= true;
1834 // Selected gets different colour.
1835 if ( reallyFocused
)
1837 rowFgCol
= m_colSelFore
;
1838 rowBgCol
= m_colSelBack
;
1840 else if ( isEnabled
)
1842 rowFgCol
= m_colPropFore
;
1843 rowBgCol
= m_colMargin
;
1847 rowFgCol
= m_colDisPropFore
;
1848 rowBgCol
= m_colSelBack
;
1855 if ( rowBgCol
.IsOk() )
1856 rowBgBrush
= wxBrush(rowBgCol
);
1858 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1859 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1862 // Fill additional margin area with background colour of first cell
1863 if ( greyDepthX
< textMarginHere
)
1865 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1867 wxPGCell
& cell
= p
->GetCell(0);
1868 rowBgCol
= cell
.GetBgCol();
1869 rowBgBrush
= wxBrush(rowBgCol
);
1871 dc
.SetBrush(rowBgBrush
);
1872 dc
.SetPen(rowBgCol
);
1873 dc
.DrawRectangle(greyDepthX
+1, y
,
1874 textMarginHere
-greyDepthX
, lh
-1);
1877 bool fontChanged
= false;
1879 // Expander button rectangle
1880 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1885 if ( p
->IsCategory() )
1887 // Captions have their cell areas merged as one
1888 dc
.SetFont(m_captionFont
);
1890 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1892 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1894 dc
.SetBrush(rowBgBrush
);
1895 dc
.SetPen(rowBgCol
);
1898 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1900 dc
.SetTextForeground(rowFgCol
);
1903 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1904 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1907 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1908 DrawExpanderButton( dc
, butRect
, p
);
1912 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1914 dc
.SetFont(m_captionFont
);
1920 int nextCellWidth
= state
->m_colWidths
[0] -
1921 (greyDepthX
- m_marginWidth
);
1922 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1923 int textXAdd
= textMarginHere
- greyDepthX
;
1925 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1927 cellRect
.width
= nextCellWidth
- 1;
1929 bool ctrlCell
= false;
1930 int cellRenderFlags
= renderFlags
;
1933 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1934 DrawExpanderButton( dc
, butRect
, p
);
1937 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1939 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1940 dc
.SetBrush(editorBgCol
);
1941 dc
.SetPen(editorBgCol
);
1942 dc
.SetTextForeground(m_colPropFore
);
1943 dc
.DrawRectangle(cellRect
);
1945 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1950 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1952 dc
.SetBrush(rowBgBrush
);
1953 dc
.SetPen(rowBgCol
);
1956 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1958 dc
.SetTextForeground(rowFgCol
);
1962 dc
.SetClippingRegion(cellRect
);
1964 cellRect
.x
+= textXAdd
;
1965 cellRect
.width
-= textXAdd
;
1970 wxPGCellRenderer
* renderer
;
1971 int cmnVal
= p
->GetCommonValue();
1972 if ( cmnVal
== -1 || ci
!= 1 )
1974 renderer
= p
->GetCellRenderer(ci
);
1975 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1980 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1981 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1986 cellX
+= state
->m_colWidths
[ci
];
1987 if ( ci
< (state
->m_colWidths
.size()-1) )
1988 nextCellWidth
= state
->m_colWidths
[ci
+1];
1990 dc
.DestroyClippingRegion(); // Is this really necessary?
1996 dc
.SetFont(normalFont
);
2001 // Refresh editor controls (seems not needed on msw)
2002 // NOTE: This code is mandatory for GTK!
2003 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2004 if ( wasSelectedPainted
)
2007 m_wndEditor
->Refresh();
2009 m_wndEditor2
->Refresh();
2016 // -----------------------------------------------------------------------
2018 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2022 if ( m_width
< 10 || m_height
< 10 ||
2023 !m_pState
->m_properties
->GetChildCount() ||
2025 return wxRect(0,0,0,0);
2030 // Return rect which encloses the given property range
2032 int visTop
= p1
->GetY();
2035 visBottom
= p2
->GetY() + m_lineHeight
;
2037 visBottom
= m_height
+ visTop
;
2039 // If seleced property is inside the range, we'll extend the range to include
2041 wxPGProperty
* selected
= m_selected
;
2044 int selectedY
= selected
->GetY();
2045 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2047 wxWindow
* editor
= GetEditorControl();
2050 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2051 if ( visBottom2
> visBottom
)
2052 visBottom
= visBottom2
;
2057 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2060 // -----------------------------------------------------------------------
2062 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2067 if ( m_pState
->m_itemsAdded
)
2068 PrepareAfterItemsAdded();
2070 wxRect r
= GetPropertyRect(p1
, p2
);
2073 m_canvas
->RefreshRect(r
);
2077 // -----------------------------------------------------------------------
2079 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2081 if ( p
== m_selected
)
2082 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2084 DrawItemAndChildren(p
);
2087 // -----------------------------------------------------------------------
2089 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2094 // Draw item, children, and parent too, if it is not category
2095 wxPGProperty
* parent
= p
->GetParent();
2098 !parent
->IsCategory() &&
2099 parent
->GetParent() )
2102 parent
= parent
->GetParent();
2105 DrawItemAndChildren(p
);
2108 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2110 wxCHECK_RET( p
, wxT("invalid property id") );
2112 // Do not draw if in non-visible page
2113 if ( p
->GetParentState() != m_pState
)
2116 // do not draw a single item if multiple pending
2117 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2120 // Update child control.
2121 if ( m_selected
&& m_selected
->GetParent() == p
)
2124 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2126 DrawItems(p
, lastDrawn
);
2129 // -----------------------------------------------------------------------
2131 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2132 const wxRect
*rect
)
2134 PrepareAfterItemsAdded();
2136 wxWindow::Refresh(false);
2138 // TODO: Coordinate translation
2139 m_canvas
->Refresh(false, rect
);
2141 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2142 // I think this really helps only GTK+1.2
2143 if ( m_wndEditor
) m_wndEditor
->Refresh();
2144 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2148 // -----------------------------------------------------------------------
2149 // wxPropertyGrid global operations
2150 // -----------------------------------------------------------------------
2152 void wxPropertyGrid::Clear()
2154 m_pState
->DoClear();
2160 RecalculateVirtualSize();
2162 // Need to clear some area at the end
2164 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2167 // -----------------------------------------------------------------------
2169 bool wxPropertyGrid::EnableCategories( bool enable
)
2176 // Enable categories
2179 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2184 // Disable categories
2186 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2189 if ( !m_pState
->EnableCategories(enable
) )
2194 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2196 m_pState
->m_itemsAdded
= 1; // force
2197 PrepareAfterItemsAdded();
2201 m_pState
->m_itemsAdded
= 1;
2203 // No need for RecalculateVirtualSize() here - it is already called in
2204 // wxPropertyGridPageState method above.
2211 // -----------------------------------------------------------------------
2213 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2215 wxASSERT( pNewState
);
2216 wxASSERT( pNewState
->GetGrid() );
2218 if ( pNewState
== m_pState
)
2221 wxPGProperty
* oldSelection
= m_selected
;
2225 m_pState
->m_selected
= oldSelection
;
2227 bool orig_mode
= m_pState
->IsInNonCatMode();
2228 bool new_state_mode
= pNewState
->IsInNonCatMode();
2230 m_pState
= pNewState
;
2233 int pgWidth
= GetClientSize().x
;
2234 if ( HasVirtualWidth() )
2236 int minWidth
= pgWidth
;
2237 if ( pNewState
->m_width
< minWidth
)
2239 pNewState
->m_width
= minWidth
;
2240 pNewState
->CheckColumnWidths();
2246 // Just in case, fully re-center splitter
2247 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2248 pNewState
->m_fSplitterX
= -1.0;
2250 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2255 // If necessary, convert state to correct mode.
2256 if ( orig_mode
!= new_state_mode
)
2258 // This should refresh as well.
2259 EnableCategories( orig_mode
?false:true );
2261 else if ( !m_frozen
)
2263 // Refresh, if not frozen.
2264 m_pState
->PrepareAfterItemsAdded();
2267 if ( m_pState
->m_selected
)
2268 DoSelectProperty( m_pState
->m_selected
);
2270 RecalculateVirtualSize(0);
2274 m_pState
->m_itemsAdded
= 1;
2277 // -----------------------------------------------------------------------
2279 // Call to SetSplitterPosition will always disable splitter auto-centering
2280 // if parent window is shown.
2281 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2283 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2286 wxPropertyGridPageState
* state
= m_pState
;
2288 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2293 CorrectEditorWidgetSizeX();
2299 // -----------------------------------------------------------------------
2301 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2303 SetSplitterPosition( m_width
/2, true );
2304 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2305 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2308 // -----------------------------------------------------------------------
2309 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2310 // -----------------------------------------------------------------------
2312 // Returns nearest paint visible property (such that will be painted unless
2313 // window is scrolled or resized). If given property is paint visible, then
2314 // it itself will be returned
2315 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2317 int vx
,vy1
;// Top left corner of client
2318 GetViewStart(&vx
,&vy1
);
2319 vy1
*= wxPG_PIXELS_PER_UNIT
;
2321 int vy2
= vy1
+ m_height
;
2322 int propY
= p
->GetY2(m_lineHeight
);
2324 if ( (propY
+ m_lineHeight
) < vy1
)
2327 return DoGetItemAtY( vy1
);
2329 else if ( propY
> vy2
)
2332 return DoGetItemAtY( vy2
);
2335 // Itself paint visible
2340 // -----------------------------------------------------------------------
2341 // Methods related to change in value, value modification and sending events
2342 // -----------------------------------------------------------------------
2344 // commits any changes in editor of selected property
2345 // return true if validation did not fail
2346 // flags are same as with DoSelectProperty
2347 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2349 // Committing already?
2350 if ( m_inCommitChangesFromEditor
)
2353 // Don't do this if already processing editor event. It might
2354 // induce recursive dialogs and crap like that.
2355 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2357 if ( m_inDoPropertyChanged
)
2364 IsEditorsValueModified() &&
2365 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2368 m_inCommitChangesFromEditor
= 1;
2370 wxVariant
variant(m_selected
->GetValueRef());
2371 bool valueIsPending
= false;
2373 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2374 // due to another window getting focus
2375 wxWindow
* oldFocus
= m_curFocused
;
2377 bool validationFailure
= false;
2378 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2380 m_chgInfo_changedProperty
= NULL
;
2382 // If truly modified, schedule value as pending.
2383 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2385 if ( DoEditorValidate() &&
2386 PerformValidation(m_selected
, variant
) )
2388 valueIsPending
= true;
2392 validationFailure
= true;
2397 EditorsValueWasNotModified();
2402 m_inCommitChangesFromEditor
= 0;
2404 if ( validationFailure
&& !forceSuccess
)
2408 oldFocus
->SetFocus();
2409 m_curFocused
= oldFocus
;
2412 res
= OnValidationFailure(m_selected
, variant
);
2414 // Now prevent further validation failure messages
2417 EditorsValueWasNotModified();
2418 OnValidationFailureReset(m_selected
);
2421 else if ( valueIsPending
)
2423 DoPropertyChanged( m_selected
, flags
);
2424 EditorsValueWasNotModified();
2433 // -----------------------------------------------------------------------
2435 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2439 // Runs all validation functionality.
2440 // Returns true if value passes all tests.
2443 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2445 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2447 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2452 // Adapt list to child values, if necessary
2453 wxVariant listValue
= pendingValue
;
2454 wxVariant
* pPendingValue
= &pendingValue
;
2455 wxVariant
* pList
= NULL
;
2457 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2458 // string value, then we need treat as it was changed instead
2459 // (or, in addition, as is the case with composite string parent).
2460 // This includes creating list variant for child values.
2462 wxPGProperty
* pwc
= p
->GetParent();
2463 wxPGProperty
* changedProperty
= p
;
2464 wxPGProperty
* baseChangedProperty
= changedProperty
;
2465 wxVariant bcpPendingList
;
2467 listValue
= pendingValue
;
2468 listValue
.SetName(p
->GetBaseName());
2471 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2473 wxVariantList tempList
;
2474 wxVariant
lv(tempList
, pwc
->GetBaseName());
2475 lv
.Append(listValue
);
2477 pPendingValue
= &listValue
;
2479 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2481 baseChangedProperty
= pwc
;
2482 bcpPendingList
= lv
;
2485 changedProperty
= pwc
;
2486 pwc
= pwc
->GetParent();
2490 wxPGProperty
* evtChangingProperty
= changedProperty
;
2492 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2494 value
= *pPendingValue
;
2498 // Convert list to child values
2499 pList
= pPendingValue
;
2500 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2503 wxVariant evtChangingValue
= value
;
2505 if ( flags
& SendEvtChanging
)
2507 // FIXME: After proper ValueToString()s added, remove
2508 // this. It is just a temporary fix, as evt_changing
2509 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2510 // (unless it is selected, and textctrl editor is open).
2511 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2513 evtChangingProperty
= baseChangedProperty
;
2514 if ( evtChangingProperty
!= p
)
2516 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2520 evtChangingValue
= pendingValue
;
2524 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2526 if ( changedProperty
== m_selected
)
2528 wxWindow
* editor
= GetEditorControl();
2529 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2530 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2534 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2539 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2540 m_chgInfo_changedProperty
= changedProperty
;
2541 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2542 m_chgInfo_pendingValue
= value
;
2545 m_chgInfo_valueList
= *pList
;
2547 m_chgInfo_valueList
.MakeNull();
2549 // If changedProperty is not property which value was edited,
2550 // then call wxPGProperty::ValidateValue() for that as well.
2551 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2553 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2557 if ( flags
& SendEvtChanging
)
2559 // SendEvent returns true if event was vetoed
2560 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2564 if ( flags
& IsStandaloneValidation
)
2566 // If called in 'generic' context, we need to reset
2567 // m_chgInfo_changedProperty and write back translated value.
2568 m_chgInfo_changedProperty
= NULL
;
2569 pendingValue
= value
;
2575 // -----------------------------------------------------------------------
2577 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2579 if ( !msg
.length() )
2583 if ( !wxPGGlobalVars
->m_offline
)
2585 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2588 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2591 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2594 pStatusBar
->SetStatusText(msg
);
2602 ::wxMessageBox(msg
, wxT("Property Error"));
2605 // -----------------------------------------------------------------------
2607 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2608 wxVariant
& invalidValue
)
2610 wxWindow
* editor
= GetEditorControl();
2612 // First call property's handler
2613 property
->OnValidationFailure(invalidValue
);
2615 bool res
= DoOnValidationFailure(property
, invalidValue
);
2618 // For non-wxTextCtrl editors, we do need to revert the value
2619 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2620 property
== m_selected
)
2622 property
->GetEditorClass()->UpdateControl(property
, editor
);
2625 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2630 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2632 int vfb
= m_validationInfo
.m_failureBehavior
;
2634 if ( vfb
& wxPG_VFB_BEEP
)
2637 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2638 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2640 unsigned int colCount
= m_pState
->GetColumnCount();
2642 // We need backup marked property's cells
2643 m_propCellsBackup
= property
->m_cells
;
2645 wxColour vfbFg
= *wxWHITE
;
2646 wxColour vfbBg
= *wxRED
;
2648 property
->EnsureCells(colCount
);
2650 for ( unsigned int i
=0; i
<colCount
; i
++ )
2652 wxPGCell
& cell
= property
->m_cells
[i
];
2653 cell
.SetFgCol(vfbFg
);
2654 cell
.SetBgCol(vfbBg
);
2657 DrawItemAndChildren(property
);
2659 if ( property
== m_selected
)
2661 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2663 wxWindow
* editor
= GetEditorControl();
2666 editor
->SetForegroundColour(vfbFg
);
2667 editor
->SetBackgroundColour(vfbBg
);
2672 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2674 wxString msg
= m_validationInfo
.m_failureMessage
;
2676 if ( !msg
.length() )
2677 msg
= wxT("You have entered invalid value. Press ESC to cancel editing.");
2679 DoShowPropertyError(property
, msg
);
2682 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2685 // -----------------------------------------------------------------------
2687 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2689 int vfb
= m_validationInfo
.m_failureBehavior
;
2691 if ( vfb
& wxPG_VFB_MARK_CELL
)
2694 property
->m_cells
= m_propCellsBackup
;
2696 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2698 if ( property
== m_selected
&& GetEditorControl() )
2700 // Calling this will recreate the control, thus resetting its colour
2701 RefreshProperty(property
);
2705 DrawItemAndChildren(property
);
2710 // -----------------------------------------------------------------------
2712 // flags are same as with DoSelectProperty
2713 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2715 if ( m_inDoPropertyChanged
)
2718 wxWindow
* editor
= GetEditorControl();
2720 m_pState
->m_anyModified
= 1;
2722 m_inDoPropertyChanged
= 1;
2724 // Maybe need to update control
2725 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2727 // These values were calculated in PerformValidation()
2728 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2729 wxVariant value
= m_chgInfo_pendingValue
;
2731 wxPGProperty
* topPaintedProperty
= changedProperty
;
2733 while ( !topPaintedProperty
->IsCategory() &&
2734 !topPaintedProperty
->IsRoot() )
2736 topPaintedProperty
= topPaintedProperty
->GetParent();
2739 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2741 // Set as Modified (not if dragging just began)
2742 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2744 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2745 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2748 SetCurControlBoldFont();
2754 // Propagate updates to parent(s)
2756 wxPGProperty
* prevPwc
= NULL
;
2758 while ( prevPwc
!= topPaintedProperty
)
2760 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2762 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2765 SetCurControlBoldFont();
2769 pwc
= pwc
->GetParent();
2772 // Draw the actual property
2773 DrawItemAndChildren( topPaintedProperty
);
2776 // If value was set by wxPGProperty::OnEvent, then update the editor
2778 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2784 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2785 if ( m_wndEditor
) m_wndEditor
->Refresh();
2786 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2791 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2793 // If top parent has composite string value, then send to child parents,
2794 // starting from baseChangedProperty.
2795 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2797 pwc
= m_chgInfo_baseChangedProperty
;
2799 while ( pwc
!= changedProperty
)
2801 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2802 pwc
= pwc
->GetParent();
2806 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2808 m_inDoPropertyChanged
= 0;
2813 // -----------------------------------------------------------------------
2815 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2817 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2819 m_chgInfo_changedProperty
= NULL
;
2821 if ( PerformValidation(p
, newValue
) )
2823 DoPropertyChanged(p
);
2828 OnValidationFailure(p
, newValue
);
2834 // -----------------------------------------------------------------------
2836 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2838 wxPGProperty
* prop
= GetSelectedProperty();
2841 return wxNullVariant
;
2843 wxTextCtrl
* tc
= GetEditorTextCtrl();
2844 wxVariant value
= prop
->GetValue();
2846 if ( !tc
|| !IsEditorsValueModified() )
2849 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2852 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2853 return prop
->GetValue();
2858 // -----------------------------------------------------------------------
2860 // Runs wxValidator for the selected property
2861 bool wxPropertyGrid::DoEditorValidate()
2866 // -----------------------------------------------------------------------
2868 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2870 wxPGProperty
* selected
= m_selected
;
2872 // Somehow, event is handled after property has been deselected.
2873 // Possibly, but very rare.
2877 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2880 wxVariant
pendingValue(selected
->GetValueRef());
2881 wxWindow
* wnd
= GetEditorControl();
2882 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
2884 bool wasUnspecified
= selected
->IsValueUnspecified();
2885 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2886 bool valueIsPending
= false;
2888 m_chgInfo_changedProperty
= NULL
;
2890 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2893 // Filter out excess wxTextCtrl modified events
2894 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2896 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2898 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2900 wxString newTcValue
= tc
->GetValue();
2901 if ( m_prevTcValue
== newTcValue
)
2904 m_prevTcValue
= newTcValue
;
2907 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2909 bool validationFailure
= false;
2910 bool buttonWasHandled
= false;
2913 // Try common button handling
2914 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2916 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2920 buttonWasHandled
= true;
2921 // Store as res2, as previously (and still currently alternatively)
2922 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2923 // in wxPGProperty::OnEvent().
2924 adapter
->ShowDialog( this, selected
);
2929 if ( !buttonWasHandled
)
2931 if ( wnd
|| m_wndEditor2
)
2933 // First call editor class' event handler.
2934 const wxPGEditor
* editor
= selected
->GetEditorClass();
2936 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
2938 // If changes, validate them
2939 if ( DoEditorValidate() )
2941 if ( editor
->GetValueFromControl( pendingValue
,
2944 valueIsPending
= true;
2948 validationFailure
= true;
2953 // Then the property's custom handler (must be always called, unless
2954 // validation failed).
2955 if ( !validationFailure
)
2956 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
2959 // SetValueInEvent(), as called in one of the functions referred above
2960 // overrides editor's value.
2961 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2963 valueIsPending
= true;
2964 pendingValue
= m_changeInEventValue
;
2965 selFlags
|= wxPG_SEL_DIALOGVAL
;
2968 if ( !validationFailure
&& valueIsPending
)
2969 if ( !PerformValidation(m_selected
, pendingValue
) )
2970 validationFailure
= true;
2972 if ( validationFailure
)
2974 OnValidationFailure(selected
, pendingValue
);
2976 else if ( valueIsPending
)
2978 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2980 DoPropertyChanged(selected
, selFlags
);
2981 EditorsValueWasNotModified();
2983 // Regardless of editor type, unfocus editor on
2984 // text-editing related enter press.
2985 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2992 // No value after all
2994 // Regardless of editor type, unfocus editor on
2995 // text-editing related enter press.
2996 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3001 // Let unhandled button click events go to the parent
3002 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3004 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3005 GetEventHandler()->AddPendingEvent(evt
);
3009 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3012 // -----------------------------------------------------------------------
3013 // wxPropertyGrid editor control helper methods
3014 // -----------------------------------------------------------------------
3016 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3018 int itemy
= p
->GetY2(m_lineHeight
);
3020 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3021 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3022 int imageOffset
= 0;
3024 // TODO: If custom image detection changes from current, change this.
3025 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3027 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3028 int iw
= p
->OnMeasureImage().x
;
3030 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3031 imageOffset
= p
->GetImageOffset(iw
);
3036 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3038 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3043 // -----------------------------------------------------------------------
3045 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3047 wxSize sz
= GetImageSize(p
, item
);
3048 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3049 wxPG_CUSTOM_IMAGE_SPACINGY
,
3054 // return size of custom paint image
3055 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3057 // If called with NULL property, then return default image
3058 // size for properties that use image.
3060 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3062 wxSize cis
= p
->OnMeasureImage(item
);
3064 int choiceCount
= p
->m_choices
.GetCount();
3065 int comVals
= p
->GetDisplayedCommonValueCount();
3066 if ( item
>= choiceCount
&& comVals
> 0 )
3068 unsigned int cvi
= item
-choiceCount
;
3069 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3071 else if ( item
>= 0 && choiceCount
== 0 )
3072 return wxSize(0, 0);
3077 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3082 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3089 // -----------------------------------------------------------------------
3091 // takes scrolling into account
3092 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3095 GetViewStart(&vx
,&vy
);
3096 vy
*=wxPG_PIXELS_PER_UNIT
;
3097 vx
*=wxPG_PIXELS_PER_UNIT
;
3100 ClientToScreen( px
, py
);
3103 // -----------------------------------------------------------------------
3105 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3108 GetViewStart(&pt2
.x
,&pt2
.y
);
3109 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3110 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3114 return m_pState
->HitTest(pt2
);
3117 // -----------------------------------------------------------------------
3119 // custom set cursor
3120 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3122 if ( type
== m_curcursor
&& !override
) return;
3124 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3126 if ( type
== wxCURSOR_SIZEWE
)
3127 cursor
= m_cursorSizeWE
;
3129 m_canvas
->SetCursor( *cursor
);
3134 // -----------------------------------------------------------------------
3135 // wxPropertyGrid property selection, editor creation
3136 // -----------------------------------------------------------------------
3139 // This class forwards events from property editor controls to wxPropertyGrid.
3140 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3143 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3144 : wxEvtHandler(), m_propGrid(propGrid
)
3148 virtual ~wxPropertyGridEditorEventForwarder()
3153 bool ProcessEvent( wxEvent
& event
)
3158 m_propGrid
->HandleCustomEditorEvent(event
);
3160 return wxEvtHandler::ProcessEvent(event
);
3163 wxPropertyGrid
* m_propGrid
;
3166 // Setups event handling for child control
3167 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3169 wxWindowID id
= argWnd
->GetId();
3171 if ( argWnd
== m_wndEditor
)
3173 argWnd
->Connect(id
, wxEVT_MOTION
,
3174 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3176 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3177 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3179 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3180 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3182 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3183 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3185 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3186 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3188 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3189 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3193 wxPropertyGridEditorEventForwarder
* forwarder
;
3194 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3195 argWnd
->PushEventHandler(forwarder
);
3197 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3198 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3202 void wxPropertyGrid::FreeEditors()
3205 // Return focus back to canvas from children (this is required at least for
3206 // GTK+, which, unlike Windows, clears focus when control is destroyed
3207 // instead of moving it to closest parent).
3208 wxWindow
* focus
= wxWindow::FindFocus();
3211 wxWindow
* parent
= focus
->GetParent();
3214 if ( parent
== m_canvas
)
3219 parent
= parent
->GetParent();
3223 // Do not free editors immediately if processing events
3226 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3227 m_wndEditor2
->Hide();
3228 wxPendingDelete
.Append( handler
);
3229 wxPendingDelete
.Append( m_wndEditor2
);
3230 m_wndEditor2
= NULL
;
3235 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3236 m_wndEditor
->Hide();
3237 wxPendingDelete
.Append( handler
);
3238 wxPendingDelete
.Append( m_wndEditor
);
3243 // Call with NULL to de-select property
3244 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3249 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3250 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3254 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3258 if ( m_inDoSelectProperty
)
3261 m_inDoSelectProperty
= 1;
3263 wxPGProperty
* prev
= m_selected
;
3267 m_inDoSelectProperty
= 0;
3273 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3275 wxPrintf( "None selected\n" );
3278 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3280 wxPrintf( "P = NULL\n" );
3283 // If we are frozen, then just set the values.
3286 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3287 m_editorFocused
= 0;
3290 m_pState
->m_selected
= p
;
3292 // If frozen, always free controls. But don't worry, as Thaw will
3293 // recall SelectProperty to recreate them.
3296 // Prevent any further selection measures in this call
3302 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3304 // Only set focus if not deselecting
3307 if ( flags
& wxPG_SEL_FOCUS
)
3311 m_wndEditor
->SetFocus();
3312 m_editorFocused
= 1;
3321 m_inDoSelectProperty
= 0;
3326 // First, deactivate previous
3330 OnValidationFailureReset(m_selected
);
3332 // Must double-check if this is an selected in case of forceswitch
3335 if ( !CommitChangesFromEditor(flags
) )
3337 // Validation has failed, so we can't exit the previous editor
3338 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3339 // _("Invalid Value"),wxOK|wxICON_ERROR);
3340 m_inDoSelectProperty
= 0;
3349 m_pState
->m_selected
= NULL
;
3351 // We need to always fully refresh the grid here
3354 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3355 EditorsValueWasNotModified();
3358 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3361 // Then, activate the one given.
3364 int propY
= p
->GetY2(m_lineHeight
);
3366 int splitterX
= GetSplitterPosition();
3367 m_editorFocused
= 0;
3369 m_pState
->m_selected
= p
;
3370 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3372 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3374 wxASSERT( m_wndEditor
== NULL
);
3377 // Only create editor for non-disabled non-caption
3378 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3380 // do this for non-caption items
3384 // Do we need to paint the custom image, if any?
3385 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3386 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3387 !p
->GetEditorClass()->CanContainCustomImage()
3389 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3391 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3392 wxPoint goodPos
= grect
.GetPosition();
3393 #if wxPG_CREATE_CONTROLS_HIDDEN
3394 int coord_adjust
= m_height
- goodPos
.y
;
3395 goodPos
.y
+= coord_adjust
;
3398 const wxPGEditor
* editor
= p
->GetEditorClass();
3399 wxCHECK_MSG(editor
, false,
3400 wxT("NULL editor class not allowed"));
3402 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3404 wxPGWindowList wndList
= editor
->CreateControls(this,
3409 m_wndEditor
= wndList
.m_primary
;
3410 m_wndEditor2
= wndList
.m_secondary
;
3411 wxWindow
* primaryCtrl
= GetEditorControl();
3414 // Essentially, primaryCtrl == m_wndEditor
3417 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3418 // value is drawn as normal, and m_wndEditor2 is assumed
3419 // to be a right-aligned button that triggers a separate editorCtrl
3424 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3425 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3427 // Set validator, if any
3428 #if wxUSE_VALIDATORS
3429 wxValidator
* validator
= p
->GetValidator();
3431 primaryCtrl
->SetValidator(*validator
);
3434 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3435 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3437 // If it has modified status, use bold font
3438 // (must be done before capturing m_ctrlXAdjust)
3439 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3440 SetCurControlBoldFont();
3443 // Fix TextCtrl indentation
3444 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3445 wxTextCtrl
* tc
= NULL
;
3446 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3447 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3449 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3451 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3454 // Store x relative to splitter (we'll need it).
3455 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3457 // Check if background clear is not necessary
3458 wxPoint pos
= m_wndEditor
->GetPosition();
3459 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3461 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3464 m_wndEditor
->SetSizeHints(3, 3);
3466 #if wxPG_CREATE_CONTROLS_HIDDEN
3467 m_wndEditor
->Show(false);
3468 m_wndEditor
->Freeze();
3470 goodPos
= m_wndEditor
->GetPosition();
3471 goodPos
.y
-= coord_adjust
;
3472 m_wndEditor
->Move( goodPos
);
3475 SetupChildEventHandling(primaryCtrl
);
3477 // Focus and select all (wxTextCtrl, wxComboBox etc)
3478 if ( flags
& wxPG_SEL_FOCUS
)
3480 primaryCtrl
->SetFocus();
3482 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3488 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3489 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3491 // Get proper id for wndSecondary
3492 m_wndSecId
= m_wndEditor2
->GetId();
3493 wxWindowList children
= m_wndEditor2
->GetChildren();
3494 wxWindowList::iterator node
= children
.begin();
3495 if ( node
!= children
.end() )
3496 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3498 m_wndEditor2
->SetSizeHints(3,3);
3500 #if wxPG_CREATE_CONTROLS_HIDDEN
3501 wxRect sec_rect
= m_wndEditor2
->GetRect();
3502 sec_rect
.y
-= coord_adjust
;
3504 // Fine tuning required to fix "oversized"
3505 // button disappearance bug.
3506 if ( sec_rect
.y
< 0 )
3508 sec_rect
.height
+= sec_rect
.y
;
3511 m_wndEditor2
->SetSize( sec_rect
);
3513 m_wndEditor2
->Show();
3515 SetupChildEventHandling(m_wndEditor2
);
3517 // If no primary editor, focus to button to allow
3518 // it to interprete ENTER etc.
3519 // NOTE: Due to problems focusing away from it, this
3520 // has been disabled.
3522 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3523 m_wndEditor2->SetFocus();
3527 if ( flags
& wxPG_SEL_FOCUS
)
3528 m_editorFocused
= 1;
3533 // Make sure focus is in grid canvas (important for wxGTK, at least)
3537 EditorsValueWasNotModified();
3539 // If it's inside collapsed section, expand parent, scroll, etc.
3540 // Also, if it was partially visible, scroll it into view.
3541 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3546 #if wxPG_CREATE_CONTROLS_HIDDEN
3547 m_wndEditor
->Thaw();
3549 m_wndEditor
->Show(true);
3556 // Make sure focus is in grid canvas
3560 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3566 // Show help text in status bar.
3567 // (if found and grid not embedded in manager with help box and
3568 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3571 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3573 wxStatusBar
* statusbar
= NULL
;
3574 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3576 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3578 statusbar
= frame
->GetStatusBar();
3583 const wxString
* pHelpString
= (const wxString
*) NULL
;
3587 pHelpString
= &p
->GetHelpString();
3588 if ( pHelpString
->length() )
3590 // Set help box text.
3591 statusbar
->SetStatusText( *pHelpString
);
3592 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3596 if ( (!pHelpString
|| !pHelpString
->length()) &&
3597 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3599 // Clear help box - but only if it was written
3600 // by us at previous time.
3601 statusbar
->SetStatusText( m_emptyString
);
3602 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3608 m_inDoSelectProperty
= 0;
3610 // call wx event handler (here so that it also occurs on deselection)
3611 if ( !(flags
& wxPG_SEL_DONT_SEND_EVENT
) )
3612 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3617 // -----------------------------------------------------------------------
3619 bool wxPropertyGrid::UnfocusEditor()
3621 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3624 if ( !CommitChangesFromEditor(0) )
3628 DrawItem(m_selected
);
3633 // -----------------------------------------------------------------------
3635 void wxPropertyGrid::RefreshEditor()
3637 wxPGProperty
* p
= m_selected
;
3641 wxWindow
* wnd
= GetEditorControl();
3645 // Set editor font boldness - must do this before
3646 // calling UpdateControl().
3647 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3649 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3650 wnd
->SetFont(GetCaptionFont());
3652 wnd
->SetFont(GetFont());
3655 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3657 editorClass
->UpdateControl(p
, wnd
);
3659 if ( p
->IsValueUnspecified() )
3660 editorClass
->SetValueToUnspecified(p
, wnd
);
3663 // -----------------------------------------------------------------------
3665 bool wxPropertyGrid::SelectProperty( wxPGPropArg id
, bool focus
)
3667 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
3669 int flags
= wxPG_SEL_DONT_SEND_EVENT
;
3671 flags
|= wxPG_SEL_FOCUS
;
3673 return DoSelectProperty(p
, flags
);
3676 // -----------------------------------------------------------------------
3678 bool wxPropertyGrid::DoClearSelection()
3680 // Unlike ClearSelection(), here we send the wxEVT_PG_SELECTED event.
3681 return DoSelectProperty(NULL
, 0);
3684 // -----------------------------------------------------------------------
3685 // wxPropertyGrid expand/collapse state
3686 // -----------------------------------------------------------------------
3688 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3690 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3692 // If active editor was inside collapsed section, then disable it
3693 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3698 // Store dont-center-splitter flag 'cause we need to temporarily set it
3699 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3700 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3702 bool res
= m_pState
->DoCollapse(pwc
);
3707 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3709 RecalculateVirtualSize();
3711 // Redraw etc. only if collapsed was visible.
3712 if (pwc
->IsVisible() &&
3714 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3716 // When item is collapsed so that scrollbar would move,
3717 // graphics mess is about (unless we redraw everything).
3722 // Clear dont-center-splitter flag if it wasn't set
3723 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3728 // -----------------------------------------------------------------------
3730 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3732 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3734 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3736 // Store dont-center-splitter flag 'cause we need to temporarily set it
3737 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3738 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3740 bool res
= m_pState
->DoExpand(pwc
);
3745 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3747 RecalculateVirtualSize();
3749 // Redraw etc. only if expanded was visible.
3750 if ( pwc
->IsVisible() && !m_frozen
&&
3751 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3755 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3758 DrawItems(pwc
, NULL
);
3763 // Clear dont-center-splitter flag if it wasn't set
3764 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3769 // -----------------------------------------------------------------------
3771 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3774 return m_pState
->DoHideProperty(p
, hide
, flags
);
3777 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3783 m_pState
->DoHideProperty(p
, hide
, flags
);
3785 RecalculateVirtualSize();
3792 // -----------------------------------------------------------------------
3793 // wxPropertyGrid size related methods
3794 // -----------------------------------------------------------------------
3796 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3798 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3802 // If virtual height was changed, then recalculate editor control position(s)
3803 if ( m_pState
->m_vhCalcPending
)
3804 CorrectEditorWidgetPosY();
3806 m_pState
->EnsureVirtualHeight();
3808 wxASSERT_LEVEL_2_MSG(
3809 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
3810 "VirtualHeight and ActualVirtualHeight should match"
3813 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3815 int x
= m_pState
->m_width
;
3816 int y
= m_pState
->m_virtualHeight
;
3819 GetClientSize(&width
,&height
);
3821 // Now adjust virtual size.
3822 SetVirtualSize(x
, y
);
3828 // Adjust scrollbars
3829 if ( HasVirtualWidth() )
3831 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3832 xPos
= GetScrollPos( wxHORIZONTAL
);
3835 if ( forceXPos
!= -1 )
3838 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3841 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3842 int yPos
= GetScrollPos( wxVERTICAL
);
3844 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3845 xAmount
, yAmount
, xPos
, yPos
, true );
3847 // Must re-get size now
3848 GetClientSize(&width
,&height
);
3850 if ( !HasVirtualWidth() )
3852 m_pState
->SetVirtualWidth(width
);
3859 m_canvas
->SetSize( x
, y
);
3861 m_pState
->CheckColumnWidths();
3864 CorrectEditorWidgetSizeX();
3866 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3869 // -----------------------------------------------------------------------
3871 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3873 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3877 GetClientSize(&width
,&height
);
3882 #if wxPG_DOUBLE_BUFFER
3883 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3885 int dblh
= (m_lineHeight
*2);
3886 if ( !m_doubleBuffer
)
3888 // Create double buffer bitmap to draw on, if none
3889 int w
= (width
>250)?width
:250;
3890 int h
= height
+ dblh
;
3892 m_doubleBuffer
= new wxBitmap( w
, h
);
3896 int w
= m_doubleBuffer
->GetWidth();
3897 int h
= m_doubleBuffer
->GetHeight();
3899 // Double buffer must be large enough
3900 if ( w
< width
|| h
< (height
+dblh
) )
3902 if ( w
< width
) w
= width
;
3903 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3904 delete m_doubleBuffer
;
3905 m_doubleBuffer
= new wxBitmap( w
, h
);
3912 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3913 m_ncWidth
= event
.GetSize().x
;
3917 if ( m_pState
->m_itemsAdded
)
3918 PrepareAfterItemsAdded();
3920 // Without this, virtual size (atleast under wxGTK) will be skewed
3921 RecalculateVirtualSize();
3927 // -----------------------------------------------------------------------
3929 void wxPropertyGrid::SetVirtualWidth( int width
)
3933 // Disable virtual width
3934 width
= GetClientSize().x
;
3935 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3939 // Enable virtual width
3940 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3942 m_pState
->SetVirtualWidth( width
);
3945 void wxPropertyGrid::SetFocusOnCanvas()
3947 m_canvas
->SetFocusIgnoringChildren();
3948 m_editorFocused
= 0;
3951 // -----------------------------------------------------------------------
3952 // wxPropertyGrid mouse event handling
3953 // -----------------------------------------------------------------------
3955 // selFlags uses same values DoSelectProperty's flags
3956 // Returns true if event was vetoed.
3957 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3959 // Send property grid event of specific type and with specific property
3960 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3961 evt
.SetPropertyGrid(this);
3962 evt
.SetEventObject(m_eventObject
);
3966 evt
.SetCanVeto(true);
3967 evt
.SetupValidationInfo();
3968 m_validationInfo
.m_pValue
= pValue
;
3970 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3972 evtHandler
->ProcessEvent(evt
);
3974 return evt
.WasVetoed();
3977 // -----------------------------------------------------------------------
3979 // Return false if should be skipped
3980 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3984 // Need to set focus?
3985 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3990 wxPropertyGridPageState
* state
= m_pState
;
3992 int splitterHitOffset
;
3993 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3995 wxPGProperty
* p
= DoGetItemAtY(y
);
3999 int depth
= (int)p
->GetDepth() - 1;
4001 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4003 if ( x
>= marginEnds
)
4007 if ( p
->IsCategory() )
4009 // This is category.
4010 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4012 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4014 // Expand, collapse, activate etc. if click on text or left of splitter.
4017 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4022 if ( !DoSelectProperty( p
) )
4025 // On double-click, expand/collapse.
4026 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4028 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4029 else DoExpand( p
, true );
4033 else if ( splitterHit
== -1 )
4036 unsigned int selFlag
= 0;
4037 if ( columnHit
== 1 )
4039 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4040 selFlag
= wxPG_SEL_FOCUS
;
4042 if ( !DoSelectProperty( p
, selFlag
) )
4045 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4047 if ( p
->GetChildCount() && !p
->IsCategory() )
4048 // On double-click, expand/collapse.
4049 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4051 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4052 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4053 else DoExpand( p
, true );
4060 // click on splitter
4061 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4063 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4065 // Double-clicking the splitter causes auto-centering
4066 CenterSplitter( true );
4068 else if ( m_dragStatus
== 0 )
4071 // Begin draggin the splitter
4075 // Changes must be committed here or the
4076 // value won't be drawn correctly
4077 if ( !CommitChangesFromEditor() )
4080 m_wndEditor
->Show ( false );
4083 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4085 m_canvas
->CaptureMouse();
4086 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4090 m_draggedSplitter
= splitterHit
;
4091 m_dragOffset
= splitterHitOffset
;
4093 wxClientDC
dc(m_canvas
);
4095 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4096 // Fixes button disappearance bug
4098 m_wndEditor2
->Show ( false );
4101 m_startingSplitterX
= x
- splitterHitOffset
;
4109 if ( p
->GetChildCount() )
4111 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4113 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4115 int y2
= y
% m_lineHeight
;
4116 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4118 // On click on expander button, expand/collapse
4119 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4120 DoCollapse( p
, true );
4122 DoExpand( p
, true );
4131 // -----------------------------------------------------------------------
4133 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4134 wxMouseEvent
& WXUNUSED(event
) )
4138 // Select property here as well
4139 wxPGProperty
* p
= m_propHover
;
4140 if ( p
!= m_selected
)
4141 DoSelectProperty( p
);
4143 // Send right click event.
4144 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4151 // -----------------------------------------------------------------------
4153 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4154 wxMouseEvent
& WXUNUSED(event
) )
4158 // Select property here as well
4159 wxPGProperty
* p
= m_propHover
;
4161 if ( p
!= m_selected
)
4162 DoSelectProperty( p
);
4164 // Send double-click event.
4165 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4172 // -----------------------------------------------------------------------
4174 #if wxPG_SUPPORT_TOOLTIPS
4176 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4178 if ( tipString
.length() )
4180 m_canvas
->SetToolTip(tipString
);
4184 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4185 m_canvas
->SetToolTip( m_emptyString
);
4187 m_canvas
->SetToolTip( NULL
);
4192 #endif // #if wxPG_SUPPORT_TOOLTIPS
4194 // -----------------------------------------------------------------------
4196 // Return false if should be skipped
4197 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4199 // Safety check (needed because mouse capturing may
4200 // otherwise freeze the control)
4201 if ( m_dragStatus
> 0 && !event
.Dragging() )
4203 HandleMouseUp(x
,y
,event
);
4206 wxPropertyGridPageState
* state
= m_pState
;
4208 int splitterHitOffset
;
4209 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4210 int splitterX
= x
- splitterHitOffset
;
4212 if ( m_dragStatus
> 0 )
4214 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4215 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4218 int newSplitterX
= x
- m_dragOffset
;
4219 int splitterX
= x
- splitterHitOffset
;
4221 // Splitter redraw required?
4222 if ( newSplitterX
!= splitterX
)
4225 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4226 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4227 state
->m_fSplitterX
= (float) newSplitterX
;
4230 CorrectEditorWidgetSizeX();
4244 int ih
= m_lineHeight
;
4247 #if wxPG_SUPPORT_TOOLTIPS
4248 wxPGProperty
* prevHover
= m_propHover
;
4249 unsigned char prevSide
= m_mouseSide
;
4251 int curPropHoverY
= y
- (y
% ih
);
4253 // On which item it hovers
4256 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4259 // Mouse moves on another property
4261 m_propHover
= DoGetItemAtY(y
);
4262 m_propHoverY
= curPropHoverY
;
4265 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4268 #if wxPG_SUPPORT_TOOLTIPS
4269 // Store which side we are on
4271 if ( columnHit
== 1 )
4273 else if ( columnHit
== 0 )
4277 // If tooltips are enabled, show label or value as a tip
4278 // in case it doesn't otherwise show in full length.
4280 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4282 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4284 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4286 if ( m_propHover
&& !m_propHover
->IsCategory() )
4289 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4291 // Show help string as a tooltip
4292 wxString tipString
= m_propHover
->GetHelpString();
4294 SetToolTip(tipString
);
4298 // Show cropped value string as a tooltip
4302 if ( m_mouseSide
== 1 )
4304 tipString
= m_propHover
->m_label
;
4305 space
= splitterX
-m_marginWidth
-3;
4307 else if ( m_mouseSide
== 2 )
4309 tipString
= m_propHover
->GetDisplayedString();
4311 space
= m_width
- splitterX
;
4312 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4313 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4319 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4322 SetToolTip( tipString
);
4329 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4330 m_canvas
->SetToolTip( m_emptyString
);
4332 m_canvas
->SetToolTip( NULL
);
4343 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4344 m_canvas
->SetToolTip( m_emptyString
);
4346 m_canvas
->SetToolTip( NULL
);
4354 if ( splitterHit
== -1 ||
4356 HasFlag(wxPG_STATIC_SPLITTER
) )
4358 // hovering on something else
4359 if ( m_curcursor
!= wxCURSOR_ARROW
)
4360 CustomSetCursor( wxCURSOR_ARROW
);
4364 // Do not allow splitter cursor on caption items.
4365 // (also not if we were dragging and its started
4366 // outside the splitter region)
4368 if ( !m_propHover
->IsCategory() &&
4372 // hovering on splitter
4374 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4375 // reliably detected.
4376 //if ( m_curcursor != wxCURSOR_SIZEWE )
4377 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4383 // hovering on something else
4384 if ( m_curcursor
!= wxCURSOR_ARROW
)
4385 CustomSetCursor( wxCURSOR_ARROW
);
4392 // -----------------------------------------------------------------------
4394 // Also handles Leaving event
4395 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4396 wxMouseEvent
&WXUNUSED(event
) )
4398 wxPropertyGridPageState
* state
= m_pState
;
4402 int splitterHitOffset
;
4403 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4405 // No event type check - basicly calling this method should
4406 // just stop dragging.
4407 // Left up after dragged?
4408 if ( m_dragStatus
>= 1 )
4411 // End Splitter Dragging
4413 // DO NOT ENABLE FOLLOWING LINE!
4414 // (it is only here as a reminder to not to do it)
4417 // Disable splitter auto-centering
4418 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4420 // This is necessary to return cursor
4421 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4423 m_canvas
->ReleaseMouse();
4424 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4427 // Set back the default cursor, if necessary
4428 if ( splitterHit
== -1 ||
4431 CustomSetCursor( wxCURSOR_ARROW
);
4436 // Control background needs to be cleared
4437 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4438 DrawItem( m_selected
);
4442 m_wndEditor
->Show ( true );
4445 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4446 // Fixes button disappearance bug
4448 m_wndEditor2
->Show ( true );
4451 // This clears the focus.
4452 m_editorFocused
= 0;
4458 // -----------------------------------------------------------------------
4460 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4462 int splitterX
= GetSplitterPosition();
4465 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4469 wxWindow
* wnd
= GetEditorControl();
4471 // Hide popup on clicks
4472 if ( event
.GetEventType() != wxEVT_MOTION
)
4473 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4475 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4481 if ( wnd
== NULL
|| m_dragStatus
||
4483 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4484 ux
>= (r
.x
+r
.width
) ||
4486 event
.m_y
>= (r
.y
+r
.height
)
4496 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4501 // -----------------------------------------------------------------------
4503 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4506 if ( OnMouseCommon( event
, &x
, &y
) )
4508 HandleMouseClick(x
,y
,event
);
4513 // -----------------------------------------------------------------------
4515 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4518 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4519 HandleMouseRightClick(x
,y
,event
);
4523 // -----------------------------------------------------------------------
4525 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4527 // Always run standard mouse-down handler as well
4528 OnMouseClick(event
);
4531 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4532 HandleMouseDoubleClick(x
,y
,event
);
4536 // -----------------------------------------------------------------------
4538 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4541 if ( OnMouseCommon( event
, &x
, &y
) )
4543 HandleMouseMove(x
,y
,event
);
4548 // -----------------------------------------------------------------------
4550 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4552 // Called when mouse moves in the empty space below the properties.
4553 CustomSetCursor( wxCURSOR_ARROW
);
4556 // -----------------------------------------------------------------------
4558 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4561 if ( OnMouseCommon( event
, &x
, &y
) )
4563 HandleMouseUp(x
,y
,event
);
4568 // -----------------------------------------------------------------------
4570 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4572 // This may get called from child control as well, so event's
4573 // mouse position cannot be relied on.
4575 if ( event
.Entering() )
4577 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4579 // TODO: Fix this (detect parent and only do
4580 // cursor trick if it is a manager).
4581 wxASSERT( GetParent() );
4582 GetParent()->SetCursor(wxNullCursor
);
4584 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4587 GetParent()->SetCursor(wxNullCursor
);
4589 else if ( event
.Leaving() )
4591 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4592 m_canvas
->SetCursor( wxNullCursor
);
4594 // Get real cursor position
4595 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4597 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4600 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4602 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4606 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4614 // -----------------------------------------------------------------------
4616 // Common code used by various OnMouseXXXChild methods.
4617 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4619 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4620 wxASSERT( topCtrlWnd
);
4622 event
.GetPosition(&x
,&y
);
4624 int splitterX
= GetSplitterPosition();
4626 wxRect r
= topCtrlWnd
->GetRect();
4627 if ( !m_dragStatus
&&
4628 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4629 y
>= 0 && y
< r
.height \
4632 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4637 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4644 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4647 if ( OnMouseChildCommon(event
,&x
,&y
) )
4649 bool res
= HandleMouseClick(x
,y
,event
);
4650 if ( !res
) event
.Skip();
4654 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4657 wxASSERT( m_wndEditor
);
4658 // These coords may not be exact (about +-2),
4659 // but that should not matter (right click is about item, not position).
4660 wxPoint pt
= m_wndEditor
->GetPosition();
4661 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4662 wxASSERT( m_selected
);
4663 m_propHover
= m_selected
;
4664 bool res
= HandleMouseRightClick(x
,y
,event
);
4665 if ( !res
) event
.Skip();
4668 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4671 if ( OnMouseChildCommon(event
,&x
,&y
) )
4673 bool res
= HandleMouseMove(x
,y
,event
);
4674 if ( !res
) event
.Skip();
4678 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4681 if ( OnMouseChildCommon(event
,&x
,&y
) )
4683 bool res
= HandleMouseUp(x
,y
,event
);
4684 if ( !res
) event
.Skip();
4688 // -----------------------------------------------------------------------
4689 // wxPropertyGrid keyboard event handling
4690 // -----------------------------------------------------------------------
4692 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4694 // Translates wxKeyEvent to wxPG_ACTION_XXX
4696 int keycode
= event
.GetKeyCode();
4697 int modifiers
= event
.GetModifiers();
4699 wxASSERT( !(modifiers
&~(0xFFFF)) );
4701 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4703 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4705 if ( it
== m_actionTriggers
.end() )
4710 int second
= (it
->second
>>16) & 0xFFFF;
4714 return (it
->second
& 0xFFFF);
4717 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4719 wxASSERT( !(modifiers
&~(0xFFFF)) );
4721 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4723 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4725 if ( it
!= m_actionTriggers
.end() )
4727 // This key combination is already used
4729 // Can add secondary?
4730 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4731 wxT("You can only add up to two separate actions per key combination.") );
4733 action
= it
->second
| (action
<<16);
4736 m_actionTriggers
[hashMapKey
] = action
;
4739 void wxPropertyGrid::ClearActionTriggers( int action
)
4741 wxPGHashMapI2I::iterator it
;
4743 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4745 if ( it
->second
== action
)
4747 m_actionTriggers
.erase(it
);
4752 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4755 // Handles key event when editor control is not focused.
4758 wxCHECK2(!m_frozen
, return);
4760 // Travelsal between items, collapsing/expanding, etc.
4761 int keycode
= event
.GetKeyCode();
4762 bool editorFocused
= IsEditorFocused();
4764 if ( keycode
== WXK_TAB
)
4766 wxWindow
* mainControl
;
4768 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4769 mainControl
= GetParent();
4773 if ( !event
.ShiftDown() )
4775 if ( !editorFocused
&& m_wndEditor
)
4777 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4781 // Tab traversal workaround for platforms on which
4782 // wxWindow::Navigate() may navigate into first child
4783 // instead of next sibling. Does not work perfectly
4784 // in every scenario (for instance, when property grid
4785 // is either first or last control).
4786 #if defined(__WXGTK__)
4787 wxWindow
* sibling
= mainControl
->GetNextSibling();
4789 sibling
->SetFocusFromKbd();
4791 Navigate(wxNavigationKeyEvent::IsForward
);
4797 if ( editorFocused
)
4803 #if defined(__WXGTK__)
4804 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4806 sibling
->SetFocusFromKbd();
4808 Navigate(wxNavigationKeyEvent::IsBackward
);
4816 // Ignore Alt and Control when they are down alone
4817 if ( keycode
== WXK_ALT
||
4818 keycode
== WXK_CONTROL
)
4825 int action
= KeyEventToActions(event
, &secondAction
);
4827 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4830 // Esc cancels any changes
4831 if ( IsEditorsValueModified() )
4833 EditorsValueWasNotModified();
4835 // Update the control as well
4836 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4838 m_selected
->GetDisplayedString() );
4841 OnValidationFailureReset(m_selected
);
4847 // Except for TAB and ESC, handle child control events in child control
4850 // Only propagate event if it had modifiers
4851 if ( !event
.HasModifiers() )
4853 event
.StopPropagation();
4859 bool wasHandled
= false;
4864 if ( ButtonTriggerKeyTest(action
, event
) )
4867 wxPGProperty
* p
= m_selected
;
4869 // Travel and expand/collapse
4872 if ( p
->GetChildCount() )
4874 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4876 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4879 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4881 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4888 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4892 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4898 if ( selectDir
>= -1 )
4900 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4902 DoSelectProperty(p
);
4908 // If nothing was selected, select the first item now
4909 // (or navigate out of tab).
4910 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4912 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4913 if ( p
) DoSelectProperty(p
);
4922 // -----------------------------------------------------------------------
4924 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4926 // If there was editor open and focused, then this event should not
4927 // really be processed here.
4928 if ( IsEditorFocused() )
4930 // However, if event had modifiers, it is probably still best
4932 if ( event
.HasModifiers() )
4935 event
.StopPropagation();
4939 HandleKeyEvent(event
, false);
4942 // -----------------------------------------------------------------------
4944 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4949 action
= KeyEventToActions(event
, &secondAction
);
4952 // Does the keycode trigger button?
4953 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4956 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4957 GetEventHandler()->AddPendingEvent(evt
);
4964 // -----------------------------------------------------------------------
4966 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4968 HandleKeyEvent(event
, true);
4971 // -----------------------------------------------------------------------
4972 // wxPropertyGrid miscellaneous event handling
4973 // -----------------------------------------------------------------------
4975 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4978 // Check if the focus is in this control or one of its children
4979 wxWindow
* newFocused
= wxWindow::FindFocus();
4981 if ( newFocused
!= m_curFocused
)
4982 HandleFocusChange( newFocused
);
4985 // Check if top-level parent has changed
4986 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
4993 bool wxPropertyGrid::IsEditorFocused() const
4995 wxWindow
* focus
= wxWindow::FindFocus();
4997 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4998 focus
== GetEditorControl() )
5004 // Called by focus event handlers. newFocused is the window that becomes focused.
5005 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5007 unsigned int oldFlags
= m_iFlags
;
5009 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5011 wxWindow
* parent
= newFocused
;
5013 // This must be one of nextFocus' parents.
5016 // Use m_eventObject, which is either wxPropertyGrid or
5017 // wxPropertyGridManager, as appropriate.
5018 if ( parent
== m_eventObject
)
5020 m_iFlags
|= wxPG_FL_FOCUSED
;
5023 parent
= parent
->GetParent();
5026 m_curFocused
= newFocused
;
5028 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5029 (oldFlags
& wxPG_FL_FOCUSED
) )
5031 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5033 // Need to store changed value
5034 CommitChangesFromEditor();
5040 // Preliminary code for tab-order respecting
5041 // tab-traversal (but should be moved to
5044 wxWindow* prevFocus = event.GetWindow();
5045 wxWindow* useThis = this;
5046 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5047 useThis = GetParent();
5050 prevFocus->GetParent() == useThis->GetParent() )
5052 wxList& children = useThis->GetParent()->GetChildren();
5054 wxNode* node = children.Find(prevFocus);
5056 if ( node->GetNext() &&
5057 useThis == node->GetNext()->GetData() )
5058 DoSelectProperty(GetFirst());
5059 else if ( node->GetPrevious () &&
5060 useThis == node->GetPrevious()->GetData() )
5061 DoSelectProperty(GetLastProperty());
5068 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5069 DrawItem( m_selected
);
5073 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5075 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5076 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5077 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5078 //else if ( event.GetWindow() )
5080 HandleFocusChange(event
.GetWindow());
5085 // -----------------------------------------------------------------------
5087 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5089 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5093 // -----------------------------------------------------------------------
5095 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5097 m_iFlags
|= wxPG_FL_SCROLLED
;
5102 // -----------------------------------------------------------------------
5104 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5106 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5108 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5112 // -----------------------------------------------------------------------
5113 // Property editor related functions
5114 // -----------------------------------------------------------------------
5116 // noDefCheck = true prevents infinite recursion.
5117 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5118 const wxString
& editorName
,
5121 wxASSERT( editorClass
);
5123 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5124 RegisterDefaultEditors();
5126 wxString name
= editorName
;
5127 if ( name
.length() == 0 )
5128 name
= editorClass
->GetName();
5130 // Existing editor under this name?
5131 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5133 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5135 // If this name was already used, try class name.
5136 name
= editorClass
->GetClassInfo()->GetClassName();
5137 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5140 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5141 (wxPGEditor
*) vt_it
->second
,
5142 "Editor with given name was already registered" );
5144 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5149 // Use this in RegisterDefaultEditors.
5150 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5151 if ( wxPGEditor_##EDITOR == NULL ) \
5153 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5154 new wxPG##EDITOR##Editor, true ); \
5157 // Registers all default editor classes
5158 void wxPropertyGrid::RegisterDefaultEditors()
5160 wxPGRegisterDefaultEditorClass( TextCtrl
);
5161 wxPGRegisterDefaultEditorClass( Choice
);
5162 wxPGRegisterDefaultEditorClass( ComboBox
);
5163 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5164 #if wxPG_INCLUDE_CHECKBOX
5165 wxPGRegisterDefaultEditorClass( CheckBox
);
5167 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5169 // Register SpinCtrl etc. editors before use
5170 RegisterAdditionalEditors();
5173 // -----------------------------------------------------------------------
5174 // wxPGStringTokenizer
5175 // Needed to handle C-style string lists (e.g. "str1" "str2")
5176 // -----------------------------------------------------------------------
5178 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5179 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5183 wxPGStringTokenizer::~wxPGStringTokenizer()
5187 bool wxPGStringTokenizer::HasMoreTokens()
5189 const wxString
& str
= *m_str
;
5191 wxString::const_iterator i
= m_curPos
;
5193 wxUniChar delim
= m_delimeter
;
5195 wxUniChar prev_a
= wxT('\0');
5197 bool inToken
= false;
5199 while ( i
!= str
.end() )
5208 m_readyToken
.clear();
5213 if ( prev_a
!= wxT('\\') )
5217 if ( a
!= wxT('\\') )
5237 m_curPos
= str
.end();
5245 wxString
wxPGStringTokenizer::GetNextToken()
5247 return m_readyToken
;
5250 // -----------------------------------------------------------------------
5252 // -----------------------------------------------------------------------
5254 wxPGChoiceEntry::wxPGChoiceEntry()
5255 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5259 // -----------------------------------------------------------------------
5261 // -----------------------------------------------------------------------
5263 wxPGChoicesData::wxPGChoicesData()
5267 wxPGChoicesData::~wxPGChoicesData()
5272 void wxPGChoicesData::Clear()
5277 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5279 wxASSERT( m_items
.size() == 0 );
5281 m_items
= data
->m_items
;
5284 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5285 const wxPGChoiceEntry
& item
)
5287 wxVector
<wxPGChoiceEntry
>::iterator it
;
5291 index
= (int) m_items
.size();
5295 it
= m_items
.begin() + index
;
5298 m_items
.insert(it
, item
);
5300 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5302 // Need to fix value?
5303 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5304 ownEntry
.SetValue(index
);
5309 // -----------------------------------------------------------------------
5310 // wxPropertyGridEvent
5311 // -----------------------------------------------------------------------
5313 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5316 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5317 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5318 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5319 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5320 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5321 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5322 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5323 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5324 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5327 // -----------------------------------------------------------------------
5329 void wxPropertyGridEvent::Init()
5331 m_validationInfo
= NULL
;
5333 m_wasVetoed
= false;
5336 // -----------------------------------------------------------------------
5338 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5339 : wxCommandEvent(commandType
,id
)
5345 // -----------------------------------------------------------------------
5347 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5348 : wxCommandEvent(event
)
5350 m_eventType
= event
.GetEventType();
5351 m_eventObject
= event
.m_eventObject
;
5353 m_property
= event
.m_property
;
5354 m_validationInfo
= event
.m_validationInfo
;
5355 m_canVeto
= event
.m_canVeto
;
5356 m_wasVetoed
= event
.m_wasVetoed
;
5359 // -----------------------------------------------------------------------
5361 wxPropertyGridEvent::~wxPropertyGridEvent()
5365 // -----------------------------------------------------------------------
5367 wxEvent
* wxPropertyGridEvent::Clone() const
5369 return new wxPropertyGridEvent( *this );
5372 // -----------------------------------------------------------------------
5373 // wxPropertyGridPopulator
5374 // -----------------------------------------------------------------------
5376 wxPropertyGridPopulator::wxPropertyGridPopulator()
5380 wxPGGlobalVars
->m_offline
++;
5383 // -----------------------------------------------------------------------
5385 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5388 m_propHierarchy
.clear();
5391 // -----------------------------------------------------------------------
5393 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5399 // -----------------------------------------------------------------------
5401 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5404 // Free unused sets of choices
5405 wxPGHashMapS2P::iterator it
;
5407 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5409 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5416 m_pg
->GetPanel()->Refresh();
5418 wxPGGlobalVars
->m_offline
--;
5421 // -----------------------------------------------------------------------
5423 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5424 const wxString
& propLabel
,
5425 const wxString
& propName
,
5426 const wxString
* propValue
,
5427 wxPGChoices
* pChoices
)
5429 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5430 wxPGProperty
* parent
= GetCurParent();
5432 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5434 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5438 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5440 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5444 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5446 property
->SetLabel(propLabel
);
5447 property
->DoSetName(propName
);
5449 if ( pChoices
&& pChoices
->IsOk() )
5450 property
->SetChoices(*pChoices
);
5452 m_state
->DoInsert(parent
, -1, property
);
5455 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5456 wxPG_PROGRAMMATIC_VALUE
);
5461 // -----------------------------------------------------------------------
5463 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5465 m_propHierarchy
.push_back(property
);
5466 DoScanForChildren();
5467 m_propHierarchy
.pop_back();
5470 // -----------------------------------------------------------------------
5472 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5473 const wxString
& idString
)
5475 wxPGChoices choices
;
5478 if ( choicesString
[0] == wxT('@') )
5480 wxString ids
= choicesString
.substr(1);
5481 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5482 if ( it
== m_dictIdChoices
.end() )
5483 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5485 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5490 if ( idString
.length() )
5492 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5493 if ( it
!= m_dictIdChoices
.end() )
5495 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5502 // Parse choices string
5503 wxString::const_iterator it
= choicesString
.begin();
5507 bool labelValid
= false;
5509 for ( ; it
!= choicesString
.end(); ++it
)
5515 if ( c
== wxT('"') )
5520 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5521 choices
.Add(label
, l
);
5524 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5529 else if ( c
== wxT('=') )
5536 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5543 if ( c
== wxT('"') )
5556 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5557 choices
.Add(label
, l
);
5560 if ( !choices
.IsOk() )
5562 choices
.EnsureData();
5566 if ( idString
.length() )
5567 m_dictIdChoices
[idString
] = choices
.GetData();
5574 // -----------------------------------------------------------------------
5576 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5578 if ( s
.Last() == wxT('%') )
5580 wxString s2
= s
.substr(0,s
.length()-1);
5582 if ( s2
.ToLong(&val
, 10) )
5584 *pval
= (val
*max
)/100;
5590 return s
.ToLong(pval
, 10);
5593 // -----------------------------------------------------------------------
5595 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5596 const wxString
& type
,
5597 const wxString
& value
)
5599 int l
= m_propHierarchy
.size();
5603 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5604 wxString valuel
= value
.Lower();
5607 if ( type
.length() == 0 )
5612 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5614 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5616 else if ( value
.ToLong(&v
, 0) )
5623 if ( type
== wxT("string") )
5627 else if ( type
== wxT("int") )
5630 value
.ToLong(&v
, 0);
5633 else if ( type
== wxT("bool") )
5635 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5642 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5647 p
->SetAttribute( name
, variant
);
5652 // -----------------------------------------------------------------------
5654 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5656 wxLogError(_("Error in resource: %s"),msg
.c_str());
5659 // -----------------------------------------------------------------------
5661 #endif // wxUSE_PROPGRID