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 operations
1190 // -----------------------------------------------------------------------
1192 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1194 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1198 bool changed
= false;
1200 // Is it inside collapsed section?
1201 if ( !p
->IsVisible() )
1204 wxPGProperty
* parent
= p
->GetParent();
1205 wxPGProperty
* grandparent
= parent
->GetParent();
1207 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1208 Expand( grandparent
);
1216 GetViewStart(&vx
,&vy
);
1217 vy
*=wxPG_PIXELS_PER_UNIT
;
1223 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1224 m_iFlags
|= wxPG_FL_SCROLLED
;
1227 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1229 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1230 m_iFlags
|= wxPG_FL_SCROLLED
;
1240 // -----------------------------------------------------------------------
1241 // wxPropertyGrid helper methods called by properties
1242 // -----------------------------------------------------------------------
1244 // Control font changer helper.
1245 void wxPropertyGrid::SetCurControlBoldFont()
1247 wxASSERT( m_wndEditor
);
1248 m_wndEditor
->SetFont( m_captionFont
);
1251 // -----------------------------------------------------------------------
1253 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1256 #if wxPG_SMALL_SCREEN
1257 // On small-screen devices, always show dialogs with default position and size.
1258 return wxDefaultPosition
;
1260 int splitterX
= GetSplitterPosition();
1264 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1266 ImprovedClientToScreen( &x
, &y
);
1268 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1269 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1276 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1286 new_y
= y
+ m_lineHeight
;
1288 return wxPoint(new_x
,new_y
);
1292 // -----------------------------------------------------------------------
1294 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1296 if ( src_str
.length() == 0 )
1302 bool prev_is_slash
= false;
1304 wxString::const_iterator i
= src_str
.begin();
1308 for ( ; i
!= src_str
.end(); ++i
)
1312 if ( a
!= wxS('\\') )
1314 if ( !prev_is_slash
)
1320 if ( a
== wxS('n') )
1323 dst_str
<< wxS('\n');
1325 dst_str
<< wxS('\n');
1328 else if ( a
== wxS('t') )
1329 dst_str
<< wxS('\t');
1333 prev_is_slash
= false;
1337 if ( prev_is_slash
)
1339 dst_str
<< wxS('\\');
1340 prev_is_slash
= false;
1344 prev_is_slash
= true;
1351 // -----------------------------------------------------------------------
1353 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1355 if ( src_str
.length() == 0 )
1361 wxString::const_iterator i
= src_str
.begin();
1362 wxUniChar prev_a
= wxS('\0');
1366 for ( ; i
!= src_str
.end(); ++i
)
1370 if ( a
>= wxS(' ') )
1372 // This surely is not something that requires an escape sequence.
1377 // This might need...
1378 if ( a
== wxS('\r') )
1380 // DOS style line end.
1381 // Already taken care below
1383 else if ( a
== wxS('\n') )
1384 // UNIX style line end.
1385 dst_str
<< wxS("\\n");
1386 else if ( a
== wxS('\t') )
1388 dst_str
<< wxS('\t');
1391 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1401 // -----------------------------------------------------------------------
1403 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1407 return (wxPGProperty
*) NULL
;
1410 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1413 // -----------------------------------------------------------------------
1414 // wxPropertyGrid graphics related methods
1415 // -----------------------------------------------------------------------
1417 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1421 // Update everything inside the box
1422 wxRect r
= GetUpdateRegion().GetBox();
1424 dc
.SetPen(m_colEmptySpace
);
1425 dc
.SetBrush(m_colEmptySpace
);
1426 dc
.DrawRectangle(r
);
1429 // -----------------------------------------------------------------------
1431 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1432 wxPGProperty
* property
) const
1434 // Prepare rectangle to be used
1436 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1437 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1439 #if (wxPG_USE_RENDERER_NATIVE)
1441 #elif wxPG_ICON_WIDTH
1442 // Drawing expand/collapse button manually
1443 dc
.SetPen(m_colPropFore
);
1444 if ( property
->IsCategory() )
1445 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1447 dc
.SetBrush(m_colPropBack
);
1449 dc
.DrawRectangle( r
);
1450 int _y
= r
.y
+(m_iconWidth
/2);
1451 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1456 if ( property
->IsExpanded() )
1458 // wxRenderer functions are non-mutating in nature, so it
1459 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1460 // Hopefully this does not cause problems.
1461 #if (wxPG_USE_RENDERER_NATIVE)
1462 wxRendererNative::Get().DrawTreeItemButton(
1468 #elif wxPG_ICON_WIDTH
1477 #if (wxPG_USE_RENDERER_NATIVE)
1478 wxRendererNative::Get().DrawTreeItemButton(
1484 #elif wxPG_ICON_WIDTH
1485 int _x
= r
.x
+(m_iconWidth
/2);
1486 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1492 #if (wxPG_USE_RENDERER_NATIVE)
1494 #elif wxPG_ICON_WIDTH
1497 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1501 // -----------------------------------------------------------------------
1504 // This is the one called by OnPaint event handler and others.
1505 // topy and bottomy are already unscrolled (ie. physical)
1507 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1509 unsigned int bottomy
,
1510 const wxRect
* clipRect
)
1512 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1514 m_pState
->EnsureVirtualHeight();
1516 wxRect tempClipRect
;
1519 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1520 clipRect
= &tempClipRect
;
1523 // items added check
1524 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1526 int paintFinishY
= 0;
1528 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1531 bool isBuffered
= false;
1533 #if wxPG_DOUBLE_BUFFER
1534 wxMemoryDC
* bufferDC
= NULL
;
1536 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1538 if ( !m_doubleBuffer
)
1540 paintFinishY
= clipRect
->y
;
1545 bufferDC
= new wxMemoryDC();
1547 // If nothing was changed, then just copy from double-buffer
1548 bufferDC
->SelectObject( *m_doubleBuffer
);
1558 dc
.SetClippingRegion( *clipRect
);
1559 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1562 #if wxPG_DOUBLE_BUFFER
1565 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1566 bufferDC
, 0, 0, wxCOPY
);
1567 dc
.DestroyClippingRegion(); // Is this really necessary?
1573 // Clear area beyond bottomY?
1574 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1576 dc
.SetPen(m_colEmptySpace
);
1577 dc
.SetBrush(m_colEmptySpace
);
1578 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1582 // -----------------------------------------------------------------------
1584 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1585 const wxPGProperty
* firstItem
,
1586 const wxPGProperty
* lastItem
,
1587 const wxRect
* clipRect
,
1588 bool isBuffered
) const
1590 // TODO: This should somehow be eliminated.
1591 wxRect tempClipRect
;
1594 wxASSERT(firstItem
);
1596 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1597 clipRect
= &tempClipRect
;
1601 firstItem
= DoGetItemAtY(clipRect
->y
);
1605 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1607 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1610 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1613 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1614 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1616 int lh
= m_lineHeight
;
1619 int lastItemBottomY
;
1621 firstItemTopY
= clipRect
->y
;
1622 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1624 // Align y coordinates to item boundaries
1625 firstItemTopY
-= firstItemTopY
% lh
;
1626 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1627 lastItemBottomY
-= 1;
1629 // Entire range outside scrolled, visible area?
1630 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1633 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1637 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1638 firstItem->GetLabel().c_str(),
1639 lastItem->GetLabel().c_str(),
1640 (int)(lastItemBottomY - firstItemTopY),
1642 (unsigned long)clipRect );
1647 long windowStyle
= m_windowStyle
;
1653 // With wxPG_DOUBLE_BUFFER, do double buffering
1654 // - buffer's y = 0, so align cliprect and coordinates to that
1656 #if wxPG_DOUBLE_BUFFER
1662 xRelMod
= clipRect
->x
;
1663 yRelMod
= clipRect
->y
;
1666 // clipRect conversion
1671 firstItemTopY
-= yRelMod
;
1672 lastItemBottomY
-= yRelMod
;
1675 wxUnusedVar(isBuffered
);
1678 int x
= m_marginWidth
- xRelMod
;
1680 const wxFont
& normalfont
= m_font
;
1682 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1684 bool isEnabled
= IsEnabled();
1687 // Prepare some pens and brushes that are often changed to.
1690 wxBrush
marginBrush(m_colMargin
);
1691 wxPen
marginPen(m_colMargin
);
1692 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1693 wxPen
linepen(m_colLine
,1,wxSOLID
);
1695 // pen that has same colour as text
1696 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1699 // Clear margin with background colour
1701 dc
.SetBrush( marginBrush
);
1702 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1704 dc
.SetPen( *wxTRANSPARENT_PEN
);
1705 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1708 const wxPGProperty
* selected
= m_selected
;
1709 const wxPropertyGridPageState
* state
= m_pState
;
1711 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1712 bool wasSelectedPainted
= false;
1715 // TODO: Only render columns that are within clipping region.
1717 dc
.SetFont(normalfont
);
1719 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1720 int endScanBottomY
= lastItemBottomY
+ lh
;
1721 int y
= firstItemTopY
;
1724 // Pregenerate list of visible properties.
1725 wxArrayPGProperty visPropArray
;
1726 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1728 for ( ; !it
.AtEnd(); it
.Next() )
1730 const wxPGProperty
* p
= *it
;
1732 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1734 visPropArray
.push_back((wxPGProperty
*)p
);
1736 if ( y
> endScanBottomY
)
1743 visPropArray
.push_back(NULL
);
1745 wxPGProperty
* nextP
= visPropArray
[0];
1747 int gridWidth
= state
->m_width
;
1750 for ( unsigned int arrInd
=1;
1751 nextP
&& y
<= lastItemBottomY
;
1754 wxPGProperty
* p
= nextP
;
1755 nextP
= visPropArray
[arrInd
];
1757 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1758 int textMarginHere
= x
;
1759 int renderFlags
= 0;
1761 int greyDepth
= m_marginWidth
;
1762 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1763 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1765 int greyDepthX
= greyDepth
- xRelMod
;
1767 // Use basic depth if in non-categoric mode and parent is base array.
1768 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1770 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1773 // Paint margin area
1774 dc
.SetBrush(marginBrush
);
1775 dc
.SetPen(marginPen
);
1776 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1778 dc
.SetPen( linepen
);
1783 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1789 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1791 sx
+= state
->m_colWidths
[si
];
1792 dc
.DrawLine( sx
, y
, sx
, y2
);
1795 // Horizontal Line, below
1796 // (not if both this and next is category caption)
1797 if ( p
->IsCategory() &&
1798 nextP
&& nextP
->IsCategory() )
1799 dc
.SetPen(m_colCapBack
);
1801 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1804 // Need to override row colours?
1808 if ( p
!= selected
)
1810 // Disabled may get different colour.
1811 if ( !p
->IsEnabled() )
1813 renderFlags
|= wxPGCellRenderer::Disabled
|
1814 wxPGCellRenderer::DontUseCellFgCol
;
1815 rowFgCol
= m_colDisPropFore
;
1820 renderFlags
|= wxPGCellRenderer::Selected
;
1822 if ( !p
->IsCategory() )
1824 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1825 wxPGCellRenderer::DontUseCellBgCol
;
1827 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1828 wasSelectedPainted
= true;
1831 // Selected gets different colour.
1832 if ( reallyFocused
)
1834 rowFgCol
= m_colSelFore
;
1835 rowBgCol
= m_colSelBack
;
1837 else if ( isEnabled
)
1839 rowFgCol
= m_colPropFore
;
1840 rowBgCol
= m_colMargin
;
1844 rowFgCol
= m_colDisPropFore
;
1845 rowBgCol
= m_colSelBack
;
1852 if ( rowBgCol
.IsOk() )
1853 rowBgBrush
= wxBrush(rowBgCol
);
1855 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1856 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1859 // Fill additional margin area with background colour of first cell
1860 if ( greyDepthX
< textMarginHere
)
1862 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1864 wxPGCell
& cell
= p
->GetCell(0);
1865 rowBgCol
= cell
.GetBgCol();
1866 rowBgBrush
= wxBrush(rowBgCol
);
1868 dc
.SetBrush(rowBgBrush
);
1869 dc
.SetPen(rowBgCol
);
1870 dc
.DrawRectangle(greyDepthX
+1, y
,
1871 textMarginHere
-greyDepthX
, lh
-1);
1874 bool fontChanged
= false;
1876 // Expander button rectangle
1877 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1882 if ( p
->IsCategory() )
1884 // Captions have their cell areas merged as one
1885 dc
.SetFont(m_captionFont
);
1887 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1889 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1891 dc
.SetBrush(rowBgBrush
);
1892 dc
.SetPen(rowBgCol
);
1895 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1897 dc
.SetTextForeground(rowFgCol
);
1900 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1901 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1904 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1905 DrawExpanderButton( dc
, butRect
, p
);
1909 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1911 dc
.SetFont(m_captionFont
);
1917 int nextCellWidth
= state
->m_colWidths
[0];
1918 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1919 int textXAdd
= textMarginHere
- greyDepthX
;
1921 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1923 cellRect
.width
= nextCellWidth
- 1;
1925 bool ctrlCell
= false;
1926 int cellRenderFlags
= renderFlags
;
1929 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1930 DrawExpanderButton( dc
, butRect
, p
);
1933 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1935 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1936 dc
.SetBrush(editorBgCol
);
1937 dc
.SetPen(editorBgCol
);
1938 dc
.SetTextForeground(m_colPropFore
);
1939 dc
.DrawRectangle(cellRect
);
1941 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1946 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1948 dc
.SetBrush(rowBgBrush
);
1949 dc
.SetPen(rowBgCol
);
1952 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1954 dc
.SetTextForeground(rowFgCol
);
1958 dc
.SetClippingRegion(cellRect
);
1960 cellRect
.x
+= textXAdd
;
1961 cellRect
.width
-= textXAdd
;
1966 wxPGCellRenderer
* renderer
;
1967 int cmnVal
= p
->GetCommonValue();
1968 if ( cmnVal
== -1 || ci
!= 1 )
1970 renderer
= p
->GetCellRenderer(ci
);
1971 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1976 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1977 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1982 cellX
+= state
->m_colWidths
[ci
];
1983 if ( ci
< (state
->m_colWidths
.size()-1) )
1984 nextCellWidth
= state
->m_colWidths
[ci
+1];
1986 dc
.DestroyClippingRegion(); // Is this really necessary?
1992 dc
.SetFont(normalfont
);
1997 // Refresh editor controls (seems not needed on msw)
1998 // NOTE: This code is mandatory for GTK!
1999 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2000 if ( wasSelectedPainted
)
2003 m_wndEditor
->Refresh();
2005 m_wndEditor2
->Refresh();
2012 // -----------------------------------------------------------------------
2014 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2018 if ( m_width
< 10 || m_height
< 10 ||
2019 !m_pState
->m_properties
->GetChildCount() ||
2020 p1
== (wxPGProperty
*) NULL
)
2021 return wxRect(0,0,0,0);
2026 // Return rect which encloses the given property range
2028 int visTop
= p1
->GetY();
2031 visBottom
= p2
->GetY() + m_lineHeight
;
2033 visBottom
= m_height
+ visTop
;
2035 // If seleced property is inside the range, we'll extend the range to include
2037 wxPGProperty
* selected
= m_selected
;
2040 int selectedY
= selected
->GetY();
2041 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2043 wxWindow
* editor
= GetEditorControl();
2046 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2047 if ( visBottom2
> visBottom
)
2048 visBottom
= visBottom2
;
2053 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2056 // -----------------------------------------------------------------------
2058 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2063 if ( m_pState
->m_itemsAdded
)
2064 PrepareAfterItemsAdded();
2066 wxRect r
= GetPropertyRect(p1
, p2
);
2069 m_canvas
->RefreshRect(r
);
2073 // -----------------------------------------------------------------------
2075 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2077 if ( p
== m_selected
)
2078 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2080 DrawItemAndChildren(p
);
2083 // -----------------------------------------------------------------------
2085 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2090 // Draw item, children, and parent too, if it is not category
2091 wxPGProperty
* parent
= p
->GetParent();
2094 !parent
->IsCategory() &&
2095 parent
->GetParent() )
2098 parent
= parent
->GetParent();
2101 DrawItemAndChildren(p
);
2104 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2106 wxCHECK_RET( p
, wxT("invalid property id") );
2108 // Do not draw if in non-visible page
2109 if ( p
->GetParentState() != m_pState
)
2112 // do not draw a single item if multiple pending
2113 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2116 // Update child control.
2117 if ( m_selected
&& m_selected
->GetParent() == p
)
2120 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2122 DrawItems(p
, lastDrawn
);
2125 // -----------------------------------------------------------------------
2127 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2128 const wxRect
*rect
)
2130 PrepareAfterItemsAdded();
2132 wxWindow::Refresh(false);
2134 // TODO: Coordinate translation
2135 m_canvas
->Refresh(false, rect
);
2137 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2138 // I think this really helps only GTK+1.2
2139 if ( m_wndEditor
) m_wndEditor
->Refresh();
2140 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2144 // -----------------------------------------------------------------------
2145 // wxPropertyGrid global operations
2146 // -----------------------------------------------------------------------
2148 void wxPropertyGrid::Clear()
2150 ClearSelection(false);
2152 m_pState
->DoClear();
2158 RecalculateVirtualSize();
2160 // Need to clear some area at the end
2162 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2165 // -----------------------------------------------------------------------
2167 bool wxPropertyGrid::EnableCategories( bool enable
)
2169 ClearSelection(false);
2174 // Enable categories
2177 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2182 // Disable categories
2184 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2187 if ( !m_pState
->EnableCategories(enable
) )
2192 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2194 m_pState
->m_itemsAdded
= 1; // force
2195 PrepareAfterItemsAdded();
2199 m_pState
->m_itemsAdded
= 1;
2201 // No need for RecalculateVirtualSize() here - it is already called in
2202 // wxPropertyGridPageState method above.
2209 // -----------------------------------------------------------------------
2211 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2213 wxASSERT( pNewState
);
2214 wxASSERT( pNewState
->GetGrid() );
2216 if ( pNewState
== m_pState
)
2219 wxPGProperty
* oldSelection
= m_selected
;
2221 ClearSelection(false);
2223 m_pState
->m_selected
= oldSelection
;
2225 bool orig_mode
= m_pState
->IsInNonCatMode();
2226 bool new_state_mode
= pNewState
->IsInNonCatMode();
2228 m_pState
= pNewState
;
2231 int pgWidth
= GetClientSize().x
;
2232 if ( HasVirtualWidth() )
2234 int minWidth
= pgWidth
;
2235 if ( pNewState
->m_width
< minWidth
)
2237 pNewState
->m_width
= minWidth
;
2238 pNewState
->CheckColumnWidths();
2244 // Just in case, fully re-center splitter
2245 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2246 pNewState
->m_fSplitterX
= -1.0;
2248 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2251 m_propHover
= (wxPGProperty
*) NULL
;
2253 // If necessary, convert state to correct mode.
2254 if ( orig_mode
!= new_state_mode
)
2256 // This should refresh as well.
2257 EnableCategories( orig_mode
?false:true );
2259 else if ( !m_frozen
)
2261 // Refresh, if not frozen.
2262 m_pState
->PrepareAfterItemsAdded();
2265 if ( m_pState
->m_selected
)
2266 DoSelectProperty( m_pState
->m_selected
);
2268 RecalculateVirtualSize(0);
2272 m_pState
->m_itemsAdded
= 1;
2275 // -----------------------------------------------------------------------
2277 // Call to SetSplitterPosition will always disable splitter auto-centering
2278 // if parent window is shown.
2279 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2281 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2284 wxPropertyGridPageState
* state
= m_pState
;
2286 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2291 CorrectEditorWidgetSizeX();
2297 // -----------------------------------------------------------------------
2299 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2301 SetSplitterPosition( m_width
/2, true );
2302 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2303 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2306 // -----------------------------------------------------------------------
2307 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2308 // -----------------------------------------------------------------------
2310 // Returns nearest paint visible property (such that will be painted unless
2311 // window is scrolled or resized). If given property is paint visible, then
2312 // it itself will be returned
2313 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2315 int vx
,vy1
;// Top left corner of client
2316 GetViewStart(&vx
,&vy1
);
2317 vy1
*= wxPG_PIXELS_PER_UNIT
;
2319 int vy2
= vy1
+ m_height
;
2320 int propY
= p
->GetY2(m_lineHeight
);
2322 if ( (propY
+ m_lineHeight
) < vy1
)
2325 return DoGetItemAtY( vy1
);
2327 else if ( propY
> vy2
)
2330 return DoGetItemAtY( vy2
);
2333 // Itself paint visible
2338 // -----------------------------------------------------------------------
2339 // Methods related to change in value, value modification and sending events
2340 // -----------------------------------------------------------------------
2342 // commits any changes in editor of selected property
2343 // return true if validation did not fail
2344 // flags are same as with DoSelectProperty
2345 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2347 // Committing already?
2348 if ( m_inCommitChangesFromEditor
)
2351 // Don't do this if already processing editor event. It might
2352 // induce recursive dialogs and crap like that.
2353 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2355 if ( m_inDoPropertyChanged
)
2362 IsEditorsValueModified() &&
2363 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2366 m_inCommitChangesFromEditor
= 1;
2368 wxVariant
variant(m_selected
->GetValueRef());
2369 bool valueIsPending
= false;
2371 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2372 // due to another window getting focus
2373 wxWindow
* oldFocus
= m_curFocused
;
2375 bool validationFailure
= false;
2376 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2378 m_chgInfo_changedProperty
= NULL
;
2380 // If truly modified, schedule value as pending.
2381 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2383 if ( DoEditorValidate() &&
2384 PerformValidation(m_selected
, variant
) )
2386 valueIsPending
= true;
2390 validationFailure
= true;
2395 EditorsValueWasNotModified();
2400 m_inCommitChangesFromEditor
= 0;
2402 if ( validationFailure
&& !forceSuccess
)
2406 oldFocus
->SetFocus();
2407 m_curFocused
= oldFocus
;
2410 res
= OnValidationFailure(m_selected
, variant
);
2412 // Now prevent further validation failure messages
2415 EditorsValueWasNotModified();
2416 OnValidationFailureReset(m_selected
);
2419 else if ( valueIsPending
)
2421 DoPropertyChanged( m_selected
, flags
);
2422 EditorsValueWasNotModified();
2431 // -----------------------------------------------------------------------
2433 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2437 // Runs all validation functionality.
2438 // Returns true if value passes all tests.
2441 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2443 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2445 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2450 // Adapt list to child values, if necessary
2451 wxVariant listValue
= pendingValue
;
2452 wxVariant
* pPendingValue
= &pendingValue
;
2453 wxVariant
* pList
= NULL
;
2455 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2456 // string value, then we need treat as it was changed instead
2457 // (or, in addition, as is the case with composite string parent).
2458 // This includes creating list variant for child values.
2460 wxPGProperty
* pwc
= p
->GetParent();
2461 wxPGProperty
* changedProperty
= p
;
2462 wxPGProperty
* baseChangedProperty
= changedProperty
;
2463 wxVariant bcpPendingList
;
2465 listValue
= pendingValue
;
2466 listValue
.SetName(p
->GetBaseName());
2469 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2471 wxVariantList tempList
;
2472 wxVariant
lv(tempList
, pwc
->GetBaseName());
2473 lv
.Append(listValue
);
2475 pPendingValue
= &listValue
;
2477 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2479 baseChangedProperty
= pwc
;
2480 bcpPendingList
= lv
;
2483 changedProperty
= pwc
;
2484 pwc
= pwc
->GetParent();
2488 wxPGProperty
* evtChangingProperty
= changedProperty
;
2490 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2492 value
= *pPendingValue
;
2496 // Convert list to child values
2497 pList
= pPendingValue
;
2498 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2501 wxVariant evtChangingValue
= value
;
2503 if ( flags
& SendEvtChanging
)
2505 // FIXME: After proper ValueToString()s added, remove
2506 // this. It is just a temporary fix, as evt_changing
2507 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2508 // (unless it is selected, and textctrl editor is open).
2509 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2511 evtChangingProperty
= baseChangedProperty
;
2512 if ( evtChangingProperty
!= p
)
2514 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2518 evtChangingValue
= pendingValue
;
2522 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2524 if ( changedProperty
== m_selected
)
2526 wxWindow
* editor
= GetEditorControl();
2527 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2528 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2532 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2537 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2538 m_chgInfo_changedProperty
= changedProperty
;
2539 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2540 m_chgInfo_pendingValue
= value
;
2543 m_chgInfo_valueList
= *pList
;
2545 m_chgInfo_valueList
.MakeNull();
2547 // If changedProperty is not property which value was edited,
2548 // then call wxPGProperty::ValidateValue() for that as well.
2549 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2551 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2555 if ( flags
& SendEvtChanging
)
2557 // SendEvent returns true if event was vetoed
2558 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2562 if ( flags
& IsStandaloneValidation
)
2564 // If called in 'generic' context, we need to reset
2565 // m_chgInfo_changedProperty and write back translated value.
2566 m_chgInfo_changedProperty
= NULL
;
2567 pendingValue
= value
;
2573 // -----------------------------------------------------------------------
2575 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2577 if ( !msg
.length() )
2581 if ( !wxPGGlobalVars
->m_offline
)
2583 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2586 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2589 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2592 pStatusBar
->SetStatusText(msg
);
2600 ::wxMessageBox(msg
, _T("Property Error"));
2603 // -----------------------------------------------------------------------
2605 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2607 int vfb
= m_validationInfo
.m_failureBehavior
;
2609 if ( vfb
& wxPG_VFB_BEEP
)
2612 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2613 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2615 unsigned int colCount
= m_pState
->GetColumnCount();
2617 // We need backup marked property's cells
2618 m_propCellsBackup
= property
->m_cells
;
2620 wxColour vfbFg
= *wxWHITE
;
2621 wxColour vfbBg
= *wxRED
;
2623 property
->EnsureCells(colCount
);
2625 for ( unsigned int i
=0; i
<colCount
; i
++ )
2627 wxPGCell
& cell
= property
->m_cells
[i
];
2628 cell
.SetFgCol(vfbFg
);
2629 cell
.SetBgCol(vfbBg
);
2632 DrawItemAndChildren(property
);
2634 if ( property
== m_selected
)
2636 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2638 wxWindow
* editor
= GetEditorControl();
2641 editor
->SetForegroundColour(vfbFg
);
2642 editor
->SetBackgroundColour(vfbBg
);
2647 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2649 wxString msg
= m_validationInfo
.m_failureMessage
;
2651 if ( !msg
.length() )
2652 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2654 DoShowPropertyError(property
, msg
);
2657 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2660 // -----------------------------------------------------------------------
2662 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2664 int vfb
= m_validationInfo
.m_failureBehavior
;
2666 if ( vfb
& wxPG_VFB_MARK_CELL
)
2669 property
->m_cells
= m_propCellsBackup
;
2671 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2673 if ( property
== m_selected
&& GetEditorControl() )
2675 // Calling this will recreate the control, thus resetting its colour
2676 RefreshProperty(property
);
2680 DrawItemAndChildren(property
);
2685 // -----------------------------------------------------------------------
2687 // flags are same as with DoSelectProperty
2688 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2690 if ( m_inDoPropertyChanged
)
2693 wxWindow
* editor
= GetEditorControl();
2695 m_pState
->m_anyModified
= 1;
2697 m_inDoPropertyChanged
= 1;
2699 // Maybe need to update control
2700 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2702 // These values were calculated in PerformValidation()
2703 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2704 wxVariant value
= m_chgInfo_pendingValue
;
2706 wxPGProperty
* topPaintedProperty
= changedProperty
;
2708 while ( !topPaintedProperty
->IsCategory() &&
2709 !topPaintedProperty
->IsRoot() )
2711 topPaintedProperty
= topPaintedProperty
->GetParent();
2714 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2716 // Set as Modified (not if dragging just began)
2717 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2719 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2720 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2723 SetCurControlBoldFont();
2729 // Propagate updates to parent(s)
2731 wxPGProperty
* prevPwc
= NULL
;
2733 while ( prevPwc
!= topPaintedProperty
)
2735 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2737 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2740 SetCurControlBoldFont();
2744 pwc
= pwc
->GetParent();
2747 // Draw the actual property
2748 DrawItemAndChildren( topPaintedProperty
);
2751 // If value was set by wxPGProperty::OnEvent, then update the editor
2753 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2759 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2760 if ( m_wndEditor
) m_wndEditor
->Refresh();
2761 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2766 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2768 // If top parent has composite string value, then send to child parents,
2769 // starting from baseChangedProperty.
2770 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2772 pwc
= m_chgInfo_baseChangedProperty
;
2774 while ( pwc
!= changedProperty
)
2776 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2777 pwc
= pwc
->GetParent();
2781 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2783 m_inDoPropertyChanged
= 0;
2788 // -----------------------------------------------------------------------
2790 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2792 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2794 m_chgInfo_changedProperty
= NULL
;
2796 if ( PerformValidation(p
, newValue
) )
2798 DoPropertyChanged(p
);
2803 OnValidationFailure(p
, newValue
);
2809 // -----------------------------------------------------------------------
2811 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2813 wxPGProperty
* prop
= GetSelectedProperty();
2816 return wxNullVariant
;
2818 wxTextCtrl
* tc
= GetEditorTextCtrl();
2819 wxVariant value
= prop
->GetValue();
2821 if ( !tc
|| !IsEditorsValueModified() )
2824 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2827 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2828 return prop
->GetValue();
2833 // -----------------------------------------------------------------------
2835 // Runs wxValidator for the selected property
2836 bool wxPropertyGrid::DoEditorValidate()
2841 // -----------------------------------------------------------------------
2843 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2845 wxPGProperty
* selected
= m_selected
;
2847 // Somehow, event is handled after property has been deselected.
2848 // Possibly, but very rare.
2852 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2855 wxVariant
pendingValue(selected
->GetValueRef());
2856 wxWindow
* wnd
= GetEditorControl();
2858 bool wasUnspecified
= selected
->IsValueUnspecified();
2859 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2861 bool valueIsPending
= false;
2863 m_chgInfo_changedProperty
= NULL
;
2865 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2868 // Filter out excess wxTextCtrl modified events
2869 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2871 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2873 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2875 wxString newTcValue
= tc
->GetValue();
2876 if ( m_prevTcValue
== newTcValue
)
2879 m_prevTcValue
= newTcValue
;
2882 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2884 bool validationFailure
= false;
2885 bool buttonWasHandled
= false;
2888 // Try common button handling
2889 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2891 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2895 buttonWasHandled
= true;
2896 // Store as res2, as previously (and still currently alternatively)
2897 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2898 // in wxPGProperty::OnEvent().
2899 adapter
->ShowDialog( this, selected
);
2904 if ( !buttonWasHandled
)
2908 // First call editor class' event handler.
2909 const wxPGEditor
* editor
= selected
->GetEditorClass();
2911 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2913 // If changes, validate them
2914 if ( DoEditorValidate() )
2916 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
2917 valueIsPending
= true;
2921 validationFailure
= true;
2926 // Then the property's custom handler (must be always called, unless
2927 // validation failed).
2928 if ( !validationFailure
)
2929 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
2932 // SetValueInEvent(), as called in one of the functions referred above
2933 // overrides editor's value.
2934 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2936 valueIsPending
= true;
2937 pendingValue
= m_changeInEventValue
;
2938 selFlags
|= wxPG_SEL_DIALOGVAL
;
2941 if ( !validationFailure
&& valueIsPending
)
2942 if ( !PerformValidation(m_selected
, pendingValue
) )
2943 validationFailure
= true;
2945 if ( validationFailure
)
2947 OnValidationFailure(selected
, pendingValue
);
2949 else if ( valueIsPending
)
2951 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2953 DoPropertyChanged(selected
, selFlags
);
2954 EditorsValueWasNotModified();
2956 // Regardless of editor type, unfocus editor on
2957 // text-editing related enter press.
2958 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2965 // No value after all
2967 // Regardless of editor type, unfocus editor on
2968 // text-editing related enter press.
2969 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
2974 // Let unhandled button click events go to the parent
2975 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2977 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
2978 GetEventHandler()->AddPendingEvent(evt
);
2982 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2985 // -----------------------------------------------------------------------
2986 // wxPropertyGrid editor control helper methods
2987 // -----------------------------------------------------------------------
2989 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
2991 int itemy
= p
->GetY2(m_lineHeight
);
2993 int cust_img_space
= 0;
2994 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
2995 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
2997 // TODO: If custom image detection changes from current, change this.
2998 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3000 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3001 int imwid
= p
->OnMeasureImage().x
;
3002 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3003 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3008 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3010 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3015 // -----------------------------------------------------------------------
3017 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3019 wxSize sz
= GetImageSize(p
, item
);
3020 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3021 wxPG_CUSTOM_IMAGE_SPACINGY
,
3026 // return size of custom paint image
3027 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3029 // If called with NULL property, then return default image
3030 // size for properties that use image.
3032 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3034 wxSize cis
= p
->OnMeasureImage(item
);
3036 int choiceCount
= p
->m_choices
.GetCount();
3037 int comVals
= p
->GetDisplayedCommonValueCount();
3038 if ( item
>= choiceCount
&& comVals
> 0 )
3040 unsigned int cvi
= item
-choiceCount
;
3041 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3043 else if ( item
>= 0 && choiceCount
== 0 )
3044 return wxSize(0, 0);
3049 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3054 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3061 // -----------------------------------------------------------------------
3063 // takes scrolling into account
3064 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3067 GetViewStart(&vx
,&vy
);
3068 vy
*=wxPG_PIXELS_PER_UNIT
;
3069 vx
*=wxPG_PIXELS_PER_UNIT
;
3072 ClientToScreen( px
, py
);
3075 // -----------------------------------------------------------------------
3077 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3080 GetViewStart(&pt2
.x
,&pt2
.y
);
3081 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3082 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3086 return m_pState
->HitTest(pt2
);
3089 // -----------------------------------------------------------------------
3091 // custom set cursor
3092 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3094 if ( type
== m_curcursor
&& !override
) return;
3096 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3098 if ( type
== wxCURSOR_SIZEWE
)
3099 cursor
= m_cursorSizeWE
;
3101 m_canvas
->SetCursor( *cursor
);
3106 // -----------------------------------------------------------------------
3107 // wxPropertyGrid property selection, editor creation
3108 // -----------------------------------------------------------------------
3111 // This class forwards events from property editor controls to wxPropertyGrid.
3112 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3115 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3116 : wxEvtHandler(), m_propGrid(propGrid
)
3120 virtual ~wxPropertyGridEditorEventForwarder()
3125 bool ProcessEvent( wxEvent
& event
)
3130 m_propGrid
->HandleCustomEditorEvent(event
);
3132 return wxEvtHandler::ProcessEvent(event
);
3135 wxPropertyGrid
* m_propGrid
;
3138 // Setups event handling for child control
3139 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3141 wxWindowID id
= argWnd
->GetId();
3143 if ( argWnd
== m_wndEditor
)
3145 argWnd
->Connect(id
, wxEVT_MOTION
,
3146 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3148 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3149 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3151 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3152 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3154 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3155 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3157 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3158 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3160 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3161 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3165 wxPropertyGridEditorEventForwarder
* forwarder
;
3166 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3167 argWnd
->PushEventHandler(forwarder
);
3169 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3170 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3174 void wxPropertyGrid::FreeEditors()
3177 // Return focus back to canvas from children (this is required at least for
3178 // GTK+, which, unlike Windows, clears focus when control is destroyed
3179 // instead of moving it to closest parent).
3180 wxWindow
* focus
= wxWindow::FindFocus();
3183 wxWindow
* parent
= focus
->GetParent();
3186 if ( parent
== m_canvas
)
3191 parent
= parent
->GetParent();
3195 // Do not free editors immediately if processing events
3198 m_wndEditor2
->PopEventHandler(true);
3199 m_wndEditor2
->Hide();
3200 wxPendingDelete
.Append( m_wndEditor2
);
3201 m_wndEditor2
= (wxWindow
*) NULL
;
3206 m_wndEditor
->PopEventHandler(true);
3207 m_wndEditor
->Hide();
3208 wxPendingDelete
.Append( m_wndEditor
);
3209 m_wndEditor
= (wxWindow
*) NULL
;
3213 // Call with NULL to de-select property
3214 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3218 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3219 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3221 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3224 if ( m_inDoSelectProperty
)
3227 m_inDoSelectProperty
= 1;
3229 wxPGProperty
* prev
= m_selected
;
3233 m_inDoSelectProperty
= 0;
3239 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3241 wxPrintf( "None selected\n" );
3244 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3246 wxPrintf( "P = NULL\n" );
3249 // If we are frozen, then just set the values.
3252 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3253 m_editorFocused
= 0;
3256 m_pState
->m_selected
= p
;
3258 // If frozen, always free controls. But don't worry, as Thaw will
3259 // recall SelectProperty to recreate them.
3262 // Prevent any further selection measures in this call
3263 p
= (wxPGProperty
*) NULL
;
3268 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3270 // Only set focus if not deselecting
3273 if ( flags
& wxPG_SEL_FOCUS
)
3277 m_wndEditor
->SetFocus();
3278 m_editorFocused
= 1;
3287 m_inDoSelectProperty
= 0;
3292 // First, deactivate previous
3296 OnValidationFailureReset(m_selected
);
3298 // Must double-check if this is an selected in case of forceswitch
3301 if ( !CommitChangesFromEditor(flags
) )
3303 // Validation has failed, so we can't exit the previous editor
3304 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3305 // _("Invalid Value"),wxOK|wxICON_ERROR);
3306 m_inDoSelectProperty
= 0;
3314 m_selected
= (wxPGProperty
*) NULL
;
3315 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3317 // We need to always fully refresh the grid here
3320 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3321 EditorsValueWasNotModified();
3324 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3327 // Then, activate the one given.
3330 int propY
= p
->GetY2(m_lineHeight
);
3332 int splitterX
= GetSplitterPosition();
3333 m_editorFocused
= 0;
3335 m_pState
->m_selected
= p
;
3336 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3338 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3340 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3343 // Only create editor for non-disabled non-caption
3344 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3346 // do this for non-caption items
3350 // Do we need to paint the custom image, if any?
3351 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3352 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3353 !p
->GetEditorClass()->CanContainCustomImage()
3355 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3357 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3358 wxPoint goodPos
= grect
.GetPosition();
3359 #if wxPG_CREATE_CONTROLS_HIDDEN
3360 int coord_adjust
= m_height
- goodPos
.y
;
3361 goodPos
.y
+= coord_adjust
;
3364 const wxPGEditor
* editor
= p
->GetEditorClass();
3365 wxCHECK_MSG(editor
, false,
3366 wxT("NULL editor class not allowed"));
3368 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3370 wxPGWindowList wndList
= editor
->CreateControls(this,
3375 m_wndEditor
= wndList
.m_primary
;
3376 m_wndEditor2
= wndList
.m_secondary
;
3377 wxWindow
* primaryCtrl
= GetEditorControl();
3380 // Essentially, primaryCtrl == m_wndEditor
3383 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3384 // value is drawn as normal, and m_wndEditor2 is assumed
3385 // to be a right-aligned button that triggers a separate editorCtrl
3390 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3391 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3393 // Set validator, if any
3394 #if wxUSE_VALIDATORS
3395 wxValidator
* validator
= p
->GetValidator();
3397 primaryCtrl
->SetValidator(*validator
);
3400 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3401 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3403 // If it has modified status, use bold font
3404 // (must be done before capturing m_ctrlXAdjust)
3405 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3406 SetCurControlBoldFont();
3409 // Fix TextCtrl indentation
3410 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3411 wxTextCtrl
* tc
= NULL
;
3412 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3413 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3415 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3417 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3420 // Store x relative to splitter (we'll need it).
3421 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3423 // Check if background clear is not necessary
3424 wxPoint pos
= m_wndEditor
->GetPosition();
3425 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3427 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3430 m_wndEditor
->SetSizeHints(3, 3);
3432 #if wxPG_CREATE_CONTROLS_HIDDEN
3433 m_wndEditor
->Show(false);
3434 m_wndEditor
->Freeze();
3436 goodPos
= m_wndEditor
->GetPosition();
3437 goodPos
.y
-= coord_adjust
;
3438 m_wndEditor
->Move( goodPos
);
3441 SetupChildEventHandling(primaryCtrl
);
3443 // Focus and select all (wxTextCtrl, wxComboBox etc)
3444 if ( flags
& wxPG_SEL_FOCUS
)
3446 primaryCtrl
->SetFocus();
3448 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3454 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3455 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3457 // Get proper id for wndSecondary
3458 m_wndSecId
= m_wndEditor2
->GetId();
3459 wxWindowList children
= m_wndEditor2
->GetChildren();
3460 wxWindowList::iterator node
= children
.begin();
3461 if ( node
!= children
.end() )
3462 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3464 m_wndEditor2
->SetSizeHints(3,3);
3466 #if wxPG_CREATE_CONTROLS_HIDDEN
3467 wxRect sec_rect
= m_wndEditor2
->GetRect();
3468 sec_rect
.y
-= coord_adjust
;
3470 // Fine tuning required to fix "oversized"
3471 // button disappearance bug.
3472 if ( sec_rect
.y
< 0 )
3474 sec_rect
.height
+= sec_rect
.y
;
3477 m_wndEditor2
->SetSize( sec_rect
);
3479 m_wndEditor2
->Show();
3481 SetupChildEventHandling(m_wndEditor2
);
3483 // If no primary editor, focus to button to allow
3484 // it to interprete ENTER etc.
3485 // NOTE: Due to problems focusing away from it, this
3486 // has been disabled.
3488 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3489 m_wndEditor2->SetFocus();
3493 if ( flags
& wxPG_SEL_FOCUS
)
3494 m_editorFocused
= 1;
3499 // Make sure focus is in grid canvas (important for wxGTK, at least)
3503 EditorsValueWasNotModified();
3505 // If it's inside collapsed section, expand parent, scroll, etc.
3506 // Also, if it was partially visible, scroll it into view.
3507 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3512 #if wxPG_CREATE_CONTROLS_HIDDEN
3513 m_wndEditor
->Thaw();
3515 m_wndEditor
->Show(true);
3522 // Make sure focus is in grid canvas
3526 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3532 // Show help text in status bar.
3533 // (if found and grid not embedded in manager with help box and
3534 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3537 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3539 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3540 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3542 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3544 statusbar
= frame
->GetStatusBar();
3549 const wxString
* pHelpString
= (const wxString
*) NULL
;
3553 pHelpString
= &p
->GetHelpString();
3554 if ( pHelpString
->length() )
3556 // Set help box text.
3557 statusbar
->SetStatusText( *pHelpString
);
3558 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3562 if ( (!pHelpString
|| !pHelpString
->length()) &&
3563 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3565 // Clear help box - but only if it was written
3566 // by us at previous time.
3567 statusbar
->SetStatusText( m_emptyString
);
3568 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3574 m_inDoSelectProperty
= 0;
3576 // call wx event handler (here so that it also occurs on deselection)
3577 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3582 // -----------------------------------------------------------------------
3584 bool wxPropertyGrid::UnfocusEditor()
3586 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3589 if ( !CommitChangesFromEditor(0) )
3593 DrawItem(m_selected
);
3598 // -----------------------------------------------------------------------
3600 void wxPropertyGrid::RefreshEditor()
3602 wxPGProperty
* p
= m_selected
;
3606 wxWindow
* wnd
= GetEditorControl();
3610 // Set editor font boldness - must do this before
3611 // calling UpdateControl().
3612 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3614 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3615 wnd
->SetFont(GetCaptionFont());
3617 wnd
->SetFont(GetFont());
3620 const wxPGEditor
* editorClass
= p
->GetEditorClass();
3622 editorClass
->UpdateControl(p
, wnd
);
3624 if ( p
->IsValueUnspecified() )
3625 editorClass
->SetValueToUnspecified(p
, wnd
);
3628 // -----------------------------------------------------------------------
3630 // This method is not inline because it called dozens of times
3631 // (i.e. two-arg function calls create smaller code size).
3632 bool wxPropertyGrid::DoClearSelection()
3634 return DoSelectProperty((wxPGProperty
*)NULL
);
3637 // -----------------------------------------------------------------------
3638 // wxPropertyGrid expand/collapse state
3639 // -----------------------------------------------------------------------
3641 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3643 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3645 // If active editor was inside collapsed section, then disable it
3646 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3648 ClearSelection(false);
3651 // Store dont-center-splitter flag 'cause we need to temporarily set it
3652 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3653 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3655 bool res
= m_pState
->DoCollapse(pwc
);
3660 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3662 RecalculateVirtualSize();
3664 // Redraw etc. only if collapsed was visible.
3665 if (pwc
->IsVisible() &&
3667 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3669 // When item is collapsed so that scrollbar would move,
3670 // graphics mess is about (unless we redraw everything).
3675 // Clear dont-center-splitter flag if it wasn't set
3676 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3681 // -----------------------------------------------------------------------
3683 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3685 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3687 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3689 // Store dont-center-splitter flag 'cause we need to temporarily set it
3690 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3691 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3693 bool res
= m_pState
->DoExpand(pwc
);
3698 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3700 RecalculateVirtualSize();
3702 // Redraw etc. only if expanded was visible.
3703 if ( pwc
->IsVisible() && !m_frozen
&&
3704 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3708 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3711 DrawItems(pwc
, NULL
);
3716 // Clear dont-center-splitter flag if it wasn't set
3717 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3722 // -----------------------------------------------------------------------
3724 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3727 return m_pState
->DoHideProperty(p
, hide
, flags
);
3730 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3733 ClearSelection(false);
3736 m_pState
->DoHideProperty(p
, hide
, flags
);
3738 RecalculateVirtualSize();
3745 // -----------------------------------------------------------------------
3746 // wxPropertyGrid size related methods
3747 // -----------------------------------------------------------------------
3749 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3751 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3755 // If virtual height was changed, then recalculate editor control position(s)
3756 if ( m_pState
->m_vhCalcPending
)
3757 CorrectEditorWidgetPosY();
3759 m_pState
->EnsureVirtualHeight();
3762 int by1
= m_pState
->GetVirtualHeight();
3763 int by2
= m_pState
->GetActualVirtualHeight();
3766 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3767 wxFAIL_MSG(s
.c_str());
3772 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3774 int x
= m_pState
->m_width
;
3775 int y
= m_pState
->m_virtualHeight
;
3778 GetClientSize(&width
,&height
);
3780 // Now adjust virtual size.
3781 SetVirtualSize(x
, y
);
3787 // Adjust scrollbars
3788 if ( HasVirtualWidth() )
3790 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3791 xPos
= GetScrollPos( wxHORIZONTAL
);
3794 if ( forceXPos
!= -1 )
3797 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3800 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3801 int yPos
= GetScrollPos( wxVERTICAL
);
3803 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3804 xAmount
, yAmount
, xPos
, yPos
, true );
3806 // Must re-get size now
3807 GetClientSize(&width
,&height
);
3809 if ( !HasVirtualWidth() )
3811 m_pState
->SetVirtualWidth(width
);
3818 m_canvas
->SetSize( x
, y
);
3820 m_pState
->CheckColumnWidths();
3823 CorrectEditorWidgetSizeX();
3825 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3828 // -----------------------------------------------------------------------
3830 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3832 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3836 GetClientSize(&width
,&height
);
3841 #if wxPG_DOUBLE_BUFFER
3842 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3844 int dblh
= (m_lineHeight
*2);
3845 if ( !m_doubleBuffer
)
3847 // Create double buffer bitmap to draw on, if none
3848 int w
= (width
>250)?width
:250;
3849 int h
= height
+ dblh
;
3851 m_doubleBuffer
= new wxBitmap( w
, h
);
3855 int w
= m_doubleBuffer
->GetWidth();
3856 int h
= m_doubleBuffer
->GetHeight();
3858 // Double buffer must be large enough
3859 if ( w
< width
|| h
< (height
+dblh
) )
3861 if ( w
< width
) w
= width
;
3862 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3863 delete m_doubleBuffer
;
3864 m_doubleBuffer
= new wxBitmap( w
, h
);
3871 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3872 m_ncWidth
= event
.GetSize().x
;
3876 if ( m_pState
->m_itemsAdded
)
3877 PrepareAfterItemsAdded();
3879 // Without this, virtual size (atleast under wxGTK) will be skewed
3880 RecalculateVirtualSize();
3886 // -----------------------------------------------------------------------
3888 void wxPropertyGrid::SetVirtualWidth( int width
)
3892 // Disable virtual width
3893 width
= GetClientSize().x
;
3894 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3898 // Enable virtual width
3899 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3901 m_pState
->SetVirtualWidth( width
);
3904 void wxPropertyGrid::SetFocusOnCanvas()
3906 m_canvas
->SetFocusIgnoringChildren();
3907 m_editorFocused
= 0;
3910 // -----------------------------------------------------------------------
3911 // wxPropertyGrid mouse event handling
3912 // -----------------------------------------------------------------------
3914 // selFlags uses same values DoSelectProperty's flags
3915 // Returns true if event was vetoed.
3916 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3918 // Send property grid event of specific type and with specific property
3919 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3920 evt
.SetPropertyGrid(this);
3921 evt
.SetEventObject(m_eventObject
);
3925 evt
.SetCanVeto(true);
3926 evt
.SetupValidationInfo();
3927 m_validationInfo
.m_pValue
= pValue
;
3929 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3931 evtHandler
->ProcessEvent(evt
);
3933 return evt
.WasVetoed();
3936 // -----------------------------------------------------------------------
3938 // Return false if should be skipped
3939 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3943 // Need to set focus?
3944 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3949 wxPropertyGridPageState
* state
= m_pState
;
3951 int splitterHitOffset
;
3952 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3954 wxPGProperty
* p
= DoGetItemAtY(y
);
3958 int depth
= (int)p
->GetDepth() - 1;
3960 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3962 if ( x
>= marginEnds
)
3966 if ( p
->IsCategory() )
3968 // This is category.
3969 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3971 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3973 // Expand, collapse, activate etc. if click on text or left of splitter.
3976 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
3981 if ( !DoSelectProperty( p
) )
3984 // On double-click, expand/collapse.
3985 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
3987 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
3988 else DoExpand( p
, true );
3992 else if ( splitterHit
== -1 )
3995 unsigned int selFlag
= 0;
3996 if ( columnHit
== 1 )
3998 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
3999 selFlag
= wxPG_SEL_FOCUS
;
4001 if ( !DoSelectProperty( p
, selFlag
) )
4004 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4006 if ( p
->GetChildCount() && !p
->IsCategory() )
4007 // On double-click, expand/collapse.
4008 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4010 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4011 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4012 else DoExpand( p
, true );
4019 // click on splitter
4020 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4022 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4024 // Double-clicking the splitter causes auto-centering
4025 CenterSplitter( true );
4027 else if ( m_dragStatus
== 0 )
4030 // Begin draggin the splitter
4034 // Changes must be committed here or the
4035 // value won't be drawn correctly
4036 if ( !CommitChangesFromEditor() )
4039 m_wndEditor
->Show ( false );
4042 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4044 m_canvas
->CaptureMouse();
4045 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4049 m_draggedSplitter
= splitterHit
;
4050 m_dragOffset
= splitterHitOffset
;
4052 wxClientDC
dc(m_canvas
);
4054 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4055 // Fixes button disappearance bug
4057 m_wndEditor2
->Show ( false );
4060 m_startingSplitterX
= x
- splitterHitOffset
;
4068 if ( p
->GetChildCount() )
4070 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4072 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4074 int y2
= y
% m_lineHeight
;
4075 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4077 // On click on expander button, expand/collapse
4078 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4079 DoCollapse( p
, true );
4081 DoExpand( p
, true );
4090 // -----------------------------------------------------------------------
4092 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4093 wxMouseEvent
& WXUNUSED(event
) )
4097 // Select property here as well
4098 wxPGProperty
* p
= m_propHover
;
4099 if ( p
!= m_selected
)
4100 DoSelectProperty( p
);
4102 // Send right click event.
4103 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4110 // -----------------------------------------------------------------------
4112 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4113 wxMouseEvent
& WXUNUSED(event
) )
4117 // Select property here as well
4118 wxPGProperty
* p
= m_propHover
;
4120 if ( p
!= m_selected
)
4121 DoSelectProperty( p
);
4123 // Send double-click event.
4124 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4131 // -----------------------------------------------------------------------
4133 #if wxPG_SUPPORT_TOOLTIPS
4135 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4137 if ( tipString
.length() )
4139 m_canvas
->SetToolTip(tipString
);
4143 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4144 m_canvas
->SetToolTip( m_emptyString
);
4146 m_canvas
->SetToolTip( NULL
);
4151 #endif // #if wxPG_SUPPORT_TOOLTIPS
4153 // -----------------------------------------------------------------------
4155 // Return false if should be skipped
4156 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4158 // Safety check (needed because mouse capturing may
4159 // otherwise freeze the control)
4160 if ( m_dragStatus
> 0 && !event
.Dragging() )
4162 HandleMouseUp(x
,y
,event
);
4165 wxPropertyGridPageState
* state
= m_pState
;
4167 int splitterHitOffset
;
4168 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4169 int splitterX
= x
- splitterHitOffset
;
4171 if ( m_dragStatus
> 0 )
4173 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4174 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4177 int newSplitterX
= x
- m_dragOffset
;
4178 int splitterX
= x
- splitterHitOffset
;
4180 // Splitter redraw required?
4181 if ( newSplitterX
!= splitterX
)
4184 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4185 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4186 state
->m_fSplitterX
= (float) newSplitterX
;
4189 CorrectEditorWidgetSizeX();
4203 int ih
= m_lineHeight
;
4206 #if wxPG_SUPPORT_TOOLTIPS
4207 wxPGProperty
* prevHover
= m_propHover
;
4208 unsigned char prevSide
= m_mouseSide
;
4210 int curPropHoverY
= y
- (y
% ih
);
4212 // On which item it hovers
4215 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4218 // Mouse moves on another property
4220 m_propHover
= DoGetItemAtY(y
);
4221 m_propHoverY
= curPropHoverY
;
4224 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4227 #if wxPG_SUPPORT_TOOLTIPS
4228 // Store which side we are on
4230 if ( columnHit
== 1 )
4232 else if ( columnHit
== 0 )
4236 // If tooltips are enabled, show label or value as a tip
4237 // in case it doesn't otherwise show in full length.
4239 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4241 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4243 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4245 if ( m_propHover
&& !m_propHover
->IsCategory() )
4248 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4250 // Show help string as a tooltip
4251 wxString tipString
= m_propHover
->GetHelpString();
4253 SetToolTip(tipString
);
4257 // Show cropped value string as a tooltip
4261 if ( m_mouseSide
== 1 )
4263 tipString
= m_propHover
->m_label
;
4264 space
= splitterX
-m_marginWidth
-3;
4266 else if ( m_mouseSide
== 2 )
4268 tipString
= m_propHover
->GetDisplayedString();
4270 space
= m_width
- splitterX
;
4271 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4272 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4278 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4281 SetToolTip( tipString
);
4288 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4289 m_canvas
->SetToolTip( m_emptyString
);
4291 m_canvas
->SetToolTip( NULL
);
4302 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4303 m_canvas
->SetToolTip( m_emptyString
);
4305 m_canvas
->SetToolTip( NULL
);
4313 if ( splitterHit
== -1 ||
4315 HasFlag(wxPG_STATIC_SPLITTER
) )
4317 // hovering on something else
4318 if ( m_curcursor
!= wxCURSOR_ARROW
)
4319 CustomSetCursor( wxCURSOR_ARROW
);
4323 // Do not allow splitter cursor on caption items.
4324 // (also not if we were dragging and its started
4325 // outside the splitter region)
4327 if ( !m_propHover
->IsCategory() &&
4331 // hovering on splitter
4333 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4334 // reliably detected.
4335 //if ( m_curcursor != wxCURSOR_SIZEWE )
4336 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4342 // hovering on something else
4343 if ( m_curcursor
!= wxCURSOR_ARROW
)
4344 CustomSetCursor( wxCURSOR_ARROW
);
4351 // -----------------------------------------------------------------------
4353 // Also handles Leaving event
4354 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4355 wxMouseEvent
&WXUNUSED(event
) )
4357 wxPropertyGridPageState
* state
= m_pState
;
4361 int splitterHitOffset
;
4362 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4364 // No event type check - basicly calling this method should
4365 // just stop dragging.
4366 // Left up after dragged?
4367 if ( m_dragStatus
>= 1 )
4370 // End Splitter Dragging
4372 // DO NOT ENABLE FOLLOWING LINE!
4373 // (it is only here as a reminder to not to do it)
4376 // Disable splitter auto-centering
4377 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4379 // This is necessary to return cursor
4380 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4382 m_canvas
->ReleaseMouse();
4383 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4386 // Set back the default cursor, if necessary
4387 if ( splitterHit
== -1 ||
4390 CustomSetCursor( wxCURSOR_ARROW
);
4395 // Control background needs to be cleared
4396 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4397 DrawItem( m_selected
);
4401 m_wndEditor
->Show ( true );
4404 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4405 // Fixes button disappearance bug
4407 m_wndEditor2
->Show ( true );
4410 // This clears the focus.
4411 m_editorFocused
= 0;
4417 // -----------------------------------------------------------------------
4419 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4421 int splitterX
= GetSplitterPosition();
4424 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4428 wxWindow
* wnd
= GetEditorControl();
4430 // Hide popup on clicks
4431 if ( event
.GetEventType() != wxEVT_MOTION
)
4432 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4434 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4440 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4442 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4443 ux
>= (r
.x
+r
.width
) ||
4445 event
.m_y
>= (r
.y
+r
.height
)
4455 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4460 // -----------------------------------------------------------------------
4462 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4465 if ( OnMouseCommon( event
, &x
, &y
) )
4467 HandleMouseClick(x
,y
,event
);
4472 // -----------------------------------------------------------------------
4474 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4477 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4478 HandleMouseRightClick(x
,y
,event
);
4482 // -----------------------------------------------------------------------
4484 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4486 // Always run standard mouse-down handler as well
4487 OnMouseClick(event
);
4490 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4491 HandleMouseDoubleClick(x
,y
,event
);
4495 // -----------------------------------------------------------------------
4497 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4500 if ( OnMouseCommon( event
, &x
, &y
) )
4502 HandleMouseMove(x
,y
,event
);
4507 // -----------------------------------------------------------------------
4509 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4511 // Called when mouse moves in the empty space below the properties.
4512 CustomSetCursor( wxCURSOR_ARROW
);
4515 // -----------------------------------------------------------------------
4517 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4520 if ( OnMouseCommon( event
, &x
, &y
) )
4522 HandleMouseUp(x
,y
,event
);
4527 // -----------------------------------------------------------------------
4529 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4531 // This may get called from child control as well, so event's
4532 // mouse position cannot be relied on.
4534 if ( event
.Entering() )
4536 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4538 // TODO: Fix this (detect parent and only do
4539 // cursor trick if it is a manager).
4540 wxASSERT( GetParent() );
4541 GetParent()->SetCursor(wxNullCursor
);
4543 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4546 GetParent()->SetCursor(wxNullCursor
);
4548 else if ( event
.Leaving() )
4550 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4551 m_canvas
->SetCursor( wxNullCursor
);
4553 // Get real cursor position
4554 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4556 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4559 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4561 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4565 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4573 // -----------------------------------------------------------------------
4575 // Common code used by various OnMouseXXXChild methods.
4576 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4578 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4579 wxASSERT( topCtrlWnd
);
4581 event
.GetPosition(&x
,&y
);
4583 int splitterX
= GetSplitterPosition();
4585 wxRect r
= topCtrlWnd
->GetRect();
4586 if ( !m_dragStatus
&&
4587 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4588 y
>= 0 && y
< r
.height \
4591 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4596 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4603 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4606 if ( OnMouseChildCommon(event
,&x
,&y
) )
4608 bool res
= HandleMouseClick(x
,y
,event
);
4609 if ( !res
) event
.Skip();
4613 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4616 wxASSERT( m_wndEditor
);
4617 // These coords may not be exact (about +-2),
4618 // but that should not matter (right click is about item, not position).
4619 wxPoint pt
= m_wndEditor
->GetPosition();
4620 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4621 wxASSERT( m_selected
);
4622 m_propHover
= m_selected
;
4623 bool res
= HandleMouseRightClick(x
,y
,event
);
4624 if ( !res
) event
.Skip();
4627 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4630 if ( OnMouseChildCommon(event
,&x
,&y
) )
4632 bool res
= HandleMouseMove(x
,y
,event
);
4633 if ( !res
) event
.Skip();
4637 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4640 if ( OnMouseChildCommon(event
,&x
,&y
) )
4642 bool res
= HandleMouseUp(x
,y
,event
);
4643 if ( !res
) event
.Skip();
4647 // -----------------------------------------------------------------------
4648 // wxPropertyGrid keyboard event handling
4649 // -----------------------------------------------------------------------
4651 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4653 // Translates wxKeyEvent to wxPG_ACTION_XXX
4655 int keycode
= event
.GetKeyCode();
4656 int modifiers
= event
.GetModifiers();
4658 wxASSERT( !(modifiers
&~(0xFFFF)) );
4660 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4662 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4664 if ( it
== m_actionTriggers
.end() )
4669 int second
= (it
->second
>>16) & 0xFFFF;
4673 return (it
->second
& 0xFFFF);
4676 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4678 wxASSERT( !(modifiers
&~(0xFFFF)) );
4680 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4682 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4684 if ( it
!= m_actionTriggers
.end() )
4686 // This key combination is already used
4688 // Can add secondary?
4689 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4690 wxT("You can only add up to two separate actions per key combination.") );
4692 action
= it
->second
| (action
<<16);
4695 m_actionTriggers
[hashMapKey
] = action
;
4698 void wxPropertyGrid::ClearActionTriggers( int action
)
4700 wxPGHashMapI2I::iterator it
;
4702 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4704 if ( it
->second
== action
)
4706 m_actionTriggers
.erase(it
);
4711 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4714 // Handles key event when editor control is not focused.
4717 wxCHECK2(!m_frozen
, return);
4719 // Travelsal between items, collapsing/expanding, etc.
4720 int keycode
= event
.GetKeyCode();
4721 bool editorFocused
= IsEditorFocused();
4723 if ( keycode
== WXK_TAB
)
4725 wxWindow
* mainControl
;
4727 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4728 mainControl
= GetParent();
4732 if ( !event
.ShiftDown() )
4734 if ( !editorFocused
&& m_wndEditor
)
4736 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4740 // Tab traversal workaround for platforms on which
4741 // wxWindow::Navigate() may navigate into first child
4742 // instead of next sibling. Does not work perfectly
4743 // in every scenario (for instance, when property grid
4744 // is either first or last control).
4745 #if defined(__WXGTK__)
4746 wxWindow
* sibling
= mainControl
->GetNextSibling();
4748 sibling
->SetFocusFromKbd();
4750 Navigate(wxNavigationKeyEvent::IsForward
);
4756 if ( editorFocused
)
4762 #if defined(__WXGTK__)
4763 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4765 sibling
->SetFocusFromKbd();
4767 Navigate(wxNavigationKeyEvent::IsBackward
);
4775 // Ignore Alt and Control when they are down alone
4776 if ( keycode
== WXK_ALT
||
4777 keycode
== WXK_CONTROL
)
4784 int action
= KeyEventToActions(event
, &secondAction
);
4786 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4789 // Esc cancels any changes
4790 if ( IsEditorsValueModified() )
4792 EditorsValueWasNotModified();
4794 // Update the control as well
4795 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4797 m_selected
->GetDisplayedString() );
4800 OnValidationFailureReset(m_selected
);
4806 // Except for TAB and ESC, handle child control events in child control
4813 bool wasHandled
= false;
4818 if ( ButtonTriggerKeyTest(action
, event
) )
4821 wxPGProperty
* p
= m_selected
;
4823 // Travel and expand/collapse
4826 if ( p
->GetChildCount() &&
4827 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4830 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4832 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4835 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4837 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4844 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4848 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4854 if ( selectDir
>= -1 )
4856 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4858 DoSelectProperty(p
);
4864 // If nothing was selected, select the first item now
4865 // (or navigate out of tab).
4866 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4868 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4869 if ( p
) DoSelectProperty(p
);
4878 // -----------------------------------------------------------------------
4880 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4882 HandleKeyEvent(event
, false);
4885 // -----------------------------------------------------------------------
4887 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4892 action
= KeyEventToActions(event
, &secondAction
);
4895 // Does the keycode trigger button?
4896 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4899 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4900 GetEventHandler()->AddPendingEvent(evt
);
4907 // -----------------------------------------------------------------------
4909 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4911 HandleKeyEvent(event
, true);
4914 // -----------------------------------------------------------------------
4915 // wxPropertyGrid miscellaneous event handling
4916 // -----------------------------------------------------------------------
4918 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4921 // Check if the focus is in this control or one of its children
4922 wxWindow
* newFocused
= wxWindow::FindFocus();
4924 if ( newFocused
!= m_curFocused
)
4925 HandleFocusChange( newFocused
);
4928 bool wxPropertyGrid::IsEditorFocused() const
4930 wxWindow
* focus
= wxWindow::FindFocus();
4932 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4933 focus
== GetEditorControl() )
4939 // Called by focus event handlers. newFocused is the window that becomes focused.
4940 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4942 unsigned int oldFlags
= m_iFlags
;
4944 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4946 wxWindow
* parent
= newFocused
;
4948 // This must be one of nextFocus' parents.
4951 // Use m_eventObject, which is either wxPropertyGrid or
4952 // wxPropertyGridManager, as appropriate.
4953 if ( parent
== m_eventObject
)
4955 m_iFlags
|= wxPG_FL_FOCUSED
;
4958 parent
= parent
->GetParent();
4961 m_curFocused
= newFocused
;
4963 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4964 (oldFlags
& wxPG_FL_FOCUSED
) )
4966 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4968 // Need to store changed value
4969 CommitChangesFromEditor();
4975 // Preliminary code for tab-order respecting
4976 // tab-traversal (but should be moved to
4979 wxWindow* prevFocus = event.GetWindow();
4980 wxWindow* useThis = this;
4981 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4982 useThis = GetParent();
4985 prevFocus->GetParent() == useThis->GetParent() )
4987 wxList& children = useThis->GetParent()->GetChildren();
4989 wxNode* node = children.Find(prevFocus);
4991 if ( node->GetNext() &&
4992 useThis == node->GetNext()->GetData() )
4993 DoSelectProperty(GetFirst());
4994 else if ( node->GetPrevious () &&
4995 useThis == node->GetPrevious()->GetData() )
4996 DoSelectProperty(GetLastProperty());
5003 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5004 DrawItem( m_selected
);
5008 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5010 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5011 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5012 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5013 //else if ( event.GetWindow() )
5015 HandleFocusChange(event
.GetWindow());
5020 // -----------------------------------------------------------------------
5022 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5024 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5027 // event.Skip() being commented out is aworkaround for bug reported
5028 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5032 // -----------------------------------------------------------------------
5034 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5036 m_iFlags
|= wxPG_FL_SCROLLED
;
5041 // -----------------------------------------------------------------------
5043 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5045 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5047 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5051 // -----------------------------------------------------------------------
5052 // Property editor related functions
5053 // -----------------------------------------------------------------------
5055 // noDefCheck = true prevents infinite recursion.
5056 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5059 wxASSERT( editorClass
);
5061 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5062 RegisterDefaultEditors();
5064 wxString name
= editorClass
->GetName();
5066 // Existing editor under this name?
5067 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5069 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5071 // If this name was already used, try class name.
5072 name
= editorClass
->GetClassInfo()->GetClassName();
5073 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5076 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5077 (wxPGEditor
*) vt_it
->second
,
5078 "Editor with given name was already registered" );
5080 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5085 // Use this in RegisterDefaultEditors.
5086 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5087 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5089 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5090 new wxPG##EDITOR##Editor, true ); \
5093 // Registers all default editor classes
5094 void wxPropertyGrid::RegisterDefaultEditors()
5096 wxPGRegisterDefaultEditorClass( TextCtrl
);
5097 wxPGRegisterDefaultEditorClass( Choice
);
5098 wxPGRegisterDefaultEditorClass( ComboBox
);
5099 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5100 #if wxPG_INCLUDE_CHECKBOX
5101 wxPGRegisterDefaultEditorClass( CheckBox
);
5103 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5105 // Register SpinCtrl etc. editors before use
5106 RegisterAdditionalEditors();
5109 // -----------------------------------------------------------------------
5110 // wxPGStringTokenizer
5111 // Needed to handle C-style string lists (e.g. "str1" "str2")
5112 // -----------------------------------------------------------------------
5114 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5115 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5119 wxPGStringTokenizer::~wxPGStringTokenizer()
5123 bool wxPGStringTokenizer::HasMoreTokens()
5125 const wxString
& str
= *m_str
;
5127 wxString::const_iterator i
= m_curPos
;
5129 wxUniChar delim
= m_delimeter
;
5131 wxUniChar prev_a
= wxT('\0');
5133 bool inToken
= false;
5135 while ( i
!= str
.end() )
5144 m_readyToken
.clear();
5149 if ( prev_a
!= wxT('\\') )
5153 if ( a
!= wxT('\\') )
5173 m_curPos
= str
.end();
5181 wxString
wxPGStringTokenizer::GetNextToken()
5183 return m_readyToken
;
5186 // -----------------------------------------------------------------------
5188 // -----------------------------------------------------------------------
5190 wxPGChoiceEntry::wxPGChoiceEntry()
5191 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5195 // -----------------------------------------------------------------------
5197 // -----------------------------------------------------------------------
5199 wxPGChoicesData::wxPGChoicesData()
5204 wxPGChoicesData::~wxPGChoicesData()
5209 void wxPGChoicesData::Clear()
5214 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5216 wxASSERT( m_items
.size() == 0 );
5218 m_items
= data
->m_items
;
5221 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5222 const wxPGChoiceEntry
& item
)
5224 wxVector
<wxPGChoiceEntry
>::iterator it
;
5228 index
= (int) m_items
.size();
5232 it
= m_items
.begin() + index
;
5235 m_items
.insert(it
, item
);
5237 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5239 // Need to fix value?
5240 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5241 ownEntry
.SetValue(index
);
5246 // -----------------------------------------------------------------------
5248 // -----------------------------------------------------------------------
5250 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5254 wxPGChoiceEntry
entry(label
, value
);
5255 return m_data
->Insert( -1, entry
);
5258 // -----------------------------------------------------------------------
5260 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5264 wxPGChoiceEntry
entry(label
, value
);
5265 entry
.SetBitmap(bitmap
);
5266 return m_data
->Insert( -1, entry
);
5269 // -----------------------------------------------------------------------
5271 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5274 return m_data
->Insert( index
, entry
);
5277 // -----------------------------------------------------------------------
5279 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5283 wxPGChoiceEntry
entry(label
, value
);
5284 return m_data
->Insert( index
, entry
);
5287 // -----------------------------------------------------------------------
5289 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5295 while ( index
< GetCount() )
5297 int cmpRes
= GetLabel(index
).Cmp(label
);
5303 wxPGChoiceEntry
entry(label
, value
);
5304 return m_data
->Insert( index
, entry
);
5307 // -----------------------------------------------------------------------
5309 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5313 unsigned int itemcount
= 0;
5314 const wxChar
** p
= &labels
[0];
5315 while ( *p
) { p
++; itemcount
++; }
5318 for ( i
= 0; i
< itemcount
; i
++ )
5323 wxPGChoiceEntry
entry(labels
[i
], value
);
5324 m_data
->Insert( i
, entry
);
5328 // -----------------------------------------------------------------------
5330 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5335 unsigned int itemcount
= arr
.size();
5337 for ( i
= 0; i
< itemcount
; i
++ )
5340 if ( &arrint
&& arrint
.size() )
5342 wxPGChoiceEntry
entry(arr
[i
], value
);
5343 m_data
->Insert( i
, entry
);
5347 // -----------------------------------------------------------------------
5349 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5351 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5352 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5353 m_data
->m_items
.begin()+nIndex
+count
);
5356 // -----------------------------------------------------------------------
5358 int wxPGChoices::Index( const wxString
& str
) const
5363 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5365 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5366 if ( entry
.HasText() && entry
.GetText() == str
)
5373 // -----------------------------------------------------------------------
5375 int wxPGChoices::Index( int val
) const
5380 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5382 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5383 if ( entry
.GetValue() == val
)
5390 // -----------------------------------------------------------------------
5392 wxArrayString
wxPGChoices::GetLabels() const
5397 if ( this && IsOk() )
5398 for ( i
=0; i
<GetCount(); i
++ )
5399 arr
.push_back(GetLabel(i
));
5404 // -----------------------------------------------------------------------
5406 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5413 for ( i
=0; i
< strings
.size(); i
++ )
5415 int index
= Index(strings
[i
]);
5417 arr
.Add(GetValue(index
));
5419 arr
.Add(wxPG_INVALID_VALUE
);
5426 // -----------------------------------------------------------------------
5428 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5429 wxArrayString
* unmatched
) const
5436 for ( i
=0; i
< strings
.size(); i
++ )
5438 const wxString
& str
= strings
[i
];
5439 int index
= Index(str
);
5442 else if ( unmatched
)
5443 unmatched
->Add(str
);
5450 // -----------------------------------------------------------------------
5452 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5456 if ( data
!= wxPGChoicesEmptyData
)
5463 // -----------------------------------------------------------------------
5465 void wxPGChoices::Init()
5467 m_data
= wxPGChoicesEmptyData
;
5470 // -----------------------------------------------------------------------
5472 void wxPGChoices::Free()
5474 if ( m_data
!= wxPGChoicesEmptyData
)
5477 m_data
= wxPGChoicesEmptyData
;
5481 // -----------------------------------------------------------------------
5482 // wxPropertyGridEvent
5483 // -----------------------------------------------------------------------
5485 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5488 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5489 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5490 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5491 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5492 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5493 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5494 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5495 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5496 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5499 // -----------------------------------------------------------------------
5501 void wxPropertyGridEvent::Init()
5503 m_validationInfo
= NULL
;
5505 m_wasVetoed
= false;
5508 // -----------------------------------------------------------------------
5510 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5511 : wxCommandEvent(commandType
,id
)
5517 // -----------------------------------------------------------------------
5519 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5520 : wxCommandEvent(event
)
5522 m_eventType
= event
.GetEventType();
5523 m_eventObject
= event
.m_eventObject
;
5525 m_property
= event
.m_property
;
5526 m_validationInfo
= event
.m_validationInfo
;
5527 m_canVeto
= event
.m_canVeto
;
5528 m_wasVetoed
= event
.m_wasVetoed
;
5531 // -----------------------------------------------------------------------
5533 wxPropertyGridEvent::~wxPropertyGridEvent()
5537 // -----------------------------------------------------------------------
5539 wxEvent
* wxPropertyGridEvent::Clone() const
5541 return new wxPropertyGridEvent( *this );
5544 // -----------------------------------------------------------------------
5545 // wxPropertyGridPopulator
5546 // -----------------------------------------------------------------------
5548 wxPropertyGridPopulator::wxPropertyGridPopulator()
5552 wxPGGlobalVars
->m_offline
++;
5555 // -----------------------------------------------------------------------
5557 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5560 m_propHierarchy
.clear();
5563 // -----------------------------------------------------------------------
5565 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5571 // -----------------------------------------------------------------------
5573 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5576 // Free unused sets of choices
5577 wxPGHashMapS2P::iterator it
;
5579 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5581 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5588 m_pg
->GetPanel()->Refresh();
5590 wxPGGlobalVars
->m_offline
--;
5593 // -----------------------------------------------------------------------
5595 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5596 const wxString
& propLabel
,
5597 const wxString
& propName
,
5598 const wxString
* propValue
,
5599 wxPGChoices
* pChoices
)
5601 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5602 wxPGProperty
* parent
= GetCurParent();
5604 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5606 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5610 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5612 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5616 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5618 property
->SetLabel(propLabel
);
5619 property
->DoSetName(propName
);
5621 if ( pChoices
&& pChoices
->IsOk() )
5622 property
->SetChoices(*pChoices
);
5624 m_state
->DoInsert(parent
, -1, property
);
5627 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5628 wxPG_PROGRAMMATIC_VALUE
);
5633 // -----------------------------------------------------------------------
5635 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5637 m_propHierarchy
.push_back(property
);
5638 DoScanForChildren();
5639 m_propHierarchy
.pop_back();
5642 // -----------------------------------------------------------------------
5644 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5645 const wxString
& idString
)
5647 wxPGChoices choices
;
5650 if ( choicesString
[0] == wxT('@') )
5652 wxString ids
= choicesString
.substr(1);
5653 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5654 if ( it
== m_dictIdChoices
.end() )
5655 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5657 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5662 if ( idString
.length() )
5664 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5665 if ( it
!= m_dictIdChoices
.end() )
5667 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5674 // Parse choices string
5675 wxString::const_iterator it
= choicesString
.begin();
5679 bool labelValid
= false;
5681 for ( ; it
!= choicesString
.end(); ++it
)
5687 if ( c
== wxT('"') )
5692 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5693 choices
.Add(label
, l
);
5696 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5701 else if ( c
== wxT('=') )
5708 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5715 if ( c
== wxT('"') )
5728 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5729 choices
.Add(label
, l
);
5732 if ( !choices
.IsOk() )
5734 choices
.EnsureData();
5738 if ( idString
.length() )
5739 m_dictIdChoices
[idString
] = choices
.GetData();
5746 // -----------------------------------------------------------------------
5748 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5750 if ( s
.Last() == wxT('%') )
5752 wxString s2
= s
.substr(0,s
.length()-1);
5754 if ( s2
.ToLong(&val
, 10) )
5756 *pval
= (val
*max
)/100;
5762 return s
.ToLong(pval
, 10);
5765 // -----------------------------------------------------------------------
5767 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5768 const wxString
& type
,
5769 const wxString
& value
)
5771 int l
= m_propHierarchy
.size();
5775 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5776 wxString valuel
= value
.Lower();
5779 if ( type
.length() == 0 )
5784 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5786 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5788 else if ( value
.ToLong(&v
, 0) )
5795 if ( type
== wxT("string") )
5799 else if ( type
== wxT("int") )
5802 value
.ToLong(&v
, 0);
5805 else if ( type
== wxT("bool") )
5807 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5814 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5819 p
->SetAttribute( name
, variant
);
5824 // -----------------------------------------------------------------------
5826 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5828 wxLogError(_("Error in resource: %s"),msg
.c_str());
5831 // -----------------------------------------------------------------------
5833 #endif // wxUSE_PROPGRID