Added copyright lines for files I've edited this year.
[synfig.git] / synfig-studio / trunk / src / gtkmm / dockdialog.cpp
index 62ff671..614e8db 100644 (file)
@@ -1,20 +1,22 @@
-/* === S I N F G =========================================================== */
+/* === S Y N F I G ========================================================= */
 /*!    \file dockdialog.cpp
 **     \brief Template File
 **
-**     $Id: dockdialog.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
+**     $Id$
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007, 2008 Chris Moore
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
 **     \endlegal
 */
 /* ========================================================================= */
 #include "dockdialog.h"
 #include "dockbook.h"
 #include "dockmanager.h"
+#include "toolbox.h"
 #include "widget_compselect.h"
-#include <sinfg/general.h>
-#include <sinfg/uniqueid.h>
+#include <synfig/general.h>
+#include <synfig/uniqueid.h>
 #include <gtkmm/table.h>
 #include <sigc++/hide.h>
 #include <sigc++/slot.h>
@@ -45,7 +48,9 @@
 #include "canvasview.h"
 #include <gtkmm/paned.h>
 #include <gtkmm/box.h>
-#include <sinfgapp/main.h>
+#include <synfigapp/main.h>
+
+#include "general.h"
 
 #endif
 
 
 using namespace std;
 using namespace etl;
-using namespace sinfg;
+using namespace synfig;
 using namespace studio;
 
 /* === M A C R O S ========================================================= */
 
 #define GRAB_HINT_DATA(y,default)      { \
                String x; \
-               if(sinfgapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
+               if(synfigapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
                { \
                        set_type_hint((Gdk::WindowTypeHint)atoi(x.c_str()));    \
                } else {\
@@ -82,12 +87,12 @@ DockDialog::DockDialog():
        is_horizontal=false;
        last_dock_book=0;
        box=0;
-       
+
        widget_comp_select=new Widget_CompSelect();
-       
+
        // Give ourselves an ID that is most likely unique
-       set_id(sinfg::UniqueID().get_uid()^reinterpret_cast<int>(this));
-       
+       set_id(synfig::UniqueID().get_uid()^reinterpret_cast<long>(this));
+
        set_role(strprintf("dock_dialog_%d",get_id()));
        GRAB_HINT_DATA(
                "dock_dialog",
@@ -97,24 +102,29 @@ DockDialog::DockDialog():
                Gdk::WINDOW_TYPE_HINT_UTILITY
 #endif
        );
-       set_keep_below(true);
        set_keep_above(false);
-       
+
+       //! \todo can we set dialog windows transient for all normal windows, not just the toolbox?
+       //! paragraph 3 of http://standards.freedesktop.org/wm-spec/1.3/ar01s07.html suggests we can
+       // this seems to have bad effects on KDE, so leave it disabled by default
+       if(getenv("SYNFIG_TRANSIENT_DIALOGS"))
+               set_transient_for(*App::toolbox);
+
        // Set up the window
        //set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
-       set_title("Dock Dialog");
-       
+       set_title(_("Dock Panel"));
+
        // Register with the dock manager
        App::dock_manager->dock_dialog_list_.push_back(this);
 
-       
-       // connect our signals  
+
+       // connect our signals
        signal_delete_event().connect(
                sigc::hide(
                        sigc::mem_fun(*this,&DockDialog::close)
                )
        );
-       
+
 /*
        App::signal_canvas_view_focus().connect(
                sigc::hide(
@@ -127,7 +137,7 @@ DockDialog::DockDialog():
 */
 
        add_accel_group(App::ui_manager()->get_accel_group());
-       App::signal_present_all().connect(sigc::mem_fun(*this,&DockDialog::present));
+       App::signal_present_all().connect(sigc::mem_fun0(*this,&DockDialog::present));
 
 }
 
@@ -137,24 +147,28 @@ DockDialog::~DockDialog()
 
        is_deleting=true;
 
-       DEBUGPOINT();
-
        // Remove all of the dock books
        for(;!dock_book_list.empty();dock_book_list.pop_front())
        {
                dock_book_list.front()->clear();
 
-               // UGLY HACK
+               //! \todo Fix this UGLY HACK
                // The following line really should be uncommented,
                // but it causes crashes. Without it, a small
                // memory hole is created--but at least it doesn't crash
                // delete dock_book_list.front();
-               
+
                // Oddly enough, the following line should
-               // theoreticly do the same thing after this
+               // theoretically do the same thing after this
                // class is destroyed, but it doesn't seem to
-               // caues a crash.
-               manage(dock_book_list.front());
+               // cause a crash.  It does, however, trigger this warning:
+               //
+               //   A floating object was finalized. This means that someone
+               //   called g_object_unref() on an object that had only a
+               //   floating reference; the initial floating reference is not
+               //   owned by anyone and must be removed with g_object_ref_sink().
+               //
+               // manage(dock_book_list.front());
        }
 
        // Remove us from the dock manager
@@ -169,12 +183,10 @@ DockDialog::~DockDialog()
        }
        catch(...)
        {
-               sinfg::warning("DockDialog::~DockDialog(): Exception thrown when trying to remove from dock manager...?");
+               synfig::warning("DockDialog::~DockDialog(): Exception thrown when trying to remove from dock manager...?");
        }
 
        delete widget_comp_select;
-
-       DEBUGPOINT();
 }
 
 void
