1 /*
2 * Authors:
3 * Ted Gould <ted@gould.cx>
4 *
5 * Copyright (C) 2005-2007 Authors
6 *
7 * Released under GNU GPL, read the file 'COPYING' for more information
8 */
10 #include <gtkmm/stock.h>
11 #include <gtkmm/checkbutton.h>
12 #include <gtkmm/separator.h>
13 #include <glibmm/i18n.h>
15 #include "../dialogs/dialog-events.h"
16 #include "xml/repr.h"
18 // Used to get SP_ACTIVE_DESKTOP
19 #include "inkscape.h"
20 #include "desktop.h"
22 #include "preferences.h"
23 #include "effect.h"
25 #include "prefdialog.h"
28 namespace Inkscape {
29 namespace Extension {
32 /** \brief Creates a new preference dialog for extension preferences
33 \param name Name of the Extension who's dialog this is
34 \param help The help string for the extension (NULL if none)
35 \param controls The extension specific widgets in the dialog
37 This function initializes the dialog with the name of the extension
38 in the title. It adds a few buttons and sets up handlers for
39 them. It also places the passed in widgets into the dialog.
40 */
41 PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls, ExecutionEnv * exEnv, Effect * effect, sigc::signal<void> * changeSignal) :
42 Gtk::Dialog::Dialog(_(name.c_str()), true, true),
43 _help(help),
44 _name(name),
45 _exEnv(exEnv),
46 _createdExEnv(false),
47 _button_ok(NULL),
48 _button_cancel(NULL),
49 _button_preview(NULL),
50 _param_preview(NULL),
51 _signal_param_change(changeSignal),
52 _effect(effect)
53 {
54 Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox());
55 hbox->pack_start(*controls, true, true, 6);
56 hbox->show();
57 this->get_vbox()->pack_start(*hbox, true, true, 6);
59 /*
60 Gtk::Button * help_button = add_button(Gtk::Stock::HELP, Gtk::RESPONSE_HELP);
61 if (_help == NULL)
62 help_button->set_sensitive(false);
63 */
64 _button_cancel = add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CANCEL);
65 _button_cancel->set_use_stock(true);
67 _button_ok = add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
68 _button_ok->set_use_stock(true);
69 set_default_response(Gtk::RESPONSE_OK);
70 _button_ok->grab_focus();
72 // If we're working with an effect that can be live and
73 // the dialog can be pinned, put those options in too
74 if (_exEnv != NULL) {
75 if (_param_preview == NULL) {
76 XML::Document * doc = sp_repr_read_mem(live_param_xml, strlen(live_param_xml), NULL);
77 _param_preview = Parameter::make(doc->root(), _exEnv->_effect);
78 }
80 Gtk::HSeparator * sep = Gtk::manage(new Gtk::HSeparator());
81 sep->show();
82 this->get_vbox()->pack_start(*sep, true, true, 4);
84 hbox = Gtk::manage(new Gtk::HBox());
85 _button_preview = _param_preview->get_widget(NULL, NULL, &_signal_preview);
86 _button_preview->show();
87 hbox->pack_start(*_button_preview, true, true,6);
88 hbox->show();
89 this->get_vbox()->pack_start(*hbox, true, true, 6);
91 preview_toggle();
92 _signal_preview.connect(sigc::mem_fun(this, &PrefDialog::preview_toggle));
94 }
96 GtkWidget *dlg = GTK_WIDGET(gobj());
97 sp_transientize(dlg);
99 if (_effect != NULL) {
100 _effect->set_pref_dialog(this);
101 }
103 return;
104 }
106 PrefDialog::~PrefDialog ( )
107 {
108 if (_effect != NULL) {
109 _effect->set_pref_dialog(NULL);
110 }
111 if (_param_preview != NULL) {
112 delete _param_preview;
113 }
115 return;
116 }
118 /** \brief Runs the dialog
119 \return The response to the dialog
121 This function overrides the run function in the GTKmm dialog
122 class, but basically it only calls it. This function only
123 handles the \c Gtk::RESPONSE_HELP return, and in that case it
124 brings up the help window. All other return values are returned
125 to the calling function.
126 */
127 int
128 PrefDialog::run (void) {
129 int resp = Gtk::RESPONSE_HELP;
130 while (resp == Gtk::RESPONSE_HELP) {
131 resp = Gtk::Dialog::run();
132 if (resp == Gtk::RESPONSE_HELP) {
133 /*
134 if (_helpDialog == NULL) {
135 _helpDialog = new HelpDialog(_help);
136 }
137 */
138 }
139 }
140 return resp;
141 }
143 void
144 PrefDialog::setPreviewState (Glib::ustring state) {
145 (void)state;
146 }
148 void
149 PrefDialog::preview_toggle (void) {
150 if(_param_preview->get_bool(NULL, NULL)) {
151 set_modal(true);
152 if (_exEnv == NULL) {
153 _exEnv = new ExecutionEnv(_effect, SP_ACTIVE_DESKTOP, NULL, _signal_param_change, this);
154 _createdExEnv = true;
155 _exEnv->livePreview(true);
156 _exEnv->run();
157 }
158 } else {
159 set_modal(false);
160 if (_exEnv != NULL) {
161 _exEnv->livePreview(false);
162 _exEnv->shutdown(_createdExEnv);
163 _exEnv = NULL;
164 }
165 }
166 }
168 void
169 PrefDialog::on_response (int signal) {
170 if (_exEnv != NULL) {
171 _param_preview->set_bool(false, NULL, NULL);
172 return;
173 }
175 if (signal == Gtk::RESPONSE_OK) {
176 _effect->effect(SP_ACTIVE_DESKTOP);
177 }
178 if (signal == Gtk::RESPONSE_CANCEL) {
179 // close the dialog
180 delete this;
181 }
183 return;
184 }
186 #include "internal/clear-n_.h"
188 const char * PrefDialog::live_param_xml = "<param name=\"__live_effect__\" type=\"boolean\" gui-text=\"" N_("Live Preview") "\" gui-description=\"" N_("Controls whether the effect settings are rendered live on canvas") "\" scope=\"user\">false</param>";
190 }; }; /* namespace Inkscape, Extension */
192 /*
193 Local Variables:
194 mode:c++
195 c-file-style:"stroustrup"
196 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
197 indent-tabs-mode:nil
198 fill-column:99
199 End:
200 */
201 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :