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

Type CStatusBarWin = Class(CWindow)
                StatusBar : CStatusBar;
                Function DeleteEventImpl(aEvent:PGdkEventAny):Gint; virtual; override;
                Procedure Destroy_; virtual; override;
                Function OnPushItem(Sender:CButton;Data:GPointer):GBoolean;
                Function OnPopItem(Sender:CButton;Data:GPointer):GBoolean;
              End;

Const Count : Integer = 1;

Var Kit : CMain;

Function CStatusBarWin.DeleteEventImpl(aEvent:PGdkEventAny):Gint;
Begin
  inherited DeleteEventImpl(aEvent);
  DeleteEventImpl := 0;
End;
Procedure CStatusBarWin.Destroy_;
Begin
  inherited Destroy_;
  Kit.Quit;
End;
Function CStatusBarWin.OnPushItem(Sender:CButton;Data:GPointer):GBoolean;
Var Buff : Array[0..19] of Char;
Begin
  g_vsnprintf(Buff, 20, 'Item %d', [@Count]);
  Inc(Count);
  StatusBar.Push(GUInt(Data), @Buff);
  OnPushItem := False;
End;
Function CStatusBarWin.OnPopItem(Sender:CButton;Data:GPointer):GBoolean;
Begin
  StatusBar.Pop(GUInt(Data));
  OnPopItem := False;
End;

Var Window    : CStatusBarWin;
    Button    : CButton;
    VBox      : CBox;
    ContextID : GInt;

Begin
  Kit := CMain.Create(@ArgC,@ArgV,False);

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

  VBox := CVBox.Create(False,1);
  Window.Add(VBox);
  VBox.Show;

  Window.StatusBar := CStatusbar.Create;
  VBox.PackStart(Window.StatusBar, TRUE, TRUE, 0);
  Window.StatusBar.Show;

  ContextID := Window.StatusBar.GetContextID('Statusbar example');

  Button := CButton.Create('push item');
  Button.OnClicked := @CStatusBarWin(Window).OnPushItem;
  Button.OnClickedData := GPointer(ContextID);
  VBox.PackStart(Button,True,True,2);
  Button.Show;

  Button := CButton.Create('pop last item');
  Button.OnClicked := @CStatusBarWin(Window).OnPopItem;
  Button.OnClickedData := GPointer(ContextID);
  VBox.PackStart(Button,True,True,2);
  Button.Show;

  (* always display the window as the last step so it all splashes on
   * the screen at once. *)
  Window.Show;

  Kit.Run;
End.

