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 wxColour def_bgcol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
964 if ( !(m_coloursCustomized
& 0x0002) )
966 wxColour col
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
968 // Make sure colour is dark enough
970 int colDec
= wxPGGetColAvg(col
) - 230;
972 int colDec
= wxPGGetColAvg(col
) - 200;
975 m_colCapBack
= wxPGAdjustColour(col
,-colDec
);
978 m_categoryDefaultCell
.GetData()->SetBgCol(m_colCapBack
);
981 if ( !(m_coloursCustomized
& 0x0001) )
982 m_colMargin
= m_colCapBack
;
984 if ( !(m_coloursCustomized
& 0x0004) )
991 wxColour capForeCol
= wxPGAdjustColour(m_colCapBack
,colDec
,5000,5000,true);
992 m_colCapFore
= capForeCol
;
993 m_categoryDefaultCell
.GetData()->SetFgCol(capForeCol
);
996 if ( !(m_coloursCustomized
& 0x0008) )
998 wxColour bgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
999 m_colPropBack
= bgCol
;
1000 m_propertyDefaultCell
.GetData()->SetBgCol(bgCol
);
1003 if ( !(m_coloursCustomized
& 0x0010) )
1005 wxColour fgCol
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1006 m_colPropFore
= fgCol
;
1007 m_propertyDefaultCell
.GetData()->SetFgCol(fgCol
);
1010 if ( !(m_coloursCustomized
& 0x0020) )
1011 m_colSelBack
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
);
1013 if ( !(m_coloursCustomized
& 0x0040) )
1014 m_colSelFore
= wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1016 if ( !(m_coloursCustomized
& 0x0080) )
1017 m_colLine
= m_colCapBack
;
1019 if ( !(m_coloursCustomized
& 0x0100) )
1020 m_colDisPropFore
= m_colCapFore
;
1022 m_colEmptySpace
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1025 // -----------------------------------------------------------------------
1027 void wxPropertyGrid::ResetColours()
1029 m_coloursCustomized
= 0;
1036 // -----------------------------------------------------------------------
1038 bool wxPropertyGrid::SetFont( const wxFont
& font
)
1040 // Must disable active editor.
1043 bool selRes
= ClearSelection();
1044 wxPG_CHECK_MSG_DBG( selRes
,
1046 wxT("failed to deselect a property (editor probably had invalid value)") );
1049 // TODO: Following code is disabled with wxMac because
1050 // it is reported to fail. I (JMS) cannot debug it
1051 // personally right now.
1052 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1053 #if 1 // !defined(__WXMAC__)
1054 bool res
= wxScrolledWindow::SetFont( font
);
1057 CalculateFontAndBitmapStuff( m_vspacing
);
1060 m_pState
->CalculateFontAndBitmapStuff(m_vspacing
);
1068 // TODO: Remove after SetFont crash fixed.
1069 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1071 wxLogDebug(wxT("WARNING: propGrid.cpp: wxPropertyGrid::SetFont has been disabled on wxMac since there has been crash reported in it. If you are willing to debug the cause, replace line '#if !defined(__WXMAC__)' with line '#if 1' in wxPropertyGrid::SetFont."));
1077 // -----------------------------------------------------------------------
1079 void wxPropertyGrid::SetLineColour( const wxColour
& col
)
1082 m_coloursCustomized
|= 0x80;
1086 // -----------------------------------------------------------------------
1088 void wxPropertyGrid::SetMarginColour( const wxColour
& col
)
1091 m_coloursCustomized
|= 0x01;
1095 // -----------------------------------------------------------------------
1097 void wxPropertyGrid::SetCellBackgroundColour( const wxColour
& col
)
1099 m_colPropBack
= col
;
1100 m_coloursCustomized
|= 0x08;
1102 m_propertyDefaultCell
.GetData()->SetBgCol(col
);
1107 // -----------------------------------------------------------------------
1109 void wxPropertyGrid::SetCellTextColour( const wxColour
& col
)
1111 m_colPropFore
= col
;
1112 m_coloursCustomized
|= 0x10;
1114 m_propertyDefaultCell
.GetData()->SetFgCol(col
);
1119 // -----------------------------------------------------------------------
1121 void wxPropertyGrid::SetEmptySpaceColour( const wxColour
& col
)
1123 m_colEmptySpace
= col
;
1128 // -----------------------------------------------------------------------
1130 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour
& col
)
1132 m_colDisPropFore
= col
;
1133 m_coloursCustomized
|= 0x100;
1137 // -----------------------------------------------------------------------
1139 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour
& col
)
1142 m_coloursCustomized
|= 0x20;
1146 // -----------------------------------------------------------------------
1148 void wxPropertyGrid::SetSelectionTextColour( const wxColour
& col
)
1151 m_coloursCustomized
|= 0x40;
1155 // -----------------------------------------------------------------------
1157 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour
& col
)
1160 m_coloursCustomized
|= 0x02;
1162 m_categoryDefaultCell
.GetData()->SetBgCol(col
);
1167 // -----------------------------------------------------------------------
1169 void wxPropertyGrid::SetCaptionTextColour( const wxColour
& col
)
1172 m_coloursCustomized
|= 0x04;
1174 m_categoryDefaultCell
.GetData()->SetFgCol(col
);
1179 // -----------------------------------------------------------------------
1180 // wxPropertyGrid property adding and removal
1181 // -----------------------------------------------------------------------
1183 void wxPropertyGrid::PrepareAfterItemsAdded()
1185 if ( !m_pState
|| !m_pState
->m_itemsAdded
) return;
1187 m_pState
->m_itemsAdded
= 0;
1189 if ( m_windowStyle
& wxPG_AUTO_SORT
)
1192 RecalculateVirtualSize();
1195 // -----------------------------------------------------------------------
1196 // wxPropertyGrid property value setting and getting
1197 // -----------------------------------------------------------------------
1199 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty
* p
)
1201 m_pState
->DoSetPropertyValueUnspecified(p
);
1202 DrawItemAndChildren(p
);
1204 wxPGProperty
* parent
= p
->GetParent();
1206 (parent
->GetFlags() & wxPG_PROP_PARENTAL_FLAGS
) == wxPG_PROP_MISC_PARENT
)
1209 parent
= parent
->GetParent();
1213 // -----------------------------------------------------------------------
1214 // wxPropertyGrid property operations
1215 // -----------------------------------------------------------------------
1217 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id
)
1219 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1223 bool changed
= false;
1225 // Is it inside collapsed section?
1226 if ( !p
->IsVisible() )
1229 wxPGProperty
* parent
= p
->GetParent();
1230 wxPGProperty
* grandparent
= parent
->GetParent();
1232 if ( grandparent
&& grandparent
!= m_pState
->m_properties
)
1233 Expand( grandparent
);
1241 GetViewStart(&vx
,&vy
);
1242 vy
*=wxPG_PIXELS_PER_UNIT
;
1248 Scroll(vx
, y
/wxPG_PIXELS_PER_UNIT
);
1249 m_iFlags
|= wxPG_FL_SCROLLED
;
1252 else if ( (y
+m_lineHeight
) > (vy
+m_height
) )
1254 Scroll(vx
, (y
-m_height
+(m_lineHeight
*2))/wxPG_PIXELS_PER_UNIT
);
1255 m_iFlags
|= wxPG_FL_SCROLLED
;
1265 // -----------------------------------------------------------------------
1266 // wxPropertyGrid helper methods called by properties
1267 // -----------------------------------------------------------------------
1269 // Control font changer helper.
1270 void wxPropertyGrid::SetCurControlBoldFont()
1272 wxASSERT( m_wndEditor
);
1273 m_wndEditor
->SetFont( m_captionFont
);
1276 // -----------------------------------------------------------------------
1278 wxPoint
wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty
* p
,
1281 #if wxPG_SMALL_SCREEN
1282 // On small-screen devices, always show dialogs with default position and size.
1283 return wxDefaultPosition
;
1285 int splitterX
= GetSplitterPosition();
1289 wxCHECK_MSG( y
>= 0, wxPoint(-1,-1), wxT("invalid y?") );
1291 ImprovedClientToScreen( &x
, &y
);
1293 int sw
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X
);
1294 int sh
= wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y
);
1301 new_x
= x
+ (m_width
-splitterX
) - sz
.x
;
1311 new_y
= y
+ m_lineHeight
;
1313 return wxPoint(new_x
,new_y
);
1317 // -----------------------------------------------------------------------
1319 wxString
& wxPropertyGrid::ExpandEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1321 if ( src_str
.length() == 0 )
1327 bool prev_is_slash
= false;
1329 wxString::const_iterator i
= src_str
.begin();
1333 for ( ; i
!= src_str
.end(); i
++ )
1337 if ( a
!= wxS('\\') )
1339 if ( !prev_is_slash
)
1345 if ( a
== wxS('n') )
1348 dst_str
<< wxS('\n');
1350 dst_str
<< wxS('\n');
1353 else if ( a
== wxS('t') )
1354 dst_str
<< wxS('\t');
1358 prev_is_slash
= false;
1362 if ( prev_is_slash
)
1364 dst_str
<< wxS('\\');
1365 prev_is_slash
= false;
1369 prev_is_slash
= true;
1376 // -----------------------------------------------------------------------
1378 wxString
& wxPropertyGrid::CreateEscapeSequences( wxString
& dst_str
, wxString
& src_str
)
1380 if ( src_str
.length() == 0 )
1386 wxString::const_iterator i
= src_str
.begin();
1387 wxUniChar prev_a
= wxS('\0');
1391 for ( ; i
!= src_str
.end(); i
++ )
1395 if ( a
>= wxS(' ') )
1397 // This surely is not something that requires an escape sequence.
1402 // This might need...
1403 if ( a
== wxS('\r') )
1405 // DOS style line end.
1406 // Already taken care below
1408 else if ( a
== wxS('\n') )
1409 // UNIX style line end.
1410 dst_str
<< wxS("\\n");
1411 else if ( a
== wxS('\t') )
1413 dst_str
<< wxS('\t');
1416 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1426 // -----------------------------------------------------------------------
1428 wxPGProperty
* wxPropertyGrid::DoGetItemAtY( int y
) const
1432 return (wxPGProperty
*) NULL
;
1435 return m_pState
->m_properties
->GetItemAtY(y
, m_lineHeight
, &a
);
1438 // -----------------------------------------------------------------------
1439 // wxPropertyGrid graphics related methods
1440 // -----------------------------------------------------------------------
1442 void wxPropertyGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1446 // Update everything inside the box
1447 wxRect r
= GetUpdateRegion().GetBox();
1449 dc
.SetPen(m_colEmptySpace
);
1450 dc
.SetBrush(m_colEmptySpace
);
1451 dc
.DrawRectangle(r
);
1454 // -----------------------------------------------------------------------
1456 void wxPropertyGrid::DrawExpanderButton( wxDC
& dc
, const wxRect
& rect
,
1457 wxPGProperty
* property
) const
1459 // Prepare rectangle to be used
1461 r
.x
+= m_gutterWidth
; r
.y
+= m_buttonSpacingY
;
1462 r
.width
= m_iconWidth
; r
.height
= m_iconHeight
;
1464 #if (wxPG_USE_RENDERER_NATIVE)
1466 #elif wxPG_ICON_WIDTH
1467 // Drawing expand/collapse button manually
1468 dc
.SetPen(m_colPropFore
);
1469 if ( property
->IsCategory() )
1470 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1472 dc
.SetBrush(m_colPropBack
);
1474 dc
.DrawRectangle( r
);
1475 int _y
= r
.y
+(m_iconWidth
/2);
1476 dc
.DrawLine(r
.x
+2,_y
,r
.x
+m_iconWidth
-2,_y
);
1481 if ( property
->IsExpanded() )
1483 // wxRenderer functions are non-mutating in nature, so it
1484 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1485 // Hopefully this does not cause problems.
1486 #if (wxPG_USE_RENDERER_NATIVE)
1487 wxRendererNative::Get().DrawTreeItemButton(
1493 #elif wxPG_ICON_WIDTH
1502 #if (wxPG_USE_RENDERER_NATIVE)
1503 wxRendererNative::Get().DrawTreeItemButton(
1509 #elif wxPG_ICON_WIDTH
1510 int _x
= r
.x
+(m_iconWidth
/2);
1511 dc
.DrawLine(_x
,r
.y
+2,_x
,r
.y
+m_iconWidth
-2);
1517 #if (wxPG_USE_RENDERER_NATIVE)
1519 #elif wxPG_ICON_WIDTH
1522 dc
.DrawBitmap( *bmp
, r
.x
, r
.y
, true );
1526 // -----------------------------------------------------------------------
1529 // This is the one called by OnPaint event handler and others.
1530 // topy and bottomy are already unscrolled (ie. physical)
1532 void wxPropertyGrid::DrawItems( wxDC
& dc
,
1534 unsigned int bottomy
,
1535 const wxRect
* clipRect
)
1537 if ( m_frozen
|| m_height
< 1 || bottomy
< topy
|| !m_pState
) return;
1539 m_pState
->EnsureVirtualHeight();
1541 wxRect tempClipRect
;
1544 tempClipRect
= wxRect(0,topy
,m_pState
->m_width
,bottomy
);
1545 clipRect
= &tempClipRect
;
1548 // items added check
1549 if ( m_pState
->m_itemsAdded
) PrepareAfterItemsAdded();
1551 int paintFinishY
= 0;
1553 if ( m_pState
->m_properties
->GetChildCount() > 0 )
1556 bool isBuffered
= false;
1558 #if wxPG_DOUBLE_BUFFER
1559 wxMemoryDC
* bufferDC
= NULL
;
1561 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
1563 if ( !m_doubleBuffer
)
1565 paintFinishY
= clipRect
->y
;
1570 bufferDC
= new wxMemoryDC();
1572 // If nothing was changed, then just copy from double-buffer
1573 bufferDC
->SelectObject( *m_doubleBuffer
);
1583 dc
.SetClippingRegion( *clipRect
);
1584 paintFinishY
= DoDrawItems( *dcPtr
, NULL
, NULL
, clipRect
, isBuffered
);
1587 #if wxPG_DOUBLE_BUFFER
1590 dc
.Blit( clipRect
->x
, clipRect
->y
, clipRect
->width
, clipRect
->height
,
1591 bufferDC
, 0, 0, wxCOPY
);
1592 dc
.DestroyClippingRegion(); // Is this really necessary?
1598 // Clear area beyond bottomY?
1599 if ( paintFinishY
< (clipRect
->y
+clipRect
->height
) )
1601 dc
.SetPen(m_colEmptySpace
);
1602 dc
.SetBrush(m_colEmptySpace
);
1603 dc
.DrawRectangle( 0, paintFinishY
, m_width
, (clipRect
->y
+clipRect
->height
) );
1607 // -----------------------------------------------------------------------
1609 int wxPropertyGrid::DoDrawItems( wxDC
& dc
,
1610 const wxPGProperty
* firstItem
,
1611 const wxPGProperty
* lastItem
,
1612 const wxRect
* clipRect
,
1613 bool isBuffered
) const
1615 // TODO: This should somehow be eliminated.
1616 wxRect tempClipRect
;
1619 wxASSERT(firstItem
);
1621 tempClipRect
= GetPropertyRect(firstItem
, lastItem
);
1622 clipRect
= &tempClipRect
;
1626 firstItem
= DoGetItemAtY(clipRect
->y
);
1630 lastItem
= DoGetItemAtY(clipRect
->y
+clipRect
->height
-1);
1632 lastItem
= GetLastItem( wxPG_ITERATE_VISIBLE
);
1635 if ( m_frozen
|| m_height
< 1 || firstItem
== NULL
)
1638 wxCHECK_MSG( !m_pState
->m_itemsAdded
, clipRect
->y
, wxT("no items added") );
1639 wxASSERT( m_pState
->m_properties
->GetChildCount() );
1641 int lh
= m_lineHeight
;
1644 int lastItemBottomY
;
1646 firstItemTopY
= clipRect
->y
;
1647 lastItemBottomY
= clipRect
->y
+ clipRect
->height
;
1649 // Align y coordinates to item boundaries
1650 firstItemTopY
-= firstItemTopY
% lh
;
1651 lastItemBottomY
+= lh
- (lastItemBottomY
% lh
);
1652 lastItemBottomY
-= 1;
1654 // Entire range outside scrolled, visible area?
1655 if ( firstItemTopY
>= (int)m_pState
->GetVirtualHeight() || lastItemBottomY
<= 0 )
1658 wxCHECK_MSG( firstItemTopY
< lastItemBottomY
, clipRect
->y
, wxT("invalid y values") );
1662 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1663 firstItem->GetLabel().c_str(),
1664 lastItem->GetLabel().c_str(),
1665 (int)(lastItemBottomY - firstItemTopY),
1667 (unsigned long)clipRect );
1672 long windowStyle
= m_windowStyle
;
1678 // With wxPG_DOUBLE_BUFFER, do double buffering
1679 // - buffer's y = 0, so align cliprect and coordinates to that
1681 #if wxPG_DOUBLE_BUFFER
1687 xRelMod
= clipRect
->x
;
1688 yRelMod
= clipRect
->y
;
1691 // clipRect conversion
1699 firstItemTopY
-= yRelMod
;
1700 lastItemBottomY
-= yRelMod
;
1703 wxUnusedVar(isBuffered
);
1706 int x
= m_marginWidth
- xRelMod
;
1708 const wxFont
& normalfont
= m_font
;
1710 bool reallyFocused
= (m_iFlags
& wxPG_FL_FOCUSED
) ? true : false;
1712 bool isEnabled
= IsEnabled();
1715 // Prepare some pens and brushes that are often changed to.
1718 wxBrush
marginBrush(m_colMargin
);
1719 wxPen
marginPen(m_colMargin
);
1720 wxBrush
capbgbrush(m_colCapBack
,wxSOLID
);
1721 wxPen
linepen(m_colLine
,1,wxSOLID
);
1723 // pen that has same colour as text
1724 wxPen
outlinepen(m_colPropFore
,1,wxSOLID
);
1727 // Clear margin with background colour
1729 dc
.SetBrush( marginBrush
);
1730 if ( !(windowStyle
& wxPG_HIDE_MARGIN
) )
1732 dc
.SetPen( *wxTRANSPARENT_PEN
);
1733 dc
.DrawRectangle(-1-xRelMod
,firstItemTopY
-1,x
+2,lastItemBottomY
-firstItemTopY
+2);
1736 const wxPGProperty
* selected
= m_selected
;
1737 const wxPropertyGridPageState
* state
= m_pState
;
1739 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1740 bool wasSelectedPainted
= false;
1743 // TODO: Only render columns that are within clipping region.
1745 dc
.SetFont(normalfont
);
1747 wxPropertyGridConstIterator
it( state
, wxPG_ITERATE_VISIBLE
, firstItem
);
1748 int endScanBottomY
= lastItemBottomY
+ lh
;
1749 int y
= firstItemTopY
;
1752 // Pregenerate list of visible properties.
1753 wxArrayPGProperty visPropArray
;
1754 visPropArray
.reserve((m_height
/m_lineHeight
)+6);
1756 for ( ; !it
.AtEnd(); it
.Next() )
1758 const wxPGProperty
* p
= *it
;
1760 if ( !p
->HasFlag(wxPG_PROP_HIDDEN
) )
1762 visPropArray
.push_back((wxPGProperty
*)p
);
1764 if ( y
> endScanBottomY
)
1771 visPropArray
.push_back(NULL
);
1773 wxPGProperty
* nextP
= visPropArray
[0];
1775 int gridWidth
= state
->m_width
;
1778 for ( unsigned int arrInd
=1;
1779 nextP
&& y
<= lastItemBottomY
;
1782 wxPGProperty
* p
= nextP
;
1783 nextP
= visPropArray
[arrInd
];
1785 int rowHeight
= m_fontHeight
+(m_spacingy
*2)+1;
1786 int textMarginHere
= x
;
1787 int renderFlags
= 0;
1789 int greyDepth
= m_marginWidth
;
1790 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) )
1791 greyDepth
= (((int)p
->m_depthBgCol
)-1) * m_subgroup_extramargin
+ m_marginWidth
;
1793 int greyDepthX
= greyDepth
- xRelMod
;
1795 // Use basic depth if in non-categoric mode and parent is base array.
1796 if ( !(windowStyle
& wxPG_HIDE_CATEGORIES
) || p
->GetParent() != m_pState
->m_properties
)
1798 textMarginHere
+= ((unsigned int)((p
->m_depth
-1)*m_subgroup_extramargin
));
1801 // Paint margin area
1802 dc
.SetBrush(marginBrush
);
1803 dc
.SetPen(marginPen
);
1804 dc
.DrawRectangle( -xRelMod
, y
, greyDepth
, lh
);
1806 dc
.SetPen( linepen
);
1811 dc
.DrawLine( greyDepthX
, y
, greyDepthX
, y2
);
1817 for ( si
=0; si
<state
->m_colWidths
.size(); si
++ )
1819 sx
+= state
->m_colWidths
[si
];
1820 dc
.DrawLine( sx
, y
, sx
, y2
);
1823 // Horizontal Line, below
1824 // (not if both this and next is category caption)
1825 if ( p
->IsCategory() &&
1826 nextP
&& nextP
->IsCategory() )
1827 dc
.SetPen(m_colCapBack
);
1829 dc
.DrawLine( greyDepthX
, y2
-1, gridWidth
-xRelMod
, y2
-1 );
1832 // Need to override row colours?
1836 if ( p
!= selected
)
1838 // Disabled may get different colour.
1839 if ( !p
->IsEnabled() )
1841 renderFlags
|= wxPGCellRenderer::Disabled
|
1842 wxPGCellRenderer::DontUseCellFgCol
;
1843 rowFgCol
= m_colDisPropFore
;
1848 renderFlags
|= wxPGCellRenderer::Selected
;
1850 if ( !p
->IsCategory() )
1852 renderFlags
|= wxPGCellRenderer::DontUseCellFgCol
|
1853 wxPGCellRenderer::DontUseCellBgCol
;
1855 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1856 wasSelectedPainted
= true;
1859 // Selected gets different colour.
1860 if ( reallyFocused
)
1862 rowFgCol
= m_colSelFore
;
1863 rowBgCol
= m_colSelBack
;
1865 else if ( isEnabled
)
1867 rowFgCol
= m_colPropFore
;
1868 rowBgCol
= m_colMargin
;
1872 rowFgCol
= m_colDisPropFore
;
1873 rowBgCol
= m_colSelBack
;
1880 if ( rowBgCol
.IsOk() )
1881 rowBgBrush
= wxBrush(rowBgCol
);
1883 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
) )
1884 renderFlags
= renderFlags
& ~wxPGCellRenderer::DontUseCellColours
;
1887 // Fill additional margin area with background colour of first cell
1888 if ( greyDepthX
< textMarginHere
)
1890 if ( !(renderFlags
& wxPGCellRenderer::DontUseCellBgCol
) )
1892 wxPGCell
& cell
= p
->GetCell(0);
1893 rowBgCol
= cell
.GetBgCol();
1894 rowBgBrush
= wxBrush(rowBgCol
);
1896 dc
.SetBrush(rowBgBrush
);
1897 dc
.SetPen(rowBgCol
);
1898 dc
.DrawRectangle(greyDepthX
+1, y
,
1899 textMarginHere
-greyDepthX
, lh
-1);
1902 bool fontChanged
= false;
1904 // Expander button rectangle
1905 wxRect
butRect( ((p
->m_depth
- 1) * m_subgroup_extramargin
) - xRelMod
,
1910 if ( p
->IsCategory() )
1912 // Captions have their cell areas merged as one
1913 dc
.SetFont(m_captionFont
);
1915 wxRect
cellRect(greyDepthX
, y
, gridWidth
- greyDepth
+ 2, rowHeight
-1 );
1917 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1919 dc
.SetBrush(rowBgBrush
);
1920 dc
.SetPen(rowBgCol
);
1923 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1925 dc
.SetTextForeground(rowFgCol
);
1928 wxPGCellRenderer
* renderer
= p
->GetCellRenderer(0);
1929 renderer
->Render( dc
, cellRect
, this, p
, 0, -1, renderFlags
);
1932 if ( !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1933 DrawExpanderButton( dc
, butRect
, p
);
1937 if ( p
->m_flags
& wxPG_PROP_MODIFIED
&& (windowStyle
& wxPG_BOLD_MODIFIED
) )
1939 dc
.SetFont(m_captionFont
);
1945 int nextCellWidth
= state
->m_colWidths
[0];
1946 wxRect
cellRect(greyDepthX
+1, y
, 0, rowHeight
-1);
1947 int textXAdd
= textMarginHere
- greyDepthX
;
1949 for ( ci
=0; ci
<state
->m_colWidths
.size(); ci
++ )
1951 cellRect
.width
= nextCellWidth
- 1;
1953 bool ctrlCell
= false;
1954 int cellRenderFlags
= renderFlags
;
1957 if ( ci
== 0 && !HasFlag(wxPG_HIDE_MARGIN
) && p
->HasVisibleChildren() )
1958 DrawExpanderButton( dc
, butRect
, p
);
1961 if ( p
== selected
&& m_wndEditor
&& ci
== 1 )
1963 wxColour editorBgCol
= GetEditorControl()->GetBackgroundColour();
1964 dc
.SetBrush(editorBgCol
);
1965 dc
.SetPen(editorBgCol
);
1966 dc
.SetTextForeground(m_colPropFore
);
1967 dc
.DrawRectangle(cellRect
);
1969 if ( m_dragStatus
== 0 && !(m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
) )
1974 if ( renderFlags
& wxPGCellRenderer::DontUseCellBgCol
)
1976 dc
.SetBrush(rowBgBrush
);
1977 dc
.SetPen(rowBgCol
);
1980 if ( renderFlags
& wxPGCellRenderer::DontUseCellFgCol
)
1982 dc
.SetTextForeground(rowFgCol
);
1986 dc
.SetClippingRegion(cellRect
);
1988 cellRect
.x
+= textXAdd
;
1989 cellRect
.width
-= textXAdd
;
1994 wxPGCellRenderer
* renderer
;
1995 int cmnVal
= p
->GetCommonValue();
1996 if ( cmnVal
== -1 || ci
!= 1 )
1998 renderer
= p
->GetCellRenderer(ci
);
1999 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2004 renderer
= GetCommonValue(cmnVal
)->GetRenderer();
2005 renderer
->Render( dc
, cellRect
, this, p
, ci
, -1,
2010 cellX
+= state
->m_colWidths
[ci
];
2011 if ( ci
< (state
->m_colWidths
.size()-1) )
2012 nextCellWidth
= state
->m_colWidths
[ci
+1];
2014 dc
.DestroyClippingRegion(); // Is this really necessary?
2020 dc
.SetFont(normalfont
);
2025 // Refresh editor controls (seems not needed on msw)
2026 // NOTE: This code is mandatory for GTK!
2027 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2028 if ( wasSelectedPainted
)
2031 m_wndEditor
->Refresh();
2033 m_wndEditor2
->Refresh();
2040 // -----------------------------------------------------------------------
2042 wxRect
wxPropertyGrid::GetPropertyRect( const wxPGProperty
* p1
, const wxPGProperty
* p2
) const
2046 if ( m_width
< 10 || m_height
< 10 ||
2047 !m_pState
->m_properties
->GetChildCount() ||
2048 p1
== (wxPGProperty
*) NULL
)
2049 return wxRect(0,0,0,0);
2054 // Return rect which encloses the given property range
2056 int visTop
= p1
->GetY();
2059 visBottom
= p2
->GetY() + m_lineHeight
;
2061 visBottom
= m_height
+ visTop
;
2063 // If seleced property is inside the range, we'll extend the range to include
2065 wxPGProperty
* selected
= m_selected
;
2068 int selectedY
= selected
->GetY();
2069 if ( selectedY
>= visTop
&& selectedY
< visBottom
)
2071 wxWindow
* editor
= GetEditorControl();
2074 int visBottom2
= selectedY
+ editor
->GetSize().y
;
2075 if ( visBottom2
> visBottom
)
2076 visBottom
= visBottom2
;
2081 return wxRect(0,visTop
-vy
,m_pState
->m_width
,visBottom
-visTop
);
2084 // -----------------------------------------------------------------------
2086 void wxPropertyGrid::DrawItems( const wxPGProperty
* p1
, const wxPGProperty
* p2
)
2091 if ( m_pState
->m_itemsAdded
)
2092 PrepareAfterItemsAdded();
2094 wxRect r
= GetPropertyRect(p1
, p2
);
2097 m_canvas
->RefreshRect(r
);
2101 // -----------------------------------------------------------------------
2103 void wxPropertyGrid::RefreshProperty( wxPGProperty
* p
)
2105 if ( p
== m_selected
)
2106 DoSelectProperty(p
, wxPG_SEL_FORCE
);
2108 DrawItemAndChildren(p
);
2111 // -----------------------------------------------------------------------
2113 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty
* p
)
2118 // Draw item, children, and parent too, if it is not category
2119 wxPGProperty
* parent
= p
->GetParent();
2122 !parent
->IsCategory() &&
2123 parent
->GetParent() )
2126 parent
= parent
->GetParent();
2129 DrawItemAndChildren(p
);
2132 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty
* p
)
2134 wxCHECK_RET( p
, wxT("invalid property id") );
2136 // Do not draw if in non-visible page
2137 if ( p
->GetParentState() != m_pState
)
2140 // do not draw a single item if multiple pending
2141 if ( m_pState
->m_itemsAdded
|| m_frozen
)
2144 wxWindow
* wndPrimary
= GetEditorControl();
2146 // Update child control.
2147 if ( m_selected
&& m_selected
->GetParent() == p
)
2148 m_selected
->UpdateControl(wndPrimary
);
2150 const wxPGProperty
* lastDrawn
= p
->GetLastVisibleSubItem();
2152 DrawItems(p
, lastDrawn
);
2155 // -----------------------------------------------------------------------
2157 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground
),
2158 const wxRect
*rect
)
2160 PrepareAfterItemsAdded();
2162 wxWindow::Refresh(false);
2164 // TODO: Coordinate translation
2165 m_canvas
->Refresh(false, rect
);
2167 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2168 // I think this really helps only GTK+1.2
2169 if ( m_wndEditor
) m_wndEditor
->Refresh();
2170 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2174 // -----------------------------------------------------------------------
2175 // wxPropertyGrid global operations
2176 // -----------------------------------------------------------------------
2178 void wxPropertyGrid::Clear()
2182 bool selRes
= DoSelectProperty(NULL
, wxPG_SEL_DELETING
); // This must be before state clear
2183 wxPG_CHECK_RET_DBG( selRes
,
2184 wxT("failed to deselect a property (editor probably had invalid value)") );
2187 m_pState
->DoClear();
2193 RecalculateVirtualSize();
2195 // Need to clear some area at the end
2197 RefreshRect(wxRect(0, 0, m_width
, m_height
));
2200 // -----------------------------------------------------------------------
2202 bool wxPropertyGrid::EnableCategories( bool enable
)
2204 if ( !ClearSelection() )
2210 // Enable categories
2213 m_windowStyle
&= ~(wxPG_HIDE_CATEGORIES
);
2218 // Disable categories
2220 m_windowStyle
|= wxPG_HIDE_CATEGORIES
;
2223 if ( !m_pState
->EnableCategories(enable
) )
2228 if ( m_windowStyle
& wxPG_AUTO_SORT
)
2230 m_pState
->m_itemsAdded
= 1; // force
2231 PrepareAfterItemsAdded();
2235 m_pState
->m_itemsAdded
= 1;
2237 // No need for RecalculateVirtualSize() here - it is already called in
2238 // wxPropertyGridPageState method above.
2245 // -----------------------------------------------------------------------
2247 void wxPropertyGrid::SwitchState( wxPropertyGridPageState
* pNewState
)
2249 wxASSERT( pNewState
);
2250 wxASSERT( pNewState
->GetGrid() );
2252 if ( pNewState
== m_pState
)
2255 wxPGProperty
* oldSelection
= m_selected
;
2260 bool selRes
= ClearSelection();
2261 wxPG_CHECK_RET_DBG( selRes
,
2262 wxT("failed to deselect a property (editor probably had invalid value)") );
2265 m_pState
->m_selected
= oldSelection
;
2267 bool orig_mode
= m_pState
->IsInNonCatMode();
2268 bool new_state_mode
= pNewState
->IsInNonCatMode();
2270 m_pState
= pNewState
;
2273 int pgWidth
= GetClientSize().x
;
2274 if ( HasVirtualWidth() )
2276 int minWidth
= pgWidth
;
2277 if ( pNewState
->m_width
< minWidth
)
2279 pNewState
->m_width
= minWidth
;
2280 pNewState
->CheckColumnWidths();
2286 // Just in case, fully re-center splitter
2287 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER
) )
2288 pNewState
->m_fSplitterX
= -1.0;
2290 pNewState
->OnClientWidthChange( pgWidth
, pgWidth
- pNewState
->m_width
);
2293 m_propHover
= (wxPGProperty
*) NULL
;
2295 // If necessary, convert state to correct mode.
2296 if ( orig_mode
!= new_state_mode
)
2298 // This should refresh as well.
2299 EnableCategories( orig_mode
?false:true );
2301 else if ( !m_frozen
)
2303 // Refresh, if not frozen.
2304 if ( m_pState
->m_itemsAdded
)
2305 PrepareAfterItemsAdded();
2308 if ( m_pState
->m_selected
)
2309 DoSelectProperty( m_pState
->m_selected
);
2311 RecalculateVirtualSize(0);
2315 m_pState
->m_itemsAdded
= 1;
2318 // -----------------------------------------------------------------------
2320 void wxPropertyGrid::SortChildren( wxPGPropArg id
)
2322 wxPG_PROP_ARG_CALL_PROLOG()
2324 m_pState
->SortChildren( p
);
2327 // -----------------------------------------------------------------------
2329 void wxPropertyGrid::Sort()
2331 bool selRes
= ClearSelection(); // This must be before state clear
2332 wxPG_CHECK_RET_DBG( selRes
,
2333 wxT("failed to deselect a property (editor probably had invalid value)") );
2338 // -----------------------------------------------------------------------
2340 // Call to SetSplitterPosition will always disable splitter auto-centering
2341 // if parent window is shown.
2342 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos
, bool refresh
, int splitterIndex
, bool allPages
)
2344 if ( ( newxpos
< wxPG_DRAG_MARGIN
) )
2347 wxPropertyGridPageState
* state
= m_pState
;
2349 state
->DoSetSplitterPosition( newxpos
, splitterIndex
, allPages
);
2354 CorrectEditorWidgetSizeX();
2360 // -----------------------------------------------------------------------
2362 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering
)
2364 SetSplitterPosition( m_width
/2, true );
2365 if ( enableAutoCentering
&& ( m_windowStyle
& wxPG_SPLITTER_AUTO_CENTER
) )
2366 m_iFlags
&= ~(wxPG_FL_DONT_CENTER_SPLITTER
);
2369 // -----------------------------------------------------------------------
2370 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2371 // -----------------------------------------------------------------------
2373 // Returns nearest paint visible property (such that will be painted unless
2374 // window is scrolled or resized). If given property is paint visible, then
2375 // it itself will be returned
2376 wxPGProperty
* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty
* p
) const
2378 int vx
,vy1
;// Top left corner of client
2379 GetViewStart(&vx
,&vy1
);
2380 vy1
*= wxPG_PIXELS_PER_UNIT
;
2382 int vy2
= vy1
+ m_height
;
2383 int propY
= p
->GetY2(m_lineHeight
);
2385 if ( (propY
+ m_lineHeight
) < vy1
)
2388 return DoGetItemAtY( vy1
);
2390 else if ( propY
> vy2
)
2393 return DoGetItemAtY( vy2
);
2396 // Itself paint visible
2401 // -----------------------------------------------------------------------
2402 // Methods related to change in value, value modification and sending events
2403 // -----------------------------------------------------------------------
2405 // commits any changes in editor of selected property
2406 // return true if validation did not fail
2407 // flags are same as with DoSelectProperty
2408 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags
)
2410 // Committing already?
2411 if ( m_inCommitChangesFromEditor
)
2414 // Don't do this if already processing editor event. It might
2415 // induce recursive dialogs and crap like that.
2416 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2418 if ( m_inDoPropertyChanged
)
2425 IsEditorsValueModified() &&
2426 (m_iFlags
& wxPG_FL_INITIALIZED
) &&
2429 m_inCommitChangesFromEditor
= 1;
2431 wxVariant
variant(m_selected
->GetValueRef());
2432 bool valueIsPending
= false;
2434 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2435 // due to another window getting focus
2436 wxWindow
* oldFocus
= m_curFocused
;
2438 bool validationFailure
= false;
2439 bool forceSuccess
= (flags
& (wxPG_SEL_NOVALIDATE
|wxPG_SEL_FORCE
)) ? true : false;
2441 m_chgInfo_changedProperty
= NULL
;
2443 // If truly modified, schedule value as pending.
2444 if ( m_selected
->GetEditorClass()->GetValueFromControl( variant
, m_selected
, GetEditorControl() ) )
2446 if ( DoEditorValidate() &&
2447 PerformValidation(m_selected
, variant
) )
2449 valueIsPending
= true;
2453 validationFailure
= true;
2458 EditorsValueWasNotModified();
2463 m_inCommitChangesFromEditor
= 0;
2465 if ( validationFailure
&& !forceSuccess
)
2469 oldFocus
->SetFocus();
2470 m_curFocused
= oldFocus
;
2473 res
= OnValidationFailure(m_selected
, variant
);
2475 // Now prevent further validation failure messages
2478 EditorsValueWasNotModified();
2479 OnValidationFailureReset(m_selected
);
2482 else if ( valueIsPending
)
2484 DoPropertyChanged( m_selected
, flags
);
2485 EditorsValueWasNotModified();
2494 // -----------------------------------------------------------------------
2496 bool wxPropertyGrid::PerformValidation( wxPGProperty
* p
, wxVariant
& pendingValue
,
2500 // Runs all validation functionality.
2501 // Returns true if value passes all tests.
2504 m_validationInfo
.m_failureBehavior
= m_permanentValidationFailureBehavior
;
2506 if ( pendingValue
.GetType() == wxPG_VARIANT_TYPE_LIST
)
2508 if ( !p
->ValidateValue(pendingValue
, m_validationInfo
) )
2513 // Adapt list to child values, if necessary
2514 wxVariant listValue
= pendingValue
;
2515 wxVariant
* pPendingValue
= &pendingValue
;
2516 wxVariant
* pList
= NULL
;
2518 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2519 // string value, then we need treat as it was changed instead
2520 // (or, in addition, as is the case with composite string parent).
2521 // This includes creating list variant for child values.
2523 wxPGProperty
* pwc
= p
->GetParent();
2524 wxPGProperty
* changedProperty
= p
;
2525 wxPGProperty
* baseChangedProperty
= changedProperty
;
2526 wxVariant bcpPendingList
;
2528 listValue
= pendingValue
;
2529 listValue
.SetName(p
->GetBaseName());
2532 (pwc
->HasFlag(wxPG_PROP_AGGREGATE
) || pwc
->HasFlag(wxPG_PROP_COMPOSED_VALUE
)) )
2534 wxVariantList tempList
;
2535 wxVariant
lv(tempList
, pwc
->GetBaseName());
2536 lv
.Append(listValue
);
2538 pPendingValue
= &listValue
;
2540 if ( pwc
->HasFlag(wxPG_PROP_AGGREGATE
) )
2542 baseChangedProperty
= pwc
;
2543 bcpPendingList
= lv
;
2546 changedProperty
= pwc
;
2547 pwc
= pwc
->GetParent();
2551 wxPGProperty
* evtChangingProperty
= changedProperty
;
2553 if ( pPendingValue
->GetType() != wxPG_VARIANT_TYPE_LIST
)
2555 value
= *pPendingValue
;
2559 // Convert list to child values
2560 pList
= pPendingValue
;
2561 changedProperty
->AdaptListToValue( *pPendingValue
, &value
);
2564 wxVariant evtChangingValue
= value
;
2566 if ( flags
& SendEvtChanging
)
2568 // FIXME: After proper ValueToString()s added, remove
2569 // this. It is just a temporary fix, as evt_changing
2570 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2571 // (unless it is selected, and textctrl editor is open).
2572 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2574 evtChangingProperty
= baseChangedProperty
;
2575 if ( evtChangingProperty
!= p
)
2577 evtChangingProperty
->AdaptListToValue( bcpPendingList
, &evtChangingValue
);
2581 evtChangingValue
= pendingValue
;
2585 if ( evtChangingProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2587 if ( changedProperty
== m_selected
)
2589 wxWindow
* editor
= GetEditorControl();
2590 wxASSERT( editor
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
2591 evtChangingValue
= wxStaticCast(editor
, wxTextCtrl
)->GetValue();
2595 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2600 wxASSERT( m_chgInfo_changedProperty
== NULL
);
2601 m_chgInfo_changedProperty
= changedProperty
;
2602 m_chgInfo_baseChangedProperty
= baseChangedProperty
;
2603 m_chgInfo_pendingValue
= value
;
2606 m_chgInfo_valueList
= *pList
;
2608 m_chgInfo_valueList
.MakeNull();
2610 // If changedProperty is not property which value was edited,
2611 // then call wxPGProperty::ValidateValue() for that as well.
2612 if ( p
!= changedProperty
&& value
.GetType() != wxPG_VARIANT_TYPE_LIST
)
2614 if ( !changedProperty
->ValidateValue(value
, m_validationInfo
) )
2618 if ( flags
& SendEvtChanging
)
2620 // SendEvent returns true if event was vetoed
2621 if ( SendEvent( wxEVT_PG_CHANGING
, evtChangingProperty
, &evtChangingValue
, 0 ) )
2625 if ( flags
& IsStandaloneValidation
)
2627 // If called in 'generic' context, we need to reset
2628 // m_chgInfo_changedProperty and write back translated value.
2629 m_chgInfo_changedProperty
= NULL
;
2630 pendingValue
= value
;
2636 // -----------------------------------------------------------------------
2638 void wxPropertyGrid::DoShowPropertyError( wxPGProperty
* WXUNUSED(property
), const wxString
& msg
)
2640 if ( !msg
.length() )
2644 if ( !wxPGGlobalVars
->m_offline
)
2646 wxWindow
* topWnd
= ::wxGetTopLevelParent(this);
2649 wxFrame
* pFrame
= wxDynamicCast(topWnd
, wxFrame
);
2652 wxStatusBar
* pStatusBar
= pFrame
->GetStatusBar();
2655 pStatusBar
->SetStatusText(msg
);
2663 ::wxMessageBox(msg
, _T("Property Error"));
2666 // -----------------------------------------------------------------------
2668 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty
* property
, wxVariant
& WXUNUSED(invalidValue
) )
2670 int vfb
= m_validationInfo
.m_failureBehavior
;
2672 if ( vfb
& wxPG_VFB_BEEP
)
2675 if ( (vfb
& wxPG_VFB_MARK_CELL
) &&
2676 !property
->HasFlag(wxPG_PROP_INVALID_VALUE
) )
2678 unsigned int colCount
= m_pState
->GetColumnCount();
2680 // We need backup marked property's cells
2681 m_propCellsBackup
= property
->m_cells
;
2683 wxColour vfbFg
= *wxWHITE
;
2684 wxColour vfbBg
= *wxRED
;
2686 property
->EnsureCells(colCount
);
2688 for ( unsigned int i
=0; i
<colCount
; i
++ )
2690 wxPGCell
& cell
= property
->m_cells
[i
];
2691 cell
.SetFgCol(vfbFg
);
2692 cell
.SetBgCol(vfbBg
);
2695 DrawItemAndChildren(property
);
2697 if ( property
== m_selected
)
2699 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2701 wxWindow
* editor
= GetEditorControl();
2704 editor
->SetForegroundColour(vfbFg
);
2705 editor
->SetBackgroundColour(vfbBg
);
2710 if ( vfb
& wxPG_VFB_SHOW_MESSAGE
)
2712 wxString msg
= m_validationInfo
.m_failureMessage
;
2714 if ( !msg
.length() )
2715 msg
= _T("You have entered invalid value. Press ESC to cancel editing.");
2717 DoShowPropertyError(property
, msg
);
2720 return (vfb
& wxPG_VFB_STAY_IN_PROPERTY
) ? false : true;
2723 // -----------------------------------------------------------------------
2725 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty
* property
)
2727 int vfb
= m_validationInfo
.m_failureBehavior
;
2729 if ( vfb
& wxPG_VFB_MARK_CELL
)
2732 property
->m_cells
= m_propCellsBackup
;
2734 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL
);
2736 if ( property
== m_selected
&& GetEditorControl() )
2738 // Calling this will recreate the control, thus resetting its colour
2739 RefreshProperty(property
);
2743 DrawItemAndChildren(property
);
2748 // -----------------------------------------------------------------------
2750 // flags are same as with DoSelectProperty
2751 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty
* p
, unsigned int selFlags
)
2753 if ( m_inDoPropertyChanged
)
2756 wxWindow
* editor
= GetEditorControl();
2758 m_pState
->m_anyModified
= 1;
2760 m_inDoPropertyChanged
= 1;
2762 // Maybe need to update control
2763 wxASSERT( m_chgInfo_changedProperty
!= NULL
);
2765 // These values were calculated in PerformValidation()
2766 wxPGProperty
* changedProperty
= m_chgInfo_changedProperty
;
2767 wxVariant value
= m_chgInfo_pendingValue
;
2769 wxPGProperty
* topPaintedProperty
= changedProperty
;
2771 while ( !topPaintedProperty
->IsCategory() &&
2772 !topPaintedProperty
->IsRoot() )
2774 topPaintedProperty
= topPaintedProperty
->GetParent();
2777 changedProperty
->SetValue(value
, &m_chgInfo_valueList
, wxPG_SETVAL_BY_USER
);
2779 // Set as Modified (not if dragging just began)
2780 if ( !(p
->m_flags
& wxPG_PROP_MODIFIED
) )
2782 p
->m_flags
|= wxPG_PROP_MODIFIED
;
2783 if ( p
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2786 SetCurControlBoldFont();
2792 // Propagate updates to parent(s)
2794 wxPGProperty
* prevPwc
= NULL
;
2796 while ( prevPwc
!= topPaintedProperty
)
2798 pwc
->m_flags
|= wxPG_PROP_MODIFIED
;
2800 if ( pwc
== m_selected
&& (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
2803 SetCurControlBoldFont();
2807 pwc
= pwc
->GetParent();
2810 // Draw the actual property
2811 DrawItemAndChildren( topPaintedProperty
);
2814 // If value was set by wxPGProperty::OnEvent, then update the editor
2816 if ( selFlags
& wxPG_SEL_DIALOGVAL
)
2819 p
->GetEditorClass()->UpdateControl(p
, editor
);
2823 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2824 if ( m_wndEditor
) m_wndEditor
->Refresh();
2825 if ( m_wndEditor2
) m_wndEditor2
->Refresh();
2830 wxASSERT( !changedProperty
->GetParent()->HasFlag(wxPG_PROP_AGGREGATE
) );
2832 // If top parent has composite string value, then send to child parents,
2833 // starting from baseChangedProperty.
2834 if ( changedProperty
->HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
2836 pwc
= m_chgInfo_baseChangedProperty
;
2838 while ( pwc
!= changedProperty
)
2840 SendEvent( wxEVT_PG_CHANGED
, pwc
, NULL
, selFlags
);
2841 pwc
= pwc
->GetParent();
2845 SendEvent( wxEVT_PG_CHANGED
, changedProperty
, NULL
, selFlags
);
2847 m_inDoPropertyChanged
= 0;
2852 // -----------------------------------------------------------------------
2854 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
)
2856 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2858 m_chgInfo_changedProperty
= NULL
;
2860 if ( PerformValidation(p
, newValue
) )
2862 DoPropertyChanged(p
);
2867 OnValidationFailure(p
, newValue
);
2873 // -----------------------------------------------------------------------
2875 wxVariant
wxPropertyGrid::GetUncommittedPropertyValue()
2877 wxPGProperty
* prop
= GetSelectedProperty();
2880 return wxNullVariant
;
2882 wxTextCtrl
* tc
= GetEditorTextCtrl();
2883 wxVariant value
= prop
->GetValue();
2885 if ( !tc
|| !IsEditorsValueModified() )
2888 if ( !prop
->StringToValue(value
, tc
->GetValue()) )
2891 if ( !PerformValidation(prop
, value
, IsStandaloneValidation
) )
2892 return prop
->GetValue();
2897 // -----------------------------------------------------------------------
2899 // Runs wxValidator for the selected property
2900 bool wxPropertyGrid::DoEditorValidate()
2905 // -----------------------------------------------------------------------
2907 bool wxPropertyGrid::ProcessEvent(wxEvent
& event
)
2909 wxWindow
* wnd
= (wxWindow
*) event
.GetEventObject();
2910 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxWindow
)) )
2912 wxWindow
* parent
= wnd
->GetParent();
2915 (parent
== m_canvas
||
2916 parent
->GetParent() == m_canvas
) )
2918 OnCustomEditorEvent(event
);
2922 return wxPanel::ProcessEvent(event
);
2925 // -----------------------------------------------------------------------
2927 void wxPropertyGrid::OnCustomEditorEvent( wxEvent
&event
)
2929 wxPGProperty
* selected
= m_selected
;
2931 // Somehow, event is handled after property has been deselected.
2932 // Possibly, but very rare.
2936 if ( m_iFlags
& wxPG_FL_IN_ONCUSTOMEDITOREVENT
)
2939 wxVariant
pendingValue(selected
->GetValueRef());
2940 wxWindow
* wnd
= GetEditorControl();
2942 bool wasUnspecified
= selected
->IsValueUnspecified();
2943 int usesAutoUnspecified
= selected
->UsesAutoUnspecified();
2945 bool valueIsPending
= false;
2947 m_chgInfo_changedProperty
= NULL
;
2949 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
|wxPG_FL_VALUE_CHANGE_IN_EVENT
);
2952 // Filter out excess wxTextCtrl modified events
2953 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
&&
2955 wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2957 wxTextCtrl
* tc
= (wxTextCtrl
*) wnd
;
2959 wxString newTcValue
= tc
->GetValue();
2960 if ( m_prevTcValue
== newTcValue
)
2963 m_prevTcValue
= newTcValue
;
2966 SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
2968 bool validationFailure
= false;
2969 bool buttonWasHandled
= false;
2972 // Try common button handling
2973 if ( m_wndEditor2
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
2975 wxPGEditorDialogAdapter
* adapter
= selected
->GetEditorDialog();
2979 buttonWasHandled
= true;
2980 // Store as res2, as previously (and still currently alternatively)
2981 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2982 // in wxPGProperty::OnEvent().
2983 adapter
->ShowDialog( this, selected
);
2988 if ( !buttonWasHandled
)
2992 // First call editor class' event handler.
2993 const wxPGEditor
* editor
= selected
->GetEditorClass();
2995 if ( editor
->OnEvent( this, selected
, wnd
, event
) )
2997 // If changes, validate them
2998 if ( DoEditorValidate() )
3000 if ( editor
->GetValueFromControl( pendingValue
, m_selected
, wnd
) )
3001 valueIsPending
= true;
3005 validationFailure
= true;
3010 // Then the property's custom handler (must be always called, unless
3011 // validation failed).
3012 if ( !validationFailure
)
3013 buttonWasHandled
= selected
->OnEvent( this, wnd
, event
);
3016 // SetValueInEvent(), as called in one of the functions referred above
3017 // overrides editor's value.
3018 if ( m_iFlags
& wxPG_FL_VALUE_CHANGE_IN_EVENT
)
3020 valueIsPending
= true;
3021 pendingValue
= m_changeInEventValue
;
3022 selFlags
|= wxPG_SEL_DIALOGVAL
;
3025 if ( !validationFailure
&& valueIsPending
)
3026 if ( !PerformValidation(m_selected
, pendingValue
) )
3027 validationFailure
= true;
3029 if ( validationFailure
)
3031 OnValidationFailure(selected
, pendingValue
);
3033 else if ( valueIsPending
)
3035 selFlags
|= ( !wasUnspecified
&& selected
->IsValueUnspecified() && usesAutoUnspecified
) ? wxPG_SEL_SETUNSPEC
: 0;
3037 DoPropertyChanged(selected
, selFlags
);
3038 EditorsValueWasNotModified();
3040 // Regardless of editor type, unfocus editor on
3041 // text-editing related enter press.
3042 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3049 // No value after all
3051 // Regardless of editor type, unfocus editor on
3052 // text-editing related enter press.
3053 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
3058 // Let unhandled button click events go to the parent
3059 if ( !buttonWasHandled
&& event
.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED
)
3061 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
,GetId());
3062 GetEventHandler()->AddPendingEvent(evt
);
3066 ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT
);
3069 // -----------------------------------------------------------------------
3070 // wxPropertyGrid editor control helper methods
3071 // -----------------------------------------------------------------------
3073 wxRect
wxPropertyGrid::GetEditorWidgetRect( wxPGProperty
* p
, int column
) const
3075 int itemy
= p
->GetY2(m_lineHeight
);
3077 int cust_img_space
= 0;
3078 int splitterX
= m_pState
->DoGetSplitterPosition(column
-1);
3079 int colEnd
= splitterX
+ m_pState
->m_colWidths
[column
];
3081 // TODO: If custom image detection changes from current, change this.
3082 if ( m_iFlags
& wxPG_FL_CUR_USES_CUSTOM_IMAGE
/*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3084 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3085 int imwid
= p
->OnMeasureImage().x
;
3086 if ( imwid
< 1 ) imwid
= wxPG_CUSTOM_IMAGE_WIDTH
;
3087 cust_img_space
= imwid
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
3092 splitterX
+cust_img_space
+wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1,
3094 colEnd
-splitterX
-wxPG_XBEFOREWIDGET
-wxPG_CONTROL_MARGIN
-cust_img_space
-1,
3099 // -----------------------------------------------------------------------
3101 wxRect
wxPropertyGrid::GetImageRect( wxPGProperty
* p
, int item
) const
3103 wxSize sz
= GetImageSize(p
, item
);
3104 return wxRect(wxPG_CONTROL_MARGIN
+ wxCC_CUSTOM_IMAGE_MARGIN1
,
3105 wxPG_CUSTOM_IMAGE_SPACINGY
,
3110 // return size of custom paint image
3111 wxSize
wxPropertyGrid::GetImageSize( wxPGProperty
* p
, int item
) const
3113 // If called with NULL property, then return default image
3114 // size for properties that use image.
3116 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH
,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
));
3118 wxSize cis
= p
->OnMeasureImage(item
);
3120 int choiceCount
= p
->m_choices
.GetCount();
3121 int comVals
= p
->GetDisplayedCommonValueCount();
3122 if ( item
>= choiceCount
&& comVals
> 0 )
3124 unsigned int cvi
= item
-choiceCount
;
3125 cis
= GetCommonValue(cvi
)->GetRenderer()->GetImageSize(NULL
, 1, cvi
);
3127 else if ( item
>= 0 && choiceCount
== 0 )
3128 return wxSize(0, 0);
3133 cis
.x
= wxPG_CUSTOM_IMAGE_WIDTH
;
3138 cis
.y
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
3145 // -----------------------------------------------------------------------
3147 // takes scrolling into account
3148 void wxPropertyGrid::ImprovedClientToScreen( int* px
, int* py
)
3151 GetViewStart(&vx
,&vy
);
3152 vy
*=wxPG_PIXELS_PER_UNIT
;
3153 vx
*=wxPG_PIXELS_PER_UNIT
;
3156 ClientToScreen( px
, py
);
3159 // -----------------------------------------------------------------------
3161 wxPropertyGridHitTestResult
wxPropertyGrid::HitTest( const wxPoint
& pt
) const
3164 GetViewStart(&pt2
.x
,&pt2
.y
);
3165 pt2
.x
*= wxPG_PIXELS_PER_UNIT
;
3166 pt2
.y
*= wxPG_PIXELS_PER_UNIT
;
3170 return m_pState
->HitTest(pt2
);
3173 // -----------------------------------------------------------------------
3175 // custom set cursor
3176 void wxPropertyGrid::CustomSetCursor( int type
, bool override
)
3178 if ( type
== m_curcursor
&& !override
) return;
3180 wxCursor
* cursor
= &wxPG_DEFAULT_CURSOR
;
3182 if ( type
== wxCURSOR_SIZEWE
)
3183 cursor
= m_cursorSizeWE
;
3185 m_canvas
->SetCursor( *cursor
);
3190 // -----------------------------------------------------------------------
3191 // wxPropertyGrid property selection
3192 // -----------------------------------------------------------------------
3194 // Setups event handling for child control
3195 void wxPropertyGrid::SetupChildEventHandling( wxWindow
* argWnd
)
3197 wxWindowID id
= argWnd
->GetId();
3199 if ( argWnd
== m_wndEditor
)
3201 argWnd
->Connect(id
, wxEVT_MOTION
,
3202 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild
),
3204 argWnd
->Connect(id
, wxEVT_LEFT_UP
,
3205 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild
),
3207 argWnd
->Connect(id
, wxEVT_LEFT_DOWN
,
3208 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild
),
3210 argWnd
->Connect(id
, wxEVT_RIGHT_UP
,
3211 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild
),
3213 argWnd
->Connect(id
, wxEVT_ENTER_WINDOW
,
3214 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3216 argWnd
->Connect(id
, wxEVT_LEAVE_WINDOW
,
3217 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry
),
3221 argWnd
->Connect(id
, wxEVT_KEY_DOWN
,
3222 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown
),
3226 void wxPropertyGrid::FreeEditors()
3229 // Return focus back to canvas from children (this is required at least for
3230 // GTK+, which, unlike Windows, clears focus when control is destroyed
3231 // instead of moving it to closest parent).
3232 wxWindow
* focus
= wxWindow::FindFocus();
3235 wxWindow
* parent
= focus
->GetParent();
3238 if ( parent
== m_canvas
)
3243 parent
= parent
->GetParent();
3247 // Do not free editors immediately if processing events
3250 m_wndEditor2
->Hide();
3251 wxPendingDelete
.Append( m_wndEditor2
);
3252 m_wndEditor2
= (wxWindow
*) NULL
;
3257 m_wndEditor
->Hide();
3258 wxPendingDelete
.Append( m_wndEditor
);
3259 m_wndEditor
= (wxWindow
*) NULL
;
3263 // Call with NULL to de-select property
3264 bool wxPropertyGrid::DoSelectProperty( wxPGProperty
* p
, unsigned int flags
)
3268 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3269 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3271 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3274 if ( m_inDoSelectProperty
)
3277 m_inDoSelectProperty
= 1;
3279 wxPGProperty
* prev
= m_selected
;
3283 m_inDoSelectProperty
= 0;
3289 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3291 wxPrintf( "None selected\n" );
3294 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3296 wxPrintf( "P = NULL\n" );
3299 // If we are frozen, then just set the values.
3302 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3303 m_editorFocused
= 0;
3306 m_pState
->m_selected
= p
;
3308 // If frozen, always free controls. But don't worry, as Thaw will
3309 // recall SelectProperty to recreate them.
3312 // Prevent any further selection measures in this call
3313 p
= (wxPGProperty
*) NULL
;
3318 if ( m_selected
== p
&& !(flags
& wxPG_SEL_FORCE
) )
3320 // Only set focus if not deselecting
3323 if ( flags
& wxPG_SEL_FOCUS
)
3327 m_wndEditor
->SetFocus();
3328 m_editorFocused
= 1;
3337 m_inDoSelectProperty
= 0;
3342 // First, deactivate previous
3346 OnValidationFailureReset(m_selected
);
3348 // Must double-check if this is an selected in case of forceswitch
3351 if ( !CommitChangesFromEditor(flags
) )
3353 // Validation has failed, so we can't exit the previous editor
3354 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3355 // _("Invalid Value"),wxOK|wxICON_ERROR);
3356 m_inDoSelectProperty
= 0;
3364 m_selected
= (wxPGProperty
*) NULL
;
3365 m_pState
->m_selected
= (wxPGProperty
*) NULL
;
3367 // We need to always fully refresh the grid here
3370 m_iFlags
&= ~(wxPG_FL_ABNORMAL_EDITOR
);
3371 EditorsValueWasNotModified();
3374 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3377 // Then, activate the one given.
3380 int propY
= p
->GetY2(m_lineHeight
);
3382 int splitterX
= GetSplitterPosition();
3383 m_editorFocused
= 0;
3385 m_pState
->m_selected
= p
;
3386 m_iFlags
|= wxPG_FL_PRIMARY_FILLS_ENTIRE
;
3388 m_iFlags
&= ~(wxPG_FL_VALIDATION_FAILED
);
3390 wxASSERT( m_wndEditor
== (wxWindow
*) NULL
);
3392 // Do we need OnMeasureCalls?
3393 wxSize imsz
= p
->OnMeasureImage();
3396 // Only create editor for non-disabled non-caption
3397 if ( !p
->IsCategory() && !(p
->m_flags
& wxPG_PROP_DISABLED
) )
3399 // do this for non-caption items
3403 // Do we need to paint the custom image, if any?
3404 m_iFlags
&= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE
);
3405 if ( (p
->m_flags
& wxPG_PROP_CUSTOMIMAGE
) &&
3406 !p
->GetEditorClass()->CanContainCustomImage()
3408 m_iFlags
|= wxPG_FL_CUR_USES_CUSTOM_IMAGE
;
3410 wxRect grect
= GetEditorWidgetRect(p
, m_selColumn
);
3411 wxPoint goodPos
= grect
.GetPosition();
3412 #if wxPG_CREATE_CONTROLS_HIDDEN
3413 int coord_adjust
= m_height
- goodPos
.y
;
3414 goodPos
.y
+= coord_adjust
;
3417 const wxPGEditor
* editor
= p
->GetEditorClass();
3418 wxCHECK_MSG(editor
, false,
3419 wxT("NULL editor class not allowed"));
3421 m_iFlags
&= ~wxPG_FL_FIXED_WIDTH_EDITOR
;
3423 wxPGWindowList wndList
= editor
->CreateControls(this,
3428 m_wndEditor
= wndList
.m_primary
;
3429 m_wndEditor2
= wndList
.m_secondary
;
3430 wxWindow
* primaryCtrl
= GetEditorControl();
3433 // Essentially, primaryCtrl == m_wndEditor
3436 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3437 // value is drawn as normal, and m_wndEditor2 is assumed
3438 // to be a right-aligned button that triggers a separate editorCtrl
3443 wxASSERT_MSG( m_wndEditor
->GetParent() == GetPanel(),
3444 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3446 // Set validator, if any
3447 #if wxUSE_VALIDATORS
3448 wxValidator
* validator
= p
->GetValidator();
3450 primaryCtrl
->SetValidator(*validator
);
3453 if ( m_wndEditor
->GetSize().y
> (m_lineHeight
+6) )
3454 m_iFlags
|= wxPG_FL_ABNORMAL_EDITOR
;
3456 // If it has modified status, use bold font
3457 // (must be done before capturing m_ctrlXAdjust)
3458 if ( (p
->m_flags
& wxPG_PROP_MODIFIED
) && (m_windowStyle
& wxPG_BOLD_MODIFIED
) )
3459 SetCurControlBoldFont();
3462 // Fix TextCtrl indentation
3463 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3464 wxTextCtrl
* tc
= NULL
;
3465 if ( primaryCtrl
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
3466 tc
= ((wxOwnerDrawnComboBox
*)primaryCtrl
)->GetTextCtrl();
3468 tc
= wxDynamicCast(primaryCtrl
, wxTextCtrl
);
3470 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
3473 // Store x relative to splitter (we'll need it).
3474 m_ctrlXAdjust
= m_wndEditor
->GetPosition().x
- splitterX
;
3476 // Check if background clear is not necessary
3477 wxPoint pos
= m_wndEditor
->GetPosition();
3478 if ( pos
.x
> (splitterX
+1) || pos
.y
> propY
)
3480 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
3483 m_wndEditor
->SetSizeHints(3, 3);
3485 #if wxPG_CREATE_CONTROLS_HIDDEN
3486 m_wndEditor
->Show(false);
3487 m_wndEditor
->Freeze();
3489 goodPos
= m_wndEditor
->GetPosition();
3490 goodPos
.y
-= coord_adjust
;
3491 m_wndEditor
->Move( goodPos
);
3494 SetupChildEventHandling(primaryCtrl
);
3496 // Focus and select all (wxTextCtrl, wxComboBox etc)
3497 if ( flags
& wxPG_SEL_FOCUS
)
3499 primaryCtrl
->SetFocus();
3501 p
->GetEditorClass()->OnFocus(p
, primaryCtrl
);
3507 wxASSERT_MSG( m_wndEditor2
->GetParent() == GetPanel(),
3508 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3510 // Get proper id for wndSecondary
3511 m_wndSecId
= m_wndEditor2
->GetId();
3512 wxWindowList children
= m_wndEditor2
->GetChildren();
3513 wxWindowList::iterator node
= children
.begin();
3514 if ( node
!= children
.end() )
3515 m_wndSecId
= ((wxWindow
*)*node
)->GetId();
3517 m_wndEditor2
->SetSizeHints(3,3);
3519 #if wxPG_CREATE_CONTROLS_HIDDEN
3520 wxRect sec_rect
= m_wndEditor2
->GetRect();
3521 sec_rect
.y
-= coord_adjust
;
3523 // Fine tuning required to fix "oversized"
3524 // button disappearance bug.
3525 if ( sec_rect
.y
< 0 )
3527 sec_rect
.height
+= sec_rect
.y
;
3530 m_wndEditor2
->SetSize( sec_rect
);
3532 m_wndEditor2
->Show();
3534 SetupChildEventHandling(m_wndEditor2
);
3536 // If no primary editor, focus to button to allow
3537 // it to interprete ENTER etc.
3538 // NOTE: Due to problems focusing away from it, this
3539 // has been disabled.
3541 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3542 m_wndEditor2->SetFocus();
3546 if ( flags
& wxPG_SEL_FOCUS
)
3547 m_editorFocused
= 1;
3552 // Make sure focus is in grid canvas (important for wxGTK, at least)
3556 EditorsValueWasNotModified();
3558 // If it's inside collapsed section, expand parent, scroll, etc.
3559 // Also, if it was partially visible, scroll it into view.
3560 if ( !(flags
& wxPG_SEL_NONVISIBLE
) )
3565 #if wxPG_CREATE_CONTROLS_HIDDEN
3566 m_wndEditor
->Thaw();
3568 m_wndEditor
->Show(true);
3575 // Make sure focus is in grid canvas
3579 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY
);
3585 // Show help text in status bar.
3586 // (if found and grid not embedded in manager with help box and
3587 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3590 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
) )
3592 wxStatusBar
* statusbar
= (wxStatusBar
*) NULL
;
3593 if ( !(m_iFlags
& wxPG_FL_NOSTATUSBARHELP
) )
3595 wxFrame
* frame
= wxDynamicCast(::wxGetTopLevelParent(this),wxFrame
);
3597 statusbar
= frame
->GetStatusBar();
3602 const wxString
* pHelpString
= (const wxString
*) NULL
;
3606 pHelpString
= &p
->GetHelpString();
3607 if ( pHelpString
->length() )
3609 // Set help box text.
3610 statusbar
->SetStatusText( *pHelpString
);
3611 m_iFlags
|= wxPG_FL_STRING_IN_STATUSBAR
;
3615 if ( (!pHelpString
|| !pHelpString
->length()) &&
3616 (m_iFlags
& wxPG_FL_STRING_IN_STATUSBAR
) )
3618 // Clear help box - but only if it was written
3619 // by us at previous time.
3620 statusbar
->SetStatusText( m_emptyString
);
3621 m_iFlags
&= ~(wxPG_FL_STRING_IN_STATUSBAR
);
3627 m_inDoSelectProperty
= 0;
3629 // call wx event handler (here so that it also occurs on deselection)
3630 SendEvent( wxEVT_PG_SELECTED
, m_selected
, NULL
, flags
);
3635 // -----------------------------------------------------------------------
3637 bool wxPropertyGrid::UnfocusEditor()
3639 if ( !m_selected
|| !m_wndEditor
|| m_frozen
)
3642 if ( !CommitChangesFromEditor(0) )
3646 DrawItem(m_selected
);
3651 // -----------------------------------------------------------------------
3653 // This method is not inline because it called dozens of times
3654 // (i.e. two-arg function calls create smaller code size).
3655 bool wxPropertyGrid::DoClearSelection()
3657 return DoSelectProperty((wxPGProperty
*)NULL
);
3660 // -----------------------------------------------------------------------
3661 // wxPropertyGrid expand/collapse state
3662 // -----------------------------------------------------------------------
3664 bool wxPropertyGrid::DoCollapse( wxPGProperty
* p
, bool sendEvents
)
3666 wxPGProperty
* pwc
= wxStaticCast(p
, wxPGProperty
);
3668 // If active editor was inside collapsed section, then disable it
3669 if ( m_selected
&& m_selected
->IsSomeParent (p
) )
3671 if ( !ClearSelection() )
3675 // Store dont-center-splitter flag 'cause we need to temporarily set it
3676 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3677 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3679 bool res
= m_pState
->DoCollapse(pwc
);
3684 SendEvent( wxEVT_PG_ITEM_COLLAPSED
, p
);
3686 RecalculateVirtualSize();
3688 // Redraw etc. only if collapsed was visible.
3689 if (pwc
->IsVisible() &&
3691 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) ) )
3693 // When item is collapsed so that scrollbar would move,
3694 // graphics mess is about (unless we redraw everything).
3699 // Clear dont-center-splitter flag if it wasn't set
3700 m_iFlags
= (m_iFlags
& ~wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3705 // -----------------------------------------------------------------------
3707 bool wxPropertyGrid::DoExpand( wxPGProperty
* p
, bool sendEvents
)
3709 wxCHECK_MSG( p
, false, wxT("invalid property id") );
3711 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
3713 // Store dont-center-splitter flag 'cause we need to temporarily set it
3714 wxUint32 old_flag
= m_iFlags
& wxPG_FL_DONT_CENTER_SPLITTER
;
3715 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
3717 bool res
= m_pState
->DoExpand(pwc
);
3722 SendEvent( wxEVT_PG_ITEM_EXPANDED
, p
);
3724 RecalculateVirtualSize();
3726 // Redraw etc. only if expanded was visible.
3727 if ( pwc
->IsVisible() && !m_frozen
&&
3728 ( !pwc
->IsCategory() || !(m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
3732 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3735 DrawItems(pwc
, NULL
);
3740 // Clear dont-center-splitter flag if it wasn't set
3741 m_iFlags
= m_iFlags
& ~(wxPG_FL_DONT_CENTER_SPLITTER
) | old_flag
;
3746 // -----------------------------------------------------------------------
3748 bool wxPropertyGrid::DoHideProperty( wxPGProperty
* p
, bool hide
, int flags
)
3751 return m_pState
->DoHideProperty(p
, hide
, flags
);
3754 ( m_selected
== p
|| m_selected
->IsSomeParent(p
) )
3757 if ( !ClearSelection() )
3761 m_pState
->DoHideProperty(p
, hide
, flags
);
3763 RecalculateVirtualSize();
3770 // -----------------------------------------------------------------------
3771 // wxPropertyGrid size related methods
3772 // -----------------------------------------------------------------------
3774 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos
)
3776 if ( (m_iFlags
& wxPG_FL_RECALCULATING_VIRTUAL_SIZE
) || m_frozen
)
3780 // If virtual height was changed, then recalculate editor control position(s)
3781 if ( m_pState
->m_vhCalcPending
)
3782 CorrectEditorWidgetPosY();
3784 m_pState
->EnsureVirtualHeight();
3787 int by1
= m_pState
->GetVirtualHeight();
3788 int by2
= m_pState
->GetActualVirtualHeight();
3791 wxString s
= wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1
, by2
);
3792 wxASSERT_MSG( false,
3798 m_iFlags
|= wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3800 int x
= m_pState
->m_width
;
3801 int y
= m_pState
->m_virtualHeight
;
3804 GetClientSize(&width
,&height
);
3806 // Now adjust virtual size.
3807 SetVirtualSize(x
, y
);
3813 // Adjust scrollbars
3814 if ( HasVirtualWidth() )
3816 xAmount
= x
/wxPG_PIXELS_PER_UNIT
;
3817 xPos
= GetScrollPos( wxHORIZONTAL
);
3820 if ( forceXPos
!= -1 )
3823 else if ( xPos
> (xAmount
-(width
/wxPG_PIXELS_PER_UNIT
)) )
3826 int yAmount
= (y
+wxPG_PIXELS_PER_UNIT
+2)/wxPG_PIXELS_PER_UNIT
;
3827 int yPos
= GetScrollPos( wxVERTICAL
);
3829 SetScrollbars( wxPG_PIXELS_PER_UNIT
, wxPG_PIXELS_PER_UNIT
,
3830 xAmount
, yAmount
, xPos
, yPos
, true );
3832 // Must re-get size now
3833 GetClientSize(&width
,&height
);
3835 if ( !HasVirtualWidth() )
3837 m_pState
->SetVirtualWidth(width
);
3844 m_canvas
->SetSize( x
, y
);
3846 m_pState
->CheckColumnWidths();
3849 CorrectEditorWidgetSizeX();
3851 m_iFlags
&= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE
;
3854 // -----------------------------------------------------------------------
3856 void wxPropertyGrid::OnResize( wxSizeEvent
& event
)
3858 if ( !(m_iFlags
& wxPG_FL_INITIALIZED
) )
3862 GetClientSize(&width
,&height
);
3867 #if wxPG_DOUBLE_BUFFER
3868 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING
) )
3870 int dblh
= (m_lineHeight
*2);
3871 if ( !m_doubleBuffer
)
3873 // Create double buffer bitmap to draw on, if none
3874 int w
= (width
>250)?width
:250;
3875 int h
= height
+ dblh
;
3877 m_doubleBuffer
= new wxBitmap( w
, h
);
3881 int w
= m_doubleBuffer
->GetWidth();
3882 int h
= m_doubleBuffer
->GetHeight();
3884 // Double buffer must be large enough
3885 if ( w
< width
|| h
< (height
+dblh
) )
3887 if ( w
< width
) w
= width
;
3888 if ( h
< (height
+dblh
) ) h
= height
+ dblh
;
3889 delete m_doubleBuffer
;
3890 m_doubleBuffer
= new wxBitmap( w
, h
);
3897 m_pState
->OnClientWidthChange( width
, event
.GetSize().x
- m_ncWidth
, true );
3898 m_ncWidth
= event
.GetSize().x
;
3902 if ( m_pState
->m_itemsAdded
)
3903 PrepareAfterItemsAdded();
3905 // Without this, virtual size (atleast under wxGTK) will be skewed
3906 RecalculateVirtualSize();
3912 // -----------------------------------------------------------------------
3914 void wxPropertyGrid::SetVirtualWidth( int width
)
3918 // Disable virtual width
3919 width
= GetClientSize().x
;
3920 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3924 // Enable virtual width
3925 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH
);
3927 m_pState
->SetVirtualWidth( width
);
3930 void wxPropertyGrid::SetFocusOnCanvas()
3932 m_canvas
->SetFocusIgnoringChildren();
3933 m_editorFocused
= 0;
3936 // -----------------------------------------------------------------------
3937 // wxPropertyGrid mouse event handling
3938 // -----------------------------------------------------------------------
3940 // selFlags uses same values DoSelectProperty's flags
3941 // Returns true if event was vetoed.
3942 bool wxPropertyGrid::SendEvent( int eventType
, wxPGProperty
* p
, wxVariant
* pValue
, unsigned int WXUNUSED(selFlags
) )
3944 // Send property grid event of specific type and with specific property
3945 wxPropertyGridEvent
evt( eventType
, m_eventObject
->GetId() );
3946 evt
.SetPropertyGrid(this);
3947 evt
.SetEventObject(m_eventObject
);
3951 evt
.SetCanVeto(true);
3952 evt
.SetupValidationInfo();
3953 m_validationInfo
.m_pValue
= pValue
;
3955 wxEvtHandler
* evtHandler
= m_eventObject
->GetEventHandler();
3957 evtHandler
->ProcessEvent(evt
);
3959 return evt
.WasVetoed();
3962 // -----------------------------------------------------------------------
3964 // Return false if should be skipped
3965 bool wxPropertyGrid::HandleMouseClick( int x
, unsigned int y
, wxMouseEvent
&event
)
3969 // Need to set focus?
3970 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
3975 wxPropertyGridPageState
* state
= m_pState
;
3977 int splitterHitOffset
;
3978 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
3980 wxPGProperty
* p
= DoGetItemAtY(y
);
3984 int depth
= (int)p
->GetDepth() - 1;
3986 int marginEnds
= m_marginWidth
+ ( depth
* m_subgroup_extramargin
);
3988 if ( x
>= marginEnds
)
3992 if ( p
->IsCategory() )
3994 // This is category.
3995 wxPropertyCategory
* pwc
= (wxPropertyCategory
*)p
;
3997 int textX
= m_marginWidth
+ ((unsigned int)((pwc
->m_depth
-1)*m_subgroup_extramargin
));
3999 // Expand, collapse, activate etc. if click on text or left of splitter.
4002 ( x
< (textX
+pwc
->GetTextExtent(this, m_captionFont
)+(wxPG_CAPRECTXMARGIN
*2)) ||
4007 if ( !DoSelectProperty( p
) )
4010 // On double-click, expand/collapse.
4011 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4013 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4014 else DoExpand( p
, true );
4018 else if ( splitterHit
== -1 )
4021 unsigned int selFlag
= 0;
4022 if ( columnHit
== 1 )
4024 m_iFlags
|= wxPG_FL_ACTIVATION_BY_CLICK
;
4025 selFlag
= wxPG_SEL_FOCUS
;
4027 if ( !DoSelectProperty( p
, selFlag
) )
4030 m_iFlags
&= ~(wxPG_FL_ACTIVATION_BY_CLICK
);
4032 if ( p
->GetChildCount() && !p
->IsCategory() )
4033 // On double-click, expand/collapse.
4034 if ( event
.ButtonDClick() && !(m_windowStyle
& wxPG_HIDE_MARGIN
) )
4036 wxPGProperty
* pwc
= (wxPGProperty
*)p
;
4037 if ( pwc
->IsExpanded() ) DoCollapse( p
, true );
4038 else DoExpand( p
, true );
4045 // click on splitter
4046 if ( !(m_windowStyle
& wxPG_STATIC_SPLITTER
) )
4048 if ( event
.GetEventType() == wxEVT_LEFT_DCLICK
)
4050 // Double-clicking the splitter causes auto-centering
4051 CenterSplitter( true );
4053 else if ( m_dragStatus
== 0 )
4056 // Begin draggin the splitter
4060 // Changes must be committed here or the
4061 // value won't be drawn correctly
4062 if ( !CommitChangesFromEditor() )
4065 m_wndEditor
->Show ( false );
4068 if ( !(m_iFlags
& wxPG_FL_MOUSE_CAPTURED
) )
4070 m_canvas
->CaptureMouse();
4071 m_iFlags
|= wxPG_FL_MOUSE_CAPTURED
;
4075 m_draggedSplitter
= splitterHit
;
4076 m_dragOffset
= splitterHitOffset
;
4078 wxClientDC
dc(m_canvas
);
4080 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4081 // Fixes button disappearance bug
4083 m_wndEditor2
->Show ( false );
4086 m_startingSplitterX
= x
- splitterHitOffset
;
4094 if ( p
->GetChildCount() )
4096 int nx
= x
+ m_marginWidth
- marginEnds
; // Normalize x.
4098 if ( (nx
>= m_gutterWidth
&& nx
< (m_gutterWidth
+m_iconWidth
)) )
4100 int y2
= y
% m_lineHeight
;
4101 if ( (y2
>= m_buttonSpacingY
&& y2
< (m_buttonSpacingY
+m_iconHeight
)) )
4103 // On click on expander button, expand/collapse
4104 if ( ((wxPGProperty
*)p
)->IsExpanded() )
4105 DoCollapse( p
, true );
4107 DoExpand( p
, true );
4116 // -----------------------------------------------------------------------
4118 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4119 wxMouseEvent
& WXUNUSED(event
) )
4123 // Select property here as well
4124 wxPGProperty
* p
= m_propHover
;
4125 if ( p
!= m_selected
)
4126 DoSelectProperty( p
);
4128 // Send right click event.
4129 SendEvent( wxEVT_PG_RIGHT_CLICK
, p
);
4136 // -----------------------------------------------------------------------
4138 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x
), unsigned int WXUNUSED(y
),
4139 wxMouseEvent
& WXUNUSED(event
) )
4143 // Select property here as well
4144 wxPGProperty
* p
= m_propHover
;
4146 if ( p
!= m_selected
)
4147 DoSelectProperty( p
);
4149 // Send double-click event.
4150 SendEvent( wxEVT_PG_DOUBLE_CLICK
, m_propHover
);
4157 // -----------------------------------------------------------------------
4159 #if wxPG_SUPPORT_TOOLTIPS
4161 void wxPropertyGrid::SetToolTip( const wxString
& tipString
)
4163 if ( tipString
.length() )
4165 m_canvas
->SetToolTip(tipString
);
4169 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4170 m_canvas
->SetToolTip( m_emptyString
);
4172 m_canvas
->SetToolTip( NULL
);
4177 #endif // #if wxPG_SUPPORT_TOOLTIPS
4179 // -----------------------------------------------------------------------
4181 // Return false if should be skipped
4182 bool wxPropertyGrid::HandleMouseMove( int x
, unsigned int y
, wxMouseEvent
&event
)
4184 // Safety check (needed because mouse capturing may
4185 // otherwise freeze the control)
4186 if ( m_dragStatus
> 0 && !event
.Dragging() )
4188 HandleMouseUp(x
,y
,event
);
4191 wxPropertyGridPageState
* state
= m_pState
;
4193 int splitterHitOffset
;
4194 int columnHit
= state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4195 int splitterX
= x
- splitterHitOffset
;
4197 if ( m_dragStatus
> 0 )
4199 if ( x
> (m_marginWidth
+ wxPG_DRAG_MARGIN
) &&
4200 x
< (m_pState
->m_width
- wxPG_DRAG_MARGIN
) )
4203 int newSplitterX
= x
- m_dragOffset
;
4204 int splitterX
= x
- splitterHitOffset
;
4206 // Splitter redraw required?
4207 if ( newSplitterX
!= splitterX
)
4210 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER
);
4211 state
->DoSetSplitterPosition( newSplitterX
, m_draggedSplitter
, false );
4212 state
->m_fSplitterX
= (float) newSplitterX
;
4215 CorrectEditorWidgetSizeX();
4229 int ih
= m_lineHeight
;
4232 #if wxPG_SUPPORT_TOOLTIPS
4233 wxPGProperty
* prevHover
= m_propHover
;
4234 unsigned char prevSide
= m_mouseSide
;
4236 int curPropHoverY
= y
- (y
% ih
);
4238 // On which item it hovers
4239 if ( ( !m_propHover
)
4241 ( m_propHover
&& ( sy
< m_propHoverY
|| sy
>= (m_propHoverY
+ih
) ) )
4244 // Mouse moves on another property
4246 m_propHover
= DoGetItemAtY(y
);
4247 m_propHoverY
= curPropHoverY
;
4250 SendEvent( wxEVT_PG_HIGHLIGHTED
, m_propHover
);
4253 #if wxPG_SUPPORT_TOOLTIPS
4254 // Store which side we are on
4256 if ( columnHit
== 1 )
4258 else if ( columnHit
== 0 )
4262 // If tooltips are enabled, show label or value as a tip
4263 // in case it doesn't otherwise show in full length.
4265 if ( m_windowStyle
& wxPG_TOOLTIPS
)
4267 wxToolTip
* tooltip
= m_canvas
->GetToolTip();
4269 if ( m_propHover
!= prevHover
|| prevSide
!= m_mouseSide
)
4271 if ( m_propHover
&& !m_propHover
->IsCategory() )
4274 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS
)
4276 // Show help string as a tooltip
4277 wxString tipString
= m_propHover
->GetHelpString();
4279 SetToolTip(tipString
);
4283 // Show cropped value string as a tooltip
4287 if ( m_mouseSide
== 1 )
4289 tipString
= m_propHover
->m_label
;
4290 space
= splitterX
-m_marginWidth
-3;
4292 else if ( m_mouseSide
== 2 )
4294 tipString
= m_propHover
->GetDisplayedString();
4296 space
= m_width
- splitterX
;
4297 if ( m_propHover
->m_flags
& wxPG_PROP_CUSTOMIMAGE
)
4298 space
-= wxPG_CUSTOM_IMAGE_WIDTH
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
4304 GetTextExtent( tipString
, &tw
, &th
, 0, 0, &m_font
);
4307 SetToolTip( tipString
);
4314 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4315 m_canvas
->SetToolTip( m_emptyString
);
4317 m_canvas
->SetToolTip( NULL
);
4328 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4329 m_canvas
->SetToolTip( m_emptyString
);
4331 m_canvas
->SetToolTip( NULL
);
4339 if ( splitterHit
== -1 ||
4341 HasFlag(wxPG_STATIC_SPLITTER
) )
4343 // hovering on something else
4344 if ( m_curcursor
!= wxCURSOR_ARROW
)
4345 CustomSetCursor( wxCURSOR_ARROW
);
4349 // Do not allow splitter cursor on caption items.
4350 // (also not if we were dragging and its started
4351 // outside the splitter region)
4354 !m_propHover
->IsCategory() &&
4358 // hovering on splitter
4360 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4361 // reliably detected.
4362 //if ( m_curcursor != wxCURSOR_SIZEWE )
4363 CustomSetCursor( wxCURSOR_SIZEWE
, true );
4369 // hovering on something else
4370 if ( m_curcursor
!= wxCURSOR_ARROW
)
4371 CustomSetCursor( wxCURSOR_ARROW
);
4378 // -----------------------------------------------------------------------
4380 // Also handles Leaving event
4381 bool wxPropertyGrid::HandleMouseUp( int x
, unsigned int WXUNUSED(y
),
4382 wxMouseEvent
&WXUNUSED(event
) )
4384 wxPropertyGridPageState
* state
= m_pState
;
4388 int splitterHitOffset
;
4389 state
->HitTestH( x
, &splitterHit
, &splitterHitOffset
);
4391 // No event type check - basicly calling this method should
4392 // just stop dragging.
4393 // Left up after dragged?
4394 if ( m_dragStatus
>= 1 )
4397 // End Splitter Dragging
4399 // DO NOT ENABLE FOLLOWING LINE!
4400 // (it is only here as a reminder to not to do it)
4403 // Disable splitter auto-centering
4404 m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
4406 // This is necessary to return cursor
4407 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
4409 m_canvas
->ReleaseMouse();
4410 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
4413 // Set back the default cursor, if necessary
4414 if ( splitterHit
== -1 ||
4417 CustomSetCursor( wxCURSOR_ARROW
);
4422 // Control background needs to be cleared
4423 if ( !(m_iFlags
& wxPG_FL_PRIMARY_FILLS_ENTIRE
) && m_selected
)
4424 DrawItem( m_selected
);
4428 m_wndEditor
->Show ( true );
4431 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4432 // Fixes button disappearance bug
4434 m_wndEditor2
->Show ( true );
4437 // This clears the focus.
4438 m_editorFocused
= 0;
4444 // -----------------------------------------------------------------------
4446 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent
& event
, int* px
, int* py
)
4448 int splitterX
= GetSplitterPosition();
4451 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4455 wxWindow
* wnd
= GetEditorControl();
4457 // Hide popup on clicks
4458 if ( event
.GetEventType() != wxEVT_MOTION
)
4459 if ( wnd
&& wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
4461 ((wxOwnerDrawnComboBox
*)wnd
)->HidePopup();
4467 if ( wnd
== (wxWindow
*) NULL
|| m_dragStatus
||
4469 ux
<= (splitterX
+ wxPG_SPLITTERX_DETECTMARGIN2
) ||
4470 ux
>= (r
.x
+r
.width
) ||
4472 event
.m_y
>= (r
.y
+r
.height
)
4482 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4487 // -----------------------------------------------------------------------
4489 void wxPropertyGrid::OnMouseClick( wxMouseEvent
&event
)
4492 if ( OnMouseCommon( event
, &x
, &y
) )
4494 HandleMouseClick(x
,y
,event
);
4499 // -----------------------------------------------------------------------
4501 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent
&event
)
4504 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4505 HandleMouseRightClick(x
,y
,event
);
4509 // -----------------------------------------------------------------------
4511 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent
&event
)
4513 // Always run standard mouse-down handler as well
4514 OnMouseClick(event
);
4517 CalcUnscrolledPosition( event
.m_x
, event
.m_y
, &x
, &y
);
4518 HandleMouseDoubleClick(x
,y
,event
);
4522 // -----------------------------------------------------------------------
4524 void wxPropertyGrid::OnMouseMove( wxMouseEvent
&event
)
4527 if ( OnMouseCommon( event
, &x
, &y
) )
4529 HandleMouseMove(x
,y
,event
);
4534 // -----------------------------------------------------------------------
4536 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent
& WXUNUSED(event
) )
4538 // Called when mouse moves in the empty space below the properties.
4539 CustomSetCursor( wxCURSOR_ARROW
);
4542 // -----------------------------------------------------------------------
4544 void wxPropertyGrid::OnMouseUp( wxMouseEvent
&event
)
4547 if ( OnMouseCommon( event
, &x
, &y
) )
4549 HandleMouseUp(x
,y
,event
);
4554 // -----------------------------------------------------------------------
4556 void wxPropertyGrid::OnMouseEntry( wxMouseEvent
&event
)
4558 // This may get called from child control as well, so event's
4559 // mouse position cannot be relied on.
4561 if ( event
.Entering() )
4563 if ( !(m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4565 // TODO: Fix this (detect parent and only do
4566 // cursor trick if it is a manager).
4567 wxASSERT( GetParent() );
4568 GetParent()->SetCursor(wxNullCursor
);
4570 m_iFlags
|= wxPG_FL_MOUSE_INSIDE
;
4573 GetParent()->SetCursor(wxNullCursor
);
4575 else if ( event
.Leaving() )
4577 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4578 m_canvas
->SetCursor( wxNullCursor
);
4580 // Get real cursor position
4581 wxPoint pt
= ScreenToClient(::wxGetMousePosition());
4583 if ( ( pt
.x
<= 0 || pt
.y
<= 0 || pt
.x
>= m_width
|| pt
.y
>= m_height
) )
4586 if ( (m_iFlags
& wxPG_FL_MOUSE_INSIDE
) )
4588 m_iFlags
&= ~(wxPG_FL_MOUSE_INSIDE
);
4592 wxPropertyGrid::HandleMouseUp ( -1, 10000, event
);
4600 // -----------------------------------------------------------------------
4602 // Common code used by various OnMouseXXXChild methods.
4603 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent
&event
, int* px
, int *py
)
4605 wxWindow
* topCtrlWnd
= (wxWindow
*)event
.GetEventObject();
4606 wxASSERT( topCtrlWnd
);
4608 event
.GetPosition(&x
,&y
);
4610 int splitterX
= GetSplitterPosition();
4612 wxRect r
= topCtrlWnd
->GetRect();
4613 if ( !m_dragStatus
&&
4614 x
> (splitterX
-r
.x
+wxPG_SPLITTERX_DETECTMARGIN2
) &&
4615 y
>= 0 && y
< r
.height \
4618 if ( m_curcursor
!= wxCURSOR_ARROW
) CustomSetCursor ( wxCURSOR_ARROW
);
4623 CalcUnscrolledPosition( event
.m_x
+ r
.x
, event
.m_y
+ r
.y
, \
4630 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent
&event
)
4633 if ( OnMouseChildCommon(event
,&x
,&y
) )
4635 bool res
= HandleMouseClick(x
,y
,event
);
4636 if ( !res
) event
.Skip();
4640 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent
&event
)
4643 wxASSERT( m_wndEditor
);
4644 // These coords may not be exact (about +-2),
4645 // but that should not matter (right click is about item, not position).
4646 wxPoint pt
= m_wndEditor
->GetPosition();
4647 CalcUnscrolledPosition( event
.m_x
+ pt
.x
, event
.m_y
+ pt
.y
, &x
, &y
);
4648 wxASSERT( m_selected
);
4649 m_propHover
= m_selected
;
4650 bool res
= HandleMouseRightClick(x
,y
,event
);
4651 if ( !res
) event
.Skip();
4654 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent
&event
)
4657 if ( OnMouseChildCommon(event
,&x
,&y
) )
4659 bool res
= HandleMouseMove(x
,y
,event
);
4660 if ( !res
) event
.Skip();
4664 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent
&event
)
4667 if ( OnMouseChildCommon(event
,&x
,&y
) )
4669 bool res
= HandleMouseUp(x
,y
,event
);
4670 if ( !res
) event
.Skip();
4674 // -----------------------------------------------------------------------
4675 // wxPropertyGrid keyboard event handling
4676 // -----------------------------------------------------------------------
4678 int wxPropertyGrid::KeyEventToActions(wxKeyEvent
&event
, int* pSecond
) const
4680 // Translates wxKeyEvent to wxPG_ACTION_XXX
4682 int keycode
= event
.GetKeyCode();
4683 int modifiers
= event
.GetModifiers();
4685 wxASSERT( !(modifiers
&~(0xFFFF)) );
4687 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4689 wxPGHashMapI2I::const_iterator it
= m_actionTriggers
.find(hashMapKey
);
4691 if ( it
== m_actionTriggers
.end() )
4696 int second
= (it
->second
>>16) & 0xFFFF;
4700 return (it
->second
& 0xFFFF);
4703 void wxPropertyGrid::AddActionTrigger( int action
, int keycode
, int modifiers
)
4705 wxASSERT( !(modifiers
&~(0xFFFF)) );
4707 int hashMapKey
= (keycode
& 0xFFFF) | ((modifiers
& 0xFFFF) << 16);
4709 wxPGHashMapI2I::iterator it
= m_actionTriggers
.find(hashMapKey
);
4711 if ( it
!= m_actionTriggers
.end() )
4713 // This key combination is already used
4715 // Can add secondary?
4716 wxASSERT_MSG( !(it
->second
&~(0xFFFF)),
4717 wxT("You can only add up to two separate actions per key combination.") );
4719 action
= it
->second
| (action
<<16);
4722 m_actionTriggers
[hashMapKey
] = action
;
4725 void wxPropertyGrid::ClearActionTriggers( int action
)
4727 wxPGHashMapI2I::iterator it
;
4729 for ( it
= m_actionTriggers
.begin(); it
!= m_actionTriggers
.end(); it
++ )
4731 if ( it
->second
== action
)
4733 m_actionTriggers
.erase(it
);
4738 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent
&event
, bool fromChild
)
4741 // Handles key event when editor control is not focused.
4744 wxASSERT( !m_frozen
);
4748 // Travelsal between items, collapsing/expanding, etc.
4749 int keycode
= event
.GetKeyCode();
4750 bool editorFocused
= IsEditorFocused();
4752 if ( keycode
== WXK_TAB
)
4754 wxWindow
* mainControl
;
4756 if ( HasInternalFlag(wxPG_FL_IN_MANAGER
) )
4757 mainControl
= GetParent();
4761 if ( !event
.ShiftDown() )
4763 if ( !editorFocused
&& m_wndEditor
)
4765 DoSelectProperty( m_selected
, wxPG_SEL_FOCUS
);
4769 // Tab traversal workaround for platforms on which
4770 // wxWindow::Navigate() may navigate into first child
4771 // instead of next sibling. Does not work perfectly
4772 // in every scenario (for instance, when property grid
4773 // is either first or last control).
4774 #if defined(__WXGTK__)
4775 wxWindow
* sibling
= mainControl
->GetNextSibling();
4777 sibling
->SetFocusFromKbd();
4779 Navigate(wxNavigationKeyEvent::IsForward
);
4785 if ( editorFocused
)
4791 #if defined(__WXGTK__)
4792 wxWindow
* sibling
= mainControl
->GetPrevSibling();
4794 sibling
->SetFocusFromKbd();
4796 Navigate(wxNavigationKeyEvent::IsBackward
);
4804 // Ignore Alt and Control when they are down alone
4805 if ( keycode
== WXK_ALT
||
4806 keycode
== WXK_CONTROL
)
4813 int action
= KeyEventToActions(event
, &secondAction
);
4815 if ( editorFocused
&& action
== wxPG_ACTION_CANCEL_EDIT
)
4818 // Esc cancels any changes
4819 if ( IsEditorsValueModified() )
4821 EditorsValueWasNotModified();
4823 // Update the control as well
4824 m_selected
->GetEditorClass()->SetControlStringValue( m_selected
,
4826 m_selected
->GetDisplayedString() );
4829 OnValidationFailureReset(m_selected
);
4835 // Except for TAB and ESC, handle child control events in child control
4842 bool wasHandled
= false;
4847 if ( ButtonTriggerKeyTest(action
, event
) )
4850 wxPGProperty
* p
= m_selected
;
4852 // Travel and expand/collapse
4855 if ( p
->GetChildCount() &&
4856 !(p
->m_flags
& wxPG_PROP_DISABLED
)
4859 if ( action
== wxPG_ACTION_COLLAPSE_PROPERTY
|| secondAction
== wxPG_ACTION_COLLAPSE_PROPERTY
)
4861 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Collapse(p
) )
4864 else if ( action
== wxPG_ACTION_EXPAND_PROPERTY
|| secondAction
== wxPG_ACTION_EXPAND_PROPERTY
)
4866 if ( (m_windowStyle
& wxPG_HIDE_MARGIN
) || Expand(p
) )
4873 if ( action
== wxPG_ACTION_PREV_PROPERTY
|| secondAction
== wxPG_ACTION_PREV_PROPERTY
)
4877 else if ( action
== wxPG_ACTION_NEXT_PROPERTY
|| secondAction
== wxPG_ACTION_NEXT_PROPERTY
)
4883 if ( selectDir
>= -1 )
4885 p
= wxPropertyGridIterator::OneStep( m_pState
, wxPG_ITERATE_VISIBLE
, p
, selectDir
);
4887 DoSelectProperty(p
);
4893 // If nothing was selected, select the first item now
4894 // (or navigate out of tab).
4895 if ( action
!= wxPG_ACTION_CANCEL_EDIT
&& secondAction
!= wxPG_ACTION_CANCEL_EDIT
)
4897 wxPGProperty
* p
= wxPropertyGridInterface::GetFirst();
4898 if ( p
) DoSelectProperty(p
);
4907 // -----------------------------------------------------------------------
4909 void wxPropertyGrid::OnKey( wxKeyEvent
&event
)
4911 HandleKeyEvent(event
, false);
4914 // -----------------------------------------------------------------------
4916 bool wxPropertyGrid::ButtonTriggerKeyTest( int action
, wxKeyEvent
& event
)
4921 action
= KeyEventToActions(event
, &secondAction
);
4924 // Does the keycode trigger button?
4925 if ( action
== wxPG_ACTION_PRESS_BUTTON
&&
4928 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, m_wndEditor2
->GetId());
4929 GetEventHandler()->AddPendingEvent(evt
);
4936 // -----------------------------------------------------------------------
4938 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent
&event
)
4940 HandleKeyEvent(event
, true);
4943 // -----------------------------------------------------------------------
4944 // wxPropertyGrid miscellaneous event handling
4945 // -----------------------------------------------------------------------
4947 void wxPropertyGrid::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
4950 // Check if the focus is in this control or one of its children
4951 wxWindow
* newFocused
= wxWindow::FindFocus();
4953 if ( newFocused
!= m_curFocused
)
4954 HandleFocusChange( newFocused
);
4957 bool wxPropertyGrid::IsEditorFocused() const
4959 wxWindow
* focus
= wxWindow::FindFocus();
4961 if ( focus
== m_wndEditor
|| focus
== m_wndEditor2
||
4962 focus
== GetEditorControl() )
4968 // Called by focus event handlers. newFocused is the window that becomes focused.
4969 void wxPropertyGrid::HandleFocusChange( wxWindow
* newFocused
)
4971 unsigned int oldFlags
= m_iFlags
;
4973 m_iFlags
&= ~(wxPG_FL_FOCUSED
);
4975 wxWindow
* parent
= newFocused
;
4977 // This must be one of nextFocus' parents.
4980 // Use m_eventObject, which is either wxPropertyGrid or
4981 // wxPropertyGridManager, as appropriate.
4982 if ( parent
== m_eventObject
)
4984 m_iFlags
|= wxPG_FL_FOCUSED
;
4987 parent
= parent
->GetParent();
4990 m_curFocused
= newFocused
;
4992 if ( (m_iFlags
& wxPG_FL_FOCUSED
) !=
4993 (oldFlags
& wxPG_FL_FOCUSED
) )
4995 if ( !(m_iFlags
& wxPG_FL_FOCUSED
) )
4997 // Need to store changed value
4998 CommitChangesFromEditor();
5004 // Preliminary code for tab-order respecting
5005 // tab-traversal (but should be moved to
5008 wxWindow* prevFocus = event.GetWindow();
5009 wxWindow* useThis = this;
5010 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5011 useThis = GetParent();
5014 prevFocus->GetParent() == useThis->GetParent() )
5016 wxList& children = useThis->GetParent()->GetChildren();
5018 wxNode* node = children.Find(prevFocus);
5020 if ( node->GetNext() &&
5021 useThis == node->GetNext()->GetData() )
5022 DoSelectProperty(GetFirst());
5023 else if ( node->GetPrevious () &&
5024 useThis == node->GetPrevious()->GetData() )
5025 DoSelectProperty(GetLastProperty());
5032 if ( m_selected
&& (m_iFlags
& wxPG_FL_INITIALIZED
) )
5033 DrawItem( m_selected
);
5037 void wxPropertyGrid::OnFocusEvent( wxFocusEvent
& event
)
5039 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
5040 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5041 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5042 //else if ( event.GetWindow() )
5044 HandleFocusChange(event
.GetWindow());
5049 // -----------------------------------------------------------------------
5051 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent
& event
)
5053 HandleFocusChange((wxWindow
*)event
.GetEventObject());
5056 // event.Skip() being commented out is aworkaround for bug reported
5057 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5061 // -----------------------------------------------------------------------
5063 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent
&event
)
5065 m_iFlags
|= wxPG_FL_SCROLLED
;
5070 // -----------------------------------------------------------------------
5072 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent
& WXUNUSED(event
) )
5074 if ( m_iFlags
& wxPG_FL_MOUSE_CAPTURED
)
5076 m_iFlags
&= ~(wxPG_FL_MOUSE_CAPTURED
);
5080 // -----------------------------------------------------------------------
5081 // Property editor related functions
5082 // -----------------------------------------------------------------------
5084 // noDefCheck = true prevents infinite recursion.
5085 wxPGEditor
* wxPropertyGrid::RegisterEditorClass( wxPGEditor
* editorClass
,
5088 wxASSERT( editorClass
);
5090 if ( !noDefCheck
&& wxPGGlobalVars
->m_mapEditorClasses
.empty() )
5091 RegisterDefaultEditors();
5093 wxString name
= editorClass
->GetName();
5095 // Existing editor under this name?
5096 wxPGHashMapS2P::iterator vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5098 if ( vt_it
!= wxPGGlobalVars
->m_mapEditorClasses
.end() )
5100 // If this name was already used, try class name.
5101 name
= editorClass
->GetClassInfo()->GetClassName();
5102 vt_it
= wxPGGlobalVars
->m_mapEditorClasses
.find(name
);
5105 wxCHECK_MSG( vt_it
== wxPGGlobalVars
->m_mapEditorClasses
.end(),
5106 (wxPGEditor
*) vt_it
->second
,
5107 "Editor with given name was already registered" );
5109 wxPGGlobalVars
->m_mapEditorClasses
[name
] = (void*)editorClass
;
5114 // Use this in RegisterDefaultEditors.
5115 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5116 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5118 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5119 new wxPG##EDITOR##Editor, true ); \
5122 // Registers all default editor classes
5123 void wxPropertyGrid::RegisterDefaultEditors()
5125 wxPGRegisterDefaultEditorClass( TextCtrl
);
5126 wxPGRegisterDefaultEditorClass( Choice
);
5127 wxPGRegisterDefaultEditorClass( ComboBox
);
5128 wxPGRegisterDefaultEditorClass( TextCtrlAndButton
);
5129 #if wxPG_INCLUDE_CHECKBOX
5130 wxPGRegisterDefaultEditorClass( CheckBox
);
5132 wxPGRegisterDefaultEditorClass( ChoiceAndButton
);
5134 // Register SpinCtrl etc. editors before use
5135 RegisterAdditionalEditors();
5138 // -----------------------------------------------------------------------
5139 // wxPGStringTokenizer
5140 // Needed to handle C-style string lists (e.g. "str1" "str2")
5141 // -----------------------------------------------------------------------
5143 wxPGStringTokenizer::wxPGStringTokenizer( const wxString
& str
, wxChar delimeter
)
5144 : m_str(&str
), m_curPos(str
.begin()), m_delimeter(delimeter
)
5148 wxPGStringTokenizer::~wxPGStringTokenizer()
5152 bool wxPGStringTokenizer::HasMoreTokens()
5154 const wxString
& str
= *m_str
;
5156 wxString::const_iterator i
= m_curPos
;
5158 wxUniChar delim
= m_delimeter
;
5160 wxUniChar prev_a
= wxT('\0');
5162 bool inToken
= false;
5164 while ( i
!= str
.end() )
5173 m_readyToken
.clear();
5178 if ( prev_a
!= wxT('\\') )
5182 if ( a
!= wxT('\\') )
5202 m_curPos
= str
.end();
5210 wxString
wxPGStringTokenizer::GetNextToken()
5212 return m_readyToken
;
5215 // -----------------------------------------------------------------------
5217 // -----------------------------------------------------------------------
5219 wxPGChoiceEntry::wxPGChoiceEntry()
5220 : wxPGCell(), m_value(wxPG_INVALID_VALUE
)
5224 // -----------------------------------------------------------------------
5226 // -----------------------------------------------------------------------
5228 wxPGChoicesData::wxPGChoicesData()
5233 wxPGChoicesData::~wxPGChoicesData()
5238 void wxPGChoicesData::Clear()
5243 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData
* data
)
5245 wxASSERT( m_items
.size() == 0 );
5247 m_items
= data
->m_items
;
5250 wxPGChoiceEntry
& wxPGChoicesData::Insert( int index
,
5251 const wxPGChoiceEntry
& item
)
5253 wxVector
<wxPGChoiceEntry
>::iterator it
;
5257 index
= (int) m_items
.size();
5261 it
= m_items
.begin() + index
;
5264 m_items
.insert(it
, item
);
5266 wxPGChoiceEntry
& ownEntry
= m_items
[index
];
5268 // Need to fix value?
5269 if ( ownEntry
.GetValue() == wxPG_INVALID_VALUE
)
5270 ownEntry
.SetValue(index
);
5275 // -----------------------------------------------------------------------
5277 // -----------------------------------------------------------------------
5279 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, int value
)
5283 wxPGChoiceEntry
entry(label
, value
);
5284 return m_data
->Insert( -1, entry
);
5287 // -----------------------------------------------------------------------
5289 wxPGChoiceEntry
& wxPGChoices::Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
)
5293 wxPGChoiceEntry
entry(label
, value
);
5294 entry
.SetBitmap(bitmap
);
5295 return m_data
->Insert( -1, entry
);
5298 // -----------------------------------------------------------------------
5300 wxPGChoiceEntry
& wxPGChoices::Insert( const wxPGChoiceEntry
& entry
, int index
)
5303 return m_data
->Insert( index
, entry
);
5306 // -----------------------------------------------------------------------
5308 wxPGChoiceEntry
& wxPGChoices::Insert( const wxString
& label
, int index
, int value
)
5312 wxPGChoiceEntry
entry(label
, value
);
5313 return m_data
->Insert( index
, entry
);
5316 // -----------------------------------------------------------------------
5318 wxPGChoiceEntry
& wxPGChoices::AddAsSorted( const wxString
& label
, int value
)
5324 while ( index
< GetCount() )
5326 int cmpRes
= GetLabel(index
).Cmp(label
);
5332 wxPGChoiceEntry
entry(label
, value
);
5333 return m_data
->Insert( index
, entry
);
5336 // -----------------------------------------------------------------------
5338 void wxPGChoices::Add( const wxChar
** labels
, const ValArrItem
* values
)
5342 unsigned int itemcount
= 0;
5343 const wxChar
** p
= &labels
[0];
5344 while ( *p
) { p
++; itemcount
++; }
5347 for ( i
= 0; i
< itemcount
; i
++ )
5352 wxPGChoiceEntry
entry(labels
[i
], value
);
5353 m_data
->Insert( i
, entry
);
5357 // -----------------------------------------------------------------------
5359 void wxPGChoices::Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
)
5364 unsigned int itemcount
= arr
.size();
5366 for ( i
= 0; i
< itemcount
; i
++ )
5369 if ( &arrint
&& arrint
.size() )
5371 wxPGChoiceEntry
entry(arr
[i
], value
);
5372 m_data
->Insert( i
, entry
);
5376 // -----------------------------------------------------------------------
5378 void wxPGChoices::RemoveAt(size_t nIndex
, size_t count
)
5380 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
5381 m_data
->m_items
.erase(m_data
->m_items
.begin()+nIndex
,
5382 m_data
->m_items
.begin()+nIndex
+count
);
5385 // -----------------------------------------------------------------------
5387 int wxPGChoices::Index( const wxString
& str
) const
5392 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5394 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5395 if ( entry
.HasText() && entry
.GetText() == str
)
5402 // -----------------------------------------------------------------------
5404 int wxPGChoices::Index( int val
) const
5409 for ( i
=0; i
< m_data
->GetCount(); i
++ )
5411 const wxPGChoiceEntry
& entry
= m_data
->Item(i
);
5412 if ( entry
.GetValue() == val
)
5419 // -----------------------------------------------------------------------
5421 wxArrayString
wxPGChoices::GetLabels() const
5426 if ( this && IsOk() )
5427 for ( i
=0; i
<GetCount(); i
++ )
5428 arr
.push_back(GetLabel(i
));
5433 // -----------------------------------------------------------------------
5435 wxArrayInt
wxPGChoices::GetValuesForStrings( const wxArrayString
& strings
) const
5442 for ( i
=0; i
< strings
.size(); i
++ )
5444 int index
= Index(strings
[i
]);
5446 arr
.Add(GetValue(index
));
5448 arr
.Add(wxPG_INVALID_VALUE
);
5455 // -----------------------------------------------------------------------
5457 wxArrayInt
wxPGChoices::GetIndicesForStrings( const wxArrayString
& strings
,
5458 wxArrayString
* unmatched
) const
5465 for ( i
=0; i
< strings
.size(); i
++ )
5467 const wxString
& str
= strings
[i
];
5468 int index
= Index(str
);
5471 else if ( unmatched
)
5472 unmatched
->Add(str
);
5479 // -----------------------------------------------------------------------
5481 void wxPGChoices::AssignData( wxPGChoicesData
* data
)
5485 if ( data
!= wxPGChoicesEmptyData
)
5492 // -----------------------------------------------------------------------
5494 void wxPGChoices::Init()
5496 m_data
= wxPGChoicesEmptyData
;
5499 // -----------------------------------------------------------------------
5501 void wxPGChoices::Free()
5503 if ( m_data
!= wxPGChoicesEmptyData
)
5506 m_data
= wxPGChoicesEmptyData
;
5510 // -----------------------------------------------------------------------
5511 // wxPropertyGridEvent
5512 // -----------------------------------------------------------------------
5514 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent
, wxCommandEvent
)
5517 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED
)
5518 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING
)
5519 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED
)
5520 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED
)
5521 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK
)
5522 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED
)
5523 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED
)
5524 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED
)
5525 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK
)
5528 // -----------------------------------------------------------------------
5530 void wxPropertyGridEvent::Init()
5532 m_validationInfo
= NULL
;
5534 m_wasVetoed
= false;
5537 // -----------------------------------------------------------------------
5539 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType
, int id
)
5540 : wxCommandEvent(commandType
,id
)
5546 // -----------------------------------------------------------------------
5548 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent
& event
)
5549 : wxCommandEvent(event
)
5551 m_eventType
= event
.GetEventType();
5552 m_eventObject
= event
.m_eventObject
;
5554 m_property
= event
.m_property
;
5555 m_validationInfo
= event
.m_validationInfo
;
5556 m_canVeto
= event
.m_canVeto
;
5557 m_wasVetoed
= event
.m_wasVetoed
;
5560 // -----------------------------------------------------------------------
5562 wxPropertyGridEvent::~wxPropertyGridEvent()
5566 // -----------------------------------------------------------------------
5568 wxEvent
* wxPropertyGridEvent::Clone() const
5570 return new wxPropertyGridEvent( *this );
5573 // -----------------------------------------------------------------------
5574 // wxPropertyGridPopulator
5575 // -----------------------------------------------------------------------
5577 wxPropertyGridPopulator::wxPropertyGridPopulator()
5581 wxPGGlobalVars
->m_offline
++;
5584 // -----------------------------------------------------------------------
5586 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState
* state
)
5589 m_propHierarchy
.clear();
5592 // -----------------------------------------------------------------------
5594 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid
* pg
)
5600 // -----------------------------------------------------------------------
5602 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5605 // Free unused sets of choices
5606 wxPGHashMapS2P::iterator it
;
5608 for( it
= m_dictIdChoices
.begin(); it
!= m_dictIdChoices
.end(); ++it
)
5610 wxPGChoicesData
* data
= (wxPGChoicesData
*) it
->second
;
5617 m_pg
->GetPanel()->Refresh();
5619 wxPGGlobalVars
->m_offline
--;
5622 // -----------------------------------------------------------------------
5624 wxPGProperty
* wxPropertyGridPopulator::Add( const wxString
& propClass
,
5625 const wxString
& propLabel
,
5626 const wxString
& propName
,
5627 const wxString
* propValue
,
5628 wxPGChoices
* pChoices
)
5630 wxClassInfo
* classInfo
= wxClassInfo::FindClass(propClass
);
5631 wxPGProperty
* parent
= GetCurParent();
5633 if ( parent
->HasFlag(wxPG_PROP_AGGREGATE
) )
5635 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent
->GetName().c_str()));
5639 if ( !classInfo
|| !classInfo
->IsKindOf(CLASSINFO(wxPGProperty
)) )
5641 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass
.c_str()));
5645 wxPGProperty
* property
= (wxPGProperty
*) classInfo
->CreateObject();
5647 property
->SetLabel(propLabel
);
5648 property
->DoSetName(propName
);
5650 if ( pChoices
&& pChoices
->IsOk() )
5651 property
->SetChoices(*pChoices
);
5653 m_state
->DoInsert(parent
, -1, property
);
5656 property
->SetValueFromString( *propValue
, wxPG_FULL_VALUE
|
5657 wxPG_PROGRAMMATIC_VALUE
);
5662 // -----------------------------------------------------------------------
5664 void wxPropertyGridPopulator::AddChildren( wxPGProperty
* property
)
5666 m_propHierarchy
.push_back(property
);
5667 DoScanForChildren();
5668 m_propHierarchy
.pop_back();
5671 // -----------------------------------------------------------------------
5673 wxPGChoices
wxPropertyGridPopulator::ParseChoices( const wxString
& choicesString
,
5674 const wxString
& idString
)
5676 wxPGChoices choices
;
5679 if ( choicesString
[0] == wxT('@') )
5681 wxString ids
= choicesString
.substr(1);
5682 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(ids
);
5683 if ( it
== m_dictIdChoices
.end() )
5684 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids
.c_str()));
5686 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5691 if ( idString
.length() )
5693 wxPGHashMapS2P::iterator it
= m_dictIdChoices
.find(idString
);
5694 if ( it
!= m_dictIdChoices
.end() )
5696 choices
.AssignData((wxPGChoicesData
*)it
->second
);
5703 // Parse choices string
5704 wxString::const_iterator it
= choicesString
.begin();
5708 bool labelValid
= false;
5710 for ( ; it
!= choicesString
.end(); it
++ )
5716 if ( c
== wxT('"') )
5721 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5722 choices
.Add(label
, l
);
5725 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5730 else if ( c
== wxT('=') )
5737 else if ( state
== 2 && (wxIsalnum(c
) || c
== wxT('x')) )
5744 if ( c
== wxT('"') )
5757 if ( !value
.ToLong(&l
, 0) ) l
= wxPG_INVALID_VALUE
;
5758 choices
.Add(label
, l
);
5761 if ( !choices
.IsOk() )
5763 choices
.EnsureData();
5767 if ( idString
.length() )
5768 m_dictIdChoices
[idString
] = choices
.GetData();
5775 // -----------------------------------------------------------------------
5777 bool wxPropertyGridPopulator::ToLongPCT( const wxString
& s
, long* pval
, long max
)
5779 if ( s
.Last() == wxT('%') )
5781 wxString s2
= s
.substr(0,s
.length()-1);
5783 if ( s2
.ToLong(&val
, 10) )
5785 *pval
= (val
*max
)/100;
5791 return s
.ToLong(pval
, 10);
5794 // -----------------------------------------------------------------------
5796 bool wxPropertyGridPopulator::AddAttribute( const wxString
& name
,
5797 const wxString
& type
,
5798 const wxString
& value
)
5800 int l
= m_propHierarchy
.size();
5804 wxPGProperty
* p
= m_propHierarchy
[l
-1];
5805 wxString valuel
= value
.Lower();
5808 if ( type
.length() == 0 )
5813 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5815 else if ( valuel
== wxT("false") || valuel
== wxT("no") || valuel
== wxT("0") )
5817 else if ( value
.ToLong(&v
, 0) )
5824 if ( type
== wxT("string") )
5828 else if ( type
== wxT("int") )
5831 value
.ToLong(&v
, 0);
5834 else if ( type
== wxT("bool") )
5836 if ( valuel
== wxT("true") || valuel
== wxT("yes") || valuel
== wxT("1") )
5843 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type
.c_str()));
5848 p
->SetAttribute( name
, variant
);
5853 // -----------------------------------------------------------------------
5855 void wxPropertyGridPopulator::ProcessError( const wxString
& msg
)
5857 wxLogError(_("Error in resource: %s"),msg
.c_str());
5860 // -----------------------------------------------------------------------
5862 #endif // wxUSE_PROPGRID