1 === modified file 'src/desktop-style.cpp'
2 --- src/desktop-style.cpp 2015年05月16日 12:50:10 +0000
3 +++ src/desktop-style.cpp 2015年05月17日 12:22:15 +0000
4 @@ -576,8 +576,8 @@
5 return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
6 }
7
8 - SPPattern *pat = pattern_getroot (pattern);
9 - SPPattern *pat_res = pattern_getroot (pattern_res);
10 + SPPattern *pat = SP_PATTERN (server)->rootPattern();
11 + SPPattern *pat_res = SP_PATTERN (server_res)->rootPattern();
12 if (pat_res != pat) {
13 return QUERY_STYLE_MULTIPLE_DIFFERENT; // different pattern roots
14 }
15
16 === modified file 'src/extension/internal/cairo-render-context.cpp'
17 --- src/extension/internal/cairo-render-context.cpp 2015年05月08日 13:46:25 +0000
18 +++ src/extension/internal/cairo-render-context.cpp 2015年05月17日 12:22:15 +0000
19 @@ -1008,17 +1008,16 @@
20 ps2user = Geom::identity();
21 pcs2dev = Geom::identity();
22
23 - double x = pattern_x(pat);
24 - double y = pattern_y(pat);
25 - double width = pattern_width(pat);
26 - double height = pattern_height(pat);
27 + double x = pat->x();
28 + double y = pat->y();
29 + double width = pat->width();
30 + double height = pat->height();
31 double bbox_width_scaler;
32 double bbox_height_scaler;
33
34 TRACE(("%f x %f pattern\n", width, height));
35
36 - if (pbox && pattern_patternUnits(pat) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) {
37 - //Geom::Affine bbox2user (pbox->x1 - pbox->x0, 0.0, 0.0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0);
38 + if (pbox && pat->patternUnits() == SPPattern::UNITS_OBJECTBOUNDINGBOX) {
39 bbox_width_scaler = pbox->width();
40 bbox_height_scaler = pbox->height();
41 ps2user[4] = x * bbox_width_scaler + pbox->left();
42 @@ -1031,13 +1030,13 @@
43 }
44
45 // apply pattern transformation
46 - Geom::Affine pattern_transform(pattern_patternTransform(pat));
47 + Geom::Affine pattern_transform(pat->getTransform());
48 ps2user *= pattern_transform;
49 Geom::Point ori (ps2user[4], ps2user[5]);
50
51 // create pattern contents coordinate system
52 if (pat->viewBox_set) {
53 - Geom::Rect view_box = *pattern_viewBox(pat);
54 + Geom::Rect view_box = *pat->viewbox();
55
56 double x, y, w, h;
57 x = 0;
58 @@ -1050,7 +1049,7 @@
59 pcs2dev[3] = h / view_box.height();
60 pcs2dev[4] = x - view_box.left() * pcs2dev[0];
61 pcs2dev[5] = y - view_box.top() * pcs2dev[3];
62 - } else if (pbox && pattern_patternContentUnits(pat) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) {
63 + } else if (pbox && pat->patternContentUnits() == SPPattern::UNITS_OBJECTBOUNDINGBOX) {
64 pcs2dev[0] = pbox->width();
65 pcs2dev[3] = pbox->height();
66 }
67
68 === modified file 'src/extension/internal/emf-print.cpp'
69 --- src/extension/internal/emf-print.cpp 2015年04月27日 18:49:22 +0000
70 +++ src/extension/internal/emf-print.cpp 2015年05月17日 12:22:15 +0000
71 @@ -388,8 +388,8 @@
72 } else if (SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style))) { // must be paint-server
73 SPPaintServer *paintserver = style->fill.value.href->getObject();
74 SPPattern *pat = SP_PATTERN(paintserver);
75 - double dwidth = pattern_width(pat);
76 - double dheight = pattern_height(pat);
77 + double dwidth = pat->width();
78 + double dheight = pat->height();
79 width = dwidth;
80 height = dheight;
81 brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor);
82 @@ -573,8 +573,8 @@
83 if (SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style))) { // must be paint-server
84 SPPaintServer *paintserver = style->stroke.value.href->getObject();
85 SPPattern *pat = SP_PATTERN(paintserver);
86 - double dwidth = pattern_width(pat);
87 - double dheight = pattern_height(pat);
88 + double dwidth = pat->width();
89 + double dheight = pat->height();
90 width = dwidth;
91 height = dheight;
92 brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor);
93
94 === modified file 'src/extension/internal/wmf-print.cpp'
95 --- src/extension/internal/wmf-print.cpp 2015年04月27日 18:49:22 +0000
96 +++ src/extension/internal/wmf-print.cpp 2015年05月17日 12:22:15 +0000
97 @@ -380,8 +380,8 @@
98 } else if (SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style))) { // must be paint-server
99 SPPaintServer *paintserver = style->fill.value.href->getObject();
100 SPPattern *pat = SP_PATTERN(paintserver);
101 - double dwidth = pattern_width(pat);
102 - double dheight = pattern_height(pat);
103 + double dwidth = pat->width();
104 + double dheight = pat->height();
105 width = dwidth;
106 height = dheight;
107 brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor);
108
109 === modified file 'src/extension/param/color.cpp'
110 --- src/extension/param/color.cpp 2015年04月27日 23:38:31 +0000
111 +++ src/extension/param/color.cpp 2015年05月17日 12:22:15 +0000
112 @@ -24,41 +24,37 @@
113 #include "color.h"
114
115 #include <color.h>
116 -#include "widgets/sp-color-selector.h"
117 -#include "widgets/sp-color-notebook.h"
118 +#include "ui/widget/color-notebook.h"
119 #include "preferences.h"
120
121 -
122 namespace Inkscape {
123 namespace Extension {
124
125 -void sp_color_param_changed(SPColorSelector *csel, GObject *cp);
126 -
127 -
128 ParamColor::~ParamColor(void)
129 {
130 -
131 + _color_changed.disconnect();
132 }
133
134 guint32 ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ )
135 {
136 - _value = in;
137 + _color_changed.block(true);
138 + _color.setValue(in);
139 + _color_changed.block(false);
140
141 gchar * prefname = this->pref_name();
142 std::string value;
143 string(value);
144 -
145 +
146 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
147 prefs->setString(extension_pref_root + prefname, value);
148 g_free(prefname);
149
150 - return _value;
151 + return in;
152 }
153
154 -ParamColor::ParamColor(const gchar *name, const gchar *guitext, const gchar *desc, const Parameter::_scope_t scope,
155 - bool gui_hidden, const gchar *gui_tip, Inkscape::Extension::Extension *ext,
156 - Inkscape::XML::Node *xml)
157 - : Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(0), _changeSignal(0)
158 +ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
159 + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext),
160 + _changeSignal(0)
161 {
162 const char * defaulthex = NULL;
163 if (xml->firstChild() != NULL)
164 @@ -72,51 +68,46 @@
165 if (!paramval.empty())
166 defaulthex = paramval.data();
167
168 - if (defaulthex)
169 - _value = atoi(defaulthex);
170 + if (defaulthex) {
171 + _color.setValue(atoi(defaulthex));
172 + }
173 + _color_changed = _color.signal_changed.connect(sigc::mem_fun(this, &ParamColor::_onColorChanged));
174 +
175 }
176
177 void ParamColor::string(std::string &string) const
178 {
179 char str[16];
180 - sprintf(str, "%i", _value);
181 + snprintf(str, 16, "%i", _color.value());
182 string += str;
183 }
184
185 Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * changeSignal )
186 {
187 - if (_gui_hidden) return NULL;
188 + using Inkscape::UI::Widget::ColorNotebook;
189 +
190 + if (_gui_hidden) return NULL;
191
192 _changeSignal = new sigc::signal<void>(*changeSignal);
193 - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4));
194 - SPColorSelector* spColorSelector = (SPColorSelector*)sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK);
195
196 - ColorSelector* colorSelector = spColorSelector->base;
197 - if (_value < 1) {
198 - _value = 0xFF000000;
199 + if (_color.value() < 1) {
200 + _color_changed.block(true);
201 + _color.setValue(0xFF000000);
202 + _color_changed.block(false);
203 }
204 - SPColor *color = new SPColor( _value );
205 - float alpha = (_value & 0xff) / 255.0F;
206 - colorSelector->setColorAlpha(*color, alpha);
207 -
208 - hbox->pack_start (*Glib::wrap(&spColorSelector->vbox), true, true, 0);
209 - g_signal_connect(G_OBJECT(spColorSelector), "changed", G_CALLBACK(sp_color_param_changed), (void*)this);
210 -
211 - gtk_widget_show(GTK_WIDGET(spColorSelector));
212 +
213 + Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox(false, 4));
214 + Gtk::Widget *selector = Gtk::manage(new ColorNotebook(_color));
215 + hbox->pack_start (*selector, true, true, 0);
216 + selector->show();
217 hbox->show();
218 -
219 - return dynamic_cast<Gtk::Widget *>(hbox);
220 + return hbox;
221 }
222
223 -void sp_color_param_changed(SPColorSelector *csel, GObject *obj)
224 +void ParamColor::_onColorChanged()
225 {
226 - const SPColor color = csel->base->getColor();
227 - float alpha = csel->base->getAlpha();
228 -
229 - ParamColor* ptr = reinterpret_cast<ParamColor*>(obj);
230 - ptr->set(color.toRGBA32( alpha ), NULL, NULL);
231 -
232 - ptr->_changeSignal->emit();
233 + if (_changeSignal)
234 + _changeSignal->emit();
235 }
236
237 }; /* namespace Extension */
238
239 === modified file 'src/extension/param/color.h'
240 --- src/extension/param/color.h 2012年02月29日 01:16:51 +0000
241 +++ src/extension/param/color.h 2015年05月17日 12:22:15 +0000
242 @@ -9,6 +9,7 @@
243 */
244
245 #include "parameter.h"
246 +#include "ui/selected-color.h"
247
248 class SPDocument;
249
250 @@ -25,14 +26,17 @@
251
252 class ParamColor : public Parameter {
253 private:
254 - guint32 _value;
255 + void _onColorChanged();
256 +
257 + Inkscape::UI::SelectedColor _color;
258 + sigc::connection _color_changed;
259 public:
260 ParamColor(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
261
262 virtual ~ParamColor(void);
263
264 /** Returns \c _value, with a \i const to protect it. */
265 - guint32 get( SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/ ) const { return _value; }
266 + guint32 get( SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/ ) const { return _color.value(); }
267
268 guint32 set (guint32 in, SPDocument * doc, Inkscape::XML::Node * node);
269
270 @@ -44,6 +48,7 @@
271 virtual void string (std::string &string) const;
272
273 sigc::signal<void> * _changeSignal;
274 +
275 }; // class ParamColor
276
277 } // namespace Extension
278
279 === modified file 'src/extension/param/parameter.cpp'
280 --- src/extension/param/parameter.cpp 2014年03月27日 01:33:44 +0000
281 +++ src/extension/param/parameter.cpp 2015年05月17日 12:22:15 +0000
282 @@ -15,6 +15,10 @@
283 # include "config.h"
284 #endif
285
286 +#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
287 +#include <glibmm/threads.h>
288 +#endif
289 +
290 #ifdef linux // does the dollar sign need escaping when passed as string parameter?
291 # define ESCAPE_DOLLAR_COMMANDLINE
292 #endif
293 @@ -26,8 +30,7 @@
294 #include "document-private.h"
295 #include "sp-object.h"
296 #include <color.h>
297 -#include "widgets/sp-color-selector.h"
298 -#include "widgets/sp-color-notebook.h"
299 +#include "ui/widget/color-notebook.h"
300
301 #include "parameter.h"
302 #include "bool.h"
303
304 === modified file 'src/knot-holder-entity.cpp'
305 --- src/knot-holder-entity.cpp 2014年08月04日 16:10:37 +0000
306 +++ src/knot-holder-entity.cpp 2015年05月17日 12:22:15 +0000
307 @@ -140,19 +140,19 @@
308
309 static gdouble sp_pattern_extract_theta(SPPattern const *pat)
310 {
311 - Geom::Affine transf = pat->patternTransform;
312 + Geom::Affine transf = pat->getTransform();
313 return Geom::atan2(transf.xAxis());
314 }
315
316 static Geom::Point sp_pattern_extract_scale(SPPattern const *pat)
317 {
318 - Geom::Affine transf = pat->patternTransform;
319 + Geom::Affine transf = pat->getTransform();
320 return Geom::Point( transf.expansionX(), transf.expansionY() );
321 }
322
323 static Geom::Point sp_pattern_extract_trans(SPPattern const *pat)
324 {
325 - return Geom::Point(pat->patternTransform[4], pat->patternTransform[5]);
326 + return Geom::Point(pat->getTransform()[4], pat->getTransform()[5]);
327 }
328
329 void
330 @@ -191,7 +191,7 @@
331 {
332 SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer());
333
334 - gdouble x = pattern_width(pat);
335 + gdouble x = pat->width();
336 gdouble y = 0;
337 Geom::Point delta = Geom::Point(x,y);
338 Geom::Point scale = sp_pattern_extract_scale(pat);
339 @@ -240,8 +240,8 @@
340
341 // Get the new scale from the position of the knotholder
342 Geom::Point d = p_snapped - sp_pattern_extract_trans(pat);
343 - gdouble pat_x = pattern_width(pat);
344 - gdouble pat_y = pattern_height(pat);
345 + gdouble pat_x = pat->width();
346 + gdouble pat_y = pat->height();
347 Geom::Scale scl(1);
348 if ( state & GDK_CONTROL_MASK ) {
349 // if ctrl is pressed: use 1:1 scaling
350 @@ -267,10 +267,10 @@
351 {
352 SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer());
353
354 - gdouble x = pattern_width(pat);
355 - gdouble y = pattern_height(pat);
356 + gdouble x = pat->width();
357 + gdouble y = pat->height();
358 Geom::Point delta = Geom::Point(x,y);
359 - Geom::Affine a = pat->patternTransform;
360 + Geom::Affine a = pat->getTransform();
361 a[4] = 0;
362 a[5] = 0;
363 delta = delta * a;
364
365 === modified file 'src/selection-chemistry.cpp'
366 --- src/selection-chemistry.cpp 2015年05月09日 12:59:00 +0000
367 +++ src/selection-chemistry.cpp 2015年05月17日 12:22:15 +0000
368 @@ -1963,8 +1963,8 @@
369 }
370
371 } else if (dynamic_cast<SPPattern *>(sel_server) && dynamic_cast<SPPattern *>(iter_server)) {
372 - SPPattern *sel_pat = pattern_getroot(dynamic_cast<SPPattern *>(sel_server));
373 - SPPattern *iter_pat = pattern_getroot(dynamic_cast<SPPattern *>(iter_server));
374 + SPPattern *sel_pat = dynamic_cast<SPPattern *>(sel_server)->rootPattern();
375 + SPPattern *iter_pat = dynamic_cast<SPPattern *>(iter_server)->rootPattern();
376 if (sel_pat == iter_pat) {
377 match = true;
378 }
379 @@ -3312,7 +3312,7 @@
380 int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
381 prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
382
383 - gchar const *pat_id = pattern_tile(repr_copies, bbox, doc,
384 + gchar const *pat_id = SPPattern::produce(repr_copies, bbox, doc,
385 ( Geom::Affine(Geom::Translate(desktop->dt2doc(Geom::Point(r->min()[Geom::X],
386 r->max()[Geom::Y]))))
387 * parent_transform.inverse() ),
388 @@ -3390,9 +3390,9 @@
389
390 did = true;
391
392 - SPPattern *pattern = pattern_getroot(basePat);
393 + SPPattern *pattern = basePat->rootPattern();
394
395 - Geom::Affine pat_transform = pattern_patternTransform(basePat);
396 + Geom::Affine pat_transform = basePat->getTransform();
397 pat_transform *= item->transform;
398
399 for (SPObject *child = pattern->firstChild() ; child != NULL; child = child->next ) {
400
401 === modified file 'src/sp-item.cpp'
402 --- src/sp-item.cpp 2015年05月10日 21:55:55 +0000
403 +++ src/sp-item.cpp 2015年05月17日 12:22:15 +0000
404 @@ -1222,8 +1222,8 @@
405 SPObject *server = style->getFillPaintServer();
406 SPPattern *serverPatt = dynamic_cast<SPPattern *>(server);
407 if ( serverPatt ) {
408 - SPPattern *pattern = sp_pattern_clone_if_necessary(this, serverPatt, "fill");
409 - sp_pattern_transform_multiply(pattern, postmul, set);
410 + SPPattern *pattern = serverPatt->clone_if_necessary(this, "fill");
411 + pattern->transform_multiply(postmul, set);
412 }
413 }
414
415 @@ -1232,8 +1232,8 @@
416 SPObject *server = style->getStrokePaintServer();
417 SPPattern *serverPatt = dynamic_cast<SPPattern *>(server);
418 if ( serverPatt ) {
419 - SPPattern *pattern = sp_pattern_clone_if_necessary(this, serverPatt, "stroke");
420 - sp_pattern_transform_multiply(pattern, postmul, set);
421 + SPPattern *pattern = serverPatt->clone_if_necessary(this, "stroke");
422 + pattern->transform_multiply(postmul, set);
423 }
424 }
425 }
426
427 === modified file 'src/sp-pattern.cpp'
428 --- src/sp-pattern.cpp 2015年04月26日 09:44:42 +0000
429 +++ src/sp-pattern.cpp 2015年05月17日 12:22:15 +0000
430 @@ -5,7 +5,7 @@
431 * Lauris Kaplinski <lauris@kaplinski.com>
432 * bulia byak <buliabyak@users.sf.net>
433 * Jon A. Cruz <jon@joncruz.org>
434 - * Abhishek Sharma
435 + * Abhishek Sharma
436 *
437 * Copyright (C) 2002 Lauris Kaplinski
438 *
439 @@ -13,15 +13,15 @@
440 */
441
442 #ifdef HAVE_CONFIG_H
443 -# include "config.h"
444 +#include "config.h"
445 #endif
446
447 #include <cstring>
448 #include <string>
449 #include <glibmm.h>
450 #include <2geom/transforms.h>
451 +#include <sigc++/functors/mem_fun.h>
452
453 -#include "macros.h"
454 #include "svg/svg.h"
455 #include "display/cairo-utils.h"
456 #include "display/drawing-context.h"
457 @@ -34,67 +34,61 @@
458 #include "style.h"
459 #include "sp-pattern.h"
460 #include "xml/repr.h"
461 -#include "display/grayscale.h"
462 -
463 -#include <sigc++/functors/ptr_fun.h>
464 -#include <sigc++/adaptors/bind.h>
465 -
466 -/*
467 - * Pattern
468 - */
469 -static void pattern_ref_changed(SPObject *old_ref, SPObject *ref, SPPattern *pat);
470 -static void pattern_ref_modified (SPObject *ref, guint flags, SPPattern *pattern);
471 -
472 -SPPattern::SPPattern() : SPPaintServer(), SPViewBox() {
473 - this->href = NULL;
474 -
475 - this->ref = new SPPatternReference(this);
476 - this->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(pattern_ref_changed), this));
477 -
478 - this->patternUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX;
479 - this->patternUnits_set = FALSE;
480 -
481 - this->patternContentUnits = SP_PATTERN_UNITS_USERSPACEONUSE;
482 - this->patternContentUnits_set = FALSE;
483 -
484 - this->patternTransform = Geom::identity();
485 - this->patternTransform_set = FALSE;
486 -
487 - this->x.unset();
488 - this->y.unset();
489 - this->width.unset();
490 - this->height.unset();
491 -}
492 -
493 -SPPattern::~SPPattern() {
494 -}
495 -
496 -void SPPattern::build(SPDocument* doc, Inkscape::XML::Node* repr) {
497 - SPPaintServer::build(doc, repr);
498 -
499 - this->readAttr( "patternUnits" );
500 - this->readAttr( "patternContentUnits" );
501 - this->readAttr( "patternTransform" );
502 - this->readAttr( "x" );
503 - this->readAttr( "y" );
504 - this->readAttr( "width" );
505 - this->readAttr( "height" );
506 - this->readAttr( "viewBox" );
507 - this->readAttr( "preserveAspectRatio" );
508 - this->readAttr( "xlink:href" );
509 -
510 - /* Register ourselves */
511 - doc->addResource("pattern", this);
512 -}
513 -
514 -void SPPattern::release() {
515 +
516 +#include "sp-factory.h"
517 +
518 +SPPattern::SPPattern()
519 + : SPPaintServer()
520 + , SPViewBox()
521 +{
522 + this->ref = new SPPatternReference(this);
523 + this->ref->changedSignal().connect(sigc::mem_fun(this, &SPPattern::_onRefChanged));
524 +
525 + this->_pattern_units = UNITS_OBJECTBOUNDINGBOX;
526 + this->_pattern_units_set = false;
527 +
528 + this->_pattern_content_units = UNITS_USERSPACEONUSE;
529 + this->_pattern_content_units_set = false;
530 +
531 + this->_pattern_transform = Geom::identity();
532 + this->_pattern_transform_set = false;
533 +
534 + this->_x.unset();
535 + this->_y.unset();
536 + this->_width.unset();
537 + this->_height.unset();
538 +}
539 +
540 +SPPattern::~SPPattern() {}
541 +
542 +void SPPattern::build(SPDocument *doc, Inkscape::XML::Node *repr)
543 +{
544 + SPPaintServer::build(doc, repr);
545 +
546 + this->readAttr("patternUnits");
547 + this->readAttr("patternContentUnits");
548 + this->readAttr("patternTransform");
549 + this->readAttr("x");
550 + this->readAttr("y");
551 + this->readAttr("width");
552 + this->readAttr("height");
553 + this->readAttr("viewBox");
554 + this->readAttr("preserveAspectRatio");
555 + this->readAttr("xlink:href");
556 +
557 + /* Register ourselves */
558 + doc->addResource("pattern", this);
559 +}
560 +
561 +void SPPattern::release()
562 +{
563 if (this->document) {
564 // Unregister ourselves
565 this->document->removeResource("pattern", this);
566 }
567
568 if (this->ref) {
569 - this->modified_connection.disconnect();
570 + this->_modified_connection.disconnect();
571 this->ref->detach();
572 delete this->ref;
573 this->ref = NULL;
574 @@ -103,113 +97,121 @@
575 SPPaintServer::release();
576 }
577
578 -void SPPattern::set(unsigned int key, const gchar* value) {
579 - switch (key) {
580 - case SP_ATTR_PATTERNUNITS:
581 - if (value) {
582 - if (!strcmp (value, "userSpaceOnUse")) {
583 - this->patternUnits = SP_PATTERN_UNITS_USERSPACEONUSE;
584 - } else {
585 - this->patternUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX;
586 - }
587 -
588 - this->patternUnits_set = TRUE;
589 - } else {
590 - this->patternUnits_set = FALSE;
591 - }
592 -
593 - this->requestModified(SP_OBJECT_MODIFIED_FLAG);
594 - break;
595 -
596 - case SP_ATTR_PATTERNCONTENTUNITS:
597 - if (value) {
598 - if (!strcmp (value, "userSpaceOnUse")) {
599 - this->patternContentUnits = SP_PATTERN_UNITS_USERSPACEONUSE;
600 - } else {
601 - this->patternContentUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX;
602 - }
603 -
604 - this->patternContentUnits_set = TRUE;
605 - } else {
606 - this->patternContentUnits_set = FALSE;
607 - }
608 -
609 - this->requestModified(SP_OBJECT_MODIFIED_FLAG);
610 - break;
611 -
612 - case SP_ATTR_PATTERNTRANSFORM: {
613 - Geom::Affine t;
614 -
615 - if (value && sp_svg_transform_read (value, &t)) {
616 - this->patternTransform = t;
617 - this->patternTransform_set = TRUE;
618 - } else {
619 - this->patternTransform = Geom::identity();
620 - this->patternTransform_set = FALSE;
621 - }
622 -
623 - this->requestModified(SP_OBJECT_MODIFIED_FLAG);
624 - break;
625 - }
626 - case SP_ATTR_X:
627 - this->x.readOrUnset(value);
628 - this->requestModified(SP_OBJECT_MODIFIED_FLAG);
629 - break;
630 -
631 - case SP_ATTR_Y:
632 - this->y.readOrUnset(value);
633 - this->requestModified(SP_OBJECT_MODIFIED_FLAG);
634 - break;
635 -
636 - case SP_ATTR_WIDTH:
637 - this->width.readOrUnset(value);
638 - this->requestModified(SP_OBJECT_MODIFIED_FLAG);
639 - break;
640 -
641 - case SP_ATTR_HEIGHT:
642 - this->height.readOrUnset(value);
643 - this->requestModified(SP_OBJECT_MODIFIED_FLAG);
644 - break;
645 -
646 - case SP_ATTR_VIEWBOX:
647 - set_viewBox( value );
648 +void SPPattern::set(unsigned int key, const gchar *value)
649 +{
650 + switch (key) {
651 + case SP_ATTR_PATTERNUNITS:
652 + if (value) {
653 + if (!strcmp(value, "userSpaceOnUse")) {
654 + this->_pattern_units = UNITS_USERSPACEONUSE;
655 + }
656 + else {
657 + this->_pattern_units = UNITS_OBJECTBOUNDINGBOX;
658 + }
659 +
660 + this->_pattern_units_set = true;
661 + }
662 + else {
663 + this->_pattern_units_set = false;
664 + }
665 +
666 + this->requestModified(SP_OBJECT_MODIFIED_FLAG);
667 + break;
668 +
669 + case SP_ATTR_PATTERNCONTENTUNITS:
670 + if (value) {
671 + if (!strcmp(value, "userSpaceOnUse")) {
672 + this->_pattern_content_units = UNITS_USERSPACEONUSE;
673 + }
674 + else {
675 + this->_pattern_content_units = UNITS_OBJECTBOUNDINGBOX;
676 + }
677 +
678 + this->_pattern_content_units_set = true;
679 + }
680 + else {
681 + this->_pattern_content_units_set = false;
682 + }
683 +
684 + this->requestModified(SP_OBJECT_MODIFIED_FLAG);
685 + break;
686 +
687 + case SP_ATTR_PATTERNTRANSFORM: {
688 + Geom::Affine t;
689 +
690 + if (value && sp_svg_transform_read(value, &t)) {
691 + this->_pattern_transform = t;
692 + this->_pattern_transform_set = true;
693 + }
694 + else {
695 + this->_pattern_transform = Geom::identity();
696 + this->_pattern_transform_set = false;
697 + }
698 +
699 + this->requestModified(SP_OBJECT_MODIFIED_FLAG);
700 + break;
701 + }
702 + case SP_ATTR_X:
703 + this->_x.readOrUnset(value);
704 + this->requestModified(SP_OBJECT_MODIFIED_FLAG);
705 + break;
706 +
707 + case SP_ATTR_Y:
708 + this->_y.readOrUnset(value);
709 + this->requestModified(SP_OBJECT_MODIFIED_FLAG);
710 + break;
711 +
712 + case SP_ATTR_WIDTH:
713 + this->_width.readOrUnset(value);
714 + this->requestModified(SP_OBJECT_MODIFIED_FLAG);
715 + break;
716 +
717 + case SP_ATTR_HEIGHT:
718 + this->_height.readOrUnset(value);
719 + this->requestModified(SP_OBJECT_MODIFIED_FLAG);
720 + break;
721 +
722 + case SP_ATTR_VIEWBOX:
723 + set_viewBox(value);
724 this->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
725 break;
726
727 case SP_ATTR_PRESERVEASPECTRATIO:
728 - set_preserveAspectRatio( value );
729 + set_preserveAspectRatio(value);
730 this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
731 break;
732
733 - case SP_ATTR_XLINK_HREF:
734 - if ( value && this->href && ( strcmp(value, this->href) == 0 ) ) {
735 - /* Href unchanged, do nothing. */
736 - } else {
737 - g_free(this->href);
738 - this->href = NULL;
739 -
740 - if (value) {
741 - // First, set the href field; it's only used in the "unchanged" check above.
742 - this->href = g_strdup(value);
743 - // Now do the attaching, which emits the changed signal.
744 - if (value) {
745 - try {
746 - this->ref->attach(Inkscape::URI(value));
747 - } catch (Inkscape::BadURIException &e) {
748 - g_warning("%s", e.what());
749 - this->ref->detach();
750 - }
751 - } else {
752 - this->ref->detach();
753 - }
754 - }
755 - }
756 - break;
757 -
758 - default:
759 - SPPaintServer::set(key, value);
760 - break;
761 - }
762 + case SP_ATTR_XLINK_HREF:
763 + if (value && this->href == value) {
764 + /* Href unchanged, do nothing. */
765 + }
766 + else {
767 + this->href.clear();
768 +
769 + if (value) {
770 + // First, set the href field; it's only used in the "unchanged" check above.
771 + this->href = value;
772 + // Now do the attaching, which emits the changed signal.
773 + if (value) {
774 + try {
775 + this->ref->attach(Inkscape::URI(value));
776 + }
777 + catch (Inkscape::BadURIException &e) {
778 + g_warning("%s", e.what());
779 + this->ref->detach();
780 + }
781 + }
782 + else {
783 + this->ref->detach();
784 + }
785 + }
786 + }
787 + break;
788 +
789 + default:
790 + SPPaintServer::set(key, value);
791 + break;
792 + }
793 }
794
795
796 @@ -217,104 +219,90 @@
797
798 /* fixme: We need ::order_changed handler too (Lauris) */
799
800 -static GSList *pattern_getchildren(SPPattern *pat)
801 +void SPPattern::_getChildren(std::list<SPObject *> &l)
802 {
803 - GSList *l = NULL;
804 -
805 - for (SPPattern *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
806 + for (SPPattern *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
807 if (pat_i->firstChild()) { // find the first one with children
808 - for (SPObject *child = pat->firstChild() ; child ; child = child->getNext() ) {
809 - l = g_slist_prepend (l, child);
810 - }
811 - break; // do not go further up the chain if children are found
812 - }
813 - }
814 -
815 - return l;
816 -}
817 -
818 -void SPPattern::update(SPCtx* ctx, unsigned int flags) {
819 - if (flags & SP_OBJECT_MODIFIED_FLAG) {
820 - flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
821 - }
822 -
823 - flags &= SP_OBJECT_MODIFIED_CASCADE;
824 -
825 - GSList *l = pattern_getchildren (this);
826 - l = g_slist_reverse (l);
827 -
828 - while (l) {
829 - SPObject *child = SP_OBJECT (l->data);
830 -
831 - sp_object_ref (child, NULL);
832 - l = g_slist_remove (l, child);
833 -
834 - if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
835 - child->updateDisplay(ctx, flags);
836 - }
837 -
838 - sp_object_unref (child, NULL);
839 - }
840 -}
841 -
842 -void SPPattern::modified(unsigned int flags) {
843 - if (flags & SP_OBJECT_MODIFIED_FLAG) {
844 - flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
845 - }
846 -
847 - flags &= SP_OBJECT_MODIFIED_CASCADE;
848 -
849 - GSList *l = pattern_getchildren (this);
850 - l = g_slist_reverse (l);
851 -
852 - while (l) {
853 - SPObject *child = SP_OBJECT (l->data);
854 -
855 - sp_object_ref (child, NULL);
856 - l = g_slist_remove (l, child);
857 -
858 - if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
859 - child->emitModified(flags);
860 - }
861 -
862 - sp_object_unref (child, NULL);
863 - }
864 -}
865 -
866 -/**
867 -Gets called when the pattern is reattached to another <pattern>
868 -*/
869 -static void
870 -pattern_ref_changed(SPObject *old_ref, SPObject *ref, SPPattern *pat)
871 -{
872 - if (old_ref) {
873 - pat->modified_connection.disconnect();
874 - }
875 -
876 - if (SP_IS_PATTERN (ref)) {
877 - pat->modified_connection = ref->connectModified(sigc::bind<2>(sigc::ptr_fun(&pattern_ref_modified), pat));
878 - }
879 -
880 - pattern_ref_modified (ref, 0, pat);
881 -}
882 -
883 -/**
884 -Gets called when the referenced <pattern> is changed
885 -*/
886 -static void pattern_ref_modified (SPObject */*ref*/, guint /*flags*/, SPPattern *pattern)
887 -{
888 - if ( SP_IS_OBJECT(pattern) ) {
889 - pattern->requestModified(SP_OBJECT_MODIFIED_FLAG);
890 - }
891 + for (SPObject *child = pat_i->firstChild(); child; child = child->getNext()) {
892 + l.push_back(child);
893 + }
894 + break; // do not go further up the chain if children are found
895 + }
896 + }
897 +}
898 +
899 +void SPPattern::update(SPCtx *ctx, unsigned int flags)
900 +{
901 + typedef std::list<SPObject *>::iterator SPObjectIterator;
902 +
903 + if (flags & SP_OBJECT_MODIFIED_FLAG) {
904 + flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
905 + }
906 +
907 + flags &= SP_OBJECT_MODIFIED_CASCADE;
908 +
909 + std::list<SPObject *> l;
910 + _getChildren(l);
911 +
912 + for (SPObjectIterator it = l.begin(); it != l.end(); it++) {
913 + SPObject *child = *it;
914 +
915 + sp_object_ref(child, NULL);
916 +
917 + if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
918 + child->updateDisplay(ctx, flags);
919 + }
920 +
921 + sp_object_unref(child, NULL);
922 + }
923 +}
924 +
925 +void SPPattern::modified(unsigned int flags)
926 +{
927 + typedef std::list<SPObject *>::iterator SPObjectIterator;
928 +
929 + if (flags & SP_OBJECT_MODIFIED_FLAG) {
930 + flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
931 + }
932 +
933 + flags &= SP_OBJECT_MODIFIED_CASCADE;
934 +
935 + std::list<SPObject *> l;
936 + _getChildren(l);
937 +
938 + for (SPObjectIterator it = l.begin(); it != l.end(); it++) {
939 + SPObject *child = *it;
940 +
941 + sp_object_ref(child, NULL);
942 +
943 + if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
944 + child->emitModified(flags);
945 + }
946 +
947 + sp_object_unref(child, NULL);
948 + }
949 +}
950 +
951 +void SPPattern::_onRefChanged(SPObject *old_ref, SPObject *ref)
952 +{
953 + if (old_ref) {
954 + _modified_connection.disconnect();
955 + }
956 +
957 + if (SP_IS_PATTERN(ref)) {
958 + _modified_connection = ref->connectModified(sigc::mem_fun(this, &SPPattern::_onRefModified));
959 + }
960 +
961 + _onRefModified(ref, 0);
962 +}
963 +
964 +void SPPattern::_onRefModified(SPObject * /*ref*/, guint /*flags*/)
965 +{
966 + requestModified(SP_OBJECT_MODIFIED_FLAG);
967 // Conditional to avoid causing infinite loop if there's a cycle in the href chain.
968 }
969
970 -
971 -/**
972 -Count how many times pat is used by the styles of o and its descendants
973 -*/
974 -static guint
975 -count_pattern_hrefs(SPObject *o, SPPattern *pat)
976 +guint SPPattern::_countHrefs(SPObject *o) const
977 {
978 if (!o)
979 return 1;
980 @@ -322,84 +310,79 @@
981 guint i = 0;
982
983 SPStyle *style = o->style;
984 - if (style
985 - && style->fill.isPaintserver()
986 - && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style))
987 - && SP_PATTERN(SP_STYLE_FILL_SERVER(style)) == pat)
988 - {
989 - i ++;
990 + if (style && style->fill.isPaintserver() && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style)) &&
991 + SP_PATTERN(SP_STYLE_FILL_SERVER(style)) == this) {
992 + i++;
993 }
994 - if (style
995 - && style->stroke.isPaintserver()
996 - && SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style))
997 - && SP_PATTERN(SP_STYLE_STROKE_SERVER(style)) == pat)
998 - {
999 - i ++;
1000 + if (style && style->stroke.isPaintserver() && SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style)) &&
1001 + SP_PATTERN(SP_STYLE_STROKE_SERVER(style)) == this) {
1002 + i++;
1003 }
1004
1005 - for ( SPObject *child = o->firstChild(); child != NULL; child = child->next ) {
1006 - i += count_pattern_hrefs(child, pat);
1007 + for (SPObject *child = o->firstChild(); child != NULL; child = child->next) {
1008 + i += _countHrefs(child);
1009 }
1010
1011 return i;
1012 }
1013
1014 -SPPattern *pattern_chain(SPPattern *pattern)
1015 +SPPattern *SPPattern::_chain() const
1016 {
1017 - SPDocument *document = pattern->document;
1018 - Inkscape::XML::Document *xml_doc = document->getReprDoc();
1019 + Inkscape::XML::Document *xml_doc = document->getReprDoc();
1020 Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr();
1021
1022 Inkscape::XML::Node *repr = xml_doc->createElement("svg:pattern");
1023 repr->setAttribute("inkscape:collect", "always");
1024 - gchar *parent_ref = g_strconcat("#", pattern->getRepr()->attribute("id"), NULL);
1025 - repr->setAttribute("xlink:href", parent_ref);
1026 - g_free (parent_ref);
1027 + Glib::ustring parent_ref = Glib::ustring::compose("#%1", getRepr()->attribute("id"));
1028 + repr->setAttribute("xlink:href", parent_ref);
1029
1030 defsrepr->addChild(repr, NULL);
1031 const gchar *child_id = repr->attribute("id");
1032 SPObject *child = document->getObjectById(child_id);
1033 - g_assert (SP_IS_PATTERN (child));
1034 + g_assert(SP_IS_PATTERN(child));
1035
1036 - return SP_PATTERN (child);
1037 + return SP_PATTERN(child);
1038 }
1039
1040 -SPPattern *
1041 -sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *property)
1042 +SPPattern *SPPattern::clone_if_necessary(SPItem *item, const gchar *property)
1043 {
1044 - if (!pattern->href || pattern->hrefcount > count_pattern_hrefs(item, pattern)) {
1045 - pattern = pattern_chain (pattern);
1046 - gchar *href = g_strconcat("url(#", pattern->getRepr()->attribute("id"), ")", NULL);
1047 + SPPattern *pattern = this;
1048 + if (pattern->href.empty() || pattern->hrefcount > _countHrefs(item)) {
1049 + pattern = _chain();
1050 + Glib::ustring href = Glib::ustring::compose("url(#%1)", pattern->getRepr()->attribute("id"));
1051
1052 - SPCSSAttr *css = sp_repr_css_attr_new ();
1053 - sp_repr_css_set_property (css, property, href);
1054 + SPCSSAttr *css = sp_repr_css_attr_new();
1055 + sp_repr_css_set_property(css, property, href.c_str());
1056 sp_repr_css_change_recursive(item->getRepr(), css, "style");
1057 }
1058 return pattern;
1059 }
1060
1061 -void
1062 -sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set)
1063 +void SPPattern::transform_multiply(Geom::Affine postmul, bool set)
1064 {
1065 // this formula is for a different interpretation of pattern transforms as described in (*) in sp-pattern.cpp
1066 // for it to work, we also need sp_object_read_attr( item, "transform");
1067 - //pattern->patternTransform = premul * item->transform * pattern->patternTransform * item->transform.inverse() * postmul;
1068 + // pattern->patternTransform = premul * item->transform * pattern->patternTransform * item->transform.inverse() *
1069 + // postmul;
1070
1071 // otherwise the formula is much simpler
1072 if (set) {
1073 - pattern->patternTransform = postmul;
1074 - } else {
1075 - pattern->patternTransform = pattern_patternTransform(pattern) * postmul;
1076 - }
1077 - pattern->patternTransform_set = TRUE;
1078 + _pattern_transform = postmul;
1079 + }
1080 + else {
1081 + _pattern_transform = getTransform() * postmul;
1082 + }
1083 + _pattern_transform_set = true;
1084
1085 - gchar *c=sp_svg_transform_write(pattern->patternTransform);
1086 - pattern->getRepr()->setAttribute("patternTransform", c);
1087 - g_free(c);
1088 + Glib::ustring c = sp_svg_transform_write(_pattern_transform);
1089 + getRepr()->setAttribute("patternTransform", c);
1090 }
1091
1092 -const gchar *pattern_tile(const std::vector<Inkscape::XML::Node*> &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move)
1093 +const gchar *SPPattern::produce(const std::vector<Inkscape::XML::Node *> &reprs, Geom::Rect bounds,
1094 + SPDocument *document, Geom::Affine transform, Geom::Affine move)
1095 {
1096 + typedef std::vector<Inkscape::XML::Node *>::const_iterator NodePtrIterator;
1097 +
1098 Inkscape::XML::Document *xml_doc = document->getReprDoc();
1099 Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr();
1100
1101 @@ -408,20 +391,19 @@
1102 sp_repr_set_svg_double(repr, "width", bounds.dimensions()[Geom::X]);
1103 sp_repr_set_svg_double(repr, "height", bounds.dimensions()[Geom::Y]);
1104
1105 - gchar *t=sp_svg_transform_write(transform);
1106 + Glib::ustring t = sp_svg_transform_write(transform);
1107 repr->setAttribute("patternTransform", t);
1108 - g_free(t);
1109
1110 defsrepr->appendChild(repr);
1111 const gchar *pat_id = repr->attribute("id");
1112 SPObject *pat_object = document->getObjectById(pat_id);
1113
1114 - for (std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();i++){
1115 + for (NodePtrIterator i = reprs.begin(); i != reprs.end(); i++) {
1116 Inkscape::XML::Node *node = *i;
1117 SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node));
1118
1119 Geom::Affine dup_transform;
1120 - if (!sp_svg_transform_read (node->attribute("transform"), &dup_transform))
1121 + if (!sp_svg_transform_read(node->attribute("transform"), &dup_transform))
1122 dup_transform = Geom::identity();
1123 dup_transform *= move;
1124
1125 @@ -432,14 +414,15 @@
1126 return pat_id;
1127 }
1128
1129 -SPPattern *pattern_getroot(SPPattern *pat)
1130 +SPPattern *SPPattern::rootPattern()
1131 {
1132 - for (SPPattern *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1133 - if ( pat_i->firstChild() ) { // find the first one with children
1134 + for (SPPattern *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1135 + if (pat_i->firstChild()) { // find the first one with children
1136 return pat_i;
1137 }
1138 }
1139 - return pat; // document is broken, we can't get to root; but at least we can return pat which is supposedly a valid pattern
1140 + return this; // document is broken, we can't get to root; but at least we can return pat which is supposedly a valid
1141 + // pattern
1142 }
1143
1144
1145 @@ -447,73 +430,73 @@
1146 // Access functions that look up fields up the chain of referenced patterns and return the first one which is set
1147 // FIXME: all of them must use chase_hrefs the same as in SPGradient, to avoid lockup on circular refs
1148
1149 -guint pattern_patternUnits (SPPattern const *pat)
1150 -{
1151 - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1152 - if (pat_i->patternUnits_set)
1153 - return pat_i->patternUnits;
1154 - }
1155 - return pat->patternUnits;
1156 -}
1157 -
1158 -guint pattern_patternContentUnits (SPPattern const *pat)
1159 -{
1160 - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1161 - if (pat_i->patternContentUnits_set)
1162 - return pat_i->patternContentUnits;
1163 - }
1164 - return pat->patternContentUnits;
1165 -}
1166 -
1167 -Geom::Affine const &pattern_patternTransform(SPPattern const *pat)
1168 -{
1169 - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1170 - if (pat_i->patternTransform_set)
1171 - return pat_i->patternTransform;
1172 - }
1173 - return pat->patternTransform;
1174 -}
1175 -
1176 -gdouble pattern_x (SPPattern const *pat)
1177 -{
1178 - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1179 - if (pat_i->x._set)
1180 - return pat_i->x.computed;
1181 - }
1182 - return 0;
1183 -}
1184 -
1185 -gdouble pattern_y (SPPattern const *pat)
1186 -{
1187 - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1188 - if (pat_i->y._set)
1189 - return pat_i->y.computed;
1190 - }
1191 - return 0;
1192 -}
1193 -
1194 -gdouble pattern_width (SPPattern const* pat)
1195 -{
1196 - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1197 - if (pat_i->width._set)
1198 - return pat_i->width.computed;
1199 - }
1200 - return 0;
1201 -}
1202 -
1203 -gdouble pattern_height (SPPattern const *pat)
1204 -{
1205 - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1206 - if (pat_i->height._set)
1207 - return pat_i->height.computed;
1208 - }
1209 - return 0;
1210 -}
1211 -
1212 -Geom::OptRect pattern_viewBox (SPPattern const *pat)
1213 +SPPattern::PatternUnits SPPattern::patternUnits() const
1214 +{
1215 + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1216 + if (pat_i->_pattern_units_set)
1217 + return pat_i->_pattern_units;
1218 + }
1219 + return _pattern_units;
1220 +}
1221 +
1222 +SPPattern::PatternUnits SPPattern::patternContentUnits() const
1223 +{
1224 + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1225 + if (pat_i->_pattern_content_units_set)
1226 + return pat_i->_pattern_content_units;
1227 + }
1228 + return _pattern_content_units;
1229 +}
1230 +
1231 +Geom::Affine const &SPPattern::getTransform() const
1232 +{
1233 + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1234 + if (pat_i->_pattern_transform_set)
1235 + return pat_i->_pattern_transform;
1236 + }
1237 + return _pattern_transform;
1238 +}
1239 +
1240 +gdouble SPPattern::x() const
1241 +{
1242 + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1243 + if (pat_i->_x._set)
1244 + return pat_i->_x.computed;
1245 + }
1246 + return 0;
1247 +}
1248 +
1249 +gdouble SPPattern::y() const
1250 +{
1251 + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1252 + if (pat_i->_y._set)
1253 + return pat_i->_y.computed;
1254 + }
1255 + return 0;
1256 +}
1257 +
1258 +gdouble SPPattern::width() const
1259 +{
1260 + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1261 + if (pat_i->_width._set)
1262 + return pat_i->_width.computed;
1263 + }
1264 + return 0;
1265 +}
1266 +
1267 +gdouble SPPattern::height() const
1268 +{
1269 + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1270 + if (pat_i->_height._set)
1271 + return pat_i->_height.computed;
1272 + }
1273 + return 0;
1274 +}
1275 +
1276 +Geom::OptRect SPPattern::viewbox() const
1277 {
1278 Geom::OptRect viewbox;
1279 - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1280 + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1281 if (pat_i->viewBox_set) {
1282 viewbox = pat_i->viewBox;
1283 break;
1284 @@ -522,10 +505,10 @@
1285 return viewbox;
1286 }
1287
1288 -static bool pattern_hasItemChildren (SPPattern const *pat)
1289 +bool SPPattern::_hasItemChildren() const
1290 {
1291 bool hasChildren = false;
1292 - for (SPObject const *child = pat->firstChild() ; child && !hasChildren ; child = child->getNext() ) {
1293 + for (SPObject const *child = firstChild(); child && !hasChildren; child = child->getNext()) {
1294 if (SP_IS_ITEM(child)) {
1295 hasChildren = true;
1296 }
1297 @@ -535,15 +518,16 @@
1298
1299 bool SPPattern::isValid() const
1300 {
1301 - double tile_width = pattern_width(this);
1302 - double tile_height = pattern_height(this);
1303 + double tile_width = width();
1304 + double tile_height = height();
1305
1306 - if (tile_width <= 0 || tile_height <= 0)
1307 - return false;
1308 - return true;
1309 + if (tile_width <= 0 || tile_height <= 0)
1310 + return false;
1311 + return true;
1312 }
1313
1314 -cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &bbox, double opacity) {
1315 +cairo_pattern_t *SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &bbox, double opacity)
1316 +{
1317
1318 bool needs_opacity = (1.0 - opacity) >= 1e-3;
1319 bool visible = opacity >= 1e-3;
1320 @@ -557,28 +541,28 @@
1321
1322 for (SPPattern *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) {
1323 // find the first one with item children
1324 - if (pat_i && SP_IS_OBJECT(pat_i) && pattern_hasItemChildren(pat_i)) {
1325 + if (pat_i && SP_IS_OBJECT(pat_i) && pat_i->_hasItemChildren()) {
1326 shown = pat_i;
1327 break; // do not go further up the chain if children are found
1328 }
1329 }
1330
1331 if (!shown) {
1332 - return cairo_pattern_create_rgba(0,0,0,0);
1333 + return cairo_pattern_create_rgba(0, 0, 0, 0);
1334 }
1335
1336 /* Create drawing for rendering */
1337 Inkscape::Drawing drawing;
1338 - unsigned int dkey = SPItem::display_key_new (1);
1339 + unsigned int dkey = SPItem::display_key_new(1);
1340 Inkscape::DrawingGroup *root = new Inkscape::DrawingGroup(drawing);
1341 drawing.setRoot(root);
1342
1343 - for (SPObject *child = shown->firstChild(); child != NULL; child = child->getNext() ) {
1344 - if (SP_IS_ITEM (child)) {
1345 + for (SPObject *child = shown->firstChild(); child != NULL; child = child->getNext()) {
1346 + if (SP_IS_ITEM(child)) {
1347 // for each item in pattern, show it on our drawing, add to the group,
1348 // and connect to the release signal in case the item gets deleted
1349 Inkscape::DrawingItem *cai;
1350 - cai = SP_ITEM(child)->invoke_show (drawing, dkey, SP_ITEM_SHOW_DISPLAY);
1351 + cai = SP_ITEM(child)->invoke_show(drawing, dkey, SP_ITEM_SHOW_DISPLAY);
1352 root->appendChild(cai);
1353 }
1354 }
1355 @@ -591,40 +575,41 @@
1356 // * "x", "y", and "patternTransform" transform tile to user space after tile is generated.
1357
1358 // These functions recursively search up the tree to find the values.
1359 - double tile_x = pattern_x(this);
1360 - double tile_y = pattern_y(this);
1361 - double tile_width = pattern_width(this);
1362 - double tile_height = pattern_height(this);
1363 - if ( bbox && (pattern_patternUnits(this) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) ) {
1364 - tile_x *= bbox->width();
1365 - tile_y *= bbox->height();
1366 - tile_width *= bbox->width();
1367 + double tile_x = x();
1368 + double tile_y = y();
1369 + double tile_width = width();
1370 + double tile_height = height();
1371 + if (bbox && (patternUnits() == UNITS_OBJECTBOUNDINGBOX)) {
1372 + tile_x *= bbox->width();
1373 + tile_y *= bbox->height();
1374 + tile_width *= bbox->width();
1375 tile_height *= bbox->height();
1376 }
1377
1378 // Pattern size in pattern space
1379 Geom::Rect pattern_tile = Geom::Rect::from_xywh(0, 0, tile_width, tile_height);
1380 -
1381 +
1382 // Content to tile (pattern space)
1383 Geom::Affine content2ps;
1384 - Geom::OptRect effective_view_box = pattern_viewBox(this);
1385 + Geom::OptRect effective_view_box = viewbox();
1386 if (effective_view_box) {
1387 - // viewBox to pattern server (using SPViewBox)
1388 + // viewBox to pattern server (using SPViewBox)
1389 viewBox = *effective_view_box;
1390 c2p.setIdentity();
1391 - apply_viewbox( pattern_tile );
1392 + apply_viewbox(pattern_tile);
1393 content2ps = c2p;
1394 - } else {
1395 + }
1396 + else {
1397
1398 // Content to bbox
1399 - if (bbox && (pattern_patternContentUnits(this) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) ) {
1400 - content2ps = Geom::Affine(bbox->width(), 0.0, 0.0, bbox->height(), 0,0);
1401 + if (bbox && (patternContentUnits() == UNITS_OBJECTBOUNDINGBOX)) {
1402 + content2ps = Geom::Affine(bbox->width(), 0.0, 0.0, bbox->height(), 0, 0);
1403 }
1404 }
1405
1406
1407 // Tile (pattern space) to user.
1408 - Geom::Affine ps2user = Geom::Translate(tile_x,tile_y) * pattern_patternTransform(this);
1409 + Geom::Affine ps2user = Geom::Translate(tile_x, tile_y) * getTransform();
1410
1411
1412 // Transform of object with pattern (includes screen scaling)
1413 @@ -644,7 +629,7 @@
1414 // to find the optimum tile size for rendering
1415 // c is number of pixels in buffer x and y.
1416 // Scale factor of 1.1 is too small... see bug #1251039
1417 - Geom::Point c(pattern_tile.dimensions()*ps2user.descrim()*full.descrim()*2.0);
1418 + Geom::Point c(pattern_tile.dimensions() * ps2user.descrim() * full.descrim() * 2.0);
1419
1420 // Create drawing surface with size of pattern tile (in pattern space) but with number of pixels
1421 // based on required resolution (c).
1422 @@ -660,16 +645,16 @@
1423 }
1424
1425 // TODO: make sure there are no leaks.
1426 - Inkscape::UpdateContext ctx; // UpdateContext is structure with only ctm!
1427 + Inkscape::UpdateContext ctx; // UpdateContext is structure with only ctm!
1428 ctx.ctm = content2ps * pattern_surface.drawingTransform();
1429 - dc.transform( pattern_surface.drawingTransform().inverse() );
1430 + dc.transform(pattern_surface.drawingTransform().inverse());
1431 drawing.update(Geom::IntRect::infinite(), ctx);
1432
1433 // Render drawing to pattern_surface via drawing context, this calls root->render
1434 // which is really DrawingItem->render().
1435 drawing.render(dc, one_tile);
1436 - for (SPObject *child = shown->firstChild() ; child != NULL; child = child->getNext() ) {
1437 - if (SP_IS_ITEM (child)) {
1438 + for (SPObject *child = shown->firstChild(); child != NULL; child = child->getNext()) {
1439 + if (SP_IS_ITEM(child)) {
1440 SP_ITEM(child)->invoke_hide(dkey);
1441 }
1442 }
1443 @@ -685,12 +670,12 @@
1444
1445 if (needs_opacity) {
1446 dc.popGroupToSource(); // pop raw pattern
1447 - dc.paint(opacity); // apply opacity
1448 + dc.paint(opacity); // apply opacity
1449 }
1450
1451 cairo_pattern_t *cp = cairo_pattern_create_for_surface(pattern_surface.raw());
1452 // Apply transformation to user space. Also compensate for oversampling.
1453 - ink_cairo_pattern_set_matrix(cp, ps2user.inverse() * pattern_surface.drawingTransform() );
1454 + ink_cairo_pattern_set_matrix(cp, ps2user.inverse() * pattern_surface.drawingTransform());
1455
1456 cairo_pattern_set_extend(cp, CAIRO_EXTEND_REPEAT);
1457
1458
1459 === modified file 'src/sp-pattern.h'
1460 --- src/sp-pattern.h 2015年02月19日 03:25:21 +0000
1461 +++ src/sp-pattern.h 2015年05月17日 12:22:15 +0000
1462 @@ -1,9 +1,6 @@
1463 -#ifndef SEEN_SP_PATTERN_H
1464 -#define SEEN_SP_PATTERN_H
1465 -
1466 -/*
1467 +/** @file
1468 * SVG <pattern> implementation
1469 - *
1470 + *//*
1471 * Author:
1472 * Lauris Kaplinski <lauris@kaplinski.com>
1473 * Abhishek Sharma
1474 @@ -13,95 +10,131 @@
1475 * Released under GNU GPL, read the file 'COPYING' for more information
1476 */
1477
1478 -#define SP_PATTERN(obj) (dynamic_cast<SPPattern*>((SPObject*)obj))
1479 -#define SP_IS_PATTERN(obj) (dynamic_cast<const SPPattern*>((SPObject*)obj) != NULL)
1480 +#ifndef SEEN_SP_PATTERN_H
1481 +#define SEEN_SP_PATTERN_H
1482
1483 -class SPPatternReference;
1484 -class SPItem;
1485 -typedef struct _GSList GSList;
1486 +#include <list>
1487 +#include <stddef.h>
1488 +#include <glibmm/ustring.h>
1489 +#include <sigc++/connection.h>
1490
1491 #include "svg/svg-length.h"
1492 #include "sp-paint-server.h"
1493 #include "uri-references.h"
1494 #include "viewbox.h"
1495
1496 -#include <sigc++/connection.h>
1497 -
1498 +class SPPatternReference;
1499 +class SPItem;
1500 +
1501 +namespace Inkscape {
1502 +namespace XML {
1503 +
1504 +class Node;
1505 +}
1506 +}
1507 +
1508 +#define SP_PATTERN(obj) (dynamic_cast<SPPattern *>((SPObject *)obj))
1509 +#define SP_IS_PATTERN(obj) (dynamic_cast<const SPPattern *>((SPObject *)obj) != NULL)
1510
1511 class SPPattern : public SPPaintServer, public SPViewBox {
1512 public:
1513 - SPPattern();
1514 - virtual ~SPPattern();
1515 + enum PatternUnits { UNITS_USERSPACEONUSE, UNITS_OBJECTBOUNDINGBOX };
1516 +
1517 + SPPattern();
1518 + virtual ~SPPattern();
1519
1520 /* Reference (href) */
1521 - char *href;
1522 + Glib::ustring href;
1523 SPPatternReference *ref;
1524
1525 + gdouble x() const;
1526 + gdouble y() const;
1527 + gdouble width() const;
1528 + gdouble height() const;
1529 + Geom::OptRect viewbox() const;
1530 + SPPattern::PatternUnits patternUnits() const;
1531 + SPPattern::PatternUnits patternContentUnits() const;
1532 + Geom::Affine const &getTransform() const;
1533 + SPPattern *rootPattern(); // TODO: const
1534 +
1535 + SPPattern *clone_if_necessary(SPItem *item, const gchar *property);
1536 + void transform_multiply(Geom::Affine postmul, bool set);
1537 +
1538 + /**
1539 + * @brief create a new pattern in XML tree
1540 + * @return created pattern id
1541 + */
1542 + static const gchar *produce(const std::vector<Inkscape::XML::Node *> &reprs, Geom::Rect bounds,
1543 + SPDocument *document, Geom::Affine transform, Geom::Affine move);
1544 +
1545 + bool isValid() const;
1546 +
1547 + virtual cairo_pattern_t *pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity);
1548 +
1549 +protected:
1550 + virtual void build(SPDocument *doc, Inkscape::XML::Node *repr);
1551 + virtual void release();
1552 + virtual void set(unsigned int key, const gchar *value);
1553 + virtual void update(SPCtx *ctx, unsigned int flags);
1554 + virtual void modified(unsigned int flags);
1555 +
1556 +private:
1557 + bool _hasItemChildren() const;
1558 + void _getChildren(std::list<SPObject *> &l);
1559 + SPPattern *_chain() const;
1560 +
1561 + /**
1562 + Count how many times pattern is used by the styles of o and its descendants
1563 + */
1564 + guint _countHrefs(SPObject *o) const;
1565 +
1566 + /**
1567 + Gets called when the pattern is reattached to another <pattern>
1568 + */
1569 + void _onRefChanged(SPObject *old_ref, SPObject *ref);
1570 +
1571 + /**
1572 + Gets called when the referenced <pattern> is changed
1573 + */
1574 + void _onRefModified(SPObject *ref, guint flags);
1575 +
1576 /* patternUnits and patternContentUnits attribute */
1577 - unsigned int patternUnits : 1;
1578 - unsigned int patternUnits_set : 1;
1579 - unsigned int patternContentUnits : 1;
1580 - unsigned int patternContentUnits_set : 1;
1581 + PatternUnits _pattern_units : 1;
1582 + bool _pattern_units_set : 1;
1583 + PatternUnits _pattern_content_units : 1;
1584 + bool _pattern_content_units_set : 1;
1585 /* patternTransform attribute */
1586 - Geom::Affine patternTransform;
1587 - unsigned int patternTransform_set : 1;
1588 + Geom::Affine _pattern_transform;
1589 + bool _pattern_transform_set : 1;
1590 /* Tile rectangle */
1591 - SVGLength x;
1592 - SVGLength y;
1593 - SVGLength width;
1594 - SVGLength height;
1595 -
1596 - sigc::connection modified_connection;
1597 -
1598 - bool isValid() const;
1599 -
1600 - virtual cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity);
1601 -
1602 -protected:
1603 - virtual void build(SPDocument* doc, Inkscape::XML::Node* repr);
1604 - virtual void release();
1605 - virtual void set(unsigned int key, const gchar* value);
1606 - virtual void update(SPCtx* ctx, unsigned int flags);
1607 - virtual void modified(unsigned int flags);
1608 + SVGLength _x;
1609 + SVGLength _y;
1610 + SVGLength _width;
1611 + SVGLength _height;
1612 +
1613 + sigc::connection _modified_connection;
1614 };
1615
1616
1617 class SPPatternReference : public Inkscape::URIReference {
1618 public:
1619 - SPPatternReference (SPObject *obj) : URIReference(obj) {}
1620 - SPPattern *getObject() const {
1621 + SPPatternReference(SPObject *obj)
1622 + : URIReference(obj)
1623 + {
1624 + }
1625 +
1626 + SPPattern *getObject() const
1627 + {
1628 return reinterpret_cast<SPPattern *>(URIReference::getObject());
1629 }
1630
1631 protected:
1632 - virtual bool _acceptObject(SPObject *obj) const {
1633 - return SP_IS_PATTERN (obj);
1634 + virtual bool _acceptObject(SPObject *obj) const
1635 + {
1636 + return SP_IS_PATTERN(obj);
1637 }
1638 };
1639
1640 -enum {
1641 - SP_PATTERN_UNITS_USERSPACEONUSE,
1642 - SP_PATTERN_UNITS_OBJECTBOUNDINGBOX
1643 -};
1644 -
1645 -unsigned int pattern_users (SPPattern *pattern);
1646 -SPPattern *pattern_chain (SPPattern *pattern);
1647 -SPPattern *sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const char *property);
1648 -void sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set);
1649 -
1650 -const char *pattern_tile (const std::vector<Inkscape::XML::Node*> &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move);
1651 -
1652 -SPPattern *pattern_getroot (SPPattern *pat);
1653 -
1654 -unsigned int pattern_patternUnits (SPPattern const *pat);
1655 -unsigned int pattern_patternContentUnits (SPPattern const *pat);
1656 -Geom::Affine const &pattern_patternTransform(SPPattern const *pat);
1657 -double pattern_x (SPPattern const *pat);
1658 -double pattern_y (SPPattern const *pat);
1659 -double pattern_width (SPPattern const *pat);
1660 -double pattern_height (SPPattern const *pat);
1661 -Geom::OptRect pattern_viewBox (SPPattern const *pat);
1662 -
1663 #endif // SEEN_SP_PATTERN_H
1664
1665 /*
1666
1667 === modified file 'src/ui/CMakeLists.txt'
1668 --- src/ui/CMakeLists.txt 2015年05月12日 20:23:05 +0000
1669 +++ src/ui/CMakeLists.txt 2015年05月17日 12:22:15 +0000
1670 @@ -6,6 +6,7 @@
1671 interface.cpp
1672 object-edit.cpp
1673 previewholder.cpp
1674 + selected-color.cpp
1675 shape-editor.cpp
1676 tool-factory.cpp
1677 tools-switch.cpp
1678 @@ -115,8 +116,14 @@
1679 widget/anchor-selector.cpp
1680 widget/button.cpp
1681 widget/clipmaskicon.cpp
1682 + widget/color-entry.cpp
1683 + widget/color-icc-selector.cpp
1684 + widget/color-notebook.cpp
1685 widget/color-picker.cpp
1686 widget/color-preview.cpp
1687 + widget/color-scales.cpp
1688 + widget/color-slider.cpp
1689 + widget/color-wheel-selector.cpp
1690 widget/dock-item.cpp
1691 widget/dock.cpp
1692 widget/entity-entry.cpp
1693 @@ -175,6 +182,7 @@
1694 previewable.h
1695 previewfillable.h
1696 previewholder.h
1697 + selected-color.h
1698 shape-editor.h
1699 tool-factory.h
1700 tools-switch.h
1701 @@ -288,8 +296,14 @@
1702 widget/anchor-selector.h
1703 widget/attr-widget.h
1704 widget/button.h
1705 + widget/color-entry.h
1706 + widget/color-icc-selector.h
1707 + widget/color-notebook.h
1708 widget/color-picker.h
1709 widget/color-preview.h
1710 + widget/color-scales.h
1711 + widget/color-slider.h
1712 + widget/color-wheel-selector.h
1713 widget/combo-enums.h
1714 widget/dock-item.h
1715 widget/dock.h
1716
1717 === modified file 'src/ui/Makefile_insert'
1718 --- src/ui/Makefile_insert 2015年02月25日 01:04:28 +0000
1719 +++ src/ui/Makefile_insert 2015年05月17日 12:22:15 +0000
1720 @@ -19,6 +19,8 @@
1721 ui/previewfillable.h \
1722 ui/previewholder.cpp \
1723 ui/previewholder.h \
1724 + ui/selected-color.h \
1725 + ui/selected-color.cpp \
1726 ui/shape-editor.cpp \
1727 ui/shape-editor.h \
1728 ui/tool-factory.cpp \
1729
1730 === modified file 'src/ui/dialog/objects.cpp'
1731 --- src/ui/dialog/objects.cpp 2015年02月27日 02:10:36 +0000
1732 +++ src/ui/dialog/objects.cpp 2015年05月17日 12:22:15 +0000
1733 @@ -45,6 +45,7 @@
1734 #include "style.h"
1735 #include "ui/tools-switch.h"
1736 #include "ui/icon-names.h"
1737 +#include "ui/selected-color.h"
1738 #include "ui/widget/imagetoggler.h"
1739 #include "ui/widget/layertypeicon.h"
1740 #include "ui/widget/insertordericon.h"
1741 @@ -53,7 +54,7 @@
1742 #include "ui/tools/node-tool.h"
1743 #include "ui/tools/tool-base.h"
1744 #include "verbs.h"
1745 -#include "widgets/sp-color-notebook.h"
1746 +#include "ui/widget/color-notebook.h"
1747 #include "widgets/icon.h"
1748 #include "xml/node.h"
1749 #include "xml/node-observer.h"
1750 @@ -928,12 +929,12 @@
1751 //If the current item is not selected, store only it in the highlight source
1752 _storeHighlightTarget(iter);
1753 }
1754 - if (_colorSelector)
1755 + if (_selectedColor)
1756 {
1757 //Set up the color selector
1758 SPColor color;
1759 color.set( row[_model->_colHighlight] );
1760 - _colorSelector->base->setColorAlpha(color, SP_RGBA32_A_F(row[_model->_colHighlight]));
1761 + _selectedColor->setColorAlpha(color, SP_RGBA32_A_F(row[_model->_colHighlight]));
1762 }
1763 //Show the color selector dialog
1764 _colorSelectorDialog.show();
1765 @@ -1440,17 +1441,16 @@
1766 * @param csel Color selector
1767 * @param cp Objects panel
1768 */
1769 -void sp_highlight_picker_color_mod(SPColorSelector *csel, GObject * cp)
1770 +void ObjectsPanel::_highlightPickerColorMod()
1771 {
1772 SPColor color;
1773 float alpha = 0;
1774 - csel->base->getColorAlpha(color, alpha);
1775 + _selectedColor->colorAlpha(color, alpha);
1776 +
1777 guint32 rgba = color.toRGBA32( alpha );
1778 -
1779 - ObjectsPanel *ptr = reinterpret_cast<ObjectsPanel *>(cp);
1780
1781 //Set the highlight color for all items in the _highlight_target (all selected items)
1782 - for (std::vector<SPItem *>::iterator iter = ptr->_highlight_target.begin(); iter != ptr->_highlight_target.end(); ++iter)
1783 + for (std::vector<SPItem *>::iterator iter = _highlight_target.begin(); iter != _highlight_target.end(); ++iter)
1784 {
1785 SPItem * target = *iter;
1786 target->setHighlightColor(rgba);
1787 @@ -1922,18 +1922,16 @@
1788 _colorSelectorDialog.set_title (_("Select Highlight Color"));
1789 _colorSelectorDialog.set_border_width (4);
1790 _colorSelectorDialog.property_modal() = true;
1791 - _colorSelector = SP_COLOR_SELECTOR(sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK));
1792 + _selectedColor.reset(new Inkscape::UI::SelectedColor);
1793 + Gtk::Widget *color_selector = Gtk::manage(new Inkscape::UI::Widget::ColorNotebook(*_selectedColor));
1794 _colorSelectorDialog.get_vbox()->pack_start (
1795 - *Glib::wrap(&_colorSelector->vbox), true, true, 0);
1796 -
1797 - g_signal_connect(G_OBJECT(_colorSelector), "dragged",
1798 - G_CALLBACK(sp_highlight_picker_color_mod), (void *)this);
1799 - g_signal_connect(G_OBJECT(_colorSelector), "released",
1800 - G_CALLBACK(sp_highlight_picker_color_mod), (void *)this);
1801 - g_signal_connect(G_OBJECT(_colorSelector), "changed",
1802 - G_CALLBACK(sp_highlight_picker_color_mod), (void *)this);
1803 -
1804 - gtk_widget_show(GTK_WIDGET(_colorSelector));
1805 + *color_selector, true, true, 0);
1806 +
1807 + _selectedColor->signal_dragged.connect(sigc::mem_fun(*this, &ObjectsPanel::_highlightPickerColorMod));
1808 + _selectedColor->signal_released.connect(sigc::mem_fun(*this, &ObjectsPanel::_highlightPickerColorMod));
1809 + _selectedColor->signal_changed.connect(sigc::mem_fun(*this, &ObjectsPanel::_highlightPickerColorMod));
1810 +
1811 + color_selector->show();
1812
1813 setDesktop( targetDesktop );
1814
1815 @@ -1951,7 +1949,6 @@
1816 {
1817 //Close the highlight selection dialog
1818 _colorSelectorDialog.hide();
1819 - _colorSelector = NULL;
1820
1821 //Set the desktop to null, which will disconnect all object watchers
1822 setDesktop(NULL);
1823
1824 === modified file 'src/ui/dialog/objects.h'
1825 --- src/ui/dialog/objects.h 2015年04月27日 23:38:31 +0000
1826 +++ src/ui/dialog/objects.h 2015年05月17日 12:22:15 +0000
1827 @@ -16,6 +16,7 @@
1828 # include <config.h>
1829 #endif
1830
1831 +#include <boost/scoped_ptr.hpp>
1832 #include <gtkmm/box.h>
1833 #include <gtkmm/treeview.h>
1834 #include <gtkmm/treestore.h>
1835 @@ -36,6 +37,9 @@
1836 namespace Inkscape {
1837
1838 namespace UI {
1839 +
1840 +class SelectedColor;
1841 +
1842 namespace Dialog {
1843
1844
1845 @@ -166,8 +170,7 @@
1846 Gtk::Alignment _blur_alignment;
1847
1848 Gtk::Dialog _colorSelectorDialog;
1849 - SPColorSelector *_colorSelector;
1850 -
1851 + boost::scoped_ptr<Inkscape::UI::SelectedColor> _selectedColor;
1852
1853 //Methods:
1854
1855 @@ -233,7 +236,7 @@
1856
1857 void setupDialog(const Glib::ustring &title);
1858
1859 - friend void sp_highlight_picker_color_mod(SPColorSelector *csel, GObject *cp);
1860 + void _highlightPickerColorMod();
1861
1862 };
1863
1864
1865 === modified file 'src/ui/dialog/tags.cpp'
1866 --- src/ui/dialog/tags.cpp 2015年02月27日 03:21:48 +0000
1867 +++ src/ui/dialog/tags.cpp 2015年05月17日 12:22:15 +0000
1868 @@ -51,7 +51,7 @@
1869 #include "ui/tools/tool-base.h" //"event-context.h"
1870 #include "selection.h"
1871 //#include "dialogs/dialog-events.h"
1872 -#include "widgets/sp-color-notebook.h"
1873 +#include "ui/widget/color-notebook.h"
1874 #include "style.h"
1875 #include "filter-chemistry.h"
1876 #include "filters/blend.h"
1877
1878 === added file 'src/ui/selected-color.cpp'
1879 --- src/ui/selected-color.cpp 1970年01月01日 00:00:00 +0000
1880 +++ src/ui/selected-color.cpp 2015年05月17日 12:22:15 +0000
1881 @@ -0,0 +1,163 @@
1882 +/** @file
1883 + * Color selected in color selector widget.
1884 + * This file was created during the refactoring of SPColorSelector
1885 + *//*
1886 + * Authors:
1887 + * bulia byak <buliabyak@users.sf.net>
1888 + * Jon A. Cruz <jon@joncruz.org>
1889 + * Tomasz Boczkowski <penginsbacon@gmail.com>
1890 + *
1891 + * Copyright (C) 2014 Authors
1892 + * Released under GNU GPL, read the file 'COPYING' for more information
1893 + */
1894 +#ifdef HAVE_CONFIG_H
1895 +# include "config.h"
1896 +#endif
1897 +
1898 +#include <glibmm/ustring.h>
1899 +#include <cmath>
1900 +
1901 +#include "svg/svg-icc-color.h"
1902 +#include "ui/selected-color.h"
1903 +
1904 +namespace Inkscape {
1905 +namespace UI {
1906 +
1907 +double const SelectedColor::_EPSILON = 1e-4;
1908 +
1909 +SelectedColor::SelectedColor()
1910 + : _color(0)
1911 + , _alpha(1.0)
1912 + , _held(false)
1913 + , _virgin(true)
1914 + , _updating(false)
1915 +{
1916 +
1917 +}
1918 +
1919 +SelectedColor::~SelectedColor() {
1920 +
1921 +}
1922 +
1923 +void SelectedColor::setColor(SPColor const &color)
1924 +{
1925 + setColorAlpha( color, _alpha);
1926 +}
1927 +
1928 +SPColor SelectedColor::color() const
1929 +{
1930 + return _color;
1931 +}
1932 +
1933 +void SelectedColor::setAlpha(gfloat alpha)
1934 +{
1935 + g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) );
1936 + setColorAlpha( _color, alpha);
1937 +}
1938 +
1939 +gfloat SelectedColor::alpha() const
1940 +{
1941 + return _alpha;
1942 +}
1943 +
1944 +void SelectedColor::setValue(guint32 value)
1945 +{
1946 + SPColor color(value);
1947 + gfloat alpha = SP_RGBA32_A_F(value);
1948 + setColorAlpha(color, alpha);
1949 +}
1950 +
1951 +guint32 SelectedColor::value() const
1952 +{
1953 + return color().toRGBA32(_alpha);
1954 +}
1955 +
1956 +void SelectedColor::setColorAlpha(SPColor const &color, gfloat alpha, bool emit_signal)
1957 +{
1958 +#ifdef DUMP_CHANGE_INFO
1959 + g_message("SelectedColor::setColorAlpha( this=%p, %f, %f, %f, %s, %f, %s)", this, color.v.c[0], color.v.c[1], color.v.c[2], (color.icc?color.icc->colorProfile.c_str():"<null>"), alpha, (emit_signal?"YES":"no"));
1960 +#endif
1961 + g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) );
1962 +
1963 + if (_updating) {
1964 + return;
1965 + }
1966 +
1967 +#ifdef DUMP_CHANGE_INFO
1968 + g_message("---- SelectedColor::setColorAlpha virgin:%s !close:%s alpha is:%s",
1969 + (_virgin?"YES":"no"),
1970 + (!color.isClose( _color, _EPSILON )?"YES":"no"),
1971 + ((fabs((_alpha) - (alpha)) >= _EPSILON )?"YES":"no")
1972 + );
1973 +#endif
1974 +
1975 + if ( _virgin || !color.isClose( _color, _EPSILON ) ||
1976 + (fabs((_alpha) - (alpha)) >= _EPSILON )) {
1977 +
1978 + _virgin = false;
1979 +
1980 + _color = color;
1981 + _alpha = alpha;
1982 +
1983 + if (emit_signal)
1984 + {
1985 + _updating = true;
1986 + if (_held) {
1987 + signal_dragged.emit();
1988 + } else {
1989 + signal_changed.emit();
1990 + }
1991 + _updating = false;
1992 + }
1993 +
1994 +#ifdef DUMP_CHANGE_INFO
1995 + } else {
1996 + g_message("++++ SelectedColor::setColorAlpha color:%08x ==> _color:%08X isClose:%s", color.toRGBA32(alpha), _color.toRGBA32(_alpha),
1997 + (color.isClose( _color, _EPSILON )?"YES":"no"));
1998 +#endif
1999 + }
2000 +}
2001 +
2002 +void SelectedColor::colorAlpha(SPColor &color, gfloat &alpha) const {
2003 + color = _color;
2004 + alpha = _alpha;
2005 +}
2006 +
2007 +void SelectedColor::setHeld(bool held) {
2008 + if (_updating) {
2009 + return;
2010 + }
2011 + bool grabbed = held && !_held;
2012 + bool released = !held && _held;
2013 +
2014 + _held = held;
2015 +
2016 + _updating = true;
2017 + if (grabbed) {
2018 + signal_grabbed.emit();
2019 + }
2020 +
2021 + if (released) {
2022 + signal_released.emit();
2023 + signal_changed.emit();
2024 + }
2025 + _updating = false;
2026 +}
2027 +
2028 +void SelectedColor::preserveICC() {
2029 + _color.icc = _color.icc ? new SVGICCColor(*_color.icc) : 0;
2030 +}
2031 +
2032 +}
2033 +}
2034 +
2035 +/*
2036 + Local Variables:
2037 + mode:c++
2038 + c-file-style:"stroustrup"
2039 + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2040 + indent-tabs-mode:nil
2041 + fill-column:99
2042 + End:
2043 +*/
2044 +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
2045
2046 === added file 'src/ui/selected-color.h'
2047 --- src/ui/selected-color.h 1970年01月01日 00:00:00 +0000
2048 +++ src/ui/selected-color.h 2015年05月17日 12:22:15 +0000
2049 @@ -0,0 +1,96 @@
2050 +/** @file
2051 + * Color selected in color selector widget.
2052 + * This file was created during the refactoring of SPColorSelector
2053 + *//*
2054 + * Authors:
2055 + * bulia byak <buliabyak@users.sf.net>
2056 + * Jon A. Cruz <jon@joncruz.org>
2057 + * Tomasz Boczkowski <penginsbacon@gmail.com>
2058 + *
2059 + * Copyright (C) 2014 Authors
2060 + * Released under GNU GPL, read the file 'COPYING' for more information
2061 + */
2062 +#ifndef SEEN_SELECTED_COLOR
2063 +#define SEEN_SELECTED_COLOR
2064 +
2065 +#include <sigc++/signal.h>
2066 +#include "color.h"
2067 +
2068 +namespace Gtk
2069 +{
2070 + class Widget;
2071 +}
2072 +
2073 +namespace Inkscape {
2074 +namespace UI {
2075 +
2076 +class SelectedColor {
2077 +public:
2078 + SelectedColor();
2079 + virtual ~SelectedColor();
2080 +
2081 + void setColor(SPColor const &color);
2082 + SPColor color() const;
2083 +
2084 + void setAlpha(gfloat alpha);
2085 + gfloat alpha() const;
2086 +
2087 + void setValue(guint32 value);
2088 + guint32 value() const;
2089 +
2090 + void setColorAlpha(SPColor const &color, gfloat alpha, bool emit_signal = true);
2091 + void colorAlpha(SPColor &color, gfloat &alpha) const;
2092 +
2093 + void setHeld(bool held);
2094 +
2095 + void preserveICC();
2096 +
2097 + sigc::signal<void> signal_grabbed;
2098 + sigc::signal<void> signal_dragged;
2099 + sigc::signal<void> signal_released;
2100 + sigc::signal<void> signal_changed;
2101 +private:
2102 + // By default, disallow copy constructor and assignment operator
2103 + SelectedColor(SelectedColor const &obj);
2104 + SelectedColor& operator=(SelectedColor const &obj);
2105 +
2106 + SPColor _color;
2107 + /**
2108 + * Color alpha value guaranteed to be in [0, 1].
2109 + */
2110 + gfloat _alpha;
2111 +
2112 + bool _held;
2113 + /**
2114 + * This flag is true if no color is set yet
2115 + */
2116 + bool _virgin;
2117 +
2118 + bool _updating;
2119 +
2120 + static double const _EPSILON;
2121 +};
2122 +
2123 +class ColorSelectorFactory {
2124 +public:
2125 + virtual ~ColorSelectorFactory() {
2126 + }
2127 +
2128 + virtual Gtk::Widget* createWidget(SelectedColor &color) const = 0;
2129 + virtual Glib::ustring modeName() const = 0;
2130 +};
2131 +
2132 +}
2133 +}
2134 +
2135 +#endif
2136 +/*
2137 + Local Variables:
2138 + mode:c++
2139 + c-file-style:"stroustrup"
2140 + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2141 + indent-tabs-mode:nil
2142 + fill-column:99
2143 + End:
2144 +*/
2145 +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
2146
2147 === modified file 'src/ui/widget/Makefile_insert'
2148 --- src/ui/widget/Makefile_insert 2015年05月12日 19:43:24 +0000
2149 +++ src/ui/widget/Makefile_insert 2015年05月17日 12:22:15 +0000
2150 @@ -6,10 +6,22 @@
2151 ui/widget/attr-widget.h \
2152 ui/widget/button.h \
2153 ui/widget/button.cpp \
2154 + ui/widget/color-entry.cpp \
2155 + ui/widget/color-entry.h \
2156 + ui/widget/color-icc-selector.cpp \
2157 + ui/widget/color-icc-selector.h \
2158 + ui/widget/color-notebook.cpp \
2159 + ui/widget/color-notebook.h \
2160 + ui/widget/color-wheel-selector.cpp \
2161 + ui/widget/color-wheel-selector.h \
2162 ui/widget/color-picker.cpp \
2163 ui/widget/color-picker.h \
2164 ui/widget/color-preview.cpp \
2165 ui/widget/color-preview.h \
2166 + ui/widget/color-slider.cpp \
2167 + ui/widget/color-slider.h \
2168 + ui/widget/color-scales.cpp \
2169 + ui/widget/color-scales.h \
2170 ui/widget/combo-enums.h \
2171 ui/widget/dock.h \
2172 ui/widget/dock.cpp \
2173
2174 === added file 'src/ui/widget/color-entry.cpp'
2175 --- src/ui/widget/color-entry.cpp 1970年01月01日 00:00:00 +0000
2176 +++ src/ui/widget/color-entry.cpp 2015年05月17日 12:22:15 +0000
2177 @@ -0,0 +1,104 @@
2178 +/** @file
2179 + * Entry widget for typing color value in css form
2180 + *//*
2181 + * Authors:
2182 + * Tomasz Boczkowski <penginsbacon@gmail.com>
2183 + *
2184 + * Copyright (C) 2014 Authors
2185 + * Released under GNU GPL, read the file 'COPYING' for more information
2186 + */
2187 +#include <glibmm.h>
2188 +#include <glibmm/i18n.h>
2189 +#include <iomanip>
2190 +
2191 +#include "color-entry.h"
2192 +
2193 +namespace Inkscape {
2194 +namespace UI {
2195 +namespace Widget {
2196 +
2197 +ColorEntry::ColorEntry(SelectedColor &color)
2198 + : _color(color)
2199 + , _updating(false)
2200 +{
2201 + _color_changed_connection = color.signal_changed.connect(sigc::mem_fun(this, &ColorEntry::_onColorChanged));
2202 + _color_dragged_connection = color.signal_dragged.connect(sigc::mem_fun(this, &ColorEntry::_onColorChanged));
2203 + _onColorChanged();
2204 +
2205 + set_max_length(8);
2206 + set_width_chars(8);
2207 + set_tooltip_text(_("Hexadecimal RGBA value of the color"));
2208 +}
2209 +
2210 +ColorEntry::~ColorEntry()
2211 +{
2212 + _color_changed_connection.disconnect();
2213 + _color_dragged_connection.disconnect();
2214 +}
2215 +
2216 +void ColorEntry::on_changed()
2217 +{
2218 + if (_updating) {
2219 + return;
2220 + }
2221 +
2222 + Glib::ustring text = get_text();
2223 + bool changed = false;
2224 +
2225 + // Coerce the value format to eight hex digits
2226 + if (!text.empty() && text[0] == '#') {
2227 + changed = true;
2228 + text.erase(0, 1);
2229 + if (text.size() == 6) {
2230 + // it was a standard RGB hex
2231 + unsigned int alpha = SP_COLOR_F_TO_U(_color.alpha());
2232 + text += Glib::ustring::format(std::hex, std::setw(2), std::setfill(L'0'), alpha);
2233 + }
2234 + }
2235 +
2236 + gchar *str = g_strdup(text.c_str());
2237 + gchar *end = 0;
2238 + guint64 rgba = g_ascii_strtoull(str, &end, 16);
2239 + if (end != str) {
2240 + ptrdiff_t len = end - str;
2241 + if (len < 8) {
2242 + rgba = rgba << (4 * (8 - len));
2243 + }
2244 + if (changed) {
2245 + set_text(str);
2246 + }
2247 + SPColor color(rgba);
2248 + _color.setColorAlpha(color, SP_RGBA32_A_F(rgba));
2249 + }
2250 + g_free(str);
2251 +}
2252 +
2253 +
2254 +void ColorEntry::_onColorChanged()
2255 +{
2256 + SPColor color = _color.color();
2257 + gdouble alpha = _color.alpha();
2258 +
2259 + guint32 rgba = color.toRGBA32(alpha);
2260 + Glib::ustring text = Glib::ustring::format(std::hex, std::setw(8), std::setfill(L'0'), rgba);
2261 +
2262 + Glib::ustring old_text = get_text();
2263 + if (old_text != text) {
2264 + _updating = true;
2265 + set_text(text);
2266 + _updating = false;
2267 + }
2268 +}
2269 +}
2270 +}
2271 +}
2272 +/*
2273 + Local Variables:
2274 + mode:c++
2275 + c-file-style:"stroustrup"
2276 + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2277 + indent-tabs-mode:nil
2278 + fill-column:99
2279 + End:
2280 +*/
2281 +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
2282
2283 === added file 'src/ui/widget/color-entry.h'
2284 --- src/ui/widget/color-entry.h 1970年01月01日 00:00:00 +0000
2285 +++ src/ui/widget/color-entry.h 2015年05月17日 12:22:15 +0000
2286 @@ -0,0 +1,53 @@
2287 +/** @file
2288 + * Entry widget for typing color value in css form
2289 + *//*
2290 + * Authors:
2291 + * Tomasz Boczkowski <penginsbacon@gmail.com>
2292 + *
2293 + * Copyright (C) 2014 Authors
2294 + * Released under GNU GPL, read the file 'COPYING' for more information
2295 + */
2296 +
2297 +#ifndef SEEN_COLOR_ENTRY_H
2298 +#define SEEN_COLOR_ENTRY_H_
2299 +
2300 +#include <gtkmm/entry.h>
2301 +#include "ui/selected-color.h"
2302 +
2303 +namespace Inkscape {
2304 +namespace UI {
2305 +namespace Widget {
2306 +
2307 +class ColorEntry : public Gtk::Entry
2308 +{
2309 +public:
2310 + ColorEntry(SelectedColor &color);
2311 + virtual ~ColorEntry();
2312 +
2313 +protected:
2314 + void on_changed();
2315 +
2316 +private:
2317 + void _onColorChanged();
2318 +
2319 + SelectedColor &_color;
2320 + sigc::connection _color_changed_connection;
2321 + sigc::connection _color_dragged_connection;
2322 + bool _updating;
2323 +};
2324 +
2325 +}
2326 +}
2327 +}
2328 +
2329 +#endif
2330 +/*
2331 + Local Variables:
2332 + mode:c++
2333 + c-file-style:"stroustrup"
2334 + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2335 + indent-tabs-mode:nil
2336 + fill-column:99
2337 + End:
2338 +*/
2339 +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
2340
2341 === renamed file 'src/widgets/sp-color-icc-selector.cpp' => 'src/ui/widget/color-icc-selector.cpp'
2342 --- src/widgets/sp-color-icc-selector.cpp 2014年10月08日 02:22:03 +0000
2343 +++ src/ui/widget/color-icc-selector.cpp 2015年05月17日 12:22:15 +0000
2344 @@ -1,24 +1,26 @@
2345 #ifdef HAVE_CONFIG_H
2346 -# include "config.h"
2347 +#include "config.h"
2348 #endif
2349
2350 -#include "gradient-vector.h"
2351 #include <math.h>
2352 +#include <gtkmm/adjustment.h>
2353 +#include <glibmm/i18n.h>
2354 +
2355 #include <gtk/gtk.h>
2356 -#include <glibmm/i18n.h>
2357 #include <map>
2358 #include <set>
2359 #include <vector>
2360
2361 #include "ui/dialog-events.h"
2362 -#include "sp-color-icc-selector.h"
2363 -#include "sp-color-scales.h"
2364 -#include "sp-color-slider.h"
2365 +#include "ui/widget/color-icc-selector.h"
2366 +#include "ui/widget/color-scales.h"
2367 +#include "ui/widget/color-slider.h"
2368 #include "svg/svg-icc-color.h"
2369 #include "colorspace.h"
2370 #include "document.h"
2371 #include "inkscape.h"
2372 #include "profile-manager.h"
2373 +#include "widgets/gradient-vector.h"
2374
2375 #define noDEBUG_LCMS
2376
2377 @@ -32,137 +34,32 @@
2378 #endif // DEBUG_LCMS
2379 #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2380
2381 -
2382 #ifdef DEBUG_LCMS
2383 extern guint update_in_progress;
2384 -#define DEBUG_MESSAGE(key, ...) \
2385 -{\
2386 - Inkscape::Preferences *prefs = Inkscape::Preferences::get();\
2387 - bool dump = prefs->getBool("/options/scislac/" #key);\
2388 - bool dumpD = prefs->getBool("/options/scislac/" #key "D");\
2389 - bool dumpD2 = prefs->getBool("/options/scislac/" #key "D2");\
2390 - dumpD &&= ( (update_in_progress == 0) || dumpD2 );\
2391 - if ( dump )\
2392 - {\
2393 - g_message( __VA_ARGS__ );\
2394 -\
2395 - }\
2396 - if ( dumpD )\
2397 - {\
2398 - GtkWidget *dialog = gtk_message_dialog_new(NULL,\
2399 - GTK_DIALOG_DESTROY_WITH_PARENT, \
2400 - GTK_MESSAGE_INFO, \
2401 - GTK_BUTTONS_OK, \
2402 - __VA_ARGS__ \
2403 - );\
2404 - g_signal_connect_swapped(dialog, "response",\
2405 - G_CALLBACK(gtk_widget_destroy), \
2406 - dialog); \
2407 - gtk_widget_show_all( dialog );\
2408 - }\
2409 -}
2410 +#define DEBUG_MESSAGE(key, ...) \
2411 + { \
2412 + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); \
2413 + bool dump = prefs->getBool("/options/scislac/" #key); \
2414 + bool dumpD = prefs->getBool("/options/scislac/" #key "D"); \
2415 + bool dumpD2 = prefs->getBool("/options/scislac/" #key "D2"); \
2416 + dumpD && = ((update_in_progress == 0) || dumpD2); \
2417 + if (dump) { \
2418 + g_message(__VA_ARGS__); \
2419 + } \
2420 + if (dumpD) { \
2421 + GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, \
2422 + GTK_BUTTONS_OK, __VA_ARGS__); \
2423 + g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); \
2424 + gtk_widget_show_all(dialog); \
2425 + } \
2426 + }
2427 #endif // DEBUG_LCMS
2428
2429
2430 -
2431 -G_BEGIN_DECLS
2432 -
2433 -static void sp_color_icc_selector_dispose(GObject *object);
2434 -static void sp_color_icc_selector_show_all (GtkWidget *widget);
2435 -static void sp_color_icc_selector_hide(GtkWidget *widget);
2436 -
2437 -G_END_DECLS
2438 -
2439 -/**
2440 - * Class containing the parts for a single color component's UI presence.
2441 - */
2442 -class ComponentUI
2443 -{
2444 -public:
2445 - ComponentUI() :
2446 - _component(),
2447 - _adj(0),
2448 - _slider(0),
2449 - _btn(0),
2450 - _label(0),
2451 - _map(0)
2452 - {
2453 - }
2454 -
2455 - ComponentUI(colorspace::Component const &component) :
2456 - _component(component),
2457 - _adj(0),
2458 - _slider(0),
2459 - _btn(0),
2460 - _label(0),
2461 - _map(0)
2462 - {
2463 - }
2464 -
2465 - colorspace::Component _component;
2466 - GtkAdjustment *_adj; // Component adjustment
2467 - GtkWidget *_slider;
2468 - GtkWidget *_btn; // spinbutton
2469 - GtkWidget *_label; // Label
2470 - guchar *_map;
2471 -};
2472 -
2473 -/**
2474 - * Class that implements the internals of the selector.
2475 - */
2476 -class ColorICCSelectorImpl
2477 -{
2478 -public:
2479 -
2480 - ColorICCSelectorImpl( ColorICCSelector *owner);
2481 -
2482 - ~ColorICCSelectorImpl();
2483 -
2484 - static void _adjustmentChanged ( GtkAdjustment *adjustment, SPColorICCSelector *cs );
2485 -
2486 - static void _sliderGrabbed( SPColorSlider *slider, SPColorICCSelector *cs );
2487 - static void _sliderReleased( SPColorSlider *slider, SPColorICCSelector *cs );
2488 - static void _sliderChanged( SPColorSlider *slider, SPColorICCSelector *cs );
2489 -
2490 - static void _profileSelected( GtkWidget* src, gpointer data );
2491 - static void _fixupHit( GtkWidget* src, gpointer data );
2492 -
2493 -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2494 - void _setProfile( SVGICCColor* profile );
2495 - void _switchToProfile( gchar const* name );
2496 -#endif
2497 - void _updateSliders( gint ignore );
2498 - void _profilesChanged( std::string const & name );
2499 -
2500 - ColorICCSelector *_owner;
2501 -
2502 - gboolean _updating : 1;
2503 - gboolean _dragging : 1;
2504 -
2505 - guint32 _fixupNeeded;
2506 - GtkWidget* _fixupBtn;
2507 - GtkWidget* _profileSel;
2508 -
2509 - std::vector<ComponentUI> _compUI;
2510 -
2511 - GtkAdjustment* _adj; // Channel adjustment
2512 - GtkWidget* _slider;
2513 - GtkWidget* _sbtn; // Spinbutton
2514 - GtkWidget* _label; // Label
2515 -
2516 -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2517 - std::string _profileName;
2518 - Inkscape::ColorProfile* _prof;
2519 - guint _profChannelCount;
2520 - gulong _profChangedID;
2521 -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2522 -};
2523 -
2524 #define XPAD 4
2525 #define YPAD 1
2526
2527 -namespace
2528 -{
2529 +namespace {
2530
2531 size_t maxColorspaceComponentCount = 0;
2532
2533 @@ -187,91 +84,40 @@
2534 /**
2535 * Helper function to handle GTK2/GTK3 attachment #ifdef code.
2536 */
2537 -void attachToGridOrTable(GtkWidget *parent,
2538 - GtkWidget *child,
2539 - guint left,
2540 - guint top,
2541 - guint width,
2542 - guint height,
2543 - bool hexpand = false,
2544 - bool centered = false,
2545 - guint xpadding = XPAD,
2546 - guint ypadding = YPAD)
2547 +void attachToGridOrTable(GtkWidget *parent, GtkWidget *child, guint left, guint top, guint width, guint height,
2548 + bool hexpand = false, bool centered = false, guint xpadding = XPAD, guint ypadding = YPAD)
2549 {
2550 -#if GTK_CHECK_VERSION(3,0,0)
2551 - #if GTK_CHECK_VERSION(3,12,0)
2552 - gtk_widget_set_margin_start( child, xpadding );
2553 - gtk_widget_set_margin_end( child, xpadding );
2554 - #else
2555 - gtk_widget_set_margin_left( child, xpadding );
2556 - gtk_widget_set_margin_right( child, xpadding );
2557 - #endif
2558 +#if GTK_CHECK_VERSION(3, 0, 0)
2559 + #if GTK_CHECK_VERSION(3, 12, 0)
2560 + gtk_widget_set_margin_start(child, xpadding);
2561 + gtk_widget_set_margin_end(child, xpadding);
2562 + #else
2563 + gtk_widget_set_margin_left(child, xpadding);
2564 + gtk_widget_set_margin_right(child, xpadding);
2565 + #endif
2566
2567 - gtk_widget_set_margin_top( child, ypadding );
2568 - gtk_widget_set_margin_bottom( child, ypadding );
2569 + gtk_widget_set_margin_top(child, ypadding);
2570 + gtk_widget_set_margin_bottom(child, ypadding);
2571 if (hexpand) {
2572 gtk_widget_set_hexpand(child, TRUE);
2573 }
2574 if (centered) {
2575 - gtk_widget_set_halign( child, GTK_ALIGN_CENTER );
2576 - gtk_widget_set_valign( child, GTK_ALIGN_CENTER );
2577 + gtk_widget_set_halign(child, GTK_ALIGN_CENTER);
2578 + gtk_widget_set_valign(child, GTK_ALIGN_CENTER);
2579 }
2580 - gtk_grid_attach( GTK_GRID(parent), child, left, top, width, height );
2581 + gtk_grid_attach(GTK_GRID(parent), child, left, top, width, height);
2582 #else
2583 - GtkAttachOptions xoptions = centered ? static_cast<GtkAttachOptions>(0) : hexpand ? (GTK_EXPAND | GTK_FILL) : GTK_FILL;
2584 + GtkAttachOptions xoptions =
2585 + centered ? static_cast<GtkAttachOptions>(0) : hexpand ? (GTK_EXPAND | GTK_FILL) : GTK_FILL;
2586 GtkAttachOptions yoptions = centered ? static_cast<GtkAttachOptions>(0) : GTK_FILL;
2587
2588 - gtk_table_attach( GTK_TABLE(parent), child, left, left + width, top, top + height, xoptions, yoptions, xpadding, ypadding );
2589 + gtk_table_attach(GTK_TABLE(parent), child, left, left + width, top, top + height, xoptions, yoptions, xpadding,
2590 + ypadding);
2591 #endif
2592 }
2593
2594 } // namespace
2595
2596 -G_DEFINE_TYPE(SPColorICCSelector, sp_color_icc_selector, SP_TYPE_COLOR_SELECTOR);
2597 -
2598 -static void sp_color_icc_selector_class_init(SPColorICCSelectorClass *klass)
2599 -{
2600 - static const gchar* nameset[] = {N_("CMS"), 0};
2601 - GObjectClass *object_class = G_OBJECT_CLASS(klass);
2602 - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
2603 - SPColorSelectorClass *selector_class = SP_COLOR_SELECTOR_CLASS (klass);
2604 -
2605 - selector_class->name = nameset;
2606 - selector_class->submode_count = 1;
2607 -
2608 - object_class->dispose = sp_color_icc_selector_dispose;
2609 -
2610 - widget_class->show_all = sp_color_icc_selector_show_all;
2611 - widget_class->hide = sp_color_icc_selector_hide;
2612 -}
2613 -
2614 -
2615 -ColorICCSelector::ColorICCSelector( SPColorSelector* csel )
2616 - : ColorSelector( csel ),
2617 - _impl(NULL)
2618 -{
2619 -}
2620 -
2621 -ColorICCSelector::~ColorICCSelector()
2622 -{
2623 - if (_impl)
2624 - {
2625 - delete _impl;
2626 - _impl = 0;
2627 - }
2628 -}
2629 -
2630 -void sp_color_icc_selector_init(SPColorICCSelector *cs)
2631 -{
2632 - SP_COLOR_SELECTOR(cs)->base = new ColorICCSelector( SP_COLOR_SELECTOR(cs) );
2633 -
2634 - if ( SP_COLOR_SELECTOR(cs)->base )
2635 - {
2636 - SP_COLOR_SELECTOR(cs)->base->init();
2637 - }
2638 -}
2639 -
2640 -
2641 /*
2642 icSigRgbData
2643 icSigCmykData
2644 @@ -283,32 +129,32 @@
2645
2646
2647 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2648 -static cmsUInt16Number* getScratch() {
2649 +static cmsUInt16Number *getScratch()
2650 +{
2651 // bytes per pixel * input channels * width
2652 - static cmsUInt16Number* scritch = static_cast<cmsUInt16Number*>(g_new(cmsUInt16Number, 4 * 1024));
2653 + static cmsUInt16Number *scritch = static_cast<cmsUInt16Number *>(g_new(cmsUInt16Number, 4 * 1024));
2654
2655 return scritch;
2656 }
2657
2658 -colorspace::Component::Component() :
2659 - name(),
2660 - tip(),
2661 - scale(1)
2662 -{
2663 -}
2664 -
2665 -colorspace::Component::Component(std::string const &name, std::string const &tip, guint scale) :
2666 - name(name),
2667 - tip(tip),
2668 - scale(scale)
2669 -{
2670 -}
2671 -
2672 -std::vector<colorspace::Component> colorspace::getColorSpaceInfo( uint32_t space )
2673 +colorspace::Component::Component()
2674 + : name()
2675 + , tip()
2676 + , scale(1)
2677 +{
2678 +}
2679 +
2680 +colorspace::Component::Component(std::string const &name, std::string const &tip, guint scale)
2681 + : name(name)
2682 + , tip(tip)
2683 + , scale(scale)
2684 +{
2685 +}
2686 +
2687 +std::vector<colorspace::Component> colorspace::getColorSpaceInfo(uint32_t space)
2688 {
2689 static std::map<cmsUInt32Number, std::vector<Component> > sets;
2690 - if (sets.empty())
2691 - {
2692 + if (sets.empty()) {
2693 sets[cmsSigXYZData].push_back(Component("_X", "X", 2)); // TYPE_XYZ_16
2694 sets[cmsSigXYZData].push_back(Component("_Y", "Y", 1));
2695 sets[cmsSigXYZData].push_back(Component("_Z", "Z", 2));
2696 @@ -317,7 +163,7 @@
2697 sets[cmsSigLabData].push_back(Component("_a", "a", 256));
2698 sets[cmsSigLabData].push_back(Component("_b", "b", 256));
2699
2700 - //cmsSigLuvData
2701 + // cmsSigLuvData
2702
2703 sets[cmsSigYCbCrData].push_back(Component("_Y", "Y", 1)); // TYPE_YCbCr_16
2704 sets[cmsSigYCbCrData].push_back(Component("C_b", "Cb", 1));
2705 @@ -350,8 +196,7 @@
2706 sets[cmsSigCmyData].push_back(Component(_("_M:"), _("Magenta"), 1));
2707 sets[cmsSigCmyData].push_back(Component(_("_Y:"), _("Yellow"), 1));
2708
2709 - for (std::map<cmsUInt32Number, std::vector<Component> >::iterator it = sets.begin(); it != sets.end(); ++it)
2710 - {
2711 + for (std::map<cmsUInt32Number, std::vector<Component> >::iterator it = sets.begin(); it != sets.end(); ++it) {
2712 knownColorspaces.insert(it->first);
2713 maxColorspaceComponentCount = std::max(maxColorspaceComponentCount, it->second.size());
2714 }
2715 @@ -359,39 +204,148 @@
2716
2717 std::vector<Component> target;
2718
2719 - if (sets.find(space) != sets.end())
2720 - {
2721 + if (sets.find(space) != sets.end()) {
2722 target = sets[space];
2723 }
2724 return target;
2725 }
2726
2727
2728 -std::vector<colorspace::Component> colorspace::getColorSpaceInfo( Inkscape::ColorProfile *prof )
2729 -{
2730 - return getColorSpaceInfo( asICColorSpaceSig(prof->getColorSpace()) );
2731 -}
2732 -
2733 -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2734 -
2735 -ColorICCSelectorImpl::ColorICCSelectorImpl(ColorICCSelector *owner) :
2736 - _owner(owner),
2737 - _updating( FALSE ),
2738 - _dragging( FALSE ),
2739 - _fixupNeeded(0),
2740 - _fixupBtn(0),
2741 - _profileSel(0),
2742 - _compUI(),
2743 - _adj(0),
2744 - _slider(0),
2745 - _sbtn(0),
2746 - _label(0)
2747 -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2748 - ,
2749 - _profileName(),
2750 - _prof(0),
2751 - _profChannelCount(0),
2752 - _profChangedID(0)
2753 +std::vector<colorspace::Component> colorspace::getColorSpaceInfo(Inkscape::ColorProfile *prof)
2754 +{
2755 + return getColorSpaceInfo(asICColorSpaceSig(prof->getColorSpace()));
2756 +}
2757 +
2758 +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2759 +
2760 +namespace Inkscape {
2761 +namespace UI {
2762 +namespace Widget {
2763 +
2764 +/**
2765 + * Class containing the parts for a single color component's UI presence.
2766 + */
2767 +class ComponentUI {
2768 + public:
2769 + ComponentUI()
2770 + : _component()
2771 + , _adj(0)
2772 + , _slider(0)
2773 + , _btn(0)
2774 + , _label(0)
2775 + , _map(0)
2776 + {
2777 + }
2778 +
2779 + ComponentUI(colorspace::Component const &component)
2780 + : _component(component)
2781 + , _adj(0)
2782 + , _slider(0)
2783 + , _btn(0)
2784 + , _label(0)
2785 + , _map(0)
2786 + {
2787 + }
2788 +
2789 + colorspace::Component _component;
2790 + GtkAdjustment *_adj; // Component adjustment
2791 + Inkscape::UI::Widget::ColorSlider *_slider;
2792 + GtkWidget *_btn; // spinbutton
2793 + GtkWidget *_label; // Label
2794 + guchar *_map;
2795 +};
2796 +
2797 +/**
2798 + * Class that implements the internals of the selector.
2799 + */
2800 +class ColorICCSelectorImpl {
2801 + public:
2802 + ColorICCSelectorImpl(ColorICCSelector *owner, SelectedColor &color);
2803 +
2804 + ~ColorICCSelectorImpl();
2805 +
2806 + static void _adjustmentChanged(GtkAdjustment *adjustment, ColorICCSelectorImpl *cs);
2807 +
2808 + void _sliderGrabbed();
2809 + void _sliderReleased();
2810 + void _sliderChanged();
2811 +
2812 + static void _profileSelected(GtkWidget *src, gpointer data);
2813 + static void _fixupHit(GtkWidget *src, gpointer data);
2814 +
2815 +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2816 + void _setProfile(SVGICCColor *profile);
2817 + void _switchToProfile(gchar const *name);
2818 +#endif
2819 + void _updateSliders(gint ignore);
2820 + void _profilesChanged(std::string const &name);
2821 +
2822 + ColorICCSelector *_owner;
2823 + SelectedColor &_color;
2824 +
2825 + gboolean _updating : 1;
2826 + gboolean _dragging : 1;
2827 +
2828 + guint32 _fixupNeeded;
2829 + GtkWidget *_fixupBtn;
2830 + GtkWidget *_profileSel;
2831 +
2832 + std::vector<ComponentUI> _compUI;
2833 +
2834 + GtkAdjustment *_adj; // Channel adjustment
2835 + Inkscape::UI::Widget::ColorSlider *_slider;
2836 + GtkWidget *_sbtn; // Spinbutton
2837 + GtkWidget *_label; // Label
2838 +
2839 +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2840 + std::string _profileName;
2841 + Inkscape::ColorProfile *_prof;
2842 + guint _profChannelCount;
2843 + gulong _profChangedID;
2844 +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2845 +};
2846 +
2847 +
2848 +
2849 +const gchar *ColorICCSelector::MODE_NAME = N_("CMS");
2850 +
2851 +ColorICCSelector::ColorICCSelector(SelectedColor &color)
2852 + : _impl(NULL)
2853 +{
2854 + _impl = new ColorICCSelectorImpl(this, color);
2855 + init();
2856 + color.signal_changed.connect(sigc::mem_fun(this, &ColorICCSelector::_colorChanged));
2857 + // color.signal_dragged.connect(sigc::mem_fun(this, &ColorICCSelector::_colorChanged));
2858 +}
2859 +
2860 +ColorICCSelector::~ColorICCSelector()
2861 +{
2862 + if (_impl) {
2863 + delete _impl;
2864 + _impl = 0;
2865 + }
2866 +}
2867 +
2868 +
2869 +
2870 +ColorICCSelectorImpl::ColorICCSelectorImpl(ColorICCSelector *owner, SelectedColor &color)
2871 + : _owner(owner)
2872 + , _color(color)
2873 + , _updating(FALSE)
2874 + , _dragging(FALSE)
2875 + , _fixupNeeded(0)
2876 + , _fixupBtn(0)
2877 + , _profileSel(0)
2878 + , _compUI()
2879 + , _adj(0)
2880 + , _slider(0)
2881 + , _sbtn(0)
2882 + , _label(0)
2883 +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2884 + , _profileName()
2885 + , _prof(0)
2886 + , _profChannelCount(0)
2887 + , _profChangedID(0)
2888 #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2889 {
2890 }
2891 @@ -405,21 +359,12 @@
2892
2893 void ColorICCSelector::init()
2894 {
2895 - if (_impl) delete(_impl);
2896 - _impl = new ColorICCSelectorImpl(this);
2897 gint row = 0;
2898
2899 _impl->_updating = FALSE;
2900 _impl->_dragging = FALSE;
2901
2902 -#if GTK_CHECK_VERSION(3,0,0)
2903 - GtkWidget *t = gtk_grid_new();
2904 -#else
2905 - GtkWidget *t = gtk_table_new(5, 3, FALSE);
2906 -#endif
2907 -
2908 - gtk_widget_show (t);
2909 - gtk_box_pack_start (GTK_BOX (_csel), t, TRUE, TRUE, 4);
2910 + GtkWidget *t = GTK_WIDGET(gobj());
2911
2912 _impl->_compUI.clear();
2913
2914 @@ -428,50 +373,53 @@
2915
2916
2917 _impl->_fixupBtn = gtk_button_new_with_label(_("Fix"));
2918 - g_signal_connect( G_OBJECT(_impl->_fixupBtn), "clicked", G_CALLBACK(ColorICCSelectorImpl::_fixupHit), (gpointer)_impl );
2919 - gtk_widget_set_sensitive( _impl->_fixupBtn, FALSE );
2920 - gtk_widget_set_tooltip_text( _impl->_fixupBtn, _("Fix RGB fallback to match icc-color() value.") );
2921 - //gtk_misc_set_alignment( GTK_MISC (_impl->_fixupBtn), 1.0, 0.5 );
2922 - gtk_widget_show( _impl->_fixupBtn );
2923 + g_signal_connect(G_OBJECT(_impl->_fixupBtn), "clicked", G_CALLBACK(ColorICCSelectorImpl::_fixupHit),
2924 + (gpointer)_impl);
2925 + gtk_widget_set_sensitive(_impl->_fixupBtn, FALSE);
2926 + gtk_widget_set_tooltip_text(_impl->_fixupBtn, _("Fix RGB fallback to match icc-color() value."));
2927 + // gtk_misc_set_alignment( GTK_MISC (_impl->_fixupBtn), 1.0, 0.5 );
2928 + gtk_widget_show(_impl->_fixupBtn);
2929
2930 attachToGridOrTable(t, _impl->_fixupBtn, 0, row, 1, 1);
2931
2932 // Combobox and store with 2 columns : label (0) and full name (1)
2933 - GtkListStore *store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
2934 - _impl->_profileSel = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
2935 + GtkListStore *store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
2936 + _impl->_profileSel = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
2937
2938 - GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
2939 + GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
2940 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(_impl->_profileSel), renderer, TRUE);
2941 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(_impl->_profileSel), renderer, "text", 0, NULL);
2942
2943 GtkTreeIter iter;
2944 - gtk_list_store_append (store, &iter);
2945 - gtk_list_store_set (store, &iter, 0, _("<none>"), 1, _("<none>"), -1);
2946 + gtk_list_store_append(store, &iter);
2947 + gtk_list_store_set(store, &iter, 0, _("<none>"), 1, _("<none>"), -1);
2948
2949 - gtk_widget_show( _impl->_profileSel );
2950 - gtk_combo_box_set_active( GTK_COMBO_BOX(_impl->_profileSel), 0 );
2951 + gtk_widget_show(_impl->_profileSel);
2952 + gtk_combo_box_set_active(GTK_COMBO_BOX(_impl->_profileSel), 0);
2953
2954 attachToGridOrTable(t, _impl->_profileSel, 1, row, 1, 1);
2955
2956 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2957 - _impl->_profChangedID = g_signal_connect( G_OBJECT(_impl->_profileSel), "changed", G_CALLBACK(ColorICCSelectorImpl::_profileSelected), (gpointer)_impl );
2958 + _impl->_profChangedID = g_signal_connect(G_OBJECT(_impl->_profileSel), "changed",
2959 + G_CALLBACK(ColorICCSelectorImpl::_profileSelected), (gpointer)_impl);
2960 #else
2961 - gtk_widget_set_sensitive( _impl->_profileSel, false );
2962 + gtk_widget_set_sensitive(_impl->_profileSel, false);
2963 #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2964
2965
2966 row++;
2967
2968 - // populate the data for colorspaces and channels:
2969 +// populate the data for colorspaces and channels:
2970 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2971 - std::vector<colorspace::Component> things = colorspace::getColorSpaceInfo( cmsSigRgbData );
2972 + std::vector<colorspace::Component> things = colorspace::getColorSpaceInfo(cmsSigRgbData);
2973 #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2974
2975 - for ( size_t i = 0; i < maxColorspaceComponentCount; i++ ) {
2976 + for (size_t i = 0; i < maxColorspaceComponentCount; i++) {
2977 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
2978 if (i < things.size()) {
2979 _impl->_compUI.push_back(ComponentUI(things[i]));
2980 - } else {
2981 + }
2982 + else {
2983 _impl->_compUI.push_back(ComponentUI());
2984 }
2985
2986 @@ -482,9 +430,10 @@
2987 std::string labelStr = ".";
2988 #endif
2989
2990 - _impl->_compUI[i]._label = gtk_label_new_with_mnemonic( labelStr.c_str() );
2991 - gtk_misc_set_alignment( GTK_MISC (_impl->_compUI[i]._label), 1.0, 0.5 );
2992 - gtk_widget_show( _impl->_compUI[i]._label );
2993 + _impl->_compUI[i]._label = gtk_label_new_with_mnemonic(labelStr.c_str());
2994 + gtk_misc_set_alignment(GTK_MISC(_impl->_compUI[i]._label), 1.0, 0.5);
2995 + gtk_widget_show(_impl->_compUI[i]._label);
2996 + gtk_widget_set_no_show_all(_impl->_compUI[i]._label, TRUE);
2997
2998 attachToGridOrTable(t, _impl->_compUI[i]._label, 0, row, 1, 1);
2999
3000 @@ -493,41 +442,47 @@
3001 gdouble step = static_cast<gdouble>(scaleValue) / 100.0;
3002 gdouble page = static_cast<gdouble>(scaleValue) / 10.0;
3003 gint digits = (step > 0.9) ? 0 : 2;
3004 - _impl->_compUI[i]._adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, 0.0, scaleValue, step, page, page ) );
3005 + _impl->_compUI[i]._adj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, scaleValue, step, page, page));
3006
3007 // Slider
3008 - _impl->_compUI[i]._slider = sp_color_slider_new( _impl->_compUI[i]._adj );
3009 -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3010 - gtk_widget_set_tooltip_text( _impl->_compUI[i]._slider, (i < things.size()) ? things[i].tip.c_str() : "" );
3011 -#else
3012 - gtk_widget_set_tooltip_text( _impl->_compUI[i]._slider, "." );
3013 -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3014 - gtk_widget_show( _impl->_compUI[i]._slider );
3015 -
3016 - attachToGridOrTable(t, _impl->_compUI[i]._slider, 1, row, 1, 1, true);
3017 -
3018 - _impl->_compUI[i]._btn = gtk_spin_button_new( _impl->_compUI[i]._adj, step, digits );
3019 -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3020 - gtk_widget_set_tooltip_text( _impl->_compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : "" );
3021 -#else
3022 - gtk_widget_set_tooltip_text( _impl->_compUI[i]._btn, "." );
3023 -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3024 - sp_dialog_defocus_on_enter( _impl->_compUI[i]._btn );
3025 - gtk_label_set_mnemonic_widget( GTK_LABEL(_impl->_compUI[i]._label), _impl->_compUI[i]._btn );
3026 - gtk_widget_show( _impl->_compUI[i]._btn );
3027 + _impl->_compUI[i]._slider =
3028 + Gtk::manage(new Inkscape::UI::Widget::ColorSlider(Glib::wrap(_impl->_compUI[i]._adj, true)));
3029 +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3030 + _impl->_compUI[i]._slider->set_tooltip_text((i < things.size()) ? things[i].tip.c_str() : "");
3031 +#else
3032 + _impl->_compUI[i]._slider->set_tooltip_text(".");
3033 +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3034 + _impl->_compUI[i]._slider->show();
3035 + _impl->_compUI[i]._slider->set_no_show_all();
3036 +
3037 + attachToGridOrTable(t, _impl->_compUI[i]._slider->gobj(), 1, row, 1, 1, true);
3038 +
3039 + _impl->_compUI[i]._btn = gtk_spin_button_new(_impl->_compUI[i]._adj, step, digits);
3040 +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3041 + gtk_widget_set_tooltip_text(_impl->_compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : "");
3042 +#else
3043 + gtk_widget_set_tooltip_text(_impl->_compUI[i]._btn, ".");
3044 +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3045 + sp_dialog_defocus_on_enter(_impl->_compUI[i]._btn);
3046 + gtk_label_set_mnemonic_widget(GTK_LABEL(_impl->_compUI[i]._label), _impl->_compUI[i]._btn);
3047 + gtk_widget_show(_impl->_compUI[i]._btn);
3048 + gtk_widget_set_no_show_all(_impl->_compUI[i]._btn, TRUE);
3049
3050 attachToGridOrTable(t, _impl->_compUI[i]._btn, 2, row, 1, 1, false, true);
3051
3052 - _impl->_compUI[i]._map = g_new( guchar, 4 * 1024 );
3053 - memset( _impl->_compUI[i]._map, 0x0ff, 1024 * 4 );
3054 + _impl->_compUI[i]._map = g_new(guchar, 4 * 1024);
3055 + memset(_impl->_compUI[i]._map, 0x0ff, 1024 * 4);
3056
3057
3058 // Signals
3059 - g_signal_connect( G_OBJECT( _impl->_compUI[i]._adj ), "value_changed", G_CALLBACK( ColorICCSelectorImpl::_adjustmentChanged ), _csel );
3060 + g_signal_connect(G_OBJECT(_impl->_compUI[i]._adj), "value_changed",
3061 + G_CALLBACK(ColorICCSelectorImpl::_adjustmentChanged), _impl);
3062
3063 - g_signal_connect( G_OBJECT( _impl->_compUI[i]._slider ), "grabbed", G_CALLBACK( ColorICCSelectorImpl::_sliderGrabbed ), _csel );
3064 - g_signal_connect( G_OBJECT( _impl->_compUI[i]._slider ), "released", G_CALLBACK( ColorICCSelectorImpl::_sliderReleased ), _csel );
3065 - g_signal_connect( G_OBJECT( _impl->_compUI[i]._slider ), "changed", G_CALLBACK( ColorICCSelectorImpl::_sliderChanged ), _csel );
3066 + _impl->_compUI[i]._slider->signal_grabbed.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderGrabbed));
3067 + _impl->_compUI[i]._slider->signal_released.connect(
3068 + sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderReleased));
3069 + _impl->_compUI[i]._slider->signal_value_changed.connect(
3070 + sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderChanged));
3071
3072 row++;
3073 }
3074 @@ -543,16 +498,14 @@
3075 _impl->_adj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 255.0, 1.0, 10.0, 10.0));
3076
3077 // Slider
3078 - _impl->_slider = sp_color_slider_new(_impl->_adj);
3079 - gtk_widget_set_tooltip_text(_impl->_slider, _("Alpha (opacity)"));
3080 - gtk_widget_show(_impl->_slider);
3081 -
3082 - attachToGridOrTable(t, _impl->_slider, 1, row, 1, 1, true);
3083 -
3084 - sp_color_slider_set_colors( SP_COLOR_SLIDER( _impl->_slider ),
3085 - SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 0.0 ),
3086 - SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 0.5 ),
3087 - SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 1.0 ) );
3088 + _impl->_slider = Gtk::manage(new Inkscape::UI::Widget::ColorSlider(Glib::wrap(_impl->_adj, true)));
3089 + _impl->_slider->set_tooltip_text(_("Alpha (opacity)"));
3090 + _impl->_slider->show();
3091 +
3092 + attachToGridOrTable(t, _impl->_slider->gobj(), 1, row, 1, 1, true);
3093 +
3094 + _impl->_slider->setColors(SP_RGBA32_F_COMPOSE(1.0, 1.0, 1.0, 0.0), SP_RGBA32_F_COMPOSE(1.0, 1.0, 1.0, 0.5),
3095 + SP_RGBA32_F_COMPOSE(1.0, 1.0, 1.0, 1.0));
3096
3097
3098 // Spinbutton
3099 @@ -565,96 +518,72 @@
3100 attachToGridOrTable(t, _impl->_sbtn, 2, row, 1, 1, false, true);
3101
3102 // Signals
3103 - g_signal_connect(G_OBJECT(_impl->_adj), "value_changed", G_CALLBACK(ColorICCSelectorImpl::_adjustmentChanged), _csel);
3104 -
3105 - g_signal_connect(G_OBJECT(_impl->_slider), "grabbed", G_CALLBACK(ColorICCSelectorImpl::_sliderGrabbed), _csel);
3106 - g_signal_connect(G_OBJECT(_impl->_slider), "released", G_CALLBACK(ColorICCSelectorImpl::_sliderReleased), _csel);
3107 - g_signal_connect(G_OBJECT(_impl->_slider), "changed", G_CALLBACK(ColorICCSelectorImpl::_sliderChanged), _csel);
3108 -}
3109 -
3110 -static void sp_color_icc_selector_dispose(GObject *object)
3111 -{
3112 - if (G_OBJECT_CLASS(sp_color_icc_selector_parent_class)->dispose) {
3113 - G_OBJECT_CLASS(sp_color_icc_selector_parent_class)->dispose(object);
3114 - }
3115 -}
3116 -
3117 -static void
3118 -sp_color_icc_selector_show_all (GtkWidget *widget)
3119 -{
3120 - gtk_widget_show (widget);
3121 -}
3122 -
3123 -static void sp_color_icc_selector_hide(GtkWidget *widget)
3124 -{
3125 - gtk_widget_hide(widget);
3126 -}
3127 -
3128 -GtkWidget *
3129 -sp_color_icc_selector_new (void)
3130 -{
3131 - SPColorICCSelector *csel;
3132 -
3133 - csel = static_cast<SPColorICCSelector*>(g_object_new (SP_TYPE_COLOR_ICC_SELECTOR, NULL));
3134 -
3135 - return GTK_WIDGET (csel);
3136 -}
3137 -
3138 -
3139 -void ColorICCSelectorImpl::_fixupHit( GtkWidget* /*src*/, gpointer data )
3140 -{
3141 - ColorICCSelectorImpl* self = reinterpret_cast<ColorICCSelectorImpl*>(data);
3142 - gtk_widget_set_sensitive( self->_fixupBtn, FALSE );
3143 - self->_adjustmentChanged( self->_compUI[0]._adj, SP_COLOR_ICC_SELECTOR(self->_owner->_csel) );
3144 + g_signal_connect(G_OBJECT(_impl->_adj), "value_changed", G_CALLBACK(ColorICCSelectorImpl::_adjustmentChanged),
3145 + _impl);
3146 +
3147 + _impl->_slider->signal_grabbed.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderGrabbed));
3148 + _impl->_slider->signal_released.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderReleased));
3149 + _impl->_slider->signal_value_changed.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderChanged));
3150 +
3151 + gtk_widget_show(t);
3152 +}
3153 +
3154 +void ColorICCSelectorImpl::_fixupHit(GtkWidget * /*src*/, gpointer data)
3155 +{
3156 + ColorICCSelectorImpl *self = reinterpret_cast<ColorICCSelectorImpl *>(data);
3157 + gtk_widget_set_sensitive(self->_fixupBtn, FALSE);
3158 + self->_adjustmentChanged(self->_compUI[0]._adj, self);
3159 }
3160
3161 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3162 -void ColorICCSelectorImpl::_profileSelected( GtkWidget* /*src*/, gpointer data )
3163 +void ColorICCSelectorImpl::_profileSelected(GtkWidget * /*src*/, gpointer data)
3164 {
3165 - ColorICCSelectorImpl* self = reinterpret_cast<ColorICCSelectorImpl*>(data);
3166 + ColorICCSelectorImpl *self = reinterpret_cast<ColorICCSelectorImpl *>(data);
3167
3168 - GtkTreeIter iter;
3169 + GtkTreeIter iter;
3170 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(self->_profileSel), &iter)) {
3171 GtkTreeModel *store = gtk_combo_box_get_model(GTK_COMBO_BOX(self->_profileSel));
3172 - gchar* name = 0;
3173 + gchar *name = 0;
3174
3175 gtk_tree_model_get(store, &iter, 1, &name, -1);
3176 - self->_switchToProfile( name );
3177 - gtk_widget_set_tooltip_text(self->_profileSel, name );
3178 + self->_switchToProfile(name);
3179 + gtk_widget_set_tooltip_text(self->_profileSel, name);
3180
3181 - if ( name ) {
3182 - g_free( name );
3183 + if (name) {
3184 + g_free(name);
3185 }
3186 }
3187 }
3188 #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3189
3190 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3191 -void ColorICCSelectorImpl::_switchToProfile( gchar const* name )
3192 +void ColorICCSelectorImpl::_switchToProfile(gchar const *name)
3193 {
3194 bool dirty = false;
3195 - SPColor tmp( _owner->_color );
3196 + SPColor tmp(_color.color());
3197
3198 - if ( name ) {
3199 - if ( tmp.icc && tmp.icc->colorProfile == name ) {
3200 -#ifdef DEBUG_LCMS
3201 - g_message("Already at name [%s]", name );
3202 -#endif // DEBUG_LCMS
3203 - } else {
3204 -#ifdef DEBUG_LCMS
3205 - g_message("Need to switch to profile [%s]", name );
3206 -#endif // DEBUG_LCMS
3207 - if ( tmp.icc ) {
3208 + if (name) {
3209 + if (tmp.icc && tmp.icc->colorProfile == name) {
3210 +#ifdef DEBUG_LCMS
3211 + g_message("Already at name [%s]", name);
3212 +#endif // DEBUG_LCMS
3213 + }
3214 + else {
3215 +#ifdef DEBUG_LCMS
3216 + g_message("Need to switch to profile [%s]", name);
3217 +#endif // DEBUG_LCMS
3218 + if (tmp.icc) {
3219 tmp.icc->colors.clear();
3220 - } else {
3221 + }
3222 + else {
3223 tmp.icc = new SVGICCColor();
3224 }
3225 tmp.icc->colorProfile = name;
3226 - Inkscape::ColorProfile* newProf = SP_ACTIVE_DOCUMENT->profileManager->find(name);
3227 - if ( newProf ) {
3228 + Inkscape::ColorProfile *newProf = SP_ACTIVE_DOCUMENT->profileManager->find(name);
3229 + if (newProf) {
3230 cmsHTRANSFORM trans = newProf->getTransfFromSRGB8();
3231 - if ( trans ) {
3232 - guint32 val = _owner->_color.toRGBA32(0);
3233 + if (trans) {
3234 + guint32 val = _color.color().toRGBA32(0);
3235 guchar pre[4] = {
3236 static_cast<guchar>(SP_RGBA32_R_U(val)),
3237 static_cast<guchar>(SP_RGBA32_G_U(val)),
3238 @@ -663,29 +592,31 @@
3239 #ifdef DEBUG_LCMS
3240 g_message("Shoving in [%02x] [%02x] [%02x]", pre[0], pre[1], pre[2]);
3241 #endif // DEBUG_LCMS
3242 - cmsUInt16Number post[4] = {0,0,0,0};
3243 - cmsDoTransform( trans, pre, post, 1 );
3244 + cmsUInt16Number post[4] = { 0, 0, 0, 0 };
3245 + cmsDoTransform(trans, pre, post, 1);
3246 #ifdef DEBUG_LCMS
3247 g_message("got on out [%04x] [%04x] [%04x] [%04x]", post[0], post[1], post[2], post[3]);
3248 #endif // DEBUG_LCMS
3249 #if HAVE_LIBLCMS1
3250 - guint count = _cmsChannelsOf( asICColorSpaceSig(newProf->getColorSpace()) );
3251 + guint count = _cmsChannelsOf(asICColorSpaceSig(newProf->getColorSpace()));
3252 #elif HAVE_LIBLCMS2
3253 - guint count = cmsChannelsOf( asICColorSpaceSig(newProf->getColorSpace()) );
3254 + guint count = cmsChannelsOf(asICColorSpaceSig(newProf->getColorSpace()));
3255 #endif
3256
3257 - std::vector<colorspace::Component> things = colorspace::getColorSpaceInfo(asICColorSpaceSig(newProf->getColorSpace()));
3258 + std::vector<colorspace::Component> things =
3259 + colorspace::getColorSpaceInfo(asICColorSpaceSig(newProf->getColorSpace()));
3260
3261 - for ( guint i = 0; i < count; i++ ) {
3262 - gdouble val = (((gdouble)post[i])/65535.0) * (gdouble)((i < things.size()) ? things[i].scale : 1);
3263 + for (guint i = 0; i < count; i++) {
3264 + gdouble val =
3265 + (((gdouble)post[i]) / 65535.0) * (gdouble)((i < things.size()) ? things[i].scale : 1);
3266 #ifdef DEBUG_LCMS
3267 g_message(" scaled %d by %d to be %f", i, ((i < things.size()) ? things[i].scale : 1), val);
3268 #endif // DEBUG_LCMS
3269 tmp.icc->colors.push_back(val);
3270 }
3271 cmsHTRANSFORM retrans = newProf->getTransfToSRGB8();
3272 - if ( retrans ) {
3273 - cmsDoTransform( retrans, post, pre, 1 );
3274 + if (retrans) {
3275 + cmsDoTransform(retrans, post, pre, 1);
3276 #ifdef DEBUG_LCMS
3277 g_message(" back out [%02x] [%02x] [%02x]", pre[0], pre[1], pre[2]);
3278 #endif // DEBUG_LCMS
3279 @@ -695,30 +626,32 @@
3280 }
3281 dirty = true;
3282 }
3283 - } else {
3284 + }
3285 + else {
3286 #ifdef DEBUG_LCMS
3287 - g_message("NUKE THE ICC");
3288 + g_message("NUKE THE ICC");
3289 #endif // DEBUG_LCMS
3290 - if ( tmp.icc ) {
3291 + if (tmp.icc) {
3292 delete tmp.icc;
3293 tmp.icc = 0;
3294 dirty = true;
3295 - _fixupHit( 0, this );
3296 - } else {
3297 + _fixupHit(0, this);
3298 + }
3299 + else {
3300 #ifdef DEBUG_LCMS
3301 - g_message("No icc to nuke");
3302 + g_message("No icc to nuke");
3303 #endif // DEBUG_LCMS
3304 }
3305 }
3306
3307 - if ( dirty ) {
3308 + if (dirty) {
3309 #ifdef DEBUG_LCMS
3310 g_message("+----------------");
3311 g_message("+ new color is [%s]", tmp.toString().c_str());
3312 #endif // DEBUG_LCMS
3313 - _setProfile( tmp.icc );
3314 + _setProfile(tmp.icc);
3315 //_adjustmentChanged( _compUI[0]._adj, SP_COLOR_ICC_SELECTOR(_csel) );
3316 - _owner->setColorAlpha( tmp, _owner->_alpha, true );
3317 + _color.setColor(tmp);
3318 #ifdef DEBUG_LCMS
3319 g_message("+_________________");
3320 #endif // DEBUG_LCMS
3321 @@ -727,238 +660,257 @@
3322 #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3323
3324 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3325 -void ColorICCSelectorImpl::_profilesChanged( std::string const & name )
3326 +void ColorICCSelectorImpl::_profilesChanged(std::string const &name)
3327 {
3328 - GtkComboBox* combo = GTK_COMBO_BOX(_profileSel);
3329 + GtkComboBox *combo = GTK_COMBO_BOX(_profileSel);
3330
3331 - g_signal_handler_block( G_OBJECT(_profileSel), _profChangedID );
3332 + g_signal_handler_block(G_OBJECT(_profileSel), _profChangedID);
3333
3334 GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(combo));
3335 gtk_list_store_clear(store);
3336
3337 GtkTreeIter iter;
3338 - gtk_list_store_append (store, &iter);
3339 + gtk_list_store_append(store, &iter);
3340 gtk_list_store_set(store, &iter, 0, _("<none>"), 1, _("<none>"), -1);
3341
3342 - gtk_combo_box_set_active( combo, 0 );
3343 + gtk_combo_box_set_active(combo, 0);
3344
3345 int index = 1;
3346 - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" );
3347 - while ( current ) {
3348 - SPObject* obj = SP_OBJECT(current->data);
3349 - Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);
3350 + const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("iccprofile");
3351 + while (current) {
3352 + SPObject *obj = SP_OBJECT(current->data);
3353 + Inkscape::ColorProfile *prof = reinterpret_cast<Inkscape::ColorProfile *>(obj);
3354
3355 - gtk_list_store_append (store, &iter);
3356 + gtk_list_store_append(store, &iter);
3357 gtk_list_store_set(store, &iter, 0, gr_ellipsize_text(prof->name, 25).c_str(), 1, prof->name, -1);
3358
3359 - if ( name == prof->name ) {
3360 - gtk_combo_box_set_active( combo, index );
3361 - gtk_widget_set_tooltip_text(_profileSel, prof->name );
3362 + if (name == prof->name) {
3363 + gtk_combo_box_set_active(combo, index);
3364 + gtk_widget_set_tooltip_text(_profileSel, prof->name);
3365 }
3366
3367 index++;
3368 current = g_slist_next(current);
3369 }
3370
3371 - g_signal_handler_unblock( G_OBJECT(_profileSel), _profChangedID );
3372 + g_signal_handler_unblock(G_OBJECT(_profileSel), _profChangedID);
3373 }
3374 #else
3375 -void ColorICCSelectorImpl::_profilesChanged( std::string const & /*name*/ )
3376 +void ColorICCSelectorImpl::_profilesChanged(std::string const & /*name*/) {}
3377 +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3378 +
3379 +void ColorICCSelector::on_show()
3380 {
3381 +#if GTK_CHECK_VERSION(3, 0, 0)
3382 + Gtk::Grid::on_show();
3383 +#else
3384 + Gtk::Table::on_show();
3385 +#endif
3386 + _colorChanged();
3387 }
3388 -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3389
3390 // Helpers for setting color value
3391
3392 void ColorICCSelector::_colorChanged()
3393 {
3394 _impl->_updating = TRUE;
3395 - //sp_color_icc_set_color( SP_COLOR_ICC( _icc ), &color );
3396 -
3397 -#ifdef DEBUG_LCMS
3398 - g_message( "/^^^^^^^^^ %p::_colorChanged(%08x:%s)", this,
3399 - _color.toRGBA32(_alpha), ( (_color.icc) ? _color.icc->colorProfile.c_str(): "<null>" )
3400 - );
3401 -#endif // DEBUG_LCMS
3402 -
3403 -#ifdef DEBUG_LCMS
3404 - g_message("FLIPPIES!!!! %p '%s'", _color.icc, (_color.icc ? _color.icc->colorProfile.c_str():"<null>"));
3405 -#endif // DEBUG_LCMS
3406 -
3407 - _impl->_profilesChanged( (_color.icc) ? _color.icc->colorProfile : std::string("") );
3408 - ColorScales::setScaled( _impl->_adj, _alpha );
3409 +// sp_color_icc_set_color( SP_COLOR_ICC( _icc ), &color );
3410 +
3411 +#ifdef DEBUG_LCMS
3412 + g_message("/^^^^^^^^^ %p::_colorChanged(%08x:%s)", this, _impl->_color.color().toRGBA32(_impl->_color.alpha()),
3413 + ((_impl->_color.color().icc) ? _impl->_color.color().icc->colorProfile.c_str() : "<null>"));
3414 +#endif // DEBUG_LCMS
3415 +
3416 +#ifdef DEBUG_LCMS
3417 + g_message("FLIPPIES!!!! %p '%s'", _impl->_color.color().icc,
3418 + (_impl->_color.color().icc ? _impl->_color.color().icc->colorProfile.c_str() : "<null>"));
3419 +#endif // DEBUG_LCMS
3420 +
3421 + _impl->_profilesChanged((_impl->_color.color().icc) ? _impl->_color.color().icc->colorProfile : std::string(""));
3422 + ColorScales::setScaled(_impl->_adj, _impl->_color.alpha());
3423
3424 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3425 - _impl->_setProfile( _color.icc );
3426 + _impl->_setProfile(_impl->_color.color().icc);
3427 _impl->_fixupNeeded = 0;
3428 - gtk_widget_set_sensitive( _impl->_fixupBtn, FALSE );
3429 + gtk_widget_set_sensitive(_impl->_fixupBtn, FALSE);
3430
3431 if (_impl->_prof) {
3432 - if (_impl->_prof->getTransfToSRGB8() ) {
3433 + if (_impl->_prof->getTransfToSRGB8()) {
3434 cmsUInt16Number tmp[4];
3435 - for ( guint i = 0; i < _impl->_profChannelCount; i++ ) {
3436 + for (guint i = 0; i < _impl->_profChannelCount; i++) {
3437 gdouble val = 0.0;
3438 - if ( _color.icc->colors.size() > i ) {
3439 - if ( _impl->_compUI[i]._component.scale == 256 ) {
3440 - val = (_color.icc->colors[i] + 128.0) / static_cast<gdouble>(_impl->_compUI[i]._component.scale);
3441 - } else {
3442 - val = _color.icc->colors[i] / static_cast<gdouble>(_impl->_compUI[i]._component.scale);
3443 + if (_impl->_color.color().icc->colors.size() > i) {
3444 + if (_impl->_compUI[i]._component.scale == 256) {
3445 + val = (_impl->_color.color().icc->colors[i] + 128.0) /
3446 + static_cast<gdouble>(_impl->_compUI[i]._component.scale);
3447 + }
3448 + else {
3449 + val = _impl->_color.color().icc->colors[i] /
3450 + static_cast<gdouble>(_impl->_compUI[i]._component.scale);
3451 }
3452 }
3453 tmp[i] = val * 0x0ffff;
3454 }
3455 - guchar post[4] = {0,0,0,0};
3456 + guchar post[4] = { 0, 0, 0, 0 };
3457 cmsHTRANSFORM trans = _impl->_prof->getTransfToSRGB8();
3458 - if ( trans ) {
3459 - cmsDoTransform( trans, tmp, post, 1 );
3460 - guint32 other = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255 );
3461 - if ( other != _color.toRGBA32(255) ) {
3462 + if (trans) {
3463 + cmsDoTransform(trans, tmp, post, 1);
3464 + guint32 other = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255);
3465 + if (other != _impl->_color.color().toRGBA32(255)) {
3466 _impl->_fixupNeeded = other;
3467 - gtk_widget_set_sensitive( _impl->_fixupBtn, TRUE );
3468 + gtk_widget_set_sensitive(_impl->_fixupBtn, TRUE);
3469 #ifdef DEBUG_LCMS
3470 - g_message("Color needs to change 0x%06x to 0x%06x", _color.toRGBA32(255) >> 8, other >> 8 );
3471 + g_message("Color needs to change 0x%06x to 0x%06x", _color.toRGBA32(255) >> 8, other >> 8);
3472 #endif // DEBUG_LCMS
3473 }
3474 }
3475 }
3476 }
3477 #else
3478 - //(void)color;
3479 +//(void)color;
3480 #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3481 - _impl->_updateSliders( -1 );
3482 + _impl->_updateSliders(-1);
3483
3484
3485 _impl->_updating = FALSE;
3486 #ifdef DEBUG_LCMS
3487 - g_message( "\\_________ %p::_colorChanged()", this );
3488 + g_message("\\_________ %p::_colorChanged()", this);
3489 #endif // DEBUG_LCMS
3490 }
3491
3492 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3493 -void ColorICCSelectorImpl::_setProfile( SVGICCColor* profile )
3494 +void ColorICCSelectorImpl::_setProfile(SVGICCColor *profile)
3495 {
3496 #ifdef DEBUG_LCMS
3497 - g_message( "/^^^^^^^^^ %p::_setProfile(%s)", this,
3498 - ( (profile) ? profile->colorProfile.c_str() : "<null>")
3499 - );
3500 + g_message("/^^^^^^^^^ %p::_setProfile(%s)", this, ((profile) ? profile->colorProfile.c_str() : "<null>"));
3501 #endif // DEBUG_LCMS
3502 bool profChanged = false;
3503 - if ( _prof && (!profile || (_profileName != profile->colorProfile) ) ) {
3504 + if (_prof && (!profile || (_profileName != profile->colorProfile))) {
3505 // Need to clear out the prior one
3506 profChanged = true;
3507 _profileName.clear();
3508 _prof = 0;
3509 _profChannelCount = 0;
3510 - } else if ( profile && !_prof ) {
3511 + }
3512 + else if (profile && !_prof) {
3513 profChanged = true;
3514 }
3515
3516 - for ( size_t i = 0; i < _compUI.size(); i++ ) {
3517 - gtk_widget_hide( _compUI[i]._label );
3518 - gtk_widget_hide( _compUI[i]._slider );
3519 - gtk_widget_hide( _compUI[i]._btn );
3520 + for (size_t i = 0; i < _compUI.size(); i++) {
3521 + gtk_widget_hide(_compUI[i]._label);
3522 + _compUI[i]._slider->hide();
3523 + gtk_widget_hide(_compUI[i]._btn);
3524 }
3525
3526 - if ( profile ) {
3527 + if (profile) {
3528 _prof = SP_ACTIVE_DOCUMENT->profileManager->find(profile->colorProfile.c_str());
3529 - if ( _prof && (asICColorProfileClassSig(_prof->getProfileClass()) != cmsSigNamedColorClass) ) {
3530 + if (_prof && (asICColorProfileClassSig(_prof->getProfileClass()) != cmsSigNamedColorClass)) {
3531 #if HAVE_LIBLCMS1
3532 - _profChannelCount = _cmsChannelsOf( asICColorSpaceSig(_prof->getColorSpace()) );
3533 + _profChannelCount = _cmsChannelsOf(asICColorSpaceSig(_prof->getColorSpace()));
3534 #elif HAVE_LIBLCMS2
3535 - _profChannelCount = cmsChannelsOf( asICColorSpaceSig(_prof->getColorSpace()) );
3536 + _profChannelCount = cmsChannelsOf(asICColorSpaceSig(_prof->getColorSpace()));
3537 #endif
3538
3539 - if ( profChanged ) {
3540 - std::vector<colorspace::Component> things = colorspace::getColorSpaceInfo(asICColorSpaceSig(_prof->getColorSpace()));
3541 - for (size_t i = 0; (i < things.size()) && (i < _profChannelCount); ++i)
3542 - {
3543 + if (profChanged) {
3544 + std::vector<colorspace::Component> things =
3545 + colorspace::getColorSpaceInfo(asICColorSpaceSig(_prof->getColorSpace()));
3546 + for (size_t i = 0; (i < things.size()) && (i < _profChannelCount); ++i) {
3547 _compUI[i]._component = things[i];
3548 }
3549
3550 - for ( guint i = 0; i < _profChannelCount; i++ ) {
3551 - gtk_label_set_text_with_mnemonic( GTK_LABEL(_compUI[i]._label), (i < things.size()) ? things[i].name.c_str() : "");
3552 -
3553 - gtk_widget_set_tooltip_text( _compUI[i]._slider, (i < things.size()) ? things[i].tip.c_str() : "" );
3554 - gtk_widget_set_tooltip_text( _compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : "" );
3555 -
3556 - sp_color_slider_set_colors( SP_COLOR_SLIDER(_compUI[i]._slider),
3557 - SPColor(0.0, 0.0, 0.0).toRGBA32(0xff),
3558 - SPColor(0.5, 0.5, 0.5).toRGBA32(0xff),
3559 - SPColor(1.0, 1.0, 1.0).toRGBA32(0xff) );
3560 -/*
3561 - _compUI[i]._adj = GTK_ADJUSTMENT( gtk_adjustment_new( val, 0.0, _fooScales[i], step, page, page ) );
3562 - g_signal_connect( G_OBJECT( _compUI[i]._adj ), "value_changed", G_CALLBACK( _adjustmentChanged ), _csel );
3563 -
3564 - sp_color_slider_set_adjustment( SP_COLOR_SLIDER(_compUI[i]._slider), _compUI[i]._adj );
3565 - gtk_spin_button_set_adjustment( GTK_SPIN_BUTTON(_compUI[i]._btn), _compUI[i]._adj );
3566 - gtk_spin_button_set_digits( GTK_SPIN_BUTTON(_compUI[i]._btn), digits );
3567 -*/
3568 - gtk_widget_show( _compUI[i]._label );
3569 - gtk_widget_show( _compUI[i]._slider );
3570 - gtk_widget_show( _compUI[i]._btn );
3571 - //gtk_adjustment_set_value( _compUI[i]._adj, 0.0 );
3572 - //gtk_adjustment_set_value( _compUI[i]._adj, val );
3573 + for (guint i = 0; i < _profChannelCount; i++) {
3574 + gtk_label_set_text_with_mnemonic(GTK_LABEL(_compUI[i]._label),
3575 + (i < things.size()) ? things[i].name.c_str() : "");
3576 +
3577 + _compUI[i]._slider->set_tooltip_text((i < things.size()) ? things[i].tip.c_str() : "");
3578 + gtk_widget_set_tooltip_text(_compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : "");
3579 +
3580 + _compUI[i]._slider->setColors(SPColor(0.0, 0.0, 0.0).toRGBA32(0xff),
3581 + SPColor(0.5, 0.5, 0.5).toRGBA32(0xff),
3582 + SPColor(1.0, 1.0, 1.0).toRGBA32(0xff));
3583 + /*
3584 + _compUI[i]._adj = GTK_ADJUSTMENT( gtk_adjustment_new( val, 0.0, _fooScales[i],
3585 + step, page, page ) );
3586 + g_signal_connect( G_OBJECT( _compUI[i]._adj ), "value_changed", G_CALLBACK(
3587 + _adjustmentChanged ), _csel );
3588 +
3589 + sp_color_slider_set_adjustment( SP_COLOR_SLIDER(_compUI[i]._slider),
3590 + _compUI[i]._adj );
3591 + gtk_spin_button_set_adjustment( GTK_SPIN_BUTTON(_compUI[i]._btn),
3592 + _compUI[i]._adj );
3593 + gtk_spin_button_set_digits( GTK_SPIN_BUTTON(_compUI[i]._btn), digits );
3594 + */
3595 + gtk_widget_show(_compUI[i]._label);
3596 + _compUI[i]._slider->show();
3597 + gtk_widget_show(_compUI[i]._btn);
3598 + // gtk_adjustment_set_value( _compUI[i]._adj, 0.0 );
3599 + // gtk_adjustment_set_value( _compUI[i]._adj, val );
3600 }
3601 - for ( size_t i = _profChannelCount; i < _compUI.size(); i++ ) {
3602 - gtk_widget_hide( _compUI[i]._label );
3603 - gtk_widget_hide( _compUI[i]._slider );
3604 - gtk_widget_hide( _compUI[i]._btn );
3605 + for (size_t i = _profChannelCount; i < _compUI.size(); i++) {
3606 + gtk_widget_hide(_compUI[i]._label);
3607 + _compUI[i]._slider->hide();
3608 + gtk_widget_hide(_compUI[i]._btn);
3609 }
3610 }
3611 - } else {
3612 + }
3613 + else {
3614 // Give up for now on named colors
3615 _prof = 0;
3616 }
3617 }
3618
3619 #ifdef DEBUG_LCMS
3620 - g_message( "\\_________ %p::_setProfile()", this );
3621 + g_message("\\_________ %p::_setProfile()", this);
3622 #endif // DEBUG_LCMS
3623 }
3624 #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3625
3626 -void ColorICCSelectorImpl::_updateSliders( gint ignore )
3627 +void ColorICCSelectorImpl::_updateSliders(gint ignore)
3628 {
3629 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3630 - if ( _owner->_color.icc )
3631 - {
3632 - for ( guint i = 0; i < _profChannelCount; i++ ) {
3633 + if (_color.color().icc) {
3634 + for (guint i = 0; i < _profChannelCount; i++) {
3635 gdouble val = 0.0;
3636 - if ( _owner->_color.icc->colors.size() > i ) {
3637 - if ( _compUI[i]._component.scale == 256 ) {
3638 - val = (_owner->_color.icc->colors[i] + 128.0) / static_cast<gdouble>(_compUI[i]._component.scale);
3639 - } else {
3640 - val = _owner->_color.icc->colors[i] / static_cast<gdouble>(_compUI[i]._component.scale);
3641 + if (_color.color().icc->colors.size() > i) {
3642 + if (_compUI[i]._component.scale == 256) {
3643 + val = (_color.color().icc->colors[i] + 128.0) / static_cast<gdouble>(_compUI[i]._component.scale);
3644 + }
3645 + else {
3646 + val = _color.color().icc->colors[i] / static_cast<gdouble>(_compUI[i]._component.scale);
3647 }
3648 }
3649 - gtk_adjustment_set_value( _compUI[i]._adj, val );
3650 + gtk_adjustment_set_value(_compUI[i]._adj, val);
3651 }
3652
3653 - if ( _prof ) {
3654 - if ( _prof->getTransfToSRGB8() ) {
3655 - for ( guint i = 0; i < _profChannelCount; i++ ) {
3656 - if ( static_cast<gint>(i) != ignore ) {
3657 - cmsUInt16Number* scratch = getScratch();
3658 - cmsUInt16Number filler[4] = {0, 0, 0, 0};
3659 - for ( guint j = 0; j < _profChannelCount; j++ ) {
3660 - filler[j] = 0x0ffff * ColorScales::getScaled( _compUI[j]._adj );
3661 + if (_prof) {
3662 + if (_prof->getTransfToSRGB8()) {
3663 + for (guint i = 0; i < _profChannelCount; i++) {
3664 + if (static_cast<gint>(i) != ignore) {
3665 + cmsUInt16Number *scratch = getScratch();
3666 + cmsUInt16Number filler[4] = { 0, 0, 0, 0 };
3667 + for (guint j = 0; j < _profChannelCount; j++) {
3668 + filler[j] = 0x0ffff * ColorScales::getScaled(_compUI[j]._adj);
3669 }
3670 -
3671 - cmsUInt16Number* p = scratch;
3672 - for ( guint x = 0; x < 1024; x++ ) {
3673 - for ( guint j = 0; j < _profChannelCount; j++ ) {
3674 - if ( j == i ) {
3675 +
3676 + cmsUInt16Number *p = scratch;
3677 + for (guint x = 0; x < 1024; x++) {
3678 + for (guint j = 0; j < _profChannelCount; j++) {
3679 + if (j == i) {
3680 *p++ = x * 0x0ffff / 1024;
3681 - } else {
3682 + }
3683 + else {
3684 *p++ = filler[j];
3685 }
3686 }
3687 }
3688 -
3689 +
3690 cmsHTRANSFORM trans = _prof->getTransfToSRGB8();
3691 - if ( trans ) {
3692 - cmsDoTransform( trans, scratch, _compUI[i]._map, 1024 );
3693 - sp_color_slider_set_map( SP_COLOR_SLIDER(_compUI[i]._slider), _compUI[i]._map );
3694 + if (trans) {
3695 + cmsDoTransform(trans, scratch, _compUI[i]._map, 1024);
3696 + if (_compUI[i]._slider)
3697 + {
3698 + _compUI[i]._slider->setMap(_compUI[i]._map);
3699 + }
3700 }
3701 }
3702 }
3703 @@ -969,15 +921,15 @@
3704 (void)ignore;
3705 #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3706
3707 - guint32 start = _owner->_color.toRGBA32( 0x00 );
3708 - guint32 mid = _owner->_color.toRGBA32( 0x7f );
3709 - guint32 end = _owner->_color.toRGBA32( 0xff );
3710 + guint32 start = _color.color().toRGBA32(0x00);
3711 + guint32 mid = _color.color().toRGBA32(0x7f);
3712 + guint32 end = _color.color().toRGBA32(0xff);
3713
3714 - sp_color_slider_set_colors( SP_COLOR_SLIDER(_slider), start, mid, end );
3715 + _slider->setColors(start, mid, end);
3716 }
3717
3718
3719 -void ColorICCSelectorImpl::_adjustmentChanged( GtkAdjustment *adjustment, SPColorICCSelector *cs )
3720 +void ColorICCSelectorImpl::_adjustmentChanged(GtkAdjustment *adjustment, ColorICCSelectorImpl *cs)
3721 {
3722 // // TODO check this. It looks questionable:
3723 // // if a value is entered between 0 and 1 exclusive, normalize it to (int) 0..255 or 0..100
3724 @@ -986,121 +938,135 @@
3725 // }
3726
3727 #ifdef DEBUG_LCMS
3728 - g_message( "/^^^^^^^^^ %p::_adjustmentChanged()", cs );
3729 + g_message("/^^^^^^^^^ %p::_adjustmentChanged()", cs);
3730 #endif // DEBUG_LCMS
3731
3732 - ColorICCSelector* iccSelector = static_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base);
3733 - if (iccSelector->_impl->_updating) {
3734 - return;
3735 - }
3736 -
3737 - iccSelector->_impl->_updating = TRUE;
3738 -
3739 - gint match = -1;
3740 -
3741 - SPColor newColor( iccSelector->_color );
3742 - gfloat scaled = ColorScales::getScaled( iccSelector->_impl->_adj );
3743 - if ( iccSelector->_impl->_adj == adjustment ) {
3744 + ColorICCSelector *iccSelector = cs->_owner;
3745 + if (iccSelector->_impl->_updating) {
3746 + return;
3747 + }
3748 +
3749 + iccSelector->_impl->_updating = TRUE;
3750 +
3751 + gint match = -1;
3752 +
3753 + SPColor newColor(iccSelector->_impl->_color.color());
3754 + gfloat scaled = ColorScales::getScaled(iccSelector->_impl->_adj);
3755 + if (iccSelector->_impl->_adj == adjustment) {
3756 #ifdef DEBUG_LCMS
3757 - g_message("ALPHA");
3758 + g_message("ALPHA");
3759 #endif // DEBUG_LCMS
3760 - } else {
3761 + }
3762 + else {
3763 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3764 - for ( size_t i = 0; i < iccSelector->_impl->_compUI.size(); i++ ) {
3765 - if ( iccSelector->_impl->_compUI[i]._adj == adjustment ) {
3766 - match = i;
3767 - break;
3768 - }
3769 - }
3770 - if ( match >= 0 ) {
3771 -#ifdef DEBUG_LCMS
3772 - g_message(" channel %d", match );
3773 -#endif // DEBUG_LCMS
3774 - }
3775 -
3776 -
3777 - cmsUInt16Number tmp[4];
3778 - for ( guint i = 0; i < 4; i++ ) {
3779 - tmp[i] = ColorScales::getScaled( iccSelector->_impl->_compUI[i]._adj ) * 0x0ffff;
3780 - }
3781 - guchar post[4] = {0,0,0,0};
3782 -
3783 - cmsHTRANSFORM trans = iccSelector->_impl->_prof->getTransfToSRGB8();
3784 - if ( trans ) {
3785 - cmsDoTransform( trans, tmp, post, 1 );
3786 - }
3787 -
3788 - SPColor other( SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255) );
3789 - other.icc = new SVGICCColor();
3790 - if ( iccSelector->_color.icc ) {
3791 - other.icc->colorProfile = iccSelector->_color.icc->colorProfile;
3792 - }
3793 -
3794 - guint32 prior = iccSelector->_color.toRGBA32(255);
3795 - guint32 newer = other.toRGBA32(255);
3796 -
3797 - if ( prior != newer ) {
3798 -#ifdef DEBUG_LCMS
3799 - g_message("Transformed color from 0x%08x to 0x%08x", prior, newer );
3800 - g_message(" ~~~~ FLIP");
3801 -#endif // DEBUG_LCMS
3802 - newColor = other;
3803 - newColor.icc->colors.clear();
3804 - for ( guint i = 0; i < iccSelector->_impl->_profChannelCount; i++ ) {
3805 - gdouble val = ColorScales::getScaled( iccSelector->_impl->_compUI[i]._adj );
3806 - val *= iccSelector->_impl->_compUI[i]._component.scale;
3807 - if ( iccSelector->_impl->_compUI[i]._component.scale == 256 ) {
3808 - val -= 128;
3809 - }
3810 - newColor.icc->colors.push_back( val );
3811 - }
3812 - }
3813 + for (size_t i = 0; i < iccSelector->_impl->_compUI.size(); i++) {
3814 + if (iccSelector->_impl->_compUI[i]._adj == adjustment) {
3815 + match = i;
3816 + break;
3817 + }
3818 + }
3819 + if (match >= 0) {
3820 +#ifdef DEBUG_LCMS
3821 + g_message(" channel %d", match);
3822 +#endif // DEBUG_LCMS
3823 + }
3824 +
3825 +
3826 + cmsUInt16Number tmp[4];
3827 + for (guint i = 0; i < 4; i++) {
3828 + tmp[i] = ColorScales::getScaled(iccSelector->_impl->_compUI[i]._adj) * 0x0ffff;
3829 + }
3830 + guchar post[4] = { 0, 0, 0, 0 };
3831 +
3832 + cmsHTRANSFORM trans = iccSelector->_impl->_prof->getTransfToSRGB8();
3833 + if (trans) {
3834 + cmsDoTransform(trans, tmp, post, 1);
3835 + }
3836 +
3837 + SPColor other(SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255));
3838 + other.icc = new SVGICCColor();
3839 + if (iccSelector->_impl->_color.color().icc) {
3840 + other.icc->colorProfile = iccSelector->_impl->_color.color().icc->colorProfile;
3841 + }
3842 +
3843 + guint32 prior = iccSelector->_impl->_color.color().toRGBA32(255);
3844 + guint32 newer = other.toRGBA32(255);
3845 +
3846 + if (prior != newer) {
3847 +#ifdef DEBUG_LCMS
3848 + g_message("Transformed color from 0x%08x to 0x%08x", prior, newer);
3849 + g_message(" ~~~~ FLIP");
3850 +#endif // DEBUG_LCMS
3851 + newColor = other;
3852 + newColor.icc->colors.clear();
3853 + for (guint i = 0; i < iccSelector->_impl->_profChannelCount; i++) {
3854 + gdouble val = ColorScales::getScaled(iccSelector->_impl->_compUI[i]._adj);
3855 + val *= iccSelector->_impl->_compUI[i]._component.scale;
3856 + if (iccSelector->_impl->_compUI[i]._component.scale == 256) {
3857 + val -= 128;
3858 + }
3859 + newColor.icc->colors.push_back(val);
3860 + }
3861 + }
3862 #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
3863 - }
3864 - iccSelector->_updateInternals( newColor, scaled, iccSelector->_impl->_dragging );
3865 - iccSelector->_impl->_updateSliders( match );
3866 + }
3867 + iccSelector->_impl->_color.setColorAlpha(newColor, scaled);
3868 + // iccSelector->_updateInternals( newColor, scaled, iccSelector->_impl->_dragging );
3869 + iccSelector->_impl->_updateSliders(match);
3870
3871 - iccSelector->_impl->_updating = FALSE;
3872 + iccSelector->_impl->_updating = FALSE;
3873 #ifdef DEBUG_LCMS
3874 - g_message( "\\_________ %p::_adjustmentChanged()", cs );
3875 + g_message("\\_________ %p::_adjustmentChanged()", cs);
3876 #endif // DEBUG_LCMS
3877 }
3878
3879 -void ColorICCSelectorImpl::_sliderGrabbed( SPColorSlider * /*slider*/, SPColorICCSelector * /*cs*/ )
3880 +void ColorICCSelectorImpl::_sliderGrabbed()
3881 {
3882 -// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base);
3883 -// if (!iccSelector->_dragging) {
3884 -// iccSelector->_dragging = TRUE;
3885 -// iccSelector->_grabbed();
3886 -// iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_impl->_adj ), iccSelector->_dragging );
3887 -// }
3888 + // ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base);
3889 + // if (!iccSelector->_dragging) {
3890 + // iccSelector->_dragging = TRUE;
3891 + // iccSelector->_grabbed();
3892 + // iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_impl->_adj ),
3893 + // iccSelector->_dragging );
3894 + // }
3895 }
3896
3897 -void ColorICCSelectorImpl::_sliderReleased( SPColorSlider * /*slider*/, SPColorICCSelector * /*cs*/ )
3898 +void ColorICCSelectorImpl::_sliderReleased()
3899 {
3900 -// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base);
3901 -// if (iccSelector->_dragging) {
3902 -// iccSelector->_dragging = FALSE;
3903 -// iccSelector->_released();
3904 -// iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), iccSelector->_dragging );
3905 -// }
3906 + // ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base);
3907 + // if (iccSelector->_dragging) {
3908 + // iccSelector->_dragging = FALSE;
3909 + // iccSelector->_released();
3910 + // iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ),
3911 + // iccSelector->_dragging );
3912 + // }
3913 }
3914
3915 #ifdef DEBUG_LCMS
3916 -void ColorICCSelectorImpl::_sliderChanged( SPColorSlider *slider, SPColorICCSelector *cs )
3917 +void ColorICCSelectorImpl::_sliderChanged(SPColorSlider *slider, SPColorICCSelector *cs)
3918 #else
3919 -void ColorICCSelectorImpl::_sliderChanged( SPColorSlider * /*slider*/, SPColorICCSelector * /*cs*/ )
3920 +void ColorICCSelectorImpl::_sliderChanged()
3921 #endif // DEBUG_LCMS
3922 {
3923 #ifdef DEBUG_LCMS
3924 - g_message("Changed %p and %p", slider, cs );
3925 + g_message("Changed %p and %p", slider, cs);
3926 #endif // DEBUG_LCMS
3927 -// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base);
3928 -
3929 -// iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), iccSelector->_dragging );
3930 -}
3931 -
3932 -
3933 + // ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base);
3934 +
3935 + // iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ),
3936 + // iccSelector->_dragging );
3937 +}
3938 +
3939 +Gtk::Widget *ColorICCSelectorFactory::createWidget(Inkscape::UI::SelectedColor &color) const
3940 +{
3941 + Gtk::Widget *w = Gtk::manage(new ColorICCSelector(color));
3942 + return w;
3943 +}
3944 +
3945 +Glib::ustring ColorICCSelectorFactory::modeName() const { return gettext(ColorICCSelector::MODE_NAME); }
3946 +}
3947 +}
3948 +}
3949 /*
3950 Local Variables:
3951 mode:c++
3952
3953 === renamed file 'src/widgets/sp-color-icc-selector.h' => 'src/ui/widget/color-icc-selector.h'
3954 --- src/widgets/sp-color-icc-selector.h 2014年10月08日 02:22:03 +0000
3955 +++ src/ui/widget/color-icc-selector.h 2015年05月17日 12:22:15 +0000
3956 @@ -1,63 +1,69 @@
3957 #ifndef SEEN_SP_COLOR_ICC_SELECTOR_H
3958 #define SEEN_SP_COLOR_ICC_SELECTOR_H
3959
3960 -#include <glib.h>
3961 -#include "sp-color-selector.h"
3962 +#ifdef HAVE_CONFIG_H
3963 +#include <config.h>
3964 +#endif
3965 +
3966 +#include <gtkmm/widget.h>
3967 +#if WITH_GTKMM_3_0
3968 +#include <gtkmm/grid.h>
3969 +#else
3970 +#include <gtkmm/table.h>
3971 +#endif
3972 +
3973 +#include "ui/selected-color.h"
3974
3975 namespace Inkscape {
3976 +
3977 class ColorProfile;
3978 -}
3979
3980 -struct SPColorICCSelector;
3981 -struct SPColorICCSelectorClass;
3982 +namespace UI {
3983 +namespace Widget {
3984
3985 class ColorICCSelectorImpl;
3986
3987 -class ColorICCSelector: public ColorSelector
3988 -{
3989 -public:
3990 - ColorICCSelector( SPColorSelector* csel );
3991 +class ColorICCSelector
3992 +#if GTK_CHECK_VERSION(3, 0, 0)
3993 + : public Gtk::Grid
3994 +#else
3995 + : public Gtk::Table
3996 +#endif
3997 + {
3998 + public:
3999 + static const gchar *MODE_NAME;
4000 +
4001 + ColorICCSelector(SelectedColor &color);
4002 virtual ~ColorICCSelector();
4003
4004 virtual void init();
4005
4006 -protected:
4007 + protected:
4008 + void on_show();
4009 +
4010 virtual void _colorChanged();
4011
4012 - void _recalcColor( gboolean changing );
4013 + void _recalcColor(gboolean changing);
4014
4015 -private:
4016 + private:
4017 friend class ColorICCSelectorImpl;
4018
4019 // By default, disallow copy constructor and assignment operator
4020 - ColorICCSelector( const ColorICCSelector& obj );
4021 - ColorICCSelector& operator=( const ColorICCSelector& obj );
4022 + ColorICCSelector(const ColorICCSelector &obj);
4023 + ColorICCSelector &operator=(const ColorICCSelector &obj);
4024
4025 ColorICCSelectorImpl *_impl;
4026 };
4027
4028
4029 -
4030 -#define SP_TYPE_COLOR_ICC_SELECTOR (sp_color_icc_selector_get_type())
4031 -#define SP_COLOR_ICC_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_COLOR_ICC_SELECTOR, SPColorICCSelector))
4032 -#define SP_COLOR_ICC_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SP_TYPE_COLOR_ICC_SELECTOR, SPColorICCSelectorClass))
4033 -#define SP_IS_COLOR_ICC_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_COLOR_ICC_SELECTOR))
4034 -#define SP_IS_COLOR_ICC_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SP_TYPE_COLOR_ICC_SELECTOR))
4035 -
4036 -struct SPColorICCSelector {
4037 - SPColorSelector parent;
4038 -};
4039 -
4040 -struct SPColorICCSelectorClass {
4041 - SPColorSelectorClass parent_class;
4042 -};
4043 -
4044 -GType sp_color_icc_selector_get_type(void);
4045 -
4046 -GtkWidget *sp_color_icc_selector_new(void);
4047 -
4048 -
4049 -
4050 +class ColorICCSelectorFactory : public ColorSelectorFactory {
4051 + public:
4052 + Gtk::Widget *createWidget(SelectedColor &color) const;
4053 + Glib::ustring modeName() const;
4054 +};
4055 +}
4056 +}
4057 +}
4058 #endif // SEEN_SP_COLOR_ICC_SELECTOR_H
4059
4060 /*
4061
4062 === renamed file 'src/widgets/sp-color-notebook.cpp' => 'src/ui/widget/color-notebook.cpp'
4063 --- src/widgets/sp-color-notebook.cpp 2014年10月08日 02:22:03 +0000
4064 +++ src/ui/widget/color-notebook.cpp 2015年05月17日 12:22:15 +0000
4065 @@ -1,11 +1,13 @@
4066 -/*
4067 - * A notebook with RGB, CMYK, CMS, HSL, and Wheel pages
4068 - *
4069 - * Author:
4070 +/**
4071 + * @file
4072 + * A notebook with RGB, CMYK, CMS, HSL, and Wheel pages - implementation
4073 + */
4074 +/* Authors:
4075 * Lauris Kaplinski <lauris@kaplinski.com>
4076 * bulia byak <buliabyak@users.sf.net>
4077 + * Tomasz Boczkowski <penginsbacon@gmail.com> (c++-sification)
4078 *
4079 - * Copyright (C) 2001-2002 Lauris Kaplinski
4080 + * Copyright (C) 2001-2014 Authors
4081 *
4082 * This code is in public domain
4083 */
4084 @@ -14,7 +16,7 @@
4085 #define noDUMP_CHANGE_INFO
4086
4087 #ifdef HAVE_CONFIG_H
4088 -# include "config.h"
4089 +#include "config.h"
4090 #endif
4091
4092 #include "widgets/icon.h"
4093 @@ -22,512 +24,233 @@
4094 #include <string>
4095 #include <cstdlib>
4096 #include <cstddef>
4097 -#include <gtk/gtk.h>
4098 #include <glibmm/i18n.h>
4099 +#include <gtkmm/label.h>
4100 +#include <gtkmm/notebook.h>
4101
4102 -#include "ui/dialog-events.h"
4103 -#include "../preferences.h"
4104 -#include "sp-color-notebook.h"
4105 -#include "spw-utilities.h"
4106 -#include "sp-color-scales.h"
4107 -#include "sp-color-icc-selector.h"
4108 -#include "sp-color-wheel-selector.h"
4109 +#include "preferences.h"
4110 +#include "widgets/spw-utilities.h"
4111 #include "svg/svg-icc-color.h"
4112 -#include "../inkscape.h"
4113 -#include "../document.h"
4114 -#include "../profile-manager.h"
4115 +#include "inkscape.h"
4116 +#include "document.h"
4117 +#include "profile-manager.h"
4118 #include "color-profile.h"
4119 #include "cms-system.h"
4120 +#include "ui/dialog-events.h"
4121 #include "ui/tools-switch.h"
4122 #include "ui/tools/tool-base.h"
4123 +#include "ui/widget/color-entry.h"
4124 +#include "ui/widget/color-icc-selector.h"
4125 +#include "ui/widget/color-notebook.h"
4126 +#include "ui/widget/color-scales.h"
4127 +#include "ui/widget/color-wheel-selector.h"
4128
4129 using Inkscape::CMSSystem;
4130
4131 -struct SPColorNotebookTracker {
4132 - const gchar* name;
4133 - const gchar* className;
4134 - GType type;
4135 - guint submode;
4136 - gboolean enabledFull;
4137 - gboolean enabledBrief;
4138 - SPColorNotebook *backPointer;
4139 -};
4140 -
4141 -static void sp_color_notebook_dispose(GObject *object);
4142 -
4143 -static void sp_color_notebook_show_all (GtkWidget *widget);
4144 -static void sp_color_notebook_hide(GtkWidget *widget);
4145 -
4146 #define XPAD 4
4147 #define YPAD 1
4148
4149 -G_DEFINE_TYPE(SPColorNotebook, sp_color_notebook, SP_TYPE_COLOR_SELECTOR);
4150 -
4151 -static void sp_color_notebook_class_init(SPColorNotebookClass *klass)
4152 -{
4153 - GObjectClass *object_class = reinterpret_cast<GObjectClass *>(klass);
4154 - GtkWidgetClass *widget_class = reinterpret_cast<GtkWidgetClass *>(klass);
4155 -
4156 - object_class->dispose = sp_color_notebook_dispose;
4157 -
4158 - widget_class->show_all = sp_color_notebook_show_all;
4159 - widget_class->hide = sp_color_notebook_hide;
4160 -}
4161 -
4162 -static void
4163 -sp_color_notebook_switch_page(GtkNotebook *notebook,
4164 - GtkWidget *page,
4165 - guint page_num,
4166 - SPColorNotebook *colorbook)
4167 -{
4168 - if ( colorbook )
4169 - {
4170 - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base);
4171 - nb->switchPage( notebook, page, page_num );
4172 -
4173 - // remember the page we switched to
4174 - Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4175 - prefs->setInt("/colorselector/page", page_num);
4176 - }
4177 -}
4178 -
4179 -void ColorNotebook::switchPage(GtkNotebook*,
4180 - GtkWidget*,
4181 - guint page_num)
4182 -{
4183 - SPColorSelector* csel;
4184 - GtkWidget* widget;
4185 -
4186 - if ( gtk_notebook_get_current_page (GTK_NOTEBOOK (_book)) >= 0 )
4187 - {
4188 - csel = getCurrentSelector();
4189 - csel->base->getColorAlpha(_color, _alpha);
4190 - }
4191 - widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (_book), page_num);
4192 - if ( widget && SP_IS_COLOR_SELECTOR(widget) )
4193 - {
4194 - csel = SP_COLOR_SELECTOR (widget);
4195 - csel->base->setColorAlpha( _color, _alpha );
4196 -
4197 - // Temporary workaround to undo a spurious GRABBED
4198 - _released();
4199 - }
4200 -}
4201 -
4202 -static gint sp_color_notebook_menu_handler( GtkWidget *widget, GdkEvent *event )
4203 -{
4204 - if (event->type == GDK_BUTTON_PRESS)
4205 - {
4206 - SPColorSelector* csel = SP_COLOR_SELECTOR(widget);
4207 - (dynamic_cast<ColorNotebook*>(csel->base))->menuHandler( event );
4208 -
4209 - /* Tell calling code that we have handled this event; the buck
4210 - * stops here. */
4211 - return TRUE;
4212 - }
4213 -
4214 - /* Tell calling code that we have not handled this event; pass it on. */
4215 - return FALSE;
4216 -}
4217 -
4218 -gint ColorNotebook::menuHandler( GdkEvent* event )
4219 -{
4220 - GdkEventButton *bevent = (GdkEventButton *) event;
4221 - gtk_menu_popup (GTK_MENU( _popup ), NULL, NULL, NULL, NULL,
4222 - bevent->button, bevent->time);
4223 - return TRUE;
4224 -}
4225 -
4226 -static void sp_color_notebook_menuitem_response (GtkMenuItem *menuitem, gpointer user_data)
4227 -{
4228 - gboolean active = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menuitem));
4229 - SPColorNotebookTracker *entry = reinterpret_cast< SPColorNotebookTracker* > (user_data);
4230 - if ( entry )
4231 - {
4232 - if ( active )
4233 - {
4234 - (dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(entry->backPointer)->base))->addPage(entry->type, entry->submode);
4235 - }
4236 - else
4237 - {
4238 - (dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(entry->backPointer)->base))->removePage(entry->type, entry->submode);
4239 - }
4240 - }
4241 -}
4242 -
4243 -static void
4244 -sp_color_notebook_init (SPColorNotebook *colorbook)
4245 -{
4246 - SP_COLOR_SELECTOR(colorbook)->base = new ColorNotebook( SP_COLOR_SELECTOR(colorbook) );
4247 -
4248 - if ( SP_COLOR_SELECTOR(colorbook)->base )
4249 - {
4250 - SP_COLOR_SELECTOR(colorbook)->base->init();
4251 - }
4252 -}
4253 -
4254 -void ColorNotebook::init()
4255 +namespace Inkscape {
4256 +namespace UI {
4257 +namespace Widget {
4258 +
4259 +
4260 +ColorNotebook::ColorNotebook(SelectedColor &color)
4261 +#if GTK_CHECK_VERSION(3, 0, 0)
4262 + : Gtk::Grid()
4263 +#else
4264 + : Gtk::Table(2, 3, false)
4265 +#endif
4266 + , _selected_color(color)
4267 +
4268 +{
4269 + Page *page;
4270 +
4271 + page = new Page(new ColorScalesFactory(SP_COLOR_SCALES_MODE_RGB), true);
4272 + _available_pages.push_back(page);
4273 + page = new Page(new ColorScalesFactory(SP_COLOR_SCALES_MODE_HSV), true);
4274 + _available_pages.push_back(page);
4275 + page = new Page(new ColorScalesFactory(SP_COLOR_SCALES_MODE_CMYK), true);
4276 + _available_pages.push_back(page);
4277 + page = new Page(new ColorWheelSelectorFactory, true);
4278 + _available_pages.push_back(page);
4279 +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4280 + page = new Page(new ColorICCSelectorFactory, true);
4281 + _available_pages.push_back(page);
4282 +#endif
4283 +
4284 + _initUI();
4285 +
4286 + _selected_color.signal_changed.connect(sigc::mem_fun(this, &ColorNotebook::_onSelectedColorChanged));
4287 + _selected_color.signal_dragged.connect(sigc::mem_fun(this, &ColorNotebook::_onSelectedColorChanged));
4288 +}
4289 +
4290 +ColorNotebook::~ColorNotebook()
4291 +{
4292 + if (_buttons) {
4293 + delete[] _buttons;
4294 + _buttons = 0;
4295 + }
4296 +}
4297 +
4298 +ColorNotebook::Page::Page(Inkscape::UI::ColorSelectorFactory *selector_factory, bool enabled_full)
4299 + : selector_factory(selector_factory)
4300 + , enabled_full(enabled_full)
4301 +{
4302 +}
4303 +
4304 +
4305 +void ColorNotebook::_initUI()
4306 {
4307 guint row = 0;
4308 - guint i = 0;
4309 - guint j = 0;
4310 - GType *selector_types = 0;
4311 - guint selector_type_count = 0;
4312 -
4313 - /* tempory hardcoding to get types loaded */
4314 - SP_TYPE_COLOR_SCALES;
4315 - SP_TYPE_COLOR_WHEEL_SELECTOR;
4316 -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4317 - SP_TYPE_COLOR_ICC_SELECTOR;
4318 -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4319 -
4320 - /* REJON: Comment out the next line to not use the normal GTK Color
4321 - wheel. */
4322 -
4323 -// SP_TYPE_COLOR_GTKSELECTOR;
4324 -
4325 - _updating = FALSE;
4326 - _updatingrgba = FALSE;
4327 - _btn = 0;
4328 - _popup = 0;
4329 - _trackerList = g_ptr_array_new ();
4330 -
4331 - _book = gtk_notebook_new ();
4332 - gtk_widget_show (_book);
4333 -
4334 - // Dont show the notebook tabs, use radiobuttons instead
4335 - gtk_notebook_set_show_border (GTK_NOTEBOOK (_book), false);
4336 - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (_book), false);
4337 -
4338 - selector_types = g_type_children (SP_TYPE_COLOR_SELECTOR, &selector_type_count);
4339 -
4340 - for ( i = 0; i < selector_type_count; i++ )
4341 - {
4342 - if (!g_type_is_a (selector_types[i], SP_TYPE_COLOR_NOTEBOOK))
4343 - {
4344 - guint howmany = 1;
4345 - gpointer klass = g_type_class_ref (selector_types[i]);
4346 - if ( klass && SP_IS_COLOR_SELECTOR_CLASS(klass) )
4347 - {
4348 - SPColorSelectorClass *ck = SP_COLOR_SELECTOR_CLASS (klass);
4349 - howmany = MAX (1, ck->submode_count);
4350 - for ( j = 0; j < howmany; j++ )
4351 - {
4352 - SPColorNotebookTracker *entry = reinterpret_cast< SPColorNotebookTracker* > (malloc(sizeof(SPColorNotebookTracker)));
4353 - if ( entry )
4354 - {
4355 - memset( entry, 0, sizeof(SPColorNotebookTracker) );
4356 - entry->name = ck->name[j];
4357 - entry->type = selector_types[i];
4358 - entry->submode = j;
4359 - entry->enabledFull = TRUE;
4360 - entry->enabledBrief = TRUE;
4361 - entry->backPointer = SP_COLOR_NOTEBOOK(_csel);
4362 -
4363 - g_ptr_array_add (_trackerList, entry);
4364 - }
4365 - }
4366 - }
4367 - }
4368 - }
4369 -
4370 -#if GTK_CHECK_VERSION(3,0,0)
4371 +
4372 + Gtk::Notebook *notebook = Gtk::manage(new Gtk::Notebook);
4373 + notebook->show();
4374 + notebook->set_show_border(false);
4375 + notebook->set_show_tabs(false);
4376 + _book = GTK_WIDGET(notebook->gobj());
4377 +
4378 +#if GTK_CHECK_VERSION(3, 0, 0)
4379 _buttonbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
4380 gtk_box_set_homogeneous(GTK_BOX(_buttonbox), TRUE);
4381 #else
4382 - _buttonbox = gtk_hbox_new (TRUE, 2);
4383 + _buttonbox = gtk_hbox_new(TRUE, 2);
4384 #endif
4385
4386 - gtk_widget_show (_buttonbox);
4387 - _buttons = new GtkWidget *[_trackerList->len];
4388 + gtk_widget_show(_buttonbox);
4389 + _buttons = new GtkWidget *[_available_pages.size()];
4390
4391 - for ( i = 0; i < _trackerList->len; i++ )
4392 - {
4393 - SPColorNotebookTracker *entry =
4394 - reinterpret_cast< SPColorNotebookTracker* > (g_ptr_array_index (_trackerList, i));
4395 - if ( entry )
4396 - {
4397 - addPage(entry->type, entry->submode);
4398 - }
4399 + for (int i = 0; static_cast<size_t>(i) < _available_pages.size(); i++) {
4400 + _addPage(_available_pages[i]);
4401 }
4402
4403 -#if GTK_CHECK_VERSION(3,0,0)
4404 - GtkWidget* table = gtk_grid_new();
4405 -#else
4406 - GtkWidget* table = gtk_table_new(2, 3, FALSE);
4407 -#endif
4408 -
4409 - gtk_widget_show (table);
4410 -
4411 - gtk_box_pack_start (GTK_BOX (_csel), table, TRUE, TRUE, 0);
4412 -
4413 - sp_set_font_size_smaller (_buttonbox);
4414 -
4415 -#if GTK_CHECK_VERSION(3,0,0)
4416 - #if GTK_CHECK_VERSION(3,12,0)
4417 + sp_set_font_size_smaller(_buttonbox);
4418 +
4419 +#if GTK_CHECK_VERSION(3, 0, 0)
4420 + #if GTK_CHECK_VERSION(3, 12, 0)
4421 gtk_widget_set_margin_start(_buttonbox, XPAD);
4422 gtk_widget_set_margin_end(_buttonbox, XPAD);
4423 - #else
4424 + #else
4425 gtk_widget_set_margin_left(_buttonbox, XPAD);
4426 gtk_widget_set_margin_right(_buttonbox, XPAD);
4427 - #endif
4428 + #endif
4429 gtk_widget_set_margin_top(_buttonbox, YPAD);
4430 gtk_widget_set_margin_bottom(_buttonbox, YPAD);
4431 gtk_widget_set_hexpand(_buttonbox, TRUE);
4432 gtk_widget_set_valign(_buttonbox, GTK_ALIGN_CENTER);
4433 - gtk_grid_attach(GTK_GRID(table), _buttonbox, 0, row, 2, 1);
4434 + attach(*Glib::wrap(_buttonbox), 0, row, 2, 1);
4435 #else
4436 - gtk_table_attach (GTK_TABLE (table), _buttonbox, 0, 2, row, row + 1,
4437 - static_cast<GtkAttachOptions>(GTK_EXPAND|GTK_FILL),
4438 - static_cast<GtkAttachOptions>(0),
4439 - XPAD, YPAD);
4440 + attach(*Glib::wrap(_buttonbox), 0, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, static_cast<Gtk::AttachOptions>(0),
4441 + XPAD, YPAD);
4442 #endif
4443
4444 row++;
4445
4446 -#if GTK_CHECK_VERSION(3,0,0)
4447 - #if GTK_CHECK_VERSION(3,12,0)
4448 - gtk_widget_set_margin_start(_book, XPAD*2);
4449 - gtk_widget_set_margin_end(_book, XPAD*2);
4450 - #else
4451 - gtk_widget_set_margin_left(_book, XPAD*2);
4452 - gtk_widget_set_margin_right(_book, XPAD*2);
4453 - #endif
4454 +#if GTK_CHECK_VERSION(3, 0, 0)
4455 +#if GTK_CHECK_VERSION(3, 12, 0)
4456 + gtk_widget_set_margin_start(_book, XPAD * 2);
4457 + gtk_widget_set_margin_end(_book, XPAD * 2);
4458 +#else
4459 + gtk_widget_set_margin_left(_book, XPAD * 2);
4460 + gtk_widget_set_margin_right(_book, XPAD * 2);
4461 +#endif
4462 gtk_widget_set_margin_top(_book, YPAD);
4463 gtk_widget_set_margin_bottom(_book, YPAD);
4464 gtk_widget_set_hexpand(_book, TRUE);
4465 gtk_widget_set_vexpand(_book, TRUE);
4466 - gtk_grid_attach(GTK_GRID(table), _book, 0, row, 2, 1);
4467 + attach(*notebook, 0, row, 2, 1);
4468 #else
4469 - gtk_table_attach (GTK_TABLE (table), _book, 0, 2, row, row + 1,
4470 - static_cast<GtkAttachOptions>(GTK_EXPAND|GTK_FILL),
4471 - static_cast<GtkAttachOptions>(GTK_EXPAND|GTK_FILL),
4472 - XPAD*2, YPAD);
4473 + attach(*notebook, 0, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, XPAD * 2, YPAD);
4474 #endif
4475
4476 // restore the last active page
4477 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4478 _setCurrentPage(prefs->getInt("/colorselector/page", 0));
4479 -
4480 - {
4481 - gboolean found = FALSE;
4482 -
4483 - _popup = gtk_menu_new();
4484 - GtkMenu *menu = GTK_MENU (_popup);
4485 -
4486 - for ( i = 0; i < _trackerList->len; i++ )
4487 - {
4488 - SPColorNotebookTracker *entry = reinterpret_cast< SPColorNotebookTracker* > (g_ptr_array_index (_trackerList, i));
4489 - if ( entry )
4490 - {
4491 - GtkWidget *item = gtk_check_menu_item_new_with_label (_(entry->name));
4492 - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), entry->enabledFull);
4493 - gtk_widget_show (item);
4494 - gtk_menu_shell_append (GTK_MENU_SHELL(menu), item);
4495 -
4496 - g_signal_connect (G_OBJECT (item), "activate",
4497 - G_CALLBACK (sp_color_notebook_menuitem_response),
4498 - reinterpret_cast< gpointer > (entry) );
4499 - found = TRUE;
4500 - }
4501 - }
4502 -
4503 - GtkWidget *arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
4504 - gtk_widget_show (arrow);
4505 -
4506 - _btn = gtk_button_new ();
4507 - gtk_widget_show (_btn);
4508 - gtk_container_add (GTK_CONTAINER (_btn), arrow);
4509 -
4510 - GtkWidget *align = gtk_alignment_new (1.0, 0.0, 0.0, 0.0);
4511 - gtk_widget_show (align);
4512 - gtk_container_add (GTK_CONTAINER (align), _btn);
4513 -
4514 - // uncomment to reenable the "show/hide modes" menu,
4515 - // but first fix it so it remembers its settings in prefs and does not take that much space (entire vertical column!)
4516 - //gtk_table_attach (GTK_TABLE (table), align, 2, 3, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD);
4517 -
4518 - g_signal_connect_swapped(G_OBJECT(_btn), "event", G_CALLBACK (sp_color_notebook_menu_handler), G_OBJECT(_csel));
4519 - if ( !found )
4520 - {
4521 - gtk_widget_set_sensitive (_btn, FALSE);
4522 - }
4523 - }
4524 -
4525 row++;
4526
4527 -#if GTK_CHECK_VERSION(3,0,0)
4528 +#if GTK_CHECK_VERSION(3, 0, 0)
4529 GtkWidget *rgbabox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
4530 #else
4531 - GtkWidget *rgbabox = gtk_hbox_new (FALSE, 0);
4532 + GtkWidget *rgbabox = gtk_hbox_new(FALSE, 0);
4533 #endif
4534
4535 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4536 /* Create color management icons */
4537 - _box_colormanaged = gtk_event_box_new ();
4538 - GtkWidget *colormanaged = gtk_image_new_from_icon_name ("color-management-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
4539 - gtk_container_add (GTK_CONTAINER (_box_colormanaged), colormanaged);
4540 - gtk_widget_set_tooltip_text (_box_colormanaged, _("Color Managed"));
4541 - gtk_widget_set_sensitive (_box_colormanaged, false);
4542 + _box_colormanaged = gtk_event_box_new();
4543 + GtkWidget *colormanaged = gtk_image_new_from_icon_name("color-management-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
4544 + gtk_container_add(GTK_CONTAINER(_box_colormanaged), colormanaged);
4545 + gtk_widget_set_tooltip_text(_box_colormanaged, _("Color Managed"));
4546 + gtk_widget_set_sensitive(_box_colormanaged, false);
4547 gtk_box_pack_start(GTK_BOX(rgbabox), _box_colormanaged, FALSE, FALSE, 2);
4548
4549 - _box_outofgamut = gtk_event_box_new ();
4550 - GtkWidget *outofgamut = gtk_image_new_from_icon_name ("out-of-gamut-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
4551 - gtk_container_add (GTK_CONTAINER (_box_outofgamut), outofgamut);
4552 - gtk_widget_set_tooltip_text (_box_outofgamut, _("Out of gamut!"));
4553 - gtk_widget_set_sensitive (_box_outofgamut, false);
4554 + _box_outofgamut = gtk_event_box_new();
4555 + GtkWidget *outofgamut = gtk_image_new_from_icon_name("out-of-gamut-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
4556 + gtk_container_add(GTK_CONTAINER(_box_outofgamut), outofgamut);
4557 + gtk_widget_set_tooltip_text(_box_outofgamut, _("Out of gamut!"));
4558 + gtk_widget_set_sensitive(_box_outofgamut, false);
4559 gtk_box_pack_start(GTK_BOX(rgbabox), _box_outofgamut, FALSE, FALSE, 2);
4560
4561 - _box_toomuchink = gtk_event_box_new ();
4562 - GtkWidget *toomuchink = gtk_image_new_from_icon_name ("too-much-ink-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
4563 - gtk_container_add (GTK_CONTAINER (_box_toomuchink), toomuchink);
4564 - gtk_widget_set_tooltip_text (_box_toomuchink, _("Too much ink!"));
4565 - gtk_widget_set_sensitive (_box_toomuchink, false);
4566 + _box_toomuchink = gtk_event_box_new();
4567 + GtkWidget *toomuchink = gtk_image_new_from_icon_name("too-much-ink-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
4568 + gtk_container_add(GTK_CONTAINER(_box_toomuchink), toomuchink);
4569 + gtk_widget_set_tooltip_text(_box_toomuchink, _("Too much ink!"));
4570 + gtk_widget_set_sensitive(_box_toomuchink, false);
4571 gtk_box_pack_start(GTK_BOX(rgbabox), _box_toomuchink, FALSE, FALSE, 2);
4572 -#endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4573 +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4574
4575
4576 /* Color picker */
4577 - GtkWidget *picker = gtk_image_new_from_icon_name ("color-picker", GTK_ICON_SIZE_SMALL_TOOLBAR);
4578 - _btn_picker = gtk_button_new ();
4579 + GtkWidget *picker = gtk_image_new_from_icon_name("color-picker", GTK_ICON_SIZE_SMALL_TOOLBAR);
4580 + _btn_picker = gtk_button_new();
4581 gtk_button_set_relief(GTK_BUTTON(_btn_picker), GTK_RELIEF_NONE);
4582 - gtk_widget_show (_btn);
4583 - gtk_container_add (GTK_CONTAINER (_btn_picker), picker);
4584 - gtk_widget_set_tooltip_text (_btn_picker, _("Pick colors from image"));
4585 + gtk_container_add(GTK_CONTAINER(_btn_picker), picker);
4586 + gtk_widget_set_tooltip_text(_btn_picker, _("Pick colors from image"));
4587 gtk_box_pack_start(GTK_BOX(rgbabox), _btn_picker, FALSE, FALSE, 2);
4588 - g_signal_connect(G_OBJECT(_btn_picker), "clicked", G_CALLBACK(ColorNotebook::_picker_clicked), _csel);
4589 + g_signal_connect(G_OBJECT(_btn_picker), "clicked", G_CALLBACK(ColorNotebook::_onPickerClicked), this);
4590
4591 /* Create RGBA entry and color preview */
4592 - _rgbal = gtk_label_new_with_mnemonic (_("RGBA_:"));
4593 - gtk_misc_set_alignment (GTK_MISC (_rgbal), 1.0, 0.5);
4594 + _rgbal = gtk_label_new_with_mnemonic(_("RGBA_:"));
4595 + gtk_misc_set_alignment(GTK_MISC(_rgbal), 1.0, 0.5);
4596 gtk_box_pack_start(GTK_BOX(rgbabox), _rgbal, TRUE, TRUE, 2);
4597
4598 - _rgbae = gtk_entry_new ();
4599 - sp_dialog_defocus_on_enter (_rgbae);
4600 - gtk_entry_set_max_length (GTK_ENTRY (_rgbae), 8);
4601 - gtk_entry_set_width_chars (GTK_ENTRY (_rgbae), 8);
4602 - gtk_widget_set_tooltip_text (_rgbae, _("Hexadecimal RGBA value of the color"));
4603 - gtk_box_pack_start(GTK_BOX(rgbabox), _rgbae, FALSE, FALSE, 0);
4604 - gtk_label_set_mnemonic_widget (GTK_LABEL(_rgbal), _rgbae);
4605 + ColorEntry *rgba_entry = Gtk::manage(new ColorEntry(_selected_color));
4606 + sp_dialog_defocus_on_enter(GTK_WIDGET(rgba_entry->gobj()));
4607 + gtk_box_pack_start(GTK_BOX(rgbabox), GTK_WIDGET(rgba_entry->gobj()), FALSE, FALSE, 0);
4608 + gtk_label_set_mnemonic_widget(GTK_LABEL(_rgbal), GTK_WIDGET(rgba_entry->gobj()));
4609
4610 - sp_set_font_size_smaller (rgbabox);
4611 - gtk_widget_show_all (rgbabox);
4612 + sp_set_font_size_smaller(rgbabox);
4613 + gtk_widget_show_all(rgbabox);
4614
4615 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4616 - //the "too much ink" icon is initially hidden
4617 + // the "too much ink" icon is initially hidden
4618 gtk_widget_hide(GTK_WIDGET(_box_toomuchink));
4619 -#endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4620 +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4621
4622 -#if GTK_CHECK_VERSION(3,0,0)
4623 - #if GTK_CHECK_VERSION(3,12,0)
4624 +#if GTK_CHECK_VERSION(3, 0, 0)
4625 + #if GTK_CHECK_VERSION(3, 12, 0)
4626 gtk_widget_set_margin_start(rgbabox, XPAD);
4627 gtk_widget_set_margin_end(rgbabox, XPAD);
4628 - #else
4629 + #else
4630 gtk_widget_set_margin_left(rgbabox, XPAD);
4631 gtk_widget_set_margin_right(rgbabox, XPAD);
4632 - #endif
4633 + #endif
4634 gtk_widget_set_margin_top(rgbabox, YPAD);
4635 gtk_widget_set_margin_bottom(rgbabox, YPAD);
4636 - gtk_grid_attach(GTK_GRID(table), rgbabox, 0, row, 2, 1);
4637 + attach(*Glib::wrap(rgbabox), 0, row, 2, 1);
4638 #else
4639 - gtk_table_attach (GTK_TABLE (table), rgbabox, 0, 2, row, row + 1, GTK_FILL, GTK_SHRINK, XPAD, YPAD);
4640 + attach(*Glib::wrap(rgbabox), 0, 2, row, row + 1, Gtk::FILL, Gtk::SHRINK, XPAD, YPAD);
4641 #endif
4642
4643 #ifdef SPCS_PREVIEW
4644 - _p = sp_color_preview_new (0xffffffff);
4645 - gtk_widget_show (_p);
4646 - gtk_table_attach (GTK_TABLE (table), _p, 2, 3, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD);
4647 + _p = sp_color_preview_new(0xffffffff);
4648 + gtk_widget_show(_p);
4649 + attach(*Glib::wrap(_p), 2, 3, row, row + 1, Gtk::FILL, Gtk::FILL, XPAD, YPAD);
4650 #endif
4651
4652 - _switchId = g_signal_connect(G_OBJECT (_book), "switch-page",
4653 - G_CALLBACK (sp_color_notebook_switch_page), SP_COLOR_NOTEBOOK(_csel));
4654 -
4655 - _entryId = g_signal_connect (G_OBJECT (_rgbae), "changed", G_CALLBACK (ColorNotebook::_rgbaEntryChangedHook), _csel);
4656 -}
4657 -
4658 -static void sp_color_notebook_dispose(GObject *object)
4659 -{
4660 - if (G_OBJECT_CLASS(sp_color_notebook_parent_class)->dispose)
4661 - G_OBJECT_CLASS(sp_color_notebook_parent_class)->dispose(object);
4662 -}
4663 -
4664 -ColorNotebook::~ColorNotebook()
4665 -{
4666 - if ( _trackerList )
4667 - {
4668 - g_ptr_array_free (_trackerList, TRUE);
4669 - _trackerList = 0;
4670 - }
4671 -
4672 - if ( _switchId )
4673 - {
4674 - if ( _book )
4675 - {
4676 - g_signal_handler_disconnect (_book, _switchId);
4677 - _switchId = 0;
4678 - }
4679 - }
4680 -
4681 - if ( _buttons )
4682 - {
4683 - delete [] _buttons;
4684 - _buttons = 0;
4685 - }
4686 -
4687 -}
4688 -
4689 -static void
4690 -sp_color_notebook_show_all (GtkWidget *widget)
4691 -{
4692 - gtk_widget_show (widget);
4693 -}
4694 -
4695 -static void sp_color_notebook_hide(GtkWidget *widget)
4696 -{
4697 - gtk_widget_hide(widget);
4698 -}
4699 -
4700 -GtkWidget *sp_color_notebook_new()
4701 -{
4702 - SPColorNotebook *colorbook = SP_COLOR_NOTEBOOK(g_object_new (SP_TYPE_COLOR_NOTEBOOK, NULL));
4703 -
4704 - return GTK_WIDGET(colorbook);
4705 -}
4706 -
4707 -ColorNotebook::ColorNotebook( SPColorSelector* csel )
4708 - : ColorSelector( csel )
4709 -{
4710 -}
4711 -
4712 -SPColorSelector* ColorNotebook::getCurrentSelector()
4713 -{
4714 - SPColorSelector* csel = NULL;
4715 - gint current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (_book));
4716 -
4717 - if ( current_page >= 0 )
4718 - {
4719 - GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (_book), current_page);
4720 - if ( SP_IS_COLOR_SELECTOR (widget) )
4721 - {
4722 - csel = SP_COLOR_SELECTOR (widget);
4723 - }
4724 - }
4725 -
4726 - return csel;
4727 -}
4728 -
4729 -void ColorNotebook::_colorChanged()
4730 -{
4731 - SPColorSelector* cselPage = getCurrentSelector();
4732 - if ( cselPage )
4733 - {
4734 - cselPage->base->setColorAlpha( _color, _alpha );
4735 - }
4736 -
4737 - _updateRgbaEntry( _color, _alpha );
4738 -}
4739 -
4740 -void ColorNotebook::_picker_clicked(GtkWidget * /*widget*/, SPColorNotebook * /*colorbook*/)
4741 + g_signal_connect(G_OBJECT(_book), "switch-page", G_CALLBACK(ColorNotebook::_onPageSwitched), this);
4742 +}
4743 +
4744 +void ColorNotebook::_onPickerClicked(GtkWidget * /*widget*/, ColorNotebook * /*colorbook*/)
4745 {
4746 // Set the dropper into a "one click" mode, so it reverts to the previous tool after a click
4747 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4748 @@ -535,283 +258,113 @@
4749 Inkscape::UI::Tools::sp_toggle_dropper(SP_ACTIVE_DESKTOP);
4750 }
4751
4752 -void ColorNotebook::_rgbaEntryChangedHook(GtkEntry *entry, SPColorNotebook *colorbook)
4753 -{
4754 - (dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base))->_rgbaEntryChanged( entry );
4755 -}
4756 -
4757 -void ColorNotebook::_rgbaEntryChanged(GtkEntry* entry)
4758 -{
4759 - if (_updating) return;
4760 - if (_updatingrgba) return;
4761 -
4762 - const gchar *t = gtk_entry_get_text( entry );
4763 -
4764 - if (t) {
4765 - Glib::ustring text = t;
4766 - bool changed = false;
4767 - if (!text.empty() && text[0] == '#') {
4768 - changed = true;
4769 - text.erase(0,1);
4770 - if (text.size() == 6) {
4771 - // it was a standard RGB hex
4772 - unsigned int alph = SP_COLOR_F_TO_U(_alpha);
4773 - gchar* tmp = g_strdup_printf("%02x", alph);
4774 - text += tmp;
4775 - g_free(tmp);
4776 - }
4777 - }
4778 - gchar* str = g_strdup(text.c_str());
4779 - gchar* end = 0;
4780 - guint64 rgba = g_ascii_strtoull( str, &end, 16 );
4781 - if ( end != str ) {
4782 - ptrdiff_t len = end - str;
4783 - if ( len < 8 ) {
4784 - rgba = rgba << ( 4 * ( 8 - len ) );
4785 - }
4786 - _updatingrgba = TRUE;
4787 - if ( changed ) {
4788 - gtk_entry_set_text( entry, str );
4789 - }
4790 - SPColor color( rgba );
4791 - setColorAlpha( color, SP_RGBA32_A_F(rgba), true );
4792 - _updatingrgba = FALSE;
4793 - }
4794 - g_free(str);
4795 - }
4796 -}
4797 +void ColorNotebook::_onButtonClicked(GtkWidget *widget, ColorNotebook *nb)
4798 +{
4799 + if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
4800 + return;
4801 + }
4802 +
4803 + for (gint i = 0; i < gtk_notebook_get_n_pages(GTK_NOTEBOOK(nb->_book)); i++) {
4804 + if (nb->_buttons[i] == widget) {
4805 + gtk_notebook_set_current_page(GTK_NOTEBOOK(nb->_book), i);
4806 + }
4807 + }
4808 +}
4809 +
4810 +void ColorNotebook::_onSelectedColorChanged() { _updateICCButtons(); }
4811 +
4812 +void ColorNotebook::_onPageSwitched(GtkNotebook *notebook, GtkWidget *page, guint page_num, ColorNotebook *colorbook)
4813 +{
4814 + if (colorbook->get_visible()) {
4815 + // remember the page we switched to
4816 + Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4817 + prefs->setInt("/colorselector/page", page_num);
4818 + }
4819 +}
4820 +
4821
4822 // TODO pass in param so as to avoid the need for SP_ACTIVE_DOCUMENT
4823 -void ColorNotebook::_updateRgbaEntry( const SPColor& color, gfloat alpha )
4824 +void ColorNotebook::_updateICCButtons()
4825 {
4826 - g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) );
4827 + SPColor color = _selected_color.color();
4828 + gfloat alpha = _selected_color.alpha();
4829 +
4830 + g_return_if_fail((0.0 <= alpha) && (alpha <= 1.0));
4831
4832 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4833 /* update color management icon*/
4834 - gtk_widget_set_sensitive (_box_colormanaged, color.icc != NULL);
4835 + gtk_widget_set_sensitive(_box_colormanaged, color.icc != NULL);
4836
4837 /* update out-of-gamut icon */
4838 - gtk_widget_set_sensitive (_box_outofgamut, false);
4839 - if (color.icc){
4840 - Inkscape::ColorProfile* target_profile = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str());
4841 - if ( target_profile )
4842 + gtk_widget_set_sensitive(_box_outofgamut, false);
4843 + if (color.icc) {
4844 + Inkscape::ColorProfile *target_profile =
4845 + SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str());
4846 + if (target_profile)
4847 gtk_widget_set_sensitive(_box_outofgamut, target_profile->GamutCheck(color));
4848 }
4849
4850 /* update too-much-ink icon */
4851 - gtk_widget_set_sensitive (_box_toomuchink, false);
4852 - if (color.icc){
4853 - Inkscape::ColorProfile* prof = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str());
4854 - if ( prof && CMSSystem::isPrintColorSpace(prof) ) {
4855 + gtk_widget_set_sensitive(_box_toomuchink, false);
4856 + if (color.icc) {
4857 + Inkscape::ColorProfile *prof = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str());
4858 + if (prof && CMSSystem::isPrintColorSpace(prof)) {
4859 gtk_widget_show(GTK_WIDGET(_box_toomuchink));
4860 double ink_sum = 0;
4861 - for (unsigned int i=0; i<color.icc->colors.size(); i++){
4862 + for (unsigned int i = 0; i < color.icc->colors.size(); i++) {
4863 ink_sum += color.icc->colors[i];
4864 }
4865
4866 - /* Some literature states that when the sum of paint values exceed 320%, it is considered to be a satured color,
4867 - which means the paper can get too wet due to an excessive ammount of ink. This may lead to several issues
4868 + /* Some literature states that when the sum of paint values exceed 320%, it is considered to be a satured
4869 + color,
4870 + which means the paper can get too wet due to an excessive ammount of ink. This may lead to several
4871 + issues
4872 such as misalignment and poor quality of printing in general.*/
4873 - if ( ink_sum > 3.2 )
4874 - gtk_widget_set_sensitive (_box_toomuchink, true);
4875 - } else {
4876 + if (ink_sum > 3.2)
4877 + gtk_widget_set_sensitive(_box_toomuchink, true);
4878 + }
4879 + else {
4880 gtk_widget_hide(GTK_WIDGET(_box_toomuchink));
4881 }
4882 }
4883 -#endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4884 -
4885 - if ( !_updatingrgba )
4886 - {
4887 - gchar s[32];
4888 - guint32 rgba;
4889 -
4890 - /* Update RGBA entry */
4891 - rgba = color.toRGBA32( alpha );
4892 -
4893 - g_snprintf (s, 32, "%08x", rgba);
4894 - const gchar* oldText = gtk_entry_get_text( GTK_ENTRY( _rgbae ) );
4895 - if ( strcmp( oldText, s ) != 0 )
4896 - {
4897 - g_signal_handler_block( _rgbae, _entryId );
4898 - gtk_entry_set_text( GTK_ENTRY(_rgbae), s );
4899 - g_signal_handler_unblock( _rgbae, _entryId );
4900 - }
4901 - }
4902 +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
4903 }
4904
4905 void ColorNotebook::_setCurrentPage(int i)
4906 {
4907 gtk_notebook_set_current_page(GTK_NOTEBOOK(_book), i);
4908
4909 - if (_buttons && _trackerList && (static_cast<size_t>(i) < _trackerList->len) ) {
4910 + if (_buttons && (static_cast<size_t>(i) < _available_pages.size())) {
4911 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(_buttons[i]), TRUE);
4912 }
4913 }
4914
4915 -void ColorNotebook::_buttonClicked(GtkWidget *widget, SPColorNotebook *colorbook)
4916 -{
4917 - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base);
4918 -
4919 - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget))) {
4920 - return;
4921 - }
4922 -
4923 - for(gint i = 0; i < gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb->_book)); i++) {
4924 - if (nb->_buttons[i] == widget) {
4925 - gtk_notebook_set_current_page (GTK_NOTEBOOK (nb->_book), i);
4926 - }
4927 - }
4928 -}
4929 -
4930 -void ColorNotebook::_entryGrabbed (SPColorSelector *, SPColorNotebook *colorbook)
4931 -{
4932 - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base);
4933 - nb->_grabbed();
4934 -}
4935 -
4936 -void ColorNotebook::_entryDragged (SPColorSelector *csel, SPColorNotebook *colorbook)
4937 -{
4938 - gboolean oldState;
4939 - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base);
4940 -
4941 - oldState = nb->_dragging;
4942 -
4943 - nb->_dragging = TRUE;
4944 - nb->_entryModified( csel, colorbook );
4945 -
4946 - nb->_dragging = oldState;
4947 -}
4948 -
4949 -void ColorNotebook::_entryReleased (SPColorSelector *, SPColorNotebook *colorbook)
4950 -{
4951 - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base);
4952 - nb->_released();
4953 -}
4954 -
4955 -void ColorNotebook::_entryChanged (SPColorSelector *csel, SPColorNotebook *colorbook)
4956 -{
4957 - gboolean oldState;
4958 - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base);
4959 -
4960 - oldState = nb->_dragging;
4961 -
4962 - nb->_dragging = FALSE;
4963 - nb->_entryModified( csel, colorbook );
4964 -
4965 - nb->_dragging = oldState;
4966 -}
4967 -
4968 -void ColorNotebook::_entryModified (SPColorSelector *csel, SPColorNotebook *colorbook)
4969 -{
4970 - g_return_if_fail (colorbook != NULL);
4971 - g_return_if_fail (SP_IS_COLOR_NOTEBOOK (colorbook));
4972 - g_return_if_fail (csel != NULL);
4973 - g_return_if_fail (SP_IS_COLOR_SELECTOR (csel));
4974 -
4975 - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base);
4976 - SPColor color;
4977 - gfloat alpha = 1.0;
4978 -
4979 - csel->base->getColorAlpha( color, alpha );
4980 - nb->_updateRgbaEntry( color, alpha );
4981 - nb->_updateInternals( color, alpha, nb->_dragging );
4982 -}
4983 -
4984 -GtkWidget* ColorNotebook::addPage(GType page_type, guint submode)
4985 -{
4986 - GtkWidget *page;
4987 -
4988 - page = sp_color_selector_new( page_type );
4989 - if ( page )
4990 - {
4991 - GtkWidget* tab_label = 0;
4992 - SPColorSelector* csel;
4993 -
4994 - csel = SP_COLOR_SELECTOR (page);
4995 - if ( submode > 0 )
4996 - {
4997 - csel->base->setSubmode( submode );
4998 - }
4999 - gtk_widget_show (page);
5000 - int index = csel->base ? csel->base->getSubmode() : 0;