1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/manager.cpp
3 // Purpose: wxPropertyGridManager
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"
33 #include "wx/cursor.h"
34 #include "wx/settings.h"
35 #include "wx/textctrl.h"
37 #include "wx/statusbr.h"
41 // This define is necessary to prevent macro clearing
42 #define __wxPG_SOURCE_FILE__
44 #include <wx/propgrid/propgrid.h>
46 #include <wx/propgrid/manager.h>
49 #define wxPG_MAN_ALTERNATE_BASE_ID 11249 // Needed for wxID_ANY madnesss
52 // -----------------------------------------------------------------------
54 // For wxMSW cursor consistency, we must do mouse capturing even
55 // when using custom controls
57 #define BEGIN_MOUSE_CAPTURE \
58 if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) ) \
61 m_iFlags |= wxPG_FL_MOUSE_CAPTURED; \
64 #define END_MOUSE_CAPTURE \
65 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) \
68 m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED); \
71 // -----------------------------------------------------------------------
72 // wxPropertyGridManager
73 // -----------------------------------------------------------------------
75 const wxChar
*wxPropertyGridManagerNameStr
= wxT("wxPropertyGridManager");
78 // Categoric Mode Icon
79 static const char* gs_xpm_catmode
[] = {
104 // Alphabetic Mode Icon
105 static const char* gs_xpm_noncatmode
[] = {
130 // Default Page Icon.
131 static const char* gs_xpm_defpage
[] = {
156 #define GETPAGESTATE(page) ((wxPropertyGridPage*)m_arrPages.Item(page))->GetStatePtr()
158 // -----------------------------------------------------------------------
159 // wxPropertyGridPage
160 // -----------------------------------------------------------------------
163 IMPLEMENT_CLASS(wxPropertyGridPage
, wxEvtHandler
)
166 BEGIN_EVENT_TABLE(wxPropertyGridPage
, wxEvtHandler
)
170 wxPropertyGridPage::wxPropertyGridPage()
171 : wxEvtHandler(), wxPropertyGridInterface(), wxPropertyGridPageState()
173 m_pState
= this; // wxPropertyGridInterface to point to State
178 wxPropertyGridPage::~wxPropertyGridPage()
182 void wxPropertyGridPage::Clear()
184 GetStatePtr()->DoClear();
187 wxSize
wxPropertyGridPage::FitColumns()
189 wxSize sz
= DoFitColumns();
193 void wxPropertyGridPage::RefreshProperty( wxPGProperty
* p
)
196 m_manager
->RefreshProperty(p
);
199 void wxPropertyGridPage::OnShow()
203 void wxPropertyGridPage::SetSplitterPosition( int splitterPos
, int col
)
205 wxPropertyGrid
* pg
= GetGrid();
206 if ( pg
->GetState() == this )
207 pg
->SetSplitterPosition(splitterPos
);
209 DoSetSplitterPosition(splitterPos
, col
, false);
212 void wxPropertyGridPage::DoSetSplitterPosition( int pos
, int splitterColumn
, bool allPages
)
214 if ( allPages
&& m_manager
->GetPageCount() )
215 m_manager
->SetSplitterPosition( pos
, splitterColumn
);
217 DoSetSplitterPositionThisPage( pos
, splitterColumn
);
220 // -----------------------------------------------------------------------
221 // wxPropertyGridManager
222 // -----------------------------------------------------------------------
224 // Final default splitter y is client height minus this.
225 #define wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y 100
227 // -----------------------------------------------------------------------
229 IMPLEMENT_CLASS(wxPropertyGridManager
, wxPanel
)
231 #define ID_ADVTOOLBAR_OFFSET 1
232 #define ID_ADVHELPCAPTION_OFFSET 2
233 #define ID_ADVHELPCONTENT_OFFSET 3
234 #define ID_ADVBUTTON_OFFSET 4
235 #define ID_ADVTBITEMSBASE_OFFSET 5 // Must be last.
237 // -----------------------------------------------------------------------
239 BEGIN_EVENT_TABLE(wxPropertyGridManager
, wxPanel
)
240 EVT_MOTION(wxPropertyGridManager::OnMouseMove
)
241 EVT_SIZE(wxPropertyGridManager::OnResize
)
242 EVT_PAINT(wxPropertyGridManager::OnPaint
)
243 EVT_LEFT_DOWN(wxPropertyGridManager::OnMouseClick
)
244 EVT_LEFT_UP(wxPropertyGridManager::OnMouseUp
)
245 EVT_LEAVE_WINDOW(wxPropertyGridManager::OnMouseEntry
)
246 //EVT_ENTER_WINDOW(wxPropertyGridManager::OnMouseEntry)
249 // -----------------------------------------------------------------------
251 wxPropertyGridManager::wxPropertyGridManager()
257 // -----------------------------------------------------------------------
259 wxPropertyGridManager::wxPropertyGridManager( wxWindow
*parent
,
268 Create(parent
,id
,pos
,size
,style
,name
);
271 // -----------------------------------------------------------------------
273 bool wxPropertyGridManager::Create( wxWindow
*parent
,
281 bool res
= wxPanel::Create( parent
, id
, pos
, size
,
282 (style
&0xFFFF0000)|wxWANTS_CHARS
,
289 // -----------------------------------------------------------------------
292 // Initialize values to defaults
294 void wxPropertyGridManager::Init1()
297 //m_pPropGrid = (wxPropertyGrid*) NULL;
298 m_pPropGrid
= CreatePropertyGrid();
301 m_pToolbar
= (wxToolBar
*) NULL
;
303 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
304 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
306 m_emptyPage
= (wxPropertyGridPage
*) NULL
;
310 m_width
= m_height
= 0;
312 m_splitterHeight
= 5;
314 m_splitterY
= -1; // -1 causes default to be set.
316 m_nextDescBoxSize
= -1;
324 // -----------------------------------------------------------------------
326 // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager.
328 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxSIMPLE_BORDER| \
329 wxNO_FULL_REPAINT_ON_RESIZE| \
332 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxNO_BORDER| \
333 wxNO_FULL_REPAINT_ON_RESIZE| \
337 // Which flags can be passed to underlying wxPropertyGrid.
338 #define wxPG_MAN_PASS_FLAGS_MASK (0xFFF0|wxTAB_TRAVERSAL)
341 // Initialize after parent etc. set
343 void wxPropertyGridManager::Init2( int style
)
346 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
349 m_windowStyle
|= (style
&0x0000FFFF);
351 wxSize csz
= GetClientSize();
353 m_cursorSizeNS
= wxCursor(wxCURSOR_SIZENS
);
355 // Prepare the first page
356 // NB: But just prepare - you still need to call Add/InsertPage
357 // to actually add properties on it.
358 wxPropertyGridPage
* pd
= new wxPropertyGridPage();
359 pd
->m_isDefault
= true;
360 pd
->m_manager
= this;
361 wxPropertyGridPageState
* state
= pd
->GetStatePtr();
362 state
->m_pPropGrid
= m_pPropGrid
;
363 m_arrPages
.Add( (void*)pd
);
364 m_pPropGrid
->m_pState
= state
;
366 wxWindowID baseId
= GetId();
367 wxWindowID useId
= baseId
;
369 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
374 // Smaller controls on Mac
375 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
378 // Create propertygrid.
379 m_pPropGrid
->Create(this,baseId
,wxPoint(0,0),csz
,
380 (m_windowStyle
&wxPG_MAN_PASS_FLAGS_MASK
)
381 |wxPG_MAN_PROPGRID_FORCED_FLAGS
);
383 m_pPropGrid
->m_eventObject
= this;
385 m_pPropGrid
->SetId(useId
);
387 m_pPropGrid
->m_iFlags
|= wxPG_FL_IN_MANAGER
;
389 m_pState
= m_pPropGrid
->m_pState
;
391 m_pPropGrid
->SetExtraStyle(wxPG_EX_INIT_NOCAT
);
393 m_nextTbInd
= baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
396 // Connect to property grid onselect event.
397 // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython
398 // (see wxPropertyGridManager::ProcessEvent).
399 Connect(m_pPropGrid
->GetId()/*wxID_ANY*/,
401 wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect
) );
403 // Connect to toolbar button events.
404 Connect(baseId
+ID_ADVTBITEMSBASE_OFFSET
,baseId
+ID_ADVTBITEMSBASE_OFFSET
+50,
405 wxEVT_COMMAND_TOOL_CLICKED
,
406 wxCommandEventHandler(wxPropertyGridManager::OnToolbarClick
) );
408 // Optional initial controls.
411 m_iFlags
|= wxPG_FL_INITIALIZED
;
415 // -----------------------------------------------------------------------
417 wxPropertyGridManager::~wxPropertyGridManager()
421 m_pPropGrid
->DoSelectProperty(NULL
);
422 m_pPropGrid
->m_pState
= NULL
;
425 for ( i
=0; i
<m_arrPages
.GetCount(); i
++ )
427 delete (wxPropertyGridPage
*)m_arrPages
.Item(i
);
433 // -----------------------------------------------------------------------
435 wxPropertyGrid
* wxPropertyGridManager::CreatePropertyGrid() const
437 return new wxPropertyGrid();
440 // -----------------------------------------------------------------------
442 void wxPropertyGridManager::SetId( wxWindowID winid
)
444 wxWindow::SetId(winid
);
446 // TODO: Reconnect propgrid event handler(s).
448 m_pPropGrid
->SetId(winid
);
451 // -----------------------------------------------------------------------
453 wxSize
wxPropertyGridManager::DoGetBestSize() const
455 return wxSize(60,150);
458 // -----------------------------------------------------------------------
460 bool wxPropertyGridManager::SetFont( const wxFont
& font
)
462 bool res
= wxWindow::SetFont(font
);
463 m_pPropGrid
->SetFont(font
);
465 // TODO: Need to do caption recacalculations for other pages as well.
467 for ( i
=0; i
<m_arrPages
.GetCount(); i
++ )
469 wxPropertyGridPage
* page
= GetPage(i
);
471 if ( page
!= m_pPropGrid
->GetState() )
472 page
->CalculateFontAndBitmapStuff(-1);
478 // -----------------------------------------------------------------------
480 void wxPropertyGridManager::SetExtraStyle( long exStyle
)
482 wxWindow::SetExtraStyle( exStyle
);
483 m_pPropGrid
->SetExtraStyle( exStyle
& 0xFFFFF000 );
485 if ( (exStyle
& wxPG_EX_NO_FLAT_TOOLBAR
) && m_pToolbar
)
490 // -----------------------------------------------------------------------
492 void wxPropertyGridManager::Freeze()
494 m_pPropGrid
->Freeze();
498 // -----------------------------------------------------------------------
500 void wxPropertyGridManager::Thaw()
506 // -----------------------------------------------------------------------
508 void wxPropertyGridManager::SetWindowStyleFlag( long style
)
510 wxWindow::SetWindowStyleFlag( style
);
511 m_pPropGrid
->SetWindowStyleFlag( (m_pPropGrid
->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK
)) |
512 (style
&wxPG_MAN_PASS_FLAGS_MASK
) );
515 // -----------------------------------------------------------------------
517 // Actually shows given page.
518 bool wxPropertyGridManager::DoSelectPage( int index
)
520 // -1 means no page was selected
521 //wxASSERT( m_selPage >= 0 );
523 wxCHECK_MSG( index
>= -1 && index
< (int)GetPageCount(),
525 wxT("invalid page index") );
527 if ( m_selPage
== index
)
530 if ( m_pPropGrid
->m_selected
)
532 if ( !m_pPropGrid
->ClearSelection() )
536 wxPropertyGridPage
* prevPage
;
538 if ( m_selPage
>= 0 )
539 prevPage
= GetPage(m_selPage
);
541 prevPage
= m_emptyPage
;
543 wxPropertyGridPage
* nextPage
;
547 nextPage
= (wxPropertyGridPage
*)m_arrPages
.Item(index
);
555 m_emptyPage
= new wxPropertyGridPage();
556 m_emptyPage
->m_pPropGrid
= m_pPropGrid
;
559 nextPage
= m_emptyPage
;
562 m_iFlags
|= wxPG_FL_DESC_REFRESH_REQUIRED
;
564 m_pPropGrid
->SwitchState( nextPage
->GetStatePtr() );
566 m_pState
= m_pPropGrid
->m_pState
;
574 m_pToolbar
->ToggleTool( nextPage
->m_id
, true );
576 m_pToolbar
->ToggleTool( prevPage
->m_id
, false );
583 // -----------------------------------------------------------------------
585 // Changes page *and* set the target page for insertion operations.
586 void wxPropertyGridManager::SelectPage( int index
)
591 // -----------------------------------------------------------------------
593 int wxPropertyGridManager::GetPageByName( const wxString
& name
) const
596 for ( i
=0; i
<GetPageCount(); i
++ )
598 if ( ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->m_label
== name
)
604 // -----------------------------------------------------------------------
606 int wxPropertyGridManager::GetPageByState( const wxPropertyGridPageState
* pState
) const
611 for ( i
=0; i
<GetPageCount(); i
++ )
613 if ( pState
== ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->GetStatePtr() )
620 // -----------------------------------------------------------------------
622 const wxString
& wxPropertyGridManager::GetPageName( int index
) const
624 wxASSERT( index
>= 0 && index
< (int)GetPageCount() );
625 return ((wxPropertyGridPage
*)m_arrPages
.Item(index
))->m_label
;
628 // -----------------------------------------------------------------------
630 wxPropertyGridPageState
* wxPropertyGridManager::GetPageState( int page
) const
632 // Do not change this into wxCHECK because returning NULL is important
633 // for wxPropertyGridInterface page enumeration mechanics.
634 if ( page
>= (int)GetPageCount() )
639 return GETPAGESTATE(page
);
642 // -----------------------------------------------------------------------
644 void wxPropertyGridManager::Clear()
646 m_pPropGrid
->Freeze();
649 for ( i
=(int)GetPageCount()-1; i
>=0; i
-- )
653 m_nextTbInd
= m_baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
658 // -----------------------------------------------------------------------
660 void wxPropertyGridManager::ClearPage( int page
)
662 wxASSERT( page
>= 0 );
663 wxASSERT( page
< (int)GetPageCount() );
665 if ( page
>= 0 && page
< (int)GetPageCount() )
667 wxPropertyGridPageState
* state
= GETPAGESTATE(page
);
669 if ( state
== m_pPropGrid
->GetState() )
670 m_pPropGrid
->Clear();
676 // -----------------------------------------------------------------------
678 int wxPropertyGridManager::GetColumnCount( int page
) const
680 wxASSERT( page
>= -1 );
681 wxASSERT( page
< (int)GetPageCount() );
683 return GetPageState(page
)->GetColumnCount();
686 // -----------------------------------------------------------------------
688 void wxPropertyGridManager::SetColumnCount( int colCount
, int page
)
690 wxASSERT( page
>= -1 );
691 wxASSERT( page
< (int)GetPageCount() );
693 GetPageState(page
)->SetColumnCount( colCount
);
694 GetGrid()->Refresh();
696 // -----------------------------------------------------------------------
698 size_t wxPropertyGridManager::GetPageCount() const
700 if ( !(m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
) )
703 return m_arrPages
.GetCount();
706 // -----------------------------------------------------------------------
708 int wxPropertyGridManager::InsertPage( int index
, const wxString
& label
,
709 const wxBitmap
& bmp
, wxPropertyGridPage
* pageObj
)
712 index
= GetPageCount();
714 wxCHECK_MSG( (size_t)index
== GetPageCount(), -1,
715 wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
717 bool needInit
= true;
718 bool isPageInserted
= m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
? true : false;
720 wxASSERT( index
== 0 || isPageInserted
);
724 // No custom page object was given, so we will either re-use the default base
725 // page (if index==0), or create a new default page object.
726 if ( !isPageInserted
)
728 pageObj
= GetPage(0);
729 // Of course, if the base page was custom, we need to delete and
731 if ( !pageObj
->m_isDefault
)
734 pageObj
= new wxPropertyGridPage();
735 m_arrPages
[0] = pageObj
;
741 pageObj
= new wxPropertyGridPage();
743 pageObj
->m_isDefault
= true;
747 if ( !isPageInserted
)
749 // Initial page needs to be deleted and replaced
751 m_arrPages
[0] = pageObj
;
752 m_pPropGrid
->m_pState
= pageObj
->GetStatePtr();
756 wxPropertyGridPageState
* state
= pageObj
->GetStatePtr();
758 pageObj
->m_manager
= this;
762 state
->m_pPropGrid
= m_pPropGrid
;
763 state
->InitNonCatMode();
766 if ( label
.length() )
768 wxASSERT_MSG( !pageObj
->m_label
.length(),
769 wxT("If page label is given in constructor, empty label must be given in AddPage"));
770 pageObj
->m_label
= label
;
773 pageObj
->m_id
= m_nextTbInd
;
775 if ( isPageInserted
)
776 m_arrPages
.Add( (void*)pageObj
);
779 if ( m_windowStyle
& wxPG_TOOLBAR
)
784 if ( !(GetExtraStyle()&wxPG_EX_HIDE_PAGE_BUTTONS
) )
786 wxASSERT( m_pToolbar
);
788 // Add separator before first page.
789 if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) &&
790 m_pToolbar
->GetToolsCount() < 3 )
791 m_pToolbar
->AddSeparator();
793 if ( &bmp
!= &wxNullBitmap
)
794 m_pToolbar
->AddTool(m_nextTbInd
,label
,bmp
,label
,wxITEM_RADIO
);
795 //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
797 m_pToolbar
->AddTool(m_nextTbInd
,label
,wxBitmap( (const char**)gs_xpm_defpage
),
802 m_pToolbar
->Realize();
809 // If selected page was above the point of insertion, fix the current page index
810 if ( isPageInserted
)
812 if ( m_selPage
>= index
)
819 // Set this value only when adding the first page
825 m_iFlags
|= wxPG_MAN_FL_PAGE_INSERTED
;
827 wxASSERT( pageObj
->GetGrid() );
832 // -----------------------------------------------------------------------
834 bool wxPropertyGridManager::IsAnyModified() const
837 for ( i
=0; i
<GetPageCount(); i
++ )
839 if ( ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->GetStatePtr()->m_anyModified
)
845 // -----------------------------------------------------------------------
847 bool wxPropertyGridManager::IsPageModified( size_t index
) const
849 if ( ((wxPropertyGridPage
*)m_arrPages
.Item(index
))->GetStatePtr()->m_anyModified
)
854 // -----------------------------------------------------------------------
856 wxPGProperty
* wxPropertyGridManager::GetPageRoot( int index
) const
858 wxASSERT( index
>= 0 );
859 wxASSERT( index
< (int)m_arrPages
.GetCount() );
861 return ((wxPropertyGridPage
*)m_arrPages
.Item(index
))->GetStatePtr()->m_properties
;
864 // -----------------------------------------------------------------------
866 bool wxPropertyGridManager::RemovePage( int page
)
868 wxCHECK_MSG( (page
>= 0) && (page
< (int)GetPageCount()),
870 wxT("invalid page index") );
872 wxPropertyGridPage
* pd
= (wxPropertyGridPage
*)m_arrPages
.Item(page
);
874 if ( m_arrPages
.GetCount() == 1 )
876 // Last page: do not remove page entry
877 m_pPropGrid
->Clear();
879 m_iFlags
&= ~wxPG_MAN_FL_PAGE_INSERTED
;
882 // Change selection if current is page
883 else if ( page
== m_selPage
)
885 if ( !m_pPropGrid
->ClearSelection() )
888 // Substitute page to select
889 int substitute
= page
- 1;
890 if ( substitute
< 0 )
891 substitute
= page
+ 1;
893 SelectPage(substitute
);
896 // Remove toolbar icon
898 if ( HasFlag(wxPG_TOOLBAR
) )
900 wxASSERT( m_pToolbar
);
902 int toolPos
= GetExtraStyle() & wxPG_EX_MODE_BUTTONS
? 3 : 0;
905 // Delete separator as well, for consistency
906 if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS
) &&
907 GetPageCount() == 1 )
908 m_pToolbar
->DeleteToolByPos(2);
910 m_pToolbar
->DeleteToolByPos(toolPos
);
914 if ( m_arrPages
.GetCount() > 1 )
916 m_arrPages
.RemoveAt(page
);
920 // Adjust indexes that were above removed
921 if ( m_selPage
> page
)
927 // -----------------------------------------------------------------------
929 bool wxPropertyGridManager::ProcessEvent( wxEvent
& event
)
931 int evtType
= event
.GetEventType();
933 // NB: For some reason, under wxPython, Connect in Init doesn't work properly,
934 // so we'll need to call OnPropertyGridSelect manually. Multiple call's
935 // don't really matter.
936 if ( evtType
== wxEVT_PG_SELECTED
)
937 OnPropertyGridSelect((wxPropertyGridEvent
&)event
);
939 // Property grid events get special attention
940 if ( evtType
>= wxPG_BASE_EVT_TYPE
&&
941 evtType
< (wxPG_MAX_EVT_TYPE
) &&
944 wxPropertyGridPage
* page
= GetPage(m_selPage
);
945 wxPropertyGridEvent
* pgEvent
= wxDynamicCast(&event
, wxPropertyGridEvent
);
947 // Add property grid events to appropriate custom pages
948 // but stop propagating to parent if page says it is
949 // handling everything.
950 if ( pgEvent
&& !page
->m_isDefault
)
952 /*if ( pgEvent->IsPending() )
953 page->AddPendingEvent(event);
955 page
->ProcessEvent(event
);
957 if ( page
->IsHandlingAllEvents() )
958 event
.StopPropagation();
962 return wxPanel::ProcessEvent(event
);
965 // -----------------------------------------------------------------------
967 void wxPropertyGridManager::RepaintSplitter( wxDC
& dc
, int new_splittery
, int new_width
,
968 int new_height
, bool desc_too
)
970 int use_hei
= new_height
;
973 wxColour bgcol
= GetBackgroundColour();
974 dc
.SetBrush( bgcol
);
976 int rect_hei
= use_hei
-new_splittery
;
978 rect_hei
= m_splitterHeight
;
979 dc
.DrawRectangle(0,new_splittery
,new_width
,rect_hei
);
980 dc
.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW
) );
981 int splitter_bottom
= new_splittery
+m_splitterHeight
- 1;
982 int box_height
= use_hei
-splitter_bottom
;
983 if ( box_height
> 1 )
984 dc
.DrawRectangle(0,splitter_bottom
,new_width
,box_height
);
986 dc
.DrawLine(0,splitter_bottom
,new_width
,splitter_bottom
);
989 // -----------------------------------------------------------------------
991 void wxPropertyGridManager::RefreshHelpBox( int new_splittery
, int new_width
, int new_height
)
993 //if ( new_splittery == m_splitterY && new_width == m_width )
996 int use_hei
= new_height
;
999 //wxRendererNative::Get().DrawSplitterSash(this,dc,
1000 //wxSize(width,m_splitterHeight),new_splittery,wxHORIZONTAL);
1002 //wxRendererNative::Get().DrawSplitterBorder(this,dc,
1003 // wxRect(0,new_splittery,new_width,m_splitterHeight));
1005 // Fix help control positions.
1006 int cap_hei
= m_pPropGrid
->m_fontHeight
;
1007 int cap_y
= new_splittery
+m_splitterHeight
+5;
1008 int cnt_y
= cap_y
+cap_hei
+3;
1009 int sub_cap_hei
= cap_y
+cap_hei
-use_hei
;
1010 int cnt_hei
= use_hei
-cnt_y
;
1011 if ( sub_cap_hei
> 0 )
1013 cap_hei
-= sub_cap_hei
;
1018 m_pTxtHelpCaption
->Show( false );
1019 m_pTxtHelpContent
->Show( false );
1023 m_pTxtHelpCaption
->SetSize(3,cap_y
,new_width
-6,cap_hei
);
1024 m_pTxtHelpCaption
->Wrap(-1);
1025 m_pTxtHelpCaption
->Show( true );
1028 m_pTxtHelpContent
->Show( false );
1032 m_pTxtHelpContent
->SetSize(3,cnt_y
,new_width
-6,cnt_hei
);
1033 m_pTxtHelpContent
->Show( true );
1037 wxClientDC
dc(this);
1038 RepaintSplitter( dc
, new_splittery
, new_width
, new_height
, true );
1040 m_splitterY
= new_splittery
;
1042 m_iFlags
&= ~(wxPG_FL_DESC_REFRESH_REQUIRED
);
1045 // -----------------------------------------------------------------------
1047 void wxPropertyGridManager::RecalculatePositions( int width
, int height
)
1050 int propgridBottomY
= height
;
1052 // Toolbar at the top.
1058 #if ( wxMINOR_VERSION < 6 || (wxMINOR_VERSION == 6 && wxRELEASE_NUMBER < 2) )
1061 // In wxWidgets 2.6.2+, Toolbar default height may be broken
1062 #if defined(__WXMSW__)
1064 #elif defined(__WXGTK__)
1065 tbHeight
= -1; // 22;
1066 #elif defined(__WXMAC__)
1073 m_pToolbar
->SetSize(0,0,width
,tbHeight
);
1074 propgridY
+= m_pToolbar
->GetSize().y
;
1079 if ( m_pTxtHelpCaption
)
1081 int new_splittery
= m_splitterY
;
1084 if ( ( m_splitterY
>= 0 || m_nextDescBoxSize
) && m_height
> 32 )
1086 if ( m_nextDescBoxSize
>= 0 )
1088 new_splittery
= m_height
- m_nextDescBoxSize
- m_splitterHeight
;
1089 m_nextDescBoxSize
= -1;
1091 new_splittery
+= (height
-m_height
);
1095 new_splittery
= height
- wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y
;
1096 if ( new_splittery
< 32 )
1100 // Check if beyond minimum.
1101 int nspy_min
= propgridY
+ m_pPropGrid
->m_lineHeight
;
1102 if ( new_splittery
< nspy_min
)
1103 new_splittery
= nspy_min
;
1105 propgridBottomY
= new_splittery
;
1107 RefreshHelpBox( new_splittery
, width
, height
);
1110 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1112 int pgh
= propgridBottomY
- propgridY
;
1113 m_pPropGrid
->SetSize( 0, propgridY
, width
, pgh
);
1115 m_extraHeight
= height
- pgh
;
1122 // -----------------------------------------------------------------------
1124 void wxPropertyGridManager::SetDescBoxHeight( int ht
, bool refresh
)
1126 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1128 m_nextDescBoxSize
= ht
;
1130 RecalculatePositions(m_width
, m_height
);
1134 // -----------------------------------------------------------------------
1136 int wxPropertyGridManager::GetDescBoxHeight() const
1138 return GetClientSize().y
- m_splitterY
;
1141 // -----------------------------------------------------------------------
1143 void wxPropertyGridManager::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1147 // Update everything inside the box
1148 wxRect r
= GetUpdateRegion().GetBox();
1150 // Repaint splitter?
1151 int r_bottom
= r
.y
+ r
.height
;
1152 int splitter_bottom
= m_splitterY
+ m_splitterHeight
;
1153 if ( r
.y
< splitter_bottom
&& r_bottom
>= m_splitterY
)
1154 RepaintSplitter( dc
, m_splitterY
, m_width
, m_height
, false );
1157 // -----------------------------------------------------------------------
1159 void wxPropertyGridManager::Refresh(bool eraseBackground
, const wxRect
* rect
)
1161 m_pPropGrid
->Refresh(eraseBackground
);
1162 wxWindow::Refresh(eraseBackground
,rect
);
1165 // -----------------------------------------------------------------------
1167 void wxPropertyGridManager::RefreshProperty( wxPGProperty
* p
)
1169 wxPropertyGrid
* grid
= p
->GetGrid();
1171 if ( GetPage(m_selPage
)->GetStatePtr() == p
->GetParent()->GetParentState() )
1172 grid
->RefreshProperty(p
);
1175 // -----------------------------------------------------------------------
1177 void wxPropertyGridManager::RecreateControls()
1180 bool was_shown
= IsShown();
1184 wxWindowID baseId
= m_pPropGrid
->GetId();
1186 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1189 if ( m_windowStyle
& wxPG_TOOLBAR
)
1194 m_pToolbar
= new wxToolBar(this,baseId
+ID_ADVTOOLBAR_OFFSET
,
1195 wxDefaultPosition
,wxDefaultSize
,
1196 ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR
)?0:wxTB_FLAT
)
1197 /*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
1199 #if defined(__WXMSW__)
1200 // Eliminate toolbar flicker on XP
1201 // NOTE: Not enabled since it corrupts drawing somewhat.
1204 #ifndef WS_EX_COMPOSITED
1205 #define WS_EX_COMPOSITED 0x02000000L
1208 HWND hWnd = (HWND)m_pToolbar->GetHWND();
1210 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1211 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1216 m_pToolbar
->SetCursor ( *wxSTANDARD_CURSOR
);
1218 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1220 wxString
desc1(_("Categorized Mode"));
1221 wxString
desc2(_("Alphabetic Mode"));
1222 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+0,
1223 desc1
,wxBitmap ( (const char**)gs_xpm_catmode
),
1224 desc1
,wxITEM_RADIO
);
1225 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+1,
1226 desc2
,wxBitmap ( (const char**)gs_xpm_noncatmode
),
1227 desc2
,wxITEM_RADIO
);
1228 m_pToolbar
->Realize();
1233 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1235 // Toggle correct mode button.
1236 // TODO: This doesn't work in wxMSW (when changing,
1237 // both items will get toggled).
1238 int toggle_but_on_ind
= ID_ADVTBITEMSBASE_OFFSET
+0;
1239 int toggle_but_off_ind
= ID_ADVTBITEMSBASE_OFFSET
+1;
1240 if ( m_pPropGrid
->m_pState
->IsInNonCatMode() )
1242 toggle_but_on_ind
++;
1243 toggle_but_off_ind
--;
1246 m_pToolbar
->ToggleTool(baseId
+toggle_but_on_ind
,true);
1247 m_pToolbar
->ToggleTool(baseId
+toggle_but_off_ind
,false);
1255 m_pToolbar
->Destroy();
1256 m_pToolbar
= (wxToolBar
*) NULL
;
1260 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1263 m_pPropGrid
->m_iFlags
|= (wxPG_FL_NOSTATUSBARHELP
);
1265 if ( !m_pTxtHelpCaption
)
1267 m_pTxtHelpCaption
= new wxStaticText (this,baseId
+ID_ADVHELPCAPTION_OFFSET
,wxEmptyString
);
1268 m_pTxtHelpCaption
->SetFont( m_pPropGrid
->m_captionFont
);
1269 m_pTxtHelpCaption
->SetCursor ( *wxSTANDARD_CURSOR
);
1271 if ( !m_pTxtHelpContent
)
1273 m_pTxtHelpContent
= new wxStaticText (this,baseId
+ID_ADVHELPCONTENT_OFFSET
,
1274 wxEmptyString
,wxDefaultPosition
,wxDefaultSize
,wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1275 m_pTxtHelpContent
->SetCursor ( *wxSTANDARD_CURSOR
);
1281 m_pPropGrid
->m_iFlags
&= ~(wxPG_FL_NOSTATUSBARHELP
);
1283 if ( m_pTxtHelpCaption
)
1284 m_pTxtHelpCaption
->Destroy();
1286 m_pTxtHelpCaption
= (wxStaticText
*) NULL
;
1288 if ( m_pTxtHelpContent
)
1289 m_pTxtHelpContent
->Destroy();
1291 m_pTxtHelpContent
= (wxStaticText
*) NULL
;
1296 GetClientSize(&width
,&height
);
1298 RecalculatePositions(width
,height
);
1304 // -----------------------------------------------------------------------
1306 wxPGProperty
* wxPropertyGridManager::DoGetPropertyByName( const wxString
& name
) const
1309 for ( i
=0; i
<GetPageCount(); i
++ )
1311 wxPropertyGridPageState
* pState
= ((wxPropertyGridPage
*)m_arrPages
.Item(i
))->GetStatePtr();
1312 wxPGProperty
* p
= pState
->BaseGetPropertyByName(name
);
1321 // -----------------------------------------------------------------------
1323 bool wxPropertyGridManager::EnsureVisible( wxPGPropArg id
)
1325 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1327 wxPropertyGridPageState
* parentState
= p
->GetParentState();
1329 // Select correct page.
1330 if ( m_pPropGrid
->m_pState
!= parentState
)
1331 DoSelectPage( GetPageByState(parentState
) );
1333 return m_pPropGrid
->EnsureVisible(id
);
1336 // -----------------------------------------------------------------------
1338 size_t wxPropertyGridManager::GetChildrenCount( int page_index
)
1340 return GetChildrenCount( GetPage(page_index
)->GetStatePtr()->m_properties
);
1343 // -----------------------------------------------------------------------
1345 void wxPropertyGridManager::OnToolbarClick( wxCommandEvent
&event
)
1347 int id
= event
.GetId();
1350 int baseId
= m_pPropGrid
->GetId();
1352 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1354 if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 0 ) )
1356 // Categorized mode.
1357 if ( m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
)
1358 m_pPropGrid
->EnableCategories( true );
1360 else if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 1 ) )
1363 if ( !(m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
1364 m_pPropGrid
->EnableCategories( false );
1372 wxPropertyGridPage
* pdc
;
1374 // Find page with given id.
1375 for ( i
=0; i
<GetPageCount(); i
++ )
1377 pdc
= (wxPropertyGridPage
*)m_arrPages
.Item(i
);
1378 if ( pdc
->m_id
== id
)
1385 wxASSERT( index
>= 0 );
1387 if ( DoSelectPage( index
) )
1390 // Event dispatching must be last.
1391 m_pPropGrid
->SendEvent( wxEVT_PG_PAGE_CHANGED
, (wxPGProperty
*) NULL
);
1396 // TODO: Depress the old button on toolbar.
1403 // -----------------------------------------------------------------------
1405 void wxPropertyGridManager::SetDescription( const wxString
& label
, const wxString
& content
)
1407 if ( m_pTxtHelpCaption
)
1409 wxSize osz1
= m_pTxtHelpCaption
->GetSize();
1410 wxSize osz2
= m_pTxtHelpContent
->GetSize();
1412 m_pTxtHelpCaption
->SetLabel(label
);
1413 m_pTxtHelpContent
->SetLabel(content
);
1415 m_pTxtHelpCaption
->SetSize(-1,osz1
.y
);
1416 m_pTxtHelpContent
->SetSize(-1,osz2
.y
);
1418 if ( (m_iFlags
& wxPG_FL_DESC_REFRESH_REQUIRED
) || (osz2
.x
<(m_width
-10)) )
1419 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1423 // -----------------------------------------------------------------------
1425 void wxPropertyGridManager::SetDescribedProperty( wxPGProperty
* p
)
1427 if ( m_pTxtHelpCaption
)
1431 SetDescription( p
->GetLabel(), p
->GetHelpString() );
1435 m_pTxtHelpCaption
->SetLabel(wxEmptyString
);
1436 m_pTxtHelpContent
->SetLabel(wxEmptyString
);
1441 // -----------------------------------------------------------------------
1443 void wxPropertyGridManager::SetSplitterLeft( bool subProps
, bool allPages
)
1447 m_pPropGrid
->SetSplitterLeft(subProps
);
1451 wxClientDC
dc(this);
1452 dc
.SetFont(m_pPropGrid
->m_font
);
1457 for ( i
=0; i
<GetPageCount(); i
++ )
1459 int maxW
= m_pState
->GetColumnFitWidth(dc
, GETPAGESTATE(i
)->m_properties
, 0, subProps
);
1460 maxW
+= m_pPropGrid
->m_marginWidth
;
1461 if ( maxW
> highest
)
1466 m_pPropGrid
->SetSplitterPosition( highest
);
1468 m_pPropGrid
->m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
1472 // -----------------------------------------------------------------------
1474 void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
1477 wxASSERT_MSG( GetId() == m_pPropGrid
->GetId(),
1478 wxT("wxPropertyGridManager id must be set with wxPropertyGridManager::SetId (not wxWindow::SetId).") );
1480 SetDescribedProperty(event
.GetProperty());
1484 // -----------------------------------------------------------------------
1486 void wxPropertyGridManager::OnResize( wxSizeEvent
& WXUNUSED(event
) )
1490 GetClientSize(&width
,&height
);
1492 if ( m_width
== -12345 )
1495 RecalculatePositions(width
,height
);
1498 // -----------------------------------------------------------------------
1500 void wxPropertyGridManager::OnMouseEntry( wxMouseEvent
& WXUNUSED(event
) )
1502 // Correct cursor. This is required atleast for wxGTK, for which
1503 // setting button's cursor to *wxSTANDARD_CURSOR does not work.
1504 SetCursor( wxNullCursor
);
1508 // -----------------------------------------------------------------------
1510 void wxPropertyGridManager::OnMouseMove( wxMouseEvent
&event
)
1512 if ( !m_pTxtHelpCaption
)
1517 if ( m_dragStatus
> 0 )
1519 int sy
= y
- m_dragOffset
;
1521 // Calculate drag limits
1522 int bottom_limit
= m_height
- m_splitterHeight
+ 1;
1523 int top_limit
= m_pPropGrid
->m_lineHeight
;
1525 if ( m_pToolbar
) top_limit
+= m_pToolbar
->GetSize().y
;
1528 if ( sy
>= top_limit
&& sy
< bottom_limit
)
1531 int change
= sy
- m_splitterY
;
1536 m_pPropGrid
->SetSize( m_width
, m_splitterY
- m_pPropGrid
->GetPosition().y
);
1537 RefreshHelpBox( m_splitterY
, m_width
, m_height
);
1539 m_extraHeight
-= change
;
1540 InvalidateBestSize();
1548 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1550 SetCursor ( m_cursorSizeNS
);
1557 SetCursor ( wxNullCursor
);
1564 // -----------------------------------------------------------------------
1566 void wxPropertyGridManager::OnMouseClick( wxMouseEvent
&event
)
1570 // Click on splitter.
1571 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1573 if ( m_dragStatus
== 0 )
1576 // Begin draggin the splitter
1583 m_dragOffset
= y
- m_splitterY
;
1589 // -----------------------------------------------------------------------
1591 void wxPropertyGridManager::OnMouseUp( wxMouseEvent
&event
)
1593 // No event type check - basicly calling this method should
1594 // just stop dragging.
1596 if ( m_dragStatus
>= 1 )
1599 // End Splitter Dragging
1604 // DO NOT ENABLE FOLLOWING LINE!
1605 // (it is only here as a reminder to not to do it)
1608 // This is necessary to return cursor
1611 // Set back the default cursor, if necessary
1612 if ( y
< m_splitterY
|| y
>= (m_splitterY
+m_splitterHeight
+2) )
1614 SetCursor ( wxNullCursor
);
1621 // -----------------------------------------------------------------------
1623 void wxPropertyGridManager::SetSplitterPosition( int pos
, int splitterColumn
)
1625 wxASSERT_MSG( GetPageCount(),
1626 wxT("SetSplitterPosition() has no effect until pages have been added") );
1629 for ( i
=0; i
<GetPageCount(); i
++ )
1631 wxPropertyGridPage
* page
= GetPage(i
);
1632 page
->DoSetSplitterPositionThisPage( pos
, splitterColumn
);
1635 m_pPropGrid
->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET
);
1638 // -----------------------------------------------------------------------
1639 // wxPGVIterator_Manager
1640 // -----------------------------------------------------------------------
1642 // Default returned by wxPropertyGridInterface::CreateVIterator().
1643 class wxPGVIteratorBase_Manager
: public wxPGVIteratorBase
1646 wxPGVIteratorBase_Manager( wxPropertyGridManager
* manager
, int flags
)
1647 : m_manager(manager
), m_flags(flags
), m_curPage(0)
1649 m_it
.Init(manager
->GetPage(0), flags
);
1651 virtual ~wxPGVIteratorBase_Manager() { }
1660 if ( m_curPage
< m_manager
->GetPageCount() )
1661 m_it
.Init( m_manager
->GetPage(m_curPage
), m_flags
);
1665 wxPropertyGridManager
* m_manager
;
1667 unsigned int m_curPage
;
1670 wxPGVIterator
wxPropertyGridManager::GetVIterator( int flags
) const
1672 return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager
*)this, flags
) );
1675 #endif // wxUSE_PROPGRID