summaryrefslogtreecommitdiff
path: root/src/reportengine/u_visu.pas
blob: eede74ae1a170daf28fb6242d5d540aaa29ffb35 (plain)
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
{
  fpGUI  -  Free Pascal GUI Toolkit

  Copyright (C) 2006 - 2012 See the file AUTHORS.txt, included in this
  distribution, for details of the copyright.

  See the file COPYING.modifiedLGPL, included in this distribution,
  for details about redistributing fpGUI.

  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.

  Description:
    This unit forms part of the PDF Reporting Engine. This unit
    implements the report preview form.

    The PDF Reporting Engine was originally written by
    Jean-Marc Levecque <jean-marc.levecque@jmlesite.fr>
}

unit U_Visu;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  {$ifdef win32}
  shellapi,
  {$endif}
  fpg_base,
  fpg_main,
  fpg_form,
  fpg_panel,
  fpg_label,
  fpg_button,
  fpg_edit,
  fpg_dialogs,
  fpg_utils,
  fpg_scrollbar,
  U_Report;

type

  TF_Visu = class(TfpgForm)
  private
    FReport: T_Report;
    Bv_Command: TfpgBevel;
    Bt_Close: TfpgButton;
    Bt_Print: TfpgButton;
    Bt_Printer: TfpgButton;
    Bt_Stop: TfpgButton;
    Bt_Pdf: TfpgButton;
    Bv_Pages: TfpgBevel;
    L_Pages: TfpgLabel;
    Bt_FirstPage: TfpgButton;
    Bt_PrecPage: TfpgButton;
    E_NumPage: TfpgEditInteger;
    Bt_NextPage: TfpgButton;
    Bt_LastPage: TfpgButton;
    L_FromPage: TfpgLabel;
    L_NbrPages: TfpgLabel;
    Bv_Sections: TfpgBevel;
    L_Sections: TfpgLabel;
    Bt_PrecSect: TfpgButton;
    E_NumSect: TfpgEditInteger;
    Bt_NextSect: TfpgButton;
    L_FromSect: TfpgLabel;
    L_NbrSect: TfpgLabel;
    L_PageSect: TfpgLabel;
    L_NumPageSect: TfpgLabel;
    L_FromPageSect: TfpgLabel;
    L_NbrPageSect: TfpgLabel;
    Bv_PreviewPage: TfpgBevel;
    VScrollBar: TfpgScrollbar;
    FPreviewMargin: integer;
    procedure FormShow(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure FormMouseScroll(Sender: TObject; AShift: TShiftState; AWheelDelta: Single; const AMousePos: TPoint);
    procedure VScrollBarScrolled(Sender: TObject; position: integer);
    procedure Bt_CloseClick(Sender: TObject);
    procedure Bt_PrintClick(Sender: TObject);
    procedure Bt_PrinterClick(Sender: TObject);
    procedure Bt_StopClick(Sender: TObject);
    procedure Bt_PdfClick(Sender: TObject);
    procedure Bt_FirstPageClick(Sender: TObject);
    procedure Bt_PrecPageClick(Sender: TObject);
    procedure Bt_NextPageClick(Sender: TObject);
    procedure Bt_LastPageClick(Sender: TObject);
    procedure Bt_PrecSectClick(Sender: TObject);
    procedure Bt_NextSectClick(Sender: TObject);
    procedure E_NumPageKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: Boolean);
    procedure E_NumSectKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: Boolean);
    procedure ChangeButtons;
    procedure SetPreviewMargin(AValue: integer);
    procedure RepositionPage;
  public
    constructor Create(AOwner: TComponent; AImprime: T_Report); reintroduce;
    destructor Destroy; override;
    procedure RecalcScrollbars;
    property PreviewMargin: integer read FPreviewMargin write SetPreviewMargin;
  end;

var
  F_Visu: TF_Visu;
  Bv_Visu: TfpgBevel;

implementation

uses
  U_Command,
  U_Pdf,
  U_ReportImages;

