Code::Blocks  SVN r11506
cctreectrl.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  *
5  * $Revision: 9043 $
6  * $Id: cctreectrl.cpp 9043 2013-05-04 04:39:36Z mortenmacfly $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/codecompletion/cctreectrl.cpp $
8  */
9 
10 #include <sdk.h>
11 
12 #ifndef CB_PRECOMP
13  #ifdef CC_BUILDTREE_MEASURING
14  #include <wx/stopwatch.h>
15  #endif
16 #endif
17 
18 #include <wx/gdicmn.h> // wxPoint, wxSize
19 
20 #include "cctreectrl.h"
21 
22 // class CCTreeCtrlData
23 
24 CCTreeCtrlData::CCTreeCtrlData(SpecialFolder sf, Token* token, short int kindMask, int parentIdx) :
25  m_Token(token),
26  m_KindMask(kindMask),
27  m_SpecialFolder(sf),
28  m_TokenIndex(token ? token->m_Index : -1),
29  m_TokenKind(token ? token->m_TokenKind : tkUndefined),
30  m_TokenName(token ? token->m_Name : _T("")),
31  m_ParentIndex(parentIdx),
32  m_Ticket(token ? token->GetTicket() : 0)
33 {
34 }
35 
36 // class CCTreeCtrlExpandedItemData
37 
39  m_Data(*data),
40  m_Level(level)
41 {
42 }
43 
44 // class CCTreeCtrl
45 
47 
48 CCTreeCtrl::CCTreeCtrl()
49 {
50  Compare = &CBNoCompare;
51 }
52 
54  const wxPoint& pos, const wxSize& size, long style) :
55  wxTreeCtrl(parent, id, pos, size, style)
56 {
58 }
59 
61 {
62  switch (type)
63  {
64  case bstAlphabet:
66  break;
67  case bstKind:
69  break;
70  case bstScope:
72  break;
73  case bstLine:
75  break;
76  case bstNone:
77  default:
79  break;
80  }
81 
82 }
83 
84 int CCTreeCtrl::OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2)
85 {
86  return Compare((CCTreeCtrlData*)GetItemData(item1), (CCTreeCtrlData*)GetItemData(item2));
87 }
88 
90 {
91  if (!lhs || !rhs)
92  return 1;
93  if (lhs->m_SpecialFolder != sfToken || rhs->m_SpecialFolder != sfToken)
94  return -1;
95  if (!lhs->m_Token || !rhs->m_Token)
96  return 1;
97  return wxStricmp(lhs->m_Token->m_Name, rhs->m_Token->m_Name);
98 }
99 
101 {
102  if (!lhs || !rhs)
103  return 1;
104  if (lhs->m_SpecialFolder != sfToken || rhs->m_SpecialFolder != sfToken)
105  return -1;
106  if (lhs->m_TokenKind == rhs->m_TokenKind)
107  return CBAlphabetCompare(lhs, rhs);
108 
109  return lhs->m_TokenKind - rhs->m_TokenKind;
110 }
111 
113 {
114  if (!lhs || !rhs)
115  return 1;
116  if (lhs->m_SpecialFolder != sfToken || rhs->m_SpecialFolder != sfToken)
117  return -1;
118 
119  if (lhs->m_Token->m_Scope == rhs->m_Token->m_Scope)
120  return CBKindCompare(lhs, rhs);
121 
122  return rhs->m_Token->m_Scope - lhs->m_Token->m_Scope;
123 }
124 
126 {
127  if (!lhs || !rhs)
128  return 1;
129  if (lhs->m_SpecialFolder != sfToken || rhs->m_SpecialFolder != sfToken)
130  return -1;
131  if (!lhs->m_Token || !rhs->m_Token)
132  return 1;
133  if (lhs->m_Token->m_FileIdx == rhs->m_Token->m_FileIdx)
134  {
135  return (lhs->m_Token->m_Line > rhs->m_Token->m_Line) * 2 - 1; // from 0,1 to -1,1
136  }
137  else
138  {
139  return (lhs->m_Token->m_FileIdx > rhs->m_Token->m_FileIdx) * 2 - 1;
140  }
141 }
142 
143 int CCTreeCtrl::CBNoCompare(cb_unused CCTreeCtrlData* lhs, cb_unused CCTreeCtrlData* rhs)
144 {
145  return 0;
146 }
147 
148 // This does not really do what it says !
149 // It only removes doubles, if they are neighbours, so the tree should be sorted !!
150 // The last one (after sorting) remains.
152 {
153  if (Manager::IsAppShuttingDown() || (!(parent.IsOk())))
154  return;
155 
156 #ifdef CC_BUILDTREE_MEASURING
157  wxStopWatch sw;
158 #endif
159  // we 'll loop backwards so we can delete nodes without problems
160  wxTreeItemId existing = GetLastChild(parent);
161  while (parent.IsOk() && existing.IsOk())
162  {
163  wxTreeItemId prevItem = GetPrevSibling(existing);
164  if (!prevItem.IsOk())
165  break;
166  CCTreeCtrlData* dataExisting = (CCTreeCtrlData*)(GetItemData(existing));
167  CCTreeCtrlData* dataPrev = (CCTreeCtrlData*)(GetItemData(prevItem));
168  if (dataExisting &&
169  dataPrev &&
170  dataExisting->m_SpecialFolder == sfToken &&
171  dataPrev->m_SpecialFolder == sfToken &&
172  dataExisting->m_Token &&
173  dataPrev->m_Token &&
174  (dataExisting->m_Token->DisplayName() == dataPrev->m_Token->DisplayName()))
175  {
176  Delete(prevItem);
177  }
178  else if (existing.IsOk())
179  existing = GetPrevSibling(existing);
180  }
181 #ifdef CC_BUILDTREE_MEASURING
182  CCLogger::Get()->DebugLog(F(_T("RemoveDoubles took : %ld"), sw.Time()));
183 #endif
184 }
wxString F(const wxChar *msg,...)
sprintf-like function
Definition: logmanager.h:20
BrowserSortType
specify the sort order of the symbol tree nodes
Definition: parser_base.h:49
CCTreeCtrlExpandedItemData(const CCTreeCtrlData *data, const int level)
Definition: cctreectrl.cpp:38
static CCLogger * Get()
Definition: cclogger.cpp:60
bool IsOk() const
wxString m_Name
Token&#39;s name, it can be searched in the TokenTree.
Definition: token.h:188
CCTreeCtrlData(SpecialFolder sf=sfToken, Token *token=0, short int kindMask=0xffff, int parentIdx=-1)
Definition: cctreectrl.cpp:24
void RemoveDoubles(const wxTreeItemId &parent)
Definition: cctreectrl.cpp:151
static bool IsAppShuttingDown()
Definition: manager.cpp:333
TokenKind m_TokenKind
a copy of Token::m_TokenKind
Definition: cctreectrl.h:58
static int CBAlphabetCompare(CCTreeCtrlData *lhs, CCTreeCtrlData *rhs)
Definition: cctreectrl.cpp:89
SpecialFolder m_SpecialFolder
the node&#39;s kind, it could be "root", "normal token",
Definition: cctreectrl.h:52
static int CBScopeCompare(CCTreeCtrlData *lhs, CCTreeCtrlData *rhs)
Definition: cctreectrl.cpp:112
alphabetical
Definition: parser_base.h:52
long Time() const
#define _T(string)
unsigned int m_Line
Line index where the token was met, which is 1 based.
Definition: token.h:210
virtual wxTreeItemData * GetItemData(const wxTreeItemId &item) const
void SetCompareFunction(const BrowserSortType type)
Definition: cctreectrl.cpp:60
TokenScope m_Scope
public? private? protected?
Definition: token.h:231
wxString DisplayName() const
a short simple string to show the token information, this usually generate for show the tip message w...
Definition: token.cpp:80
void DebugLog(const wxString &msg)
Definition: cclogger.cpp:107
unsigned int m_FileIdx
File index in TokenTree.
Definition: token.h:207
a symbol found in the parsed files, it can be many kinds, such as a variable, a class and so on...
Definition: token.h:82
Token * m_Token
a pointer to the associated Token instance in the TokenTree
Definition: cctreectrl.h:44
IMPLEMENT_DYNAMIC_CLASS(cbDummyEditor, wxPGEditor)
virtual wxTreeItemId GetLastChild(const wxTreeItemId &item) const
static int CBLineCompare(CCTreeCtrlData *lhs, CCTreeCtrlData *rhs)
Definition: cctreectrl.cpp:125
code like order
Definition: parser_base.h:55
Actual data stored with each node in the symbol tree.
Definition: cctreectrl.h:37
undefined or just "all"
Definition: token.h:76
static int CBKindCompare(CCTreeCtrlData *lhs, CCTreeCtrlData *rhs)
Definition: cctreectrl.cpp:100
virtual void Delete(const wxTreeItemId &item)
SpecialFolder
Specify which kind of node it is.
Definition: cctreectrl.h:23
int(* Compare)(CCTreeCtrlData *lhs, CCTreeCtrlData *rhs)
Definition: cctreectrl.h:109
virtual wxTreeItemId GetPrevSibling(const wxTreeItemId &item) const
public, protected, private
Definition: parser_base.h:54
class, function, macros
Definition: parser_base.h:53
int wxWindowID
int OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2)
Definition: cctreectrl.cpp:84
static int CBNoCompare(CCTreeCtrlData *lhs, CCTreeCtrlData *rhs)
Definition: cctreectrl.cpp:143