GtkLayout

only for RuBoard - do not distribute or recompile

GtkLayout

The GtkLayout widget is very similar to the GtkFixed widget, but it allows a larger widget placement area. It also handles re-drawing of child widgets differently, necessitating the use of the *_freeze* and *_thaw* calls (see the end of Listing 4.4). Listing 4.4 is presented in Figure 4.4.

Figure 4.4. The GtkLayout demo program running.
graphics/04fig04.gif

Listing 4.4 and Figure 4.4 are intentionally very similar to Listing 4.3 and Figure 4.3 The purpose is to demonstrate the similarities and differences between these two very similar widgets; compile and run both to see which will best fit your needs.

Listing 4.4 GtkLayout Demo
 #include <gtk/gtk.h>  #include <stdlib.h>  GtkWidget *frm_layout;  GtkWidget *layout_main;  GtkWidget *cmd1;  void destroy_main();  void cmd1_clicked();  gint main(gint argc, gchar *argv[])  {    gtk_init(&argc, &argv);     frm_layout = gtk_window_new(GTK_WINDOW_TOPLEVEL);     gtk_window_set_title(GTK_WINDOW(frm_layout), "Layout Widget Demo");     gtk_signal_connect(GTK_OBJECT(frm_layout),          "destroy",          GTK_SIGNAL_FUNC(destroy_main),          NULL);     layout_main = gtk_layout_new(NULL, NULL);  /* Other than the call above to  gtk_layout_new()  ,   * which requires vertical and horizontal adjustment   * objects as parameters, you could take the previous   * listing and change every instance of "fixed" to   * "layout," and the program should work.   *   * However, lines have also been added   * to this program to demonstrate the Layout widget   * functionality.   */  cmd1 = gtk_button_new_with_label("Button 1");     gtk_signal_connect(GTK_OBJECT(cmd1),          "clicked",          GTK_SIGNAL_FUNC(cmd1_clicked),          NULL);     gtk_layout_put(GTK_LAYOUT(layout_main), cmd1, 1, 100);     gtk_container_add(GTK_CONTAINER(frm_layout), layout_main);     gtk_widget_show_all (frm_layout);     gtk_main ();     return 0;  }  void destroy_main()  {   gtk_main_quit();  }  void cmd1_clicked()  {    gint x_pos, y_pos;     x_pos = rand();     y_pos = rand();  /* The following is a poor man's bounded   * random number generator. In this case,   * the target is for a number between 1 and 200.   */  do{       x_pos = x_pos - 200;     } while (x_pos > 200);     do{       y_pos = y_pos - 200;     } while (y_pos > 200);  /* Here is one big difference between the Fixed and Layout widgets.   * It is best to freeze and thaw the Layout widget, especially if you   * have a lot of child widgets to move around and show simultaneously.   * This prevents having to redraw the screen unnecessarily.   */  gtk_layout_freeze(GTK_LAYOUT(layout_main));     gtk_layout_move(GTK_LAYOUT(layout_main), GTK_WIDGET(cmd1), x_pos, y_pos);     gtk_layout_thaw(GTK_LAYOUT(layout_main));  } 
only for RuBoard - do not distribute or recompile


MySQL Building User Interfaces
MySQL: Building User Interfaces (Landmark)
ISBN: 073571049X
EAN: 2147483647
Year: 2001
Pages: 119

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net