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 ("An unknown RDF format was requested.");
53 }
55 g_assert (obj);
56 obj->_label.show();
57 return obj;
58 }
60 EntityEntry::EntityEntry (rdf_work_entity_t* ent, Gtk::Tooltips& tt, Registry& wr)
61 : _label(Glib::ustring(_(ent->title))+":", 1.0, 0.5), _packable(0),
62 _entity(ent), _tt(&tt), _wr(&wr)
63 {
64 }
66 EntityEntry::~EntityEntry()
67 {
68 _changed_connection.disconnect();
69 }
71 EntityLineEntry::EntityLineEntry (rdf_work_entity_t* ent, Gtk::Tooltips& tt, Registry& wr)
72 : EntityEntry (ent, tt, wr)
73 {
74 Gtk::Entry *e = new Gtk::Entry;
75 tt.set_tip (*e, _(ent->tip));
76 _packable = e;
77 _changed_connection = e->signal_changed().connect (sigc::mem_fun (*this, &EntityLineEntry::on_changed));
78 }
80 EntityLineEntry::~EntityLineEntry()
81 {
82 delete static_cast<Gtk::Entry*>(_packable);
83 }
85 void
86 EntityLineEntry::update (SPDocument *doc)
87 {
88 const char *text = rdf_get_work_entity (doc, _entity);
89 static_cast<Gtk::Entry*>(_packable)->set_text (text ? text : "");
90 }
92 void
93 EntityLineEntry::on_changed()
94 {
95 if (_wr->isUpdating()) return;
97 _wr->setUpdating (true);
98 SPDocument *doc = SP_ACTIVE_DOCUMENT;
99 Glib::ustring text = static_cast<Gtk::Entry*>(_packable)->get_text();
100 if (rdf_set_work_entity (doc, _entity, text.c_str()))
101 sp_document_done (doc, SP_VERB_NONE,
102 /* TODO: annotate */ "entity-entry.cpp:101");
103 _wr->setUpdating (false);
104 }
106 EntityMultiLineEntry::EntityMultiLineEntry (rdf_work_entity_t* ent, Gtk::Tooltips& tt, Registry& wr)
107 : EntityEntry (ent, tt, wr)
108 {
109 Gtk::ScrolledWindow *s = new Gtk::ScrolledWindow;
110 s->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
111 s->set_shadow_type (Gtk::SHADOW_IN);
112 _packable = s;
113 _v.set_size_request (-1, 5);
114 _v.set_wrap_mode (Gtk::WRAP_WORD);
115 _v.set_accepts_tab (false);
116 s->add (_v);
117 tt.set_tip (_v, _(ent->tip));
118 _changed_connection = _v.get_buffer()->signal_changed().connect (sigc::mem_fun (*this, &EntityMultiLineEntry::on_changed));
119 }
121 EntityMultiLineEntry::~EntityMultiLineEntry()
122 {
123 delete static_cast<Gtk::ScrolledWindow*>(_packable);
124 }
126 void
127 EntityMultiLineEntry::update (SPDocument *doc)
128 {
129 const char *text = rdf_get_work_entity (doc, _entity);
130 Gtk::ScrolledWindow *s = static_cast<Gtk::ScrolledWindow*>(_packable);
131 Gtk::TextView *tv = static_cast<Gtk::TextView*>(s->get_child());
132 tv->get_buffer()->set_text (text ? text : "");
133 }
135 void
136 EntityMultiLineEntry::on_changed()
137 {
138 if (_wr->isUpdating()) return;
140 _wr->setUpdating (true);
141 SPDocument *doc = SP_ACTIVE_DOCUMENT;
142 Gtk::ScrolledWindow *s = static_cast<Gtk::ScrolledWindow*>(_packable);
143 Gtk::TextView *tv = static_cast<Gtk::TextView*>(s->get_child());
144 Glib::ustring text = tv->get_buffer()->get_text();
145 if (rdf_set_work_entity (doc, _entity, text.c_str()))
146 sp_document_done (doc, SP_VERB_NONE,
147 /* TODO: annotate */ "entity-entry.cpp:146");
148 _wr->setUpdating (false);
149 }
151 } // namespace Dialog
152 } // namespace UI
153 } // namespace Inkscape
155 /*
156 Local Variables:
157 mode:c++
158 c-file-style:"stroustrup"
159 c-file-offsets:((innamespace . 0)(inline-open . 0))
160 indent-tabs-mode:nil
161 fill-column:99
162 End:
163 */
164 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :