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