source: synfigstudio/trunk/fuentes/src/gui/docks/dockdroparea.cpp @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 4.2 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file dockdroparea.cpp
3**      \brief Template File
4**
5**      $Id$
6**
7**      \legal
8**      ......... ... 2013 Ivan Mahonin
9**
10**      This package is free software; you can redistribute it and/or
11**      modify it under the terms of the GNU General Public License as
12**      published by the Free Software Foundation; either version 2 of
13**      the License, or (at your option) any later version.
14**
15**      This package is distributed in the hope that it will be useful,
16**      but WITHOUT ANY WARRANTY; without even the implied warranty of
17**      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18**      General Public License for more details.
19**      \endlegal
20*/
21/* ========================================================================= */
22
23/* === H E A D E R S ======================================================= */
24
25#ifdef USING_PCH
26#       include "pch.h"
27#else
28#ifdef HAVE_CONFIG_H
29#       include <config.h>
30#endif
31
32#include "app.h"
33#include "docks/dockdroparea.h"
34#include "docks/dockmanager.h"
35#include <gtkmm/button.h>
36
37#endif
38
39/* === U S I N G =========================================================== */
40
41using namespace std;
42using namespace etl;
43using namespace synfig;
44using namespace studio;
45
46/* === M A C R O S ========================================================= */
47
48/* === G L O B A L S ======================================================= */
49
50/* === P R O C E D U R E S ================================================= */
51
52/* === M E T H O D S ======================================================= */
53
54DockDropArea::DockDropArea(Gtk::Widget *target):
55        Gtk::Table(3, 3, true),
56        target(target)
57{
58        std::vector<Gtk::TargetEntry> listTargets;
59        listTargets.push_back( Gtk::TargetEntry("SYNFIG_DOCK") );
60
61        Gtk::Button *button_left   = manage(new Gtk::Button());
62        Gtk::Button *button_right  = manage(new Gtk::Button());
63        Gtk::Button *button_top    = manage(new Gtk::Button());
64        Gtk::Button *button_bottom = manage(new Gtk::Button());
65
66        button_left->drag_dest_set(listTargets);
67        button_right->drag_dest_set(listTargets);
68        button_top->drag_dest_set(listTargets);
69        button_bottom->drag_dest_set(listTargets);
70
71        button_left->signal_drag_data_received().connect(
72                        sigc::mem_fun(*this,&DockDropArea::drop_on_left));
73        button_right->signal_drag_data_received().connect(
74                        sigc::mem_fun(*this,&DockDropArea::drop_on_right));
75        button_top->signal_drag_data_received().connect(
76                        sigc::mem_fun(*this,&DockDropArea::drop_on_top));
77        button_bottom->signal_drag_data_received().connect(
78                        sigc::mem_fun(*this,&DockDropArea::drop_on_bottom));
79
80        attach(*button_left,   0, 1, 1, 2, Gtk::FILL, Gtk::FILL);
81        attach(*button_right,  2, 3, 1, 2, Gtk::FILL, Gtk::FILL);
82        attach(*button_top,    1, 2, 0, 1, Gtk::FILL, Gtk::FILL);
83        attach(*button_bottom, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL);
84        show_all_children();
85}
86
87void
88DockDropArea::drop_on(bool vertical, bool first, const Glib::RefPtr<Gdk::DragContext>& context, const Gtk::SelectionData& selection_data, guint time)
89{
90        if (target != NULL && (selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
91        {
92                Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
93                if (DockManager::add_dockable(*target, dockable, vertical, first))
94                {
95                        context->drag_finish(true, false, time);
96                        App::dock_manager->update_window_titles();
97                        return;
98                }
99        }
100        context->drag_finish(false, false, time);
101}
102
103void
104DockDropArea::drop_on_left(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
105{
106        drop_on(false, true, context, selection_data, time);
107}
108
109void
110DockDropArea::drop_on_right(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
111{
112        drop_on(false, false, context, selection_data, time);
113}
114
115void
116DockDropArea::drop_on_top(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
117{
118        drop_on(true, true, context, selection_data, time);
119}
120
121void
122DockDropArea::drop_on_bottom(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
123{
124        drop_on(true, false, context, selection_data, time);
125}
Note: See TracBrowser for help on using the repository browser.