]> git.saurik.com Git - wxWidgets.git/blob - src/propgrid/propgrid.cpp
Reworked wxPGCell. It is now reference counted, and therefore much more user friendly...
[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 wxChar *wxPropertyGridNameStr = wxT("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 wxChar* 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 wxChar* 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 wxPanel* canvas = GetPanel();
3315
3316 /*
3317 if (p)
3318 wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(),
3319 p->m_parent->m_label.c_str(),p->GetIndexInParent());
3320 else
3321 wxLogDebug(wxT("SelectProperty( NULL, -1 )"));
3322 */
3323
3324 if ( m_inDoSelectProperty )
3325 return true;
3326
3327 m_inDoSelectProperty = 1;
3328
3329 wxPGProperty* prev = m_selected;
3330
3331 if ( !m_pState )
3332 {
3333 m_inDoSelectProperty = 0;
3334 return false;
3335 }
3336
3337 /*
3338 if (m_selected)
3339 wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() );
3340 else
3341 wxPrintf( "None selected\n" );
3342
3343 if (p)
3344 wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() );
3345 else
3346 wxPrintf( "P = NULL\n" );
3347 */
3348
3349 // If we are frozen, then just set the values.
3350 if ( m_frozen )
3351 {
3352 m_iFlags &= ~(wxPG_FL_ABNORMAL_EDITOR);
3353 m_editorFocused = 0;
3354 m_selected = p;
3355 m_selColumn = 1;
3356 m_pState->m_selected = p;
3357
3358 // If frozen, always free controls. But don't worry, as Thaw will
3359 // recall SelectProperty to recreate them.
3360 FreeEditors();
3361
3362 // Prevent any further selection measures in this call
3363 p = (wxPGProperty*) NULL;
3364 }
3365 else
3366 {
3367 // Is it the same?
3368 if ( m_selected == p && !(flags & wxPG_SEL_FORCE) )
3369 {
3370 // Only set focus if not deselecting
3371 if ( p )
3372 {
3373 if ( flags & wxPG_SEL_FOCUS )
3374 {
3375 if ( m_wndEditor )
3376 {
3377 m_wndEditor->SetFocus();
3378 m_editorFocused = 1;
3379 }
3380 }
3381 else
3382 {
3383 SetFocusOnCanvas();
3384 }
3385 }
3386
3387 m_inDoSelectProperty = 0;
3388 return true;
3389 }
3390
3391 //
3392 // First, deactivate previous
3393 if ( m_selected )
3394 {
3395
3396 OnValidationFailureReset(m_selected);
3397
3398 // Must double-check if this is an selected in case of forceswitch
3399 if ( p != prev )
3400 {
3401 if ( !CommitChangesFromEditor(flags) )
3402 {
3403 // Validation has failed, so we can't exit the previous editor
3404 //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."),
3405 // _("Invalid Value"),wxOK|wxICON_ERROR);
3406 m_inDoSelectProperty = 0;
3407 return false;
3408 }
3409 }
3410
3411 FreeEditors();
3412 m_selColumn = -1;
3413
3414 m_selected = (wxPGProperty*) NULL;
3415 m_pState->m_selected = (wxPGProperty*) NULL;
3416
3417 // We need to always fully refresh the grid here
3418 Refresh(false);
3419
3420 m_iFlags &= ~(wxPG_FL_ABNORMAL_EDITOR);
3421 EditorsValueWasNotModified();
3422 }
3423
3424 SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY);
3425
3426 //
3427 // Then, activate the one given.
3428 if ( p )
3429 {
3430 int propY = p->GetY2(m_lineHeight);
3431
3432 int splitterX = GetSplitterPosition();
3433 m_editorFocused = 0;
3434 m_selected = p;
3435 m_pState->m_selected = p;
3436 m_iFlags |= wxPG_FL_PRIMARY_FILLS_ENTIRE;
3437 if ( p != prev )
3438 m_iFlags &= ~(wxPG_FL_VALIDATION_FAILED);
3439
3440 wxASSERT( m_wndEditor == (wxWindow*) NULL );
3441
3442 // Do we need OnMeasureCalls?
3443 wxSize imsz = p->OnMeasureImage();
3444
3445 //
3446 // Only create editor for non-disabled non-caption
3447 if ( !p->IsCategory() && !(p->m_flags & wxPG_PROP_DISABLED) )
3448 {
3449 // do this for non-caption items
3450
3451 m_selColumn = 1;
3452
3453 // Do we need to paint the custom image, if any?
3454 m_iFlags &= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE);
3455 if ( (p->m_flags & wxPG_PROP_CUSTOMIMAGE) &&
3456 !p->GetEditorClass()->CanContainCustomImage()
3457 )
3458 m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE;
3459
3460 wxRect grect = GetEditorWidgetRect(p, m_selColumn);
3461 wxPoint goodPos = grect.GetPosition();
3462 #if wxPG_CREATE_CONTROLS_HIDDEN
3463 int coord_adjust = m_height - goodPos.y;
3464 goodPos.y += coord_adjust;
3465 #endif
3466
3467 const wxPGEditor* editor = p->GetEditorClass();
3468 wxCHECK_MSG(editor, false,
3469 wxT("NULL editor class not allowed"));
3470
3471 m_iFlags &= ~wxPG_FL_FIXED_WIDTH_EDITOR;
3472
3473 wxPGWindowList wndList = editor->CreateControls(this,
3474 p,
3475 goodPos,
3476 grect.GetSize());
3477
3478 m_wndEditor = wndList.m_primary;
3479 m_wndEditor2 = wndList.m_secondary;
3480 wxWindow* primaryCtrl = GetEditorControl();
3481
3482 //
3483 // Essentially, primaryCtrl == m_wndEditor
3484 //
3485
3486 // NOTE: It is allowed for m_wndEditor to be NULL - in this case
3487 // value is drawn as normal, and m_wndEditor2 is assumed
3488 // to be a right-aligned button that triggers a separate editorCtrl
3489 // window.
3490
3491 if ( m_wndEditor )
3492 {
3493 wxASSERT_MSG( m_wndEditor->GetParent() == canvas,
3494 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3495
3496 // Set validator, if any
3497 #if wxUSE_VALIDATORS
3498 wxValidator* validator = p->GetValidator();
3499 if ( validator )
3500 primaryCtrl->SetValidator(*validator);
3501 #endif
3502
3503 if ( m_wndEditor->GetSize().y > (m_lineHeight+6) )
3504 m_iFlags |= wxPG_FL_ABNORMAL_EDITOR;
3505
3506 // If it has modified status, use bold font
3507 // (must be done before capturing m_ctrlXAdjust)
3508 if ( (p->m_flags & wxPG_PROP_MODIFIED) && (m_windowStyle & wxPG_BOLD_MODIFIED) )
3509 SetCurControlBoldFont();
3510
3511 //
3512 // Fix TextCtrl indentation
3513 #if defined(__WXMSW__) && !defined(__WXWINCE__)
3514 wxTextCtrl* tc = NULL;
3515 if ( primaryCtrl->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)) )
3516 tc = ((wxOwnerDrawnComboBox*)primaryCtrl)->GetTextCtrl();
3517 else
3518 tc = wxDynamicCast(primaryCtrl, wxTextCtrl);
3519 if ( tc )
3520 ::SendMessage(GetHwndOf(tc), EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0, 0));
3521 #endif
3522
3523 // Store x relative to splitter (we'll need it).
3524 m_ctrlXAdjust = m_wndEditor->GetPosition().x - splitterX;
3525
3526 // Check if background clear is not necessary
3527 wxPoint pos = m_wndEditor->GetPosition();
3528 if ( pos.x > (splitterX+1) || pos.y > propY )
3529 {
3530 m_iFlags &= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE);
3531 }
3532
3533 m_wndEditor->SetSizeHints(3, 3);
3534
3535 #if wxPG_CREATE_CONTROLS_HIDDEN
3536 m_wndEditor->Show(false);
3537 m_wndEditor->Freeze();
3538
3539 goodPos = m_wndEditor->GetPosition();
3540 goodPos.y -= coord_adjust;
3541 m_wndEditor->Move( goodPos );
3542 #endif
3543
3544 SetupChildEventHandling(primaryCtrl);
3545
3546 // Focus and select all (wxTextCtrl, wxComboBox etc)
3547 if ( flags & wxPG_SEL_FOCUS )
3548 {
3549 primaryCtrl->SetFocus();
3550
3551 p->GetEditorClass()->OnFocus(p, primaryCtrl);
3552 }
3553 }
3554
3555 if ( m_wndEditor2 )
3556 {
3557 wxASSERT_MSG( m_wndEditor2->GetParent() == canvas,
3558 wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") );
3559
3560 // Get proper id for wndSecondary
3561 m_wndSecId = m_wndEditor2->GetId();
3562 wxWindowList children = m_wndEditor2->GetChildren();
3563 wxWindowList::iterator node = children.begin();
3564 if ( node != children.end() )
3565 m_wndSecId = ((wxWindow*)*node)->GetId();
3566
3567 m_wndEditor2->SetSizeHints(3,3);
3568
3569 #if wxPG_CREATE_CONTROLS_HIDDEN
3570 wxRect sec_rect = m_wndEditor2->GetRect();
3571 sec_rect.y -= coord_adjust;
3572
3573 // Fine tuning required to fix "oversized"
3574 // button disappearance bug.
3575 if ( sec_rect.y < 0 )
3576 {
3577 sec_rect.height += sec_rect.y;
3578 sec_rect.y = 0;
3579 }
3580 m_wndEditor2->SetSize( sec_rect );
3581 #endif
3582 m_wndEditor2->Show();
3583
3584 SetupChildEventHandling(m_wndEditor2);
3585
3586 // If no primary editor, focus to button to allow
3587 // it to interprete ENTER etc.
3588 // NOTE: Due to problems focusing away from it, this
3589 // has been disabled.
3590 /*
3591 if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor )
3592 m_wndEditor2->SetFocus();
3593 */
3594 }
3595
3596 if ( flags & wxPG_SEL_FOCUS )
3597 m_editorFocused = 1;
3598
3599 }
3600 else
3601 {
3602 // Make sure focus is in grid canvas (important for wxGTK, at least)
3603 SetFocusOnCanvas();
3604 }
3605
3606 EditorsValueWasNotModified();
3607
3608 // If it's inside collapsed section, expand parent, scroll, etc.
3609 // Also, if it was partially visible, scroll it into view.
3610 if ( !(flags & wxPG_SEL_NONVISIBLE) )
3611 EnsureVisible( p );
3612
3613 if ( m_wndEditor )
3614 {
3615 #if wxPG_CREATE_CONTROLS_HIDDEN
3616 m_wndEditor->Thaw();
3617 #endif
3618 m_wndEditor->Show(true);
3619 }
3620
3621 DrawItems(p, p);
3622 }
3623 else
3624 {
3625 // Make sure focus is in grid canvas
3626 SetFocusOnCanvas();
3627 }
3628
3629 ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY);
3630 }
3631
3632 #if wxUSE_STATUSBAR
3633
3634 //
3635 // Show help text in status bar.
3636 // (if found and grid not embedded in manager with help box and
3637 // style wxPG_EX_HELP_AS_TOOLTIPS is not used).
3638 //
3639
3640 if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS) )
3641 {
3642 wxStatusBar* statusbar = (wxStatusBar*) NULL;
3643 if ( !(m_iFlags & wxPG_FL_NOSTATUSBARHELP) )
3644 {
3645 wxFrame* frame = wxDynamicCast(::wxGetTopLevelParent(this),wxFrame);
3646 if ( frame )
3647 statusbar = frame->GetStatusBar();
3648 }
3649
3650 if ( statusbar )
3651 {
3652 const wxString* pHelpString = (const wxString*) NULL;
3653
3654 if ( p )
3655 {
3656 pHelpString = &p->GetHelpString();
3657 if ( pHelpString->length() )
3658 {
3659 // Set help box text.
3660 statusbar->SetStatusText( *pHelpString );
3661 m_iFlags |= wxPG_FL_STRING_IN_STATUSBAR;
3662 }
3663 }
3664
3665 if ( (!pHelpString || !pHelpString->length()) &&
3666 (m_iFlags & wxPG_FL_STRING_IN_STATUSBAR) )
3667 {
3668 // Clear help box - but only if it was written
3669 // by us at previous time.
3670 statusbar->SetStatusText( m_emptyString );
3671 m_iFlags &= ~(wxPG_FL_STRING_IN_STATUSBAR);
3672 }
3673 }
3674 }
3675 #endif
3676
3677 m_inDoSelectProperty = 0;
3678
3679 // call wx event handler (here so that it also occurs on deselection)
3680 SendEvent( wxEVT_PG_SELECTED, m_selected, NULL, flags );
3681
3682 return true;
3683 }
3684
3685 // -----------------------------------------------------------------------
3686
3687 bool wxPropertyGrid::UnfocusEditor()
3688 {
3689 if ( !m_selected || !m_wndEditor || m_frozen )
3690 return true;
3691
3692 if ( !CommitChangesFromEditor(0) )
3693 return false;
3694
3695 SetFocusOnCanvas();
3696 DrawItem(m_selected);
3697
3698 return true;
3699 }
3700
3701 // -----------------------------------------------------------------------
3702
3703 // This method is not inline because it called dozens of times
3704 // (i.e. two-arg function calls create smaller code size).
3705 bool wxPropertyGrid::DoClearSelection()
3706 {
3707 return DoSelectProperty((wxPGProperty*)NULL);
3708 }
3709
3710 // -----------------------------------------------------------------------
3711 // wxPropertyGrid expand/collapse state
3712 // -----------------------------------------------------------------------
3713
3714 bool wxPropertyGrid::DoCollapse( wxPGProperty* p, bool sendEvents )
3715 {
3716 wxPGProperty* pwc = wxStaticCast(p, wxPGProperty);
3717
3718 // If active editor was inside collapsed section, then disable it
3719 if ( m_selected && m_selected->IsSomeParent (p) )
3720 {
3721 if ( !ClearSelection() )
3722 return false;
3723 }
3724
3725 // Store dont-center-splitter flag 'cause we need to temporarily set it
3726 wxUint32 old_flag = m_iFlags & wxPG_FL_DONT_CENTER_SPLITTER;
3727 m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER;
3728
3729 bool res = m_pState->DoCollapse(pwc);
3730
3731 if ( res )
3732 {
3733 if ( sendEvents )
3734 SendEvent( wxEVT_PG_ITEM_COLLAPSED, p );
3735
3736 RecalculateVirtualSize();
3737
3738 // Redraw etc. only if collapsed was visible.
3739 if (pwc->IsVisible() &&
3740 !m_frozen &&
3741 ( !pwc->IsCategory() || !(m_windowStyle & wxPG_HIDE_CATEGORIES) ) )
3742 {
3743 // When item is collapsed so that scrollbar would move,
3744 // graphics mess is about (unless we redraw everything).
3745 Refresh();
3746 }
3747 }
3748
3749 // Clear dont-center-splitter flag if it wasn't set
3750 m_iFlags = (m_iFlags & ~wxPG_FL_DONT_CENTER_SPLITTER) | old_flag;
3751
3752 return res;
3753 }
3754
3755 // -----------------------------------------------------------------------
3756
3757 bool wxPropertyGrid::DoExpand( wxPGProperty* p, bool sendEvents )
3758 {
3759 wxCHECK_MSG( p, false, wxT("invalid property id") );
3760
3761 wxPGProperty* pwc = (wxPGProperty*)p;
3762
3763 // Store dont-center-splitter flag 'cause we need to temporarily set it
3764 wxUint32 old_flag = m_iFlags & wxPG_FL_DONT_CENTER_SPLITTER;
3765 m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER;
3766
3767 bool res = m_pState->DoExpand(pwc);
3768
3769 if ( res )
3770 {
3771 if ( sendEvents )
3772 SendEvent( wxEVT_PG_ITEM_EXPANDED, p );
3773
3774 RecalculateVirtualSize();
3775
3776 // Redraw etc. only if expanded was visible.
3777 if ( pwc->IsVisible() && !m_frozen &&
3778 ( !pwc->IsCategory() || !(m_windowStyle & wxPG_HIDE_CATEGORIES) )
3779 )
3780 {
3781 // Redraw
3782 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
3783 Refresh();
3784 #else
3785 DrawItems(pwc, NULL);
3786 #endif
3787 }
3788 }
3789
3790 // Clear dont-center-splitter flag if it wasn't set
3791 m_iFlags = m_iFlags & ~(wxPG_FL_DONT_CENTER_SPLITTER) | old_flag;
3792
3793 return res;
3794 }
3795
3796 // -----------------------------------------------------------------------
3797
3798 bool wxPropertyGrid::DoHideProperty( wxPGProperty* p, bool hide, int flags )
3799 {
3800 if ( m_frozen )
3801 return m_pState->DoHideProperty(p, hide, flags);
3802
3803 if ( m_selected &&
3804 ( m_selected == p || m_selected->IsSomeParent(p) )
3805 )
3806 {
3807 if ( !ClearSelection() )
3808 return false;
3809 }
3810
3811 m_pState->DoHideProperty(p, hide, flags);
3812
3813 RecalculateVirtualSize();
3814 Refresh();
3815
3816 return true;
3817 }
3818
3819
3820 // -----------------------------------------------------------------------
3821 // wxPropertyGrid size related methods
3822 // -----------------------------------------------------------------------
3823
3824 void wxPropertyGrid::RecalculateVirtualSize( int forceXPos )
3825 {
3826 if ( (m_iFlags & wxPG_FL_RECALCULATING_VIRTUAL_SIZE) || m_frozen )
3827 return;
3828
3829 //
3830 // If virtual height was changed, then recalculate editor control position(s)
3831 if ( m_pState->m_vhCalcPending )
3832 CorrectEditorWidgetPosY();
3833
3834 m_pState->EnsureVirtualHeight();
3835
3836 #ifdef __WXDEBUG__
3837 int by1 = m_pState->GetVirtualHeight();
3838 int by2 = m_pState->GetActualVirtualHeight();
3839 if ( by1 != by2 )
3840 {
3841 wxString s = wxString::Format(wxT("VirtualHeight=%i, ActualVirtualHeight=%i, should match!"), by1, by2);
3842 wxASSERT_MSG( false,
3843 s.c_str() );
3844 wxLogDebug(s);
3845 }
3846 #endif
3847
3848 m_iFlags |= wxPG_FL_RECALCULATING_VIRTUAL_SIZE;
3849
3850 int x = m_pState->m_width;
3851 int y = m_pState->m_virtualHeight;
3852
3853 int width, height;
3854 GetClientSize(&width,&height);
3855
3856 // Now adjust virtual size.
3857 SetVirtualSize(x, y);
3858
3859 int xAmount = 0;
3860 int xPos = 0;
3861
3862 //
3863 // Adjust scrollbars
3864 if ( HasVirtualWidth() )
3865 {
3866 xAmount = x/wxPG_PIXELS_PER_UNIT;
3867 xPos = GetScrollPos( wxHORIZONTAL );
3868 }
3869
3870 if ( forceXPos != -1 )
3871 xPos = forceXPos;
3872 // xPos too high?
3873 else if ( xPos > (xAmount-(width/wxPG_PIXELS_PER_UNIT)) )
3874 xPos = 0;
3875
3876 int yAmount = (y+wxPG_PIXELS_PER_UNIT+2)/wxPG_PIXELS_PER_UNIT;
3877 int yPos = GetScrollPos( wxVERTICAL );
3878
3879 SetScrollbars( wxPG_PIXELS_PER_UNIT, wxPG_PIXELS_PER_UNIT,
3880 xAmount, yAmount, xPos, yPos, true );
3881
3882 // Must re-get size now
3883 GetClientSize(&width,&height);
3884
3885 if ( !HasVirtualWidth() )
3886 {
3887 m_pState->SetVirtualWidth(width);
3888 x = width;
3889 }
3890
3891 m_width = width;
3892 m_height = height;
3893
3894 m_canvas->SetSize( x, y );
3895
3896 m_pState->CheckColumnWidths();
3897
3898 if ( m_selected )
3899 CorrectEditorWidgetSizeX();
3900
3901 m_iFlags &= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE;
3902 }
3903
3904 // -----------------------------------------------------------------------
3905
3906 void wxPropertyGrid::OnResize( wxSizeEvent& event )
3907 {
3908 if ( !(m_iFlags & wxPG_FL_INITIALIZED) )
3909 return;
3910
3911 int width, height;
3912 GetClientSize(&width,&height);
3913
3914 m_width = width;
3915 m_height = height;
3916
3917 #if wxPG_DOUBLE_BUFFER
3918 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING) )
3919 {
3920 int dblh = (m_lineHeight*2);
3921 if ( !m_doubleBuffer )
3922 {
3923 // Create double buffer bitmap to draw on, if none
3924 int w = (width>250)?width:250;
3925 int h = height + dblh;
3926 h = (h>400)?h:400;
3927 m_doubleBuffer = new wxBitmap( w, h );
3928 }
3929 else
3930 {
3931 int w = m_doubleBuffer->GetWidth();
3932 int h = m_doubleBuffer->GetHeight();
3933
3934 // Double buffer must be large enough
3935 if ( w < width || h < (height+dblh) )
3936 {
3937 if ( w < width ) w = width;
3938 if ( h < (height+dblh) ) h = height + dblh;
3939 delete m_doubleBuffer;
3940 m_doubleBuffer = new wxBitmap( w, h );
3941 }
3942 }
3943 }
3944
3945 #endif
3946
3947 m_pState->OnClientWidthChange( width, event.GetSize().x - m_ncWidth, true );
3948 m_ncWidth = event.GetSize().x;
3949
3950 if ( !m_frozen )
3951 {
3952 if ( m_pState->m_itemsAdded )
3953 PrepareAfterItemsAdded();
3954 else
3955 // Without this, virtual size (atleast under wxGTK) will be skewed
3956 RecalculateVirtualSize();
3957
3958 Refresh();
3959 }
3960 }
3961
3962 // -----------------------------------------------------------------------
3963
3964 void wxPropertyGrid::SetVirtualWidth( int width )
3965 {
3966 if ( width == -1 )
3967 {
3968 // Disable virtual width
3969 width = GetClientSize().x;
3970 ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH);
3971 }
3972 else
3973 {
3974 // Enable virtual width
3975 SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH);
3976 }
3977 m_pState->SetVirtualWidth( width );
3978 }
3979
3980 void wxPropertyGrid::SetFocusOnCanvas()
3981 {
3982 m_canvas->SetFocusIgnoringChildren();
3983 m_editorFocused = 0;
3984 }
3985
3986 // -----------------------------------------------------------------------
3987 // wxPropertyGrid mouse event handling
3988 // -----------------------------------------------------------------------
3989
3990 // selFlags uses same values DoSelectProperty's flags
3991 // Returns true if event was vetoed.
3992 bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p, wxVariant* pValue, unsigned int WXUNUSED(selFlags) )
3993 {
3994 // Send property grid event of specific type and with specific property
3995 wxPropertyGridEvent evt( eventType, m_eventObject->GetId() );
3996 evt.SetPropertyGrid(this);
3997 evt.SetEventObject(m_eventObject);
3998 evt.SetProperty(p);
3999 if ( pValue )
4000 {
4001 evt.SetCanVeto(true);
4002 evt.SetupValidationInfo();
4003 m_validationInfo.m_pValue = pValue;
4004 }
4005 wxEvtHandler* evtHandler = m_eventObject->GetEventHandler();
4006
4007 evtHandler->ProcessEvent(evt);
4008
4009 return evt.WasVetoed();
4010 }
4011
4012 // -----------------------------------------------------------------------
4013
4014 // Return false if should be skipped
4015 bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &event )
4016 {
4017 bool res = true;
4018
4019 // Need to set focus?
4020 if ( !(m_iFlags & wxPG_FL_FOCUSED) )
4021 {
4022 SetFocusOnCanvas();
4023 }
4024
4025 wxPropertyGridPageState* state = m_pState;
4026 int splitterHit;
4027 int splitterHitOffset;
4028 int columnHit = state->HitTestH( x, &splitterHit, &splitterHitOffset );
4029
4030 wxPGProperty* p = DoGetItemAtY(y);
4031
4032 if ( p )
4033 {
4034 int depth = (int)p->GetDepth() - 1;
4035
4036 int marginEnds = m_marginWidth + ( depth * m_subgroup_extramargin );
4037
4038 if ( x >= marginEnds )
4039 {
4040 // Outside margin.
4041
4042 if ( p->IsCategory() )
4043 {
4044 // This is category.
4045 wxPropertyCategory* pwc = (wxPropertyCategory*)p;
4046
4047 int textX = m_marginWidth + ((unsigned int)((pwc->m_depth-1)*m_subgroup_extramargin));
4048
4049 // Expand, collapse, activate etc. if click on text or left of splitter.
4050 if ( x >= textX
4051 &&
4052 ( x < (textX+pwc->GetTextExtent(this, m_captionFont)+(wxPG_CAPRECTXMARGIN*2)) ||
4053 columnHit == 0
4054 )
4055 )
4056 {
4057 if ( !DoSelectProperty( p ) )
4058 return res;
4059
4060 // On double-click, expand/collapse.
4061 if ( event.ButtonDClick() && !(m_windowStyle & wxPG_HIDE_MARGIN) )
4062 {
4063 if ( pwc->IsExpanded() ) DoCollapse( p, true );
4064 else DoExpand( p, true );
4065 }
4066 }
4067 }
4068 else if ( splitterHit == -1 )
4069 {
4070 // Click on value.
4071 unsigned int selFlag = 0;
4072 if ( columnHit == 1 )
4073 {
4074 m_iFlags |= wxPG_FL_ACTIVATION_BY_CLICK;
4075 selFlag = wxPG_SEL_FOCUS;
4076 }
4077 if ( !DoSelectProperty( p, selFlag ) )
4078 return res;
4079
4080 m_iFlags &= ~(wxPG_FL_ACTIVATION_BY_CLICK);
4081
4082 if ( p->GetChildCount() && !p->IsCategory() )
4083 // On double-click, expand/collapse.
4084 if ( event.ButtonDClick() && !(m_windowStyle & wxPG_HIDE_MARGIN) )
4085 {
4086 wxPGProperty* pwc = (wxPGProperty*)p;
4087 if ( pwc->IsExpanded() ) DoCollapse( p, true );
4088 else DoExpand( p, true );
4089 }
4090
4091 res = false;
4092 }
4093 else
4094 {
4095 // click on splitter
4096 if ( !(m_windowStyle & wxPG_STATIC_SPLITTER) )
4097 {
4098 if ( event.GetEventType() == wxEVT_LEFT_DCLICK )
4099 {
4100 // Double-clicking the splitter causes auto-centering
4101 CenterSplitter( true );
4102 }
4103 else if ( m_dragStatus == 0 )
4104 {
4105 //
4106 // Begin draggin the splitter
4107 //
4108 if ( m_wndEditor )
4109 {
4110 // Changes must be committed here or the
4111 // value won't be drawn correctly
4112 if ( !CommitChangesFromEditor() )
4113 return res;
4114
4115 m_wndEditor->Show ( false );
4116 }
4117
4118 if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) )
4119 {
4120 m_canvas->CaptureMouse();
4121 m_iFlags |= wxPG_FL_MOUSE_CAPTURED;
4122 }
4123
4124 m_dragStatus = 1;
4125 m_draggedSplitter = splitterHit;
4126 m_dragOffset = splitterHitOffset;
4127
4128 wxClientDC dc(m_canvas);
4129
4130 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4131 // Fixes button disappearance bug
4132 if ( m_wndEditor2 )
4133 m_wndEditor2->Show ( false );
4134 #endif
4135
4136 m_startingSplitterX = x - splitterHitOffset;
4137 }
4138 }
4139 }
4140 }
4141 else
4142 {
4143 // Click on margin.
4144 if ( p->GetChildCount() )
4145 {
4146 int nx = x + m_marginWidth - marginEnds; // Normalize x.
4147
4148 if ( (nx >= m_gutterWidth && nx < (m_gutterWidth+m_iconWidth)) )
4149 {
4150 int y2 = y % m_lineHeight;
4151 if ( (y2 >= m_buttonSpacingY && y2 < (m_buttonSpacingY+m_iconHeight)) )
4152 {
4153 // On click on expander button, expand/collapse
4154 if ( ((wxPGProperty*)p)->IsExpanded() )
4155 DoCollapse( p, true );
4156 else
4157 DoExpand( p, true );
4158 }
4159 }
4160 }
4161 }
4162 }
4163 return res;
4164 }
4165
4166 // -----------------------------------------------------------------------
4167
4168 bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x), unsigned int WXUNUSED(y),
4169 wxMouseEvent& WXUNUSED(event) )
4170 {
4171 if ( m_propHover )
4172 {
4173 // Select property here as well
4174 wxPGProperty* p = m_propHover;
4175 if ( p != m_selected )
4176 DoSelectProperty( p );
4177
4178 // Send right click event.
4179 SendEvent( wxEVT_PG_RIGHT_CLICK, p );
4180
4181 return true;
4182 }
4183 return false;
4184 }
4185
4186 // -----------------------------------------------------------------------
4187
4188 bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x), unsigned int WXUNUSED(y),
4189 wxMouseEvent& WXUNUSED(event) )
4190 {
4191 if ( m_propHover )
4192 {
4193 // Select property here as well
4194 wxPGProperty* p = m_propHover;
4195
4196 if ( p != m_selected )
4197 DoSelectProperty( p );
4198
4199 // Send double-click event.
4200 SendEvent( wxEVT_PG_DOUBLE_CLICK, m_propHover );
4201
4202 return true;
4203 }
4204 return false;
4205 }
4206
4207 // -----------------------------------------------------------------------
4208
4209 #if wxPG_SUPPORT_TOOLTIPS
4210
4211 void wxPropertyGrid::SetToolTip( const wxString& tipString )
4212 {
4213 if ( tipString.length() )
4214 {
4215 m_canvas->SetToolTip(tipString);
4216 }
4217 else
4218 {
4219 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4220 m_canvas->SetToolTip( m_emptyString );
4221 #else
4222 m_canvas->SetToolTip( NULL );
4223 #endif
4224 }
4225 }
4226
4227 #endif // #if wxPG_SUPPORT_TOOLTIPS
4228
4229 // -----------------------------------------------------------------------
4230
4231 // Return false if should be skipped
4232 bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y, wxMouseEvent &event )
4233 {
4234 // Safety check (needed because mouse capturing may
4235 // otherwise freeze the control)
4236 if ( m_dragStatus > 0 && !event.Dragging() )
4237 {
4238 HandleMouseUp(x,y,event);
4239 }
4240
4241 wxPropertyGridPageState* state = m_pState;
4242 int splitterHit;
4243 int splitterHitOffset;
4244 int columnHit = state->HitTestH( x, &splitterHit, &splitterHitOffset );
4245 int splitterX = x - splitterHitOffset;
4246
4247 if ( m_dragStatus > 0 )
4248 {
4249 if ( x > (m_marginWidth + wxPG_DRAG_MARGIN) &&
4250 x < (m_pState->m_width - wxPG_DRAG_MARGIN) )
4251 {
4252
4253 int newSplitterX = x - m_dragOffset;
4254 int splitterX = x - splitterHitOffset;
4255
4256 // Splitter redraw required?
4257 if ( newSplitterX != splitterX )
4258 {
4259 // Move everything
4260 SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER);
4261 state->DoSetSplitterPosition( newSplitterX, m_draggedSplitter, false );
4262 state->m_fSplitterX = (float) newSplitterX;
4263
4264 if ( m_selected )
4265 CorrectEditorWidgetSizeX();
4266
4267 Update();
4268 Refresh();
4269 }
4270
4271 m_dragStatus = 2;
4272 }
4273
4274 return false;
4275 }
4276 else
4277 {
4278
4279 int ih = m_lineHeight;
4280 int sy = y;
4281
4282 #if wxPG_SUPPORT_TOOLTIPS
4283 wxPGProperty* prevHover = m_propHover;
4284 unsigned char prevSide = m_mouseSide;
4285 #endif
4286 int curPropHoverY = y - (y % ih);
4287
4288 // On which item it hovers
4289 if ( ( !m_propHover )
4290 ||
4291 ( m_propHover && ( sy < m_propHoverY || sy >= (m_propHoverY+ih) ) )
4292 )
4293 {
4294 // Mouse moves on another property
4295
4296 m_propHover = DoGetItemAtY(y);
4297 m_propHoverY = curPropHoverY;
4298
4299 // Send hover event
4300 SendEvent( wxEVT_PG_HIGHLIGHTED, m_propHover );
4301 }
4302
4303 #if wxPG_SUPPORT_TOOLTIPS
4304 // Store which side we are on
4305 m_mouseSide = 0;
4306 if ( columnHit == 1 )
4307 m_mouseSide = 2;
4308 else if ( columnHit == 0 )
4309 m_mouseSide = 1;
4310
4311 //
4312 // If tooltips are enabled, show label or value as a tip
4313 // in case it doesn't otherwise show in full length.
4314 //
4315 if ( m_windowStyle & wxPG_TOOLTIPS )
4316 {
4317 wxToolTip* tooltip = m_canvas->GetToolTip();
4318
4319 if ( m_propHover != prevHover || prevSide != m_mouseSide )
4320 {
4321 if ( m_propHover && !m_propHover->IsCategory() )
4322 {
4323
4324 if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS )
4325 {
4326 // Show help string as a tooltip
4327 wxString tipString = m_propHover->GetHelpString();
4328
4329 SetToolTip(tipString);
4330 }
4331 else
4332 {
4333 // Show cropped value string as a tooltip
4334 wxString tipString;
4335 int space = 0;
4336
4337 if ( m_mouseSide == 1 )
4338 {
4339 tipString = m_propHover->m_label;
4340 space = splitterX-m_marginWidth-3;
4341 }
4342 else if ( m_mouseSide == 2 )
4343 {
4344 tipString = m_propHover->GetDisplayedString();
4345
4346 space = m_width - splitterX;
4347 if ( m_propHover->m_flags & wxPG_PROP_CUSTOMIMAGE )
4348 space -= wxPG_CUSTOM_IMAGE_WIDTH + wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
4349 }
4350
4351 if ( space )
4352 {
4353 int tw, th;
4354 GetTextExtent( tipString, &tw, &th, 0, 0, &m_font );
4355 if ( tw > space )
4356 {
4357 SetToolTip( tipString );
4358 }
4359 }
4360 else
4361 {
4362 if ( tooltip )
4363 {
4364 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4365 m_canvas->SetToolTip( m_emptyString );
4366 #else
4367 m_canvas->SetToolTip( NULL );
4368 #endif
4369 }
4370 }
4371
4372 }
4373 }
4374 else
4375 {
4376 if ( tooltip )
4377 {
4378 #if wxPG_ALLOW_EMPTY_TOOLTIPS
4379 m_canvas->SetToolTip( m_emptyString );
4380 #else
4381 m_canvas->SetToolTip( NULL );
4382 #endif
4383 }
4384 }
4385 }
4386 }
4387 #endif
4388
4389 if ( splitterHit == -1 ||
4390 !m_propHover ||
4391 HasFlag(wxPG_STATIC_SPLITTER) )
4392 {
4393 // hovering on something else
4394 if ( m_curcursor != wxCURSOR_ARROW )
4395 CustomSetCursor( wxCURSOR_ARROW );
4396 }
4397 else
4398 {
4399 // Do not allow splitter cursor on caption items.
4400 // (also not if we were dragging and its started
4401 // outside the splitter region)
4402
4403 if ( m_propHover &&
4404 !m_propHover->IsCategory() &&
4405 !event.Dragging() )
4406 {
4407
4408 // hovering on splitter
4409
4410 // NB: Condition disabled since MouseLeave event (from the editor control) cannot be
4411 // reliably detected.
4412 //if ( m_curcursor != wxCURSOR_SIZEWE )
4413 CustomSetCursor( wxCURSOR_SIZEWE, true );
4414
4415 return false;
4416 }
4417 else
4418 {
4419 // hovering on something else
4420 if ( m_curcursor != wxCURSOR_ARROW )
4421 CustomSetCursor( wxCURSOR_ARROW );
4422 }
4423 }
4424 }
4425 return true;
4426 }
4427
4428 // -----------------------------------------------------------------------
4429
4430 // Also handles Leaving event
4431 bool wxPropertyGrid::HandleMouseUp( int x, unsigned int WXUNUSED(y),
4432 wxMouseEvent &WXUNUSED(event) )
4433 {
4434 wxPropertyGridPageState* state = m_pState;
4435 bool res = false;
4436
4437 int splitterHit;
4438 int splitterHitOffset;
4439 state->HitTestH( x, &splitterHit, &splitterHitOffset );
4440
4441 // No event type check - basicly calling this method should
4442 // just stop dragging.
4443 // Left up after dragged?
4444 if ( m_dragStatus >= 1 )
4445 {
4446 //
4447 // End Splitter Dragging
4448 //
4449 // DO NOT ENABLE FOLLOWING LINE!
4450 // (it is only here as a reminder to not to do it)
4451 //splitterX = x;
4452
4453 // Disable splitter auto-centering
4454 m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER;
4455
4456 // This is necessary to return cursor
4457 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
4458 {
4459 m_canvas->ReleaseMouse();
4460 m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED);
4461 }
4462
4463 // Set back the default cursor, if necessary
4464 if ( splitterHit == -1 ||
4465 !m_propHover )
4466 {
4467 CustomSetCursor( wxCURSOR_ARROW );
4468 }
4469
4470 m_dragStatus = 0;
4471
4472 // Control background needs to be cleared
4473 if ( !(m_iFlags & wxPG_FL_PRIMARY_FILLS_ENTIRE) && m_selected )
4474 DrawItem( m_selected );
4475
4476 if ( m_wndEditor )
4477 {
4478 m_wndEditor->Show ( true );
4479 }
4480
4481 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
4482 // Fixes button disappearance bug
4483 if ( m_wndEditor2 )
4484 m_wndEditor2->Show ( true );
4485 #endif
4486
4487 // This clears the focus.
4488 m_editorFocused = 0;
4489
4490 }
4491 return res;
4492 }
4493
4494 // -----------------------------------------------------------------------
4495
4496 bool wxPropertyGrid::OnMouseCommon( wxMouseEvent& event, int* px, int* py )
4497 {
4498 int splitterX = GetSplitterPosition();
4499
4500 //int ux, uy;
4501 //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy );
4502 int ux = event.m_x;
4503 int uy = event.m_y;
4504
4505 wxWindow* wnd = GetEditorControl();
4506
4507 // Hide popup on clicks
4508 if ( event.GetEventType() != wxEVT_MOTION )
4509 if ( wnd && wnd->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)) )
4510 {
4511 ((wxOwnerDrawnComboBox*)wnd)->HidePopup();
4512 }
4513
4514 wxRect r;
4515 if ( wnd )
4516 r = wnd->GetRect();
4517 if ( wnd == (wxWindow*) NULL || m_dragStatus ||
4518 (
4519 ux <= (splitterX + wxPG_SPLITTERX_DETECTMARGIN2) ||
4520 ux >= (r.x+r.width) ||
4521 event.m_y < r.y ||
4522 event.m_y >= (r.y+r.height)
4523 )
4524 )
4525 {
4526 *px = ux;
4527 *py = uy;
4528 return true;
4529 }
4530 else
4531 {
4532 if ( m_curcursor != wxCURSOR_ARROW ) CustomSetCursor ( wxCURSOR_ARROW );
4533 }
4534 return false;
4535 }
4536
4537 // -----------------------------------------------------------------------
4538
4539 void wxPropertyGrid::OnMouseClick( wxMouseEvent &event )
4540 {
4541 int x, y;
4542 if ( OnMouseCommon( event, &x, &y ) )
4543 {
4544 HandleMouseClick(x,y,event);
4545 }
4546 event.Skip();
4547 }
4548
4549 // -----------------------------------------------------------------------
4550
4551 void wxPropertyGrid::OnMouseRightClick( wxMouseEvent &event )
4552 {
4553 int x, y;
4554 CalcUnscrolledPosition( event.m_x, event.m_y, &x, &y );
4555 HandleMouseRightClick(x,y,event);
4556 event.Skip();
4557 }
4558
4559 // -----------------------------------------------------------------------
4560
4561 void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent &event )
4562 {
4563 // Always run standard mouse-down handler as well
4564 OnMouseClick(event);
4565
4566 int x, y;
4567 CalcUnscrolledPosition( event.m_x, event.m_y, &x, &y );
4568 HandleMouseDoubleClick(x,y,event);
4569 event.Skip();
4570 }
4571
4572 // -----------------------------------------------------------------------
4573
4574 void wxPropertyGrid::OnMouseMove( wxMouseEvent &event )
4575 {
4576 int x, y;
4577 if ( OnMouseCommon( event, &x, &y ) )
4578 {
4579 HandleMouseMove(x,y,event);
4580 }
4581 event.Skip();
4582 }
4583
4584 // -----------------------------------------------------------------------
4585
4586 void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent& WXUNUSED(event) )
4587 {
4588 // Called when mouse moves in the empty space below the properties.
4589 CustomSetCursor( wxCURSOR_ARROW );
4590 }
4591
4592 // -----------------------------------------------------------------------
4593
4594 void wxPropertyGrid::OnMouseUp( wxMouseEvent &event )
4595 {
4596 int x, y;
4597 if ( OnMouseCommon( event, &x, &y ) )
4598 {
4599 HandleMouseUp(x,y,event);
4600 }
4601 event.Skip();
4602 }
4603
4604 // -----------------------------------------------------------------------
4605
4606 void wxPropertyGrid::OnMouseEntry( wxMouseEvent &event )
4607 {
4608 // This may get called from child control as well, so event's
4609 // mouse position cannot be relied on.
4610
4611 if ( event.Entering() )
4612 {
4613 if ( !(m_iFlags & wxPG_FL_MOUSE_INSIDE) )
4614 {
4615 // TODO: Fix this (detect parent and only do
4616 // cursor trick if it is a manager).
4617 wxASSERT( GetParent() );
4618 GetParent()->SetCursor(wxNullCursor);
4619
4620 m_iFlags |= wxPG_FL_MOUSE_INSIDE;
4621 }
4622 else
4623 GetParent()->SetCursor(wxNullCursor);
4624 }
4625 else if ( event.Leaving() )
4626 {
4627 // Without this, wxSpinCtrl editor will sometimes have wrong cursor
4628 m_canvas->SetCursor( wxNullCursor );
4629
4630 // Get real cursor position
4631 wxPoint pt = ScreenToClient(::wxGetMousePosition());
4632
4633 if ( ( pt.x <= 0 || pt.y <= 0 || pt.x >= m_width || pt.y >= m_height ) )
4634 {
4635 {
4636 if ( (m_iFlags & wxPG_FL_MOUSE_INSIDE) )
4637 {
4638 m_iFlags &= ~(wxPG_FL_MOUSE_INSIDE);
4639 }
4640
4641 if ( m_dragStatus )
4642 wxPropertyGrid::HandleMouseUp ( -1, 10000, event );
4643 }
4644 }
4645 }
4646
4647 event.Skip();
4648 }
4649
4650 // -----------------------------------------------------------------------
4651
4652 // Common code used by various OnMouseXXXChild methods.
4653 bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent &event, int* px, int *py )
4654 {
4655 wxWindow* topCtrlWnd = (wxWindow*)event.GetEventObject();
4656 wxASSERT( topCtrlWnd );
4657 int x, y;
4658 event.GetPosition(&x,&y);
4659
4660 int splitterX = GetSplitterPosition();
4661
4662 wxRect r = topCtrlWnd->GetRect();
4663 if ( !m_dragStatus &&
4664 x > (splitterX-r.x+wxPG_SPLITTERX_DETECTMARGIN2) &&
4665 y >= 0 && y < r.height \
4666 )
4667 {
4668 if ( m_curcursor != wxCURSOR_ARROW ) CustomSetCursor ( wxCURSOR_ARROW );
4669 event.Skip();
4670 }
4671 else
4672 {
4673 CalcUnscrolledPosition( event.m_x + r.x, event.m_y + r.y, \
4674 px, py );
4675 return true;
4676 }
4677 return false;
4678 }
4679
4680 void wxPropertyGrid::OnMouseClickChild( wxMouseEvent &event )
4681 {
4682 int x,y;
4683 if ( OnMouseChildCommon(event,&x,&y) )
4684 {
4685 bool res = HandleMouseClick(x,y,event);
4686 if ( !res ) event.Skip();
4687 }
4688 }
4689
4690 void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent &event )
4691 {
4692 int x,y;
4693 wxASSERT( m_wndEditor );
4694 // These coords may not be exact (about +-2),
4695 // but that should not matter (right click is about item, not position).
4696 wxPoint pt = m_wndEditor->GetPosition();
4697 CalcUnscrolledPosition( event.m_x + pt.x, event.m_y + pt.y, &x, &y );
4698 wxASSERT( m_selected );
4699 m_propHover = m_selected;
4700 bool res = HandleMouseRightClick(x,y,event);
4701 if ( !res ) event.Skip();
4702 }
4703
4704 void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent &event )
4705 {
4706 int x,y;
4707 if ( OnMouseChildCommon(event,&x,&y) )
4708 {
4709 bool res = HandleMouseMove(x,y,event);
4710 if ( !res ) event.Skip();
4711 }
4712 }
4713
4714 void wxPropertyGrid::OnMouseUpChild( wxMouseEvent &event )
4715 {
4716 int x,y;
4717 if ( OnMouseChildCommon(event,&x,&y) )
4718 {
4719 bool res = HandleMouseUp(x,y,event);
4720 if ( !res ) event.Skip();
4721 }
4722 }
4723
4724 // -----------------------------------------------------------------------
4725 // wxPropertyGrid keyboard event handling
4726 // -----------------------------------------------------------------------
4727
4728 int wxPropertyGrid::KeyEventToActions(wxKeyEvent &event, int* pSecond) const
4729 {
4730 // Translates wxKeyEvent to wxPG_ACTION_XXX
4731
4732 int keycode = event.GetKeyCode();
4733 int modifiers = event.GetModifiers();
4734
4735 wxASSERT( !(modifiers&~(0xFFFF)) );
4736
4737 int hashMapKey = (keycode & 0xFFFF) | ((modifiers & 0xFFFF) << 16);
4738
4739 wxPGHashMapI2I::const_iterator it = m_actionTriggers.find(hashMapKey);
4740
4741 if ( it == m_actionTriggers.end() )
4742 return 0;
4743
4744 if ( pSecond )
4745 {
4746 int second = (it->second>>16) & 0xFFFF;
4747 *pSecond = second;
4748 }
4749
4750 return (it->second & 0xFFFF);
4751 }
4752
4753 void wxPropertyGrid::AddActionTrigger( int action, int keycode, int modifiers )
4754 {
4755 wxASSERT( !(modifiers&~(0xFFFF)) );
4756
4757 int hashMapKey = (keycode & 0xFFFF) | ((modifiers & 0xFFFF) << 16);
4758
4759 wxPGHashMapI2I::iterator it = m_actionTriggers.find(hashMapKey);
4760
4761 if ( it != m_actionTriggers.end() )
4762 {
4763 // This key combination is already used
4764
4765 // Can add secondary?
4766 wxASSERT_MSG( !(it->second&~(0xFFFF)),
4767 wxT("You can only add up to two separate actions per key combination.") );
4768
4769 action = it->second | (action<<16);
4770 }
4771
4772 m_actionTriggers[hashMapKey] = action;
4773 }
4774
4775 void wxPropertyGrid::ClearActionTriggers( int action )
4776 {
4777 wxPGHashMapI2I::iterator it;
4778
4779 for ( it = m_actionTriggers.begin(); it != m_actionTriggers.end(); it++ )
4780 {
4781 if ( it->second == action )
4782 {
4783 m_actionTriggers.erase(it);
4784 }
4785 }
4786 }
4787
4788 void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild )
4789 {
4790 //
4791 // Handles key event when editor control is not focused.
4792 //
4793
4794 wxASSERT( !m_frozen );
4795 if ( m_frozen )
4796 return;
4797
4798 // Travelsal between items, collapsing/expanding, etc.
4799 int keycode = event.GetKeyCode();
4800 bool editorFocused = IsEditorFocused();
4801
4802 if ( keycode == WXK_TAB )
4803 {
4804 wxWindow* mainControl;
4805
4806 if ( HasInternalFlag(wxPG_FL_IN_MANAGER) )
4807 mainControl = GetParent();
4808 else
4809 mainControl = this;
4810
4811 if ( !event.ShiftDown() )
4812 {
4813 if ( !editorFocused && m_wndEditor )
4814 {
4815 DoSelectProperty( m_selected, wxPG_SEL_FOCUS );
4816 }
4817 else
4818 {
4819 // Tab traversal workaround for platforms on which
4820 // wxWindow::Navigate() may navigate into first child
4821 // instead of next sibling. Does not work perfectly
4822 // in every scenario (for instance, when property grid
4823 // is either first or last control).
4824 #if defined(__WXGTK__)
4825 wxWindow* sibling = mainControl->GetNextSibling();
4826 if ( sibling )
4827 sibling->SetFocusFromKbd();
4828 #else
4829 Navigate(wxNavigationKeyEvent::IsForward);
4830 #endif
4831 }
4832 }
4833 else
4834 {
4835 if ( editorFocused )
4836 {
4837 UnfocusEditor();
4838 }
4839 else
4840 {
4841 #if defined(__WXGTK__)
4842 wxWindow* sibling = mainControl->GetPrevSibling();
4843 if ( sibling )
4844 sibling->SetFocusFromKbd();
4845 #else
4846 Navigate(wxNavigationKeyEvent::IsBackward);
4847 #endif
4848 }
4849 }
4850
4851 return;
4852 }
4853
4854 // Ignore Alt and Control when they are down alone
4855 if ( keycode == WXK_ALT ||
4856 keycode == WXK_CONTROL )
4857 {
4858 event.Skip();
4859 return;
4860 }
4861
4862 int secondAction;
4863 int action = KeyEventToActions(event, &secondAction);
4864
4865 if ( editorFocused && action == wxPG_ACTION_CANCEL_EDIT )
4866 {
4867 //
4868 // Esc cancels any changes
4869 if ( IsEditorsValueModified() )
4870 {
4871 EditorsValueWasNotModified();
4872
4873 // Update the control as well
4874 m_selected->GetEditorClass()->SetControlStringValue( m_selected,
4875 GetEditorControl(),
4876 m_selected->GetDisplayedString() );
4877 }
4878
4879 OnValidationFailureReset(m_selected);
4880
4881 UnfocusEditor();
4882 return;
4883 }
4884
4885 // Except for TAB and ESC, handle child control events in child control
4886 if ( fromChild )
4887 {
4888 event.Skip();
4889 return;
4890 }
4891
4892 bool wasHandled = false;
4893
4894 if ( m_selected )
4895 {
4896 // Show dialog?
4897 if ( ButtonTriggerKeyTest(action, event) )
4898 return;
4899
4900 wxPGProperty* p = m_selected;
4901
4902 // Travel and expand/collapse
4903 int selectDir = -2;
4904
4905 if ( p->GetChildCount() &&
4906 !(p->m_flags & wxPG_PROP_DISABLED)
4907 )
4908 {
4909 if ( action == wxPG_ACTION_COLLAPSE_PROPERTY || secondAction == wxPG_ACTION_COLLAPSE_PROPERTY )
4910 {
4911 if ( (m_windowStyle & wxPG_HIDE_MARGIN) || Collapse(p) )
4912 wasHandled = true;
4913 }
4914 else if ( action == wxPG_ACTION_EXPAND_PROPERTY || secondAction == wxPG_ACTION_EXPAND_PROPERTY )
4915 {
4916 if ( (m_windowStyle & wxPG_HIDE_MARGIN) || Expand(p) )
4917 wasHandled = true;
4918 }
4919 }
4920
4921 if ( !wasHandled )
4922 {
4923 if ( action == wxPG_ACTION_PREV_PROPERTY || secondAction == wxPG_ACTION_PREV_PROPERTY )
4924 {
4925 selectDir = -1;
4926 }
4927 else if ( action == wxPG_ACTION_NEXT_PROPERTY || secondAction == wxPG_ACTION_NEXT_PROPERTY )
4928 {
4929 selectDir = 1;
4930 }
4931 }
4932
4933 if ( selectDir >= -1 )
4934 {
4935 p = wxPropertyGridIterator::OneStep( m_pState, wxPG_ITERATE_VISIBLE, p, selectDir );
4936 if ( p )
4937 DoSelectProperty(p);
4938 wasHandled = true;
4939 }
4940 }
4941 else
4942 {
4943 // If nothing was selected, select the first item now
4944 // (or navigate out of tab).
4945 if ( action != wxPG_ACTION_CANCEL_EDIT && secondAction != wxPG_ACTION_CANCEL_EDIT )
4946 {
4947 wxPGProperty* p = wxPropertyGridInterface::GetFirst();
4948 if ( p ) DoSelectProperty(p);
4949 wasHandled = true;
4950 }
4951 }
4952
4953 if ( !wasHandled )
4954 event.Skip();
4955 }
4956
4957 // -----------------------------------------------------------------------
4958
4959 void wxPropertyGrid::OnKey( wxKeyEvent &event )
4960 {
4961 HandleKeyEvent(event, false);
4962 }
4963
4964 // -----------------------------------------------------------------------
4965
4966 bool wxPropertyGrid::ButtonTriggerKeyTest( int action, wxKeyEvent& event )
4967 {
4968 if ( action == -1 )
4969 {
4970 int secondAction;
4971 action = KeyEventToActions(event, &secondAction);
4972 }
4973
4974 // Does the keycode trigger button?
4975 if ( action == wxPG_ACTION_PRESS_BUTTON &&
4976 m_wndEditor2 )
4977 {
4978 wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, m_wndEditor2->GetId());
4979 GetEventHandler()->AddPendingEvent(evt);
4980 return true;
4981 }
4982
4983 return false;
4984 }
4985
4986 // -----------------------------------------------------------------------
4987
4988 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent &event )
4989 {
4990 HandleKeyEvent(event, true);
4991 }
4992
4993 // -----------------------------------------------------------------------
4994 // wxPropertyGrid miscellaneous event handling
4995 // -----------------------------------------------------------------------
4996
4997 void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) )
4998 {
4999 //
5000 // Check if the focus is in this control or one of its children
5001 wxWindow* newFocused = wxWindow::FindFocus();
5002
5003 if ( newFocused != m_curFocused )
5004 HandleFocusChange( newFocused );
5005 }
5006
5007 bool wxPropertyGrid::IsEditorFocused() const
5008 {
5009 wxWindow* focus = wxWindow::FindFocus();
5010
5011 if ( focus == m_wndEditor || focus == m_wndEditor2 ||
5012 focus == GetEditorControl() )
5013 return true;
5014
5015 return false;
5016 }
5017
5018 // Called by focus event handlers. newFocused is the window that becomes focused.
5019 void wxPropertyGrid::HandleFocusChange( wxWindow* newFocused )
5020 {
5021 unsigned int oldFlags = m_iFlags;
5022
5023 m_iFlags &= ~(wxPG_FL_FOCUSED);
5024
5025 wxWindow* parent = newFocused;
5026
5027 // This must be one of nextFocus' parents.
5028 while ( parent )
5029 {
5030 // Use m_eventObject, which is either wxPropertyGrid or
5031 // wxPropertyGridManager, as appropriate.
5032 if ( parent == m_eventObject )
5033 {
5034 m_iFlags |= wxPG_FL_FOCUSED;
5035 break;
5036 }
5037 parent = parent->GetParent();
5038 }
5039
5040 m_curFocused = newFocused;
5041
5042 if ( (m_iFlags & wxPG_FL_FOCUSED) !=
5043 (oldFlags & wxPG_FL_FOCUSED) )
5044 {
5045 if ( !(m_iFlags & wxPG_FL_FOCUSED) )
5046 {
5047 // Need to store changed value
5048 CommitChangesFromEditor();
5049 }
5050 else
5051 {
5052 /*
5053 //
5054 // Preliminary code for tab-order respecting
5055 // tab-traversal (but should be moved to
5056 // OnNav handler)
5057 //
5058 wxWindow* prevFocus = event.GetWindow();
5059 wxWindow* useThis = this;
5060 if ( m_iFlags & wxPG_FL_IN_MANAGER )
5061 useThis = GetParent();
5062
5063 if ( prevFocus &&
5064 prevFocus->GetParent() == useThis->GetParent() )
5065 {
5066 wxList& children = useThis->GetParent()->GetChildren();
5067
5068 wxNode* node = children.Find(prevFocus);
5069
5070 if ( node->GetNext() &&
5071 useThis == node->GetNext()->GetData() )
5072 DoSelectProperty(GetFirst());
5073 else if ( node->GetPrevious () &&
5074 useThis == node->GetPrevious()->GetData() )
5075 DoSelectProperty(GetLastProperty());
5076
5077 }
5078 */
5079 }
5080
5081 // Redraw selected
5082 if ( m_selected && (m_iFlags & wxPG_FL_INITIALIZED) )
5083 DrawItem( m_selected );
5084 }
5085 }
5086
5087 void wxPropertyGrid::OnFocusEvent( wxFocusEvent& event )
5088 {
5089 if ( event.GetEventType() == wxEVT_SET_FOCUS )
5090 HandleFocusChange((wxWindow*)event.GetEventObject());
5091 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5092 //else if ( event.GetWindow() )
5093 else
5094 HandleFocusChange(event.GetWindow());
5095
5096 event.Skip();
5097 }
5098
5099 // -----------------------------------------------------------------------
5100
5101 void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent& event )
5102 {
5103 HandleFocusChange((wxWindow*)event.GetEventObject());
5104
5105 //
5106 // event.Skip() being commented out is aworkaround for bug reported
5107 // in ticket #4840 (wxScrolledWindow problem with automatic scrolling).
5108 //event.Skip();
5109 }
5110
5111 // -----------------------------------------------------------------------
5112
5113 void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent &event )
5114 {
5115 m_iFlags |= wxPG_FL_SCROLLED;
5116
5117 event.Skip();
5118 }
5119
5120 // -----------------------------------------------------------------------
5121
5122 void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent& WXUNUSED(event) )
5123 {
5124 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
5125 {
5126 m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED);
5127 }
5128 }
5129
5130 // -----------------------------------------------------------------------
5131 // Property editor related functions
5132 // -----------------------------------------------------------------------
5133
5134 // noDefCheck = true prevents infinite recursion.
5135 wxPGEditor* wxPropertyGrid::RegisterEditorClass( wxPGEditor* editorClass,
5136 bool noDefCheck )
5137 {
5138 wxASSERT( editorClass );
5139
5140 if ( !noDefCheck && wxPGGlobalVars->m_mapEditorClasses.empty() )
5141 RegisterDefaultEditors();
5142
5143 wxString name = editorClass->GetName();
5144
5145 // Existing editor under this name?
5146 wxPGHashMapS2P::iterator vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name);
5147
5148 if ( vt_it != wxPGGlobalVars->m_mapEditorClasses.end() )
5149 {
5150 // If this name was already used, try class name.
5151 name = editorClass->GetClassInfo()->GetClassName();
5152 vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name);
5153 }
5154
5155 wxCHECK_MSG( vt_it == wxPGGlobalVars->m_mapEditorClasses.end(),
5156 (wxPGEditor*) vt_it->second,
5157 "Editor with given name was already registered" );
5158
5159 wxPGGlobalVars->m_mapEditorClasses[name] = (void*)editorClass;
5160
5161 return editorClass;
5162 }
5163
5164 // Use this in RegisterDefaultEditors.
5165 #define wxPGRegisterDefaultEditorClass(EDITOR) \
5166 if ( wxPGEditor_##EDITOR == (wxPGEditor*) NULL ) \
5167 { \
5168 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5169 new wxPG##EDITOR##Editor, true ); \
5170 }
5171
5172 // Registers all default editor classes
5173 void wxPropertyGrid::RegisterDefaultEditors()
5174 {
5175 wxPGRegisterDefaultEditorClass( TextCtrl );
5176 wxPGRegisterDefaultEditorClass( Choice );
5177 wxPGRegisterDefaultEditorClass( ComboBox );
5178 wxPGRegisterDefaultEditorClass( TextCtrlAndButton );
5179 #if wxPG_INCLUDE_CHECKBOX
5180 wxPGRegisterDefaultEditorClass( CheckBox );
5181 #endif
5182 wxPGRegisterDefaultEditorClass( ChoiceAndButton );
5183
5184 // Register SpinCtrl etc. editors before use
5185 RegisterAdditionalEditors();
5186 }
5187
5188 // -----------------------------------------------------------------------
5189 // wxPGStringTokenizer
5190 // Needed to handle C-style string lists (e.g. "str1" "str2")
5191 // -----------------------------------------------------------------------
5192
5193 wxPGStringTokenizer::wxPGStringTokenizer( const wxString& str, wxChar delimeter )
5194 : m_str(&str), m_curPos(str.begin()), m_delimeter(delimeter)
5195 {
5196 }
5197
5198 wxPGStringTokenizer::~wxPGStringTokenizer()
5199 {
5200 }
5201
5202 bool wxPGStringTokenizer::HasMoreTokens()
5203 {
5204 const wxString& str = *m_str;
5205
5206 wxString::const_iterator i = m_curPos;
5207
5208 wxUniChar delim = m_delimeter;
5209 wxUniChar a;
5210 wxUniChar prev_a = wxT('\0');
5211
5212 bool inToken = false;
5213
5214 while ( i != str.end() )
5215 {
5216 a = *i;
5217
5218 if ( !inToken )
5219 {
5220 if ( a == delim )
5221 {
5222 inToken = true;
5223 m_readyToken.clear();
5224 }
5225 }
5226 else
5227 {
5228 if ( prev_a != wxT('\\') )
5229 {
5230 if ( a != delim )
5231 {
5232 if ( a != wxT('\\') )
5233 m_readyToken << a;
5234 }
5235 else
5236 {
5237 i++;
5238 m_curPos = i;
5239 return true;
5240 }
5241 prev_a = a;
5242 }
5243 else
5244 {
5245 m_readyToken << a;
5246 prev_a = wxT('\0');
5247 }
5248 }
5249 i++;
5250 }
5251
5252 m_curPos = str.end();
5253
5254 if ( inToken )
5255 return true;
5256
5257 return false;
5258 }
5259
5260 wxString wxPGStringTokenizer::GetNextToken()
5261 {
5262 return m_readyToken;
5263 }
5264
5265 // -----------------------------------------------------------------------
5266 // wxPGChoiceEntry
5267 // -----------------------------------------------------------------------
5268
5269 wxPGChoiceEntry::wxPGChoiceEntry()
5270 : wxPGCell(), m_value(wxPG_INVALID_VALUE)
5271 {
5272 }
5273
5274 // -----------------------------------------------------------------------
5275 // wxPGChoicesData
5276 // -----------------------------------------------------------------------
5277
5278 wxPGChoicesData::wxPGChoicesData()
5279 {
5280 m_refCount = 1;
5281 }
5282
5283 wxPGChoicesData::~wxPGChoicesData()
5284 {
5285 Clear();
5286 }
5287
5288 void wxPGChoicesData::Clear()
5289 {
5290 m_items.clear();
5291 }
5292
5293 void wxPGChoicesData::CopyDataFrom( wxPGChoicesData* data )
5294 {
5295 wxASSERT( m_items.size() == 0 );
5296
5297 m_items = data->m_items;
5298 }
5299
5300 wxPGChoiceEntry& wxPGChoicesData::Insert( int index,
5301 const wxPGChoiceEntry& item )
5302 {
5303 wxVector<wxPGChoiceEntry>::iterator it;
5304 if ( index == -1 )
5305 {
5306 it = m_items.end();
5307 index = (int) m_items.size();
5308 }
5309 else
5310 {
5311 it = m_items.begin() + index;
5312 }
5313
5314 m_items.insert(it, item);
5315
5316 wxPGChoiceEntry& ownEntry = m_items[index];
5317
5318 // Need to fix value?
5319 if ( ownEntry.GetValue() == wxPG_INVALID_VALUE )
5320 ownEntry.SetValue(index);
5321
5322 return ownEntry;
5323 }
5324
5325 // -----------------------------------------------------------------------
5326 // wxPGChoices
5327 // -----------------------------------------------------------------------
5328
5329 wxPGChoiceEntry& wxPGChoices::Add( const wxString& label, int value )
5330 {
5331 EnsureData();
5332
5333 wxPGChoiceEntry entry(label, value);
5334 return m_data->Insert( -1, entry );
5335 }
5336
5337 // -----------------------------------------------------------------------
5338
5339 wxPGChoiceEntry& wxPGChoices::Add( const wxString& label, const wxBitmap& bitmap, int value )
5340 {
5341 EnsureData();
5342
5343 wxPGChoiceEntry entry(label, value);
5344 entry.SetBitmap(bitmap);
5345 return m_data->Insert( -1, entry );
5346 }
5347
5348 // -----------------------------------------------------------------------
5349
5350 wxPGChoiceEntry& wxPGChoices::Insert( const wxPGChoiceEntry& entry, int index )
5351 {
5352 EnsureData();
5353 return m_data->Insert( index, entry );
5354 }
5355
5356 // -----------------------------------------------------------------------
5357
5358 wxPGChoiceEntry& wxPGChoices::Insert( const wxString& label, int index, int value )
5359 {
5360 EnsureData();
5361
5362 wxPGChoiceEntry entry(label, value);
5363 return m_data->Insert( index, entry );
5364 }
5365
5366 // -----------------------------------------------------------------------
5367
5368 wxPGChoiceEntry& wxPGChoices::AddAsSorted( const wxString& label, int value )
5369 {
5370 EnsureData();
5371
5372 size_t index = 0;
5373
5374 while ( index < GetCount() )
5375 {
5376 int cmpRes = GetLabel(index).Cmp(label);
5377 if ( cmpRes > 0 )
5378 break;
5379 index++;
5380 }
5381
5382 wxPGChoiceEntry entry(label, value);
5383 return m_data->Insert( index, entry );
5384 }
5385
5386 // -----------------------------------------------------------------------
5387
5388 void wxPGChoices::Add( const wxChar** labels, const ValArrItem* values )
5389 {
5390 EnsureData();
5391
5392 unsigned int itemcount = 0;
5393 const wxChar** p = &labels[0];
5394 while ( *p ) { p++; itemcount++; }
5395
5396 unsigned int i;
5397 for ( i = 0; i < itemcount; i++ )
5398 {
5399 int value = i;
5400 if ( values )
5401 value = values[i];
5402 wxPGChoiceEntry entry(labels[i], value);
5403 m_data->Insert( i, entry );
5404 }
5405 }
5406
5407 // -----------------------------------------------------------------------
5408
5409 void wxPGChoices::Add( const wxArrayString& arr, const wxArrayInt& arrint )
5410 {
5411 EnsureData();
5412
5413 unsigned int i;
5414 unsigned int itemcount = arr.size();
5415
5416 for ( i = 0; i < itemcount; i++ )
5417 {
5418 int value = i;
5419 if ( &arrint && arrint.size() )
5420 value = arrint[i];
5421 wxPGChoiceEntry entry(arr[i], value);
5422 m_data->Insert( i, entry );
5423 }
5424 }
5425
5426 // -----------------------------------------------------------------------
5427
5428 void wxPGChoices::RemoveAt(size_t nIndex, size_t count)
5429 {
5430 wxASSERT( m_data->m_refCount != 0xFFFFFFF );
5431 m_data->m_items.erase(m_data->m_items.begin()+nIndex,
5432 m_data->m_items.begin()+nIndex+count);
5433 }
5434
5435 // -----------------------------------------------------------------------
5436
5437 int wxPGChoices::Index( const wxString& str ) const
5438 {
5439 if ( IsOk() )
5440 {
5441 unsigned int i;
5442 for ( i=0; i< m_data->GetCount(); i++ )
5443 {
5444 const wxPGChoiceEntry& entry = m_data->Item(i);
5445 if ( entry.HasText() && entry.GetText() == str )
5446 return i;
5447 }
5448 }
5449 return -1;
5450 }
5451
5452 // -----------------------------------------------------------------------
5453
5454 int wxPGChoices::Index( int val ) const
5455 {
5456 if ( IsOk() )
5457 {
5458 unsigned int i;
5459 for ( i=0; i< m_data->GetCount(); i++ )
5460 {
5461 const wxPGChoiceEntry& entry = m_data->Item(i);
5462 if ( entry.GetValue() == val )
5463 return i;
5464 }
5465 }
5466 return -1;
5467 }
5468
5469 // -----------------------------------------------------------------------
5470
5471 wxArrayString wxPGChoices::GetLabels() const
5472 {
5473 wxArrayString arr;
5474 unsigned int i;
5475
5476 if ( this && IsOk() )
5477 for ( i=0; i<GetCount(); i++ )
5478 arr.push_back(GetLabel(i));
5479
5480 return arr;
5481 }
5482
5483 // -----------------------------------------------------------------------
5484
5485 wxArrayInt wxPGChoices::GetValuesForStrings( const wxArrayString& strings ) const
5486 {
5487 wxArrayInt arr;
5488
5489 if ( IsOk() )
5490 {
5491 unsigned int i;
5492 for ( i=0; i< strings.size(); i++ )
5493 {
5494 int index = Index(strings[i]);
5495 if ( index >= 0 )
5496 arr.Add(GetValue(index));
5497 else
5498 arr.Add(wxPG_INVALID_VALUE);
5499 }
5500 }
5501
5502 return arr;
5503 }
5504
5505 // -----------------------------------------------------------------------
5506
5507 wxArrayInt wxPGChoices::GetIndicesForStrings( const wxArrayString& strings,
5508 wxArrayString* unmatched ) const
5509 {
5510 wxArrayInt arr;
5511
5512 if ( IsOk() )
5513 {
5514 unsigned int i;
5515 for ( i=0; i< strings.size(); i++ )
5516 {
5517 const wxString& str = strings[i];
5518 int index = Index(str);
5519 if ( index >= 0 )
5520 arr.Add(index);
5521 else if ( unmatched )
5522 unmatched->Add(str);
5523 }
5524 }
5525
5526 return arr;
5527 }
5528
5529 // -----------------------------------------------------------------------
5530
5531 void wxPGChoices::AssignData( wxPGChoicesData* data )
5532 {
5533 Free();
5534
5535 if ( data != wxPGChoicesEmptyData )
5536 {
5537 m_data = data;
5538 data->m_refCount++;
5539 }
5540 }
5541
5542 // -----------------------------------------------------------------------
5543
5544 void wxPGChoices::Init()
5545 {
5546 m_data = wxPGChoicesEmptyData;
5547 }
5548
5549 // -----------------------------------------------------------------------
5550
5551 void wxPGChoices::Free()
5552 {
5553 if ( m_data != wxPGChoicesEmptyData )
5554 {
5555 m_data->DecRef();
5556 m_data = wxPGChoicesEmptyData;
5557 }
5558 }
5559
5560 // -----------------------------------------------------------------------
5561 // wxPropertyGridEvent
5562 // -----------------------------------------------------------------------
5563
5564 IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent, wxCommandEvent)
5565
5566
5567 DEFINE_EVENT_TYPE( wxEVT_PG_SELECTED )
5568 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGING )
5569 DEFINE_EVENT_TYPE( wxEVT_PG_CHANGED )
5570 DEFINE_EVENT_TYPE( wxEVT_PG_HIGHLIGHTED )
5571 DEFINE_EVENT_TYPE( wxEVT_PG_RIGHT_CLICK )
5572 DEFINE_EVENT_TYPE( wxEVT_PG_PAGE_CHANGED )
5573 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_EXPANDED )
5574 DEFINE_EVENT_TYPE( wxEVT_PG_ITEM_COLLAPSED )
5575 DEFINE_EVENT_TYPE( wxEVT_PG_DOUBLE_CLICK )
5576
5577
5578 // -----------------------------------------------------------------------
5579
5580 void wxPropertyGridEvent::Init()
5581 {
5582 m_validationInfo = NULL;
5583 m_canVeto = false;
5584 m_wasVetoed = false;
5585 }
5586
5587 // -----------------------------------------------------------------------
5588
5589 wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType, int id)
5590 : wxCommandEvent(commandType,id)
5591 {
5592 m_property = NULL;
5593 Init();
5594 }
5595
5596 // -----------------------------------------------------------------------
5597
5598 wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent& event)
5599 : wxCommandEvent(event)
5600 {
5601 m_eventType = event.GetEventType();
5602 m_eventObject = event.m_eventObject;
5603 m_pg = event.m_pg;
5604 m_property = event.m_property;
5605 m_validationInfo = event.m_validationInfo;
5606 m_canVeto = event.m_canVeto;
5607 m_wasVetoed = event.m_wasVetoed;
5608 }
5609
5610 // -----------------------------------------------------------------------
5611
5612 wxPropertyGridEvent::~wxPropertyGridEvent()
5613 {
5614 }
5615
5616 // -----------------------------------------------------------------------
5617
5618 wxEvent* wxPropertyGridEvent::Clone() const
5619 {
5620 return new wxPropertyGridEvent( *this );
5621 }
5622
5623 // -----------------------------------------------------------------------
5624 // wxPropertyGridPopulator
5625 // -----------------------------------------------------------------------
5626
5627 wxPropertyGridPopulator::wxPropertyGridPopulator()
5628 {
5629 m_state = NULL;
5630 m_pg = NULL;
5631 wxPGGlobalVars->m_offline++;
5632 }
5633
5634 // -----------------------------------------------------------------------
5635
5636 void wxPropertyGridPopulator::SetState( wxPropertyGridPageState* state )
5637 {
5638 m_state = state;
5639 m_propHierarchy.clear();
5640 }
5641
5642 // -----------------------------------------------------------------------
5643
5644 void wxPropertyGridPopulator::SetGrid( wxPropertyGrid* pg )
5645 {
5646 m_pg = pg;
5647 pg->Freeze();
5648 }
5649
5650 // -----------------------------------------------------------------------
5651
5652 wxPropertyGridPopulator::~wxPropertyGridPopulator()
5653 {
5654 //
5655 // Free unused sets of choices
5656 wxPGHashMapS2P::iterator it;
5657
5658 for( it = m_dictIdChoices.begin(); it != m_dictIdChoices.end(); ++it )
5659 {
5660 wxPGChoicesData* data = (wxPGChoicesData*) it->second;
5661 data->DecRef();
5662 }
5663
5664 if ( m_pg )
5665 {
5666 m_pg->Thaw();
5667 m_pg->GetPanel()->Refresh();
5668 }
5669 wxPGGlobalVars->m_offline--;
5670 }
5671
5672 // -----------------------------------------------------------------------
5673
5674 wxPGProperty* wxPropertyGridPopulator::Add( const wxString& propClass,
5675 const wxString& propLabel,
5676 const wxString& propName,
5677 const wxString* propValue,
5678 wxPGChoices* pChoices )
5679 {
5680 wxClassInfo* classInfo = wxClassInfo::FindClass(propClass);
5681 wxPGProperty* parent = GetCurParent();
5682
5683 if ( parent->HasFlag(wxPG_PROP_AGGREGATE) )
5684 {
5685 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent->GetName().c_str()));
5686 return NULL;
5687 }
5688
5689 if ( !classInfo || !classInfo->IsKindOf(CLASSINFO(wxPGProperty)) )
5690 {
5691 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass.c_str()));
5692 return NULL;
5693 }
5694
5695 wxPGProperty* property = (wxPGProperty*) classInfo->CreateObject();
5696
5697 property->SetLabel(propLabel);
5698 property->DoSetName(propName);
5699
5700 if ( pChoices && pChoices->IsOk() )
5701 property->SetChoices(*pChoices);
5702
5703 m_state->DoInsert(parent, -1, property);
5704
5705 if ( propValue )
5706 property->SetValueFromString( *propValue, wxPG_FULL_VALUE|
5707 wxPG_PROGRAMMATIC_VALUE );
5708
5709 return property;
5710 }
5711
5712 // -----------------------------------------------------------------------
5713
5714 void wxPropertyGridPopulator::AddChildren( wxPGProperty* property )
5715 {
5716 m_propHierarchy.push_back(property);
5717 DoScanForChildren();
5718 m_propHierarchy.pop_back();
5719 }
5720
5721 // -----------------------------------------------------------------------
5722
5723 wxPGChoices wxPropertyGridPopulator::ParseChoices( const wxString& choicesString,
5724 const wxString& idString )
5725 {
5726 wxPGChoices choices;
5727
5728 // Using id?
5729 if ( choicesString[0] == wxT('@') )
5730 {
5731 wxString ids = choicesString.substr(1);
5732 wxPGHashMapS2P::iterator it = m_dictIdChoices.find(ids);
5733 if ( it == m_dictIdChoices.end() )
5734 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids.c_str()));
5735 else
5736 choices.AssignData((wxPGChoicesData*)it->second);
5737 }
5738 else
5739 {
5740 bool found = false;
5741 if ( idString.length() )
5742 {
5743 wxPGHashMapS2P::iterator it = m_dictIdChoices.find(idString);
5744 if ( it != m_dictIdChoices.end() )
5745 {
5746 choices.AssignData((wxPGChoicesData*)it->second);
5747 found = true;
5748 }
5749 }
5750
5751 if ( !found )
5752 {
5753 // Parse choices string
5754 wxString::const_iterator it = choicesString.begin();
5755 wxString label;
5756 wxString value;
5757 int state = 0;
5758 bool labelValid = false;
5759
5760 for ( ; it != choicesString.end(); it++ )
5761 {
5762 wxChar c = *it;
5763
5764 if ( state != 1 )
5765 {
5766 if ( c == wxT('"') )
5767 {
5768 if ( labelValid )
5769 {
5770 long l;
5771 if ( !value.ToLong(&l, 0) ) l = wxPG_INVALID_VALUE;
5772 choices.Add(label, l);
5773 }
5774 labelValid = false;
5775 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5776 value.clear();
5777 label.clear();
5778 state = 1;
5779 }
5780 else if ( c == wxT('=') )
5781 {
5782 if ( labelValid )
5783 {
5784 state = 2;
5785 }
5786 }
5787 else if ( state == 2 && (wxIsalnum(c) || c == wxT('x')) )
5788 {
5789 value << c;
5790 }
5791 }
5792 else
5793 {
5794 if ( c == wxT('"') )
5795 {
5796 state = 0;
5797 labelValid = true;
5798 }
5799 else
5800 label << c;
5801 }
5802 }
5803
5804 if ( labelValid )
5805 {
5806 long l;
5807 if ( !value.ToLong(&l, 0) ) l = wxPG_INVALID_VALUE;
5808 choices.Add(label, l);
5809 }
5810
5811 if ( !choices.IsOk() )
5812 {
5813 choices.EnsureData();
5814 }
5815
5816 // Assign to id
5817 if ( idString.length() )
5818 m_dictIdChoices[idString] = choices.GetData();
5819 }
5820 }
5821
5822 return choices;
5823 }
5824
5825 // -----------------------------------------------------------------------
5826
5827 bool wxPropertyGridPopulator::ToLongPCT( const wxString& s, long* pval, long max )
5828 {
5829 if ( s.Last() == wxT('%') )
5830 {
5831 wxString s2 = s.substr(0,s.length()-1);
5832 long val;
5833 if ( s2.ToLong(&val, 10) )
5834 {
5835 *pval = (val*max)/100;
5836 return true;
5837 }
5838 return false;
5839 }
5840
5841 return s.ToLong(pval, 10);
5842 }
5843
5844 // -----------------------------------------------------------------------
5845
5846 bool wxPropertyGridPopulator::AddAttribute( const wxString& name,
5847 const wxString& type,
5848 const wxString& value )
5849 {
5850 int l = m_propHierarchy.size();
5851 if ( !l )
5852 return false;
5853
5854 wxPGProperty* p = m_propHierarchy[l-1];
5855 wxString valuel = value.Lower();
5856 wxVariant variant;
5857
5858 if ( type.length() == 0 )
5859 {
5860 long v;
5861
5862 // Auto-detect type
5863 if ( valuel == wxT("true") || valuel == wxT("yes") || valuel == wxT("1") )
5864 variant = true;
5865 else if ( valuel == wxT("false") || valuel == wxT("no") || valuel == wxT("0") )
5866 variant = false;
5867 else if ( value.ToLong(&v, 0) )
5868 variant = v;
5869 else
5870 variant = value;
5871 }
5872 else
5873 {
5874 if ( type == wxT("string") )
5875 {
5876 variant = value;
5877 }
5878 else if ( type == wxT("int") )
5879 {
5880 long v = 0;
5881 value.ToLong(&v, 0);
5882 variant = v;
5883 }
5884 else if ( type == wxT("bool") )
5885 {
5886 if ( valuel == wxT("true") || valuel == wxT("yes") || valuel == wxT("1") )
5887 variant = true;
5888 else
5889 variant = false;
5890 }
5891 else
5892 {
5893 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type.c_str()));
5894 return false;
5895 }
5896 }
5897
5898 p->SetAttribute( name, variant );
5899
5900 return true;
5901 }
5902
5903 // -----------------------------------------------------------------------
5904
5905 void wxPropertyGridPopulator::ProcessError( const wxString& msg )
5906 {
5907 wxLogError(_("Error in resource: %s"),msg.c_str());
5908 }
5909
5910 // -----------------------------------------------------------------------
5911
5912 #endif // wxUSE_PROPGRID