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 // set virtual size to this window size
557 wxSize wndsize
= GetSize();
558 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
560 m_timeCreated
= ::wxGetLocalTimeMillis();
562 m_canvas
= new wxPGCanvas();
563 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
564 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
565 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
567 m_iFlags
|= wxPG_FL_INITIALIZED
;
569 m_ncWidth
= wndsize
.GetWidth();
571 // Need to call OnResize handler or size given in constructor/Create
573 wxSizeEvent
sizeEvent(wndsize
,0);
577 // -----------------------------------------------------------------------
579 wxPropertyGrid::~wxPropertyGrid()
583 DoSelectProperty(NULL
);
585 // This should do prevent things from going too badly wrong
586 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
588 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
589 m_canvas
->ReleaseMouse();
591 // Do TLP check, recommend use of OnTLPChanging()
592 wxWindow
* tlp
= ::wxGetTopLevelParent(this);
595 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
596 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
601 wxLogError("Top-level parent of wxPropertyGrid has changed. "
602 "Consider calling wxPropertyGrid::OnTLPChanging() "
603 "when appropriate.");
606 wxASSERT_MSG( !IsEditorsValueModified(),
607 wxS("Most recent change in property editor was lost!!! ")
608 wxS("(if you don't want this to happen, close your frames ")
609 wxS("and dialogs using Close(false).)") );
611 #if wxPG_DOUBLE_BUFFER
612 if ( m_doubleBuffer
)
613 delete m_doubleBuffer
;
618 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
621 delete m_cursorSizeWE
;
623 #ifndef wxPG_ICON_WIDTH
628 // Delete common value records
629 for ( i
=0; i
<m_commonValues
.size(); i
++ )
631 delete GetCommonValue(i
);
635 // -----------------------------------------------------------------------
637 bool wxPropertyGrid::Destroy()
639 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
640 m_canvas
->ReleaseMouse();
642 return wxScrolledWindow::Destroy();
645 // -----------------------------------------------------------------------
647 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
649 return new wxPropertyGridPageState();
652 // -----------------------------------------------------------------------
653 // wxPropertyGrid overridden wxWindow methods
654 // -----------------------------------------------------------------------
656 void wxPropertyGrid::SetWindowStyleFlag( long style
)
658 long old_style
= m_windowStyle
;
660 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
662 wxASSERT( m_pState
);
664 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
667 EnableCategories( true );
669 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
671 // Disable categories
672 EnableCategories( false );
674 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
680 PrepareAfterItemsAdded();
682 m_pState
->m_itemsAdded
= 1;
684 #if wxPG_SUPPORT_TOOLTIPS
685 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
691 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
692 SetToolTip ( tooltip );
693 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
696 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
701 m_canvas
->SetToolTip( NULL
);
706 wxScrolledWindow::SetWindowStyleFlag ( style
);
708 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
710 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
712 CalculateFontAndBitmapStuff( m_vspacing
);
718 // -----------------------------------------------------------------------
720 void wxPropertyGrid::Freeze()
724 wxScrolledWindow::Freeze();
729 // -----------------------------------------------------------------------
731 void wxPropertyGrid::Thaw()
737 wxScrolledWindow::Thaw();
738 RecalculateVirtualSize();
739 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
743 // Force property re-selection
745 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
749 // -----------------------------------------------------------------------
751 void wxPropertyGrid::SetExtraStyle( long exStyle
)
753 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
755 #if defined(__WXMSW__)
758 // Don't use WS_EX_COMPOSITED just now.
761 if ( m_iFlags & wxPG_FL_IN_MANAGER )
762 hWnd = (HWND)GetParent()->GetHWND();
764 hWnd = (HWND)GetHWND();
766 ::SetWindowLong( hWnd, GWL_EXSTYLE,
767 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
770 //#elif defined(__WXGTK20__)
772 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
773 // truly was double-buffered.
774 if ( !this->IsDoubleBuffered() )
776 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
780 #if wxPG_DOUBLE_BUFFER
781 delete m_doubleBuffer
;
782 m_doubleBuffer
= NULL
;
787 wxScrolledWindow::SetExtraStyle( exStyle
);
789 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
790 m_pState
->InitNonCatMode();
792 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
793 m_windowStyle
|= wxPG_TOOLTIPS
;
796 wxPGGlobalVars
->m_extraStyle
= exStyle
;
799 // -----------------------------------------------------------------------
801 // returns the best acceptable minimal size
802 wxSize
wxPropertyGrid::DoGetBestSize() const
804 int lineHeight
= wxMax(15, m_lineHeight
);
806 // don't make the grid too tall (limit height to 10 items) but don't
807 // make it too small neither
810 wxMax(m_pState
->m_properties
->GetChildCount(), 3),
814 const wxSize sz
= wxSize(60, lineHeight
*numLines
+ 40);
819 // -----------------------------------------------------------------------
821 void wxPropertyGrid::OnTLPChanging( wxWindow
* newTLP
)
824 // Parent changed so let's redetermine and re-hook the
825 // correct top-level window.
828 wxASSERT_MSG( m_tlp
== ::wxGetTopLevelParent(this),
829 "You must call OnTLPChanging() before the "
830 "top-level parent has changed.");
832 m_tlp
->Disconnect( wxEVT_CLOSE_WINDOW
,
833 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
838 newTLP
= ::wxGetTopLevelParent(this);
841 m_tlp
->Connect( wxEVT_CLOSE_WINDOW
,
842 wxCloseEventHandler(wxPropertyGrid::OnTLPClose
),
846 // -----------------------------------------------------------------------
848 void wxPropertyGrid::OnTLPClose( wxCloseEvent
& event
)
850 // ClearSelection forces value validation/commit.
851 if ( event
.CanVeto() && !ClearSelection() )
860 // -----------------------------------------------------------------------
862 bool wxPropertyGrid::Reparent( wxWindowBase
*newParent
)
864 OnTLPChanging((wxWindow
*)newParent
);
866 bool res
= wxScrolledWindow::Reparent(newParent
);
871 // -----------------------------------------------------------------------
872 // wxPropertyGrid Font and Colour Methods
873 // -----------------------------------------------------------------------
875 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
879 m_captionFont
= wxScrolledWindow::GetFont();
881 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
882 m_subgroup_extramargin
= x
+ (x
/2);
885 #if wxPG_USE_RENDERER_NATIVE
886 m_iconWidth
= wxPG_ICON_WIDTH
;
887 #elif wxPG_ICON_WIDTH
889 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
890 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
891 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
895 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
896 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
897 m_gutterWidth
= wxPG_GUTTER_MIN
;
900 if ( vspacing
<= 1 ) vdiv
= 12;
901 else if ( vspacing
>= 3 ) vdiv
= 3;
903 m_spacingy
= m_fontHeight
/ vdiv
;
904 if ( m_spacingy
< wxPG_YSPACING_MIN
)
905 m_spacingy
= wxPG_YSPACING_MIN
;
908 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
909 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
911 m_captionFont
.SetWeight(wxBOLD
);
912 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
914 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
917 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
918 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
921 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
923 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
924 RecalculateVirtualSize();
926 InvalidateBestSize();
929 // -----------------------------------------------------------------------
931 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
937 // -----------------------------------------------------------------------
939 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
940 int ga
= 1000, int ba
= 1000,
941 bool forceDifferent
= false)
948 // Recursion guard (allow 2 max)
949 static int isinside
= 0;
951 wxCHECK_MSG( isinside
< 3,
953 wxT("wxPGAdjustColour should not be recursively called more than once") );
961 if ( r2
>255 ) r2
= 255;
962 else if ( r2
<0) r2
= 0;
964 if ( g2
>255 ) g2
= 255;
965 else if ( g2
<0) g2
= 0;
967 if ( b2
>255 ) b2
= 255;
968 else if ( b2
<0) b2
= 0;
970 // Make sure they are somewhat different
971 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
972 dst
= wxPGAdjustColour(src
,-(ra
*2));
974 dst
= wxColour(r2
,g2
,b2
);
976 // Recursion guard (allow 2 max)
983 static int wxPGGetColAvg( const wxColour
& col
)
985 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
989 void wxPropertyGrid::RegainColours()
991 if ( !(m_coloursCustomized
& 0x0002) )
993 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
995 // Make sure colour is dark enough
997 int colDec
= wxPGGetColAvg(col
) - 230;
999 int colDec
= wxPGGetColAvg(col
) - 200;
1002 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
1005 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
1008 if ( !(m_coloursCustomized
& 0x0001) )
1009 m_colMargin
= m_colCapBack
;
1011 if ( !(m_coloursCustomized
& 0x0004) )
1018 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
1019 m_colCapFore
= capForeCol
;
1020 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1023 if ( !(m_coloursCustomized
& 0x0008) )
1025 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1026 m_colPropBack
= bgCol
;
1027 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1030 if ( !(m_coloursCustomized
& 0x0010) )
1032 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1033 m_colPropFore
= fgCol
;
1034 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1037 if ( !(m_coloursCustomized
& 0x0020) )
1038 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1040 if ( !(m_coloursCustomized
& 0x0040) )
1041 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1043 if ( !(m_coloursCustomized
& 0x0080) )
1044 m_colLine
= m_colCapBack
;
1046 if ( !(m_coloursCustomized
& 0x0100) )
1047 m_colDisPropFore
= m_colCapFore
;
1049 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1052 // -----------------------------------------------------------------------
1054 void wxPropertyGrid::ResetColours()
1056 m_coloursCustomized
= 0;
1063 // -----------------------------------------------------------------------
1065 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1067 // Must disable active editor.
1068 ClearSelection(false);
1070 bool res
= wxScrolledWindow::SetFont( font
);
1071 if ( res
&& GetParent()) // may not have been Create()ed yet
1073 CalculateFontAndBitmapStuff( m_vspacing
);
1080 // -----------------------------------------------------------------------
1082 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1085 m_coloursCustomized
|= 0x80;
1089 // -----------------------------------------------------------------------
1091 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1094 m_coloursCustomized
|= 0x01;
1098 // -----------------------------------------------------------------------
1100 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1102 m_colPropBack
= col
;
1103 m_coloursCustomized
|= 0x08;
1105 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1110 // -----------------------------------------------------------------------
1112 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1114 m_colPropFore
= col
;
1115 m_coloursCustomized
|= 0x10;
1117 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1122 // -----------------------------------------------------------------------
1124 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1126 m_colEmptySpace
= col
;
1131 // -----------------------------------------------------------------------
1133 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1135 m_colDisPropFore
= col
;
1136 m_coloursCustomized
|= 0x100;
1140 // -----------------------------------------------------------------------
1142 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1145 m_coloursCustomized
|= 0x20;
1149 // -----------------------------------------------------------------------
1151 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1154 m_coloursCustomized
|= 0x40;
1158 // -----------------------------------------------------------------------
1160 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1163 m_coloursCustomized
|= 0x02;
1165 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1170 // -----------------------------------------------------------------------
1172 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1175 m_coloursCustomized
|= 0x04;
1177 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1182 // -----------------------------------------------------------------------
1183 // wxPropertyGrid property adding and removal
1184 // -----------------------------------------------------------------------
1186 void wxPropertyGrid::PrepareAfterItemsAdded()
1188 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1190 m_pState
->m_itemsAdded
= 0;
1192 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1193 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1195 RecalculateVirtualSize();
1198 // -----------------------------------------------------------------------
1199 // wxPropertyGrid property operations
1200 // -----------------------------------------------------------------------
1202 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1204 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1208 bool changed
= false;
1210 // Is it inside collapsed section?
1211 if ( !p
->IsVisible() )
1214 wxPGProperty
* parent
= p
->GetParent();
1215 wxPGProperty
* grandparent
= parent
->GetParent();
1217 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1218 Expand( grandparent
);
1226 GetViewStart(&vx
,&vy
);
1227 vy
*=wxPG_PIXELS_PER_UNIT
;
1233 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1234 m_iFlags
|= wxPG_FL_SCROLLED
;
1237 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1239 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1240 m_iFlags
|= wxPG_FL_SCROLLED
;
1250 // -----------------------------------------------------------------------
1251 // wxPropertyGrid helper methods called by properties
1252 // -----------------------------------------------------------------------
1254 // Control font changer helper.
1255 void wxPropertyGrid::SetCurControlBoldFont()
1257 wxASSERT( m_wndEditor
);
1258 m_wndEditor
->SetFont( m_captionFont
);
1261 // -----------------------------------------------------------------------
1263 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1266 #if wxPG_SMALL_SCREEN
1267 // On small-screen devices, always show dialogs with default position and size.
1268 return wxDefaultPosition
;
1270 int splitterX
= GetSplitterPosition();
1274 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1276 ImprovedClientToScreen( &x
, &y
);
1278 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1279 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1286 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1296 new_y
= y
+ m_lineHeight
;
1298 return wxPoint(new_x
,new_y
);
1302 // -----------------------------------------------------------------------
1304 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1306 if ( src_str
.length() == 0 )
1312 bool prev_is_slash
= false;
1314 wxString::const_iterator i
= src_str
.begin();
1318 for ( ; i
!= src_str
.end(); ++i
)
1322 if ( a
!= wxS('\\') )
1324 if ( !prev_is_slash
)
1330 if ( a
== wxS('n') )
1333 dst_str
<< wxS('\n');
1335 dst_str
<< wxS('\n');
1338 else if ( a
== wxS('t') )
1339 dst_str
<< wxS('\t');
1343 prev_is_slash
= false;
1347 if ( prev_is_slash
)
1349 dst_str
<< wxS('\\');
1350 prev_is_slash
= false;
1354 prev_is_slash
= true;
1361 // -----------------------------------------------------------------------
1363 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1365 if ( src_str
.length() == 0 )
1371 wxString::const_iterator i
= src_str
.begin();
1372 wxUniChar prev_a
= wxS('\0');
1376 for ( ; i
!= src_str
.end(); ++i
)
1380 if ( a
>= wxS(' ') )
1382 // This surely is not something that requires an escape sequence.
1387 // This might need...
1388 if ( a
== wxS('\r') )
1390 // DOS style line end.
1391 // Already taken care below
1393 else if ( a
== wxS('\n') )
1394 // UNIX style line end.
1395 dst_str
<< wxS("\\n");
1396 else if ( a
== wxS('\t') )
1398 dst_str
<< wxS('\t');
1401 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1411 // -----------------------------------------------------------------------
1413 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1420 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1423 // -----------------------------------------------------------------------
1424 // wxPropertyGrid graphics related methods
1425 // -----------------------------------------------------------------------
1427 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1431 // Update everything inside the box
1432 wxRect r
= GetUpdateRegion().GetBox();
1434 dc
.SetPen(m_colEmptySpace
);
1435 dc
.SetBrush(m_colEmptySpace
);
1436 dc
.DrawRectangle(r
);
1439 // -----------------------------------------------------------------------
1441 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1442 wxPGProperty
* property
) const
1444 // Prepare rectangle to be used
1446 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1447 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1449 #if (wxPG_USE_RENDERER_NATIVE)
1451 #elif wxPG_ICON_WIDTH
1452 // Drawing expand/collapse button manually
1453 dc
.SetPen(m_colPropFore
);
1454 if ( property
->IsCategory() )
1455 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1457 dc
.SetBrush(m_colPropBack
);
1459 dc
.DrawRectangle( r
);
1460 int _y
= r
.y
+(m_iconWidth
/2);
1461 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1466 if ( property
->IsExpanded() )
1468 // wxRenderer functions are non-mutating in nature, so it
1469 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1470 // Hopefully this does not cause problems.
1471 #if (wxPG_USE_RENDERER_NATIVE)
1472 wxRendererNative::Get().DrawTreeItemButton(
1478 #elif wxPG_ICON_WIDTH
1487 #if (wxPG_USE_RENDERER_NATIVE)
1488 wxRendererNative::Get().DrawTreeItemButton(
1494 #elif wxPG_ICON_WIDTH
1495 int _x
= r
.x
+(m_iconWidth
/2);
1496 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1502 #if (wxPG_USE_RENDERER_NATIVE)
1504 #elif wxPG_ICON_WIDTH
1507 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1511 // -----------------------------------------------------------------------
1514 // This is the one called by OnPaint event handler and others.
1515 // topy and bottomy are already unscrolled (ie. physical)
1517 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1519 unsigned int bottomy
,
1520 const wxRect
* clipRect
)
1522 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1524 m_pState
->EnsureVirtualHeight();
1526 wxRect tempClipRect
;
1529 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1530 clipRect
= &tempClipRect
;
1533 // items added check
1534 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1536 int paintFinishY
= 0;
1538 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1541 bool isBuffered
= false;
1543 #if wxPG_DOUBLE_BUFFER
1544 wxMemoryDC
* bufferDC
= NULL
;
1546 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1548 if ( !m_doubleBuffer
)
1550 paintFinishY
= clipRect
->y
;
1555 bufferDC
= new wxMemoryDC();
1557 // If nothing was changed, then just copy from double-buffer
1558 bufferDC
->SelectObject( *m_doubleBuffer
);
1568 dc
.SetClippingRegion( *clipRect
);
1569 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1572 #if wxPG_DOUBLE_BUFFER
1575 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1576 bufferDC
, 0, 0, wxCOPY
);
1577 dc
.DestroyClippingRegion(); // Is this really necessary?
1583 // Clear area beyond bottomY?
1584 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1586 dc
.SetPen(m_colEmptySpace
);
1587 dc
.SetBrush(m_colEmptySpace
);
1588 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1592 // -----------------------------------------------------------------------
1594 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1595 const wxRect
* clipRect
,
1596 bool isBuffered
) const
1598 const wxPGProperty
* firstItem
;
1599 const wxPGProperty
* lastItem
;
1601 firstItem
= DoGetItemAtY(clipRect
->y
);
1602 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1605 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1607 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1610 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1611 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1613 int lh
= m_lineHeight
;
1616 int lastItemBottomY
;
1618 firstItemTopY
= clipRect
->y
;
1619 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1621 // Align y coordinates to item boundaries
1622 firstItemTopY
-= firstItemTopY
% lh
;
1623 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1624 lastItemBottomY
-= 1;
1626 // Entire range outside scrolled, visible area?
1627 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1630 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1634 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1635 firstItem->GetLabel().c_str(),
1636 lastItem->GetLabel().c_str(),
1637 (int)(lastItemBottomY - firstItemTopY),
1639 (unsigned long)clipRect );
1644 long windowStyle
= m_windowStyle
;
1650 // With wxPG_DOUBLE_BUFFER, do double buffering
1651 // - buffer's y = 0, so align cliprect and coordinates to that
1653 #if wxPG_DOUBLE_BUFFER
1659 xRelMod
= clipRect
->x
;
1660 yRelMod
= clipRect
->y
;
1663 // clipRect conversion
1668 firstItemTopY
-= yRelMod
;
1669 lastItemBottomY
-= yRelMod
;
1672 wxUnusedVar(isBuffered
);
1675 int x
= m_marginWidth
- xRelMod
;
1677 wxFont normalFont
= GetFont();
1679 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1681 bool isEnabled
= IsEnabled();
1684 // Prepare some pens and brushes that are often changed to.
1687 wxBrush
marginBrush(m_colMargin
);
1688 wxPen
marginPen(m_colMargin
);
1689 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1690 wxPen
linepen(m_colLine
,1,wxSOLID
);
1692 // pen that has same colour as text
1693 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1696 // Clear margin with background colour
1698 dc
.SetBrush( marginBrush
);
1699 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1701 dc
.SetPen( *wxTRANSPARENT_PEN
);
1702 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1705 const wxPGProperty
* selected
= m_selected
;
1706 const wxPropertyGridPageState
* state
= m_pState
;
1708 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1709 bool wasSelectedPainted
= false;
1712 // TODO: Only render columns that are within clipping region.
1714 dc
.SetFont(normalFont
);
1716 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1717 int endScanBottomY
= lastItemBottomY
+ lh
;
1718 int y
= firstItemTopY
;
1721 // Pregenerate list of visible properties.
1722 wxArrayPGProperty visPropArray
;
1723 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1725 for ( ; !it
.AtEnd(); it
.Next() )
1727 const wxPGProperty
* p
= *it
;
1729 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1731 visPropArray
.push_back((wxPGProperty
*)p
);
1733 if ( y
> endScanBottomY
)
1740 visPropArray
.push_back(NULL
);
1742 wxPGProperty
* nextP
= visPropArray
[0];
1744 int gridWidth
= state
->m_width
;
1747 for ( unsigned int arrInd
=1;
1748 nextP
&& y
<= lastItemBottomY
;
1751 wxPGProperty
* p
= nextP
;
1752 nextP
= visPropArray
[arrInd
];
1754 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1755 int textMarginHere
= x
;
1756 int renderFlags
= 0;
1758 int greyDepth
= m_marginWidth
;
1759 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1760 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1762 int greyDepthX
= greyDepth
- xRelMod
;
1764 // Use basic depth if in non-categoric mode and parent is base array.
1765 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1767 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1770 // Paint margin area
1771 dc
.SetBrush(marginBrush
);
1772 dc
.SetPen(marginPen
);
1773 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1775 dc
.SetPen( linepen
);
1780 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1786 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1788 sx
+= state
->m_colWidths
[si
];
1789 dc
.DrawLine( sx
, y
, sx
, y2
);
1792 // Horizontal Line, below
1793 // (not if both this and next is category caption)
1794 if ( p
->IsCategory() &&
1795 nextP
&& nextP
->IsCategory() )
1796 dc
.SetPen(m_colCapBack
);
1798 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1801 // Need to override row colours?
1805 if ( p
!= selected
)
1807 // Disabled may get different colour.
1808 if ( !p
->IsEnabled() )
1810 renderFlags
|= wxPGCellRenderer::Disabled
|
1811 wxPGCellRenderer::DontUseCellFgCol
;
1812 rowFgCol
= m_colDisPropFore
;
1817 renderFlags
|= wxPGCellRenderer::Selected
;
1819 if ( !p
->IsCategory() )
1821 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1822 wxPGCellRenderer::DontUseCellBgCol
;
1824 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1825 wasSelectedPainted
= true;
1828 // Selected gets different colour.
1829 if ( reallyFocused
)
1831 rowFgCol
= m_colSelFore
;
1832 rowBgCol
= m_colSelBack
;
1834 else if ( isEnabled
)
1836 rowFgCol
= m_colPropFore
;
1837 rowBgCol
= m_colMargin
;
1841 rowFgCol
= m_colDisPropFore
;
1842 rowBgCol
= m_colSelBack
;
1849 if ( rowBgCol
.IsOk() )
1850 rowBgBrush
= wxBrush(rowBgCol
);
1852 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1853 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1856 // Fill additional margin area with background colour of first cell
1857 if ( greyDepthX
< textMarginHere
)
1859 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1861 wxPGCell
& cell
= p
->GetCell(0);
1862 rowBgCol
= cell
.GetBgCol();
1863 rowBgBrush
= wxBrush(rowBgCol
);
1865 dc
.SetBrush(rowBgBrush
);
1866 dc
.SetPen(rowBgCol
);
1867 dc
.DrawRectangle(greyDepthX
+1, y
,
1868 textMarginHere
-greyDepthX
, lh
-1);
1871 bool fontChanged
= false;
1873 // Expander button rectangle
1874 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1879 if ( p
->IsCategory() )
1881 // Captions have their cell areas merged as one
1882 dc
.SetFont(m_captionFont
);
1884 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1886 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1888 dc
.SetBrush(rowBgBrush
);
1889 dc
.SetPen(rowBgCol
);
1892 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1894 dc
.SetTextForeground(rowFgCol
);
1897 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1898 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1901 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1902 DrawExpanderButton( dc
, butRect
, p
);
1906 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1908 dc
.SetFont(m_captionFont
);
1914 int nextCellWidth
= state
->m_colWidths
[0] -
1915 (greyDepthX
- m_marginWidth
);
1916 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1917 int textXAdd
= textMarginHere
- greyDepthX
;
1919 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1921 cellRect
.width
= nextCellWidth
- 1;
1923 bool ctrlCell
= false;
1924 int cellRenderFlags
= renderFlags
;
1927 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1928 DrawExpanderButton( dc
, butRect
, p
);
1931 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1933 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1934 dc
.SetBrush(editorBgCol
);
1935 dc
.SetPen(editorBgCol
);
1936 dc
.SetTextForeground(m_colPropFore
);
1937 dc
.DrawRectangle(cellRect
);
1939 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1944 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1946 dc
.SetBrush(rowBgBrush
);
1947 dc
.SetPen(rowBgCol
);
1950 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1952 dc
.SetTextForeground(rowFgCol
);
1956 dc
.SetClippingRegion(cellRect
);
1958 cellRect
.x
+= textXAdd
;
1959 cellRect
.width
-= textXAdd
;
1964 wxPGCellRenderer
* renderer
;
1965 int cmnVal
= p
->GetCommonValue();
1966 if ( cmnVal
== -1 || ci
!= 1 )
1968 renderer
= p
->GetCellRenderer(ci
);
1969 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1974 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1975 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1980 cellX
+= state
->m_colWidths
[ci
];
1981 if ( ci
< (state
->m_colWidths
.size()-1) )
1982 nextCellWidth
= state
->m_colWidths
[ci
+1];
1984 dc
.DestroyClippingRegion(); // Is this really necessary?
1990 dc
.SetFont(normalFont
);
1995 // Refresh editor controls (seems not needed on msw)
1996 // NOTE: This code is mandatory for GTK!
1997 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1998 if ( wasSelectedPainted
)
2001 m_wndEditor
->Refresh();
2003 m_wndEditor2
->Refresh();
2010 // -----------------------------------------------------------------------
2012 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2016 if ( m_width
< 10 || m_height
< 10 ||
2017 !m_pState
->m_properties
->GetChildCount() ||
2019 return wxRect(0,0,0,0);
2024 // Return rect which encloses the given property range
2026 int visTop
= p1
->GetY();
2029 visBottom
= p2
->GetY() + m_lineHeight
;
2031 visBottom
= m_height
+ visTop
;
2033 // If seleced property is inside the range, we'll extend the range to include
2035 wxPGProperty
* selected
= m_selected
;
2038 int selectedY
= selected
->GetY();
2039 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2041 wxWindow
* editor
= GetEditorControl();
2044 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2045 if ( visBottom2
> visBottom
)
2046 visBottom
= visBottom2
;
2051 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2054 // -----------------------------------------------------------------------
2056 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2061 if ( m_pState
->m_itemsAdded
)
2062 PrepareAfterItemsAdded();
2064 wxRect r
= GetPropertyRect(p1
, p2
);
2067 m_canvas
->RefreshRect(r
);
2071 // -----------------------------------------------------------------------
2073 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2075 if ( p
== m_selected
)
2076 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2078 DrawItemAndChildren(p
);
2081 // -----------------------------------------------------------------------
2083 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2088 // Draw item, children, and parent too, if it is not category
2089 wxPGProperty
* parent
= p
->GetParent();
2092 !parent
->IsCategory() &&
2093 parent
->GetParent() )
2096 parent
= parent
->GetParent();
2099 DrawItemAndChildren(p
);
2102 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2104 wxCHECK_RET( p
, wxT("invalid property id") );
2106 // Do not draw if in non-visible page
2107 if ( p
->GetParentState() != m_pState
)
2110 // do not draw a single item if multiple pending
2111 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2114 // Update child control.
2115 if ( m_selected
&& m_selected
->GetParent() == p
)
2118 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2120 DrawItems(p
, lastDrawn
);
2123 // -----------------------------------------------------------------------
2125 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2126 const wxRect
*rect
)
2128 PrepareAfterItemsAdded();
2130 wxWindow::Refresh(false);
2132 // TODO: Coordinate translation
2133 m_canvas
->Refresh(false, rect
);
2135 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2136 // I think this really helps only GTK+1.2
2137 if ( m_wndEditor
) m_wndEditor
->Refresh();
2138 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2142 // -----------------------------------------------------------------------
2143 // wxPropertyGrid global operations
2144 // -----------------------------------------------------------------------
2146 void wxPropertyGrid::Clear()
2148 m_pState
->DoClear();
2154 RecalculateVirtualSize();
2156 // Need to clear some area at the end
2158 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2161 // -----------------------------------------------------------------------
2163 bool wxPropertyGrid::EnableCategories( bool enable
)
2165 ClearSelection(false);
2170 // Enable categories
2173 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2178 // Disable categories
2180 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2183 if ( !m_pState
->EnableCategories(enable
) )
2188 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2190 m_pState
->m_itemsAdded
= 1; // force
2191 PrepareAfterItemsAdded();
2195 m_pState
->m_itemsAdded
= 1;
2197 // No need for RecalculateVirtualSize() here - it is already called in
2198 // wxPropertyGridPageState method above.
2205 // -----------------------------------------------------------------------
2207 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2209 wxASSERT( pNewState
);
2210 wxASSERT( pNewState
->GetGrid() );
2212 if ( pNewState
== m_pState
)
2215 wxPGProperty
* oldSelection
= m_selected
;
2217 ClearSelection(false);
2219 m_pState
->m_selected
= oldSelection
;
2221 bool orig_mode
= m_pState
->IsInNonCatMode();
2222 bool new_state_mode
= pNewState
->IsInNonCatMode();
2224 m_pState
= pNewState
;
2227 int pgWidth
= GetClientSize().x
;
2228 if ( HasVirtualWidth() )
2230 int minWidth
= pgWidth
;
2231 if ( pNewState
->m_width
< minWidth
)
2233 pNewState
->m_width
= minWidth
;
2234 pNewState
->CheckColumnWidths();
2240 // Just in case, fully re-center splitter
2241 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2242 pNewState
->m_fSplitterX
= -1.0;
2244 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2249 // If necessary, convert state to correct mode.
2250 if ( orig_mode
!= new_state_mode
)
2252 // This should refresh as well.
2253 EnableCategories( orig_mode
?false:true );
2255 else if ( !m_frozen
)
2257 // Refresh, if not frozen.
2258 m_pState
->PrepareAfterItemsAdded();
2261 if ( m_pState
->m_selected
)
2262 DoSelectProperty( m_pState
->m_selected
);
2264 RecalculateVirtualSize(0);
2268 m_pState
->m_itemsAdded
= 1;
2271 // -----------------------------------------------------------------------
2273 // Call to SetSplitterPosition will always disable splitter auto-centering
2274 // if parent window is shown.
2275 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2277 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2280 wxPropertyGridPageState
* state
= m_pState
;
2282 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2287 CorrectEditorWidgetSizeX();
2293 // -----------------------------------------------------------------------
2295 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2297 SetSplitterPosition( m_width
/2, true );
2298 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2299 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2302 // -----------------------------------------------------------------------
2303 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2304 // -----------------------------------------------------------------------
2306 // Returns nearest paint visible property (such that will be painted unless
2307 // window is scrolled or resized). If given property is paint visible, then
2308 // it itself will be returned
2309 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2311 int vx
,vy1
;// Top left corner of client
2312 GetViewStart(&vx
,&vy1
);
2313 vy1
*= wxPG_PIXELS_PER_UNIT
;
2315 int vy2
= vy1
+ m_height
;
2316 int propY
= p
->GetY2(m_lineHeight
);
2318 if ( (propY
+ m_lineHeight
) < vy1
)
2321 return DoGetItemAtY( vy1
);
2323 else if ( propY
> vy2
)
2326 return DoGetItemAtY( vy2
);
2329 // Itself paint visible
2334 // -----------------------------------------------------------------------
2335 // Methods related to change in value, value modification and sending events
2336 // -----------------------------------------------------------------------
2338 // commits any changes in editor of selected property
2339 // return true if validation did not fail
2340 // flags are same as with DoSelectProperty
2341 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2343 // Committing already?
2344 if ( m_inCommitChangesFromEditor
)
2347 // Don't do this if already processing editor event. It might
2348 // induce recursive dialogs and crap like that.
2349 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2351 if ( m_inDoPropertyChanged
)
2358 IsEditorsValueModified() &&
2359 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2362 m_inCommitChangesFromEditor
= 1;
2364 wxVariant
variant(m_selected
->GetValueRef());
2365 bool valueIsPending
= false;
2367 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2368 // due to another window getting focus
2369 wxWindow
* oldFocus
= m_curFocused
;
2371 bool validationFailure
= false;
2372 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2374 m_chgInfo_changedProperty
= NULL
;
2376 // If truly modified, schedule value as pending.
2377 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2379 if ( DoEditorValidate() &&
2380 PerformValidation(m_selected
, variant
) )
2382 valueIsPending
= true;
2386 validationFailure
= true;
2391 EditorsValueWasNotModified();
2396 m_inCommitChangesFromEditor
= 0;
2398 if ( validationFailure
&& !forceSuccess
)
2402 oldFocus
->SetFocus();
2403 m_curFocused
= oldFocus
;
2406 res
= OnValidationFailure(m_selected
, variant
);
2408 // Now prevent further validation failure messages
2411 EditorsValueWasNotModified();
2412 OnValidationFailureReset(m_selected
);
2415 else if ( valueIsPending
)
2417 DoPropertyChanged( m_selected
, flags
);
2418 EditorsValueWasNotModified();
2427 // -----------------------------------------------------------------------
2429 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2433 // Runs all validation functionality.
2434 // Returns true if value passes all tests.
2437 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2439 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2441 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2446 // Adapt list to child values, if necessary
2447 wxVariant listValue
= pendingValue
;
2448 wxVariant
* pPendingValue
= &pendingValue
;
2449 wxVariant
* pList
= NULL
;
2451 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2452 // string value, then we need treat as it was changed instead
2453 // (or, in addition, as is the case with composite string parent).
2454 // This includes creating list variant for child values.
2456 wxPGProperty
* pwc
= p
->GetParent();
2457 wxPGProperty
* changedProperty
= p
;
2458 wxPGProperty
* baseChangedProperty
= changedProperty
;
2459 wxVariant bcpPendingList
;
2461 listValue
= pendingValue
;
2462 listValue
.SetName(p
->GetBaseName());
2465 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2467 wxVariantList tempList
;
2468 wxVariant
lv(tempList
, pwc
->GetBaseName());
2469 lv
.Append(listValue
);
2471 pPendingValue
= &listValue
;
2473 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2475 baseChangedProperty
= pwc
;
2476 bcpPendingList
= lv
;
2479 changedProperty
= pwc
;
2480 pwc
= pwc
->GetParent();
2484 wxPGProperty
* evtChangingProperty
= changedProperty
;
2486 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2488 value
= *pPendingValue
;
2492 // Convert list to child values
2493 pList
= pPendingValue
;
2494 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2497 wxVariant evtChangingValue
= value
;
2499 if ( flags
& SendEvtChanging
)
2501 // FIXME: After proper ValueToString()s added, remove
2502 // this. It is just a temporary fix, as evt_changing
2503 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2504 // (unless it is selected, and textctrl editor is open).
2505 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2507 evtChangingProperty
= baseChangedProperty
;
2508 if ( evtChangingProperty
!= p
)
2510 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2514 evtChangingValue
= pendingValue
;
2518 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2520 if ( changedProperty
== m_selected
)
2522 wxWindow
* editor
= GetEditorControl();
2523 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2524 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2528 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2533 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2534 m_chgInfo_changedProperty
= changedProperty
;
2535 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2536 m_chgInfo_pendingValue
= value
;
2539 m_chgInfo_valueList
= *pList
;
2541 m_chgInfo_valueList
.MakeNull();
2543 // If changedProperty is not property which value was edited,
2544 // then call wxPGProperty::ValidateValue() for that as well.
2545 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2547 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2551 if ( flags
& SendEvtChanging
)
2553 // SendEvent returns true if event was vetoed
2554 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2558 if ( flags
& IsStandaloneValidation
)
2560 // If called in 'generic' context, we need to reset
2561 // m_chgInfo_changedProperty and write back translated value.
2562 m_chgInfo_changedProperty
= NULL
;
2563 pendingValue
= value
;
2569 // -----------------------------------------------------------------------
2571 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2573 if ( !msg
.length() )
2577 if ( !wxPGGlobalVars
->m_offline
)
2579 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2582 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2585 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2588 pStatusBar
->SetStatusText(msg
);
2596 ::wxMessageBox(msg
, _T("Property Error"));
2599 // -----------------------------------------------------------------------
2601 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2602 wxVariant
& invalidValue
)
2604 wxWindow
* editor
= GetEditorControl();
2606 // First call property's handler
2607 property
->OnValidationFailure(invalidValue
);
2609 bool res
= DoOnValidationFailure(property
, invalidValue
);
2612 // For non-wxTextCtrl editors, we do need to revert the value
2613 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2614 property
== m_selected
)
2616 property
->GetEditorClass()->UpdateControl(property
, editor
);
2619 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2624 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2626 int vfb
= m_validationInfo
.m_failureBehavior
;
2628 if ( vfb
& wxPG_VFB_BEEP
)
2631 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2632 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2634 unsigned int colCount
= m_pState
->GetColumnCount();
2636 // We need backup marked property's cells
2637 m_propCellsBackup
= property
->m_cells
;
2639 wxColour vfbFg
= *wxWHITE
;
2640 wxColour vfbBg
= *wxRED
;
2642 property
->EnsureCells(colCount
);
2644 for ( unsigned int i
=0; i
<colCount
; i
++ )
2646 wxPGCell
& cell
= property
->m_cells
[i
];
2647 cell
.SetFgCol(vfbFg
);
2648 cell
.SetBgCol(vfbBg
);
2651 DrawItemAndChildren(property
);
2653 if ( property
== m_selected
)
2655 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2657 wxWindow
* editor
= GetEditorControl();
2660 editor
->SetForegroundColour(vfbFg
);
2661 editor
->SetBackgroundColour(vfbBg
);
2666 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2668 wxString msg
= m_validationInfo
.m_failureMessage
;
2670 if ( !msg
.length() )
2671 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2673 DoShowPropertyError(property
, msg
);
2676 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2679 // -----------------------------------------------------------------------
2681 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2683 int vfb
= m_validationInfo
.m_failureBehavior
;
2685 if ( vfb
& wxPG_VFB_MARK_CELL
)
2688 property
->m_cells
= m_propCellsBackup
;
2690 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2692 if ( property
== m_selected
&& GetEditorControl() )
2694 // Calling this will recreate the control, thus resetting its colour
2695 RefreshProperty(property
);
2699 DrawItemAndChildren(property
);
2704 // -----------------------------------------------------------------------
2706 // flags are same as with DoSelectProperty
2707 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2709 if ( m_inDoPropertyChanged
)
2712 wxWindow
* editor
= GetEditorControl();
2714 m_pState
->m_anyModified
= 1;
2716 m_inDoPropertyChanged
= 1;
2718 // Maybe need to update control
2719 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2721 // These values were calculated in PerformValidation()
2722 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2723 wxVariant value
= m_chgInfo_pendingValue
;
2725 wxPGProperty
* topPaintedProperty
= changedProperty
;
2727 while ( !topPaintedProperty
->IsCategory() &&
2728 !topPaintedProperty
->IsRoot() )
2730 topPaintedProperty
= topPaintedProperty
->GetParent();
2733 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2735 // Set as Modified (not if dragging just began)
2736 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2738 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2739 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2742 SetCurControlBoldFont();
2748 // Propagate updates to parent(s)
2750 wxPGProperty
* prevPwc
= NULL
;
2752 while ( prevPwc
!= topPaintedProperty
)
2754 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2756 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2759 SetCurControlBoldFont();
2763 pwc
= pwc
->GetParent();
2766 // Draw the actual property
2767 DrawItemAndChildren( topPaintedProperty
);
2770 // If value was set by wxPGProperty::OnEvent, then update the editor
2772 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2778 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2779 if ( m_wndEditor
) m_wndEditor
->Refresh();
2780 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2785 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2787 // If top parent has composite string value, then send to child parents,
2788 // starting from baseChangedProperty.
2789 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2791 pwc
= m_chgInfo_baseChangedProperty
;
2793 while ( pwc
!= changedProperty
)
2795 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2796 pwc
= pwc
->GetParent();
2800 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2802 m_inDoPropertyChanged
= 0;
2807 // -----------------------------------------------------------------------
2809 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2811 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2813 m_chgInfo_changedProperty
= NULL
;
2815 if ( PerformValidation(p
, newValue
) )
2817 DoPropertyChanged(p
);
2822 OnValidationFailure(p
, newValue
);
2828 // -----------------------------------------------------------------------
2830 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2832 wxPGProperty
* prop
= GetSelectedProperty();
2835 return wxNullVariant
;
2837 wxTextCtrl
* tc
= GetEditorTextCtrl();
2838 wxVariant value
= prop
->GetValue();
2840 if ( !tc
|| !IsEditorsValueModified() )
2843 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2846 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2847 return prop
->GetValue();
2852 // -----------------------------------------------------------------------
2854 // Runs wxValidator for the selected property
2855 bool wxPropertyGrid::DoEditorValidate()
2860 // -----------------------------------------------------------------------
2862 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2864 wxPGProperty
* selected
= m_selected
;
2866 // Somehow, event is handled after property has been deselected.
2867 // Possibly, but very rare.
2871 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2874 wxVariant
pendingValue(selected
->GetValueRef());
2875 wxWindow
* wnd
= GetEditorControl();
2876 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
2878 bool wasUnspecified
= selected
->IsValueUnspecified();
2879 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2880 bool valueIsPending
= false;
2882 m_chgInfo_changedProperty
= NULL
;
2884 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2887 // Filter out excess wxTextCtrl modified events
2888 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2890 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2892 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2894 wxString newTcValue
= tc
->GetValue();
2895 if ( m_prevTcValue
== newTcValue
)
2898 m_prevTcValue
= newTcValue
;
2901 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2903 bool validationFailure
= false;
2904 bool buttonWasHandled
= false;
2907 // Try common button handling
2908 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2910 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2914 buttonWasHandled
= true;
2915 // Store as res2, as previously (and still currently alternatively)
2916 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2917 // in wxPGProperty::OnEvent().
2918 adapter
->ShowDialog( this, selected
);
2923 if ( !buttonWasHandled
)
2925 if ( wnd
|| m_wndEditor2
)
2927 // First call editor class' event handler.
2928 const wxPGEditor
* editor
= selected
->GetEditorClass();
2930 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
2932 // If changes, validate them
2933 if ( DoEditorValidate() )
2935 if ( editor
->GetValueFromControl( pendingValue
,
2938 valueIsPending
= true;
2942 validationFailure
= true;
2947 // Then the property's custom handler (must be always called, unless
2948 // validation failed).
2949 if ( !validationFailure
)
2950 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
2953 // SetValueInEvent(), as called in one of the functions referred above
2954 // overrides editor's value.
2955 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2957 valueIsPending
= true;
2958 pendingValue
= m_changeInEventValue
;
2959 selFlags
|= wxPG_SEL_DIALOGVAL
;
2962 if ( !validationFailure
&& valueIsPending
)
2963 if ( !PerformValidation(m_selected
, pendingValue
) )
2964 validationFailure
= true;
2966 if ( validationFailure
)
2968 OnValidationFailure(selected
, pendingValue
);
2970 else if ( valueIsPending
)
2972 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2974 DoPropertyChanged(selected
, selFlags
);
2975 EditorsValueWasNotModified();
2977 // Regardless of editor type, unfocus editor on
2978 // text-editing related enter press.
2979 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2986 // No value after all
2988 // Regardless of editor type, unfocus editor on
2989 // text-editing related enter press.
2990 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2995 // Let unhandled button click events go to the parent
2996 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2998 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2999 GetEventHandler()->AddPendingEvent(evt
);
3003 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3006 // -----------------------------------------------------------------------
3007 // wxPropertyGrid editor control helper methods
3008 // -----------------------------------------------------------------------
3010 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3012 int itemy
= p
->GetY2(m_lineHeight
);
3014 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3015 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3016 int imageOffset
= 0;
3018 // TODO: If custom image detection changes from current, change this.
3019 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
3021 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3022 int iw
= p
->OnMeasureImage().x
;
3024 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
3025 imageOffset
= p
->GetImageOffset(iw
);
3030 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3032 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3037 // -----------------------------------------------------------------------
3039 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3041 wxSize sz
= GetImageSize(p
, item
);
3042 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3043 wxPG_CUSTOM_IMAGE_SPACINGY
,
3048 // return size of custom paint image
3049 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3051 // If called with NULL property, then return default image
3052 // size for properties that use image.
3054 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3056 wxSize cis
= p
->OnMeasureImage(item
);
3058 int choiceCount
= p
->m_choices
.GetCount();
3059 int comVals
= p
->GetDisplayedCommonValueCount();
3060 if ( item
>= choiceCount
&& comVals
> 0 )
3062 unsigned int cvi
= item
-choiceCount
;
3063 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3065 else if ( item
>= 0 && choiceCount
== 0 )
3066 return wxSize(0, 0);
3071 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3076 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3083 // -----------------------------------------------------------------------
3085 // takes scrolling into account
3086 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3089 GetViewStart(&vx
,&vy
);
3090 vy
*=wxPG_PIXELS_PER_UNIT
;
3091 vx
*=wxPG_PIXELS_PER_UNIT
;
3094 ClientToScreen( px
, py
);
3097 // -----------------------------------------------------------------------
3099 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3102 GetViewStart(&pt2
.x
,&pt2
.y
);
3103 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3104 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3108 return m_pState
->HitTest(pt2
);
3111 // -----------------------------------------------------------------------
3113 // custom set cursor
3114 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3116 if ( type
== m_curcursor
&& !override
) return;
3118 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3120 if ( type
== wxCURSOR_SIZEWE
)
3121 cursor
= m_cursorSizeWE
;
3123 m_canvas
->SetCursor( *cursor
);
3128 // -----------------------------------------------------------------------
3129 // wxPropertyGrid property selection, editor creation
3130 // -----------------------------------------------------------------------
3133 // This class forwards events from property editor controls to wxPropertyGrid.
3134 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3137 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3138 : wxEvtHandler(), m_propGrid(propGrid
)
3142 virtual ~wxPropertyGridEditorEventForwarder()
3147 bool ProcessEvent( wxEvent
& event
)
3152 m_propGrid
->HandleCustomEditorEvent(event
);
3154 return wxEvtHandler::ProcessEvent(event
);
3157 wxPropertyGrid
* m_propGrid
;
3160 // Setups event handling for child control
3161 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3163 wxWindowID id
= argWnd
->GetId();
3165 if ( argWnd
== m_wndEditor
)
3167 argWnd
->Connect(id
, wxEVT_MOTION
,
3168 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3170 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3171 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3173 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3174 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3176 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3177 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3179 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3180 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3182 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3183 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3187 wxPropertyGridEditorEventForwarder
* forwarder
;
3188 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3189 argWnd
->PushEventHandler(forwarder
);
3191 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3192 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3196 void wxPropertyGrid::FreeEditors()
3199 // Return focus back to canvas from children (this is required at least for
3200 // GTK+, which, unlike Windows, clears focus when control is destroyed
3201 // instead of moving it to closest parent).
3202 wxWindow
* focus
= wxWindow::FindFocus();
3205 wxWindow
* parent
= focus
->GetParent();
3208 if ( parent
== m_canvas
)
3213 parent
= parent
->GetParent();
3217 // Do not free editors immediately if processing events
3220 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3221 m_wndEditor2
->Hide();
3222 wxPendingDelete
.Append( handler
);
3223 wxPendingDelete
.Append( m_wndEditor2
);
3224 m_wndEditor2
= NULL
;
3229 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3230 m_wndEditor
->Hide();
3231 wxPendingDelete
.Append( handler
);
3232 wxPendingDelete
.Append( m_wndEditor
);
3237 // Call with NULL to de-select property
3238 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3242 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3243 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3245 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3248 if ( m_inDoSelectProperty
)
3251 m_inDoSelectProperty
= 1;
3253 wxPGProperty
* prev
= m_selected
;
3257 m_inDoSelectProperty
= 0;
3263 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3265 wxPrintf( "None selected\n" );
3268 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3270 wxPrintf( "P = NULL\n" );
3273 // If we are frozen, then just set the values.
3276 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3277 m_editorFocused
= 0;
3280 m_pState
->m_selected
= p
;
3282 // If frozen, always free controls. But don't worry, as Thaw will
3283 // recall SelectProperty to recreate them.
3286 // Prevent any further selection measures in this call
3292 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3294 // Only set focus if not deselecting
3297 if ( flags
& wxPG_SEL_FOCUS
)
3301 m_wndEditor
->SetFocus();
3302 m_editorFocused
= 1;
3311 m_inDoSelectProperty
= 0;
3316 // First, deactivate previous
3320 OnValidationFailureReset(m_selected
);
3322 // Must double-check if this is an selected in case of forceswitch
3325 if ( !CommitChangesFromEditor(flags
) )
3327 // Validation has failed, so we can't exit the previous editor
3328 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3329 // _("Invalid Value"),wxOK|wxICON_ERROR);
3330 m_inDoSelectProperty
= 0;
3339 m_pState
->m_selected
= NULL
;
3341 // We need to always fully refresh the grid here
3344 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3345 EditorsValueWasNotModified();
3348 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3351 // Then, activate the one given.
3354 int propY
= p
->GetY2(m_lineHeight
);
3356 int splitterX
= GetSplitterPosition();
3357 m_editorFocused
= 0;
3359 m_pState
->m_selected
= p
;
3360 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3362 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3364 wxASSERT( m_wndEditor
== NULL
);
3367 // Only create editor for non-disabled non-caption
3368 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3370 // do this for non-caption items
3374 // Do we need to paint the custom image, if any?
3375 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3376 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3377 !p
->GetEditorClass()->CanContainCustomImage()
3379 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3381 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3382 wxPoint goodPos
= grect
.GetPosition();
3383 #if wxPG_CREATE_CONTROLS_HIDDEN
3384 int coord_adjust
= m_height
- goodPos
.y
;
3385 goodPos
.y
+= coord_adjust
;
3388 const wxPGEditor
* editor
= p
->GetEditorClass();
3389 wxCHECK_MSG(editor
, false,
3390 wxT("NULL editor class not allowed"));
3392 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3394 wxPGWindowList wndList
= editor
->CreateControls(this,
3399 m_wndEditor
= wndList
.m_primary
;
3400 m_wndEditor2
= wndList
.m_secondary
;
3401 wxWindow
* primaryCtrl
= GetEditorControl();
3404 // Essentially, primaryCtrl == m_wndEditor
3407 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3408 // value is drawn as normal, and m_wndEditor2 is assumed
3409 // to be a right-aligned button that triggers a separate editorCtrl
3414 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3415 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3417 // Set validator, if any
3418 #if wxUSE_VALIDATORS
3419 wxValidator
* validator
= p
->GetValidator();
3421 primaryCtrl
->SetValidator(*validator
);
3424 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3425 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3427 // If it has modified status, use bold font
3428 // (must be done before capturing m_ctrlXAdjust)
3429 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3430 SetCurControlBoldFont();
3433 // Fix TextCtrl indentation
3434 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3435 wxTextCtrl
* tc
= NULL
;
3436 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3437 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3439 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3441 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3444 // Store x relative to splitter (we'll need it).
3445 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3447 // Check if background clear is not necessary
3448 wxPoint pos
= m_wndEditor
->GetPosition();
3449 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3451 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3454 m_wndEditor
->SetSizeHints(3, 3);
3456 #if wxPG_CREATE_CONTROLS_HIDDEN
3457 m_wndEditor
->Show(false);
3458 m_wndEditor
->Freeze();
3460 goodPos
= m_wndEditor
->GetPosition();
3461 goodPos
.y
-= coord_adjust
;
3462 m_wndEditor
->Move( goodPos
);
3465 SetupChildEventHandling(primaryCtrl
);
3467 // Focus and select all (wxTextCtrl, wxComboBox etc)
3468 if ( flags
& wxPG_SEL_FOCUS
)
3470 primaryCtrl
->SetFocus();
3472 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3478 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3479 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3481 // Get proper id for wndSecondary
3482 m_wndSecId
= m_wndEditor2
->GetId();
3483 wxWindowList children
= m_wndEditor2
->GetChildren();
3484 wxWindowList::iterator node
= children
.begin();
3485 if ( node
!= children
.end() )
3486 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3488 m_wndEditor2
->SetSizeHints(3,3);
3490 #if wxPG_CREATE_CONTROLS_HIDDEN
3491 wxRect sec_rect
= m_wndEditor2
->GetRect();
3492 sec_rect
.y
-= coord_adjust
;
3494 // Fine tuning required to fix "oversized"
3495 // button disappearance bug.
3496 if ( sec_rect
.y
< 0 )
3498 sec_rect
.height
+= sec_rect
.y
;
3501 m_wndEditor2
->SetSize( sec_rect
);
3503 m_wndEditor2
->Show();
3505 SetupChildEventHandling(m_wndEditor2
);
3507 // If no primary editor, focus to button to allow
3508 // it to interprete ENTER etc.
3509 // NOTE: Due to problems focusing away from it, this
3510 // has been disabled.
3512 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3513 m_wndEditor2->SetFocus();
3517 if ( flags
& wxPG_SEL_FOCUS
)
3518 m_editorFocused
= 1;
3523 // Make sure focus is in grid canvas (important for wxGTK, at least)
3527 EditorsValueWasNotModified();
3529 // If it's inside collapsed section, expand parent, scroll, etc.
3530 // Also, if it was partially visible, scroll it into view.
3531 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3536 #if wxPG_CREATE_CONTROLS_HIDDEN
3537 m_wndEditor
->Thaw();
3539 m_wndEditor
->Show(true);
3546 // Make sure focus is in grid canvas
3550 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3556 // Show help text in status bar.
3557 // (if found and grid not embedded in manager with help box and
3558 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3561 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3563 wxStatusBar
* statusbar
= NULL
;
3564 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3566 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3568 statusbar
= frame
->GetStatusBar();
3573 const wxString
* pHelpString
= (const wxString
*) NULL
;
3577 pHelpString
= &p
->GetHelpString();
3578 if ( pHelpString
->length() )
3580 // Set help box text.
3581 statusbar
->SetStatusText( *pHelpString
);
3582 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3586 if ( (!pHelpString
|| !pHelpString
->length()) &&
3587 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3589 // Clear help box - but only if it was written
3590 // by us at previous time.
3591 statusbar
->SetStatusText( m_emptyString
);
3592 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3598 m_inDoSelectProperty
= 0;
3600 // call wx event handler (here so that it also occurs on deselection)
3601 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3606 // -----------------------------------------------------------------------
3608 bool wxPropertyGrid::UnfocusEditor()
3610 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3613 if ( !CommitChangesFromEditor(0) )
3617 DrawItem(m_selected
);
3622 // -----------------------------------------------------------------------
3624 void wxPropertyGrid::RefreshEditor()
3626 wxPGProperty
* p
= m_selected
;
3630 wxWindow
* wnd
= GetEditorControl();
3634 // Set editor font boldness - must do this before
3635 // calling UpdateControl().
3636 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3638 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3639 wnd
->SetFont(GetCaptionFont());
3641 wnd
->SetFont(GetFont());
3644 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3646 editorClass
->UpdateControl(p
, wnd
);
3648 if ( p
->IsValueUnspecified() )
3649 editorClass
->SetValueToUnspecified(p
, wnd
);
3652 // -----------------------------------------------------------------------
3654 // This method is not inline because it called dozens of times
3655 // (i.e. two-arg function calls create smaller code size).
3656 bool wxPropertyGrid::DoClearSelection()
3658 return DoSelectProperty(NULL
);
3661 // -----------------------------------------------------------------------
3662 // wxPropertyGrid expand/collapse state
3663 // -----------------------------------------------------------------------
3665 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3667 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3669 // If active editor was inside collapsed section, then disable it
3670 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3672 ClearSelection(false);
3675 // Store dont-center-splitter flag 'cause we need to temporarily set it
3676 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3677 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3679 bool res
= m_pState
->DoCollapse(pwc
);
3684 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3686 RecalculateVirtualSize();
3688 // Redraw etc. only if collapsed was visible.
3689 if (pwc
->IsVisible() &&
3691 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3693 // When item is collapsed so that scrollbar would move,
3694 // graphics mess is about (unless we redraw everything).
3699 // Clear dont-center-splitter flag if it wasn't set
3700 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3705 // -----------------------------------------------------------------------
3707 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3709 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3711 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3713 // Store dont-center-splitter flag 'cause we need to temporarily set it
3714 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3715 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3717 bool res
= m_pState
->DoExpand(pwc
);
3722 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3724 RecalculateVirtualSize();
3726 // Redraw etc. only if expanded was visible.
3727 if ( pwc
->IsVisible() && !m_frozen
&&
3728 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3732 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3735 DrawItems(pwc
, NULL
);
3740 // Clear dont-center-splitter flag if it wasn't set
3741 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3746 // -----------------------------------------------------------------------
3748 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3751 return m_pState
->DoHideProperty(p
, hide
, flags
);
3754 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3757 ClearSelection(false);
3760 m_pState
->DoHideProperty(p
, hide
, flags
);
3762 RecalculateVirtualSize();
3769 // -----------------------------------------------------------------------
3770 // wxPropertyGrid size related methods
3771 // -----------------------------------------------------------------------
3773 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3775 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3779 // If virtual height was changed, then recalculate editor control position(s)
3780 if ( m_pState
->m_vhCalcPending
)
3781 CorrectEditorWidgetPosY();
3783 m_pState
->EnsureVirtualHeight();
3785 wxASSERT_LEVEL_2_MSG(
3786 m_pState
->GetVirtualHeight() == m_pState
->GetActualVirtualHeight(),
3787 "VirtualHeight and ActualVirtualHeight should match"
3790 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3792 int x
= m_pState
->m_width
;
3793 int y
= m_pState
->m_virtualHeight
;
3796 GetClientSize(&width
,&height
);
3798 // Now adjust virtual size.
3799 SetVirtualSize(x
, y
);
3805 // Adjust scrollbars
3806 if ( HasVirtualWidth() )
3808 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3809 xPos
= GetScrollPos( wxHORIZONTAL
);
3812 if ( forceXPos
!= -1 )
3815 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3818 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3819 int yPos
= GetScrollPos( wxVERTICAL
);
3821 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3822 xAmount
, yAmount
, xPos
, yPos
, true );
3824 // Must re-get size now
3825 GetClientSize(&width
,&height
);
3827 if ( !HasVirtualWidth() )
3829 m_pState
->SetVirtualWidth(width
);
3836 m_canvas
->SetSize( x
, y
);
3838 m_pState
->CheckColumnWidths();
3841 CorrectEditorWidgetSizeX();
3843 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3846 // -----------------------------------------------------------------------
3848 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3850 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3854 GetClientSize(&width
,&height
);
3859 #if wxPG_DOUBLE_BUFFER
3860 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3862 int dblh
= (m_lineHeight
*2);
3863 if ( !m_doubleBuffer
)
3865 // Create double buffer bitmap to draw on, if none
3866 int w
= (width
>250)?width
:250;
3867 int h
= height
+ dblh
;
3869 m_doubleBuffer
= new wxBitmap( w
, h
);
3873 int w
= m_doubleBuffer
->GetWidth();
3874 int h
= m_doubleBuffer
->GetHeight();
3876 // Double buffer must be large enough
3877 if ( w
< width
|| h
< (height
+dblh
) )
3879 if ( w
< width
) w
= width
;
3880 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3881 delete m_doubleBuffer
;
3882 m_doubleBuffer
= new wxBitmap( w
, h
);
3889 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3890 m_ncWidth
= event
.GetSize().x
;
3894 if ( m_pState
->m_itemsAdded
)
3895 PrepareAfterItemsAdded();
3897 // Without this, virtual size (atleast under wxGTK) will be skewed
3898 RecalculateVirtualSize();
3904 // -----------------------------------------------------------------------
3906 void wxPropertyGrid::SetVirtualWidth( int width
)
3910 // Disable virtual width
3911 width
= GetClientSize().x
;
3912 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3916 // Enable virtual width
3917 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3919 m_pState
->SetVirtualWidth( width
);
3922 void wxPropertyGrid::SetFocusOnCanvas()
3924 m_canvas
->SetFocusIgnoringChildren();
3925 m_editorFocused
= 0;
3928 // -----------------------------------------------------------------------
3929 // wxPropertyGrid mouse event handling
3930 // -----------------------------------------------------------------------
3932 // selFlags uses same values DoSelectProperty's flags
3933 // Returns true if event was vetoed.
3934 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3936 // Send property grid event of specific type and with specific property
3937 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3938 evt
.SetPropertyGrid(this);
3939 evt
.SetEventObject(m_eventObject
);
3943 evt
.SetCanVeto(true);
3944 evt
.SetupValidationInfo();
3945 m_validationInfo
.m_pValue
= pValue
;
3947 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3949 evtHandler
->ProcessEvent(evt
);
3951 return evt
.WasVetoed();
3954 // -----------------------------------------------------------------------
3956 // Return false if should be skipped
3957 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3961 // Need to set focus?
3962 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3967 wxPropertyGridPageState
* state
= m_pState
;
3969 int splitterHitOffset
;
3970 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3972 wxPGProperty
* p
= DoGetItemAtY(y
);
3976 int depth
= (int)p
->GetDepth() - 1;
3978 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3980 if ( x
>= marginEnds
)
3984 if ( p
->IsCategory() )
3986 // This is category.
3987 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3989 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3991 // Expand, collapse, activate etc. if click on text or left of splitter.
3994 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3999 if ( !DoSelectProperty( p
) )
4002 // On double-click, expand/collapse.
4003 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4005 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4006 else DoExpand( p
, true );
4010 else if ( splitterHit
== -1 )
4013 unsigned int selFlag
= 0;
4014 if ( columnHit
== 1 )
4016 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4017 selFlag
= wxPG_SEL_FOCUS
;
4019 if ( !DoSelectProperty( p
, selFlag
) )
4022 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4024 if ( p
->GetChildCount() && !p
->IsCategory() )
4025 // On double-click, expand/collapse.
4026 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4028 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4029 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4030 else DoExpand( p
, true );
4037 // click on splitter
4038 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4040 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4042 // Double-clicking the splitter causes auto-centering
4043 CenterSplitter( true );
4045 else if ( m_dragStatus
== 0 )
4048 // Begin draggin the splitter
4052 // Changes must be committed here or the
4053 // value won't be drawn correctly
4054 if ( !CommitChangesFromEditor() )
4057 m_wndEditor
->Show ( false );
4060 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4062 m_canvas
->CaptureMouse();
4063 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4067 m_draggedSplitter
= splitterHit
;
4068 m_dragOffset
= splitterHitOffset
;
4070 wxClientDC
dc(m_canvas
);
4072 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4073 // Fixes button disappearance bug
4075 m_wndEditor2
->Show ( false );
4078 m_startingSplitterX
= x
- splitterHitOffset
;
4086 if ( p
->GetChildCount() )
4088 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4090 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4092 int y2
= y
% m_lineHeight
;
4093 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4095 // On click on expander button, expand/collapse
4096 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4097 DoCollapse( p
, true );
4099 DoExpand( p
, true );
4108 // -----------------------------------------------------------------------
4110 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4111 wxMouseEvent
& WXUNUSED(event
) )
4115 // Select property here as well
4116 wxPGProperty
* p
= m_propHover
;
4117 if ( p
!= m_selected
)
4118 DoSelectProperty( p
);
4120 // Send right click event.
4121 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4128 // -----------------------------------------------------------------------
4130 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4131 wxMouseEvent
& WXUNUSED(event
) )
4135 // Select property here as well
4136 wxPGProperty
* p
= m_propHover
;
4138 if ( p
!= m_selected
)
4139 DoSelectProperty( p
);
4141 // Send double-click event.
4142 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4149 // -----------------------------------------------------------------------
4151 #if wxPG_SUPPORT_TOOLTIPS
4153 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4155 if ( tipString
.length() )
4157 m_canvas
->SetToolTip(tipString
);
4161 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4162 m_canvas
->SetToolTip( m_emptyString
);
4164 m_canvas
->SetToolTip( NULL
);
4169 #endif // #if wxPG_SUPPORT_TOOLTIPS
4171 // -----------------------------------------------------------------------
4173 // Return false if should be skipped
4174 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4176 // Safety check (needed because mouse capturing may
4177 // otherwise freeze the control)
4178 if ( m_dragStatus
> 0 && !event
.Dragging() )
4180 HandleMouseUp(x
,y
,event
);
4183 wxPropertyGridPageState
* state
= m_pState
;
4185 int splitterHitOffset
;
4186 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4187 int splitterX
= x
- splitterHitOffset
;
4189 if ( m_dragStatus
> 0 )
4191 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4192 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4195 int newSplitterX
= x
- m_dragOffset
;
4196 int splitterX
= x
- splitterHitOffset
;
4198 // Splitter redraw required?
4199 if ( newSplitterX
!= splitterX
)
4202 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4203 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4204 state
->m_fSplitterX
= (float) newSplitterX
;
4207 CorrectEditorWidgetSizeX();
4221 int ih
= m_lineHeight
;
4224 #if wxPG_SUPPORT_TOOLTIPS
4225 wxPGProperty
* prevHover
= m_propHover
;
4226 unsigned char prevSide
= m_mouseSide
;
4228 int curPropHoverY
= y
- (y
% ih
);
4230 // On which item it hovers
4233 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4236 // Mouse moves on another property
4238 m_propHover
= DoGetItemAtY(y
);
4239 m_propHoverY
= curPropHoverY
;
4242 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4245 #if wxPG_SUPPORT_TOOLTIPS
4246 // Store which side we are on
4248 if ( columnHit
== 1 )
4250 else if ( columnHit
== 0 )
4254 // If tooltips are enabled, show label or value as a tip
4255 // in case it doesn't otherwise show in full length.
4257 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4259 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4261 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4263 if ( m_propHover
&& !m_propHover
->IsCategory() )
4266 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4268 // Show help string as a tooltip
4269 wxString tipString
= m_propHover
->GetHelpString();
4271 SetToolTip(tipString
);
4275 // Show cropped value string as a tooltip
4279 if ( m_mouseSide
== 1 )
4281 tipString
= m_propHover
->m_label
;
4282 space
= splitterX
-m_marginWidth
-3;
4284 else if ( m_mouseSide
== 2 )
4286 tipString
= m_propHover
->GetDisplayedString();
4288 space
= m_width
- splitterX
;
4289 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4290 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4296 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4299 SetToolTip( tipString
);
4306 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4307 m_canvas
->SetToolTip( m_emptyString
);
4309 m_canvas
->SetToolTip( NULL
);
4320 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4321 m_canvas
->SetToolTip( m_emptyString
);
4323 m_canvas
->SetToolTip( NULL
);
4331 if ( splitterHit
== -1 ||
4333 HasFlag(wxPG_STATIC_SPLITTER
) )
4335 // hovering on something else
4336 if ( m_curcursor
!= wxCURSOR_ARROW
)
4337 CustomSetCursor( wxCURSOR_ARROW
);
4341 // Do not allow splitter cursor on caption items.
4342 // (also not if we were dragging and its started
4343 // outside the splitter region)
4345 if ( !m_propHover
->IsCategory() &&
4349 // hovering on splitter
4351 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4352 // reliably detected.
4353 //if ( m_curcursor != wxCURSOR_SIZEWE )
4354 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4360 // hovering on something else
4361 if ( m_curcursor
!= wxCURSOR_ARROW
)
4362 CustomSetCursor( wxCURSOR_ARROW
);
4369 // -----------------------------------------------------------------------
4371 // Also handles Leaving event
4372 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4373 wxMouseEvent
&WXUNUSED(event
) )
4375 wxPropertyGridPageState
* state
= m_pState
;
4379 int splitterHitOffset
;
4380 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4382 // No event type check - basicly calling this method should
4383 // just stop dragging.
4384 // Left up after dragged?
4385 if ( m_dragStatus
>= 1 )
4388 // End Splitter Dragging
4390 // DO NOT ENABLE FOLLOWING LINE!
4391 // (it is only here as a reminder to not to do it)
4394 // Disable splitter auto-centering
4395 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4397 // This is necessary to return cursor
4398 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4400 m_canvas
->ReleaseMouse();
4401 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4404 // Set back the default cursor, if necessary
4405 if ( splitterHit
== -1 ||
4408 CustomSetCursor( wxCURSOR_ARROW
);
4413 // Control background needs to be cleared
4414 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4415 DrawItem( m_selected
);
4419 m_wndEditor
->Show ( true );
4422 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4423 // Fixes button disappearance bug
4425 m_wndEditor2
->Show ( true );
4428 // This clears the focus.
4429 m_editorFocused
= 0;
4435 // -----------------------------------------------------------------------
4437 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4439 int splitterX
= GetSplitterPosition();
4442 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4446 wxWindow
* wnd
= GetEditorControl();
4448 // Hide popup on clicks
4449 if ( event
.GetEventType() != wxEVT_MOTION
)
4450 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4452 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4458 if ( wnd
== NULL
|| m_dragStatus
||
4460 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4461 ux
>= (r
.x
+r
.width
) ||
4463 event
.m_y
>= (r
.y
+r
.height
)
4473 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4478 // -----------------------------------------------------------------------
4480 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4483 if ( OnMouseCommon( event
, &x
, &y
) )
4485 HandleMouseClick(x
,y
,event
);
4490 // -----------------------------------------------------------------------
4492 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4495 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4496 HandleMouseRightClick(x
,y
,event
);
4500 // -----------------------------------------------------------------------
4502 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4504 // Always run standard mouse-down handler as well
4505 OnMouseClick(event
);
4508 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4509 HandleMouseDoubleClick(x
,y
,event
);
4513 // -----------------------------------------------------------------------
4515 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4518 if ( OnMouseCommon( event
, &x
, &y
) )
4520 HandleMouseMove(x
,y
,event
);
4525 // -----------------------------------------------------------------------
4527 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4529 // Called when mouse moves in the empty space below the properties.
4530 CustomSetCursor( wxCURSOR_ARROW
);
4533 // -----------------------------------------------------------------------
4535 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4538 if ( OnMouseCommon( event
, &x
, &y
) )
4540 HandleMouseUp(x
,y
,event
);
4545 // -----------------------------------------------------------------------
4547 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4549 // This may get called from child control as well, so event's
4550 // mouse position cannot be relied on.
4552 if ( event
.Entering() )
4554 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4556 // TODO: Fix this (detect parent and only do
4557 // cursor trick if it is a manager).
4558 wxASSERT( GetParent() );
4559 GetParent()->SetCursor(wxNullCursor
);
4561 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4564 GetParent()->SetCursor(wxNullCursor
);
4566 else if ( event
.Leaving() )
4568 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4569 m_canvas
->SetCursor( wxNullCursor
);
4571 // Get real cursor position
4572 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4574 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4577 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4579 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4583 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4591 // -----------------------------------------------------------------------
4593 // Common code used by various OnMouseXXXChild methods.
4594 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4596 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4597 wxASSERT( topCtrlWnd
);
4599 event
.GetPosition(&x
,&y
);
4601 int splitterX
= GetSplitterPosition();
4603 wxRect r
= topCtrlWnd
->GetRect();
4604 if ( !m_dragStatus
&&
4605 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4606 y
>= 0 && y
< r
.height \
4609 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4614 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4621 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4624 if ( OnMouseChildCommon(event
,&x
,&y
) )
4626 bool res
= HandleMouseClick(x
,y
,event
);
4627 if ( !res
) event
.Skip();
4631 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4634 wxASSERT( m_wndEditor
);
4635 // These coords may not be exact (about +-2),
4636 // but that should not matter (right click is about item, not position).
4637 wxPoint pt
= m_wndEditor
->GetPosition();
4638 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4639 wxASSERT( m_selected
);
4640 m_propHover
= m_selected
;
4641 bool res
= HandleMouseRightClick(x
,y
,event
);
4642 if ( !res
) event
.Skip();
4645 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4648 if ( OnMouseChildCommon(event
,&x
,&y
) )
4650 bool res
= HandleMouseMove(x
,y
,event
);
4651 if ( !res
) event
.Skip();
4655 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4658 if ( OnMouseChildCommon(event
,&x
,&y
) )
4660 bool res
= HandleMouseUp(x
,y
,event
);
4661 if ( !res
) event
.Skip();
4665 // -----------------------------------------------------------------------
4666 // wxPropertyGrid keyboard event handling
4667 // -----------------------------------------------------------------------
4669 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4671 // Translates wxKeyEvent to wxPG_ACTION_XXX
4673 int keycode
= event
.GetKeyCode();
4674 int modifiers
= event
.GetModifiers();
4676 wxASSERT( !(modifiers
&~(0xFFFF)) );
4678 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4680 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4682 if ( it
== m_actionTriggers
.end() )
4687 int second
= (it
->second
>>16) & 0xFFFF;
4691 return (it
->second
& 0xFFFF);
4694 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4696 wxASSERT( !(modifiers
&~(0xFFFF)) );
4698 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4700 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4702 if ( it
!= m_actionTriggers
.end() )
4704 // This key combination is already used
4706 // Can add secondary?
4707 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4708 wxT("You can only add up to two separate actions per key combination.") );
4710 action
= it
->second
| (action
<<16);
4713 m_actionTriggers
[hashMapKey
] = action
;
4716 void wxPropertyGrid::ClearActionTriggers( int action
)
4718 wxPGHashMapI2I::iterator it
;
4720 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4722 if ( it
->second
== action
)
4724 m_actionTriggers
.erase(it
);
4729 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4732 // Handles key event when editor control is not focused.
4735 wxCHECK2(!m_frozen
, return);
4737 // Travelsal between items, collapsing/expanding, etc.
4738 int keycode
= event
.GetKeyCode();
4739 bool editorFocused
= IsEditorFocused();
4741 if ( keycode
== WXK_TAB
)
4743 wxWindow
* mainControl
;
4745 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4746 mainControl
= GetParent();
4750 if ( !event
.ShiftDown() )
4752 if ( !editorFocused
&& m_wndEditor
)
4754 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4758 // Tab traversal workaround for platforms on which
4759 // wxWindow::Navigate() may navigate into first child
4760 // instead of next sibling. Does not work perfectly
4761 // in every scenario (for instance, when property grid
4762 // is either first or last control).
4763 #if defined(__WXGTK__)
4764 wxWindow
* sibling
= mainControl
->GetNextSibling();
4766 sibling
->SetFocusFromKbd();
4768 Navigate(wxNavigationKeyEvent::IsForward
);
4774 if ( editorFocused
)
4780 #if defined(__WXGTK__)
4781 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4783 sibling
->SetFocusFromKbd();
4785 Navigate(wxNavigationKeyEvent::IsBackward
);
4793 // Ignore Alt and Control when they are down alone
4794 if ( keycode
== WXK_ALT
||
4795 keycode
== WXK_CONTROL
)
4802 int action
= KeyEventToActions(event
, &secondAction
);
4804 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4807 // Esc cancels any changes
4808 if ( IsEditorsValueModified() )
4810 EditorsValueWasNotModified();
4812 // Update the control as well
4813 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4815 m_selected
->GetDisplayedString() );
4818 OnValidationFailureReset(m_selected
);
4824 // Except for TAB and ESC, handle child control events in child control
4827 // Only propagate event if it had modifiers
4828 if ( !event
.HasModifiers() )
4830 event
.StopPropagation();
4836 bool wasHandled
= false;
4841 if ( ButtonTriggerKeyTest(action
, event
) )
4844 wxPGProperty
* p
= m_selected
;
4846 // Travel and expand/collapse
4849 if ( p
->GetChildCount() )
4851 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4853 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4856 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4858 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4865 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4869 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4875 if ( selectDir
>= -1 )
4877 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4879 DoSelectProperty(p
);
4885 // If nothing was selected, select the first item now
4886 // (or navigate out of tab).
4887 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4889 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4890 if ( p
) DoSelectProperty(p
);
4899 // -----------------------------------------------------------------------
4901 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4903 // If there was editor open and focused, then this event should not
4904 // really be processed here.
4905 if ( IsEditorFocused() )
4907 // However, if event had modifiers, it is probably still best
4909 if ( event
.HasModifiers() )
4912 event
.StopPropagation();
4916 HandleKeyEvent(event
, false);
4919 // -----------------------------------------------------------------------
4921 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4926 action
= KeyEventToActions(event
, &secondAction
);
4929 // Does the keycode trigger button?
4930 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4933 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4934 GetEventHandler()->AddPendingEvent(evt
);
4941 // -----------------------------------------------------------------------
4943 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4945 HandleKeyEvent(event
, true);
4948 // -----------------------------------------------------------------------
4949 // wxPropertyGrid miscellaneous event handling
4950 // -----------------------------------------------------------------------
4952 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4955 // Check if the focus is in this control or one of its children
4956 wxWindow
* newFocused
= wxWindow::FindFocus();
4958 if ( newFocused
!= m_curFocused
)
4959 HandleFocusChange( newFocused
);
4962 bool wxPropertyGrid::IsEditorFocused() const
4964 wxWindow
* focus
= wxWindow::FindFocus();
4966 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4967 focus
== GetEditorControl() )
4973 // Called by focus event handlers. newFocused is the window that becomes focused.
4974 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4976 unsigned int oldFlags
= m_iFlags
;
4978 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4980 wxWindow
* parent
= newFocused
;
4982 // This must be one of nextFocus' parents.
4985 // Use m_eventObject, which is either wxPropertyGrid or
4986 // wxPropertyGridManager, as appropriate.
4987 if ( parent
== m_eventObject
)
4989 m_iFlags
|= wxPG_FL_FOCUSED
;
4992 parent
= parent
->GetParent();
4995 m_curFocused
= newFocused
;
4997 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4998 (oldFlags
& wxPG_FL_FOCUSED
) )
5000 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5002 // Need to store changed value
5003 CommitChangesFromEditor();
5009 // Preliminary code for tab-order respecting
5010 // tab-traversal (but should be moved to
5013 wxWindow* prevFocus = event.GetWindow();
5014 wxWindow* useThis = this;
5015 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5016 useThis = GetParent();
5019 prevFocus->GetParent() == useThis->GetParent() )
5021 wxList& children = useThis->GetParent()->GetChildren();
5023 wxNode* node = children.Find(prevFocus);
5025 if ( node->GetNext() &&
5026 useThis == node->GetNext()->GetData() )
5027 DoSelectProperty(GetFirst());
5028 else if ( node->GetPrevious () &&
5029 useThis == node->GetPrevious()->GetData() )
5030 DoSelectProperty(GetLastProperty());
5037 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5038 DrawItem( m_selected
);
5042 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5044 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5045 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5046 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5047 //else if ( event.GetWindow() )
5049 HandleFocusChange(event
.GetWindow());
5054 // -----------------------------------------------------------------------
5056 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5058 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5062 // -----------------------------------------------------------------------
5064 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5066 m_iFlags
|= wxPG_FL_SCROLLED
;
5071 // -----------------------------------------------------------------------
5073 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5075 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5077 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5081 // -----------------------------------------------------------------------
5082 // Property editor related functions
5083 // -----------------------------------------------------------------------
5085 // noDefCheck = true prevents infinite recursion.
5086 wxPGEditor
* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor
* editorClass
,
5087 const wxString
& editorName
,
5090 wxASSERT( editorClass
);
5092 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5093 RegisterDefaultEditors();
5095 wxString name
= editorName
;
5096 if ( name
.length() == 0 )
5097 name
= editorClass
->GetName();
5099 // Existing editor under this name?
5100 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5102 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5104 // If this name was already used, try class name.
5105 name
= editorClass
->GetClassInfo()->GetClassName();
5106 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5109 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5110 (wxPGEditor
*) vt_it
->second
,
5111 "Editor with given name was already registered" );
5113 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5118 // Use this in RegisterDefaultEditors.
5119 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5120 if ( wxPGEditor_##EDITOR == NULL ) \
5122 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5123 new wxPG##EDITOR##Editor, true ); \
5126 // Registers all default editor classes
5127 void wxPropertyGrid::RegisterDefaultEditors()
5129 wxPGRegisterDefaultEditorClass( TextCtrl
);
5130 wxPGRegisterDefaultEditorClass( Choice
);
5131 wxPGRegisterDefaultEditorClass( ComboBox
);
5132 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5133 #if wxPG_INCLUDE_CHECKBOX
5134 wxPGRegisterDefaultEditorClass( CheckBox
);
5136 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5138 // Register SpinCtrl etc. editors before use
5139 RegisterAdditionalEditors();
5142 // -----------------------------------------------------------------------
5143 // wxPGStringTokenizer
5144 // Needed to handle C-style string lists (e.g. "str1" "str2")
5145 // -----------------------------------------------------------------------
5147 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5148 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5152 wxPGStringTokenizer::~wxPGStringTokenizer()
5156 bool wxPGStringTokenizer::HasMoreTokens()
5158 const wxString
& str
= *m_str
;
5160 wxString::const_iterator i
= m_curPos
;
5162 wxUniChar delim
= m_delimeter
;
5164 wxUniChar prev_a
= wxT('\0');
5166 bool inToken
= false;
5168 while ( i
!= str
.end() )
5177 m_readyToken
.clear();
5182 if ( prev_a
!= wxT('\\') )
5186 if ( a
!= wxT('\\') )
5206 m_curPos
= str
.end();
5214 wxString
wxPGStringTokenizer::GetNextToken()
5216 return m_readyToken
;
5219 // -----------------------------------------------------------------------
5221 // -----------------------------------------------------------------------
5223 wxPGChoiceEntry::wxPGChoiceEntry()
5224 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5228 // -----------------------------------------------------------------------
5230 // -----------------------------------------------------------------------
5232 wxPGChoicesData::wxPGChoicesData()
5236 wxPGChoicesData::~wxPGChoicesData()
5241 void wxPGChoicesData::Clear()
5246 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5248 wxASSERT( m_items
.size() == 0 );
5250 m_items
= data
->m_items
;
5253 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5254 const wxPGChoiceEntry
& item
)
5256 wxVector
<wxPGChoiceEntry
>::iterator it
;
5260 index
= (int) m_items
.size();
5264 it
= m_items
.begin() + index
;
5267 m_items
.insert(it
, item
);
5269 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5271 // Need to fix value?
5272 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5273 ownEntry
.SetValue(index
);
5278 // -----------------------------------------------------------------------
5279 // wxPropertyGridEvent
5280 // -----------------------------------------------------------------------
5282 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5285 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5286 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5287 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5288 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5289 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5290 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5291 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5292 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5293 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5296 // -----------------------------------------------------------------------
5298 void wxPropertyGridEvent::Init()
5300 m_validationInfo
= NULL
;
5302 m_wasVetoed
= false;
5305 // -----------------------------------------------------------------------
5307 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5308 : wxCommandEvent(commandType
,id
)
5314 // -----------------------------------------------------------------------
5316 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5317 : wxCommandEvent(event
)
5319 m_eventType
= event
.GetEventType();
5320 m_eventObject
= event
.m_eventObject
;
5322 m_property
= event
.m_property
;
5323 m_validationInfo
= event
.m_validationInfo
;
5324 m_canVeto
= event
.m_canVeto
;
5325 m_wasVetoed
= event
.m_wasVetoed
;
5328 // -----------------------------------------------------------------------
5330 wxPropertyGridEvent::~wxPropertyGridEvent()
5334 // -----------------------------------------------------------------------
5336 wxEvent
* wxPropertyGridEvent::Clone() const
5338 return new wxPropertyGridEvent( *this );
5341 // -----------------------------------------------------------------------
5342 // wxPropertyGridPopulator
5343 // -----------------------------------------------------------------------
5345 wxPropertyGridPopulator::wxPropertyGridPopulator()
5349 wxPGGlobalVars
->m_offline
++;
5352 // -----------------------------------------------------------------------
5354 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5357 m_propHierarchy
.clear();
5360 // -----------------------------------------------------------------------
5362 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5368 // -----------------------------------------------------------------------
5370 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5373 // Free unused sets of choices
5374 wxPGHashMapS2P::iterator it
;
5376 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5378 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5385 m_pg
->GetPanel()->Refresh();
5387 wxPGGlobalVars
->m_offline
--;
5390 // -----------------------------------------------------------------------
5392 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5393 const wxString
& propLabel
,
5394 const wxString
& propName
,
5395 const wxString
* propValue
,
5396 wxPGChoices
* pChoices
)
5398 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5399 wxPGProperty
* parent
= GetCurParent();
5401 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5403 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5407 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5409 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5413 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5415 property
->SetLabel(propLabel
);
5416 property
->DoSetName(propName
);
5418 if ( pChoices
&& pChoices
->IsOk() )
5419 property
->SetChoices(*pChoices
);
5421 m_state
->DoInsert(parent
, -1, property
);
5424 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5425 wxPG_PROGRAMMATIC_VALUE
);
5430 // -----------------------------------------------------------------------
5432 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5434 m_propHierarchy
.push_back(property
);
5435 DoScanForChildren();
5436 m_propHierarchy
.pop_back();
5439 // -----------------------------------------------------------------------
5441 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5442 const wxString
& idString
)
5444 wxPGChoices choices
;
5447 if ( choicesString
[0] == wxT('@') )
5449 wxString ids
= choicesString
.substr(1);
5450 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5451 if ( it
== m_dictIdChoices
.end() )
5452 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5454 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5459 if ( idString
.length() )
5461 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5462 if ( it
!= m_dictIdChoices
.end() )
5464 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5471 // Parse choices string
5472 wxString::const_iterator it
= choicesString
.begin();
5476 bool labelValid
= false;
5478 for ( ; it
!= choicesString
.end(); ++it
)
5484 if ( c
== wxT('"') )
5489 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5490 choices
.Add(label
, l
);
5493 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5498 else if ( c
== wxT('=') )
5505 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5512 if ( c
== wxT('"') )
5525 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5526 choices
.Add(label
, l
);
5529 if ( !choices
.IsOk() )
5531 choices
.EnsureData();
5535 if ( idString
.length() )
5536 m_dictIdChoices
[idString
] = choices
.GetData();
5543 // -----------------------------------------------------------------------
5545 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5547 if ( s
.Last() == wxT('%') )
5549 wxString s2
= s
.substr(0,s
.length()-1);
5551 if ( s2
.ToLong(&val
, 10) )
5553 *pval
= (val
*max
)/100;
5559 return s
.ToLong(pval
, 10);
5562 // -----------------------------------------------------------------------
5564 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5565 const wxString
& type
,
5566 const wxString
& value
)
5568 int l
= m_propHierarchy
.size();
5572 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5573 wxString valuel
= value
.Lower();
5576 if ( type
.length() == 0 )
5581 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5583 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5585 else if ( value
.ToLong(&v
, 0) )
5592 if ( type
== wxT("string") )
5596 else if ( type
== wxT("int") )
5599 value
.ToLong(&v
, 0);
5602 else if ( type
== wxT("bool") )
5604 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5611 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5616 p
->SetAttribute( name
, variant
);
5621 // -----------------------------------------------------------------------
5623 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5625 wxLogError(_("Error in resource: %s"),msg
.c_str());
5628 // -----------------------------------------------------------------------
5630 #endif // wxUSE_PROPGRID