GtkFixed

only for RuBoard - do not distribute or recompile

GtkFixed

The GtkFixed widget is initially attractive to developers coming from VB or VC++ because the paradigm is familiar to them. That is, unlike the GTK+ paradigm of packing widgets, the GtkFixed widget allows the developer to place widgets at certain points on a grid and to move the widgets around (see Figure 4.3). However, most developers will tend to gravitate toward the GtkLayout widget (see the following section, titled GtkLayout) because it has slightly more advanced functionality.

Figure 4.3. The GtkFixed demo program running.
graphics/04fig03.gif

The program in Listing 4.3 is fairly simple: It has a GtkFixed widget and a single command button that jumps around within the GtkFixed widget when pushed . Compare this with the GtkLayout widget (covered in the next section) before you decide which one is best suited to your project.

Listing 4.3 GtkFixed Demo
 #include <gtk/gtk.h>  #include <stdlib.h>  /* This is needed for the random number function in the callback   * at the bottom of the listing. This random number function   * is used to jump the command button (cmd1) around within the   * fixed widget.   */  GtkWidget *frm_fixed;  GtkWidget *fixed_main;  GtkWidget *cmd1;  void destroy_main();  void cmd1_clicked();  gint main(gint argc, gchar *argv[])  {    gtk_init(&argc, &argv);     frm_fixed = gtk_window_new(GTK_WINDOW_TOPLEVEL);     gtk_window_set_title(GTK_WINDOW(frm_fixed), "Fixed Widget Demo");     gtk_signal_connect(GTK_OBJECT(frm_fixed),          "destroy",          GTK_SIGNAL_FUNC(destroy_main),          NULL);     fixed_main = gtk_fixed_new();  /* The GtkFixed widget is very simple to use. As shown   * below, you give it the coordinates at which to place   * a child widget. The widget attributes of fill, expand,   * padding, and so on, are irrelevant here; the child widgets   * placed onto the fixed widget will default to the   * minimum required to show correctly. This is the same   * behavior of the GtkFixed widget; it will size itself   * to the minimum required to show all its child   * widgets. If a child widget is moved to an area outside   * of the GtkFixed's current size, the fixed widget will   * grow just enough to properly show the widget. If,   * however, the child widgets are moved to a location   * that would allow the window to shrink, the fixed   * widget will not automatically shrink to the minimum   * required size.   *   * This can lead to some unexpected behavior. For example,   * suppose the initial position is 1, 1. Then the   * position changes to 100, 100. If the position then   * changes to 50, 50, the window size will not change.   * If, however, the position changes to 150, 50, the   * window will change size, to be just large enough to   * properly show the widget. Another way to put it is   * that the window will be redrawn whenever the child   * widgets push an outside boundary of the window   * pushing either the right or the bottom boundary out. Then   * the window will be resized. Thus, you could go from an   * essentially square window to a long and thin one,   * and vice-versa.   *   * Although the GtkFixed widget is simple to implement,   * you will probably want to use the GtkLayout widget   * in most instances. Examine it before deciding   * which will best suit your project.   */  cmd1 = gtk_button_new_with_label("Button 1");     gtk_signal_connect(GTK_OBJECT(cmd1),          "clicked",          GTK_SIGNAL_FUNC(cmd1_clicked),          NULL);     gtk_fixed_put(GTK_FIXED(fixed_main), cmd1, 1, 100);  /* The third and fourth parameters of the previous call   * are the distance from the left edge of the window in pixels,   * and the distance from the top edge of the window in pixels,   * respectively.   */  gtk_container_add(GTK_CONTAINER(frm_fixed), fixed_main);     gtk_widget_show_all (frm_fixed);     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 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);     gtk_fixed_move(GTK_FIXED(fixed_main), GTK_WIDGET(cmd1), x_pos, y_pos);  } 
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