Code

Fix bug with invalid singleton pointer. If we want a single dialog displayed, we...
authorishmal <ishmal@users.sourceforge.net>
Fri, 3 Mar 2006 21:52:01 +0000 (21:52 +0000)
committerishmal <ishmal@users.sourceforge.net>
Fri, 3 Mar 2006 21:52:01 +0000 (21:52 +0000)
src/ui/widget/color-picker.cpp
src/ui/widget/color-picker.h

index 9bc79ddc1f9f1a999e5c94be4791f39eb0c9431f..ef8c491d0fe458a4c953c74b6cb5a61fa50336b5 100644 (file)
 #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<CPPointer*>((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:
index adff8181a7295a709d25a1389be09365c425607f..0349c75e5452be1b3ac1a98a247151676fb15789 100644 (file)
 
 #include <sigc++/sigc++.h>
 #include <gtkmm/button.h>
+#include <gtkmm/dialog.h>
 #include <gtkmm/tooltips.h>
+#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<void,guint>& slot) 
+
+    sigc::connection connectChanged (const sigc::slot<void,guint>& 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<void,guint32> _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__ */