X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c4e7c2aa5822f9a6e97d8d7848b95ea2eadcd98b..2356708db31b737c6eae53c2316b642aa5a2e68d:/src/msw/metafile.cpp diff --git a/src/msw/metafile.cpp b/src/msw/metafile.cpp index c22d980311..0d4a30f506 100644 --- a/src/msw/metafile.cpp +++ b/src/msw/metafile.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: metafile.cpp -// Purpose: wxMetaFileDC etc. +// Purpose: wxMetafileDC etc. // Author: Julian Smart // Modified by: // Created: 04/01/98 @@ -24,7 +24,7 @@ #include "wx/setup.h" #endif -#if USE_METAFILE +#if wxUSE_METAFILE #ifndef WX_PRECOMP #include "wx/utils.h" @@ -41,53 +41,90 @@ extern bool wxClipboardIsOpen; #if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxMetaFile, wxObject) -IMPLEMENT_ABSTRACT_CLASS(wxMetaFileDC, wxDC) +IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject) +IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC) #endif /* - * Metafiles - Windows 3.1 only + * Metafiles * Currently, the only purpose for making a metafile is to put * it on the clipboard. */ -wxMetaFile::wxMetaFile(const wxString& file) +wxMetafileRefData::wxMetafileRefData(void) { - m_windowsMappingMode = MM_ANISOTROPIC; - m_metaFile = 0; - if (!file.IsNull() && file == "") - m_metaFile = (WXHANDLE) GetMetaFile(file); + m_metafile = 0; + m_windowsMappingMode = wxMM_ANISOTROPIC; } -wxMetaFile::~wxMetaFile(void) +wxMetafileRefData::~wxMetafileRefData(void) { - if (m_metaFile) - { DeleteMetaFile((HMETAFILE) m_metaFile); m_metaFile = 0; } + if (m_metafile) + { + DeleteMetaFile((HMETAFILE) m_metafile); + m_metafile = 0; + } } -bool wxMetaFile::SetClipboard(int width, int height) +wxMetafile::wxMetafile(const wxString& file) { - bool alreadyOpen=wxClipboardOpen(); - if (!alreadyOpen) - { - wxOpenClipboard(); - if (!wxEmptyClipboard()) return FALSE; - } - bool success = wxSetClipboardData(wxCF_METAFILE,this, width,height); - if (!alreadyOpen) wxCloseClipboard(); - return (bool) success; + m_refData = new wxMetafileRefData; + + M_METAFILEDATA->m_windowsMappingMode = wxMM_ANISOTROPIC; + M_METAFILEDATA->m_metafile = 0; + if (!file.IsNull() && (file.Cmp(_T("")) == 0)) + M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file); } -bool wxMetaFile::Play(wxDC *dc) +wxMetafile::~wxMetafile(void) { - dc->BeginDrawing(); +} - if (dc->GetHDC() && m_metaFile) - PlayMetaFile((HDC) dc->GetHDC(), (HMETAFILE) m_metaFile); +bool wxMetafile::SetClipboard(int width, int height) +{ + if (!m_refData) + return FALSE; - dc->EndDrawing(); + bool alreadyOpen=wxClipboardOpen(); + if (!alreadyOpen) + { + wxOpenClipboard(); + if (!wxEmptyClipboard()) return FALSE; + } + bool success = wxSetClipboardData(wxDF_METAFILE, this, width,height); + if (!alreadyOpen) wxCloseClipboard(); + return (bool) success; +} - return TRUE; +bool wxMetafile::Play(wxDC *dc) +{ + if (!m_refData) + return FALSE; + + dc->BeginDrawing(); + + if (dc->GetHDC() && M_METAFILEDATA->m_metafile) + PlayMetaFile((HDC) dc->GetHDC(), (HMETAFILE) M_METAFILEDATA->m_metafile); + + dc->EndDrawing(); + + return TRUE; +} + +void wxMetafile::SetHMETAFILE(WXHANDLE mf) +{ + if (m_refData) + m_refData = new wxMetafileRefData; + + M_METAFILEDATA->m_metafile = mf; +} + +void wxMetafile::SetWindowsMappingMode(int mm) +{ + if (m_refData) + m_refData = new wxMetafileRefData; + + M_METAFILEDATA->m_windowsMappingMode = mm; } /* @@ -96,8 +133,8 @@ bool wxMetaFile::Play(wxDC *dc) */ // Original constructor that does not takes origin and extent. If you use this, -// *DO* give origin/extent arguments to wxMakeMetaFilePlaceable. -wxMetaFileDC::wxMetaFileDC(const wxString& file) +// *DO* give origin/extent arguments to wxMakeMetafilePlaceable. +wxMetafileDC::wxMetafileDC(const wxString& file) { m_metaFile = NULL; m_minX = 10000; @@ -108,25 +145,29 @@ wxMetaFileDC::wxMetaFileDC(const wxString& file) if (!file.IsNull() && wxFileExists(file)) wxRemoveFile(file); - m_hDC = (WXHDC) CreateMetaFile(file); - m_ok = TRUE; + if (!file.IsNull() && (file != _T(""))) + m_hDC = (WXHDC) CreateMetaFile(file); + else + m_hDC = (WXHDC) CreateMetaFile(NULL); + + m_ok = (m_hDC != (WXHDC) 0) ; // Actual Windows mapping mode, for future reference. - m_windowsMappingMode = MM_TEXT; - - SetMapMode(MM_TEXT); // NOTE: does not set HDC mapmode (this is correct) + m_windowsMappingMode = wxMM_TEXT; + + 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 -// give origin/extent arguments to wxMakeMetaFilePlaceable. -wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, int yorg) +// give origin/extent arguments to wxMakeMetafilePlaceable. +wxMetafileDC::wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg) { m_minX = 10000; m_minY = 10000; m_maxX = -10000; m_maxY = -10000; - if (file != "" && wxFileExists(file)) wxRemoveFile(file); + if (file != _T("") && wxFileExists(file)) wxRemoveFile(file); m_hDC = (WXHDC) CreateMetaFile(file); m_ok = TRUE; @@ -135,46 +176,50 @@ wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, i ::SetWindowExtEx((HDC) m_hDC,xext,yext, NULL); // Actual Windows mapping mode, for future reference. - m_windowsMappingMode = MM_ANISOTROPIC; - - SetMapMode(MM_TEXT); // NOTE: does not set HDC mapmode (this is correct) + m_windowsMappingMode = wxMM_ANISOTROPIC; + + SetMapMode(wxMM_TEXT); // NOTE: does not set HDC mapmode (this is correct) } -wxMetaFileDC::~wxMetaFileDC(void) +wxMetafileDC::~wxMetafileDC(void) { m_hDC = 0; } -void wxMetaFileDC::GetTextExtent(const wxString& string, float *x, float *y, - float *descent, float *externalLeading, wxFont *theFont, bool use16bit) +void wxMetafileDC::GetTextExtent(const wxString& string, long *x, long *y, + long *descent, long *externalLeading, wxFont *theFont, bool use16bit) const { wxFont *fontToUse = theFont; if (!fontToUse) - fontToUse = &m_font; + fontToUse = (wxFont*) &m_font; HDC dc = GetDC(NULL); SIZE sizeRect; TEXTMETRIC tm; - GetTextExtentPoint(dc, (char *)(const char *) string, strlen((char *)(const char *) string), &sizeRect); + GetTextExtentPoint(dc, WXSTRINGCAST string, wxStrlen(WXSTRINGCAST string), &sizeRect); GetTextMetrics(dc, &tm); ReleaseDC(NULL, dc); - *x = (float)XDEV2LOGREL(sizeRect.cx); - *y = (float)YDEV2LOGREL(sizeRect.cy); - if (descent) *descent = (float)tm.tmDescent; - if (externalLeading) *externalLeading = (float)tm.tmExternalLeading; + if ( x ) + *x = sizeRect.cx; + if ( y ) + *y = sizeRect.cy; + if ( descent ) + *descent = tm.tmDescent; + if ( externalLeading ) + *externalLeading = tm.tmExternalLeading; } -wxMetaFile *wxMetaFileDC::Close(void) +wxMetafile *wxMetafileDC::Close(void) { SelectOldObjects(m_hDC); HANDLE mf = CloseMetaFile((HDC) m_hDC); m_hDC = 0; if (mf) { - wxMetaFile *wx_mf = new wxMetaFile; + wxMetafile *wx_mf = new wxMetafile; wx_mf->SetHMETAFILE((WXHANDLE) mf); wx_mf->SetWindowsMappingMode(m_windowsMappingMode); return wx_mf; @@ -182,7 +227,7 @@ wxMetaFile *wxMetaFileDC::Close(void) return NULL; } -void wxMetaFileDC::SetMapMode(int mode) +void wxMetafileDC::SetMapMode(int mode) { m_mappingMode = mode; @@ -196,32 +241,32 @@ void wxMetaFileDC::SetMapMode(int mode) switch (mode) { - case MM_TWIPS: + case wxMM_TWIPS: { m_logicalScaleX = (float)(twips2mm * mm2pixelsX); m_logicalScaleY = (float)(twips2mm * mm2pixelsY); break; } - case MM_POINTS: + case wxMM_POINTS: { m_logicalScaleX = (float)(pt2mm * mm2pixelsX); m_logicalScaleY = (float)(pt2mm * mm2pixelsY); break; } - case MM_METRIC: + case wxMM_METRIC: { m_logicalScaleX = mm2pixelsX; m_logicalScaleY = mm2pixelsY; break; } - case MM_LOMETRIC: + case wxMM_LOMETRIC: { m_logicalScaleX = (float)(mm2pixelsX/10.0); m_logicalScaleY = (float)(mm2pixelsY/10.0); break; } default: - case MM_TEXT: + case wxMM_TEXT: { m_logicalScaleX = 1.0; m_logicalScaleY = 1.0; @@ -263,16 +308,16 @@ struct mfPLACEABLEHEADER { /* * Pass filename of existing non-placeable metafile, and bounding box. * Adds a placeable metafile header, sets the mapping mode to anisotropic, - * and sets the window origin and extent to mimic the MM_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); } -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 // to the client application, but it's the only way I can find. @@ -295,12 +340,12 @@ bool wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, i p < (WORD *)&pMFHead ->checksum; ++p) pMFHead ->checksum ^= *p; - FILE *fd = fopen((char *)(const char *)filename, "rb"); + FILE *fd = fopen(filename.mb_str(wxConvFile), "rb"); if (!fd) return FALSE; - char tempFileBuf[256]; - wxGetTempFileName("mf", tempFileBuf); - FILE *fHandle = fopen(tempFileBuf, "wb"); + wxChar tempFileBuf[256]; + wxGetTempFileName(_T("mf"), tempFileBuf); + FILE *fHandle = fopen(wxConvFile.cWX2MB(tempFileBuf), "wb"); if (!fHandle) return FALSE; fwrite((void *)&header, sizeof(unsigned char), sizeof(mfPLACEABLEHEADER), fHandle); @@ -370,4 +415,5 @@ bool wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, i return TRUE; } -#endif // USE_METAFILE +#endif // wxUSE_METAFILE +