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