Commit 7007f055 authored by Murray Cumming's avatar Murray Cumming Committed by Murray Cumming
Browse files

Overried on_expose_event() so we can scale the image when we actually have

2006-02-19  Murray Cumming  <murrayc@murrayc.com>

        * glom/utility_widgets/imageglom.cc:
        * glom/utility_widgets/imageglom.h: Overried on_expose_event() so we can
        scale the image when we actually have a real (>1) allocation.
        scale(): Do not call set_image() if the scaled pixbuf has exactly the same
        dimensions as the existing image. And do not try to scale the image if the
        allocation is very small, because this will generally fail. This fixes the
        disappearing image problem.
parent b66707a5
2006-02-19 Murray Cumming <murrayc@murrayc.com>
* glom/utility_widgets/imageglom.cc:
* glom/utility_widgets/imageglom.h: Overried on_expose_event() so we can
scale the image when we actually have a real (>1) allocation.
scale(): Do not call set_image() if the scaled pixbuf has exactly the same
dimensions as the existing image. And do not try to scale the image if the
allocation is very small, because this will generally fail. This fixes the
disappearing image problem.
2006-02-18 Murray Cumming <murrayc@murrayc.com>
* glom/data_structure/relationship.cc:
......
......@@ -7,6 +7,7 @@
appropriate. This is often the case for related fields.
* Save Field Layout Properties when the dialog closes. (Fixes a regression)
* Avoid python warnings when adding new records.
* Stop images from disappearing when refreshing layouts.
0.9.5:
......
......@@ -118,7 +118,7 @@ bool ImageGlom::get_has_original_data() const
}
void ImageGlom::set_value(const Gnome::Gda::Value& value)
{
{
bool pixbuf_set = false;
if(value.get_value_type() == Gnome::Gda::VALUE_TYPE_BINARY)
......@@ -151,6 +151,8 @@ void ImageGlom::set_value(const Gnome::Gda::Value& value)
GdkPixbufLoader* loader = gdk_pixbuf_loader_new_with_type(GLOM_IMAGE_FORMAT, &error);
if(!error)
refPixbufLoader = Glib::wrap(loader);
else
std::cerr << "ImageGlom::set_value(): Error while calling gdk_pixbuf_loader_new_with_type()." << std::endl;
/*
try
......@@ -245,6 +247,13 @@ Gnome::Gda::Value ImageGlom::get_value() const
return result;
}
bool ImageGlom::on_expose_event(GdkEventExpose* event)
{
const bool result = Gtk::EventBox::on_expose_event(event);
scale();
return result;
}
void ImageGlom::scale()
{
Glib::RefPtr<Gdk::Pixbuf> pixbuf = m_pixbuf_original;
......@@ -258,8 +267,21 @@ void ImageGlom::scale()
if( (pixbuf_height > allocation.get_height()) ||
(pixbuf_width > allocation.get_width()) )
{
Glib::RefPtr<Gdk::Pixbuf> pixbuf_scaled = scale_keeping_ratio(pixbuf, allocation.get_height(), allocation.get_width());
m_image.set(pixbuf_scaled);
if(allocation.get_height() > 10 || allocation.get_width() > 10)
{
Glib::RefPtr<Gdk::Pixbuf> pixbuf_scaled = scale_keeping_ratio(pixbuf, allocation.get_height(), allocation.get_width());
if(!pixbuf_scaled)
{
std::cerr << "ImageGlom::scale(): scale_keeping_ratio() returned NULL pixbuf." << std::endl;
}
else
{
//Don't set a new pixbuf if the dimenstions have not changed:
Glib::RefPtr<const Gdk::Pixbuf> pixbuf_in_image = m_image.get_pixbuf();
if( !pixbuf_in_image || (pixbuf_in_image->get_height() != pixbuf_scaled->get_height()) || (pixbuf_in_image->get_width() != pixbuf_scaled->get_width()) )
m_image.set(pixbuf_scaled);
}
}
}
}
else
......@@ -321,7 +343,6 @@ Glib::RefPtr<Gdk::Pixbuf> ImageGlom::scale_keeping_ratio(const Glib::RefPtr<Gdk:
if( (target_height == 0) || (target_width == 0) )
{
//g_warning("ImageGlom::scale_keeping_ratio(): calculated dimension is zero: target_width=%d, target_height=%d", target_width, target_height);
return Glib::RefPtr<Gdk::Pixbuf>(); //This shouldn't happen anyway. It seems to happen sometimes though, when ratio is very small.
}
......
......@@ -35,35 +35,37 @@ public:
ImageGlom();
virtual ~ImageGlom();
virtual void set_value(const Gnome::Gda::Value& value);
virtual Gnome::Gda::Value get_value() const;
virtual bool get_has_original_data() const;
protected:
virtual bool on_expose_event(GdkEventExpose* event);
virtual bool on_button_press_event(GdkEventButton *event);
void on_menupopup_activate_select_file();
void on_menupopup_activate_copy();
void on_menupopup_activate_paste();
void on_menupopup_activate_clear();
void on_clipboard_get(Gtk::SelectionData& selection_data, guint /* info */);
void on_clipboard_clear();
void on_clipboard_received_image(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf);
virtual App_Glom* get_application();
void setup_menu_usermode();
void scale();
static Glib::RefPtr<Gdk::Pixbuf> scale_keeping_ratio(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf, int target_height, int target_width);
Gtk::Image m_image;
Gtk::Frame m_frame;
Glib::RefPtr<Gdk::Pixbuf> m_pixbuf_original; //Only stored temporarily, because it could be big.
Glib::RefPtr<Gdk::Pixbuf> m_pixbuf_clipboard; //When copy is used, store it here until it is pasted.
Gtk::Menu* m_pMenuPopup_UserMode;
Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup_UserModePopup;
Glib::RefPtr<Gtk::UIManager> m_refUIManager_UserModePopup;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment