libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GtkCRNProp3.cpp
Go to the documentation of this file.
1 /* Copyright 2010 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: GtkCRNProp3.cpp
19  * \author Yann LEYDIER
20  */
21 
22 #include <GtkCRNProp3.h>
23 #include <CRNi18n.h>
24 
25 using namespace GtkCRN;
26 
27 Prop3::Prop3(Gtk::IconSize is, const crn::Prop3 &p):
28  prop(p),
29  size(is)
30 {
31  img.show();
32  add(img);
33  set_image();
34  signal_button_release_event().connect(sigc::mem_fun(this, &Prop3::click));
35 }
36 
38 {
39  prop = p;
40  set_image();
41  value_changed.emit(prop);
42 }
43 
44 void Prop3::set_icon_size(Gtk::IconSize is)
45 {
46  size = is;
47  set_image();
48 }
49 
51 void Prop3::set_image()
52 {
53 #ifdef CRN_USING_GTKMM3
54  switch (prop.GetValue())
55  {
56  case TRUE:
57  img.set_from_icon_name("_Cancel", size);
58  break;
59  case FALSE:
60  img.set_from_icon_name("_OK", size);
61  break;
62  default:
63  img.set_from_icon_name("dialog-question", size);
64  }
65 #else
66  switch (prop.GetValue())
67  {
68  case TRUE:
69  img.set(Gtk::Stock::YES, size);
70  break;
71  case FALSE:
72  img.set(Gtk::Stock::NO, size);
73  break;
74  default:
75  img.set(Gtk::Stock::DIALOG_QUESTION, size);
76  }
77 #endif
78 }
79 
89 bool Prop3::click(GdkEventButton *ev)
90 {
91  if (!ev)
92  {
93  throw Glib::OptionError(Glib::OptionError::BAD_VALUE,
94  Glib::ustring("bool Prop3::click(GdkEventButton *ev): ") + _("null event."));
95  }
96  switch (ev->button)
97  {
98  case 1:
99  if (prop.IsTrue())
100  prop = crn::Prop3::False();
101  else if (prop.IsFalse())
102  prop = crn::Prop3::Unknown();
103  else
104  prop = crn::Prop3::True();
105  break;
106  case 3:
107  if (prop.IsFalse())
108  prop = crn::Prop3::True();
109  else if (prop.IsTrue())
110  prop = crn::Prop3::Unknown();
111  else
112  prop = crn::Prop3::False();
113  break;
114  }
115  set_image();
116  value_changed.emit(prop);
117  return false;
118 }
119 
static Prop3 Unknown()
Definition: CRNProp3.h:90
#define _(String)
Definition: CRNi18n.h:51
bool IsFalse() const noexcept
Is false?
Definition: CRNProp3.cpp:177
bool IsTrue() const noexcept
Is true?
Definition: CRNProp3.cpp:175
Prop3(Gtk::IconSize is, const crn::Prop3 &p=crn::Prop3::Unknown())
Constructor.
Definition: GtkCRNProp3.cpp:27
static Prop3 False()
Definition: CRNProp3.h:89
void set_icon_size(Gtk::IconSize is)
Sets the icon size.
Definition: GtkCRNProp3.cpp:44
bool click(GdkEventButton *ev)
Emulates a mouse button release on the image.
Definition: GtkCRNProp3.cpp:89
int GetValue() const noexcept
Returns the internal integer value.
Definition: CRNProp3.h:83
static Prop3 True()
Definition: CRNProp3.h:88
void set_value(const crn::Prop3 &p)
Sets the value.
Definition: GtkCRNProp3.cpp:37
A ternary proposition.
Definition: CRNProp3.h:40
#define TRUE
Definition: CRNProp3.cpp:28