filedialogimpl-win32.cpp revision c47710c683ff17ff46d18b2027696403930c0a54
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Implementation of native file dialogs for Win32.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Joel Holdsworth
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The Inkscape Organization
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Abhishek Sharma
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright (C) 2004-2008 The Inkscape Organization
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Released under GNU GPL, read the file 'COPYING' for more information
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster//General includes
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster//Inkscape includes
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterusing namespace std;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterusing namespace Glib;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterusing namespace Cairo;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterconst char PreviewWindowClassName[] = "PreviewWnd";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterconst unsigned long MaxPreviewFileSize = 10240; // kB
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster// Windows 2000 version of OPENFILENAMEW
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterustring utf16_to_ustring(const wchar_t *utf16string, int utf16length = -1)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster gchar *utf8string = g_utf16_to_utf8((const gunichar2*)utf16string,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterint sanitizeWindowSizeParam( int size, int delta, int minimum, int fallback )
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_warning( "Window size %d is less than cutoff.", size );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster} // namespace
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*#########################################################################
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster### F I L E D I A L O G B A S E C L A S S
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#########################################################################*/
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterFileDialogBaseWin32::FileDialogBaseWin32(Gtk::Window &parent,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileDialogType type, gchar const* /*preferenceBase*/) :
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _title = (wchar_t*)g_utf8_to_utf16(title, -1, NULL, NULL, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Glib::RefPtr<const Gdk::Window> parentWindow = parent.get_window();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _ownerHwnd = (HWND)gdk_win32_drawable_get_handle((GdkDrawable*)parentWindow->gobj());
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterInkscape::Extension::Extension *FileDialogBaseWin32::getSelectionType()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterGlib::ustring FileDialogBaseWin32::getCurrentDirectory()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*#########################################################################
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster### F I L E O P E N
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#########################################################################*/
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterbool FileOpenDialogImplWin32::_show_preview = true;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructor. Not called directly. Use the factory.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterFileOpenDialogImplWin32::FileOpenDialogImplWin32(Gtk::Window &parent,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileDialogBaseWin32(parent, dir, title, fileTypes, "dialogs.open")
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Initalize to Autodetect
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Set our dialog type (open, import, etc...)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Destructor
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterFileOpenDialogImplWin32::~FileOpenDialogImplWin32()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::createFilterMenu()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Compose the filter string
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Inkscape::Extension::DB::InputList extension_list;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Inkscape::Extension::db.get_input_list(extension_list);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ustring all_inkscape_files_filter, all_image_files_filter, all_vectors_filter, all_bitmaps_filter;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Filter all_files, all_inkscape_files, all_image_files, all_vectors, all_bitmaps;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *all_files_filter_name = _("All Files");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *all_inkscape_files_filter_name = _("All Inkscape Files");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *all_image_files_filter_name = _("All Images");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *all_vectors_filter_name = _("All Vectors");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *all_bitmaps_filter_name = _("All Bitmaps");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Calculate the amount of memory required
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int filter_count = 5; // 5 - one for each filter type
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster current_item != extension_list.end(); ++current_item)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Inkscape::Extension::Input *imod = *current_item;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter.name = g_utf8_to_utf16(_(imod->get_filetypename()),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Extension
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *file_extension_name = imod->get_extension();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter.filter = g_utf8_to_utf16(file_extension_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter.filter_length + 3; // Add 3 for two \0s and a *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Add to the "All Inkscape Files" Entry
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_inkscape_files_filter += file_extension_name;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if( strncmp("image", imod->get_mimetype(), 5) == 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Add to the "All Image Files" Entry
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // I don't know of any other way to define "bitmap" formats other than by listing them
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // if you change it here, do the same change in filedialogimpl-gtkmm
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/png", imod->get_mimetype(), 9)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/jpeg", imod->get_mimetype(), 10)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/gif", imod->get_mimetype(), 9)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/x-icon", imod->get_mimetype(), 12)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/x-navi-animation", imod->get_mimetype(), 22)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/x-cmu-raster", imod->get_mimetype(), 18)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/x-xpixmap", imod->get_mimetype(), 15)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/bmp", imod->get_mimetype(), 9)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/vnd.wap.wbmp", imod->get_mimetype(), 18)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/tiff", imod->get_mimetype(), 10)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/x-xbitmap", imod->get_mimetype(), 15)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/x-tga", imod->get_mimetype(), 11)==0 ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster strncmp("image/x-pcx", imod->get_mimetype(), 11)==0
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _extension_map = new Inkscape::Extension::Extension*[filter_count];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter bitmap files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_bitmaps.name = g_utf8_to_utf16(all_bitmaps_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_bitmaps.filter = g_utf8_to_utf16(all_bitmaps_filter.data(),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter vector files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_vectors.name = g_utf8_to_utf16(all_vectors_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_vectors.filter = g_utf8_to_utf16(all_vectors_filter.data(),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter Image Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_image_files.name = g_utf8_to_utf16(all_image_files_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_image_files.filter = g_utf8_to_utf16(all_image_files_filter.data(),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_image_files.filter_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter Inkscape Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_inkscape_files.name = g_utf8_to_utf16(all_inkscape_files_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_inkscape_files.name_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_inkscape_files.filter = g_utf8_to_utf16(all_inkscape_files_filter.data(),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_inkscape_files.filter_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter All Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_files.name = g_utf8_to_utf16(all_files_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Add 3 for 2*2 \0s and a *, and 1 for a trailing \0
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Executables only
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ustring all_exe_files_filter = "*.exe;*.bat;*.com";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *all_files_filter_name = _("All Files");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *all_exe_files_filter_name = _("All Executable Files");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Calculate the amount of memory required
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int filter_count = 2; // 2 - All Files and All Executable Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _extension_map = new Inkscape::Extension::Extension*[filter_count];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter Executable Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_exe_files.name = g_utf8_to_utf16(all_exe_files_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_exe_files.filter = g_utf8_to_utf16(all_exe_files_filter.data(),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter All Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_files.name = g_utf8_to_utf16(all_files_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Add 3 for 2*2 \0s and a *, and 1 for a trailing \0
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for(list<Filter>::iterator filter_iterator = filter_list.begin();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_iterator != filter_list.end(); ++filter_iterator)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster wcsncpy(filterptr, (wchar_t*)filter.name, filter.name_length);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster wcsncpy(filterptr, (wchar_t*)filter.filter, filter.filter_length);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Associate this input extension with the file type name
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _extension_map[extension_index++] = filter.mod;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _filter_index = 2; // Select the 2nd filter in the list - 2 is NOT the 3rd
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::GetOpenFileName_thread()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WCHAR* current_directory_string = (WCHAR*)g_utf8_to_utf16(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _current_directory.data(), _current_directory.length(),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Copy the selected file name, converting from UTF-8 to UTF-16
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster gunichar2* utf16_path_string = g_utf8_to_utf16(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster wcsncpy(_path_string, (wchar_t*)utf16_path_string, _MAX_PATH);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.lpstrInitialDir = current_directory_string;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_HIDEREADONLY | OFN_ENABLESIZING;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_assert(ofn.nFilterIndex >= 1 && ofn.nFilterIndex <= _filter_count);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _extension = _extension_map[ofn.nFilterIndex - 1];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Copy the selected file name, converting from UTF-16 to UTF-8
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster myFilename = utf16_to_ustring(_path_string, _MAX_PATH);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::register_preview_wnd_class()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterUINT_PTR CALLBACK FileOpenDialogImplWin32::GetOpenFileName_hookproc(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileOpenDialogImplWin32 *pImpl = reinterpret_cast<FileOpenDialogImplWin32*>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Set the pointer to the object
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster OPENFILENAMEW *ofn = reinterpret_cast<OPENFILENAMEW*>(lParam);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SetWindowLongPtr(hdlg, GWLP_USERDATA, ofn->lCustData);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SetWindowLongPtr(hParentWnd, GWLP_USERDATA, ofn->lCustData);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl = reinterpret_cast<FileOpenDialogImplWin32*>(ofn->lCustData);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Make the window a bit wider
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Don't show the preview when opening executable files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MoveWindow(hParentWnd, rcRect.left, rcRect.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MoveWindow(hParentWnd, rcRect.left, rcRect.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Subclass the parent
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_base_window_proc = (WNDPROC)GetWindowLongPtr(hParentWnd, GWLP_WNDPROC);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SetWindowLongPtr(hParentWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(file_dialog_subclass_proc));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Add a button to the toolbar
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_toolbar_wnd = FindWindowEx(hParentWnd, NULL, "ToolbarWindow32", NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_show_preview_button_bitmap = LoadBitmap(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster TBADDBITMAP tbAddBitmap = {NULL, reinterpret_cast<UINT_PTR>(pImpl->_show_preview_button_bitmap)};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int iBitmapIndex = SendMessage(pImpl->_toolbar_wnd,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tbButton.fsState = (pImpl->_show_preview ? TBSTATE_CHECKED : 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SendMessage(pImpl->_toolbar_wnd, TB_ADDBUTTONS, 1, (LPARAM)&tbButton);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Create preview pane
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster 0, 0, 100, 100, hParentWnd, NULL, hInstance, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SetWindowLongPtr(pImpl->_preview_wnd, GWLP_USERDATA, ofn->lCustData);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster OFNOTIFY *pOFNotify = reinterpret_cast<OFNOTIFY*>(lParam);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get the file name
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SendMessage(pOFNotify->hdr.hwndFrom, CDM_GETFILEPATH,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteObject(pImpl->_show_preview_button_bitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Use default dialog behaviour
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterLRESULT CALLBACK FileOpenDialogImplWin32::file_dialog_subclass_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileOpenDialogImplWin32 *pImpl = reinterpret_cast<FileOpenDialogImplWin32*>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster LRESULT lResult = CallWindowProc(pImpl->_base_window_proc, hwnd, uMsg, wParam, lParam);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const bool enable = SendMessage(pImpl->_toolbar_wnd,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterLRESULT CALLBACK FileOpenDialogImplWin32::preview_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileOpenDialogImplWin32 *pImpl = reinterpret_cast<FileOpenDialogImplWin32*>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Do nothing to erase the background
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // - otherwise there'll be flicker
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get the client rect
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Prepare to paint
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HFONT hCaptionFont = reinterpret_cast<HFONT>(SendMessage(GetParent(hwnd),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HFONT hOldFont = static_cast<HFONT>(SelectObject(dc, hCaptionFont));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WCHAR* noFileText=(WCHAR*)g_utf8_to_utf16(_("No file selected"),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FillRect(dc, &rcClient, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetObject(pImpl->_preview_bitmap, sizeof(bitmap), &bitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int destX = (rcClient.right - bitmap.bmWidth) / 2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Render the image
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HBITMAP hOldBitmap = (HBITMAP)SelectObject(hSrcDC, pImpl->_preview_bitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster BitBlt(dc, destX, 0, bitmap.bmWidth, bitmap.bmHeight,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Fill in the background area
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HRGN hEraseRgn = CreateRectRgn(rcClient.left, rcClient.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster CombineRgn(hEraseRgn, hEraseRgn, hImageRgn, RGN_DIFF);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FillRgn(dc, hEraseRgn, GetSysColorBrush(COLOR_3DFACE));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the caption on
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcClient.top + bitmap.bmHeight + CaptionPadding,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DrawTextW(dc, szCaption, iLength, &rcCaptionRect,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DT_CENTER | DT_TOP | DT_NOPREFIX | DT_PATH_ELLIPSIS);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FillRect(dc, &rcClient, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the files icon
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int destX = (rcClient.right - IconSize) / 2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DrawIconEx(dc, destX, 0, pImpl->_preview_file_icon,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the caption on
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WCHAR szFileName[_MAX_FNAME], szCaption[_MAX_FNAME + 32];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _wsplitpath(pImpl->_path_string, NULL, NULL, szFileName, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DrawTextW(dc, szCaption, iLength, &rcCaptionRect,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DT_CENTER | DT_TOP | DT_NOPREFIX | DT_PATH_ELLIPSIS);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Can't show anything!
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FillRect(dc, &rcClient, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Finish painting
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster lResult = DefWindowProc(hwnd, uMsg, wParam, lParam);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::enable_preview(bool enable)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Relayout the dialog
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ShowWindow(_preview_wnd, enable ? SW_SHOW : SW_HIDE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Load or unload the preview
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Re-layout the dialog
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HWND hFileListWnd = GetDlgItem(_file_dialog_wnd, lst2);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HWND hFolderComboWnd = GetDlgItem(_file_dialog_wnd, cmb2);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetWindowRect(hFolderComboWnd, &rcFolderComboRect);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int iPadding = rcFileList.r.top - rcFolderComboRect.bottom;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MapWindowPoints(NULL, _file_dialog_wnd, rcFileList.p, 2);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rcBody = {rcFileList.r.left, rcFileList.r.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcClient.right - iPadding, rcFileList.r.bottom};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcPreview.left = rcClient.right - (rcBody.bottom - rcBody.top);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int iMaxExtent = (int)(MaxExtentScale * (float)(rcBody.left + rcBody.right)) + iPadding / 2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(rcPreview.left < iMaxExtent) rcPreview.left = iMaxExtent;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Re-layout the preview box
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_width = rcPreview.right - rcPreview.left;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_height = rcPreview.bottom - rcPreview.top;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MoveWindow(_preview_wnd, rcPreview.left, rcPreview.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcFileList.r.right = rcPreview.left - iPadding;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Re-layout the file list box
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MoveWindow(hFileListWnd, rcFileList.r.left, rcFileList.r.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Re-layout the toolbar
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MapWindowPoints(NULL, _file_dialog_wnd, rcToolBar.p, 2);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MoveWindow(_toolbar_wnd, rcToolBar.r.left, rcToolBar.r.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcToolBar.r.right - rcToolBar.r.left, rcToolBar.r.bottom - rcToolBar.r.top, TRUE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Destroy any previous previews
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Determine if the file exists
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD attributes = GetFileAttributesW(_path_string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Check the file exists and get the file size
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HANDLE file_handle = CreateFileW(_path_string, GENERIC_READ,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(file_handle == INVALID_HANDLE_VALUE) return;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const DWORD file_size = GetFileSize(file_handle, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Destroy any previous previews
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Try to get the file icon
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(SUCCEEDED(SHGetFileInfoW(_path_string, 0, &fileInfo,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster sizeof(fileInfo), SHGFI_ICON | SHGFI_LARGEICON)))
0cd8368ca65c58915ee90bc73d84e65f3da9e120Mark de Reeper // Will this file be too big?
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Prepare to render a preview
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring path = utf16_to_ustring(_path_string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bool success = false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_document_width = _preview_document_height = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (hasSuffix(path, svg) || hasSuffix(path, svgz)))
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else if (hasSuffix(path, emf) || hasSuffix(path, wmf))
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Show no preview
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // NOTE: it's not worth the effort to fix this to use Cairo.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Native file dialogs are unmaintainable and should be removed anyway.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster gchar *utf8string = g_utf16_to_utf8((const gunichar2*)_path_string,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SPDocument *svgDoc = SPDocument::createNewDoc (utf8string, true);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Check the document loaded properly
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get the size of the document
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Find the minimum scale to fit the image inside the preview area
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaleFactorX = PreviewSize / svgWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaleFactorY = PreviewSize / svgHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaleFactor = (scaleFactorX > scaleFactorY) ? scaleFactorY : scaleFactorX;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Now get the resized values
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaledSvgWidth = scaleFactor * svgWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaledSvgHeight = scaleFactor * svgHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Geom::Rect area(Geom::Point(0, 0), Geom::Point(scaledSvgWidth, scaledSvgHeight));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NRRectL areaL = {0, 0, scaledSvgWidth, scaledSvgHeight};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NRRectL bbox = {0, 0, scaledSvgWidth, scaledSvgHeight};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // write object bbox to area
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Geom::OptRect maybeArea = area | svgDoc->getRoot()->desktopVisualBounds();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster unsigned const key = SPItem::display_key_new(1);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NRArenaItem *root = svgDoc->getRoot()->invoke_show(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster gc.transform = Geom::Affine(Geom::Scale(scaleFactor, scaleFactor));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Prepare a GDI compatible NRPixBlock
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pixBlock.visible_area.x0 = pixBlock.area.x0 = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pixBlock.visible_area.y0 = pixBlock.area.y0 = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pixBlock.visible_area.x1 = pixBlock.area.x1 = scaledSvgWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pixBlock.visible_area.y1 = pixBlock.area.y1 = scaledSvgHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pixBlock.rs = 4 * ((3 * (int)scaledSvgWidth + 3) / 4);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pixBlock.data.px = g_try_new (unsigned char, pixBlock.rs * scaledSvgHeight);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Fail if the pixblock failed to allocate
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster memset(pixBlock.data.px, 0xFF, pixBlock.rs * scaledSvgHeight);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Render the image
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster nr_arena_item_invoke_render(NULL, root, &bbox, &pixBlock, /*0*/NR_ARENA_ITEM_RENDER_NO_CACHE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Create the GDK pixbuf
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_bitmap_image = Gdk::Pixbuf::create_from_data(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pixBlock.data.px, Gdk::COLORSPACE_RGB, false, 8,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (int)scaledSvgWidth, (int)scaledSvgHeight, pixBlock.rs,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return true;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::destroy_svg_rendering(const guint8 *buffer)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterbool FileOpenDialogImplWin32::set_image_preview()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring path = utf16_to_ustring(_path_string, _MAX_PATH);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_bitmap_image = Gdk::Pixbuf::create_from_file(path);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_image_width = _preview_bitmap_image->get_width();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_document_width = _preview_image_width;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_image_height = _preview_bitmap_image->get_height();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_document_height = _preview_image_height;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster// Aldus Placeable Header ===================================================
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster// Since we are a 32bit app, we have to be sure this structure compiles to
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster// be identical to a 16 bit app's version. To do this, we use the #pragma
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster// to adjust packing, we use a WORD for the hmf handle, and a SMALL_RECT
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster// for the bbox rectangle.
41a9970725e78d29b2f5e82518e354ce972cec53Mark de Reepertypedef struct
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Try open as Enhanced Metafile
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Try open as Windows Metafile
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD dw = GetShortPathNameW( filename, szTemp, MAX_PATH );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Convert Windows Metafile to Enhanced Metafile
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD nSize = GetMetaFileBitsEx( hmf, 0, NULL );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD dw = GetMetaFileBitsEx( hmf, nSize, lpvData );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Fill out a METAFILEPICT structure
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get a reference DC
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Make an enhanced metafile from the windows metafile
882df6887ad52745d38d9bf0d92b3ac6f7703126Peter Major hemf = SetWinMetaFileBits( nSize, lpvData, hDC, &mp );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Try open as Aldus Placeable Metafile
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hFile = CreateFileW( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD dw = ReadFile( hFile, lpvData, nSize, &nSize, NULL );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ( ((PAPMHEADER)lpvData)->dwKey == 0x9ac6cdd7l ) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Fill out a METAFILEPICT structure
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mp.xExt = ((PAPMHEADER)lpvData)->bbox.Right - ((PAPMHEADER)lpvData)->bbox.Left;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mp.xExt = ( mp.xExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mp.yExt = ((PAPMHEADER)lpvData)->bbox.Bottom - ((PAPMHEADER)lpvData)->bbox.Top;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mp.yExt = ( mp.yExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get a reference DC
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Create an enhanced metafile from the bits
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hemf = SetWinMetaFileBits( nSize, lpvData+sizeof(APMHEADER), hDC, &mp );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HENHMETAFILE hemf = MyGetEnhMetaFileW( _path_string );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ok = GetEnhMetaFileHeader(hemf, sizeof(emh), &emh) != 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get the size of the document
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double emfWidth = w;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double emfHeight = h;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Find the minimum scale to fit the image inside the preview area
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaleFactorX = PreviewSize / emfWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaleFactorY = PreviewSize / emfHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaleFactor = (scaleFactorX > scaleFactorY) ? scaleFactorY : scaleFactorX;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Now get the resized values
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaledEmfWidth = scaleFactor * emfWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaledEmfHeight = scaleFactor * emfHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster double x, y;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Is the preview showing?
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Do we have anything to render?
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(!_preview_bitmap_image && !_preview_emf_image)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Tidy up any previous bitmap renderings
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Calculate the size of the caption
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DrawTextW(dc, szCaption, iLength, &rcCaptionRect,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DT_CENTER | DT_TOP | DT_NOPREFIX | DT_PATH_ELLIPSIS | DT_CALCRECT);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster captionHeight = rcCaptionRect.bottom - rcCaptionRect.top;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Find the minimum scale to fit the image inside the preview area
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaleFactorX =
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ((double)_preview_width - pagePadding * 2 - blurRadius) / _preview_document_width;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaleFactorY =
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster - shaddowOffsetY - halfBlurRadius - captionHeight) / _preview_document_height;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster double scaleFactor = (scaleFactorX > scaleFactorY) ? scaleFactorY : scaleFactorX;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster scaleFactor = (scaleFactor > 1.0) ? 1.0 : scaleFactor;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Now get the resized values
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaledSvgWidth = scaleFactor * _preview_document_width;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaledSvgHeight = scaleFactor * _preview_document_height;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int frameWidth = scaledSvgWidth + pagePadding * 2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int frameHeight = scaledSvgHeight + pagePadding * 2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int totalWidth = (int)ceil(frameWidth + blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int totalHeight = (int)ceil(frameHeight + blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Prepare the drawing surface
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_bitmap = CreateCompatibleBitmap(hDC, totalWidth, totalHeight);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, _preview_bitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<Win32Surface> surface = Win32Surface::create(hMemDC);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<Context> context = Context::create(surface);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Paint the background to match the dialog colour
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const COLORREF background = GetSysColor(COLOR_3DFACE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster //----- Draw the drop shaddow -----//
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Left Edge
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<LinearGradient> leftEdgeFade = LinearGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster leftEdgeFade->add_color_stop_rgba (0, 0, 0, 0, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster leftEdgeFade->add_color_stop_rgba (1, 0, 0, 0, shaddowAlpha);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (x, frameY + shaddowOffsetY + halfBlurRadius,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Right Edge
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x = frameX + frameWidth + shaddowOffsetX - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<LinearGradient> rightEdgeFade = LinearGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rightEdgeFade->add_color_stop_rgba (0, 0, 0, 0, shaddowAlpha);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rightEdgeFade->add_color_stop_rgba (1, 0, 0, 0, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (frameX + frameWidth + shaddowOffsetX - halfBlurRadius,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<LinearGradient> topEdgeFade = LinearGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster topEdgeFade->add_color_stop_rgba (0, 0, 0, 0, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster topEdgeFade->add_color_stop_rgba (1, 0, 0, 0, shaddowAlpha);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (frameX + shaddowOffsetX + halfBlurRadius, y,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Bottom Edge
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster y = frameY + frameHeight + shaddowOffsetY - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<LinearGradient> bottomEdgeFade = LinearGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bottomEdgeFade->add_color_stop_rgba (0, 0, 0, 0, shaddowAlpha);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bottomEdgeFade->add_color_stop_rgba (1, 0, 0, 0, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (frameX + shaddowOffsetX + halfBlurRadius, y,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Top Left Corner
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<RadialGradient> topLeftCornerFade = RadialGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x + blurRadius, y + blurRadius, 0, x + blurRadius, y + blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster topLeftCornerFade->add_color_stop_rgba (0, 0, 0, 0, shaddowAlpha);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster topLeftCornerFade->add_color_stop_rgba (1, 0, 0, 0, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (x, y, blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Top Right Corner
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x = frameX + frameWidth + shaddowOffsetX - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<RadialGradient> topRightCornerFade = RadialGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x, y + blurRadius, 0, x, y + blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster topRightCornerFade->add_color_stop_rgba (0, 0, 0, 0, shaddowAlpha);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster topRightCornerFade->add_color_stop_rgba (1, 0, 0, 0, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (x, y, blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Bottom Left Corner
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster y = frameY + frameHeight + shaddowOffsetY - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<RadialGradient> bottomLeftCornerFade = RadialGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x + blurRadius, y, 0, x + blurRadius, y, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bottomLeftCornerFade->add_color_stop_rgba (0, 0, 0, 0, shaddowAlpha);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bottomLeftCornerFade->add_color_stop_rgba (1, 0, 0, 0, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (x, y, blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Bottom Right Corner
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x = frameX + frameWidth + shaddowOffsetX - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster y = frameY + frameHeight + shaddowOffsetY - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<RadialGradient> bottomRightCornerFade = RadialGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x, y, 0, x, y, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bottomRightCornerFade->add_color_stop_rgba (0, 0, 0, 0, shaddowAlpha);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bottomRightCornerFade->add_color_stop_rgba (1, 0, 0, 0, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (frameX + frameWidth + shaddowOffsetX - halfBlurRadius,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster frameY + frameHeight + shaddowOffsetY - halfBlurRadius,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the frame
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (frameX, frameY, frameWidth, frameHeight);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the image
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_preview_bitmap_image) // Is the image a pixbuf?
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Set the transformation
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Render the image
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster set_source_pixbuf (context, _preview_bitmap_image, 0, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Reset the transformation
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the inner frame
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (svgX, svgY, scaledSvgWidth, scaledSvgHeight);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Finish drawing
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HENHMETAFILE hemf = MyGetEnhMetaFileW(_path_string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Refresh the preview pane
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterint FileOpenDialogImplWin32::format_caption(wchar_t *caption, int caption_size)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _wsplitpath(_path_string, NULL, NULL, szFileName, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster L"%s\n%d kB\n%d \xD7 %d", szFileName, _preview_file_size,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (int)_preview_document_width, (int)_preview_document_height);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Show this dialog modally. Return true if user hits [OK]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // We can only run one worker thread at a time
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _main_loop = g_main_loop_new(g_main_context_default(), FALSE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(Glib::Thread::create(sigc::mem_fun(*this, &FileOpenDialogImplWin32::GetOpenFileName_thread), true))
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_main_context_iteration(g_main_context_default(), FALSE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Read mutexed data
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * To Get Multiple filenames selected at-once.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstd::vector<Glib::ustring>FileOpenDialogImplWin32::getFilenames()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*#########################################################################
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster### F I L E S A V E
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#########################################################################*/
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructor
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterFileSaveDialogImplWin32::FileSaveDialogImplWin32(Gtk::Window &parent,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Inkscape::Extension::FileSaveMethod save_method) :
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileDialogBaseWin32(parent, dir, title, fileTypes,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) ? "dialogs.save_copy" : "dialogs.save_as"),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* The code below sets the default file name */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // leaving a trailing backslash on the directory name leads to the infamous
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // double-directory bug on win32
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Remove the extension: remove everything past the last period found past the last slash
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster size_t last_slash_index = udir.find_last_of( '\\' );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster size_t last_period_index = udir.find_last_of( '.' );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster myFilename = udir.substr(0, last_period_index );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // remove one slash if double
33fc82147580d6f2d1299f6282e1cf8a28212bc5Peter Major myFilename.replace(myFilename.find("\\\\",2), 1, "");
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter MajorFileSaveDialogImplWin32::~FileSaveDialogImplWin32()
5bdd6bf9211505ff52afc7e32bdc49cdfacf4879Charles Sparey // Compose the filter string
5bdd6bf9211505ff52afc7e32bdc49cdfacf4879Charles Sparey Glib::ustring all_inkscape_files_filter, all_image_files_filter;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Inkscape::Extension::DB::OutputList extension_list;
int filter_count = 0;
filter_count++;
int extension_index = 0;
*(filterptr++) = 0;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_ENABLESIZING;
_result = false;
if(Glib::Thread::create(sigc::mem_fun(*this, &FileSaveDialogImplWin32::GetSaveFileName_thread), true))
if(_result)
return _result;
switch(uiMsg)
case WM_INITDIALOG:
if ( ydelta < 0 ) {
ydelta = 0;
// Note: we have a width delta of 1 because there is a suspicion that MoveWindow() to the same size causes zero-width results.
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);
case WM_DESTROY:
delete[] temp_title;