libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GtkCRNHelpers.cpp
Go to the documentation of this file.
1 /* Copyright 2016 CoReNum
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn 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  * libcrn 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 libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: GtkCRNHelpers.cpp
19  * \author Yann LEYDIER
20  */
21 
22 #include <GtkCRNHelpers.h>
23 #include <CRNStringUTF8.h>
24 #include <CRNi18n.h>
25 
26 using namespace GtkCRN;
27 
28 #ifdef CRN_USING_GTKMM3
29 void GtkCRN::set_enable_action_group(const Glib::RefPtr<Gio::SimpleActionGroup> &grp, bool enabled)
30 {
31  const auto actions = grp->list_actions();
32  for (const auto &act : actions)
33  set_enable_action(grp, act, enabled);
34 }
35 
36 void GtkCRN::enable_action_group(const Glib::RefPtr<Gio::SimpleActionGroup> &grp)
37 {
38  set_enable_action_group(grp, true);
39 }
40 
41 void GtkCRN::disable_action_group(const Glib::RefPtr<Gio::SimpleActionGroup> &grp)
42 {
43  set_enable_action_group(grp, false);
44 }
45 #else
46 void GtkCRN::set_enable_action_group(const Glib::RefPtr<Gtk::ActionGroup> &grp, bool enabled)
47 {
48  grp->set_sensitive(enabled);
49 }
50 
51 void GtkCRN::enable_action_group(const Glib::RefPtr<Gtk::ActionGroup> &grp)
52 {
53  set_enable_action_group(grp, true);
54 }
55 
56 void GtkCRN::disable_action_group(const Glib::RefPtr<Gtk::ActionGroup> &grp)
57 {
58  set_enable_action_group(grp, false);
59 }
60 
61 void GtkCRN::set_enable_action(const Glib::RefPtr<Gtk::ActionGroup> &grp, const Glib::ustring &action, bool enabled)
62 {
63  grp->get_action(action)->set_sensitive(enabled);
64 }
65 
66 void GtkCRN::enable_action(const Glib::RefPtr<Gtk::ActionGroup> &grp, const Glib::ustring &action)
67 {
68  set_enable_action(grp, action, true);
69 }
70 
71 void GtkCRN::disable_action(const Glib::RefPtr<Gtk::ActionGroup> &grp, const Glib::ustring &action)
72 {
73  set_enable_action(grp, action, false);
74 }
75 
76 bool GtkCRN::is_toggle_action_active(const Glib::RefPtr<Gtk::ActionGroup> &grp, const Glib::ustring &action)
77 {
78  auto act = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(grp->get_action(action));
79  if (!act)
80  throw crn::ExceptionRuntime(crn::StringUTF8("GtkCRN::is_toggle_action_active(): ") + _("not a ToggleAction."));
81  return act->get_active();
82 }
83 
84 #endif
85 
void disable_action(const Glib::RefPtr< Gtk::ActionGroup > &grp, const Glib::ustring &action)
A generic runtime error.
Definition: CRNException.h:131
#define _(String)
Definition: CRNi18n.h:51
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)
A character string class.
Definition: CRNStringUTF8.h:49