1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPropertyGridManager
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
9 /** @class wxPropertyGridPage
11 Holder of property grid page information. You can subclass this and
12 give instance in wxPropertyGridManager::AddPage. It inherits from
13 wxEvtHandler and can be used to process events specific to this
14 page (id of events will still be same as manager's). If you don't
15 want to use it to process all events of the page, you need to
16 return false in the derived wxPropertyGridPage::IsHandlingAllEvents.
18 Please note that wxPropertyGridPage lacks many non-const property
19 manipulation functions found in wxPropertyGridManager. Please use
20 parent manager (m_manager member variable) when needed.
22 Please note that most member functions are inherited and as such not
23 documented on this page. This means you will probably also want to read
24 wxPropertyGridInterface class reference.
26 @section propgridpage_event_handling Event Handling
28 wxPropertyGridPage receives events emitted by its wxPropertyGridManager, but
29 only those events that are specific to that page. If wxPropertyGridPage::
30 IsHandlingAllEvents returns false, then unhandled events are sent to the
31 manager's parent, as usual.
33 See @ref propgrid_event_handling "wxPropertyGrid Event Handling"
39 class WXDLLIMPEXP_PROPGRID wxPropertyGridPage
: public wxEvtHandler
,
40 public wxPropertyGridInterface
42 friend class wxPropertyGridManager
;
46 virtual ~wxPropertyGridPage();
49 Deletes all properties on page.
54 Reduces column sizes to minimum possible that contents are still visibly
55 (naturally some margin space will be applied as well).
57 @return Returns minimum size for the page to still display everything.
59 @remarks This function only works properly if size of containing grid was
62 Note that you can also get calculated column widths by calling
63 GetColumnWidth() immediately after this function returns.
68 Returns page index in manager;
70 inline int GetIndex() const;
73 Returns "root property". It does not have name, etc. and it is not
74 visible. It is only useful for accessing its children.
76 wxPGProperty
* GetRoot() const;
79 Returns x-coordinate position of splitter on a page.
81 int GetSplitterPosition( int col
= 0 ) const;
84 Returns id of the tool bar item that represents this page on
85 wxPropertyGridManager's wxToolBar.
93 Do any member initialization in this method.
95 @remarks - Called every time the page is added into a manager.
96 - You can add properties to the page here.
98 virtual void Init() {}
101 Return false here to indicate unhandled events should be
102 propagated to manager's parent, as normal.
104 virtual bool IsHandlingAllEvents() const { return true; }
107 Called every time page is about to be shown.
108 Useful, for instance, creating properties just-in-time.
110 virtual void OnShow();
113 Refreshes given property on page.
115 virtual void RefreshProperty( wxPGProperty
* p
);
117 /** Sets splitter position on page.
119 Splitter position cannot exceed grid size, and therefore setting it
120 during form creation may fail as initial grid size is often smaller than
121 desired splitter position, especially when sizers are being used.
123 void SetSplitterPosition( int splitterPos
, int col
= 0 );
126 // -----------------------------------------------------------------------
128 /** @class wxPropertyGridManager
130 wxPropertyGridManager is an efficient multi-page version of wxPropertyGrid,
131 which can optionally have toolbar for mode and page selection, and a help text
134 wxPropertyGridManager inherits from wxPropertyGridInterface, and as such
135 it has most property manipulation functions. However, only some of them affect
136 properties on all pages (eg. GetPropertyByName() and ExpandAll()), while some
137 (eg. Append()) only apply to the currently selected page.
139 To operate explicitly on properties on specific page, use
140 wxPropertyGridManager::GetPage() to obtain pointer to page's
141 wxPropertyGridPage object.
143 Visual methods, such as SetCellBackgroundColour() are only available in
144 wxPropertyGrid. Use wxPropertyGridManager::GetGrid() to obtain pointer to it.
146 Non-virtual iterators will not work in wxPropertyGridManager. Instead, you must
147 acquire the internal grid (GetGrid()) or wxPropertyGridPage object (GetPage()).
149 wxPropertyGridManager constructor has exact same format as wxPropertyGrid
150 constructor, and basicly accepts same extra window style flags (albeit also
151 has some extra ones).
153 Here's some example code for creating and populating a wxPropertyGridManager:
157 wxPropertyGridManager* pgMan = new wxPropertyGridManager(this, PGID,
158 wxDefaultPosition, wxDefaultSize,
159 // These and other similar styles are automatically
160 // passed to the embedded wxPropertyGrid.
161 wxPG_BOLD_MODIFIED|wxPG_SPLITTER_AUTO_CENTER|
164 // Include description box.
166 // Include compactor.
169 wxPGMAN_DEFAULT_STYLE
172 wxPropertyGridPage* page;
174 page = pgMan->AddPage(wxT("First Page"));
176 page->Append( new wxPropertyCategory(wxT("Category A1")) );
178 page->Append( new wxIntProperty(wxT("Number"),wxPG_LABEL,1) );
180 page->Append( new wxColourProperty(wxT("Colour"),wxPG_LABEL,*wxWHITE) );
182 page = pgMan->AddPage(wxT("Second Page"));
184 page->Append( wxT("Text"),wxPG_LABEL,wxT("(no text)") );
186 page->Append( new wxFontProperty(wxT("Font"),wxPG_LABEL) );
191 @section propgridmanager_window_styles_ Window Styles
193 See @ref propgrid_window_styles.
195 @section propgridmanager_event_handling Event Handling
197 See @ref propgrid_event_handling "wxPropertyGrid Event Handling"
198 for more information.
203 class wxPropertyGridManager
: public wxPanel
, public wxPropertyGridInterface
207 Creates new property page. Note that the first page is not created
211 A label for the page. This may be shown as a toolbar tooltip etc.
214 Bitmap image for toolbar. If wxNullBitmap is used, then a built-in
215 default image is used.
218 wxPropertyGridPage instance. Manager will take ownership of this
219 object. NULL indicates that a default page instance should be created.
221 @return Returns pointer to created property grid page.
223 @remarks If toolbar is used, it is highly recommended that the pages are
224 added when the toolbar is not turned off using window style flag
225 switching. Otherwise toolbar buttons might not be added properly.
227 wxPropertyGridPage
* AddPage( const wxString
& label
= wxEmptyString
,
228 const wxBitmap
& bmp
= wxPG_NULL_BITMAP
,
229 wxPropertyGridPage
* pageObj
= NULL
);
231 void ClearModifiedStatus( wxPGPropArg id
);
233 void ClearModifiedStatus()
235 m_pPropGrid
->ClearModifiedStatus();
239 Deletes all properties and all pages.
241 virtual void Clear();
244 Deletes all properties on given page.
246 void ClearPage( int page
);
249 Forces updating the value of property from the editor control.
251 @return Returns @true if value was actually updated.
253 bool CommitChangesFromEditor( wxUint32 flags
= 0 )
255 return m_pPropGrid
->CommitChangesFromEditor(flags
);
259 Two step creation. Whenever the control is created without any parameters,
260 use Create to actually create it. Don't access the control's public methods
261 before this is called.
263 @see @ref propgrid_window_styles
265 bool Create( wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
266 const wxPoint
& pos
= wxDefaultPosition
,
267 const wxSize
& size
= wxDefaultSize
,
268 long style
= wxPGMAN_DEFAULT_STYLE
,
269 const wxChar
* name
= wxPropertyGridManagerNameStr
);
272 Enables or disables (shows/hides) categories according to parameter enable.
275 Calling his may not properly update toolbar buttons.
277 bool EnableCategories( bool enable
)
279 long fl
= m_windowStyle
| wxPG_HIDE_CATEGORIES
;
280 if ( enable
) fl
= m_windowStyle
& ~(wxPG_HIDE_CATEGORIES
);
281 SetWindowStyleFlag(fl
);
286 Selects page, scrolls and/or expands items to ensure that the
287 given item is visible.
289 @return Returns @true if something was actually done.
291 bool EnsureVisible( wxPGPropArg id
);
294 Returns number of children of the root property of the selected page.
296 size_t GetChildrenCount()
298 return GetChildrenCount( m_pPropGrid
->m_pState
->m_properties
);
302 Returns number of children of the root property of given page.
304 size_t GetChildrenCount( int pageIndex
);
307 Returns number of children for the property.
309 NB: Cannot be in container methods class due to name hiding.
311 size_t GetChildrenCount( wxPGPropArg id
) const
313 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0)
314 return p
->GetChildCount();
318 Returns number of columns on given page. By the default,
319 returns number of columns on current page.
321 int GetColumnCount( int page
= -1 ) const;
324 Returns height of the description text box.
326 int GetDescBoxHeight() const;
329 Returns pointer to the contained wxPropertyGrid. This does not change
330 after wxPropertyGridManager has been created, so you can safely obtain
331 pointer once and use it for the entire lifetime of the manager
334 wxPropertyGrid
* GetGrid();
337 Similar to GetIterator, but instead returns wxPGVIterator instance,
338 which can be useful for forward-iterating through arbitrary property
341 virtual wxPGVIterator
GetVIterator( int flags
) const;
344 Returns currently selected page.
346 wxPropertyGridPage
* GetCurrentPage() const;
349 Returns page object for given page index.
351 wxPropertyGridPage
* GetPage( unsigned int ind
) const
353 return (wxPropertyGridPage
*)m_arrPages
.Item(ind
);
357 Returns page object for given page name.
359 wxPropertyGridPage
* GetPage( const wxString
& name
) const
361 return GetPage(GetPageByName(name
));
365 Returns index for a page name. If no match is found, wxNOT_FOUND is
368 int GetPageByName( const wxString
& name
) const;
371 Returns number of managed pages.
373 size_t GetPageCount() const;
375 /** Returns name of given page. */
376 const wxString
& GetPageName( int index
) const;
379 Returns "root property" of the given page. It does not have name, etc.
380 and it is not visible. It is only useful for accessing its children.
382 wxPGProperty
* GetPageRoot( int index
) const;
384 /** Returns index to currently selected page. */
385 int GetSelectedPage() const { return m_selPage
; }
387 /** Shortcut for GetGrid()->GetSelection(). */
388 wxPGProperty
* GetSelectedProperty() const
390 return m_pPropGrid
->GetSelection();
393 /** Synonyme for GetSelectedPage. */
394 int GetSelection() const { return m_selPage
; }
397 Returns a pointer to the toolbar currently associated with the
398 wxPropertyGridManager (if any).
400 wxToolBar
* GetToolBar() const { return m_pToolbar
; }
402 /** Creates new property page. Note that the first page is not created
406 Add to this position. -1 will add as the last item.
409 A label for the page. This may be shown as a toolbar tooltip etc.
412 Bitmap image for toolbar. If wxNullBitmap is used, then a built-in
413 default image is used.
416 wxPropertyGridPage instance. Manager will take ownership of this
417 object. If NULL, default page object is constructed.
419 @return Returns pointer to created page.
421 virtual wxPropertyGridPage
* InsertPage( int index
, const wxString
& label
,
422 const wxBitmap
& bmp
= wxNullBitmap
,
423 wxPropertyGridPage
* pageObj
= NULL
);
426 Returns @true if any property on any page has been modified by the user.
428 bool IsAnyModified() const;
431 Returns @true if updating is frozen (ie. Freeze() called but not yet
434 bool IsFrozen() const;
437 Returns @true if any property on given page has been modified by the user.
439 bool IsPageModified( size_t index
) const;
443 @return Returns @false if it was not possible to remove page in question.
445 virtual bool RemovePage( int page
);
447 /** Select and displays a given page.
450 Index of page being seleced. Can be -1 to select nothing.
452 void SelectPage( int index
);
455 Select and displays a given page (by label).
457 void SelectPage( const wxString
& label
);
459 /** Select and displays a given page. */
460 void SelectPage( wxPropertyGridPage
* page
);
462 /** Select a property. */
463 bool SelectProperty( wxPGPropArg id
, bool focus
= false );
466 Sets number of columns on given page (default is current page).
468 void SetColumnCount( int colCount
, int page
= -1 );
470 /** Sets label and text in description box.
472 void SetDescription( const wxString
& label
, const wxString
& content
);
474 /** Sets y coordinate of the description box splitter. */
475 void SetDescBoxHeight( int ht
, bool refresh
= true );
477 /** Moves splitter as left as possible, while still allowing all
478 labels to be shown in full.
481 If @false, will still allow sub-properties (ie. properties which
482 parent is not root or category) to be cropped.
485 If @true, takes labels on all pages into account.
487 void SetSplitterLeft( bool subProps
= false, bool allPages
= true );
489 /** Sets splitter position on individual page. */
490 void SetPageSplitterPosition( int page
, int pos
, int column
= 0 )
492 GetPage(page
)->DoSetSplitterPosition( pos
, column
);
496 Sets splitter position for all pages.
498 @remarks Splitter position cannot exceed grid size, and therefore setting
499 it during form creation may fail as initial grid size is often
500 smaller than desired splitter position, especially when sizers
503 void SetSplitterPosition( int pos
, int column
= 0 );
505 /** Synonyme for SelectPage(name). */
506 void SetStringSelection( const wxChar
* name
)
508 SelectPage( GetPageByName(name
) );
514 // Subclassing helpers
518 Creates property grid for the manager. Override to use subclassed
521 virtual wxPropertyGrid
* CreatePropertyGrid() const;
524 // -----------------------------------------------------------------------