1 unit ExceptionViewClass
;
6 ConstantsClass
, HardwareClass
, ResourcesClass
, TypesClass
,
7 Classes
, Controls
, Graphics
, Grids
, Menus
, Types
;
13 TExceptionView
= class(TStringGrid
)
15 pChanges
: array [0..2] of array [0..8] of Boolean;
16 pColorTheme
: TViewTheme
;
18 pOldOnState
: TChangeEvent
;
19 function pGetChanges(ACol
, ARow
: Integer): Boolean; virtual;
20 function pGetWidth
: Integer; virtual;
21 procedure pCustomDblClick(Sender
: TObject
); virtual;
22 procedure pCustomDrawCell(Sender
: TObject
; ACol
, ARow
: Integer; Rect
: TRect
; State
: TGridDrawState
); virtual;
23 procedure pCustomKeyDown(Sender
: TObject
; var Key
: Word; Shift
: TShiftState
); virtual;
24 procedure pCustomMouseDown(Sender
: TObject
; Button
: TMouseButton
; Shift
: TShiftState
; X
, Y
: Integer); virtual;
25 procedure pDrawSingleCell(Canvas
: TCanvas
; ACol
, ARow
: Integer; Rect
: TRect
; Colors
: TColors
); virtual;
26 procedure pOnSelectCell(Sender
: TObject
; ACol
, ARow
: Integer; var CanSelect
: Boolean); virtual;
27 procedure pOnState(Sender
: TObject
); virtual;
28 procedure pSetChanges(ACol
, ARow
: Integer; Change
: Boolean); virtual;
29 procedure pSetColorTheme(ColorTheme
: TViewTheme
); virtual;
30 procedure pSetHardware(Input
: THardware
); virtual;
31 procedure pSetWidth(Width
: Integer); virtual;
33 constructor CreateExceptionView(AOwner
: TComponent
; Hw
: THardware
); virtual;
34 procedure ToggleException(Line
: Integer); virtual;
35 procedure ToggleMask(Line
: Integer); virtual;
36 property Changes
[ACol
, ARow
: Integer]: Boolean read pGetChanges write pSetChanges
;
37 property ColorTheme
: TViewTheme read pColorTheme write pSetColorTheme
;
38 property Hardware
: THardware read pHardware write pSetHardware
;
39 property Width
: Integer read pGetWidth write pSetWidth
;
44 // ************************************************************************** //
45 // * TStackView implementation * //
46 // ************************************************************************** //
48 function TExceptionView
.pGetChanges(ACol
, ARow
: Integer): Boolean;
51 if (ACol
< 0) or (ACol
> 2) or (ARow
< 0) or (ARow
> 8) then Exit
;
52 Result
:= pChanges
[ACol
, ARow
];
55 function TExceptionView
.pGetWidth
: Integer;
57 Result
:= TStringGrid(Self
).Width
;
60 procedure TExceptionView
.pCustomDblClick(Sender
: TObject
);
65 pCustomKeyDown(Self
, lkey
, []);
68 procedure TExceptionView
.pCustomDrawCell(Sender
: TObject
; ACol
, ARow
: Integer;
69 Rect
: TRect
; State
: TGridDrawState
);
71 if (gdSelected
in State
) then
72 pDrawSingleCell(Canvas
, ACol
, ARow
, Rect
, ColorTheme
.Line
.Selected
)
74 pDrawSingleCell(Canvas
, ACol
, ARow
, Rect
, ColorTheme
.Line
.None
)
77 procedure TExceptionView
.pCustomKeyDown(Sender
: TObject
; var Key
: Word;
82 lselect
:= Selection
.TopLeft
;
84 KEY_RETURN
, KEY_SPACE
:
86 1: ToggleException(lselect
.Y
);
87 2: ToggleMask(lselect
.Y
);
92 procedure TExceptionView
.pCustomMouseDown(Sender
: TObject
;
93 Button
: TMouseButton
; Shift
: TShiftState
; X
, Y
: Integer);
98 MouseToCell(X
, Y
, lcol
, lrow
);
99 if SelectCell(lcol
, lrow
) then
102 // Lazarus is really nice, by having incompatible calls :-(
106 lselect
.Bottom
:= lrow
;
107 lselect
.Left
:= lcol
;
108 lselect
.Right
:= lcol
;
109 Selection
:= lselect
;
114 procedure TExceptionView
.pDrawSingleCell(Canvas
: TCanvas
; ACol
, ARow
: Integer;
115 Rect
: TRect
; Colors
: TColors
);
122 Canvas
.Brush
.Color
:= Colors
.BG
;
123 if Changes
[ACol
, ARow
] then Canvas
.Font
.Color
:= ColorTheme
.Change
124 else Canvas
.Font
.Color
:= Colors
.FG
;
125 lsize
:= Canvas
.TextExtent(Cells
[ACol
, ARow
]);
126 lx
:= (Right
- Left
- lsize
.cx
) div 2 + Left
;
127 ly
:= (Bottom
- Top
- lsize
.cy
) div 2 + Top
;
128 Canvas
.FillRect(Rect
);
129 Canvas
.TextOut(lx
, ly
, Cells
[ACol
, ARow
]);
133 procedure TExceptionView
.pOnSelectCell(Sender
: TObject
; ACol
, ARow
: Integer;
134 var CanSelect
: Boolean);
137 if (ACol
= 0) or (ARow
= 0) then Exit
;
138 if (ACol
= 2) and ((ARow
= 1) or (ARow
= 2)) then Exit
;
142 procedure TExceptionView
.pOnState(Sender
: TObject
);
146 Cells
[0, 0] := EXC_VIEW_TYPE
;
147 Cells
[1, 0] := EXC_VIEW_EXC
;
148 Cells
[2, 0] := EXC_VIEW_MASK
;
151 Changes
[1, i
] := not CompareStateException(Hardware
, 8 - i
);
152 Changes
[2, i
] := not CompareStateMask(Hardware
, 8 - i
);
153 Cells
[0, i
] := DESC_FLAG
[i
- 1];
154 if GetException(Hardware
.State
, 8 - i
) then Cells
[1, i
] := EXC_VIEW_TRUE
155 else Cells
[1, i
] := EXC_VIEW_FALSE
;
157 if GetMask(Hardware
.State
, 8 - i
) then Cells
[2, i
] := EXC_VIEW_TRUE
158 else Cells
[2, i
] := EXC_VIEW_FALSE
159 else Cells
[2, i
] := '';
162 if not(@pOldOnState
= nil) then pOldOnState(Sender
);
165 procedure TExceptionView
.pSetChanges(ACol
, ARow
: Integer; Change
: Boolean);
167 if (ACol
< 0) or (ACol
> 2) or (ARow
< 0) or (ARow
> 8) then Exit
;
168 pChanges
[ACol
, ARow
] := Change
;
171 procedure TExceptionView
.pSetColorTheme(ColorTheme
: TViewTheme
);
173 pColorTheme
:= ColorTheme
;
174 Color
:= ColorTheme
.Line
.None
.BG
;
177 procedure TExceptionView
.pSetHardware(Input
: THardware
);
180 if not(Input
= nil) then
182 pOldOnState
:= Input
.OnState
;
183 Input
.OnState
:= pOnState
;
187 procedure TExceptionView
.pSetWidth(Width
: Integer);
189 TStringGrid(Self
).Width
:= Width
;
190 ColWidths
[1] := Canvas
.TextWidth(EXC_VIEW_EXC
+ ' ');
191 ColWidths
[2] := Canvas
.TextWidth(EXC_VIEW_MASK
+ ' ');
192 ColWidths
[0] := ClientWidth
- ColWidths
[1] - ColWidths
[2];
195 constructor TExceptionView
.CreateExceptionView(AOwner
: TComponent
;
200 inherited Create(AOwner
);
201 DoubleBuffered
:= True;
202 ColorTheme
:= THEME_VIEW_DEFAULT
;
208 Options
:= [goRangeSelect
, goThumbTracking
];
209 // Behavior of goRangeSelect differ in Lazarus :-(
211 Options
:= [goThumbTracking
];
213 DefaultDrawing
:= False;
214 OnDrawCell
:= pCustomDrawCell
;
215 OnDblClick
:= pCustomDblClick
;
216 OnKeyDown
:= pCustomKeyDown
;
217 OnMouseDown
:= pCustomMouseDown
;
218 OnSelectCell
:= pOnSelectCell
;
219 Canvas
.Font
.Name
:= FONT_DEFAULT_NAME
;
220 Canvas
.Font
.Size
:= FONT_DEFAULT_SIZE
;
221 DefaultRowHeight
:= FONT_DEFAULT_HEIGHT
;
222 PopupMenu
:= TPopupMenu
.Create(Self
);
225 Items
.Add(TMenuItem
.Create(PopupMenu
));
226 with Items
[Items
.Count
- 1] do
228 Caption
:= EXC_VIEW_TOGGLE
;
229 OnClick
:= pCustomDblClick
;
237 // Lazarus is really nice, by having incompatible calls :-(
243 Selection
:= lselect
;
247 procedure TExceptionView
.ToggleException(Line
: Integer);
249 lstate
: THardwareState
;
251 if not(Line
> 0) then Exit
;
253 lstate
:= Hardware
.State
;
254 SetException(lstate
, Line
, not GetException(lstate
, Line
));
255 Hardware
.State
:= lstate
;
258 procedure TExceptionView
.ToggleMask(Line
: Integer);
260 lstate
: THardwareState
;
262 if not(Line
> 2) then Exit
;
264 lstate
:= Hardware
.State
;
265 SetMask(lstate
, Line
, not GetMask(lstate
, Line
));
266 Hardware
.State
:= lstate
;