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 char wxPropertyGridManagerNameStr
[] = "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 // -----------------------------------------------------------------------
157 // wxPropertyGridPage
158 // -----------------------------------------------------------------------
161 IMPLEMENT_CLASS(wxPropertyGridPage
, wxEvtHandler
)
164 BEGIN_EVENT_TABLE(wxPropertyGridPage
, wxEvtHandler
)
168 wxPropertyGridPage::wxPropertyGridPage()
169 : wxEvtHandler(), wxPropertyGridInterface(), wxPropertyGridPageState()
171 m_pState
= this; // wxPropertyGridInterface to point to State
176 wxPropertyGridPage::~wxPropertyGridPage()
180 void wxPropertyGridPage::Clear()
182 GetStatePtr()->DoClear();
185 wxSize
wxPropertyGridPage::FitColumns()
187 wxSize sz
= DoFitColumns();
191 void wxPropertyGridPage::RefreshProperty( wxPGProperty
* p
)
194 m_manager
->RefreshProperty(p
);
197 void wxPropertyGridPage::OnShow()
201 void wxPropertyGridPage::SetSplitterPosition( int splitterPos
, int col
)
203 wxPropertyGrid
* pg
= GetGrid();
204 if ( pg
->GetState() == this )
205 pg
->SetSplitterPosition(splitterPos
);
207 DoSetSplitterPosition(splitterPos
, col
, false);
210 void wxPropertyGridPage::DoSetSplitterPosition( int pos
,
213 bool fromAutoCenter
)
215 if ( allPages
&& m_manager
->GetPageCount() )
216 m_manager
->SetSplitterPosition( pos
, splitterColumn
);
218 wxPropertyGridPageState::DoSetSplitterPosition( pos
,
224 // -----------------------------------------------------------------------
225 // wxPropertyGridManager
226 // -----------------------------------------------------------------------
228 // Final default splitter y is client height minus this.
229 #define wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y 100
231 // -----------------------------------------------------------------------
233 IMPLEMENT_CLASS(wxPropertyGridManager
, wxPanel
)
235 #define ID_ADVTOOLBAR_OFFSET 1
236 #define ID_ADVHELPCAPTION_OFFSET 2
237 #define ID_ADVHELPCONTENT_OFFSET 3
238 //#define ID_ADVBUTTON_OFFSET 4
239 #define ID_ADVTBITEMSBASE_OFFSET 5 // Must be last.
241 // -----------------------------------------------------------------------
243 BEGIN_EVENT_TABLE(wxPropertyGridManager
, wxPanel
)
244 EVT_MOTION(wxPropertyGridManager::OnMouseMove
)
245 EVT_SIZE(wxPropertyGridManager::OnResize
)
246 EVT_PAINT(wxPropertyGridManager::OnPaint
)
247 EVT_LEFT_DOWN(wxPropertyGridManager::OnMouseClick
)
248 EVT_LEFT_UP(wxPropertyGridManager::OnMouseUp
)
249 EVT_LEAVE_WINDOW(wxPropertyGridManager::OnMouseEntry
)
250 //EVT_ENTER_WINDOW(wxPropertyGridManager::OnMouseEntry)
253 // -----------------------------------------------------------------------
255 wxPropertyGridManager::wxPropertyGridManager()
261 // -----------------------------------------------------------------------
263 wxPropertyGridManager::wxPropertyGridManager( wxWindow
*parent
,
268 const wxString
& name
)
272 Create(parent
,id
,pos
,size
,style
,name
);
275 // -----------------------------------------------------------------------
277 bool wxPropertyGridManager::Create( wxWindow
*parent
,
282 const wxString
& name
)
285 bool res
= wxPanel::Create( parent
, id
, pos
, size
,
286 (style
&0xFFFF0000)|wxWANTS_CHARS
,
293 // -----------------------------------------------------------------------
296 // Initialize values to defaults
298 void wxPropertyGridManager::Init1()
301 //m_pPropGrid = NULL;
302 m_pPropGrid
= CreatePropertyGrid();
307 m_pTxtHelpCaption
= NULL
;
308 m_pTxtHelpContent
= NULL
;
314 m_width
= m_height
= 0;
316 m_splitterHeight
= 5;
318 m_splitterY
= -1; // -1 causes default to be set.
320 m_nextDescBoxSize
= -1;
328 // -----------------------------------------------------------------------
330 // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager.
332 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxSIMPLE_BORDER| \
333 wxNO_FULL_REPAINT_ON_RESIZE| \
336 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxNO_BORDER| \
337 wxNO_FULL_REPAINT_ON_RESIZE| \
341 // Which flags can be passed to underlying wxPropertyGrid.
342 #define wxPG_MAN_PASS_FLAGS_MASK (0xFFF0|wxTAB_TRAVERSAL)
345 // Initialize after parent etc. set
347 void wxPropertyGridManager::Init2( int style
)
350 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
353 m_windowStyle
|= (style
&0x0000FFFF);
355 wxSize csz
= GetClientSize();
357 m_cursorSizeNS
= wxCursor(wxCURSOR_SIZENS
);
359 // Prepare the first page
360 // NB: But just prepare - you still need to call Add/InsertPage
361 // to actually add properties on it.
362 wxPropertyGridPage
* pd
= new wxPropertyGridPage();
363 pd
->m_isDefault
= true;
364 pd
->m_manager
= this;
365 wxPropertyGridPageState
* state
= pd
->GetStatePtr();
366 state
->m_pPropGrid
= m_pPropGrid
;
367 m_arrPages
.push_back( pd
);
368 m_pPropGrid
->m_pState
= state
;
370 wxWindowID baseId
= GetId();
371 wxWindowID useId
= baseId
;
373 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
378 // Smaller controls on Mac
379 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
382 // Create propertygrid.
383 m_pPropGrid
->Create(this,baseId
,wxPoint(0,0),csz
,
384 (m_windowStyle
&wxPG_MAN_PASS_FLAGS_MASK
)
385 |wxPG_MAN_PROPGRID_FORCED_FLAGS
);
387 m_pPropGrid
->m_eventObject
= this;
389 m_pPropGrid
->SetId(useId
);
391 m_pPropGrid
->m_iFlags
|= wxPG_FL_IN_MANAGER
;
393 m_pState
= m_pPropGrid
->m_pState
;
395 m_pPropGrid
->SetExtraStyle(wxPG_EX_INIT_NOCAT
);
397 m_nextTbInd
= baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
400 // Connect to property grid onselect event.
401 // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython
402 // (see wxPropertyGridManager::ProcessEvent).
403 Connect(m_pPropGrid
->GetId()/*wxID_ANY*/,
405 wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect
) );
407 // Connect to toolbar button events.
408 Connect(baseId
+ID_ADVTBITEMSBASE_OFFSET
,baseId
+ID_ADVTBITEMSBASE_OFFSET
+50,
409 wxEVT_COMMAND_TOOL_CLICKED
,
410 wxCommandEventHandler(wxPropertyGridManager::OnToolbarClick
) );
412 // Optional initial controls.
415 m_iFlags
|= wxPG_FL_INITIALIZED
;
419 // -----------------------------------------------------------------------
421 wxPropertyGridManager::~wxPropertyGridManager()
425 m_pPropGrid
->DoSelectProperty(NULL
);
426 m_pPropGrid
->m_pState
= NULL
;
429 for ( i
=0; i
<m_arrPages
.size(); i
++ )
431 delete m_arrPages
[i
];
437 // -----------------------------------------------------------------------
439 wxPropertyGrid
* wxPropertyGridManager::CreatePropertyGrid() const
441 return new wxPropertyGrid();
444 // -----------------------------------------------------------------------
446 void wxPropertyGridManager::SetId( wxWindowID winid
)
448 wxWindow::SetId(winid
);
450 // TODO: Reconnect propgrid event handler(s).
452 m_pPropGrid
->SetId(winid
);
455 // -----------------------------------------------------------------------
457 wxSize
wxPropertyGridManager::DoGetBestSize() const
459 return wxSize(60,150);
462 // -----------------------------------------------------------------------
464 bool wxPropertyGridManager::SetFont( const wxFont
& font
)
466 bool res
= wxWindow::SetFont(font
);
467 m_pPropGrid
->SetFont(font
);
469 // TODO: Need to do caption recacalculations for other pages as well.
471 for ( i
=0; i
<m_arrPages
.size(); i
++ )
473 wxPropertyGridPage
* page
= GetPage(i
);
475 if ( page
!= m_pPropGrid
->GetState() )
476 page
->CalculateFontAndBitmapStuff(-1);
482 // -----------------------------------------------------------------------
484 void wxPropertyGridManager::SetExtraStyle( long exStyle
)
486 wxWindow::SetExtraStyle( exStyle
);
487 m_pPropGrid
->SetExtraStyle( exStyle
& 0xFFFFF000 );
489 if ( (exStyle
& wxPG_EX_NO_FLAT_TOOLBAR
) && m_pToolbar
)
494 // -----------------------------------------------------------------------
496 void wxPropertyGridManager::Freeze()
498 m_pPropGrid
->Freeze();
502 // -----------------------------------------------------------------------
504 void wxPropertyGridManager::Thaw()
510 // -----------------------------------------------------------------------
512 void wxPropertyGridManager::SetWindowStyleFlag( long style
)
514 int oldWindowStyle
= GetWindowStyleFlag();
516 wxWindow::SetWindowStyleFlag( style
);
517 m_pPropGrid
->SetWindowStyleFlag( (m_pPropGrid
->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK
)) |
518 (style
&wxPG_MAN_PASS_FLAGS_MASK
) );
520 // Need to re-position windows?
521 if ( (oldWindowStyle
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) !=
522 (style
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) )
528 // -----------------------------------------------------------------------
530 // Actually shows given page.
531 bool wxPropertyGridManager::DoSelectPage( int index
)
533 // -1 means no page was selected
534 //wxASSERT( m_selPage >= 0 );
536 wxCHECK_MSG( index
>= -1 && index
< (int)GetPageCount(),
538 wxT("invalid page index") );
540 if ( m_selPage
== index
)
543 if ( m_pPropGrid
->m_selected
)
545 if ( !m_pPropGrid
->ClearSelection() )
549 wxPropertyGridPage
* prevPage
;
551 if ( m_selPage
>= 0 )
552 prevPage
= GetPage(m_selPage
);
554 prevPage
= m_emptyPage
;
556 wxPropertyGridPage
* nextPage
;
560 nextPage
= m_arrPages
[index
];
568 m_emptyPage
= new wxPropertyGridPage();
569 m_emptyPage
->m_pPropGrid
= m_pPropGrid
;
572 nextPage
= m_emptyPage
;
575 m_iFlags
|= wxPG_FL_DESC_REFRESH_REQUIRED
;
577 m_pPropGrid
->SwitchState( nextPage
->GetStatePtr() );
579 m_pState
= m_pPropGrid
->m_pState
;
587 m_pToolbar
->ToggleTool( nextPage
->m_id
, true );
589 m_pToolbar
->ToggleTool( prevPage
->m_id
, false );
596 // -----------------------------------------------------------------------
598 // Changes page *and* set the target page for insertion operations.
599 void wxPropertyGridManager::SelectPage( int index
)
604 // -----------------------------------------------------------------------
606 int wxPropertyGridManager::GetPageByName( const wxString
& name
) const
609 for ( i
=0; i
<GetPageCount(); i
++ )
611 if ( m_arrPages
[i
]->m_label
== name
)
617 // -----------------------------------------------------------------------
619 int wxPropertyGridManager::GetPageByState( const wxPropertyGridPageState
* pState
) const
624 for ( i
=0; i
<GetPageCount(); i
++ )
626 if ( pState
== m_arrPages
[i
]->GetStatePtr() )
633 // -----------------------------------------------------------------------
635 const wxString
& wxPropertyGridManager::GetPageName( int index
) const
637 wxASSERT( index
>= 0 && index
< (int)GetPageCount() );
638 return m_arrPages
[index
]->m_label
;
641 // -----------------------------------------------------------------------
643 wxPropertyGridPageState
* wxPropertyGridManager::GetPageState( int page
) const
645 // Do not change this into wxCHECK because returning NULL is important
646 // for wxPropertyGridInterface page enumeration mechanics.
647 if ( page
>= (int)GetPageCount() )
652 return m_arrPages
[page
];
655 // -----------------------------------------------------------------------
657 void wxPropertyGridManager::Clear()
659 m_pPropGrid
->Freeze();
662 for ( i
=(int)GetPageCount()-1; i
>=0; i
-- )
666 m_nextTbInd
= m_baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
671 // -----------------------------------------------------------------------
673 void wxPropertyGridManager::ClearPage( int page
)
675 wxASSERT( page
>= 0 );
676 wxASSERT( page
< (int)GetPageCount() );
678 if ( page
>= 0 && page
< (int)GetPageCount() )
680 wxPropertyGridPageState
* state
= m_arrPages
[page
];
682 if ( state
== m_pPropGrid
->GetState() )
683 m_pPropGrid
->Clear();
689 // -----------------------------------------------------------------------
691 int wxPropertyGridManager::GetColumnCount( int page
) const
693 wxASSERT( page
>= -1 );
694 wxASSERT( page
< (int)GetPageCount() );
696 return GetPageState(page
)->GetColumnCount();
699 // -----------------------------------------------------------------------
701 void wxPropertyGridManager::SetColumnCount( int colCount
, int page
)
703 wxASSERT( page
>= -1 );
704 wxASSERT( page
< (int)GetPageCount() );
706 GetPageState(page
)->SetColumnCount( colCount
);
707 GetGrid()->Refresh();
709 // -----------------------------------------------------------------------
711 size_t wxPropertyGridManager::GetPageCount() const
713 if ( !(m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
) )
716 return m_arrPages
.size();
719 // -----------------------------------------------------------------------
721 wxPropertyGridPage
* wxPropertyGridManager::InsertPage( int index
,
722 const wxString
& label
,
724 wxPropertyGridPage
* pageObj
)
727 index
= GetPageCount();
729 wxCHECK_MSG( (size_t)index
== GetPageCount(), NULL
,
730 wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
732 bool needInit
= true;
733 bool isPageInserted
= m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
? true : false;
735 wxASSERT( index
== 0 || isPageInserted
);
739 // No custom page object was given, so we will either re-use the default base
740 // page (if index==0), or create a new default page object.
741 if ( !isPageInserted
)
743 pageObj
= GetPage(0);
744 // Of course, if the base page was custom, we need to delete and
746 if ( !pageObj
->m_isDefault
)
749 pageObj
= new wxPropertyGridPage();
750 m_arrPages
[0] = pageObj
;
756 pageObj
= new wxPropertyGridPage();
758 pageObj
->m_isDefault
= true;
762 if ( !isPageInserted
)
764 // Initial page needs to be deleted and replaced
766 m_arrPages
[0] = pageObj
;
767 m_pPropGrid
->m_pState
= pageObj
->GetStatePtr();
771 wxPropertyGridPageState
* state
= pageObj
->GetStatePtr();
773 pageObj
->m_manager
= this;
777 state
->m_pPropGrid
= m_pPropGrid
;
778 state
->InitNonCatMode();
781 if ( label
.length() )
783 wxASSERT_MSG( !pageObj
->m_label
.length(),
784 wxT("If page label is given in constructor, empty label must be given in AddPage"));
785 pageObj
->m_label
= label
;
788 pageObj
->m_id
= m_nextTbInd
;
790 if ( isPageInserted
)
791 m_arrPages
.push_back( pageObj
);
794 if ( m_windowStyle
& wxPG_TOOLBAR
)
799 if ( !(GetExtraStyle()&wxPG_EX_HIDE_PAGE_BUTTONS
) )
801 wxASSERT( m_pToolbar
);
803 // Add separator before first page.
804 if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) &&
805 m_pToolbar
->GetToolsCount() < 3 )
806 m_pToolbar
->AddSeparator();
808 if ( &bmp
!= &wxNullBitmap
)
809 m_pToolbar
->AddTool(m_nextTbInd
,label
,bmp
,label
,wxITEM_RADIO
);
810 //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
812 m_pToolbar
->AddTool(m_nextTbInd
,label
,wxBitmap( (const char**)gs_xpm_defpage
),
817 m_pToolbar
->Realize();
824 // If selected page was above the point of insertion, fix the current page index
825 if ( isPageInserted
)
827 if ( m_selPage
>= index
)
834 // Set this value only when adding the first page
840 m_iFlags
|= wxPG_MAN_FL_PAGE_INSERTED
;
842 wxASSERT( pageObj
->GetGrid() );
847 // -----------------------------------------------------------------------
849 bool wxPropertyGridManager::IsAnyModified() const
852 for ( i
=0; i
<GetPageCount(); i
++ )
854 if ( m_arrPages
[i
]->GetStatePtr()->m_anyModified
)
860 // -----------------------------------------------------------------------
862 bool wxPropertyGridManager::IsPageModified( size_t index
) const
864 if ( m_arrPages
[index
]->GetStatePtr()->m_anyModified
)
869 // -----------------------------------------------------------------------
871 wxPGProperty
* wxPropertyGridManager::GetPageRoot( int index
) const
873 wxASSERT( index
>= 0 );
874 wxASSERT( index
< (int)m_arrPages
.size() );
876 return m_arrPages
[index
]->GetStatePtr()->m_properties
;
879 // -----------------------------------------------------------------------
881 bool wxPropertyGridManager::RemovePage( int page
)
883 wxCHECK_MSG( (page
>= 0) && (page
< (int)GetPageCount()),
885 wxT("invalid page index") );
887 wxPropertyGridPage
* pd
= m_arrPages
[page
];
889 if ( m_arrPages
.size() == 1 )
891 // Last page: do not remove page entry
892 m_pPropGrid
->Clear();
894 m_iFlags
&= ~wxPG_MAN_FL_PAGE_INSERTED
;
898 // Change selection if current is page
899 else if ( page
== m_selPage
)
901 if ( !m_pPropGrid
->ClearSelection() )
904 // Substitute page to select
905 int substitute
= page
- 1;
906 if ( substitute
< 0 )
907 substitute
= page
+ 1;
909 SelectPage(substitute
);
912 // Remove toolbar icon
914 if ( HasFlag(wxPG_TOOLBAR
) )
916 wxASSERT( m_pToolbar
);
918 int toolPos
= GetExtraStyle() & wxPG_EX_MODE_BUTTONS
? 3 : 0;
921 // Delete separator as well, for consistency
922 if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS
) &&
923 GetPageCount() == 1 )
924 m_pToolbar
->DeleteToolByPos(2);
926 m_pToolbar
->DeleteToolByPos(toolPos
);
930 if ( m_arrPages
.size() > 1 )
932 m_arrPages
.erase(m_arrPages
.begin() + page
);
936 // Adjust indexes that were above removed
937 if ( m_selPage
> page
)
943 // -----------------------------------------------------------------------
945 bool wxPropertyGridManager::ProcessEvent( wxEvent
& event
)
947 int evtType
= event
.GetEventType();
949 // NB: For some reason, under wxPython, Connect in Init doesn't work properly,
950 // so we'll need to call OnPropertyGridSelect manually. Multiple call's
951 // don't really matter.
952 if ( evtType
== wxEVT_PG_SELECTED
)
953 OnPropertyGridSelect((wxPropertyGridEvent
&)event
);
955 // Property grid events get special attention
956 if ( evtType
>= wxPG_BASE_EVT_TYPE
&&
957 evtType
< (wxPG_MAX_EVT_TYPE
) &&
960 wxPropertyGridPage
* page
= GetPage(m_selPage
);
961 wxPropertyGridEvent
* pgEvent
= wxDynamicCast(&event
, wxPropertyGridEvent
);
963 // Add property grid events to appropriate custom pages
964 // but stop propagating to parent if page says it is
965 // handling everything.
966 if ( pgEvent
&& !page
->m_isDefault
)
968 /*if ( pgEvent->IsPending() )
969 page->AddPendingEvent(event);
971 page
->ProcessEvent(event
);
973 if ( page
->IsHandlingAllEvents() )
974 event
.StopPropagation();
978 return wxPanel::ProcessEvent(event
);
981 // -----------------------------------------------------------------------
983 void wxPropertyGridManager::RepaintSplitter( wxDC
& dc
, int new_splittery
, int new_width
,
984 int new_height
, bool desc_too
)
986 int use_hei
= new_height
;
989 wxColour bgcol
= GetBackgroundColour();
990 dc
.SetBrush( bgcol
);
992 int rect_hei
= use_hei
-new_splittery
;
994 rect_hei
= m_splitterHeight
;
995 dc
.DrawRectangle(0,new_splittery
,new_width
,rect_hei
);
996 dc
.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW
) );
997 int splitter_bottom
= new_splittery
+m_splitterHeight
- 1;
998 int box_height
= use_hei
-splitter_bottom
;
999 if ( box_height
> 1 )
1000 dc
.DrawRectangle(0,splitter_bottom
,new_width
,box_height
);
1002 dc
.DrawLine(0,splitter_bottom
,new_width
,splitter_bottom
);
1005 // -----------------------------------------------------------------------
1007 void wxPropertyGridManager::UpdateDescriptionBox( int new_splittery
, int new_width
, int new_height
)
1009 int use_hei
= new_height
;
1012 // Fix help control positions.
1013 int cap_hei
= m_pPropGrid
->m_fontHeight
;
1014 int cap_y
= new_splittery
+m_splitterHeight
+5;
1015 int cnt_y
= cap_y
+cap_hei
+3;
1016 int sub_cap_hei
= cap_y
+cap_hei
-use_hei
;
1017 int cnt_hei
= use_hei
-cnt_y
;
1018 if ( sub_cap_hei
> 0 )
1020 cap_hei
-= sub_cap_hei
;
1025 m_pTxtHelpCaption
->Show( false );
1026 m_pTxtHelpContent
->Show( false );
1030 m_pTxtHelpCaption
->SetSize(3,cap_y
,new_width
-6,cap_hei
);
1031 m_pTxtHelpCaption
->Wrap(-1);
1032 m_pTxtHelpCaption
->Show( true );
1035 m_pTxtHelpContent
->Show( false );
1039 m_pTxtHelpContent
->SetSize(3,cnt_y
,new_width
-6,cnt_hei
);
1040 m_pTxtHelpContent
->Show( true );
1044 wxRect
r(0, new_splittery
, new_width
, new_height
-new_splittery
);
1047 m_splitterY
= new_splittery
;
1049 m_iFlags
&= ~(wxPG_FL_DESC_REFRESH_REQUIRED
);
1052 // -----------------------------------------------------------------------
1054 void wxPropertyGridManager::RecalculatePositions( int width
, int height
)
1057 int propgridBottomY
= height
;
1059 // Toolbar at the top.
1065 #if ( wxMINOR_VERSION < 6 || (wxMINOR_VERSION == 6 && wxRELEASE_NUMBER < 2) )
1068 // In wxWidgets 2.6.2+, Toolbar default height may be broken
1069 #if defined(__WXMSW__)
1071 #elif defined(__WXGTK__)
1072 tbHeight
= -1; // 22;
1073 #elif defined(__WXMAC__)
1080 m_pToolbar
->SetSize(0,0,width
,tbHeight
);
1081 propgridY
+= m_pToolbar
->GetSize().y
;
1086 if ( m_pTxtHelpCaption
)
1088 int new_splittery
= m_splitterY
;
1091 if ( ( m_splitterY
>= 0 || m_nextDescBoxSize
) && m_height
> 32 )
1093 if ( m_nextDescBoxSize
>= 0 )
1095 new_splittery
= m_height
- m_nextDescBoxSize
- m_splitterHeight
;
1096 m_nextDescBoxSize
= -1;
1098 new_splittery
+= (height
-m_height
);
1102 new_splittery
= height
- wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y
;
1103 if ( new_splittery
< 32 )
1107 // Check if beyond minimum.
1108 int nspy_min
= propgridY
+ m_pPropGrid
->m_lineHeight
;
1109 if ( new_splittery
< nspy_min
)
1110 new_splittery
= nspy_min
;
1112 propgridBottomY
= new_splittery
;
1114 UpdateDescriptionBox( new_splittery
, width
, height
);
1117 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1119 int pgh
= propgridBottomY
- propgridY
;
1120 m_pPropGrid
->SetSize( 0, propgridY
, width
, pgh
);
1122 m_extraHeight
= height
- pgh
;
1129 // -----------------------------------------------------------------------
1131 void wxPropertyGridManager::SetDescBoxHeight( int ht
, bool refresh
)
1133 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1135 if ( ht
!= GetDescBoxHeight() )
1137 m_nextDescBoxSize
= ht
;
1139 RecalculatePositions(m_width
, m_height
);
1144 // -----------------------------------------------------------------------
1146 int wxPropertyGridManager::GetDescBoxHeight() const
1148 return GetClientSize().y
- m_splitterY
- m_splitterHeight
;
1151 // -----------------------------------------------------------------------
1153 void wxPropertyGridManager::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1157 // Update everything inside the box
1158 wxRect r
= GetUpdateRegion().GetBox();
1160 // Repaint splitter?
1161 int r_bottom
= r
.y
+ r
.height
;
1162 int splitter_bottom
= m_splitterY
+ m_splitterHeight
;
1163 if ( r
.y
< splitter_bottom
&& r_bottom
>= m_splitterY
)
1164 RepaintSplitter( dc
, m_splitterY
, m_width
, m_height
, false );
1167 // -----------------------------------------------------------------------
1169 void wxPropertyGridManager::Refresh(bool eraseBackground
, const wxRect
* rect
)
1171 m_pPropGrid
->Refresh(eraseBackground
);
1172 wxWindow::Refresh(eraseBackground
,rect
);
1175 // -----------------------------------------------------------------------
1177 void wxPropertyGridManager::RefreshProperty( wxPGProperty
* p
)
1179 wxPropertyGrid
* grid
= p
->GetGrid();
1181 if ( GetPage(m_selPage
)->GetStatePtr() == p
->GetParent()->GetParentState() )
1182 grid
->RefreshProperty(p
);
1185 // -----------------------------------------------------------------------
1187 void wxPropertyGridManager::RecreateControls()
1190 bool was_shown
= IsShown();
1194 wxWindowID baseId
= m_pPropGrid
->GetId();
1196 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1199 if ( m_windowStyle
& wxPG_TOOLBAR
)
1204 m_pToolbar
= new wxToolBar(this,baseId
+ID_ADVTOOLBAR_OFFSET
,
1205 wxDefaultPosition
,wxDefaultSize
,
1206 ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR
)?0:wxTB_FLAT
)
1207 /*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
1209 #if defined(__WXMSW__)
1210 // Eliminate toolbar flicker on XP
1211 // NOTE: Not enabled since it corrupts drawing somewhat.
1214 #ifndef WS_EX_COMPOSITED
1215 #define WS_EX_COMPOSITED 0x02000000L
1218 HWND hWnd = (HWND)m_pToolbar->GetHWND();
1220 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1221 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1226 m_pToolbar
->SetCursor ( *wxSTANDARD_CURSOR
);
1228 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1230 wxString
desc1(_("Categorized Mode"));
1231 wxString
desc2(_("Alphabetic Mode"));
1232 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+0,
1233 desc1
,wxBitmap ( (const char**)gs_xpm_catmode
),
1234 desc1
,wxITEM_RADIO
);
1235 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+1,
1236 desc2
,wxBitmap ( (const char**)gs_xpm_noncatmode
),
1237 desc2
,wxITEM_RADIO
);
1238 m_pToolbar
->Realize();
1243 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1245 // Toggle correct mode button.
1246 // TODO: This doesn't work in wxMSW (when changing,
1247 // both items will get toggled).
1248 int toggle_but_on_ind
= ID_ADVTBITEMSBASE_OFFSET
+0;
1249 int toggle_but_off_ind
= ID_ADVTBITEMSBASE_OFFSET
+1;
1250 if ( m_pPropGrid
->m_pState
->IsInNonCatMode() )
1252 toggle_but_on_ind
++;
1253 toggle_but_off_ind
--;
1256 m_pToolbar
->ToggleTool(baseId
+toggle_but_on_ind
,true);
1257 m_pToolbar
->ToggleTool(baseId
+toggle_but_off_ind
,false);
1265 m_pToolbar
->Destroy();
1270 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1273 m_pPropGrid
->m_iFlags
|= (wxPG_FL_NOSTATUSBARHELP
);
1275 if ( !m_pTxtHelpCaption
)
1277 m_pTxtHelpCaption
= new wxStaticText(this,
1278 baseId
+ID_ADVHELPCAPTION_OFFSET
,
1282 wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1283 m_pTxtHelpCaption
->SetFont( m_pPropGrid
->m_captionFont
);
1284 m_pTxtHelpCaption
->SetCursor( *wxSTANDARD_CURSOR
);
1286 if ( !m_pTxtHelpContent
)
1288 m_pTxtHelpContent
= new wxStaticText(this,
1289 baseId
+ID_ADVHELPCONTENT_OFFSET
,
1293 wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1294 m_pTxtHelpContent
->SetCursor( *wxSTANDARD_CURSOR
);
1297 SetDescribedProperty(GetSelection());
1302 m_pPropGrid
->m_iFlags
&= ~(wxPG_FL_NOSTATUSBARHELP
);
1304 if ( m_pTxtHelpCaption
)
1305 m_pTxtHelpCaption
->Destroy();
1307 m_pTxtHelpCaption
= NULL
;
1309 if ( m_pTxtHelpContent
)
1310 m_pTxtHelpContent
->Destroy();
1312 m_pTxtHelpContent
= NULL
;
1317 GetClientSize(&width
,&height
);
1319 RecalculatePositions(width
,height
);
1325 // -----------------------------------------------------------------------
1327 wxPGProperty
* wxPropertyGridManager::DoGetPropertyByName( const wxString
& name
) const
1330 for ( i
=0; i
<GetPageCount(); i
++ )
1332 wxPropertyGridPageState
* pState
= m_arrPages
[i
]->GetStatePtr();
1333 wxPGProperty
* p
= pState
->BaseGetPropertyByName(name
);
1342 // -----------------------------------------------------------------------
1344 bool wxPropertyGridManager::EnsureVisible( wxPGPropArg id
)
1346 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1348 wxPropertyGridPageState
* parentState
= p
->GetParentState();
1350 // Select correct page.
1351 if ( m_pPropGrid
->m_pState
!= parentState
)
1352 DoSelectPage( GetPageByState(parentState
) );
1354 return m_pPropGrid
->EnsureVisible(id
);
1357 // -----------------------------------------------------------------------
1359 void wxPropertyGridManager::OnToolbarClick( wxCommandEvent
&event
)
1361 int id
= event
.GetId();
1364 int baseId
= m_pPropGrid
->GetId();
1366 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1368 if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 0 ) )
1370 // Categorized mode.
1371 if ( m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
)
1373 if ( !m_pPropGrid
->HasInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
) )
1374 m_pPropGrid
->m_windowStyle
&= ~wxPG_AUTO_SORT
;
1375 m_pPropGrid
->EnableCategories( true );
1378 else if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 1 ) )
1381 if ( !(m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
1383 if ( m_pPropGrid
->HasFlag(wxPG_AUTO_SORT
) )
1384 m_pPropGrid
->SetInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1386 m_pPropGrid
->ClearInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1388 m_pPropGrid
->m_windowStyle
|= wxPG_AUTO_SORT
;
1389 m_pPropGrid
->EnableCategories( false );
1398 wxPropertyGridPage
* pdc
;
1400 // Find page with given id.
1401 for ( i
=0; i
<GetPageCount(); i
++ )
1403 pdc
= m_arrPages
[i
];
1404 if ( pdc
->m_id
== id
)
1411 wxASSERT( index
>= 0 );
1413 if ( DoSelectPage( index
) )
1416 // Event dispatching must be last.
1417 m_pPropGrid
->SendEvent( wxEVT_PG_PAGE_CHANGED
, NULL
);
1422 // TODO: Depress the old button on toolbar.
1429 // -----------------------------------------------------------------------
1431 bool wxPropertyGridManager::SetEditableStateItem( const wxString
& name
, wxVariant value
)
1433 if ( name
== wxS("descboxheight") )
1435 SetDescBoxHeight(value
.GetLong(), true);
1441 // -----------------------------------------------------------------------
1443 wxVariant
wxPropertyGridManager::GetEditableStateItem( const wxString
& name
) const
1445 if ( name
== wxS("descboxheight") )
1447 return (long) GetDescBoxHeight();
1449 return wxNullVariant
;
1452 // -----------------------------------------------------------------------
1454 void wxPropertyGridManager::SetDescription( const wxString
& label
, const wxString
& content
)
1456 if ( m_pTxtHelpCaption
)
1458 wxSize osz1
= m_pTxtHelpCaption
->GetSize();
1459 wxSize osz2
= m_pTxtHelpContent
->GetSize();
1461 m_pTxtHelpCaption
->SetLabel(label
);
1462 m_pTxtHelpContent
->SetLabel(content
);
1464 m_pTxtHelpCaption
->SetSize(-1,osz1
.y
);
1465 m_pTxtHelpContent
->SetSize(-1,osz2
.y
);
1467 UpdateDescriptionBox( m_splitterY
, m_width
, m_height
);
1471 // -----------------------------------------------------------------------
1473 void wxPropertyGridManager::SetDescribedProperty( wxPGProperty
* p
)
1475 if ( m_pTxtHelpCaption
)
1479 SetDescription( p
->GetLabel(), p
->GetHelpString() );
1483 SetDescription( wxEmptyString
, wxEmptyString
);
1488 // -----------------------------------------------------------------------
1490 void wxPropertyGridManager::SetSplitterLeft( bool subProps
, bool allPages
)
1494 m_pPropGrid
->SetSplitterLeft(subProps
);
1498 wxClientDC
dc(this);
1499 dc
.SetFont(m_pPropGrid
->m_font
);
1504 for ( i
=0; i
<GetPageCount(); i
++ )
1506 int maxW
= m_pState
->GetColumnFitWidth(dc
, m_arrPages
[i
]->m_properties
, 0, subProps
);
1507 maxW
+= m_pPropGrid
->m_marginWidth
;
1508 if ( maxW
> highest
)
1513 m_pPropGrid
->SetSplitterPosition( highest
);
1515 m_pPropGrid
->m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
1519 // -----------------------------------------------------------------------
1521 void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
1524 wxASSERT_MSG( GetId() == m_pPropGrid
->GetId(),
1525 wxT("wxPropertyGridManager id must be set with wxPropertyGridManager::SetId (not wxWindow::SetId).") );
1527 SetDescribedProperty(event
.GetProperty());
1531 // -----------------------------------------------------------------------
1533 void wxPropertyGridManager::OnResize( wxSizeEvent
& WXUNUSED(event
) )
1537 GetClientSize(&width
,&height
);
1539 if ( m_width
== -12345 )
1542 RecalculatePositions(width
,height
);
1545 // -----------------------------------------------------------------------
1547 void wxPropertyGridManager::OnMouseEntry( wxMouseEvent
& WXUNUSED(event
) )
1549 // Correct cursor. This is required atleast for wxGTK, for which
1550 // setting button's cursor to *wxSTANDARD_CURSOR does not work.
1551 SetCursor( wxNullCursor
);
1555 // -----------------------------------------------------------------------
1557 void wxPropertyGridManager::OnMouseMove( wxMouseEvent
&event
)
1559 if ( !m_pTxtHelpCaption
)
1564 if ( m_dragStatus
> 0 )
1566 int sy
= y
- m_dragOffset
;
1568 // Calculate drag limits
1569 int bottom_limit
= m_height
- m_splitterHeight
+ 1;
1570 int top_limit
= m_pPropGrid
->m_lineHeight
;
1572 if ( m_pToolbar
) top_limit
+= m_pToolbar
->GetSize().y
;
1575 if ( sy
>= top_limit
&& sy
< bottom_limit
)
1578 int change
= sy
- m_splitterY
;
1583 m_pPropGrid
->SetSize( m_width
, m_splitterY
- m_pPropGrid
->GetPosition().y
);
1584 UpdateDescriptionBox( m_splitterY
, m_width
, m_height
);
1586 m_extraHeight
-= change
;
1587 InvalidateBestSize();
1595 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1597 SetCursor ( m_cursorSizeNS
);
1604 SetCursor ( wxNullCursor
);
1611 // -----------------------------------------------------------------------
1613 void wxPropertyGridManager::OnMouseClick( wxMouseEvent
&event
)
1617 // Click on splitter.
1618 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1620 if ( m_dragStatus
== 0 )
1623 // Begin draggin the splitter
1630 m_dragOffset
= y
- m_splitterY
;
1636 // -----------------------------------------------------------------------
1638 void wxPropertyGridManager::OnMouseUp( wxMouseEvent
&event
)
1640 // No event type check - basicly calling this method should
1641 // just stop dragging.
1643 if ( m_dragStatus
>= 1 )
1646 // End Splitter Dragging
1651 // DO NOT ENABLE FOLLOWING LINE!
1652 // (it is only here as a reminder to not to do it)
1655 // This is necessary to return cursor
1658 // Set back the default cursor, if necessary
1659 if ( y
< m_splitterY
|| y
>= (m_splitterY
+m_splitterHeight
+2) )
1661 SetCursor ( wxNullCursor
);
1668 // -----------------------------------------------------------------------
1670 void wxPropertyGridManager::SetSplitterPosition( int pos
, int splitterColumn
)
1672 wxASSERT_MSG( GetPageCount(),
1673 wxT("SetSplitterPosition() has no effect until pages have been added") );
1676 for ( i
=0; i
<GetPageCount(); i
++ )
1678 wxPropertyGridPage
* page
= GetPage(i
);
1679 page
->DoSetSplitterPosition( pos
, splitterColumn
, false );
1682 m_pPropGrid
->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET
);
1685 // -----------------------------------------------------------------------
1686 // wxPGVIterator_Manager
1687 // -----------------------------------------------------------------------
1689 // Default returned by wxPropertyGridInterface::CreateVIterator().
1690 class wxPGVIteratorBase_Manager
: public wxPGVIteratorBase
1693 wxPGVIteratorBase_Manager( wxPropertyGridManager
* manager
, int flags
)
1694 : m_manager(manager
), m_flags(flags
), m_curPage(0)
1696 m_it
.Init(manager
->GetPage(0), flags
);
1698 virtual ~wxPGVIteratorBase_Manager() { }
1707 if ( m_curPage
< m_manager
->GetPageCount() )
1708 m_it
.Init( m_manager
->GetPage(m_curPage
), m_flags
);
1712 wxPropertyGridManager
* m_manager
;
1714 unsigned int m_curPage
;
1717 wxPGVIterator
wxPropertyGridManager::GetVIterator( int flags
) const
1719 return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager
*)this, flags
) );
1722 #endif // wxUSE_PROPGRID