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
;
578 wxFont useFont
= wxScrolledWindow::GetFont();
579 wxScrolledWindow::SetOwnFont( useFont
);
583 // This should be otherwise called by SetOwnFont
584 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
587 // Allocate cell datas indirectly by calling setter
588 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
589 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
593 // This helps with flicker
594 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
597 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
598 m_tlp
= ::wxGetTopLevelParent(this);
599 m_tlwHandler
= handler
;
600 m_tlp
->PushEventHandler(handler
);
602 // set virtual size to this window size
603 wxSize wndsize
= GetSize();
604 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
606 m_timeCreated
= ::wxGetLocalTimeMillis();
608 m_canvas
= new wxPGCanvas();
609 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
610 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
611 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
613 m_iFlags
|= wxPG_FL_INITIALIZED
;
615 m_ncWidth
= wndsize
.GetWidth();
617 // Need to call OnResize handler or size given in constructor/Create
619 wxSizeEvent
sizeEvent(wndsize
,0);
623 // -----------------------------------------------------------------------
625 wxPropertyGrid::~wxPropertyGrid()
629 DoSelectProperty(NULL
);
631 // This should do prevent things from going too badly wrong
632 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
634 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
635 m_canvas
->ReleaseMouse();
637 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
638 m_tlp
->RemoveEventHandler(handler
);
642 if ( IsEditorsValueModified() )
643 ::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).)"),
644 wxS("wxPropertyGrid Debug Warning") );
647 #if wxPG_DOUBLE_BUFFER
648 if ( m_doubleBuffer
)
649 delete m_doubleBuffer
;
654 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
657 delete m_cursorSizeWE
;
659 #ifndef wxPG_ICON_WIDTH
664 // Delete common value records
665 for ( i
=0; i
<m_commonValues
.size(); i
++ )
667 delete GetCommonValue(i
);
671 // -----------------------------------------------------------------------
673 bool wxPropertyGrid::Destroy()
675 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
676 m_canvas
->ReleaseMouse();
678 return wxScrolledWindow::Destroy();
681 // -----------------------------------------------------------------------
683 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
685 return new wxPropertyGridPageState();
688 // -----------------------------------------------------------------------
689 // wxPropertyGrid overridden wxWindow methods
690 // -----------------------------------------------------------------------
692 void wxPropertyGrid::SetWindowStyleFlag( long style
)
694 long old_style
= m_windowStyle
;
696 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
698 wxASSERT( m_pState
);
700 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
703 EnableCategories( true );
705 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
707 // Disable categories
708 EnableCategories( false );
710 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
716 PrepareAfterItemsAdded();
718 m_pState
->m_itemsAdded
= 1;
720 #if wxPG_SUPPORT_TOOLTIPS
721 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
727 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
728 SetToolTip ( tooltip );
729 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
732 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
737 m_canvas
->SetToolTip( NULL
);
742 wxScrolledWindow::SetWindowStyleFlag ( style
);
744 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
746 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
748 CalculateFontAndBitmapStuff( m_vspacing
);
754 // -----------------------------------------------------------------------
756 void wxPropertyGrid::Freeze()
760 wxScrolledWindow::Freeze();
765 // -----------------------------------------------------------------------
767 void wxPropertyGrid::Thaw()
773 wxScrolledWindow::Thaw();
774 RecalculateVirtualSize();
775 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
779 // Force property re-selection
781 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
785 // -----------------------------------------------------------------------
787 void wxPropertyGrid::SetExtraStyle( long exStyle
)
789 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
791 #if defined(__WXMSW__)
794 // Don't use WS_EX_COMPOSITED just now.
797 if ( m_iFlags & wxPG_FL_IN_MANAGER )
798 hWnd = (HWND)GetParent()->GetHWND();
800 hWnd = (HWND)GetHWND();
802 ::SetWindowLong( hWnd, GWL_EXSTYLE,
803 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
806 //#elif defined(__WXGTK20__)
808 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
809 // truly was double-buffered.
810 if ( !this->IsDoubleBuffered() )
812 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
816 #if wxPG_DOUBLE_BUFFER
817 delete m_doubleBuffer
;
818 m_doubleBuffer
= NULL
;
823 wxScrolledWindow::SetExtraStyle( exStyle
);
825 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
826 m_pState
->InitNonCatMode();
828 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
829 m_windowStyle
|= wxPG_TOOLTIPS
;
832 wxPGGlobalVars
->m_extraStyle
= exStyle
;
835 // -----------------------------------------------------------------------
837 // returns the best acceptable minimal size
838 wxSize
wxPropertyGrid::DoGetBestSize() const
841 if ( m_lineHeight
> hei
)
843 wxSize sz
= wxSize( 60, hei
+40 );
849 // -----------------------------------------------------------------------
850 // wxPropertyGrid Font and Colour Methods
851 // -----------------------------------------------------------------------
853 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
857 m_captionFont
= wxScrolledWindow::GetFont();
859 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
860 m_subgroup_extramargin
= x
+ (x
/2);
863 #if wxPG_USE_RENDERER_NATIVE
864 m_iconWidth
= wxPG_ICON_WIDTH
;
865 #elif wxPG_ICON_WIDTH
867 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
868 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
869 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
873 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
874 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
875 m_gutterWidth
= wxPG_GUTTER_MIN
;
878 if ( vspacing
<= 1 ) vdiv
= 12;
879 else if ( vspacing
>= 3 ) vdiv
= 3;
881 m_spacingy
= m_fontHeight
/ vdiv
;
882 if ( m_spacingy
< wxPG_YSPACING_MIN
)
883 m_spacingy
= wxPG_YSPACING_MIN
;
886 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
887 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
889 m_captionFont
.SetWeight(wxBOLD
);
890 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
892 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
895 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
896 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
899 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
901 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
902 RecalculateVirtualSize();
904 InvalidateBestSize();
907 // -----------------------------------------------------------------------
909 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
915 // -----------------------------------------------------------------------
917 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
918 int ga
= 1000, int ba
= 1000,
919 bool forceDifferent
= false)
926 // Recursion guard (allow 2 max)
927 static int isinside
= 0;
929 wxCHECK_MSG( isinside
< 3,
931 wxT("wxPGAdjustColour should not be recursively called more than once") );
939 if ( r2
>255 ) r2
= 255;
940 else if ( r2
<0) r2
= 0;
942 if ( g2
>255 ) g2
= 255;
943 else if ( g2
<0) g2
= 0;
945 if ( b2
>255 ) b2
= 255;
946 else if ( b2
<0) b2
= 0;
948 // Make sure they are somewhat different
949 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
950 dst
= wxPGAdjustColour(src
,-(ra
*2));
952 dst
= wxColour(r2
,g2
,b2
);
954 // Recursion guard (allow 2 max)
961 static int wxPGGetColAvg( const wxColour
& col
)
963 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
967 void wxPropertyGrid::RegainColours()
969 if ( !(m_coloursCustomized
& 0x0002) )
971 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
973 // Make sure colour is dark enough
975 int colDec
= wxPGGetColAvg(col
) - 230;
977 int colDec
= wxPGGetColAvg(col
) - 200;
980 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
983 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
986 if ( !(m_coloursCustomized
& 0x0001) )
987 m_colMargin
= m_colCapBack
;
989 if ( !(m_coloursCustomized
& 0x0004) )
996 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
997 m_colCapFore
= capForeCol
;
998 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
1001 if ( !(m_coloursCustomized
& 0x0008) )
1003 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1004 m_colPropBack
= bgCol
;
1005 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1008 if ( !(m_coloursCustomized
& 0x0010) )
1010 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1011 m_colPropFore
= fgCol
;
1012 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1015 if ( !(m_coloursCustomized
& 0x0020) )
1016 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1018 if ( !(m_coloursCustomized
& 0x0040) )
1019 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1021 if ( !(m_coloursCustomized
& 0x0080) )
1022 m_colLine
= m_colCapBack
;
1024 if ( !(m_coloursCustomized
& 0x0100) )
1025 m_colDisPropFore
= m_colCapFore
;
1027 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1030 // -----------------------------------------------------------------------
1032 void wxPropertyGrid::ResetColours()
1034 m_coloursCustomized
= 0;
1041 // -----------------------------------------------------------------------
1043 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1045 // Must disable active editor.
1046 ClearSelection(false);
1048 // TODO: Following code is disabled with wxMac because
1049 // it is reported to fail. I (JMS) cannot debug it
1050 // personally right now.
1051 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1052 #if 1 // !defined(__WXMAC__)
1053 bool res
= wxScrolledWindow::SetFont( font
);
1056 CalculateFontAndBitmapStuff( m_vspacing
);
1059 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1067 // TODO: Remove after SetFont crash fixed.
1068 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1070 wxLogDebug(wxT("WARNING: propGrid.cpp: wxPropertyGrid::SetFont has been disabled on wxMac since there has been crash reported in it. If you are willing to debug the cause, replace line '#if !defined(__WXMAC__)' with line '#if 1' in wxPropertyGrid::SetFont."));
1076 // -----------------------------------------------------------------------
1078 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1081 m_coloursCustomized
|= 0x80;
1085 // -----------------------------------------------------------------------
1087 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1090 m_coloursCustomized
|= 0x01;
1094 // -----------------------------------------------------------------------
1096 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1098 m_colPropBack
= col
;
1099 m_coloursCustomized
|= 0x08;
1101 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1106 // -----------------------------------------------------------------------
1108 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1110 m_colPropFore
= col
;
1111 m_coloursCustomized
|= 0x10;
1113 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1118 // -----------------------------------------------------------------------
1120 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1122 m_colEmptySpace
= col
;
1127 // -----------------------------------------------------------------------
1129 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1131 m_colDisPropFore
= col
;
1132 m_coloursCustomized
|= 0x100;
1136 // -----------------------------------------------------------------------
1138 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1141 m_coloursCustomized
|= 0x20;
1145 // -----------------------------------------------------------------------
1147 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1150 m_coloursCustomized
|= 0x40;
1154 // -----------------------------------------------------------------------
1156 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1159 m_coloursCustomized
|= 0x02;
1161 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1166 // -----------------------------------------------------------------------
1168 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1171 m_coloursCustomized
|= 0x04;
1173 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1178 // -----------------------------------------------------------------------
1179 // wxPropertyGrid property adding and removal
1180 // -----------------------------------------------------------------------
1182 void wxPropertyGrid::PrepareAfterItemsAdded()
1184 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1186 m_pState
->m_itemsAdded
= 0;
1188 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1189 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
1191 RecalculateVirtualSize();
1194 // -----------------------------------------------------------------------
1195 // wxPropertyGrid property operations
1196 // -----------------------------------------------------------------------
1198 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1200 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1204 bool changed
= false;
1206 // Is it inside collapsed section?
1207 if ( !p
->IsVisible() )
1210 wxPGProperty
* parent
= p
->GetParent();
1211 wxPGProperty
* grandparent
= parent
->GetParent();
1213 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1214 Expand( grandparent
);
1222 GetViewStart(&vx
,&vy
);
1223 vy
*=wxPG_PIXELS_PER_UNIT
;
1229 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1230 m_iFlags
|= wxPG_FL_SCROLLED
;
1233 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1235 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1236 m_iFlags
|= wxPG_FL_SCROLLED
;
1246 // -----------------------------------------------------------------------
1247 // wxPropertyGrid helper methods called by properties
1248 // -----------------------------------------------------------------------
1250 // Control font changer helper.
1251 void wxPropertyGrid::SetCurControlBoldFont()
1253 wxASSERT( m_wndEditor
);
1254 m_wndEditor
->SetFont( m_captionFont
);
1257 // -----------------------------------------------------------------------
1259 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1262 #if wxPG_SMALL_SCREEN
1263 // On small-screen devices, always show dialogs with default position and size.
1264 return wxDefaultPosition
;
1266 int splitterX
= GetSplitterPosition();
1270 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1272 ImprovedClientToScreen( &x
, &y
);
1274 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1275 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1282 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1292 new_y
= y
+ m_lineHeight
;
1294 return wxPoint(new_x
,new_y
);
1298 // -----------------------------------------------------------------------
1300 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1302 if ( src_str
.length() == 0 )
1308 bool prev_is_slash
= false;
1310 wxString::const_iterator i
= src_str
.begin();
1314 for ( ; i
!= src_str
.end(); ++i
)
1318 if ( a
!= wxS('\\') )
1320 if ( !prev_is_slash
)
1326 if ( a
== wxS('n') )
1329 dst_str
<< wxS('\n');
1331 dst_str
<< wxS('\n');
1334 else if ( a
== wxS('t') )
1335 dst_str
<< wxS('\t');
1339 prev_is_slash
= false;
1343 if ( prev_is_slash
)
1345 dst_str
<< wxS('\\');
1346 prev_is_slash
= false;
1350 prev_is_slash
= true;
1357 // -----------------------------------------------------------------------
1359 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1361 if ( src_str
.length() == 0 )
1367 wxString::const_iterator i
= src_str
.begin();
1368 wxUniChar prev_a
= wxS('\0');
1372 for ( ; i
!= src_str
.end(); ++i
)
1376 if ( a
>= wxS(' ') )
1378 // This surely is not something that requires an escape sequence.
1383 // This might need...
1384 if ( a
== wxS('\r') )
1386 // DOS style line end.
1387 // Already taken care below
1389 else if ( a
== wxS('\n') )
1390 // UNIX style line end.
1391 dst_str
<< wxS("\\n");
1392 else if ( a
== wxS('\t') )
1394 dst_str
<< wxS('\t');
1397 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1407 // -----------------------------------------------------------------------
1409 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1416 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1419 // -----------------------------------------------------------------------
1420 // wxPropertyGrid graphics related methods
1421 // -----------------------------------------------------------------------
1423 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1427 // Update everything inside the box
1428 wxRect r
= GetUpdateRegion().GetBox();
1430 dc
.SetPen(m_colEmptySpace
);
1431 dc
.SetBrush(m_colEmptySpace
);
1432 dc
.DrawRectangle(r
);
1435 // -----------------------------------------------------------------------
1437 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1438 wxPGProperty
* property
) const
1440 // Prepare rectangle to be used
1442 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1443 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1445 #if (wxPG_USE_RENDERER_NATIVE)
1447 #elif wxPG_ICON_WIDTH
1448 // Drawing expand/collapse button manually
1449 dc
.SetPen(m_colPropFore
);
1450 if ( property
->IsCategory() )
1451 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1453 dc
.SetBrush(m_colPropBack
);
1455 dc
.DrawRectangle( r
);
1456 int _y
= r
.y
+(m_iconWidth
/2);
1457 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1462 if ( property
->IsExpanded() )
1464 // wxRenderer functions are non-mutating in nature, so it
1465 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1466 // Hopefully this does not cause problems.
1467 #if (wxPG_USE_RENDERER_NATIVE)
1468 wxRendererNative::Get().DrawTreeItemButton(
1474 #elif wxPG_ICON_WIDTH
1483 #if (wxPG_USE_RENDERER_NATIVE)
1484 wxRendererNative::Get().DrawTreeItemButton(
1490 #elif wxPG_ICON_WIDTH
1491 int _x
= r
.x
+(m_iconWidth
/2);
1492 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1498 #if (wxPG_USE_RENDERER_NATIVE)
1500 #elif wxPG_ICON_WIDTH
1503 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1507 // -----------------------------------------------------------------------
1510 // This is the one called by OnPaint event handler and others.
1511 // topy and bottomy are already unscrolled (ie. physical)
1513 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1515 unsigned int bottomy
,
1516 const wxRect
* clipRect
)
1518 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1520 m_pState
->EnsureVirtualHeight();
1522 wxRect tempClipRect
;
1525 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1526 clipRect
= &tempClipRect
;
1529 // items added check
1530 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1532 int paintFinishY
= 0;
1534 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1537 bool isBuffered
= false;
1539 #if wxPG_DOUBLE_BUFFER
1540 wxMemoryDC
* bufferDC
= NULL
;
1542 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1544 if ( !m_doubleBuffer
)
1546 paintFinishY
= clipRect
->y
;
1551 bufferDC
= new wxMemoryDC();
1553 // If nothing was changed, then just copy from double-buffer
1554 bufferDC
->SelectObject( *m_doubleBuffer
);
1564 dc
.SetClippingRegion( *clipRect
);
1565 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1568 #if wxPG_DOUBLE_BUFFER
1571 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1572 bufferDC
, 0, 0, wxCOPY
);
1573 dc
.DestroyClippingRegion(); // Is this really necessary?
1579 // Clear area beyond bottomY?
1580 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1582 dc
.SetPen(m_colEmptySpace
);
1583 dc
.SetBrush(m_colEmptySpace
);
1584 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1588 // -----------------------------------------------------------------------
1590 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1591 const wxPGProperty
* firstItem
,
1592 const wxPGProperty
* lastItem
,
1593 const wxRect
* clipRect
,
1594 bool isBuffered
) const
1596 // TODO: This should somehow be eliminated.
1597 wxRect tempClipRect
;
1600 wxASSERT(firstItem
);
1602 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1603 clipRect
= &tempClipRect
;
1607 firstItem
= DoGetItemAtY(clipRect
->y
);
1611 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1613 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1616 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1619 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1620 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1622 int lh
= m_lineHeight
;
1625 int lastItemBottomY
;
1627 firstItemTopY
= clipRect
->y
;
1628 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1630 // Align y coordinates to item boundaries
1631 firstItemTopY
-= firstItemTopY
% lh
;
1632 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1633 lastItemBottomY
-= 1;
1635 // Entire range outside scrolled, visible area?
1636 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1639 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1643 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1644 firstItem->GetLabel().c_str(),
1645 lastItem->GetLabel().c_str(),
1646 (int)(lastItemBottomY - firstItemTopY),
1648 (unsigned long)clipRect );
1653 long windowStyle
= m_windowStyle
;
1659 // With wxPG_DOUBLE_BUFFER, do double buffering
1660 // - buffer's y = 0, so align cliprect and coordinates to that
1662 #if wxPG_DOUBLE_BUFFER
1668 xRelMod
= clipRect
->x
;
1669 yRelMod
= clipRect
->y
;
1672 // clipRect conversion
1677 firstItemTopY
-= yRelMod
;
1678 lastItemBottomY
-= yRelMod
;
1681 wxUnusedVar(isBuffered
);
1684 int x
= m_marginWidth
- xRelMod
;
1686 const wxFont
& normalfont
= m_font
;
1688 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1690 bool isEnabled
= IsEnabled();
1693 // Prepare some pens and brushes that are often changed to.
1696 wxBrush
marginBrush(m_colMargin
);
1697 wxPen
marginPen(m_colMargin
);
1698 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1699 wxPen
linepen(m_colLine
,1,wxSOLID
);
1701 // pen that has same colour as text
1702 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1705 // Clear margin with background colour
1707 dc
.SetBrush( marginBrush
);
1708 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1710 dc
.SetPen( *wxTRANSPARENT_PEN
);
1711 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1714 const wxPGProperty
* selected
= m_selected
;
1715 const wxPropertyGridPageState
* state
= m_pState
;
1717 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1718 bool wasSelectedPainted
= false;
1721 // TODO: Only render columns that are within clipping region.
1723 dc
.SetFont(normalfont
);
1725 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1726 int endScanBottomY
= lastItemBottomY
+ lh
;
1727 int y
= firstItemTopY
;
1730 // Pregenerate list of visible properties.
1731 wxArrayPGProperty visPropArray
;
1732 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1734 for ( ; !it
.AtEnd(); it
.Next() )
1736 const wxPGProperty
* p
= *it
;
1738 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1740 visPropArray
.push_back((wxPGProperty
*)p
);
1742 if ( y
> endScanBottomY
)
1749 visPropArray
.push_back(NULL
);
1751 wxPGProperty
* nextP
= visPropArray
[0];
1753 int gridWidth
= state
->m_width
;
1756 for ( unsigned int arrInd
=1;
1757 nextP
&& y
<= lastItemBottomY
;
1760 wxPGProperty
* p
= nextP
;
1761 nextP
= visPropArray
[arrInd
];
1763 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1764 int textMarginHere
= x
;
1765 int renderFlags
= 0;
1767 int greyDepth
= m_marginWidth
;
1768 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1769 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1771 int greyDepthX
= greyDepth
- xRelMod
;
1773 // Use basic depth if in non-categoric mode and parent is base array.
1774 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1776 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1779 // Paint margin area
1780 dc
.SetBrush(marginBrush
);
1781 dc
.SetPen(marginPen
);
1782 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1784 dc
.SetPen( linepen
);
1789 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1795 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1797 sx
+= state
->m_colWidths
[si
];
1798 dc
.DrawLine( sx
, y
, sx
, y2
);
1801 // Horizontal Line, below
1802 // (not if both this and next is category caption)
1803 if ( p
->IsCategory() &&
1804 nextP
&& nextP
->IsCategory() )
1805 dc
.SetPen(m_colCapBack
);
1807 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1810 // Need to override row colours?
1814 if ( p
!= selected
)
1816 // Disabled may get different colour.
1817 if ( !p
->IsEnabled() )
1819 renderFlags
|= wxPGCellRenderer::Disabled
|
1820 wxPGCellRenderer::DontUseCellFgCol
;
1821 rowFgCol
= m_colDisPropFore
;
1826 renderFlags
|= wxPGCellRenderer::Selected
;
1828 if ( !p
->IsCategory() )
1830 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1831 wxPGCellRenderer::DontUseCellBgCol
;
1833 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1834 wasSelectedPainted
= true;
1837 // Selected gets different colour.
1838 if ( reallyFocused
)
1840 rowFgCol
= m_colSelFore
;
1841 rowBgCol
= m_colSelBack
;
1843 else if ( isEnabled
)
1845 rowFgCol
= m_colPropFore
;
1846 rowBgCol
= m_colMargin
;
1850 rowFgCol
= m_colDisPropFore
;
1851 rowBgCol
= m_colSelBack
;
1858 if ( rowBgCol
.IsOk() )
1859 rowBgBrush
= wxBrush(rowBgCol
);
1861 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1862 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1865 // Fill additional margin area with background colour of first cell
1866 if ( greyDepthX
< textMarginHere
)
1868 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1870 wxPGCell
& cell
= p
->GetCell(0);
1871 rowBgCol
= cell
.GetBgCol();
1872 rowBgBrush
= wxBrush(rowBgCol
);
1874 dc
.SetBrush(rowBgBrush
);
1875 dc
.SetPen(rowBgCol
);
1876 dc
.DrawRectangle(greyDepthX
+1, y
,
1877 textMarginHere
-greyDepthX
, lh
-1);
1880 bool fontChanged
= false;
1882 // Expander button rectangle
1883 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1888 if ( p
->IsCategory() )
1890 // Captions have their cell areas merged as one
1891 dc
.SetFont(m_captionFont
);
1893 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1895 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1897 dc
.SetBrush(rowBgBrush
);
1898 dc
.SetPen(rowBgCol
);
1901 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1903 dc
.SetTextForeground(rowFgCol
);
1906 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1907 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1910 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1911 DrawExpanderButton( dc
, butRect
, p
);
1915 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1917 dc
.SetFont(m_captionFont
);
1923 int nextCellWidth
= state
->m_colWidths
[0] -
1924 (greyDepthX
- m_marginWidth
);
1925 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1926 int textXAdd
= textMarginHere
- greyDepthX
;
1928 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1930 cellRect
.width
= nextCellWidth
- 1;
1932 bool ctrlCell
= false;
1933 int cellRenderFlags
= renderFlags
;
1936 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1937 DrawExpanderButton( dc
, butRect
, p
);
1940 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1942 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1943 dc
.SetBrush(editorBgCol
);
1944 dc
.SetPen(editorBgCol
);
1945 dc
.SetTextForeground(m_colPropFore
);
1946 dc
.DrawRectangle(cellRect
);
1948 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1953 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1955 dc
.SetBrush(rowBgBrush
);
1956 dc
.SetPen(rowBgCol
);
1959 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1961 dc
.SetTextForeground(rowFgCol
);
1965 dc
.SetClippingRegion(cellRect
);
1967 cellRect
.x
+= textXAdd
;
1968 cellRect
.width
-= textXAdd
;
1973 wxPGCellRenderer
* renderer
;
1974 int cmnVal
= p
->GetCommonValue();
1975 if ( cmnVal
== -1 || ci
!= 1 )
1977 renderer
= p
->GetCellRenderer(ci
);
1978 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1983 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1984 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1989 cellX
+= state
->m_colWidths
[ci
];
1990 if ( ci
< (state
->m_colWidths
.size()-1) )
1991 nextCellWidth
= state
->m_colWidths
[ci
+1];
1993 dc
.DestroyClippingRegion(); // Is this really necessary?
1999 dc
.SetFont(normalfont
);
2004 // Refresh editor controls (seems not needed on msw)
2005 // NOTE: This code is mandatory for GTK!
2006 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2007 if ( wasSelectedPainted
)
2010 m_wndEditor
->Refresh();
2012 m_wndEditor2
->Refresh();
2019 // -----------------------------------------------------------------------
2021 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2025 if ( m_width
< 10 || m_height
< 10 ||
2026 !m_pState
->m_properties
->GetChildCount() ||
2028 return wxRect(0,0,0,0);
2033 // Return rect which encloses the given property range
2035 int visTop
= p1
->GetY();
2038 visBottom
= p2
->GetY() + m_lineHeight
;
2040 visBottom
= m_height
+ visTop
;
2042 // If seleced property is inside the range, we'll extend the range to include
2044 wxPGProperty
* selected
= m_selected
;
2047 int selectedY
= selected
->GetY();
2048 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2050 wxWindow
* editor
= GetEditorControl();
2053 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2054 if ( visBottom2
> visBottom
)
2055 visBottom
= visBottom2
;
2060 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2063 // -----------------------------------------------------------------------
2065 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2070 if ( m_pState
->m_itemsAdded
)
2071 PrepareAfterItemsAdded();
2073 wxRect r
= GetPropertyRect(p1
, p2
);
2076 m_canvas
->RefreshRect(r
);
2080 // -----------------------------------------------------------------------
2082 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2084 if ( p
== m_selected
)
2085 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2087 DrawItemAndChildren(p
);
2090 // -----------------------------------------------------------------------
2092 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2097 // Draw item, children, and parent too, if it is not category
2098 wxPGProperty
* parent
= p
->GetParent();
2101 !parent
->IsCategory() &&
2102 parent
->GetParent() )
2105 parent
= parent
->GetParent();
2108 DrawItemAndChildren(p
);
2111 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2113 wxCHECK_RET( p
, wxT("invalid property id") );
2115 // Do not draw if in non-visible page
2116 if ( p
->GetParentState() != m_pState
)
2119 // do not draw a single item if multiple pending
2120 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2123 // Update child control.
2124 if ( m_selected
&& m_selected
->GetParent() == p
)
2127 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2129 DrawItems(p
, lastDrawn
);
2132 // -----------------------------------------------------------------------
2134 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2135 const wxRect
*rect
)
2137 PrepareAfterItemsAdded();
2139 wxWindow::Refresh(false);
2141 // TODO: Coordinate translation
2142 m_canvas
->Refresh(false, rect
);
2144 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2145 // I think this really helps only GTK+1.2
2146 if ( m_wndEditor
) m_wndEditor
->Refresh();
2147 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2151 // -----------------------------------------------------------------------
2152 // wxPropertyGrid global operations
2153 // -----------------------------------------------------------------------
2155 void wxPropertyGrid::Clear()
2157 ClearSelection(false);
2159 m_pState
->DoClear();
2165 RecalculateVirtualSize();
2167 // Need to clear some area at the end
2169 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2172 // -----------------------------------------------------------------------
2174 bool wxPropertyGrid::EnableCategories( bool enable
)
2176 ClearSelection(false);
2181 // Enable categories
2184 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2189 // Disable categories
2191 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2194 if ( !m_pState
->EnableCategories(enable
) )
2199 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2201 m_pState
->m_itemsAdded
= 1; // force
2202 PrepareAfterItemsAdded();
2206 m_pState
->m_itemsAdded
= 1;
2208 // No need for RecalculateVirtualSize() here - it is already called in
2209 // wxPropertyGridPageState method above.
2216 // -----------------------------------------------------------------------
2218 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2220 wxASSERT( pNewState
);
2221 wxASSERT( pNewState
->GetGrid() );
2223 if ( pNewState
== m_pState
)
2226 wxPGProperty
* oldSelection
= m_selected
;
2228 ClearSelection(false);
2230 m_pState
->m_selected
= oldSelection
;
2232 bool orig_mode
= m_pState
->IsInNonCatMode();
2233 bool new_state_mode
= pNewState
->IsInNonCatMode();
2235 m_pState
= pNewState
;
2238 int pgWidth
= GetClientSize().x
;
2239 if ( HasVirtualWidth() )
2241 int minWidth
= pgWidth
;
2242 if ( pNewState
->m_width
< minWidth
)
2244 pNewState
->m_width
= minWidth
;
2245 pNewState
->CheckColumnWidths();
2251 // Just in case, fully re-center splitter
2252 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2253 pNewState
->m_fSplitterX
= -1.0;
2255 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2260 // If necessary, convert state to correct mode.
2261 if ( orig_mode
!= new_state_mode
)
2263 // This should refresh as well.
2264 EnableCategories( orig_mode
?false:true );
2266 else if ( !m_frozen
)
2268 // Refresh, if not frozen.
2269 m_pState
->PrepareAfterItemsAdded();
2272 if ( m_pState
->m_selected
)
2273 DoSelectProperty( m_pState
->m_selected
);
2275 RecalculateVirtualSize(0);
2279 m_pState
->m_itemsAdded
= 1;
2282 // -----------------------------------------------------------------------
2284 // Call to SetSplitterPosition will always disable splitter auto-centering
2285 // if parent window is shown.
2286 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2288 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2291 wxPropertyGridPageState
* state
= m_pState
;
2293 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2298 CorrectEditorWidgetSizeX();
2304 // -----------------------------------------------------------------------
2306 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2308 SetSplitterPosition( m_width
/2, true );
2309 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2310 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2313 // -----------------------------------------------------------------------
2314 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2315 // -----------------------------------------------------------------------
2317 // Returns nearest paint visible property (such that will be painted unless
2318 // window is scrolled or resized). If given property is paint visible, then
2319 // it itself will be returned
2320 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2322 int vx
,vy1
;// Top left corner of client
2323 GetViewStart(&vx
,&vy1
);
2324 vy1
*= wxPG_PIXELS_PER_UNIT
;
2326 int vy2
= vy1
+ m_height
;
2327 int propY
= p
->GetY2(m_lineHeight
);
2329 if ( (propY
+ m_lineHeight
) < vy1
)
2332 return DoGetItemAtY( vy1
);
2334 else if ( propY
> vy2
)
2337 return DoGetItemAtY( vy2
);
2340 // Itself paint visible
2345 // -----------------------------------------------------------------------
2346 // Methods related to change in value, value modification and sending events
2347 // -----------------------------------------------------------------------
2349 // commits any changes in editor of selected property
2350 // return true if validation did not fail
2351 // flags are same as with DoSelectProperty
2352 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2354 // Committing already?
2355 if ( m_inCommitChangesFromEditor
)
2358 // Don't do this if already processing editor event. It might
2359 // induce recursive dialogs and crap like that.
2360 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2362 if ( m_inDoPropertyChanged
)
2369 IsEditorsValueModified() &&
2370 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2373 m_inCommitChangesFromEditor
= 1;
2375 wxVariant
variant(m_selected
->GetValueRef());
2376 bool valueIsPending
= false;
2378 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2379 // due to another window getting focus
2380 wxWindow
* oldFocus
= m_curFocused
;
2382 bool validationFailure
= false;
2383 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2385 m_chgInfo_changedProperty
= NULL
;
2387 // If truly modified, schedule value as pending.
2388 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2390 if ( DoEditorValidate() &&
2391 PerformValidation(m_selected
, variant
) )
2393 valueIsPending
= true;
2397 validationFailure
= true;
2402 EditorsValueWasNotModified();
2407 m_inCommitChangesFromEditor
= 0;
2409 if ( validationFailure
&& !forceSuccess
)
2413 oldFocus
->SetFocus();
2414 m_curFocused
= oldFocus
;
2417 res
= OnValidationFailure(m_selected
, variant
);
2419 // Now prevent further validation failure messages
2422 EditorsValueWasNotModified();
2423 OnValidationFailureReset(m_selected
);
2426 else if ( valueIsPending
)
2428 DoPropertyChanged( m_selected
, flags
);
2429 EditorsValueWasNotModified();
2438 // -----------------------------------------------------------------------
2440 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2444 // Runs all validation functionality.
2445 // Returns true if value passes all tests.
2448 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2450 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2452 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2457 // Adapt list to child values, if necessary
2458 wxVariant listValue
= pendingValue
;
2459 wxVariant
* pPendingValue
= &pendingValue
;
2460 wxVariant
* pList
= NULL
;
2462 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2463 // string value, then we need treat as it was changed instead
2464 // (or, in addition, as is the case with composite string parent).
2465 // This includes creating list variant for child values.
2467 wxPGProperty
* pwc
= p
->GetParent();
2468 wxPGProperty
* changedProperty
= p
;
2469 wxPGProperty
* baseChangedProperty
= changedProperty
;
2470 wxVariant bcpPendingList
;
2472 listValue
= pendingValue
;
2473 listValue
.SetName(p
->GetBaseName());
2476 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2478 wxVariantList tempList
;
2479 wxVariant
lv(tempList
, pwc
->GetBaseName());
2480 lv
.Append(listValue
);
2482 pPendingValue
= &listValue
;
2484 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2486 baseChangedProperty
= pwc
;
2487 bcpPendingList
= lv
;
2490 changedProperty
= pwc
;
2491 pwc
= pwc
->GetParent();
2495 wxPGProperty
* evtChangingProperty
= changedProperty
;
2497 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2499 value
= *pPendingValue
;
2503 // Convert list to child values
2504 pList
= pPendingValue
;
2505 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2508 wxVariant evtChangingValue
= value
;
2510 if ( flags
& SendEvtChanging
)
2512 // FIXME: After proper ValueToString()s added, remove
2513 // this. It is just a temporary fix, as evt_changing
2514 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2515 // (unless it is selected, and textctrl editor is open).
2516 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2518 evtChangingProperty
= baseChangedProperty
;
2519 if ( evtChangingProperty
!= p
)
2521 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2525 evtChangingValue
= pendingValue
;
2529 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2531 if ( changedProperty
== m_selected
)
2533 wxWindow
* editor
= GetEditorControl();
2534 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2535 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2539 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2544 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2545 m_chgInfo_changedProperty
= changedProperty
;
2546 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2547 m_chgInfo_pendingValue
= value
;
2550 m_chgInfo_valueList
= *pList
;
2552 m_chgInfo_valueList
.MakeNull();
2554 // If changedProperty is not property which value was edited,
2555 // then call wxPGProperty::ValidateValue() for that as well.
2556 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2558 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2562 if ( flags
& SendEvtChanging
)
2564 // SendEvent returns true if event was vetoed
2565 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2569 if ( flags
& IsStandaloneValidation
)
2571 // If called in 'generic' context, we need to reset
2572 // m_chgInfo_changedProperty and write back translated value.
2573 m_chgInfo_changedProperty
= NULL
;
2574 pendingValue
= value
;
2580 // -----------------------------------------------------------------------
2582 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2584 if ( !msg
.length() )
2588 if ( !wxPGGlobalVars
->m_offline
)
2590 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2593 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2596 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2599 pStatusBar
->SetStatusText(msg
);
2607 ::wxMessageBox(msg
, _T("Property Error"));
2610 // -----------------------------------------------------------------------
2612 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2613 wxVariant
& invalidValue
)
2615 wxWindow
* editor
= GetEditorControl();
2617 // First call property's handler
2618 property
->OnValidationFailure(invalidValue
);
2620 bool res
= DoOnValidationFailure(property
, invalidValue
);
2623 // For non-wxTextCtrl editors, we do need to revert the value
2624 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2625 property
== m_selected
)
2627 property
->GetEditorClass()->UpdateControl(property
, editor
);
2630 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2635 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2637 int vfb
= m_validationInfo
.m_failureBehavior
;
2639 if ( vfb
& wxPG_VFB_BEEP
)
2642 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2643 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2645 unsigned int colCount
= m_pState
->GetColumnCount();
2647 // We need backup marked property's cells
2648 m_propCellsBackup
= property
->m_cells
;
2650 wxColour vfbFg
= *wxWHITE
;
2651 wxColour vfbBg
= *wxRED
;
2653 property
->EnsureCells(colCount
);
2655 for ( unsigned int i
=0; i
<colCount
; i
++ )
2657 wxPGCell
& cell
= property
->m_cells
[i
];
2658 cell
.SetFgCol(vfbFg
);
2659 cell
.SetBgCol(vfbBg
);
2662 DrawItemAndChildren(property
);
2664 if ( property
== m_selected
)
2666 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2668 wxWindow
* editor
= GetEditorControl();
2671 editor
->SetForegroundColour(vfbFg
);
2672 editor
->SetBackgroundColour(vfbBg
);
2677 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2679 wxString msg
= m_validationInfo
.m_failureMessage
;
2681 if ( !msg
.length() )
2682 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2684 DoShowPropertyError(property
, msg
);
2687 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2690 // -----------------------------------------------------------------------
2692 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2694 int vfb
= m_validationInfo
.m_failureBehavior
;
2696 if ( vfb
& wxPG_VFB_MARK_CELL
)
2699 property
->m_cells
= m_propCellsBackup
;
2701 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2703 if ( property
== m_selected
&& GetEditorControl() )
2705 // Calling this will recreate the control, thus resetting its colour
2706 RefreshProperty(property
);
2710 DrawItemAndChildren(property
);
2715 // -----------------------------------------------------------------------
2717 // flags are same as with DoSelectProperty
2718 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2720 if ( m_inDoPropertyChanged
)
2723 wxWindow
* editor
= GetEditorControl();
2725 m_pState
->m_anyModified
= 1;
2727 m_inDoPropertyChanged
= 1;
2729 // Maybe need to update control
2730 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2732 // These values were calculated in PerformValidation()
2733 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2734 wxVariant value
= m_chgInfo_pendingValue
;
2736 wxPGProperty
* topPaintedProperty
= changedProperty
;
2738 while ( !topPaintedProperty
->IsCategory() &&
2739 !topPaintedProperty
->IsRoot() )
2741 topPaintedProperty
= topPaintedProperty
->GetParent();
2744 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2746 // Set as Modified (not if dragging just began)
2747 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2749 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2750 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2753 SetCurControlBoldFont();
2759 // Propagate updates to parent(s)
2761 wxPGProperty
* prevPwc
= NULL
;
2763 while ( prevPwc
!= topPaintedProperty
)
2765 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2767 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2770 SetCurControlBoldFont();
2774 pwc
= pwc
->GetParent();
2777 // Draw the actual property
2778 DrawItemAndChildren( topPaintedProperty
);
2781 // If value was set by wxPGProperty::OnEvent, then update the editor
2783 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2789 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2790 if ( m_wndEditor
) m_wndEditor
->Refresh();
2791 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2796 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2798 // If top parent has composite string value, then send to child parents,
2799 // starting from baseChangedProperty.
2800 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2802 pwc
= m_chgInfo_baseChangedProperty
;
2804 while ( pwc
!= changedProperty
)
2806 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2807 pwc
= pwc
->GetParent();
2811 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2813 m_inDoPropertyChanged
= 0;
2818 // -----------------------------------------------------------------------
2820 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2822 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2824 m_chgInfo_changedProperty
= NULL
;
2826 if ( PerformValidation(p
, newValue
) )
2828 DoPropertyChanged(p
);
2833 OnValidationFailure(p
, newValue
);
2839 // -----------------------------------------------------------------------
2841 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2843 wxPGProperty
* prop
= GetSelectedProperty();
2846 return wxNullVariant
;
2848 wxTextCtrl
* tc
= GetEditorTextCtrl();
2849 wxVariant value
= prop
->GetValue();
2851 if ( !tc
|| !IsEditorsValueModified() )
2854 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2857 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2858 return prop
->GetValue();
2863 // -----------------------------------------------------------------------
2865 // Runs wxValidator for the selected property
2866 bool wxPropertyGrid::DoEditorValidate()
2871 // -----------------------------------------------------------------------
2873 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2875 wxPGProperty
* selected
= m_selected
;
2877 // Somehow, event is handled after property has been deselected.
2878 // Possibly, but very rare.
2882 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2885 wxVariant
pendingValue(selected
->GetValueRef());
2886 wxWindow
* wnd
= GetEditorControl();
2888 bool wasUnspecified
= selected
->IsValueUnspecified();
2889 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2891 bool valueIsPending
= false;
2893 m_chgInfo_changedProperty
= NULL
;
2895 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2898 // Filter out excess wxTextCtrl modified events
2899 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2901 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2903 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2905 wxString newTcValue
= tc
->GetValue();
2906 if ( m_prevTcValue
== newTcValue
)
2909 m_prevTcValue
= newTcValue
;
2912 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2914 bool validationFailure
= false;
2915 bool buttonWasHandled
= false;
2918 // Try common button handling
2919 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2921 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2925 buttonWasHandled
= true;
2926 // Store as res2, as previously (and still currently alternatively)
2927 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2928 // in wxPGProperty::OnEvent().
2929 adapter
->ShowDialog( this, selected
);
2934 if ( !buttonWasHandled
)
2938 // First call editor class' event handler.
2939 const wxPGEditor
* editor
= selected
->GetEditorClass();
2941 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2943 // If changes, validate them
2944 if ( DoEditorValidate() )
2946 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
2947 valueIsPending
= true;
2951 validationFailure
= true;
2956 // Then the property's custom handler (must be always called, unless
2957 // validation failed).
2958 if ( !validationFailure
)
2959 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
2962 // SetValueInEvent(), as called in one of the functions referred above
2963 // overrides editor's value.
2964 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2966 valueIsPending
= true;
2967 pendingValue
= m_changeInEventValue
;
2968 selFlags
|= wxPG_SEL_DIALOGVAL
;
2971 if ( !validationFailure
&& valueIsPending
)
2972 if ( !PerformValidation(m_selected
, pendingValue
) )
2973 validationFailure
= true;
2975 if ( validationFailure
)
2977 OnValidationFailure(selected
, pendingValue
);
2979 else if ( valueIsPending
)
2981 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2983 DoPropertyChanged(selected
, selFlags
);
2984 EditorsValueWasNotModified();
2986 // Regardless of editor type, unfocus editor on
2987 // text-editing related enter press.
2988 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2995 // No value after all
2997 // Regardless of editor type, unfocus editor on
2998 // text-editing related enter press.
2999 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3004 // Let unhandled button click events go to the parent
3005 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3007 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3008 GetEventHandler()->AddPendingEvent(evt
);
3012 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3015 // -----------------------------------------------------------------------
3016 // wxPropertyGrid editor control helper methods
3017 // -----------------------------------------------------------------------
3019 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3021 int itemy
= p
->GetY2(m_lineHeight
);
3023 int cust_img_space
= 0;
3024 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3025 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3027 // TODO: If custom image detection changes from current, change this.
3028 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3030 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3031 int imwid
= p
->OnMeasureImage().x
;
3032 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3033 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3038 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3040 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3045 // -----------------------------------------------------------------------
3047 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3049 wxSize sz
= GetImageSize(p
, item
);
3050 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3051 wxPG_CUSTOM_IMAGE_SPACINGY
,
3056 // return size of custom paint image
3057 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3059 // If called with NULL property, then return default image
3060 // size for properties that use image.
3062 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3064 wxSize cis
= p
->OnMeasureImage(item
);
3066 int choiceCount
= p
->m_choices
.GetCount();
3067 int comVals
= p
->GetDisplayedCommonValueCount();
3068 if ( item
>= choiceCount
&& comVals
> 0 )
3070 unsigned int cvi
= item
-choiceCount
;
3071 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3073 else if ( item
>= 0 && choiceCount
== 0 )
3074 return wxSize(0, 0);
3079 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3084 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3091 // -----------------------------------------------------------------------
3093 // takes scrolling into account
3094 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3097 GetViewStart(&vx
,&vy
);
3098 vy
*=wxPG_PIXELS_PER_UNIT
;
3099 vx
*=wxPG_PIXELS_PER_UNIT
;
3102 ClientToScreen( px
, py
);
3105 // -----------------------------------------------------------------------
3107 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3110 GetViewStart(&pt2
.x
,&pt2
.y
);
3111 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3112 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3116 return m_pState
->HitTest(pt2
);
3119 // -----------------------------------------------------------------------
3121 // custom set cursor
3122 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3124 if ( type
== m_curcursor
&& !override
) return;
3126 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3128 if ( type
== wxCURSOR_SIZEWE
)
3129 cursor
= m_cursorSizeWE
;
3131 m_canvas
->SetCursor( *cursor
);
3136 // -----------------------------------------------------------------------
3137 // wxPropertyGrid property selection, editor creation
3138 // -----------------------------------------------------------------------
3141 // This class forwards events from property editor controls to wxPropertyGrid.
3142 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3145 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3146 : wxEvtHandler(), m_propGrid(propGrid
)
3150 virtual ~wxPropertyGridEditorEventForwarder()
3155 bool ProcessEvent( wxEvent
& event
)
3160 m_propGrid
->HandleCustomEditorEvent(event
);
3162 return wxEvtHandler::ProcessEvent(event
);
3165 wxPropertyGrid
* m_propGrid
;
3168 // Setups event handling for child control
3169 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3171 wxWindowID id
= argWnd
->GetId();
3173 if ( argWnd
== m_wndEditor
)
3175 argWnd
->Connect(id
, wxEVT_MOTION
,
3176 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3178 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3179 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3181 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3182 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3184 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3185 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3187 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3188 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3190 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3191 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3195 wxPropertyGridEditorEventForwarder
* forwarder
;
3196 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3197 argWnd
->PushEventHandler(forwarder
);
3199 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3200 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3204 void wxPropertyGrid::FreeEditors()
3207 // Return focus back to canvas from children (this is required at least for
3208 // GTK+, which, unlike Windows, clears focus when control is destroyed
3209 // instead of moving it to closest parent).
3210 wxWindow
* focus
= wxWindow::FindFocus();
3213 wxWindow
* parent
= focus
->GetParent();
3216 if ( parent
== m_canvas
)
3221 parent
= parent
->GetParent();
3225 // Do not free editors immediately if processing events
3228 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3229 m_wndEditor2
->Hide();
3230 wxPendingDelete
.Append( handler
);
3231 wxPendingDelete
.Append( m_wndEditor2
);
3232 m_wndEditor2
= NULL
;
3237 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3238 m_wndEditor
->Hide();
3239 wxPendingDelete
.Append( handler
);
3240 wxPendingDelete
.Append( m_wndEditor
);
3245 // Call with NULL to de-select property
3246 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3250 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3251 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3253 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3256 if ( m_inDoSelectProperty
)
3259 m_inDoSelectProperty
= 1;
3261 wxPGProperty
* prev
= m_selected
;
3265 m_inDoSelectProperty
= 0;
3271 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3273 wxPrintf( "None selected\n" );
3276 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3278 wxPrintf( "P = NULL\n" );
3281 // If we are frozen, then just set the values.
3284 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3285 m_editorFocused
= 0;
3288 m_pState
->m_selected
= p
;
3290 // If frozen, always free controls. But don't worry, as Thaw will
3291 // recall SelectProperty to recreate them.
3294 // Prevent any further selection measures in this call
3300 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3302 // Only set focus if not deselecting
3305 if ( flags
& wxPG_SEL_FOCUS
)
3309 m_wndEditor
->SetFocus();
3310 m_editorFocused
= 1;
3319 m_inDoSelectProperty
= 0;
3324 // First, deactivate previous
3328 OnValidationFailureReset(m_selected
);
3330 // Must double-check if this is an selected in case of forceswitch
3333 if ( !CommitChangesFromEditor(flags
) )
3335 // Validation has failed, so we can't exit the previous editor
3336 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3337 // _("Invalid Value"),wxOK|wxICON_ERROR);
3338 m_inDoSelectProperty
= 0;
3347 m_pState
->m_selected
= NULL
;
3349 // We need to always fully refresh the grid here
3352 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3353 EditorsValueWasNotModified();
3356 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3359 // Then, activate the one given.
3362 int propY
= p
->GetY2(m_lineHeight
);
3364 int splitterX
= GetSplitterPosition();
3365 m_editorFocused
= 0;
3367 m_pState
->m_selected
= p
;
3368 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3370 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3372 wxASSERT( m_wndEditor
== NULL
);
3375 // Only create editor for non-disabled non-caption
3376 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3378 // do this for non-caption items
3382 // Do we need to paint the custom image, if any?
3383 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3384 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3385 !p
->GetEditorClass()->CanContainCustomImage()
3387 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3389 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3390 wxPoint goodPos
= grect
.GetPosition();
3391 #if wxPG_CREATE_CONTROLS_HIDDEN
3392 int coord_adjust
= m_height
- goodPos
.y
;
3393 goodPos
.y
+= coord_adjust
;
3396 const wxPGEditor
* editor
= p
->GetEditorClass();
3397 wxCHECK_MSG(editor
, false,
3398 wxT("NULL editor class not allowed"));
3400 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3402 wxPGWindowList wndList
= editor
->CreateControls(this,
3407 m_wndEditor
= wndList
.m_primary
;
3408 m_wndEditor2
= wndList
.m_secondary
;
3409 wxWindow
* primaryCtrl
= GetEditorControl();
3412 // Essentially, primaryCtrl == m_wndEditor
3415 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3416 // value is drawn as normal, and m_wndEditor2 is assumed
3417 // to be a right-aligned button that triggers a separate editorCtrl
3422 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3423 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3425 // Set validator, if any
3426 #if wxUSE_VALIDATORS
3427 wxValidator
* validator
= p
->GetValidator();
3429 primaryCtrl
->SetValidator(*validator
);
3432 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3433 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3435 // If it has modified status, use bold font
3436 // (must be done before capturing m_ctrlXAdjust)
3437 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3438 SetCurControlBoldFont();
3441 // Fix TextCtrl indentation
3442 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3443 wxTextCtrl
* tc
= NULL
;
3444 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3445 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3447 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3449 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3452 // Store x relative to splitter (we'll need it).
3453 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3455 // Check if background clear is not necessary
3456 wxPoint pos
= m_wndEditor
->GetPosition();
3457 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3459 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3462 m_wndEditor
->SetSizeHints(3, 3);
3464 #if wxPG_CREATE_CONTROLS_HIDDEN
3465 m_wndEditor
->Show(false);
3466 m_wndEditor
->Freeze();
3468 goodPos
= m_wndEditor
->GetPosition();
3469 goodPos
.y
-= coord_adjust
;
3470 m_wndEditor
->Move( goodPos
);
3473 SetupChildEventHandling(primaryCtrl
);
3475 // Focus and select all (wxTextCtrl, wxComboBox etc)
3476 if ( flags
& wxPG_SEL_FOCUS
)
3478 primaryCtrl
->SetFocus();
3480 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3486 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3487 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3489 // Get proper id for wndSecondary
3490 m_wndSecId
= m_wndEditor2
->GetId();
3491 wxWindowList children
= m_wndEditor2
->GetChildren();
3492 wxWindowList::iterator node
= children
.begin();
3493 if ( node
!= children
.end() )
3494 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3496 m_wndEditor2
->SetSizeHints(3,3);
3498 #if wxPG_CREATE_CONTROLS_HIDDEN
3499 wxRect sec_rect
= m_wndEditor2
->GetRect();
3500 sec_rect
.y
-= coord_adjust
;
3502 // Fine tuning required to fix "oversized"
3503 // button disappearance bug.
3504 if ( sec_rect
.y
< 0 )
3506 sec_rect
.height
+= sec_rect
.y
;
3509 m_wndEditor2
->SetSize( sec_rect
);
3511 m_wndEditor2
->Show();
3513 SetupChildEventHandling(m_wndEditor2
);
3515 // If no primary editor, focus to button to allow
3516 // it to interprete ENTER etc.
3517 // NOTE: Due to problems focusing away from it, this
3518 // has been disabled.
3520 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3521 m_wndEditor2->SetFocus();
3525 if ( flags
& wxPG_SEL_FOCUS
)
3526 m_editorFocused
= 1;
3531 // Make sure focus is in grid canvas (important for wxGTK, at least)
3535 EditorsValueWasNotModified();
3537 // If it's inside collapsed section, expand parent, scroll, etc.
3538 // Also, if it was partially visible, scroll it into view.
3539 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3544 #if wxPG_CREATE_CONTROLS_HIDDEN
3545 m_wndEditor
->Thaw();
3547 m_wndEditor
->Show(true);
3554 // Make sure focus is in grid canvas
3558 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3564 // Show help text in status bar.
3565 // (if found and grid not embedded in manager with help box and
3566 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3569 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3571 wxStatusBar
* statusbar
= NULL
;
3572 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3574 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3576 statusbar
= frame
->GetStatusBar();
3581 const wxString
* pHelpString
= (const wxString
*) NULL
;
3585 pHelpString
= &p
->GetHelpString();
3586 if ( pHelpString
->length() )
3588 // Set help box text.
3589 statusbar
->SetStatusText( *pHelpString
);
3590 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3594 if ( (!pHelpString
|| !pHelpString
->length()) &&
3595 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3597 // Clear help box - but only if it was written
3598 // by us at previous time.
3599 statusbar
->SetStatusText( m_emptyString
);
3600 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3606 m_inDoSelectProperty
= 0;
3608 // call wx event handler (here so that it also occurs on deselection)
3609 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3614 // -----------------------------------------------------------------------
3616 bool wxPropertyGrid::UnfocusEditor()
3618 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3621 if ( !CommitChangesFromEditor(0) )
3625 DrawItem(m_selected
);
3630 // -----------------------------------------------------------------------
3632 void wxPropertyGrid::RefreshEditor()
3634 wxPGProperty
* p
= m_selected
;
3638 wxWindow
* wnd
= GetEditorControl();
3642 // Set editor font boldness - must do this before
3643 // calling UpdateControl().
3644 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3646 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3647 wnd
->SetFont(GetCaptionFont());
3649 wnd
->SetFont(GetFont());
3652 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3654 editorClass
->UpdateControl(p
, wnd
);
3656 if ( p
->IsValueUnspecified() )
3657 editorClass
->SetValueToUnspecified(p
, wnd
);
3660 // -----------------------------------------------------------------------
3662 // This method is not inline because it called dozens of times
3663 // (i.e. two-arg function calls create smaller code size).
3664 bool wxPropertyGrid::DoClearSelection()
3666 return DoSelectProperty(NULL
);
3669 // -----------------------------------------------------------------------
3670 // wxPropertyGrid expand/collapse state
3671 // -----------------------------------------------------------------------
3673 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3675 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3677 // If active editor was inside collapsed section, then disable it
3678 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3680 ClearSelection(false);
3683 // Store dont-center-splitter flag 'cause we need to temporarily set it
3684 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3685 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3687 bool res
= m_pState
->DoCollapse(pwc
);
3692 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3694 RecalculateVirtualSize();
3696 // Redraw etc. only if collapsed was visible.
3697 if (pwc
->IsVisible() &&
3699 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3701 // When item is collapsed so that scrollbar would move,
3702 // graphics mess is about (unless we redraw everything).
3707 // Clear dont-center-splitter flag if it wasn't set
3708 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3713 // -----------------------------------------------------------------------
3715 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3717 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3719 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3721 // Store dont-center-splitter flag 'cause we need to temporarily set it
3722 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3723 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3725 bool res
= m_pState
->DoExpand(pwc
);
3730 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3732 RecalculateVirtualSize();
3734 // Redraw etc. only if expanded was visible.
3735 if ( pwc
->IsVisible() && !m_frozen
&&
3736 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3740 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3743 DrawItems(pwc
, NULL
);
3748 // Clear dont-center-splitter flag if it wasn't set
3749 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3754 // -----------------------------------------------------------------------
3756 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3759 return m_pState
->DoHideProperty(p
, hide
, flags
);
3762 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3765 ClearSelection(false);
3768 m_pState
->DoHideProperty(p
, hide
, flags
);
3770 RecalculateVirtualSize();
3777 // -----------------------------------------------------------------------
3778 // wxPropertyGrid size related methods
3779 // -----------------------------------------------------------------------
3781 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3783 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3787 // If virtual height was changed, then recalculate editor control position(s)
3788 if ( m_pState
->m_vhCalcPending
)
3789 CorrectEditorWidgetPosY();
3791 m_pState
->EnsureVirtualHeight();
3794 int by1
= m_pState
->GetVirtualHeight();
3795 int by2
= m_pState
->GetActualVirtualHeight();
3798 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3799 wxFAIL_MSG(s
.c_str());
3804 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3806 int x
= m_pState
->m_width
;
3807 int y
= m_pState
->m_virtualHeight
;
3810 GetClientSize(&width
,&height
);
3812 // Now adjust virtual size.
3813 SetVirtualSize(x
, y
);
3819 // Adjust scrollbars
3820 if ( HasVirtualWidth() )
3822 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3823 xPos
= GetScrollPos( wxHORIZONTAL
);
3826 if ( forceXPos
!= -1 )
3829 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3832 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3833 int yPos
= GetScrollPos( wxVERTICAL
);
3835 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3836 xAmount
, yAmount
, xPos
, yPos
, true );
3838 // Must re-get size now
3839 GetClientSize(&width
,&height
);
3841 if ( !HasVirtualWidth() )
3843 m_pState
->SetVirtualWidth(width
);
3850 m_canvas
->SetSize( x
, y
);
3852 m_pState
->CheckColumnWidths();
3855 CorrectEditorWidgetSizeX();
3857 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3860 // -----------------------------------------------------------------------
3862 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3864 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3868 GetClientSize(&width
,&height
);
3873 #if wxPG_DOUBLE_BUFFER
3874 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3876 int dblh
= (m_lineHeight
*2);
3877 if ( !m_doubleBuffer
)
3879 // Create double buffer bitmap to draw on, if none
3880 int w
= (width
>250)?width
:250;
3881 int h
= height
+ dblh
;
3883 m_doubleBuffer
= new wxBitmap( w
, h
);
3887 int w
= m_doubleBuffer
->GetWidth();
3888 int h
= m_doubleBuffer
->GetHeight();
3890 // Double buffer must be large enough
3891 if ( w
< width
|| h
< (height
+dblh
) )
3893 if ( w
< width
) w
= width
;
3894 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3895 delete m_doubleBuffer
;
3896 m_doubleBuffer
= new wxBitmap( w
, h
);
3903 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3904 m_ncWidth
= event
.GetSize().x
;
3908 if ( m_pState
->m_itemsAdded
)
3909 PrepareAfterItemsAdded();
3911 // Without this, virtual size (atleast under wxGTK) will be skewed
3912 RecalculateVirtualSize();
3918 // -----------------------------------------------------------------------
3920 void wxPropertyGrid::SetVirtualWidth( int width
)
3924 // Disable virtual width
3925 width
= GetClientSize().x
;
3926 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3930 // Enable virtual width
3931 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3933 m_pState
->SetVirtualWidth( width
);
3936 void wxPropertyGrid::SetFocusOnCanvas()
3938 m_canvas
->SetFocusIgnoringChildren();
3939 m_editorFocused
= 0;
3942 // -----------------------------------------------------------------------
3943 // wxPropertyGrid mouse event handling
3944 // -----------------------------------------------------------------------
3946 // selFlags uses same values DoSelectProperty's flags
3947 // Returns true if event was vetoed.
3948 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3950 // Send property grid event of specific type and with specific property
3951 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3952 evt
.SetPropertyGrid(this);
3953 evt
.SetEventObject(m_eventObject
);
3957 evt
.SetCanVeto(true);
3958 evt
.SetupValidationInfo();
3959 m_validationInfo
.m_pValue
= pValue
;
3961 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3963 evtHandler
->ProcessEvent(evt
);
3965 return evt
.WasVetoed();
3968 // -----------------------------------------------------------------------
3970 // Return false if should be skipped
3971 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3975 // Need to set focus?
3976 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3981 wxPropertyGridPageState
* state
= m_pState
;
3983 int splitterHitOffset
;
3984 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3986 wxPGProperty
* p
= DoGetItemAtY(y
);
3990 int depth
= (int)p
->GetDepth() - 1;
3992 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3994 if ( x
>= marginEnds
)
3998 if ( p
->IsCategory() )
4000 // This is category.
4001 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4003 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4005 // Expand, collapse, activate etc. if click on text or left of splitter.
4008 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4013 if ( !DoSelectProperty( p
) )
4016 // On double-click, expand/collapse.
4017 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4019 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4020 else DoExpand( p
, true );
4024 else if ( splitterHit
== -1 )
4027 unsigned int selFlag
= 0;
4028 if ( columnHit
== 1 )
4030 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4031 selFlag
= wxPG_SEL_FOCUS
;
4033 if ( !DoSelectProperty( p
, selFlag
) )
4036 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4038 if ( p
->GetChildCount() && !p
->IsCategory() )
4039 // On double-click, expand/collapse.
4040 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4042 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4043 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4044 else DoExpand( p
, true );
4051 // click on splitter
4052 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4054 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4056 // Double-clicking the splitter causes auto-centering
4057 CenterSplitter( true );
4059 else if ( m_dragStatus
== 0 )
4062 // Begin draggin the splitter
4066 // Changes must be committed here or the
4067 // value won't be drawn correctly
4068 if ( !CommitChangesFromEditor() )
4071 m_wndEditor
->Show ( false );
4074 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4076 m_canvas
->CaptureMouse();
4077 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4081 m_draggedSplitter
= splitterHit
;
4082 m_dragOffset
= splitterHitOffset
;
4084 wxClientDC
dc(m_canvas
);
4086 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4087 // Fixes button disappearance bug
4089 m_wndEditor2
->Show ( false );
4092 m_startingSplitterX
= x
- splitterHitOffset
;
4100 if ( p
->GetChildCount() )
4102 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4104 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4106 int y2
= y
% m_lineHeight
;
4107 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4109 // On click on expander button, expand/collapse
4110 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4111 DoCollapse( p
, true );
4113 DoExpand( p
, true );
4122 // -----------------------------------------------------------------------
4124 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4125 wxMouseEvent
& WXUNUSED(event
) )
4129 // Select property here as well
4130 wxPGProperty
* p
= m_propHover
;
4131 if ( p
!= m_selected
)
4132 DoSelectProperty( p
);
4134 // Send right click event.
4135 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4142 // -----------------------------------------------------------------------
4144 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4145 wxMouseEvent
& WXUNUSED(event
) )
4149 // Select property here as well
4150 wxPGProperty
* p
= m_propHover
;
4152 if ( p
!= m_selected
)
4153 DoSelectProperty( p
);
4155 // Send double-click event.
4156 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4163 // -----------------------------------------------------------------------
4165 #if wxPG_SUPPORT_TOOLTIPS
4167 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4169 if ( tipString
.length() )
4171 m_canvas
->SetToolTip(tipString
);
4175 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4176 m_canvas
->SetToolTip( m_emptyString
);
4178 m_canvas
->SetToolTip( NULL
);
4183 #endif // #if wxPG_SUPPORT_TOOLTIPS
4185 // -----------------------------------------------------------------------
4187 // Return false if should be skipped
4188 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4190 // Safety check (needed because mouse capturing may
4191 // otherwise freeze the control)
4192 if ( m_dragStatus
> 0 && !event
.Dragging() )
4194 HandleMouseUp(x
,y
,event
);
4197 wxPropertyGridPageState
* state
= m_pState
;
4199 int splitterHitOffset
;
4200 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4201 int splitterX
= x
- splitterHitOffset
;
4203 if ( m_dragStatus
> 0 )
4205 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4206 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4209 int newSplitterX
= x
- m_dragOffset
;
4210 int splitterX
= x
- splitterHitOffset
;
4212 // Splitter redraw required?
4213 if ( newSplitterX
!= splitterX
)
4216 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4217 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4218 state
->m_fSplitterX
= (float) newSplitterX
;
4221 CorrectEditorWidgetSizeX();
4235 int ih
= m_lineHeight
;
4238 #if wxPG_SUPPORT_TOOLTIPS
4239 wxPGProperty
* prevHover
= m_propHover
;
4240 unsigned char prevSide
= m_mouseSide
;
4242 int curPropHoverY
= y
- (y
% ih
);
4244 // On which item it hovers
4247 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4250 // Mouse moves on another property
4252 m_propHover
= DoGetItemAtY(y
);
4253 m_propHoverY
= curPropHoverY
;
4256 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4259 #if wxPG_SUPPORT_TOOLTIPS
4260 // Store which side we are on
4262 if ( columnHit
== 1 )
4264 else if ( columnHit
== 0 )
4268 // If tooltips are enabled, show label or value as a tip
4269 // in case it doesn't otherwise show in full length.
4271 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4273 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4275 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4277 if ( m_propHover
&& !m_propHover
->IsCategory() )
4280 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4282 // Show help string as a tooltip
4283 wxString tipString
= m_propHover
->GetHelpString();
4285 SetToolTip(tipString
);
4289 // Show cropped value string as a tooltip
4293 if ( m_mouseSide
== 1 )
4295 tipString
= m_propHover
->m_label
;
4296 space
= splitterX
-m_marginWidth
-3;
4298 else if ( m_mouseSide
== 2 )
4300 tipString
= m_propHover
->GetDisplayedString();
4302 space
= m_width
- splitterX
;
4303 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4304 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4310 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4313 SetToolTip( tipString
);
4320 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4321 m_canvas
->SetToolTip( m_emptyString
);
4323 m_canvas
->SetToolTip( NULL
);
4334 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4335 m_canvas
->SetToolTip( m_emptyString
);
4337 m_canvas
->SetToolTip( NULL
);
4345 if ( splitterHit
== -1 ||
4347 HasFlag(wxPG_STATIC_SPLITTER
) )
4349 // hovering on something else
4350 if ( m_curcursor
!= wxCURSOR_ARROW
)
4351 CustomSetCursor( wxCURSOR_ARROW
);
4355 // Do not allow splitter cursor on caption items.
4356 // (also not if we were dragging and its started
4357 // outside the splitter region)
4359 if ( !m_propHover
->IsCategory() &&
4363 // hovering on splitter
4365 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4366 // reliably detected.
4367 //if ( m_curcursor != wxCURSOR_SIZEWE )
4368 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4374 // hovering on something else
4375 if ( m_curcursor
!= wxCURSOR_ARROW
)
4376 CustomSetCursor( wxCURSOR_ARROW
);
4383 // -----------------------------------------------------------------------
4385 // Also handles Leaving event
4386 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4387 wxMouseEvent
&WXUNUSED(event
) )
4389 wxPropertyGridPageState
* state
= m_pState
;
4393 int splitterHitOffset
;
4394 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4396 // No event type check - basicly calling this method should
4397 // just stop dragging.
4398 // Left up after dragged?
4399 if ( m_dragStatus
>= 1 )
4402 // End Splitter Dragging
4404 // DO NOT ENABLE FOLLOWING LINE!
4405 // (it is only here as a reminder to not to do it)
4408 // Disable splitter auto-centering
4409 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4411 // This is necessary to return cursor
4412 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4414 m_canvas
->ReleaseMouse();
4415 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4418 // Set back the default cursor, if necessary
4419 if ( splitterHit
== -1 ||
4422 CustomSetCursor( wxCURSOR_ARROW
);
4427 // Control background needs to be cleared
4428 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4429 DrawItem( m_selected
);
4433 m_wndEditor
->Show ( true );
4436 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4437 // Fixes button disappearance bug
4439 m_wndEditor2
->Show ( true );
4442 // This clears the focus.
4443 m_editorFocused
= 0;
4449 // -----------------------------------------------------------------------
4451 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4453 int splitterX
= GetSplitterPosition();
4456 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4460 wxWindow
* wnd
= GetEditorControl();
4462 // Hide popup on clicks
4463 if ( event
.GetEventType() != wxEVT_MOTION
)
4464 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4466 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4472 if ( wnd
== NULL
|| m_dragStatus
||
4474 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4475 ux
>= (r
.x
+r
.width
) ||
4477 event
.m_y
>= (r
.y
+r
.height
)
4487 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4492 // -----------------------------------------------------------------------
4494 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4497 if ( OnMouseCommon( event
, &x
, &y
) )
4499 HandleMouseClick(x
,y
,event
);
4504 // -----------------------------------------------------------------------
4506 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4509 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4510 HandleMouseRightClick(x
,y
,event
);
4514 // -----------------------------------------------------------------------
4516 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4518 // Always run standard mouse-down handler as well
4519 OnMouseClick(event
);
4522 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4523 HandleMouseDoubleClick(x
,y
,event
);
4527 // -----------------------------------------------------------------------
4529 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4532 if ( OnMouseCommon( event
, &x
, &y
) )
4534 HandleMouseMove(x
,y
,event
);
4539 // -----------------------------------------------------------------------
4541 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4543 // Called when mouse moves in the empty space below the properties.
4544 CustomSetCursor( wxCURSOR_ARROW
);
4547 // -----------------------------------------------------------------------
4549 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4552 if ( OnMouseCommon( event
, &x
, &y
) )
4554 HandleMouseUp(x
,y
,event
);
4559 // -----------------------------------------------------------------------
4561 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4563 // This may get called from child control as well, so event's
4564 // mouse position cannot be relied on.
4566 if ( event
.Entering() )
4568 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4570 // TODO: Fix this (detect parent and only do
4571 // cursor trick if it is a manager).
4572 wxASSERT( GetParent() );
4573 GetParent()->SetCursor(wxNullCursor
);
4575 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4578 GetParent()->SetCursor(wxNullCursor
);
4580 else if ( event
.Leaving() )
4582 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4583 m_canvas
->SetCursor( wxNullCursor
);
4585 // Get real cursor position
4586 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4588 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4591 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4593 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4597 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4605 // -----------------------------------------------------------------------
4607 // Common code used by various OnMouseXXXChild methods.
4608 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4610 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4611 wxASSERT( topCtrlWnd
);
4613 event
.GetPosition(&x
,&y
);
4615 int splitterX
= GetSplitterPosition();
4617 wxRect r
= topCtrlWnd
->GetRect();
4618 if ( !m_dragStatus
&&
4619 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4620 y
>= 0 && y
< r
.height \
4623 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4628 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4635 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4638 if ( OnMouseChildCommon(event
,&x
,&y
) )
4640 bool res
= HandleMouseClick(x
,y
,event
);
4641 if ( !res
) event
.Skip();
4645 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4648 wxASSERT( m_wndEditor
);
4649 // These coords may not be exact (about +-2),
4650 // but that should not matter (right click is about item, not position).
4651 wxPoint pt
= m_wndEditor
->GetPosition();
4652 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4653 wxASSERT( m_selected
);
4654 m_propHover
= m_selected
;
4655 bool res
= HandleMouseRightClick(x
,y
,event
);
4656 if ( !res
) event
.Skip();
4659 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4662 if ( OnMouseChildCommon(event
,&x
,&y
) )
4664 bool res
= HandleMouseMove(x
,y
,event
);
4665 if ( !res
) event
.Skip();
4669 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4672 if ( OnMouseChildCommon(event
,&x
,&y
) )
4674 bool res
= HandleMouseUp(x
,y
,event
);
4675 if ( !res
) event
.Skip();
4679 // -----------------------------------------------------------------------
4680 // wxPropertyGrid keyboard event handling
4681 // -----------------------------------------------------------------------
4683 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4685 // Translates wxKeyEvent to wxPG_ACTION_XXX
4687 int keycode
= event
.GetKeyCode();
4688 int modifiers
= event
.GetModifiers();
4690 wxASSERT( !(modifiers
&~(0xFFFF)) );
4692 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4694 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4696 if ( it
== m_actionTriggers
.end() )
4701 int second
= (it
->second
>>16) & 0xFFFF;
4705 return (it
->second
& 0xFFFF);
4708 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4710 wxASSERT( !(modifiers
&~(0xFFFF)) );
4712 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4714 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4716 if ( it
!= m_actionTriggers
.end() )
4718 // This key combination is already used
4720 // Can add secondary?
4721 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4722 wxT("You can only add up to two separate actions per key combination.") );
4724 action
= it
->second
| (action
<<16);
4727 m_actionTriggers
[hashMapKey
] = action
;
4730 void wxPropertyGrid::ClearActionTriggers( int action
)
4732 wxPGHashMapI2I::iterator it
;
4734 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4736 if ( it
->second
== action
)
4738 m_actionTriggers
.erase(it
);
4743 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4746 // Handles key event when editor control is not focused.
4749 wxCHECK2(!m_frozen
, return);
4751 // Travelsal between items, collapsing/expanding, etc.
4752 int keycode
= event
.GetKeyCode();
4753 bool editorFocused
= IsEditorFocused();
4755 if ( keycode
== WXK_TAB
)
4757 wxWindow
* mainControl
;
4759 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4760 mainControl
= GetParent();
4764 if ( !event
.ShiftDown() )
4766 if ( !editorFocused
&& m_wndEditor
)
4768 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4772 // Tab traversal workaround for platforms on which
4773 // wxWindow::Navigate() may navigate into first child
4774 // instead of next sibling. Does not work perfectly
4775 // in every scenario (for instance, when property grid
4776 // is either first or last control).
4777 #if defined(__WXGTK__)
4778 wxWindow
* sibling
= mainControl
->GetNextSibling();
4780 sibling
->SetFocusFromKbd();
4782 Navigate(wxNavigationKeyEvent::IsForward
);
4788 if ( editorFocused
)
4794 #if defined(__WXGTK__)
4795 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4797 sibling
->SetFocusFromKbd();
4799 Navigate(wxNavigationKeyEvent::IsBackward
);
4807 // Ignore Alt and Control when they are down alone
4808 if ( keycode
== WXK_ALT
||
4809 keycode
== WXK_CONTROL
)
4816 int action
= KeyEventToActions(event
, &secondAction
);
4818 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4821 // Esc cancels any changes
4822 if ( IsEditorsValueModified() )
4824 EditorsValueWasNotModified();
4826 // Update the control as well
4827 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4829 m_selected
->GetDisplayedString() );
4832 OnValidationFailureReset(m_selected
);
4838 // Except for TAB and ESC, handle child control events in child control
4841 // Only propagate event if it had modifiers
4842 if ( !event
.HasModifiers() )
4844 event
.StopPropagation();
4850 bool wasHandled
= false;
4855 if ( ButtonTriggerKeyTest(action
, event
) )
4858 wxPGProperty
* p
= m_selected
;
4860 // Travel and expand/collapse
4863 if ( p
->GetChildCount() &&
4864 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4867 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4869 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4872 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4874 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4881 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4885 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4891 if ( selectDir
>= -1 )
4893 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4895 DoSelectProperty(p
);
4901 // If nothing was selected, select the first item now
4902 // (or navigate out of tab).
4903 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4905 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4906 if ( p
) DoSelectProperty(p
);
4915 // -----------------------------------------------------------------------
4917 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4919 // If there was editor open and focused, then this event should not
4920 // really be processed here.
4921 if ( IsEditorFocused() )
4923 // However, if event had modifiers, it is probably still best
4925 if ( event
.HasModifiers() )
4928 event
.StopPropagation();
4932 HandleKeyEvent(event
, false);
4935 // -----------------------------------------------------------------------
4937 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4942 action
= KeyEventToActions(event
, &secondAction
);
4945 // Does the keycode trigger button?
4946 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4949 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4950 GetEventHandler()->AddPendingEvent(evt
);
4957 // -----------------------------------------------------------------------
4959 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4961 HandleKeyEvent(event
, true);
4964 // -----------------------------------------------------------------------
4965 // wxPropertyGrid miscellaneous event handling
4966 // -----------------------------------------------------------------------
4968 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4971 // Check if the focus is in this control or one of its children
4972 wxWindow
* newFocused
= wxWindow::FindFocus();
4974 if ( newFocused
!= m_curFocused
)
4975 HandleFocusChange( newFocused
);
4978 bool wxPropertyGrid::IsEditorFocused() const
4980 wxWindow
* focus
= wxWindow::FindFocus();
4982 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4983 focus
== GetEditorControl() )
4989 // Called by focus event handlers. newFocused is the window that becomes focused.
4990 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4992 unsigned int oldFlags
= m_iFlags
;
4994 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4996 wxWindow
* parent
= newFocused
;
4998 // This must be one of nextFocus' parents.
5001 // Use m_eventObject, which is either wxPropertyGrid or
5002 // wxPropertyGridManager, as appropriate.
5003 if ( parent
== m_eventObject
)
5005 m_iFlags
|= wxPG_FL_FOCUSED
;
5008 parent
= parent
->GetParent();
5011 m_curFocused
= newFocused
;
5013 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5014 (oldFlags
& wxPG_FL_FOCUSED
) )
5016 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5018 // Need to store changed value
5019 CommitChangesFromEditor();
5025 // Preliminary code for tab-order respecting
5026 // tab-traversal (but should be moved to
5029 wxWindow* prevFocus = event.GetWindow();
5030 wxWindow* useThis = this;
5031 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5032 useThis = GetParent();
5035 prevFocus->GetParent() == useThis->GetParent() )
5037 wxList& children = useThis->GetParent()->GetChildren();
5039 wxNode* node = children.Find(prevFocus);
5041 if ( node->GetNext() &&
5042 useThis == node->GetNext()->GetData() )
5043 DoSelectProperty(GetFirst());
5044 else if ( node->GetPrevious () &&
5045 useThis == node->GetPrevious()->GetData() )
5046 DoSelectProperty(GetLastProperty());
5053 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5054 DrawItem( m_selected
);
5058 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5060 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5061 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5062 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5063 //else if ( event.GetWindow() )
5065 HandleFocusChange(event
.GetWindow());
5070 // -----------------------------------------------------------------------
5072 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5074 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5077 // event.Skip() being commented out is aworkaround for bug reported
5078 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5082 // -----------------------------------------------------------------------
5084 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5086 m_iFlags
|= wxPG_FL_SCROLLED
;
5091 // -----------------------------------------------------------------------
5093 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5095 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5097 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5101 // -----------------------------------------------------------------------
5102 // Property editor related functions
5103 // -----------------------------------------------------------------------
5105 // noDefCheck = true prevents infinite recursion.
5106 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5109 wxASSERT( editorClass
);
5111 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5112 RegisterDefaultEditors();
5114 wxString name
= editorClass
->GetName();
5116 // Existing editor under this name?
5117 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5119 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5121 // If this name was already used, try class name.
5122 name
= editorClass
->GetClassInfo()->GetClassName();
5123 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5126 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5127 (wxPGEditor
*) vt_it
->second
,
5128 "Editor with given name was already registered" );
5130 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5135 // Use this in RegisterDefaultEditors.
5136 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5137 if ( wxPGEditor_##EDITOR == NULL ) \
5139 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5140 new wxPG##EDITOR##Editor, true ); \
5143 // Registers all default editor classes
5144 void wxPropertyGrid::RegisterDefaultEditors()
5146 wxPGRegisterDefaultEditorClass( TextCtrl
);
5147 wxPGRegisterDefaultEditorClass( Choice
);
5148 wxPGRegisterDefaultEditorClass( ComboBox
);
5149 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5150 #if wxPG_INCLUDE_CHECKBOX
5151 wxPGRegisterDefaultEditorClass( CheckBox
);
5153 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5155 // Register SpinCtrl etc. editors before use
5156 RegisterAdditionalEditors();
5159 // -----------------------------------------------------------------------
5160 // wxPGStringTokenizer
5161 // Needed to handle C-style string lists (e.g. "str1" "str2")
5162 // -----------------------------------------------------------------------
5164 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5165 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5169 wxPGStringTokenizer::~wxPGStringTokenizer()
5173 bool wxPGStringTokenizer::HasMoreTokens()
5175 const wxString
& str
= *m_str
;
5177 wxString::const_iterator i
= m_curPos
;
5179 wxUniChar delim
= m_delimeter
;
5181 wxUniChar prev_a
= wxT('\0');
5183 bool inToken
= false;
5185 while ( i
!= str
.end() )
5194 m_readyToken
.clear();
5199 if ( prev_a
!= wxT('\\') )
5203 if ( a
!= wxT('\\') )
5223 m_curPos
= str
.end();
5231 wxString
wxPGStringTokenizer::GetNextToken()
5233 return m_readyToken
;
5236 // -----------------------------------------------------------------------
5238 // -----------------------------------------------------------------------
5240 wxPGChoiceEntry::wxPGChoiceEntry()
5241 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5245 // -----------------------------------------------------------------------
5247 // -----------------------------------------------------------------------
5249 wxPGChoicesData::wxPGChoicesData()
5254 wxPGChoicesData::~wxPGChoicesData()
5259 void wxPGChoicesData::Clear()
5264 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5266 wxASSERT( m_items
.size() == 0 );
5268 m_items
= data
->m_items
;
5271 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5272 const wxPGChoiceEntry
& item
)
5274 wxVector
<wxPGChoiceEntry
>::iterator it
;
5278 index
= (int) m_items
.size();
5282 it
= m_items
.begin() + index
;
5285 m_items
.insert(it
, item
);
5287 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5289 // Need to fix value?
5290 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5291 ownEntry
.SetValue(index
);
5296 // -----------------------------------------------------------------------
5297 // wxPropertyGridEvent
5298 // -----------------------------------------------------------------------
5300 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5303 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
)
5304 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
)
5305 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
)
5306 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
)
5307 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
)
5308 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
)
5309 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
)
5310 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
)
5311 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
)
5314 // -----------------------------------------------------------------------
5316 void wxPropertyGridEvent::Init()
5318 m_validationInfo
= NULL
;
5320 m_wasVetoed
= false;
5323 // -----------------------------------------------------------------------
5325 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5326 : wxCommandEvent(commandType
,id
)
5332 // -----------------------------------------------------------------------
5334 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5335 : wxCommandEvent(event
)
5337 m_eventType
= event
.GetEventType();
5338 m_eventObject
= event
.m_eventObject
;
5340 m_property
= event
.m_property
;
5341 m_validationInfo
= event
.m_validationInfo
;
5342 m_canVeto
= event
.m_canVeto
;
5343 m_wasVetoed
= event
.m_wasVetoed
;
5346 // -----------------------------------------------------------------------
5348 wxPropertyGridEvent::~wxPropertyGridEvent()
5352 // -----------------------------------------------------------------------
5354 wxEvent
* wxPropertyGridEvent::Clone() const
5356 return new wxPropertyGridEvent( *this );
5359 // -----------------------------------------------------------------------
5360 // wxPropertyGridPopulator
5361 // -----------------------------------------------------------------------
5363 wxPropertyGridPopulator::wxPropertyGridPopulator()
5367 wxPGGlobalVars
->m_offline
++;
5370 // -----------------------------------------------------------------------
5372 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5375 m_propHierarchy
.clear();
5378 // -----------------------------------------------------------------------
5380 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5386 // -----------------------------------------------------------------------
5388 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5391 // Free unused sets of choices
5392 wxPGHashMapS2P::iterator it
;
5394 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5396 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5403 m_pg
->GetPanel()->Refresh();
5405 wxPGGlobalVars
->m_offline
--;
5408 // -----------------------------------------------------------------------
5410 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5411 const wxString
& propLabel
,
5412 const wxString
& propName
,
5413 const wxString
* propValue
,
5414 wxPGChoices
* pChoices
)
5416 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5417 wxPGProperty
* parent
= GetCurParent();
5419 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5421 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5425 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5427 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5431 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5433 property
->SetLabel(propLabel
);
5434 property
->DoSetName(propName
);
5436 if ( pChoices
&& pChoices
->IsOk() )
5437 property
->SetChoices(*pChoices
);
5439 m_state
->DoInsert(parent
, -1, property
);
5442 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5443 wxPG_PROGRAMMATIC_VALUE
);
5448 // -----------------------------------------------------------------------
5450 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5452 m_propHierarchy
.push_back(property
);
5453 DoScanForChildren();
5454 m_propHierarchy
.pop_back();
5457 // -----------------------------------------------------------------------
5459 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5460 const wxString
& idString
)
5462 wxPGChoices choices
;
5465 if ( choicesString
[0] == wxT('@') )
5467 wxString ids
= choicesString
.substr(1);
5468 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5469 if ( it
== m_dictIdChoices
.end() )
5470 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5472 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5477 if ( idString
.length() )
5479 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5480 if ( it
!= m_dictIdChoices
.end() )
5482 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5489 // Parse choices string
5490 wxString::const_iterator it
= choicesString
.begin();
5494 bool labelValid
= false;
5496 for ( ; it
!= choicesString
.end(); ++it
)
5502 if ( c
== wxT('"') )
5507 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5508 choices
.Add(label
, l
);
5511 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5516 else if ( c
== wxT('=') )
5523 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5530 if ( c
== wxT('"') )
5543 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5544 choices
.Add(label
, l
);
5547 if ( !choices
.IsOk() )
5549 choices
.EnsureData();
5553 if ( idString
.length() )
5554 m_dictIdChoices
[idString
] = choices
.GetData();
5561 // -----------------------------------------------------------------------
5563 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5565 if ( s
.Last() == wxT('%') )
5567 wxString s2
= s
.substr(0,s
.length()-1);
5569 if ( s2
.ToLong(&val
, 10) )
5571 *pval
= (val
*max
)/100;
5577 return s
.ToLong(pval
, 10);
5580 // -----------------------------------------------------------------------
5582 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5583 const wxString
& type
,
5584 const wxString
& value
)
5586 int l
= m_propHierarchy
.size();
5590 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5591 wxString valuel
= value
.Lower();
5594 if ( type
.length() == 0 )
5599 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5601 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5603 else if ( value
.ToLong(&v
, 0) )
5610 if ( type
== wxT("string") )
5614 else if ( type
== wxT("int") )
5617 value
.ToLong(&v
, 0);
5620 else if ( type
== wxT("bool") )
5622 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5629 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5634 p
->SetAttribute( name
, variant
);
5639 // -----------------------------------------------------------------------
5641 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5643 wxLogError(_("Error in resource: %s"),msg
.c_str());
5646 // -----------------------------------------------------------------------
5648 #endif // wxUSE_PROPGRID