From 4332ec89e368205ed79a0ac55bbc3aa9e45cb3d9 Mon Sep 17 00:00:00 2001 From: ishmal Date: Fri, 3 Mar 2006 21:52:01 +0000 Subject: [PATCH] Fix bug with invalid singleton pointer. If we want a single dialog displayed, we can do it a safer way. (Callbacks in document-properties.cpp) --- src/ui/widget/color-picker.cpp | 127 +++++++++++++-------------------- src/ui/widget/color-picker.h | 47 +++++++++--- 2 files changed, 86 insertions(+), 88 deletions(-) diff --git a/src/ui/widget/color-picker.cpp b/src/ui/widget/color-picker.cpp index 9bc79ddc1..ef8c491d0 100644 --- a/src/ui/widget/color-picker.cpp +++ b/src/ui/widget/color-picker.cpp @@ -17,35 +17,21 @@ #include "desktop-handles.h" #include "document.h" -#include "ui/dialog/dialog.h" - #include "widgets/sp-color-notebook.h" #include "color-picker.h" namespace Inkscape { - namespace UI { - namespace Widget { - -struct CPPointer { - ColorPicker *ptr; -}; - -class ColorPickerWindow : public Inkscape::UI::Dialog::Dialog { -public: - ColorPickerWindow (ColorPicker* cp, const Glib::ustring &title); - virtual ~ColorPickerWindow(); - void setRgba32 (guint32); - - SPColorSelector *_csel; - CPPointer _cpp; -}; - -ColorPicker::ColorPicker (const Glib::ustring& title, const Glib::ustring& tip, +namespace UI { +namespace Widget { + + +ColorPicker::ColorPicker (const Glib::ustring& title, const Glib::ustring& tip, guint32 rgba, bool undo) -: _preview(rgba), _window(0), - _title(title), _rgba(rgba), _undo(undo) + : _preview(rgba), _title(title), _rgba(rgba), _undo(undo), + _colorSelectorDialog("dialogs.colorpickerwindow") { + setupDialog(title); set_relief (Gtk::RELIEF_NONE); _preview.show(); add (_preview); @@ -55,42 +41,61 @@ ColorPicker::ColorPicker (const Glib::ustring& title, const Glib::ustring& tip, ColorPicker::~ColorPicker() { closeWindow(); + _colorSelector = NULL; } +void +ColorPicker::setupDialog(const Glib::ustring &title) +{ + _colorSelectorDialog.hide(); + _colorSelectorDialog.set_title (title); + _colorSelectorDialog.set_border_width (4); + _colorSelector = (SPColorSelector*)sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK, + SP_COLORSPACE_TYPE_UNKNOWN); + _colorSelectorDialog.get_vbox()->pack_start ( + *Glib::wrap(&_colorSelector->vbox), true, true, 0); + + g_signal_connect(G_OBJECT(_colorSelector), "dragged", + G_CALLBACK(sp_color_picker_color_mod), (void *)this); + g_signal_connect(G_OBJECT(_colorSelector), "changed", + G_CALLBACK(sp_color_picker_color_mod), (void *)this); + + gtk_widget_show(GTK_WIDGET(_colorSelector)); + +} + + + + void ColorPicker::setRgba32 (guint32 rgba) { _preview.setRgba32 (rgba); _rgba = rgba; - if (_window) - _window->setRgba32 (rgba); + if (_colorSelector) + { + SPColor color; + sp_color_set_rgb_rgba32(&color, rgba); + _colorSelector->base->setColorAlpha(color, SP_RGBA32_A_F(rgba)); + } } void ColorPicker::closeWindow() { - if (_window) - { - delete _window; - _window = 0; - } + _colorSelectorDialog.hide(); } void ColorPicker::on_clicked() { - static int _x, _y; - if (_window) - { - _window->move(_x,_y); - _window->present(); - return; + if (_colorSelector) + { + SPColor color; + sp_color_set_rgb_rgba32(&color, _rgba); + _colorSelector->base->setColorAlpha(color, SP_RGBA32_A_F(_rgba)); } - - _window =new ColorPickerWindow (this, _title); - _window->setRgba32 (_rgba); - _window->show_all(); - _window->get_position (_x, _y); + _colorSelectorDialog.show(); } void @@ -105,8 +110,8 @@ sp_color_picker_color_mod(SPColorSelector *csel, GObject *cp) float alpha; csel->base->getColorAlpha(color, &alpha); guint32 rgba = sp_color_get_rgba32_falpha(&color, alpha); - - ColorPicker *ptr = static_cast((void*)cp)->ptr; + + ColorPicker *ptr = (ColorPicker *)(cp); (ptr->_preview).setRgba32 (rgba); @@ -117,43 +122,11 @@ sp_color_picker_color_mod(SPColorSelector *csel, GObject *cp) ptr->_changed_signal.emit (rgba); } -//============================================================== - -ColorPickerWindow::ColorPickerWindow (ColorPicker *cp, const Glib::ustring &title) - : Dialog("dialogs.colorpickerwindow") -{ - set_title (title); - set_border_width (4); - _csel = (SPColorSelector*)sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK, - SP_COLORSPACE_TYPE_UNKNOWN); - get_vbox()->pack_start (*Glib::wrap(&_csel->vbox), true, true, 0); - - _cpp.ptr = cp; - g_signal_connect(G_OBJECT(_csel), "dragged", - G_CALLBACK(sp_color_picker_color_mod), &_cpp); - g_signal_connect(G_OBJECT(_csel), "changed", - G_CALLBACK(sp_color_picker_color_mod), &_cpp); - - show(); -} -ColorPickerWindow::~ColorPickerWindow() -{ - _csel = 0; -} - -void -ColorPickerWindow::setRgba32 (guint32 rgba) -{ - if (_csel) - { - SPColor color; - sp_color_set_rgb_rgba32(&color, rgba); - _csel->base->setColorAlpha(color, SP_RGBA32_A_F(rgba)); - } -} +}//namespace Widget +}//namespace UI +}//namespace Inkscape -}}} /* Local Variables: diff --git a/src/ui/widget/color-picker.h b/src/ui/widget/color-picker.h index adff8181a..0349c75e5 100644 --- a/src/ui/widget/color-picker.h +++ b/src/ui/widget/color-picker.h @@ -16,40 +16,65 @@ #include #include +#include #include +#include "widgets/sp-color-selector.h" #include "ui/widget/color-preview.h" +//#include "ui/dialog/dialog.h" + + + +namespace Inkscape +{ +namespace UI +{ +namespace Widget +{ -class SPColorSelector; -namespace Inkscape { - namespace UI { - namespace Widget { - class ColorPickerWindow; class ColorPicker : public Gtk::Button { public: - ColorPicker (const Glib::ustring& title, const Glib::ustring& tip, const guint32 rgba, bool undo); + + ColorPicker (const Glib::ustring& title, + const Glib::ustring& tip, + const guint32 rgba, + bool undo); + virtual ~ColorPicker(); + void setRgba32 (guint32 rgba); + void closeWindow(); - sigc::connection connectChanged (const sigc::slot& slot) + + sigc::connection connectChanged (const sigc::slot& slot) { return _changed_signal.connect (slot); } protected: + friend void sp_color_picker_color_mod(SPColorSelector *csel, GObject *cp); virtual void on_clicked(); virtual void on_changed (guint32); - + ColorPreview _preview; Gtk::Tooltips _tt; - ColorPickerWindow *_window; - + const Glib::ustring _title; sigc::signal _changed_signal; guint32 _rgba; bool _undo; + + + //Dialog + void setupDialog(const Glib::ustring &title); + //Inkscape::UI::Dialog::Dialog _colorSelectorDialog; + Gtk::Dialog _colorSelectorDialog; + SPColorSelector *_colorSelector; + }; -}}} +}//namespace Widget +}//namespace UI +}//namespace Inkscape #endif /* !__COLOR_PICKER_H__ */ -- 2.30.2