LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-26-2003, 02:10 PM   #1
Gerardoj
Member
 
Registered: May 2003
Location: Somewhere over the Rainbow
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465

Rep: Reputation: 30
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;

Last edited by Gerardoj; 09-26-2003 at 10:45 PM.
 
Old 09-26-2003, 02:20 PM   #2
joesbox
Member
 
Registered: Feb 2003
Location: hampton va
Distribution: ubuntu
Posts: 502

Rep: Reputation: 30
sorry i haven't seen pascal since jr. high
 
Old 09-26-2003, 04:07 PM   #3
darin3200
LQ Guru
 
Registered: Dec 2002
Distribution: Gentoo!
Posts: 1,153

Rep: Reputation: 45
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.
 
Old 09-26-2003, 04:28 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Gerardoj, do you need very details or just 'how it works'?
 
Old 09-26-2003, 05:45 PM   #5
Gerardoj
Member
 
Registered: May 2003
Location: Somewhere over the Rainbow
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465

Original Poster
Rep: Reputation: 30
I prefer If is possible it Many details.

Thanks A lot.

Last edited by Gerardoj; 09-26-2003 at 05:49 PM.
 
Old 09-27-2003, 11:41 AM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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/

Last edited by Mara; 09-27-2003 at 11:54 AM.
 
Old 09-28-2003, 12:46 PM   #7
Gerardoj
Member
 
Registered: May 2003
Location: Somewhere over the Rainbow
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465

Original Poster
Rep: Reputation: 30
Hey thanks for all the replys and your help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can someone help me with Pascal? randyriver10 Programming 2 09-29-2005 04:09 PM
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM
Pascal Code Explanation Gerardoj Programming 1 09-25-2003 01:15 AM
Pascal for Linux HELP ! linuxlover1 Linux - Software 1 06-22-2003 03:31 PM
GUI pascal nivek Programming 1 03-11-2003 08:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration