Finalize version.
[marekmrva_bc.git] / StackViewClass.pas
blob39da081d255963c91d2f8536aee53724c66eafb5
1 unit StackViewClass;
3 interface
5 uses
6 ConstantsClass, CustomViewClass, FloatEditClass, FunctionsClass,
7 HardwareClass, ResourcesClass, TagEditClass, TypesClass,
8 Classes, Grids, Menus;
10 type
12 { TStackView }
14 TStackView = class(TCustomView)
15 private
16 pFloatEdit: TFLoatEdit;
17 pTagEdit: TTagEdit;
18 function pGetWidth: Integer; virtual;
19 procedure pCustomKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); virtual;
20 procedure pOnState(Sender: TObject); virtual;
21 procedure pSetWidth(Width: Integer); virtual;
22 public
23 constructor CreateStackView(AOwner: TComponent; Hw: THardware); virtual;
24 procedure ChangeStack(Line: Integer); virtual;
25 procedure ChangeTag(Line: Integer); virtual;
26 property Width read pGetWidth write pSetWidth;
27 end;
29 implementation
31 // ************************************************************************** //
32 // * TStackView implementation * //
33 // ************************************************************************** //
35 function TStackView.pGetWidth: Integer;
36 begin
37 Result := inherited Width;
38 end;
40 procedure TStackView.pCustomKeyDown(Sender: TObject; var Key: Word;
41 Shift: TShiftState);
42 var
43 lselect: TGridCoord;
44 begin
45 lselect := Selection.TopLeft;
46 case Key of
47 KEY_RETURN, KEY_SPACE:
48 case lselect.X of
49 1: ChangeTag(lselect.Y);
50 2: ChangeStack(lselect.Y);
51 end;
52 end;
53 end;
55 procedure TStackView.pOnState(Sender: TObject);
56 var
57 i: Integer;
58 begin
59 with Hardware.State.FPUState do
60 for i := 0 to 7 do
61 begin
62 Changes[1, i] := not CompareStateTag(Hardware, i);
63 Changes[2, i] := not CompareStateStack(Hardware, i);
64 Changes[0, i] := Changes[1, i] or Changes[2, i];
65 Cells[0, i] := DESC_STACKS[i];
66 Cells[1, i] := DESC_TAG[GetTag(Hardware.State, i)];
67 Cells[2, i] := CustomFloatToStr(@ST[i], SizeOf(ST[i]));
68 end;
69 end;
71 procedure TStackView.pSetWidth(Width: Integer);
72 begin
73 inherited Width := Width;
74 ColWidths[0] := Canvas.TextWidth(Cells[0, 0] + ' ');
75 ColWidths[1] := Canvas.TextWidth(DESC_TAG[DESC_TAG_LONGEST] + ' ');
76 ColWidths[2] := ClientWidth - ColWidths[1] - ColWidths[0];
77 end;
79 constructor TStackView.CreateStackView(AOwner: TComponent; Hw: THardware);
80 begin
81 inherited CreateView(AOwner, Hw);
82 RowCount := 8;
83 ColCount := 3;
84 OnKeyDown := pCustomKeyDown;
85 OnState := pOnState;
86 pFloatEdit := TFLoatEdit.Create(AOwner);
87 pTagEdit := TTagEdit.Create(AOwner);
88 PopupMenu := TPopupMenu.Create(Self);
89 with PopupMenu do
90 begin
91 Items.Add(TMenuItem.Create(PopupMenu));
92 with Items[Items.Count - 1] do
93 begin
94 Caption := FL_EDIT_MODIFY;
95 OnClick := OnDblClick;
96 Default := True;
97 end;
98 end;
99 pOnState(Self);
100 end;
102 procedure TStackView.ChangeStack(Line: Integer);
104 lcheck: Boolean;
105 lstate: THardwareState;
106 begin
107 lcheck := True;
108 lstate := Hardware.State;
109 pFloatEdit.Caption := FL_EDIT_MODIFY + DESC_STACKS[Line];
110 with lstate.FPUState do
111 if pFloatEdit.ShowBox(@ST[Line], SizeOf(ST[Line]), lcheck) then
112 begin
113 if lcheck then
114 case FloatType(@ST[Line], SizeOf(ST[Line])) of
115 -1: SetTag(lstate, Line, 2);
116 0: SetTag(lstate, Line, 1);
117 1: SetTag(lstate, Line, 0);
118 end;
119 Hardware.State := lstate;
120 end;
121 end;
123 procedure TStackView.ChangeTag(Line: Integer);
125 ltag: Integer;
126 lstate: THardwareState;
127 begin
128 lstate := Hardware.State;
129 pTagEdit.Caption := FL_EDIT_MODIFY + DESC_STACKS[Line] + ' Tag';
130 ltag := GetTag(lstate, Line);
131 if pTagEdit.ShowBox(ltag) then
132 begin
133 SetTag(lstate, Line, ltag);
134 Hardware.State := lstate;
135 end;
136 end;
138 end.