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