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
)
3249 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3250 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3254 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3258 if ( m_inDoSelectProperty
)
3261 m_inDoSelectProperty
= 1;
3263 wxPGProperty
* prev
= m_selected
;
3267 m_inDoSelectProperty
= 0;
3273 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3275 wxPrintf( "None selected\n" );
3278 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3280 wxPrintf( "P = NULL\n" );
3283 // If we are frozen, then just set the values.
3286 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3287 m_editorFocused
= 0;
3290 m_pState
->m_selected
= p
;
3292 // If frozen, always free controls. But don't worry, as Thaw will
3293 // recall SelectProperty to recreate them.
3296 // Prevent any further selection measures in this call
3302 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3304 // Only set focus if not deselecting
3307 if ( flags
& wxPG_SEL_FOCUS
)
3311 m_wndEditor
->SetFocus();
3312 m_editorFocused
= 1;
3321 m_inDoSelectProperty
= 0;
3326 // First, deactivate previous
3330 OnValidationFailureReset(m_selected
);
3332 // Must double-check if this is an selected in case of forceswitch
3335 if ( !CommitChangesFromEditor(flags
) )
3337 // Validation has failed, so we can't exit the previous editor
3338 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3339 // _("Invalid Value"),wxOK|wxICON_ERROR);
3340 m_inDoSelectProperty
= 0;
3349 m_pState
->m_selected
= NULL
;
3351 // We need to always fully refresh the grid here
3354 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3355 EditorsValueWasNotModified();
3358 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3361 // Then, activate the one given.
3364 int propY
= p
->GetY2(m_lineHeight
);
3366 int splitterX
= GetSplitterPosition();
3367 m_editorFocused
= 0;
3369 m_pState
->m_selected
= p
;
3370 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3372 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3374 wxASSERT( m_wndEditor
== NULL
);
3377 // Only create editor for non-disabled non-caption
3378 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3380 // do this for non-caption items
3384 // Do we need to paint the custom image, if any?
3385 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3386 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3387 !p
->GetEditorClass()->CanContainCustomImage()
3389 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3391 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3392 wxPoint goodPos
= grect
.GetPosition();
3393 #if wxPG_CREATE_CONTROLS_HIDDEN
3394 int coord_adjust
= m_height
- goodPos
.y
;
3395 goodPos
.y
+= coord_adjust
;
3398 const wxPGEditor
* editor
= p
->GetEditorClass();
3399 wxCHECK_MSG(editor
, false,
3400 wxT("NULL editor class not allowed"));
3402 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3404 wxPGWindowList wndList
= editor
->CreateControls(this,
3409 m_wndEditor
= wndList
.m_primary
;
3410 m_wndEditor2
= wndList
.m_secondary
;
3411 wxWindow
* primaryCtrl
= GetEditorControl();
3414 // Essentially, primaryCtrl == m_wndEditor
3417 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3418 // value is drawn as normal, and m_wndEditor2 is assumed
3419 // to be a right-aligned button that triggers a separate editorCtrl
3424 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3425 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3427 // Set validator, if any
3428 #if wxUSE_VALIDATORS
3429 wxValidator
* validator
= p
->GetValidator();
3431 primaryCtrl
->SetValidator(*validator
);
3434 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3435 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3437 // If it has modified status, use bold font
3438 // (must be done before capturing m_ctrlXAdjust)
3439 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3440 SetCurControlBoldFont();
3443 // Fix TextCtrl indentation
3444 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3445 wxTextCtrl
* tc
= NULL
;
3446 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3447 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3449 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3451 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3454 // Store x relative to splitter (we'll need it).
3455 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3457 // Check if background clear is not necessary
3458 wxPoint pos
= m_wndEditor
->GetPosition();
3459 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3461 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3464 m_wndEditor
->SetSizeHints(3, 3);
3466 #if wxPG_CREATE_CONTROLS_HIDDEN
3467 m_wndEditor
->Show(false);
3468 m_wndEditor
->Freeze();
3470 goodPos
= m_wndEditor
->GetPosition();
3471 goodPos
.y
-= coord_adjust
;
3472 m_wndEditor
->Move( goodPos
);
3475 SetupChildEventHandling(primaryCtrl
);
3477 // Focus and select all (wxTextCtrl, wxComboBox etc)
3478 if ( flags
& wxPG_SEL_FOCUS
)
3480 primaryCtrl
->SetFocus();
3482 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3488 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3489 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3491 // Get proper id for wndSecondary
3492 m_wndSecId
= m_wndEditor2
->GetId();
3493 wxWindowList children
= m_wndEditor2
->GetChildren();
3494 wxWindowList::iterator node
= children
.begin();
3495 if ( node
!= children
.end() )
3496 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3498 m_wndEditor2
->SetSizeHints(3,3);
3500 #if wxPG_CREATE_CONTROLS_HIDDEN
3501 wxRect sec_rect
= m_wndEditor2
->GetRect();
3502 sec_rect
.y
-= coord_adjust
;
3504 // Fine tuning required to fix "oversized"
3505 // button disappearance bug.
3506 if ( sec_rect
.y
< 0 )
3508 sec_rect
.height
+= sec_rect
.y
;
3511 m_wndEditor2
->SetSize( sec_rect
);
3513 m_wndEditor2
->Show();
3515 SetupChildEventHandling(m_wndEditor2
);
3517 // If no primary editor, focus to button to allow
3518 // it to interprete ENTER etc.
3519 // NOTE: Due to problems focusing away from it, this
3520 // has been disabled.
3522 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3523 m_wndEditor2->SetFocus();
3527 if ( flags
& wxPG_SEL_FOCUS
)
3528 m_editorFocused
= 1;
3533 // Make sure focus is in grid canvas (important for wxGTK, at least)
3537 EditorsValueWasNotModified();
3539 // If it's inside collapsed section, expand parent, scroll, etc.
3540 // Also, if it was partially visible, scroll it into view.
3541 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3546 #if wxPG_CREATE_CONTROLS_HIDDEN
3547 m_wndEditor
->Thaw();
3549 m_wndEditor
->Show(true);
3556 // Make sure focus is in grid canvas
3560 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3566 // Show help text in status bar.
3567 // (if found and grid not embedded in manager with help box and
3568 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3571 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3573 wxStatusBar
* statusbar
= NULL
;
3574 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3576 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3578 statusbar
= frame
->GetStatusBar();
3583 const wxString
* pHelpString
= (const wxString
*) NULL
;
3587 pHelpString
= &p
->GetHelpString();
3588 if ( pHelpString
->length() )
3590 // Set help box text.
3591 statusbar
->SetStatusText( *pHelpString
);
3592 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3596 if ( (!pHelpString
|| !pHelpString
->length()) &&
3597 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3599 // Clear help box - but only if it was written
3600 // by us at previous time.
3601 statusbar
->SetStatusText( m_emptyString
);
3602 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3608 m_inDoSelectProperty
= 0;
3610 // call wx event handler (here so that it also occurs on deselection)
3611 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3616 // -----------------------------------------------------------------------
3618 bool wxPropertyGrid::UnfocusEditor()
3620 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3623 if ( !CommitChangesFromEditor(0) )
3627 DrawItem(m_selected
);
3632 // -----------------------------------------------------------------------
3634 void wxPropertyGrid::RefreshEditor()
3636 wxPGProperty
* p
= m_selected
;
3640 wxWindow
* wnd
= GetEditorControl();
3644 // Set editor font boldness - must do this before
3645 // calling UpdateControl().
3646 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3648 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3649 wnd
->SetFont(GetCaptionFont());
3651 wnd
->SetFont(GetFont());
3654 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3656 editorClass
->UpdateControl(p
, wnd
);
3658 if ( p
->IsValueUnspecified() )
3659 editorClass
->SetValueToUnspecified(p
, wnd
);
3662 // -----------------------------------------------------------------------
3664 // This method is not inline because it called dozens of times
3665 // (i.e. two-arg function calls create smaller code size).
3666 bool wxPropertyGrid::DoClearSelection()
3668 return DoSelectProperty(NULL
);
3671 // -----------------------------------------------------------------------
3672 // wxPropertyGrid expand/collapse state
3673 // -----------------------------------------------------------------------
3675 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3677 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3679 // If active editor was inside collapsed section, then disable it
3680 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3682 ClearSelection(false);
3685 // Store dont-center-splitter flag 'cause we need to temporarily set it
3686 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3687 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3689 bool res
= m_pState
->DoCollapse(pwc
);
3694 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3696 RecalculateVirtualSize();
3698 // Redraw etc. only if collapsed was visible.
3699 if (pwc
->IsVisible() &&
3701 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3703 // When item is collapsed so that scrollbar would move,
3704 // graphics mess is about (unless we redraw everything).
3709 // Clear dont-center-splitter flag if it wasn't set
3710 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3715 // -----------------------------------------------------------------------
3717 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3719 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3721 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3723 // Store dont-center-splitter flag 'cause we need to temporarily set it
3724 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3725 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3727 bool res
= m_pState
->DoExpand(pwc
);
3732 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3734 RecalculateVirtualSize();
3736 // Redraw etc. only if expanded was visible.
3737 if ( pwc
->IsVisible() && !m_frozen
&&
3738 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3742 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3745 DrawItems(pwc
, NULL
);
3750 // Clear dont-center-splitter flag if it wasn't set
3751 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3756 // -----------------------------------------------------------------------
3758 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3761 return m_pState
->DoHideProperty(p
, hide
, flags
);
3764 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3767 ClearSelection(false);
3770 m_pState
->DoHideProperty(p
, hide
, flags
);
3772 RecalculateVirtualSize();
3779 // -----------------------------------------------------------------------
3780 // wxPropertyGrid size related methods
3781 // -----------------------------------------------------------------------
3783 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3785 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3789 // If virtual height was changed, then recalculate editor control position(s)
3790 if ( m_pState
->m_vhCalcPending
)
3791 CorrectEditorWidgetPosY();
3793 m_pState
->EnsureVirtualHeight();
3795 wxASSERT_LEVEL_2_MSG(
3796 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
3797 "VirtualHeight and ActualVirtualHeight should match"
3800 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3802 int x
= m_pState
->m_width
;
3803 int y
= m_pState
->m_virtualHeight
;
3806 GetClientSize(&width
,&height
);
3808 // Now adjust virtual size.
3809 SetVirtualSize(x
, y
);
3815 // Adjust scrollbars
3816 if ( HasVirtualWidth() )
3818 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3819 xPos
= GetScrollPos( wxHORIZONTAL
);
3822 if ( forceXPos
!= -1 )
3825 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3828 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3829 int yPos
= GetScrollPos( wxVERTICAL
);
3831 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3832 xAmount
, yAmount
, xPos
, yPos
, true );
3834 // Must re-get size now
3835 GetClientSize(&width
,&height
);
3837 if ( !HasVirtualWidth() )
3839 m_pState
->SetVirtualWidth(width
);
3846 m_canvas
->SetSize( x
, y
);
3848 m_pState
->CheckColumnWidths();
3851 CorrectEditorWidgetSizeX();
3853 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3856 // -----------------------------------------------------------------------
3858 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3860 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3864 GetClientSize(&width
,&height
);
3869 #if wxPG_DOUBLE_BUFFER
3870 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3872 int dblh
= (m_lineHeight
*2);
3873 if ( !m_doubleBuffer
)
3875 // Create double buffer bitmap to draw on, if none
3876 int w
= (width
>250)?width
:250;
3877 int h
= height
+ dblh
;
3879 m_doubleBuffer
= new wxBitmap( w
, h
);
3883 int w
= m_doubleBuffer
->GetWidth();
3884 int h
= m_doubleBuffer
->GetHeight();
3886 // Double buffer must be large enough
3887 if ( w
< width
|| h
< (height
+dblh
) )
3889 if ( w
< width
) w
= width
;
3890 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3891 delete m_doubleBuffer
;
3892 m_doubleBuffer
= new wxBitmap( w
, h
);
3899 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3900 m_ncWidth
= event
.GetSize().x
;
3904 if ( m_pState
->m_itemsAdded
)
3905 PrepareAfterItemsAdded();
3907 // Without this, virtual size (atleast under wxGTK) will be skewed
3908 RecalculateVirtualSize();
3914 // -----------------------------------------------------------------------
3916 void wxPropertyGrid::SetVirtualWidth( int width
)
3920 // Disable virtual width
3921 width
= GetClientSize().x
;
3922 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3926 // Enable virtual width
3927 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3929 m_pState
->SetVirtualWidth( width
);
3932 void wxPropertyGrid::SetFocusOnCanvas()
3934 m_canvas
->SetFocusIgnoringChildren();
3935 m_editorFocused
= 0;
3938 // -----------------------------------------------------------------------
3939 // wxPropertyGrid mouse event handling
3940 // -----------------------------------------------------------------------
3942 // selFlags uses same values DoSelectProperty's flags
3943 // Returns true if event was vetoed.
3944 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3946 // Send property grid event of specific type and with specific property
3947 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3948 evt
.SetPropertyGrid(this);
3949 evt
.SetEventObject(m_eventObject
);
3953 evt
.SetCanVeto(true);
3954 evt
.SetupValidationInfo();
3955 m_validationInfo
.m_pValue
= pValue
;
3957 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3959 evtHandler
->ProcessEvent(evt
);
3961 return evt
.WasVetoed();
3964 // -----------------------------------------------------------------------
3966 // Return false if should be skipped
3967 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3971 // Need to set focus?
3972 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3977 wxPropertyGridPageState
* state
= m_pState
;
3979 int splitterHitOffset
;
3980 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3982 wxPGProperty
* p
= DoGetItemAtY(y
);
3986 int depth
= (int)p
->GetDepth() - 1;
3988 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3990 if ( x
>= marginEnds
)
3994 if ( p
->IsCategory() )
3996 // This is category.
3997 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3999 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4001 // Expand, collapse, activate etc. if click on text or left of splitter.
4004 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4009 if ( !DoSelectProperty( p
) )
4012 // On double-click, expand/collapse.
4013 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4015 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4016 else DoExpand( p
, true );
4020 else if ( splitterHit
== -1 )
4023 unsigned int selFlag
= 0;
4024 if ( columnHit
== 1 )
4026 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4027 selFlag
= wxPG_SEL_FOCUS
;
4029 if ( !DoSelectProperty( p
, selFlag
) )
4032 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4034 if ( p
->GetChildCount() && !p
->IsCategory() )
4035 // On double-click, expand/collapse.
4036 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4038 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4039 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4040 else DoExpand( p
, true );
4047 // click on splitter
4048 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4050 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4052 // Double-clicking the splitter causes auto-centering
4053 CenterSplitter( true );
4055 else if ( m_dragStatus
== 0 )
4058 // Begin draggin the splitter
4062 // Changes must be committed here or the
4063 // value won't be drawn correctly
4064 if ( !CommitChangesFromEditor() )
4067 m_wndEditor
->Show ( false );
4070 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4072 m_canvas
->CaptureMouse();
4073 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4077 m_draggedSplitter
= splitterHit
;
4078 m_dragOffset
= splitterHitOffset
;
4080 wxClientDC
dc(m_canvas
);
4082 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4083 // Fixes button disappearance bug
4085 m_wndEditor2
->Show ( false );
4088 m_startingSplitterX
= x
- splitterHitOffset
;
4096 if ( p
->GetChildCount() )
4098 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4100 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4102 int y2
= y
% m_lineHeight
;
4103 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4105 // On click on expander button, expand/collapse
4106 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4107 DoCollapse( p
, true );
4109 DoExpand( p
, true );
4118 // -----------------------------------------------------------------------
4120 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4121 wxMouseEvent
& WXUNUSED(event
) )
4125 // Select property here as well
4126 wxPGProperty
* p
= m_propHover
;
4127 if ( p
!= m_selected
)
4128 DoSelectProperty( p
);
4130 // Send right click event.
4131 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4138 // -----------------------------------------------------------------------
4140 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4141 wxMouseEvent
& WXUNUSED(event
) )
4145 // Select property here as well
4146 wxPGProperty
* p
= m_propHover
;
4148 if ( p
!= m_selected
)
4149 DoSelectProperty( p
);
4151 // Send double-click event.
4152 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4159 // -----------------------------------------------------------------------
4161 #if wxPG_SUPPORT_TOOLTIPS
4163 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4165 if ( tipString
.length() )
4167 m_canvas
->SetToolTip(tipString
);
4171 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4172 m_canvas
->SetToolTip( m_emptyString
);
4174 m_canvas
->SetToolTip( NULL
);
4179 #endif // #if wxPG_SUPPORT_TOOLTIPS
4181 // -----------------------------------------------------------------------
4183 // Return false if should be skipped
4184 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4186 // Safety check (needed because mouse capturing may
4187 // otherwise freeze the control)
4188 if ( m_dragStatus
> 0 && !event
.Dragging() )
4190 HandleMouseUp(x
,y
,event
);
4193 wxPropertyGridPageState
* state
= m_pState
;
4195 int splitterHitOffset
;
4196 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4197 int splitterX
= x
- splitterHitOffset
;
4199 if ( m_dragStatus
> 0 )
4201 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4202 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4205 int newSplitterX
= x
- m_dragOffset
;
4206 int splitterX
= x
- splitterHitOffset
;
4208 // Splitter redraw required?
4209 if ( newSplitterX
!= splitterX
)
4212 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4213 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4214 state
->m_fSplitterX
= (float) newSplitterX
;
4217 CorrectEditorWidgetSizeX();
4231 int ih
= m_lineHeight
;
4234 #if wxPG_SUPPORT_TOOLTIPS
4235 wxPGProperty
* prevHover
= m_propHover
;
4236 unsigned char prevSide
= m_mouseSide
;
4238 int curPropHoverY
= y
- (y
% ih
);
4240 // On which item it hovers
4243 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4246 // Mouse moves on another property
4248 m_propHover
= DoGetItemAtY(y
);
4249 m_propHoverY
= curPropHoverY
;
4252 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4255 #if wxPG_SUPPORT_TOOLTIPS
4256 // Store which side we are on
4258 if ( columnHit
== 1 )
4260 else if ( columnHit
== 0 )
4264 // If tooltips are enabled, show label or value as a tip
4265 // in case it doesn't otherwise show in full length.
4267 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4269 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4271 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4273 if ( m_propHover
&& !m_propHover
->IsCategory() )
4276 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4278 // Show help string as a tooltip
4279 wxString tipString
= m_propHover
->GetHelpString();
4281 SetToolTip(tipString
);
4285 // Show cropped value string as a tooltip
4289 if ( m_mouseSide
== 1 )
4291 tipString
= m_propHover
->m_label
;
4292 space
= splitterX
-m_marginWidth
-3;
4294 else if ( m_mouseSide
== 2 )
4296 tipString
= m_propHover
->GetDisplayedString();
4298 space
= m_width
- splitterX
;
4299 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4300 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4306 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4309 SetToolTip( tipString
);
4316 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4317 m_canvas
->SetToolTip( m_emptyString
);
4319 m_canvas
->SetToolTip( NULL
);
4330 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4331 m_canvas
->SetToolTip( m_emptyString
);
4333 m_canvas
->SetToolTip( NULL
);
4341 if ( splitterHit
== -1 ||
4343 HasFlag(wxPG_STATIC_SPLITTER
) )
4345 // hovering on something else
4346 if ( m_curcursor
!= wxCURSOR_ARROW
)
4347 CustomSetCursor( wxCURSOR_ARROW
);
4351 // Do not allow splitter cursor on caption items.
4352 // (also not if we were dragging and its started
4353 // outside the splitter region)
4355 if ( !m_propHover
->IsCategory() &&
4359 // hovering on splitter
4361 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4362 // reliably detected.
4363 //if ( m_curcursor != wxCURSOR_SIZEWE )
4364 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4370 // hovering on something else
4371 if ( m_curcursor
!= wxCURSOR_ARROW
)
4372 CustomSetCursor( wxCURSOR_ARROW
);
4379 // -----------------------------------------------------------------------
4381 // Also handles Leaving event
4382 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4383 wxMouseEvent
&WXUNUSED(event
) )
4385 wxPropertyGridPageState
* state
= m_pState
;
4389 int splitterHitOffset
;
4390 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4392 // No event type check - basicly calling this method should
4393 // just stop dragging.
4394 // Left up after dragged?
4395 if ( m_dragStatus
>= 1 )
4398 // End Splitter Dragging
4400 // DO NOT ENABLE FOLLOWING LINE!
4401 // (it is only here as a reminder to not to do it)
4404 // Disable splitter auto-centering
4405 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4407 // This is necessary to return cursor
4408 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4410 m_canvas
->ReleaseMouse();
4411 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4414 // Set back the default cursor, if necessary
4415 if ( splitterHit
== -1 ||
4418 CustomSetCursor( wxCURSOR_ARROW
);
4423 // Control background needs to be cleared
4424 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4425 DrawItem( m_selected
);
4429 m_wndEditor
->Show ( true );
4432 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4433 // Fixes button disappearance bug
4435 m_wndEditor2
->Show ( true );
4438 // This clears the focus.
4439 m_editorFocused
= 0;
4445 // -----------------------------------------------------------------------
4447 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4449 int splitterX
= GetSplitterPosition();
4452 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4456 wxWindow
* wnd
= GetEditorControl();
4458 // Hide popup on clicks
4459 if ( event
.GetEventType() != wxEVT_MOTION
)
4460 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4462 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4468 if ( wnd
== NULL
|| m_dragStatus
||
4470 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4471 ux
>= (r
.x
+r
.width
) ||
4473 event
.m_y
>= (r
.y
+r
.height
)
4483 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4488 // -----------------------------------------------------------------------
4490 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4493 if ( OnMouseCommon( event
, &x
, &y
) )
4495 HandleMouseClick(x
,y
,event
);
4500 // -----------------------------------------------------------------------
4502 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4505 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4506 HandleMouseRightClick(x
,y
,event
);
4510 // -----------------------------------------------------------------------
4512 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4514 // Always run standard mouse-down handler as well
4515 OnMouseClick(event
);
4518 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4519 HandleMouseDoubleClick(x
,y
,event
);
4523 // -----------------------------------------------------------------------
4525 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4528 if ( OnMouseCommon( event
, &x
, &y
) )
4530 HandleMouseMove(x
,y
,event
);
4535 // -----------------------------------------------------------------------
4537 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4539 // Called when mouse moves in the empty space below the properties.
4540 CustomSetCursor( wxCURSOR_ARROW
);
4543 // -----------------------------------------------------------------------
4545 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4548 if ( OnMouseCommon( event
, &x
, &y
) )
4550 HandleMouseUp(x
,y
,event
);
4555 // -----------------------------------------------------------------------
4557 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4559 // This may get called from child control as well, so event's
4560 // mouse position cannot be relied on.
4562 if ( event
.Entering() )
4564 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4566 // TODO: Fix this (detect parent and only do
4567 // cursor trick if it is a manager).
4568 wxASSERT( GetParent() );
4569 GetParent()->SetCursor(wxNullCursor
);
4571 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4574 GetParent()->SetCursor(wxNullCursor
);
4576 else if ( event
.Leaving() )
4578 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4579 m_canvas
->SetCursor( wxNullCursor
);
4581 // Get real cursor position
4582 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4584 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4587 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4589 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4593 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4601 // -----------------------------------------------------------------------
4603 // Common code used by various OnMouseXXXChild methods.
4604 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4606 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4607 wxASSERT( topCtrlWnd
);
4609 event
.GetPosition(&x
,&y
);
4611 int splitterX
= GetSplitterPosition();
4613 wxRect r
= topCtrlWnd
->GetRect();
4614 if ( !m_dragStatus
&&
4615 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4616 y
>= 0 && y
< r
.height \
4619 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4624 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4631 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4634 if ( OnMouseChildCommon(event
,&x
,&y
) )
4636 bool res
= HandleMouseClick(x
,y
,event
);
4637 if ( !res
) event
.Skip();
4641 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4644 wxASSERT( m_wndEditor
);
4645 // These coords may not be exact (about +-2),
4646 // but that should not matter (right click is about item, not position).
4647 wxPoint pt
= m_wndEditor
->GetPosition();
4648 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4649 wxASSERT( m_selected
);
4650 m_propHover
= m_selected
;
4651 bool res
= HandleMouseRightClick(x
,y
,event
);
4652 if ( !res
) event
.Skip();
4655 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4658 if ( OnMouseChildCommon(event
,&x
,&y
) )
4660 bool res
= HandleMouseMove(x
,y
,event
);
4661 if ( !res
) event
.Skip();
4665 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4668 if ( OnMouseChildCommon(event
,&x
,&y
) )
4670 bool res
= HandleMouseUp(x
,y
,event
);
4671 if ( !res
) event
.Skip();
4675 // -----------------------------------------------------------------------
4676 // wxPropertyGrid keyboard event handling
4677 // -----------------------------------------------------------------------
4679 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4681 // Translates wxKeyEvent to wxPG_ACTION_XXX
4683 int keycode
= event
.GetKeyCode();
4684 int modifiers
= event
.GetModifiers();
4686 wxASSERT( !(modifiers
&~(0xFFFF)) );
4688 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4690 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4692 if ( it
== m_actionTriggers
.end() )
4697 int second
= (it
->second
>>16) & 0xFFFF;
4701 return (it
->second
& 0xFFFF);
4704 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4706 wxASSERT( !(modifiers
&~(0xFFFF)) );
4708 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4710 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4712 if ( it
!= m_actionTriggers
.end() )
4714 // This key combination is already used
4716 // Can add secondary?
4717 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4718 wxT("You can only add up to two separate actions per key combination.") );
4720 action
= it
->second
| (action
<<16);
4723 m_actionTriggers
[hashMapKey
] = action
;
4726 void wxPropertyGrid::ClearActionTriggers( int action
)
4728 wxPGHashMapI2I::iterator it
;
4730 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4732 if ( it
->second
== action
)
4734 m_actionTriggers
.erase(it
);
4739 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4742 // Handles key event when editor control is not focused.
4745 wxCHECK2(!m_frozen
, return);
4747 // Travelsal between items, collapsing/expanding, etc.
4748 int keycode
= event
.GetKeyCode();
4749 bool editorFocused
= IsEditorFocused();
4751 if ( keycode
== WXK_TAB
)
4753 wxWindow
* mainControl
;
4755 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4756 mainControl
= GetParent();
4760 if ( !event
.ShiftDown() )
4762 if ( !editorFocused
&& m_wndEditor
)
4764 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4768 // Tab traversal workaround for platforms on which
4769 // wxWindow::Navigate() may navigate into first child
4770 // instead of next sibling. Does not work perfectly
4771 // in every scenario (for instance, when property grid
4772 // is either first or last control).
4773 #if defined(__WXGTK__)
4774 wxWindow
* sibling
= mainControl
->GetNextSibling();
4776 sibling
->SetFocusFromKbd();
4778 Navigate(wxNavigationKeyEvent::IsForward
);
4784 if ( editorFocused
)
4790 #if defined(__WXGTK__)
4791 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4793 sibling
->SetFocusFromKbd();
4795 Navigate(wxNavigationKeyEvent::IsBackward
);
4803 // Ignore Alt and Control when they are down alone
4804 if ( keycode
== WXK_ALT
||
4805 keycode
== WXK_CONTROL
)
4812 int action
= KeyEventToActions(event
, &secondAction
);
4814 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4817 // Esc cancels any changes
4818 if ( IsEditorsValueModified() )
4820 EditorsValueWasNotModified();
4822 // Update the control as well
4823 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4825 m_selected
->GetDisplayedString() );
4828 OnValidationFailureReset(m_selected
);
4834 // Except for TAB and ESC, handle child control events in child control
4837 // Only propagate event if it had modifiers
4838 if ( !event
.HasModifiers() )
4840 event
.StopPropagation();
4846 bool wasHandled
= false;
4851 if ( ButtonTriggerKeyTest(action
, event
) )
4854 wxPGProperty
* p
= m_selected
;
4856 // Travel and expand/collapse
4859 if ( p
->GetChildCount() )
4861 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4863 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4866 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4868 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4875 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4879 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4885 if ( selectDir
>= -1 )
4887 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4889 DoSelectProperty(p
);
4895 // If nothing was selected, select the first item now
4896 // (or navigate out of tab).
4897 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4899 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4900 if ( p
) DoSelectProperty(p
);
4909 // -----------------------------------------------------------------------
4911 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4913 // If there was editor open and focused, then this event should not
4914 // really be processed here.
4915 if ( IsEditorFocused() )
4917 // However, if event had modifiers, it is probably still best
4919 if ( event
.HasModifiers() )
4922 event
.StopPropagation();
4926 HandleKeyEvent(event
, false);
4929 // -----------------------------------------------------------------------
4931 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4936 action
= KeyEventToActions(event
, &secondAction
);
4939 // Does the keycode trigger button?
4940 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4943 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4944 GetEventHandler()->AddPendingEvent(evt
);
4951 // -----------------------------------------------------------------------
4953 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4955 HandleKeyEvent(event
, true);
4958 // -----------------------------------------------------------------------
4959 // wxPropertyGrid miscellaneous event handling
4960 // -----------------------------------------------------------------------
4962 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4965 // Check if the focus is in this control or one of its children
4966 wxWindow
* newFocused
= wxWindow::FindFocus();
4968 if ( newFocused
!= m_curFocused
)
4969 HandleFocusChange( newFocused
);
4972 // Check if top-level parent has changed
4973 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
4980 bool wxPropertyGrid::IsEditorFocused() const
4982 wxWindow
* focus
= wxWindow::FindFocus();
4984 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4985 focus
== GetEditorControl() )
4991 // Called by focus event handlers. newFocused is the window that becomes focused.
4992 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4994 unsigned int oldFlags
= m_iFlags
;
4996 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4998 wxWindow
* parent
= newFocused
;
5000 // This must be one of nextFocus' parents.
5003 // Use m_eventObject, which is either wxPropertyGrid or
5004 // wxPropertyGridManager, as appropriate.
5005 if ( parent
== m_eventObject
)
5007 m_iFlags
|= wxPG_FL_FOCUSED
;
5010 parent
= parent
->GetParent();
5013 m_curFocused
= newFocused
;
5015 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5016 (oldFlags
& wxPG_FL_FOCUSED
) )
5018 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5020 // Need to store changed value
5021 CommitChangesFromEditor();
5027 // Preliminary code for tab-order respecting
5028 // tab-traversal (but should be moved to
5031 wxWindow* prevFocus = event.GetWindow();
5032 wxWindow* useThis = this;
5033 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5034 useThis = GetParent();
5037 prevFocus->GetParent() == useThis->GetParent() )
5039 wxList& children = useThis->GetParent()->GetChildren();
5041 wxNode* node = children.Find(prevFocus);
5043 if ( node->GetNext() &&
5044 useThis == node->GetNext()->GetData() )
5045 DoSelectProperty(GetFirst());
5046 else if ( node->GetPrevious () &&
5047 useThis == node->GetPrevious()->GetData() )
5048 DoSelectProperty(GetLastProperty());
5055 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5056 DrawItem( m_selected
);
5060 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5062 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5063 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5064 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5065 //else if ( event.GetWindow() )
5067 HandleFocusChange(event
.GetWindow());
5072 // -----------------------------------------------------------------------
5074 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5076 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5080 // -----------------------------------------------------------------------
5082 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5084 m_iFlags
|= wxPG_FL_SCROLLED
;
5089 // -----------------------------------------------------------------------
5091 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5093 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5095 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5099 // -----------------------------------------------------------------------
5100 // Property editor related functions
5101 // -----------------------------------------------------------------------
5103 // noDefCheck = true prevents infinite recursion.
5104 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5105 const wxString
& editorName
,
5108 wxASSERT( editorClass
);
5110 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5111 RegisterDefaultEditors();
5113 wxString name
= editorName
;
5114 if ( name
.length() == 0 )
5115 name
= editorClass
->GetName();
5117 // Existing editor under this name?
5118 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5120 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5122 // If this name was already used, try class name.
5123 name
= editorClass
->GetClassInfo()->GetClassName();
5124 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5127 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5128 (wxPGEditor
*) vt_it
->second
,
5129 "Editor with given name was already registered" );
5131 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5136 // Use this in RegisterDefaultEditors.
5137 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5138 if ( wxPGEditor_##EDITOR == NULL ) \
5140 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5141 new wxPG##EDITOR##Editor, true ); \
5144 // Registers all default editor classes
5145 void wxPropertyGrid::RegisterDefaultEditors()
5147 wxPGRegisterDefaultEditorClass( TextCtrl
);
5148 wxPGRegisterDefaultEditorClass( Choice
);
5149 wxPGRegisterDefaultEditorClass( ComboBox
);
5150 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5151 #if wxPG_INCLUDE_CHECKBOX
5152 wxPGRegisterDefaultEditorClass( CheckBox
);
5154 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5156 // Register SpinCtrl etc. editors before use
5157 RegisterAdditionalEditors();
5160 // -----------------------------------------------------------------------
5161 // wxPGStringTokenizer
5162 // Needed to handle C-style string lists (e.g. "str1" "str2")
5163 // -----------------------------------------------------------------------
5165 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5166 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5170 wxPGStringTokenizer::~wxPGStringTokenizer()
5174 bool wxPGStringTokenizer::HasMoreTokens()
5176 const wxString
& str
= *m_str
;
5178 wxString::const_iterator i
= m_curPos
;
5180 wxUniChar delim
= m_delimeter
;
5182 wxUniChar prev_a
= wxT('\0');
5184 bool inToken
= false;
5186 while ( i
!= str
.end() )
5195 m_readyToken
.clear();
5200 if ( prev_a
!= wxT('\\') )
5204 if ( a
!= wxT('\\') )
5224 m_curPos
= str
.end();
5232 wxString
wxPGStringTokenizer::GetNextToken()
5234 return m_readyToken
;
5237 // -----------------------------------------------------------------------
5239 // -----------------------------------------------------------------------
5241 wxPGChoiceEntry::wxPGChoiceEntry()
5242 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5246 // -----------------------------------------------------------------------
5248 // -----------------------------------------------------------------------
5250 wxPGChoicesData::wxPGChoicesData()
5254 wxPGChoicesData::~wxPGChoicesData()
5259 void wxPGChoicesData::Clear()
5264 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5266 wxASSERT( m_items
.size() == 0 );
5268 m_items
= data
->m_items
;
5271 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5272 const wxPGChoiceEntry
& item
)
5274 wxVector
<wxPGChoiceEntry
>::iterator it
;
5278 index
= (int) m_items
.size();
5282 it
= m_items
.begin() + index
;
5285 m_items
.insert(it
, item
);
5287 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5289 // Need to fix value?
5290 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5291 ownEntry
.SetValue(index
);
5296 // -----------------------------------------------------------------------
5297 // wxPropertyGridEvent
5298 // -----------------------------------------------------------------------
5300 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5303 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5304 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5305 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5306 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5307 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5308 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5309 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5310 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5311 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5314 // -----------------------------------------------------------------------
5316 void wxPropertyGridEvent::Init()
5318 m_validationInfo
= NULL
;
5320 m_wasVetoed
= false;
5323 // -----------------------------------------------------------------------
5325 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5326 : wxCommandEvent(commandType
,id
)
5332 // -----------------------------------------------------------------------
5334 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5335 : wxCommandEvent(event
)
5337 m_eventType
= event
.GetEventType();
5338 m_eventObject
= event
.m_eventObject
;
5340 m_property
= event
.m_property
;
5341 m_validationInfo
= event
.m_validationInfo
;
5342 m_canVeto
= event
.m_canVeto
;
5343 m_wasVetoed
= event
.m_wasVetoed
;
5346 // -----------------------------------------------------------------------
5348 wxPropertyGridEvent::~wxPropertyGridEvent()
5352 // -----------------------------------------------------------------------
5354 wxEvent
* wxPropertyGridEvent::Clone() const
5356 return new wxPropertyGridEvent( *this );
5359 // -----------------------------------------------------------------------
5360 // wxPropertyGridPopulator
5361 // -----------------------------------------------------------------------
5363 wxPropertyGridPopulator::wxPropertyGridPopulator()
5367 wxPGGlobalVars
->m_offline
++;
5370 // -----------------------------------------------------------------------
5372 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5375 m_propHierarchy
.clear();
5378 // -----------------------------------------------------------------------
5380 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5386 // -----------------------------------------------------------------------
5388 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5391 // Free unused sets of choices
5392 wxPGHashMapS2P::iterator it
;
5394 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5396 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5403 m_pg
->GetPanel()->Refresh();
5405 wxPGGlobalVars
->m_offline
--;
5408 // -----------------------------------------------------------------------
5410 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5411 const wxString
& propLabel
,
5412 const wxString
& propName
,
5413 const wxString
* propValue
,
5414 wxPGChoices
* pChoices
)
5416 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5417 wxPGProperty
* parent
= GetCurParent();
5419 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5421 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5425 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5427 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5431 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5433 property
->SetLabel(propLabel
);
5434 property
->DoSetName(propName
);
5436 if ( pChoices
&& pChoices
->IsOk() )
5437 property
->SetChoices(*pChoices
);
5439 m_state
->DoInsert(parent
, -1, property
);
5442 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5443 wxPG_PROGRAMMATIC_VALUE
);
5448 // -----------------------------------------------------------------------
5450 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5452 m_propHierarchy
.push_back(property
);
5453 DoScanForChildren();
5454 m_propHierarchy
.pop_back();
5457 // -----------------------------------------------------------------------
5459 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5460 const wxString
& idString
)
5462 wxPGChoices choices
;
5465 if ( choicesString
[0] == wxT('@') )
5467 wxString ids
= choicesString
.substr(1);
5468 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5469 if ( it
== m_dictIdChoices
.end() )
5470 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5472 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5477 if ( idString
.length() )
5479 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5480 if ( it
!= m_dictIdChoices
.end() )
5482 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5489 // Parse choices string
5490 wxString::const_iterator it
= choicesString
.begin();
5494 bool labelValid
= false;
5496 for ( ; it
!= choicesString
.end(); ++it
)
5502 if ( c
== wxT('"') )
5507 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5508 choices
.Add(label
, l
);
5511 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5516 else if ( c
== wxT('=') )
5523 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5530 if ( c
== wxT('"') )
5543 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5544 choices
.Add(label
, l
);
5547 if ( !choices
.IsOk() )
5549 choices
.EnsureData();
5553 if ( idString
.length() )
5554 m_dictIdChoices
[idString
] = choices
.GetData();
5561 // -----------------------------------------------------------------------
5563 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5565 if ( s
.Last() == wxT('%') )
5567 wxString s2
= s
.substr(0,s
.length()-1);
5569 if ( s2
.ToLong(&val
, 10) )
5571 *pval
= (val
*max
)/100;
5577 return s
.ToLong(pval
, 10);
5580 // -----------------------------------------------------------------------
5582 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5583 const wxString
& type
,
5584 const wxString
& value
)
5586 int l
= m_propHierarchy
.size();
5590 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5591 wxString valuel
= value
.Lower();
5594 if ( type
.length() == 0 )
5599 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5601 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5603 else if ( value
.ToLong(&v
, 0) )
5610 if ( type
== wxT("string") )
5614 else if ( type
== wxT("int") )
5617 value
.ToLong(&v
, 0);
5620 else if ( type
== wxT("bool") )
5622 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5629 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5634 p
->SetAttribute( name
, variant
);
5639 // -----------------------------------------------------------------------
5641 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5643 wxLogError(_("Error in resource: %s"),msg
.c_str());
5646 // -----------------------------------------------------------------------
5648 #endif // wxUSE_PROPGRID