File: cetitlefootdlg.pas

package info (click to toggle)
lazarus 2.2.6%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 219,980 kB
  • sloc: pascal: 1,944,919; xml: 357,634; makefile: 270,608; cpp: 57,115; sh: 3,249; java: 609; perl: 297; sql: 222; ansic: 137
file content (114 lines) | stat: -rw-r--r-- 2,585 bytes parent folder | download | duplicates (4)
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
unit ceTitleFootDlg;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Graphics,
  Forms, Controls, Dialogs, ButtonPanel, ExtCtrls, Buttons, ComCtrls,
  TAGraph, TATextElements,
  ceTitleFootFrame;

type

  { TChartTitleFootEditor }

  TChartTitleFootEditor = class(TForm)
    ButtonPanel: TButtonPanel;
    procedure FormActivate(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure OKButtonClick(Sender: TObject);
  private
    FTitle: TChartTitle;
    FSavedTitle: TChartTitle;
    FTitleFootFrame: TChartTitleFootFrame;
    FOKClicked: boolean;
  protected
    function GetChart: TChart;
  public
    procedure Prepare(ATitle: TChartTitle; ACaption: String = '');

  end;

var
  TitleFootEditor: TChartTitleFootEditor;

implementation

{$R *.lfm}

uses
  TATypes;

procedure TChartTitleFootEditor.FormActivate(Sender: TObject);
var
  h: Integer = 0;
  w: Integer = 0;
begin
  FTitleFootFrame.GetPreferredSize(w, h);
  inc(h, FTitleFootFrame.BorderSpacing.Around * 2);
  inc(w, FTitleFootFrame.BorderSpacing.Around * 2);

  Constraints.MinHeight := h + ButtonPanel.Height + ButtonPanel.BorderSpacing.Around*2;
  Constraints.MinWidth := w;

  Width := 1;   // Enforce the constraints.
  Height := 1;
end;

procedure TChartTitleFootEditor.FormCloseQuery(Sender: TObject;
  var CanClose: boolean);
begin
  if not CanClose then exit;
  if not FOKClicked then begin
    FTitle.Assign(FSavedTitle);
    GetChart.Invalidate;
  end;
end;

procedure TChartTitleFootEditor.FormCreate(Sender: TObject);
begin
  // Insert frames at runtime - this makes life much easier...
  FTitleFootFrame := TChartTitleFootFrame.Create(self);
  FTitleFootFrame.Parent := Self;
  FTitleFootFrame.Name := '';
  FTitleFootFrame.Align := alClient;
  FTitleFootFrame.BorderSpacing.Around := 8;
  FTitleFootFrame.AutoSize := true;

//  AutoSize := true;
end;

procedure TChartTitleFootEditor.FormDestroy(Sender: TObject);
begin
  FSavedTitle.Free;
end;

function TChartTitleFootEditor.GetChart: TChart;
begin
  Result := FTitle.GetOwner as TChart;
end;

procedure TChartTitleFootEditor.OKButtonClick(Sender: TObject);
begin
  FOKClicked := true;
end;

procedure TChartTitleFootEditor.Prepare(ATitle: TChartTitle; ACaption: String = '');
begin
  FTitle := ATitle;
  if FSavedTitle = nil then
    FSavedTitle := TChartTitle.Create(GetChart);
  FSavedTitle.Assign(FTitle);

  if ACaption <> '' then
    Caption := ACaption;

  FTitleFootFrame.Prepare(ATitle);
end;

end.