Code

Ok, committed msgloan's patch to convert gbooleans to bools thus completing
[inkscape.git] / src / ui / widget / entity-entry.cpp
1 /** \file
2  *
3  * Authors:
4  *   bulia byak <buliabyak@users.sf.net>
5  *   Bryce W. Harrington <bryce@bryceharrington.org>
6  *   Lauris Kaplinski <lauris@kaplinski.com>
7  *   Jon Phillips <jon@rejon.org>
8  *   Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
9  *
10  * Copyright (C) 2000 - 2005 Authors
11  *
12  * Released under GNU GPL.  Read the file 'COPYING' for more information
13  */
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
19 #include <gtkmm/scrolledwindow.h>
20 #include <gtkmm/entry.h>
22 #include "ui/widget/registry.h"
24 #include "dialogs/rdf.h"
26 #include "inkscape.h"
28 #include "entity-entry.h"
30 namespace Inkscape {
31 namespace UI {
32 namespace Widget {
34 //===================================================
36 //---------------------------------------------------
38 EntityEntry*
39 EntityEntry::create (rdf_work_entity_t* ent, Gtk::Tooltips& tt, Registry& wr)
40 {
41     g_assert (ent);
42     EntityEntry* obj = 0;
43     switch (ent->format)
44     {
45         case RDF_FORMAT_LINE: 
46             obj = new EntityLineEntry (ent, tt, wr);
47             break;
48         case RDF_FORMAT_MULTILINE: 
49             obj = new EntityMultiLineEntry (ent, tt, wr);
50             break;
51         default:
52             g_warning ("Can't happen.");
53     }
55     obj->_label.show();
56     return obj;
57 }
59 EntityEntry::EntityEntry (rdf_work_entity_t* ent, Gtk::Tooltips& tt, Registry& wr)
60 : _label(Glib::ustring(_(ent->title))+":", 1.0, 0.5), _packable(0), 
61   _entity(ent), _tt(&tt), _wr(&wr)
62 {
63 }
65 EntityEntry::~EntityEntry()
66 {
67     _changed_connection.disconnect();
68 }
70 EntityLineEntry::EntityLineEntry (rdf_work_entity_t* ent, Gtk::Tooltips& tt, Registry& wr)
71 : EntityEntry (ent, tt, wr)
72 {
73     Gtk::Entry *e = new Gtk::Entry;
74     tt.set_tip (*e, _(ent->tip));
75     _packable = e;
76     _changed_connection = e->signal_changed().connect (sigc::mem_fun (*this, &EntityLineEntry::on_changed));
77 }
79 EntityLineEntry::~EntityLineEntry()
80 {
81     delete reinterpret_cast<Gtk::Entry*>(_packable);
82 }
84 void 
85 EntityLineEntry::update (SPDocument *doc)
86 {
87     const char *text = rdf_get_work_entity (doc, _entity);
88     reinterpret_cast<Gtk::Entry*>(_packable)->set_text (text ? text : "");
89 }
91 void
92 EntityLineEntry::on_changed()
93 {
94     if (_wr->isUpdating()) return;
96     _wr->setUpdating (true);
97     SPDocument *doc = SP_ACTIVE_DOCUMENT;
98     char const *text = reinterpret_cast<Gtk::Entry*>(_packable)->get_text().c_str();
99     if (rdf_set_work_entity (doc, _entity, text))
100         sp_document_done (doc, SP_VERB_NONE, 
101                           /* TODO: annotate */ "entity-entry.cpp:101");
102     _wr->setUpdating (false);
105 EntityMultiLineEntry::EntityMultiLineEntry (rdf_work_entity_t* ent, Gtk::Tooltips& tt, Registry& wr)
106 : EntityEntry (ent, tt, wr)
108     Gtk::ScrolledWindow *s = new Gtk::ScrolledWindow;
109     s->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
110     s->set_shadow_type (Gtk::SHADOW_IN);
111     _packable = s;
112     _v.set_size_request (-1, 5);
113     _v.set_wrap_mode (Gtk::WRAP_WORD);
114     _v.set_accepts_tab (false);
115     s->add (_v);
116     tt.set_tip (_v, _(ent->tip));
117     _changed_connection = _v.get_buffer()->signal_changed().connect (sigc::mem_fun (*this, &EntityMultiLineEntry::on_changed));
120 EntityMultiLineEntry::~EntityMultiLineEntry()
122     delete reinterpret_cast<Gtk::ScrolledWindow*>(_packable);
125 void 
126 EntityMultiLineEntry::update (SPDocument *doc)
128     const char *text = rdf_get_work_entity (doc, _entity);
129     Gtk::ScrolledWindow *s = reinterpret_cast<Gtk::ScrolledWindow*>(_packable);
130     Gtk::TextView *tv = reinterpret_cast<Gtk::TextView*>(s->get_child());
131     tv->get_buffer()->set_text (text ? text : "");
134 void
135 EntityMultiLineEntry::on_changed()
137     if (_wr->isUpdating()) return;
139     _wr->setUpdating (true);
140     SPDocument *doc = SP_ACTIVE_DOCUMENT;
141     Gtk::ScrolledWindow *s = reinterpret_cast<Gtk::ScrolledWindow*>(_packable);
142     Gtk::TextView *tv = reinterpret_cast<Gtk::TextView*>(s->get_child());
143     char const *text = tv->get_buffer()->get_text().c_str();
144     if (rdf_set_work_entity (doc, _entity, text))
145         sp_document_done (doc, SP_VERB_NONE, 
146                           /* TODO: annotate */ "entity-entry.cpp:146");
147     _wr->setUpdating (false);
150 } // namespace Dialog
151 } // namespace UI
152 } // namespace Inkscape
154 /*
155   Local Variables:
156   mode:c++
157   c-file-style:"stroustrup"
158   c-file-offsets:((innamespace . 0)(inline-open . 0))
159   indent-tabs-mode:nil
160   fill-column:99
161   End:
162 */
163 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :