]> git.saurik.com Git - wxWidgets.git/blob - src/propgrid/property.cpp
Added bool property to the nested car sample (for testing purposes)
[wxWidgets.git] / src / propgrid / property.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/property.cpp
3 // Purpose: wxPGProperty and related support classes
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: 2008-08-23
7 // RCS-ID: $Id$
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_PROPGRID
20
21 #ifndef WX_PRECOMP
22 #include "wx/defs.h"
23 #include "wx/object.h"
24 #include "wx/hash.h"
25 #include "wx/string.h"
26 #include "wx/log.h"
27 #include "wx/event.h"
28 #include "wx/window.h"
29 #include "wx/panel.h"
30 #include "wx/dc.h"
31 #include "wx/dcmemory.h"
32 #include "wx/pen.h"
33 #include "wx/brush.h"
34 #include "wx/settings.h"
35 #include "wx/intl.h"
36 #endif
37
38 #include "wx/propgrid/propgrid.h"
39
40
41 #define PWC_CHILD_SUMMARY_LIMIT 16 // Maximum number of children summarized in a parent property's
42 // value field.
43
44 #define PWC_CHILD_SUMMARY_CHAR_LIMIT 64 // Character limit of summary field when not editing
45
46 #if wxPG_COMPATIBILITY_1_4
47
48 // Used to establish backwards compatiblity
49 const char* g_invalidStringContent = "@__TOTALLY_INVALID_STRING__@";
50
51 #endif
52
53 // -----------------------------------------------------------------------
54
55 static void wxPGDrawFocusRect( wxDC& dc, const wxRect& rect )
56 {
57 #if defined(__WXMSW__) && !defined(__WXWINCE__)
58 // FIXME: Use DrawFocusRect code above (currently it draws solid line
59 // for caption focus but works ok for other stuff).
60 // Also, it seems that this code may not work in future wx versions.
61 dc.SetLogicalFunction(wxINVERT);
62
63 wxPen pen(*wxBLACK,1,wxDOT);
64 pen.SetCap(wxCAP_BUTT);
65 dc.SetPen(pen);
66 dc.SetBrush(*wxTRANSPARENT_BRUSH);
67
68 dc.DrawRectangle(rect);
69
70 dc.SetLogicalFunction(wxCOPY);
71 #else
72 dc.SetLogicalFunction(wxINVERT);
73
74 dc.SetPen(wxPen(*wxBLACK,1,wxDOT));
75 dc.SetBrush(*wxTRANSPARENT_BRUSH);
76
77 dc.DrawRectangle(rect);
78
79 dc.SetLogicalFunction(wxCOPY);
80 #endif
81 }
82
83 // -----------------------------------------------------------------------
84 // wxPGCellRenderer
85 // -----------------------------------------------------------------------
86
87 wxSize wxPGCellRenderer::GetImageSize( const wxPGProperty* WXUNUSED(property),
88 int WXUNUSED(column),
89 int WXUNUSED(item) ) const
90 {
91 return wxSize(0, 0);
92 }
93
94 void wxPGCellRenderer::DrawText( wxDC& dc, const wxRect& rect,
95 int xOffset, const wxString& text ) const
96 {
97 if ( xOffset )
98 xOffset += wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
99 dc.DrawText( text,
100 rect.x+xOffset+wxPG_XBEFORETEXT,
101 rect.y+((rect.height-dc.GetCharHeight())/2) );
102 }
103
104 void wxPGCellRenderer::DrawEditorValue( wxDC& dc, const wxRect& rect,
105 int xOffset, const wxString& text,
106 wxPGProperty* property,
107 const wxPGEditor* editor ) const
108 {
109 if ( xOffset )
110 xOffset += wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
111
112 int yOffset = ((rect.height-dc.GetCharHeight())/2);
113
114 if ( editor )
115 {
116 wxRect rect2(rect);
117 rect2.x += xOffset;
118 rect2.y += yOffset;
119 rect2.height -= yOffset;
120 editor->DrawValue( dc, rect2, property, text );
121 }
122 else
123 {
124 dc.DrawText( text,
125 rect.x+xOffset+wxPG_XBEFORETEXT,
126 rect.y+yOffset );
127 }
128 }
129
130 void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC& dc, int x, int y, int w, int h ) const
131 {
132 wxRect focusRect(x,y+((h-dc.GetCharHeight())/2),w,h);
133 wxPGDrawFocusRect(dc,focusRect);
134 }
135
136 int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell& cell, int flags ) const
137 {
138 int imageOffset = 0;
139
140 // If possible, use cell colours
141 if ( !(flags & DontUseCellBgCol) )
142 {
143 dc.SetPen(cell.GetBgCol());
144 dc.SetBrush(cell.GetBgCol());
145 }
146
147 if ( !(flags & DontUseCellFgCol) )
148 {
149 dc.SetTextForeground(cell.GetFgCol());
150 }
151
152 // Draw Background, but only if not rendering in control
153 // (as control already has rendered correct background).
154 if ( !(flags & (Control|ChoicePopup)) )
155 dc.DrawRectangle(rect);
156
157 const wxBitmap& bmp = cell.GetBitmap();
158 if ( bmp.Ok() &&
159 // Do not draw oversized bitmap outside choice popup
160 ((flags & ChoicePopup) || bmp.GetHeight() < rect.height )
161 )
162 {
163 dc.DrawBitmap( bmp,
164 rect.x + wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1,
165 rect.y + wxPG_CUSTOM_IMAGE_SPACINGY,
166 true );
167 imageOffset = bmp.GetWidth();
168 }
169
170 return imageOffset;
171 }
172
173 // -----------------------------------------------------------------------
174 // wxPGDefaultRenderer
175 // -----------------------------------------------------------------------
176
177 void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
178 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
179 int column, int item, int flags ) const
180 {
181 bool isUnspecified = property->IsValueUnspecified();
182
183 if ( column == 1 && item == -1 )
184 {
185 int cmnVal = property->GetCommonValue();
186 if ( cmnVal >= 0 )
187 {
188 // Common Value
189 if ( !isUnspecified )
190 DrawText( dc, rect, 0, propertyGrid->GetCommonValueLabel(cmnVal) );
191 return;
192 }
193 }
194
195 const wxPGEditor* editor = NULL;
196 const wxPGCell* cell = NULL;
197
198 wxString text;
199 int imageOffset = 0;
200 int preDrawFlags = flags;
201
202 property->GetDisplayInfo(column, item, flags, &text, &cell);
203
204 imageOffset = PreDrawCell( dc, rect, *cell, preDrawFlags );
205
206 if ( column == 1 )
207 {
208 if ( !isUnspecified )
209 {
210 editor = property->GetColumnEditor(column);
211
212 // Regular property value
213
214 wxSize imageSize = propertyGrid->GetImageSize(property, item);
215
216 wxPGPaintData paintdata;
217 paintdata.m_parent = propertyGrid;
218 paintdata.m_choiceItem = item;
219
220 if ( imageSize.x > 0 )
221 {
222 wxRect imageRect(rect.x + wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1,
223 rect.y+wxPG_CUSTOM_IMAGE_SPACINGY,
224 wxPG_CUSTOM_IMAGE_WIDTH,
225 rect.height-(wxPG_CUSTOM_IMAGE_SPACINGY*2));
226
227 dc.SetPen( wxPen(propertyGrid->GetCellTextColour(), 1, wxSOLID) );
228
229 paintdata.m_drawnWidth = imageSize.x;
230 paintdata.m_drawnHeight = imageSize.y;
231
232 property->OnCustomPaint( dc, imageRect, paintdata );
233
234 imageOffset = paintdata.m_drawnWidth;
235 }
236
237 text = property->GetValueAsString();
238
239 // Add units string?
240 if ( propertyGrid->GetColumnCount() <= 2 )
241 {
242 wxString unitsString = property->GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
243 if ( unitsString.length() )
244 text = wxString::Format(wxS("%s %s"), text.c_str(), unitsString.c_str() );
245 }
246 }
247
248 if ( text.length() == 0 )
249 {
250 // Try to show inline help if no text
251 wxVariant vInlineHelp = property->GetAttribute(wxPGGlobalVars->m_strInlineHelp);
252 if ( !vInlineHelp.IsNull() )
253 {
254 text = vInlineHelp.GetString();
255 dc.SetTextForeground(propertyGrid->GetCellDisabledTextColour());
256 }
257 }
258 }
259
260 DrawEditorValue( dc, rect, imageOffset, text, property, editor );
261
262 // active caption gets nice dotted rectangle
263 if ( property->IsCategory() /*&& column == 0*/ )
264 {
265 if ( flags & Selected )
266 {
267 if ( imageOffset > 0 )
268 imageOffset += wxCC_CUSTOM_IMAGE_MARGIN2 + 4;
269
270 DrawCaptionSelectionRect( dc,
271 rect.x+wxPG_XBEFORETEXT-wxPG_CAPRECTXMARGIN+imageOffset,
272 rect.y-wxPG_CAPRECTYMARGIN+1,
273 ((wxPropertyCategory*)property)->GetTextExtent(propertyGrid,
274 propertyGrid->GetCaptionFont())
275 +(wxPG_CAPRECTXMARGIN*2),
276 propertyGrid->GetFontHeight()+(wxPG_CAPRECTYMARGIN*2) );
277 }
278 }
279 }
280
281 wxSize wxPGDefaultRenderer::GetImageSize( const wxPGProperty* property,
282 int column,
283 int item ) const
284 {
285 if ( property && column == 1 )
286 {
287 if ( item == -1 )
288 {
289 wxBitmap* bmp = property->GetValueImage();
290
291 if ( bmp && bmp->Ok() )
292 return wxSize(bmp->GetWidth(),bmp->GetHeight());
293 }
294 }
295 return wxSize(0,0);
296 }
297
298 // -----------------------------------------------------------------------
299 // wxPGCellData
300 // -----------------------------------------------------------------------
301
302 wxPGCellData::wxPGCellData()
303 : wxObjectRefData()
304 {
305 m_hasValidText = false;
306 }
307
308 // -----------------------------------------------------------------------
309 // wxPGCell
310 // -----------------------------------------------------------------------
311
312 wxPGCell::wxPGCell()
313 : wxObject()
314 {
315 }
316
317 wxPGCell::wxPGCell( const wxString& text,
318 const wxBitmap& bitmap,
319 const wxColour& fgCol,
320 const wxColour& bgCol )
321 : wxObject()
322 {
323 wxPGCellData* data = new wxPGCellData();
324 m_refData = data;
325 data->m_text = text;
326 data->m_bitmap = bitmap;
327 data->m_fgCol = fgCol;
328 data->m_bgCol = bgCol;
329 data->m_hasValidText = true;
330 }
331
332 wxObjectRefData *wxPGCell::CloneRefData( const wxObjectRefData *data ) const
333 {
334 wxPGCellData* c = new wxPGCellData();
335 const wxPGCellData* o = (const wxPGCellData*) data;
336 c->m_text = o->m_text;
337 c->m_bitmap = o->m_bitmap;
338 c->m_fgCol = o->m_fgCol;
339 c->m_bgCol = o->m_bgCol;
340 c->m_hasValidText = o->m_hasValidText;
341 return c;
342 }
343
344 void wxPGCell::SetText( const wxString& text )
345 {
346 AllocExclusive();
347
348 GetData()->SetText(text);
349 }
350
351 void wxPGCell::SetBitmap( const wxBitmap& bitmap )
352 {
353 AllocExclusive();
354
355 GetData()->SetBitmap(bitmap);
356 }
357
358 void wxPGCell::SetFgCol( const wxColour& col )
359 {
360 AllocExclusive();
361
362 GetData()->SetFgCol(col);
363 }
364
365 void wxPGCell::SetBgCol( const wxColour& col )
366 {
367 AllocExclusive();
368
369 GetData()->SetBgCol(col);
370 }
371
372 void wxPGCell::MergeFrom( const wxPGCell& srcCell )
373 {
374 AllocExclusive();
375
376 wxPGCellData* data = GetData();
377
378 if ( srcCell.HasText() )
379 data->SetText(srcCell.GetText());
380
381 if ( srcCell.GetFgCol().IsOk() )
382 data->SetFgCol(srcCell.GetFgCol());
383
384 if ( srcCell.GetBgCol().IsOk() )
385 data->SetBgCol(srcCell.GetBgCol());
386
387 if ( srcCell.GetBitmap().IsOk() )
388 data->SetBitmap(srcCell.GetBitmap());
389 }
390
391 // -----------------------------------------------------------------------
392 // wxPGProperty
393 // -----------------------------------------------------------------------
394
395 IMPLEMENT_ABSTRACT_CLASS(wxPGProperty, wxObject)
396
397 wxString* wxPGProperty::sm_wxPG_LABEL = NULL;
398
399 void wxPGProperty::Init()
400 {
401 m_commonValue = -1;
402 m_arrIndex = 0xFFFF;
403 m_parent = NULL;
404
405 m_parentState = (wxPropertyGridPageState*) NULL;
406
407 m_clientData = NULL;
408 m_clientObject = NULL;
409
410 m_customEditor = (wxPGEditor*) NULL;
411 #if wxUSE_VALIDATORS
412 m_validator = (wxValidator*) NULL;
413 #endif
414 m_valueBitmap = (wxBitmap*) NULL;
415
416 m_maxLen = 0; // infinite maximum length
417
418 m_flags = wxPG_PROP_PROPERTY;
419
420 m_depth = 1;
421
422 SetExpanded(true);
423 }
424
425
426 void wxPGProperty::Init( const wxString& label, const wxString& name )
427 {
428 // We really need to check if &label and &name are NULL pointers
429 // (this can if we are called before property grid has been initalized)
430
431 if ( (&label) != NULL && label != wxPG_LABEL )
432 m_label = label;
433
434 if ( (&name) != NULL && name != wxPG_LABEL )
435 DoSetName( name );
436 else
437 DoSetName( m_label );
438
439 Init();
440 }
441
442 void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState,
443 wxPropertyGrid* propgrid )
444 {
445 //
446 // Called after property has been added to grid or page
447 // (so propgrid can be NULL, too).
448
449 wxPGProperty* parent = m_parent;
450 bool parentIsRoot = parent->IsKindOf(CLASSINFO(wxPGRootProperty));
451
452 m_parentState = pageState;
453
454 #if wxPG_COMPATIBILITY_1_4
455 // Make sure deprecated virtual functions are not implemented
456 wxString s = GetValueAsString( 0xFFFF );
457 wxASSERT_MSG( s == g_invalidStringContent,
458 "Implement ValueToString() instead of GetValueAsString()" );
459 #endif
460
461 if ( !parentIsRoot && !parent->IsCategory() )
462 {
463 m_cells = parent->m_cells;
464 }
465
466 // If in hideable adding mode, or if assigned parent is hideable, then
467 // make this one hideable.
468 if (
469 ( !parentIsRoot && parent->HasFlag(wxPG_PROP_HIDDEN) ) ||
470 ( propgrid && (propgrid->HasInternalFlag(wxPG_FL_ADDING_HIDEABLES)) )
471 )
472 SetFlag( wxPG_PROP_HIDDEN );
473
474 // Set custom image flag.
475 int custImgHeight = OnMeasureImage().y;
476 if ( custImgHeight < 0 )
477 {
478 SetFlag(wxPG_PROP_CUSTOMIMAGE);
479 }
480
481 if ( propgrid && (propgrid->HasFlag(wxPG_LIMITED_EDITING)) )
482 SetFlag(wxPG_PROP_NOEDITOR);
483
484 // Make sure parent has some parental flags
485 if ( !parent->HasFlag(wxPG_PROP_PARENTAL_FLAGS) )
486 parent->SetParentalType(wxPG_PROP_MISC_PARENT);
487
488 if ( !IsCategory() )
489 {
490 // This is not a category.
491
492 // Depth.
493 //
494 unsigned char depth = 1;
495 if ( !parentIsRoot )
496 {
497 depth = parent->m_depth;
498 if ( !parent->IsCategory() )
499 depth++;
500 }
501 m_depth = depth;
502 unsigned char greyDepth = depth;
503
504 if ( !parentIsRoot )
505 {
506 wxPropertyCategory* pc;
507
508 if ( parent->IsCategory() )
509 pc = (wxPropertyCategory* ) parent;
510 else
511 // This conditional compile is necessary to
512 // bypass some compiler bug.
513 pc = pageState->GetPropertyCategory(parent);
514
515 if ( pc )
516 greyDepth = pc->GetDepth();
517 else
518 greyDepth = parent->m_depthBgCol;
519 }
520
521 m_depthBgCol = greyDepth;
522 }
523 else
524 {
525 // This is a category.
526
527 // depth
528 unsigned char depth = 1;
529 if ( !parentIsRoot )
530 {
531 depth = parent->m_depth + 1;
532 }
533 m_depth = depth;
534 m_depthBgCol = depth;
535 }
536
537 //
538 // Has initial children
539 if ( GetChildCount() )
540 {
541 // Check parental flags
542 wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS),
543 "Call SetFlag(wxPG_PROP_MISC_PARENT) or"
544 "SetFlag(wxPG_PROP_AGGREGATE) before calling"
545 "wxPGProperty::AddChild()." );
546
547 if ( HasFlag(wxPG_PROP_AGGREGATE) )
548 {
549 // Properties with private children are not expanded by default.
550 SetExpanded(false);
551 }
552 else if ( propgrid && propgrid->HasFlag(wxPG_HIDE_MARGIN) )
553 {
554 // ...unless it cannot be expanded by user and therefore must
555 // remain visible at all times
556 SetExpanded(true);
557 }
558
559 //
560 // Prepare children recursively
561 for ( unsigned int i=0; i<GetChildCount(); i++ )
562 {
563 wxPGProperty* child = Item(i);
564 child->InitAfterAdded(pageState, pageState->GetGrid());
565 }
566
567 if ( propgrid && (propgrid->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES) )
568 SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED, true);
569 }
570 }
571
572 wxPGProperty::wxPGProperty()
573 : wxObject()
574 {
575 Init();
576 }
577
578
579 wxPGProperty::wxPGProperty( const wxString& label, const wxString& name )
580 : wxObject()
581 {
582 Init( label, name );
583 }
584
585
586 wxPGProperty::~wxPGProperty()
587 {
588 delete m_clientObject;
589
590 Empty(); // this deletes items
591
592 delete m_valueBitmap;
593 #if wxUSE_VALIDATORS
594 delete m_validator;
595 #endif
596
597 // This makes it easier for us to detect dangling pointers
598 m_parent = NULL;
599 }
600
601
602 bool wxPGProperty::IsSomeParent( wxPGProperty* candidate ) const
603 {
604 wxPGProperty* parent = m_parent;
605 do
606 {
607 if ( parent == candidate )
608 return true;
609 parent = parent->m_parent;
610 } while ( parent );
611 return false;
612 }
613
614
615 wxString wxPGProperty::GetName() const
616 {
617 wxPGProperty* parent = GetParent();
618
619 if ( !m_name.length() || !parent || parent->IsCategory() || parent->IsRoot() )
620 return m_name;
621
622 return m_parent->GetName() + wxS(".") + m_name;
623 }
624
625 wxPropertyGrid* wxPGProperty::GetGrid() const
626 {
627 if ( !m_parentState )
628 return NULL;
629 return m_parentState->GetGrid();
630 }
631
632 int wxPGProperty::Index( const wxPGProperty* p ) const
633 {
634 for ( unsigned int i = 0; i<m_children.size(); i++ )
635 {
636 if ( p == m_children[i] )
637 return i;
638 }
639 return wxNOT_FOUND;
640 }
641
642 bool wxPGProperty::ValidateValue( wxVariant& WXUNUSED(value), wxPGValidationInfo& WXUNUSED(validationInfo) ) const
643 {
644 return true;
645 }
646
647 void wxPGProperty::OnSetValue()
648 {
649 }
650
651 void wxPGProperty::RefreshChildren ()
652 {
653 }
654
655 void wxPGProperty::GetDisplayInfo( unsigned int column,
656 int choiceIndex,
657 int flags,
658 wxString* pString,
659 const wxPGCell** pCell )
660 {
661 const wxPGCell* cell = NULL;
662
663 if ( !(flags & wxPGCellRenderer::ChoicePopup) )
664 {
665 // Not painting listi of choice popups, so get text from property
666 cell = &GetCell(column);
667 if ( cell->HasText() )
668 {
669 *pString = cell->GetText();
670 }
671 else
672 {
673 if ( column == 0 )
674 *pString = GetLabel();
675 else if ( column == 1 )
676 *pString = GetDisplayedString();
677 else if ( column == 2 )
678 *pString = GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
679 }
680 }
681 else
682 {
683 wxASSERT( column == 1 );
684
685 if ( choiceIndex != wxNOT_FOUND )
686 {
687 const wxPGChoiceEntry& entry = m_choices[choiceIndex];
688 if ( entry.GetBitmap().IsOk() ||
689 entry.GetFgCol().IsOk() ||
690 entry.GetBgCol().IsOk() )
691 cell = &entry;
692 *pString = m_choices.GetLabel(choiceIndex);
693 }
694 }
695
696 if ( !cell )
697 cell = &GetCell(column);
698
699 wxASSERT_MSG( cell->GetData(),
700 wxString::Format("Invalid cell for property %s",
701 GetName().c_str()) );
702
703 *pCell = cell;
704 }
705
706 /*
707 wxString wxPGProperty::GetColumnText( unsigned int col, int choiceIndex ) const
708 {
709
710 if ( col != 1 || choiceIndex == wxNOT_FOUND )
711 {
712 const wxPGCell& cell = GetCell(col);
713 if ( cell->HasText() )
714 {
715 return cell->GetText();
716 }
717 else
718 {
719 if ( col == 0 )
720 return GetLabel();
721 else if ( col == 1 )
722 return GetDisplayedString();
723 else if ( col == 2 )
724 return GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString);
725 }
726 }
727 else
728 {
729 // Use choice
730 return m_choices.GetLabel(choiceIndex);
731 }
732
733 return wxEmptyString;
734 }
735 */
736
737 void wxPGProperty::DoGenerateComposedValue( wxString& text,
738 int argFlags,
739 const wxVariantList* valueOverrides,
740 wxPGHashMapS2S* childResults ) const
741 {
742 int i;
743 int iMax = m_children.size();
744
745 text.clear();
746 if ( iMax == 0 )
747 return;
748
749 if ( iMax > PWC_CHILD_SUMMARY_LIMIT &&
750 !(argFlags & wxPG_FULL_VALUE) )
751 iMax = PWC_CHILD_SUMMARY_LIMIT;
752
753 int iMaxMinusOne = iMax-1;
754
755 if ( !IsTextEditable() )
756 argFlags |= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT;
757
758 wxPGProperty* curChild = m_children[0];
759
760 bool overridesLeft = false;
761 wxVariant overrideValue;
762 wxVariantList::const_iterator node;
763
764 if ( valueOverrides )
765 {
766 node = valueOverrides->begin();
767 if ( node != valueOverrides->end() )
768 {
769 overrideValue = *node;
770 overridesLeft = true;
771 }
772 }
773
774 for ( i = 0; i < iMax; i++ )
775 {
776 wxVariant childValue;
777
778 wxString childLabel = curChild->GetLabel();
779
780 // Check for value override
781 if ( overridesLeft && overrideValue.GetName() == childLabel )
782 {
783 if ( !overrideValue.IsNull() )
784 childValue = overrideValue;
785 else
786 childValue = curChild->GetValue();
787 ++node;
788 if ( node != valueOverrides->end() )
789 overrideValue = *node;
790 else
791 overridesLeft = false;
792 }
793 else
794 {
795 childValue = curChild->GetValue();
796 }
797
798 wxString s;
799 if ( !childValue.IsNull() )
800 {
801 if ( overridesLeft &&
802 curChild->HasFlag(wxPG_PROP_COMPOSED_VALUE) &&
803 childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
804 {
805 wxVariantList& childList = childValue.GetList();
806 DoGenerateComposedValue(s, argFlags|wxPG_COMPOSITE_FRAGMENT,
807 &childList, childResults);
808 }
809 else
810 {
811 s = curChild->ValueToString(childValue,
812 argFlags|wxPG_COMPOSITE_FRAGMENT);
813 }
814 }
815
816 if ( childResults && curChild->GetChildCount() )
817 (*childResults)[curChild->GetName()] = s;
818
819 bool skip = false;
820 if ( (argFlags & wxPG_UNEDITABLE_COMPOSITE_FRAGMENT) && !s.length() )
821 skip = true;
822
823 if ( !curChild->GetChildCount() || skip )
824 text += s;
825 else
826 text += wxS("[") + s + wxS("]");
827
828 if ( i < iMaxMinusOne )
829 {
830 if ( text.length() > PWC_CHILD_SUMMARY_CHAR_LIMIT &&
831 !(argFlags & wxPG_EDITABLE_VALUE) &&
832 !(argFlags & wxPG_FULL_VALUE) )
833 break;
834
835 if ( !skip )
836 {
837 if ( !curChild->GetChildCount() )
838 text += wxS("; ");
839 else
840 text += wxS(" ");
841 }
842
843 curChild = m_children[i+1];
844 }
845 }
846
847 if ( (unsigned int)i < m_children.size() )
848 {
849 if ( !text.EndsWith(wxS("; ")) )
850 text += wxS("; ...");
851 else
852 text += wxS("...");
853 }
854 }
855
856 wxString wxPGProperty::ValueToString( wxVariant& WXUNUSED(value),
857 int argFlags ) const
858 {
859 wxCHECK_MSG( GetChildCount() > 0,
860 wxString(),
861 "If user property does not have any children, it must "
862 "override GetValueAsString" );
863
864 // FIXME: Currently code below only works if value is actually m_value
865 wxASSERT_MSG( argFlags & wxPG_VALUE_IS_CURRENT,
866 "Sorry, currently default wxPGProperty::ValueToString() "
867 "implementation only works if value is m_value." );
868
869 wxString text;
870 DoGenerateComposedValue(text, argFlags);
871 return text;
872 }
873
874 wxString wxPGProperty::GetValueAsString( int argFlags ) const
875 {
876 #if wxPG_COMPATIBILITY_1_4
877 // This is backwards compatibility test
878 // That is, to make sure this function is not overridden
879 // (instead, ValueToString() should be).
880 if ( argFlags == 0xFFFF )
881 {
882 // Do not override! (for backwards compliancy)
883 return g_invalidStringContent;
884 }
885 #endif
886
887 if ( IsValueUnspecified() )
888 return wxEmptyString;
889
890 if ( m_commonValue == -1 )
891 {
892 wxVariant value(GetValue());
893 return ValueToString(value, argFlags|wxPG_VALUE_IS_CURRENT);
894 }
895
896 //
897 // Return common value's string representation
898 wxPropertyGrid* pg = GetGrid();
899 const wxPGCommonValue* cv = pg->GetCommonValue(m_commonValue);
900
901 if ( argFlags & wxPG_FULL_VALUE )
902 {
903 return cv->GetLabel();
904 }
905 else if ( argFlags & wxPG_EDITABLE_VALUE )
906 {
907 return cv->GetEditableText();
908 }
909 else
910 {
911 return cv->GetLabel();
912 }
913 }
914
915 wxString wxPGProperty::GetValueString( int argFlags ) const
916 {
917 return GetValueAsString(argFlags);
918 }
919
920 bool wxPGProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(argFlags) ) const
921 {
922 variant = (long)number;
923 return true;
924 }
925
926 // Convert semicolon delimited tokens into child values.
927 bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const
928 {
929 if ( !GetChildCount() )
930 return false;
931
932 unsigned int curChild = 0;
933
934 unsigned int iMax = m_children.size();
935
936 if ( iMax > PWC_CHILD_SUMMARY_LIMIT &&
937 !(argFlags & wxPG_FULL_VALUE) )
938 iMax = PWC_CHILD_SUMMARY_LIMIT;
939
940 bool changed = false;
941
942 wxString token;
943 size_t pos = 0;
944
945 // Its best only to add non-empty group items
946 bool addOnlyIfNotEmpty = false;
947 const wxChar delimeter = wxS(';');
948
949 size_t tokenStart = 0xFFFFFF;
950
951 wxVariantList temp_list;
952 wxVariant list(temp_list);
953
954 int propagatedFlags = argFlags & (wxPG_REPORT_ERROR|wxPG_PROGRAMMATIC_VALUE);
955
956 #ifdef __WXDEBUG__
957 bool debug_print = false;
958 #endif
959
960 #ifdef __WXDEBUG__
961 if ( debug_print )
962 wxLogDebug(wxT(">> %s.StringToValue('%s')"),GetLabel().c_str(),text.c_str());
963 #endif
964
965 wxString::const_iterator it = text.begin();
966 wxUniChar a;
967
968 if ( it != text.end() )
969 a = *it;
970 else
971 a = 0;
972
973 for ( ;; )
974 {
975 if ( tokenStart != 0xFFFFFF )
976 {
977 // Token is running
978 if ( a == delimeter || a == 0 )
979 {
980 token = text.substr(tokenStart,pos-tokenStart);
981 token.Trim(true);
982 size_t len = token.length();
983
984 if ( !addOnlyIfNotEmpty || len > 0 )
985 {
986 const wxPGProperty* child = Item(curChild);
987 wxVariant variant(child->GetValue());
988 variant.SetName(child->GetBaseName());
989
990 #ifdef __WXDEBUG__
991 if ( debug_print )
992 wxLogDebug(wxT("token = '%s', child = %s"),token.c_str(),child->GetLabel().c_str());
993 #endif
994
995 // Add only if editable or setting programmatically
996 if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) ||
997 !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) )
998 {
999 if ( len > 0 )
1000 {
1001 if ( child->StringToValue(variant, token, propagatedFlags|wxPG_COMPOSITE_FRAGMENT) )
1002 {
1003 list.Append(variant);
1004
1005 changed = true;
1006 }
1007 }
1008 else
1009 {
1010 // Empty, becomes unspecified
1011 variant.MakeNull();
1012 list.Append(variant);
1013 changed = true;
1014 }
1015 }
1016
1017 curChild++;
1018 if ( curChild >= iMax )
1019 break;
1020 }
1021
1022 tokenStart = 0xFFFFFF;
1023 }
1024 }
1025 else
1026 {
1027 // Token is not running
1028 if ( a != wxS(' ') )
1029 {
1030
1031 addOnlyIfNotEmpty = false;
1032
1033 // Is this a group of tokens?
1034 if ( a == wxS('[') )
1035 {
1036 int depth = 1;
1037
1038 if ( it != text.end() ) ++it;
1039 pos++;
1040 size_t startPos = pos;
1041
1042 // Group item - find end
1043 while ( it != text.end() && depth > 0 )
1044 {
1045 a = *it;
1046 ++it;
1047 pos++;
1048
1049 if ( a == wxS(']') )
1050 depth--;
1051 else if ( a == wxS('[') )
1052 depth++;
1053 }
1054
1055 token = text.substr(startPos,pos-startPos-1);
1056
1057 if ( !token.length() )
1058 break;
1059
1060 const wxPGProperty* child = Item(curChild);
1061
1062 wxVariant oldChildValue = child->GetValue();
1063 wxVariant variant(oldChildValue);
1064
1065 if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) ||
1066 !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) )
1067 {
1068 bool stvRes = child->StringToValue( variant, token, propagatedFlags );
1069 if ( stvRes || (variant != oldChildValue) )
1070 {
1071 if ( stvRes )
1072 changed = true;
1073 }
1074 else
1075 {
1076 // Failed, becomes unspecified
1077 variant.MakeNull();
1078 changed = true;
1079 }
1080 }
1081
1082 variant.SetName(child->GetBaseName());
1083 list.Append(variant);
1084
1085 curChild++;
1086 if ( curChild >= iMax )
1087 break;
1088
1089 addOnlyIfNotEmpty = true;
1090
1091 tokenStart = 0xFFFFFF;
1092 }
1093 else
1094 {
1095 tokenStart = pos;
1096
1097 if ( a == delimeter )
1098 {
1099 pos--;
1100 --it;
1101 }
1102 }
1103 }
1104 }
1105
1106 if ( a == 0 )
1107 break;
1108
1109 ++it;
1110 if ( it != text.end() )
1111 {
1112 a = *it;
1113 }
1114 else
1115 {
1116 a = 0;
1117 }
1118 pos++;
1119 }
1120
1121 if ( changed )
1122 variant = list;
1123
1124 return changed;
1125 }
1126
1127 bool wxPGProperty::SetValueFromString( const wxString& text, int argFlags )
1128 {
1129 wxVariant variant(m_value);
1130 bool res = StringToValue(variant, text, argFlags);
1131 if ( res )
1132 SetValue(variant);
1133 return res;
1134 }
1135
1136 bool wxPGProperty::SetValueFromInt( long number, int argFlags )
1137 {
1138 wxVariant variant(m_value);
1139 bool res = IntToValue(variant, number, argFlags);
1140 if ( res )
1141 SetValue(variant);
1142 return res;
1143 }
1144
1145 wxSize wxPGProperty::OnMeasureImage( int WXUNUSED(item) ) const
1146 {
1147 if ( m_valueBitmap )
1148 return wxSize(m_valueBitmap->GetWidth(),-1);
1149
1150 return wxSize(0,0);
1151 }
1152
1153 wxPGCellRenderer* wxPGProperty::GetCellRenderer( int WXUNUSED(column) ) const
1154 {
1155 return wxPGGlobalVars->m_defaultRenderer;
1156 }
1157
1158 void wxPGProperty::OnCustomPaint( wxDC& dc,
1159 const wxRect& rect,
1160 wxPGPaintData& )
1161 {
1162 wxBitmap* bmp = m_valueBitmap;
1163
1164 wxCHECK_RET( bmp && bmp->Ok(), wxT("invalid bitmap") );
1165
1166 wxCHECK_RET( rect.x >= 0, wxT("unexpected measure call") );
1167
1168 dc.DrawBitmap(*bmp,rect.x,rect.y);
1169 }
1170
1171 const wxPGEditor* wxPGProperty::DoGetEditorClass() const
1172 {
1173 return wxPGEditor_TextCtrl;
1174 }
1175
1176 // Default extra property event handling - that is, none at all.
1177 bool wxPGProperty::OnEvent( wxPropertyGrid*, wxWindow*, wxEvent& )
1178 {
1179 return false;
1180 }
1181
1182
1183 void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
1184 {
1185 // If auto unspecified values are not wanted (via window or property style),
1186 // then get default value instead of wxNullVariant.
1187 if ( value.IsNull() && (flags & wxPG_SETVAL_BY_USER) &&
1188 !UsesAutoUnspecified() )
1189 {
1190 value = GetDefaultValue();
1191 }
1192
1193 if ( !value.IsNull() )
1194 {
1195 wxVariant tempListVariant;
1196
1197 SetCommonValue(-1);
1198 // List variants are reserved a special purpose
1199 // as intermediate containers for child values
1200 // of properties with children.
1201 if ( value.GetType() == wxPG_VARIANT_TYPE_LIST )
1202 {
1203 //
1204 // However, situation is different for composed string properties
1205 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE) )
1206 {
1207 tempListVariant = value;
1208 pList = &tempListVariant;
1209 }
1210
1211 wxVariant newValue;
1212 AdaptListToValue(value, &newValue);
1213 value = newValue;
1214 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1215 }
1216
1217 if ( HasFlag( wxPG_PROP_AGGREGATE) )
1218 flags |= wxPG_SETVAL_AGGREGATED;
1219
1220 if ( pList && !pList->IsNull() )
1221 {
1222 wxASSERT( pList->GetType() == wxPG_VARIANT_TYPE_LIST );
1223 wxASSERT( GetChildCount() );
1224 wxASSERT( !IsCategory() );
1225
1226 wxVariantList& list = pList->GetList();
1227 wxVariantList::iterator node;
1228 unsigned int i = 0;
1229
1230 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1231
1232 // Children in list can be in any order, but we will give hint to
1233 // GetPropertyByNameWH(). This optimizes for full list parsing.
1234 for ( node = list.begin(); node != list.end(); ++node )
1235 {
1236 wxVariant& childValue = *((wxVariant*)*node);
1237 wxPGProperty* child = GetPropertyByNameWH(childValue.GetName(), i);
1238 if ( child )
1239 {
1240 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1241 if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
1242 {
1243 if ( child->HasFlag(wxPG_PROP_AGGREGATE) && !(flags & wxPG_SETVAL_AGGREGATED) )
1244 {
1245 wxVariant listRefCopy = childValue;
1246 child->SetValue(childValue, &listRefCopy, flags|wxPG_SETVAL_FROM_PARENT);
1247 }
1248 else
1249 {
1250 wxVariant oldVal = child->GetValue();
1251 child->SetValue(oldVal, &childValue, flags|wxPG_SETVAL_FROM_PARENT);
1252 }
1253 }
1254 else if ( child->GetValue() != childValue )
1255 {
1256 // For aggregate properties, we will trust RefreshChildren()
1257 // to update child values.
1258 if ( !HasFlag(wxPG_PROP_AGGREGATE) )
1259 child->SetValue(childValue, NULL, flags|wxPG_SETVAL_FROM_PARENT);
1260 if ( flags & wxPG_SETVAL_BY_USER )
1261 child->SetFlag(wxPG_PROP_MODIFIED);
1262 }
1263 }
1264 i++;
1265 }
1266 }
1267
1268 if ( !value.IsNull() )
1269 {
1270 m_value = value;
1271 OnSetValue();
1272
1273 if ( !(flags & wxPG_SETVAL_FROM_PARENT) )
1274 UpdateParentValues();
1275 }
1276
1277 if ( flags & wxPG_SETVAL_BY_USER )
1278 SetFlag(wxPG_PROP_MODIFIED);
1279
1280 if ( HasFlag(wxPG_PROP_AGGREGATE) )
1281 RefreshChildren();
1282 }
1283 else
1284 {
1285 if ( m_commonValue != -1 )
1286 {
1287 wxPropertyGrid* pg = GetGrid();
1288 if ( !pg || m_commonValue != pg->GetUnspecifiedCommonValue() )
1289 SetCommonValue(-1);
1290 }
1291
1292 m_value = value;
1293
1294 // Set children to unspecified, but only if aggregate or
1295 // value is <composed>
1296 if ( AreChildrenComponents() )
1297 {
1298 unsigned int i;
1299 for ( i=0; i<GetChildCount(); i++ )
1300 Item(i)->SetValue(value, NULL, flags|wxPG_SETVAL_FROM_PARENT);
1301 }
1302 }
1303
1304 //
1305 // Update editor control
1306 //
1307
1308 // We need to check for these, otherwise GetGrid() may fail.
1309 if ( flags & wxPG_SETVAL_REFRESH_EDITOR )
1310 RefreshEditor();
1311 }
1312
1313
1314 void wxPGProperty::SetValueInEvent( wxVariant value ) const
1315 {
1316 GetGrid()->ValueChangeInEvent(value);
1317 }
1318
1319 void wxPGProperty::SetFlagRecursively( FlagType flag, bool set )
1320 {
1321 if ( set )
1322 SetFlag(flag);
1323 else
1324 ClearFlag(flag);
1325
1326 unsigned int i;
1327 for ( i = 0; i < GetChildCount(); i++ )
1328 Item(i)->SetFlagRecursively(flag, set);
1329 }
1330
1331 void wxPGProperty::RefreshEditor()
1332 {
1333 if ( !m_parent )
1334 return;
1335
1336 wxPropertyGrid* pg = GetGrid();
1337 if ( pg && pg->GetSelectedProperty() == this )
1338 pg->RefreshEditor();
1339 }
1340
1341 wxVariant wxPGProperty::GetDefaultValue() const
1342 {
1343 wxVariant defVal = GetAttribute(wxS("DefaultValue"));
1344 if ( !defVal.IsNull() )
1345 return defVal;
1346
1347 wxVariant value = GetValue();
1348
1349 if ( !value.IsNull() )
1350 {
1351 wxString valueType(value.GetType());
1352
1353 if ( valueType == wxPG_VARIANT_TYPE_LONG )
1354 return wxPGVariant_Zero;
1355 if ( valueType == wxPG_VARIANT_TYPE_STRING )
1356 return wxPGVariant_EmptyString;
1357 if ( valueType == wxPG_VARIANT_TYPE_BOOL )
1358 return wxPGVariant_False;
1359 if ( valueType == wxPG_VARIANT_TYPE_DOUBLE )
1360 return wxVariant(0.0);
1361 if ( valueType == wxPG_VARIANT_TYPE_ARRSTRING )
1362 return wxVariant(wxArrayString());
1363 if ( valueType == wxS("wxLongLong") )
1364 return WXVARIANT(wxLongLong(0));
1365 if ( valueType == wxS("wxULongLong") )
1366 return WXVARIANT(wxULongLong(0));
1367 if ( valueType == wxS("wxColour") )
1368 return WXVARIANT(*wxBLACK);
1369 #if wxUSE_DATETIME
1370 if ( valueType == wxPG_VARIANT_TYPE_DATETIME )
1371 return wxVariant(wxDateTime::Now());
1372 #endif
1373 if ( valueType == wxS("wxFont") )
1374 return WXVARIANT(*wxNORMAL_FONT);
1375 if ( valueType == wxS("wxPoint") )
1376 return WXVARIANT(wxPoint(0, 0));
1377 if ( valueType == wxS("wxSize") )
1378 return WXVARIANT(wxSize(0, 0));
1379 }
1380
1381 return wxVariant();
1382 }
1383
1384 void wxPGProperty::EnsureCells( unsigned int column )
1385 {
1386 if ( column >= m_cells.size() )
1387 {
1388 // Fill empty slots with default cells
1389 wxPropertyGrid* pg = GetGrid();
1390 wxPGCell defaultCell;
1391
1392 if ( !HasFlag(wxPG_PROP_CATEGORY) )
1393 defaultCell = pg->GetPropertyDefaultCell();
1394 else
1395 defaultCell = pg->GetCategoryDefaultCell();
1396
1397 // TODO: Replace with resize() call
1398 unsigned int cellCountMax = column+1;
1399
1400 for ( unsigned int i=m_cells.size(); i<cellCountMax; i++ )
1401 m_cells.push_back(defaultCell);
1402 }
1403 }
1404
1405 void wxPGProperty::SetCell( int column,
1406 const wxPGCell& cell )
1407 {
1408 EnsureCells(column);
1409
1410 m_cells[column] = cell;
1411 }
1412
1413 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol,
1414 unsigned int lastCol,
1415 const wxPGCell& cell,
1416 const wxPGCell& srcData,
1417 wxPGCellData* unmodCellData,
1418 FlagType ignoreWithFlags,
1419 bool recursively )
1420 {
1421 //
1422 // Sets cell in memory optimizing fashion. That is, if
1423 // current cell data matches unmodCellData, we will
1424 // simply get reference to data from cell. Otherwise,
1425 // cell information from srcData is merged into current.
1426 //
1427
1428 if ( !(m_flags & ignoreWithFlags) && !IsRoot() )
1429 {
1430 EnsureCells(lastCol);
1431
1432 for ( unsigned int col=firstCol; col<=lastCol; col++ )
1433 {
1434 if ( m_cells[col].GetData() == unmodCellData )
1435 {
1436 // Data matches... use cell directly
1437 m_cells[col] = cell;
1438 }
1439 else
1440 {
1441 // Data did not match... merge valid information
1442 m_cells[col].MergeFrom(srcData);
1443 }
1444 }
1445 }
1446
1447 if ( recursively )
1448 {
1449 for ( unsigned int i=0; i<GetChildCount(); i++ )
1450 Item(i)->AdaptiveSetCell( firstCol,
1451 lastCol,
1452 cell,
1453 srcData,
1454 unmodCellData,
1455 ignoreWithFlags,
1456 recursively );
1457 }
1458 }
1459
1460 const wxPGCell& wxPGProperty::GetCell( unsigned int column ) const
1461 {
1462 if ( m_cells.size() > column )
1463 return m_cells[column];
1464
1465 wxPropertyGrid* pg = GetGrid();
1466
1467 if ( IsCategory() )
1468 return pg->GetCategoryDefaultCell();
1469
1470 return pg->GetPropertyDefaultCell();
1471 }
1472
1473 wxPGCell& wxPGProperty::GetCell( unsigned int column )
1474 {
1475 EnsureCells(column);
1476 return m_cells[column];
1477 }
1478
1479 void wxPGProperty::SetBackgroundColour( const wxColour& colour,
1480 bool recursively )
1481 {
1482 wxPGProperty* firstProp = this;
1483
1484 //
1485 // If category is tried to set recursively, skip it and only
1486 // affect the children.
1487 if ( recursively )
1488 {
1489 while ( firstProp->IsCategory() )
1490 {
1491 if ( !firstProp->GetChildCount() )
1492 return;
1493 firstProp = firstProp->Item(0);
1494 }
1495 }
1496
1497 wxPGCell& firstCell = firstProp->GetCell(0);
1498 wxPGCellData* firstCellData = firstCell.GetData();
1499
1500 wxPGCell newCell(firstCell);
1501 newCell.SetBgCol(colour);
1502 wxPGCell srcCell;
1503 srcCell.SetBgCol(colour);
1504
1505 AdaptiveSetCell( 0,
1506 GetParentState()->GetColumnCount()-1,
1507 newCell,
1508 srcCell,
1509 firstCellData,
1510 recursively ? wxPG_PROP_CATEGORY : 0,
1511 recursively );
1512 }
1513
1514 void wxPGProperty::SetTextColour( const wxColour& colour,
1515 bool recursively )
1516 {
1517 wxPGProperty* firstProp = this;
1518
1519 //
1520 // If category is tried to set recursively, skip it and only
1521 // affect the children.
1522 if ( recursively )
1523 {
1524 while ( firstProp->IsCategory() )
1525 {
1526 if ( !firstProp->GetChildCount() )
1527 return;
1528 firstProp = firstProp->Item(0);
1529 }
1530 }
1531
1532 wxPGCell& firstCell = firstProp->GetCell(0);
1533 wxPGCellData* firstCellData = firstCell.GetData();
1534
1535 wxPGCell newCell(firstCell);
1536 newCell.SetFgCol(colour);
1537 wxPGCell srcCell;
1538 srcCell.SetFgCol(colour);
1539
1540 AdaptiveSetCell( 0,
1541 GetParentState()->GetColumnCount()-1,
1542 newCell,
1543 srcCell,
1544 firstCellData,
1545 recursively ? wxPG_PROP_CATEGORY : 0,
1546 recursively );
1547 }
1548
1549 wxPGEditorDialogAdapter* wxPGProperty::GetEditorDialog() const
1550 {
1551 return NULL;
1552 }
1553
1554 bool wxPGProperty::DoSetAttribute( const wxString& WXUNUSED(name), wxVariant& WXUNUSED(value) )
1555 {
1556 return false;
1557 }
1558
1559 void wxPGProperty::SetAttribute( const wxString& name, wxVariant value )
1560 {
1561 if ( DoSetAttribute( name, value ) )
1562 {
1563 // Support working without grid, when possible
1564 if ( wxPGGlobalVars->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES ) )
1565 return;
1566 }
1567
1568 m_attributes.Set( name, value );
1569 }
1570
1571 void wxPGProperty::SetAttributes( const wxPGAttributeStorage& attributes )
1572 {
1573 wxPGAttributeStorage::const_iterator it = attributes.StartIteration();
1574 wxVariant variant;
1575
1576 while ( attributes.GetNext(it, variant) )
1577 SetAttribute( variant.GetName(), variant );
1578 }
1579
1580 wxVariant wxPGProperty::DoGetAttribute( const wxString& WXUNUSED(name) ) const
1581 {
1582 return wxVariant();
1583 }
1584
1585
1586 wxVariant wxPGProperty::GetAttribute( const wxString& name ) const
1587 {
1588 return m_attributes.FindValue(name);
1589 }
1590
1591 wxString wxPGProperty::GetAttribute( const wxString& name, const wxString& defVal ) const
1592 {
1593 wxVariant variant = m_attributes.FindValue(name);
1594
1595 if ( !variant.IsNull() )
1596 return variant.GetString();
1597
1598 return defVal;
1599 }
1600
1601 long wxPGProperty::GetAttributeAsLong( const wxString& name, long defVal ) const
1602 {
1603 wxVariant variant = m_attributes.FindValue(name);
1604
1605 return wxPGVariantToInt(variant, defVal);
1606 }
1607
1608 double wxPGProperty::GetAttributeAsDouble( const wxString& name, double defVal ) const
1609 {
1610 double retVal;
1611 wxVariant variant = m_attributes.FindValue(name);
1612
1613 if ( wxPGVariantToDouble(variant, &retVal) )
1614 return retVal;
1615
1616 return defVal;
1617 }
1618
1619 wxVariant wxPGProperty::GetAttributesAsList() const
1620 {
1621 wxVariantList tempList;
1622 wxVariant v( tempList, wxString::Format(wxS("@%s@attr"),m_name.c_str()) );
1623
1624 wxPGAttributeStorage::const_iterator it = m_attributes.StartIteration();
1625 wxVariant variant;
1626
1627 while ( m_attributes.GetNext(it, variant) )
1628 v.Append(variant);
1629
1630 return v;
1631 }
1632
1633 // Slots of utility flags are NULL
1634 const unsigned int gs_propFlagToStringSize = 14;
1635
1636 static const wxChar* gs_propFlagToString[gs_propFlagToStringSize] = {
1637 NULL,
1638 wxT("DISABLED"),
1639 wxT("HIDDEN"),
1640 NULL,
1641 wxT("NOEDITOR"),
1642 wxT("COLLAPSED"),
1643 NULL,
1644 NULL,
1645 NULL,
1646 NULL,
1647 NULL,
1648 NULL,
1649 NULL,
1650 NULL
1651 };
1652
1653 wxString wxPGProperty::GetFlagsAsString( FlagType flagsMask ) const
1654 {
1655 wxString s;
1656 int relevantFlags = m_flags & flagsMask & wxPG_STRING_STORED_FLAGS;
1657 FlagType a = 1;
1658
1659 unsigned int i = 0;
1660 for ( i=0; i<gs_propFlagToStringSize; i++ )
1661 {
1662 if ( relevantFlags & a )
1663 {
1664 const wxChar* fs = gs_propFlagToString[i];
1665 wxASSERT(fs);
1666 if ( s.length() )
1667 s << wxS("|");
1668 s << fs;
1669 }
1670 a = a << 1;
1671 }
1672
1673 return s;
1674 }
1675
1676 void wxPGProperty::SetFlagsFromString( const wxString& str )
1677 {
1678 FlagType flags = 0;
1679
1680 WX_PG_TOKENIZER1_BEGIN(str, wxS('|'))
1681 unsigned int i;
1682 for ( i=0; i<gs_propFlagToStringSize; i++ )
1683 {
1684 const wxChar* fs = gs_propFlagToString[i];
1685 if ( fs && str == fs )
1686 {
1687 flags |= (1<<i);
1688 break;
1689 }
1690 }
1691 WX_PG_TOKENIZER1_END()
1692
1693 m_flags = (m_flags & ~wxPG_STRING_STORED_FLAGS) | flags;
1694 }
1695
1696 wxValidator* wxPGProperty::DoGetValidator() const
1697 {
1698 return (wxValidator*) NULL;
1699 }
1700
1701 int wxPGProperty::InsertChoice( const wxString& label, int index, int value )
1702 {
1703 wxPropertyGrid* pg = GetGrid();
1704 int sel = GetChoiceSelection();
1705
1706 int newSel = sel;
1707
1708 if ( index == wxNOT_FOUND )
1709 index = m_choices.GetCount();
1710
1711 if ( index <= sel )
1712 newSel++;
1713
1714 m_choices.Insert(label, index, value);
1715
1716 if ( sel != newSel )
1717 SetChoiceSelection(newSel);
1718
1719 if ( this == pg->GetSelection() )
1720 GetEditorClass()->InsertItem(pg->GetEditorControl(),label,index);
1721
1722 return index;
1723 }
1724
1725
1726 void wxPGProperty::DeleteChoice( int index )
1727 {
1728 wxPropertyGrid* pg = GetGrid();
1729
1730 int sel = GetChoiceSelection();
1731 int newSel = sel;
1732
1733 // Adjust current value
1734 if ( sel == index )
1735 {
1736 SetValueToUnspecified();
1737 newSel = 0;
1738 }
1739 else if ( index < sel )
1740 {
1741 newSel--;
1742 }
1743
1744 m_choices.RemoveAt(index);
1745
1746 if ( sel != newSel )
1747 SetChoiceSelection(newSel);
1748
1749 if ( this == pg->GetSelection() )
1750 GetEditorClass()->DeleteItem(pg->GetEditorControl(), index);
1751 }
1752
1753 int wxPGProperty::GetChoiceSelection() const
1754 {
1755 wxVariant value = GetValue();
1756 wxString valueType = value.GetType();
1757 int index = wxNOT_FOUND;
1758
1759 if ( IsValueUnspecified() || !m_choices.GetCount() )
1760 return wxNOT_FOUND;
1761
1762 if ( valueType == wxPG_VARIANT_TYPE_LONG )
1763 {
1764 index = value.GetLong();
1765 }
1766 else if ( valueType == wxPG_VARIANT_TYPE_STRING )
1767 {
1768 index = m_choices.Index(value.GetString());
1769 }
1770 else if ( valueType == wxPG_VARIANT_TYPE_BOOL )
1771 {
1772 index = value.GetBool()? 1 : 0;
1773 }
1774
1775 return index;
1776 }
1777
1778 void wxPGProperty::SetChoiceSelection( int newValue )
1779 {
1780 // Changes value of a property with choices, but only
1781 // works if the value type is long or string.
1782 wxString valueType = GetValue().GetType();
1783
1784 wxCHECK_RET( m_choices.IsOk(), wxT("invalid choiceinfo") );
1785
1786 if ( valueType == wxPG_VARIANT_TYPE_STRING )
1787 {
1788 SetValue( m_choices.GetLabel(newValue) );
1789 }
1790 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1791 {
1792 SetValue( (long) newValue );
1793 }
1794 }
1795
1796 bool wxPGProperty::SetChoices( wxPGChoices& choices )
1797 {
1798 m_choices.Assign(choices);
1799
1800 {
1801 // This may be needed to trigger some initialization
1802 // (but don't do it if property is somewhat uninitialized)
1803 wxVariant defVal = GetDefaultValue();
1804 if ( defVal.IsNull() )
1805 return false;
1806
1807 SetValue(defVal);
1808 }
1809
1810 return true;
1811 }
1812
1813
1814 const wxPGEditor* wxPGProperty::GetEditorClass() const
1815 {
1816 const wxPGEditor* editor;
1817
1818 if ( !m_customEditor )
1819 {
1820 editor = DoGetEditorClass();
1821 }
1822 else
1823 editor = m_customEditor;
1824
1825 //
1826 // Maybe override editor if common value specified
1827 if ( GetDisplayedCommonValueCount() )
1828 {
1829 // TextCtrlAndButton -> ComboBoxAndButton
1830 if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor)) )
1831 editor = wxPGEditor_ChoiceAndButton;
1832
1833 // TextCtrl -> ComboBox
1834 else if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlEditor)) )
1835 editor = wxPGEditor_ComboBox;
1836 }
1837
1838 return editor;
1839 }
1840
1841 bool wxPGProperty::HasVisibleChildren() const
1842 {
1843 unsigned int i;
1844
1845 for ( i=0; i<GetChildCount(); i++ )
1846 {
1847 wxPGProperty* child = Item(i);
1848
1849 if ( !child->HasFlag(wxPG_PROP_HIDDEN) )
1850 return true;
1851 }
1852
1853 return false;
1854 }
1855
1856 bool wxPGProperty::RecreateEditor()
1857 {
1858 wxPropertyGrid* pg = GetGrid();
1859 wxASSERT(pg);
1860
1861 wxPGProperty* selected = pg->GetSelection();
1862 if ( this == selected )
1863 {
1864 pg->DoSelectProperty(this, wxPG_SEL_FORCE);
1865 return true;
1866 }
1867 return false;
1868 }
1869
1870
1871 void wxPGProperty::SetValueImage( wxBitmap& bmp )
1872 {
1873 delete m_valueBitmap;
1874
1875 if ( &bmp && bmp.Ok() )
1876 {
1877 // Resize the image
1878 wxSize maxSz = GetGrid()->GetImageSize();
1879 wxSize imSz(bmp.GetWidth(),bmp.GetHeight());
1880
1881 if ( imSz.x != maxSz.x || imSz.y != maxSz.y )
1882 {
1883 // Create a memory DC
1884 wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth());
1885
1886 wxMemoryDC dc;
1887 dc.SelectObject(*bmpNew);
1888
1889 // Scale
1890 // FIXME: This is ugly - use image or wait for scaling patch.
1891 double scaleX = (double)maxSz.x / (double)imSz.x;
1892 double scaleY = (double)maxSz.y / (double)imSz.y;
1893
1894 dc.SetUserScale(scaleX,scaleY);
1895
1896 dc.DrawBitmap( bmp, 0, 0 );
1897
1898 m_valueBitmap = bmpNew;
1899 }
1900 else
1901 {
1902 m_valueBitmap = new wxBitmap(bmp);
1903 }
1904
1905 m_flags |= wxPG_PROP_CUSTOMIMAGE;
1906 }
1907 else
1908 {
1909 m_valueBitmap = NULL;
1910 m_flags &= ~(wxPG_PROP_CUSTOMIMAGE);
1911 }
1912 }
1913
1914
1915 wxPGProperty* wxPGProperty::GetMainParent() const
1916 {
1917 const wxPGProperty* curChild = this;
1918 const wxPGProperty* curParent = m_parent;
1919
1920 while ( curParent && !curParent->IsCategory() )
1921 {
1922 curChild = curParent;
1923 curParent = curParent->m_parent;
1924 }
1925
1926 return (wxPGProperty*) curChild;
1927 }
1928
1929
1930 const wxPGProperty* wxPGProperty::GetLastVisibleSubItem() const
1931 {
1932 //
1933 // Returns last visible sub-item, recursively.
1934 if ( !IsExpanded() || !GetChildCount() )
1935 return this;
1936
1937 return Last()->GetLastVisibleSubItem();
1938 }
1939
1940
1941 bool wxPGProperty::IsVisible() const
1942 {
1943 const wxPGProperty* parent;
1944
1945 if ( HasFlag(wxPG_PROP_HIDDEN) )
1946 return false;
1947
1948 for ( parent = GetParent(); parent != NULL; parent = parent->GetParent() )
1949 {
1950 if ( !parent->IsExpanded() || parent->HasFlag(wxPG_PROP_HIDDEN) )
1951 return false;
1952 }
1953
1954 return true;
1955 }
1956
1957 wxPropertyGrid* wxPGProperty::GetGridIfDisplayed() const
1958 {
1959 wxPropertyGridPageState* state = GetParentState();
1960 wxPropertyGrid* propGrid = state->GetGrid();
1961 if ( state == propGrid->GetState() )
1962 return propGrid;
1963 return NULL;
1964 }
1965
1966
1967 int wxPGProperty::GetY2( int lh ) const
1968 {
1969 const wxPGProperty* parent;
1970 const wxPGProperty* child = this;
1971
1972 int y = 0;
1973
1974 for ( parent = GetParent(); parent != NULL; parent = child->GetParent() )
1975 {
1976 if ( !parent->IsExpanded() )
1977 return -1;
1978 y += parent->GetChildrenHeight(lh, child->GetIndexInParent());
1979 y += lh;
1980 child = parent;
1981 }
1982
1983 y -= lh; // need to reduce one level
1984
1985 return y;
1986 }
1987
1988
1989 int wxPGProperty::GetY() const
1990 {
1991 return GetY2(GetGrid()->GetRowHeight());
1992 }
1993
1994 // This is used by Insert etc.
1995 void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
1996 {
1997 if ( index < 0 || (size_t)index >= m_children.size() )
1998 {
1999 if ( correct_mode ) prop->m_arrIndex = m_children.size();
2000 m_children.push_back( prop );
2001 }
2002 else
2003 {
2004 m_children.insert( m_children.begin()+index, prop);
2005 if ( correct_mode ) FixIndicesOfChildren( index );
2006 }
2007
2008 prop->m_parent = this;
2009 }
2010
2011 // This is used by properties that have fixed sub-properties
2012 void wxPGProperty::AddChild( wxPGProperty* prop )
2013 {
2014 wxASSERT_MSG( prop->GetBaseName().length(),
2015 "Property's children must have unique, non-empty names within their scope" );
2016
2017 prop->m_arrIndex = m_children.size();
2018 m_children.push_back( prop );
2019
2020 int custImgHeight = prop->OnMeasureImage().y;
2021 if ( custImgHeight < 0 /*|| custImgHeight > 1*/ )
2022 prop->m_flags |= wxPG_PROP_CUSTOMIMAGE;
2023
2024 prop->m_parent = this;
2025 }
2026
2027 void wxPGProperty::RemoveChild( wxPGProperty* p )
2028 {
2029 wxArrayPGProperty::iterator it;
2030 wxArrayPGProperty& children = m_children;
2031
2032 for ( it=children.begin(); it != children.end(); it++ )
2033 {
2034 if ( *it == p )
2035 {
2036 m_children.erase(it);
2037 break;
2038 }
2039 }
2040 }
2041
2042 void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
2043 {
2044 wxASSERT( GetChildCount() );
2045 wxASSERT( !IsCategory() );
2046
2047 *value = GetValue();
2048
2049 if ( !list.GetCount() )
2050 return;
2051
2052 wxASSERT( GetChildCount() >= (unsigned int)list.GetCount() );
2053
2054 bool allChildrenSpecified;
2055
2056 // Don't fully update aggregate properties unless all children have
2057 // specified value
2058 if ( HasFlag(wxPG_PROP_AGGREGATE) )
2059 allChildrenSpecified = AreAllChildrenSpecified(&list);
2060 else
2061 allChildrenSpecified = true;
2062
2063 wxVariant childValue = list[0];
2064 unsigned int i;
2065 unsigned int n = 0;
2066
2067 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2068
2069 for ( i=0; i<GetChildCount(); i++ )
2070 {
2071 const wxPGProperty* child = Item(i);
2072
2073 if ( childValue.GetName() == child->GetBaseName() )
2074 {
2075 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2076
2077 if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
2078 {
2079 wxVariant cv2(child->GetValue());
2080 child->AdaptListToValue(childValue, &cv2);
2081 childValue = cv2;
2082 }
2083
2084 if ( allChildrenSpecified )
2085 ChildChanged(*value, i, childValue);
2086 n++;
2087 if ( n == (unsigned int)list.GetCount() )
2088 break;
2089 childValue = list[n];
2090 }
2091 }
2092 }
2093
2094
2095 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere )
2096 {
2097 size_t i;
2098 for ( i=starthere;i<GetChildCount();i++)
2099 Item(i)->m_arrIndex = i;
2100 }
2101
2102
2103 // Returns (direct) child property with given name (or NULL if not found)
2104 wxPGProperty* wxPGProperty::GetPropertyByName( const wxString& name ) const
2105 {
2106 size_t i;
2107
2108 for ( i=0; i<GetChildCount(); i++ )
2109 {
2110 wxPGProperty* p = Item(i);
2111 if ( p->m_name == name )
2112 return p;
2113 }
2114
2115 // Does it have point, then?
2116 int pos = name.Find(wxS('.'));
2117 if ( pos <= 0 )
2118 return (wxPGProperty*) NULL;
2119
2120 wxPGProperty* p = GetPropertyByName(name. substr(0,pos));
2121
2122 if ( !p || !p->GetChildCount() )
2123 return NULL;
2124
2125 return p->GetPropertyByName(name.substr(pos+1,name.length()-pos-1));
2126 }
2127
2128 wxPGProperty* wxPGProperty::GetPropertyByNameWH( const wxString& name, unsigned int hintIndex ) const
2129 {
2130 unsigned int i = hintIndex;
2131
2132 if ( i >= GetChildCount() )
2133 i = 0;
2134
2135 unsigned int lastIndex = i - 1;
2136
2137 if ( lastIndex >= GetChildCount() )
2138 lastIndex = GetChildCount() - 1;
2139
2140 for (;;)
2141 {
2142 wxPGProperty* p = Item(i);
2143 if ( p->m_name == name )
2144 return p;
2145
2146 if ( i == lastIndex )
2147 break;
2148
2149 i++;
2150 if ( i == GetChildCount() )
2151 i = 0;
2152 };
2153
2154 return NULL;
2155 }
2156
2157 int wxPGProperty::GetChildrenHeight( int lh, int iMax_ ) const
2158 {
2159 // Returns height of children, recursively, and
2160 // by taking expanded/collapsed status into account.
2161 //
2162 // iMax is used when finding property y-positions.
2163 //
2164 unsigned int i = 0;
2165 int h = 0;
2166
2167 if ( iMax_ == -1 )
2168 iMax_ = GetChildCount();
2169
2170 unsigned int iMax = iMax_;
2171
2172 wxASSERT( iMax <= GetChildCount() );
2173
2174 if ( !IsExpanded() && GetParent() )
2175 return 0;
2176
2177 while ( i < iMax )
2178 {
2179 wxPGProperty* pwc = (wxPGProperty*) Item(i);
2180
2181 if ( !pwc->HasFlag(wxPG_PROP_HIDDEN) )
2182 {
2183 if ( !pwc->IsExpanded() ||
2184 pwc->GetChildCount() == 0 )
2185 h += lh;
2186 else
2187 h += pwc->GetChildrenHeight(lh) + lh;
2188 }
2189
2190 i++;
2191 }
2192
2193 return h;
2194 }
2195
2196 wxPGProperty* wxPGProperty::GetItemAtY( unsigned int y, unsigned int lh, unsigned int* nextItemY ) const
2197 {
2198 wxASSERT( nextItemY );
2199
2200 // Linear search at the moment
2201 //
2202 // nextItemY = y of next visible property, final value will be written back.
2203 wxPGProperty* result = NULL;
2204 wxPGProperty* current = NULL;
2205 unsigned int iy = *nextItemY;
2206 unsigned int i = 0;
2207 unsigned int iMax = GetChildCount();
2208
2209 while ( i < iMax )
2210 {
2211 wxPGProperty* pwc = Item(i);
2212
2213 if ( !pwc->HasFlag(wxPG_PROP_HIDDEN) )
2214 {
2215 // Found?
2216 if ( y < iy )
2217 {
2218 result = current;
2219 break;
2220 }
2221
2222 iy += lh;
2223
2224 if ( pwc->IsExpanded() &&
2225 pwc->GetChildCount() > 0 )
2226 {
2227 result = (wxPGProperty*) pwc->GetItemAtY( y, lh, &iy );
2228 if ( result )
2229 break;
2230 }
2231
2232 current = pwc;
2233 }
2234
2235 i++;
2236 }
2237
2238 // Found?
2239 if ( !result && y < iy )
2240 result = current;
2241
2242 *nextItemY = iy;
2243
2244 /*
2245 if ( current )
2246 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2247 else
2248 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2249 */
2250
2251 return (wxPGProperty*) result;
2252 }
2253
2254 void wxPGProperty::Empty()
2255 {
2256 size_t i;
2257 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES) )
2258 {
2259 for ( i=0; i<GetChildCount(); i++ )
2260 {
2261 delete m_children[i];
2262 }
2263 }
2264
2265 m_children.clear();
2266 }
2267
2268 void wxPGProperty::DeleteChildren()
2269 {
2270 wxPropertyGridPageState* state = m_parentState;
2271
2272 while ( GetChildCount() )
2273 {
2274 wxPGProperty* child = Item(GetChildCount()-1);
2275 state->DoDelete(child, true);
2276 }
2277 }
2278
2279 void wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue),
2280 int WXUNUSED(childIndex),
2281 wxVariant& WXUNUSED(childValue) ) const
2282 {
2283 }
2284
2285 bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
2286 {
2287 unsigned int i;
2288
2289 const wxVariantList* pList = NULL;
2290 wxVariantList::const_iterator node;
2291
2292 if ( pendingList )
2293 {
2294 pList = &pendingList->GetList();
2295 node = pList->begin();
2296 }
2297
2298 for ( i=0; i<GetChildCount(); i++ )
2299 {
2300 wxPGProperty* child = Item(i);
2301 const wxVariant* listValue = NULL;
2302 wxVariant value;
2303
2304 if ( pendingList )
2305 {
2306 const wxString& childName = child->GetBaseName();
2307
2308 for ( ; node != pList->end(); ++node )
2309 {
2310 const wxVariant& item = *((const wxVariant*)*node);
2311 if ( item.GetName() == childName )
2312 {
2313 listValue = &item;
2314 value = item;
2315 break;
2316 }
2317 }
2318 }
2319
2320 if ( !listValue )
2321 value = child->GetValue();
2322
2323 if ( value.IsNull() )
2324 return false;
2325
2326 // Check recursively
2327 if ( child->GetChildCount() )
2328 {
2329 const wxVariant* childList = NULL;
2330
2331 if ( listValue && listValue->GetType() == wxPG_VARIANT_TYPE_LIST )
2332 childList = listValue;
2333
2334 if ( !child->AreAllChildrenSpecified((wxVariant*)childList) )
2335 return false;
2336 }
2337 }
2338
2339 return true;
2340 }
2341
2342 wxPGProperty* wxPGProperty::UpdateParentValues()
2343 {
2344 wxPGProperty* parent = m_parent;
2345 if ( parent && parent->HasFlag(wxPG_PROP_COMPOSED_VALUE) &&
2346 !parent->IsCategory() && !parent->IsRoot() )
2347 {
2348 wxString s;
2349 parent->DoGenerateComposedValue(s);
2350 parent->m_value = s;
2351 return parent->UpdateParentValues();
2352 }
2353 return this;
2354 }
2355
2356 bool wxPGProperty::IsTextEditable() const
2357 {
2358 if ( HasFlag(wxPG_PROP_READONLY) )
2359 return false;
2360
2361 if ( HasFlag(wxPG_PROP_NOEDITOR) &&
2362 (GetChildCount() ||
2363 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2364 )
2365 return false;
2366
2367 return true;
2368 }
2369
2370 // Call after fixed sub-properties added/removed after creation.
2371 // if oldSelInd >= 0 and < new max items, then selection is
2372 // moved to it. Note: oldSelInd -2 indicates that this property
2373 // should be selected.
2374 void wxPGProperty::SubPropsChanged( int oldSelInd )
2375 {
2376 wxPropertyGridPageState* state = GetParentState();
2377 wxPropertyGrid* grid = state->GetGrid();
2378
2379 //
2380 // Re-repare children (recursively)
2381 for ( unsigned int i=0; i<GetChildCount(); i++ )
2382 {
2383 wxPGProperty* child = Item(i);
2384 child->InitAfterAdded(state, grid);
2385 }
2386
2387 wxPGProperty* sel = (wxPGProperty*) NULL;
2388 if ( oldSelInd >= (int)m_children.size() )
2389 oldSelInd = (int)m_children.size() - 1;
2390
2391 if ( oldSelInd >= 0 )
2392 sel = m_children[oldSelInd];
2393 else if ( oldSelInd == -2 )
2394 sel = this;
2395
2396 if ( sel )
2397 state->DoSelectProperty(sel);
2398
2399 if ( state == grid->GetState() )
2400 {
2401 grid->GetPanel()->Refresh();
2402 }
2403 }
2404
2405 // -----------------------------------------------------------------------
2406 // wxPGRootProperty
2407 // -----------------------------------------------------------------------
2408
2409 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty,none,TextCtrl)
2410 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty, wxPGProperty)
2411
2412
2413 wxPGRootProperty::wxPGRootProperty()
2414 : wxPGProperty()
2415 {
2416 #ifdef __WXDEBUG__
2417 m_name = wxS("<root>");
2418 #endif
2419 SetParentalType(0);
2420 m_depth = 0;
2421 }
2422
2423
2424 wxPGRootProperty::~wxPGRootProperty()
2425 {
2426 }
2427
2428
2429 // -----------------------------------------------------------------------
2430 // wxPropertyCategory
2431 // -----------------------------------------------------------------------
2432
2433 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory,none,TextCtrl)
2434 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory, wxPGProperty)
2435
2436 void wxPropertyCategory::Init()
2437 {
2438 // don't set colour - prepareadditem method should do this
2439 SetParentalType(wxPG_PROP_CATEGORY);
2440 m_capFgColIndex = 1;
2441 m_textExtent = -1;
2442 }
2443
2444 wxPropertyCategory::wxPropertyCategory()
2445 : wxPGProperty()
2446 {
2447 Init();
2448 }
2449
2450
2451 wxPropertyCategory::wxPropertyCategory( const wxString &label, const wxString& name )
2452 : wxPGProperty(label,name)
2453 {
2454 Init();
2455 }
2456
2457
2458 wxPropertyCategory::~wxPropertyCategory()
2459 {
2460 }
2461
2462
2463 wxString wxPropertyCategory::ValueToString( wxVariant& WXUNUSED(value),
2464 int WXUNUSED(argFlags) ) const
2465 {
2466 return wxEmptyString;
2467 }
2468
2469 int wxPropertyCategory::GetTextExtent( const wxWindow* wnd, const wxFont& font ) const
2470 {
2471 if ( m_textExtent > 0 )
2472 return m_textExtent;
2473 int x = 0, y = 0;
2474 ((wxWindow*)wnd)->GetTextExtent( m_label, &x, &y, 0, 0, &font );
2475 return x;
2476 }
2477
2478 void wxPropertyCategory::CalculateTextExtent( wxWindow* wnd, const wxFont& font )
2479 {
2480 int x = 0, y = 0;
2481 wnd->GetTextExtent( m_label, &x, &y, 0, 0, &font );
2482 m_textExtent = x;
2483 }
2484
2485 // -----------------------------------------------------------------------
2486 // wxPGAttributeStorage
2487 // -----------------------------------------------------------------------
2488
2489 wxPGAttributeStorage::wxPGAttributeStorage()
2490 {
2491 }
2492
2493 wxPGAttributeStorage::~wxPGAttributeStorage()
2494 {
2495 wxPGHashMapS2P::iterator it;
2496
2497 for ( it = m_map.begin(); it != m_map.end(); ++it )
2498 {
2499 wxVariantData* data = (wxVariantData*) it->second;
2500 data->DecRef();
2501 }
2502 }
2503
2504 void wxPGAttributeStorage::Set( const wxString& name, const wxVariant& value )
2505 {
2506 wxVariantData* data = value.GetData();
2507
2508 // Free old, if any
2509 wxPGHashMapS2P::iterator it = m_map.find(name);
2510 if ( it != m_map.end() )
2511 {
2512 ((wxVariantData*)it->second)->DecRef();
2513
2514 if ( !data )
2515 {
2516 // If Null variant, just remove from set
2517 m_map.erase(it);
2518 return;
2519 }
2520 }
2521
2522 if ( data )
2523 {
2524 data->IncRef();
2525
2526 m_map[name] = data;
2527 }
2528 }
2529
2530 #endif // wxUSE_PROPGRID