libyui-gtk  2.49.0
YGImage.cc
1 /********************************************************************
2  * YaST2-GTK - http://en.opensuse.org/YaST2-GTK *
3  ********************************************************************/
4 
5 #define YUILogComponent "gtk"
6 #include <yui/Libyui_config.h>
7 #include "ygdkmngloader.h"
8 #include "YGUI.h"
9 #include "YGWidget.h"
10 #include "YImage.h"
11 #include "ygtkimage.h"
12 #include <string.h>
13 
14 static inline bool endsWith (const std::string &str1, const char *str2)
15 {
16  size_t len = strlen (str2);
17  if (str1.size() < len) return false;
18  return str1.compare (str1.size()-len, len, str2, len) == 0;
19 }
20 
21 class YGImage : public YImage, public YGWidget
22 {
23 public:
24  YGImage (YWidget *parent, const std::string &filename, bool animated)
25  : YImage (NULL, filename, animated),
26  YGWidget (this, parent, YGTK_TYPE_IMAGE, NULL)
27  {
28  setImage( filename, animated );
29  }
30 
31  virtual void setImage( const std::string & filename, bool animated )
32  {
33  YImage::setImage ( filename, animated );
34 
35  YGtkImage *image = YGTK_IMAGE (getWidget());
36  const char *iconname = NULL;
37  if (endsWith (filename, "/msg_question.png"))
38  iconname = "dialog-question";
39  else if (endsWith (filename, "/msg_info.png"))
40  iconname = "dialog-information";
41  else if (endsWith (filename, "/msg_warning.png"))
42  iconname = "dialog-warning";
43  else if (endsWith (filename, "/msg_error.png"))
44  iconname = "dialog-error";
45 
46  if (iconname && gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default(), iconname, GTK_ICON_SIZE_DIALOG, GTK_ICON_LOOKUP_USE_BUILTIN)) {
47  GdkPixbuf *pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(), iconname, GTK_ICON_SIZE_DIALOG, GTK_ICON_LOOKUP_USE_BUILTIN,NULL);
48  ygtk_image_set_from_pixbuf (image, pixbuf);
49  }
50  else
51  ygtk_image_set_from_file (image, filename.c_str(), animated);
52  }
53 
54  virtual void setAutoScale (bool scale)
55  {
56  YGtkImageAlign align = CENTER_IMAGE_ALIGN;
57  if (scale)
58  align = SCALE_IMAGE_ALIGN;
59  ygtk_image_set_props (YGTK_IMAGE (getWidget()), align, NULL);
60  }
61 
62  YGWIDGET_IMPL_COMMON (YImage)
63 };
64 
65 YImage *YGWidgetFactory::createImage (YWidget *parent, const std::string &filename, bool animated)
66 { return new YGImage (parent, filename, animated); }
67 
YGImage
Definition: YGImage.cc:22
_YGtkImage
Definition: ygtkimage.h:41
YGWidget
Definition: YGWidget.h:14