1 // This file is part of GtkEveMon.
2 //
3 // GtkEveMon 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 // You should have received a copy of the GNU General Public License
9 // along with GtkEveMon. If not, see <http://www.gnu.org/licenses/>.
10
11 #ifndef GTK_PLANNER_BASE_HEADER
12 #define GTK_PLANNER_BASE_HEADER
13
14 #include <gtkmm.h>
15
16 #include "api/apiskilltree.h"
17 #include "api/apicerttree.h"
18
19 typedef sigc::signal<void, ApiElement const*, int> SignalPlanningRequested;
20 typedef sigc::signal<void, ApiElement const*> SignalApiElementSelected;
21 typedef sigc::signal<void, ApiElement const*> SignalApiElementActivated;
22
23 /* ---------------------------------------------------------------- */
24
25 class GtkElementContextMenu : public Gtk::Menu
26 {
27 protected:
28 SignalPlanningRequested sig_planning_requested;
29
30 protected:
31 void delete_me (void);
32
33 public:
34 GtkElementContextMenu (void);
35 SignalPlanningRequested& signal_planning_requested (void);
36 };
37
38 /* ---------------------------------------------------------------- */
39
40 class GtkSkillContextMenu : public GtkElementContextMenu
41 {
42 private:
43 ApiSkill const* skill;
44
45 protected:
46 void on_training_requested (int level);
47
48 public:
49 void set_skill (ApiSkill const* skill, int min_level);
50 };
51
52 /* ---------------------------------------------------------------- */
53
54 class GtkCertContextMenu : public GtkElementContextMenu
55 {
56 private:
57 ApiCert const* cert;
58
59 protected:
60 void on_training_requested (void);
61
62 public:
63 void set_cert (ApiCert const* cert);
64 };
65
66 /* ---------------------------------------------------------------- */
67
68 /* A wrapper around TreeView to handle context menu requests. */
69 class GtkListViewHelper : public Gtk::TreeView
70 {
71 private:
72 sigc::signal<void, GdkEventButton*> sig_button_press_event;
73
74 protected:
75 bool on_button_press_event (GdkEventButton* event);
76
77 public:
78 GtkListViewHelper (Glib::RefPtr<Gtk::TreeModel> const& model);
~GtkListViewHelper(void)79 virtual ~GtkListViewHelper (void) {}
80 sigc::signal<void, GdkEventButton*>& signal_button_press_myevent (void);
81 };
82
83 /* ---------------------------------------------------------------- */
84
85 template <class T>
86 class GuiPlannerCols : public Gtk::TreeModel::ColumnRecord
87 {
88 public:
89 GuiPlannerCols (void);
90
91 Gtk::TreeModelColumn<Glib::ustring> name;
92 Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon;
93 Gtk::TreeModelColumn<T> data;
94 };
95
96 typedef GuiPlannerCols<ApiElement const*> GuiPlannerElemCols;
97 typedef GuiPlannerCols<ApiSkill const*> GuiPlannerSkillCols;
98 typedef GuiPlannerCols<ApiCert const*> GuiPlannerCertCols;
99
100 /* ---------------------------------------------------------------- */
101
102 inline SignalPlanningRequested&
signal_planning_requested(void)103 GtkElementContextMenu::signal_planning_requested (void)
104 {
105 return this->sig_planning_requested;
106 }
107
108 inline void
delete_me(void)109 GtkElementContextMenu::delete_me (void)
110 {
111 delete this;
112 }
113
114 inline
GtkListViewHelper(Glib::RefPtr<Gtk::TreeModel> const & model)115 GtkListViewHelper::GtkListViewHelper (Glib::RefPtr<Gtk::TreeModel> const& model)
116 : Gtk::TreeView(model)
117 {
118 }
119
120 inline sigc::signal<void, GdkEventButton*>&
signal_button_press_myevent(void)121 GtkListViewHelper::signal_button_press_myevent (void)
122 {
123 return this->sig_button_press_event;
124 }
125
126 template <class T>
127 inline
GuiPlannerCols(void)128 GuiPlannerCols<T>::GuiPlannerCols (void)
129 {
130 this->add(name);
131 this->add(icon);
132 this->add(data);
133 }
134
135 #endif /* GTK_PLANNER_BASE_HEADER */
136