PageRenderTime 34ms CodeModel.GetById 16ms app.highlight 15ms RepoModel.GetById 2ms app.codeStats 0ms

/examples/toolbar.pp

http://github.com/graemeg/lazarus
Pascal | 156 lines | 104 code | 19 blank | 33 comment | 0 complexity | c5a1755b984878f7d2cf25ff2ef1adc6 MD5 | raw file
  1 {
  2 /***************************************************************************
  3                          toolbar - example
  4                          ------------------
  5
  6
  7                   Initial Revision  : Wed Dec 29 1999
  8
  9                   by Shane Miller
 10
 11 ***************************************************************************/
 12
 13 ***************************************************************************
 14 *                                                                         *
 15 *   This source is free software; you can redistribute it and/or modify   *
 16 *   it under the terms of the GNU General Public License as published by  *
 17 *   the Free Software Foundation; either version 2 of the License, or     *
 18 *   (at your option) any later version.                                   *
 19 *                                                                         *
 20 *   This code is distributed in the hope that it will be useful, but      *
 21 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 22 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 23 *   General Public License for more details.                              *
 24 *                                                                         *
 25 *   A copy of the GNU General Public License is available on the World    *
 26 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 27 *   obtain it by writing to the Free Software Foundation,                 *
 28 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 29 *                                                                         *
 30 ***************************************************************************
 31}
 32program Toolbar;
 33
 34{$mode objfpc}{$H+}
 35
 36uses
 37  Interfaces, Classes, StdCtrls, Forms, Buttons, Menus, ComCtrls,
 38  SysUtils, ExtCtrls, Controls, LazLogger;
 39
 40type
 41        TForm1 = class(TFORM)
 42        public
 43          Toolbar1 : TToolbar;
 44          Toolbutton1 : TToolbutton;
 45          Toolbutton2 : TToolbutton;
 46          Toolbutton3 : TToolbutton;
 47          ComboBox1 : TComboBox;
 48          constructor Create(AOwner: TComponent); override;
 49        protected
 50        Procedure Button1Click(Sender : TObject);
 51        Procedure Button2Click(Sender : TObject);
 52        Procedure Button3Click(Sender : TObject);
 53        end;
 54
 55var
 56Form1 : TForm1;
 57
 58constructor TForm1.Create(AOwner: TComponent);
 59begin
 60   inherited CreateNew(AOwner, 1);
 61   Name:='Form1';
 62   Caption := 'Toolbar Demo v0.1';
 63   {  set the height and width }
 64   Height := 350;
 65   Width := 700;
 66
 67ToolBar1 := TToolbar.Create(Self);
 68  with Toolbar1 do
 69  begin
 70    Name:='ToolBar1';
 71    Parent := Self;
 72  end;
 73
 74Toolbutton1 := TToolButton.Create(Toolbar1);
 75with ToolButton1 do
 76  Begin
 77    Name:='Toolbutton1';
 78    Parent := Toolbar1;
 79    Caption := '1';
 80    Style := tbsButton;
 81    OnClick := @Button1Click;
 82    Show;
 83  end;
 84Toolbutton2 := TToolButton.Create(Toolbar1);
 85with ToolButton2 do
 86  Begin
 87    Name:='Toolbutton2';
 88    Parent := Toolbar1;
 89    Caption := '2';
 90    Style := tbsButton;
 91    OnClick := @Button2Click;
 92    Show;
 93  end;
 94Toolbutton3 := TToolButton.Create(Toolbar1);
 95with ToolButton3 do
 96  Begin
 97    Parent := Toolbar1;
 98    Caption := '3';
 99    Style := tbsButton;
100    OnClick := @Button3Click;
101    Show;
102  end;
103
104
105ComboBox1 := TComboBox.Create(Self);
106with ComboBox1 do
107  Begin
108    Parent := Toolbar1;
109    Items.Add('Item1');
110    Items.Add('Item2');
111    Items.Add('Item3');
112    Items.Add('Item4');
113    Items.Add('Item5');
114    Items.Add('Item6');
115    ItemIndex := 0;
116    Show;
117  end;
118
119Toolbar1.ShowCaptions := True;
120Toolbar1.Height := 25;
121Toolbar1.Top := 1;
122Toolbar1.Width := ClientWidth;
123Toolbar1.Show;
124
125
126end;
127
128Procedure TFORM1.Button1Click(Sender : TObject);
129Begin
130  debugln('******************');
131  debugln('Toolbar button  1  clicked!');
132  debugln('******************');
133end;
134
135Procedure TFORM1.Button2Click(Sender : TObject);
136Begin
137  debugln('******************');
138  debugln('Toolbar button  2  clicked!');
139  debugln('******************');
140end;
141
142Procedure TFORM1.Button3Click(Sender : TObject);
143Begin
144  DebugLn('******************');
145  debugln('Toolbar button  3  clicked!');
146  debugln('******************');
147end;
148
149
150
151begin
152   Application.Initialize; { calls InitProcedure which starts up GTK }
153   Application.CreateForm(TForm1, Form1);
154   Application.Run;
155end.
156