]> git.saurik.com Git - wxWidgets.git/blob - src/propgrid/propgrid.cpp
Update editor control font centrally, in wxPropertyGrid::RefreshEditor()
[wxWidgets.git] / src / propgrid / propgrid.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/propgrid.cpp
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 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_PROPGRID
20
21 #ifndef WX_PRECOMP
22 #include "wx/defs.h"
23 #include "wx/object.h"
24 #include "wx/hash.h"
25 #include "wx/string.h"
26 #include "wx/log.h"
27 #include "wx/event.h"
28 #include "wx/window.h"
29 #include "wx/panel.h"
30 #include "wx/dc.h"
31 #include "wx/dcmemory.h"
32 #include "wx/button.h"
33 #include "wx/pen.h"
34 #include "wx/brush.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
43 #include "wx/sizer.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
47 #include "wx/intl.h"
48 #include "wx/frame.h"
49 #endif
50
51
52 // This define is necessary to prevent macro clearing
53 #define __wxPG_SOURCE_FILE__
54
55 #include "wx/propgrid/propgrid.h"
56 #include "wx/propgrid/editors.h"
57
58 #if wxPG_USE_RENDERER_NATIVE
59 #include "wx/renderer.h"
60 #endif
61
62 #include "wx/odcombo.h"
63
64 #include "wx/timer.h"
65 #include "wx/dcbuffer.h"
66 #include "wx/clipbrd.h"
67 #include "wx/dataobj.h"
68
69 #ifdef __WXMSW__
70 #include "wx/msw/private.h"
71 #endif
72
73 // Two pics for the expand / collapse buttons.
74 // Files are not supplied with this project (since it is
75 // recommended to use either custom or native rendering).
76 // If you want them, get wxTreeMultiCtrl by Jorgen Bodde,
77 // and copy xpm files from archive to wxPropertyGrid src directory
78 // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h
79 // and set wxPG_USE_RENDERER_NATIVE to 0).
80 #ifndef wxPG_ICON_WIDTH
81 #if defined(__WXMAC__)
82 #include "mac_collapse.xpm"
83 #include "mac_expand.xpm"
84 #elif defined(__WXGTK__)
85 #include "linux_collapse.xpm"
86 #include "linux_expand.xpm"
87 #else
88 #include "default_collapse.xpm"
89 #include "default_expand.xpm"
90 #endif
91 #endif
92
93
94 //#define wxPG_TEXT_INDENT 4 // For the wxComboControl
95 //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored
96 #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min)
97 #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-]
98 #define wxPG_YSPACING_MIN 1
99 #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value,
100 // but causes normal combobox to spill out under MSW
101
102 //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary
103
104 //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform
105 // Must be larger than largest control border
106 // width * 2.
107
108
109 #define wxPG_DEFAULT_CURSOR wxNullCursor
110
111
112 //#define wxPG_NAT_CHOICE_BORDER_ANY 0
113
114 //#define wxPG_HIDER_BUTTON_HEIGHT 25
115
116 #define wxPG_PIXELS_PER_UNIT m_lineHeight
117
118 #ifdef wxPG_ICON_WIDTH
119 #define m_iconHeight m_iconWidth
120 #endif
121
122 //#define wxPG_TOOLTIP_DELAY 1000
123
124 // -----------------------------------------------------------------------
125
126 #if wxUSE_INTL
127 void wxPropertyGrid::AutoGetTranslation ( bool enable )
128 {
129 wxPGGlobalVars->m_autoGetTranslation = enable;
130 }
131 #else
132 void wxPropertyGrid::AutoGetTranslation ( bool ) { }
133 #endif
134
135 // -----------------------------------------------------------------------
136
137 const char wxPropertyGridNameStr[] = "wxPropertyGrid";
138
139 // -----------------------------------------------------------------------
140 // Statics in one class for easy destruction.
141 // -----------------------------------------------------------------------
142
143 #include "wx/module.h"
144
145 class wxPGGlobalVarsClassManager : public wxModule
146 {
147 DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager)
148 public:
149 wxPGGlobalVarsClassManager() {}
150 virtual bool OnInit() { wxPGGlobalVars = new wxPGGlobalVarsClass(); return true; }
151 virtual void OnExit() { delete wxPGGlobalVars; wxPGGlobalVars = NULL; }
152 };
153
154 IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager, wxModule)
155
156
157 wxPGGlobalVarsClass* wxPGGlobalVars = (wxPGGlobalVarsClass*) NULL;
158
159
160 wxPGGlobalVarsClass::wxPGGlobalVarsClass()
161 {
162 wxPGProperty::sm_wxPG_LABEL = new wxString(wxPG_LABEL_STRING);
163
164 m_boolChoices.Add(_("False"));
165 m_boolChoices.Add(_("True"));
166
167 m_fontFamilyChoices = (wxPGChoices*) NULL;
168
169 m_defaultRenderer = new wxPGDefaultRenderer();
170
171 m_autoGetTranslation = false;
172
173 m_offline = 0;
174
175 m_extraStyle = 0;
176
177 wxVariant v;
178
179 // Prepare some shared variants
180 m_vEmptyString = wxString();
181 m_vZero = (long) 0;
182 m_vMinusOne = (long) -1;
183 m_vTrue = true;
184 m_vFalse = false;
185
186 // Prepare cached string constants
187 m_strstring = wxS("string");
188 m_strlong = wxS("long");
189 m_strbool = wxS("bool");
190 m_strlist = wxS("list");
191 m_strMin = wxS("Min");
192 m_strMax = wxS("Max");
193 m_strUnits = wxS("Units");
194 m_strInlineHelp = wxS("InlineHelp");
195
196 #ifdef __WXDEBUG__
197 m_warnings = 0;
198 #endif
199 }
200
201
202 wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
203 {
204 size_t i;
205
206 delete m_defaultRenderer;
207
208 // This will always have one ref
209 delete m_fontFamilyChoices;
210
211 #if wxUSE_VALIDATORS
212 for ( i=0; i<m_arrValidators.size(); i++ )
213 delete ((wxValidator*)m_arrValidators[i]);
214 #endif
215
216 //
217 // Destroy value type class instances.
218 wxPGHashMapS2P::iterator vt_it;
219
220 // Destroy editor class instances.
221 // iterate over all the elements in the class
222 for( vt_it = m_mapEditorClasses.begin(); vt_it != m_mapEditorClasses.end(); ++vt_it )
223 {
224 delete ((wxPGEditor*)vt_it->second);
225 }
226
227 delete wxPGProperty::sm_wxPG_LABEL;
228 }
229
230 void wxPropertyGridInitGlobalsIfNeeded()
231 {
232 }
233
234 // -----------------------------------------------------------------------
235 // wxPGTLWHandler
236 // Intercepts Close-events sent to wxPropertyGrid's top-level parent,
237 // and tries to commit property value.
238 // -----------------------------------------------------------------------
239
240 class wxPGTLWHandler : public wxEvtHandler
241 {
242 public:
243
244 wxPGTLWHandler( wxPropertyGrid* pg )
245 : wxEvtHandler()
246 {
247 m_pg = pg;
248 }
249
250 protected:
251
252 void OnClose( wxCloseEvent& event )
253 {
254 // ClearSelection forces value validation/commit.
255 if ( event.CanVeto() && !m_pg->ClearSelection() )
256 {
257 event.Veto();
258 return;
259 }
260
261 event.Skip();
262 }
263
264 private:
265 wxPropertyGrid* m_pg;
266
267 DECLARE_EVENT_TABLE()
268 };
269
270 BEGIN_EVENT_TABLE(wxPGTLWHandler, wxEvtHandler)
271 EVT_CLOSE(wxPGTLWHandler::OnClose)
272 END_EVENT_TABLE()
273
274 // -----------------------------------------------------------------------
275 // wxPGCanvas
276 // -----------------------------------------------------------------------
277
278 //
279 // wxPGCanvas acts as a graphics sub-window of the
280 // wxScrolledWindow that wxPropertyGrid is.
281 //
282 class wxPGCanvas : public wxPanel
283 {
284 public:
285 wxPGCanvas() : wxPanel()
286 {
287 }
288 virtual ~wxPGCanvas() { }
289
290 protected:
291 void OnMouseMove( wxMouseEvent &event )
292 {
293 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
294 pg->OnMouseMove( event );
295 }
296
297 void OnMouseClick( wxMouseEvent &event )
298 {
299 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
300 pg->OnMouseClick( event );
301 }
302
303 void OnMouseUp( wxMouseEvent &event )
304 {
305 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
306 pg->OnMouseUp( event );
307 }
308
309 void OnMouseRightClick( wxMouseEvent &event )
310 {
311 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
312 pg->OnMouseRightClick( event );
313 }
314
315 void OnMouseDoubleClick( wxMouseEvent &event )
316 {
317 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
318 pg->OnMouseDoubleClick( event );
319 }
320
321 void OnKey( wxKeyEvent& event )
322 {
323 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
324 pg->OnKey( event );
325 }
326
327 void OnPaint( wxPaintEvent& event );
328
329 // Always be focussable, even with child windows
330 virtual void SetCanFocus(bool WXUNUSED(canFocus))
331 { wxPanel::SetCanFocus(true); }
332
333
334 private:
335 DECLARE_EVENT_TABLE()
336 DECLARE_ABSTRACT_CLASS(wxPGCanvas)
337 };
338
339
340 IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas,wxPanel)
341
342 BEGIN_EVENT_TABLE(wxPGCanvas, wxPanel)
343 EVT_MOTION(wxPGCanvas::OnMouseMove)
344 EVT_PAINT(wxPGCanvas::OnPaint)
345 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick)
346 EVT_LEFT_UP(wxPGCanvas::OnMouseUp)
347 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick)
348 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick)
349 EVT_KEY_DOWN(wxPGCanvas::OnKey)
350 END_EVENT_TABLE()
351
352
353 void wxPGCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
354 {
355 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
356 wxASSERT( pg->IsKindOf(CLASSINFO(wxPropertyGrid)) );
357
358 wxPaintDC dc(this);
359
360 // Don't paint after destruction has begun
361 if ( !(pg->GetInternalFlags() & wxPG_FL_INITIALIZED) )
362 return;
363
364 // Update everything inside the box
365 wxRect r = GetUpdateRegion().GetBox();
366
367 // Repaint this rectangle
368 pg->DrawItems( dc, r.y, r.y + r.height, &r );
369
370 // We assume that the size set when grid is shown
371 // is what is desired.
372 pg->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET);
373 }
374
375 // -----------------------------------------------------------------------
376 // wxPropertyGrid
377 // -----------------------------------------------------------------------
378
379 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid, wxScrolledWindow)
380
381 BEGIN_EVENT_TABLE(wxPropertyGrid, wxScrolledWindow)
382 EVT_IDLE(wxPropertyGrid::OnIdle)
383 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom)
384 EVT_PAINT(wxPropertyGrid::OnPaint)
385 EVT_SIZE(wxPropertyGrid::OnResize)
386 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry)
387 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry)
388 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange)
389 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent)
390 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent)
391 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent)
392 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent)
393 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged)
394 END_EVENT_TABLE()
395
396
397 // -----------------------------------------------------------------------
398
399 wxPropertyGrid::wxPropertyGrid()
400 : wxScrolledWindow()
401 {
402 Init1();
403 }
404
405 // -----------------------------------------------------------------------
406
407 wxPropertyGrid::wxPropertyGrid( wxWindow *parent,
408 wxWindowID id,
409 const wxPoint& pos,
410 const wxSize& size,
411 long style,
412 const wxString& name )
413 : wxScrolledWindow()
414 {
415 Init1();
416 Create(parent,id,pos,size,style,name);
417 }
418
419 // -----------------------------------------------------------------------
420
421 bool wxPropertyGrid::Create( wxWindow *parent,
422 wxWindowID id,
423 const wxPoint& pos,
424 const wxSize& size,
425 long style,
426 const wxString& name )
427 {
428
429 if ( !(style&wxBORDER_MASK) )
430 style |= wxSIMPLE_BORDER;
431
432 style |= wxVSCROLL;
433
434 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
435 style &= ~(wxTAB_TRAVERSAL);
436 style |= wxWANTS_CHARS;
437
438 wxScrolledWindow::Create(parent,id,pos,size,style,name);
439
440 Init2();
441
442 return true;
443 }
444
445 // -----------------------------------------------------------------------
446
447 //
448 // Initialize values to defaults
449 //
450 void wxPropertyGrid::Init1()
451 {
452 // Register editor classes, if necessary.
453 if ( wxPGGlobalVars->m_mapEditorClasses.empty() )
454 wxPropertyGrid::RegisterDefaultEditors();
455
456 m_iFlags = 0;
457 m_pState = (wxPropertyGridPageState*) NULL;
458 m_wndEditor = m_wndEditor2 = (wxWindow*) NULL;
459 m_selected = (wxPGProperty*) NULL;
460 m_selColumn = -1;
461 m_propHover = (wxPGProperty*) NULL;
462 m_eventObject = this;
463 m_curFocused = (wxWindow*) NULL;
464 m_tlwHandler = NULL;
465 m_inDoPropertyChanged = 0;
466 m_inCommitChangesFromEditor = 0;
467 m_inDoSelectProperty = 0;
468 m_permanentValidationFailureBehavior = wxPG_VFB_DEFAULT;
469 m_dragStatus = 0;
470 m_mouseSide = 16;
471 m_editorFocused = 0;
472
473 // Set default keys
474 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RIGHT );
475 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN );
476 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_LEFT );
477 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP );
478 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY, WXK_RIGHT);
479 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY, WXK_LEFT);
480 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT, WXK_ESCAPE );
481 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON, WXK_DOWN, wxMOD_ALT );
482 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON, WXK_F4 );
483
484 m_coloursCustomized = 0;
485 m_frozen = 0;
486
487 m_canvas = NULL;
488
489 #if wxPG_DOUBLE_BUFFER
490 m_doubleBuffer = (wxBitmap*) NULL;
491 #endif
492
493 #ifndef wxPG_ICON_WIDTH
494 m_expandbmp = NULL;
495 m_collbmp = NULL;
496 m_iconWidth = 11;
497 m_iconHeight = 11;
498 #else
499 m_iconWidth = wxPG_ICON_WIDTH;
500 #endif
501
502 m_prevVY = -1;
503
504 m_gutterWidth = wxPG_GUTTER_MIN;
505 m_subgroup_extramargin = 10;
506
507 m_lineHeight = 0;
508
509 m_width = m_height = 0;
510
511 m_commonValues.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars->m_defaultRenderer) );
512 m_cvUnspecified = 0;
513
514 m_chgInfo_changedProperty = NULL;
515 }
516
517 // -----------------------------------------------------------------------
518
519 //
520 // Initialize after parent etc. set
521 //
522 void wxPropertyGrid::Init2()
523 {
524 wxASSERT( !(m_iFlags & wxPG_FL_INITIALIZED ) );
525
526 #ifdef __WXMAC__
527 // Smaller controls on Mac
528 SetWindowVariant(wxWINDOW_VARIANT_SMALL);
529 #endif
530
531 // Now create state, if one didn't exist already
532 // (wxPropertyGridManager might have created it for us).
533 if ( !m_pState )
534 {
535 m_pState = CreateState();
536 m_pState->m_pPropGrid = this;
537 m_iFlags |= wxPG_FL_CREATEDSTATE;
538 }
539
540 if ( !(m_windowStyle & wxPG_SPLITTER_AUTO_CENTER) )
541 m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER;
542
543 if ( m_windowStyle & wxPG_HIDE_CATEGORIES )
544 {
545 m_pState->InitNonCatMode();
546
547 m_pState->m_properties = m_pState->m_abcArray;
548 }
549
550 GetClientSize(&m_width,&m_height);
551
552 #ifndef wxPG_ICON_WIDTH
553 // create two bitmap nodes for drawing
554 m_expandbmp = new wxBitmap(expand_xpm);
555 m_collbmp = new wxBitmap(collapse_xpm);
556
557 // calculate average font height for bitmap centering
558
559 m_iconWidth = m_expandbmp->GetWidth();
560 m_iconHeight = m_expandbmp->GetHeight();
561 #endif
562
563 m_curcursor = wxCURSOR_ARROW;
564 m_cursorSizeWE = new wxCursor( wxCURSOR_SIZEWE );
565
566 // adjust bitmap icon y position so they are centered
567 m_vspacing = wxPG_DEFAULT_VSPACING;
568
569 if ( !m_font.Ok() )
570 {
571 wxFont useFont = wxScrolledWindow::GetFont();
572 wxScrolledWindow::SetOwnFont( useFont );
573 }
574 else
575 {
576 // This should be otherwise called by SetOwnFont
577 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING );
578 }
579
580 // Allocate cell datas indirectly by calling setter
581 m_propertyDefaultCell.SetBgCol(*wxBLACK);
582 m_categoryDefaultCell.SetBgCol(*wxBLACK);
583
584 RegainColours();
585
586 // This helps with flicker
587 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
588
589 // Hook the TLW
590 wxPGTLWHandler* handler = new wxPGTLWHandler(this);
591 m_tlp = ::wxGetTopLevelParent(this);
592 m_tlwHandler = handler;
593 m_tlp->PushEventHandler(handler);
594
595 // set virtual size to this window size
596 wxSize wndsize = GetSize();
597 SetVirtualSize(wndsize.GetWidth(), wndsize.GetWidth());
598
599 m_timeCreated = ::wxGetLocalTimeMillis();
600
601 m_canvas = new wxPGCanvas();
602 m_canvas->Create(this, 1, wxPoint(0, 0), GetClientSize(),
603 wxWANTS_CHARS | wxCLIP_CHILDREN);
604 m_canvas->SetBackgroundStyle( wxBG_STYLE_CUSTOM );
605
606 m_iFlags |= wxPG_FL_INITIALIZED;
607
608 m_ncWidth = wndsize.GetWidth();
609
610 // Need to call OnResize handler or size given in constructor/Create
611 // will never work.
612 wxSizeEvent sizeEvent(wndsize,0);
613 OnResize(sizeEvent);
614 }
615
616 // -----------------------------------------------------------------------
617
618 wxPropertyGrid::~wxPropertyGrid()
619 {
620 size_t i;
621
622 DoSelectProperty(NULL);
623
624 // This should do prevent things from going too badly wrong
625 m_iFlags &= ~(wxPG_FL_INITIALIZED);
626
627 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
628 m_canvas->ReleaseMouse();
629
630 wxPGTLWHandler* handler = (wxPGTLWHandler*) m_tlwHandler;
631 m_tlp->RemoveEventHandler(handler);
632 delete handler;
633
634 #ifdef __WXDEBUG__
635 if ( IsEditorsValueModified() )
636 ::wxMessageBox(wxS("Most recent change in property editor was lost!!!\n\n(if you don't want this to happen, close your frames and dialogs using Close(false).)"),
637 wxS("wxPropertyGrid Debug Warning") );
638 #endif
639
640 #if wxPG_DOUBLE_BUFFER
641 if ( m_doubleBuffer )
642 delete m_doubleBuffer;
643 #endif
644
645 //m_selected = (wxPGProperty*) NULL;
646
647 if ( m_iFlags & wxPG_FL_CREATEDSTATE )
648 delete m_pState;
649
650 delete m_cursorSizeWE;
651
652 #ifndef wxPG_ICON_WIDTH
653 delete m_expandbmp;
654 delete m_collbmp;
655 #endif
656
657 // Delete common value records
658 for ( i=0; i<m_commonValues.size(); i++ )
659 {
660 delete GetCommonValue(i);
661 }
662 }
663
664 // -----------------------------------------------------------------------
665
666 bool wxPropertyGrid::Destroy()
667 {
668 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
669 m_canvas->ReleaseMouse();
670
671 return wxScrolledWindow::Destroy();
672 }
673
674 // -----------------------------------------------------------------------
675
676 wxPropertyGridPageState* wxPropertyGrid::CreateState() const
677 {
678 return new wxPropertyGridPageState();
679 }
680
681 // -----------------------------------------------------------------------
682 // wxPropertyGrid overridden wxWindow methods
683 // -----------------------------------------------------------------------
684
685 void wxPropertyGrid::SetWindowStyleFlag( long style )
686 {
687 long old_style = m_windowStyle;
688
689 if ( m_iFlags & wxPG_FL_INITIALIZED )
690 {
691 wxASSERT( m_pState );
692
693 if ( !(style & wxPG_HIDE_CATEGORIES) && (old_style & wxPG_HIDE_CATEGORIES) )
694 {
695 // Enable categories
696 EnableCategories( true );
697 }
698 else if ( (style & wxPG_HIDE_CATEGORIES) && !(old_style & wxPG_HIDE_CATEGORIES) )
699 {
700 // Disable categories
701 EnableCategories( false );
702 }
703 if ( !(old_style & wxPG_AUTO_SORT) && (style & wxPG_AUTO_SORT) )
704 {
705 //
706 // Autosort enabled
707 //
708 if ( !m_frozen )
709 PrepareAfterItemsAdded();
710 else
711 m_pState->m_itemsAdded = 1;
712 }
713 #if wxPG_SUPPORT_TOOLTIPS
714 if ( !(old_style & wxPG_TOOLTIPS) && (style & wxPG_TOOLTIPS) )
715 {
716 //
717 // Tooltips enabled
718 //
719 /*
720 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
721 SetToolTip ( tooltip );
722 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
723 */
724 }
725 else if ( (old_style & wxPG_TOOLTIPS) && !(style & wxPG_TOOLTIPS) )
726 {
727 //
728 // Tooltips disabled
729 //
730 m_canvas->SetToolTip( (wxToolTip*) NULL );
731 }
732 #endif
733 }
734
735 wxScrolledWindow::SetWindowStyleFlag ( style );
736
737 if ( m_iFlags & wxPG_FL_INITIALIZED )
738 {
739 if ( (old_style & wxPG_HIDE_MARGIN) != (style & wxPG_HIDE_MARGIN) )
740 {
741 CalculateFontAndBitmapStuff( m_vspacing );
742 Refresh();
743 }
744 }
745 }
746
747 // -----------------------------------------------------------------------
748
749 void wxPropertyGrid::Freeze()
750 {
751 if ( !m_frozen )
752 {
753 wxScrolledWindow::Freeze();
754 }
755 m_frozen++;
756 }
757
758 // -----------------------------------------------------------------------
759
760 void wxPropertyGrid::Thaw()
761 {
762 m_frozen--;
763
764 if ( !m_frozen )
765 {
766 wxScrolledWindow::Thaw();
767 RecalculateVirtualSize();
768 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
769 m_canvas->Refresh();
770 #endif
771
772 // Force property re-selection
773 if ( m_selected )
774 DoSelectProperty(m_selected, wxPG_SEL_FORCE);
775 }
776 }
777
778 // -----------------------------------------------------------------------
779
780 void wxPropertyGrid::SetExtraStyle( long exStyle )
781 {
782 if ( exStyle & wxPG_EX_NATIVE_DOUBLE_BUFFERING )
783 {
784 #if defined(__WXMSW__)
785
786 /*
787 // Don't use WS_EX_COMPOSITED just now.
788 HWND hWnd;
789
790 if ( m_iFlags & wxPG_FL_IN_MANAGER )
791 hWnd = (HWND)GetParent()->GetHWND();
792 else
793 hWnd = (HWND)GetHWND();
794
795 ::SetWindowLong( hWnd, GWL_EXSTYLE,
796 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
797 */
798
799 //#elif defined(__WXGTK20__)
800 #endif
801 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
802 // truly was double-buffered.
803 if ( !this->IsDoubleBuffered() )
804 {
805 exStyle &= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING);
806 }
807 else
808 {
809 #if wxPG_DOUBLE_BUFFER
810 delete m_doubleBuffer;
811 m_doubleBuffer = NULL;
812 #endif
813 }
814 }
815
816 wxScrolledWindow::SetExtraStyle( exStyle );
817
818 if ( exStyle & wxPG_EX_INIT_NOCAT )
819 m_pState->InitNonCatMode();
820
821 if ( exStyle & wxPG_EX_HELP_AS_TOOLTIPS )
822 m_windowStyle |= wxPG_TOOLTIPS;
823
824 // Set global style
825 wxPGGlobalVars->m_extraStyle = exStyle;
826 }
827
828 // -----------------------------------------------------------------------
829
830 // returns the best acceptable minimal size
831 wxSize wxPropertyGrid::DoGetBestSize() const
832 {
833 int hei = 15;
834 if ( m_lineHeight > hei )
835 hei = m_lineHeight;
836 wxSize sz = wxSize( 60, hei+40 );
837
838 CacheBestSize(sz);
839 return sz;
840 }
841
842 // -----------------------------------------------------------------------
843 // wxPropertyGrid Font and Colour Methods
844 // -----------------------------------------------------------------------
845
846 void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing )
847 {
848 int x = 0, y = 0;
849
850 m_captionFont = wxScrolledWindow::GetFont();
851
852 GetTextExtent(wxS("jG"), &x, &y, 0, 0, &m_captionFont);
853 m_subgroup_extramargin = x + (x/2);
854 m_fontHeight = y;
855
856 #if wxPG_USE_RENDERER_NATIVE
857 m_iconWidth = wxPG_ICON_WIDTH;
858 #elif wxPG_ICON_WIDTH
859 // scale icon
860 m_iconWidth = (m_fontHeight * wxPG_ICON_WIDTH) / 13;
861 if ( m_iconWidth < 5 ) m_iconWidth = 5;
862 else if ( !(m_iconWidth & 0x01) ) m_iconWidth++; // must be odd
863
864 #endif
865
866 m_gutterWidth = m_iconWidth / wxPG_GUTTER_DIV;
867 if ( m_gutterWidth < wxPG_GUTTER_MIN )
868 m_gutterWidth = wxPG_GUTTER_MIN;
869
870 int vdiv = 6;
871 if ( vspacing <= 1 ) vdiv = 12;
872 else if ( vspacing >= 3 ) vdiv = 3;
873
874 m_spacingy = m_fontHeight / vdiv;
875 if ( m_spacingy < wxPG_YSPACING_MIN )
876 m_spacingy = wxPG_YSPACING_MIN;
877
878 m_marginWidth = 0;
879 if ( !(m_windowStyle & wxPG_HIDE_MARGIN) )
880 m_marginWidth = m_gutterWidth*2 + m_iconWidth;
881
882 m_captionFont.SetWeight(wxBOLD);
883 GetTextExtent(wxS("jG"), &x, &y, 0, 0, &m_captionFont);
884
885 m_lineHeight = m_fontHeight+(2*m_spacingy)+1;
886
887 // button spacing
888 m_buttonSpacingY = (m_lineHeight - m_iconHeight) / 2;
889 if ( m_buttonSpacingY < 0 ) m_buttonSpacingY = 0;
890
891 if ( m_pState )
892 m_pState->CalculateFontAndBitmapStuff(vspacing);
893
894 if ( m_iFlags & wxPG_FL_INITIALIZED )
895 RecalculateVirtualSize();
896
897 InvalidateBestSize();
898 }
899
900 // -----------------------------------------------------------------------
901
902 void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent &WXUNUSED(event) )
903 {
904 RegainColours();
905 Refresh();
906 }
907
908 // -----------------------------------------------------------------------
909
910 static wxColour wxPGAdjustColour(const wxColour& src, int ra,
911 int ga = 1000, int ba = 1000,
912 bool forceDifferent = false)
913 {
914 if ( ga >= 1000 )
915 ga = ra;
916 if ( ba >= 1000 )
917 ba = ra;
918
919 // Recursion guard (allow 2 max)
920 static int isinside = 0;
921 isinside++;
922 wxCHECK_MSG( isinside < 3,
923 *wxBLACK,
924 wxT("wxPGAdjustColour should not be recursively called more than once") );
925
926 wxColour dst;
927
928 int r = src.Red();
929 int g = src.Green();
930 int b = src.Blue();
931 int r2 = r + ra;
932 if ( r2>255 ) r2 = 255;
933 else if ( r2<0) r2 = 0;
934 int g2 = g + ga;
935 if ( g2>255 ) g2 = 255;
936 else if ( g2<0) g2 = 0;
937 int b2 = b + ba;
938 if ( b2>255 ) b2 = 255;
939 else if ( b2<0) b2 = 0;
940
941 // Make sure they are somewhat different
942 if ( forceDifferent && (abs((r+g+b)-(r2+g2+b2)) < abs(ra/2)) )
943 dst = wxPGAdjustColour(src,-(ra*2));
944 else
945 dst = wxColour(r2,g2,b2);
946
947 // Recursion guard (allow 2 max)
948 isinside--;
949
950 return dst;
951 }
952
953
954 static int wxPGGetColAvg( const wxColour& col )
955 {
956 return (col.Red() + col.Green() + col.Blue()) / 3;
957 }
958
959
960 void wxPropertyGrid::RegainColours()
961 {
962 if ( !(m_coloursCustomized & 0x0002) )
963 {
964 wxColour col = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
965
966 // Make sure colour is dark enough
967 #ifdef __WXGTK__
968 int colDec = wxPGGetColAvg(col) - 230;
969 #else
970 int colDec = wxPGGetColAvg(col) - 200;
971 #endif
972 if ( colDec > 0 )
973 m_colCapBack = wxPGAdjustColour(col,-colDec);
974 else
975 m_colCapBack = col;
976 m_categoryDefaultCell.GetData()->SetBgCol(m_colCapBack);
977 }
978
979 if ( !(m_coloursCustomized & 0x0001) )
980 m_colMargin = m_colCapBack;
981
982 if ( !(m_coloursCustomized & 0x0004) )
983 {
984 #ifdef __WXGTK__
985 int colDec = -90;
986 #else
987 int colDec = -72;
988 #endif
989 wxColour capForeCol = wxPGAdjustColour(m_colCapBack,colDec,5000,5000,true);
990 m_colCapFore = capForeCol;
991 m_categoryDefaultCell.GetData()->SetFgCol(capForeCol);
992 }
993
994 if ( !(m_coloursCustomized & 0x0008) )
995 {
996 wxColour bgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
997 m_colPropBack = bgCol;
998 m_propertyDefaultCell.GetData()->SetBgCol(bgCol);
999 }
1000
1001 if ( !(m_coloursCustomized & 0x0010) )
1002 {
1003 wxColour fgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
1004 m_colPropFore = fgCol;
1005 m_propertyDefaultCell.GetData()->SetFgCol(fgCol);
1006 }
1007
1008 if ( !(m_coloursCustomized & 0x0020) )
1009 m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT );
1010
1011 if ( !(m_coloursCustomized & 0x0040) )
1012 m_colSelFore = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
1013
1014 if ( !(m_coloursCustomized & 0x0080) )
1015 m_colLine = m_colCapBack;
1016
1017 if ( !(m_coloursCustomized & 0x0100) )
1018 m_colDisPropFore = m_colCapFore;
1019
1020 m_colEmptySpace = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
1021 }
1022
1023 // -----------------------------------------------------------------------
1024
1025 void wxPropertyGrid::ResetColours()
1026 {
1027 m_coloursCustomized = 0;
1028
1029 RegainColours();
1030
1031 Refresh();
1032 }
1033
1034 // -----------------------------------------------------------------------
1035
1036 bool wxPropertyGrid::SetFont( const wxFont& font )
1037 {
1038 // Must disable active editor.
1039 ClearSelection(false);
1040
1041 // TODO: Following code is disabled with wxMac because
1042 // it is reported to fail. I (JMS) cannot debug it
1043 // personally right now.
1044 // CS: should be fixed now, leaving old code in just in case, TODO: REMOVE
1045 #if 1 // !defined(__WXMAC__)
1046 bool res = wxScrolledWindow::SetFont( font );
1047 if ( res )
1048 {
1049 CalculateFontAndBitmapStuff( m_vspacing );
1050
1051 if ( m_pState )
1052 m_pState->CalculateFontAndBitmapStuff(m_vspacing);
1053
1054 Refresh();
1055 }
1056
1057 return res;
1058 #else
1059 // ** wxMAC Only **
1060 // TODO: Remove after SetFont crash fixed.
1061 if ( m_iFlags & wxPG_FL_INITIALIZED )
1062 {
1063 wxLogDebug(wxT("WARNING: propGrid.cpp: wxPropertyGrid::SetFont has been disabled on wxMac since there has been crash reported in it. If you are willing to debug the cause, replace line '#if !defined(__WXMAC__)' with line '#if 1' in wxPropertyGrid::SetFont."));
1064 }
1065 return false;
1066 #endif
1067 }
1068
1069 // -----------------------------------------------------------------------
1070
1071 void wxPropertyGrid::SetLineColour( const wxColour& col )
1072 {
1073 m_colLine = col;
1074 m_coloursCustomized |= 0x80;
1075 Refresh();
1076 }
1077
1078 // -----------------------------------------------------------------------
1079
1080 void wxPropertyGrid::SetMarginColour( const wxColour& col )
1081 {
1082 m_colMargin = col;
1083 m_coloursCustomized |= 0x01;
1084 Refresh();
1085 }
1086
1087 // -----------------------------------------------------------------------
1088
1089 void wxPropertyGrid::SetCellBackgroundColour( const wxColour& col )
1090 {
1091 m_colPropBack = col;
1092 m_coloursCustomized |= 0x08;
1093
1094 m_propertyDefaultCell.GetData()->SetBgCol(col);
1095
1096 Refresh();
1097 }
1098
1099 // -----------------------------------------------------------------------
1100
1101 void wxPropertyGrid::SetCellTextColour( const wxColour& col )
1102 {
1103 m_colPropFore = col;
1104 m_coloursCustomized |= 0x10;
1105
1106 m_propertyDefaultCell.GetData()->SetFgCol(col);
1107
1108 Refresh();
1109 }
1110
1111 // -----------------------------------------------------------------------
1112
1113 void wxPropertyGrid::SetEmptySpaceColour( const wxColour& col )
1114 {
1115 m_colEmptySpace = col;
1116
1117 Refresh();
1118 }
1119
1120 // -----------------------------------------------------------------------
1121
1122 void wxPropertyGrid::SetCellDisabledTextColour( const wxColour& col )
1123 {
1124 m_colDisPropFore = col;
1125 m_coloursCustomized |= 0x100;
1126 Refresh();
1127 }
1128
1129 // -----------------------------------------------------------------------
1130
1131 void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour& col )
1132 {
1133 m_colSelBack = col;
1134 m_coloursCustomized |= 0x20;
1135 Refresh();
1136 }
1137
1138 // -----------------------------------------------------------------------
1139
1140 void wxPropertyGrid::SetSelectionTextColour( const wxColour& col )
1141 {
1142 m_colSelFore = col;
1143 m_coloursCustomized |= 0x40;
1144 Refresh();
1145 }
1146
1147 // -----------------------------------------------------------------------
1148
1149 void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour& col )
1150 {
1151 m_colCapBack = col;
1152 m_coloursCustomized |= 0x02;
1153
1154 m_categoryDefaultCell.GetData()->SetBgCol(col);
1155
1156 Refresh();
1157 }
1158
1159 // -----------------------------------------------------------------------
1160
1161 void wxPropertyGrid::SetCaptionTextColour( const wxColour& col )
1162 {
1163 m_colCapFore = col;
1164 m_coloursCustomized |= 0x04;
1165
1166 m_categoryDefaultCell.GetData()->SetFgCol(col);
1167
1168 Refresh();
1169 }
1170
1171 // -----------------------------------------------------------------------
1172 // wxPropertyGrid property adding and removal
1173 // -----------------------------------------------------------------------
1174
1175 void wxPropertyGrid::PrepareAfterItemsAdded()
1176 {
1177 if ( !m_pState || !m_pState->m_itemsAdded ) return;
1178
1179 m_pState->m_itemsAdded = 0;
1180
1181 if ( m_windowStyle & wxPG_AUTO_SORT )
1182 Sort();
1183
1184 RecalculateVirtualSize();
1185 }
1186
1187 // -----------------------------------------------------------------------
1188 // wxPropertyGrid property value setting and getting
1189 // -----------------------------------------------------------------------
1190
1191 void wxPropertyGrid::DoSetPropertyValueUnspecified( wxPGProperty* p )
1192 {
1193 m_pState->DoSetPropertyValueUnspecified(p);
1194 DrawItemAndChildren(p);
1195
1196 wxPGProperty* parent = p->GetParent();
1197 while ( parent &&
1198 (parent->GetFlags() & wxPG_PROP_PARENTAL_FLAGS) == wxPG_PROP_MISC_PARENT )
1199 {
1200 DrawItem(parent);
1201 parent = parent->GetParent();
1202 }
1203 }
1204
1205 // -----------------------------------------------------------------------
1206 // wxPropertyGrid property operations
1207 // -----------------------------------------------------------------------
1208
1209 bool wxPropertyGrid::EnsureVisible( wxPGPropArg id )
1210 {
1211 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1212
1213 Update();
1214
1215 bool changed = false;
1216
1217 // Is it inside collapsed section?
1218 if ( !p->IsVisible() )
1219 {
1220 // expand parents
1221 wxPGProperty* parent = p->GetParent();
1222 wxPGProperty* grandparent = parent->GetParent();
1223
1224 if ( grandparent && grandparent != m_pState->m_properties )
1225 Expand( grandparent );
1226
1227 Expand( parent );
1228 changed = true;
1229 }
1230
1231 // Need to scroll?
1232 int vx, vy;
1233 GetViewStart(&vx,&vy);
1234 vy*=wxPG_PIXELS_PER_UNIT;
1235
1236 int y = p->GetY();
1237
1238 if ( y < vy )
1239 {
1240 Scroll(vx, y/wxPG_PIXELS_PER_UNIT );
1241 m_iFlags |= wxPG_FL_SCROLLED;
1242 changed = true;
1243 }
1244 else if ( (y+m_lineHeight) > (vy+m_height) )
1245 {
1246 Scroll(vx, (y-m_height+(m_lineHeight*2))/wxPG_PIXELS_PER_UNIT );
1247 m_iFlags |= wxPG_FL_SCROLLED;
1248 changed = true;
1249 }
1250
1251 if ( changed )
1252 DrawItems( p, p );
1253
1254 return changed;
1255 }
1256
1257 // -----------------------------------------------------------------------
1258 // wxPropertyGrid helper methods called by properties
1259 // -----------------------------------------------------------------------
1260
1261 // Control font changer helper.
1262 void wxPropertyGrid::SetCurControlBoldFont()
1263 {
1264 wxASSERT( m_wndEditor );
1265 m_wndEditor->SetFont( m_captionFont );
1266 }
1267
1268 // -----------------------------------------------------------------------
1269
1270 wxPoint wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty* p,
1271 const wxSize& sz )
1272 {
1273 #if wxPG_SMALL_SCREEN
1274 // On small-screen devices, always show dialogs with default position and size.
1275 return wxDefaultPosition;
1276 #else
1277 int splitterX = GetSplitterPosition();
1278 int x = splitterX;
1279 int y = p->GetY();
1280
1281 wxCHECK_MSG( y >= 0, wxPoint(-1,-1), wxT("invalid y?") );
1282
1283 ImprovedClientToScreen( &x, &y );
1284
1285 int sw = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X );
1286 int sh = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y );
1287
1288 int new_x;
1289 int new_y;
1290
1291 if ( x > (sw/2) )
1292 // left
1293 new_x = x + (m_width-splitterX) - sz.x;
1294 else
1295 // right
1296 new_x = x;
1297
1298 if ( y > (sh/2) )
1299 // above
1300 new_y = y - sz.y;
1301 else
1302 // below
1303 new_y = y + m_lineHeight;
1304
1305 return wxPoint(new_x,new_y);
1306 #endif
1307 }
1308
1309 // -----------------------------------------------------------------------
1310
1311 wxString& wxPropertyGrid::ExpandEscapeSequences( wxString& dst_str, wxString& src_str )
1312 {
1313 if ( src_str.length() == 0 )
1314 {
1315 dst_str = src_str;
1316 return src_str;
1317 }
1318
1319 bool prev_is_slash = false;
1320
1321 wxString::const_iterator i = src_str.begin();
1322
1323 dst_str.clear();
1324
1325 for ( ; i != src_str.end(); ++i )
1326 {
1327 wxUniChar a = *i;
1328
1329 if ( a != wxS('\\') )
1330 {
1331 if ( !prev_is_slash )
1332 {
1333 dst_str << a;
1334 }
1335 else
1336 {
1337 if ( a == wxS('n') )
1338 {
1339 #ifdef __WXMSW__
1340 dst_str << wxS('\n');
1341 #else
1342 dst_str << wxS('\n');
1343 #endif
1344 }
1345 else if ( a == wxS('t') )
1346 dst_str << wxS('\t');
1347 else
1348 dst_str << a;
1349 }
1350 prev_is_slash = false;
1351 }
1352 else
1353 {
1354 if ( prev_is_slash )
1355 {
1356 dst_str << wxS('\\');
1357 prev_is_slash = false;
1358 }
1359 else
1360 {
1361 prev_is_slash = true;
1362 }
1363 }
1364 }
1365 return dst_str;
1366 }
1367
1368 // -----------------------------------------------------------------------
1369
1370 wxString& wxPropertyGrid::CreateEscapeSequences( wxString& dst_str, wxString& src_str )
1371 {
1372 if ( src_str.length() == 0 )
1373 {
1374 dst_str = src_str;
1375 return src_str;
1376 }
1377
1378 wxString::const_iterator i = src_str.begin();
1379 wxUniChar prev_a = wxS('\0');
1380
1381 dst_str.clear();
1382
1383 for ( ; i != src_str.end(); ++i )
1384 {
1385 wxChar a = *i;
1386
1387 if ( a >= wxS(' ') )
1388 {
1389 // This surely is not something that requires an escape sequence.
1390 dst_str << a;
1391 }
1392 else
1393 {
1394 // This might need...
1395 if ( a == wxS('\r') )
1396 {
1397 // DOS style line end.
1398 // Already taken care below
1399 }
1400 else if ( a == wxS('\n') )
1401 // UNIX style line end.
1402 dst_str << wxS("\\n");
1403 else if ( a == wxS('\t') )
1404 // Tab.
1405 dst_str << wxS('\t');
1406 else
1407 {
1408 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1409 dst_str << a;
1410 }
1411 }
1412
1413 prev_a = a;
1414 }
1415 return dst_str;
1416 }
1417
1418 // -----------------------------------------------------------------------
1419
1420 wxPGProperty* wxPropertyGrid::DoGetItemAtY( int y ) const
1421 {
1422 // Outside?
1423 if ( y < 0 )
1424 return (wxPGProperty*) NULL;
1425
1426 unsigned int a = 0;
1427 return m_pState->m_properties->GetItemAtY(y, m_lineHeight, &a);
1428 }
1429
1430 // -----------------------------------------------------------------------
1431 // wxPropertyGrid graphics related methods
1432 // -----------------------------------------------------------------------
1433
1434 void wxPropertyGrid::OnPaint( wxPaintEvent& WXUNUSED(event) )
1435 {
1436 wxPaintDC dc(this);
1437
1438 // Update everything inside the box
1439 wxRect r = GetUpdateRegion().GetBox();
1440
1441 dc.SetPen(m_colEmptySpace);
1442 dc.SetBrush(m_colEmptySpace);
1443 dc.DrawRectangle(r);
1444 }
1445
1446 // -----------------------------------------------------------------------
1447
1448 void wxPropertyGrid::DrawExpanderButton( wxDC& dc, const wxRect& rect,
1449 wxPGProperty* property ) const
1450 {
1451 // Prepare rectangle to be used
1452 wxRect r(rect);
1453 r.x += m_gutterWidth; r.y += m_buttonSpacingY;
1454 r.width = m_iconWidth; r.height = m_iconHeight;
1455
1456 #if (wxPG_USE_RENDERER_NATIVE)
1457 //
1458 #elif wxPG_ICON_WIDTH
1459 // Drawing expand/collapse button manually
1460 dc.SetPen(m_colPropFore);
1461 if ( property->IsCategory() )
1462 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1463 else
1464 dc.SetBrush(m_colPropBack);
1465
1466 dc.DrawRectangle( r );
1467 int _y = r.y+(m_iconWidth/2);
1468 dc.DrawLine(r.x+2,_y,r.x+m_iconWidth-2,_y);
1469 #else
1470 wxBitmap* bmp;
1471 #endif
1472
1473 if ( property->IsExpanded() )
1474 {
1475 // wxRenderer functions are non-mutating in nature, so it
1476 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1477 // Hopefully this does not cause problems.
1478 #if (wxPG_USE_RENDERER_NATIVE)
1479 wxRendererNative::Get().DrawTreeItemButton(
1480 (wxWindow*)this,
1481 dc,
1482 r,
1483 wxCONTROL_EXPANDED
1484 );
1485 #elif wxPG_ICON_WIDTH
1486 //
1487 #else
1488 bmp = m_collbmp;
1489 #endif
1490
1491 }
1492 else
1493 {
1494 #if (wxPG_USE_RENDERER_NATIVE)
1495 wxRendererNative::Get().DrawTreeItemButton(
1496 (wxWindow*)this,
1497 dc,
1498 r,
1499 0
1500 );
1501 #elif wxPG_ICON_WIDTH
1502 int _x = r.x+(m_iconWidth/2);
1503 dc.DrawLine(_x,r.y+2,_x,r.y+m_iconWidth-2);
1504 #else
1505 bmp = m_expandbmp;
1506 #endif
1507 }
1508
1509 #if (wxPG_USE_RENDERER_NATIVE)
1510 //
1511 #elif wxPG_ICON_WIDTH
1512 //
1513 #else
1514 dc.DrawBitmap( *bmp, r.x, r.y, true );
1515 #endif
1516 }
1517
1518 // -----------------------------------------------------------------------
1519
1520 //
1521 // This is the one called by OnPaint event handler and others.
1522 // topy and bottomy are already unscrolled (ie. physical)
1523 //
1524 void wxPropertyGrid::DrawItems( wxDC& dc,
1525 unsigned int topy,
1526 unsigned int bottomy,
1527 const wxRect* clipRect )
1528 {
1529 if ( m_frozen || m_height < 1 || bottomy < topy || !m_pState ) return;
1530
1531 m_pState->EnsureVirtualHeight();
1532
1533 wxRect tempClipRect;
1534 if ( !clipRect )
1535 {
1536 tempClipRect = wxRect(0,topy,m_pState->m_width,bottomy);
1537 clipRect = &tempClipRect;
1538 }
1539
1540 // items added check
1541 if ( m_pState->m_itemsAdded ) PrepareAfterItemsAdded();
1542
1543 int paintFinishY = 0;
1544
1545 if ( m_pState->m_properties->GetChildCount() > 0 )
1546 {
1547 wxDC* dcPtr = &dc;
1548 bool isBuffered = false;
1549
1550 #if wxPG_DOUBLE_BUFFER
1551 wxMemoryDC* bufferDC = NULL;
1552
1553 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING) )
1554 {
1555 if ( !m_doubleBuffer )
1556 {
1557 paintFinishY = clipRect->y;
1558 dcPtr = NULL;
1559 }
1560 else
1561 {
1562 bufferDC = new wxMemoryDC();
1563
1564 // If nothing was changed, then just copy from double-buffer
1565 bufferDC->SelectObject( *m_doubleBuffer );
1566 dcPtr = bufferDC;
1567
1568 isBuffered = true;
1569 }
1570 }
1571 #endif
1572
1573 if ( dcPtr )
1574 {
1575 dc.SetClippingRegion( *clipRect );
1576 paintFinishY = DoDrawItems( *dcPtr, NULL, NULL, clipRect, isBuffered );
1577 }
1578
1579 #if wxPG_DOUBLE_BUFFER
1580 if ( bufferDC )
1581 {
1582 dc.Blit( clipRect->x, clipRect->y, clipRect->width, clipRect->height,
1583 bufferDC, 0, 0, wxCOPY );
1584 dc.DestroyClippingRegion(); // Is this really necessary?
1585 delete bufferDC;
1586 }
1587 #endif
1588 }
1589
1590 // Clear area beyond bottomY?
1591 if ( paintFinishY < (clipRect->y+clipRect->height) )
1592 {
1593 dc.SetPen(m_colEmptySpace);
1594 dc.SetBrush(m_colEmptySpace);
1595 dc.DrawRectangle( 0, paintFinishY, m_width, (clipRect->y+clipRect->height) );
1596 }
1597 }
1598
1599 // -----------------------------------------------------------------------
1600
1601 int wxPropertyGrid::DoDrawItems( wxDC& dc,
1602 const wxPGProperty* firstItem,
1603 const wxPGProperty* lastItem,
1604 const wxRect* clipRect,
1605 bool isBuffered ) const
1606 {
1607 // TODO: This should somehow be eliminated.
1608 wxRect tempClipRect;
1609 if ( !clipRect )
1610 {
1611 wxASSERT(firstItem);
1612 wxASSERT(lastItem);
1613 tempClipRect = GetPropertyRect(firstItem, lastItem);
1614 clipRect = &tempClipRect;
1615 }
1616
1617 if ( !firstItem )
1618 firstItem = DoGetItemAtY(clipRect->y);
1619
1620 if ( !lastItem )
1621 {
1622 lastItem = DoGetItemAtY(clipRect->y+clipRect->height-1);
1623 if ( !lastItem )
1624 lastItem = GetLastItem( wxPG_ITERATE_VISIBLE );
1625 }
1626
1627 if ( m_frozen || m_height < 1 || firstItem == NULL )
1628 return clipRect->y;
1629
1630 wxCHECK_MSG( !m_pState->m_itemsAdded, clipRect->y, wxT("no items added") );
1631 wxASSERT( m_pState->m_properties->GetChildCount() );
1632
1633 int lh = m_lineHeight;
1634
1635 int firstItemTopY;
1636 int lastItemBottomY;
1637
1638 firstItemTopY = clipRect->y;
1639 lastItemBottomY = clipRect->y + clipRect->height;
1640
1641 // Align y coordinates to item boundaries
1642 firstItemTopY -= firstItemTopY % lh;
1643 lastItemBottomY += lh - (lastItemBottomY % lh);
1644 lastItemBottomY -= 1;
1645
1646 // Entire range outside scrolled, visible area?
1647 if ( firstItemTopY >= (int)m_pState->GetVirtualHeight() || lastItemBottomY <= 0 )
1648 return clipRect->y;
1649
1650 wxCHECK_MSG( firstItemTopY < lastItemBottomY, clipRect->y, wxT("invalid y values") );
1651
1652
1653 /*
1654 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1655 firstItem->GetLabel().c_str(),
1656 lastItem->GetLabel().c_str(),
1657 (int)(lastItemBottomY - firstItemTopY),
1658 (int)m_height,
1659 (unsigned long)clipRect );
1660 */
1661
1662 wxRect r;
1663
1664 long windowStyle = m_windowStyle;
1665
1666 int xRelMod = 0;
1667 int yRelMod = 0;
1668
1669 //
1670 // With wxPG_DOUBLE_BUFFER, do double buffering
1671 // - buffer's y = 0, so align cliprect and coordinates to that
1672 //
1673 #if wxPG_DOUBLE_BUFFER
1674
1675 wxRect cr2;
1676
1677 if ( isBuffered )
1678 {
1679 xRelMod = clipRect->x;
1680 yRelMod = clipRect->y;
1681
1682 //
1683 // clipRect conversion
1684 cr2 = *clipRect;
1685 cr2.x -= xRelMod;
1686 cr2.y -= yRelMod;
1687 clipRect = &cr2;
1688 firstItemTopY -= yRelMod;
1689 lastItemBottomY -= yRelMod;
1690 }
1691 #else
1692 wxUnusedVar(isBuffered);
1693 #endif
1694
1695 int x = m_marginWidth - xRelMod;
1696
1697 const wxFont& normalfont = m_font;
1698
1699 bool reallyFocused = (m_iFlags & wxPG_FL_FOCUSED) != 0;
1700
1701 bool isEnabled = IsEnabled();
1702
1703 //
1704 // Prepare some pens and brushes that are often changed to.
1705 //
1706
1707 wxBrush marginBrush(m_colMargin);
1708 wxPen marginPen(m_colMargin);
1709 wxBrush capbgbrush(m_colCapBack,wxSOLID);
1710 wxPen linepen(m_colLine,1,wxSOLID);
1711
1712 // pen that has same colour as text
1713 wxPen outlinepen(m_colPropFore,1,wxSOLID);
1714
1715 //
1716 // Clear margin with background colour
1717 //
1718 dc.SetBrush( marginBrush );
1719 if ( !(windowStyle & wxPG_HIDE_MARGIN) )
1720 {
1721 dc.SetPen( *wxTRANSPARENT_PEN );
1722 dc.DrawRectangle(-1-xRelMod,firstItemTopY-1,x+2,lastItemBottomY-firstItemTopY+2);
1723 }
1724
1725 const wxPGProperty* selected = m_selected;
1726 const wxPropertyGridPageState* state = m_pState;
1727
1728 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1729 bool wasSelectedPainted = false;
1730 #endif
1731
1732 // TODO: Only render columns that are within clipping region.
1733
1734 dc.SetFont(normalfont);
1735
1736 wxPropertyGridConstIterator it( state, wxPG_ITERATE_VISIBLE, firstItem );
1737 int endScanBottomY = lastItemBottomY + lh;
1738 int y = firstItemTopY;
1739
1740 //
1741 // Pregenerate list of visible properties.
1742 wxArrayPGProperty visPropArray;
1743 visPropArray.reserve((m_height/m_lineHeight)+6);
1744
1745 for ( ; !it.AtEnd(); it.Next() )
1746 {
1747 const wxPGProperty* p = *it;
1748
1749 if ( !p->HasFlag(wxPG_PROP_HIDDEN) )
1750 {
1751 visPropArray.push_back((wxPGProperty*)p);
1752
1753 if ( y > endScanBottomY )
1754 break;
1755
1756 y += lh;
1757 }
1758 }
1759
1760 visPropArray.push_back(NULL);
1761
1762 wxPGProperty* nextP = visPropArray[0];
1763
1764 int gridWidth = state->m_width;
1765
1766 y = firstItemTopY;
1767 for ( unsigned int arrInd=1;
1768 nextP && y <= lastItemBottomY;
1769 arrInd++ )
1770 {
1771 wxPGProperty* p = nextP;
1772 nextP = visPropArray[arrInd];
1773
1774 int rowHeight = m_fontHeight+(m_spacingy*2)+1;
1775 int textMarginHere = x;
1776 int renderFlags = 0;
1777
1778 int greyDepth = m_marginWidth;
1779 if ( !(windowStyle & wxPG_HIDE_CATEGORIES) )
1780 greyDepth = (((int)p->m_depthBgCol)-1) * m_subgroup_extramargin + m_marginWidth;
1781
1782 int greyDepthX = greyDepth - xRelMod;
1783
1784 // Use basic depth if in non-categoric mode and parent is base array.
1785 if ( !(windowStyle & wxPG_HIDE_CATEGORIES) || p->GetParent() != m_pState->m_properties )
1786 {
1787 textMarginHere += ((unsigned int)((p->m_depth-1)*m_subgroup_extramargin));
1788 }
1789
1790 // Paint margin area
1791 dc.SetBrush(marginBrush);
1792 dc.SetPen(marginPen);
1793 dc.DrawRectangle( -xRelMod, y, greyDepth, lh );
1794
1795 dc.SetPen( linepen );
1796
1797 int y2 = y + lh;
1798
1799 // Margin Edge
1800 dc.DrawLine( greyDepthX, y, greyDepthX, y2 );
1801
1802 // Splitters
1803 unsigned int si;
1804 int sx = x;
1805
1806 for ( si=0; si<state->m_colWidths.size(); si++ )
1807 {
1808 sx += state->m_colWidths[si];
1809 dc.DrawLine( sx, y, sx, y2 );
1810 }
1811
1812 // Horizontal Line, below
1813 // (not if both this and next is category caption)
1814 if ( p->IsCategory() &&
1815 nextP && nextP->IsCategory() )
1816 dc.SetPen(m_colCapBack);
1817
1818 dc.DrawLine( greyDepthX, y2-1, gridWidth-xRelMod, y2-1 );
1819
1820 //
1821 // Need to override row colours?
1822 wxColour rowFgCol;
1823 wxColour rowBgCol;
1824
1825 if ( p != selected )
1826 {
1827 // Disabled may get different colour.
1828 if ( !p->IsEnabled() )
1829 {
1830 renderFlags |= wxPGCellRenderer::Disabled |
1831 wxPGCellRenderer::DontUseCellFgCol;
1832 rowFgCol = m_colDisPropFore;
1833 }
1834 }
1835 else
1836 {
1837 renderFlags |= wxPGCellRenderer::Selected;
1838
1839 if ( !p->IsCategory() )
1840 {
1841 renderFlags |= wxPGCellRenderer::DontUseCellFgCol |
1842 wxPGCellRenderer::DontUseCellBgCol;
1843
1844 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1845 wasSelectedPainted = true;
1846 #endif
1847
1848 // Selected gets different colour.
1849 if ( reallyFocused )
1850 {
1851 rowFgCol = m_colSelFore;
1852 rowBgCol = m_colSelBack;
1853 }
1854 else if ( isEnabled )
1855 {
1856 rowFgCol = m_colPropFore;
1857 rowBgCol = m_colMargin;
1858 }
1859 else
1860 {
1861 rowFgCol = m_colDisPropFore;
1862 rowBgCol = m_colSelBack;
1863 }
1864 }
1865 }
1866
1867 wxBrush rowBgBrush;
1868
1869 if ( rowBgCol.IsOk() )
1870 rowBgBrush = wxBrush(rowBgCol);
1871
1872 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL) )
1873 renderFlags = renderFlags & ~wxPGCellRenderer::DontUseCellColours;
1874
1875 //
1876 // Fill additional margin area with background colour of first cell
1877 if ( greyDepthX < textMarginHere )
1878 {
1879 if ( !(renderFlags & wxPGCellRenderer::DontUseCellBgCol) )
1880 {
1881 wxPGCell& cell = p->GetCell(0);
1882 rowBgCol = cell.GetBgCol();
1883 rowBgBrush = wxBrush(rowBgCol);
1884 }
1885 dc.SetBrush(rowBgBrush);
1886 dc.SetPen(rowBgCol);
1887 dc.DrawRectangle(greyDepthX+1, y,
1888 textMarginHere-greyDepthX, lh-1);
1889 }
1890
1891 bool fontChanged = false;
1892
1893 // Expander button rectangle
1894 wxRect butRect( ((p->m_depth - 1) * m_subgroup_extramargin) - xRelMod,
1895 y,
1896 m_marginWidth,
1897 lh );
1898
1899 if ( p->IsCategory() )
1900 {
1901 // Captions have their cell areas merged as one
1902 dc.SetFont(m_captionFont);
1903 fontChanged = true;
1904 wxRect cellRect(greyDepthX, y, gridWidth - greyDepth + 2, rowHeight-1 );
1905
1906 if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol )
1907 {
1908 dc.SetBrush(rowBgBrush);
1909 dc.SetPen(rowBgCol);
1910 }
1911
1912 if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol )
1913 {
1914 dc.SetTextForeground(rowFgCol);
1915 }
1916
1917 wxPGCellRenderer* renderer = p->GetCellRenderer(0);
1918 renderer->Render( dc, cellRect, this, p, 0, -1, renderFlags );
1919
1920 // Tree Item Button
1921 if ( !HasFlag(wxPG_HIDE_MARGIN) && p->HasVisibleChildren() )
1922 DrawExpanderButton( dc, butRect, p );
1923 }
1924 else
1925 {
1926 if ( p->m_flags & wxPG_PROP_MODIFIED && (windowStyle & wxPG_BOLD_MODIFIED) )
1927 {
1928 dc.SetFont(m_captionFont);
1929 fontChanged = true;
1930 }
1931
1932 unsigned int ci;
1933 int cellX = x + 1;
1934 int nextCellWidth = state->m_colWidths[0];
1935 wxRect cellRect(greyDepthX+1, y, 0, rowHeight-1);
1936 int textXAdd = textMarginHere - greyDepthX;
1937
1938 for ( ci=0; ci<state->m_colWidths.size(); ci++ )
1939 {
1940 cellRect.width = nextCellWidth - 1;
1941
1942 bool ctrlCell = false;
1943 int cellRenderFlags = renderFlags;
1944
1945 // Tree Item Button
1946 if ( ci == 0 && !HasFlag(wxPG_HIDE_MARGIN) && p->HasVisibleChildren() )
1947 DrawExpanderButton( dc, butRect, p );
1948
1949 // Background
1950 if ( p == selected && m_wndEditor && ci == 1 )
1951 {
1952 wxColour editorBgCol = GetEditorControl()->GetBackgroundColour();
1953 dc.SetBrush(editorBgCol);
1954 dc.SetPen(editorBgCol);
1955 dc.SetTextForeground(m_colPropFore);
1956 dc.DrawRectangle(cellRect);
1957
1958 if ( m_dragStatus == 0 && !(m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE) )
1959 ctrlCell = true;
1960 }
1961 else
1962 {
1963 if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol )
1964 {
1965 dc.SetBrush(rowBgBrush);
1966 dc.SetPen(rowBgCol);
1967 }
1968
1969 if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol )
1970 {
1971 dc.SetTextForeground(rowFgCol);
1972 }
1973 }
1974
1975 dc.SetClippingRegion(cellRect);
1976
1977 cellRect.x += textXAdd;
1978 cellRect.width -= textXAdd;
1979
1980 // Foreground
1981 if ( !ctrlCell )
1982 {
1983 wxPGCellRenderer* renderer;
1984 int cmnVal = p->GetCommonValue();
1985 if ( cmnVal == -1 || ci != 1 )
1986 {
1987 renderer = p->GetCellRenderer(ci);
1988 renderer->Render( dc, cellRect, this, p, ci, -1,
1989 cellRenderFlags );
1990 }
1991 else
1992 {
1993 renderer = GetCommonValue(cmnVal)->GetRenderer();
1994 renderer->Render( dc, cellRect, this, p, ci, -1,
1995 cellRenderFlags );
1996 }
1997 }
1998
1999 cellX += state->m_colWidths[ci];
2000 if ( ci < (state->m_colWidths.size()-1) )
2001 nextCellWidth = state->m_colWidths[ci+1];
2002 cellRect.x = cellX;
2003 dc.DestroyClippingRegion(); // Is this really necessary?
2004 textXAdd = 0;
2005 }
2006 }
2007
2008 if ( fontChanged )
2009 dc.SetFont(normalfont);
2010
2011 y += rowHeight;
2012 }
2013
2014 // Refresh editor controls (seems not needed on msw)
2015 // NOTE: This code is mandatory for GTK!
2016 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2017 if ( wasSelectedPainted )
2018 {
2019 if ( m_wndEditor )
2020 m_wndEditor->Refresh();
2021 if ( m_wndEditor2 )
2022 m_wndEditor2->Refresh();
2023 }
2024 #endif
2025
2026 return y + yRelMod;
2027 }
2028
2029 // -----------------------------------------------------------------------
2030
2031 wxRect wxPropertyGrid::GetPropertyRect( const wxPGProperty* p1, const wxPGProperty* p2 ) const
2032 {
2033 wxRect r;
2034
2035 if ( m_width < 10 || m_height < 10 ||
2036 !m_pState->m_properties->GetChildCount() ||
2037 p1 == (wxPGProperty*) NULL )
2038 return wxRect(0,0,0,0);
2039
2040 int vy = 0;
2041
2042 //
2043 // Return rect which encloses the given property range
2044
2045 int visTop = p1->GetY();
2046 int visBottom;
2047 if ( p2 )
2048 visBottom = p2->GetY() + m_lineHeight;
2049 else
2050 visBottom = m_height + visTop;
2051
2052 // If seleced property is inside the range, we'll extend the range to include
2053 // control's size.
2054 wxPGProperty* selected = m_selected;
2055 if ( selected )
2056 {
2057 int selectedY = selected->GetY();
2058 if ( selectedY >= visTop && selectedY < visBottom )
2059 {
2060 wxWindow* editor = GetEditorControl();
2061 if ( editor )
2062 {
2063 int visBottom2 = selectedY + editor->GetSize().y;
2064 if ( visBottom2 > visBottom )
2065 visBottom = visBottom2;
2066 }
2067 }
2068 }
2069
2070 return wxRect(0,visTop-vy,m_pState->m_width,visBottom-visTop);
2071 }
2072
2073 // -----------------------------------------------------------------------
2074
2075 void wxPropertyGrid::DrawItems( const wxPGProperty* p1, const wxPGProperty* p2 )
2076 {
2077 if ( m_frozen )
2078 return;
2079
2080 if ( m_pState->m_itemsAdded )
2081 PrepareAfterItemsAdded();
2082
2083 wxRect r = GetPropertyRect(p1, p2);
2084 if ( r.width > 0 )
2085 {
2086 m_canvas->RefreshRect(r);
2087 }
2088 }
2089
2090 // -----------------------------------------------------------------------
2091
2092 void wxPropertyGrid::RefreshProperty( wxPGProperty* p )
2093 {
2094 if ( p == m_selected )
2095 DoSelectProperty(p, wxPG_SEL_FORCE);
2096
2097 DrawItemAndChildren(p);
2098 }
2099
2100 // -----------------------------------------------------------------------
2101
2102 void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty* p )
2103 {
2104 if ( m_frozen )
2105 return;
2106
2107 // Draw item, children, and parent too, if it is not category
2108 wxPGProperty* parent = p->GetParent();
2109
2110 while ( parent &&
2111 !parent->IsCategory() &&
2112 parent->GetParent() )
2113 {
2114 DrawItem(parent);
2115 parent = parent->GetParent();
2116 }
2117
2118 DrawItemAndChildren(p);
2119 }
2120
2121 void wxPropertyGrid::DrawItemAndChildren( wxPGProperty* p )
2122 {
2123 wxCHECK_RET( p, wxT("invalid property id") );
2124
2125 // Do not draw if in non-visible page
2126 if ( p->GetParentState() != m_pState )
2127 return;
2128
2129 // do not draw a single item if multiple pending
2130 if ( m_pState->m_itemsAdded || m_frozen )
2131 return;
2132
2133 // Update child control.
2134 if ( m_selected && m_selected->GetParent() == p )
2135 RefreshEditor();
2136
2137 const wxPGProperty* lastDrawn = p->GetLastVisibleSubItem();
2138
2139 DrawItems(p, lastDrawn);
2140 }
2141
2142 // -----------------------------------------------------------------------
2143
2144 void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground),
2145 const wxRect *rect )
2146 {
2147 PrepareAfterItemsAdded();
2148
2149 wxWindow::Refresh(false);
2150 if ( m_canvas )
2151 // TODO: Coordinate translation
2152 m_canvas->Refresh(false, rect);
2153
2154 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2155 // I think this really helps only GTK+1.2
2156 if ( m_wndEditor ) m_wndEditor->Refresh();
2157 if ( m_wndEditor2 ) m_wndEditor2->Refresh();
2158 #endif
2159 }
2160
2161 // -----------------------------------------------------------------------
2162 // wxPropertyGrid global operations
2163 // -----------------------------------------------------------------------
2164
2165 void wxPropertyGrid::Clear()
2166 {
2167 ClearSelection(false);
2168
2169 m_pState->DoClear();
2170
2171 m_propHover = NULL;
2172
2173 m_prevVY = 0;
2174
2175 RecalculateVirtualSize();
2176
2177 // Need to clear some area at the end
2178 if ( !m_frozen )
2179 RefreshRect(wxRect(0, 0, m_width, m_height));
2180 }
2181
2182 // -----------------------------------------------------------------------
2183
2184 bool wxPropertyGrid::EnableCategories( bool enable )
2185 {
2186 ClearSelection(false);
2187
2188 if ( enable )
2189 {
2190 //
2191 // Enable categories
2192 //
2193
2194 m_windowStyle &= ~(wxPG_HIDE_CATEGORIES);
2195 }
2196 else
2197 {
2198 //
2199 // Disable categories
2200 //
2201 m_windowStyle |= wxPG_HIDE_CATEGORIES;
2202 }
2203
2204 if ( !m_pState->EnableCategories(enable) )
2205 return false;
2206
2207 if ( !m_frozen )
2208 {
2209 if ( m_windowStyle & wxPG_AUTO_SORT )
2210 {
2211 m_pState->m_itemsAdded = 1; // force
2212 PrepareAfterItemsAdded();
2213 }
2214 }
2215 else
2216 m_pState->m_itemsAdded = 1;
2217
2218 // No need for RecalculateVirtualSize() here - it is already called in
2219 // wxPropertyGridPageState method above.
2220
2221 Refresh();
2222
2223 return true;
2224 }
2225
2226 // -----------------------------------------------------------------------
2227
2228 void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState )
2229 {
2230 wxASSERT( pNewState );
2231 wxASSERT( pNewState->GetGrid() );
2232
2233 if ( pNewState == m_pState )
2234 return;
2235
2236 wxPGProperty* oldSelection = m_selected;
2237
2238 ClearSelection(false);
2239
2240 m_pState->m_selected = oldSelection;
2241
2242 bool orig_mode = m_pState->IsInNonCatMode();
2243 bool new_state_mode = pNewState->IsInNonCatMode();
2244
2245 m_pState = pNewState;
2246
2247 // Validate width
2248 int pgWidth = GetClientSize().x;
2249 if ( HasVirtualWidth() )
2250 {
2251 int minWidth = pgWidth;
2252 if ( pNewState->m_width < minWidth )
2253 {
2254 pNewState->m_width = minWidth;
2255 pNewState->CheckColumnWidths();
2256 }
2257 }
2258 else
2259 {
2260 //
2261 // Just in case, fully re-center splitter
2262 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2263 pNewState->m_fSplitterX = -1.0;
2264
2265 pNewState->OnClientWidthChange( pgWidth, pgWidth - pNewState->m_width );
2266 }
2267
2268 m_propHover = (wxPGProperty*) NULL;
2269
2270 // If necessary, convert state to correct mode.
2271 if ( orig_mode != new_state_mode )
2272 {
2273 // This should refresh as well.
2274 EnableCategories( orig_mode?false:true );
2275 }
2276 else if ( !m_frozen )
2277 {
2278 // Refresh, if not frozen.
2279 if ( m_pState->m_itemsAdded )
2280 PrepareAfterItemsAdded();
2281
2282 // Reselect
2283 if ( m_pState->m_selected )
2284 DoSelectProperty( m_pState->m_selected );
2285
2286 RecalculateVirtualSize(0);
2287 Refresh();
2288 }
2289 else
2290 m_pState->m_itemsAdded = 1;
2291 }
2292
2293 // -----------------------------------------------------------------------
2294
2295 void wxPropertyGrid::SortChildren( wxPGPropArg id )
2296 {
2297 wxPG_PROP_ARG_CALL_PROLOG()
2298
2299 m_pState->SortChildren( p );
2300 }
2301
2302 // -----------------------------------------------------------------------
2303
2304 void wxPropertyGrid::Sort()
2305 {
2306 ClearSelection(false); // This must be before state clear
2307
2308 m_pState->Sort();
2309 }
2310
2311 // -----------------------------------------------------------------------
2312
2313 // Call to SetSplitterPosition will always disable splitter auto-centering
2314 // if parent window is shown.
2315 void wxPropertyGrid::DoSetSplitterPosition_( int newxpos, bool refresh, int splitterIndex, bool allPages )
2316 {
2317 if ( ( newxpos < wxPG_DRAG_MARGIN ) )
2318 return;
2319
2320 wxPropertyGridPageState* state = m_pState;
2321
2322 state->DoSetSplitterPosition( newxpos, splitterIndex, allPages );
2323
2324 if ( refresh )
2325 {
2326 if ( m_selected )
2327 CorrectEditorWidgetSizeX();
2328
2329 Refresh();
2330 }
2331 }
2332
2333 // -----------------------------------------------------------------------
2334
2335 void wxPropertyGrid::CenterSplitter( bool enableAutoCentering )
2336 {
2337 SetSplitterPosition( m_width/2, true );
2338 if ( enableAutoCentering && ( m_windowStyle & wxPG_SPLITTER_AUTO_CENTER ) )
2339 m_iFlags &= ~(wxPG_FL_DONT_CENTER_SPLITTER);
2340 }
2341
2342 // -----------------------------------------------------------------------
2343 // wxPropertyGrid item iteration (GetNextProperty etc.) methods
2344 // -----------------------------------------------------------------------
2345
2346 // Returns nearest paint visible property (such that will be painted unless
2347 // window is scrolled or resized). If given property is paint visible, then
2348 // it itself will be returned
2349 wxPGProperty* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty* p ) const
2350 {
2351 int vx,vy1;// Top left corner of client
2352 GetViewStart(&vx,&vy1);
2353 vy1 *= wxPG_PIXELS_PER_UNIT;
2354
2355 int vy2 = vy1 + m_height;
2356 int propY = p->GetY2(m_lineHeight);
2357
2358 if ( (propY + m_lineHeight) < vy1 )
2359 {
2360 // Too high
2361 return DoGetItemAtY( vy1 );
2362 }
2363 else if ( propY > vy2 )
2364 {
2365 // Too low
2366 return DoGetItemAtY( vy2 );
2367 }
2368
2369 // Itself paint visible
2370 return p;
2371
2372 }
2373
2374 // -----------------------------------------------------------------------
2375 // Methods related to change in value, value modification and sending events
2376 // -----------------------------------------------------------------------
2377
2378 // commits any changes in editor of selected property
2379 // return true if validation did not fail
2380 // flags are same as with DoSelectProperty
2381 bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags )
2382 {
2383 // Committing already?
2384 if ( m_inCommitChangesFromEditor )
2385 return true;
2386
2387 // Don't do this if already processing editor event. It might
2388 // induce recursive dialogs and crap like that.
2389 if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT )
2390 {
2391 if ( m_inDoPropertyChanged )
2392 return true;
2393
2394 return false;
2395 }
2396
2397 if ( m_wndEditor &&
2398 IsEditorsValueModified() &&
2399 (m_iFlags & wxPG_FL_INITIALIZED) &&
2400 m_selected )
2401 {
2402 m_inCommitChangesFromEditor = 1;
2403
2404 wxVariant variant(m_selected->GetValueRef());
2405 bool valueIsPending = false;
2406
2407 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2408 // due to another window getting focus
2409 wxWindow* oldFocus = m_curFocused;
2410
2411 bool validationFailure = false;
2412 bool forceSuccess = (flags & (wxPG_SEL_NOVALIDATE|wxPG_SEL_FORCE)) ? true : false;
2413
2414 m_chgInfo_changedProperty = NULL;
2415
2416 // If truly modified, schedule value as pending.
2417 if ( m_selected->GetEditorClass()->GetValueFromControl( variant, m_selected, GetEditorControl() ) )
2418 {
2419 if ( DoEditorValidate() &&
2420 PerformValidation(m_selected, variant) )
2421 {
2422 valueIsPending = true;
2423 }
2424 else
2425 {
2426 validationFailure = true;
2427 }
2428 }
2429 else
2430 {
2431 EditorsValueWasNotModified();
2432 }
2433
2434 bool res = true;
2435
2436 m_inCommitChangesFromEditor = 0;
2437
2438 if ( validationFailure && !forceSuccess )
2439 {
2440 if (oldFocus)
2441 {
2442 oldFocus->SetFocus();
2443 m_curFocused = oldFocus;
2444 }
2445
2446 res = OnValidationFailure(m_selected, variant);
2447
2448 // Now prevent further validation failure messages
2449 if ( res )
2450 {
2451 EditorsValueWasNotModified();
2452 OnValidationFailureReset(m_selected);
2453 }
2454 }
2455 else if ( valueIsPending )
2456 {
2457 DoPropertyChanged( m_selected, flags );
2458 EditorsValueWasNotModified();
2459 }
2460
2461 return res;
2462 }
2463
2464 return true;
2465 }
2466
2467 // -----------------------------------------------------------------------
2468
2469 bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue,
2470 int flags )
2471 {
2472 //
2473 // Runs all validation functionality.
2474 // Returns true if value passes all tests.
2475 //
2476
2477 m_validationInfo.m_failureBehavior = m_permanentValidationFailureBehavior;
2478
2479 if ( pendingValue.GetType() == wxPG_VARIANT_TYPE_LIST )
2480 {
2481 if ( !p->ValidateValue(pendingValue, m_validationInfo) )
2482 return false;
2483 }
2484
2485 //
2486 // Adapt list to child values, if necessary
2487 wxVariant listValue = pendingValue;
2488 wxVariant* pPendingValue = &pendingValue;
2489 wxVariant* pList = NULL;
2490
2491 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2492 // string value, then we need treat as it was changed instead
2493 // (or, in addition, as is the case with composite string parent).
2494 // This includes creating list variant for child values.
2495
2496 wxPGProperty* pwc = p->GetParent();
2497 wxPGProperty* changedProperty = p;
2498 wxPGProperty* baseChangedProperty = changedProperty;
2499 wxVariant bcpPendingList;
2500
2501 listValue = pendingValue;
2502 listValue.SetName(p->GetBaseName());
2503
2504 while ( pwc &&
2505 (pwc->HasFlag(wxPG_PROP_AGGREGATE) || pwc->HasFlag(wxPG_PROP_COMPOSED_VALUE)) )
2506 {
2507 wxVariantList tempList;
2508 wxVariant lv(tempList, pwc->GetBaseName());
2509 lv.Append(listValue);
2510 listValue = lv;
2511 pPendingValue = &listValue;
2512
2513 if ( pwc->HasFlag(wxPG_PROP_AGGREGATE) )
2514 {
2515 baseChangedProperty = pwc;
2516 bcpPendingList = lv;
2517 }
2518
2519 changedProperty = pwc;
2520 pwc = pwc->GetParent();
2521 }
2522
2523 wxVariant value;
2524 wxPGProperty* evtChangingProperty = changedProperty;
2525
2526 if ( pPendingValue->GetType() != wxPG_VARIANT_TYPE_LIST )
2527 {
2528 value = *pPendingValue;
2529 }
2530 else
2531 {
2532 // Convert list to child values
2533 pList = pPendingValue;
2534 changedProperty->AdaptListToValue( *pPendingValue, &value );
2535 }
2536
2537 wxVariant evtChangingValue = value;
2538
2539 if ( flags & SendEvtChanging )
2540 {
2541 // FIXME: After proper ValueToString()s added, remove
2542 // this. It is just a temporary fix, as evt_changing
2543 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2544 // (unless it is selected, and textctrl editor is open).
2545 if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
2546 {
2547 evtChangingProperty = baseChangedProperty;
2548 if ( evtChangingProperty != p )
2549 {
2550 evtChangingProperty->AdaptListToValue( bcpPendingList, &evtChangingValue );
2551 }
2552 else
2553 {
2554 evtChangingValue = pendingValue;
2555 }
2556 }
2557
2558 if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
2559 {
2560 if ( changedProperty == m_selected )
2561 {
2562 wxWindow* editor = GetEditorControl();
2563 wxASSERT( editor->IsKindOf(CLASSINFO(wxTextCtrl)) );
2564 evtChangingValue = wxStaticCast(editor, wxTextCtrl)->GetValue();
2565 }
2566 else
2567 {
2568 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2569 }
2570 }
2571 }
2572
2573 wxASSERT( m_chgInfo_changedProperty == NULL );
2574 m_chgInfo_changedProperty = changedProperty;
2575 m_chgInfo_baseChangedProperty = baseChangedProperty;
2576 m_chgInfo_pendingValue = value;
2577
2578 if ( pList )
2579 m_chgInfo_valueList = *pList;
2580 else
2581 m_chgInfo_valueList.MakeNull();
2582
2583 // If changedProperty is not property which value was edited,
2584 // then call wxPGProperty::ValidateValue() for that as well.
2585 if ( p != changedProperty && value.GetType() != wxPG_VARIANT_TYPE_LIST )
2586 {
2587 if ( !changedProperty->ValidateValue(value, m_validationInfo) )
2588 return false;
2589 }
2590
2591 if ( flags & SendEvtChanging )
2592 {
2593 // SendEvent returns true if event was vetoed
2594 if ( SendEvent( wxEVT_PG_CHANGING, evtChangingProperty, &evtChangingValue, 0 ) )
2595 return false;
2596 }
2597
2598 if ( flags & IsStandaloneValidation )
2599 {
2600 // If called in 'generic' context, we need to reset
2601 // m_chgInfo_changedProperty and write back translated value.
2602 m_chgInfo_changedProperty = NULL;
2603 pendingValue = value;
2604 }
2605
2606 return true;
2607 }
2608
2609 // -----------------------------------------------------------------------
2610
2611 void wxPropertyGrid::DoShowPropertyError( wxPGProperty* WXUNUSED(property), const wxString& msg )
2612 {
2613 if ( !msg.length() )
2614 return;
2615
2616 #if wxUSE_STATUSBAR
2617 if ( !wxPGGlobalVars->m_offline )
2618 {
2619 wxWindow* topWnd = ::wxGetTopLevelParent(this);
2620 if ( topWnd )
2621 {
2622 wxFrame* pFrame = wxDynamicCast(topWnd, wxFrame);
2623 if ( pFrame )
2624 {
2625 wxStatusBar* pStatusBar = pFrame->GetStatusBar();
2626 if ( pStatusBar )
2627 {
2628 pStatusBar->SetStatusText(msg);
2629 return;
2630 }
2631 }
2632 }
2633 }
2634 #endif
2635
2636 ::wxMessageBox(msg, _T("Property Error"));
2637 }
2638
2639 // -----------------------------------------------------------------------
2640
2641 bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty* property, wxVariant& WXUNUSED(invalidValue) )
2642 {
2643 int vfb = m_validationInfo.m_failureBehavior;
2644
2645 if ( vfb & wxPG_VFB_BEEP )
2646 ::wxBell();
2647
2648 if ( (vfb & wxPG_VFB_MARK_CELL) &&
2649 !property->HasFlag(wxPG_PROP_INVALID_VALUE) )
2650 {
2651 unsigned int colCount = m_pState->GetColumnCount();
2652
2653 // We need backup marked property's cells
2654 m_propCellsBackup = property->m_cells;
2655
2656 wxColour vfbFg = *wxWHITE;
2657 wxColour vfbBg = *wxRED;
2658
2659 property->EnsureCells(colCount);
2660
2661 for ( unsigned int i=0; i<colCount; i++ )
2662 {
2663 wxPGCell& cell = property->m_cells[i];
2664 cell.SetFgCol(vfbFg);
2665 cell.SetBgCol(vfbBg);
2666 }
2667
2668 DrawItemAndChildren(property);
2669
2670 if ( property == m_selected )
2671 {
2672 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL);
2673
2674 wxWindow* editor = GetEditorControl();
2675 if ( editor )
2676 {
2677 editor->SetForegroundColour(vfbFg);
2678 editor->SetBackgroundColour(vfbBg);
2679 }
2680 }
2681 }
2682
2683 if ( vfb & wxPG_VFB_SHOW_MESSAGE )
2684 {
2685 wxString msg = m_validationInfo.m_failureMessage;
2686
2687 if ( !msg.length() )
2688 msg = _T("You have entered invalid value. Press ESC to cancel editing.");
2689
2690 DoShowPropertyError(property, msg);
2691 }
2692
2693 return (vfb & wxPG_VFB_STAY_IN_PROPERTY) ? false : true;
2694 }
2695
2696 // -----------------------------------------------------------------------
2697
2698 void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty* property )
2699 {
2700 int vfb = m_validationInfo.m_failureBehavior;
2701
2702 if ( vfb & wxPG_VFB_MARK_CELL )
2703 {
2704 // Revert cells
2705 property->m_cells = m_propCellsBackup;
2706
2707 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL);
2708
2709 if ( property == m_selected && GetEditorControl() )
2710 {
2711 // Calling this will recreate the control, thus resetting its colour
2712 RefreshProperty(property);
2713 }
2714 else
2715 {
2716 DrawItemAndChildren(property);
2717 }
2718 }
2719 }
2720
2721 // -----------------------------------------------------------------------
2722
2723 // flags are same as with DoSelectProperty
2724 bool wxPropertyGrid::DoPropertyChanged( wxPGProperty* p, unsigned int selFlags )
2725 {
2726 if ( m_inDoPropertyChanged )
2727 return true;
2728
2729 wxWindow* editor = GetEditorControl();
2730
2731 m_pState->m_anyModified = 1;
2732
2733 m_inDoPropertyChanged = 1;
2734
2735 // Maybe need to update control
2736 wxASSERT( m_chgInfo_changedProperty != NULL );
2737
2738 // These values were calculated in PerformValidation()
2739 wxPGProperty* changedProperty = m_chgInfo_changedProperty;
2740 wxVariant value = m_chgInfo_pendingValue;
2741
2742 wxPGProperty* topPaintedProperty = changedProperty;
2743
2744 while ( !topPaintedProperty->IsCategory() &&
2745 !topPaintedProperty->IsRoot() )
2746 {
2747 topPaintedProperty = topPaintedProperty->GetParent();
2748 }
2749
2750 changedProperty->SetValue(value, &m_chgInfo_valueList, wxPG_SETVAL_BY_USER);
2751
2752 // Set as Modified (not if dragging just began)
2753 if ( !(p->m_flags & wxPG_PROP_MODIFIED) )
2754 {
2755 p->m_flags |= wxPG_PROP_MODIFIED;
2756 if ( p == m_selected && (m_windowStyle & wxPG_BOLD_MODIFIED) )
2757 {
2758 if ( editor )
2759 SetCurControlBoldFont();
2760 }
2761 }
2762
2763 wxPGProperty* pwc;
2764
2765 // Propagate updates to parent(s)
2766 pwc = p;
2767 wxPGProperty* prevPwc = NULL;
2768
2769 while ( prevPwc != topPaintedProperty )
2770 {
2771 pwc->m_flags |= wxPG_PROP_MODIFIED;
2772
2773 if ( pwc == m_selected && (m_windowStyle & wxPG_BOLD_MODIFIED) )
2774 {
2775 if ( editor )
2776 SetCurControlBoldFont();
2777 }
2778
2779 prevPwc = pwc;
2780 pwc = pwc->GetParent();
2781 }
2782
2783 // Draw the actual property
2784 DrawItemAndChildren( topPaintedProperty );
2785
2786 //
2787 // If value was set by wxPGProperty::OnEvent, then update the editor
2788 // control.
2789 if ( selFlags & wxPG_SEL_DIALOGVAL )
2790 {
2791 RefreshEditor();
2792 }
2793 else
2794 {
2795 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2796 if ( m_wndEditor ) m_wndEditor->Refresh();
2797 if ( m_wndEditor2 ) m_wndEditor2->Refresh();
2798 #endif
2799 }
2800
2801 // Sanity check
2802 wxASSERT( !changedProperty->GetParent()->HasFlag(wxPG_PROP_AGGREGATE) );
2803
2804 // If top parent has composite string value, then send to child parents,
2805 // starting from baseChangedProperty.
2806 if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
2807 {
2808 pwc = m_chgInfo_baseChangedProperty;
2809
2810 while ( pwc != changedProperty )
2811 {
2812 SendEvent( wxEVT_PG_CHANGED, pwc, NULL, selFlags );
2813 pwc = pwc->GetParent();
2814 }
2815 }
2816
2817 SendEvent( wxEVT_PG_CHANGED, changedProperty, NULL, selFlags );
2818
2819 m_inDoPropertyChanged = 0;
2820
2821 return true;
2822 }
2823
2824 // -----------------------------------------------------------------------
2825
2826 bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id, wxVariant newValue )
2827 {
2828 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2829
2830 m_chgInfo_changedProperty = NULL;
2831
2832 if ( PerformValidation(p, newValue) )
2833 {
2834 DoPropertyChanged(p);
2835 return true;
2836 }
2837 else
2838 {
2839 OnValidationFailure(p, newValue);
2840 }
2841
2842 return false;
2843 }
2844
2845 // -----------------------------------------------------------------------
2846
2847 wxVariant wxPropertyGrid::GetUncommittedPropertyValue()
2848 {
2849 wxPGProperty* prop = GetSelectedProperty();
2850
2851 if ( !prop )
2852 return wxNullVariant;
2853
2854 wxTextCtrl* tc = GetEditorTextCtrl();
2855 wxVariant value = prop->GetValue();
2856
2857 if ( !tc || !IsEditorsValueModified() )
2858 return value;
2859
2860 if ( !prop->StringToValue(value, tc->GetValue()) )
2861 return value;
2862
2863 if ( !PerformValidation(prop, value, IsStandaloneValidation) )
2864 return prop->GetValue();
2865
2866 return value;
2867 }
2868
2869 // -----------------------------------------------------------------------
2870
2871 // Runs wxValidator for the selected property
2872 bool wxPropertyGrid::DoEditorValidate()
2873 {
2874 return true;
2875 }
2876
2877 // -----------------------------------------------------------------------
2878
2879 void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event )
2880 {
2881 wxPGProperty* selected = m_selected;
2882
2883 // Somehow, event is handled after property has been deselected.
2884 // Possibly, but very rare.
2885 if ( !selected )
2886 return;
2887
2888 if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT )
2889 return;
2890
2891 wxVariant pendingValue(selected->GetValueRef());
2892 wxWindow* wnd = GetEditorControl();
2893 int selFlags = 0;
2894 bool wasUnspecified = selected->IsValueUnspecified();
2895 int usesAutoUnspecified = selected->UsesAutoUnspecified();
2896
2897 bool valueIsPending = false;
2898
2899 m_chgInfo_changedProperty = NULL;
2900
2901 m_iFlags &= ~(wxPG_FL_VALIDATION_FAILED|wxPG_FL_VALUE_CHANGE_IN_EVENT);
2902
2903 //
2904 // Filter out excess wxTextCtrl modified events
2905 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED &&
2906 wnd &&
2907 wnd->IsKindOf(CLASSINFO(wxTextCtrl)) )
2908 {
2909 wxTextCtrl* tc = (wxTextCtrl*) wnd;
2910
2911 wxString newTcValue = tc->GetValue();
2912 if ( m_prevTcValue == newTcValue )
2913 return;
2914
2915 m_prevTcValue = newTcValue;
2916 }
2917
2918 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT);
2919
2920 bool validationFailure = false;
2921 bool buttonWasHandled = false;
2922
2923 //
2924 // Try common button handling
2925 if ( m_wndEditor2 && event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
2926 {
2927 wxPGEditorDialogAdapter* adapter = selected->GetEditorDialog();
2928
2929 if ( adapter )
2930 {
2931 buttonWasHandled = true;
2932 // Store as res2, as previously (and still currently alternatively)
2933 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2934 // in wxPGProperty::OnEvent().
2935 adapter->ShowDialog( this, selected );
2936 delete adapter;
2937 }
2938 }
2939
2940 if ( !buttonWasHandled )
2941 {
2942 if ( wnd )
2943 {
2944 // First call editor class' event handler.
2945 const wxPGEditor* editor = selected->GetEditorClass();
2946
2947 if ( editor->OnEvent( this, selected, wnd, event ) )
2948 {
2949 // If changes, validate them
2950 if ( DoEditorValidate() )
2951 {
2952 if ( editor->GetValueFromControl( pendingValue, m_selected, wnd ) )
2953 valueIsPending = true;
2954 }
2955 else
2956 {
2957 validationFailure = true;
2958 }
2959 }
2960 }
2961
2962 // Then the property's custom handler (must be always called, unless
2963 // validation failed).
2964 if ( !validationFailure )
2965 buttonWasHandled = selected->OnEvent( this, wnd, event );
2966 }
2967
2968 // SetValueInEvent(), as called in one of the functions referred above
2969 // overrides editor's value.
2970 if ( m_iFlags & wxPG_FL_VALUE_CHANGE_IN_EVENT )
2971 {
2972 valueIsPending = true;
2973 pendingValue = m_changeInEventValue;
2974 selFlags |= wxPG_SEL_DIALOGVAL;
2975 }
2976
2977 if ( !validationFailure && valueIsPending )
2978 if ( !PerformValidation(m_selected, pendingValue) )
2979 validationFailure = true;
2980
2981 if ( validationFailure)
2982 {
2983 OnValidationFailure(selected, pendingValue);
2984 }
2985 else if ( valueIsPending )
2986 {
2987 selFlags |= ( !wasUnspecified && selected->IsValueUnspecified() && usesAutoUnspecified ) ? wxPG_SEL_SETUNSPEC : 0;
2988
2989 DoPropertyChanged(selected, selFlags);
2990 EditorsValueWasNotModified();
2991
2992 // Regardless of editor type, unfocus editor on
2993 // text-editing related enter press.
2994 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER )
2995 {
2996 SetFocusOnCanvas();
2997 }
2998 }
2999 else
3000 {
3001 // No value after all
3002
3003 // Regardless of editor type, unfocus editor on
3004 // text-editing related enter press.
3005 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER )
3006 {
3007 SetFocusOnCanvas();
3008 }
3009
3010 // Let unhandled button click events go to the parent
3011 if ( !buttonWasHandled && event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
3012 {
3013 wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED,GetId());
3014 GetEventHandler()->AddPendingEvent(evt);
3015 }
3016 }
3017
3018 ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT);
3019 }
3020
3021 // -----------------------------------------------------------------------
3022 // wxPropertyGrid editor control helper methods
3023 // -----------------------------------------------------------------------
3024
3025 wxRect wxPropertyGrid::GetEditorWidgetRect( wxPGProperty* p, int column ) const
3026 {
3027 int itemy = p->GetY2(m_lineHeight);
3028 int vy = 0;
3029 int cust_img_space = 0;
3030 int splitterX = m_pState->DoGetSplitterPosition(column-1);
3031 int colEnd = splitterX + m_pState->m_colWidths[column];
3032
3033 // TODO: If custom image detection changes from current, change this.
3034 if ( m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE /*p->m_flags & wxPG_PROP_CUSTOMIMAGE*/ )
3035 {
3036 //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3037 int imwid = p->OnMeasureImage().x;
3038 if ( imwid < 1 ) imwid = wxPG_CUSTOM_IMAGE_WIDTH;
3039 cust_img_space = imwid + wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
3040 }
3041
3042 return wxRect
3043 (
3044 splitterX+cust_img_space+wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1,
3045 itemy-vy,
3046 colEnd-splitterX-wxPG_XBEFOREWIDGET-wxPG_CONTROL_MARGIN-cust_img_space-1,
3047 m_lineHeight-1
3048 );
3049 }
3050
3051 // -----------------------------------------------------------------------
3052
3053 wxRect wxPropertyGrid::GetImageRect( wxPGProperty* p, int item ) const
3054 {
3055 wxSize sz = GetImageSize(p, item);
3056 return wxRect(wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1,
3057 wxPG_CUSTOM_IMAGE_SPACINGY,
3058 sz.x,
3059 sz.y);
3060 }
3061
3062 // return size of custom paint image
3063 wxSize wxPropertyGrid::GetImageSize( wxPGProperty* p, int item ) const
3064 {
3065 // If called with NULL property, then return default image
3066 // size for properties that use image.
3067 if ( !p )
3068 return wxSize(wxPG_CUSTOM_IMAGE_WIDTH,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight));
3069
3070 wxSize cis = p->OnMeasureImage(item);
3071
3072 int choiceCount = p->m_choices.GetCount();
3073 int comVals = p->GetDisplayedCommonValueCount();
3074 if ( item >= choiceCount && comVals > 0 )
3075 {
3076 unsigned int cvi = item-choiceCount;
3077 cis = GetCommonValue(cvi)->GetRenderer()->GetImageSize(NULL, 1, cvi);
3078 }
3079 else if ( item >= 0 && choiceCount == 0 )
3080 return wxSize(0, 0);
3081
3082 if ( cis.x < 0 )
3083 {
3084 if ( cis.x <= -1 )
3085 cis.x = wxPG_CUSTOM_IMAGE_WIDTH;
3086 }
3087 if ( cis.y <= 0 )
3088 {
3089 if ( cis.y >= -1 )
3090 cis.y = wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight);
3091 else
3092 cis.y = -cis.y;
3093 }
3094 return cis;
3095 }
3096
3097 // -----------------------------------------------------------------------
3098
3099 // takes scrolling into account
3100 void wxPropertyGrid::ImprovedClientToScreen( int* px, int* py )
3101 {
3102 int vx, vy;
3103 GetViewStart(&vx,&vy);
3104 vy*=wxPG_PIXELS_PER_UNIT;
3105 vx*=wxPG_PIXELS_PER_UNIT;
3106 *px -= vx;
3107 *py -= vy;
3108 ClientToScreen( px, py );
3109 }
3110
3111 // -----------------------------------------------------------------------
3112
3113 wxPropertyGridHitTestResult wxPropertyGrid::HitTest( const wxPoint& pt ) const
3114 {
3115 wxPoint pt2;
3116 GetViewStart(&pt2.x,&pt2.y);
3117 pt2.x *= wxPG_PIXELS_PER_UNIT;
3118 pt2.y *= wxPG_PIXELS_PER_UNIT;
3119 pt2.x += pt.x;
3120 pt2.y += pt.y;
3121
3122 return m_pState->HitTest(pt2);
3123 }
3124
3125 // -----------------------------------------------------------------------
3126
3127 // custom set cursor
3128 void wxPropertyGrid::CustomSetCursor( int type, bool override )
3129 {
3130 if ( type == m_curcursor && !override ) return;
3131
3132 wxCursor* cursor = &wxPG_DEFAULT_CURSOR;
3133
3134 if ( type == wxCURSOR_SIZEWE )
3135 cursor = m_cursorSizeWE;
3136
3137 m_canvas->SetCursor( *cursor );
3138
3139 m_curcursor = type;
3140 }
3141
3142 // -----------------------------------------------------------------------
3143 // wxPropertyGrid property selection, editor creation
3144 // -----------------------------------------------------------------------
3145
3146 //
3147 // This class forwards events from property editor controls to wxPropertyGrid.
3148 class wxPropertyGridEditorEventForwarder : public wxEvtHandler
3149 {
3150 public:
3151 wxPropertyGridEditorEventForwarder( wxPropertyGrid* propGrid )
3152 : wxEvtHandler(), m_propGrid(propGrid)
3153 {
3154 }
3155
3156 virtual ~wxPropertyGridEditorEventForwarder()
3157 {
3158 }
3159
3160 private:
3161 bool ProcessEvent( wxEvent& event )
3162 {
3163 // Always skip
3164 event.Skip();
3165
3166 m_propGrid->HandleCustomEditorEvent(event);
3167
3168 return wxEvtHandler::ProcessEvent(event);
3169 }
3170
3171 wxPropertyGrid* m_propGrid;
3172 };
3173
3174 // Setups event handling for child control
3175 void wxPropertyGrid::SetupChildEventHandling( wxWindow* argWnd )
3176 {
3177 wxWindowID id = argWnd->GetId();
3178
3179 if ( argWnd == m_wndEditor )
3180 {
3181 argWnd->Connect(id, wxEVT_MOTION,
3182 wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild),
3183 NULL, this);
3184 argWnd->Connect(id, wxEVT_LEFT_UP,
3185 wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild),
3186 NULL, this);
3187 argWnd->Connect(id, wxEVT_LEFT_DOWN,
3188 wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild),
3189 NULL, this);
3190 argWnd->Connect(id, wxEVT_RIGHT_UP,
3191 wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild),
3192 NULL, this);
3193 argWnd->Connect(id, wxEVT_ENTER_WINDOW,
3194 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry),
3195 NULL, this);
3196 argWnd->Connect(id, wxEVT_LEAVE_WINDOW,
3197 wxMouseEventHandler(wxPropertyGrid::OnMouseEntry),
3198 NULL, this);
3199 }
3200
3201 wxPropertyGridEditorEventForwarder* forwarder;
3202 forwarder = new wxPropertyGridEditorEventForwarder(this);
3203 argWnd->PushEventHandler(forwarder);
3204
3205 argWnd->Connect(id, wxEVT_KEY_DOWN,
3206 wxCharEventHandler(wxPropertyGrid::OnChildKeyDown),
3207 NULL, this);
3208 }
3209
3210 void wxPropertyGrid::FreeEditors()
3211 {
3212 //
3213 // Return focus back to canvas from children (this is required at least for
3214 // GTK+, which, unlike Windows, clears focus when control is destroyed
3215 // instead of moving it to closest parent).
3216 wxWindow* focus = wxWindow::FindFocus();
3217 if ( focus )
3218 {
3219 wxWindow* parent = focus->GetParent();
3220 while ( parent )
3221 {
3222 if ( parent == m_canvas )
3223 {
3224 SetFocusOnCanvas();
3225 break;
3226 }
3227 parent = parent->GetParent();
3228 }
3229 }
3230
3231 // Do not free editors immediately if processing events
3232 if ( m_wndEditor2 )
3233 {
3234 m_wndEditor2->PopEventHandler(true);
3235 m_wndEditor2->Hide();
3236 wxPendingDelete.Append( m_wndEditor2 );
3237 m_wndEditor2 = (wxWindow*) NULL;
3238 }
3239
3240 if ( m_wndEditor )
3241 {
3242 m_wndEditor->PopEventHandler(true);
3243 m_wndEditor->Hide();
3244 wxPendingDelete.Append( m_wndEditor );
3245 m_wndEditor = (wxWindow*) NULL;
3246 }
3247 }
3248
3249 // Call with NULL to de-select property
3250 bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags )
3251 {
3252 /*
3253 if (p)
3254 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3255 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3256 else
3257 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3258 */
3259
3260 if ( m_inDoSelectProperty )
3261 return true;
3262
3263 m_inDoSelectProperty = 1;
3264
3265 wxPGProperty* prev = m_selected;
3266
3267 if ( !m_pState )
3268 {
3269 m_inDoSelectProperty = 0;
3270 return false;
3271 }
3272
3273 /*
3274 if (m_selected)
3275 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3276 else
3277 wxPrintf( "None selected\n" );
3278
3279 if (p)
3280 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3281 else
3282 wxPrintf( "P = NULL\n" );
3283 */
3284
3285 // If we are frozen, then just set the values.
3286 if ( m_frozen )
3287 {
3288 m_iFlags &= ~(wxPG_FL_ABNORMAL_EDITOR);
3289 m_editorFocused = 0;
3290 m_selected = p;
3291 m_selColumn = 1;
3292 m_pState->m_selected = p;
3293
3294 // If frozen, always free controls. But don't worry, as Thaw will
3295 // recall SelectProperty to recreate them.
3296 FreeEditors();
3297
3298 // Prevent any further selection measures in this call
3299 p = (wxPGProperty*) NULL;
3300 }
3301 else
3302 {
3303 // Is it the same?
3304 if ( m_selected == p && !(flags & wxPG_SEL_FORCE) )
3305 {
3306 // Only set focus if not deselecting
3307 if ( p )
3308 {
3309 if ( flags & wxPG_SEL_FOCUS )
3310 {
3311 if ( m_wndEditor )
3312 {
3313 m_wndEditor->SetFocus();
3314 m_editorFocused = 1;
3315 }
3316 }
3317 else
3318 {
3319 SetFocusOnCanvas();
3320 }
3321 }
3322
3323 m_inDoSelectProperty = 0;
3324 return true;
3325 }
3326
3327 //
3328 // First, deactivate previous
3329 if ( m_selected )
3330 {
3331
3332 OnValidationFailureReset(m_selected);
3333
3334 // Must double-check if this is an selected in case of forceswitch
3335 if ( p != prev )
3336 {
3337 if ( !CommitChangesFromEditor(flags) )
3338 {
3339 // Validation has failed, so we can't exit the previous editor
3340 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3341 // _("Invalid Value"),wxOK|wxICON_ERROR);
3342 m_inDoSelectProperty = 0;
3343 return false;
3344 }
3345 }
3346
3347 FreeEditors();
3348 m_selColumn = -1;
3349
3350 m_selected = (wxPGProperty*) NULL;
3351 m_pState->m_selected = (wxPGProperty*) NULL;
3352
3353 // We need to always fully refresh the grid here
3354 Refresh(false);
3355
3356 m_iFlags &= ~(wxPG_FL_ABNORMAL_EDITOR);
3357 EditorsValueWasNotModified();
3358 }
3359
3360 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY);
3361
3362 //
3363 // Then, activate the one given.
3364 if ( p )
3365 {
3366 int propY = p->GetY2(m_lineHeight);
3367
3368 int splitterX = GetSplitterPosition();
3369 m_editorFocused = 0;
3370 m_selected = p;
3371 m_pState->m_selected = p;
3372 m_iFlags |= wxPG_FL_PRIMARY_FILLS_ENTIRE;
3373 if ( p != prev )
3374 m_iFlags &= ~(wxPG_FL_VALIDATION_FAILED);
3375
3376 wxASSERT( m_wndEditor == (wxWindow*) NULL );
3377
3378 //
3379 // Only create editor for non-disabled non-caption
3380 if ( !p->IsCategory() && !(p->m_flags & wxPG_PROP_DISABLED) )
3381 {
3382 // do this for non-caption items
3383
3384 m_selColumn = 1;
3385
3386 // Do we need to paint the custom image, if any?
3387 m_iFlags &= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE);
3388 if ( (p->m_flags & wxPG_PROP_CUSTOMIMAGE) &&
3389 !p->GetEditorClass()->CanContainCustomImage()
3390 )
3391 m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3392
3393 wxRect grect = GetEditorWidgetRect(p, m_selColumn);
3394 wxPoint goodPos = grect.GetPosition();
3395 #if wxPG_CREATE_CONTROLS_HIDDEN
3396 int coord_adjust = m_height - goodPos.y;
3397 goodPos.y += coord_adjust;
3398 #endif
3399
3400 const wxPGEditor* editor = p->GetEditorClass();
3401 wxCHECK_MSG(editor, false,
3402 wxT("NULL editor class not allowed"));
3403
3404 m_iFlags &= ~wxPG_FL_FIXED_WIDTH_EDITOR;
3405
3406 wxPGWindowList wndList = editor->CreateControls(this,
3407 p,
3408 goodPos,
3409 grect.GetSize());
3410
3411 m_wndEditor = wndList.m_primary;
3412 m_wndEditor2 = wndList.m_secondary;
3413 wxWindow* primaryCtrl = GetEditorControl();
3414
3415 //
3416 // Essentially, primaryCtrl == m_wndEditor
3417 //
3418
3419 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3420 // value is drawn as normal, and m_wndEditor2 is assumed
3421 // to be a right-aligned button that triggers a separate editorCtrl
3422 // window.
3423
3424 if ( m_wndEditor )
3425 {
3426 wxASSERT_MSG( m_wndEditor->GetParent() == GetPanel(),
3427 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3428
3429 // Set validator, if any
3430 #if wxUSE_VALIDATORS
3431 wxValidator* validator = p->GetValidator();
3432 if ( validator )
3433 primaryCtrl->SetValidator(*validator);
3434 #endif
3435
3436 if ( m_wndEditor->GetSize().y > (m_lineHeight+6) )
3437 m_iFlags |= wxPG_FL_ABNORMAL_EDITOR;
3438
3439 // If it has modified status, use bold font
3440 // (must be done before capturing m_ctrlXAdjust)
3441 if ( (p->m_flags & wxPG_PROP_MODIFIED) && (m_windowStyle & wxPG_BOLD_MODIFIED) )
3442 SetCurControlBoldFont();
3443
3444 //
3445 // Fix TextCtrl indentation
3446 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3447 wxTextCtrl* tc = NULL;
3448 if ( primaryCtrl->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)) )
3449 tc = ((wxOwnerDrawnComboBox*)primaryCtrl)->GetTextCtrl();
3450 else
3451 tc = wxDynamicCast(primaryCtrl, wxTextCtrl);
3452 if ( tc )
3453 ::SendMessage(GetHwndOf(tc), EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0, 0));
3454 #endif
3455
3456 // Store x relative to splitter (we'll need it).
3457 m_ctrlXAdjust = m_wndEditor->GetPosition().x - splitterX;
3458
3459 // Check if background clear is not necessary
3460 wxPoint pos = m_wndEditor->GetPosition();
3461 if ( pos.x > (splitterX+1) || pos.y > propY )
3462 {
3463 m_iFlags &= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE);
3464 }
3465
3466 m_wndEditor->SetSizeHints(3, 3);
3467
3468 #if wxPG_CREATE_CONTROLS_HIDDEN
3469 m_wndEditor->Show(false);
3470 m_wndEditor->Freeze();
3471
3472 goodPos = m_wndEditor->GetPosition();
3473 goodPos.y -= coord_adjust;
3474 m_wndEditor->Move( goodPos );
3475 #endif
3476
3477 SetupChildEventHandling(primaryCtrl);
3478
3479 // Focus and select all (wxTextCtrl, wxComboBox etc)
3480 if ( flags & wxPG_SEL_FOCUS )
3481 {
3482 primaryCtrl->SetFocus();
3483
3484 p->GetEditorClass()->OnFocus(p, primaryCtrl);
3485 }
3486 }
3487
3488 if ( m_wndEditor2 )
3489 {
3490 wxASSERT_MSG( m_wndEditor2->GetParent() == GetPanel(),
3491 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3492
3493 // Get proper id for wndSecondary
3494 m_wndSecId = m_wndEditor2->GetId();
3495 wxWindowList children = m_wndEditor2->GetChildren();
3496 wxWindowList::iterator node = children.begin();
3497 if ( node != children.end() )
3498 m_wndSecId = ((wxWindow*)*node)->GetId();
3499
3500 m_wndEditor2->SetSizeHints(3,3);
3501
3502 #if wxPG_CREATE_CONTROLS_HIDDEN
3503 wxRect sec_rect = m_wndEditor2->GetRect();
3504 sec_rect.y -= coord_adjust;
3505
3506 // Fine tuning required to fix "oversized"
3507 // button disappearance bug.
3508 if ( sec_rect.y < 0 )
3509 {
3510 sec_rect.height += sec_rect.y;
3511 sec_rect.y = 0;
3512 }
3513 m_wndEditor2->SetSize( sec_rect );
3514 #endif
3515 m_wndEditor2->Show();
3516
3517 SetupChildEventHandling(m_wndEditor2);
3518
3519 // If no primary editor, focus to button to allow
3520 // it to interprete ENTER etc.
3521 // NOTE: Due to problems focusing away from it, this
3522 // has been disabled.
3523 /*
3524 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3525 m_wndEditor2->SetFocus();
3526 */
3527 }
3528
3529 if ( flags & wxPG_SEL_FOCUS )
3530 m_editorFocused = 1;
3531
3532 }
3533 else
3534 {
3535 // Make sure focus is in grid canvas (important for wxGTK, at least)
3536 SetFocusOnCanvas();
3537 }
3538
3539 EditorsValueWasNotModified();
3540
3541 // If it's inside collapsed section, expand parent, scroll, etc.
3542 // Also, if it was partially visible, scroll it into view.
3543 if ( !(flags & wxPG_SEL_NONVISIBLE) )
3544 EnsureVisible( p );
3545
3546 if ( m_wndEditor )
3547 {
3548 #if wxPG_CREATE_CONTROLS_HIDDEN
3549 m_wndEditor->Thaw();
3550 #endif
3551 m_wndEditor->Show(true);
3552 }
3553
3554 DrawItems(p, p);
3555 }
3556 else
3557 {
3558 // Make sure focus is in grid canvas
3559 SetFocusOnCanvas();
3560 }
3561
3562 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY);
3563 }
3564
3565 #if wxUSE_STATUSBAR
3566
3567 //
3568 // Show help text in status bar.
3569 // (if found and grid not embedded in manager with help box and
3570 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3571 //
3572
3573 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS) )
3574 {
3575 wxStatusBar* statusbar = (wxStatusBar*) NULL;
3576 if ( !(m_iFlags & wxPG_FL_NOSTATUSBARHELP) )
3577 {
3578 wxFrame* frame = wxDynamicCast(::wxGetTopLevelParent(this),wxFrame);
3579 if ( frame )
3580 statusbar = frame->GetStatusBar();
3581 }
3582
3583 if ( statusbar )
3584 {
3585 const wxString* pHelpString = (const wxString*) NULL;
3586
3587 if ( p )
3588 {
3589 pHelpString = &p->GetHelpString();
3590 if ( pHelpString->length() )
3591 {
3592 // Set help box text.
3593 statusbar->SetStatusText( *pHelpString );
3594 m_iFlags |= wxPG_FL_STRING_IN_STATUSBAR;
3595 }
3596 }
3597
3598 if ( (!pHelpString || !pHelpString->length()) &&
3599 (m_iFlags & wxPG_FL_STRING_IN_STATUSBAR) )
3600 {
3601 // Clear help box - but only if it was written
3602 // by us at previous time.
3603 statusbar->SetStatusText( m_emptyString );
3604 m_iFlags &= ~(wxPG_FL_STRING_IN_STATUSBAR);
3605 }
3606 }
3607 }
3608 #endif
3609
3610 m_inDoSelectProperty = 0;
3611
3612 // call wx event handler (here so that it also occurs on deselection)
3613 SendEvent( wxEVT_PG_SELECTED, m_selected, NULL, flags );
3614
3615 return true;
3616 }
3617
3618 // -----------------------------------------------------------------------
3619
3620 bool wxPropertyGrid::UnfocusEditor()
3621 {
3622 if ( !m_selected || !m_wndEditor || m_frozen )
3623 return true;
3624
3625 if ( !CommitChangesFromEditor(0) )
3626 return false;
3627
3628 SetFocusOnCanvas();
3629 DrawItem(m_selected);
3630
3631 return true;
3632 }
3633
3634 // -----------------------------------------------------------------------
3635
3636 void wxPropertyGrid::RefreshEditor()
3637 {
3638 wxPGProperty* p = m_selected;
3639 if ( !p )
3640 return;
3641
3642 wxWindow* wnd = GetEditorControl();
3643 if ( !wnd )
3644 return;
3645
3646 // Set editor font boldness - must do this before
3647 // calling UpdateControl().
3648 if ( HasFlag(wxPG_BOLD_MODIFIED) )
3649 {
3650 if ( p->HasFlag(wxPG_PROP_MODIFIED) )
3651 wnd->SetFont(GetCaptionFont());
3652 else
3653 wnd->SetFont(GetFont());
3654 }
3655
3656 p->GetEditorClass()->UpdateControl(p, wnd);
3657 }
3658
3659 // -----------------------------------------------------------------------
3660
3661 // This method is not inline because it called dozens of times
3662 // (i.e. two-arg function calls create smaller code size).
3663 bool wxPropertyGrid::DoClearSelection()
3664 {
3665 return DoSelectProperty((wxPGProperty*)NULL);
3666 }
3667
3668 // -----------------------------------------------------------------------
3669 // wxPropertyGrid expand/collapse state
3670 // -----------------------------------------------------------------------
3671
3672 bool wxPropertyGrid::DoCollapse( wxPGProperty* p, bool sendEvents )
3673 {
3674 wxPGProperty* pwc = wxStaticCast(p, wxPGProperty);
3675
3676 // If active editor was inside collapsed section, then disable it
3677 if ( m_selected && m_selected->IsSomeParent(p) )
3678 {
3679 ClearSelection(false);
3680 }
3681
3682 // Store dont-center-splitter flag 'cause we need to temporarily set it
3683 wxUint32 old_flag = m_iFlags & wxPG_FL_DONT_CENTER_SPLITTER;
3684 m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER;
3685
3686 bool res = m_pState->DoCollapse(pwc);
3687
3688 if ( res )
3689 {
3690 if ( sendEvents )
3691 SendEvent( wxEVT_PG_ITEM_COLLAPSED, p );
3692
3693 RecalculateVirtualSize();
3694
3695 // Redraw etc. only if collapsed was visible.
3696 if (pwc->IsVisible() &&
3697 !m_frozen &&
3698 ( !pwc->IsCategory() || !(m_windowStyle & wxPG_HIDE_CATEGORIES) ) )
3699 {
3700 // When item is collapsed so that scrollbar would move,
3701 // graphics mess is about (unless we redraw everything).
3702 Refresh();
3703 }
3704 }
3705
3706 // Clear dont-center-splitter flag if it wasn't set
3707 m_iFlags = (m_iFlags & ~wxPG_FL_DONT_CENTER_SPLITTER) | old_flag;
3708
3709 return res;
3710 }
3711
3712 // -----------------------------------------------------------------------
3713
3714 bool wxPropertyGrid::DoExpand( wxPGProperty* p, bool sendEvents )
3715 {
3716 wxCHECK_MSG( p, false, wxT("invalid property id") );
3717
3718 wxPGProperty* pwc = (wxPGProperty*)p;
3719
3720 // Store dont-center-splitter flag 'cause we need to temporarily set it
3721 wxUint32 old_flag = m_iFlags & wxPG_FL_DONT_CENTER_SPLITTER;
3722 m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER;
3723
3724 bool res = m_pState->DoExpand(pwc);
3725
3726 if ( res )
3727 {
3728 if ( sendEvents )
3729 SendEvent( wxEVT_PG_ITEM_EXPANDED, p );
3730
3731 RecalculateVirtualSize();
3732
3733 // Redraw etc. only if expanded was visible.
3734 if ( pwc->IsVisible() && !m_frozen &&
3735 ( !pwc->IsCategory() || !(m_windowStyle & wxPG_HIDE_CATEGORIES) )
3736 )
3737 {
3738 // Redraw
3739 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3740 Refresh();
3741 #else
3742 DrawItems(pwc, NULL);
3743 #endif
3744 }
3745 }
3746
3747 // Clear dont-center-splitter flag if it wasn't set
3748 m_iFlags = (m_iFlags & ~wxPG_FL_DONT_CENTER_SPLITTER) | old_flag;
3749
3750 return res;
3751 }
3752
3753 // -----------------------------------------------------------------------
3754
3755 bool wxPropertyGrid::DoHideProperty( wxPGProperty* p, bool hide, int flags )
3756 {
3757 if ( m_frozen )
3758 return m_pState->DoHideProperty(p, hide, flags);
3759
3760 if ( m_selected &&
3761 ( m_selected == p || m_selected->IsSomeParent(p) )
3762 )
3763 {
3764 ClearSelection(false);
3765 }
3766
3767 m_pState->DoHideProperty(p, hide, flags);
3768
3769 RecalculateVirtualSize();
3770 Refresh();
3771
3772 return true;
3773 }
3774
3775
3776 // -----------------------------------------------------------------------
3777 // wxPropertyGrid size related methods
3778 // -----------------------------------------------------------------------
3779
3780 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos )
3781 {
3782 if ( (m_iFlags & wxPG_FL_RECALCULATING_VIRTUAL_SIZE) || m_frozen )
3783 return;
3784
3785 //
3786 // If virtual height was changed, then recalculate editor control position(s)
3787 if ( m_pState->m_vhCalcPending )
3788 CorrectEditorWidgetPosY();
3789
3790 m_pState->EnsureVirtualHeight();
3791
3792 #ifdef __WXDEBUG__
3793 int by1 = m_pState->GetVirtualHeight();
3794 int by2 = m_pState->GetActualVirtualHeight();
3795 if ( by1 != by2 )
3796 {
3797 wxString s = wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1, by2);
3798 wxFAIL_MSG(s.c_str());
3799 wxLogDebug(s);
3800 }
3801 #endif
3802
3803 m_iFlags |= wxPG_FL_RECALCULATING_VIRTUAL_SIZE;
3804
3805 int x = m_pState->m_width;
3806 int y = m_pState->m_virtualHeight;
3807
3808 int width, height;
3809 GetClientSize(&width,&height);
3810
3811 // Now adjust virtual size.
3812 SetVirtualSize(x, y);
3813
3814 int xAmount = 0;
3815 int xPos = 0;
3816
3817 //
3818 // Adjust scrollbars
3819 if ( HasVirtualWidth() )
3820 {
3821 xAmount = x/wxPG_PIXELS_PER_UNIT;
3822 xPos = GetScrollPos( wxHORIZONTAL );
3823 }
3824
3825 if ( forceXPos != -1 )
3826 xPos = forceXPos;
3827 // xPos too high?
3828 else if ( xPos > (xAmount-(width/wxPG_PIXELS_PER_UNIT)) )
3829 xPos = 0;
3830
3831 int yAmount = (y+wxPG_PIXELS_PER_UNIT+2)/wxPG_PIXELS_PER_UNIT;
3832 int yPos = GetScrollPos( wxVERTICAL );
3833
3834 SetScrollbars( wxPG_PIXELS_PER_UNIT, wxPG_PIXELS_PER_UNIT,
3835 xAmount, yAmount, xPos, yPos, true );
3836
3837 // Must re-get size now
3838 GetClientSize(&width,&height);
3839
3840 if ( !HasVirtualWidth() )
3841 {
3842 m_pState->SetVirtualWidth(width);
3843 x = width;
3844 }
3845
3846 m_width = width;
3847 m_height = height;
3848
3849 m_canvas->SetSize( x, y );
3850
3851 m_pState->CheckColumnWidths();
3852
3853 if ( m_selected )
3854 CorrectEditorWidgetSizeX();
3855
3856 m_iFlags &= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE;
3857 }
3858
3859 // -----------------------------------------------------------------------
3860
3861 void wxPropertyGrid::OnResize( wxSizeEvent& event )
3862 {
3863 if ( !(m_iFlags & wxPG_FL_INITIALIZED) )
3864 return;
3865
3866 int width, height;
3867 GetClientSize(&width,&height);
3868
3869 m_width = width;
3870 m_height = height;
3871
3872 #if wxPG_DOUBLE_BUFFER
3873 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING) )
3874 {
3875 int dblh = (m_lineHeight*2);
3876 if ( !m_doubleBuffer )
3877 {
3878 // Create double buffer bitmap to draw on, if none
3879 int w = (width>250)?width:250;
3880 int h = height + dblh;
3881 h = (h>400)?h:400;
3882 m_doubleBuffer = new wxBitmap( w, h );
3883 }
3884 else
3885 {
3886 int w = m_doubleBuffer->GetWidth();
3887 int h = m_doubleBuffer->GetHeight();
3888
3889 // Double buffer must be large enough
3890 if ( w < width || h < (height+dblh) )
3891 {
3892 if ( w < width ) w = width;
3893 if ( h < (height+dblh) ) h = height + dblh;
3894 delete m_doubleBuffer;
3895 m_doubleBuffer = new wxBitmap( w, h );
3896 }
3897 }
3898 }
3899
3900 #endif
3901
3902 m_pState->OnClientWidthChange( width, event.GetSize().x - m_ncWidth, true );
3903 m_ncWidth = event.GetSize().x;
3904
3905 if ( !m_frozen )
3906 {
3907 if ( m_pState->m_itemsAdded )
3908 PrepareAfterItemsAdded();
3909 else
3910 // Without this, virtual size (atleast under wxGTK) will be skewed
3911 RecalculateVirtualSize();
3912
3913 Refresh();
3914 }
3915 }
3916
3917 // -----------------------------------------------------------------------
3918
3919 void wxPropertyGrid::SetVirtualWidth( int width )
3920 {
3921 if ( width == -1 )
3922 {
3923 // Disable virtual width
3924 width = GetClientSize().x;
3925 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH);
3926 }
3927 else
3928 {
3929 // Enable virtual width
3930 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH);
3931 }
3932 m_pState->SetVirtualWidth( width );
3933 }
3934
3935 void wxPropertyGrid::SetFocusOnCanvas()
3936 {
3937 m_canvas->SetFocusIgnoringChildren();
3938 m_editorFocused = 0;
3939 }
3940
3941 // -----------------------------------------------------------------------
3942 // wxPropertyGrid mouse event handling
3943 // -----------------------------------------------------------------------
3944
3945 // selFlags uses same values DoSelectProperty's flags
3946 // Returns true if event was vetoed.
3947 bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p, wxVariant* pValue, unsigned int WXUNUSED(selFlags) )
3948 {
3949 // Send property grid event of specific type and with specific property
3950 wxPropertyGridEvent evt( eventType, m_eventObject->GetId() );
3951 evt.SetPropertyGrid(this);
3952 evt.SetEventObject(m_eventObject);
3953 evt.SetProperty(p);
3954 if ( pValue )
3955 {
3956 evt.SetCanVeto(true);
3957 evt.SetupValidationInfo();
3958 m_validationInfo.m_pValue = pValue;
3959 }
3960 wxEvtHandler* evtHandler = m_eventObject->GetEventHandler();
3961
3962 evtHandler->ProcessEvent(evt);
3963
3964 return evt.WasVetoed();
3965 }
3966
3967 // -----------------------------------------------------------------------
3968
3969 // Return false if should be skipped
3970 bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &event )
3971 {
3972 bool res = true;
3973
3974 // Need to set focus?
3975 if ( !(m_iFlags & wxPG_FL_FOCUSED) )
3976 {
3977 SetFocusOnCanvas();
3978 }
3979
3980 wxPropertyGridPageState* state = m_pState;
3981 int splitterHit;
3982 int splitterHitOffset;
3983 int columnHit = state->HitTestH( x, &splitterHit, &splitterHitOffset );
3984
3985 wxPGProperty* p = DoGetItemAtY(y);
3986
3987 if ( p )
3988 {
3989 int depth = (int)p->GetDepth() - 1;
3990
3991 int marginEnds = m_marginWidth + ( depth * m_subgroup_extramargin );
3992
3993 if ( x >= marginEnds )
3994 {
3995 // Outside margin.
3996
3997 if ( p->IsCategory() )
3998 {
3999 // This is category.
4000 wxPropertyCategory* pwc = (wxPropertyCategory*)p;
4001
4002 int textX = m_marginWidth + ((unsigned int)((pwc->m_depth-1)*m_subgroup_extramargin));
4003
4004 // Expand, collapse, activate etc. if click on text or left of splitter.
4005 if ( x >= textX
4006 &&
4007 ( x < (textX+pwc->GetTextExtent(this, m_captionFont)+(wxPG_CAPRECTXMARGIN*2)) ||
4008 columnHit == 0
4009 )
4010 )
4011 {
4012 if ( !DoSelectProperty( p ) )
4013 return res;
4014
4015 // On double-click, expand/collapse.
4016 if ( event.ButtonDClick() && !(m_windowStyle & wxPG_HIDE_MARGIN) )
4017 {
4018 if ( pwc->IsExpanded() ) DoCollapse( p, true );
4019 else DoExpand( p, true );
4020 }
4021 }
4022 }
4023 else if ( splitterHit == -1 )
4024 {
4025 // Click on value.
4026 unsigned int selFlag = 0;
4027 if ( columnHit == 1 )
4028 {
4029 m_iFlags |= wxPG_FL_ACTIVATION_BY_CLICK;
4030 selFlag = wxPG_SEL_FOCUS;
4031 }
4032 if ( !DoSelectProperty( p, selFlag ) )
4033 return res;
4034
4035 m_iFlags &= ~(wxPG_FL_ACTIVATION_BY_CLICK);
4036
4037 if ( p->GetChildCount() && !p->IsCategory() )
4038 // On double-click, expand/collapse.
4039 if ( event.ButtonDClick() && !(m_windowStyle & wxPG_HIDE_MARGIN) )
4040 {
4041 wxPGProperty* pwc = (wxPGProperty*)p;
4042 if ( pwc->IsExpanded() ) DoCollapse( p, true );
4043 else DoExpand( p, true );
4044 }
4045
4046 res = false;
4047 }
4048 else
4049 {
4050 // click on splitter
4051 if ( !(m_windowStyle & wxPG_STATIC_SPLITTER) )
4052 {
4053 if ( event.GetEventType() == wxEVT_LEFT_DCLICK )
4054 {
4055 // Double-clicking the splitter causes auto-centering
4056 CenterSplitter( true );
4057 }
4058 else if ( m_dragStatus == 0 )
4059 {
4060 //
4061 // Begin draggin the splitter
4062 //
4063 if ( m_wndEditor )
4064 {
4065 // Changes must be committed here or the
4066 // value won't be drawn correctly
4067 if ( !CommitChangesFromEditor() )
4068 return res;
4069
4070 m_wndEditor->Show ( false );
4071 }
4072
4073 if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) )
4074 {
4075 m_canvas->CaptureMouse();
4076 m_iFlags |= wxPG_FL_MOUSE_CAPTURED;
4077 }
4078
4079 m_dragStatus = 1;
4080 m_draggedSplitter = splitterHit;
4081 m_dragOffset = splitterHitOffset;
4082
4083 wxClientDC dc(m_canvas);
4084
4085 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4086 // Fixes button disappearance bug
4087 if ( m_wndEditor2 )
4088 m_wndEditor2->Show ( false );
4089 #endif
4090
4091 m_startingSplitterX = x - splitterHitOffset;
4092 }
4093 }
4094 }
4095 }
4096 else
4097 {
4098 // Click on margin.
4099 if ( p->GetChildCount() )
4100 {
4101 int nx = x + m_marginWidth - marginEnds; // Normalize x.
4102
4103 if ( (nx >= m_gutterWidth && nx < (m_gutterWidth+m_iconWidth)) )
4104 {
4105 int y2 = y % m_lineHeight;
4106 if ( (y2 >= m_buttonSpacingY && y2 < (m_buttonSpacingY+m_iconHeight)) )
4107 {
4108 // On click on expander button, expand/collapse
4109 if ( ((wxPGProperty*)p)->IsExpanded() )
4110 DoCollapse( p, true );
4111 else
4112 DoExpand( p, true );
4113 }
4114 }
4115 }
4116 }
4117 }
4118 return res;
4119 }
4120
4121 // -----------------------------------------------------------------------
4122
4123 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x), unsigned int WXUNUSED(y),
4124 wxMouseEvent& WXUNUSED(event) )
4125 {
4126 if ( m_propHover )
4127 {
4128 // Select property here as well
4129 wxPGProperty* p = m_propHover;
4130 if ( p != m_selected )
4131 DoSelectProperty( p );
4132
4133 // Send right click event.
4134 SendEvent( wxEVT_PG_RIGHT_CLICK, p );
4135
4136 return true;
4137 }
4138 return false;
4139 }
4140
4141 // -----------------------------------------------------------------------
4142
4143 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x), unsigned int WXUNUSED(y),
4144 wxMouseEvent& WXUNUSED(event) )
4145 {
4146 if ( m_propHover )
4147 {
4148 // Select property here as well
4149 wxPGProperty* p = m_propHover;
4150
4151 if ( p != m_selected )
4152 DoSelectProperty( p );
4153
4154 // Send double-click event.
4155 SendEvent( wxEVT_PG_DOUBLE_CLICK, m_propHover );
4156
4157 return true;
4158 }
4159 return false;
4160 }
4161
4162 // -----------------------------------------------------------------------
4163
4164 #if wxPG_SUPPORT_TOOLTIPS
4165
4166 void wxPropertyGrid::SetToolTip( const wxString& tipString )
4167 {
4168 if ( tipString.length() )
4169 {
4170 m_canvas->SetToolTip(tipString);
4171 }
4172 else
4173 {
4174 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4175 m_canvas->SetToolTip( m_emptyString );
4176 #else
4177 m_canvas->SetToolTip( NULL );
4178 #endif
4179 }
4180 }
4181
4182 #endif // #if wxPG_SUPPORT_TOOLTIPS
4183
4184 // -----------------------------------------------------------------------
4185
4186 // Return false if should be skipped
4187 bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y, wxMouseEvent &event )
4188 {
4189 // Safety check (needed because mouse capturing may
4190 // otherwise freeze the control)
4191 if ( m_dragStatus > 0 && !event.Dragging() )
4192 {
4193 HandleMouseUp(x,y,event);
4194 }
4195
4196 wxPropertyGridPageState* state = m_pState;
4197 int splitterHit;
4198 int splitterHitOffset;
4199 int columnHit = state->HitTestH( x, &splitterHit, &splitterHitOffset );
4200 int splitterX = x - splitterHitOffset;
4201
4202 if ( m_dragStatus > 0 )
4203 {
4204 if ( x > (m_marginWidth + wxPG_DRAG_MARGIN) &&
4205 x < (m_pState->m_width - wxPG_DRAG_MARGIN) )
4206 {
4207
4208 int newSplitterX = x - m_dragOffset;
4209 int splitterX = x - splitterHitOffset;
4210
4211 // Splitter redraw required?
4212 if ( newSplitterX != splitterX )
4213 {
4214 // Move everything
4215 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER);
4216 state->DoSetSplitterPosition( newSplitterX, m_draggedSplitter, false );
4217 state->m_fSplitterX = (float) newSplitterX;
4218
4219 if ( m_selected )
4220 CorrectEditorWidgetSizeX();
4221
4222 Update();
4223 Refresh();
4224 }
4225
4226 m_dragStatus = 2;
4227 }
4228
4229 return false;
4230 }
4231 else
4232 {
4233
4234 int ih = m_lineHeight;
4235 int sy = y;
4236
4237 #if wxPG_SUPPORT_TOOLTIPS
4238 wxPGProperty* prevHover = m_propHover;
4239 unsigned char prevSide = m_mouseSide;
4240 #endif
4241 int curPropHoverY = y - (y % ih);
4242
4243 // On which item it hovers
4244 if ( !m_propHover
4245 ||
4246 ( sy < m_propHoverY || sy >= (m_propHoverY+ih) )
4247 )
4248 {
4249 // Mouse moves on another property
4250
4251 m_propHover = DoGetItemAtY(y);
4252 m_propHoverY = curPropHoverY;
4253
4254 // Send hover event
4255 SendEvent( wxEVT_PG_HIGHLIGHTED, m_propHover );
4256 }
4257
4258 #if wxPG_SUPPORT_TOOLTIPS
4259 // Store which side we are on
4260 m_mouseSide = 0;
4261 if ( columnHit == 1 )
4262 m_mouseSide = 2;
4263 else if ( columnHit == 0 )
4264 m_mouseSide = 1;
4265
4266 //
4267 // If tooltips are enabled, show label or value as a tip
4268 // in case it doesn't otherwise show in full length.
4269 //
4270 if ( m_windowStyle & wxPG_TOOLTIPS )
4271 {
4272 wxToolTip* tooltip = m_canvas->GetToolTip();
4273
4274 if ( m_propHover != prevHover || prevSide != m_mouseSide )
4275 {
4276 if ( m_propHover && !m_propHover->IsCategory() )
4277 {
4278
4279 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS )
4280 {
4281 // Show help string as a tooltip
4282 wxString tipString = m_propHover->GetHelpString();
4283
4284 SetToolTip(tipString);
4285 }
4286 else
4287 {
4288 // Show cropped value string as a tooltip
4289 wxString tipString;
4290 int space = 0;
4291
4292 if ( m_mouseSide == 1 )
4293 {
4294 tipString = m_propHover->m_label;
4295 space = splitterX-m_marginWidth-3;
4296 }
4297 else if ( m_mouseSide == 2 )
4298 {
4299 tipString = m_propHover->GetDisplayedString();
4300
4301 space = m_width - splitterX;
4302 if ( m_propHover->m_flags & wxPG_PROP_CUSTOMIMAGE )
4303 space -= wxPG_CUSTOM_IMAGE_WIDTH + wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
4304 }
4305
4306 if ( space )
4307 {
4308 int tw, th;
4309 GetTextExtent( tipString, &tw, &th, 0, 0, &m_font );
4310 if ( tw > space )
4311 {
4312 SetToolTip( tipString );
4313 }
4314 }
4315 else
4316 {
4317 if ( tooltip )
4318 {
4319 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4320 m_canvas->SetToolTip( m_emptyString );
4321 #else
4322 m_canvas->SetToolTip( NULL );
4323 #endif
4324 }
4325 }
4326
4327 }
4328 }
4329 else
4330 {
4331 if ( tooltip )
4332 {
4333 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4334 m_canvas->SetToolTip( m_emptyString );
4335 #else
4336 m_canvas->SetToolTip( NULL );
4337 #endif
4338 }
4339 }
4340 }
4341 }
4342 #endif
4343
4344 if ( splitterHit == -1 ||
4345 !m_propHover ||
4346 HasFlag(wxPG_STATIC_SPLITTER) )
4347 {
4348 // hovering on something else
4349 if ( m_curcursor != wxCURSOR_ARROW )
4350 CustomSetCursor( wxCURSOR_ARROW );
4351 }
4352 else
4353 {
4354 // Do not allow splitter cursor on caption items.
4355 // (also not if we were dragging and its started
4356 // outside the splitter region)
4357
4358 if ( !m_propHover->IsCategory() &&
4359 !event.Dragging() )
4360 {
4361
4362 // hovering on splitter
4363
4364 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4365 // reliably detected.
4366 //if ( m_curcursor != wxCURSOR_SIZEWE )
4367 CustomSetCursor( wxCURSOR_SIZEWE, true );
4368
4369 return false;
4370 }
4371 else
4372 {
4373 // hovering on something else
4374 if ( m_curcursor != wxCURSOR_ARROW )
4375 CustomSetCursor( wxCURSOR_ARROW );
4376 }
4377 }
4378 }
4379 return true;
4380 }
4381
4382 // -----------------------------------------------------------------------
4383
4384 // Also handles Leaving event
4385 bool wxPropertyGrid::HandleMouseUp( int x, unsigned int WXUNUSED(y),
4386 wxMouseEvent &WXUNUSED(event) )
4387 {
4388 wxPropertyGridPageState* state = m_pState;
4389 bool res = false;
4390
4391 int splitterHit;
4392 int splitterHitOffset;
4393 state->HitTestH( x, &splitterHit, &splitterHitOffset );
4394
4395 // No event type check - basicly calling this method should
4396 // just stop dragging.
4397 // Left up after dragged?
4398 if ( m_dragStatus >= 1 )
4399 {
4400 //
4401 // End Splitter Dragging
4402 //
4403 // DO NOT ENABLE FOLLOWING LINE!
4404 // (it is only here as a reminder to not to do it)
4405 //splitterX = x;
4406
4407 // Disable splitter auto-centering
4408 m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER;
4409
4410 // This is necessary to return cursor
4411 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
4412 {
4413 m_canvas->ReleaseMouse();
4414 m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED);
4415 }
4416
4417 // Set back the default cursor, if necessary
4418 if ( splitterHit == -1 ||
4419 !m_propHover )
4420 {
4421 CustomSetCursor( wxCURSOR_ARROW );
4422 }
4423
4424 m_dragStatus = 0;
4425
4426 // Control background needs to be cleared
4427 if ( !(m_iFlags & wxPG_FL_PRIMARY_FILLS_ENTIRE) && m_selected )
4428 DrawItem( m_selected );
4429
4430 if ( m_wndEditor )
4431 {
4432 m_wndEditor->Show ( true );
4433 }
4434
4435 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4436 // Fixes button disappearance bug
4437 if ( m_wndEditor2 )
4438 m_wndEditor2->Show ( true );
4439 #endif
4440
4441 // This clears the focus.
4442 m_editorFocused = 0;
4443
4444 }
4445 return res;
4446 }
4447
4448 // -----------------------------------------------------------------------
4449
4450 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent& event, int* px, int* py )
4451 {
4452 int splitterX = GetSplitterPosition();
4453
4454 //int ux, uy;
4455 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4456 int ux = event.m_x;
4457 int uy = event.m_y;
4458
4459 wxWindow* wnd = GetEditorControl();
4460
4461 // Hide popup on clicks
4462 if ( event.GetEventType() != wxEVT_MOTION )
4463 if ( wnd && wnd->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)) )
4464 {
4465 ((wxOwnerDrawnComboBox*)wnd)->HidePopup();
4466 }
4467
4468 wxRect r;
4469 if ( wnd )
4470 r = wnd->GetRect();
4471 if ( wnd == (wxWindow*) NULL || m_dragStatus ||
4472 (
4473 ux <= (splitterX + wxPG_SPLITTERX_DETECTMARGIN2) ||
4474 ux >= (r.x+r.width) ||
4475 event.m_y < r.y ||
4476 event.m_y >= (r.y+r.height)
4477 )
4478 )
4479 {
4480 *px = ux;
4481 *py = uy;
4482 return true;
4483 }
4484 else
4485 {
4486 if ( m_curcursor != wxCURSOR_ARROW ) CustomSetCursor ( wxCURSOR_ARROW );
4487 }
4488 return false;
4489 }
4490
4491 // -----------------------------------------------------------------------
4492
4493 void wxPropertyGrid::OnMouseClick( wxMouseEvent &event )
4494 {
4495 int x, y;
4496 if ( OnMouseCommon( event, &x, &y ) )
4497 {
4498 HandleMouseClick(x,y,event);
4499 }
4500 event.Skip();
4501 }
4502
4503 // -----------------------------------------------------------------------
4504
4505 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent &event )
4506 {
4507 int x, y;
4508 CalcUnscrolledPosition( event.m_x, event.m_y, &x, &y );
4509 HandleMouseRightClick(x,y,event);
4510 event.Skip();
4511 }
4512
4513 // -----------------------------------------------------------------------
4514
4515 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent &event )
4516 {
4517 // Always run standard mouse-down handler as well
4518 OnMouseClick(event);
4519
4520 int x, y;
4521 CalcUnscrolledPosition( event.m_x, event.m_y, &x, &y );
4522 HandleMouseDoubleClick(x,y,event);
4523 event.Skip();
4524 }
4525
4526 // -----------------------------------------------------------------------
4527
4528 void wxPropertyGrid::OnMouseMove( wxMouseEvent &event )
4529 {
4530 int x, y;
4531 if ( OnMouseCommon( event, &x, &y ) )
4532 {
4533 HandleMouseMove(x,y,event);
4534 }
4535 event.Skip();
4536 }
4537
4538 // -----------------------------------------------------------------------
4539
4540 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent& WXUNUSED(event) )
4541 {
4542 // Called when mouse moves in the empty space below the properties.
4543 CustomSetCursor( wxCURSOR_ARROW );
4544 }
4545
4546 // -----------------------------------------------------------------------
4547
4548 void wxPropertyGrid::OnMouseUp( wxMouseEvent &event )
4549 {
4550 int x, y;
4551 if ( OnMouseCommon( event, &x, &y ) )
4552 {
4553 HandleMouseUp(x,y,event);
4554 }
4555 event.Skip();
4556 }
4557
4558 // -----------------------------------------------------------------------
4559
4560 void wxPropertyGrid::OnMouseEntry( wxMouseEvent &event )
4561 {
4562 // This may get called from child control as well, so event's
4563 // mouse position cannot be relied on.
4564
4565 if ( event.Entering() )
4566 {
4567 if ( !(m_iFlags & wxPG_FL_MOUSE_INSIDE) )
4568 {
4569 // TODO: Fix this (detect parent and only do
4570 // cursor trick if it is a manager).
4571 wxASSERT( GetParent() );
4572 GetParent()->SetCursor(wxNullCursor);
4573
4574 m_iFlags |= wxPG_FL_MOUSE_INSIDE;
4575 }
4576 else
4577 GetParent()->SetCursor(wxNullCursor);
4578 }
4579 else if ( event.Leaving() )
4580 {
4581 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4582 m_canvas->SetCursor( wxNullCursor );
4583
4584 // Get real cursor position
4585 wxPoint pt = ScreenToClient(::wxGetMousePosition());
4586
4587 if ( ( pt.x <= 0 || pt.y <= 0 || pt.x >= m_width || pt.y >= m_height ) )
4588 {
4589 {
4590 if ( (m_iFlags & wxPG_FL_MOUSE_INSIDE) )
4591 {
4592 m_iFlags &= ~(wxPG_FL_MOUSE_INSIDE);
4593 }
4594
4595 if ( m_dragStatus )
4596 wxPropertyGrid::HandleMouseUp ( -1, 10000, event );
4597 }
4598 }
4599 }
4600
4601 event.Skip();
4602 }
4603
4604 // -----------------------------------------------------------------------
4605
4606 // Common code used by various OnMouseXXXChild methods.
4607 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent &event, int* px, int *py )
4608 {
4609 wxWindow* topCtrlWnd = (wxWindow*)event.GetEventObject();
4610 wxASSERT( topCtrlWnd );
4611 int x, y;
4612 event.GetPosition(&x,&y);
4613
4614 int splitterX = GetSplitterPosition();
4615
4616 wxRect r = topCtrlWnd->GetRect();
4617 if ( !m_dragStatus &&
4618 x > (splitterX-r.x+wxPG_SPLITTERX_DETECTMARGIN2) &&
4619 y >= 0 && y < r.height \
4620 )
4621 {
4622 if ( m_curcursor != wxCURSOR_ARROW ) CustomSetCursor ( wxCURSOR_ARROW );
4623 event.Skip();
4624 }
4625 else
4626 {
4627 CalcUnscrolledPosition( event.m_x + r.x, event.m_y + r.y, \
4628 px, py );
4629 return true;
4630 }
4631 return false;
4632 }
4633
4634 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent &event )
4635 {
4636 int x,y;
4637 if ( OnMouseChildCommon(event,&x,&y) )
4638 {
4639 bool res = HandleMouseClick(x,y,event);
4640 if ( !res ) event.Skip();
4641 }
4642 }
4643
4644 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent &event )
4645 {
4646 int x,y;
4647 wxASSERT( m_wndEditor );
4648 // These coords may not be exact (about +-2),
4649 // but that should not matter (right click is about item, not position).
4650 wxPoint pt = m_wndEditor->GetPosition();
4651 CalcUnscrolledPosition( event.m_x + pt.x, event.m_y + pt.y, &x, &y );
4652 wxASSERT( m_selected );
4653 m_propHover = m_selected;
4654 bool res = HandleMouseRightClick(x,y,event);
4655 if ( !res ) event.Skip();
4656 }
4657
4658 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent &event )
4659 {
4660 int x,y;
4661 if ( OnMouseChildCommon(event,&x,&y) )
4662 {
4663 bool res = HandleMouseMove(x,y,event);
4664 if ( !res ) event.Skip();
4665 }
4666 }
4667
4668 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent &event )
4669 {
4670 int x,y;
4671 if ( OnMouseChildCommon(event,&x,&y) )
4672 {
4673 bool res = HandleMouseUp(x,y,event);
4674 if ( !res ) event.Skip();
4675 }
4676 }
4677
4678 // -----------------------------------------------------------------------
4679 // wxPropertyGrid keyboard event handling
4680 // -----------------------------------------------------------------------
4681
4682 int wxPropertyGrid::KeyEventToActions(wxKeyEvent &event, int* pSecond) const
4683 {
4684 // Translates wxKeyEvent to wxPG_ACTION_XXX
4685
4686 int keycode = event.GetKeyCode();
4687 int modifiers = event.GetModifiers();
4688
4689 wxASSERT( !(modifiers&~(0xFFFF)) );
4690
4691 int hashMapKey = (keycode & 0xFFFF) | ((modifiers & 0xFFFF) << 16);
4692
4693 wxPGHashMapI2I::const_iterator it = m_actionTriggers.find(hashMapKey);
4694
4695 if ( it == m_actionTriggers.end() )
4696 return 0;
4697
4698 if ( pSecond )
4699 {
4700 int second = (it->second>>16) & 0xFFFF;
4701 *pSecond = second;
4702 }
4703
4704 return (it->second & 0xFFFF);
4705 }
4706
4707 void wxPropertyGrid::AddActionTrigger( int action, int keycode, int modifiers )
4708 {
4709 wxASSERT( !(modifiers&~(0xFFFF)) );
4710
4711 int hashMapKey = (keycode & 0xFFFF) | ((modifiers & 0xFFFF) << 16);
4712
4713 wxPGHashMapI2I::iterator it = m_actionTriggers.find(hashMapKey);
4714
4715 if ( it != m_actionTriggers.end() )
4716 {
4717 // This key combination is already used
4718
4719 // Can add secondary?
4720 wxASSERT_MSG( !(it->second&~(0xFFFF)),
4721 wxT("You can only add up to two separate actions per key combination.") );
4722
4723 action = it->second | (action<<16);
4724 }
4725
4726 m_actionTriggers[hashMapKey] = action;
4727 }
4728
4729 void wxPropertyGrid::ClearActionTriggers( int action )
4730 {
4731 wxPGHashMapI2I::iterator it;
4732
4733 for ( it = m_actionTriggers.begin(); it != m_actionTriggers.end(); ++it )
4734 {
4735 if ( it->second == action )
4736 {
4737 m_actionTriggers.erase(it);
4738 }
4739 }
4740 }
4741
4742 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild )
4743 {
4744 //
4745 // Handles key event when editor control is not focused.
4746 //
4747
4748 wxCHECK2(!m_frozen, return);
4749
4750 // Travelsal between items, collapsing/expanding, etc.
4751 int keycode = event.GetKeyCode();
4752 bool editorFocused = IsEditorFocused();
4753
4754 if ( keycode == WXK_TAB )
4755 {
4756 wxWindow* mainControl;
4757
4758 if ( HasInternalFlag(wxPG_FL_IN_MANAGER) )
4759 mainControl = GetParent();
4760 else
4761 mainControl = this;
4762
4763 if ( !event.ShiftDown() )
4764 {
4765 if ( !editorFocused && m_wndEditor )
4766 {
4767 DoSelectProperty( m_selected, wxPG_SEL_FOCUS );
4768 }
4769 else
4770 {
4771 // Tab traversal workaround for platforms on which
4772 // wxWindow::Navigate() may navigate into first child
4773 // instead of next sibling. Does not work perfectly
4774 // in every scenario (for instance, when property grid
4775 // is either first or last control).
4776 #if defined(__WXGTK__)
4777 wxWindow* sibling = mainControl->GetNextSibling();
4778 if ( sibling )
4779 sibling->SetFocusFromKbd();
4780 #else
4781 Navigate(wxNavigationKeyEvent::IsForward);
4782 #endif
4783 }
4784 }
4785 else
4786 {
4787 if ( editorFocused )
4788 {
4789 UnfocusEditor();
4790 }
4791 else
4792 {
4793 #if defined(__WXGTK__)
4794 wxWindow* sibling = mainControl->GetPrevSibling();
4795 if ( sibling )
4796 sibling->SetFocusFromKbd();
4797 #else
4798 Navigate(wxNavigationKeyEvent::IsBackward);
4799 #endif
4800 }
4801 }
4802
4803 return;
4804 }
4805
4806 // Ignore Alt and Control when they are down alone
4807 if ( keycode == WXK_ALT ||
4808 keycode == WXK_CONTROL )
4809 {
4810 event.Skip();
4811 return;
4812 }
4813
4814 int secondAction;
4815 int action = KeyEventToActions(event, &secondAction);
4816
4817 if ( editorFocused && action == wxPG_ACTION_CANCEL_EDIT )
4818 {
4819 //
4820 // Esc cancels any changes
4821 if ( IsEditorsValueModified() )
4822 {
4823 EditorsValueWasNotModified();
4824
4825 // Update the control as well
4826 m_selected->GetEditorClass()->SetControlStringValue( m_selected,
4827 GetEditorControl(),
4828 m_selected->GetDisplayedString() );
4829 }
4830
4831 OnValidationFailureReset(m_selected);
4832
4833 UnfocusEditor();
4834 return;
4835 }
4836
4837 // Except for TAB and ESC, handle child control events in child control
4838 if ( fromChild )
4839 {
4840 event.Skip();
4841 return;
4842 }
4843
4844 bool wasHandled = false;
4845
4846 if ( m_selected )
4847 {
4848 // Show dialog?
4849 if ( ButtonTriggerKeyTest(action, event) )
4850 return;
4851
4852 wxPGProperty* p = m_selected;
4853
4854 // Travel and expand/collapse
4855 int selectDir = -2;
4856
4857 if ( p->GetChildCount() &&
4858 !(p->m_flags & wxPG_PROP_DISABLED)
4859 )
4860 {
4861 if ( action == wxPG_ACTION_COLLAPSE_PROPERTY || secondAction == wxPG_ACTION_COLLAPSE_PROPERTY )
4862 {
4863 if ( (m_windowStyle & wxPG_HIDE_MARGIN) || Collapse(p) )
4864 wasHandled = true;
4865 }
4866 else if ( action == wxPG_ACTION_EXPAND_PROPERTY || secondAction == wxPG_ACTION_EXPAND_PROPERTY )
4867 {
4868 if ( (m_windowStyle & wxPG_HIDE_MARGIN) || Expand(p) )
4869 wasHandled = true;
4870 }
4871 }
4872
4873 if ( !wasHandled )
4874 {
4875 if ( action == wxPG_ACTION_PREV_PROPERTY || secondAction == wxPG_ACTION_PREV_PROPERTY )
4876 {
4877 selectDir = -1;
4878 }
4879 else if ( action == wxPG_ACTION_NEXT_PROPERTY || secondAction == wxPG_ACTION_NEXT_PROPERTY )
4880 {
4881 selectDir = 1;
4882 }
4883 }
4884
4885 if ( selectDir >= -1 )
4886 {
4887 p = wxPropertyGridIterator::OneStep( m_pState, wxPG_ITERATE_VISIBLE, p, selectDir );
4888 if ( p )
4889 DoSelectProperty(p);
4890 wasHandled = true;
4891 }
4892 }
4893 else
4894 {
4895 // If nothing was selected, select the first item now
4896 // (or navigate out of tab).
4897 if ( action != wxPG_ACTION_CANCEL_EDIT && secondAction != wxPG_ACTION_CANCEL_EDIT )
4898 {
4899 wxPGProperty* p = wxPropertyGridInterface::GetFirst();
4900 if ( p ) DoSelectProperty(p);
4901 wasHandled = true;
4902 }
4903 }
4904
4905 if ( !wasHandled )
4906 event.Skip();
4907 }
4908
4909 // -----------------------------------------------------------------------
4910
4911 void wxPropertyGrid::OnKey( wxKeyEvent &event )
4912 {
4913 HandleKeyEvent(event, false);
4914 }
4915
4916 // -----------------------------------------------------------------------
4917
4918 bool wxPropertyGrid::ButtonTriggerKeyTest( int action, wxKeyEvent& event )
4919 {
4920 if ( action == -1 )
4921 {
4922 int secondAction;
4923 action = KeyEventToActions(event, &secondAction);
4924 }
4925
4926 // Does the keycode trigger button?
4927 if ( action == wxPG_ACTION_PRESS_BUTTON &&
4928 m_wndEditor2 )
4929 {
4930 wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, m_wndEditor2->GetId());
4931 GetEventHandler()->AddPendingEvent(evt);
4932 return true;
4933 }
4934
4935 return false;
4936 }
4937
4938 // -----------------------------------------------------------------------
4939
4940 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent &event )
4941 {
4942 HandleKeyEvent(event, true);
4943 }
4944
4945 // -----------------------------------------------------------------------
4946 // wxPropertyGrid miscellaneous event handling
4947 // -----------------------------------------------------------------------
4948
4949 void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) )
4950 {
4951 //
4952 // Check if the focus is in this control or one of its children
4953 wxWindow* newFocused = wxWindow::FindFocus();
4954
4955 if ( newFocused != m_curFocused )
4956 HandleFocusChange( newFocused );
4957 }
4958
4959 bool wxPropertyGrid::IsEditorFocused() const
4960 {
4961 wxWindow* focus = wxWindow::FindFocus();
4962
4963 if ( focus == m_wndEditor || focus == m_wndEditor2 ||
4964 focus == GetEditorControl() )
4965 return true;
4966
4967 return false;
4968 }
4969
4970 // Called by focus event handlers. newFocused is the window that becomes focused.
4971 void wxPropertyGrid::HandleFocusChange( wxWindow* newFocused )
4972 {
4973 unsigned int oldFlags = m_iFlags;
4974
4975 m_iFlags &= ~(wxPG_FL_FOCUSED);
4976
4977 wxWindow* parent = newFocused;
4978
4979 // This must be one of nextFocus' parents.
4980 while ( parent )
4981 {
4982 // Use m_eventObject, which is either wxPropertyGrid or
4983 // wxPropertyGridManager, as appropriate.
4984 if ( parent == m_eventObject )
4985 {
4986 m_iFlags |= wxPG_FL_FOCUSED;
4987 break;
4988 }
4989 parent = parent->GetParent();
4990 }
4991
4992 m_curFocused = newFocused;
4993
4994 if ( (m_iFlags & wxPG_FL_FOCUSED) !=
4995 (oldFlags & wxPG_FL_FOCUSED) )
4996 {
4997 if ( !(m_iFlags & wxPG_FL_FOCUSED) )
4998 {
4999 // Need to store changed value
5000 CommitChangesFromEditor();
5001 }
5002 else
5003 {
5004 /*
5005 //
5006 // Preliminary code for tab-order respecting
5007 // tab-traversal (but should be moved to
5008 // OnNav handler)
5009 //
5010 wxWindow* prevFocus = event.GetWindow();
5011 wxWindow* useThis = this;
5012 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5013 useThis = GetParent();
5014
5015 if ( prevFocus &&
5016 prevFocus->GetParent() == useThis->GetParent() )
5017 {
5018 wxList& children = useThis->GetParent()->GetChildren();
5019
5020 wxNode* node = children.Find(prevFocus);
5021
5022 if ( node->GetNext() &&
5023 useThis == node->GetNext()->GetData() )
5024 DoSelectProperty(GetFirst());
5025 else if ( node->GetPrevious () &&
5026 useThis == node->GetPrevious()->GetData() )
5027 DoSelectProperty(GetLastProperty());
5028
5029 }
5030 */
5031 }
5032
5033 // Redraw selected
5034 if ( m_selected && (m_iFlags & wxPG_FL_INITIALIZED) )
5035 DrawItem( m_selected );
5036 }
5037 }
5038
5039 void wxPropertyGrid::OnFocusEvent( wxFocusEvent& event )
5040 {
5041 if ( event.GetEventType() == wxEVT_SET_FOCUS )
5042 HandleFocusChange((wxWindow*)event.GetEventObject());
5043 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5044 //else if ( event.GetWindow() )
5045 else
5046 HandleFocusChange(event.GetWindow());
5047
5048 event.Skip();
5049 }
5050
5051 // -----------------------------------------------------------------------
5052
5053 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent& event )
5054 {
5055 HandleFocusChange((wxWindow*)event.GetEventObject());
5056
5057 //
5058 // event.Skip() being commented out is aworkaround for bug reported
5059 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5060 //event.Skip();
5061 }
5062
5063 // -----------------------------------------------------------------------
5064
5065 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent &event )
5066 {
5067 m_iFlags |= wxPG_FL_SCROLLED;
5068
5069 event.Skip();
5070 }
5071
5072 // -----------------------------------------------------------------------
5073
5074 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent& WXUNUSED(event) )
5075 {
5076 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
5077 {
5078 m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED);
5079 }
5080 }
5081
5082 // -----------------------------------------------------------------------
5083 // Property editor related functions
5084 // -----------------------------------------------------------------------
5085
5086 // noDefCheck = true prevents infinite recursion.
5087 wxPGEditor* wxPropertyGrid::RegisterEditorClass( wxPGEditor* editorClass,
5088 bool noDefCheck )
5089 {
5090 wxASSERT( editorClass );
5091
5092 if ( !noDefCheck && wxPGGlobalVars->m_mapEditorClasses.empty() )
5093 RegisterDefaultEditors();
5094
5095 wxString name = editorClass->GetName();
5096
5097 // Existing editor under this name?
5098 wxPGHashMapS2P::iterator vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name);
5099
5100 if ( vt_it != wxPGGlobalVars->m_mapEditorClasses.end() )
5101 {
5102 // If this name was already used, try class name.
5103 name = editorClass->GetClassInfo()->GetClassName();
5104 vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name);
5105 }
5106
5107 wxCHECK_MSG( vt_it == wxPGGlobalVars->m_mapEditorClasses.end(),
5108 (wxPGEditor*) vt_it->second,
5109 "Editor with given name was already registered" );
5110
5111 wxPGGlobalVars->m_mapEditorClasses[name] = (void*)editorClass;
5112
5113 return editorClass;
5114 }
5115
5116 // Use this in RegisterDefaultEditors.
5117 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5118 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5119 { \
5120 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5121 new wxPG##EDITOR##Editor, true ); \
5122 }
5123
5124 // Registers all default editor classes
5125 void wxPropertyGrid::RegisterDefaultEditors()
5126 {
5127 wxPGRegisterDefaultEditorClass( TextCtrl );
5128 wxPGRegisterDefaultEditorClass( Choice );
5129 wxPGRegisterDefaultEditorClass( ComboBox );
5130 wxPGRegisterDefaultEditorClass( TextCtrlAndButton );
5131 #if wxPG_INCLUDE_CHECKBOX
5132 wxPGRegisterDefaultEditorClass( CheckBox );
5133 #endif
5134 wxPGRegisterDefaultEditorClass( ChoiceAndButton );
5135
5136 // Register SpinCtrl etc. editors before use
5137 RegisterAdditionalEditors();
5138 }
5139
5140 // -----------------------------------------------------------------------
5141 // wxPGStringTokenizer
5142 // Needed to handle C-style string lists (e.g. "str1" "str2")
5143 // -----------------------------------------------------------------------
5144
5145 wxPGStringTokenizer::wxPGStringTokenizer( const wxString& str, wxChar delimeter )
5146 : m_str(&str), m_curPos(str.begin()), m_delimeter(delimeter)
5147 {
5148 }
5149
5150 wxPGStringTokenizer::~wxPGStringTokenizer()
5151 {
5152 }
5153
5154 bool wxPGStringTokenizer::HasMoreTokens()
5155 {
5156 const wxString& str = *m_str;
5157
5158 wxString::const_iterator i = m_curPos;
5159
5160 wxUniChar delim = m_delimeter;
5161 wxUniChar a;
5162 wxUniChar prev_a = wxT('\0');
5163
5164 bool inToken = false;
5165
5166 while ( i != str.end() )
5167 {
5168 a = *i;
5169
5170 if ( !inToken )
5171 {
5172 if ( a == delim )
5173 {
5174 inToken = true;
5175 m_readyToken.clear();
5176 }
5177 }
5178 else
5179 {
5180 if ( prev_a != wxT('\\') )
5181 {
5182 if ( a != delim )
5183 {
5184 if ( a != wxT('\\') )
5185 m_readyToken << a;
5186 }
5187 else
5188 {
5189 ++i;
5190 m_curPos = i;
5191 return true;
5192 }
5193 prev_a = a;
5194 }
5195 else
5196 {
5197 m_readyToken << a;
5198 prev_a = wxT('\0');
5199 }
5200 }
5201 ++i;
5202 }
5203
5204 m_curPos = str.end();
5205
5206 if ( inToken )
5207 return true;
5208
5209 return false;
5210 }
5211
5212 wxString wxPGStringTokenizer::GetNextToken()
5213 {
5214 return m_readyToken;
5215 }
5216
5217 // -----------------------------------------------------------------------
5218 // wxPGChoiceEntry
5219 // -----------------------------------------------------------------------
5220
5221 wxPGChoiceEntry::wxPGChoiceEntry()
5222 : wxPGCell(), m_value(wxPG_INVALID_VALUE)
5223 {
5224 }
5225
5226 // -----------------------------------------------------------------------
5227 // wxPGChoicesData
5228 // -----------------------------------------------------------------------
5229
5230 wxPGChoicesData::wxPGChoicesData()
5231 {
5232 m_refCount = 1;
5233 }
5234
5235 wxPGChoicesData::~wxPGChoicesData()
5236 {
5237 Clear();
5238 }
5239
5240 void wxPGChoicesData::Clear()
5241 {
5242 m_items.clear();
5243 }
5244
5245 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData* data )
5246 {
5247 wxASSERT( m_items.size() == 0 );
5248
5249 m_items = data->m_items;
5250 }
5251
5252 wxPGChoiceEntry& wxPGChoicesData::Insert( int index,
5253 const wxPGChoiceEntry& item )
5254 {
5255 wxVector<wxPGChoiceEntry>::iterator it;
5256 if ( index == -1 )
5257 {
5258 it = m_items.end();
5259 index = (int) m_items.size();
5260 }
5261 else
5262 {
5263 it = m_items.begin() + index;
5264 }
5265
5266 m_items.insert(it, item);
5267
5268 wxPGChoiceEntry& ownEntry = m_items[index];
5269
5270 // Need to fix value?
5271 if ( ownEntry.GetValue() == wxPG_INVALID_VALUE )
5272 ownEntry.SetValue(index);
5273
5274 return ownEntry;
5275 }
5276
5277 // -----------------------------------------------------------------------
5278 // wxPGChoices
5279 // -----------------------------------------------------------------------
5280
5281 wxPGChoiceEntry& wxPGChoices::Add( const wxString& label, int value )
5282 {
5283 EnsureData();
5284
5285 wxPGChoiceEntry entry(label, value);
5286 return m_data->Insert( -1, entry );
5287 }
5288
5289 // -----------------------------------------------------------------------
5290
5291 wxPGChoiceEntry& wxPGChoices::Add( const wxString& label, const wxBitmap& bitmap, int value )
5292 {
5293 EnsureData();
5294
5295 wxPGChoiceEntry entry(label, value);
5296 entry.SetBitmap(bitmap);
5297 return m_data->Insert( -1, entry );
5298 }
5299
5300 // -----------------------------------------------------------------------
5301
5302 wxPGChoiceEntry& wxPGChoices::Insert( const wxPGChoiceEntry& entry, int index )
5303 {
5304 EnsureData();
5305 return m_data->Insert( index, entry );
5306 }
5307
5308 // -----------------------------------------------------------------------
5309
5310 wxPGChoiceEntry& wxPGChoices::Insert( const wxString& label, int index, int value )
5311 {
5312 EnsureData();
5313
5314 wxPGChoiceEntry entry(label, value);
5315 return m_data->Insert( index, entry );
5316 }
5317
5318 // -----------------------------------------------------------------------
5319
5320 wxPGChoiceEntry& wxPGChoices::AddAsSorted( const wxString& label, int value )
5321 {
5322 EnsureData();
5323
5324 size_t index = 0;
5325
5326 while ( index < GetCount() )
5327 {
5328 int cmpRes = GetLabel(index).Cmp(label);
5329 if ( cmpRes > 0 )
5330 break;
5331 index++;
5332 }
5333
5334 wxPGChoiceEntry entry(label, value);
5335 return m_data->Insert( index, entry );
5336 }
5337
5338 // -----------------------------------------------------------------------
5339
5340 void wxPGChoices::Add( const wxChar** labels, const ValArrItem* values )
5341 {
5342 EnsureData();
5343
5344 unsigned int itemcount = 0;
5345 const wxChar** p = &labels[0];
5346 while ( *p ) { p++; itemcount++; }
5347
5348 unsigned int i;
5349 for ( i = 0; i < itemcount; i++ )
5350 {
5351 int value = i;
5352 if ( values )
5353 value = values[i];
5354 wxPGChoiceEntry entry(labels[i], value);
5355 m_data->Insert( i, entry );
5356 }
5357 }
5358
5359 // -----------------------------------------------------------------------
5360
5361 void wxPGChoices::Add( const wxArrayString& arr, const wxArrayInt& arrint )
5362 {
5363 EnsureData();
5364
5365 unsigned int i;
5366 unsigned int itemcount = arr.size();
5367
5368 for ( i = 0; i < itemcount; i++ )
5369 {
5370 int value = i;
5371 if ( &arrint && arrint.size() )
5372 value = arrint[i];
5373 wxPGChoiceEntry entry(arr[i], value);
5374 m_data->Insert( i, entry );
5375 }
5376 }
5377
5378 // -----------------------------------------------------------------------
5379
5380 void wxPGChoices::RemoveAt(size_t nIndex, size_t count)
5381 {
5382 wxASSERT( m_data->m_refCount != 0xFFFFFFF );
5383 m_data->m_items.erase(m_data->m_items.begin()+nIndex,
5384 m_data->m_items.begin()+nIndex+count);
5385 }
5386
5387 // -----------------------------------------------------------------------
5388
5389 int wxPGChoices::Index( const wxString& str ) const
5390 {
5391 if ( IsOk() )
5392 {
5393 unsigned int i;
5394 for ( i=0; i< m_data->GetCount(); i++ )
5395 {
5396 const wxPGChoiceEntry& entry = m_data->Item(i);
5397 if ( entry.HasText() && entry.GetText() == str )
5398 return i;
5399 }
5400 }
5401 return -1;
5402 }
5403
5404 // -----------------------------------------------------------------------
5405
5406 int wxPGChoices::Index( int val ) const
5407 {
5408 if ( IsOk() )
5409 {
5410 unsigned int i;
5411 for ( i=0; i< m_data->GetCount(); i++ )
5412 {
5413 const wxPGChoiceEntry& entry = m_data->Item(i);
5414 if ( entry.GetValue() == val )
5415 return i;
5416 }
5417 }
5418 return -1;
5419 }
5420
5421 // -----------------------------------------------------------------------
5422
5423 wxArrayString wxPGChoices::GetLabels() const
5424 {
5425 wxArrayString arr;
5426 unsigned int i;
5427
5428 if ( this && IsOk() )
5429 for ( i=0; i<GetCount(); i++ )
5430 arr.push_back(GetLabel(i));
5431
5432 return arr;
5433 }
5434
5435 // -----------------------------------------------------------------------
5436
5437 wxArrayInt wxPGChoices::GetValuesForStrings( const wxArrayString& strings ) const
5438 {
5439 wxArrayInt arr;
5440
5441 if ( IsOk() )
5442 {
5443 unsigned int i;
5444 for ( i=0; i< strings.size(); i++ )
5445 {
5446 int index = Index(strings[i]);
5447 if ( index >= 0 )
5448 arr.Add(GetValue(index));
5449 else
5450 arr.Add(wxPG_INVALID_VALUE);
5451 }
5452 }
5453
5454 return arr;
5455 }
5456
5457 // -----------------------------------------------------------------------
5458
5459 wxArrayInt wxPGChoices::GetIndicesForStrings( const wxArrayString& strings,
5460 wxArrayString* unmatched ) const
5461 {
5462 wxArrayInt arr;
5463
5464 if ( IsOk() )
5465 {
5466 unsigned int i;
5467 for ( i=0; i< strings.size(); i++ )
5468 {
5469 const wxString& str = strings[i];
5470 int index = Index(str);
5471 if ( index >= 0 )
5472 arr.Add(index);
5473 else if ( unmatched )
5474 unmatched->Add(str);
5475 }
5476 }
5477
5478 return arr;
5479 }
5480
5481 // -----------------------------------------------------------------------
5482
5483 void wxPGChoices::AssignData( wxPGChoicesData* data )
5484 {
5485 Free();
5486
5487 if ( data != wxPGChoicesEmptyData )
5488 {
5489 m_data = data;
5490 data->m_refCount++;
5491 }
5492 }
5493
5494 // -----------------------------------------------------------------------
5495
5496 void wxPGChoices::Init()
5497 {
5498 m_data = wxPGChoicesEmptyData;
5499 }
5500
5501 // -----------------------------------------------------------------------
5502
5503 void wxPGChoices::Free()
5504 {
5505 if ( m_data != wxPGChoicesEmptyData )
5506 {
5507 m_data->DecRef();
5508 m_data = wxPGChoicesEmptyData;
5509 }
5510 }
5511
5512 // -----------------------------------------------------------------------
5513 // wxPropertyGridEvent
5514 // -----------------------------------------------------------------------
5515
5516 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent, wxCommandEvent)
5517
5518
5519 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED )
5520 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING )
5521 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED )
5522 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED )
5523 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK )
5524 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED )
5525 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED )
5526 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED )
5527 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK )
5528
5529
5530 // -----------------------------------------------------------------------
5531
5532 void wxPropertyGridEvent::Init()
5533 {
5534 m_validationInfo = NULL;
5535 m_canVeto = false;
5536 m_wasVetoed = false;
5537 }
5538
5539 // -----------------------------------------------------------------------
5540
5541 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType, int id)
5542 : wxCommandEvent(commandType,id)
5543 {
5544 m_property = NULL;
5545 Init();
5546 }
5547
5548 // -----------------------------------------------------------------------
5549
5550 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent& event)
5551 : wxCommandEvent(event)
5552 {
5553 m_eventType = event.GetEventType();
5554 m_eventObject = event.m_eventObject;
5555 m_pg = event.m_pg;
5556 m_property = event.m_property;
5557 m_validationInfo = event.m_validationInfo;
5558 m_canVeto = event.m_canVeto;
5559 m_wasVetoed = event.m_wasVetoed;
5560 }
5561
5562 // -----------------------------------------------------------------------
5563
5564 wxPropertyGridEvent::~wxPropertyGridEvent()
5565 {
5566 }
5567
5568 // -----------------------------------------------------------------------
5569
5570 wxEvent* wxPropertyGridEvent::Clone() const
5571 {
5572 return new wxPropertyGridEvent( *this );
5573 }
5574
5575 // -----------------------------------------------------------------------
5576 // wxPropertyGridPopulator
5577 // -----------------------------------------------------------------------
5578
5579 wxPropertyGridPopulator::wxPropertyGridPopulator()
5580 {
5581 m_state = NULL;
5582 m_pg = NULL;
5583 wxPGGlobalVars->m_offline++;
5584 }
5585
5586 // -----------------------------------------------------------------------
5587
5588 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState* state )
5589 {
5590 m_state = state;
5591 m_propHierarchy.clear();
5592 }
5593
5594 // -----------------------------------------------------------------------
5595
5596 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid* pg )
5597 {
5598 m_pg = pg;
5599 pg->Freeze();
5600 }
5601
5602 // -----------------------------------------------------------------------
5603
5604 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5605 {
5606 //
5607 // Free unused sets of choices
5608 wxPGHashMapS2P::iterator it;
5609
5610 for( it = m_dictIdChoices.begin(); it != m_dictIdChoices.end(); ++it )
5611 {
5612 wxPGChoicesData* data = (wxPGChoicesData*) it->second;
5613 data->DecRef();
5614 }
5615
5616 if ( m_pg )
5617 {
5618 m_pg->Thaw();
5619 m_pg->GetPanel()->Refresh();
5620 }
5621 wxPGGlobalVars->m_offline--;
5622 }
5623
5624 // -----------------------------------------------------------------------
5625
5626 wxPGProperty* wxPropertyGridPopulator::Add( const wxString& propClass,
5627 const wxString& propLabel,
5628 const wxString& propName,
5629 const wxString* propValue,
5630 wxPGChoices* pChoices )
5631 {
5632 wxClassInfo* classInfo = wxClassInfo::FindClass(propClass);
5633 wxPGProperty* parent = GetCurParent();
5634
5635 if ( parent->HasFlag(wxPG_PROP_AGGREGATE) )
5636 {
5637 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent->GetName().c_str()));
5638 return NULL;
5639 }
5640
5641 if ( !classInfo || !classInfo->IsKindOf(CLASSINFO(wxPGProperty)) )
5642 {
5643 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass.c_str()));
5644 return NULL;
5645 }
5646
5647 wxPGProperty* property = (wxPGProperty*) classInfo->CreateObject();
5648
5649 property->SetLabel(propLabel);
5650 property->DoSetName(propName);
5651
5652 if ( pChoices && pChoices->IsOk() )
5653 property->SetChoices(*pChoices);
5654
5655 m_state->DoInsert(parent, -1, property);
5656
5657 if ( propValue )
5658 property->SetValueFromString( *propValue, wxPG_FULL_VALUE|
5659 wxPG_PROGRAMMATIC_VALUE );
5660
5661 return property;
5662 }
5663
5664 // -----------------------------------------------------------------------
5665
5666 void wxPropertyGridPopulator::AddChildren( wxPGProperty* property )
5667 {
5668 m_propHierarchy.push_back(property);
5669 DoScanForChildren();
5670 m_propHierarchy.pop_back();
5671 }
5672
5673 // -----------------------------------------------------------------------
5674
5675 wxPGChoices wxPropertyGridPopulator::ParseChoices( const wxString& choicesString,
5676 const wxString& idString )
5677 {
5678 wxPGChoices choices;
5679
5680 // Using id?
5681 if ( choicesString[0] == wxT('@') )
5682 {
5683 wxString ids = choicesString.substr(1);
5684 wxPGHashMapS2P::iterator it = m_dictIdChoices.find(ids);
5685 if ( it == m_dictIdChoices.end() )
5686 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids.c_str()));
5687 else
5688 choices.AssignData((wxPGChoicesData*)it->second);
5689 }
5690 else
5691 {
5692 bool found = false;
5693 if ( idString.length() )
5694 {
5695 wxPGHashMapS2P::iterator it = m_dictIdChoices.find(idString);
5696 if ( it != m_dictIdChoices.end() )
5697 {
5698 choices.AssignData((wxPGChoicesData*)it->second);
5699 found = true;
5700 }
5701 }
5702
5703 if ( !found )
5704 {
5705 // Parse choices string
5706 wxString::const_iterator it = choicesString.begin();
5707 wxString label;
5708 wxString value;
5709 int state = 0;
5710 bool labelValid = false;
5711
5712 for ( ; it != choicesString.end(); ++it )
5713 {
5714 wxChar c = *it;
5715
5716 if ( state != 1 )
5717 {
5718 if ( c == wxT('"') )
5719 {
5720 if ( labelValid )
5721 {
5722 long l;
5723 if ( !value.ToLong(&l, 0) ) l = wxPG_INVALID_VALUE;
5724 choices.Add(label, l);
5725 }
5726 labelValid = false;
5727 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5728 value.clear();
5729 label.clear();
5730 state = 1;
5731 }
5732 else if ( c == wxT('=') )
5733 {
5734 if ( labelValid )
5735 {
5736 state = 2;
5737 }
5738 }
5739 else if ( state == 2 && (wxIsalnum(c) || c == wxT('x')) )
5740 {
5741 value << c;
5742 }
5743 }
5744 else
5745 {
5746 if ( c == wxT('"') )
5747 {
5748 state = 0;
5749 labelValid = true;
5750 }
5751 else
5752 label << c;
5753 }
5754 }
5755
5756 if ( labelValid )
5757 {
5758 long l;
5759 if ( !value.ToLong(&l, 0) ) l = wxPG_INVALID_VALUE;
5760 choices.Add(label, l);
5761 }
5762
5763 if ( !choices.IsOk() )
5764 {
5765 choices.EnsureData();
5766 }
5767
5768 // Assign to id
5769 if ( idString.length() )
5770 m_dictIdChoices[idString] = choices.GetData();
5771 }
5772 }
5773
5774 return choices;
5775 }
5776
5777 // -----------------------------------------------------------------------
5778
5779 bool wxPropertyGridPopulator::ToLongPCT( const wxString& s, long* pval, long max )
5780 {
5781 if ( s.Last() == wxT('%') )
5782 {
5783 wxString s2 = s.substr(0,s.length()-1);
5784 long val;
5785 if ( s2.ToLong(&val, 10) )
5786 {
5787 *pval = (val*max)/100;
5788 return true;
5789 }
5790 return false;
5791 }
5792
5793 return s.ToLong(pval, 10);
5794 }
5795
5796 // -----------------------------------------------------------------------
5797
5798 bool wxPropertyGridPopulator::AddAttribute( const wxString& name,
5799 const wxString& type,
5800 const wxString& value )
5801 {
5802 int l = m_propHierarchy.size();
5803 if ( !l )
5804 return false;
5805
5806 wxPGProperty* p = m_propHierarchy[l-1];
5807 wxString valuel = value.Lower();
5808 wxVariant variant;
5809
5810 if ( type.length() == 0 )
5811 {
5812 long v;
5813
5814 // Auto-detect type
5815 if ( valuel == wxT("true") || valuel == wxT("yes") || valuel == wxT("1") )
5816 variant = true;
5817 else if ( valuel == wxT("false") || valuel == wxT("no") || valuel == wxT("0") )
5818 variant = false;
5819 else if ( value.ToLong(&v, 0) )
5820 variant = v;
5821 else
5822 variant = value;
5823 }
5824 else
5825 {
5826 if ( type == wxT("string") )
5827 {
5828 variant = value;
5829 }
5830 else if ( type == wxT("int") )
5831 {
5832 long v = 0;
5833 value.ToLong(&v, 0);
5834 variant = v;
5835 }
5836 else if ( type == wxT("bool") )
5837 {
5838 if ( valuel == wxT("true") || valuel == wxT("yes") || valuel == wxT("1") )
5839 variant = true;
5840 else
5841 variant = false;
5842 }
5843 else
5844 {
5845 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type.c_str()));
5846 return false;
5847 }
5848 }
5849
5850 p->SetAttribute( name, variant );
5851
5852 return true;
5853 }
5854
5855 // -----------------------------------------------------------------------
5856
5857 void wxPropertyGridPopulator::ProcessError( const wxString& msg )
5858 {
5859 wxLogError(_("Error in resource: %s"),msg.c_str());
5860 }
5861
5862 // -----------------------------------------------------------------------
5863
5864 #endif // wxUSE_PROPGRID