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 m_pPropGrid
= CreatePropertyGrid();
287 bool res
= wxPanel::Create( parent
, id
, pos
, size
,
288 (style
&0xFFFF0000)|wxWANTS_CHARS
,
295 // -----------------------------------------------------------------------
298 // Initialize values to defaults
300 void wxPropertyGridManager::Init1()
308 m_pTxtHelpCaption
= NULL
;
309 m_pTxtHelpContent
= NULL
;
315 m_width
= m_height
= 0;
317 m_splitterHeight
= 5;
319 m_splitterY
= -1; // -1 causes default to be set.
321 m_nextDescBoxSize
= -1;
329 // -----------------------------------------------------------------------
331 // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager.
333 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxSIMPLE_BORDER| \
334 wxNO_FULL_REPAINT_ON_RESIZE| \
337 #define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxNO_BORDER| \
338 wxNO_FULL_REPAINT_ON_RESIZE| \
342 // Which flags can be passed to underlying wxPropertyGrid.
343 #define wxPG_MAN_PASS_FLAGS_MASK (0xFFF0|wxTAB_TRAVERSAL)
346 // Initialize after parent etc. set
348 void wxPropertyGridManager::Init2( int style
)
351 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
354 m_windowStyle
|= (style
&0x0000FFFF);
356 wxSize csz
= GetClientSize();
358 m_cursorSizeNS
= wxCursor(wxCURSOR_SIZENS
);
360 // Prepare the first page
361 // NB: But just prepare - you still need to call Add/InsertPage
362 // to actually add properties on it.
363 wxPropertyGridPage
* pd
= new wxPropertyGridPage();
364 pd
->m_isDefault
= true;
365 pd
->m_manager
= this;
366 wxPropertyGridPageState
* state
= pd
->GetStatePtr();
367 state
->m_pPropGrid
= m_pPropGrid
;
368 m_arrPages
.push_back( pd
);
369 m_pPropGrid
->m_pState
= state
;
371 wxWindowID baseId
= GetId();
372 wxWindowID useId
= baseId
;
374 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
379 // Smaller controls on Mac
380 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
383 // Create propertygrid.
384 m_pPropGrid
->Create(this,baseId
,wxPoint(0,0),csz
,
385 (m_windowStyle
&wxPG_MAN_PASS_FLAGS_MASK
)
386 |wxPG_MAN_PROPGRID_FORCED_FLAGS
);
388 m_pPropGrid
->m_eventObject
= this;
390 m_pPropGrid
->SetId(useId
);
392 m_pPropGrid
->m_iFlags
|= wxPG_FL_IN_MANAGER
;
394 m_pState
= m_pPropGrid
->m_pState
;
396 m_pPropGrid
->SetExtraStyle(wxPG_EX_INIT_NOCAT
);
398 m_nextTbInd
= baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
401 // Connect to property grid onselect event.
402 // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython
403 // (see wxPropertyGridManager::ProcessEvent).
404 Connect(m_pPropGrid
->GetId()/*wxID_ANY*/,
406 wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect
) );
408 // Connect to toolbar button events.
409 Connect(baseId
+ID_ADVTBITEMSBASE_OFFSET
,baseId
+ID_ADVTBITEMSBASE_OFFSET
+50,
410 wxEVT_COMMAND_TOOL_CLICKED
,
411 wxCommandEventHandler(wxPropertyGridManager::OnToolbarClick
) );
413 // Optional initial controls.
416 m_iFlags
|= wxPG_FL_INITIALIZED
;
420 // -----------------------------------------------------------------------
422 wxPropertyGridManager::~wxPropertyGridManager()
426 //m_pPropGrid->ClearSelection();
431 for ( i
=0; i
<m_arrPages
.size(); i
++ )
433 delete m_arrPages
[i
];
439 // -----------------------------------------------------------------------
441 wxPropertyGrid
* wxPropertyGridManager::CreatePropertyGrid() const
443 return new wxPropertyGrid();
446 // -----------------------------------------------------------------------
448 void wxPropertyGridManager::SetId( wxWindowID winid
)
450 wxWindow::SetId(winid
);
452 // TODO: Reconnect propgrid event handler(s).
454 m_pPropGrid
->SetId(winid
);
457 // -----------------------------------------------------------------------
459 wxSize
wxPropertyGridManager::DoGetBestSize() const
461 return wxSize(60,150);
464 // -----------------------------------------------------------------------
466 bool wxPropertyGridManager::SetFont( const wxFont
& font
)
468 bool res
= wxWindow::SetFont(font
);
469 m_pPropGrid
->SetFont(font
);
471 // TODO: Need to do caption recacalculations for other pages as well.
473 for ( i
=0; i
<m_arrPages
.size(); i
++ )
475 wxPropertyGridPage
* page
= GetPage(i
);
477 if ( page
!= m_pPropGrid
->GetState() )
478 page
->CalculateFontAndBitmapStuff(-1);
484 // -----------------------------------------------------------------------
486 void wxPropertyGridManager::SetExtraStyle( long exStyle
)
488 wxWindow::SetExtraStyle( exStyle
);
489 m_pPropGrid
->SetExtraStyle( exStyle
& 0xFFFFF000 );
491 if ( (exStyle
& wxPG_EX_NO_FLAT_TOOLBAR
) && m_pToolbar
)
496 // -----------------------------------------------------------------------
498 void wxPropertyGridManager::Freeze()
500 m_pPropGrid
->Freeze();
504 // -----------------------------------------------------------------------
506 void wxPropertyGridManager::Thaw()
512 // -----------------------------------------------------------------------
514 void wxPropertyGridManager::SetWindowStyleFlag( long style
)
516 int oldWindowStyle
= GetWindowStyleFlag();
518 wxWindow::SetWindowStyleFlag( style
);
519 m_pPropGrid
->SetWindowStyleFlag( (m_pPropGrid
->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK
)) |
520 (style
&wxPG_MAN_PASS_FLAGS_MASK
) );
522 // Need to re-position windows?
523 if ( (oldWindowStyle
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) !=
524 (style
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) )
530 // -----------------------------------------------------------------------
532 bool wxPropertyGridManager::Reparent( wxWindowBase
*newParent
)
535 m_pPropGrid
->OnTLPChanging((wxWindow
*)newParent
);
537 bool res
= wxPanel::Reparent(newParent
);
542 // -----------------------------------------------------------------------
544 // Actually shows given page.
545 bool wxPropertyGridManager::DoSelectPage( int index
)
547 // -1 means no page was selected
548 //wxASSERT( m_selPage >= 0 );
550 wxCHECK_MSG( index
>= -1 && index
< (int)GetPageCount(),
552 wxT("invalid page index") );
554 if ( m_selPage
== index
)
557 if ( m_pPropGrid
->GetSelection() )
559 if ( !m_pPropGrid
->ClearSelection() )
563 wxPropertyGridPage
* prevPage
;
565 if ( m_selPage
>= 0 )
566 prevPage
= GetPage(m_selPage
);
568 prevPage
= m_emptyPage
;
570 wxPropertyGridPage
* nextPage
;
574 nextPage
= m_arrPages
[index
];
582 m_emptyPage
= new wxPropertyGridPage();
583 m_emptyPage
->m_pPropGrid
= m_pPropGrid
;
586 nextPage
= m_emptyPage
;
589 m_iFlags
|= wxPG_FL_DESC_REFRESH_REQUIRED
;
591 m_pPropGrid
->SwitchState( nextPage
->GetStatePtr() );
593 m_pState
= m_pPropGrid
->m_pState
;
601 m_pToolbar
->ToggleTool( nextPage
->m_id
, true );
603 m_pToolbar
->ToggleTool( prevPage
->m_id
, false );
610 // -----------------------------------------------------------------------
612 // Changes page *and* set the target page for insertion operations.
613 void wxPropertyGridManager::SelectPage( int index
)
618 // -----------------------------------------------------------------------
620 int wxPropertyGridManager::GetPageByName( const wxString
& name
) const
623 for ( i
=0; i
<GetPageCount(); i
++ )
625 if ( m_arrPages
[i
]->m_label
== name
)
631 // -----------------------------------------------------------------------
633 int wxPropertyGridManager::GetPageByState( const wxPropertyGridPageState
* pState
) const
638 for ( i
=0; i
<GetPageCount(); i
++ )
640 if ( pState
== m_arrPages
[i
]->GetStatePtr() )
647 // -----------------------------------------------------------------------
649 const wxString
& wxPropertyGridManager::GetPageName( int index
) const
651 wxASSERT( index
>= 0 && index
< (int)GetPageCount() );
652 return m_arrPages
[index
]->m_label
;
655 // -----------------------------------------------------------------------
657 wxPropertyGridPageState
* wxPropertyGridManager::GetPageState( int page
) const
659 // Do not change this into wxCHECK because returning NULL is important
660 // for wxPropertyGridInterface page enumeration mechanics.
661 if ( page
>= (int)GetPageCount() )
666 return m_arrPages
[page
];
669 // -----------------------------------------------------------------------
671 void wxPropertyGridManager::Clear()
673 m_pPropGrid
->ClearSelection(false);
675 m_pPropGrid
->Freeze();
678 for ( i
=(int)GetPageCount()-1; i
>=0; i
-- )
682 m_nextTbInd
= m_baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
687 // -----------------------------------------------------------------------
689 void wxPropertyGridManager::ClearPage( int page
)
691 wxASSERT( page
>= 0 );
692 wxASSERT( page
< (int)GetPageCount() );
694 if ( page
>= 0 && page
< (int)GetPageCount() )
696 wxPropertyGridPageState
* state
= m_arrPages
[page
];
698 if ( state
== m_pPropGrid
->GetState() )
699 m_pPropGrid
->Clear();
705 // -----------------------------------------------------------------------
707 int wxPropertyGridManager::GetColumnCount( int page
) const
709 wxASSERT( page
>= -1 );
710 wxASSERT( page
< (int)GetPageCount() );
712 return GetPageState(page
)->GetColumnCount();
715 // -----------------------------------------------------------------------
717 void wxPropertyGridManager::SetColumnCount( int colCount
, int page
)
719 wxASSERT( page
>= -1 );
720 wxASSERT( page
< (int)GetPageCount() );
722 GetPageState(page
)->SetColumnCount( colCount
);
723 GetGrid()->Refresh();
725 // -----------------------------------------------------------------------
727 size_t wxPropertyGridManager::GetPageCount() const
729 if ( !(m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
) )
732 return m_arrPages
.size();
735 // -----------------------------------------------------------------------
737 wxPropertyGridPage
* wxPropertyGridManager::InsertPage( int index
,
738 const wxString
& label
,
740 wxPropertyGridPage
* pageObj
)
743 index
= GetPageCount();
745 wxCHECK_MSG( (size_t)index
== GetPageCount(), NULL
,
746 wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
748 bool needInit
= true;
749 bool isPageInserted
= m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
? true : false;
751 wxASSERT( index
== 0 || isPageInserted
);
755 // No custom page object was given, so we will either re-use the default base
756 // page (if index==0), or create a new default page object.
757 if ( !isPageInserted
)
759 pageObj
= GetPage(0);
760 // Of course, if the base page was custom, we need to delete and
762 if ( !pageObj
->m_isDefault
)
765 pageObj
= new wxPropertyGridPage();
766 m_arrPages
[0] = pageObj
;
772 pageObj
= new wxPropertyGridPage();
774 pageObj
->m_isDefault
= true;
778 if ( !isPageInserted
)
780 // Initial page needs to be deleted and replaced
782 m_arrPages
[0] = pageObj
;
783 m_pPropGrid
->m_pState
= pageObj
->GetStatePtr();
787 wxPropertyGridPageState
* state
= pageObj
->GetStatePtr();
789 pageObj
->m_manager
= this;
793 state
->m_pPropGrid
= m_pPropGrid
;
794 state
->InitNonCatMode();
797 if ( label
.length() )
799 wxASSERT_MSG( !pageObj
->m_label
.length(),
800 wxT("If page label is given in constructor, empty label must be given in AddPage"));
801 pageObj
->m_label
= label
;
804 pageObj
->m_id
= m_nextTbInd
;
806 if ( isPageInserted
)
807 m_arrPages
.push_back( pageObj
);
810 if ( m_windowStyle
& wxPG_TOOLBAR
)
815 if ( !(GetExtraStyle()&wxPG_EX_HIDE_PAGE_BUTTONS
) )
817 wxASSERT( m_pToolbar
);
819 // Add separator before first page.
820 if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) &&
821 m_pToolbar
->GetToolsCount() < 3 )
822 m_pToolbar
->AddSeparator();
824 if ( &bmp
!= &wxNullBitmap
)
825 m_pToolbar
->AddTool(m_nextTbInd
,label
,bmp
,label
,wxITEM_RADIO
);
826 //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
828 m_pToolbar
->AddTool(m_nextTbInd
,label
,wxBitmap( (const char**)gs_xpm_defpage
),
833 m_pToolbar
->Realize();
840 // If selected page was above the point of insertion, fix the current page index
841 if ( isPageInserted
)
843 if ( m_selPage
>= index
)
850 // Set this value only when adding the first page
856 m_iFlags
|= wxPG_MAN_FL_PAGE_INSERTED
;
858 wxASSERT( pageObj
->GetGrid() );
863 // -----------------------------------------------------------------------
865 bool wxPropertyGridManager::IsAnyModified() const
868 for ( i
=0; i
<GetPageCount(); i
++ )
870 if ( m_arrPages
[i
]->GetStatePtr()->m_anyModified
)
876 // -----------------------------------------------------------------------
878 bool wxPropertyGridManager::IsPageModified( size_t index
) const
880 if ( m_arrPages
[index
]->GetStatePtr()->m_anyModified
)
885 // -----------------------------------------------------------------------
887 bool wxPropertyGridManager::IsPropertySelected( wxPGPropArg id
) const
889 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
890 for ( unsigned int i
=0; i
<GetPageCount(); i
++ )
892 if ( GetPageState(i
)->DoIsPropertySelected(p
) )
898 // -----------------------------------------------------------------------
900 wxPGProperty
* wxPropertyGridManager::GetPageRoot( int index
) const
902 wxASSERT( index
>= 0 );
903 wxASSERT( index
< (int)m_arrPages
.size() );
905 return m_arrPages
[index
]->GetStatePtr()->m_properties
;
908 // -----------------------------------------------------------------------
910 bool wxPropertyGridManager::RemovePage( int page
)
912 wxCHECK_MSG( (page
>= 0) && (page
< (int)GetPageCount()),
914 wxT("invalid page index") );
916 wxPropertyGridPage
* pd
= m_arrPages
[page
];
918 if ( m_arrPages
.size() == 1 )
920 // Last page: do not remove page entry
921 m_pPropGrid
->Clear();
923 m_iFlags
&= ~wxPG_MAN_FL_PAGE_INSERTED
;
927 // Change selection if current is page
928 else if ( page
== m_selPage
)
930 if ( !m_pPropGrid
->ClearSelection() )
933 // Substitute page to select
934 int substitute
= page
- 1;
935 if ( substitute
< 0 )
936 substitute
= page
+ 1;
938 SelectPage(substitute
);
941 // Remove toolbar icon
943 if ( HasFlag(wxPG_TOOLBAR
) )
945 wxASSERT( m_pToolbar
);
947 int toolPos
= GetExtraStyle() & wxPG_EX_MODE_BUTTONS
? 3 : 0;
950 // Delete separator as well, for consistency
951 if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS
) &&
952 GetPageCount() == 1 )
953 m_pToolbar
->DeleteToolByPos(2);
955 m_pToolbar
->DeleteToolByPos(toolPos
);
959 if ( m_arrPages
.size() > 1 )
961 m_arrPages
.erase(m_arrPages
.begin() + page
);
965 // Adjust indexes that were above removed
966 if ( m_selPage
> page
)
972 // -----------------------------------------------------------------------
974 bool wxPropertyGridManager::ProcessEvent( wxEvent
& event
)
976 int evtType
= event
.GetEventType();
978 // NB: For some reason, under wxPython, Connect in Init doesn't work properly,
979 // so we'll need to call OnPropertyGridSelect manually. Multiple call's
980 // don't really matter.
981 if ( evtType
== wxEVT_PG_SELECTED
)
982 OnPropertyGridSelect((wxPropertyGridEvent
&)event
);
984 // Property grid events get special attention
985 if ( evtType
>= wxPG_BASE_EVT_TYPE
&&
986 evtType
< (wxPG_MAX_EVT_TYPE
) &&
989 wxPropertyGridPage
* page
= GetPage(m_selPage
);
990 wxPropertyGridEvent
* pgEvent
= wxDynamicCast(&event
, wxPropertyGridEvent
);
992 // Add property grid events to appropriate custom pages
993 // but stop propagating to parent if page says it is
994 // handling everything.
995 if ( pgEvent
&& !page
->m_isDefault
)
997 /*if ( pgEvent->IsPending() )
998 page->AddPendingEvent(event);
1000 page
->ProcessEvent(event
);
1002 if ( page
->IsHandlingAllEvents() )
1003 event
.StopPropagation();
1007 return wxPanel::ProcessEvent(event
);
1010 // -----------------------------------------------------------------------
1012 void wxPropertyGridManager::RepaintDescBoxDecorations( wxDC
& dc
,
1018 wxColour bgcol
= GetBackgroundColour();
1021 int rectHeight
= m_splitterHeight
;
1022 dc
.DrawRectangle(0, newSplitterY
, newWidth
, rectHeight
);
1023 dc
.SetPen( wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
) );
1024 int splitterBottom
= newSplitterY
+ m_splitterHeight
- 1;
1025 int boxHeight
= newHeight
- splitterBottom
;
1026 if ( boxHeight
> 1 )
1027 dc
.DrawRectangle(0, splitterBottom
, newWidth
, boxHeight
);
1029 dc
.DrawLine(0, splitterBottom
, newWidth
, splitterBottom
);
1032 // -----------------------------------------------------------------------
1034 void wxPropertyGridManager::UpdateDescriptionBox( int new_splittery
, int new_width
, int new_height
)
1036 int use_hei
= new_height
;
1039 // Fix help control positions.
1040 int cap_hei
= m_pPropGrid
->m_fontHeight
;
1041 int cap_y
= new_splittery
+m_splitterHeight
+5;
1042 int cnt_y
= cap_y
+cap_hei
+3;
1043 int sub_cap_hei
= cap_y
+cap_hei
-use_hei
;
1044 int cnt_hei
= use_hei
-cnt_y
;
1045 if ( sub_cap_hei
> 0 )
1047 cap_hei
-= sub_cap_hei
;
1052 m_pTxtHelpCaption
->Show( false );
1053 m_pTxtHelpContent
->Show( false );
1057 m_pTxtHelpCaption
->SetSize(3,cap_y
,new_width
-6,cap_hei
);
1058 m_pTxtHelpCaption
->Wrap(-1);
1059 m_pTxtHelpCaption
->Show( true );
1062 m_pTxtHelpContent
->Show( false );
1066 m_pTxtHelpContent
->SetSize(3,cnt_y
,new_width
-6,cnt_hei
);
1067 m_pTxtHelpContent
->Show( true );
1071 wxRect
r(0, new_splittery
, new_width
, new_height
-new_splittery
);
1074 m_splitterY
= new_splittery
;
1076 m_iFlags
&= ~(wxPG_FL_DESC_REFRESH_REQUIRED
);
1079 // -----------------------------------------------------------------------
1081 void wxPropertyGridManager::RecalculatePositions( int width
, int height
)
1084 int propgridBottomY
= height
;
1086 // Toolbar at the top.
1090 m_pToolbar
->SetSize(0, 0, width
, -1);
1091 propgridY
+= m_pToolbar
->GetSize().y
;
1096 if ( m_pTxtHelpCaption
)
1098 int new_splittery
= m_splitterY
;
1101 if ( ( m_splitterY
>= 0 || m_nextDescBoxSize
) && m_height
> 32 )
1103 if ( m_nextDescBoxSize
>= 0 )
1105 new_splittery
= m_height
- m_nextDescBoxSize
- m_splitterHeight
;
1106 m_nextDescBoxSize
= -1;
1108 new_splittery
+= (height
-m_height
);
1112 new_splittery
= height
- wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y
;
1113 if ( new_splittery
< 32 )
1117 // Check if beyond minimum.
1118 int nspy_min
= propgridY
+ m_pPropGrid
->m_lineHeight
;
1119 if ( new_splittery
< nspy_min
)
1120 new_splittery
= nspy_min
;
1122 propgridBottomY
= new_splittery
;
1124 UpdateDescriptionBox( new_splittery
, width
, height
);
1127 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1129 int pgh
= propgridBottomY
- propgridY
;
1132 m_pPropGrid
->SetSize( 0, propgridY
, width
, pgh
);
1134 m_extraHeight
= height
- pgh
;
1141 // -----------------------------------------------------------------------
1143 void wxPropertyGridManager::SetDescBoxHeight( int ht
, bool refresh
)
1145 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1147 if ( ht
!= GetDescBoxHeight() )
1149 m_nextDescBoxSize
= ht
;
1151 RecalculatePositions(m_width
, m_height
);
1156 // -----------------------------------------------------------------------
1158 int wxPropertyGridManager::GetDescBoxHeight() const
1160 return GetClientSize().y
- m_splitterY
- m_splitterHeight
;
1163 // -----------------------------------------------------------------------
1165 void wxPropertyGridManager::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1169 // Update everything inside the box
1170 wxRect r
= GetUpdateRegion().GetBox();
1172 // Repaint splitter and any other description box decorations
1173 if ( (r
.y
+ r
.height
) >= m_splitterY
)
1174 RepaintDescBoxDecorations( dc
, m_splitterY
, m_width
, m_height
);
1177 // -----------------------------------------------------------------------
1179 void wxPropertyGridManager::Refresh(bool eraseBackground
, const wxRect
* rect
)
1181 m_pPropGrid
->Refresh(eraseBackground
);
1182 wxWindow::Refresh(eraseBackground
,rect
);
1185 // -----------------------------------------------------------------------
1187 void wxPropertyGridManager::RefreshProperty( wxPGProperty
* p
)
1189 wxPropertyGrid
* grid
= p
->GetGrid();
1191 if ( GetPage(m_selPage
)->GetStatePtr() == p
->GetParent()->GetParentState() )
1192 grid
->RefreshProperty(p
);
1195 // -----------------------------------------------------------------------
1197 void wxPropertyGridManager::RecreateControls()
1200 bool was_shown
= IsShown();
1204 wxWindowID baseId
= m_pPropGrid
->GetId();
1206 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1209 if ( m_windowStyle
& wxPG_TOOLBAR
)
1214 m_pToolbar
= new wxToolBar(this,baseId
+ID_ADVTOOLBAR_OFFSET
,
1215 wxDefaultPosition
,wxDefaultSize
,
1216 ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR
)?0:wxTB_FLAT
)
1217 /*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
1218 m_pToolbar
->SetToolBitmapSize(wxSize(16, 15));
1220 #if defined(__WXMSW__)
1221 // Eliminate toolbar flicker on XP
1222 // NOTE: Not enabled since it corrupts drawing somewhat.
1225 #ifndef WS_EX_COMPOSITED
1226 #define WS_EX_COMPOSITED 0x02000000L
1229 HWND hWnd = (HWND)m_pToolbar->GetHWND();
1231 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1232 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1237 m_pToolbar
->SetCursor ( *wxSTANDARD_CURSOR
);
1239 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1241 wxString
desc1(_("Categorized Mode"));
1242 wxString
desc2(_("Alphabetic Mode"));
1243 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+0,
1244 desc1
,wxBitmap ( (const char**)gs_xpm_catmode
),
1245 desc1
,wxITEM_RADIO
);
1246 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+1,
1247 desc2
,wxBitmap ( (const char**)gs_xpm_noncatmode
),
1248 desc2
,wxITEM_RADIO
);
1249 m_pToolbar
->Realize();
1254 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1256 // Toggle correct mode button.
1257 // TODO: This doesn't work in wxMSW (when changing,
1258 // both items will get toggled).
1259 int toggle_but_on_ind
= ID_ADVTBITEMSBASE_OFFSET
+0;
1260 int toggle_but_off_ind
= ID_ADVTBITEMSBASE_OFFSET
+1;
1261 if ( m_pPropGrid
->m_pState
->IsInNonCatMode() )
1263 toggle_but_on_ind
++;
1264 toggle_but_off_ind
--;
1267 m_pToolbar
->ToggleTool(baseId
+toggle_but_on_ind
,true);
1268 m_pToolbar
->ToggleTool(baseId
+toggle_but_off_ind
,false);
1276 m_pToolbar
->Destroy();
1281 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1284 m_pPropGrid
->m_iFlags
|= (wxPG_FL_NOSTATUSBARHELP
);
1286 if ( !m_pTxtHelpCaption
)
1288 m_pTxtHelpCaption
= new wxStaticText(this,
1289 baseId
+ID_ADVHELPCAPTION_OFFSET
,
1293 wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1294 m_pTxtHelpCaption
->SetFont( m_pPropGrid
->m_captionFont
);
1295 m_pTxtHelpCaption
->SetCursor( *wxSTANDARD_CURSOR
);
1297 if ( !m_pTxtHelpContent
)
1299 m_pTxtHelpContent
= new wxStaticText(this,
1300 baseId
+ID_ADVHELPCONTENT_OFFSET
,
1304 wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1305 m_pTxtHelpContent
->SetCursor( *wxSTANDARD_CURSOR
);
1308 SetDescribedProperty(GetSelection());
1313 m_pPropGrid
->m_iFlags
&= ~(wxPG_FL_NOSTATUSBARHELP
);
1315 if ( m_pTxtHelpCaption
)
1316 m_pTxtHelpCaption
->Destroy();
1318 m_pTxtHelpCaption
= NULL
;
1320 if ( m_pTxtHelpContent
)
1321 m_pTxtHelpContent
->Destroy();
1323 m_pTxtHelpContent
= NULL
;
1328 GetClientSize(&width
,&height
);
1330 RecalculatePositions(width
,height
);
1336 // -----------------------------------------------------------------------
1338 wxPGProperty
* wxPropertyGridManager::DoGetPropertyByName( const wxString
& name
) const
1341 for ( i
=0; i
<GetPageCount(); i
++ )
1343 wxPropertyGridPageState
* pState
= m_arrPages
[i
]->GetStatePtr();
1344 wxPGProperty
* p
= pState
->BaseGetPropertyByName(name
);
1353 // -----------------------------------------------------------------------
1355 bool wxPropertyGridManager::EnsureVisible( wxPGPropArg id
)
1357 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1359 wxPropertyGridPageState
* parentState
= p
->GetParentState();
1361 // Select correct page.
1362 if ( m_pPropGrid
->m_pState
!= parentState
)
1363 DoSelectPage( GetPageByState(parentState
) );
1365 return m_pPropGrid
->EnsureVisible(id
);
1368 // -----------------------------------------------------------------------
1370 void wxPropertyGridManager::OnToolbarClick( wxCommandEvent
&event
)
1372 int id
= event
.GetId();
1375 int baseId
= m_pPropGrid
->GetId();
1377 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1379 if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 0 ) )
1381 // Categorized mode.
1382 if ( m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
)
1384 if ( !m_pPropGrid
->HasInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
) )
1385 m_pPropGrid
->m_windowStyle
&= ~wxPG_AUTO_SORT
;
1386 m_pPropGrid
->EnableCategories( true );
1389 else if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 1 ) )
1392 if ( !(m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
1394 if ( m_pPropGrid
->HasFlag(wxPG_AUTO_SORT
) )
1395 m_pPropGrid
->SetInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1397 m_pPropGrid
->ClearInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1399 m_pPropGrid
->m_windowStyle
|= wxPG_AUTO_SORT
;
1400 m_pPropGrid
->EnableCategories( false );
1409 wxPropertyGridPage
* pdc
;
1411 // Find page with given id.
1412 for ( i
=0; i
<GetPageCount(); i
++ )
1414 pdc
= m_arrPages
[i
];
1415 if ( pdc
->m_id
== id
)
1422 wxASSERT( index
>= 0 );
1424 if ( DoSelectPage( index
) )
1427 // Event dispatching must be last.
1428 m_pPropGrid
->SendEvent( wxEVT_PG_PAGE_CHANGED
, NULL
);
1433 // TODO: Depress the old button on toolbar.
1440 // -----------------------------------------------------------------------
1442 bool wxPropertyGridManager::SetEditableStateItem( const wxString
& name
, wxVariant value
)
1444 if ( name
== wxS("descboxheight") )
1446 SetDescBoxHeight(value
.GetLong(), true);
1452 // -----------------------------------------------------------------------
1454 wxVariant
wxPropertyGridManager::GetEditableStateItem( const wxString
& name
) const
1456 if ( name
== wxS("descboxheight") )
1458 return (long) GetDescBoxHeight();
1460 return wxNullVariant
;
1463 // -----------------------------------------------------------------------
1465 void wxPropertyGridManager::SetDescription( const wxString
& label
, const wxString
& content
)
1467 if ( m_pTxtHelpCaption
)
1469 wxSize osz1
= m_pTxtHelpCaption
->GetSize();
1470 wxSize osz2
= m_pTxtHelpContent
->GetSize();
1472 m_pTxtHelpCaption
->SetLabel(label
);
1473 m_pTxtHelpContent
->SetLabel(content
);
1475 m_pTxtHelpCaption
->SetSize(-1,osz1
.y
);
1476 m_pTxtHelpContent
->SetSize(-1,osz2
.y
);
1478 UpdateDescriptionBox( m_splitterY
, m_width
, m_height
);
1482 // -----------------------------------------------------------------------
1484 void wxPropertyGridManager::SetDescribedProperty( wxPGProperty
* p
)
1486 if ( m_pTxtHelpCaption
)
1490 SetDescription( p
->GetLabel(), p
->GetHelpString() );
1494 SetDescription( wxEmptyString
, wxEmptyString
);
1499 // -----------------------------------------------------------------------
1501 void wxPropertyGridManager::SetSplitterLeft( bool subProps
, bool allPages
)
1505 m_pPropGrid
->SetSplitterLeft(subProps
);
1509 wxClientDC
dc(this);
1510 dc
.SetFont(m_pPropGrid
->GetFont());
1515 for ( i
=0; i
<GetPageCount(); i
++ )
1517 int maxW
= m_pState
->GetColumnFitWidth(dc
, m_arrPages
[i
]->m_properties
, 0, subProps
);
1518 maxW
+= m_pPropGrid
->m_marginWidth
;
1519 if ( maxW
> highest
)
1524 m_pPropGrid
->SetSplitterPosition( highest
);
1526 m_pPropGrid
->m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
1530 // -----------------------------------------------------------------------
1532 void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
1535 wxASSERT_MSG( GetId() == m_pPropGrid
->GetId(),
1536 wxT("wxPropertyGridManager id must be set with wxPropertyGridManager::SetId (not wxWindow::SetId).") );
1538 SetDescribedProperty(event
.GetProperty());
1542 // -----------------------------------------------------------------------
1544 void wxPropertyGridManager::OnResize( wxSizeEvent
& WXUNUSED(event
) )
1548 GetClientSize(&width
,&height
);
1550 if ( m_width
== -12345 )
1553 RecalculatePositions(width
,height
);
1556 // -----------------------------------------------------------------------
1558 void wxPropertyGridManager::OnMouseEntry( wxMouseEvent
& WXUNUSED(event
) )
1560 // Correct cursor. This is required atleast for wxGTK, for which
1561 // setting button's cursor to *wxSTANDARD_CURSOR does not work.
1562 SetCursor( wxNullCursor
);
1566 // -----------------------------------------------------------------------
1568 void wxPropertyGridManager::OnMouseMove( wxMouseEvent
&event
)
1570 if ( !m_pTxtHelpCaption
)
1575 if ( m_dragStatus
> 0 )
1577 int sy
= y
- m_dragOffset
;
1579 // Calculate drag limits
1580 int bottom_limit
= m_height
- m_splitterHeight
+ 1;
1581 int top_limit
= m_pPropGrid
->m_lineHeight
;
1583 if ( m_pToolbar
) top_limit
+= m_pToolbar
->GetSize().y
;
1586 if ( sy
>= top_limit
&& sy
< bottom_limit
)
1589 int change
= sy
- m_splitterY
;
1594 m_pPropGrid
->SetSize( m_width
, m_splitterY
- m_pPropGrid
->GetPosition().y
);
1595 UpdateDescriptionBox( m_splitterY
, m_width
, m_height
);
1597 m_extraHeight
-= change
;
1598 InvalidateBestSize();
1606 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1608 SetCursor ( m_cursorSizeNS
);
1615 SetCursor ( wxNullCursor
);
1622 // -----------------------------------------------------------------------
1624 void wxPropertyGridManager::OnMouseClick( wxMouseEvent
&event
)
1628 // Click on splitter.
1629 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1631 if ( m_dragStatus
== 0 )
1634 // Begin draggin the splitter
1641 m_dragOffset
= y
- m_splitterY
;
1647 // -----------------------------------------------------------------------
1649 void wxPropertyGridManager::OnMouseUp( wxMouseEvent
&event
)
1651 // No event type check - basicly calling this method should
1652 // just stop dragging.
1654 if ( m_dragStatus
>= 1 )
1657 // End Splitter Dragging
1662 // DO NOT ENABLE FOLLOWING LINE!
1663 // (it is only here as a reminder to not to do it)
1666 // This is necessary to return cursor
1669 // Set back the default cursor, if necessary
1670 if ( y
< m_splitterY
|| y
>= (m_splitterY
+m_splitterHeight
+2) )
1672 SetCursor ( wxNullCursor
);
1679 // -----------------------------------------------------------------------
1681 void wxPropertyGridManager::SetSplitterPosition( int pos
, int splitterColumn
)
1683 wxASSERT_MSG( GetPageCount(),
1684 wxT("SetSplitterPosition() has no effect until pages have been added") );
1687 for ( i
=0; i
<GetPageCount(); i
++ )
1689 wxPropertyGridPage
* page
= GetPage(i
);
1690 page
->DoSetSplitterPosition( pos
, splitterColumn
, false );
1693 m_pPropGrid
->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET
);
1696 // -----------------------------------------------------------------------
1697 // wxPGVIterator_Manager
1698 // -----------------------------------------------------------------------
1700 // Default returned by wxPropertyGridInterface::CreateVIterator().
1701 class wxPGVIteratorBase_Manager
: public wxPGVIteratorBase
1704 wxPGVIteratorBase_Manager( wxPropertyGridManager
* manager
, int flags
)
1705 : m_manager(manager
), m_flags(flags
), m_curPage(0)
1707 m_it
.Init(manager
->GetPage(0), flags
);
1709 virtual ~wxPGVIteratorBase_Manager() { }
1718 if ( m_curPage
< m_manager
->GetPageCount() )
1719 m_it
.Init( m_manager
->GetPage(m_curPage
), m_flags
);
1723 wxPropertyGridManager
* m_manager
;
1725 unsigned int m_curPage
;
1728 wxPGVIterator
wxPropertyGridManager::GetVIterator( int flags
) const
1730 return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager
*)this, flags
) );
1733 #endif // wxUSE_PROPGRID