]>
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 | { | |
1c4293cb VZ |
97 | dc.DrawText( text, |
98 | rect.x+xOffset+wxPG_XBEFORETEXT, | |
99 | rect.y+((rect.height-dc.GetCharHeight())/2) ); | |
100 | } | |
101 | ||
102 | void wxPGCellRenderer::DrawEditorValue( wxDC& dc, const wxRect& rect, | |
103 | int xOffset, const wxString& text, | |
104 | wxPGProperty* property, | |
105 | const wxPGEditor* editor ) const | |
106 | { | |
1c4293cb VZ |
107 | int yOffset = ((rect.height-dc.GetCharHeight())/2); |
108 | ||
109 | if ( editor ) | |
110 | { | |
111 | wxRect rect2(rect); | |
112 | rect2.x += xOffset; | |
113 | rect2.y += yOffset; | |
114 | rect2.height -= yOffset; | |
115 | editor->DrawValue( dc, rect2, property, text ); | |
116 | } | |
117 | else | |
118 | { | |
119 | dc.DrawText( text, | |
120 | rect.x+xOffset+wxPG_XBEFORETEXT, | |
121 | rect.y+yOffset ); | |
122 | } | |
123 | } | |
124 | ||
125 | void wxPGCellRenderer::DrawCaptionSelectionRect( wxDC& dc, int x, int y, int w, int h ) const | |
126 | { | |
127 | wxRect focusRect(x,y+((h-dc.GetCharHeight())/2),w,h); | |
128 | wxPGDrawFocusRect(dc,focusRect); | |
129 | } | |
130 | ||
131 | int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell& cell, int flags ) const | |
132 | { | |
4aee8334 | 133 | int imageWidth = 0; |
1c4293cb | 134 | |
d7e2b522 JS |
135 | // If possible, use cell colours |
136 | if ( !(flags & DontUseCellBgCol) ) | |
1c4293cb | 137 | { |
d7e2b522 JS |
138 | dc.SetPen(cell.GetBgCol()); |
139 | dc.SetBrush(cell.GetBgCol()); | |
140 | } | |
1c4293cb | 141 | |
d7e2b522 JS |
142 | if ( !(flags & DontUseCellFgCol) ) |
143 | { | |
144 | dc.SetTextForeground(cell.GetFgCol()); | |
1c4293cb VZ |
145 | } |
146 | ||
a2851207 JS |
147 | // Draw Background, but only if not rendering in control |
148 | // (as control already has rendered correct background). | |
149 | if ( !(flags & (Control|ChoicePopup)) ) | |
150 | dc.DrawRectangle(rect); | |
d7e2b522 | 151 | |
1c4293cb VZ |
152 | const wxBitmap& bmp = cell.GetBitmap(); |
153 | if ( bmp.Ok() && | |
d7e2b522 JS |
154 | // Do not draw oversized bitmap outside choice popup |
155 | ((flags & ChoicePopup) || bmp.GetHeight() < rect.height ) | |
1c4293cb VZ |
156 | ) |
157 | { | |
158 | dc.DrawBitmap( bmp, | |
159 | rect.x + wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1, | |
160 | rect.y + wxPG_CUSTOM_IMAGE_SPACINGY, | |
161 | true ); | |
4aee8334 | 162 | imageWidth = bmp.GetWidth(); |
1c4293cb VZ |
163 | } |
164 | ||
4aee8334 | 165 | return imageWidth; |
1c4293cb VZ |
166 | } |
167 | ||
168 | // ----------------------------------------------------------------------- | |
169 | // wxPGDefaultRenderer | |
170 | // ----------------------------------------------------------------------- | |
171 | ||
172 | void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect, | |
173 | const wxPropertyGrid* propertyGrid, wxPGProperty* property, | |
174 | int column, int item, int flags ) const | |
175 | { | |
176 | bool isUnspecified = property->IsValueUnspecified(); | |
177 | ||
178 | if ( column == 1 && item == -1 ) | |
179 | { | |
180 | int cmnVal = property->GetCommonValue(); | |
181 | if ( cmnVal >= 0 ) | |
182 | { | |
183 | // Common Value | |
184 | if ( !isUnspecified ) | |
185 | DrawText( dc, rect, 0, propertyGrid->GetCommonValueLabel(cmnVal) ); | |
186 | return; | |
187 | } | |
188 | } | |
189 | ||
190 | const wxPGEditor* editor = NULL; | |
d7e2b522 | 191 | const wxPGCell* cell = NULL; |
1c4293cb VZ |
192 | |
193 | wxString text; | |
4aee8334 | 194 | int imageWidth = 0; |
d7e2b522 | 195 | int preDrawFlags = flags; |
1c4293cb | 196 | |
d7e2b522 | 197 | property->GetDisplayInfo(column, item, flags, &text, &cell); |
1c4293cb | 198 | |
4aee8334 | 199 | imageWidth = PreDrawCell( dc, rect, *cell, preDrawFlags ); |
1c4293cb | 200 | |
d7e2b522 | 201 | if ( column == 1 ) |
1c4293cb VZ |
202 | { |
203 | if ( !isUnspecified ) | |
204 | { | |
205 | editor = property->GetColumnEditor(column); | |
206 | ||
207 | // Regular property value | |
208 | ||
209 | wxSize imageSize = propertyGrid->GetImageSize(property, item); | |
210 | ||
211 | wxPGPaintData paintdata; | |
212 | paintdata.m_parent = propertyGrid; | |
213 | paintdata.m_choiceItem = item; | |
214 | ||
215 | if ( imageSize.x > 0 ) | |
216 | { | |
217 | wxRect imageRect(rect.x + wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1, | |
218 | rect.y+wxPG_CUSTOM_IMAGE_SPACINGY, | |
219 | wxPG_CUSTOM_IMAGE_WIDTH, | |
220 | rect.height-(wxPG_CUSTOM_IMAGE_SPACINGY*2)); | |
221 | ||
1c4293cb VZ |
222 | dc.SetPen( wxPen(propertyGrid->GetCellTextColour(), 1, wxSOLID) ); |
223 | ||
224 | paintdata.m_drawnWidth = imageSize.x; | |
225 | paintdata.m_drawnHeight = imageSize.y; | |
226 | ||
b7bc9d80 | 227 | property->OnCustomPaint( dc, imageRect, paintdata ); |
1c4293cb | 228 | |
4aee8334 | 229 | imageWidth = paintdata.m_drawnWidth; |
1c4293cb VZ |
230 | } |
231 | ||
1425eca5 | 232 | text = property->GetValueAsString(); |
1c4293cb VZ |
233 | |
234 | // Add units string? | |
235 | if ( propertyGrid->GetColumnCount() <= 2 ) | |
236 | { | |
237 | wxString unitsString = property->GetAttribute(wxPGGlobalVars->m_strUnits, wxEmptyString); | |
238 | if ( unitsString.length() ) | |
239 | text = wxString::Format(wxS("%s %s"), text.c_str(), unitsString.c_str() ); | |
240 | } | |
241 | } | |
242 | ||
243 | if ( text.length() == 0 ) | |
244 | { | |
245 | // Try to show inline help if no text | |
246 | wxVariant vInlineHelp = property->GetAttribute(wxPGGlobalVars->m_strInlineHelp); | |
247 | if ( !vInlineHelp.IsNull() ) | |
248 | { | |
249 | text = vInlineHelp.GetString(); | |
250 | dc.SetTextForeground(propertyGrid->GetCellDisabledTextColour()); | |
251 | } | |
252 | } | |
253 | } | |
1c4293cb | 254 | |
4aee8334 JS |
255 | int imageOffset = property->GetImageOffset(imageWidth); |
256 | ||
1c4293cb VZ |
257 | DrawEditorValue( dc, rect, imageOffset, text, property, editor ); |
258 | ||
259 | // active caption gets nice dotted rectangle | |
260 | if ( property->IsCategory() /*&& column == 0*/ ) | |
261 | { | |
262 | if ( flags & Selected ) | |
263 | { | |
4aee8334 JS |
264 | if ( imageWidth > 0 ) |
265 | { | |
266 | imageOffset -= DEFAULT_IMAGE_OFFSET_INCREMENT; | |
267 | imageWidth += wxCC_CUSTOM_IMAGE_MARGIN2 + 4; | |
268 | } | |
1c4293cb VZ |
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 | ||
d3b9f782 | 405 | m_parentState = NULL; |
1c4293cb VZ |
406 | |
407 | m_clientData = NULL; | |
408 | m_clientObject = NULL; | |
409 | ||
d3b9f782 | 410 | m_customEditor = NULL; |
1c4293cb | 411 | #if wxUSE_VALIDATORS |
d3b9f782 | 412 | m_validator = NULL; |
1c4293cb | 413 | #endif |
d3b9f782 | 414 | m_valueBitmap = NULL; |
1c4293cb VZ |
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 |
48a32cf6 JS |
542 | wxASSERT_MSG( ((m_flags & wxPG_PROP_PARENTAL_FLAGS) == |
543 | wxPG_PROP_AGGREGATE) || | |
544 | ((m_flags & wxPG_PROP_PARENTAL_FLAGS) == | |
545 | wxPG_PROP_MISC_PARENT), | |
546 | "wxPGProperty parental flags set incorrectly at " | |
547 | "this time" ); | |
2fd4a524 JS |
548 | |
549 | if ( HasFlag(wxPG_PROP_AGGREGATE) ) | |
550 | { | |
551 | // Properties with private children are not expanded by default. | |
552 | SetExpanded(false); | |
553 | } | |
554 | else if ( propgrid && propgrid->HasFlag(wxPG_HIDE_MARGIN) ) | |
555 | { | |
556 | // ...unless it cannot be expanded by user and therefore must | |
557 | // remain visible at all times | |
558 | SetExpanded(true); | |
559 | } | |
560 | ||
561 | // | |
562 | // Prepare children recursively | |
563 | for ( unsigned int i=0; i<GetChildCount(); i++ ) | |
564 | { | |
565 | wxPGProperty* child = Item(i); | |
566 | child->InitAfterAdded(pageState, pageState->GetGrid()); | |
567 | } | |
568 | ||
569 | if ( propgrid && (propgrid->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES) ) | |
570 | SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED, true); | |
571 | } | |
572 | } | |
573 | ||
1c4293cb VZ |
574 | wxPGProperty::wxPGProperty() |
575 | : wxObject() | |
576 | { | |
577 | Init(); | |
578 | } | |
579 | ||
580 | ||
581 | wxPGProperty::wxPGProperty( const wxString& label, const wxString& name ) | |
582 | : wxObject() | |
583 | { | |
584 | Init( label, name ); | |
585 | } | |
586 | ||
587 | ||
588 | wxPGProperty::~wxPGProperty() | |
589 | { | |
590 | delete m_clientObject; | |
591 | ||
592 | Empty(); // this deletes items | |
593 | ||
594 | delete m_valueBitmap; | |
595 | #if wxUSE_VALIDATORS | |
596 | delete m_validator; | |
597 | #endif | |
598 | ||
1c4293cb VZ |
599 | // This makes it easier for us to detect dangling pointers |
600 | m_parent = NULL; | |
601 | } | |
602 | ||
603 | ||
604 | bool wxPGProperty::IsSomeParent( wxPGProperty* candidate ) const | |
605 | { | |
606 | wxPGProperty* parent = m_parent; | |
607 | do | |
608 | { | |
609 | if ( parent == candidate ) | |
610 | return true; | |
611 | parent = parent->m_parent; | |
612 | } while ( parent ); | |
613 | return false; | |
614 | } | |
615 | ||
616 | ||
617 | wxString wxPGProperty::GetName() const | |
618 | { | |
619 | wxPGProperty* parent = GetParent(); | |
620 | ||
621 | if ( !m_name.length() || !parent || parent->IsCategory() || parent->IsRoot() ) | |
622 | return m_name; | |
623 | ||
624 | return m_parent->GetName() + wxS(".") + m_name; | |
625 | } | |
626 | ||
627 | wxPropertyGrid* wxPGProperty::GetGrid() const | |
628 | { | |
629 | if ( !m_parentState ) | |
630 | return NULL; | |
631 | return m_parentState->GetGrid(); | |
632 | } | |
633 | ||
f7a094e1 JS |
634 | int wxPGProperty::Index( const wxPGProperty* p ) const |
635 | { | |
636 | for ( unsigned int i = 0; i<m_children.size(); i++ ) | |
637 | { | |
638 | if ( p == m_children[i] ) | |
639 | return i; | |
640 | } | |
641 | return wxNOT_FOUND; | |
642 | } | |
1c4293cb | 643 | |
1c4293cb VZ |
644 | bool wxPGProperty::ValidateValue( wxVariant& WXUNUSED(value), wxPGValidationInfo& WXUNUSED(validationInfo) ) const |
645 | { | |
646 | return true; | |
647 | } | |
648 | ||
649 | void wxPGProperty::OnSetValue() | |
650 | { | |
651 | } | |
652 | ||
653 | void wxPGProperty::RefreshChildren () | |
654 | { | |
655 | } | |
656 | ||
d8812c6e JS |
657 | void wxPGProperty::OnValidationFailure( wxVariant& WXUNUSED(pendingValue) ) |
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 | 961 | |
4b6a582b VZ |
962 | wxLogTrace("propgrid", |
963 | wxT(">> %s.StringToValue('%s')"), GetLabel(), text); | |
1c4293cb VZ |
964 | |
965 | wxString::const_iterator it = text.begin(); | |
966 | wxUniChar a; | |
967 | ||
968 | if ( it != text.end() ) | |
969 | a = *it; | |
970 | else | |
971 | a = 0; | |
972 | ||
973 | for ( ;; ) | |
974 | { | |
a64a1bf7 JS |
975 | // How many units we iterate string forward at the end of loop? |
976 | // We need to keep track of this or risk going to negative | |
977 | // with it-- operation. | |
978 | unsigned int strPosIncrement = 1; | |
979 | ||
1c4293cb VZ |
980 | if ( tokenStart != 0xFFFFFF ) |
981 | { | |
982 | // Token is running | |
983 | if ( a == delimeter || a == 0 ) | |
984 | { | |
985 | token = text.substr(tokenStart,pos-tokenStart); | |
986 | token.Trim(true); | |
987 | size_t len = token.length(); | |
988 | ||
989 | if ( !addOnlyIfNotEmpty || len > 0 ) | |
990 | { | |
991 | const wxPGProperty* child = Item(curChild); | |
f275b5db | 992 | wxVariant variant(child->GetValue()); |
ae82388e | 993 | wxString childName = child->GetBaseName(); |
f275b5db | 994 | |
4b6a582b VZ |
995 | wxLogTrace("propgrid", |
996 | wxT("token = '%s', child = %s"), | |
997 | token, childName); | |
1c4293cb | 998 | |
f275b5db JS |
999 | // Add only if editable or setting programmatically |
1000 | if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) || | |
1001 | !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) ) | |
1c4293cb | 1002 | { |
f275b5db | 1003 | if ( len > 0 ) |
1c4293cb | 1004 | { |
ae82388e JS |
1005 | if ( child->StringToValue(variant, token, |
1006 | propagatedFlags|wxPG_COMPOSITE_FRAGMENT) ) | |
1c4293cb | 1007 | { |
ae82388e JS |
1008 | // We really need to set the variant's name |
1009 | // *after* child->StringToValue() has been | |
1010 | // called, since variant's value may be set by | |
1011 | // assigning another variant into it, which | |
1012 | // then usually causes name to be copied (ie. | |
1013 | // usually cleared) as well. wxBoolProperty | |
1014 | // being case in point with its use of | |
1015 | // wxPGVariant_Bool macro as an optimization. | |
1016 | variant.SetName(childName); | |
f275b5db | 1017 | list.Append(variant); |
1c4293cb | 1018 | |
f275b5db JS |
1019 | changed = true; |
1020 | } | |
1021 | } | |
1022 | else | |
1023 | { | |
1024 | // Empty, becomes unspecified | |
1025 | variant.MakeNull(); | |
ae82388e | 1026 | variant.SetName(childName); |
f275b5db | 1027 | list.Append(variant); |
1c4293cb VZ |
1028 | changed = true; |
1029 | } | |
1030 | } | |
1c4293cb VZ |
1031 | |
1032 | curChild++; | |
1033 | if ( curChild >= iMax ) | |
1034 | break; | |
1035 | } | |
1036 | ||
1037 | tokenStart = 0xFFFFFF; | |
1038 | } | |
1039 | } | |
1040 | else | |
1041 | { | |
1042 | // Token is not running | |
1043 | if ( a != wxS(' ') ) | |
1044 | { | |
1045 | ||
1046 | addOnlyIfNotEmpty = false; | |
1047 | ||
1048 | // Is this a group of tokens? | |
1049 | if ( a == wxS('[') ) | |
1050 | { | |
1051 | int depth = 1; | |
1052 | ||
b7bc9d80 | 1053 | if ( it != text.end() ) ++it; |
1c4293cb VZ |
1054 | pos++; |
1055 | size_t startPos = pos; | |
1056 | ||
1057 | // Group item - find end | |
1058 | while ( it != text.end() && depth > 0 ) | |
1059 | { | |
1060 | a = *it; | |
b7bc9d80 | 1061 | ++it; |
1c4293cb VZ |
1062 | pos++; |
1063 | ||
1064 | if ( a == wxS(']') ) | |
1065 | depth--; | |
1066 | else if ( a == wxS('[') ) | |
1067 | depth++; | |
1068 | } | |
1069 | ||
1070 | token = text.substr(startPos,pos-startPos-1); | |
1071 | ||
1072 | if ( !token.length() ) | |
1073 | break; | |
1074 | ||
1075 | const wxPGProperty* child = Item(curChild); | |
1076 | ||
2bbd3749 JS |
1077 | wxVariant oldChildValue = child->GetValue(); |
1078 | wxVariant variant(oldChildValue); | |
f275b5db JS |
1079 | |
1080 | if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) || | |
1081 | !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) ) | |
1c4293cb | 1082 | { |
a64a1bf7 JS |
1083 | wxString childName = child->GetBaseName(); |
1084 | ||
1085 | bool stvRes = child->StringToValue( variant, token, | |
1086 | propagatedFlags ); | |
f275b5db JS |
1087 | if ( stvRes || (variant != oldChildValue) ) |
1088 | { | |
a64a1bf7 JS |
1089 | variant.SetName(childName); |
1090 | list.Append(variant); | |
1091 | ||
1092 | changed = true; | |
f275b5db JS |
1093 | } |
1094 | else | |
1095 | { | |
a64a1bf7 | 1096 | // No changes... |
f275b5db | 1097 | } |
1c4293cb VZ |
1098 | } |
1099 | ||
1100 | curChild++; | |
1101 | if ( curChild >= iMax ) | |
1102 | break; | |
1103 | ||
1104 | addOnlyIfNotEmpty = true; | |
1105 | ||
1106 | tokenStart = 0xFFFFFF; | |
1107 | } | |
1108 | else | |
1109 | { | |
1110 | tokenStart = pos; | |
1111 | ||
1112 | if ( a == delimeter ) | |
a64a1bf7 | 1113 | strPosIncrement -= 1; |
1c4293cb VZ |
1114 | } |
1115 | } | |
1116 | } | |
1117 | ||
1118 | if ( a == 0 ) | |
1119 | break; | |
1120 | ||
a64a1bf7 JS |
1121 | it += strPosIncrement; |
1122 | ||
1c4293cb VZ |
1123 | if ( it != text.end() ) |
1124 | { | |
1125 | a = *it; | |
1126 | } | |
1127 | else | |
1128 | { | |
1129 | a = 0; | |
1130 | } | |
a64a1bf7 JS |
1131 | |
1132 | pos += strPosIncrement; | |
1c4293cb VZ |
1133 | } |
1134 | ||
1135 | if ( changed ) | |
1136 | variant = list; | |
1137 | ||
1138 | return changed; | |
1139 | } | |
1140 | ||
1141 | bool wxPGProperty::SetValueFromString( const wxString& text, int argFlags ) | |
1142 | { | |
1143 | wxVariant variant(m_value); | |
1144 | bool res = StringToValue(variant, text, argFlags); | |
1145 | if ( res ) | |
1146 | SetValue(variant); | |
1147 | return res; | |
1148 | } | |
1149 | ||
1150 | bool wxPGProperty::SetValueFromInt( long number, int argFlags ) | |
1151 | { | |
1152 | wxVariant variant(m_value); | |
1153 | bool res = IntToValue(variant, number, argFlags); | |
1154 | if ( res ) | |
1155 | SetValue(variant); | |
1156 | return res; | |
1157 | } | |
1158 | ||
1159 | wxSize wxPGProperty::OnMeasureImage( int WXUNUSED(item) ) const | |
1160 | { | |
1161 | if ( m_valueBitmap ) | |
1162 | return wxSize(m_valueBitmap->GetWidth(),-1); | |
1163 | ||
1164 | return wxSize(0,0); | |
1165 | } | |
1166 | ||
4aee8334 JS |
1167 | int wxPGProperty::GetImageOffset( int imageWidth ) const |
1168 | { | |
1169 | int imageOffset = 0; | |
1170 | ||
1171 | if ( imageWidth ) | |
1172 | { | |
1173 | // Do not increment offset too much for wide images | |
1174 | if ( imageWidth <= (wxPG_CUSTOM_IMAGE_WIDTH+5) ) | |
1175 | imageOffset = imageWidth + DEFAULT_IMAGE_OFFSET_INCREMENT; | |
1176 | else | |
1177 | imageOffset = imageWidth + 1; | |
1178 | } | |
1179 | ||
1180 | return imageOffset; | |
1181 | } | |
1182 | ||
1c4293cb VZ |
1183 | wxPGCellRenderer* wxPGProperty::GetCellRenderer( int WXUNUSED(column) ) const |
1184 | { | |
1185 | return wxPGGlobalVars->m_defaultRenderer; | |
1186 | } | |
1187 | ||
1188 | void wxPGProperty::OnCustomPaint( wxDC& dc, | |
1189 | const wxRect& rect, | |
1190 | wxPGPaintData& ) | |
1191 | { | |
1192 | wxBitmap* bmp = m_valueBitmap; | |
1193 | ||
1194 | wxCHECK_RET( bmp && bmp->Ok(), wxT("invalid bitmap") ); | |
1195 | ||
1196 | wxCHECK_RET( rect.x >= 0, wxT("unexpected measure call") ); | |
1197 | ||
1198 | dc.DrawBitmap(*bmp,rect.x,rect.y); | |
1199 | } | |
1200 | ||
1201 | const wxPGEditor* wxPGProperty::DoGetEditorClass() const | |
1202 | { | |
c26873c8 | 1203 | return wxPGEditor_TextCtrl; |
1c4293cb VZ |
1204 | } |
1205 | ||
1206 | // Default extra property event handling - that is, none at all. | |
1207 | bool wxPGProperty::OnEvent( wxPropertyGrid*, wxWindow*, wxEvent& ) | |
1208 | { | |
1209 | return false; | |
1210 | } | |
1211 | ||
1212 | ||
1213 | void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags ) | |
1214 | { | |
104837f2 JS |
1215 | // If auto unspecified values are not wanted (via window or property style), |
1216 | // then get default value instead of wxNullVariant. | |
1217 | if ( value.IsNull() && (flags & wxPG_SETVAL_BY_USER) && | |
1218 | !UsesAutoUnspecified() ) | |
1219 | { | |
1220 | value = GetDefaultValue(); | |
1221 | } | |
1222 | ||
1c4293cb VZ |
1223 | if ( !value.IsNull() ) |
1224 | { | |
8f18b252 JS |
1225 | wxVariant tempListVariant; |
1226 | ||
1c4293cb VZ |
1227 | SetCommonValue(-1); |
1228 | // List variants are reserved a special purpose | |
1229 | // as intermediate containers for child values | |
1230 | // of properties with children. | |
0372d42e | 1231 | if ( value.GetType() == wxPG_VARIANT_TYPE_LIST ) |
1c4293cb | 1232 | { |
8f18b252 JS |
1233 | // |
1234 | // However, situation is different for composed string properties | |
1235 | if ( HasFlag(wxPG_PROP_COMPOSED_VALUE) ) | |
1236 | { | |
1237 | tempListVariant = value; | |
1238 | pList = &tempListVariant; | |
1239 | } | |
1240 | ||
1c4293cb VZ |
1241 | wxVariant newValue; |
1242 | AdaptListToValue(value, &newValue); | |
1243 | value = newValue; | |
1244 | //wxLogDebug(wxT(">> %s.SetValue() adapted list value to type '%s'"),GetName().c_str(),value.GetType().c_str()); | |
1245 | } | |
1246 | ||
1247 | if ( HasFlag( wxPG_PROP_AGGREGATE) ) | |
1248 | flags |= wxPG_SETVAL_AGGREGATED; | |
1249 | ||
1250 | if ( pList && !pList->IsNull() ) | |
1251 | { | |
0372d42e | 1252 | wxASSERT( pList->GetType() == wxPG_VARIANT_TYPE_LIST ); |
1c4293cb VZ |
1253 | wxASSERT( GetChildCount() ); |
1254 | wxASSERT( !IsCategory() ); | |
1255 | ||
1256 | wxVariantList& list = pList->GetList(); | |
1257 | wxVariantList::iterator node; | |
1258 | unsigned int i = 0; | |
1259 | ||
1260 | //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str()); | |
1261 | ||
1262 | // Children in list can be in any order, but we will give hint to | |
d665918b | 1263 | // GetPropertyByNameWH(). This optimizes for full list parsing. |
b7bc9d80 | 1264 | for ( node = list.begin(); node != list.end(); ++node ) |
1c4293cb VZ |
1265 | { |
1266 | wxVariant& childValue = *((wxVariant*)*node); | |
d665918b | 1267 | wxPGProperty* child = GetPropertyByNameWH(childValue.GetName(), i); |
1c4293cb VZ |
1268 | if ( child ) |
1269 | { | |
d665918b | 1270 | //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str()); |
0372d42e | 1271 | if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST ) |
1c4293cb VZ |
1272 | { |
1273 | if ( child->HasFlag(wxPG_PROP_AGGREGATE) && !(flags & wxPG_SETVAL_AGGREGATED) ) | |
1274 | { | |
1275 | wxVariant listRefCopy = childValue; | |
1276 | child->SetValue(childValue, &listRefCopy, flags|wxPG_SETVAL_FROM_PARENT); | |
1277 | } | |
1278 | else | |
1279 | { | |
1280 | wxVariant oldVal = child->GetValue(); | |
1281 | child->SetValue(oldVal, &childValue, flags|wxPG_SETVAL_FROM_PARENT); | |
1282 | } | |
1283 | } | |
0372d42e | 1284 | else if ( child->GetValue() != childValue ) |
1c4293cb VZ |
1285 | { |
1286 | // For aggregate properties, we will trust RefreshChildren() | |
1287 | // to update child values. | |
1288 | if ( !HasFlag(wxPG_PROP_AGGREGATE) ) | |
1289 | child->SetValue(childValue, NULL, flags|wxPG_SETVAL_FROM_PARENT); | |
8f18b252 JS |
1290 | if ( flags & wxPG_SETVAL_BY_USER ) |
1291 | child->SetFlag(wxPG_PROP_MODIFIED); | |
1c4293cb VZ |
1292 | } |
1293 | } | |
1294 | i++; | |
1295 | } | |
1296 | } | |
1297 | ||
1298 | if ( !value.IsNull() ) | |
1299 | { | |
0372d42e | 1300 | m_value = value; |
1c4293cb | 1301 | OnSetValue(); |
1c4293cb VZ |
1302 | } |
1303 | ||
8f18b252 | 1304 | if ( flags & wxPG_SETVAL_BY_USER ) |
1c4293cb VZ |
1305 | SetFlag(wxPG_PROP_MODIFIED); |
1306 | ||
1307 | if ( HasFlag(wxPG_PROP_AGGREGATE) ) | |
1308 | RefreshChildren(); | |
1309 | } | |
1310 | else | |
1311 | { | |
1312 | if ( m_commonValue != -1 ) | |
1313 | { | |
1314 | wxPropertyGrid* pg = GetGrid(); | |
1315 | if ( !pg || m_commonValue != pg->GetUnspecifiedCommonValue() ) | |
1316 | SetCommonValue(-1); | |
1317 | } | |
1318 | ||
1319 | m_value = value; | |
1320 | ||
1321 | // Set children to unspecified, but only if aggregate or | |
1322 | // value is <composed> | |
1323 | if ( AreChildrenComponents() ) | |
1324 | { | |
1325 | unsigned int i; | |
1326 | for ( i=0; i<GetChildCount(); i++ ) | |
1327 | Item(i)->SetValue(value, NULL, flags|wxPG_SETVAL_FROM_PARENT); | |
1328 | } | |
1329 | } | |
1330 | ||
daeb4e4d JS |
1331 | if ( !(flags & wxPG_SETVAL_FROM_PARENT) ) |
1332 | UpdateParentValues(); | |
1333 | ||
1c4293cb VZ |
1334 | // |
1335 | // Update editor control | |
1336 | // | |
1337 | ||
1338 | // We need to check for these, otherwise GetGrid() may fail. | |
1339 | if ( flags & wxPG_SETVAL_REFRESH_EDITOR ) | |
e777bd14 | 1340 | { |
1c4293cb | 1341 | RefreshEditor(); |
e777bd14 JS |
1342 | wxPropertyGrid* pg = GetGridIfDisplayed(); |
1343 | if ( pg ) | |
1344 | pg->DrawItemAndValueRelated(this); | |
1345 | } | |
1c4293cb VZ |
1346 | } |
1347 | ||
1348 | ||
1349 | void wxPGProperty::SetValueInEvent( wxVariant value ) const | |
1350 | { | |
1351 | GetGrid()->ValueChangeInEvent(value); | |
1352 | } | |
1353 | ||
1354 | void wxPGProperty::SetFlagRecursively( FlagType flag, bool set ) | |
1355 | { | |
d58526d5 | 1356 | ChangeFlag(flag, set); |
1c4293cb VZ |
1357 | |
1358 | unsigned int i; | |
1359 | for ( i = 0; i < GetChildCount(); i++ ) | |
1360 | Item(i)->SetFlagRecursively(flag, set); | |
1361 | } | |
1362 | ||
1363 | void wxPGProperty::RefreshEditor() | |
1364 | { | |
f521bae6 JS |
1365 | if ( !m_parent ) |
1366 | return; | |
1c4293cb | 1367 | |
f521bae6 JS |
1368 | wxPropertyGrid* pg = GetGrid(); |
1369 | if ( pg && pg->GetSelectedProperty() == this ) | |
a6353fe8 | 1370 | pg->RefreshEditor(); |
f521bae6 | 1371 | } |
1c4293cb VZ |
1372 | |
1373 | wxVariant wxPGProperty::GetDefaultValue() const | |
1374 | { | |
0ce8e27f | 1375 | wxVariant defVal = GetAttribute(wxPG_ATTR_DEFAULT_VALUE); |
1c4293cb VZ |
1376 | if ( !defVal.IsNull() ) |
1377 | return defVal; | |
1378 | ||
1379 | wxVariant value = GetValue(); | |
1380 | ||
1381 | if ( !value.IsNull() ) | |
1382 | { | |
0372d42e JS |
1383 | wxString valueType(value.GetType()); |
1384 | ||
1385 | if ( valueType == wxPG_VARIANT_TYPE_LONG ) | |
1c4293cb | 1386 | return wxPGVariant_Zero; |
0372d42e | 1387 | if ( valueType == wxPG_VARIANT_TYPE_STRING ) |
1c4293cb | 1388 | return wxPGVariant_EmptyString; |
0372d42e | 1389 | if ( valueType == wxPG_VARIANT_TYPE_BOOL ) |
1c4293cb | 1390 | return wxPGVariant_False; |
0372d42e | 1391 | if ( valueType == wxPG_VARIANT_TYPE_DOUBLE ) |
1c4293cb | 1392 | return wxVariant(0.0); |
0372d42e | 1393 | if ( valueType == wxPG_VARIANT_TYPE_ARRSTRING ) |
1c4293cb | 1394 | return wxVariant(wxArrayString()); |
0372d42e JS |
1395 | if ( valueType == wxS("wxLongLong") ) |
1396 | return WXVARIANT(wxLongLong(0)); | |
1397 | if ( valueType == wxS("wxULongLong") ) | |
1398 | return WXVARIANT(wxULongLong(0)); | |
1399 | if ( valueType == wxS("wxColour") ) | |
1400 | return WXVARIANT(*wxBLACK); | |
1c4293cb | 1401 | #if wxUSE_DATETIME |
0372d42e | 1402 | if ( valueType == wxPG_VARIANT_TYPE_DATETIME ) |
1c4293cb VZ |
1403 | return wxVariant(wxDateTime::Now()); |
1404 | #endif | |
0372d42e JS |
1405 | if ( valueType == wxS("wxFont") ) |
1406 | return WXVARIANT(*wxNORMAL_FONT); | |
1407 | if ( valueType == wxS("wxPoint") ) | |
1408 | return WXVARIANT(wxPoint(0, 0)); | |
1409 | if ( valueType == wxS("wxSize") ) | |
1410 | return WXVARIANT(wxSize(0, 0)); | |
1c4293cb VZ |
1411 | } |
1412 | ||
1413 | return wxVariant(); | |
1414 | } | |
1415 | ||
d7e2b522 JS |
1416 | void wxPGProperty::EnsureCells( unsigned int column ) |
1417 | { | |
1418 | if ( column >= m_cells.size() ) | |
1419 | { | |
1420 | // Fill empty slots with default cells | |
1421 | wxPropertyGrid* pg = GetGrid(); | |
1422 | wxPGCell defaultCell; | |
1423 | ||
1424 | if ( !HasFlag(wxPG_PROP_CATEGORY) ) | |
1425 | defaultCell = pg->GetPropertyDefaultCell(); | |
1426 | else | |
1427 | defaultCell = pg->GetCategoryDefaultCell(); | |
1428 | ||
1429 | // TODO: Replace with resize() call | |
1430 | unsigned int cellCountMax = column+1; | |
1431 | ||
1432 | for ( unsigned int i=m_cells.size(); i<cellCountMax; i++ ) | |
1433 | m_cells.push_back(defaultCell); | |
1434 | } | |
1435 | } | |
1436 | ||
1437 | void wxPGProperty::SetCell( int column, | |
1438 | const wxPGCell& cell ) | |
1439 | { | |
1440 | EnsureCells(column); | |
1441 | ||
1442 | m_cells[column] = cell; | |
1443 | } | |
1444 | ||
1445 | void wxPGProperty::AdaptiveSetCell( unsigned int firstCol, | |
1446 | unsigned int lastCol, | |
1447 | const wxPGCell& cell, | |
1448 | const wxPGCell& srcData, | |
1449 | wxPGCellData* unmodCellData, | |
1450 | FlagType ignoreWithFlags, | |
1451 | bool recursively ) | |
1452 | { | |
1453 | // | |
1454 | // Sets cell in memory optimizing fashion. That is, if | |
1455 | // current cell data matches unmodCellData, we will | |
1456 | // simply get reference to data from cell. Otherwise, | |
1457 | // cell information from srcData is merged into current. | |
1458 | // | |
1459 | ||
1460 | if ( !(m_flags & ignoreWithFlags) && !IsRoot() ) | |
1461 | { | |
1462 | EnsureCells(lastCol); | |
1463 | ||
1464 | for ( unsigned int col=firstCol; col<=lastCol; col++ ) | |
1465 | { | |
1466 | if ( m_cells[col].GetData() == unmodCellData ) | |
1467 | { | |
1468 | // Data matches... use cell directly | |
1469 | m_cells[col] = cell; | |
1470 | } | |
1471 | else | |
1472 | { | |
1473 | // Data did not match... merge valid information | |
1474 | m_cells[col].MergeFrom(srcData); | |
1475 | } | |
1476 | } | |
1477 | } | |
1478 | ||
1479 | if ( recursively ) | |
1480 | { | |
1481 | for ( unsigned int i=0; i<GetChildCount(); i++ ) | |
1482 | Item(i)->AdaptiveSetCell( firstCol, | |
1483 | lastCol, | |
1484 | cell, | |
1485 | srcData, | |
1486 | unmodCellData, | |
1487 | ignoreWithFlags, | |
1488 | recursively ); | |
1489 | } | |
1490 | } | |
1491 | ||
1492 | const wxPGCell& wxPGProperty::GetCell( unsigned int column ) const | |
1c4293cb | 1493 | { |
d7e2b522 JS |
1494 | if ( m_cells.size() > column ) |
1495 | return m_cells[column]; | |
1496 | ||
1497 | wxPropertyGrid* pg = GetGrid(); | |
1498 | ||
1499 | if ( IsCategory() ) | |
1500 | return pg->GetCategoryDefaultCell(); | |
1501 | ||
1502 | return pg->GetPropertyDefaultCell(); | |
1503 | } | |
1504 | ||
1505 | wxPGCell& wxPGProperty::GetCell( unsigned int column ) | |
1506 | { | |
1507 | EnsureCells(column); | |
1508 | return m_cells[column]; | |
1509 | } | |
1510 | ||
1511 | void wxPGProperty::SetBackgroundColour( const wxColour& colour, | |
1512 | bool recursively ) | |
1513 | { | |
1514 | wxPGProperty* firstProp = this; | |
1515 | ||
1516 | // | |
1517 | // If category is tried to set recursively, skip it and only | |
1518 | // affect the children. | |
1519 | if ( recursively ) | |
1520 | { | |
1521 | while ( firstProp->IsCategory() ) | |
1522 | { | |
1523 | if ( !firstProp->GetChildCount() ) | |
1524 | return; | |
1525 | firstProp = firstProp->Item(0); | |
1526 | } | |
1527 | } | |
1528 | ||
1529 | wxPGCell& firstCell = firstProp->GetCell(0); | |
1530 | wxPGCellData* firstCellData = firstCell.GetData(); | |
1531 | ||
1532 | wxPGCell newCell(firstCell); | |
1533 | newCell.SetBgCol(colour); | |
1534 | wxPGCell srcCell; | |
1535 | srcCell.SetBgCol(colour); | |
1536 | ||
1537 | AdaptiveSetCell( 0, | |
1538 | GetParentState()->GetColumnCount()-1, | |
1539 | newCell, | |
1540 | srcCell, | |
1541 | firstCellData, | |
1542 | recursively ? wxPG_PROP_CATEGORY : 0, | |
1543 | recursively ); | |
1544 | } | |
1545 | ||
1546 | void wxPGProperty::SetTextColour( const wxColour& colour, | |
1547 | bool recursively ) | |
1548 | { | |
1549 | wxPGProperty* firstProp = this; | |
1550 | ||
1551 | // | |
1552 | // If category is tried to set recursively, skip it and only | |
1553 | // affect the children. | |
1554 | if ( recursively ) | |
1555 | { | |
1556 | while ( firstProp->IsCategory() ) | |
1557 | { | |
1558 | if ( !firstProp->GetChildCount() ) | |
1559 | return; | |
1560 | firstProp = firstProp->Item(0); | |
1561 | } | |
1562 | } | |
1c4293cb | 1563 | |
d7e2b522 JS |
1564 | wxPGCell& firstCell = firstProp->GetCell(0); |
1565 | wxPGCellData* firstCellData = firstCell.GetData(); | |
1566 | ||
1567 | wxPGCell newCell(firstCell); | |
1568 | newCell.SetFgCol(colour); | |
1569 | wxPGCell srcCell; | |
1570 | srcCell.SetFgCol(colour); | |
1571 | ||
1572 | AdaptiveSetCell( 0, | |
1573 | GetParentState()->GetColumnCount()-1, | |
1574 | newCell, | |
1575 | srcCell, | |
1576 | firstCellData, | |
1577 | recursively ? wxPG_PROP_CATEGORY : 0, | |
1578 | recursively ); | |
1c4293cb VZ |
1579 | } |
1580 | ||
1c4293cb VZ |
1581 | wxPGEditorDialogAdapter* wxPGProperty::GetEditorDialog() const |
1582 | { | |
1583 | return NULL; | |
1584 | } | |
1585 | ||
1586 | bool wxPGProperty::DoSetAttribute( const wxString& WXUNUSED(name), wxVariant& WXUNUSED(value) ) | |
1587 | { | |
1588 | return false; | |
1589 | } | |
1590 | ||
1591 | void wxPGProperty::SetAttribute( const wxString& name, wxVariant value ) | |
1592 | { | |
1593 | if ( DoSetAttribute( name, value ) ) | |
1594 | { | |
1595 | // Support working without grid, when possible | |
1596 | if ( wxPGGlobalVars->HasExtraStyle( wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES ) ) | |
1597 | return; | |
1598 | } | |
1599 | ||
1600 | m_attributes.Set( name, value ); | |
1601 | } | |
1602 | ||
1603 | void wxPGProperty::SetAttributes( const wxPGAttributeStorage& attributes ) | |
1604 | { | |
1605 | wxPGAttributeStorage::const_iterator it = attributes.StartIteration(); | |
1606 | wxVariant variant; | |
1607 | ||
1608 | while ( attributes.GetNext(it, variant) ) | |
1609 | SetAttribute( variant.GetName(), variant ); | |
1610 | } | |
1611 | ||
1612 | wxVariant wxPGProperty::DoGetAttribute( const wxString& WXUNUSED(name) ) const | |
1613 | { | |
1614 | return wxVariant(); | |
1615 | } | |
1616 | ||
1617 | ||
1618 | wxVariant wxPGProperty::GetAttribute( const wxString& name ) const | |
1619 | { | |
1620 | return m_attributes.FindValue(name); | |
1621 | } | |
1622 | ||
1623 | wxString wxPGProperty::GetAttribute( const wxString& name, const wxString& defVal ) const | |
1624 | { | |
1625 | wxVariant variant = m_attributes.FindValue(name); | |
1626 | ||
1627 | if ( !variant.IsNull() ) | |
1628 | return variant.GetString(); | |
1629 | ||
1630 | return defVal; | |
1631 | } | |
1632 | ||
1633 | long wxPGProperty::GetAttributeAsLong( const wxString& name, long defVal ) const | |
1634 | { | |
1635 | wxVariant variant = m_attributes.FindValue(name); | |
1636 | ||
4e00b908 JS |
1637 | if ( variant.IsNull() ) |
1638 | return defVal; | |
1639 | ||
1640 | return variant.GetLong(); | |
1c4293cb VZ |
1641 | } |
1642 | ||
1643 | double wxPGProperty::GetAttributeAsDouble( const wxString& name, double defVal ) const | |
1644 | { | |
1c4293cb VZ |
1645 | wxVariant variant = m_attributes.FindValue(name); |
1646 | ||
4e00b908 JS |
1647 | if ( variant.IsNull() ) |
1648 | return defVal; | |
1c4293cb | 1649 | |
4e00b908 | 1650 | return variant.GetDouble(); |
1c4293cb VZ |
1651 | } |
1652 | ||
1653 | wxVariant wxPGProperty::GetAttributesAsList() const | |
1654 | { | |
1655 | wxVariantList tempList; | |
1656 | wxVariant v( tempList, wxString::Format(wxS("@%s@attr"),m_name.c_str()) ); | |
1657 | ||
1658 | wxPGAttributeStorage::const_iterator it = m_attributes.StartIteration(); | |
1659 | wxVariant variant; | |
1660 | ||
1661 | while ( m_attributes.GetNext(it, variant) ) | |
1662 | v.Append(variant); | |
1663 | ||
1664 | return v; | |
1665 | } | |
1666 | ||
1667 | // Slots of utility flags are NULL | |
1668 | const unsigned int gs_propFlagToStringSize = 14; | |
1669 | ||
1670 | static const wxChar* gs_propFlagToString[gs_propFlagToStringSize] = { | |
1671 | NULL, | |
1672 | wxT("DISABLED"), | |
1673 | wxT("HIDDEN"), | |
1674 | NULL, | |
1675 | wxT("NOEDITOR"), | |
1676 | wxT("COLLAPSED"), | |
1677 | NULL, | |
1678 | NULL, | |
1679 | NULL, | |
1680 | NULL, | |
1681 | NULL, | |
1682 | NULL, | |
1683 | NULL, | |
1684 | NULL | |
1685 | }; | |
1686 | ||
1687 | wxString wxPGProperty::GetFlagsAsString( FlagType flagsMask ) const | |
1688 | { | |
1689 | wxString s; | |
1690 | int relevantFlags = m_flags & flagsMask & wxPG_STRING_STORED_FLAGS; | |
1691 | FlagType a = 1; | |
1692 | ||
1693 | unsigned int i = 0; | |
1694 | for ( i=0; i<gs_propFlagToStringSize; i++ ) | |
1695 | { | |
1696 | if ( relevantFlags & a ) | |
1697 | { | |
1698 | const wxChar* fs = gs_propFlagToString[i]; | |
1699 | wxASSERT(fs); | |
1700 | if ( s.length() ) | |
1701 | s << wxS("|"); | |
1702 | s << fs; | |
1703 | } | |
1704 | a = a << 1; | |
1705 | } | |
1706 | ||
1707 | return s; | |
1708 | } | |
1709 | ||
1710 | void wxPGProperty::SetFlagsFromString( const wxString& str ) | |
1711 | { | |
1712 | FlagType flags = 0; | |
1713 | ||
1714 | WX_PG_TOKENIZER1_BEGIN(str, wxS('|')) | |
1715 | unsigned int i; | |
1716 | for ( i=0; i<gs_propFlagToStringSize; i++ ) | |
1717 | { | |
1718 | const wxChar* fs = gs_propFlagToString[i]; | |
1719 | if ( fs && str == fs ) | |
1720 | { | |
1721 | flags |= (1<<i); | |
1722 | break; | |
1723 | } | |
1724 | } | |
1725 | WX_PG_TOKENIZER1_END() | |
1726 | ||
1727 | m_flags = (m_flags & ~wxPG_STRING_STORED_FLAGS) | flags; | |
1728 | } | |
1729 | ||
1730 | wxValidator* wxPGProperty::DoGetValidator() const | |
1731 | { | |
d3b9f782 | 1732 | return NULL; |
1c4293cb VZ |
1733 | } |
1734 | ||
939d9364 | 1735 | int wxPGProperty::InsertChoice( const wxString& label, int index, int value ) |
1c4293cb | 1736 | { |
939d9364 JS |
1737 | wxPropertyGrid* pg = GetGrid(); |
1738 | int sel = GetChoiceSelection(); | |
1739 | ||
1740 | int newSel = sel; | |
1741 | ||
1742 | if ( index == wxNOT_FOUND ) | |
1743 | index = m_choices.GetCount(); | |
1744 | ||
1745 | if ( index <= sel ) | |
1746 | newSel++; | |
1747 | ||
1748 | m_choices.Insert(label, index, value); | |
1749 | ||
1750 | if ( sel != newSel ) | |
1751 | SetChoiceSelection(newSel); | |
1752 | ||
1753 | if ( this == pg->GetSelection() ) | |
1754 | GetEditorClass()->InsertItem(pg->GetEditorControl(),label,index); | |
1755 | ||
1756 | return index; | |
1c4293cb VZ |
1757 | } |
1758 | ||
939d9364 JS |
1759 | |
1760 | void wxPGProperty::DeleteChoice( int index ) | |
1c4293cb | 1761 | { |
939d9364 JS |
1762 | wxPropertyGrid* pg = GetGrid(); |
1763 | ||
1764 | int sel = GetChoiceSelection(); | |
1765 | int newSel = sel; | |
1766 | ||
1767 | // Adjust current value | |
1768 | if ( sel == index ) | |
1769 | { | |
1770 | SetValueToUnspecified(); | |
1771 | newSel = 0; | |
1772 | } | |
1773 | else if ( index < sel ) | |
1774 | { | |
1775 | newSel--; | |
1776 | } | |
1777 | ||
1778 | m_choices.RemoveAt(index); | |
1779 | ||
1780 | if ( sel != newSel ) | |
1781 | SetChoiceSelection(newSel); | |
1782 | ||
1783 | if ( this == pg->GetSelection() ) | |
1784 | GetEditorClass()->DeleteItem(pg->GetEditorControl(), index); | |
1c4293cb VZ |
1785 | } |
1786 | ||
939d9364 | 1787 | int wxPGProperty::GetChoiceSelection() const |
1c4293cb | 1788 | { |
939d9364 JS |
1789 | wxVariant value = GetValue(); |
1790 | wxString valueType = value.GetType(); | |
1791 | int index = wxNOT_FOUND; | |
1792 | ||
1793 | if ( IsValueUnspecified() || !m_choices.GetCount() ) | |
1794 | return wxNOT_FOUND; | |
1795 | ||
1796 | if ( valueType == wxPG_VARIANT_TYPE_LONG ) | |
1797 | { | |
1798 | index = value.GetLong(); | |
1799 | } | |
1800 | else if ( valueType == wxPG_VARIANT_TYPE_STRING ) | |
1801 | { | |
1802 | index = m_choices.Index(value.GetString()); | |
1803 | } | |
1804 | else if ( valueType == wxPG_VARIANT_TYPE_BOOL ) | |
1805 | { | |
1806 | index = value.GetBool()? 1 : 0; | |
1807 | } | |
1808 | ||
1809 | return index; | |
1c4293cb VZ |
1810 | } |
1811 | ||
939d9364 | 1812 | void wxPGProperty::SetChoiceSelection( int newValue ) |
1c4293cb | 1813 | { |
939d9364 JS |
1814 | // Changes value of a property with choices, but only |
1815 | // works if the value type is long or string. | |
1816 | wxString valueType = GetValue().GetType(); | |
1817 | ||
1818 | wxCHECK_RET( m_choices.IsOk(), wxT("invalid choiceinfo") ); | |
1c4293cb | 1819 | |
939d9364 JS |
1820 | if ( valueType == wxPG_VARIANT_TYPE_STRING ) |
1821 | { | |
1822 | SetValue( m_choices.GetLabel(newValue) ); | |
1823 | } | |
1824 | else // if ( valueType == wxPG_VARIANT_TYPE_LONG ) | |
1825 | { | |
1826 | SetValue( (long) newValue ); | |
1827 | } | |
1c4293cb VZ |
1828 | } |
1829 | ||
1830 | bool wxPGProperty::SetChoices( wxPGChoices& choices ) | |
1831 | { | |
939d9364 | 1832 | m_choices.Assign(choices); |
1c4293cb | 1833 | |
1c4293cb | 1834 | { |
939d9364 JS |
1835 | // This may be needed to trigger some initialization |
1836 | // (but don't do it if property is somewhat uninitialized) | |
1837 | wxVariant defVal = GetDefaultValue(); | |
1838 | if ( defVal.IsNull() ) | |
1839 | return false; | |
1c4293cb | 1840 | |
939d9364 | 1841 | SetValue(defVal); |
1c4293cb | 1842 | } |
939d9364 JS |
1843 | |
1844 | return true; | |
1c4293cb VZ |
1845 | } |
1846 | ||
1847 | ||
1848 | const wxPGEditor* wxPGProperty::GetEditorClass() const | |
1849 | { | |
1850 | const wxPGEditor* editor; | |
1851 | ||
1852 | if ( !m_customEditor ) | |
1853 | { | |
1854 | editor = DoGetEditorClass(); | |
1855 | } | |
1856 | else | |
1857 | editor = m_customEditor; | |
1858 | ||
1859 | // | |
1860 | // Maybe override editor if common value specified | |
1861 | if ( GetDisplayedCommonValueCount() ) | |
1862 | { | |
1863 | // TextCtrlAndButton -> ComboBoxAndButton | |
1864 | if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor)) ) | |
c26873c8 | 1865 | editor = wxPGEditor_ChoiceAndButton; |
1c4293cb VZ |
1866 | |
1867 | // TextCtrl -> ComboBox | |
1868 | else if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlEditor)) ) | |
c26873c8 | 1869 | editor = wxPGEditor_ComboBox; |
1c4293cb VZ |
1870 | } |
1871 | ||
1872 | return editor; | |
1873 | } | |
1874 | ||
1c4293cb VZ |
1875 | bool wxPGProperty::HasVisibleChildren() const |
1876 | { | |
1877 | unsigned int i; | |
1878 | ||
1879 | for ( i=0; i<GetChildCount(); i++ ) | |
1880 | { | |
1881 | wxPGProperty* child = Item(i); | |
1882 | ||
1883 | if ( !child->HasFlag(wxPG_PROP_HIDDEN) ) | |
1884 | return true; | |
1885 | } | |
1886 | ||
1887 | return false; | |
1888 | } | |
1889 | ||
1c4293cb VZ |
1890 | bool wxPGProperty::RecreateEditor() |
1891 | { | |
1892 | wxPropertyGrid* pg = GetGrid(); | |
1893 | wxASSERT(pg); | |
1894 | ||
1895 | wxPGProperty* selected = pg->GetSelection(); | |
1896 | if ( this == selected ) | |
1897 | { | |
1898 | pg->DoSelectProperty(this, wxPG_SEL_FORCE); | |
1899 | return true; | |
1900 | } | |
1901 | return false; | |
1902 | } | |
1903 | ||
1904 | ||
1905 | void wxPGProperty::SetValueImage( wxBitmap& bmp ) | |
1906 | { | |
1907 | delete m_valueBitmap; | |
1908 | ||
1909 | if ( &bmp && bmp.Ok() ) | |
1910 | { | |
1911 | // Resize the image | |
1912 | wxSize maxSz = GetGrid()->GetImageSize(); | |
1913 | wxSize imSz(bmp.GetWidth(),bmp.GetHeight()); | |
1914 | ||
4aee8334 | 1915 | if ( imSz.y != maxSz.y ) |
1c4293cb VZ |
1916 | { |
1917 | // Create a memory DC | |
1918 | wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth()); | |
1919 | ||
1920 | wxMemoryDC dc; | |
1921 | dc.SelectObject(*bmpNew); | |
1922 | ||
1923 | // Scale | |
1924 | // FIXME: This is ugly - use image or wait for scaling patch. | |
1c4293cb VZ |
1925 | double scaleY = (double)maxSz.y / (double)imSz.y; |
1926 | ||
4aee8334 | 1927 | dc.SetUserScale(scaleY, scaleY); |
1c4293cb | 1928 | |
4aee8334 | 1929 | dc.DrawBitmap(bmp, 0, 0); |
1c4293cb VZ |
1930 | |
1931 | m_valueBitmap = bmpNew; | |
1932 | } | |
1933 | else | |
1934 | { | |
1935 | m_valueBitmap = new wxBitmap(bmp); | |
1936 | } | |
1937 | ||
1938 | m_flags |= wxPG_PROP_CUSTOMIMAGE; | |
1939 | } | |
1940 | else | |
1941 | { | |
1942 | m_valueBitmap = NULL; | |
1943 | m_flags &= ~(wxPG_PROP_CUSTOMIMAGE); | |
1944 | } | |
1945 | } | |
1946 | ||
1947 | ||
1948 | wxPGProperty* wxPGProperty::GetMainParent() const | |
1949 | { | |
1950 | const wxPGProperty* curChild = this; | |
1951 | const wxPGProperty* curParent = m_parent; | |
1952 | ||
1953 | while ( curParent && !curParent->IsCategory() ) | |
1954 | { | |
1955 | curChild = curParent; | |
1956 | curParent = curParent->m_parent; | |
1957 | } | |
1958 | ||
1959 | return (wxPGProperty*) curChild; | |
1960 | } | |
1961 | ||
1962 | ||
1963 | const wxPGProperty* wxPGProperty::GetLastVisibleSubItem() const | |
1964 | { | |
1965 | // | |
1966 | // Returns last visible sub-item, recursively. | |
1967 | if ( !IsExpanded() || !GetChildCount() ) | |
1968 | return this; | |
1969 | ||
1970 | return Last()->GetLastVisibleSubItem(); | |
1971 | } | |
1972 | ||
1973 | ||
1974 | bool wxPGProperty::IsVisible() const | |
1975 | { | |
1976 | const wxPGProperty* parent; | |
1977 | ||
1978 | if ( HasFlag(wxPG_PROP_HIDDEN) ) | |
1979 | return false; | |
1980 | ||
1981 | for ( parent = GetParent(); parent != NULL; parent = parent->GetParent() ) | |
1982 | { | |
1983 | if ( !parent->IsExpanded() || parent->HasFlag(wxPG_PROP_HIDDEN) ) | |
1984 | return false; | |
1985 | } | |
1986 | ||
1987 | return true; | |
1988 | } | |
1989 | ||
1990 | wxPropertyGrid* wxPGProperty::GetGridIfDisplayed() const | |
1991 | { | |
1992 | wxPropertyGridPageState* state = GetParentState(); | |
e777bd14 JS |
1993 | if ( !state ) |
1994 | return NULL; | |
1c4293cb VZ |
1995 | wxPropertyGrid* propGrid = state->GetGrid(); |
1996 | if ( state == propGrid->GetState() ) | |
1997 | return propGrid; | |
1998 | return NULL; | |
1999 | } | |
2000 | ||
2001 | ||
2002 | int wxPGProperty::GetY2( int lh ) const | |
2003 | { | |
2004 | const wxPGProperty* parent; | |
2005 | const wxPGProperty* child = this; | |
2006 | ||
2007 | int y = 0; | |
2008 | ||
2009 | for ( parent = GetParent(); parent != NULL; parent = child->GetParent() ) | |
2010 | { | |
2011 | if ( !parent->IsExpanded() ) | |
2012 | return -1; | |
2013 | y += parent->GetChildrenHeight(lh, child->GetIndexInParent()); | |
2014 | y += lh; | |
2015 | child = parent; | |
2016 | } | |
2017 | ||
2018 | y -= lh; // need to reduce one level | |
2019 | ||
2020 | return y; | |
2021 | } | |
2022 | ||
2023 | ||
2024 | int wxPGProperty::GetY() const | |
2025 | { | |
2026 | return GetY2(GetGrid()->GetRowHeight()); | |
2027 | } | |
2028 | ||
1c4293cb | 2029 | // This is used by Insert etc. |
48a32cf6 JS |
2030 | void wxPGProperty::DoAddChild( wxPGProperty* prop, int index, |
2031 | bool correct_mode ) | |
1c4293cb | 2032 | { |
f7a094e1 | 2033 | if ( index < 0 || (size_t)index >= m_children.size() ) |
1c4293cb | 2034 | { |
f7a094e1 JS |
2035 | if ( correct_mode ) prop->m_arrIndex = m_children.size(); |
2036 | m_children.push_back( prop ); | |
1c4293cb VZ |
2037 | } |
2038 | else | |
2039 | { | |
f7a094e1 | 2040 | m_children.insert( m_children.begin()+index, prop); |
1b895132 | 2041 | if ( correct_mode ) FixIndicesOfChildren( index ); |
1c4293cb VZ |
2042 | } |
2043 | ||
2044 | prop->m_parent = this; | |
2045 | } | |
2046 | ||
48a32cf6 | 2047 | void wxPGProperty::DoPreAddChild( int index, wxPGProperty* prop ) |
1c4293cb | 2048 | { |
d665918b | 2049 | wxASSERT_MSG( prop->GetBaseName().length(), |
48a32cf6 JS |
2050 | "Property's children must have unique, non-empty " |
2051 | "names within their scope" ); | |
d665918b | 2052 | |
48a32cf6 JS |
2053 | prop->m_arrIndex = index; |
2054 | m_children.insert( m_children.begin()+index, | |
2055 | prop ); | |
1c4293cb VZ |
2056 | |
2057 | int custImgHeight = prop->OnMeasureImage().y; | |
2058 | if ( custImgHeight < 0 /*|| custImgHeight > 1*/ ) | |
2059 | prop->m_flags |= wxPG_PROP_CUSTOMIMAGE; | |
2060 | ||
2061 | prop->m_parent = this; | |
2062 | } | |
2063 | ||
48a32cf6 JS |
2064 | void wxPGProperty::AddPrivateChild( wxPGProperty* prop ) |
2065 | { | |
2066 | if ( !(m_flags & wxPG_PROP_PARENTAL_FLAGS) ) | |
2067 | SetParentalType(wxPG_PROP_AGGREGATE); | |
2068 | ||
2069 | wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS) == | |
2070 | wxPG_PROP_AGGREGATE, | |
2071 | "Do not mix up AddPrivateChild() calls with other " | |
2072 | "property adders." ); | |
2073 | ||
2074 | DoPreAddChild( m_children.size(), prop ); | |
2075 | } | |
2076 | ||
2077 | #if wxPG_COMPATIBILITY_1_4 | |
2078 | void wxPGProperty::AddChild( wxPGProperty* prop ) | |
2079 | { | |
2080 | AddPrivateChild(prop); | |
2081 | } | |
2082 | #endif | |
2083 | ||
2084 | wxPGProperty* wxPGProperty::InsertChild( int index, | |
2085 | wxPGProperty* childProperty ) | |
2086 | { | |
2087 | if ( index < 0 ) | |
2088 | index = m_children.size(); | |
2089 | ||
2090 | if ( m_parentState ) | |
2091 | { | |
2092 | m_parentState->DoInsert(this, index, childProperty); | |
2093 | } | |
2094 | else | |
2095 | { | |
2096 | if ( !(m_flags & wxPG_PROP_PARENTAL_FLAGS) ) | |
2097 | SetParentalType(wxPG_PROP_MISC_PARENT); | |
2098 | ||
2099 | wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS) == | |
2100 | wxPG_PROP_MISC_PARENT, | |
2101 | "Do not mix up AddPrivateChild() calls with other " | |
2102 | "property adders." ); | |
2103 | ||
2104 | DoPreAddChild( index, childProperty ); | |
2105 | } | |
2106 | ||
2107 | return childProperty; | |
2108 | } | |
2109 | ||
d8c74d04 JS |
2110 | void wxPGProperty::RemoveChild( wxPGProperty* p ) |
2111 | { | |
2112 | wxArrayPGProperty::iterator it; | |
2113 | wxArrayPGProperty& children = m_children; | |
2114 | ||
2115 | for ( it=children.begin(); it != children.end(); it++ ) | |
2116 | { | |
2117 | if ( *it == p ) | |
2118 | { | |
2119 | m_children.erase(it); | |
2120 | break; | |
2121 | } | |
2122 | } | |
2123 | } | |
1c4293cb VZ |
2124 | |
2125 | void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const | |
2126 | { | |
2127 | wxASSERT( GetChildCount() ); | |
2128 | wxASSERT( !IsCategory() ); | |
2129 | ||
2130 | *value = GetValue(); | |
2131 | ||
2132 | if ( !list.GetCount() ) | |
2133 | return; | |
2134 | ||
2135 | wxASSERT( GetChildCount() >= (unsigned int)list.GetCount() ); | |
2136 | ||
2137 | bool allChildrenSpecified; | |
2138 | ||
2139 | // Don't fully update aggregate properties unless all children have | |
2140 | // specified value | |
2141 | if ( HasFlag(wxPG_PROP_AGGREGATE) ) | |
2142 | allChildrenSpecified = AreAllChildrenSpecified(&list); | |
2143 | else | |
2144 | allChildrenSpecified = true; | |
2145 | ||
2146 | wxVariant childValue = list[0]; | |
2147 | unsigned int i; | |
2148 | unsigned int n = 0; | |
2149 | ||
d665918b | 2150 | //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str()); |
1c4293cb VZ |
2151 | |
2152 | for ( i=0; i<GetChildCount(); i++ ) | |
2153 | { | |
2154 | const wxPGProperty* child = Item(i); | |
2155 | ||
d665918b | 2156 | if ( childValue.GetName() == child->GetBaseName() ) |
1c4293cb VZ |
2157 | { |
2158 | //wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str()); | |
2159 | ||
0372d42e | 2160 | if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST ) |
1c4293cb VZ |
2161 | { |
2162 | wxVariant cv2(child->GetValue()); | |
2163 | child->AdaptListToValue(childValue, &cv2); | |
2164 | childValue = cv2; | |
2165 | } | |
2166 | ||
2167 | if ( allChildrenSpecified ) | |
b8b1ff48 JS |
2168 | { |
2169 | *value = ChildChanged(*value, i, childValue); | |
2170 | } | |
2171 | ||
1c4293cb VZ |
2172 | n++; |
2173 | if ( n == (unsigned int)list.GetCount() ) | |
2174 | break; | |
2175 | childValue = list[n]; | |
2176 | } | |
2177 | } | |
2178 | } | |
2179 | ||
2180 | ||
1b895132 | 2181 | void wxPGProperty::FixIndicesOfChildren( unsigned int starthere ) |
1c4293cb VZ |
2182 | { |
2183 | size_t i; | |
2184 | for ( i=starthere;i<GetChildCount();i++) | |
2185 | Item(i)->m_arrIndex = i; | |
2186 | } | |
2187 | ||
2188 | ||
2189 | // Returns (direct) child property with given name (or NULL if not found) | |
2190 | wxPGProperty* wxPGProperty::GetPropertyByName( const wxString& name ) const | |
2191 | { | |
2192 | size_t i; | |
2193 | ||
2194 | for ( i=0; i<GetChildCount(); i++ ) | |
2195 | { | |
2196 | wxPGProperty* p = Item(i); | |
2197 | if ( p->m_name == name ) | |
2198 | return p; | |
2199 | } | |
2200 | ||
2201 | // Does it have point, then? | |
2202 | int pos = name.Find(wxS('.')); | |
2203 | if ( pos <= 0 ) | |
d3b9f782 | 2204 | return NULL; |
1c4293cb VZ |
2205 | |
2206 | wxPGProperty* p = GetPropertyByName(name. substr(0,pos)); | |
2207 | ||
2208 | if ( !p || !p->GetChildCount() ) | |
2209 | return NULL; | |
2210 | ||
2211 | return p->GetPropertyByName(name.substr(pos+1,name.length()-pos-1)); | |
2212 | } | |
2213 | ||
d665918b | 2214 | wxPGProperty* wxPGProperty::GetPropertyByNameWH( const wxString& name, unsigned int hintIndex ) const |
1c4293cb VZ |
2215 | { |
2216 | unsigned int i = hintIndex; | |
2217 | ||
2218 | if ( i >= GetChildCount() ) | |
2219 | i = 0; | |
2220 | ||
2221 | unsigned int lastIndex = i - 1; | |
2222 | ||
2223 | if ( lastIndex >= GetChildCount() ) | |
2224 | lastIndex = GetChildCount() - 1; | |
2225 | ||
2226 | for (;;) | |
2227 | { | |
2228 | wxPGProperty* p = Item(i); | |
d665918b | 2229 | if ( p->m_name == name ) |
1c4293cb VZ |
2230 | return p; |
2231 | ||
2232 | if ( i == lastIndex ) | |
2233 | break; | |
2234 | ||
2235 | i++; | |
2236 | if ( i == GetChildCount() ) | |
2237 | i = 0; | |
2238 | }; | |
2239 | ||
2240 | return NULL; | |
2241 | } | |
2242 | ||
2243 | int wxPGProperty::GetChildrenHeight( int lh, int iMax_ ) const | |
2244 | { | |
2245 | // Returns height of children, recursively, and | |
2246 | // by taking expanded/collapsed status into account. | |
2247 | // | |
2248 | // iMax is used when finding property y-positions. | |
2249 | // | |
2250 | unsigned int i = 0; | |
2251 | int h = 0; | |
2252 | ||
2253 | if ( iMax_ == -1 ) | |
2254 | iMax_ = GetChildCount(); | |
2255 | ||
2256 | unsigned int iMax = iMax_; | |
2257 | ||
2258 | wxASSERT( iMax <= GetChildCount() ); | |
2259 | ||
2260 | if ( !IsExpanded() && GetParent() ) | |
2261 | return 0; | |
2262 | ||
2263 | while ( i < iMax ) | |
2264 | { | |
2265 | wxPGProperty* pwc = (wxPGProperty*) Item(i); | |
2266 | ||
2267 | if ( !pwc->HasFlag(wxPG_PROP_HIDDEN) ) | |
2268 | { | |
2269 | if ( !pwc->IsExpanded() || | |
2270 | pwc->GetChildCount() == 0 ) | |
2271 | h += lh; | |
2272 | else | |
2273 | h += pwc->GetChildrenHeight(lh) + lh; | |
2274 | } | |
2275 | ||
2276 | i++; | |
2277 | } | |
2278 | ||
2279 | return h; | |
2280 | } | |
2281 | ||
14bac4b5 JS |
2282 | wxPGProperty* wxPGProperty::GetItemAtY( unsigned int y, |
2283 | unsigned int lh, | |
2284 | unsigned int* nextItemY ) const | |
1c4293cb VZ |
2285 | { |
2286 | wxASSERT( nextItemY ); | |
2287 | ||
2288 | // Linear search at the moment | |
2289 | // | |
2290 | // nextItemY = y of next visible property, final value will be written back. | |
2291 | wxPGProperty* result = NULL; | |
2292 | wxPGProperty* current = NULL; | |
2293 | unsigned int iy = *nextItemY; | |
2294 | unsigned int i = 0; | |
2295 | unsigned int iMax = GetChildCount(); | |
2296 | ||
2297 | while ( i < iMax ) | |
2298 | { | |
2299 | wxPGProperty* pwc = Item(i); | |
2300 | ||
2301 | if ( !pwc->HasFlag(wxPG_PROP_HIDDEN) ) | |
2302 | { | |
2303 | // Found? | |
2304 | if ( y < iy ) | |
2305 | { | |
2306 | result = current; | |
2307 | break; | |
2308 | } | |
2309 | ||
2310 | iy += lh; | |
2311 | ||
2312 | if ( pwc->IsExpanded() && | |
2313 | pwc->GetChildCount() > 0 ) | |
2314 | { | |
2315 | result = (wxPGProperty*) pwc->GetItemAtY( y, lh, &iy ); | |
2316 | if ( result ) | |
2317 | break; | |
2318 | } | |
2319 | ||
2320 | current = pwc; | |
2321 | } | |
2322 | ||
2323 | i++; | |
2324 | } | |
2325 | ||
2326 | // Found? | |
2327 | if ( !result && y < iy ) | |
2328 | result = current; | |
2329 | ||
2330 | *nextItemY = iy; | |
2331 | ||
2332 | /* | |
2333 | if ( current ) | |
43b2d5e7 | 2334 | { |
1c4293cb | 2335 | wxLogDebug(wxT("%s::GetItemAtY(%i) -> %s"),this->GetLabel().c_str(),y,current->GetLabel().c_str()); |
43b2d5e7 | 2336 | } |
1c4293cb | 2337 | else |
43b2d5e7 | 2338 | { |
1c4293cb | 2339 | wxLogDebug(wxT("%s::GetItemAtY(%i) -> NULL"),this->GetLabel().c_str(),y); |
43b2d5e7 | 2340 | } |
1c4293cb VZ |
2341 | */ |
2342 | ||
2343 | return (wxPGProperty*) result; | |
2344 | } | |
2345 | ||
2346 | void wxPGProperty::Empty() | |
2347 | { | |
2348 | size_t i; | |
2349 | if ( !HasFlag(wxPG_PROP_CHILDREN_ARE_COPIES) ) | |
2350 | { | |
2351 | for ( i=0; i<GetChildCount(); i++ ) | |
2352 | { | |
f7a094e1 | 2353 | delete m_children[i]; |
1c4293cb VZ |
2354 | } |
2355 | } | |
2356 | ||
f7a094e1 | 2357 | m_children.clear(); |
1c4293cb VZ |
2358 | } |
2359 | ||
14bac4b5 JS |
2360 | wxPGProperty* wxPGProperty::GetItemAtY( unsigned int y ) const |
2361 | { | |
2362 | unsigned int nextItem; | |
2363 | return GetItemAtY( y, GetGrid()->GetRowHeight(), &nextItem); | |
2364 | } | |
2365 | ||
91c818f8 JS |
2366 | void wxPGProperty::DeleteChildren() |
2367 | { | |
2368 | wxPropertyGridPageState* state = m_parentState; | |
2369 | ||
2370 | while ( GetChildCount() ) | |
2371 | { | |
2372 | wxPGProperty* child = Item(GetChildCount()-1); | |
2373 | state->DoDelete(child, true); | |
2374 | } | |
2375 | } | |
2376 | ||
b8b1ff48 JS |
2377 | wxVariant wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue), |
2378 | int WXUNUSED(childIndex), | |
2379 | wxVariant& WXUNUSED(childValue) ) const | |
1c4293cb | 2380 | { |
b8b1ff48 | 2381 | return wxNullVariant; |
1c4293cb VZ |
2382 | } |
2383 | ||
2384 | bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const | |
2385 | { | |
2386 | unsigned int i; | |
2387 | ||
2388 | const wxVariantList* pList = NULL; | |
2389 | wxVariantList::const_iterator node; | |
2390 | ||
2391 | if ( pendingList ) | |
2392 | { | |
2393 | pList = &pendingList->GetList(); | |
2394 | node = pList->begin(); | |
2395 | } | |
2396 | ||
1c4293cb VZ |
2397 | for ( i=0; i<GetChildCount(); i++ ) |
2398 | { | |
2399 | wxPGProperty* child = Item(i); | |
2400 | const wxVariant* listValue = NULL; | |
2401 | wxVariant value; | |
2402 | ||
2403 | if ( pendingList ) | |
2404 | { | |
d665918b | 2405 | const wxString& childName = child->GetBaseName(); |
1c4293cb | 2406 | |
b7bc9d80 | 2407 | for ( ; node != pList->end(); ++node ) |
1c4293cb VZ |
2408 | { |
2409 | const wxVariant& item = *((const wxVariant*)*node); | |
d665918b | 2410 | if ( item.GetName() == childName ) |
1c4293cb VZ |
2411 | { |
2412 | listValue = &item; | |
2413 | value = item; | |
2414 | break; | |
2415 | } | |
2416 | } | |
2417 | } | |
2418 | ||
2419 | if ( !listValue ) | |
2420 | value = child->GetValue(); | |
2421 | ||
2422 | if ( value.IsNull() ) | |
2423 | return false; | |
2424 | ||
2425 | // Check recursively | |
2426 | if ( child->GetChildCount() ) | |
2427 | { | |
2428 | const wxVariant* childList = NULL; | |
2429 | ||
0372d42e | 2430 | if ( listValue && listValue->GetType() == wxPG_VARIANT_TYPE_LIST ) |
1c4293cb VZ |
2431 | childList = listValue; |
2432 | ||
2433 | if ( !child->AreAllChildrenSpecified((wxVariant*)childList) ) | |
2434 | return false; | |
2435 | } | |
2436 | } | |
2437 | ||
2438 | return true; | |
2439 | } | |
2440 | ||
2441 | wxPGProperty* wxPGProperty::UpdateParentValues() | |
2442 | { | |
2443 | wxPGProperty* parent = m_parent; | |
2444 | if ( parent && parent->HasFlag(wxPG_PROP_COMPOSED_VALUE) && | |
2445 | !parent->IsCategory() && !parent->IsRoot() ) | |
2446 | { | |
2447 | wxString s; | |
c82a80e8 | 2448 | parent->DoGenerateComposedValue(s); |
1c4293cb VZ |
2449 | parent->m_value = s; |
2450 | return parent->UpdateParentValues(); | |
2451 | } | |
2452 | return this; | |
2453 | } | |
2454 | ||
2455 | bool wxPGProperty::IsTextEditable() const | |
2456 | { | |
2457 | if ( HasFlag(wxPG_PROP_READONLY) ) | |
2458 | return false; | |
2459 | ||
2460 | if ( HasFlag(wxPG_PROP_NOEDITOR) && | |
2461 | (GetChildCount() || | |
2462 | wxString(GetEditorClass()->GetClassInfo()->GetClassName()).EndsWith(wxS("Button"))) | |
2463 | ) | |
2464 | return false; | |
2465 | ||
2466 | return true; | |
2467 | } | |
2468 | ||
1c4293cb VZ |
2469 | // Call after fixed sub-properties added/removed after creation. |
2470 | // if oldSelInd >= 0 and < new max items, then selection is | |
2471 | // moved to it. Note: oldSelInd -2 indicates that this property | |
2472 | // should be selected. | |
2473 | void wxPGProperty::SubPropsChanged( int oldSelInd ) | |
2474 | { | |
2475 | wxPropertyGridPageState* state = GetParentState(); | |
2476 | wxPropertyGrid* grid = state->GetGrid(); | |
2477 | ||
2fd4a524 JS |
2478 | // |
2479 | // Re-repare children (recursively) | |
2480 | for ( unsigned int i=0; i<GetChildCount(); i++ ) | |
2481 | { | |
2482 | wxPGProperty* child = Item(i); | |
2483 | child->InitAfterAdded(state, grid); | |
2484 | } | |
1c4293cb | 2485 | |
d3b9f782 | 2486 | wxPGProperty* sel = NULL; |
f7a094e1 JS |
2487 | if ( oldSelInd >= (int)m_children.size() ) |
2488 | oldSelInd = (int)m_children.size() - 1; | |
1c4293cb VZ |
2489 | |
2490 | if ( oldSelInd >= 0 ) | |
f7a094e1 | 2491 | sel = m_children[oldSelInd]; |
1c4293cb VZ |
2492 | else if ( oldSelInd == -2 ) |
2493 | sel = this; | |
2494 | ||
2495 | if ( sel ) | |
2496 | state->DoSelectProperty(sel); | |
2497 | ||
2498 | if ( state == grid->GetState() ) | |
2499 | { | |
2500 | grid->GetPanel()->Refresh(); | |
2501 | } | |
2502 | } | |
2503 | ||
2504 | // ----------------------------------------------------------------------- | |
2505 | // wxPGRootProperty | |
2506 | // ----------------------------------------------------------------------- | |
2507 | ||
2508 | WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPGRootProperty,none,TextCtrl) | |
2509 | IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty, wxPGProperty) | |
2510 | ||
2511 | ||
94b8ecf1 | 2512 | wxPGRootProperty::wxPGRootProperty( const wxString& name ) |
1c4293cb VZ |
2513 | : wxPGProperty() |
2514 | { | |
94b8ecf1 JS |
2515 | m_name = name; |
2516 | m_label = m_name; | |
1c4293cb VZ |
2517 | SetParentalType(0); |
2518 | m_depth = 0; | |
2519 | } | |
2520 | ||
2521 | ||
2522 | wxPGRootProperty::~wxPGRootProperty() | |
2523 | { | |
2524 | } | |
2525 | ||
2526 | ||
2527 | // ----------------------------------------------------------------------- | |
2528 | // wxPropertyCategory | |
2529 | // ----------------------------------------------------------------------- | |
2530 | ||
2531 | WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxPropertyCategory,none,TextCtrl) | |
2532 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyCategory, wxPGProperty) | |
2533 | ||
2534 | void wxPropertyCategory::Init() | |
2535 | { | |
2536 | // don't set colour - prepareadditem method should do this | |
2537 | SetParentalType(wxPG_PROP_CATEGORY); | |
2538 | m_capFgColIndex = 1; | |
2539 | m_textExtent = -1; | |
2540 | } | |
2541 | ||
2542 | wxPropertyCategory::wxPropertyCategory() | |
2543 | : wxPGProperty() | |
2544 | { | |
2545 | Init(); | |
2546 | } | |
2547 | ||
2548 | ||
2549 | wxPropertyCategory::wxPropertyCategory( const wxString &label, const wxString& name ) | |
2550 | : wxPGProperty(label,name) | |
2551 | { | |
2552 | Init(); | |
2553 | } | |
2554 | ||
2555 | ||
2556 | wxPropertyCategory::~wxPropertyCategory() | |
2557 | { | |
2558 | } | |
2559 | ||
2560 | ||
1425eca5 JS |
2561 | wxString wxPropertyCategory::ValueToString( wxVariant& WXUNUSED(value), |
2562 | int WXUNUSED(argFlags) ) const | |
1c4293cb VZ |
2563 | { |
2564 | return wxEmptyString; | |
2565 | } | |
2566 | ||
2567 | int wxPropertyCategory::GetTextExtent( const wxWindow* wnd, const wxFont& font ) const | |
2568 | { | |
2569 | if ( m_textExtent > 0 ) | |
2570 | return m_textExtent; | |
2571 | int x = 0, y = 0; | |
2572 | ((wxWindow*)wnd)->GetTextExtent( m_label, &x, &y, 0, 0, &font ); | |
2573 | return x; | |
2574 | } | |
2575 | ||
2576 | void wxPropertyCategory::CalculateTextExtent( wxWindow* wnd, const wxFont& font ) | |
2577 | { | |
2578 | int x = 0, y = 0; | |
2579 | wnd->GetTextExtent( m_label, &x, &y, 0, 0, &font ); | |
2580 | m_textExtent = x; | |
2581 | } | |
2582 | ||
2728c3bf JS |
2583 | // ----------------------------------------------------------------------- |
2584 | // wxPGChoices | |
2585 | // ----------------------------------------------------------------------- | |
2586 | ||
2587 | wxPGChoiceEntry& wxPGChoices::Add( const wxString& label, int value ) | |
2588 | { | |
2589 | AllocExclusive(); | |
2590 | ||
2591 | wxPGChoiceEntry entry(label, value); | |
2592 | return m_data->Insert( -1, entry ); | |
2593 | } | |
2594 | ||
2595 | // ----------------------------------------------------------------------- | |
2596 | ||
2597 | wxPGChoiceEntry& wxPGChoices::Add( const wxString& label, const wxBitmap& bitmap, int value ) | |
2598 | { | |
2599 | AllocExclusive(); | |
2600 | ||
2601 | wxPGChoiceEntry entry(label, value); | |
2602 | entry.SetBitmap(bitmap); | |
2603 | return m_data->Insert( -1, entry ); | |
2604 | } | |
2605 | ||
2606 | // ----------------------------------------------------------------------- | |
2607 | ||
2608 | wxPGChoiceEntry& wxPGChoices::Insert( const wxPGChoiceEntry& entry, int index ) | |
2609 | { | |
2610 | AllocExclusive(); | |
2611 | ||
2612 | return m_data->Insert( index, entry ); | |
2613 | } | |
2614 | ||
2615 | // ----------------------------------------------------------------------- | |
2616 | ||
2617 | wxPGChoiceEntry& wxPGChoices::Insert( const wxString& label, int index, int value ) | |
2618 | { | |
2619 | AllocExclusive(); | |
2620 | ||
2621 | wxPGChoiceEntry entry(label, value); | |
2622 | return m_data->Insert( index, entry ); | |
2623 | } | |
2624 | ||
2625 | // ----------------------------------------------------------------------- | |
2626 | ||
2627 | wxPGChoiceEntry& wxPGChoices::AddAsSorted( const wxString& label, int value ) | |
2628 | { | |
2629 | AllocExclusive(); | |
2630 | ||
2631 | size_t index = 0; | |
2632 | ||
2633 | while ( index < GetCount() ) | |
2634 | { | |
2635 | int cmpRes = GetLabel(index).Cmp(label); | |
2636 | if ( cmpRes > 0 ) | |
2637 | break; | |
2638 | index++; | |
2639 | } | |
2640 | ||
2641 | wxPGChoiceEntry entry(label, value); | |
2642 | return m_data->Insert( index, entry ); | |
2643 | } | |
2644 | ||
2645 | // ----------------------------------------------------------------------- | |
2646 | ||
2647 | void wxPGChoices::Add( const wxChar** labels, const ValArrItem* values ) | |
2648 | { | |
2649 | AllocExclusive(); | |
2650 | ||
2651 | unsigned int itemcount = 0; | |
2652 | const wxChar** p = &labels[0]; | |
2653 | while ( *p ) { p++; itemcount++; } | |
2654 | ||
2655 | unsigned int i; | |
2656 | for ( i = 0; i < itemcount; i++ ) | |
2657 | { | |
2658 | int value = i; | |
2659 | if ( values ) | |
2660 | value = values[i]; | |
2661 | wxPGChoiceEntry entry(labels[i], value); | |
2662 | m_data->Insert( i, entry ); | |
2663 | } | |
2664 | } | |
2665 | ||
2666 | // ----------------------------------------------------------------------- | |
2667 | ||
2668 | void wxPGChoices::Add( const wxArrayString& arr, const wxArrayInt& arrint ) | |
2669 | { | |
2670 | AllocExclusive(); | |
2671 | ||
2672 | unsigned int i; | |
2673 | unsigned int itemcount = arr.size(); | |
2674 | ||
2675 | for ( i = 0; i < itemcount; i++ ) | |
2676 | { | |
2677 | int value = i; | |
2678 | if ( &arrint && arrint.size() ) | |
2679 | value = arrint[i]; | |
2680 | wxPGChoiceEntry entry(arr[i], value); | |
2681 | m_data->Insert( i, entry ); | |
2682 | } | |
2683 | } | |
2684 | ||
2685 | // ----------------------------------------------------------------------- | |
2686 | ||
2687 | void wxPGChoices::RemoveAt(size_t nIndex, size_t count) | |
2688 | { | |
2689 | AllocExclusive(); | |
2690 | ||
92ffc98a | 2691 | wxASSERT( m_data->GetRefCount() != -1 ); |
2728c3bf JS |
2692 | m_data->m_items.erase(m_data->m_items.begin()+nIndex, |
2693 | m_data->m_items.begin()+nIndex+count); | |
2694 | } | |
2695 | ||
2696 | // ----------------------------------------------------------------------- | |
2697 | ||
2698 | void wxPGChoices::Clear() | |
2699 | { | |
2700 | if ( m_data != wxPGChoicesEmptyData ) | |
2701 | { | |
2702 | AllocExclusive(); | |
2703 | m_data->Clear(); | |
2704 | } | |
2705 | } | |
2706 | ||
2707 | // ----------------------------------------------------------------------- | |
2708 | ||
2709 | int wxPGChoices::Index( const wxString& str ) const | |
2710 | { | |
2711 | if ( IsOk() ) | |
2712 | { | |
2713 | unsigned int i; | |
2714 | for ( i=0; i< m_data->GetCount(); i++ ) | |
2715 | { | |
2716 | const wxPGChoiceEntry& entry = m_data->Item(i); | |
2717 | if ( entry.HasText() && entry.GetText() == str ) | |
2718 | return i; | |
2719 | } | |
2720 | } | |
2721 | return -1; | |
2722 | } | |
2723 | ||
2724 | // ----------------------------------------------------------------------- | |
2725 | ||
2726 | int wxPGChoices::Index( int val ) const | |
2727 | { | |
2728 | if ( IsOk() ) | |
2729 | { | |
2730 | unsigned int i; | |
2731 | for ( i=0; i< m_data->GetCount(); i++ ) | |
2732 | { | |
2733 | const wxPGChoiceEntry& entry = m_data->Item(i); | |
2734 | if ( entry.GetValue() == val ) | |
2735 | return i; | |
2736 | } | |
2737 | } | |
2738 | return -1; | |
2739 | } | |
2740 | ||
2741 | // ----------------------------------------------------------------------- | |
2742 | ||
2743 | wxArrayString wxPGChoices::GetLabels() const | |
2744 | { | |
2745 | wxArrayString arr; | |
2746 | unsigned int i; | |
2747 | ||
2748 | if ( this && IsOk() ) | |
2749 | for ( i=0; i<GetCount(); i++ ) | |
2750 | arr.push_back(GetLabel(i)); | |
2751 | ||
2752 | return arr; | |
2753 | } | |
2754 | ||
2755 | // ----------------------------------------------------------------------- | |
2756 | ||
2757 | wxArrayInt wxPGChoices::GetValuesForStrings( const wxArrayString& strings ) const | |
2758 | { | |
2759 | wxArrayInt arr; | |
2760 | ||
2761 | if ( IsOk() ) | |
2762 | { | |
2763 | unsigned int i; | |
2764 | for ( i=0; i< strings.size(); i++ ) | |
2765 | { | |
2766 | int index = Index(strings[i]); | |
2767 | if ( index >= 0 ) | |
2768 | arr.Add(GetValue(index)); | |
2769 | else | |
2770 | arr.Add(wxPG_INVALID_VALUE); | |
2771 | } | |
2772 | } | |
2773 | ||
2774 | return arr; | |
2775 | } | |
2776 | ||
2777 | // ----------------------------------------------------------------------- | |
2778 | ||
2779 | wxArrayInt wxPGChoices::GetIndicesForStrings( const wxArrayString& strings, | |
2780 | wxArrayString* unmatched ) const | |
2781 | { | |
2782 | wxArrayInt arr; | |
2783 | ||
2784 | if ( IsOk() ) | |
2785 | { | |
2786 | unsigned int i; | |
2787 | for ( i=0; i< strings.size(); i++ ) | |
2788 | { | |
2789 | const wxString& str = strings[i]; | |
2790 | int index = Index(str); | |
2791 | if ( index >= 0 ) | |
2792 | arr.Add(index); | |
2793 | else if ( unmatched ) | |
2794 | unmatched->Add(str); | |
2795 | } | |
2796 | } | |
2797 | ||
2798 | return arr; | |
2799 | } | |
2800 | ||
2801 | // ----------------------------------------------------------------------- | |
2802 | ||
2803 | void wxPGChoices::AllocExclusive() | |
2804 | { | |
2805 | EnsureData(); | |
2806 | ||
92ffc98a | 2807 | if ( m_data->GetRefCount() != 1 ) |
2728c3bf JS |
2808 | { |
2809 | wxPGChoicesData* data = new wxPGChoicesData(); | |
2810 | data->CopyDataFrom(m_data); | |
2811 | Free(); | |
2812 | m_data = data; | |
2813 | } | |
2814 | } | |
2815 | ||
2816 | // ----------------------------------------------------------------------- | |
2817 | ||
2818 | void wxPGChoices::AssignData( wxPGChoicesData* data ) | |
2819 | { | |
2820 | Free(); | |
2821 | ||
2822 | if ( data != wxPGChoicesEmptyData ) | |
2823 | { | |
2824 | m_data = data; | |
92ffc98a | 2825 | data->IncRef(); |
2728c3bf JS |
2826 | } |
2827 | } | |
2828 | ||
2829 | // ----------------------------------------------------------------------- | |
2830 | ||
2831 | void wxPGChoices::Init() | |
2832 | { | |
2833 | m_data = wxPGChoicesEmptyData; | |
2834 | } | |
2835 | ||
2836 | // ----------------------------------------------------------------------- | |
2837 | ||
2838 | void wxPGChoices::Free() | |
2839 | { | |
2840 | if ( m_data != wxPGChoicesEmptyData ) | |
2841 | { | |
2842 | m_data->DecRef(); | |
2843 | m_data = wxPGChoicesEmptyData; | |
2844 | } | |
2845 | } | |
2846 | ||
1c4293cb VZ |
2847 | // ----------------------------------------------------------------------- |
2848 | // wxPGAttributeStorage | |
2849 | // ----------------------------------------------------------------------- | |
2850 | ||
2851 | wxPGAttributeStorage::wxPGAttributeStorage() | |
2852 | { | |
2853 | } | |
2854 | ||
2855 | wxPGAttributeStorage::~wxPGAttributeStorage() | |
2856 | { | |
2857 | wxPGHashMapS2P::iterator it; | |
2858 | ||
b7bc9d80 | 2859 | for ( it = m_map.begin(); it != m_map.end(); ++it ) |
1c4293cb VZ |
2860 | { |
2861 | wxVariantData* data = (wxVariantData*) it->second; | |
2862 | data->DecRef(); | |
2863 | } | |
2864 | } | |
2865 | ||
2866 | void wxPGAttributeStorage::Set( const wxString& name, const wxVariant& value ) | |
2867 | { | |
2868 | wxVariantData* data = value.GetData(); | |
2869 | ||
2870 | // Free old, if any | |
2871 | wxPGHashMapS2P::iterator it = m_map.find(name); | |
2872 | if ( it != m_map.end() ) | |
1802a91d | 2873 | { |
1c4293cb VZ |
2874 | ((wxVariantData*)it->second)->DecRef(); |
2875 | ||
1802a91d JS |
2876 | if ( !data ) |
2877 | { | |
2878 | // If Null variant, just remove from set | |
2879 | m_map.erase(it); | |
2880 | return; | |
2881 | } | |
2882 | } | |
2883 | ||
1c4293cb | 2884 | if ( data ) |
1802a91d | 2885 | { |
1c4293cb VZ |
2886 | data->IncRef(); |
2887 | ||
1802a91d JS |
2888 | m_map[name] = data; |
2889 | } | |
1c4293cb VZ |
2890 | } |
2891 | ||
f4bc1aa2 | 2892 | #endif // wxUSE_PROPGRID |