Re: Foobar patch
- From: Chris Phelps <chicane reninet com>
- To: gnome-2-0-list gnome org
- Cc: Havoc Pennington <hp redhat com>
- Subject: Re: Foobar patch
- Date: 11 Dec 2001 16:38:46 -0800
/me reads manual and re-submits...
Later,
Chris
On Tue, 2001-12-11 at 14:33, Havoc Pennington wrote:
>
> Chris Phelps <chicane reninet com> writes:
> > there might be some balking on #1 due to its
> > usage of usize (since it is deprecated and all...),
>
> Things that are deprecated are either a bad idea to use, or have a
> replacement. So you shouldn't use them. ;-) That's the idea of
> deprecation.
>
> Oddly enough the replacement for set_usize() is documented:
>
> http://developer.gnome.org/doc/API/2.0/gtk/gtkwidget.html#GTK-WIDGET-SET-USIZE
>
> (Thanks to some cool people like Matthias Clasen, 85% of GTK functions
> are documented, and most of what isn't is stuff you probably don't care about...)
>
> > and the possibility
> > of the label needing to change size if the font
> > is changed.
>
> > + width = > gdk_string_width(foo->clock_label->style->private_font, hour);
>
> Eeeeaaggghh garrrghh - you're using broken/deprecated API _and_ a
> private struct field that _has private in the name_. Dude.
>
> Anyway, it's private because it is not guaranteed to be non-NULL. Plus
> gdk_string_width() does _not_ give accurate results for the width of a
> PangoLayout, which is why it's deprecated.
>
> /me hands Chris the manual:
> http://developer.gnome.org/doc/API/2.0/gtk/gtkstyle.html#GTK-STYLE-GET-FONT
> http://developer.gnome.org/doc/API/2.0/pango/pango-layout-objects.html#PANGO-LAYOUT-GET-PIXEL-SIZE
> http://developer.gnome.org/doc/API/2.0/gtk/gtkwidget.html#GTK-WIDGET-CREATE-PANGO-LAYOUT
> http://developer.gnome.org/dotplan/porting/ar01s10.html
>
> Havoc
--
http://glimmer.sourceforge.net - My pet project
http://uberhackers.dhs.org - My personal website
./configure --prefix=/dev/mocha --enable-caffeine
--- foobar-widget.c Tue Dec 11 14:57:14 2001
+++ foobar-widget-hacked.c Tue Dec 11 16:35:32 2001
@@ -520,4 +520,20 @@
foo->clock_format = g_strdup (clock_format);
+ if(foo->clock_label) {
+ time_t das_time;
+ struct tm *das_tm;
+ char hour[256];
+ int width;
+ PangoLayout *layout;
+
+ das_time = 0;
+ das_tm = localtime (&das_time);
+ strftime(hour, sizeof(hour), _(clock_format), das_tm);
+ layout = gtk_widget_create_pango_layout (foo->clock_label, hour);
+ pango_layout_get_pixel_size (layout, &width, NULL);
+ width += 8; /* Padding */
+ gtk_widget_set_size_request (foo->clock_label, width, 0);
+ g_object_unref (G_OBJECT(layout));
+ }
update_clock (foo);
}
@@ -672,4 +688,16 @@
pb = get_default_image ();
if (pb != NULL) {
+ double pix_x, pix_y;
+ pix_x = gdk_pixbuf_get_width (pb);
+ pix_y = gdk_pixbuf_get_height (pb);
+ if (pix_x > ICON_SIZE || pix_y > ICON_SIZE) {
+ double greatest;
+
+ greatest = pix_x > pix_y ? pix_x : pix_y;
+ pb = gdk_pixbuf_scale_simple (pb,
+ (ICON_SIZE / greatest) * pix_x,
+ (ICON_SIZE / greatest) * pix_y,
+ GDK_INTERP_BILINEAR);
+ }
image = gtk_image_new_from_pixbuf (pb);
gtk_widget_show (image);
@@ -772,4 +800,16 @@
if (pb != NULL) {
+ double pix_x, pix_y;
+ pix_x = gdk_pixbuf_get_width (pb);
+ pix_y = gdk_pixbuf_get_height (pb);
+ if (pix_x > ICON_SIZE || pix_y > ICON_SIZE) {
+ double greatest;
+
+ greatest = pix_x > pix_y ? pix_x : pix_y;
+ pb = gdk_pixbuf_scale_simple (pb,
+ (ICON_SIZE / greatest) * pix_x,
+ (ICON_SIZE / greatest) * pix_y,
+ GDK_INTERP_BILINEAR);
+ }
foo->task_image = gtk_image_new_from_pixbuf (pb);
gtk_widget_show (foo->task_image);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]