]> git.saurik.com Git - wxWidgets.git/blame - src/msw/printdlg.cpp
better learn the operators...
[wxWidgets.git] / src / msw / printdlg.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: printdlg.cpp
3// Purpose: wxPrintDialog, wxPageSetupDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
103aec29 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
103aec29
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
103aec29 21 #pragma implementation "printdlg.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
2bda0e17
KB
25#include "wx/wxprec.h"
26
a3b46648 27#ifdef __BORLANDC__
103aec29 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
f6bcfd97
BP
31#if wxUSE_PRINTING_ARCHITECTURE
32
33#ifndef WX_PRECOMP
34 #include "wx/app.h"
35#endif
36
2bda0e17
KB
37#include "wx/printdlg.h"
38#include "wx/dcprint.h"
39
40// Have to emulate page setup dialog for Win16
41#if !defined(__WIN95__)
103aec29 42 #include "wx/generic/prntdlgg.h"
2bda0e17
KB
43#endif
44
45#include <stdlib.h>
42e69d6b
VZ
46
47#include "wx/msw/private.h"
48
2bda0e17
KB
49#include <commdlg.h>
50
51#ifndef __WIN32__
103aec29 52 #include <print.h>
2bda0e17
KB
53#endif
54
103aec29
VZ
55// ---------------------------------------------------------------------------
56// wxWin macros
57// ---------------------------------------------------------------------------
58
103aec29
VZ
59 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
60 IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
2bda0e17 61
103aec29
VZ
62// ===========================================================================
63// implementation
64// ===========================================================================
65
66// ---------------------------------------------------------------------------
67// wxPrintDialog
68// ---------------------------------------------------------------------------
69
70wxPrintDialog::wxPrintDialog()
2bda0e17 71{
7bcb11d3
JS
72 m_dialogParent = NULL;
73 m_printerDC = NULL;
74 m_destroyDC = TRUE;
2bda0e17
KB
75}
76
103aec29 77wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data)
2bda0e17 78{
7bcb11d3 79 Create(p, data);
2bda0e17
KB
80}
81
103aec29
VZ
82wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data)
83{
84 wxPrintDialogData data2;
85 if ( data )
86 data2 = *data;
87
88 Create(p, &data2);
89}
90
7bcb11d3 91bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
2bda0e17 92{
7bcb11d3
JS
93 m_dialogParent = p;
94 m_printerDC = NULL;
95 m_destroyDC = TRUE;
96
97 if ( data )
98 m_printDialogData = *data;
103aec29 99
7bcb11d3 100 m_printDialogData.SetOwnerWindow(p);
2bda0e17 101
7bcb11d3 102 return TRUE;
2bda0e17
KB
103}
104
103aec29 105wxPrintDialog::~wxPrintDialog()
2bda0e17 106{
7bcb11d3
JS
107 if (m_destroyDC && m_printerDC)
108 delete m_printerDC;
2bda0e17
KB
109}
110
103aec29 111int wxPrintDialog::ShowModal()
2bda0e17 112{
7bcb11d3 113 m_printDialogData.ConvertToNative();
103aec29 114
f6bcfd97
BP
115 PRINTDLG* p = (PRINTDLG *)m_printDialogData.GetNativeData() ;
116 if (m_dialogParent)
117 p->hwndOwner = (HWND) m_dialogParent->GetHWND();
118 else if (wxTheApp->GetTopWindow())
119 p->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
120 else
121 p->hwndOwner = 0;
122
123 bool ret = (PrintDlg( p ) != 0);
124
125 p->hwndOwner = 0;
126
7bcb11d3
JS
127 if ( ret != FALSE && ((PRINTDLG *)m_printDialogData.GetNativeData())->hDC)
128 {
129 wxPrinterDC *pdc = new wxPrinterDC((WXHDC) ((PRINTDLG *)m_printDialogData.GetNativeData())->hDC);
130 m_printerDC = pdc;
131 m_printDialogData.ConvertFromNative();
132 return wxID_OK;
133 }
134 else
135 {
7bcb11d3
JS
136 return wxID_CANCEL;
137 }
2bda0e17
KB
138}
139
103aec29 140wxDC *wxPrintDialog::GetPrintDC()
2bda0e17 141{
7bcb11d3
JS
142 if (m_printerDC)
143 {
144 m_destroyDC = FALSE;
145 return m_printerDC;
146 }
147 else
148 return (wxDC*) NULL;
2bda0e17
KB
149}
150
103aec29
VZ
151// ---------------------------------------------------------------------------
152// wxPageSetupDialog
153// ---------------------------------------------------------------------------
2bda0e17 154
103aec29 155wxPageSetupDialog::wxPageSetupDialog()
2bda0e17 156{
7bcb11d3 157 m_dialogParent = NULL;
2bda0e17
KB
158}
159
103aec29 160wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data)
2bda0e17 161{
7bcb11d3 162 Create(p, data);
2bda0e17
KB
163}
164
165bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data)
166{
7bcb11d3 167 m_dialogParent = p;
103aec29 168
7bcb11d3
JS
169 if (data)
170 m_pageSetupData = (*data);
103aec29 171
2bda0e17 172#if defined(__WIN95__)
7bcb11d3 173 m_pageSetupData.SetOwnerWindow(p);
2bda0e17 174#endif
7bcb11d3 175 return TRUE;
2bda0e17
KB
176}
177
103aec29 178wxPageSetupDialog::~wxPageSetupDialog()
2bda0e17
KB
179{
180}
181
103aec29 182int wxPageSetupDialog::ShowModal()
2bda0e17
KB
183{
184#ifdef __WIN95__
185 m_pageSetupData.ConvertToNative();
f6bcfd97
BP
186 PAGESETUPDLG *p = (PAGESETUPDLG *)m_pageSetupData.GetNativeData();
187 if (m_dialogParent)
188 p->hwndOwner = (HWND) m_dialogParent->GetHWND();
189 else if (wxTheApp->GetTopWindow())
190 p->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
191 else
192 p->hwndOwner = 0;
193 BOOL retVal = PageSetupDlg( p ) ;
194 p->hwndOwner = 0;
195 if (retVal)
2bda0e17 196 {
7bcb11d3
JS
197 m_pageSetupData.ConvertFromNative();
198 return wxID_OK;
2bda0e17
KB
199 }
200 else
7bcb11d3 201 return wxID_CANCEL;
2bda0e17
KB
202#else
203 wxGenericPageSetupDialog *genericPageSetupDialog = new wxGenericPageSetupDialog(GetParent(), & m_pageSetupData);
204 int ret = genericPageSetupDialog->ShowModal();
205 m_pageSetupData = genericPageSetupDialog->GetPageSetupData();
206 genericPageSetupDialog->Close(TRUE);
207 return ret;
208#endif
209}
210
f6bcfd97
BP
211#endif
212 // wxUSE_PRINTING_ARCHITECTURE