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