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 ClearSelection(false);
2119 m_pState
->DoClear();
2125 RecalculateVirtualSize();
2127 // Need to clear some area at the end
2129 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2132 // -----------------------------------------------------------------------
2134 bool wxPropertyGrid::EnableCategories( bool enable
)
2136 ClearSelection(false);
2141 // Enable categories
2144 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2149 // Disable categories
2151 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2154 if ( !m_pState
->EnableCategories(enable
) )
2159 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2161 m_pState
->m_itemsAdded
= 1; // force
2162 PrepareAfterItemsAdded();
2166 m_pState
->m_itemsAdded
= 1;
2168 // No need for RecalculateVirtualSize() here - it is already called in
2169 // wxPropertyGridPageState method above.
2176 // -----------------------------------------------------------------------
2178 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2180 wxASSERT( pNewState
);
2181 wxASSERT( pNewState
->GetGrid() );
2183 if ( pNewState
== m_pState
)
2186 wxPGProperty
* oldSelection
= m_selected
;
2188 ClearSelection(false);
2190 m_pState
->m_selected
= oldSelection
;
2192 bool orig_mode
= m_pState
->IsInNonCatMode();
2193 bool new_state_mode
= pNewState
->IsInNonCatMode();
2195 m_pState
= pNewState
;
2198 int pgWidth
= GetClientSize().x
;
2199 if ( HasVirtualWidth() )
2201 int minWidth
= pgWidth
;
2202 if ( pNewState
->m_width
< minWidth
)
2204 pNewState
->m_width
= minWidth
;
2205 pNewState
->CheckColumnWidths();
2211 // Just in case, fully re-center splitter
2212 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2213 pNewState
->m_fSplitterX
= -1.0;
2215 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2220 // If necessary, convert state to correct mode.
2221 if ( orig_mode
!= new_state_mode
)
2223 // This should refresh as well.
2224 EnableCategories( orig_mode
?false:true );
2226 else if ( !m_frozen
)
2228 // Refresh, if not frozen.
2229 m_pState
->PrepareAfterItemsAdded();
2232 if ( m_pState
->m_selected
)
2233 DoSelectProperty( m_pState
->m_selected
);
2235 RecalculateVirtualSize(0);
2239 m_pState
->m_itemsAdded
= 1;
2242 // -----------------------------------------------------------------------
2244 // Call to SetSplitterPosition will always disable splitter auto-centering
2245 // if parent window is shown.
2246 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2248 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2251 wxPropertyGridPageState
* state
= m_pState
;
2253 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2258 CorrectEditorWidgetSizeX();
2264 // -----------------------------------------------------------------------
2266 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2268 SetSplitterPosition( m_width
/2, true );
2269 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2270 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2273 // -----------------------------------------------------------------------
2274 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2275 // -----------------------------------------------------------------------
2277 // Returns nearest paint visible property (such that will be painted unless
2278 // window is scrolled or resized). If given property is paint visible, then
2279 // it itself will be returned
2280 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2282 int vx
,vy1
;// Top left corner of client
2283 GetViewStart(&vx
,&vy1
);
2284 vy1
*= wxPG_PIXELS_PER_UNIT
;
2286 int vy2
= vy1
+ m_height
;
2287 int propY
= p
->GetY2(m_lineHeight
);
2289 if ( (propY
+ m_lineHeight
) < vy1
)
2292 return DoGetItemAtY( vy1
);
2294 else if ( propY
> vy2
)
2297 return DoGetItemAtY( vy2
);
2300 // Itself paint visible
2305 // -----------------------------------------------------------------------
2306 // Methods related to change in value, value modification and sending events
2307 // -----------------------------------------------------------------------
2309 // commits any changes in editor of selected property
2310 // return true if validation did not fail
2311 // flags are same as with DoSelectProperty
2312 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2314 // Committing already?
2315 if ( m_inCommitChangesFromEditor
)
2318 // Don't do this if already processing editor event. It might
2319 // induce recursive dialogs and crap like that.
2320 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2322 if ( m_inDoPropertyChanged
)
2329 IsEditorsValueModified() &&
2330 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2333 m_inCommitChangesFromEditor
= 1;
2335 wxVariant
variant(m_selected
->GetValueRef());
2336 bool valueIsPending
= false;
2338 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2339 // due to another window getting focus
2340 wxWindow
* oldFocus
= m_curFocused
;
2342 bool validationFailure
= false;
2343 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2345 m_chgInfo_changedProperty
= NULL
;
2347 // If truly modified, schedule value as pending.
2348 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2350 if ( DoEditorValidate() &&
2351 PerformValidation(m_selected
, variant
) )
2353 valueIsPending
= true;
2357 validationFailure
= true;
2362 EditorsValueWasNotModified();
2367 m_inCommitChangesFromEditor
= 0;
2369 if ( validationFailure
&& !forceSuccess
)
2373 oldFocus
->SetFocus();
2374 m_curFocused
= oldFocus
;
2377 res
= OnValidationFailure(m_selected
, variant
);
2379 // Now prevent further validation failure messages
2382 EditorsValueWasNotModified();
2383 OnValidationFailureReset(m_selected
);
2386 else if ( valueIsPending
)
2388 DoPropertyChanged( m_selected
, flags
);
2389 EditorsValueWasNotModified();
2398 // -----------------------------------------------------------------------
2400 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2404 // Runs all validation functionality.
2405 // Returns true if value passes all tests.
2408 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2410 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2412 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2417 // Adapt list to child values, if necessary
2418 wxVariant listValue
= pendingValue
;
2419 wxVariant
* pPendingValue
= &pendingValue
;
2420 wxVariant
* pList
= NULL
;
2422 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2423 // string value, then we need treat as it was changed instead
2424 // (or, in addition, as is the case with composite string parent).
2425 // This includes creating list variant for child values.
2427 wxPGProperty
* pwc
= p
->GetParent();
2428 wxPGProperty
* changedProperty
= p
;
2429 wxPGProperty
* baseChangedProperty
= changedProperty
;
2430 wxVariant bcpPendingList
;
2432 listValue
= pendingValue
;
2433 listValue
.SetName(p
->GetBaseName());
2436 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2438 wxVariantList tempList
;
2439 wxVariant
lv(tempList
, pwc
->GetBaseName());
2440 lv
.Append(listValue
);
2442 pPendingValue
= &listValue
;
2444 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2446 baseChangedProperty
= pwc
;
2447 bcpPendingList
= lv
;
2450 changedProperty
= pwc
;
2451 pwc
= pwc
->GetParent();
2455 wxPGProperty
* evtChangingProperty
= changedProperty
;
2457 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2459 value
= *pPendingValue
;
2463 // Convert list to child values
2464 pList
= pPendingValue
;
2465 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2468 wxVariant evtChangingValue
= value
;
2470 if ( flags
& SendEvtChanging
)
2472 // FIXME: After proper ValueToString()s added, remove
2473 // this. It is just a temporary fix, as evt_changing
2474 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2475 // (unless it is selected, and textctrl editor is open).
2476 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2478 evtChangingProperty
= baseChangedProperty
;
2479 if ( evtChangingProperty
!= p
)
2481 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2485 evtChangingValue
= pendingValue
;
2489 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2491 if ( changedProperty
== m_selected
)
2493 wxWindow
* editor
= GetEditorControl();
2494 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2495 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2499 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2504 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2505 m_chgInfo_changedProperty
= changedProperty
;
2506 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2507 m_chgInfo_pendingValue
= value
;
2510 m_chgInfo_valueList
= *pList
;
2512 m_chgInfo_valueList
.MakeNull();
2514 // If changedProperty is not property which value was edited,
2515 // then call wxPGProperty::ValidateValue() for that as well.
2516 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2518 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2522 if ( flags
& SendEvtChanging
)
2524 // SendEvent returns true if event was vetoed
2525 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2529 if ( flags
& IsStandaloneValidation
)
2531 // If called in 'generic' context, we need to reset
2532 // m_chgInfo_changedProperty and write back translated value.
2533 m_chgInfo_changedProperty
= NULL
;
2534 pendingValue
= value
;
2540 // -----------------------------------------------------------------------
2542 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2544 if ( !msg
.length() )
2548 if ( !wxPGGlobalVars
->m_offline
)
2550 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2553 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2556 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2559 pStatusBar
->SetStatusText(msg
);
2567 ::wxMessageBox(msg
, _T("Property Error"));
2570 // -----------------------------------------------------------------------
2572 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2573 wxVariant
& invalidValue
)
2575 wxWindow
* editor
= GetEditorControl();
2577 // First call property's handler
2578 property
->OnValidationFailure(invalidValue
);
2580 bool res
= DoOnValidationFailure(property
, invalidValue
);
2583 // For non-wxTextCtrl editors, we do need to revert the value
2584 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2585 property
== m_selected
)
2587 property
->GetEditorClass()->UpdateControl(property
, editor
);
2590 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2595 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2597 int vfb
= m_validationInfo
.m_failureBehavior
;
2599 if ( vfb
& wxPG_VFB_BEEP
)
2602 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2603 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2605 unsigned int colCount
= m_pState
->GetColumnCount();
2607 // We need backup marked property's cells
2608 m_propCellsBackup
= property
->m_cells
;
2610 wxColour vfbFg
= *wxWHITE
;
2611 wxColour vfbBg
= *wxRED
;
2613 property
->EnsureCells(colCount
);
2615 for ( unsigned int i
=0; i
<colCount
; i
++ )
2617 wxPGCell
& cell
= property
->m_cells
[i
];
2618 cell
.SetFgCol(vfbFg
);
2619 cell
.SetBgCol(vfbBg
);
2622 DrawItemAndChildren(property
);
2624 if ( property
== m_selected
)
2626 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2628 wxWindow
* editor
= GetEditorControl();
2631 editor
->SetForegroundColour(vfbFg
);
2632 editor
->SetBackgroundColour(vfbBg
);
2637 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2639 wxString msg
= m_validationInfo
.m_failureMessage
;
2641 if ( !msg
.length() )
2642 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2644 DoShowPropertyError(property
, msg
);
2647 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2650 // -----------------------------------------------------------------------
2652 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2654 int vfb
= m_validationInfo
.m_failureBehavior
;
2656 if ( vfb
& wxPG_VFB_MARK_CELL
)
2659 property
->m_cells
= m_propCellsBackup
;
2661 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2663 if ( property
== m_selected
&& GetEditorControl() )
2665 // Calling this will recreate the control, thus resetting its colour
2666 RefreshProperty(property
);
2670 DrawItemAndChildren(property
);
2675 // -----------------------------------------------------------------------
2677 // flags are same as with DoSelectProperty
2678 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2680 if ( m_inDoPropertyChanged
)
2683 wxWindow
* editor
= GetEditorControl();
2685 m_pState
->m_anyModified
= 1;
2687 m_inDoPropertyChanged
= 1;
2689 // Maybe need to update control
2690 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2692 // These values were calculated in PerformValidation()
2693 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2694 wxVariant value
= m_chgInfo_pendingValue
;
2696 wxPGProperty
* topPaintedProperty
= changedProperty
;
2698 while ( !topPaintedProperty
->IsCategory() &&
2699 !topPaintedProperty
->IsRoot() )
2701 topPaintedProperty
= topPaintedProperty
->GetParent();
2704 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2706 // Set as Modified (not if dragging just began)
2707 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2709 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2710 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2713 SetCurControlBoldFont();
2719 // Propagate updates to parent(s)
2721 wxPGProperty
* prevPwc
= NULL
;
2723 while ( prevPwc
!= topPaintedProperty
)
2725 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2727 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2730 SetCurControlBoldFont();
2734 pwc
= pwc
->GetParent();
2737 // Draw the actual property
2738 DrawItemAndChildren( topPaintedProperty
);
2741 // If value was set by wxPGProperty::OnEvent, then update the editor
2743 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2749 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2750 if ( m_wndEditor
) m_wndEditor
->Refresh();
2751 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2756 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2758 // If top parent has composite string value, then send to child parents,
2759 // starting from baseChangedProperty.
2760 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2762 pwc
= m_chgInfo_baseChangedProperty
;
2764 while ( pwc
!= changedProperty
)
2766 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2767 pwc
= pwc
->GetParent();
2771 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2773 m_inDoPropertyChanged
= 0;
2778 // -----------------------------------------------------------------------
2780 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2782 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2784 m_chgInfo_changedProperty
= NULL
;
2786 if ( PerformValidation(p
, newValue
) )
2788 DoPropertyChanged(p
);
2793 OnValidationFailure(p
, newValue
);
2799 // -----------------------------------------------------------------------
2801 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2803 wxPGProperty
* prop
= GetSelectedProperty();
2806 return wxNullVariant
;
2808 wxTextCtrl
* tc
= GetEditorTextCtrl();
2809 wxVariant value
= prop
->GetValue();
2811 if ( !tc
|| !IsEditorsValueModified() )
2814 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2817 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2818 return prop
->GetValue();
2823 // -----------------------------------------------------------------------
2825 // Runs wxValidator for the selected property
2826 bool wxPropertyGrid::DoEditorValidate()
2831 // -----------------------------------------------------------------------
2833 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2835 wxPGProperty
* selected
= m_selected
;
2837 // Somehow, event is handled after property has been deselected.
2838 // Possibly, but very rare.
2842 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2845 wxVariant
pendingValue(selected
->GetValueRef());
2846 wxWindow
* wnd
= GetEditorControl();
2848 bool wasUnspecified
= selected
->IsValueUnspecified();
2849 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2851 bool valueIsPending
= false;
2853 m_chgInfo_changedProperty
= NULL
;
2855 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2858 // Filter out excess wxTextCtrl modified events
2859 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2861 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2863 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2865 wxString newTcValue
= tc
->GetValue();
2866 if ( m_prevTcValue
== newTcValue
)
2869 m_prevTcValue
= newTcValue
;
2872 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2874 bool validationFailure
= false;
2875 bool buttonWasHandled
= false;
2878 // Try common button handling
2879 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2881 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2885 buttonWasHandled
= true;
2886 // Store as res2, as previously (and still currently alternatively)
2887 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2888 // in wxPGProperty::OnEvent().
2889 adapter
->ShowDialog( this, selected
);
2894 if ( !buttonWasHandled
)
2898 // First call editor class' event handler.
2899 const wxPGEditor
* editor
= selected
->GetEditorClass();
2901 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2903 // If changes, validate them
2904 if ( DoEditorValidate() )
2906 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
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, wnd
, 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 cust_img_space
= 0;
2984 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2985 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2987 // TODO: If custom image detection changes from current, change this.
2988 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
2990 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
2991 int imwid
= p
->OnMeasureImage().x
;
2992 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
2993 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
2998 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3000 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3005 // -----------------------------------------------------------------------
3007 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3009 wxSize sz
= GetImageSize(p
, item
);
3010 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3011 wxPG_CUSTOM_IMAGE_SPACINGY
,
3016 // return size of custom paint image
3017 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3019 // If called with NULL property, then return default image
3020 // size for properties that use image.
3022 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3024 wxSize cis
= p
->OnMeasureImage(item
);
3026 int choiceCount
= p
->m_choices
.GetCount();
3027 int comVals
= p
->GetDisplayedCommonValueCount();
3028 if ( item
>= choiceCount
&& comVals
> 0 )
3030 unsigned int cvi
= item
-choiceCount
;
3031 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3033 else if ( item
>= 0 && choiceCount
== 0 )
3034 return wxSize(0, 0);
3039 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3044 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3051 // -----------------------------------------------------------------------
3053 // takes scrolling into account
3054 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3057 GetViewStart(&vx
,&vy
);
3058 vy
*=wxPG_PIXELS_PER_UNIT
;
3059 vx
*=wxPG_PIXELS_PER_UNIT
;
3062 ClientToScreen( px
, py
);
3065 // -----------------------------------------------------------------------
3067 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3070 GetViewStart(&pt2
.x
,&pt2
.y
);
3071 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3072 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3076 return m_pState
->HitTest(pt2
);
3079 // -----------------------------------------------------------------------
3081 // custom set cursor
3082 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3084 if ( type
== m_curcursor
&& !override
) return;
3086 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3088 if ( type
== wxCURSOR_SIZEWE
)
3089 cursor
= m_cursorSizeWE
;
3091 m_canvas
->SetCursor( *cursor
);
3096 // -----------------------------------------------------------------------
3097 // wxPropertyGrid property selection, editor creation
3098 // -----------------------------------------------------------------------
3101 // This class forwards events from property editor controls to wxPropertyGrid.
3102 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3105 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3106 : wxEvtHandler(), m_propGrid(propGrid
)
3110 virtual ~wxPropertyGridEditorEventForwarder()
3115 bool ProcessEvent( wxEvent
& event
)
3120 m_propGrid
->HandleCustomEditorEvent(event
);
3122 return wxEvtHandler::ProcessEvent(event
);
3125 wxPropertyGrid
* m_propGrid
;
3128 // Setups event handling for child control
3129 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3131 wxWindowID id
= argWnd
->GetId();
3133 if ( argWnd
== m_wndEditor
)
3135 argWnd
->Connect(id
, wxEVT_MOTION
,
3136 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3138 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3139 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3141 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3142 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3144 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3145 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3147 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3148 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3150 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3151 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3155 wxPropertyGridEditorEventForwarder
* forwarder
;
3156 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3157 argWnd
->PushEventHandler(forwarder
);
3159 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3160 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3164 void wxPropertyGrid::FreeEditors()
3167 // Return focus back to canvas from children (this is required at least for
3168 // GTK+, which, unlike Windows, clears focus when control is destroyed
3169 // instead of moving it to closest parent).
3170 wxWindow
* focus
= wxWindow::FindFocus();
3173 wxWindow
* parent
= focus
->GetParent();
3176 if ( parent
== m_canvas
)
3181 parent
= parent
->GetParent();
3185 // Do not free editors immediately if processing events
3188 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3189 m_wndEditor2
->Hide();
3190 wxPendingDelete
.Append( handler
);
3191 wxPendingDelete
.Append( m_wndEditor2
);
3192 m_wndEditor2
= NULL
;
3197 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3198 m_wndEditor
->Hide();
3199 wxPendingDelete
.Append( handler
);
3200 wxPendingDelete
.Append( m_wndEditor
);
3205 // Call with NULL to de-select property
3206 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3210 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3211 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3213 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3216 if ( m_inDoSelectProperty
)
3219 m_inDoSelectProperty
= 1;
3221 wxPGProperty
* prev
= m_selected
;
3225 m_inDoSelectProperty
= 0;
3231 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3233 wxPrintf( "None selected\n" );
3236 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3238 wxPrintf( "P = NULL\n" );
3241 // If we are frozen, then just set the values.
3244 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3245 m_editorFocused
= 0;
3248 m_pState
->m_selected
= p
;
3250 // If frozen, always free controls. But don't worry, as Thaw will
3251 // recall SelectProperty to recreate them.
3254 // Prevent any further selection measures in this call
3260 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3262 // Only set focus if not deselecting
3265 if ( flags
& wxPG_SEL_FOCUS
)
3269 m_wndEditor
->SetFocus();
3270 m_editorFocused
= 1;
3279 m_inDoSelectProperty
= 0;
3284 // First, deactivate previous
3288 OnValidationFailureReset(m_selected
);
3290 // Must double-check if this is an selected in case of forceswitch
3293 if ( !CommitChangesFromEditor(flags
) )
3295 // Validation has failed, so we can't exit the previous editor
3296 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3297 // _("Invalid Value"),wxOK|wxICON_ERROR);
3298 m_inDoSelectProperty
= 0;
3307 m_pState
->m_selected
= NULL
;
3309 // We need to always fully refresh the grid here
3312 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3313 EditorsValueWasNotModified();
3316 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3319 // Then, activate the one given.
3322 int propY
= p
->GetY2(m_lineHeight
);
3324 int splitterX
= GetSplitterPosition();
3325 m_editorFocused
= 0;
3327 m_pState
->m_selected
= p
;
3328 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3330 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3332 wxASSERT( m_wndEditor
== NULL
);
3335 // Only create editor for non-disabled non-caption
3336 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3338 // do this for non-caption items
3342 // Do we need to paint the custom image, if any?
3343 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3344 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3345 !p
->GetEditorClass()->CanContainCustomImage()
3347 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3349 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3350 wxPoint goodPos
= grect
.GetPosition();
3351 #if wxPG_CREATE_CONTROLS_HIDDEN
3352 int coord_adjust
= m_height
- goodPos
.y
;
3353 goodPos
.y
+= coord_adjust
;
3356 const wxPGEditor
* editor
= p
->GetEditorClass();
3357 wxCHECK_MSG(editor
, false,
3358 wxT("NULL editor class not allowed"));
3360 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3362 wxPGWindowList wndList
= editor
->CreateControls(this,
3367 m_wndEditor
= wndList
.m_primary
;
3368 m_wndEditor2
= wndList
.m_secondary
;
3369 wxWindow
* primaryCtrl
= GetEditorControl();
3372 // Essentially, primaryCtrl == m_wndEditor
3375 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3376 // value is drawn as normal, and m_wndEditor2 is assumed
3377 // to be a right-aligned button that triggers a separate editorCtrl
3382 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3383 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3385 // Set validator, if any
3386 #if wxUSE_VALIDATORS
3387 wxValidator
* validator
= p
->GetValidator();
3389 primaryCtrl
->SetValidator(*validator
);
3392 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3393 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3395 // If it has modified status, use bold font
3396 // (must be done before capturing m_ctrlXAdjust)
3397 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3398 SetCurControlBoldFont();
3401 // Fix TextCtrl indentation
3402 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3403 wxTextCtrl
* tc
= NULL
;
3404 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3405 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3407 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3409 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3412 // Store x relative to splitter (we'll need it).
3413 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3415 // Check if background clear is not necessary
3416 wxPoint pos
= m_wndEditor
->GetPosition();
3417 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3419 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3422 m_wndEditor
->SetSizeHints(3, 3);
3424 #if wxPG_CREATE_CONTROLS_HIDDEN
3425 m_wndEditor
->Show(false);
3426 m_wndEditor
->Freeze();
3428 goodPos
= m_wndEditor
->GetPosition();
3429 goodPos
.y
-= coord_adjust
;
3430 m_wndEditor
->Move( goodPos
);
3433 SetupChildEventHandling(primaryCtrl
);
3435 // Focus and select all (wxTextCtrl, wxComboBox etc)
3436 if ( flags
& wxPG_SEL_FOCUS
)
3438 primaryCtrl
->SetFocus();
3440 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3446 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3447 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3449 // Get proper id for wndSecondary
3450 m_wndSecId
= m_wndEditor2
->GetId();
3451 wxWindowList children
= m_wndEditor2
->GetChildren();
3452 wxWindowList::iterator node
= children
.begin();
3453 if ( node
!= children
.end() )
3454 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3456 m_wndEditor2
->SetSizeHints(3,3);
3458 #if wxPG_CREATE_CONTROLS_HIDDEN
3459 wxRect sec_rect
= m_wndEditor2
->GetRect();
3460 sec_rect
.y
-= coord_adjust
;
3462 // Fine tuning required to fix "oversized"
3463 // button disappearance bug.
3464 if ( sec_rect
.y
< 0 )
3466 sec_rect
.height
+= sec_rect
.y
;
3469 m_wndEditor2
->SetSize( sec_rect
);
3471 m_wndEditor2
->Show();
3473 SetupChildEventHandling(m_wndEditor2
);
3475 // If no primary editor, focus to button to allow
3476 // it to interprete ENTER etc.
3477 // NOTE: Due to problems focusing away from it, this
3478 // has been disabled.
3480 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3481 m_wndEditor2->SetFocus();
3485 if ( flags
& wxPG_SEL_FOCUS
)
3486 m_editorFocused
= 1;
3491 // Make sure focus is in grid canvas (important for wxGTK, at least)
3495 EditorsValueWasNotModified();
3497 // If it's inside collapsed section, expand parent, scroll, etc.
3498 // Also, if it was partially visible, scroll it into view.
3499 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3504 #if wxPG_CREATE_CONTROLS_HIDDEN
3505 m_wndEditor
->Thaw();
3507 m_wndEditor
->Show(true);
3514 // Make sure focus is in grid canvas
3518 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3524 // Show help text in status bar.
3525 // (if found and grid not embedded in manager with help box and
3526 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3529 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3531 wxStatusBar
* statusbar
= NULL
;
3532 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3534 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3536 statusbar
= frame
->GetStatusBar();
3541 const wxString
* pHelpString
= (const wxString
*) NULL
;
3545 pHelpString
= &p
->GetHelpString();
3546 if ( pHelpString
->length() )
3548 // Set help box text.
3549 statusbar
->SetStatusText( *pHelpString
);
3550 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3554 if ( (!pHelpString
|| !pHelpString
->length()) &&
3555 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3557 // Clear help box - but only if it was written
3558 // by us at previous time.
3559 statusbar
->SetStatusText( m_emptyString
);
3560 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3566 m_inDoSelectProperty
= 0;
3568 // call wx event handler (here so that it also occurs on deselection)
3569 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3574 // -----------------------------------------------------------------------
3576 bool wxPropertyGrid::UnfocusEditor()
3578 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3581 if ( !CommitChangesFromEditor(0) )
3585 DrawItem(m_selected
);
3590 // -----------------------------------------------------------------------
3592 void wxPropertyGrid::RefreshEditor()
3594 wxPGProperty
* p
= m_selected
;
3598 wxWindow
* wnd
= GetEditorControl();
3602 // Set editor font boldness - must do this before
3603 // calling UpdateControl().
3604 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3606 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3607 wnd
->SetFont(GetCaptionFont());
3609 wnd
->SetFont(GetFont());
3612 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3614 editorClass
->UpdateControl(p
, wnd
);
3616 if ( p
->IsValueUnspecified() )
3617 editorClass
->SetValueToUnspecified(p
, wnd
);
3620 // -----------------------------------------------------------------------
3622 // This method is not inline because it called dozens of times
3623 // (i.e. two-arg function calls create smaller code size).
3624 bool wxPropertyGrid::DoClearSelection()
3626 return DoSelectProperty(NULL
);
3629 // -----------------------------------------------------------------------
3630 // wxPropertyGrid expand/collapse state
3631 // -----------------------------------------------------------------------
3633 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3635 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3637 // If active editor was inside collapsed section, then disable it
3638 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3640 ClearSelection(false);
3643 // Store dont-center-splitter flag 'cause we need to temporarily set it
3644 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3645 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3647 bool res
= m_pState
->DoCollapse(pwc
);
3652 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3654 RecalculateVirtualSize();
3656 // Redraw etc. only if collapsed was visible.
3657 if (pwc
->IsVisible() &&
3659 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3661 // When item is collapsed so that scrollbar would move,
3662 // graphics mess is about (unless we redraw everything).
3667 // Clear dont-center-splitter flag if it wasn't set
3668 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3673 // -----------------------------------------------------------------------
3675 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3677 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3679 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3681 // Store dont-center-splitter flag 'cause we need to temporarily set it
3682 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3683 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3685 bool res
= m_pState
->DoExpand(pwc
);
3690 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3692 RecalculateVirtualSize();
3694 // Redraw etc. only if expanded was visible.
3695 if ( pwc
->IsVisible() && !m_frozen
&&
3696 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3700 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3703 DrawItems(pwc
, NULL
);
3708 // Clear dont-center-splitter flag if it wasn't set
3709 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3714 // -----------------------------------------------------------------------
3716 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3719 return m_pState
->DoHideProperty(p
, hide
, flags
);
3722 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3725 ClearSelection(false);
3728 m_pState
->DoHideProperty(p
, hide
, flags
);
3730 RecalculateVirtualSize();
3737 // -----------------------------------------------------------------------
3738 // wxPropertyGrid size related methods
3739 // -----------------------------------------------------------------------
3741 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3743 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3747 // If virtual height was changed, then recalculate editor control position(s)
3748 if ( m_pState
->m_vhCalcPending
)
3749 CorrectEditorWidgetPosY();
3751 m_pState
->EnsureVirtualHeight();
3754 int by1
= m_pState
->GetVirtualHeight();
3755 int by2
= m_pState
->GetActualVirtualHeight();
3758 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3759 wxFAIL_MSG(s
.c_str());
3764 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3766 int x
= m_pState
->m_width
;
3767 int y
= m_pState
->m_virtualHeight
;
3770 GetClientSize(&width
,&height
);
3772 // Now adjust virtual size.
3773 SetVirtualSize(x
, y
);
3779 // Adjust scrollbars
3780 if ( HasVirtualWidth() )
3782 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3783 xPos
= GetScrollPos( wxHORIZONTAL
);
3786 if ( forceXPos
!= -1 )
3789 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3792 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3793 int yPos
= GetScrollPos( wxVERTICAL
);
3795 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3796 xAmount
, yAmount
, xPos
, yPos
, true );
3798 // Must re-get size now
3799 GetClientSize(&width
,&height
);
3801 if ( !HasVirtualWidth() )
3803 m_pState
->SetVirtualWidth(width
);
3810 m_canvas
->SetSize( x
, y
);
3812 m_pState
->CheckColumnWidths();
3815 CorrectEditorWidgetSizeX();
3817 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3820 // -----------------------------------------------------------------------
3822 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3824 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3828 GetClientSize(&width
,&height
);
3833 #if wxPG_DOUBLE_BUFFER
3834 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3836 int dblh
= (m_lineHeight
*2);
3837 if ( !m_doubleBuffer
)
3839 // Create double buffer bitmap to draw on, if none
3840 int w
= (width
>250)?width
:250;
3841 int h
= height
+ dblh
;
3843 m_doubleBuffer
= new wxBitmap( w
, h
);
3847 int w
= m_doubleBuffer
->GetWidth();
3848 int h
= m_doubleBuffer
->GetHeight();
3850 // Double buffer must be large enough
3851 if ( w
< width
|| h
< (height
+dblh
) )
3853 if ( w
< width
) w
= width
;
3854 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3855 delete m_doubleBuffer
;
3856 m_doubleBuffer
= new wxBitmap( w
, h
);
3863 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3864 m_ncWidth
= event
.GetSize().x
;
3868 if ( m_pState
->m_itemsAdded
)
3869 PrepareAfterItemsAdded();
3871 // Without this, virtual size (atleast under wxGTK) will be skewed
3872 RecalculateVirtualSize();
3878 // -----------------------------------------------------------------------
3880 void wxPropertyGrid::SetVirtualWidth( int width
)
3884 // Disable virtual width
3885 width
= GetClientSize().x
;
3886 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3890 // Enable virtual width
3891 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3893 m_pState
->SetVirtualWidth( width
);
3896 void wxPropertyGrid::SetFocusOnCanvas()
3898 m_canvas
->SetFocusIgnoringChildren();
3899 m_editorFocused
= 0;
3902 // -----------------------------------------------------------------------
3903 // wxPropertyGrid mouse event handling
3904 // -----------------------------------------------------------------------
3906 // selFlags uses same values DoSelectProperty's flags
3907 // Returns true if event was vetoed.
3908 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3910 // Send property grid event of specific type and with specific property
3911 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3912 evt
.SetPropertyGrid(this);
3913 evt
.SetEventObject(m_eventObject
);
3917 evt
.SetCanVeto(true);
3918 evt
.SetupValidationInfo();
3919 m_validationInfo
.m_pValue
= pValue
;
3921 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3923 evtHandler
->ProcessEvent(evt
);
3925 return evt
.WasVetoed();
3928 // -----------------------------------------------------------------------
3930 // Return false if should be skipped
3931 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3935 // Need to set focus?
3936 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3941 wxPropertyGridPageState
* state
= m_pState
;
3943 int splitterHitOffset
;
3944 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3946 wxPGProperty
* p
= DoGetItemAtY(y
);
3950 int depth
= (int)p
->GetDepth() - 1;
3952 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3954 if ( x
>= marginEnds
)
3958 if ( p
->IsCategory() )
3960 // This is category.
3961 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3963 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3965 // Expand, collapse, activate etc. if click on text or left of splitter.
3968 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3973 if ( !DoSelectProperty( p
) )
3976 // On double-click, expand/collapse.
3977 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3979 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3980 else DoExpand( p
, true );
3984 else if ( splitterHit
== -1 )
3987 unsigned int selFlag
= 0;
3988 if ( columnHit
== 1 )
3990 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3991 selFlag
= wxPG_SEL_FOCUS
;
3993 if ( !DoSelectProperty( p
, selFlag
) )
3996 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
3998 if ( p
->GetChildCount() && !p
->IsCategory() )
3999 // On double-click, expand/collapse.
4000 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4002 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4003 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4004 else DoExpand( p
, true );
4011 // click on splitter
4012 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4014 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4016 // Double-clicking the splitter causes auto-centering
4017 CenterSplitter( true );
4019 else if ( m_dragStatus
== 0 )
4022 // Begin draggin the splitter
4026 // Changes must be committed here or the
4027 // value won't be drawn correctly
4028 if ( !CommitChangesFromEditor() )
4031 m_wndEditor
->Show ( false );
4034 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4036 m_canvas
->CaptureMouse();
4037 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4041 m_draggedSplitter
= splitterHit
;
4042 m_dragOffset
= splitterHitOffset
;
4044 wxClientDC
dc(m_canvas
);
4046 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4047 // Fixes button disappearance bug
4049 m_wndEditor2
->Show ( false );
4052 m_startingSplitterX
= x
- splitterHitOffset
;
4060 if ( p
->GetChildCount() )
4062 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4064 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4066 int y2
= y
% m_lineHeight
;
4067 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4069 // On click on expander button, expand/collapse
4070 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4071 DoCollapse( p
, true );
4073 DoExpand( p
, true );
4082 // -----------------------------------------------------------------------
4084 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4085 wxMouseEvent
& WXUNUSED(event
) )
4089 // Select property here as well
4090 wxPGProperty
* p
= m_propHover
;
4091 if ( p
!= m_selected
)
4092 DoSelectProperty( p
);
4094 // Send right click event.
4095 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4102 // -----------------------------------------------------------------------
4104 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4105 wxMouseEvent
& WXUNUSED(event
) )
4109 // Select property here as well
4110 wxPGProperty
* p
= m_propHover
;
4112 if ( p
!= m_selected
)
4113 DoSelectProperty( p
);
4115 // Send double-click event.
4116 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4123 // -----------------------------------------------------------------------
4125 #if wxPG_SUPPORT_TOOLTIPS
4127 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4129 if ( tipString
.length() )
4131 m_canvas
->SetToolTip(tipString
);
4135 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4136 m_canvas
->SetToolTip( m_emptyString
);
4138 m_canvas
->SetToolTip( NULL
);
4143 #endif // #if wxPG_SUPPORT_TOOLTIPS
4145 // -----------------------------------------------------------------------
4147 // Return false if should be skipped
4148 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4150 // Safety check (needed because mouse capturing may
4151 // otherwise freeze the control)
4152 if ( m_dragStatus
> 0 && !event
.Dragging() )
4154 HandleMouseUp(x
,y
,event
);
4157 wxPropertyGridPageState
* state
= m_pState
;
4159 int splitterHitOffset
;
4160 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4161 int splitterX
= x
- splitterHitOffset
;
4163 if ( m_dragStatus
> 0 )
4165 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4166 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4169 int newSplitterX
= x
- m_dragOffset
;
4170 int splitterX
= x
- splitterHitOffset
;
4172 // Splitter redraw required?
4173 if ( newSplitterX
!= splitterX
)
4176 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4177 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4178 state
->m_fSplitterX
= (float) newSplitterX
;
4181 CorrectEditorWidgetSizeX();
4195 int ih
= m_lineHeight
;
4198 #if wxPG_SUPPORT_TOOLTIPS
4199 wxPGProperty
* prevHover
= m_propHover
;
4200 unsigned char prevSide
= m_mouseSide
;
4202 int curPropHoverY
= y
- (y
% ih
);
4204 // On which item it hovers
4207 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4210 // Mouse moves on another property
4212 m_propHover
= DoGetItemAtY(y
);
4213 m_propHoverY
= curPropHoverY
;
4216 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4219 #if wxPG_SUPPORT_TOOLTIPS
4220 // Store which side we are on
4222 if ( columnHit
== 1 )
4224 else if ( columnHit
== 0 )
4228 // If tooltips are enabled, show label or value as a tip
4229 // in case it doesn't otherwise show in full length.
4231 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4233 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4235 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4237 if ( m_propHover
&& !m_propHover
->IsCategory() )
4240 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4242 // Show help string as a tooltip
4243 wxString tipString
= m_propHover
->GetHelpString();
4245 SetToolTip(tipString
);
4249 // Show cropped value string as a tooltip
4253 if ( m_mouseSide
== 1 )
4255 tipString
= m_propHover
->m_label
;
4256 space
= splitterX
-m_marginWidth
-3;
4258 else if ( m_mouseSide
== 2 )
4260 tipString
= m_propHover
->GetDisplayedString();
4262 space
= m_width
- splitterX
;
4263 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4264 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4270 GetTextExtent( tipString
, &tw
, &th
, 0, 0 );
4273 SetToolTip( tipString
);
4280 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4281 m_canvas
->SetToolTip( m_emptyString
);
4283 m_canvas
->SetToolTip( NULL
);
4294 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4295 m_canvas
->SetToolTip( m_emptyString
);
4297 m_canvas
->SetToolTip( NULL
);
4305 if ( splitterHit
== -1 ||
4307 HasFlag(wxPG_STATIC_SPLITTER
) )
4309 // hovering on something else
4310 if ( m_curcursor
!= wxCURSOR_ARROW
)
4311 CustomSetCursor( wxCURSOR_ARROW
);
4315 // Do not allow splitter cursor on caption items.
4316 // (also not if we were dragging and its started
4317 // outside the splitter region)
4319 if ( !m_propHover
->IsCategory() &&
4323 // hovering on splitter
4325 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4326 // reliably detected.
4327 //if ( m_curcursor != wxCURSOR_SIZEWE )
4328 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4334 // hovering on something else
4335 if ( m_curcursor
!= wxCURSOR_ARROW
)
4336 CustomSetCursor( wxCURSOR_ARROW
);
4343 // -----------------------------------------------------------------------
4345 // Also handles Leaving event
4346 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4347 wxMouseEvent
&WXUNUSED(event
) )
4349 wxPropertyGridPageState
* state
= m_pState
;
4353 int splitterHitOffset
;
4354 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4356 // No event type check - basicly calling this method should
4357 // just stop dragging.
4358 // Left up after dragged?
4359 if ( m_dragStatus
>= 1 )
4362 // End Splitter Dragging
4364 // DO NOT ENABLE FOLLOWING LINE!
4365 // (it is only here as a reminder to not to do it)
4368 // Disable splitter auto-centering
4369 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4371 // This is necessary to return cursor
4372 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4374 m_canvas
->ReleaseMouse();
4375 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4378 // Set back the default cursor, if necessary
4379 if ( splitterHit
== -1 ||
4382 CustomSetCursor( wxCURSOR_ARROW
);
4387 // Control background needs to be cleared
4388 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4389 DrawItem( m_selected
);
4393 m_wndEditor
->Show ( true );
4396 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4397 // Fixes button disappearance bug
4399 m_wndEditor2
->Show ( true );
4402 // This clears the focus.
4403 m_editorFocused
= 0;
4409 // -----------------------------------------------------------------------
4411 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4413 int splitterX
= GetSplitterPosition();
4416 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4420 wxWindow
* wnd
= GetEditorControl();
4422 // Hide popup on clicks
4423 if ( event
.GetEventType() != wxEVT_MOTION
)
4424 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4426 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4432 if ( wnd
== NULL
|| m_dragStatus
||
4434 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4435 ux
>= (r
.x
+r
.width
) ||
4437 event
.m_y
>= (r
.y
+r
.height
)
4447 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4452 // -----------------------------------------------------------------------
4454 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4457 if ( OnMouseCommon( event
, &x
, &y
) )
4459 HandleMouseClick(x
,y
,event
);
4464 // -----------------------------------------------------------------------
4466 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4469 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4470 HandleMouseRightClick(x
,y
,event
);
4474 // -----------------------------------------------------------------------
4476 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4478 // Always run standard mouse-down handler as well
4479 OnMouseClick(event
);
4482 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4483 HandleMouseDoubleClick(x
,y
,event
);
4487 // -----------------------------------------------------------------------
4489 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4492 if ( OnMouseCommon( event
, &x
, &y
) )
4494 HandleMouseMove(x
,y
,event
);
4499 // -----------------------------------------------------------------------
4501 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4503 // Called when mouse moves in the empty space below the properties.
4504 CustomSetCursor( wxCURSOR_ARROW
);
4507 // -----------------------------------------------------------------------
4509 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4512 if ( OnMouseCommon( event
, &x
, &y
) )
4514 HandleMouseUp(x
,y
,event
);
4519 // -----------------------------------------------------------------------
4521 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4523 // This may get called from child control as well, so event's
4524 // mouse position cannot be relied on.
4526 if ( event
.Entering() )
4528 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4530 // TODO: Fix this (detect parent and only do
4531 // cursor trick if it is a manager).
4532 wxASSERT( GetParent() );
4533 GetParent()->SetCursor(wxNullCursor
);
4535 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4538 GetParent()->SetCursor(wxNullCursor
);
4540 else if ( event
.Leaving() )
4542 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4543 m_canvas
->SetCursor( wxNullCursor
);
4545 // Get real cursor position
4546 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4548 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4551 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4553 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4557 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4565 // -----------------------------------------------------------------------
4567 // Common code used by various OnMouseXXXChild methods.
4568 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4570 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4571 wxASSERT( topCtrlWnd
);
4573 event
.GetPosition(&x
,&y
);
4575 int splitterX
= GetSplitterPosition();
4577 wxRect r
= topCtrlWnd
->GetRect();
4578 if ( !m_dragStatus
&&
4579 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4580 y
>= 0 && y
< r
.height \
4583 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4588 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4595 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4598 if ( OnMouseChildCommon(event
,&x
,&y
) )
4600 bool res
= HandleMouseClick(x
,y
,event
);
4601 if ( !res
) event
.Skip();
4605 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4608 wxASSERT( m_wndEditor
);
4609 // These coords may not be exact (about +-2),
4610 // but that should not matter (right click is about item, not position).
4611 wxPoint pt
= m_wndEditor
->GetPosition();
4612 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4613 wxASSERT( m_selected
);
4614 m_propHover
= m_selected
;
4615 bool res
= HandleMouseRightClick(x
,y
,event
);
4616 if ( !res
) event
.Skip();
4619 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4622 if ( OnMouseChildCommon(event
,&x
,&y
) )
4624 bool res
= HandleMouseMove(x
,y
,event
);
4625 if ( !res
) event
.Skip();
4629 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4632 if ( OnMouseChildCommon(event
,&x
,&y
) )
4634 bool res
= HandleMouseUp(x
,y
,event
);
4635 if ( !res
) event
.Skip();
4639 // -----------------------------------------------------------------------
4640 // wxPropertyGrid keyboard event handling
4641 // -----------------------------------------------------------------------
4643 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4645 // Translates wxKeyEvent to wxPG_ACTION_XXX
4647 int keycode
= event
.GetKeyCode();
4648 int modifiers
= event
.GetModifiers();
4650 wxASSERT( !(modifiers
&~(0xFFFF)) );
4652 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4654 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4656 if ( it
== m_actionTriggers
.end() )
4661 int second
= (it
->second
>>16) & 0xFFFF;
4665 return (it
->second
& 0xFFFF);
4668 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4670 wxASSERT( !(modifiers
&~(0xFFFF)) );
4672 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4674 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4676 if ( it
!= m_actionTriggers
.end() )
4678 // This key combination is already used
4680 // Can add secondary?
4681 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4682 wxT("You can only add up to two separate actions per key combination.") );
4684 action
= it
->second
| (action
<<16);
4687 m_actionTriggers
[hashMapKey
] = action
;
4690 void wxPropertyGrid::ClearActionTriggers( int action
)
4692 wxPGHashMapI2I::iterator it
;
4694 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4696 if ( it
->second
== action
)
4698 m_actionTriggers
.erase(it
);
4703 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4706 // Handles key event when editor control is not focused.
4709 wxCHECK2(!m_frozen
, return);
4711 // Travelsal between items, collapsing/expanding, etc.
4712 int keycode
= event
.GetKeyCode();
4713 bool editorFocused
= IsEditorFocused();
4715 if ( keycode
== WXK_TAB
)
4717 wxWindow
* mainControl
;
4719 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4720 mainControl
= GetParent();
4724 if ( !event
.ShiftDown() )
4726 if ( !editorFocused
&& m_wndEditor
)
4728 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4732 // Tab traversal workaround for platforms on which
4733 // wxWindow::Navigate() may navigate into first child
4734 // instead of next sibling. Does not work perfectly
4735 // in every scenario (for instance, when property grid
4736 // is either first or last control).
4737 #if defined(__WXGTK__)
4738 wxWindow
* sibling
= mainControl
->GetNextSibling();
4740 sibling
->SetFocusFromKbd();
4742 Navigate(wxNavigationKeyEvent::IsForward
);
4748 if ( editorFocused
)
4754 #if defined(__WXGTK__)
4755 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4757 sibling
->SetFocusFromKbd();
4759 Navigate(wxNavigationKeyEvent::IsBackward
);
4767 // Ignore Alt and Control when they are down alone
4768 if ( keycode
== WXK_ALT
||
4769 keycode
== WXK_CONTROL
)
4776 int action
= KeyEventToActions(event
, &secondAction
);
4778 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4781 // Esc cancels any changes
4782 if ( IsEditorsValueModified() )
4784 EditorsValueWasNotModified();
4786 // Update the control as well
4787 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4789 m_selected
->GetDisplayedString() );
4792 OnValidationFailureReset(m_selected
);
4798 // Except for TAB and ESC, handle child control events in child control
4801 // Only propagate event if it had modifiers
4802 if ( !event
.HasModifiers() )
4804 event
.StopPropagation();
4810 bool wasHandled
= false;
4815 if ( ButtonTriggerKeyTest(action
, event
) )
4818 wxPGProperty
* p
= m_selected
;
4820 // Travel and expand/collapse
4823 if ( p
->GetChildCount() &&
4824 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4827 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4829 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4832 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4834 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4841 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4845 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4851 if ( selectDir
>= -1 )
4853 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4855 DoSelectProperty(p
);
4861 // If nothing was selected, select the first item now
4862 // (or navigate out of tab).
4863 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4865 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4866 if ( p
) DoSelectProperty(p
);
4875 // -----------------------------------------------------------------------
4877 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4879 // If there was editor open and focused, then this event should not
4880 // really be processed here.
4881 if ( IsEditorFocused() )
4883 // However, if event had modifiers, it is probably still best
4885 if ( event
.HasModifiers() )
4888 event
.StopPropagation();
4892 HandleKeyEvent(event
, false);
4895 // -----------------------------------------------------------------------
4897 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4902 action
= KeyEventToActions(event
, &secondAction
);
4905 // Does the keycode trigger button?
4906 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4909 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4910 GetEventHandler()->AddPendingEvent(evt
);
4917 // -----------------------------------------------------------------------
4919 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4921 HandleKeyEvent(event
, true);
4924 // -----------------------------------------------------------------------
4925 // wxPropertyGrid miscellaneous event handling
4926 // -----------------------------------------------------------------------
4928 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4931 // Check if the focus is in this control or one of its children
4932 wxWindow
* newFocused
= wxWindow::FindFocus();
4934 if ( newFocused
!= m_curFocused
)
4935 HandleFocusChange( newFocused
);
4938 bool wxPropertyGrid::IsEditorFocused() const
4940 wxWindow
* focus
= wxWindow::FindFocus();
4942 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4943 focus
== GetEditorControl() )
4949 // Called by focus event handlers. newFocused is the window that becomes focused.
4950 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4952 unsigned int oldFlags
= m_iFlags
;
4954 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4956 wxWindow
* parent
= newFocused
;
4958 // This must be one of nextFocus' parents.
4961 // Use m_eventObject, which is either wxPropertyGrid or
4962 // wxPropertyGridManager, as appropriate.
4963 if ( parent
== m_eventObject
)
4965 m_iFlags
|= wxPG_FL_FOCUSED
;
4968 parent
= parent
->GetParent();
4971 m_curFocused
= newFocused
;
4973 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4974 (oldFlags
& wxPG_FL_FOCUSED
) )
4976 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4978 // Need to store changed value
4979 CommitChangesFromEditor();
4985 // Preliminary code for tab-order respecting
4986 // tab-traversal (but should be moved to
4989 wxWindow* prevFocus = event.GetWindow();
4990 wxWindow* useThis = this;
4991 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4992 useThis = GetParent();
4995 prevFocus->GetParent() == useThis->GetParent() )
4997 wxList& children = useThis->GetParent()->GetChildren();
4999 wxNode* node = children.Find(prevFocus);
5001 if ( node->GetNext() &&
5002 useThis == node->GetNext()->GetData() )
5003 DoSelectProperty(GetFirst());
5004 else if ( node->GetPrevious () &&
5005 useThis == node->GetPrevious()->GetData() )
5006 DoSelectProperty(GetLastProperty());
5013 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5014 DrawItem( m_selected
);
5018 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5020 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5021 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5022 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5023 //else if ( event.GetWindow() )
5025 HandleFocusChange(event
.GetWindow());
5030 // -----------------------------------------------------------------------
5032 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5034 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5037 // event.Skip() being commented out is aworkaround for bug reported
5038 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5042 // -----------------------------------------------------------------------
5044 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5046 m_iFlags
|= wxPG_FL_SCROLLED
;
5051 // -----------------------------------------------------------------------
5053 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5055 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5057 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5061 // -----------------------------------------------------------------------
5062 // Property editor related functions
5063 // -----------------------------------------------------------------------
5065 // noDefCheck = true prevents infinite recursion.
5066 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5069 wxASSERT( editorClass
);
5071 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5072 RegisterDefaultEditors();
5074 wxString name
= editorClass
->GetName();
5076 // Existing editor under this name?
5077 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5079 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5081 // If this name was already used, try class name.
5082 name
= editorClass
->GetClassInfo()->GetClassName();
5083 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5086 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5087 (wxPGEditor
*) vt_it
->second
,
5088 "Editor with given name was already registered" );
5090 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5095 // Use this in RegisterDefaultEditors.
5096 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5097 if ( wxPGEditor_##EDITOR == NULL ) \
5099 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5100 new wxPG##EDITOR##Editor, true ); \
5103 // Registers all default editor classes
5104 void wxPropertyGrid::RegisterDefaultEditors()
5106 wxPGRegisterDefaultEditorClass( TextCtrl
);
5107 wxPGRegisterDefaultEditorClass( Choice
);
5108 wxPGRegisterDefaultEditorClass( ComboBox
);
5109 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5110 #if wxPG_INCLUDE_CHECKBOX
5111 wxPGRegisterDefaultEditorClass( CheckBox
);
5113 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5115 // Register SpinCtrl etc. editors before use
5116 RegisterAdditionalEditors();
5119 // -----------------------------------------------------------------------
5120 // wxPGStringTokenizer
5121 // Needed to handle C-style string lists (e.g. "str1" "str2")
5122 // -----------------------------------------------------------------------
5124 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5125 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5129 wxPGStringTokenizer::~wxPGStringTokenizer()
5133 bool wxPGStringTokenizer::HasMoreTokens()
5135 const wxString
& str
= *m_str
;
5137 wxString::const_iterator i
= m_curPos
;
5139 wxUniChar delim
= m_delimeter
;
5141 wxUniChar prev_a
= wxT('\0');
5143 bool inToken
= false;
5145 while ( i
!= str
.end() )
5154 m_readyToken
.clear();
5159 if ( prev_a
!= wxT('\\') )
5163 if ( a
!= wxT('\\') )
5183 m_curPos
= str
.end();
5191 wxString
wxPGStringTokenizer::GetNextToken()
5193 return m_readyToken
;
5196 // -----------------------------------------------------------------------
5198 // -----------------------------------------------------------------------
5200 wxPGChoiceEntry::wxPGChoiceEntry()
5201 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5205 // -----------------------------------------------------------------------
5207 // -----------------------------------------------------------------------
5209 wxPGChoicesData::wxPGChoicesData()
5214 wxPGChoicesData::~wxPGChoicesData()
5219 void wxPGChoicesData::Clear()
5224 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5226 wxASSERT( m_items
.size() == 0 );
5228 m_items
= data
->m_items
;
5231 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5232 const wxPGChoiceEntry
& item
)
5234 wxVector
<wxPGChoiceEntry
>::iterator it
;
5238 index
= (int) m_items
.size();
5242 it
= m_items
.begin() + index
;
5245 m_items
.insert(it
, item
);
5247 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5249 // Need to fix value?
5250 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5251 ownEntry
.SetValue(index
);
5256 // -----------------------------------------------------------------------
5257 // wxPropertyGridEvent
5258 // -----------------------------------------------------------------------
5260 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5263 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5264 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5265 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5266 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5267 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5268 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5269 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5270 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5271 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5274 // -----------------------------------------------------------------------
5276 void wxPropertyGridEvent::Init()
5278 m_validationInfo
= NULL
;
5280 m_wasVetoed
= false;
5283 // -----------------------------------------------------------------------
5285 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5286 : wxCommandEvent(commandType
,id
)
5292 // -----------------------------------------------------------------------
5294 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5295 : wxCommandEvent(event
)
5297 m_eventType
= event
.GetEventType();
5298 m_eventObject
= event
.m_eventObject
;
5300 m_property
= event
.m_property
;
5301 m_validationInfo
= event
.m_validationInfo
;
5302 m_canVeto
= event
.m_canVeto
;
5303 m_wasVetoed
= event
.m_wasVetoed
;
5306 // -----------------------------------------------------------------------
5308 wxPropertyGridEvent::~wxPropertyGridEvent()
5312 // -----------------------------------------------------------------------
5314 wxEvent
* wxPropertyGridEvent::Clone() const
5316 return new wxPropertyGridEvent( *this );
5319 // -----------------------------------------------------------------------
5320 // wxPropertyGridPopulator
5321 // -----------------------------------------------------------------------
5323 wxPropertyGridPopulator::wxPropertyGridPopulator()
5327 wxPGGlobalVars
->m_offline
++;
5330 // -----------------------------------------------------------------------
5332 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5335 m_propHierarchy
.clear();
5338 // -----------------------------------------------------------------------
5340 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5346 // -----------------------------------------------------------------------
5348 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5351 // Free unused sets of choices
5352 wxPGHashMapS2P::iterator it
;
5354 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5356 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5363 m_pg
->GetPanel()->Refresh();
5365 wxPGGlobalVars
->m_offline
--;
5368 // -----------------------------------------------------------------------
5370 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5371 const wxString
& propLabel
,
5372 const wxString
& propName
,
5373 const wxString
* propValue
,
5374 wxPGChoices
* pChoices
)
5376 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5377 wxPGProperty
* parent
= GetCurParent();
5379 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5381 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5385 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5387 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5391 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5393 property
->SetLabel(propLabel
);
5394 property
->DoSetName(propName
);
5396 if ( pChoices
&& pChoices
->IsOk() )
5397 property
->SetChoices(*pChoices
);
5399 m_state
->DoInsert(parent
, -1, property
);
5402 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5403 wxPG_PROGRAMMATIC_VALUE
);
5408 // -----------------------------------------------------------------------
5410 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5412 m_propHierarchy
.push_back(property
);
5413 DoScanForChildren();
5414 m_propHierarchy
.pop_back();
5417 // -----------------------------------------------------------------------
5419 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5420 const wxString
& idString
)
5422 wxPGChoices choices
;
5425 if ( choicesString
[0] == wxT('@') )
5427 wxString ids
= choicesString
.substr(1);
5428 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5429 if ( it
== m_dictIdChoices
.end() )
5430 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5432 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5437 if ( idString
.length() )
5439 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5440 if ( it
!= m_dictIdChoices
.end() )
5442 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5449 // Parse choices string
5450 wxString::const_iterator it
= choicesString
.begin();
5454 bool labelValid
= false;
5456 for ( ; it
!= choicesString
.end(); ++it
)
5462 if ( c
== wxT('"') )
5467 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5468 choices
.Add(label
, l
);
5471 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5476 else if ( c
== wxT('=') )
5483 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5490 if ( c
== wxT('"') )
5503 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5504 choices
.Add(label
, l
);
5507 if ( !choices
.IsOk() )
5509 choices
.EnsureData();
5513 if ( idString
.length() )
5514 m_dictIdChoices
[idString
] = choices
.GetData();
5521 // -----------------------------------------------------------------------
5523 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5525 if ( s
.Last() == wxT('%') )
5527 wxString s2
= s
.substr(0,s
.length()-1);
5529 if ( s2
.ToLong(&val
, 10) )
5531 *pval
= (val
*max
)/100;
5537 return s
.ToLong(pval
, 10);
5540 // -----------------------------------------------------------------------
5542 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5543 const wxString
& type
,
5544 const wxString
& value
)
5546 int l
= m_propHierarchy
.size();
5550 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5551 wxString valuel
= value
.Lower();
5554 if ( type
.length() == 0 )
5559 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5561 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5563 else if ( value
.ToLong(&v
, 0) )
5570 if ( type
== wxT("string") )
5574 else if ( type
== wxT("int") )
5577 value
.ToLong(&v
, 0);
5580 else if ( type
== wxT("bool") )
5582 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5589 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5594 p
->SetAttribute( name
, variant
);
5599 // -----------------------------------------------------------------------
5601 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5603 wxLogError(_("Error in resource: %s"),msg
.c_str());
5606 // -----------------------------------------------------------------------
5608 #endif // wxUSE_PROPGRID