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
, 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 wxRect
* clipRect
,
1592 bool isBuffered
) const
1594 const wxPGProperty
* firstItem
;
1595 const wxPGProperty
* lastItem
;
1597 firstItem
= DoGetItemAtY(clipRect
->y
);
1598 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1601 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1603 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1606 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1607 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1609 int lh
= m_lineHeight
;
1612 int lastItemBottomY
;
1614 firstItemTopY
= clipRect
->y
;
1615 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1617 // Align y coordinates to item boundaries
1618 firstItemTopY
-= firstItemTopY
% lh
;
1619 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1620 lastItemBottomY
-= 1;
1622 // Entire range outside scrolled, visible area?
1623 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1626 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1630 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1631 firstItem->GetLabel().c_str(),
1632 lastItem->GetLabel().c_str(),
1633 (int)(lastItemBottomY - firstItemTopY),
1635 (unsigned long)clipRect );
1640 long windowStyle
= m_windowStyle
;
1646 // With wxPG_DOUBLE_BUFFER, do double buffering
1647 // - buffer's y = 0, so align cliprect and coordinates to that
1649 #if wxPG_DOUBLE_BUFFER
1655 xRelMod
= clipRect
->x
;
1656 yRelMod
= clipRect
->y
;
1659 // clipRect conversion
1664 firstItemTopY
-= yRelMod
;
1665 lastItemBottomY
-= yRelMod
;
1668 wxUnusedVar(isBuffered
);
1671 int x
= m_marginWidth
- xRelMod
;
1673 const wxFont
& normalfont
= m_font
;
1675 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1677 bool isEnabled
= IsEnabled();
1680 // Prepare some pens and brushes that are often changed to.
1683 wxBrush
marginBrush(m_colMargin
);
1684 wxPen
marginPen(m_colMargin
);
1685 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1686 wxPen
linepen(m_colLine
,1,wxSOLID
);
1688 // pen that has same colour as text
1689 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1692 // Clear margin with background colour
1694 dc
.SetBrush( marginBrush
);
1695 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1697 dc
.SetPen( *wxTRANSPARENT_PEN
);
1698 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1701 const wxPGProperty
* selected
= m_selected
;
1702 const wxPropertyGridPageState
* state
= m_pState
;
1704 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1705 bool wasSelectedPainted
= false;
1708 // TODO: Only render columns that are within clipping region.
1710 dc
.SetFont(normalfont
);
1712 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1713 int endScanBottomY
= lastItemBottomY
+ lh
;
1714 int y
= firstItemTopY
;
1717 // Pregenerate list of visible properties.
1718 wxArrayPGProperty visPropArray
;
1719 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1721 for ( ; !it
.AtEnd(); it
.Next() )
1723 const wxPGProperty
* p
= *it
;
1725 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1727 visPropArray
.push_back((wxPGProperty
*)p
);
1729 if ( y
> endScanBottomY
)
1736 visPropArray
.push_back(NULL
);
1738 wxPGProperty
* nextP
= visPropArray
[0];
1740 int gridWidth
= state
->m_width
;
1743 for ( unsigned int arrInd
=1;
1744 nextP
&& y
<= lastItemBottomY
;
1747 wxPGProperty
* p
= nextP
;
1748 nextP
= visPropArray
[arrInd
];
1750 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1751 int textMarginHere
= x
;
1752 int renderFlags
= 0;
1754 int greyDepth
= m_marginWidth
;
1755 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1756 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1758 int greyDepthX
= greyDepth
- xRelMod
;
1760 // Use basic depth if in non-categoric mode and parent is base array.
1761 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1763 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1766 // Paint margin area
1767 dc
.SetBrush(marginBrush
);
1768 dc
.SetPen(marginPen
);
1769 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1771 dc
.SetPen( linepen
);
1776 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1782 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1784 sx
+= state
->m_colWidths
[si
];
1785 dc
.DrawLine( sx
, y
, sx
, y2
);
1788 // Horizontal Line, below
1789 // (not if both this and next is category caption)
1790 if ( p
->IsCategory() &&
1791 nextP
&& nextP
->IsCategory() )
1792 dc
.SetPen(m_colCapBack
);
1794 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1797 // Need to override row colours?
1801 if ( p
!= selected
)
1803 // Disabled may get different colour.
1804 if ( !p
->IsEnabled() )
1806 renderFlags
|= wxPGCellRenderer::Disabled
|
1807 wxPGCellRenderer::DontUseCellFgCol
;
1808 rowFgCol
= m_colDisPropFore
;
1813 renderFlags
|= wxPGCellRenderer::Selected
;
1815 if ( !p
->IsCategory() )
1817 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1818 wxPGCellRenderer::DontUseCellBgCol
;
1820 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1821 wasSelectedPainted
= true;
1824 // Selected gets different colour.
1825 if ( reallyFocused
)
1827 rowFgCol
= m_colSelFore
;
1828 rowBgCol
= m_colSelBack
;
1830 else if ( isEnabled
)
1832 rowFgCol
= m_colPropFore
;
1833 rowBgCol
= m_colMargin
;
1837 rowFgCol
= m_colDisPropFore
;
1838 rowBgCol
= m_colSelBack
;
1845 if ( rowBgCol
.IsOk() )
1846 rowBgBrush
= wxBrush(rowBgCol
);
1848 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1849 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1852 // Fill additional margin area with background colour of first cell
1853 if ( greyDepthX
< textMarginHere
)
1855 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1857 wxPGCell
& cell
= p
->GetCell(0);
1858 rowBgCol
= cell
.GetBgCol();
1859 rowBgBrush
= wxBrush(rowBgCol
);
1861 dc
.SetBrush(rowBgBrush
);
1862 dc
.SetPen(rowBgCol
);
1863 dc
.DrawRectangle(greyDepthX
+1, y
,
1864 textMarginHere
-greyDepthX
, lh
-1);
1867 bool fontChanged
= false;
1869 // Expander button rectangle
1870 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1875 if ( p
->IsCategory() )
1877 // Captions have their cell areas merged as one
1878 dc
.SetFont(m_captionFont
);
1880 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1882 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1884 dc
.SetBrush(rowBgBrush
);
1885 dc
.SetPen(rowBgCol
);
1888 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1890 dc
.SetTextForeground(rowFgCol
);
1893 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1894 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1897 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1898 DrawExpanderButton( dc
, butRect
, p
);
1902 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1904 dc
.SetFont(m_captionFont
);
1910 int nextCellWidth
= state
->m_colWidths
[0] -
1911 (greyDepthX
- m_marginWidth
);
1912 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1913 int textXAdd
= textMarginHere
- greyDepthX
;
1915 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1917 cellRect
.width
= nextCellWidth
- 1;
1919 bool ctrlCell
= false;
1920 int cellRenderFlags
= renderFlags
;
1923 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1924 DrawExpanderButton( dc
, butRect
, p
);
1927 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1929 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1930 dc
.SetBrush(editorBgCol
);
1931 dc
.SetPen(editorBgCol
);
1932 dc
.SetTextForeground(m_colPropFore
);
1933 dc
.DrawRectangle(cellRect
);
1935 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1940 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1942 dc
.SetBrush(rowBgBrush
);
1943 dc
.SetPen(rowBgCol
);
1946 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1948 dc
.SetTextForeground(rowFgCol
);
1952 dc
.SetClippingRegion(cellRect
);
1954 cellRect
.x
+= textXAdd
;
1955 cellRect
.width
-= textXAdd
;
1960 wxPGCellRenderer
* renderer
;
1961 int cmnVal
= p
->GetCommonValue();
1962 if ( cmnVal
== -1 || ci
!= 1 )
1964 renderer
= p
->GetCellRenderer(ci
);
1965 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1970 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1971 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1976 cellX
+= state
->m_colWidths
[ci
];
1977 if ( ci
< (state
->m_colWidths
.size()-1) )
1978 nextCellWidth
= state
->m_colWidths
[ci
+1];
1980 dc
.DestroyClippingRegion(); // Is this really necessary?
1986 dc
.SetFont(normalfont
);
1991 // Refresh editor controls (seems not needed on msw)
1992 // NOTE: This code is mandatory for GTK!
1993 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1994 if ( wasSelectedPainted
)
1997 m_wndEditor
->Refresh();
1999 m_wndEditor2
->Refresh();
2006 // -----------------------------------------------------------------------
2008 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2012 if ( m_width
< 10 || m_height
< 10 ||
2013 !m_pState
->m_properties
->GetChildCount() ||
2015 return wxRect(0,0,0,0);
2020 // Return rect which encloses the given property range
2022 int visTop
= p1
->GetY();
2025 visBottom
= p2
->GetY() + m_lineHeight
;
2027 visBottom
= m_height
+ visTop
;
2029 // If seleced property is inside the range, we'll extend the range to include
2031 wxPGProperty
* selected
= m_selected
;
2034 int selectedY
= selected
->GetY();
2035 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2037 wxWindow
* editor
= GetEditorControl();
2040 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2041 if ( visBottom2
> visBottom
)
2042 visBottom
= visBottom2
;
2047 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2050 // -----------------------------------------------------------------------
2052 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2057 if ( m_pState
->m_itemsAdded
)
2058 PrepareAfterItemsAdded();
2060 wxRect r
= GetPropertyRect(p1
, p2
);
2063 m_canvas
->RefreshRect(r
);
2067 // -----------------------------------------------------------------------
2069 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2071 if ( p
== m_selected
)
2072 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2074 DrawItemAndChildren(p
);
2077 // -----------------------------------------------------------------------
2079 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2084 // Draw item, children, and parent too, if it is not category
2085 wxPGProperty
* parent
= p
->GetParent();
2088 !parent
->IsCategory() &&
2089 parent
->GetParent() )
2092 parent
= parent
->GetParent();
2095 DrawItemAndChildren(p
);
2098 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2100 wxCHECK_RET( p
, wxT("invalid property id") );
2102 // Do not draw if in non-visible page
2103 if ( p
->GetParentState() != m_pState
)
2106 // do not draw a single item if multiple pending
2107 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2110 // Update child control.
2111 if ( m_selected
&& m_selected
->GetParent() == p
)
2114 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2116 DrawItems(p
, lastDrawn
);
2119 // -----------------------------------------------------------------------
2121 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2122 const wxRect
*rect
)
2124 PrepareAfterItemsAdded();
2126 wxWindow::Refresh(false);
2128 // TODO: Coordinate translation
2129 m_canvas
->Refresh(false, rect
);
2131 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2132 // I think this really helps only GTK+1.2
2133 if ( m_wndEditor
) m_wndEditor
->Refresh();
2134 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2138 // -----------------------------------------------------------------------
2139 // wxPropertyGrid global operations
2140 // -----------------------------------------------------------------------
2142 void wxPropertyGrid::Clear()
2144 ClearSelection(false);
2146 m_pState
->DoClear();
2152 RecalculateVirtualSize();
2154 // Need to clear some area at the end
2156 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2159 // -----------------------------------------------------------------------
2161 bool wxPropertyGrid::EnableCategories( bool enable
)
2163 ClearSelection(false);
2168 // Enable categories
2171 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2176 // Disable categories
2178 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2181 if ( !m_pState
->EnableCategories(enable
) )
2186 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2188 m_pState
->m_itemsAdded
= 1; // force
2189 PrepareAfterItemsAdded();
2193 m_pState
->m_itemsAdded
= 1;
2195 // No need for RecalculateVirtualSize() here - it is already called in
2196 // wxPropertyGridPageState method above.
2203 // -----------------------------------------------------------------------
2205 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2207 wxASSERT( pNewState
);
2208 wxASSERT( pNewState
->GetGrid() );
2210 if ( pNewState
== m_pState
)
2213 wxPGProperty
* oldSelection
= m_selected
;
2215 ClearSelection(false);
2217 m_pState
->m_selected
= oldSelection
;
2219 bool orig_mode
= m_pState
->IsInNonCatMode();
2220 bool new_state_mode
= pNewState
->IsInNonCatMode();
2222 m_pState
= pNewState
;
2225 int pgWidth
= GetClientSize().x
;
2226 if ( HasVirtualWidth() )
2228 int minWidth
= pgWidth
;
2229 if ( pNewState
->m_width
< minWidth
)
2231 pNewState
->m_width
= minWidth
;
2232 pNewState
->CheckColumnWidths();
2238 // Just in case, fully re-center splitter
2239 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2240 pNewState
->m_fSplitterX
= -1.0;
2242 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2247 // If necessary, convert state to correct mode.
2248 if ( orig_mode
!= new_state_mode
)
2250 // This should refresh as well.
2251 EnableCategories( orig_mode
?false:true );
2253 else if ( !m_frozen
)
2255 // Refresh, if not frozen.
2256 m_pState
->PrepareAfterItemsAdded();
2259 if ( m_pState
->m_selected
)
2260 DoSelectProperty( m_pState
->m_selected
);
2262 RecalculateVirtualSize(0);
2266 m_pState
->m_itemsAdded
= 1;
2269 // -----------------------------------------------------------------------
2271 // Call to SetSplitterPosition will always disable splitter auto-centering
2272 // if parent window is shown.
2273 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2275 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2278 wxPropertyGridPageState
* state
= m_pState
;
2280 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2285 CorrectEditorWidgetSizeX();
2291 // -----------------------------------------------------------------------
2293 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2295 SetSplitterPosition( m_width
/2, true );
2296 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2297 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2300 // -----------------------------------------------------------------------
2301 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2302 // -----------------------------------------------------------------------
2304 // Returns nearest paint visible property (such that will be painted unless
2305 // window is scrolled or resized). If given property is paint visible, then
2306 // it itself will be returned
2307 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2309 int vx
,vy1
;// Top left corner of client
2310 GetViewStart(&vx
,&vy1
);
2311 vy1
*= wxPG_PIXELS_PER_UNIT
;
2313 int vy2
= vy1
+ m_height
;
2314 int propY
= p
->GetY2(m_lineHeight
);
2316 if ( (propY
+ m_lineHeight
) < vy1
)
2319 return DoGetItemAtY( vy1
);
2321 else if ( propY
> vy2
)
2324 return DoGetItemAtY( vy2
);
2327 // Itself paint visible
2332 // -----------------------------------------------------------------------
2333 // Methods related to change in value, value modification and sending events
2334 // -----------------------------------------------------------------------
2336 // commits any changes in editor of selected property
2337 // return true if validation did not fail
2338 // flags are same as with DoSelectProperty
2339 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2341 // Committing already?
2342 if ( m_inCommitChangesFromEditor
)
2345 // Don't do this if already processing editor event. It might
2346 // induce recursive dialogs and crap like that.
2347 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2349 if ( m_inDoPropertyChanged
)
2356 IsEditorsValueModified() &&
2357 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2360 m_inCommitChangesFromEditor
= 1;
2362 wxVariant
variant(m_selected
->GetValueRef());
2363 bool valueIsPending
= false;
2365 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2366 // due to another window getting focus
2367 wxWindow
* oldFocus
= m_curFocused
;
2369 bool validationFailure
= false;
2370 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2372 m_chgInfo_changedProperty
= NULL
;
2374 // If truly modified, schedule value as pending.
2375 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2377 if ( DoEditorValidate() &&
2378 PerformValidation(m_selected
, variant
) )
2380 valueIsPending
= true;
2384 validationFailure
= true;
2389 EditorsValueWasNotModified();
2394 m_inCommitChangesFromEditor
= 0;
2396 if ( validationFailure
&& !forceSuccess
)
2400 oldFocus
->SetFocus();
2401 m_curFocused
= oldFocus
;
2404 res
= OnValidationFailure(m_selected
, variant
);
2406 // Now prevent further validation failure messages
2409 EditorsValueWasNotModified();
2410 OnValidationFailureReset(m_selected
);
2413 else if ( valueIsPending
)
2415 DoPropertyChanged( m_selected
, flags
);
2416 EditorsValueWasNotModified();
2425 // -----------------------------------------------------------------------
2427 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2431 // Runs all validation functionality.
2432 // Returns true if value passes all tests.
2435 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2437 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2439 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2444 // Adapt list to child values, if necessary
2445 wxVariant listValue
= pendingValue
;
2446 wxVariant
* pPendingValue
= &pendingValue
;
2447 wxVariant
* pList
= NULL
;
2449 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2450 // string value, then we need treat as it was changed instead
2451 // (or, in addition, as is the case with composite string parent).
2452 // This includes creating list variant for child values.
2454 wxPGProperty
* pwc
= p
->GetParent();
2455 wxPGProperty
* changedProperty
= p
;
2456 wxPGProperty
* baseChangedProperty
= changedProperty
;
2457 wxVariant bcpPendingList
;
2459 listValue
= pendingValue
;
2460 listValue
.SetName(p
->GetBaseName());
2463 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2465 wxVariantList tempList
;
2466 wxVariant
lv(tempList
, pwc
->GetBaseName());
2467 lv
.Append(listValue
);
2469 pPendingValue
= &listValue
;
2471 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2473 baseChangedProperty
= pwc
;
2474 bcpPendingList
= lv
;
2477 changedProperty
= pwc
;
2478 pwc
= pwc
->GetParent();
2482 wxPGProperty
* evtChangingProperty
= changedProperty
;
2484 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2486 value
= *pPendingValue
;
2490 // Convert list to child values
2491 pList
= pPendingValue
;
2492 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2495 wxVariant evtChangingValue
= value
;
2497 if ( flags
& SendEvtChanging
)
2499 // FIXME: After proper ValueToString()s added, remove
2500 // this. It is just a temporary fix, as evt_changing
2501 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2502 // (unless it is selected, and textctrl editor is open).
2503 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2505 evtChangingProperty
= baseChangedProperty
;
2506 if ( evtChangingProperty
!= p
)
2508 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2512 evtChangingValue
= pendingValue
;
2516 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2518 if ( changedProperty
== m_selected
)
2520 wxWindow
* editor
= GetEditorControl();
2521 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2522 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2526 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2531 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2532 m_chgInfo_changedProperty
= changedProperty
;
2533 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2534 m_chgInfo_pendingValue
= value
;
2537 m_chgInfo_valueList
= *pList
;
2539 m_chgInfo_valueList
.MakeNull();
2541 // If changedProperty is not property which value was edited,
2542 // then call wxPGProperty::ValidateValue() for that as well.
2543 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2545 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2549 if ( flags
& SendEvtChanging
)
2551 // SendEvent returns true if event was vetoed
2552 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2556 if ( flags
& IsStandaloneValidation
)
2558 // If called in 'generic' context, we need to reset
2559 // m_chgInfo_changedProperty and write back translated value.
2560 m_chgInfo_changedProperty
= NULL
;
2561 pendingValue
= value
;
2567 // -----------------------------------------------------------------------
2569 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2571 if ( !msg
.length() )
2575 if ( !wxPGGlobalVars
->m_offline
)
2577 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2580 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2583 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2586 pStatusBar
->SetStatusText(msg
);
2594 ::wxMessageBox(msg
, _T("Property Error"));
2597 // -----------------------------------------------------------------------
2599 bool wxPropertyGrid::OnValidationFailure( wxPGProperty
* property
,
2600 wxVariant
& invalidValue
)
2602 wxWindow
* editor
= GetEditorControl();
2604 // First call property's handler
2605 property
->OnValidationFailure(invalidValue
);
2607 bool res
= DoOnValidationFailure(property
, invalidValue
);
2610 // For non-wxTextCtrl editors, we do need to revert the value
2611 if ( !editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) &&
2612 property
== m_selected
)
2614 property
->GetEditorClass()->UpdateControl(property
, editor
);
2617 property
->SetFlag(wxPG_PROP_INVALID_VALUE
);
2622 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2624 int vfb
= m_validationInfo
.m_failureBehavior
;
2626 if ( vfb
& wxPG_VFB_BEEP
)
2629 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2630 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2632 unsigned int colCount
= m_pState
->GetColumnCount();
2634 // We need backup marked property's cells
2635 m_propCellsBackup
= property
->m_cells
;
2637 wxColour vfbFg
= *wxWHITE
;
2638 wxColour vfbBg
= *wxRED
;
2640 property
->EnsureCells(colCount
);
2642 for ( unsigned int i
=0; i
<colCount
; i
++ )
2644 wxPGCell
& cell
= property
->m_cells
[i
];
2645 cell
.SetFgCol(vfbFg
);
2646 cell
.SetBgCol(vfbBg
);
2649 DrawItemAndChildren(property
);
2651 if ( property
== m_selected
)
2653 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2655 wxWindow
* editor
= GetEditorControl();
2658 editor
->SetForegroundColour(vfbFg
);
2659 editor
->SetBackgroundColour(vfbBg
);
2664 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2666 wxString msg
= m_validationInfo
.m_failureMessage
;
2668 if ( !msg
.length() )
2669 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2671 DoShowPropertyError(property
, msg
);
2674 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2677 // -----------------------------------------------------------------------
2679 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2681 int vfb
= m_validationInfo
.m_failureBehavior
;
2683 if ( vfb
& wxPG_VFB_MARK_CELL
)
2686 property
->m_cells
= m_propCellsBackup
;
2688 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2690 if ( property
== m_selected
&& GetEditorControl() )
2692 // Calling this will recreate the control, thus resetting its colour
2693 RefreshProperty(property
);
2697 DrawItemAndChildren(property
);
2702 // -----------------------------------------------------------------------
2704 // flags are same as with DoSelectProperty
2705 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2707 if ( m_inDoPropertyChanged
)
2710 wxWindow
* editor
= GetEditorControl();
2712 m_pState
->m_anyModified
= 1;
2714 m_inDoPropertyChanged
= 1;
2716 // Maybe need to update control
2717 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2719 // These values were calculated in PerformValidation()
2720 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2721 wxVariant value
= m_chgInfo_pendingValue
;
2723 wxPGProperty
* topPaintedProperty
= changedProperty
;
2725 while ( !topPaintedProperty
->IsCategory() &&
2726 !topPaintedProperty
->IsRoot() )
2728 topPaintedProperty
= topPaintedProperty
->GetParent();
2731 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2733 // Set as Modified (not if dragging just began)
2734 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2736 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2737 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2740 SetCurControlBoldFont();
2746 // Propagate updates to parent(s)
2748 wxPGProperty
* prevPwc
= NULL
;
2750 while ( prevPwc
!= topPaintedProperty
)
2752 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2754 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2757 SetCurControlBoldFont();
2761 pwc
= pwc
->GetParent();
2764 // Draw the actual property
2765 DrawItemAndChildren( topPaintedProperty
);
2768 // If value was set by wxPGProperty::OnEvent, then update the editor
2770 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2776 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2777 if ( m_wndEditor
) m_wndEditor
->Refresh();
2778 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2783 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2785 // If top parent has composite string value, then send to child parents,
2786 // starting from baseChangedProperty.
2787 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2789 pwc
= m_chgInfo_baseChangedProperty
;
2791 while ( pwc
!= changedProperty
)
2793 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2794 pwc
= pwc
->GetParent();
2798 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2800 m_inDoPropertyChanged
= 0;
2805 // -----------------------------------------------------------------------
2807 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2809 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2811 m_chgInfo_changedProperty
= NULL
;
2813 if ( PerformValidation(p
, newValue
) )
2815 DoPropertyChanged(p
);
2820 OnValidationFailure(p
, newValue
);
2826 // -----------------------------------------------------------------------
2828 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2830 wxPGProperty
* prop
= GetSelectedProperty();
2833 return wxNullVariant
;
2835 wxTextCtrl
* tc
= GetEditorTextCtrl();
2836 wxVariant value
= prop
->GetValue();
2838 if ( !tc
|| !IsEditorsValueModified() )
2841 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2844 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2845 return prop
->GetValue();
2850 // -----------------------------------------------------------------------
2852 // Runs wxValidator for the selected property
2853 bool wxPropertyGrid::DoEditorValidate()
2858 // -----------------------------------------------------------------------
2860 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2862 wxPGProperty
* selected
= m_selected
;
2864 // Somehow, event is handled after property has been deselected.
2865 // Possibly, but very rare.
2869 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2872 wxVariant
pendingValue(selected
->GetValueRef());
2873 wxWindow
* wnd
= GetEditorControl();
2875 bool wasUnspecified
= selected
->IsValueUnspecified();
2876 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2878 bool valueIsPending
= false;
2880 m_chgInfo_changedProperty
= NULL
;
2882 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2885 // Filter out excess wxTextCtrl modified events
2886 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2888 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2890 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2892 wxString newTcValue
= tc
->GetValue();
2893 if ( m_prevTcValue
== newTcValue
)
2896 m_prevTcValue
= newTcValue
;
2899 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2901 bool validationFailure
= false;
2902 bool buttonWasHandled
= false;
2905 // Try common button handling
2906 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2908 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2912 buttonWasHandled
= true;
2913 // Store as res2, as previously (and still currently alternatively)
2914 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2915 // in wxPGProperty::OnEvent().
2916 adapter
->ShowDialog( this, selected
);
2921 if ( !buttonWasHandled
)
2925 // First call editor class' event handler.
2926 const wxPGEditor
* editor
= selected
->GetEditorClass();
2928 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2930 // If changes, validate them
2931 if ( DoEditorValidate() )
2933 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
2934 valueIsPending
= true;
2938 validationFailure
= true;
2943 // Then the property's custom handler (must be always called, unless
2944 // validation failed).
2945 if ( !validationFailure
)
2946 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
2949 // SetValueInEvent(), as called in one of the functions referred above
2950 // overrides editor's value.
2951 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2953 valueIsPending
= true;
2954 pendingValue
= m_changeInEventValue
;
2955 selFlags
|= wxPG_SEL_DIALOGVAL
;
2958 if ( !validationFailure
&& valueIsPending
)
2959 if ( !PerformValidation(m_selected
, pendingValue
) )
2960 validationFailure
= true;
2962 if ( validationFailure
)
2964 OnValidationFailure(selected
, pendingValue
);
2966 else if ( valueIsPending
)
2968 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2970 DoPropertyChanged(selected
, selFlags
);
2971 EditorsValueWasNotModified();
2973 // Regardless of editor type, unfocus editor on
2974 // text-editing related enter press.
2975 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2982 // No value after all
2984 // Regardless of editor type, unfocus editor on
2985 // text-editing related enter press.
2986 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2991 // Let unhandled button click events go to the parent
2992 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2994 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2995 GetEventHandler()->AddPendingEvent(evt
);
2999 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3002 // -----------------------------------------------------------------------
3003 // wxPropertyGrid editor control helper methods
3004 // -----------------------------------------------------------------------
3006 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3008 int itemy
= p
->GetY2(m_lineHeight
);
3010 int cust_img_space
= 0;
3011 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3012 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3014 // TODO: If custom image detection changes from current, change this.
3015 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3017 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3018 int imwid
= p
->OnMeasureImage().x
;
3019 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3020 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3025 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3027 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3032 // -----------------------------------------------------------------------
3034 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3036 wxSize sz
= GetImageSize(p
, item
);
3037 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3038 wxPG_CUSTOM_IMAGE_SPACINGY
,
3043 // return size of custom paint image
3044 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3046 // If called with NULL property, then return default image
3047 // size for properties that use image.
3049 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3051 wxSize cis
= p
->OnMeasureImage(item
);
3053 int choiceCount
= p
->m_choices
.GetCount();
3054 int comVals
= p
->GetDisplayedCommonValueCount();
3055 if ( item
>= choiceCount
&& comVals
> 0 )
3057 unsigned int cvi
= item
-choiceCount
;
3058 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3060 else if ( item
>= 0 && choiceCount
== 0 )
3061 return wxSize(0, 0);
3066 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3071 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3078 // -----------------------------------------------------------------------
3080 // takes scrolling into account
3081 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3084 GetViewStart(&vx
,&vy
);
3085 vy
*=wxPG_PIXELS_PER_UNIT
;
3086 vx
*=wxPG_PIXELS_PER_UNIT
;
3089 ClientToScreen( px
, py
);
3092 // -----------------------------------------------------------------------
3094 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3097 GetViewStart(&pt2
.x
,&pt2
.y
);
3098 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3099 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3103 return m_pState
->HitTest(pt2
);
3106 // -----------------------------------------------------------------------
3108 // custom set cursor
3109 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3111 if ( type
== m_curcursor
&& !override
) return;
3113 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3115 if ( type
== wxCURSOR_SIZEWE
)
3116 cursor
= m_cursorSizeWE
;
3118 m_canvas
->SetCursor( *cursor
);
3123 // -----------------------------------------------------------------------
3124 // wxPropertyGrid property selection, editor creation
3125 // -----------------------------------------------------------------------
3128 // This class forwards events from property editor controls to wxPropertyGrid.
3129 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3132 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3133 : wxEvtHandler(), m_propGrid(propGrid
)
3137 virtual ~wxPropertyGridEditorEventForwarder()
3142 bool ProcessEvent( wxEvent
& event
)
3147 m_propGrid
->HandleCustomEditorEvent(event
);
3149 return wxEvtHandler::ProcessEvent(event
);
3152 wxPropertyGrid
* m_propGrid
;
3155 // Setups event handling for child control
3156 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3158 wxWindowID id
= argWnd
->GetId();
3160 if ( argWnd
== m_wndEditor
)
3162 argWnd
->Connect(id
, wxEVT_MOTION
,
3163 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3165 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3166 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3168 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3169 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3171 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3172 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3174 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3175 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3177 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3178 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3182 wxPropertyGridEditorEventForwarder
* forwarder
;
3183 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3184 argWnd
->PushEventHandler(forwarder
);
3186 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3187 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3191 void wxPropertyGrid::FreeEditors()
3194 // Return focus back to canvas from children (this is required at least for
3195 // GTK+, which, unlike Windows, clears focus when control is destroyed
3196 // instead of moving it to closest parent).
3197 wxWindow
* focus
= wxWindow::FindFocus();
3200 wxWindow
* parent
= focus
->GetParent();
3203 if ( parent
== m_canvas
)
3208 parent
= parent
->GetParent();
3212 // Do not free editors immediately if processing events
3215 wxEvtHandler
* handler
= m_wndEditor2
->PopEventHandler(false);
3216 m_wndEditor2
->Hide();
3217 wxPendingDelete
.Append( handler
);
3218 wxPendingDelete
.Append( m_wndEditor2
);
3219 m_wndEditor2
= NULL
;
3224 wxEvtHandler
* handler
= m_wndEditor
->PopEventHandler(false);
3225 m_wndEditor
->Hide();
3226 wxPendingDelete
.Append( handler
);
3227 wxPendingDelete
.Append( m_wndEditor
);
3232 // Call with NULL to de-select property
3233 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3237 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3238 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3240 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3243 if ( m_inDoSelectProperty
)
3246 m_inDoSelectProperty
= 1;
3248 wxPGProperty
* prev
= m_selected
;
3252 m_inDoSelectProperty
= 0;
3258 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3260 wxPrintf( "None selected\n" );
3263 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3265 wxPrintf( "P = NULL\n" );
3268 // If we are frozen, then just set the values.
3271 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3272 m_editorFocused
= 0;
3275 m_pState
->m_selected
= p
;
3277 // If frozen, always free controls. But don't worry, as Thaw will
3278 // recall SelectProperty to recreate them.
3281 // Prevent any further selection measures in this call
3287 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3289 // Only set focus if not deselecting
3292 if ( flags
& wxPG_SEL_FOCUS
)
3296 m_wndEditor
->SetFocus();
3297 m_editorFocused
= 1;
3306 m_inDoSelectProperty
= 0;
3311 // First, deactivate previous
3315 OnValidationFailureReset(m_selected
);
3317 // Must double-check if this is an selected in case of forceswitch
3320 if ( !CommitChangesFromEditor(flags
) )
3322 // Validation has failed, so we can't exit the previous editor
3323 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3324 // _("Invalid Value"),wxOK|wxICON_ERROR);
3325 m_inDoSelectProperty
= 0;
3334 m_pState
->m_selected
= NULL
;
3336 // We need to always fully refresh the grid here
3339 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3340 EditorsValueWasNotModified();
3343 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3346 // Then, activate the one given.
3349 int propY
= p
->GetY2(m_lineHeight
);
3351 int splitterX
= GetSplitterPosition();
3352 m_editorFocused
= 0;
3354 m_pState
->m_selected
= p
;
3355 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3357 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3359 wxASSERT( m_wndEditor
== NULL
);
3362 // Only create editor for non-disabled non-caption
3363 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3365 // do this for non-caption items
3369 // Do we need to paint the custom image, if any?
3370 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3371 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3372 !p
->GetEditorClass()->CanContainCustomImage()
3374 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3376 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3377 wxPoint goodPos
= grect
.GetPosition();
3378 #if wxPG_CREATE_CONTROLS_HIDDEN
3379 int coord_adjust
= m_height
- goodPos
.y
;
3380 goodPos
.y
+= coord_adjust
;
3383 const wxPGEditor
* editor
= p
->GetEditorClass();
3384 wxCHECK_MSG(editor
, false,
3385 wxT("NULL editor class not allowed"));
3387 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3389 wxPGWindowList wndList
= editor
->CreateControls(this,
3394 m_wndEditor
= wndList
.m_primary
;
3395 m_wndEditor2
= wndList
.m_secondary
;
3396 wxWindow
* primaryCtrl
= GetEditorControl();
3399 // Essentially, primaryCtrl == m_wndEditor
3402 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3403 // value is drawn as normal, and m_wndEditor2 is assumed
3404 // to be a right-aligned button that triggers a separate editorCtrl
3409 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3410 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3412 // Set validator, if any
3413 #if wxUSE_VALIDATORS
3414 wxValidator
* validator
= p
->GetValidator();
3416 primaryCtrl
->SetValidator(*validator
);
3419 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3420 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3422 // If it has modified status, use bold font
3423 // (must be done before capturing m_ctrlXAdjust)
3424 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3425 SetCurControlBoldFont();
3428 // Fix TextCtrl indentation
3429 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3430 wxTextCtrl
* tc
= NULL
;
3431 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3432 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3434 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3436 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3439 // Store x relative to splitter (we'll need it).
3440 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3442 // Check if background clear is not necessary
3443 wxPoint pos
= m_wndEditor
->GetPosition();
3444 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3446 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3449 m_wndEditor
->SetSizeHints(3, 3);
3451 #if wxPG_CREATE_CONTROLS_HIDDEN
3452 m_wndEditor
->Show(false);
3453 m_wndEditor
->Freeze();
3455 goodPos
= m_wndEditor
->GetPosition();
3456 goodPos
.y
-= coord_adjust
;
3457 m_wndEditor
->Move( goodPos
);
3460 SetupChildEventHandling(primaryCtrl
);
3462 // Focus and select all (wxTextCtrl, wxComboBox etc)
3463 if ( flags
& wxPG_SEL_FOCUS
)
3465 primaryCtrl
->SetFocus();
3467 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3473 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3474 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3476 // Get proper id for wndSecondary
3477 m_wndSecId
= m_wndEditor2
->GetId();
3478 wxWindowList children
= m_wndEditor2
->GetChildren();
3479 wxWindowList::iterator node
= children
.begin();
3480 if ( node
!= children
.end() )
3481 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3483 m_wndEditor2
->SetSizeHints(3,3);
3485 #if wxPG_CREATE_CONTROLS_HIDDEN
3486 wxRect sec_rect
= m_wndEditor2
->GetRect();
3487 sec_rect
.y
-= coord_adjust
;
3489 // Fine tuning required to fix "oversized"
3490 // button disappearance bug.
3491 if ( sec_rect
.y
< 0 )
3493 sec_rect
.height
+= sec_rect
.y
;
3496 m_wndEditor2
->SetSize( sec_rect
);
3498 m_wndEditor2
->Show();
3500 SetupChildEventHandling(m_wndEditor2
);
3502 // If no primary editor, focus to button to allow
3503 // it to interprete ENTER etc.
3504 // NOTE: Due to problems focusing away from it, this
3505 // has been disabled.
3507 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3508 m_wndEditor2->SetFocus();
3512 if ( flags
& wxPG_SEL_FOCUS
)
3513 m_editorFocused
= 1;
3518 // Make sure focus is in grid canvas (important for wxGTK, at least)
3522 EditorsValueWasNotModified();
3524 // If it's inside collapsed section, expand parent, scroll, etc.
3525 // Also, if it was partially visible, scroll it into view.
3526 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3531 #if wxPG_CREATE_CONTROLS_HIDDEN
3532 m_wndEditor
->Thaw();
3534 m_wndEditor
->Show(true);
3541 // Make sure focus is in grid canvas
3545 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3551 // Show help text in status bar.
3552 // (if found and grid not embedded in manager with help box and
3553 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3556 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3558 wxStatusBar
* statusbar
= NULL
;
3559 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3561 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3563 statusbar
= frame
->GetStatusBar();
3568 const wxString
* pHelpString
= (const wxString
*) NULL
;
3572 pHelpString
= &p
->GetHelpString();
3573 if ( pHelpString
->length() )
3575 // Set help box text.
3576 statusbar
->SetStatusText( *pHelpString
);
3577 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3581 if ( (!pHelpString
|| !pHelpString
->length()) &&
3582 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3584 // Clear help box - but only if it was written
3585 // by us at previous time.
3586 statusbar
->SetStatusText( m_emptyString
);
3587 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3593 m_inDoSelectProperty
= 0;
3595 // call wx event handler (here so that it also occurs on deselection)
3596 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3601 // -----------------------------------------------------------------------
3603 bool wxPropertyGrid::UnfocusEditor()
3605 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3608 if ( !CommitChangesFromEditor(0) )
3612 DrawItem(m_selected
);
3617 // -----------------------------------------------------------------------
3619 void wxPropertyGrid::RefreshEditor()
3621 wxPGProperty
* p
= m_selected
;
3625 wxWindow
* wnd
= GetEditorControl();
3629 // Set editor font boldness - must do this before
3630 // calling UpdateControl().
3631 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3633 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3634 wnd
->SetFont(GetCaptionFont());
3636 wnd
->SetFont(GetFont());
3639 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3641 editorClass
->UpdateControl(p
, wnd
);
3643 if ( p
->IsValueUnspecified() )
3644 editorClass
->SetValueToUnspecified(p
, wnd
);
3647 // -----------------------------------------------------------------------
3649 // This method is not inline because it called dozens of times
3650 // (i.e. two-arg function calls create smaller code size).
3651 bool wxPropertyGrid::DoClearSelection()
3653 return DoSelectProperty(NULL
);
3656 // -----------------------------------------------------------------------
3657 // wxPropertyGrid expand/collapse state
3658 // -----------------------------------------------------------------------
3660 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3662 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3664 // If active editor was inside collapsed section, then disable it
3665 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3667 ClearSelection(false);
3670 // Store dont-center-splitter flag 'cause we need to temporarily set it
3671 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3672 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3674 bool res
= m_pState
->DoCollapse(pwc
);
3679 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3681 RecalculateVirtualSize();
3683 // Redraw etc. only if collapsed was visible.
3684 if (pwc
->IsVisible() &&
3686 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3688 // When item is collapsed so that scrollbar would move,
3689 // graphics mess is about (unless we redraw everything).
3694 // Clear dont-center-splitter flag if it wasn't set
3695 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3700 // -----------------------------------------------------------------------
3702 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3704 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3706 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3708 // Store dont-center-splitter flag 'cause we need to temporarily set it
3709 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3710 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3712 bool res
= m_pState
->DoExpand(pwc
);
3717 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3719 RecalculateVirtualSize();
3721 // Redraw etc. only if expanded was visible.
3722 if ( pwc
->IsVisible() && !m_frozen
&&
3723 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3727 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3730 DrawItems(pwc
, NULL
);
3735 // Clear dont-center-splitter flag if it wasn't set
3736 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3741 // -----------------------------------------------------------------------
3743 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3746 return m_pState
->DoHideProperty(p
, hide
, flags
);
3749 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3752 ClearSelection(false);
3755 m_pState
->DoHideProperty(p
, hide
, flags
);
3757 RecalculateVirtualSize();
3764 // -----------------------------------------------------------------------
3765 // wxPropertyGrid size related methods
3766 // -----------------------------------------------------------------------
3768 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3770 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3774 // If virtual height was changed, then recalculate editor control position(s)
3775 if ( m_pState
->m_vhCalcPending
)
3776 CorrectEditorWidgetPosY();
3778 m_pState
->EnsureVirtualHeight();
3781 int by1
= m_pState
->GetVirtualHeight();
3782 int by2
= m_pState
->GetActualVirtualHeight();
3785 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3786 wxFAIL_MSG(s
.c_str());
3791 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3793 int x
= m_pState
->m_width
;
3794 int y
= m_pState
->m_virtualHeight
;
3797 GetClientSize(&width
,&height
);
3799 // Now adjust virtual size.
3800 SetVirtualSize(x
, y
);
3806 // Adjust scrollbars
3807 if ( HasVirtualWidth() )
3809 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3810 xPos
= GetScrollPos( wxHORIZONTAL
);
3813 if ( forceXPos
!= -1 )
3816 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3819 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3820 int yPos
= GetScrollPos( wxVERTICAL
);
3822 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3823 xAmount
, yAmount
, xPos
, yPos
, true );
3825 // Must re-get size now
3826 GetClientSize(&width
,&height
);
3828 if ( !HasVirtualWidth() )
3830 m_pState
->SetVirtualWidth(width
);
3837 m_canvas
->SetSize( x
, y
);
3839 m_pState
->CheckColumnWidths();
3842 CorrectEditorWidgetSizeX();
3844 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3847 // -----------------------------------------------------------------------
3849 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3851 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3855 GetClientSize(&width
,&height
);
3860 #if wxPG_DOUBLE_BUFFER
3861 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3863 int dblh
= (m_lineHeight
*2);
3864 if ( !m_doubleBuffer
)
3866 // Create double buffer bitmap to draw on, if none
3867 int w
= (width
>250)?width
:250;
3868 int h
= height
+ dblh
;
3870 m_doubleBuffer
= new wxBitmap( w
, h
);
3874 int w
= m_doubleBuffer
->GetWidth();
3875 int h
= m_doubleBuffer
->GetHeight();
3877 // Double buffer must be large enough
3878 if ( w
< width
|| h
< (height
+dblh
) )
3880 if ( w
< width
) w
= width
;
3881 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3882 delete m_doubleBuffer
;
3883 m_doubleBuffer
= new wxBitmap( w
, h
);
3890 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3891 m_ncWidth
= event
.GetSize().x
;
3895 if ( m_pState
->m_itemsAdded
)
3896 PrepareAfterItemsAdded();
3898 // Without this, virtual size (atleast under wxGTK) will be skewed
3899 RecalculateVirtualSize();
3905 // -----------------------------------------------------------------------
3907 void wxPropertyGrid::SetVirtualWidth( int width
)
3911 // Disable virtual width
3912 width
= GetClientSize().x
;
3913 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3917 // Enable virtual width
3918 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3920 m_pState
->SetVirtualWidth( width
);
3923 void wxPropertyGrid::SetFocusOnCanvas()
3925 m_canvas
->SetFocusIgnoringChildren();
3926 m_editorFocused
= 0;
3929 // -----------------------------------------------------------------------
3930 // wxPropertyGrid mouse event handling
3931 // -----------------------------------------------------------------------
3933 // selFlags uses same values DoSelectProperty's flags
3934 // Returns true if event was vetoed.
3935 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3937 // Send property grid event of specific type and with specific property
3938 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3939 evt
.SetPropertyGrid(this);
3940 evt
.SetEventObject(m_eventObject
);
3944 evt
.SetCanVeto(true);
3945 evt
.SetupValidationInfo();
3946 m_validationInfo
.m_pValue
= pValue
;
3948 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3950 evtHandler
->ProcessEvent(evt
);
3952 return evt
.WasVetoed();
3955 // -----------------------------------------------------------------------
3957 // Return false if should be skipped
3958 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3962 // Need to set focus?
3963 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3968 wxPropertyGridPageState
* state
= m_pState
;
3970 int splitterHitOffset
;
3971 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3973 wxPGProperty
* p
= DoGetItemAtY(y
);
3977 int depth
= (int)p
->GetDepth() - 1;
3979 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3981 if ( x
>= marginEnds
)
3985 if ( p
->IsCategory() )
3987 // This is category.
3988 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3990 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3992 // Expand, collapse, activate etc. if click on text or left of splitter.
3995 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4000 if ( !DoSelectProperty( p
) )
4003 // On double-click, expand/collapse.
4004 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4006 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4007 else DoExpand( p
, true );
4011 else if ( splitterHit
== -1 )
4014 unsigned int selFlag
= 0;
4015 if ( columnHit
== 1 )
4017 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4018 selFlag
= wxPG_SEL_FOCUS
;
4020 if ( !DoSelectProperty( p
, selFlag
) )
4023 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4025 if ( p
->GetChildCount() && !p
->IsCategory() )
4026 // On double-click, expand/collapse.
4027 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4029 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4030 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4031 else DoExpand( p
, true );
4038 // click on splitter
4039 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4041 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4043 // Double-clicking the splitter causes auto-centering
4044 CenterSplitter( true );
4046 else if ( m_dragStatus
== 0 )
4049 // Begin draggin the splitter
4053 // Changes must be committed here or the
4054 // value won't be drawn correctly
4055 if ( !CommitChangesFromEditor() )
4058 m_wndEditor
->Show ( false );
4061 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4063 m_canvas
->CaptureMouse();
4064 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4068 m_draggedSplitter
= splitterHit
;
4069 m_dragOffset
= splitterHitOffset
;
4071 wxClientDC
dc(m_canvas
);
4073 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4074 // Fixes button disappearance bug
4076 m_wndEditor2
->Show ( false );
4079 m_startingSplitterX
= x
- splitterHitOffset
;
4087 if ( p
->GetChildCount() )
4089 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4091 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4093 int y2
= y
% m_lineHeight
;
4094 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4096 // On click on expander button, expand/collapse
4097 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4098 DoCollapse( p
, true );
4100 DoExpand( p
, true );
4109 // -----------------------------------------------------------------------
4111 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4112 wxMouseEvent
& WXUNUSED(event
) )
4116 // Select property here as well
4117 wxPGProperty
* p
= m_propHover
;
4118 if ( p
!= m_selected
)
4119 DoSelectProperty( p
);
4121 // Send right click event.
4122 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4129 // -----------------------------------------------------------------------
4131 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4132 wxMouseEvent
& WXUNUSED(event
) )
4136 // Select property here as well
4137 wxPGProperty
* p
= m_propHover
;
4139 if ( p
!= m_selected
)
4140 DoSelectProperty( p
);
4142 // Send double-click event.
4143 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4150 // -----------------------------------------------------------------------
4152 #if wxPG_SUPPORT_TOOLTIPS
4154 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4156 if ( tipString
.length() )
4158 m_canvas
->SetToolTip(tipString
);
4162 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4163 m_canvas
->SetToolTip( m_emptyString
);
4165 m_canvas
->SetToolTip( NULL
);
4170 #endif // #if wxPG_SUPPORT_TOOLTIPS
4172 // -----------------------------------------------------------------------
4174 // Return false if should be skipped
4175 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4177 // Safety check (needed because mouse capturing may
4178 // otherwise freeze the control)
4179 if ( m_dragStatus
> 0 && !event
.Dragging() )
4181 HandleMouseUp(x
,y
,event
);
4184 wxPropertyGridPageState
* state
= m_pState
;
4186 int splitterHitOffset
;
4187 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4188 int splitterX
= x
- splitterHitOffset
;
4190 if ( m_dragStatus
> 0 )
4192 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4193 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4196 int newSplitterX
= x
- m_dragOffset
;
4197 int splitterX
= x
- splitterHitOffset
;
4199 // Splitter redraw required?
4200 if ( newSplitterX
!= splitterX
)
4203 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4204 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4205 state
->m_fSplitterX
= (float) newSplitterX
;
4208 CorrectEditorWidgetSizeX();
4222 int ih
= m_lineHeight
;
4225 #if wxPG_SUPPORT_TOOLTIPS
4226 wxPGProperty
* prevHover
= m_propHover
;
4227 unsigned char prevSide
= m_mouseSide
;
4229 int curPropHoverY
= y
- (y
% ih
);
4231 // On which item it hovers
4234 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4237 // Mouse moves on another property
4239 m_propHover
= DoGetItemAtY(y
);
4240 m_propHoverY
= curPropHoverY
;
4243 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4246 #if wxPG_SUPPORT_TOOLTIPS
4247 // Store which side we are on
4249 if ( columnHit
== 1 )
4251 else if ( columnHit
== 0 )
4255 // If tooltips are enabled, show label or value as a tip
4256 // in case it doesn't otherwise show in full length.
4258 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4260 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4262 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4264 if ( m_propHover
&& !m_propHover
->IsCategory() )
4267 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4269 // Show help string as a tooltip
4270 wxString tipString
= m_propHover
->GetHelpString();
4272 SetToolTip(tipString
);
4276 // Show cropped value string as a tooltip
4280 if ( m_mouseSide
== 1 )
4282 tipString
= m_propHover
->m_label
;
4283 space
= splitterX
-m_marginWidth
-3;
4285 else if ( m_mouseSide
== 2 )
4287 tipString
= m_propHover
->GetDisplayedString();
4289 space
= m_width
- splitterX
;
4290 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4291 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4297 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4300 SetToolTip( tipString
);
4307 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4308 m_canvas
->SetToolTip( m_emptyString
);
4310 m_canvas
->SetToolTip( NULL
);
4321 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4322 m_canvas
->SetToolTip( m_emptyString
);
4324 m_canvas
->SetToolTip( NULL
);
4332 if ( splitterHit
== -1 ||
4334 HasFlag(wxPG_STATIC_SPLITTER
) )
4336 // hovering on something else
4337 if ( m_curcursor
!= wxCURSOR_ARROW
)
4338 CustomSetCursor( wxCURSOR_ARROW
);
4342 // Do not allow splitter cursor on caption items.
4343 // (also not if we were dragging and its started
4344 // outside the splitter region)
4346 if ( !m_propHover
->IsCategory() &&
4350 // hovering on splitter
4352 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4353 // reliably detected.
4354 //if ( m_curcursor != wxCURSOR_SIZEWE )
4355 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4361 // hovering on something else
4362 if ( m_curcursor
!= wxCURSOR_ARROW
)
4363 CustomSetCursor( wxCURSOR_ARROW
);
4370 // -----------------------------------------------------------------------
4372 // Also handles Leaving event
4373 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4374 wxMouseEvent
&WXUNUSED(event
) )
4376 wxPropertyGridPageState
* state
= m_pState
;
4380 int splitterHitOffset
;
4381 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4383 // No event type check - basicly calling this method should
4384 // just stop dragging.
4385 // Left up after dragged?
4386 if ( m_dragStatus
>= 1 )
4389 // End Splitter Dragging
4391 // DO NOT ENABLE FOLLOWING LINE!
4392 // (it is only here as a reminder to not to do it)
4395 // Disable splitter auto-centering
4396 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4398 // This is necessary to return cursor
4399 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4401 m_canvas
->ReleaseMouse();
4402 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4405 // Set back the default cursor, if necessary
4406 if ( splitterHit
== -1 ||
4409 CustomSetCursor( wxCURSOR_ARROW
);
4414 // Control background needs to be cleared
4415 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4416 DrawItem( m_selected
);
4420 m_wndEditor
->Show ( true );
4423 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4424 // Fixes button disappearance bug
4426 m_wndEditor2
->Show ( true );
4429 // This clears the focus.
4430 m_editorFocused
= 0;
4436 // -----------------------------------------------------------------------
4438 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4440 int splitterX
= GetSplitterPosition();
4443 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4447 wxWindow
* wnd
= GetEditorControl();
4449 // Hide popup on clicks
4450 if ( event
.GetEventType() != wxEVT_MOTION
)
4451 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4453 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4459 if ( wnd
== NULL
|| m_dragStatus
||
4461 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4462 ux
>= (r
.x
+r
.width
) ||
4464 event
.m_y
>= (r
.y
+r
.height
)
4474 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4479 // -----------------------------------------------------------------------
4481 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4484 if ( OnMouseCommon( event
, &x
, &y
) )
4486 HandleMouseClick(x
,y
,event
);
4491 // -----------------------------------------------------------------------
4493 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4496 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4497 HandleMouseRightClick(x
,y
,event
);
4501 // -----------------------------------------------------------------------
4503 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4505 // Always run standard mouse-down handler as well
4506 OnMouseClick(event
);
4509 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4510 HandleMouseDoubleClick(x
,y
,event
);
4514 // -----------------------------------------------------------------------
4516 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4519 if ( OnMouseCommon( event
, &x
, &y
) )
4521 HandleMouseMove(x
,y
,event
);
4526 // -----------------------------------------------------------------------
4528 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4530 // Called when mouse moves in the empty space below the properties.
4531 CustomSetCursor( wxCURSOR_ARROW
);
4534 // -----------------------------------------------------------------------
4536 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4539 if ( OnMouseCommon( event
, &x
, &y
) )
4541 HandleMouseUp(x
,y
,event
);
4546 // -----------------------------------------------------------------------
4548 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4550 // This may get called from child control as well, so event's
4551 // mouse position cannot be relied on.
4553 if ( event
.Entering() )
4555 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4557 // TODO: Fix this (detect parent and only do
4558 // cursor trick if it is a manager).
4559 wxASSERT( GetParent() );
4560 GetParent()->SetCursor(wxNullCursor
);
4562 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4565 GetParent()->SetCursor(wxNullCursor
);
4567 else if ( event
.Leaving() )
4569 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4570 m_canvas
->SetCursor( wxNullCursor
);
4572 // Get real cursor position
4573 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4575 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4578 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4580 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4584 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4592 // -----------------------------------------------------------------------
4594 // Common code used by various OnMouseXXXChild methods.
4595 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4597 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4598 wxASSERT( topCtrlWnd
);
4600 event
.GetPosition(&x
,&y
);
4602 int splitterX
= GetSplitterPosition();
4604 wxRect r
= topCtrlWnd
->GetRect();
4605 if ( !m_dragStatus
&&
4606 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4607 y
>= 0 && y
< r
.height \
4610 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4615 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4622 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4625 if ( OnMouseChildCommon(event
,&x
,&y
) )
4627 bool res
= HandleMouseClick(x
,y
,event
);
4628 if ( !res
) event
.Skip();
4632 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4635 wxASSERT( m_wndEditor
);
4636 // These coords may not be exact (about +-2),
4637 // but that should not matter (right click is about item, not position).
4638 wxPoint pt
= m_wndEditor
->GetPosition();
4639 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4640 wxASSERT( m_selected
);
4641 m_propHover
= m_selected
;
4642 bool res
= HandleMouseRightClick(x
,y
,event
);
4643 if ( !res
) event
.Skip();
4646 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4649 if ( OnMouseChildCommon(event
,&x
,&y
) )
4651 bool res
= HandleMouseMove(x
,y
,event
);
4652 if ( !res
) event
.Skip();
4656 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4659 if ( OnMouseChildCommon(event
,&x
,&y
) )
4661 bool res
= HandleMouseUp(x
,y
,event
);
4662 if ( !res
) event
.Skip();
4666 // -----------------------------------------------------------------------
4667 // wxPropertyGrid keyboard event handling
4668 // -----------------------------------------------------------------------
4670 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4672 // Translates wxKeyEvent to wxPG_ACTION_XXX
4674 int keycode
= event
.GetKeyCode();
4675 int modifiers
= event
.GetModifiers();
4677 wxASSERT( !(modifiers
&~(0xFFFF)) );
4679 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4681 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4683 if ( it
== m_actionTriggers
.end() )
4688 int second
= (it
->second
>>16) & 0xFFFF;
4692 return (it
->second
& 0xFFFF);
4695 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4697 wxASSERT( !(modifiers
&~(0xFFFF)) );
4699 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4701 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4703 if ( it
!= m_actionTriggers
.end() )
4705 // This key combination is already used
4707 // Can add secondary?
4708 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4709 wxT("You can only add up to two separate actions per key combination.") );
4711 action
= it
->second
| (action
<<16);
4714 m_actionTriggers
[hashMapKey
] = action
;
4717 void wxPropertyGrid::ClearActionTriggers( int action
)
4719 wxPGHashMapI2I::iterator it
;
4721 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4723 if ( it
->second
== action
)
4725 m_actionTriggers
.erase(it
);
4730 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4733 // Handles key event when editor control is not focused.
4736 wxCHECK2(!m_frozen
, return);
4738 // Travelsal between items, collapsing/expanding, etc.
4739 int keycode
= event
.GetKeyCode();
4740 bool editorFocused
= IsEditorFocused();
4742 if ( keycode
== WXK_TAB
)
4744 wxWindow
* mainControl
;
4746 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4747 mainControl
= GetParent();
4751 if ( !event
.ShiftDown() )
4753 if ( !editorFocused
&& m_wndEditor
)
4755 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4759 // Tab traversal workaround for platforms on which
4760 // wxWindow::Navigate() may navigate into first child
4761 // instead of next sibling. Does not work perfectly
4762 // in every scenario (for instance, when property grid
4763 // is either first or last control).
4764 #if defined(__WXGTK__)
4765 wxWindow
* sibling
= mainControl
->GetNextSibling();
4767 sibling
->SetFocusFromKbd();
4769 Navigate(wxNavigationKeyEvent::IsForward
);
4775 if ( editorFocused
)
4781 #if defined(__WXGTK__)
4782 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4784 sibling
->SetFocusFromKbd();
4786 Navigate(wxNavigationKeyEvent::IsBackward
);
4794 // Ignore Alt and Control when they are down alone
4795 if ( keycode
== WXK_ALT
||
4796 keycode
== WXK_CONTROL
)
4803 int action
= KeyEventToActions(event
, &secondAction
);
4805 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4808 // Esc cancels any changes
4809 if ( IsEditorsValueModified() )
4811 EditorsValueWasNotModified();
4813 // Update the control as well
4814 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4816 m_selected
->GetDisplayedString() );
4819 OnValidationFailureReset(m_selected
);
4825 // Except for TAB and ESC, handle child control events in child control
4828 // Only propagate event if it had modifiers
4829 if ( !event
.HasModifiers() )
4831 event
.StopPropagation();
4837 bool wasHandled
= false;
4842 if ( ButtonTriggerKeyTest(action
, event
) )
4845 wxPGProperty
* p
= m_selected
;
4847 // Travel and expand/collapse
4850 if ( p
->GetChildCount() &&
4851 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4854 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4856 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4859 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4861 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4868 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4872 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4878 if ( selectDir
>= -1 )
4880 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4882 DoSelectProperty(p
);
4888 // If nothing was selected, select the first item now
4889 // (or navigate out of tab).
4890 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4892 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4893 if ( p
) DoSelectProperty(p
);
4902 // -----------------------------------------------------------------------
4904 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4906 // If there was editor open and focused, then this event should not
4907 // really be processed here.
4908 if ( IsEditorFocused() )
4910 // However, if event had modifiers, it is probably still best
4912 if ( event
.HasModifiers() )
4915 event
.StopPropagation();
4919 HandleKeyEvent(event
, false);
4922 // -----------------------------------------------------------------------
4924 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4929 action
= KeyEventToActions(event
, &secondAction
);
4932 // Does the keycode trigger button?
4933 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4936 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4937 GetEventHandler()->AddPendingEvent(evt
);
4944 // -----------------------------------------------------------------------
4946 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4948 HandleKeyEvent(event
, true);
4951 // -----------------------------------------------------------------------
4952 // wxPropertyGrid miscellaneous event handling
4953 // -----------------------------------------------------------------------
4955 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4958 // Check if the focus is in this control or one of its children
4959 wxWindow
* newFocused
= wxWindow::FindFocus();
4961 if ( newFocused
!= m_curFocused
)
4962 HandleFocusChange( newFocused
);
4965 bool wxPropertyGrid::IsEditorFocused() const
4967 wxWindow
* focus
= wxWindow::FindFocus();
4969 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4970 focus
== GetEditorControl() )
4976 // Called by focus event handlers. newFocused is the window that becomes focused.
4977 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4979 unsigned int oldFlags
= m_iFlags
;
4981 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4983 wxWindow
* parent
= newFocused
;
4985 // This must be one of nextFocus' parents.
4988 // Use m_eventObject, which is either wxPropertyGrid or
4989 // wxPropertyGridManager, as appropriate.
4990 if ( parent
== m_eventObject
)
4992 m_iFlags
|= wxPG_FL_FOCUSED
;
4995 parent
= parent
->GetParent();
4998 m_curFocused
= newFocused
;
5000 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5001 (oldFlags
& wxPG_FL_FOCUSED
) )
5003 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5005 // Need to store changed value
5006 CommitChangesFromEditor();
5012 // Preliminary code for tab-order respecting
5013 // tab-traversal (but should be moved to
5016 wxWindow* prevFocus = event.GetWindow();
5017 wxWindow* useThis = this;
5018 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5019 useThis = GetParent();
5022 prevFocus->GetParent() == useThis->GetParent() )
5024 wxList& children = useThis->GetParent()->GetChildren();
5026 wxNode* node = children.Find(prevFocus);
5028 if ( node->GetNext() &&
5029 useThis == node->GetNext()->GetData() )
5030 DoSelectProperty(GetFirst());
5031 else if ( node->GetPrevious () &&
5032 useThis == node->GetPrevious()->GetData() )
5033 DoSelectProperty(GetLastProperty());
5040 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5041 DrawItem( m_selected
);
5045 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5047 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5048 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5049 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5050 //else if ( event.GetWindow() )
5052 HandleFocusChange(event
.GetWindow());
5057 // -----------------------------------------------------------------------
5059 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5061 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5064 // event.Skip() being commented out is aworkaround for bug reported
5065 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5069 // -----------------------------------------------------------------------
5071 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5073 m_iFlags
|= wxPG_FL_SCROLLED
;
5078 // -----------------------------------------------------------------------
5080 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5082 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5084 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5088 // -----------------------------------------------------------------------
5089 // Property editor related functions
5090 // -----------------------------------------------------------------------
5092 // noDefCheck = true prevents infinite recursion.
5093 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5096 wxASSERT( editorClass
);
5098 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5099 RegisterDefaultEditors();
5101 wxString name
= editorClass
->GetName();
5103 // Existing editor under this name?
5104 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5106 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5108 // If this name was already used, try class name.
5109 name
= editorClass
->GetClassInfo()->GetClassName();
5110 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5113 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5114 (wxPGEditor
*) vt_it
->second
,
5115 "Editor with given name was already registered" );
5117 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5122 // Use this in RegisterDefaultEditors.
5123 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5124 if ( wxPGEditor_##EDITOR == NULL ) \
5126 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5127 new wxPG##EDITOR##Editor, true ); \
5130 // Registers all default editor classes
5131 void wxPropertyGrid::RegisterDefaultEditors()
5133 wxPGRegisterDefaultEditorClass( TextCtrl
);
5134 wxPGRegisterDefaultEditorClass( Choice
);
5135 wxPGRegisterDefaultEditorClass( ComboBox
);
5136 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5137 #if wxPG_INCLUDE_CHECKBOX
5138 wxPGRegisterDefaultEditorClass( CheckBox
);
5140 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5142 // Register SpinCtrl etc. editors before use
5143 RegisterAdditionalEditors();
5146 // -----------------------------------------------------------------------
5147 // wxPGStringTokenizer
5148 // Needed to handle C-style string lists (e.g. "str1" "str2")
5149 // -----------------------------------------------------------------------
5151 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5152 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5156 wxPGStringTokenizer::~wxPGStringTokenizer()
5160 bool wxPGStringTokenizer::HasMoreTokens()
5162 const wxString
& str
= *m_str
;
5164 wxString::const_iterator i
= m_curPos
;
5166 wxUniChar delim
= m_delimeter
;
5168 wxUniChar prev_a
= wxT('\0');
5170 bool inToken
= false;
5172 while ( i
!= str
.end() )
5181 m_readyToken
.clear();
5186 if ( prev_a
!= wxT('\\') )
5190 if ( a
!= wxT('\\') )
5210 m_curPos
= str
.end();
5218 wxString
wxPGStringTokenizer::GetNextToken()
5220 return m_readyToken
;
5223 // -----------------------------------------------------------------------
5225 // -----------------------------------------------------------------------
5227 wxPGChoiceEntry::wxPGChoiceEntry()
5228 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5232 // -----------------------------------------------------------------------
5234 // -----------------------------------------------------------------------
5236 wxPGChoicesData::wxPGChoicesData()
5241 wxPGChoicesData::~wxPGChoicesData()
5246 void wxPGChoicesData::Clear()
5251 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5253 wxASSERT( m_items
.size() == 0 );
5255 m_items
= data
->m_items
;
5258 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5259 const wxPGChoiceEntry
& item
)
5261 wxVector
<wxPGChoiceEntry
>::iterator it
;
5265 index
= (int) m_items
.size();
5269 it
= m_items
.begin() + index
;
5272 m_items
.insert(it
, item
);
5274 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5276 // Need to fix value?
5277 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5278 ownEntry
.SetValue(index
);
5283 // -----------------------------------------------------------------------
5284 // wxPropertyGridEvent
5285 // -----------------------------------------------------------------------
5287 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5290 wxDEFINE_EVENT( wxEVT_PG_SELECTED
, wxPropertyGridEvent
);
5291 wxDEFINE_EVENT( wxEVT_PG_CHANGING
, wxPropertyGridEvent
);
5292 wxDEFINE_EVENT( wxEVT_PG_CHANGED
, wxPropertyGridEvent
);
5293 wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED
, wxPropertyGridEvent
);
5294 wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK
, wxPropertyGridEvent
);
5295 wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED
, wxPropertyGridEvent
);
5296 wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED
, wxPropertyGridEvent
);
5297 wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED
, wxPropertyGridEvent
);
5298 wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK
, wxPropertyGridEvent
);
5301 // -----------------------------------------------------------------------
5303 void wxPropertyGridEvent::Init()
5305 m_validationInfo
= NULL
;
5307 m_wasVetoed
= false;
5310 // -----------------------------------------------------------------------
5312 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5313 : wxCommandEvent(commandType
,id
)
5319 // -----------------------------------------------------------------------
5321 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5322 : wxCommandEvent(event
)
5324 m_eventType
= event
.GetEventType();
5325 m_eventObject
= event
.m_eventObject
;
5327 m_property
= event
.m_property
;
5328 m_validationInfo
= event
.m_validationInfo
;
5329 m_canVeto
= event
.m_canVeto
;
5330 m_wasVetoed
= event
.m_wasVetoed
;
5333 // -----------------------------------------------------------------------
5335 wxPropertyGridEvent::~wxPropertyGridEvent()
5339 // -----------------------------------------------------------------------
5341 wxEvent
* wxPropertyGridEvent::Clone() const
5343 return new wxPropertyGridEvent( *this );
5346 // -----------------------------------------------------------------------
5347 // wxPropertyGridPopulator
5348 // -----------------------------------------------------------------------
5350 wxPropertyGridPopulator::wxPropertyGridPopulator()
5354 wxPGGlobalVars
->m_offline
++;
5357 // -----------------------------------------------------------------------
5359 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5362 m_propHierarchy
.clear();
5365 // -----------------------------------------------------------------------
5367 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5373 // -----------------------------------------------------------------------
5375 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5378 // Free unused sets of choices
5379 wxPGHashMapS2P::iterator it
;
5381 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5383 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5390 m_pg
->GetPanel()->Refresh();
5392 wxPGGlobalVars
->m_offline
--;
5395 // -----------------------------------------------------------------------
5397 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5398 const wxString
& propLabel
,
5399 const wxString
& propName
,
5400 const wxString
* propValue
,
5401 wxPGChoices
* pChoices
)
5403 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5404 wxPGProperty
* parent
= GetCurParent();
5406 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5408 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5412 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5414 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5418 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5420 property
->SetLabel(propLabel
);
5421 property
->DoSetName(propName
);
5423 if ( pChoices
&& pChoices
->IsOk() )
5424 property
->SetChoices(*pChoices
);
5426 m_state
->DoInsert(parent
, -1, property
);
5429 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5430 wxPG_PROGRAMMATIC_VALUE
);
5435 // -----------------------------------------------------------------------
5437 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5439 m_propHierarchy
.push_back(property
);
5440 DoScanForChildren();
5441 m_propHierarchy
.pop_back();
5444 // -----------------------------------------------------------------------
5446 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5447 const wxString
& idString
)
5449 wxPGChoices choices
;
5452 if ( choicesString
[0] == wxT('@') )
5454 wxString ids
= choicesString
.substr(1);
5455 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5456 if ( it
== m_dictIdChoices
.end() )
5457 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5459 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5464 if ( idString
.length() )
5466 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5467 if ( it
!= m_dictIdChoices
.end() )
5469 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5476 // Parse choices string
5477 wxString::const_iterator it
= choicesString
.begin();
5481 bool labelValid
= false;
5483 for ( ; it
!= choicesString
.end(); ++it
)
5489 if ( c
== wxT('"') )
5494 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5495 choices
.Add(label
, l
);
5498 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5503 else if ( c
== wxT('=') )
5510 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5517 if ( c
== wxT('"') )
5530 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5531 choices
.Add(label
, l
);
5534 if ( !choices
.IsOk() )
5536 choices
.EnsureData();
5540 if ( idString
.length() )
5541 m_dictIdChoices
[idString
] = choices
.GetData();
5548 // -----------------------------------------------------------------------
5550 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5552 if ( s
.Last() == wxT('%') )
5554 wxString s2
= s
.substr(0,s
.length()-1);
5556 if ( s2
.ToLong(&val
, 10) )
5558 *pval
= (val
*max
)/100;
5564 return s
.ToLong(pval
, 10);
5567 // -----------------------------------------------------------------------
5569 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5570 const wxString
& type
,
5571 const wxString
& value
)
5573 int l
= m_propHierarchy
.size();
5577 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5578 wxString valuel
= value
.Lower();
5581 if ( type
.length() == 0 )
5586 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5588 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5590 else if ( value
.ToLong(&v
, 0) )
5597 if ( type
== wxT("string") )
5601 else if ( type
== wxT("int") )
5604 value
.ToLong(&v
, 0);
5607 else if ( type
== wxT("bool") )
5609 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5616 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5621 p
->SetAttribute( name
, variant
);
5626 // -----------------------------------------------------------------------
5628 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5630 wxLogError(_("Error in resource: %s"),msg
.c_str());
5633 // -----------------------------------------------------------------------
5635 #endif // wxUSE_PROPGRID