Auto-pick window size and general geometry management



So I was trying to implement the feature in the Eye of Gnome image
viewer where it picks the window size and zoom factor automatically
based on the image size.  I have the following widget hierarchy:

	GnomeApp
		GtkScrollFrame (GtkScrolledWindow hacked to draw its
		own internal frame)
			ImageView (my own core viewing widget)

Normally the ImageView widget returns a size requisition equal to the
image size multiplied by the current zoom factor.  That doesn't work
as intended here, however, because GtkScrollFrame (or
GtkScrolledWindow, for that matter) does not pay attention at all to
the child's size requisition unless either the child has its usize
set, or the scrollbar policy is NEVER.  I'm using a policy of
AUTOMATIC, though.

So I tried setting the usize of the ImageView to whatever EOG
considered a reasonable size.  With this, however, the effect is that
the toplevel window gets (almost) the correct size but then it cannot
be shrunk by the user with the window manager.

So I set the window policy to allow_shrink, but then it comes up with
some default small useless window size.

So I'm stumped.

Maybe this is just GtkScrolledWindow's usual suckage, but this does
indicate a problem in the way we handle geometry management.  Things
should not be this hard.

Suggestions?  Do I really have to do the GIMP's evil thing where it
does this:

      gdisp->disp_width  = width;
      gdisp->disp_height = height;

      allocation.width  = width  + border_x;
      allocation.height = height + border_y;

      /*  don't call gdisplay_canvas_events() on any of the following
       *  changes because our caller has to do a full display update anyway
       */
      gtk_signal_handler_block_by_data (GTK_OBJECT (gdisp->canvas), gdisp);

      gtk_widget_size_allocate (gdisp->shell, &allocation);

      gdk_window_resize (gdisp->shell->window,
			 allocation.width,
			 allocation.height);

      /*  let Gtk/X/WM position the window  */
      while (gtk_events_pending ())
	gtk_main_iteration ();

      gdk_window_get_origin (gdisp->shell->window, &shell_x, &shell_y);

      /*  if the window is offscreen, center it...  */
      if (shell_x > s_width || shell_y > s_height ||
	  (shell_x + width +  border_x) < 0 || (shell_y + height + border_y) < 0)
	{
	  shell_x = (s_width  - width  - border_x) >> 1;
	  shell_y = (s_height - height - border_y) >> 1;

	  gdk_window_move (gdisp->shell->window, shell_x, shell_y);
	}

      gtk_signal_handler_unblock_by_data (GTK_OBJECT (gdisp->canvas), gdisp);

I really would prefer not to move the Gdk window by hand or
size_allocate things explicitly.

  Federico




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