Code

Win32 post-GSoC fixups.
[inkscape.git] / src / ui / dialog / filedialogimpl-win32.cpp
index 2196ef0de4091acde803385591acc35def231f8e..ca3a995616d6cdba73480d79e0f16899569fc76b 100644 (file)
@@ -4,6 +4,7 @@
 /* Authors:
  *   Joel Holdsworth
  *   The Inkscape Organization
+ *   Abhishek Sharma
  *
  * Copyright (C) 2004-2008 The Inkscape Organization
  *
@@ -59,9 +60,13 @@ namespace UI
 namespace Dialog
 {
 
-const int PreviewWidening = 150;
+const int PREVIEW_WIDENING = 150;
+const int WINDOW_WIDTH_MINIMUM = 32;
+const int WINDOW_WIDTH_FALLBACK = 450;
+const int WINDOW_HEIGHT_MINIMUM = 32;
+const int WINDOW_HEIGHT_FALLBACK = 360;
 const char PreviewWindowClassName[] = "PreviewWnd";
-const unsigned long MaxPreviewFileSize = 1344; // kB
+const unsigned long MaxPreviewFileSize = 10240; // kB
 
 #define IDC_SHOW_PREVIEW    1000
 
@@ -91,6 +96,21 @@ ustring utf16_to_ustring(const wchar_t *utf16string, int utf16length = -1)
     return result;
 }
 
+namespace {
+
+int sanitizeWindowSizeParam( int size, int delta, int minimum, int fallback )
+{
+    int result = size;
+    if ( size < minimum ) {
+        g_warning( "Window size %d is less than cutoff.", size );
+        result = fallback - delta;
+    }
+    result += delta;
+    return result;
+}
+
+} // namespace
+
 /*#########################################################################
 ### F I L E     D I A L O G    B A S E    C L A S S
 #########################################################################*/
@@ -193,11 +213,11 @@ void FileOpenDialogImplWin32::createFilterMenu()
     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 Images");
-    const gchar *all_vectors_filter_name = N_("All Vectors");
-    const gchar *all_bitmaps_filter_name = N_("All Bitmaps");
+    const gchar *all_files_filter_name = _("All Files");
+    const gchar *all_inkscape_files_filter_name = _("All Inkscape Files");
+    const gchar *all_image_files_filter_name = _("All Images");
+    const gchar *all_vectors_filter_name = _("All Vectors");
+    const gchar *all_bitmaps_filter_name = _("All Bitmaps");
 
     // Calculate the amount of memory required
     int filter_count = 5;       // 5 - one for each filter type
@@ -443,9 +463,9 @@ UINT_PTR CALLBACK FileOpenDialogImplWin32::GetOpenFileName_hookproc(
             RECT rcRect;
             GetWindowRect(hParentWnd, &rcRect);
             MoveWindow(hParentWnd, rcRect.left, rcRect.top,
-                rcRect.right - rcRect.left + PreviewWidening,
-                rcRect.bottom - rcRect.top,
-                FALSE);
+                       rcRect.right - rcRect.left + PREVIEW_WIDENING,
+                       rcRect.bottom - rcRect.top,
+                       FALSE);
 
             // Set the pointer to the object
             OPENFILENAMEW *ofn = (OPENFILENAMEW*)lParam;
