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