]> git.saurik.com Git - wxWidgets.git/blob - utils/framelayout/samples/demo/wxinfo.cpp
bug with object being passed through ... corrected
[wxWidgets.git] / utils / framelayout / samples / demo / wxinfo.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: No names yet.
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by:
6 // Created: 23/11/98
7 // RCS-ID: $Id$
8 // Copyright: 1998 (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "wxinifo.cpp"
14 #pragma interface "wxinifo.cpp"
15 #endif
16
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WX_PRECOMP
25 #include "wx/wx.h"
26 #endif
27
28 #include "wx/hash.h"
29 #include "wxinfo.h"
30
31 inline static void expand_item( wxTreeCtrl* pTree, wxTreeItemId& itemId )
32 {
33 pTree->Expand( itemId );
34 }
35
36 void wxCreateClassInfoTree( wxTreeCtrl* pTree,
37 wxTreeItemId parentBranchId,
38 long classImageNo
39 )
40 {
41 expand_item( pTree, parentBranchId );
42
43 wxHashTable hash;
44
45 wxList lst;
46
47 // collect all classes into list
48
49 {
50 wxClassInfo* pCur = wxClassInfo::GetFirst();
51
52 wxClassInfo::InitializeClasses();
53
54 while( pCur )
55 {
56 lst.Append( (wxObject*)pCur );
57
58 pCur = pCur->GetNext();
59 }
60 }
61
62 wxClassInfo::InitializeClasses();
63
64 // reflect class-hierarchy into the tree nodes
65
66 int nHanged;
67
68 do
69 {
70 nHanged = 0;
71
72 wxNode* pCur = lst.First();
73
74 // repeat passes through class list, untill all of
75 // the class items are "hanged" onto their parent-items in the tree
76
77 while( pCur )
78 {
79 wxClassInfo& info = *((wxClassInfo*)pCur->Data());
80
81 if ( info.GetBaseClass1() == NULL )
82 {
83 // parentless classes are put into the root branch
84
85 wxTreeItemId* pId = new wxTreeItemId();
86 *pId = pTree->AppendItem( parentBranchId, info.GetClassName(), classImageNo );
87
88 expand_item( pTree, *pId );
89
90 // "remember" it
91 hash.Put( long(&info), (wxObject*)pId );
92
93 // class is "hanged", remove it from the list
94 wxNode* pTmp = pCur;
95
96 pCur = pCur->Next();
97
98 delete pTmp;
99
100 ++nHanged;
101 }
102 else
103 {
104 wxTreeItemId* pParentId = (wxTreeItemId*)hash.Get( (long)info.GetBaseClass1() );
105
106 if ( pParentId != NULL )
107 {
108 wxTreeItemId* pId = new wxTreeItemId();
109
110 *pId = pTree->AppendItem( *pParentId, info.GetClassName(), classImageNo );
111
112 expand_item( pTree, *pId );
113
114 hash.Put( long(&info), (wxObject*)pId );
115
116 wxNode* pTmp = pCur;
117
118 pCur = pCur->Next();
119
120 // class is "hanged", remove it from the list
121 delete pTmp;
122
123 ++nHanged;
124 }
125 else
126 {
127 // otherwise there's a parent, but it's not in the tree yet...
128 // hope to "hang" it in the subsequent passes
129
130 pCur = pCur->Next();
131 }
132 }
133 }
134
135 } while( nHanged != 0 );
136 }
137
138