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