Page 1 of 3

Hello Linux!!!

Posted: Tue May 11, 2010 2:13 am
by Roberto Lopez
Hi All,

For those finding interesting the experimentation, here are some tips:

1. Install Ubuntu 10.04.

2. Download and install Harbour compiler for Ubuntu: http://sourceforge.net/projects/harbour ... b/download

3. Install Development files for the GTK+ library. You can do it with Synaptic Package Manager (libgtk2.0-dev).

4. Create a file called test.prg (with the code below) and build it with hbmk test `pkg-config --cflags --libs gtk+-2.0` command . Run it with ./test

test.prg:

Code: Select all

function main()

	PUBLIC bButtonAction := { || GTK_MSGINFO('Click!!!') }

	GTK_INIT()

	aRet := GTK_DEFINEWINDOW( 100 , 100 , 400 , 200 , "hello Linux!!!!" )

	GTK_DEFINEBUTTON ( aRet [2] , 50 , 50 , 'Click Me!!' )

	GTK_ACTIVATEWINDOW()

return nil

*----------------------------------------------------------------------------------------------*
PROCEDURE HMG_BUTTON_CALLBACK ( HANDLE )
*----------------------------------------------------------------------------------------------*
	EVAL ( bButtonAction )
RETURN
*----------------------------------------------------------------------------------------------*
#pragma BEGINDUMP
#include <gtk/gtk.h>
// BUTTON ONCLICK EVENT HANDLER ////////////////////////////////////
static long button_clicked ( GtkWidget *handle )
{
	static PHB_DYNS Dyns = 0 ;
	long int r;
	if( ! Dyns )
	{
		Dyns = hb_dynsymFindName( "HMG_BUTTON_CALLBACK" );
	}
	hb_vmPushSymbol( hb_dynsymSymbol( Dyns ) );
	hb_vmPushNil();
	hb_vmPushLong( (long) handle );
	hb_vmPushLong( 0 );
	hb_vmPushLong( 0 );
	hb_vmPushLong( 0 );
	hb_vmDo( 4 );

	r = hb_parnl( -1 );

	return r;
}
static gboolean delete_event( GtkWidget *widget,GdkEvent  *event, gpointer   data )
{
    g_print ("delete event occurred\n");
    return FALSE;
}
static void destroy( GtkWidget *widget, gpointer   data )
{
    gtk_main_quit ();
}
//--------------------------------------------------------------------------------------------//
HB_FUNC ( GTK_INIT )
//--------------------------------------------------------------------------------------------//
{
    gtk_init ( 0 , 0 );
}
//--------------------------------------------------------------------------------------------//
HB_FUNC ( GTK_DEFINEWINDOW )
//--------------------------------------------------------------------------------------------//
{
	GtkWidget *window;
	GtkWidget *fixed;
	char* cTitle = (gchar*) hb_parc(5);
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect (window, "delete-event",G_CALLBACK (delete_event), NULL);
	g_signal_connect (window, "destroy",G_CALLBACK (destroy), NULL);
	gtk_window_move( GTK_WINDOW(window) , hb_parni(2), hb_parni(1) );
	gtk_widget_set_size_request( GTK_WIDGET(window) , hb_parni(3) , hb_parni(4) );
	gtk_window_set_title( GTK_WINDOW(window) , cTitle );
	/* Create a Fixed Container */
	fixed = gtk_fixed_new ();
	gtk_container_add (GTK_CONTAINER (window), fixed);
	gtk_widget_show (fixed);
	gtk_widget_show  (window);
	hb_reta(2);
	hb_storvnl( window , -1 , 1 );
	hb_storvnl( fixed , -1 , 2 );
}
//--------------------------------------------------------------------------------------------//
HB_FUNC ( GTK_DEFINEBUTTON )
//--------------------------------------------------------------------------------------------//
{
	GtkWidget *button;
	button = gtk_button_new_with_label ( (gchar*) hb_parc(4));
	gtk_fixed_put (GTK_FIXED ((long) hb_parnl(1)), button, hb_parni(2), hb_parni(3) );
	gtk_widget_show (button);
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (button_clicked), (gpointer) button );
}
//--------------------------------------------------------------------------------------------//
HB_FUNC ( GTK_ACTIVATEWINDOW )
//--------------------------------------------------------------------------------------------//
{
	gtk_main ();
}
//--------------------------------------------------------------------------------------------//
HB_FUNC ( GTK_MSGINFO )
//--------------------------------------------------------------------------------------------//
{
GtkWidget *dialog;
	dialog = gtk_message_dialog_new ( 0 ,
                                  GTK_DIALOG_MODAL,
                                  GTK_MESSAGE_INFO,
                                  GTK_BUTTONS_OK,
                                  (gchar*) hb_parc (1) ,"Hi1" );

	gtk_dialog_run (GTK_DIALOG (dialog));
	gtk_widget_destroy (dialog);
}
#pragma ENDDUMP 
Enjoy!

