Back to index

easystroke  0.5.5.1
actions.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008-2009, Thomas Jaeger <ThJaeger@gmail.com>
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00011  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
00013  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00014  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 #ifndef __ACTIONS_H__
00017 #define __ACTIONS_H__
00018 
00019 #include <gtkmm.h>
00020 
00021 class Unique;
00022 class Win;
00023 class ActionListDiff;
00024 
00025 class TreeViewMulti : public Gtk::TreeView {
00026        bool pending;
00027        Gtk::TreePath path;
00028        Gtk::TreeViewColumn *column;
00029        virtual bool on_button_press_event(GdkEventButton* event);
00030        virtual bool on_button_release_event(GdkEventButton* event);
00031        virtual void on_drag_begin(const Glib::RefPtr<Gdk::DragContext> &context);
00032 public:
00033        TreeViewMulti();
00034 };
00035 
00036 class Actions {
00037 public:
00038        Actions();
00039 private:
00040        void on_button_delete();
00041        void on_button_new();
00042        void on_button_record();
00043        void on_selection_changed();
00044        void on_cursor_changed();
00045        void on_name_edited(const Glib::ustring& path, const Glib::ustring& new_text);
00046        void on_text_edited(const Glib::ustring& path, const Glib::ustring& new_text);
00047        void on_type_edited(const Glib::ustring& path, const Glib::ustring& new_text);
00048        void on_accel_edited(const Glib::ustring& path_string, guint accel_key, Gdk::ModifierType accel_mods, guint hardware_keycode);
00049        void on_combo_edited(const Glib::ustring& path_string, guint item);
00050        void on_arg_editing_started(Gtk::CellEditable* editable, const Glib::ustring& path);
00051        void on_something_editing_started(Gtk::CellEditable* editable, const Glib::ustring& path);
00052        void on_something_editing_canceled();
00053        void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
00054        void on_cell_data_name(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter);
00055        void on_cell_data_type(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter);
00056        void on_cell_data_arg(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter);
00057        int compare_ids(const Gtk::TreeModel::iterator &a, const Gtk::TreeModel::iterator &b);
00058        class OnStroke;
00059        Gtk::TreeRow get_selected_row();
00060 
00061        void focus(Unique *id, int col, bool edit);
00062        bool do_focus(Unique *id, Gtk::TreeViewColumn *col, bool edit);
00063 
00064        bool select_app(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter, ActionListDiff *actions);
00065        void on_add_app();
00066        void on_add_group();
00067        void on_group_name_edited(const Glib::ustring& path, const Glib::ustring& new_text);
00068        void on_apps_selection_changed();
00069        void load_app_list(const Gtk::TreeNodeChildren &ch, ActionListDiff *actions);
00070        void on_cell_data_apps(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter);
00071        void update_action_list();
00072        void update_row(const Gtk::TreeRow &row);
00073        bool count_app_actions(const Gtk::TreeIter &i);
00074        void update_counts();
00075        void on_reset_actions();
00076        void on_remove_app();
00077 
00078        class ModelColumns : public Gtk::TreeModel::ColumnRecord {
00079        public:
00080               ModelColumns() {
00081                      add(stroke); add(name); add(type); add(arg); add(cmd_save); add(id);
00082                      add(name_bold); add(action_bold); add(deactivated);
00083               }
00084               Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > stroke;
00085               Gtk::TreeModelColumn<Glib::ustring> name, type, arg, cmd_save;
00086               Gtk::TreeModelColumn<Unique *> id;
00087               Gtk::TreeModelColumn<bool> name_bold, action_bold;
00088               Gtk::TreeModelColumn<bool> deactivated;
00089        };
00090        class Store : public Gtk::ListStore {
00091               Actions *parent;
00092        public:
00093               Store(const Gtk::TreeModelColumnRecord &columns, Actions *p) : Gtk::ListStore(columns), parent(p) {}
00094               static Glib::RefPtr<Store> create(const Gtk::TreeModelColumnRecord &columns, Actions *parent) {
00095                      return Glib::RefPtr<Store>(new Store(columns, parent));
00096               }
00097        protected:
00098               bool row_draggable_vfunc(const Gtk::TreeModel::Path &path) const;
00099               bool row_drop_possible_vfunc(const Gtk::TreeModel::Path &dest, const Gtk::SelectionData &selection) const;
00100               bool drag_data_received_vfunc(const Gtk::TreeModel::Path &dest, const Gtk::SelectionData& selection);
00101        };
00102        class AppsStore : public Gtk::TreeStore {
00103               Actions *parent;
00104        public:
00105               AppsStore(const Gtk::TreeModelColumnRecord &columns, Actions *p) : Gtk::TreeStore(columns), parent(p) {}
00106               static Glib::RefPtr<AppsStore> create(const Gtk::TreeModelColumnRecord &columns, Actions *parent) {
00107                      return Glib::RefPtr<AppsStore>(new AppsStore(columns, parent));
00108               }
00109        protected:
00110               bool row_drop_possible_vfunc(const Gtk::TreeModel::Path &dest, const Gtk::SelectionData &selection) const;
00111               bool drag_data_received_vfunc(const Gtk::TreeModel::Path &dest, const Gtk::SelectionData& selection);
00112        };
00113        ModelColumns cols;
00114        TreeViewMulti tv;
00115        Glib::RefPtr<Store> tm;
00116 
00117        Gtk::TreeView *apps_view;
00118        Glib::RefPtr<AppsStore> apps_model;
00119 
00120        class Single : public Gtk::TreeModel::ColumnRecord {
00121        public:
00122               Single() { add(type); }
00123               Gtk::TreeModelColumn<Glib::ustring> type;
00124        };
00125        Single type;
00126 
00127        class Apps : public Gtk::TreeModel::ColumnRecord {
00128        public:
00129               Apps() { add(app); add(actions); add(count); }
00130               Gtk::TreeModelColumn<Glib::ustring> app;
00131               Gtk::TreeModelColumn<ActionListDiff *> actions;
00132               Gtk::TreeModelColumn<int> count;
00133        };
00134        Apps ca;
00135 
00136        struct Focus;
00137 
00138        Glib::RefPtr<Gtk::ListStore> type_store;
00139 
00140        Gtk::Button *button_record, *button_delete, *button_remove_app, *button_reset_actions;
00141        Gtk::CheckButton *check_show_deleted;
00142        Gtk::Expander *expander_apps;
00143 
00144        bool editing_new;
00145        bool editing;
00146 
00147        ActionListDiff *action_list;
00148 };
00149 
00150 #endif