]> git.saurik.com Git - wxWidgets.git/blame - src/propgrid/propgrid.cpp
correct wxASSERT_LEVEL_2 definition
[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
657a8a35 179 // Prepare some shared variants
1c4293cb
VZ
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
1c4293cb 196 m_warnings = 0;
1c4293cb
VZ
197}
198
199
200wxPGGlobalVarsClass::~wxPGGlobalVarsClass()
201{
202 size_t i;
203
204 delete m_defaultRenderer;
205
206 // This will always have one ref
207 delete m_fontFamilyChoices;
208
209#if wxUSE_VALIDATORS
210 for ( i=0; i<m_arrValidators.size(); i++ )
211 delete ((wxValidator*)m_arrValidators[i]);
212#endif
213
214 //
215 // Destroy value type class instances.
216 wxPGHashMapS2P::iterator vt_it;
217
218 // Destroy editor class instances.
219 // iterate over all the elements in the class
220 for( vt_it = m_mapEditorClasses.begin(); vt_it != m_mapEditorClasses.end(); ++vt_it )
221 {
222 delete ((wxPGEditor*)vt_it->second);
223 }
224
225 delete wxPGProperty::sm_wxPG_LABEL;
226}
227
c8074be0
JS
228void wxPropertyGridInitGlobalsIfNeeded()
229{
230}
231
1c4293cb
VZ
232// -----------------------------------------------------------------------
233// wxPGTLWHandler
234// Intercepts Close-events sent to wxPropertyGrid's top-level parent,
235// and tries to commit property value.
236// -----------------------------------------------------------------------
237
238class wxPGTLWHandler : public wxEvtHandler
239{
240public:
241
242 wxPGTLWHandler( wxPropertyGrid* pg )
243 : wxEvtHandler()
244 {
245 m_pg = pg;
246 }
247
248protected:
249
250 void OnClose( wxCloseEvent& event )
251 {
252 // ClearSelection forces value validation/commit.
253 if ( event.CanVeto() && !m_pg->ClearSelection() )
254 {
255 event.Veto();
256 return;
257 }
258
259 event.Skip();
260 }
261
262private:
263 wxPropertyGrid* m_pg;
264
265 DECLARE_EVENT_TABLE()
266};
267
268BEGIN_EVENT_TABLE(wxPGTLWHandler, wxEvtHandler)
269 EVT_CLOSE(wxPGTLWHandler::OnClose)
270END_EVENT_TABLE()
271
272// -----------------------------------------------------------------------
273// wxPGCanvas
274// -----------------------------------------------------------------------
275
276//
277// wxPGCanvas acts as a graphics sub-window of the
278// wxScrolledWindow that wxPropertyGrid is.
279//
280class wxPGCanvas : public wxPanel
281{
282public:
283 wxPGCanvas() : wxPanel()
284 {
285 }
286 virtual ~wxPGCanvas() { }
287
288protected:
289 void OnMouseMove( wxMouseEvent &event )
290 {
291 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
292 pg->OnMouseMove( event );
293 }
294
295 void OnMouseClick( wxMouseEvent &event )
296 {
297 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
298 pg->OnMouseClick( event );
299 }
300
301 void OnMouseUp( wxMouseEvent &event )
302 {
303 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
304 pg->OnMouseUp( event );
305 }
306
307 void OnMouseRightClick( wxMouseEvent &event )
308 {
309 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
310 pg->OnMouseRightClick( event );
311 }
312
313 void OnMouseDoubleClick( wxMouseEvent &event )
314 {
315 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
316 pg->OnMouseDoubleClick( event );
317 }
318
319 void OnKey( wxKeyEvent& event )
320 {
321 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
322 pg->OnKey( event );
323 }
324
1c4293cb 325 void OnPaint( wxPaintEvent& event );
23318a53 326
7a809222
RR
327 // Always be focussable, even with child windows
328 virtual void SetCanFocus(bool WXUNUSED(canFocus))
329 { wxPanel::SetCanFocus(true); }
23318a53 330
7a809222 331
1c4293cb
VZ
332private:
333 DECLARE_EVENT_TABLE()
1e6935a6 334 DECLARE_ABSTRACT_CLASS(wxPGCanvas)
1c4293cb
VZ
335};
336
337
1e6935a6
RR
338IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas,wxPanel)
339
1c4293cb
VZ
340BEGIN_EVENT_TABLE(wxPGCanvas, wxPanel)
341 EVT_MOTION(wxPGCanvas::OnMouseMove)
342 EVT_PAINT(wxPGCanvas::OnPaint)
343 EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick)
344 EVT_LEFT_UP(wxPGCanvas::OnMouseUp)
345 EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick)
346 EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick)
347 EVT_KEY_DOWN(wxPGCanvas::OnKey)
1c4293cb
VZ
348END_EVENT_TABLE()
349
350
351void wxPGCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
352{
353 wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
354 wxASSERT( pg->IsKindOf(CLASSINFO(wxPropertyGrid)) );
355
356 wxPaintDC dc(this);
357
358 // Don't paint after destruction has begun
359 if ( !(pg->GetInternalFlags() & wxPG_FL_INITIALIZED) )
360 return;
361
362 // Update everything inside the box
363 wxRect r = GetUpdateRegion().GetBox();
58fbf261
JS
364
365 // FIXME: This is just a workaround for a bug that causes splitters not
366 // to paint when other windows are being dragged over the grid.
367 wxRect fullRect = GetRect();
368 r.x = fullRect.x;
369 r.width = fullRect.width;
1c4293cb
VZ
370
371 // Repaint this rectangle
372 pg->DrawItems( dc, r.y, r.y + r.height, &r );
373
374 // We assume that the size set when grid is shown
375 // is what is desired.
376 pg->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET);
377}
378
379// -----------------------------------------------------------------------
380// wxPropertyGrid
381// -----------------------------------------------------------------------
382
383IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid, wxScrolledWindow)
384
385BEGIN_EVENT_TABLE(wxPropertyGrid, wxScrolledWindow)
386 EVT_IDLE(wxPropertyGrid::OnIdle)
387 EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom)
388 EVT_PAINT(wxPropertyGrid::OnPaint)
389 EVT_SIZE(wxPropertyGrid::OnResize)
390 EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry)
391 EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry)
392 EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange)
393 EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent)
394 EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent)
395 EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent)
396 EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent)
1c4293cb
VZ
397 EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged)
398END_EVENT_TABLE()
399
400
401// -----------------------------------------------------------------------
402
403wxPropertyGrid::wxPropertyGrid()
404 : wxScrolledWindow()
405{
406 Init1();
407}
408
409// -----------------------------------------------------------------------
410
411wxPropertyGrid::wxPropertyGrid( wxWindow *parent,
412 wxWindowID id,
413 const wxPoint& pos,
414 const wxSize& size,
415 long style,
23318a53 416 const wxString& name )
1c4293cb
VZ
417 : wxScrolledWindow()
418{
419 Init1();
420 Create(parent,id,pos,size,style,name);
421}
422
423// -----------------------------------------------------------------------
424
425bool wxPropertyGrid::Create( wxWindow *parent,
426 wxWindowID id,
427 const wxPoint& pos,
428 const wxSize& size,
429 long style,
23318a53 430 const wxString& name )
1c4293cb
VZ
431{
432
433 if ( !(style&wxBORDER_MASK) )
434 style |= wxSIMPLE_BORDER;
435
436 style |= wxVSCROLL;
437
68f9e025
JS
438 // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
439 style &= ~(wxTAB_TRAVERSAL);
440 style |= wxWANTS_CHARS;
1c4293cb
VZ
441
442 wxScrolledWindow::Create(parent,id,pos,size,style,name);
443
444 Init2();
445
446 return true;
447}
448
449// -----------------------------------------------------------------------
450
451//
452// Initialize values to defaults
453//
454void wxPropertyGrid::Init1()
455{
1c4293cb
VZ
456 // Register editor classes, if necessary.
457 if ( wxPGGlobalVars->m_mapEditorClasses.empty() )
c8074be0 458 wxPropertyGrid::RegisterDefaultEditors();
1c4293cb
VZ
459
460 m_iFlags = 0;
d3b9f782
VZ
461 m_pState = NULL;
462 m_wndEditor = m_wndEditor2 = NULL;
463 m_selected = NULL;
1c4293cb 464 m_selColumn = -1;
d3b9f782 465 m_propHover = NULL;
1c4293cb 466 m_eventObject = this;
d3b9f782 467 m_curFocused = NULL;
1c4293cb 468 m_tlwHandler = NULL;
43396981 469 m_sortFunction = NULL;
1c4293cb
VZ
470 m_inDoPropertyChanged = 0;
471 m_inCommitChangesFromEditor = 0;
472 m_inDoSelectProperty = 0;
473 m_permanentValidationFailureBehavior = wxPG_VFB_DEFAULT;
474 m_dragStatus = 0;
475 m_mouseSide = 16;
476 m_editorFocused = 0;
477
478 // Set default keys
479 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RIGHT );
480 AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN );
481 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_LEFT );
482 AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP );
483 AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY, WXK_RIGHT);
484 AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY, WXK_LEFT);
485 AddActionTrigger( wxPG_ACTION_CANCEL_EDIT, WXK_ESCAPE );
1766bf34 486 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON, WXK_DOWN, wxMOD_ALT );
cfb97361 487 AddActionTrigger( wxPG_ACTION_PRESS_BUTTON, WXK_F4 );
1c4293cb
VZ
488
489 m_coloursCustomized = 0;
490 m_frozen = 0;
491
492 m_canvas = NULL;
493
494#if wxPG_DOUBLE_BUFFER
d3b9f782 495 m_doubleBuffer = NULL;
1c4293cb
VZ
496#endif
497
1c4293cb 498#ifndef wxPG_ICON_WIDTH
657a8a35
VZ
499 m_expandbmp = NULL;
500 m_collbmp = NULL;
501 m_iconWidth = 11;
502 m_iconHeight = 11;
1c4293cb
VZ
503#else
504 m_iconWidth = wxPG_ICON_WIDTH;
505#endif
506
507 m_prevVY = -1;
508
509 m_gutterWidth = wxPG_GUTTER_MIN;
510 m_subgroup_extramargin = 10;
511
512 m_lineHeight = 0;
513
514 m_width = m_height = 0;
515
1c4293cb
VZ
516 m_commonValues.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars->m_defaultRenderer) );
517 m_cvUnspecified = 0;
518
519 m_chgInfo_changedProperty = NULL;
520}
521
522// -----------------------------------------------------------------------
523
524//
525// Initialize after parent etc. set
526//
527void wxPropertyGrid::Init2()
528{
529 wxASSERT( !(m_iFlags & wxPG_FL_INITIALIZED ) );
530
531#ifdef __WXMAC__
532 // Smaller controls on Mac
533 SetWindowVariant(wxWINDOW_VARIANT_SMALL);
23318a53 534#endif
1c4293cb
VZ
535
536 // Now create state, if one didn't exist already
537 // (wxPropertyGridManager might have created it for us).
538 if ( !m_pState )
539 {
540 m_pState = CreateState();
541 m_pState->m_pPropGrid = this;
542 m_iFlags |= wxPG_FL_CREATEDSTATE;
543 }
544
545 if ( !(m_windowStyle & wxPG_SPLITTER_AUTO_CENTER) )
546 m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER;
547
548 if ( m_windowStyle & wxPG_HIDE_CATEGORIES )
549 {
550 m_pState->InitNonCatMode();
551
552 m_pState->m_properties = m_pState->m_abcArray;
553 }
554
555 GetClientSize(&m_width,&m_height);
556
557#ifndef wxPG_ICON_WIDTH
558 // create two bitmap nodes for drawing
657a8a35
VZ
559 m_expandbmp = new wxBitmap(expand_xpm);
560 m_collbmp = new wxBitmap(collapse_xpm);
1c4293cb 561
657a8a35 562 // calculate average font height for bitmap centering
1c4293cb 563
657a8a35
VZ
564 m_iconWidth = m_expandbmp->GetWidth();
565 m_iconHeight = m_expandbmp->GetHeight();
1c4293cb
VZ
566#endif
567
568 m_curcursor = wxCURSOR_ARROW;
569 m_cursorSizeWE = new wxCursor( wxCURSOR_SIZEWE );
570
657a8a35 571 // adjust bitmap icon y position so they are centered
1c4293cb
VZ
572 m_vspacing = wxPG_DEFAULT_VSPACING;
573
2197ec80 574 CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING );
1c4293cb 575
d7e2b522
JS
576 // Allocate cell datas indirectly by calling setter
577 m_propertyDefaultCell.SetBgCol(*wxBLACK);
578 m_categoryDefaultCell.SetBgCol(*wxBLACK);
1c4293cb
VZ
579
580 RegainColours();
581
582 // This helps with flicker
583 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
584
585 // Hook the TLW
586 wxPGTLWHandler* handler = new wxPGTLWHandler(this);
587 m_tlp = ::wxGetTopLevelParent(this);
588 m_tlwHandler = handler;
589 m_tlp->PushEventHandler(handler);
590
657a8a35 591 // set virtual size to this window size
1c4293cb 592 wxSize wndsize = GetSize();
657a8a35 593 SetVirtualSize(wndsize.GetWidth(), wndsize.GetWidth());
1c4293cb
VZ
594
595 m_timeCreated = ::wxGetLocalTimeMillis();
596
597 m_canvas = new wxPGCanvas();
598 m_canvas->Create(this, 1, wxPoint(0, 0), GetClientSize(),
68f9e025 599 wxWANTS_CHARS | wxCLIP_CHILDREN);
1c4293cb
VZ
600 m_canvas->SetBackgroundStyle( wxBG_STYLE_CUSTOM );
601
602 m_iFlags |= wxPG_FL_INITIALIZED;
603
604 m_ncWidth = wndsize.GetWidth();
605
606 // Need to call OnResize handler or size given in constructor/Create
607 // will never work.
608 wxSizeEvent sizeEvent(wndsize,0);
609 OnResize(sizeEvent);
610}
611
612// -----------------------------------------------------------------------
613
614wxPropertyGrid::~wxPropertyGrid()
615{
616 size_t i;
617
618 DoSelectProperty(NULL);
619
620 // This should do prevent things from going too badly wrong
621 m_iFlags &= ~(wxPG_FL_INITIALIZED);
622
623 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
624 m_canvas->ReleaseMouse();
625
626 wxPGTLWHandler* handler = (wxPGTLWHandler*) m_tlwHandler;
627 m_tlp->RemoveEventHandler(handler);
628 delete handler;
629
630#ifdef __WXDEBUG__
631 if ( IsEditorsValueModified() )
632 ::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).)"),
633 wxS("wxPropertyGrid Debug Warning") );
634#endif
635
636#if wxPG_DOUBLE_BUFFER
637 if ( m_doubleBuffer )
638 delete m_doubleBuffer;
639#endif
640
d3b9f782 641 //m_selected = NULL;
1c4293cb
VZ
642
643 if ( m_iFlags & wxPG_FL_CREATEDSTATE )
644 delete m_pState;
645
646 delete m_cursorSizeWE;
647
648#ifndef wxPG_ICON_WIDTH
657a8a35
VZ
649 delete m_expandbmp;
650 delete m_collbmp;
1c4293cb
VZ
651#endif
652
1c4293cb
VZ
653 // Delete common value records
654 for ( i=0; i<m_commonValues.size(); i++ )
655 {
656 delete GetCommonValue(i);
657 }
658}
659
660// -----------------------------------------------------------------------
661
662bool wxPropertyGrid::Destroy()
663{
664 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
665 m_canvas->ReleaseMouse();
666
667 return wxScrolledWindow::Destroy();
668}
669
670// -----------------------------------------------------------------------
671
672wxPropertyGridPageState* wxPropertyGrid::CreateState() const
673{
674 return new wxPropertyGridPageState();
675}
676
677// -----------------------------------------------------------------------
678// wxPropertyGrid overridden wxWindow methods
679// -----------------------------------------------------------------------
680
681void wxPropertyGrid::SetWindowStyleFlag( long style )
682{
683 long old_style = m_windowStyle;
684
685 if ( m_iFlags & wxPG_FL_INITIALIZED )
686 {
687 wxASSERT( m_pState );
688
689 if ( !(style & wxPG_HIDE_CATEGORIES) && (old_style & wxPG_HIDE_CATEGORIES) )
690 {
691 // Enable categories
692 EnableCategories( true );
693 }
694 else if ( (style & wxPG_HIDE_CATEGORIES) && !(old_style & wxPG_HIDE_CATEGORIES) )
695 {
696 // Disable categories
697 EnableCategories( false );
698 }
699 if ( !(old_style & wxPG_AUTO_SORT) && (style & wxPG_AUTO_SORT) )
700 {
701 //
702 // Autosort enabled
703 //
704 if ( !m_frozen )
705 PrepareAfterItemsAdded();
706 else
707 m_pState->m_itemsAdded = 1;
708 }
709 #if wxPG_SUPPORT_TOOLTIPS
710 if ( !(old_style & wxPG_TOOLTIPS) && (style & wxPG_TOOLTIPS) )
711 {
712 //
713 // Tooltips enabled
714 //
715 /*
716 wxToolTip* tooltip = new wxToolTip ( wxEmptyString );
717 SetToolTip ( tooltip );
718 tooltip->SetDelay ( wxPG_TOOLTIP_DELAY );
719 */
720 }
721 else if ( (old_style & wxPG_TOOLTIPS) && !(style & wxPG_TOOLTIPS) )
722 {
723 //
724 // Tooltips disabled
725 //
d3b9f782 726 m_canvas->SetToolTip( NULL );
1c4293cb
VZ
727 }
728 #endif
729 }
730
731 wxScrolledWindow::SetWindowStyleFlag ( style );
732
733 if ( m_iFlags & wxPG_FL_INITIALIZED )
734 {
735 if ( (old_style & wxPG_HIDE_MARGIN) != (style & wxPG_HIDE_MARGIN) )
736 {
737 CalculateFontAndBitmapStuff( m_vspacing );
738 Refresh();
739 }
740 }
741}
742
743// -----------------------------------------------------------------------
744
745void wxPropertyGrid::Freeze()
746{
747 if ( !m_frozen )
748 {
749 wxScrolledWindow::Freeze();
750 }
751 m_frozen++;
752}
753
754// -----------------------------------------------------------------------
755
756void wxPropertyGrid::Thaw()
757{
758 m_frozen--;
759
760 if ( !m_frozen )
761 {
762 wxScrolledWindow::Thaw();
763 RecalculateVirtualSize();
764 #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
765 m_canvas->Refresh();
766 #endif
767
768 // Force property re-selection
769 if ( m_selected )
770 DoSelectProperty(m_selected, wxPG_SEL_FORCE);
771 }
772}
773
774// -----------------------------------------------------------------------
775
776void wxPropertyGrid::SetExtraStyle( long exStyle )
777{
778 if ( exStyle & wxPG_EX_NATIVE_DOUBLE_BUFFERING )
779 {
780#if defined(__WXMSW__)
781
782 /*
783 // Don't use WS_EX_COMPOSITED just now.
784 HWND hWnd;
785
786 if ( m_iFlags & wxPG_FL_IN_MANAGER )
787 hWnd = (HWND)GetParent()->GetHWND();
788 else
789 hWnd = (HWND)GetHWND();
790
791 ::SetWindowLong( hWnd, GWL_EXSTYLE,
792 ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
793 */
794
795//#elif defined(__WXGTK20__)
796#endif
797 // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window
798 // truly was double-buffered.
799 if ( !this->IsDoubleBuffered() )
800 {
801 exStyle &= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING);
802 }
803 else
804 {
805 #if wxPG_DOUBLE_BUFFER
806 delete m_doubleBuffer;
807 m_doubleBuffer = NULL;
808 #endif
809 }
810 }
811
812 wxScrolledWindow::SetExtraStyle( exStyle );
813
814 if ( exStyle & wxPG_EX_INIT_NOCAT )
815 m_pState->InitNonCatMode();
816
817 if ( exStyle & wxPG_EX_HELP_AS_TOOLTIPS )
818 m_windowStyle |= wxPG_TOOLTIPS;
819
820 // Set global style
821 wxPGGlobalVars->m_extraStyle = exStyle;
822}
823
824// -----------------------------------------------------------------------
825
826// returns the best acceptable minimal size
827wxSize wxPropertyGrid::DoGetBestSize() const
828{
829 int hei = 15;
830 if ( m_lineHeight > hei )
831 hei = m_lineHeight;
832 wxSize sz = wxSize( 60, hei+40 );
833
834 CacheBestSize(sz);
835 return sz;
836}
837
838// -----------------------------------------------------------------------
839// wxPropertyGrid Font and Colour Methods
840// -----------------------------------------------------------------------
841
842void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing )
843{
657a8a35 844 int x = 0, y = 0;
1c4293cb
VZ
845
846 m_captionFont = wxScrolledWindow::GetFont();
847
657a8a35 848 GetTextExtent(wxS("jG"), &x, &y, 0, 0, &m_captionFont);
1c4293cb 849 m_subgroup_extramargin = x + (x/2);
657a8a35 850 m_fontHeight = y;
1c4293cb
VZ
851
852#if wxPG_USE_RENDERER_NATIVE
853 m_iconWidth = wxPG_ICON_WIDTH;
854#elif wxPG_ICON_WIDTH
855 // scale icon
856 m_iconWidth = (m_fontHeight * wxPG_ICON_WIDTH) / 13;
857 if ( m_iconWidth < 5 ) m_iconWidth = 5;
858 else if ( !(m_iconWidth & 0x01) ) m_iconWidth++; // must be odd
859
860#endif
861
862 m_gutterWidth = m_iconWidth / wxPG_GUTTER_DIV;
863 if ( m_gutterWidth < wxPG_GUTTER_MIN )
864 m_gutterWidth = wxPG_GUTTER_MIN;
865
866 int vdiv = 6;
867 if ( vspacing <= 1 ) vdiv = 12;
868 else if ( vspacing >= 3 ) vdiv = 3;
869
870 m_spacingy = m_fontHeight / vdiv;
871 if ( m_spacingy < wxPG_YSPACING_MIN )
872 m_spacingy = wxPG_YSPACING_MIN;
873
874 m_marginWidth = 0;
875 if ( !(m_windowStyle & wxPG_HIDE_MARGIN) )
876 m_marginWidth = m_gutterWidth*2 + m_iconWidth;
877
878 m_captionFont.SetWeight(wxBOLD);
657a8a35 879 GetTextExtent(wxS("jG"), &x, &y, 0, 0, &m_captionFont);
1c4293cb
VZ
880
881 m_lineHeight = m_fontHeight+(2*m_spacingy)+1;
1c4293cb
VZ
882
883 // button spacing
884 m_buttonSpacingY = (m_lineHeight - m_iconHeight) / 2;
885 if ( m_buttonSpacingY < 0 ) m_buttonSpacingY = 0;
886
887 if ( m_pState )
888 m_pState->CalculateFontAndBitmapStuff(vspacing);
889
890 if ( m_iFlags & wxPG_FL_INITIALIZED )
891 RecalculateVirtualSize();
892
893 InvalidateBestSize();
894}
895
896// -----------------------------------------------------------------------
897
898void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent &WXUNUSED(event) )
899{
900 RegainColours();
901 Refresh();
902}
903
904// -----------------------------------------------------------------------
905
906static wxColour wxPGAdjustColour(const wxColour& src, int ra,
907 int ga = 1000, int ba = 1000,
908 bool forceDifferent = false)
909{
910 if ( ga >= 1000 )
911 ga = ra;
912 if ( ba >= 1000 )
913 ba = ra;
914
915 // Recursion guard (allow 2 max)
916 static int isinside = 0;
917 isinside++;
918 wxCHECK_MSG( isinside < 3,
919 *wxBLACK,
920 wxT("wxPGAdjustColour should not be recursively called more than once") );
921
922 wxColour dst;
923
924 int r = src.Red();
925 int g = src.Green();
926 int b = src.Blue();
927 int r2 = r + ra;
928 if ( r2>255 ) r2 = 255;
929 else if ( r2<0) r2 = 0;
930 int g2 = g + ga;
931 if ( g2>255 ) g2 = 255;
932 else if ( g2<0) g2 = 0;
933 int b2 = b + ba;
934 if ( b2>255 ) b2 = 255;
935 else if ( b2<0) b2 = 0;
936
937 // Make sure they are somewhat different
938 if ( forceDifferent && (abs((r+g+b)-(r2+g2+b2)) < abs(ra/2)) )
939 dst = wxPGAdjustColour(src,-(ra*2));
940 else
941 dst = wxColour(r2,g2,b2);
942
943 // Recursion guard (allow 2 max)
944 isinside--;
945
946 return dst;
947}
948
949
950static int wxPGGetColAvg( const wxColour& col )
951{
952 return (col.Red() + col.Green() + col.Blue()) / 3;
953}
954
955
956void wxPropertyGrid::RegainColours()
957{
1c4293cb
VZ
958 if ( !(m_coloursCustomized & 0x0002) )
959 {
960 wxColour col = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
961
962 // Make sure colour is dark enough
963 #ifdef __WXGTK__
964 int colDec = wxPGGetColAvg(col) - 230;
965 #else
966 int colDec = wxPGGetColAvg(col) - 200;
967 #endif
968 if ( colDec > 0 )
969 m_colCapBack = wxPGAdjustColour(col,-colDec);
970 else
971 m_colCapBack = col;
d7e2b522 972 m_categoryDefaultCell.GetData()->SetBgCol(m_colCapBack);
1c4293cb
VZ
973 }
974
975 if ( !(m_coloursCustomized & 0x0001) )
976 m_colMargin = m_colCapBack;
977
978 if ( !(m_coloursCustomized & 0x0004) )
979 {
980 #ifdef __WXGTK__
981 int colDec = -90;
982 #else
983 int colDec = -72;
984 #endif
985 wxColour capForeCol = wxPGAdjustColour(m_colCapBack,colDec,5000,5000,true);
986 m_colCapFore = capForeCol;
d7e2b522 987 m_categoryDefaultCell.GetData()->SetFgCol(capForeCol);
1c4293cb
VZ
988 }
989
990 if ( !(m_coloursCustomized & 0x0008) )
991 {
992 wxColour bgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
993 m_colPropBack = bgCol;
d7e2b522 994 m_propertyDefaultCell.GetData()->SetBgCol(bgCol);
1c4293cb
VZ
995 }
996
997 if ( !(m_coloursCustomized & 0x0010) )
998 {
999 wxColour fgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
1000 m_colPropFore = fgCol;
d7e2b522 1001 m_propertyDefaultCell.GetData()->SetFgCol(fgCol);
1c4293cb
VZ
1002 }
1003
1004 if ( !(m_coloursCustomized & 0x0020) )
1005 m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT );
1006
1007 if ( !(m_coloursCustomized & 0x0040) )
1008 m_colSelFore = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
1009
1010 if ( !(m_coloursCustomized & 0x0080) )
1011 m_colLine = m_colCapBack;
1012
1013 if ( !(m_coloursCustomized & 0x0100) )
1014 m_colDisPropFore = m_colCapFore;
1015
1016 m_colEmptySpace = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
1017}
1018
1019// -----------------------------------------------------------------------
1020
1021void wxPropertyGrid::ResetColours()
1022{
1023 m_coloursCustomized = 0;
1024
1025 RegainColours();
1026
1027 Refresh();
1028}
1029
1030// -----------------------------------------------------------------------
1031
1032bool wxPropertyGrid::SetFont( const wxFont& font )
1033{
1034 // Must disable active editor.
1621f192 1035 ClearSelection(false);
1c4293cb 1036
1c4293cb
VZ
1037 bool res = wxScrolledWindow::SetFont( font );
1038 if ( res )
1039 {
1040 CalculateFontAndBitmapStuff( m_vspacing );
1c4293cb
VZ
1041 Refresh();
1042 }
1043
1044 return res;
1c4293cb
VZ
1045}
1046
1047// -----------------------------------------------------------------------
1048
1049void wxPropertyGrid::SetLineColour( const wxColour& col )
1050{
1051 m_colLine = col;
1052 m_coloursCustomized |= 0x80;
1053 Refresh();
1054}
1055
1056// -----------------------------------------------------------------------
1057
1058void wxPropertyGrid::SetMarginColour( const wxColour& col )
1059{
1060 m_colMargin = col;
1061 m_coloursCustomized |= 0x01;
1062 Refresh();
1063}
1064
1065// -----------------------------------------------------------------------
1066
1067void wxPropertyGrid::SetCellBackgroundColour( const wxColour& col )
1068{
1069 m_colPropBack = col;
1070 m_coloursCustomized |= 0x08;
1071
d7e2b522 1072 m_propertyDefaultCell.GetData()->SetBgCol(col);
1c4293cb
VZ
1073
1074 Refresh();
1075}
1076
1077// -----------------------------------------------------------------------
1078
1079void wxPropertyGrid::SetCellTextColour( const wxColour& col )
1080{
1081 m_colPropFore = col;
1082 m_coloursCustomized |= 0x10;
1083
d7e2b522 1084 m_propertyDefaultCell.GetData()->SetFgCol(col);
1c4293cb
VZ
1085
1086 Refresh();
1087}
1088
1089// -----------------------------------------------------------------------
1090
1091void wxPropertyGrid::SetEmptySpaceColour( const wxColour& col )
1092{
1093 m_colEmptySpace = col;
1094
1095 Refresh();
1096}
1097
1098// -----------------------------------------------------------------------
1099
1100void wxPropertyGrid::SetCellDisabledTextColour( const wxColour& col )
1101{
1102 m_colDisPropFore = col;
1103 m_coloursCustomized |= 0x100;
1104 Refresh();
1105}
1106
1107// -----------------------------------------------------------------------
1108
1109void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour& col )
1110{
1111 m_colSelBack = col;
1112 m_coloursCustomized |= 0x20;
1113 Refresh();
1114}
1115
1116// -----------------------------------------------------------------------
1117
1118void wxPropertyGrid::SetSelectionTextColour( const wxColour& col )
1119{
1120 m_colSelFore = col;
1121 m_coloursCustomized |= 0x40;
1122 Refresh();
1123}
1124
1125// -----------------------------------------------------------------------
1126
1127void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour& col )
1128{
1129 m_colCapBack = col;
1130 m_coloursCustomized |= 0x02;
d7e2b522
JS
1131
1132 m_categoryDefaultCell.GetData()->SetBgCol(col);
1133
1c4293cb
VZ
1134 Refresh();
1135}
1136
1137// -----------------------------------------------------------------------
1138
1139void wxPropertyGrid::SetCaptionTextColour( const wxColour& col )
1140{
1141 m_colCapFore = col;
1142 m_coloursCustomized |= 0x04;
1143
d7e2b522 1144 m_categoryDefaultCell.GetData()->SetFgCol(col);
1c4293cb
VZ
1145
1146 Refresh();
1147}
1148
1c4293cb
VZ
1149// -----------------------------------------------------------------------
1150// wxPropertyGrid property adding and removal
1151// -----------------------------------------------------------------------
1152
1153void wxPropertyGrid::PrepareAfterItemsAdded()
1154{
1155 if ( !m_pState || !m_pState->m_itemsAdded ) return;
1156
1157 m_pState->m_itemsAdded = 0;
1158
1159 if ( m_windowStyle & wxPG_AUTO_SORT )
0eb877f2 1160 Sort(wxPG_SORT_TOP_LEVEL_ONLY);
1c4293cb
VZ
1161
1162 RecalculateVirtualSize();
1163}
1164
1c4293cb
VZ
1165// -----------------------------------------------------------------------
1166// wxPropertyGrid property operations
1167// -----------------------------------------------------------------------
1168
1c4293cb
VZ
1169bool wxPropertyGrid::EnsureVisible( wxPGPropArg id )
1170{
1171 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
1172
1173 Update();
1174
1175 bool changed = false;
1176
1177 // Is it inside collapsed section?
1178 if ( !p->IsVisible() )
1179 {
1180 // expand parents
1181 wxPGProperty* parent = p->GetParent();
1182 wxPGProperty* grandparent = parent->GetParent();
1183
1184 if ( grandparent && grandparent != m_pState->m_properties )
1185 Expand( grandparent );
1186
1187 Expand( parent );
1188 changed = true;
1189 }
1190
1191 // Need to scroll?
1192 int vx, vy;
1193 GetViewStart(&vx,&vy);
1194 vy*=wxPG_PIXELS_PER_UNIT;
1195
1196 int y = p->GetY();
1197
1198 if ( y < vy )
1199 {
1200 Scroll(vx, y/wxPG_PIXELS_PER_UNIT );
1201 m_iFlags |= wxPG_FL_SCROLLED;
1202 changed = true;
1203 }
1204 else if ( (y+m_lineHeight) > (vy+m_height) )
1205 {
1206 Scroll(vx, (y-m_height+(m_lineHeight*2))/wxPG_PIXELS_PER_UNIT );
1207 m_iFlags |= wxPG_FL_SCROLLED;
1208 changed = true;
1209 }
1210
1211 if ( changed )
1212 DrawItems( p, p );
1213
1214 return changed;
1215}
1216
1217// -----------------------------------------------------------------------
1218// wxPropertyGrid helper methods called by properties
1219// -----------------------------------------------------------------------
1220
1221// Control font changer helper.
1222void wxPropertyGrid::SetCurControlBoldFont()
1223{
1224 wxASSERT( m_wndEditor );
1225 m_wndEditor->SetFont( m_captionFont );
1226}
1227
1228// -----------------------------------------------------------------------
1229
1230wxPoint wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty* p,
1231 const wxSize& sz )
1232{
1233#if wxPG_SMALL_SCREEN
1234 // On small-screen devices, always show dialogs with default position and size.
1235 return wxDefaultPosition;
1236#else
1237 int splitterX = GetSplitterPosition();
1238 int x = splitterX;
1239 int y = p->GetY();
1240
1241 wxCHECK_MSG( y >= 0, wxPoint(-1,-1), wxT("invalid y?") );
1242
1243 ImprovedClientToScreen( &x, &y );
1244
1245 int sw = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X );
1246 int sh = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y );
1247
1248 int new_x;
1249 int new_y;
1250
1251 if ( x > (sw/2) )
1252 // left
1253 new_x = x + (m_width-splitterX) - sz.x;
1254 else
1255 // right
1256 new_x = x;
1257
1258 if ( y > (sh/2) )
1259 // above
1260 new_y = y - sz.y;
1261 else
1262 // below
1263 new_y = y + m_lineHeight;
1264
1265 return wxPoint(new_x,new_y);
1266#endif
1267}
1268
1269// -----------------------------------------------------------------------
1270
1271wxString& wxPropertyGrid::ExpandEscapeSequences( wxString& dst_str, wxString& src_str )
1272{
1273 if ( src_str.length() == 0 )
1274 {
1275 dst_str = src_str;
1276 return src_str;
1277 }
1278
1279 bool prev_is_slash = false;
1280
1281 wxString::const_iterator i = src_str.begin();
1282
1283 dst_str.clear();
1284
b7bc9d80 1285 for ( ; i != src_str.end(); ++i )
1c4293cb
VZ
1286 {
1287 wxUniChar a = *i;
1288
1289 if ( a != wxS('\\') )
1290 {
1291 if ( !prev_is_slash )
1292 {
1293 dst_str << a;
1294 }
1295 else
1296 {
1297 if ( a == wxS('n') )
1298 {
1299 #ifdef __WXMSW__
1300 dst_str << wxS('\n');
1301 #else
1302 dst_str << wxS('\n');
1303 #endif
1304 }
1305 else if ( a == wxS('t') )
1306 dst_str << wxS('\t');
1307 else
1308 dst_str << a;
1309 }
1310 prev_is_slash = false;
1311 }
1312 else
1313 {
1314 if ( prev_is_slash )
1315 {
1316 dst_str << wxS('\\');
1317 prev_is_slash = false;
1318 }
1319 else
1320 {
1321 prev_is_slash = true;
1322 }
1323 }
1324 }
1325 return dst_str;
1326}
1327
1328// -----------------------------------------------------------------------
1329
1330wxString& wxPropertyGrid::CreateEscapeSequences( wxString& dst_str, wxString& src_str )
1331{
1332 if ( src_str.length() == 0 )
1333 {
1334 dst_str = src_str;
1335 return src_str;
1336 }
1337
1338 wxString::const_iterator i = src_str.begin();
1339 wxUniChar prev_a = wxS('\0');
1340
1341 dst_str.clear();
1342
b7bc9d80 1343 for ( ; i != src_str.end(); ++i )
1c4293cb
VZ
1344 {
1345 wxChar a = *i;
1346
1347 if ( a >= wxS(' ') )
1348 {
1349 // This surely is not something that requires an escape sequence.
1350 dst_str << a;
1351 }
1352 else
1353 {
1354 // This might need...
1355 if ( a == wxS('\r') )
1356 {
1357 // DOS style line end.
1358 // Already taken care below
1359 }
1360 else if ( a == wxS('\n') )
1361 // UNIX style line end.
1362 dst_str << wxS("\\n");
1363 else if ( a == wxS('\t') )
1364 // Tab.
1365 dst_str << wxS('\t');
1366 else
1367 {
1368 //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a);
1369 dst_str << a;
1370 }
1371 }
1372
1373 prev_a = a;
1374 }
1375 return dst_str;
1376}
1377
1378// -----------------------------------------------------------------------
1379
1380wxPGProperty* wxPropertyGrid::DoGetItemAtY( int y ) const
1381{
1382 // Outside?
1383 if ( y < 0 )
d3b9f782 1384 return NULL;
1c4293cb
VZ
1385
1386 unsigned int a = 0;
1387 return m_pState->m_properties->GetItemAtY(y, m_lineHeight, &a);
1388}
1389
1390// -----------------------------------------------------------------------
1391// wxPropertyGrid graphics related methods
1392// -----------------------------------------------------------------------
1393
1394void wxPropertyGrid::OnPaint( wxPaintEvent& WXUNUSED(event) )
1395{
1396 wxPaintDC dc(this);
1397
1398 // Update everything inside the box
1399 wxRect r = GetUpdateRegion().GetBox();
1400
1401 dc.SetPen(m_colEmptySpace);
1402 dc.SetBrush(m_colEmptySpace);
1403 dc.DrawRectangle(r);
1404}
1405
1406// -----------------------------------------------------------------------
1407
1408void wxPropertyGrid::DrawExpanderButton( wxDC& dc, const wxRect& rect,
1409 wxPGProperty* property ) const
1410{
1411 // Prepare rectangle to be used
1412 wxRect r(rect);
1413 r.x += m_gutterWidth; r.y += m_buttonSpacingY;
1414 r.width = m_iconWidth; r.height = m_iconHeight;
1415
1416#if (wxPG_USE_RENDERER_NATIVE)
1417 //
1418#elif wxPG_ICON_WIDTH
1419 // Drawing expand/collapse button manually
1420 dc.SetPen(m_colPropFore);
1421 if ( property->IsCategory() )
1422 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1423 else
1424 dc.SetBrush(m_colPropBack);
1425
1426 dc.DrawRectangle( r );
1427 int _y = r.y+(m_iconWidth/2);
1428 dc.DrawLine(r.x+2,_y,r.x+m_iconWidth-2,_y);
1429#else
1430 wxBitmap* bmp;
1431#endif
1432
1433 if ( property->IsExpanded() )
1434 {
1435 // wxRenderer functions are non-mutating in nature, so it
1436 // should be safe to cast "const wxPropertyGrid*" to "wxWindow*".
1437 // Hopefully this does not cause problems.
1438 #if (wxPG_USE_RENDERER_NATIVE)
1439 wxRendererNative::Get().DrawTreeItemButton(
1440 (wxWindow*)this,
1441 dc,
1442 r,
1443 wxCONTROL_EXPANDED
1444 );
1445 #elif wxPG_ICON_WIDTH
1446 //
1447 #else
1448 bmp = m_collbmp;
1449 #endif
1450
1451 }
1452 else
1453 {
1454 #if (wxPG_USE_RENDERER_NATIVE)
1455 wxRendererNative::Get().DrawTreeItemButton(
1456 (wxWindow*)this,
1457 dc,
1458 r,
1459 0
1460 );
1461 #elif wxPG_ICON_WIDTH
1462 int _x = r.x+(m_iconWidth/2);
1463 dc.DrawLine(_x,r.y+2,_x,r.y+m_iconWidth-2);
1464 #else
1465 bmp = m_expandbmp;
1466 #endif
1467 }
1468
1469#if (wxPG_USE_RENDERER_NATIVE)
1470 //
1471#elif wxPG_ICON_WIDTH
1472 //
1473#else
1474 dc.DrawBitmap( *bmp, r.x, r.y, true );
1475#endif
1476}
1477
1478// -----------------------------------------------------------------------
1479
1480//
1481// This is the one called by OnPaint event handler and others.
1482// topy and bottomy are already unscrolled (ie. physical)
1483//
1484void wxPropertyGrid::DrawItems( wxDC& dc,
1485 unsigned int topy,
1486 unsigned int bottomy,
1487 const wxRect* clipRect )
1488{
1489 if ( m_frozen || m_height < 1 || bottomy < topy || !m_pState ) return;
1490
1491 m_pState->EnsureVirtualHeight();
1492
1493 wxRect tempClipRect;
1494 if ( !clipRect )
1495 {
1496 tempClipRect = wxRect(0,topy,m_pState->m_width,bottomy);
1497 clipRect = &tempClipRect;
1498 }
1499
1500 // items added check
1501 if ( m_pState->m_itemsAdded ) PrepareAfterItemsAdded();
1502
1503 int paintFinishY = 0;
1504
1505 if ( m_pState->m_properties->GetChildCount() > 0 )
1506 {
1507 wxDC* dcPtr = &dc;
1508 bool isBuffered = false;
1509
1510 #if wxPG_DOUBLE_BUFFER
1511 wxMemoryDC* bufferDC = NULL;
1512
1513 if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING) )
1514 {
1515 if ( !m_doubleBuffer )
1516 {
1517 paintFinishY = clipRect->y;
1518 dcPtr = NULL;
1519 }
1520 else
1521 {
1522 bufferDC = new wxMemoryDC();
1523
1524 // If nothing was changed, then just copy from double-buffer
1525 bufferDC->SelectObject( *m_doubleBuffer );
1526 dcPtr = bufferDC;
1527
1528 isBuffered = true;
1529 }
1530 }
1531 #endif
1532
1533 if ( dcPtr )
1534 {
1535 dc.SetClippingRegion( *clipRect );
bcf324be 1536 paintFinishY = DoDrawItems( *dcPtr, clipRect, isBuffered );
1c4293cb
VZ
1537 }
1538
1539 #if wxPG_DOUBLE_BUFFER
1540 if ( bufferDC )
1541 {
1542 dc.Blit( clipRect->x, clipRect->y, clipRect->width, clipRect->height,
1543 bufferDC, 0, 0, wxCOPY );
1544 dc.DestroyClippingRegion(); // Is this really necessary?
1545 delete bufferDC;
1546 }
1547 #endif
1548 }
1549
1550 // Clear area beyond bottomY?
1551 if ( paintFinishY < (clipRect->y+clipRect->height) )
1552 {
1553 dc.SetPen(m_colEmptySpace);
1554 dc.SetBrush(m_colEmptySpace);
1555 dc.DrawRectangle( 0, paintFinishY, m_width, (clipRect->y+clipRect->height) );
1556 }
1557}
1558
1559// -----------------------------------------------------------------------
1560
1561int wxPropertyGrid::DoDrawItems( wxDC& dc,
1c4293cb
VZ
1562 const wxRect* clipRect,
1563 bool isBuffered ) const
1564{
bcf324be
JS
1565 const wxPGProperty* firstItem;
1566 const wxPGProperty* lastItem;
1c4293cb 1567
bcf324be
JS
1568 firstItem = DoGetItemAtY(clipRect->y);
1569 lastItem = DoGetItemAtY(clipRect->y+clipRect->height-1);
1c4293cb
VZ
1570
1571 if ( !lastItem )
bcf324be 1572 lastItem = GetLastItem( wxPG_ITERATE_VISIBLE );
1c4293cb
VZ
1573
1574 if ( m_frozen || m_height < 1 || firstItem == NULL )
1575 return clipRect->y;
1576
1577 wxCHECK_MSG( !m_pState->m_itemsAdded, clipRect->y, wxT("no items added") );
1578 wxASSERT( m_pState->m_properties->GetChildCount() );
1579
1580 int lh = m_lineHeight;
1581
1582 int firstItemTopY;
1583 int lastItemBottomY;
1584
1585 firstItemTopY = clipRect->y;
1586 lastItemBottomY = clipRect->y + clipRect->height;
1587
1588 // Align y coordinates to item boundaries
1589 firstItemTopY -= firstItemTopY % lh;
1590 lastItemBottomY += lh - (lastItemBottomY % lh);
1591 lastItemBottomY -= 1;
1592
1593 // Entire range outside scrolled, visible area?
1594 if ( firstItemTopY >= (int)m_pState->GetVirtualHeight() || lastItemBottomY <= 0 )
1595 return clipRect->y;
1596
1597 wxCHECK_MSG( firstItemTopY < lastItemBottomY, clipRect->y, wxT("invalid y values") );
1598
1599
1600 /*
1601 wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"),
1602 firstItem->GetLabel().c_str(),
1603 lastItem->GetLabel().c_str(),
1604 (int)(lastItemBottomY - firstItemTopY),
1605 (int)m_height,
1606 (unsigned long)clipRect );
1607 */
1608
1609 wxRect r;
1610
1611 long windowStyle = m_windowStyle;
1612
1613 int xRelMod = 0;
1614 int yRelMod = 0;
1615
1616 //
1617 // With wxPG_DOUBLE_BUFFER, do double buffering
1618 // - buffer's y = 0, so align cliprect and coordinates to that
1619 //
1620#if wxPG_DOUBLE_BUFFER
1621
1622 wxRect cr2;
1623
1624 if ( isBuffered )
1625 {
1626 xRelMod = clipRect->x;
1627 yRelMod = clipRect->y;
1628
1629 //
1630 // clipRect conversion
b7bc9d80
PC
1631 cr2 = *clipRect;
1632 cr2.x -= xRelMod;
1633 cr2.y -= yRelMod;
1634 clipRect = &cr2;
1c4293cb
VZ
1635 firstItemTopY -= yRelMod;
1636 lastItemBottomY -= yRelMod;
1637 }
1638#else
1639 wxUnusedVar(isBuffered);
1640#endif
1641
1642 int x = m_marginWidth - xRelMod;
1643
2197ec80 1644 wxFont normalFont = GetFont();
1c4293cb 1645
b7bc9d80 1646 bool reallyFocused = (m_iFlags & wxPG_FL_FOCUSED) != 0;
1c4293cb
VZ
1647
1648 bool isEnabled = IsEnabled();
1649
1650 //
1651 // Prepare some pens and brushes that are often changed to.
1652 //
1653
1654 wxBrush marginBrush(m_colMargin);
1655 wxPen marginPen(m_colMargin);
1656 wxBrush capbgbrush(m_colCapBack,wxSOLID);
1657 wxPen linepen(m_colLine,1,wxSOLID);
1658
1659 // pen that has same colour as text
1660 wxPen outlinepen(m_colPropFore,1,wxSOLID);
1661
1662 //
1663 // Clear margin with background colour
1664 //
1665 dc.SetBrush( marginBrush );
1666 if ( !(windowStyle & wxPG_HIDE_MARGIN) )
1667 {
1668 dc.SetPen( *wxTRANSPARENT_PEN );
1669 dc.DrawRectangle(-1-xRelMod,firstItemTopY-1,x+2,lastItemBottomY-firstItemTopY+2);
1670 }
1671
1672 const wxPGProperty* selected = m_selected;
1673 const wxPropertyGridPageState* state = m_pState;
1674
1675#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1676 bool wasSelectedPainted = false;
1677#endif
1678
1679 // TODO: Only render columns that are within clipping region.
1680
2197ec80 1681 dc.SetFont(normalFont);
1c4293cb
VZ
1682
1683 wxPropertyGridConstIterator it( state, wxPG_ITERATE_VISIBLE, firstItem );
1684 int endScanBottomY = lastItemBottomY + lh;
1685 int y = firstItemTopY;
23b4f320
JS
1686
1687 //
1688 // Pregenerate list of visible properties.
1689 wxArrayPGProperty visPropArray;
1690 visPropArray.reserve((m_height/m_lineHeight)+6);
1c4293cb
VZ
1691
1692 for ( ; !it.AtEnd(); it.Next() )
1693 {
1694 const wxPGProperty* p = *it;
1695
1696 if ( !p->HasFlag(wxPG_PROP_HIDDEN) )
1697 {
23b4f320 1698 visPropArray.push_back((wxPGProperty*)p);
1c4293cb
VZ
1699
1700 if ( y > endScanBottomY )
1701 break;
1702
1703 y += lh;
1704 }
1705 }
1706
23b4f320
JS
1707 visPropArray.push_back(NULL);
1708
1709 wxPGProperty* nextP = visPropArray[0];
1c4293cb
VZ
1710
1711 int gridWidth = state->m_width;
1712
1713 y = firstItemTopY;
23b4f320
JS
1714 for ( unsigned int arrInd=1;
1715 nextP && y <= lastItemBottomY;
1c4293cb
VZ
1716 arrInd++ )
1717 {
23b4f320
JS
1718 wxPGProperty* p = nextP;
1719 nextP = visPropArray[arrInd];
1c4293cb
VZ
1720
1721 int rowHeight = m_fontHeight+(m_spacingy*2)+1;
1722 int textMarginHere = x;
d7e2b522 1723 int renderFlags = 0;
1c4293cb
VZ
1724
1725 int greyDepth = m_marginWidth;
1726 if ( !(windowStyle & wxPG_HIDE_CATEGORIES) )
1727 greyDepth = (((int)p->m_depthBgCol)-1) * m_subgroup_extramargin + m_marginWidth;
1728
1729 int greyDepthX = greyDepth - xRelMod;
1730
1731 // Use basic depth if in non-categoric mode and parent is base array.
1732 if ( !(windowStyle & wxPG_HIDE_CATEGORIES) || p->GetParent() != m_pState->m_properties )
1733 {
1734 textMarginHere += ((unsigned int)((p->m_depth-1)*m_subgroup_extramargin));
1735 }
1736
1737 // Paint margin area
1738 dc.SetBrush(marginBrush);
1739 dc.SetPen(marginPen);
1740 dc.DrawRectangle( -xRelMod, y, greyDepth, lh );
1741
1742 dc.SetPen( linepen );
1743
1744 int y2 = y + lh;
1745
1746 // Margin Edge
1747 dc.DrawLine( greyDepthX, y, greyDepthX, y2 );
1748
1749 // Splitters
1750 unsigned int si;
1751 int sx = x;
1752
1753 for ( si=0; si<state->m_colWidths.size(); si++ )
1754 {
1755 sx += state->m_colWidths[si];
1756 dc.DrawLine( sx, y, sx, y2 );
1757 }
1758
1759 // Horizontal Line, below
1760 // (not if both this and next is category caption)
1761 if ( p->IsCategory() &&
1762 nextP && nextP->IsCategory() )
1763 dc.SetPen(m_colCapBack);
1764
1765 dc.DrawLine( greyDepthX, y2-1, gridWidth-xRelMod, y2-1 );
1766
d7e2b522
JS
1767 //
1768 // Need to override row colours?
1c4293cb 1769 wxColour rowFgCol;
d7e2b522 1770 wxColour rowBgCol;
1c4293cb 1771
d7e2b522 1772 if ( p != selected )
1c4293cb
VZ
1773 {
1774 // Disabled may get different colour.
1775 if ( !p->IsEnabled() )
d7e2b522
JS
1776 {
1777 renderFlags |= wxPGCellRenderer::Disabled |
1778 wxPGCellRenderer::DontUseCellFgCol;
1c4293cb 1779 rowFgCol = m_colDisPropFore;
d7e2b522 1780 }
1c4293cb
VZ
1781 }
1782 else
1783 {
b7bc9d80 1784 renderFlags |= wxPGCellRenderer::Selected;
d7e2b522 1785
b7bc9d80
PC
1786 if ( !p->IsCategory() )
1787 {
d7e2b522
JS
1788 renderFlags |= wxPGCellRenderer::DontUseCellFgCol |
1789 wxPGCellRenderer::DontUseCellBgCol;
1790
1791#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1792 wasSelectedPainted = true;
1793#endif
1794
1795 // Selected gets different colour.
1796 if ( reallyFocused )
1797 {
1798 rowFgCol = m_colSelFore;
1799 rowBgCol = m_colSelBack;
1800 }
1801 else if ( isEnabled )
1802 {
1803 rowFgCol = m_colPropFore;
1804 rowBgCol = m_colMargin;
1805 }
1806 else
1807 {
1808 rowFgCol = m_colDisPropFore;
1809 rowBgCol = m_colSelBack;
1810 }
1c4293cb 1811 }
d7e2b522
JS
1812 }
1813
1814 wxBrush rowBgBrush;
1815
1816 if ( rowBgCol.IsOk() )
1817 rowBgBrush = wxBrush(rowBgCol);
1818
1819 if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL) )
1820 renderFlags = renderFlags & ~wxPGCellRenderer::DontUseCellColours;
1821
1822 //
1823 // Fill additional margin area with background colour of first cell
1824 if ( greyDepthX < textMarginHere )
1825 {
1826 if ( !(renderFlags & wxPGCellRenderer::DontUseCellBgCol) )
1c4293cb 1827 {
d7e2b522
JS
1828 wxPGCell& cell = p->GetCell(0);
1829 rowBgCol = cell.GetBgCol();
1830 rowBgBrush = wxBrush(rowBgCol);
1c4293cb 1831 }
d7e2b522
JS
1832 dc.SetBrush(rowBgBrush);
1833 dc.SetPen(rowBgCol);
1834 dc.DrawRectangle(greyDepthX+1, y,
1835 textMarginHere-greyDepthX, lh-1);
1c4293cb
VZ
1836 }
1837
1838 bool fontChanged = false;
1839
d7e2b522 1840 // Expander button rectangle
1c4293cb
VZ
1841 wxRect butRect( ((p->m_depth - 1) * m_subgroup_extramargin) - xRelMod,
1842 y,
1843 m_marginWidth,
1844 lh );
1845
1846 if ( p->IsCategory() )
1847 {
d7e2b522 1848 // Captions have their cell areas merged as one
1c4293cb
VZ
1849 dc.SetFont(m_captionFont);
1850 fontChanged = true;
1851 wxRect cellRect(greyDepthX, y, gridWidth - greyDepth + 2, rowHeight-1 );
1852
d7e2b522
JS
1853 if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol )
1854 {
1855 dc.SetBrush(rowBgBrush);
1856 dc.SetPen(rowBgCol);
1857 }
1c4293cb 1858
d7e2b522
JS
1859 if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol )
1860 {
1861 dc.SetTextForeground(rowFgCol);
1862 }
1c4293cb 1863
1c4293cb
VZ
1864 wxPGCellRenderer* renderer = p->GetCellRenderer(0);
1865 renderer->Render( dc, cellRect, this, p, 0, -1, renderFlags );
1866
1867 // Tree Item Button
1868 if ( !HasFlag(wxPG_HIDE_MARGIN) && p->HasVisibleChildren() )
1869 DrawExpanderButton( dc, butRect, p );
1870 }
1871 else
1872 {
1873 if ( p->m_flags & wxPG_PROP_MODIFIED && (windowStyle & wxPG_BOLD_MODIFIED) )
1874 {
1875 dc.SetFont(m_captionFont);
1876 fontChanged = true;
1877 }
1878
1879 unsigned int ci;
1880 int cellX = x + 1;
9667d393
JS
1881 int nextCellWidth = state->m_colWidths[0] -
1882 (greyDepthX - m_marginWidth);
1c4293cb
VZ
1883 wxRect cellRect(greyDepthX+1, y, 0, rowHeight-1);
1884 int textXAdd = textMarginHere - greyDepthX;
1885
1886 for ( ci=0; ci<state->m_colWidths.size(); ci++ )
1887 {
1888 cellRect.width = nextCellWidth - 1;
1889
1890 bool ctrlCell = false;
d7e2b522
JS
1891 int cellRenderFlags = renderFlags;
1892
1893 // Tree Item Button
1894 if ( ci == 0 && !HasFlag(wxPG_HIDE_MARGIN) && p->HasVisibleChildren() )
1895 DrawExpanderButton( dc, butRect, p );
1c4293cb
VZ
1896
1897 // Background
1898 if ( p == selected && m_wndEditor && ci == 1 )
1899 {
1900 wxColour editorBgCol = GetEditorControl()->GetBackgroundColour();
1901 dc.SetBrush(editorBgCol);
1902 dc.SetPen(editorBgCol);
1903 dc.SetTextForeground(m_colPropFore);
d7e2b522 1904 dc.DrawRectangle(cellRect);
1c4293cb
VZ
1905
1906 if ( m_dragStatus == 0 && !(m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE) )
1907 ctrlCell = true;
1908 }
1909 else
1910 {
d7e2b522
JS
1911 if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol )
1912 {
1913 dc.SetBrush(rowBgBrush);
1914 dc.SetPen(rowBgCol);
1915 }
1c4293cb 1916
d7e2b522
JS
1917 if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol )
1918 {
1919 dc.SetTextForeground(rowFgCol);
1920 }
1921 }
1c4293cb
VZ
1922
1923 dc.SetClippingRegion(cellRect);
1924
1925 cellRect.x += textXAdd;
1926 cellRect.width -= textXAdd;
1927
1928 // Foreground
1929 if ( !ctrlCell )
1930 {
1931 wxPGCellRenderer* renderer;
1932 int cmnVal = p->GetCommonValue();
1933 if ( cmnVal == -1 || ci != 1 )
1934 {
1935 renderer = p->GetCellRenderer(ci);
d7e2b522
JS
1936 renderer->Render( dc, cellRect, this, p, ci, -1,
1937 cellRenderFlags );
1c4293cb
VZ
1938 }
1939 else
1940 {
1941 renderer = GetCommonValue(cmnVal)->GetRenderer();
d7e2b522
JS
1942 renderer->Render( dc, cellRect, this, p, ci, -1,
1943 cellRenderFlags );
1c4293cb
VZ
1944 }
1945 }
1946
1947 cellX += state->m_colWidths[ci];
1948 if ( ci < (state->m_colWidths.size()-1) )
1949 nextCellWidth = state->m_colWidths[ci+1];
23318a53 1950 cellRect.x = cellX;
1c4293cb
VZ
1951 dc.DestroyClippingRegion(); // Is this really necessary?
1952 textXAdd = 0;
1953 }
1954 }
1955
1956 if ( fontChanged )
2197ec80 1957 dc.SetFont(normalFont);
1c4293cb
VZ
1958
1959 y += rowHeight;
1960 }
1961
1962 // Refresh editor controls (seems not needed on msw)
1963 // NOTE: This code is mandatory for GTK!
1964#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
1965 if ( wasSelectedPainted )
1966 {
1967 if ( m_wndEditor )
1968 m_wndEditor->Refresh();
1969 if ( m_wndEditor2 )
1970 m_wndEditor2->Refresh();
1971 }
1972#endif
1973
1974 return y + yRelMod;
1975}
1976
1977// -----------------------------------------------------------------------
1978
1979wxRect wxPropertyGrid::GetPropertyRect( const wxPGProperty* p1, const wxPGProperty* p2 ) const
1980{
1981 wxRect r;
1982
1983 if ( m_width < 10 || m_height < 10 ||
1984 !m_pState->m_properties->GetChildCount() ||
d3b9f782 1985 p1 == NULL )
1c4293cb
VZ
1986 return wxRect(0,0,0,0);
1987
1988 int vy = 0;
1989
1990 //
1991 // Return rect which encloses the given property range
1992
1993 int visTop = p1->GetY();
1994 int visBottom;
1995 if ( p2 )
1996 visBottom = p2->GetY() + m_lineHeight;
1997 else
1998 visBottom = m_height + visTop;
1999
2000 // If seleced property is inside the range, we'll extend the range to include
2001 // control's size.
2002 wxPGProperty* selected = m_selected;
2003 if ( selected )
2004 {
2005 int selectedY = selected->GetY();
2006 if ( selectedY >= visTop && selectedY < visBottom )
2007 {
2008 wxWindow* editor = GetEditorControl();
2009 if ( editor )
2010 {
2011 int visBottom2 = selectedY + editor->GetSize().y;
2012 if ( visBottom2 > visBottom )
2013 visBottom = visBottom2;
2014 }
2015 }
2016 }
2017
2018 return wxRect(0,visTop-vy,m_pState->m_width,visBottom-visTop);
2019}
2020
2021// -----------------------------------------------------------------------
2022
2023void wxPropertyGrid::DrawItems( const wxPGProperty* p1, const wxPGProperty* p2 )
2024{
2025 if ( m_frozen )
2026 return;
2027
2028 if ( m_pState->m_itemsAdded )
2029 PrepareAfterItemsAdded();
2030
2031 wxRect r = GetPropertyRect(p1, p2);
2032 if ( r.width > 0 )
2033 {
2034 m_canvas->RefreshRect(r);
2035 }
2036}
2037
2038// -----------------------------------------------------------------------
2039
2040void wxPropertyGrid::RefreshProperty( wxPGProperty* p )
2041{
2042 if ( p == m_selected )
2043 DoSelectProperty(p, wxPG_SEL_FORCE);
2044
2045 DrawItemAndChildren(p);
2046}
2047
2048// -----------------------------------------------------------------------
2049
2050void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty* p )
2051{
2052 if ( m_frozen )
2053 return;
2054
2055 // Draw item, children, and parent too, if it is not category
2056 wxPGProperty* parent = p->GetParent();
2057
2058 while ( parent &&
2059 !parent->IsCategory() &&
2060 parent->GetParent() )
2061 {
2062 DrawItem(parent);
2063 parent = parent->GetParent();
2064 }
2065
2066 DrawItemAndChildren(p);
2067}
2068
2069void wxPropertyGrid::DrawItemAndChildren( wxPGProperty* p )
2070{
2071 wxCHECK_RET( p, wxT("invalid property id") );
2072
2073 // Do not draw if in non-visible page
2074 if ( p->GetParentState() != m_pState )
2075 return;
2076
2077 // do not draw a single item if multiple pending
2078 if ( m_pState->m_itemsAdded || m_frozen )
2079 return;
2080
1c4293cb
VZ
2081 // Update child control.
2082 if ( m_selected && m_selected->GetParent() == p )
a6353fe8 2083 RefreshEditor();
1c4293cb
VZ
2084
2085 const wxPGProperty* lastDrawn = p->GetLastVisibleSubItem();
2086
2087 DrawItems(p, lastDrawn);
2088}
2089
2090// -----------------------------------------------------------------------
2091
2092void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground),
2093 const wxRect *rect )
2094{
2095 PrepareAfterItemsAdded();
2096
2097 wxWindow::Refresh(false);
2098 if ( m_canvas )
2099 // TODO: Coordinate translation
2100 m_canvas->Refresh(false, rect);
2101
2102#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2103 // I think this really helps only GTK+1.2
2104 if ( m_wndEditor ) m_wndEditor->Refresh();
2105 if ( m_wndEditor2 ) m_wndEditor2->Refresh();
2106#endif
2107}
2108
2109// -----------------------------------------------------------------------
2110// wxPropertyGrid global operations
2111// -----------------------------------------------------------------------
2112
2113void wxPropertyGrid::Clear()
2114{
1c4293cb
VZ
2115 m_pState->DoClear();
2116
2117 m_propHover = NULL;
2118
2119 m_prevVY = 0;
2120
2121 RecalculateVirtualSize();
2122
2123 // Need to clear some area at the end
2124 if ( !m_frozen )
2125 RefreshRect(wxRect(0, 0, m_width, m_height));
2126}
2127
2128// -----------------------------------------------------------------------
2129
2130bool wxPropertyGrid::EnableCategories( bool enable )
2131{
1621f192 2132 ClearSelection(false);
1c4293cb
VZ
2133
2134 if ( enable )
2135 {
2136 //
2137 // Enable categories
2138 //
2139
2140 m_windowStyle &= ~(wxPG_HIDE_CATEGORIES);
2141 }
2142 else
2143 {
2144 //
2145 // Disable categories
2146 //
2147 m_windowStyle |= wxPG_HIDE_CATEGORIES;
2148 }
2149
2150 if ( !m_pState->EnableCategories(enable) )
2151 return false;
2152
2153 if ( !m_frozen )
2154 {
2155 if ( m_windowStyle & wxPG_AUTO_SORT )
2156 {
2157 m_pState->m_itemsAdded = 1; // force
2158 PrepareAfterItemsAdded();
2159 }
2160 }
2161 else
2162 m_pState->m_itemsAdded = 1;
2163
2164 // No need for RecalculateVirtualSize() here - it is already called in
2165 // wxPropertyGridPageState method above.
2166
2167 Refresh();
2168
2169 return true;
2170}
2171
2172// -----------------------------------------------------------------------
2173
2174void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState )
2175{
2176 wxASSERT( pNewState );
2177 wxASSERT( pNewState->GetGrid() );
2178
2179 if ( pNewState == m_pState )
2180 return;
2181
2182 wxPGProperty* oldSelection = m_selected;
2183
1621f192 2184 ClearSelection(false);
1c4293cb
VZ
2185
2186 m_pState->m_selected = oldSelection;
2187
2188 bool orig_mode = m_pState->IsInNonCatMode();
2189 bool new_state_mode = pNewState->IsInNonCatMode();
2190
2191 m_pState = pNewState;
2192
2193 // Validate width
2194 int pgWidth = GetClientSize().x;
2195 if ( HasVirtualWidth() )
2196 {
2197 int minWidth = pgWidth;
2198 if ( pNewState->m_width < minWidth )
2199 {
2200 pNewState->m_width = minWidth;
2201 pNewState->CheckColumnWidths();
2202 }
2203 }
2204 else
2205 {
2206 //
2207 // Just in case, fully re-center splitter
2208 if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) )
2209 pNewState->m_fSplitterX = -1.0;
2210
2211 pNewState->OnClientWidthChange( pgWidth, pgWidth - pNewState->m_width );
2212 }
2213
d3b9f782 2214 m_propHover = NULL;
1c4293cb
VZ
2215
2216 // If necessary, convert state to correct mode.
2217 if ( orig_mode != new_state_mode )
2218 {
2219 // This should refresh as well.
2220 EnableCategories( orig_mode?false:true );
2221 }
2222 else if ( !m_frozen )
2223 {
2224 // Refresh, if not frozen.
0eb877f2 2225 m_pState->PrepareAfterItemsAdded();
1c4293cb
VZ
2226
2227 // Reselect
2228 if ( m_pState->m_selected )
2229 DoSelectProperty( m_pState->m_selected );
2230
2231 RecalculateVirtualSize(0);
2232 Refresh();
2233 }
2234 else
2235 m_pState->m_itemsAdded = 1;
2236}
2237
2238// -----------------------------------------------------------------------
2239
1c4293cb
VZ
2240// Call to SetSplitterPosition will always disable splitter auto-centering
2241// if parent window is shown.
2242void wxPropertyGrid::DoSetSplitterPosition_( int newxpos, bool refresh, int splitterIndex, bool allPages )
2243{
2244 if ( ( newxpos < wxPG_DRAG_MARGIN ) )
2245 return;
2246
2247 wxPropertyGridPageState* state = m_pState;
2248
2249 state->DoSetSplitterPosition( newxpos, splitterIndex, allPages );
2250
2251 if ( refresh )
2252 {
2253 if ( m_selected )
2254 CorrectEditorWidgetSizeX();
2255
2256 Refresh();
2257 }
2258}
2259
2260// -----------------------------------------------------------------------
2261
2262void wxPropertyGrid::CenterSplitter( bool enableAutoCentering )
2263{
2264 SetSplitterPosition( m_width/2, true );
2265 if ( enableAutoCentering && ( m_windowStyle & wxPG_SPLITTER_AUTO_CENTER ) )
2266 m_iFlags &= ~(wxPG_FL_DONT_CENTER_SPLITTER);
2267}
2268
2269// -----------------------------------------------------------------------
2270// wxPropertyGrid item iteration (GetNextProperty etc.) methods
2271// -----------------------------------------------------------------------
2272
2273// Returns nearest paint visible property (such that will be painted unless
2274// window is scrolled or resized). If given property is paint visible, then
2275// it itself will be returned
2276wxPGProperty* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty* p ) const
2277{
2278 int vx,vy1;// Top left corner of client
2279 GetViewStart(&vx,&vy1);
2280 vy1 *= wxPG_PIXELS_PER_UNIT;
2281
2282 int vy2 = vy1 + m_height;
2283 int propY = p->GetY2(m_lineHeight);
2284
2285 if ( (propY + m_lineHeight) < vy1 )
2286 {
2287 // Too high
2288 return DoGetItemAtY( vy1 );
2289 }
2290 else if ( propY > vy2 )
2291 {
2292 // Too low
2293 return DoGetItemAtY( vy2 );
2294 }
2295
2296 // Itself paint visible
2297 return p;
2298
2299}
2300
1c4293cb
VZ
2301// -----------------------------------------------------------------------
2302// Methods related to change in value, value modification and sending events
2303// -----------------------------------------------------------------------
2304
2305// commits any changes in editor of selected property
2306// return true if validation did not fail
2307// flags are same as with DoSelectProperty
2308bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags )
2309{
2310 // Committing already?
2311 if ( m_inCommitChangesFromEditor )
2312 return true;
2313
2314 // Don't do this if already processing editor event. It might
2315 // induce recursive dialogs and crap like that.
b0996c3d 2316 if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT )
1c4293cb
VZ
2317 {
2318 if ( m_inDoPropertyChanged )
2319 return true;
2320
2321 return false;
2322 }
2323
2324 if ( m_wndEditor &&
2325 IsEditorsValueModified() &&
2326 (m_iFlags & wxPG_FL_INITIALIZED) &&
2327 m_selected )
2328 {
2329 m_inCommitChangesFromEditor = 1;
2330
2331 wxVariant variant(m_selected->GetValueRef());
2332 bool valueIsPending = false;
2333
2334 // JACS - necessary to avoid new focus being found spuriously within OnIdle
2335 // due to another window getting focus
2336 wxWindow* oldFocus = m_curFocused;
2337
2338 bool validationFailure = false;
2339 bool forceSuccess = (flags & (wxPG_SEL_NOVALIDATE|wxPG_SEL_FORCE)) ? true : false;
2340
2341 m_chgInfo_changedProperty = NULL;
2342
2343 // If truly modified, schedule value as pending.
2344 if ( m_selected->GetEditorClass()->GetValueFromControl( variant, m_selected, GetEditorControl() ) )
2345 {
2346 if ( DoEditorValidate() &&
2347 PerformValidation(m_selected, variant) )
2348 {
2349 valueIsPending = true;
2350 }
2351 else
2352 {
2353 validationFailure = true;
2354 }
2355 }
2356 else
2357 {
2358 EditorsValueWasNotModified();
2359 }
2360
2361 bool res = true;
2362
2363 m_inCommitChangesFromEditor = 0;
2364
2365 if ( validationFailure && !forceSuccess )
2366 {
2367 if (oldFocus)
2368 {
2369 oldFocus->SetFocus();
2370 m_curFocused = oldFocus;
2371 }
2372
2373 res = OnValidationFailure(m_selected, variant);
2374
2375 // Now prevent further validation failure messages
2376 if ( res )
2377 {
2378 EditorsValueWasNotModified();
2379 OnValidationFailureReset(m_selected);
2380 }
2381 }
2382 else if ( valueIsPending )
2383 {
2384 DoPropertyChanged( m_selected, flags );
2385 EditorsValueWasNotModified();
2386 }
2387
2388 return res;
2389 }
2390
2391 return true;
2392}
2393
2394// -----------------------------------------------------------------------
2395
9b5bafcf
JS
2396bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue,
2397 int flags )
1c4293cb
VZ
2398{
2399 //
2400 // Runs all validation functionality.
2401 // Returns true if value passes all tests.
2402 //
2403
2404 m_validationInfo.m_failureBehavior = m_permanentValidationFailureBehavior;
2405
0372d42e 2406 if ( pendingValue.GetType() == wxPG_VARIANT_TYPE_LIST )
1c4293cb
VZ
2407 {
2408 if ( !p->ValidateValue(pendingValue, m_validationInfo) )
2409 return false;
2410 }
2411
2412 //
2413 // Adapt list to child values, if necessary
2414 wxVariant listValue = pendingValue;
2415 wxVariant* pPendingValue = &pendingValue;
2416 wxVariant* pList = NULL;
2417
2418 // If parent has wxPG_PROP_AGGREGATE flag, or uses composite
2419 // string value, then we need treat as it was changed instead
2420 // (or, in addition, as is the case with composite string parent).
2421 // This includes creating list variant for child values.
2422
2423 wxPGProperty* pwc = p->GetParent();
2424 wxPGProperty* changedProperty = p;
2425 wxPGProperty* baseChangedProperty = changedProperty;
2426 wxVariant bcpPendingList;
2427
2428 listValue = pendingValue;
d665918b 2429 listValue.SetName(p->GetBaseName());
1c4293cb
VZ
2430
2431 while ( pwc &&
2432 (pwc->HasFlag(wxPG_PROP_AGGREGATE) || pwc->HasFlag(wxPG_PROP_COMPOSED_VALUE)) )
2433 {
2434 wxVariantList tempList;
d665918b 2435 wxVariant lv(tempList, pwc->GetBaseName());
1c4293cb
VZ
2436 lv.Append(listValue);
2437 listValue = lv;
2438 pPendingValue = &listValue;
2439
2440 if ( pwc->HasFlag(wxPG_PROP_AGGREGATE) )
2441 {
2442 baseChangedProperty = pwc;
2443 bcpPendingList = lv;
2444 }
2445
2446 changedProperty = pwc;
2447 pwc = pwc->GetParent();
2448 }
2449
2450 wxVariant value;
2451 wxPGProperty* evtChangingProperty = changedProperty;
2452
0372d42e 2453 if ( pPendingValue->GetType() != wxPG_VARIANT_TYPE_LIST )
1c4293cb
VZ
2454 {
2455 value = *pPendingValue;
2456 }
2457 else
2458 {
2459 // Convert list to child values
2460 pList = pPendingValue;
2461 changedProperty->AdaptListToValue( *pPendingValue, &value );
2462 }
2463
2464 wxVariant evtChangingValue = value;
2465
9b5bafcf 2466 if ( flags & SendEvtChanging )
1c4293cb 2467 {
9b5bafcf
JS
2468 // FIXME: After proper ValueToString()s added, remove
2469 // this. It is just a temporary fix, as evt_changing
2470 // will simply not work for wxPG_PROP_COMPOSED_VALUE
2471 // (unless it is selected, and textctrl editor is open).
2472 if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
1c4293cb 2473 {
9b5bafcf
JS
2474 evtChangingProperty = baseChangedProperty;
2475 if ( evtChangingProperty != p )
2476 {
2477 evtChangingProperty->AdaptListToValue( bcpPendingList, &evtChangingValue );
2478 }
2479 else
2480 {
2481 evtChangingValue = pendingValue;
2482 }
1c4293cb 2483 }
1c4293cb 2484
9b5bafcf 2485 if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
1c4293cb 2486 {
9b5bafcf
JS
2487 if ( changedProperty == m_selected )
2488 {
2489 wxWindow* editor = GetEditorControl();
2490 wxASSERT( editor->IsKindOf(CLASSINFO(wxTextCtrl)) );
2491 evtChangingValue = wxStaticCast(editor, wxTextCtrl)->GetValue();
2492 }
2493 else
2494 {
2495 wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value."));
2496 }
1c4293cb
VZ
2497 }
2498 }
2499
2500 wxASSERT( m_chgInfo_changedProperty == NULL );
2501 m_chgInfo_changedProperty = changedProperty;
2502 m_chgInfo_baseChangedProperty = baseChangedProperty;
2503 m_chgInfo_pendingValue = value;
2504
2505 if ( pList )
2506 m_chgInfo_valueList = *pList;
2507 else
2508 m_chgInfo_valueList.MakeNull();
2509
2510 // If changedProperty is not property which value was edited,
2511 // then call wxPGProperty::ValidateValue() for that as well.
0372d42e 2512 if ( p != changedProperty && value.GetType() != wxPG_VARIANT_TYPE_LIST )
1c4293cb
VZ
2513 {
2514 if ( !changedProperty->ValidateValue(value, m_validationInfo) )
2515 return false;
2516 }
2517
9b5bafcf
JS
2518 if ( flags & SendEvtChanging )
2519 {
2520 // SendEvent returns true if event was vetoed
2521 if ( SendEvent( wxEVT_PG_CHANGING, evtChangingProperty, &evtChangingValue, 0 ) )
2522 return false;
2523 }
2524
2525 if ( flags & IsStandaloneValidation )
2526 {
2527 // If called in 'generic' context, we need to reset
2528 // m_chgInfo_changedProperty and write back translated value.
2529 m_chgInfo_changedProperty = NULL;
2530 pendingValue = value;
2531 }
1c4293cb
VZ
2532
2533 return true;
2534}
2535
2536// -----------------------------------------------------------------------
2537
2538void wxPropertyGrid::DoShowPropertyError( wxPGProperty* WXUNUSED(property), const wxString& msg )
2539{
2540 if ( !msg.length() )
2541 return;
2542
2543#if wxUSE_STATUSBAR
2544 if ( !wxPGGlobalVars->m_offline )
2545 {
2546 wxWindow* topWnd = ::wxGetTopLevelParent(this);
2547 if ( topWnd )
2548 {
2549 wxFrame* pFrame = wxDynamicCast(topWnd, wxFrame);
2550 if ( pFrame )
2551 {
2552 wxStatusBar* pStatusBar = pFrame->GetStatusBar();
2553 if ( pStatusBar )
2554 {
2555 pStatusBar->SetStatusText(msg);
2556 return;
2557 }
2558 }
2559 }
2560 }
2561#endif
2562
2563 ::wxMessageBox(msg, _T("Property Error"));
2564}
2565
2566// -----------------------------------------------------------------------
2567
d8812c6e
JS
2568bool wxPropertyGrid::OnValidationFailure( wxPGProperty* property,
2569 wxVariant& invalidValue )
2570{
2571 wxWindow* editor = GetEditorControl();
2572
2573 // First call property's handler
2574 property->OnValidationFailure(invalidValue);
2575
2576 bool res = DoOnValidationFailure(property, invalidValue);
2577
2578 //
2579 // For non-wxTextCtrl editors, we do need to revert the value
2580 if ( !editor->IsKindOf(CLASSINFO(wxTextCtrl)) &&
2581 property == m_selected )
2582 {
2583 property->GetEditorClass()->UpdateControl(property, editor);
2584 }
2585
2586 property->SetFlag(wxPG_PROP_INVALID_VALUE);
2587
2588 return res;
2589}
2590
1c4293cb
VZ
2591bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty* property, wxVariant& WXUNUSED(invalidValue) )
2592{
2593 int vfb = m_validationInfo.m_failureBehavior;
2594
2595 if ( vfb & wxPG_VFB_BEEP )
2596 ::wxBell();
2597
2598 if ( (vfb & wxPG_VFB_MARK_CELL) &&
2599 !property->HasFlag(wxPG_PROP_INVALID_VALUE) )
2600 {
d7e2b522 2601 unsigned int colCount = m_pState->GetColumnCount();
1c4293cb 2602
d7e2b522
JS
2603 // We need backup marked property's cells
2604 m_propCellsBackup = property->m_cells;
2605
2606 wxColour vfbFg = *wxWHITE;
2607 wxColour vfbBg = *wxRED;
2608
2609 property->EnsureCells(colCount);
2610
2611 for ( unsigned int i=0; i<colCount; i++ )
1c4293cb 2612 {
d7e2b522
JS
2613 wxPGCell& cell = property->m_cells[i];
2614 cell.SetFgCol(vfbFg);
2615 cell.SetBgCol(vfbBg);
2616 }
1c4293cb 2617
d7e2b522 2618 DrawItemAndChildren(property);
1c4293cb 2619
d7e2b522
JS
2620 if ( property == m_selected )
2621 {
2622 SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL);
1c4293cb 2623
d7e2b522
JS
2624 wxWindow* editor = GetEditorControl();
2625 if ( editor )
2626 {
2627 editor->SetForegroundColour(vfbFg);
2628 editor->SetBackgroundColour(vfbBg);
1c4293cb
VZ
2629 }
2630 }
2631 }
2632
2633 if ( vfb & wxPG_VFB_SHOW_MESSAGE )
2634 {
2635 wxString msg = m_validationInfo.m_failureMessage;
2636
2637 if ( !msg.length() )
2638 msg = _T("You have entered invalid value. Press ESC to cancel editing.");
2639
2640 DoShowPropertyError(property, msg);
2641 }
2642
2643 return (vfb & wxPG_VFB_STAY_IN_PROPERTY) ? false : true;
2644}
2645
2646// -----------------------------------------------------------------------
2647
2648void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty* property )
2649{
2650 int vfb = m_validationInfo.m_failureBehavior;
2651
2652 if ( vfb & wxPG_VFB_MARK_CELL )
2653 {
d7e2b522
JS
2654 // Revert cells
2655 property->m_cells = m_propCellsBackup;
1c4293cb
VZ
2656
2657 ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL);
2658
2659 if ( property == m_selected && GetEditorControl() )
2660 {
2661 // Calling this will recreate the control, thus resetting its colour
2662 RefreshProperty(property);
2663 }
2664 else
2665 {
2666 DrawItemAndChildren(property);
2667 }
2668 }
2669}
2670
2671// -----------------------------------------------------------------------
2672
2673// flags are same as with DoSelectProperty
2674bool wxPropertyGrid::DoPropertyChanged( wxPGProperty* p, unsigned int selFlags )
2675{
2676 if ( m_inDoPropertyChanged )
2677 return true;
2678
f9189014
JS
2679 wxWindow* editor = GetEditorControl();
2680
1c4293cb
VZ
2681 m_pState->m_anyModified = 1;
2682
2683 m_inDoPropertyChanged = 1;
2684
2685 // Maybe need to update control
2686 wxASSERT( m_chgInfo_changedProperty != NULL );
2687
2688 // These values were calculated in PerformValidation()
2689 wxPGProperty* changedProperty = m_chgInfo_changedProperty;
2690 wxVariant value = m_chgInfo_pendingValue;
2691
2692 wxPGProperty* topPaintedProperty = changedProperty;
2693
2694 while ( !topPaintedProperty->IsCategory() &&
2695 !topPaintedProperty->IsRoot() )
2696 {
2697 topPaintedProperty = topPaintedProperty->GetParent();
2698 }
2699
8f18b252 2700 changedProperty->SetValue(value, &m_chgInfo_valueList, wxPG_SETVAL_BY_USER);
1c4293cb
VZ
2701
2702 // Set as Modified (not if dragging just began)
2703 if ( !(p->m_flags & wxPG_PROP_MODIFIED) )
2704 {
2705 p->m_flags |= wxPG_PROP_MODIFIED;
2706 if ( p == m_selected && (m_windowStyle & wxPG_BOLD_MODIFIED) )
2707 {
f9189014 2708 if ( editor )
1c4293cb
VZ
2709 SetCurControlBoldFont();
2710 }
2711 }
2712
2713 wxPGProperty* pwc;
2714
2715 // Propagate updates to parent(s)
2716 pwc = p;
2717 wxPGProperty* prevPwc = NULL;
2718
2719 while ( prevPwc != topPaintedProperty )
2720 {
2721 pwc->m_flags |= wxPG_PROP_MODIFIED;
2722
2723 if ( pwc == m_selected && (m_windowStyle & wxPG_BOLD_MODIFIED) )
2724 {
f9189014 2725 if ( editor )
1c4293cb
VZ
2726 SetCurControlBoldFont();
2727 }
2728
2729 prevPwc = pwc;
2730 pwc = pwc->GetParent();
2731 }
2732
2733 // Draw the actual property
2734 DrawItemAndChildren( topPaintedProperty );
2735
2736 //
2737 // If value was set by wxPGProperty::OnEvent, then update the editor
2738 // control.
2739 if ( selFlags & wxPG_SEL_DIALOGVAL )
2740 {
a6353fe8 2741 RefreshEditor();
1c4293cb
VZ
2742 }
2743 else
2744 {
2745#if wxPG_REFRESH_CONTROLS_AFTER_REPAINT
2746 if ( m_wndEditor ) m_wndEditor->Refresh();
2747 if ( m_wndEditor2 ) m_wndEditor2->Refresh();
2748#endif
2749 }
2750
2751 // Sanity check
2752 wxASSERT( !changedProperty->GetParent()->HasFlag(wxPG_PROP_AGGREGATE) );
2753
2754 // If top parent has composite string value, then send to child parents,
2755 // starting from baseChangedProperty.
2756 if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) )
2757 {
2758 pwc = m_chgInfo_baseChangedProperty;
2759
2760 while ( pwc != changedProperty )
2761 {
2762 SendEvent( wxEVT_PG_CHANGED, pwc, NULL, selFlags );
2763 pwc = pwc->GetParent();
2764 }
2765 }
2766
2767 SendEvent( wxEVT_PG_CHANGED, changedProperty, NULL, selFlags );
2768
2769 m_inDoPropertyChanged = 0;
2770
2771 return true;
2772}
2773
2774// -----------------------------------------------------------------------
2775
2776bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id, wxVariant newValue )
2777{
2778 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
2779
2780 m_chgInfo_changedProperty = NULL;
2781
2782 if ( PerformValidation(p, newValue) )
2783 {
2784 DoPropertyChanged(p);
2785 return true;
2786 }
2787 else
2788 {
2789 OnValidationFailure(p, newValue);
2790 }
2791
2792 return false;
2793}
2794
2795// -----------------------------------------------------------------------
9b5bafcf 2796
703ee9f5 2797wxVariant wxPropertyGrid::GetUncommittedPropertyValue()
9b5bafcf
JS
2798{
2799 wxPGProperty* prop = GetSelectedProperty();
2800
2801 if ( !prop )
2802 return wxNullVariant;
2803
2804 wxTextCtrl* tc = GetEditorTextCtrl();
2805 wxVariant value = prop->GetValue();
2806
2807 if ( !tc || !IsEditorsValueModified() )
2808 return value;
2809
2810 if ( !prop->StringToValue(value, tc->GetValue()) )
2811 return value;
2812
2813 if ( !PerformValidation(prop, value, IsStandaloneValidation) )
2814 return prop->GetValue();
2815
2816 return value;
2817}
2818
2819// -----------------------------------------------------------------------
1c4293cb
VZ
2820
2821// Runs wxValidator for the selected property
2822bool wxPropertyGrid::DoEditorValidate()
2823{
1c4293cb
VZ
2824 return true;
2825}
2826
2827// -----------------------------------------------------------------------
2828
b0996c3d 2829void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event )
1c4293cb
VZ
2830{
2831 wxPGProperty* selected = m_selected;
2832
1c4293cb
VZ
2833 // Somehow, event is handled after property has been deselected.
2834 // Possibly, but very rare.
2835 if ( !selected )
2836 return;
2837
b0996c3d 2838 if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT )
1c4293cb
VZ
2839 return;
2840
2841 wxVariant pendingValue(selected->GetValueRef());
2842 wxWindow* wnd = GetEditorControl();
6086bcc8 2843 wxWindow* editorWnd = wxDynamicCast(event.GetEventObject(), wxWindow);
1c4293cb
VZ
2844 int selFlags = 0;
2845 bool wasUnspecified = selected->IsValueUnspecified();
2846 int usesAutoUnspecified = selected->UsesAutoUnspecified();
1c4293cb
VZ
2847 bool valueIsPending = false;
2848
2849 m_chgInfo_changedProperty = NULL;
2850
2851 m_iFlags &= ~(wxPG_FL_VALIDATION_FAILED|wxPG_FL_VALUE_CHANGE_IN_EVENT);
2852
2853 //
2854 // Filter out excess wxTextCtrl modified events
2855 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED &&
2856 wnd &&
2857 wnd->IsKindOf(CLASSINFO(wxTextCtrl)) )
2858 {
2859 wxTextCtrl* tc = (wxTextCtrl*) wnd;
2860
2861 wxString newTcValue = tc->GetValue();
2862 if ( m_prevTcValue == newTcValue )
2863 return;
2864
2865 m_prevTcValue = newTcValue;
2866 }
2867
b0996c3d 2868 SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT);
1c4293cb
VZ
2869
2870 bool validationFailure = false;
2871 bool buttonWasHandled = false;
2872
2873 //
2874 // Try common button handling
2875 if ( m_wndEditor2 && event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
2876 {
2877 wxPGEditorDialogAdapter* adapter = selected->GetEditorDialog();
2878
2879 if ( adapter )
2880 {
2881 buttonWasHandled = true;
2882 // Store as res2, as previously (and still currently alternatively)
2883 // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED
2884 // in wxPGProperty::OnEvent().
2885 adapter->ShowDialog( this, selected );
2886 delete adapter;
2887 }
2888 }
2889
7de050ad 2890 if ( !buttonWasHandled )
1c4293cb 2891 {
6086bcc8 2892 if ( wnd || m_wndEditor2 )
1c4293cb 2893 {
7de050ad
JS
2894 // First call editor class' event handler.
2895 const wxPGEditor* editor = selected->GetEditorClass();
2896
6086bcc8 2897 if ( editor->OnEvent( this, selected, editorWnd, event ) )
1c4293cb 2898 {
7de050ad
JS
2899 // If changes, validate them
2900 if ( DoEditorValidate() )
2901 {
6086bcc8
JS
2902 if ( editor->GetValueFromControl( pendingValue,
2903 m_selected,
2904 wnd ) )
7de050ad
JS
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 )
6086bcc8 2917 buttonWasHandled = selected->OnEvent( this, editorWnd, event );
1c4293cb
VZ
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.
657a8a35 3772 SetVirtualSize(x, y);
1c4293cb
VZ
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;
657a8a35 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
48f0334d 4822 if ( p->GetChildCount() )
1c4293cb 4823 {
174b59ac
JS
4824 if ( action == wxPG_ACTION_COLLAPSE_PROPERTY || secondAction == wxPG_ACTION_COLLAPSE_PROPERTY )
4825 {
4826 if ( (m_windowStyle & wxPG_HIDE_MARGIN) || Collapse(p) )
4d11369d 4827 wasHandled = true;
174b59ac
JS
4828 }
4829 else if ( action == wxPG_ACTION_EXPAND_PROPERTY || secondAction == wxPG_ACTION_EXPAND_PROPERTY )
4830 {
4831 if ( (m_windowStyle & wxPG_HIDE_MARGIN) || Expand(p) )
4d11369d 4832 wasHandled = true;
174b59ac 4833 }
1c4293cb 4834 }
1c4293cb 4835
4d11369d 4836 if ( !wasHandled )
174b59ac
JS
4837 {
4838 if ( action == wxPG_ACTION_PREV_PROPERTY || secondAction == wxPG_ACTION_PREV_PROPERTY )
1c4293cb 4839 {
174b59ac 4840 selectDir = -1;
1c4293cb 4841 }
174b59ac 4842 else if ( action == wxPG_ACTION_NEXT_PROPERTY || secondAction == wxPG_ACTION_NEXT_PROPERTY )
1c4293cb 4843 {
174b59ac 4844 selectDir = 1;
1c4293cb 4845 }
174b59ac
JS
4846 }
4847
4848 if ( selectDir >= -1 )
4849 {
4850 p = wxPropertyGridIterator::OneStep( m_pState, wxPG_ITERATE_VISIBLE, p, selectDir );
4851 if ( p )
4852 DoSelectProperty(p);
4d11369d 4853 wasHandled = true;
1c4293cb
VZ
4854 }
4855 }
4856 else
4857 {
4858 // If nothing was selected, select the first item now
4859 // (or navigate out of tab).
4860 if ( action != wxPG_ACTION_CANCEL_EDIT && secondAction != wxPG_ACTION_CANCEL_EDIT )
4861 {
4862 wxPGProperty* p = wxPropertyGridInterface::GetFirst();
4863 if ( p ) DoSelectProperty(p);
4d11369d 4864 wasHandled = true;
1c4293cb
VZ
4865 }
4866 }
4d11369d
JS
4867
4868 if ( !wasHandled )
4869 event.Skip();
1c4293cb
VZ
4870}
4871
4872// -----------------------------------------------------------------------
4873
1c4293cb
VZ
4874void wxPropertyGrid::OnKey( wxKeyEvent &event )
4875{
c12822fe
JS
4876 // If there was editor open and focused, then this event should not
4877 // really be processed here.
4878 if ( IsEditorFocused() )
4879 {
4880 // However, if event had modifiers, it is probably still best
4881 // to skip it.
4882 if ( event.HasModifiers() )
4883 event.Skip();
4884 else
4885 event.StopPropagation();
4886 return;
4887 }
4888
68f9e025 4889 HandleKeyEvent(event, false);
1c4293cb
VZ
4890}
4891
4892// -----------------------------------------------------------------------
4893
1766bf34 4894bool wxPropertyGrid::ButtonTriggerKeyTest( int action, wxKeyEvent& event )
1c4293cb 4895{
1766bf34
JS
4896 if ( action == -1 )
4897 {
4898 int secondAction;
4899 action = KeyEventToActions(event, &secondAction);
4900 }
1c4293cb
VZ
4901
4902 // Does the keycode trigger button?
1766bf34
JS
4903 if ( action == wxPG_ACTION_PRESS_BUTTON &&
4904 m_wndEditor2 )
1c4293cb 4905 {
1766bf34 4906 wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, m_wndEditor2->GetId());
1c4293cb
VZ
4907 GetEventHandler()->AddPendingEvent(evt);
4908 return true;
4909 }
4910
4911 return false;
4912}
4913
4914// -----------------------------------------------------------------------
4915
4916void wxPropertyGrid::OnChildKeyDown( wxKeyEvent &event )
4917{
68f9e025 4918 HandleKeyEvent(event, true);
1c4293cb
VZ
4919}
4920
4921// -----------------------------------------------------------------------
4922// wxPropertyGrid miscellaneous event handling
4923// -----------------------------------------------------------------------
4924
4925void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) )
4926{
4927 //
4928 // Check if the focus is in this control or one of its children
4929 wxWindow* newFocused = wxWindow::FindFocus();
4930
4931 if ( newFocused != m_curFocused )
4932 HandleFocusChange( newFocused );
4933}
4934
68f9e025
JS
4935bool wxPropertyGrid::IsEditorFocused() const
4936{
4937 wxWindow* focus = wxWindow::FindFocus();
4938
4939 if ( focus == m_wndEditor || focus == m_wndEditor2 ||
4940 focus == GetEditorControl() )
4941 return true;
4942
4943 return false;
4944}
4945
1c4293cb
VZ
4946// Called by focus event handlers. newFocused is the window that becomes focused.
4947void wxPropertyGrid::HandleFocusChange( wxWindow* newFocused )
4948{
4949 unsigned int oldFlags = m_iFlags;
4950
4951 m_iFlags &= ~(wxPG_FL_FOCUSED);
4952
4953 wxWindow* parent = newFocused;
4954
4955 // This must be one of nextFocus' parents.
4956 while ( parent )
4957 {
4958 // Use m_eventObject, which is either wxPropertyGrid or
4959 // wxPropertyGridManager, as appropriate.
4960 if ( parent == m_eventObject )
4961 {
4962 m_iFlags |= wxPG_FL_FOCUSED;
4963 break;
4964 }
4965 parent = parent->GetParent();
4966 }
4967
4968 m_curFocused = newFocused;
4969
4970 if ( (m_iFlags & wxPG_FL_FOCUSED) !=
4971 (oldFlags & wxPG_FL_FOCUSED) )
4972 {
1c4293cb
VZ
4973 if ( !(m_iFlags & wxPG_FL_FOCUSED) )
4974 {
1c4293cb
VZ
4975 // Need to store changed value
4976 CommitChangesFromEditor();
4977 }
4978 else
4979 {
4980 /*
4981 //
4982 // Preliminary code for tab-order respecting
4983 // tab-traversal (but should be moved to
4984 // OnNav handler)
4985 //
4986 wxWindow* prevFocus = event.GetWindow();
4987 wxWindow* useThis = this;
4988 if ( m_iFlags & wxPG_FL_IN_MANAGER )
4989 useThis = GetParent();
4990
4991 if ( prevFocus &&
4992 prevFocus->GetParent() == useThis->GetParent() )
4993 {
4994 wxList& children = useThis->GetParent()->GetChildren();
4995
4996 wxNode* node = children.Find(prevFocus);
4997
4998 if ( node->GetNext() &&
4999 useThis == node->GetNext()->GetData() )
5000 DoSelectProperty(GetFirst());
5001 else if ( node->GetPrevious () &&
5002 useThis == node->GetPrevious()->GetData() )
5003 DoSelectProperty(GetLastProperty());
5004
5005 }
5006 */
1c4293cb
VZ
5007 }
5008
5009 // Redraw selected
5010 if ( m_selected && (m_iFlags & wxPG_FL_INITIALIZED) )
5011 DrawItem( m_selected );
5012 }
5013}
5014
5015void wxPropertyGrid::OnFocusEvent( wxFocusEvent& event )
5016{
5017 if ( event.GetEventType() == wxEVT_SET_FOCUS )
5018 HandleFocusChange((wxWindow*)event.GetEventObject());
5019 // Line changed to "else" when applying wxPropertyGrid patch #1675902
5020 //else if ( event.GetWindow() )
5021 else
5022 HandleFocusChange(event.GetWindow());
5023
5024 event.Skip();
5025}
5026
5027// -----------------------------------------------------------------------
5028
5029void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent& event )
5030{
5031 HandleFocusChange((wxWindow*)event.GetEventObject());
8c5c56e2 5032 event.Skip();
1c4293cb
VZ
5033}
5034
5035// -----------------------------------------------------------------------
5036
5037void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent &event )
5038{
5039 m_iFlags |= wxPG_FL_SCROLLED;
5040
5041 event.Skip();
5042}
5043
5044// -----------------------------------------------------------------------
5045
5046void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent& WXUNUSED(event) )
5047{
5048 if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED )
5049 {
5050 m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED);
5051 }
5052}
5053
5054// -----------------------------------------------------------------------
5055// Property editor related functions
5056// -----------------------------------------------------------------------
5057
5058// noDefCheck = true prevents infinite recursion.
7a344f1b 5059wxPGEditor* wxPropertyGrid::RegisterEditorClass( wxPGEditor* editorClass,
1c4293cb
VZ
5060 bool noDefCheck )
5061{
7a344f1b 5062 wxASSERT( editorClass );
1c4293cb
VZ
5063
5064 if ( !noDefCheck && wxPGGlobalVars->m_mapEditorClasses.empty() )
5065 RegisterDefaultEditors();
5066
7a344f1b 5067 wxString name = editorClass->GetName();
614fbbad
JS
5068
5069 // Existing editor under this name?
5070 wxPGHashMapS2P::iterator vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name);
5071
5a45dd6f
JS
5072 if ( vt_it != wxPGGlobalVars->m_mapEditorClasses.end() )
5073 {
5074 // If this name was already used, try class name.
5075 name = editorClass->GetClassInfo()->GetClassName();
5076 vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name);
5077 }
5078
614fbbad
JS
5079 wxCHECK_MSG( vt_it == wxPGGlobalVars->m_mapEditorClasses.end(),
5080 (wxPGEditor*) vt_it->second,
5081 "Editor with given name was already registered" );
5082
7a344f1b 5083 wxPGGlobalVars->m_mapEditorClasses[name] = (void*)editorClass;
1c4293cb 5084
7a344f1b 5085 return editorClass;
1c4293cb
VZ
5086}
5087
52cefafe
JS
5088// Use this in RegisterDefaultEditors.
5089#define wxPGRegisterDefaultEditorClass(EDITOR) \
d3b9f782 5090 if ( wxPGEditor_##EDITOR == NULL ) \
52cefafe
JS
5091 { \
5092 wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \
5093 new wxPG##EDITOR##Editor, true ); \
5094 }
5095
1c4293cb
VZ
5096// Registers all default editor classes
5097void wxPropertyGrid::RegisterDefaultEditors()
5098{
5099 wxPGRegisterDefaultEditorClass( TextCtrl );
5100 wxPGRegisterDefaultEditorClass( Choice );
5101 wxPGRegisterDefaultEditorClass( ComboBox );
5102 wxPGRegisterDefaultEditorClass( TextCtrlAndButton );
5103#if wxPG_INCLUDE_CHECKBOX
5104 wxPGRegisterDefaultEditorClass( CheckBox );
5105#endif
5106 wxPGRegisterDefaultEditorClass( ChoiceAndButton );
5107
5108 // Register SpinCtrl etc. editors before use
5109 RegisterAdditionalEditors();
5110}
5111
5112// -----------------------------------------------------------------------
5113// wxPGStringTokenizer
5114// Needed to handle C-style string lists (e.g. "str1" "str2")
5115// -----------------------------------------------------------------------
5116
5117wxPGStringTokenizer::wxPGStringTokenizer( const wxString& str, wxChar delimeter )
5118 : m_str(&str), m_curPos(str.begin()), m_delimeter(delimeter)
5119{
5120}
5121
5122wxPGStringTokenizer::~wxPGStringTokenizer()
5123{
5124}
5125
5126bool wxPGStringTokenizer::HasMoreTokens()
5127{
5128 const wxString& str = *m_str;
5129
5130 wxString::const_iterator i = m_curPos;
5131
5132 wxUniChar delim = m_delimeter;
5133 wxUniChar a;
5134 wxUniChar prev_a = wxT('\0');
5135
5136 bool inToken = false;
5137
5138 while ( i != str.end() )
5139 {
5140 a = *i;
5141
5142 if ( !inToken )
5143 {
5144 if ( a == delim )
5145 {
5146 inToken = true;
5147 m_readyToken.clear();
5148 }
5149 }
5150 else
5151 {
5152 if ( prev_a != wxT('\\') )
5153 {
5154 if ( a != delim )
5155 {
5156 if ( a != wxT('\\') )
5157 m_readyToken << a;
5158 }
5159 else
5160 {
b7bc9d80 5161 ++i;
1c4293cb
VZ
5162 m_curPos = i;
5163 return true;
5164 }
5165 prev_a = a;
5166 }
5167 else
5168 {
5169 m_readyToken << a;
5170 prev_a = wxT('\0');
5171 }
5172 }
b7bc9d80 5173 ++i;
1c4293cb
VZ
5174 }
5175
5176 m_curPos = str.end();
5177
5178 if ( inToken )
5179 return true;
5180
5181 return false;
5182}
5183
5184wxString wxPGStringTokenizer::GetNextToken()
5185{
5186 return m_readyToken;
5187}
5188
5189// -----------------------------------------------------------------------
5190// wxPGChoiceEntry
5191// -----------------------------------------------------------------------
5192
5193wxPGChoiceEntry::wxPGChoiceEntry()
5194 : wxPGCell(), m_value(wxPG_INVALID_VALUE)
5195{
5196}
5197
1c4293cb
VZ
5198// -----------------------------------------------------------------------
5199// wxPGChoicesData
5200// -----------------------------------------------------------------------
5201
5202wxPGChoicesData::wxPGChoicesData()
5203{
5204 m_refCount = 1;
5205}
5206
5207wxPGChoicesData::~wxPGChoicesData()
5208{
5209 Clear();
5210}
5211
5212void wxPGChoicesData::Clear()
5213{
f7a094e1 5214 m_items.clear();
1c4293cb
VZ
5215}
5216
5217void wxPGChoicesData::CopyDataFrom( wxPGChoicesData* data )
5218{
5219 wxASSERT( m_items.size() == 0 );
5220
d7e2b522
JS
5221 m_items = data->m_items;
5222}
1c4293cb 5223
d7e2b522
JS
5224wxPGChoiceEntry& wxPGChoicesData::Insert( int index,
5225 const wxPGChoiceEntry& item )
5226{
5227 wxVector<wxPGChoiceEntry>::iterator it;
5228 if ( index == -1 )
5229 {
5230 it = m_items.end();
5231 index = (int) m_items.size();
5232 }
5233 else
5234 {
5235 it = m_items.begin() + index;
5236 }
5237
5238 m_items.insert(it, item);
5239
5240 wxPGChoiceEntry& ownEntry = m_items[index];
5241
5242 // Need to fix value?
5243 if ( ownEntry.GetValue() == wxPG_INVALID_VALUE )
5244 ownEntry.SetValue(index);
5245
5246 return ownEntry;
1c4293cb
VZ
5247}
5248
1c4293cb
VZ
5249// -----------------------------------------------------------------------
5250// wxPropertyGridEvent
5251// -----------------------------------------------------------------------
5252
5253IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent, wxCommandEvent)
5254
5255
9b11752c
VZ
5256wxDEFINE_EVENT( wxEVT_PG_SELECTED, wxPropertyGridEvent );
5257wxDEFINE_EVENT( wxEVT_PG_CHANGING, wxPropertyGridEvent );
5258wxDEFINE_EVENT( wxEVT_PG_CHANGED, wxPropertyGridEvent );
5259wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED, wxPropertyGridEvent );
5260wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK, wxPropertyGridEvent );
5261wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED, wxPropertyGridEvent );
5262wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED, wxPropertyGridEvent );
5263wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED, wxPropertyGridEvent );
5264wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEvent );
1c4293cb
VZ
5265
5266
5267// -----------------------------------------------------------------------
5268
5269void wxPropertyGridEvent::Init()
5270{
5271 m_validationInfo = NULL;
5272 m_canVeto = false;
5273 m_wasVetoed = false;
5274}
5275
5276// -----------------------------------------------------------------------
5277
5278wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType, int id)
5279 : wxCommandEvent(commandType,id)
5280{
5281 m_property = NULL;
5282 Init();
5283}
5284
5285// -----------------------------------------------------------------------
5286
5287wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent& event)
5288 : wxCommandEvent(event)
5289{
5290 m_eventType = event.GetEventType();
5291 m_eventObject = event.m_eventObject;
5292 m_pg = event.m_pg;
5293 m_property = event.m_property;
5294 m_validationInfo = event.m_validationInfo;
5295 m_canVeto = event.m_canVeto;
5296 m_wasVetoed = event.m_wasVetoed;
5297}
5298
5299// -----------------------------------------------------------------------
5300
5301wxPropertyGridEvent::~wxPropertyGridEvent()
5302{
5303}
5304
5305// -----------------------------------------------------------------------
5306
5307wxEvent* wxPropertyGridEvent::Clone() const
5308{
5309 return new wxPropertyGridEvent( *this );
5310}
5311
1c4293cb
VZ
5312// -----------------------------------------------------------------------
5313// wxPropertyGridPopulator
5314// -----------------------------------------------------------------------
5315
5316wxPropertyGridPopulator::wxPropertyGridPopulator()
5317{
5318 m_state = NULL;
5319 m_pg = NULL;
5320 wxPGGlobalVars->m_offline++;
5321}
5322
5323// -----------------------------------------------------------------------
5324
5325void wxPropertyGridPopulator::SetState( wxPropertyGridPageState* state )
5326{
5327 m_state = state;
5328 m_propHierarchy.clear();
5329}
5330
5331// -----------------------------------------------------------------------
5332
5333void wxPropertyGridPopulator::SetGrid( wxPropertyGrid* pg )
5334{
5335 m_pg = pg;
5336 pg->Freeze();
5337}
5338
5339// -----------------------------------------------------------------------
5340
5341wxPropertyGridPopulator::~wxPropertyGridPopulator()
5342{
5343 //
5344 // Free unused sets of choices
5345 wxPGHashMapS2P::iterator it;
5346
5347 for( it = m_dictIdChoices.begin(); it != m_dictIdChoices.end(); ++it )
5348 {
5349 wxPGChoicesData* data = (wxPGChoicesData*) it->second;
5350 data->DecRef();
5351 }
5352
5353 if ( m_pg )
5354 {
5355 m_pg->Thaw();
5356 m_pg->GetPanel()->Refresh();
5357 }
5358 wxPGGlobalVars->m_offline--;
5359}
5360
5361// -----------------------------------------------------------------------
5362
5363wxPGProperty* wxPropertyGridPopulator::Add( const wxString& propClass,
5364 const wxString& propLabel,
5365 const wxString& propName,
5366 const wxString* propValue,
5367 wxPGChoices* pChoices )
5368{
5369 wxClassInfo* classInfo = wxClassInfo::FindClass(propClass);
5370 wxPGProperty* parent = GetCurParent();
5371
5372 if ( parent->HasFlag(wxPG_PROP_AGGREGATE) )
5373 {
5374 ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent->GetName().c_str()));
5375 return NULL;
5376 }
5377
5378 if ( !classInfo || !classInfo->IsKindOf(CLASSINFO(wxPGProperty)) )
5379 {
5380 ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass.c_str()));
5381 return NULL;
5382 }
5383
5384 wxPGProperty* property = (wxPGProperty*) classInfo->CreateObject();
5385
5386 property->SetLabel(propLabel);
5387 property->DoSetName(propName);
5388
5389 if ( pChoices && pChoices->IsOk() )
5390 property->SetChoices(*pChoices);
5391
5392 m_state->DoInsert(parent, -1, property);
5393
5394 if ( propValue )
f275b5db
JS
5395 property->SetValueFromString( *propValue, wxPG_FULL_VALUE|
5396 wxPG_PROGRAMMATIC_VALUE );
1c4293cb
VZ
5397
5398 return property;
5399}
5400
5401// -----------------------------------------------------------------------
5402
5403void wxPropertyGridPopulator::AddChildren( wxPGProperty* property )
5404{
5405 m_propHierarchy.push_back(property);
5406 DoScanForChildren();
5407 m_propHierarchy.pop_back();
5408}
5409
5410// -----------------------------------------------------------------------
5411
5412wxPGChoices wxPropertyGridPopulator::ParseChoices( const wxString& choicesString,
5413 const wxString& idString )
5414{
5415 wxPGChoices choices;
5416
5417 // Using id?
5418 if ( choicesString[0] == wxT('@') )
5419 {
5420 wxString ids = choicesString.substr(1);
5421 wxPGHashMapS2P::iterator it = m_dictIdChoices.find(ids);
5422 if ( it == m_dictIdChoices.end() )
5423 ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids.c_str()));
5424 else
5425 choices.AssignData((wxPGChoicesData*)it->second);
5426 }
5427 else
5428 {
5429 bool found = false;
5430 if ( idString.length() )
5431 {
5432 wxPGHashMapS2P::iterator it = m_dictIdChoices.find(idString);
5433 if ( it != m_dictIdChoices.end() )
5434 {
5435 choices.AssignData((wxPGChoicesData*)it->second);
5436 found = true;
5437 }
5438 }
5439
5440 if ( !found )
5441 {
5442 // Parse choices string
5443 wxString::const_iterator it = choicesString.begin();
5444 wxString label;
5445 wxString value;
5446 int state = 0;
5447 bool labelValid = false;
5448
b7bc9d80 5449 for ( ; it != choicesString.end(); ++it )
1c4293cb
VZ
5450 {
5451 wxChar c = *it;
5452
5453 if ( state != 1 )
5454 {
5455 if ( c == wxT('"') )
5456 {
5457 if ( labelValid )
5458 {
5459 long l;
5460 if ( !value.ToLong(&l, 0) ) l = wxPG_INVALID_VALUE;
5461 choices.Add(label, l);
5462 }
5463 labelValid = false;
5464 //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str());
5465 value.clear();
5466 label.clear();
5467 state = 1;
5468 }
5469 else if ( c == wxT('=') )
5470 {
5471 if ( labelValid )
5472 {
5473 state = 2;
5474 }
5475 }
5476 else if ( state == 2 && (wxIsalnum(c) || c == wxT('x')) )
5477 {
5478 value << c;
5479 }
5480 }
5481 else
5482 {
5483 if ( c == wxT('"') )
5484 {
5485 state = 0;
5486 labelValid = true;
5487 }
5488 else
5489 label << c;
5490 }
5491 }
5492
5493 if ( labelValid )
5494 {
5495 long l;
5496 if ( !value.ToLong(&l, 0) ) l = wxPG_INVALID_VALUE;
5497 choices.Add(label, l);
5498 }
5499
5500 if ( !choices.IsOk() )
5501 {
5502 choices.EnsureData();
5503 }
5504
5505 // Assign to id
5506 if ( idString.length() )
5507 m_dictIdChoices[idString] = choices.GetData();
5508 }
5509 }
5510
5511 return choices;
5512}
5513
5514// -----------------------------------------------------------------------
5515
5516bool wxPropertyGridPopulator::ToLongPCT( const wxString& s, long* pval, long max )
5517{
5518 if ( s.Last() == wxT('%') )
5519 {
5520 wxString s2 = s.substr(0,s.length()-1);
5521 long val;
5522 if ( s2.ToLong(&val, 10) )
5523 {
5524 *pval = (val*max)/100;
5525 return true;
5526 }
5527 return false;
5528 }
5529
5530 return s.ToLong(pval, 10);
5531}
5532
5533// -----------------------------------------------------------------------
5534
5535bool wxPropertyGridPopulator::AddAttribute( const wxString& name,
5536 const wxString& type,
5537 const wxString& value )
5538{
5539 int l = m_propHierarchy.size();
5540 if ( !l )
5541 return false;
5542
5543 wxPGProperty* p = m_propHierarchy[l-1];
5544 wxString valuel = value.Lower();
5545 wxVariant variant;
5546
5547 if ( type.length() == 0 )
5548 {
5549 long v;
5550
5551 // Auto-detect type
5552 if ( valuel == wxT("true") || valuel == wxT("yes") || valuel == wxT("1") )
5553 variant = true;
5554 else if ( valuel == wxT("false") || valuel == wxT("no") || valuel == wxT("0") )
5555 variant = false;
5556 else if ( value.ToLong(&v, 0) )
5557 variant = v;
5558 else
5559 variant = value;
5560 }
5561 else
5562 {
5563 if ( type == wxT("string") )
5564 {
5565 variant = value;
5566 }
5567 else if ( type == wxT("int") )
5568 {
5569 long v = 0;
5570 value.ToLong(&v, 0);
5571 variant = v;
5572 }
5573 else if ( type == wxT("bool") )
5574 {
5575 if ( valuel == wxT("true") || valuel == wxT("yes") || valuel == wxT("1") )
5576 variant = true;
5577 else
5578 variant = false;
5579 }
5580 else
5581 {
5582 ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type.c_str()));
5583 return false;
5584 }
5585 }
5586
5587 p->SetAttribute( name, variant );
5588
5589 return true;
5590}
5591
5592// -----------------------------------------------------------------------
5593
5594void wxPropertyGridPopulator::ProcessError( const wxString& msg )
5595{
5596 wxLogError(_("Error in resource: %s"),msg.c_str());
5597}
5598
5599// -----------------------------------------------------------------------
f4bc1aa2
JS
5600
5601#endif // wxUSE_PROPGRID