-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIntellisenseListBox.cpp
274 lines (234 loc) · 6.12 KB
/
IntellisenseListBox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
// IntellisenseListBox.cpp : implementation file
//
//
// Listbox that is populated with intellisense results.
// Intellisense is currently disabled as a result of moving to a different parser.
//
#include "stdafx.h"
#include "SCIPicEditor.h"
#include "IntellisenseListBox.h"
#include "ScriptView.h"
//
// Intellisense icons
//
#define ICON_CLASS 0
#define ICON_PROPERTY 1
#define ICON_METHOD 2
#define ICON_PROC 3
#define ICON_PUBLICPROC 4
#define ICON_METHODVAR 5
#define ICON_SCRIPTVAR 6
#define ICON_GLOBALVAR 7
#define ICON_KEYWORD 8
#define ICON_KERNEL 9
#define ICON_DEFINE 10
#define ICON_UNKNOWN 10
// CIntellisenseListBox
IMPLEMENT_DYNAMIC(CIntellisenseListBox, CListBox)
CIntellisenseListBox::CIntellisenseListBox()
{
_pClient = NULL;
}
CIntellisenseListBox::~CIntellisenseListBox()
{
}
int CIntellisenseListBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (__super::OnCreate(lpCreateStruct) == -1)
return -1;
// Get a nice font (menu font) to use.
NONCLIENTMETRICS metrics = { 0 };
metrics.cbSize = sizeof(metrics);
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, 0))
{
m_font.CreateFontIndirect(&metrics.lfMenuFont);
SetFont(&m_font);
}
// Load an image list.
_imageList.Create(IDB_CLASSBROWSER, 16, 0, RGB(255, 0, 255));
return 0;
}
void CIntellisenseListBox::OnDestroy()
{
}
BOOL CIntellisenseListBox::GetSelectedText(CString &strText)
{
BOOL fRet = (GetCurSel() != LB_ERR);
if (fRet)
{
GetText(GetCurSel(), strText);
}
return fRet;
}
BEGIN_MESSAGE_MAP(CIntellisenseListBox, CListBox)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_CONTROL_REFLECT(LBN_DBLCLK, OnDblClick)
END_MESSAGE_MAP()
void CIntellisenseListBox::OnDblClick()
{
if (_pClient)
{
_pClient->OnACDoubleClick();
}
}
// Map some wellknown defines to colours
const PCTSTR c_szColorDefines[] =
{
TEXT("clBLACK"),
TEXT("clNAVY"),
TEXT("clGREEN"),
TEXT("clTEAL"),
TEXT("clMAROON"),
TEXT("clPURPLE"),
TEXT("clBROWN"),
TEXT("clSILVER"),
TEXT("clGREY"),
TEXT("clBLUE"),
TEXT("clLIME"),
TEXT("clCYAN"),
TEXT("clRED"),
TEXT("clFUCHSIA"),
TEXT("clYELLOW"),
TEXT("clWHITE"),
};
// Map some wellknown defines to colours
const PCTSTR c_szControlDefines[] =
{
TEXT("ctlBLACK"),
TEXT("ctlNAVY"),
TEXT("ctlGREEN"),
TEXT("ctlTEAL"),
TEXT("ctlMAROON"),
TEXT("ctlPURPLE"),
TEXT("ctlBROWN"),
TEXT("ctlSILVER"),
TEXT("ctlGREY"),
TEXT("ctlBLUE"),
TEXT("ctlLIME"),
TEXT("ctlCYAN"),
TEXT("ctlRED"),
TEXT("ctlFUCHSIA"),
TEXT("ctlYELLOW"),
TEXT("ctlWHITE"),
};
// STLCLEANUP
BOOL _MapDefineToColor(PCTSTR pszDefine, COLORREF *pcr)
{
BOOL fRet = FALSE;
int i = 0;
for (i = 0; i < ARRAYSIZE(c_szColorDefines); i++)
{
if (0 == lstrcmp(c_szColorDefines[i], pszDefine))
{
*pcr = EGA_TO_COLORREF(i);
fRet = TRUE;
break;
}
}
if (!fRet)
{
for (i = 0; i < ARRAYSIZE(c_szControlDefines); i++)
{
if (0 == lstrcmp(c_szControlDefines[i], pszDefine))
{
*pcr = EGA_TO_COLORREF(i);
fRet = TRUE;
break;
}
}
}
return fRet;
}
// CIntellisenseListBox message handlers
void CIntellisenseListBox::DrawItem(LPDRAWITEMSTRUCT pDrawItemStruct)
{
CDC dc;
dc.Attach(pDrawItemStruct->hDC);
// Save these values to restore them when done drawing.
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
int iMode = dc.GetBkMode();
CString str;
GetText(pDrawItemStruct->itemID, str);
CRect rc = pDrawItemStruct->rcItem;
COLORREF color;
if (_MapDefineToColor(str, &color))
{
// Draw a colour
int iOldMode = dc.SetBkMode(TRANSPARENT);
dc.Rectangle(rc.left, rc.top + 1, rc.left + 16, rc.top + 14);
dc.FillSolidRect(rc.left + 1, rc.top + 2, 14, 11, color);
dc.SetBkMode(iOldMode);
}
else
{
// Draw a little icon next to the guy.
_imageList.Draw(&dc, (int)pDrawItemStruct->itemData, CPoint(rc.left, rc.top), ILD_NORMAL);
}
rc.left += 18;
// Now draw the text
if ((pDrawItemStruct->itemAction | ODA_SELECT) && (pDrawItemStruct->itemState & ODS_SELECTED))
{
// Show something for the selected it.
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
dc.FillSolidRect(&rc, ::GetSysColor(COLOR_HIGHLIGHT));
}
else
{
if (ICON_KEYWORD == (int)pDrawItemStruct->itemData)
{
// Highlight keywords in blue.
dc.SetTextColor(RGB(0, 0, 255));
}
dc.FillSolidRect(&rc, crOldBkColor);
}
rc.left += 3; // Offset a little more.
dc.DrawText(str, &rc, DT_SINGLELINE);
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.SetBkMode(iMode);
dc.Detach();
}
int CIntellisenseListBox::CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct)
{
return 0;
}
void CIntellisenseListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
// We're fixed height.
}
void CIntellisenseListBox::Show(CPoint pt)
{
int cy = 150;
CDC *pDC = GetDC();
if (pDC)
{
CRect rc;
int iHeightLine = pDC->DrawText(TEXT("M"), -1, &rc, DT_CALCRECT);
int iFudge = 6;
cy = min(150, iHeightLine * GetCount() + iFudge);
ReleaseDC(pDC);
}
// Before showing ourselves, figure out how big we should be.
SetWindowPos(NULL, pt.x, pt.y, 210, cy, SWP_NOZORDER | SWP_NOACTIVATE);
ShowWindow(SW_SHOWNOACTIVATE);
}
void CIntellisenseListBox::Hide()
{
ShowWindow(SW_HIDE);
}
void CIntellisenseListBox::Highlight(PCTSTR pszText)
{
CRect rcClient;
GetClientRect(&rcClient);
int cyItem = GetItemHeight(0);
int iIndex = FindString(-1, pszText);
// Center the item.
int cItemsVisible = rcClient.Height() / cyItem;
SetCurSel(iIndex);
iIndex -= (cItemsVisible / 2);
iIndex = max(0, iIndex);
SetTopIndex(iIndex);
}