Back to index

easystroke  0.5.5.1
win.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 __WIN_H__
00017 #define __WIN_H__
00018 #include "gesture.h"
00019 #include <gtkmm.h>
00020 #include "util.h"
00021 #include "prefdb.h"
00022 
00023 class Actions;
00024 class Prefs;
00025 class Stats;
00026 class Ranking;
00027 
00028 // Convenience macro for on-the-fly creation of widgets
00029 #define WIDGET(TYPE, NAME, ARGS...) TYPE &NAME = *Gtk::manage(new TYPE(ARGS))
00030 
00031 extern Glib::RefPtr<Gtk::Builder> widgets;
00032 
00033 class CellRendererTextish : public Gtk::CellRendererText {
00034 public:
00035        enum Mode { TEXT, KEY, POPUP, COMBO };
00036        Mode mode;
00037        const char **items;
00038        CellRendererTextish() : mode(TEXT) {}
00039        typedef sigc::signal<void, const Glib::ustring&, guint, Gdk::ModifierType, guint> key_edited;
00040        typedef sigc::signal<void, const Glib::ustring&, guint> combo_edited;
00041        key_edited &signal_key_edited() { return signal_key_edited_; }
00042        combo_edited &signal_combo_edited() { return signal_combo_edited_; }
00043 protected:
00044        virtual Gtk::CellEditable* start_editing_vfunc(GdkEvent *event, Gtk::Widget &widget, const Glib::ustring &path,
00045                      const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area,
00046                      Gtk::CellRendererState flags);
00047 private:
00048        key_edited signal_key_edited_;
00049        combo_edited signal_combo_edited_;
00050 };
00051 
00052 class Win : Timeout {
00053 public:
00054        Win();
00055 
00056        Gtk::Window& get_window() { return *win; }
00057        boost::shared_ptr<Actions> actions;
00058        boost::shared_ptr<Prefs> prefs_tab;
00059        boost::shared_ptr<Stats> stats;
00060        void show_hide();
00061        void set_icon(RStroke stroke, bool invert);
00062 private:
00063        bool on_icon_size_changed(int);
00064        virtual void timeout();
00065        void on_help_toggled();
00066        void show_popup(guint, guint32);
00067        void show_hide_icon();
00068        void on_about();
00069 
00070        Gtk::Window *win;
00071 
00072        Gtk::Menu menu;
00073 
00074        Glib::RefPtr<Gtk::StatusIcon> icon;
00075        Glib::RefPtr<Gdk::Pixbuf> icon_pb[2];
00076 };
00077 
00078 extern Win *win;
00079 
00080 class Stats {
00081 public:
00082        Stats();
00083        bool on_stroke(boost::shared_ptr<Ranking>);
00084 private:
00085        void on_pdf();
00086        void on_cursor_changed();
00087 
00088        class ModelColumns : public Gtk::TreeModel::ColumnRecord {
00089        public:
00090               ModelColumns() { add(stroke); add(debug); add(name); add(score); add(child); }
00091 
00092               Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > stroke;
00093               Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > debug;
00094               Gtk::TreeModelColumn<Glib::ustring> name;
00095               Gtk::TreeModelColumn<Glib::ustring> score;
00096               Gtk::TreeModelColumn<Glib::RefPtr<Gtk::ListStore> > child;
00097        };
00098        ModelColumns cols;
00099 
00100        Gtk::TreeView *recent_view;
00101        Glib::RefPtr<Gtk::ListStore> recent_store;
00102 
00103        Gtk::TreeView *ranking_view;
00104 };
00105 
00106 class SelectButton {
00107 public:
00108        SelectButton(ButtonInfo bi, bool def, bool any);
00109        ~SelectButton();
00110        bool run();
00111        ButtonInfo event;
00112 private:
00113        Gtk::MessageDialog *dialog;
00114        bool on_button_press(GdkEventButton *ev);
00115        void on_any_toggled();
00116 
00117        Gtk::EventBox *eventbox;
00118        Gtk::ToggleButton *toggle_shift, *toggle_control, *toggle_alt, *toggle_super, *toggle_any;
00119        Gtk::ComboBoxText *select_button;
00120        Gtk::RadioButton *radio_timeout_default, *radio_instant, *radio_click_hold;
00121        sigc::connection handler[2];
00122 };
00123 
00124 void error_dialog(const Glib::ustring &);
00125 Glib::ustring app_name_hr(Glib::ustring);
00126 #endif