(***********************************************************************
   This file is part of GTKpas, an OOP wrapper for GTK+ written
   for Pascal.

   Copyright (C) 2000 by Johann Glaser <Johann.Glaser@gmx.at>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program in the file COPYING; if not, write to the 
   Free Software Foundation, Inc., 
   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
***********************************************************************)
Program TableExample;
{$MODE OBJFPC}
Uses GLib,GDK,GTK,GTKpas;

Type CTableEx = Class(CWindow)
                  Function DeleteEventImpl(aEvent:PGdkEventAny):Gint; virtual; override;
                  Procedure Destroy_; virtual; override;
                  Function OnMyButtonClicked(Sender:CButton;Data:GPointer):GBoolean;
                  Function OnQuitButtonClicked(Sender:CButton;Data:GPointer):GBoolean;
                End;

Var Kit    : CMain;
    Window : CTableEx;
    Button : CButton;
    Table  : CTable;

(* Set a handler for delete_event that immediately
 * exits GTK. *)
(* This callback quits the program *)
Function CTableEx.DeleteEventImpl(aEvent:PGdkEventAny):Gint;
Begin
  inherited DeleteEventImpl(aEvent);
  DeleteEventImpl := 0;
End;
Procedure CTableEx.Destroy_;
Begin
  inherited Destroy_;
  Kit.Quit;
End;
(* Our callbacks.
 * The data passed to this function is printed to stdout *)
Function  CTableEx.OnMyButtonClicked(Sender:CButton;Data:GPointer):GBoolean;
Begin
  WriteLn('Hello again - ',PChar(Data),' was pressed');
End;
Function  CTableEx.OnQuitButtonClicked(Sender:CButton;Data:GPointer):GBoolean;
Begin
  Window.Destroy_;
End;

Const Button1Name : PGChar = 'Button 1';
      Button2Name : PGChar = 'Button 2';
      
Begin
  Kit := CMain.Create(@ArgC,@ArgV,False);

  (* Create a new window *)
  Window := CTableEx.Create(GTK_WINDOW_TOPLEVEL);

  (* Set the window title *)
  Window.Title := 'Table';

  (* Sets the border width of the window. *)
  Window.BorderWidth := 20;

  (* Create a 2x2 table *)
  Table := CTable.Create(2, 2, TRUE);

  (* Put the table in the main window *)
  Window.Add(Table);

  (* Create first button *)
  Button := CButton.Create(Button1Name);

  (* When the button is clicked, we call the 'callback' function
   * with a pointer to 'button 1' as its argument *)
  Button.OnClicked := @Window.OnMyButtonClicked;
  Button.OnClickedData := Button1Name;

  (* Insert button 1 into the upper left quadrant of the table *)
  Table.AttachDefaults(Button, 0, 1, 0, 1);

  Button.Show;

  (* Create second button *)
  Button := CButton.Create(Button2Name);

  (* When the button is clicked, we call the 'callback' function
   * with a pointer to 'button 2' as its argument *)
  Button.OnClicked := @Window.OnMyButtonClicked;
  Button.OnClickedData := Button2Name;
            
  (* Insert button 2 into the upper right quadrant of the table *)
  Table.AttachDefaults(Button, 1, 2, 0, 1);

  Button.Show;

  (* Create 'Quit' button *)
  Button := CButton.Create('Quit');
  (* When the button is clicked, we call the 'OnQuitButtonClicked' function
   * and the program exits *)
  Button.OnClicked := @Window.OnQuitButtonClicked;

  (* Insert the quit button into the both 
   * lower quadrants of the table *)
  Table.AttachDefaults(Button, 0, 2, 1, 2);

  Button.Show;
  Table.Show;
  Window.Show;

  Kit.Run;
End.
