LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Pascal code (https://www.linuxquestions.org/questions/programming-9/pascal-code-97224/)

Gerardoj 09-26-2003 02:10 PM

Pascal code
 
Hi, I know a little bit of pascal but I dont know about GTK, Is there someone who can help me to explain this code?

Code:

procedure change_xpm(sbutton:pgtkwidget; smile:ppgchar);
begin;
  gtk_container_remove( pGTKCONTAINER(sbutton), pixmapwid );
  style := gtk_widget_get_style( window );
  thepixmap := gdk_pixmap_create_from_xpm_d( window^.window,  @mask,
                                        @style^.bg[GTK_STATE_NORMAL],
                                        ppgchar (smile ));
  pixmapwid := gtk_pixmap_new( thepixmap, mask );
  gtk_widget_show( pixmapwid );
  gtk_container_add( pGTKCONTAINER(sbutton), pixmapwid );
  GTK_Widget_Show(sbutton);
end;


PROCEDURE Button_Label(widget:pGtkWidget; var blabel:pGtkWidget; num:integer);
begin
  gtk_container_remove(GTK_CONTAINER(widget), blabel);
  case num of
    0:blabel:=gtk_label_new(pchar(''));
    1:blabel:=gtk_pixmap_new( xpm1, mask1 );
    2:blabel:=gtk_pixmap_new( xpm2, mask2 );
    3:blabel:=gtk_pixmap_new( xpm3, mask3 );
    4:blabel:=gtk_pixmap_new( xpm4, mask4 );
    5:blabel:=gtk_pixmap_new( xpm5, mask5 );
    6:blabel:=gtk_pixmap_new( xpm6, mask6 );
    7:blabel:=gtk_pixmap_new( xpm7, mask7 );
    8:blabel:=gtk_pixmap_new( xpm8, mask8 );
    10:blabel:=gtk_pixmap_new( xpm10, mask10 );
    11:blabel:=gtk_pixmap_new( xpm11, mask11 );
    13:blabel:=gtk_pixmap_new( xpm13, mask13 );
  end;
  gtk_container_add(GTK_CONTAINER(widget), blabel);
  gtk_widget_show(blabel);
  gtk_widget_show (widget);
end;


joesbox 09-26-2003 02:20 PM

sorry i haven't seen pascal since jr. high

darin3200 09-26-2003 04:07 PM

Quote:

Originally posted by joesbox
sorry i haven't seen pascal since jr. high
If you have nothing to contribute to a thread please don't respond, many people go though the forums first and look for posts that have not yet had any repilies.

Mara 09-26-2003 04:28 PM

Gerardoj, do you need very details or just 'how it works'?

Gerardoj 09-26-2003 05:45 PM

I prefer If is possible it Many details.

Thanks A lot.

Mara 09-27-2003 11:41 AM

Re: Pascal code
 
First note: I'm using GTK in C, but it looks for me that the functions you have in the code are exactly the same and have the same arguments as C ones.
Code:

procedure change_xpm(sbutton:pgtkwidget; smile:ppgchar);
begin;
  gtk_container_remove( pGTKCONTAINER(sbutton), pixmapwid );
 widget 'pixmapwid' is removed from container sbutton
  style := gtk_widget_get_style( window );
  thepixmap := gdk_pixmap_create_from_xpm_d( window^.window,  @mask,
                                        @style^.bg[GTK_STATE_NORMAL],
                                        ppgchar (smile ));
gdk_pixmap_create_from_xpm_ prototype (in C) is:
GdkPixmap*  gdk_pixmap_create_from_xpm_d
                                          (GdkDrawable *drawable,
                                            GdkBitmap **mask,
                                            GdkColor *transparent_color,
                                            gchar **data);
It simply creates a pixmap from data in XPM format. In this case,
the data (smile) was one of the procedure's arguments.

  pixmapwid := gtk_pixmap_new( thepixmap, mask );
  gtk_widget_show( pixmapwid );
  gtk_container_add( pGTKCONTAINER(sbutton), pixmapwid );pixmapwid (new) is added to container sbutton
  GTK_Widget_Show(sbutton); showing the button
end;
The procedure simply changes pixmap of 'sbutton' from the current one to data passed in 'smile'

PROCEDURE Button_Label(widget:pGtkWidget; var blabel:pGtkWidget; num:integer);
begin
  gtk_container_remove(GTK_CONTAINER(widget), blabel);
Removing widget from container.
  case num of
    0:blabel:=gtk_label_new(pchar(''));
    1:blabel:=gtk_pixmap_new( xpm1, mask1 );
    2:blabel:=gtk_pixmap_new( xpm2, mask2 );
    3:blabel:=gtk_pixmap_new( xpm3, mask3 );
    4:blabel:=gtk_pixmap_new( xpm4, mask4 );
    5:blabel:=gtk_pixmap_new( xpm5, mask5 );
    6:blabel:=gtk_pixmap_new( xpm6, mask6 );
    7:blabel:=gtk_pixmap_new( xpm7, mask7 );
    8:blabel:=gtk_pixmap_new( xpm8, mask8 );
    10:blabel:=gtk_pixmap_new( xpm10, mask10 );
    11:blabel:=gtk_pixmap_new( xpm11, mask11 );
    13:blabel:=gtk_pixmap_new( xpm13, mask13 );
  end;
Depending on the number 'num' passed as
third argument, the right XPM is loaded, with right mask
(you have them defined somewhere in the code, I guess.

  gtk_container_add(GTK_CONTAINER(widget), blabel);
Newly loaded data is added to the container.
  gtk_widget_show(blabel);
  gtk_widget_show (widget);
And the widgets are shown.
end;

Hope that helps. As I wrote before, you can use manual for C, so when you want to check what a certainfunction does, you can find the info in GTK/GDK manual here: http://gtk.org/api/

Gerardoj 09-28-2003 12:46 PM

Hey thanks for all the replys and your help.


All times are GMT -5. The time now is 07:41 PM.