filedialogimpl-win32.cpp revision c47710c683ff17ff46d18b2027696403930c0a54
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter Major/**
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @file
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Implementation of native file dialogs for Win32.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/* Authors:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Joel Holdsworth
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The Inkscape Organization
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Abhishek Sharma
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright (C) 2004-2008 The Inkscape Organization
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Released under GNU GPL, read the file 'COPYING' for more information
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#ifdef WIN32
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#ifdef HAVE_CONFIG_H
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster# include <config.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#endif
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster//General includes
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <list>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <unistd.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/stat.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <errno.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <set>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <gdk/gdkwin32.h>
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter Major#include <glib/gstdio.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <glibmm/i18n.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <gtkmm/window.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster//Inkscape includes
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include "inkscape.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include "dialogs/dialog-events.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include "extension/input.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include "extension/output.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include "extension/db.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster//#include "display/drawing-item.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster//#include "display/drawing.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include "sp-item.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include "display/canvas-arena.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include "filedialog.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include "filedialogimpl-win32.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include "sp-root.h"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <zlib.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <cairomm/win32_surface.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <cairomm/context.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <gdkmm/general.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterusing namespace std;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterusing namespace Glib;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterusing namespace Cairo;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterusing namespace Gdk::Cairo;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosternamespace Inkscape
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosternamespace UI
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosternamespace Dialog
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterconst int PREVIEW_WIDENING = 150;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterconst int WINDOW_WIDTH_MINIMUM = 32;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterconst int WINDOW_WIDTH_FALLBACK = 450;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterconst int WINDOW_HEIGHT_MINIMUM = 32;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterconst int WINDOW_HEIGHT_FALLBACK = 360;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterconst char PreviewWindowClassName[] = "PreviewWnd";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterconst unsigned long MaxPreviewFileSize = 10240; // kB
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#define IDC_SHOW_PREVIEW 1000
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster// Windows 2000 version of OPENFILENAMEW
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstruct OPENFILENAMEEXW : public OPENFILENAMEW {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster void * pvReserved;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD dwReserved;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD FlagsEx;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstruct Filter
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster gunichar2* name;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster glong name_length;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster gunichar2* filter;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster glong filter_length;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Inkscape::Extension::Extension* mod;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterustring utf16_to_ustring(const wchar_t *utf16string, int utf16length = -1)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster gchar *utf8string = g_utf16_to_utf8((const gunichar2*)utf16string,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster utf16length, NULL, NULL, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ustring result(utf8string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_free(utf8string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return result;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosternamespace {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterint sanitizeWindowSizeParam( int size, int delta, int minimum, int fallback )
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int result = size;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ( size < minimum ) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_warning( "Window size %d is less than cutoff.", size );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster result = fallback - delta;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster result += delta;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return result;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster} // namespace
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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 Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterFileDialogBaseWin32::FileDialogBaseWin32(Gtk::Window &parent,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring &dir, const gchar *title,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileDialogType type, gchar const* /*preferenceBase*/) :
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster dialogType(type),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster parent(parent),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _current_directory(dir)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _main_loop = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _filter_index = 1;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _filter_count = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _title = (wchar_t*)g_utf8_to_utf16(title, -1, NULL, NULL, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_assert(_title != NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Glib::RefPtr<const Gdk::Window> parentWindow = parent.get_window();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_assert(parentWindow->gobj() != NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _ownerHwnd = (HWND)gdk_win32_drawable_get_handle((GdkDrawable*)parentWindow->gobj());
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterFileDialogBaseWin32::~FileDialogBaseWin32()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_free(_title);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterInkscape::Extension::Extension *FileDialogBaseWin32::getSelectionType()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return _extension;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterGlib::ustring FileDialogBaseWin32::getCurrentDirectory()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return _current_directory;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*#########################################################################
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster### F I L E O P E N
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#########################################################################*/
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterbool FileOpenDialogImplWin32::_show_preview = true;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/**
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructor. Not called directly. Use the factory.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterFileOpenDialogImplWin32::FileOpenDialogImplWin32(Gtk::Window &parent,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring &dir,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileDialogType fileTypes,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *title) :
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileDialogBaseWin32(parent, dir, title, fileTypes, "dialogs.open")
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Initalize to Autodetect
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _extension = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Set our dialog type (open, import, etc...)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster dialogType = fileTypes;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _show_preview_button_bitmap = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_wnd = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _file_dialog_wnd = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _base_window_proc = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_file_size = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_bitmap = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_file_icon = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_document_width = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_document_height = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_image_width = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_image_height = 0;
87eb3f7fa6a83f2e2682123f21cf20afcdc88f4aPeter Major _preview_emf_image = false;
87eb3f7fa6a83f2e2682123f21cf20afcdc88f4aPeter Major
87eb3f7fa6a83f2e2682123f21cf20afcdc88f4aPeter Major _mutex = NULL;
87eb3f7fa6a83f2e2682123f21cf20afcdc88f4aPeter Major
87eb3f7fa6a83f2e2682123f21cf20afcdc88f4aPeter Major createFilterMenu();
87eb3f7fa6a83f2e2682123f21cf20afcdc88f4aPeter Major}
87eb3f7fa6a83f2e2682123f21cf20afcdc88f4aPeter Major
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/**
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Destructor
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterFileOpenDialogImplWin32::~FileOpenDialogImplWin32()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_filter != NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster delete[] _filter;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_extension_map != NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster delete[] _extension_map;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::createFilterMenu()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster list<Filter> filter_list;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int extension_index = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int filter_length = 1;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (dialogType != EXE_TYPES) {
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
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
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Calculate the amount of memory required
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int filter_count = 5; // 5 - one for each filter type
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster current_item != extension_list.end(); ++current_item)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Filter filter;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Inkscape::Extension::Input *imod = *current_item;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (imod->deactivated()) continue;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Type
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter.name = g_utf8_to_utf16(_(imod->get_filetypename()),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &filter.name_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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 -1, NULL, &filter.filter_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter.mod = imod;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_list.push_back(filter);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_length += filter.name_length +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter.filter_length + 3; // Add 3 for two \0s and a *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Add to the "All Inkscape Files" Entry
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(all_inkscape_files_filter.length() > 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_inkscape_files_filter += ";*";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_inkscape_files_filter += file_extension_name;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if( strncmp("image", imod->get_mimetype(), 5) == 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Add to the "All Image Files" Entry
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(all_image_files_filter.length() > 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_image_files_filter += ";*";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_image_files_filter += file_extension_name;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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 if (
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 ) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(all_bitmaps_filter.length() > 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_bitmaps_filter += ";*";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_bitmaps_filter += file_extension_name;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster } else {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(all_vectors_filter.length() > 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_vectors_filter += ";*";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_vectors_filter += file_extension_name;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_count++;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _extension_map = new Inkscape::Extension::Extension*[filter_count];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter bitmap files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_bitmaps.name = g_utf8_to_utf16(all_bitmaps_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_bitmaps.name_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_bitmaps.filter = g_utf8_to_utf16(all_bitmaps_filter.data(),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_bitmaps.filter_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_bitmaps.mod = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_list.push_front(all_bitmaps);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter vector files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_vectors.name = g_utf8_to_utf16(all_vectors_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_vectors.name_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_vectors.filter = g_utf8_to_utf16(all_vectors_filter.data(),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_vectors.filter_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_vectors.mod = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_list.push_front(all_vectors);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter Image Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_image_files.name = g_utf8_to_utf16(all_image_files_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_image_files.name_length, NULL);
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 all_image_files.mod = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_list.push_front(all_image_files);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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 all_inkscape_files.mod = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_list.push_front(all_inkscape_files);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter All Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_files.name = g_utf8_to_utf16(all_files_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_files.name_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_files.filter = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_files.filter_length = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_files.mod = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_list.push_front(all_files);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_length += all_files.name_length + 3 +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_inkscape_files.filter_length +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_inkscape_files.name_length + 3 +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_image_files.filter_length +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_image_files.name_length + 3 +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_vectors.filter_length +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_vectors.name_length + 3 +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_bitmaps.filter_length +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_bitmaps.name_length + 3 +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster 1;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Add 3 for 2*2 \0s and a *, and 1 for a trailing \0
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster } else {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Executables only
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ustring all_exe_files_filter = "*.exe;*.bat;*.com";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Filter all_exe_files, all_files;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *all_files_filter_name = _("All Files");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const gchar *all_exe_files_filter_name = _("All Executable Files");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Calculate the amount of memory required
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int filter_count = 2; // 2 - All Files and All Executable Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _extension_map = new Inkscape::Extension::Extension*[filter_count];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter Executable Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_exe_files.name = g_utf8_to_utf16(all_exe_files_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_exe_files.name_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_exe_files.filter = g_utf8_to_utf16(all_exe_files_filter.data(),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_exe_files.filter_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_exe_files.mod = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_list.push_front(all_exe_files);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Filter All Files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_files.name = g_utf8_to_utf16(all_files_filter_name,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, &all_files.name_length, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_files.filter = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_files.filter_length = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_files.mod = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_list.push_front(all_files);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_length += all_files.name_length + 3 +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_exe_files.filter_length +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster all_exe_files.name_length + 3 +
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster 1;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Add 3 for 2*2 \0s and a *, and 1 for a trailing \0
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _filter = new wchar_t[filter_length];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster wchar_t *filterptr = _filter;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for(list<Filter>::iterator filter_iterator = filter_list.begin();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filter_iterator != filter_list.end(); ++filter_iterator)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Filter &filter = *filter_iterator;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster wcsncpy(filterptr, (wchar_t*)filter.name, filter.name_length);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filterptr += filter.name_length;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_free(filter.name);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *(filterptr++) = L'\0';
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *(filterptr++) = L'*';
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(filter.filter != NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster wcsncpy(filterptr, (wchar_t*)filter.filter, filter.filter_length);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster filterptr += filter.filter_length;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_free(filter.filter);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *(filterptr++) = L'\0';
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Associate this input extension with the file type name
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _extension_map[extension_index++] = filter.mod;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *(filterptr++) = L'\0';
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _filter_count = extension_index;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _filter_index = 2; // Select the 2nd filter in the list - 2 is NOT the 3rd
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::GetOpenFileName_thread()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster OPENFILENAMEEXW ofn;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_assert(this != NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_assert(_mutex != NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WCHAR* current_directory_string = (WCHAR*)g_utf8_to_utf16(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _current_directory.data(), _current_directory.length(),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NULL, NULL, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster memset(&ofn, 0, sizeof(ofn));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Copy the selected file name, converting from UTF-8 to UTF-16
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster memset(_path_string, 0, sizeof(_path_string));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster gunichar2* utf16_path_string = g_utf8_to_utf16(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster myFilename.data(), -1, NULL, NULL, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster wcsncpy(_path_string, (wchar_t*)utf16_path_string, _MAX_PATH);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_free(utf16_path_string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.lStructSize = sizeof(ofn);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.hwndOwner = _ownerHwnd;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.lpstrFile = _path_string;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.nMaxFile = _MAX_PATH;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.lpstrFileTitle = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.nMaxFileTitle = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.lpstrInitialDir = current_directory_string;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.lpstrTitle = _title;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_HIDEREADONLY | OFN_ENABLESIZING;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.lpstrFilter = _filter;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.nFilterIndex = _filter_index;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.lpfnHook = GetOpenFileName_hookproc;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ofn.lCustData = (LPARAM)this;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _result = GetOpenFileNameW(&ofn) != 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_assert(ofn.nFilterIndex >= 1 && ofn.nFilterIndex <= _filter_count);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _filter_index = ofn.nFilterIndex;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _extension = _extension_map[ofn.nFilterIndex - 1];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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 Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Tidy up
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_free(current_directory_string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _finished = true;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::register_preview_wnd_class()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HINSTANCE hInstance = GetModuleHandle(NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const WNDCLASSA PreviewWndClass =
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster CS_HREDRAW | CS_VREDRAW,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster preview_wnd_proc,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster 0,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster 0,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hInstance,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NULL,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster LoadCursor(hInstance, IDC_ARROW),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (HBRUSH)(COLOR_BTNFACE + 1),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NULL,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster PreviewWindowClassName
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster };
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RegisterClassA(&PreviewWndClass);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterUINT_PTR CALLBACK FileOpenDialogImplWin32::GetOpenFileName_hookproc(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HWND hdlg, UINT uiMsg, WPARAM, LPARAM lParam)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileOpenDialogImplWin32 *pImpl = reinterpret_cast<FileOpenDialogImplWin32*>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (GetWindowLongPtr(hdlg, GWLP_USERDATA));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster switch(uiMsg)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case WM_INITDIALOG:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HWND hParentWnd = GetParent(hdlg);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HINSTANCE hInstance = GetModuleHandle(NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Make the window a bit wider
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rcRect;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetWindowRect(hParentWnd, &rcRect);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Don't show the preview when opening executable files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ( pImpl->dialogType == EXE_TYPES) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MoveWindow(hParentWnd, rcRect.left, rcRect.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcRect.right - rcRect.left,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcRect.bottom - rcRect.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FALSE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster } else {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MoveWindow(hParentWnd, rcRect.left, rcRect.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcRect.right - rcRect.left + PREVIEW_WIDENING,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcRect.bottom - rcRect.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FALSE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ( pImpl->dialogType != EXE_TYPES) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Add a button to the toolbar
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_toolbar_wnd = FindWindowEx(hParentWnd, NULL, "ToolbarWindow32", NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_show_preview_button_bitmap = LoadBitmap(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hInstance, MAKEINTRESOURCE(IDC_SHOW_PREVIEW));
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 TB_ADDBITMAP, 1, (LPARAM)&tbAddBitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster TBBUTTON tbButton;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster memset(&tbButton, 0, sizeof(TBBUTTON));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tbButton.iBitmap = iBitmapIndex;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tbButton.idCommand = IDC_SHOW_PREVIEW;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tbButton.fsState = (pImpl->_show_preview ? TBSTATE_CHECKED : 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | TBSTATE_ENABLED;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tbButton.fsStyle = TBSTYLE_CHECK;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tbButton.iString = (INT_PTR)_("Show Preview");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SendMessage(pImpl->_toolbar_wnd, TB_ADDBUTTONS, 1, (LPARAM)&tbButton);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Create preview pane
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster register_preview_wnd_class();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_file_dialog_wnd = hParentWnd;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ( pImpl->dialogType != EXE_TYPES) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_preview_wnd =
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster CreateWindowA(PreviewWindowClassName, "",
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WS_CHILD | WS_VISIBLE,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster 0, 0, 100, 100, hParentWnd, NULL, hInstance, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SetWindowLongPtr(pImpl->_preview_wnd, GWLP_USERDATA, ofn->lCustData);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->layout_dialog();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case WM_NOTIFY:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster OFNOTIFY *pOFNotify = reinterpret_cast<OFNOTIFY*>(lParam);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster switch(pOFNotify->hdr.code)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case CDN_SELCHANGE:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(pImpl != NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get the file name
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SendMessage(pOFNotify->hdr.hwndFrom, CDM_GETFILEPATH,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster sizeof(pImpl->_path_string) / sizeof(wchar_t),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (LPARAM)pImpl->_path_string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_file_selected = true;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case WM_CLOSE:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_preview_file_size = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_file_dialog_wnd = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DestroyWindow(pImpl->_preview_wnd);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_preview_wnd = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteObject(pImpl->_show_preview_button_bitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_show_preview_button_bitmap = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Use default dialog behaviour
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterLRESULT CALLBACK FileOpenDialogImplWin32::file_dialog_subclass_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileOpenDialogImplWin32 *pImpl = reinterpret_cast<FileOpenDialogImplWin32*>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (GetWindowLongPtr(hwnd, GWLP_USERDATA));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster LRESULT lResult = CallWindowProc(pImpl->_base_window_proc, hwnd, uMsg, wParam, lParam);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster switch(uMsg)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case WM_SHOWWINDOW:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(wParam != 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->layout_dialog();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case WM_SIZE:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->layout_dialog();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case WM_COMMAND:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(wParam == IDC_SHOW_PREVIEW)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const bool enable = SendMessage(pImpl->_toolbar_wnd,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster TB_ISBUTTONCHECKED, IDC_SHOW_PREVIEW, 0) != 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->enable_preview(enable);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return lResult;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterLRESULT CALLBACK FileOpenDialogImplWin32::preview_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int CaptionPadding = 4;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int IconSize = 32;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileOpenDialogImplWin32 *pImpl = reinterpret_cast<FileOpenDialogImplWin32*>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (GetWindowLongPtr(hwnd, GWLP_USERDATA));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster LRESULT lResult = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster switch(uMsg)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case WM_ERASEBKGND:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Do nothing to erase the background
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // - otherwise there'll be flicker
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster lResult = 1;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case WM_PAINT:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get the client rect
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rcClient;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetClientRect(hwnd, &rcClient);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Prepare to paint
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster PAINTSTRUCT paint_struct;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HDC dc = BeginPaint(hwnd, &paint_struct);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HFONT hCaptionFont = reinterpret_cast<HFONT>(SendMessage(GetParent(hwnd),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WM_GETFONT, 0, 0));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HFONT hOldFont = static_cast<HFONT>(SelectObject(dc, hCaptionFont));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SetBkMode(dc, TRANSPARENT);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(pImpl->_path_string[0] == 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WCHAR* noFileText=(WCHAR*)g_utf8_to_utf16(_("No file selected"),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -1, NULL, NULL, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FillRect(dc, &rcClient, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DrawTextW(dc, noFileText, -1, &rcClient,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DT_CENTER | DT_VCENTER | DT_NOPREFIX);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_free(noFileText);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else if(pImpl->_preview_bitmap != NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster BITMAP bitmap;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetObject(pImpl->_preview_bitmap, sizeof(bitmap), &bitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int destX = (rcClient.right - bitmap.bmWidth) / 2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Render the image
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HDC hSrcDC = CreateCompatibleDC(dc);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HBITMAP hOldBitmap = (HBITMAP)SelectObject(hSrcDC, pImpl->_preview_bitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster BitBlt(dc, destX, 0, bitmap.bmWidth, bitmap.bmHeight,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hSrcDC, 0, 0, SRCCOPY);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SelectObject(hSrcDC, hOldBitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteDC(hSrcDC);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Fill in the background area
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HRGN hEraseRgn = CreateRectRgn(rcClient.left, rcClient.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcClient.right, rcClient.bottom);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HRGN hImageRgn = CreateRectRgn(destX, 0,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster destX + bitmap.bmWidth, bitmap.bmHeight);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster CombineRgn(hEraseRgn, hEraseRgn, hImageRgn, RGN_DIFF);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FillRgn(dc, hEraseRgn, GetSysColorBrush(COLOR_3DFACE));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteObject(hImageRgn);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteObject(hEraseRgn);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the caption on
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rcCaptionRect = {rcClient.left,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcClient.top + bitmap.bmHeight + CaptionPadding,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcClient.right, rcClient.bottom};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WCHAR szCaption[_MAX_FNAME + 32];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int iLength = pImpl->format_caption(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster szCaption, sizeof(szCaption) / sizeof(WCHAR));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DrawTextW(dc, szCaption, iLength, &rcCaptionRect,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DT_CENTER | DT_TOP | DT_NOPREFIX | DT_PATH_ELLIPSIS);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else if(pImpl->_preview_file_icon != NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FillRect(dc, &rcClient, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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 IconSize, IconSize, 0, NULL,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DI_NORMAL | DI_COMPAT);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the caption on
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rcCaptionRect = {rcClient.left,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcClient.top + IconSize + CaptionPadding,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcClient.right, rcClient.bottom};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WCHAR szFileName[_MAX_FNAME], szCaption[_MAX_FNAME + 32];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _wsplitpath(pImpl->_path_string, NULL, NULL, szFileName, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int iLength = snwprintf(szCaption,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster sizeof(szCaption), L"%s\n%d kB",
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster szFileName, pImpl->_preview_file_size);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DrawTextW(dc, szCaption, iLength, &rcCaptionRect,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DT_CENTER | DT_TOP | DT_NOPREFIX | DT_PATH_ELLIPSIS);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Can't show anything!
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FillRect(dc, &rcClient, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->_mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Finish painting
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SelectObject(dc, hOldFont);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster EndPaint(hwnd, &paint_struct);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case WM_DESTROY:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pImpl->free_preview();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster default:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster lResult = DefWindowProc(hwnd, uMsg, wParam, lParam);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return lResult;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::enable_preview(bool enable)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _show_preview = enable;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Relayout the dialog
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ShowWindow(_preview_wnd, enable ? SW_SHOW : SW_HIDE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster layout_dialog();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Load or unload the preview
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(enable)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _file_selected = true;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else free_preview();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::layout_dialog()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster union RECTPOINTS
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT r;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster POINT p[2];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster };
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const float MaxExtentScale = 2.0f / 3.0f;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rcClient;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetClientRect(_file_dialog_wnd, &rcClient);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rcFolderComboRect;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECTPOINTS rcFileList;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetWindowRect(hFileListWnd, &rcFileList.r);
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rcPreview;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rcBody = {rcFileList.r.left, rcFileList.r.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcClient.right - iPadding, rcFileList.r.bottom};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcFileList.r.right = rcBody.right;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_show_preview && dialogType != EXE_TYPES)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcPreview.top = rcBody.top;
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 rcPreview.bottom = rcBody.bottom;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcPreview.right = rcBody.right;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Re-layout the preview box
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_width = rcPreview.right - rcPreview.left;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_height = rcPreview.bottom - rcPreview.top;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster render_preview();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MoveWindow(_preview_wnd, rcPreview.left, rcPreview.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_width, _preview_height, TRUE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcFileList.r.right = rcPreview.left - iPadding;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Re-layout the file list box
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster MoveWindow(hFileListWnd, rcFileList.r.left, rcFileList.r.top,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcFileList.r.right - rcFileList.r.left,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rcFileList.r.bottom - rcFileList.r.top, TRUE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Re-layout the toolbar
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECTPOINTS rcToolBar;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetWindowRect(_toolbar_wnd, &rcToolBar.r);
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}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::file_selected()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Destroy any previous previews
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster free_preview();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Determine if the file exists
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD attributes = GetFileAttributesW(_path_string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(attributes == 0xFFFFFFFF ||
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster attributes == FILE_ATTRIBUTE_DIRECTORY)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster InvalidateRect(_preview_wnd, NULL, FALSE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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 if (file_size == INVALID_FILE_SIZE) return;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_file_size = file_size / 1024;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster CloseHandle(file_handle);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_show_preview) load_preview();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::load_preview()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Destroy any previous previews
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster free_preview();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Try to get the file icon
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SHFILEINFOW fileInfo;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(SUCCEEDED(SHGetFileInfoW(_path_string, 0, &fileInfo,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster sizeof(fileInfo), SHGFI_ICON | SHGFI_LARGEICON)))
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_file_icon = fileInfo.hIcon;
0cd8368ca65c58915ee90bc73d84e65f3da9e120Mark de Reeper
0cd8368ca65c58915ee90bc73d84e65f3da9e120Mark de Reeper // Will this file be too big?
0cd8368ca65c58915ee90bc73d84e65f3da9e120Mark de Reeper if(_preview_file_size > MaxPreviewFileSize)
0cd8368ca65c58915ee90bc73d84e65f3da9e120Mark de Reeper {
0cd8368ca65c58915ee90bc73d84e65f3da9e120Mark de Reeper InvalidateRect(_preview_wnd, NULL, FALSE);
0cd8368ca65c58915ee90bc73d84e65f3da9e120Mark de Reeper return;
0cd8368ca65c58915ee90bc73d84e65f3da9e120Mark de Reeper }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Prepare to render a preview
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring svg = ".svg";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring svgz = ".svgz";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring emf = ".emf";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring wmf = ".wmf";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring path = utf16_to_ustring(_path_string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bool success = false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_document_width = _preview_document_height = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (hasSuffix(path, svg) || hasSuffix(path, svgz)))
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster success = set_svg_preview();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else if (hasSuffix(path, emf) || hasSuffix(path, wmf))
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster success = set_emf_preview();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else if (isValidImageFile(path))
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster success = set_image_preview();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Show no preview
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(success) render_preview();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster InvalidateRect(_preview_wnd, NULL, FALSE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::free_preview()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_preview_bitmap != NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteObject(_preview_bitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_bitmap = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_preview_file_icon != NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DestroyIcon(_preview_file_icon);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_file_icon = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_bitmap_image.reset();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_emf_image = false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterbool FileOpenDialogImplWin32::set_svg_preview()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
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 #if 0
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int PreviewSize = 512;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster gchar *utf8string = g_utf16_to_utf8((const gunichar2*)_path_string,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _MAX_PATH, NULL, NULL, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SPDocument *svgDoc = SPDocument::createNewDoc (utf8string, true);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_free(utf8string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Check the document loaded properly
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (svgDoc == NULL) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (svgDoc->getRoot() == NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster svgDoc->doUnref();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get the size of the document
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double svgWidth = svgDoc->getWidth();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double svgHeight = svgDoc->getHeight();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Now get the resized values
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaledSvgWidth = scaleFactor * svgWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaledSvgHeight = scaleFactor * svgHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // write object bbox to area
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster svgDoc->ensureUpToDate();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Geom::OptRect maybeArea = area | svgDoc->getRoot()->desktopVisualBounds();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NRArena *const arena = NRArena::create();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster unsigned const key = SPItem::display_key_new(1);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NRArenaItem *root = svgDoc->getRoot()->invoke_show(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster arena, key, SP_ITEM_SHOW_DISPLAY);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NRGC gc(NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster gc.transform = Geom::Affine(Geom::Scale(scaleFactor, scaleFactor));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster nr_arena_item_invoke_update (root, NULL, &gc,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Prepare a GDI compatible NRPixBlock
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NRPixBlock pixBlock;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pixBlock.size = NR_PIXBLOCK_SIZE_BIG;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pixBlock.mode = NR_PIXBLOCK_MODE_R8G8B8;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pixBlock.empty = 1;
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Fail if the pixblock failed to allocate
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(pixBlock.data.px == NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster svgDoc->doUnref();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster memset(pixBlock.data.px, 0xFF, pixBlock.rs * scaledSvgHeight);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster memcpy(&root->bbox, &areaL, sizeof(areaL));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Tidy up
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster svgDoc->doUnref();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster svgDoc->getRoot()->invoke_hide(key);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster nr_object_unref((NRObject *) arena);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Create the GDK pixbuf
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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 sigc::ptr_fun(destroy_svg_rendering));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_document_width = scaledSvgWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_document_height = scaledSvgHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_image_width = svgWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_image_height = svgHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return true;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster #endif
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::destroy_svg_rendering(const guint8 *buffer)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_assert(buffer != NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_free((void*)buffer);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterbool FileOpenDialogImplWin32::set_image_preview()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring path = utf16_to_ustring(_path_string, _MAX_PATH);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster bool successful = false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster try {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_bitmap_image = Gdk::Pixbuf::create_from_file(path);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (_preview_bitmap_image) {
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 successful = true;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster catch (const Gdk::PixbufError&) {}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster catch (const Glib::FileError&) {}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return successful;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#pragma pack( push )
41a9970725e78d29b2f5e82518e354ce972cec53Mark de Reeper#pragma pack( 2 )
41a9970725e78d29b2f5e82518e354ce972cec53Mark de Reepertypedef struct
41a9970725e78d29b2f5e82518e354ce972cec53Mark de Reeper{
41a9970725e78d29b2f5e82518e354ce972cec53Mark de Reeper DWORD dwKey;
41a9970725e78d29b2f5e82518e354ce972cec53Mark de Reeper WORD hmf;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SMALL_RECT bbox;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WORD wInch;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD dwReserved;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WORD wCheckSum;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster} APMHEADER, *PAPMHEADER;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#pragma pack( pop )
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic HENHMETAFILE
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterMyGetEnhMetaFileW( const WCHAR *filename )
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Try open as Enhanced Metafile
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HENHMETAFILE hemf = GetEnhMetaFileW(filename);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (!hemf) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Try open as Windows Metafile
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HMETAFILE hmf = GetMetaFileW(filename);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster METAFILEPICT mp;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HDC hDC;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (!hmf) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WCHAR szTemp[MAX_PATH];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD dw = GetShortPathNameW( filename, szTemp, MAX_PATH );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (dw) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hmf = GetMetaFileW( szTemp );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (hmf) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Convert Windows Metafile to Enhanced Metafile
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD nSize = GetMetaFileBitsEx( hmf, 0, NULL );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (nSize) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster BYTE *lpvData = new BYTE[nSize];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (lpvData) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD dw = GetMetaFileBitsEx( hmf, nSize, lpvData );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (dw) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Fill out a METAFILEPICT structure
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mp.mm = MM_ANISOTROPIC;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mp.xExt = 1000;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mp.yExt = 1000;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mp.hMF = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get a reference DC
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hDC = GetDC( NULL );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Make an enhanced metafile from the windows metafile
882df6887ad52745d38d9bf0d92b3ac6f7703126Peter Major hemf = SetWinMetaFileBits( nSize, lpvData, hDC, &mp );
882df6887ad52745d38d9bf0d92b3ac6f7703126Peter Major // Clean up
882df6887ad52745d38d9bf0d92b3ac6f7703126Peter Major ReleaseDC( NULL, hDC );
882df6887ad52745d38d9bf0d92b3ac6f7703126Peter Major DeleteMetaFile( hmf );
882df6887ad52745d38d9bf0d92b3ac6f7703126Peter Major }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster delete[] lpvData;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteMetaFile( hmf );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteMetaFile( hmf );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster else {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Try open as Aldus Placeable Metafile
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HANDLE hFile;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hFile = CreateFileW( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (hFile != INVALID_HANDLE_VALUE) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD nSize = GetFileSize( hFile, NULL );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (nSize) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster BYTE *lpvData = new BYTE[nSize];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (lpvData) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD dw = ReadFile( hFile, lpvData, nSize, &nSize, NULL );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (dw) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ( ((PAPMHEADER)lpvData)->dwKey == 0x9ac6cdd7l ) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Fill out a METAFILEPICT structure
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mp.mm = MM_ANISOTROPIC;
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 mp.hMF = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get a reference DC
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hDC = GetDC( NULL );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Create an enhanced metafile from the bits
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hemf = SetWinMetaFileBits( nSize, lpvData+sizeof(APMHEADER), hDC, &mp );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Clean up
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ReleaseDC( NULL, hDC );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster delete[] lpvData;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster CloseHandle( hFile );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return hemf;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterbool FileOpenDialogImplWin32::set_emf_preview()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster BOOL ok = FALSE;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD w = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DWORD h = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HENHMETAFILE hemf = MyGetEnhMetaFileW( _path_string );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (hemf)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ENHMETAHEADER emh;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ZeroMemory(&emh, sizeof(emh));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ok = GetEnhMetaFileHeader(hemf, sizeof(emh), &emh) != 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster w = (emh.rclFrame.right - emh.rclFrame.left);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster h = (emh.rclFrame.bottom - emh.rclFrame.top);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteEnhMetaFile(hemf);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (ok)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int PreviewSize = 512;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Get the size of the document
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double emfWidth = w;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double emfHeight = h;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Now get the resized values
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaledEmfWidth = scaleFactor * emfWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double scaledEmfHeight = scaleFactor * emfHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_document_width = scaledEmfWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_document_height = scaledEmfHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_image_width = emfWidth;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_image_height = emfHeight;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_emf_image = true;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return ok;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid FileOpenDialogImplWin32::render_preview()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster double x, y;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double blurRadius = 8;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double halfBlurRadius = blurRadius / 2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int shaddowOffsetX = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int shaddowOffsetY = 2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int pagePadding = 5;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const double shaddowAlpha = 0.75;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Is the preview showing?
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(!_show_preview)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Do we have anything to render?
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->lock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(!_preview_bitmap_image && !_preview_emf_image)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Tidy up any previous bitmap renderings
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_preview_bitmap != NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteObject(_preview_bitmap);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _preview_bitmap = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Calculate the size of the caption
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int captionHeight = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_preview_wnd != NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rcCaptionRect;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster WCHAR szCaption[_MAX_FNAME + 32];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int iLength = format_caption(szCaption,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster sizeof(szCaption) / sizeof(WCHAR));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HDC dc = GetDC(_preview_wnd);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DrawTextW(dc, szCaption, iLength, &rcCaptionRect,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DT_CENTER | DT_TOP | DT_NOPREFIX | DT_PATH_ELLIPSIS | DT_CALCRECT);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ReleaseDC(_preview_wnd, dc);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster captionHeight = rcCaptionRect.bottom - rcCaptionRect.top;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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 ((double)_preview_height - pagePadding * 2
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
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int svgX = pagePadding + halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int svgY = pagePadding;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int frameX = svgX - pagePadding;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int frameY = svgY - pagePadding;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int frameWidth = scaledSvgWidth + pagePadding * 2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int frameHeight = scaledSvgHeight + pagePadding * 2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int totalWidth = (int)ceil(frameWidth + blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const int totalHeight = (int)ceil(frameHeight + blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Prepare the drawing surface
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HDC hDC = GetDC(_preview_wnd);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HDC hMemDC = CreateCompatibleDC(hDC);
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
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Paint the background to match the dialog colour
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const COLORREF background = GetSysColor(COLOR_3DFACE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->set_source_rgb(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetRValue(background) / 255.0,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetGValue(background) / 255.0,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster GetBValue(background) / 255.0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->paint();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster //----- Draw the drop shaddow -----//
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Left Edge
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x = frameX + shaddowOffsetX - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<LinearGradient> leftEdgeFade = LinearGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x, 0.0, x + blurRadius, 0.0);
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->set_source(leftEdgeFade);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (x, frameY + shaddowOffsetY + halfBlurRadius,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster blurRadius, frameHeight - blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->fill();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Right Edge
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x = frameX + frameWidth + shaddowOffsetX - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<LinearGradient> rightEdgeFade = LinearGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x, 0.0, x + blurRadius, 0.0);
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->set_source(rightEdgeFade);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (frameX + frameWidth + shaddowOffsetX - halfBlurRadius,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster frameY + shaddowOffsetY + halfBlurRadius,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster blurRadius, frameHeight - blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->fill();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Top Edge
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster y = frameY + shaddowOffsetY - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<LinearGradient> topEdgeFade = LinearGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster 0.0, y, 0.0, y + blurRadius);
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->set_source(topEdgeFade);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (frameX + shaddowOffsetX + halfBlurRadius, y,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster frameWidth - blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->fill();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Bottom Edge
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster y = frameY + frameHeight + shaddowOffsetY - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Cairo::RefPtr<LinearGradient> bottomEdgeFade = LinearGradient::create(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster 0.0, y, 0.0, y + blurRadius);
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->set_source(bottomEdgeFade);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (frameX + shaddowOffsetX + halfBlurRadius, y,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster frameWidth - blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->fill();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Top Left Corner
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x = frameX + shaddowOffsetX - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster y = frameY + shaddowOffsetY - halfBlurRadius;
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->set_source(topLeftCornerFade);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (x, y, blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->fill();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Top Right Corner
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x = frameX + frameWidth + shaddowOffsetX - halfBlurRadius;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster y = frameY + shaddowOffsetY - 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->set_source(topRightCornerFade);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (x, y, blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->fill();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Bottom Left Corner
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster x = frameX + shaddowOffsetX - halfBlurRadius;
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->set_source(bottomLeftCornerFade);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (x, y, blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->fill();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
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->set_source(bottomRightCornerFade);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (frameX + frameWidth + shaddowOffsetX - halfBlurRadius,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster frameY + frameHeight + shaddowOffsetY - halfBlurRadius,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster blurRadius, blurRadius);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->fill();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the frame
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->set_line_width(1);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (frameX, frameY, frameWidth, frameHeight);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->set_source_rgb(1.0, 1.0, 1.0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->fill_preserve();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->set_source_rgb(0.25, 0.25, 0.25);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->stroke_preserve();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the image
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_preview_bitmap_image) // Is the image a pixbuf?
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Set the transformation
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Cairo::Matrix matrix(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster scaleFactor, 0,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster 0, scaleFactor,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster svgX, svgY);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->set_matrix (matrix);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Render the image
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster set_source_pixbuf (context, _preview_bitmap_image, 0, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->paint();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Reset the transformation
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->set_identity_matrix();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Draw the inner frame
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->set_source_rgb(0.75, 0.75, 0.75);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->rectangle (svgX, svgY, scaledSvgWidth, scaledSvgHeight);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster context->stroke();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Finish drawing
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster surface->finish();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (_preview_emf_image) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HENHMETAFILE hemf = MyGetEnhMetaFileW(_path_string);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (hemf) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RECT rc;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rc.top = svgY+2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rc.left = svgX+2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rc.bottom = scaledSvgHeight-2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster rc.right = scaledSvgWidth-2;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster PlayEnhMetaFile(hMemDC, hemf, &rc);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteEnhMetaFile(hemf);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SelectObject(hMemDC, hOldBitmap) ;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DeleteDC(hMemDC);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Refresh the preview pane
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster InvalidateRect(_preview_wnd, NULL, FALSE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterint FileOpenDialogImplWin32::format_caption(wchar_t *caption, int caption_size)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster wchar_t szFileName[_MAX_FNAME];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _wsplitpath(_path_string, NULL, NULL, szFileName, NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return snwprintf(caption, caption_size,
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}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/**
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Show this dialog modally. Return true if user hits [OK]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterbool
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterFileOpenDialogImplWin32::show()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // We can only run one worker thread at a time
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_mutex != NULL) return false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(!Glib::thread_supported())
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Glib::thread_init();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _result = false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _finished = false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _file_selected = false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex = new Glib::Mutex();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _main_loop = g_main_loop_new(g_main_context_default(), FALSE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(Glib::Thread::create(sigc::mem_fun(*this, &FileOpenDialogImplWin32::GetOpenFileName_thread), true))
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster while(1)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster g_main_context_iteration(g_main_context_default(), FALSE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(_mutex->trylock())
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Read mutexed data
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const bool finished = _finished;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const bool is_file_selected = _file_selected;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _file_selected = false;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex->unlock();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(finished) break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(is_file_selected) file_selected();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Sleep(10);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Tidy up
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster delete _mutex;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _mutex = NULL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return _result;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/**
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * To Get Multiple filenames selected at-once.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstd::vector<Glib::ustring>FileOpenDialogImplWin32::getFilenames()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster std::vector<Glib::ustring> result;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster result.push_back(getFilename());
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return result;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*#########################################################################
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster### F I L E S A V E
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#########################################################################*/
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/**
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructor
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterFileSaveDialogImplWin32::FileSaveDialogImplWin32(Gtk::Window &parent,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring &dir,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileDialogType fileTypes,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const char *title,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const Glib::ustring &/*default_key*/,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster const char *docTitle,
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 _title_label(NULL),
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster _title_edit(NULL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FileSaveDialog::myDocTitle = docTitle;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster createFilterMenu();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* The code below sets the default file name */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster myFilename = "";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (dir.size() > 0) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Glib::ustring udir(dir);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Glib::ustring::size_type len = udir.length();
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
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 if (last_period_index > last_slash_index) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster myFilename = udir.substr(0, last_period_index );
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // remove one slash if double
33fc82147580d6f2d1299f6282e1cf8a28212bc5Peter Major if (1 + myFilename.find("\\\\",2)) {
33fc82147580d6f2d1299f6282e1cf8a28212bc5Peter Major myFilename.replace(myFilename.find("\\\\",2), 1, "");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter Major }
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter Major}
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter Major
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter MajorFileSaveDialogImplWin32::~FileSaveDialogImplWin32()
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter Major{
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter Major}
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter Major
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter Majorvoid FileSaveDialogImplWin32::createFilterMenu()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
07856bf23b706ef4e3654388d9ca26a720e0ad6aPeter Major list<Filter> filter_list;
5bdd6bf9211505ff52afc7e32bdc49cdfacf4879Charles Sparey
5bdd6bf9211505ff52afc7e32bdc49cdfacf4879Charles Sparey knownExtensions.clear();
5bdd6bf9211505ff52afc7e32bdc49cdfacf4879Charles Sparey
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;
Inkscape::Extension::db.get_output_list(extension_list);
int filter_count = 0;
int filter_length = 1;
for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
current_item != extension_list.end(); ++current_item)
{
Inkscape::Extension::Output *omod = *current_item;
if (omod->deactivated()) continue;
filter_count++;
Filter filter;
// Extension
const gchar *filter_extension = omod->get_extension();
filter.filter = g_utf8_to_utf16(
filter_extension, -1, NULL, &filter.filter_length, NULL);
knownExtensions.insert( Glib::ustring(filter_extension).casefold() );
// Type
filter.name = g_utf8_to_utf16(
_(omod->get_filetypename()), -1, NULL, &filter.name_length, NULL);
filter.mod = omod;
filter_length += filter.name_length +
filter.filter_length + 3; // Add 3 for two \0s and a *
filter_list.push_back(filter);
}
int extension_index = 0;
_extension_map = new Inkscape::Extension::Extension*[filter_count];
_filter = new wchar_t[filter_length];
wchar_t *filterptr = _filter;
for(list<Filter>::iterator filter_iterator = filter_list.begin();
filter_iterator != filter_list.end(); ++filter_iterator)
{
const Filter &filter = *filter_iterator;
wcsncpy(filterptr, (wchar_t*)filter.name, filter.name_length);
filterptr += filter.name_length;
g_free(filter.name);
*(filterptr++) = L'\0';
*(filterptr++) = L'*';
wcsncpy(filterptr, (wchar_t*)filter.filter, filter.filter_length);
filterptr += filter.filter_length;
g_free(filter.filter);
*(filterptr++) = L'\0';
// Associate this input extension with the file type name
_extension_map[extension_index++] = filter.mod;
}
*(filterptr++) = 0;
_filter_count = extension_index;
_filter_index = 1; // A value of 1 selects the 1st filter - NOT the 2nd
}
void FileSaveDialogImplWin32::GetSaveFileName_thread()
{
OPENFILENAMEEXW ofn;
g_assert(this != NULL);
g_assert(_main_loop != NULL);
WCHAR* current_directory_string = (WCHAR*)g_utf8_to_utf16(
_current_directory.data(), _current_directory.length(),
NULL, NULL, NULL);
// Copy the selected file name, converting from UTF-8 to UTF-16
memset(_path_string, 0, sizeof(_path_string));
gunichar2* utf16_path_string = g_utf8_to_utf16(
myFilename.data(), -1, NULL, NULL, NULL);
wcsncpy(_path_string, (wchar_t*)utf16_path_string, _MAX_PATH);
g_free(utf16_path_string);
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = _ownerHwnd;
ofn.lpstrFile = _path_string;
ofn.nMaxFile = _MAX_PATH;
ofn.nFilterIndex = _filter_index;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = current_directory_string;
ofn.lpstrTitle = _title;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_ENABLESIZING;
ofn.lpstrFilter = _filter;
ofn.nFilterIndex = _filter_index;
ofn.lpfnHook = GetSaveFileName_hookproc;
ofn.lCustData = (LPARAM)this;
_result = GetSaveFileNameW(&ofn) != 0;
g_assert(ofn.nFilterIndex >= 1 && ofn.nFilterIndex <= _filter_count);
_filter_index = ofn.nFilterIndex;
_extension = _extension_map[ofn.nFilterIndex - 1];
// Copy the selected file name, converting from UTF-16 to UTF-8
myFilename = utf16_to_ustring(_path_string, _MAX_PATH);
// Tidy up
g_free(current_directory_string);
g_main_loop_quit(_main_loop);
}
/**
* Show this dialog modally. Return true if user hits [OK]
*/
bool
FileSaveDialogImplWin32::show()
{
if(!Glib::thread_supported())
Glib::thread_init();
_result = false;
_main_loop = g_main_loop_new(g_main_context_default(), FALSE);
if(_main_loop != NULL)
{
if(Glib::Thread::create(sigc::mem_fun(*this, &FileSaveDialogImplWin32::GetSaveFileName_thread), true))
g_main_loop_run(_main_loop);
if(_result)
appendExtension(myFilename, (Inkscape::Extension::Output*)_extension);
}
return _result;
}
void FileSaveDialogImplWin32::setSelectionType( Inkscape::Extension::Extension * /*key*/ )
{
// If no pointer to extension is passed in, look up based on filename extension.
}
UINT_PTR CALLBACK FileSaveDialogImplWin32::GetSaveFileName_hookproc(
HWND hdlg, UINT uiMsg, WPARAM, LPARAM lParam)
{
FileSaveDialogImplWin32 *pImpl = reinterpret_cast<FileSaveDialogImplWin32*>
(GetWindowLongPtr(hdlg, GWLP_USERDATA));
switch(uiMsg)
{
case WM_INITDIALOG:
{
HWND hParentWnd = GetParent(hdlg);
HINSTANCE hInstance = GetModuleHandle(NULL);
// get size/pos of typical combo box
RECT rEDT1, rCB1, rROOT, rST;
GetWindowRect(GetDlgItem(hParentWnd, cmb1), &rCB1);
GetWindowRect(GetDlgItem(hParentWnd, cmb13), &rEDT1);
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,
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);
// Set the pointer to the object
OPENFILENAMEW *ofn = reinterpret_cast<OPENFILENAMEW*>(lParam);
SetWindowLongPtr(hdlg, GWLP_USERDATA, ofn->lCustData);
SetWindowLongPtr(hParentWnd, GWLP_USERDATA, ofn->lCustData);
pImpl = reinterpret_cast<FileSaveDialogImplWin32*>(ofn->lCustData);
// Create the Title label and edit control
pImpl->_title_label = CreateWindowEx(0, "STATIC", "Title:",
WS_VISIBLE|WS_CHILD,
CW_USEDEFAULT, CW_USEDEFAULT, rCB1.left-rST.left, rST.bottom-rST.top,
hParentWnd, NULL, hInstance, NULL);
if(pImpl->_title_label) {
if(dlgFont) SendMessage(pImpl->_title_label, WM_SETFONT, (WPARAM)dlgFont, MAKELPARAM(FALSE, 0));
SetWindowPos(pImpl->_title_label, NULL, rST.left-rROOT.left, rST.top+ydelta-rROOT.top,
rCB1.left-rST.left, rST.bottom-rST.top, SWP_SHOWWINDOW|SWP_NOZORDER);
}
pImpl->_title_edit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
WS_VISIBLE|WS_CHILD|WS_TABSTOP|ES_AUTOHSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT, rCB1.right-rCB1.left, rCB1.bottom-rCB1.top,
hParentWnd, NULL, hInstance, NULL);
if(pImpl->_title_edit) {
if(dlgFont) SendMessage(pImpl->_title_edit, WM_SETFONT, (WPARAM)dlgFont, MAKELPARAM(FALSE, 0));
SetWindowPos(pImpl->_title_edit, NULL, rCB1.left-rROOT.left, rCB1.top+ydelta-rROOT.top,
rCB1.right-rCB1.left, rCB1.bottom-rCB1.top, SWP_SHOWWINDOW|SWP_NOZORDER);
// TODO: make sure this works for Unicode
SetWindowText(pImpl->_title_edit, pImpl->myDocTitle.c_str());
}
}
break;
case WM_DESTROY:
{
if(pImpl->_title_edit) {
int length = GetWindowTextLength(pImpl->_title_edit)+1;
char* temp_title = new char[length];
GetWindowText(pImpl->_title_edit, temp_title, length);
pImpl->myDocTitle = temp_title;
delete[] temp_title;
DestroyWindow(pImpl->_title_label);
pImpl->_title_label = NULL;
DestroyWindow(pImpl->_title_edit);
pImpl->_title_edit = NULL;
}
}
break;
}
// Use default dialog behaviour
return 0;
}
} } } // namespace Dialog, UI, Inkscape
#endif // ifdef WIN32
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :