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
)
3316 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3317 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3319 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3322 if ( m_inDoSelectProperty
)
3325 m_inDoSelectProperty
= 1;
3327 wxPGProperty
* prev
= m_selected
;
3331 m_inDoSelectProperty
= 0;
3337 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3339 wxPrintf( "None selected\n" );
3342 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3344 wxPrintf( "P = NULL\n" );
3347 // If we are frozen, then just set the values.
3350 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3351 m_editorFocused
= 0;
3354 m_pState
->m_selected
= p
;
3356 // If frozen, always free controls. But don't worry, as Thaw will
3357 // recall SelectProperty to recreate them.
3360 // Prevent any further selection measures in this call
3361 p
= (wxPGProperty
*) NULL
;
3366 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3368 // Only set focus if not deselecting
3371 if ( flags
& wxPG_SEL_FOCUS
)
3375 m_wndEditor
->SetFocus();
3376 m_editorFocused
= 1;
3385 m_inDoSelectProperty
= 0;
3390 // First, deactivate previous
3394 OnValidationFailureReset(m_selected
);
3396 // Must double-check if this is an selected in case of forceswitch
3399 if ( !CommitChangesFromEditor(flags
) )
3401 // Validation has failed, so we can't exit the previous editor
3402 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3403 // _("Invalid Value"),wxOK|wxICON_ERROR);
3404 m_inDoSelectProperty
= 0;
3412 m_selected
= (wxPGProperty
*) NULL
;
3413 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3415 // We need to always fully refresh the grid here
3418 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3419 EditorsValueWasNotModified();
3422 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3425 // Then, activate the one given.
3428 int propY
= p
->GetY2(m_lineHeight
);
3430 int splitterX
= GetSplitterPosition();
3431 m_editorFocused
= 0;
3433 m_pState
->m_selected
= p
;
3434 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3436 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3438 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3440 // Do we need OnMeasureCalls?
3441 wxSize imsz
= p
->OnMeasureImage();
3444 // Only create editor for non-disabled non-caption
3445 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3447 // do this for non-caption items
3451 // Do we need to paint the custom image, if any?
3452 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3453 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3454 !p
->GetEditorClass()->CanContainCustomImage()
3456 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3458 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3459 wxPoint goodPos
= grect
.GetPosition();
3460 #if wxPG_CREATE_CONTROLS_HIDDEN
3461 int coord_adjust
= m_height
- goodPos
.y
;
3462 goodPos
.y
+= coord_adjust
;
3465 const wxPGEditor
* editor
= p
->GetEditorClass();
3466 wxCHECK_MSG(editor
, false,
3467 wxT("NULL editor class not allowed"));
3469 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3471 wxPGWindowList wndList
= editor
->CreateControls(this,
3476 m_wndEditor
= wndList
.m_primary
;
3477 m_wndEditor2
= wndList
.m_secondary
;
3478 wxWindow
* primaryCtrl
= GetEditorControl();
3481 // Essentially, primaryCtrl == m_wndEditor
3484 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3485 // value is drawn as normal, and m_wndEditor2 is assumed
3486 // to be a right-aligned button that triggers a separate editorCtrl
3491 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3492 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3494 // Set validator, if any
3495 #if wxUSE_VALIDATORS
3496 wxValidator
* validator
= p
->GetValidator();
3498 primaryCtrl
->SetValidator(*validator
);
3501 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3502 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3504 // If it has modified status, use bold font
3505 // (must be done before capturing m_ctrlXAdjust)
3506 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3507 SetCurControlBoldFont();
3510 // Fix TextCtrl indentation
3511 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3512 wxTextCtrl
* tc
= NULL
;
3513 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3514 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3516 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3518 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3521 // Store x relative to splitter (we'll need it).
3522 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3524 // Check if background clear is not necessary
3525 wxPoint pos
= m_wndEditor
->GetPosition();
3526 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3528 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3531 m_wndEditor
->SetSizeHints(3, 3);
3533 #if wxPG_CREATE_CONTROLS_HIDDEN
3534 m_wndEditor
->Show(false);
3535 m_wndEditor
->Freeze();
3537 goodPos
= m_wndEditor
->GetPosition();
3538 goodPos
.y
-= coord_adjust
;
3539 m_wndEditor
->Move( goodPos
);
3542 SetupChildEventHandling(primaryCtrl
);
3544 // Focus and select all (wxTextCtrl, wxComboBox etc)
3545 if ( flags
& wxPG_SEL_FOCUS
)
3547 primaryCtrl
->SetFocus();
3549 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3555 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3556 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3558 // Get proper id for wndSecondary
3559 m_wndSecId
= m_wndEditor2
->GetId();
3560 wxWindowList children
= m_wndEditor2
->GetChildren();
3561 wxWindowList::iterator node
= children
.begin();
3562 if ( node
!= children
.end() )
3563 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3565 m_wndEditor2
->SetSizeHints(3,3);
3567 #if wxPG_CREATE_CONTROLS_HIDDEN
3568 wxRect sec_rect
= m_wndEditor2
->GetRect();
3569 sec_rect
.y
-= coord_adjust
;
3571 // Fine tuning required to fix "oversized"
3572 // button disappearance bug.
3573 if ( sec_rect
.y
< 0 )
3575 sec_rect
.height
+= sec_rect
.y
;
3578 m_wndEditor2
->SetSize( sec_rect
);
3580 m_wndEditor2
->Show();
3582 SetupChildEventHandling(m_wndEditor2
);
3584 // If no primary editor, focus to button to allow
3585 // it to interprete ENTER etc.
3586 // NOTE: Due to problems focusing away from it, this
3587 // has been disabled.
3589 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3590 m_wndEditor2->SetFocus();
3594 if ( flags
& wxPG_SEL_FOCUS
)
3595 m_editorFocused
= 1;
3600 // Make sure focus is in grid canvas (important for wxGTK, at least)
3604 EditorsValueWasNotModified();
3606 // If it's inside collapsed section, expand parent, scroll, etc.
3607 // Also, if it was partially visible, scroll it into view.
3608 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3613 #if wxPG_CREATE_CONTROLS_HIDDEN
3614 m_wndEditor
->Thaw();
3616 m_wndEditor
->Show(true);
3623 // Make sure focus is in grid canvas
3627 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3633 // Show help text in status bar.
3634 // (if found and grid not embedded in manager with help box and
3635 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3638 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3640 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3641 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3643 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3645 statusbar
= frame
->GetStatusBar();
3650 const wxString
* pHelpString
= (const wxString
*) NULL
;
3654 pHelpString
= &p
->GetHelpString();
3655 if ( pHelpString
->length() )
3657 // Set help box text.
3658 statusbar
->SetStatusText( *pHelpString
);
3659 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3663 if ( (!pHelpString
|| !pHelpString
->length()) &&
3664 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3666 // Clear help box - but only if it was written
3667 // by us at previous time.
3668 statusbar
->SetStatusText( m_emptyString
);
3669 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3675 m_inDoSelectProperty
= 0;
3677 // call wx event handler (here so that it also occurs on deselection)
3678 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3683 // -----------------------------------------------------------------------
3685 bool wxPropertyGrid::UnfocusEditor()
3687 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3690 if ( !CommitChangesFromEditor(0) )
3694 DrawItem(m_selected
);
3699 // -----------------------------------------------------------------------
3701 // This method is not inline because it called dozens of times
3702 // (i.e. two-arg function calls create smaller code size).
3703 bool wxPropertyGrid::DoClearSelection()
3705 return DoSelectProperty((wxPGProperty
*)NULL
);
3708 // -----------------------------------------------------------------------
3709 // wxPropertyGrid expand/collapse state
3710 // -----------------------------------------------------------------------
3712 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3714 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3716 // If active editor was inside collapsed section, then disable it
3717 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3719 if ( !ClearSelection() )
3723 // Store dont-center-splitter flag 'cause we need to temporarily set it
3724 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3725 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3727 bool res
= m_pState
->DoCollapse(pwc
);
3732 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3734 RecalculateVirtualSize();
3736 // Redraw etc. only if collapsed was visible.
3737 if (pwc
->IsVisible() &&
3739 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3741 // When item is collapsed so that scrollbar would move,
3742 // graphics mess is about (unless we redraw everything).
3747 // Clear dont-center-splitter flag if it wasn't set
3748 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3753 // -----------------------------------------------------------------------
3755 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3757 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3759 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3761 // Store dont-center-splitter flag 'cause we need to temporarily set it
3762 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3763 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3765 bool res
= m_pState
->DoExpand(pwc
);
3770 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3772 RecalculateVirtualSize();
3774 // Redraw etc. only if expanded was visible.
3775 if ( pwc
->IsVisible() && !m_frozen
&&
3776 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3780 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3783 DrawItems(pwc
, NULL
);
3788 // Clear dont-center-splitter flag if it wasn't set
3789 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3794 // -----------------------------------------------------------------------
3796 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3799 return m_pState
->DoHideProperty(p
, hide
, flags
);
3802 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3805 if ( !ClearSelection() )
3809 m_pState
->DoHideProperty(p
, hide
, flags
);
3811 RecalculateVirtualSize();
3818 // -----------------------------------------------------------------------
3819 // wxPropertyGrid size related methods
3820 // -----------------------------------------------------------------------
3822 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3824 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3828 // If virtual height was changed, then recalculate editor control position(s)
3829 if ( m_pState
->m_vhCalcPending
)
3830 CorrectEditorWidgetPosY();
3832 m_pState
->EnsureVirtualHeight();
3835 int by1
= m_pState
->GetVirtualHeight();
3836 int by2
= m_pState
->GetActualVirtualHeight();
3839 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3840 wxASSERT_MSG( false,
3846 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3848 int x
= m_pState
->m_width
;
3849 int y
= m_pState
->m_virtualHeight
;
3852 GetClientSize(&width
,&height
);
3854 // Now adjust virtual size.
3855 SetVirtualSize(x
, y
);
3861 // Adjust scrollbars
3862 if ( HasVirtualWidth() )
3864 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3865 xPos
= GetScrollPos( wxHORIZONTAL
);
3868 if ( forceXPos
!= -1 )
3871 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3874 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3875 int yPos
= GetScrollPos( wxVERTICAL
);
3877 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3878 xAmount
, yAmount
, xPos
, yPos
, true );
3880 // Must re-get size now
3881 GetClientSize(&width
,&height
);
3883 if ( !HasVirtualWidth() )
3885 m_pState
->SetVirtualWidth(width
);
3892 m_canvas
->SetSize( x
, y
);
3894 m_pState
->CheckColumnWidths();
3897 CorrectEditorWidgetSizeX();
3899 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3902 // -----------------------------------------------------------------------
3904 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3906 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3910 GetClientSize(&width
,&height
);
3915 #if wxPG_DOUBLE_BUFFER
3916 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3918 int dblh
= (m_lineHeight
*2);
3919 if ( !m_doubleBuffer
)
3921 // Create double buffer bitmap to draw on, if none
3922 int w
= (width
>250)?width
:250;
3923 int h
= height
+ dblh
;
3925 m_doubleBuffer
= new wxBitmap( w
, h
);
3929 int w
= m_doubleBuffer
->GetWidth();
3930 int h
= m_doubleBuffer
->GetHeight();
3932 // Double buffer must be large enough
3933 if ( w
< width
|| h
< (height
+dblh
) )
3935 if ( w
< width
) w
= width
;
3936 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3937 delete m_doubleBuffer
;
3938 m_doubleBuffer
= new wxBitmap( w
, h
);
3945 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3946 m_ncWidth
= event
.GetSize().x
;
3950 if ( m_pState
->m_itemsAdded
)
3951 PrepareAfterItemsAdded();
3953 // Without this, virtual size (atleast under wxGTK) will be skewed
3954 RecalculateVirtualSize();
3960 // -----------------------------------------------------------------------
3962 void wxPropertyGrid::SetVirtualWidth( int width
)
3966 // Disable virtual width
3967 width
= GetClientSize().x
;
3968 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3972 // Enable virtual width
3973 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3975 m_pState
->SetVirtualWidth( width
);
3978 void wxPropertyGrid::SetFocusOnCanvas()
3980 m_canvas
->SetFocusIgnoringChildren();
3981 m_editorFocused
= 0;
3984 // -----------------------------------------------------------------------
3985 // wxPropertyGrid mouse event handling
3986 // -----------------------------------------------------------------------
3988 // selFlags uses same values DoSelectProperty's flags
3989 // Returns true if event was vetoed.
3990 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3992 // Send property grid event of specific type and with specific property
3993 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3994 evt
.SetPropertyGrid(this);
3995 evt
.SetEventObject(m_eventObject
);
3999 evt
.SetCanVeto(true);
4000 evt
.SetupValidationInfo();
4001 m_validationInfo
.m_pValue
= pValue
;
4003 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
4005 evtHandler
->ProcessEvent(evt
);
4007 return evt
.WasVetoed();
4010 // -----------------------------------------------------------------------
4012 // Return false if should be skipped
4013 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
4017 // Need to set focus?
4018 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4023 wxPropertyGridPageState
* state
= m_pState
;
4025 int splitterHitOffset
;
4026 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4028 wxPGProperty
* p
= DoGetItemAtY(y
);
4032 int depth
= (int)p
->GetDepth() - 1;
4034 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
4036 if ( x
>= marginEnds
)
4040 if ( p
->IsCategory() )
4042 // This is category.
4043 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4045 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4047 // Expand, collapse, activate etc. if click on text or left of splitter.
4050 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4055 if ( !DoSelectProperty( p
) )
4058 // On double-click, expand/collapse.
4059 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4061 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4062 else DoExpand( p
, true );
4066 else if ( splitterHit
== -1 )
4069 unsigned int selFlag
= 0;
4070 if ( columnHit
== 1 )
4072 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4073 selFlag
= wxPG_SEL_FOCUS
;
4075 if ( !DoSelectProperty( p
, selFlag
) )
4078 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4080 if ( p
->GetChildCount() && !p
->IsCategory() )
4081 // On double-click, expand/collapse.
4082 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4084 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4085 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4086 else DoExpand( p
, true );
4093 // click on splitter
4094 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4096 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4098 // Double-clicking the splitter causes auto-centering
4099 CenterSplitter( true );
4101 else if ( m_dragStatus
== 0 )
4104 // Begin draggin the splitter
4108 // Changes must be committed here or the
4109 // value won't be drawn correctly
4110 if ( !CommitChangesFromEditor() )
4113 m_wndEditor
->Show ( false );
4116 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4118 m_canvas
->CaptureMouse();
4119 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4123 m_draggedSplitter
= splitterHit
;
4124 m_dragOffset
= splitterHitOffset
;
4126 wxClientDC
dc(m_canvas
);
4128 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4129 // Fixes button disappearance bug
4131 m_wndEditor2
->Show ( false );
4134 m_startingSplitterX
= x
- splitterHitOffset
;
4142 if ( p
->GetChildCount() )
4144 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4146 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4148 int y2
= y
% m_lineHeight
;
4149 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4151 // On click on expander button, expand/collapse
4152 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4153 DoCollapse( p
, true );
4155 DoExpand( p
, true );
4164 // -----------------------------------------------------------------------
4166 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4167 wxMouseEvent
& WXUNUSED(event
) )
4171 // Select property here as well
4172 wxPGProperty
* p
= m_propHover
;
4173 if ( p
!= m_selected
)
4174 DoSelectProperty( p
);
4176 // Send right click event.
4177 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4184 // -----------------------------------------------------------------------
4186 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4187 wxMouseEvent
& WXUNUSED(event
) )
4191 // Select property here as well
4192 wxPGProperty
* p
= m_propHover
;
4194 if ( p
!= m_selected
)
4195 DoSelectProperty( p
);
4197 // Send double-click event.
4198 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4205 // -----------------------------------------------------------------------
4207 #if wxPG_SUPPORT_TOOLTIPS
4209 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4211 if ( tipString
.length() )
4213 m_canvas
->SetToolTip(tipString
);
4217 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4218 m_canvas
->SetToolTip( m_emptyString
);
4220 m_canvas
->SetToolTip( NULL
);
4225 #endif // #if wxPG_SUPPORT_TOOLTIPS
4227 // -----------------------------------------------------------------------
4229 // Return false if should be skipped
4230 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4232 // Safety check (needed because mouse capturing may
4233 // otherwise freeze the control)
4234 if ( m_dragStatus
> 0 && !event
.Dragging() )
4236 HandleMouseUp(x
,y
,event
);
4239 wxPropertyGridPageState
* state
= m_pState
;
4241 int splitterHitOffset
;
4242 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4243 int splitterX
= x
- splitterHitOffset
;
4245 if ( m_dragStatus
> 0 )
4247 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4248 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4251 int newSplitterX
= x
- m_dragOffset
;
4252 int splitterX
= x
- splitterHitOffset
;
4254 // Splitter redraw required?
4255 if ( newSplitterX
!= splitterX
)
4258 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4259 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4260 state
->m_fSplitterX
= (float) newSplitterX
;
4263 CorrectEditorWidgetSizeX();
4277 int ih
= m_lineHeight
;
4280 #if wxPG_SUPPORT_TOOLTIPS
4281 wxPGProperty
* prevHover
= m_propHover
;
4282 unsigned char prevSide
= m_mouseSide
;
4284 int curPropHoverY
= y
- (y
% ih
);
4286 // On which item it hovers
4287 if ( ( !m_propHover
)
4289 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4292 // Mouse moves on another property
4294 m_propHover
= DoGetItemAtY(y
);
4295 m_propHoverY
= curPropHoverY
;
4298 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4301 #if wxPG_SUPPORT_TOOLTIPS
4302 // Store which side we are on
4304 if ( columnHit
== 1 )
4306 else if ( columnHit
== 0 )
4310 // If tooltips are enabled, show label or value as a tip
4311 // in case it doesn't otherwise show in full length.
4313 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4315 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4317 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4319 if ( m_propHover
&& !m_propHover
->IsCategory() )
4322 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4324 // Show help string as a tooltip
4325 wxString tipString
= m_propHover
->GetHelpString();
4327 SetToolTip(tipString
);
4331 // Show cropped value string as a tooltip
4335 if ( m_mouseSide
== 1 )
4337 tipString
= m_propHover
->m_label
;
4338 space
= splitterX
-m_marginWidth
-3;
4340 else if ( m_mouseSide
== 2 )
4342 tipString
= m_propHover
->GetDisplayedString();
4344 space
= m_width
- splitterX
;
4345 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4346 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4352 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4355 SetToolTip( tipString
);
4362 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4363 m_canvas
->SetToolTip( m_emptyString
);
4365 m_canvas
->SetToolTip( NULL
);
4376 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4377 m_canvas
->SetToolTip( m_emptyString
);
4379 m_canvas
->SetToolTip( NULL
);
4387 if ( splitterHit
== -1 ||
4389 HasFlag(wxPG_STATIC_SPLITTER
) )
4391 // hovering on something else
4392 if ( m_curcursor
!= wxCURSOR_ARROW
)
4393 CustomSetCursor( wxCURSOR_ARROW
);
4397 // Do not allow splitter cursor on caption items.
4398 // (also not if we were dragging and its started
4399 // outside the splitter region)
4402 !m_propHover
->IsCategory() &&
4406 // hovering on splitter
4408 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4409 // reliably detected.
4410 //if ( m_curcursor != wxCURSOR_SIZEWE )
4411 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4417 // hovering on something else
4418 if ( m_curcursor
!= wxCURSOR_ARROW
)
4419 CustomSetCursor( wxCURSOR_ARROW
);
4426 // -----------------------------------------------------------------------
4428 // Also handles Leaving event
4429 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4430 wxMouseEvent
&WXUNUSED(event
) )
4432 wxPropertyGridPageState
* state
= m_pState
;
4436 int splitterHitOffset
;
4437 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4439 // No event type check - basicly calling this method should
4440 // just stop dragging.
4441 // Left up after dragged?
4442 if ( m_dragStatus
>= 1 )
4445 // End Splitter Dragging
4447 // DO NOT ENABLE FOLLOWING LINE!
4448 // (it is only here as a reminder to not to do it)
4451 // Disable splitter auto-centering
4452 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4454 // This is necessary to return cursor
4455 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4457 m_canvas
->ReleaseMouse();
4458 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4461 // Set back the default cursor, if necessary
4462 if ( splitterHit
== -1 ||
4465 CustomSetCursor( wxCURSOR_ARROW
);
4470 // Control background needs to be cleared
4471 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4472 DrawItem( m_selected
);
4476 m_wndEditor
->Show ( true );
4479 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4480 // Fixes button disappearance bug
4482 m_wndEditor2
->Show ( true );
4485 // This clears the focus.
4486 m_editorFocused
= 0;
4492 // -----------------------------------------------------------------------
4494 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4496 int splitterX
= GetSplitterPosition();
4499 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4503 wxWindow
* wnd
= GetEditorControl();
4505 // Hide popup on clicks
4506 if ( event
.GetEventType() != wxEVT_MOTION
)
4507 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4509 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4515 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4517 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4518 ux
>= (r
.x
+r
.width
) ||
4520 event
.m_y
>= (r
.y
+r
.height
)
4530 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4535 // -----------------------------------------------------------------------
4537 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4540 if ( OnMouseCommon( event
, &x
, &y
) )
4542 HandleMouseClick(x
,y
,event
);
4547 // -----------------------------------------------------------------------
4549 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4552 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4553 HandleMouseRightClick(x
,y
,event
);
4557 // -----------------------------------------------------------------------
4559 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4561 // Always run standard mouse-down handler as well
4562 OnMouseClick(event
);
4565 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4566 HandleMouseDoubleClick(x
,y
,event
);
4570 // -----------------------------------------------------------------------
4572 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4575 if ( OnMouseCommon( event
, &x
, &y
) )
4577 HandleMouseMove(x
,y
,event
);
4582 // -----------------------------------------------------------------------
4584 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4586 // Called when mouse moves in the empty space below the properties.
4587 CustomSetCursor( wxCURSOR_ARROW
);
4590 // -----------------------------------------------------------------------
4592 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4595 if ( OnMouseCommon( event
, &x
, &y
) )
4597 HandleMouseUp(x
,y
,event
);
4602 // -----------------------------------------------------------------------
4604 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4606 // This may get called from child control as well, so event's
4607 // mouse position cannot be relied on.
4609 if ( event
.Entering() )
4611 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4613 // TODO: Fix this (detect parent and only do
4614 // cursor trick if it is a manager).
4615 wxASSERT( GetParent() );
4616 GetParent()->SetCursor(wxNullCursor
);
4618 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4621 GetParent()->SetCursor(wxNullCursor
);
4623 else if ( event
.Leaving() )
4625 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4626 m_canvas
->SetCursor( wxNullCursor
);
4628 // Get real cursor position
4629 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4631 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4634 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4636 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4640 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4648 // -----------------------------------------------------------------------
4650 // Common code used by various OnMouseXXXChild methods.
4651 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4653 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4654 wxASSERT( topCtrlWnd
);
4656 event
.GetPosition(&x
,&y
);
4658 int splitterX
= GetSplitterPosition();
4660 wxRect r
= topCtrlWnd
->GetRect();
4661 if ( !m_dragStatus
&&
4662 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4663 y
>= 0 && y
< r
.height \
4666 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4671 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4678 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4681 if ( OnMouseChildCommon(event
,&x
,&y
) )
4683 bool res
= HandleMouseClick(x
,y
,event
);
4684 if ( !res
) event
.Skip();
4688 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4691 wxASSERT( m_wndEditor
);
4692 // These coords may not be exact (about +-2),
4693 // but that should not matter (right click is about item, not position).
4694 wxPoint pt
= m_wndEditor
->GetPosition();
4695 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4696 wxASSERT( m_selected
);
4697 m_propHover
= m_selected
;
4698 bool res
= HandleMouseRightClick(x
,y
,event
);
4699 if ( !res
) event
.Skip();
4702 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4705 if ( OnMouseChildCommon(event
,&x
,&y
) )
4707 bool res
= HandleMouseMove(x
,y
,event
);
4708 if ( !res
) event
.Skip();
4712 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4715 if ( OnMouseChildCommon(event
,&x
,&y
) )
4717 bool res
= HandleMouseUp(x
,y
,event
);
4718 if ( !res
) event
.Skip();
4722 // -----------------------------------------------------------------------
4723 // wxPropertyGrid keyboard event handling
4724 // -----------------------------------------------------------------------
4726 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4728 // Translates wxKeyEvent to wxPG_ACTION_XXX
4730 int keycode
= event
.GetKeyCode();
4731 int modifiers
= event
.GetModifiers();
4733 wxASSERT( !(modifiers
&~(0xFFFF)) );
4735 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4737 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4739 if ( it
== m_actionTriggers
.end() )
4744 int second
= (it
->second
>>16) & 0xFFFF;
4748 return (it
->second
& 0xFFFF);
4751 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4753 wxASSERT( !(modifiers
&~(0xFFFF)) );
4755 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4757 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4759 if ( it
!= m_actionTriggers
.end() )
4761 // This key combination is already used
4763 // Can add secondary?
4764 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4765 wxT("You can only add up to two separate actions per key combination.") );
4767 action
= it
->second
| (action
<<16);
4770 m_actionTriggers
[hashMapKey
] = action
;
4773 void wxPropertyGrid::ClearActionTriggers( int action
)
4775 wxPGHashMapI2I::iterator it
;
4777 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4779 if ( it
->second
== action
)
4781 m_actionTriggers
.erase(it
);
4786 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4789 // Handles key event when editor control is not focused.
4792 wxASSERT( !m_frozen
);
4796 // Travelsal between items, collapsing/expanding, etc.
4797 int keycode
= event
.GetKeyCode();
4798 bool editorFocused
= IsEditorFocused();
4800 if ( keycode
== WXK_TAB
)
4802 wxWindow
* mainControl
;
4804 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4805 mainControl
= GetParent();
4809 if ( !event
.ShiftDown() )
4811 if ( !editorFocused
&& m_wndEditor
)
4813 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4817 // Tab traversal workaround for platforms on which
4818 // wxWindow::Navigate() may navigate into first child
4819 // instead of next sibling. Does not work perfectly
4820 // in every scenario (for instance, when property grid
4821 // is either first or last control).
4822 #if defined(__WXGTK__)
4823 wxWindow
* sibling
= mainControl
->GetNextSibling();
4825 sibling
->SetFocusFromKbd();
4827 Navigate(wxNavigationKeyEvent::IsForward
);
4833 if ( editorFocused
)
4839 #if defined(__WXGTK__)
4840 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4842 sibling
->SetFocusFromKbd();
4844 Navigate(wxNavigationKeyEvent::IsBackward
);
4852 // Ignore Alt and Control when they are down alone
4853 if ( keycode
== WXK_ALT
||
4854 keycode
== WXK_CONTROL
)
4861 int action
= KeyEventToActions(event
, &secondAction
);
4863 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4866 // Esc cancels any changes
4867 if ( IsEditorsValueModified() )
4869 EditorsValueWasNotModified();
4871 // Update the control as well
4872 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4874 m_selected
->GetDisplayedString() );
4877 OnValidationFailureReset(m_selected
);
4883 // Except for TAB and ESC, handle child control events in child control
4890 bool wasHandled
= false;
4895 if ( ButtonTriggerKeyTest(action
, event
) )
4898 wxPGProperty
* p
= m_selected
;
4900 // Travel and expand/collapse
4903 if ( p
->GetChildCount() &&
4904 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4907 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4909 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4912 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4914 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4921 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4925 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4931 if ( selectDir
>= -1 )
4933 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4935 DoSelectProperty(p
);
4941 // If nothing was selected, select the first item now
4942 // (or navigate out of tab).
4943 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4945 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4946 if ( p
) DoSelectProperty(p
);
4955 // -----------------------------------------------------------------------
4957 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4959 HandleKeyEvent(event
, false);
4962 // -----------------------------------------------------------------------
4964 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4969 action
= KeyEventToActions(event
, &secondAction
);
4972 // Does the keycode trigger button?
4973 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4976 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4977 GetEventHandler()->AddPendingEvent(evt
);
4984 // -----------------------------------------------------------------------
4986 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4988 HandleKeyEvent(event
, true);
4991 // -----------------------------------------------------------------------
4992 // wxPropertyGrid miscellaneous event handling
4993 // -----------------------------------------------------------------------
4995 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4998 // Check if the focus is in this control or one of its children
4999 wxWindow
* newFocused
= wxWindow::FindFocus();
5001 if ( newFocused
!= m_curFocused
)
5002 HandleFocusChange( newFocused
);
5005 bool wxPropertyGrid::IsEditorFocused() const
5007 wxWindow
* focus
= wxWindow::FindFocus();
5009 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
5010 focus
== GetEditorControl() )
5016 // Called by focus event handlers. newFocused is the window that becomes focused.
5017 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
5019 unsigned int oldFlags
= m_iFlags
;
5021 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
5023 wxWindow
* parent
= newFocused
;
5025 // This must be one of nextFocus' parents.
5028 // Use m_eventObject, which is either wxPropertyGrid or
5029 // wxPropertyGridManager, as appropriate.
5030 if ( parent
== m_eventObject
)
5032 m_iFlags
|= wxPG_FL_FOCUSED
;
5035 parent
= parent
->GetParent();
5038 m_curFocused
= newFocused
;
5040 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
5041 (oldFlags
& wxPG_FL_FOCUSED
) )
5043 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
5045 // Need to store changed value
5046 CommitChangesFromEditor();
5052 // Preliminary code for tab-order respecting
5053 // tab-traversal (but should be moved to
5056 wxWindow* prevFocus = event.GetWindow();
5057 wxWindow* useThis = this;
5058 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5059 useThis = GetParent();
5062 prevFocus->GetParent() == useThis->GetParent() )
5064 wxList& children = useThis->GetParent()->GetChildren();
5066 wxNode* node = children.Find(prevFocus);
5068 if ( node->GetNext() &&
5069 useThis == node->GetNext()->GetData() )
5070 DoSelectProperty(GetFirst());
5071 else if ( node->GetPrevious () &&
5072 useThis == node->GetPrevious()->GetData() )
5073 DoSelectProperty(GetLastProperty());
5080 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5081 DrawItem( m_selected
);
5085 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5087 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5088 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5089 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5090 //else if ( event.GetWindow() )
5092 HandleFocusChange(event
.GetWindow());
5097 // -----------------------------------------------------------------------
5099 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5101 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5104 // event.Skip() being commented out is aworkaround for bug reported
5105 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5109 // -----------------------------------------------------------------------
5111 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5113 m_iFlags
|= wxPG_FL_SCROLLED
;
5118 // -----------------------------------------------------------------------
5120 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5122 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5124 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5128 // -----------------------------------------------------------------------
5129 // Property editor related functions
5130 // -----------------------------------------------------------------------
5132 // noDefCheck = true prevents infinite recursion.
5133 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5136 wxASSERT( editorClass
);
5138 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5139 RegisterDefaultEditors();
5141 wxString name
= editorClass
->GetName();
5143 // Existing editor under this name?
5144 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5146 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5148 // If this name was already used, try class name.
5149 name
= editorClass
->GetClassInfo()->GetClassName();
5150 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5153 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5154 (wxPGEditor
*) vt_it
->second
,
5155 "Editor with given name was already registered" );
5157 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5162 // Use this in RegisterDefaultEditors.
5163 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5164 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5166 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5167 new wxPG##EDITOR##Editor, true ); \
5170 // Registers all default editor classes
5171 void wxPropertyGrid::RegisterDefaultEditors()
5173 wxPGRegisterDefaultEditorClass( TextCtrl
);
5174 wxPGRegisterDefaultEditorClass( Choice
);
5175 wxPGRegisterDefaultEditorClass( ComboBox
);
5176 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5177 #if wxPG_INCLUDE_CHECKBOX
5178 wxPGRegisterDefaultEditorClass( CheckBox
);
5180 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5182 // Register SpinCtrl etc. editors before use
5183 RegisterAdditionalEditors();
5186 // -----------------------------------------------------------------------
5187 // wxPGStringTokenizer
5188 // Needed to handle C-style string lists (e.g. "str1" "str2")
5189 // -----------------------------------------------------------------------
5191 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5192 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5196 wxPGStringTokenizer::~wxPGStringTokenizer()
5200 bool wxPGStringTokenizer::HasMoreTokens()
5202 const wxString
& str
= *m_str
;
5204 wxString::const_iterator i
= m_curPos
;
5206 wxUniChar delim
= m_delimeter
;
5208 wxUniChar prev_a
= wxT('\0');
5210 bool inToken
= false;
5212 while ( i
!= str
.end() )
5221 m_readyToken
.clear();
5226 if ( prev_a
!= wxT('\\') )
5230 if ( a
!= wxT('\\') )
5250 m_curPos
= str
.end();
5258 wxString
wxPGStringTokenizer::GetNextToken()
5260 return m_readyToken
;
5263 // -----------------------------------------------------------------------
5265 // -----------------------------------------------------------------------
5267 wxPGChoiceEntry::wxPGChoiceEntry()
5268 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5272 // -----------------------------------------------------------------------
5274 // -----------------------------------------------------------------------
5276 wxPGChoicesData::wxPGChoicesData()
5281 wxPGChoicesData::~wxPGChoicesData()
5286 void wxPGChoicesData::Clear()
5291 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5293 wxASSERT( m_items
.size() == 0 );
5295 m_items
= data
->m_items
;
5298 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5299 const wxPGChoiceEntry
& item
)
5301 wxVector
<wxPGChoiceEntry
>::iterator it
;
5305 index
= (int) m_items
.size();
5309 it
= m_items
.begin() + index
;
5312 m_items
.insert(it
, item
);
5314 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5316 // Need to fix value?
5317 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5318 ownEntry
.SetValue(index
);
5323 // -----------------------------------------------------------------------
5325 // -----------------------------------------------------------------------
5327 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5331 wxPGChoiceEntry
entry(label
, value
);
5332 return m_data
->Insert( -1, entry
);
5335 // -----------------------------------------------------------------------
5337 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5341 wxPGChoiceEntry
entry(label
, value
);
5342 entry
.SetBitmap(bitmap
);
5343 return m_data
->Insert( -1, entry
);
5346 // -----------------------------------------------------------------------
5348 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5351 return m_data
->Insert( index
, entry
);
5354 // -----------------------------------------------------------------------
5356 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5360 wxPGChoiceEntry
entry(label
, value
);
5361 return m_data
->Insert( index
, entry
);
5364 // -----------------------------------------------------------------------
5366 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5372 while ( index
< GetCount() )
5374 int cmpRes
= GetLabel(index
).Cmp(label
);
5380 wxPGChoiceEntry
entry(label
, value
);
5381 return m_data
->Insert( index
, entry
);
5384 // -----------------------------------------------------------------------
5386 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5390 unsigned int itemcount
= 0;
5391 const wxChar
** p
= &labels
[0];
5392 while ( *p
) { p
++; itemcount
++; }
5395 for ( i
= 0; i
< itemcount
; i
++ )
5400 wxPGChoiceEntry
entry(labels
[i
], value
);
5401 m_data
->Insert( i
, entry
);
5405 // -----------------------------------------------------------------------
5407 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5412 unsigned int itemcount
= arr
.size();
5414 for ( i
= 0; i
< itemcount
; i
++ )
5417 if ( &arrint
&& arrint
.size() )
5419 wxPGChoiceEntry
entry(arr
[i
], value
);
5420 m_data
->Insert( i
, entry
);
5424 // -----------------------------------------------------------------------
5426 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5428 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5429 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5430 m_data
->m_items
.begin()+nIndex
+count
);
5433 // -----------------------------------------------------------------------
5435 int wxPGChoices::Index( const wxString
& str
) const
5440 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5442 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5443 if ( entry
.HasText() && entry
.GetText() == str
)
5450 // -----------------------------------------------------------------------
5452 int wxPGChoices::Index( int val
) const
5457 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5459 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5460 if ( entry
.GetValue() == val
)
5467 // -----------------------------------------------------------------------
5469 wxArrayString
wxPGChoices::GetLabels() const
5474 if ( this && IsOk() )
5475 for ( i
=0; i
<GetCount(); i
++ )
5476 arr
.push_back(GetLabel(i
));
5481 // -----------------------------------------------------------------------
5483 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5490 for ( i
=0; i
< strings
.size(); i
++ )
5492 int index
= Index(strings
[i
]);
5494 arr
.Add(GetValue(index
));
5496 arr
.Add(wxPG_INVALID_VALUE
);
5503 // -----------------------------------------------------------------------
5505 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5506 wxArrayString
* unmatched
) const
5513 for ( i
=0; i
< strings
.size(); i
++ )
5515 const wxString
& str
= strings
[i
];
5516 int index
= Index(str
);
5519 else if ( unmatched
)
5520 unmatched
->Add(str
);
5527 // -----------------------------------------------------------------------
5529 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5533 if ( data
!= wxPGChoicesEmptyData
)
5540 // -----------------------------------------------------------------------
5542 void wxPGChoices::Init()
5544 m_data
= wxPGChoicesEmptyData
;
5547 // -----------------------------------------------------------------------
5549 void wxPGChoices::Free()
5551 if ( m_data
!= wxPGChoicesEmptyData
)
5554 m_data
= wxPGChoicesEmptyData
;
5558 // -----------------------------------------------------------------------
5559 // wxPropertyGridEvent
5560 // -----------------------------------------------------------------------
5562 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5565 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5566 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5567 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5568 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5569 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5570 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5571 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5572 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5573 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5576 // -----------------------------------------------------------------------
5578 void wxPropertyGridEvent::Init()
5580 m_validationInfo
= NULL
;
5582 m_wasVetoed
= false;
5585 // -----------------------------------------------------------------------
5587 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5588 : wxCommandEvent(commandType
,id
)
5594 // -----------------------------------------------------------------------
5596 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5597 : wxCommandEvent(event
)
5599 m_eventType
= event
.GetEventType();
5600 m_eventObject
= event
.m_eventObject
;
5602 m_property
= event
.m_property
;
5603 m_validationInfo
= event
.m_validationInfo
;
5604 m_canVeto
= event
.m_canVeto
;
5605 m_wasVetoed
= event
.m_wasVetoed
;
5608 // -----------------------------------------------------------------------
5610 wxPropertyGridEvent::~wxPropertyGridEvent()
5614 // -----------------------------------------------------------------------
5616 wxEvent
* wxPropertyGridEvent::Clone() const
5618 return new wxPropertyGridEvent( *this );
5621 // -----------------------------------------------------------------------
5622 // wxPropertyGridPopulator
5623 // -----------------------------------------------------------------------
5625 wxPropertyGridPopulator::wxPropertyGridPopulator()
5629 wxPGGlobalVars
->m_offline
++;
5632 // -----------------------------------------------------------------------
5634 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5637 m_propHierarchy
.clear();
5640 // -----------------------------------------------------------------------
5642 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5648 // -----------------------------------------------------------------------
5650 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5653 // Free unused sets of choices
5654 wxPGHashMapS2P::iterator it
;
5656 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5658 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5665 m_pg
->GetPanel()->Refresh();
5667 wxPGGlobalVars
->m_offline
--;
5670 // -----------------------------------------------------------------------
5672 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5673 const wxString
& propLabel
,
5674 const wxString
& propName
,
5675 const wxString
* propValue
,
5676 wxPGChoices
* pChoices
)
5678 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5679 wxPGProperty
* parent
= GetCurParent();
5681 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5683 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5687 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5689 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5693 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5695 property
->SetLabel(propLabel
);
5696 property
->DoSetName(propName
);
5698 if ( pChoices
&& pChoices
->IsOk() )
5699 property
->SetChoices(*pChoices
);
5701 m_state
->DoInsert(parent
, -1, property
);
5704 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5705 wxPG_PROGRAMMATIC_VALUE
);
5710 // -----------------------------------------------------------------------
5712 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5714 m_propHierarchy
.push_back(property
);
5715 DoScanForChildren();
5716 m_propHierarchy
.pop_back();
5719 // -----------------------------------------------------------------------
5721 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5722 const wxString
& idString
)
5724 wxPGChoices choices
;
5727 if ( choicesString
[0] == wxT('@') )
5729 wxString ids
= choicesString
.substr(1);
5730 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5731 if ( it
== m_dictIdChoices
.end() )
5732 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5734 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5739 if ( idString
.length() )
5741 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5742 if ( it
!= m_dictIdChoices
.end() )
5744 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5751 // Parse choices string
5752 wxString::const_iterator it
= choicesString
.begin();
5756 bool labelValid
= false;
5758 for ( ; it
!= choicesString
.end(); it
++ )
5764 if ( c
== wxT('"') )
5769 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5770 choices
.Add(label
, l
);
5773 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5778 else if ( c
== wxT('=') )
5785 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5792 if ( c
== wxT('"') )
5805 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5806 choices
.Add(label
, l
);
5809 if ( !choices
.IsOk() )
5811 choices
.EnsureData();
5815 if ( idString
.length() )
5816 m_dictIdChoices
[idString
] = choices
.GetData();
5823 // -----------------------------------------------------------------------
5825 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5827 if ( s
.Last() == wxT('%') )
5829 wxString s2
= s
.substr(0,s
.length()-1);
5831 if ( s2
.ToLong(&val
, 10) )
5833 *pval
= (val
*max
)/100;
5839 return s
.ToLong(pval
, 10);
5842 // -----------------------------------------------------------------------
5844 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5845 const wxString
& type
,
5846 const wxString
& value
)
5848 int l
= m_propHierarchy
.size();
5852 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5853 wxString valuel
= value
.Lower();
5856 if ( type
.length() == 0 )
5861 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5863 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5865 else if ( value
.ToLong(&v
, 0) )
5872 if ( type
== wxT("string") )
5876 else if ( type
== wxT("int") )
5879 value
.ToLong(&v
, 0);
5882 else if ( type
== wxT("bool") )
5884 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5891 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5896 p
->SetAttribute( name
, variant
);
5901 // -----------------------------------------------------------------------
5903 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5905 wxLogError(_("Error in resource: %s"),msg
.c_str());
5908 // -----------------------------------------------------------------------
5910 #endif // wxUSE_PROPGRID