@@ -187,7 +199,7 @@ DockDialog::drop_on_prepend(const Glib::RefPtr<Gdk::DragContext>& context, int,
                context->drag_finish(true, false, time);
                return;
        }
-       
+
        context->drag_finish(false, false, time);
 }
 
@@ -201,7 +213,7 @@ DockDialog::drop_on_append(const Glib::RefPtr<Gdk::DragContext>& context, int, i
                context->drag_finish(true, false, time);
                return;
        }
-       
+
        context->drag_finish(false, false, time);
 }
 
@@ -217,7 +229,7 @@ DockBook*
 DockDialog::prepend_dock_book()
 {
        if(is_deleting)return 0;
-               
+
        dock_book_list.push_front(new DockBook);
        last_dock_book=dock_book_list.front();
 
@@ -238,7 +250,7 @@ DockBook*
 DockDialog::append_dock_book()
 {
        if(is_deleting)return 0;
-               
+
        dock_book_list.push_back(new DockBook);
        last_dock_book=dock_book_list.back();
        last_dock_book->signal_empty().connect(
@@ -282,9 +294,9 @@ DockDialog::erase_dock_book(DockBook* dock_book)
                                if(last_dock_book==dock_book)
                                        last_dock_book=dock_book_list.front();
                        }
-                       
+
                        refresh();
-                       
+
                        return;
                }
 }
@@ -292,21 +304,21 @@ DockDialog::erase_dock_book(DockBook* dock_book)
 void
 DockDialog::refresh()
 {
-       sinfg::info("dock_book_list.size()=%d",dock_book_list.size());
+       // synfig::info("dock_book_list.size()=%d",dock_book_list.size());
        //remove();
 
        if(dock_book_list.empty())
                return;
-       
+
        if(box)delete box;
        box=(manage(is_horizontal?(Gtk::Box*)new Gtk::HBox:(Gtk::Box*)new Gtk::VBox));
        add(*box);
-       
+
        box->pack_start(*widget_comp_select,false,true);
 
        Gtk::Button* append_button(manage(new Gtk::Button));
        Gtk::Button* prepend_button(manage(new Gtk::Button));
-       
+
        std::list<Gtk::TargetEntry> listTargets;
        listTargets.push_back( Gtk::TargetEntry("DOCK") );
 
@@ -320,14 +332,14 @@ DockDialog::refresh()
        prepend_button->signal_drag_data_received().connect(
                sigc::mem_fun(*this,&DockDialog::drop_on_prepend)
        );
-       
+
        box->pack_start(*prepend_button,false,true);
        box->pack_end(*append_button,false,true);
 
        //prepend_button->show();
        //append_button->show();
-       pannels_.clear();
-       
+       panels_.clear();
+
        if(dock_book_list.size()==1)
        {
                box->pack_start(get_dock_book(),true,true);
@@ -335,29 +347,29 @@ DockDialog::refresh()
        else
        {
                Gtk::Paned* parent(manage(is_horizontal?(Gtk::Paned*)new Gtk::HPaned:(Gtk::Paned*)new Gtk::VPaned));
-               
-               pannels_.push_back(parent);
-               
-               if(pannels_.size()<=dock_book_sizes_.size())
-                       pannels_.back()->set_position(dock_book_sizes_[pannels_.size()-1]);
-               pannels_.back()->property_position().signal_changed().connect(
+
+               panels_.push_back(parent);
+
+               if(panels_.size()<=dock_book_sizes_.size())
+                       panels_.back()->set_position(dock_book_sizes_[panels_.size()-1]);
+               panels_.back()->property_position().signal_changed().connect(
                        sigc::mem_fun(*this,&DockDialog::rebuild_sizes)
                );
                //parent->show();
                parent->add1(*dock_book_list.front());
                //dock_book_list.front()->show();
-        
+
                box->pack_start(*parent,true,true);
-               
+
                std::list<DockBook*>::iterator iter,next;
                for(next=dock_book_list.begin(),next++,iter=next++;next!=dock_book_list.end();iter=next++)
                {
                        Gtk::Paned* current(manage(is_horizontal?(Gtk::Paned*)new Gtk::HPaned:(Gtk::Paned*)new Gtk::VPaned));
-                       pannels_.push_back(current);
-                       
-                       if(pannels_.size()<=dock_book_sizes_.size())
-                               pannels_.back()->set_position(dock_book_sizes_[pannels_.size()-1]);
-                       pannels_.back()->property_position().signal_changed().connect(
+                       panels_.push_back(current);
+
+                       if(panels_.size()<=dock_book_sizes_.size())
+                               panels_.back()->set_position(dock_book_sizes_[panels_.size()-1]);
+                       panels_.back()->property_position().signal_changed().connect(
                                sigc::mem_fun(*this,&DockDialog::rebuild_sizes)
                        );
 
@@ -367,13 +379,13 @@ DockDialog::refresh()
                        current->add1(**iter);
                        //(*iter)->show();
                        //current->show();
-                       
+
                        parent=current;
                }
                parent->add2(**iter);
                //(*iter)->show();
        }
-       
+
        box->show_all();
        if(!composition_selector_)
                widget_comp_select->hide();
@@ -385,9 +397,9 @@ DockDialog::rebuild_sizes()
 {
        unsigned int i=0;
        dock_book_sizes_.clear();
-       for(i=0;i<pannels_.size();i++)
+       for(i=0;i<panels_.size();i++)
        {
-               dock_book_sizes_.push_back(pannels_[i]->get_position());
+               dock_book_sizes_.push_back(panels_[i]->get_position());
        }
 }
 
@@ -395,9 +407,9 @@ void
 DockDialog::set_dock_book_sizes(const std::vector<int>& new_sizes)
 {
        unsigned int i=0;
-       for(i=0;i<pannels_.size() && i<new_sizes.size();i++)
+       for(i=0;i<panels_.size() && i<new_sizes.size();i++)
        {
-               pannels_[i]->set_position(new_sizes[i]);
+               panels_[i]->set_position(new_sizes[i]);
        }
        dock_book_sizes_=new_sizes;
        //rebuild_sizes();
@@ -413,7 +425,7 @@ DockDialog::refresh_accel_group()
                remove_accel_group(last_accel_group_);
                last_accel_group_=Glib::RefPtr<Gtk::AccelGroup>();
        }
-       
+
        etl::loose_handle<CanvasView> canvas_view(App::get_selected_canvas_view());
        if(canvas_view)
        {
@@ -432,10 +444,12 @@ DockDialog::refresh_accel_group()
 bool
 DockDialog::close()
 {
-       sinfg::info("DockDialog::close(): DELETED!");
+       if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
+               synfig::info("DockDialog::close(): Deleted");
+
        empty_sig.disconnect();
        //get_dock_book().clear();
-       delete this;    
+       delete this;
        return true;
 }
 
@@ -454,10 +468,10 @@ DockDialog::get_dock_book()const
 }
 
 
-sinfg::String
+synfig::String
 DockDialog::get_contents()const
 {
-       sinfg::String ret;
+       synfig::String ret;
 
        std::list<DockBook*>::const_iterator iter;
        for(iter=dock_book_list.begin();iter!=dock_book_list.end();++iter)
@@ -466,26 +480,26 @@ DockDialog::get_contents()const
                        ret+=is_horizontal?" | ":" - ";
                ret+=(*iter)->get_contents();
        }
-               
-       
+
+
        return ret;
 }
 
 void
-DockDialog::set_contents(const sinfg::String& z)
+DockDialog::set_contents(const synfig::String& z)
 {
        int x,y;
        get_size(x,y);
 
-       sinfg::String str(z);
+       synfig::String str(z);
        while(!str.empty())
        {
-               unsigned int separator=str.find_first_of('-');
+               synfig::String::size_type separator=str.find_first_of('-');
                {
-                       unsigned int sep2=str.find_first_of('|');
-                       if(separator!=sinfg::String::npos || sep2!=sinfg::String::npos)
+                       synfig::String::size_type sep2=str.find_first_of('|');
+                       if(separator!=synfig::String::npos || sep2!=synfig::String::npos)
                        {
-                               if((separator==sinfg::String::npos || sep2<separator) && sep2!=sinfg::String::npos)
+                               if((separator==synfig::String::npos || sep2<separator) && sep2!=synfig::String::npos)
                                {
                                        separator=sep2;
                                        is_horizontal=true;
@@ -494,9 +508,9 @@ DockDialog::set_contents(const sinfg::String& z)
                                        is_horizontal=false;
                        }
                }
-               
-               sinfg::String book_contents;
-               if(separator==sinfg::String::npos)
+
+               synfig::String book_contents;
+               if(separator==synfig::String::npos)
                {
                        book_contents=str;
                        str.clear();
@@ -506,7 +520,7 @@ DockDialog::set_contents(const sinfg::String& z)
                        book_contents=String(str.begin(),str.begin()+separator);
                        str=String(str.begin()+separator+1,str.end());
                }
-               
+
                try
                {
                        append_dock_book()->set_contents(book_contents);
@@ -534,7 +548,7 @@ DockDialog::refresh_title()
        if(is_deleting)return;
        if(dock_book_list.size())
        {
-               sinfg::String title;
+               synfig::String title;
 
                std::list<DockBook*>::const_iterator iter;
                for(iter=dock_book_list.begin();iter!=dock_book_list.end();++iter)
@@ -546,5 +560,5 @@ DockDialog::refresh_title()
                set_title(title);
        }
        else
-               set_title(_("Empty Dock Dialog"));
+               set_title(_("Empty Dock Panel"));
 }