Window size adjustment problems.



Hi all,

Attached below is a simple self-contained example that shows the problem 
I'm seeing. This was produced by taking the Glade generated output, and 
consolidating into a single file.

Save the attachment as perfmeter.c, and compile with:

gcc -o perfmeter `gtk-config --cflags` perfmeter.c `gtk-config --libs`

When you run perfmeter, you should see a 200x200 window (with a non-functional
menubar) and a drawing area below. If you click on the drawing area, the
menubar is hidden and a 100x100 pixel white square is drawn in the middle of
the drawing area. If you click again on the menubar, it reappears, and 
another 100x100 pixel white square is drawn in the drawing area. And so on.

What I want to happen is that if the menubar was showing when you click on
the drawing area, then it's hidden, the main window reduces in size by the
height of the menubar, and the canvas is the only thing left (and would
take up the whole height of the window). When you reclick on the drawing
area, the menubar reappears at the top, with the canvas below it.

Any pointers to what I'm doing wrong or failing to understand would be much
appreciated.

This is on a Solaris box with Gtk v1.2.9 should that make a difference.

Thanks.

--
Rich Burridge                                   Email: rich burridge Sun COM
Sun Microsystems, Desktop Foundation Software.  Phone: +1.408.343.1850
901 San Antonio Rd. CUP01-103                   AIM/YAHOO: RicBurridge
Palo Alto, CA 94303                       WWW: http://java.sun.com/people/richb/

#include <gtk/gtk.h>

static GtkWidget *MainWin, *MenuBar, *Canvas;

gboolean CanvasResize (GtkWidget *, GdkEventConfigure *, gpointer);
gboolean ButtonPress  (GtkWidget *, GdkEventButton *,    gpointer);
GtkWidget *create_MainWin(void);


int
main(int argc, char *argv[])
{
  gtk_set_locale();
  gtk_init(&argc, &argv);

  MainWin = create_MainWin();

  gtk_widget_set_usize(MainWin, 200, 200);
  gtk_widget_show(MainWin);

  gtk_main();
  return(0);
}


GtkWidget*
create_MainWin (void)
{
  GtkWidget *MainWin;
  GtkWidget *VBox;
  GtkWidget *view1;

  MainWin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_object_set_data (GTK_OBJECT (MainWin), "MainWin", MainWin);
  gtk_widget_set_events (MainWin, GDK_KEY_PRESS_MASK);
  gtk_window_set_title (GTK_WINDOW (MainWin), "Performance Meter");
  gtk_window_set_policy (GTK_WINDOW (MainWin), FALSE, TRUE, TRUE);

  VBox = gtk_vbox_new (FALSE, 0);
  gtk_widget_ref (VBox);
  gtk_object_set_data_full (GTK_OBJECT (MainWin), "VBox", VBox,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (VBox);
  gtk_container_add (GTK_CONTAINER (MainWin), VBox);

  MenuBar = gtk_menu_bar_new ();
  gtk_widget_ref (MenuBar);
  gtk_object_set_data_full (GTK_OBJECT (MainWin), "MenuBar", MenuBar,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (MenuBar);
  gtk_box_pack_start (GTK_BOX (VBox), MenuBar, FALSE, FALSE, 0);

  view1 = gtk_menu_item_new_with_label ("View");
  gtk_widget_ref (view1);
  gtk_object_set_data_full (GTK_OBJECT (MainWin), "view1", view1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (view1);
  gtk_container_add (GTK_CONTAINER (MenuBar), view1);

  Canvas = gtk_drawing_area_new ();
  gtk_widget_ref (Canvas);
  gtk_object_set_data_full (GTK_OBJECT (MainWin), "Canvas", Canvas,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (Canvas);
  gtk_box_pack_start (GTK_BOX (VBox), Canvas, TRUE, TRUE, 0);
  gtk_widget_set_events (Canvas, GDK_BUTTON_PRESS_MASK);
 
  gtk_signal_connect (GTK_OBJECT (Canvas), "configure_event",
                      GTK_SIGNAL_FUNC (CanvasResize),
                      NULL);
  gtk_signal_connect (GTK_OBJECT (Canvas), "button_press_event",
                      GTK_SIGNAL_FUNC (ButtonPress),
                      NULL);
 
  return MainWin;
}


gboolean
CanvasResize(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data)
{
  printf("CanvasResize called.\n");

  return(FALSE);
}


gboolean
ButtonPress(GtkWidget *widget, GdkEventButton  *event, gpointer user_data)
{
  printf("ButtonPress called.\n");
  if (GTK_WIDGET_MAPPED(MenuBar)) {
      gtk_widget_unmap(MenuBar);
  } else {
      gtk_widget_map(MenuBar);
  }

  /* draw a 100 pixel white square in the center of the drawing area. */
  gdk_draw_rectangle(Canvas->window, Canvas->style->white_gc, TRUE,
                     (Canvas->allocation.width - 100) /2,
                     (Canvas->allocation.height - 100) / 2, 100, 100);

  return(FALSE);
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]