2
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; version 2 of the
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19
#ifndef _LF_IMAGEBOX_H_
20
#define _LF_IMAGEBOX_H_
22
#include "mforms/label.h"
25
#include "mforms/app.h"
30
class ImageBoxImpl : public ViewImpl
33
mutable Gtk::Image _image;
35
virtual Gtk::Widget *get_outer() const { return &_image; }
37
ImageBoxImpl(::mforms::ImageBox *self)
40
//_image = Gtk::manage(new Gtk::Image());
41
_image.set_alignment(0, 0.5);
43
_image.signal_realize().connect(sigc::mem_fun(this, &ImageBoxImpl::on_realize));
54
_image.get_size_request(w, h);
57
Glib::RefPtr<Gdk::Pixbuf> pb= _image.get_pixbuf();
61
ratio = (double)iw/ih;
63
pb= pb->scale_simple(h*ratio, h, Gdk::INTERP_BILINEAR);
65
pb= pb->scale_simple(w, w/ratio, Gdk::INTERP_BILINEAR);
67
pb= pb->scale_simple(h/ratio, h, Gdk::INTERP_BILINEAR);
69
pb= pb->scale_simple(w, w/ratio, Gdk::INTERP_BILINEAR);
75
static bool create(::mforms::ImageBox *self)
77
return new ImageBoxImpl(self) != 0;
80
static void set_image(::mforms::ImageBox *self, const std::string &file)
82
ImageBoxImpl* image = self->get_data<ImageBoxImpl>();
85
image->_image.set(mforms::App::get()->get_resource_path(file));
88
static void set_scale_contents(::mforms::ImageBox *self, bool flag)
90
ImageBoxImpl* image = self->get_data<ImageBoxImpl>();
101
static void set_image_align(::mforms::ImageBox *self, ::mforms::Alignment alignment)
103
ImageBoxImpl* image = self->get_data<ImageBoxImpl>();
109
case mforms::BottomLeft:
110
image->_image.set_alignment(0.0, 1.0);
112
case mforms::MiddleLeft:
113
image->_image.set_alignment(0.0, 0.5);
115
case mforms::TopLeft:
116
image->_image.set_alignment(0.0, 0.0);
118
case mforms::BottomCenter:
119
image->_image.set_alignment(0.5, 1.0);
121
case mforms::TopCenter:
122
image->_image.set_alignment(0.5, 0.0);
124
case mforms::MiddleCenter:
125
image->_image.set_alignment(0.5, 0.5);
127
case mforms::BottomRight:
128
image->_image.set_alignment(1.0, 1.0);
130
case mforms::MiddleRight:
131
image->_image.set_alignment(1.0, 0.5);
133
case mforms::TopRight:
134
image->_image.set_alignment(1.0, 0.0);
136
case mforms::WizardLabelAlignment:
145
::mforms::ControlFactory *f = ::mforms::ControlFactory::get_instance();
147
f->_imagebox_impl.create = &ImageBoxImpl::create;
148
f->_imagebox_impl.set_image = &ImageBoxImpl::set_image;
149
f->_imagebox_impl.set_scale_contents = &ImageBoxImpl::set_scale_contents;
150
f->_imagebox_impl.set_image_align = &ImageBoxImpl::set_image_align;
158
#endif /* _LF_IMAGEBOX_H_ */