-
Notifications
You must be signed in to change notification settings - Fork 1
/
presedit.pas
480 lines (407 loc) · 13 KB
/
presedit.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
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
{
This file belongs to the package "nick" which can be installed in the Lazarus IDE.
The package "nick" is dedicated to Nick Reinders.
Copyright (C) 2016 - 2018 Andreas Jakobsche [email protected]
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,and
to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a
module which is not derived from or based on this library. If you modify
this library, you may extend this exception to your version of the library,
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
unit PresEdit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DBObjPas,
ExtCtrls;
type
{ TPresentationPage }
TPresentationPage = class(TDataRecord)
private
FDelay: Integer;
FPicture: TPicture;
function GetPicture: TPicture;
public
destructor Destroy; override;
published
property Delay: Integer read FDelay write FDelay;
property Picture: TPicture read GetPicture write FPicture;
end;
TPresentationEditor = class;
{ TPresentation }
TPresentation = class(TDataTable) {streamable container for a presentation}
private
FDelay: Integer;
FEditor: TPresentationEditor;
FTitle: string;
function GetPages(I: Integer): TPresentationPage;
procedure Loaded; override;
public
constructor Create(AnOwner: TComponent); override;
procedure AddPage(FileName: string);
procedure Clear;
procedure Delete(AnIndex: Integer);
function IsEmpty: Boolean;
procedure LoadFromFile(FileName: string);
procedure SaveToFile(FileName: string);
property Editor: TPresentationEditor read FEditor write FEditor;
property Pages[I: Integer]: TPresentationPage read GetPages;
published
property Delay: Integer read FDelay write FDelay; {used for pages without
their own value}
property Title: string read FTitle write FTitle;
end;
{ TMiniPageView }
TMiniPageView = class(TCustomControl)
private
FEditor: TPresentationEditor;
FPageIndex: Integer;
FPage: TPresentationPage;
FBitmap: TBitmap;
procedure Move(Destination: TMiniPageView);
procedure SetPage(AValue: TPresentationPage);
property Bitmap: TBitmap read FBitmap write FBitmap;
property Editor: TPresentationEditor read FEditor;
protected
procedure DragOver(Source: TObject; X,Y: Integer; State: TDragState;
var Accept: Boolean); override;
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
procedure Paint; override;
procedure SetParent(NewParent: TWinControl); override;
public
constructor Create(AnOwner: TComponent); override;
destructor Destroy; override;
procedure DragDrop(Source: TObject; X,Y: Integer); override;
procedure SetFocus; override;
procedure View;
property Page: TPresentationPage read FPage write SetPage;
property PageIndex: Integer read FPageIndex write FPageIndex;
end;
type
{ TPresentationEditor }
TPresentationEditor = class(TScrollBox)
private
FItemIndex: Integer;
FMiniPageViewList: TList;
FPresentation: TPresentation;
FImage: TImage;
function GetMiniPageView(i: Integer): TMiniPageView;
function GetMiniPageViewCount: Integer;
function GetMiniPageViewList: TList;
function GetMiniPageViews(i: Integer): TMiniPageView;
function GetPresentation: TPresentation;
procedure ResizeMiniPageViews;
procedure SetItemIndex(Value: Integer);
procedure UpdateMiniPageViews;
property MiniPageViewList: TList read GetMiniPageViewList;
protected
public
constructor Create(AnOwner: TComponent); override;
destructor Destroy; override;
procedure AddPage(FileName: string);
procedure Delete(AnIndex: Integer);
property ItemIndex: Integer read FItemIndex write SetItemIndex;
property MiniPageViewCount: Integer read GetMiniPageViewCount;
property MiniPageViews[i: Integer]: TMiniPageView read GetMiniPageView;
property Presentation: TPresentation read GetPresentation;
published
property Image: TImage read FImage Write FImage;
end;
procedure Register;
implementation
uses Streaming2;
procedure Register;
begin
RegisterComponents('Nick''s Components',[TPresentationEditor]);
end;
{ TMiniPageView }
procedure TMiniPageView.Move(Destination: TMiniPageView);
begin
Editor.Presentation.Move(Self.Page, Destination.Page);
Editor.UpdateMiniPageViews;
end;
procedure TMiniPageView.SetPage(AValue: TPresentationPage);
var
Rel: Extended;
begin
if FPage=AValue then Exit;
FPage:=AValue;
if FPage.Picture <> nil then begin
if FBitmap = nil then FBitmap := TBitmap.Create;
if FPage.Picture.Width > FPage.Picture.Height then Rel := Width / FPage.Picture.Width
else Rel := Height / FPage.Picture.Height;
FBitmap.Width := Round(FPage.Picture.Width * Rel);
FBitmap.Height := Round(FPage.Picture.Height * Rel);
FBitmap.Canvas.StretchDraw(Rect(0, 0, FBitmap.Width, FBitmap.Height), FPage.Picture.Graphic);
end;
end;
procedure TMiniPageView.DragDrop(Source: TObject; X, Y: Integer);
begin
inherited DragDrop(Source, X, Y);
if Source <> Self then begin
(Source as TMiniPageView).Move(Self);
SetFocus
end;
end;
procedure TMiniPageView.DragOver(Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
inherited DragOver(Source, X, Y, State, Accept);
Accept := True
end;
procedure TMiniPageView.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
View;
if (Shift = []) and (Button = mbLeft) then BeginDrag(True)
end;
procedure TMiniPageView.SetFocus;
begin
inherited SetFocus;
View
end;
procedure TMiniPageView.View;
begin
if Editor <> nil then begin
Editor.FItemIndex := PageIndex;
if Editor.Image <> nil then
if Page <> nil then
if Page.Picture <> nil then
Editor.Image.Picture := Page.Picture;
Editor.ScrollInView(Self)
end;
end;
procedure TMiniPageView.Paint;
var
X, Y: Integer;
begin
inherited Paint;
if Focused then Canvas.Brush.Color := clRed
else Canvas.Brush.Color := clGray;
Canvas.FillRect(ClientRect);
if Page <> nil then
if Page.Picture <> nil then begin
X := (Width - Bitmap.Width) div 2;
Y := (Height - Bitmap.Height) div 2;
Canvas.Draw(X, Y, Bitmap);
end;
end;
procedure TMiniPageView.SetParent(NewParent: TWinControl);
begin
inherited SetParent(NewParent);
if Parent is TPresentationEditor then TWinControl(FEditor) := Parent;
end;
constructor TMiniPageView.Create(AnOwner: TComponent);
begin
inherited Create(AnOwner);
DragMode := dmAutomatic;
end;
destructor TMiniPageView.Destroy;
begin
FBitmap.Free;
inherited Destroy;
end;
{ TPresentationPage }
function TPresentationPage.GetPicture: TPicture;
begin
if not Assigned(FPicture) then FPicture := TPicture.Create;
Result := FPicture;
end;
destructor TPresentationPage.Destroy;
begin
FPicture.Free;
inherited Destroy;
end;
{ TPresentation }
function TPresentation.GetPages(I: Integer): TPresentationPage;
begin
TDataRecord(Result) := Items[I]
end;
procedure TPresentation.Loaded;
begin
inherited Loaded;
if Editor <> nil then Editor.UpdateMiniPageViews;
end;
constructor TPresentation.Create(AnOwner: TComponent);
begin
inherited Create(AnOwner);
Delay := 18000;
Title := 'Beispiel für Presenta Viewer'
end;
procedure TPresentation.AddPage(FileName: string);
var
Page: TPresentationPage;
begin
TDataRecord(Page) := NewItem(TPresentationPage);
Page.Picture.LoadFromFile(FileName);
end;
procedure TPresentation.Clear;
var
i: Integer;
begin
for i := ItemCount - 1 downto 0 do Pages[i].Free;
ItemList.Clear;
end;
procedure TPresentation.Delete(AnIndex: Integer);
var
ToDelete: TPresentationPage;
begin
ToDelete := Pages[AnIndex];
ToDelete.Free
end;
function TPresentation.IsEmpty: Boolean;
begin
Result := ItemCount = 0
end;
procedure TPresentation.LoadFromFile(FileName: string);
begin
ReadBinaryFromFile(FileName, TComponent(Self));
if Editor <> nil then Editor.UpdateMiniPageViews;
end;
procedure TPresentation.SaveToFile(FileName: string);
begin
WriteBinaryToFile(FileName, Self)
end;
{ TPresentationEditor }
procedure TPresentationEditor.UpdateMiniPageViews;
var
i, j: Integer;
MPV: TMiniPageView;
begin
if MiniPageViewCount <= Presentation.ItemCount then begin
for i := 0 to MiniPageViewCount - 1 do begin
MiniPageViews[i].Page := Presentation.Pages[i];
if i = ItemIndex then MiniPageViews[i].SetFocus;
end;
for j := MiniPageViewCount to Presentation.ItemCount - 1 do begin
MPV := TMiniPageView.Create(Self);
MPV.Parent := Self;
MPV.PageIndex := j;
MPV.Top := 0;
MPV.Height := ClientHeight;
MPV.Width := ClientHeight;
MPV.Left := (MPV.Width + 8) * j;
MiniPageViewList.Add(MPV);
MPV.Page := Presentation.Pages[j];
if j = ItemIndex then MiniPageViews[j].SetFocus;
end;
end
else begin
for i := 0 to Presentation.ItemCount - 1 do begin
MiniPageViews[i].Page := Presentation.Pages[i];
if ItemIndex = -1 then ItemIndex := i;
end;
for j := Presentation.ItemCount to MiniPageViewCount - 1 do begin
if j = ItemIndex then ItemIndex := j - 1;
MPV := MiniPageViews[j];
MiniPageViewList.Delete(j);
MPV.Free
end;
end;
ResizeMiniPageViews;
for i := 0 to MiniPageViewCount - 1 do MiniPageViews[i].Paint
end;
function TPresentationEditor.GetMiniPageViewCount: Integer;
begin
if Assigned(FMiniPageViewList) then Result := FMiniPageViewList.Count
else Result := 0
end;
function TPresentationEditor.GetMiniPageViewList: TList;
begin
if not Assigned(FMiniPageViewList) then FMiniPageViewList := TList.Create;
Result := FMiniPageViewList
end;
function TPresentationEditor.GetMiniPageViews(i: Integer): TMiniPageView;
begin
Pointer(Result) := MiniPageViewList[i]
end;
function TPresentationEditor.GetMiniPageView(i: Integer): TMiniPageView;
begin
Pointer(Result) := MiniPageViewList[i]
end;
{function TPresentationEditor.GetMiniPageViewCount: Integer;
begin
if Assigned(FMiniPageViewList) then Result := FMiniPageViewList.Count
else Result := 0
end;}
{function TPresentationEditor.GetMiniPageViewList: TList;
begin
if not Assigned(FMiniPageViewList) then FMiniPageViewList := TList.Create
Result := FMiniPageViewList
end;}
{function TPresentationEditor.GetMiniPageViews(i: Integer): TMiniPageView;
begin
Pointer(Result) := MiniPageViewList[i]
end;}
function TPresentationEditor.GetPresentation: TPresentation;
begin
if not Assigned(FPresentation) then begin
FPresentation := TPresentation.Create(Self);
FPresentation.Editor := Self;
end;
Result := FPresentation
end;
procedure TPresentationEditor.ResizeMiniPageViews;
begin
end;
procedure TPresentationEditor.SetItemIndex(Value: Integer);
begin
if FItemIndex = Value then Exit;
if Value < MiniPageViewCount then begin
FItemIndex := Value;
if Value > -1 then MiniPageViews[Value].SetFocus;
if Image <> nil then Image.Picture := MiniPageViews[Value].Page.Picture;
end;
end;
{procedure TPresentationEditor.UpdateMiniPageViews;
begin
end;}
{procedure TPresentationEditor.ResizeMiniPageViews;
var
i: Integer;
begin
for i := 0 to MiniPageViewCount - 1 do begin
MiniPageViews[i].Height := ClientHeight;
MiniPageViews[i].Width := MiniPageViews[i].Height;
MiniPageViews[i].Top := 0;
MiniPageViews[i].Left := (MiniPageViews[i].Width + 8) * i
end;
end;}
constructor TPresentationEditor.Create(AnOwner: TComponent);
begin
inherited Create(AnOwner);
if not (csDesigning in ComponentState) then Color := clBlack;
end;
destructor TPresentationEditor.Destroy;
begin
FMiniPageViewList.Free;
inherited Destroy;
end;
procedure TPresentationEditor.AddPage(FileName: string);
begin
Presentation.AddPage(FileName);
{if not (csUpdating in ComponentState) then} UpdateMiniPageViews;
end;
procedure TPresentationEditor.Delete(AnIndex: Integer);
begin
Presentation.Delete(AnIndex);
UpdateMiniPageViews;
end;
end.