]> git.saurik.com Git - wxWidgets.git/blame - include/wx/propgrid/propgrid.h
moving themeing include to private.h
[wxWidgets.git] / include / wx / propgrid / propgrid.h
CommitLineData
1c4293cb
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/propgrid/propgrid.h
3// Purpose: wxPropertyGrid
4// Author: Jaakko Salli
5// Modified by:
6// Created: 2004-09-25
ea5af9c5 7// RCS-ID: $Id$
1c4293cb
VZ
8// Copyright: (c) Jaakko Salli
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_PROPGRID_PROPGRID_H_
13#define _WX_PROPGRID_PROPGRID_H_
14
f4bc1aa2
JS
15#if wxUSE_PROPGRID
16
1c4293cb
VZ
17#include "wx/dcclient.h"
18#include "wx/scrolwin.h"
19#include "wx/tooltip.h"
20#include "wx/datetime.h"
21
22#include "wx/propgrid/property.h"
23#include "wx/propgrid/propgridiface.h"
24
25
26#ifndef SWIG
23318a53 27extern WXDLLIMPEXP_DATA_PROPGRID(const char) wxPropertyGridNameStr[];
1c4293cb
VZ
28#endif
29
e9cc4973 30class wxPGComboBox;
1c4293cb
VZ
31
32// -----------------------------------------------------------------------
33// Global variables
34// -----------------------------------------------------------------------
35
36#ifndef SWIG
37
38// This is required for sharing common global variables.
39class WXDLLIMPEXP_PROPGRID wxPGGlobalVarsClass
40{
41public:
42
43 wxPGGlobalVarsClass();
44 ~wxPGGlobalVarsClass();
45
46 // Used by advprops, but here to make things easier.
47 wxString m_pDefaultImageWildcard;
48
49 // Map of editor class instances (keys are name string).
50 wxPGHashMapS2P m_mapEditorClasses;
51
52#if wxUSE_VALIDATORS
f7a094e1 53 wxVector<wxValidator*> m_arrValidators; // These wxValidators need to be freed
1c4293cb
VZ
54#endif
55
56 wxPGHashMapS2P m_dictPropertyClassInfo; // PropertyName -> ClassInfo
57
58 wxPGChoices* m_fontFamilyChoices;
59
60 // Replace with your own to affect all properties using default renderer.
61 wxPGCellRenderer* m_defaultRenderer;
62
1c4293cb
VZ
63 wxPGChoices m_boolChoices;
64
65 wxVariant m_vEmptyString;
66 wxVariant m_vZero;
67 wxVariant m_vMinusOne;
68 wxVariant m_vTrue;
69 wxVariant m_vFalse;
70
71 // Cached constant strings
0372d42e
JS
72 wxPGCachedString m_strstring;
73 wxPGCachedString m_strlong;
74 wxPGCachedString m_strbool;
75 wxPGCachedString m_strlist;
76
0ce8e27f 77 wxPGCachedString m_strDefaultValue;
1c4293cb
VZ
78 wxPGCachedString m_strMin;
79 wxPGCachedString m_strMax;
80 wxPGCachedString m_strUnits;
81 wxPGCachedString m_strInlineHelp;
82
83 // If true then some things are automatically translated
84 bool m_autoGetTranslation;
85
86 // > 0 if errors cannot or should not be shown in statusbar etc.
87 int m_offline;
88
89 int m_extraStyle; // global extra style
90
1c4293cb 91 int m_warnings;
1c4293cb
VZ
92
93 int HasExtraStyle( int style ) const { return (m_extraStyle & style); }
94};
95
96extern WXDLLIMPEXP_PROPGRID wxPGGlobalVarsClass* wxPGGlobalVars;
97
1c4293cb
VZ
98#define wxPGVariant_EmptyString (wxPGGlobalVars->m_vEmptyString)
99#define wxPGVariant_Zero (wxPGGlobalVars->m_vZero)
100#define wxPGVariant_MinusOne (wxPGGlobalVars->m_vMinusOne)
101#define wxPGVariant_True (wxPGGlobalVars->m_vTrue)
102#define wxPGVariant_False (wxPGGlobalVars->m_vFalse)
103
104#define wxPGVariant_Bool(A) (A?wxPGVariant_True:wxPGVariant_False)
105
b512ed93
JS
106// When wxPG is loaded dynamically after the application is already running
107// then the built-in module system won't pick this one up. Add it manually.
108WXDLLIMPEXP_PROPGRID void wxPGInitResourceModule();
109
1c4293cb
VZ
110#endif // !SWIG
111
112// -----------------------------------------------------------------------
113
114/** @section propgrid_window_styles wxPropertyGrid Window Styles
115
116 SetWindowStyleFlag method can be used to modify some of these at run-time.
117 @{
118*/
119enum wxPG_WINDOW_STYLES
120{
121
122/** This will cause Sort() automatically after an item is added.
123 When inserting a lot of items in this mode, it may make sense to
124 use Freeze() before operations and Thaw() afterwards to increase
125 performance.
126*/
127wxPG_AUTO_SORT = 0x00000010,
128
129/** Categories are not initially shown (even if added).
130 IMPORTANT NOTE: If you do not plan to use categories, then this
131 style will waste resources.
132 This flag can also be changed using wxPropertyGrid::EnableCategories method.
133*/
134wxPG_HIDE_CATEGORIES = 0x00000020,
135
136/* This style combines non-categoric mode and automatic sorting.
137*/
138wxPG_ALPHABETIC_MODE = (wxPG_HIDE_CATEGORIES|wxPG_AUTO_SORT),
139
140/** Modified values are shown in bold font. Changing this requires Refresh()
141 to show changes.
142*/
143wxPG_BOLD_MODIFIED = 0x00000040,
144
145/** When wxPropertyGrid is resized, splitter moves to the center. This
146 behavior stops once the user manually moves the splitter.
147*/
148wxPG_SPLITTER_AUTO_CENTER = 0x00000080,
149
150/** Display tooltips for cell text that cannot be shown completely. If
151 wxUSE_TOOLTIPS is 0, then this doesn't have any effect.
152*/
153wxPG_TOOLTIPS = 0x00000100,
154
155/** Disables margin and hides all expand/collapse buttons that would appear
156 outside the margin (for sub-properties). Toggling this style automatically
157 expands all collapsed items.
158*/
159wxPG_HIDE_MARGIN = 0x00000200,
160
161/** This style prevents user from moving the splitter.
162*/
163wxPG_STATIC_SPLITTER = 0x00000400,
164
165/** Combination of other styles that make it impossible for user to modify
166 the layout.
167*/
168wxPG_STATIC_LAYOUT = (wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER),
169
170/** Disables wxTextCtrl based editors for properties which
171 can be edited in another way.
172
173 Equals calling wxPropertyGrid::LimitPropertyEditing for all added
174 properties.
175*/
176wxPG_LIMITED_EDITING = 0x00000800,
177
178/** wxPropertyGridManager only: Show toolbar for mode and page selection. */
179wxPG_TOOLBAR = 0x00001000,
180
181/** wxPropertyGridManager only: Show adjustable text box showing description
182 or help text, if available, for currently selected property.
183*/
521f1d83 184wxPG_DESCRIPTION = 0x00002000,
1c4293cb 185
c7994b56
JS
186/** wxPropertyGridManager only: don't show an internal border around
187 the property grid.
521f1d83
JS
188*/
189wxPG_NO_INTERNAL_BORDER = 0x00004000
1c4293cb
VZ
190};
191
c7994b56
JS
192#if wxPG_COMPATIBILITY_1_4
193 // In wxPG 1.4 this was used to enable now-default theme border support
194 // in wxPropertyGridManager.
195 #define wxPG_THEME_BORDER 0x00000000
196#endif
197
198
1c4293cb
VZ
199enum wxPG_EX_WINDOW_STYLES
200{
201
202/**
203 NOTE: wxPG_EX_xxx are extra window styles and must be set using
204 SetExtraStyle() member function.
205
206 Speeds up switching to wxPG_HIDE_CATEGORIES mode. Initially, if
207 wxPG_HIDE_CATEGORIES is not defined, the non-categorized data storage is
208 not activated, and switching the mode first time becomes somewhat slower.
209 wxPG_EX_INIT_NOCAT activates the non-categorized data storage right away.
210 IMPORTANT NOTE: If you do plan not switching to non-categoric mode, or if
211 you don't plan to use categories at all, then using this style will result
212 in waste of resources.
213
214*/
215wxPG_EX_INIT_NOCAT = 0x00001000,
216
217/** Extended window style that sets wxPropertyGridManager toolbar to not
218 use flat style.
219*/
220wxPG_EX_NO_FLAT_TOOLBAR = 0x00002000,
221
222/** Shows alphabetic/categoric mode buttons from toolbar.
223*/
224wxPG_EX_MODE_BUTTONS = 0x00008000,
225
226/** Show property help strings as tool tips instead as text on the status bar.
227 You can set the help strings using SetPropertyHelpString member function.
228*/
229wxPG_EX_HELP_AS_TOOLTIPS = 0x00010000,
230
231/** Prevent TAB from focusing to wxButtons. This behavior was default
232 in version 1.2.0 and earlier.
233 NOTE! Tabbing to button doesn't work yet. Problem seems to be that on wxMSW
234 atleast the button doesn't properly propagate key events (yes, I'm using
235 wxWANTS_CHARS).
236*/
237//wxPG_EX_NO_TAB_TO_BUTTON = 0x00020000,
238
239/** Allows relying on native double-buffering.
240*/
241wxPG_EX_NATIVE_DOUBLE_BUFFERING = 0x00080000,
242
243/** Set this style to let user have ability to set values of properties to
244 unspecified state. Same as setting wxPG_PROP_AUTO_UNSPECIFIED for
245 all properties.
246*/
247wxPG_EX_AUTO_UNSPECIFIED_VALUES = 0x00200000,
248
249/**
250 If this style is used, built-in attributes (such as wxPG_FLOAT_PRECISION
251 and wxPG_STRING_PASSWORD) are not stored into property's attribute storage
252 (thus they are not readable).
253
254 Note that this option is global, and applies to all wxPG property
255 containers.
256*/
257wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES = 0x00400000,
258
1c4293cb
VZ
259/** Hides page selection buttons from toolbar.
260*/
fc72fab6 261wxPG_EX_HIDE_PAGE_BUTTONS = 0x01000000,
03647350 262
fc72fab6
JS
263/** Allows multiple properties to be selected by user (by pressing SHIFT
264 when clicking on a property, or by dragging with left mouse button
265 down).
266
267 You can get array of selected properties with
268 wxPropertyGridInterface::GetSelectedProperties(). In multiple selection
269 mode wxPropertyGridInterface::GetSelection() returns
270 property which has editor active (usually the first one
271 selected). Other useful member functions are ClearSelection(),
272 AddToSelection() and RemoveFromSelection().
273*/
08c1613f
JS
274wxPG_EX_MULTIPLE_SELECTION = 0x02000000,
275
276/**
277 This enables top-level window tracking which allows wxPropertyGrid to
278 notify the application of last-minute property value changes by user.
279
280 This style is not enabled by default because it may cause crashes when
281 wxPropertyGrid is used in with wxAUI or similar system.
282
283 @remarks If you are not in fact using any system that may change
284 wxPropertyGrid's top-level parent window on its own, then you
285 are recommended to enable this style.
286*/
521f1d83
JS
287wxPG_EX_ENABLE_TLP_TRACKING = 0x04000000,
288
289/** Don't show divider above toolbar, on Windows.
290*/
20fb9ddf 291wxPG_EX_NO_TOOLBAR_DIVIDER = 0x08000000,
521f1d83
JS
292
293/** Show a separator below the toolbar.
294*/
20fb9ddf 295wxPG_EX_TOOLBAR_SEPARATOR = 0x10000000
1c4293cb
VZ
296
297};
298
08c1613f
JS
299#if wxPG_COMPATIBILITY_1_4
300 #define wxPG_EX_DISABLE_TLP_TRACKING 0x00000000
301#endif
302
1c4293cb
VZ
303/** Combines various styles.
304*/
305#define wxPG_DEFAULT_STYLE (0)
306
307/** Combines various styles.
308*/
309#define wxPGMAN_DEFAULT_STYLE (0)
310
311/** @}
312*/
313
314// -----------------------------------------------------------------------
315
316//
317// Ids for sub-controls
318// NB: It should not matter what these are.
319#define wxPG_SUBID1 2
320#define wxPG_SUBID2 3
321#define wxPG_SUBID_TEMP1 4
322
323// -----------------------------------------------------------------------
324
325/** @class wxPGCommonValue
326
327 wxPropertyGrid stores information about common values in these
328 records.
329
330 NB: Common value feature is not complete, and thus not mentioned in
331 documentation.
332*/
333class WXDLLIMPEXP_PROPGRID wxPGCommonValue
334{
335public:
336
337 wxPGCommonValue( const wxString& label, wxPGCellRenderer* renderer )
338 {
339 m_label = label;
340 m_renderer = renderer;
341 renderer->IncRef();
342 }
343 virtual ~wxPGCommonValue()
344 {
345 m_renderer->DecRef();
346 }
347
348 virtual wxString GetEditableText() const { return m_label; }
349 const wxString& GetLabel() const { return m_label; }
350 wxPGCellRenderer* GetRenderer() const { return m_renderer; }
351
352protected:
353 wxString m_label;
354 wxPGCellRenderer* m_renderer;
355};
356
357// -----------------------------------------------------------------------
358
359/** @section propgrid_vfbflags wxPropertyGrid Validation Failure Behavior Flags
360 @{
361*/
362
363enum wxPG_VALIDATION_FAILURE_BEHAVIOR_FLAGS
364{
365
366/** Prevents user from leaving property unless value is valid. If this
367 behavior flag is not used, then value change is instead cancelled.
368*/
369wxPG_VFB_STAY_IN_PROPERTY = 0x01,
370
371/** Calls wxBell() on validation failure.
372*/
373wxPG_VFB_BEEP = 0x02,
374
375/** Cell with invalid value will be marked (with red colour).
376*/
377wxPG_VFB_MARK_CELL = 0x04,
378
379/** Display customizable text message explaining the situation.
380*/
381wxPG_VFB_SHOW_MESSAGE = 0x08,
382
383/** Defaults. */
384wxPG_VFB_DEFAULT = wxPG_VFB_STAY_IN_PROPERTY|wxPG_VFB_BEEP,
385
386/** Only used internally. */
387wxPG_VFB_UNDEFINED = 0x80
388
389};
390
391/** @}
392*/
393
394typedef wxByte wxPGVFBFlags;
395
2a8312bc
JS
396/**
397 wxPGValidationInfo
1c4293cb
VZ
398
399 Used to convey validation information to and from functions that
2a8312bc
JS
400 actually perform validation. Mostly used in custom property
401 classes.
1c4293cb 402*/
47e343c6 403class WXDLLIMPEXP_PROPGRID wxPGValidationInfo
1c4293cb 404{
2a8312bc
JS
405 friend class wxPropertyGrid;
406public:
6b03a638
JS
407 /**
408 @return Returns failure behavior which is a combination of
409 @ref propgrid_vfbflags.
410 */
47e343c6
JS
411 wxPGVFBFlags GetFailureBehavior() const
412 { return m_failureBehavior; }
6b03a638
JS
413
414 /**
415 Returns current failure message.
416 */
417 const wxString& GetFailureMessage() const
418 { return m_failureMessage; }
419
2a8312bc
JS
420 /**
421 Returns reference to pending value.
422 */
423 const wxVariant& GetValue() const
424 {
425 wxASSERT(m_pValue);
426 return *m_pValue;
427 }
428
6b03a638 429 /** Set validation failure behavior
1c4293cb 430
6b03a638
JS
431 @param failureBehavior
432 Mixture of @ref propgrid_vfbflags.
433 */
1c4293cb
VZ
434 void SetFailureBehavior(wxPGVFBFlags failureBehavior)
435 { m_failureBehavior = failureBehavior; }
436
6b03a638
JS
437 /**
438 Set current failure message.
439 */
9891e165
JS
440 void SetFailureMessage(const wxString& message)
441 { m_failureMessage = message; }
2a8312bc
JS
442
443private:
444 /** Value to be validated.
445 */
446 wxVariant* m_pValue;
447
448 /** Message displayed on validation failure.
449 */
450 wxString m_failureMessage;
451
452 /** Validation failure behavior. Use wxPG_VFB_XXX flags.
453 */
454 wxPGVFBFlags m_failureBehavior;
1c4293cb
VZ
455};
456
457// -----------------------------------------------------------------------
458
459/** @section propgrid_pgactions wxPropertyGrid Action Identifiers
460
461 These are used with wxPropertyGrid::AddActionTrigger() and
462 wxPropertyGrid::ClearActionTriggers().
463 @{
464*/
465
466enum wxPG_KEYBOARD_ACTIONS
467{
468 wxPG_ACTION_INVALID = 0,
469 wxPG_ACTION_NEXT_PROPERTY,
470 wxPG_ACTION_PREV_PROPERTY,
471 wxPG_ACTION_EXPAND_PROPERTY,
472 wxPG_ACTION_COLLAPSE_PROPERTY,
473 wxPG_ACTION_CANCEL_EDIT,
23318a53 474 wxPG_ACTION_PRESS_BUTTON, // Causes editor button (if any) to be pressed
1c4293cb
VZ
475 wxPG_ACTION_MAX
476};
23318a53 477
1c4293cb
VZ
478/** @}
479*/
480
481// -----------------------------------------------------------------------
482
483
484// wxPropertyGrid::DoSelectProperty flags (selFlags)
485
486// Focuses to created editor
58935d4a 487#define wxPG_SEL_FOCUS 0x0001
1c4293cb 488// Forces deletion and recreation of editor
58935d4a 489#define wxPG_SEL_FORCE 0x0002
1c4293cb 490// For example, doesn't cause EnsureVisible
58935d4a 491#define wxPG_SEL_NONVISIBLE 0x0004
1c4293cb 492// Do not validate editor's value before selecting
58935d4a 493#define wxPG_SEL_NOVALIDATE 0x0008
1c4293cb 494// Property being deselected is about to be deleted
58935d4a 495#define wxPG_SEL_DELETING 0x0010
1c4293cb 496// Property's values was set to unspecified by the user
58935d4a 497#define wxPG_SEL_SETUNSPEC 0x0020
1c4293cb 498// Property's event handler changed the value
58935d4a 499#define wxPG_SEL_DIALOGVAL 0x0040
01b5ad3b 500// Set to disable sending of wxEVT_PG_SELECTED event
58935d4a
JS
501#define wxPG_SEL_DONT_SEND_EVENT 0x0080
502// Don't make any graphics updates
503#define wxPG_SEL_NO_REFRESH 0x0100
1c4293cb
VZ
504
505// -----------------------------------------------------------------------
506
507#ifndef SWIG
508
509// Internal flags
510#define wxPG_FL_INITIALIZED 0x0001
511// Set when creating editor controls if it was clicked on.
512#define wxPG_FL_ACTIVATION_BY_CLICK 0x0002
513#define wxPG_FL_DONT_CENTER_SPLITTER 0x0004
514#define wxPG_FL_FOCUSED 0x0008
515#define wxPG_FL_MOUSE_CAPTURED 0x0010
516#define wxPG_FL_MOUSE_INSIDE 0x0020
517#define wxPG_FL_VALUE_MODIFIED 0x0040
518// don't clear background of m_wndEditor
519#define wxPG_FL_PRIMARY_FILLS_ENTIRE 0x0080
520// currently active editor uses custom image
521#define wxPG_FL_CUR_USES_CUSTOM_IMAGE 0x0100
522// cell colours override selection colours for selected cell
523#define wxPG_FL_CELL_OVERRIDES_SEL 0x0200
524#define wxPG_FL_SCROLLED 0x0400
525// set when all added/inserted properties get hideable flag
526#define wxPG_FL_ADDING_HIDEABLES 0x0800
527// Disables showing help strings on statusbar.
528#define wxPG_FL_NOSTATUSBARHELP 0x1000
529// Marks that we created the state, so we have to destroy it too.
530#define wxPG_FL_CREATEDSTATE 0x2000
531// Set if scrollbar's existence was detected in last onresize.
532#define wxPG_FL_SCROLLBAR_DETECTED 0x4000
533// Set if wxPGMan requires redrawing of description text box.
534#define wxPG_FL_DESC_REFRESH_REQUIRED 0x8000
535// Set if contained in wxPropertyGridManager
536#define wxPG_FL_IN_MANAGER 0x00020000
537// Set after wxPropertyGrid is shown in its initial good size
538#define wxPG_FL_GOOD_SIZE_SET 0x00040000
1c4293cb
VZ
539// Set when in SelectProperty.
540#define wxPG_FL_IN_SELECT_PROPERTY 0x00100000
541// Set when help string is shown in status bar
542#define wxPG_FL_STRING_IN_STATUSBAR 0x00200000
543// Splitter position has been custom-set by the user
544#define wxPG_FL_SPLITTER_PRE_SET 0x00400000
545// Validation failed. Clear on modify event.
546#define wxPG_FL_VALIDATION_FAILED 0x00800000
9bc11214
JS
547// Auto sort is enabled (for categorized mode)
548#define wxPG_FL_CATMODE_AUTO_SORT 0x01000000
1c4293cb
VZ
549// Set after page has been inserted to manager
550#define wxPG_MAN_FL_PAGE_INSERTED 0x02000000
551// Active editor control is abnormally large
552#define wxPG_FL_ABNORMAL_EDITOR 0x04000000
b0996c3d
JS
553// Recursion guard for HandleCustomEditorEvent
554#define wxPG_FL_IN_HANDLECUSTOMEDITOREVENT 0x08000000
1c4293cb
VZ
555#define wxPG_FL_VALUE_CHANGE_IN_EVENT 0x10000000
556// Editor control width should not change on resize
557#define wxPG_FL_FIXED_WIDTH_EDITOR 0x20000000
558// Width of panel can be different than width of grid
559#define wxPG_FL_HAS_VIRTUAL_WIDTH 0x40000000
560// Prevents RecalculateVirtualSize re-entrancy
561#define wxPG_FL_RECALCULATING_VIRTUAL_SIZE 0x80000000
562
563#endif // #ifndef SWIG
564
565#if !defined(__wxPG_SOURCE_FILE__) && !defined(SWIG)
566 // Reduce compile time, but still include in user app
567 #include "wx/propgrid/props.h"
568#endif
569
570// -----------------------------------------------------------------------
571
572/** @class wxPropertyGrid
573
574 wxPropertyGrid is a specialized grid for editing properties
575 such as strings, numbers, flagsets, fonts, and colours. wxPropertySheet
576 used to do the very same thing, but it hasn't been updated for a while
577 and it is currently deprecated.
578
579 Please note that most member functions are inherited and as such not
580 documented on this page. This means you will probably also want to read
581 wxPropertyGridInterface class reference.
582
583 See also @ref overview_propgrid.
584
585 @section propgrid_window_styles_ Window Styles
586
587 See @ref propgrid_window_styles.
588
589 @section propgrid_event_handling Event Handling
590
591 To process input from a propertygrid control, use these event handler
592 macros to direct input to member functions that take a wxPropertyGridEvent
593 argument.
594
595 @beginEventTable{wxPropertyGridEvent}
596 @event{EVT_PG_SELECTED (id, func)}
01b5ad3b
JS
597 Respond to wxEVT_PG_SELECTED event, generated when a property selection
598 has been changed, either by user action or by indirect program
599 function. For instance, collapsing a parent property programmatically
600 causes any selected child property to become unselected, and may
601 therefore cause this event to be generated.
1c4293cb
VZ
602 @event{EVT_PG_CHANGING(id, func)}
603 Respond to wxEVT_PG_CHANGING event, generated when property value
604 is about to be changed by user. Use wxPropertyGridEvent::GetValue()
605 to take a peek at the pending value, and wxPropertyGridEvent::Veto()
606 to prevent change from taking place, if necessary.
607 @event{EVT_PG_HIGHLIGHTED(id, func)}
608 Respond to wxEVT_PG_HIGHLIGHTED event, which occurs when mouse
609 moves over a property. Event's property is NULL if hovered area does
610 not belong to any property.
611 @event{EVT_PG_RIGHT_CLICK(id, func)}
612 Respond to wxEVT_PG_RIGHT_CLICK event, which occurs when property is
613 clicked on with right mouse button.
614 @event{EVT_PG_DOUBLE_CLICK(id, func)}
615 Respond to wxEVT_PG_DOUBLE_CLICK event, which occurs when property is
616 double-clicked onwith left mouse button.
617 @event{EVT_PG_ITEM_COLLAPSED(id, func)}
618 Respond to wxEVT_PG_ITEM_COLLAPSED event, generated when user collapses
619 a property or category..
620 @event{EVT_PG_ITEM_EXPANDED(id, func)}
621 Respond to wxEVT_PG_ITEM_EXPANDED event, generated when user expands
622 a property or category..
58935d4a
JS
623 @event{EVT_PG_LABEL_EDIT_BEGIN(id, func)}
624 Respond to wxEVT_PG_LABEL_EDIT_BEGIN event, generated when is about to
625 begin editing a property label. You can veto this event to prevent the
626 action.
627 @event{EVT_PG_LABEL_EDIT_ENDING(id, func)}
628 Respond to wxEVT_PG_LABEL_EDIT_ENDING event, generated when is about to
629 end editing of a property label. You can veto this event to prevent the
630 action.
1c4293cb
VZ
631 @endEventTable
632
633 @remarks
634
635 - Use Freeze() and Thaw() respectively to disable and enable drawing. This
636 will also delay sorting etc. miscellaneous calculations to the last
637 possible moment.
638
639 @library{wxpropgrid}
640 @category{propgrid}
641*/
642class WXDLLIMPEXP_PROPGRID
643 wxPropertyGrid : public wxScrolledWindow, public wxPropertyGridInterface
644{
645 friend class wxPropertyGridPageState;
646 friend class wxPropertyGridInterface;
647 friend class wxPropertyGridManager;
648 friend class wxPGCanvas;
649
1c4293cb 650 DECLARE_DYNAMIC_CLASS(wxPropertyGrid)
1c4293cb
VZ
651public:
652
14bac4b5 653#ifndef SWIG
1c4293cb
VZ
654 /**
655 Two step constructor.
656
657 Call Create when this constructor is called to build up the
658 wxPropertyGrid
659 */
660 wxPropertyGrid();
14bac4b5 661#endif
1c4293cb
VZ
662
663 /** The default constructor. The styles to be used are styles valid for
664 the wxWindow and wxScrolledWindow.
23318a53
FM
665
666 @see @link wndflags Additional Window Styles @endlink
1c4293cb
VZ
667 */
668 wxPropertyGrid( wxWindow *parent, wxWindowID id = wxID_ANY,
669 const wxPoint& pos = wxDefaultPosition,
670 const wxSize& size = wxDefaultSize,
671 long style = wxPG_DEFAULT_STYLE,
23318a53 672 const wxString& name = wxPropertyGridNameStr );
1c4293cb
VZ
673
674 /** Destructor */
675 virtual ~wxPropertyGrid();
1c4293cb
VZ
676
677 /** Adds given key combination to trigger given action.
23318a53 678
1c4293cb
VZ
679 @param action
680 Which action to trigger. See @link pgactions List of list of
681 wxPropertyGrid actions@endlink.
682 */
683 void AddActionTrigger( int action, int keycode, int modifiers = 0 );
684
685 /**
686 This static function enables or disables automatic use of
687 wxGetTranslation for following strings: wxEnumProperty list labels,
688 wxFlagsProperty sub-property labels.
689
690 Default is false.
691 */
692 static void AutoGetTranslation( bool enable );
693
694 /**
695 Changes value of a property, as if from an editor.
696
697 Use this instead of SetPropertyValue() if you need the value to run
698 through validation process, and also send the property change event.
699
700 @return
701 Returns true if value was successfully changed.
702 */
703 bool ChangePropertyValue( wxPGPropArg id, wxVariant newValue );
704
705 /**
706 Centers the splitter.
707
708 If argument is true, automatic splitter centering is enabled (only
709 applicapple if style wxPG_SPLITTER_AUTO_CENTER was defined).
710 */
711 void CenterSplitter( bool enable_auto_centering = false );
712
713 /** Deletes all properties.
714 */
715 virtual void Clear();
716
717 /** Clears action triggers for given action.
718 @param action
719 Which action to trigger. See @link pgactions List of list of
720 wxPropertyGrid actions@endlink.
721 */
722 void ClearActionTriggers( int action );
723
724 /** Forces updating the value of property from the editor control.
725
726 Note that wxEVT_PG_CHANGING and wxEVT_PG_CHANGED are dispatched using
727 ProcessEvent, meaning your event handlers will be called immediately.
728
729 @return
730 Returns true if anything was changed.
731 */
732 virtual bool CommitChangesFromEditor( wxUint32 flags = 0 );
733
734 /**
735 Two step creation.
736
737 Whenever the control is created without any parameters, use Create to
738 actually create it. Don't access the control's public methods before
739 this is called @see @link wndflags Additional Window Styles@endlink
740 */
741 bool Create( wxWindow *parent, wxWindowID id = wxID_ANY,
742 const wxPoint& pos = wxDefaultPosition,
743 const wxSize& size = wxDefaultSize,
744 long style = wxPG_DEFAULT_STYLE,
23318a53 745 const wxString& name = wxPropertyGridNameStr );
1c4293cb
VZ
746
747 /**
748 Call when editor widget's contents is modified.
749
750 For example, this is called when changes text in wxTextCtrl (used in
751 wxStringProperty and wxIntProperty).
752
753 @remarks
754 This function should only be called by custom properties.
755
756 @see wxPGProperty::OnEvent()
757 */
758 void EditorsValueWasModified() { m_iFlags |= wxPG_FL_VALUE_MODIFIED; }
759
760 /** Reverse of EditorsValueWasModified().
761
762 @remarks
763 This function should only be called by custom properties.
764 */
765 void EditorsValueWasNotModified()
766 {
767 m_iFlags &= ~(wxPG_FL_VALUE_MODIFIED);
768 }
769
770 /**
771 Enables or disables (shows/hides) categories according to parameter
772 enable.
773 */
774 bool EnableCategories( bool enable );
775
776 /** Scrolls and/or expands items to ensure that the given item is visible.
777 Returns true if something was actually done.
778 */
779 bool EnsureVisible( wxPGPropArg id );
780
781 /**
782 Reduces column sizes to minimum possible that contents are still
783 visibly (naturally some margin space will be applied as well).
784
785 @return
786 Minimum size for the grid to still display everything.
787
788 @remarks
789 Does not work well with wxPG_SPLITTER_AUTO_CENTER window style.
790
791 This function only works properly if grid size prior to call was already
792 fairly large.
793
794 Note that you can also get calculated column widths by calling
795 GetState->GetColumnWidth() immediately after this function returns.
796 */
797 wxSize FitColumns()
798 {
799 wxSize sz = m_pState->DoFitColumns();
800 return sz;
801 }
802
803 /**
804 Returns wxWindow that the properties are painted on, and which should
805 be used as the parent for editor controls.
806 */
807 wxPanel* GetPanel() const
808 {
809 return m_canvas;
810 }
811
812 /** Returns current category caption background colour. */
813 wxColour GetCaptionBackgroundColour() const { return m_colCapBack; }
814
815 wxFont& GetCaptionFont() { return m_captionFont; }
816
817 const wxFont& GetCaptionFont() const { return m_captionFont; }
818
819 /** Returns current category caption text colour. */
820 wxColour GetCaptionForegroundColour() const { return m_colCapFore; }
821
822 /** Returns current cell background colour. */
823 wxColour GetCellBackgroundColour() const { return m_colPropBack; }
824
825 /** Returns current cell text colour when disabled. */
826 wxColour GetCellDisabledTextColour() const { return m_colDisPropFore; }
827
828 /** Returns current cell text colour. */
829 wxColour GetCellTextColour() const { return m_colPropFore; }
830
6b03a638
JS
831 /**
832 Returns number of columns currently on grid.
833 */
68bcfd2c 834 unsigned int GetColumnCount() const
1c4293cb 835 {
68bcfd2c 836 return (unsigned int) m_pState->m_colWidths.size();
1c4293cb
VZ
837 }
838
839 /** Returns colour of empty space below properties. */
840 wxColour GetEmptySpaceColour() const { return m_colEmptySpace; }
841
842 /** Returns height of highest characters of used font. */
843 int GetFontHeight() const { return m_fontHeight; }
844
845 /** Returns pointer to itself. Dummy function that enables same kind
846 of code to use wxPropertyGrid and wxPropertyGridManager.
847 */
848 wxPropertyGrid* GetGrid() { return this; }
849
850 /** Returns rectangle of custom paint image.
851 */
852 wxRect GetImageRect( wxPGProperty* p, int item ) const;
853
854 /** Returns size of the custom paint image in front of property.
855 If no argument is given, returns preferred size.
856 */
857 wxSize GetImageSize( wxPGProperty* p = NULL, int item = -1 ) const;
858
859 //@{
860 /** Returns last item which could be iterated using given flags.
861 @param flags
862 See @ref propgrid_iterator_flags.
863 */
864 wxPGProperty* GetLastItem( int flags = wxPG_ITERATE_DEFAULT )
865 {
866 return m_pState->GetLastItem(flags);
867 }
868
869 const wxPGProperty* GetLastItem( int flags = wxPG_ITERATE_DEFAULT ) const
870 {
871 return m_pState->GetLastItem(flags);
872 }
873 //@}
874
875 /** Returns colour of lines between cells. */
876 wxColour GetLineColour() const { return m_colLine; }
877
878 /** Returns background colour of margin. */
879 wxColour GetMarginColour() const { return m_colMargin; }
880
9b5bafcf
JS
881 /**
882 Returns most up-to-date value of selected property. This will return
883 value different from GetSelectedProperty()->GetValue() only when text
884 editor is activate and string edited by user represents valid,
885 uncommitted property value.
886 */
703ee9f5 887 wxVariant GetUncommittedPropertyValue();
9b5bafcf 888
1c4293cb
VZ
889 /** Returns "root property". It does not have name, etc. and it is not
890 visible. It is only useful for accessing its children.
891 */
892 wxPGProperty* GetRoot() const { return m_pState->m_properties; }
893
894 /** Returns height of a single grid row (in pixels). */
895 int GetRowHeight() const { return m_lineHeight; }
896
897 /** Returns currently selected property. */
6b03a638 898 wxPGProperty* GetSelectedProperty() const { return GetSelection(); }
1c4293cb 899
1c4293cb
VZ
900 /** Returns current selection background colour. */
901 wxColour GetSelectionBackgroundColour() const { return m_colSelBack; }
902
903 /** Returns current selection text colour. */
904 wxColour GetSelectionForegroundColour() const { return m_colSelFore; }
905
906 /** Returns current splitter x position. */
907 int GetSplitterPosition() const
908 { return m_pState->DoGetSplitterPosition(0); }
909
910 /** Returns wxTextCtrl active in currently selected property, if any. Takes
911 into account wxOwnerDrawnComboBox.
912 */
913 wxTextCtrl* GetEditorTextCtrl() const;
914
915 wxPGValidationInfo& GetValidationInfo()
916 {
917 return m_validationInfo;
918 }
919
920 /** Returns current vertical spacing. */
921 int GetVerticalSpacing() const { return (int)m_vspacing; }
922
45843442
JS
923 /**
924 Returns @true if a property editor control has focus.
925 */
926 bool IsEditorFocused() const;
927
1c4293cb
VZ
928 /** Returns true if editor's value was marked modified.
929 */
930 bool IsEditorsValueModified() const
931 { return ( m_iFlags & wxPG_FL_VALUE_MODIFIED ) ? true : false; }
932
e276acb5
JS
933 /**
934 Returns information about arbitrary position in the grid.
1c4293cb 935
e276acb5 936 @param pt
58b6a137
JS
937 Coordinates in the virtual grid space. You may need to use
938 wxScrolledWindow::CalcScrolledPosition() for translating
939 wxPropertyGrid client coordinates into something this member
940 function can use.
1c4293cb
VZ
941 */
942 wxPropertyGridHitTestResult HitTest( const wxPoint& pt ) const;
943
944 /** Returns true if any property has been modified by the user. */
945 bool IsAnyModified() const { return (m_pState->m_anyModified>0); }
946
947 /**
948 Returns true if updating is frozen (ie Freeze() called but not yet
949 Thaw() ).
950 */
951 bool IsFrozen() const { return (m_frozen>0)?true:false; }
952
27c1f235 953 /**
6edd8829
JS
954 It is recommended that you call this function any time your code causes
955 wxPropertyGrid's top-level parent to change. wxPropertyGrid's OnIdle()
956 handler should be able to detect most changes, but it is not perfect.
27c1f235
JS
957
958 @param newTLP
959 New top-level parent that is about to be set. Old top-level parent
960 window should still exist as the current one.
961
962 @remarks This function is automatically called from wxPropertyGrid::
963 Reparent() and wxPropertyGridManager::Reparent(). You only
964 need to use it if you reparent wxPropertyGrid indirectly.
965 */
966 void OnTLPChanging( wxWindow* newTLP );
967
1c4293cb
VZ
968 /** Redraws given property.
969 */
970 virtual void RefreshProperty( wxPGProperty* p );
971
972#ifndef SWIG
973 /** Registers a new editor class.
974 @return
975 Pointer to the editor class instance that should be used.
976 */
977 static wxPGEditor* RegisterEditorClass( wxPGEditor* editor,
b7d19850
JS
978 bool noDefCheck = false )
979 {
980 return DoRegisterEditorClass(editor, wxEmptyString, noDefCheck);
981 }
982
983 static wxPGEditor* DoRegisterEditorClass( wxPGEditor* editorClass,
984 const wxString& editorName,
985 bool noDefCheck = false );
1c4293cb
VZ
986#endif
987
988 /** Resets all colours to the original system values.
989 */
990 void ResetColours();
991
992 /**
993 Selects a property.
994 Editor widget is automatically created, but not focused unless focus is
01b5ad3b
JS
995 true.
996
1c4293cb
VZ
997 @param id
998 Property to select.
01b5ad3b 999
1c4293cb
VZ
1000 @return
1001 True if selection finished successfully. Usually only fails if
1002 current value in editor is not valid.
01b5ad3b
JS
1003
1004 @remarks In wxPropertyGrid 1.4, this member function used to generate
1005 wxEVT_PG_SELECTED. In wxWidgets 2.9 and later, it no longer
1006 does that.
1007
fc72fab6 1008 @remarks This clears any previous selection.
1c4293cb 1009 */
01b5ad3b 1010 bool SelectProperty( wxPGPropArg id, bool focus = false );
1c4293cb 1011
fc72fab6
JS
1012 /**
1013 Set entire new selection from given list of properties.
1014 */
1015 void SetSelection( const wxArrayPGProperty& newSelection )
1016 {
1017 DoSetSelection( newSelection, wxPG_SEL_DONT_SEND_EVENT );
1018 }
1019
1020 /**
1021 Adds given property into selection. If wxPG_EX_MULTIPLE_SELECTION
1022 extra style is not used, then this has same effect as
1023 calling SelectProperty().
1024
1025 @remarks Multiple selection is not supported for categories. This
1026 means that if you have properties selected, you cannot
1027 add category to selection, and also if you have category
1028 selected, you cannot add other properties to selection.
1029 This member function will fail silently in these cases,
1030 even returning true.
1031 */
1032 bool AddToSelection( wxPGPropArg id )
1033 {
1034 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1035 return DoAddToSelection(p, wxPG_SEL_DONT_SEND_EVENT);
1036 }
1037
1038 /**
1039 Removes given property from selection. If property is not selected,
1040 an assertion failure will occur.
1041 */
1042 bool RemoveFromSelection( wxPGPropArg id )
1043 {
1044 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1045 return DoRemoveFromSelection(p, wxPG_SEL_DONT_SEND_EVENT);
1046 }
1047
58935d4a
JS
1048 /**
1049 Makes given column editable by user.
1050
e9fb1910
JS
1051 @param editable
1052 Using @false here will disable column from being editable.
58935d4a 1053 */
e9fb1910 1054 void MakeColumnEditable( unsigned int column, bool editable = true );
58935d4a
JS
1055
1056 /**
1057 Creates label editor wxTextCtrl for given column, for property
1058 that is currently selected. When multiple selection is
1059 enabled, this applies to whatever property GetSelection()
1060 returns.
1061
1062 @param colIndex
1063 Which column's label to edit. Note that you should not
1064 use value 1, which is reserved for property value
1065 column.
1066
1067 @see EndLabelEdit(), MakeColumnEditable()
1068 */
1069 void BeginLabelEdit( unsigned int column = 0 )
1070 {
1071 DoBeginLabelEdit(column, wxPG_SEL_DONT_SEND_EVENT);
1072 }
1073
1074 /**
1075 Destroys label editor wxTextCtrl, if any.
1076
1077 @param commit
1078 Use @true (default) to store edited label text in
1079 property cell data.
1080
1081 @see BeginLabelEdit(), MakeColumnEditable()
1082 */
1083 void EndLabelEdit( bool commit = true )
1084 {
1085 DoEndLabelEdit(commit, wxPG_SEL_DONT_SEND_EVENT);
1086 }
1087
1088 /**
1089 Returns currently active label editor, NULL if none.
1090 */
1091 wxTextCtrl* GetLabelEditor() const
1092 {
1093 return m_labelEditor;
1094 }
1095
1c4293cb
VZ
1096 /** Sets category caption background colour. */
1097 void SetCaptionBackgroundColour(const wxColour& col);
1098
1099 /** Sets category caption text colour. */
1100 void SetCaptionTextColour(const wxColour& col);
1101
1102 /** Sets default cell background colour - applies to property cells.
1103 Note that appearance of editor widgets may not be affected.
1104 */
1105 void SetCellBackgroundColour(const wxColour& col);
1106
1107 /** Sets cell text colour for disabled properties.
1108 */
1109 void SetCellDisabledTextColour(const wxColour& col);
1110
1111 /** Sets default cell text colour - applies to property name and value text.
1112 Note that appearance of editor widgets may not be affected.
1113 */
1114 void SetCellTextColour(const wxColour& col);
1115
1116 /** Set number of columns (2 or more).
1117 */
1118 void SetColumnCount( int colCount )
1119 {
1120 m_pState->SetColumnCount(colCount);
1121 Refresh();
1122 }
1123
1124 /**
1125 Sets the 'current' category - Append will add non-category properties
1126 under it.
1127 */
1128 void SetCurrentCategory( wxPGPropArg id )
1129 {
1130 wxPG_PROP_ARG_CALL_PROLOG()
30595b81
JS
1131 wxPropertyCategory* pc = wxDynamicCast(p, wxPropertyCategory);
1132 wxASSERT(pc);
1c4293cb
VZ
1133 m_pState->m_currentCategory = pc;
1134 }
1135
1136 /** Sets colour of empty space below properties. */
1137 void SetEmptySpaceColour(const wxColour& col);
1138
1139 /** Sets colour of lines between cells. */
1140 void SetLineColour(const wxColour& col);
1141
1142 /** Sets background colour of margin. */
1143 void SetMarginColour(const wxColour& col);
1144
1c4293cb
VZ
1145 /**
1146 Sets selection background colour - applies to selected property name
1147 background.
1148 */
1149 void SetSelectionBackgroundColour(const wxColour& col);
1150
1151 /**
1152 Sets selection foreground colour - applies to selected property name
1153 text.
1154 */
1155 void SetSelectionTextColour(const wxColour& col);
1156
1157 /** Sets x coordinate of the splitter.
1158 @remarks
1159 Splitter position cannot exceed grid size, and therefore setting it
1160 during form creation may fail as initial grid size is often smaller
1161 than desired splitter position, especially when sizers are being used.
1162 */
1163 void SetSplitterPosition( int newxpos, int col = 0 )
1164 {
1165 DoSetSplitterPosition_(newxpos, true, col);
1166 m_iFlags |= wxPG_FL_SPLITTER_PRE_SET;
1167 }
1168
43396981
JS
1169 /**
1170 Sets the property sorting function.
1171
1172 @param sortFunction
1173 The sorting function to be used. It should return a value greater
1174 than 0 if position of p1 is after p2. So, for instance, when
1175 comparing property names, you can use following implementation:
1176
1177 @code
1178 int MyPropertySortFunction(wxPropertyGrid* propGrid,
1179 wxPGProperty* p1,
1180 wxPGProperty* p2)
1181 {
1182 return p1->GetBaseName().compare( p2->GetBaseName() );
1183 }
1184 @endcode
1185
1186 @remarks
1187 Default property sort function sorts properties by their labels
1188 (case-insensitively).
1189
1190 @see GetSortFunction, wxPropertyGridInterface::Sort,
1191 wxPropertyGridInterface::SortChildren
1192 */
1193 void SetSortFunction( wxPGSortCallback sortFunction )
1194 {
1195 m_sortFunction = sortFunction;
1196 }
1197
1198 /**
1199 Returns the property sort function (default is @NULL).
1200
1201 @see SetSortFunction
1202 */
1203 wxPGSortCallback GetSortFunction() const
1204 {
1205 return m_sortFunction;
1206 }
1207
1c4293cb
VZ
1208 /** Set virtual width for this particular page. Width -1 indicates that the
1209 virtual width should be disabled. */
1210 void SetVirtualWidth( int width );
1211
6b03a638
JS
1212 /**
1213 Moves splitter as left as possible, while still allowing all
1c4293cb 1214 labels to be shown in full.
6b03a638
JS
1215
1216 @param privateChildrenToo
1217 If @false, will still allow private children to be cropped.
1c4293cb 1218 */
6b03a638 1219 void SetSplitterLeft( bool privateChildrenToo = false )
1c4293cb 1220 {
6b03a638 1221 m_pState->SetSplitterLeft(privateChildrenToo);
1c4293cb
VZ
1222 }
1223
1224 /** Sets vertical spacing. Can be 1, 2, or 3 - a value relative to font
1225 height. Value of 2 should be default on most platforms.
1c4293cb
VZ
1226 */
1227 void SetVerticalSpacing( int vspacing )
1228 {
1229 m_vspacing = (unsigned char)vspacing;
1230 CalculateFontAndBitmapStuff( vspacing );
1231 if ( !m_pState->m_itemsAdded ) Refresh();
1232 }
1233
1234 /** Shows an brief error message that is related to a property. */
1235 void ShowPropertyError( wxPGPropArg id, const wxString& msg )
1236 {
1237 wxPG_PROP_ARG_CALL_PROLOG()
1238 DoShowPropertyError(p, msg);
1239 }
1240
1c4293cb
VZ
1241 /////////////////////////////////////////////////////////////////
1242 //
1243 // Following methods do not need to be (currently) documented
1244 //
1245 /////////////////////////////////////////////////////////////////
1246
1247 bool HasVirtualWidth() const
1248 { return (m_iFlags & wxPG_FL_HAS_VIRTUAL_WIDTH) ? true : false; }
1249
1250 const wxPGCommonValue* GetCommonValue( unsigned int i ) const
1251 {
1252 return (wxPGCommonValue*) m_commonValues[i];
1253 }
1254
1255 /** Returns number of common values.
1256 */
1257 unsigned int GetCommonValueCount() const
1258 {
68bcfd2c 1259 return (unsigned int) m_commonValues.size();
1c4293cb
VZ
1260 }
1261
1262 /** Returns label of given common value.
1263 */
1264 wxString GetCommonValueLabel( unsigned int i ) const
1265 {
1266 wxASSERT( GetCommonValue(i) );
1267 return GetCommonValue(i)->GetLabel();
1268 }
1269
1270 /**
1271 Returns index of common value that will truly change value to
1272 unspecified.
1273 */
1274 int GetUnspecifiedCommonValue() const { return m_cvUnspecified; }
1275
1276 /** Set index of common value that will truly change value to unspecified.
1277 Using -1 will set none to have such effect.
1278 Default is 0.
1279 */
1280 void SetUnspecifiedCommonValue( int index ) { m_cvUnspecified = index; }
1281
1282 /**
1283 Shortcut for creating dialog-caller button. Used, for example, by
1284 wxFontProperty.
1285 @remarks
1286 This should only be called by properties.
1287 */
1288 wxWindow* GenerateEditorButton( const wxPoint& pos, const wxSize& sz );
1289
1290 /** Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1291 fits as one). Call after control has been created (but before
1292 shown).
1293 */
1294 void FixPosForTextCtrl( wxWindow* ctrl,
58935d4a 1295 unsigned int forColumn = 1,
1c4293cb
VZ
1296 const wxPoint& offset = wxPoint(0, 0) );
1297
1298 /** Shortcut for creating text editor widget.
1299 @param pos
1300 Same as pos given for CreateEditor.
1301 @param sz
1302 Same as sz given for CreateEditor.
1303 @param value
1304 Initial text for wxTextCtrl.
1305 @param secondary
1306 If right-side control, such as button, also created, then create it
1307 first and pass it as this parameter.
1308 @param extraStyle
1309 Extra style flags to pass for wxTextCtrl.
1310 @remarks
1311 Note that this should generally be called only by new classes derived
1312 from wxPGProperty.
1313 */
1314 wxWindow* GenerateEditorTextCtrl( const wxPoint& pos,
1315 const wxSize& sz,
1316 const wxString& value,
1317 wxWindow* secondary,
1318 int extraStyle = 0,
58935d4a
JS
1319 int maxLen = 0,
1320 unsigned int forColumn = 1 );
1c4293cb
VZ
1321
1322 /* Generates both textctrl and button.
1323 */
1324 wxWindow* GenerateEditorTextCtrlAndButton( const wxPoint& pos,
1325 const wxSize& sz, wxWindow** psecondary, int limited_editing,
1326 wxPGProperty* property );
1327
1328 /** Generates position for a widget editor dialog box.
1329 @param p
1330 Property for which dialog is positioned.
1331 @param sz
1332 Known or over-approximated size of the dialog.
1333 @return
1334 Position for dialog.
1335 */
1336 wxPoint GetGoodEditorDialogPosition( wxPGProperty* p,
1337 const wxSize& sz );
1338
1339 // Converts escape sequences in src_str to newlines,
1340 // tabs, etc. and copies result to dst_str.
1341 static wxString& ExpandEscapeSequences( wxString& dst_str,
1342 wxString& src_str );
1343
1344 // Converts newlines, tabs, etc. in src_str to escape
1345 // sequences, and copies result to dst_str.
1346 static wxString& CreateEscapeSequences( wxString& dst_str,
1347 wxString& src_str );
1348
1349 /**
1350 Returns rectangle that fully contains properties between and including
1351 p1 and p2.
1352 */
1353 wxRect GetPropertyRect( const wxPGProperty* p1,
1354 const wxPGProperty* p2 ) const;
1355
1356 /** Returns pointer to current active primary editor control (NULL if none).
1c4293cb
VZ
1357 */
1358 wxWindow* GetEditorControl() const;
1359
1c4293cb
VZ
1360 wxWindow* GetPrimaryEditor() const
1361 {
1362 return GetEditorControl();
1363 }
1364
1365 /**
1366 Returns pointer to current active secondary editor control (NULL if
1367 none).
1368 */
1369 wxWindow* GetEditorControlSecondary() const
1370 {
1371 return m_wndEditor2;
1372 }
1373
f521bae6
JS
1374 /**
1375 Refreshes any active editor control.
1376 */
1377 void RefreshEditor();
1378
b0996c3d
JS
1379 // Events from editor controls are forward to this function
1380 void HandleCustomEditorEvent( wxEvent &event );
1381
1c4293cb
VZ
1382#ifndef SWIG
1383
1384 /**
1385 Generates contents for string dst based on the contents of
1386 wxArrayString src.
1387
1388 Format will be "(preDelim)str1(postDelim) (preDelim)str2(postDelim) and
1389 so on. Set flags to 1 inorder to convert backslashes to double-back-
1390 slashes and "(preDelims)"'s to "(preDelims)".
1391 */
1392 static void ArrayStringToString( wxString& dst, const wxArrayString& src,
1393 wxChar preDelim, wxChar postDelim,
1394 int flags );
1395
1396 // Mostly useful for page switching.
1397 void SwitchState( wxPropertyGridPageState* pNewState );
1398
1c4293cb 1399 long GetInternalFlags() const { return m_iFlags; }
2fd4a524
JS
1400 bool HasInternalFlag( long flag ) const
1401 { return (m_iFlags & flag) ? true : false; }
1c4293cb
VZ
1402 void SetInternalFlag( long flag ) { m_iFlags |= flag; }
1403 void ClearInternalFlag( long flag ) { m_iFlags &= ~(flag); }
1404 void IncFrozen() { m_frozen++; }
1405 void DecFrozen() { m_frozen--; }
1406
e9cc4973
JS
1407 void OnComboItemPaint( const wxPGComboBox* pCb,
1408 int item,
1409 wxDC* pDc,
1410 wxRect& rect,
1411 int flags );
1c4293cb 1412
1c4293cb
VZ
1413 /** Standardized double-to-string conversion.
1414 */
1415 static void DoubleToString( wxString& target,
1416 double value,
1417 int precision,
1418 bool removeZeroes,
1419 wxString* precTemplate );
1420
1421 /**
1422 Call this from wxPGProperty::OnEvent() to cause property value to be
1423 changed after the function returns (with true as return value).
1424 ValueChangeInEvent() must be used if you wish the application to be
1425 able to use wxEVT_PG_CHANGING to potentially veto the given value.
1426 */
1427 void ValueChangeInEvent( wxVariant variant )
1428 {
1429 m_changeInEventValue = variant;
1430 m_iFlags |= wxPG_FL_VALUE_CHANGE_IN_EVENT;
1431 }
1432
eddcc4b4
JS
1433 /**
1434 You can use this member function, for instance, to detect in
1435 wxPGProperty::OnEvent() if wxPGProperty::SetValueInEvent() was
1436 already called in wxPGEditor::OnEvent(). It really only detects
1437 if was value was changed using wxPGProperty::SetValueInEvent(), which
1438 is usually used when a 'picker' dialog is displayed. If value was
1439 written by "normal means" in wxPGProperty::StringToValue() or
1440 IntToValue(), then this function will return false (on the other hand,
1441 wxPGProperty::OnEvent() is not even called in those cases).
1442 */
1443 bool WasValueChangedInEvent() const
1444 {
1445 return (m_iFlags & wxPG_FL_VALUE_CHANGE_IN_EVENT) ? true : false;
1446 }
1447
1c4293cb
VZ
1448 /** Returns true if given event is from first of an array of buttons
1449 (as can be in case when wxPGMultiButton is used).
1450 */
1451 bool IsMainButtonEvent( const wxEvent& event )
1452 {
1453 return (event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED)
1454 && (m_wndSecId == event.GetId());
1455 }
1456
1457 /** Pending value is expected to be passed in PerformValidation().
1458 */
1459 virtual bool DoPropertyChanged( wxPGProperty* p,
1460 unsigned int selFlags = 0 );
1461
1c4293cb
VZ
1462 /** Called when validation for given property fails.
1463 @param invalidValue
1464 Value which failed in validation.
1465 @return
1466 Return true if user is allowed to change to another property even
1467 if current has invalid value.
1468 @remarks
1469 To add your own validation failure behavior, override
1470 wxPropertyGrid::DoOnValidationFailure().
1471 */
d8812c6e
JS
1472 bool OnValidationFailure( wxPGProperty* property,
1473 wxVariant& invalidValue );
1c4293cb
VZ
1474
1475 /** Called to indicate property and editor has valid value now.
1476 */
1477 void OnValidationFailureReset( wxPGProperty* property )
1478 {
1479 if ( property && property->HasFlag(wxPG_PROP_INVALID_VALUE) )
1480 {
1481 DoOnValidationFailureReset(property);
1482 property->ClearFlag(wxPG_PROP_INVALID_VALUE);
1483 }
1484 m_validationInfo.m_failureMessage.clear();
1485 }
1486
1487 /** Override in derived class to display error messages in custom manner
1488 (these message usually only result from validation failure).
1489 */
1490 virtual void DoShowPropertyError( wxPGProperty* property,
1491 const wxString& msg );
1492
1493 /** Override to customize property validation failure behavior.
1494 @param invalidValue
1495 Value which failed in validation.
1496 @return
1497 Return true if user is allowed to change to another property even
1498 if current has invalid value.
1499 */
1500 virtual bool DoOnValidationFailure( wxPGProperty* property,
1501 wxVariant& invalidValue );
1502
1503 /** Override to customize resetting of property validation failure status.
1504 @remarks
1505 Property is guaranteed to have flag wxPG_PROP_INVALID_VALUE set.
1506 */
1507 virtual void DoOnValidationFailureReset( wxPGProperty* property );
1508
1509 int GetSpacingY() const { return m_spacingy; }
1510
1511 /**
1512 Must be called in wxPGEditor::CreateControls() if primary editor window
1513 is wxTextCtrl, just before textctrl is created.
1514 @param text
1515 Initial text value of created wxTextCtrl.
1516 */
1517 void SetupTextCtrlValue( const wxString text ) { m_prevTcValue = text; }
1518
1519 /**
1520 Unfocuses or closes editor if one was open, but does not deselect
1521 property.
1522 */
1523 bool UnfocusEditor();
1524
470f357f
PC
1525 virtual void SetWindowStyleFlag( long style );
1526
e777bd14
JS
1527 void DrawItems( const wxPGProperty* p1, const wxPGProperty* p2 );
1528
1529 void DrawItem( wxPGProperty* p )
1530 {
1531 DrawItems(p,p);
1532 }
1533
1534 virtual void DrawItemAndChildren( wxPGProperty* p );
1535
1536 /**
1537 Draws item, children, and consequtive parents as long as category is
1538 not met.
1539 */
1540 void DrawItemAndValueRelated( wxPGProperty* p );
1541
1c4293cb
VZ
1542protected:
1543
1544 /**
1545 wxPropertyGridPageState used by the grid is created here.
1546
1547 If grid is used in wxPropertyGridManager, there is no point overriding
1548 this - instead, set custom wxPropertyGridPage classes.
1549 */
1550 virtual wxPropertyGridPageState* CreateState() const;
1551
9b5bafcf
JS
1552 enum PerformValidationFlags
1553 {
1554 SendEvtChanging = 0x0001,
1555 IsStandaloneValidation = 0x0002 // Not called in response to event
1556 };
1557
1558 /**
1559 Runs all validation functionality (includes sending wxEVT_PG_CHANGING).
1560 Returns true if all tests passed. Implement in derived class to
1561 add additional validation behavior.
1562 */
1563 virtual bool PerformValidation( wxPGProperty* p,
1564 wxVariant& pendingValue,
1565 int flags = SendEvtChanging );
1566
1c4293cb
VZ
1567public:
1568
1569 // Control font changer helper.
1570 void SetCurControlBoldFont();
1571
d7e2b522
JS
1572 wxPGCell& GetPropertyDefaultCell()
1573 {
1574 return m_propertyDefaultCell;
1575 }
1576
1577 wxPGCell& GetCategoryDefaultCell()
1578 {
1579 return m_categoryDefaultCell;
1580 }
1581
1c4293cb
VZ
1582 //
1583 // Public methods for semi-public use
1c4293cb
VZ
1584 //
1585 bool DoSelectProperty( wxPGProperty* p, unsigned int flags = 0 );
1586
1587 // Overridden functions.
1588 virtual bool Destroy();
1c4293cb
VZ
1589 // Returns property at given y coordinate (relative to grid's top left).
1590 wxPGProperty* GetItemAtY( int y ) const { return DoGetItemAtY(y); }
1591
1592 virtual void Refresh( bool eraseBackground = true,
1593 const wxRect *rect = (const wxRect *) NULL );
1594 virtual bool SetFont( const wxFont& font );
1595#if wxPG_SUPPORT_TOOLTIPS
1596 void SetToolTip( const wxString& tipString );
1597#endif
1598 virtual void Freeze();
1599 virtual void SetExtraStyle( long exStyle );
1600 virtual void Thaw();
27c1f235 1601 virtual bool Reparent( wxWindowBase *newParent );
1c4293cb
VZ
1602
1603protected:
470f357f 1604 virtual wxSize DoGetBestSize() const;
1c4293cb
VZ
1605
1606#ifndef wxPG_ICON_WIDTH
1607 wxBitmap *m_expandbmp, *m_collbmp;
1608#endif
1609
1610 wxCursor *m_cursorSizeWE;
1611
1612 /** wxWindow pointers to editor control(s). */
1613 wxWindow *m_wndEditor;
1614 wxWindow *m_wndEditor2;
1615
1616 /** wxPGCanvas instance. */
1617 wxPanel *m_canvas;
1618
1619#if wxPG_DOUBLE_BUFFER
1620 wxBitmap *m_doubleBuffer;
1621#endif
1622
1c4293cb
VZ
1623 /** Local time ms when control was created. */
1624 wxLongLong m_timeCreated;
1625
1626 /** wxPGProperty::OnEvent can change value by setting this. */
1627 wxVariant m_changeInEventValue;
1628
1629 /** Id of m_wndEditor2, or its first child, if any. */
1630 int m_wndSecId;
1631
1632 /** Extra Y spacing between the items. */
1633 int m_spacingy;
1634
1635 /** Control client area width; updated on resize. */
1636 int m_width;
1637
1638 /** Control client area height; updated on resize. */
1639 int m_height;
1640
1641 /** Current non-client width (needed when auto-centering). */
1642 int m_ncWidth;
1643
1644 /** Non-client width (auto-centering helper). */
1645 //int m_fWidth;
1646
1647 /** Previously recorded scroll start position. */
1648 int m_prevVY;
1649
1650 /**
1651 The gutter spacing in front and back of the image.
1652 This determines the amount of spacing in front of each item
1653 */
1654 int m_gutterWidth;
1655
1656 /** Includes separator line. */
1657 int m_lineHeight;
1658
1659 /** Gutter*2 + image width. */
1660 int m_marginWidth;
1661
1662 // y spacing for expand/collapse button.
1663 int m_buttonSpacingY;
1664
1665 /** Extra margin for expanded sub-group items. */
1666 int m_subgroup_extramargin;
1667
1668 /**
1669 The image width of the [+] icon.
1670
1671 This is also calculated in the gutter
1672 */
1673 int m_iconWidth;
1674
1675#ifndef wxPG_ICON_WIDTH
1676
1677 /**
1678 The image height of the [+] icon.
1679
1680 This is calculated as minimal size and to align
1681 */
1682 int m_iconHeight;
1683#endif
1684
1685 /** Current cursor id. */
1686 int m_curcursor;
1687
1688 /**
1689 This captionFont is made equal to the font of the wxScrolledWindow.
1690
1691 As extra the bold face is set on it when this is wanted by the user
1692 (see flags)
1693 */
1694 wxFont m_captionFont;
1695
1696 int m_fontHeight; // Height of the font.
1697
1c4293cb
VZ
1698 /** m_splitterx when drag began. */
1699 int m_startingSplitterX;
1700
1701 /**
1702 Index to splitter currently being dragged (0=one after the first
1703 column).
1704 */
1705 int m_draggedSplitter;
1706
1707 /** Changed property, calculated in PerformValidation(). */
1708 wxPGProperty* m_chgInfo_changedProperty;
1709
1710 /**
1711 Lowest property for which editing happened, but which does not have
1712 aggregate parent
1713 */
1714 wxPGProperty* m_chgInfo_baseChangedProperty;
1715
1716 /** Changed property value, calculated in PerformValidation(). */
1717 wxVariant m_chgInfo_pendingValue;
1718
1719 /** Passed to SetValue. */
1720 wxVariant m_chgInfo_valueList;
1721
1722 /** Validation information. */
1723 wxPGValidationInfo m_validationInfo;
1724
1725 /** Actions and keys that trigger them. */
1726 wxPGHashMapI2I m_actionTriggers;
1727
1728 //
1729 // Temporary values
1730 //
1731
1732 /** Bits are used to indicate which colours are customized. */
1733 unsigned short m_coloursCustomized;
1734
1735 /** x - m_splitterx. */
1736 signed char m_dragOffset;
1737
1738 /** 0 = not dragging, 1 = drag just started, 2 = drag in progress */
1739 unsigned char m_dragStatus;
1740
1741 /** 0 = margin, 1 = label, 2 = value. */
1742 unsigned char m_mouseSide;
1743
1744 /** True when editor control is focused. */
1745 unsigned char m_editorFocused;
1746
1747 /** 1 if m_latsCaption is also the bottommost caption. */
1748 //unsigned char m_lastCaptionBottomnest;
1749
1750 /** Set to 1 when graphics frozen. */
1751 unsigned char m_frozen;
1752
1753 unsigned char m_vspacing;
1754
1c4293cb
VZ
1755 // Used to track when Alt/Ctrl+Key was consumed.
1756 unsigned char m_keyComboConsumed;
1757
1758 /** 1 if in DoPropertyChanged() */
1759 unsigned char m_inDoPropertyChanged;
1760
1761 /** 1 if in CommitChangesFromEditor() */
1762 unsigned char m_inCommitChangesFromEditor;
1763
1764 /** 1 if in DoSelectProperty() */
1765 unsigned char m_inDoSelectProperty;
1766
1767 wxPGVFBFlags m_permanentValidationFailureBehavior; // Set by app
1768
1769 /** Internal flags - see wxPG_FL_XXX constants. */
1770 wxUint32 m_iFlags;
1771
1772 /** When drawing next time, clear this many item slots at the end. */
1773 int m_clearThisMany;
1774
58935d4a
JS
1775 // Mouse is hovering over this column (index)
1776 unsigned int m_colHover;
1777
1c4293cb
VZ
1778 // pointer to property that has mouse hovering
1779 wxPGProperty* m_propHover;
1780
58935d4a
JS
1781 // Active label editor
1782 wxTextCtrl* m_labelEditor;
1783
1784 // For which property the label editor is active
1785 wxPGProperty* m_labelEditorProperty;
1786
1c4293cb
VZ
1787 // EventObject for wxPropertyGridEvents
1788 wxWindow* m_eventObject;
1789
1790 // What (global) window is currently focused (needed to resolve event
1791 // handling mess).
1792 wxWindow* m_curFocused;
1793
e84e5ba3
JS
1794 // Event currently being sent - NULL if none at the moment
1795 wxPropertyGridEvent* m_processedEvent;
1796
27c1f235 1797 // Last known top-level parent
1c4293cb
VZ
1798 wxWindow* m_tlp;
1799
6edd8829
JS
1800 // Last closed top-level parent
1801 wxWindow* m_tlpClosed;
1802
1803 // Local time ms when tlp was closed.
1804 wxLongLong m_tlpClosedTime;
1805
43396981
JS
1806 // Sort function
1807 wxPGSortCallback m_sortFunction;
1808
1c4293cb
VZ
1809 // y coordinate of property that mouse hovering
1810 int m_propHoverY;
58935d4a 1811
1c4293cb 1812 // Which column's editor is selected (usually 1)?
58935d4a 1813 unsigned int m_selColumn;
1c4293cb
VZ
1814
1815 // x relative to splitter (needed for resize).
1816 int m_ctrlXAdjust;
1817
1818 // lines between cells
1819 wxColour m_colLine;
1820 // property labels and values are written in this colour
1821 wxColour m_colPropFore;
1822 // or with this colour when disabled
1823 wxColour m_colDisPropFore;
1824 // background for m_colPropFore
1825 wxColour m_colPropBack;
1826 // text color for captions
1827 wxColour m_colCapFore;
1828 // background color for captions
1829 wxColour m_colCapBack;
1830 // foreground for selected property
1831 wxColour m_colSelFore;
1832 // background for selected property (actually use background color when
1833 // control out-of-focus)
1834 wxColour m_colSelBack;
1835 // background colour for margin
1836 wxColour m_colMargin;
1837 // background colour for empty space below the grid
1838 wxColour m_colEmptySpace;
1839
d7e2b522
JS
1840 // Default property colours
1841 wxPGCell m_propertyDefaultCell;
1842
1843 // Default property category
1844 wxPGCell m_categoryDefaultCell;
1c4293cb 1845
d7e2b522
JS
1846 // Backup of selected property's cells
1847 wxVector<wxPGCell> m_propCellsBackup;
f7a094e1 1848
d7e2b522 1849 // NB: These *cannot* be moved to globals.
1c4293cb
VZ
1850
1851 // labels when properties use common values
f7a094e1
JS
1852 wxVector<wxPGCommonValue*> m_commonValues;
1853
1c4293cb
VZ
1854 // Which cv selection really sets value to unspecified?
1855 int m_cvUnspecified;
1856
1857 // Used to skip excess text editor events
1858 wxString m_prevTcValue;
1859
1860protected:
1861
1862 // Sets some members to defaults (called constructors).
1863 void Init1();
1864
1865 // Initializes some members (called by Create and complex constructor).
1866 void Init2();
1867
1868 void OnPaint(wxPaintEvent &event );
1869
1870 // main event receivers
1871 void OnMouseMove( wxMouseEvent &event );
1872 void OnMouseMoveBottom( wxMouseEvent &event );
1873 void OnMouseClick( wxMouseEvent &event );
1874 void OnMouseRightClick( wxMouseEvent &event );
1875 void OnMouseDoubleClick( wxMouseEvent &event );
1876 void OnMouseUp( wxMouseEvent &event );
1877 void OnKey( wxKeyEvent &event );
1c4293cb
VZ
1878 void OnResize( wxSizeEvent &event );
1879
1880 // event handlers
1881 bool HandleMouseMove( int x, unsigned int y, wxMouseEvent &event );
1882 bool HandleMouseClick( int x, unsigned int y, wxMouseEvent &event );
1883 bool HandleMouseRightClick( int x, unsigned int y, wxMouseEvent &event );
1884 bool HandleMouseDoubleClick( int x, unsigned int y, wxMouseEvent &event );
1885 bool HandleMouseUp( int x, unsigned int y, wxMouseEvent &event );
68f9e025 1886 void HandleKeyEvent( wxKeyEvent &event, bool fromChild );
1c4293cb
VZ
1887
1888 void OnMouseEntry( wxMouseEvent &event );
1889
1890 void OnIdle( wxIdleEvent &event );
1891 void OnFocusEvent( wxFocusEvent &event );
1892 void OnChildFocusEvent( wxChildFocusEvent& event );
1893
1894 bool OnMouseCommon( wxMouseEvent &event, int* px, int *py );
1895 bool OnMouseChildCommon( wxMouseEvent &event, int* px, int *py );
1896
1897 // sub-control event handlers
1898 void OnMouseClickChild( wxMouseEvent &event );
1899 void OnMouseRightClickChild( wxMouseEvent &event );
1900 void OnMouseMoveChild( wxMouseEvent &event );
1901 void OnMouseUpChild( wxMouseEvent &event );
1902 void OnChildKeyDown( wxKeyEvent &event );
1c4293cb
VZ
1903
1904 void OnCaptureChange( wxMouseCaptureChangedEvent &event );
1905
1906 void OnScrollEvent( wxScrollWinEvent &event );
1907
1908 void OnSysColourChanged( wxSysColourChangedEvent &event );
1909
27c1f235
JS
1910 void OnTLPClose( wxCloseEvent& event );
1911
1c4293cb
VZ
1912protected:
1913
fc72fab6 1914 bool AddToSelectionFromInputEvent( wxPGProperty* prop,
58935d4a 1915 unsigned int colIndex,
fc72fab6
JS
1916 wxMouseEvent* event = NULL,
1917 int selFlags = 0 );
1918
1c4293cb
VZ
1919 /**
1920 Adjust the centering of the bitmap icons (collapse / expand) when the
1921 caption font changes.
1922
1923 They need to be centered in the middle of the font, so a bit of deltaY
1924 adjustment is needed. On entry, m_captionFont must be set to window
1925 font. It will be modified properly.
1926 */
1927 void CalculateFontAndBitmapStuff( int vspacing );
1928
1929 wxRect GetEditorWidgetRect( wxPGProperty* p, int column ) const;
1930
1931 void CorrectEditorWidgetSizeX();
1932
1933 /** Called in RecalculateVirtualSize() to reposition control
1934 on virtual height changes.
1935 */
1936 void CorrectEditorWidgetPosY();
1937
1c4293cb 1938 int DoDrawItems( wxDC& dc,
bcf324be 1939 const wxRect* clipRect,
1c4293cb
VZ
1940 bool isBuffered ) const;
1941
1c4293cb
VZ
1942 /** Draws an expand/collapse (ie. +/-) button.
1943 */
1944 virtual void DrawExpanderButton( wxDC& dc, const wxRect& rect,
1945 wxPGProperty* property ) const;
1946
1947 /** Draws items from topitemy to bottomitemy */
1948 void DrawItems( wxDC& dc, unsigned int topitemy, unsigned int bottomitemy,
1949 const wxRect* clip_rect = (const wxRect*) NULL );
1950
1c4293cb
VZ
1951 // Translate wxKeyEvent to wxPG_ACTION_XXX
1952 int KeyEventToActions(wxKeyEvent &event, int* pSecond) const;
1953
1954 int KeyEventToAction(wxKeyEvent &event) const
1955 {
1956 return KeyEventToActions(event, NULL);
1957 }
1958
1959 void ImprovedClientToScreen( int* px, int* py );
1960
1961 // Called by focus event handlers. newFocused is the window that becomes
1962 // focused.
1963 void HandleFocusChange( wxWindow* newFocused );
1964
1965 /** Reloads all non-customized colours from system settings. */
1966 void RegainColours();
1967
1968 bool DoEditorValidate();
1969
58935d4a
JS
1970 // Similar to DoSelectProperty() but also works on columns
1971 // other than 1. Does not active editor if column is not
1972 // editable.
1973 bool DoSelectAndEdit( wxPGProperty* prop,
1974 unsigned int colIndex,
1975 unsigned int selFlags );
1976
fc72fab6
JS
1977 void DoSetSelection( const wxArrayPGProperty& newSelection,
1978 int selFlags = 0 );
1979
1980 bool DoAddToSelection( wxPGProperty* prop,
1981 int selFlags = 0 );
1982
1983 bool DoRemoveFromSelection( wxPGProperty* prop,
1984 int selFlags = 0 );
1985
58935d4a
JS
1986 void DoBeginLabelEdit( unsigned int colIndex, int selFlags = 0 );
1987 void DoEndLabelEdit( bool commit, int selFlags = 0 );
1988 void OnLabelEditorEnterPress( wxCommandEvent& event );
1989 void OnLabelEditorKeyPress( wxKeyEvent& event );
1990
1c4293cb
VZ
1991 wxPGProperty* DoGetItemAtY( int y ) const;
1992
1993 void DoSetSplitterPosition_( int newxpos,
1994 bool refresh = true,
1995 int splitterIndex = 0,
1996 bool allPages = false );
1997
58935d4a 1998 void DestroyEditorWnd( wxWindow* wnd );
1c4293cb
VZ
1999 void FreeEditors();
2000
2001 virtual bool DoExpand( wxPGProperty* p, bool sendEvent = false );
2002
2003 virtual bool DoCollapse( wxPGProperty* p, bool sendEvent = false );
2004
2005 // Returns nearest paint visible property (such that will be painted unless
2006 // window is scrolled or resized). If given property is paint visible, then
2007 // it itself will be returned.
2008 wxPGProperty* GetNearestPaintVisible( wxPGProperty* p ) const;
2009
2010 static void RegisterDefaultEditors();
2011
d9fb481c 2012 // Sets up basic event handling for child control
28fb19ef 2013 void SetupChildEventHandling( wxWindow* wnd );
1c4293cb
VZ
2014
2015 void CustomSetCursor( int type, bool override = false );
2016
1c4293cb
VZ
2017 /**
2018 Repositions scrollbar and underlying panel according to changed virtual
2019 size.
2020 */
2021 void RecalculateVirtualSize( int forceXPos = -1 );
2022
2023 void PrepareAfterItemsAdded();
2024
58935d4a
JS
2025 // Omit the wxPG_SEL_NOVALIDATE flag to allow vetoing the event
2026 bool SendEvent( int eventType, wxPGProperty* p,
1c4293cb 2027 wxVariant* pValue = NULL,
58935d4a
JS
2028 unsigned int selFlags = wxPG_SEL_NOVALIDATE,
2029 unsigned int column = 1 );
1c4293cb 2030
0ca422ef 2031 void SetFocusOnCanvas();
c29e714c 2032
1c4293cb
VZ
2033 bool DoHideProperty( wxPGProperty* p, bool hide, int flags );
2034
2035private:
2036
1766bf34 2037 bool ButtonTriggerKeyTest( int action, wxKeyEvent& event );
1c4293cb 2038
1c4293cb
VZ
2039 DECLARE_EVENT_TABLE()
2040#endif // #ifndef SWIG
2041};
2042
2043// -----------------------------------------------------------------------
2044//
2045// Bunch of inlines that need to resolved after all classes have been defined.
2046//
2047
2048#ifndef SWIG
2049inline bool wxPropertyGridPageState::IsDisplayed() const
2050{
2051 return ( this == m_pPropGrid->GetState() );
2052}
2053
2054inline unsigned int wxPropertyGridPageState::GetActualVirtualHeight() const
2055{
2056 return DoGetRoot()->GetChildrenHeight(GetGrid()->GetRowHeight());
2057}
2058#endif
2059
2060inline int wxPGProperty::GetDisplayedCommonValueCount() const
2061{
2062 if ( HasFlag(wxPG_PROP_USES_COMMON_VALUE) )
2063 {
2064 wxPropertyGrid* pg = GetGrid();
2065 if ( pg )
68bcfd2c 2066 return (int) pg->GetCommonValueCount();
1c4293cb
VZ
2067 }
2068 return 0;
2069}
2070
0ce8e27f
JS
2071inline void wxPGProperty::SetDefaultValue( wxVariant& value )
2072{
2073 SetAttribute(wxPG_ATTR_DEFAULT_VALUE, value);
2074}
2075
1c4293cb
VZ
2076inline void wxPGProperty::SetEditor( const wxString& editorName )
2077{
2078 m_customEditor = wxPropertyGridInterface::GetEditorByName(editorName);
2079}
2080
1c4293cb
VZ
2081inline bool wxPGProperty::Hide( bool hide, int flags )
2082{
2083 return GetGrid()->HideProperty(this, hide, flags);
2084}
2085
2086inline bool wxPGProperty::SetMaxLength( int maxLen )
2087{
2088 return GetGrid()->SetPropertyMaxLength(this,maxLen);
2089}
2090
2091// -----------------------------------------------------------------------
2092
c5bb5453 2093#define wxPG_BASE_EVT_PRE_ID 1775
1c4293cb
VZ
2094
2095#ifndef SWIG
2096
9b11752c
VZ
2097wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_SELECTED, wxPropertyGridEvent );
2098wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_CHANGING, wxPropertyGridEvent );
2099wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_CHANGED, wxPropertyGridEvent );
2100wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_HIGHLIGHTED, wxPropertyGridEvent );
2101wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_RIGHT_CLICK, wxPropertyGridEvent );
2102wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_PAGE_CHANGED, wxPropertyGridEvent );
2103wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_ITEM_COLLAPSED, wxPropertyGridEvent );
2104wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_ITEM_EXPANDED, wxPropertyGridEvent );
2105wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID, wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEvent );
58935d4a
JS
2106wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID,
2107 wxEVT_PG_LABEL_EDIT_BEGIN, wxPropertyGridEvent );
2108wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_PROPGRID,
2109 wxEVT_PG_LABEL_EDIT_ENDING, wxPropertyGridEvent );
1c4293cb 2110
1c4293cb
VZ
2111#else
2112 enum {
2113 wxEVT_PG_SELECTED = wxPG_BASE_EVT_PRE_ID,
2114 wxEVT_PG_CHANGING,
2115 wxEVT_PG_CHANGED,
2116 wxEVT_PG_HIGHLIGHTED,
2117 wxEVT_PG_RIGHT_CLICK,
2118 wxEVT_PG_PAGE_CHANGED,
2119 wxEVT_PG_ITEM_COLLAPSED,
2120 wxEVT_PG_ITEM_EXPANDED,
58935d4a
JS
2121 wxEVT_PG_DOUBLE_CLICK,
2122 wxEVT_PG_LABEL_EDIT_BEGIN,
2123 wxEVT_PG_LABEL_EDIT_ENDING
1c4293cb
VZ
2124 };
2125#endif
2126
2127
2128#define wxPG_BASE_EVT_TYPE wxEVT_PG_SELECTED
2129#define wxPG_MAX_EVT_TYPE (wxPG_BASE_EVT_TYPE+30)
2130
2131
2132#ifndef SWIG
2133typedef void (wxEvtHandler::*wxPropertyGridEventFunction)(wxPropertyGridEvent&);
2134
d3b9f782
VZ
2135#define EVT_PG_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_SELECTED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
2136#define EVT_PG_CHANGING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_CHANGING, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
2137#define EVT_PG_CHANGED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_CHANGED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
2138#define EVT_PG_HIGHLIGHTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_HIGHLIGHTED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
2139#define EVT_PG_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_RIGHT_CLICK, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
2140#define EVT_PG_DOUBLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_DOUBLE_CLICK, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
2141#define EVT_PG_PAGE_CHANGED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_PAGE_CHANGED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
2142#define EVT_PG_ITEM_COLLAPSED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_ITEM_COLLAPSED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
2143#define EVT_PG_ITEM_EXPANDED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_ITEM_EXPANDED, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
58935d4a
JS
2144#define EVT_PG_LABEL_EDIT_BEGIN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_LABEL_EDIT_BEGIN, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
2145#define EVT_PG_LABEL_EDIT_ENDING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PG_LABEL_EDIT_ENDING, id, -1, wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn ), NULL ),
3c778901
VZ
2146
2147#define wxPropertyGridEventHandler(fn) \
2148 wxEVENT_HANDLER_CAST( wxPropertyGridEventFunction, fn )
1c4293cb
VZ
2149
2150#endif
2151
2152
2153/** @class wxPropertyGridEvent
2154
2155 A propertygrid event holds information about events associated with
2156 wxPropertyGrid objects.
2157
2158 @library{wxpropgrid}
2159 @category{propgrid}
2160*/
2161class WXDLLIMPEXP_PROPGRID wxPropertyGridEvent : public wxCommandEvent
2162{
2163public:
2164
2165 /** Constructor. */
2166 wxPropertyGridEvent(wxEventType commandType=0, int id=0);
2167#ifndef SWIG
2168 /** Copy constructor. */
2169 wxPropertyGridEvent(const wxPropertyGridEvent& event);
2170#endif
2171 /** Destructor. */
2172 ~wxPropertyGridEvent();
2173
2174 /** Copyer. */
2175 virtual wxEvent* Clone() const;
2176
58935d4a
JS
2177 /**
2178 Returns the column index associated with this event.
2179 */
2180 unsigned int GetColumn() const
2181 {
2182 return m_column;
2183 }
2184
1c4293cb
VZ
2185 wxPGProperty* GetMainParent() const
2186 {
2187 wxASSERT(m_property);
2188 return m_property->GetMainParent();
2189 }
2190
2191 /** Returns id of associated property. */
2192 wxPGProperty* GetProperty() const
2193 {
2194 return m_property;
2195 }
2196
2197 wxPGValidationInfo& GetValidationInfo()
2198 {
2199 wxASSERT(m_validationInfo);
2200 return *m_validationInfo;
2201 }
2202
1c4293cb
VZ
2203 /** Returns true if you can veto the action that the event is signaling.
2204 */
2205 bool CanVeto() const { return m_canVeto; }
2206
2207 /**
2208 Call this from your event handler to veto action that the event is
2209 signaling.
2210
2211 You can only veto a shutdown if wxPropertyGridEvent::CanVeto returns
2212 true.
2213 @remarks
2214 Currently only wxEVT_PG_CHANGING supports vetoing.
2215 */
2216 void Veto( bool veto = true ) { m_wasVetoed = veto; }
2217
2218 /** Returns value that is about to be set for wxEVT_PG_CHANGING.
2219 */
2220 const wxVariant& GetValue() const
2221 {
2222 wxASSERT_MSG( m_validationInfo,
2223 "Only call GetValue from a handler "
2224 "of event type that supports it" );
2a8312bc 2225 return m_validationInfo->GetValue();
1c4293cb
VZ
2226 }
2227
2228 /**
2229 Set override validation failure behavior.
2230
2231 Only effective if Veto was also called, and only allowed if event type
2232 is wxEVT_PG_CHANGING.
2233 */
2a8312bc 2234 void SetValidationFailureBehavior( wxPGVFBFlags flags )
1c4293cb
VZ
2235 {
2236 wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
2a8312bc 2237 m_validationInfo->SetFailureBehavior( flags );
1c4293cb
VZ
2238 }
2239
2240 /** Sets custom failure message for this time only. Only applies if
2241 wxPG_VFB_SHOW_MESSAGE is set in validation failure flags.
2242 */
2243 void SetValidationFailureMessage( const wxString& message )
2244 {
2245 wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
2a8312bc 2246 m_validationInfo->SetFailureMessage( message );
1c4293cb
VZ
2247 }
2248
2249#ifndef SWIG
2250 wxPGVFBFlags GetValidationFailureBehavior() const
2251 {
2252 wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
2a8312bc 2253 return m_validationInfo->GetFailureBehavior();
1c4293cb
VZ
2254 }
2255
58935d4a
JS
2256 void SetColumn( unsigned int column )
2257 {
2258 m_column = column;
2259 }
2260
1c4293cb
VZ
2261 void SetCanVeto( bool canVeto ) { m_canVeto = canVeto; }
2262 bool WasVetoed() const { return m_wasVetoed; }
2263
2264 /** Changes the associated property. */
2265 void SetProperty( wxPGProperty* p ) { m_property = p; }
2266
2267 void SetPropertyGrid( wxPropertyGrid* pg ) { m_pg = pg; }
2268
2269 void SetupValidationInfo()
2270 {
2271 wxASSERT(m_pg);
2272 wxASSERT( GetEventType() == wxEVT_PG_CHANGING );
2273 m_validationInfo = &m_pg->GetValidationInfo();
2274 }
2275
2276private:
2277 void Init();
2278 DECLARE_DYNAMIC_CLASS(wxPropertyGridEvent)
2279
2280 wxPGProperty* m_property;
2281 wxPropertyGrid* m_pg;
2282 wxPGValidationInfo* m_validationInfo;
2283
58935d4a
JS
2284 unsigned int m_column;
2285
1c4293cb
VZ
2286 bool m_canVeto;
2287 bool m_wasVetoed;
2288
2289#endif
2290};
2291
2292
2293// -----------------------------------------------------------------------
2294
2295/** @class wxPropertyGridPopulator
2296 @ingroup classes
2297 Allows populating wxPropertyGrid from arbitrary text source.
2298*/
2299class WXDLLIMPEXP_PROPGRID wxPropertyGridPopulator
2300{
2301public:
2302 /** Default constructor.
2303 */
2304 wxPropertyGridPopulator();
2305
2306 /** Destructor. */
2307 virtual ~wxPropertyGridPopulator();
2308
2309 void SetState( wxPropertyGridPageState* state );
2310
2311 void SetGrid( wxPropertyGrid* pg );
2312
2313 /** Appends a new property under bottommost parent.
2314 @param propClass
2315 Property class as string.
2316 */
2317 wxPGProperty* Add( const wxString& propClass,
2318 const wxString& propLabel,
2319 const wxString& propName,
2320 const wxString* propValue,
2321 wxPGChoices* pChoices = NULL );
2322
2323 /**
2324 Pushes property to the back of parent array (ie it becomes bottommost
2325 parent), and starts scanning/adding children for it.
2326
2327 When finished, parent array is returned to the original state.
2328 */
2329 void AddChildren( wxPGProperty* property );
2330
2331 /** Adds attribute to the bottommost property.
2332 @param type
2333 Allowed values: "string", (same as string), "int", "bool". Empty string
2334 mean autodetect.
2335 */
2336 bool AddAttribute( const wxString& name,
2337 const wxString& type,
2338 const wxString& value );
2339
2340 /** Called once in AddChildren.
2341 */
2342 virtual void DoScanForChildren() = 0;
2343
2344 /**
2345 Returns id of parent property for which children can currently be
2346 added.
2347 */
2348 wxPGProperty* GetCurParent() const
2349 {
2350 return (wxPGProperty*) m_propHierarchy[m_propHierarchy.size()-1];
2351 }
2352
2353 wxPropertyGridPageState* GetState() { return m_state; }
2354 const wxPropertyGridPageState* GetState() const { return m_state; }
2355
2356 /** Like wxString::ToLong, except allows N% in addition of N.
2357 */
2358 static bool ToLongPCT( const wxString& s, long* pval, long max );
2359
2360 /** Parses strings of format "choice1"[=value1] ... "choiceN"[=valueN] into
2361 wxPGChoices. Registers parsed result using idString (if not empty).
2362 Also, if choices with given id already registered, then don't parse but
2363 return those choices instead.
2364 */
2365 wxPGChoices ParseChoices( const wxString& choicesString,
2366 const wxString& idString );
2367
2368 /** Implement in derived class to do custom process when an error occurs.
2369 Default implementation uses wxLogError.
2370 */
2371 virtual void ProcessError( const wxString& msg );
2372
2373protected:
2374
2375 /** Used property grid. */
2376 wxPropertyGrid* m_pg;
2377
2378 /** Used property grid state. */
2379 wxPropertyGridPageState* m_state;
2380
2381 /** Tree-hierarchy of added properties (that can have children). */
2382 wxArrayPGProperty m_propHierarchy;
2383
2384 /** Hashmap for string-id to wxPGChoicesData mapping. */
2385 wxPGHashMapS2P m_dictIdChoices;
2386};
2387
2388// -----------------------------------------------------------------------
2389
2390//
2391// Undefine macros that are not needed outside propertygrid sources
2392//
2393#ifndef __wxPG_SOURCE_FILE__
2394 #undef wxPG_FL_DESC_REFRESH_REQUIRED
2395 #undef wxPG_FL_SCROLLBAR_DETECTED
2396 #undef wxPG_FL_CREATEDSTATE
2397 #undef wxPG_FL_NOSTATUSBARHELP
2398 #undef wxPG_FL_SCROLLED
2399 #undef wxPG_FL_FOCUS_INSIDE_CHILD
2400 #undef wxPG_FL_FOCUS_INSIDE
2401 #undef wxPG_FL_MOUSE_INSIDE_CHILD
2402 #undef wxPG_FL_CUR_USES_CUSTOM_IMAGE
2403 #undef wxPG_FL_PRIMARY_FILLS_ENTIRE
2404 #undef wxPG_FL_VALUE_MODIFIED
2405 #undef wxPG_FL_MOUSE_INSIDE
2406 #undef wxPG_FL_FOCUSED
2407 #undef wxPG_FL_MOUSE_CAPTURED
2408 #undef wxPG_FL_INITIALIZED
2409 #undef wxPG_FL_ACTIVATION_BY_CLICK
2410 #undef wxPG_FL_DONT_CENTER_SPLITTER
2411 #undef wxPG_SUPPORT_TOOLTIPS
2412 #undef wxPG_DOUBLE_BUFFER
2413 #undef wxPG_ICON_WIDTH
2414 #undef wxPG_USE_RENDERER_NATIVE
2415// Following are needed by the manager headers
2416// #undef const wxString&
2417#endif
2418
1c4293cb
VZ
2419// -----------------------------------------------------------------------
2420
f4bc1aa2
JS
2421#endif
2422
1c4293cb
VZ
2423#endif // _WX_PROPGRID_PROPGRID_H_
2424