@@ -454,15 +474,15 @@ UINT_PTR CALLBACK FileOpenDialogImplWin32::GetOpenFileName_hookproc(
             pImpl = (FileOpenDialogImplWin32*)ofn->lCustData;
 
             // Subclass the parent
-            pImpl->_base_window_proc = (WNDPROC)GetWindowLongPtr(hParentWnd, GWL_WNDPROC);
-            SetWindowLongPtr(hParentWnd, GWL_WNDPROC, (LONG_PTR)file_dialog_subclass_proc);
+            pImpl->_base_window_proc = (WNDPROC)GetWindowLongPtr(hParentWnd, GWLP_WNDPROC);
+            SetWindowLongPtr(hParentWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(file_dialog_subclass_proc));
 
             // Add a button to the toolbar
             pImpl->_toolbar_wnd = FindWindowEx(hParentWnd, NULL, "ToolbarWindow32", NULL);
 
             pImpl->_show_preview_button_bitmap = LoadBitmap(
                 hInstance, MAKEINTRESOURCE(IDC_SHOW_PREVIEW));
-            TBADDBITMAP tbAddBitmap = {NULL, (UINT)pImpl->_show_preview_button_bitmap};
+            TBADDBITMAP tbAddBitmap = {NULL, reinterpret_cast<UINT_PTR>(pImpl->_show_preview_button_bitmap)};
             const int iBitmapIndex = SendMessage(pImpl->_toolbar_wnd,
                 TB_ADDBITMAP, 1, (LPARAM)&tbAddBitmap);
 
@@ -887,20 +907,20 @@ bool FileOpenDialogImplWin32::set_svg_preview()
 
     gchar *utf8string = g_utf16_to_utf8((const gunichar2*)_path_string,
         _MAX_PATH, NULL, NULL, NULL);
-    SPDocument *svgDoc = sp_document_new (utf8string, true);
+    SPDocument *svgDoc = SPDocument::createNewDoc (utf8string, true);
     g_free(utf8string);
 
     // Check the document loaded properly
     if(svgDoc == NULL) return false;
     if(svgDoc->root == NULL)
     {
-        sp_document_unref(svgDoc);
+        svgDoc->doUnref();
         return false;
     }
 
     // Get the size of the document
-    const double svgWidth = sp_document_width(svgDoc);
-    const double svgHeight = sp_document_height(svgDoc);
+    const double svgWidth = svgDoc->getWidth();
+    const double svgHeight = svgDoc->getHeight();
 
     // Find the minimum scale to fit the image inside the preview area
     const double scaleFactorX =    PreviewSize / svgWidth;
@@ -917,15 +937,15 @@ bool FileOpenDialogImplWin32::set_svg_preview()
 
     // write object bbox to area
     Geom::OptRect maybeArea(area);
-    sp_document_ensure_up_to_date (svgDoc);
-    sp_item_invoke_bbox((SPItem *) svgDoc->root, maybeArea,
-        sp_item_i2d_affine((SPItem *)(svgDoc->root)), TRUE);
+    svgDoc->ensureUpToDate();
+    static_cast<SPItem *>(svgDoc->root)->invoke_bbox( maybeArea,
+        static_cast<SPItem *>(svgDoc->root)->i2d_affine(), TRUE);
 
     NRArena *const arena = NRArena::create();
 
-    unsigned const key = sp_item_display_key_new(1);
+    unsigned const key = SPItem::display_key_new(1);
 
-    NRArenaItem *root = sp_item_invoke_show((SPItem*)(svgDoc->root),
+    NRArenaItem *root = static_cast<SPItem*>(svgDoc->root)->invoke_show(
         arena, key, SP_ITEM_SHOW_DISPLAY);
 
     NRGC gc(NULL);
@@ -949,7 +969,7 @@ bool FileOpenDialogImplWin32::set_svg_preview()
     // Fail if the pixblock failed to allocate
     if(pixBlock.data.px == NULL)
     {
-        sp_document_unref(svgDoc);
+        svgDoc->doUnref();
         return false;
     }
 
@@ -961,8 +981,8 @@ bool FileOpenDialogImplWin32::set_svg_preview()
     nr_arena_item_invoke_render(NULL, root, &bbox, &pixBlock, /*0*/NR_ARENA_ITEM_RENDER_NO_CACHE);
 
     // Tidy up
-    sp_document_unref(svgDoc);
-    sp_item_invoke_hide((SPItem*)(svgDoc->root), key);
+    svgDoc->doUnref();
+    static_cast<SPItem*>(svgDoc->root)->invoke_hide(key);
     nr_object_unref((NRObject *) arena);
 
     // Create the GDK pixbuf
@@ -1373,10 +1393,10 @@ void FileOpenDialogImplWin32::render_preview()
     if(_preview_bitmap_image)    // Is the image a pixbuf?
     {
         // Set the transformation
-        const Matrix matrix = {
+        const Cairo::Matrix matrix(
             scaleFactor, 0,
             0, scaleFactor,
-            svgX, svgY };
+            svgX, svgY);
         context->set_matrix (matrix);
 
         // Render the image
@@ -1686,12 +1706,19 @@ UINT_PTR CALLBACK FileSaveDialogImplWin32::GetSaveFileName_hookproc(
             GetWindowRect(GetDlgItem(hParentWnd, stc2), &rST);
             GetWindowRect(hdlg, &rROOT);
             int ydelta = rCB1.top - rEDT1.top;
+            if ( ydelta < 0 ) {
+                g_warning("Negative dialog ydelta");
+                ydelta = 0;
+            }
 
             // Make the window a bit longer
+            // Note: we have a width delta of 1 because there is a suspicion that MoveWindow() to the same size causes zero-width results.
             RECT rcRect;
             GetWindowRect(hParentWnd, &rcRect);
-            MoveWindow(hParentWnd, rcRect.left, rcRect.top, rcRect.right - rcRect.left,
-                       rcRect.bottom - rcRect.top + ydelta, FALSE);
+            MoveWindow(hParentWnd, rcRect.left, rcRect.top,
+                       sanitizeWindowSizeParam( rcRect.right - rcRect.left, 1, WINDOW_WIDTH_MINIMUM, WINDOW_WIDTH_FALLBACK ),
+                       sanitizeWindowSizeParam( rcRect.bottom - rcRect.top, ydelta, WINDOW_HEIGHT_MINIMUM, WINDOW_HEIGHT_FALLBACK ),
+                       FALSE);
 
             // It is not necessary to delete stock objects by calling DeleteObject
             HGDIOBJ dlgFont = GetStockObject(DEFAULT_GUI_FONT);
@@ -1760,4 +1787,4 @@ UINT_PTR CALLBACK FileSaveDialogImplWin32::GetSaveFileName_hookproc(
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :