/examples/toolbar.pp

http://github.com/graemeg/lazarus · Puppet · 156 lines · 132 code · 24 blank · 0 comment · 1 complexity · c5a1755b984878f7d2cf25ff2ef1adc6 MD5 · raw file

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