]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dcprint.cpp
dd2a5488130dbbb84c9941629446ff0df56dc6d2
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
14 #pragma implementation "dcprint.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
27 #include "wx/dcprint.h"
32 #if wxUSE_COMMON_DIALOGS
52 #if !USE_SHARED_LIBRARY
53 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
56 wxPrinterDC::wxPrinterDC(const wxString
& driver_name
, const wxString
& device_name
, const wxString
& file
, bool interactive
, int orientation
)
58 m_isInteractive
= interactive
;
60 if (!file
.IsNull() && file
!= "")
63 #if wxUSE_COMMON_DIALOGS
68 pd
.lStructSize
= sizeof( PRINTDLG
);
70 pd
.hDevMode
=(HANDLE
)NULL
;
71 pd
.hDevNames
=(HANDLE
)NULL
;
72 pd
.Flags
=PD_RETURNDC
| PD_NOSELECTION
| PD_NOPAGENUMS
;
78 pd
.hInstance
=(HINSTANCE
)NULL
;
80 if ( PrintDlg( &pd
) != 0 )
82 m_hDC
= (WXHDC
) pd
.hDC
;
91 // m_dontDelete = TRUE;
95 if ((!driver_name
.IsNull() && driver_name
!= "") &&
96 (!device_name
.IsNull() && device_name
!= "") &&
97 (!file
.IsNull() && file
!= ""))
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
;
104 m_hDC
= wxGetPrinterDC(orientation
);
105 m_ok
= m_hDC
? TRUE
: FALSE
;
110 // int width = GetDeviceCaps(m_hDC, VERTRES);
111 // int height = GetDeviceCaps(m_hDC, HORZRES);
114 SetBrush(*wxBLACK_BRUSH
);
115 SetPen(*wxBLACK_PEN
);
118 wxPrinterDC::wxPrinterDC(WXHDC theDC
)
120 m_isInteractive
= FALSE
;
126 // int width = GetDeviceCaps(m_hDC, VERTRES);
127 // int height = GetDeviceCaps(m_hDC, HORZRES);
130 SetBrush(*wxBLACK_BRUSH
);
131 SetPen(*wxBLACK_PEN
);
134 wxPrinterDC::~wxPrinterDC(void)
138 WXHDC
wxGetPrinterDC(int orientation
)
141 LPDEVMODE lpDevMode
= NULL
;
142 LPDEVNAMES lpDevNames
;
143 LPSTR lpszDriverName
;
144 LPSTR lpszDeviceName
;
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
;
156 if (!PrintDlg((LPPRINTDLG
)&pd
))
159 GlobalFree(pd
.hDevMode
);
161 GlobalFree(pd
.hDevNames
);
169 GlobalFree(pd
.hDevMode
);
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
);
180 lpDevMode
= (DEVMODE
*) GlobalLock(pd
.hDevMode
);
181 lpDevMode
->dmOrientation
= orientation
;
182 lpDevMode
->dmFields
|= DM_ORIENTATION
;
186 hDC
= CreateDC(lpszDriverName
, lpszDeviceName
, lpszPortName
, (DEVMODE
*)lpDevMode
);
188 hDC
= CreateDC(lpszDriverName
, lpszDeviceName
, lpszPortName
, (LPSTR
)lpDevMode
);
191 if (pd
.hDevMode
&& lpDevMode
)
192 GlobalUnlock(pd
.hDevMode
);
196 GlobalFree(pd
.hDevNames
);
201 GlobalFree(pd
.hDevMode
);