1 /* gobby - A GTKmm driven libobby client 2 * Copyright (C) 2005 0x539 dev group 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public 15 * License along with this program; if not, write to the Free 16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 */ 18 19 #ifndef _GOBBY_HEADER_HPP_ 20 #define _GOBBY_HEADER_HPP_ 21 22 #include <list> 23 24 #include <gtkmm/box.h> 25 #include <gtkmm/uimanager.h> 26 #include <gtkmm/radioaction.h> 27 #include <gtkmm/menubar.h> 28 #include <gtkmm/toolbar.h> 29 30 #include "preferences.hpp" // Defines GtkSourceLanguageManager (gtksourceview1) 31 #include "application_state.hpp" 32 33 namespace Gobby 34 { 35 36 class Header: public Gtk::VBox 37 { 38 public: 39 class Error: public Glib::Error 40 { 41 public: 42 enum Code { 43 MENUBAR_MISSING, 44 TOOLBAR_MISSING 45 }; 46 47 Error(Code error_code, const Glib::ustring& error_message); 48 Code code() const; 49 }; 50 51 /** @brief Action that automatically chances sensitivity depending 52 * on application state. 53 */ 54 class AutoAction 55 { 56 public: 57 typedef Glib::RefPtr<Gtk::Action> action_type; 58 59 AutoAction(action_type action, 60 const ApplicationState& state, 61 ApplicationFlags inc_flags, 62 ApplicationFlags exc_flags); 63 64 protected: 65 void on_state_change(const ApplicationState& state); 66 67 action_type m_action; 68 ApplicationFlags m_inc_flags; 69 ApplicationFlags m_exc_flags; 70 }; 71 72 /** @brief Class that stores multiple AutoActions. 73 * 74 * Once an AutoAction has been created, it works without any further 75 * need to access the AutoAction object again, one just needs to 76 * keep the AutoAction somewhere and release it when the application 77 * exits. 78 * 79 * So this class does just keep auto actions without providing access 80 * to them. 81 */ 82 class AutoList 83 { 84 public: 85 typedef AutoAction::action_type action_type; 86 87 void add(action_type action, 88 const ApplicationState& state, 89 ApplicationFlags inc_flags, 90 ApplicationFlags exc_flags); 91 92 ~AutoList(); 93 94 protected: 95 std::list<AutoAction*> m_list; 96 }; 97 98 class LanguageWrapper 99 { 100 public: 101 //typedef AutoAction<Gtk::RadioAction> Action; 102 typedef Glib::RefPtr<Gtk::RadioAction> Action; 103 104 LanguageWrapper(Action action, 105 GtkSourceLanguage* language); 106 ~LanguageWrapper(); 107 108 Action get_action() const; 109 GtkSourceLanguage* get_language() const; 110 protected: 111 Action m_action; 112 GtkSourceLanguage* m_language; 113 }; 114 115 Header(const ApplicationState& state, 116 GtkSourceLanguageManager* lang_mgr); 117 118 // Access to accelerator groups of the ui manager 119 Glib::RefPtr<Gtk::AccelGroup> get_accel_group(); 120 Glib::RefPtr<const Gtk::AccelGroup> get_accel_group() const; 121 122 // Access to toolbar & menubar 123 Gtk::MenuBar& get_menubar(); 124 Gtk::Toolbar& get_toolbar(); 125 126 const Glib::RefPtr<Gtk::ActionGroup> group_app; 127 const Glib::RefPtr<Gtk::ActionGroup> group_session; 128 const Glib::RefPtr<Gtk::ActionGroup> group_edit; 129 const Glib::RefPtr<Gtk::ActionGroup> group_user; 130 const Glib::RefPtr<Gtk::ActionGroup> group_window; 131 const Glib::RefPtr<Gtk::ActionGroup> group_help; 132 133 const Glib::RefPtr<Gtk::Action> action_app; 134 const Glib::RefPtr<Gtk::Action> action_app_session_create; 135 const Glib::RefPtr<Gtk::Action> action_app_session_join; 136 const Glib::RefPtr<Gtk::Action> action_app_session_save; 137 const Glib::RefPtr<Gtk::Action> action_app_session_save_as; 138 const Glib::RefPtr<Gtk::Action> action_app_session_quit; 139 const Glib::RefPtr<Gtk::Action> action_app_quit; 140 141 const Glib::RefPtr<Gtk::Action> action_session; 142 const Glib::RefPtr<Gtk::Action> action_session_document_create; 143 const Glib::RefPtr<Gtk::Action> action_session_document_open; 144 const Glib::RefPtr<Gtk::Action> action_session_document_save; 145 const Glib::RefPtr<Gtk::Action> action_session_document_save_as; 146 const Glib::RefPtr<Gtk::Action> action_session_document_save_all; 147 const Glib::RefPtr<Gtk::Action> action_session_document_close; 148 149 const Glib::RefPtr<Gtk::Action> action_edit; 150 const Glib::RefPtr<Gtk::Action> action_edit_search; 151 const Glib::RefPtr<Gtk::Action> action_edit_search_replace; 152 const Glib::RefPtr<Gtk::Action> action_edit_goto_line; 153 const Glib::RefPtr<Gtk::Action> action_edit_preferences; 154 const Glib::RefPtr<Gtk::Action> action_edit_document_preferences; 155 const Glib::RefPtr<Gtk::Action> action_edit_syntax; 156 std::list<LanguageWrapper> action_edit_syntax_languages; 157 158 const Glib::RefPtr<Gtk::Action> action_user; 159 const Glib::RefPtr<Gtk::Action> action_user_set_password; 160 const Glib::RefPtr<Gtk::Action> action_user_set_colour; 161 162 const Glib::RefPtr<Gtk::Action> action_window; 163 const Glib::RefPtr<Gtk::ToggleAction> action_window_userlist; 164 const Glib::RefPtr<Gtk::ToggleAction> action_window_documentlist; 165 const Glib::RefPtr<Gtk::ToggleAction> action_window_chat; 166 167 const Glib::RefPtr<Gtk::Action> action_help; 168 const Glib::RefPtr<Gtk::Action> action_help_about; 169 170 protected: 171 void set_action_auto(const Glib::RefPtr<Gtk::Action>& action, 172 const ApplicationState& state, 173 ApplicationFlags inc_flags, 174 ApplicationFlags exc_flags); 175 176 const Glib::RefPtr<Gtk::UIManager> m_ui_manager; 177 178 Gtk::MenuBar* m_menubar; 179 Gtk::Toolbar* m_toolbar; 180 181 Gtk::RadioButtonGroup m_lang_group; 182 183 /** @brief List that just stores internally the auto actions to have 184 * the actions change sensitivity automatically. 185 */ 186 AutoList m_auto_actions; 187 }; 188 189 } 190 191 #endif // _GOBBY_HEADER_HPP_ 192