From fbb9317b912eba2ac02019869b687ec637790e9f Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 8 May 2016 09:29:51 +0200 Subject: Start of GTK3 external style sheet support. (bzr r14873.1.1) --- src/main.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 840643a90..99e3ccfe6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,6 +52,11 @@ #include #include +#if GTK_CHECK_VERSION(3,0,0) +#include +#include +#endif + #include "inkgc/gc-core.h" #ifdef AND @@ -1051,6 +1056,35 @@ sp_main_gui(int argc, char const **argv) #endif g_free(usericondir); + +#if GTK_CHECK_VERSION(3,0,0) + // Add style sheet (GTK3) + Glib::RefPtr screen = Gdk::Screen::get_default(); + + Glib::ustring inkscape_style = INKSCAPE_UIDIR; + inkscape_style += "/style.css"; + // std::cout << "CSS Stylesheet Inkscape: " << inkscape_style << std::endl; + Glib::RefPtr provider = Gtk::CssProvider::create(); + try { + provider->load_from_path (inkscape_style); + } + catch (const Gtk::CssProviderError& ex) + { + std::cerr << "CSSProviderError::load_from_path(): failed to load: " << inkscape_style << "\n (" << ex.what() << ")" << std::endl; + } + Gtk::StyleContext::add_provider_for_screen (screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + + Glib::ustring user_style = Inkscape::Application::profile_path("ui/style.css"); + // std::cout << "CSS Stylesheet User: " << user_style << std::endl; + Glib::RefPtr provider2 = Gtk::CssProvider::create(); + try { + provider2->load_from_path (user_style); + } + catch (const Gtk::CssProviderError& ex) + {} + Gtk::StyleContext::add_provider_for_screen (screen, provider2, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); +#endif + gdk_event_handler_set((GdkEventFunc)snooper, NULL, NULL); Inkscape::Debug::log_display_config(); -- cgit v1.2.3 From 424f8f6d1fd8e77e948edbe9fe9a712b75ec5385 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 15 May 2016 10:21:07 +0200 Subject: GTK3: Fix compile for GTK3 versions less than 3.16. (bzr r14887) --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 99e3ccfe6..4ce8ff145 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1068,10 +1068,12 @@ sp_main_gui(int argc, char const **argv) try { provider->load_from_path (inkscape_style); } +#if GTK_CHECK_VERSION(3,16,0) catch (const Gtk::CssProviderError& ex) { std::cerr << "CSSProviderError::load_from_path(): failed to load: " << inkscape_style << "\n (" << ex.what() << ")" << std::endl; } +#endif Gtk::StyleContext::add_provider_for_screen (screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); Glib::ustring user_style = Inkscape::Application::profile_path("ui/style.css"); @@ -1080,8 +1082,10 @@ sp_main_gui(int argc, char const **argv) try { provider2->load_from_path (user_style); } +#if GTK_CHECK_VERSION(3,16,0) catch (const Gtk::CssProviderError& ex) {} +#endif Gtk::StyleContext::add_provider_for_screen (screen, provider2, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); #endif -- cgit v1.2.3 From 1984f31c4efcc8be0cdd90a9eb7cc4882890f3cd Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 16 May 2016 12:35:28 +0200 Subject: GTK3: Fix compile for GTK3 versions less than 3.16. Try 2. (bzr r14891) --- src/main.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 4ce8ff145..07d970d59 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1065,28 +1065,39 @@ sp_main_gui(int argc, char const **argv) inkscape_style += "/style.css"; // std::cout << "CSS Stylesheet Inkscape: " << inkscape_style << std::endl; Glib::RefPtr provider = Gtk::CssProvider::create(); + + // From 3.16, throws an error which we must catch. try { provider->load_from_path (inkscape_style); } #if GTK_CHECK_VERSION(3,16,0) + // Gtk::CssProviderError not defined until 3.16. catch (const Gtk::CssProviderError& ex) { std::cerr << "CSSProviderError::load_from_path(): failed to load: " << inkscape_style << "\n (" << ex.what() << ")" << std::endl; } +#else + catch (...) + {} #endif + provider->load_from_path (inkscape_style); + Gtk::StyleContext::add_provider_for_screen (screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); Glib::ustring user_style = Inkscape::Application::profile_path("ui/style.css"); // std::cout << "CSS Stylesheet User: " << user_style << std::endl; Glib::RefPtr provider2 = Gtk::CssProvider::create(); + + // From 3.16, throws an error which we must catch. try { provider2->load_from_path (user_style); } -#if GTK_CHECK_VERSION(3,16,0) - catch (const Gtk::CssProviderError& ex) + catch (...) {} -#endif + provider2->load_from_path (user_style); + Gtk::StyleContext::add_provider_for_screen (screen, provider2, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + #endif gdk_event_handler_set((GdkEventFunc)snooper, NULL, NULL); -- cgit v1.2.3 From 742cc9ebed209c412c7ec315697a373d008320d3 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 17 May 2016 13:22:07 +0200 Subject: GTK3: Fix error if default style.css file not found. Modified patch from houz. (bzr r14897) --- src/main.cpp | 82 ++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 33 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 07d970d59..8cf52127b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -493,7 +493,7 @@ struct poptOption options[] = { POPT_ARG_NONE, &sp_vacuum_defs, SP_ARG_VACUUM_DEFS, N_("Remove unused definitions from the defs section(s) of the document"), NULL}, - + #ifdef WITH_DBUS {"dbus-listen", 0, POPT_ARG_NONE, &sp_dbus_listen, SP_ARG_DBUS_LISTEN, @@ -551,7 +551,7 @@ static void _win32_set_inkscape_env(gchar const *exe) gchar *perl = g_build_filename(exe, "python", NULL); gchar *pythonlib = g_build_filename(exe, "python", "Lib", NULL); gchar *pythondll = g_build_filename(exe, "python", "DLLs", NULL); - + // Python 2.x needs short paths in PYTHONPATH. // Otherwise it doesn't work when Inkscape is installed in Unicode directories. // g_win32_locale_filename_from_utf8 is the GLib wrapper for GetShortPathName. @@ -602,14 +602,14 @@ static void _win32_set_inkscape_env(gchar const *exe) g_free(perl); g_free(pythonlib); g_free(pythondll); - + g_free(python_s); g_free(pythonlib_s); g_free(pythondll_s); g_free(new_path); g_free(new_pythonpath); - + g_free(localepath); } #endif @@ -619,7 +619,7 @@ static void set_extensions_env() gchar const *pythonpath = g_getenv("PYTHONPATH"); gchar *extdir; gchar *new_pythonpath; - + #ifdef WIN32 extdir = g_win32_locale_filename_from_utf8(INKSCAPE_EXTENSIONDIR); #else @@ -905,7 +905,7 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) if ( sp_global_printer ) sp_global_printer_utf8 = g_strdup( sp_global_printer ); } - + #ifdef WITH_DBUS // Before initializing extensions, we must set the DBus bus name if required if (sp_dbus_name != NULL) { @@ -1064,40 +1064,56 @@ sp_main_gui(int argc, char const **argv) Glib::ustring inkscape_style = INKSCAPE_UIDIR; inkscape_style += "/style.css"; // std::cout << "CSS Stylesheet Inkscape: " << inkscape_style << std::endl; - Glib::RefPtr provider = Gtk::CssProvider::create(); - // From 3.16, throws an error which we must catch. - try { - provider->load_from_path (inkscape_style); - } + if (g_file_test (inkscape_style.c_str(), G_FILE_TEST_EXISTS)) { + Glib::RefPtr provider = Gtk::CssProvider::create(); + + // From 3.16, throws an error which we must catch. + try { + provider->load_from_path (inkscape_style); + } #if GTK_CHECK_VERSION(3,16,0) - // Gtk::CssProviderError not defined until 3.16. - catch (const Gtk::CssProviderError& ex) - { - std::cerr << "CSSProviderError::load_from_path(): failed to load: " << inkscape_style << "\n (" << ex.what() << ")" << std::endl; - } + // Gtk::CssProviderError not defined until 3.16. + catch (const Gtk::CssProviderError& ex) + { + std::cerr << "CSSProviderError::load_from_path(): failed to load: " << inkscape_style + << "\n (" << ex.what() << ")" << std::endl; + } #else - catch (...) - {} + catch (...) + {} #endif - provider->load_from_path (inkscape_style); - Gtk::StyleContext::add_provider_for_screen (screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + Gtk::StyleContext::add_provider_for_screen (screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } else { + std::cerr << "sp_main_gui: Cannot find default style file:\n (" << inkscape_style + << ")" << std::endl; + } Glib::ustring user_style = Inkscape::Application::profile_path("ui/style.css"); // std::cout << "CSS Stylesheet User: " << user_style << std::endl; - Glib::RefPtr provider2 = Gtk::CssProvider::create(); - // From 3.16, throws an error which we must catch. - try { - provider2->load_from_path (user_style); - } - catch (...) - {} - provider2->load_from_path (user_style); + if (g_file_test (user_style.c_str(), G_FILE_TEST_EXISTS)) { + Glib::RefPtr provider2 = Gtk::CssProvider::create(); - Gtk::StyleContext::add_provider_for_screen (screen, provider2, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + // From 3.16, throws an error which we must catch. + try { + provider2->load_from_path (user_style); + } +#if GTK_CHECK_VERSION(3,16,0) + // Gtk::CssProviderError not defined until 3.16. + catch (const Gtk::CssProviderError& ex) + { + std::cerr << "CSSProviderError::load_from_path(): failed to load: " << user_style + << "\n (" << ex.what() << ")" << std::endl; + } +#else + catch (...) + {} +#endif + Gtk::StyleContext::add_provider_for_screen (screen, provider2, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } #endif gdk_event_handler_set((GdkEventFunc)snooper, NULL, NULL); @@ -1183,7 +1199,7 @@ static int sp_process_file_list(GSList *fl) if (sp_vacuum_defs) { doc->vacuumDocument(); } - + // Execute command-line actions (selections and verbs) using our local models bool has_performed_actions = Inkscape::CmdLineAction::doList(INKSCAPE.active_action_context()); @@ -1694,9 +1710,9 @@ static int sp_do_export_png(SPDocument *doc) g_print("Background RRGGBBAA: %08x\n", bgcolor); g_print("Area %g:%g:%g:%g exported to %lu x %lu pixels (%g dpi)\n", area[Geom::X][0], area[Geom::Y][0], area[Geom::X][1], area[Geom::Y][1], width, height, dpi); - + reverse(items.begin(),items.end()); - + if ((width >= 1) && (height >= 1) && (width <= PNG_UINT_31_MAX) && (height <= PNG_UINT_31_MAX)) { if( sp_export_png_file(doc, path.c_str(), area, width, height, dpi, dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : std::vector()) == 1 ) { @@ -1866,7 +1882,7 @@ static int do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const* mime) } /** - * Export a document to EMF or WMF + * Export a document to EMF or WMF * * \param doc Document to export. * \param uri URI to export to. -- cgit v1.2.3