some changes

This commit is contained in:
Antonio Linares
2001-09-24 06:48:29 +00:00
parent 4d5048b398
commit d3c4a94cb3
7 changed files with 220 additions and 59 deletions

View File

@@ -6,14 +6,21 @@ ROOT = ../../../
C_SOURCES=\
creawin.c \
general.c \
creamenu.c \
creabutt.c \
dispatch.c \
msginfo.c \
PRG_SOURCES=\
tform.prg \
tmenu.prg \
menuitem.prg \
form.prg \
menu.prg \
button.prg \
menuitem.prg \
winctrl.prg \
LIBNAME=hbgtk
include $(TOP)$(ROOT)config/lib.cf

View File

@@ -60,12 +60,21 @@
/* ********************************************************************* */
HB_FUNC( HB_GTKCREATEMENU )
{
GtkWidget *Menu = gtk_menu_new();
hb_retnl( GPOINTER_TO_UINT( Menu ) );
}
/* ********************************************************************* */
HB_FUNC( HB_GTKCREATEMENUBAR )
{
GtkBox *Box = ( GtkBox * )GUINT_TO_POINTER( hb_parnl( 1 ) );
if( Box )
{
GtkWidget *MenuBar = gtk_menu_bar_new();
gtk_menu_bar_set_shadow_type( GTK_MENU_BAR( MenuBar ), GTK_SHADOW_OUT );
gtk_box_pack_start( Box, MenuBar, FALSE, FALSE, 0 );
gtk_box_reorder_child( Box, MenuBar, 0 );
@@ -77,6 +86,15 @@ HB_FUNC( HB_GTKCREATEMENUBAR )
/* ********************************************************************* */
static void ActivateMenuItem( GtkWidget *Widget, gpointer Data )
{
GtkWidget *Form = ( GtkWidget * )gtk_object_get_data( GTK_OBJECT( Widget ), "Form" );
if( !( GTK_MENU_ITEM( Widget )->submenu ) )
CallHarbour( Form, Widget, HGF_EV_MENU, GPOINTER_TO_INT( Data ), ( PHB_ITEM )NULL );
}
/* ********************************************************************* */
HB_FUNC( HB_GTKBARADDMENUITEM )
{
GtkMenuBar *Bar = ( GtkMenuBar * )GUINT_TO_POINTER( hb_parnl( 1 ) );
@@ -84,14 +102,24 @@ HB_FUNC( HB_GTKBARADDMENUITEM )
if( Bar )
{
gchar *Caption = ( gchar * )hb_parc( 2 );
/* gint Id = ( gint )hb_parni( 3 ); */
gint ItemID = ( gint )hb_parni( 3 );
gboolean Enabled = ( gboolean )hb_parl( 4 );
GtkWidget *Form = ( GtkWidget * )GUINT_TO_POINTER( hb_parnl( 5 ) );
GtkWidget *Item = gtk_menu_item_new_with_label( Caption );
gtk_widget_set_sensitive( Item, Enabled );
gtk_widget_show( Item );
gtk_menu_bar_append( GTK_MENU_BAR( Bar ), Item );
gtk_widget_set_sensitive( Item, Enabled );
gtk_object_set_data( GTK_OBJECT( Item ), "Form", ( gpointer )Form );
gtk_signal_connect
(
GTK_OBJECT( Item ),
"activate",
GTK_SIGNAL_FUNC( ( GtkSignalFunc ) ActivateMenuItem ),
GINT_TO_POINTER( ItemID )
);
gtk_menu_bar_append( GTK_MENU_BAR( Bar ), Item );
hb_retnl( GPOINTER_TO_UINT( Item ) );
}
else
@@ -103,31 +131,38 @@ HB_FUNC( HB_GTKBARADDMENUITEM )
HB_FUNC( HB_GTKADDMENUITEM )
{
GtkWidget *Menu = ( GtkWidget * )GUINT_TO_POINTER( hb_parnl( 1 ) );
GtkMenuItem *Self = ( GtkMenuItem * )GUINT_TO_POINTER( hb_parnl( 2 ) );
GtkMenuItem *Curr = ( GtkMenuItem * )GUINT_TO_POINTER( hb_parnl( 2 ) );
if( !Menu )
{
Menu = gtk_menu_new();
gtk_menu_item_set_submenu( Self, Menu );
gtk_menu_item_set_submenu( Curr, Menu );
hb_stornl( GPOINTER_TO_UINT( Menu ), 1 );
}
if( Self )
if( Curr )
{
GtkWidget *Item = ( GtkWidget * )GUINT_TO_POINTER( hb_parnl( 3 ) );
gchar *Caption = ( gchar * )hb_parc( 4 );
/* gint Id = ( gint )hb_parni( 5 ); */
gint ItemID = ( gint )hb_parni( 5 );
gboolean Enabled = ( gboolean )hb_parl( 6 );
GtkWidget *Form = ( GtkWidget * )GUINT_TO_POINTER( hb_parnl( 7 ) );
if( !Item )
{
Item = gtk_menu_item_new_with_label( Caption );
gtk_widget_show( Item );
}
gtk_widget_set_sensitive( Item, Enabled );
gtk_menu_append( GTK_MENU( Menu ), Item );
gtk_object_set_data( GTK_OBJECT( Item ), "Form", ( gpointer )Form );
gtk_signal_connect
(
GTK_OBJECT( Item ),
"activate",
GTK_SIGNAL_FUNC( ( GtkSignalFunc ) ActivateMenuItem ),
GINT_TO_POINTER( ItemID )
);
gtk_menu_append( GTK_MENU( Menu ), Item );
hb_retnl( GPOINTER_TO_UINT( Item ) );
}
else

View File

@@ -60,38 +60,70 @@
/* ********************************************************************* */
/* "delete_event" event handler - will be used for VALID clause in the future */
static gint DeleteEventWindowCallback( GtkWidget *Widget, GdkEventAny *Event, gpointer Data )
{
gint DeleteAllowed = FALSE;
/* the code needs to be added here in the future */
return ( DeleteAllowed );
return( CallHarbour( Widget, Widget, HGF_EV_CLOSE, GPOINTER_TO_INT( Data ), ( PHB_ITEM )NULL ) );
}
/* ********************************************************************* */
/* "destroy" signal handler */
static gint DestroyWindowCallback( GtkWidget *Widget, gpointer Data )
{
gint DestroyAllowed = FALSE;
gint Propagate = CallHarbour( Widget, Widget, HGF_EV_DESTROY, GPOINTER_TO_INT( Data ), ( PHB_ITEM )NULL );
/* the code needs to be added here in the future */
if( !DestroyAllowed )
if( !Propagate )
{
/* the code needs to be added here in the future */
/* the code needs to be added here in the future ? */
if( Widget == gtk_widget_get_toplevel( Widget ) )
gtk_main_quit();
}
return ( DestroyAllowed );
return ( Propagate );
}
/* ********************************************************************* */
static gint ButtonPressCallback( GtkWidget *Widget, GdkEventButton *Event, gpointer Data )
{
GtkWidget *Form = ( GtkWidget * )gtk_object_get_data( GTK_OBJECT( Widget ), "Form" );
gint Propagate = FALSE, ButtonNO = Event->button;
PHB_ITEM ReturnArray = hb_itemArrayNew( HGF_EVENTDATA_MAXLEN );
PHB_ITEM ArrayItem = hb_itemNew( NULL );
if( !Form ) Form = Widget;
hb_itemPutND( ArrayItem, ( double )Event->y );
hb_itemArrayPut( ReturnArray, 1, ArrayItem );
hb_itemPutND( ArrayItem, ( double )Event->x );
hb_itemArrayPut( ReturnArray, 2, ArrayItem );
hb_itemPutNL( ArrayItem, ( LONG )Event->state & 0xFF );
hb_itemArrayPut( ReturnArray, 3, ArrayItem );
switch ( ButtonNO )
{
case 1 :
Propagate = CallHarbour( Form, Widget, HGF_EV_LBUTTONPRESSED, GPOINTER_TO_INT( Data ), ReturnArray );
break;
case 2 :
Propagate = CallHarbour( Form, Widget, HGF_EV_RBUTTONPRESSED, GPOINTER_TO_INT( Data ), ReturnArray );
break;
default :
Propagate = CallHarbour( Form, Widget, HGF_EV_MBUTTONPRESSED, GPOINTER_TO_INT( Data ), ReturnArray );
break;
}
hb_itemRelease( ReturnArray );
hb_itemRelease( ArrayItem );
return( Propagate );
}
/* ************************************************************************* */
HB_FUNC( HB_GTKWINDOWCREATE )
{
GtkWidget *MainWin, *VBox, *MoveBar, *MenuBar,
@@ -101,6 +133,8 @@ HB_FUNC( HB_GTKWINDOWCREATE )
/* for the future enhancements */
gint YSize=400, XSize=500;
gint WinID = ( gint )hb_parni( 1 );
MainWin = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_default_size( GTK_WINDOW( MainWin ), XSize, YSize );
gtk_window_set_policy( GTK_WINDOW( MainWin ), TRUE, TRUE, FALSE );
@@ -112,28 +146,34 @@ HB_FUNC( HB_GTKWINDOWCREATE )
Current = VBox;
LayoutW = gtk_layout_new( NULL, NULL );
gtk_layout_set_size( GTK_LAYOUT( LayoutW ), XSize, YSize );
/* gtk_layout_set_size( GTK_LAYOUT( LayoutW ), XSize, YSize ); */
gtk_box_pack_start( GTK_BOX( Current ), LayoutW, TRUE, TRUE, 0 );
/* for the future signal handling */
gtk_signal_connect
(
GTK_OBJECT( MainWin ),
"delete_event",
GTK_SIGNAL_FUNC( ( GtkSignalFunc ) DeleteEventWindowCallback ),
( gpointer ) NULL
GINT_TO_POINTER( WinID )
);
/* for the future signal handling */
gtk_signal_connect
(
GTK_OBJECT( MainWin ),
"destroy",
GTK_SIGNAL_FUNC( ( GtkSignalFunc ) DestroyWindowCallback ),
( gpointer ) NULL
GINT_TO_POINTER( WinID )
);
gtk_widget_add_events( MainWin, GDK_BUTTON_PRESS_MASK );
gtk_signal_connect
(
GTK_OBJECT( MainWin ),
"button_press_event",
GTK_SIGNAL_FUNC( ButtonPressCallback ),
GINT_TO_POINTER( WinID )
);
/* for the future enhancements */
ScrlWin = MoveBar = MenuBar = NULL;
{
@@ -171,7 +211,7 @@ HB_FUNC( HB_GTKWINDOWCREATE )
/* ********************************************************************* */
HB_FUNC( HB_GTKWINGETTEXT )
HB_FUNC( HB_GTKWINDOWGETTEXT )
{
PHB_ITEM hWnd = hb_param( 1, HB_IT_ARRAY );
@@ -186,13 +226,13 @@ HB_FUNC( HB_GTKWINGETTEXT )
/* ********************************************************************* */
HB_FUNC( HB_GTKWINSETTEXT )
HB_FUNC( HB_GTKWINDOWSETTEXT )
{
PHB_ITEM hWnd = hb_param( 1, HB_IT_ARRAY );
if( hWnd )
{
gchar *Title = hb_parc( 2 ); /* either tilte or "" */
gchar *Title = hb_parc( 2 );
GtkWindow *Win = ( GtkWindow * )GUINT_TO_POINTER( hb_arrayGetNL( hWnd, 1 ) );
gtk_window_set_title( Win, Title );
}
@@ -214,3 +254,24 @@ HB_FUNC( HB_GTKSHOWMODAL )
}
/* ********************************************************************* */
HB_FUNC( HB_GTKWINDOWREQUESTDELETE )
{
GtkWidget *Widget;
PHB_ITEM hWnd = hb_param( 1, HB_IT_ARRAY );
if( hWnd )
Widget = ( GtkWidget * )GUINT_TO_POINTER( hb_arrayGetNL( hWnd, 1 ) );
else
Widget = ( GtkWidget * )GUINT_TO_POINTER( hb_parnl( 1 ) );
if( Widget )
{
GdkEvent Event;
Event.type = GDK_DELETE;
Event.any.window = Widget->window;
gdk_event_put( &Event );
}
}
/* ********************************************************************* */

View File

@@ -51,3 +51,7 @@
*/
/* ********************************************************************* */
#include "shared.ch"
/* ********************************************************************* */

View File

@@ -69,7 +69,9 @@
/* delimiters into it */
extern gchar *MultiLineDelimiters;
/* a general Tooltips holder */
extern GtkTooltips *MainTooltips;
/* ************************************************************************* */
/* calls Harbour level dispatcher */
glong CallHarbour( GtkWidget *hWnd, GtkWidget *Widget, glong Command, gint ObjId, PHB_ITEM aParam );
/* ************************************************************************* */

View File

@@ -5,9 +5,9 @@
/*
* Harbour Project source code:
* Harbour GUI framework for Gtk
* Class HBMenuItem
*
* Copyright 2001 Antonio Linares <alinares@fivetech.com>
* Copyright 2001 Maurilio Longo <maurilio.longo@libero.it>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
@@ -49,57 +49,86 @@
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
* Additional Copyright notes :
* adapted for Hgf Gtk by Marek Paliwoda <paliwoda@inetia.pl>
*/
/* ********************************************************************* */
#include "common.ch"
#include "hbclass.ch"
#include "harbgtk.ch"
/* ********************************************************************* */
CLASS TMenuItem
CLASS HBMenuItem FROM HBPersistent
DATA cCaption INIT "" // Specifies the text of the menu item
DATA cAction INIT "" // A character description of the method to invoke
DATA nId // Command value to send to the container form
DATA lEnabled INIT .T. // Specifies whether the menu item is enabled
DATA aItems INIT {} // Contains the menu items in the submenu of the menu item
DATA oParent // Identifies the parent menu item of this menu item
DATA nHandle INIT 0 // The handle of the submenu of this menu item
DATA hMenuItem INIT 0 // The handle of this menu item
DATA Caption INIT "" PROPERTY // Specifies the text of the menu item
DATA Name PROPERTY // The name of this component
DATA OnClick PROPERTY // A character description of the method to invoke
DATA Enabled INIT .T. PROPERTY // Specifies whether the menu item is enabled
DATA Items INIT {} PROPERTY // Contains the menu items in the submenu of the menu item
DATA nId // Command value to send to the container form
DATA oParent // Identifies the parent menu item of this menu item
DATA Container
DATA nHandle INIT 0 // The handle of the submenu of this menu item
DATA hMenuItem INIT 0 // The handle of this menu item
CLASSDATA nIdStart INIT 110 // start value for commands value to assign to menu items
METHOD New( oOwner ) // Creates a new menu item
METHOD Add( oMenuItem ) // Adds a new drop down menu item
METHOD New( oOwner ) // Creates a new menu item
METHOD Add( oMenuItem ) // Adds a new drop down menu item
METHOD FindItem( nId ) // Searches for a sub menuitem given its id
ENDCLASS
/* ********************************************************************* */
METHOD New( oOwner ) CLASS TMenuItem
METHOD New( oOwner ) CLASS HBMenuItem
::nId := ::nIdStart++
::oParent := oOwner
::nId := ::nIdStart++
IF oOwner != nil
::Container := oOwner:Container
ENDIF
::oParent := oOwner
// NOTE : physical creation is delayed until MenuItem is added to a parent
RETURN Self
/* ********************************************************************* */
METHOD Add( oMenuItem ) CLASS TMenuItem
METHOD Add( oMenuItem ) CLASS HBMenuItem
/* required because of a stupid Harbour compiler error */
LOCAL nHandle := ::nHandle
oMenuItem:hMenuItem := hb_GtkAddMenuItem( @nHandle, ::hMenuItem, ;
oMenuItem:hMenuItem, oMenuItem:cCaption, oMenuItem:nId, ;
oMenuItem:lEnabled )
oMenuItem:hMenuItem, oMenuItem:Caption, oMenuItem:nId, ;
oMenuItem:Enabled, ::Container:hWnd[ 1 ] )
::nHandle := nHandle
AAdd( ::aItems, oMenuItem )
oMenuItem:oParent = Self
AAdd( ::Items, oMenuItem )
RETURN nil
/* ********************************************************************* */
METHOD FindItem( nId ) CLASS HBMenuItem
LOCAL oMenuItem, n
FOR n = 1 TO Len( ::Items )
IF ( oMenuItem := ::Items[ n ] ):nId == nId
RETURN oMenuItem
ELSE
IF oMenuItem:Items != nil
IF ( oMenuItem := oMenuItem:FindItem( nId ) ) != nil
RETURN oMenuItem
ENDIF
ENDIF
ENDIF
NEXT
RETURN oMenuItem
/* ********************************************************************* */

View File

@@ -52,3 +52,26 @@
/* ************************************************************************* */
#define HGF_EV_MENU 0x0001
#define HGF_EV_CLICK 0x0002
#define HGF_EV_CLOSE 0x0003
#define HGF_EV_DESTROY 0x0004
#define HGF_EV_LBUTTONPRESSED 0x0005
#define HGF_EV_RBUTTONPRESSED 0x0006
#define HGF_EV_MBUTTONPRESSED 0x0007
/* ************************************************************************* */
#define HGF_EVENTDATA_MAXLEN 3
/* ************************************************************************* */
/* These are for HGF GTK only */
/* Harbour equivalent menu types of GTK+ menu types */
#define HBGTKMENUTYPEBAR 0
#define HBGTKMENUTYPEPOP 1
#define HGF_GTK_WIDGET_GEOMETRY_UNKNOWN -99999
/* ************************************************************************* */