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
,
292 // FIXME: this changes call ordering so wxPropertyGrid is created
293 // immediately, before SetExtraStyle has a chance to be called. However,
294 // without it, we may get assertions if size is wxDefaultSize.
295 //SetInitialSize(size);
300 // -----------------------------------------------------------------------
303 // Initialize values to defaults
305 void wxPropertyGridManager::Init1()
313 m_pTxtHelpCaption
= NULL
;
314 m_pTxtHelpContent
= NULL
;
320 m_width
= m_height
= 0;
322 m_splitterHeight
= 5;
324 m_splitterY
= -1; // -1 causes default to be set.
326 m_nextDescBoxSize
= -1;
334 // -----------------------------------------------------------------------
336 // These flags are always used in wxPropertyGrid integrated in wxPropertyGridManager.
337 #define wxPG_MAN_PROPGRID_FORCED_FLAGS ( wxBORDER_THEME | \
338 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 long propGridFlags
= (m_windowStyle
&wxPG_MAN_PASS_FLAGS_MASK
)
383 |wxPG_MAN_PROPGRID_FORCED_FLAGS
;
385 propGridFlags
&= ~wxBORDER_MASK
;
387 if ((style
& wxPG_NO_INTERNAL_BORDER
) == 0)
389 propGridFlags
|= wxBORDER_THEME
;
393 propGridFlags
|= wxBORDER_NONE
;
394 wxWindow::SetExtraStyle(wxPG_EX_TOOLBAR_SEPARATOR
);
397 // Create propertygrid.
398 m_pPropGrid
->Create(this,baseId
,wxPoint(0,0),csz
, propGridFlags
);
400 m_pPropGrid
->m_eventObject
= this;
402 m_pPropGrid
->SetId(useId
);
404 m_pPropGrid
->m_iFlags
|= wxPG_FL_IN_MANAGER
;
406 m_pState
= m_pPropGrid
->m_pState
;
408 m_pPropGrid
->SetExtraStyle(wxPG_EX_INIT_NOCAT
);
410 m_nextTbInd
= baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
413 // Connect to property grid onselect event.
414 // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython
415 // (see wxPropertyGridManager::ProcessEvent).
416 Connect(m_pPropGrid
->GetId()/*wxID_ANY*/,
418 wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect
) );
420 // Connect to toolbar button events.
421 Connect(baseId
+ID_ADVTBITEMSBASE_OFFSET
,baseId
+ID_ADVTBITEMSBASE_OFFSET
+50,
422 wxEVT_COMMAND_TOOL_CLICKED
,
423 wxCommandEventHandler(wxPropertyGridManager::OnToolbarClick
) );
425 // Optional initial controls.
428 m_iFlags
|= wxPG_FL_INITIALIZED
;
432 // -----------------------------------------------------------------------
434 wxPropertyGridManager::~wxPropertyGridManager()
438 //m_pPropGrid->ClearSelection();
443 for ( i
=0; i
<m_arrPages
.size(); i
++ )
445 delete m_arrPages
[i
];
451 // -----------------------------------------------------------------------
453 wxPropertyGrid
* wxPropertyGridManager::CreatePropertyGrid() const
455 return new wxPropertyGrid();
458 // -----------------------------------------------------------------------
460 void wxPropertyGridManager::SetId( wxWindowID winid
)
462 wxWindow::SetId(winid
);
464 // TODO: Reconnect propgrid event handler(s).
466 m_pPropGrid
->SetId(winid
);
469 // -----------------------------------------------------------------------
471 wxSize
wxPropertyGridManager::DoGetBestSize() const
473 return wxSize(60,150);
476 // -----------------------------------------------------------------------
478 bool wxPropertyGridManager::SetFont( const wxFont
& font
)
480 bool res
= wxWindow::SetFont(font
);
481 m_pPropGrid
->SetFont(font
);
483 // TODO: Need to do caption recacalculations for other pages as well.
485 for ( i
=0; i
<m_arrPages
.size(); i
++ )
487 wxPropertyGridPage
* page
= GetPage(i
);
489 if ( page
!= m_pPropGrid
->GetState() )
490 page
->CalculateFontAndBitmapStuff(-1);
496 // -----------------------------------------------------------------------
498 void wxPropertyGridManager::SetExtraStyle( long exStyle
)
500 wxWindow::SetExtraStyle( exStyle
);
501 m_pPropGrid
->SetExtraStyle( exStyle
& 0xFFFFF000 );
503 if ( (exStyle
& wxPG_EX_NO_FLAT_TOOLBAR
) && m_pToolbar
)
508 // -----------------------------------------------------------------------
510 void wxPropertyGridManager::Freeze()
512 m_pPropGrid
->Freeze();
516 // -----------------------------------------------------------------------
518 void wxPropertyGridManager::Thaw()
524 // -----------------------------------------------------------------------
526 void wxPropertyGridManager::SetWindowStyleFlag( long style
)
528 int oldWindowStyle
= GetWindowStyleFlag();
530 wxWindow::SetWindowStyleFlag( style
);
531 m_pPropGrid
->SetWindowStyleFlag( (m_pPropGrid
->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK
)) |
532 (style
&wxPG_MAN_PASS_FLAGS_MASK
) );
534 // Need to re-position windows?
535 if ( (oldWindowStyle
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) !=
536 (style
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) )
542 // -----------------------------------------------------------------------
544 bool wxPropertyGridManager::Reparent( wxWindowBase
*newParent
)
547 m_pPropGrid
->OnTLPChanging((wxWindow
*)newParent
);
549 bool res
= wxPanel::Reparent(newParent
);
554 // -----------------------------------------------------------------------
556 // Actually shows given page.
557 bool wxPropertyGridManager::DoSelectPage( int index
)
559 // -1 means no page was selected
560 //wxASSERT( m_selPage >= 0 );
562 wxCHECK_MSG( index
>= -1 && index
< (int)GetPageCount(),
564 wxT("invalid page index") );
566 if ( m_selPage
== index
)
569 if ( m_pPropGrid
->GetSelection() )
571 if ( !m_pPropGrid
->ClearSelection() )
575 wxPropertyGridPage
* prevPage
;
577 if ( m_selPage
>= 0 )
578 prevPage
= GetPage(m_selPage
);
580 prevPage
= m_emptyPage
;
582 wxPropertyGridPage
* nextPage
;
586 nextPage
= m_arrPages
[index
];
594 m_emptyPage
= new wxPropertyGridPage();
595 m_emptyPage
->m_pPropGrid
= m_pPropGrid
;
598 nextPage
= m_emptyPage
;
601 m_iFlags
|= wxPG_FL_DESC_REFRESH_REQUIRED
;
603 m_pPropGrid
->SwitchState( nextPage
->GetStatePtr() );
605 m_pState
= m_pPropGrid
->m_pState
;
613 m_pToolbar
->ToggleTool( nextPage
->m_id
, true );
615 m_pToolbar
->ToggleTool( prevPage
->m_id
, false );
622 // -----------------------------------------------------------------------
624 // Changes page *and* set the target page for insertion operations.
625 void wxPropertyGridManager::SelectPage( int index
)
630 // -----------------------------------------------------------------------
632 int wxPropertyGridManager::GetPageByName( const wxString
& name
) const
635 for ( i
=0; i
<GetPageCount(); i
++ )
637 if ( m_arrPages
[i
]->m_label
== name
)
643 // -----------------------------------------------------------------------
645 int wxPropertyGridManager::GetPageByState( const wxPropertyGridPageState
* pState
) const
650 for ( i
=0; i
<GetPageCount(); i
++ )
652 if ( pState
== m_arrPages
[i
]->GetStatePtr() )
659 // -----------------------------------------------------------------------
661 const wxString
& wxPropertyGridManager::GetPageName( int index
) const
663 wxASSERT( index
>= 0 && index
< (int)GetPageCount() );
664 return m_arrPages
[index
]->m_label
;
667 // -----------------------------------------------------------------------
669 wxPropertyGridPageState
* wxPropertyGridManager::GetPageState( int page
) const
671 // Do not change this into wxCHECK because returning NULL is important
672 // for wxPropertyGridInterface page enumeration mechanics.
673 if ( page
>= (int)GetPageCount() )
678 return m_arrPages
[page
];
681 // -----------------------------------------------------------------------
683 void wxPropertyGridManager::Clear()
685 m_pPropGrid
->ClearSelection(false);
687 m_pPropGrid
->Freeze();
690 for ( i
=(int)GetPageCount()-1; i
>=0; i
-- )
694 m_nextTbInd
= m_baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
699 // -----------------------------------------------------------------------
701 void wxPropertyGridManager::ClearPage( int page
)
703 wxASSERT( page
>= 0 );
704 wxASSERT( page
< (int)GetPageCount() );
706 if ( page
>= 0 && page
< (int)GetPageCount() )
708 wxPropertyGridPageState
* state
= m_arrPages
[page
];
710 if ( state
== m_pPropGrid
->GetState() )
711 m_pPropGrid
->Clear();
717 // -----------------------------------------------------------------------
719 int wxPropertyGridManager::GetColumnCount( int page
) const
721 wxASSERT( page
>= -1 );
722 wxASSERT( page
< (int)GetPageCount() );
724 return GetPageState(page
)->GetColumnCount();
727 // -----------------------------------------------------------------------
729 void wxPropertyGridManager::SetColumnCount( int colCount
, int page
)
731 wxASSERT( page
>= -1 );
732 wxASSERT( page
< (int)GetPageCount() );
734 GetPageState(page
)->SetColumnCount( colCount
);
735 GetGrid()->Refresh();
737 // -----------------------------------------------------------------------
739 size_t wxPropertyGridManager::GetPageCount() const
741 if ( !(m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
) )
744 return m_arrPages
.size();
747 // -----------------------------------------------------------------------
749 wxPropertyGridPage
* wxPropertyGridManager::InsertPage( int index
,
750 const wxString
& label
,
752 wxPropertyGridPage
* pageObj
)
755 index
= GetPageCount();
757 wxCHECK_MSG( (size_t)index
== GetPageCount(), NULL
,
758 wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
760 bool needInit
= true;
761 bool isPageInserted
= m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
? true : false;
763 wxASSERT( index
== 0 || isPageInserted
);
767 // No custom page object was given, so we will either re-use the default base
768 // page (if index==0), or create a new default page object.
769 if ( !isPageInserted
)
771 pageObj
= GetPage(0);
772 // Of course, if the base page was custom, we need to delete and
774 if ( !pageObj
->m_isDefault
)
777 pageObj
= new wxPropertyGridPage();
778 m_arrPages
[0] = pageObj
;
784 pageObj
= new wxPropertyGridPage();
786 pageObj
->m_isDefault
= true;
790 if ( !isPageInserted
)
792 // Initial page needs to be deleted and replaced
794 m_arrPages
[0] = pageObj
;
795 m_pPropGrid
->m_pState
= pageObj
->GetStatePtr();
799 wxPropertyGridPageState
* state
= pageObj
->GetStatePtr();
801 pageObj
->m_manager
= this;
805 state
->m_pPropGrid
= m_pPropGrid
;
806 state
->InitNonCatMode();
809 if ( label
.length() )
811 wxASSERT_MSG( !pageObj
->m_label
.length(),
812 wxT("If page label is given in constructor, empty label must be given in AddPage"));
813 pageObj
->m_label
= label
;
816 pageObj
->m_id
= m_nextTbInd
;
818 if ( isPageInserted
)
819 m_arrPages
.push_back( pageObj
);
822 if ( m_windowStyle
& wxPG_TOOLBAR
)
827 if ( !(GetExtraStyle()&wxPG_EX_HIDE_PAGE_BUTTONS
) )
829 wxASSERT( m_pToolbar
);
831 // Add separator before first page.
832 if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) &&
833 m_pToolbar
->GetToolsCount() < 3 )
834 m_pToolbar
->AddSeparator();
836 if ( &bmp
!= &wxNullBitmap
)
837 m_pToolbar
->AddTool(m_nextTbInd
,label
,bmp
,label
,wxITEM_RADIO
);
838 //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
840 m_pToolbar
->AddTool(m_nextTbInd
,label
,wxBitmap( (const char**)gs_xpm_defpage
),
845 m_pToolbar
->Realize();
852 // If selected page was above the point of insertion, fix the current page index
853 if ( isPageInserted
)
855 if ( m_selPage
>= index
)
862 // Set this value only when adding the first page
868 m_iFlags
|= wxPG_MAN_FL_PAGE_INSERTED
;
870 wxASSERT( pageObj
->GetGrid() );
875 // -----------------------------------------------------------------------
877 bool wxPropertyGridManager::IsAnyModified() const
880 for ( i
=0; i
<GetPageCount(); i
++ )
882 if ( m_arrPages
[i
]->GetStatePtr()->m_anyModified
)
888 // -----------------------------------------------------------------------
890 bool wxPropertyGridManager::IsPageModified( size_t index
) const
892 if ( m_arrPages
[index
]->GetStatePtr()->m_anyModified
)
897 // -----------------------------------------------------------------------
899 bool wxPropertyGridManager::IsPropertySelected( wxPGPropArg id
) const
901 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
902 for ( unsigned int i
=0; i
<GetPageCount(); i
++ )
904 if ( GetPageState(i
)->DoIsPropertySelected(p
) )
910 // -----------------------------------------------------------------------
912 wxPGProperty
* wxPropertyGridManager::GetPageRoot( int index
) const
914 wxASSERT( index
>= 0 );
915 wxASSERT( index
< (int)m_arrPages
.size() );
917 return m_arrPages
[index
]->GetStatePtr()->m_properties
;
920 // -----------------------------------------------------------------------
922 bool wxPropertyGridManager::RemovePage( int page
)
924 wxCHECK_MSG( (page
>= 0) && (page
< (int)GetPageCount()),
926 wxT("invalid page index") );
928 wxPropertyGridPage
* pd
= m_arrPages
[page
];
930 if ( m_arrPages
.size() == 1 )
932 // Last page: do not remove page entry
933 m_pPropGrid
->Clear();
935 m_iFlags
&= ~wxPG_MAN_FL_PAGE_INSERTED
;
939 // Change selection if current is page
940 else if ( page
== m_selPage
)
942 if ( !m_pPropGrid
->ClearSelection() )
945 // Substitute page to select
946 int substitute
= page
- 1;
947 if ( substitute
< 0 )
948 substitute
= page
+ 1;
950 SelectPage(substitute
);
953 // Remove toolbar icon
955 if ( HasFlag(wxPG_TOOLBAR
) )
957 wxASSERT( m_pToolbar
);
959 int toolPos
= GetExtraStyle() & wxPG_EX_MODE_BUTTONS
? 3 : 0;
962 // Delete separator as well, for consistency
963 if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS
) &&
964 GetPageCount() == 1 )
965 m_pToolbar
->DeleteToolByPos(2);
967 m_pToolbar
->DeleteToolByPos(toolPos
);
971 if ( m_arrPages
.size() > 1 )
973 m_arrPages
.erase(m_arrPages
.begin() + page
);
977 // Adjust indexes that were above removed
978 if ( m_selPage
> page
)
984 // -----------------------------------------------------------------------
986 bool wxPropertyGridManager::ProcessEvent( wxEvent
& event
)
988 int evtType
= event
.GetEventType();
990 // NB: For some reason, under wxPython, Connect in Init doesn't work properly,
991 // so we'll need to call OnPropertyGridSelect manually. Multiple call's
992 // don't really matter.
993 if ( evtType
== wxEVT_PG_SELECTED
)
994 OnPropertyGridSelect((wxPropertyGridEvent
&)event
);
996 // Property grid events get special attention
997 if ( evtType
>= wxPG_BASE_EVT_TYPE
&&
998 evtType
< (wxPG_MAX_EVT_TYPE
) &&
1001 wxPropertyGridPage
* page
= GetPage(m_selPage
);
1002 wxPropertyGridEvent
* pgEvent
= wxDynamicCast(&event
, wxPropertyGridEvent
);
1004 // Add property grid events to appropriate custom pages
1005 // but stop propagating to parent if page says it is
1006 // handling everything.
1007 if ( pgEvent
&& !page
->m_isDefault
)
1009 /*if ( pgEvent->IsPending() )
1010 page->AddPendingEvent(event);
1012 page
->ProcessEvent(event
);
1014 if ( page
->IsHandlingAllEvents() )
1015 event
.StopPropagation();
1019 return wxPanel::ProcessEvent(event
);
1022 // -----------------------------------------------------------------------
1024 void wxPropertyGridManager::RepaintDescBoxDecorations( wxDC
& dc
,
1030 wxColour bgcol
= GetBackgroundColour();
1033 int rectHeight
= m_splitterHeight
;
1034 dc
.DrawRectangle(0, newSplitterY
, newWidth
, rectHeight
);
1035 dc
.SetPen( wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
) );
1036 int splitterBottom
= newSplitterY
+ m_splitterHeight
- 1;
1037 int boxHeight
= newHeight
- splitterBottom
;
1038 if ( boxHeight
> 1 )
1039 dc
.DrawRectangle(0, splitterBottom
, newWidth
, boxHeight
);
1041 dc
.DrawLine(0, splitterBottom
, newWidth
, splitterBottom
);
1044 // -----------------------------------------------------------------------
1046 void wxPropertyGridManager::UpdateDescriptionBox( int new_splittery
, int new_width
, int new_height
)
1048 int use_hei
= new_height
;
1051 // Fix help control positions.
1052 int cap_hei
= m_pPropGrid
->m_fontHeight
;
1053 int cap_y
= new_splittery
+m_splitterHeight
+5;
1054 int cnt_y
= cap_y
+cap_hei
+3;
1055 int sub_cap_hei
= cap_y
+cap_hei
-use_hei
;
1056 int cnt_hei
= use_hei
-cnt_y
;
1057 if ( sub_cap_hei
> 0 )
1059 cap_hei
-= sub_cap_hei
;
1064 m_pTxtHelpCaption
->Show( false );
1065 m_pTxtHelpContent
->Show( false );
1069 m_pTxtHelpCaption
->SetSize(3,cap_y
,new_width
-6,cap_hei
);
1070 m_pTxtHelpCaption
->Wrap(-1);
1071 m_pTxtHelpCaption
->Show( true );
1074 m_pTxtHelpContent
->Show( false );
1078 m_pTxtHelpContent
->SetSize(3,cnt_y
,new_width
-6,cnt_hei
);
1079 m_pTxtHelpContent
->Show( true );
1083 wxRect
r(0, new_splittery
, new_width
, new_height
-new_splittery
);
1086 m_splitterY
= new_splittery
;
1088 m_iFlags
&= ~(wxPG_FL_DESC_REFRESH_REQUIRED
);
1091 // -----------------------------------------------------------------------
1093 void wxPropertyGridManager::RecalculatePositions( int width
, int height
)
1096 int propgridBottomY
= height
;
1098 // Toolbar at the top.
1102 m_pToolbar
->SetSize(0, 0, width
, -1);
1103 propgridY
+= m_pToolbar
->GetSize().y
;
1105 if (GetExtraStyle() & wxPG_EX_TOOLBAR_SEPARATOR
)
1111 if ( m_pTxtHelpCaption
)
1113 int new_splittery
= m_splitterY
;
1116 if ( ( m_splitterY
>= 0 || m_nextDescBoxSize
) && m_height
> 32 )
1118 if ( m_nextDescBoxSize
>= 0 )
1120 new_splittery
= m_height
- m_nextDescBoxSize
- m_splitterHeight
;
1121 m_nextDescBoxSize
= -1;
1123 new_splittery
+= (height
-m_height
);
1127 new_splittery
= height
- wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y
;
1128 if ( new_splittery
< 32 )
1132 // Check if beyond minimum.
1133 int nspy_min
= propgridY
+ m_pPropGrid
->m_lineHeight
;
1134 if ( new_splittery
< nspy_min
)
1135 new_splittery
= nspy_min
;
1137 propgridBottomY
= new_splittery
;
1139 UpdateDescriptionBox( new_splittery
, width
, height
);
1142 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1144 int pgh
= propgridBottomY
- propgridY
;
1147 m_pPropGrid
->SetSize( 0, propgridY
, width
, pgh
);
1149 m_extraHeight
= height
- pgh
;
1156 // -----------------------------------------------------------------------
1158 void wxPropertyGridManager::SetDescBoxHeight( int ht
, bool refresh
)
1160 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1162 if ( ht
!= GetDescBoxHeight() )
1164 m_nextDescBoxSize
= ht
;
1166 RecalculatePositions(m_width
, m_height
);
1171 // -----------------------------------------------------------------------
1173 int wxPropertyGridManager::GetDescBoxHeight() const
1175 return GetClientSize().y
- m_splitterY
- m_splitterHeight
;
1178 // -----------------------------------------------------------------------
1180 void wxPropertyGridManager::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1184 // Update everything inside the box
1185 wxRect r
= GetUpdateRegion().GetBox();
1187 if (GetExtraStyle() & wxPG_EX_TOOLBAR_SEPARATOR
)
1189 if (m_pToolbar
&& m_pPropGrid
)
1191 wxPen
marginPen(m_pPropGrid
->GetMarginColour());
1192 dc
.SetPen(marginPen
);
1194 int y
= m_pPropGrid
->GetPosition().y
-1;
1195 dc
.DrawLine(0, y
, GetClientSize().x
, y
);
1199 // Repaint splitter and any other description box decorations
1200 if ( (r
.y
+ r
.height
) >= m_splitterY
&& m_splitterY
!= -1)
1201 RepaintDescBoxDecorations( dc
, m_splitterY
, m_width
, m_height
);
1204 // -----------------------------------------------------------------------
1206 void wxPropertyGridManager::Refresh(bool eraseBackground
, const wxRect
* rect
)
1208 m_pPropGrid
->Refresh(eraseBackground
);
1209 wxWindow::Refresh(eraseBackground
,rect
);
1212 // -----------------------------------------------------------------------
1214 void wxPropertyGridManager::RefreshProperty( wxPGProperty
* p
)
1216 wxPropertyGrid
* grid
= p
->GetGrid();
1218 if ( GetPage(m_selPage
)->GetStatePtr() == p
->GetParent()->GetParentState() )
1219 grid
->RefreshProperty(p
);
1222 // -----------------------------------------------------------------------
1224 void wxPropertyGridManager::RecreateControls()
1227 bool was_shown
= IsShown();
1231 wxWindowID baseId
= m_pPropGrid
->GetId();
1233 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1236 if ( m_windowStyle
& wxPG_TOOLBAR
)
1241 long toolBarFlags
= ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR
)?0:wxTB_FLAT
);
1242 if (GetExtraStyle() & wxPG_EX_NO_TOOLBAR_DIVIDER
)
1243 toolBarFlags
|= wxTB_NODIVIDER
;
1245 m_pToolbar
= new wxToolBar(this,baseId
+ID_ADVTOOLBAR_OFFSET
,
1246 wxDefaultPosition
,wxDefaultSize
,
1248 m_pToolbar
->SetToolBitmapSize(wxSize(16, 15));
1250 #if defined(__WXMSW__)
1251 // Eliminate toolbar flicker on XP
1252 // NOTE: Not enabled since it corrupts drawing somewhat.
1255 #ifndef WS_EX_COMPOSITED
1256 #define WS_EX_COMPOSITED 0x02000000L
1259 HWND hWnd = (HWND)m_pToolbar->GetHWND();
1261 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1262 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1267 m_pToolbar
->SetCursor ( *wxSTANDARD_CURSOR
);
1269 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1271 wxString
desc1(_("Categorized Mode"));
1272 wxString
desc2(_("Alphabetic Mode"));
1273 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+0,
1274 desc1
,wxBitmap ( (const char**)gs_xpm_catmode
),
1275 desc1
,wxITEM_RADIO
);
1276 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+1,
1277 desc2
,wxBitmap ( (const char**)gs_xpm_noncatmode
),
1278 desc2
,wxITEM_RADIO
);
1279 m_pToolbar
->Realize();
1284 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1286 // Toggle correct mode button.
1287 // TODO: This doesn't work in wxMSW (when changing,
1288 // both items will get toggled).
1289 int toggle_but_on_ind
= ID_ADVTBITEMSBASE_OFFSET
+0;
1290 int toggle_but_off_ind
= ID_ADVTBITEMSBASE_OFFSET
+1;
1291 if ( m_pPropGrid
->m_pState
->IsInNonCatMode() )
1293 toggle_but_on_ind
++;
1294 toggle_but_off_ind
--;
1297 m_pToolbar
->ToggleTool(baseId
+toggle_but_on_ind
,true);
1298 m_pToolbar
->ToggleTool(baseId
+toggle_but_off_ind
,false);
1306 m_pToolbar
->Destroy();
1311 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1314 m_pPropGrid
->m_iFlags
|= (wxPG_FL_NOSTATUSBARHELP
);
1316 if ( !m_pTxtHelpCaption
)
1318 m_pTxtHelpCaption
= new wxStaticText(this,
1319 baseId
+ID_ADVHELPCAPTION_OFFSET
,
1323 wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1324 m_pTxtHelpCaption
->SetFont( m_pPropGrid
->m_captionFont
);
1325 m_pTxtHelpCaption
->SetCursor( *wxSTANDARD_CURSOR
);
1327 if ( !m_pTxtHelpContent
)
1329 m_pTxtHelpContent
= new wxStaticText(this,
1330 baseId
+ID_ADVHELPCONTENT_OFFSET
,
1334 wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1335 m_pTxtHelpContent
->SetCursor( *wxSTANDARD_CURSOR
);
1338 SetDescribedProperty(GetSelection());
1343 m_pPropGrid
->m_iFlags
&= ~(wxPG_FL_NOSTATUSBARHELP
);
1345 if ( m_pTxtHelpCaption
)
1346 m_pTxtHelpCaption
->Destroy();
1348 m_pTxtHelpCaption
= NULL
;
1350 if ( m_pTxtHelpContent
)
1351 m_pTxtHelpContent
->Destroy();
1353 m_pTxtHelpContent
= NULL
;
1358 GetClientSize(&width
,&height
);
1360 RecalculatePositions(width
,height
);
1366 // -----------------------------------------------------------------------
1368 wxPGProperty
* wxPropertyGridManager::DoGetPropertyByName( const wxString
& name
) const
1371 for ( i
=0; i
<GetPageCount(); i
++ )
1373 wxPropertyGridPageState
* pState
= m_arrPages
[i
]->GetStatePtr();
1374 wxPGProperty
* p
= pState
->BaseGetPropertyByName(name
);
1383 // -----------------------------------------------------------------------
1385 bool wxPropertyGridManager::EnsureVisible( wxPGPropArg id
)
1387 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1389 wxPropertyGridPageState
* parentState
= p
->GetParentState();
1391 // Select correct page.
1392 if ( m_pPropGrid
->m_pState
!= parentState
)
1393 DoSelectPage( GetPageByState(parentState
) );
1395 return m_pPropGrid
->EnsureVisible(id
);
1398 // -----------------------------------------------------------------------
1400 void wxPropertyGridManager::OnToolbarClick( wxCommandEvent
&event
)
1402 int id
= event
.GetId();
1405 int baseId
= m_pPropGrid
->GetId();
1407 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1409 if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 0 ) )
1411 // Categorized mode.
1412 if ( m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
)
1414 if ( !m_pPropGrid
->HasInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
) )
1415 m_pPropGrid
->m_windowStyle
&= ~wxPG_AUTO_SORT
;
1416 m_pPropGrid
->EnableCategories( true );
1419 else if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 1 ) )
1422 if ( !(m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
1424 if ( m_pPropGrid
->HasFlag(wxPG_AUTO_SORT
) )
1425 m_pPropGrid
->SetInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1427 m_pPropGrid
->ClearInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1429 m_pPropGrid
->m_windowStyle
|= wxPG_AUTO_SORT
;
1430 m_pPropGrid
->EnableCategories( false );
1439 wxPropertyGridPage
* pdc
;
1441 // Find page with given id.
1442 for ( i
=0; i
<GetPageCount(); i
++ )
1444 pdc
= m_arrPages
[i
];
1445 if ( pdc
->m_id
== id
)
1452 wxASSERT( index
>= 0 );
1454 if ( DoSelectPage( index
) )
1457 // Event dispatching must be last.
1458 m_pPropGrid
->SendEvent( wxEVT_PG_PAGE_CHANGED
, NULL
);
1463 // TODO: Depress the old button on toolbar.
1470 // -----------------------------------------------------------------------
1472 bool wxPropertyGridManager::SetEditableStateItem( const wxString
& name
, wxVariant value
)
1474 if ( name
== wxS("descboxheight") )
1476 SetDescBoxHeight(value
.GetLong(), true);
1482 // -----------------------------------------------------------------------
1484 wxVariant
wxPropertyGridManager::GetEditableStateItem( const wxString
& name
) const
1486 if ( name
== wxS("descboxheight") )
1488 return (long) GetDescBoxHeight();
1490 return wxNullVariant
;
1493 // -----------------------------------------------------------------------
1495 void wxPropertyGridManager::SetDescription( const wxString
& label
, const wxString
& content
)
1497 if ( m_pTxtHelpCaption
)
1499 wxSize osz1
= m_pTxtHelpCaption
->GetSize();
1500 wxSize osz2
= m_pTxtHelpContent
->GetSize();
1502 m_pTxtHelpCaption
->SetLabel(label
);
1503 m_pTxtHelpContent
->SetLabel(content
);
1505 m_pTxtHelpCaption
->SetSize(-1,osz1
.y
);
1506 m_pTxtHelpContent
->SetSize(-1,osz2
.y
);
1508 UpdateDescriptionBox( m_splitterY
, m_width
, m_height
);
1512 // -----------------------------------------------------------------------
1514 void wxPropertyGridManager::SetDescribedProperty( wxPGProperty
* p
)
1516 if ( m_pTxtHelpCaption
)
1520 SetDescription( p
->GetLabel(), p
->GetHelpString() );
1524 SetDescription( wxEmptyString
, wxEmptyString
);
1529 // -----------------------------------------------------------------------
1531 void wxPropertyGridManager::SetSplitterLeft( bool subProps
, bool allPages
)
1535 m_pPropGrid
->SetSplitterLeft(subProps
);
1539 wxClientDC
dc(this);
1540 dc
.SetFont(m_pPropGrid
->GetFont());
1545 for ( i
=0; i
<GetPageCount(); i
++ )
1547 int maxW
= m_pState
->GetColumnFitWidth(dc
, m_arrPages
[i
]->m_properties
, 0, subProps
);
1548 maxW
+= m_pPropGrid
->m_marginWidth
;
1549 if ( maxW
> highest
)
1554 m_pPropGrid
->SetSplitterPosition( highest
);
1556 m_pPropGrid
->m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
1560 // -----------------------------------------------------------------------
1562 void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
1565 wxASSERT_MSG( GetId() == m_pPropGrid
->GetId(),
1566 wxT("wxPropertyGridManager id must be set with wxPropertyGridManager::SetId (not wxWindow::SetId).") );
1568 SetDescribedProperty(event
.GetProperty());
1572 // -----------------------------------------------------------------------
1574 void wxPropertyGridManager::OnResize( wxSizeEvent
& WXUNUSED(event
) )
1578 GetClientSize(&width
,&height
);
1580 if ( m_width
== -12345 )
1583 RecalculatePositions(width
,height
);
1586 // -----------------------------------------------------------------------
1588 void wxPropertyGridManager::OnMouseEntry( wxMouseEvent
& WXUNUSED(event
) )
1590 // Correct cursor. This is required atleast for wxGTK, for which
1591 // setting button's cursor to *wxSTANDARD_CURSOR does not work.
1592 SetCursor( wxNullCursor
);
1596 // -----------------------------------------------------------------------
1598 void wxPropertyGridManager::OnMouseMove( wxMouseEvent
&event
)
1600 if ( !m_pTxtHelpCaption
)
1605 if ( m_dragStatus
> 0 )
1607 int sy
= y
- m_dragOffset
;
1609 // Calculate drag limits
1610 int bottom_limit
= m_height
- m_splitterHeight
+ 1;
1611 int top_limit
= m_pPropGrid
->m_lineHeight
;
1613 if ( m_pToolbar
) top_limit
+= m_pToolbar
->GetSize().y
;
1616 if ( sy
>= top_limit
&& sy
< bottom_limit
)
1619 int change
= sy
- m_splitterY
;
1624 m_pPropGrid
->SetSize( m_width
, m_splitterY
- m_pPropGrid
->GetPosition().y
);
1625 UpdateDescriptionBox( m_splitterY
, m_width
, m_height
);
1627 m_extraHeight
-= change
;
1628 InvalidateBestSize();
1636 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1638 SetCursor ( m_cursorSizeNS
);
1645 SetCursor ( wxNullCursor
);
1652 // -----------------------------------------------------------------------
1654 void wxPropertyGridManager::OnMouseClick( wxMouseEvent
&event
)
1658 // Click on splitter.
1659 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1661 if ( m_dragStatus
== 0 )
1664 // Begin draggin the splitter
1671 m_dragOffset
= y
- m_splitterY
;
1677 // -----------------------------------------------------------------------
1679 void wxPropertyGridManager::OnMouseUp( wxMouseEvent
&event
)
1681 // No event type check - basicly calling this method should
1682 // just stop dragging.
1684 if ( m_dragStatus
>= 1 )
1687 // End Splitter Dragging
1692 // DO NOT ENABLE FOLLOWING LINE!
1693 // (it is only here as a reminder to not to do it)
1696 // This is necessary to return cursor
1699 // Set back the default cursor, if necessary
1700 if ( y
< m_splitterY
|| y
>= (m_splitterY
+m_splitterHeight
+2) )
1702 SetCursor ( wxNullCursor
);
1709 // -----------------------------------------------------------------------
1711 void wxPropertyGridManager::SetSplitterPosition( int pos
, int splitterColumn
)
1713 wxASSERT_MSG( GetPageCount(),
1714 wxT("SetSplitterPosition() has no effect until pages have been added") );
1717 for ( i
=0; i
<GetPageCount(); i
++ )
1719 wxPropertyGridPage
* page
= GetPage(i
);
1720 page
->DoSetSplitterPosition( pos
, splitterColumn
, false );
1723 m_pPropGrid
->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET
);
1726 // -----------------------------------------------------------------------
1727 // wxPGVIterator_Manager
1728 // -----------------------------------------------------------------------
1730 // Default returned by wxPropertyGridInterface::CreateVIterator().
1731 class wxPGVIteratorBase_Manager
: public wxPGVIteratorBase
1734 wxPGVIteratorBase_Manager( wxPropertyGridManager
* manager
, int flags
)
1735 : m_manager(manager
), m_flags(flags
), m_curPage(0)
1737 m_it
.Init(manager
->GetPage(0), flags
);
1739 virtual ~wxPGVIteratorBase_Manager() { }
1748 if ( m_curPage
< m_manager
->GetPageCount() )
1749 m_it
.Init( m_manager
->GetPage(m_curPage
), m_flags
);
1753 wxPropertyGridManager
* m_manager
;
1755 unsigned int m_curPage
;
1758 wxPGVIterator
wxPropertyGridManager::GetVIterator( int flags
) const
1760 return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager
*)this, flags
) );
1763 #endif // wxUSE_PROPGRID