1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/manager.h
3 // Purpose: wxPropertyGridManager
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_MANAGER_H_
13 #define _WX_PROPGRID_MANAGER_H_
17 #include "wx/propgrid/propgrid.h"
19 #include "wx/dcclient.h"
20 #include "wx/scrolwin.h"
21 #include "wx/toolbar.h"
22 #include "wx/stattext.h"
23 #include "wx/button.h"
24 #include "wx/textctrl.h"
25 #include "wx/dialog.h"
27 // -----------------------------------------------------------------------
30 extern WXDLLIMPEXP_PROPGRID
const wxChar
*wxPropertyGridManagerNameStr
;
33 /** @class wxPropertyGridPage
35 Holder of property grid page information. You can subclass this and
36 give instance in wxPropertyGridManager::AddPage. It inherits from
37 wxEvtHandler and can be used to process events specific to this
38 page (id of events will still be same as manager's). If you don't
39 want to use it to process all events of the page, you need to
40 return false in the derived wxPropertyGridPage::IsHandlingAllEvents.
42 Please note that wxPropertyGridPage lacks many non-const property
43 manipulation functions found in wxPropertyGridManager. Please use
44 parent manager (m_manager member variable) when needed.
46 Please note that most member functions are inherited and as such not
47 documented on this page. This means you will probably also want to read
48 wxPropertyGridInterface class reference.
50 @section propgridpage_event_handling Event Handling
52 wxPropertyGridPage receives events emitted by its wxPropertyGridManager, but
53 only those events that are specific to that page. If
54 wxPropertyGridPage::IsHandlingAllEvents returns false, then unhandled
55 events are sent to the manager's parent, as usual.
57 See @ref propgrid_event_handling "wxPropertyGrid Event Handling"
63 class WXDLLIMPEXP_PROPGRID wxPropertyGridPage
: public wxEvtHandler
,
64 public wxPropertyGridInterface
,
65 public wxPropertyGridPageState
67 friend class wxPropertyGridManager
;
69 DECLARE_CLASS(wxPropertyGridPage
)
74 virtual ~wxPropertyGridPage();
76 /** Deletes all properties on page.
81 Reduces column sizes to minimum possible that contents are still
82 visibly (naturally some margin space will be applied as well).
85 Minimum size for the page to still display everything.
88 This function only works properly if size of containing grid was
91 Note that you can also get calculated column widths by calling
92 GetColumnWidth() immediately after this function returns.
96 /** Returns page index in manager;
98 inline int GetIndex() const;
100 /** Returns x-coordinate position of splitter on a page.
102 int GetSplitterPosition( int col
= 0 ) const
103 { return GetStatePtr()->DoGetSplitterPosition(col
); }
105 /** Returns "root property". It does not have name, etc. and it is not
106 visible. It is only useful for accessing its children.
108 wxPGProperty
* GetRoot() const { return GetStatePtr()->DoGetRoot(); }
110 /** Return pointer to contained property grid state.
112 wxPropertyGridPageState
* GetStatePtr()
117 /** Return pointer to contained property grid state.
119 const wxPropertyGridPageState
* GetStatePtr() const
125 Returns id of the tool bar item that represents this page on
126 wxPropertyGridManager's wxToolBar.
128 int GetToolId() const
133 /** Do any member initialization in this method.
135 - Called every time the page is added into a manager.
136 - You can add properties to the page here.
138 virtual void Init() {}
140 /** Return false here to indicate unhandled events should be
141 propagated to manager's parent, as normal.
143 virtual bool IsHandlingAllEvents() const { return true; }
145 /** Called every time page is about to be shown.
146 Useful, for instance, creating properties just-in-time.
148 virtual void OnShow();
150 virtual void RefreshProperty( wxPGProperty
* p
);
152 /** Sets splitter position on page.
154 Splitter position cannot exceed grid size, and therefore setting it
155 during form creation may fail as initial grid size is often smaller
156 than desired splitter position, especially when sizers are being used.
158 void SetSplitterPosition( int splitterPos
, int col
= 0 );
162 /** Propagate to other pages.
164 virtual void DoSetSplitterPosition( int pos
,
165 int splitterColumn
= 0,
166 bool allPages
= false );
168 /** Propagate to other pages.
170 void DoSetSplitterPositionThisPage( int pos
, int splitterColumn
= 0 )
172 wxPropertyGridPageState
::DoSetSplitterPosition( pos
, splitterColumn
);
175 /** Page label (may be referred as name in some parts of documentation).
176 Can be set in constructor, or passed in
177 wxPropertyGridManager::AddPage(), but *not* in both.
183 //virtual bool ProcessEvent( wxEvent& event );
185 wxPropertyGridManager
* m_manager
;
187 int m_id
; // toolbar index
190 bool m_isDefault
; // is this base page object?
193 DECLARE_EVENT_TABLE()
197 // -----------------------------------------------------------------------
199 /** @class wxPropertyGridManager
201 wxPropertyGridManager is an efficient multi-page version of wxPropertyGrid,
202 which can optionally have toolbar for mode and page selection, and help
204 Use window flags to select components to include.
206 @section propgridmanager_window_styles_ Window Styles
208 See @ref propgrid_window_styles.
210 @section propgridmanager_event_handling Event Handling
212 See @ref propgrid_event_handling "wxPropertyGrid Event Handling"
213 for more information.
218 class WXDLLIMPEXP_PROPGRID
219 wxPropertyGridManager
: public wxPanel
, public wxPropertyGridInterface
222 DECLARE_CLASS(wxPropertyGridManager
)
224 friend class wxPropertyGridPage
;
228 %pythonAppend wxPropertyGridManager
{
229 self
._setOORInfo(self
)
230 self
.DoDefaultTypeMappings()
231 self
.edited_objects
= {}
232 self
.DoDefaultValueTypeMappings()
233 if not hasattr(self
.__class__
,'_vt2setter'):
234 self
.__class__
._vt2setter
= {}
236 %pythonAppend
wxPropertyGridManager() ""
238 wxPropertyGridManager( wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
239 const wxPoint
& pos
= wxDefaultPosition
,
240 const wxSize
& size
= wxDefaultSize
,
241 long style
= wxPGMAN_DEFAULT_STYLE
,
243 wxPyPropertyGridManagerNameStr
);
244 %RenameCtor(PrePropertyGridManager
, wxPropertyGridManager());
249 Two step constructor.
250 Call Create when this constructor is called to build up the
251 wxPropertyGridManager.
253 wxPropertyGridManager();
255 /** The default constructor. The styles to be used are styles valid for
257 @see @link wndflags Additional Window Styles@endlink
259 wxPropertyGridManager( wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
260 const wxPoint
& pos
= wxDefaultPosition
,
261 const wxSize
& size
= wxDefaultSize
,
262 long style
= wxPGMAN_DEFAULT_STYLE
,
263 const wxChar
* name
= wxPropertyGridManagerNameStr
);
266 virtual ~wxPropertyGridManager();
270 /** Creates new property page. Note that the first page is not created
273 A label for the page. This may be shown as a toolbar tooltip etc.
275 Bitmap image for toolbar. If wxNullBitmap is used, then a built-in
276 default image is used.
278 wxPropertyGridPage instance. Manager will take ownership of this object.
279 NULL indicates that a default page instance should be created.
282 Returns pointer to created page.
285 If toolbar is used, it is highly recommended that the pages are
286 added when the toolbar is not turned off using window style flag
289 wxPropertyGridPage
* AddPage( const wxString
& label
= wxEmptyString
,
290 const wxBitmap
& bmp
= wxPG_NULL_BITMAP
,
291 wxPropertyGridPage
* pageObj
= NULL
)
293 return InsertPage(-1, label
, bmp
, pageObj
);
296 void ClearModifiedStatus ( wxPGPropArg id
);
298 void ClearModifiedStatus ()
300 m_pPropGrid
->ClearModifiedStatus();
303 /** Deletes all all properties and all pages.
305 virtual void Clear();
307 /** Deletes all properties on given page.
309 void ClearPage( int page
);
311 /** Forces updating the value of property from the editor control.
312 Returns true if DoPropertyChanged was actually called.
314 bool CommitChangesFromEditor( wxUint32 flags
= 0 )
316 return m_pPropGrid
->CommitChangesFromEditor(flags
);
321 Whenever the control is created without any parameters, use Create to
322 actually create it. Don't access the control's public methods before
324 @see @link wndflags Additional Window Styles@endlink
326 bool Create( wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
327 const wxPoint
& pos
= wxDefaultPosition
,
328 const wxSize
& size
= wxDefaultSize
,
329 long style
= wxPGMAN_DEFAULT_STYLE
,
330 const wxChar
* name
= wxPropertyGridManagerNameStr
);
333 Enables or disables (shows/hides) categories according to parameter
336 WARNING: Not tested properly, use at your own risk.
338 bool EnableCategories( bool enable
)
340 long fl
= m_windowStyle
| wxPG_HIDE_CATEGORIES
;
341 if ( enable
) fl
= m_windowStyle
& ~(wxPG_HIDE_CATEGORIES
);
342 SetWindowStyleFlag(fl
);
346 /** Selects page, scrolls and/or expands items to ensure that the
347 given item is visible. Returns true if something was actually done.
349 bool EnsureVisible( wxPGPropArg id
);
351 /** Returns number of children of the root property of the selected page. */
352 size_t GetChildrenCount()
354 return GetChildrenCount( m_pPropGrid
->m_pState
->m_properties
);
357 /** Returns number of children of the root property of given page. */
358 size_t GetChildrenCount( int pageIndex
);
360 /** Returns number of children for the property.
362 NB: Cannot be in container methods class due to name hiding.
364 size_t GetChildrenCount( wxPGPropArg id
) const
366 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0)
367 return p
->GetChildCount();
370 /** Returns number of columns on given page. By the default,
371 returns number of columns on current page. */
372 int GetColumnCount( int page
= -1 ) const;
374 /** Returns height of the description text box. */
375 int GetDescBoxHeight() const;
377 /** Returns pointer to the contained wxPropertyGrid. This does not change
378 after wxPropertyGridManager has been created, so you can safely obtain
379 pointer once and use it for the entire lifetime of the instance.
381 wxPropertyGrid
* GetGrid()
383 wxASSERT(m_pPropGrid
);
387 const wxPropertyGrid
* GetGrid() const
389 wxASSERT(m_pPropGrid
);
390 return (const wxPropertyGrid
*)m_pPropGrid
;
393 /** Returns iterator class instance.
395 Calling this method in wxPropertyGridManager causes run-time assertion
396 failure. Please only iterate through individual pages or use
399 wxPropertyGridIterator
GetIterator( int flags
= wxPG_ITERATE_DEFAULT
,
400 wxPGProperty
* firstProp
= NULL
)
402 wxFAIL_MSG( "Please only iterate through individual pages "
403 "or use CreateVIterator()" );
404 return wxPropertyGridInterface
::GetIterator( flags
, firstProp
);
407 wxPropertyGridConstIterator
408 GetIterator(int flags
= wxPG_ITERATE_DEFAULT
,
409 wxPGProperty
* firstProp
= NULL
) const
411 wxFAIL_MSG( "Please only iterate through individual pages "
412 " or use CreateVIterator()" );
413 return wxPropertyGridInterface
::GetIterator( flags
, firstProp
);
416 /** Returns iterator class instance.
418 Calling this method in wxPropertyGridManager causes run-time assertion
419 failure. Please only iterate through individual pages or use
422 wxPropertyGridIterator
GetIterator( int flags
, int startPos
)
424 wxFAIL_MSG( "Please only iterate through individual pages "
425 "or use CreateVIterator()" );
427 return wxPropertyGridInterface
::GetIterator( flags
, startPos
);
430 wxPropertyGridConstIterator
GetIterator( int flags
, int startPos
) const
432 wxFAIL_MSG( "Please only iterate through individual pages "
433 "or use CreateVIterator()" );
434 return wxPropertyGridInterface
::GetIterator( flags
, startPos
);
437 /** Similar to GetIterator, but instead returns wxPGVIterator instance,
438 which can be useful for forward-iterating through arbitrary property
441 virtual wxPGVIterator
GetVIterator( int flags
) const;
443 /** Returns currently selected page.
445 wxPropertyGridPage
* GetCurrentPage() const
447 return GetPage(m_selPage
);
450 /** Returns page object for given page index.
452 wxPropertyGridPage
* GetPage( unsigned int ind
) const
454 return (wxPropertyGridPage
*)m_arrPages
.Item(ind
);
457 /** Returns page object for given page name.
459 wxPropertyGridPage
* GetPage( const wxString
& name
) const
461 return GetPage(GetPageByName(name
));
465 Returns index for a page name.
467 If no match is found, wxNOT_FOUND is returned.
469 int GetPageByName( const wxString
& name
) const;
471 /** Returns index for a relevant propertygrid state.
473 If no match is found, wxNOT_FOUND is returned.
475 int GetPageByState( const wxPropertyGridPageState
* pstate
) const;
477 /** Returns wxPropertyGridPageState of given page, current page's for -1.
479 virtual wxPropertyGridPageState
* GetPageState( int page
) const;
481 /** Returns number of managed pages. */
482 size_t GetPageCount() const;
484 /** Returns name of given page. */
485 const wxString
& GetPageName( int index
) const;
487 /** Returns "root property" of the given page. It does not have name, etc.
488 and it is not visible. It is only useful for accessing its children.
490 wxPGProperty
* GetPageRoot( int index
) const;
492 /** Returns index to currently selected page. */
493 int GetSelectedPage() const { return m_selPage
; }
495 /** Shortcut for GetGrid()->GetSelection(). */
496 wxPGProperty
* GetSelection() const
498 return m_pPropGrid
->GetSelection();
501 /** Returns a pointer to the toolbar currently associated with the
502 wxPropertyGridManager (if any). */
503 wxToolBar
* GetToolBar() const { return m_pToolbar
; }
505 /** Creates new property page. Note that the first page is not created
508 Add to this position. -1 will add as the last item.
510 A label for the page. This may be shown as a toolbar tooltip etc.
512 Bitmap image for toolbar. If wxNullBitmap is used, then a built-in
513 default image is used.
515 wxPropertyGridPage instance. Manager will take ownership of this object.
516 If NULL, default page object is constructed.
519 Returns pointer to created page.
521 virtual wxPropertyGridPage
* InsertPage( int index
,
522 const wxString
& label
,
523 const wxBitmap
& bmp
= wxNullBitmap
,
524 wxPropertyGridPage
* pageObj
= NULL
);
527 Returns true if any property on any page has been modified by the user.
529 bool IsAnyModified() const;
532 Returns true if updating is frozen (ie Freeze() called but not yet
535 bool IsFrozen() const { return m_pPropGrid
->m_frozen
> 0; }
538 Returns true if any property on given page has been modified by the
541 bool IsPageModified( size_t index
) const;
543 virtual void Refresh( bool eraseBackground
= true,
544 const wxRect
* rect
= (const wxRect
*) NULL
);
548 Returns false if it was not possible to remove page in question.
550 virtual bool RemovePage( int page
);
552 /** Select and displays a given page.
555 Index of page being seleced. Can be -1 to select nothing.
557 void SelectPage( int index
);
559 /** Select and displays a given page (by label). */
560 void SelectPage( const wxString
& label
)
562 int index
= GetPageByName(label
);
563 wxCHECK_RET( index
>= 0, wxT("No page with such name") );
567 /** Select and displays a given page. */
568 void SelectPage( wxPropertyGridPage
* ptr
)
570 SelectPage( GetPageByState(ptr
) );
573 /** Select a property. */
574 bool SelectProperty( wxPGPropArg id
, bool focus
= false )
576 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
577 return p
->GetParentState()->DoSelectProperty(p
, focus
);
580 /** Sets number of columns on given page (default is current page).
582 void SetColumnCount( int colCount
, int page
= -1 );
584 /** Sets label and text in description box.
586 void SetDescription( const wxString
& label
, const wxString
& content
);
588 /** Sets y coordinate of the description box splitter. */
589 void SetDescBoxHeight( int ht
, bool refresh
= true );
591 /** Moves splitter as left as possible, while still allowing all
592 labels to be shown in full.
594 If false, will still allow sub-properties (ie. properties which
595 parent is not root or category) to be cropped.
597 If true, takes labels on all pages into account.
599 void SetSplitterLeft( bool subProps
= false, bool allPages
= true );
601 /** Sets splitter position on individual page. */
602 void SetPageSplitterPosition( int page
, int pos
, int column
= 0 )
604 GetPage(page
)->DoSetSplitterPosition( pos
, column
);
607 /** Sets splitter position for all pages.
609 Splitter position cannot exceed grid size, and therefore setting it
610 during form creation may fail as initial grid size is often smaller
611 than desired splitter position, especially when sizers are being used.
613 void SetSplitterPosition( int pos
, int column
= 0 );
617 def
GetValuesFromPage(self
,
621 inc_attributes
=False
):
622 "Same as GetValues, but returns values from specific page only."
623 "For argument descriptions, see GetValues."
624 return page
.GetPropertyValues(dict_
, as_strings
, inc_attributes
)
631 // Subclassing helpers
634 /** Creates property grid for the manager. Override to use subclassed
637 virtual wxPropertyGrid
* CreatePropertyGrid() const;
639 virtual void RefreshProperty( wxPGProperty
* p
);
646 // Overridden functions - no documentation required.
649 virtual wxSize
DoGetBestSize() const;
650 void SetId( wxWindowID winid
);
652 virtual void Freeze();
654 virtual void SetExtraStyle ( long exStyle
);
655 virtual bool SetFont ( const wxFont
& font
);
656 virtual void SetWindowStyleFlag ( long style
);
667 void OnMouseMove( wxMouseEvent
&event
);
668 void OnMouseClick( wxMouseEvent
&event
);
669 void OnMouseUp( wxMouseEvent
&event
);
670 void OnMouseEntry( wxMouseEvent
&event
);
672 void OnPaint( wxPaintEvent
&event
);
674 void OnToolbarClick( wxCommandEvent
&event
);
675 void OnResize( wxSizeEvent
& event
);
676 void OnPropertyGridSelect( wxPropertyGridEvent
& event
);
680 wxPropertyGrid
* m_pPropGrid
;
682 wxArrayPtrVoid m_arrPages
;
685 wxToolBar
* m_pToolbar
;
687 wxStaticText
* m_pTxtHelpCaption
;
688 wxStaticText
* m_pTxtHelpContent
;
690 wxPropertyGridPage
* m_emptyPage
;
694 // Selected page index.
705 int m_splitterHeight
;
711 wxCursor m_cursorSizeNS
;
713 int m_nextDescBoxSize
;
717 unsigned char m_dragStatus
;
719 unsigned char m_onSplitter
;
721 virtual wxPGProperty
* DoGetPropertyByName( const wxString
& name
) const;
723 /** Select and displays a given page. */
724 virtual bool DoSelectPage( int index
);
726 // Sets some members to defaults.
729 // Initializes some members.
730 void Init2( int style
);
733 virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle) const;
736 /** Recalculates new positions for components, according to the
739 void RecalculatePositions( int width
, int height
);
741 /** (Re)creates/destroys controls, according to the window style bits. */
742 void RecreateControls();
744 void RefreshHelpBox( int new_splittery
, int new_width
, int new_height
);
746 void RepaintSplitter( wxDC
& dc
,
752 void SetDescribedProperty( wxPGProperty
* p
);
754 virtual bool ProcessEvent( wxEvent
& event
);
757 DECLARE_EVENT_TABLE()
758 #endif // #ifndef SWIG
759 #endif // #ifndef DOXYGEN
762 // -----------------------------------------------------------------------
764 inline int wxPropertyGridPage
::GetIndex() const
768 return m_manager
->GetPageByState(this);
771 // -----------------------------------------------------------------------
773 #endif // wxUSE_PROPGRID
775 #endif // _WX_PROPGRID_MANAGER_H_