summaryrefslogtreecommitdiff
path: root/examples/gui/fontselect/fontselect.lpr
blob: 06b3486b2c1b0e1bb33efc106622adc0f48bff4b (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
program fontselect;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,
  fpg_main,
  fpg_form,
  fpg_dialogs,
  fpg_button,
  fpg_listbox,
  fpg_edit,
  fpg_label,
  fpg_constants;
  
  
resourcestring
  rsMyTitle = 'Font selection test';
  rsMyFontList = 'Font List';


type
  TMainForm = class(TfpgForm)
  private
    btnQuit: TfpgButton;
    btnSelectFont: TfpgButton;
    lbFontList: TfpgListBox;
    edFontDesc: TfpgEdit;
    lblFontList: TfpgLabel;
    procedure   btnQuitClick(Sender: TObject);
    procedure   btnSelectFontClick(Sender: TObject);
    procedure   CreateFontList;
  public
    constructor Create(AOwner: TComponent); override;
  end;


{ TMainForm }

procedure TMainForm.btnQuitClick(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.btnSelectFontClick(Sender: TObject);
var
  fontdesc: string;
begin
  fontdesc := edFontDesc.Text;
  if SelectFontDialog(fontdesc) then
    edFontDesc.Text := fontdesc;
end;

procedure TMainForm.CreateFontList;
var
  fl: TStringList;
  i: integer;
begin
  lbFontList.Items.Clear;
  fl := fpgApplication.GetFontFaceList;
  for i := 0 to fl.Count-1 do
    lbFontList.Items.Add(fl.Strings[i]);
  fl.Free;
end;

constructor TMainForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  WindowTitle := rsMyTitle;
  SetPosition(100, 100, 500, 400);
  
  btnSelectFont := CreateButton(self, 10, 10, 110, rsSelectAFont, @btnSelectFontClick);

  edFontDesc := CreateEdit(self, 10, 45, Width - 20, 24);
  edFontDesc.Text := 'Bitstream Vera Sans-9';

  lblFontList := CreateLabel(self, 10, 80, rsMyFontList + ':');
  lbFontList := TfpgListBox.Create(self);
  with lbFontList do
  begin
    Name := 'lbFontList';
    SetPosition(10, 100, 232, 236);
    Items.Clear;
  end;

  CreateFontList;

  btnQuit := CreateButton(self, 415, 370, 80, rsExit, @btnQuitClick);
  btnQuit.ImageName := 'stdimg.Quit';
  btnQuit.ShowImage := True;
  btnQuit.Anchors := [anRight, anBottom];

  btnSelectFont.TabOrder := 1;
  edFontDesc.TabOrder := 2;
  lbFontList.TabOrder := 3;
  btnQuit.TabOrder := 4;
end;

procedure MainProc;
var
  frm: TMainForm;
begin
  fpgApplication.Initialize;
  frm := TMainForm.Create(nil);
  frm.Show;
  fpgApplication.Run;
  frm.Free;
end;

begin
  MainProc;
end.