]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dcprint.cpp
Changes mostly as a result of __WXSTUBS__ compilation. The stubs code now
[wxWidgets.git] / src / msw / dcprint.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: dcprint.cpp
3// Purpose: wxPrinterDC class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation
14#pragma implementation "dcprint.h"
15#endif
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25#endif
26
27#include "wx/dcprint.h"
28#include "math.h"
29#include "fstream.h"
30
31#include <windows.h>
32
33#if USE_COMMON_DIALOGS
34#include <commdlg.h>
35#endif
36
37#ifndef __WIN32__
38#include <print.h>
39#endif
40
41#ifdef DrawText
42#undef DrawText
43#endif
44
45#ifdef GetCharWidth
46#undef GetCharWidth
47#endif
48
49#ifdef StartDoc
50#undef StartDoc
51#endif
52
53#if !USE_SHARED_LIBRARY
54IMPLEMENT_CLASS(wxPrinterDC, wxDC)
55#endif
56
debe6624 57wxPrinterDC::wxPrinterDC(const wxString& driver_name, const wxString& device_name, const wxString& file, bool interactive, int orientation)
2bda0e17
KB
58{
59 m_isInteractive = interactive;
60
61 if (!file.IsNull() && file != "")
62 m_filename = file;
63
64#if USE_COMMON_DIALOGS
65 if (interactive)
66 {
67 PRINTDLG pd;
68
69 pd.lStructSize = sizeof( PRINTDLG );
70 pd.hwndOwner=NULL;
71 pd.hDevMode=(HANDLE)NULL;
72 pd.hDevNames=(HANDLE)NULL;
73 pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
74 pd.nFromPage=0;
75 pd.nToPage=0;
76 pd.nMinPage=0;
77 pd.nMaxPage=0;
78 pd.nCopies=1;
79 pd.hInstance=(HINSTANCE)NULL;
80
81 if ( PrintDlg( &pd ) != 0 )
82 {
83 m_hDC = (WXHDC) pd.hDC;
84 m_ok = TRUE;
85 }
86 else
87 {
88 m_ok = FALSE;
89 return;
90 }
91
92// m_dontDelete = TRUE;
93 }
94 else
95#endif
96 if ((!driver_name.IsNull() && driver_name != "") &&
97 (!device_name.IsNull() && device_name != "") &&
98 (!file.IsNull() && file != ""))
99 {
100 m_hDC = (WXHDC) CreateDC((char *) (const char *) driver_name, (char *) (const char *) device_name, (char *) (const char *) file, NULL);
101 m_ok = m_hDC ? TRUE: FALSE;
102 }
103 else
104 {
105 m_hDC = wxGetPrinterDC(orientation);
106 m_ok = m_hDC ? TRUE: FALSE;
107 }
108
109 if (m_hDC)
110 {
111// int width = GetDeviceCaps(m_hDC, VERTRES);
112// int height = GetDeviceCaps(m_hDC, HORZRES);
113 SetMapMode(MM_TEXT);
114 }
115 SetBrush(*wxBLACK_BRUSH);
116 SetPen(*wxBLACK_PEN);
117}
118
119wxPrinterDC::wxPrinterDC(WXHDC theDC)
120{
121 m_isInteractive = FALSE;
122
123 m_hDC = theDC;
124 m_ok = TRUE;
125 if (m_hDC)
126 {
127// int width = GetDeviceCaps(m_hDC, VERTRES);
128// int height = GetDeviceCaps(m_hDC, HORZRES);
129 SetMapMode(MM_TEXT);
130 }
131 SetBrush(*wxBLACK_BRUSH);
132 SetPen(*wxBLACK_PEN);
133}
134
135wxPrinterDC::~wxPrinterDC(void)
136{
137}
138
139WXHDC wxGetPrinterDC(int orientation)
140{
141 HDC hDC;
142 LPDEVMODE lpDevMode = NULL;
143 LPDEVNAMES lpDevNames;
144 LPSTR lpszDriverName;
145 LPSTR lpszDeviceName;
146 LPSTR lpszPortName;
147
148 PRINTDLG pd;
149 // __GNUWIN32__ has trouble believing PRINTDLG is 66 bytes - thinks it is 68
150 pd.lStructSize = 66; // sizeof(PRINTDLG);
151 pd.hwndOwner = (HWND)NULL;
152 pd.hDevMode = NULL; // Will be created by PrintDlg
153 pd.hDevNames = NULL; // Ditto
154 pd.Flags = PD_RETURNDEFAULT;
155 pd.nCopies = 1;
156
157 if (!PrintDlg((LPPRINTDLG)&pd))
158 {
159 if ( pd.hDevMode )
160 GlobalFree(pd.hDevMode);
161 if (pd.hDevNames)
162 GlobalFree(pd.hDevNames);
163
164 return(0);
165 }
166
167 if (!pd.hDevNames)
168 {
169 if ( pd.hDevMode )
170 GlobalFree(pd.hDevMode);
171 }
172
173 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
174 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
175 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
176 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
177 GlobalUnlock(pd.hDevNames);
178
179 if ( pd.hDevMode )
180 {
181 lpDevMode = (DEVMODE*) GlobalLock(pd.hDevMode);
182 lpDevMode->dmOrientation = orientation;
183 lpDevMode->dmFields |= DM_ORIENTATION;
184 }
185
186#ifdef __WIN32__
187 hDC = CreateDC(lpszDriverName, lpszDeviceName, lpszPortName, (DEVMODE *)lpDevMode);
188#else
189 hDC = CreateDC(lpszDriverName, lpszDeviceName, lpszPortName, (LPSTR)lpDevMode);
190#endif
191
192 if (pd.hDevMode && lpDevMode)
193 GlobalUnlock(pd.hDevMode);
194
195 if (pd.hDevNames)
196 {
197 GlobalFree(pd.hDevNames);
198 pd.hDevNames=NULL;
199 }
200 if (pd.hDevMode)
201 {
202 GlobalFree(pd.hDevMode);
203 pd.hDevMode=NULL;
204 }
205 return (WXHDC) hDC;
206}
207
208