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