6 ConstantsClass
, FloatEditClass
, FunctionsClass
, HardwareClass
, ResourcesClass
,
7 TagEditClass
, TypesClass
,
8 Classes
, Controls
, Graphics
, Grids
, Menus
, Types
;
14 TStackView
= class(TStringGrid
)
16 pChanges
: array [0..2] of array [0..7] of Boolean;
17 pColorTheme
: TViewTheme
;
18 pFloatEdit
: TFLoatEdit
;
20 pOldOnState
: TChangeEvent
;
22 function pGetChanges(ACol
, ARow
: Integer): Boolean; virtual;
23 function pGetWidth
: Integer; virtual;
24 procedure pCustomDblClick(Sender
: TObject
); virtual;
25 procedure pCustomDrawCell(Sender
: TObject
; ACol
, ARow
: Integer; Rect
: TRect
; State
: TGridDrawState
); virtual;
26 procedure pCustomKeyDown(Sender
: TObject
; var Key
: Word; Shift
: TShiftState
); virtual;
27 procedure pCustomMouseDown(Sender
: TObject
; Button
: TMouseButton
; Shift
: TShiftState
; X
, Y
: Integer); virtual;
28 procedure pDrawSingleCell(Canvas
: TCanvas
; ACol
, ARow
: Integer; Rect
: TRect
; Colors
: TColors
); virtual;
29 procedure pOnSelectCell(Sender
: TObject
; ACol
, ARow
: Integer; var CanSelect
: Boolean); virtual;
30 procedure pOnState(Sender
: TObject
); virtual;
31 procedure pSetChanges(ACol
, ARow
: Integer; Change
: Boolean); virtual;
32 procedure pSetColorTheme(ColorTheme
: TViewTheme
); virtual;
33 procedure pSetHardware(Input
: THardware
); virtual;
34 procedure pSetWidth(Width
: Integer); virtual;
36 constructor CreateStackView(AOwner
: TComponent
; Hw
: THardware
); virtual;
37 procedure ChangeStack(Line
: Integer); virtual;
38 procedure ChangeTag(Line
: Integer); virtual;
39 property Changes
[ACol
, ARow
: Integer]: Boolean read pGetChanges write pSetChanges
;
40 property ColorTheme
: TViewTheme read pColorTheme write pSetColorTheme
;
41 property FloatEdit
: TFLoatEdit read pFloatEdit write pFloatEdit
;
42 property TagEdit
: TTagEdit read pTagEdit write pTagEdit
;
43 property Hardware
: THardware read pHardware write pSetHardware
;
44 property Width
: Integer read pGetWidth write pSetWidth
;
49 // ************************************************************************** //
50 // * TStackView implementation * //
51 // ************************************************************************** //
53 function TStackView
.pGetChanges(ACol
, ARow
: Integer): Boolean;
56 if (ACol
< 0) or (ACol
> 2) or (ARow
< 0) or (ARow
> 7) then Exit
;
57 Result
:= pChanges
[ACol
, ARow
];
60 function TStackView
.pGetWidth
: Integer;
62 Result
:= TStringGrid(Self
).Width
;
65 procedure TStackView
.pCustomDblClick(Sender
: TObject
);
70 pCustomKeyDown(Self
, lkey
, []);
73 procedure TStackView
.pCustomDrawCell(Sender
: TObject
; ACol
, ARow
: Integer;
74 Rect
: TRect
; State
: TGridDrawState
);
76 if (gdSelected
in State
) then
77 pDrawSingleCell(Canvas
, ACol
, ARow
, Rect
, ColorTheme
.Line
.Selected
)
79 pDrawSingleCell(Canvas
, ACol
, ARow
, Rect
, ColorTheme
.Line
.None
)
82 procedure TStackView
.pCustomKeyDown(Sender
: TObject
; var Key
: Word;
87 lselect
:= Selection
.TopLeft
;
89 KEY_RETURN
, KEY_SPACE
:
91 1: ChangeTag(lselect
.Y
);
92 2: ChangeStack(lselect
.Y
);
97 procedure TStackView
.pCustomMouseDown(Sender
: TObject
; Button
: TMouseButton
;
98 Shift
: TShiftState
; X
, Y
: Integer);
103 MouseToCell(X
, Y
, lcol
, lrow
);
104 if SelectCell(lcol
, lrow
) then
107 // Lazarus is really nice, by having incompatible calls :-(
111 lselect
.Bottom
:= lrow
;
112 lselect
.Left
:= lcol
;
113 lselect
.Right
:= lcol
;
114 Selection
:= lselect
;
119 procedure TStackView
.pDrawSingleCell(Canvas
: TCanvas
; ACol
, ARow
: Integer;
120 Rect
: TRect
; Colors
: TColors
);
127 Canvas
.Brush
.Color
:= Colors
.BG
;
128 if Changes
[ACol
, ARow
] then Canvas
.Font
.Color
:= ColorTheme
.Change
129 else Canvas
.Font
.Color
:= Colors
.FG
;
130 lsize
:= Canvas
.TextExtent(Cells
[ACol
, ARow
]);
131 lx
:= (Right
- Left
- lsize
.cx
) div 2 + Left
;
132 ly
:= (Bottom
- Top
- lsize
.cy
) div 2 + Top
;
133 Canvas
.FillRect(Rect
);
134 Canvas
.TextOut(lx
, ly
, Cells
[ACol
, ARow
]);
138 procedure TStackView
.pOnSelectCell(Sender
: TObject
; ACol
, ARow
: Integer;
139 var CanSelect
: Boolean);
141 CanSelect
:= not(ACol
= 0);
144 procedure TStackView
.pOnState(Sender
: TObject
);
148 with Hardware
.State
.FPUState
do
151 Changes
[1, i
] := not CompareStateTag(Hardware
, i
);
152 Changes
[2, i
] := not CompareStateStack(Hardware
, i
);
153 Changes
[0, i
] := Changes
[1, i
] or Changes
[2, i
];
154 Cells
[0, i
] := DESC_STACKS
[i
];
155 Cells
[1, i
] := DESC_TAG
[GetTag(Hardware
.State
, i
)];
156 Cells
[2, i
] := CustomFloatToStr(@ST
[i
], SizeOf(ST
[i
]));
159 if not(@pOldOnState
= nil) then pOldOnState(Sender
);
162 procedure TStackView
.pSetChanges(ACol
, ARow
: Integer; Change
: Boolean);
164 if (ACol
< 0) or (ACol
> 2) or (ARow
< 0) or (ARow
> 7) then Exit
;
165 pChanges
[ACol
, ARow
] := Change
;
168 procedure TStackView
.pSetColorTheme(ColorTheme
: TViewTheme
);
170 pColorTheme
:= ColorTheme
;
171 Color
:= ColorTheme
.Line
.None
.BG
;
174 procedure TStackView
.pSetHardware(Input
: THardware
);
177 if not(Input
= nil) then
179 pOldOnState
:= Input
.OnState
;
180 Input
.OnState
:= pOnState
;
184 procedure TStackView
.pSetWidth(Width
: Integer);
186 TStringGrid(Self
).Width
:= Width
;
187 ColWidths
[0] := Canvas
.TextWidth(Cells
[0, 0] + ' ');
188 ColWidths
[1] := Canvas
.TextWidth(DESC_TAG
[DESC_TAG_LONGEST
] + ' ');
189 ColWidths
[2] := ClientWidth
- ColWidths
[1] - ColWidths
[0];
192 constructor TStackView
.CreateStackView(AOwner
: TComponent
; Hw
: THardware
);
196 inherited Create(AOwner
);
197 DoubleBuffered
:= True;
198 ColorTheme
:= THEME_VIEW_DEFAULT
;
204 Options
:= [goRangeSelect
, goThumbTracking
];
205 // Behavior of goRangeSelect differ in Lazarus :-(
207 Options
:= [goThumbTracking
];
209 DefaultDrawing
:= False;
210 OnDrawCell
:= pCustomDrawCell
;
211 OnDblClick
:= pCustomDblClick
;
212 OnKeyDown
:= pCustomKeyDown
;
213 OnMouseDown
:= pCustomMouseDown
;
214 OnSelectCell
:= pOnSelectCell
;
215 Canvas
.Font
.Name
:= FONT_DEFAULT_NAME
;
216 Canvas
.Font
.Size
:= FONT_DEFAULT_SIZE
;
217 DefaultRowHeight
:= FONT_DEFAULT_HEIGHT
;
218 FloatEdit
:= TFLoatEdit
.Create(AOwner
);
219 TagEdit
:= TTagEdit
.Create(AOwner
);
220 PopupMenu
:= TPopupMenu
.Create(Self
);
223 Items
.Add(TMenuItem
.Create(PopupMenu
));
224 with Items
[Items
.Count
- 1] do
226 Caption
:= FL_EDIT_MODIFY
;
227 OnClick
:= pCustomDblClick
;
235 // Lazarus is really nice, by having incompatible calls :-(
241 Selection
:= lselect
;
245 procedure TStackView
.ChangeStack(Line
: Integer);
248 lstate
: THardwareState
;
251 lstate
:= Hardware
.State
;
252 FloatEdit
.Caption
:= FL_EDIT_MODIFY
+ DESC_STACKS
[Line
];
253 with lstate
.FPUState
do
254 if FloatEdit
.ShowBox(@ST
[Line
], SizeOf(ST
[Line
]), lcheck
) then
257 case FloatType(@ST
[Line
], SizeOf(ST
[Line
])) of
258 -1: SetTag(lstate
, Line
, 2);
259 0: SetTag(lstate
, Line
, 1);
260 1: SetTag(lstate
, Line
, 0);
262 Hardware
.State
:= lstate
;
266 procedure TStackView
.ChangeTag(Line
: Integer);
269 lstate
: THardwareState
;
271 lstate
:= Hardware
.State
;
272 TagEdit
.Caption
:= FL_EDIT_MODIFY
+ DESC_STACKS
[Line
] + ' Tag';
273 ltag
:= GetTag(lstate
, Line
);
274 if TagEdit
.ShowBox(ltag
) then SetTag(lstate
, Line
, ltag
);
275 Hardware
.State
:= lstate
;