(***********************************************************************
   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 PixmapExample;
{$MODE OBJFPC}
Uses GLib,GDK,GTK,GTKpas;

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

(* XPM data of Open-File icon *)
Const XPMData : Array[0..19] of PChar =
                  ('16 16 3 1',
                   '       c None',
                   '.      c #000000000000',
                   'X      c #FFFFFFFFFFFF',
                   '                ',
                   '   ......       ',
                   '   .XXX.X.      ',
                   '   .XXX.XX.     ',
                   '   .XXX.XXX.    ',
                   '   .XXX.....    ',
                   '   .XXXXXXX.    ',
                   '   .XXXXXXX.    ',
                   '   .XXXXXXX.    ',
                   '   .XXXXXXX.    ',
                   '   .XXXXXXX.    ',
                   '   .XXXXXXX.    ',
                   '   .XXXXXXX.    ',
                   '   .........    ',
                   '                ',
                   '                ');


Var Kit       : CMain;

Function CPixmapWin.DeleteEventImpl(aEvent:PGdkEventAny):Gint;
Begin
  inherited DeleteEventImpl(aEvent);
  DeleteEventImpl := 0;
End;
Procedure CPixmapWin.Destroy_;
Begin
  inherited Destroy_;
  Kit.Quit;
End;
Function CPixmapWin.OnButtonClicked(Sender:CButton;Data:GPointer):GBoolean;
Begin
  WriteLn('button clicked');
  OnButtonClicked := False;
End;

Var Window    : CPixmapWin;
    Style     : PGtkStyle;
    Mask      : PGdkBitmap;
    Pixmap    : PGdkPixmap;
    Button    : CButton;
    PixmapWid : CWidget;

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

  (* create the main window, and attach delete_event signal to terminating
     the application (which is done during Create) *)
  Window := CPixmapWin.Create(GTK_WINDOW_TOPLEVEL);
  Window.BorderWidth := 10;
  Window.Show;
  Window.Title := 'radio buttons';

  (* now for the pixmap from gdk *)
  Style := Window.Style;
  Pixmap := gdk_pixmap_create_from_xpm_d(PGtkWidget(Window.GtkObject)^.Window, @Mask,
                                         @Style^.BG[GTK_STATE_NORMAL],
                                         PPGChar(XPMData));

  (* a pixmap widget to contain the pixmap *)
  PixmapWid := CPixmap.Create(Pixmap,Mask);
  PixmapWid.Show;

  (* a button to contain the pixmap widget *)
  Button := CButton.Create;
  Button.Add(PixmapWid);
  Window.Add(Button);
  Button.Show;
  Button.OnClicked := @Window.OnButtonClicked;

  (* show the window *)
  Window.Show;

  Kit.Run;
End.

