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