procedure TF_Visu.FormShow(Sender: TObject);
begin
  L_Pages.Text    := 'Page';
  L_Sections.Text := 'Section';
  L_PageSect.Text := 'Page';
  L_FromPage.Text := 'of';
  with FReport do
  begin
    if Sections.Count = 1 then
      E_NumSect.Focusable := False;
    if T_Section(Sections[Pred(Sections.Count)]).TotPages = 1 then
      E_NumPage.Focusable := False;
    E_NumPage.Text := IntToStr(NumPage);
    L_NbrPages.Text := IntToStr(T_Section(Sections[Pred(Sections.Count)]).TotPages);
    E_NumSect.Text := IntToStr(NumSection);
    L_NbrSect.Text     := IntToStr(Sections.Count);
    L_NumPageSect.Text := IntToStr(NumPageSection);
    L_NbrPageSect.Text := IntToStr(T_Section(Sections[Pred(NumSection)]).NbPages);
    ChangeButtons;
  end;
end;

procedure TF_Visu.FormResize(Sender: TObject);
begin
  if Assigned(Bv_Visu) then
  begin
    RepositionPage;
  end;
end;

procedure TF_Visu.FormMouseScroll(Sender: TObject; AShift: TShiftState;
    AWheelDelta: Single; const AMousePos: TPoint);
begin
  if AWheelDelta < 0 then
    VScrollBar.LineUp
  else
    VScrollBar.LineDown;
end;

procedure TF_Visu.VScrollBarScrolled(Sender: TObject; position: integer);
begin
  if Assigned(Bv_Visu) then
  begin
    Bv_Visu.Top := Bv_Command.Height + PreviewMargin - position;
    Bv_Visu.UpdateWindowPosition;
  end;
end;

procedure TF_Visu.Bt_CloseClick(Sender: TObject);
begin
  Close;
end;

procedure TF_Visu.Bt_PrintClick(Sender: TObject);
begin
end;

procedure TF_Visu.Bt_PrinterClick(Sender: TObject);
begin
end;

procedure TF_Visu.Bt_StopClick(Sender: TObject);
begin
end;

procedure TF_Visu.Bt_PdfClick(Sender: TObject);
var
  Fd_SavePdf: TfpgFileDialog;
  PdfFile: string;
  PdfFileStream: TFileStream;
begin
  Fd_SavePdf          := TfpgFileDialog.Create(nil);
  Fd_SavePdf.InitialDir := ExtractFilePath(ParamStr(0));
  Fd_SavePdf.FontDesc := 'bitstream vera sans-9';
  Fd_SavePdf.Filter   := 'PDF Documents |*.pdf';
  Fd_SavePdf.FileName := FReport.DefaultFile;
  try
    if Fd_SavePdf.RunSaveFile then
    begin
      PdfFile := Fd_SavePdf.FileName;
      if Lowercase(Copy(PdfFile, Length(PdfFile) - 3, 4)) <> '.pdf' then
        PdfFile := PdfFile + '.pdf';
      Document := TPdfDocument.CreateDocument;
      with Document do
      begin
        PdfFileStream := TFileStream.Create(PdfFile, fmCreate);
        WriteDocument(PdfFileStream);
        PdfFileStream.Free;
        Free;
      end;
      {$ifdef linux}
      fpgOpenURL(PdfFile);
      {$endif}
      {$ifdef win32}
      ShellExecute(0, PChar('OPEN'), PChar(PdfFile), PChar(''), PChar(''), 1);
      {$endif}
    end;
  finally
    Fd_SavePdf.Free;
  end;
end;

procedure TF_Visu.Bt_FirstPageClick(Sender: TObject);
begin
  with FReport do
  begin
    NumPage         := 1;
    NumSection      := 1;
    NumPageSection  := 1;
    E_NumPage.Text  := IntToStr(NumPage);
    with T_Section(Sections[Pred(NumSection)]), F_Visu do
    begin
      Bv_Visu.Height := Paper.H;
      Bv_Visu.Width  := Paper.W;
      RepositionPage;
      Bv_Visu.Invalidate;
    end;
    ChangeButtons;
    E_NumSect.Text     := IntToStr(NumSection);
    L_NumPageSect.Text := IntToStr(NumPageSection);
    L_NbrPageSect.Text := IntToStr(T_Section(Sections[Pred(NumSection)]).NbPages);
  end;
