]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dcprint.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPrinterDC class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dcprint.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/dcprint.h"
31 #if wxUSE_COMMON_DIALOGS
51 #if !USE_SHARED_LIBRARY
52 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
55 wxPrinterDC::wxPrinterDC(const wxString
& driver_name
, const wxString
& device_name
, const wxString
& file
, bool interactive
, int orientation
)
57 m_isInteractive
= interactive
;
59 if (!file
.IsNull() && file
!= "")
62 #if wxUSE_COMMON_DIALOGS
67 pd
.lStructSize
= sizeof( PRINTDLG
);
69 pd
.hDevMode
=(HANDLE
)NULL
;
70 pd
.hDevNames
=(HANDLE
)NULL
;
71 pd
.Flags
=PD_RETURNDC
| PD_NOSELECTION
| PD_NOPAGENUMS
;
77 pd
.hInstance
=(HINSTANCE
)NULL
;
79 if ( PrintDlg( &pd
) != 0 )
81 m_hDC
= (WXHDC
) pd
.hDC
;
90 // m_dontDelete = TRUE;
94 if ((!driver_name
.IsNull() && driver_name
!= "") &&
95 (!device_name
.IsNull() && device_name
!= "") &&
96 (!file
.IsNull() && file
!= ""))
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
;
103 m_hDC
= wxGetPrinterDC(orientation
);
104 m_ok
= m_hDC
? TRUE
: FALSE
;
109 // int width = GetDeviceCaps(m_hDC, VERTRES);
110 // int height = GetDeviceCaps(m_hDC, HORZRES);
113 SetBrush(*wxBLACK_BRUSH
);
114 SetPen(*wxBLACK_PEN
);
117 wxPrinterDC::wxPrinterDC(WXHDC theDC
)
119 m_isInteractive
= FALSE
;
125 // int width = GetDeviceCaps(m_hDC, VERTRES);
126 // int height = GetDeviceCaps(m_hDC, HORZRES);
129 SetBrush(*wxBLACK_BRUSH
);
130 SetPen(*wxBLACK_PEN
);
133 wxPrinterDC::~wxPrinterDC(void)
137 WXHDC
wxGetPrinterDC(int orientation
)
140 LPDEVMODE lpDevMode
= NULL
;
141 LPDEVNAMES lpDevNames
;
142 LPSTR lpszDriverName
;
143 LPSTR lpszDeviceName
;
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
;
155 if (!PrintDlg((LPPRINTDLG
)&pd
))
158 GlobalFree(pd
.hDevMode
);
160 GlobalFree(pd
.hDevNames
);
168 GlobalFree(pd
.hDevMode
);
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
);
179 lpDevMode
= (DEVMODE
*) GlobalLock(pd
.hDevMode
);
180 lpDevMode
->dmOrientation
= orientation
;
181 lpDevMode
->dmFields
|= DM_ORIENTATION
;
185 hDC
= CreateDC(lpszDriverName
, lpszDeviceName
, lpszPortName
, (DEVMODE
*)lpDevMode
);
187 hDC
= CreateDC(lpszDriverName
, lpszDeviceName
, lpszPortName
, (LPSTR
)lpDevMode
);
190 if (pd
.hDevMode
&& lpDevMode
)
191 GlobalUnlock(pd
.hDevMode
);
195 GlobalFree(pd
.hDevNames
);
200 GlobalFree(pd
.hDevMode
);