1 //  Copyright (C) 2010, 2014, 2015 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 //  02110-1301, USA.
17 
18 #pragma once
19 #ifndef TILESTYLE_ORGANIZER_DIALOG_H
20 #define TILESTYLE_ORGANIZER_DIALOG_H
21 
22 #include <gtkmm.h>
23 #include <sigc++/signal.h>
24 #include "lw-editor-dialog.h"
25 
26 class Tile;
27 class TileStyle;
28 
29 class TileStyleOrganizerDialog: public LwEditorDialog
30 {
31  public:
32     TileStyleOrganizerDialog(Gtk::Window &parent, Tile *tile);
~TileStyleOrganizerDialog()33     ~TileStyleOrganizerDialog() {}
34 
35     sigc::signal<void, guint32> tilestyle_selected;
36 
37  protected:
38 
39   class CategoriesColumns : public Gtk::TreeModel::ColumnRecord
40   {
41     public:
CategoriesColumns()42     CategoriesColumns()
43       {
44         add(type);
45         add(name);
46         add(image);
47       }
48 
49     Gtk::TreeModelColumn<guint32> type;
50     Gtk::TreeModelColumn<Glib::ustring> name;
51     Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > image;
52   };
53 
54   CategoriesColumns categories_columns;
55   Glib::RefPtr<Gtk::ListStore> categories_list;
56 
57   class TileStyleColumns : public Gtk::TreeModel::ColumnRecord
58   {
59     public:
TileStyleColumns()60     TileStyleColumns()
61       {
62         add(style);
63         add(name);
64         add(image);
65       }
66 
67     Gtk::TreeModelColumn<TileStyle*> style;
68     Gtk::TreeModelColumn<Glib::ustring> name;
69     Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > image;
70   };
71 
72   TileStyleColumns tilestyle_columns;
73   Glib::RefPtr<Gtk::ListStore> category_list;
74   Glib::RefPtr<Gtk::ListStore> unsorted_list;
75  private:
76     Tile *d_tile;
77     Gtk::IconView *categories_iconview;
78     Gtk::IconView *category_iconview;
79     Gtk::IconView *unsorted_iconview;
80     Gtk::Label *category_label;
81     Gtk::Label *unsorted_label;
82 
83     void add_category(guint32 type);
84     void fill_in_categories();
85     void fill_category(guint32 type);
86     void empty_category();
87     void on_category_selected();
88     void add_tilestyle(Glib::RefPtr<Gtk::ListStore> list, TileStyle *tilestyle);
89     void on_category_drag_data_get(const Glib::RefPtr<Gdk::DragContext> &drag_context,
90                                    Gtk::SelectionData &data);
91     void on_unsorted_drag_data_get(const Glib::RefPtr<Gdk::DragContext> &drag_context,
92                                    Gtk::SelectionData &data);
93     std::list<TileStyle*> get_selected_unsorted_tilestyles();
94     std::list<TileStyle*> get_selected_category_tilestyles();
95     int get_selected_category();
96 
97     void on_categories_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext> &context, int a, int b, const Gtk::SelectionData& selection_data, guint c, guint time);
98     void on_category_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext> &context, int a, int b, const Gtk::SelectionData& selection_data, guint c, guint time);
99     void on_unsorted_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext> &context, int a, int b, const Gtk::SelectionData& selection_data, guint c, guint time);
100     void on_category_tilestyle_activated(const Gtk::TreeModel::Path &path);
101     void on_unsorted_tilestyle_activated(const Gtk::TreeModel::Path &path);
102 
103     void on_drag_begin(Gtk::IconView *i);
104     std::list<TileStyle*> selected_category_tilestyles;
105     void on_selection_made(Gtk::IconView *iconview);
106     Glib::TimeVal time_of_last_selection;
107     std::vector<Gtk::TreeModel::Path> last_multiple_selection;
108     bool inhibit_select;
109     sigc::connection selection_timeout_handler;
110     bool expire_selection();
111 };
112 
113 #endif
114