end;

procedure TF_Visu.Bt_PrecPageClick(Sender: TObject);
begin
  with FReport do
  begin
    NumPage := NumPage - 1;
    if NumPageSection = 1 then
    begin
      NumSection      := NumSection - 1;
      NumPageSection  := T_Section(Sections[Pred(NumSection)]).NbPages;
      with T_Section(Sections[Pred(NumSection)]), F_Visu do
      begin
        Bv_Visu.Height := Paper.H;
        Bv_Visu.Width  := Paper.W;
        RepositionPage;
      end;
    end
    else
    begin
      NumPageSection := NumPageSection - 1;
      Bv_Visu.Invalidate;
    end;
    E_NumPage.Text     := IntToStr(NumPage);
    ChangeButtons;
    E_NumSect.Text     := IntToStr(NumSection);
    L_NumPageSect.Text := IntToStr(NumPageSection);
    L_NbrPageSect.Text := IntToStr(T_Section(Sections[Pred(NumSection)]).NbPages);
  end;
end;

procedure TF_Visu.Bt_NextPageClick(Sender: TObject);
begin
  with FReport do
  begin
    NumPage := NumPage + 1;
    if NumPageSection = T_Section(Sections[Pred(NumSection)]).NbPages then
    begin
      NumSection      := NumSection + 1;
      NumPageSection  := 1;
      with T_Section(Sections[Pred(NumSection)]), F_Visu do
      begin
        Bv_Visu.Height := Paper.H;
        Bv_Visu.Width  := Paper.W;
        RepositionPage;
      end;
    end
    else
    begin
      NumPageSection := NumPageSection + 1;
      Bv_Visu.Invalidate;
    end;
    E_NumPage.Text     := IntToStr(NumPage);
    ChangeButtons;
    E_NumSect.Text     := IntToStr(NumSection);
    L_NumPageSect.Text := IntToStr(NumPageSection);
    L_NbrPageSect.Text := IntToStr(T_Section(Sections[Pred(NumSection)]).NbPages);
  end;
end;

procedure TF_Visu.Bt_LastPageClick(Sender: TObject);
begin
  with FReport do
  begin
    NumPage         := T_Section(Sections[Pred(Sections.Count)]).TotPages;
    NumSection      := Sections.Count;
    NumPageSection  := T_Section(Sections[Pred(Sections.Count)]).NbPages;
    E_NumPage.Text  := IntToStr(NumPage);
    with T_Section(Sections[Pred(NumSection)]), F_Visu do
    begin
      Bv_Visu.Height := Paper.H;
      Bv_Visu.Width  := Paper.W;
      RepositionPage;
      Bv_Visu.Invalidate;
    end;
    ChangeButtons;
    E_NumSect.Text     := IntToStr(NumSection);
    L_NumPageSect.Text := IntToStr(NumPageSection);
    L_NbrPageSect.Text := IntToStr(T_Section(Sections[Pred(NumSection)]).NbPages);
  end;
end;

procedure TF_Visu.Bt_PrecSectClick(Sender: TObject);
begin
  with FReport do
  begin
    NumSection      := NumSection - 1;
    NumPage         := T_Section(Sections[Pred(NumSection)]).FirstPage;
    NumPageSection  := 1;
    E_NumPage.Text  := IntToStr(NumPage);
    with T_Section(Sections[Pred(NumSection)]), F_Visu do
    begin
      Bv_Visu.Height := Paper.H;
      Bv_Visu.Width  := Paper.W;
      RepositionPage;
    end;
    ChangeButtons;
    E_NumSect.Text     := IntToStr(NumSection);
    L_NumPageSect.Text := IntToStr(NumPageSection);
    L_NbrPageSect.Text := IntToStr(T_Section(Sections[Pred(NumSection)]).NbPages);
  end;
end;

