[yast-commit] r42682 - in /trunk/gtk/unstable: ChangeLog src/Makefile.am src/YGImage.cc src/ygdkmngloader.c tests/ImageMng.ycp
Author: rpmcruz Date: Tue Dec 4 22:57:38 2007 New Revision: 42682 URL: http://svn.opensuse.org/viewcvs/yast?rev=42682&view=rev Log: * src/ygtkimage.h/c: moved YGImage stuff to an actual widget impl. Added dim/gray when disabled as asked by bug #345506. Used the same code as gtk -- done at expose-time, using style engine. * src/YGImage.cc: according changes. Much smaller, of course. * tests/ImageMng.ycp: added Enable option, to test this. Very cool. * src/ygdkmngloader.c: bug fix: when fopen() fails, it returns null, so don't call fclose() on null, on error case. Modified: trunk/gtk/unstable/ChangeLog trunk/gtk/unstable/src/Makefile.am trunk/gtk/unstable/src/YGImage.cc trunk/gtk/unstable/src/ygdkmngloader.c trunk/gtk/unstable/tests/ImageMng.ycp Modified: trunk/gtk/unstable/ChangeLog URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/unstable/ChangeLog?rev=42682&r1=42681&r2=42682&view=diff ============================================================================== --- trunk/gtk/unstable/ChangeLog (original) +++ trunk/gtk/unstable/ChangeLog Tue Dec 4 22:57:38 2007 @@ -1,3 +1,15 @@ +2007-12-04 Ricardo Cruz <rpmcruz@alunos.dcc.fc.up.pt> + + * src/ygtkimage.h/c: moved YGImage stuff to an actual widget impl. Added + dim/gray when disabled as asked by bug #345506. Used the same code as gtk + -- done at expose-time, using style engine. + * src/YGImage.cc: according changes. Much smaller, of course. + + * tests/ImageMng.ycp: added Enable option, to test this. Very cool. + + * src/ygdkmngloader.c: bug fix: when fopen() fails, it returns null, so don't + call fclose() on null, on error case. + 2007-12-03 Ricardo Cruz <rpmcruz@alunos.dcc.fc.up.pt> * src/ygtkwizard.c: set label title centered (visible on our Package Selector Modified: trunk/gtk/unstable/src/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/unstable/src/Makefile.am?rev=42682&r1=42681&r2=42682&view=diff ============================================================================== --- trunk/gtk/unstable/src/Makefile.am (original) +++ trunk/gtk/unstable/src/Makefile.am Tue Dec 4 22:57:38 2007 @@ -48,6 +48,7 @@ ygtkwizard.c \ ygtkfindentry.c \ ygdkmngloader.c \ + ygtkimage.c \ ygtkhtmlwrap.c \ ygtkrichtext.c \ yzyppwrapper.cc \ Modified: trunk/gtk/unstable/src/YGImage.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/unstable/src/YGImage.cc?rev=42682&r1=42681&r2=42682&view=diff ============================================================================== --- trunk/gtk/unstable/src/YGImage.cc (original) +++ trunk/gtk/unstable/src/YGImage.cc Tue Dec 4 22:57:38 2007 @@ -5,266 +5,57 @@ #include "ygdkmngloader.h" #include <config.h> #include <ycp/y2log.h> -#include <YGUI.h> -#include "YEvent.h" +#include "YGUI.h" #include "YGWidget.h" #include "YImage.h" +#include "ygtkimage.h" class YGImage : public YImage, public YGWidget { - bool m_hasZeroWidth, m_hasZeroHeight, m_isScaled, m_isTiled, m_isAnimation; - bool m_imageLoaded; - - struct Animation { - GdkPixbufAnimation *pixbuf; - GdkPixbufAnimationIter *frame; - guint timeout_id; - }; - union { - GdkPixbuf *m_pixbuf; - Animation *m_animation; - }; - gchar *alt_text; - - void initOptions (const YWidgetOpt &opt) + void setProps (const YWidgetOpt &opt, const YCPString &alt_text) { - IMPL - m_imageLoaded = false; - m_hasZeroWidth = opt.zeroWidth.value(); - m_hasZeroHeight = opt.zeroHeight.value(); - m_isAnimation = opt.animated.value(); - m_isScaled = opt.scaleToFit.value(); - m_isTiled = opt.tiled.value(); + bool scale = opt.scaleToFit.value(), tile = opt.tiled.value(); + YGtkImageAlign align = CENTER_IMAGE_ALIGN; + if (tile) + align = TILE_IMAGE_ALIGN; + if (scale) + align = SCALE_IMAGE_ALIGN; + if (scale && tile) + y2warning ("YImage can't be scaled and tiled at the same time"); + ygtk_image_set_props (YGTK_IMAGE (getWidget()), align, alt_text->value_cstr()); - if (m_hasZeroWidth || m_isScaled || m_isTiled) + bool zeroWidth = opt.zeroWidth.value(), zeroHeight = opt.zeroHeight.value(); + if (zeroWidth || scale || tile) setStretchable (YD_HORIZ, true); - if (m_hasZeroHeight || m_isScaled || m_isTiled) + if (zeroHeight || scale || tile) setStretchable (YD_VERT, true); - - if (m_isScaled && m_isTiled) { - y2warning ("YImage can't be scaled and tiled at the same time"); - m_isTiled = false; - } - - if (m_isAnimation) - m_animation = NULL; - else - m_pixbuf = NULL; - - g_signal_connect (G_OBJECT (getWidget()), "expose-event", - G_CALLBACK (expose_event_cb), this); - gtk_widget_queue_draw (getWidget()); - } - - void loadImage (GdkPixbuf *pixbuf, const char *error_msg) - { - IMPL - if (pixbuf == NULL) { - g_warning ("Couldn't load image - %s", error_msg); - return; - } - - m_imageLoaded = true; - m_pixbuf = pixbuf; - gtk_widget_set_size_request (getWidget(), m_hasZeroWidth ? -1 : gdk_pixbuf_get_width (pixbuf), - m_hasZeroHeight ? -1 : gdk_pixbuf_get_height (pixbuf)); - } - - void loadAnimation (GdkPixbufAnimation *pixbuf, const char *error_msg) - { - IMPL - if (pixbuf == NULL) { - g_warning ("Couldn't load animation - %s", error_msg); - return; - } - - m_imageLoaded = true; - m_animation = new Animation; - m_animation->pixbuf = pixbuf; - - m_animation->frame = NULL; - advance_frame_cb (this); - - g_signal_connect (G_OBJECT (getWidget()), "expose-event", - G_CALLBACK (expose_event_cb), this); - gtk_widget_queue_draw (getWidget()); + gtk_widget_set_size_request (getWidget(), zeroWidth ? 1 : -1, zeroHeight ? 1 : -1); } public: YGImage (const YWidgetOpt &opt, YGWidget *parent, const YCPString &filename_str, const YCPString &text) : YImage (opt), - YGWidget (this, parent, true, GTK_TYPE_DRAWING_AREA, NULL) + YGWidget (this, parent, true, YGTK_TYPE_IMAGE, NULL) { IMPL - alt_text = g_strdup (text->value_cstr()); - initOptions (opt); - + setProps (opt, text); const char *filename = filename_str->value_cstr(); - GError *error = 0; - if (m_isAnimation) { - GdkPixbufAnimation *pixbuf; - if (ygdk_mng_pixbuf_is_file_mng (filename)) - pixbuf = ygdk_mng_pixbuf_new_from_file (filename, &error); - else - pixbuf = gdk_pixbuf_animation_new_from_file (filename, &error); - loadAnimation (pixbuf, error ? error->message : "(undefined)"); - } - else { - GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (filename, &error); - loadImage (pixbuf, error ? error->message : "(undefined)"); - } + bool animated = opt.animated.value(); + ygtk_image_set_from_file (YGTK_IMAGE (getWidget()), filename, animated); } YGImage (const YWidgetOpt &opt, YGWidget *parent, const YCPByteblock &byteblock, const YCPString &text) : YImage (opt), - YGWidget (this, parent, true, GTK_TYPE_DRAWING_AREA, NULL) - { - IMPL - alt_text = g_strdup (text->value_cstr()); - initOptions (opt); - - GError *error = 0; - if (m_isAnimation && ygdk_mng_pixbuf_is_data_mng (byteblock->value(), byteblock->size())) - { - GdkPixbufAnimation *pixbuf; - pixbuf = ygdk_mng_pixbuf_new_from_data (byteblock->value(), byteblock->size(), &error); - loadAnimation (pixbuf, error ? error->message : "(undefined)"); - } - else - { - GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); - g_signal_connect (G_OBJECT (loader), "area-prepared", - G_CALLBACK (image_loaded_cb), this); - - if (!gdk_pixbuf_loader_write (loader, - byteblock->value(), byteblock->size(), &error)) - g_warning ("Could not load image from data blocks: %s", error->message); - gdk_pixbuf_loader_close (loader, &error); - } - } - - virtual ~YGImage() - { - IMPL - if (m_imageLoaded) { - if (m_isAnimation) { - g_object_unref (G_OBJECT (m_animation->pixbuf)); - if (m_animation->timeout_id) - g_source_remove (m_animation->timeout_id); - delete m_animation; - } - else - g_object_unref (G_OBJECT (m_pixbuf)); - } - g_free (alt_text); - } - - // callback for image loading - static void image_loaded_cb (GdkPixbufLoader *loader, YGImage *pThis) - { - IMPL - if (pThis->m_isAnimation) { - if (pThis->m_animation) { - // a new frame loaded -- just redraw the widget - if (gdk_pixbuf_animation_iter_on_currently_loading_frame - (pThis->m_animation->frame)) - gtk_widget_queue_draw (pThis->getWidget()); - } - else { - GdkPixbufAnimation *pixbuf = gdk_pixbuf_loader_get_animation (loader); - g_object_ref (G_OBJECT (pixbuf)); - pThis->loadAnimation (pixbuf, " on block data reading callback"); - } - } - else { - GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); - g_object_ref (G_OBJECT (pixbuf)); - pThis->loadImage (pixbuf, " on block data reading callback"); - } - } - - // callback for image displaying - static gboolean advance_frame_cb (void *pData) - { - IMPL - YGImage *pThis = (YGImage *) pData; - Animation *animation = pThis->m_animation; - - if (!animation->frame) // no frame yet loaded - animation->frame = gdk_pixbuf_animation_get_iter (animation->pixbuf, NULL); - else - if (gdk_pixbuf_animation_iter_advance (animation->frame, NULL)) - gtk_widget_queue_draw (pThis->getWidget()); - - // shedule next frame - int delay = gdk_pixbuf_animation_iter_get_delay_time (animation->frame); - if (delay != -1) - animation->timeout_id = g_timeout_add (delay, advance_frame_cb, pThis); - - GdkPixbuf *pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (pThis->m_animation->frame); - gtk_widget_set_size_request (pThis->getWidget(), gdk_pixbuf_get_width (pixbuf), - gdk_pixbuf_get_height (pixbuf)); - return FALSE; - } - - static gboolean expose_event_cb (GtkWidget *widget, GdkEventExpose *event, - YGImage *pThis) + YGWidget (this, parent, true, YGTK_TYPE_IMAGE, NULL) { IMPL - int x, y, width, height; - x = widget->allocation.x + 6; - y = widget->allocation.y + 6; - width = widget->allocation.width; - height = widget->allocation.height; - - cairo_t *cr = gdk_cairo_create (widget->window); - - if (!pThis->m_imageLoaded) { - // show default text if no image was loaded - PangoLayout *layout; - layout = gtk_widget_create_pango_layout (widget, pThis->alt_text); - - int text_width, text_height; - pango_layout_get_size (layout, &text_width, &text_height); - text_width /= PANGO_SCALE; - text_height /= PANGO_SCALE; - - x += (width - text_width) / 2; - y += (height - text_height) / 2; - - cairo_move_to (cr, x, y); - pango_cairo_show_layout (cr, layout); - - g_object_unref (layout); - cairo_destroy (cr); - return TRUE; - } - - GdkPixbuf *pixbuf; - if (pThis->m_isAnimation) - pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (pThis->m_animation->frame); - else - pixbuf = pThis->m_pixbuf; - gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); - - if (pThis->m_isTiled) - cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT); - - if (pThis->m_isScaled) { - double scale_x = (double) gdk_pixbuf_get_width (pixbuf) / width; - double scale_y = (double) gdk_pixbuf_get_height (pixbuf) / height; - cairo_matrix_t matrix; - cairo_matrix_init_scale (&matrix, scale_x, scale_y); - cairo_pattern_set_matrix (cairo_get_source (cr), &matrix); - } - - cairo_rectangle (cr, 0, 0, width, height); - cairo_fill (cr); - - cairo_destroy (cr); - return TRUE; + setProps (opt, text); + const guint8 *data = byteblock->value(); + long data_size = byteblock->size(); + bool animated = opt.animated.value(); + ygtk_image_set_from_data (YGTK_IMAGE (getWidget()), data, data_size, animated); } YGWIDGET_IMPL_COMMON Modified: trunk/gtk/unstable/src/ygdkmngloader.c URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/unstable/src/ygdkmngloader.c?rev=42682&r1=42681&r2=42682&view=diff ============================================================================== --- trunk/gtk/unstable/src/ygdkmngloader.c (original) +++ trunk/gtk/unstable/src/ygdkmngloader.c Tue Dec 4 22:57:38 2007 @@ -113,7 +113,8 @@ return ret; is_file_mng_failed: - fclose (file); + if (file) + fclose (file); return FALSE; } Modified: trunk/gtk/unstable/tests/ImageMng.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/unstable/tests/ImageMng.ycp?rev=42682&r1=42681&r2=42682&view=diff ============================================================================== --- trunk/gtk/unstable/tests/ImageMng.ycp (original) +++ trunk/gtk/unstable/tests/ImageMng.ycp Tue Dec 4 22:57:38 2007 @@ -4,35 +4,42 @@ { UI::OpenDialog ( `VBox ( + `Heading ("Movie"), `ReplacePoint (`id (`replace_image), - `ColoredLabel ("Choose an image first!", `rgb (0, 0, 0), - `rgb (255, 0, 0), 5) + `ColoredLabel (`opt(`hstretch, `vstretch), "Pick an image!", + `rgb (0, 0, 0), `rgb (255, 0, 0), 5) ), - `Frame ("Which MNG file:", - `RadioButtonGroup (`id(`rb), - `VBox( - `Left (`RadioButton(`id (`movie1), `opt(`notify), "&Movie1")), - `Left (`RadioButton(`id (`movie2), `opt(`notify), "&Movie2")), - `Left (`RadioButton(`id (`movie3), `opt(`notify), "&Movie3")), - `Left (`RadioButton(`id (`movie4), `opt(`notify), "&Movie4")), - `Left (`RadioButton(`id (`movie5), `opt(`notify), "&Movie5")), - `Left (`RadioButton(`id (`movie6), `opt(`notify), "&Movie6")), - `Left (`RadioButton(`id (`movie7), `opt(`notify), "&Movie7")), - `Left (`RadioButton(`id (`movie8), `opt(`notify), "&Movie8")) + `VSquash (`HBox ( + `Top (`Frame ("Which MNG file:", + `RadioButtonGroup (`id(`rb), + `VBox( + `Left (`RadioButton(`id (`movie1), `opt(`notify), "&Movie1")), + `Left (`RadioButton(`id (`movie2), `opt(`notify), "&Movie2")), + `Left (`RadioButton(`id (`movie3), `opt(`notify), "&Movie3")), + `Left (`RadioButton(`id (`movie4), `opt(`notify), "&Movie4")), + `Left (`RadioButton(`id (`movie5), `opt(`notify), "&Movie5")), + `Left (`RadioButton(`id (`movie6), `opt(`notify), "&Movie6")), + `Left (`RadioButton(`id (`movie7), `opt(`notify), "&Movie7")), + `Left (`RadioButton(`id (`movie8), `opt(`notify), "&Movie8")) + ) ) - ) - ), + )), + + `Top (`VBox ( + `Frame ("Image effect:", + `RadioButtonGroup (`id(`rb), + `VBox( + `Left (`RadioButton(`id (`no_effect), `opt(`notify), "&None", true)), + `Left (`RadioButton(`id (`tiled_effect),`opt(`notify), "&Tiled")), + `Left (`RadioButton(`id (`scaled_effect), `opt(`notify), "&Scaled")) + ) + ) + ), + `Left (`CheckBox(`id (`enabled), `opt(`notify), "&Enabled", true)) + )) + )), - `Frame ("Image effect:", - `RadioButtonGroup (`id(`rb), - `VBox( - `Left (`RadioButton(`id (`no_effect), `opt(`notify), "&None", true)), - `Left (`RadioButton(`id (`tiled_effect),`opt(`notify), "&Tiled")), - `Left (`RadioButton(`id (`scaled_effect), `opt(`notify), "&Scaled")) - ) - ) - ), `Right (`Label ("Resize the window!")), `PushButton(`id (`close), "&Close") ) @@ -77,13 +84,18 @@ else filename = "tests/movie8.mng"; + any enabled_opt = nil; + boolean check = (boolean) UI::QueryWidget(`enabled, `Value); + if (!check) + enabled_opt = `disabled; + // to test inline images, uncomment next line and pass it to `Image //byteblock data = (byteblock) SCR::Read (.target.byte, filename); + term image = `Image (`id (`image), + `opt (`animated, effect_opt, enabled_opt, `hstretch, `vstretch), + filename, filename + " not found"); - UI::ReplaceWidget (`replace_image, - `Image (`opt (`animated, effect_opt, zerowidth, zeroheight), - filename, filename + " not found")); - + UI::ReplaceWidget (`replace_image, image); } UI::CloseDialog(); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
rpmcruz@svn.opensuse.org