(***********************************************************************
   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.
***********************************************************************)
(* example-start entry entry.pas *)
Program EntryExample;
{$MODE OBJFPC}
Uses GLib,GDK,GTK,GTKpas;

Type CEntryWin = Class(CWindow)
                Function  DeleteEventImpl(aEvent:PGdkEventAny):Gint; virtual; override;
                Procedure Destroy_; virtual; override;
                Function  OnQuitButtonClicked(Sender:CButton;Data:GPointer):GBoolean;
                Function  OnEnterCallback(Sender:CEntry;Data:GPointer):GBoolean;
                Function  OnEntryToggleEditable(Sender:CToggleButton;Data:GPointer):GBoolean;
                Function  OnEntryToggleVisible(Sender:CToggleButton;Data:GPointer):GBoolean;
              End;

Var Kit       : CMain;

Function  CEntryWin.DeleteEventImpl(aEvent:PGdkEventAny):Gint;
Begin
  inherited DeleteEventImpl(aEvent);
  DeleteEventImpl := 0;
End;
Procedure CEntryWin.Destroy_;
Begin
  inherited Destroy_;
  Kit.Quit;
End;
Function  CEntryWin.OnQuitButtonClicked(Sender:CButton;Data:GPointer):GBoolean;
Begin
  Destroy_;
  OnQuitButtonClicked := True;
End;

Function  CEntryWin.OnEnterCallback(Sender:CEntry;Data:GPointer):GBoolean;
Var EntryText : PGChar;
Begin
  EntryText := CEntry(Data).Text;
  WriteLn('Entry contents: ',EntryText);
  OnEnterCallback := True;
End;

Function  CEntryWin.OnEntryToggleEditable(Sender:CToggleButton;Data:GPointer):GBoolean;
Begin
  CEntry(Data).Editable := Sender.Active;
  OnEntryToggleEditable := True;
End;

Function  CEntryWin.OnEntryToggleVisible(Sender:CToggleButton;Data:GPointer):GBoolean;
Begin
  CEntry(Data).Visibility := Sender.Active;
  OnEntryToggleVisible := True;
End;

Var Window : CEntryWin;
    VBox   : CVBox;
    Entry  : CEntry;
    HBox   : CHBox;
    Check  : CCheckButton;
    Button : CButton;
    
Begin
  Kit := CMain.Create(@ArgC,@ArgV,False);

  (* create a new window *)
  Window := CEntryWin.Create(GTK_WINDOW_TOPLEVEL);
  Window.SetUSize(200,100);
  Window.Title := 'GTK Entry';

  VBox := CVBox.Create(FALSE, 0);
  Window.Add(VBox);
  VBox.Show;

  Entry := CEntry.Create(GUInt16(50));
  Entry.OnActivate := @Window.OnEnterCallback;
  Entry.OnActivateData := Entry;
  Entry.Text := 'hello';
  Entry.AppendText(' world');
  Entry.SelectRegion(0, PGtkEntry(Entry.GtkObject)^.Text_Length);
  VBox.PackStart(Entry, TRUE, TRUE, 0);
  Entry.Show;

  HBox := CHBox.Create(FALSE, 0);
  VBox.Add(HBox);  { ??? !!! }
  HBox.Show;
                                
  Check := CCheckButton.Create('Editable');
  HBox.PackStart(Check, TRUE, TRUE, 0);
  Check.OnToggled := @Window.OnEntryToggleEditable;
  Check.OnToggledData := Entry;
  Check.Active := True;
  Check.Show;
  
  Check := CCheckButton.Create('Visible');
  HBox.PackStart(Check, TRUE, TRUE, 0);
  Check.OnToggled := @Window.OnEntryToggleVisible;
  Check.OnToggledData := Entry;
  Check.Active := True;
  Check.Show;

  Button := CButton.Create('Close');
  Button.OnClicked := @Window.OnQuitButtonClicked;
  VBox.PackStart(Button,True,True,0);
  GTK_WIDGET_SET_FLAGS(PGtkWidget(Button.GtkObject),GTK_CAN_DEFAULT);
  Button.GrabDefault;
  Button.Show;

  Window.Show;

  Kit.Run;
End.

