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
)
1183 Sort(wxPG_SORT_TOP_LEVEL_ONLY
);
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 m_pState
->PrepareAfterItemsAdded();
2283 if ( m_pState
->m_selected
)
2284 DoSelectProperty( m_pState
->m_selected
);
2286 RecalculateVirtualSize(0);
2290 m_pState
->m_itemsAdded
= 1;
2293 // -----------------------------------------------------------------------
2295 // Call to SetSplitterPosition will always disable splitter auto-centering
2296 // if parent window is shown.
2297 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2299 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2302 wxPropertyGridPageState
* state
= m_pState
;
2304 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2309 CorrectEditorWidgetSizeX();
2315 // -----------------------------------------------------------------------
2317 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2319 SetSplitterPosition( m_width
/2, true );
2320 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2321 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2324 // -----------------------------------------------------------------------
2325 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2326 // -----------------------------------------------------------------------
2328 // Returns nearest paint visible property (such that will be painted unless
2329 // window is scrolled or resized). If given property is paint visible, then
2330 // it itself will be returned
2331 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2333 int vx
,vy1
;// Top left corner of client
2334 GetViewStart(&vx
,&vy1
);
2335 vy1
*= wxPG_PIXELS_PER_UNIT
;
2337 int vy2
= vy1
+ m_height
;
2338 int propY
= p
->GetY2(m_lineHeight
);
2340 if ( (propY
+ m_lineHeight
) < vy1
)
2343 return DoGetItemAtY( vy1
);
2345 else if ( propY
> vy2
)
2348 return DoGetItemAtY( vy2
);
2351 // Itself paint visible
2356 // -----------------------------------------------------------------------
2357 // Methods related to change in value, value modification and sending events
2358 // -----------------------------------------------------------------------
2360 // commits any changes in editor of selected property
2361 // return true if validation did not fail
2362 // flags are same as with DoSelectProperty
2363 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2365 // Committing already?
2366 if ( m_inCommitChangesFromEditor
)
2369 // Don't do this if already processing editor event. It might
2370 // induce recursive dialogs and crap like that.
2371 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2373 if ( m_inDoPropertyChanged
)
2380 IsEditorsValueModified() &&
2381 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2384 m_inCommitChangesFromEditor
= 1;
2386 wxVariant
variant(m_selected
->GetValueRef());
2387 bool valueIsPending
= false;
2389 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2390 // due to another window getting focus
2391 wxWindow
* oldFocus
= m_curFocused
;
2393 bool validationFailure
= false;
2394 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2396 m_chgInfo_changedProperty
= NULL
;
2398 // If truly modified, schedule value as pending.
2399 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2401 if ( DoEditorValidate() &&
2402 PerformValidation(m_selected
, variant
) )
2404 valueIsPending
= true;
2408 validationFailure
= true;
2413 EditorsValueWasNotModified();
2418 m_inCommitChangesFromEditor
= 0;
2420 if ( validationFailure
&& !forceSuccess
)
2424 oldFocus
->SetFocus();
2425 m_curFocused
= oldFocus
;
2428 res
= OnValidationFailure(m_selected
, variant
);
2430 // Now prevent further validation failure messages
2433 EditorsValueWasNotModified();
2434 OnValidationFailureReset(m_selected
);
2437 else if ( valueIsPending
)
2439 DoPropertyChanged( m_selected
, flags
);
2440 EditorsValueWasNotModified();
2449 // -----------------------------------------------------------------------
2451 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2455 // Runs all validation functionality.
2456 // Returns true if value passes all tests.
2459 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2461 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2463 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2468 // Adapt list to child values, if necessary
2469 wxVariant listValue
= pendingValue
;
2470 wxVariant
* pPendingValue
= &pendingValue
;
2471 wxVariant
* pList
= NULL
;
2473 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2474 // string value, then we need treat as it was changed instead
2475 // (or, in addition, as is the case with composite string parent).
2476 // This includes creating list variant for child values.
2478 wxPGProperty
* pwc
= p
->GetParent();
2479 wxPGProperty
* changedProperty
= p
;
2480 wxPGProperty
* baseChangedProperty
= changedProperty
;
2481 wxVariant bcpPendingList
;
2483 listValue
= pendingValue
;
2484 listValue
.SetName(p
->GetBaseName());
2487 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2489 wxVariantList tempList
;
2490 wxVariant
lv(tempList
, pwc
->GetBaseName());
2491 lv
.Append(listValue
);
2493 pPendingValue
= &listValue
;
2495 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2497 baseChangedProperty
= pwc
;
2498 bcpPendingList
= lv
;
2501 changedProperty
= pwc
;
2502 pwc
= pwc
->GetParent();
2506 wxPGProperty
* evtChangingProperty
= changedProperty
;
2508 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2510 value
= *pPendingValue
;
2514 // Convert list to child values
2515 pList
= pPendingValue
;
2516 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2519 wxVariant evtChangingValue
= value
;
2521 if ( flags
& SendEvtChanging
)
2523 // FIXME: After proper ValueToString()s added, remove
2524 // this. It is just a temporary fix, as evt_changing
2525 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2526 // (unless it is selected, and textctrl editor is open).
2527 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2529 evtChangingProperty
= baseChangedProperty
;
2530 if ( evtChangingProperty
!= p
)
2532 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2536 evtChangingValue
= pendingValue
;
2540 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2542 if ( changedProperty
== m_selected
)
2544 wxWindow
* editor
= GetEditorControl();
2545 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2546 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2550 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2555 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2556 m_chgInfo_changedProperty
= changedProperty
;
2557 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2558 m_chgInfo_pendingValue
= value
;
2561 m_chgInfo_valueList
= *pList
;
2563 m_chgInfo_valueList
.MakeNull();
2565 // If changedProperty is not property which value was edited,
2566 // then call wxPGProperty::ValidateValue() for that as well.
2567 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2569 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2573 if ( flags
& SendEvtChanging
)
2575 // SendEvent returns true if event was vetoed
2576 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2580 if ( flags
& IsStandaloneValidation
)
2582 // If called in 'generic' context, we need to reset
2583 // m_chgInfo_changedProperty and write back translated value.
2584 m_chgInfo_changedProperty
= NULL
;
2585 pendingValue
= value
;
2591 // -----------------------------------------------------------------------
2593 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2595 if ( !msg
.length() )
2599 if ( !wxPGGlobalVars
->m_offline
)
2601 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2604 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2607 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2610 pStatusBar
->SetStatusText(msg
);
2618 ::wxMessageBox(msg
, _T("Property Error"));
2621 // -----------------------------------------------------------------------
2623 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2625 int vfb
= m_validationInfo
.m_failureBehavior
;
2627 if ( vfb
& wxPG_VFB_BEEP
)
2630 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2631 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2633 unsigned int colCount
= m_pState
->GetColumnCount();
2635 // We need backup marked property's cells
2636 m_propCellsBackup
= property
->m_cells
;
2638 wxColour vfbFg
= *wxWHITE
;
2639 wxColour vfbBg
= *wxRED
;
2641 property
->EnsureCells(colCount
);
2643 for ( unsigned int i
=0; i
<colCount
; i
++ )
2645 wxPGCell
& cell
= property
->m_cells
[i
];
2646 cell
.SetFgCol(vfbFg
);
2647 cell
.SetBgCol(vfbBg
);
2650 DrawItemAndChildren(property
);
2652 if ( property
== m_selected
)
2654 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2656 wxWindow
* editor
= GetEditorControl();
2659 editor
->SetForegroundColour(vfbFg
);
2660 editor
->SetBackgroundColour(vfbBg
);
2665 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2667 wxString msg
= m_validationInfo
.m_failureMessage
;
2669 if ( !msg
.length() )
2670 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2672 DoShowPropertyError(property
, msg
);
2675 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2678 // -----------------------------------------------------------------------
2680 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2682 int vfb
= m_validationInfo
.m_failureBehavior
;
2684 if ( vfb
& wxPG_VFB_MARK_CELL
)
2687 property
->m_cells
= m_propCellsBackup
;
2689 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2691 if ( property
== m_selected
&& GetEditorControl() )
2693 // Calling this will recreate the control, thus resetting its colour
2694 RefreshProperty(property
);
2698 DrawItemAndChildren(property
);
2703 // -----------------------------------------------------------------------
2705 // flags are same as with DoSelectProperty
2706 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2708 if ( m_inDoPropertyChanged
)
2711 wxWindow
* editor
= GetEditorControl();
2713 m_pState
->m_anyModified
= 1;
2715 m_inDoPropertyChanged
= 1;
2717 // Maybe need to update control
2718 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2720 // These values were calculated in PerformValidation()
2721 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2722 wxVariant value
= m_chgInfo_pendingValue
;
2724 wxPGProperty
* topPaintedProperty
= changedProperty
;
2726 while ( !topPaintedProperty
->IsCategory() &&
2727 !topPaintedProperty
->IsRoot() )
2729 topPaintedProperty
= topPaintedProperty
->GetParent();
2732 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2734 // Set as Modified (not if dragging just began)
2735 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2737 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2738 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2741 SetCurControlBoldFont();
2747 // Propagate updates to parent(s)
2749 wxPGProperty
* prevPwc
= NULL
;
2751 while ( prevPwc
!= topPaintedProperty
)
2753 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2755 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2758 SetCurControlBoldFont();
2762 pwc
= pwc
->GetParent();
2765 // Draw the actual property
2766 DrawItemAndChildren( topPaintedProperty
);
2769 // If value was set by wxPGProperty::OnEvent, then update the editor
2771 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2777 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2778 if ( m_wndEditor
) m_wndEditor
->Refresh();
2779 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2784 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2786 // If top parent has composite string value, then send to child parents,
2787 // starting from baseChangedProperty.
2788 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2790 pwc
= m_chgInfo_baseChangedProperty
;
2792 while ( pwc
!= changedProperty
)
2794 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2795 pwc
= pwc
->GetParent();
2799 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2801 m_inDoPropertyChanged
= 0;
2806 // -----------------------------------------------------------------------
2808 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2810 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2812 m_chgInfo_changedProperty
= NULL
;
2814 if ( PerformValidation(p
, newValue
) )
2816 DoPropertyChanged(p
);
2821 OnValidationFailure(p
, newValue
);
2827 // -----------------------------------------------------------------------
2829 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2831 wxPGProperty
* prop
= GetSelectedProperty();
2834 return wxNullVariant
;
2836 wxTextCtrl
* tc
= GetEditorTextCtrl();
2837 wxVariant value
= prop
->GetValue();
2839 if ( !tc
|| !IsEditorsValueModified() )
2842 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2845 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2846 return prop
->GetValue();
2851 // -----------------------------------------------------------------------
2853 // Runs wxValidator for the selected property
2854 bool wxPropertyGrid::DoEditorValidate()
2859 // -----------------------------------------------------------------------
2861 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2863 wxPGProperty
* selected
= m_selected
;
2865 // Somehow, event is handled after property has been deselected.
2866 // Possibly, but very rare.
2870 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2873 wxVariant
pendingValue(selected
->GetValueRef());
2874 wxWindow
* wnd
= GetEditorControl();
2876 bool wasUnspecified
= selected
->IsValueUnspecified();
2877 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2879 bool valueIsPending
= false;
2881 m_chgInfo_changedProperty
= NULL
;
2883 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2886 // Filter out excess wxTextCtrl modified events
2887 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2889 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2891 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2893 wxString newTcValue
= tc
->GetValue();
2894 if ( m_prevTcValue
== newTcValue
)
2897 m_prevTcValue
= newTcValue
;
2900 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2902 bool validationFailure
= false;
2903 bool buttonWasHandled
= false;
2906 // Try common button handling
2907 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2909 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2913 buttonWasHandled
= true;
2914 // Store as res2, as previously (and still currently alternatively)
2915 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2916 // in wxPGProperty::OnEvent().
2917 adapter
->ShowDialog( this, selected
);
2922 if ( !buttonWasHandled
)
2926 // First call editor class' event handler.
2927 const wxPGEditor
* editor
= selected
->GetEditorClass();
2929 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2931 // If changes, validate them
2932 if ( DoEditorValidate() )
2934 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
2935 valueIsPending
= true;
2939 validationFailure
= true;
2944 // Then the property's custom handler (must be always called, unless
2945 // validation failed).
2946 if ( !validationFailure
)
2947 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
2950 // SetValueInEvent(), as called in one of the functions referred above
2951 // overrides editor's value.
2952 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2954 valueIsPending
= true;
2955 pendingValue
= m_changeInEventValue
;
2956 selFlags
|= wxPG_SEL_DIALOGVAL
;
2959 if ( !validationFailure
&& valueIsPending
)
2960 if ( !PerformValidation(m_selected
, pendingValue
) )
2961 validationFailure
= true;
2963 if ( validationFailure
)
2965 OnValidationFailure(selected
, pendingValue
);
2967 else if ( valueIsPending
)
2969 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2971 DoPropertyChanged(selected
, selFlags
);
2972 EditorsValueWasNotModified();
2974 // Regardless of editor type, unfocus editor on
2975 // text-editing related enter press.
2976 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2983 // No value after all
2985 // Regardless of editor type, unfocus editor on
2986 // text-editing related enter press.
2987 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2992 // Let unhandled button click events go to the parent
2993 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2995 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2996 GetEventHandler()->AddPendingEvent(evt
);
3000 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3003 // -----------------------------------------------------------------------
3004 // wxPropertyGrid editor control helper methods
3005 // -----------------------------------------------------------------------
3007 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3009 int itemy
= p
->GetY2(m_lineHeight
);
3011 int cust_img_space
= 0;
3012 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3013 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3015 // TODO: If custom image detection changes from current, change this.
3016 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3018 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3019 int imwid
= p
->OnMeasureImage().x
;
3020 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3021 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3026 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3028 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3033 // -----------------------------------------------------------------------
3035 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3037 wxSize sz
= GetImageSize(p
, item
);
3038 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3039 wxPG_CUSTOM_IMAGE_SPACINGY
,
3044 // return size of custom paint image
3045 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3047 // If called with NULL property, then return default image
3048 // size for properties that use image.
3050 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3052 wxSize cis
= p
->OnMeasureImage(item
);
3054 int choiceCount
= p
->m_choices
.GetCount();
3055 int comVals
= p
->GetDisplayedCommonValueCount();
3056 if ( item
>= choiceCount
&& comVals
> 0 )
3058 unsigned int cvi
= item
-choiceCount
;
3059 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3061 else if ( item
>= 0 && choiceCount
== 0 )
3062 return wxSize(0, 0);
3067 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3072 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3079 // -----------------------------------------------------------------------
3081 // takes scrolling into account
3082 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3085 GetViewStart(&vx
,&vy
);
3086 vy
*=wxPG_PIXELS_PER_UNIT
;
3087 vx
*=wxPG_PIXELS_PER_UNIT
;
3090 ClientToScreen( px
, py
);
3093 // -----------------------------------------------------------------------
3095 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3098 GetViewStart(&pt2
.x
,&pt2
.y
);
3099 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3100 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3104 return m_pState
->HitTest(pt2
);
3107 // -----------------------------------------------------------------------
3109 // custom set cursor
3110 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3112 if ( type
== m_curcursor
&& !override
) return;
3114 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3116 if ( type
== wxCURSOR_SIZEWE
)
3117 cursor
= m_cursorSizeWE
;
3119 m_canvas
->SetCursor( *cursor
);
3124 // -----------------------------------------------------------------------
3125 // wxPropertyGrid property selection, editor creation
3126 // -----------------------------------------------------------------------
3129 // This class forwards events from property editor controls to wxPropertyGrid.
3130 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3133 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3134 : wxEvtHandler(), m_propGrid(propGrid
)
3138 virtual ~wxPropertyGridEditorEventForwarder()
3143 bool ProcessEvent( wxEvent
& event
)
3148 m_propGrid
->HandleCustomEditorEvent(event
);
3150 return wxEvtHandler::ProcessEvent(event
);
3153 wxPropertyGrid
* m_propGrid
;
3156 // Setups event handling for child control
3157 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3159 wxWindowID id
= argWnd
->GetId();
3161 if ( argWnd
== m_wndEditor
)
3163 argWnd
->Connect(id
, wxEVT_MOTION
,
3164 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3166 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3167 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3169 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3170 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3172 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3173 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3175 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3176 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3178 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3179 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3183 wxPropertyGridEditorEventForwarder
* forwarder
;
3184 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3185 argWnd
->PushEventHandler(forwarder
);
3187 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3188 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3192 void wxPropertyGrid::FreeEditors()
3195 // Return focus back to canvas from children (this is required at least for
3196 // GTK+, which, unlike Windows, clears focus when control is destroyed
3197 // instead of moving it to closest parent).
3198 wxWindow
* focus
= wxWindow::FindFocus();
3201 wxWindow
* parent
= focus
->GetParent();
3204 if ( parent
== m_canvas
)
3209 parent
= parent
->GetParent();
3213 // Do not free editors immediately if processing events
3216 m_wndEditor2
->PopEventHandler(true);
3217 m_wndEditor2
->Hide();
3218 wxPendingDelete
.Append( m_wndEditor2
);
3219 m_wndEditor2
= (wxWindow
*) NULL
;
3224 m_wndEditor
->PopEventHandler(true);
3225 m_wndEditor
->Hide();
3226 wxPendingDelete
.Append( m_wndEditor
);
3227 m_wndEditor
= (wxWindow
*) NULL
;
3231 // Call with NULL to de-select property
3232 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3236 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3237 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3239 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3242 if ( m_inDoSelectProperty
)
3245 m_inDoSelectProperty
= 1;
3247 wxPGProperty
* prev
= m_selected
;
3251 m_inDoSelectProperty
= 0;
3257 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3259 wxPrintf( "None selected\n" );
3262 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3264 wxPrintf( "P = NULL\n" );
3267 // If we are frozen, then just set the values.
3270 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3271 m_editorFocused
= 0;
3274 m_pState
->m_selected
= p
;
3276 // If frozen, always free controls. But don't worry, as Thaw will
3277 // recall SelectProperty to recreate them.
3280 // Prevent any further selection measures in this call
3281 p
= (wxPGProperty
*) NULL
;
3286 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3288 // Only set focus if not deselecting
3291 if ( flags
& wxPG_SEL_FOCUS
)
3295 m_wndEditor
->SetFocus();
3296 m_editorFocused
= 1;
3305 m_inDoSelectProperty
= 0;
3310 // First, deactivate previous
3314 OnValidationFailureReset(m_selected
);
3316 // Must double-check if this is an selected in case of forceswitch
3319 if ( !CommitChangesFromEditor(flags
) )
3321 // Validation has failed, so we can't exit the previous editor
3322 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3323 // _("Invalid Value"),wxOK|wxICON_ERROR);
3324 m_inDoSelectProperty
= 0;
3332 m_selected
= (wxPGProperty
*) NULL
;
3333 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3335 // We need to always fully refresh the grid here
3338 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3339 EditorsValueWasNotModified();
3342 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3345 // Then, activate the one given.
3348 int propY
= p
->GetY2(m_lineHeight
);
3350 int splitterX
= GetSplitterPosition();
3351 m_editorFocused
= 0;
3353 m_pState
->m_selected
= p
;
3354 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3356 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3358 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3361 // Only create editor for non-disabled non-caption
3362 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3364 // do this for non-caption items
3368 // Do we need to paint the custom image, if any?
3369 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3370 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3371 !p
->GetEditorClass()->CanContainCustomImage()
3373 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3375 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3376 wxPoint goodPos
= grect
.GetPosition();
3377 #if wxPG_CREATE_CONTROLS_HIDDEN
3378 int coord_adjust
= m_height
- goodPos
.y
;
3379 goodPos
.y
+= coord_adjust
;
3382 const wxPGEditor
* editor
= p
->GetEditorClass();
3383 wxCHECK_MSG(editor
, false,
3384 wxT("NULL editor class not allowed"));
3386 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3388 wxPGWindowList wndList
= editor
->CreateControls(this,
3393 m_wndEditor
= wndList
.m_primary
;
3394 m_wndEditor2
= wndList
.m_secondary
;
3395 wxWindow
* primaryCtrl
= GetEditorControl();
3398 // Essentially, primaryCtrl == m_wndEditor
3401 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3402 // value is drawn as normal, and m_wndEditor2 is assumed
3403 // to be a right-aligned button that triggers a separate editorCtrl
3408 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3409 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3411 // Set validator, if any
3412 #if wxUSE_VALIDATORS
3413 wxValidator
* validator
= p
->GetValidator();
3415 primaryCtrl
->SetValidator(*validator
);
3418 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3419 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3421 // If it has modified status, use bold font
3422 // (must be done before capturing m_ctrlXAdjust)
3423 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3424 SetCurControlBoldFont();
3427 // Fix TextCtrl indentation
3428 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3429 wxTextCtrl
* tc
= NULL
;
3430 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3431 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3433 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3435 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3438 // Store x relative to splitter (we'll need it).
3439 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3441 // Check if background clear is not necessary
3442 wxPoint pos
= m_wndEditor
->GetPosition();
3443 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3445 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3448 m_wndEditor
->SetSizeHints(3, 3);
3450 #if wxPG_CREATE_CONTROLS_HIDDEN
3451 m_wndEditor
->Show(false);
3452 m_wndEditor
->Freeze();
3454 goodPos
= m_wndEditor
->GetPosition();
3455 goodPos
.y
-= coord_adjust
;
3456 m_wndEditor
->Move( goodPos
);
3459 SetupChildEventHandling(primaryCtrl
);
3461 // Focus and select all (wxTextCtrl, wxComboBox etc)
3462 if ( flags
& wxPG_SEL_FOCUS
)
3464 primaryCtrl
->SetFocus();
3466 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3472 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3473 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3475 // Get proper id for wndSecondary
3476 m_wndSecId
= m_wndEditor2
->GetId();
3477 wxWindowList children
= m_wndEditor2
->GetChildren();
3478 wxWindowList::iterator node
= children
.begin();
3479 if ( node
!= children
.end() )
3480 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3482 m_wndEditor2
->SetSizeHints(3,3);
3484 #if wxPG_CREATE_CONTROLS_HIDDEN
3485 wxRect sec_rect
= m_wndEditor2
->GetRect();
3486 sec_rect
.y
-= coord_adjust
;
3488 // Fine tuning required to fix "oversized"
3489 // button disappearance bug.
3490 if ( sec_rect
.y
< 0 )
3492 sec_rect
.height
+= sec_rect
.y
;
3495 m_wndEditor2
->SetSize( sec_rect
);
3497 m_wndEditor2
->Show();
3499 SetupChildEventHandling(m_wndEditor2
);
3501 // If no primary editor, focus to button to allow
3502 // it to interprete ENTER etc.
3503 // NOTE: Due to problems focusing away from it, this
3504 // has been disabled.
3506 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3507 m_wndEditor2->SetFocus();
3511 if ( flags
& wxPG_SEL_FOCUS
)
3512 m_editorFocused
= 1;
3517 // Make sure focus is in grid canvas (important for wxGTK, at least)
3521 EditorsValueWasNotModified();
3523 // If it's inside collapsed section, expand parent, scroll, etc.
3524 // Also, if it was partially visible, scroll it into view.
3525 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3530 #if wxPG_CREATE_CONTROLS_HIDDEN
3531 m_wndEditor
->Thaw();
3533 m_wndEditor
->Show(true);
3540 // Make sure focus is in grid canvas
3544 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3550 // Show help text in status bar.
3551 // (if found and grid not embedded in manager with help box and
3552 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3555 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3557 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3558 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3560 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3562 statusbar
= frame
->GetStatusBar();
3567 const wxString
* pHelpString
= (const wxString
*) NULL
;
3571 pHelpString
= &p
->GetHelpString();
3572 if ( pHelpString
->length() )
3574 // Set help box text.
3575 statusbar
->SetStatusText( *pHelpString
);
3576 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3580 if ( (!pHelpString
|| !pHelpString
->length()) &&
3581 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3583 // Clear help box - but only if it was written
3584 // by us at previous time.
3585 statusbar
->SetStatusText( m_emptyString
);
3586 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3592 m_inDoSelectProperty
= 0;
3594 // call wx event handler (here so that it also occurs on deselection)
3595 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3600 // -----------------------------------------------------------------------
3602 bool wxPropertyGrid::UnfocusEditor()
3604 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3607 if ( !CommitChangesFromEditor(0) )
3611 DrawItem(m_selected
);
3616 // -----------------------------------------------------------------------
3618 void wxPropertyGrid::RefreshEditor()
3620 wxPGProperty
* p
= m_selected
;
3624 wxWindow
* wnd
= GetEditorControl();
3628 // Set editor font boldness - must do this before
3629 // calling UpdateControl().
3630 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3632 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3633 wnd
->SetFont(GetCaptionFont());
3635 wnd
->SetFont(GetFont());
3638 p
->GetEditorClass()->UpdateControl(p
, wnd
);
3641 // -----------------------------------------------------------------------
3643 // This method is not inline because it called dozens of times
3644 // (i.e. two-arg function calls create smaller code size).
3645 bool wxPropertyGrid::DoClearSelection()
3647 return DoSelectProperty((wxPGProperty
*)NULL
);
3650 // -----------------------------------------------------------------------
3651 // wxPropertyGrid expand/collapse state
3652 // -----------------------------------------------------------------------
3654 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3656 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3658 // If active editor was inside collapsed section, then disable it
3659 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3661 ClearSelection(false);
3664 // Store dont-center-splitter flag 'cause we need to temporarily set it
3665 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3666 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3668 bool res
= m_pState
->DoCollapse(pwc
);
3673 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3675 RecalculateVirtualSize();
3677 // Redraw etc. only if collapsed was visible.
3678 if (pwc
->IsVisible() &&
3680 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3682 // When item is collapsed so that scrollbar would move,
3683 // graphics mess is about (unless we redraw everything).
3688 // Clear dont-center-splitter flag if it wasn't set
3689 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3694 // -----------------------------------------------------------------------
3696 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3698 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3700 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3702 // Store dont-center-splitter flag 'cause we need to temporarily set it
3703 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3704 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3706 bool res
= m_pState
->DoExpand(pwc
);
3711 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3713 RecalculateVirtualSize();
3715 // Redraw etc. only if expanded was visible.
3716 if ( pwc
->IsVisible() && !m_frozen
&&
3717 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3721 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3724 DrawItems(pwc
, NULL
);
3729 // Clear dont-center-splitter flag if it wasn't set
3730 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3735 // -----------------------------------------------------------------------
3737 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3740 return m_pState
->DoHideProperty(p
, hide
, flags
);
3743 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3746 ClearSelection(false);
3749 m_pState
->DoHideProperty(p
, hide
, flags
);
3751 RecalculateVirtualSize();
3758 // -----------------------------------------------------------------------
3759 // wxPropertyGrid size related methods
3760 // -----------------------------------------------------------------------
3762 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3764 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3768 // If virtual height was changed, then recalculate editor control position(s)
3769 if ( m_pState
->m_vhCalcPending
)
3770 CorrectEditorWidgetPosY();
3772 m_pState
->EnsureVirtualHeight();
3775 int by1
= m_pState
->GetVirtualHeight();
3776 int by2
= m_pState
->GetActualVirtualHeight();
3779 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3780 wxFAIL_MSG(s
.c_str());
3785 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3787 int x
= m_pState
->m_width
;
3788 int y
= m_pState
->m_virtualHeight
;
3791 GetClientSize(&width
,&height
);
3793 // Now adjust virtual size.
3794 SetVirtualSize(x
, y
);
3800 // Adjust scrollbars
3801 if ( HasVirtualWidth() )
3803 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3804 xPos
= GetScrollPos( wxHORIZONTAL
);
3807 if ( forceXPos
!= -1 )
3810 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3813 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3814 int yPos
= GetScrollPos( wxVERTICAL
);
3816 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3817 xAmount
, yAmount
, xPos
, yPos
, true );
3819 // Must re-get size now
3820 GetClientSize(&width
,&height
);
3822 if ( !HasVirtualWidth() )
3824 m_pState
->SetVirtualWidth(width
);
3831 m_canvas
->SetSize( x
, y
);
3833 m_pState
->CheckColumnWidths();
3836 CorrectEditorWidgetSizeX();
3838 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3841 // -----------------------------------------------------------------------
3843 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3845 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3849 GetClientSize(&width
,&height
);
3854 #if wxPG_DOUBLE_BUFFER
3855 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3857 int dblh
= (m_lineHeight
*2);
3858 if ( !m_doubleBuffer
)
3860 // Create double buffer bitmap to draw on, if none
3861 int w
= (width
>250)?width
:250;
3862 int h
= height
+ dblh
;
3864 m_doubleBuffer
= new wxBitmap( w
, h
);
3868 int w
= m_doubleBuffer
->GetWidth();
3869 int h
= m_doubleBuffer
->GetHeight();
3871 // Double buffer must be large enough
3872 if ( w
< width
|| h
< (height
+dblh
) )
3874 if ( w
< width
) w
= width
;
3875 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3876 delete m_doubleBuffer
;
3877 m_doubleBuffer
= new wxBitmap( w
, h
);
3884 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3885 m_ncWidth
= event
.GetSize().x
;
3889 if ( m_pState
->m_itemsAdded
)
3890 PrepareAfterItemsAdded();
3892 // Without this, virtual size (atleast under wxGTK) will be skewed
3893 RecalculateVirtualSize();
3899 // -----------------------------------------------------------------------
3901 void wxPropertyGrid::SetVirtualWidth( int width
)
3905 // Disable virtual width
3906 width
= GetClientSize().x
;
3907 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3911 // Enable virtual width
3912 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3914 m_pState
->SetVirtualWidth( width
);
3917 void wxPropertyGrid::SetFocusOnCanvas()
3919 m_canvas
->SetFocusIgnoringChildren();
3920 m_editorFocused
= 0;
3923 // -----------------------------------------------------------------------
3924 // wxPropertyGrid mouse event handling
3925 // -----------------------------------------------------------------------
3927 // selFlags uses same values DoSelectProperty's flags
3928 // Returns true if event was vetoed.
3929 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3931 // Send property grid event of specific type and with specific property
3932 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3933 evt
.SetPropertyGrid(this);
3934 evt
.SetEventObject(m_eventObject
);
3938 evt
.SetCanVeto(true);
3939 evt
.SetupValidationInfo();
3940 m_validationInfo
.m_pValue
= pValue
;
3942 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3944 evtHandler
->ProcessEvent(evt
);
3946 return evt
.WasVetoed();
3949 // -----------------------------------------------------------------------
3951 // Return false if should be skipped
3952 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3956 // Need to set focus?
3957 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3962 wxPropertyGridPageState
* state
= m_pState
;
3964 int splitterHitOffset
;
3965 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3967 wxPGProperty
* p
= DoGetItemAtY(y
);
3971 int depth
= (int)p
->GetDepth() - 1;
3973 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3975 if ( x
>= marginEnds
)
3979 if ( p
->IsCategory() )
3981 // This is category.
3982 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3984 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3986 // Expand, collapse, activate etc. if click on text or left of splitter.
3989 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3994 if ( !DoSelectProperty( p
) )
3997 // On double-click, expand/collapse.
3998 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4000 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4001 else DoExpand( p
, true );
4005 else if ( splitterHit
== -1 )
4008 unsigned int selFlag
= 0;
4009 if ( columnHit
== 1 )
4011 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4012 selFlag
= wxPG_SEL_FOCUS
;
4014 if ( !DoSelectProperty( p
, selFlag
) )
4017 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4019 if ( p
->GetChildCount() && !p
->IsCategory() )
4020 // On double-click, expand/collapse.
4021 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4023 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4024 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4025 else DoExpand( p
, true );
4032 // click on splitter
4033 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4035 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4037 // Double-clicking the splitter causes auto-centering
4038 CenterSplitter( true );
4040 else if ( m_dragStatus
== 0 )
4043 // Begin draggin the splitter
4047 // Changes must be committed here or the
4048 // value won't be drawn correctly
4049 if ( !CommitChangesFromEditor() )
4052 m_wndEditor
->Show ( false );
4055 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4057 m_canvas
->CaptureMouse();
4058 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4062 m_draggedSplitter
= splitterHit
;
4063 m_dragOffset
= splitterHitOffset
;
4065 wxClientDC
dc(m_canvas
);
4067 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4068 // Fixes button disappearance bug
4070 m_wndEditor2
->Show ( false );
4073 m_startingSplitterX
= x
- splitterHitOffset
;
4081 if ( p
->GetChildCount() )
4083 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4085 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4087 int y2
= y
% m_lineHeight
;
4088 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4090 // On click on expander button, expand/collapse
4091 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4092 DoCollapse( p
, true );
4094 DoExpand( p
, true );
4103 // -----------------------------------------------------------------------
4105 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4106 wxMouseEvent
& WXUNUSED(event
) )
4110 // Select property here as well
4111 wxPGProperty
* p
= m_propHover
;
4112 if ( p
!= m_selected
)
4113 DoSelectProperty( p
);
4115 // Send right click event.
4116 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4123 // -----------------------------------------------------------------------
4125 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4126 wxMouseEvent
& WXUNUSED(event
) )
4130 // Select property here as well
4131 wxPGProperty
* p
= m_propHover
;
4133 if ( p
!= m_selected
)
4134 DoSelectProperty( p
);
4136 // Send double-click event.
4137 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4144 // -----------------------------------------------------------------------
4146 #if wxPG_SUPPORT_TOOLTIPS
4148 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4150 if ( tipString
.length() )
4152 m_canvas
->SetToolTip(tipString
);
4156 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4157 m_canvas
->SetToolTip( m_emptyString
);
4159 m_canvas
->SetToolTip( NULL
);
4164 #endif // #if wxPG_SUPPORT_TOOLTIPS
4166 // -----------------------------------------------------------------------
4168 // Return false if should be skipped
4169 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4171 // Safety check (needed because mouse capturing may
4172 // otherwise freeze the control)
4173 if ( m_dragStatus
> 0 && !event
.Dragging() )
4175 HandleMouseUp(x
,y
,event
);
4178 wxPropertyGridPageState
* state
= m_pState
;
4180 int splitterHitOffset
;
4181 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4182 int splitterX
= x
- splitterHitOffset
;
4184 if ( m_dragStatus
> 0 )
4186 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4187 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4190 int newSplitterX
= x
- m_dragOffset
;
4191 int splitterX
= x
- splitterHitOffset
;
4193 // Splitter redraw required?
4194 if ( newSplitterX
!= splitterX
)
4197 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4198 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4199 state
->m_fSplitterX
= (float) newSplitterX
;
4202 CorrectEditorWidgetSizeX();
4216 int ih
= m_lineHeight
;
4219 #if wxPG_SUPPORT_TOOLTIPS
4220 wxPGProperty
* prevHover
= m_propHover
;
4221 unsigned char prevSide
= m_mouseSide
;
4223 int curPropHoverY
= y
- (y
% ih
);
4225 // On which item it hovers
4228 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4231 // Mouse moves on another property
4233 m_propHover
= DoGetItemAtY(y
);
4234 m_propHoverY
= curPropHoverY
;
4237 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4240 #if wxPG_SUPPORT_TOOLTIPS
4241 // Store which side we are on
4243 if ( columnHit
== 1 )
4245 else if ( columnHit
== 0 )
4249 // If tooltips are enabled, show label or value as a tip
4250 // in case it doesn't otherwise show in full length.
4252 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4254 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4256 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4258 if ( m_propHover
&& !m_propHover
->IsCategory() )
4261 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4263 // Show help string as a tooltip
4264 wxString tipString
= m_propHover
->GetHelpString();
4266 SetToolTip(tipString
);
4270 // Show cropped value string as a tooltip
4274 if ( m_mouseSide
== 1 )
4276 tipString
= m_propHover
->m_label
;
4277 space
= splitterX
-m_marginWidth
-3;
4279 else if ( m_mouseSide
== 2 )
4281 tipString
= m_propHover
->GetDisplayedString();
4283 space
= m_width
- splitterX
;
4284 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4285 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4291 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4294 SetToolTip( tipString
);
4301 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4302 m_canvas
->SetToolTip( m_emptyString
);
4304 m_canvas
->SetToolTip( NULL
);
4315 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4316 m_canvas
->SetToolTip( m_emptyString
);
4318 m_canvas
->SetToolTip( NULL
);
4326 if ( splitterHit
== -1 ||
4328 HasFlag(wxPG_STATIC_SPLITTER
) )
4330 // hovering on something else
4331 if ( m_curcursor
!= wxCURSOR_ARROW
)
4332 CustomSetCursor( wxCURSOR_ARROW
);
4336 // Do not allow splitter cursor on caption items.
4337 // (also not if we were dragging and its started
4338 // outside the splitter region)
4340 if ( !m_propHover
->IsCategory() &&
4344 // hovering on splitter
4346 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4347 // reliably detected.
4348 //if ( m_curcursor != wxCURSOR_SIZEWE )
4349 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4355 // hovering on something else
4356 if ( m_curcursor
!= wxCURSOR_ARROW
)
4357 CustomSetCursor( wxCURSOR_ARROW
);
4364 // -----------------------------------------------------------------------
4366 // Also handles Leaving event
4367 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4368 wxMouseEvent
&WXUNUSED(event
) )
4370 wxPropertyGridPageState
* state
= m_pState
;
4374 int splitterHitOffset
;
4375 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4377 // No event type check - basicly calling this method should
4378 // just stop dragging.
4379 // Left up after dragged?
4380 if ( m_dragStatus
>= 1 )
4383 // End Splitter Dragging
4385 // DO NOT ENABLE FOLLOWING LINE!
4386 // (it is only here as a reminder to not to do it)
4389 // Disable splitter auto-centering
4390 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4392 // This is necessary to return cursor
4393 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4395 m_canvas
->ReleaseMouse();
4396 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4399 // Set back the default cursor, if necessary
4400 if ( splitterHit
== -1 ||
4403 CustomSetCursor( wxCURSOR_ARROW
);
4408 // Control background needs to be cleared
4409 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4410 DrawItem( m_selected
);
4414 m_wndEditor
->Show ( true );
4417 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4418 // Fixes button disappearance bug
4420 m_wndEditor2
->Show ( true );
4423 // This clears the focus.
4424 m_editorFocused
= 0;
4430 // -----------------------------------------------------------------------
4432 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4434 int splitterX
= GetSplitterPosition();
4437 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4441 wxWindow
* wnd
= GetEditorControl();
4443 // Hide popup on clicks
4444 if ( event
.GetEventType() != wxEVT_MOTION
)
4445 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4447 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4453 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4455 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4456 ux
>= (r
.x
+r
.width
) ||
4458 event
.m_y
>= (r
.y
+r
.height
)
4468 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4473 // -----------------------------------------------------------------------
4475 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4478 if ( OnMouseCommon( event
, &x
, &y
) )
4480 HandleMouseClick(x
,y
,event
);
4485 // -----------------------------------------------------------------------
4487 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4490 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4491 HandleMouseRightClick(x
,y
,event
);
4495 // -----------------------------------------------------------------------
4497 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4499 // Always run standard mouse-down handler as well
4500 OnMouseClick(event
);
4503 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4504 HandleMouseDoubleClick(x
,y
,event
);
4508 // -----------------------------------------------------------------------
4510 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4513 if ( OnMouseCommon( event
, &x
, &y
) )
4515 HandleMouseMove(x
,y
,event
);
4520 // -----------------------------------------------------------------------
4522 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4524 // Called when mouse moves in the empty space below the properties.
4525 CustomSetCursor( wxCURSOR_ARROW
);
4528 // -----------------------------------------------------------------------
4530 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4533 if ( OnMouseCommon( event
, &x
, &y
) )
4535 HandleMouseUp(x
,y
,event
);
4540 // -----------------------------------------------------------------------
4542 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4544 // This may get called from child control as well, so event's
4545 // mouse position cannot be relied on.
4547 if ( event
.Entering() )
4549 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4551 // TODO: Fix this (detect parent and only do
4552 // cursor trick if it is a manager).
4553 wxASSERT( GetParent() );
4554 GetParent()->SetCursor(wxNullCursor
);
4556 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4559 GetParent()->SetCursor(wxNullCursor
);
4561 else if ( event
.Leaving() )
4563 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4564 m_canvas
->SetCursor( wxNullCursor
);
4566 // Get real cursor position
4567 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4569 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4572 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4574 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4578 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4586 // -----------------------------------------------------------------------
4588 // Common code used by various OnMouseXXXChild methods.
4589 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4591 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4592 wxASSERT( topCtrlWnd
);
4594 event
.GetPosition(&x
,&y
);
4596 int splitterX
= GetSplitterPosition();
4598 wxRect r
= topCtrlWnd
->GetRect();
4599 if ( !m_dragStatus
&&
4600 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4601 y
>= 0 && y
< r
.height \
4604 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4609 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4616 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4619 if ( OnMouseChildCommon(event
,&x
,&y
) )
4621 bool res
= HandleMouseClick(x
,y
,event
);
4622 if ( !res
) event
.Skip();
4626 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4629 wxASSERT( m_wndEditor
);
4630 // These coords may not be exact (about +-2),
4631 // but that should not matter (right click is about item, not position).
4632 wxPoint pt
= m_wndEditor
->GetPosition();
4633 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4634 wxASSERT( m_selected
);
4635 m_propHover
= m_selected
;
4636 bool res
= HandleMouseRightClick(x
,y
,event
);
4637 if ( !res
) event
.Skip();
4640 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4643 if ( OnMouseChildCommon(event
,&x
,&y
) )
4645 bool res
= HandleMouseMove(x
,y
,event
);
4646 if ( !res
) event
.Skip();
4650 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4653 if ( OnMouseChildCommon(event
,&x
,&y
) )
4655 bool res
= HandleMouseUp(x
,y
,event
);
4656 if ( !res
) event
.Skip();
4660 // -----------------------------------------------------------------------
4661 // wxPropertyGrid keyboard event handling
4662 // -----------------------------------------------------------------------
4664 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4666 // Translates wxKeyEvent to wxPG_ACTION_XXX
4668 int keycode
= event
.GetKeyCode();
4669 int modifiers
= event
.GetModifiers();
4671 wxASSERT( !(modifiers
&~(0xFFFF)) );
4673 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4675 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4677 if ( it
== m_actionTriggers
.end() )
4682 int second
= (it
->second
>>16) & 0xFFFF;
4686 return (it
->second
& 0xFFFF);
4689 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4691 wxASSERT( !(modifiers
&~(0xFFFF)) );
4693 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4695 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4697 if ( it
!= m_actionTriggers
.end() )
4699 // This key combination is already used
4701 // Can add secondary?
4702 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4703 wxT("You can only add up to two separate actions per key combination.") );
4705 action
= it
->second
| (action
<<16);
4708 m_actionTriggers
[hashMapKey
] = action
;
4711 void wxPropertyGrid::ClearActionTriggers( int action
)
4713 wxPGHashMapI2I::iterator it
;
4715 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4717 if ( it
->second
== action
)
4719 m_actionTriggers
.erase(it
);
4724 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4727 // Handles key event when editor control is not focused.
4730 wxCHECK2(!m_frozen
, return);
4732 // Travelsal between items, collapsing/expanding, etc.
4733 int keycode
= event
.GetKeyCode();
4734 bool editorFocused
= IsEditorFocused();
4736 if ( keycode
== WXK_TAB
)
4738 wxWindow
* mainControl
;
4740 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4741 mainControl
= GetParent();
4745 if ( !event
.ShiftDown() )
4747 if ( !editorFocused
&& m_wndEditor
)
4749 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4753 // Tab traversal workaround for platforms on which
4754 // wxWindow::Navigate() may navigate into first child
4755 // instead of next sibling. Does not work perfectly
4756 // in every scenario (for instance, when property grid
4757 // is either first or last control).
4758 #if defined(__WXGTK__)
4759 wxWindow
* sibling
= mainControl
->GetNextSibling();
4761 sibling
->SetFocusFromKbd();
4763 Navigate(wxNavigationKeyEvent::IsForward
);
4769 if ( editorFocused
)
4775 #if defined(__WXGTK__)
4776 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4778 sibling
->SetFocusFromKbd();
4780 Navigate(wxNavigationKeyEvent::IsBackward
);
4788 // Ignore Alt and Control when they are down alone
4789 if ( keycode
== WXK_ALT
||
4790 keycode
== WXK_CONTROL
)
4797 int action
= KeyEventToActions(event
, &secondAction
);
4799 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4802 // Esc cancels any changes
4803 if ( IsEditorsValueModified() )
4805 EditorsValueWasNotModified();
4807 // Update the control as well
4808 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4810 m_selected
->GetDisplayedString() );
4813 OnValidationFailureReset(m_selected
);
4819 // Except for TAB and ESC, handle child control events in child control
4826 bool wasHandled
= false;
4831 if ( ButtonTriggerKeyTest(action
, event
) )
4834 wxPGProperty
* p
= m_selected
;
4836 // Travel and expand/collapse
4839 if ( p
->GetChildCount() &&
4840 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4843 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4845 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4848 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4850 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4857 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4861 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4867 if ( selectDir
>= -1 )
4869 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4871 DoSelectProperty(p
);
4877 // If nothing was selected, select the first item now
4878 // (or navigate out of tab).
4879 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4881 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4882 if ( p
) DoSelectProperty(p
);
4891 // -----------------------------------------------------------------------
4893 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4895 HandleKeyEvent(event
, false);
4898 // -----------------------------------------------------------------------
4900 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4905 action
= KeyEventToActions(event
, &secondAction
);
4908 // Does the keycode trigger button?
4909 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4912 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4913 GetEventHandler()->AddPendingEvent(evt
);
4920 // -----------------------------------------------------------------------
4922 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4924 HandleKeyEvent(event
, true);
4927 // -----------------------------------------------------------------------
4928 // wxPropertyGrid miscellaneous event handling
4929 // -----------------------------------------------------------------------
4931 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4934 // Check if the focus is in this control or one of its children
4935 wxWindow
* newFocused
= wxWindow::FindFocus();
4937 if ( newFocused
!= m_curFocused
)
4938 HandleFocusChange( newFocused
);
4941 bool wxPropertyGrid::IsEditorFocused() const
4943 wxWindow
* focus
= wxWindow::FindFocus();
4945 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4946 focus
== GetEditorControl() )
4952 // Called by focus event handlers. newFocused is the window that becomes focused.
4953 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4955 unsigned int oldFlags
= m_iFlags
;
4957 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4959 wxWindow
* parent
= newFocused
;
4961 // This must be one of nextFocus' parents.
4964 // Use m_eventObject, which is either wxPropertyGrid or
4965 // wxPropertyGridManager, as appropriate.
4966 if ( parent
== m_eventObject
)
4968 m_iFlags
|= wxPG_FL_FOCUSED
;
4971 parent
= parent
->GetParent();
4974 m_curFocused
= newFocused
;
4976 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4977 (oldFlags
& wxPG_FL_FOCUSED
) )
4979 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4981 // Need to store changed value
4982 CommitChangesFromEditor();
4988 // Preliminary code for tab-order respecting
4989 // tab-traversal (but should be moved to
4992 wxWindow* prevFocus = event.GetWindow();
4993 wxWindow* useThis = this;
4994 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4995 useThis = GetParent();
4998 prevFocus->GetParent() == useThis->GetParent() )
5000 wxList& children = useThis->GetParent()->GetChildren();
5002 wxNode* node = children.Find(prevFocus);
5004 if ( node->GetNext() &&
5005 useThis == node->GetNext()->GetData() )
5006 DoSelectProperty(GetFirst());
5007 else if ( node->GetPrevious () &&
5008 useThis == node->GetPrevious()->GetData() )
5009 DoSelectProperty(GetLastProperty());
5016 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5017 DrawItem( m_selected
);
5021 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5023 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5024 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5025 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5026 //else if ( event.GetWindow() )
5028 HandleFocusChange(event
.GetWindow());
5033 // -----------------------------------------------------------------------
5035 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5037 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5040 // event.Skip() being commented out is aworkaround for bug reported
5041 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5045 // -----------------------------------------------------------------------
5047 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5049 m_iFlags
|= wxPG_FL_SCROLLED
;
5054 // -----------------------------------------------------------------------
5056 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5058 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5060 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5064 // -----------------------------------------------------------------------
5065 // Property editor related functions
5066 // -----------------------------------------------------------------------
5068 // noDefCheck = true prevents infinite recursion.
5069 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5072 wxASSERT( editorClass
);
5074 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5075 RegisterDefaultEditors();
5077 wxString name
= editorClass
->GetName();
5079 // Existing editor under this name?
5080 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5082 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5084 // If this name was already used, try class name.
5085 name
= editorClass
->GetClassInfo()->GetClassName();
5086 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5089 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5090 (wxPGEditor
*) vt_it
->second
,
5091 "Editor with given name was already registered" );
5093 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5098 // Use this in RegisterDefaultEditors.
5099 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5100 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5102 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5103 new wxPG##EDITOR##Editor, true ); \
5106 // Registers all default editor classes
5107 void wxPropertyGrid::RegisterDefaultEditors()
5109 wxPGRegisterDefaultEditorClass( TextCtrl
);
5110 wxPGRegisterDefaultEditorClass( Choice
);
5111 wxPGRegisterDefaultEditorClass( ComboBox
);
5112 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5113 #if wxPG_INCLUDE_CHECKBOX
5114 wxPGRegisterDefaultEditorClass( CheckBox
);
5116 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5118 // Register SpinCtrl etc. editors before use
5119 RegisterAdditionalEditors();
5122 // -----------------------------------------------------------------------
5123 // wxPGStringTokenizer
5124 // Needed to handle C-style string lists (e.g. "str1" "str2")
5125 // -----------------------------------------------------------------------
5127 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5128 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5132 wxPGStringTokenizer::~wxPGStringTokenizer()
5136 bool wxPGStringTokenizer::HasMoreTokens()
5138 const wxString
& str
= *m_str
;
5140 wxString::const_iterator i
= m_curPos
;
5142 wxUniChar delim
= m_delimeter
;
5144 wxUniChar prev_a
= wxT('\0');
5146 bool inToken
= false;
5148 while ( i
!= str
.end() )
5157 m_readyToken
.clear();
5162 if ( prev_a
!= wxT('\\') )
5166 if ( a
!= wxT('\\') )
5186 m_curPos
= str
.end();
5194 wxString
wxPGStringTokenizer::GetNextToken()
5196 return m_readyToken
;
5199 // -----------------------------------------------------------------------
5201 // -----------------------------------------------------------------------
5203 wxPGChoiceEntry::wxPGChoiceEntry()
5204 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5208 // -----------------------------------------------------------------------
5210 // -----------------------------------------------------------------------
5212 wxPGChoicesData::wxPGChoicesData()
5217 wxPGChoicesData::~wxPGChoicesData()
5222 void wxPGChoicesData::Clear()
5227 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5229 wxASSERT( m_items
.size() == 0 );
5231 m_items
= data
->m_items
;
5234 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5235 const wxPGChoiceEntry
& item
)
5237 wxVector
<wxPGChoiceEntry
>::iterator it
;
5241 index
= (int) m_items
.size();
5245 it
= m_items
.begin() + index
;
5248 m_items
.insert(it
, item
);
5250 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5252 // Need to fix value?
5253 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5254 ownEntry
.SetValue(index
);
5259 // -----------------------------------------------------------------------
5261 // -----------------------------------------------------------------------
5263 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5267 wxPGChoiceEntry
entry(label
, value
);
5268 return m_data
->Insert( -1, entry
);
5271 // -----------------------------------------------------------------------
5273 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5277 wxPGChoiceEntry
entry(label
, value
);
5278 entry
.SetBitmap(bitmap
);
5279 return m_data
->Insert( -1, entry
);
5282 // -----------------------------------------------------------------------
5284 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5287 return m_data
->Insert( index
, entry
);
5290 // -----------------------------------------------------------------------
5292 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5296 wxPGChoiceEntry
entry(label
, value
);
5297 return m_data
->Insert( index
, entry
);
5300 // -----------------------------------------------------------------------
5302 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5308 while ( index
< GetCount() )
5310 int cmpRes
= GetLabel(index
).Cmp(label
);
5316 wxPGChoiceEntry
entry(label
, value
);
5317 return m_data
->Insert( index
, entry
);
5320 // -----------------------------------------------------------------------
5322 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5326 unsigned int itemcount
= 0;
5327 const wxChar
** p
= &labels
[0];
5328 while ( *p
) { p
++; itemcount
++; }
5331 for ( i
= 0; i
< itemcount
; i
++ )
5336 wxPGChoiceEntry
entry(labels
[i
], value
);
5337 m_data
->Insert( i
, entry
);
5341 // -----------------------------------------------------------------------
5343 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5348 unsigned int itemcount
= arr
.size();
5350 for ( i
= 0; i
< itemcount
; i
++ )
5353 if ( &arrint
&& arrint
.size() )
5355 wxPGChoiceEntry
entry(arr
[i
], value
);
5356 m_data
->Insert( i
, entry
);
5360 // -----------------------------------------------------------------------
5362 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5364 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5365 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5366 m_data
->m_items
.begin()+nIndex
+count
);
5369 // -----------------------------------------------------------------------
5371 int wxPGChoices::Index( const wxString
& str
) const
5376 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5378 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5379 if ( entry
.HasText() && entry
.GetText() == str
)
5386 // -----------------------------------------------------------------------
5388 int wxPGChoices::Index( int val
) const
5393 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5395 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5396 if ( entry
.GetValue() == val
)
5403 // -----------------------------------------------------------------------
5405 wxArrayString
wxPGChoices::GetLabels() const
5410 if ( this && IsOk() )
5411 for ( i
=0; i
<GetCount(); i
++ )
5412 arr
.push_back(GetLabel(i
));
5417 // -----------------------------------------------------------------------
5419 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5426 for ( i
=0; i
< strings
.size(); i
++ )
5428 int index
= Index(strings
[i
]);
5430 arr
.Add(GetValue(index
));
5432 arr
.Add(wxPG_INVALID_VALUE
);
5439 // -----------------------------------------------------------------------
5441 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5442 wxArrayString
* unmatched
) const
5449 for ( i
=0; i
< strings
.size(); i
++ )
5451 const wxString
& str
= strings
[i
];
5452 int index
= Index(str
);
5455 else if ( unmatched
)
5456 unmatched
->Add(str
);
5463 // -----------------------------------------------------------------------
5465 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5469 if ( data
!= wxPGChoicesEmptyData
)
5476 // -----------------------------------------------------------------------
5478 void wxPGChoices::Init()
5480 m_data
= wxPGChoicesEmptyData
;
5483 // -----------------------------------------------------------------------
5485 void wxPGChoices::Free()
5487 if ( m_data
!= wxPGChoicesEmptyData
)
5490 m_data
= wxPGChoicesEmptyData
;
5494 // -----------------------------------------------------------------------
5495 // wxPropertyGridEvent
5496 // -----------------------------------------------------------------------
5498 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5501 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5502 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5503 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5504 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5505 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5506 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5507 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5508 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5509 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5512 // -----------------------------------------------------------------------
5514 void wxPropertyGridEvent::Init()
5516 m_validationInfo
= NULL
;
5518 m_wasVetoed
= false;
5521 // -----------------------------------------------------------------------
5523 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5524 : wxCommandEvent(commandType
,id
)
5530 // -----------------------------------------------------------------------
5532 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5533 : wxCommandEvent(event
)
5535 m_eventType
= event
.GetEventType();
5536 m_eventObject
= event
.m_eventObject
;
5538 m_property
= event
.m_property
;
5539 m_validationInfo
= event
.m_validationInfo
;
5540 m_canVeto
= event
.m_canVeto
;
5541 m_wasVetoed
= event
.m_wasVetoed
;
5544 // -----------------------------------------------------------------------
5546 wxPropertyGridEvent::~wxPropertyGridEvent()
5550 // -----------------------------------------------------------------------
5552 wxEvent
* wxPropertyGridEvent::Clone() const
5554 return new wxPropertyGridEvent( *this );
5557 // -----------------------------------------------------------------------
5558 // wxPropertyGridPopulator
5559 // -----------------------------------------------------------------------
5561 wxPropertyGridPopulator::wxPropertyGridPopulator()
5565 wxPGGlobalVars
->m_offline
++;
5568 // -----------------------------------------------------------------------
5570 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5573 m_propHierarchy
.clear();
5576 // -----------------------------------------------------------------------
5578 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5584 // -----------------------------------------------------------------------
5586 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5589 // Free unused sets of choices
5590 wxPGHashMapS2P::iterator it
;
5592 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5594 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5601 m_pg
->GetPanel()->Refresh();
5603 wxPGGlobalVars
->m_offline
--;
5606 // -----------------------------------------------------------------------
5608 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5609 const wxString
& propLabel
,
5610 const wxString
& propName
,
5611 const wxString
* propValue
,
5612 wxPGChoices
* pChoices
)
5614 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5615 wxPGProperty
* parent
= GetCurParent();
5617 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5619 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5623 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5625 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5629 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5631 property
->SetLabel(propLabel
);
5632 property
->DoSetName(propName
);
5634 if ( pChoices
&& pChoices
->IsOk() )
5635 property
->SetChoices(*pChoices
);
5637 m_state
->DoInsert(parent
, -1, property
);
5640 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5641 wxPG_PROGRAMMATIC_VALUE
);
5646 // -----------------------------------------------------------------------
5648 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5650 m_propHierarchy
.push_back(property
);
5651 DoScanForChildren();
5652 m_propHierarchy
.pop_back();
5655 // -----------------------------------------------------------------------
5657 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5658 const wxString
& idString
)
5660 wxPGChoices choices
;
5663 if ( choicesString
[0] == wxT('@') )
5665 wxString ids
= choicesString
.substr(1);
5666 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5667 if ( it
== m_dictIdChoices
.end() )
5668 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5670 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5675 if ( idString
.length() )
5677 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5678 if ( it
!= m_dictIdChoices
.end() )
5680 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5687 // Parse choices string
5688 wxString::const_iterator it
= choicesString
.begin();
5692 bool labelValid
= false;
5694 for ( ; it
!= choicesString
.end(); ++it
)
5700 if ( c
== wxT('"') )
5705 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5706 choices
.Add(label
, l
);
5709 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5714 else if ( c
== wxT('=') )
5721 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5728 if ( c
== wxT('"') )
5741 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5742 choices
.Add(label
, l
);
5745 if ( !choices
.IsOk() )
5747 choices
.EnsureData();
5751 if ( idString
.length() )
5752 m_dictIdChoices
[idString
] = choices
.GetData();
5759 // -----------------------------------------------------------------------
5761 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5763 if ( s
.Last() == wxT('%') )
5765 wxString s2
= s
.substr(0,s
.length()-1);
5767 if ( s2
.ToLong(&val
, 10) )
5769 *pval
= (val
*max
)/100;
5775 return s
.ToLong(pval
, 10);
5778 // -----------------------------------------------------------------------
5780 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5781 const wxString
& type
,
5782 const wxString
& value
)
5784 int l
= m_propHierarchy
.size();
5788 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5789 wxString valuel
= value
.Lower();
5792 if ( type
.length() == 0 )
5797 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5799 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5801 else if ( value
.ToLong(&v
, 0) )
5808 if ( type
== wxT("string") )
5812 else if ( type
== wxT("int") )
5815 value
.ToLong(&v
, 0);
5818 else if ( type
== wxT("bool") )
5820 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5827 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5832 p
->SetAttribute( name
, variant
);
5837 // -----------------------------------------------------------------------
5839 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5841 wxLogError(_("Error in resource: %s"),msg
.c_str());
5844 // -----------------------------------------------------------------------
5846 #endif // wxUSE_PROPGRID