1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
3 // Purpose: wxPropertyGrid
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
62 #include "wx/odcombo.h"
65 #include "wx/dcbuffer.h"
66 #include "wx/clipbrd.h"
67 #include "wx/dataobj.h"
70 #include "wx/msw/private.h"
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
102 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
104 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
114 //#define wxPG_HIDER_BUTTON_HEIGHT 25
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
122 //#define wxPG_TOOLTIP_DELAY 1000
124 // -----------------------------------------------------------------------
127 void wxPropertyGrid::AutoGetTranslation ( bool enable
)
129 wxPGGlobalVars
->m_autoGetTranslation
= enable
;
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
135 // -----------------------------------------------------------------------
137 const char wxPropertyGridNameStr
[] = "wxPropertyGrid";
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
143 #include "wx/module.h"
145 class wxPGGlobalVarsClassManager
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
)
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars
= new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { delete wxPGGlobalVars
; wxPGGlobalVars
= NULL
; }
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager
, wxModule
)
157 wxPGGlobalVarsClass
* wxPGGlobalVars
= (wxPGGlobalVarsClass
*) NULL
;
160 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
162 wxPGProperty::sm_wxPG_LABEL
= new wxString(wxPG_LABEL_STRING
);
164 m_boolChoices
.Add(_("False"));
165 m_boolChoices
.Add(_("True"));
167 m_fontFamilyChoices
= (wxPGChoices
*) NULL
;
169 m_defaultRenderer
= new wxPGDefaultRenderer();
171 m_autoGetTranslation
= false;
179 // Prepare some shared variants
180 m_vEmptyString
= wxString();
182 m_vMinusOne
= (long) -1;
186 // Prepare cached string constants
187 m_strstring
= wxS("string");
188 m_strlong
= wxS("long");
189 m_strbool
= wxS("bool");
190 m_strlist
= wxS("list");
191 m_strMin
= wxS("Min");
192 m_strMax
= wxS("Max");
193 m_strUnits
= wxS("Units");
194 m_strInlineHelp
= wxS("InlineHelp");
202 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
206 delete m_defaultRenderer
;
208 // This will always have one ref
209 delete m_fontFamilyChoices
;
212 for ( i
=0; i
<m_arrValidators
.size(); i
++ )
213 delete ((wxValidator
*)m_arrValidators
[i
]);
217 // Destroy value type class instances.
218 wxPGHashMapS2P::iterator vt_it
;
220 // Destroy editor class instances.
221 // iterate over all the elements in the class
222 for( vt_it
= m_mapEditorClasses
.begin(); vt_it
!= m_mapEditorClasses
.end(); ++vt_it
)
224 delete ((wxPGEditor
*)vt_it
->second
);
227 delete wxPGProperty::sm_wxPG_LABEL
;
230 void wxPropertyGridInitGlobalsIfNeeded()
234 // -----------------------------------------------------------------------
236 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
237 // and tries to commit property value.
238 // -----------------------------------------------------------------------
240 class wxPGTLWHandler
: public wxEvtHandler
244 wxPGTLWHandler( wxPropertyGrid
* pg
)
252 void OnClose( wxCloseEvent
& event
)
254 // ClearSelection forces value validation/commit.
255 if ( event
.CanVeto() && !m_pg
->ClearSelection() )
265 wxPropertyGrid
* m_pg
;
267 DECLARE_EVENT_TABLE()
270 BEGIN_EVENT_TABLE(wxPGTLWHandler
, wxEvtHandler
)
271 EVT_CLOSE(wxPGTLWHandler::OnClose
)
274 // -----------------------------------------------------------------------
276 // -----------------------------------------------------------------------
279 // wxPGCanvas acts as a graphics sub-window of the
280 // wxScrolledWindow that wxPropertyGrid is.
282 class wxPGCanvas
: public wxPanel
285 wxPGCanvas() : wxPanel()
288 virtual ~wxPGCanvas() { }
291 void OnMouseMove( wxMouseEvent
&event
)
293 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
294 pg
->OnMouseMove( event
);
297 void OnMouseClick( wxMouseEvent
&event
)
299 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
300 pg
->OnMouseClick( event
);
303 void OnMouseUp( wxMouseEvent
&event
)
305 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
306 pg
->OnMouseUp( event
);
309 void OnMouseRightClick( wxMouseEvent
&event
)
311 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
312 pg
->OnMouseRightClick( event
);
315 void OnMouseDoubleClick( wxMouseEvent
&event
)
317 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
318 pg
->OnMouseDoubleClick( event
);
321 void OnKey( wxKeyEvent
& event
)
323 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
327 void OnPaint( wxPaintEvent
& event
);
329 // Always be focussable, even with child windows
330 virtual void SetCanFocus(bool WXUNUSED(canFocus
))
331 { wxPanel::SetCanFocus(true); }
335 DECLARE_EVENT_TABLE()
336 DECLARE_ABSTRACT_CLASS(wxPGCanvas
)
340 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas
,wxPanel
)
342 BEGIN_EVENT_TABLE(wxPGCanvas
, wxPanel
)
343 EVT_MOTION(wxPGCanvas::OnMouseMove
)
344 EVT_PAINT(wxPGCanvas::OnPaint
)
345 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick
)
346 EVT_LEFT_UP(wxPGCanvas::OnMouseUp
)
347 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick
)
348 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick
)
349 EVT_KEY_DOWN(wxPGCanvas::OnKey
)
353 void wxPGCanvas::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
355 wxPropertyGrid
* pg
= wxStaticCast(GetParent(), wxPropertyGrid
);
356 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
360 // Don't paint after destruction has begun
361 if ( !(pg
->GetInternalFlags() & wxPG_FL_INITIALIZED
) )
364 // Update everything inside the box
365 wxRect r
= GetUpdateRegion().GetBox();
367 // Repaint this rectangle
368 pg
->DrawItems( dc
, r
.y
, r
.y
+ r
.height
, &r
);
370 // We assume that the size set when grid is shown
371 // is what is desired.
372 pg
->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET
);
375 // -----------------------------------------------------------------------
377 // -----------------------------------------------------------------------
379 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid
, wxScrolledWindow
)
381 BEGIN_EVENT_TABLE(wxPropertyGrid
, wxScrolledWindow
)
382 EVT_IDLE(wxPropertyGrid::OnIdle
)
383 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom
)
384 EVT_PAINT(wxPropertyGrid::OnPaint
)
385 EVT_SIZE(wxPropertyGrid::OnResize
)
386 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry
)
387 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry
)
388 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange
)
389 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent
)
390 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent
)
391 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent
)
392 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent
)
393 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged
)
397 // -----------------------------------------------------------------------
399 wxPropertyGrid::wxPropertyGrid()
405 // -----------------------------------------------------------------------
407 wxPropertyGrid::wxPropertyGrid( wxWindow
*parent
,
412 const wxString
& name
)
416 Create(parent
,id
,pos
,size
,style
,name
);
419 // -----------------------------------------------------------------------
421 bool wxPropertyGrid::Create( wxWindow
*parent
,
426 const wxString
& name
)
429 if ( !(style
&wxBORDER_MASK
) )
430 style
|= wxSIMPLE_BORDER
;
434 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
435 style
&= ~(wxTAB_TRAVERSAL
);
436 style
|= wxWANTS_CHARS
;
438 wxScrolledWindow::Create(parent
,id
,pos
,size
,style
,name
);
445 // -----------------------------------------------------------------------
448 // Initialize values to defaults
450 void wxPropertyGrid::Init1()
452 // Register editor classes, if necessary.
453 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
454 wxPropertyGrid::RegisterDefaultEditors();
457 m_pState
= (wxPropertyGridPageState
*) NULL
;
458 m_wndEditor
= m_wndEditor2
= (wxWindow
*) NULL
;
459 m_selected
= (wxPGProperty
*) NULL
;
461 m_propHover
= (wxPGProperty
*) NULL
;
462 m_eventObject
= this;
463 m_curFocused
= (wxWindow
*) NULL
;
465 m_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 if ( !(m_coloursCustomized
& 0x0002) )
964 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
966 // Make sure colour is dark enough
968 int colDec
= wxPGGetColAvg(col
) - 230;
970 int colDec
= wxPGGetColAvg(col
) - 200;
973 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
976 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
979 if ( !(m_coloursCustomized
& 0x0001) )
980 m_colMargin
= m_colCapBack
;
982 if ( !(m_coloursCustomized
& 0x0004) )
989 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
990 m_colCapFore
= capForeCol
;
991 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
994 if ( !(m_coloursCustomized
& 0x0008) )
996 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
997 m_colPropBack
= bgCol
;
998 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1001 if ( !(m_coloursCustomized
& 0x0010) )
1003 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1004 m_colPropFore
= fgCol
;
1005 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1008 if ( !(m_coloursCustomized
& 0x0020) )
1009 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1011 if ( !(m_coloursCustomized
& 0x0040) )
1012 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1014 if ( !(m_coloursCustomized
& 0x0080) )
1015 m_colLine
= m_colCapBack
;
1017 if ( !(m_coloursCustomized
& 0x0100) )
1018 m_colDisPropFore
= m_colCapFore
;
1020 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1023 // -----------------------------------------------------------------------
1025 void wxPropertyGrid::ResetColours()
1027 m_coloursCustomized
= 0;
1034 // -----------------------------------------------------------------------
1036 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1038 // Must disable active editor.
1039 ClearSelection(false);
1041 // TODO: Following code is disabled with wxMac because
1042 // it is reported to fail. I (JMS) cannot debug it
1043 // personally right now.
1044 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1045 #if 1 // !defined(__WXMAC__)
1046 bool res
= wxScrolledWindow::SetFont( font
);
1049 CalculateFontAndBitmapStuff( m_vspacing
);
1052 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1060 // TODO: Remove after SetFont crash fixed.
1061 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1063 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."));
1069 // -----------------------------------------------------------------------
1071 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1074 m_coloursCustomized
|= 0x80;
1078 // -----------------------------------------------------------------------
1080 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1083 m_coloursCustomized
|= 0x01;
1087 // -----------------------------------------------------------------------
1089 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1091 m_colPropBack
= col
;
1092 m_coloursCustomized
|= 0x08;
1094 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1099 // -----------------------------------------------------------------------
1101 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1103 m_colPropFore
= col
;
1104 m_coloursCustomized
|= 0x10;
1106 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1111 // -----------------------------------------------------------------------
1113 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1115 m_colEmptySpace
= col
;
1120 // -----------------------------------------------------------------------
1122 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1124 m_colDisPropFore
= col
;
1125 m_coloursCustomized
|= 0x100;
1129 // -----------------------------------------------------------------------
1131 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1134 m_coloursCustomized
|= 0x20;
1138 // -----------------------------------------------------------------------
1140 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1143 m_coloursCustomized
|= 0x40;
1147 // -----------------------------------------------------------------------
1149 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1152 m_coloursCustomized
|= 0x02;
1154 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1159 // -----------------------------------------------------------------------
1161 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1164 m_coloursCustomized
|= 0x04;
1166 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1171 // -----------------------------------------------------------------------
1172 // wxPropertyGrid property adding and removal
1173 // -----------------------------------------------------------------------
1175 void wxPropertyGrid::PrepareAfterItemsAdded()
1177 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1179 m_pState
->m_itemsAdded
= 0;
1181 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1184 RecalculateVirtualSize();
1187 // -----------------------------------------------------------------------
1188 // wxPropertyGrid property value setting and getting
1189 // -----------------------------------------------------------------------
1191 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1193 m_pState
->DoSetPropertyValueUnspecified(p
);
1194 DrawItemAndChildren(p
);
1196 wxPGProperty
* parent
= p
->GetParent();
1198 (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1201 parent
= parent
->GetParent();
1205 // -----------------------------------------------------------------------
1206 // wxPropertyGrid property operations
1207 // -----------------------------------------------------------------------
1209 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1211 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1215 bool changed
= false;
1217 // Is it inside collapsed section?
1218 if ( !p
->IsVisible() )
1221 wxPGProperty
* parent
= p
->GetParent();
1222 wxPGProperty
* grandparent
= parent
->GetParent();
1224 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1225 Expand( grandparent
);
1233 GetViewStart(&vx
,&vy
);
1234 vy
*=wxPG_PIXELS_PER_UNIT
;
1240 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1241 m_iFlags
|= wxPG_FL_SCROLLED
;
1244 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1246 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1247 m_iFlags
|= wxPG_FL_SCROLLED
;
1257 // -----------------------------------------------------------------------
1258 // wxPropertyGrid helper methods called by properties
1259 // -----------------------------------------------------------------------
1261 // Control font changer helper.
1262 void wxPropertyGrid::SetCurControlBoldFont()
1264 wxASSERT( m_wndEditor
);
1265 m_wndEditor
->SetFont( m_captionFont
);
1268 // -----------------------------------------------------------------------
1270 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1273 #if wxPG_SMALL_SCREEN
1274 // On small-screen devices, always show dialogs with default position and size.
1275 return wxDefaultPosition
;
1277 int splitterX
= GetSplitterPosition();
1281 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1283 ImprovedClientToScreen( &x
, &y
);
1285 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1286 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1293 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1303 new_y
= y
+ m_lineHeight
;
1305 return wxPoint(new_x
,new_y
);
1309 // -----------------------------------------------------------------------
1311 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1313 if ( src_str
.length() == 0 )
1319 bool prev_is_slash
= false;
1321 wxString::const_iterator i
= src_str
.begin();
1325 for ( ; i
!= src_str
.end(); ++i
)
1329 if ( a
!= wxS('\\') )
1331 if ( !prev_is_slash
)
1337 if ( a
== wxS('n') )
1340 dst_str
<< wxS('\n');
1342 dst_str
<< wxS('\n');
1345 else if ( a
== wxS('t') )
1346 dst_str
<< wxS('\t');
1350 prev_is_slash
= false;
1354 if ( prev_is_slash
)
1356 dst_str
<< wxS('\\');
1357 prev_is_slash
= false;
1361 prev_is_slash
= true;
1368 // -----------------------------------------------------------------------
1370 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1372 if ( src_str
.length() == 0 )
1378 wxString::const_iterator i
= src_str
.begin();
1379 wxUniChar prev_a
= wxS('\0');
1383 for ( ; i
!= src_str
.end(); ++i
)
1387 if ( a
>= wxS(' ') )
1389 // This surely is not something that requires an escape sequence.
1394 // This might need...
1395 if ( a
== wxS('\r') )
1397 // DOS style line end.
1398 // Already taken care below
1400 else if ( a
== wxS('\n') )
1401 // UNIX style line end.
1402 dst_str
<< wxS("\\n");
1403 else if ( a
== wxS('\t') )
1405 dst_str
<< wxS('\t');
1408 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1418 // -----------------------------------------------------------------------
1420 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1424 return (wxPGProperty
*) NULL
;
1427 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1430 // -----------------------------------------------------------------------
1431 // wxPropertyGrid graphics related methods
1432 // -----------------------------------------------------------------------
1434 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1438 // Update everything inside the box
1439 wxRect r
= GetUpdateRegion().GetBox();
1441 dc
.SetPen(m_colEmptySpace
);
1442 dc
.SetBrush(m_colEmptySpace
);
1443 dc
.DrawRectangle(r
);
1446 // -----------------------------------------------------------------------
1448 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1449 wxPGProperty
* property
) const
1451 // Prepare rectangle to be used
1453 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1454 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1456 #if (wxPG_USE_RENDERER_NATIVE)
1458 #elif wxPG_ICON_WIDTH
1459 // Drawing expand/collapse button manually
1460 dc
.SetPen(m_colPropFore
);
1461 if ( property
->IsCategory() )
1462 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1464 dc
.SetBrush(m_colPropBack
);
1466 dc
.DrawRectangle( r
);
1467 int _y
= r
.y
+(m_iconWidth
/2);
1468 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1473 if ( property
->IsExpanded() )
1475 // wxRenderer functions are non-mutating in nature, so it
1476 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1477 // Hopefully this does not cause problems.
1478 #if (wxPG_USE_RENDERER_NATIVE)
1479 wxRendererNative::Get().DrawTreeItemButton(
1485 #elif wxPG_ICON_WIDTH
1494 #if (wxPG_USE_RENDERER_NATIVE)
1495 wxRendererNative::Get().DrawTreeItemButton(
1501 #elif wxPG_ICON_WIDTH
1502 int _x
= r
.x
+(m_iconWidth
/2);
1503 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1509 #if (wxPG_USE_RENDERER_NATIVE)
1511 #elif wxPG_ICON_WIDTH
1514 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1518 // -----------------------------------------------------------------------
1521 // This is the one called by OnPaint event handler and others.
1522 // topy and bottomy are already unscrolled (ie. physical)
1524 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1526 unsigned int bottomy
,
1527 const wxRect
* clipRect
)
1529 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1531 m_pState
->EnsureVirtualHeight();
1533 wxRect tempClipRect
;
1536 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1537 clipRect
= &tempClipRect
;
1540 // items added check
1541 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1543 int paintFinishY
= 0;
1545 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1548 bool isBuffered
= false;
1550 #if wxPG_DOUBLE_BUFFER
1551 wxMemoryDC
* bufferDC
= NULL
;
1553 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1555 if ( !m_doubleBuffer
)
1557 paintFinishY
= clipRect
->y
;
1562 bufferDC
= new wxMemoryDC();
1564 // If nothing was changed, then just copy from double-buffer
1565 bufferDC
->SelectObject( *m_doubleBuffer
);
1575 dc
.SetClippingRegion( *clipRect
);
1576 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1579 #if wxPG_DOUBLE_BUFFER
1582 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1583 bufferDC
, 0, 0, wxCOPY
);
1584 dc
.DestroyClippingRegion(); // Is this really necessary?
1590 // Clear area beyond bottomY?
1591 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1593 dc
.SetPen(m_colEmptySpace
);
1594 dc
.SetBrush(m_colEmptySpace
);
1595 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1599 // -----------------------------------------------------------------------
1601 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1602 const wxPGProperty
* firstItem
,
1603 const wxPGProperty
* lastItem
,
1604 const wxRect
* clipRect
,
1605 bool isBuffered
) const
1607 // TODO: This should somehow be eliminated.
1608 wxRect tempClipRect
;
1611 wxASSERT(firstItem
);
1613 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1614 clipRect
= &tempClipRect
;
1618 firstItem
= DoGetItemAtY(clipRect
->y
);
1622 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1624 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1627 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1630 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1631 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1633 int lh
= m_lineHeight
;
1636 int lastItemBottomY
;
1638 firstItemTopY
= clipRect
->y
;
1639 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1641 // Align y coordinates to item boundaries
1642 firstItemTopY
-= firstItemTopY
% lh
;
1643 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1644 lastItemBottomY
-= 1;
1646 // Entire range outside scrolled, visible area?
1647 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1650 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1654 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1655 firstItem->GetLabel().c_str(),
1656 lastItem->GetLabel().c_str(),
1657 (int)(lastItemBottomY - firstItemTopY),
1659 (unsigned long)clipRect );
1664 long windowStyle
= m_windowStyle
;
1670 // With wxPG_DOUBLE_BUFFER, do double buffering
1671 // - buffer's y = 0, so align cliprect and coordinates to that
1673 #if wxPG_DOUBLE_BUFFER
1679 xRelMod
= clipRect
->x
;
1680 yRelMod
= clipRect
->y
;
1683 // clipRect conversion
1688 firstItemTopY
-= yRelMod
;
1689 lastItemBottomY
-= yRelMod
;
1692 wxUnusedVar(isBuffered
);
1695 int x
= m_marginWidth
- xRelMod
;
1697 const wxFont
& normalfont
= m_font
;
1699 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) != 0;
1701 bool isEnabled
= IsEnabled();
1704 // Prepare some pens and brushes that are often changed to.
1707 wxBrush
marginBrush(m_colMargin
);
1708 wxPen
marginPen(m_colMargin
);
1709 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1710 wxPen
linepen(m_colLine
,1,wxSOLID
);
1712 // pen that has same colour as text
1713 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1716 // Clear margin with background colour
1718 dc
.SetBrush( marginBrush
);
1719 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1721 dc
.SetPen( *wxTRANSPARENT_PEN
);
1722 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1725 const wxPGProperty
* selected
= m_selected
;
1726 const wxPropertyGridPageState
* state
= m_pState
;
1728 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1729 bool wasSelectedPainted
= false;
1732 // TODO: Only render columns that are within clipping region.
1734 dc
.SetFont(normalfont
);
1736 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1737 int endScanBottomY
= lastItemBottomY
+ lh
;
1738 int y
= firstItemTopY
;
1741 // Pregenerate list of visible properties.
1742 wxArrayPGProperty visPropArray
;
1743 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1745 for ( ; !it
.AtEnd(); it
.Next() )
1747 const wxPGProperty
* p
= *it
;
1749 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1751 visPropArray
.push_back((wxPGProperty
*)p
);
1753 if ( y
> endScanBottomY
)
1760 visPropArray
.push_back(NULL
);
1762 wxPGProperty
* nextP
= visPropArray
[0];
1764 int gridWidth
= state
->m_width
;
1767 for ( unsigned int arrInd
=1;
1768 nextP
&& y
<= lastItemBottomY
;
1771 wxPGProperty
* p
= nextP
;
1772 nextP
= visPropArray
[arrInd
];
1774 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1775 int textMarginHere
= x
;
1776 int renderFlags
= 0;
1778 int greyDepth
= m_marginWidth
;
1779 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1780 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1782 int greyDepthX
= greyDepth
- xRelMod
;
1784 // Use basic depth if in non-categoric mode and parent is base array.
1785 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1787 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1790 // Paint margin area
1791 dc
.SetBrush(marginBrush
);
1792 dc
.SetPen(marginPen
);
1793 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1795 dc
.SetPen( linepen
);
1800 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1806 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1808 sx
+= state
->m_colWidths
[si
];
1809 dc
.DrawLine( sx
, y
, sx
, y2
);
1812 // Horizontal Line, below
1813 // (not if both this and next is category caption)
1814 if ( p
->IsCategory() &&
1815 nextP
&& nextP
->IsCategory() )
1816 dc
.SetPen(m_colCapBack
);
1818 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1821 // Need to override row colours?
1825 if ( p
!= selected
)
1827 // Disabled may get different colour.
1828 if ( !p
->IsEnabled() )
1830 renderFlags
|= wxPGCellRenderer::Disabled
|
1831 wxPGCellRenderer::DontUseCellFgCol
;
1832 rowFgCol
= m_colDisPropFore
;
1837 renderFlags
|= wxPGCellRenderer::Selected
;
1839 if ( !p
->IsCategory() )
1841 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1842 wxPGCellRenderer::DontUseCellBgCol
;
1844 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1845 wasSelectedPainted
= true;
1848 // Selected gets different colour.
1849 if ( reallyFocused
)
1851 rowFgCol
= m_colSelFore
;
1852 rowBgCol
= m_colSelBack
;
1854 else if ( isEnabled
)
1856 rowFgCol
= m_colPropFore
;
1857 rowBgCol
= m_colMargin
;
1861 rowFgCol
= m_colDisPropFore
;
1862 rowBgCol
= m_colSelBack
;
1869 if ( rowBgCol
.IsOk() )
1870 rowBgBrush
= wxBrush(rowBgCol
);
1872 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1873 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1876 // Fill additional margin area with background colour of first cell
1877 if ( greyDepthX
< textMarginHere
)
1879 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1881 wxPGCell
& cell
= p
->GetCell(0);
1882 rowBgCol
= cell
.GetBgCol();
1883 rowBgBrush
= wxBrush(rowBgCol
);
1885 dc
.SetBrush(rowBgBrush
);
1886 dc
.SetPen(rowBgCol
);
1887 dc
.DrawRectangle(greyDepthX
+1, y
,
1888 textMarginHere
-greyDepthX
, lh
-1);
1891 bool fontChanged
= false;
1893 // Expander button rectangle
1894 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1899 if ( p
->IsCategory() )
1901 // Captions have their cell areas merged as one
1902 dc
.SetFont(m_captionFont
);
1904 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1906 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1908 dc
.SetBrush(rowBgBrush
);
1909 dc
.SetPen(rowBgCol
);
1912 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1914 dc
.SetTextForeground(rowFgCol
);
1917 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1918 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1921 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1922 DrawExpanderButton( dc
, butRect
, p
);
1926 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1928 dc
.SetFont(m_captionFont
);
1934 int nextCellWidth
= state
->m_colWidths
[0];
1935 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1936 int textXAdd
= textMarginHere
- greyDepthX
;
1938 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1940 cellRect
.width
= nextCellWidth
- 1;
1942 bool ctrlCell
= false;
1943 int cellRenderFlags
= renderFlags
;
1946 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1947 DrawExpanderButton( dc
, butRect
, p
);
1950 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1952 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1953 dc
.SetBrush(editorBgCol
);
1954 dc
.SetPen(editorBgCol
);
1955 dc
.SetTextForeground(m_colPropFore
);
1956 dc
.DrawRectangle(cellRect
);
1958 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1963 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1965 dc
.SetBrush(rowBgBrush
);
1966 dc
.SetPen(rowBgCol
);
1969 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1971 dc
.SetTextForeground(rowFgCol
);
1975 dc
.SetClippingRegion(cellRect
);
1977 cellRect
.x
+= textXAdd
;
1978 cellRect
.width
-= textXAdd
;
1983 wxPGCellRenderer
* renderer
;
1984 int cmnVal
= p
->GetCommonValue();
1985 if ( cmnVal
== -1 || ci
!= 1 )
1987 renderer
= p
->GetCellRenderer(ci
);
1988 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1993 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
1994 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
1999 cellX
+= state
->m_colWidths
[ci
];
2000 if ( ci
< (state
->m_colWidths
.size()-1) )
2001 nextCellWidth
= state
->m_colWidths
[ci
+1];
2003 dc
.DestroyClippingRegion(); // Is this really necessary?
2009 dc
.SetFont(normalfont
);
2014 // Refresh editor controls (seems not needed on msw)
2015 // NOTE: This code is mandatory for GTK!
2016 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2017 if ( wasSelectedPainted
)
2020 m_wndEditor
->Refresh();
2022 m_wndEditor2
->Refresh();
2029 // -----------------------------------------------------------------------
2031 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2035 if ( m_width
< 10 || m_height
< 10 ||
2036 !m_pState
->m_properties
->GetChildCount() ||
2037 p1
== (wxPGProperty
*) NULL
)
2038 return wxRect(0,0,0,0);
2043 // Return rect which encloses the given property range
2045 int visTop
= p1
->GetY();
2048 visBottom
= p2
->GetY() + m_lineHeight
;
2050 visBottom
= m_height
+ visTop
;
2052 // If seleced property is inside the range, we'll extend the range to include
2054 wxPGProperty
* selected
= m_selected
;
2057 int selectedY
= selected
->GetY();
2058 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2060 wxWindow
* editor
= GetEditorControl();
2063 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2064 if ( visBottom2
> visBottom
)
2065 visBottom
= visBottom2
;
2070 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2073 // -----------------------------------------------------------------------
2075 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2080 if ( m_pState
->m_itemsAdded
)
2081 PrepareAfterItemsAdded();
2083 wxRect r
= GetPropertyRect(p1
, p2
);
2086 m_canvas
->RefreshRect(r
);
2090 // -----------------------------------------------------------------------
2092 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2094 if ( p
== m_selected
)
2095 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2097 DrawItemAndChildren(p
);
2100 // -----------------------------------------------------------------------
2102 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2107 // Draw item, children, and parent too, if it is not category
2108 wxPGProperty
* parent
= p
->GetParent();
2111 !parent
->IsCategory() &&
2112 parent
->GetParent() )
2115 parent
= parent
->GetParent();
2118 DrawItemAndChildren(p
);
2121 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2123 wxCHECK_RET( p
, wxT("invalid property id") );
2125 // Do not draw if in non-visible page
2126 if ( p
->GetParentState() != m_pState
)
2129 // do not draw a single item if multiple pending
2130 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2133 // Update child control.
2134 if ( m_selected
&& m_selected
->GetParent() == p
)
2137 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2139 DrawItems(p
, lastDrawn
);
2142 // -----------------------------------------------------------------------
2144 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2145 const wxRect
*rect
)
2147 PrepareAfterItemsAdded();
2149 wxWindow::Refresh(false);
2151 // TODO: Coordinate translation
2152 m_canvas
->Refresh(false, rect
);
2154 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2155 // I think this really helps only GTK+1.2
2156 if ( m_wndEditor
) m_wndEditor
->Refresh();
2157 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2161 // -----------------------------------------------------------------------
2162 // wxPropertyGrid global operations
2163 // -----------------------------------------------------------------------
2165 void wxPropertyGrid::Clear()
2167 ClearSelection(false);
2169 m_pState
->DoClear();
2175 RecalculateVirtualSize();
2177 // Need to clear some area at the end
2179 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2182 // -----------------------------------------------------------------------
2184 bool wxPropertyGrid::EnableCategories( bool enable
)
2186 ClearSelection(false);
2191 // Enable categories
2194 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2199 // Disable categories
2201 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2204 if ( !m_pState
->EnableCategories(enable
) )
2209 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2211 m_pState
->m_itemsAdded
= 1; // force
2212 PrepareAfterItemsAdded();
2216 m_pState
->m_itemsAdded
= 1;
2218 // No need for RecalculateVirtualSize() here - it is already called in
2219 // wxPropertyGridPageState method above.
2226 // -----------------------------------------------------------------------
2228 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2230 wxASSERT( pNewState
);
2231 wxASSERT( pNewState
->GetGrid() );
2233 if ( pNewState
== m_pState
)
2236 wxPGProperty
* oldSelection
= m_selected
;
2238 ClearSelection(false);
2240 m_pState
->m_selected
= oldSelection
;
2242 bool orig_mode
= m_pState
->IsInNonCatMode();
2243 bool new_state_mode
= pNewState
->IsInNonCatMode();
2245 m_pState
= pNewState
;
2248 int pgWidth
= GetClientSize().x
;
2249 if ( HasVirtualWidth() )
2251 int minWidth
= pgWidth
;
2252 if ( pNewState
->m_width
< minWidth
)
2254 pNewState
->m_width
= minWidth
;
2255 pNewState
->CheckColumnWidths();
2261 // Just in case, fully re-center splitter
2262 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2263 pNewState
->m_fSplitterX
= -1.0;
2265 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2268 m_propHover
= (wxPGProperty
*) NULL
;
2270 // If necessary, convert state to correct mode.
2271 if ( orig_mode
!= new_state_mode
)
2273 // This should refresh as well.
2274 EnableCategories( orig_mode
?false:true );
2276 else if ( !m_frozen
)
2278 // Refresh, if not frozen.
2279 if ( m_pState
->m_itemsAdded
)
2280 PrepareAfterItemsAdded();
2283 if ( m_pState
->m_selected
)
2284 DoSelectProperty( m_pState
->m_selected
);
2286 RecalculateVirtualSize(0);
2290 m_pState
->m_itemsAdded
= 1;
2293 // -----------------------------------------------------------------------
2295 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2297 wxPG_PROP_ARG_CALL_PROLOG()
2299 m_pState
->SortChildren( p
);
2302 // -----------------------------------------------------------------------
2304 void wxPropertyGrid::Sort()
2306 ClearSelection(false); // This must be before state clear
2311 // -----------------------------------------------------------------------
2313 // Call to SetSplitterPosition will always disable splitter auto-centering
2314 // if parent window is shown.
2315 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2317 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2320 wxPropertyGridPageState
* state
= m_pState
;
2322 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2327 CorrectEditorWidgetSizeX();
2333 // -----------------------------------------------------------------------
2335 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2337 SetSplitterPosition( m_width
/2, true );
2338 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2339 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2342 // -----------------------------------------------------------------------
2343 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2344 // -----------------------------------------------------------------------
2346 // Returns nearest paint visible property (such that will be painted unless
2347 // window is scrolled or resized). If given property is paint visible, then
2348 // it itself will be returned
2349 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2351 int vx
,vy1
;// Top left corner of client
2352 GetViewStart(&vx
,&vy1
);
2353 vy1
*= wxPG_PIXELS_PER_UNIT
;
2355 int vy2
= vy1
+ m_height
;
2356 int propY
= p
->GetY2(m_lineHeight
);
2358 if ( (propY
+ m_lineHeight
) < vy1
)
2361 return DoGetItemAtY( vy1
);
2363 else if ( propY
> vy2
)
2366 return DoGetItemAtY( vy2
);
2369 // Itself paint visible
2374 // -----------------------------------------------------------------------
2375 // Methods related to change in value, value modification and sending events
2376 // -----------------------------------------------------------------------
2378 // commits any changes in editor of selected property
2379 // return true if validation did not fail
2380 // flags are same as with DoSelectProperty
2381 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2383 // Committing already?
2384 if ( m_inCommitChangesFromEditor
)
2387 // Don't do this if already processing editor event. It might
2388 // induce recursive dialogs and crap like that.
2389 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2391 if ( m_inDoPropertyChanged
)
2398 IsEditorsValueModified() &&
2399 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2402 m_inCommitChangesFromEditor
= 1;
2404 wxVariant
variant(m_selected
->GetValueRef());
2405 bool valueIsPending
= false;
2407 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2408 // due to another window getting focus
2409 wxWindow
* oldFocus
= m_curFocused
;
2411 bool validationFailure
= false;
2412 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2414 m_chgInfo_changedProperty
= NULL
;
2416 // If truly modified, schedule value as pending.
2417 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2419 if ( DoEditorValidate() &&
2420 PerformValidation(m_selected
, variant
) )
2422 valueIsPending
= true;
2426 validationFailure
= true;
2431 EditorsValueWasNotModified();
2436 m_inCommitChangesFromEditor
= 0;
2438 if ( validationFailure
&& !forceSuccess
)
2442 oldFocus
->SetFocus();
2443 m_curFocused
= oldFocus
;
2446 res
= OnValidationFailure(m_selected
, variant
);
2448 // Now prevent further validation failure messages
2451 EditorsValueWasNotModified();
2452 OnValidationFailureReset(m_selected
);
2455 else if ( valueIsPending
)
2457 DoPropertyChanged( m_selected
, flags
);
2458 EditorsValueWasNotModified();
2467 // -----------------------------------------------------------------------
2469 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2473 // Runs all validation functionality.
2474 // Returns true if value passes all tests.
2477 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2479 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2481 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2486 // Adapt list to child values, if necessary
2487 wxVariant listValue
= pendingValue
;
2488 wxVariant
* pPendingValue
= &pendingValue
;
2489 wxVariant
* pList
= NULL
;
2491 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2492 // string value, then we need treat as it was changed instead
2493 // (or, in addition, as is the case with composite string parent).
2494 // This includes creating list variant for child values.
2496 wxPGProperty
* pwc
= p
->GetParent();
2497 wxPGProperty
* changedProperty
= p
;
2498 wxPGProperty
* baseChangedProperty
= changedProperty
;
2499 wxVariant bcpPendingList
;
2501 listValue
= pendingValue
;
2502 listValue
.SetName(p
->GetBaseName());
2505 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2507 wxVariantList tempList
;
2508 wxVariant
lv(tempList
, pwc
->GetBaseName());
2509 lv
.Append(listValue
);
2511 pPendingValue
= &listValue
;
2513 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2515 baseChangedProperty
= pwc
;
2516 bcpPendingList
= lv
;
2519 changedProperty
= pwc
;
2520 pwc
= pwc
->GetParent();
2524 wxPGProperty
* evtChangingProperty
= changedProperty
;
2526 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2528 value
= *pPendingValue
;
2532 // Convert list to child values
2533 pList
= pPendingValue
;
2534 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2537 wxVariant evtChangingValue
= value
;
2539 if ( flags
& SendEvtChanging
)
2541 // FIXME: After proper ValueToString()s added, remove
2542 // this. It is just a temporary fix, as evt_changing
2543 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2544 // (unless it is selected, and textctrl editor is open).
2545 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2547 evtChangingProperty
= baseChangedProperty
;
2548 if ( evtChangingProperty
!= p
)
2550 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2554 evtChangingValue
= pendingValue
;
2558 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2560 if ( changedProperty
== m_selected
)
2562 wxWindow
* editor
= GetEditorControl();
2563 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2564 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2568 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2573 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2574 m_chgInfo_changedProperty
= changedProperty
;
2575 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2576 m_chgInfo_pendingValue
= value
;
2579 m_chgInfo_valueList
= *pList
;
2581 m_chgInfo_valueList
.MakeNull();
2583 // If changedProperty is not property which value was edited,
2584 // then call wxPGProperty::ValidateValue() for that as well.
2585 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2587 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2591 if ( flags
& SendEvtChanging
)
2593 // SendEvent returns true if event was vetoed
2594 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2598 if ( flags
& IsStandaloneValidation
)
2600 // If called in 'generic' context, we need to reset
2601 // m_chgInfo_changedProperty and write back translated value.
2602 m_chgInfo_changedProperty
= NULL
;
2603 pendingValue
= value
;
2609 // -----------------------------------------------------------------------
2611 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2613 if ( !msg
.length() )
2617 if ( !wxPGGlobalVars
->m_offline
)
2619 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2622 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2625 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2628 pStatusBar
->SetStatusText(msg
);
2636 ::wxMessageBox(msg
, _T("Property Error"));
2639 // -----------------------------------------------------------------------
2641 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2643 int vfb
= m_validationInfo
.m_failureBehavior
;
2645 if ( vfb
& wxPG_VFB_BEEP
)
2648 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2649 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2651 unsigned int colCount
= m_pState
->GetColumnCount();
2653 // We need backup marked property's cells
2654 m_propCellsBackup
= property
->m_cells
;
2656 wxColour vfbFg
= *wxWHITE
;
2657 wxColour vfbBg
= *wxRED
;
2659 property
->EnsureCells(colCount
);
2661 for ( unsigned int i
=0; i
<colCount
; i
++ )
2663 wxPGCell
& cell
= property
->m_cells
[i
];
2664 cell
.SetFgCol(vfbFg
);
2665 cell
.SetBgCol(vfbBg
);
2668 DrawItemAndChildren(property
);
2670 if ( property
== m_selected
)
2672 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2674 wxWindow
* editor
= GetEditorControl();
2677 editor
->SetForegroundColour(vfbFg
);
2678 editor
->SetBackgroundColour(vfbBg
);
2683 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2685 wxString msg
= m_validationInfo
.m_failureMessage
;
2687 if ( !msg
.length() )
2688 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2690 DoShowPropertyError(property
, msg
);
2693 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2696 // -----------------------------------------------------------------------
2698 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2700 int vfb
= m_validationInfo
.m_failureBehavior
;
2702 if ( vfb
& wxPG_VFB_MARK_CELL
)
2705 property
->m_cells
= m_propCellsBackup
;
2707 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2709 if ( property
== m_selected
&& GetEditorControl() )
2711 // Calling this will recreate the control, thus resetting its colour
2712 RefreshProperty(property
);
2716 DrawItemAndChildren(property
);
2721 // -----------------------------------------------------------------------
2723 // flags are same as with DoSelectProperty
2724 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2726 if ( m_inDoPropertyChanged
)
2729 wxWindow
* editor
= GetEditorControl();
2731 m_pState
->m_anyModified
= 1;
2733 m_inDoPropertyChanged
= 1;
2735 // Maybe need to update control
2736 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2738 // These values were calculated in PerformValidation()
2739 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2740 wxVariant value
= m_chgInfo_pendingValue
;
2742 wxPGProperty
* topPaintedProperty
= changedProperty
;
2744 while ( !topPaintedProperty
->IsCategory() &&
2745 !topPaintedProperty
->IsRoot() )
2747 topPaintedProperty
= topPaintedProperty
->GetParent();
2750 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2752 // Set as Modified (not if dragging just began)
2753 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2755 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2756 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2759 SetCurControlBoldFont();
2765 // Propagate updates to parent(s)
2767 wxPGProperty
* prevPwc
= NULL
;
2769 while ( prevPwc
!= topPaintedProperty
)
2771 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2773 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2776 SetCurControlBoldFont();
2780 pwc
= pwc
->GetParent();
2783 // Draw the actual property
2784 DrawItemAndChildren( topPaintedProperty
);
2787 // If value was set by wxPGProperty::OnEvent, then update the editor
2789 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2795 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2796 if ( m_wndEditor
) m_wndEditor
->Refresh();
2797 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2802 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2804 // If top parent has composite string value, then send to child parents,
2805 // starting from baseChangedProperty.
2806 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2808 pwc
= m_chgInfo_baseChangedProperty
;
2810 while ( pwc
!= changedProperty
)
2812 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2813 pwc
= pwc
->GetParent();
2817 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2819 m_inDoPropertyChanged
= 0;
2824 // -----------------------------------------------------------------------
2826 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2828 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2830 m_chgInfo_changedProperty
= NULL
;
2832 if ( PerformValidation(p
, newValue
) )
2834 DoPropertyChanged(p
);
2839 OnValidationFailure(p
, newValue
);
2845 // -----------------------------------------------------------------------
2847 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2849 wxPGProperty
* prop
= GetSelectedProperty();
2852 return wxNullVariant
;
2854 wxTextCtrl
* tc
= GetEditorTextCtrl();
2855 wxVariant value
= prop
->GetValue();
2857 if ( !tc
|| !IsEditorsValueModified() )
2860 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2863 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2864 return prop
->GetValue();
2869 // -----------------------------------------------------------------------
2871 // Runs wxValidator for the selected property
2872 bool wxPropertyGrid::DoEditorValidate()
2877 // -----------------------------------------------------------------------
2879 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent
&event
)
2881 wxPGProperty
* selected
= m_selected
;
2883 // Somehow, event is handled after property has been deselected.
2884 // Possibly, but very rare.
2888 if ( m_iFlags
& wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
)
2891 wxVariant
pendingValue(selected
->GetValueRef());
2892 wxWindow
* wnd
= GetEditorControl();
2894 bool wasUnspecified
= selected
->IsValueUnspecified();
2895 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2897 bool valueIsPending
= false;
2899 m_chgInfo_changedProperty
= NULL
;
2901 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2904 // Filter out excess wxTextCtrl modified events
2905 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2907 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2909 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2911 wxString newTcValue
= tc
->GetValue();
2912 if ( m_prevTcValue
== newTcValue
)
2915 m_prevTcValue
= newTcValue
;
2918 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
2920 bool validationFailure
= false;
2921 bool buttonWasHandled
= false;
2924 // Try common button handling
2925 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2927 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2931 buttonWasHandled
= true;
2932 // Store as res2, as previously (and still currently alternatively)
2933 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2934 // in wxPGProperty::OnEvent().
2935 adapter
->ShowDialog( this, selected
);
2940 if ( !buttonWasHandled
)
2944 // First call editor class' event handler.
2945 const wxPGEditor
* editor
= selected
->GetEditorClass();
2947 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2949 // If changes, validate them
2950 if ( DoEditorValidate() )
2952 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
2953 valueIsPending
= true;
2957 validationFailure
= true;
2962 // Then the property's custom handler (must be always called, unless
2963 // validation failed).
2964 if ( !validationFailure
)
2965 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
2968 // SetValueInEvent(), as called in one of the functions referred above
2969 // overrides editor's value.
2970 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
2972 valueIsPending
= true;
2973 pendingValue
= m_changeInEventValue
;
2974 selFlags
|= wxPG_SEL_DIALOGVAL
;
2977 if ( !validationFailure
&& valueIsPending
)
2978 if ( !PerformValidation(m_selected
, pendingValue
) )
2979 validationFailure
= true;
2981 if ( validationFailure
)
2983 OnValidationFailure(selected
, pendingValue
);
2985 else if ( valueIsPending
)
2987 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
2989 DoPropertyChanged(selected
, selFlags
);
2990 EditorsValueWasNotModified();
2992 // Regardless of editor type, unfocus editor on
2993 // text-editing related enter press.
2994 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3001 // No value after all
3003 // Regardless of editor type, unfocus editor on
3004 // text-editing related enter press.
3005 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3010 // Let unhandled button click events go to the parent
3011 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3013 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3014 GetEventHandler()->AddPendingEvent(evt
);
3018 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
);
3021 // -----------------------------------------------------------------------
3022 // wxPropertyGrid editor control helper methods
3023 // -----------------------------------------------------------------------
3025 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3027 int itemy
= p
->GetY2(m_lineHeight
);
3029 int cust_img_space
= 0;
3030 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3031 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3033 // TODO: If custom image detection changes from current, change this.
3034 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3036 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3037 int imwid
= p
->OnMeasureImage().x
;
3038 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3039 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3044 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3046 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3051 // -----------------------------------------------------------------------
3053 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3055 wxSize sz
= GetImageSize(p
, item
);
3056 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3057 wxPG_CUSTOM_IMAGE_SPACINGY
,
3062 // return size of custom paint image
3063 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3065 // If called with NULL property, then return default image
3066 // size for properties that use image.
3068 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3070 wxSize cis
= p
->OnMeasureImage(item
);
3072 int choiceCount
= p
->m_choices
.GetCount();
3073 int comVals
= p
->GetDisplayedCommonValueCount();
3074 if ( item
>= choiceCount
&& comVals
> 0 )
3076 unsigned int cvi
= item
-choiceCount
;
3077 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3079 else if ( item
>= 0 && choiceCount
== 0 )
3080 return wxSize(0, 0);
3085 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3090 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3097 // -----------------------------------------------------------------------
3099 // takes scrolling into account
3100 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3103 GetViewStart(&vx
,&vy
);
3104 vy
*=wxPG_PIXELS_PER_UNIT
;
3105 vx
*=wxPG_PIXELS_PER_UNIT
;
3108 ClientToScreen( px
, py
);
3111 // -----------------------------------------------------------------------
3113 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3116 GetViewStart(&pt2
.x
,&pt2
.y
);
3117 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3118 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3122 return m_pState
->HitTest(pt2
);
3125 // -----------------------------------------------------------------------
3127 // custom set cursor
3128 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3130 if ( type
== m_curcursor
&& !override
) return;
3132 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3134 if ( type
== wxCURSOR_SIZEWE
)
3135 cursor
= m_cursorSizeWE
;
3137 m_canvas
->SetCursor( *cursor
);
3142 // -----------------------------------------------------------------------
3143 // wxPropertyGrid property selection, editor creation
3144 // -----------------------------------------------------------------------
3147 // This class forwards events from property editor controls to wxPropertyGrid.
3148 class wxPropertyGridEditorEventForwarder
: public wxEvtHandler
3151 wxPropertyGridEditorEventForwarder( wxPropertyGrid
* propGrid
)
3152 : wxEvtHandler(), m_propGrid(propGrid
)
3156 virtual ~wxPropertyGridEditorEventForwarder()
3161 bool ProcessEvent( wxEvent
& event
)
3166 m_propGrid
->HandleCustomEditorEvent(event
);
3168 return wxEvtHandler::ProcessEvent(event
);
3171 wxPropertyGrid
* m_propGrid
;
3174 // Setups event handling for child control
3175 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3177 wxWindowID id
= argWnd
->GetId();
3179 if ( argWnd
== m_wndEditor
)
3181 argWnd
->Connect(id
, wxEVT_MOTION
,
3182 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3184 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3185 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3187 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3188 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3190 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3191 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3193 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3194 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3196 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3197 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3201 wxPropertyGridEditorEventForwarder
* forwarder
;
3202 forwarder
= new wxPropertyGridEditorEventForwarder(this);
3203 argWnd
->PushEventHandler(forwarder
);
3205 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3206 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3210 void wxPropertyGrid::FreeEditors()
3213 // Return focus back to canvas from children (this is required at least for
3214 // GTK+, which, unlike Windows, clears focus when control is destroyed
3215 // instead of moving it to closest parent).
3216 wxWindow
* focus
= wxWindow::FindFocus();
3219 wxWindow
* parent
= focus
->GetParent();
3222 if ( parent
== m_canvas
)
3227 parent
= parent
->GetParent();
3231 // Do not free editors immediately if processing events
3234 m_wndEditor2
->PopEventHandler(true);
3235 m_wndEditor2
->Hide();
3236 wxPendingDelete
.Append( m_wndEditor2
);
3237 m_wndEditor2
= (wxWindow
*) NULL
;
3242 m_wndEditor
->PopEventHandler(true);
3243 m_wndEditor
->Hide();
3244 wxPendingDelete
.Append( m_wndEditor
);
3245 m_wndEditor
= (wxWindow
*) NULL
;
3249 // Call with NULL to de-select property
3250 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3254 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3255 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3257 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3260 if ( m_inDoSelectProperty
)
3263 m_inDoSelectProperty
= 1;
3265 wxPGProperty
* prev
= m_selected
;
3269 m_inDoSelectProperty
= 0;
3275 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3277 wxPrintf( "None selected\n" );
3280 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3282 wxPrintf( "P = NULL\n" );
3285 // If we are frozen, then just set the values.
3288 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3289 m_editorFocused
= 0;
3292 m_pState
->m_selected
= p
;
3294 // If frozen, always free controls. But don't worry, as Thaw will
3295 // recall SelectProperty to recreate them.
3298 // Prevent any further selection measures in this call
3299 p
= (wxPGProperty
*) NULL
;
3304 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3306 // Only set focus if not deselecting
3309 if ( flags
& wxPG_SEL_FOCUS
)
3313 m_wndEditor
->SetFocus();
3314 m_editorFocused
= 1;
3323 m_inDoSelectProperty
= 0;
3328 // First, deactivate previous
3332 OnValidationFailureReset(m_selected
);
3334 // Must double-check if this is an selected in case of forceswitch
3337 if ( !CommitChangesFromEditor(flags
) )
3339 // Validation has failed, so we can't exit the previous editor
3340 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3341 // _("Invalid Value"),wxOK|wxICON_ERROR);
3342 m_inDoSelectProperty
= 0;
3350 m_selected
= (wxPGProperty
*) NULL
;
3351 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3353 // We need to always fully refresh the grid here
3356 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3357 EditorsValueWasNotModified();
3360 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3363 // Then, activate the one given.
3366 int propY
= p
->GetY2(m_lineHeight
);
3368 int splitterX
= GetSplitterPosition();
3369 m_editorFocused
= 0;
3371 m_pState
->m_selected
= p
;
3372 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3374 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3376 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3379 // Only create editor for non-disabled non-caption
3380 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3382 // do this for non-caption items
3386 // Do we need to paint the custom image, if any?
3387 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3388 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3389 !p
->GetEditorClass()->CanContainCustomImage()
3391 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3393 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3394 wxPoint goodPos
= grect
.GetPosition();
3395 #if wxPG_CREATE_CONTROLS_HIDDEN
3396 int coord_adjust
= m_height
- goodPos
.y
;
3397 goodPos
.y
+= coord_adjust
;
3400 const wxPGEditor
* editor
= p
->GetEditorClass();
3401 wxCHECK_MSG(editor
, false,
3402 wxT("NULL editor class not allowed"));
3404 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3406 wxPGWindowList wndList
= editor
->CreateControls(this,
3411 m_wndEditor
= wndList
.m_primary
;
3412 m_wndEditor2
= wndList
.m_secondary
;
3413 wxWindow
* primaryCtrl
= GetEditorControl();
3416 // Essentially, primaryCtrl == m_wndEditor
3419 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3420 // value is drawn as normal, and m_wndEditor2 is assumed
3421 // to be a right-aligned button that triggers a separate editorCtrl
3426 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3427 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3429 // Set validator, if any
3430 #if wxUSE_VALIDATORS
3431 wxValidator
* validator
= p
->GetValidator();
3433 primaryCtrl
->SetValidator(*validator
);
3436 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3437 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3439 // If it has modified status, use bold font
3440 // (must be done before capturing m_ctrlXAdjust)
3441 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3442 SetCurControlBoldFont();
3445 // Fix TextCtrl indentation
3446 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3447 wxTextCtrl
* tc
= NULL
;
3448 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3449 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3451 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3453 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3456 // Store x relative to splitter (we'll need it).
3457 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3459 // Check if background clear is not necessary
3460 wxPoint pos
= m_wndEditor
->GetPosition();
3461 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3463 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3466 m_wndEditor
->SetSizeHints(3, 3);
3468 #if wxPG_CREATE_CONTROLS_HIDDEN
3469 m_wndEditor
->Show(false);
3470 m_wndEditor
->Freeze();
3472 goodPos
= m_wndEditor
->GetPosition();
3473 goodPos
.y
-= coord_adjust
;
3474 m_wndEditor
->Move( goodPos
);
3477 SetupChildEventHandling(primaryCtrl
);
3479 // Focus and select all (wxTextCtrl, wxComboBox etc)
3480 if ( flags
& wxPG_SEL_FOCUS
)
3482 primaryCtrl
->SetFocus();
3484 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3490 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3491 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3493 // Get proper id for wndSecondary
3494 m_wndSecId
= m_wndEditor2
->GetId();
3495 wxWindowList children
= m_wndEditor2
->GetChildren();
3496 wxWindowList::iterator node
= children
.begin();
3497 if ( node
!= children
.end() )
3498 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3500 m_wndEditor2
->SetSizeHints(3,3);
3502 #if wxPG_CREATE_CONTROLS_HIDDEN
3503 wxRect sec_rect
= m_wndEditor2
->GetRect();
3504 sec_rect
.y
-= coord_adjust
;
3506 // Fine tuning required to fix "oversized"
3507 // button disappearance bug.
3508 if ( sec_rect
.y
< 0 )
3510 sec_rect
.height
+= sec_rect
.y
;
3513 m_wndEditor2
->SetSize( sec_rect
);
3515 m_wndEditor2
->Show();
3517 SetupChildEventHandling(m_wndEditor2
);
3519 // If no primary editor, focus to button to allow
3520 // it to interprete ENTER etc.
3521 // NOTE: Due to problems focusing away from it, this
3522 // has been disabled.
3524 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3525 m_wndEditor2->SetFocus();
3529 if ( flags
& wxPG_SEL_FOCUS
)
3530 m_editorFocused
= 1;
3535 // Make sure focus is in grid canvas (important for wxGTK, at least)
3539 EditorsValueWasNotModified();
3541 // If it's inside collapsed section, expand parent, scroll, etc.
3542 // Also, if it was partially visible, scroll it into view.
3543 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3548 #if wxPG_CREATE_CONTROLS_HIDDEN
3549 m_wndEditor
->Thaw();
3551 m_wndEditor
->Show(true);
3558 // Make sure focus is in grid canvas
3562 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3568 // Show help text in status bar.
3569 // (if found and grid not embedded in manager with help box and
3570 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3573 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3575 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3576 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3578 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3580 statusbar
= frame
->GetStatusBar();
3585 const wxString
* pHelpString
= (const wxString
*) NULL
;
3589 pHelpString
= &p
->GetHelpString();
3590 if ( pHelpString
->length() )
3592 // Set help box text.
3593 statusbar
->SetStatusText( *pHelpString
);
3594 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3598 if ( (!pHelpString
|| !pHelpString
->length()) &&
3599 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3601 // Clear help box - but only if it was written
3602 // by us at previous time.
3603 statusbar
->SetStatusText( m_emptyString
);
3604 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3610 m_inDoSelectProperty
= 0;
3612 // call wx event handler (here so that it also occurs on deselection)
3613 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3618 // -----------------------------------------------------------------------
3620 bool wxPropertyGrid::UnfocusEditor()
3622 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3625 if ( !CommitChangesFromEditor(0) )
3629 DrawItem(m_selected
);
3634 // -----------------------------------------------------------------------
3636 void wxPropertyGrid::RefreshEditor()
3638 wxPGProperty
* p
= m_selected
;
3642 wxWindow
* wnd
= GetEditorControl();
3646 // Set editor font boldness - must do this before
3647 // calling UpdateControl().
3648 if ( HasFlag(wxPG_BOLD_MODIFIED
) )
3650 if ( p
->HasFlag(wxPG_PROP_MODIFIED
) )
3651 wnd
->SetFont(GetCaptionFont());
3653 wnd
->SetFont(GetFont());
3656 p
->GetEditorClass()->UpdateControl(p
, wnd
);
3659 // -----------------------------------------------------------------------
3661 // This method is not inline because it called dozens of times
3662 // (i.e. two-arg function calls create smaller code size).
3663 bool wxPropertyGrid::DoClearSelection()
3665 return DoSelectProperty((wxPGProperty
*)NULL
);
3668 // -----------------------------------------------------------------------
3669 // wxPropertyGrid expand/collapse state
3670 // -----------------------------------------------------------------------
3672 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3674 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3676 // If active editor was inside collapsed section, then disable it
3677 if ( m_selected
&& m_selected
->IsSomeParent(p
) )
3679 ClearSelection(false);
3682 // Store dont-center-splitter flag 'cause we need to temporarily set it
3683 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3684 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3686 bool res
= m_pState
->DoCollapse(pwc
);
3691 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3693 RecalculateVirtualSize();
3695 // Redraw etc. only if collapsed was visible.
3696 if (pwc
->IsVisible() &&
3698 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3700 // When item is collapsed so that scrollbar would move,
3701 // graphics mess is about (unless we redraw everything).
3706 // Clear dont-center-splitter flag if it wasn't set
3707 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3712 // -----------------------------------------------------------------------
3714 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3716 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3718 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3720 // Store dont-center-splitter flag 'cause we need to temporarily set it
3721 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3722 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3724 bool res
= m_pState
->DoExpand(pwc
);
3729 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3731 RecalculateVirtualSize();
3733 // Redraw etc. only if expanded was visible.
3734 if ( pwc
->IsVisible() && !m_frozen
&&
3735 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3739 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3742 DrawItems(pwc
, NULL
);
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::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3758 return m_pState
->DoHideProperty(p
, hide
, flags
);
3761 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3764 ClearSelection(false);
3767 m_pState
->DoHideProperty(p
, hide
, flags
);
3769 RecalculateVirtualSize();
3776 // -----------------------------------------------------------------------
3777 // wxPropertyGrid size related methods
3778 // -----------------------------------------------------------------------
3780 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3782 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3786 // If virtual height was changed, then recalculate editor control position(s)
3787 if ( m_pState
->m_vhCalcPending
)
3788 CorrectEditorWidgetPosY();
3790 m_pState
->EnsureVirtualHeight();
3793 int by1
= m_pState
->GetVirtualHeight();
3794 int by2
= m_pState
->GetActualVirtualHeight();
3797 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3798 wxFAIL_MSG(s
.c_str());
3803 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3805 int x
= m_pState
->m_width
;
3806 int y
= m_pState
->m_virtualHeight
;
3809 GetClientSize(&width
,&height
);
3811 // Now adjust virtual size.
3812 SetVirtualSize(x
, y
);
3818 // Adjust scrollbars
3819 if ( HasVirtualWidth() )
3821 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3822 xPos
= GetScrollPos( wxHORIZONTAL
);
3825 if ( forceXPos
!= -1 )
3828 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3831 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3832 int yPos
= GetScrollPos( wxVERTICAL
);
3834 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3835 xAmount
, yAmount
, xPos
, yPos
, true );
3837 // Must re-get size now
3838 GetClientSize(&width
,&height
);
3840 if ( !HasVirtualWidth() )
3842 m_pState
->SetVirtualWidth(width
);
3849 m_canvas
->SetSize( x
, y
);
3851 m_pState
->CheckColumnWidths();
3854 CorrectEditorWidgetSizeX();
3856 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3859 // -----------------------------------------------------------------------
3861 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3863 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3867 GetClientSize(&width
,&height
);
3872 #if wxPG_DOUBLE_BUFFER
3873 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3875 int dblh
= (m_lineHeight
*2);
3876 if ( !m_doubleBuffer
)
3878 // Create double buffer bitmap to draw on, if none
3879 int w
= (width
>250)?width
:250;
3880 int h
= height
+ dblh
;
3882 m_doubleBuffer
= new wxBitmap( w
, h
);
3886 int w
= m_doubleBuffer
->GetWidth();
3887 int h
= m_doubleBuffer
->GetHeight();
3889 // Double buffer must be large enough
3890 if ( w
< width
|| h
< (height
+dblh
) )
3892 if ( w
< width
) w
= width
;
3893 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3894 delete m_doubleBuffer
;
3895 m_doubleBuffer
= new wxBitmap( w
, h
);
3902 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3903 m_ncWidth
= event
.GetSize().x
;
3907 if ( m_pState
->m_itemsAdded
)
3908 PrepareAfterItemsAdded();
3910 // Without this, virtual size (atleast under wxGTK) will be skewed
3911 RecalculateVirtualSize();
3917 // -----------------------------------------------------------------------
3919 void wxPropertyGrid::SetVirtualWidth( int width
)
3923 // Disable virtual width
3924 width
= GetClientSize().x
;
3925 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3929 // Enable virtual width
3930 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3932 m_pState
->SetVirtualWidth( width
);
3935 void wxPropertyGrid::SetFocusOnCanvas()
3937 m_canvas
->SetFocusIgnoringChildren();
3938 m_editorFocused
= 0;
3941 // -----------------------------------------------------------------------
3942 // wxPropertyGrid mouse event handling
3943 // -----------------------------------------------------------------------
3945 // selFlags uses same values DoSelectProperty's flags
3946 // Returns true if event was vetoed.
3947 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3949 // Send property grid event of specific type and with specific property
3950 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3951 evt
.SetPropertyGrid(this);
3952 evt
.SetEventObject(m_eventObject
);
3956 evt
.SetCanVeto(true);
3957 evt
.SetupValidationInfo();
3958 m_validationInfo
.m_pValue
= pValue
;
3960 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3962 evtHandler
->ProcessEvent(evt
);
3964 return evt
.WasVetoed();
3967 // -----------------------------------------------------------------------
3969 // Return false if should be skipped
3970 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3974 // Need to set focus?
3975 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3980 wxPropertyGridPageState
* state
= m_pState
;
3982 int splitterHitOffset
;
3983 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3985 wxPGProperty
* p
= DoGetItemAtY(y
);
3989 int depth
= (int)p
->GetDepth() - 1;
3991 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3993 if ( x
>= marginEnds
)
3997 if ( p
->IsCategory() )
3999 // This is category.
4000 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
4002 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
4004 // Expand, collapse, activate etc. if click on text or left of splitter.
4007 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4012 if ( !DoSelectProperty( p
) )
4015 // On double-click, expand/collapse.
4016 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4018 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4019 else DoExpand( p
, true );
4023 else if ( splitterHit
== -1 )
4026 unsigned int selFlag
= 0;
4027 if ( columnHit
== 1 )
4029 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4030 selFlag
= wxPG_SEL_FOCUS
;
4032 if ( !DoSelectProperty( p
, selFlag
) )
4035 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4037 if ( p
->GetChildCount() && !p
->IsCategory() )
4038 // On double-click, expand/collapse.
4039 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4041 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4042 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4043 else DoExpand( p
, true );
4050 // click on splitter
4051 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4053 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4055 // Double-clicking the splitter causes auto-centering
4056 CenterSplitter( true );
4058 else if ( m_dragStatus
== 0 )
4061 // Begin draggin the splitter
4065 // Changes must be committed here or the
4066 // value won't be drawn correctly
4067 if ( !CommitChangesFromEditor() )
4070 m_wndEditor
->Show ( false );
4073 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4075 m_canvas
->CaptureMouse();
4076 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4080 m_draggedSplitter
= splitterHit
;
4081 m_dragOffset
= splitterHitOffset
;
4083 wxClientDC
dc(m_canvas
);
4085 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4086 // Fixes button disappearance bug
4088 m_wndEditor2
->Show ( false );
4091 m_startingSplitterX
= x
- splitterHitOffset
;
4099 if ( p
->GetChildCount() )
4101 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4103 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4105 int y2
= y
% m_lineHeight
;
4106 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4108 // On click on expander button, expand/collapse
4109 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4110 DoCollapse( p
, true );
4112 DoExpand( p
, true );
4121 // -----------------------------------------------------------------------
4123 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4124 wxMouseEvent
& WXUNUSED(event
) )
4128 // Select property here as well
4129 wxPGProperty
* p
= m_propHover
;
4130 if ( p
!= m_selected
)
4131 DoSelectProperty( p
);
4133 // Send right click event.
4134 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4141 // -----------------------------------------------------------------------
4143 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4144 wxMouseEvent
& WXUNUSED(event
) )
4148 // Select property here as well
4149 wxPGProperty
* p
= m_propHover
;
4151 if ( p
!= m_selected
)
4152 DoSelectProperty( p
);
4154 // Send double-click event.
4155 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4162 // -----------------------------------------------------------------------
4164 #if wxPG_SUPPORT_TOOLTIPS
4166 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4168 if ( tipString
.length() )
4170 m_canvas
->SetToolTip(tipString
);
4174 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4175 m_canvas
->SetToolTip( m_emptyString
);
4177 m_canvas
->SetToolTip( NULL
);
4182 #endif // #if wxPG_SUPPORT_TOOLTIPS
4184 // -----------------------------------------------------------------------
4186 // Return false if should be skipped
4187 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4189 // Safety check (needed because mouse capturing may
4190 // otherwise freeze the control)
4191 if ( m_dragStatus
> 0 && !event
.Dragging() )
4193 HandleMouseUp(x
,y
,event
);
4196 wxPropertyGridPageState
* state
= m_pState
;
4198 int splitterHitOffset
;
4199 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4200 int splitterX
= x
- splitterHitOffset
;
4202 if ( m_dragStatus
> 0 )
4204 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4205 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4208 int newSplitterX
= x
- m_dragOffset
;
4209 int splitterX
= x
- splitterHitOffset
;
4211 // Splitter redraw required?
4212 if ( newSplitterX
!= splitterX
)
4215 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4216 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4217 state
->m_fSplitterX
= (float) newSplitterX
;
4220 CorrectEditorWidgetSizeX();
4234 int ih
= m_lineHeight
;
4237 #if wxPG_SUPPORT_TOOLTIPS
4238 wxPGProperty
* prevHover
= m_propHover
;
4239 unsigned char prevSide
= m_mouseSide
;
4241 int curPropHoverY
= y
- (y
% ih
);
4243 // On which item it hovers
4246 ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) )
4249 // Mouse moves on another property
4251 m_propHover
= DoGetItemAtY(y
);
4252 m_propHoverY
= curPropHoverY
;
4255 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4258 #if wxPG_SUPPORT_TOOLTIPS
4259 // Store which side we are on
4261 if ( columnHit
== 1 )
4263 else if ( columnHit
== 0 )
4267 // If tooltips are enabled, show label or value as a tip
4268 // in case it doesn't otherwise show in full length.
4270 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4272 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4274 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4276 if ( m_propHover
&& !m_propHover
->IsCategory() )
4279 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4281 // Show help string as a tooltip
4282 wxString tipString
= m_propHover
->GetHelpString();
4284 SetToolTip(tipString
);
4288 // Show cropped value string as a tooltip
4292 if ( m_mouseSide
== 1 )
4294 tipString
= m_propHover
->m_label
;
4295 space
= splitterX
-m_marginWidth
-3;
4297 else if ( m_mouseSide
== 2 )
4299 tipString
= m_propHover
->GetDisplayedString();
4301 space
= m_width
- splitterX
;
4302 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4303 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4309 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4312 SetToolTip( tipString
);
4319 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4320 m_canvas
->SetToolTip( m_emptyString
);
4322 m_canvas
->SetToolTip( NULL
);
4333 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4334 m_canvas
->SetToolTip( m_emptyString
);
4336 m_canvas
->SetToolTip( NULL
);
4344 if ( splitterHit
== -1 ||
4346 HasFlag(wxPG_STATIC_SPLITTER
) )
4348 // hovering on something else
4349 if ( m_curcursor
!= wxCURSOR_ARROW
)
4350 CustomSetCursor( wxCURSOR_ARROW
);
4354 // Do not allow splitter cursor on caption items.
4355 // (also not if we were dragging and its started
4356 // outside the splitter region)
4358 if ( !m_propHover
->IsCategory() &&
4362 // hovering on splitter
4364 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4365 // reliably detected.
4366 //if ( m_curcursor != wxCURSOR_SIZEWE )
4367 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4373 // hovering on something else
4374 if ( m_curcursor
!= wxCURSOR_ARROW
)
4375 CustomSetCursor( wxCURSOR_ARROW
);
4382 // -----------------------------------------------------------------------
4384 // Also handles Leaving event
4385 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4386 wxMouseEvent
&WXUNUSED(event
) )
4388 wxPropertyGridPageState
* state
= m_pState
;
4392 int splitterHitOffset
;
4393 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4395 // No event type check - basicly calling this method should
4396 // just stop dragging.
4397 // Left up after dragged?
4398 if ( m_dragStatus
>= 1 )
4401 // End Splitter Dragging
4403 // DO NOT ENABLE FOLLOWING LINE!
4404 // (it is only here as a reminder to not to do it)
4407 // Disable splitter auto-centering
4408 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4410 // This is necessary to return cursor
4411 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4413 m_canvas
->ReleaseMouse();
4414 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4417 // Set back the default cursor, if necessary
4418 if ( splitterHit
== -1 ||
4421 CustomSetCursor( wxCURSOR_ARROW
);
4426 // Control background needs to be cleared
4427 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4428 DrawItem( m_selected
);
4432 m_wndEditor
->Show ( true );
4435 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4436 // Fixes button disappearance bug
4438 m_wndEditor2
->Show ( true );
4441 // This clears the focus.
4442 m_editorFocused
= 0;
4448 // -----------------------------------------------------------------------
4450 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4452 int splitterX
= GetSplitterPosition();
4455 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4459 wxWindow
* wnd
= GetEditorControl();
4461 // Hide popup on clicks
4462 if ( event
.GetEventType() != wxEVT_MOTION
)
4463 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4465 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4471 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4473 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4474 ux
>= (r
.x
+r
.width
) ||
4476 event
.m_y
>= (r
.y
+r
.height
)
4486 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4491 // -----------------------------------------------------------------------
4493 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4496 if ( OnMouseCommon( event
, &x
, &y
) )
4498 HandleMouseClick(x
,y
,event
);
4503 // -----------------------------------------------------------------------
4505 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4508 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4509 HandleMouseRightClick(x
,y
,event
);
4513 // -----------------------------------------------------------------------
4515 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4517 // Always run standard mouse-down handler as well
4518 OnMouseClick(event
);
4521 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4522 HandleMouseDoubleClick(x
,y
,event
);
4526 // -----------------------------------------------------------------------
4528 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4531 if ( OnMouseCommon( event
, &x
, &y
) )
4533 HandleMouseMove(x
,y
,event
);
4538 // -----------------------------------------------------------------------
4540 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4542 // Called when mouse moves in the empty space below the properties.
4543 CustomSetCursor( wxCURSOR_ARROW
);
4546 // -----------------------------------------------------------------------
4548 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4551 if ( OnMouseCommon( event
, &x
, &y
) )
4553 HandleMouseUp(x
,y
,event
);
4558 // -----------------------------------------------------------------------
4560 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4562 // This may get called from child control as well, so event's
4563 // mouse position cannot be relied on.
4565 if ( event
.Entering() )
4567 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4569 // TODO: Fix this (detect parent and only do
4570 // cursor trick if it is a manager).
4571 wxASSERT( GetParent() );
4572 GetParent()->SetCursor(wxNullCursor
);
4574 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4577 GetParent()->SetCursor(wxNullCursor
);
4579 else if ( event
.Leaving() )
4581 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4582 m_canvas
->SetCursor( wxNullCursor
);
4584 // Get real cursor position
4585 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4587 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4590 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4592 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4596 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4604 // -----------------------------------------------------------------------
4606 // Common code used by various OnMouseXXXChild methods.
4607 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4609 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4610 wxASSERT( topCtrlWnd
);
4612 event
.GetPosition(&x
,&y
);
4614 int splitterX
= GetSplitterPosition();
4616 wxRect r
= topCtrlWnd
->GetRect();
4617 if ( !m_dragStatus
&&
4618 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4619 y
>= 0 && y
< r
.height \
4622 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4627 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4634 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4637 if ( OnMouseChildCommon(event
,&x
,&y
) )
4639 bool res
= HandleMouseClick(x
,y
,event
);
4640 if ( !res
) event
.Skip();
4644 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4647 wxASSERT( m_wndEditor
);
4648 // These coords may not be exact (about +-2),
4649 // but that should not matter (right click is about item, not position).
4650 wxPoint pt
= m_wndEditor
->GetPosition();
4651 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4652 wxASSERT( m_selected
);
4653 m_propHover
= m_selected
;
4654 bool res
= HandleMouseRightClick(x
,y
,event
);
4655 if ( !res
) event
.Skip();
4658 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4661 if ( OnMouseChildCommon(event
,&x
,&y
) )
4663 bool res
= HandleMouseMove(x
,y
,event
);
4664 if ( !res
) event
.Skip();
4668 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4671 if ( OnMouseChildCommon(event
,&x
,&y
) )
4673 bool res
= HandleMouseUp(x
,y
,event
);
4674 if ( !res
) event
.Skip();
4678 // -----------------------------------------------------------------------
4679 // wxPropertyGrid keyboard event handling
4680 // -----------------------------------------------------------------------
4682 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4684 // Translates wxKeyEvent to wxPG_ACTION_XXX
4686 int keycode
= event
.GetKeyCode();
4687 int modifiers
= event
.GetModifiers();
4689 wxASSERT( !(modifiers
&~(0xFFFF)) );
4691 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4693 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4695 if ( it
== m_actionTriggers
.end() )
4700 int second
= (it
->second
>>16) & 0xFFFF;
4704 return (it
->second
& 0xFFFF);
4707 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4709 wxASSERT( !(modifiers
&~(0xFFFF)) );
4711 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4713 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4715 if ( it
!= m_actionTriggers
.end() )
4717 // This key combination is already used
4719 // Can add secondary?
4720 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4721 wxT("You can only add up to two separate actions per key combination.") );
4723 action
= it
->second
| (action
<<16);
4726 m_actionTriggers
[hashMapKey
] = action
;
4729 void wxPropertyGrid::ClearActionTriggers( int action
)
4731 wxPGHashMapI2I::iterator it
;
4733 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); ++it
)
4735 if ( it
->second
== action
)
4737 m_actionTriggers
.erase(it
);
4742 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4745 // Handles key event when editor control is not focused.
4748 wxCHECK2(!m_frozen
, return);
4750 // Travelsal between items, collapsing/expanding, etc.
4751 int keycode
= event
.GetKeyCode();
4752 bool editorFocused
= IsEditorFocused();
4754 if ( keycode
== WXK_TAB
)
4756 wxWindow
* mainControl
;
4758 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4759 mainControl
= GetParent();
4763 if ( !event
.ShiftDown() )
4765 if ( !editorFocused
&& m_wndEditor
)
4767 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4771 // Tab traversal workaround for platforms on which
4772 // wxWindow::Navigate() may navigate into first child
4773 // instead of next sibling. Does not work perfectly
4774 // in every scenario (for instance, when property grid
4775 // is either first or last control).
4776 #if defined(__WXGTK__)
4777 wxWindow
* sibling
= mainControl
->GetNextSibling();
4779 sibling
->SetFocusFromKbd();
4781 Navigate(wxNavigationKeyEvent::IsForward
);
4787 if ( editorFocused
)
4793 #if defined(__WXGTK__)
4794 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4796 sibling
->SetFocusFromKbd();
4798 Navigate(wxNavigationKeyEvent::IsBackward
);
4806 // Ignore Alt and Control when they are down alone
4807 if ( keycode
== WXK_ALT
||
4808 keycode
== WXK_CONTROL
)
4815 int action
= KeyEventToActions(event
, &secondAction
);
4817 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4820 // Esc cancels any changes
4821 if ( IsEditorsValueModified() )
4823 EditorsValueWasNotModified();
4825 // Update the control as well
4826 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4828 m_selected
->GetDisplayedString() );
4831 OnValidationFailureReset(m_selected
);
4837 // Except for TAB and ESC, handle child control events in child control
4844 bool wasHandled
= false;
4849 if ( ButtonTriggerKeyTest(action
, event
) )
4852 wxPGProperty
* p
= m_selected
;
4854 // Travel and expand/collapse
4857 if ( p
->GetChildCount() &&
4858 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4861 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4863 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4866 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4868 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4875 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4879 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4885 if ( selectDir
>= -1 )
4887 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4889 DoSelectProperty(p
);
4895 // If nothing was selected, select the first item now
4896 // (or navigate out of tab).
4897 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4899 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4900 if ( p
) DoSelectProperty(p
);
4909 // -----------------------------------------------------------------------
4911 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4913 HandleKeyEvent(event
, false);
4916 // -----------------------------------------------------------------------
4918 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4923 action
= KeyEventToActions(event
, &secondAction
);
4926 // Does the keycode trigger button?
4927 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4930 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4931 GetEventHandler()->AddPendingEvent(evt
);
4938 // -----------------------------------------------------------------------
4940 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4942 HandleKeyEvent(event
, true);
4945 // -----------------------------------------------------------------------
4946 // wxPropertyGrid miscellaneous event handling
4947 // -----------------------------------------------------------------------
4949 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4952 // Check if the focus is in this control or one of its children
4953 wxWindow
* newFocused
= wxWindow::FindFocus();
4955 if ( newFocused
!= m_curFocused
)
4956 HandleFocusChange( newFocused
);
4959 bool wxPropertyGrid::IsEditorFocused() const
4961 wxWindow
* focus
= wxWindow::FindFocus();
4963 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4964 focus
== GetEditorControl() )
4970 // Called by focus event handlers. newFocused is the window that becomes focused.
4971 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4973 unsigned int oldFlags
= m_iFlags
;
4975 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4977 wxWindow
* parent
= newFocused
;
4979 // This must be one of nextFocus' parents.
4982 // Use m_eventObject, which is either wxPropertyGrid or
4983 // wxPropertyGridManager, as appropriate.
4984 if ( parent
== m_eventObject
)
4986 m_iFlags
|= wxPG_FL_FOCUSED
;
4989 parent
= parent
->GetParent();
4992 m_curFocused
= newFocused
;
4994 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4995 (oldFlags
& wxPG_FL_FOCUSED
) )
4997 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4999 // Need to store changed value
5000 CommitChangesFromEditor();
5006 // Preliminary code for tab-order respecting
5007 // tab-traversal (but should be moved to
5010 wxWindow* prevFocus = event.GetWindow();
5011 wxWindow* useThis = this;
5012 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5013 useThis = GetParent();
5016 prevFocus->GetParent() == useThis->GetParent() )
5018 wxList& children = useThis->GetParent()->GetChildren();
5020 wxNode* node = children.Find(prevFocus);
5022 if ( node->GetNext() &&
5023 useThis == node->GetNext()->GetData() )
5024 DoSelectProperty(GetFirst());
5025 else if ( node->GetPrevious () &&
5026 useThis == node->GetPrevious()->GetData() )
5027 DoSelectProperty(GetLastProperty());
5034 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5035 DrawItem( m_selected
);
5039 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5041 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5042 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5043 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5044 //else if ( event.GetWindow() )
5046 HandleFocusChange(event
.GetWindow());
5051 // -----------------------------------------------------------------------
5053 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5055 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5058 // event.Skip() being commented out is aworkaround for bug reported
5059 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5063 // -----------------------------------------------------------------------
5065 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5067 m_iFlags
|= wxPG_FL_SCROLLED
;
5072 // -----------------------------------------------------------------------
5074 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5076 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5078 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5082 // -----------------------------------------------------------------------
5083 // Property editor related functions
5084 // -----------------------------------------------------------------------
5086 // noDefCheck = true prevents infinite recursion.
5087 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5090 wxASSERT( editorClass
);
5092 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5093 RegisterDefaultEditors();
5095 wxString name
= editorClass
->GetName();
5097 // Existing editor under this name?
5098 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5100 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5102 // If this name was already used, try class name.
5103 name
= editorClass
->GetClassInfo()->GetClassName();
5104 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5107 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5108 (wxPGEditor
*) vt_it
->second
,
5109 "Editor with given name was already registered" );
5111 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5116 // Use this in RegisterDefaultEditors.
5117 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5118 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5120 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5121 new wxPG##EDITOR##Editor, true ); \
5124 // Registers all default editor classes
5125 void wxPropertyGrid::RegisterDefaultEditors()
5127 wxPGRegisterDefaultEditorClass( TextCtrl
);
5128 wxPGRegisterDefaultEditorClass( Choice
);
5129 wxPGRegisterDefaultEditorClass( ComboBox
);
5130 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5131 #if wxPG_INCLUDE_CHECKBOX
5132 wxPGRegisterDefaultEditorClass( CheckBox
);
5134 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5136 // Register SpinCtrl etc. editors before use
5137 RegisterAdditionalEditors();
5140 // -----------------------------------------------------------------------
5141 // wxPGStringTokenizer
5142 // Needed to handle C-style string lists (e.g. "str1" "str2")
5143 // -----------------------------------------------------------------------
5145 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5146 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5150 wxPGStringTokenizer::~wxPGStringTokenizer()
5154 bool wxPGStringTokenizer::HasMoreTokens()
5156 const wxString
& str
= *m_str
;
5158 wxString::const_iterator i
= m_curPos
;
5160 wxUniChar delim
= m_delimeter
;
5162 wxUniChar prev_a
= wxT('\0');
5164 bool inToken
= false;
5166 while ( i
!= str
.end() )
5175 m_readyToken
.clear();
5180 if ( prev_a
!= wxT('\\') )
5184 if ( a
!= wxT('\\') )
5204 m_curPos
= str
.end();
5212 wxString
wxPGStringTokenizer::GetNextToken()
5214 return m_readyToken
;
5217 // -----------------------------------------------------------------------
5219 // -----------------------------------------------------------------------
5221 wxPGChoiceEntry::wxPGChoiceEntry()
5222 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5226 // -----------------------------------------------------------------------
5228 // -----------------------------------------------------------------------
5230 wxPGChoicesData::wxPGChoicesData()
5235 wxPGChoicesData::~wxPGChoicesData()
5240 void wxPGChoicesData::Clear()
5245 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5247 wxASSERT( m_items
.size() == 0 );
5249 m_items
= data
->m_items
;
5252 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5253 const wxPGChoiceEntry
& item
)
5255 wxVector
<wxPGChoiceEntry
>::iterator it
;
5259 index
= (int) m_items
.size();
5263 it
= m_items
.begin() + index
;
5266 m_items
.insert(it
, item
);
5268 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5270 // Need to fix value?
5271 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5272 ownEntry
.SetValue(index
);
5277 // -----------------------------------------------------------------------
5279 // -----------------------------------------------------------------------
5281 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5285 wxPGChoiceEntry
entry(label
, value
);
5286 return m_data
->Insert( -1, entry
);
5289 // -----------------------------------------------------------------------
5291 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5295 wxPGChoiceEntry
entry(label
, value
);
5296 entry
.SetBitmap(bitmap
);
5297 return m_data
->Insert( -1, entry
);
5300 // -----------------------------------------------------------------------
5302 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5305 return m_data
->Insert( index
, entry
);
5308 // -----------------------------------------------------------------------
5310 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5314 wxPGChoiceEntry
entry(label
, value
);
5315 return m_data
->Insert( index
, entry
);
5318 // -----------------------------------------------------------------------
5320 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5326 while ( index
< GetCount() )
5328 int cmpRes
= GetLabel(index
).Cmp(label
);
5334 wxPGChoiceEntry
entry(label
, value
);
5335 return m_data
->Insert( index
, entry
);
5338 // -----------------------------------------------------------------------
5340 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5344 unsigned int itemcount
= 0;
5345 const wxChar
** p
= &labels
[0];
5346 while ( *p
) { p
++; itemcount
++; }
5349 for ( i
= 0; i
< itemcount
; i
++ )
5354 wxPGChoiceEntry
entry(labels
[i
], value
);
5355 m_data
->Insert( i
, entry
);
5359 // -----------------------------------------------------------------------
5361 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5366 unsigned int itemcount
= arr
.size();
5368 for ( i
= 0; i
< itemcount
; i
++ )
5371 if ( &arrint
&& arrint
.size() )
5373 wxPGChoiceEntry
entry(arr
[i
], value
);
5374 m_data
->Insert( i
, entry
);
5378 // -----------------------------------------------------------------------
5380 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5382 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5383 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5384 m_data
->m_items
.begin()+nIndex
+count
);
5387 // -----------------------------------------------------------------------
5389 int wxPGChoices::Index( const wxString
& str
) const
5394 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5396 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5397 if ( entry
.HasText() && entry
.GetText() == str
)
5404 // -----------------------------------------------------------------------
5406 int wxPGChoices::Index( int val
) const
5411 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5413 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5414 if ( entry
.GetValue() == val
)
5421 // -----------------------------------------------------------------------
5423 wxArrayString
wxPGChoices::GetLabels() const
5428 if ( this && IsOk() )
5429 for ( i
=0; i
<GetCount(); i
++ )
5430 arr
.push_back(GetLabel(i
));
5435 // -----------------------------------------------------------------------
5437 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5444 for ( i
=0; i
< strings
.size(); i
++ )
5446 int index
= Index(strings
[i
]);
5448 arr
.Add(GetValue(index
));
5450 arr
.Add(wxPG_INVALID_VALUE
);
5457 // -----------------------------------------------------------------------
5459 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5460 wxArrayString
* unmatched
) const
5467 for ( i
=0; i
< strings
.size(); i
++ )
5469 const wxString
& str
= strings
[i
];
5470 int index
= Index(str
);
5473 else if ( unmatched
)
5474 unmatched
->Add(str
);
5481 // -----------------------------------------------------------------------
5483 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5487 if ( data
!= wxPGChoicesEmptyData
)
5494 // -----------------------------------------------------------------------
5496 void wxPGChoices::Init()
5498 m_data
= wxPGChoicesEmptyData
;
5501 // -----------------------------------------------------------------------
5503 void wxPGChoices::Free()
5505 if ( m_data
!= wxPGChoicesEmptyData
)
5508 m_data
= wxPGChoicesEmptyData
;
5512 // -----------------------------------------------------------------------
5513 // wxPropertyGridEvent
5514 // -----------------------------------------------------------------------
5516 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5519 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5520 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5521 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5522 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5523 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5524 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5525 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5526 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5527 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5530 // -----------------------------------------------------------------------
5532 void wxPropertyGridEvent::Init()
5534 m_validationInfo
= NULL
;
5536 m_wasVetoed
= false;
5539 // -----------------------------------------------------------------------
5541 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5542 : wxCommandEvent(commandType
,id
)
5548 // -----------------------------------------------------------------------
5550 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5551 : wxCommandEvent(event
)
5553 m_eventType
= event
.GetEventType();
5554 m_eventObject
= event
.m_eventObject
;
5556 m_property
= event
.m_property
;
5557 m_validationInfo
= event
.m_validationInfo
;
5558 m_canVeto
= event
.m_canVeto
;
5559 m_wasVetoed
= event
.m_wasVetoed
;
5562 // -----------------------------------------------------------------------
5564 wxPropertyGridEvent::~wxPropertyGridEvent()
5568 // -----------------------------------------------------------------------
5570 wxEvent
* wxPropertyGridEvent::Clone() const
5572 return new wxPropertyGridEvent( *this );
5575 // -----------------------------------------------------------------------
5576 // wxPropertyGridPopulator
5577 // -----------------------------------------------------------------------
5579 wxPropertyGridPopulator::wxPropertyGridPopulator()
5583 wxPGGlobalVars
->m_offline
++;
5586 // -----------------------------------------------------------------------
5588 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5591 m_propHierarchy
.clear();
5594 // -----------------------------------------------------------------------
5596 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5602 // -----------------------------------------------------------------------
5604 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5607 // Free unused sets of choices
5608 wxPGHashMapS2P::iterator it
;
5610 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5612 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5619 m_pg
->GetPanel()->Refresh();
5621 wxPGGlobalVars
->m_offline
--;
5624 // -----------------------------------------------------------------------
5626 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5627 const wxString
& propLabel
,
5628 const wxString
& propName
,
5629 const wxString
* propValue
,
5630 wxPGChoices
* pChoices
)
5632 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5633 wxPGProperty
* parent
= GetCurParent();
5635 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5637 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5641 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5643 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5647 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5649 property
->SetLabel(propLabel
);
5650 property
->DoSetName(propName
);
5652 if ( pChoices
&& pChoices
->IsOk() )
5653 property
->SetChoices(*pChoices
);
5655 m_state
->DoInsert(parent
, -1, property
);
5658 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5659 wxPG_PROGRAMMATIC_VALUE
);
5664 // -----------------------------------------------------------------------
5666 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5668 m_propHierarchy
.push_back(property
);
5669 DoScanForChildren();
5670 m_propHierarchy
.pop_back();
5673 // -----------------------------------------------------------------------
5675 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5676 const wxString
& idString
)
5678 wxPGChoices choices
;
5681 if ( choicesString
[0] == wxT('@') )
5683 wxString ids
= choicesString
.substr(1);
5684 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5685 if ( it
== m_dictIdChoices
.end() )
5686 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5688 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5693 if ( idString
.length() )
5695 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5696 if ( it
!= m_dictIdChoices
.end() )
5698 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5705 // Parse choices string
5706 wxString::const_iterator it
= choicesString
.begin();
5710 bool labelValid
= false;
5712 for ( ; it
!= choicesString
.end(); ++it
)
5718 if ( c
== wxT('"') )
5723 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5724 choices
.Add(label
, l
);
5727 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5732 else if ( c
== wxT('=') )
5739 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5746 if ( c
== wxT('"') )
5759 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5760 choices
.Add(label
, l
);
5763 if ( !choices
.IsOk() )
5765 choices
.EnsureData();
5769 if ( idString
.length() )
5770 m_dictIdChoices
[idString
] = choices
.GetData();
5777 // -----------------------------------------------------------------------
5779 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5781 if ( s
.Last() == wxT('%') )
5783 wxString s2
= s
.substr(0,s
.length()-1);
5785 if ( s2
.ToLong(&val
, 10) )
5787 *pval
= (val
*max
)/100;
5793 return s
.ToLong(pval
, 10);
5796 // -----------------------------------------------------------------------
5798 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5799 const wxString
& type
,
5800 const wxString
& value
)
5802 int l
= m_propHierarchy
.size();
5806 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5807 wxString valuel
= value
.Lower();
5810 if ( type
.length() == 0 )
5815 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5817 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5819 else if ( value
.ToLong(&v
, 0) )
5826 if ( type
== wxT("string") )
5830 else if ( type
== wxT("int") )
5833 value
.ToLong(&v
, 0);
5836 else if ( type
== wxT("bool") )
5838 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5845 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5850 p
->SetAttribute( name
, variant
);
5855 // -----------------------------------------------------------------------
5857 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5859 wxLogError(_("Error in resource: %s"),msg
.c_str());
5862 // -----------------------------------------------------------------------
5864 #endif // wxUSE_PROPGRID