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