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