~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to library/forms/gtk/lf_imagebox.h

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
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
 
7
 * License.
 
8
 * 
 
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.
 
13
 * 
 
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
 
17
 * 02110-1301  USA
 
18
 */
 
19
#ifndef _LF_IMAGEBOX_H_
 
20
#define _LF_IMAGEBOX_H_
 
21
 
 
22
#include "mforms/label.h"
 
23
 
 
24
#include "lf_view.h"
 
25
#include "mforms/app.h"
 
26
 
 
27
namespace mforms {
 
28
namespace gtk {
 
29
 
 
30
class ImageBoxImpl : public ViewImpl
 
31
{
 
32
protected:
 
33
  mutable Gtk::Image _image;
 
34
  bool _scale;
 
35
  virtual Gtk::Widget *get_outer() const { return &_image; }
 
36
 
 
37
  ImageBoxImpl(::mforms::ImageBox *self)
 
38
    : ViewImpl(self)
 
39
  {
 
40
    //_image = Gtk::manage(new Gtk::Image());
 
41
    _image.set_alignment(0, 0.5);
 
42
    _scale= false;
 
43
    _image.signal_realize().connect(sigc::mem_fun(this, &ImageBoxImpl::on_realize));
 
44
 
 
45
    setup();
 
46
  }
 
47
 
 
48
  void on_realize()
 
49
  {
 
50
    if (_scale)
 
51
    {
 
52
      int w, h;
 
53
      int iw, ih;
 
54
      _image.get_size_request(w, h);
 
55
      if (w > 0 || h > 0)
 
56
      {
 
57
        Glib::RefPtr<Gdk::Pixbuf> pb= _image.get_pixbuf();
 
58
        double ratio;
 
59
        iw= pb->get_width();
 
60
        ih= pb->get_height();
 
61
        ratio = (double)iw/ih;
 
62
        if (w < 0)
 
63
          pb= pb->scale_simple(h*ratio, h, Gdk::INTERP_BILINEAR);
 
64
        else if (h < 0)
 
65
          pb= pb->scale_simple(w, w/ratio, Gdk::INTERP_BILINEAR);
 
66
        else if (w > h)
 
67
          pb= pb->scale_simple(h/ratio, h, Gdk::INTERP_BILINEAR);
 
68
        else
 
69
          pb= pb->scale_simple(w, w/ratio, Gdk::INTERP_BILINEAR);
 
70
        _image.set(pb);
 
71
      }
 
72
    }
 
73
  }
 
74
 
 
75
  static bool create(::mforms::ImageBox *self)
 
76
  {
 
77
    return new ImageBoxImpl(self) != 0;
 
78
  }
 
79
 
 
80
  static void set_image(::mforms::ImageBox *self, const std::string &file)
 
81
  {
 
82
    ImageBoxImpl* image = self->get_data<ImageBoxImpl>();
 
83
 
 
84
    if (image)
 
85
      image->_image.set(mforms::App::get()->get_resource_path(file));
 
86
  }
 
87
 
 
88
  static void set_scale_contents(::mforms::ImageBox *self, bool flag)
 
89
  {
 
90
    ImageBoxImpl* image = self->get_data<ImageBoxImpl>();
 
91
 
 
92
    if (image)
 
93
    {
 
94
      image->_scale= flag;
 
95
      if (flag)
 
96
      {
 
97
      }
 
98
    }
 
99
  }
 
100
 
 
101
  static void set_image_align(::mforms::ImageBox *self, ::mforms::Alignment alignment)
 
102
  {
 
103
    ImageBoxImpl* image = self->get_data<ImageBoxImpl>();
 
104
 
 
105
    if (image)
 
106
    {
 
107
      switch (alignment)
 
108
      {
 
109
      case mforms::BottomLeft:
 
110
        image->_image.set_alignment(0.0, 1.0);
 
111
        break;
 
112
      case mforms::MiddleLeft:
 
113
        image->_image.set_alignment(0.0, 0.5);
 
114
        break;
 
115
      case mforms::TopLeft:
 
116
        image->_image.set_alignment(0.0, 0.0);
 
117
        break;
 
118
      case mforms::BottomCenter:
 
119
        image->_image.set_alignment(0.5, 1.0);
 
120
        break;
 
121
      case mforms::TopCenter:
 
122
        image->_image.set_alignment(0.5, 0.0);
 
123
        break;
 
124
      case mforms::MiddleCenter:
 
125
        image->_image.set_alignment(0.5, 0.5);
 
126
        break;
 
127
      case mforms::BottomRight:
 
128
        image->_image.set_alignment(1.0, 1.0);
 
129
        break;
 
130
      case mforms::MiddleRight:
 
131
        image->_image.set_alignment(1.0, 0.5);
 
132
        break;
 
133
      case mforms::TopRight:
 
134
        image->_image.set_alignment(1.0, 0.0);
 
135
        break;
 
136
      case mforms::WizardLabelAlignment:
 
137
        break;
 
138
      }
 
139
    }
 
140
  }
 
141
 
 
142
 public:
 
143
  static void init()
 
144
  {
 
145
    ::mforms::ControlFactory *f = ::mforms::ControlFactory::get_instance();
 
146
 
 
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;
 
151
  }
 
152
};
 
153
 
 
154
};
 
155
};
 
156
 
 
157
 
 
158
#endif /* _LF_IMAGEBOX_H_ */