attempts at providing clipboard/dnd support for metafiles - unsuccessful

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5283 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-01-07 02:30:29 +00:00
parent 85ac091e8f
commit 265b0c070b
4 changed files with 416 additions and 325 deletions

View File

@@ -1,39 +1,42 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: metafile.h // Name: wx/msw/metafile.h
// Purpose: wxMetaFile, wxMetaFileDC classes // Purpose: wxMetaFile, wxMetaFileDC and wxMetaFileDataObject classes
// Author: Julian Smart // Author: Julian Smart
// Modified by: // Modified by: VZ 07.01.00: implemented wxMetaFileDataObject
// Created: 01/02/97 // Created: 01/02/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart // Copyright: (c) Julian Smart
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_METAFIILE_H_ #ifndef _WX_METAFIILE_H_
#define _WX_METAFIILE_H_ #define _WX_METAFIILE_H_
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface "metafile.h" #pragma interface "metafile.h"
#endif #endif
#include "wx/setup.h" #include "wx/setup.h"
#if wxUSE_METAFILE #if wxUSE_METAFILE
#include "wx/dc.h" #include "wx/dc.h"
#include "wx/gdiobj.h" #include "wx/gdiobj.h"
#if wxUSE_DRAG_AND_DROP #if wxUSE_DRAG_AND_DROP
#include "wx/dataobj.h" #include "wx/dataobj.h"
#endif #endif
/* // provide synonyms for all metafile classes
* Metafile and metafile device context classes
*
*/
#define wxMetaFile wxMetafile #define wxMetaFile wxMetafile
#define wxMetaFileDC wxMetafileDC #define wxMetaFileDC wxMetafileDC
#define wxMetaFileDataObject wxMetafileDataObject
#define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
// ----------------------------------------------------------------------------
// Metafile and metafile device context classes
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxMetafile; class WXDLLEXPORT wxMetafile;
@@ -41,79 +44,88 @@ class WXDLLEXPORT wxMetafileRefData: public wxGDIRefData
{ {
friend class WXDLLEXPORT wxMetafile; friend class WXDLLEXPORT wxMetafile;
public: public:
wxMetafileRefData(void); wxMetafileRefData();
~wxMetafileRefData(void); ~wxMetafileRefData();
public: public:
WXHANDLE m_metafile; WXHANDLE m_metafile;
int m_windowsMappingMode; int m_windowsMappingMode;
int m_width, m_height;
}; };
#define M_METAFILEDATA ((wxMetafileRefData *)m_refData) #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
class WXDLLEXPORT wxMetafile: public wxGDIObject class WXDLLEXPORT wxMetafile: public wxGDIObject
{ {
DECLARE_DYNAMIC_CLASS(wxMetafile) public:
public: wxMetafile(const wxString& file = wxEmptyString);
// Copy constructor wxMetafile(const wxMetafile& metafile) { Ref(metafile); }
inline wxMetafile(const wxMetafile& metafile) virtual ~wxMetafile();
{ Ref(metafile); }
wxMetafile(const wxString& file = ""); // After this is called, the metafile cannot be used for anything
~wxMetafile(void); // since it is now owned by the clipboard.
virtual bool SetClipboard(int width = 0, int height = 0);
// After this is called, the metafile cannot be used for anything virtual bool Play(wxDC *dc);
// since it is now owned by the clipboard. bool Ok() const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); };
virtual bool SetClipboard(int width = 0, int height = 0);
virtual bool Play(wxDC *dc); // set/get the size of metafile for clipboard operations
inline bool Ok(void) const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); }; int GetWidth() const { return M_METAFILEDATA->m_width; }
int GetHeight() const { return M_METAFILEDATA->m_height; }
// Implementation void SetWidth(int width) { M_METAFILEDATA->m_width = width; }
inline WXHANDLE GetHMETAFILE(void) { return M_METAFILEDATA->m_metafile; } void SetHeight(int height) { M_METAFILEDATA->m_height = height; }
void SetHMETAFILE(WXHANDLE mf) ;
inline int GetWindowsMappingMode(void) { return M_METAFILEDATA->m_windowsMappingMode; }
void SetWindowsMappingMode(int mm);
// Operators // Implementation
inline wxMetafile& operator = (const wxMetafile& metafile) { if (*this == metafile) return (*this); Ref(metafile); return *this; } WXHANDLE GetHMETAFILE() const { return M_METAFILEDATA->m_metafile; }
inline bool operator == (const wxMetafile& metafile) { return m_refData == metafile.m_refData; } void SetHMETAFILE(WXHANDLE mf) ;
inline bool operator != (const wxMetafile& metafile) { return m_refData != metafile.m_refData; } int GetWindowsMappingMode() const { return M_METAFILEDATA->m_windowsMappingMode; }
void SetWindowsMappingMode(int mm);
protected: // Operators
wxMetafile& operator=(const wxMetafile& metafile)
{ if (*this != metafile) Ref(metafile); return *this; }
bool operator==(const wxMetafile& metafile) const
{ return m_refData == metafile.m_refData; }
bool operator!=(const wxMetafile& metafile) const
{ return m_refData != metafile.m_refData; }
private:
DECLARE_DYNAMIC_CLASS(wxMetafile)
}; };
class WXDLLEXPORT wxMetafileDC: public wxDC class WXDLLEXPORT wxMetafileDC: public wxDC
{ {
DECLARE_DYNAMIC_CLASS(wxMetafileDC) public:
// Don't supply origin and extent
// Supply them to wxMakeMetaFilePlaceable instead.
wxMetafileDC(const wxString& file = "");
public: // Supply origin and extent (recommended).
// Don't supply origin and extent // Then don't need to supply them to wxMakeMetaFilePlaceable.
// Supply them to wxMakeMetaFilePlaceable instead. wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg);
wxMetafileDC(const wxString& file = "");
// Supply origin and extent (recommended). virtual ~wxMetafileDC();
// Then don't need to supply them to wxMakeMetaFilePlaceable.
wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg);
~wxMetafileDC(void); // Should be called at end of drawing
virtual wxMetafile *Close();
virtual void SetMapMode(int mode);
virtual void GetTextExtent(const wxString& string, long *x, long *y,
long *descent = NULL, long *externalLeading = NULL,
wxFont *theFont = NULL, bool use16bit = FALSE) const;
// Should be called at end of drawing // Implementation
virtual wxMetafile *Close(void); wxMetafile *GetMetaFile() const { return m_metaFile; }
virtual void SetMapMode(int mode); void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; }
virtual void GetTextExtent(const wxString& string, long *x, long *y, int GetWindowsMappingMode() const { return m_windowsMappingMode; }
long *descent = NULL, long *externalLeading = NULL, void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; }
wxFont *theFont = NULL, bool use16bit = FALSE) const;
// Implementation
inline wxMetafile *GetMetaFile(void) const { return m_metaFile; }
inline void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; }
inline int GetWindowsMappingMode(void) const { return m_windowsMappingMode; }
inline void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; }
protected: protected:
int m_windowsMappingMode; int m_windowsMappingMode;
wxMetafile* m_metaFile; wxMetafile* m_metaFile;
private:
DECLARE_DYNAMIC_CLASS(wxMetafileDC)
}; };
/* /*
@@ -124,7 +136,6 @@ protected:
*/ */
// No origin or extent // No origin or extent
#define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0); bool WXDLLEXPORT wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0);
// Optional origin and extent // Optional origin and extent
@@ -134,44 +145,34 @@ bool WXDLLEXPORT wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y
// wxMetafileDataObject is a specialization of wxDataObject for metafile data // wxMetafileDataObject is a specialization of wxDataObject for metafile data
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// TODO: implement OLE side of things. At present, it's just for clipboard
// use.
#if wxUSE_DRAG_AND_DROP #if wxUSE_DRAG_AND_DROP
class WXDLLEXPORT wxMetafileDataObject : public wxDataObject
class WXDLLEXPORT wxMetafileDataObject : public wxDataObjectSimple
{ {
public: public:
// ctors // ctors
wxMetafileDataObject() { m_width = 0; m_height = 0; }; wxMetafileDataObject() : wxDataObjectSimple(wxDF_METAFILE)
wxMetafileDataObject(const wxMetafile& metafile, int width = 0, int height = 0): { }
m_metafile(metafile), m_width(width), m_height(height) { } wxMetafileDataObject(const wxMetafile& metafile)
: wxDataObjectSimple(wxDF_METAFILE), m_metafile(metafile) { }
void SetMetafile(const wxMetafile& metafile, int w = 0, int h = 0) // virtual functions which you may override if you want to provide data on
{ m_metafile = metafile; m_width = w; m_height = h; } // demand only - otherwise, the trivial default versions will be used
wxMetafile GetMetafile() const { return m_metafile; } virtual void SetMetafile(const wxMetafile& metafile)
int GetWidth() const { return m_width; } { m_metafile = metafile; }
int GetHeight() const { return m_height; } virtual wxMetafile GetMetafile() const
{ return m_metafile; }
virtual wxDataFormat GetFormat() const { return wxDF_METAFILE; } // implement base class pure virtuals
virtual size_t GetDataSize() const;
virtual bool GetDataHere(void *buf) const;
virtual bool SetData(size_t len, const void *buf);
/* ?? protected:
// implement base class pure virtuals wxMetafile m_metafile;
virtual wxDataFormat GetPreferredFormat() const
{ return (wxDataFormat) wxDataObject::Text; }
virtual bool IsSupportedFormat(wxDataFormat format) const
{ return format == wxDataObject::Text || format == wxDataObject::Locale; }
virtual size_t GetDataSize() const
{ return m_strText.Len() + 1; } // +1 for trailing '\0'of course
virtual void GetDataHere(void *pBuf) const
{ memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
*/
private:
wxMetafile m_metafile;
int m_width;
int m_height;
}; };
#endif
#endif // wxUSE_DRAG_AND_DROP
#endif // wxUSE_METAFILE #endif // wxUSE_METAFILE
#endif #endif

