1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
//===============================================================
// vwinprtr.cpp - Windows Printer class
//
// Copyright (C) 1995,1996, 1997, 1998 Bruce E. Wampler
//
// This file is part of the V C++ GUI Framework, and is covered
// under the terms of the GNU Library General Public License,
// Version 2. This library has NO WARRANTY. See the source file
// vapp.cxx for more complete information about license terms.
//===============================================================
#include <v/vwin32.h> // for Win 32 stuff
#include <v/vapp.h>
#include <v/vwinprtr.h>
#include <commdlg.h>
int vWinPrinter::_instances = 0; // reference counter for copy / assignment
//================>>> vWinPrinter::vWinPrinter <<<========================
vWinPrinter::vWinPrinter()
{
_name = 0;
_paperType = vPaperDefault;
_copies = 1;
_toFile = 1;
_width = 1;
_height = 1;
_portrait = 1;
_useColor = 0;
_printhDC = 0;
++_instances; // bump reference counter
}
//================>>> vWinPrinter::vWinPrinter <<<========================
vWinPrinter::vWinPrinter(const vWinPrinter& pr)
{
// copy constructor
_name = pr._name;
_width = pr._width;
_height = pr._height;
_portrait = pr._portrait;
_useColor = pr._useColor;
_paperType = pr._paperType;
_copies = pr._copies;
_toFile = pr._toFile;
_printhDC = pr._printhDC;
++_instances; // bump reference counter
}
//================>>> vWinPrinter::= <<<========================
vWinPrinter& vWinPrinter::operator =(const vWinPrinter& pr)
{
if (this == &pr) // to self?
return *this;
if (_name)
delete [] _name; // free space before overwrite
_name = pr._name;
_width = pr._width;
_height = pr._height;
_portrait = pr._portrait;
_useColor = pr._useColor;
_paperType = pr._paperType;
_copies = pr._copies;
_toFile = pr._toFile;
_printhDC = pr._printhDC;
return *this;
}
//================>>> vWinPrinter::~vWinPrinter <<<========================
vWinPrinter::~vWinPrinter()
{
// We are using a reference count to track instances of printers.
// We want to allow the user to pass copies of the single printer
// around, but there should only be one name and one stream;
--_instances; // not reference any more
if (_instances > 0)
return; // don't do anything else
if (_name)
delete [] _name;
}
//================>>> vWinPrinter::GetPaperName <<<========================
char* vWinPrinter::GetPaperName()
{
if (_paperType == vPaperLetter) // we have (8.5x11) added...
return "Letter";
else
return "Unknown";
}
//================>>> vWinPrinter::Setup <<<========================
int vWinPrinter::Setup(VCONST char* fn)
{
// fn is an override default name
PRINTDLG pd;
if (_printhDC != 0)
return 0;
pd.lStructSize = sizeof( PRINTDLG );
pd.hwndOwner=NULL;
pd.hDevMode=(HANDLE)NULL;
pd.hDevNames=(HANDLE)NULL;
pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS |
PD_HIDEPRINTTOFILE;
pd.nFromPage=0;
pd.nToPage=0;
pd.nMinPage=0;
pd.nMaxPage=0;
pd.nCopies=1;
pd.hInstance=(HINSTANCE)NULL;
pd.lCustData = (LPARAM)0;
pd.lpfnPrintHook = 0;
pd.lpfnSetupHook = 0;
pd.lpPrintTemplateName = (LPCSTR) 0;
pd.lpSetupTemplateName = (LPCSTR) 0;
pd.hPrintTemplate = (HGLOBAL)0;
pd.hSetupTemplate = (HGLOBAL)0;
if ( ::PrintDlg( &pd ) != 0 )
{
int pixw, pixh;
_printhDC = pd.hDC;
pixw = ::GetDeviceCaps(_printhDC, HORZRES);
pixh = ::GetDeviceCaps(_printhDC, VERTRES);
// This scaling gives about the same proportions as the X version
_width = ::GetDeviceCaps(_printhDC, HORZSIZE) * 3;
_height = ::GetDeviceCaps(_printhDC,VERTSIZE) * 3;
// ::SetMapMode(_printhDC, MM_ISOTROPIC);
// ::SetWindowExt(_printhDC,_width,_height);
// ::SetViewportExt(_printhDC,pixw,pixh);
}
return _printhDC != 0;
}
|