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