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
= (wxPGGlobalVarsClass
*) 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
= (wxPGChoices
*) 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 // Repaint this rectangle
368 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
370 // We assume that the size set when grid is shown
371 // is what is desired.
372 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
375 // -----------------------------------------------------------------------
377 // -----------------------------------------------------------------------
379 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
381 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
382 EVT_IDLE(wxPropertyGrid::OnIdle
)
383 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
384 EVT_PAINT(wxPropertyGrid::OnPaint
)
385 EVT_SIZE(wxPropertyGrid::OnResize
)
386 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
387 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
388 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
389 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
390 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
391 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
392 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
393 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
397 // -----------------------------------------------------------------------
399 wxPropertyGrid::wxPropertyGrid()
405 // -----------------------------------------------------------------------
407 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
412 const wxString
& name
)
416 Create(parent
,id
,pos
,size
,style
,name
);
419 // -----------------------------------------------------------------------
421 bool wxPropertyGrid::Create( wxWindow
*parent
,
426 const wxString
& name
)
429 if ( !(style
&wxBORDER_MASK
) )
430 style
|= wxSIMPLE_BORDER
;
434 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
435 style
&= ~(wxTAB_TRAVERSAL
);
436 style
|= wxWANTS_CHARS
;
438 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
445 // -----------------------------------------------------------------------
448 // Initialize values to defaults
450 void wxPropertyGrid::Init1()
452 // Register editor classes, if necessary.
453 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
454 wxPropertyGrid::RegisterDefaultEditors();
457 m_pState
= (wxPropertyGridPageState
*) NULL
;
458 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
459 m_selected
= (wxPGProperty
*) NULL
;
461 m_propHover
= (wxPGProperty
*) NULL
;
462 m_eventObject
= this;
463 m_curFocused
= (wxWindow
*) NULL
;
465 m_sortFunction
= NULL
;
466 m_inDoPropertyChanged
= 0;
467 m_inCommitChangesFromEditor
= 0;
468 m_inDoSelectProperty
= 0;
469 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
475 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
476 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
477 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
478 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
479 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
480 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
481 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
482 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
483 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
485 m_coloursCustomized
= 0;
490 #if wxPG_DOUBLE_BUFFER
491 m_doubleBuffer
= (wxBitmap
*) NULL
;
494 #ifndef wxPG_ICON_WIDTH
500 m_iconWidth
= wxPG_ICON_WIDTH
;
505 m_gutterWidth
= wxPG_GUTTER_MIN
;
506 m_subgroup_extramargin
= 10;
510 m_width
= m_height
= 0;
512 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
515 m_chgInfo_changedProperty
= NULL
;
518 // -----------------------------------------------------------------------
521 // Initialize after parent etc. set
523 void wxPropertyGrid::Init2()
525 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
528 // Smaller controls on Mac
529 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
532 // Now create state, if one didn't exist already
533 // (wxPropertyGridManager might have created it for us).
536 m_pState
= CreateState();
537 m_pState
->m_pPropGrid
= this;
538 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
541 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
542 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
544 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
546 m_pState
->InitNonCatMode();
548 m_pState
->m_properties
= m_pState
->m_abcArray
;
551 GetClientSize(&m_width
,&m_height
);
553 #ifndef wxPG_ICON_WIDTH
554 // create two bitmap nodes for drawing
555 m_expandbmp
= new wxBitmap(expand_xpm
);
556 m_collbmp
= new wxBitmap(collapse_xpm
);
558 // calculate average font height for bitmap centering
560 m_iconWidth
= m_expandbmp
->GetWidth();
561 m_iconHeight
= m_expandbmp
->GetHeight();
564 m_curcursor
= wxCURSOR_ARROW
;
565 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
567 // adjust bitmap icon y position so they are centered
568 m_vspacing
= wxPG_DEFAULT_VSPACING
;
572 wxFont useFont
= wxScrolledWindow::GetFont();
573 wxScrolledWindow::SetOwnFont( useFont
);
577 // This should be otherwise called by SetOwnFont
578 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
581 // Allocate cell datas indirectly by calling setter
582 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
583 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
587 // This helps with flicker
588 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
591 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
592 m_tlp
= ::wxGetTopLevelParent(this);
593 m_tlwHandler
= handler
;
594 m_tlp
->PushEventHandler(handler
);
596 // set virtual size to this window size
597 wxSize wndsize
= GetSize();
598 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
600 m_timeCreated
= ::wxGetLocalTimeMillis();
602 m_canvas
= new wxPGCanvas();
603 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
604 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
605 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
607 m_iFlags
|= wxPG_FL_INITIALIZED
;
609 m_ncWidth
= wndsize
.GetWidth();
611 // Need to call OnResize handler or size given in constructor/Create
613 wxSizeEvent
sizeEvent(wndsize
,0);
617 // -----------------------------------------------------------------------
619 wxPropertyGrid::~wxPropertyGrid()
623 DoSelectProperty(NULL
);
625 // This should do prevent things from going too badly wrong
626 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
628 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
629 m_canvas
->ReleaseMouse();
631 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
632 m_tlp
->RemoveEventHandler(handler
);
636 if ( IsEditorsValueModified() )
637 ::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).)"),
638 wxS("wxPropertyGrid Debug Warning") );
641 #if wxPG_DOUBLE_BUFFER
642 if ( m_doubleBuffer
)
643 delete m_doubleBuffer
;
646 //m_selected = (wxPGProperty*) NULL;
648 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
651 delete m_cursorSizeWE
;
653 #ifndef wxPG_ICON_WIDTH
658 // Delete common value records
659 for ( i
=0; i
<m_commonValues
.size(); i
++ )
661 delete GetCommonValue(i
);
665 // -----------------------------------------------------------------------
667 bool wxPropertyGrid::Destroy()
669 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
670 m_canvas
->ReleaseMouse();
672 return wxScrolledWindow::Destroy();
675 // -----------------------------------------------------------------------
677 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
679 return new wxPropertyGridPageState();
682 // -----------------------------------------------------------------------
683 // wxPropertyGrid overridden wxWindow methods
684 // -----------------------------------------------------------------------
686 void wxPropertyGrid::SetWindowStyleFlag( long style
)
688 long old_style
= m_windowStyle
;
690 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
692 wxASSERT( m_pState
);
694 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
697 EnableCategories( true );
699 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
701 // Disable categories
702 EnableCategories( false );
704 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
710 PrepareAfterItemsAdded();
712 m_pState
->m_itemsAdded
= 1;
714 #if wxPG_SUPPORT_TOOLTIPS
715 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
721 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
722 SetToolTip ( tooltip );
723 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
726 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
731 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
736 wxScrolledWindow::SetWindowStyleFlag ( style
);
738 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
740 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
742 CalculateFontAndBitmapStuff( m_vspacing
);
748 // -----------------------------------------------------------------------
750 void wxPropertyGrid::Freeze()
754 wxScrolledWindow::Freeze();
759 // -----------------------------------------------------------------------
761 void wxPropertyGrid::Thaw()
767 wxScrolledWindow::Thaw();
768 RecalculateVirtualSize();
769 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
773 // Force property re-selection
775 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
779 // -----------------------------------------------------------------------
781 void wxPropertyGrid::SetExtraStyle( long exStyle
)
783 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
785 #if defined(__WXMSW__)
788 // Don't use WS_EX_COMPOSITED just now.
791 if ( m_iFlags & wxPG_FL_IN_MANAGER )
792 hWnd = (HWND)GetParent()->GetHWND();
794 hWnd = (HWND)GetHWND();
796 ::SetWindowLong( hWnd, GWL_EXSTYLE,
797 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
800 //#elif defined(__WXGTK20__)
802 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
803 // truly was double-buffered.
804 if ( !this->IsDoubleBuffered() )
806 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
810 #if wxPG_DOUBLE_BUFFER
811 delete m_doubleBuffer
;
812 m_doubleBuffer
= NULL
;
817 wxScrolledWindow::SetExtraStyle( exStyle
);
819 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
820 m_pState
->InitNonCatMode();
822 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
823 m_windowStyle
|= wxPG_TOOLTIPS
;
826 wxPGGlobalVars
->m_extraStyle
= exStyle
;
829 // -----------------------------------------------------------------------
831 // returns the best acceptable minimal size
832 wxSize
wxPropertyGrid::DoGetBestSize() const
835 if ( m_lineHeight
> hei
)
837 wxSize sz
= wxSize( 60, hei
+40 );
843 // -----------------------------------------------------------------------
844 // wxPropertyGrid Font and Colour Methods
845 // -----------------------------------------------------------------------
847 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
851 m_captionFont
= wxScrolledWindow::GetFont();
853 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
854 m_subgroup_extramargin
= x
+ (x
/2);
857 #if wxPG_USE_RENDERER_NATIVE
858 m_iconWidth
= wxPG_ICON_WIDTH
;
859 #elif wxPG_ICON_WIDTH
861 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
862 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
863 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
867 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
868 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
869 m_gutterWidth
= wxPG_GUTTER_MIN
;
872 if ( vspacing
<= 1 ) vdiv
= 12;
873 else if ( vspacing
>= 3 ) vdiv
= 3;
875 m_spacingy
= m_fontHeight
/ vdiv
;
876 if ( m_spacingy
< wxPG_YSPACING_MIN
)
877 m_spacingy
= wxPG_YSPACING_MIN
;
880 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
881 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
883 m_captionFont
.SetWeight(wxBOLD
);
884 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
886 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
889 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
890 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
893 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
895 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
896 RecalculateVirtualSize();
898 InvalidateBestSize();
901 // -----------------------------------------------------------------------
903 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
909 // -----------------------------------------------------------------------
911 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
912 int ga
= 1000, int ba
= 1000,
913 bool forceDifferent
= false)
920 // Recursion guard (allow 2 max)
921 static int isinside
= 0;
923 wxCHECK_MSG( isinside
< 3,
925 wxT("wxPGAdjustColour should not be recursively called more than once") );
933 if ( r2
>255 ) r2
= 255;
934 else if ( r2
<0) r2
= 0;
936 if ( g2
>255 ) g2
= 255;
937 else if ( g2
<0) g2
= 0;
939 if ( b2
>255 ) b2
= 255;
940 else if ( b2
<0) b2
= 0;
942 // Make sure they are somewhat different
943 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
944 dst
= wxPGAdjustColour(src
,-(ra
*2));
946 dst
= wxColour(r2
,g2
,b2
);
948 // Recursion guard (allow 2 max)
955 static int wxPGGetColAvg( const wxColour
& col
)
957 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
961 void wxPropertyGrid::RegainColours()
963 if ( !(m_coloursCustomized
& 0x0002) )
965 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
967 // Make sure colour is dark enough
969 int colDec
= wxPGGetColAvg(col
) - 230;
971 int colDec
= wxPGGetColAvg(col
) - 200;
974 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
977 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
980 if ( !(m_coloursCustomized
& 0x0001) )
981 m_colMargin
= m_colCapBack
;
983 if ( !(m_coloursCustomized
& 0x0004) )
990 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
991 m_colCapFore
= capForeCol
;
992 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
995 if ( !(m_coloursCustomized
& 0x0008) )
997 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
998 m_colPropBack
= bgCol
;
999 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1002 if ( !(m_coloursCustomized
& 0x0010) )
1004 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1005 m_colPropFore
= fgCol
;
1006 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1009 if ( !(m_coloursCustomized
& 0x0020) )
1010 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1012 if ( !(m_coloursCustomized
& 0x0040) )
1013 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1015 if ( !(m_coloursCustomized
& 0x0080) )
1016 m_colLine
= m_colCapBack
;
1018 if ( !(m_coloursCustomized
& 0x0100) )
1019 m_colDisPropFore
= m_colCapFore
;
1021 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1024 // -----------------------------------------------------------------------
1026 void wxPropertyGrid::ResetColours()
1028 m_coloursCustomized
= 0;
1035 // -----------------------------------------------------------------------
1037 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1039 // Must disable active editor.
1040 ClearSelection(false);
1042 // TODO: Following code is disabled with wxMac because
1043 // it is reported to fail. I (JMS) cannot debug it
1044 // personally right now.
1045 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1046 #if 1 // !defined(__WXMAC__)
1047 bool res
= wxScrolledWindow::SetFont( font
);
1050 CalculateFontAndBitmapStuff( m_vspacing
);
1053 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1061 // TODO: Remove after SetFont crash fixed.
1062 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1064 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."));
1070 // -----------------------------------------------------------------------
1072 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1075 m_coloursCustomized
|= 0x80;
1079 // -----------------------------------------------------------------------
1081 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1084 m_coloursCustomized
|= 0x01;
1088 // -----------------------------------------------------------------------
1090 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1092 m_colPropBack
= col
;
1093 m_coloursCustomized
|= 0x08;
1095 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1100 // -----------------------------------------------------------------------
1102 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1104 m_colPropFore
= col
;
1105 m_coloursCustomized
|= 0x10;
1107 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1112 // -----------------------------------------------------------------------
1114 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1116 m_colEmptySpace
= col
;
1121 // -----------------------------------------------------------------------
1123 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1125 m_colDisPropFore
= col
;
1126 m_coloursCustomized
|= 0x100;
1130 // -----------------------------------------------------------------------
1132 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1135 m_coloursCustomized
|= 0x20;
1139 // -----------------------------------------------------------------------
1141 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1144 m_coloursCustomized
|= 0x40;
1148 // -----------------------------------------------------------------------
1150 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1153 m_coloursCustomized
|= 0x02;
1155 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1160 // -----------------------------------------------------------------------
1162 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1165 m_coloursCustomized
|= 0x04;
1167 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1172 // -----------------------------------------------------------------------
1173 // wxPropertyGrid property adding and removal
1174 // -----------------------------------------------------------------------
1176 void wxPropertyGrid::PrepareAfterItemsAdded()
1178 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1180 m_pState
->m_itemsAdded
= 0;
1182 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1185 RecalculateVirtualSize();
1188 // -----------------------------------------------------------------------
1189 // wxPropertyGrid property value setting and getting
1190 // -----------------------------------------------------------------------
1192 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1194 m_pState
->DoSetPropertyValueUnspecified(p
);
1195 DrawItemAndChildren(p
);
1197 wxPGProperty
* parent
= p
->GetParent();
1199 (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1202 parent
= parent
->GetParent();
1206 // -----------------------------------------------------------------------
1207 // wxPropertyGrid property operations
1208 // -----------------------------------------------------------------------
1210 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1212 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1216 bool changed
= false;
1218 // Is it inside collapsed section?
1219 if ( !p
->IsVisible() )
1222 wxPGProperty
* parent
= p
->GetParent();
1223 wxPGProperty
* grandparent
= parent
->GetParent();
1225 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1226 Expand( grandparent
);
1234 GetViewStart(&vx
,&vy
);
1235 vy
*=wxPG_PIXELS_PER_UNIT
;
1241 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1242 m_iFlags
|= wxPG_FL_SCROLLED
;
1245 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1247 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1248 m_iFlags
|= wxPG_FL_SCROLLED
;
1258 // -----------------------------------------------------------------------
1259 // wxPropertyGrid helper methods called by properties
1260 // -----------------------------------------------------------------------
1262 // Control font changer helper.
1263 void wxPropertyGrid::SetCurControlBoldFont()
1265 wxASSERT( m_wndEditor
);
1266 m_wndEditor
->SetFont( m_captionFont
);
1269 // -----------------------------------------------------------------------
1271 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1274 #if wxPG_SMALL_SCREEN
1275 // On small-screen devices, always show dialogs with default position and size.
1276 return wxDefaultPosition
;
1278 int splitterX
= GetSplitterPosition();
1282 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1284 ImprovedClientToScreen( &x
, &y
);
1286 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1287 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1294 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1304 new_y
= y
+ m_lineHeight
;
1306 return wxPoint(new_x
,new_y
);
1310 // -----------------------------------------------------------------------
1312 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1314 if ( src_str
.length() == 0 )
1320 bool prev_is_slash
= false;
1322 wxString::const_iterator i
= src_str
.begin();
1326 for ( ; i
!= src_str
.end(); ++i
)
1330 if ( a
!= wxS('\\') )
1332 if ( !prev_is_slash
)
1338 if ( a
== wxS('n') )
1341 dst_str
<< wxS('\n');
1343 dst_str
<< wxS('\n');
1346 else if ( a
== wxS('t') )
1347 dst_str
<< wxS('\t');
1351 prev_is_slash
= false;
1355 if ( prev_is_slash
)
1357 dst_str
<< wxS('\\');
1358 prev_is_slash
= false;
1362 prev_is_slash
= true;
1369 // -----------------------------------------------------------------------
1371 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1373 if ( src_str
.length() == 0 )
1379 wxString::const_iterator i
= src_str
.begin();
1380 wxUniChar prev_a
= wxS('\0');
1384 for ( ; i
!= src_str
.end(); ++i
)
1388 if ( a
>= wxS(' ') )
1390 // This surely is not something that requires an escape sequence.
1395 // This might need...
1396 if ( a
== wxS('\r') )
1398 // DOS style line end.
1399 // Already taken care below
1401 else if ( a
== wxS('\n') )
1402 // UNIX style line end.
1403 dst_str
<< wxS("\\n");
1404 else if ( a
== wxS('\t') )
1406 dst_str
<< wxS('\t');
1409 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1419 // -----------------------------------------------------------------------
1421 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1425 return (wxPGProperty
*) NULL
;
1428 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1431 // -----------------------------------------------------------------------
1432 // wxPropertyGrid graphics related methods
1433 // -----------------------------------------------------------------------
1435 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1439 // Update everything inside the box
1440 wxRect r
= GetUpdateRegion().GetBox();
1442 dc
.SetPen(m_colEmptySpace
);
1443 dc
.SetBrush(m_colEmptySpace
);
1444 dc
.DrawRectangle(r
);
1447 // -----------------------------------------------------------------------
1449 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1450 wxPGProperty
* property
) const
1452 // Prepare rectangle to be used
1454 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1455 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1457 #if (wxPG_USE_RENDERER_NATIVE)
1459 #elif wxPG_ICON_WIDTH
1460 // Drawing expand/collapse button manually
1461 dc
.SetPen(m_colPropFore
);
1462 if ( property
->IsCategory() )
1463 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1465 dc
.SetBrush(m_colPropBack
);
1467 dc
.DrawRectangle( r
);
1468 int _y
= r
.y
+(m_iconWidth
/2);
1469 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1474 if ( property
->IsExpanded() )
1476 // wxRenderer functions are non-mutating in nature, so it
1477 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1478 // Hopefully this does not cause problems.
1479 #if (wxPG_USE_RENDERER_NATIVE)
1480 wxRendererNative::Get().DrawTreeItemButton(
1486 #elif wxPG_ICON_WIDTH
1495 #if (wxPG_USE_RENDERER_NATIVE)
1496 wxRendererNative::Get().DrawTreeItemButton(
1502 #elif wxPG_ICON_WIDTH
1503 int _x
= r
.x
+(m_iconWidth
/2);
1504 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1510 #if (wxPG_USE_RENDERER_NATIVE)
1512 #elif wxPG_ICON_WIDTH
1515 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1519 // -----------------------------------------------------------------------
1522 // This is the one called by OnPaint event handler and others.
1523 // topy and bottomy are already unscrolled (ie. physical)
1525 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1527 unsigned int bottomy
,
1528 const wxRect
* clipRect
)
1530 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1532 m_pState
->EnsureVirtualHeight();
1534 wxRect tempClipRect
;
1537 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1538 clipRect
= &tempClipRect
;
1541 // items added check
1542 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1544 int paintFinishY
= 0;
1546 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1549 bool isBuffered
= false;
1551 #if wxPG_DOUBLE_BUFFER
1552 wxMemoryDC
* bufferDC
= NULL
;
1554 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1556 if ( !m_doubleBuffer
)
1558 paintFinishY
= clipRect
->y
;
1563 bufferDC
= new wxMemoryDC();
1565 // If nothing was changed, then just copy from double-buffer
1566 bufferDC
->SelectObject( *m_doubleBuffer
);
1576 dc
.SetClippingRegion( *clipRect
);
1577 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1580 #if wxPG_DOUBLE_BUFFER
1583 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1584 bufferDC
, 0, 0, wxCOPY
);
1585 dc
.DestroyClippingRegion(); // Is this really necessary?
1591 // Clear area beyond bottomY?
1592 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1594 dc
.SetPen(m_colEmptySpace
);
1595 dc
.SetBrush(m_colEmptySpace
);
1596 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1600 // -----------------------------------------------------------------------
1602 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1603 const wxPGProperty
* firstItem
,
1604 const wxPGProperty
* lastItem
,
1605 const wxRect
* clipRect
,
1606 bool isBuffered
) const
1608 // TODO: This should somehow be eliminated.
1609 wxRect tempClipRect
;
1612 wxASSERT(firstItem
);
1614 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1615 clipRect
= &tempClipRect
;
1619 firstItem
= DoGetItemAtY(clipRect
->y
);
1623 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1625 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1628 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1631 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1632 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1634 int lh
= m_lineHeight
;
1637 int lastItemBottomY
;
1639 firstItemTopY
= clipRect
->y
;
1640 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1642 // Align y coordinates to item boundaries
1643 firstItemTopY
-= firstItemTopY
% lh
;
1644 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1645 lastItemBottomY
-= 1;
1647 // Entire range outside scrolled, visible area?
1648 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1651 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1655 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1656 firstItem->GetLabel().c_str(),
1657 lastItem->GetLabel().c_str(),
1658 (int)(lastItemBottomY - firstItemTopY),
1660 (unsigned long)clipRect );
1665 long windowStyle
= m_windowStyle
;
1671 // With wxPG_DOUBLE_BUFFER, do double buffering
1672 // - buffer's y = 0, so align cliprect and coordinates to that
1674 #if wxPG_DOUBLE_BUFFER
1680 xRelMod
= clipRect
->x
;
1681 yRelMod
= clipRect
->y
;
1684 // clipRect conversion
1689 firstItemTopY
-= yRelMod
;
1690 lastItemBottomY
-= yRelMod
;
1693 wxUnusedVar(isBuffered
);
1696 int x
= m_marginWidth
- xRelMod
;
1698 const wxFont
& normalfont
= m_font
;
1700 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1702 bool isEnabled
= IsEnabled();
1705 // Prepare some pens and brushes that are often changed to.
1708 wxBrush
marginBrush(m_colMargin
);
1709 wxPen
marginPen(m_colMargin
);
1710 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1711 wxPen
linepen(m_colLine
,1,wxSOLID
);
1713 // pen that has same colour as text
1714 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1717 // Clear margin with background colour
1719 dc
.SetBrush( marginBrush
);
1720 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1722 dc
.SetPen( *wxTRANSPARENT_PEN
);
1723 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1726 const wxPGProperty
* selected
= m_selected
;
1727 const wxPropertyGridPageState
* state
= m_pState
;
1729 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1730 bool wasSelectedPainted
= false;
1733 // TODO: Only render columns that are within clipping region.
1735 dc
.SetFont(normalfont
);
1737 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1738 int endScanBottomY
= lastItemBottomY
+ lh
;
1739 int y
= firstItemTopY
;
1742 // Pregenerate list of visible properties.
1743 wxArrayPGProperty visPropArray
;
1744 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1746 for ( ; !it
.AtEnd(); it
.Next() )
1748 const wxPGProperty
* p
= *it
;
1750 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1752 visPropArray
.push_back((wxPGProperty
*)p
);
1754 if ( y
> endScanBottomY
)
1761 visPropArray
.push_back(NULL
);
1763 wxPGProperty
* nextP
= visPropArray
[0];
1765 int gridWidth
= state
->m_width
;
1768 for ( unsigned int arrInd
=1;
1769 nextP
&& y
<= lastItemBottomY
;
1772 wxPGProperty
* p
= nextP
;
1773 nextP
= visPropArray
[arrInd
];
1775 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1776 int textMarginHere
= x
;
1777 int renderFlags
= 0;
1779 int greyDepth
= m_marginWidth
;
1780 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1781 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1783 int greyDepthX
= greyDepth
- xRelMod
;
1785 // Use basic depth if in non-categoric mode and parent is base array.
1786 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1788 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1791 // Paint margin area
1792 dc
.SetBrush(marginBrush
);
1793 dc
.SetPen(marginPen
);
1794 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1796 dc
.SetPen( linepen
);
1801 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1807 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1809 sx
+= state
->m_colWidths
[si
];
1810 dc
.DrawLine( sx
, y
, sx
, y2
);
1813 // Horizontal Line, below
1814 // (not if both this and next is category caption)
1815 if ( p
->IsCategory() &&
1816 nextP
&& nextP
->IsCategory() )
1817 dc
.SetPen(m_colCapBack
);
1819 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1822 // Need to override row colours?
1826 if ( p
!= selected
)
1828 // Disabled may get different colour.
1829 if ( !p
->IsEnabled() )
1831 renderFlags
|= wxPGCellRenderer::Disabled
|
1832 wxPGCellRenderer::DontUseCellFgCol
;
1833 rowFgCol
= m_colDisPropFore
;
1838 renderFlags
|= wxPGCellRenderer::Selected
;
1840 if ( !p
->IsCategory() )
1842 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1843 wxPGCellRenderer::DontUseCellBgCol
;
1845 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1846 wasSelectedPainted
= true;
1849 // Selected gets different colour.
1850 if ( reallyFocused
)
1852 rowFgCol
= m_colSelFore
;
1853 rowBgCol
= m_colSelBack
;
1855 else if ( isEnabled
)
1857 rowFgCol
= m_colPropFore
;
1858 rowBgCol
= m_colMargin
;
1862 rowFgCol
= m_colDisPropFore
;
1863 rowBgCol
= m_colSelBack
;
1870 if ( rowBgCol
.IsOk() )
1871 rowBgBrush
= wxBrush(rowBgCol
);
1873 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1874 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1877 // Fill additional margin area with background colour of first cell
1878 if ( greyDepthX
< textMarginHere
)
1880 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1882 wxPGCell
& cell
= p
->GetCell(0);
1883 rowBgCol
= cell
.GetBgCol();
1884 rowBgBrush
= wxBrush(rowBgCol
);
1886 dc
.SetBrush(rowBgBrush
);
1887 dc
.SetPen(rowBgCol
);
1888 dc
.DrawRectangle(greyDepthX
+1, y
,
1889 textMarginHere
-greyDepthX
, lh
-1);
1892 bool fontChanged
= false;
1894 // Expander button rectangle
1895 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1900 if ( p
->IsCategory() )
1902 // Captions have their cell areas merged as one
1903 dc
.SetFont(m_captionFont
);
1905 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1907 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1909 dc
.SetBrush(rowBgBrush
);
1910 dc
.SetPen(rowBgCol
);
1913 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1915 dc
.SetTextForeground(rowFgCol
);
1918 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1919 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1922 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1923 DrawExpanderButton( dc
, butRect
, p
);
1927 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1929 dc
.SetFont(m_captionFont
);
1935 int nextCellWidth
= state
->m_colWidths
[0];
1936 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1937 int textXAdd
= textMarginHere
- greyDepthX
;
1939 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1941 cellRect
.width
= nextCellWidth
- 1;
1943 bool ctrlCell
= false;
1944 int cellRenderFlags
= renderFlags
;
1947 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1948 DrawExpanderButton( dc
, butRect
, p
);
1951 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1953 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1954 dc
.SetBrush(editorBgCol
);
1955 dc
.SetPen(editorBgCol
);
1956 dc
.SetTextForeground(m_colPropFore
);
1957 dc
.DrawRectangle(cellRect
);
1959 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1964 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1966 dc
.SetBrush(rowBgBrush
);
1967 dc
.SetPen(rowBgCol
);
1970 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1972 dc
.SetTextForeground(rowFgCol
);
1976 dc
.SetClippingRegion(cellRect
);
1978 cellRect
.x
+= textXAdd
;
1979 cellRect
.width
-= textXAdd
;
1984 wxPGCellRenderer
* renderer
;
1985 int cmnVal
= p
->GetCommonValue();
1986 if ( cmnVal
== -1 || ci
!= 1 )
1988 renderer
= p
->GetCellRenderer(ci
);
1989 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1994 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1995 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2000 cellX
+= state
->m_colWidths
[ci
];
2001 if ( ci
< (state
->m_colWidths
.size()-1) )
2002 nextCellWidth
= state
->m_colWidths
[ci
+1];
2004 dc
.DestroyClippingRegion(); // Is this really necessary?
2010 dc
.SetFont(normalfont
);
2015 // Refresh editor controls (seems not needed on msw)
2016 // NOTE: This code is mandatory for GTK!
2017 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2018 if ( wasSelectedPainted
)
2021 m_wndEditor
->Refresh();
2023 m_wndEditor2
->Refresh();
2030 // -----------------------------------------------------------------------
2032 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2036 if ( m_width
< 10 || m_height
< 10 ||
2037 !m_pState
->m_properties
->GetChildCount() ||
2038 p1
== (wxPGProperty
*) NULL
)
2039 return wxRect(0,0,0,0);
2044 // Return rect which encloses the given property range
2046 int visTop
= p1
->GetY();
2049 visBottom
= p2
->GetY() + m_lineHeight
;
2051 visBottom
= m_height
+ visTop
;
2053 // If seleced property is inside the range, we'll extend the range to include
2055 wxPGProperty
* selected
= m_selected
;
2058 int selectedY
= selected
->GetY();
2059 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2061 wxWindow
* editor
= GetEditorControl();
2064 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2065 if ( visBottom2
> visBottom
)
2066 visBottom
= visBottom2
;
2071 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2074 // -----------------------------------------------------------------------
2076 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2081 if ( m_pState
->m_itemsAdded
)
2082 PrepareAfterItemsAdded();
2084 wxRect r
= GetPropertyRect(p1
, p2
);
2087 m_canvas
->RefreshRect(r
);
2091 // -----------------------------------------------------------------------
2093 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2095 if ( p
== m_selected
)
2096 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2098 DrawItemAndChildren(p
);
2101 // -----------------------------------------------------------------------
2103 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2108 // Draw item, children, and parent too, if it is not category
2109 wxPGProperty
* parent
= p
->GetParent();
2112 !parent
->IsCategory() &&
2113 parent
->GetParent() )
2116 parent
= parent
->GetParent();
2119 DrawItemAndChildren(p
);
2122 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2124 wxCHECK_RET( p
, wxT("invalid property id") );
2126 // Do not draw if in non-visible page
2127 if ( p
->GetParentState() != m_pState
)
2130 // do not draw a single item if multiple pending
2131 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2134 // Update child control.
2135 if ( m_selected
&& m_selected
->GetParent() == p
)
2138 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2140 DrawItems(p
, lastDrawn
);
2143 // -----------------------------------------------------------------------
2145 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2146 const wxRect
*rect
)
2148 PrepareAfterItemsAdded();
2150 wxWindow::Refresh(false);
2152 // TODO: Coordinate translation
2153 m_canvas
->Refresh(false, rect
);
2155 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2156 // I think this really helps only GTK+1.2
2157 if ( m_wndEditor
) m_wndEditor
->Refresh();
2158 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2162 // -----------------------------------------------------------------------
2163 // wxPropertyGrid global operations
2164 // -----------------------------------------------------------------------
2166 void wxPropertyGrid::Clear()
2168 ClearSelection(false);
2170 m_pState
->DoClear();
2176 RecalculateVirtualSize();
2178 // Need to clear some area at the end
2180 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2183 // -----------------------------------------------------------------------
2185 bool wxPropertyGrid::EnableCategories( bool enable
)
2187 ClearSelection(false);
2192 // Enable categories
2195 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2200 // Disable categories
2202 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2205 if ( !m_pState
->EnableCategories(enable
) )
2210 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2212 m_pState
->m_itemsAdded
= 1; // force
2213 PrepareAfterItemsAdded();
2217 m_pState
->m_itemsAdded
= 1;
2219 // No need for RecalculateVirtualSize() here - it is already called in
2220 // wxPropertyGridPageState method above.
2227 // -----------------------------------------------------------------------
2229 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2231 wxASSERT( pNewState
);
2232 wxASSERT( pNewState
->GetGrid() );
2234 if ( pNewState
== m_pState
)
2237 wxPGProperty
* oldSelection
= m_selected
;
2239 ClearSelection(false);
2241 m_pState
->m_selected
= oldSelection
;
2243 bool orig_mode
= m_pState
->IsInNonCatMode();
2244 bool new_state_mode
= pNewState
->IsInNonCatMode();
2246 m_pState
= pNewState
;
2249 int pgWidth
= GetClientSize().x
;
2250 if ( HasVirtualWidth() )
2252 int minWidth
= pgWidth
;
2253 if ( pNewState
->m_width
< minWidth
)
2255 pNewState
->m_width
= minWidth
;
2256 pNewState
->CheckColumnWidths();
2262 // Just in case, fully re-center splitter
2263 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2264 pNewState
->m_fSplitterX
= -1.0;
2266 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2269 m_propHover
= (wxPGProperty
*) NULL
;
2271 // If necessary, convert state to correct mode.
2272 if ( orig_mode
!= new_state_mode
)
2274 // This should refresh as well.
2275 EnableCategories( orig_mode
?false:true );
2277 else if ( !m_frozen
)
2279 // Refresh, if not frozen.
2280 if ( m_pState
->m_itemsAdded
)
2281 PrepareAfterItemsAdded();
2284 if ( m_pState
->m_selected
)
2285 DoSelectProperty( m_pState
->m_selected
);
2287 RecalculateVirtualSize(0);
2291 m_pState
->m_itemsAdded
= 1;
2294 // -----------------------------------------------------------------------
2296 // Call to SetSplitterPosition will always disable splitter auto-centering
2297 // if parent window is shown.
2298 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2300 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2303 wxPropertyGridPageState
* state
= m_pState
;
2305 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2310 CorrectEditorWidgetSizeX();
2316 // -----------------------------------------------------------------------
2318 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2320 SetSplitterPosition( m_width
/2, true );
2321 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2322 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2325 // -----------------------------------------------------------------------
2326 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2327 // -----------------------------------------------------------------------
2329 // Returns nearest paint visible property (such that will be painted unless
2330 // window is scrolled or resized). If given property is paint visible, then
2331 // it itself will be returned
2332 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2334 int vx
,vy1
;// Top left corner of client
2335 GetViewStart(&vx
,&vy1
);
2336 vy1
*= wxPG_PIXELS_PER_UNIT
;
2338 int vy2
= vy1
+ m_height
;
2339 int propY
= p
->GetY2(m_lineHeight
);
2341 if ( (propY
+ m_lineHeight
) < vy1
)
2344 return DoGetItemAtY( vy1
);
2346 else if ( propY
> vy2
)
2349 return DoGetItemAtY( vy2
);
2352 // Itself paint visible
2357 // -----------------------------------------------------------------------
2358 // Methods related to change in value, value modification and sending events
2359 // -----------------------------------------------------------------------
2361 // commits any changes in editor of selected property
2362 // return true if validation did not fail
2363 // flags are same as with DoSelectProperty
2364 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2366 // Committing already?
2367 if ( m_inCommitChangesFromEditor
)
2370 // Don't do this if already processing editor event. It might
2371 // induce recursive dialogs and crap like that.
2372 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2374 if ( m_inDoPropertyChanged
)
2381 IsEditorsValueModified() &&
2382 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2385 m_inCommitChangesFromEditor
= 1;
2387 wxVariant
variant(m_selected
->GetValueRef());
2388 bool valueIsPending
= false;
2390 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2391 // due to another window getting focus
2392 wxWindow
* oldFocus
= m_curFocused
;
2394 bool validationFailure
= false;
2395 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2397 m_chgInfo_changedProperty
= NULL
;
2399 // If truly modified, schedule value as pending.
2400 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2402 if ( DoEditorValidate() &&
2403 PerformValidation(m_selected
, variant
) )
2405 valueIsPending
= true;
2409 validationFailure
= true;
2414 EditorsValueWasNotModified();
2419 m_inCommitChangesFromEditor
= 0;
2421 if ( validationFailure
&& !forceSuccess
)
2425 oldFocus
->SetFocus();
2426 m_curFocused
= oldFocus
;
2429 res
= OnValidationFailure(m_selected
, variant
);
2431 // Now prevent further validation failure messages
2434 EditorsValueWasNotModified();
2435 OnValidationFailureReset(m_selected
);
2438 else if ( valueIsPending
)
2440 DoPropertyChanged( m_selected
, flags
);
2441 EditorsValueWasNotModified();
2450 // -----------------------------------------------------------------------
2452 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2456 // Runs all validation functionality.
2457 // Returns true if value passes all tests.
2460 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2462 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2464 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2469 // Adapt list to child values, if necessary
2470 wxVariant listValue
= pendingValue
;
2471 wxVariant
* pPendingValue
= &pendingValue
;
2472 wxVariant
* pList
= NULL
;
2474 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2475 // string value, then we need treat as it was changed instead
2476 // (or, in addition, as is the case with composite string parent).
2477 // This includes creating list variant for child values.
2479 wxPGProperty
* pwc
= p
->GetParent();
2480 wxPGProperty
* changedProperty
= p
;
2481 wxPGProperty
* baseChangedProperty
= changedProperty
;
2482 wxVariant bcpPendingList
;
2484 listValue
= pendingValue
;
2485 listValue
.SetName(p
->GetBaseName());
2488 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2490 wxVariantList tempList
;
2491 wxVariant
lv(tempList
, pwc
->GetBaseName());
2492 lv
.Append(listValue
);
2494 pPendingValue
= &listValue
;
2496 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2498 baseChangedProperty
= pwc
;
2499 bcpPendingList
= lv
;
2502 changedProperty
= pwc
;
2503 pwc
= pwc
->GetParent();
2507 wxPGProperty
* evtChangingProperty
= changedProperty
;
2509 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2511 value
= *pPendingValue
;
2515 // Convert list to child values
2516 pList
= pPendingValue
;
2517 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2520 wxVariant evtChangingValue
= value
;
2522 if ( flags
& SendEvtChanging
)
2524 // FIXME: After proper ValueToString()s added, remove
2525 // this. It is just a temporary fix, as evt_changing
2526 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2527 // (unless it is selected, and textctrl editor is open).
2528 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2530 evtChangingProperty
= baseChangedProperty
;
2531 if ( evtChangingProperty
!= p
)
2533 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2537 evtChangingValue
= pendingValue
;
2541 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2543 if ( changedProperty
== m_selected
)
2545 wxWindow
* editor
= GetEditorControl();
2546 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2547 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2551 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2556 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2557 m_chgInfo_changedProperty
= changedProperty
;
2558 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2559 m_chgInfo_pendingValue
= value
;
2562 m_chgInfo_valueList
= *pList
;
2564 m_chgInfo_valueList
.MakeNull();
2566 // If changedProperty is not property which value was edited,
2567 // then call wxPGProperty::ValidateValue() for that as well.
2568 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2570 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2574 if ( flags
& SendEvtChanging
)
2576 // SendEvent returns true if event was vetoed
2577 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2581 if ( flags
& IsStandaloneValidation
)
2583 // If called in 'generic' context, we need to reset
2584 // m_chgInfo_changedProperty and write back translated value.
2585 m_chgInfo_changedProperty
= NULL
;
2586 pendingValue
= value
;
2592 // -----------------------------------------------------------------------
2594 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2596 if ( !msg
.length() )
2600 if ( !wxPGGlobalVars
->m_offline
)
2602 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2605 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2608 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2611 pStatusBar
->SetStatusText(msg
);
2619 ::wxMessageBox(msg
, _T("Property Error"));
2622 // -----------------------------------------------------------------------
2624 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2626 int vfb
= m_validationInfo
.m_failureBehavior
;
2628 if ( vfb
& wxPG_VFB_BEEP
)
2631 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2632 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2634 unsigned int colCount
= m_pState
->GetColumnCount();
2636 // We need backup marked property's cells
2637 m_propCellsBackup
= property
->m_cells
;
2639 wxColour vfbFg
= *wxWHITE
;
2640 wxColour vfbBg
= *wxRED
;
2642 property
->EnsureCells(colCount
);
2644 for ( unsigned int i
=0; i
<colCount
; i
++ )
2646 wxPGCell
& cell
= property
->m_cells
[i
];
2647 cell
.SetFgCol(vfbFg
);
2648 cell
.SetBgCol(vfbBg
);
2651 DrawItemAndChildren(property
);
2653 if ( property
== m_selected
)
2655 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2657 wxWindow
* editor
= GetEditorControl();
2660 editor
->SetForegroundColour(vfbFg
);
2661 editor
->SetBackgroundColour(vfbBg
);
2666 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2668 wxString msg
= m_validationInfo
.m_failureMessage
;
2670 if ( !msg
.length() )
2671 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2673 DoShowPropertyError(property
, msg
);
2676 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2679 // -----------------------------------------------------------------------
2681 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2683 int vfb
= m_validationInfo
.m_failureBehavior
;
2685 if ( vfb
& wxPG_VFB_MARK_CELL
)
2688 property
->m_cells
= m_propCellsBackup
;
2690 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2692 if ( property
== m_selected
&& GetEditorControl() )
2694 // Calling this will recreate the control, thus resetting its colour
2695 RefreshProperty(property
);
2699 DrawItemAndChildren(property
);
2704 // -----------------------------------------------------------------------
2706 // flags are same as with DoSelectProperty
2707 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2709 if ( m_inDoPropertyChanged
)
2712 wxWindow
* editor
= GetEditorControl();
2714 m_pState
->m_anyModified
= 1;
2716 m_inDoPropertyChanged
= 1;
2718 // Maybe need to update control
2719 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2721 // These values were calculated in PerformValidation()
2722 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2723 wxVariant value
= m_chgInfo_pendingValue
;
2725 wxPGProperty
* topPaintedProperty
= changedProperty
;
2727 while ( !topPaintedProperty
->IsCategory() &&
2728 !topPaintedProperty
->IsRoot() )
2730 topPaintedProperty
= topPaintedProperty
->GetParent();
2733 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2735 // Set as Modified (not if dragging just began)
2736 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2738 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2739 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2742 SetCurControlBoldFont();
2748 // Propagate updates to parent(s)
2750 wxPGProperty
* prevPwc
= NULL
;
2752 while ( prevPwc
!= topPaintedProperty
)
2754 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2756 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2759 SetCurControlBoldFont();
2763 pwc
= pwc
->GetParent();
2766 // Draw the actual property
2767 DrawItemAndChildren( topPaintedProperty
);
2770 // If value was set by wxPGProperty::OnEvent, then update the editor
2772 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2778 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2779 if ( m_wndEditor
) m_wndEditor
->Refresh();
2780 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2785 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2787 // If top parent has composite string value, then send to child parents,
2788 // starting from baseChangedProperty.
2789 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2791 pwc
= m_chgInfo_baseChangedProperty
;
2793 while ( pwc
!= changedProperty
)
2795 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2796 pwc
= pwc
->GetParent();
2800 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2802 m_inDoPropertyChanged
= 0;
2807 // -----------------------------------------------------------------------
2809 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2811 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2813 m_chgInfo_changedProperty
= NULL
;
2815 if ( PerformValidation(p
, newValue
) )
2817 DoPropertyChanged(p
);
2822 OnValidationFailure(p
, newValue
);
2828 // -----------------------------------------------------------------------
2830 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2832 wxPGProperty
* prop
= GetSelectedProperty();
2835 return wxNullVariant
;
2837 wxTextCtrl
* tc
= GetEditorTextCtrl();
2838 wxVariant value
= prop
->GetValue();
2840 if ( !tc
|| !IsEditorsValueModified() )
2843 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2846 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2847 return prop
->GetValue();
2852 // -----------------------------------------------------------------------
2854 // Runs wxValidator for the selected property
2855 bool wxPropertyGrid::DoEditorValidate()
2860 // -----------------------------------------------------------------------
2862 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2864 wxPGProperty
* selected
= m_selected
;
2866 // Somehow, event is handled after property has been deselected.
2867 // Possibly, but very rare.
2871 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2874 wxVariant
pendingValue(selected
->GetValueRef());
2875 wxWindow
* wnd
= GetEditorControl();
2877 bool wasUnspecified
= selected
->IsValueUnspecified();
2878 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2880 bool valueIsPending
= false;
2882 m_chgInfo_changedProperty
= NULL
;
2884 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2887 // Filter out excess wxTextCtrl modified events
2888 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2890 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2892 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2894 wxString newTcValue
= tc
->GetValue();
2895 if ( m_prevTcValue
== newTcValue
)
2898 m_prevTcValue
= newTcValue
;
2901 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2903 bool validationFailure
= false;
2904 bool buttonWasHandled
= false;
2907 // Try common button handling
2908 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2910 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2914 buttonWasHandled
= true;
2915 // Store as res2, as previously (and still currently alternatively)
2916 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2917 // in wxPGProperty::OnEvent().
2918 adapter
->ShowDialog( this, selected
);
2923 if ( !buttonWasHandled
)
2927 // First call editor class' event handler.
2928 const wxPGEditor
* editor
= selected
->GetEditorClass();
2930 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2932 // If changes, validate them
2933 if ( DoEditorValidate() )
2935 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
2936 valueIsPending
= true;
2940 validationFailure
= true;
2945 // Then the property's custom handler (must be always called, unless
2946 // validation failed).
2947 if ( !validationFailure
)
2948 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
2951 // SetValueInEvent(), as called in one of the functions referred above
2952 // overrides editor's value.
2953 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2955 valueIsPending
= true;
2956 pendingValue
= m_changeInEventValue
;
2957 selFlags
|= wxPG_SEL_DIALOGVAL
;
2960 if ( !validationFailure
&& valueIsPending
)
2961 if ( !PerformValidation(m_selected
, pendingValue
) )
2962 validationFailure
= true;
2964 if ( validationFailure
)
2966 OnValidationFailure(selected
, pendingValue
);
2968 else if ( valueIsPending
)
2970 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2972 DoPropertyChanged(selected
, selFlags
);
2973 EditorsValueWasNotModified();
2975 // Regardless of editor type, unfocus editor on
2976 // text-editing related enter press.
2977 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2984 // No value after all
2986 // Regardless of editor type, unfocus editor on
2987 // text-editing related enter press.
2988 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2993 // Let unhandled button click events go to the parent
2994 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2996 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2997 GetEventHandler()->AddPendingEvent(evt
);
3001 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3004 // -----------------------------------------------------------------------
3005 // wxPropertyGrid editor control helper methods
3006 // -----------------------------------------------------------------------
3008 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3010 int itemy
= p
->GetY2(m_lineHeight
);
3012 int cust_img_space
= 0;
3013 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3014 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3016 // TODO: If custom image detection changes from current, change this.
3017 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3019 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3020 int imwid
= p
->OnMeasureImage().x
;
3021 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3022 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3027 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3029 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3034 // -----------------------------------------------------------------------
3036 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3038 wxSize sz
= GetImageSize(p
, item
);
3039 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3040 wxPG_CUSTOM_IMAGE_SPACINGY
,
3045 // return size of custom paint image
3046 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3048 // If called with NULL property, then return default image
3049 // size for properties that use image.
3051 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3053 wxSize cis
= p
->OnMeasureImage(item
);
3055 int choiceCount
= p
->m_choices
.GetCount();
3056 int comVals
= p
->GetDisplayedCommonValueCount();
3057 if ( item
>= choiceCount
&& comVals
> 0 )
3059 unsigned int cvi
= item
-choiceCount
;
3060 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3062 else if ( item
>= 0 && choiceCount
== 0 )
3063 return wxSize(0, 0);
3068 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3073 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3080 // -----------------------------------------------------------------------
3082 // takes scrolling into account
3083 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3086 GetViewStart(&vx
,&vy
);
3087 vy
*=wxPG_PIXELS_PER_UNIT
;
3088 vx
*=wxPG_PIXELS_PER_UNIT
;
3091 ClientToScreen( px
, py
);
3094 // -----------------------------------------------------------------------
3096 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3099 GetViewStart(&pt2
.x
,&pt2
.y
);
3100 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3101 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3105 return m_pState
->HitTest(pt2
);
3108 // -----------------------------------------------------------------------
3110 // custom set cursor
3111 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3113 if ( type
== m_curcursor
&& !override
) return;
3115 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3117 if ( type
== wxCURSOR_SIZEWE
)
3118 cursor
= m_cursorSizeWE
;
3120 m_canvas
->SetCursor( *cursor
);
3125 // -----------------------------------------------------------------------
3126 // wxPropertyGrid property selection, editor creation
3127 // -----------------------------------------------------------------------
3130 // This class forwards events from property editor controls to wxPropertyGrid.
3131 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3134 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3135 : wxEvtHandler(), m_propGrid(propGrid
)
3139 virtual ~wxPropertyGridEditorEventForwarder()
3144 bool ProcessEvent( wxEvent
& event
)
3149 m_propGrid
->HandleCustomEditorEvent(event
);
3151 return wxEvtHandler::ProcessEvent(event
);
3154 wxPropertyGrid
* m_propGrid
;
3157 // Setups event handling for child control
3158 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3160 wxWindowID id
= argWnd
->GetId();
3162 if ( argWnd
== m_wndEditor
)
3164 argWnd
->Connect(id
, wxEVT_MOTION
,
3165 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3167 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3168 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3170 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3171 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3173 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3174 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3176 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3177 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3179 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3180 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3184 wxPropertyGridEditorEventForwarder
* forwarder
;
3185 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3186 argWnd
->PushEventHandler(forwarder
);
3188 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3189 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3193 void wxPropertyGrid::FreeEditors()
3196 // Return focus back to canvas from children (this is required at least for
3197 // GTK+, which, unlike Windows, clears focus when control is destroyed
3198 // instead of moving it to closest parent).
3199 wxWindow
* focus
= wxWindow::FindFocus();
3202 wxWindow
* parent
= focus
->GetParent();
3205 if ( parent
== m_canvas
)
3210 parent
= parent
->GetParent();
3214 // Do not free editors immediately if processing events
3217 m_wndEditor2
->PopEventHandler(true);
3218 m_wndEditor2
->Hide();
3219 wxPendingDelete
.Append( m_wndEditor2
);
3220 m_wndEditor2
= (wxWindow
*) NULL
;
3225 m_wndEditor
->PopEventHandler(true);
3226 m_wndEditor
->Hide();
3227 wxPendingDelete
.Append( m_wndEditor
);
3228 m_wndEditor
= (wxWindow
*) NULL
;
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
3282 p
= (wxPGProperty
*) NULL
;
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;
3333 m_selected
= (wxPGProperty
*) NULL
;
3334 m_pState
->m_selected
= (wxPGProperty
*) 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
== (wxWindow
*) 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
= (wxStatusBar
*) 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 p
->GetEditorClass()->UpdateControl(p
, wnd
);
3642 // -----------------------------------------------------------------------
3644 // This method is not inline because it called dozens of times
3645 // (i.e. two-arg function calls create smaller code size).
3646 bool wxPropertyGrid::DoClearSelection()
3648 return DoSelectProperty((wxPGProperty
*)NULL
);
3651 // -----------------------------------------------------------------------
3652 // wxPropertyGrid expand/collapse state
3653 // -----------------------------------------------------------------------
3655 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3657 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3659 // If active editor was inside collapsed section, then disable it
3660 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3662 ClearSelection(false);
3665 // Store dont-center-splitter flag 'cause we need to temporarily set it
3666 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3667 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3669 bool res
= m_pState
->DoCollapse(pwc
);
3674 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3676 RecalculateVirtualSize();
3678 // Redraw etc. only if collapsed was visible.
3679 if (pwc
->IsVisible() &&
3681 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3683 // When item is collapsed so that scrollbar would move,
3684 // graphics mess is about (unless we redraw everything).
3689 // Clear dont-center-splitter flag if it wasn't set
3690 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3695 // -----------------------------------------------------------------------
3697 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3699 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3701 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3703 // Store dont-center-splitter flag 'cause we need to temporarily set it
3704 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3705 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3707 bool res
= m_pState
->DoExpand(pwc
);
3712 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3714 RecalculateVirtualSize();
3716 // Redraw etc. only if expanded was visible.
3717 if ( pwc
->IsVisible() && !m_frozen
&&
3718 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3722 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3725 DrawItems(pwc
, NULL
);
3730 // Clear dont-center-splitter flag if it wasn't set
3731 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3736 // -----------------------------------------------------------------------
3738 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3741 return m_pState
->DoHideProperty(p
, hide
, flags
);
3744 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3747 ClearSelection(false);
3750 m_pState
->DoHideProperty(p
, hide
, flags
);
3752 RecalculateVirtualSize();
3759 // -----------------------------------------------------------------------
3760 // wxPropertyGrid size related methods
3761 // -----------------------------------------------------------------------
3763 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3765 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3769 // If virtual height was changed, then recalculate editor control position(s)
3770 if ( m_pState
->m_vhCalcPending
)
3771 CorrectEditorWidgetPosY();
3773 m_pState
->EnsureVirtualHeight();
3776 int by1
= m_pState
->GetVirtualHeight();
3777 int by2
= m_pState
->GetActualVirtualHeight();
3780 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3781 wxFAIL_MSG(s
.c_str());
3786 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3788 int x
= m_pState
->m_width
;
3789 int y
= m_pState
->m_virtualHeight
;
3792 GetClientSize(&width
,&height
);
3794 // Now adjust virtual size.
3795 SetVirtualSize(x
, y
);
3801 // Adjust scrollbars
3802 if ( HasVirtualWidth() )
3804 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3805 xPos
= GetScrollPos( wxHORIZONTAL
);
3808 if ( forceXPos
!= -1 )
3811 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3814 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3815 int yPos
= GetScrollPos( wxVERTICAL
);
3817 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3818 xAmount
, yAmount
, xPos
, yPos
, true );
3820 // Must re-get size now
3821 GetClientSize(&width
,&height
);
3823 if ( !HasVirtualWidth() )
3825 m_pState
->SetVirtualWidth(width
);
3832 m_canvas
->SetSize( x
, y
);
3834 m_pState
->CheckColumnWidths();
3837 CorrectEditorWidgetSizeX();
3839 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3842 // -----------------------------------------------------------------------
3844 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3846 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3850 GetClientSize(&width
,&height
);
3855 #if wxPG_DOUBLE_BUFFER
3856 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3858 int dblh
= (m_lineHeight
*2);
3859 if ( !m_doubleBuffer
)
3861 // Create double buffer bitmap to draw on, if none
3862 int w
= (width
>250)?width
:250;
3863 int h
= height
+ dblh
;
3865 m_doubleBuffer
= new wxBitmap( w
, h
);
3869 int w
= m_doubleBuffer
->GetWidth();
3870 int h
= m_doubleBuffer
->GetHeight();
3872 // Double buffer must be large enough
3873 if ( w
< width
|| h
< (height
+dblh
) )
3875 if ( w
< width
) w
= width
;
3876 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3877 delete m_doubleBuffer
;
3878 m_doubleBuffer
= new wxBitmap( w
, h
);
3885 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3886 m_ncWidth
= event
.GetSize().x
;
3890 if ( m_pState
->m_itemsAdded
)
3891 PrepareAfterItemsAdded();
3893 // Without this, virtual size (atleast under wxGTK) will be skewed
3894 RecalculateVirtualSize();
3900 // -----------------------------------------------------------------------
3902 void wxPropertyGrid::SetVirtualWidth( int width
)
3906 // Disable virtual width
3907 width
= GetClientSize().x
;
3908 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3912 // Enable virtual width
3913 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3915 m_pState
->SetVirtualWidth( width
);
3918 void wxPropertyGrid::SetFocusOnCanvas()
3920 m_canvas
->SetFocusIgnoringChildren();
3921 m_editorFocused
= 0;
3924 // -----------------------------------------------------------------------
3925 // wxPropertyGrid mouse event handling
3926 // -----------------------------------------------------------------------
3928 // selFlags uses same values DoSelectProperty's flags
3929 // Returns true if event was vetoed.
3930 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3932 // Send property grid event of specific type and with specific property
3933 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3934 evt
.SetPropertyGrid(this);
3935 evt
.SetEventObject(m_eventObject
);
3939 evt
.SetCanVeto(true);
3940 evt
.SetupValidationInfo();
3941 m_validationInfo
.m_pValue
= pValue
;
3943 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3945 evtHandler
->ProcessEvent(evt
);
3947 return evt
.WasVetoed();
3950 // -----------------------------------------------------------------------
3952 // Return false if should be skipped
3953 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3957 // Need to set focus?
3958 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3963 wxPropertyGridPageState
* state
= m_pState
;
3965 int splitterHitOffset
;
3966 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3968 wxPGProperty
* p
= DoGetItemAtY(y
);
3972 int depth
= (int)p
->GetDepth() - 1;
3974 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3976 if ( x
>= marginEnds
)
3980 if ( p
->IsCategory() )
3982 // This is category.
3983 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3985 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3987 // Expand, collapse, activate etc. if click on text or left of splitter.
3990 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3995 if ( !DoSelectProperty( p
) )
3998 // On double-click, expand/collapse.
3999 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4001 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4002 else DoExpand( p
, true );
4006 else if ( splitterHit
== -1 )
4009 unsigned int selFlag
= 0;
4010 if ( columnHit
== 1 )
4012 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4013 selFlag
= wxPG_SEL_FOCUS
;
4015 if ( !DoSelectProperty( p
, selFlag
) )
4018 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4020 if ( p
->GetChildCount() && !p
->IsCategory() )
4021 // On double-click, expand/collapse.
4022 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4024 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4025 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4026 else DoExpand( p
, true );
4033 // click on splitter
4034 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4036 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4038 // Double-clicking the splitter causes auto-centering
4039 CenterSplitter( true );
4041 else if ( m_dragStatus
== 0 )
4044 // Begin draggin the splitter
4048 // Changes must be committed here or the
4049 // value won't be drawn correctly
4050 if ( !CommitChangesFromEditor() )
4053 m_wndEditor
->Show ( false );
4056 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4058 m_canvas
->CaptureMouse();
4059 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4063 m_draggedSplitter
= splitterHit
;
4064 m_dragOffset
= splitterHitOffset
;
4066 wxClientDC
dc(m_canvas
);
4068 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4069 // Fixes button disappearance bug
4071 m_wndEditor2
->Show ( false );
4074 m_startingSplitterX
= x
- splitterHitOffset
;
4082 if ( p
->GetChildCount() )
4084 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4086 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4088 int y2
= y
% m_lineHeight
;
4089 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4091 // On click on expander button, expand/collapse
4092 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4093 DoCollapse( p
, true );
4095 DoExpand( p
, true );
4104 // -----------------------------------------------------------------------
4106 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4107 wxMouseEvent
& WXUNUSED(event
) )
4111 // Select property here as well
4112 wxPGProperty
* p
= m_propHover
;
4113 if ( p
!= m_selected
)
4114 DoSelectProperty( p
);
4116 // Send right click event.
4117 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4124 // -----------------------------------------------------------------------
4126 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4127 wxMouseEvent
& WXUNUSED(event
) )
4131 // Select property here as well
4132 wxPGProperty
* p
= m_propHover
;
4134 if ( p
!= m_selected
)
4135 DoSelectProperty( p
);
4137 // Send double-click event.
4138 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4145 // -----------------------------------------------------------------------
4147 #if wxPG_SUPPORT_TOOLTIPS
4149 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4151 if ( tipString
.length() )
4153 m_canvas
->SetToolTip(tipString
);
4157 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4158 m_canvas
->SetToolTip( m_emptyString
);
4160 m_canvas
->SetToolTip( NULL
);
4165 #endif // #if wxPG_SUPPORT_TOOLTIPS
4167 // -----------------------------------------------------------------------
4169 // Return false if should be skipped
4170 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4172 // Safety check (needed because mouse capturing may
4173 // otherwise freeze the control)
4174 if ( m_dragStatus
> 0 && !event
.Dragging() )
4176 HandleMouseUp(x
,y
,event
);
4179 wxPropertyGridPageState
* state
= m_pState
;
4181 int splitterHitOffset
;
4182 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4183 int splitterX
= x
- splitterHitOffset
;
4185 if ( m_dragStatus
> 0 )
4187 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4188 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4191 int newSplitterX
= x
- m_dragOffset
;
4192 int splitterX
= x
- splitterHitOffset
;
4194 // Splitter redraw required?
4195 if ( newSplitterX
!= splitterX
)
4198 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4199 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4200 state
->m_fSplitterX
= (float) newSplitterX
;
4203 CorrectEditorWidgetSizeX();
4217 int ih
= m_lineHeight
;
4220 #if wxPG_SUPPORT_TOOLTIPS
4221 wxPGProperty
* prevHover
= m_propHover
;
4222 unsigned char prevSide
= m_mouseSide
;
4224 int curPropHoverY
= y
- (y
% ih
);
4226 // On which item it hovers
4229 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4232 // Mouse moves on another property
4234 m_propHover
= DoGetItemAtY(y
);
4235 m_propHoverY
= curPropHoverY
;
4238 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4241 #if wxPG_SUPPORT_TOOLTIPS
4242 // Store which side we are on
4244 if ( columnHit
== 1 )
4246 else if ( columnHit
== 0 )
4250 // If tooltips are enabled, show label or value as a tip
4251 // in case it doesn't otherwise show in full length.
4253 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4255 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4257 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4259 if ( m_propHover
&& !m_propHover
->IsCategory() )
4262 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4264 // Show help string as a tooltip
4265 wxString tipString
= m_propHover
->GetHelpString();
4267 SetToolTip(tipString
);
4271 // Show cropped value string as a tooltip
4275 if ( m_mouseSide
== 1 )
4277 tipString
= m_propHover
->m_label
;
4278 space
= splitterX
-m_marginWidth
-3;
4280 else if ( m_mouseSide
== 2 )
4282 tipString
= m_propHover
->GetDisplayedString();
4284 space
= m_width
- splitterX
;
4285 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4286 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4292 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4295 SetToolTip( tipString
);
4302 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4303 m_canvas
->SetToolTip( m_emptyString
);
4305 m_canvas
->SetToolTip( NULL
);
4316 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4317 m_canvas
->SetToolTip( m_emptyString
);
4319 m_canvas
->SetToolTip( NULL
);
4327 if ( splitterHit
== -1 ||
4329 HasFlag(wxPG_STATIC_SPLITTER
) )
4331 // hovering on something else
4332 if ( m_curcursor
!= wxCURSOR_ARROW
)
4333 CustomSetCursor( wxCURSOR_ARROW
);
4337 // Do not allow splitter cursor on caption items.
4338 // (also not if we were dragging and its started
4339 // outside the splitter region)
4341 if ( !m_propHover
->IsCategory() &&
4345 // hovering on splitter
4347 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4348 // reliably detected.
4349 //if ( m_curcursor != wxCURSOR_SIZEWE )
4350 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4356 // hovering on something else
4357 if ( m_curcursor
!= wxCURSOR_ARROW
)
4358 CustomSetCursor( wxCURSOR_ARROW
);
4365 // -----------------------------------------------------------------------
4367 // Also handles Leaving event
4368 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4369 wxMouseEvent
&WXUNUSED(event
) )
4371 wxPropertyGridPageState
* state
= m_pState
;
4375 int splitterHitOffset
;
4376 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4378 // No event type check - basicly calling this method should
4379 // just stop dragging.
4380 // Left up after dragged?
4381 if ( m_dragStatus
>= 1 )
4384 // End Splitter Dragging
4386 // DO NOT ENABLE FOLLOWING LINE!
4387 // (it is only here as a reminder to not to do it)
4390 // Disable splitter auto-centering
4391 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4393 // This is necessary to return cursor
4394 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4396 m_canvas
->ReleaseMouse();
4397 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4400 // Set back the default cursor, if necessary
4401 if ( splitterHit
== -1 ||
4404 CustomSetCursor( wxCURSOR_ARROW
);
4409 // Control background needs to be cleared
4410 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4411 DrawItem( m_selected
);
4415 m_wndEditor
->Show ( true );
4418 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4419 // Fixes button disappearance bug
4421 m_wndEditor2
->Show ( true );
4424 // This clears the focus.
4425 m_editorFocused
= 0;
4431 // -----------------------------------------------------------------------
4433 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4435 int splitterX
= GetSplitterPosition();
4438 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4442 wxWindow
* wnd
= GetEditorControl();
4444 // Hide popup on clicks
4445 if ( event
.GetEventType() != wxEVT_MOTION
)
4446 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4448 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4454 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4456 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4457 ux
>= (r
.x
+r
.width
) ||
4459 event
.m_y
>= (r
.y
+r
.height
)
4469 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4474 // -----------------------------------------------------------------------
4476 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4479 if ( OnMouseCommon( event
, &x
, &y
) )
4481 HandleMouseClick(x
,y
,event
);
4486 // -----------------------------------------------------------------------
4488 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4491 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4492 HandleMouseRightClick(x
,y
,event
);
4496 // -----------------------------------------------------------------------
4498 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4500 // Always run standard mouse-down handler as well
4501 OnMouseClick(event
);
4504 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4505 HandleMouseDoubleClick(x
,y
,event
);
4509 // -----------------------------------------------------------------------
4511 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4514 if ( OnMouseCommon( event
, &x
, &y
) )
4516 HandleMouseMove(x
,y
,event
);
4521 // -----------------------------------------------------------------------
4523 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4525 // Called when mouse moves in the empty space below the properties.
4526 CustomSetCursor( wxCURSOR_ARROW
);
4529 // -----------------------------------------------------------------------
4531 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4534 if ( OnMouseCommon( event
, &x
, &y
) )
4536 HandleMouseUp(x
,y
,event
);
4541 // -----------------------------------------------------------------------
4543 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4545 // This may get called from child control as well, so event's
4546 // mouse position cannot be relied on.
4548 if ( event
.Entering() )
4550 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4552 // TODO: Fix this (detect parent and only do
4553 // cursor trick if it is a manager).
4554 wxASSERT( GetParent() );
4555 GetParent()->SetCursor(wxNullCursor
);
4557 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4560 GetParent()->SetCursor(wxNullCursor
);
4562 else if ( event
.Leaving() )
4564 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4565 m_canvas
->SetCursor( wxNullCursor
);
4567 // Get real cursor position
4568 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4570 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4573 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4575 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4579 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4587 // -----------------------------------------------------------------------
4589 // Common code used by various OnMouseXXXChild methods.
4590 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4592 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4593 wxASSERT( topCtrlWnd
);
4595 event
.GetPosition(&x
,&y
);
4597 int splitterX
= GetSplitterPosition();
4599 wxRect r
= topCtrlWnd
->GetRect();
4600 if ( !m_dragStatus
&&
4601 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4602 y
>= 0 && y
< r
.height \
4605 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4610 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4617 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4620 if ( OnMouseChildCommon(event
,&x
,&y
) )
4622 bool res
= HandleMouseClick(x
,y
,event
);
4623 if ( !res
) event
.Skip();
4627 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4630 wxASSERT( m_wndEditor
);
4631 // These coords may not be exact (about +-2),
4632 // but that should not matter (right click is about item, not position).
4633 wxPoint pt
= m_wndEditor
->GetPosition();
4634 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4635 wxASSERT( m_selected
);
4636 m_propHover
= m_selected
;
4637 bool res
= HandleMouseRightClick(x
,y
,event
);
4638 if ( !res
) event
.Skip();
4641 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4644 if ( OnMouseChildCommon(event
,&x
,&y
) )
4646 bool res
= HandleMouseMove(x
,y
,event
);
4647 if ( !res
) event
.Skip();
4651 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4654 if ( OnMouseChildCommon(event
,&x
,&y
) )
4656 bool res
= HandleMouseUp(x
,y
,event
);
4657 if ( !res
) event
.Skip();
4661 // -----------------------------------------------------------------------
4662 // wxPropertyGrid keyboard event handling
4663 // -----------------------------------------------------------------------
4665 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4667 // Translates wxKeyEvent to wxPG_ACTION_XXX
4669 int keycode
= event
.GetKeyCode();
4670 int modifiers
= event
.GetModifiers();
4672 wxASSERT( !(modifiers
&~(0xFFFF)) );
4674 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4676 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4678 if ( it
== m_actionTriggers
.end() )
4683 int second
= (it
->second
>>16) & 0xFFFF;
4687 return (it
->second
& 0xFFFF);
4690 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4692 wxASSERT( !(modifiers
&~(0xFFFF)) );
4694 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4696 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4698 if ( it
!= m_actionTriggers
.end() )
4700 // This key combination is already used
4702 // Can add secondary?
4703 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4704 wxT("You can only add up to two separate actions per key combination.") );
4706 action
= it
->second
| (action
<<16);
4709 m_actionTriggers
[hashMapKey
] = action
;
4712 void wxPropertyGrid::ClearActionTriggers( int action
)
4714 wxPGHashMapI2I::iterator it
;
4716 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4718 if ( it
->second
== action
)
4720 m_actionTriggers
.erase(it
);
4725 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4728 // Handles key event when editor control is not focused.
4731 wxCHECK2(!m_frozen
, return);
4733 // Travelsal between items, collapsing/expanding, etc.
4734 int keycode
= event
.GetKeyCode();
4735 bool editorFocused
= IsEditorFocused();
4737 if ( keycode
== WXK_TAB
)
4739 wxWindow
* mainControl
;
4741 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4742 mainControl
= GetParent();
4746 if ( !event
.ShiftDown() )
4748 if ( !editorFocused
&& m_wndEditor
)
4750 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4754 // Tab traversal workaround for platforms on which
4755 // wxWindow::Navigate() may navigate into first child
4756 // instead of next sibling. Does not work perfectly
4757 // in every scenario (for instance, when property grid
4758 // is either first or last control).
4759 #if defined(__WXGTK__)
4760 wxWindow
* sibling
= mainControl
->GetNextSibling();
4762 sibling
->SetFocusFromKbd();
4764 Navigate(wxNavigationKeyEvent::IsForward
);
4770 if ( editorFocused
)
4776 #if defined(__WXGTK__)
4777 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4779 sibling
->SetFocusFromKbd();
4781 Navigate(wxNavigationKeyEvent::IsBackward
);
4789 // Ignore Alt and Control when they are down alone
4790 if ( keycode
== WXK_ALT
||
4791 keycode
== WXK_CONTROL
)
4798 int action
= KeyEventToActions(event
, &secondAction
);
4800 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4803 // Esc cancels any changes
4804 if ( IsEditorsValueModified() )
4806 EditorsValueWasNotModified();
4808 // Update the control as well
4809 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4811 m_selected
->GetDisplayedString() );
4814 OnValidationFailureReset(m_selected
);
4820 // Except for TAB and ESC, handle child control events in child control
4827 bool wasHandled
= false;
4832 if ( ButtonTriggerKeyTest(action
, event
) )
4835 wxPGProperty
* p
= m_selected
;
4837 // Travel and expand/collapse
4840 if ( p
->GetChildCount() &&
4841 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4844 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4846 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4849 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4851 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4858 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4862 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4868 if ( selectDir
>= -1 )
4870 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4872 DoSelectProperty(p
);
4878 // If nothing was selected, select the first item now
4879 // (or navigate out of tab).
4880 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4882 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4883 if ( p
) DoSelectProperty(p
);
4892 // -----------------------------------------------------------------------
4894 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4896 HandleKeyEvent(event
, false);
4899 // -----------------------------------------------------------------------
4901 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4906 action
= KeyEventToActions(event
, &secondAction
);
4909 // Does the keycode trigger button?
4910 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4913 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4914 GetEventHandler()->AddPendingEvent(evt
);
4921 // -----------------------------------------------------------------------
4923 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4925 HandleKeyEvent(event
, true);
4928 // -----------------------------------------------------------------------
4929 // wxPropertyGrid miscellaneous event handling
4930 // -----------------------------------------------------------------------
4932 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4935 // Check if the focus is in this control or one of its children
4936 wxWindow
* newFocused
= wxWindow::FindFocus();
4938 if ( newFocused
!= m_curFocused
)
4939 HandleFocusChange( newFocused
);
4942 bool wxPropertyGrid::IsEditorFocused() const
4944 wxWindow
* focus
= wxWindow::FindFocus();
4946 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4947 focus
== GetEditorControl() )
4953 // Called by focus event handlers. newFocused is the window that becomes focused.
4954 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4956 unsigned int oldFlags
= m_iFlags
;
4958 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4960 wxWindow
* parent
= newFocused
;
4962 // This must be one of nextFocus' parents.
4965 // Use m_eventObject, which is either wxPropertyGrid or
4966 // wxPropertyGridManager, as appropriate.
4967 if ( parent
== m_eventObject
)
4969 m_iFlags
|= wxPG_FL_FOCUSED
;
4972 parent
= parent
->GetParent();
4975 m_curFocused
= newFocused
;
4977 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4978 (oldFlags
& wxPG_FL_FOCUSED
) )
4980 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4982 // Need to store changed value
4983 CommitChangesFromEditor();
4989 // Preliminary code for tab-order respecting
4990 // tab-traversal (but should be moved to
4993 wxWindow* prevFocus = event.GetWindow();
4994 wxWindow* useThis = this;
4995 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4996 useThis = GetParent();
4999 prevFocus->GetParent() == useThis->GetParent() )
5001 wxList& children = useThis->GetParent()->GetChildren();
5003 wxNode* node = children.Find(prevFocus);
5005 if ( node->GetNext() &&
5006 useThis == node->GetNext()->GetData() )
5007 DoSelectProperty(GetFirst());
5008 else if ( node->GetPrevious () &&
5009 useThis == node->GetPrevious()->GetData() )
5010 DoSelectProperty(GetLastProperty());
5017 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5018 DrawItem( m_selected
);
5022 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5024 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5025 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5026 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5027 //else if ( event.GetWindow() )
5029 HandleFocusChange(event
.GetWindow());
5034 // -----------------------------------------------------------------------
5036 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5038 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5041 // event.Skip() being commented out is aworkaround for bug reported
5042 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5046 // -----------------------------------------------------------------------
5048 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5050 m_iFlags
|= wxPG_FL_SCROLLED
;
5055 // -----------------------------------------------------------------------
5057 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5059 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5061 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5065 // -----------------------------------------------------------------------
5066 // Property editor related functions
5067 // -----------------------------------------------------------------------
5069 // noDefCheck = true prevents infinite recursion.
5070 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5073 wxASSERT( editorClass
);
5075 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5076 RegisterDefaultEditors();
5078 wxString name
= editorClass
->GetName();
5080 // Existing editor under this name?
5081 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5083 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5085 // If this name was already used, try class name.
5086 name
= editorClass
->GetClassInfo()->GetClassName();
5087 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5090 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5091 (wxPGEditor
*) vt_it
->second
,
5092 "Editor with given name was already registered" );
5094 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5099 // Use this in RegisterDefaultEditors.
5100 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5101 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5103 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5104 new wxPG##EDITOR##Editor, true ); \
5107 // Registers all default editor classes
5108 void wxPropertyGrid::RegisterDefaultEditors()
5110 wxPGRegisterDefaultEditorClass( TextCtrl
);
5111 wxPGRegisterDefaultEditorClass( Choice
);
5112 wxPGRegisterDefaultEditorClass( ComboBox
);
5113 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5114 #if wxPG_INCLUDE_CHECKBOX
5115 wxPGRegisterDefaultEditorClass( CheckBox
);
5117 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5119 // Register SpinCtrl etc. editors before use
5120 RegisterAdditionalEditors();
5123 // -----------------------------------------------------------------------
5124 // wxPGStringTokenizer
5125 // Needed to handle C-style string lists (e.g. "str1" "str2")
5126 // -----------------------------------------------------------------------
5128 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5129 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5133 wxPGStringTokenizer::~wxPGStringTokenizer()
5137 bool wxPGStringTokenizer::HasMoreTokens()
5139 const wxString
& str
= *m_str
;
5141 wxString::const_iterator i
= m_curPos
;
5143 wxUniChar delim
= m_delimeter
;
5145 wxUniChar prev_a
= wxT('\0');
5147 bool inToken
= false;
5149 while ( i
!= str
.end() )
5158 m_readyToken
.clear();
5163 if ( prev_a
!= wxT('\\') )
5167 if ( a
!= wxT('\\') )
5187 m_curPos
= str
.end();
5195 wxString
wxPGStringTokenizer::GetNextToken()
5197 return m_readyToken
;
5200 // -----------------------------------------------------------------------
5202 // -----------------------------------------------------------------------
5204 wxPGChoiceEntry::wxPGChoiceEntry()
5205 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5209 // -----------------------------------------------------------------------
5211 // -----------------------------------------------------------------------
5213 wxPGChoicesData::wxPGChoicesData()
5218 wxPGChoicesData::~wxPGChoicesData()
5223 void wxPGChoicesData::Clear()
5228 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5230 wxASSERT( m_items
.size() == 0 );
5232 m_items
= data
->m_items
;
5235 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5236 const wxPGChoiceEntry
& item
)
5238 wxVector
<wxPGChoiceEntry
>::iterator it
;
5242 index
= (int) m_items
.size();
5246 it
= m_items
.begin() + index
;
5249 m_items
.insert(it
, item
);
5251 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5253 // Need to fix value?
5254 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5255 ownEntry
.SetValue(index
);
5260 // -----------------------------------------------------------------------
5262 // -----------------------------------------------------------------------
5264 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5268 wxPGChoiceEntry
entry(label
, value
);
5269 return m_data
->Insert( -1, entry
);
5272 // -----------------------------------------------------------------------
5274 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5278 wxPGChoiceEntry
entry(label
, value
);
5279 entry
.SetBitmap(bitmap
);
5280 return m_data
->Insert( -1, entry
);
5283 // -----------------------------------------------------------------------
5285 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5288 return m_data
->Insert( index
, entry
);
5291 // -----------------------------------------------------------------------
5293 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5297 wxPGChoiceEntry
entry(label
, value
);
5298 return m_data
->Insert( index
, entry
);
5301 // -----------------------------------------------------------------------
5303 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5309 while ( index
< GetCount() )
5311 int cmpRes
= GetLabel(index
).Cmp(label
);
5317 wxPGChoiceEntry
entry(label
, value
);
5318 return m_data
->Insert( index
, entry
);
5321 // -----------------------------------------------------------------------
5323 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5327 unsigned int itemcount
= 0;
5328 const wxChar
** p
= &labels
[0];
5329 while ( *p
) { p
++; itemcount
++; }
5332 for ( i
= 0; i
< itemcount
; i
++ )
5337 wxPGChoiceEntry
entry(labels
[i
], value
);
5338 m_data
->Insert( i
, entry
);
5342 // -----------------------------------------------------------------------
5344 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5349 unsigned int itemcount
= arr
.size();
5351 for ( i
= 0; i
< itemcount
; i
++ )
5354 if ( &arrint
&& arrint
.size() )
5356 wxPGChoiceEntry
entry(arr
[i
], value
);
5357 m_data
->Insert( i
, entry
);
5361 // -----------------------------------------------------------------------
5363 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5365 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5366 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5367 m_data
->m_items
.begin()+nIndex
+count
);
5370 // -----------------------------------------------------------------------
5372 int wxPGChoices::Index( const wxString
& str
) const
5377 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5379 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5380 if ( entry
.HasText() && entry
.GetText() == str
)
5387 // -----------------------------------------------------------------------
5389 int wxPGChoices::Index( int val
) const
5394 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5396 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5397 if ( entry
.GetValue() == val
)
5404 // -----------------------------------------------------------------------
5406 wxArrayString
wxPGChoices::GetLabels() const
5411 if ( this && IsOk() )
5412 for ( i
=0; i
<GetCount(); i
++ )
5413 arr
.push_back(GetLabel(i
));
5418 // -----------------------------------------------------------------------
5420 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5427 for ( i
=0; i
< strings
.size(); i
++ )
5429 int index
= Index(strings
[i
]);
5431 arr
.Add(GetValue(index
));
5433 arr
.Add(wxPG_INVALID_VALUE
);
5440 // -----------------------------------------------------------------------
5442 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5443 wxArrayString
* unmatched
) const
5450 for ( i
=0; i
< strings
.size(); i
++ )
5452 const wxString
& str
= strings
[i
];
5453 int index
= Index(str
);
5456 else if ( unmatched
)
5457 unmatched
->Add(str
);
5464 // -----------------------------------------------------------------------
5466 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5470 if ( data
!= wxPGChoicesEmptyData
)
5477 // -----------------------------------------------------------------------
5479 void wxPGChoices::Init()
5481 m_data
= wxPGChoicesEmptyData
;
5484 // -----------------------------------------------------------------------
5486 void wxPGChoices::Free()
5488 if ( m_data
!= wxPGChoicesEmptyData
)
5491 m_data
= wxPGChoicesEmptyData
;
5495 // -----------------------------------------------------------------------
5496 // wxPropertyGridEvent
5497 // -----------------------------------------------------------------------
5499 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5502 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5503 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5504 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5505 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5506 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5507 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5508 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5509 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5510 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5513 // -----------------------------------------------------------------------
5515 void wxPropertyGridEvent::Init()
5517 m_validationInfo
= NULL
;
5519 m_wasVetoed
= false;
5522 // -----------------------------------------------------------------------
5524 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5525 : wxCommandEvent(commandType
,id
)
5531 // -----------------------------------------------------------------------
5533 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5534 : wxCommandEvent(event
)
5536 m_eventType
= event
.GetEventType();
5537 m_eventObject
= event
.m_eventObject
;
5539 m_property
= event
.m_property
;
5540 m_validationInfo
= event
.m_validationInfo
;
5541 m_canVeto
= event
.m_canVeto
;
5542 m_wasVetoed
= event
.m_wasVetoed
;
5545 // -----------------------------------------------------------------------
5547 wxPropertyGridEvent::~wxPropertyGridEvent()
5551 // -----------------------------------------------------------------------
5553 wxEvent
* wxPropertyGridEvent::Clone() const
5555 return new wxPropertyGridEvent( *this );
5558 // -----------------------------------------------------------------------
5559 // wxPropertyGridPopulator
5560 // -----------------------------------------------------------------------
5562 wxPropertyGridPopulator::wxPropertyGridPopulator()
5566 wxPGGlobalVars
->m_offline
++;
5569 // -----------------------------------------------------------------------
5571 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5574 m_propHierarchy
.clear();
5577 // -----------------------------------------------------------------------
5579 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5585 // -----------------------------------------------------------------------
5587 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5590 // Free unused sets of choices
5591 wxPGHashMapS2P::iterator it
;
5593 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5595 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5602 m_pg
->GetPanel()->Refresh();
5604 wxPGGlobalVars
->m_offline
--;
5607 // -----------------------------------------------------------------------
5609 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5610 const wxString
& propLabel
,
5611 const wxString
& propName
,
5612 const wxString
* propValue
,
5613 wxPGChoices
* pChoices
)
5615 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5616 wxPGProperty
* parent
= GetCurParent();
5618 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5620 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5624 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5626 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5630 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5632 property
->SetLabel(propLabel
);
5633 property
->DoSetName(propName
);
5635 if ( pChoices
&& pChoices
->IsOk() )
5636 property
->SetChoices(*pChoices
);
5638 m_state
->DoInsert(parent
, -1, property
);
5641 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5642 wxPG_PROGRAMMATIC_VALUE
);
5647 // -----------------------------------------------------------------------
5649 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5651 m_propHierarchy
.push_back(property
);
5652 DoScanForChildren();
5653 m_propHierarchy
.pop_back();
5656 // -----------------------------------------------------------------------
5658 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5659 const wxString
& idString
)
5661 wxPGChoices choices
;
5664 if ( choicesString
[0] == wxT('@') )
5666 wxString ids
= choicesString
.substr(1);
5667 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5668 if ( it
== m_dictIdChoices
.end() )
5669 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5671 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5676 if ( idString
.length() )
5678 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5679 if ( it
!= m_dictIdChoices
.end() )
5681 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5688 // Parse choices string
5689 wxString::const_iterator it
= choicesString
.begin();
5693 bool labelValid
= false;
5695 for ( ; it
!= choicesString
.end(); ++it
)
5701 if ( c
== wxT('"') )
5706 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5707 choices
.Add(label
, l
);
5710 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5715 else if ( c
== wxT('=') )
5722 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5729 if ( c
== wxT('"') )
5742 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5743 choices
.Add(label
, l
);
5746 if ( !choices
.IsOk() )
5748 choices
.EnsureData();
5752 if ( idString
.length() )
5753 m_dictIdChoices
[idString
] = choices
.GetData();
5760 // -----------------------------------------------------------------------
5762 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5764 if ( s
.Last() == wxT('%') )
5766 wxString s2
= s
.substr(0,s
.length()-1);
5768 if ( s2
.ToLong(&val
, 10) )
5770 *pval
= (val
*max
)/100;
5776 return s
.ToLong(pval
, 10);
5779 // -----------------------------------------------------------------------
5781 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5782 const wxString
& type
,
5783 const wxString
& value
)
5785 int l
= m_propHierarchy
.size();
5789 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5790 wxString valuel
= value
.Lower();
5793 if ( type
.length() == 0 )
5798 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5800 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5802 else if ( value
.ToLong(&v
, 0) )
5809 if ( type
== wxT("string") )
5813 else if ( type
== wxT("int") )
5816 value
.ToLong(&v
, 0);
5819 else if ( type
== wxT("bool") )
5821 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5828 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5833 p
->SetAttribute( name
, variant
);
5838 // -----------------------------------------------------------------------
5840 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5842 wxLogError(_("Error in resource: %s"),msg
.c_str());
5845 // -----------------------------------------------------------------------
5847 #endif // wxUSE_PROPGRID