paint-selector.cpp revision 32dbfdf82f6abb93aeed3f0d1cf66a2cf62164aa
/** \file
* SPPaintSelector: Generic paint selector widget.
*/
/*
* Authors:
* Lauris Kaplinski
* bulia byak <buliabyak@users.sf.net>
* John Cliff <simarilius@yahoo.com>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) Lauris Kaplinski 2002
* Copyright (C) 2010 Authors
*/
#define noSP_PS_VERBOSE
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <cstring>
#include <string>
#include "../sp-pattern.h"
#include "widgets/widget-sizes.h"
#include "sp-color-notebook.h"
#include "sp-linear-gradient-fns.h"
#include "sp-radial-gradient-fns.h"
/* fixme: Move it from dialogs to here */
#include "gradient-selector.h"
#include <inkscape.h>
#include <document-private.h>
#include <desktop-style.h>
#include <style.h>
#include "svg/svg-color.h"
#include "svg/css-ostringstream.h"
#include "path-prefix.h"
#include "helper/stock-items.h"
#include "ui/icon-names.h"
#include "widgets/swatch-selector.h"
#include "paint-selector.h"
#ifdef SP_PS_VERBOSE
#include "svg/svg-icc-color.h"
#endif // SP_PS_VERBOSE
enum {
};
static GtkWidget *sp_paint_selector_style_button_add(SPPaintSelector *psel, gchar const *px, SPPaintSelector::Mode mode, gchar const *tip);
static GtkVBoxClass *parent_class;
#ifdef SP_PS_VERBOSE
static gchar const* modeStrings[] = {
"MODE_EMPTY",
"MODE_MULTIPLE",
"MODE_NONE",
"MODE_COLOR_RGB",
"MODE_COLOR_CMYK",
"MODE_GRADIENT_LINEAR",
"MODE_GRADIENT_RADIAL",
"MODE_PATTERN",
"MODE_SWATCH",
"MODE_UNSET",
".",
".",
".",
};
#endif
{
return isGrad;
}
{
SPGradientSelector *grad = 0;
SwatchSelector *swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(psel->selector), "swatch-selector"));
if (swatchsel) {
}
} else {
grad = reinterpret_cast<SPGradientSelector*>(gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"));
}
return grad;
}
{
if (!type) {
sizeof(SPPaintSelectorClass),
0, // base_init
0, // base_finalize
0, // class_finalize
0, // class_data
sizeof(SPPaintSelector),
0, // n_preallocs
0 // value_table
};
}
return type;
}
static void
{
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
}
#define XPAD 4
#define YPAD 1
static void
{
psel->mode = static_cast<SPPaintSelector::Mode>(-1); // huh? do you mean 0xff? -- I think this means "not in the enum"
/* Paint style button box */
/* Buttons */
/* Fillrule */
{
GtkWidget *w;
// TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/painting.html#FillRuleProperty
gtk_widget_set_tooltip_text(psel->evenodd, _("Any path self-intersections or subpaths create holes in the fill (fill-rule: evenodd)"));
gtk_object_set_data(GTK_OBJECT(psel->evenodd), "mode", GUINT_TO_POINTER(SPPaintSelector::FILLRULE_EVENODD));
g_signal_connect(G_OBJECT(psel->evenodd), "toggled", G_CALLBACK(sp_paint_selector_fillrule_toggled), psel);
// TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/painting.html#FillRuleProperty
gtk_widget_set_tooltip_text(psel->nonzero, _("Fill is solid unless a subpath is counterdirectional (fill-rule: nonzero)"));
gtk_object_set_data(GTK_OBJECT(psel->nonzero), "mode", GUINT_TO_POINTER(SPPaintSelector::FILLRULE_NONZERO));
g_signal_connect(G_OBJECT(psel->nonzero), "toggled", G_CALLBACK(sp_paint_selector_fillrule_toggled), psel);
}
/* Frame */
/* Last used color */
}
static void
{
// clean up our long-living pattern menu
}
{
GtkWidget *b, *w;
b = gtk_toggle_button_new();
gtk_widget_show(b);
gtk_widget_show(w);
gtk_container_add(GTK_CONTAINER(b), w);
return b;
}
static void
{
psel->setMode(static_cast<SPPaintSelector::Mode>(GPOINTER_TO_UINT(gtk_object_get_data(GTK_OBJECT(tb), "mode"))));
}
}
static void
{
SPPaintSelector::FillRule fr = static_cast<SPPaintSelector::FillRule>(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(tb), "mode")));
}
}
void
{
if (psel->fillrulebox) {
if (is_fill) {
} else {
}
}
}
{
// This silliness is here because I don't know how to pass a parameter to the
// GtkObject "constructor" (sp_paint_selector_init). Remove it when paint_selector
// becomes a normal class.
return psel;
}
{
#ifdef SP_PS_VERBOSE
g_print("Mode change %d -> %d %s -> %s\n", this->mode, mode, modeStrings[this->mode], modeStrings[mode]);
#endif
switch (mode) {
case MODE_EMPTY:
break;
case MODE_MULTIPLE:
break;
case MODE_NONE:
break;
case MODE_COLOR_RGB:
case MODE_COLOR_CMYK:
sp_paint_selector_set_mode_color(this, mode);
break;
case MODE_GRADIENT_LINEAR:
case MODE_GRADIENT_RADIAL:
break;
case MODE_PATTERN:
break;
case MODE_SWATCH:
break;
case MODE_UNSET:
break;
default:
break;
}
}
}
{
if (fillrulebox) {
// TODO this flips widgets but does not use a member to store state. Revisit
}
}
{
SPColorSelector *csel = 0;
/*
if ( sp_color_get_colorspace_type(color) == SP_COLORSPACE_TYPE_CMYK )
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set CMYKA\n");
#endif
sp_paint_selector_set_mode(psel, MODE_COLOR_CMYK);
}
else
*/
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set RGBA\n");
#endif
}
csel = reinterpret_cast<SPColorSelector*>(gtk_object_get_data(GTK_OBJECT(selector), "color-selector"));
}
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set SWATCH\n");
#endif
SwatchSelector *swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(selector), "swatch-selector"));
if (swatchsel) {
}
}
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set GRADIENT LINEAR\n");
#endif
}
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set GRADIENT RADIAL\n");
#endif
}
{
}
void SPPaintSelector::getGradientProperties( SPGradientUnits &units, SPGradientSpread &spread) const
{
}
/**
* \post (alpha == NULL) || (*alpha in [0.0, 1.0]).
*/
{
&& ( alpha <= 1.0 ) );
}
{
SPGradient* vect = 0;
if (isPaintModeGradient(mode)) {
}
return vect;
}
{
gr->updateRepr();
}
static void
{
/* before we destroy the frame contents, we must detach
* the patternmenu so that Gtk doesn't gtk_widget_destroy
* all the children of the menu. (We also have a g_object_ref
* count set on it too so that the gtk_container_remove doesn't
* end up destroying it.
*/
}
}
}
}
static void
{
}
static void
{
}
static void
{
}
static void
{
}
/* Color paint */
{
}
{
}
{
}
static void
{
}
{
if ((psel->mode == SPPaintSelector::MODE_COLOR_RGB) || (psel->mode == SPPaintSelector::MODE_COLOR_CMYK)) {
/* Already have color selector */
} else {
/* Create new color selector */
/* Create vbox */
/* Color selector */
/* Pack everything to frame */
/* Set color */
}
#ifdef SP_PS_VERBOSE
g_print("Color req\n");
#endif
}
/* Gradient */
{
}
{
}
{
}
{
}
{
/* fixme: We do not need function-wide gsel at all */
} else {
}
if ((psel->mode == SPPaintSelector::MODE_GRADIENT_LINEAR) || (psel->mode == SPPaintSelector::MODE_GRADIENT_RADIAL)) {
/* Already have gradient selector */
} else {
/* Create new gradient selector */
g_signal_connect(G_OBJECT(gsel), "released", G_CALLBACK(sp_paint_selector_gradient_released), psel);
/* Pack everything to frame */
}
/* Actually we have to set option menu history here */
//sp_gradient_selector_set_mode(SP_GRADIENT_SELECTOR(gsel), SP_GRADIENT_SELECTOR_MODE_LINEAR);
} else {
}
#ifdef SP_PS_VERBOSE
g_print("Gradient req\n");
#endif
}
static void
{
}
{
// drop our reference to the pattern menu widget
}
{
}
/**
* Returns a list of patterns in the defs of the given source document as a GSList object
* Returns NULL if there are no patterns in the document.
*/
GSList *
{
return NULL;
if (SP_PATTERN(l->data) == pattern_getroot(SP_PATTERN(l->data))) { // only if this is a root pattern
}
}
return pl;
}
/**
* Adds menu items for pattern list - derived from marker code, left hb etc in to make addition of previews easier at some point.
*/
static void
{
GtkWidget *i = gtk_menu_item_new();
gtk_widget_show(i);
else
// create label
GtkWidget *l;
else
gtk_widget_show(l);
gtk_menu_append(GTK_MENU(m), i);
}
}
/**
* sp_pattern_list_from_doc()
*
* \brief Pick up all patterns from source, except those that are in
* current_doc (if non-NULL), and add items to the pattern menu
*
*/
static void sp_pattern_list_from_doc (GtkWidget *m, SPDocument * /*current_doc*/, SPDocument *source, SPDocument * /*pattern_doc*/)
{
continue;
}
// Add to the list of patterns we really do wish to show
}
g_slist_free (pl);
}
static void
{
// find and load patterns.svg
if (patterns_doc == NULL) {
}
}
// suck in from current doc
// add separator
{
GtkWidget *i = gtk_separator_menu_item_new();
gtk_widget_show(i);
gtk_menu_append(GTK_MENU(m), i);
}
// suck in from patterns.svg
if (patterns_doc) {
doc->ensureUpToDate();
}
}
static GtkWidget*
{
/* Create new menu widget */
GtkWidget *m = gtk_menu_new();
gtk_widget_show(m);
if (!doc) {
GtkWidget *i;
i = gtk_menu_item_new_with_label(_("No document selected"));
gtk_widget_show(i);
gtk_menu_append(GTK_MENU(m), i);
} else {
}
/* Set history */
return mnu;
}
/*update pattern list*/
{
if (update) {
return;
}
/* Clear existing menu if any */
/* Set history */
int patpos = 0;
int i = 0;
patpos = i;
}
i++;
}
}
//gtk_option_menu_set_history(GTK_OPTION_MENU(mnu), 0);
}
{
}
/* Already have pattern menu */
} else {
/* Create vbox */
{
}
{
gtk_label_set_markup(GTK_LABEL(l), _("Use the <b>Node tool</b> to adjust position, scale, and rotation of the pattern on canvas. Use <b>Object > Pattern > Objects to Pattern</b> to create a new pattern from selection."));
gtk_label_set_line_wrap(GTK_LABEL(l), true);
}
}
#ifdef SP_PS_VERBOSE
g_print("Pattern req\n");
#endif
}
{
/* no pattern menu if we were just selected */
/* Get Pattern */
{
return NULL;
}
"pattern");
//gchar *pattern = "";
"stockid");
if (pat_obj) {
}
} else {
}
pat = 0;
}
return pat;
}
{
}
SwatchSelector *swatchsel = 0;
swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(psel->selector), "swatch-selector"));
} else {
// Create new gradient selector
// Pack everything to frame
}
#ifdef SP_PS_VERBOSE
g_print("Swatch req\n");
#endif
}
// TODO this seems very bad to be taking in a desktop pointer to muck with. Logic probably belongs elsewhere
void SPPaintSelector::setFlatColor( SPDesktop *desktop, gchar const *color_property, gchar const *opacity_property )
{
#ifdef SP_PS_VERBOSE
g_message("sp_paint_selector_set_flat_color() to '%s' from 0x%08x::%s",
rgba,
#endif // SP_PS_VERBOSE
}
{
mode = MODE_UNSET;
} else if ( target.isPaintserver() ) {
SPPaintServer const *server = (kind == FILL) ? style.getFillPaintServer() : style.getStrokePaintServer();
#ifdef SP_PS_VERBOSE
g_message("==== server:%p %s grad:%s swatch:%s", server, server->getId(), (SP_IS_GRADIENT(server)?"Y":"n"), (SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()?"Y":"n"));
#endif // SP_PS_VERBOSE
mode = MODE_SWATCH;
} else if (SP_IS_LINEARGRADIENT(server)) {
} else if (SP_IS_RADIALGRADIENT(server)) {
} else if (SP_IS_PATTERN(server)) {
mode = MODE_PATTERN;
} else {
}
// TODO this is no longer a valid assertion:
} else {
}
return mode;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :