libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GtkCRNObject.cpp
Go to the documentation of this file.
1 /* Copyright 2010-2016 CoReNum, INSA-Lyon, ENS-Lyon
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: GtkCRNObject.cpp
19  * \author Yann LEYDIER
20  */
21 
22 #include <GtkCRNObject.h>
23 #include <CRNString.h>
24 #include <CRNData/CRNMap.h>
25 #include <CRNData/CRNVector.h>
26 #include <GtkCRNProp3.h>
27 #include <GdkCRNPixbuf.h>
28 #include <CRNi18n.h>
29 
30 using namespace GtkCRN;
31 
38 {
39  if (!obj)
40  {
41  return new Gtk::Label(_("null object"));
42  }
43  // Map
44  const crn::Map *m = static_cast<const crn::Map*>(obj);
45  if (m)
46  {
47  if (m->IsEmpty())
48  {
49  Glib::ustring txt("<i>(empty)</i>");
50  Gtk::Label *lab = Gtk::manage(new Gtk::Label(txt));
51  lab->set_use_markup();
52  return lab;
53  }
54  else
55  {
56  Gtk::Expander *expander = new Gtk::Expander("Map");
57 #ifdef CRN_USING_GTKMM3
58  Gtk::Grid *tab = Gtk::manage(new Gtk::Grid);
59 #else
60  Gtk::Table *tab = Gtk::manage(new Gtk::Table(int(m->Size()), 2));
61 #endif
62  //tab->set_col_spacings(4);
63  expander->add(*tab);
64  int row = 0;
65  for (crn::Map::const_iterator it = m->begin(); it != m->end(); ++it)
66  {
67  //tab->attach(*Gtk::manage(new Gtk::Label(it->first.CStr())), 0, 1, row, row + 1, Gtk::FILL, Gtk::FILL);
68  //tab->attach(*Gtk::manage(create_widget_from_object(it->second.get())), 1, 2, row, row + 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
69  row += 1;
70  }
71  tab->show_all();
72  return expander;
73  }
74  }
75  // Vector
76  const crn::Vector *v = static_cast<const crn::Vector*>(obj);
77  if (v)
78  {
79  if (v->IsEmpty())
80  {
81  Glib::ustring txt("<i>(empty)</i>");
82  Gtk::Label *lab = Gtk::manage(new Gtk::Label(txt));
83  lab->set_use_markup();
84  return lab;
85  }
86  else
87  {
88  Gtk::Expander *expander = new Gtk::Expander("Vector");
89  Gtk::VBox *vbox = Gtk::manage(new Gtk::VBox);
90  expander->add(*vbox);
91  for (crn::Vector::const_iterator it = v->begin(); it != v->end(); ++it)
92  {
93  vbox->pack_start(*Gtk::manage(create_widget_from_object((*it).get())), false, true, 0);
94  }
95  vbox->show_all();
96  return expander;
97  }
98  }
99  // Prop3
100  const crn::Prop3 *p = static_cast<const crn::Prop3*>(obj);
101  if (p)
102  {
103  GtkCRN::Prop3 *pw = new GtkCRN::Prop3(Gtk::ICON_SIZE_BUTTON, *p);
104  pw->set_sensitive(false);
105  return pw;
106  }
107  // String
108  const auto *s = static_cast<const crn::String*>(obj);
109  if (s)
110  {
111  return new Gtk::Label(s->CStr());
112  }
113  // StringUTF8 and Path
114  const auto *su = static_cast<const crn::StringUTF8*>(obj);
115  if (su)
116  {
117  return new Gtk::Label(su->CStr());
118  }
119  // TODO XXX add Int and Real
120  // Other
121  return new Gtk::Label(typeid(*obj).name());
122 }
123 
#define _(String)
Definition: CRNi18n.h:51
iterator begin()
Returns an iterator to the first element.
Definition: CRNVector.h:100
A UTF32 character string class.
Definition: CRNString.h:61
iterator begin()
Returns an iterator to the first element.
Definition: CRNMap.h:86
std::map< String, SObject >::const_iterator const_iterator
const_iterator on the contents of the container
Definition: CRNMap.h:93
Data vector class.
Definition: CRNVector.h:42
iterator end()
Returns a iterator to the end of the list.
Definition: CRNVector.h:102
size_t Size() const noexcept
Returns the number of data objects in the map.
Definition: CRNMap.h:56
bool IsEmpty() const noexcept
Tests if the map is empty.
Definition: CRNMap.h:58
Data map class.
Definition: CRNMap.h:42
A widget for ternary values representation.
Definition: GtkCRNProp3.h:40
A character string class.
Definition: CRNStringUTF8.h:49
Gtk::Widget * create_widget_from_object(const crn::Object *obj)
Creates a widget to display an object.
A ternary proposition.
Definition: CRNProp3.h:40
iterator end()
Returns an iterator after the last element.
Definition: CRNMap.h:88
bool IsEmpty() const noexcept
Tests if the vector is empty.
Definition: CRNVector.h:58