Code

Add missing namespaces in win32 code (thanks to Yann Papouin for pointing this out)
[inkscape.git] / src / ui / dialog / filedialogimpl-win32.cpp
index e2d0449084e2bff8c15b2ba6154eff216a1dc453..2196ef0de4091acde803385591acc35def231f8e 100644 (file)
@@ -1,7 +1,7 @@
-/**
- * Implementation of the file dialog interfaces defined in filedialog.h for Win32
- *
- * Authors:
+/** @file
+ * @brief Implementation of native file dialogs for Win32
+ */
+/* Authors:
  *   Joel Holdsworth
  *   The Inkscape Organization
  *
@@ -9,13 +9,12 @@
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
+#ifdef WIN32
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
 
-#ifdef WIN32
-
 //General includes
 #include <list>
 #include <unistd.h>
@@ -29,7 +28,6 @@
 
 //Inkscape includes
 #include "inkscape.h"
-#include "prefs-utils.h"
 #include <dialogs/dialog-events.h>
 #include <extension/input.h>
 #include <extension/output.h>
@@ -192,15 +190,17 @@ void FileOpenDialogImplWin32::createFilterMenu()
     Inkscape::Extension::DB::InputList extension_list;
     Inkscape::Extension::db.get_input_list(extension_list);
 
-    ustring all_inkscape_files_filter, all_image_files_filter;
-    Filter all_files, all_inkscape_files, all_image_files;
+    ustring all_inkscape_files_filter, all_image_files_filter, all_vectors_filter, all_bitmaps_filter;
+    Filter all_files, all_inkscape_files, all_image_files, all_vectors, all_bitmaps;
 
     const gchar *all_files_filter_name = N_("All Files");
     const gchar *all_inkscape_files_filter_name = N_("All Inkscape Files");
-    const gchar *all_image_files_filter_name = N_("All Image Files");
+    const gchar *all_image_files_filter_name = N_("All Images");
+    const gchar *all_vectors_filter_name = N_("All Vectors");
+    const gchar *all_bitmaps_filter_name = N_("All Bitmaps");
 
     // Calculate the amount of memory required
-    int filter_count = 3;       // 3 - one for All Files, All Images and All Inkscape Files
+    int filter_count = 5;       // 5 - one for each filter type
     int filter_length = 1;
 
     for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
@@ -238,12 +238,54 @@ void FileOpenDialogImplWin32::createFilterMenu()
             all_image_files_filter += file_extension_name;
         }
 
+        // I don't know of any other way to define "bitmap" formats other than by listing them
+        // if you change it here, do the same change in filedialogimpl-gtkmm
+        if ( 
+            strncmp("image/png", imod->get_mimetype(), 9)==0 ||
+            strncmp("image/jpeg", imod->get_mimetype(), 10)==0 ||
+            strncmp("image/gif", imod->get_mimetype(), 9)==0 ||
+            strncmp("image/x-icon", imod->get_mimetype(), 12)==0 ||
+            strncmp("image/x-navi-animation", imod->get_mimetype(), 22)==0 ||
+            strncmp("image/x-cmu-raster", imod->get_mimetype(), 18)==0 ||
+            strncmp("image/x-xpixmap", imod->get_mimetype(), 15)==0 ||
+            strncmp("image/bmp", imod->get_mimetype(), 9)==0 ||
+            strncmp("image/vnd.wap.wbmp", imod->get_mimetype(), 18)==0 ||
+            strncmp("image/tiff", imod->get_mimetype(), 10)==0 ||
+            strncmp("image/x-xbitmap", imod->get_mimetype(), 15)==0 ||
+            strncmp("image/x-tga", imod->get_mimetype(), 11)==0 ||
+            strncmp("image/x-pcx", imod->get_mimetype(), 11)==0 
+            ) {
+            if(all_bitmaps_filter.length() > 0)
+                all_bitmaps_filter += ";*";
+            all_bitmaps_filter += file_extension_name;
+        } else {
+            if(all_vectors_filter.length() > 0)
+                all_vectors_filter += ";*";
+            all_vectors_filter += file_extension_name;
+        }
+
         filter_count++;
     }
 
     int extension_index = 0;
     _extension_map = new Inkscape::Extension::Extension*[filter_count];
 
+    // Filter bitmap files
+    all_bitmaps.name = g_utf8_to_utf16(all_bitmaps_filter_name,
+        -1, NULL, &all_bitmaps.name_length, NULL);
+    all_bitmaps.filter = g_utf8_to_utf16(all_bitmaps_filter.data(),
+            -1, NULL, &all_bitmaps.filter_length, NULL);
+       all_bitmaps.mod = NULL;
+    filter_list.push_front(all_bitmaps);
+
+    // Filter vector files
+    all_vectors.name = g_utf8_to_utf16(all_vectors_filter_name,
+        -1, NULL, &all_vectors.name_length, NULL);
+    all_vectors.filter = g_utf8_to_utf16(all_vectors_filter.data(),
+            -1, NULL, &all_vectors.filter_length, NULL);
+       all_vectors.mod = NULL;
+    filter_list.push_front(all_vectors);
+
     // Filter Image Files
     all_image_files.name = g_utf8_to_utf16(all_image_files_filter_name,
         -1, NULL, &all_image_files.name_length, NULL);
@@ -272,7 +314,12 @@ void FileOpenDialogImplWin32::createFilterMenu()
                     all_inkscape_files.filter_length +
                     all_inkscape_files.name_length + 3 +
                     all_image_files.filter_length +
-                    all_image_files.name_length + 3 + 1;
+                    all_image_files.name_length + 3 +
+                    all_vectors.filter_length +
+                    all_vectors.name_length + 3 +
+                    all_bitmaps.filter_length +
+                    all_bitmaps.name_length + 3 +
+                                                  1;
      // Add 3 for 2*2 \0s and a *, and 1 for a trailing \0
 
        _filter = new wchar_t[filter_length];
@@ -561,9 +608,12 @@ LRESULT CALLBACK FileOpenDialogImplWin32::preview_wnd_proc(HWND hwnd, UINT uMsg,
 
             if(pImpl->_path_string[0] == 0)
             {
+                WCHAR* noFileText=(WCHAR*)g_utf8_to_utf16(_("No file selected"),
+                    -1, NULL, NULL, NULL);
                 FillRect(dc, &rcClient, (HBRUSH)(COLOR_3DFACE + 1));
-                DrawText(dc, _("No file selected"), -1, &rcClient,
+                DrawTextW(dc,  noFileText, -1, &rcClient, 
                     DT_CENTER | DT_VCENTER | DT_NOPREFIX);
+                g_free(noFileText);
             }
             else if(pImpl->_preview_bitmap != NULL)
             {
@@ -866,10 +916,10 @@ bool FileOpenDialogImplWin32::set_svg_preview()
     NRRectL bbox = {0, 0, scaledSvgWidth, scaledSvgHeight};
 
     // write object bbox to area
-    boost::optional<NR::Rect> maybeArea(from_2geom(area));
+    Geom::OptRect maybeArea(area);
     sp_document_ensure_up_to_date (svgDoc);
     sp_item_invoke_bbox((SPItem *) svgDoc->root, maybeArea,
-        sp_item_i2r_affine((SPItem *)(svgDoc->root)), TRUE);
+        sp_item_i2d_affine((SPItem *)(svgDoc->root)), TRUE);
 
     NRArena *const arena = NRArena::create();
 
@@ -1447,8 +1497,10 @@ FileSaveDialogImplWin32::FileSaveDialogImplWin32(Gtk::Window &parent,
             FileDialogType fileTypes,
             const char *title,
             const Glib::ustring &/*default_key*/,
-            const char *docTitle) :
-    FileDialogBaseWin32(parent, dir, title, fileTypes, "dialogs.save_as"),
+            const char *docTitle,
+            const Inkscape::Extension::FileSaveMethod save_method) :
+    FileDialogBaseWin32(parent, dir, title, fileTypes,
+                        (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) ? "dialogs.save_copy" :  "dialogs.save_as"),
         _title_label(NULL),
         _title_edit(NULL)
 {
@@ -1695,11 +1747,9 @@ UINT_PTR CALLBACK FileSaveDialogImplWin32::GetSaveFileName_hookproc(
     return 0;
 }
 
-}
-}
-}
+} } } // namespace Dialog, UI, Inkscape
 
-#endif
+#endif // ifdef WIN32
 
 /*
   Local Variables:
@@ -1710,4 +1760,4 @@ UINT_PTR CALLBACK FileSaveDialogImplWin32::GetSaveFileName_hookproc(
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :