Code

From trunk
[inkscape.git] / src / ui / dialog / floating-behavior.cpp
index 7d321b21b9e7494a7aefe6a7c154b8ef11f7f28b..19147f2c7cfddd277140816722b1d4f9f1ad60ed 100644 (file)
@@ -1,7 +1,7 @@
-/**
- * \brief A floating dialog implementation.
- *
- * Author:
+/** @file
+ * @brief Floating dialog implementation.
+ */
+/* Author:
  *   Gustav Broberg <broberg@kth.se>
  *
  * Copyright (C) 2007 Authors
@@ -21,7 +21,7 @@
 #include "desktop.h"
 #include "dialogs/dialog-events.h"
 #include "interface.h"
-#include "prefs-utils.h"
+#include "preferences.h"
 #include "verbs.h"
 
 namespace Inkscape {
@@ -29,32 +29,115 @@ namespace UI {
 namespace Dialog {
 namespace Behavior {
 
-FloatingBehavior::FloatingBehavior(Dialogdialog) :
+FloatingBehavior::FloatingBehavior(Dialog &dialog) :
     Behavior(dialog),
     _d (new Gtk::Dialog(_dialog._title))
+#if GTK_VERSION_GE(2, 12)
+       ,_dialog_active(_d->property_is_active())
+       ,_steps(0)
+       ,_trans_focus(Inkscape::Preferences::get()->getDoubleLimited("/dialogs/transparency/on-focus", 0.95, 0.0, 1.0))
+       ,_trans_blur(Inkscape::Preferences::get()->getDoubleLimited("/dialogs/transparency/on-blur", 0.50, 0.0, 1.0))
+       ,_trans_time(Inkscape::Preferences::get()->getIntLimited("/dialogs/transparency/animate-time", 100, 0, 5000))
+#endif
 {
     hide();
     _d->set_has_separator(false);
 
-    signal_response().connect(sigc::mem_fun(_dialog, &Inkscape::UI::Dialog::Dialog::_onResponse));
     signal_delete_event().connect(sigc::mem_fun(_dialog, &Inkscape::UI::Dialog::Dialog::_onDeleteEvent));
 
     sp_transientize(GTK_WIDGET(_d->gobj()));
     _dialog.retransientize_suppress = false;
+
+#if GTK_VERSION_GE(2, 12)
+       _focus_event();
+       _dialog_active.signal_changed().connect(sigc::mem_fun(this, &FloatingBehavior::_focus_event));
+#endif
+
+}
+
+#if GTK_VERSION_GE(2, 12)
+/** \brief  A function called when the window gets focus
+
+       This function gets called on a focus event.  It figures out how much
+       time is required for a transition, and the number of steps that'll take,
+       and sets up the _trans_timer function to do the work.  If the transition
+       time is set to 0 ms it just calls _trans_timer once with _steps equal to
+       zero so that the transition happens instantaneously.  This occurs on
+       windows as opacity changes cause flicker there.
+*/
+void FloatingBehavior::_focus_event (void)
+{
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    _steps = 0;
+    _trans_focus = prefs->getDoubleLimited("/dialogs/transparency/on-focus", 0.95, 0.0, 1.0);
+    _trans_blur = prefs->getDoubleLimited("/dialogs/transparency/on-blur", 0.50, 0.0, 1.0);
+    _trans_time = prefs->getIntLimited("/dialogs/transparency/animate-time", 100, 0, 5000);
+
+    if (_trans_time != 0) {
+        float diff = _trans_focus - _trans_blur;
+        if (diff < 0.0) diff *= -1.0;
+
+        while (diff > 0.05) {
+            _steps++;
+            diff = diff / 2.0;
+        }
+
+        if (_steps != 0) {
+            Glib::signal_timeout().connect(sigc::mem_fun(this, &FloatingBehavior::_trans_timer), _trans_time / _steps);
+        }
+    }
+    _trans_timer();
+
+    return;
+}
+
+/** \brief  Move the opacity of a window towards our goal
+
+       This is a timer function that is set up by _focus_event to slightly
+       move the opacity of the window along in an animated fashion.  It moves
+       the opacity half way to the goal until it runs out of steps, and then
+       it just forces the goal.
+*/
+bool FloatingBehavior::_trans_timer (void) {
+       // printf("Go go gadget timer: %d\n", _steps);
+       if (_steps == 0) {
+               if (_dialog_active.get_value()) {
+                       _d->set_opacity(_trans_focus);
+               } else {
+                       _d->set_opacity(_trans_blur);
+               }
+
+               return false;
+       }
+
+       float goal, current;
+       goal = current = _d->get_opacity();
+
+       if (_dialog_active.get_value()) {
+               goal = _trans_focus;
+       } else {
+               goal = _trans_blur;
+       }
+       
+       _d->set_opacity(current - ((current - goal) / 2));
+       _steps--;
+       return true;
 }
 
+#endif
+
 FloatingBehavior::~FloatingBehavior() 
 { 
     delete _d;
 }
 
 Behavior *
-FloatingBehavior::create(Dialogdialog)
+FloatingBehavior::create(Dialog &dialog)
 {
     return new FloatingBehavior(dialog);
 }
 
-inline FloatingBehavior::operator Gtk::Widget&()                          { return *_d; }
+inline FloatingBehavior::operator Gtk::Widget &()                          { return *_d; }
 inline GtkWidget *FloatingBehavior::gobj()                                { return GTK_WIDGET(_d->gobj()); }
 inline Gtk::VBox* FloatingBehavior::get_vbox()                            { return _d->get_vbox(); }
 inline void FloatingBehavior::present()                                   { _d->present(); }
@@ -65,27 +148,15 @@ inline void FloatingBehavior::resize(int width, int height)               { _d->
 inline void FloatingBehavior::move(int x, int y)                          { _d->move(x, y); }
 inline void FloatingBehavior::set_position(Gtk::WindowPosition position)  { _d->set_position(position); }
 inline void FloatingBehavior::set_size_request(int width, int height)     { _d->set_size_request(width, height); }
-inline void FloatingBehavior::size_request(Gtk::Requisitionrequisition) { _d->size_request(requisition); }
-inline void FloatingBehavior::get_position(int& x, int& y)                { _d->get_position(x, y); }
-inline void FloatingBehavior::get_size(int& width, int& height)           { _d->get_size(width, height); }
+inline void FloatingBehavior::size_request(Gtk::Requisition &requisition) { _d->size_request(requisition); }
+inline void FloatingBehavior::get_position(int &x, int &y)                { _d->get_position(x, y); }
+inline void FloatingBehavior::get_size(int &width, int &height)           { _d->get_size(width, height); }
 inline void FloatingBehavior::set_title(Glib::ustring title)              { _d->set_title(title); }
 inline void FloatingBehavior::set_sensitive(bool sensitive)               { _d->set_sensitive(sensitive); }
 
-void FloatingBehavior::set_response_sensitive(int response_id, bool setting) 
-{ _d->set_response_sensitive(response_id, setting); }
-
-Gtk::Button *FloatingBehavior::add_button(const Glib::ustring& button_text, int response_id)
-{ return _d->add_button(button_text, response_id); }
-
-Gtk::Button *FloatingBehavior::add_button(const Gtk::StockID& stock_id, int response_id)
-{ return _d->add_button(stock_id, response_id); }
-
-inline void FloatingBehavior::set_default_response(int response_id) { _d->set_default_response(response_id); }
-
 Glib::SignalProxy0<void> FloatingBehavior::signal_show() { return _d->signal_show(); }
 Glib::SignalProxy0<void> FloatingBehavior::signal_hide() { return _d->signal_hide(); }
 Glib::SignalProxy1<bool, GdkEventAny *> FloatingBehavior::signal_delete_event () { return _d->signal_delete_event(); }
-Glib::SignalProxy1<void, int> FloatingBehavior::signal_response () { return _d->signal_response(); }
 
 
 void
@@ -108,13 +179,11 @@ FloatingBehavior::onShutdown() {}
 void
 FloatingBehavior::onDesktopActivated (SPDesktop *desktop)
 {
-    gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    gint transient_policy = prefs->getIntLimited("/options/transientpolicy/value", 1, 0, 2);
 
-#ifdef WIN32 // FIXME: Temporary Win32 special code to enable transient dialogs
-    if (prefs_get_int_attribute ( "options.dialogsontopwin32", "value", 0))
-        transient_policy = 2;
-    else    
-        return;
+#ifdef WIN32 // Win32 special code to enable transient dialogs
+    transient_policy = 2;
 #endif        
 
     if (!transient_policy)