1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/manager.h
3 // Purpose: wxPropertyGridManager
4 // Author: Jaakko Salli
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PROPGRID_MANAGER_H_
12 #define _WX_PROPGRID_MANAGER_H_
18 #include "wx/propgrid/propgrid.h"
20 #include "wx/dcclient.h"
21 #include "wx/scrolwin.h"
22 #include "wx/toolbar.h"
23 #include "wx/stattext.h"
24 #include "wx/button.h"
25 #include "wx/textctrl.h"
26 #include "wx/dialog.h"
27 #include "wx/headerctrl.h"
29 // -----------------------------------------------------------------------
32 extern WXDLLIMPEXP_DATA_PROPGRID(const char) wxPropertyGridManagerNameStr
[];
35 /** @class wxPropertyGridPage
37 Holder of property grid page information. You can subclass this and
38 give instance in wxPropertyGridManager::AddPage. It inherits from
39 wxEvtHandler and can be used to process events specific to this
40 page (id of events will still be same as manager's). If you don't
41 want to use it to process all events of the page, you need to
42 return false in the derived wxPropertyGridPage::IsHandlingAllEvents.
44 Please note that wxPropertyGridPage lacks many non-const property
45 manipulation functions found in wxPropertyGridManager. Please use
46 parent manager (m_manager member variable) when needed.
48 Please note that most member functions are inherited and as such not
49 documented on this page. This means you will probably also want to read
50 wxPropertyGridInterface class reference.
52 @section propgridpage_event_handling Event Handling
54 wxPropertyGridPage receives events emitted by its wxPropertyGridManager, but
55 only those events that are specific to that page. If
56 wxPropertyGridPage::IsHandlingAllEvents returns false, then unhandled
57 events are sent to the manager's parent, as usual.
59 See @ref propgrid_event_handling "wxPropertyGrid Event Handling"
65 class WXDLLIMPEXP_PROPGRID wxPropertyGridPage
: public wxEvtHandler
,
66 public wxPropertyGridInterface
,
67 public wxPropertyGridPageState
69 friend class wxPropertyGridManager
;
70 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 int flags
= wxPG_SPLITTER_REFRESH
);
168 /** Page label (may be referred as name in some parts of documentation).
169 Can be set in constructor, or passed in
170 wxPropertyGridManager::AddPage(), but *not* in both.
174 //virtual bool ProcessEvent( wxEvent& event );
176 wxPropertyGridManager
* m_manager
;
178 // Toolbar tool id. Note that this is only valid when the tool bar
183 bool m_isDefault
; // is this base page object?
185 DECLARE_EVENT_TABLE()
188 // -----------------------------------------------------------------------
191 class wxPGHeaderCtrl
;
195 /** @class wxPropertyGridManager
197 wxPropertyGridManager is an efficient multi-page version of wxPropertyGrid,
198 which can optionally have toolbar for mode and page selection, and help
200 Use window flags to select components to include.
202 @section propgridmanager_window_styles_ Window Styles
204 See @ref propgrid_window_styles.
206 @section propgridmanager_event_handling Event Handling
208 See @ref propgrid_event_handling "wxPropertyGrid Event Handling"
209 for more information.
214 class WXDLLIMPEXP_PROPGRID
215 wxPropertyGridManager
: public wxPanel
, public wxPropertyGridInterface
217 DECLARE_CLASS(wxPropertyGridManager
)
218 friend class wxPropertyGridPage
;
223 Two step constructor.
224 Call Create when this constructor is called to build up the
225 wxPropertyGridManager.
227 wxPropertyGridManager();
230 /** The default constructor. The styles to be used are styles valid for
232 @see @link wndflags Additional Window Styles@endlink
234 wxPropertyGridManager( wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
235 const wxPoint
& pos
= wxDefaultPosition
,
236 const wxSize
& size
= wxDefaultSize
,
237 long style
= wxPGMAN_DEFAULT_STYLE
,
238 const wxString
& name
= wxPropertyGridManagerNameStr
);
241 virtual ~wxPropertyGridManager();
243 /** Creates new property page. Note that the first page is not created
246 A label for the page. This may be shown as a toolbar tooltip etc.
248 Bitmap image for toolbar. If wxNullBitmap is used, then a built-in
249 default image is used.
251 wxPropertyGridPage instance. Manager will take ownership of this object.
252 NULL indicates that a default page instance should be created.
255 Returns pointer to created page.
258 If toolbar is used, it is highly recommended that the pages are
259 added when the toolbar is not turned off using window style flag
262 wxPropertyGridPage
* AddPage( const wxString
& label
= wxEmptyString
,
263 const wxBitmap
& bmp
= wxPG_NULL_BITMAP
,
264 wxPropertyGridPage
* pageObj
= NULL
)
266 return InsertPage(-1, label
, bmp
, pageObj
);
269 /** Deletes all all properties and all pages.
271 virtual void Clear();
273 /** Deletes all properties on given page.
275 void ClearPage( int page
);
277 /** Forces updating the value of property from the editor control.
278 Returns true if DoPropertyChanged was actually called.
280 bool CommitChangesFromEditor( wxUint32 flags
= 0 )
282 return m_pPropGrid
->CommitChangesFromEditor(flags
);
287 Whenever the control is created without any parameters, use Create to
288 actually create it. Don't access the control's public methods before
290 @see @link wndflags Additional Window Styles@endlink
292 bool Create( wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
293 const wxPoint
& pos
= wxDefaultPosition
,
294 const wxSize
& size
= wxDefaultSize
,
295 long style
= wxPGMAN_DEFAULT_STYLE
,
296 const wxString
& name
= wxPropertyGridManagerNameStr
);
299 Enables or disables (shows/hides) categories according to parameter
302 WARNING: Not tested properly, use at your own risk.
304 bool EnableCategories( bool enable
)
306 long fl
= m_windowStyle
| wxPG_HIDE_CATEGORIES
;
307 if ( enable
) fl
= m_windowStyle
& ~(wxPG_HIDE_CATEGORIES
);
308 SetWindowStyleFlag(fl
);
312 /** Selects page, scrolls and/or expands items to ensure that the
313 given item is visible. Returns true if something was actually done.
315 bool EnsureVisible( wxPGPropArg id
);
317 /** Returns number of columns on given page. By the default,
318 returns number of columns on current page. */
319 int GetColumnCount( int page
= -1 ) const;
321 /** Returns height of the description text box. */
322 int GetDescBoxHeight() const;
324 /** Returns pointer to the contained wxPropertyGrid. This does not change
325 after wxPropertyGridManager has been created, so you can safely obtain
326 pointer once and use it for the entire lifetime of the instance.
328 wxPropertyGrid
* GetGrid()
330 wxASSERT(m_pPropGrid
);
334 const wxPropertyGrid
* GetGrid() const
336 wxASSERT(m_pPropGrid
);
337 return (const wxPropertyGrid
*)m_pPropGrid
;
340 /** Returns iterator class instance.
342 Calling this method in wxPropertyGridManager causes run-time assertion
343 failure. Please only iterate through individual pages or use
346 wxPropertyGridIterator
GetIterator( int flags
= wxPG_ITERATE_DEFAULT
,
347 wxPGProperty
* firstProp
= NULL
)
349 wxFAIL_MSG( "Please only iterate through individual pages "
350 "or use CreateVIterator()" );
351 return wxPropertyGridInterface::GetIterator( flags
, firstProp
);
354 wxPropertyGridConstIterator
355 GetIterator(int flags
= wxPG_ITERATE_DEFAULT
,
356 wxPGProperty
* firstProp
= NULL
) const
358 wxFAIL_MSG( "Please only iterate through individual pages "
359 " or use CreateVIterator()" );
360 return wxPropertyGridInterface::GetIterator( flags
, firstProp
);
363 /** Returns iterator class instance.
365 Calling this method in wxPropertyGridManager causes run-time assertion
366 failure. Please only iterate through individual pages or use
369 wxPropertyGridIterator
GetIterator( int flags
, int startPos
)
371 wxFAIL_MSG( "Please only iterate through individual pages "
372 "or use CreateVIterator()" );
374 return wxPropertyGridInterface::GetIterator( flags
, startPos
);
377 wxPropertyGridConstIterator
GetIterator( int flags
, int startPos
) const
379 wxFAIL_MSG( "Please only iterate through individual pages "
380 "or use CreateVIterator()" );
381 return wxPropertyGridInterface::GetIterator( flags
, startPos
);
384 /** Similar to GetIterator, but instead returns wxPGVIterator instance,
385 which can be useful for forward-iterating through arbitrary property
388 virtual wxPGVIterator
GetVIterator( int flags
) const;
390 /** Returns currently selected page.
392 wxPropertyGridPage
* GetCurrentPage() const
394 return GetPage(m_selPage
);
397 /** Returns page object for given page index.
399 wxPropertyGridPage
* GetPage( unsigned int ind
) const
401 return m_arrPages
[ind
];
404 /** Returns page object for given page name.
406 wxPropertyGridPage
* GetPage( const wxString
& name
) const
408 return GetPage(GetPageByName(name
));
412 Returns index for a page name.
414 If no match is found, wxNOT_FOUND is returned.
416 int GetPageByName( const wxString
& name
) const;
418 /** Returns index for a relevant propertygrid state.
420 If no match is found, wxNOT_FOUND is returned.
422 int GetPageByState( const wxPropertyGridPageState
* pstate
) const;
425 /** Returns wxPropertyGridPageState of given page, current page's for -1.
427 virtual wxPropertyGridPageState
* GetPageState( int page
) const;
430 /** Returns number of managed pages. */
431 size_t GetPageCount() const;
433 /** Returns name of given page. */
434 const wxString
& GetPageName( int index
) const;
436 /** Returns "root property" of the given page. It does not have name, etc.
437 and it is not visible. It is only useful for accessing its children.
439 wxPGProperty
* GetPageRoot( int index
) const;
441 /** Returns index to currently selected page. */
442 int GetSelectedPage() const { return m_selPage
; }
444 /** Alias for GetSelection(). */
445 wxPGProperty
* GetSelectedProperty() const
447 return GetSelection();
450 /** Shortcut for GetGrid()->GetSelection(). */
451 wxPGProperty
* GetSelection() const
453 return m_pPropGrid
->GetSelection();
456 /** Returns a pointer to the toolbar currently associated with the
457 wxPropertyGridManager (if any). */
458 wxToolBar
* GetToolBar() const { return m_pToolbar
; }
460 /** Creates new property page. Note that the first page is not created
463 Add to this position. -1 will add as the last item.
465 A label for the page. This may be shown as a toolbar tooltip etc.
467 Bitmap image for toolbar. If wxNullBitmap is used, then a built-in
468 default image is used.
470 wxPropertyGridPage instance. Manager will take ownership of this object.
471 If NULL, default page object is constructed.
474 Returns pointer to created page.
476 virtual wxPropertyGridPage
* InsertPage( int index
,
477 const wxString
& label
,
478 const wxBitmap
& bmp
= wxNullBitmap
,
479 wxPropertyGridPage
* pageObj
= NULL
);
482 Returns true if any property on any page has been modified by the user.
484 bool IsAnyModified() const;
487 Returns true if updating is frozen (ie Freeze() called but not yet
490 bool IsFrozen() const { return m_pPropGrid
->m_frozen
> 0; }
493 Returns true if any property on given page has been modified by the
496 bool IsPageModified( size_t index
) const;
499 Returns true if property is selected. Since selection is page
500 based, this function checks every page in the manager.
502 virtual bool IsPropertySelected( wxPGPropArg id
) const;
504 virtual void Refresh( bool eraseBackground
= true,
505 const wxRect
* rect
= (const wxRect
*) NULL
);
509 Returns false if it was not possible to remove page in question.
511 virtual bool RemovePage( int page
);
513 /** Select and displays a given page.
516 Index of page being seleced. Can be -1 to select nothing.
518 void SelectPage( int index
);
520 /** Select and displays a given page (by label). */
521 void SelectPage( const wxString
& label
)
523 int index
= GetPageByName(label
);
524 wxCHECK_RET( index
>= 0, wxT("No page with such name") );
528 /** Select and displays a given page. */
529 void SelectPage( wxPropertyGridPage
* ptr
)
531 SelectPage( GetPageByState(ptr
) );
534 /** Select a property. */
535 bool SelectProperty( wxPGPropArg id
, bool focus
= false )
537 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
538 return p
->GetParentState()->DoSelectProperty(p
, focus
);
542 Sets a column title. Default title for column 0 is "Property",
543 and "Value" for column 1.
545 @remarks If header is not shown yet, then calling this
546 member function will make it visible.
548 void SetColumnTitle( int idx
, const wxString
& title
);
551 Sets number of columns on given page (default is current page).
553 @remarks If you use header, then you should always use this
554 member function to set the column count, instead of
555 ones present in wxPropertyGrid or wxPropertyGridPage.
557 void SetColumnCount( int colCount
, int page
= -1 );
559 /** Sets label and text in description box.
561 void SetDescription( const wxString
& label
, const wxString
& content
);
563 /** Sets y coordinate of the description box splitter. */
564 void SetDescBoxHeight( int ht
, bool refresh
= true );
566 /** Moves splitter as left as possible, while still allowing all
567 labels to be shown in full.
569 If false, will still allow sub-properties (ie. properties which
570 parent is not root or category) to be cropped.
572 If true, takes labels on all pages into account.
574 void SetSplitterLeft( bool subProps
= false, bool allPages
= true );
576 /** Moves splitter as left as possible on an individual page, while still allowing all
577 labels to be shown in full.
579 void SetPageSplitterLeft(int page
, bool subProps
= false);
582 Sets splitter position on individual page.
584 @remarks If you use header, then you should always use this
585 member function to set the splitter position, instead of
586 ones present in wxPropertyGrid or wxPropertyGridPage.
588 void SetPageSplitterPosition( int page
, int pos
, int column
= 0 );
591 Sets splitter position for all pages.
593 @remarks Splitter position cannot exceed grid size, and therefore
594 setting it during form creation may fail as initial grid
595 size is often smaller than desired splitter position,
596 especially when sizers are being used.
598 If you use header, then you should always use this
599 member function to set the splitter position, instead of
600 ones present in wxPropertyGrid or wxPropertyGridPage.
602 void SetSplitterPosition( int pos
, int column
= 0 );
606 Show or hide the property grid header control. It is hidden
609 @remarks Grid may look better if you use wxPG_NO_INTERNAL_BORDER
610 window style when showing a header.
612 void ShowHeader(bool show
= true);
618 // Subclassing helpers
622 Creates property grid for the manager. Reimplement in derived class to
623 use subclassed wxPropertyGrid. However, if you do this then you
624 must also use the two-step construction (ie. default constructor and
625 Create() instead of constructor with arguments) when creating the
628 virtual wxPropertyGrid
* CreatePropertyGrid() const;
631 virtual void RefreshProperty( wxPGProperty
* p
);
634 // Overridden functions - no documentation required.
637 void SetId( wxWindowID winid
);
639 virtual void Freeze();
641 virtual void SetExtraStyle ( long exStyle
);
642 virtual bool SetFont ( const wxFont
& font
);
643 virtual void SetWindowStyleFlag ( long style
);
644 virtual bool Reparent( wxWindowBase
*newParent
);
647 virtual wxSize
DoGetBestSize() const;
652 void OnMouseMove( wxMouseEvent
&event
);
653 void OnMouseClick( wxMouseEvent
&event
);
654 void OnMouseUp( wxMouseEvent
&event
);
655 void OnMouseEntry( wxMouseEvent
&event
);
657 void OnPaint( wxPaintEvent
&event
);
659 void OnToolbarClick( wxCommandEvent
&event
);
660 void OnResize( wxSizeEvent
& event
);
661 void OnPropertyGridSelect( wxPropertyGridEvent
& event
);
662 void OnPGColDrag( wxPropertyGridEvent
& event
);
665 wxPropertyGrid
* m_pPropGrid
;
667 wxVector
<wxPropertyGridPage
*> m_arrPages
;
670 wxToolBar
* m_pToolbar
;
673 wxPGHeaderCtrl
* m_pHeaderCtrl
;
675 wxStaticText
* m_pTxtHelpCaption
;
676 wxStaticText
* m_pTxtHelpContent
;
678 wxPropertyGridPage
* m_emptyPage
;
680 wxArrayString m_columnLabels
;
684 // Selected page index.
695 int m_splitterHeight
;
699 wxCursor m_cursorSizeNS
;
701 int m_nextDescBoxSize
;
703 // Toolbar tool ids for categorized and alphabetic mode selectors.
704 int m_categorizedModeToolId
;
705 int m_alphabeticModeToolId
;
707 unsigned char m_dragStatus
;
709 unsigned char m_onSplitter
;
713 virtual wxPGProperty
* DoGetPropertyByName( const wxString
& name
) const;
715 /** Select and displays a given page. */
716 virtual bool DoSelectPage( int index
);
718 // Sets some members to defaults.
721 // Initializes some members.
722 void Init2( int style
);
725 virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle) const;
728 virtual bool ProcessEvent( wxEvent
& event
);
730 /** Recalculates new positions for components, according to the
733 void RecalculatePositions( int width
, int height
);
735 /** (Re)creates/destroys controls, according to the window style bits. */
736 void RecreateControls();
738 void UpdateDescriptionBox( int new_splittery
, int new_width
, int new_height
);
740 void RepaintDescBoxDecorations( wxDC
& dc
,
745 void SetDescribedProperty( wxPGProperty
* p
);
747 // Reimplement these to handle "descboxheight" state item
748 virtual bool SetEditableStateItem( const wxString
& name
, wxVariant value
);
749 virtual wxVariant
GetEditableStateItem( const wxString
& name
) const;
752 DECLARE_EVENT_TABLE()
755 // -----------------------------------------------------------------------
757 inline int wxPropertyGridPage::GetIndex() const
761 return m_manager
->GetPageByState(this);
764 // -----------------------------------------------------------------------
766 #endif // wxUSE_PROPGRID
768 #endif // _WX_PROPGRID_MANAGER_H_