View File

@@ -670,7 +670,6 @@ bool wxClipboard::GetData( wxDataObject& data )
formatEtc.ptd = NULL; formatEtc.ptd = NULL;
formatEtc.dwAspect = DVASPECT_CONTENT; formatEtc.dwAspect = DVASPECT_CONTENT;
formatEtc.lindex = -1; formatEtc.lindex = -1;
formatEtc.tymed = TYMED_HGLOBAL;
size_t nSupportedFormats = supportedFormats.GetCount(); size_t nSupportedFormats = supportedFormats.GetCount();
for ( size_t n = 0; !result && (n < nSupportedFormats); n++ ) for ( size_t n = 0; !result && (n < nSupportedFormats); n++ )
@@ -678,6 +677,21 @@ bool wxClipboard::GetData( wxDataObject& data )
STGMEDIUM medium; STGMEDIUM medium;
formatEtc.cfFormat = supportedFormats[n]; formatEtc.cfFormat = supportedFormats[n];
// use the appropriate tymed
switch ( formatEtc.cfFormat )
{
case CF_BITMAP:
formatEtc.tymed = TYMED_GDI;
break;
case CF_METAFILEPICT:
formatEtc.tymed = TYMED_MFPICT;
break;
default:
formatEtc.tymed = TYMED_HGLOBAL;
}
// try to get data // try to get data
hr = pDataObject->GetData(&formatEtc, &medium); hr = pDataObject->GetData(&formatEtc, &medium);
if ( FAILED(hr) ) if ( FAILED(hr) )

