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