filedialogimpl-win32.cpp revision d18b4d7c4eb090852371bf44013cd4e2b0e620ad
/**
* Implementation of the file dialog interfaces defined in filedialog.h for Win32
*
* Authors:
* Joel Holdsworth
* The Inkscape Organization
*
* Copyright (C) 2004-2008 The Inkscape Organization
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef WIN32
//General includes
#include <list>
#include <unistd.h>
#include <errno.h>
#include <set>
#include <gdk/gdkwin32.h>
//Inkscape includes
#include "inkscape.h"
#include "prefs-utils.h"
#include <dialogs/dialog-events.h>
#include <libnr/nr-pixops.h>
#include <libnr/nr-translate-scale-ops.h>
#include <display/nr-arena-item.h>
#include <display/nr-arena.h>
#include "sp-item.h"
#include "canvas-arena.h"
#include "filedialog.h"
#include "filedialogimpl-win32.h"
#include <zlib.h>
#include <cairomm/win32_surface.h>
using namespace std;
using namespace Glib;
using namespace Cairo;
namespace Inkscape
{
namespace UI
{
namespace Dialog
{
const int PreviewWidening = 150;
const char PreviewWindowClassName[] = "PreviewWnd";
#define IDC_SHOW_PREVIEW 1000
// Windows 2000 version of OPENFILENAMEW
struct OPENFILENAMEEXW : public OPENFILENAMEW {
void * pvReserved;
};
struct Filter
{
};
{
return result;
}
/*#########################################################################
### F I L E D I A L O G B A S E C L A S S
#########################################################################*/
{
//_mutex = NULL;
_main_loop = NULL;
}
{
}
{
return _extension;
}
{
return _current_directory;
}
/*#########################################################################
### F I L E O P E N
#########################################################################*/
bool FileOpenDialogImplWin32::_show_preview = true;
/**
* Constructor. Not called directly. Use the factory.
*/
{
// Initalize to Autodetect
_extension = NULL;
// Set our dialog type (open, import, etc...)
_preview_wnd = NULL;
_preview_file_size = 0;
_preview_image_width = 0;
}
/**
* Destructor
*/
{
delete[] _filter;
if(_extension_map != NULL)
delete[] _extension_map;
}
{
// Compose the filter string
// Calculate the amount of memory required
int filter_length = 1;
{
if (imod->deactivated()) continue;
// Type
// Extension
// Add to the "All Inkscape Files" Entry
if(all_inkscape_files_filter.length() > 0)
all_inkscape_files_filter += ";*";
{
// Add to the "All Image Files" Entry
if(all_image_files_filter.length() > 0)
all_image_files_filter += ";*";
}
filter_count++;
}
int extension_index = 0;
// Filter Image Files
// Filter Inkscape Files
// Filter All Files
all_files.filter_length = 0;
// Add 3 for 2*2 \0s and a *, and 1 for a trailing \0
_filter = new wchar_t[filter_length];
{
*(filterptr++) = L'\0';
*(filterptr++) = L'*';
{
}
*(filterptr++) = L'\0';
// Associate this input extension with the file type name
}
*(filterptr++) = L'\0';
_filterIndex = 2;
}
{
//g_assert(_mutex != NULL);
// Copy the selected file name, converting from UTF-8 to UTF-16
ofn.nMaxFileTitle = 0;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_HIDEREADONLY | OFN_ENABLESIZING;
// Copy the selected file name, converting from UTF-16 to UTF-8
// Tidy up
_finished = true;
//g_main_loop_quit(_main_loop);
}
{
const WNDCLASSA PreviewWndClass =
{
0,
0,
NULL,
NULL,
};
}
{
switch(uiMsg)
{
case WM_INITDIALOG:
{
// Make the window a bit wider
FALSE);
// Set the pointer to the object
// Subclass the parent
// Add a button to the toolbar
// Create preview pane
pImpl->layout_dialog();
}
break;
case WM_NOTIFY:
{
{
case CDN_SELCHANGE:
{
{
// Get the file name
sizeof(pImpl->_path_string) / sizeof(wchar_t),
pImpl->_file_selected = true;
//pImpl->file_selected();
}
}
break;
}
}
break;
case WM_CLOSE:
pImpl->_preview_file_size = 0;
break;
}
// Use default dialog behaviour
return 0;
}
LRESULT CALLBACK FileOpenDialogImplWin32::file_dialog_subclass_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_SHOWWINDOW:
if(wParam != 0)
pImpl->layout_dialog();
break;
case WM_SIZE:
pImpl->layout_dialog();
break;
case WM_COMMAND:
if(wParam == IDC_SHOW_PREVIEW)
{
TB_ISBUTTONCHECKED, IDC_SHOW_PREVIEW, 0) != 0;
}
break;
}
return lResult;
}
LRESULT CALLBACK FileOpenDialogImplWin32::preview_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
const int CaptionPadding = 4;
const int IconSize = 32;
switch(uMsg)
{
case WM_ERASEBKGND:
// Do nothing to erase the background
// - otherwise there'll be flicker
lResult = 1;
break;
case WM_PAINT:
{
// Get the client rect
// Prepare to paint
WM_GETFONT, 0, 0);
//FillRect(dc, &client_rect, (HBRUSH)(COLOR_HOTLIGHT+1));
if(pImpl->_path_string[0] == 0)
{
}
{
// Render the image
// Fill in the background area
// Draw the caption on
}
{
// Draw the files icon
// Draw the caption on
sizeof(szCaption), L"%s\n%d kB",
}
else
{
// Can't show anything!
}
// Finish painting
}
break;
case WM_DESTROY:
pImpl->free_preview();
break;
default:
break;
}
return lResult;
}
{
// Relayout the dialog
// Load or unload the preview
if(enable)
{
_file_selected = true;
}
else free_preview();
}
void FileOpenDialogImplWin32::layout_dialog()
{
union RECTPOINTS
{
RECT r;
POINT p[2];
};
// Re-layout the dialog
if(_show_preview)
{
// Re-layout the preview box
}
// Re-layout the file list box
// Re-layout the toolbar
}
void FileOpenDialogImplWin32::file_selected()
{
// Destroy any previous previews
free_preview();
// Determine if the file exists
if(attributes == 0xFFFFFFFF ||
{
return;
}
// Check the file exists and get the file size
if(file_handle == INVALID_HANDLE_VALUE) return;
if (file_size == INVALID_FILE_SIZE) return;
if(_show_preview) load_preview();
}
void FileOpenDialogImplWin32::load_preview()
{
// Destroy any previous previews
free_preview();
// Try to get the file icon
// Will this file be too big?
{
return;
}
// Prepare to render a preview
bool success = false;
success = set_svg_preview();
else if (isValidImageFile(path))
success = set_image_preview();
else {
// Show no preview
}
if(success) render_preview();
}
void FileOpenDialogImplWin32::free_preview()
{
if(_preview_bitmap != NULL)
if(_preview_file_icon != NULL)
}
{
const int PreviewSize = 512;
// Check the document loaded properly
{
return false;
}
// Get the size of the document
// Find the minimum scale to fit the image inside the preview area
// Now get the resized values
// write object bbox to area
// Prepare a GDI compatible NRPixBlock
// Fail if the pixblock failed to allocate
{
return false;
}
// Render the image
// Tidy up
// Create the GDK pixbuf
return true;
}
{
}
{
if(!_preview_bitmap_image) return false;
return true;
}
{
double x, y;
const double blurRadius = 8;
const int shaddowOffsetX = 0;
const int shaddowOffsetY = 2;
const int pagePadding = 5;
const double shaddowAlpha = 0.75;
// Is the preview showing?
if(!_show_preview)
return;
// Do we have anything to render?
{
return;
}
// Tidy up any previous bitmap renderings
if(_preview_bitmap != NULL)
// Calculate the size of the caption
int captionHeight = 0;
if(_preview_wnd != NULL)
{
}
// Find the minimum scale to fit the image inside the preview area
const double scaleFactorX =
const double scaleFactorY =
// Now get the resized values
const int svgY = pagePadding;
// Prepare the drawing surface
// Paint the background to match the dialog colour
//----- Draw the drop shaddow -----//
// Left Edge
leftEdgeFade->add_color_stop_rgba (0, 0, 0, 0, 0);
// Right Edge
// Top Edge
topEdgeFade->add_color_stop_rgba (0, 0, 0, 0, 0);
// Bottom Edge
// Top Left Corner
// Top Right Corner
// Bottom Left Corner
// Bottom Right Corner
x, y, 0, x, y, blurRadius);
// Draw the frame
context->fill_preserve();
// Draw the image
if(_preview_bitmap_image) // Is the image a pixbuf?
{
// Set the transformation
scaleFactor, 0,
0, scaleFactor,
// Render the image
// Reset the transformation
}
// Draw the inner frame
// Finish drawing
// Refresh the preview pane
}
{
wchar_t szFileName[_MAX_FNAME];
(int)_preview_document_width, (int)_preview_document_height);
}
/**
* Show this dialog modally. Return true if user hits [OK]
*/
bool
{
// We can only run one worker thread at a time
//if(_mutex != NULL) return false;
if(!Glib::thread_supported())
Glib::thread_init();
_result = false;
_finished = false;
_file_selected = false;
if(Glib::Thread::create(sigc::mem_fun(*this, &FileOpenDialogImplWin32::GetOpenFileName_thread), true))
{
while(1)
{
{
// Read mutexed data
const bool is_file_selected = _file_selected;
_file_selected = false;
if(finished) break;
if(is_file_selected) file_selected();
}
Sleep(10);
}
//g_main_loop_run(_main_loop);
}
// Tidy up
delete _mutex;
return _result;
}
/**
* To Get Multiple filenames selected at-once.
*/
{
return result;
}
/*#########################################################################
### F I L E S A V E
#########################################################################*/
/**
* Constructor
*/
const char *title,
{
_main_loop = NULL;
}
{
}
{
// Compose the filter string
int filter_count = 0;
int filter_length = 0;
{
if (omod->deactivated()) continue;
filter_count++;
// Extension
// Type
}
int extension_index = 0;
_filter = new wchar_t[filter_length];
{
*(filterptr++) = L'\0';
*(filterptr++) = L'*';
*(filterptr++) = L'\0';
// Associate this input extension with the file type name
}
*(filterptr++) = 0;
_filterIndex = 0;
}
{
//g_assert(_mutex != NULL);
// Copy the selected file name, converting from UTF-8 to UTF-16
ofn.nMaxFileTitle = 0;
// Copy the selected file name, converting from UTF-16 to UTF-8
//_mutex->lock();
//_finished = true;
//_mutex->unlock();
// Tidy up
}
/**
* Show this dialog modally. Return true if user hits [OK]
*/
bool
{
// We can only run one worker thread at a time
//if(_mutex != NULL) return false;
if(!Glib::thread_supported())
Glib::thread_init();
_result = false;
//_finished = false;
//_mutex = new Glib::Mutex();
if(Glib::Thread::create(sigc::mem_fun(*this, &FileSaveDialogImplWin32::GetSaveFileName_thread), true))
{
/*while(1)
{
// While the dialog runs - keep the main UI alive
g_main_context_iteration(g_main_context_default(), FALSE);
if(_mutex->trylock())
{
if(_finished) break;
_mutex->unlock();
}
Sleep(10);
}*/
}
//delete _mutex;
//_mutex = NULL;
if(_result)
return _result;
}
{
// If no pointer to extension is passed in, look up based on filename extension.
}
}
}
}
#endif
/*
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 :