Menu

[327ada]: / Source / VCL / ClassBrowsing / CodeCompletionForm.pas  Maximize  Restore  History

Download this file

200 lines (167 with data), 5.8 kB

  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
{
This file is part of Dev-C++
Copyright (c) 2004 Bloodshed Software
Dev-C++ is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Dev-C++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dev-C++; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit CodeCompletionForm;
interface
uses
{$IFDEF WIN32}
Windows, Classes, Graphics, Forms, StdCtrls, Controls,
CodeCompletion, CppParser, CBUtils, Winapi.Messages, Vcl.ExtCtrls;
{$ENDIF}
{$IFDEF LINUX}
Xlib, SysUtils, Classes, QGraphics, QForms, QStdCtrls, QControls,
CodeCompletion, CppParser, QGrids, QDialogs, Types;
{$ENDIF}
type
TCodeComplForm = class(TForm)
lbCompletion: TListBox;
Bevel1: TBevel;
procedure FormShow(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
procedure lbCompletionDblClick(Sender: TObject);
procedure lbCompletionDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure lbCompletionKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
fOwner: TCodeCompletion;
protected
procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
public
constructor Create(AOwner: TComponent); override;
procedure CreateParams(var Params: TCreateParams); override;
end;
var
CodeComplForm: TCodeComplForm;
implementation
{$R *.dfm}
procedure TCodeComplForm.FormShow(Sender: TObject);
begin
Width := fOwner.Width;
Height := fOwner.Height;
Color := fOwner.Color;
lbCompletion.Color := fOwner.Color;
lbCompletion.DoubleBuffered := true; // performance hit, but reduces flicker a lit
end;
procedure TCodeComplForm.FormDeactivate(Sender: TObject);
begin
fOwner.Hide;
end;
procedure TCodeComplForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
// Params.Style := Params.Style or WS_SIZEBOX;
end;
constructor TCodeComplForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fOwner := TCodeCompletion(AOwner);
end;
procedure TCodeComplForm.lbCompletionDblClick(Sender: TObject);
var
Key: Char;
begin
// Send command to TEditor
if Assigned(fOwner.OnKeyPress) then begin
Key := Char(VK_RETURN);
fOwner.OnKeyPress(self, Key);
end;
end;
procedure TCodeComplForm.lbCompletionDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State:
TOwnerDrawState);
var
Offset: integer;
statement: PStatement;
begin
Offset := 4;
with lbCompletion do begin
statement := PStatement(Items.Objects[Index]);
// Draw statement kind string, like 'Preprocessor'
if odSelected in State then begin
Canvas.Brush.Color := clHighlight;
Canvas.FillRect(Rect);
Canvas.Font.Color := clHighlightText;
end else begin
Canvas.Brush.Color := fOwner.Color;
Canvas.FillRect(Rect);
case statement^._Kind of
skFunction: Canvas.Font.Color := clGreen;
skClass: Canvas.Font.Color := clMaroon;
skVariable: Canvas.Font.Color := clBlue;
skTypedef: Canvas.Font.Color := clOlive;
skPreprocessor: Canvas.Font.Color := clPurple;
skEnum: Canvas.Font.Color := clNavy;
else
Canvas.Font.Color := clGray;
end;
end;
Canvas.TextOut(Offset, Rect.Top, fOwner.Parser.StatementKindStr(statement^._Kind));
Offset := Offset + Canvas.TextWidth('preprocessor '); // worst case width + spacing
if not (odSelected in State) then
Canvas.Font.Color := clWindowText;
// Draw data type string, like 'int', hide for defines/others that don't have this property
if Length(statement^._Type) > 0 then begin
Canvas.TextOut(Offset, Rect.Top, statement^._Type);
Offset := Offset + Canvas.TextWidth(statement^._Type + ' ');
end;
// draw statement name, like 'foo'
Canvas.Font.Style := [fsBold];
Canvas.TextOut(Offset, Rect.Top, statement^._Command);
Offset := Offset + Canvas.TextWidth(statement^._Command + ' ');
// if applicable, draw arguments
if statement^._Kind in [skFunction, skConstructor, skDestructor] then begin
Canvas.Font.Style := [];
Canvas.TextOut(Offset, Rect.Top, statement^._Args);
end;
end;
end;
procedure TCodeComplForm.lbCompletionKeyPress(Sender: TObject; var Key: Char);
begin
if Assigned(fOwner.OnKeyPress) then
fOwner.OnKeyPress(self, Key);
end;
procedure TCodeComplForm.WMNCHitTest(var Message: TWMNCHitTest);
var
D: Integer;
P: TPoint;
begin
D := GetSystemMetrics(SM_CXSIZEFRAME);
P := Self.ScreenToClient(Message.Pos);
if P.Y < D then
begin
if P.X < D then
Message.Result := HTTOPLEFT
else if P.X > ClientWidth - D then
Message.Result := HTTOPRIGHT
else
Message.Result := HTTOP;
end
else if P.Y > ClientHeight - D then
begin
if P.X < D then
Message.Result := HTBOTTOMLEFT
else if P.X > ClientWidth - D then
Message.Result := HTBOTTOMRIGHT
else
Message.Result := HTBOTTOM;
end
else
begin
if P.X < D then
Message.Result := HTLEFT
else if P.X > ClientWidth - D then
Message.Result := HTRIGHT
end;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.