Merged revisions 6293,6296-6306,6308 via svnmerge from
[ardour.git] / libs / gtkmm2 / gtk / src / image.ccg
1 // -*- c++ -*-
2 /* $Id: image.ccg,v 1.3 2005/07/10 19:24:22 murrayc Exp $ */
3
4 /* 
5  *
6  * Copyright 1998-2002 The gtkmm Development Team
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <gtk/gtkimage.h>
24 #include <gdkmm/image.h>
25 #include <gdkmm/bitmap.h>
26 #include <gdkmm/pixmap.h>
27
28 namespace Gtk
29 {
30
31 Image::Image(const Gtk::StockID& stock_id, IconSize size)
32 :
33   _CONSTRUCT("stock", stock_id.get_c_str(), "icon-size", (GtkIconSize) int(size))
34 {}
35
36 Image::Image(IconSet& icon_set, IconSize size)
37 :
38   _CONSTRUCT("icon-set", icon_set.gobj(), "icon-size", (GtkIconSize) int(size))
39 {}
40
41 Image::Image(const Glib::RefPtr<Gdk::PixbufAnimation>& animation)
42 :
43   _CONSTRUCT("pixbuf-animation", Glib::unwrap(animation))
44 {}
45
46 void Image::get_pixmap(Glib::RefPtr<Gdk::Pixmap>& pixmap, Glib::RefPtr<Gdk::Bitmap>& mask) const
47 {
48   GdkPixmap* pPixmap = 0;
49   GdkBitmap* pBitmap = 0;
50
51   gtk_image_get_pixmap(const_cast<GtkImage*>(gobj()), &pPixmap, &pBitmap);
52
53   pixmap = Glib::wrap((GdkPixmapObject*) pPixmap, true);
54   mask   = Glib::RefPtr<Gdk::Bitmap>::cast_dynamic(Glib::wrap((GdkPixmapObject*) pBitmap, true));
55 }
56
57 void Image::get_image(Glib::RefPtr<Gdk::Image>& gdk_image, Glib::RefPtr<Gdk::Bitmap>& mask) const
58 {
59   GdkImage* pImage = 0;
60   GdkBitmap* pBitmap = 0;
61
62   gtk_image_get_image(const_cast<GtkImage*>(gobj()), &pImage, &pBitmap);
63
64   gdk_image = Glib::wrap(pImage, true);
65   mask = Glib::RefPtr<Gdk::Bitmap>::cast_dynamic(Glib::wrap((GdkPixmapObject*) pBitmap, true));
66 }
67
68 void Image::get_stock(Gtk::StockID& stock_id, IconSize& size) const
69 {
70   char* pStockID = 0; // GTK+ iconsistency: although not const, it should not be freed.
71   GtkIconSize icon_size = GTK_ICON_SIZE_INVALID;
72
73   gtk_image_get_stock(const_cast<GtkImage*>(gobj()), &pStockID, &icon_size);
74
75   size = IconSize(static_cast<int>(icon_size));
76   stock_id = Gtk::StockID(pStockID); // the StockID ctor checks for 0
77 }
78
79 void Image::get_icon_set(IconSet& icon_set, IconSize& size) const
80 {
81   GtkIconSet* pIconSet = 0;
82   GtkIconSize icon_size = GTK_ICON_SIZE_INVALID;
83
84   gtk_image_get_icon_set(const_cast<GtkImage*>(gobj()), &pIconSet, &icon_size);
85
86   size = IconSize(static_cast<int>(icon_size));
87   icon_set = Glib::wrap(pIconSet, true); //true = take_copy.
88 }
89
90 Glib::ustring Image::get_icon_name() const
91 {
92   const gchar* pchIconName = 0;
93   gtk_image_get_icon_name(const_cast<GtkImage*>(gobj()), &pchIconName, 0);
94   return Glib::convert_const_gchar_ptr_to_ustring(pchIconName);
95 }
96
97 Glib::ustring Image::get_icon_name(IconSize& size)
98 {
99   const gchar* pchIconName = 0;
100   GtkIconSize cIconSize = GTK_ICON_SIZE_INVALID;
101   gtk_image_get_icon_name(const_cast<GtkImage*>(gobj()), &pchIconName, &cIconSize);
102   size = (IconSize)cIconSize;
103   return Glib::convert_const_gchar_ptr_to_ustring(pchIconName);
104 }
105
106 } // namespace Gtk
107