summaryrefslogtreecommitdiff
path: root/examples/gui/tabtest/tabtest.lpr
blob: 3675e29a32b18c643ce00ef80284e19262608ebb (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
program tabtest;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils,
  fpg_main, fpg_base, fpg_widget, fpg_form, fpg_tab, fpg_button,
  fpg_label, fpg_edit, fpg_checkbox, fpg_combobox;

type
  TMainForm = class(TfpgForm)
  private
    btnQuit: TfpgButton;
    pcMain: TfpgPageControl;
    tsOne: TfpgTabSheet;
    tsTwo: TfpgTabSheet;
    tsThree: TfpgTabSheet;
    tsFour: TfpgTabSheet;
    btn2, btn3: TfpgButton;
    chkSort: TfpgCheckBox;
    cbTabPos: TfpgComboBox;
    edtHeight: TfpgEditInteger;
    lbl: TfpgLabel;
    procedure   TabSheet4Painting(Sender: TObject);
    procedure   edtHeightChanged(Sender: TObject);
    procedure   btnQuitClick(Sender: TObject);
    procedure   btn2Click(Sender: TObject);
    procedure   btn3Click(Sender: TObject);
    procedure   chkSortChange(Sender: TObject);
    procedure   cbTabPosChanged(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
  end;

{ TMainForm }

procedure TMainForm.TabSheet4Painting(Sender: TObject);
begin
  lbl.Text := 'H: ' + IntToStr(tsFour.Height);
end;

procedure TMainForm.edtHeightChanged(Sender: TObject);
begin
  pcMain.FixedTabHeight := edtHeight.Value;
end;

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

procedure TMainForm.btn2Click(Sender: TObject);
begin
  pcMain.ActivePageIndex := 0;
end;

procedure TMainForm.btn3Click(Sender: TObject);
var
  i: integer;
begin
  i := tsFour.PageIndex + 1;
  if i > pcMain.PageCount-1 then  // we reached the end so start from front
    i := 0;
    
  tsFour.PageIndex := i;
end;

procedure TMainForm.chkSortChange(Sender: TObject);
begin
  pcMain.SortPages := chkSort.Checked;
  btn3.Enabled := not chkSort.Checked;
end;

procedure TMainForm.cbTabPosChanged(Sender: TObject);
begin
  if cbTabPos.FocusItem = 0 then
    pcMain.TabPosition := tpTop
  else if cbTabPos.FocusItem = 1 then
    pcMain.TabPosition := tpBottom
  else if cbTabPos.FocusItem = 2 then
    pcMain.TabPosition := tpLeft
  else if cbTabPos.FocusItem = 3 then
    pcMain.TabPosition := tpRight
  else
    pcMain.TabPosition := tpNone;
end;

constructor TMainForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  WindowTitle := 'Tab control test';
  SetPosition(100, 100, 566, 350);
  ShowHint := True;
  
  btnQuit := CreateButton(self, 476, 320, 80, 'Quit', @btnQuitClick);
  btnQuit.ImageName := 'stdimg.Quit';
  btnQuit.ShowImage := True;
  btnQuit.Anchors := [anRight, anBottom];

  pcMain := TfpgPageControl.Create(self);
  pcMain.Top      := 10;
  pcMain.Left     := 10;
  pcMain.Width    := Width - 20;
  pcMain.Height   := 300;
  pcMain.Anchors  := [anLeft, anTop, anRight, anBottom];
//  pcMain.FixedTabWidth:=150;

  // Tab One
  tsOne := TfpgTabSheet.Create(pcMain);
  tsOne.Text := 'Tab One';
  CreateLabel(tsOne, 15, 50, 'TabSheet One');
  CreateLabel(tsOne, 15, 30, 'Resize form to see PageControl left/right buttons in action.');
  CreateEdit(tsOne, 15, 100, 150, 25);

  // Tab Two
  tsTwo := TfpgTabSheet.Create(pcMain);
  tsTwo.Text := 'Tab Two';
  CreateLabel(tsTwo, 50, 50, 'TabSheet Two');
  CreateButton(tsTwo, 50, 100, 80, 'Button1', nil);

  // Tab Three
  tsThree := TfpgTabSheet.Create(pcMain);
  tsThree.Text := 'Tab Three';
  CreateLabel(tsThree, 80, 50, 'TabSheet Three');
  
  // Tab Four
  tsFour := TfpgTabSheet.Create(pcMain);
  tsFour.Text := 'This is one long text caption';
  tsFour.BackgroundColor := clMediumSeaGreen;
  tsFour.OnPaint := @TabSheet4Painting;
  lbl := CreateLabel(tsFour, 30, 50, 'TabSheet Four');

  pcMain.ActivePage := tsOne;

  btn2 := CreateButton(self, 10, 320, 80, 'Page 1', @btn2Click);
  btn2.Anchors := [anLeft, anBottom];

  btn3 := CreateButton(self, 100, 320, 80, 'Reorder Tab', @btn3Click);
  btn3.Anchors := [anLeft, anBottom];
  
  chkSort := CreateCheckBox(self, 190, 320, 'Sort Tabs');
  chkSort.Anchors := [anBottom, anLeft];
  chkSort.OnChange := @chkSortChange;
  
  cbTabPos := CreateComboBox(self, 300, 320, 80, nil);
  cbTabPos.Items.Add('tpTop');
  cbTabPos.Items.Add('tpBottom');
  cbTabPos.Items.Add('tpLeft');
  cbTabPos.Items.Add('tpRight');
  cbTabPos.Items.Add('tpNone');
  cbTabPos.FocusItem := 0;
  cbTabPos.Anchors := [anBottom, anLeft];
  cbTabPos.Hint := 'Tab position';
  cbTabPos.OnChange := @cbTabPosChanged;

  CreateLabel(self, 390, 325, 'Height:');
  edtHeight := CreateEditInteger(self, 435, 320, 30, 24, False);
  edtHeight.Value := 0;
  edtHeight.Hint := 'Tab height';
  edtHeight.OnChange := @edtHeightChanged;
end;

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

begin
  MainProc;
end.