Event box, Alignment e Container

 

Event box.

Alcune widget non hanno associata una finestra e sono disegnate direttamente nei loro "parents".
Questo vuol dire che non possono ricevere eventi essere ridimensionate etc.
Qualora ciò servisse la soluzione è di inserirle in una event box
Per creare una nuova event box si usa:

GtkWidget *gtk_event_box_new( void );

Per aggiungere alla EventBox la widget useremo invece:

gtk_container_add( GTK_CONTAINER(event_box), child_widget );

Il seguente esempio mostra l'uso di una Event box con una label. Quando si clikka sulla label il programma esce.

/* Inizio esempio eventbox eventbox.c */

#include <gtk/gtk.h>

int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *event_box;
GtkWidget *label;

gtk_init (&argc, &argv);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

gtk_window_set_title (GTK_WINDOW (window), "Event Box");

gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_exit), NULL);

gtk_container_set_border_width (GTK_CONTAINER (window), 10);

/* Crea una an EventBox */

event_box = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER(window), event_box);
gtk_widget_show (event_box);

/* Crea una lunga label */

label = gtk_label_new ("Click here to quit, quit, quit, quit, quit");
gtk_container_add (GTK_CONTAINER (event_box), label);
gtk_widget_show (label);

gtk_widget_set_usize (label, 110, 20);

/* Colleghiamo l'evento */
gtk_widget_set_events (event_box, GDK_BUTTON_PRESS_MASK);
gtk_signal_connect (GTK_OBJECT(event_box), "button_press_event",
GTK_SIGNAL_FUNC (gtk_exit), NULL);

gtk_widget_realize (event_box);
gdk_window_set_cursor (event_box->window, gdk_cursor_new (GDK_HAND1));

gtk_widget_show (window);

gtk_main ();

return(0);
}
/* Fine esempio */

Il widget Alignment.

Serve per posizionare un widget nella sua finestra.
Ad esempio può essere molto utile per centrare il widget nella finestra.

Ci sono solo due funzioni associate all'Alignment:

GtkWidget* gtk_alignment_new( gfloat xalign,
gfloat yalign,
gfloat xscale,
gfloat yscale );

void gtk_alignment_set( GtkAlignment *alignment,
gfloat xalign,
gfloat yalign,
gfloat xscale,
gfloat yscale );

La prima crea un nuovo Alignment con i parametri specificati.
La seconda permette di alterare i parametri di un aligment esistente.

Un child widget può essere aggiunto all'Alignment usando:

gtk_container_add( GTK_CONTAINER(alignment), child_widget );

Per un esempio ci si può riferire a quello relativo alla progress bar.

 

 

Container

Fixed Container

Permette di posizionare un widget in una posizione fissa all'interno di una finestra relativamente al suo angolo superiore sinistro.
La posizione può essere cambiata dinamicamente.

Ci sono solo tre funzioni associate al fixed container:

GtkWidget* gtk_fixed_new( void );

void gtk_fixed_put( GtkFixed *fixed,
GtkWidget *widget,
gint16 x,
gint16 y );

void gtk_fixed_move( GtkFixed *fixed,
GtkWidget *widget,
gint16 x,
gint16 y );

La funzione gtk_fixed_new permette di creare un nuovo fixed.

gtk_fixed_put posiziona il widget alla posizione specificata da x e y.

gtk_fixed_move permette di muovere il widget in una nuova posizione.

 

Layout Container.

Il Layout container è simile al Fixed container eccettuato per il fatto che implementa uno scrolling infinito

Il Layout container viene creato con la funzione:

GtkWidget *gtk_layout_new( GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment );

Come si vede può essere specificato un Adjustment object che il Layout widget userà per il suo scrolling.

Si possono aggiungere e spostare widget nel Layout container usando le seguenti funzioni:

void gtk_layout_put( GtkLayout *layout,
GtkWidget *widget,
gint x,
gint y );

void gtk_layout_move( GtkLayout *layout,
GtkWidget *widget,
gint x,
gint y );

La misura del Layout container può essere settata con:

void gtk_layout_set_size( GtkLayout *layout,
guint width,
guint height );

Le ultime funzioni disponibili per il Layout widgets sono per manipolare gli adjustment orizzontali e vertcali:

GtkAdjustment* gtk_layout_get_hadjustment( GtkLayout *layout );

GtkAdjustment* gtk_layout_get_vadjustment( GtkLayout *layout );

void gtk_layout_set_hadjustment( GtkLayout *layout,
GtkAdjustment *adjustment );

void gtk_layout_set_vadjustment( GtkLayout *layout,
GtkAdjustment *adjustment);.

 

Torna all'indice