Re: Eog release (was: Re: Any Weekly Snapshot Releases Left?)



On 22 May 2002, Federico Mena Quintero wrote:

> On Wed, 2002-05-22 at 01:28, Jens Finke wrote:
> > Your patch works wonderful. The problem was (is) something with my patch I
> > am working on. It should fix the bug that the image doesn't fit into the
> > eog window on startup. Strange ... need to work on it a little bit more.
>
> Hmm, I am working on a related problem --- you can't shrink the window
> after you load an image.
>
> Could I please take a look at your patch?  I'd like to get this nailed
> down once and for good.

As you wrote in bugreport #72352, it's not a trivial problem. Also bug
#75713 depends on this patch.

But I am stuck with my patch at the moment. I've attached it to get more
eyes on it, because for now it doesn't work correctly.

My idea is to obtain the required control size through properties set by
the control (eog-window.c:adapt_shell_size_to_control). Unfourtunately we
can't rely on GTK here because there goes so much async stuff on at
startup that 99% of the time the control thinks it should be 2x2 pixels in
size if we query for it. After getting the desired size of the control I
try to calculate the needed window size and make a gtk_window_resize. This
has the advantage that the window is then completely resizable by the user
(the gtk_widget_set_size_request method which is used currently determines
also the minimum size, so the window isn't shrinkable any further).

This works all so far. The tricky part is to make the image fit into the
window (it's possible that the window remains smaller than the image if it
is larger than screensize). For this, I call Bonobo_Zoomable_zoomFit,
which doesn't work in all cases. It works better if we add an idle
function to eog_image_view_zoom_to_fit, so that the real ui_image_zoom_fit
function will be hopefully called after all the initial GTK resize stuff.

However, even if this would all work, there is yet another problem.
Somehow the "zoom to fit" function doesn't even work correctly after the
inital startup. If you zoom into an image so the scrollbars appear and do
a zoom to fit, strange things happen (big black borders and the image is
shifted somehow).

Any comments? Has anybody a better idea?


Best regards,

   Jens

-- 
 -= http://triq.net/~pearl =-   -= jens triq net =-

? diff
? eog-0.117.0
? my-fit-size-on-startup.patch
? eog-collection-build.patch
? eog-0.117.0.tar.gz
? fit-on-startup.patch
? announcements
Index: libeog/ui-image.c
===================================================================
RCS file: /cvs/gnome/eog/libeog/ui-image.c,v
retrieving revision 1.32
diff -u -p -B -r1.32 ui-image.c
--- libeog/ui-image.c	15 May 2002 02:49:59 -0000	1.32
+++ libeog/ui-image.c	23 May 2002 06:36:06 -0000
@@ -319,52 +319,3 @@ ui_image_zoom_fit (UIImage *ui)
 		priv->idle_id = g_idle_add (set_policy_idle_cb, ui);
 }
 
-/**
- * ui_image_fit_to_screen:
- * @ui: An UIImage object.
- *
- * Resizes the UIImage in that way that it shows the whole image at zoom factor
- * 1.0. If the image is larger than the screen, it will be zoomed to fit into
- * 75% of the screen width/height. The proportion will be preserved.
- **/
-void 
-ui_image_fit_to_screen (UIImage *ui)
-{
-	gint width, height;
-	gint sw, sh;
-	GdkPixbuf *pixbuf;
-
-	g_return_if_fail (ui != NULL);
-	g_return_if_fail (IS_UI_IMAGE (ui));
-
-	pixbuf = image_view_get_pixbuf (IMAGE_VIEW (ui->priv->view));
-	if (!pixbuf)
-		return;
-
-	width = gdk_pixbuf_get_width (pixbuf);
-	height = gdk_pixbuf_get_height (pixbuf);
-	g_object_unref (pixbuf);
-
-	sw = gdk_screen_width ();
-	sh = gdk_screen_height ();
-
-	if (width < 200 && height < 200)
-		width = height = 200;
-
-	if (width >= sw || height >= sh) {
-		double zoom;
-
-		if (width > height)
-			zoom = sw*0.75/width;
-		else
-			zoom = sh*0.75/height;
-
-		image_view_set_zoom (IMAGE_VIEW (ui->priv->view), 
-				     zoom, zoom);
-		image_view_get_scaled_size (IMAGE_VIEW (ui->priv->view),
-					    &width, &height);
-	}
-
-	gtk_widget_set_size_request (GTK_WIDGET (ui), width, height);
-}
-
Index: shell/eog-window.c
===================================================================
RCS file: /cvs/gnome/eog/shell/eog-window.c,v
retrieving revision 1.56
diff -u -p -B -r1.56 eog-window.c
--- shell/eog-window.c	21 May 2002 01:14:34 -0000	1.56
+++ shell/eog-window.c	23 May 2002 06:36:06 -0000
@@ -1046,6 +1046,82 @@ get_collection_control_list (GList *text
 	return control;
 }
 