procedure TF_Visu.Bt_NextSectClick(Sender: TObject);
begin
  with FReport do
  begin
    NumSection      := NumSection + 1;
    NumPage         := T_Section(Sections[Pred(NumSection)]).FirstPage;
    NumPageSection  := 1;
    E_NumPage.Text  := IntToStr(NumPage);
    with T_Section(Sections[Pred(NumSection)]), F_Visu do
    begin
      Bv_Visu.Height := Paper.H;
      Bv_Visu.Width  := Paper.W;
      RepositionPage;
    end;
    ChangeButtons;
    E_NumSect.Text     := IntToStr(NumSection);
    L_NumPageSect.Text := IntToStr(NumPageSection);
    L_NbrPageSect.Text := IntToStr(T_Section(Sections[Pred(NumSection)]).NbPages);
  end;
end;

procedure TF_Visu.ChangeButtons;
begin
  with FReport do
    if T_Section(Sections[Pred(Sections.Count)]).TotPages > 1 then
      if NumPage = 1 then
      begin
        Bt_FirstPage.Enabled := False;
        Bt_PrecPage.Enabled  := False;
        Bt_NextPage.Enabled  := True;
        Bt_LastPage.Enabled  := True;
        Bt_PrecSect.Enabled  := False;
        if Sections.Count > 1 then
          Bt_NextSect.Enabled := True
        else
          Bt_NextSect.Enabled := False;
      end
      else if NumPage = T_Section(Sections[Pred(Sections.Count)]).TotPages then
      begin
        Bt_FirstPage.Enabled := True;
        Bt_PrecPage.Enabled  := True;
        Bt_NextPage.Enabled  := False;
        Bt_LastPage.Enabled  := False;
        if Sections.Count > 1 then
          Bt_PrecSect.Enabled := True
        else
          Bt_PrecSect.Enabled := False;
        Bt_NextSect.Enabled := False;
      end
      else
      begin
        Bt_FirstPage.Enabled := True;
        Bt_PrecPage.Enabled  := True;
        Bt_NextPage.Enabled  := True;
        Bt_LastPage.Enabled  := True;
        if Sections.Count > 1 then
          if NumSection = 1 then
          begin
            Bt_PrecSect.Enabled := False;
            Bt_NextSect.Enabled := True;
          end
          else if NumSection = Sections.Count then
          begin
            Bt_PrecSect.Enabled := True;
            Bt_NextSect.Enabled := False;
          end
          else
          begin
            Bt_PrecSect.Enabled := True;
            Bt_NextSect.Enabled := True;
          end
        else
        begin
          Bt_PrecSect.Enabled := False;
          Bt_NextSect.Enabled := False;
        end;
      end
    else
    begin
      Bt_FirstPage.Enabled := False;
      Bt_PrecPage.Enabled  := False;
      Bt_NextPage.Enabled  := False;
      Bt_LastPage.Enabled  := False;
      Bt_PrecSect.Enabled  := False;
      Bt_NextSect.Enabled  := False;
    end;
end;

procedure TF_Visu.SetPreviewMargin(AValue: integer);
begin
  if FPreviewMargin = AValue then
    Exit;
  FPreviewMargin := AValue;
end;

procedure TF_Visu.RepositionPage;
begin
  Bv_Visu.Left := (Width - Bv_Visu.Width - VScrollBar.Width - (PreviewMargin*2)) div 2;
  if Bv_Visu.Left < PreviewMargin then
    Bv_Visu.Left := PreviewMargin;

  Bv_Visu.Top := (Height - Bv_Visu.Height - (PreviewMargin*2)) div 2;
  if Bv_Visu.Top < Bv_Command.Height+PreviewMargin then
    Bv_Visu.Top := Bv_Command.Height+PreviewMargin;

  Bv_Visu.UpdateWindowPosition;
  RecalcScrollbars;
end;

procedure TF_Visu.E_NumPageKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: Boolean);
var
  CptSect, CptPage, CptPageSect: integer;
