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() && !ClearSelection() )
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.
1074 ClearSelection(false);
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
)
2171 ClearSelection(false);
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
;
2223 ClearSelection(false);
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
, _T("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
= _T("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
)
3248 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3249 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3251 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3254 if ( m_inDoSelectProperty
)
3257 m_inDoSelectProperty
= 1;
3259 wxPGProperty
* prev
= m_selected
;
3263 m_inDoSelectProperty
= 0;
3269 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3271 wxPrintf( "None selected\n" );
3274 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3276 wxPrintf( "P = NULL\n" );
3279 // If we are frozen, then just set the values.
3282 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3283 m_editorFocused
= 0;
3286 m_pState
->m_selected
= p
;
3288 // If frozen, always free controls. But don't worry, as Thaw will
3289 // recall SelectProperty to recreate them.
3292 // Prevent any further selection measures in this call
3298 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3300 // Only set focus if not deselecting
3303 if ( flags
& wxPG_SEL_FOCUS
)
3307 m_wndEditor
->SetFocus();
3308 m_editorFocused
= 1;
3317 m_inDoSelectProperty
= 0;
3322 // First, deactivate previous
3326 OnValidationFailureReset(m_selected
);
3328 // Must double-check if this is an selected in case of forceswitch
3331 if ( !CommitChangesFromEditor(flags
) )
3333 // Validation has failed, so we can't exit the previous editor
3334 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3335 // _("Invalid Value"),wxOK|wxICON_ERROR);
3336 m_inDoSelectProperty
= 0;
3345 m_pState
->m_selected
= NULL
;
3347 // We need to always fully refresh the grid here
3350 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3351 EditorsValueWasNotModified();
3354 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3357 // Then, activate the one given.
3360 int propY
= p
->GetY2(m_lineHeight
);
3362 int splitterX
= GetSplitterPosition();
3363 m_editorFocused
= 0;
3365 m_pState
->m_selected
= p
;
3366 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3368 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3370 wxASSERT( m_wndEditor
== NULL
);
3373 // Only create editor for non-disabled non-caption
3374 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3376 // do this for non-caption items
3380 // Do we need to paint the custom image, if any?
3381 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3382 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3383 !p
->GetEditorClass()->CanContainCustomImage()
3385 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3387 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3388 wxPoint goodPos
= grect
.GetPosition();
3389 #if wxPG_CREATE_CONTROLS_HIDDEN
3390 int coord_adjust
= m_height
- goodPos
.y
;
3391 goodPos
.y
+= coord_adjust
;
3394 const wxPGEditor
* editor
= p
->GetEditorClass();
3395 wxCHECK_MSG(editor
, false,
3396 wxT("NULL editor class not allowed"));
3398 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3400 wxPGWindowList wndList
= editor
->CreateControls(this,
3405 m_wndEditor
= wndList
.m_primary
;
3406 m_wndEditor2
= wndList
.m_secondary
;
3407 wxWindow
* primaryCtrl
= GetEditorControl();
3410 // Essentially, primaryCtrl == m_wndEditor
3413 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3414 // value is drawn as normal, and m_wndEditor2 is assumed
3415 // to be a right-aligned button that triggers a separate editorCtrl
3420 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3421 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3423 // Set validator, if any
3424 #if wxUSE_VALIDATORS
3425 wxValidator
* validator
= p
->GetValidator();
3427 primaryCtrl
->SetValidator(*validator
);
3430 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3431 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3433 // If it has modified status, use bold font
3434 // (must be done before capturing m_ctrlXAdjust)
3435 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3436 SetCurControlBoldFont();
3439 // Fix TextCtrl indentation
3440 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3441 wxTextCtrl
* tc
= NULL
;
3442 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3443 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3445 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3447 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3450 // Store x relative to splitter (we'll need it).
3451 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3453 // Check if background clear is not necessary
3454 wxPoint pos
= m_wndEditor
->GetPosition();
3455 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3457 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3460 m_wndEditor
->SetSizeHints(3, 3);
3462 #if wxPG_CREATE_CONTROLS_HIDDEN
3463 m_wndEditor
->Show(false);
3464 m_wndEditor
->Freeze();
3466 goodPos
= m_wndEditor
->GetPosition();
3467 goodPos
.y
-= coord_adjust
;
3468 m_wndEditor
->Move( goodPos
);
3471 SetupChildEventHandling(primaryCtrl
);
3473 // Focus and select all (wxTextCtrl, wxComboBox etc)
3474 if ( flags
& wxPG_SEL_FOCUS
)
3476 primaryCtrl
->SetFocus();
3478 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3484 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3485 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3487 // Get proper id for wndSecondary
3488 m_wndSecId
= m_wndEditor2
->GetId();
3489 wxWindowList children
= m_wndEditor2
->GetChildren();
3490 wxWindowList::iterator node
= children
.begin();
3491 if ( node
!= children
.end() )
3492 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3494 m_wndEditor2
->SetSizeHints(3,3);
3496 #if wxPG_CREATE_CONTROLS_HIDDEN
3497 wxRect sec_rect
= m_wndEditor2
->GetRect();
3498 sec_rect
.y
-= coord_adjust
;
3500 // Fine tuning required to fix "oversized"
3501 // button disappearance bug.
3502 if ( sec_rect
.y
< 0 )
3504 sec_rect
.height
+= sec_rect
.y
;
3507 m_wndEditor2
->SetSize( sec_rect
);
3509 m_wndEditor2
->Show();
3511 SetupChildEventHandling(m_wndEditor2
);
3513 // If no primary editor, focus to button to allow
3514 // it to interprete ENTER etc.
3515 // NOTE: Due to problems focusing away from it, this
3516 // has been disabled.
3518 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3519 m_wndEditor2->SetFocus();
3523 if ( flags
& wxPG_SEL_FOCUS
)
3524 m_editorFocused
= 1;
3529 // Make sure focus is in grid canvas (important for wxGTK, at least)
3533 EditorsValueWasNotModified();
3535 // If it's inside collapsed section, expand parent, scroll, etc.
3536 // Also, if it was partially visible, scroll it into view.
3537 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3542 #if wxPG_CREATE_CONTROLS_HIDDEN
3543 m_wndEditor
->Thaw();
3545 m_wndEditor
->Show(true);
3552 // Make sure focus is in grid canvas
3556 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3562 // Show help text in status bar.
3563 // (if found and grid not embedded in manager with help box and
3564 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3567 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3569 wxStatusBar
* statusbar
= NULL
;
3570 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3572 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3574 statusbar
= frame
->GetStatusBar();
3579 const wxString
* pHelpString
= (const wxString
*) NULL
;
3583 pHelpString
= &p
->GetHelpString();
3584 if ( pHelpString
->length() )
3586 // Set help box text.
3587 statusbar
->SetStatusText( *pHelpString
);
3588 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3592 if ( (!pHelpString
|| !pHelpString
->length()) &&
3593 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3595 // Clear help box - but only if it was written
3596 // by us at previous time.
3597 statusbar
->SetStatusText( m_emptyString
);
3598 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3604 m_inDoSelectProperty
= 0;
3606 // call wx event handler (here so that it also occurs on deselection)
3607 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3612 // -----------------------------------------------------------------------
3614 bool wxPropertyGrid::UnfocusEditor()
3616 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3619 if ( !CommitChangesFromEditor(0) )
3623 DrawItem(m_selected
);
3628 // -----------------------------------------------------------------------
3630 void wxPropertyGrid::RefreshEditor()
3632 wxPGProperty
* p
= m_selected
;
3636 wxWindow
* wnd
= GetEditorControl();
3640 // Set editor font boldness - must do this before
3641 // calling UpdateControl().
3642 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3644 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3645 wnd
->SetFont(GetCaptionFont());
3647 wnd
->SetFont(GetFont());
3650 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3652 editorClass
->UpdateControl(p
, wnd
);
3654 if ( p
->IsValueUnspecified() )
3655 editorClass
->SetValueToUnspecified(p
, wnd
);
3658 // -----------------------------------------------------------------------
3660 // This method is not inline because it called dozens of times
3661 // (i.e. two-arg function calls create smaller code size).
3662 bool wxPropertyGrid::DoClearSelection()
3664 return DoSelectProperty(NULL
);
3667 // -----------------------------------------------------------------------
3668 // wxPropertyGrid expand/collapse state
3669 // -----------------------------------------------------------------------
3671 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3673 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3675 // If active editor was inside collapsed section, then disable it
3676 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3678 ClearSelection(false);
3681 // Store dont-center-splitter flag 'cause we need to temporarily set it
3682 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3683 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3685 bool res
= m_pState
->DoCollapse(pwc
);
3690 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3692 RecalculateVirtualSize();
3694 // Redraw etc. only if collapsed was visible.
3695 if (pwc
->IsVisible() &&
3697 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3699 // When item is collapsed so that scrollbar would move,
3700 // graphics mess is about (unless we redraw everything).
3705 // Clear dont-center-splitter flag if it wasn't set
3706 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3711 // -----------------------------------------------------------------------
3713 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3715 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3717 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3719 // Store dont-center-splitter flag 'cause we need to temporarily set it
3720 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3721 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3723 bool res
= m_pState
->DoExpand(pwc
);
3728 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3730 RecalculateVirtualSize();
3732 // Redraw etc. only if expanded was visible.
3733 if ( pwc
->IsVisible() && !m_frozen
&&
3734 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3738 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3741 DrawItems(pwc
, NULL
);
3746 // Clear dont-center-splitter flag if it wasn't set
3747 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3752 // -----------------------------------------------------------------------
3754 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3757 return m_pState
->DoHideProperty(p
, hide
, flags
);
3760 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3763 ClearSelection(false);
3766 m_pState
->DoHideProperty(p
, hide
, flags
);
3768 RecalculateVirtualSize();
3775 // -----------------------------------------------------------------------
3776 // wxPropertyGrid size related methods
3777 // -----------------------------------------------------------------------
3779 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3781 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3785 // If virtual height was changed, then recalculate editor control position(s)
3786 if ( m_pState
->m_vhCalcPending
)
3787 CorrectEditorWidgetPosY();
3789 m_pState
->EnsureVirtualHeight();
3791 wxASSERT_LEVEL_2_MSG(
3792 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
3793 "VirtualHeight and ActualVirtualHeight should match"
3796 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3798 int x
= m_pState
->m_width
;
3799 int y
= m_pState
->m_virtualHeight
;
3802 GetClientSize(&width
,&height
);
3804 // Now adjust virtual size.
3805 SetVirtualSize(x
, y
);
3811 // Adjust scrollbars
3812 if ( HasVirtualWidth() )
3814 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3815 xPos
= GetScrollPos( wxHORIZONTAL
);
3818 if ( forceXPos
!= -1 )
3821 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3824 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3825 int yPos
= GetScrollPos( wxVERTICAL
);
3827 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3828 xAmount
, yAmount
, xPos
, yPos
, true );
3830 // Must re-get size now
3831 GetClientSize(&width
,&height
);
3833 if ( !HasVirtualWidth() )
3835 m_pState
->SetVirtualWidth(width
);
3842 m_canvas
->SetSize( x
, y
);
3844 m_pState
->CheckColumnWidths();
3847 CorrectEditorWidgetSizeX();
3849 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3852 // -----------------------------------------------------------------------
3854 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3856 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3860 GetClientSize(&width
,&height
);
3865 #if wxPG_DOUBLE_BUFFER
3866 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3868 int dblh
= (m_lineHeight
*2);
3869 if ( !m_doubleBuffer
)
3871 // Create double buffer bitmap to draw on, if none
3872 int w
= (width
>250)?width
:250;
3873 int h
= height
+ dblh
;
3875 m_doubleBuffer
= new wxBitmap( w
, h
);
3879 int w
= m_doubleBuffer
->GetWidth();
3880 int h
= m_doubleBuffer
->GetHeight();
3882 // Double buffer must be large enough
3883 if ( w
< width
|| h
< (height
+dblh
) )
3885 if ( w
< width
) w
= width
;
3886 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3887 delete m_doubleBuffer
;
3888 m_doubleBuffer
= new wxBitmap( w
, h
);
3895 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3896 m_ncWidth
= event
.GetSize().x
;
3900 if ( m_pState
->m_itemsAdded
)
3901 PrepareAfterItemsAdded();
3903 // Without this, virtual size (atleast under wxGTK) will be skewed
3904 RecalculateVirtualSize();
3910 // -----------------------------------------------------------------------
3912 void wxPropertyGrid::SetVirtualWidth( int width
)
3916 // Disable virtual width
3917 width
= GetClientSize().x
;
3918 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3922 // Enable virtual width
3923 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3925 m_pState
->SetVirtualWidth( width
);
3928 void wxPropertyGrid::SetFocusOnCanvas()
3930 m_canvas
->SetFocusIgnoringChildren();
3931 m_editorFocused
= 0;
3934 // -----------------------------------------------------------------------
3935 // wxPropertyGrid mouse event handling
3936 // -----------------------------------------------------------------------
3938 // selFlags uses same values DoSelectProperty's flags
3939 // Returns true if event was vetoed.
3940 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3942 // Send property grid event of specific type and with specific property
3943 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3944 evt
.SetPropertyGrid(this);
3945 evt
.SetEventObject(m_eventObject
);
3949 evt
.SetCanVeto(true);
3950 evt
.SetupValidationInfo();
3951 m_validationInfo
.m_pValue
= pValue
;
3953 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3955 evtHandler
->ProcessEvent(evt
);
3957 return evt
.WasVetoed();
3960 // -----------------------------------------------------------------------
3962 // Return false if should be skipped
3963 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3967 // Need to set focus?
3968 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3973 wxPropertyGridPageState
* state
= m_pState
;
3975 int splitterHitOffset
;
3976 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3978 wxPGProperty
* p
= DoGetItemAtY(y
);
3982 int depth
= (int)p
->GetDepth() - 1;
3984 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3986 if ( x
>= marginEnds
)
3990 if ( p
->IsCategory() )
3992 // This is category.
3993 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3995 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3997 // Expand, collapse, activate etc. if click on text or left of splitter.
4000 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4005 if ( !DoSelectProperty( p
) )
4008 // On double-click, expand/collapse.
4009 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4011 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4012 else DoExpand( p
, true );
4016 else if ( splitterHit
== -1 )
4019 unsigned int selFlag
= 0;
4020 if ( columnHit
== 1 )
4022 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4023 selFlag
= wxPG_SEL_FOCUS
;
4025 if ( !DoSelectProperty( p
, selFlag
) )
4028 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4030 if ( p
->GetChildCount() && !p
->IsCategory() )
4031 // On double-click, expand/collapse.
4032 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4034 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4035 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4036 else DoExpand( p
, true );
4043 // click on splitter
4044 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4046 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4048 // Double-clicking the splitter causes auto-centering
4049 CenterSplitter( true );
4051 else if ( m_dragStatus
== 0 )
4054 // Begin draggin the splitter
4058 // Changes must be committed here or the
4059 // value won't be drawn correctly
4060 if ( !CommitChangesFromEditor() )
4063 m_wndEditor
->Show ( false );
4066 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4068 m_canvas
->CaptureMouse();
4069 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4073 m_draggedSplitter
= splitterHit
;
4074 m_dragOffset
= splitterHitOffset
;
4076 wxClientDC
dc(m_canvas
);
4078 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4079 // Fixes button disappearance bug
4081 m_wndEditor2
->Show ( false );
4084 m_startingSplitterX
= x
- splitterHitOffset
;
4092 if ( p
->GetChildCount() )
4094 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4096 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4098 int y2
= y
% m_lineHeight
;
4099 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4101 // On click on expander button, expand/collapse
4102 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4103 DoCollapse( p
, true );
4105 DoExpand( p
, true );
4114 // -----------------------------------------------------------------------
4116 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4117 wxMouseEvent
& WXUNUSED(event
) )
4121 // Select property here as well
4122 wxPGProperty
* p
= m_propHover
;
4123 if ( p
!= m_selected
)
4124 DoSelectProperty( p
);
4126 // Send right click event.
4127 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4134 // -----------------------------------------------------------------------
4136 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4137 wxMouseEvent
& WXUNUSED(event
) )
4141 // Select property here as well
4142 wxPGProperty
* p
= m_propHover
;
4144 if ( p
!= m_selected
)
4145 DoSelectProperty( p
);
4147 // Send double-click event.
4148 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4155 // -----------------------------------------------------------------------
4157 #if wxPG_SUPPORT_TOOLTIPS
4159 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4161 if ( tipString
.length() )
4163 m_canvas
->SetToolTip(tipString
);
4167 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4168 m_canvas
->SetToolTip( m_emptyString
);
4170 m_canvas
->SetToolTip( NULL
);
4175 #endif // #if wxPG_SUPPORT_TOOLTIPS
4177 // -----------------------------------------------------------------------
4179 // Return false if should be skipped
4180 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4182 // Safety check (needed because mouse capturing may
4183 // otherwise freeze the control)
4184 if ( m_dragStatus
> 0 && !event
.Dragging() )
4186 HandleMouseUp(x
,y
,event
);
4189 wxPropertyGridPageState
* state
= m_pState
;
4191 int splitterHitOffset
;
4192 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4193 int splitterX
= x
- splitterHitOffset
;
4195 if ( m_dragStatus
> 0 )
4197 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4198 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4201 int newSplitterX
= x
- m_dragOffset
;
4202 int splitterX
= x
- splitterHitOffset
;
4204 // Splitter redraw required?
4205 if ( newSplitterX
!= splitterX
)
4208 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4209 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4210 state
->m_fSplitterX
= (float) newSplitterX
;
4213 CorrectEditorWidgetSizeX();
4227 int ih
= m_lineHeight
;
4230 #if wxPG_SUPPORT_TOOLTIPS
4231 wxPGProperty
* prevHover
= m_propHover
;
4232 unsigned char prevSide
= m_mouseSide
;
4234 int curPropHoverY
= y
- (y
% ih
);
4236 // On which item it hovers
4239 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4242 // Mouse moves on another property
4244 m_propHover
= DoGetItemAtY(y
);
4245 m_propHoverY
= curPropHoverY
;
4248 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4251 #if wxPG_SUPPORT_TOOLTIPS
4252 // Store which side we are on
4254 if ( columnHit
== 1 )
4256 else if ( columnHit
== 0 )
4260 // If tooltips are enabled, show label or value as a tip
4261 // in case it doesn't otherwise show in full length.
4263 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4265 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4267 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4269 if ( m_propHover
&& !m_propHover
->IsCategory() )
4272 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4274 // Show help string as a tooltip
4275 wxString tipString
= m_propHover
->GetHelpString();
4277 SetToolTip(tipString
);
4281 // Show cropped value string as a tooltip
4285 if ( m_mouseSide
== 1 )
4287 tipString
= m_propHover
->m_label
;
4288 space
= splitterX
-m_marginWidth
-3;
4290 else if ( m_mouseSide
== 2 )
4292 tipString
= m_propHover
->GetDisplayedString();
4294 space
= m_width
- splitterX
;
4295 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4296 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4302 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4305 SetToolTip( tipString
);
4312 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4313 m_canvas
->SetToolTip( m_emptyString
);
4315 m_canvas
->SetToolTip( NULL
);
4326 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4327 m_canvas
->SetToolTip( m_emptyString
);
4329 m_canvas
->SetToolTip( NULL
);
4337 if ( splitterHit
== -1 ||
4339 HasFlag(wxPG_STATIC_SPLITTER
) )
4341 // hovering on something else
4342 if ( m_curcursor
!= wxCURSOR_ARROW
)
4343 CustomSetCursor( wxCURSOR_ARROW
);
4347 // Do not allow splitter cursor on caption items.
4348 // (also not if we were dragging and its started
4349 // outside the splitter region)
4351 if ( !m_propHover
->IsCategory() &&
4355 // hovering on splitter
4357 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4358 // reliably detected.
4359 //if ( m_curcursor != wxCURSOR_SIZEWE )
4360 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4366 // hovering on something else
4367 if ( m_curcursor
!= wxCURSOR_ARROW
)
4368 CustomSetCursor( wxCURSOR_ARROW
);
4375 // -----------------------------------------------------------------------
4377 // Also handles Leaving event
4378 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4379 wxMouseEvent
&WXUNUSED(event
) )
4381 wxPropertyGridPageState
* state
= m_pState
;
4385 int splitterHitOffset
;
4386 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4388 // No event type check - basicly calling this method should
4389 // just stop dragging.
4390 // Left up after dragged?
4391 if ( m_dragStatus
>= 1 )
4394 // End Splitter Dragging
4396 // DO NOT ENABLE FOLLOWING LINE!
4397 // (it is only here as a reminder to not to do it)
4400 // Disable splitter auto-centering
4401 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4403 // This is necessary to return cursor
4404 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4406 m_canvas
->ReleaseMouse();
4407 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4410 // Set back the default cursor, if necessary
4411 if ( splitterHit
== -1 ||
4414 CustomSetCursor( wxCURSOR_ARROW
);
4419 // Control background needs to be cleared
4420 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4421 DrawItem( m_selected
);
4425 m_wndEditor
->Show ( true );
4428 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4429 // Fixes button disappearance bug
4431 m_wndEditor2
->Show ( true );
4434 // This clears the focus.
4435 m_editorFocused
= 0;
4441 // -----------------------------------------------------------------------
4443 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4445 int splitterX
= GetSplitterPosition();
4448 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4452 wxWindow
* wnd
= GetEditorControl();
4454 // Hide popup on clicks
4455 if ( event
.GetEventType() != wxEVT_MOTION
)
4456 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4458 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4464 if ( wnd
== NULL
|| m_dragStatus
||
4466 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4467 ux
>= (r
.x
+r
.width
) ||
4469 event
.m_y
>= (r
.y
+r
.height
)
4479 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4484 // -----------------------------------------------------------------------
4486 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4489 if ( OnMouseCommon( event
, &x
, &y
) )
4491 HandleMouseClick(x
,y
,event
);
4496 // -----------------------------------------------------------------------
4498 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4501 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4502 HandleMouseRightClick(x
,y
,event
);
4506 // -----------------------------------------------------------------------
4508 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4510 // Always run standard mouse-down handler as well
4511 OnMouseClick(event
);
4514 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4515 HandleMouseDoubleClick(x
,y
,event
);
4519 // -----------------------------------------------------------------------
4521 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4524 if ( OnMouseCommon( event
, &x
, &y
) )
4526 HandleMouseMove(x
,y
,event
);
4531 // -----------------------------------------------------------------------
4533 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4535 // Called when mouse moves in the empty space below the properties.
4536 CustomSetCursor( wxCURSOR_ARROW
);
4539 // -----------------------------------------------------------------------
4541 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4544 if ( OnMouseCommon( event
, &x
, &y
) )
4546 HandleMouseUp(x
,y
,event
);
4551 // -----------------------------------------------------------------------
4553 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4555 // This may get called from child control as well, so event's
4556 // mouse position cannot be relied on.
4558 if ( event
.Entering() )
4560 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4562 // TODO: Fix this (detect parent and only do
4563 // cursor trick if it is a manager).
4564 wxASSERT( GetParent() );
4565 GetParent()->SetCursor(wxNullCursor
);
4567 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4570 GetParent()->SetCursor(wxNullCursor
);
4572 else if ( event
.Leaving() )
4574 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4575 m_canvas
->SetCursor( wxNullCursor
);
4577 // Get real cursor position
4578 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4580 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4583 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4585 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4589 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4597 // -----------------------------------------------------------------------
4599 // Common code used by various OnMouseXXXChild methods.
4600 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4602 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4603 wxASSERT( topCtrlWnd
);
4605 event
.GetPosition(&x
,&y
);
4607 int splitterX
= GetSplitterPosition();
4609 wxRect r
= topCtrlWnd
->GetRect();
4610 if ( !m_dragStatus
&&
4611 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4612 y
>= 0 && y
< r
.height \
4615 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4620 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4627 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4630 if ( OnMouseChildCommon(event
,&x
,&y
) )
4632 bool res
= HandleMouseClick(x
,y
,event
);
4633 if ( !res
) event
.Skip();
4637 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4640 wxASSERT( m_wndEditor
);
4641 // These coords may not be exact (about +-2),
4642 // but that should not matter (right click is about item, not position).
4643 wxPoint pt
= m_wndEditor
->GetPosition();
4644 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4645 wxASSERT( m_selected
);
4646 m_propHover
= m_selected
;
4647 bool res
= HandleMouseRightClick(x
,y
,event
);
4648 if ( !res
) event
.Skip();
4651 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4654 if ( OnMouseChildCommon(event
,&x
,&y
) )
4656 bool res
= HandleMouseMove(x
,y
,event
);
4657 if ( !res
) event
.Skip();
4661 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4664 if ( OnMouseChildCommon(event
,&x
,&y
) )
4666 bool res
= HandleMouseUp(x
,y
,event
);
4667 if ( !res
) event
.Skip();
4671 // -----------------------------------------------------------------------
4672 // wxPropertyGrid keyboard event handling
4673 // -----------------------------------------------------------------------
4675 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4677 // Translates wxKeyEvent to wxPG_ACTION_XXX
4679 int keycode
= event
.GetKeyCode();
4680 int modifiers
= event
.GetModifiers();
4682 wxASSERT( !(modifiers
&~(0xFFFF)) );
4684 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4686 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4688 if ( it
== m_actionTriggers
.end() )
4693 int second
= (it
->second
>>16) & 0xFFFF;
4697 return (it
->second
& 0xFFFF);
4700 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4702 wxASSERT( !(modifiers
&~(0xFFFF)) );
4704 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4706 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4708 if ( it
!= m_actionTriggers
.end() )
4710 // This key combination is already used
4712 // Can add secondary?
4713 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4714 wxT("You can only add up to two separate actions per key combination.") );
4716 action
= it
->second
| (action
<<16);
4719 m_actionTriggers
[hashMapKey
] = action
;
4722 void wxPropertyGrid::ClearActionTriggers( int action
)
4724 wxPGHashMapI2I::iterator it
;
4726 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4728 if ( it
->second
== action
)
4730 m_actionTriggers
.erase(it
);
4735 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4738 // Handles key event when editor control is not focused.
4741 wxCHECK2(!m_frozen
, return);
4743 // Travelsal between items, collapsing/expanding, etc.
4744 int keycode
= event
.GetKeyCode();
4745 bool editorFocused
= IsEditorFocused();
4747 if ( keycode
== WXK_TAB
)
4749 wxWindow
* mainControl
;
4751 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4752 mainControl
= GetParent();
4756 if ( !event
.ShiftDown() )
4758 if ( !editorFocused
&& m_wndEditor
)
4760 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4764 // Tab traversal workaround for platforms on which
4765 // wxWindow::Navigate() may navigate into first child
4766 // instead of next sibling. Does not work perfectly
4767 // in every scenario (for instance, when property grid
4768 // is either first or last control).
4769 #if defined(__WXGTK__)
4770 wxWindow
* sibling
= mainControl
->GetNextSibling();
4772 sibling
->SetFocusFromKbd();
4774 Navigate(wxNavigationKeyEvent::IsForward
);
4780 if ( editorFocused
)
4786 #if defined(__WXGTK__)
4787 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4789 sibling
->SetFocusFromKbd();
4791 Navigate(wxNavigationKeyEvent::IsBackward
);
4799 // Ignore Alt and Control when they are down alone
4800 if ( keycode
== WXK_ALT
||
4801 keycode
== WXK_CONTROL
)
4808 int action
= KeyEventToActions(event
, &secondAction
);
4810 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4813 // Esc cancels any changes
4814 if ( IsEditorsValueModified() )
4816 EditorsValueWasNotModified();
4818 // Update the control as well
4819 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4821 m_selected
->GetDisplayedString() );
4824 OnValidationFailureReset(m_selected
);
4830 // Except for TAB and ESC, handle child control events in child control
4833 // Only propagate event if it had modifiers
4834 if ( !event
.HasModifiers() )
4836 event
.StopPropagation();
4842 bool wasHandled
= false;
4847 if ( ButtonTriggerKeyTest(action
, event
) )
4850 wxPGProperty
* p
= m_selected
;
4852 // Travel and expand/collapse
4855 if ( p
->GetChildCount() )
4857 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4859 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4862 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4864 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4871 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4875 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4881 if ( selectDir
>= -1 )
4883 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4885 DoSelectProperty(p
);
4891 // If nothing was selected, select the first item now
4892 // (or navigate out of tab).
4893 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4895 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4896 if ( p
) DoSelectProperty(p
);
4905 // -----------------------------------------------------------------------
4907 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4909 // If there was editor open and focused, then this event should not
4910 // really be processed here.
4911 if ( IsEditorFocused() )
4913 // However, if event had modifiers, it is probably still best
4915 if ( event
.HasModifiers() )
4918 event
.StopPropagation();
4922 HandleKeyEvent(event
, false);
4925 // -----------------------------------------------------------------------
4927 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4932 action
= KeyEventToActions(event
, &secondAction
);
4935 // Does the keycode trigger button?
4936 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4939 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4940 GetEventHandler()->AddPendingEvent(evt
);
4947 // -----------------------------------------------------------------------
4949 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4951 HandleKeyEvent(event
, true);
4954 // -----------------------------------------------------------------------
4955 // wxPropertyGrid miscellaneous event handling
4956 // -----------------------------------------------------------------------
4958 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4961 // Check if the focus is in this control or one of its children
4962 wxWindow
* newFocused
= wxWindow::FindFocus();
4964 if ( newFocused
!= m_curFocused
)
4965 HandleFocusChange( newFocused
);
4968 // Check if top-level parent has changed
4969 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
4976 bool wxPropertyGrid::IsEditorFocused() const
4978 wxWindow
* focus
= wxWindow::FindFocus();
4980 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4981 focus
== GetEditorControl() )
4987 // Called by focus event handlers. newFocused is the window that becomes focused.
4988 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4990 unsigned int oldFlags
= m_iFlags
;
4992 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4994 wxWindow
* parent
= newFocused
;
4996 // This must be one of nextFocus' parents.
4999 // Use m_eventObject, which is either wxPropertyGrid or
5000 // wxPropertyGridManager, as appropriate.
5001 if ( parent
== m_eventObject
)
5003 m_iFlags
|= wxPG_FL_FOCUSED
;
5006 parent
= parent
->GetParent();
5009 m_curFocused
= newFocused
;
5011 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5012 (oldFlags
& wxPG_FL_FOCUSED
) )
5014 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5016 // Need to store changed value
5017 CommitChangesFromEditor();
5023 // Preliminary code for tab-order respecting
5024 // tab-traversal (but should be moved to
5027 wxWindow* prevFocus = event.GetWindow();
5028 wxWindow* useThis = this;
5029 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5030 useThis = GetParent();
5033 prevFocus->GetParent() == useThis->GetParent() )
5035 wxList& children = useThis->GetParent()->GetChildren();
5037 wxNode* node = children.Find(prevFocus);
5039 if ( node->GetNext() &&
5040 useThis == node->GetNext()->GetData() )
5041 DoSelectProperty(GetFirst());
5042 else if ( node->GetPrevious () &&
5043 useThis == node->GetPrevious()->GetData() )
5044 DoSelectProperty(GetLastProperty());
5051 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5052 DrawItem( m_selected
);
5056 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5058 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5059 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5060 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5061 //else if ( event.GetWindow() )
5063 HandleFocusChange(event
.GetWindow());
5068 // -----------------------------------------------------------------------
5070 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5072 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5076 // -----------------------------------------------------------------------
5078 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5080 m_iFlags
|= wxPG_FL_SCROLLED
;
5085 // -----------------------------------------------------------------------
5087 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5089 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5091 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5095 // -----------------------------------------------------------------------
5096 // Property editor related functions
5097 // -----------------------------------------------------------------------
5099 // noDefCheck = true prevents infinite recursion.
5100 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5101 const wxString
& editorName
,
5104 wxASSERT( editorClass
);
5106 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5107 RegisterDefaultEditors();
5109 wxString name
= editorName
;
5110 if ( name
.length() == 0 )
5111 name
= editorClass
->GetName();
5113 // Existing editor under this name?
5114 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5116 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5118 // If this name was already used, try class name.
5119 name
= editorClass
->GetClassInfo()->GetClassName();
5120 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5123 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5124 (wxPGEditor
*) vt_it
->second
,
5125 "Editor with given name was already registered" );
5127 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5132 // Use this in RegisterDefaultEditors.
5133 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5134 if ( wxPGEditor_##EDITOR == NULL ) \
5136 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5137 new wxPG##EDITOR##Editor, true ); \
5140 // Registers all default editor classes
5141 void wxPropertyGrid::RegisterDefaultEditors()
5143 wxPGRegisterDefaultEditorClass( TextCtrl
);
5144 wxPGRegisterDefaultEditorClass( Choice
);
5145 wxPGRegisterDefaultEditorClass( ComboBox
);
5146 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5147 #if wxPG_INCLUDE_CHECKBOX
5148 wxPGRegisterDefaultEditorClass( CheckBox
);
5150 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5152 // Register SpinCtrl etc. editors before use
5153 RegisterAdditionalEditors();
5156 // -----------------------------------------------------------------------
5157 // wxPGStringTokenizer
5158 // Needed to handle C-style string lists (e.g. "str1" "str2")
5159 // -----------------------------------------------------------------------
5161 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5162 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5166 wxPGStringTokenizer::~wxPGStringTokenizer()
5170 bool wxPGStringTokenizer::HasMoreTokens()
5172 const wxString
& str
= *m_str
;
5174 wxString::const_iterator i
= m_curPos
;
5176 wxUniChar delim
= m_delimeter
;
5178 wxUniChar prev_a
= wxT('\0');
5180 bool inToken
= false;
5182 while ( i
!= str
.end() )
5191 m_readyToken
.clear();
5196 if ( prev_a
!= wxT('\\') )
5200 if ( a
!= wxT('\\') )
5220 m_curPos
= str
.end();
5228 wxString
wxPGStringTokenizer::GetNextToken()
5230 return m_readyToken
;
5233 // -----------------------------------------------------------------------
5235 // -----------------------------------------------------------------------
5237 wxPGChoiceEntry::wxPGChoiceEntry()
5238 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5242 // -----------------------------------------------------------------------
5244 // -----------------------------------------------------------------------
5246 wxPGChoicesData::wxPGChoicesData()
5250 wxPGChoicesData::~wxPGChoicesData()
5255 void wxPGChoicesData::Clear()
5260 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5262 wxASSERT( m_items
.size() == 0 );
5264 m_items
= data
->m_items
;
5267 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5268 const wxPGChoiceEntry
& item
)
5270 wxVector
<wxPGChoiceEntry
>::iterator it
;
5274 index
= (int) m_items
.size();
5278 it
= m_items
.begin() + index
;
5281 m_items
.insert(it
, item
);
5283 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5285 // Need to fix value?
5286 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5287 ownEntry
.SetValue(index
);
5292 // -----------------------------------------------------------------------
5293 // wxPropertyGridEvent
5294 // -----------------------------------------------------------------------
5296 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5299 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5300 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5301 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5302 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5303 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5304 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5305 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5306 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5307 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5310 // -----------------------------------------------------------------------
5312 void wxPropertyGridEvent::Init()
5314 m_validationInfo
= NULL
;
5316 m_wasVetoed
= false;
5319 // -----------------------------------------------------------------------
5321 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5322 : wxCommandEvent(commandType
,id
)
5328 // -----------------------------------------------------------------------
5330 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5331 : wxCommandEvent(event
)
5333 m_eventType
= event
.GetEventType();
5334 m_eventObject
= event
.m_eventObject
;
5336 m_property
= event
.m_property
;
5337 m_validationInfo
= event
.m_validationInfo
;
5338 m_canVeto
= event
.m_canVeto
;
5339 m_wasVetoed
= event
.m_wasVetoed
;
5342 // -----------------------------------------------------------------------
5344 wxPropertyGridEvent::~wxPropertyGridEvent()
5348 // -----------------------------------------------------------------------
5350 wxEvent
* wxPropertyGridEvent::Clone() const
5352 return new wxPropertyGridEvent( *this );
5355 // -----------------------------------------------------------------------
5356 // wxPropertyGridPopulator
5357 // -----------------------------------------------------------------------
5359 wxPropertyGridPopulator::wxPropertyGridPopulator()
5363 wxPGGlobalVars
->m_offline
++;
5366 // -----------------------------------------------------------------------
5368 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5371 m_propHierarchy
.clear();
5374 // -----------------------------------------------------------------------
5376 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5382 // -----------------------------------------------------------------------
5384 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5387 // Free unused sets of choices
5388 wxPGHashMapS2P::iterator it
;
5390 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5392 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5399 m_pg
->GetPanel()->Refresh();
5401 wxPGGlobalVars
->m_offline
--;
5404 // -----------------------------------------------------------------------
5406 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5407 const wxString
& propLabel
,
5408 const wxString
& propName
,
5409 const wxString
* propValue
,
5410 wxPGChoices
* pChoices
)
5412 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5413 wxPGProperty
* parent
= GetCurParent();
5415 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5417 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5421 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5423 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5427 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5429 property
->SetLabel(propLabel
);
5430 property
->DoSetName(propName
);
5432 if ( pChoices
&& pChoices
->IsOk() )
5433 property
->SetChoices(*pChoices
);
5435 m_state
->DoInsert(parent
, -1, property
);
5438 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5439 wxPG_PROGRAMMATIC_VALUE
);
5444 // -----------------------------------------------------------------------
5446 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5448 m_propHierarchy
.push_back(property
);
5449 DoScanForChildren();
5450 m_propHierarchy
.pop_back();
5453 // -----------------------------------------------------------------------
5455 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5456 const wxString
& idString
)
5458 wxPGChoices choices
;
5461 if ( choicesString
[0] == wxT('@') )
5463 wxString ids
= choicesString
.substr(1);
5464 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5465 if ( it
== m_dictIdChoices
.end() )
5466 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5468 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5473 if ( idString
.length() )
5475 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5476 if ( it
!= m_dictIdChoices
.end() )
5478 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5485 // Parse choices string
5486 wxString::const_iterator it
= choicesString
.begin();
5490 bool labelValid
= false;
5492 for ( ; it
!= choicesString
.end(); ++it
)
5498 if ( c
== wxT('"') )
5503 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5504 choices
.Add(label
, l
);
5507 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5512 else if ( c
== wxT('=') )
5519 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5526 if ( c
== wxT('"') )
5539 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5540 choices
.Add(label
, l
);
5543 if ( !choices
.IsOk() )
5545 choices
.EnsureData();
5549 if ( idString
.length() )
5550 m_dictIdChoices
[idString
] = choices
.GetData();
5557 // -----------------------------------------------------------------------
5559 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5561 if ( s
.Last() == wxT('%') )
5563 wxString s2
= s
.substr(0,s
.length()-1);
5565 if ( s2
.ToLong(&val
, 10) )
5567 *pval
= (val
*max
)/100;
5573 return s
.ToLong(pval
, 10);
5576 // -----------------------------------------------------------------------
5578 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5579 const wxString
& type
,
5580 const wxString
& value
)
5582 int l
= m_propHierarchy
.size();
5586 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5587 wxString valuel
= value
.Lower();
5590 if ( type
.length() == 0 )
5595 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5597 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5599 else if ( value
.ToLong(&v
, 0) )
5606 if ( type
== wxT("string") )
5610 else if ( type
== wxT("int") )
5613 value
.ToLong(&v
, 0);
5616 else if ( type
== wxT("bool") )
5618 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5625 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5630 p
->SetAttribute( name
, variant
);
5635 // -----------------------------------------------------------------------
5637 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5639 wxLogError(_("Error in resource: %s"),msg
.c_str());
5642 // -----------------------------------------------------------------------
5644 #endif // wxUSE_PROPGRID