+void
+adapt_shell_size_to_control (EogWindow *window, Bonobo_Control control)
+{
+	CORBA_Environment ev;
+	EogWindowPrivate *priv;
+	Bonobo_PropertyBag pb;
+	gint32 width, height;
+	int sw, sh;
+	GtkResizeMode mode;
+	Bonobo_Zoomable zi;
+	int req_width, req_height;
+	int xthick, ythick;
+
+	g_return_if_fail (EOG_IS_WINDOW (window));
+
+	CORBA_exception_init (&ev);
+	priv = window->priv;
+
+	/* calculate initial eog window size */
+	pb = bonobo_control_frame_get_control_property_bag (priv->ctrl_frame, &ev);
+	if (pb == CORBA_OBJECT_NIL) return;
+
+		
+	/* FIXME: We try to obtain the desired size of the component
+	 * here. The image/width image/height properties aren't
+	 * generally available in controls and work only with the
+	 * eog-image-viewer component!  
+	 */
+	width = bonobo_pbclient_get_long (pb, "image/width", &ev);
+	height = bonobo_pbclient_get_long (pb, "image/height", &ev);
+	
+	sw = gdk_screen_width ();
+	sh = gdk_screen_height ();
+
+	if (width >= sw)
+		width = 0.75 * sw;
+	if (height >= sh)
+		height = 0.75 * sh;
+	
+	if (!width  || !height) {
+		bonobo_object_release_unref (pb, &ev);
+		return;
+	}		
+
+	/* this is the size of the frame around the vbox */
+	xthick = priv->box->style->xthickness;
+	ythick = priv->box->style->ythickness;
+	
+	req_height = 
+		height + 
+		(GTK_WIDGET(window)->allocation.height - priv->box->allocation.height) +
+		priv->statusbar->allocation.height + 
+		2 * ythick;
+	
+	req_width = 
+		width + 
+		(GTK_WIDGET(window)->allocation.width - priv->box->allocation.width) +
+		2 * xthick;
+
+	mode = gtk_container_get_resize_mode (GTK_CONTAINER (window));
+	gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_IMMEDIATE);
+	gtk_window_resize (GTK_WINDOW (window), req_width, req_height);
+
+	zi = Bonobo_Unknown_queryInterface (control, "IDL:Bonobo/Zoomable:1.0", &ev);
+	if (zi != CORBA_OBJECT_NIL) {
+		Bonobo_Zoomable_zoomFit (zi, &ev);
+		bonobo_object_release_unref (zi, &ev);
+	}
+
+	gtk_container_set_resize_mode (GTK_CONTAINER (window), mode);
+	
+	bonobo_object_release_unref (pb, &ev);
+
+	CORBA_exception_free (&ev);
+}
+
 static void 
 add_control_to_ui (EogWindow *window, Bonobo_Control control)
 {
@@ -1062,7 +1138,7 @@ add_control_to_ui (EogWindow *window, Bo
 	
 	bonobo_control_frame_bind_to_control (priv->ctrl_frame, control, &ev);
 	widget = bonobo_control_frame_get_widget (priv->ctrl_frame);
-	
+
 	if (!widget) {
 	        g_warning ("Could not create a widget from the control!");
 		return;
@@ -1088,6 +1164,8 @@ add_control_to_ui (EogWindow *window, Bo
 	 *        the menu, so that we don't view an empty menu.
 	 */
 	bonobo_ui_component_set_prop (priv->ui_comp, "/menu/View", "hidden", "0", &ev);
+
+	adapt_shell_size_to_control (window, control);
 
 	CORBA_exception_free (&ev);
 
Index: viewer/eog-image-view.c
===================================================================
RCS file: /cvs/gnome/eog/viewer/eog-image-view.c,v
retrieving revision 1.61
diff -u -p -B -r1.61 eog-image-view.c
--- viewer/eog-image-view.c	25 Apr 2002 20:43:15 -0000	1.61
+++ viewer/eog-image-view.c	23 May 2002 06:36:07 -0000
@@ -113,8 +113,6 @@ image_set_image_cb (EogImage *eog_image,
 /*	if (image_view->priv->zoom_fit); */
 		image_view_set_pixbuf (image_view->priv->image_view, pixbuf);
 		g_object_unref (pixbuf);
-
-		ui_image_fit_to_screen (UI_IMAGE (image_view->priv->ui_image));
 	}
 }
 
@@ -1715,6 +1713,17 @@ eog_image_view_set_zoom (EogImageView *i
 	image_view_set_zoom (image_view->priv->image_view, zoomx, zoomy);
 }
 
+static gboolean
+call_zoom_fit (gpointer data)
+{
+	UIImage *ui_image;
+
+	ui_image = UI_IMAGE (data);
+	ui_image_zoom_fit (ui_image);
+
+	return FALSE;
+}
+
 void
 eog_image_view_zoom_to_fit (EogImageView *image_view,
 			    gboolean      keep_aspect_ratio)
@@ -1722,7 +1731,7 @@ eog_image_view_zoom_to_fit (EogImageView
 	g_return_if_fail (image_view != NULL);
 	g_return_if_fail (EOG_IS_IMAGE_VIEW (image_view));
 
-	ui_image_zoom_fit (UI_IMAGE (image_view->priv->ui_image));
+	g_idle_add (call_zoom_fit, image_view->priv->ui_image);
 }
 
 static void


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