[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gtk-app-devel
Subject:    Again: force a popup fully to the screen
From:       "Dipl.-Ing. Uwe Koloska" <koloska () Rcs1 ! urz ! tu-dresden ! de>
Date:       1999-07-09 15:30:15
[Download RAW message or body]

Hello,

do you remember?  I asked what I can do to force a popup window appear fully to
the screen.
	gtk_widget_show_all(popup)
	gdk_window_get_size()
works but gives some flicker (the popup is sometimes drawn twice) and
	gtk_widget_realize(popup)
	/* with all widget shown by gtk_widget_show_all(box) box inside popup */
gives redraw artefacts left from the upper left corner of the popup.

To show you the code, I stripped down the programm and run into trubble.  Now
after gtk_widget_show_all(popup) the size is 1x1 and resizes some times later
to the right one ...

I have a drawing_area in my main-window. Clicking in this drawing_area runs the
following callback:

--------------------------------------------------------------------------------
static gint mouse_event(GtkWidget *widget, GdkEventButton *event,
			gpointer data)
{
  static GtkWidget *popup = NULL;
  static guint buttonclicked = 0;
  int width, height;
  GtkWidget *toplevel;
  int pos_x, pos_y, delta_x, delta_y;
  int chrsize;
  gint size_x, size_y;

  toplevel = gtk_widget_get_toplevel(widget);

  if (event->type == GDK_BUTTON_PRESS) {
    if (buttonclicked != 0)
      return FALSE;  /* Do not allow a second parallel click */
    buttonclicked = event->button;  /* Record which button was clicked */
    switch (event->button) {
    case 1:
      chrsize = 80;
      break;
    case 2:
      chrsize = 160;
      break;
    case 3:
      chrsize = 240;
      break;
    default:
      /* sorry, scrolling wheels don't do anything here */
      return FALSE;
    }
    width = chrsize;
    height = chrsize * 2;

    popup = showglyph(GTK_WINDOW_POPUP, width, height);
    pos_x = (int)event->x_root;
    pos_y = (int)event->y_root;

    gtk_widget_set_uposition(popup, pos_x, pos_y);
    /* we have to show it to determine the size */
    g_message("mouse_event(): before gtk_widget_show_all()\n");
    /* gtk_widget_show_all(popup); */
    gtk_widget_realize(popup);

    gdk_window_get_size(popup->window, &size_x, &size_y);
    delta_x = gdk_screen_width() - (pos_x + size_x);
    delta_y = gdk_screen_height() - (pos_y + size_y);
    g_message("mouse_event(): size_x = %d; size_y = %d\n", size_x, size_y);
    if (delta_x < 0) pos_x += delta_x;
    if (delta_y < 0) pos_y += delta_y;
    gtk_widget_set_uposition(popup, pos_x, pos_y);
    gtk_widget_show_all(popup);
    g_message("mouse_event(): end\n");
  }

  if (event->type == GDK_BUTTON_RELEASE) {
    if (event->button != buttonclicked) return FALSE;
    buttonclicked = 0;
    if (popup) {
      gtk_widget_destroy(popup);
      gtk_widget_destroyed(popup, &popup);
    }
  }
  return FALSE;
}
--------------------------------------------------------------------------------


the popup is created by the following subroutine
---------------------------------------------------------------------------------
static GtkWidget* showglyph(GtkWindowType type, 
		     int width, int height)
{
  GtkWidget* window;
  GtkWidget* box;
  GtkWidget* char_name;
  char zahl[10+1];
  int chr = 46;
  GdkPixmap *pixmap;
  GtkWidget *char_ascii, *char_oct, *char_hex;
  GtkWidget* hbox;
  GtkWidget* drawing_area;
  int w, h;

  window = gtk_window_new(type);
  gtk_container_border_width(GTK_CONTAINER(window), 10);
  gtk_widget_realize(window);

  pixmap = gdk_pixmap_new(window->window, width, height, -1);
  drawing_area = gtk_drawing_area_new();
  gtk_widget_set_events(drawing_area, GDK_EXPOSURE_MASK | 
			GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
  gtk_drawing_area_size(GTK_DRAWING_AREA(drawing_area), width, height);
  
  gdk_draw_rectangle(pixmap, window->style->white_gc, TRUE,
		     0, 0, -1, -1);  

  box = gtk_vbox_new(FALSE, 4);
  gtk_container_add(GTK_CONTAINER(window), box);

  gtk_box_pack_start(GTK_BOX (box), drawing_area, FALSE, FALSE, 10);

  char_name = gtk_label_new("Test");
  gtk_box_pack_start(GTK_BOX(box), char_name, FALSE, TRUE, 4);

  snprintf(zahl, 10, "%3d", chr);
  char_ascii = gtk_label_new(zahl);
  snprintf(zahl, 10, "0%03o", chr);
  char_oct = gtk_label_new(zahl);
  snprintf(zahl, 10, "0x%02x", chr);
  char_hex = gtk_label_new(zahl);

  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start(GTK_BOX(box), hbox, TRUE, TRUE, 0);
    
  gtk_box_pack_start(GTK_BOX(hbox), char_ascii, TRUE, TRUE, 4);
  gtk_box_pack_start(GTK_BOX(hbox), char_oct, TRUE, TRUE, 4);
  gtk_box_pack_start(GTK_BOX(hbox), char_hex, TRUE, TRUE, 4);

  /* gtk_widget_show_all(box); */
  gtk_signal_connect(GTK_OBJECT(drawing_area), "expose_event", 
		     (GtkSignalFunc)expose_event, (gpointer)pixmap);

  gtk_signal_connect(GTK_OBJECT(window), "delete_event",
		     GTK_SIGNAL_FUNC(gtk_false), NULL);
  gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
		     GTK_SIGNAL_FUNC(window_resize_callback), NULL);
  /* gtk_widget_realize(window); */
  /* gdk_window_get_size(window->window, &w, &h); */
  /* printf("showglyph: w=%d; h=%d\n",w,h); */
  return window;
}
-------------------------------------------------------------------------------

As you can see I have tested several places to show the widget and get the
right size ...

A typicall printout that makes me crazy looks like
	
	Message: mouse_event(): before gtk_widget_show_all()
 
	Message: mouse_event(): size_x = 1; size_y = 1
 
	Message: mouse_event(): end
 
	Message: x = 1207, y = 415, width = 1, height = 1, data = 0
 
	Message: x = 1207, y = 415, width = 136, height = 248, data = 0                 


Why did the popup resize it's right size moments after gtk_widget_show_all()?
What's wrong with this code?

Thank you
  Uwe Koloska

--
mailto:koloska@rcs.urz.tu-dresden.de
http://rcswww.urz.tu-dresden.de/~koloska/
--                                    --
right now the web page is in german only
but this will change as time goes by ;-)


--
         To unsubscribe: mail gtk-app-devel-list-request@redhat.com with
                       "unsubscribe" as the Subject.

	Mailing list concerns should be mailed to <listmaster@redhat.com>

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic