]> git.saurik.com Git - wxWidgets.git/blame - src/propgrid/propgridpagestate.cpp
fix default argument values
[wxWidgets.git] / src / propgrid / propgridpagestate.cpp
CommitLineData
1c4293cb
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/propgrid/propgridpagestate.cpp
3// Purpose: wxPropertyGridPageState class
4// Author: Jaakko Salli
5// Modified by:
6// Created: 2008-08-24
7// RCS-ID: $Id:
8// Copyright: (c) Jaakko Salli
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
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"
32 #include "wx/button.h"
33 #include "wx/pen.h"
34 #include "wx/brush.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/scrolwin.h"
42 #include "wx/dirdlg.h"
43 #include "wx/layout.h"
44 #include "wx/sizer.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
47 #include "wx/statusbr.h"
48 #include "wx/intl.h"
49 #include "wx/frame.h"
fbfe2d4e 50 #include "wx/stopwatch.h"
1c4293cb
VZ
51#endif
52
53// This define is necessary to prevent macro clearing
54#define __wxPG_SOURCE_FILE__
55
56#include <wx/propgrid/propgridpagestate.h>
57#include <wx/propgrid/propgrid.h>
58#include <wx/propgrid/editors.h>
59
1c4293cb
VZ
60#define wxPG_DEFAULT_SPLITTERX 110
61
62
63// -----------------------------------------------------------------------
64// wxPropertyGridIterator
65// -----------------------------------------------------------------------
66
67void wxPropertyGridIteratorBase::Init( wxPropertyGridPageState* state, int flags, wxPGProperty* property, int dir )
68{
69 wxASSERT( dir == 1 || dir == -1 );
70
71 m_state = state;
72 m_baseParent = state->DoGetRoot();
73 if ( !property && m_baseParent->GetChildCount() )
74 property = m_baseParent->Item(0);
75
76 m_property = property;
77
78 wxPG_ITERATOR_CREATE_MASKS(flags, m_itemExMask, m_parentExMask)
79
80 // Need to skip first?
81 if ( property && (property->GetFlags() & m_itemExMask) )
82 {
83 if ( dir == 1 )
84 Next();
85 else
86 Prev();
87 }
88}
89
90void wxPropertyGridIteratorBase::Init( wxPropertyGridPageState* state, int flags, int startPos, int dir )
91{
92 wxPGProperty* property;
93
94 if ( startPos == wxTOP )
95 {
96 property = NULL;
97 if ( dir == 0 )
98 dir = 1;
99 }
100 else if ( startPos == wxBOTTOM )
101 {
102 property = state->GetLastItem(flags);
103 if ( dir == 0 )
104 dir = -1;
105 }
106 else
107 {
108 wxASSERT_MSG( false, wxT("Only supported stating positions are wxTOP and wxBOTTOM") );
109 property = NULL;
110 }
111
112 Init( state, flags, property, dir );
113}
114
115void wxPropertyGridIteratorBase::Assign( const wxPropertyGridIteratorBase& it )
116{
117 m_property = it.m_property;
118 m_state = it.m_state;
119 m_baseParent = it.m_baseParent;
120 m_itemExMask = it.m_itemExMask;
121 m_parentExMask = it.m_parentExMask;
122}
123
124void wxPropertyGridIteratorBase::Prev()
125{
126 wxPGProperty* property = m_property;
127 wxASSERT( property );
128
129 wxPGProperty* parent = property->GetParent();
130 wxASSERT( parent );
131 unsigned int index = property->GetIndexInParent();
132
133 if ( index > 0 )
134 {
135 // Previous sibling
136 index--;
137
138 property = parent->Item(index);
139
140 // Go to last children?
141 if ( property->GetChildCount() &&
142 wxPG_ITERATOR_PARENTEXMASK_TEST(property, m_parentExMask) )
143 {
144 // First child
145 property = property->Last();
146 }
147 }
148 else
149 {
150 // Up to a parent
151 if ( parent == m_baseParent )
152 {
153 m_property = NULL;
154 return;
155 }
156 else
157 {
158 property = parent;
159 }
160 }
161
162 m_property = property;
163
164 // If property does not match our criteria, skip it
165 if ( property->GetFlags() & m_itemExMask )
166 Prev();
167}
168
169void wxPropertyGridIteratorBase::Next( bool iterateChildren )
170{
171 wxPGProperty* property = m_property;
172 wxASSERT( property );
173
174 if ( property->GetChildCount() &&
175 wxPG_ITERATOR_PARENTEXMASK_TEST(property, m_parentExMask) &&
176 iterateChildren )
177 {
178 // First child
179 property = property->Item(0);
180 }
181 else
182 {
183 wxPGProperty* parent = property->GetParent();
184 wxASSERT( parent );
185 unsigned int index = property->GetIndexInParent() + 1;
186
187 if ( index < parent->GetChildCount() )
188 {
189 // Next sibling
190 property = parent->Item(index);
191 }
192 else
193 {
194 // Next sibling of parent
195 if ( parent == m_baseParent )
196 {
197 m_property = NULL;
198 }
199 else
200 {
201 m_property = parent;
202 Next(false);
203 }
204 return;
205 }
206 }
207
208 m_property = property;
209
210 // If property does not match our criteria, skip it
211 if ( property->GetFlags() & m_itemExMask )
212 Next();
213}
214
215// -----------------------------------------------------------------------
216// wxPropertyGridPageState
217// -----------------------------------------------------------------------
218
219wxPropertyGridPageState::wxPropertyGridPageState()
220{
221 m_pPropGrid = (wxPropertyGrid*) NULL;
222 m_regularArray.SetParentState(this);
223 m_properties = &m_regularArray;
224 m_abcArray = (wxPGRootProperty*) NULL;
225 m_currentCategory = (wxPropertyCategory*) NULL;
226 m_selected = (wxPGProperty*) NULL;
227 m_width = 0;
228 m_virtualHeight = 0;
229 m_lastCaptionBottomnest = 1;
230 m_itemsAdded = 0;
231 m_anyModified = 0;
232 m_vhCalcPending = 0;
233 m_colWidths.push_back( wxPG_DEFAULT_SPLITTERX );
234 m_colWidths.push_back( wxPG_DEFAULT_SPLITTERX );
235 m_fSplitterX = wxPG_DEFAULT_SPLITTERX;
236}
237
238// -----------------------------------------------------------------------
239
240wxPropertyGridPageState::~wxPropertyGridPageState()
241{
242 delete m_abcArray;
243}
244
245// -----------------------------------------------------------------------
246
247void wxPropertyGridPageState::InitNonCatMode()
248{
249 if ( !m_abcArray )
250 {
251 m_abcArray = new wxPGRootProperty();
252 m_abcArray->SetParentState(this);
253 m_abcArray->SetFlag(wxPG_PROP_CHILDREN_ARE_COPIES);
254 }
255
256 // Must be called when state::m_properties still points to regularArray.
257 wxPGProperty* oldProperties = m_properties;
258
259 // Must use temp value in state::m_properties for item iteration loop
260 // to run as expected.
261 m_properties = &m_regularArray;
262
263 if ( m_properties->GetChildCount() )
264 {
265 // Copy items.
266 wxPropertyGridIterator it( this, wxPG_ITERATE_DEFAULT|wxPG_ITERATE_CATEGORIES );
267
268 for ( ; !it.AtEnd(); it.Next() )
269 {
270 wxPGProperty* p = it.GetProperty();
271 wxPGProperty* parent = p->GetParent();
272 if ( p->HasFlag(wxPG_PROP_MISC_PARENT) &&
273 ( parent == m_properties || (parent->IsCategory() || parent->IsRoot()) ) )
274 {
275 m_abcArray->AddChild2( p );
276 p->m_parent = &m_regularArray;
277 }
278 }
279 }
280
281 m_properties = oldProperties;
282}
283
284// -----------------------------------------------------------------------
285
286void wxPropertyGridPageState::DoClear()
287{
288 m_regularArray.Empty();
289 if ( m_abcArray )
290 m_abcArray->Empty();
291
292 m_dictName.clear();
293
294 m_currentCategory = (wxPropertyCategory*) NULL;
295 m_lastCaptionBottomnest = 1;
296 m_itemsAdded = 0;
297
298 m_virtualHeight = 0;
299 m_vhCalcPending = 0;
300
301 m_selected = (wxPGProperty*) NULL;
302}
303
304// -----------------------------------------------------------------------
305
306void wxPropertyGridPageState::CalculateFontAndBitmapStuff( int WXUNUSED(vspacing) )
307{
308 wxPropertyGrid* propGrid = GetGrid();
309
310 VirtualHeightChanged();
311
312 // Recalculate caption text extents.
313 unsigned int i;
314
315 for ( i=0;i<m_regularArray.GetChildCount();i++ )
316 {
317 wxPGProperty* p =m_regularArray.Item(i);
318
319 if ( p->IsCategory() )
320 ((wxPropertyCategory*)p)->CalculateTextExtent(propGrid, propGrid->GetCaptionFont());
321 }
322}
323
324// -----------------------------------------------------------------------
325
326void wxPropertyGridPageState::SetVirtualWidth( int width )
327{
328 wxASSERT( width >= 0 );
329 wxPropertyGrid* pg = GetGrid();
330 int gw = pg->GetClientSize().x;
331 if ( width < gw )
332 width = gw;
333
334 m_width = width;
335}
336
337// -----------------------------------------------------------------------
338
339void wxPropertyGridPageState::OnClientWidthChange( int newWidth, int widthChange, bool fromOnResize )
340{
341 wxPropertyGrid* pg = GetGrid();
342
343 if ( pg->HasVirtualWidth() )
344 {
345 if ( m_width < newWidth )
346 SetVirtualWidth( newWidth );
347
348 CheckColumnWidths(widthChange);
349 }
350 else
351 {
352 SetVirtualWidth( newWidth );
353
354 // This should be done before splitter auto centering
355 // NOTE: Splitter auto-centering is done in this function.
356 if ( !fromOnResize )
357 widthChange = 0;
358 CheckColumnWidths(widthChange);
359
360 if ( !(GetGrid()->GetInternalFlags() & wxPG_FL_SPLITTER_PRE_SET) &&
361 (GetGrid()->GetInternalFlags() & wxPG_FL_DONT_CENTER_SPLITTER) )
362 {
363 long timeSinceCreation = (::wxGetLocalTimeMillis() - GetGrid()->m_timeCreated).ToLong();
364
365 // If too long, don't set splitter
366 if ( timeSinceCreation < 3000 )
367 {
368 if ( m_properties->GetChildCount() || timeSinceCreation > 750 )
369 {
370 SetSplitterLeft( false );
371 }
372 else
373 {
374 DoSetSplitterPosition( newWidth / 2 );
375 GetGrid()->ClearInternalFlag(wxPG_FL_SPLITTER_PRE_SET);
376 }
377 }
378 }
379 }
380}
381
382// -----------------------------------------------------------------------
383// wxPropertyGridPageState item iteration methods
384// -----------------------------------------------------------------------
385
386wxPGProperty* wxPropertyGridPageState::GetLastItem( int flags )
387{
388 if ( !m_properties->GetChildCount() )
389 return (wxPGProperty*) NULL;
390
391 wxPG_ITERATOR_CREATE_MASKS(flags, int itemExMask, int parentExMask)
392
393 // First, get last child of last parent
394 wxPGProperty* pwc = (wxPGProperty*)m_properties->Last();
395 while ( pwc->GetChildCount() &&
396 wxPG_ITERATOR_PARENTEXMASK_TEST(pwc, parentExMask) )
397 pwc = (wxPGProperty*) pwc->Last();
398
399 // Then, if it doesn't fit our criteria, back up until we find something that does
400 if ( pwc->GetFlags() & itemExMask )
401 {
402 wxPropertyGridIterator it( this, flags, pwc );
6bce2ad9
VZ
403 for ( ; !it.AtEnd(); it.Prev() )
404 ;
1c4293cb
VZ
405 pwc = (wxPGProperty*) it.GetProperty();
406 }
407
408 return pwc;
409}
410
411wxPropertyCategory* wxPropertyGridPageState::GetPropertyCategory( const wxPGProperty* p ) const
412{
413 const wxPGProperty* parent = (const wxPGProperty*)p;
414 const wxPGProperty* grandparent = (const wxPGProperty*)parent->GetParent();
415 do
416 {
417 parent = grandparent;
418 grandparent = (wxPGProperty*)parent->GetParent();
419 if ( parent->IsCategory() && grandparent )
420 return (wxPropertyCategory*)parent;
421 } while ( grandparent );
422
423 return (wxPropertyCategory*) NULL;
424}
425
426// -----------------------------------------------------------------------
427// wxPropertyGridPageState GetPropertyXXX methods
428// -----------------------------------------------------------------------
429
430wxPGProperty* wxPropertyGridPageState::GetPropertyByLabel( const wxString& label,
431 wxPGProperty* parent ) const
432{
433
434 size_t i;
435
436 if ( !parent ) parent = (wxPGProperty*) &m_regularArray;
437
438 for ( i=0; i<parent->GetChildCount(); i++ )
439 {
440 wxPGProperty* p = parent->Item(i);
441 if ( p->m_label == label )
442 return p;
443 // Check children recursively.
444 if ( p->GetChildCount() )
445 {
446 p = GetPropertyByLabel(label,(wxPGProperty*)p);
447 if ( p )
448 return p;
449 }
450 }
451
452 return NULL;
453}
454
455// -----------------------------------------------------------------------
456
457wxPGProperty* wxPropertyGridPageState::BaseGetPropertyByName( const wxString& name ) const
458{
459 wxPGHashMapS2P::const_iterator it;
460 it = m_dictName.find(name);
461 if ( it != m_dictName.end() )
462 return (wxPGProperty*) it->second;
463 return (wxPGProperty*) NULL;
464}
465
466// -----------------------------------------------------------------------
467// wxPropertyGridPageState global operations
468// -----------------------------------------------------------------------
469
470// -----------------------------------------------------------------------
471// Item iteration macros
472// NB: Nowadays only needed for alphabetic/categoric mode switching.
473// -----------------------------------------------------------------------
474
475#define II_INVALID_I 0x00FFFFFF
476
477#define ITEM_ITERATION_VARIABLES \
478 wxPGProperty* parent; \
479 unsigned int i; \
480 unsigned int iMax;
481
482#define ITEM_ITERATION_INIT_FROM_THE_TOP \
483 parent = m_properties; \
484 i = 0;
485
486#define ITEM_ITERATION_INIT(startparent, startindex, state) \
487 parent = startparent; \
488 i = (unsigned int)startindex; \
489 if ( parent == (wxPGProperty*) NULL ) \
490 { \
491 parent = state->m_properties; \
492 i = 0; \
493 }
494
495#define ITEM_ITERATION_LOOP_BEGIN \
496 do \
497 { \
498 iMax = parent->GetChildCount(); \
499 while ( i < iMax ) \
500 { \
501 wxPGProperty* p = parent->Item(i);
502
503#define ITEM_ITERATION_LOOP_END \
504 if ( p->GetChildCount() ) \
505 { \
506 i = 0; \
507 parent = (wxPGProperty*)p; \
508 iMax = parent->GetChildCount(); \
509 } \
510 else \
511 i++; \
512 } \
513 i = parent->m_arrIndex + 1; \
514 parent = parent->m_parent; \
515 } \
516 while ( parent != NULL );
517
518bool wxPropertyGridPageState::EnableCategories( bool enable )
519{
520 //
521 // NB: We can't use wxPropertyGridIterator in this
522 // function, since it depends on m_arrIndexes,
523 // which, among other things, is being fixed here.
524 //
525 ITEM_ITERATION_VARIABLES
526
527 if ( enable )
528 {
529 //
530 // Enable categories
531 //
532
533 if ( !IsInNonCatMode() )
534 return false;
535
536 m_properties = &m_regularArray;
537
538 // fix parents, indexes, and depths
539 ITEM_ITERATION_INIT_FROM_THE_TOP
540
541 ITEM_ITERATION_LOOP_BEGIN
542
543 p->m_arrIndex = i;
544
545 p->m_parent = parent;
546
547 // If parent was category, and this is not,
548 // then the depth stays the same.
549 if ( parent->IsCategory() &&
550 !p->IsCategory() )
551 p->m_depth = parent->m_depth;
552 else
553 p->m_depth = parent->m_depth + 1;
554
555 ITEM_ITERATION_LOOP_END
556
557 }
558 else
559 {
560 //
561 // Disable categories
562 //
563
564 if ( IsInNonCatMode() )
565 return false;
566
567 // Create array, if necessary.
568 if ( !m_abcArray )
569 InitNonCatMode();
570
571 m_properties = m_abcArray;
572
573 // fix parents, indexes, and depths
574 ITEM_ITERATION_INIT_FROM_THE_TOP
575
576 ITEM_ITERATION_LOOP_BEGIN
577
578 p->m_arrIndex = i;
579
580 p->m_parent = parent;
581
582 p->m_depth = parent->m_depth + 1;
583
584 ITEM_ITERATION_LOOP_END
585 }
586
587 VirtualHeightChanged();
588
589 if ( m_pPropGrid->GetState() == this )
590 m_pPropGrid->RecalculateVirtualSize();
591
592 return true;
593}
594
595// -----------------------------------------------------------------------
596
597static int wxPG_SortFunc(void **p1, void **p2)
598{
599 wxPGProperty *pp1 = *((wxPGProperty**)p1);
600 wxPGProperty *pp2 = *((wxPGProperty**)p2);
601 return pp1->GetLabel().compare( pp2->GetLabel() );
602}
603
604void wxPropertyGridPageState::SortChildren( wxPGProperty* p )
605{
606 if ( !p )
607 p = (wxPGProperty*)m_properties;
608
609 if ( !p->GetChildCount() )
610 return;
611
612 wxPGProperty* pwc = (wxPGProperty*)p;
613
614 // Can only sort items with children
615 if ( pwc->GetChildCount() < 1 )
616 return;
617
618 pwc->m_children.Sort( wxPG_SortFunc );
619
620 // Fix indexes
621 pwc->FixIndexesOfChildren();
622
623}
624
625// -----------------------------------------------------------------------
626
627void wxPropertyGridPageState::Sort()
628{
629 SortChildren( m_properties );
630
631 // Sort categories as well
632 if ( !IsInNonCatMode() )
633 {
634 size_t i;
635 for ( i=0;i<m_properties->GetChildCount();i++)
636 {
637 wxPGProperty* p = m_properties->Item(i);
638 if ( p->IsCategory() )
639 SortChildren( p );
640 }
641 }
642}
643
644// -----------------------------------------------------------------------
645// wxPropertyGridPageState splitter, column and hittest functions
646// -----------------------------------------------------------------------
647
648wxPGProperty* wxPropertyGridPageState::DoGetItemAtY( int y ) const
649{
650 // Outside?
651 if ( y < 0 )
652 return (wxPGProperty*) NULL;
653
654 unsigned int a = 0;
655 return m_properties->GetItemAtY(y, GetGrid()->m_lineHeight, &a);
656}
657
658// -----------------------------------------------------------------------
659
660wxPropertyGridHitTestResult wxPropertyGridPageState::HitTest( const wxPoint&pt ) const
661{
662 wxPropertyGridHitTestResult result;
663 result.column = HitTestH( pt.x, &result.splitter, &result.splitterHitOffset );
664 result.property = DoGetItemAtY( pt.y );
665 return result;
666}
667
668// -----------------------------------------------------------------------
669
670// Used by SetSplitterLeft() and DotFitColumns()
671int wxPropertyGridPageState::GetColumnFitWidth(wxClientDC& dc,
672 wxPGProperty* pwc,
673 unsigned int col,
674 bool subProps) const
675{
676 wxPropertyGrid* pg = m_pPropGrid;
677 size_t i;
678 int maxW = 0;
679 int w, h;
680
681 for ( i=0; i<pwc->GetChildCount(); i++ )
682 {
683 wxPGProperty* p = pwc->Item(i);
684 if ( !p->IsCategory() )
685 {
686 dc.GetTextExtent( p->GetColumnText(col), &w, &h );
687 if ( col == 0 )
688 w += ( ((int)p->m_depth-1) * pg->m_subgroup_extramargin );
689
690 //
691 // TODO: Add bitmap support.
692
693 w += (wxPG_XBEFORETEXT*2);
694
695 if ( w > maxW )
696 maxW = w;
697 }
698
699 if ( p->GetChildCount() &&
700 ( subProps || p->IsCategory() ) )
701 {
702 w = GetColumnFitWidth( dc, p, col, subProps );
703
704 if ( w > maxW )
705 maxW = w;
706 }
707 }
708
709 return maxW;
710}
711
712int wxPropertyGridPageState::DoGetSplitterPosition( int splitterColumn ) const
713{
714 int n = GetGrid()->m_marginWidth;
715 int i;
716 for ( i=0; i<=splitterColumn; i++ )
717 n += m_colWidths[i];
718 return n;
719}
720
721int wxPropertyGridPageState::GetColumnMinWidth( int WXUNUSED(column) ) const
722{
723 return wxPG_DRAG_MARGIN;
724}
725
726void wxPropertyGridPageState::PropagateColSizeDec( int column, int decrease, int dir )
727{
728 int origWidth = m_colWidths[column];
729 m_colWidths[column] -= decrease;
730 int min = GetColumnMinWidth(column);
731 int more = 0;
732 if ( m_colWidths[column] < min )
733 {
734 more = decrease - (origWidth - min);
735 m_colWidths[column] = min;
736 }
737
738 //
739 // FIXME: Causes erratic splitter changing, so as a workaround
740 // disabled if two or less columns.
741
742 if ( m_colWidths.size() <= 2 )
743 return;
744
745 column += dir;
746 if ( more && column < (int)m_colWidths.size() && column >= 0 )
747 PropagateColSizeDec( column, more, dir );
748}
749
750void wxPropertyGridPageState::DoSetSplitterPosition( int newXPos, int splitterColumn, bool WXUNUSED(allPages), bool fromAutoCenter )
751{
752 wxPropertyGrid* pg = GetGrid();
753
754 int adjust = newXPos - DoGetSplitterPosition(splitterColumn);
755
756 if ( !pg->HasVirtualWidth() )
757 {
758 // No virtual width
759 int otherColumn;
760 if ( adjust > 0 )
761 {
762 otherColumn = splitterColumn + 1;
763 if ( otherColumn == (int)m_colWidths.size() )
764 otherColumn = 0;
765 m_colWidths[splitterColumn] += adjust;
766 PropagateColSizeDec( otherColumn, adjust, 1 );
767 }
768 else
769 {
770 otherColumn = splitterColumn + 1;
771 if ( otherColumn == (int)m_colWidths.size() )
772 otherColumn = 0;
773 m_colWidths[otherColumn] -= adjust;
774 PropagateColSizeDec( splitterColumn, -adjust, -1 );
775 }
776 }
777 else
778 {
779 m_colWidths[splitterColumn] += adjust;
780 }
781
782 if ( splitterColumn == 0 )
783 m_fSplitterX = (double) newXPos;
784
785 if ( !fromAutoCenter )
786 {
787 // Don't allow initial splitter auto-positioning after this.
788 if ( pg->GetState() == this )
789 pg->SetInternalFlag(wxPG_FL_SPLITTER_PRE_SET);
790
791 CheckColumnWidths();
792 }
793}
794
795// Moves splitter so that all labels are visible, but just.
796void wxPropertyGridPageState::SetSplitterLeft( bool subProps )
797{
798 wxPropertyGrid* pg = GetGrid();
799 wxClientDC dc(pg);
800 dc.SetFont(pg->m_font);
801
802 int maxW = GetColumnFitWidth(dc, m_properties, 0, subProps);
803
804 if ( maxW > 0 )
805 {
806 maxW += pg->m_marginWidth;
807 DoSetSplitterPosition( maxW );
808 }
809
810 pg->SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER);
811}
812
813wxSize wxPropertyGridPageState::DoFitColumns( bool WXUNUSED(allowGridResize) )
814{
815 wxPropertyGrid* pg = GetGrid();
816 wxClientDC dc(pg);
817 dc.SetFont(pg->m_font);
818
819 int marginWidth = pg->m_marginWidth;
820 int accWid = marginWidth;
821 int maxColWidth = 500;
822
823 for ( unsigned int col=0; col < GetColumnCount(); col++ )
824 {
825 int fitWid = GetColumnFitWidth(dc, m_properties, col, true);
826 int colMinWidth = GetColumnMinWidth(col);
827 if ( fitWid < colMinWidth )
828 fitWid = colMinWidth;
829 else if ( fitWid > maxColWidth )
830 fitWid = maxColWidth;
831
832 m_colWidths[col] = fitWid;
833
834 accWid += fitWid;
835 }
836
837 // Expand last one to fill the width
838 int remaining = m_width - accWid;
839 m_colWidths[GetColumnCount()-1] += remaining;
840
841 pg->SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER);
842
843 int firstSplitterX = marginWidth + m_colWidths[0];
844 m_fSplitterX = (double) firstSplitterX;
845
846 // Don't allow initial splitter auto-positioning after this.
847 if ( pg->GetState() == this )
848 {
849 pg->SetSplitterPosition(firstSplitterX, false);
850 pg->Refresh();
851 }
852
853 int x, y;
854 pg->GetVirtualSize(&x, &y);
855
856 return wxSize(accWid, y);
857}
858
859void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
860{
861 if ( m_width == 0 )
862 return;
863
864 wxPropertyGrid* pg = GetGrid();
865
866#ifdef __WXDEBUG__
867 const bool debug = false;
868#endif
869
870 unsigned int i;
871 unsigned int lastColumn = m_colWidths.size() - 1;
872 int width = m_width;
873 int clientWidth = pg->GetClientSize().x;
874
875 //
876 // Column to reduce, if needed. Take last one that exceeds minimum width.
877 // Except if auto splitter centering is used, in which case use widest.
878 int reduceCol = -1;
879 int highestColWidth = 0;
880
881 bool minimizedCols = false;
882
883#ifdef __WXDEBUG__
884 if ( debug )
885 wxLogDebug(wxT("ColumnWidthCheck (virtualWidth: %i, clientWidth: %i)"), width, clientWidth);
886#endif
887
888 //
889 // Check min sizes
890 for ( i=0; i<m_colWidths.size(); i++ )
891 {
892 int min = GetColumnMinWidth(i);
893 if ( m_colWidths[i] <= min )
894 {
895 m_colWidths[i] = min;
896 minimizedCols = true;
897 }
898 else
899 {
900 if ( pg->HasFlag(wxPG_SPLITTER_AUTO_CENTER) )
901 {
902 if ( m_colWidths[i] >= highestColWidth )
903 {
904 highestColWidth = m_colWidths[i];
905 reduceCol = i;
906 }
907 }
908 else
909 {
910 reduceCol = i;
911 }
912 }
913 }
914
915 int colsWidth = pg->m_marginWidth;
916 for ( i=0; i<m_colWidths.size(); i++ )
917 colsWidth += m_colWidths[i];
918
919#ifdef __WXDEBUG__
920 if ( debug )
921 wxLogDebug(wxT(" HasVirtualWidth: %i colsWidth: %i"),(int)pg->HasVirtualWidth(),colsWidth);
922#endif
923
924 // Then mode-based requirement
925 if ( !pg->HasVirtualWidth() )
926 {
927 int widthHigher = width - colsWidth;
928
929 // Adapt colsWidth to width
930 if ( colsWidth < width )
931 {
932 // Increase column
933 #ifdef __WXDEBUG__
934 if ( debug )
935 wxLogDebug(wxT(" Adjust last column to %i"), m_colWidths[lastColumn] + widthHigher);
936 #endif
937 m_colWidths[lastColumn] = m_colWidths[lastColumn] + widthHigher;
938 }
939 else if ( colsWidth > width )
940 {
941 // Reduce column
942 if ( reduceCol != -1 )
943 {
944 #ifdef __WXDEBUG__
945 if ( debug )
946 wxLogDebug(wxT(" Reduce column %i (by %i)"), reduceCol, -widthHigher);
947 #endif
948 // Reduce widest column, and recheck
949 m_colWidths[reduceCol] = m_colWidths[reduceCol] + widthHigher;
950 CheckColumnWidths();
951 }
952 }
953 }
954 else
955 {
956 // Only check colsWidth against clientWidth
957 if ( colsWidth < clientWidth )
958 {
959 m_colWidths[lastColumn] = m_colWidths[lastColumn] + (clientWidth-colsWidth);
960 }
961
962 m_width = colsWidth;
963
964 // If width changed, recalculate virtual size
965 if ( pg->GetState() == this )
966 pg->RecalculateVirtualSize();
967 }
968
969#ifdef __WXDEBUG__
970 if ( debug )
971 for ( i=0; i<m_colWidths.size(); i++ )
972 wxLogDebug(wxT("col%i: %i"),i,m_colWidths[i]);
973#endif
974
975 // Auto center splitter
976 if ( !(pg->GetInternalFlags() & wxPG_FL_DONT_CENTER_SPLITTER) &&
977 m_colWidths.size() == 2 )
978 {
979 float centerX = (float)(pg->m_width/2);
980 float splitterX;
981
982 if ( m_fSplitterX < 0.0 )
983 {
984 splitterX = centerX;
985 }
986 else if ( widthChange )
987 {
988 //float centerX = float(pg->GetSize().x) * 0.5;
989
990 // Recenter?
991 splitterX = m_fSplitterX + (float(widthChange) * 0.5);
992 float deviation = fabs(centerX - splitterX);
993
994 // If deviating from center, adjust towards it
995 if ( deviation > 20.0 )
996 {
997 if ( splitterX > centerX)
998 splitterX -= 2;
999 else
1000 splitterX += 2;
1001 }
1002 }
1003 else
1004 {
1005 // No width change, just keep sure we keep splitter position intact
1006 splitterX = m_fSplitterX;
1007 float deviation = fabs(centerX - splitterX);
1008 if ( deviation > 50.0 )
1009 {
1010 splitterX = centerX;
1011 }
1012 }
1013
1014 DoSetSplitterPosition((int)splitterX, 0, false, true);
1015
1016 m_fSplitterX = splitterX; // needed to retain accuracy
1017 }
1018}
1019
1020void wxPropertyGridPageState::SetColumnCount( int colCount )
1021{
1022 wxASSERT( colCount >= 2 );
1023 m_colWidths.SetCount( colCount, wxPG_DRAG_MARGIN );
1024 if ( m_colWidths.size() > (unsigned int)colCount )
1025 m_colWidths.RemoveAt( m_colWidths.size(), m_colWidths.size() - colCount );
1026
1027 if ( m_pPropGrid->GetState() == this )
1028 m_pPropGrid->RecalculateVirtualSize();
1029 else
1030 CheckColumnWidths();
1031}
1032
1033// Returns column index, -1 for margin
1034int wxPropertyGridPageState::HitTestH( int x, int* pSplitterHit, int* pSplitterHitOffset ) const
1035{
1036 int cx = GetGrid()->m_marginWidth;
1037 int col = -1;
1038 int prevSplitter = -1;
1039
1040 while ( x > cx )
1041 {
1042 col++;
1043 if ( col >= (int)m_colWidths.size() )
1044 {
1045 *pSplitterHit = -1;
1046 return col;
1047 }
1048 prevSplitter = cx;
1049 cx += m_colWidths[col];
1050 }
1051
1052 // Near prev. splitter
1053 if ( col >= 1 )
1054 {
1055 int diff = x - prevSplitter;
1056 if ( abs(diff) < wxPG_SPLITTERX_DETECTMARGIN1 )
1057 {
1058 *pSplitterHit = col - 1;
1059 *pSplitterHitOffset = diff;
1060 return col;
1061 }
1062 }
1063
1064 // Near next splitter
1065 int nextSplitter = cx;
1066 if ( col < (int)(m_colWidths.size()-1) )
1067 {
1068 int diff = x - nextSplitter;
1069 if ( abs(diff) < wxPG_SPLITTERX_DETECTMARGIN1 )
1070 {
1071 *pSplitterHit = col;
1072 *pSplitterHitOffset = diff;
1073 return col;
1074 }
1075 }
1076
1077 *pSplitterHit = -1;
1078 return col;
1079}
1080
1081// -----------------------------------------------------------------------
1082// wxPropertyGridPageState property value setting and getting
1083// -----------------------------------------------------------------------
1084
1085bool wxPropertyGridPageState::DoSetPropertyValueString( wxPGProperty* p, const wxString& value )
1086{
1087 if ( p )
1088 {
1089 int flags = wxPG_REPORT_ERROR|wxPG_FULL_VALUE;
1090
1091 wxVariant variant = p->GetValueRef();
1092 bool res;
1093
1094 if ( p->GetMaxLength() <= 0 )
1095 res = p->StringToValue( variant, value, flags );
1096 else
1097 res = p->StringToValue( variant, value.Mid(0,p->GetMaxLength()), flags );
1098
1099 if ( res )
1100 {
1101 p->SetValue(variant);
1102 if ( m_selected==p && this==m_pPropGrid->GetState() )
1103 p->UpdateControl(m_pPropGrid->GetEditorControl());
1104 }
1105
1106 return true;
1107 }
1108 return false;
1109}
1110
1111// -----------------------------------------------------------------------
1112
1113bool wxPropertyGridPageState::DoSetPropertyValue( wxPGProperty* p, wxVariant& value )
1114{
1115 if ( p )
1116 {
1117 p->SetValue(value);
1118 if ( m_selected==p && this==m_pPropGrid->GetState() )
1119 p->UpdateControl(m_pPropGrid->GetEditorControl());
1120
1121 return true;
1122 }
1123 return false;
1124}
1125
1126// -----------------------------------------------------------------------
1127
1128bool wxPropertyGridPageState::DoSetPropertyValueWxObjectPtr( wxPGProperty* p, wxObject* value )
1129{
1130 if ( p )
1131 {
1132 // wnd_primary has to be given so the control can be updated as well.
1133 wxVariant v(value);
1134 DoSetPropertyValue(p, v);
1135 return true;
1136 }
1137 return false;
1138}
1139
1140// -----------------------------------------------------------------------
1141
1142void wxPropertyGridPageState::DoSetPropertyValueUnspecified( wxPGProperty* p )
1143{
1144 wxCHECK_RET( p, wxT("invalid property id") );
1145
1146 if ( !p->IsValueUnspecified() )
1147 {
1148 // Value should be set first - editor class methods may need it
1149 p->m_value.MakeNull();
1150
1151 wxASSERT( m_pPropGrid );
1152
1153 if ( m_pPropGrid->GetState() == this )
1154 {
1155 if ( m_pPropGrid->m_selected == p && m_pPropGrid->m_wndEditor )
1156 {
1157 p->GetEditorClass()->SetValueToUnspecified(p, m_pPropGrid->GetEditorControl());
1158 }
1159 }
1160
1161 unsigned int i;
1162 for ( i = 0; i < p->GetChildCount(); i++ )
1163 DoSetPropertyValueUnspecified( p->Item(i) );
1164 }
1165}
1166
1167// -----------------------------------------------------------------------
1168// wxPropertyGridPageState property operations
1169// -----------------------------------------------------------------------
1170
1171bool wxPropertyGridPageState::DoCollapse( wxPGProperty* p )
1172{
1173 wxCHECK_MSG( p, false, wxT("invalid property id") );
1174
1175 if ( !p->GetChildCount() ) return false;
1176
1177 if ( !p->IsExpanded() ) return false;
1178
1179 p->SetExpanded(false);
1180
1181 VirtualHeightChanged();
1182
1183 return true;
1184}
1185
1186// -----------------------------------------------------------------------
1187
1188bool wxPropertyGridPageState::DoExpand( wxPGProperty* p )
1189{
1190 wxCHECK_MSG( p, false, wxT("invalid property id") );
1191
1192 if ( !p->GetChildCount() ) return false;
1193
1194 if ( p->IsExpanded() ) return false;
1195
1196 p->SetExpanded(true);
1197
1198 VirtualHeightChanged();
1199
1200 return true;
1201}
1202
1203// -----------------------------------------------------------------------
1204
1205bool wxPropertyGridPageState::DoSelectProperty( wxPGProperty* p, unsigned int flags )
1206{
1207 if ( this == m_pPropGrid->GetState() )
1208 return m_pPropGrid->DoSelectProperty( p, flags );
1209
1210 m_selected = p;
1211 return true;
1212}
1213
1214// -----------------------------------------------------------------------
1215
1216bool wxPropertyGridPageState::DoHideProperty( wxPGProperty* p, bool hide, int flags )
1217{
1218 if ( !hide )
1219 p->ClearFlag( wxPG_PROP_HIDDEN );
1220 else
1221 p->SetFlag( wxPG_PROP_HIDDEN );
1222
1223 if ( flags & wxPG_RECURSE )
1224 {
1225 unsigned int i;
1226 for ( i = 0; i < p->GetChildCount(); i++ )
1227 DoHideProperty(p->Item(i), hide, flags | wxPG_RECURSE_STARTS);
1228 }
1229
1230 VirtualHeightChanged();
1231
1232 return true;
1233}
1234
1235// -----------------------------------------------------------------------
1236
1237bool wxPropertyGridPageState::DoEnableProperty( wxPGProperty* p, bool enable )
1238{
1239 if ( p )
1240 {
1241 if ( enable )
1242 {
1243 if ( !(p->m_flags & wxPG_PROP_DISABLED) )
1244 return false;
1245
1246 // Enabling
1247
1248 p->m_flags &= ~(wxPG_PROP_DISABLED);
1249 }
1250 else
1251 {
1252 if ( p->m_flags & wxPG_PROP_DISABLED )
1253 return false;
1254
1255 // Disabling
1256
1257 p->m_flags |= wxPG_PROP_DISABLED;
1258
1259 }
1260
1261 // Apply same to sub-properties as well
1262 unsigned int i;
1263 for ( i = 0; i < p->GetChildCount(); i++ )
1264 DoEnableProperty( p->Item(i), enable );
1265
1266 return true;
1267 }
1268 return false;
1269}
1270
1271// -----------------------------------------------------------------------
1272// wxPropertyGridPageState wxVariant related routines
1273// -----------------------------------------------------------------------
1274
1275// Returns list of wxVariant objects (non-categories and non-sub-properties only).
1276// Never includes sub-properties (unless they are parented by wxParentProperty).
1277wxVariant wxPropertyGridPageState::DoGetPropertyValues( const wxString& listname,
1278 wxPGProperty* baseparent,
1279 long flags ) const
1280{
1281 wxPGProperty* pwc = (wxPGProperty*) baseparent;
1282
1283 // Root is the default base-parent.
1284 if ( !pwc )
1285 pwc = m_properties;
1286
1287 wxVariantList tempList;
1288 wxVariant v( tempList, listname );
1289
1290 if ( pwc->GetChildCount() )
1291 {
1292 if ( flags & wxPG_KEEP_STRUCTURE )
1293 {
1294 wxASSERT( !pwc->HasFlag(wxPG_PROP_AGGREGATE) );
1295
1296 size_t i;
1297 for ( i=0; i<pwc->GetChildCount(); i++ )
1298 {
1299 wxPGProperty* p = pwc->Item(i);
1300 if ( !p->GetChildCount() || p->HasFlag(wxPG_PROP_AGGREGATE) )
1301 {
1302 wxVariant variant = p->GetValue();
1303 variant.SetName( p->GetBaseName() );
1304 v.Append( variant );
1305 }
1306 else
1307 {
1308 v.Append( DoGetPropertyValues(p->m_name,p,flags|wxPG_KEEP_STRUCTURE) );
1309 }
1310 if ( (flags & wxPG_INC_ATTRIBUTES) && p->m_attributes.GetCount() )
1311 v.Append( p->GetAttributesAsList() );
1312 }
1313 }
1314 else
1315 {
1316 wxPropertyGridConstIterator it( this, wxPG_ITERATE_DEFAULT, pwc->Item(0) );
1317 it.SetBaseParent( pwc );
1318
1319 for ( ; !it.AtEnd(); it.Next() )
1320 {
1321 const wxPGProperty* p = it.GetProperty();
1322
1323 // Use a trick to ignore wxParentProperty itself, but not its sub-properties.
1324 if ( !p->GetChildCount() || p->HasFlag(wxPG_PROP_AGGREGATE) )
1325 {
1326 wxVariant variant = p->GetValue();
1327 variant.SetName( p->GetName() );
1328 v.Append( variant );
1329 if ( (flags & wxPG_INC_ATTRIBUTES) && p->m_attributes.GetCount() )
1330 v.Append( p->GetAttributesAsList() );
1331 }
1332 }
1333 }
1334 }
1335
1336 return v;
1337}
1338
1339// -----------------------------------------------------------------------
1340
1341void wxPropertyGridPageState::DoSetPropertyValues( const wxVariantList& list, wxPGProperty* defaultCategory )
1342{
1343 unsigned char origFrozen = 1;
1344
1345 if ( m_pPropGrid->GetState() == this )
1346 {
1347 origFrozen = m_pPropGrid->m_frozen;
1348 if ( !origFrozen ) m_pPropGrid->Freeze();
1349 }
1350
1351 wxPropertyCategory* use_category = (wxPropertyCategory*)defaultCategory;
1352
1353 if ( !use_category )
1354 use_category = (wxPropertyCategory*)m_properties;
1355
1356 // Let's iterate over the list of variants.
1357 wxVariantList::const_iterator node;
1358 int numSpecialEntries = 0;
1359
1360 //
1361 // Second pass for special entries
1362 for ( node = list.begin(); node != list.end(); node++ )
1363 {
1364 wxVariant *current = (wxVariant*)*node;
1365
1366 // Make sure it is wxVariant.
1367 wxASSERT( current );
1368 wxASSERT( wxStrcmp(current->GetClassInfo()->GetClassName(),wxT("wxVariant")) == 0 );
1369
1370 const wxString& name = current->GetName();
1371 if ( name.length() > 0 )
1372 {
1373 //
1374 // '@' signified a special entry
1375 if ( name[0] == wxS('@') )
1376 {
1377 numSpecialEntries++;
1378 }
1379 else
1380 {
1381 wxPGProperty* foundProp = BaseGetPropertyByName(name);
1382 if ( foundProp )
1383 {
1384 wxPGProperty* p = foundProp;
1385
1386 // If it was a list, we still have to go through it.
1387 if ( wxStrcmp(current->GetType(), wxS("list")) == 0 )
1388 {
1389 DoSetPropertyValues( current->GetList(),
1390 p->IsCategory()?p:((wxPGProperty*)NULL)
1391 );
1392 }
1393 else
1394 {
1395 #ifdef __WXDEBUG__
1396 if ( wxStrcmp(current->GetType(), p->GetValue().GetType()) != 0)
1397 {
1398 wxLogDebug(wxT("wxPropertyGridPageState::DoSetPropertyValues Warning: Setting value of property \"%s\" from variant"),
1399 p->GetName().c_str());
1400 }
1401 #endif
1402
1403 p->SetValue(*current);
1404 }
1405 }
1406 else
1407 {
1408 // Is it list?
1409 if ( current->GetType() != wxS("list") )
1410 {
1411 // Not.
1412 }
1413 else
1414 {
1415 // Yes, it is; create a sub category and append contents there.
1416 wxPGProperty* newCat = DoInsert(use_category,-1,new wxPropertyCategory(current->GetName(),wxPG_LABEL));
1417 DoSetPropertyValues( current->GetList(), newCat );
1418 }
1419 }
1420 }
1421 }
1422 }
1423
1424 if ( numSpecialEntries )
1425 {
1426 for ( node = list.begin(); node != list.end(); node++ )
1427 {
1428 wxVariant *current = (wxVariant*)*node;
1429
1430 const wxString& name = current->GetName();
1431 if ( name.length() > 0 )
1432 {
1433 //
1434 // '@' signified a special entry
1435 if ( name[0] == wxS('@') )
1436 {
1437 numSpecialEntries--;
1438
1439 size_t pos2 = name.rfind(wxS('@'));
1440 if ( pos2 > 0 && pos2 < (name.size()-1) )
1441 {
1442 wxString propName = name.substr(1, pos2-1);
1443 wxString entryType = name.substr(pos2+1, wxString::npos);
1444
1445 if ( entryType == wxS("attr") )
1446 {
1447 //
1448 // List of attributes
1449 wxPGProperty* foundProp = BaseGetPropertyByName(propName);
1450 if ( foundProp )
1451 {
0372d42e 1452 wxASSERT( current->GetType() == wxPG_VARIANT_TYPE_LIST );
1c4293cb
VZ
1453
1454 wxVariantList& list2 = current->GetList();
1455 wxVariantList::const_iterator node2;
1456
1457 for ( node2 = list2.begin(); node2 != list2.end(); node2++ )
1458 {
1459 wxVariant *attr = (wxVariant*)*node2;
1460 foundProp->SetAttribute( attr->GetName(), *attr );
1461 }
1462 }
1463 else
1464 {
1465 // ERROR: No such property: 'propName'
1466 }
1467 }
1468 }
1469 else
1470 {
1471 // ERROR: Special entry requires name of format @<propname>@<entrytype>
1472 }
1473 }
1474 }
1475
1476 if ( !numSpecialEntries )
1477 break;
1478 }
1479 }
1480
1481 if ( !origFrozen )
1482 {
1483 m_pPropGrid->Thaw();
1484
1485 if ( this == m_pPropGrid->GetState() )
1486 {
1487 m_selected->UpdateControl(m_pPropGrid->GetEditorControl());
1488 }
1489 }
1490
1491}
1492
1493// -----------------------------------------------------------------------
1494// wxPropertyGridPageState property adding and removal
1495// -----------------------------------------------------------------------
1496
1497int wxPropertyGridPageState::PrepareToAddItem( wxPGProperty* property,
1498 wxPGProperty* scheduledParent )
1499{
1500 wxPropertyGrid* propGrid = m_pPropGrid;
1501
1502 // This will allow better behavior.
1503 if ( scheduledParent == m_properties )
1504 scheduledParent = (wxPGProperty*) NULL;
1505
d665918b
JS
1506 if ( scheduledParent && !scheduledParent->IsCategory() )
1507 {
1508 wxASSERT_MSG( property->GetBaseName().length(),
1509 "Property's children must have unique, non-empty names within their scope" );
1510 }
1511
1c4293cb
VZ
1512 property->m_parentState = this;
1513
1514 if ( property->IsCategory() )
1515 {
1516
1517 // Parent of a category must be either root or another category
1518 // (otherwise Bad Things might happen).
1519 wxASSERT_MSG( scheduledParent == NULL ||
1520 scheduledParent == m_properties ||
1521 scheduledParent->IsCategory(),
1522 wxT("Parent of a category must be either root or another category."));
1523
1524 // If we already have category with same name, delete given property
1525 // and use it instead as most recent caption item.
1526 wxPGProperty* found_id = BaseGetPropertyByName( property->GetBaseName() );
1527 if ( found_id )
1528 {
1529 wxPropertyCategory* pwc = (wxPropertyCategory*) found_id;
1530 if ( pwc->IsCategory() ) // Must be a category.
1531 {
1532 delete property;
1533 m_currentCategory = pwc;
1534 return 2; // Tells the caller what we did.
1535 }
1536 }
1537 }
1538
1539#ifdef __WXDEBUG__
1540 // Warn for identical names in debug mode.
1541 if ( BaseGetPropertyByName(property->GetName()) &&
1542 (!scheduledParent || scheduledParent->IsCategory()) )
1543 {
1544 wxLogError(wxT("wxPropertyGrid: Warning - item with name \"%s\" already exists."),
1545 property->GetName().c_str());
1546 wxPGGlobalVars->m_warnings++;
1547 }
1548#endif
1549
1550 // Make sure nothing is selected.
1551 if ( propGrid && propGrid->m_selected )
1552 {
1553 bool selRes = propGrid->ClearSelection();
1554 wxPG_CHECK_MSG_DBG( selRes,
1555 -1,
1556 wxT("failed to deselect a property (editor probably had invalid value)") );
1557 }
1558
1559 if ( scheduledParent )
1560 {
1561 // Use parent's colours.
1562 property->m_bgColIndex = scheduledParent->m_bgColIndex;
1563 property->m_fgColIndex = scheduledParent->m_fgColIndex;
1564
1565 // Fix no parent does not yet have parenting flag yet, set one now
1566 if ( !scheduledParent->HasFlag(wxPG_PROP_PARENTAL_FLAGS) )
1567 scheduledParent->SetParentalType(wxPG_PROP_MISC_PARENT);
1568 //scheduledParent->SetFlag(wxPG_PROP_MISC_PARENT);
1569 }
1570
1571 // If in hideable adding mode, or if assigned parent is hideable, then
1572 // make this one hideable.
1573 if (
1574 ( scheduledParent && (scheduledParent->m_flags & wxPG_PROP_HIDDEN) ) ||
1575 ( propGrid && (propGrid->m_iFlags & wxPG_FL_ADDING_HIDEABLES) )
1576 )
1577 property->SetFlag( wxPG_PROP_HIDDEN );
1578
1579 // Set custom image flag.
1580 int custImgHeight = property->OnMeasureImage().y;
1581 if ( custImgHeight < 0 /*|| custImgHeight > 1*/ )
1582 {
1583 property->m_flags |= wxPG_PROP_CUSTOMIMAGE;
1584 }
1585
1586 if ( propGrid && (propGrid->GetWindowStyleFlag() & wxPG_LIMITED_EDITING) )
1587 property->m_flags |= wxPG_PROP_NOEDITOR;
1588
1589 if ( !property->IsCategory() )
1590 {
1591 // This is not a category.
1592
1593 //wxASSERT_MSG( property->GetEditorClass(), wxT("Editor class not initialized!") );
1594
1595 // Depth.
1596 //
1597 unsigned char depth = 1;
1598 if ( scheduledParent )
1599 {
1600 depth = scheduledParent->m_depth;
1601 if ( !scheduledParent->IsCategory() )
1602 depth++;
1603 }
1604 property->m_depth = depth;
1605 unsigned char greyDepth = depth;
1606
1607 if ( scheduledParent )
1608 {
1609 wxPropertyCategory* pc;
1610
1611 if ( scheduledParent->IsCategory() || scheduledParent->IsRoot() )
1612 pc = (wxPropertyCategory*)scheduledParent;
1613 else
1614 // This conditional compile is necessary to
1615 // bypass some compiler bug.
1616 pc = GetPropertyCategory(scheduledParent);
1617
1618 if ( pc )
1619 greyDepth = pc->GetDepth();
1620 else
1621 greyDepth = scheduledParent->m_depthBgCol;
1622 }
1623
1624 property->m_depthBgCol = greyDepth;
1625
1626 // Prepare children pre-added children
1627 if ( property->GetChildCount() )
1628 {
1629 property->SetParentalType(wxPG_PROP_AGGREGATE);
1630
1631 property->SetExpanded(false); // Properties with children are not expanded by default.
1632 if ( propGrid && propGrid->GetWindowStyleFlag() & wxPG_HIDE_MARGIN )
1633 property->SetExpanded(true); // ...unless it cannot be expanded.
1634
1635 property->PrepareSubProperties();
1636
1637 return -1;
1638 }
1639
1640 if ( propGrid && (propGrid->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES) )
1641 property->SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED, true);
1642
1643 return 0;
1644 }
1645 else
1646 {
1647 // This is a category.
1648
1649 // depth
1650 unsigned char depth = 1;
1651 if ( scheduledParent )
1652 {
1653 depth = scheduledParent->m_depth + 1;
1654 }
1655 property->m_depth = depth;
1656 property->m_depthBgCol = depth;
1657
1658 m_currentCategory = (wxPropertyCategory*)property;
1659
1660 wxPropertyCategory* pc = (wxPropertyCategory*)property;
1661
1662 // Calculate text extent for caption item.
1663 if ( propGrid )
1664 pc->CalculateTextExtent(propGrid, propGrid->GetCaptionFont());
1665
1666 return 1;
1667 }
1668}
1669
1670// -----------------------------------------------------------------------
1671
1672wxPGProperty* wxPropertyGridPageState::DoAppend( wxPGProperty* property )
1673{
1674 wxPropertyCategory* cur_cat = m_currentCategory;
1675 if ( property->IsCategory() )
1676 cur_cat = (wxPropertyCategory*) NULL;
1677
1678 return DoInsert( cur_cat, -1, property );
1679}
1680
1681// -----------------------------------------------------------------------
1682
1683wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index, wxPGProperty* property )
1684{
1685 if ( !parent )
1686 parent = m_properties;
1687
1688 wxCHECK_MSG( !parent->HasFlag(wxPG_PROP_AGGREGATE),
1689 wxNullProperty,
1690 wxT("when adding properties to fixed parents, use BeginAddChildren and EndAddChildren.") );
1691
1692 int parenting = PrepareToAddItem( property, (wxPropertyCategory*)parent );
1693
1694 // This type of invalid parenting value indicates we should exit now, returning
1695 // id of most recent category.
1696 if ( parenting > 1 )
1697 return m_currentCategory;
1698
1699 // Note that item must be added into current mode later.
1700
1701 // If parent is wxParentProperty, just stick it in...
1702 // If parent is root (m_properties), then...
1703 // In categoric mode: Add as last item in m_abcArray (if not category).
1704 // Add to given index in m_regularArray.
1705 // In non-cat mode: Add as last item in m_regularArray.
1706 // Add to given index in m_abcArray.
1707 // If parent is category, then...
1708 // 1) Add to given category in given index.
1709 // 2) Add as last item in m_abcArray.
1710
1711 if ( !parent->IsCategory() && !parent->IsRoot() )
1712 {
1713 // Parent is wxParentingProperty: Just stick it in...
1714 parent->AddChild2( property, index );
1715 }
1716 else
1717 {
1718 // Parent is Category or Root.
1719
1720 if ( m_properties == &m_regularArray )
1721 {
1722 // Categorized mode
1723
1724 // Only add non-categories to m_abcArray.
1725 if ( m_abcArray && parenting <= 0 )
1726 m_abcArray->AddChild2( property, -1, false );
1727
1728 // Add to current mode.
1729 parent->AddChild2( property, index );
1730
1731 }
1732 else
1733 {
1734 // Non-categorized mode.
1735
1736 if ( parent != m_properties )
1737 // Parent is category.
1738 parent->AddChild2( property, index, false );
1739 else
1740 // Parent is root.
1741 m_regularArray.AddChild2( property, -1, false );
1742
1743 // Add to current mode (no categories).
1744 if ( parenting <= 0 )
1745 m_abcArray->AddChild2( property, index );
1746 }
1747 }
1748
1749 // category stuff
1750 if ( property->IsCategory() )
1751 {
1752 // This is a category caption item.
1753
1754 // Last caption is not the bottom one (this info required by append)
1755 m_lastCaptionBottomnest = 0;
1756 }
1757
1758 // Only add name to hashmap if parent is root or category
1759 if ( (parent->IsCategory() || parent->IsRoot()) && property->m_name.length() )
1760 m_dictName[property->m_name] = (void*) property;
1761
1762 VirtualHeightChanged();
1763
1764 property->UpdateParentValues();
1765
1766 m_itemsAdded = 1;
1767
1768 return property;
1769}
1770
1771// -----------------------------------------------------------------------
1772
1773void wxPropertyGridPageState::DoDelete( wxPGProperty* item )
1774{
1775 wxCHECK_RET( item->GetParent(),
1776 wxT("this property was already deleted") );
1777
1778 wxCHECK_RET( item != &m_regularArray && item != m_abcArray,
1779 wxT("wxPropertyGrid: Do not attempt to remove the root item.") );
1780
1781 size_t i;
1782 unsigned int indinparent = item->GetIndexInParent();
1783
1784 wxPGProperty* pwc = (wxPGProperty*)item;
1785
1786 wxCHECK_RET( !item->GetParent()->HasFlag(wxPG_PROP_AGGREGATE),
1787 wxT("wxPropertyGrid: Do not attempt to remove sub-properties.") );
1788
1789 if ( item->IsCategory() )
1790 {
1791 // deleting a category
1792
1793 // erase category entries from the hash table
1794 for ( i=0; i<pwc->GetChildCount(); i++ )
1795 {
1796 wxPGProperty* sp = pwc->Item( i );
1797 if ( sp->GetBaseName().Len() ) m_dictName.erase(sp->GetBaseName());
1798 }
1799
1800 if ( pwc == m_currentCategory )
1801 m_currentCategory = (wxPropertyCategory*) NULL;
1802
1803 if ( m_abcArray )
1804 {
1805 // Remove children from non-categorized array.
1806 for ( i=0; i<pwc->GetChildCount(); i++ )
1807 {
1808 wxPGProperty * p = pwc->Item( i );
1809 wxASSERT( p != NULL );
1810 if ( !p->IsCategory() )
1811 m_abcArray->m_children.Remove( p );
1812 }
1813
1814 if ( IsInNonCatMode() )
1815 m_abcArray->FixIndexesOfChildren();
1816 }
1817 }
1818
1819 if ( !IsInNonCatMode() )
1820 {
1821 // categorized mode - non-categorized array
1822
1823 // Remove from non-cat array, but only if parent is in it
1824 if ( !item->IsCategory() && item->GetParent()->IsCategory() )
1825 {
1826 if ( m_abcArray )
1827 {
1828 m_abcArray->m_children.Remove( item );
1829 }
1830 }
1831
1832 // categorized mode - categorized array
1833 item->m_parent->m_children.RemoveAt(indinparent);
1834 item->m_parent->FixIndexesOfChildren(/*indinparent*/);
1835 }
1836 else
1837 {
1838 // non-categorized mode - categorized array
1839
1840 // We need to find location of item.
1841 wxPGProperty* cat_parent = &m_regularArray;
1842 int cat_index = m_regularArray.GetChildCount();
1843 size_t i;
1844 for ( i = 0; i < m_regularArray.GetChildCount(); i++ )
1845 {
1846 wxPGProperty* p = m_regularArray.Item(i);
1847 if ( p == item ) { cat_index = i; break; }
1848 if ( p->IsCategory() )
1849 {
1850 int subind = ((wxPGProperty*)p)->Index(item);
1851 if ( subind != wxNOT_FOUND )
1852 {
1853 cat_parent = ((wxPGProperty*)p);
1854 cat_index = subind;
1855 break;
1856 }
1857 }
1858 }
1859 cat_parent->m_children.RemoveAt(cat_index);
1860
1861 // non-categorized mode - non-categorized array
1862 if ( !item->IsCategory() )
1863 {
1864 wxASSERT( item->m_parent == m_abcArray );
1865 item->m_parent->m_children.RemoveAt(indinparent);
1866 item->m_parent->FixIndexesOfChildren(indinparent);
1867 }
1868 }
1869
1870 if ( item->GetBaseName().Len() ) m_dictName.erase(item->GetBaseName());
1871
1872 // We can actually delete it now
1873 delete item;
1874
1875 m_itemsAdded = 1; // Not a logical assignment (but required nonetheless).
1876
1877 VirtualHeightChanged();
1878}
1879
1880// -----------------------------------------------------------------------
f4bc1aa2
JS
1881
1882#endif // wxUSE_PROPGRID