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
->DoSelectProperty(NULL
);
427 m_pPropGrid
->m_pState
= NULL
;
430 for ( i
=0; i
<m_arrPages
.size(); i
++ )
432 delete m_arrPages
[i
];
438 // -----------------------------------------------------------------------
440 wxPropertyGrid
* wxPropertyGridManager::CreatePropertyGrid() const
442 return new wxPropertyGrid();
445 // -----------------------------------------------------------------------
447 void wxPropertyGridManager::SetId( wxWindowID winid
)
449 wxWindow::SetId(winid
);
451 // TODO: Reconnect propgrid event handler(s).
453 m_pPropGrid
->SetId(winid
);
456 // -----------------------------------------------------------------------
458 wxSize
wxPropertyGridManager::DoGetBestSize() const
460 return wxSize(60,150);
463 // -----------------------------------------------------------------------
465 bool wxPropertyGridManager::SetFont( const wxFont
& font
)
467 bool res
= wxWindow::SetFont(font
);
468 m_pPropGrid
->SetFont(font
);
470 // TODO: Need to do caption recacalculations for other pages as well.
472 for ( i
=0; i
<m_arrPages
.size(); i
++ )
474 wxPropertyGridPage
* page
= GetPage(i
);
476 if ( page
!= m_pPropGrid
->GetState() )
477 page
->CalculateFontAndBitmapStuff(-1);
483 // -----------------------------------------------------------------------
485 void wxPropertyGridManager::SetExtraStyle( long exStyle
)
487 wxWindow::SetExtraStyle( exStyle
);
488 m_pPropGrid
->SetExtraStyle( exStyle
& 0xFFFFF000 );
490 if ( (exStyle
& wxPG_EX_NO_FLAT_TOOLBAR
) && m_pToolbar
)
495 // -----------------------------------------------------------------------
497 void wxPropertyGridManager::Freeze()
499 m_pPropGrid
->Freeze();
503 // -----------------------------------------------------------------------
505 void wxPropertyGridManager::Thaw()
511 // -----------------------------------------------------------------------
513 void wxPropertyGridManager::SetWindowStyleFlag( long style
)
515 int oldWindowStyle
= GetWindowStyleFlag();
517 wxWindow::SetWindowStyleFlag( style
);
518 m_pPropGrid
->SetWindowStyleFlag( (m_pPropGrid
->GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK
)) |
519 (style
&wxPG_MAN_PASS_FLAGS_MASK
) );
521 // Need to re-position windows?
522 if ( (oldWindowStyle
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) !=
523 (style
& (wxPG_TOOLBAR
|wxPG_DESCRIPTION
)) )
529 // -----------------------------------------------------------------------
531 // Actually shows given page.
532 bool wxPropertyGridManager::DoSelectPage( int index
)
534 // -1 means no page was selected
535 //wxASSERT( m_selPage >= 0 );
537 wxCHECK_MSG( index
>= -1 && index
< (int)GetPageCount(),
539 wxT("invalid page index") );
541 if ( m_selPage
== index
)
544 if ( m_pPropGrid
->m_selected
)
546 if ( !m_pPropGrid
->ClearSelection() )
550 wxPropertyGridPage
* prevPage
;
552 if ( m_selPage
>= 0 )
553 prevPage
= GetPage(m_selPage
);
555 prevPage
= m_emptyPage
;
557 wxPropertyGridPage
* nextPage
;
561 nextPage
= m_arrPages
[index
];
569 m_emptyPage
= new wxPropertyGridPage();
570 m_emptyPage
->m_pPropGrid
= m_pPropGrid
;
573 nextPage
= m_emptyPage
;
576 m_iFlags
|= wxPG_FL_DESC_REFRESH_REQUIRED
;
578 m_pPropGrid
->SwitchState( nextPage
->GetStatePtr() );
580 m_pState
= m_pPropGrid
->m_pState
;
588 m_pToolbar
->ToggleTool( nextPage
->m_id
, true );
590 m_pToolbar
->ToggleTool( prevPage
->m_id
, false );
597 // -----------------------------------------------------------------------
599 // Changes page *and* set the target page for insertion operations.
600 void wxPropertyGridManager::SelectPage( int index
)
605 // -----------------------------------------------------------------------
607 int wxPropertyGridManager::GetPageByName( const wxString
& name
) const
610 for ( i
=0; i
<GetPageCount(); i
++ )
612 if ( m_arrPages
[i
]->m_label
== name
)
618 // -----------------------------------------------------------------------
620 int wxPropertyGridManager::GetPageByState( const wxPropertyGridPageState
* pState
) const
625 for ( i
=0; i
<GetPageCount(); i
++ )
627 if ( pState
== m_arrPages
[i
]->GetStatePtr() )
634 // -----------------------------------------------------------------------
636 const wxString
& wxPropertyGridManager::GetPageName( int index
) const
638 wxASSERT( index
>= 0 && index
< (int)GetPageCount() );
639 return m_arrPages
[index
]->m_label
;
642 // -----------------------------------------------------------------------
644 wxPropertyGridPageState
* wxPropertyGridManager::GetPageState( int page
) const
646 // Do not change this into wxCHECK because returning NULL is important
647 // for wxPropertyGridInterface page enumeration mechanics.
648 if ( page
>= (int)GetPageCount() )
653 return m_arrPages
[page
];
656 // -----------------------------------------------------------------------
658 void wxPropertyGridManager::Clear()
660 m_pPropGrid
->Freeze();
663 for ( i
=(int)GetPageCount()-1; i
>=0; i
-- )
667 m_nextTbInd
= m_baseId
+ID_ADVTBITEMSBASE_OFFSET
+ 2;
672 // -----------------------------------------------------------------------
674 void wxPropertyGridManager::ClearPage( int page
)
676 wxASSERT( page
>= 0 );
677 wxASSERT( page
< (int)GetPageCount() );
679 if ( page
>= 0 && page
< (int)GetPageCount() )
681 wxPropertyGridPageState
* state
= m_arrPages
[page
];
683 if ( state
== m_pPropGrid
->GetState() )
684 m_pPropGrid
->Clear();
690 // -----------------------------------------------------------------------
692 int wxPropertyGridManager::GetColumnCount( int page
) const
694 wxASSERT( page
>= -1 );
695 wxASSERT( page
< (int)GetPageCount() );
697 return GetPageState(page
)->GetColumnCount();
700 // -----------------------------------------------------------------------
702 void wxPropertyGridManager::SetColumnCount( int colCount
, int page
)
704 wxASSERT( page
>= -1 );
705 wxASSERT( page
< (int)GetPageCount() );
707 GetPageState(page
)->SetColumnCount( colCount
);
708 GetGrid()->Refresh();
710 // -----------------------------------------------------------------------
712 size_t wxPropertyGridManager::GetPageCount() const
714 if ( !(m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
) )
717 return m_arrPages
.size();
720 // -----------------------------------------------------------------------
722 wxPropertyGridPage
* wxPropertyGridManager::InsertPage( int index
,
723 const wxString
& label
,
725 wxPropertyGridPage
* pageObj
)
728 index
= GetPageCount();
730 wxCHECK_MSG( (size_t)index
== GetPageCount(), NULL
,
731 wxT("wxPropertyGridManager currently only supports appending pages (due to wxToolBar limitation)."));
733 bool needInit
= true;
734 bool isPageInserted
= m_iFlags
& wxPG_MAN_FL_PAGE_INSERTED
? true : false;
736 wxASSERT( index
== 0 || isPageInserted
);
740 // No custom page object was given, so we will either re-use the default base
741 // page (if index==0), or create a new default page object.
742 if ( !isPageInserted
)
744 pageObj
= GetPage(0);
745 // Of course, if the base page was custom, we need to delete and
747 if ( !pageObj
->m_isDefault
)
750 pageObj
= new wxPropertyGridPage();
751 m_arrPages
[0] = pageObj
;
757 pageObj
= new wxPropertyGridPage();
759 pageObj
->m_isDefault
= true;
763 if ( !isPageInserted
)
765 // Initial page needs to be deleted and replaced
767 m_arrPages
[0] = pageObj
;
768 m_pPropGrid
->m_pState
= pageObj
->GetStatePtr();
772 wxPropertyGridPageState
* state
= pageObj
->GetStatePtr();
774 pageObj
->m_manager
= this;
778 state
->m_pPropGrid
= m_pPropGrid
;
779 state
->InitNonCatMode();
782 if ( label
.length() )
784 wxASSERT_MSG( !pageObj
->m_label
.length(),
785 wxT("If page label is given in constructor, empty label must be given in AddPage"));
786 pageObj
->m_label
= label
;
789 pageObj
->m_id
= m_nextTbInd
;
791 if ( isPageInserted
)
792 m_arrPages
.push_back( pageObj
);
795 if ( m_windowStyle
& wxPG_TOOLBAR
)
800 if ( !(GetExtraStyle()&wxPG_EX_HIDE_PAGE_BUTTONS
) )
802 wxASSERT( m_pToolbar
);
804 // Add separator before first page.
805 if ( GetPageCount() < 2 && (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) &&
806 m_pToolbar
->GetToolsCount() < 3 )
807 m_pToolbar
->AddSeparator();
809 if ( &bmp
!= &wxNullBitmap
)
810 m_pToolbar
->AddTool(m_nextTbInd
,label
,bmp
,label
,wxITEM_RADIO
);
811 //m_pToolbar->InsertTool(index+3,m_nextTbInd,bmp);
813 m_pToolbar
->AddTool(m_nextTbInd
,label
,wxBitmap( (const char**)gs_xpm_defpage
),
818 m_pToolbar
->Realize();
825 // If selected page was above the point of insertion, fix the current page index
826 if ( isPageInserted
)
828 if ( m_selPage
>= index
)
835 // Set this value only when adding the first page
841 m_iFlags
|= wxPG_MAN_FL_PAGE_INSERTED
;
843 wxASSERT( pageObj
->GetGrid() );
848 // -----------------------------------------------------------------------
850 bool wxPropertyGridManager::IsAnyModified() const
853 for ( i
=0; i
<GetPageCount(); i
++ )
855 if ( m_arrPages
[i
]->GetStatePtr()->m_anyModified
)
861 // -----------------------------------------------------------------------
863 bool wxPropertyGridManager::IsPageModified( size_t index
) const
865 if ( m_arrPages
[index
]->GetStatePtr()->m_anyModified
)
870 // -----------------------------------------------------------------------
872 wxPGProperty
* wxPropertyGridManager::GetPageRoot( int index
) const
874 wxASSERT( index
>= 0 );
875 wxASSERT( index
< (int)m_arrPages
.size() );
877 return m_arrPages
[index
]->GetStatePtr()->m_properties
;
880 // -----------------------------------------------------------------------
882 bool wxPropertyGridManager::RemovePage( int page
)
884 wxCHECK_MSG( (page
>= 0) && (page
< (int)GetPageCount()),
886 wxT("invalid page index") );
888 wxPropertyGridPage
* pd
= m_arrPages
[page
];
890 if ( m_arrPages
.size() == 1 )
892 // Last page: do not remove page entry
893 m_pPropGrid
->Clear();
895 m_iFlags
&= ~wxPG_MAN_FL_PAGE_INSERTED
;
899 // Change selection if current is page
900 else if ( page
== m_selPage
)
902 if ( !m_pPropGrid
->ClearSelection() )
905 // Substitute page to select
906 int substitute
= page
- 1;
907 if ( substitute
< 0 )
908 substitute
= page
+ 1;
910 SelectPage(substitute
);
913 // Remove toolbar icon
915 if ( HasFlag(wxPG_TOOLBAR
) )
917 wxASSERT( m_pToolbar
);
919 int toolPos
= GetExtraStyle() & wxPG_EX_MODE_BUTTONS
? 3 : 0;
922 // Delete separator as well, for consistency
923 if ( (GetExtraStyle() & wxPG_EX_MODE_BUTTONS
) &&
924 GetPageCount() == 1 )
925 m_pToolbar
->DeleteToolByPos(2);
927 m_pToolbar
->DeleteToolByPos(toolPos
);
931 if ( m_arrPages
.size() > 1 )
933 m_arrPages
.erase(m_arrPages
.begin() + page
);
937 // Adjust indexes that were above removed
938 if ( m_selPage
> page
)
944 // -----------------------------------------------------------------------
946 bool wxPropertyGridManager::ProcessEvent( wxEvent
& event
)
948 int evtType
= event
.GetEventType();
950 // NB: For some reason, under wxPython, Connect in Init doesn't work properly,
951 // so we'll need to call OnPropertyGridSelect manually. Multiple call's
952 // don't really matter.
953 if ( evtType
== wxEVT_PG_SELECTED
)
954 OnPropertyGridSelect((wxPropertyGridEvent
&)event
);
956 // Property grid events get special attention
957 if ( evtType
>= wxPG_BASE_EVT_TYPE
&&
958 evtType
< (wxPG_MAX_EVT_TYPE
) &&
961 wxPropertyGridPage
* page
= GetPage(m_selPage
);
962 wxPropertyGridEvent
* pgEvent
= wxDynamicCast(&event
, wxPropertyGridEvent
);
964 // Add property grid events to appropriate custom pages
965 // but stop propagating to parent if page says it is
966 // handling everything.
967 if ( pgEvent
&& !page
->m_isDefault
)
969 /*if ( pgEvent->IsPending() )
970 page->AddPendingEvent(event);
972 page
->ProcessEvent(event
);
974 if ( page
->IsHandlingAllEvents() )
975 event
.StopPropagation();
979 return wxPanel::ProcessEvent(event
);
982 // -----------------------------------------------------------------------
984 void wxPropertyGridManager::RepaintSplitter( wxDC
& dc
, int new_splittery
, int new_width
,
985 int new_height
, bool desc_too
)
987 int use_hei
= new_height
;
990 wxColour bgcol
= GetBackgroundColour();
991 dc
.SetBrush( bgcol
);
993 int rect_hei
= use_hei
-new_splittery
;
995 rect_hei
= m_splitterHeight
;
996 dc
.DrawRectangle(0,new_splittery
,new_width
,rect_hei
);
997 dc
.SetPen ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DDKSHADOW
) );
998 int splitter_bottom
= new_splittery
+m_splitterHeight
- 1;
999 int box_height
= use_hei
-splitter_bottom
;
1000 if ( box_height
> 1 )
1001 dc
.DrawRectangle(0,splitter_bottom
,new_width
,box_height
);
1003 dc
.DrawLine(0,splitter_bottom
,new_width
,splitter_bottom
);
1006 // -----------------------------------------------------------------------
1008 void wxPropertyGridManager::UpdateDescriptionBox( int new_splittery
, int new_width
, int new_height
)
1010 int use_hei
= new_height
;
1013 // Fix help control positions.
1014 int cap_hei
= m_pPropGrid
->m_fontHeight
;
1015 int cap_y
= new_splittery
+m_splitterHeight
+5;
1016 int cnt_y
= cap_y
+cap_hei
+3;
1017 int sub_cap_hei
= cap_y
+cap_hei
-use_hei
;
1018 int cnt_hei
= use_hei
-cnt_y
;
1019 if ( sub_cap_hei
> 0 )
1021 cap_hei
-= sub_cap_hei
;
1026 m_pTxtHelpCaption
->Show( false );
1027 m_pTxtHelpContent
->Show( false );
1031 m_pTxtHelpCaption
->SetSize(3,cap_y
,new_width
-6,cap_hei
);
1032 m_pTxtHelpCaption
->Wrap(-1);
1033 m_pTxtHelpCaption
->Show( true );
1036 m_pTxtHelpContent
->Show( false );
1040 m_pTxtHelpContent
->SetSize(3,cnt_y
,new_width
-6,cnt_hei
);
1041 m_pTxtHelpContent
->Show( true );
1045 wxRect
r(0, new_splittery
, new_width
, new_height
-new_splittery
);
1048 m_splitterY
= new_splittery
;
1050 m_iFlags
&= ~(wxPG_FL_DESC_REFRESH_REQUIRED
);
1053 // -----------------------------------------------------------------------
1055 void wxPropertyGridManager::RecalculatePositions( int width
, int height
)
1058 int propgridBottomY
= height
;
1060 // Toolbar at the top.
1066 #if ( wxMINOR_VERSION < 6 || (wxMINOR_VERSION == 6 && wxRELEASE_NUMBER < 2) )
1069 // In wxWidgets 2.6.2+, Toolbar default height may be broken
1070 #if defined(__WXMSW__)
1072 #elif defined(__WXGTK__)
1073 tbHeight
= -1; // 22;
1074 #elif defined(__WXMAC__)
1081 m_pToolbar
->SetSize(0,0,width
,tbHeight
);
1082 propgridY
+= m_pToolbar
->GetSize().y
;
1087 if ( m_pTxtHelpCaption
)
1089 int new_splittery
= m_splitterY
;
1092 if ( ( m_splitterY
>= 0 || m_nextDescBoxSize
) && m_height
> 32 )
1094 if ( m_nextDescBoxSize
>= 0 )
1096 new_splittery
= m_height
- m_nextDescBoxSize
- m_splitterHeight
;
1097 m_nextDescBoxSize
= -1;
1099 new_splittery
+= (height
-m_height
);
1103 new_splittery
= height
- wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y
;
1104 if ( new_splittery
< 32 )
1108 // Check if beyond minimum.
1109 int nspy_min
= propgridY
+ m_pPropGrid
->m_lineHeight
;
1110 if ( new_splittery
< nspy_min
)
1111 new_splittery
= nspy_min
;
1113 propgridBottomY
= new_splittery
;
1115 UpdateDescriptionBox( new_splittery
, width
, height
);
1118 if ( m_iFlags
& wxPG_FL_INITIALIZED
)
1120 int pgh
= propgridBottomY
- propgridY
;
1121 m_pPropGrid
->SetSize( 0, propgridY
, width
, pgh
);
1123 m_extraHeight
= height
- pgh
;
1130 // -----------------------------------------------------------------------
1132 void wxPropertyGridManager::SetDescBoxHeight( int ht
, bool refresh
)
1134 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1136 if ( ht
!= GetDescBoxHeight() )
1138 m_nextDescBoxSize
= ht
;
1140 RecalculatePositions(m_width
, m_height
);
1145 // -----------------------------------------------------------------------
1147 int wxPropertyGridManager::GetDescBoxHeight() const
1149 return GetClientSize().y
- m_splitterY
- m_splitterHeight
;
1152 // -----------------------------------------------------------------------
1154 void wxPropertyGridManager::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1158 // Update everything inside the box
1159 wxRect r
= GetUpdateRegion().GetBox();
1161 // Repaint splitter?
1162 int r_bottom
= r
.y
+ r
.height
;
1163 int splitter_bottom
= m_splitterY
+ m_splitterHeight
;
1164 if ( r
.y
< splitter_bottom
&& r_bottom
>= m_splitterY
)
1165 RepaintSplitter( dc
, m_splitterY
, m_width
, m_height
, false );
1168 // -----------------------------------------------------------------------
1170 void wxPropertyGridManager::Refresh(bool eraseBackground
, const wxRect
* rect
)
1172 m_pPropGrid
->Refresh(eraseBackground
);
1173 wxWindow::Refresh(eraseBackground
,rect
);
1176 // -----------------------------------------------------------------------
1178 void wxPropertyGridManager::RefreshProperty( wxPGProperty
* p
)
1180 wxPropertyGrid
* grid
= p
->GetGrid();
1182 if ( GetPage(m_selPage
)->GetStatePtr() == p
->GetParent()->GetParentState() )
1183 grid
->RefreshProperty(p
);
1186 // -----------------------------------------------------------------------
1188 void wxPropertyGridManager::RecreateControls()
1191 bool was_shown
= IsShown();
1195 wxWindowID baseId
= m_pPropGrid
->GetId();
1197 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1200 if ( m_windowStyle
& wxPG_TOOLBAR
)
1205 m_pToolbar
= new wxToolBar(this,baseId
+ID_ADVTOOLBAR_OFFSET
,
1206 wxDefaultPosition
,wxDefaultSize
,
1207 ((GetExtraStyle()&wxPG_EX_NO_FLAT_TOOLBAR
)?0:wxTB_FLAT
)
1208 /*| wxTB_HORIZONTAL | wxNO_BORDER*/ );
1210 #if defined(__WXMSW__)
1211 // Eliminate toolbar flicker on XP
1212 // NOTE: Not enabled since it corrupts drawing somewhat.
1215 #ifndef WS_EX_COMPOSITED
1216 #define WS_EX_COMPOSITED 0x02000000L
1219 HWND hWnd = (HWND)m_pToolbar->GetHWND();
1221 ::SetWindowLong( hWnd, GWL_EXSTYLE,
1222 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
1227 m_pToolbar
->SetCursor ( *wxSTANDARD_CURSOR
);
1229 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1231 wxString
desc1(_("Categorized Mode"));
1232 wxString
desc2(_("Alphabetic Mode"));
1233 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+0,
1234 desc1
,wxBitmap ( (const char**)gs_xpm_catmode
),
1235 desc1
,wxITEM_RADIO
);
1236 m_pToolbar
->AddTool(baseId
+ID_ADVTBITEMSBASE_OFFSET
+1,
1237 desc2
,wxBitmap ( (const char**)gs_xpm_noncatmode
),
1238 desc2
,wxITEM_RADIO
);
1239 m_pToolbar
->Realize();
1244 if ( (GetExtraStyle()&wxPG_EX_MODE_BUTTONS
) )
1246 // Toggle correct mode button.
1247 // TODO: This doesn't work in wxMSW (when changing,
1248 // both items will get toggled).
1249 int toggle_but_on_ind
= ID_ADVTBITEMSBASE_OFFSET
+0;
1250 int toggle_but_off_ind
= ID_ADVTBITEMSBASE_OFFSET
+1;
1251 if ( m_pPropGrid
->m_pState
->IsInNonCatMode() )
1253 toggle_but_on_ind
++;
1254 toggle_but_off_ind
--;
1257 m_pToolbar
->ToggleTool(baseId
+toggle_but_on_ind
,true);
1258 m_pToolbar
->ToggleTool(baseId
+toggle_but_off_ind
,false);
1266 m_pToolbar
->Destroy();
1271 if ( m_windowStyle
& wxPG_DESCRIPTION
)
1274 m_pPropGrid
->m_iFlags
|= (wxPG_FL_NOSTATUSBARHELP
);
1276 if ( !m_pTxtHelpCaption
)
1278 m_pTxtHelpCaption
= new wxStaticText(this,
1279 baseId
+ID_ADVHELPCAPTION_OFFSET
,
1283 wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1284 m_pTxtHelpCaption
->SetFont( m_pPropGrid
->m_captionFont
);
1285 m_pTxtHelpCaption
->SetCursor( *wxSTANDARD_CURSOR
);
1287 if ( !m_pTxtHelpContent
)
1289 m_pTxtHelpContent
= new wxStaticText(this,
1290 baseId
+ID_ADVHELPCONTENT_OFFSET
,
1294 wxALIGN_LEFT
|wxST_NO_AUTORESIZE
);
1295 m_pTxtHelpContent
->SetCursor( *wxSTANDARD_CURSOR
);
1298 SetDescribedProperty(GetSelection());
1303 m_pPropGrid
->m_iFlags
&= ~(wxPG_FL_NOSTATUSBARHELP
);
1305 if ( m_pTxtHelpCaption
)
1306 m_pTxtHelpCaption
->Destroy();
1308 m_pTxtHelpCaption
= NULL
;
1310 if ( m_pTxtHelpContent
)
1311 m_pTxtHelpContent
->Destroy();
1313 m_pTxtHelpContent
= NULL
;
1318 GetClientSize(&width
,&height
);
1320 RecalculatePositions(width
,height
);
1326 // -----------------------------------------------------------------------
1328 wxPGProperty
* wxPropertyGridManager::DoGetPropertyByName( const wxString
& name
) const
1331 for ( i
=0; i
<GetPageCount(); i
++ )
1333 wxPropertyGridPageState
* pState
= m_arrPages
[i
]->GetStatePtr();
1334 wxPGProperty
* p
= pState
->BaseGetPropertyByName(name
);
1343 // -----------------------------------------------------------------------
1345 bool wxPropertyGridManager::EnsureVisible( wxPGPropArg id
)
1347 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1349 wxPropertyGridPageState
* parentState
= p
->GetParentState();
1351 // Select correct page.
1352 if ( m_pPropGrid
->m_pState
!= parentState
)
1353 DoSelectPage( GetPageByState(parentState
) );
1355 return m_pPropGrid
->EnsureVisible(id
);
1358 // -----------------------------------------------------------------------
1360 void wxPropertyGridManager::OnToolbarClick( wxCommandEvent
&event
)
1362 int id
= event
.GetId();
1365 int baseId
= m_pPropGrid
->GetId();
1367 baseId
= wxPG_MAN_ALTERNATE_BASE_ID
;
1369 if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 0 ) )
1371 // Categorized mode.
1372 if ( m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
)
1374 if ( !m_pPropGrid
->HasInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
) )
1375 m_pPropGrid
->m_windowStyle
&= ~wxPG_AUTO_SORT
;
1376 m_pPropGrid
->EnableCategories( true );
1379 else if ( id
== ( baseId
+ ID_ADVTBITEMSBASE_OFFSET
+ 1 ) )
1382 if ( !(m_pPropGrid
->m_windowStyle
& wxPG_HIDE_CATEGORIES
) )
1384 if ( m_pPropGrid
->HasFlag(wxPG_AUTO_SORT
) )
1385 m_pPropGrid
->SetInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1387 m_pPropGrid
->ClearInternalFlag(wxPG_FL_CATMODE_AUTO_SORT
);
1389 m_pPropGrid
->m_windowStyle
|= wxPG_AUTO_SORT
;
1390 m_pPropGrid
->EnableCategories( false );
1399 wxPropertyGridPage
* pdc
;
1401 // Find page with given id.
1402 for ( i
=0; i
<GetPageCount(); i
++ )
1404 pdc
= m_arrPages
[i
];
1405 if ( pdc
->m_id
== id
)
1412 wxASSERT( index
>= 0 );
1414 if ( DoSelectPage( index
) )
1417 // Event dispatching must be last.
1418 m_pPropGrid
->SendEvent( wxEVT_PG_PAGE_CHANGED
, NULL
);
1423 // TODO: Depress the old button on toolbar.
1430 // -----------------------------------------------------------------------
1432 bool wxPropertyGridManager::SetEditableStateItem( const wxString
& name
, wxVariant value
)
1434 if ( name
== wxS("descboxheight") )
1436 SetDescBoxHeight(value
.GetLong(), true);
1442 // -----------------------------------------------------------------------
1444 wxVariant
wxPropertyGridManager::GetEditableStateItem( const wxString
& name
) const
1446 if ( name
== wxS("descboxheight") )
1448 return (long) GetDescBoxHeight();
1450 return wxNullVariant
;
1453 // -----------------------------------------------------------------------
1455 void wxPropertyGridManager::SetDescription( const wxString
& label
, const wxString
& content
)
1457 if ( m_pTxtHelpCaption
)
1459 wxSize osz1
= m_pTxtHelpCaption
->GetSize();
1460 wxSize osz2
= m_pTxtHelpContent
->GetSize();
1462 m_pTxtHelpCaption
->SetLabel(label
);
1463 m_pTxtHelpContent
->SetLabel(content
);
1465 m_pTxtHelpCaption
->SetSize(-1,osz1
.y
);
1466 m_pTxtHelpContent
->SetSize(-1,osz2
.y
);
1468 UpdateDescriptionBox( m_splitterY
, m_width
, m_height
);
1472 // -----------------------------------------------------------------------
1474 void wxPropertyGridManager::SetDescribedProperty( wxPGProperty
* p
)
1476 if ( m_pTxtHelpCaption
)
1480 SetDescription( p
->GetLabel(), p
->GetHelpString() );
1484 SetDescription( wxEmptyString
, wxEmptyString
);
1489 // -----------------------------------------------------------------------
1491 void wxPropertyGridManager::SetSplitterLeft( bool subProps
, bool allPages
)
1495 m_pPropGrid
->SetSplitterLeft(subProps
);
1499 wxClientDC
dc(this);
1500 dc
.SetFont(m_pPropGrid
->m_font
);
1505 for ( i
=0; i
<GetPageCount(); i
++ )
1507 int maxW
= m_pState
->GetColumnFitWidth(dc
, m_arrPages
[i
]->m_properties
, 0, subProps
);
1508 maxW
+= m_pPropGrid
->m_marginWidth
;
1509 if ( maxW
> highest
)
1514 m_pPropGrid
->SetSplitterPosition( highest
);
1516 m_pPropGrid
->m_iFlags
|= wxPG_FL_DONT_CENTER_SPLITTER
;
1520 // -----------------------------------------------------------------------
1522 void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent
& event
)
1525 wxASSERT_MSG( GetId() == m_pPropGrid
->GetId(),
1526 wxT("wxPropertyGridManager id must be set with wxPropertyGridManager::SetId (not wxWindow::SetId).") );
1528 SetDescribedProperty(event
.GetProperty());
1532 // -----------------------------------------------------------------------
1534 void wxPropertyGridManager::OnResize( wxSizeEvent
& WXUNUSED(event
) )
1538 GetClientSize(&width
,&height
);
1540 if ( m_width
== -12345 )
1543 RecalculatePositions(width
,height
);
1546 // -----------------------------------------------------------------------
1548 void wxPropertyGridManager::OnMouseEntry( wxMouseEvent
& WXUNUSED(event
) )
1550 // Correct cursor. This is required atleast for wxGTK, for which
1551 // setting button's cursor to *wxSTANDARD_CURSOR does not work.
1552 SetCursor( wxNullCursor
);
1556 // -----------------------------------------------------------------------
1558 void wxPropertyGridManager::OnMouseMove( wxMouseEvent
&event
)
1560 if ( !m_pTxtHelpCaption
)
1565 if ( m_dragStatus
> 0 )
1567 int sy
= y
- m_dragOffset
;
1569 // Calculate drag limits
1570 int bottom_limit
= m_height
- m_splitterHeight
+ 1;
1571 int top_limit
= m_pPropGrid
->m_lineHeight
;
1573 if ( m_pToolbar
) top_limit
+= m_pToolbar
->GetSize().y
;
1576 if ( sy
>= top_limit
&& sy
< bottom_limit
)
1579 int change
= sy
- m_splitterY
;
1584 m_pPropGrid
->SetSize( m_width
, m_splitterY
- m_pPropGrid
->GetPosition().y
);
1585 UpdateDescriptionBox( m_splitterY
, m_width
, m_height
);
1587 m_extraHeight
-= change
;
1588 InvalidateBestSize();
1596 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1598 SetCursor ( m_cursorSizeNS
);
1605 SetCursor ( wxNullCursor
);
1612 // -----------------------------------------------------------------------
1614 void wxPropertyGridManager::OnMouseClick( wxMouseEvent
&event
)
1618 // Click on splitter.
1619 if ( y
>= m_splitterY
&& y
< (m_splitterY
+m_splitterHeight
+2) )
1621 if ( m_dragStatus
== 0 )
1624 // Begin draggin the splitter
1631 m_dragOffset
= y
- m_splitterY
;
1637 // -----------------------------------------------------------------------
1639 void wxPropertyGridManager::OnMouseUp( wxMouseEvent
&event
)
1641 // No event type check - basicly calling this method should
1642 // just stop dragging.
1644 if ( m_dragStatus
>= 1 )
1647 // End Splitter Dragging
1652 // DO NOT ENABLE FOLLOWING LINE!
1653 // (it is only here as a reminder to not to do it)
1656 // This is necessary to return cursor
1659 // Set back the default cursor, if necessary
1660 if ( y
< m_splitterY
|| y
>= (m_splitterY
+m_splitterHeight
+2) )
1662 SetCursor ( wxNullCursor
);
1669 // -----------------------------------------------------------------------
1671 void wxPropertyGridManager::SetSplitterPosition( int pos
, int splitterColumn
)
1673 wxASSERT_MSG( GetPageCount(),
1674 wxT("SetSplitterPosition() has no effect until pages have been added") );
1677 for ( i
=0; i
<GetPageCount(); i
++ )
1679 wxPropertyGridPage
* page
= GetPage(i
);
1680 page
->DoSetSplitterPosition( pos
, splitterColumn
, false );
1683 m_pPropGrid
->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET
);
1686 // -----------------------------------------------------------------------
1687 // wxPGVIterator_Manager
1688 // -----------------------------------------------------------------------
1690 // Default returned by wxPropertyGridInterface::CreateVIterator().
1691 class wxPGVIteratorBase_Manager
: public wxPGVIteratorBase
1694 wxPGVIteratorBase_Manager( wxPropertyGridManager
* manager
, int flags
)
1695 : m_manager(manager
), m_flags(flags
), m_curPage(0)
1697 m_it
.Init(manager
->GetPage(0), flags
);
1699 virtual ~wxPGVIteratorBase_Manager() { }
1708 if ( m_curPage
< m_manager
->GetPageCount() )
1709 m_it
.Init( m_manager
->GetPage(m_curPage
), m_flags
);
1713 wxPropertyGridManager
* m_manager
;
1715 unsigned int m_curPage
;
1718 wxPGVIterator
wxPropertyGridManager::GetVIterator( int flags
) const
1720 return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager
*)this, flags
) );
1723 #endif // wxUSE_PROPGRID