Studio was crashing on Windows if built with debug enabled when trying to recover...
[synfig.git] / synfig-studio / trunk / src / gtkmm / app.cpp
index 69aa237..e9dcbb2 100644 (file)
@@ -7,6 +7,7 @@
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
 **     Copyright (c) 2007, 2008 Chris Moore
+**     Copyright (c) 2008 Gerald Young
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
 #      include <config.h>
 #endif
 
+#ifdef WIN32
+#define WINVER 0x0500
+#include <windows.h>
+#endif
+
 #include <fstream>
 #include <iostream>
 #include <locale>
 #include <fmod.h>
 #endif
 
-#ifdef WIN32
-#define _WIN32_WINNT 0x0500
-#include <windows.h>
-#endif
 #include <gtkmm/accelmap.h>
 #include <gtkmm/filechooser.h>
 #include <gtkmm/filechooserdialog.h>
@@ -1326,7 +1328,12 @@ App::~App()
 String
 App::get_user_app_directory()
 {
+//! \todo do we need locale_from_utf8() on non-Windows boxes too?  (bug #1837445)
+#ifdef WIN32
+       return Glib::locale_from_utf8(Glib::build_filename(Glib::get_home_dir(),SYNFIG_USER_APP_DIR));
+#else
        return Glib::build_filename(Glib::get_home_dir(),SYNFIG_USER_APP_DIR);
+#endif
 }
 
 synfig::String
@@ -1349,12 +1356,13 @@ App::set_recent_file_window_size(etl::handle<Instance> instance)
                return;
 
        synfig::String::size_type current=0;
+       bool seen_root(false), shown_non_root(false);
 
        while(current != synfig::String::npos)
        {
                // find end of first field (canvas) or return
                synfig::String::size_type separator = canvas_window_size.find_first_of(' ', current);
-               if(separator == synfig::String::npos) return;
+               if(separator == synfig::String::npos) break;
 
                // find the canvas
                synfig::Canvas::Handle canvas;
@@ -1369,8 +1377,10 @@ App::set_recent_file_window_size(etl::handle<Instance> instance)
                        continue;
                }
 
-               CanvasView::Handle canvasview = instance->find_canvas_view(canvas);
-               canvasview->present();
+               if (canvas->is_root())
+                       seen_root = true;
+               else
+                       shown_non_root = true;
 
                // check that we have the tab character the ends this canvas' data or return
                current = separator+1;
@@ -1392,17 +1402,20 @@ App::set_recent_file_window_size(etl::handle<Instance> instance)
                        x += atoi(getenv("SYNFIG_WINDOW_POSITION_X_OFFSET"));
                if(getenv("SYNFIG_WINDOW_POSITION_Y_OFFSET"))
                        y += atoi(getenv("SYNFIG_WINDOW_POSITION_Y_OFFSET"));
-               canvasview->move(x,y);
 
                if (w > SCALE_FACTOR) w = 150; if (w < 0) w = 0;
                if (h > SCALE_FACTOR) h = 150; if (h < 0) h = 0;
-               w=w*screen_w/SCALE_FACTOR;
-               h=h*screen_h/SCALE_FACTOR;
-               canvasview->set_default_size(w,h);
-               canvasview->set_size_request(w,h);
+
+               CanvasView::Handle canvasview = instance->find_canvas_view(canvas);
+               canvasview->move(x,y);
+               canvasview->resize(w*screen_w/SCALE_FACTOR,h*screen_h/SCALE_FACTOR);
+               canvasview->present();
 
                current = separator+1;
        }
+
+       if (shown_non_root && !seen_root)
+               instance->find_canvas_view(instance->get_canvas())->hide();
 }
 
 void
@@ -1612,7 +1625,7 @@ App::load_settings()
                std::string filename=get_config_file("settings");
                if(!synfigapp::Main::settings().load_from_file(filename))
                {
-                       //std::string filename=Glib::build_filename(Glib::get_home_dir(),".synfigrc");
+                       //std::string filename=Glib::locale_from_utf8(Glib::build_filename(Glib::get_home_dir(),".synfigrc"));
                        //if(!synfigapp::Main::settings().load_from_file(filename))
                        {
                                gamma.set_gamma(1.0/2.2);
@@ -2154,7 +2167,10 @@ App::open_as(std::string filename,std::string as)
 #ifdef WIN32
     char long_name[1024];
     if(GetLongPathName(as.c_str(),long_name,sizeof(long_name)));
-    as=long_name;
+       // when called from autorecover.cpp, filename doesn't exist, and so long_name is empty
+       // don't use it if that's the case
+       if (long_name[0] != '\0')
+               as=long_name;
 #endif
 
        try