Commit 893e44ae authored by Murray Cumming's avatar Murray Cumming Committed by Murray Cumming
Browse files

Put the Gtk::Image in a Gtk::Frame so we can see it when it is empty.

2005-07-14  Murray Cumming  <murrayc@murrayc.com>

        * glom/utility_widgets/imageglom.cc:
        * glom/utility_widgets/imageglom.h: Put the Gtk::Image in a
        Gtk::Frame so we can see it when it is empty. Added a context
        menu for user mode, and restricted the file chooser to pixbuf
        types.
parent 693156f8
2005-07-14 Murray Cumming <murrayc@murrayc.com>
* glom/utility_widgets/imageglom.cc:
* glom/utility_widgets/imageglom.h: Put the Gtk::Image in a
Gtk::Frame so we can see it when it is empty. Added a context
menu for user mode, and restricted the file chooser to pixbuf
types.
2005-07-14 Murray Cumming <murrayc.com>
* glom/data_structure/field.cc: sql(): Handle TYPE_IMAGE
......
......@@ -609,11 +609,9 @@ Gnome::Gda::Value GlomConversions::get_example_value(Field::glom_field_type fiel
Glib::ustring GlomConversions::get_escaped_binary_data(guint8* buffer, size_t buffer_size)
{
g_warning("debug: get_escaped_binary_data start");
g_warning("GlomConversions::get_escaped_binary_data: debug: buffer ");
for(int i = 0; i < 10; ++i)
g_warning("%02X (%c), ", (guint8)buffer[i], buffer[i]);
//g_warning("GlomConversions::get_escaped_binary_data: debug: buffer ");
//for(int i = 0; i < 10; ++i)
// g_warning("%02X (%c), ", (guint8)buffer[i], buffer[i]);
//TODO: Performance: Preallocate a string of the appropriate size.
//Use an output parameter instead of copying it during return.
......@@ -635,8 +633,7 @@ g_warning("debug: get_escaped_binary_data start");
result += Glib::ustring("\\\\") + byte_as_octal;
}
}
g_warning("debug: get_escaped_binary_data end");
return result;
}
......
......@@ -27,11 +27,18 @@
#include <iostream> // for cout, endl
ImageGlom::ImageGlom()
: m_image(Gtk::Stock::MISSING_IMAGE, Gtk::ICON_SIZE_DIALOG) //The widget is invisible if we don't specify an image.
: m_image(Gtk::Stock::MISSING_IMAGE, Gtk::ICON_SIZE_DIALOG), //The widget is invisible if we don't specify an image.
m_pMenuPopup_UserMode(0)
{
setup_menu();
setup_menu_usermode();
m_image.show();
add(m_image);
m_frame.set_shadow_type(Gtk::SHADOW_ETCHED_IN); //Without this, the image widget has no borders and is completely invisible when empty.
m_frame.add(m_image);
m_frame.show();
add(m_frame);
}
ImageGlom::~ImageGlom()
......@@ -67,38 +74,22 @@ bool ImageGlom::on_button_press_event(GdkEventButton *event)
return true; //We handled this event.
}
}
else
{
if(mods & GDK_BUTTON3_MASK)
{
//Give user choices of actions on this item:
m_pMenuPopup_UserMode->popup(event->button, event->time);
return true; //We handled this event.
}
}
//Single-click to select file:
if(mods & GDK_BUTTON1_MASK)
{
Gtk::FileChooserDialog dialog(_("Choose image"), Gtk::FILE_CHOOSER_ACTION_OPEN);
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
int response = dialog.run();
dialog.hide();
if(response != Gtk::RESPONSE_CANCEL)
{
const std::string filepath = dialog.get_filename();
if(!filepath.empty())
{
try
{
m_pixbuf_original = Gdk::Pixbuf::create_from_file(filepath);
if(m_pixbuf_original)
{
m_image.set(m_pixbuf_original); //Load the image.
scale();
signal_edited().emit();
}
}
catch(const Glib::Exception& ex)
{
Frame_Glom::show_ok_dialog(_("Image loading failed"), _("The image file could not be opened:\n") + ex.what(), *pApp);
}
return true; //We handled this event.
}
}
on_menupopup_activate_select_file();
return true; //We handled this event.
}
}
......@@ -248,8 +239,8 @@ void ImageGlom::scale()
if( (pixbuf_height > allocation.get_height()) ||
(pixbuf_width > allocation.get_width()) )
{
pixbuf = scale_keeping_ratio(pixbuf, allocation.get_height(), allocation.get_width());
m_image.set(pixbuf);
Glib::RefPtr<Gdk::Pixbuf> pixbuf_scaled = scale_keeping_ratio(pixbuf, allocation.get_height(), allocation.get_width());
m_image.set(pixbuf_scaled);
}
}
}
......@@ -306,3 +297,100 @@ Glib::RefPtr<Gdk::Pixbuf> ImageGlom::scale_keeping_ratio(const Glib::RefPtr<Gdk:
return pixbuf->scale_simple(target_width, target_height, Gdk::INTERP_NEAREST);
}
void ImageGlom::on_menupopup_activate_select_file()
{
Gtk::FileChooserDialog dialog(_("Choose image"), Gtk::FILE_CHOOSER_ACTION_OPEN);
//Get image formats only:
Gtk::FileFilter filter;
filter.add_pixbuf_formats();
dialog.add_filter(filter);
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
int response = dialog.run();
dialog.hide();
if(response != Gtk::RESPONSE_CANCEL)
{
const std::string filepath = dialog.get_filename();
if(!filepath.empty())
{
try
{
m_pixbuf_original = Gdk::Pixbuf::create_from_file(filepath);
if(m_pixbuf_original)
{
m_image.set(m_pixbuf_original); //Load the image.
scale();
signal_edited().emit();
}
}
catch(const Glib::Exception& ex)
{
App_Glom* pApp = get_application();
if(pApp)
Frame_Glom::show_ok_dialog(_("Image loading failed"), _("The image file could not be opened:\n") + ex.what(), *pApp);
}
}
}
}
void ImageGlom::on_menupopup_activate_copy()
{
}
void ImageGlom::on_menupopup_activate_paste()
{
}
void ImageGlom::setup_menu_usermode()
{
m_refActionGroup_UserModePopup = Gtk::ActionGroup::create();
m_refActionGroup_UserModePopup->add(Gtk::Action::create("ContextMenu_UserMode", "Context Menu") );
m_refActionSelectFile = Gtk::Action::create("ContextSelectFile", Gtk::Stock::EDIT, _("Choose File"));
m_refActionCopy = Gtk::Action::create("ContextCopy", Gtk::Stock::COPY);
m_refActionPaste = Gtk::Action::create("ContextPaste", Gtk::Stock::PASTE);
m_refActionGroup_UserModePopup->add(m_refActionSelectFile,
sigc::mem_fun(*this, &ImageGlom::on_menupopup_activate_select_file) );
m_refActionGroup_UserModePopup->add(m_refActionCopy,
sigc::mem_fun(*this, &ImageGlom::on_menupopup_activate_copy) );
m_refActionGroup_UserModePopup->add(m_refActionPaste,
sigc::mem_fun(*this, &ImageGlom::on_menupopup_activate_paste) );
m_refUIManager_UserModePopup = Gtk::UIManager::create();
m_refUIManager_UserModePopup->insert_action_group(m_refActionGroup_UserModePopup);
//TODO: add_accel_group(m_refUIManager_UserModePopup->get_accel_group());
try
{
Glib::ustring ui_info =
"<ui>"
" <popup name='ContextMenu_UserMode'>"
" <menuitem action='ContextSelectFile'/>"
" <menuitem action='ContextCopy'/>"
" <menuitem action='ContextPaste'/>"
" </popup>"
"</ui>";
m_refUIManager_UserModePopup->add_ui_from_string(ui_info);
}
catch(const Glib::Error& ex)
{
std::cerr << "building menus failed: " << ex.what();
}
//Get the menu:
m_pMenuPopup_UserMode = dynamic_cast<Gtk::Menu*>( m_refUIManager_UserModePopup->get_widget("/ContextMenu_UserMode") );
if(!m_pMenuPopup_UserMode)
g_warning("menu not found");
}
......@@ -43,15 +43,25 @@ public:
protected:
virtual bool on_button_press_event(GdkEventButton *event);
void on_menupopup_activate_select_file();
void on_menupopup_activate_copy();
void on_menupopup_activate_paste();
virtual App_Glom* get_application();
void setup_menu_usermode();
void scale();
static Glib::RefPtr<Gdk::Pixbuf> scale_keeping_ratio(const Glib::RefPtr<Gdk::Pixbuf> pixbu, 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.
Gtk::Menu* m_pMenuPopup_UserMode;
Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup_UserModePopup;
Glib::RefPtr<Gtk::UIManager> m_refUIManager_UserModePopup;
Glib::RefPtr<Gtk::Action> m_refActionSelectFile, m_refActionCopy, m_refActionPaste;
};
#endif //GLOM_UTILITY_WIDGETS_COMBOENTRY_GLOM_H
......
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