libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GtkCRNHelpers.h
Go to the documentation of this file.
1 /* Copyright 2016 CoReNum
2  *
3  * This file is part of libgtkcrnmm.
4  *
5  * libgtkcrnmm is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libgtkcrnmm is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libgtkcrnmm. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: GtkCRNHelpers.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef GtkCRNHelpers_HEADER
23 #define GtkCRNHelpers_HEADER
24 
25 #include <libgtkcrnmm_config.h>
26 #include <gtkmm.h>
27 #include <CRNException.h>
28 
29 namespace GtkCRN
30 {
31 #ifdef CRN_USING_GTKMM3
32  void set_enable_action_group(const Glib::RefPtr<Gio::SimpleActionGroup> &grp, bool enabled);
33  void enable_action_group(const Glib::RefPtr<Gio::SimpleActionGroup> &grp);
34  void disable_action_group(const Glib::RefPtr<Gio::SimpleActionGroup> &grp);
35 
36  template<typename ACTIONMAPPTR> void set_enable_action(const ACTIONMAPPTR &grp, const Glib::ustring &action, bool enabled)
37  {
38  auto obj = grp->lookup_action(action);
39  auto act = Glib::RefPtr<Gio::SimpleAction>::cast_dynamic(obj);
40  if (act)
41  act->set_enabled(enabled);
42  else
43  throw crn::ExceptionNotFound(("GtkCRN::set_enable_action(): action not found: " + action).c_str());
44  }
45 
46  template<typename ACTIONMAPPTR> void enable_action(const ACTIONMAPPTR &grp, const Glib::ustring &action)
47  {
48  set_enable_action(grp, action, true);
49  }
50 
51  template<typename ACTIONMAPPTR> void disable_action(const ACTIONMAPPTR &grp, const Glib::ustring &action)
52  {
53  set_enable_action(grp, action, false);
54  }
55 
56  template<typename ACTIONMAPPTR> bool is_toggle_action_active(const ACTIONMAPPTR &grp, const Glib::ustring &action)
57  {
58  auto ok = false;
59  grp->lookup_action(action)->get_state(ok);
60  return ok;
61  }
62 
63 #else
64  void set_enable_action_group(const Glib::RefPtr<Gtk::ActionGroup> &grp, bool enabled);
65  void enable_action_group(const Glib::RefPtr<Gtk::ActionGroup> &grp);
66  void disable_action_group(const Glib::RefPtr<Gtk::ActionGroup> &grp);
67 
68  void set_enable_action(const Glib::RefPtr<Gtk::ActionGroup> &grp, const Glib::ustring &action, bool enabled);
69  void enable_action(const Glib::RefPtr<Gtk::ActionGroup> &grp, const Glib::ustring &action);
70  void disable_action(const Glib::RefPtr<Gtk::ActionGroup> &grp, const Glib::ustring &action);
71 
72  bool is_toggle_action_active(const Glib::RefPtr<Gtk::ActionGroup> &grp, const Glib::ustring &action);
73 #endif
74 };
75 
76 #endif
77 
78 
void disable_action(const Glib::RefPtr< Gtk::ActionGroup > &grp, const Glib::ustring &action)
bool is_toggle_action_active(const Glib::RefPtr< Gtk::ActionGroup > &grp, const Glib::ustring &action)
void enable_action_group(const Glib::RefPtr< Gtk::ActionGroup > &grp)
void enable_action(const Glib::RefPtr< Gtk::ActionGroup > &grp, const Glib::ustring &action)
void set_enable_action(const Glib::RefPtr< Gtk::ActionGroup > &grp, const Glib::ustring &action, bool enabled)
void set_enable_action_group(const Glib::RefPtr< Gtk::ActionGroup > &grp, bool enabled)
void disable_action_group(const Glib::RefPtr< Gtk::ActionGroup > &grp)
An item was not found in a container.
Definition: CRNException.h:95