3
* Copyright (C) 2007, 2008 Openismus GmbH
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
21
#include "print_layout_toolbar_button.h"
22
#include <glom/utility_widgets/egg/toolpalette/eggtoolpalette.h>
28
std::string get_icon_path(const std::string& filename)
31
gchar* basepath = g_win32_get_package_installation_subdirectory(NULL, NULL, "share/glom/pixmaps");
32
const std::string result = Glib::build_filename(basepath, filename);
36
return Glib::build_filename(GLOM_ICON_DIR, filename);
40
} //anonymous namespace
46
PrintLayoutToolbarButton::PrintLayoutToolbarButton(const std::string& icon_name, enumItems type,
47
const Glib::ustring& title, const Glib::ustring& tooltip)
48
: Gtk::ToolButton( *(Gtk::manage (new Gtk::Image(get_icon_path(icon_name)))) )
51
g_object_set_data(G_OBJECT(gobj()), "glom-type", GINT_TO_POINTER(type));
53
std::list<Gtk::TargetEntry> targetentries;
54
targetentries.push_back(Gtk::TargetEntry(get_target()));
56
drag_source_set(targetentries, Gdk::MODIFIER_MASK,
57
Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
58
set_tooltip_text(tooltip);
62
PrintLayoutToolbarButton::~PrintLayoutToolbarButton()
66
PrintLayoutToolbarButton::enumItems PrintLayoutToolbarButton::get_item_type_from_selection_data(const Glib::RefPtr<Gdk::DragContext>& drag_context, const Gtk::SelectionData& selection_data)
68
PrintLayoutToolbarButton::enumItems result = ITEM_INVALID;
70
//Put this code in the toolbar class:
71
Gtk::Widget* palette = drag_get_source_widget(drag_context);
72
while(palette && !EGG_IS_TOOL_PALETTE (palette->gobj()))
73
palette = palette->get_parent();
78
GtkWidget* tool_item = egg_tool_palette_get_drag_item(EGG_TOOL_PALETTE (palette->gobj()), selection_data.gobj());
82
result = static_cast<PrintLayoutToolbarButton::enumItems>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tool_item), "glom-type")));
86
void PrintLayoutToolbarButton::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
87
Gtk::SelectionData& selection_data, guint, guint)
89
selection_data.set(8, (guint8*)(&m_type), 4);
92
void PrintLayoutToolbarButton::on_drag_begin(const Glib::RefPtr<Gdk::DragContext>& drag_context)
94
drag_context->set_icon(dynamic_cast<Gtk::Image*>(get_icon_widget())->get_pixbuf(), 0, 0);