forked from groehner/JavaEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUBaseForm.pas
More file actions
429 lines (371 loc) · 10.6 KB
/
UBaseForm.pas
File metadata and controls
429 lines (371 loc) · 10.6 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
unit UBaseForm;
interface
uses
Messages,
Classes,
Graphics,
Controls,
Forms;
{ are derived from TFForm (with type identifier)
FormTag
// a ActiveTDIChild
TFEditForm %E% 1 FormMouseActivate
TFUMLForm %U% 2 FormMouseActivate
TFGUIForm %G% 3 FormMouseActivate but no TDIForm
TFTextDiff %D% 4 FormMouseActivate
TFBrowser %B% 5 FormMouseActivate
TFExplorer %X% 6 FormMouseActivate
TFStructogram %S% 11 FormMouseActivate
TFSequenceForm %Q% 14 FormMouseActivate
// a ActiveTool FJava.ActiveTool:=
TFMessages 7 X nicht modal FormMouseActivate + FormShow FormClose -1
TFObjectInspector 8 X nicht modal FormMouseActivate + FormShow FormClose -1
TFObjectGenerator 9 - modal FormShow FormClose -1
TFScpHint 10 - nicht modal FormMouseActivate + FormShow FormClose -1
TFTooltip 12 - nicht modal FormMouseActivate + FormShow FormClose -1
TSynBaseCompletionProposalFormEx 13
TFConfiguration 15 - modal FormShow FormClose -1
TFFileStructure 16 X nicht modal FormMouseActivate + FormShow FormClose -1
TFGUIForm 17 nicht modal because no TDIForm DOPPELT?
}
type
TFormKind = (fkEditor, fkUML, fkGUI, fkFXGUI, fkTextDiff, fkBrowser, fkExplorer, fkStructogram, fkSequence);
{ TFForm }
TFForm = class(TForm)
procedure WMSize(var Msg: TMessage); message WM_SIZE;
procedure FormMouseActivate(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y, HitTest: Integer;
var MouseActivate: TMouseActivate);
procedure FormActivate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
private
FModified: Boolean;
FNumber: Integer;
FPathname: string;
FPartner: TFForm;
FFormTag: Integer;
FLockEnter: Boolean;
FHasFocus : Boolean;
FAlreadySavedAs: Boolean;
class var FFormNumber: Integer; // class attribute
protected
procedure FormClose(Sender: TObject; var AAction: TCloseAction); virtual;
procedure UpdateState; virtual;
function GetModified: Boolean; virtual;
procedure SetModified(Modified: Boolean); virtual;
public
constructor Create(AOwner: TComponent); override;
procedure SetOptions; virtual;
function GetState: string; virtual;
function GetFormType: string; virtual;
function IsDefaultFilename: Boolean;
procedure OpenWindow(Sender: TObject); virtual;
procedure CollectClasses(StringList: TStringList); virtual;
procedure ToMainPanel;
procedure SetActiveControl(AControl: TWinControl);
function MyActiveControl: TWinControl;
procedure SaveIn(const Dir: string); virtual;
function GetSaveAsName: string; virtual;
procedure Save(WithBackup: Boolean); virtual;
procedure DoExport; virtual;
procedure Print; virtual;
procedure Search; virtual;
procedure SearchAgain; virtual;
procedure Replace; virtual;
procedure Undo; virtual;
procedure Redo; virtual;
procedure CutToClipboard; virtual;
procedure CopyToClipboard; virtual;
procedure PasteFromClipboard; virtual;
procedure SetFont(AFont: TFont); virtual;
function GetFont: TFont; virtual;
procedure SetFontSize(Delta: Integer); virtual;
procedure Enter(Sender: TObject); virtual;
procedure SetState(var State: string); virtual;
function GetAllPathnames: TStringList; virtual;
function GetAllClassnames: TStringList; virtual;
procedure ChangeStyle; virtual;
procedure DPIChanged; virtual;
property Number: Integer read FNumber;
property HasFocus: Boolean read FHasFocus;
property Pathname: string read FPathname write FPathname;
property Partner: TFForm read FPartner write FPartner;
property FormTag: Integer read FFormTag write FFormTag;
property LockEnter: Boolean read FLockEnter write FLockEnter;
property AlreadySavedAs: Boolean read FAlreadySavedAs write FAlreadySavedAs;
property Modified: Boolean read GetModified write SetModified;
end;
implementation
uses
Windows,
SysUtils,
JvGnugettext,
UStringRessources,
UUtils,
UJava,
UConfiguration,
UTabObject;
{$R *.dfm}
constructor TFForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FPartner:= nil;
Inc(FFormNumber);
FNumber:= FFormNumber;
FAlreadySavedAs:= False;
FLockEnter:= False;
OnClose:= FormClose;
OnMouseActivate:= FormMouseActivate;
ParentFont:= False;
// this garanties, that the form is scaled to effectiv dpi
// scaling is not done fore every position, see: procedure TCustomForm.SetWindowToMonitor
// SetBounds calls TCustomForm.WMDpiChanged
Position:= poScreenCenter;
end;
procedure TFForm.FormActivate(Sender: TObject);
begin
FHasFocus := True;
end;
procedure TFForm.FormClose(Sender: TObject; var AAction: TCloseAction);
begin
try
FJava.DeleteTabAndWindow(Number);
if not IsDefaultFilename and (FJava.ProjectFilename = '') then
FJava.RearrangeFileHistory(Pathname);
finally
FJava.TDIFormsList.Remove(Self);
if Assigned(FJava.myTabBar.SelectedTab) and Assigned(FJava.myTabBar.SelectedTab.Data)
then FJava.ActiveTDIChild:= TTabObject(FJava.myTabBar.SelectedTab.Data).Form
else FJava.ActiveTDIChild:= nil;
AAction:= caFree;
end;
end;
procedure TFForm.FormDeactivate(Sender: TObject);
begin
FHasFocus := False;
end;
procedure TFForm.FormMouseActivate(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y, HitTest: Integer;
var MouseActivate: TMouseActivate);
begin
if (FJava.ActiveTDIChild <> Self) or (FJava.ActiveTool > 0) then
Enter(Self);
MouseActivate:= maActivate;
end;
procedure TFForm.Save(WithBackup: Boolean);
begin
// in some descendet classes Save isn't needed
end;
procedure TFForm.SaveIn(const Dir: string);
begin
// nothing to do
end;
function TFForm.GetSaveAsName: string;
begin
Result:= '';
end;
function TFForm.GetFormType: string;
begin
Result:= '';
end;
procedure TFForm.Print;
begin
inherited Print; // because of GUI-Formular-Print
end;
function TFForm.GetState: string;
begin
Result:= 'W' + IntToStr(Left) + ')' + IntToStr(Top) + ')' +
IntToStr(Width) + ')' + IntToStr(Height) + ')' +
WindowStateToStr(WindowState) + ')';
end;
procedure TFForm.SetState(var State: string);
var Posi: Integer;
begin
if Copy(State, 1, 1) = 'W' then begin
Posi:= Pos(')', State); Delete(State, 1, Posi);
Posi:= Pos(')', State); Delete(State, 1, Posi);
Posi:= Pos(')', State); Delete(State, 1, Posi);
Posi:= Pos(')', State); Delete(State, 1, Posi);
Posi:= Pos(')', State);
WindowState:= StrToWindowState(Copy(State, 1, Posi - 1));
end;
end;
procedure TFForm.SetFont(AFont: TFont);
begin
Font.Assign(AFont);
end;
function TFForm.GetFont: TFont;
begin
Result:= Font;
end;
procedure TFForm.SetFontSize(Delta: Integer);
begin
Font.Size:= Font.Size + Delta;
if Font.Size < 6 then Font.Size:= 6;
SetFont(Font);
end;
procedure TFForm.SetOptions;
begin
// nothing to do
end;
procedure TFForm.Search;
begin
// nothing to do
end;
procedure TFForm.SearchAgain;
begin
// nothing to do
end;
procedure TFForm.Replace;
begin
// nothing to do
end;
procedure TFForm.CutToClipboard;
begin
// nothing to do
end;
procedure TFForm.CopyToClipboard;
begin
// nothing to do
end;
procedure TFForm.PasteFromClipboard;
begin
// nothing to do
end;
procedure TFForm.Undo;
begin
// nothing to do
end;
procedure TFForm.Redo;
begin
// nothing to do
end;
procedure TFForm.OpenWindow(Sender: TObject);
var Animation: Boolean;
begin
LockWindow(Self.Handle);
try
try
Animation:= GetAnimation;
if Animation then
SetAnimation(False);
if Parent = FJava.MainPanel then begin
if Left > FJava.Width - 200 then
Left:= FJava.Width - 200;
end;
if not Visible then begin
Visible:= True;
FJava.AddToWindowMenuAndTabBar(Number, OpenWindow, Self);
end;
if Animation then
SetAnimation(True);
BringToFront;
Enter(Self);
except
on E: Exception do
FConfiguration.Log('OpenWindow: ' + Pathname, E);
end;
finally
UnlockWindow;
end;
end;
procedure TFForm.Enter(Sender: TObject);
begin
FJava.ActiveTool:= -1;
FJava.SetSelectedTabAndWindow(Number);
FJava.MyTabBarColorize;
FJava.ActiveTDIChild:= Self;
FJava.UpdateMenuItems(Self);
ChangeStyle;
end;
procedure TFForm.UpdateState;
begin
with FJava do begin
DisableMI(MIUndo);
DisableTB(TBUndo);
DisableMI(MIRedo);
DisableTB(TBRedo);
DisableMI(MICopyRTF);
DisableMI(MICopyHTML);
DisableMI(MICopyHTMLAsText);
DisableMI(MICopyNumbered);
DisableMI(MICopyRtfNumbered);
end;
end;
procedure TFForm.SetModified(Modified: Boolean);
begin
FModified:= Modified;
FJava.TabModified(Number, Modified);
end;
function TFForm.GetModified: Boolean;
begin
Result:= FModified;
end;
procedure TFForm.ChangeStyle;
begin
// nothing to do
end;
procedure TFForm.DPIChanged;
begin
ScaleForCurrentDPI;
end;
procedure TFForm.DoExport;
begin
// nothing to do
end;
procedure TFForm.CollectClasses(StringList: TStringList);
begin
// nothing to do
end;
function TFForm.IsDefaultFilename: Boolean;
var Posi: Integer; Str, Default: string;
begin
Result:= False;
if Assigned(FConfiguration) then
if not FConfiguration.AcceptDefaultname then begin
Default:= UpperCase(_(LNGFile));
Str:= UpperCase(ExtractFileName(Pathname));
if Copy(Str, 1, Length(Default)) = Default then begin
Delete(Str, 1, Length(Default));
Posi:= Pos('.', Str);
Delete(Str, Posi, Length(Str));
Result:= TryStrToInt(Str, Posi);
end
else
Result:= False;
end;
end;
function TFForm.GetAllPathnames: TStringList;
begin
Result:= TStringList.Create;
end;
function TFForm.GetAllClassnames: TStringList;
begin
Result:= TStringList.Create;
end;
procedure TFForm.WMSize(var Msg: TMessage);
begin
inherited;
if Msg.WParam = SIZE_MAXIMIZED then
FConfiguration.WindowStateMaximized:= True;
end;
procedure TFForm.ToMainPanel;
begin
Align:= alClient;
BorderStyle:= bsNone;
BorderIcons:= [];
Parent:= FJava.MainPanel;
end;
function TFForm.MyActiveControl: TWinControl;
// https://de.comp.lang.delphi.misc.narkive.com/AU1p5kiy/activecontrol-nil
begin
Result:= Application.MainForm.ActiveControl;
end;
procedure TFForm.SetActiveControl(AControl: TWinControl);
begin
if Assigned(Parent) then
Application.MainForm.ActiveControl:= AControl;
end;
initialization
TFForm.FFormNumber:= 0;
end.