1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
66 #include "wx/clipbrd.h"
67 #include "wx/dataobj.h"
70 #include "wx/msw/private.h"
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 //#define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 //#define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include "wx/module.h"
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 wxPGGlobalVarsClass
* wxPGGlobalVars
= NULL
;
160 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
162 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
164 m_boolChoices
.Add(_("False"));
165 m_boolChoices
.Add(_("True"));
167 m_fontFamilyChoices
= NULL
;
169 m_defaultRenderer
= new wxPGDefaultRenderer();
171 m_autoGetTranslation
= false;
179 // Prepare some shared variants
180 m_vEmptyString
= wxString();
182 m_vMinusOne
= (long) -1;
186 // Prepare cached string constants
187 m_strstring
= wxS("string");
188 m_strlong
= wxS("long");
189 m_strbool
= wxS("bool");
190 m_strlist
= wxS("list");
191 m_strMin
= wxS("Min");
192 m_strMax
= wxS("Max");
193 m_strUnits
= wxS("Units");
194 m_strInlineHelp
= wxS("InlineHelp");
202 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
206 delete m_defaultRenderer
;
208 // This will always have one ref
209 delete m_fontFamilyChoices
;
212 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
213 delete ((wxValidator
*)m_arrValidators
[i
]);
217 // Destroy value type class instances.
218 wxPGHashMapS2P::iterator vt_it
;
220 // Destroy editor class instances.
221 // iterate over all the elements in the class
222 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
224 delete ((wxPGEditor
*)vt_it
->second
);
227 delete wxPGProperty::sm_wxPG_LABEL
;
230 void wxPropertyGridInitGlobalsIfNeeded()
234 // -----------------------------------------------------------------------
236 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
237 // and tries to commit property value.
238 // -----------------------------------------------------------------------
240 class wxPGTLWHandler
: public wxEvtHandler
244 wxPGTLWHandler( wxPropertyGrid
* pg
)
252 void OnClose( wxCloseEvent
& event
)
254 // ClearSelection forces value validation/commit.
255 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
265 wxPropertyGrid
* m_pg
;
267 DECLARE_EVENT_TABLE()
270 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
271 EVT_CLOSE(wxPGTLWHandler::OnClose
)
274 // -----------------------------------------------------------------------
276 // -----------------------------------------------------------------------
279 // wxPGCanvas acts as a graphics sub-window of the
280 // wxScrolledWindow that wxPropertyGrid is.
282 class wxPGCanvas
: public wxPanel
285 wxPGCanvas() : wxPanel()
288 virtual ~wxPGCanvas() { }
291 void OnMouseMove( wxMouseEvent
&event
)
293 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
294 pg
->OnMouseMove( event
);
297 void OnMouseClick( wxMouseEvent
&event
)
299 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
300 pg
->OnMouseClick( event
);
303 void OnMouseUp( wxMouseEvent
&event
)
305 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
306 pg
->OnMouseUp( event
);
309 void OnMouseRightClick( wxMouseEvent
&event
)
311 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
312 pg
->OnMouseRightClick( event
);
315 void OnMouseDoubleClick( wxMouseEvent
&event
)
317 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
318 pg
->OnMouseDoubleClick( event
);
321 void OnKey( wxKeyEvent
& event
)
323 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
327 void OnPaint( wxPaintEvent
& event
);
329 // Always be focussable, even with child windows
330 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
331 { wxPanel::SetCanFocus(true); }
335 DECLARE_EVENT_TABLE()
336 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
340 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
342 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
343 EVT_MOTION(wxPGCanvas::OnMouseMove
)
344 EVT_PAINT(wxPGCanvas::OnPaint
)
345 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
346 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
347 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
348 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
349 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
353 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
355 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
356 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
360 // Don't paint after destruction has begun
361 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
364 // Update everything inside the box
365 wxRect r
= GetUpdateRegion().GetBox();
367 // FIXME: This is just a workaround for a bug that causes splitters not
368 // to paint when other windows are being dragged over the grid.
369 wxRect fullRect
= GetRect();
371 r
.width
= fullRect
.width
;
373 // Repaint this rectangle
374 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
376 // We assume that the size set when grid is shown
377 // is what is desired.
378 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
381 // -----------------------------------------------------------------------
383 // -----------------------------------------------------------------------
385 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
387 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
388 EVT_IDLE(wxPropertyGrid::OnIdle
)
389 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
390 EVT_PAINT(wxPropertyGrid::OnPaint
)
391 EVT_SIZE(wxPropertyGrid::OnResize
)
392 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
393 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
394 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
395 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
396 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
397 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
398 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
399 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
403 // -----------------------------------------------------------------------
405 wxPropertyGrid::wxPropertyGrid()
411 // -----------------------------------------------------------------------
413 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
418 const wxString
& name
)
422 Create(parent
,id
,pos
,size
,style
,name
);
425 // -----------------------------------------------------------------------
427 bool wxPropertyGrid::Create( wxWindow
*parent
,
432 const wxString
& name
)
435 if ( !(style
&wxBORDER_MASK
) )
436 style
|= wxSIMPLE_BORDER
;
440 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
441 style
&= ~(wxTAB_TRAVERSAL
);
442 style
|= wxWANTS_CHARS
;
444 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
451 // -----------------------------------------------------------------------
454 // Initialize values to defaults
456 void wxPropertyGrid::Init1()
458 // Register editor classes, if necessary.
459 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
460 wxPropertyGrid::RegisterDefaultEditors();
464 m_wndEditor
= m_wndEditor2
= NULL
;
468 m_eventObject
= this;
471 m_sortFunction
= NULL
;
472 m_inDoPropertyChanged
= 0;
473 m_inCommitChangesFromEditor
= 0;
474 m_inDoSelectProperty
= 0;
475 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
481 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
482 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
483 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
484 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
485 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
486 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
487 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
488 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
489 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
491 m_coloursCustomized
= 0;
496 #if wxPG_DOUBLE_BUFFER
497 m_doubleBuffer
= NULL
;
500 #ifndef wxPG_ICON_WIDTH
506 m_iconWidth
= wxPG_ICON_WIDTH
;
511 m_gutterWidth
= wxPG_GUTTER_MIN
;
512 m_subgroup_extramargin
= 10;
516 m_width
= m_height
= 0;
518 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
521 m_chgInfo_changedProperty
= NULL
;
524 // -----------------------------------------------------------------------
527 // Initialize after parent etc. set
529 void wxPropertyGrid::Init2()
531 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
534 // Smaller controls on Mac
535 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
538 // Now create state, if one didn't exist already
539 // (wxPropertyGridManager might have created it for us).
542 m_pState
= CreateState();
543 m_pState
->m_pPropGrid
= this;
544 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
547 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
548 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
550 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
552 m_pState
->InitNonCatMode();
554 m_pState
->m_properties
= m_pState
->m_abcArray
;
557 GetClientSize(&m_width
,&m_height
);
559 #ifndef wxPG_ICON_WIDTH
560 // create two bitmap nodes for drawing
561 m_expandbmp
= new wxBitmap(expand_xpm
);
562 m_collbmp
= new wxBitmap(collapse_xpm
);
564 // calculate average font height for bitmap centering
566 m_iconWidth
= m_expandbmp
->GetWidth();
567 m_iconHeight
= m_expandbmp
->GetHeight();
570 m_curcursor
= wxCURSOR_ARROW
;
571 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
573 // adjust bitmap icon y position so they are centered
574 m_vspacing
= wxPG_DEFAULT_VSPACING
;
576 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
578 // Allocate cell datas indirectly by calling setter
579 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
580 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
584 // This helps with flicker
585 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
588 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
589 m_tlp
= ::wxGetTopLevelParent(this);
590 m_tlwHandler
= handler
;
591 m_tlp
->PushEventHandler(handler
);
593 // set virtual size to this window size
594 wxSize wndsize
= GetSize();
595 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
597 m_timeCreated
= ::wxGetLocalTimeMillis();
599 m_canvas
= new wxPGCanvas();
600 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
601 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
602 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
604 m_iFlags
|= wxPG_FL_INITIALIZED
;
606 m_ncWidth
= wndsize
.GetWidth();
608 // Need to call OnResize handler or size given in constructor/Create
610 wxSizeEvent
sizeEvent(wndsize
,0);
614 // -----------------------------------------------------------------------
616 wxPropertyGrid::~wxPropertyGrid()
620 DoSelectProperty(NULL
);
622 // This should do prevent things from going too badly wrong
623 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
625 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
626 m_canvas
->ReleaseMouse();
628 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
629 m_tlp
->RemoveEventHandler(handler
);
633 if ( IsEditorsValueModified() )
634 ::wxMessageBox(wxS("Most recent change in property editor was lost!!!\n\n(if you don't want this to happen, close your frames and dialogs using Close(false).)"),
635 wxS("wxPropertyGrid Debug Warning") );
638 #if wxPG_DOUBLE_BUFFER
639 if ( m_doubleBuffer
)
640 delete m_doubleBuffer
;
645 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
648 delete m_cursorSizeWE
;
650 #ifndef wxPG_ICON_WIDTH
655 // Delete common value records
656 for ( i
=0; i
<m_commonValues
.size(); i
++ )
658 delete GetCommonValue(i
);
662 // -----------------------------------------------------------------------
664 bool wxPropertyGrid::Destroy()
666 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
667 m_canvas
->ReleaseMouse();
669 return wxScrolledWindow::Destroy();
672 // -----------------------------------------------------------------------
674 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
676 return new wxPropertyGridPageState();
679 // -----------------------------------------------------------------------
680 // wxPropertyGrid overridden wxWindow methods
681 // -----------------------------------------------------------------------
683 void wxPropertyGrid::SetWindowStyleFlag( long style
)
685 long old_style
= m_windowStyle
;
687 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
689 wxASSERT( m_pState
);
691 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
694 EnableCategories( true );
696 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
698 // Disable categories
699 EnableCategories( false );
701 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
707 PrepareAfterItemsAdded();
709 m_pState
->m_itemsAdded
= 1;
711 #if wxPG_SUPPORT_TOOLTIPS
712 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
718 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
719 SetToolTip ( tooltip );
720 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
723 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
728 m_canvas
->SetToolTip( NULL
);
733 wxScrolledWindow::SetWindowStyleFlag ( style
);
735 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
737 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
739 CalculateFontAndBitmapStuff( m_vspacing
);
745 // -----------------------------------------------------------------------
747 void wxPropertyGrid::Freeze()
751 wxScrolledWindow::Freeze();
756 // -----------------------------------------------------------------------
758 void wxPropertyGrid::Thaw()
764 wxScrolledWindow::Thaw();
765 RecalculateVirtualSize();
766 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
770 // Force property re-selection
772 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
776 // -----------------------------------------------------------------------
778 void wxPropertyGrid::SetExtraStyle( long exStyle
)
780 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
782 #if defined(__WXMSW__)
785 // Don't use WS_EX_COMPOSITED just now.
788 if ( m_iFlags & wxPG_FL_IN_MANAGER )
789 hWnd = (HWND)GetParent()->GetHWND();
791 hWnd = (HWND)GetHWND();
793 ::SetWindowLong( hWnd, GWL_EXSTYLE,
794 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
797 //#elif defined(__WXGTK20__)
799 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
800 // truly was double-buffered.
801 if ( !this->IsDoubleBuffered() )
803 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
807 #if wxPG_DOUBLE_BUFFER
808 delete m_doubleBuffer
;
809 m_doubleBuffer
= NULL
;
814 wxScrolledWindow::SetExtraStyle( exStyle
);
816 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
817 m_pState
->InitNonCatMode();
819 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
820 m_windowStyle
|= wxPG_TOOLTIPS
;
823 wxPGGlobalVars
->m_extraStyle
= exStyle
;
826 // -----------------------------------------------------------------------
828 // returns the best acceptable minimal size
829 wxSize
wxPropertyGrid::DoGetBestSize() const
832 if ( m_lineHeight
> hei
)
834 wxSize sz
= wxSize( 60, hei
+40 );
840 // -----------------------------------------------------------------------
841 // wxPropertyGrid Font and Colour Methods
842 // -----------------------------------------------------------------------
844 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
848 m_captionFont
= wxScrolledWindow::GetFont();
850 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
851 m_subgroup_extramargin
= x
+ (x
/2);
854 #if wxPG_USE_RENDERER_NATIVE
855 m_iconWidth
= wxPG_ICON_WIDTH
;
856 #elif wxPG_ICON_WIDTH
858 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
859 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
860 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
864 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
865 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
866 m_gutterWidth
= wxPG_GUTTER_MIN
;
869 if ( vspacing
<= 1 ) vdiv
= 12;
870 else if ( vspacing
>= 3 ) vdiv
= 3;
872 m_spacingy
= m_fontHeight
/ vdiv
;
873 if ( m_spacingy
< wxPG_YSPACING_MIN
)
874 m_spacingy
= wxPG_YSPACING_MIN
;
877 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
878 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
880 m_captionFont
.SetWeight(wxBOLD
);
881 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
883 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
886 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
887 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
890 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
892 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
893 RecalculateVirtualSize();
895 InvalidateBestSize();
898 // -----------------------------------------------------------------------
900 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
906 // -----------------------------------------------------------------------
908 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
909 int ga
= 1000, int ba
= 1000,
910 bool forceDifferent
= false)
917 // Recursion guard (allow 2 max)
918 static int isinside
= 0;
920 wxCHECK_MSG( isinside
< 3,
922 wxT("wxPGAdjustColour should not be recursively called more than once") );
930 if ( r2
>255 ) r2
= 255;
931 else if ( r2
<0) r2
= 0;
933 if ( g2
>255 ) g2
= 255;
934 else if ( g2
<0) g2
= 0;
936 if ( b2
>255 ) b2
= 255;
937 else if ( b2
<0) b2
= 0;
939 // Make sure they are somewhat different
940 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
941 dst
= wxPGAdjustColour(src
,-(ra
*2));
943 dst
= wxColour(r2
,g2
,b2
);
945 // Recursion guard (allow 2 max)
952 static int wxPGGetColAvg( const wxColour
& col
)
954 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
958 void wxPropertyGrid::RegainColours()
960 if ( !(m_coloursCustomized
& 0x0002) )
962 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
964 // Make sure colour is dark enough
966 int colDec
= wxPGGetColAvg(col
) - 230;
968 int colDec
= wxPGGetColAvg(col
) - 200;
971 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
974 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
977 if ( !(m_coloursCustomized
& 0x0001) )
978 m_colMargin
= m_colCapBack
;
980 if ( !(m_coloursCustomized
& 0x0004) )
987 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
988 m_colCapFore
= capForeCol
;
989 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
992 if ( !(m_coloursCustomized
& 0x0008) )
994 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
995 m_colPropBack
= bgCol
;
996 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
999 if ( !(m_coloursCustomized
& 0x0010) )
1001 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1002 m_colPropFore
= fgCol
;
1003 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1006 if ( !(m_coloursCustomized
& 0x0020) )
1007 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1009 if ( !(m_coloursCustomized
& 0x0040) )
1010 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1012 if ( !(m_coloursCustomized
& 0x0080) )
1013 m_colLine
= m_colCapBack
;
1015 if ( !(m_coloursCustomized
& 0x0100) )
1016 m_colDisPropFore
= m_colCapFore
;
1018 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1021 // -----------------------------------------------------------------------
1023 void wxPropertyGrid::ResetColours()
1025 m_coloursCustomized
= 0;
1032 // -----------------------------------------------------------------------
1034 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1036 // Must disable active editor.
1037 ClearSelection(false);
1039 bool res
= wxScrolledWindow::SetFont( font
);
1042 CalculateFontAndBitmapStuff( m_vspacing
);
1049 // -----------------------------------------------------------------------
1051 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1054 m_coloursCustomized
|= 0x80;
1058 // -----------------------------------------------------------------------
1060 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1063 m_coloursCustomized
|= 0x01;
1067 // -----------------------------------------------------------------------
1069 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1071 m_colPropBack
= col
;
1072 m_coloursCustomized
|= 0x08;
1074 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1079 // -----------------------------------------------------------------------
1081 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1083 m_colPropFore
= col
;
1084 m_coloursCustomized
|= 0x10;
1086 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1091 // -----------------------------------------------------------------------
1093 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1095 m_colEmptySpace
= col
;
1100 // -----------------------------------------------------------------------
1102 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1104 m_colDisPropFore
= col
;
1105 m_coloursCustomized
|= 0x100;
1109 // -----------------------------------------------------------------------
1111 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1114 m_coloursCustomized
|= 0x20;
1118 // -----------------------------------------------------------------------
1120 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1123 m_coloursCustomized
|= 0x40;
1127 // -----------------------------------------------------------------------
1129 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1132 m_coloursCustomized
|= 0x02;
1134 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1139 // -----------------------------------------------------------------------
1141 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1144 m_coloursCustomized
|= 0x04;
1146 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1151 // -----------------------------------------------------------------------
1152 // wxPropertyGrid property adding and removal
1153 // -----------------------------------------------------------------------
1155 void wxPropertyGrid::PrepareAfterItemsAdded()
1157 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1159 m_pState
->m_itemsAdded
= 0;
1161 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1162 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1164 RecalculateVirtualSize();
1167 // -----------------------------------------------------------------------
1168 // wxPropertyGrid property operations
1169 // -----------------------------------------------------------------------
1171 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1173 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1177 bool changed
= false;
1179 // Is it inside collapsed section?
1180 if ( !p
->IsVisible() )
1183 wxPGProperty
* parent
= p
->GetParent();
1184 wxPGProperty
* grandparent
= parent
->GetParent();
1186 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1187 Expand( grandparent
);
1195 GetViewStart(&vx
,&vy
);
1196 vy
*=wxPG_PIXELS_PER_UNIT
;
1202 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1203 m_iFlags
|= wxPG_FL_SCROLLED
;
1206 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1208 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1209 m_iFlags
|= wxPG_FL_SCROLLED
;
1219 // -----------------------------------------------------------------------
1220 // wxPropertyGrid helper methods called by properties
1221 // -----------------------------------------------------------------------
1223 // Control font changer helper.
1224 void wxPropertyGrid::SetCurControlBoldFont()
1226 wxASSERT( m_wndEditor
);
1227 m_wndEditor
->SetFont( m_captionFont
);
1230 // -----------------------------------------------------------------------
1232 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1235 #if wxPG_SMALL_SCREEN
1236 // On small-screen devices, always show dialogs with default position and size.
1237 return wxDefaultPosition
;
1239 int splitterX
= GetSplitterPosition();
1243 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1245 ImprovedClientToScreen( &x
, &y
);
1247 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1248 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1255 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1265 new_y
= y
+ m_lineHeight
;
1267 return wxPoint(new_x
,new_y
);
1271 // -----------------------------------------------------------------------
1273 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1275 if ( src_str
.length() == 0 )
1281 bool prev_is_slash
= false;
1283 wxString::const_iterator i
= src_str
.begin();
1287 for ( ; i
!= src_str
.end(); ++i
)
1291 if ( a
!= wxS('\\') )
1293 if ( !prev_is_slash
)
1299 if ( a
== wxS('n') )
1302 dst_str
<< wxS('\n');
1304 dst_str
<< wxS('\n');
1307 else if ( a
== wxS('t') )
1308 dst_str
<< wxS('\t');
1312 prev_is_slash
= false;
1316 if ( prev_is_slash
)
1318 dst_str
<< wxS('\\');
1319 prev_is_slash
= false;
1323 prev_is_slash
= true;
1330 // -----------------------------------------------------------------------
1332 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1334 if ( src_str
.length() == 0 )
1340 wxString::const_iterator i
= src_str
.begin();
1341 wxUniChar prev_a
= wxS('\0');
1345 for ( ; i
!= src_str
.end(); ++i
)
1349 if ( a
>= wxS(' ') )
1351 // This surely is not something that requires an escape sequence.
1356 // This might need...
1357 if ( a
== wxS('\r') )
1359 // DOS style line end.
1360 // Already taken care below
1362 else if ( a
== wxS('\n') )
1363 // UNIX style line end.
1364 dst_str
<< wxS("\\n");
1365 else if ( a
== wxS('\t') )
1367 dst_str
<< wxS('\t');
1370 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1380 // -----------------------------------------------------------------------
1382 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1389 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1392 // -----------------------------------------------------------------------
1393 // wxPropertyGrid graphics related methods
1394 // -----------------------------------------------------------------------
1396 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1400 // Update everything inside the box
1401 wxRect r
= GetUpdateRegion().GetBox();
1403 dc
.SetPen(m_colEmptySpace
);
1404 dc
.SetBrush(m_colEmptySpace
);
1405 dc
.DrawRectangle(r
);
1408 // -----------------------------------------------------------------------
1410 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1411 wxPGProperty
* property
) const
1413 // Prepare rectangle to be used
1415 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1416 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1418 #if (wxPG_USE_RENDERER_NATIVE)
1420 #elif wxPG_ICON_WIDTH
1421 // Drawing expand/collapse button manually
1422 dc
.SetPen(m_colPropFore
);
1423 if ( property
->IsCategory() )
1424 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1426 dc
.SetBrush(m_colPropBack
);
1428 dc
.DrawRectangle( r
);
1429 int _y
= r
.y
+(m_iconWidth
/2);
1430 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1435 if ( property
->IsExpanded() )
1437 // wxRenderer functions are non-mutating in nature, so it
1438 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1439 // Hopefully this does not cause problems.
1440 #if (wxPG_USE_RENDERER_NATIVE)
1441 wxRendererNative::Get().DrawTreeItemButton(
1447 #elif wxPG_ICON_WIDTH
1456 #if (wxPG_USE_RENDERER_NATIVE)
1457 wxRendererNative::Get().DrawTreeItemButton(
1463 #elif wxPG_ICON_WIDTH
1464 int _x
= r
.x
+(m_iconWidth
/2);
1465 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1471 #if (wxPG_USE_RENDERER_NATIVE)
1473 #elif wxPG_ICON_WIDTH
1476 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1480 // -----------------------------------------------------------------------
1483 // This is the one called by OnPaint event handler and others.
1484 // topy and bottomy are already unscrolled (ie. physical)
1486 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1488 unsigned int bottomy
,
1489 const wxRect
* clipRect
)
1491 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1493 m_pState
->EnsureVirtualHeight();
1495 wxRect tempClipRect
;
1498 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1499 clipRect
= &tempClipRect
;
1502 // items added check
1503 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1505 int paintFinishY
= 0;
1507 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1510 bool isBuffered
= false;
1512 #if wxPG_DOUBLE_BUFFER
1513 wxMemoryDC
* bufferDC
= NULL
;
1515 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1517 if ( !m_doubleBuffer
)
1519 paintFinishY
= clipRect
->y
;
1524 bufferDC
= new wxMemoryDC();
1526 // If nothing was changed, then just copy from double-buffer
1527 bufferDC
->SelectObject( *m_doubleBuffer
);
1537 dc
.SetClippingRegion( *clipRect
);
1538 paintFinishY
= DoDrawItems( *dcPtr
, clipRect
, isBuffered
);
1541 #if wxPG_DOUBLE_BUFFER
1544 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1545 bufferDC
, 0, 0, wxCOPY
);
1546 dc
.DestroyClippingRegion(); // Is this really necessary?
1552 // Clear area beyond bottomY?
1553 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1555 dc
.SetPen(m_colEmptySpace
);
1556 dc
.SetBrush(m_colEmptySpace
);
1557 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1561 // -----------------------------------------------------------------------
1563 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1564 const wxRect
* clipRect
,
1565 bool isBuffered
) const
1567 const wxPGProperty
* firstItem
;
1568 const wxPGProperty
* lastItem
;
1570 firstItem
= DoGetItemAtY(clipRect
->y
);
1571 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1574 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1576 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1579 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1580 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1582 int lh
= m_lineHeight
;
1585 int lastItemBottomY
;
1587 firstItemTopY
= clipRect
->y
;
1588 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1590 // Align y coordinates to item boundaries
1591 firstItemTopY
-= firstItemTopY
% lh
;
1592 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1593 lastItemBottomY
-= 1;
1595 // Entire range outside scrolled, visible area?
1596 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1599 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1603 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1604 firstItem->GetLabel().c_str(),
1605 lastItem->GetLabel().c_str(),
1606 (int)(lastItemBottomY - firstItemTopY),
1608 (unsigned long)clipRect );
1613 long windowStyle
= m_windowStyle
;
1619 // With wxPG_DOUBLE_BUFFER, do double buffering
1620 // - buffer's y = 0, so align cliprect and coordinates to that
1622 #if wxPG_DOUBLE_BUFFER
1628 xRelMod
= clipRect
->x
;
1629 yRelMod
= clipRect
->y
;
1632 // clipRect conversion
1637 firstItemTopY
-= yRelMod
;
1638 lastItemBottomY
-= yRelMod
;
1641 wxUnusedVar(isBuffered
);
1644 int x
= m_marginWidth
- xRelMod
;
1646 wxFont normalFont
= GetFont();
1648 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1650 bool isEnabled
= IsEnabled();
1653 // Prepare some pens and brushes that are often changed to.
1656 wxBrush
marginBrush(m_colMargin
);
1657 wxPen
marginPen(m_colMargin
);
1658 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1659 wxPen
linepen(m_colLine
,1,wxSOLID
);
1661 // pen that has same colour as text
1662 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1665 // Clear margin with background colour
1667 dc
.SetBrush( marginBrush
);
1668 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1670 dc
.SetPen( *wxTRANSPARENT_PEN
);
1671 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1674 const wxPGProperty
* selected
= m_selected
;
1675 const wxPropertyGridPageState
* state
= m_pState
;
1677 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1678 bool wasSelectedPainted
= false;
1681 // TODO: Only render columns that are within clipping region.
1683 dc
.SetFont(normalFont
);
1685 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1686 int endScanBottomY
= lastItemBottomY
+ lh
;
1687 int y
= firstItemTopY
;
1690 // Pregenerate list of visible properties.
1691 wxArrayPGProperty visPropArray
;
1692 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1694 for ( ; !it
.AtEnd(); it
.Next() )
1696 const wxPGProperty
* p
= *it
;
1698 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1700 visPropArray
.push_back((wxPGProperty
*)p
);
1702 if ( y
> endScanBottomY
)
1709 visPropArray
.push_back(NULL
);
1711 wxPGProperty
* nextP
= visPropArray
[0];
1713 int gridWidth
= state
->m_width
;
1716 for ( unsigned int arrInd
=1;
1717 nextP
&& y
<= lastItemBottomY
;
1720 wxPGProperty
* p
= nextP
;
1721 nextP
= visPropArray
[arrInd
];
1723 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1724 int textMarginHere
= x
;
1725 int renderFlags
= 0;
1727 int greyDepth
= m_marginWidth
;
1728 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1729 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1731 int greyDepthX
= greyDepth
- xRelMod
;
1733 // Use basic depth if in non-categoric mode and parent is base array.
1734 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1736 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1739 // Paint margin area
1740 dc
.SetBrush(marginBrush
);
1741 dc
.SetPen(marginPen
);
1742 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1744 dc
.SetPen( linepen
);
1749 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1755 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1757 sx
+= state
->m_colWidths
[si
];
1758 dc
.DrawLine( sx
, y
, sx
, y2
);
1761 // Horizontal Line, below
1762 // (not if both this and next is category caption)
1763 if ( p
->IsCategory() &&
1764 nextP
&& nextP
->IsCategory() )
1765 dc
.SetPen(m_colCapBack
);
1767 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1770 // Need to override row colours?
1774 if ( p
!= selected
)
1776 // Disabled may get different colour.
1777 if ( !p
->IsEnabled() )
1779 renderFlags
|= wxPGCellRenderer::Disabled
|
1780 wxPGCellRenderer::DontUseCellFgCol
;
1781 rowFgCol
= m_colDisPropFore
;
1786 renderFlags
|= wxPGCellRenderer::Selected
;
1788 if ( !p
->IsCategory() )
1790 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1791 wxPGCellRenderer::DontUseCellBgCol
;
1793 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1794 wasSelectedPainted
= true;
1797 // Selected gets different colour.
1798 if ( reallyFocused
)
1800 rowFgCol
= m_colSelFore
;
1801 rowBgCol
= m_colSelBack
;
1803 else if ( isEnabled
)
1805 rowFgCol
= m_colPropFore
;
1806 rowBgCol
= m_colMargin
;
1810 rowFgCol
= m_colDisPropFore
;
1811 rowBgCol
= m_colSelBack
;
1818 if ( rowBgCol
.IsOk() )
1819 rowBgBrush
= wxBrush(rowBgCol
);
1821 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1822 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1825 // Fill additional margin area with background colour of first cell
1826 if ( greyDepthX
< textMarginHere
)
1828 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1830 wxPGCell
& cell
= p
->GetCell(0);
1831 rowBgCol
= cell
.GetBgCol();
1832 rowBgBrush
= wxBrush(rowBgCol
);
1834 dc
.SetBrush(rowBgBrush
);
1835 dc
.SetPen(rowBgCol
);
1836 dc
.DrawRectangle(greyDepthX
+1, y
,
1837 textMarginHere
-greyDepthX
, lh
-1);
1840 bool fontChanged
= false;
1842 // Expander button rectangle
1843 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1848 if ( p
->IsCategory() )
1850 // Captions have their cell areas merged as one
1851 dc
.SetFont(m_captionFont
);
1853 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1855 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1857 dc
.SetBrush(rowBgBrush
);
1858 dc
.SetPen(rowBgCol
);
1861 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1863 dc
.SetTextForeground(rowFgCol
);
1866 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1867 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1870 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1871 DrawExpanderButton( dc
, butRect
, p
);
1875 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1877 dc
.SetFont(m_captionFont
);
1883 int nextCellWidth
= state
->m_colWidths
[0] -
1884 (greyDepthX
- m_marginWidth
);
1885 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1886 int textXAdd
= textMarginHere
- greyDepthX
;
1888 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1890 cellRect
.width
= nextCellWidth
- 1;
1892 bool ctrlCell
= false;
1893 int cellRenderFlags
= renderFlags
;
1896 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1897 DrawExpanderButton( dc
, butRect
, p
);
1900 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1902 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1903 dc
.SetBrush(editorBgCol
);
1904 dc
.SetPen(editorBgCol
);
1905 dc
.SetTextForeground(m_colPropFore
);
1906 dc
.DrawRectangle(cellRect
);
1908 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1913 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1915 dc
.SetBrush(rowBgBrush
);
1916 dc
.SetPen(rowBgCol
);
1919 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1921 dc
.SetTextForeground(rowFgCol
);
1925 dc
.SetClippingRegion(cellRect
);
1927 cellRect
.x
+= textXAdd
;
1928 cellRect
.width
-= textXAdd
;
1933 wxPGCellRenderer
* renderer
;
1934 int cmnVal
= p
->GetCommonValue();
1935 if ( cmnVal
== -1 || ci
!= 1 )
1937 renderer
= p
->GetCellRenderer(ci
);
1938 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1943 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1944 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1949 cellX
+= state
->m_colWidths
[ci
];
1950 if ( ci
< (state
->m_colWidths
.size()-1) )
1951 nextCellWidth
= state
->m_colWidths
[ci
+1];
1953 dc
.DestroyClippingRegion(); // Is this really necessary?
1959 dc
.SetFont(normalFont
);
1964 // Refresh editor controls (seems not needed on msw)
1965 // NOTE: This code is mandatory for GTK!
1966 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1967 if ( wasSelectedPainted
)
1970 m_wndEditor
->Refresh();
1972 m_wndEditor2
->Refresh();
1979 // -----------------------------------------------------------------------
1981 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
1985 if ( m_width
< 10 || m_height
< 10 ||
1986 !m_pState
->m_properties
->GetChildCount() ||
1988 return wxRect(0,0,0,0);
1993 // Return rect which encloses the given property range
1995 int visTop
= p1
->GetY();
1998 visBottom
= p2
->GetY() + m_lineHeight
;
2000 visBottom
= m_height
+ visTop
;
2002 // If seleced property is inside the range, we'll extend the range to include
2004 wxPGProperty
* selected
= m_selected
;
2007 int selectedY
= selected
->GetY();
2008 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2010 wxWindow
* editor
= GetEditorControl();
2013 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2014 if ( visBottom2
> visBottom
)
2015 visBottom
= visBottom2
;
2020 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2023 // -----------------------------------------------------------------------
2025 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2030 if ( m_pState
->m_itemsAdded
)
2031 PrepareAfterItemsAdded();
2033 wxRect r
= GetPropertyRect(p1
, p2
);
2036 m_canvas
->RefreshRect(r
);
2040 // -----------------------------------------------------------------------
2042 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2044 if ( p
== m_selected
)
2045 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2047 DrawItemAndChildren(p
);
2050 // -----------------------------------------------------------------------
2052 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2057 // Draw item, children, and parent too, if it is not category
2058 wxPGProperty
* parent
= p
->GetParent();
2061 !parent
->IsCategory() &&
2062 parent
->GetParent() )
2065 parent
= parent
->GetParent();
2068 DrawItemAndChildren(p
);
2071 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2073 wxCHECK_RET( p
, wxT("invalid property id") );
2075 // Do not draw if in non-visible page
2076 if ( p
->GetParentState() != m_pState
)
2079 // do not draw a single item if multiple pending
2080 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2083 // Update child control.
2084 if ( m_selected
&& m_selected
->GetParent() == p
)
2087 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2089 DrawItems(p
, lastDrawn
);
2092 // -----------------------------------------------------------------------
2094 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2095 const wxRect
*rect
)
2097 PrepareAfterItemsAdded();
2099 wxWindow::Refresh(false);
2101 // TODO: Coordinate translation
2102 m_canvas
->Refresh(false, rect
);
2104 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2105 // I think this really helps only GTK+1.2
2106 if ( m_wndEditor
) m_wndEditor
->Refresh();
2107 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2111 // -----------------------------------------------------------------------
2112 // wxPropertyGrid global operations
2113 // -----------------------------------------------------------------------
2115 void wxPropertyGrid::Clear()
2117 m_pState
->DoClear();
2123 RecalculateVirtualSize();
2125 // Need to clear some area at the end
2127 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2130 // -----------------------------------------------------------------------
2132 bool wxPropertyGrid::EnableCategories( bool enable
)
2134 ClearSelection(false);
2139 // Enable categories
2142 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2147 // Disable categories
2149 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2152 if ( !m_pState
->EnableCategories(enable
) )
2157 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2159 m_pState
->m_itemsAdded
= 1; // force
2160 PrepareAfterItemsAdded();
2164 m_pState
->m_itemsAdded
= 1;
2166 // No need for RecalculateVirtualSize() here - it is already called in
2167 // wxPropertyGridPageState method above.
2174 // -----------------------------------------------------------------------
2176 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2178 wxASSERT( pNewState
);
2179 wxASSERT( pNewState
->GetGrid() );
2181 if ( pNewState
== m_pState
)
2184 wxPGProperty
* oldSelection
= m_selected
;
2186 ClearSelection(false);
2188 m_pState
->m_selected
= oldSelection
;
2190 bool orig_mode
= m_pState
->IsInNonCatMode();
2191 bool new_state_mode
= pNewState
->IsInNonCatMode();
2193 m_pState
= pNewState
;
2196 int pgWidth
= GetClientSize().x
;
2197 if ( HasVirtualWidth() )
2199 int minWidth
= pgWidth
;
2200 if ( pNewState
->m_width
< minWidth
)
2202 pNewState
->m_width
= minWidth
;
2203 pNewState
->CheckColumnWidths();
2209 // Just in case, fully re-center splitter
2210 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2211 pNewState
->m_fSplitterX
= -1.0;
2213 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2218 // If necessary, convert state to correct mode.
2219 if ( orig_mode
!= new_state_mode
)
2221 // This should refresh as well.
2222 EnableCategories( orig_mode
?false:true );
2224 else if ( !m_frozen
)
2226 // Refresh, if not frozen.
2227 m_pState
->PrepareAfterItemsAdded();
2230 if ( m_pState
->m_selected
)
2231 DoSelectProperty( m_pState
->m_selected
);
2233 RecalculateVirtualSize(0);
2237 m_pState
->m_itemsAdded
= 1;
2240 // -----------------------------------------------------------------------
2242 // Call to SetSplitterPosition will always disable splitter auto-centering
2243 // if parent window is shown.
2244 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2246 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2249 wxPropertyGridPageState
* state
= m_pState
;
2251 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2256 CorrectEditorWidgetSizeX();
2262 // -----------------------------------------------------------------------
2264 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2266 SetSplitterPosition( m_width
/2, true );
2267 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2268 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2271 // -----------------------------------------------------------------------
2272 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2273 // -----------------------------------------------------------------------
2275 // Returns nearest paint visible property (such that will be painted unless
2276 // window is scrolled or resized). If given property is paint visible, then
2277 // it itself will be returned
2278 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2280 int vx
,vy1
;// Top left corner of client
2281 GetViewStart(&vx
,&vy1
);
2282 vy1
*= wxPG_PIXELS_PER_UNIT
;
2284 int vy2
= vy1
+ m_height
;
2285 int propY
= p
->GetY2(m_lineHeight
);
2287 if ( (propY
+ m_lineHeight
) < vy1
)
2290 return DoGetItemAtY( vy1
);
2292 else if ( propY
> vy2
)
2295 return DoGetItemAtY( vy2
);
2298 // Itself paint visible
2303 // -----------------------------------------------------------------------
2304 // Methods related to change in value, value modification and sending events
2305 // -----------------------------------------------------------------------
2307 // commits any changes in editor of selected property
2308 // return true if validation did not fail
2309 // flags are same as with DoSelectProperty
2310 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2312 // Committing already?
2313 if ( m_inCommitChangesFromEditor
)
2316 // Don't do this if already processing editor event. It might
2317 // induce recursive dialogs and crap like that.
2318 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2320 if ( m_inDoPropertyChanged
)
2327 IsEditorsValueModified() &&
2328 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2331 m_inCommitChangesFromEditor
= 1;
2333 wxVariant
variant(m_selected
->GetValueRef());
2334 bool valueIsPending
= false;
2336 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2337 // due to another window getting focus
2338 wxWindow
* oldFocus
= m_curFocused
;
2340 bool validationFailure
= false;
2341 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2343 m_chgInfo_changedProperty
= NULL
;
2345 // If truly modified, schedule value as pending.
2346 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2348 if ( DoEditorValidate() &&
2349 PerformValidation(m_selected
, variant
) )
2351 valueIsPending
= true;
2355 validationFailure
= true;
2360 EditorsValueWasNotModified();
2365 m_inCommitChangesFromEditor
= 0;
2367 if ( validationFailure
&& !forceSuccess
)
2371 oldFocus
->SetFocus();
2372 m_curFocused
= oldFocus
;
2375 res
= OnValidationFailure(m_selected
, variant
);
2377 // Now prevent further validation failure messages
2380 EditorsValueWasNotModified();
2381 OnValidationFailureReset(m_selected
);
2384 else if ( valueIsPending
)
2386 DoPropertyChanged( m_selected
, flags
);
2387 EditorsValueWasNotModified();
2396 // -----------------------------------------------------------------------
2398 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2402 // Runs all validation functionality.
2403 // Returns true if value passes all tests.
2406 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2408 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2410 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2415 // Adapt list to child values, if necessary
2416 wxVariant listValue
= pendingValue
;
2417 wxVariant
* pPendingValue
= &pendingValue
;
2418 wxVariant
* pList
= NULL
;
2420 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2421 // string value, then we need treat as it was changed instead
2422 // (or, in addition, as is the case with composite string parent).
2423 // This includes creating list variant for child values.
2425 wxPGProperty
* pwc
= p
->GetParent();
2426 wxPGProperty
* changedProperty
= p
;
2427 wxPGProperty
* baseChangedProperty
= changedProperty
;
2428 wxVariant bcpPendingList
;
2430 listValue
= pendingValue
;
2431 listValue
.SetName(p
->GetBaseName());
2434 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2436 wxVariantList tempList
;
2437 wxVariant
lv(tempList
, pwc
->GetBaseName());
2438 lv
.Append(listValue
);
2440 pPendingValue
= &listValue
;
2442 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2444 baseChangedProperty
= pwc
;
2445 bcpPendingList
= lv
;
2448 changedProperty
= pwc
;
2449 pwc
= pwc
->GetParent();
2453 wxPGProperty
* evtChangingProperty
= changedProperty
;
2455 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2457 value
= *pPendingValue
;
2461 // Convert list to child values
2462 pList
= pPendingValue
;
2463 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2466 wxVariant evtChangingValue
= value
;
2468 if ( flags
& SendEvtChanging
)
2470 // FIXME: After proper ValueToString()s added, remove
2471 // this. It is just a temporary fix, as evt_changing
2472 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2473 // (unless it is selected, and textctrl editor is open).
2474 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2476 evtChangingProperty
= baseChangedProperty
;
2477 if ( evtChangingProperty
!= p
)
2479 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2483 evtChangingValue
= pendingValue
;
2487 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2489 if ( changedProperty
== m_selected
)
2491 wxWindow
* editor
= GetEditorControl();
2492 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2493 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2497 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2502 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2503 m_chgInfo_changedProperty
= changedProperty
;
2504 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2505 m_chgInfo_pendingValue
= value
;
2508 m_chgInfo_valueList
= *pList
;
2510 m_chgInfo_valueList
.MakeNull();
2512 // If changedProperty is not property which value was edited,
2513 // then call wxPGProperty::ValidateValue() for that as well.
2514 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2516 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2520 if ( flags
& SendEvtChanging
)
2522 // SendEvent returns true if event was vetoed
2523 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2527 if ( flags
& IsStandaloneValidation
)
2529 // If called in 'generic' context, we need to reset
2530 // m_chgInfo_changedProperty and write back translated value.
2531 m_chgInfo_changedProperty
= NULL
;
2532 pendingValue
= value
;
2538 // -----------------------------------------------------------------------
2540 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2542 if ( !msg
.length() )
2546 if ( !wxPGGlobalVars
->m_offline
)
2548 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2551 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2554 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2557 pStatusBar
->SetStatusText(msg
);
2565 ::wxMessageBox(msg
, _T("Property Error"));
2568 // -----------------------------------------------------------------------
2570 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2571 wxVariant
& invalidValue
)
2573 wxWindow
* editor
= GetEditorControl();
2575 // First call property's handler
2576 property
->OnValidationFailure(invalidValue
);
2578 bool res
= DoOnValidationFailure(property
, invalidValue
);
2581 // For non-wxTextCtrl editors, we do need to revert the value
2582 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2583 property
== m_selected
)
2585 property
->GetEditorClass()->UpdateControl(property
, editor
);
2588 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2593 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2595 int vfb
= m_validationInfo
.m_failureBehavior
;
2597 if ( vfb
& wxPG_VFB_BEEP
)
2600 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2601 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2603 unsigned int colCount
= m_pState
->GetColumnCount();
2605 // We need backup marked property's cells
2606 m_propCellsBackup
= property
->m_cells
;
2608 wxColour vfbFg
= *wxWHITE
;
2609 wxColour vfbBg
= *wxRED
;
2611 property
->EnsureCells(colCount
);
2613 for ( unsigned int i
=0; i
<colCount
; i
++ )
2615 wxPGCell
& cell
= property
->m_cells
[i
];
2616 cell
.SetFgCol(vfbFg
);
2617 cell
.SetBgCol(vfbBg
);
2620 DrawItemAndChildren(property
);
2622 if ( property
== m_selected
)
2624 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2626 wxWindow
* editor
= GetEditorControl();
2629 editor
->SetForegroundColour(vfbFg
);
2630 editor
->SetBackgroundColour(vfbBg
);
2635 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2637 wxString msg
= m_validationInfo
.m_failureMessage
;
2639 if ( !msg
.length() )
2640 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2642 DoShowPropertyError(property
, msg
);
2645 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2648 // -----------------------------------------------------------------------
2650 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2652 int vfb
= m_validationInfo
.m_failureBehavior
;
2654 if ( vfb
& wxPG_VFB_MARK_CELL
)
2657 property
->m_cells
= m_propCellsBackup
;
2659 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2661 if ( property
== m_selected
&& GetEditorControl() )
2663 // Calling this will recreate the control, thus resetting its colour
2664 RefreshProperty(property
);
2668 DrawItemAndChildren(property
);
2673 // -----------------------------------------------------------------------
2675 // flags are same as with DoSelectProperty
2676 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2678 if ( m_inDoPropertyChanged
)
2681 wxWindow
* editor
= GetEditorControl();
2683 m_pState
->m_anyModified
= 1;
2685 m_inDoPropertyChanged
= 1;
2687 // Maybe need to update control
2688 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2690 // These values were calculated in PerformValidation()
2691 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2692 wxVariant value
= m_chgInfo_pendingValue
;
2694 wxPGProperty
* topPaintedProperty
= changedProperty
;
2696 while ( !topPaintedProperty
->IsCategory() &&
2697 !topPaintedProperty
->IsRoot() )
2699 topPaintedProperty
= topPaintedProperty
->GetParent();
2702 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2704 // Set as Modified (not if dragging just began)
2705 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2707 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2708 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2711 SetCurControlBoldFont();
2717 // Propagate updates to parent(s)
2719 wxPGProperty
* prevPwc
= NULL
;
2721 while ( prevPwc
!= topPaintedProperty
)
2723 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2725 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2728 SetCurControlBoldFont();
2732 pwc
= pwc
->GetParent();
2735 // Draw the actual property
2736 DrawItemAndChildren( topPaintedProperty
);
2739 // If value was set by wxPGProperty::OnEvent, then update the editor
2741 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2747 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2748 if ( m_wndEditor
) m_wndEditor
->Refresh();
2749 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2754 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2756 // If top parent has composite string value, then send to child parents,
2757 // starting from baseChangedProperty.
2758 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2760 pwc
= m_chgInfo_baseChangedProperty
;
2762 while ( pwc
!= changedProperty
)
2764 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2765 pwc
= pwc
->GetParent();
2769 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2771 m_inDoPropertyChanged
= 0;
2776 // -----------------------------------------------------------------------
2778 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2780 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2782 m_chgInfo_changedProperty
= NULL
;
2784 if ( PerformValidation(p
, newValue
) )
2786 DoPropertyChanged(p
);
2791 OnValidationFailure(p
, newValue
);
2797 // -----------------------------------------------------------------------
2799 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2801 wxPGProperty
* prop
= GetSelectedProperty();
2804 return wxNullVariant
;
2806 wxTextCtrl
* tc
= GetEditorTextCtrl();
2807 wxVariant value
= prop
->GetValue();
2809 if ( !tc
|| !IsEditorsValueModified() )
2812 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2815 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2816 return prop
->GetValue();
2821 // -----------------------------------------------------------------------
2823 // Runs wxValidator for the selected property
2824 bool wxPropertyGrid::DoEditorValidate()
2829 // -----------------------------------------------------------------------
2831 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2833 wxPGProperty
* selected
= m_selected
;
2835 // Somehow, event is handled after property has been deselected.
2836 // Possibly, but very rare.
2840 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2843 wxVariant
pendingValue(selected
->GetValueRef());
2844 wxWindow
* wnd
= GetEditorControl();
2845 wxWindow
* editorWnd
= wxDynamicCast(event
.GetEventObject(), wxWindow
);
2847 bool wasUnspecified
= selected
->IsValueUnspecified();
2848 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2849 bool valueIsPending
= false;
2851 m_chgInfo_changedProperty
= NULL
;
2853 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2856 // Filter out excess wxTextCtrl modified events
2857 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2859 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2861 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2863 wxString newTcValue
= tc
->GetValue();
2864 if ( m_prevTcValue
== newTcValue
)
2867 m_prevTcValue
= newTcValue
;
2870 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2872 bool validationFailure
= false;
2873 bool buttonWasHandled
= false;
2876 // Try common button handling
2877 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2879 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2883 buttonWasHandled
= true;
2884 // Store as res2, as previously (and still currently alternatively)
2885 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2886 // in wxPGProperty::OnEvent().
2887 adapter
->ShowDialog( this, selected
);
2892 if ( !buttonWasHandled
)
2894 if ( wnd
|| m_wndEditor2
)
2896 // First call editor class' event handler.
2897 const wxPGEditor
* editor
= selected
->GetEditorClass();
2899 if ( editor
->OnEvent( this, selected
, editorWnd
, event
) )
2901 // If changes, validate them
2902 if ( DoEditorValidate() )
2904 if ( editor
->GetValueFromControl( pendingValue
,
2907 valueIsPending
= true;
2911 validationFailure
= true;
2916 // Then the property's custom handler (must be always called, unless
2917 // validation failed).
2918 if ( !validationFailure
)
2919 buttonWasHandled
= selected
->OnEvent( this, editorWnd
, event
);
2922 // SetValueInEvent(), as called in one of the functions referred above
2923 // overrides editor's value.
2924 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2926 valueIsPending
= true;
2927 pendingValue
= m_changeInEventValue
;
2928 selFlags
|= wxPG_SEL_DIALOGVAL
;
2931 if ( !validationFailure
&& valueIsPending
)
2932 if ( !PerformValidation(m_selected
, pendingValue
) )
2933 validationFailure
= true;
2935 if ( validationFailure
)
2937 OnValidationFailure(selected
, pendingValue
);
2939 else if ( valueIsPending
)
2941 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2943 DoPropertyChanged(selected
, selFlags
);
2944 EditorsValueWasNotModified();
2946 // Regardless of editor type, unfocus editor on
2947 // text-editing related enter press.
2948 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2955 // No value after all
2957 // Regardless of editor type, unfocus editor on
2958 // text-editing related enter press.
2959 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2964 // Let unhandled button click events go to the parent
2965 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2967 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2968 GetEventHandler()->AddPendingEvent(evt
);
2972 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2975 // -----------------------------------------------------------------------
2976 // wxPropertyGrid editor control helper methods
2977 // -----------------------------------------------------------------------
2979 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
2981 int itemy
= p
->GetY2(m_lineHeight
);
2983 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2984 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2985 int imageOffset
= 0;
2987 // TODO: If custom image detection changes from current, change this.
2988 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
)
2990 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
2991 int iw
= p
->OnMeasureImage().x
;
2993 iw
= wxPG_CUSTOM_IMAGE_WIDTH
;
2994 imageOffset
= p
->GetImageOffset(iw
);
2999 splitterX
+imageOffset
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3001 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-imageOffset
-1,
3006 // -----------------------------------------------------------------------
3008 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3010 wxSize sz
= GetImageSize(p
, item
);
3011 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3012 wxPG_CUSTOM_IMAGE_SPACINGY
,
3017 // return size of custom paint image
3018 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3020 // If called with NULL property, then return default image
3021 // size for properties that use image.
3023 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3025 wxSize cis
= p
->OnMeasureImage(item
);
3027 int choiceCount
= p
->m_choices
.GetCount();
3028 int comVals
= p
->GetDisplayedCommonValueCount();
3029 if ( item
>= choiceCount
&& comVals
> 0 )
3031 unsigned int cvi
= item
-choiceCount
;
3032 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3034 else if ( item
>= 0 && choiceCount
== 0 )
3035 return wxSize(0, 0);
3040 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3045 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3052 // -----------------------------------------------------------------------
3054 // takes scrolling into account
3055 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3058 GetViewStart(&vx
,&vy
);
3059 vy
*=wxPG_PIXELS_PER_UNIT
;
3060 vx
*=wxPG_PIXELS_PER_UNIT
;
3063 ClientToScreen( px
, py
);
3066 // -----------------------------------------------------------------------
3068 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3071 GetViewStart(&pt2
.x
,&pt2
.y
);
3072 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3073 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3077 return m_pState
->HitTest(pt2
);
3080 // -----------------------------------------------------------------------
3082 // custom set cursor
3083 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3085 if ( type
== m_curcursor
&& !override
) return;
3087 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3089 if ( type
== wxCURSOR_SIZEWE
)
3090 cursor
= m_cursorSizeWE
;
3092 m_canvas
->SetCursor( *cursor
);
3097 // -----------------------------------------------------------------------
3098 // wxPropertyGrid property selection, editor creation
3099 // -----------------------------------------------------------------------
3102 // This class forwards events from property editor controls to wxPropertyGrid.
3103 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3106 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3107 : wxEvtHandler(), m_propGrid(propGrid
)
3111 virtual ~wxPropertyGridEditorEventForwarder()
3116 bool ProcessEvent( wxEvent
& event
)
3121 m_propGrid
->HandleCustomEditorEvent(event
);
3123 return wxEvtHandler::ProcessEvent(event
);
3126 wxPropertyGrid
* m_propGrid
;
3129 // Setups event handling for child control
3130 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3132 wxWindowID id
= argWnd
->GetId();
3134 if ( argWnd
== m_wndEditor
)
3136 argWnd
->Connect(id
, wxEVT_MOTION
,
3137 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3139 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3140 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3142 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3143 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3145 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3146 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3148 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3149 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3151 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3152 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3156 wxPropertyGridEditorEventForwarder
* forwarder
;
3157 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3158 argWnd
->PushEventHandler(forwarder
);
3160 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3161 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3165 void wxPropertyGrid::FreeEditors()
3168 // Return focus back to canvas from children (this is required at least for
3169 // GTK+, which, unlike Windows, clears focus when control is destroyed
3170 // instead of moving it to closest parent).
3171 wxWindow
* focus
= wxWindow::FindFocus();
3174 wxWindow
* parent
= focus
->GetParent();
3177 if ( parent
== m_canvas
)
3182 parent
= parent
->GetParent();
3186 // Do not free editors immediately if processing events
3189 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3190 m_wndEditor2
->Hide();
3191 wxPendingDelete
.Append( handler
);
3192 wxPendingDelete
.Append( m_wndEditor2
);
3193 m_wndEditor2
= NULL
;
3198 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3199 m_wndEditor
->Hide();
3200 wxPendingDelete
.Append( handler
);
3201 wxPendingDelete
.Append( m_wndEditor
);
3206 // Call with NULL to de-select property
3207 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3211 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3212 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3214 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3217 if ( m_inDoSelectProperty
)
3220 m_inDoSelectProperty
= 1;
3222 wxPGProperty
* prev
= m_selected
;
3226 m_inDoSelectProperty
= 0;
3232 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3234 wxPrintf( "None selected\n" );
3237 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3239 wxPrintf( "P = NULL\n" );
3242 // If we are frozen, then just set the values.
3245 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3246 m_editorFocused
= 0;
3249 m_pState
->m_selected
= p
;
3251 // If frozen, always free controls. But don't worry, as Thaw will
3252 // recall SelectProperty to recreate them.
3255 // Prevent any further selection measures in this call
3261 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3263 // Only set focus if not deselecting
3266 if ( flags
& wxPG_SEL_FOCUS
)
3270 m_wndEditor
->SetFocus();
3271 m_editorFocused
= 1;
3280 m_inDoSelectProperty
= 0;
3285 // First, deactivate previous
3289 OnValidationFailureReset(m_selected
);
3291 // Must double-check if this is an selected in case of forceswitch
3294 if ( !CommitChangesFromEditor(flags
) )
3296 // Validation has failed, so we can't exit the previous editor
3297 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3298 // _("Invalid Value"),wxOK|wxICON_ERROR);
3299 m_inDoSelectProperty
= 0;
3308 m_pState
->m_selected
= NULL
;
3310 // We need to always fully refresh the grid here
3313 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3314 EditorsValueWasNotModified();
3317 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3320 // Then, activate the one given.
3323 int propY
= p
->GetY2(m_lineHeight
);
3325 int splitterX
= GetSplitterPosition();
3326 m_editorFocused
= 0;
3328 m_pState
->m_selected
= p
;
3329 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3331 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3333 wxASSERT( m_wndEditor
== NULL
);
3336 // Only create editor for non-disabled non-caption
3337 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3339 // do this for non-caption items
3343 // Do we need to paint the custom image, if any?
3344 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3345 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3346 !p
->GetEditorClass()->CanContainCustomImage()
3348 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3350 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3351 wxPoint goodPos
= grect
.GetPosition();
3352 #if wxPG_CREATE_CONTROLS_HIDDEN
3353 int coord_adjust
= m_height
- goodPos
.y
;
3354 goodPos
.y
+= coord_adjust
;
3357 const wxPGEditor
* editor
= p
->GetEditorClass();
3358 wxCHECK_MSG(editor
, false,
3359 wxT("NULL editor class not allowed"));
3361 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3363 wxPGWindowList wndList
= editor
->CreateControls(this,
3368 m_wndEditor
= wndList
.m_primary
;
3369 m_wndEditor2
= wndList
.m_secondary
;
3370 wxWindow
* primaryCtrl
= GetEditorControl();
3373 // Essentially, primaryCtrl == m_wndEditor
3376 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3377 // value is drawn as normal, and m_wndEditor2 is assumed
3378 // to be a right-aligned button that triggers a separate editorCtrl
3383 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3384 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3386 // Set validator, if any
3387 #if wxUSE_VALIDATORS
3388 wxValidator
* validator
= p
->GetValidator();
3390 primaryCtrl
->SetValidator(*validator
);
3393 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3394 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3396 // If it has modified status, use bold font
3397 // (must be done before capturing m_ctrlXAdjust)
3398 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3399 SetCurControlBoldFont();
3402 // Fix TextCtrl indentation
3403 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3404 wxTextCtrl
* tc
= NULL
;
3405 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3406 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3408 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3410 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3413 // Store x relative to splitter (we'll need it).
3414 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3416 // Check if background clear is not necessary
3417 wxPoint pos
= m_wndEditor
->GetPosition();
3418 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3420 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3423 m_wndEditor
->SetSizeHints(3, 3);
3425 #if wxPG_CREATE_CONTROLS_HIDDEN
3426 m_wndEditor
->Show(false);
3427 m_wndEditor
->Freeze();
3429 goodPos
= m_wndEditor
->GetPosition();
3430 goodPos
.y
-= coord_adjust
;
3431 m_wndEditor
->Move( goodPos
);
3434 SetupChildEventHandling(primaryCtrl
);
3436 // Focus and select all (wxTextCtrl, wxComboBox etc)
3437 if ( flags
& wxPG_SEL_FOCUS
)
3439 primaryCtrl
->SetFocus();
3441 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3447 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3448 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3450 // Get proper id for wndSecondary
3451 m_wndSecId
= m_wndEditor2
->GetId();
3452 wxWindowList children
= m_wndEditor2
->GetChildren();
3453 wxWindowList::iterator node
= children
.begin();
3454 if ( node
!= children
.end() )
3455 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3457 m_wndEditor2
->SetSizeHints(3,3);
3459 #if wxPG_CREATE_CONTROLS_HIDDEN
3460 wxRect sec_rect
= m_wndEditor2
->GetRect();
3461 sec_rect
.y
-= coord_adjust
;
3463 // Fine tuning required to fix "oversized"
3464 // button disappearance bug.
3465 if ( sec_rect
.y
< 0 )
3467 sec_rect
.height
+= sec_rect
.y
;
3470 m_wndEditor2
->SetSize( sec_rect
);
3472 m_wndEditor2
->Show();
3474 SetupChildEventHandling(m_wndEditor2
);
3476 // If no primary editor, focus to button to allow
3477 // it to interprete ENTER etc.
3478 // NOTE: Due to problems focusing away from it, this
3479 // has been disabled.
3481 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3482 m_wndEditor2->SetFocus();
3486 if ( flags
& wxPG_SEL_FOCUS
)
3487 m_editorFocused
= 1;
3492 // Make sure focus is in grid canvas (important for wxGTK, at least)
3496 EditorsValueWasNotModified();
3498 // If it's inside collapsed section, expand parent, scroll, etc.
3499 // Also, if it was partially visible, scroll it into view.
3500 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3505 #if wxPG_CREATE_CONTROLS_HIDDEN
3506 m_wndEditor
->Thaw();
3508 m_wndEditor
->Show(true);
3515 // Make sure focus is in grid canvas
3519 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3525 // Show help text in status bar.
3526 // (if found and grid not embedded in manager with help box and
3527 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3530 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3532 wxStatusBar
* statusbar
= NULL
;
3533 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3535 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3537 statusbar
= frame
->GetStatusBar();
3542 const wxString
* pHelpString
= (const wxString
*) NULL
;
3546 pHelpString
= &p
->GetHelpString();
3547 if ( pHelpString
->length() )
3549 // Set help box text.
3550 statusbar
->SetStatusText( *pHelpString
);
3551 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3555 if ( (!pHelpString
|| !pHelpString
->length()) &&
3556 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3558 // Clear help box - but only if it was written
3559 // by us at previous time.
3560 statusbar
->SetStatusText( m_emptyString
);
3561 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3567 m_inDoSelectProperty
= 0;
3569 // call wx event handler (here so that it also occurs on deselection)
3570 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3575 // -----------------------------------------------------------------------
3577 bool wxPropertyGrid::UnfocusEditor()
3579 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3582 if ( !CommitChangesFromEditor(0) )
3586 DrawItem(m_selected
);
3591 // -----------------------------------------------------------------------
3593 void wxPropertyGrid::RefreshEditor()
3595 wxPGProperty
* p
= m_selected
;
3599 wxWindow
* wnd
= GetEditorControl();
3603 // Set editor font boldness - must do this before
3604 // calling UpdateControl().
3605 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3607 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3608 wnd
->SetFont(GetCaptionFont());
3610 wnd
->SetFont(GetFont());
3613 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3615 editorClass
->UpdateControl(p
, wnd
);
3617 if ( p
->IsValueUnspecified() )
3618 editorClass
->SetValueToUnspecified(p
, wnd
);
3621 // -----------------------------------------------------------------------
3623 // This method is not inline because it called dozens of times
3624 // (i.e. two-arg function calls create smaller code size).
3625 bool wxPropertyGrid::DoClearSelection()
3627 return DoSelectProperty(NULL
);
3630 // -----------------------------------------------------------------------
3631 // wxPropertyGrid expand/collapse state
3632 // -----------------------------------------------------------------------
3634 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3636 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3638 // If active editor was inside collapsed section, then disable it
3639 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3641 ClearSelection(false);
3644 // Store dont-center-splitter flag 'cause we need to temporarily set it
3645 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3646 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3648 bool res
= m_pState
->DoCollapse(pwc
);
3653 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3655 RecalculateVirtualSize();
3657 // Redraw etc. only if collapsed was visible.
3658 if (pwc
->IsVisible() &&
3660 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3662 // When item is collapsed so that scrollbar would move,
3663 // graphics mess is about (unless we redraw everything).
3668 // Clear dont-center-splitter flag if it wasn't set
3669 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3674 // -----------------------------------------------------------------------
3676 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3678 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3680 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3682 // Store dont-center-splitter flag 'cause we need to temporarily set it
3683 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3684 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3686 bool res
= m_pState
->DoExpand(pwc
);
3691 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3693 RecalculateVirtualSize();
3695 // Redraw etc. only if expanded was visible.
3696 if ( pwc
->IsVisible() && !m_frozen
&&
3697 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3701 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3704 DrawItems(pwc
, NULL
);
3709 // Clear dont-center-splitter flag if it wasn't set
3710 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3715 // -----------------------------------------------------------------------
3717 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3720 return m_pState
->DoHideProperty(p
, hide
, flags
);
3723 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3726 ClearSelection(false);
3729 m_pState
->DoHideProperty(p
, hide
, flags
);
3731 RecalculateVirtualSize();
3738 // -----------------------------------------------------------------------
3739 // wxPropertyGrid size related methods
3740 // -----------------------------------------------------------------------
3742 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3744 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3748 // If virtual height was changed, then recalculate editor control position(s)
3749 if ( m_pState
->m_vhCalcPending
)
3750 CorrectEditorWidgetPosY();
3752 m_pState
->EnsureVirtualHeight();
3755 int by1
= m_pState
->GetVirtualHeight();
3756 int by2
= m_pState
->GetActualVirtualHeight();
3759 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3760 wxFAIL_MSG(s
.c_str());
3765 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3767 int x
= m_pState
->m_width
;
3768 int y
= m_pState
->m_virtualHeight
;
3771 GetClientSize(&width
,&height
);
3773 // Now adjust virtual size.
3774 SetVirtualSize(x
, y
);
3780 // Adjust scrollbars
3781 if ( HasVirtualWidth() )
3783 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3784 xPos
= GetScrollPos( wxHORIZONTAL
);
3787 if ( forceXPos
!= -1 )
3790 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3793 int yAmount
= y
/ wxPG_PIXELS_PER_UNIT
;
3794 int yPos
= GetScrollPos( wxVERTICAL
);
3796 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3797 xAmount
, yAmount
, xPos
, yPos
, true );
3799 // Must re-get size now
3800 GetClientSize(&width
,&height
);
3802 if ( !HasVirtualWidth() )
3804 m_pState
->SetVirtualWidth(width
);
3811 m_canvas
->SetSize( x
, y
);
3813 m_pState
->CheckColumnWidths();
3816 CorrectEditorWidgetSizeX();
3818 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3821 // -----------------------------------------------------------------------
3823 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3825 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3829 GetClientSize(&width
,&height
);
3834 #if wxPG_DOUBLE_BUFFER
3835 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3837 int dblh
= (m_lineHeight
*2);
3838 if ( !m_doubleBuffer
)
3840 // Create double buffer bitmap to draw on, if none
3841 int w
= (width
>250)?width
:250;
3842 int h
= height
+ dblh
;
3844 m_doubleBuffer
= new wxBitmap( w
, h
);
3848 int w
= m_doubleBuffer
->GetWidth();
3849 int h
= m_doubleBuffer
->GetHeight();
3851 // Double buffer must be large enough
3852 if ( w
< width
|| h
< (height
+dblh
) )
3854 if ( w
< width
) w
= width
;
3855 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3856 delete m_doubleBuffer
;
3857 m_doubleBuffer
= new wxBitmap( w
, h
);
3864 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3865 m_ncWidth
= event
.GetSize().x
;
3869 if ( m_pState
->m_itemsAdded
)
3870 PrepareAfterItemsAdded();
3872 // Without this, virtual size (atleast under wxGTK) will be skewed
3873 RecalculateVirtualSize();
3879 // -----------------------------------------------------------------------
3881 void wxPropertyGrid::SetVirtualWidth( int width
)
3885 // Disable virtual width
3886 width
= GetClientSize().x
;
3887 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3891 // Enable virtual width
3892 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3894 m_pState
->SetVirtualWidth( width
);
3897 void wxPropertyGrid::SetFocusOnCanvas()
3899 m_canvas
->SetFocusIgnoringChildren();
3900 m_editorFocused
= 0;
3903 // -----------------------------------------------------------------------
3904 // wxPropertyGrid mouse event handling
3905 // -----------------------------------------------------------------------
3907 // selFlags uses same values DoSelectProperty's flags
3908 // Returns true if event was vetoed.
3909 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3911 // Send property grid event of specific type and with specific property
3912 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3913 evt
.SetPropertyGrid(this);
3914 evt
.SetEventObject(m_eventObject
);
3918 evt
.SetCanVeto(true);
3919 evt
.SetupValidationInfo();
3920 m_validationInfo
.m_pValue
= pValue
;
3922 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3924 evtHandler
->ProcessEvent(evt
);
3926 return evt
.WasVetoed();
3929 // -----------------------------------------------------------------------
3931 // Return false if should be skipped
3932 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3936 // Need to set focus?
3937 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3942 wxPropertyGridPageState
* state
= m_pState
;
3944 int splitterHitOffset
;
3945 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3947 wxPGProperty
* p
= DoGetItemAtY(y
);
3951 int depth
= (int)p
->GetDepth() - 1;
3953 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3955 if ( x
>= marginEnds
)
3959 if ( p
->IsCategory() )
3961 // This is category.
3962 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3964 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3966 // Expand, collapse, activate etc. if click on text or left of splitter.
3969 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3974 if ( !DoSelectProperty( p
) )
3977 // On double-click, expand/collapse.
3978 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3980 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3981 else DoExpand( p
, true );
3985 else if ( splitterHit
== -1 )
3988 unsigned int selFlag
= 0;
3989 if ( columnHit
== 1 )
3991 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3992 selFlag
= wxPG_SEL_FOCUS
;
3994 if ( !DoSelectProperty( p
, selFlag
) )
3997 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
3999 if ( p
->GetChildCount() && !p
->IsCategory() )
4000 // On double-click, expand/collapse.
4001 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4003 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4004 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4005 else DoExpand( p
, true );
4012 // click on splitter
4013 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4015 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4017 // Double-clicking the splitter causes auto-centering
4018 CenterSplitter( true );
4020 else if ( m_dragStatus
== 0 )
4023 // Begin draggin the splitter
4027 // Changes must be committed here or the
4028 // value won't be drawn correctly
4029 if ( !CommitChangesFromEditor() )
4032 m_wndEditor
->Show ( false );
4035 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4037 m_canvas
->CaptureMouse();
4038 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4042 m_draggedSplitter
= splitterHit
;
4043 m_dragOffset
= splitterHitOffset
;
4045 wxClientDC
dc(m_canvas
);
4047 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4048 // Fixes button disappearance bug
4050 m_wndEditor2
->Show ( false );
4053 m_startingSplitterX
= x
- splitterHitOffset
;
4061 if ( p
->GetChildCount() )
4063 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4065 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4067 int y2
= y
% m_lineHeight
;
4068 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4070 // On click on expander button, expand/collapse
4071 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4072 DoCollapse( p
, true );
4074 DoExpand( p
, true );
4083 // -----------------------------------------------------------------------
4085 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4086 wxMouseEvent
& WXUNUSED(event
) )
4090 // Select property here as well
4091 wxPGProperty
* p
= m_propHover
;
4092 if ( p
!= m_selected
)
4093 DoSelectProperty( p
);
4095 // Send right click event.
4096 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4103 // -----------------------------------------------------------------------
4105 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4106 wxMouseEvent
& WXUNUSED(event
) )
4110 // Select property here as well
4111 wxPGProperty
* p
= m_propHover
;
4113 if ( p
!= m_selected
)
4114 DoSelectProperty( p
);
4116 // Send double-click event.
4117 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4124 // -----------------------------------------------------------------------
4126 #if wxPG_SUPPORT_TOOLTIPS
4128 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4130 if ( tipString
.length() )
4132 m_canvas
->SetToolTip(tipString
);
4136 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4137 m_canvas
->SetToolTip( m_emptyString
);
4139 m_canvas
->SetToolTip( NULL
);
4144 #endif // #if wxPG_SUPPORT_TOOLTIPS
4146 // -----------------------------------------------------------------------
4148 // Return false if should be skipped
4149 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4151 // Safety check (needed because mouse capturing may
4152 // otherwise freeze the control)
4153 if ( m_dragStatus
> 0 && !event
.Dragging() )
4155 HandleMouseUp(x
,y
,event
);
4158 wxPropertyGridPageState
* state
= m_pState
;
4160 int splitterHitOffset
;
4161 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4162 int splitterX
= x
- splitterHitOffset
;
4164 if ( m_dragStatus
> 0 )
4166 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4167 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4170 int newSplitterX
= x
- m_dragOffset
;
4171 int splitterX
= x
- splitterHitOffset
;
4173 // Splitter redraw required?
4174 if ( newSplitterX
!= splitterX
)
4177 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4178 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4179 state
->m_fSplitterX
= (float) newSplitterX
;
4182 CorrectEditorWidgetSizeX();
4196 int ih
= m_lineHeight
;
4199 #if wxPG_SUPPORT_TOOLTIPS
4200 wxPGProperty
* prevHover
= m_propHover
;
4201 unsigned char prevSide
= m_mouseSide
;
4203 int curPropHoverY
= y
- (y
% ih
);
4205 // On which item it hovers
4208 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4211 // Mouse moves on another property
4213 m_propHover
= DoGetItemAtY(y
);
4214 m_propHoverY
= curPropHoverY
;
4217 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4220 #if wxPG_SUPPORT_TOOLTIPS
4221 // Store which side we are on
4223 if ( columnHit
== 1 )
4225 else if ( columnHit
== 0 )
4229 // If tooltips are enabled, show label or value as a tip
4230 // in case it doesn't otherwise show in full length.
4232 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4234 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4236 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4238 if ( m_propHover
&& !m_propHover
->IsCategory() )
4241 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4243 // Show help string as a tooltip
4244 wxString tipString
= m_propHover
->GetHelpString();
4246 SetToolTip(tipString
);
4250 // Show cropped value string as a tooltip
4254 if ( m_mouseSide
== 1 )
4256 tipString
= m_propHover
->m_label
;
4257 space
= splitterX
-m_marginWidth
-3;
4259 else if ( m_mouseSide
== 2 )
4261 tipString
= m_propHover
->GetDisplayedString();
4263 space
= m_width
- splitterX
;
4264 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4265 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4271 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4274 SetToolTip( tipString
);
4281 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4282 m_canvas
->SetToolTip( m_emptyString
);
4284 m_canvas
->SetToolTip( NULL
);
4295 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4296 m_canvas
->SetToolTip( m_emptyString
);
4298 m_canvas
->SetToolTip( NULL
);
4306 if ( splitterHit
== -1 ||
4308 HasFlag(wxPG_STATIC_SPLITTER
) )
4310 // hovering on something else
4311 if ( m_curcursor
!= wxCURSOR_ARROW
)
4312 CustomSetCursor( wxCURSOR_ARROW
);
4316 // Do not allow splitter cursor on caption items.
4317 // (also not if we were dragging and its started
4318 // outside the splitter region)
4320 if ( !m_propHover
->IsCategory() &&
4324 // hovering on splitter
4326 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4327 // reliably detected.
4328 //if ( m_curcursor != wxCURSOR_SIZEWE )
4329 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4335 // hovering on something else
4336 if ( m_curcursor
!= wxCURSOR_ARROW
)
4337 CustomSetCursor( wxCURSOR_ARROW
);
4344 // -----------------------------------------------------------------------
4346 // Also handles Leaving event
4347 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4348 wxMouseEvent
&WXUNUSED(event
) )
4350 wxPropertyGridPageState
* state
= m_pState
;
4354 int splitterHitOffset
;
4355 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4357 // No event type check - basicly calling this method should
4358 // just stop dragging.
4359 // Left up after dragged?
4360 if ( m_dragStatus
>= 1 )
4363 // End Splitter Dragging
4365 // DO NOT ENABLE FOLLOWING LINE!
4366 // (it is only here as a reminder to not to do it)
4369 // Disable splitter auto-centering
4370 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4372 // This is necessary to return cursor
4373 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4375 m_canvas
->ReleaseMouse();
4376 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4379 // Set back the default cursor, if necessary
4380 if ( splitterHit
== -1 ||
4383 CustomSetCursor( wxCURSOR_ARROW
);
4388 // Control background needs to be cleared
4389 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4390 DrawItem( m_selected
);
4394 m_wndEditor
->Show ( true );
4397 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4398 // Fixes button disappearance bug
4400 m_wndEditor2
->Show ( true );
4403 // This clears the focus.
4404 m_editorFocused
= 0;
4410 // -----------------------------------------------------------------------
4412 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4414 int splitterX
= GetSplitterPosition();
4417 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4421 wxWindow
* wnd
= GetEditorControl();
4423 // Hide popup on clicks
4424 if ( event
.GetEventType() != wxEVT_MOTION
)
4425 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4427 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4433 if ( wnd
== NULL
|| m_dragStatus
||
4435 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4436 ux
>= (r
.x
+r
.width
) ||
4438 event
.m_y
>= (r
.y
+r
.height
)
4448 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4453 // -----------------------------------------------------------------------
4455 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4458 if ( OnMouseCommon( event
, &x
, &y
) )
4460 HandleMouseClick(x
,y
,event
);
4465 // -----------------------------------------------------------------------
4467 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4470 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4471 HandleMouseRightClick(x
,y
,event
);
4475 // -----------------------------------------------------------------------
4477 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4479 // Always run standard mouse-down handler as well
4480 OnMouseClick(event
);
4483 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4484 HandleMouseDoubleClick(x
,y
,event
);
4488 // -----------------------------------------------------------------------
4490 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4493 if ( OnMouseCommon( event
, &x
, &y
) )
4495 HandleMouseMove(x
,y
,event
);
4500 // -----------------------------------------------------------------------
4502 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4504 // Called when mouse moves in the empty space below the properties.
4505 CustomSetCursor( wxCURSOR_ARROW
);
4508 // -----------------------------------------------------------------------
4510 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4513 if ( OnMouseCommon( event
, &x
, &y
) )
4515 HandleMouseUp(x
,y
,event
);
4520 // -----------------------------------------------------------------------
4522 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4524 // This may get called from child control as well, so event's
4525 // mouse position cannot be relied on.
4527 if ( event
.Entering() )
4529 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4531 // TODO: Fix this (detect parent and only do
4532 // cursor trick if it is a manager).
4533 wxASSERT( GetParent() );
4534 GetParent()->SetCursor(wxNullCursor
);
4536 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4539 GetParent()->SetCursor(wxNullCursor
);
4541 else if ( event
.Leaving() )
4543 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4544 m_canvas
->SetCursor( wxNullCursor
);
4546 // Get real cursor position
4547 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4549 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4552 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4554 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4558 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4566 // -----------------------------------------------------------------------
4568 // Common code used by various OnMouseXXXChild methods.
4569 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4571 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4572 wxASSERT( topCtrlWnd
);
4574 event
.GetPosition(&x
,&y
);
4576 int splitterX
= GetSplitterPosition();
4578 wxRect r
= topCtrlWnd
->GetRect();
4579 if ( !m_dragStatus
&&
4580 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4581 y
>= 0 && y
< r
.height \
4584 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4589 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4596 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4599 if ( OnMouseChildCommon(event
,&x
,&y
) )
4601 bool res
= HandleMouseClick(x
,y
,event
);
4602 if ( !res
) event
.Skip();
4606 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4609 wxASSERT( m_wndEditor
);
4610 // These coords may not be exact (about +-2),
4611 // but that should not matter (right click is about item, not position).
4612 wxPoint pt
= m_wndEditor
->GetPosition();
4613 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4614 wxASSERT( m_selected
);
4615 m_propHover
= m_selected
;
4616 bool res
= HandleMouseRightClick(x
,y
,event
);
4617 if ( !res
) event
.Skip();
4620 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4623 if ( OnMouseChildCommon(event
,&x
,&y
) )
4625 bool res
= HandleMouseMove(x
,y
,event
);
4626 if ( !res
) event
.Skip();
4630 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4633 if ( OnMouseChildCommon(event
,&x
,&y
) )
4635 bool res
= HandleMouseUp(x
,y
,event
);
4636 if ( !res
) event
.Skip();
4640 // -----------------------------------------------------------------------
4641 // wxPropertyGrid keyboard event handling
4642 // -----------------------------------------------------------------------
4644 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4646 // Translates wxKeyEvent to wxPG_ACTION_XXX
4648 int keycode
= event
.GetKeyCode();
4649 int modifiers
= event
.GetModifiers();
4651 wxASSERT( !(modifiers
&~(0xFFFF)) );
4653 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4655 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4657 if ( it
== m_actionTriggers
.end() )
4662 int second
= (it
->second
>>16) & 0xFFFF;
4666 return (it
->second
& 0xFFFF);
4669 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4671 wxASSERT( !(modifiers
&~(0xFFFF)) );
4673 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4675 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4677 if ( it
!= m_actionTriggers
.end() )
4679 // This key combination is already used
4681 // Can add secondary?
4682 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4683 wxT("You can only add up to two separate actions per key combination.") );
4685 action
= it
->second
| (action
<<16);
4688 m_actionTriggers
[hashMapKey
] = action
;
4691 void wxPropertyGrid::ClearActionTriggers( int action
)
4693 wxPGHashMapI2I::iterator it
;
4695 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4697 if ( it
->second
== action
)
4699 m_actionTriggers
.erase(it
);
4704 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4707 // Handles key event when editor control is not focused.
4710 wxCHECK2(!m_frozen
, return);
4712 // Travelsal between items, collapsing/expanding, etc.
4713 int keycode
= event
.GetKeyCode();
4714 bool editorFocused
= IsEditorFocused();
4716 if ( keycode
== WXK_TAB
)
4718 wxWindow
* mainControl
;
4720 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4721 mainControl
= GetParent();
4725 if ( !event
.ShiftDown() )
4727 if ( !editorFocused
&& m_wndEditor
)
4729 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4733 // Tab traversal workaround for platforms on which
4734 // wxWindow::Navigate() may navigate into first child
4735 // instead of next sibling. Does not work perfectly
4736 // in every scenario (for instance, when property grid
4737 // is either first or last control).
4738 #if defined(__WXGTK__)
4739 wxWindow
* sibling
= mainControl
->GetNextSibling();
4741 sibling
->SetFocusFromKbd();
4743 Navigate(wxNavigationKeyEvent::IsForward
);
4749 if ( editorFocused
)
4755 #if defined(__WXGTK__)
4756 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4758 sibling
->SetFocusFromKbd();
4760 Navigate(wxNavigationKeyEvent::IsBackward
);
4768 // Ignore Alt and Control when they are down alone
4769 if ( keycode
== WXK_ALT
||
4770 keycode
== WXK_CONTROL
)
4777 int action
= KeyEventToActions(event
, &secondAction
);
4779 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4782 // Esc cancels any changes
4783 if ( IsEditorsValueModified() )
4785 EditorsValueWasNotModified();
4787 // Update the control as well
4788 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4790 m_selected
->GetDisplayedString() );
4793 OnValidationFailureReset(m_selected
);
4799 // Except for TAB and ESC, handle child control events in child control
4802 // Only propagate event if it had modifiers
4803 if ( !event
.HasModifiers() )
4805 event
.StopPropagation();
4811 bool wasHandled
= false;
4816 if ( ButtonTriggerKeyTest(action
, event
) )
4819 wxPGProperty
* p
= m_selected
;
4821 // Travel and expand/collapse
4824 if ( p
->GetChildCount() &&
4825 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4828 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4830 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4833 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4835 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4842 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4846 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4852 if ( selectDir
>= -1 )
4854 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4856 DoSelectProperty(p
);
4862 // If nothing was selected, select the first item now
4863 // (or navigate out of tab).
4864 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4866 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4867 if ( p
) DoSelectProperty(p
);
4876 // -----------------------------------------------------------------------
4878 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4880 // If there was editor open and focused, then this event should not
4881 // really be processed here.
4882 if ( IsEditorFocused() )
4884 // However, if event had modifiers, it is probably still best
4886 if ( event
.HasModifiers() )
4889 event
.StopPropagation();
4893 HandleKeyEvent(event
, false);
4896 // -----------------------------------------------------------------------
4898 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4903 action
= KeyEventToActions(event
, &secondAction
);
4906 // Does the keycode trigger button?
4907 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4910 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4911 GetEventHandler()->AddPendingEvent(evt
);
4918 // -----------------------------------------------------------------------
4920 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4922 HandleKeyEvent(event
, true);
4925 // -----------------------------------------------------------------------
4926 // wxPropertyGrid miscellaneous event handling
4927 // -----------------------------------------------------------------------
4929 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4932 // Check if the focus is in this control or one of its children
4933 wxWindow
* newFocused
= wxWindow::FindFocus();
4935 if ( newFocused
!= m_curFocused
)
4936 HandleFocusChange( newFocused
);
4939 bool wxPropertyGrid::IsEditorFocused() const
4941 wxWindow
* focus
= wxWindow::FindFocus();
4943 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4944 focus
== GetEditorControl() )
4950 // Called by focus event handlers. newFocused is the window that becomes focused.
4951 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4953 unsigned int oldFlags
= m_iFlags
;
4955 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4957 wxWindow
* parent
= newFocused
;
4959 // This must be one of nextFocus' parents.
4962 // Use m_eventObject, which is either wxPropertyGrid or
4963 // wxPropertyGridManager, as appropriate.
4964 if ( parent
== m_eventObject
)
4966 m_iFlags
|= wxPG_FL_FOCUSED
;
4969 parent
= parent
->GetParent();
4972 m_curFocused
= newFocused
;
4974 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4975 (oldFlags
& wxPG_FL_FOCUSED
) )
4977 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4979 // Need to store changed value
4980 CommitChangesFromEditor();
4986 // Preliminary code for tab-order respecting
4987 // tab-traversal (but should be moved to
4990 wxWindow* prevFocus = event.GetWindow();
4991 wxWindow* useThis = this;
4992 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4993 useThis = GetParent();
4996 prevFocus->GetParent() == useThis->GetParent() )
4998 wxList& children = useThis->GetParent()->GetChildren();
5000 wxNode* node = children.Find(prevFocus);
5002 if ( node->GetNext() &&
5003 useThis == node->GetNext()->GetData() )
5004 DoSelectProperty(GetFirst());
5005 else if ( node->GetPrevious () &&
5006 useThis == node->GetPrevious()->GetData() )
5007 DoSelectProperty(GetLastProperty());
5014 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5015 DrawItem( m_selected
);
5019 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5021 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5022 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5023 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5024 //else if ( event.GetWindow() )
5026 HandleFocusChange(event
.GetWindow());
5031 // -----------------------------------------------------------------------
5033 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5035 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5039 // -----------------------------------------------------------------------
5041 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5043 m_iFlags
|= wxPG_FL_SCROLLED
;
5048 // -----------------------------------------------------------------------
5050 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5052 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5054 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5058 // -----------------------------------------------------------------------
5059 // Property editor related functions
5060 // -----------------------------------------------------------------------
5062 // noDefCheck = true prevents infinite recursion.
5063 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5066 wxASSERT( editorClass
);
5068 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5069 RegisterDefaultEditors();
5071 wxString name
= editorClass
->GetName();
5073 // Existing editor under this name?
5074 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5076 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5078 // If this name was already used, try class name.
5079 name
= editorClass
->GetClassInfo()->GetClassName();
5080 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5083 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5084 (wxPGEditor
*) vt_it
->second
,
5085 "Editor with given name was already registered" );
5087 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5092 // Use this in RegisterDefaultEditors.
5093 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5094 if ( wxPGEditor_##EDITOR == NULL ) \
5096 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5097 new wxPG##EDITOR##Editor, true ); \
5100 // Registers all default editor classes
5101 void wxPropertyGrid::RegisterDefaultEditors()
5103 wxPGRegisterDefaultEditorClass( TextCtrl
);
5104 wxPGRegisterDefaultEditorClass( Choice
);
5105 wxPGRegisterDefaultEditorClass( ComboBox
);
5106 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5107 #if wxPG_INCLUDE_CHECKBOX
5108 wxPGRegisterDefaultEditorClass( CheckBox
);
5110 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5112 // Register SpinCtrl etc. editors before use
5113 RegisterAdditionalEditors();
5116 // -----------------------------------------------------------------------
5117 // wxPGStringTokenizer
5118 // Needed to handle C-style string lists (e.g. "str1" "str2")
5119 // -----------------------------------------------------------------------
5121 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5122 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5126 wxPGStringTokenizer::~wxPGStringTokenizer()
5130 bool wxPGStringTokenizer::HasMoreTokens()
5132 const wxString
& str
= *m_str
;
5134 wxString::const_iterator i
= m_curPos
;
5136 wxUniChar delim
= m_delimeter
;
5138 wxUniChar prev_a
= wxT('\0');
5140 bool inToken
= false;
5142 while ( i
!= str
.end() )
5151 m_readyToken
.clear();
5156 if ( prev_a
!= wxT('\\') )
5160 if ( a
!= wxT('\\') )
5180 m_curPos
= str
.end();
5188 wxString
wxPGStringTokenizer::GetNextToken()
5190 return m_readyToken
;
5193 // -----------------------------------------------------------------------
5195 // -----------------------------------------------------------------------
5197 wxPGChoiceEntry::wxPGChoiceEntry()
5198 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5202 // -----------------------------------------------------------------------
5204 // -----------------------------------------------------------------------
5206 wxPGChoicesData::wxPGChoicesData()
5211 wxPGChoicesData::~wxPGChoicesData()
5216 void wxPGChoicesData::Clear()
5221 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5223 wxASSERT( m_items
.size() == 0 );
5225 m_items
= data
->m_items
;
5228 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5229 const wxPGChoiceEntry
& item
)
5231 wxVector
<wxPGChoiceEntry
>::iterator it
;
5235 index
= (int) m_items
.size();
5239 it
= m_items
.begin() + index
;
5242 m_items
.insert(it
, item
);
5244 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5246 // Need to fix value?
5247 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5248 ownEntry
.SetValue(index
);
5253 // -----------------------------------------------------------------------
5254 // wxPropertyGridEvent
5255 // -----------------------------------------------------------------------
5257 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5260 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5261 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5262 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5263 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5264 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5265 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5266 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5267 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5268 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5271 // -----------------------------------------------------------------------
5273 void wxPropertyGridEvent::Init()
5275 m_validationInfo
= NULL
;
5277 m_wasVetoed
= false;
5280 // -----------------------------------------------------------------------
5282 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5283 : wxCommandEvent(commandType
,id
)
5289 // -----------------------------------------------------------------------
5291 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5292 : wxCommandEvent(event
)
5294 m_eventType
= event
.GetEventType();
5295 m_eventObject
= event
.m_eventObject
;
5297 m_property
= event
.m_property
;
5298 m_validationInfo
= event
.m_validationInfo
;
5299 m_canVeto
= event
.m_canVeto
;
5300 m_wasVetoed
= event
.m_wasVetoed
;
5303 // -----------------------------------------------------------------------
5305 wxPropertyGridEvent::~wxPropertyGridEvent()
5309 // -----------------------------------------------------------------------
5311 wxEvent
* wxPropertyGridEvent::Clone() const
5313 return new wxPropertyGridEvent( *this );
5316 // -----------------------------------------------------------------------
5317 // wxPropertyGridPopulator
5318 // -----------------------------------------------------------------------
5320 wxPropertyGridPopulator::wxPropertyGridPopulator()
5324 wxPGGlobalVars
->m_offline
++;
5327 // -----------------------------------------------------------------------
5329 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5332 m_propHierarchy
.clear();
5335 // -----------------------------------------------------------------------
5337 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5343 // -----------------------------------------------------------------------
5345 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5348 // Free unused sets of choices
5349 wxPGHashMapS2P::iterator it
;
5351 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5353 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5360 m_pg
->GetPanel()->Refresh();
5362 wxPGGlobalVars
->m_offline
--;
5365 // -----------------------------------------------------------------------
5367 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5368 const wxString
& propLabel
,
5369 const wxString
& propName
,
5370 const wxString
* propValue
,
5371 wxPGChoices
* pChoices
)
5373 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5374 wxPGProperty
* parent
= GetCurParent();
5376 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5378 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5382 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5384 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5388 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5390 property
->SetLabel(propLabel
);
5391 property
->DoSetName(propName
);
5393 if ( pChoices
&& pChoices
->IsOk() )
5394 property
->SetChoices(*pChoices
);
5396 m_state
->DoInsert(parent
, -1, property
);
5399 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5400 wxPG_PROGRAMMATIC_VALUE
);
5405 // -----------------------------------------------------------------------
5407 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5409 m_propHierarchy
.push_back(property
);
5410 DoScanForChildren();
5411 m_propHierarchy
.pop_back();
5414 // -----------------------------------------------------------------------
5416 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5417 const wxString
& idString
)
5419 wxPGChoices choices
;
5422 if ( choicesString
[0] == wxT('@') )
5424 wxString ids
= choicesString
.substr(1);
5425 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5426 if ( it
== m_dictIdChoices
.end() )
5427 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5429 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5434 if ( idString
.length() )
5436 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5437 if ( it
!= m_dictIdChoices
.end() )
5439 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5446 // Parse choices string
5447 wxString::const_iterator it
= choicesString
.begin();
5451 bool labelValid
= false;
5453 for ( ; it
!= choicesString
.end(); ++it
)
5459 if ( c
== wxT('"') )
5464 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5465 choices
.Add(label
, l
);
5468 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5473 else if ( c
== wxT('=') )
5480 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5487 if ( c
== wxT('"') )
5500 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5501 choices
.Add(label
, l
);
5504 if ( !choices
.IsOk() )
5506 choices
.EnsureData();
5510 if ( idString
.length() )
5511 m_dictIdChoices
[idString
] = choices
.GetData();
5518 // -----------------------------------------------------------------------
5520 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5522 if ( s
.Last() == wxT('%') )
5524 wxString s2
= s
.substr(0,s
.length()-1);
5526 if ( s2
.ToLong(&val
, 10) )
5528 *pval
= (val
*max
)/100;
5534 return s
.ToLong(pval
, 10);
5537 // -----------------------------------------------------------------------
5539 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5540 const wxString
& type
,
5541 const wxString
& value
)
5543 int l
= m_propHierarchy
.size();
5547 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5548 wxString valuel
= value
.Lower();
5551 if ( type
.length() == 0 )
5556 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5558 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5560 else if ( value
.ToLong(&v
, 0) )
5567 if ( type
== wxT("string") )
5571 else if ( type
== wxT("int") )
5574 value
.ToLong(&v
, 0);
5577 else if ( type
== wxT("bool") )
5579 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5586 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5591 p
->SetAttribute( name
, variant
);
5596 // -----------------------------------------------------------------------
5598 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5600 wxLogError(_("Error in resource: %s"),msg
.c_str());
5603 // -----------------------------------------------------------------------
5605 #endif // wxUSE_PROPGRID