begin
  if (KeyCode = KeyReturn) or (KeyCode = KeyPEnter) then
    with FReport do
    begin
      if E_NumPage.Value > T_Section(Sections[Pred(Sections.Count)]).TotPages then
        NumPage := T_Section(Sections[Pred(Sections.Count)]).TotPages
      else if E_NumPage.Value = 0 then
        NumPage := 1
      else
        NumPage := E_NumPage.Value;
      E_NumPage.Value := NumPage;
      CptSect := 0;
      CptPage := 0;
      repeat
        Inc(CptSect);
        CptPageSect := 0;
        repeat
          Inc(CptPage);
          Inc(CptPageSect);
        until (CptPage = NumPage) or (CptPage = T_Section(Sections[Pred(Cptsect)]).NbPages);
      until CptPage = NumPage;
      NumSection         := CptSect;
      NumPageSection     := CptPagesect;
      Bv_Visu.Invalidate;
      ChangeButtons;
      E_NumSect.Text     := IntToStr(NumSection);
      L_NumPageSect.Text := IntToStr(NumPageSection);
      L_NbrPageSect.Text := IntToStr(T_Section(Sections[Pred(NumSection)]).NbPages);
    end;
end;

procedure TF_Visu.E_NumSectKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: Boolean);
begin
  if (KeyCode = KeyReturn) or (KeyCode = KeyPEnter) then
    with FReport do
    begin
      if E_NumSect.Value > Sections.Count then
        NumSection := Sections.Count
      else if E_NumSect.Value = 0 then
        NumSection := 1
      else
        NumSection := E_NumSect.Value;
      E_NumSect.Value := NumSection;
      NumPage := T_Section(Sections[Pred(NumSection)]).FirstPage;
      NumPageSection := 1;
      E_NumPage.Value    := NumPage;
      Bv_Visu.Invalidate;
      ChangeButtons;
      L_NumPageSect.Text := IntToStr(NumPageSection);
      L_NbrPageSect.Text := IntToStr(T_Section(Sections[Pred(NumSection)]).NbPages);
    end;
end;

constructor TF_Visu.Create(AOwner: TComponent; AImprime: T_Report);
var
  w: integer;
  h: integer;
