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 wxChar
*wxPropertyGridNameStr
= wxT("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
,
416 Create(parent
,id
,pos
,size
,style
,name
);
419 // -----------------------------------------------------------------------
421 bool wxPropertyGrid::Create( wxWindow
*parent
,
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_inDoPropertyChanged
= 0;
466 m_inCommitChangesFromEditor
= 0;
467 m_inDoSelectProperty
= 0;
468 m_permanentValidationFailureBehavior
= wxPG_VFB_DEFAULT
;
474 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_RIGHT
);
475 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY
, WXK_DOWN
);
476 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_LEFT
);
477 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY
, WXK_UP
);
478 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY
, WXK_RIGHT
);
479 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY
, WXK_LEFT
);
480 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT
, WXK_ESCAPE
);
481 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_DOWN
, wxMOD_ALT
);
482 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON
, WXK_F4
);
484 m_coloursCustomized
= 0;
489 #if wxPG_DOUBLE_BUFFER
490 m_doubleBuffer
= (wxBitmap
*) NULL
;
493 #ifndef wxPG_ICON_WIDTH
499 m_iconWidth
= wxPG_ICON_WIDTH
;
504 m_gutterWidth
= wxPG_GUTTER_MIN
;
505 m_subgroup_extramargin
= 10;
509 m_width
= m_height
= 0;
511 m_commonValues
.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars
->m_defaultRenderer
) );
514 m_chgInfo_changedProperty
= NULL
;
517 // -----------------------------------------------------------------------
520 // Initialize after parent etc. set
522 void wxPropertyGrid::Init2()
524 wxASSERT( !(m_iFlags
& wxPG_FL_INITIALIZED
) );
527 // Smaller controls on Mac
528 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
531 // Now create state, if one didn't exist already
532 // (wxPropertyGridManager might have created it for us).
535 m_pState
= CreateState();
536 m_pState
->m_pPropGrid
= this;
537 m_iFlags
|= wxPG_FL_CREATEDSTATE
;
540 if ( !(m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
541 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
543 if ( m_windowStyle
& wxPG_HIDE_CATEGORIES
)
545 m_pState
->InitNonCatMode();
547 m_pState
->m_properties
= m_pState
->m_abcArray
;
550 GetClientSize(&m_width
,&m_height
);
552 #ifndef wxPG_ICON_WIDTH
553 // create two bitmap nodes for drawing
554 m_expandbmp
= new wxBitmap(expand_xpm
);
555 m_collbmp
= new wxBitmap(collapse_xpm
);
557 // calculate average font height for bitmap centering
559 m_iconWidth
= m_expandbmp
->GetWidth();
560 m_iconHeight
= m_expandbmp
->GetHeight();
563 m_curcursor
= wxCURSOR_ARROW
;
564 m_cursorSizeWE
= new wxCursor( wxCURSOR_SIZEWE
);
566 // adjust bitmap icon y position so they are centered
567 m_vspacing
= wxPG_DEFAULT_VSPACING
;
571 wxFont useFont
= wxScrolledWindow::GetFont();
572 wxScrolledWindow::SetOwnFont( useFont
);
576 // This should be otherwise called by SetOwnFont
577 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING
);
580 // Allocate cell datas indirectly by calling setter
581 m_propertyDefaultCell
.SetBgCol(*wxBLACK
);
582 m_categoryDefaultCell
.SetBgCol(*wxBLACK
);
586 // This helps with flicker
587 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
590 wxPGTLWHandler
* handler
= new wxPGTLWHandler(this);
591 m_tlp
= ::wxGetTopLevelParent(this);
592 m_tlwHandler
= handler
;
593 m_tlp
->PushEventHandler(handler
);
595 // set virtual size to this window size
596 wxSize wndsize
= GetSize();
597 SetVirtualSize(wndsize
.GetWidth(), wndsize
.GetWidth());
599 m_timeCreated
= ::wxGetLocalTimeMillis();
601 m_canvas
= new wxPGCanvas();
602 m_canvas
->Create(this, 1, wxPoint(0, 0), GetClientSize(),
603 wxWANTS_CHARS
| wxCLIP_CHILDREN
);
604 m_canvas
->SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
606 m_iFlags
|= wxPG_FL_INITIALIZED
;
608 m_ncWidth
= wndsize
.GetWidth();
610 // Need to call OnResize handler or size given in constructor/Create
612 wxSizeEvent
sizeEvent(wndsize
,0);
616 // -----------------------------------------------------------------------
618 wxPropertyGrid::~wxPropertyGrid()
622 DoSelectProperty(NULL
);
624 // This should do prevent things from going too badly wrong
625 m_iFlags
&= ~(wxPG_FL_INITIALIZED
);
627 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
628 m_canvas
->ReleaseMouse();
630 wxPGTLWHandler
* handler
= (wxPGTLWHandler
*) m_tlwHandler
;
631 m_tlp
->RemoveEventHandler(handler
);
635 if ( IsEditorsValueModified() )
636 ::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).)"),
637 wxS("wxPropertyGrid Debug Warning") );
640 #if wxPG_DOUBLE_BUFFER
641 if ( m_doubleBuffer
)
642 delete m_doubleBuffer
;
645 //m_selected = (wxPGProperty*) NULL;
647 if ( m_iFlags
& wxPG_FL_CREATEDSTATE
)
650 delete m_cursorSizeWE
;
652 #ifndef wxPG_ICON_WIDTH
657 // Delete common value records
658 for ( i
=0; i
<m_commonValues
.size(); i
++ )
660 delete GetCommonValue(i
);
664 // -----------------------------------------------------------------------
666 bool wxPropertyGrid::Destroy()
668 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
669 m_canvas
->ReleaseMouse();
671 return wxScrolledWindow::Destroy();
674 // -----------------------------------------------------------------------
676 wxPropertyGridPageState
* wxPropertyGrid::CreateState() const
678 return new wxPropertyGridPageState();
681 // -----------------------------------------------------------------------
682 // wxPropertyGrid overridden wxWindow methods
683 // -----------------------------------------------------------------------
685 void wxPropertyGrid::SetWindowStyleFlag( long style
)
687 long old_style
= m_windowStyle
;
689 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
691 wxASSERT( m_pState
);
693 if ( !(style
& wxPG_HIDE_CATEGORIES
) && (old_style
& wxPG_HIDE_CATEGORIES
) )
696 EnableCategories( true );
698 else if ( (style
& wxPG_HIDE_CATEGORIES
) && !(old_style
& wxPG_HIDE_CATEGORIES
) )
700 // Disable categories
701 EnableCategories( false );
703 if ( !(old_style
& wxPG_AUTO_SORT
) && (style
& wxPG_AUTO_SORT
) )
709 PrepareAfterItemsAdded();
711 m_pState
->m_itemsAdded
= 1;
713 #if wxPG_SUPPORT_TOOLTIPS
714 if ( !(old_style
& wxPG_TOOLTIPS
) && (style
& wxPG_TOOLTIPS
) )
720 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
721 SetToolTip ( tooltip );
722 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
725 else if ( (old_style
& wxPG_TOOLTIPS
) && !(style
& wxPG_TOOLTIPS
) )
730 m_canvas
->SetToolTip( (wxToolTip
*) NULL
);
735 wxScrolledWindow::SetWindowStyleFlag ( style
);
737 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
739 if ( (old_style
& wxPG_HIDE_MARGIN
) != (style
& wxPG_HIDE_MARGIN
) )
741 CalculateFontAndBitmapStuff( m_vspacing
);
747 // -----------------------------------------------------------------------
749 void wxPropertyGrid::Freeze()
753 wxScrolledWindow::Freeze();
758 // -----------------------------------------------------------------------
760 void wxPropertyGrid::Thaw()
766 wxScrolledWindow::Thaw();
767 RecalculateVirtualSize();
768 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
772 // Force property re-selection
774 DoSelectProperty(m_selected
, wxPG_SEL_FORCE
);
778 // -----------------------------------------------------------------------
780 void wxPropertyGrid::SetExtraStyle( long exStyle
)
782 if ( exStyle
& wxPG_EX_NATIVE_DOUBLE_BUFFERING
)
784 #if defined(__WXMSW__)
787 // Don't use WS_EX_COMPOSITED just now.
790 if ( m_iFlags & wxPG_FL_IN_MANAGER )
791 hWnd = (HWND)GetParent()->GetHWND();
793 hWnd = (HWND)GetHWND();
795 ::SetWindowLong( hWnd, GWL_EXSTYLE,
796 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
799 //#elif defined(__WXGTK20__)
801 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
802 // truly was double-buffered.
803 if ( !this->IsDoubleBuffered() )
805 exStyle
&= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING
);
809 #if wxPG_DOUBLE_BUFFER
810 delete m_doubleBuffer
;
811 m_doubleBuffer
= NULL
;
816 wxScrolledWindow::SetExtraStyle( exStyle
);
818 if ( exStyle
& wxPG_EX_INIT_NOCAT
)
819 m_pState
->InitNonCatMode();
821 if ( exStyle
& wxPG_EX_HELP_AS_TOOLTIPS
)
822 m_windowStyle
|= wxPG_TOOLTIPS
;
825 wxPGGlobalVars
->m_extraStyle
= exStyle
;
828 // -----------------------------------------------------------------------
830 // returns the best acceptable minimal size
831 wxSize
wxPropertyGrid::DoGetBestSize() const
834 if ( m_lineHeight
> hei
)
836 wxSize sz
= wxSize( 60, hei
+40 );
842 // -----------------------------------------------------------------------
843 // wxPropertyGrid Font and Colour Methods
844 // -----------------------------------------------------------------------
846 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing
)
850 m_captionFont
= wxScrolledWindow::GetFont();
852 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
853 m_subgroup_extramargin
= x
+ (x
/2);
856 #if wxPG_USE_RENDERER_NATIVE
857 m_iconWidth
= wxPG_ICON_WIDTH
;
858 #elif wxPG_ICON_WIDTH
860 m_iconWidth
= (m_fontHeight
* wxPG_ICON_WIDTH
) / 13;
861 if ( m_iconWidth
< 5 ) m_iconWidth
= 5;
862 else if ( !(m_iconWidth
& 0x01) ) m_iconWidth
++; // must be odd
866 m_gutterWidth
= m_iconWidth
/ wxPG_GUTTER_DIV
;
867 if ( m_gutterWidth
< wxPG_GUTTER_MIN
)
868 m_gutterWidth
= wxPG_GUTTER_MIN
;
871 if ( vspacing
<= 1 ) vdiv
= 12;
872 else if ( vspacing
>= 3 ) vdiv
= 3;
874 m_spacingy
= m_fontHeight
/ vdiv
;
875 if ( m_spacingy
< wxPG_YSPACING_MIN
)
876 m_spacingy
= wxPG_YSPACING_MIN
;
879 if ( !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
880 m_marginWidth
= m_gutterWidth
*2 + m_iconWidth
;
882 m_captionFont
.SetWeight(wxBOLD
);
883 GetTextExtent(wxS("jG"), &x
, &y
, 0, 0, &m_captionFont
);
885 m_lineHeight
= m_fontHeight
+(2*m_spacingy
)+1;
888 m_buttonSpacingY
= (m_lineHeight
- m_iconHeight
) / 2;
889 if ( m_buttonSpacingY
< 0 ) m_buttonSpacingY
= 0;
892 m_pState
->CalculateFontAndBitmapStuff(vspacing
);
894 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
895 RecalculateVirtualSize();
897 InvalidateBestSize();
900 // -----------------------------------------------------------------------
902 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) )
908 // -----------------------------------------------------------------------
910 static wxColour
wxPGAdjustColour(const wxColour
& src
, int ra
,
911 int ga
= 1000, int ba
= 1000,
912 bool forceDifferent
= false)
919 // Recursion guard (allow 2 max)
920 static int isinside
= 0;
922 wxCHECK_MSG( isinside
< 3,
924 wxT("wxPGAdjustColour should not be recursively called more than once") );
932 if ( r2
>255 ) r2
= 255;
933 else if ( r2
<0) r2
= 0;
935 if ( g2
>255 ) g2
= 255;
936 else if ( g2
<0) g2
= 0;
938 if ( b2
>255 ) b2
= 255;
939 else if ( b2
<0) b2
= 0;
941 // Make sure they are somewhat different
942 if ( forceDifferent
&& (abs((r
+g
+b
)-(r2
+g2
+b2
)) < abs(ra
/2)) )
943 dst
= wxPGAdjustColour(src
,-(ra
*2));
945 dst
= wxColour(r2
,g2
,b2
);
947 // Recursion guard (allow 2 max)
954 static int wxPGGetColAvg( const wxColour
& col
)
956 return (col
.Red() + col
.Green() + col
.Blue()) / 3;
960 void wxPropertyGrid::RegainColours()
962 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
964 if ( !(m_coloursCustomized
& 0x0002) )
966 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
968 // Make sure colour is dark enough
970 int colDec
= wxPGGetColAvg(col
) - 230;
972 int colDec
= wxPGGetColAvg(col
) - 200;
975 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
978 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
981 if ( !(m_coloursCustomized
& 0x0001) )
982 m_colMargin
= m_colCapBack
;
984 if ( !(m_coloursCustomized
& 0x0004) )
991 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
992 m_colCapFore
= capForeCol
;
993 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
996 if ( !(m_coloursCustomized
& 0x0008) )
998 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
999 m_colPropBack
= bgCol
;
1000 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1003 if ( !(m_coloursCustomized
& 0x0010) )
1005 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1006 m_colPropFore
= fgCol
;
1007 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1010 if ( !(m_coloursCustomized
& 0x0020) )
1011 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1013 if ( !(m_coloursCustomized
& 0x0040) )
1014 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1016 if ( !(m_coloursCustomized
& 0x0080) )
1017 m_colLine
= m_colCapBack
;
1019 if ( !(m_coloursCustomized
& 0x0100) )
1020 m_colDisPropFore
= m_colCapFore
;
1022 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1025 // -----------------------------------------------------------------------
1027 void wxPropertyGrid::ResetColours()
1029 m_coloursCustomized
= 0;
1036 // -----------------------------------------------------------------------
1038 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1040 // Must disable active editor.
1043 bool selRes
= ClearSelection();
1044 wxPG_CHECK_MSG_DBG( selRes
,
1046 wxT("failed to deselect a property (editor probably had invalid value)") );
1049 // TODO: Following code is disabled with wxMac because
1050 // it is reported to fail. I (JMS) cannot debug it
1051 // personally right now.
1052 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1053 #if 1 // !defined(__WXMAC__)
1054 bool res
= wxScrolledWindow::SetFont( font
);
1057 CalculateFontAndBitmapStuff( m_vspacing
);
1060 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1068 // TODO: Remove after SetFont crash fixed.
1069 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1071 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."));
1077 // -----------------------------------------------------------------------
1079 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1082 m_coloursCustomized
|= 0x80;
1086 // -----------------------------------------------------------------------
1088 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1091 m_coloursCustomized
|= 0x01;
1095 // -----------------------------------------------------------------------
1097 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1099 m_colPropBack
= col
;
1100 m_coloursCustomized
|= 0x08;
1102 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1107 // -----------------------------------------------------------------------
1109 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1111 m_colPropFore
= col
;
1112 m_coloursCustomized
|= 0x10;
1114 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1119 // -----------------------------------------------------------------------
1121 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1123 m_colEmptySpace
= col
;
1128 // -----------------------------------------------------------------------
1130 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1132 m_colDisPropFore
= col
;
1133 m_coloursCustomized
|= 0x100;
1137 // -----------------------------------------------------------------------
1139 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1142 m_coloursCustomized
|= 0x20;
1146 // -----------------------------------------------------------------------
1148 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1151 m_coloursCustomized
|= 0x40;
1155 // -----------------------------------------------------------------------
1157 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1160 m_coloursCustomized
|= 0x02;
1162 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1167 // -----------------------------------------------------------------------
1169 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1172 m_coloursCustomized
|= 0x04;
1174 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1179 // -----------------------------------------------------------------------
1181 void wxPropertyGrid::SetPropertyBackgroundColour( wxPGPropArg id
,
1182 const wxColour
& colour
,
1185 wxPG_PROP_ARG_CALL_PROLOG()
1186 p
->SetBackgroundColour( colour
, recursively
);
1187 DrawItemAndChildren( p
);
1190 // -----------------------------------------------------------------------
1192 wxColour
wxPropertyGrid::GetPropertyBackgroundColour( wxPGPropArg id
) const
1194 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1196 return p
->GetCell(0).GetBgCol();
1199 // -----------------------------------------------------------------------
1201 void wxPropertyGrid::SetPropertyTextColour( wxPGPropArg id
, const wxColour
& colour
,
1204 wxPG_PROP_ARG_CALL_PROLOG()
1205 p
->SetTextColour( colour
, recursively
);
1206 DrawItemAndChildren( p
);
1209 // -----------------------------------------------------------------------
1211 wxColour
wxPropertyGrid::GetPropertyTextColour( wxPGPropArg id
) const
1213 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
1215 return p
->GetCell(0).GetFgCol();
1218 // -----------------------------------------------------------------------
1220 void wxPropertyGrid::SetPropertyColoursToDefault( wxPGPropArg id
)
1222 wxPG_PROP_ARG_CALL_PROLOG()
1227 // -----------------------------------------------------------------------
1228 // wxPropertyGrid property adding and removal
1229 // -----------------------------------------------------------------------
1231 void wxPropertyGrid::PrepareAfterItemsAdded()
1233 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1235 m_pState
->m_itemsAdded
= 0;
1237 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1240 RecalculateVirtualSize();
1243 // -----------------------------------------------------------------------
1244 // wxPropertyGrid property value setting and getting
1245 // -----------------------------------------------------------------------
1247 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1249 m_pState
->DoSetPropertyValueUnspecified(p
);
1250 DrawItemAndChildren(p
);
1252 wxPGProperty
* parent
= p
->GetParent();
1254 (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1257 parent
= parent
->GetParent();
1261 // -----------------------------------------------------------------------
1262 // wxPropertyGrid property operations
1263 // -----------------------------------------------------------------------
1265 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1267 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1271 bool changed
= false;
1273 // Is it inside collapsed section?
1274 if ( !p
->IsVisible() )
1277 wxPGProperty
* parent
= p
->GetParent();
1278 wxPGProperty
* grandparent
= parent
->GetParent();
1280 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1281 Expand( grandparent
);
1289 GetViewStart(&vx
,&vy
);
1290 vy
*=wxPG_PIXELS_PER_UNIT
;
1296 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1297 m_iFlags
|= wxPG_FL_SCROLLED
;
1300 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1302 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1303 m_iFlags
|= wxPG_FL_SCROLLED
;
1313 // -----------------------------------------------------------------------
1314 // wxPropertyGrid helper methods called by properties
1315 // -----------------------------------------------------------------------
1317 // Control font changer helper.
1318 void wxPropertyGrid::SetCurControlBoldFont()
1320 wxASSERT( m_wndEditor
);
1321 m_wndEditor
->SetFont( m_captionFont
);
1324 // -----------------------------------------------------------------------
1326 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1329 #if wxPG_SMALL_SCREEN
1330 // On small-screen devices, always show dialogs with default position and size.
1331 return wxDefaultPosition
;
1333 int splitterX
= GetSplitterPosition();
1337 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1339 ImprovedClientToScreen( &x
, &y
);
1341 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1342 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1349 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1359 new_y
= y
+ m_lineHeight
;
1361 return wxPoint(new_x
,new_y
);
1365 // -----------------------------------------------------------------------
1367 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1369 if ( src_str
.length() == 0 )
1375 bool prev_is_slash
= false;
1377 wxString::const_iterator i
= src_str
.begin();
1381 for ( ; i
!= src_str
.end(); i
++ )
1385 if ( a
!= wxS('\\') )
1387 if ( !prev_is_slash
)
1393 if ( a
== wxS('n') )
1396 dst_str
<< wxS('\n');
1398 dst_str
<< wxS('\n');
1401 else if ( a
== wxS('t') )
1402 dst_str
<< wxS('\t');
1406 prev_is_slash
= false;
1410 if ( prev_is_slash
)
1412 dst_str
<< wxS('\\');
1413 prev_is_slash
= false;
1417 prev_is_slash
= true;
1424 // -----------------------------------------------------------------------
1426 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1428 if ( src_str
.length() == 0 )
1434 wxString::const_iterator i
= src_str
.begin();
1435 wxUniChar prev_a
= wxS('\0');
1439 for ( ; i
!= src_str
.end(); i
++ )
1443 if ( a
>= wxS(' ') )
1445 // This surely is not something that requires an escape sequence.
1450 // This might need...
1451 if ( a
== wxS('\r') )
1453 // DOS style line end.
1454 // Already taken care below
1456 else if ( a
== wxS('\n') )
1457 // UNIX style line end.
1458 dst_str
<< wxS("\\n");
1459 else if ( a
== wxS('\t') )
1461 dst_str
<< wxS('\t');
1464 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1474 // -----------------------------------------------------------------------
1476 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1480 return (wxPGProperty
*) NULL
;
1483 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1486 // -----------------------------------------------------------------------
1487 // wxPropertyGrid graphics related methods
1488 // -----------------------------------------------------------------------
1490 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1494 // Update everything inside the box
1495 wxRect r
= GetUpdateRegion().GetBox();
1497 dc
.SetPen(m_colEmptySpace
);
1498 dc
.SetBrush(m_colEmptySpace
);
1499 dc
.DrawRectangle(r
);
1502 // -----------------------------------------------------------------------
1504 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1505 wxPGProperty
* property
) const
1507 // Prepare rectangle to be used
1509 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1510 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1512 #if (wxPG_USE_RENDERER_NATIVE)
1514 #elif wxPG_ICON_WIDTH
1515 // Drawing expand/collapse button manually
1516 dc
.SetPen(m_colPropFore
);
1517 if ( property
->IsCategory() )
1518 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1520 dc
.SetBrush(m_colPropBack
);
1522 dc
.DrawRectangle( r
);
1523 int _y
= r
.y
+(m_iconWidth
/2);
1524 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1529 if ( property
->IsExpanded() )
1531 // wxRenderer functions are non-mutating in nature, so it
1532 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1533 // Hopefully this does not cause problems.
1534 #if (wxPG_USE_RENDERER_NATIVE)
1535 wxRendererNative::Get().DrawTreeItemButton(
1541 #elif wxPG_ICON_WIDTH
1550 #if (wxPG_USE_RENDERER_NATIVE)
1551 wxRendererNative::Get().DrawTreeItemButton(
1557 #elif wxPG_ICON_WIDTH
1558 int _x
= r
.x
+(m_iconWidth
/2);
1559 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1565 #if (wxPG_USE_RENDERER_NATIVE)
1567 #elif wxPG_ICON_WIDTH
1570 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1574 // -----------------------------------------------------------------------
1577 // This is the one called by OnPaint event handler and others.
1578 // topy and bottomy are already unscrolled (ie. physical)
1580 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1582 unsigned int bottomy
,
1583 const wxRect
* clipRect
)
1585 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1587 m_pState
->EnsureVirtualHeight();
1589 wxRect tempClipRect
;
1592 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1593 clipRect
= &tempClipRect
;
1596 // items added check
1597 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1599 int paintFinishY
= 0;
1601 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1604 bool isBuffered
= false;
1606 #if wxPG_DOUBLE_BUFFER
1607 wxMemoryDC
* bufferDC
= NULL
;
1609 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1611 if ( !m_doubleBuffer
)
1613 paintFinishY
= clipRect
->y
;
1618 bufferDC
= new wxMemoryDC();
1620 // If nothing was changed, then just copy from double-buffer
1621 bufferDC
->SelectObject( *m_doubleBuffer
);
1631 dc
.SetClippingRegion( *clipRect
);
1632 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1635 #if wxPG_DOUBLE_BUFFER
1638 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1639 bufferDC
, 0, 0, wxCOPY
);
1640 dc
.DestroyClippingRegion(); // Is this really necessary?
1646 // Clear area beyond bottomY?
1647 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1649 dc
.SetPen(m_colEmptySpace
);
1650 dc
.SetBrush(m_colEmptySpace
);
1651 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1655 // -----------------------------------------------------------------------
1657 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1658 const wxPGProperty
* firstItem
,
1659 const wxPGProperty
* lastItem
,
1660 const wxRect
* clipRect
,
1661 bool isBuffered
) const
1663 // TODO: This should somehow be eliminated.
1664 wxRect tempClipRect
;
1667 wxASSERT(firstItem
);
1669 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1670 clipRect
= &tempClipRect
;
1674 firstItem
= DoGetItemAtY(clipRect
->y
);
1678 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1680 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1683 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1686 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1687 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1689 int lh
= m_lineHeight
;
1692 int lastItemBottomY
;
1694 firstItemTopY
= clipRect
->y
;
1695 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1697 // Align y coordinates to item boundaries
1698 firstItemTopY
-= firstItemTopY
% lh
;
1699 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1700 lastItemBottomY
-= 1;
1702 // Entire range outside scrolled, visible area?
1703 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1706 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1710 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1711 firstItem->GetLabel().c_str(),
1712 lastItem->GetLabel().c_str(),
1713 (int)(lastItemBottomY - firstItemTopY),
1715 (unsigned long)clipRect );
1720 long windowStyle
= m_windowStyle
;
1726 // With wxPG_DOUBLE_BUFFER, do double buffering
1727 // - buffer's y = 0, so align cliprect and coordinates to that
1729 #if wxPG_DOUBLE_BUFFER
1735 xRelMod
= clipRect
->x
;
1736 yRelMod
= clipRect
->y
;
1739 // clipRect conversion
1747 firstItemTopY
-= yRelMod
;
1748 lastItemBottomY
-= yRelMod
;
1751 wxUnusedVar(isBuffered
);
1754 int x
= m_marginWidth
- xRelMod
;
1756 const wxFont
& normalfont
= m_font
;
1758 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1760 bool isEnabled
= IsEnabled();
1763 // Prepare some pens and brushes that are often changed to.
1766 wxBrush
marginBrush(m_colMargin
);
1767 wxPen
marginPen(m_colMargin
);
1768 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1769 wxPen
linepen(m_colLine
,1,wxSOLID
);
1771 // pen that has same colour as text
1772 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1775 // Clear margin with background colour
1777 dc
.SetBrush( marginBrush
);
1778 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1780 dc
.SetPen( *wxTRANSPARENT_PEN
);
1781 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1784 const wxPGProperty
* selected
= m_selected
;
1785 const wxPropertyGridPageState
* state
= m_pState
;
1787 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1788 bool wasSelectedPainted
= false;
1791 // TODO: Only render columns that are within clipping region.
1793 dc
.SetFont(normalfont
);
1795 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1796 int endScanBottomY
= lastItemBottomY
+ lh
;
1797 int y
= firstItemTopY
;
1800 // Pregenerate list of visible properties.
1801 wxArrayPGProperty visPropArray
;
1802 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1804 for ( ; !it
.AtEnd(); it
.Next() )
1806 const wxPGProperty
* p
= *it
;
1808 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1810 visPropArray
.push_back((wxPGProperty
*)p
);
1812 if ( y
> endScanBottomY
)
1819 visPropArray
.push_back(NULL
);
1821 wxPGProperty
* nextP
= visPropArray
[0];
1823 int gridWidth
= state
->m_width
;
1826 for ( unsigned int arrInd
=1;
1827 nextP
&& y
<= lastItemBottomY
;
1830 wxPGProperty
* p
= nextP
;
1831 nextP
= visPropArray
[arrInd
];
1833 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1834 int textMarginHere
= x
;
1835 int renderFlags
= 0;
1837 int greyDepth
= m_marginWidth
;
1838 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1839 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1841 int greyDepthX
= greyDepth
- xRelMod
;
1843 // Use basic depth if in non-categoric mode and parent is base array.
1844 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1846 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1849 // Paint margin area
1850 dc
.SetBrush(marginBrush
);
1851 dc
.SetPen(marginPen
);
1852 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1854 dc
.SetPen( linepen
);
1859 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1865 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1867 sx
+= state
->m_colWidths
[si
];
1868 dc
.DrawLine( sx
, y
, sx
, y2
);
1871 // Horizontal Line, below
1872 // (not if both this and next is category caption)
1873 if ( p
->IsCategory() &&
1874 nextP
&& nextP
->IsCategory() )
1875 dc
.SetPen(m_colCapBack
);
1877 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1880 // Need to override row colours?
1884 if ( p
!= selected
)
1886 // Disabled may get different colour.
1887 if ( !p
->IsEnabled() )
1889 renderFlags
|= wxPGCellRenderer::Disabled
|
1890 wxPGCellRenderer::DontUseCellFgCol
;
1891 rowFgCol
= m_colDisPropFore
;
1896 renderFlags
|= wxPGCellRenderer::Selected
;
1898 if ( !p
->IsCategory() )
1900 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1901 wxPGCellRenderer::DontUseCellBgCol
;
1903 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1904 wasSelectedPainted
= true;
1907 // Selected gets different colour.
1908 if ( reallyFocused
)
1910 rowFgCol
= m_colSelFore
;
1911 rowBgCol
= m_colSelBack
;
1913 else if ( isEnabled
)
1915 rowFgCol
= m_colPropFore
;
1916 rowBgCol
= m_colMargin
;
1920 rowFgCol
= m_colDisPropFore
;
1921 rowBgCol
= m_colSelBack
;
1928 if ( rowBgCol
.IsOk() )
1929 rowBgBrush
= wxBrush(rowBgCol
);
1931 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1932 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1935 // Fill additional margin area with background colour of first cell
1936 if ( greyDepthX
< textMarginHere
)
1938 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1940 wxPGCell
& cell
= p
->GetCell(0);
1941 rowBgCol
= cell
.GetBgCol();
1942 rowBgBrush
= wxBrush(rowBgCol
);
1944 dc
.SetBrush(rowBgBrush
);
1945 dc
.SetPen(rowBgCol
);
1946 dc
.DrawRectangle(greyDepthX
+1, y
,
1947 textMarginHere
-greyDepthX
, lh
-1);
1950 bool fontChanged
= false;
1952 // Expander button rectangle
1953 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1958 if ( p
->IsCategory() )
1960 // Captions have their cell areas merged as one
1961 dc
.SetFont(m_captionFont
);
1963 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1965 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1967 dc
.SetBrush(rowBgBrush
);
1968 dc
.SetPen(rowBgCol
);
1971 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1973 dc
.SetTextForeground(rowFgCol
);
1976 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1977 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1980 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1981 DrawExpanderButton( dc
, butRect
, p
);
1985 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1987 dc
.SetFont(m_captionFont
);
1993 int nextCellWidth
= state
->m_colWidths
[0];
1994 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1995 int textXAdd
= textMarginHere
- greyDepthX
;
1997 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1999 cellRect
.width
= nextCellWidth
- 1;
2001 bool ctrlCell
= false;
2002 int cellRenderFlags
= renderFlags
;
2005 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
2006 DrawExpanderButton( dc
, butRect
, p
);
2009 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
2011 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
2012 dc
.SetBrush(editorBgCol
);
2013 dc
.SetPen(editorBgCol
);
2014 dc
.SetTextForeground(m_colPropFore
);
2015 dc
.DrawRectangle(cellRect
);
2017 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
2022 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
2024 dc
.SetBrush(rowBgBrush
);
2025 dc
.SetPen(rowBgCol
);
2028 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
2030 dc
.SetTextForeground(rowFgCol
);
2034 dc
.SetClippingRegion(cellRect
);
2036 cellRect
.x
+= textXAdd
;
2037 cellRect
.width
-= textXAdd
;
2042 wxPGCellRenderer
* renderer
;
2043 int cmnVal
= p
->GetCommonValue();
2044 if ( cmnVal
== -1 || ci
!= 1 )
2046 renderer
= p
->GetCellRenderer(ci
);
2047 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2052 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2053 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2058 cellX
+= state
->m_colWidths
[ci
];
2059 if ( ci
< (state
->m_colWidths
.size()-1) )
2060 nextCellWidth
= state
->m_colWidths
[ci
+1];
2062 dc
.DestroyClippingRegion(); // Is this really necessary?
2068 dc
.SetFont(normalfont
);
2073 // Refresh editor controls (seems not needed on msw)
2074 // NOTE: This code is mandatory for GTK!
2075 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2076 if ( wasSelectedPainted
)
2079 m_wndEditor
->Refresh();
2081 m_wndEditor2
->Refresh();
2088 // -----------------------------------------------------------------------
2090 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2094 if ( m_width
< 10 || m_height
< 10 ||
2095 !m_pState
->m_properties
->GetChildCount() ||
2096 p1
== (wxPGProperty
*) NULL
)
2097 return wxRect(0,0,0,0);
2102 // Return rect which encloses the given property range
2104 int visTop
= p1
->GetY();
2107 visBottom
= p2
->GetY() + m_lineHeight
;
2109 visBottom
= m_height
+ visTop
;
2111 // If seleced property is inside the range, we'll extend the range to include
2113 wxPGProperty
* selected
= m_selected
;
2116 int selectedY
= selected
->GetY();
2117 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2119 wxWindow
* editor
= GetEditorControl();
2122 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2123 if ( visBottom2
> visBottom
)
2124 visBottom
= visBottom2
;
2129 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2132 // -----------------------------------------------------------------------
2134 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2139 if ( m_pState
->m_itemsAdded
)
2140 PrepareAfterItemsAdded();
2142 wxRect r
= GetPropertyRect(p1
, p2
);
2145 m_canvas
->RefreshRect(r
);
2149 // -----------------------------------------------------------------------
2151 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2153 if ( p
== m_selected
)
2154 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2156 DrawItemAndChildren(p
);
2159 // -----------------------------------------------------------------------
2161 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2166 // Draw item, children, and parent too, if it is not category
2167 wxPGProperty
* parent
= p
->GetParent();
2170 !parent
->IsCategory() &&
2171 parent
->GetParent() )
2174 parent
= parent
->GetParent();
2177 DrawItemAndChildren(p
);
2180 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2182 wxCHECK_RET( p
, wxT("invalid property id") );
2184 // Do not draw if in non-visible page
2185 if ( p
->GetParentState() != m_pState
)
2188 // do not draw a single item if multiple pending
2189 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2192 wxWindow
* wndPrimary
= GetEditorControl();
2194 // Update child control.
2195 if ( m_selected
&& m_selected
->GetParent() == p
)
2196 m_selected
->UpdateControl(wndPrimary
);
2198 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2200 DrawItems(p
, lastDrawn
);
2203 // -----------------------------------------------------------------------
2205 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2206 const wxRect
*rect
)
2208 PrepareAfterItemsAdded();
2210 wxWindow::Refresh(false);
2212 // TODO: Coordinate translation
2213 m_canvas
->Refresh(false, rect
);
2215 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2216 // I think this really helps only GTK+1.2
2217 if ( m_wndEditor
) m_wndEditor
->Refresh();
2218 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2222 // -----------------------------------------------------------------------
2223 // wxPropertyGrid global operations
2224 // -----------------------------------------------------------------------
2226 void wxPropertyGrid::Clear()
2230 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2231 wxPG_CHECK_RET_DBG( selRes
,
2232 wxT("failed to deselect a property (editor probably had invalid value)") );
2235 m_pState
->DoClear();
2241 RecalculateVirtualSize();
2243 // Need to clear some area at the end
2245 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2248 // -----------------------------------------------------------------------
2250 bool wxPropertyGrid::EnableCategories( bool enable
)
2252 if ( !ClearSelection() )
2258 // Enable categories
2261 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2266 // Disable categories
2268 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2271 if ( !m_pState
->EnableCategories(enable
) )
2276 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2278 m_pState
->m_itemsAdded
= 1; // force
2279 PrepareAfterItemsAdded();
2283 m_pState
->m_itemsAdded
= 1;
2285 // No need for RecalculateVirtualSize() here - it is already called in
2286 // wxPropertyGridPageState method above.
2293 // -----------------------------------------------------------------------
2295 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2297 wxASSERT( pNewState
);
2298 wxASSERT( pNewState
->GetGrid() );
2300 if ( pNewState
== m_pState
)
2303 wxPGProperty
* oldSelection
= m_selected
;
2308 bool selRes
= ClearSelection();
2309 wxPG_CHECK_RET_DBG( selRes
,
2310 wxT("failed to deselect a property (editor probably had invalid value)") );
2313 m_pState
->m_selected
= oldSelection
;
2315 bool orig_mode
= m_pState
->IsInNonCatMode();
2316 bool new_state_mode
= pNewState
->IsInNonCatMode();
2318 m_pState
= pNewState
;
2321 int pgWidth
= GetClientSize().x
;
2322 if ( HasVirtualWidth() )
2324 int minWidth
= pgWidth
;
2325 if ( pNewState
->m_width
< minWidth
)
2327 pNewState
->m_width
= minWidth
;
2328 pNewState
->CheckColumnWidths();
2334 // Just in case, fully re-center splitter
2335 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2336 pNewState
->m_fSplitterX
= -1.0;
2338 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2341 m_propHover
= (wxPGProperty
*) NULL
;
2343 // If necessary, convert state to correct mode.
2344 if ( orig_mode
!= new_state_mode
)
2346 // This should refresh as well.
2347 EnableCategories( orig_mode
?false:true );
2349 else if ( !m_frozen
)
2351 // Refresh, if not frozen.
2352 if ( m_pState
->m_itemsAdded
)
2353 PrepareAfterItemsAdded();
2356 if ( m_pState
->m_selected
)
2357 DoSelectProperty( m_pState
->m_selected
);
2359 RecalculateVirtualSize(0);
2363 m_pState
->m_itemsAdded
= 1;
2366 // -----------------------------------------------------------------------
2368 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2370 wxPG_PROP_ARG_CALL_PROLOG()
2372 m_pState
->SortChildren( p
);
2375 // -----------------------------------------------------------------------
2377 void wxPropertyGrid::Sort()
2379 bool selRes
= ClearSelection(); // This must be before state clear
2380 wxPG_CHECK_RET_DBG( selRes
,
2381 wxT("failed to deselect a property (editor probably had invalid value)") );
2386 // -----------------------------------------------------------------------
2388 // Call to SetSplitterPosition will always disable splitter auto-centering
2389 // if parent window is shown.
2390 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2392 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2395 wxPropertyGridPageState
* state
= m_pState
;
2397 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2402 CorrectEditorWidgetSizeX();
2408 // -----------------------------------------------------------------------
2410 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2412 SetSplitterPosition( m_width
/2, true );
2413 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2414 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2417 // -----------------------------------------------------------------------
2418 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2419 // -----------------------------------------------------------------------
2421 // Returns nearest paint visible property (such that will be painted unless
2422 // window is scrolled or resized). If given property is paint visible, then
2423 // it itself will be returned
2424 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2426 int vx
,vy1
;// Top left corner of client
2427 GetViewStart(&vx
,&vy1
);
2428 vy1
*= wxPG_PIXELS_PER_UNIT
;
2430 int vy2
= vy1
+ m_height
;
2431 int propY
= p
->GetY2(m_lineHeight
);
2433 if ( (propY
+ m_lineHeight
) < vy1
)
2436 return DoGetItemAtY( vy1
);
2438 else if ( propY
> vy2
)
2441 return DoGetItemAtY( vy2
);
2444 // Itself paint visible
2449 // -----------------------------------------------------------------------
2450 // Methods related to change in value, value modification and sending events
2451 // -----------------------------------------------------------------------
2453 // commits any changes in editor of selected property
2454 // return true if validation did not fail
2455 // flags are same as with DoSelectProperty
2456 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2458 // Committing already?
2459 if ( m_inCommitChangesFromEditor
)
2462 // Don't do this if already processing editor event. It might
2463 // induce recursive dialogs and crap like that.
2464 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2466 if ( m_inDoPropertyChanged
)
2473 IsEditorsValueModified() &&
2474 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2477 m_inCommitChangesFromEditor
= 1;
2479 wxVariant
variant(m_selected
->GetValueRef());
2480 bool valueIsPending
= false;
2482 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2483 // due to another window getting focus
2484 wxWindow
* oldFocus
= m_curFocused
;
2486 bool validationFailure
= false;
2487 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2489 m_chgInfo_changedProperty
= NULL
;
2491 // If truly modified, schedule value as pending.
2492 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2494 if ( DoEditorValidate() &&
2495 PerformValidation(m_selected
, variant
) )
2497 valueIsPending
= true;
2501 validationFailure
= true;
2506 EditorsValueWasNotModified();
2511 m_inCommitChangesFromEditor
= 0;
2513 if ( validationFailure
&& !forceSuccess
)
2517 oldFocus
->SetFocus();
2518 m_curFocused
= oldFocus
;
2521 res
= OnValidationFailure(m_selected
, variant
);
2523 // Now prevent further validation failure messages
2526 EditorsValueWasNotModified();
2527 OnValidationFailureReset(m_selected
);
2530 else if ( valueIsPending
)
2532 DoPropertyChanged( m_selected
, flags
);
2533 EditorsValueWasNotModified();
2542 // -----------------------------------------------------------------------
2544 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2548 // Runs all validation functionality.
2549 // Returns true if value passes all tests.
2552 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2554 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2556 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2561 // Adapt list to child values, if necessary
2562 wxVariant listValue
= pendingValue
;
2563 wxVariant
* pPendingValue
= &pendingValue
;
2564 wxVariant
* pList
= NULL
;
2566 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2567 // string value, then we need treat as it was changed instead
2568 // (or, in addition, as is the case with composite string parent).
2569 // This includes creating list variant for child values.
2571 wxPGProperty
* pwc
= p
->GetParent();
2572 wxPGProperty
* changedProperty
= p
;
2573 wxPGProperty
* baseChangedProperty
= changedProperty
;
2574 wxVariant bcpPendingList
;
2576 listValue
= pendingValue
;
2577 listValue
.SetName(p
->GetBaseName());
2580 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2582 wxVariantList tempList
;
2583 wxVariant
lv(tempList
, pwc
->GetBaseName());
2584 lv
.Append(listValue
);
2586 pPendingValue
= &listValue
;
2588 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2590 baseChangedProperty
= pwc
;
2591 bcpPendingList
= lv
;
2594 changedProperty
= pwc
;
2595 pwc
= pwc
->GetParent();
2599 wxPGProperty
* evtChangingProperty
= changedProperty
;
2601 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2603 value
= *pPendingValue
;
2607 // Convert list to child values
2608 pList
= pPendingValue
;
2609 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2612 wxVariant evtChangingValue
= value
;
2614 if ( flags
& SendEvtChanging
)
2616 // FIXME: After proper ValueToString()s added, remove
2617 // this. It is just a temporary fix, as evt_changing
2618 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2619 // (unless it is selected, and textctrl editor is open).
2620 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2622 evtChangingProperty
= baseChangedProperty
;
2623 if ( evtChangingProperty
!= p
)
2625 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2629 evtChangingValue
= pendingValue
;
2633 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2635 if ( changedProperty
== m_selected
)
2637 wxWindow
* editor
= GetEditorControl();
2638 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2639 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2643 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2648 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2649 m_chgInfo_changedProperty
= changedProperty
;
2650 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2651 m_chgInfo_pendingValue
= value
;
2654 m_chgInfo_valueList
= *pList
;
2656 m_chgInfo_valueList
.MakeNull();
2658 // If changedProperty is not property which value was edited,
2659 // then call wxPGProperty::ValidateValue() for that as well.
2660 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2662 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2666 if ( flags
& SendEvtChanging
)
2668 // SendEvent returns true if event was vetoed
2669 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2673 if ( flags
& IsStandaloneValidation
)
2675 // If called in 'generic' context, we need to reset
2676 // m_chgInfo_changedProperty and write back translated value.
2677 m_chgInfo_changedProperty
= NULL
;
2678 pendingValue
= value
;
2684 // -----------------------------------------------------------------------
2686 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2688 if ( !msg
.length() )
2692 if ( !wxPGGlobalVars
->m_offline
)
2694 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2697 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2700 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2703 pStatusBar
->SetStatusText(msg
);
2711 ::wxMessageBox(msg
, _T("Property Error"));
2714 // -----------------------------------------------------------------------
2716 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2718 int vfb
= m_validationInfo
.m_failureBehavior
;
2720 if ( vfb
& wxPG_VFB_BEEP
)
2723 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2724 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2726 unsigned int colCount
= m_pState
->GetColumnCount();
2728 // We need backup marked property's cells
2729 m_propCellsBackup
= property
->m_cells
;
2731 wxColour vfbFg
= *wxWHITE
;
2732 wxColour vfbBg
= *wxRED
;
2734 property
->EnsureCells(colCount
);
2736 for ( unsigned int i
=0; i
<colCount
; i
++ )
2738 wxPGCell
& cell
= property
->m_cells
[i
];
2739 cell
.SetFgCol(vfbFg
);
2740 cell
.SetBgCol(vfbBg
);
2743 DrawItemAndChildren(property
);
2745 if ( property
== m_selected
)
2747 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2749 wxWindow
* editor
= GetEditorControl();
2752 editor
->SetForegroundColour(vfbFg
);
2753 editor
->SetBackgroundColour(vfbBg
);
2758 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2760 wxString msg
= m_validationInfo
.m_failureMessage
;
2762 if ( !msg
.length() )
2763 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2765 DoShowPropertyError(property
, msg
);
2768 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2771 // -----------------------------------------------------------------------
2773 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2775 int vfb
= m_validationInfo
.m_failureBehavior
;
2777 if ( vfb
& wxPG_VFB_MARK_CELL
)
2780 property
->m_cells
= m_propCellsBackup
;
2782 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2784 if ( property
== m_selected
&& GetEditorControl() )
2786 // Calling this will recreate the control, thus resetting its colour
2787 RefreshProperty(property
);
2791 DrawItemAndChildren(property
);
2796 // -----------------------------------------------------------------------
2798 // flags are same as with DoSelectProperty
2799 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2801 if ( m_inDoPropertyChanged
)
2804 wxWindow
* editor
= GetEditorControl();
2806 m_pState
->m_anyModified
= 1;
2808 m_inDoPropertyChanged
= 1;
2810 // Maybe need to update control
2811 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2813 // These values were calculated in PerformValidation()
2814 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2815 wxVariant value
= m_chgInfo_pendingValue
;
2817 wxPGProperty
* topPaintedProperty
= changedProperty
;
2819 while ( !topPaintedProperty
->IsCategory() &&
2820 !topPaintedProperty
->IsRoot() )
2822 topPaintedProperty
= topPaintedProperty
->GetParent();
2825 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2827 // Set as Modified (not if dragging just began)
2828 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2830 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2831 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2834 SetCurControlBoldFont();
2840 // Propagate updates to parent(s)
2842 wxPGProperty
* prevPwc
= NULL
;
2844 while ( prevPwc
!= topPaintedProperty
)
2846 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2848 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2851 SetCurControlBoldFont();
2855 pwc
= pwc
->GetParent();
2858 // Draw the actual property
2859 DrawItemAndChildren( topPaintedProperty
);
2862 // If value was set by wxPGProperty::OnEvent, then update the editor
2864 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2867 p
->GetEditorClass()->UpdateControl(p
, editor
);
2871 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2872 if ( m_wndEditor
) m_wndEditor
->Refresh();
2873 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2878 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2880 // If top parent has composite string value, then send to child parents,
2881 // starting from baseChangedProperty.
2882 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2884 pwc
= m_chgInfo_baseChangedProperty
;
2886 while ( pwc
!= changedProperty
)
2888 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2889 pwc
= pwc
->GetParent();
2893 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2895 m_inDoPropertyChanged
= 0;
2900 // -----------------------------------------------------------------------
2902 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2904 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2906 m_chgInfo_changedProperty
= NULL
;
2908 if ( PerformValidation(p
, newValue
) )
2910 DoPropertyChanged(p
);
2915 OnValidationFailure(p
, newValue
);
2921 // -----------------------------------------------------------------------
2923 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2925 wxPGProperty
* prop
= GetSelectedProperty();
2928 return wxNullVariant
;
2930 wxTextCtrl
* tc
= GetEditorTextCtrl();
2931 wxVariant value
= prop
->GetValue();
2933 if ( !tc
|| !IsEditorsValueModified() )
2936 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2939 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2940 return prop
->GetValue();
2945 // -----------------------------------------------------------------------
2947 // Runs wxValidator for the selected property
2948 bool wxPropertyGrid::DoEditorValidate()
2953 // -----------------------------------------------------------------------
2955 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
2957 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
2958 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
2960 wxWindow
* parent
= wnd
->GetParent();
2963 (parent
== m_canvas
||
2964 parent
->GetParent() == m_canvas
) )
2966 OnCustomEditorEvent(event
);
2970 return wxPanel::ProcessEvent(event
);
2973 // -----------------------------------------------------------------------
2975 void wxPropertyGrid::OnCustomEditorEvent( wxEvent
&event
)
2977 wxPGProperty
* selected
= m_selected
;
2979 // Somehow, event is handled after property has been deselected.
2980 // Possibly, but very rare.
2984 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2987 wxVariant
pendingValue(selected
->GetValueRef());
2988 wxWindow
* wnd
= GetEditorControl();
2990 bool wasUnspecified
= selected
->IsValueUnspecified();
2991 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2993 bool valueIsPending
= false;
2995 m_chgInfo_changedProperty
= NULL
;
2997 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
3000 // Filter out excess wxTextCtrl modified events
3001 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
3003 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
3005 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
3007 wxString newTcValue
= tc
->GetValue();
3008 if ( m_prevTcValue
== newTcValue
)
3011 m_prevTcValue
= newTcValue
;
3014 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3016 bool validationFailure
= false;
3017 bool buttonWasHandled
= false;
3020 // Try common button handling
3021 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3023 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
3027 buttonWasHandled
= true;
3028 // Store as res2, as previously (and still currently alternatively)
3029 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
3030 // in wxPGProperty::OnEvent().
3031 adapter
->ShowDialog( this, selected
);
3036 if ( !buttonWasHandled
)
3040 // First call editor class' event handler.
3041 const wxPGEditor
* editor
= selected
->GetEditorClass();
3043 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
3045 // If changes, validate them
3046 if ( DoEditorValidate() )
3048 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3049 valueIsPending
= true;
3053 validationFailure
= true;
3058 // Then the property's custom handler (must be always called, unless
3059 // validation failed).
3060 if ( !validationFailure
)
3061 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3064 // SetValueInEvent(), as called in one of the functions referred above
3065 // overrides editor's value.
3066 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3068 valueIsPending
= true;
3069 pendingValue
= m_changeInEventValue
;
3070 selFlags
|= wxPG_SEL_DIALOGVAL
;
3073 if ( !validationFailure
&& valueIsPending
)
3074 if ( !PerformValidation(m_selected
, pendingValue
) )
3075 validationFailure
= true;
3077 if ( validationFailure
)
3079 OnValidationFailure(selected
, pendingValue
);
3081 else if ( valueIsPending
)
3083 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3085 DoPropertyChanged(selected
, selFlags
);
3086 EditorsValueWasNotModified();
3088 // Regardless of editor type, unfocus editor on
3089 // text-editing related enter press.
3090 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3097 // No value after all
3099 // Regardless of editor type, unfocus editor on
3100 // text-editing related enter press.
3101 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3106 // Let unhandled button click events go to the parent
3107 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3109 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3110 GetEventHandler()->AddPendingEvent(evt
);
3114 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3117 // -----------------------------------------------------------------------
3118 // wxPropertyGrid editor control helper methods
3119 // -----------------------------------------------------------------------
3121 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3123 int itemy
= p
->GetY2(m_lineHeight
);
3125 int cust_img_space
= 0;
3126 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3127 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3129 // TODO: If custom image detection changes from current, change this.
3130 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3132 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3133 int imwid
= p
->OnMeasureImage().x
;
3134 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3135 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3140 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3142 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3147 // -----------------------------------------------------------------------
3149 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3151 wxSize sz
= GetImageSize(p
, item
);
3152 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3153 wxPG_CUSTOM_IMAGE_SPACINGY
,
3158 // return size of custom paint image
3159 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3161 // If called with NULL property, then return default image
3162 // size for properties that use image.
3164 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3166 wxSize cis
= p
->OnMeasureImage(item
);
3168 int choiceCount
= p
->m_choices
.GetCount();
3169 int comVals
= p
->GetDisplayedCommonValueCount();
3170 if ( item
>= choiceCount
&& comVals
> 0 )
3172 unsigned int cvi
= item
-choiceCount
;
3173 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3175 else if ( item
>= 0 && choiceCount
== 0 )
3176 return wxSize(0, 0);
3181 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3186 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3193 // -----------------------------------------------------------------------
3195 // takes scrolling into account
3196 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3199 GetViewStart(&vx
,&vy
);
3200 vy
*=wxPG_PIXELS_PER_UNIT
;
3201 vx
*=wxPG_PIXELS_PER_UNIT
;
3204 ClientToScreen( px
, py
);
3207 // -----------------------------------------------------------------------
3209 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3212 GetViewStart(&pt2
.x
,&pt2
.y
);
3213 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3214 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3218 return m_pState
->HitTest(pt2
);
3221 // -----------------------------------------------------------------------
3223 // custom set cursor
3224 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3226 if ( type
== m_curcursor
&& !override
) return;
3228 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3230 if ( type
== wxCURSOR_SIZEWE
)
3231 cursor
= m_cursorSizeWE
;
3233 m_canvas
->SetCursor( *cursor
);
3238 // -----------------------------------------------------------------------
3239 // wxPropertyGrid property selection
3240 // -----------------------------------------------------------------------
3242 // Setups event handling for child control
3243 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3245 wxWindowID id
= argWnd
->GetId();
3247 if ( argWnd
== m_wndEditor
)
3249 argWnd
->Connect(id
, wxEVT_MOTION
,
3250 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3252 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3253 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3255 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3256 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3258 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3259 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3261 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3262 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3264 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3265 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3269 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3270 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3274 void wxPropertyGrid::FreeEditors()
3277 // Return focus back to canvas from children (this is required at least for
3278 // GTK+, which, unlike Windows, clears focus when control is destroyed
3279 // instead of moving it to closest parent).
3280 wxWindow
* focus
= wxWindow::FindFocus();
3283 wxWindow
* parent
= focus
->GetParent();
3286 if ( parent
== m_canvas
)
3291 parent
= parent
->GetParent();
3295 // Do not free editors immediately if processing events
3298 m_wndEditor2
->Hide();
3299 wxPendingDelete
.Append( m_wndEditor2
);
3300 m_wndEditor2
= (wxWindow
*) NULL
;
3305 m_wndEditor
->Hide();
3306 wxPendingDelete
.Append( m_wndEditor
);
3307 m_wndEditor
= (wxWindow
*) NULL
;
3311 // Call with NULL to de-select property
3312 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3314 wxPanel
* canvas
= GetPanel();
3318 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3319 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3321 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3324 if ( m_inDoSelectProperty
)
3327 m_inDoSelectProperty
= 1;
3329 wxPGProperty
* prev
= m_selected
;
3333 m_inDoSelectProperty
= 0;
3339 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3341 wxPrintf( "None selected\n" );
3344 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3346 wxPrintf( "P = NULL\n" );
3349 // If we are frozen, then just set the values.
3352 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3353 m_editorFocused
= 0;
3356 m_pState
->m_selected
= p
;
3358 // If frozen, always free controls. But don't worry, as Thaw will
3359 // recall SelectProperty to recreate them.
3362 // Prevent any further selection measures in this call
3363 p
= (wxPGProperty
*) NULL
;
3368 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3370 // Only set focus if not deselecting
3373 if ( flags
& wxPG_SEL_FOCUS
)
3377 m_wndEditor
->SetFocus();
3378 m_editorFocused
= 1;
3387 m_inDoSelectProperty
= 0;
3392 // First, deactivate previous
3396 OnValidationFailureReset(m_selected
);
3398 // Must double-check if this is an selected in case of forceswitch
3401 if ( !CommitChangesFromEditor(flags
) )
3403 // Validation has failed, so we can't exit the previous editor
3404 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3405 // _("Invalid Value"),wxOK|wxICON_ERROR);
3406 m_inDoSelectProperty
= 0;
3414 m_selected
= (wxPGProperty
*) NULL
;
3415 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3417 // We need to always fully refresh the grid here
3420 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3421 EditorsValueWasNotModified();
3424 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3427 // Then, activate the one given.
3430 int propY
= p
->GetY2(m_lineHeight
);
3432 int splitterX
= GetSplitterPosition();
3433 m_editorFocused
= 0;
3435 m_pState
->m_selected
= p
;
3436 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3438 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3440 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3442 // Do we need OnMeasureCalls?
3443 wxSize imsz
= p
->OnMeasureImage();
3446 // Only create editor for non-disabled non-caption
3447 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3449 // do this for non-caption items
3453 // Do we need to paint the custom image, if any?
3454 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3455 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3456 !p
->GetEditorClass()->CanContainCustomImage()
3458 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3460 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3461 wxPoint goodPos
= grect
.GetPosition();
3462 #if wxPG_CREATE_CONTROLS_HIDDEN
3463 int coord_adjust
= m_height
- goodPos
.y
;
3464 goodPos
.y
+= coord_adjust
;
3467 const wxPGEditor
* editor
= p
->GetEditorClass();
3468 wxCHECK_MSG(editor
, false,
3469 wxT("NULL editor class not allowed"));
3471 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3473 wxPGWindowList wndList
= editor
->CreateControls(this,
3478 m_wndEditor
= wndList
.m_primary
;
3479 m_wndEditor2
= wndList
.m_secondary
;
3480 wxWindow
* primaryCtrl
= GetEditorControl();
3483 // Essentially, primaryCtrl == m_wndEditor
3486 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3487 // value is drawn as normal, and m_wndEditor2 is assumed
3488 // to be a right-aligned button that triggers a separate editorCtrl
3493 wxASSERT_MSG( m_wndEditor
->GetParent() == canvas
,
3494 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3496 // Set validator, if any
3497 #if wxUSE_VALIDATORS
3498 wxValidator
* validator
= p
->GetValidator();
3500 primaryCtrl
->SetValidator(*validator
);
3503 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3504 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3506 // If it has modified status, use bold font
3507 // (must be done before capturing m_ctrlXAdjust)
3508 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3509 SetCurControlBoldFont();
3512 // Fix TextCtrl indentation
3513 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3514 wxTextCtrl
* tc
= NULL
;
3515 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3516 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3518 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3520 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3523 // Store x relative to splitter (we'll need it).
3524 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3526 // Check if background clear is not necessary
3527 wxPoint pos
= m_wndEditor
->GetPosition();
3528 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3530 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3533 m_wndEditor
->SetSizeHints(3, 3);
3535 #if wxPG_CREATE_CONTROLS_HIDDEN
3536 m_wndEditor
->Show(false);
3537 m_wndEditor
->Freeze();
3539 goodPos
= m_wndEditor
->GetPosition();
3540 goodPos
.y
-= coord_adjust
;
3541 m_wndEditor
->Move( goodPos
);
3544 SetupChildEventHandling(primaryCtrl
);
3546 // Focus and select all (wxTextCtrl, wxComboBox etc)
3547 if ( flags
& wxPG_SEL_FOCUS
)
3549 primaryCtrl
->SetFocus();
3551 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3557 wxASSERT_MSG( m_wndEditor2
->GetParent() == canvas
,
3558 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3560 // Get proper id for wndSecondary
3561 m_wndSecId
= m_wndEditor2
->GetId();
3562 wxWindowList children
= m_wndEditor2
->GetChildren();
3563 wxWindowList::iterator node
= children
.begin();
3564 if ( node
!= children
.end() )
3565 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3567 m_wndEditor2
->SetSizeHints(3,3);
3569 #if wxPG_CREATE_CONTROLS_HIDDEN
3570 wxRect sec_rect
= m_wndEditor2
->GetRect();
3571 sec_rect
.y
-= coord_adjust
;
3573 // Fine tuning required to fix "oversized"
3574 // button disappearance bug.
3575 if ( sec_rect
.y
< 0 )
3577 sec_rect
.height
+= sec_rect
.y
;
3580 m_wndEditor2
->SetSize( sec_rect
);
3582 m_wndEditor2
->Show();
3584 SetupChildEventHandling(m_wndEditor2
);
3586 // If no primary editor, focus to button to allow
3587 // it to interprete ENTER etc.
3588 // NOTE: Due to problems focusing away from it, this
3589 // has been disabled.
3591 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3592 m_wndEditor2->SetFocus();
3596 if ( flags
& wxPG_SEL_FOCUS
)
3597 m_editorFocused
= 1;
3602 // Make sure focus is in grid canvas (important for wxGTK, at least)
3606 EditorsValueWasNotModified();
3608 // If it's inside collapsed section, expand parent, scroll, etc.
3609 // Also, if it was partially visible, scroll it into view.
3610 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3615 #if wxPG_CREATE_CONTROLS_HIDDEN
3616 m_wndEditor
->Thaw();
3618 m_wndEditor
->Show(true);
3625 // Make sure focus is in grid canvas
3629 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3635 // Show help text in status bar.
3636 // (if found and grid not embedded in manager with help box and
3637 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3640 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3642 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3643 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3645 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3647 statusbar
= frame
->GetStatusBar();
3652 const wxString
* pHelpString
= (const wxString
*) NULL
;
3656 pHelpString
= &p
->GetHelpString();
3657 if ( pHelpString
->length() )
3659 // Set help box text.
3660 statusbar
->SetStatusText( *pHelpString
);
3661 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3665 if ( (!pHelpString
|| !pHelpString
->length()) &&
3666 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3668 // Clear help box - but only if it was written
3669 // by us at previous time.
3670 statusbar
->SetStatusText( m_emptyString
);
3671 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3677 m_inDoSelectProperty
= 0;
3679 // call wx event handler (here so that it also occurs on deselection)
3680 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3685 // -----------------------------------------------------------------------
3687 bool wxPropertyGrid::UnfocusEditor()
3689 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3692 if ( !CommitChangesFromEditor(0) )
3696 DrawItem(m_selected
);
3701 // -----------------------------------------------------------------------
3703 // This method is not inline because it called dozens of times
3704 // (i.e. two-arg function calls create smaller code size).
3705 bool wxPropertyGrid::DoClearSelection()
3707 return DoSelectProperty((wxPGProperty
*)NULL
);
3710 // -----------------------------------------------------------------------
3711 // wxPropertyGrid expand/collapse state
3712 // -----------------------------------------------------------------------
3714 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3716 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3718 // If active editor was inside collapsed section, then disable it
3719 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3721 if ( !ClearSelection() )
3725 // Store dont-center-splitter flag 'cause we need to temporarily set it
3726 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3727 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3729 bool res
= m_pState
->DoCollapse(pwc
);
3734 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3736 RecalculateVirtualSize();
3738 // Redraw etc. only if collapsed was visible.
3739 if (pwc
->IsVisible() &&
3741 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3743 // When item is collapsed so that scrollbar would move,
3744 // graphics mess is about (unless we redraw everything).
3749 // Clear dont-center-splitter flag if it wasn't set
3750 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3755 // -----------------------------------------------------------------------
3757 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3759 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3761 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3763 // Store dont-center-splitter flag 'cause we need to temporarily set it
3764 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3765 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3767 bool res
= m_pState
->DoExpand(pwc
);
3772 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3774 RecalculateVirtualSize();
3776 // Redraw etc. only if expanded was visible.
3777 if ( pwc
->IsVisible() && !m_frozen
&&
3778 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3782 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3785 DrawItems(pwc
, NULL
);
3790 // Clear dont-center-splitter flag if it wasn't set
3791 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3796 // -----------------------------------------------------------------------
3798 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3801 return m_pState
->DoHideProperty(p
, hide
, flags
);
3804 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3807 if ( !ClearSelection() )
3811 m_pState
->DoHideProperty(p
, hide
, flags
);
3813 RecalculateVirtualSize();
3820 // -----------------------------------------------------------------------
3821 // wxPropertyGrid size related methods
3822 // -----------------------------------------------------------------------
3824 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3826 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3830 // If virtual height was changed, then recalculate editor control position(s)
3831 if ( m_pState
->m_vhCalcPending
)
3832 CorrectEditorWidgetPosY();
3834 m_pState
->EnsureVirtualHeight();
3837 int by1
= m_pState
->GetVirtualHeight();
3838 int by2
= m_pState
->GetActualVirtualHeight();
3841 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3842 wxASSERT_MSG( false,
3848 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3850 int x
= m_pState
->m_width
;
3851 int y
= m_pState
->m_virtualHeight
;
3854 GetClientSize(&width
,&height
);
3856 // Now adjust virtual size.
3857 SetVirtualSize(x
, y
);
3863 // Adjust scrollbars
3864 if ( HasVirtualWidth() )
3866 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3867 xPos
= GetScrollPos( wxHORIZONTAL
);
3870 if ( forceXPos
!= -1 )
3873 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3876 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3877 int yPos
= GetScrollPos( wxVERTICAL
);
3879 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3880 xAmount
, yAmount
, xPos
, yPos
, true );
3882 // Must re-get size now
3883 GetClientSize(&width
,&height
);
3885 if ( !HasVirtualWidth() )
3887 m_pState
->SetVirtualWidth(width
);
3894 m_canvas
->SetSize( x
, y
);
3896 m_pState
->CheckColumnWidths();
3899 CorrectEditorWidgetSizeX();
3901 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3904 // -----------------------------------------------------------------------
3906 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3908 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3912 GetClientSize(&width
,&height
);
3917 #if wxPG_DOUBLE_BUFFER
3918 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3920 int dblh
= (m_lineHeight
*2);
3921 if ( !m_doubleBuffer
)
3923 // Create double buffer bitmap to draw on, if none
3924 int w
= (width
>250)?width
:250;
3925 int h
= height
+ dblh
;
3927 m_doubleBuffer
= new wxBitmap( w
, h
);
3931 int w
= m_doubleBuffer
->GetWidth();
3932 int h
= m_doubleBuffer
->GetHeight();
3934 // Double buffer must be large enough
3935 if ( w
< width
|| h
< (height
+dblh
) )
3937 if ( w
< width
) w
= width
;
3938 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3939 delete m_doubleBuffer
;
3940 m_doubleBuffer
= new wxBitmap( w
, h
);
3947 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3948 m_ncWidth
= event
.GetSize().x
;
3952 if ( m_pState
->m_itemsAdded
)
3953 PrepareAfterItemsAdded();
3955 // Without this, virtual size (atleast under wxGTK) will be skewed
3956 RecalculateVirtualSize();
3962 // -----------------------------------------------------------------------
3964 void wxPropertyGrid::SetVirtualWidth( int width
)
3968 // Disable virtual width
3969 width
= GetClientSize().x
;
3970 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3974 // Enable virtual width
3975 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3977 m_pState
->SetVirtualWidth( width
);
3980 void wxPropertyGrid::SetFocusOnCanvas()
3982 m_canvas
->SetFocusIgnoringChildren();
3983 m_editorFocused
= 0;
3986 // -----------------------------------------------------------------------
3987 // wxPropertyGrid mouse event handling
3988 // -----------------------------------------------------------------------
3990 // selFlags uses same values DoSelectProperty's flags
3991 // Returns true if event was vetoed.
3992 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3994 // Send property grid event of specific type and with specific property
3995 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3996 evt
.SetPropertyGrid(this);
3997 evt
.SetEventObject(m_eventObject
);
4001 evt
.SetCanVeto(true);
4002 evt
.SetupValidationInfo();
4003 m_validationInfo
.m_pValue
= pValue
;
4005 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4007 evtHandler
->ProcessEvent(evt
);
4009 return evt
.WasVetoed();
4012 // -----------------------------------------------------------------------
4014 // Return false if should be skipped
4015 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4019 // Need to set focus?
4020 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4025 wxPropertyGridPageState
* state
= m_pState
;
4027 int splitterHitOffset
;
4028 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4030 wxPGProperty
* p
= DoGetItemAtY(y
);
4034 int depth
= (int)p
->GetDepth() - 1;
4036 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4038 if ( x
>= marginEnds
)
4042 if ( p
->IsCategory() )
4044 // This is category.
4045 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4047 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4049 // Expand, collapse, activate etc. if click on text or left of splitter.
4052 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4057 if ( !DoSelectProperty( p
) )
4060 // On double-click, expand/collapse.
4061 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4063 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4064 else DoExpand( p
, true );
4068 else if ( splitterHit
== -1 )
4071 unsigned int selFlag
= 0;
4072 if ( columnHit
== 1 )
4074 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4075 selFlag
= wxPG_SEL_FOCUS
;
4077 if ( !DoSelectProperty( p
, selFlag
) )
4080 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4082 if ( p
->GetChildCount() && !p
->IsCategory() )
4083 // On double-click, expand/collapse.
4084 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4086 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4087 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4088 else DoExpand( p
, true );
4095 // click on splitter
4096 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4098 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4100 // Double-clicking the splitter causes auto-centering
4101 CenterSplitter( true );
4103 else if ( m_dragStatus
== 0 )
4106 // Begin draggin the splitter
4110 // Changes must be committed here or the
4111 // value won't be drawn correctly
4112 if ( !CommitChangesFromEditor() )
4115 m_wndEditor
->Show ( false );
4118 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4120 m_canvas
->CaptureMouse();
4121 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4125 m_draggedSplitter
= splitterHit
;
4126 m_dragOffset
= splitterHitOffset
;
4128 wxClientDC
dc(m_canvas
);
4130 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4131 // Fixes button disappearance bug
4133 m_wndEditor2
->Show ( false );
4136 m_startingSplitterX
= x
- splitterHitOffset
;
4144 if ( p
->GetChildCount() )
4146 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4148 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4150 int y2
= y
% m_lineHeight
;
4151 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4153 // On click on expander button, expand/collapse
4154 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4155 DoCollapse( p
, true );
4157 DoExpand( p
, true );
4166 // -----------------------------------------------------------------------
4168 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4169 wxMouseEvent
& WXUNUSED(event
) )
4173 // Select property here as well
4174 wxPGProperty
* p
= m_propHover
;
4175 if ( p
!= m_selected
)
4176 DoSelectProperty( p
);
4178 // Send right click event.
4179 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4186 // -----------------------------------------------------------------------
4188 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4189 wxMouseEvent
& WXUNUSED(event
) )
4193 // Select property here as well
4194 wxPGProperty
* p
= m_propHover
;
4196 if ( p
!= m_selected
)
4197 DoSelectProperty( p
);
4199 // Send double-click event.
4200 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4207 // -----------------------------------------------------------------------
4209 #if wxPG_SUPPORT_TOOLTIPS
4211 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4213 if ( tipString
.length() )
4215 m_canvas
->SetToolTip(tipString
);
4219 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4220 m_canvas
->SetToolTip( m_emptyString
);
4222 m_canvas
->SetToolTip( NULL
);
4227 #endif // #if wxPG_SUPPORT_TOOLTIPS
4229 // -----------------------------------------------------------------------
4231 // Return false if should be skipped
4232 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4234 // Safety check (needed because mouse capturing may
4235 // otherwise freeze the control)
4236 if ( m_dragStatus
> 0 && !event
.Dragging() )
4238 HandleMouseUp(x
,y
,event
);
4241 wxPropertyGridPageState
* state
= m_pState
;
4243 int splitterHitOffset
;
4244 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4245 int splitterX
= x
- splitterHitOffset
;
4247 if ( m_dragStatus
> 0 )
4249 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4250 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4253 int newSplitterX
= x
- m_dragOffset
;
4254 int splitterX
= x
- splitterHitOffset
;
4256 // Splitter redraw required?
4257 if ( newSplitterX
!= splitterX
)
4260 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4261 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4262 state
->m_fSplitterX
= (float) newSplitterX
;
4265 CorrectEditorWidgetSizeX();
4279 int ih
= m_lineHeight
;
4282 #if wxPG_SUPPORT_TOOLTIPS
4283 wxPGProperty
* prevHover
= m_propHover
;
4284 unsigned char prevSide
= m_mouseSide
;
4286 int curPropHoverY
= y
- (y
% ih
);
4288 // On which item it hovers
4289 if ( ( !m_propHover
)
4291 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4294 // Mouse moves on another property
4296 m_propHover
= DoGetItemAtY(y
);
4297 m_propHoverY
= curPropHoverY
;
4300 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4303 #if wxPG_SUPPORT_TOOLTIPS
4304 // Store which side we are on
4306 if ( columnHit
== 1 )
4308 else if ( columnHit
== 0 )
4312 // If tooltips are enabled, show label or value as a tip
4313 // in case it doesn't otherwise show in full length.
4315 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4317 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4319 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4321 if ( m_propHover
&& !m_propHover
->IsCategory() )
4324 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4326 // Show help string as a tooltip
4327 wxString tipString
= m_propHover
->GetHelpString();
4329 SetToolTip(tipString
);
4333 // Show cropped value string as a tooltip
4337 if ( m_mouseSide
== 1 )
4339 tipString
= m_propHover
->m_label
;
4340 space
= splitterX
-m_marginWidth
-3;
4342 else if ( m_mouseSide
== 2 )
4344 tipString
= m_propHover
->GetDisplayedString();
4346 space
= m_width
- splitterX
;
4347 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4348 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4354 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4357 SetToolTip( tipString
);
4364 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4365 m_canvas
->SetToolTip( m_emptyString
);
4367 m_canvas
->SetToolTip( NULL
);
4378 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4379 m_canvas
->SetToolTip( m_emptyString
);
4381 m_canvas
->SetToolTip( NULL
);
4389 if ( splitterHit
== -1 ||
4391 HasFlag(wxPG_STATIC_SPLITTER
) )
4393 // hovering on something else
4394 if ( m_curcursor
!= wxCURSOR_ARROW
)
4395 CustomSetCursor( wxCURSOR_ARROW
);
4399 // Do not allow splitter cursor on caption items.
4400 // (also not if we were dragging and its started
4401 // outside the splitter region)
4404 !m_propHover
->IsCategory() &&
4408 // hovering on splitter
4410 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4411 // reliably detected.
4412 //if ( m_curcursor != wxCURSOR_SIZEWE )
4413 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4419 // hovering on something else
4420 if ( m_curcursor
!= wxCURSOR_ARROW
)
4421 CustomSetCursor( wxCURSOR_ARROW
);
4428 // -----------------------------------------------------------------------
4430 // Also handles Leaving event
4431 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4432 wxMouseEvent
&WXUNUSED(event
) )
4434 wxPropertyGridPageState
* state
= m_pState
;
4438 int splitterHitOffset
;
4439 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4441 // No event type check - basicly calling this method should
4442 // just stop dragging.
4443 // Left up after dragged?
4444 if ( m_dragStatus
>= 1 )
4447 // End Splitter Dragging
4449 // DO NOT ENABLE FOLLOWING LINE!
4450 // (it is only here as a reminder to not to do it)
4453 // Disable splitter auto-centering
4454 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4456 // This is necessary to return cursor
4457 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4459 m_canvas
->ReleaseMouse();
4460 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4463 // Set back the default cursor, if necessary
4464 if ( splitterHit
== -1 ||
4467 CustomSetCursor( wxCURSOR_ARROW
);
4472 // Control background needs to be cleared
4473 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4474 DrawItem( m_selected
);
4478 m_wndEditor
->Show ( true );
4481 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4482 // Fixes button disappearance bug
4484 m_wndEditor2
->Show ( true );
4487 // This clears the focus.
4488 m_editorFocused
= 0;
4494 // -----------------------------------------------------------------------
4496 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4498 int splitterX
= GetSplitterPosition();
4501 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4505 wxWindow
* wnd
= GetEditorControl();
4507 // Hide popup on clicks
4508 if ( event
.GetEventType() != wxEVT_MOTION
)
4509 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4511 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4517 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4519 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4520 ux
>= (r
.x
+r
.width
) ||
4522 event
.m_y
>= (r
.y
+r
.height
)
4532 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4537 // -----------------------------------------------------------------------
4539 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4542 if ( OnMouseCommon( event
, &x
, &y
) )
4544 HandleMouseClick(x
,y
,event
);
4549 // -----------------------------------------------------------------------
4551 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4554 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4555 HandleMouseRightClick(x
,y
,event
);
4559 // -----------------------------------------------------------------------
4561 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4563 // Always run standard mouse-down handler as well
4564 OnMouseClick(event
);
4567 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4568 HandleMouseDoubleClick(x
,y
,event
);
4572 // -----------------------------------------------------------------------
4574 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4577 if ( OnMouseCommon( event
, &x
, &y
) )
4579 HandleMouseMove(x
,y
,event
);
4584 // -----------------------------------------------------------------------
4586 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4588 // Called when mouse moves in the empty space below the properties.
4589 CustomSetCursor( wxCURSOR_ARROW
);
4592 // -----------------------------------------------------------------------
4594 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4597 if ( OnMouseCommon( event
, &x
, &y
) )
4599 HandleMouseUp(x
,y
,event
);
4604 // -----------------------------------------------------------------------
4606 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4608 // This may get called from child control as well, so event's
4609 // mouse position cannot be relied on.
4611 if ( event
.Entering() )
4613 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4615 // TODO: Fix this (detect parent and only do
4616 // cursor trick if it is a manager).
4617 wxASSERT( GetParent() );
4618 GetParent()->SetCursor(wxNullCursor
);
4620 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4623 GetParent()->SetCursor(wxNullCursor
);
4625 else if ( event
.Leaving() )
4627 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4628 m_canvas
->SetCursor( wxNullCursor
);
4630 // Get real cursor position
4631 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4633 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4636 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4638 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4642 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4650 // -----------------------------------------------------------------------
4652 // Common code used by various OnMouseXXXChild methods.
4653 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4655 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4656 wxASSERT( topCtrlWnd
);
4658 event
.GetPosition(&x
,&y
);
4660 int splitterX
= GetSplitterPosition();
4662 wxRect r
= topCtrlWnd
->GetRect();
4663 if ( !m_dragStatus
&&
4664 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4665 y
>= 0 && y
< r
.height \
4668 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4673 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4680 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4683 if ( OnMouseChildCommon(event
,&x
,&y
) )
4685 bool res
= HandleMouseClick(x
,y
,event
);
4686 if ( !res
) event
.Skip();
4690 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4693 wxASSERT( m_wndEditor
);
4694 // These coords may not be exact (about +-2),
4695 // but that should not matter (right click is about item, not position).
4696 wxPoint pt
= m_wndEditor
->GetPosition();
4697 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4698 wxASSERT( m_selected
);
4699 m_propHover
= m_selected
;
4700 bool res
= HandleMouseRightClick(x
,y
,event
);
4701 if ( !res
) event
.Skip();
4704 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4707 if ( OnMouseChildCommon(event
,&x
,&y
) )
4709 bool res
= HandleMouseMove(x
,y
,event
);
4710 if ( !res
) event
.Skip();
4714 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4717 if ( OnMouseChildCommon(event
,&x
,&y
) )
4719 bool res
= HandleMouseUp(x
,y
,event
);
4720 if ( !res
) event
.Skip();
4724 // -----------------------------------------------------------------------
4725 // wxPropertyGrid keyboard event handling
4726 // -----------------------------------------------------------------------
4728 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4730 // Translates wxKeyEvent to wxPG_ACTION_XXX
4732 int keycode
= event
.GetKeyCode();
4733 int modifiers
= event
.GetModifiers();
4735 wxASSERT( !(modifiers
&~(0xFFFF)) );
4737 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4739 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4741 if ( it
== m_actionTriggers
.end() )
4746 int second
= (it
->second
>>16) & 0xFFFF;
4750 return (it
->second
& 0xFFFF);
4753 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4755 wxASSERT( !(modifiers
&~(0xFFFF)) );
4757 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4759 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4761 if ( it
!= m_actionTriggers
.end() )
4763 // This key combination is already used
4765 // Can add secondary?
4766 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4767 wxT("You can only add up to two separate actions per key combination.") );
4769 action
= it
->second
| (action
<<16);
4772 m_actionTriggers
[hashMapKey
] = action
;
4775 void wxPropertyGrid::ClearActionTriggers( int action
)
4777 wxPGHashMapI2I::iterator it
;
4779 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4781 if ( it
->second
== action
)
4783 m_actionTriggers
.erase(it
);
4788 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4791 // Handles key event when editor control is not focused.
4794 wxASSERT( !m_frozen
);
4798 // Travelsal between items, collapsing/expanding, etc.
4799 int keycode
= event
.GetKeyCode();
4800 bool editorFocused
= IsEditorFocused();
4802 if ( keycode
== WXK_TAB
)
4804 wxWindow
* mainControl
;
4806 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4807 mainControl
= GetParent();
4811 if ( !event
.ShiftDown() )
4813 if ( !editorFocused
&& m_wndEditor
)
4815 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4819 // Tab traversal workaround for platforms on which
4820 // wxWindow::Navigate() may navigate into first child
4821 // instead of next sibling. Does not work perfectly
4822 // in every scenario (for instance, when property grid
4823 // is either first or last control).
4824 #if defined(__WXGTK__)
4825 wxWindow
* sibling
= mainControl
->GetNextSibling();
4827 sibling
->SetFocusFromKbd();
4829 Navigate(wxNavigationKeyEvent::IsForward
);
4835 if ( editorFocused
)
4841 #if defined(__WXGTK__)
4842 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4844 sibling
->SetFocusFromKbd();
4846 Navigate(wxNavigationKeyEvent::IsBackward
);
4854 // Ignore Alt and Control when they are down alone
4855 if ( keycode
== WXK_ALT
||
4856 keycode
== WXK_CONTROL
)
4863 int action
= KeyEventToActions(event
, &secondAction
);
4865 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4868 // Esc cancels any changes
4869 if ( IsEditorsValueModified() )
4871 EditorsValueWasNotModified();
4873 // Update the control as well
4874 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4876 m_selected
->GetDisplayedString() );
4879 OnValidationFailureReset(m_selected
);
4885 // Except for TAB and ESC, handle child control events in child control
4892 bool wasHandled
= false;
4897 if ( ButtonTriggerKeyTest(action
, event
) )
4900 wxPGProperty
* p
= m_selected
;
4902 // Travel and expand/collapse
4905 if ( p
->GetChildCount() &&
4906 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4909 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4911 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4914 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4916 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4923 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4927 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4933 if ( selectDir
>= -1 )
4935 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4937 DoSelectProperty(p
);
4943 // If nothing was selected, select the first item now
4944 // (or navigate out of tab).
4945 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4947 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4948 if ( p
) DoSelectProperty(p
);
4957 // -----------------------------------------------------------------------
4959 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4961 HandleKeyEvent(event
, false);
4964 // -----------------------------------------------------------------------
4966 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4971 action
= KeyEventToActions(event
, &secondAction
);
4974 // Does the keycode trigger button?
4975 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4978 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4979 GetEventHandler()->AddPendingEvent(evt
);
4986 // -----------------------------------------------------------------------
4988 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4990 HandleKeyEvent(event
, true);
4993 // -----------------------------------------------------------------------
4994 // wxPropertyGrid miscellaneous event handling
4995 // -----------------------------------------------------------------------
4997 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
5000 // Check if the focus is in this control or one of its children
5001 wxWindow
* newFocused
= wxWindow::FindFocus();
5003 if ( newFocused
!= m_curFocused
)
5004 HandleFocusChange( newFocused
);
5007 bool wxPropertyGrid::IsEditorFocused() const
5009 wxWindow
* focus
= wxWindow::FindFocus();
5011 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5012 focus
== GetEditorControl() )
5018 // Called by focus event handlers. newFocused is the window that becomes focused.
5019 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5021 unsigned int oldFlags
= m_iFlags
;
5023 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5025 wxWindow
* parent
= newFocused
;
5027 // This must be one of nextFocus' parents.
5030 // Use m_eventObject, which is either wxPropertyGrid or
5031 // wxPropertyGridManager, as appropriate.
5032 if ( parent
== m_eventObject
)
5034 m_iFlags
|= wxPG_FL_FOCUSED
;
5037 parent
= parent
->GetParent();
5040 m_curFocused
= newFocused
;
5042 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5043 (oldFlags
& wxPG_FL_FOCUSED
) )
5045 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5047 // Need to store changed value
5048 CommitChangesFromEditor();
5054 // Preliminary code for tab-order respecting
5055 // tab-traversal (but should be moved to
5058 wxWindow* prevFocus = event.GetWindow();
5059 wxWindow* useThis = this;
5060 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5061 useThis = GetParent();
5064 prevFocus->GetParent() == useThis->GetParent() )
5066 wxList& children = useThis->GetParent()->GetChildren();
5068 wxNode* node = children.Find(prevFocus);
5070 if ( node->GetNext() &&
5071 useThis == node->GetNext()->GetData() )
5072 DoSelectProperty(GetFirst());
5073 else if ( node->GetPrevious () &&
5074 useThis == node->GetPrevious()->GetData() )
5075 DoSelectProperty(GetLastProperty());
5082 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5083 DrawItem( m_selected
);
5087 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5089 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5090 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5091 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5092 //else if ( event.GetWindow() )
5094 HandleFocusChange(event
.GetWindow());
5099 // -----------------------------------------------------------------------
5101 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5103 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5106 // event.Skip() being commented out is aworkaround for bug reported
5107 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5111 // -----------------------------------------------------------------------
5113 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5115 m_iFlags
|= wxPG_FL_SCROLLED
;
5120 // -----------------------------------------------------------------------
5122 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5124 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5126 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5130 // -----------------------------------------------------------------------
5131 // Property editor related functions
5132 // -----------------------------------------------------------------------
5134 // noDefCheck = true prevents infinite recursion.
5135 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5138 wxASSERT( editorClass
);
5140 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5141 RegisterDefaultEditors();
5143 wxString name
= editorClass
->GetName();
5145 // Existing editor under this name?
5146 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5148 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5150 // If this name was already used, try class name.
5151 name
= editorClass
->GetClassInfo()->GetClassName();
5152 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5155 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5156 (wxPGEditor
*) vt_it
->second
,
5157 "Editor with given name was already registered" );
5159 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5164 // Use this in RegisterDefaultEditors.
5165 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5166 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5168 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5169 new wxPG##EDITOR##Editor, true ); \
5172 // Registers all default editor classes
5173 void wxPropertyGrid::RegisterDefaultEditors()
5175 wxPGRegisterDefaultEditorClass( TextCtrl
);
5176 wxPGRegisterDefaultEditorClass( Choice
);
5177 wxPGRegisterDefaultEditorClass( ComboBox
);
5178 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5179 #if wxPG_INCLUDE_CHECKBOX
5180 wxPGRegisterDefaultEditorClass( CheckBox
);
5182 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5184 // Register SpinCtrl etc. editors before use
5185 RegisterAdditionalEditors();
5188 // -----------------------------------------------------------------------
5189 // wxPGStringTokenizer
5190 // Needed to handle C-style string lists (e.g. "str1" "str2")
5191 // -----------------------------------------------------------------------
5193 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5194 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5198 wxPGStringTokenizer::~wxPGStringTokenizer()
5202 bool wxPGStringTokenizer::HasMoreTokens()
5204 const wxString
& str
= *m_str
;
5206 wxString::const_iterator i
= m_curPos
;
5208 wxUniChar delim
= m_delimeter
;
5210 wxUniChar prev_a
= wxT('\0');
5212 bool inToken
= false;
5214 while ( i
!= str
.end() )
5223 m_readyToken
.clear();
5228 if ( prev_a
!= wxT('\\') )
5232 if ( a
!= wxT('\\') )
5252 m_curPos
= str
.end();
5260 wxString
wxPGStringTokenizer::GetNextToken()
5262 return m_readyToken
;
5265 // -----------------------------------------------------------------------
5267 // -----------------------------------------------------------------------
5269 wxPGChoiceEntry::wxPGChoiceEntry()
5270 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5274 // -----------------------------------------------------------------------
5276 // -----------------------------------------------------------------------
5278 wxPGChoicesData::wxPGChoicesData()
5283 wxPGChoicesData::~wxPGChoicesData()
5288 void wxPGChoicesData::Clear()
5293 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5295 wxASSERT( m_items
.size() == 0 );
5297 m_items
= data
->m_items
;
5300 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5301 const wxPGChoiceEntry
& item
)
5303 wxVector
<wxPGChoiceEntry
>::iterator it
;
5307 index
= (int) m_items
.size();
5311 it
= m_items
.begin() + index
;
5314 m_items
.insert(it
, item
);
5316 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5318 // Need to fix value?
5319 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5320 ownEntry
.SetValue(index
);
5325 // -----------------------------------------------------------------------
5327 // -----------------------------------------------------------------------
5329 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5333 wxPGChoiceEntry
entry(label
, value
);
5334 return m_data
->Insert( -1, entry
);
5337 // -----------------------------------------------------------------------
5339 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5343 wxPGChoiceEntry
entry(label
, value
);
5344 entry
.SetBitmap(bitmap
);
5345 return m_data
->Insert( -1, entry
);
5348 // -----------------------------------------------------------------------
5350 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5353 return m_data
->Insert( index
, entry
);
5356 // -----------------------------------------------------------------------
5358 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5362 wxPGChoiceEntry
entry(label
, value
);
5363 return m_data
->Insert( index
, entry
);
5366 // -----------------------------------------------------------------------
5368 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5374 while ( index
< GetCount() )
5376 int cmpRes
= GetLabel(index
).Cmp(label
);
5382 wxPGChoiceEntry
entry(label
, value
);
5383 return m_data
->Insert( index
, entry
);
5386 // -----------------------------------------------------------------------
5388 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5392 unsigned int itemcount
= 0;
5393 const wxChar
** p
= &labels
[0];
5394 while ( *p
) { p
++; itemcount
++; }
5397 for ( i
= 0; i
< itemcount
; i
++ )
5402 wxPGChoiceEntry
entry(labels
[i
], value
);
5403 m_data
->Insert( i
, entry
);
5407 // -----------------------------------------------------------------------
5409 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5414 unsigned int itemcount
= arr
.size();
5416 for ( i
= 0; i
< itemcount
; i
++ )
5419 if ( &arrint
&& arrint
.size() )
5421 wxPGChoiceEntry
entry(arr
[i
], value
);
5422 m_data
->Insert( i
, entry
);
5426 // -----------------------------------------------------------------------
5428 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5430 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5431 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5432 m_data
->m_items
.begin()+nIndex
+count
);
5435 // -----------------------------------------------------------------------
5437 int wxPGChoices::Index( const wxString
& str
) const
5442 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5444 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5445 if ( entry
.HasText() && entry
.GetText() == str
)
5452 // -----------------------------------------------------------------------
5454 int wxPGChoices::Index( int val
) const
5459 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5461 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5462 if ( entry
.GetValue() == val
)
5469 // -----------------------------------------------------------------------
5471 wxArrayString
wxPGChoices::GetLabels() const
5476 if ( this && IsOk() )
5477 for ( i
=0; i
<GetCount(); i
++ )
5478 arr
.push_back(GetLabel(i
));
5483 // -----------------------------------------------------------------------
5485 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5492 for ( i
=0; i
< strings
.size(); i
++ )
5494 int index
= Index(strings
[i
]);
5496 arr
.Add(GetValue(index
));
5498 arr
.Add(wxPG_INVALID_VALUE
);
5505 // -----------------------------------------------------------------------
5507 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5508 wxArrayString
* unmatched
) const
5515 for ( i
=0; i
< strings
.size(); i
++ )
5517 const wxString
& str
= strings
[i
];
5518 int index
= Index(str
);
5521 else if ( unmatched
)
5522 unmatched
->Add(str
);
5529 // -----------------------------------------------------------------------
5531 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5535 if ( data
!= wxPGChoicesEmptyData
)
5542 // -----------------------------------------------------------------------
5544 void wxPGChoices::Init()
5546 m_data
= wxPGChoicesEmptyData
;
5549 // -----------------------------------------------------------------------
5551 void wxPGChoices::Free()
5553 if ( m_data
!= wxPGChoicesEmptyData
)
5556 m_data
= wxPGChoicesEmptyData
;
5560 // -----------------------------------------------------------------------
5561 // wxPropertyGridEvent
5562 // -----------------------------------------------------------------------
5564 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5567 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5568 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5569 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5570 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5571 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5572 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5573 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5574 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5575 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5578 // -----------------------------------------------------------------------
5580 void wxPropertyGridEvent::Init()
5582 m_validationInfo
= NULL
;
5584 m_wasVetoed
= false;
5587 // -----------------------------------------------------------------------
5589 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5590 : wxCommandEvent(commandType
,id
)
5596 // -----------------------------------------------------------------------
5598 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5599 : wxCommandEvent(event
)
5601 m_eventType
= event
.GetEventType();
5602 m_eventObject
= event
.m_eventObject
;
5604 m_property
= event
.m_property
;
5605 m_validationInfo
= event
.m_validationInfo
;
5606 m_canVeto
= event
.m_canVeto
;
5607 m_wasVetoed
= event
.m_wasVetoed
;
5610 // -----------------------------------------------------------------------
5612 wxPropertyGridEvent::~wxPropertyGridEvent()
5616 // -----------------------------------------------------------------------
5618 wxEvent
* wxPropertyGridEvent::Clone() const
5620 return new wxPropertyGridEvent( *this );
5623 // -----------------------------------------------------------------------
5624 // wxPropertyGridPopulator
5625 // -----------------------------------------------------------------------
5627 wxPropertyGridPopulator::wxPropertyGridPopulator()
5631 wxPGGlobalVars
->m_offline
++;
5634 // -----------------------------------------------------------------------
5636 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5639 m_propHierarchy
.clear();
5642 // -----------------------------------------------------------------------
5644 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5650 // -----------------------------------------------------------------------
5652 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5655 // Free unused sets of choices
5656 wxPGHashMapS2P::iterator it
;
5658 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5660 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5667 m_pg
->GetPanel()->Refresh();
5669 wxPGGlobalVars
->m_offline
--;
5672 // -----------------------------------------------------------------------
5674 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5675 const wxString
& propLabel
,
5676 const wxString
& propName
,
5677 const wxString
* propValue
,
5678 wxPGChoices
* pChoices
)
5680 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5681 wxPGProperty
* parent
= GetCurParent();
5683 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5685 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5689 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5691 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5695 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5697 property
->SetLabel(propLabel
);
5698 property
->DoSetName(propName
);
5700 if ( pChoices
&& pChoices
->IsOk() )
5701 property
->SetChoices(*pChoices
);
5703 m_state
->DoInsert(parent
, -1, property
);
5706 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5707 wxPG_PROGRAMMATIC_VALUE
);
5712 // -----------------------------------------------------------------------
5714 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5716 m_propHierarchy
.push_back(property
);
5717 DoScanForChildren();
5718 m_propHierarchy
.pop_back();
5721 // -----------------------------------------------------------------------
5723 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5724 const wxString
& idString
)
5726 wxPGChoices choices
;
5729 if ( choicesString
[0] == wxT('@') )
5731 wxString ids
= choicesString
.substr(1);
5732 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5733 if ( it
== m_dictIdChoices
.end() )
5734 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5736 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5741 if ( idString
.length() )
5743 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5744 if ( it
!= m_dictIdChoices
.end() )
5746 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5753 // Parse choices string
5754 wxString::const_iterator it
= choicesString
.begin();
5758 bool labelValid
= false;
5760 for ( ; it
!= choicesString
.end(); it
++ )
5766 if ( c
== wxT('"') )
5771 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5772 choices
.Add(label
, l
);
5775 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5780 else if ( c
== wxT('=') )
5787 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5794 if ( c
== wxT('"') )
5807 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5808 choices
.Add(label
, l
);
5811 if ( !choices
.IsOk() )
5813 choices
.EnsureData();
5817 if ( idString
.length() )
5818 m_dictIdChoices
[idString
] = choices
.GetData();
5825 // -----------------------------------------------------------------------
5827 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5829 if ( s
.Last() == wxT('%') )
5831 wxString s2
= s
.substr(0,s
.length()-1);
5833 if ( s2
.ToLong(&val
, 10) )
5835 *pval
= (val
*max
)/100;
5841 return s
.ToLong(pval
, 10);
5844 // -----------------------------------------------------------------------
5846 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5847 const wxString
& type
,
5848 const wxString
& value
)
5850 int l
= m_propHierarchy
.size();
5854 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5855 wxString valuel
= value
.Lower();
5858 if ( type
.length() == 0 )
5863 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5865 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5867 else if ( value
.ToLong(&v
, 0) )
5874 if ( type
== wxT("string") )
5878 else if ( type
== wxT("int") )
5881 value
.ToLong(&v
, 0);
5884 else if ( type
== wxT("bool") )
5886 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5893 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5898 p
->SetAttribute( name
, variant
);
5903 // -----------------------------------------------------------------------
5905 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5907 wxLogError(_("Error in resource: %s"),msg
.c_str());
5910 // -----------------------------------------------------------------------
5912 #endif // wxUSE_PROPGRID