Commit 357393d0 authored by Murray Cumming's avatar Murray Cumming Committed by Murray Cumming
Browse files

Use a derived Image widget so we can catch button_press_events on it.

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

        * glom/utility_widgets/Makefile.am:
        * glom/utility_widgets/datawidget.cc:
        * glom/utility_widgets/imageglom.cc:
        * glom/utility_widgets/imageglom.h: Use a derived Image widget
        so we can catch button_press_events on it.
parent c4228843
2005-07-12 Murray Cumming <murrayc@murrayc.com>
* glom/utility_widgets/Makefile.am:
* glom/utility_widgets/datawidget.cc:
* glom/utility_widgets/imageglom.cc:
* glom/utility_widgets/imageglom.h: Use a derived Image widget
so we can catch button_press_events on it.
2005-07-12 Murray Cumming <murrayc@murrayc.com>
* glom/data_structure/field.cc:
......
......@@ -26,7 +26,8 @@ libutility_widgets_a_SOURCES = alignment_justified.cc alignment_justified.h \
textviewglom.h textviewglom.cc \
combo_textglade.h combo_textglade.cc \
cellrendererlist.h cellrendererlist.cc \
comboentry_currency.h comboentry_currency.cc
comboentry_currency.h comboentry_currency.cc \
imageglom.h imageglom.cc
libutility_widgets_a_LIBADD = adddel/libutility_widgets_adddel.a \
db_adddel/libutility_widgets_db_adddel.a
......
......@@ -23,6 +23,7 @@
#include "comboentryglom.h"
#include "comboglom.h"
#include "textviewglom.h"
#include "imageglom.h"
#include "../data_structure/glomconversions.h"
#include "../application.h"
#include "../mode_data/dialog_choose_field.h"
......@@ -57,8 +58,8 @@ DataWidget::DataWidget(const LayoutItem_Field& field, const Glib::ustring& table
}
else if(glom_type == Field::TYPE_IMAGE)
{
Gtk::Image* image = Gtk::manage( new Gtk::Image(Gtk::Stock::MISSING_IMAGE, Gtk::ICON_SIZE_DIALOG) ); //The widget will be invisible if we don't specify an image.
image->set_size_request(100, 100);
ImageGlom* image = Gtk::manage( new ImageGlom() );
image->set_size_request(200, 200);
//Gtk::Image* image = Gtk::manage( new Gtk::Image("/home/murrayc/gnome-small.jpg") );
image->show();
//TODO: Respond to double-click: checkbutton->signal_toggled().connect( sigc::mem_fun(*this, &DataWidget::on_widget_edited) );
......
/* Glom
*
* Copyright (C) 2001-2004 Murray Cumming
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "imageglom.h"
#include <glibmm/i18n.h>
#include "../application.h"
//#include <sstream> //For stringstream
#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.
{
setup_menu();
add(m_image);
}
ImageGlom::~ImageGlom()
{
}
bool ImageGlom::on_button_press_event(GdkEventButton *event)
{
g_warning("ImageGlom::on_button_press_event()");
GdkModifierType mods;
gdk_window_get_pointer( Gtk::Widget::gobj()->window, 0, 0, &mods );
//Enable/Disable items.
//We did this earlier, but get_application is more likely to work now:
App_Glom* pApp = get_application();
if(pApp)
{
pApp->add_developer_action(m_refContextLayout); //So that it can be disabled when not in developer mode.
pApp->add_developer_action(m_refContextAddField);
pApp->add_developer_action(m_refContextAddRelatedRecords);
pApp->add_developer_action(m_refContextAddGroup);
pApp->update_userlevel_ui(); //Update our action's sensitivity.
//Only show this popup in developer mode, so operators still see the default GtkEntry context menu.
//TODO: It would be better to add it somehow to the standard context menu.
if(pApp->get_userlevel() == AppState::USERLEVEL_DEVELOPER)
{
if(mods & GDK_BUTTON3_MASK)
{
//Give user choices of actions on this item:
m_pMenuPopup->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())
{
//TODO: Scale it down to the preferred size:
m_image.set(filepath); //Load the image.
return true; //We handled this event.
}
}
}
return Gtk::EventBox::on_button_press_event(event);
}
App_Glom* ImageGlom::get_application()
{
Gtk::Container* pWindow = get_toplevel();
//TODO: This only works when the child widget is already in its parent.
return dynamic_cast<App_Glom*>(pWindow);
}
void ImageGlom::set_value(const Gnome::Gda::Value& /* value */)
{
//TODO
}
Gnome::Gda::Value ImageGlom::get_value() const
{
Gnome::Gda::Value result;
//TODO
return result;
}
/* Glom
*
* Copyright (C) 2001-2004 Murray Cumming
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef GLOM_UTILITY_WIDGETS_IMAGE_GLOM_H
#define GLOM_UTILITY_WIDGETS_IMAGE_GLOM_H
#include <gtkmm.h>
#include "../data_structure/field.h"
#include "layoutwidgetfield.h"
class App_Glom;
class ImageGlom
: public Gtk::EventBox,
public LayoutWidgetField
{
public:
ImageGlom();
virtual ~ImageGlom();
virtual void set_value(const Gnome::Gda::Value& value);
virtual Gnome::Gda::Value get_value() const;
protected:
virtual bool on_button_press_event(GdkEventButton *event);
virtual App_Glom* get_application();
Gtk::Image m_image;
};
#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