6 ConstantsClass
, CustomViewClass
, FunctionsClass
, HardwareClass
,
7 OperandEditClass
, MemoryEditClass
, PrefixTreeClass
, ResourcesClass
,
9 Classes
, Controls
, Graphics
, Grids
, StdCtrls
, Types
, Menus
;
15 TLogView
= class(TCustomView
)
18 function pGetSelectedLine
: Integer; virtual;
19 function pGetWidth
: Integer; virtual;
20 procedure pCustomDrawCell(Sender
: TObject
; ACol
, ARow
: Integer; Rect
: TRect
; State
: TGridDrawState
); virtual;
21 procedure pCustomKeyDown(Sender
: TObject
; var Key
: Word; Shift
: TShiftState
); virtual;
22 procedure pCustomPopupClear(Sender
: TObject
); virtual;
23 procedure pDrawSingleCell(Canvas
: TCanvas
; ACol
, ARow
: Integer; Rect
: TRect
; Colors
: TColors
); virtual;
24 procedure pOnSelectCell(Sender
: TObject
; ACol
, ARow
: Integer; var CanSelect
: Boolean); virtual;
25 procedure pSetSelectedLine(Line
: Integer); virtual;
26 procedure pSetWidth(Width
: Integer); virtual;
28 constructor CreateLogView(AOwner
: TComponent
; Hw
: THardware
); virtual;
29 procedure Clear(Sender
: TObject
); virtual;
30 procedure Write(Sender
: TObject
; Log
: String; Error
: Boolean = False); virtual;
31 property SelectedLine
: Integer read pGetSelectedLine write pSetSelectedLine
;
32 property Width read pGetWidth write pSetWidth
;
37 uses CustomStringGridClass
;
39 // ************************************************************************** //
40 // * TLogView implementation * //
41 // ************************************************************************** //
43 function TLogView
.pGetSelectedLine
: Integer;
45 Result
:= Selection
.Top
;
48 function TLogView
.pGetWidth
: Integer;
50 Result
:= inherited Width
;
53 procedure TLogView
.pCustomDrawCell(Sender
: TObject
; ACol
, ARow
: Integer;
54 Rect
: TRect
; State
: TGridDrawState
);
56 if (gdSelected
in State
) and Selected
then
57 pDrawSingleCell(Canvas
, ACol
, ARow
, Rect
, ColorTheme
.Line
.Selected
)
59 pDrawSingleCell(Canvas
, ACol
, ARow
, Rect
, ColorTheme
.Line
.None
)
62 procedure TLogView
.pCustomKeyDown(Sender
: TObject
; var Key
: Word;
71 procedure TLogView
.pCustomPopupClear(Sender
: TObject
);
76 pCustomKeyDown(Sender
, lkey
, []);
79 procedure TLogView
.pDrawSingleCell(Canvas
: TCanvas
; ACol
, ARow
: Integer;
80 Rect
: TRect
; Colors
: TColors
);
86 Canvas
.Brush
.Color
:= Colors
.BG
;
87 if Changes
[ACol
, ARow
] then Canvas
.Font
.Color
:= ColorTheme
.Change
88 else Canvas
.Font
.Color
:= Colors
.FG
;
89 lx
:= Left
+ Canvas
.TextWidth(' ');
90 ly
:= (Bottom
- Top
- Canvas
.TextHeight(Cells
[ACol
, ARow
])) div 2 + Top
;
91 Canvas
.FillRect(Rect
);
92 Canvas
.TextOut(lx
, ly
, Cells
[ACol
, ARow
]);
96 procedure TLogView
.pOnSelectCell(Sender
: TObject
; ACol
, ARow
: Integer;
97 var CanSelect
: Boolean);
102 procedure TLogView
.pSetSelectedLine(Line
: Integer);
106 if (Line
< 0) then Line
:= 0;
107 if (Line
> RowCount
) then Line
:= RowCount
- 1;
110 // Lazarus is really nice, by having incompatible calls :-(
113 lselect
.Bottom
:= Line
;
116 Selection
:= lselect
;
120 procedure TLogView
.pSetWidth(Width
: Integer);
122 inherited Width
:= Width
;
123 pMinWidth
:= MaxOf(pMinWidth
, ClientWidth
);
124 ColWidths
[0] := pMinWidth
;
127 constructor TLogView
.CreateLogView(AOwner
: TComponent
; Hw
: THardware
);
129 inherited CreateView(AOwner
, Hw
);
130 ScrollBars
:= ssBoth
;
133 OnDrawCell
:= pCustomDrawCell
;
134 OnKeyDown
:= pCustomKeyDown
;
136 Log_OnClear
:= Clear
;
137 Log_OnWrite
:= Write
;
138 OnSelectCell
:= pOnSelectCell
;
139 PopupMenu
:= TPopupMenu
.Create(Self
);
142 Items
.Add(TMenuItem
.Create(PopupMenu
));
143 with Items
[Items
.Count
- 1] do
145 Caption
:= LOG_VIEW_CLEAR
;
146 OnClick
:= pCustomPopupClear
;
153 procedure TLogView
.Clear(Sender
: TObject
);
160 procedure TLogView
.Write(Sender
: TObject
; Log
: String; Error
: Boolean = False
163 Log
:= TrimCharacterLeft(Log
, ' ');
164 if Error
then Log
:= 'Error: ' + Log
165 else if not(Log
= '') then Log
:= '- ' + Log
;
166 Cells
[0, RowCount
- 1] := Log
;
167 Changes
[0, RowCount
- 1] := Error
;
168 pMinWidth
:= MaxOf(pMinWidth
, Canvas
.TextWidth(Log
));
169 ColWidths
[0] := pMinWidth
;
170 SelectedLine
:= RowCount
- 1;
172 RowCount
:= RowCount
+ 1;
173 Cells
[0, RowCount
- 1] := '';