Re: Hello Linux!!!

Posted: Tue May 11, 2010 3:06 am
by Rathinagiri
Aha! Super!

Re: Hello Linux!!!

Posted: Tue May 11, 2010 6:49 pm
by Roberto Lopez
rathinagiri wrote:Aha! Super!
GTK is amazing.

As I've already pointed sometimes, it is the foundation used by GNOME (the Ubuntu default desktop).

GTK is compact, simple and fast. It is extremely easy compared with Windows API.

So, for those wanting GUI support on Linux, it appeared a good idea to show how much easily, the things can be done.

Re: Hello Linux!!!

Posted: Tue May 11, 2010 8:04 pm
by jparada
Hi,

This is my first test and this is the result, please take a look.
javier@javier:~/testhmg$ hbmk test `pkg-config --cflags --libs gtk+-2.0`
Harbour 2.1.0beta1 (Rev. 14450)
Copyright (c) 1999-2010, http://www.harbour-project.org/
Compiling 'test.prg' and generating preprocessed output to 'thread'...
Lines 111, Functions/Procedures 2
Generating C source output to 'test.c'... Done.
test.prg: In function ‘button_clicked’:
test.prg:30: warning: assignment makes pointer from integer without a cast
test.prg: In function ‘HB_FUN_GTK_MSGINFO’:
test.prg:109: error: expected declaration or statement at end of input
javier@javier:~/testhmg$
Any help is welcome.

Thanks

PS: Under VM Ubuntu 10.4

Best Regards
Javier

Re: Hello Linux!!!

Posted: Tue May 11, 2010 9:46 pm
by Roberto Lopez
jparada wrote:Hi,

This is my first test and this is the result, please take a look.
javier@javier:~/testhmg$ hbmk test `pkg-config --cflags --libs gtk+-2.0`
Harbour 2.1.0beta1 (Rev. 14450)
Copyright (c) 1999-2010, http://www.harbour-project.org/
Compiling 'test.prg' and generating preprocessed output to 'thread'...
Lines 111, Functions/Procedures 2
Generating C source output to 'test.c'... Done.
test.prg: In function ‘button_clicked’:
test.prg:30: warning: assignment makes pointer from integer without a cast
test.prg: In function ‘HB_FUN_GTK_MSGINFO’:
test.prg:109: error: expected declaration or statement at end of input
javier@javier:~/testhmg$
Any help is welcome.

Thanks

PS: Under VM Ubuntu 10.4

Best Regards
Javier
At copypasting I've missed a right bracket before #pragma ENDDUMP.

Please add it and it should work.

Re: Hello Linux!!!

Posted: Wed May 12, 2010 2:30 am
by sudip
Great News! Roberto, thank you very much :)
Regards.
Sudip

Re: Hello Linux!!!

Posted: Wed May 12, 2010 3:51 am
by jparada
Hi,

Thanks a lot Roberto, now works fine

I attached picture, please take a look

Thanks

Best Regards
Javier

Re: Hello Linux!!!

Posted: Wed May 12, 2010 4:06 am
by Roberto Lopez
jparada wrote:Hi,

Thanks a lot Roberto, now works fine

I attached picture, please take a look

Thanks

Best Regards
Javier
Congratulations!

Re: Hello Linux!!!

Posted: Thu May 13, 2010 8:07 am
by l3whmg
Hi Roberto,
you are SIMPLY THE ...GREAT!!

And now I must find a PC to install Linux, learn this SysOp, etc., etc., etc. :lol:

I always say to you: MANY THANKS!

Best Regards

Re: Hello Linux!!!

Posted: Thu May 13, 2010 8:23 am
by Rathinagiri
Since this is cross platform, this can be compiled in Windows too. Isn't it?!

What are the tools to be installed in windows?