/////////////////////////////////////////////////////////////////////////////
-// Name: printdlg.cpp
+// Name: src/msw/printdlg.cpp
// Purpose: wxPrintDialog, wxPageSetupDialog
// Author: Julian Smart
// Modified by:
#if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXUNIVERSAL__) || !wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
#ifndef WX_PRECOMP
+ #include "wx/msw/wrapcdlg.h"
#include "wx/app.h"
+ #include "wx/dcprint.h"
+ #include "wx/cmndata.h"
#endif
-#include "wx/cmndata.h"
#include "wx/printdlg.h"
#include "wx/msw/printdlg.h"
-#include "wx/dcprint.h"
#include "wx/paper.h"
#include <stdlib.h>
-#include "wx/msw/wrapcdlg.h"
-
#ifndef __WIN32__
#include <print.h>
#endif
else
{
hDev = GlobalAlloc(GPTR, 4*sizeof(WORD)+
- ( driverName.Length() + 1 +
- printerName.Length() + 1 +
- portName.Length()+1 ) * sizeof(wxChar) );
+ ( driverName.length() + 1 +
+ printerName.length() + 1 +
+ portName.length()+1 ) * sizeof(wxChar) );
LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(hDev);
lpDev->wDriverOffset = sizeof(WORD) * 4 / sizeof(wxChar);
wxStrcpy((wxChar*)lpDev + lpDev->wDriverOffset, driverName);
lpDev->wDeviceOffset = (WORD)( lpDev->wDriverOffset +
- driverName.Length() + 1 );
+ driverName.length() + 1 );
wxStrcpy((wxChar*)lpDev + lpDev->wDeviceOffset, printerName);
lpDev->wOutputOffset = (WORD)( lpDev->wDeviceOffset +
- printerName.Length() + 1 );
+ printerName.length() + 1 );
wxStrcpy((wxChar*)lpDev + lpDev->wOutputOffset, portName);
lpDev->wDefault = 0;
GlobalFree(hDevNames);
}
-bool wxWindowsPrintNativeData::Ok() const
+bool wxWindowsPrintNativeData::IsOk() const
{
return (m_devMode != NULL) ;
}
} else {
data.SetBin(wxPRINTBIN_DEFAULT);
}
-
+ if (devMode->dmFields & DM_MEDIATYPE)
+ {
+ wxASSERT( (int)devMode->dmMediaType != wxPRINTMEDIA_DEFAULT );
+ data.SetMedia(devMode->dmMediaType);
+ }
//// Printer name
if (devMode->dmDeviceName[0] != 0)
// This syntax fixes a crash when using VS 7.1
devMode->dmFields |= DM_COLOR;
//// Paper size
- if (data.GetPaperId() == wxPAPER_NONE)
+
+ // Paper id has priority over paper size. If id is specified, then size
+ // is ignored (as it can be filled in even for standard paper sizes)
+
+ wxPrintPaperType *paperType = NULL;
+
+ const wxPaperSize paperId = data.GetPaperId();
+ if ( paperId != wxPAPER_NONE && wxThePrintPaperDatabase )
{
- // DEVMODE is in tenths of a milimeter
- devMode->dmPaperWidth = (short)(data.GetPaperSize().x * 10);
- devMode->dmPaperLength = (short)(data.GetPaperSize().y * 10);
- if(m_customWindowsPaperId != 0)
- devMode->dmPaperSize = m_customWindowsPaperId;
- else
- devMode->dmPaperSize = DMPAPER_USER;
- devMode->dmFields |= DM_PAPERWIDTH;
- devMode->dmFields |= DM_PAPERLENGTH;
+ paperType = wxThePrintPaperDatabase->FindPaperType(paperId);
}
- else
+
+ if ( paperType )
{
- if (wxThePrintPaperDatabase)
+ devMode->dmPaperSize = (short)paperType->GetPlatformId();
+ devMode->dmFields |= DM_PAPERSIZE;
+ }
+ else // custom (or no) paper size
+ {
+ const wxSize paperSize = data.GetPaperSize();
+ if ( paperSize != wxDefaultSize )
{
- wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType( data.GetPaperId() );
- if (paper)
- {
- devMode->dmPaperSize = (short)paper->GetPlatformId();
- devMode->dmFields |= DM_PAPERSIZE;
- }
+ // Fall back on specifying the paper size explicitly
+ if(m_customWindowsPaperId != 0)
+ devMode->dmPaperSize = m_customWindowsPaperId;
else
- {
- // Fall back on specifying the paper size explicitly
- devMode->dmPaperWidth = (short)(data.GetPaperSize().x * 10);
- devMode->dmPaperLength = (short)(data.GetPaperSize().y * 10);
devMode->dmPaperSize = DMPAPER_USER;
- devMode->dmFields |= DM_PAPERWIDTH;
- devMode->dmFields |= DM_PAPERLENGTH;
- }
+ devMode->dmPaperWidth = (short)(paperSize.x * 10);
+ devMode->dmPaperLength = (short)(paperSize.y * 10);
+ devMode->dmFields |= DM_PAPERWIDTH;
+ devMode->dmFields |= DM_PAPERLENGTH;
}
+ //else: neither paper type nor size specified, don't fill DEVMODE
+ // at all so that the system defaults are used
}
//// Duplex
devMode->dmFields |= DM_DEFAULTSOURCE;
}
-
+ if (data.GetMedia() != wxPRINTMEDIA_DEFAULT)
+ {
+ devMode->dmMediaType = data.GetMedia();
+ devMode->dmFields |= DM_MEDIATYPE;
+ }
GlobalUnlock(hDevMode);
}
return m_printerDC;
}
else
- return (wxDC*) NULL;
+ return (wxPrinterDC*) NULL;
}
bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data )