In wxPGProperty::StringToValue(), variant.SetName() really has to be called after...
[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 wxString childName = child->GetBaseName();
989
990 #ifdef __WXDEBUG__
991 if ( debug_print )
992 wxLogDebug(wxT("token = '%s', child = %s"),
993 token.c_str(), childName.c_str());
994 #endif
995
996 // Add only if editable or setting programmatically
997 if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) ||
998 !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) )
999 {
1000 if ( len > 0 )
1001 {
1002 if ( child->StringToValue(variant, token,
1003 propagatedFlags|wxPG_COMPOSITE_FRAGMENT) )
1004 {
1005 // We really need to set the variant's name
1006 // *after* child->StringToValue() has been
1007 // called, since variant's value may be set by
1008 // assigning another variant into it, which
1009 // then usually causes name to be copied (ie.
1010 // usually cleared) as well. wxBoolProperty
1011 // being case in point with its use of
1012 // wxPGVariant_Bool macro as an optimization.
1013 variant.SetName(childName);
1014 list.Append(variant);
1015
1016 changed = true;
1017 }
1018 }
1019 else
1020 {
1021 // Empty, becomes unspecified
1022 variant.MakeNull();
1023 variant.SetName(childName);
1024 list.Append(variant);
1025 changed = true;
1026 }
1027 }
1028
1029 curChild++;
1030 if ( curChild >= iMax )
1031 break;
1032 }
1033
1034 tokenStart = 0xFFFFFF;
1035 }
1036 }
1037 else
1038 {
1039 // Token is not running
1040 if ( a != wxS(' ') )
1041 {
1042
1043 addOnlyIfNotEmpty = false;
1044
1045 // Is this a group of tokens?
1046 if ( a == wxS('[') )
1047 {
1048 int depth = 1;
1049
1050 if ( it != text.end() ) ++it;
1051 pos++;
1052 size_t startPos = pos;
1053
1054 // Group item - find end
1055 while ( it != text.end() && depth > 0 )
1056 {
1057 a = *it;
1058 ++it;
1059 pos++;
1060
1061 if ( a == wxS(']') )
1062 depth--;
1063 else if ( a == wxS('[') )
1064 depth++;
1065 }
1066
1067 token = text.substr(startPos,pos-startPos-1);
1068
1069 if ( !token.length() )
1070 break;
1071
1072 const wxPGProperty* child = Item(curChild);
1073
1074 wxVariant oldChildValue = child->GetValue();
1075 wxVariant variant(oldChildValue);
1076
1077 if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) ||
1078 !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) )
1079 {
1080 bool stvRes = child->StringToValue( variant, token, propagatedFlags );
1081 if ( stvRes || (variant != oldChildValue) )
1082 {
1083 if ( stvRes )
1084 changed = true;
1085 }
1086 else
1087 {
1088 // Failed, becomes unspecified
1089 variant.MakeNull();
1090 changed = true;
1091 }
1092 }
1093
1094 variant.SetName(child->GetBaseName());
1095 list.Append(variant);
1096
1097 curChild++;
1098 if ( curChild >= iMax )
1099 break;
1100
1101 addOnlyIfNotEmpty = true;
1102
1103 tokenStart = 0xFFFFFF;
1104 }
1105 else
1106 {
1107 tokenStart = pos;
1108
1109 if ( a == delimeter )
1110 {
1111 pos--;
1112 --it;
1113 }
1114 }
1115 }
1116 }
1117
1118 if ( a == 0 )
1119 break;
1120
1121 ++it;
1122 if ( it != text.end() )
1123 {
1124 a = *it;
1125 }
1126 else
1127 {
1128 a = 0;
1129 }
1130 pos++;
1131 }
1132
1133 if ( changed )
1134 variant = list;
1135
1136 return changed;
1137 }
1138
1139 bool wxPGProperty::SetValueFromString( const wxString& text, int argFlags )
1140 {
1141 wxVariant variant(m_value);
1142 bool res = StringToValue(variant, text, argFlags);
1143 if ( res )
1144 SetValue(variant);
1145 return res;
1146 }
1147
1148 bool wxPGProperty::SetValueFromInt( long number, int argFlags )
1149 {
1150 wxVariant variant(m_value);
1151 bool res = IntToValue(variant, number, argFlags);
1152 if ( res )
1153 SetValue(variant);
1154 return res;
1155 }
1156
1157 wxSize wxPGProperty::OnMeasureImage( int WXUNUSED(item) ) const
1158 {
1159 if ( m_valueBitmap )
1160 return wxSize(m_valueBitmap->GetWidth(),-1);
1161
1162 return wxSize(0,0);
1163 }
1164
1165 wxPGCellRenderer* wxPGProperty::GetCellRenderer( int WXUNUSED(column) ) const
1166 {
1167 return wxPGGlobalVars->m_defaultRenderer;
1168 }
1169
1170 void wxPGProperty::OnCustomPaint( wxDC& dc,
1171 const wxRect& rect,
1172 wxPGPaintData& )
1173 {
1174 wxBitmap* bmp = m_valueBitmap;
1175
1176 wxCHECK_RET( bmp && bmp->Ok(), wxT("invalid bitmap") );
1177
1178 wxCHECK_RET( rect.x >= 0, wxT("unexpected measure call") );
1179
1180 dc.DrawBitmap(*bmp,rect.x,rect.y);
1181 }
1182
1183 const wxPGEditor* wxPGProperty::DoGetEditorClass() const
1184 {
1185 return wxPGEditor_TextCtrl;
1186 }
1187
1188 // Default extra property event handling - that is, none at all.
1189 bool wxPGProperty::OnEvent( wxPropertyGrid*, wxWindow*, wxEvent& )
1190 {
1191 return false;
1192 }
1193
1194
1195 void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
1196 {
1197 // If auto unspecified values are not wanted (via window or property style),
1198 // then get default value instead of wxNullVariant.
1199 if ( value.IsNull() && (flags & wxPG_SETVAL_BY_USER) &&
1200 !UsesAutoUnspecified() )
1201 {
1202 value = GetDefaultValue();
1203 }
1204
1205 if ( !value.IsNull() )
1206 {
1207 wxVariant tempListVariant;
1208
1209 SetCommonValue(-1);
1210 // List variants are reserved a special purpose
1211 // as intermediate containers for child values
1212 // of properties with children.
1213 if ( value.GetType() == wxPG_VARIANT_TYPE_LIST )
1214 {
1215 //
1216 // However, situation is different for composed string properties
1217 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE) )
1218 {
1219 tempListVariant = value;
1220 pList = &tempListVariant;
1221 }
1222
1223 wxVariant newValue;
1224 AdaptListToValue(value, &newValue);
1225 value = newValue;
1226 //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str());
1227 }
1228
1229 if ( HasFlag( wxPG_PROP_AGGREGATE) )
1230 flags |= wxPG_SETVAL_AGGREGATED;
1231
1232 if ( pList && !pList->IsNull() )
1233 {
1234 wxASSERT( pList->GetType() == wxPG_VARIANT_TYPE_LIST );
1235 wxASSERT( GetChildCount() );
1236 wxASSERT( !IsCategory() );
1237
1238 wxVariantList& list = pList->GetList();
1239 wxVariantList::iterator node;
1240 unsigned int i = 0;
1241
1242 //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
1243
1244 // Children in list can be in any order, but we will give hint to
1245 // GetPropertyByNameWH(). This optimizes for full list parsing.
1246 for ( node = list.begin(); node != list.end(); ++node )
1247 {
1248 wxVariant& childValue = *((wxVariant*)*node);
1249 wxPGProperty* child = GetPropertyByNameWH(childValue.GetName(), i);
1250 if ( child )
1251 {
1252 //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
1253 if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
1254 {
1255 if ( child->HasFlag(wxPG_PROP_AGGREGATE) && !(flags & wxPG_SETVAL_AGGREGATED) )
1256 {
1257 wxVariant listRefCopy = childValue;
1258 child->SetValue(childValue, &listRefCopy, flags|wxPG_SETVAL_FROM_PARENT);
1259 }
1260 else
1261 {
1262 wxVariant oldVal = child->GetValue();
1263 child->SetValue(oldVal, &childValue, flags|wxPG_SETVAL_FROM_PARENT);
1264 }
1265 }
1266 else if ( child->GetValue() != childValue )
1267 {
1268 // For aggregate properties, we will trust RefreshChildren()
1269 // to update child values.
1270 if ( !HasFlag(wxPG_PROP_AGGREGATE) )
1271 child->SetValue(childValue, NULL, flags|wxPG_SETVAL_FROM_PARENT);
1272 if ( flags & wxPG_SETVAL_BY_USER )
1273 child->SetFlag(wxPG_PROP_MODIFIED);
1274 }
1275 }
1276 i++;
1277 }
1278 }
1279
1280 if ( !value.IsNull() )
1281 {
1282 m_value = value;
1283 OnSetValue();
1284
1285 if ( !(flags & wxPG_SETVAL_FROM_PARENT) )
1286 UpdateParentValues();
1287 }
1288
1289 if ( flags & wxPG_SETVAL_BY_USER )
1290 SetFlag(wxPG_PROP_MODIFIED);
1291
1292 if ( HasFlag(wxPG_PROP_AGGREGATE) )
1293 RefreshChildren();
1294 }
1295 else
1296 {
1297 if ( m_commonValue != -1 )
1298 {
1299 wxPropertyGrid* pg = GetGrid();
1300 if ( !pg || m_commonValue != pg->GetUnspecifiedCommonValue() )
1301 SetCommonValue(-1);
1302 }
1303
1304 m_value = value;
1305
1306 // Set children to unspecified, but only if aggregate or
1307 // value is <composed>
1308 if ( AreChildrenComponents() )
1309 {
1310 unsigned int i;
1311 for ( i=0; i<GetChildCount(); i++ )
1312 Item(i)->SetValue(value, NULL, flags|wxPG_SETVAL_FROM_PARENT);
1313 }
1314 }
1315
1316 //
1317 // Update editor control
1318 //
1319
1320 // We need to check for these, otherwise GetGrid() may fail.
1321 if ( flags & wxPG_SETVAL_REFRESH_EDITOR )
1322 RefreshEditor();
1323 }
1324
1325
1326 void wxPGProperty::SetValueInEvent( wxVariant value ) const
1327 {
1328 GetGrid()->ValueChangeInEvent(value);
1329 }
1330
1331 void wxPGProperty::SetFlagRecursively( FlagType flag, bool set )
1332 {
1333 if ( set )
1334 SetFlag(flag);
1335 else
1336 ClearFlag(flag);
1337
1338 unsigned int i;
1339 for ( i = 0; i < GetChildCount(); i++ )
1340 Item(i)->SetFlagRecursively(flag, set);
1341 }
1342
1343 void wxPGProperty::RefreshEditor()
1344 {
1345 if ( !m_parent )
1346 return;
1347
1348 wxPropertyGrid* pg = GetGrid();
1349 if ( pg && pg->GetSelectedProperty() == this )
1350 pg->RefreshEditor();
1351 }
1352
1353 wxVariant wxPGProperty::GetDefaultValue() const
1354 {
1355 wxVariant defVal = GetAttribute(wxS("DefaultValue"));
1356 if ( !defVal.IsNull() )
1357 return defVal;
1358
1359 wxVariant value = GetValue();
1360
1361 if ( !value.IsNull() )
1362 {
1363 wxString valueType(value.GetType());
1364
1365 if ( valueType == wxPG_VARIANT_TYPE_LONG )
1366 return wxPGVariant_Zero;
1367 if ( valueType == wxPG_VARIANT_TYPE_STRING )
1368 return wxPGVariant_EmptyString;
1369 if ( valueType == wxPG_VARIANT_TYPE_BOOL )
1370 return wxPGVariant_False;
1371 if ( valueType == wxPG_VARIANT_TYPE_DOUBLE )
1372 return wxVariant(0.0);
1373 if ( valueType == wxPG_VARIANT_TYPE_ARRSTRING )
1374 return wxVariant(wxArrayString());
1375 if ( valueType == wxS("wxLongLong") )
1376 return WXVARIANT(wxLongLong(0));
1377 if ( valueType == wxS("wxULongLong") )
1378 return WXVARIANT(wxULongLong(0));
1379 if ( valueType == wxS("wxColour") )
1380 return WXVARIANT(*wxBLACK);
1381 #if wxUSE_DATETIME
1382 if ( valueType == wxPG_VARIANT_TYPE_DATETIME )
1383 return wxVariant(wxDateTime::Now());
1384 #endif
1385 if ( valueType == wxS("wxFont") )
1386 return WXVARIANT(*wxNORMAL_FONT);
1387 if ( valueType == wxS("wxPoint") )
1388 return WXVARIANT(wxPoint(0, 0));
1389 if ( valueType == wxS("wxSize") )
1390 return WXVARIANT(wxSize(0, 0));
1391 }
1392
1393 return wxVariant();
1394 }
1395
1396 void wxPGProperty::EnsureCells( unsigned int column )
1397 {
1398 if ( column >= m_cells.size() )
1399 {
1400 // Fill empty slots with default cells
1401 wxPropertyGrid* pg = GetGrid();
1402 wxPGCell defaultCell;
1403
1404 if ( !HasFlag(wxPG_PROP_CATEGORY) )
1405 defaultCell = pg->GetPropertyDefaultCell();
1406 else
1407 defaultCell = pg->GetCategoryDefaultCell();
1408
1409 // TODO: Replace with resize() call
1410 unsigned int cellCountMax = column+1;
1411
1412 for ( unsigned int i=m_cells.size(); i<cellCountMax; i++ )
1413 m_cells.push_back(defaultCell);
1414 }
1415 }
1416
1417 void wxPGProperty::SetCell( int column,
1418 const wxPGCell& cell )
1419 {
1420 EnsureCells(column);
1421
1422 m_cells[column] = cell;
1423 }
1424
1425 void wxPGProperty::AdaptiveSetCell( unsigned int firstCol,
1426 unsigned int lastCol,
1427 const wxPGCell& cell,
1428 const wxPGCell& srcData,
1429 wxPGCellData* unmodCellData,
1430 FlagType ignoreWithFlags,
1431 bool recursively )
1432 {
1433 //
1434 // Sets cell in memory optimizing fashion. That is, if
1435 // current cell data matches unmodCellData, we will
1436 // simply get reference to data from cell. Otherwise,
1437 // cell information from srcData is merged into current.
1438 //
1439
1440 if ( !(m_flags & ignoreWithFlags) && !IsRoot() )
1441 {
1442 EnsureCells(lastCol);
1443
1444 for ( unsigned int col=firstCol; col<=lastCol; col++ )
1445 {
1446 if ( m_cells[col].GetData() == unmodCellData )
1447 {
1448 // Data matches... use cell directly
1449 m_cells[col] = cell;
1450 }
1451 else
1452 {
1453 // Data did not match... merge valid information
1454 m_cells[col].MergeFrom(srcData);
1455 }
1456 }
1457 }
1458
1459 if ( recursively )
1460 {
1461 for ( unsigned int i=0; i<GetChildCount(); i++ )
1462 Item(i)->AdaptiveSetCell( firstCol,
1463 lastCol,
1464 cell,
1465 srcData,
1466 unmodCellData,
1467 ignoreWithFlags,
1468 recursively );
1469 }
1470 }
1471
1472 const wxPGCell& wxPGProperty::GetCell( unsigned int column ) const
1473 {
1474 if ( m_cells.size() > column )
1475 return m_cells[column];
1476
1477 wxPropertyGrid* pg = GetGrid();
1478
1479 if ( IsCategory() )
1480 return pg->GetCategoryDefaultCell();
1481
1482 return pg->GetPropertyDefaultCell();
1483 }
1484
1485 wxPGCell& wxPGProperty::GetCell( unsigned int column )
1486 {
1487 EnsureCells(column);
1488 return m_cells[column];
1489 }
1490
1491 void wxPGProperty::SetBackgroundColour( const wxColour& colour,
1492 bool recursively )
1493 {
1494 wxPGProperty* firstProp = this;
1495
1496 //
1497 // If category is tried to set recursively, skip it and only
1498 // affect the children.
1499 if ( recursively )
1500 {
1501 while ( firstProp->IsCategory() )
1502 {
1503 if ( !firstProp->GetChildCount() )
1504 return;
1505 firstProp = firstProp->Item(0);
1506 }
1507 }
1508
1509 wxPGCell& firstCell = firstProp->GetCell(0);
1510 wxPGCellData* firstCellData = firstCell.GetData();
1511
1512 wxPGCell newCell(firstCell);
1513 newCell.SetBgCol(colour);
1514 wxPGCell srcCell;
1515 srcCell.SetBgCol(colour);
1516
1517 AdaptiveSetCell( 0,
1518 GetParentState()->GetColumnCount()-1,
1519 newCell,
1520 srcCell,
1521 firstCellData,
1522 recursively ? wxPG_PROP_CATEGORY : 0,
1523 recursively );
1524 }
1525
1526 void wxPGProperty::SetTextColour( const wxColour& colour,
1527 bool recursively )
1528 {
1529 wxPGProperty* firstProp = this;
1530
1531 //
1532 // If category is tried to set recursively, skip it and only
1533 // affect the children.
1534 if ( recursively )
1535 {
1536 while ( firstProp->IsCategory() )
1537 {
1538 if ( !firstProp->GetChildCount() )
1539 return;
1540 firstProp = firstProp->Item(0);
1541 }
1542 }
1543
1544 wxPGCell& firstCell = firstProp->GetCell(0);
1545 wxPGCellData* firstCellData = firstCell.GetData();
1546
1547 wxPGCell newCell(firstCell);
1548 newCell.SetFgCol(colour);
1549 wxPGCell srcCell;
1550 srcCell.SetFgCol(colour);
1551
1552 AdaptiveSetCell( 0,
1553 GetParentState()->GetColumnCount()-1,
1554 newCell,
1555 srcCell,
1556 firstCellData,
1557 recursively ? wxPG_PROP_CATEGORY : 0,
1558 recursively );
1559 }
1560
1561 wxPGEditorDialogAdapter* wxPGProperty::GetEditorDialog() const
1562 {
1563 return NULL;
1564 }
1565
1566 bool wxPGProperty::DoSetAttribute( const wxString& WXUNUSED(name), wxVariant& WXUNUSED(value) )
1567 {
1568 return false;
1569 }
1570
1571 void wxPGProperty::SetAttribute( const wxString& name, wxVariant value )
1572 {
1573 if ( DoSetAttribute( name, value ) )
1574 {
1575 // Support working without grid, when possible
1576 if ( wxPGGlobalVars->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES ) )
1577 return;
1578 }
1579
1580 m_attributes.Set( name, value );
1581 }
1582
1583 void wxPGProperty::SetAttributes( const wxPGAttributeStorage& attributes )
1584 {
1585 wxPGAttributeStorage::const_iterator it = attributes.StartIteration();
1586 wxVariant variant;
1587
1588 while ( attributes.GetNext(it, variant) )
1589 SetAttribute( variant.GetName(), variant );
1590 }
1591
1592 wxVariant wxPGProperty::DoGetAttribute( const wxString& WXUNUSED(name) ) const
1593 {
1594 return wxVariant();
1595 }
1596
1597
1598 wxVariant wxPGProperty::GetAttribute( const wxString& name ) const
1599 {
1600 return m_attributes.FindValue(name);
1601 }
1602
1603 wxString wxPGProperty::GetAttribute( const wxString& name, const wxString& defVal ) const
1604 {
1605 wxVariant variant = m_attributes.FindValue(name);
1606
1607 if ( !variant.IsNull() )
1608 return variant.GetString();
1609
1610 return defVal;
1611 }
1612
1613 long wxPGProperty::GetAttributeAsLong( const wxString& name, long defVal ) const
1614 {
1615 wxVariant variant = m_attributes.FindValue(name);
1616
1617 return wxPGVariantToInt(variant, defVal);
1618 }
1619
1620 double wxPGProperty::GetAttributeAsDouble( const wxString& name, double defVal ) const
1621 {
1622 double retVal;
1623 wxVariant variant = m_attributes.FindValue(name);
1624
1625 if ( wxPGVariantToDouble(variant, &retVal) )
1626 return retVal;
1627
1628 return defVal;
1629 }
1630
1631 wxVariant wxPGProperty::GetAttributesAsList() const
1632 {
1633 wxVariantList tempList;
1634 wxVariant v( tempList, wxString::Format(wxS("@%s@attr"),m_name.c_str()) );
1635
1636 wxPGAttributeStorage::const_iterator it = m_attributes.StartIteration();
1637 wxVariant variant;
1638
1639 while ( m_attributes.GetNext(it, variant) )
1640 v.Append(variant);
1641
1642 return v;
1643 }
1644
1645 // Slots of utility flags are NULL
1646 const unsigned int gs_propFlagToStringSize = 14;
1647
1648 static const wxChar* gs_propFlagToString[gs_propFlagToStringSize] = {
1649 NULL,
1650 wxT("DISABLED"),
1651 wxT("HIDDEN"),
1652 NULL,
1653 wxT("NOEDITOR"),
1654 wxT("COLLAPSED"),
1655 NULL,
1656 NULL,
1657 NULL,
1658 NULL,
1659 NULL,
1660 NULL,
1661 NULL,
1662 NULL
1663 };
1664
1665 wxString wxPGProperty::GetFlagsAsString( FlagType flagsMask ) const
1666 {
1667 wxString s;
1668 int relevantFlags = m_flags & flagsMask & wxPG_STRING_STORED_FLAGS;
1669 FlagType a = 1;
1670
1671 unsigned int i = 0;
1672 for ( i=0; i<gs_propFlagToStringSize; i++ )
1673 {
1674 if ( relevantFlags & a )
1675 {
1676 const wxChar* fs = gs_propFlagToString[i];
1677 wxASSERT(fs);
1678 if ( s.length() )
1679 s << wxS("|");
1680 s << fs;
1681 }
1682 a = a << 1;
1683 }
1684
1685 return s;
1686 }
1687
1688 void wxPGProperty::SetFlagsFromString( const wxString& str )
1689 {
1690 FlagType flags = 0;
1691
1692 WX_PG_TOKENIZER1_BEGIN(str, wxS('|'))
1693 unsigned int i;
1694 for ( i=0; i<gs_propFlagToStringSize; i++ )
1695 {
1696 const wxChar* fs = gs_propFlagToString[i];
1697 if ( fs && str == fs )
1698 {
1699 flags |= (1<<i);
1700 break;
1701 }
1702 }
1703 WX_PG_TOKENIZER1_END()
1704
1705 m_flags = (m_flags & ~wxPG_STRING_STORED_FLAGS) | flags;
1706 }
1707
1708 wxValidator* wxPGProperty::DoGetValidator() const
1709 {
1710 return (wxValidator*) NULL;
1711 }
1712
1713 int wxPGProperty::InsertChoice( const wxString& label, int index, int value )
1714 {
1715 wxPropertyGrid* pg = GetGrid();
1716 int sel = GetChoiceSelection();
1717
1718 int newSel = sel;
1719
1720 if ( index == wxNOT_FOUND )
1721 index = m_choices.GetCount();
1722
1723 if ( index <= sel )
1724 newSel++;
1725
1726 m_choices.Insert(label, index, value);
1727
1728 if ( sel != newSel )
1729 SetChoiceSelection(newSel);
1730
1731 if ( this == pg->GetSelection() )
1732 GetEditorClass()->InsertItem(pg->GetEditorControl(),label,index);
1733
1734 return index;
1735 }
1736
1737
1738 void wxPGProperty::DeleteChoice( int index )
1739 {
1740 wxPropertyGrid* pg = GetGrid();
1741
1742 int sel = GetChoiceSelection();
1743 int newSel = sel;
1744
1745 // Adjust current value
1746 if ( sel == index )
1747 {
1748 SetValueToUnspecified();
1749 newSel = 0;
1750 }
1751 else if ( index < sel )
1752 {
1753 newSel--;
1754 }
1755
1756 m_choices.RemoveAt(index);
1757
1758 if ( sel != newSel )
1759 SetChoiceSelection(newSel);
1760
1761 if ( this == pg->GetSelection() )
1762 GetEditorClass()->DeleteItem(pg->GetEditorControl(), index);
1763 }
1764
1765 int wxPGProperty::GetChoiceSelection() const
1766 {
1767 wxVariant value = GetValue();
1768 wxString valueType = value.GetType();
1769 int index = wxNOT_FOUND;
1770
1771 if ( IsValueUnspecified() || !m_choices.GetCount() )
1772 return wxNOT_FOUND;
1773
1774 if ( valueType == wxPG_VARIANT_TYPE_LONG )
1775 {
1776 index = value.GetLong();
1777 }
1778 else if ( valueType == wxPG_VARIANT_TYPE_STRING )
1779 {
1780 index = m_choices.Index(value.GetString());
1781 }
1782 else if ( valueType == wxPG_VARIANT_TYPE_BOOL )
1783 {
1784 index = value.GetBool()? 1 : 0;
1785 }
1786
1787 return index;
1788 }
1789
1790 void wxPGProperty::SetChoiceSelection( int newValue )
1791 {
1792 // Changes value of a property with choices, but only
1793 // works if the value type is long or string.
1794 wxString valueType = GetValue().GetType();
1795
1796 wxCHECK_RET( m_choices.IsOk(), wxT("invalid choiceinfo") );
1797
1798 if ( valueType == wxPG_VARIANT_TYPE_STRING )
1799 {
1800 SetValue( m_choices.GetLabel(newValue) );
1801 }
1802 else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
1803 {
1804 SetValue( (long) newValue );
1805 }
1806 }
1807
1808 bool wxPGProperty::SetChoices( wxPGChoices& choices )
1809 {
1810 m_choices.Assign(choices);
1811
1812 {
1813 // This may be needed to trigger some initialization
1814 // (but don't do it if property is somewhat uninitialized)
1815 wxVariant defVal = GetDefaultValue();
1816 if ( defVal.IsNull() )
1817 return false;
1818
1819 SetValue(defVal);
1820 }
1821
1822 return true;
1823 }
1824
1825
1826 const wxPGEditor* wxPGProperty::GetEditorClass() const
1827 {
1828 const wxPGEditor* editor;
1829
1830 if ( !m_customEditor )
1831 {
1832 editor = DoGetEditorClass();
1833 }
1834 else
1835 editor = m_customEditor;
1836
1837 //
1838 // Maybe override editor if common value specified
1839 if ( GetDisplayedCommonValueCount() )
1840 {
1841 // TextCtrlAndButton -> ComboBoxAndButton
1842 if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor)) )
1843 editor = wxPGEditor_ChoiceAndButton;
1844
1845 // TextCtrl -> ComboBox
1846 else if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlEditor)) )
1847 editor = wxPGEditor_ComboBox;
1848 }
1849
1850 return editor;
1851 }
1852
1853 bool wxPGProperty::HasVisibleChildren() const
1854 {
1855 unsigned int i;
1856
1857 for ( i=0; i<GetChildCount(); i++ )
1858 {
1859 wxPGProperty* child = Item(i);
1860
1861 if ( !child->HasFlag(wxPG_PROP_HIDDEN) )
1862 return true;
1863 }
1864
1865 return false;
1866 }
1867
1868 bool wxPGProperty::RecreateEditor()
1869 {
1870 wxPropertyGrid* pg = GetGrid();
1871 wxASSERT(pg);
1872
1873 wxPGProperty* selected = pg->GetSelection();
1874 if ( this == selected )
1875 {
1876 pg->DoSelectProperty(this, wxPG_SEL_FORCE);
1877 return true;
1878 }
1879 return false;
1880 }
1881
1882
1883 void wxPGProperty::SetValueImage( wxBitmap& bmp )
1884 {
1885 delete m_valueBitmap;
1886
1887 if ( &bmp && bmp.Ok() )
1888 {
1889 // Resize the image
1890 wxSize maxSz = GetGrid()->GetImageSize();
1891 wxSize imSz(bmp.GetWidth(),bmp.GetHeight());
1892
1893 if ( imSz.x != maxSz.x || imSz.y != maxSz.y )
1894 {
1895 // Create a memory DC
1896 wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth());
1897
1898 wxMemoryDC dc;
1899 dc.SelectObject(*bmpNew);
1900
1901 // Scale
1902 // FIXME: This is ugly - use image or wait for scaling patch.
1903 double scaleX = (double)maxSz.x / (double)imSz.x;
1904 double scaleY = (double)maxSz.y / (double)imSz.y;
1905
1906 dc.SetUserScale(scaleX,scaleY);
1907
1908 dc.DrawBitmap( bmp, 0, 0 );
1909
1910 m_valueBitmap = bmpNew;
1911 }
1912 else
1913 {
1914 m_valueBitmap = new wxBitmap(bmp);
1915 }
1916
1917 m_flags |= wxPG_PROP_CUSTOMIMAGE;
1918 }
1919 else
1920 {
1921 m_valueBitmap = NULL;
1922 m_flags &= ~(wxPG_PROP_CUSTOMIMAGE);
1923 }
1924 }
1925
1926
1927 wxPGProperty* wxPGProperty::GetMainParent() const
1928 {
1929 const wxPGProperty* curChild = this;
1930 const wxPGProperty* curParent = m_parent;
1931
1932 while ( curParent && !curParent->IsCategory() )
1933 {
1934 curChild = curParent;
1935 curParent = curParent->m_parent;
1936 }
1937
1938 return (wxPGProperty*) curChild;
1939 }
1940
1941
1942 const wxPGProperty* wxPGProperty::GetLastVisibleSubItem() const
1943 {
1944 //
1945 // Returns last visible sub-item, recursively.
1946 if ( !IsExpanded() || !GetChildCount() )
1947 return this;
1948
1949 return Last()->GetLastVisibleSubItem();
1950 }
1951
1952
1953 bool wxPGProperty::IsVisible() const
1954 {
1955 const wxPGProperty* parent;
1956
1957 if ( HasFlag(wxPG_PROP_HIDDEN) )
1958 return false;
1959
1960 for ( parent = GetParent(); parent != NULL; parent = parent->GetParent() )
1961 {
1962 if ( !parent->IsExpanded() || parent->HasFlag(wxPG_PROP_HIDDEN) )
1963 return false;
1964 }
1965
1966 return true;
1967 }
1968
1969 wxPropertyGrid* wxPGProperty::GetGridIfDisplayed() const
1970 {
1971 wxPropertyGridPageState* state = GetParentState();
1972 wxPropertyGrid* propGrid = state->GetGrid();
1973 if ( state == propGrid->GetState() )
1974 return propGrid;
1975 return NULL;
1976 }
1977
1978
1979 int wxPGProperty::GetY2( int lh ) const
1980 {
1981 const wxPGProperty* parent;
1982 const wxPGProperty* child = this;
1983
1984 int y = 0;
1985
1986 for ( parent = GetParent(); parent != NULL; parent = child->GetParent() )
1987 {
1988 if ( !parent->IsExpanded() )
1989 return -1;
1990 y += parent->GetChildrenHeight(lh, child->GetIndexInParent());
1991 y += lh;
1992 child = parent;
1993 }
1994
1995 y -= lh; // need to reduce one level
1996
1997 return y;
1998 }
1999
2000
2001 int wxPGProperty::GetY() const
2002 {
2003 return GetY2(GetGrid()->GetRowHeight());
2004 }
2005
2006 // This is used by Insert etc.
2007 void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
2008 {
2009 if ( index < 0 || (size_t)index >= m_children.size() )
2010 {
2011 if ( correct_mode ) prop->m_arrIndex = m_children.size();
2012 m_children.push_back( prop );
2013 }
2014 else
2015 {
2016 m_children.insert( m_children.begin()+index, prop);
2017 if ( correct_mode ) FixIndicesOfChildren( index );
2018 }
2019
2020 prop->m_parent = this;
2021 }
2022
2023 // This is used by properties that have fixed sub-properties
2024 void wxPGProperty::AddChild( wxPGProperty* prop )
2025 {
2026 wxASSERT_MSG( prop->GetBaseName().length(),
2027 "Property's children must have unique, non-empty names within their scope" );
2028
2029 prop->m_arrIndex = m_children.size();
2030 m_children.push_back( prop );
2031
2032 int custImgHeight = prop->OnMeasureImage().y;
2033 if ( custImgHeight < 0 /*|| custImgHeight > 1*/ )
2034 prop->m_flags |= wxPG_PROP_CUSTOMIMAGE;
2035
2036 prop->m_parent = this;
2037 }
2038
2039 void wxPGProperty::RemoveChild( wxPGProperty* p )
2040 {
2041 wxArrayPGProperty::iterator it;
2042 wxArrayPGProperty& children = m_children;
2043
2044 for ( it=children.begin(); it != children.end(); it++ )
2045 {
2046 if ( *it == p )
2047 {
2048 m_children.erase(it);
2049 break;
2050 }
2051 }
2052 }
2053
2054 void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
2055 {
2056 wxASSERT( GetChildCount() );
2057 wxASSERT( !IsCategory() );
2058
2059 *value = GetValue();
2060
2061 if ( !list.GetCount() )
2062 return;
2063
2064 wxASSERT( GetChildCount() >= (unsigned int)list.GetCount() );
2065
2066 bool allChildrenSpecified;
2067
2068 // Don't fully update aggregate properties unless all children have
2069 // specified value
2070 if ( HasFlag(wxPG_PROP_AGGREGATE) )
2071 allChildrenSpecified = AreAllChildrenSpecified(&list);
2072 else
2073 allChildrenSpecified = true;
2074
2075 wxVariant childValue = list[0];
2076 unsigned int i;
2077 unsigned int n = 0;
2078
2079 //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
2080
2081 for ( i=0; i<GetChildCount(); i++ )
2082 {
2083 const wxPGProperty* child = Item(i);
2084
2085 if ( childValue.GetName() == child->GetBaseName() )
2086 {
2087 //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
2088
2089 if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
2090 {
2091 wxVariant cv2(child->GetValue());
2092 child->AdaptListToValue(childValue, &cv2);
2093 childValue = cv2;
2094 }
2095
2096 if ( allChildrenSpecified )
2097 ChildChanged(*value, i, childValue);
2098 n++;
2099 if ( n == (unsigned int)list.GetCount() )
2100 break;
2101 childValue = list[n];
2102 }
2103 }
2104 }
2105
2106
2107 void wxPGProperty::FixIndicesOfChildren( unsigned int starthere )
2108 {
2109 size_t i;
2110 for ( i=starthere;i<GetChildCount();i++)
2111 Item(i)->m_arrIndex = i;
2112 }
2113
2114
2115 // Returns (direct) child property with given name (or NULL if not found)
2116 wxPGProperty* wxPGProperty::GetPropertyByName( const wxString& name ) const
2117 {
2118 size_t i;
2119
2120 for ( i=0; i<GetChildCount(); i++ )
2121 {
2122 wxPGProperty* p = Item(i);
2123 if ( p->m_name == name )
2124 return p;
2125 }
2126
2127 // Does it have point, then?
2128 int pos = name.Find(wxS('.'));
2129 if ( pos <= 0 )
2130 return (wxPGProperty*) NULL;
2131
2132 wxPGProperty* p = GetPropertyByName(name. substr(0,pos));
2133
2134 if ( !p || !p->GetChildCount() )
2135 return NULL;
2136
2137 return p->GetPropertyByName(name.substr(pos+1,name.length()-pos-1));
2138 }
2139
2140 wxPGProperty* wxPGProperty::GetPropertyByNameWH( const wxString& name, unsigned int hintIndex ) const
2141 {
2142 unsigned int i = hintIndex;
2143
2144 if ( i >= GetChildCount() )
2145 i = 0;
2146
2147 unsigned int lastIndex = i - 1;
2148
2149 if ( lastIndex >= GetChildCount() )
2150 lastIndex = GetChildCount() - 1;
2151
2152 for (;;)
2153 {
2154 wxPGProperty* p = Item(i);
2155 if ( p->m_name == name )
2156 return p;
2157
2158 if ( i == lastIndex )
2159 break;
2160
2161 i++;
2162 if ( i == GetChildCount() )
2163 i = 0;
2164 };
2165
2166 return NULL;
2167 }
2168
2169 int wxPGProperty::GetChildrenHeight( int lh, int iMax_ ) const
2170 {
2171 // Returns height of children, recursively, and
2172 // by taking expanded/collapsed status into account.
2173 //
2174 // iMax is used when finding property y-positions.
2175 //
2176 unsigned int i = 0;
2177 int h = 0;
2178
2179 if ( iMax_ == -1 )
2180 iMax_ = GetChildCount();
2181
2182 unsigned int iMax = iMax_;
2183
2184 wxASSERT( iMax <= GetChildCount() );
2185
2186 if ( !IsExpanded() && GetParent() )
2187 return 0;
2188
2189 while ( i < iMax )
2190 {
2191 wxPGProperty* pwc = (wxPGProperty*) Item(i);
2192
2193 if ( !pwc->HasFlag(wxPG_PROP_HIDDEN) )
2194 {
2195 if ( !pwc->IsExpanded() ||
2196 pwc->GetChildCount() == 0 )
2197 h += lh;
2198 else
2199 h += pwc->GetChildrenHeight(lh) + lh;
2200 }
2201
2202 i++;
2203 }
2204
2205 return h;
2206 }
2207
2208 wxPGProperty* wxPGProperty::GetItemAtY( unsigned int y, unsigned int lh, unsigned int* nextItemY ) const
2209 {
2210 wxASSERT( nextItemY );
2211
2212 // Linear search at the moment
2213 //
2214 // nextItemY = y of next visible property, final value will be written back.
2215 wxPGProperty* result = NULL;
2216 wxPGProperty* current = NULL;
2217 unsigned int iy = *nextItemY;
2218 unsigned int i = 0;
2219 unsigned int iMax = GetChildCount();
2220
2221 while ( i < iMax )
2222 {
2223 wxPGProperty* pwc = Item(i);
2224
2225 if ( !pwc->HasFlag(wxPG_PROP_HIDDEN) )
2226 {
2227 // Found?
2228 if ( y < iy )
2229 {
2230 result = current;
2231 break;
2232 }
2233
2234 iy += lh;
2235
2236 if ( pwc->IsExpanded() &&
2237 pwc->GetChildCount() > 0 )
2238 {
2239 result = (wxPGProperty*) pwc->GetItemAtY( y, lh, &iy );
2240 if ( result )
2241 break;
2242 }
2243
2244 current = pwc;
2245 }
2246
2247 i++;
2248 }
2249
2250 // Found?
2251 if ( !result && y < iy )
2252 result = current;
2253
2254 *nextItemY = iy;
2255
2256 /*
2257 if ( current )
2258 wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str());
2259 else
2260 wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y);
2261 */
2262
2263 return (wxPGProperty*) result;
2264 }
2265
2266 void wxPGProperty::Empty()
2267 {
2268 size_t i;
2269 if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES) )
2270 {
2271 for ( i=0; i<GetChildCount(); i++ )
2272 {
2273 delete m_children[i];
2274 }
2275 }
2276
2277 m_children.clear();
2278 }
2279
2280 void wxPGProperty::DeleteChildren()
2281 {
2282 wxPropertyGridPageState* state = m_parentState;
2283
2284 while ( GetChildCount() )
2285 {
2286 wxPGProperty* child = Item(GetChildCount()-1);
2287 state->DoDelete(child, true);
2288 }
2289 }
2290
2291 void wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue),
2292 int WXUNUSED(childIndex),
2293 wxVariant& WXUNUSED(childValue) ) const
2294 {
2295 }
2296
2297 bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
2298 {
2299 unsigned int i;
2300
2301 const wxVariantList* pList = NULL;
2302 wxVariantList::const_iterator node;
2303
2304 if ( pendingList )
2305 {
2306 pList = &pendingList->GetList();
2307 node = pList->begin();
2308 }
2309
2310 for ( i=0; i<GetChildCount(); i++ )
2311 {
2312 wxPGProperty* child = Item(i);
2313 const wxVariant* listValue = NULL;
2314 wxVariant value;
2315
2316 if ( pendingList )
2317 {
2318 const wxString& childName = child->GetBaseName();
2319
2320 for ( ; node != pList->end(); ++node )
2321 {
2322 const wxVariant& item = *((const wxVariant*)*node);
2323 if ( item.GetName() == childName )
2324 {
2325 listValue = &item;
2326 value = item;
2327 break;
2328 }
2329 }
2330 }
2331
2332 if ( !listValue )
2333 value = child->GetValue();
2334
2335 if ( value.IsNull() )
2336 return false;
2337
2338 // Check recursively
2339 if ( child->GetChildCount() )
2340 {
2341 const wxVariant* childList = NULL;
2342
2343 if ( listValue && listValue->GetType() == wxPG_VARIANT_TYPE_LIST )
2344 childList = listValue;
2345
2346 if ( !child->AreAllChildrenSpecified((wxVariant*)childList) )
2347 return false;
2348 }
2349 }
2350
2351 return true;
2352 }
2353
2354 wxPGProperty* wxPGProperty::UpdateParentValues()
2355 {
2356 wxPGProperty* parent = m_parent;
2357 if ( parent && parent->HasFlag(wxPG_PROP_COMPOSED_VALUE) &&
2358 !parent->IsCategory() && !parent->IsRoot() )
2359 {
2360 wxString s;
2361 parent->DoGenerateComposedValue(s);
2362 parent->m_value = s;
2363 return parent->UpdateParentValues();
2364 }
2365 return this;
2366 }
2367
2368 bool wxPGProperty::IsTextEditable() const
2369 {
2370 if ( HasFlag(wxPG_PROP_READONLY) )
2371 return false;
2372
2373 if ( HasFlag(wxPG_PROP_NOEDITOR) &&
2374 (GetChildCount() ||
2375 wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button")))
2376 )
2377 return false;
2378
2379 return true;
2380 }
2381
2382 // Call after fixed sub-properties added/removed after creation.
2383 // if oldSelInd >= 0 and < new max items, then selection is
2384 // moved to it. Note: oldSelInd -2 indicates that this property
2385 // should be selected.
2386 void wxPGProperty::SubPropsChanged( int oldSelInd )
2387 {
2388 wxPropertyGridPageState* state = GetParentState();
2389 wxPropertyGrid* grid = state->GetGrid();
2390
2391 //
2392 // Re-repare children (recursively)
2393 for ( unsigned int i=0; i<GetChildCount(); i++ )
2394 {
2395 wxPGProperty* child = Item(i);
2396 child->InitAfterAdded(state, grid);
2397 }
2398
2399 wxPGProperty* sel = (wxPGProperty*) NULL;
2400 if ( oldSelInd >= (int)m_children.size() )
2401 oldSelInd = (int)m_children.size() - 1;
2402
2403 if ( oldSelInd >= 0 )
2404 sel = m_children[oldSelInd];
2405 else if ( oldSelInd == -2 )
2406 sel = this;
2407
2408 if ( sel )
2409 state->DoSelectProperty(sel);
2410
2411 if ( state == grid->GetState() )
2412 {
2413 grid->GetPanel()->Refresh();
2414 }
2415 }
2416
2417 // -----------------------------------------------------------------------
2418 // wxPGRootProperty
2419 // -----------------------------------------------------------------------
2420
2421 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty,none,TextCtrl)
2422 IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty, wxPGProperty)
2423
2424
2425 wxPGRootProperty::wxPGRootProperty()
2426 : wxPGProperty()
2427 {
2428 #ifdef __WXDEBUG__
2429 m_name = wxS("<root>");
2430 #endif
2431 SetParentalType(0);
2432 m_depth = 0;
2433 }
2434
2435
2436 wxPGRootProperty::~wxPGRootProperty()
2437 {
2438 }
2439
2440
2441 // -----------------------------------------------------------------------
2442 // wxPropertyCategory
2443 // -----------------------------------------------------------------------
2444
2445 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory,none,TextCtrl)
2446 IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory, wxPGProperty)
2447
2448 void wxPropertyCategory::Init()
2449 {
2450 // don't set colour - prepareadditem method should do this
2451 SetParentalType(wxPG_PROP_CATEGORY);
2452 m_capFgColIndex = 1;
2453 m_textExtent = -1;
2454 }
2455
2456 wxPropertyCategory::wxPropertyCategory()
2457 : wxPGProperty()
2458 {
2459 Init();
2460 }
2461
2462
2463 wxPropertyCategory::wxPropertyCategory( const wxString &label, const wxString& name )
2464 : wxPGProperty(label,name)
2465 {
2466 Init();
2467 }
2468
2469
2470 wxPropertyCategory::~wxPropertyCategory()
2471 {
2472 }
2473
2474
2475 wxString wxPropertyCategory::ValueToString( wxVariant& WXUNUSED(value),
2476 int WXUNUSED(argFlags) ) const
2477 {
2478 return wxEmptyString;
2479 }
2480
2481 int wxPropertyCategory::GetTextExtent( const wxWindow* wnd, const wxFont& font ) const
2482 {
2483 if ( m_textExtent > 0 )
2484 return m_textExtent;
2485 int x = 0, y = 0;
2486 ((wxWindow*)wnd)->GetTextExtent( m_label, &x, &y, 0, 0, &font );
2487 return x;
2488 }
2489
2490 void wxPropertyCategory::CalculateTextExtent( wxWindow* wnd, const wxFont& font )
2491 {
2492 int x = 0, y = 0;
2493 wnd->GetTextExtent( m_label, &x, &y, 0, 0, &font );
2494 m_textExtent = x;
2495 }
2496
2497 // -----------------------------------------------------------------------
2498 // wxPGAttributeStorage
2499 // -----------------------------------------------------------------------
2500
2501 wxPGAttributeStorage::wxPGAttributeStorage()
2502 {
2503 }
2504
2505 wxPGAttributeStorage::~wxPGAttributeStorage()
2506 {
2507 wxPGHashMapS2P::iterator it;
2508
2509 for ( it = m_map.begin(); it != m_map.end(); ++it )
2510 {
2511 wxVariantData* data = (wxVariantData*) it->second;
2512 data->DecRef();
2513 }
2514 }
2515
2516 void wxPGAttributeStorage::Set( const wxString& name, const wxVariant& value )
2517 {
2518 wxVariantData* data = value.GetData();
2519
2520 // Free old, if any
2521 wxPGHashMapS2P::iterator it = m_map.find(name);
2522 if ( it != m_map.end() )
2523 {
2524 ((wxVariantData*)it->second)->DecRef();
2525
2526 if ( !data )
2527 {
2528 // If Null variant, just remove from set
2529 m_map.erase(it);
2530 return;
2531 }
2532 }
2533
2534 if ( data )
2535 {
2536 data->IncRef();
2537
2538 m_map[name] = data;
2539 }
2540 }
2541
2542 #endif // wxUSE_PROPGRID