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