]>
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 | ||
a2851207 JS |
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); | |
d7e2b522 | 156 | |
1c4293cb VZ |
157 | const wxBitmap& bmp = cell.GetBitmap(); |
158 | if ( bmp.Ok() && | |
d7e2b522 JS |
159 | // Do not draw oversized bitmap outside choice popup |
160 | ((flags & ChoicePopup) || bmp.GetHeight() < rect.height ) | |
1c4293cb VZ |
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; | |
d7e2b522 | 196 | const wxPGCell* cell = NULL; |
1c4293cb VZ |
197 | |
198 | wxString text; | |
199 | int imageOffset = 0; | |
d7e2b522 | 200 | int preDrawFlags = flags; |
1c4293cb | 201 | |
d7e2b522 | 202 | property->GetDisplayInfo(column, item, flags, &text, &cell); |
1c4293cb | 203 | |
d7e2b522 | 204 | imageOffset = PreDrawCell( dc, rect, *cell, preDrawFlags ); |
1c4293cb | 205 | |
d7e2b522 | 206 | if ( column == 1 ) |
1c4293cb VZ |
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 | ||
1c4293cb VZ |
227 | dc.SetPen( wxPen(propertyGrid->GetCellTextColour(), 1, wxSOLID) ); |
228 | ||
229 | paintdata.m_drawnWidth = imageSize.x; | |
230 | paintdata.m_drawnHeight = imageSize.y; | |
231 | ||
b7bc9d80 | 232 | property->OnCustomPaint( dc, imageRect, paintdata ); |
1c4293cb VZ |
233 | |
234 | imageOffset = paintdata.m_drawnWidth; | |
235 | } | |
236 | ||
1425eca5 | 237 | text = property->GetValueAsString(); |
1c4293cb VZ |
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 | } | |
1c4293cb VZ |
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 | ||
d7e2b522 JS |
298 | // ----------------------------------------------------------------------- |
299 | // wxPGCellData | |
300 | // ----------------------------------------------------------------------- | |
301 | ||
302 | wxPGCellData::wxPGCellData() | |
303 | : wxObjectRefData() | |
304 | { | |
305 | m_hasValidText = false; | |
306 | } | |
307 | ||
1c4293cb VZ |
308 | // ----------------------------------------------------------------------- |
309 | // wxPGCell | |
310 | // ----------------------------------------------------------------------- | |
311 | ||
312 | wxPGCell::wxPGCell() | |
d7e2b522 | 313 | : wxObject() |
1c4293cb VZ |
314 | { |
315 | } | |
316 | ||
317 | wxPGCell::wxPGCell( const wxString& text, | |
318 | const wxBitmap& bitmap, | |
319 | const wxColour& fgCol, | |
320 | const wxColour& bgCol ) | |
d7e2b522 JS |
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 ) | |
1c4293cb | 352 | { |
d7e2b522 JS |
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()); | |
1c4293cb VZ |
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; | |
1c4293cb VZ |
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 | ||
2fd4a524 JS |
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 | ||
1425eca5 JS |
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 | ||
d7e2b522 | 461 | if ( !parentIsRoot && !parent->IsCategory() ) |
2fd4a524 | 462 | { |
d7e2b522 | 463 | m_cells = parent->m_cells; |
2fd4a524 JS |
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 | { | |
2fd4a524 | 541 | // Check parental flags |
b0f0eda8 | 542 | wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS), |
2fd4a524 JS |
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 | ||
1c4293cb VZ |
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 | ||
1c4293cb VZ |
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 | ||
f7a094e1 JS |
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 | } | |
1c4293cb VZ |
641 | |
642 | void wxPGProperty::UpdateControl( wxWindow* primary ) | |
643 | { | |
644 | if ( primary ) | |
645 | GetEditorClass()->UpdateControl(this, primary); | |
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 | ||
d7e2b522 JS |
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 | |
1c4293cb | 714 | { |
d7e2b522 JS |
715 | |
716 | if ( col != 1 || choiceIndex == wxNOT_FOUND ) | |
1c4293cb | 717 | { |
d7e2b522 JS |
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 | } | |
1c4293cb VZ |
732 | } |
733 | else | |
734 | { | |
d7e2b522 JS |
735 | // Use choice |
736 | return m_choices.GetLabel(choiceIndex); | |
1c4293cb VZ |
737 | } |
738 | ||
739 | return wxEmptyString; | |
740 | } | |
d7e2b522 | 741 | */ |
1c4293cb | 742 | |
c82a80e8 JS |
743 | void wxPGProperty::DoGenerateComposedValue( wxString& text, |
744 | int argFlags, | |
745 | const wxVariantList* valueOverrides, | |
746 | wxPGHashMapS2S* childResults ) const | |
1c4293cb VZ |
747 | { |
748 | int i; | |
f7a094e1 | 749 | int iMax = m_children.size(); |
1c4293cb VZ |
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 | ||
f7a094e1 | 764 | wxPGProperty* curChild = m_children[0]; |
1c4293cb | 765 | |
1425eca5 JS |
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 | ||
1c4293cb VZ |
780 | for ( i = 0; i < iMax; i++ ) |
781 | { | |
1425eca5 JS |
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(); | |
b7bc9d80 | 793 | ++node; |
1425eca5 JS |
794 | if ( node != valueOverrides->end() ) |
795 | overrideValue = *node; | |
796 | else | |
797 | overridesLeft = false; | |
798 | } | |
799 | else | |
800 | { | |
801 | childValue = curChild->GetValue(); | |
802 | } | |
803 | ||
1c4293cb | 804 | wxString s; |
1425eca5 JS |
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(); | |
c82a80e8 JS |
812 | DoGenerateComposedValue(s, argFlags|wxPG_COMPOSITE_FRAGMENT, |
813 | &childList, childResults); | |
1425eca5 JS |
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; | |
1c4293cb VZ |
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 | ||
f7a094e1 | 849 | curChild = m_children[i+1]; |
1c4293cb VZ |
850 | } |
851 | } | |
852 | ||
f7a094e1 | 853 | if ( (unsigned int)i < m_children.size() ) |
7036fd20 JS |
854 | { |
855 | if ( !text.EndsWith(wxS("; ")) ) | |
856 | text += wxS("; ..."); | |
857 | else | |
858 | text += wxS("..."); | |
859 | } | |
1c4293cb VZ |
860 | } |
861 | ||
1425eca5 JS |
862 | wxString wxPGProperty::ValueToString( wxVariant& WXUNUSED(value), |
863 | int argFlags ) const | |
1c4293cb VZ |
864 | { |
865 | wxCHECK_MSG( GetChildCount() > 0, | |
866 | wxString(), | |
1425eca5 JS |
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." ); | |
1c4293cb VZ |
874 | |
875 | wxString text; | |
c82a80e8 | 876 | DoGenerateComposedValue(text, argFlags); |
1c4293cb VZ |
877 | return text; |
878 | } | |
879 | ||
1425eca5 | 880 | wxString wxPGProperty::GetValueAsString( int argFlags ) const |
1c4293cb | 881 | { |
1425eca5 JS |
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 | ||
1c4293cb VZ |
893 | if ( IsValueUnspecified() ) |
894 | return wxEmptyString; | |
895 | ||
896 | if ( m_commonValue == -1 ) | |
1425eca5 JS |
897 | { |
898 | wxVariant value(GetValue()); | |
899 | return ValueToString(value, argFlags|wxPG_VALUE_IS_CURRENT); | |
900 | } | |
1c4293cb VZ |
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 | ||
1425eca5 JS |
921 | wxString wxPGProperty::GetValueString( int argFlags ) const |
922 | { | |
923 | return GetValueAsString(argFlags); | |
924 | } | |
925 | ||
1c4293cb VZ |
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 | ||
f7a094e1 | 940 | unsigned int iMax = m_children.size(); |
1c4293cb VZ |
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 | ||
f275b5db | 960 | int propagatedFlags = argFlags & (wxPG_REPORT_ERROR|wxPG_PROGRAMMATIC_VALUE); |
1c4293cb VZ |
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); | |
f275b5db JS |
993 | wxVariant variant(child->GetValue()); |
994 | variant.SetName(child->GetBaseName()); | |
995 | ||
1c4293cb VZ |
996 | #ifdef __WXDEBUG__ |
997 | if ( debug_print ) | |
998 | wxLogDebug(wxT("token = '%s', child = %s"),token.c_str(),child->GetLabel().c_str()); | |
999 | #endif | |
1000 | ||
f275b5db JS |
1001 | // Add only if editable or setting programmatically |
1002 | if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) || | |
1003 | !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) ) | |
1c4293cb | 1004 | { |
f275b5db | 1005 | if ( len > 0 ) |
1c4293cb | 1006 | { |
f275b5db | 1007 | if ( child->StringToValue(variant, token, propagatedFlags|wxPG_COMPOSITE_FRAGMENT) ) |
1c4293cb | 1008 | { |
f275b5db | 1009 | list.Append(variant); |
1c4293cb | 1010 | |
f275b5db JS |
1011 | changed = true; |
1012 | } | |
1013 | } | |
1014 | else | |
1015 | { | |
1016 | // Empty, becomes unspecified | |
1017 | variant.MakeNull(); | |
1018 | list.Append(variant); | |
1c4293cb VZ |
1019 | changed = true; |
1020 | } | |
1021 | } | |
1c4293cb VZ |
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 | ||
b7bc9d80 | 1044 | if ( it != text.end() ) ++it; |
1c4293cb VZ |
1045 | pos++; |
1046 | size_t startPos = pos; | |
1047 | ||
1048 | // Group item - find end | |
1049 | while ( it != text.end() && depth > 0 ) | |
1050 | { | |
1051 | a = *it; | |
b7bc9d80 | 1052 | ++it; |
1c4293cb VZ |
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 | ||
2bbd3749 JS |
1068 | wxVariant oldChildValue = child->GetValue(); |
1069 | wxVariant variant(oldChildValue); | |
f275b5db JS |
1070 | |
1071 | if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) || | |
1072 | !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) ) | |
1c4293cb | 1073 | { |
f275b5db JS |
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(); | |
2bbd3749 | 1084 | changed = true; |
f275b5db | 1085 | } |
1c4293cb VZ |
1086 | } |
1087 | ||
2bbd3749 JS |
1088 | variant.SetName(child->GetBaseName()); |
1089 | list.Append(variant); | |
1090 | ||
1c4293cb VZ |
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--; | |
b7bc9d80 | 1106 | --it; |
1c4293cb VZ |
1107 | } |
1108 | } | |
1109 | } | |
1110 | } | |
1111 | ||
1112 | if ( a == 0 ) | |
1113 | break; | |
1114 | ||
b7bc9d80 | 1115 | ++it; |
1c4293cb VZ |
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 | { | |
c26873c8 | 1179 | return wxPGEditor_TextCtrl; |
1c4293cb VZ |
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 | { | |
104837f2 JS |
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 | ||
1c4293cb VZ |
1199 | if ( !value.IsNull() ) |
1200 | { | |
8f18b252 JS |
1201 | wxVariant tempListVariant; |
1202 | ||
1c4293cb VZ |
1203 | SetCommonValue(-1); |
1204 | // List variants are reserved a special purpose | |
1205 | // as intermediate containers for child values | |
1206 | // of properties with children. | |
0372d42e | 1207 | if ( value.GetType() == wxPG_VARIANT_TYPE_LIST ) |
1c4293cb | 1208 | { |
8f18b252 JS |
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 | ||
1c4293cb VZ |
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 | { | |
0372d42e | 1228 | wxASSERT( pList->GetType() == wxPG_VARIANT_TYPE_LIST ); |
1c4293cb VZ |
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 | |
d665918b | 1239 | // GetPropertyByNameWH(). This optimizes for full list parsing. |
b7bc9d80 | 1240 | for ( node = list.begin(); node != list.end(); ++node ) |
1c4293cb VZ |
1241 | { |
1242 | wxVariant& childValue = *((wxVariant*)*node); | |
d665918b | 1243 | wxPGProperty* child = GetPropertyByNameWH(childValue.GetName(), i); |
1c4293cb VZ |
1244 | if ( child ) |
1245 | { | |
d665918b | 1246 | //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str()); |
0372d42e | 1247 | if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST ) |
1c4293cb VZ |
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 | } | |
0372d42e | 1260 | else if ( child->GetValue() != childValue ) |
1c4293cb VZ |
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); | |
8f18b252 JS |
1266 | if ( flags & wxPG_SETVAL_BY_USER ) |
1267 | child->SetFlag(wxPG_PROP_MODIFIED); | |
1c4293cb VZ |
1268 | } |
1269 | } | |
1270 | i++; | |
1271 | } | |
1272 | } | |
1273 | ||
1274 | if ( !value.IsNull() ) | |
1275 | { | |
0372d42e | 1276 | m_value = value; |
1c4293cb VZ |
1277 | OnSetValue(); |
1278 | ||
1279 | if ( !(flags & wxPG_SETVAL_FROM_PARENT) ) | |
1280 | UpdateParentValues(); | |
1281 | } | |
1282 | ||
8f18b252 | 1283 | if ( flags & wxPG_SETVAL_BY_USER ) |
1c4293cb VZ |
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 && GetParentState() ) | |
1340 | { | |
1341 | wxPropertyGrid* pg = GetParentState()->GetGrid(); | |
1342 | if ( pg->GetSelectedProperty() == this ) | |
1343 | { | |
1344 | wxWindow* editor = pg->GetEditorControl(); | |
1345 | if ( editor ) | |
1346 | GetEditorClass()->UpdateControl( this, editor ); | |
1347 | } | |
1348 | } | |
1349 | } | |
1350 | ||
1351 | ||
1352 | wxVariant wxPGProperty::GetDefaultValue() const | |
1353 | { | |
1354 | wxVariant defVal = GetAttribute(wxS("DefaultValue")); | |
1355 | if ( !defVal.IsNull() ) | |
1356 | return defVal; | |
1357 | ||
1358 | wxVariant value = GetValue(); | |
1359 | ||
1360 | if ( !value.IsNull() ) | |
1361 | { | |
0372d42e JS |
1362 | wxString valueType(value.GetType()); |
1363 | ||
1364 | if ( valueType == wxPG_VARIANT_TYPE_LONG ) | |
1c4293cb | 1365 | return wxPGVariant_Zero; |
0372d42e | 1366 | if ( valueType == wxPG_VARIANT_TYPE_STRING ) |
1c4293cb | 1367 | return wxPGVariant_EmptyString; |
0372d42e | 1368 | if ( valueType == wxPG_VARIANT_TYPE_BOOL ) |
1c4293cb | 1369 | return wxPGVariant_False; |
0372d42e | 1370 | if ( valueType == wxPG_VARIANT_TYPE_DOUBLE ) |
1c4293cb | 1371 | return wxVariant(0.0); |
0372d42e | 1372 | if ( valueType == wxPG_VARIANT_TYPE_ARRSTRING ) |
1c4293cb | 1373 | return wxVariant(wxArrayString()); |
0372d42e JS |
1374 | if ( valueType == wxS("wxLongLong") ) |
1375 | return WXVARIANT(wxLongLong(0)); | |
1376 | if ( valueType == wxS("wxULongLong") ) | |
1377 | return WXVARIANT(wxULongLong(0)); | |
1378 | if ( valueType == wxS("wxColour") ) | |
1379 | return WXVARIANT(*wxBLACK); | |
1c4293cb | 1380 | #if wxUSE_DATETIME |
0372d42e | 1381 | if ( valueType == wxPG_VARIANT_TYPE_DATETIME ) |
1c4293cb VZ |
1382 | return wxVariant(wxDateTime::Now()); |
1383 | #endif | |
0372d42e JS |
1384 | if ( valueType == wxS("wxFont") ) |
1385 | return WXVARIANT(*wxNORMAL_FONT); | |
1386 | if ( valueType == wxS("wxPoint") ) | |
1387 | return WXVARIANT(wxPoint(0, 0)); | |
1388 | if ( valueType == wxS("wxSize") ) | |
1389 | return WXVARIANT(wxSize(0, 0)); | |
1c4293cb VZ |
1390 | } |
1391 | ||
1392 | return wxVariant(); | |
1393 | } | |
1394 | ||
d7e2b522 JS |
1395 | void wxPGProperty::EnsureCells( unsigned int column ) |
1396 | { | |
1397 | if ( column >= m_cells.size() ) | |
1398 | { | |
1399 | // Fill empty slots with default cells | |
1400 | wxPropertyGrid* pg = GetGrid(); | |
1401 | wxPGCell defaultCell; | |
1402 | ||
1403 | if ( !HasFlag(wxPG_PROP_CATEGORY) ) | |
1404 | defaultCell = pg->GetPropertyDefaultCell(); | |
1405 | else | |
1406 | defaultCell = pg->GetCategoryDefaultCell(); | |
1407 | ||
1408 | // TODO: Replace with resize() call | |
1409 | unsigned int cellCountMax = column+1; | |
1410 | ||
1411 | for ( unsigned int i=m_cells.size(); i<cellCountMax; i++ ) | |
1412 | m_cells.push_back(defaultCell); | |
1413 | } | |
1414 | } | |
1415 | ||
1416 | void wxPGProperty::SetCell( int column, | |
1417 | const wxPGCell& cell ) | |
1418 | { | |
1419 | EnsureCells(column); | |
1420 | ||
1421 | m_cells[column] = cell; | |
1422 | } | |
1423 | ||
1424 | void wxPGProperty::AdaptiveSetCell( unsigned int firstCol, | |
1425 | unsigned int lastCol, | |
1426 | const wxPGCell& cell, | |
1427 | const wxPGCell& srcData, | |
1428 | wxPGCellData* unmodCellData, | |
1429 | FlagType ignoreWithFlags, | |
1430 | bool recursively ) | |
1431 | { | |
1432 | // | |
1433 | // Sets cell in memory optimizing fashion. That is, if | |
1434 | // current cell data matches unmodCellData, we will | |
1435 | // simply get reference to data from cell. Otherwise, | |
1436 | // cell information from srcData is merged into current. | |
1437 | // | |
1438 | ||
1439 | if ( !(m_flags & ignoreWithFlags) && !IsRoot() ) | |
1440 | { | |
1441 | EnsureCells(lastCol); | |
1442 | ||
1443 | for ( unsigned int col=firstCol; col<=lastCol; col++ ) | |
1444 | { | |
1445 | if ( m_cells[col].GetData() == unmodCellData ) | |
1446 | { | |
1447 | // Data matches... use cell directly | |
1448 | m_cells[col] = cell; | |
1449 | } | |
1450 | else | |
1451 | { | |
1452 | // Data did not match... merge valid information | |
1453 | m_cells[col].MergeFrom(srcData); | |
1454 | } | |
1455 | } | |
1456 | } | |
1457 | ||
1458 | if ( recursively ) | |
1459 | { | |
1460 | for ( unsigned int i=0; i<GetChildCount(); i++ ) | |
1461 | Item(i)->AdaptiveSetCell( firstCol, | |
1462 | lastCol, | |
1463 | cell, | |
1464 | srcData, | |
1465 | unmodCellData, | |
1466 | ignoreWithFlags, | |
1467 | recursively ); | |
1468 | } | |
1469 | } | |
1470 | ||
1471 | const wxPGCell& wxPGProperty::GetCell( unsigned int column ) const | |
1c4293cb | 1472 | { |
d7e2b522 JS |
1473 | if ( m_cells.size() > column ) |
1474 | return m_cells[column]; | |
1475 | ||
1476 | wxPropertyGrid* pg = GetGrid(); | |
1477 | ||
1478 | if ( IsCategory() ) | |
1479 | return pg->GetCategoryDefaultCell(); | |
1480 | ||
1481 | return pg->GetPropertyDefaultCell(); | |
1482 | } | |
1483 | ||
1484 | wxPGCell& wxPGProperty::GetCell( unsigned int column ) | |
1485 | { | |
1486 | EnsureCells(column); | |
1487 | return m_cells[column]; | |
1488 | } | |
1489 | ||
1490 | void wxPGProperty::SetBackgroundColour( const wxColour& colour, | |
1491 | bool recursively ) | |
1492 | { | |
1493 | wxPGProperty* firstProp = this; | |
1494 | ||
1495 | // | |
1496 | // If category is tried to set recursively, skip it and only | |
1497 | // affect the children. | |
1498 | if ( recursively ) | |
1499 | { | |
1500 | while ( firstProp->IsCategory() ) | |
1501 | { | |
1502 | if ( !firstProp->GetChildCount() ) | |
1503 | return; | |
1504 | firstProp = firstProp->Item(0); | |
1505 | } | |
1506 | } | |
1507 | ||
1508 | wxPGCell& firstCell = firstProp->GetCell(0); | |
1509 | wxPGCellData* firstCellData = firstCell.GetData(); | |
1510 | ||
1511 | wxPGCell newCell(firstCell); | |
1512 | newCell.SetBgCol(colour); | |
1513 | wxPGCell srcCell; | |
1514 | srcCell.SetBgCol(colour); | |
1515 | ||
1516 | AdaptiveSetCell( 0, | |
1517 | GetParentState()->GetColumnCount()-1, | |
1518 | newCell, | |
1519 | srcCell, | |
1520 | firstCellData, | |
1521 | recursively ? wxPG_PROP_CATEGORY : 0, | |
1522 | recursively ); | |
1523 | } | |
1524 | ||
1525 | void wxPGProperty::SetTextColour( const wxColour& colour, | |
1526 | bool recursively ) | |
1527 | { | |
1528 | wxPGProperty* firstProp = this; | |
1529 | ||
1530 | // | |
1531 | // If category is tried to set recursively, skip it and only | |
1532 | // affect the children. | |
1533 | if ( recursively ) | |
1534 | { | |
1535 | while ( firstProp->IsCategory() ) | |
1536 | { | |
1537 | if ( !firstProp->GetChildCount() ) | |
1538 | return; | |
1539 | firstProp = firstProp->Item(0); | |
1540 | } | |
1541 | } | |
1c4293cb | 1542 | |
d7e2b522 JS |
1543 | wxPGCell& firstCell = firstProp->GetCell(0); |
1544 | wxPGCellData* firstCellData = firstCell.GetData(); | |
1545 | ||
1546 | wxPGCell newCell(firstCell); | |
1547 | newCell.SetFgCol(colour); | |
1548 | wxPGCell srcCell; | |
1549 | srcCell.SetFgCol(colour); | |
1550 | ||
1551 | AdaptiveSetCell( 0, | |
1552 | GetParentState()->GetColumnCount()-1, | |
1553 | newCell, | |
1554 | srcCell, | |
1555 | firstCellData, | |
1556 | recursively ? wxPG_PROP_CATEGORY : 0, | |
1557 | recursively ); | |
1c4293cb VZ |
1558 | } |
1559 | ||
1c4293cb VZ |
1560 | wxPGEditorDialogAdapter* wxPGProperty::GetEditorDialog() const |
1561 | { | |
1562 | return NULL; | |
1563 | } | |
1564 | ||
1565 | bool wxPGProperty::DoSetAttribute( const wxString& WXUNUSED(name), wxVariant& WXUNUSED(value) ) | |
1566 | { | |
1567 | return false; | |
1568 | } | |
1569 | ||
1570 | void wxPGProperty::SetAttribute( const wxString& name, wxVariant value ) | |
1571 | { | |
1572 | if ( DoSetAttribute( name, value ) ) | |
1573 | { | |
1574 | // Support working without grid, when possible | |
1575 | if ( wxPGGlobalVars->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES ) ) | |
1576 | return; | |
1577 | } | |
1578 | ||
1579 | m_attributes.Set( name, value ); | |
1580 | } | |
1581 | ||
1582 | void wxPGProperty::SetAttributes( const wxPGAttributeStorage& attributes ) | |
1583 | { | |
1584 | wxPGAttributeStorage::const_iterator it = attributes.StartIteration(); | |
1585 | wxVariant variant; | |
1586 | ||
1587 | while ( attributes.GetNext(it, variant) ) | |
1588 | SetAttribute( variant.GetName(), variant ); | |
1589 | } | |
1590 | ||
1591 | wxVariant wxPGProperty::DoGetAttribute( const wxString& WXUNUSED(name) ) const | |
1592 | { | |
1593 | return wxVariant(); | |
1594 | } | |
1595 | ||
1596 | ||
1597 | wxVariant wxPGProperty::GetAttribute( const wxString& name ) const | |
1598 | { | |
1599 | return m_attributes.FindValue(name); | |
1600 | } | |
1601 | ||
1602 | wxString wxPGProperty::GetAttribute( const wxString& name, const wxString& defVal ) const | |
1603 | { | |
1604 | wxVariant variant = m_attributes.FindValue(name); | |
1605 | ||
1606 | if ( !variant.IsNull() ) | |
1607 | return variant.GetString(); | |
1608 | ||
1609 | return defVal; | |
1610 | } | |
1611 | ||
1612 | long wxPGProperty::GetAttributeAsLong( const wxString& name, long defVal ) const | |
1613 | { | |
1614 | wxVariant variant = m_attributes.FindValue(name); | |
1615 | ||
1616 | return wxPGVariantToInt(variant, defVal); | |
1617 | } | |
1618 | ||
1619 | double wxPGProperty::GetAttributeAsDouble( const wxString& name, double defVal ) const | |
1620 | { | |
1621 | double retVal; | |
1622 | wxVariant variant = m_attributes.FindValue(name); | |
1623 | ||
1624 | if ( wxPGVariantToDouble(variant, &retVal) ) | |
1625 | return retVal; | |
1626 | ||
1627 | return defVal; | |
1628 | } | |
1629 | ||
1630 | wxVariant wxPGProperty::GetAttributesAsList() const | |
1631 | { | |
1632 | wxVariantList tempList; | |
1633 | wxVariant v( tempList, wxString::Format(wxS("@%s@attr"),m_name.c_str()) ); | |
1634 | ||
1635 | wxPGAttributeStorage::const_iterator it = m_attributes.StartIteration(); | |
1636 | wxVariant variant; | |
1637 | ||
1638 | while ( m_attributes.GetNext(it, variant) ) | |
1639 | v.Append(variant); | |
1640 | ||
1641 | return v; | |
1642 | } | |
1643 | ||
1644 | // Slots of utility flags are NULL | |
1645 | const unsigned int gs_propFlagToStringSize = 14; | |
1646 | ||
1647 | static const wxChar* gs_propFlagToString[gs_propFlagToStringSize] = { | |
1648 | NULL, | |
1649 | wxT("DISABLED"), | |
1650 | wxT("HIDDEN"), | |
1651 | NULL, | |
1652 | wxT("NOEDITOR"), | |
1653 | wxT("COLLAPSED"), | |
1654 | NULL, | |
1655 | NULL, | |
1656 | NULL, | |
1657 | NULL, | |
1658 | NULL, | |
1659 | NULL, | |
1660 | NULL, | |
1661 | NULL | |
1662 | }; | |
1663 | ||
1664 | wxString wxPGProperty::GetFlagsAsString( FlagType flagsMask ) const | |
1665 | { | |
1666 | wxString s; | |
1667 | int relevantFlags = m_flags & flagsMask & wxPG_STRING_STORED_FLAGS; | |
1668 | FlagType a = 1; | |
1669 | ||
1670 | unsigned int i = 0; | |
1671 | for ( i=0; i<gs_propFlagToStringSize; i++ ) | |
1672 | { | |
1673 | if ( relevantFlags & a ) | |
1674 | { | |
1675 | const wxChar* fs = gs_propFlagToString[i]; | |
1676 | wxASSERT(fs); | |
1677 | if ( s.length() ) | |
1678 | s << wxS("|"); | |
1679 | s << fs; | |
1680 | } | |
1681 | a = a << 1; | |
1682 | } | |
1683 | ||
1684 | return s; | |
1685 | } | |
1686 | ||
1687 | void wxPGProperty::SetFlagsFromString( const wxString& str ) | |
1688 | { | |
1689 | FlagType flags = 0; | |
1690 | ||
1691 | WX_PG_TOKENIZER1_BEGIN(str, wxS('|')) | |
1692 | unsigned int i; | |
1693 | for ( i=0; i<gs_propFlagToStringSize; i++ ) | |
1694 | { | |
1695 | const wxChar* fs = gs_propFlagToString[i]; | |
1696 | if ( fs && str == fs ) | |
1697 | { | |
1698 | flags |= (1<<i); | |
1699 | break; | |
1700 | } | |
1701 | } | |
1702 | WX_PG_TOKENIZER1_END() | |
1703 | ||
1704 | m_flags = (m_flags & ~wxPG_STRING_STORED_FLAGS) | flags; | |
1705 | } | |
1706 | ||
1707 | wxValidator* wxPGProperty::DoGetValidator() const | |
1708 | { | |
1709 | return (wxValidator*) NULL; | |
1710 | } | |
1711 | ||
939d9364 | 1712 | int wxPGProperty::InsertChoice( const wxString& label, int index, int value ) |
1c4293cb | 1713 | { |
939d9364 JS |
1714 | wxPropertyGrid* pg = GetGrid(); |
1715 | int sel = GetChoiceSelection(); | |
1716 | ||
1717 | int newSel = sel; | |
1718 | ||
1719 | if ( index == wxNOT_FOUND ) | |
1720 | index = m_choices.GetCount(); | |
1721 | ||
1722 | if ( index <= sel ) | |
1723 | newSel++; | |
1724 | ||
1725 | m_choices.Insert(label, index, value); | |
1726 | ||
1727 | if ( sel != newSel ) | |
1728 | SetChoiceSelection(newSel); | |
1729 | ||
1730 | if ( this == pg->GetSelection() ) | |
1731 | GetEditorClass()->InsertItem(pg->GetEditorControl(),label,index); | |
1732 | ||
1733 | return index; | |
1c4293cb VZ |
1734 | } |
1735 | ||
939d9364 JS |
1736 | |
1737 | void wxPGProperty::DeleteChoice( int index ) | |
1c4293cb | 1738 | { |
939d9364 JS |
1739 | wxPropertyGrid* pg = GetGrid(); |
1740 | ||
1741 | int sel = GetChoiceSelection(); | |
1742 | int newSel = sel; | |
1743 | ||
1744 | // Adjust current value | |
1745 | if ( sel == index ) | |
1746 | { | |
1747 | SetValueToUnspecified(); | |
1748 | newSel = 0; | |
1749 | } | |
1750 | else if ( index < sel ) | |
1751 | { | |
1752 | newSel--; | |
1753 | } | |
1754 | ||
1755 | m_choices.RemoveAt(index); | |
1756 | ||
1757 | if ( sel != newSel ) | |
1758 | SetChoiceSelection(newSel); | |
1759 | ||
1760 | if ( this == pg->GetSelection() ) | |
1761 | GetEditorClass()->DeleteItem(pg->GetEditorControl(), index); | |
1c4293cb VZ |
1762 | } |
1763 | ||
939d9364 | 1764 | int wxPGProperty::GetChoiceSelection() const |
1c4293cb | 1765 | { |
939d9364 JS |
1766 | wxVariant value = GetValue(); |
1767 | wxString valueType = value.GetType(); | |
1768 | int index = wxNOT_FOUND; | |
1769 | ||
1770 | if ( IsValueUnspecified() || !m_choices.GetCount() ) | |
1771 | return wxNOT_FOUND; | |
1772 | ||
1773 | if ( valueType == wxPG_VARIANT_TYPE_LONG ) | |
1774 | { | |
1775 | index = value.GetLong(); | |
1776 | } | |
1777 | else if ( valueType == wxPG_VARIANT_TYPE_STRING ) | |
1778 | { | |
1779 | index = m_choices.Index(value.GetString()); | |
1780 | } | |
1781 | else if ( valueType == wxPG_VARIANT_TYPE_BOOL ) | |
1782 | { | |
1783 | index = value.GetBool()? 1 : 0; | |
1784 | } | |
1785 | ||
1786 | return index; | |
1c4293cb VZ |
1787 | } |
1788 | ||
939d9364 | 1789 | void wxPGProperty::SetChoiceSelection( int newValue ) |
1c4293cb | 1790 | { |
939d9364 JS |
1791 | // Changes value of a property with choices, but only |
1792 | // works if the value type is long or string. | |
1793 | wxString valueType = GetValue().GetType(); | |
1794 | ||
1795 | wxCHECK_RET( m_choices.IsOk(), wxT("invalid choiceinfo") ); | |
1c4293cb | 1796 | |
939d9364 JS |
1797 | if ( valueType == wxPG_VARIANT_TYPE_STRING ) |
1798 | { | |
1799 | SetValue( m_choices.GetLabel(newValue) ); | |
1800 | } | |
1801 | else // if ( valueType == wxPG_VARIANT_TYPE_LONG ) | |
1802 | { | |
1803 | SetValue( (long) newValue ); | |
1804 | } | |
1c4293cb VZ |
1805 | } |
1806 | ||
1807 | bool wxPGProperty::SetChoices( wxPGChoices& choices ) | |
1808 | { | |
939d9364 | 1809 | m_choices.Assign(choices); |
1c4293cb | 1810 | |
1c4293cb | 1811 | { |
939d9364 JS |
1812 | // This may be needed to trigger some initialization |
1813 | // (but don't do it if property is somewhat uninitialized) | |
1814 | wxVariant defVal = GetDefaultValue(); | |
1815 | if ( defVal.IsNull() ) | |
1816 | return false; | |
1c4293cb | 1817 | |
939d9364 | 1818 | SetValue(defVal); |
1c4293cb | 1819 | } |
939d9364 JS |
1820 | |
1821 | return true; | |
1c4293cb VZ |
1822 | } |
1823 | ||
1824 | ||
1825 | const wxPGEditor* wxPGProperty::GetEditorClass() const | |
1826 | { | |
1827 | const wxPGEditor* editor; | |
1828 | ||
1829 | if ( !m_customEditor ) | |
1830 | { | |
1831 | editor = DoGetEditorClass(); | |
1832 | } | |
1833 | else | |
1834 | editor = m_customEditor; | |
1835 | ||
1836 | // | |
1837 | // Maybe override editor if common value specified | |
1838 | if ( GetDisplayedCommonValueCount() ) | |
1839 | { | |
1840 | // TextCtrlAndButton -> ComboBoxAndButton | |
1841 | if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor)) ) | |
c26873c8 | 1842 | editor = wxPGEditor_ChoiceAndButton; |
1c4293cb VZ |
1843 | |
1844 | // TextCtrl -> ComboBox | |
1845 | else if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlEditor)) ) | |
c26873c8 | 1846 | editor = wxPGEditor_ComboBox; |
1c4293cb VZ |
1847 | } |
1848 | ||
1849 | return editor; | |
1850 | } | |
1851 | ||
1c4293cb VZ |
1852 | bool wxPGProperty::HasVisibleChildren() const |
1853 | { | |
1854 | unsigned int i; | |
1855 | ||
1856 | for ( i=0; i<GetChildCount(); i++ ) | |
1857 | { | |
1858 | wxPGProperty* child = Item(i); | |
1859 | ||
1860 | if ( !child->HasFlag(wxPG_PROP_HIDDEN) ) | |
1861 | return true; | |
1862 | } | |
1863 | ||
1864 | return false; | |
1865 | } | |
1866 | ||
1c4293cb VZ |
1867 | bool wxPGProperty::RecreateEditor() |
1868 | { | |
1869 | wxPropertyGrid* pg = GetGrid(); | |
1870 | wxASSERT(pg); | |
1871 | ||
1872 | wxPGProperty* selected = pg->GetSelection(); | |
1873 | if ( this == selected ) | |
1874 | { | |
1875 | pg->DoSelectProperty(this, wxPG_SEL_FORCE); | |
1876 | return true; | |
1877 | } | |
1878 | return false; | |
1879 | } | |
1880 | ||
1881 | ||
1882 | void wxPGProperty::SetValueImage( wxBitmap& bmp ) | |
1883 | { | |
1884 | delete m_valueBitmap; | |
1885 | ||
1886 | if ( &bmp && bmp.Ok() ) | |
1887 | { | |
1888 | // Resize the image | |
1889 | wxSize maxSz = GetGrid()->GetImageSize(); | |
1890 | wxSize imSz(bmp.GetWidth(),bmp.GetHeight()); | |
1891 | ||
1892 | if ( imSz.x != maxSz.x || imSz.y != maxSz.y ) | |
1893 | { | |
1894 | // Create a memory DC | |
1895 | wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth()); | |
1896 | ||
1897 | wxMemoryDC dc; | |
1898 | dc.SelectObject(*bmpNew); | |
1899 | ||
1900 | // Scale | |
1901 | // FIXME: This is ugly - use image or wait for scaling patch. | |
1902 | double scaleX = (double)maxSz.x / (double)imSz.x; | |
1903 | double scaleY = (double)maxSz.y / (double)imSz.y; | |
1904 | ||
1905 | dc.SetUserScale(scaleX,scaleY); | |
1906 | ||
1907 | dc.DrawBitmap( bmp, 0, 0 ); | |
1908 | ||
1909 | m_valueBitmap = bmpNew; | |
1910 | } | |
1911 | else | |
1912 | { | |
1913 | m_valueBitmap = new wxBitmap(bmp); | |
1914 | } | |
1915 | ||
1916 | m_flags |= wxPG_PROP_CUSTOMIMAGE; | |
1917 | } | |
1918 | else | |
1919 | { | |
1920 | m_valueBitmap = NULL; | |
1921 | m_flags &= ~(wxPG_PROP_CUSTOMIMAGE); | |
1922 | } | |
1923 | } | |
1924 | ||
1925 | ||
1926 | wxPGProperty* wxPGProperty::GetMainParent() const | |
1927 | { | |
1928 | const wxPGProperty* curChild = this; | |
1929 | const wxPGProperty* curParent = m_parent; | |
1930 | ||
1931 | while ( curParent && !curParent->IsCategory() ) | |
1932 | { | |
1933 | curChild = curParent; | |
1934 | curParent = curParent->m_parent; | |
1935 | } | |
1936 | ||
1937 | return (wxPGProperty*) curChild; | |
1938 | } | |
1939 | ||
1940 | ||
1941 | const wxPGProperty* wxPGProperty::GetLastVisibleSubItem() const | |
1942 | { | |
1943 | // | |
1944 | // Returns last visible sub-item, recursively. | |
1945 | if ( !IsExpanded() || !GetChildCount() ) | |
1946 | return this; | |
1947 | ||
1948 | return Last()->GetLastVisibleSubItem(); | |
1949 | } | |
1950 | ||
1951 | ||
1952 | bool wxPGProperty::IsVisible() const | |
1953 | { | |
1954 | const wxPGProperty* parent; | |
1955 | ||
1956 | if ( HasFlag(wxPG_PROP_HIDDEN) ) | |
1957 | return false; | |
1958 | ||
1959 | for ( parent = GetParent(); parent != NULL; parent = parent->GetParent() ) | |
1960 | { | |
1961 | if ( !parent->IsExpanded() || parent->HasFlag(wxPG_PROP_HIDDEN) ) | |
1962 | return false; | |
1963 | } | |
1964 | ||
1965 | return true; | |
1966 | } | |
1967 | ||
1968 | wxPropertyGrid* wxPGProperty::GetGridIfDisplayed() const | |
1969 | { | |
1970 | wxPropertyGridPageState* state = GetParentState(); | |
1971 | wxPropertyGrid* propGrid = state->GetGrid(); | |
1972 | if ( state == propGrid->GetState() ) | |
1973 | return propGrid; | |
1974 | return NULL; | |
1975 | } | |
1976 | ||
1977 | ||
1978 | int wxPGProperty::GetY2( int lh ) const | |
1979 | { | |
1980 | const wxPGProperty* parent; | |
1981 | const wxPGProperty* child = this; | |
1982 | ||
1983 | int y = 0; | |
1984 | ||
1985 | for ( parent = GetParent(); parent != NULL; parent = child->GetParent() ) | |
1986 | { | |
1987 | if ( !parent->IsExpanded() ) | |
1988 | return -1; | |
1989 | y += parent->GetChildrenHeight(lh, child->GetIndexInParent()); | |
1990 | y += lh; | |
1991 | child = parent; | |
1992 | } | |
1993 | ||
1994 | y -= lh; // need to reduce one level | |
1995 | ||
1996 | return y; | |
1997 | } | |
1998 | ||
1999 | ||
2000 | int wxPGProperty::GetY() const | |
2001 | { | |
2002 | return GetY2(GetGrid()->GetRowHeight()); | |
2003 | } | |
2004 | ||
1c4293cb VZ |
2005 | // This is used by Insert etc. |
2006 | void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode ) | |
2007 | { | |
f7a094e1 | 2008 | if ( index < 0 || (size_t)index >= m_children.size() ) |
1c4293cb | 2009 | { |
f7a094e1 JS |
2010 | if ( correct_mode ) prop->m_arrIndex = m_children.size(); |
2011 | m_children.push_back( prop ); | |
1c4293cb VZ |
2012 | } |
2013 | else | |
2014 | { | |
f7a094e1 | 2015 | m_children.insert( m_children.begin()+index, prop); |
1b895132 | 2016 | if ( correct_mode ) FixIndicesOfChildren( index ); |
1c4293cb VZ |
2017 | } |
2018 | ||
2019 | prop->m_parent = this; | |
2020 | } | |
2021 | ||
2022 | // This is used by properties that have fixed sub-properties | |
2023 | void wxPGProperty::AddChild( wxPGProperty* prop ) | |
2024 | { | |
d665918b JS |
2025 | wxASSERT_MSG( prop->GetBaseName().length(), |
2026 | "Property's children must have unique, non-empty names within their scope" ); | |
2027 | ||
f7a094e1 JS |
2028 | prop->m_arrIndex = m_children.size(); |
2029 | m_children.push_back( prop ); | |
1c4293cb VZ |
2030 | |
2031 | int custImgHeight = prop->OnMeasureImage().y; | |
2032 | if ( custImgHeight < 0 /*|| custImgHeight > 1*/ ) | |
2033 | prop->m_flags |= wxPG_PROP_CUSTOMIMAGE; | |
2034 | ||
2035 | prop->m_parent = this; | |
2036 | } | |
2037 | ||
d8c74d04 JS |
2038 | void wxPGProperty::RemoveChild( wxPGProperty* p ) |
2039 | { | |
2040 | wxArrayPGProperty::iterator it; | |
2041 | wxArrayPGProperty& children = m_children; | |
2042 | ||
2043 | for ( it=children.begin(); it != children.end(); it++ ) | |
2044 | { | |
2045 | if ( *it == p ) | |
2046 | { | |
2047 | m_children.erase(it); | |
2048 | break; | |
2049 | } | |
2050 | } | |
2051 | } | |
1c4293cb VZ |
2052 | |
2053 | void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const | |
2054 | { | |
2055 | wxASSERT( GetChildCount() ); | |
2056 | wxASSERT( !IsCategory() ); | |
2057 | ||
2058 | *value = GetValue(); | |
2059 | ||
2060 | if ( !list.GetCount() ) | |
2061 | return; | |
2062 | ||
2063 | wxASSERT( GetChildCount() >= (unsigned int)list.GetCount() ); | |
2064 | ||
2065 | bool allChildrenSpecified; | |
2066 | ||
2067 | // Don't fully update aggregate properties unless all children have | |
2068 | // specified value | |
2069 | if ( HasFlag(wxPG_PROP_AGGREGATE) ) | |
2070 | allChildrenSpecified = AreAllChildrenSpecified(&list); | |
2071 | else | |
2072 | allChildrenSpecified = true; | |
2073 | ||
2074 | wxVariant childValue = list[0]; | |
2075 | unsigned int i; | |
2076 | unsigned int n = 0; | |
2077 | ||
d665918b | 2078 | //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str()); |
1c4293cb VZ |
2079 | |
2080 | for ( i=0; i<GetChildCount(); i++ ) | |
2081 | { | |
2082 | const wxPGProperty* child = Item(i); | |
2083 | ||
d665918b | 2084 | if ( childValue.GetName() == child->GetBaseName() ) |
1c4293cb VZ |
2085 | { |
2086 | //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str()); | |
2087 | ||
0372d42e | 2088 | if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST ) |
1c4293cb VZ |
2089 | { |
2090 | wxVariant cv2(child->GetValue()); | |
2091 | child->AdaptListToValue(childValue, &cv2); | |
2092 | childValue = cv2; | |
2093 | } | |
2094 | ||
2095 | if ( allChildrenSpecified ) | |
2096 | ChildChanged(*value, i, childValue); | |
2097 | n++; | |
2098 | if ( n == (unsigned int)list.GetCount() ) | |
2099 | break; | |
2100 | childValue = list[n]; | |
2101 | } | |
2102 | } | |
2103 | } | |
2104 | ||
2105 | ||
1b895132 | 2106 | void wxPGProperty::FixIndicesOfChildren( unsigned int starthere ) |
1c4293cb VZ |
2107 | { |
2108 | size_t i; | |
2109 | for ( i=starthere;i<GetChildCount();i++) | |
2110 | Item(i)->m_arrIndex = i; | |
2111 | } | |
2112 | ||
2113 | ||
2114 | // Returns (direct) child property with given name (or NULL if not found) | |
2115 | wxPGProperty* wxPGProperty::GetPropertyByName( const wxString& name ) const | |
2116 | { | |
2117 | size_t i; | |
2118 | ||
2119 | for ( i=0; i<GetChildCount(); i++ ) | |
2120 | { | |
2121 | wxPGProperty* p = Item(i); | |
2122 | if ( p->m_name == name ) | |
2123 | return p; | |
2124 | } | |
2125 | ||
2126 | // Does it have point, then? | |
2127 | int pos = name.Find(wxS('.')); | |
2128 | if ( pos <= 0 ) | |
2129 | return (wxPGProperty*) NULL; | |
2130 | ||
2131 | wxPGProperty* p = GetPropertyByName(name. substr(0,pos)); | |
2132 | ||
2133 | if ( !p || !p->GetChildCount() ) | |
2134 | return NULL; | |
2135 | ||
2136 | return p->GetPropertyByName(name.substr(pos+1,name.length()-pos-1)); | |
2137 | } | |
2138 | ||
d665918b | 2139 | wxPGProperty* wxPGProperty::GetPropertyByNameWH( const wxString& name, unsigned int hintIndex ) const |
1c4293cb VZ |
2140 | { |
2141 | unsigned int i = hintIndex; | |
2142 | ||
2143 | if ( i >= GetChildCount() ) | |
2144 | i = 0; | |
2145 | ||
2146 | unsigned int lastIndex = i - 1; | |
2147 | ||
2148 | if ( lastIndex >= GetChildCount() ) | |
2149 | lastIndex = GetChildCount() - 1; | |
2150 | ||
2151 | for (;;) | |
2152 | { | |
2153 | wxPGProperty* p = Item(i); | |
d665918b | 2154 | if ( p->m_name == name ) |
1c4293cb VZ |
2155 | return p; |
2156 | ||
2157 | if ( i == lastIndex ) | |
2158 | break; | |
2159 | ||
2160 | i++; | |
2161 | if ( i == GetChildCount() ) | |
2162 | i = 0; | |
2163 | }; | |
2164 | ||
2165 | return NULL; | |
2166 | } | |
2167 | ||
2168 | int wxPGProperty::GetChildrenHeight( int lh, int iMax_ ) const | |
2169 | { | |
2170 | // Returns height of children, recursively, and | |
2171 | // by taking expanded/collapsed status into account. | |
2172 | // | |
2173 | // iMax is used when finding property y-positions. | |
2174 | // | |
2175 | unsigned int i = 0; | |
2176 | int h = 0; | |
2177 | ||
2178 | if ( iMax_ == -1 ) | |
2179 | iMax_ = GetChildCount(); | |
2180 | ||
2181 | unsigned int iMax = iMax_; | |
2182 | ||
2183 | wxASSERT( iMax <= GetChildCount() ); | |
2184 | ||
2185 | if ( !IsExpanded() && GetParent() ) | |
2186 | return 0; | |
2187 | ||
2188 | while ( i < iMax ) | |
2189 | { | |
2190 | wxPGProperty* pwc = (wxPGProperty*) Item(i); | |
2191 | ||
2192 | if ( !pwc->HasFlag(wxPG_PROP_HIDDEN) ) | |
2193 | { | |
2194 | if ( !pwc->IsExpanded() || | |
2195 | pwc->GetChildCount() == 0 ) | |
2196 | h += lh; | |
2197 | else | |
2198 | h += pwc->GetChildrenHeight(lh) + lh; | |
2199 | } | |
2200 | ||
2201 | i++; | |
2202 | } | |
2203 | ||
2204 | return h; | |
2205 | } | |
2206 | ||
2207 | wxPGProperty* wxPGProperty::GetItemAtY( unsigned int y, unsigned int lh, unsigned int* nextItemY ) const | |
2208 | { | |
2209 | wxASSERT( nextItemY ); | |
2210 | ||
2211 | // Linear search at the moment | |
2212 | // | |
2213 | // nextItemY = y of next visible property, final value will be written back. | |
2214 | wxPGProperty* result = NULL; | |
2215 | wxPGProperty* current = NULL; | |
2216 | unsigned int iy = *nextItemY; | |
2217 | unsigned int i = 0; | |
2218 | unsigned int iMax = GetChildCount(); | |
2219 | ||
2220 | while ( i < iMax ) | |
2221 | { | |
2222 | wxPGProperty* pwc = Item(i); | |
2223 | ||
2224 | if ( !pwc->HasFlag(wxPG_PROP_HIDDEN) ) | |
2225 | { | |
2226 | // Found? | |
2227 | if ( y < iy ) | |
2228 | { | |
2229 | result = current; | |
2230 | break; | |
2231 | } | |
2232 | ||
2233 | iy += lh; | |
2234 | ||
2235 | if ( pwc->IsExpanded() && | |
2236 | pwc->GetChildCount() > 0 ) | |
2237 | { | |
2238 | result = (wxPGProperty*) pwc->GetItemAtY( y, lh, &iy ); | |
2239 | if ( result ) | |
2240 | break; | |
2241 | } | |
2242 | ||
2243 | current = pwc; | |
2244 | } | |
2245 | ||
2246 | i++; | |
2247 | } | |
2248 | ||
2249 | // Found? | |
2250 | if ( !result && y < iy ) | |
2251 | result = current; | |
2252 | ||
2253 | *nextItemY = iy; | |
2254 | ||
2255 | /* | |
2256 | if ( current ) | |
2257 | wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str()); | |
2258 | else | |
2259 | wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y); | |
2260 | */ | |
2261 | ||
2262 | return (wxPGProperty*) result; | |
2263 | } | |
2264 | ||
2265 | void wxPGProperty::Empty() | |
2266 | { | |
2267 | size_t i; | |
2268 | if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES) ) | |
2269 | { | |
2270 | for ( i=0; i<GetChildCount(); i++ ) | |
2271 | { | |
f7a094e1 | 2272 | delete m_children[i]; |
1c4293cb VZ |
2273 | } |
2274 | } | |
2275 | ||
f7a094e1 | 2276 | m_children.clear(); |
1c4293cb VZ |
2277 | } |
2278 | ||
91c818f8 JS |
2279 | void wxPGProperty::DeleteChildren() |
2280 | { | |
2281 | wxPropertyGridPageState* state = m_parentState; | |
2282 | ||
2283 | while ( GetChildCount() ) | |
2284 | { | |
2285 | wxPGProperty* child = Item(GetChildCount()-1); | |
2286 | state->DoDelete(child, true); | |
2287 | } | |
2288 | } | |
2289 | ||
1c4293cb VZ |
2290 | void wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue), |
2291 | int WXUNUSED(childIndex), | |
2292 | wxVariant& WXUNUSED(childValue) ) const | |
2293 | { | |
2294 | } | |
2295 | ||
2296 | bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const | |
2297 | { | |
2298 | unsigned int i; | |
2299 | ||
2300 | const wxVariantList* pList = NULL; | |
2301 | wxVariantList::const_iterator node; | |
2302 | ||
2303 | if ( pendingList ) | |
2304 | { | |
2305 | pList = &pendingList->GetList(); | |
2306 | node = pList->begin(); | |
2307 | } | |
2308 | ||
1c4293cb VZ |
2309 | for ( i=0; i<GetChildCount(); i++ ) |
2310 | { | |
2311 | wxPGProperty* child = Item(i); | |
2312 | const wxVariant* listValue = NULL; | |
2313 | wxVariant value; | |
2314 | ||
2315 | if ( pendingList ) | |
2316 | { | |
d665918b | 2317 | const wxString& childName = child->GetBaseName(); |
1c4293cb | 2318 | |
b7bc9d80 | 2319 | for ( ; node != pList->end(); ++node ) |
1c4293cb VZ |
2320 | { |
2321 | const wxVariant& item = *((const wxVariant*)*node); | |
d665918b | 2322 | if ( item.GetName() == childName ) |
1c4293cb VZ |
2323 | { |
2324 | listValue = &item; | |
2325 | value = item; | |
2326 | break; | |
2327 | } | |
2328 | } | |
2329 | } | |
2330 | ||
2331 | if ( !listValue ) | |
2332 | value = child->GetValue(); | |
2333 | ||
2334 | if ( value.IsNull() ) | |
2335 | return false; | |
2336 | ||
2337 | // Check recursively | |
2338 | if ( child->GetChildCount() ) | |
2339 | { | |
2340 | const wxVariant* childList = NULL; | |
2341 | ||
0372d42e | 2342 | if ( listValue && listValue->GetType() == wxPG_VARIANT_TYPE_LIST ) |
1c4293cb VZ |
2343 | childList = listValue; |
2344 | ||
2345 | if ( !child->AreAllChildrenSpecified((wxVariant*)childList) ) | |
2346 | return false; | |
2347 | } | |
2348 | } | |
2349 | ||
2350 | return true; | |
2351 | } | |
2352 | ||
2353 | wxPGProperty* wxPGProperty::UpdateParentValues() | |
2354 | { | |
2355 | wxPGProperty* parent = m_parent; | |
2356 | if ( parent && parent->HasFlag(wxPG_PROP_COMPOSED_VALUE) && | |
2357 | !parent->IsCategory() && !parent->IsRoot() ) | |
2358 | { | |
2359 | wxString s; | |
c82a80e8 | 2360 | parent->DoGenerateComposedValue(s); |
1c4293cb VZ |
2361 | parent->m_value = s; |
2362 | return parent->UpdateParentValues(); | |
2363 | } | |
2364 | return this; | |
2365 | } | |
2366 | ||
2367 | bool wxPGProperty::IsTextEditable() const | |
2368 | { | |
2369 | if ( HasFlag(wxPG_PROP_READONLY) ) | |
2370 | return false; | |
2371 | ||
2372 | if ( HasFlag(wxPG_PROP_NOEDITOR) && | |
2373 | (GetChildCount() || | |
2374 | wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button"))) | |
2375 | ) | |
2376 | return false; | |
2377 | ||
2378 | return true; | |
2379 | } | |
2380 | ||
1c4293cb VZ |
2381 | // Call after fixed sub-properties added/removed after creation. |
2382 | // if oldSelInd >= 0 and < new max items, then selection is | |
2383 | // moved to it. Note: oldSelInd -2 indicates that this property | |
2384 | // should be selected. | |
2385 | void wxPGProperty::SubPropsChanged( int oldSelInd ) | |
2386 | { | |
2387 | wxPropertyGridPageState* state = GetParentState(); | |
2388 | wxPropertyGrid* grid = state->GetGrid(); | |
2389 | ||
2fd4a524 JS |
2390 | // |
2391 | // Re-repare children (recursively) | |
2392 | for ( unsigned int i=0; i<GetChildCount(); i++ ) | |
2393 | { | |
2394 | wxPGProperty* child = Item(i); | |
2395 | child->InitAfterAdded(state, grid); | |
2396 | } | |
1c4293cb VZ |
2397 | |
2398 | wxPGProperty* sel = (wxPGProperty*) NULL; | |
f7a094e1 JS |
2399 | if ( oldSelInd >= (int)m_children.size() ) |
2400 | oldSelInd = (int)m_children.size() - 1; | |
1c4293cb VZ |
2401 | |
2402 | if ( oldSelInd >= 0 ) | |
f7a094e1 | 2403 | sel = m_children[oldSelInd]; |
1c4293cb VZ |
2404 | else if ( oldSelInd == -2 ) |
2405 | sel = this; | |
2406 | ||
2407 | if ( sel ) | |
2408 | state->DoSelectProperty(sel); | |
2409 | ||
2410 | if ( state == grid->GetState() ) | |
2411 | { | |
2412 | grid->GetPanel()->Refresh(); | |
2413 | } | |
2414 | } | |
2415 | ||
2416 | // ----------------------------------------------------------------------- | |
2417 | // wxPGRootProperty | |
2418 | // ----------------------------------------------------------------------- | |
2419 | ||
2420 | WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty,none,TextCtrl) | |
2421 | IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty, wxPGProperty) | |
2422 | ||
2423 | ||
2424 | wxPGRootProperty::wxPGRootProperty() | |
2425 | : wxPGProperty() | |
2426 | { | |
2427 | #ifdef __WXDEBUG__ | |
2428 | m_name = wxS("<root>"); | |
2429 | #endif | |
2430 | SetParentalType(0); | |
2431 | m_depth = 0; | |
2432 | } | |
2433 | ||
2434 | ||
2435 | wxPGRootProperty::~wxPGRootProperty() | |
2436 | { | |
2437 | } | |
2438 | ||
2439 | ||
2440 | // ----------------------------------------------------------------------- | |
2441 | // wxPropertyCategory | |
2442 | // ----------------------------------------------------------------------- | |
2443 | ||
2444 | WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory,none,TextCtrl) | |
2445 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory, wxPGProperty) | |
2446 | ||
2447 | void wxPropertyCategory::Init() | |
2448 | { | |
2449 | // don't set colour - prepareadditem method should do this | |
2450 | SetParentalType(wxPG_PROP_CATEGORY); | |
2451 | m_capFgColIndex = 1; | |
2452 | m_textExtent = -1; | |
2453 | } | |
2454 | ||
2455 | wxPropertyCategory::wxPropertyCategory() | |
2456 | : wxPGProperty() | |
2457 | { | |
2458 | Init(); | |
2459 | } | |
2460 | ||
2461 | ||
2462 | wxPropertyCategory::wxPropertyCategory( const wxString &label, const wxString& name ) | |
2463 | : wxPGProperty(label,name) | |
2464 | { | |
2465 | Init(); | |
2466 | } | |
2467 | ||
2468 | ||
2469 | wxPropertyCategory::~wxPropertyCategory() | |
2470 | { | |
2471 | } | |
2472 | ||
2473 | ||
1425eca5 JS |
2474 | wxString wxPropertyCategory::ValueToString( wxVariant& WXUNUSED(value), |
2475 | int WXUNUSED(argFlags) ) const | |
1c4293cb VZ |
2476 | { |
2477 | return wxEmptyString; | |
2478 | } | |
2479 | ||
2480 | int wxPropertyCategory::GetTextExtent( const wxWindow* wnd, const wxFont& font ) const | |
2481 | { | |
2482 | if ( m_textExtent > 0 ) | |
2483 | return m_textExtent; | |
2484 | int x = 0, y = 0; | |
2485 | ((wxWindow*)wnd)->GetTextExtent( m_label, &x, &y, 0, 0, &font ); | |
2486 | return x; | |
2487 | } | |
2488 | ||
2489 | void wxPropertyCategory::CalculateTextExtent( wxWindow* wnd, const wxFont& font ) | |
2490 | { | |
2491 | int x = 0, y = 0; | |
2492 | wnd->GetTextExtent( m_label, &x, &y, 0, 0, &font ); | |
2493 | m_textExtent = x; | |
2494 | } | |
2495 | ||
2496 | // ----------------------------------------------------------------------- | |
2497 | // wxPGAttributeStorage | |
2498 | // ----------------------------------------------------------------------- | |
2499 | ||
2500 | wxPGAttributeStorage::wxPGAttributeStorage() | |
2501 | { | |
2502 | } | |
2503 | ||
2504 | wxPGAttributeStorage::~wxPGAttributeStorage() | |
2505 | { | |
2506 | wxPGHashMapS2P::iterator it; | |
2507 | ||
b7bc9d80 | 2508 | for ( it = m_map.begin(); it != m_map.end(); ++it ) |
1c4293cb VZ |
2509 | { |
2510 | wxVariantData* data = (wxVariantData*) it->second; | |
2511 | data->DecRef(); | |
2512 | } | |
2513 | } | |
2514 | ||
2515 | void wxPGAttributeStorage::Set( const wxString& name, const wxVariant& value ) | |
2516 | { | |
2517 | wxVariantData* data = value.GetData(); | |
2518 | ||
2519 | // Free old, if any | |
2520 | wxPGHashMapS2P::iterator it = m_map.find(name); | |
2521 | if ( it != m_map.end() ) | |
1802a91d | 2522 | { |
1c4293cb VZ |
2523 | ((wxVariantData*)it->second)->DecRef(); |
2524 | ||
1802a91d JS |
2525 | if ( !data ) |
2526 | { | |
2527 | // If Null variant, just remove from set | |
2528 | m_map.erase(it); | |
2529 | return; | |
2530 | } | |
2531 | } | |
2532 | ||
1c4293cb | 2533 | if ( data ) |
1802a91d | 2534 | { |
1c4293cb VZ |
2535 | data->IncRef(); |
2536 | ||
1802a91d JS |
2537 | m_map[name] = data; |
2538 | } | |
1c4293cb VZ |
2539 | } |
2540 | ||
f4bc1aa2 | 2541 | #endif // wxUSE_PROPGRID |