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