~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to packages/gtk/examples/tutorial/tut6_1.pp

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2004-08-12 16:29:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040812162937-moo8ulvysp1ln771
Tags: 1.9.4-5
fp-compiler: needs ld, adding dependency on binutils.  (Closes: #265265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{
2
 
  $Id: tut6_1.pp,v 1.1 2000/07/13 06:34:01 michael Exp $
3
 
 
4
 
  This file extracted from the GTK 1.2 tutorial.
5
 
  Section 6.1
6
 
 
7
 
  Converted from C to Pascal by Thomas E. Payne
8
 
}
9
 
 program Tut6_1;
10
 
 
11
 
{$mode objfpc}
12
 
 
13
 
 uses
14
 
  glib,gdk,gtk,sysutils;
15
 
 
16
 
  //* Create a new hbox with an image and a label packed into it
17
 
  //* and return the box. */
18
 
   function xpm_label_box( parent: pGtkWidget;
19
 
                           xpm_filename : pchar;
20
 
                           label_text : pchar ): pGtkWidget; cdecl;
21
 
   var
22
 
 
23
 
     box1, label_,pixmapwid : pGtkWidget;
24
 
     pixmap :   pGdkPixmap;
25
 
     mask   : pGdkBitmap;
26
 
     style  : pGtkStyle;
27
 
   begin
28
 
     //* Create box for xpm and label */
29
 
     box1 := gtk_hbox_new (FALSE, 0);
30
 
     gtk_container_set_border_width (GTK_CONTAINER (box1), 2);
31
 
     //* Get the style of the button to get the background color. */
32
 
     style := gtk_widget_get_style(parent);
33
 
     //* Now on to the xpm stuff */
34
 
     //function  gdk_pixmap_create_from_xpm(window:PGdkWindow;
35
 
     //mask:PPGdkBitmap;
36
 
     // transparent_color:PGdkColor; filename:Pgchar):PGdkPixmap;
37
 
 
38
 
     pixmap := gdk_pixmap_create_from_xpm (parent^.window, @mask,
39
 
                                          @style^.bg[GTK_STATE_NORMAL],
40
 
                                          xpm_filename);
41
 
     pixmapwid := gtk_pixmap_new (pixmap, mask);
42
 
     //* Create a label for the button */
43
 
     label_ := gtk_label_new (label_text);
44
 
     //* Pack the pixmap and label into the box */
45
 
     gtk_box_pack_start (GTK_BOX (box1),
46
 
                         pixmapwid, FALSE, FALSE, 3);
47
 
     gtk_box_pack_start (GTK_BOX (box1), label_, FALSE, FALSE, 3);
48
 
     gtk_widget_show(pixmapwid);
49
 
     gtk_widget_show(label_);
50
 
     xpm_label_box := box1;
51
 
   end;
52
 
 
53
 
   //* Our usual callback function */
54
 
 procedure callback( widget : pGtkWidget; data : pgpointer   );cdecl;
55
 
   begin
56
 
     writeln ('Hello again - '+pchar(data)+' was pressed');
57
 
   end;
58
 
 
59
 
  var
60
 
    //* GtkWidget is the storage type for widgets */
61
 
    window,button,box1 : pGtkWidget;
62
 
  begin
63
 
     gtk_init (@argc, @argv);
64
 
     //* Create a new window */
65
 
     window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
66
 
     gtk_window_set_title (GTK_WINDOW (window), 'Pixmap''d Buttons!');
67
 
     //* It's a good idea to do this for all windows. */
68
 
     gtk_signal_connect (GTK_OBJECT (window), 'destroy',
69
 
                         GTK_SIGNAL_FUNC (@gtk_exit), Nil);
70
 
     gtk_signal_connect (GTK_OBJECT (window), 'delete_event',
71
 
                         GTK_SIGNAL_FUNC (@gtk_exit), Nil);
72
 
     //* Sets the border width of the window. */
73
 
     gtk_container_set_border_width (GTK_CONTAINER (window), 10);
74
 
     gtk_widget_realize(window);
75
 
     //* Create a new button */
76
 
     button := gtk_button_new ();
77
 
     //* Connect the "clicked" signal of the button to our callback */
78
 
     gtk_signal_connect (GTK_OBJECT (button), 'clicked',
79
 
                         GTK_SIGNAL_FUNC (@callback), pchar('cool button'));
80
 
     //* This calls our box creating function */
81
 
     box1 := xpm_label_box(window, 'info.xpm', 'cool button');
82
 
     //* Pack and show all our widgets */
83
 
     gtk_widget_show(box1);
84
 
     gtk_container_add (GTK_CONTAINER (button), box1);
85
 
     gtk_widget_show(button);
86
 
     gtk_container_add (GTK_CONTAINER (window), button);
87
 
     gtk_widget_show (window);
88
 
     //* Rest in gtk_main and wait for the fun to begin! */
89
 
     gtk_main ();
90
 
 end.
 
 
b'\\ No newline at end of file'