-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUInput.pas
201 lines (168 loc) · 4.6 KB
/
UInput.pas
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
199
200
201
(*
Letterpress
Copyright 2009-2010, Garnet
*)
unit UInput;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms, UxTheme, StdCtrls,
{ Letterpress }
URoutine,
{ SynEdit }
SynUnicode, ExtCtrls;
type
TFrmInput = class(TForm)
memoInput: TMemo;
btnOK: TButton;
btnCancel: TButton;
btnEOF: TButton;
btnEOLEOF: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure btnEOFClick(Sender: TObject);
procedure btnEOLEOFClick(Sender: TObject);
procedure btnOKClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
private
fData: PUTF8String;
fInputThread: TInputCommandThread;
fEditor: TObject;
fHTMLWindow: TForm;
public
property InputData: PUTF8String write fData;
property InputThread: TInputCommandThread read fInputThread write fInputThread;
property Editor: TObject read fEditor write fEditor;
property HTMLWindow: TForm read fHTMLWindow write fHTMLWindow;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
end;
var
FrmInput: TFrmInput;
implementation
uses
UImpress, UConst;
{$R *.dfm}
{ TFrmInput }
// -----------------------------------------------------------------------------
procedure TFrmInput.CreateParams(var Params: TCreateParams);
begin
inherited;
with Params do
begin
ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
WndParent := (Owner as TForm).Handle;
end;
end;
// -----------------------------------------------------------------------------
// Allow to drag form by contents, allow to resize by gripper
procedure TFrmInput.WMNCHitTest(var Msg: TWMNCHitTest);
var
GripRect: TRect;
begin
inherited;
if Msg.Result = htClient then
Msg.Result := htCaption;
{ See if on gripper }
GripRect := BoundsRect;
with GripRect do
begin
Left := Right - GetSystemMetrics(SM_CXVSCROLL);
Top := Bottom - GetSystemMetrics(SM_CYVSCROLL);
end;
if PtInRect(GripRect, Point(Msg.XPos, Msg.YPos)) then
Msg.Result := HTBOTTOMRIGHT;
end;
// -----------------------------------------------------------------------------
// Paint size gripper
procedure TFrmInput.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
var
Theme: HTHEME;
GripRect: TRect;
begin
{ Initialize }
Msg.Result := 1;
inherited;
{ Get size grip rect }
GripRect := ClientRect;
with GripRect do
begin
Left := Right - GetSystemMetrics(SM_CXVSCROLL);
Top := Bottom - GetSystemMetrics(SM_CYVSCROLL);
{ Fill it and everything to the lft with background color }
Canvas.FillRect(Rect(0, Top, Right, Bottom));
end;
{ Draw size grip }
Theme := OpenThemeData(Application.Handle, 'STATUS');
try
DrawThemeBackground(Theme, Canvas.Handle, SP_GRIPPER, 0, GripRect, nil);
finally
CloseThemeData(Theme);
end;
end;
{ Form }
// -----------------------------------------------------------------------------
procedure TFrmInput.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
(*
if Assigned(fEditor) then
(fEditor as TSynEdit).RemoveInputForm;
if Assigned(fHTMLWindow) then
(fHTMLWindow as TFrmImpress).RemoveInputForm;
if ModalResult = mrNone then
try
fInputThread.Canceled := True;
finally
end;
*)
end;
procedure TFrmInput.FormCreate(Sender: TObject);
begin
DesktopFont := True;
fEditor := nil;
fHTMLWindow := nil;
end;
{ Answers }
// -----------------------------------------------------------------------------
procedure TFrmInput.btnEOFClick(Sender: TObject);
begin
try
fData^ := UnicodeStringToUTF8(memoInput.Text) + #13#10#26;
fInputThread.InputReady := True;
finally
end;
ModalResult := mrOk;
Close;
end;
procedure TFrmInput.btnEOLEOFClick(Sender: TObject);
begin
try
fData^ := UnicodeStringToUTF8(memoInput.Text) + #26;
fInputThread.InputReady := True;
finally
end;
ModalResult := mrOk;
Close;
end;
procedure TFrmInput.btnOKClick(Sender: TObject);
begin
try
fData^ := UnicodeStringToUTF8(memoInput.Text) + #13#10;
fInputThread.InputReady := True;
finally
end;
ModalResult := mrOk;
Close;
end;
procedure TFrmInput.btnCancelClick(Sender: TObject);
begin
try
fInputThread.Canceled := True;
finally
end;
ModalResult := mrCancel;
Close;
end;
end.