View File

@@ -1,34 +1,42 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: metafile.cpp // Name: msw/metafile.cpp
// Purpose: wxMetafileDC etc. // Purpose: wxMetafileDC etc.
// Author: Julian Smart // Author: Julian Smart
// Modified by: // Modified by: VZ 07.01.00: implemented wxMetaFileDataObject
// Created: 04/01/98 // Created: 04/01/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem // Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "metafile.h" #pragma implementation "metafile.h"
#endif #endif
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif #endif
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/setup.h" #include "wx/setup.h"
#endif #endif
#if wxUSE_METAFILE #if wxUSE_METAFILE
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/app.h" #include "wx/app.h"
#endif #endif
#include "wx/metafile.h" #include "wx/metafile.h"
@@ -38,24 +46,35 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
extern bool wxClipboardIsOpen; // ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC) IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxMetafileRefData
// ----------------------------------------------------------------------------
/* /*
* Metafiles * Metafiles
* Currently, the only purpose for making a metafile is to put * Currently, the only purpose for making a metafile is to put
* it on the clipboard. * it on the clipboard.
*/ */
wxMetafileRefData::wxMetafileRefData(void) wxMetafileRefData::wxMetafileRefData()
{ {
m_metafile = 0; m_metafile = 0;
m_windowsMappingMode = wxMM_ANISOTROPIC; m_windowsMappingMode = wxMM_ANISOTROPIC;
m_width = m_height = 0;
} }
wxMetafileRefData::~wxMetafileRefData(void) wxMetafileRefData::~wxMetafileRefData()
{ {
if (m_metafile) if (m_metafile)
{ {
@@ -64,6 +83,10 @@ wxMetafileRefData::~wxMetafileRefData(void)
} }
} }
// ----------------------------------------------------------------------------
// wxMetafile
// ----------------------------------------------------------------------------
wxMetafile::wxMetafile(const wxString& file) wxMetafile::wxMetafile(const wxString& file)
{ {
m_refData = new wxMetafileRefData; m_refData = new wxMetafileRefData;
@@ -74,7 +97,7 @@ wxMetafile::wxMetafile(const wxString& file)
M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file); M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
} }
wxMetafile::~wxMetafile(void) wxMetafile::~wxMetafile()
{ {
} }
@@ -83,15 +106,18 @@ bool wxMetafile::SetClipboard(int width, int height)
if (!m_refData) if (!m_refData)
return FALSE; return FALSE;
bool alreadyOpen=wxClipboardOpen(); bool alreadyOpen = wxClipboardOpen();
if (!alreadyOpen) if (!alreadyOpen)
{ {
wxOpenClipboard(); wxOpenClipboard();
if (!wxEmptyClipboard()) return FALSE; if (!wxEmptyClipboard())
return FALSE;
} }
bool success = wxSetClipboardData(wxDF_METAFILE, this, width,height); bool success = wxSetClipboardData(wxDF_METAFILE, this, width,height);
if (!alreadyOpen) wxCloseClipboard(); if (!alreadyOpen)
return (bool) success; wxCloseClipboard();
return success;
} }
bool wxMetafile::Play(wxDC *dc) bool wxMetafile::Play(wxDC *dc)
@@ -102,7 +128,7 @@ bool wxMetafile::Play(wxDC *dc)
dc->BeginDrawing(); dc->BeginDrawing();
if (dc->GetHDC() && M_METAFILEDATA->m_metafile) if (dc->GetHDC() && M_METAFILEDATA->m_metafile)
PlayMetaFile((HDC) dc->GetHDC(), (HMETAFILE) M_METAFILEDATA->m_metafile); PlayMetaFile(GetHdcOf(*dc), (HMETAFILE) M_METAFILEDATA->m_metafile);
dc->EndDrawing(); dc->EndDrawing();
@@ -111,7 +137,7 @@ bool wxMetafile::Play(wxDC *dc)
void wxMetafile::SetHMETAFILE(WXHANDLE mf) void wxMetafile::SetHMETAFILE(WXHANDLE mf)
{ {
if (m_refData) if (!m_refData)
m_refData = new wxMetafileRefData; m_refData = new wxMetafileRefData;
M_METAFILEDATA->m_metafile = mf; M_METAFILEDATA->m_metafile = mf;
@@ -119,162 +145,166 @@ void wxMetafile::SetHMETAFILE(WXHANDLE mf)
void wxMetafile::SetWindowsMappingMode(int mm) void wxMetafile::SetWindowsMappingMode(int mm)
{ {
if (m_refData) if (!m_refData)
m_refData = new wxMetafileRefData; m_refData = new wxMetafileRefData;
M_METAFILEDATA->m_windowsMappingMode = mm; M_METAFILEDATA->m_windowsMappingMode = mm;
} }
/* // ----------------------------------------------------------------------------
* Metafile device context // Metafile device context
* // ----------------------------------------------------------------------------
*/
// Original constructor that does not takes origin and extent. If you use this, // Original constructor that does not takes origin and extent. If you use this,
// *DO* give origin/extent arguments to wxMakeMetafilePlaceable. // *DO* give origin/extent arguments to wxMakeMetafilePlaceable.
wxMetafileDC::wxMetafileDC(const wxString& file) wxMetafileDC::wxMetafileDC(const wxString& file)
{ {
m_metaFile = NULL; m_metaFile = NULL;
m_minX = 10000; m_minX = 10000;
m_minY = 10000; m_minY = 10000;
m_maxX = -10000; m_maxX = -10000;
m_maxY = -10000; m_maxY = -10000;
// m_title = NULL; // m_title = NULL;
if (!file.IsNull() && wxFileExists(file)) if (!file.IsNull() && wxFileExists(file))
wxRemoveFile(file); wxRemoveFile(file);
if (!file.IsNull() && (file != wxT(""))) if (!file.IsNull() && (file != wxT("")))
m_hDC = (WXHDC) CreateMetaFile(file); m_hDC = (WXHDC) CreateMetaFile(file);
else else
m_hDC = (WXHDC) CreateMetaFile(NULL); m_hDC = (WXHDC) CreateMetaFile(NULL);
m_ok = (m_hDC != (WXHDC) 0) ; m_ok = (m_hDC != (WXHDC) 0) ;
// Actual Windows mapping mode, for future reference. // Actual Windows mapping mode, for future reference.
m_windowsMappingMode = wxMM_TEXT; m_windowsMappingMode = wxMM_TEXT;
SetMapMode(wxMM_TEXT); // NOTE: does not set HDC mapmode (this is correct) SetMapMode(wxMM_TEXT); // NOTE: does not set HDC mapmode (this is correct)
} }
// New constructor that takes origin and extent. If you use this, don't // New constructor that takes origin and extent. If you use this, don't
// give origin/extent arguments to wxMakeMetafilePlaceable. // give origin/extent arguments to wxMakeMetafilePlaceable.
wxMetafileDC::wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg) wxMetafileDC::wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg)
{ {
m_minX = 10000; m_minX = 10000;
m_minY = 10000; m_minY = 10000;
m_maxX = -10000; m_maxX = -10000;
m_maxY = -10000; m_maxY = -10000;
if (file != wxT("") && wxFileExists(file)) wxRemoveFile(file); if ( !!file && wxFileExists(file))
m_hDC = (WXHDC) CreateMetaFile(file); wxRemoveFile(file);
m_hDC = (WXHDC) CreateMetaFile(file);
m_ok = TRUE; m_ok = TRUE;
::SetWindowOrgEx((HDC) m_hDC,xorg,yorg, NULL); ::SetWindowOrgEx((HDC) m_hDC,xorg,yorg, NULL);
::SetWindowExtEx((HDC) m_hDC,xext,yext, NULL); ::SetWindowExtEx((HDC) m_hDC,xext,yext, NULL);
// Actual Windows mapping mode, for future reference. // Actual Windows mapping mode, for future reference.
m_windowsMappingMode = wxMM_ANISOTROPIC; m_windowsMappingMode = wxMM_ANISOTROPIC;
SetMapMode(wxMM_TEXT); // NOTE: does not set HDC mapmode (this is correct) SetMapMode(wxMM_TEXT); // NOTE: does not set HDC mapmode (this is correct)
} }
wxMetafileDC::~wxMetafileDC(void) wxMetafileDC::~wxMetafileDC()
{ {
m_hDC = 0; m_hDC = 0;
} }
void wxMetafileDC::GetTextExtent(const wxString& string, long *x, long *y, void wxMetafileDC::GetTextExtent(const wxString& string, long *x, long *y,
long *descent, long *externalLeading, wxFont *theFont, bool use16bit) const long *descent, long *externalLeading, wxFont *theFont, bool use16bit) const
{ {
wxFont *fontToUse = theFont; wxFont *fontToUse = theFont;
if (!fontToUse) if (!fontToUse)
fontToUse = (wxFont*) &m_font; fontToUse = (wxFont*) &m_font;
HDC dc = GetDC(NULL); HDC dc = GetDC(NULL);
SIZE sizeRect; SIZE sizeRect;
TEXTMETRIC tm; TEXTMETRIC tm;
GetTextExtentPoint(dc, WXSTRINGCAST string, wxStrlen(WXSTRINGCAST string), &sizeRect); GetTextExtentPoint(dc, WXSTRINGCAST string, wxStrlen(WXSTRINGCAST string), &sizeRect);
GetTextMetrics(dc, &tm); GetTextMetrics(dc, &tm);
ReleaseDC(NULL, dc); ReleaseDC(NULL, dc);
if ( x ) if ( x )
*x = sizeRect.cx; *x = sizeRect.cx;
if ( y ) if ( y )
*y = sizeRect.cy; *y = sizeRect.cy;
if ( descent ) if ( descent )
*descent = tm.tmDescent; *descent = tm.tmDescent;
if ( externalLeading ) if ( externalLeading )
*externalLeading = tm.tmExternalLeading; *externalLeading = tm.tmExternalLeading;
} }
wxMetafile *wxMetafileDC::Close(void) wxMetafile *wxMetafileDC::Close()
{ {
SelectOldObjects(m_hDC); SelectOldObjects(m_hDC);
HANDLE mf = CloseMetaFile((HDC) m_hDC); HANDLE mf = CloseMetaFile((HDC) m_hDC);
m_hDC = 0; m_hDC = 0;
if (mf) if (mf)
{ {
wxMetafile *wx_mf = new wxMetafile; wxMetafile *wx_mf = new wxMetafile;
wx_mf->SetHMETAFILE((WXHANDLE) mf); wx_mf->SetHMETAFILE((WXHANDLE) mf);
wx_mf->SetWindowsMappingMode(m_windowsMappingMode); wx_mf->SetWindowsMappingMode(m_windowsMappingMode);
return wx_mf; return wx_mf;
} }
return NULL; return NULL;
} }
void wxMetafileDC::SetMapMode(int mode) void wxMetafileDC::SetMapMode(int mode)
{ {
m_mappingMode = mode; m_mappingMode = mode;
// int pixel_width = 0; // int pixel_width = 0;
// int pixel_height = 0; // int pixel_height = 0;
// int mm_width = 0; // int mm_width = 0;
// int mm_height = 0; // int mm_height = 0;
float mm2pixelsX = 10.0; float mm2pixelsX = 10.0;
float mm2pixelsY = 10.0; float mm2pixelsY = 10.0;
switch (mode) switch (mode)
{
case wxMM_TWIPS:
{ {
m_logicalScaleX = (float)(twips2mm * mm2pixelsX); case wxMM_TWIPS:
m_logicalScaleY = (float)(twips2mm * mm2pixelsY); {
break; m_logicalScaleX = (float)(twips2mm * mm2pixelsX);
m_logicalScaleY = (float)(twips2mm * mm2pixelsY);
break;
}
case wxMM_POINTS:
{
m_logicalScaleX = (float)(pt2mm * mm2pixelsX);
m_logicalScaleY = (float)(pt2mm * mm2pixelsY);
break;
}
case wxMM_METRIC:
{
m_logicalScaleX = mm2pixelsX;
m_logicalScaleY = mm2pixelsY;
break;
}
case wxMM_LOMETRIC:
{
m_logicalScaleX = (float)(mm2pixelsX/10.0);
m_logicalScaleY = (float)(mm2pixelsY/10.0);
break;
}
default:
case wxMM_TEXT:
{
m_logicalScaleX = 1.0;
m_logicalScaleY = 1.0;
break;
}
} }
case wxMM_POINTS: m_windowExtX = 100;
{ m_windowExtY = 100;
m_logicalScaleX = (float)(pt2mm * mm2pixelsX);
m_logicalScaleY = (float)(pt2mm * mm2pixelsY);
break;
}
case wxMM_METRIC:
{
m_logicalScaleX = mm2pixelsX;
m_logicalScaleY = mm2pixelsY;
break;
}
case wxMM_LOMETRIC:
{
m_logicalScaleX = (float)(mm2pixelsX/10.0);
m_logicalScaleY = (float)(mm2pixelsY/10.0);
break;
}
default:
case wxMM_TEXT:
{
m_logicalScaleX = 1.0;
m_logicalScaleY = 1.0;
break;
}
}
m_windowExtX = 100;
m_windowExtY = 100;
} }
// ----------------------------------------------------------------------------
// wxMakeMetafilePlaceable
// ----------------------------------------------------------------------------
#ifdef __WIN32__ #ifdef __WIN32__
struct RECT32 struct RECT32
{ {
@@ -285,21 +315,21 @@ struct RECT32
}; };
struct mfPLACEABLEHEADER { struct mfPLACEABLEHEADER {
DWORD key; DWORD key;
short hmf; short hmf;
RECT32 bbox; RECT32 bbox;
WORD inch; WORD inch;
DWORD reserved; DWORD reserved;
WORD checksum; WORD checksum;
}; };
#else #else
struct mfPLACEABLEHEADER { struct mfPLACEABLEHEADER {
DWORD key; DWORD key;
HANDLE hmf; HANDLE hmf;
RECT bbox; RECT bbox;
WORD inch; WORD inch;
DWORD reserved; DWORD reserved;
WORD checksum; WORD checksum;
}; };
#endif #endif
@@ -309,7 +339,7 @@ struct mfPLACEABLEHEADER {
* and sets the window origin and extent to mimic the wxMM_TEXT mapping mode. * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
* *
*/ */
bool wxMakeMetafilePlaceable(const wxString& filename, float scale) bool wxMakeMetafilePlaceable(const wxString& filename, float scale)
{ {
return wxMakeMetafilePlaceable(filename, 0, 0, 0, 0, scale, FALSE); return wxMakeMetafilePlaceable(filename, 0, 0, 0, 0, scale, FALSE);
@@ -317,100 +347,140 @@ bool wxMakeMetafilePlaceable(const wxString& filename, float scale)
bool wxMakeMetafilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale, bool useOriginAndExtent) bool wxMakeMetafilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale, bool useOriginAndExtent)
{ {
// I'm not sure if this is the correct way of suggesting a scale // I'm not sure if this is the correct way of suggesting a scale
// to the client application, but it's the only way I can find. // to the client application, but it's the only way I can find.
int unitsPerInch = (int)(576/scale); int unitsPerInch = (int)(576/scale);
mfPLACEABLEHEADER header;
header.key = 0x9AC6CDD7L;
header.hmf = 0;
header.bbox.left = (int)(x1);
header.bbox.top = (int)(y1);
header.bbox.right = (int)(x2);
header.bbox.bottom = (int)(y2);
header.inch = unitsPerInch;
header.reserved = 0;
// Calculate checksum mfPLACEABLEHEADER header;
WORD *p; header.key = 0x9AC6CDD7L;
mfPLACEABLEHEADER *pMFHead = &header; header.hmf = 0;
for (p =(WORD *)pMFHead,pMFHead -> checksum = 0; header.bbox.left = (int)(x1);
p < (WORD *)&pMFHead ->checksum; ++p) header.bbox.top = (int)(y1);
pMFHead ->checksum ^= *p; header.bbox.right = (int)(x2);
header.bbox.bottom = (int)(y2);
header.inch = unitsPerInch;
header.reserved = 0;
FILE *fd = fopen(filename.fn_str(), "rb"); // Calculate checksum
if (!fd) return FALSE; WORD *p;
mfPLACEABLEHEADER *pMFHead = &header;
wxChar tempFileBuf[256]; for (p =(WORD *)pMFHead,pMFHead -> checksum = 0;
wxGetTempFileName(wxT("mf"), tempFileBuf); p < (WORD *)&pMFHead ->checksum; ++p)
FILE *fHandle = fopen(wxConvFile.cWX2MB(tempFileBuf), "wb"); pMFHead ->checksum ^= *p;
if (!fHandle)
return FALSE;
fwrite((void *)&header, sizeof(unsigned char), sizeof(mfPLACEABLEHEADER), fHandle);
// Calculate origin and extent FILE *fd = fopen(filename.fn_str(), "rb");
int originX = x1; if (!fd) return FALSE;
int originY = y1;
int extentX = x2 - x1;
int extentY = (y2 - y1);
// Read metafile header and write wxChar tempFileBuf[256];
METAHEADER metaHeader; wxGetTempFileName(wxT("mf"), tempFileBuf);
fread((void *)&metaHeader, sizeof(unsigned char), sizeof(metaHeader), fd); FILE *fHandle = fopen(wxConvFile.cWX2MB(tempFileBuf), "wb");
if (!fHandle)
if (useOriginAndExtent) return FALSE;
metaHeader.mtSize += 15; fwrite((void *)&header, sizeof(unsigned char), sizeof(mfPLACEABLEHEADER), fHandle);
else
metaHeader.mtSize += 5;
fwrite((void *)&metaHeader, sizeof(unsigned char), sizeof(metaHeader), fHandle);
// Write SetMapMode, SetWindowOrigin and SetWindowExt records // Calculate origin and extent
char modeBuffer[8]; int originX = x1;
char originBuffer[10]; int originY = y1;
char extentBuffer[10]; int extentX = x2 - x1;
METARECORD *modeRecord = (METARECORD *)&modeBuffer; int extentY = (y2 - y1);
METARECORD *originRecord = (METARECORD *)&originBuffer; // Read metafile header and write
METARECORD *extentRecord = (METARECORD *)&extentBuffer; METAHEADER metaHeader;
fread((void *)&metaHeader, sizeof(unsigned char), sizeof(metaHeader), fd);
modeRecord->rdSize = 4; if (useOriginAndExtent)
modeRecord->rdFunction = META_SETMAPMODE; metaHeader.mtSize += 15;
modeRecord->rdParm[0] = MM_ANISOTROPIC; else
metaHeader.mtSize += 5;
originRecord->rdSize = 5; fwrite((void *)&metaHeader, sizeof(unsigned char), sizeof(metaHeader), fHandle);
originRecord->rdFunction = META_SETWINDOWORG;
originRecord->rdParm[0] = originY;
originRecord->rdParm[1] = originX;
extentRecord->rdSize = 5; // Write SetMapMode, SetWindowOrigin and SetWindowExt records
extentRecord->rdFunction = META_SETWINDOWEXT; char modeBuffer[8];
extentRecord->rdParm[0] = extentY; char originBuffer[10];
extentRecord->rdParm[1] = extentX; char extentBuffer[10];
METARECORD *modeRecord = (METARECORD *)&modeBuffer;
fwrite((void *)modeBuffer, sizeof(char), 8, fHandle); METARECORD *originRecord = (METARECORD *)&originBuffer;
METARECORD *extentRecord = (METARECORD *)&extentBuffer;
if (useOriginAndExtent)
{
fwrite((void *)originBuffer, sizeof(char), 10, fHandle);
fwrite((void *)extentBuffer, sizeof(char), 10, fHandle);
}
int ch = -2; modeRecord->rdSize = 4;
while (ch != EOF) modeRecord->rdFunction = META_SETMAPMODE;
{ modeRecord->rdParm[0] = MM_ANISOTROPIC;
ch = getc(fd);
if (ch != EOF) originRecord->rdSize = 5;
originRecord->rdFunction = META_SETWINDOWORG;
originRecord->rdParm[0] = originY;
originRecord->rdParm[1] = originX;
extentRecord->rdSize = 5;
extentRecord->rdFunction = META_SETWINDOWEXT;
extentRecord->rdParm[0] = extentY;
extentRecord->rdParm[1] = extentX;
fwrite((void *)modeBuffer, sizeof(char), 8, fHandle);
if (useOriginAndExtent)
{ {
putc(ch, fHandle); fwrite((void *)originBuffer, sizeof(char), 10, fHandle);
fwrite((void *)extentBuffer, sizeof(char), 10, fHandle);
} }
}
fclose(fHandle); int ch = -2;
fclose(fd); while (ch != EOF)
wxRemoveFile(filename); {
wxCopyFile(tempFileBuf, filename); ch = getc(fd);
wxRemoveFile(tempFileBuf); if (ch != EOF)
return TRUE; {
putc(ch, fHandle);
}
}
fclose(fHandle);
fclose(fd);
wxRemoveFile(filename);
wxCopyFile(tempFileBuf, filename);
wxRemoveFile(tempFileBuf);
return TRUE;
}
// ----------------------------------------------------------------------------
// wxMetafileDataObject
// ----------------------------------------------------------------------------
size_t wxMetafileDataObject::GetDataSize() const
{
return sizeof(METAFILEPICT);
}
bool wxMetafileDataObject::GetDataHere(void *buf) const
{
METAFILEPICT *mfpict = (METAFILEPICT *)buf;
const wxMetafile mf = GetMetafile();
mfpict->mm = mf.GetWindowsMappingMode();
mfpict->xExt = mf.GetWidth();
mfpict->yExt = mf.GetHeight();
mfpict->hMF = (HMETAFILE)mf.GetHMETAFILE();
wxCHECK_MSG( mfpict->hMF, FALSE, _T("copying invalid metafile") );
return TRUE;
}
bool wxMetafileDataObject::SetData(size_t WXUNUSED(len), const void *buf)
{
const METAFILEPICT *mfpict = (const METAFILEPICT *)buf;
wxMetafile mf;
mf.SetWindowsMappingMode(mfpict->mm);
mf.SetWidth(mfpict->xExt);
mf.SetHeight(mfpict->yExt);
mf.SetHMETAFILE((WXHANDLE)mfpict->hMF);
wxCHECK_MSG( mfpict->hMF, FALSE, _T("pasting invalid metafile") );
SetMetafile(mf);
return TRUE;
} }
#endif // wxUSE_METAFILE #endif // wxUSE_METAFILE

View File

@@ -298,6 +298,12 @@ STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium)
break; break;
case wxDF_METAFILE: case wxDF_METAFILE:
pmedium->hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE,
sizeof(METAFILEPICT));
if ( !pmedium->hGlobal ) {
wxLogLastError("GlobalAlloc");
return E_OUTOFMEMORY;
}
pmedium->tymed = TYMED_MFPICT; pmedium->tymed = TYMED_MFPICT;
break; break;
@@ -334,7 +340,7 @@ STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium)
hr = GetDataHere(pformatetcIn, pmedium); hr = GetDataHere(pformatetcIn, pmedium);
if ( FAILED(hr) ) { if ( FAILED(hr) ) {
// free resources we allocated // free resources we allocated
if ( pmedium->tymed == TYMED_HGLOBAL ) { if ( pmedium->tymed & (TYMED_HGLOBAL | TYMED_MFPICT) ) {
GlobalFree(pmedium->hGlobal); GlobalFree(pmedium->hGlobal);
} }
@@ -358,11 +364,6 @@ STDMETHODIMP wxIDataObject::GetDataHere(FORMATETC *pformatetc,
break; break;
case TYMED_MFPICT: case TYMED_MFPICT:
// this should be copied on bitmaps - but I don't have time for
// this now
wxFAIL_MSG(wxT("TODO - no support for metafiles in wxDataObject"));
break;
case TYMED_HGLOBAL: case TYMED_HGLOBAL:
{ {
// copy data // copy data
@@ -409,11 +410,6 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc,
break; break;
case TYMED_MFPICT: case TYMED_MFPICT:
// this should be copied on bitmaps - but I don't have time for
// this now
wxFAIL_MSG(wxT("TODO - no support for metafiles in wxDataObject"));
break;
case TYMED_HGLOBAL: case TYMED_HGLOBAL:
{ {
wxDataFormat format = pformatetc->cfFormat; wxDataFormat format = pformatetc->cfFormat;
@@ -467,6 +463,10 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc,
size = 0; size = 0;
break; break;
case CF_METAFILEPICT:
size = sizeof(METAFILEPICT);
break;
default: default:
{ {
// we suppose that the size precedes the data // we suppose that the size precedes the data
@@ -491,11 +491,17 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc,
} }
if ( fRelease ) { if ( fRelease ) {
// we own the medium, so we must release it - but do *not* free the // we own the medium, so we must release it - but do *not* free any
// bitmap handle fi we have it because we have copied it elsewhere // data we pass by handle because we have copied it elsewhere
if ( pmedium->tymed == TYMED_GDI ) switch ( pmedium->tymed )
{ {
pmedium->hBitmap = 0; case TYMED_GDI:
pmedium->hBitmap = 0;
break;
case TYMED_MFPICT:
pmedium->hMetaFilePict = 0;
break;
} }
ReleaseStgMedium(pmedium); ReleaseStgMedium(pmedium);
@@ -759,7 +765,7 @@ bool wxBitmapDataObject2::GetDataHere(void *pBuf) const
return TRUE; return TRUE;
} }
bool wxBitmapDataObject2::SetData(size_t len, const void *pBuf) bool wxBitmapDataObject2::SetData(size_t WXUNUSED(len), const void *pBuf)
{ {
HBITMAP hbmp = *(HBITMAP *)pBuf; HBITMAP hbmp = *(HBITMAP *)pBuf;