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