begin
  inherited Create(AOwner);
  FReport        := AImprime;
  Name           := 'F_Visu';
  WindowTitle    := 'Preview';
  WindowPosition := wpAuto;
  if fpgApplication.ScreenWidth < 1055 then
    w := fpgApplication.ScreenWidth
  else
    w := 1055;
  if fpgApplication.ScreenHeight < 940 then
    h := fpgApplication.ScreenHeight - 66 { some taskbar height I guess }
  else
    h := 940;
  SetPosition(0, 0, w, h);
  BackgroundColor := fpgColor(51,51,51); // black/brown or should we use clShadow2 for theming abilities??
  MinHeight := 350;
  MinWidth := 640;
  OnShow   := @FormShow;
  OnResize := @FormResize;
  OnMouseScroll := @FormMouseScroll;

  FPreviewMargin := 10;

  CreateReportImages;

  Bv_PreviewPage := CreateBevel(self, 0, 0, 50, 50, bsBox, bsRaised);
  Bv_PreviewPage.BackgroundColor := clWhite;
  Bv_PreviewPage.OnMouseScroll := @FormMouseScroll;

  Bv_Command     := CreateBevel(Self, 0, 0, Width, 50, bsBox, bsRaised);
  Bv_Command.Align := alTop;
  Bt_Close       := CreateButton(Bv_Command, 10, 10, 26, '', @Bt_CloseClick, 'stdimg.exit');
  Bt_Print       := CreateButton(Bv_Command, 50, 10, 26, '', @Bt_PrintClick, 'stdimg.print');
  Bt_Print.Enabled := False;
  Bt_Printer     := CreateButton(Bv_Command, 90, 10, 26, '', @Bt_PrinterClick, 'repimg.Printer');
  Bt_Printer.Enabled := False;
  Bt_Stop        := CreateButton(Bv_Command, 130, 10, 26, '', @Bt_StopClick, 'repimg.Stop');
  Bt_Pdf         := CreateButton(Bv_Command, 170, 10, 26, '', @Bt_PdfClick, 'stdimg.Adobe_pdf');
  Bt_Pdf.ImageMargin := 0;
  Bv_Pages       := CreateBevel(Bv_Command, 220, 5, 300, 40, bsBox, bsLowered);
  Bv_Sections    := CreateBevel(Bv_Command, 540, 5, 500, 40, bsBox, bsLowered);

  Bt_FirstPage   := CreateButton(Bv_Pages, 54, 6, 26, '', @Bt_FirstPageClick, 'repimg.First');
  Bt_PrecPage    := CreateButton(Bv_Pages, 80, 6, 26, '', @Bt_PrecPageClick, 'repimg.Precedent');
  E_NumPage      := CreateEditInteger(Bv_Pages, 110, 6, 60, 0);
  E_NumPage.OnKeyPress := @E_NumPageKeypress;
  Bt_NextPage    := CreateButton(Bv_Pages, 174, 6, 26, '', @Bt_NextPageClick, 'repimg.Next');
  Bt_LastPage    := CreateButton(Bv_Pages, 200, 6, 26, '', @Bt_LastPageClick, 'repimg.Last');
  L_Pages        := CreateLabel(Bv_Pages, 5, E_NumPage.Top, 'Page', 45, E_NumPage.Height, taLeftJustify, tlcenter);
  L_FromPage     := CreateLabel(Bv_Pages, 235, E_NumPage.Top, 'of', 30, E_NumPage.Height, taLeftJustify, tlcenter);
  L_NbrPages     := CreateLabel(Bv_Pages, 265, E_NumPage.Top, ' ', 30, E_NumPage.Height, taCenter, tlcenter);

  Bt_PrecSect    := CreateButton(Bv_Sections, 90, 6, 26, '', @Bt_PrecSectClick, 'repimg.Precedent');
  E_NumSect      := CreateEditInteger(Bv_Sections, 120, 6, 60, 0);
  E_NumSect.OnKeyPress := @E_NumSectKeyPress;
  Bt_NextSect    := CreateButton(Bv_Sections, 184, 6, 26, '', @Bt_NextSectClick, 'repimg.Next');
  L_Sections     := CreateLabel(Bv_Sections, 5, E_NumSect.Top, 'Section', 75, E_NumSect.Height, taLeftJustify, tlcenter);
  L_FromSect     := CreateLabel(Bv_Sections, 250, E_NumSect.Top, 'of', 30, E_NumSect.Height, taLeftJustify, tlcenter);
  L_NbrSect      := CreateLabel(Bv_Sections, 280, E_NumSect.Top, '-', 30, E_NumSect.Height, taLeftJustify, tlcenter);
  L_PageSect     := CreateLabel(Bv_Sections, 320, E_NumSect.Top, 'Page', 45, E_NumSect.Height, taLeftJustify, tlcenter);
  L_NumPageSect  := CreateLabel(Bv_Sections, 365, E_NumSect.Top, '-', 30, E_NumSect.Height, taLeftJustify, tlcenter);
  L_FromPageSect := CreateLabel(Bv_Sections, 410, E_NumSect.Top, 'of', 30, E_NumSect.Height, taLeftJustify, tlcenter);
  L_NbrPageSect  := CreateLabel(Bv_Sections, 440, E_NumSect.Top, '-', 30, E_NumSect.Height, taLeftJustify, tlcenter);

  Bv_Visu := Bv_PreviewPage; // assign to global reference variable

  VScrollBar := TfpgScrollbar.Create(self);
  with VScrollBar do
  begin
    Name := 'VScrollBar';
    SetPosition(self.Width-24, 51, 16, self.Height - (Bv_Command.Height));
    Orientation := orVertical;
    Align := alRight;
    ScrollStep := 50;
    PageSize := 200;
    OnScroll := @VScrollBarScrolled;
  end;
end;

destructor TF_Visu.Destroy;
begin
  DeleteReportImages;
  inherited Destroy;
end;

procedure TF_Visu.RecalcScrollbars;
var
  h: integer;
begin
  h := Bv_Visu.Height + (PreviewMargin*2);
  { if page is smaller than screen space, scrolling gets disabled }
  if h > VScrollBar.Height then
    VScrollBar.Max := Abs(h - VScrollBar.Height)
  else
    VScrollBar.Max := 0;
  VScrollBar.SliderSize := VScrollBar.Height / h;
  VScrollBar.Position := 0;
  VScrollBar.RepaintSlider;
end;

end.