]> git.saurik.com Git - wxWidgets.git/blob - src/common/paper.cpp
Updated wxvc_dll.dsp and memory.h to make VC++ compile in DLL mode again
[wxWidgets.git] / src / common / paper.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: paper.cpp
3 // Purpose: Paper size classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "paper.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 #include "wx/defs.h"
24
25 #ifndef WX_PRECOMP
26 #include "wx/utils.h"
27 #include "wx/settings.h"
28 #include "wx/intl.h"
29 #endif
30
31 #include "wx/paper.h"
32 #include "wx/module.h"
33
34 #include <stdlib.h>
35 #include <string.h>
36
37 #ifdef __WXMSW__
38 #include <windows.h>
39 #include <commdlg.h>
40
41 #ifndef __WIN32__
42 #include <print.h>
43 #endif
44
45 #endif
46 // End __WXMSW__
47
48 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType, wxObject)
49 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase, wxList)
50
51 /*
52 * Paper size database for all platforms
53 */
54
55 wxPrintPaperType::wxPrintPaperType()
56 {
57 m_paperId = wxPAPER_NONE;
58 m_platformId = 0;
59 m_paperName = "";
60 m_width = 0;
61 m_height = 0;
62 }
63
64 wxPrintPaperType::wxPrintPaperType(wxPaperSize paperId, int platformId, const wxString& name, int w, int h)
65 {
66 m_paperId = paperId;
67 m_platformId = platformId;
68 m_paperName = name;
69 m_width = w;
70 m_height = h;
71 }
72
73 // Get width and height in points (1/72th of an inch)
74 wxSize wxPrintPaperType::GetSizeDeviceUnits() const
75 {
76 return wxSize( (int) ((m_width / 10.0) / (25.4 / 72.0)), (int) ((m_height / 10.0) / (25.4 / 72.0)) );
77 }
78
79 /*
80 * Print paper database for PostScript
81 */
82
83 wxPrintPaperDatabase* wxThePrintPaperDatabase = (wxPrintPaperDatabase*) NULL;
84
85 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING)
86 {
87 DeleteContents(TRUE);
88 }
89
90 void wxPrintPaperDatabase::CreateDatabase()
91 {
92 /*
93 AddPaperType(_("A4 210 x 297 mm"), 210, 297);
94 AddPaperType(_("A3 297 x 420 mm"), 297, 420);
95 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279);
96 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356);
97 */
98
99 WXADDPAPER(wxPAPER_LETTER, DMPAPER_LETTER, "Letter, 8 1/2 x 11 in", 2159, 2794);
100 WXADDPAPER(wxPAPER_LEGAL, DMPAPER_LEGAL, "Legal, 8 1/2 x 14 in", 2159, 3556);
101 WXADDPAPER(wxPAPER_A4, DMPAPER_A4, "A4 sheet, 210 x 297 mm", 2100, 2970);
102 WXADDPAPER(wxPAPER_CSHEET, DMPAPER_CSHEET, "C sheet, 17 x 22 in", 4318, 5588);
103 WXADDPAPER(wxPAPER_DSHEET, DMPAPER_DSHEET, "D sheet, 22 x 34 in", 5588, 8636);
104 WXADDPAPER(wxPAPER_ESHEET, DMPAPER_ESHEET, "E sheet, 34 x 44 in", 8636, 11176);
105 WXADDPAPER(wxPAPER_LETTERSMALL, DMPAPER_LETTERSMALL, "Letter Small, 8 1/2 x 11 in", 2159, 2794);
106 WXADDPAPER(wxPAPER_TABLOID, DMPAPER_TABLOID, "Tabloid, 11 x 17 in", 2794, 4318);
107 WXADDPAPER(wxPAPER_LEDGER, DMPAPER_LEDGER, "Ledger, 17 x 11 in", 4318, 2794);
108 WXADDPAPER(wxPAPER_STATEMENT, DMPAPER_STATEMENT, "Statement, 5 1/2 x 8 1/2 in", 1397, 2159);
109 WXADDPAPER(wxPAPER_EXECUTIVE, DMPAPER_EXECUTIVE, "Executive, 7 1/4 x 10 1/2 in", 1842, 2667);
110 WXADDPAPER(wxPAPER_A3, DMPAPER_A3, "A3 sheet, 297 x 420 mm", 2970, 4200);
111 WXADDPAPER(wxPAPER_A4SMALL, DMPAPER_A4SMALL, "A4 small sheet, 210 x 297 mm", 2100, 2970);
112 WXADDPAPER(wxPAPER_A5, DMPAPER_A5, "A5 sheet, 148 x 210 mm", 1480, 2100);
113 WXADDPAPER(wxPAPER_B4, DMPAPER_B4, "B4 sheet, 250 x 354 mm", 2500, 3540);
114 WXADDPAPER(wxPAPER_B5, DMPAPER_B5, "B5 sheet, 182 x 257 millimeter", 1820, 2570);
115 WXADDPAPER(wxPAPER_FOLIO, DMPAPER_FOLIO, "Folio, 8 1/2 x 13 in", 2159, 3302);
116 WXADDPAPER(wxPAPER_QUARTO, DMPAPER_QUARTO, "Quarto, 215 x 275 mm", 2150, 2750);
117 WXADDPAPER(wxPAPER_10X14, DMPAPER_10X14, "10 x 14 in", 2540, 3556);
118 WXADDPAPER(wxPAPER_11X17, DMPAPER_11X17, "11 x 17 in", 2794, 4318);
119 WXADDPAPER(wxPAPER_NOTE, DMPAPER_NOTE, "Note, 8 1/2 x 11 in", 2159, 2794);
120 WXADDPAPER(wxPAPER_ENV_9, DMPAPER_ENV_9, "#9 Envelope, 3 7/8 x 8 7/8 in", 984, 2254);
121 WXADDPAPER(wxPAPER_ENV_10, DMPAPER_ENV_10, "#10 Envelope, 4 1/8 x 9 1/2 in", 1048, 2413);
122 WXADDPAPER(wxPAPER_ENV_11, DMPAPER_ENV_11, "#11 Envelope, 4 1/2 x 10 3/8 in", 1143, 2635);
123 WXADDPAPER(wxPAPER_ENV_12, DMPAPER_ENV_12, "#12 Envelope, 4 3/4 x 11 in", 1206, 2794);
124 WXADDPAPER(wxPAPER_ENV_14, DMPAPER_ENV_14, "#14 Envelope, 5 x 11 1/2 in", 1270, 2921);
125 WXADDPAPER(wxPAPER_ENV_DL, DMPAPER_ENV_DL, "DL Envelope, 110 x 220 mm", 1100, 2200);
126 WXADDPAPER(wxPAPER_ENV_C5, DMPAPER_ENV_C5, "C5 Envelope, 162 x 229 mm", 1620, 2290);
127 WXADDPAPER(wxPAPER_ENV_C3, DMPAPER_ENV_C3, "C3 Envelope, 324 x 458 mm", 3240, 4580);
128 WXADDPAPER(wxPAPER_ENV_C4, DMPAPER_ENV_C4, "C4 Envelope, 229 x 324 mm", 2290, 3240);
129 WXADDPAPER(wxPAPER_ENV_C6, DMPAPER_ENV_C6, "C6 Envelope, 114 x 162 mm", 1140, 1620);
130 WXADDPAPER(wxPAPER_ENV_C65, DMPAPER_ENV_C65, "C65 Envelope, 114 x 229 mm", 1140, 2290);
131 WXADDPAPER(wxPAPER_ENV_B4, DMPAPER_ENV_B4, "B4 Envelope, 250 x 353 mm", 2500, 3530);
132 WXADDPAPER(wxPAPER_ENV_B5, DMPAPER_ENV_B5, "B5 Envelope, 176 x 250 mm", 1760, 2500);
133 WXADDPAPER(wxPAPER_ENV_B6, DMPAPER_ENV_B6, "B6 Envelope, 176 x 125 mm", 1760, 1250);
134 WXADDPAPER(wxPAPER_ENV_ITALY, DMPAPER_ENV_ITALY, "Italy Envelope, 110 x 230 mm", 1100, 2300);
135 WXADDPAPER(wxPAPER_ENV_MONARCH, DMPAPER_ENV_MONARCH, "Monarch Envelope, 3 7/8 x 7 1/2 in", 984, 1905);
136 WXADDPAPER(wxPAPER_ENV_PERSONAL, DMPAPER_ENV_PERSONAL, "6 3/4 Envelope, 3 5/8 x 6 1/2 in", 921, 1651);
137 WXADDPAPER(wxPAPER_FANFOLD_US, DMPAPER_FANFOLD_US, "US Std Fanfold, 14 7/8 x 11 in", 3778, 2794);
138 WXADDPAPER(wxPAPER_FANFOLD_STD_GERMAN, DMPAPER_FANFOLD_STD_GERMAN, "German Std Fanfold, 8 1/2 x 12 in", 2159, 3048);
139 WXADDPAPER(wxPAPER_FANFOLD_LGL_GERMAN, DMPAPER_FANFOLD_LGL_GERMAN, "German Legal Fanfold, 8 1/2 x 13 in", 2159, 3302);
140
141 /* Another time!
142 #ifdef __WIN95__
143 WXADDPAPER(wxPAPER_ISO_B4, DMPAPER_ISO_B4, "B4 (ISO) 250 x 353 mm",
144 WXADDPAPER(wxPAPER_JAPANESE_POSTCARD, DMPAPER_JAPANESE_POSTCARD, "Japanese Postcard 100 x 148 mm",
145 WXADDPAPER(wxPAPER_9X11, DMPAPER_9X11, "9 x 11 in",
146 WXADDPAPER(wxPAPER_10X11, DMPAPER_10X11, "10 x 11 in",
147 WXADDPAPER(wxPAPER_15X11, DMPAPER_15X11, "15 x 11 in",
148 WXADDPAPER(wxPAPER_ENV_INVITE, DMPAPER_ENV_INVITE, "Envelope Invite 220 x 220 mm",
149 // What does \275 mean?
150 // WXADDPAPER(wxPAPER_LETTER_EXTRA, DMPAPER_LETTER_EXTRA, "Letter Extra 9 \275 x 12 in",
151 // WXADDPAPER(wxPAPER_LEGAL_EXTRA, DMPAPER_LEGAL_EXTRA, "Legal Extra 9 \275 x 15 in",
152 WXADDPAPER(wxPAPER_TABLOID_EXTRA, DMPAPER_TABLOID_EXTRA, "Tabloid Extra 11.69 x 18 in",
153 WXADDPAPER(wxPAPER_A4_EXTRA, DMPAPER_A4_EXTRA, "A4 Extra 9.27 x 12.69 in",
154 // WXADDPAPER(wxPAPER_LETTER_TRANSVERSE, DMPAPER_LETTER_TRANSVERSE, "Letter Transverse 8 \275 x 11 in",
155 WXADDPAPER(wxPAPER_A4_TRANSVERSE, DMPAPER_A4_TRANSVERSE, "A4 Transverse 210 x 297 mm",
156 // WXADDPAPER(wxPAPER_LETTER_EXTRA_TRANSVERSE, DMPAPER_LETTER_EXTRA_TRANSVERSE, "Letter Extra Transverse 9\275 x 12 in",
157 WXADDPAPER(wxPAPER_A_PLUS, DMPAPER_A_PLUS, "SuperA/SuperA/A4 227 x 356 mm",
158 WXADDPAPER(wxPAPER_B_PLUS, DMPAPER_B_PLUS, "SuperB/SuperB/A3 305 x 487 mm",
159 WXADDPAPER(wxPAPER_LETTER_PLUS, DMPAPER_LETTER_PLUS, "Letter Plus 8.5 x 12.69 in",
160 WXADDPAPER(wxPAPER_A4_PLUS, DMPAPER_A4_PLUS, "A4 Plus 210 x 330 mm",
161 WXADDPAPER(wxPAPER_A5_TRANSVERSE, DMPAPER_A5_TRANSVERSE, "A5 Transverse 148 x 210 mm",
162 WXADDPAPER(wxPAPER_B5_TRANSVERSE, DMPAPER_B5_TRANSVERSE, "B5 (JIS) Transverse 182 x 257 mm",
163 WXADDPAPER(wxPAPER_A3_EXTRA, DMPAPER_A3_EXTRA, "A3 Extra 322 x 445 mm",
164 WXADDPAPER(wxPAPER_A5_EXTRA, DMPAPER_A5_EXTRA, "A5 Extra 174 x 235 mm",
165 WXADDPAPER(wxPAPER_B5_EXTRA, DMPAPER_B5_EXTRA, "B5 (ISO) Extra 201 x 276 mm",
166 WXADDPAPER(wxPAPER_A2, DMPAPER_A2, "A2 420 x 594 mm",
167 WXADDPAPER(wxPAPER_A3_TRANSVERSE, DMPAPER_A3_TRANSVERSE, "A3 Transverse 297 x 420 mm",
168 WXADDPAPER(wxPAPER_A3_EXTRA_TRANSVERSE DMPAPER_A3_EXTRA_TRANSVERSE "A3 Extra Transverse 322 x 445 mm",
169 #endif
170 */
171 }
172
173 void wxPrintPaperDatabase::ClearDatabase()
174 {
175 Clear();
176 }
177
178 void wxPrintPaperDatabase::AddPaperType(wxPaperSize paperId, const wxString& name, int w, int h)
179 {
180 Append(name, new wxPrintPaperType(paperId, 0, name, w, h));
181 }
182
183 void wxPrintPaperDatabase::AddPaperType(wxPaperSize paperId, int platformId, const wxString& name, int w, int h)
184 {
185 Append(name, new wxPrintPaperType(paperId, platformId, name, w, h));
186 }
187
188 wxPrintPaperType *wxPrintPaperDatabase::FindPaperType(const wxString& name)
189 {
190 wxNode *node = Find(name);
191 if (node)
192 return (wxPrintPaperType *)node->Data();
193 else
194 return (wxPrintPaperType *) NULL;
195 }
196
197 wxPrintPaperType *wxPrintPaperDatabase::FindPaperType(wxPaperSize id)
198 {
199 wxNode *node = First();
200 while (node)
201 {
202 wxPrintPaperType* paperType = (wxPrintPaperType*) node->Data();
203 if (paperType->GetId() == id)
204 return paperType;
205 node = node->Next();
206 }
207 return (wxPrintPaperType *) NULL;
208 }
209
210 wxPrintPaperType *wxPrintPaperDatabase::FindPaperTypeByPlatformId(int id)
211 {
212 wxNode *node = First();
213 while (node)
214 {
215 wxPrintPaperType* paperType = (wxPrintPaperType*) node->Data();
216 if (paperType->GetPlatformId() == id)
217 return paperType;
218 node = node->Next();
219 }
220 return (wxPrintPaperType *) NULL;
221 }
222
223 wxPrintPaperType *wxPrintPaperDatabase::FindPaperType(const wxSize& sz)
224 {
225 wxNode *node = First();
226 while (node)
227 {
228 wxPrintPaperType* paperType = (wxPrintPaperType*) node->Data();
229 if (paperType->GetSize() == sz)
230 return paperType;
231 node = node->Next();
232 }
233 return (wxPrintPaperType *) NULL;
234 }
235
236 // Convert name to size id
237 wxPaperSize wxPrintPaperDatabase::ConvertNameToId(const wxString& name)
238 {
239 wxPrintPaperType* type = FindPaperType(name);
240 if (type)
241 return type->GetId();
242 else
243 return wxPAPER_NONE;
244 }
245
246 // Convert size id to name
247 wxString wxPrintPaperDatabase::ConvertIdToName(wxPaperSize paperId)
248 {
249 wxPrintPaperType* type = FindPaperType(paperId);
250 if (type)
251 return type->GetName();
252 else
253 return wxEmptyString;
254 }
255
256 // Get the paper size
257 wxSize wxPrintPaperDatabase::GetSize(wxPaperSize paperId)
258 {
259 wxPrintPaperType* type = FindPaperType(paperId);
260 if (type)
261 return type->GetSize();
262 else
263 return wxSize(0, 0);
264 }
265
266 // Get the paper size
267 wxPaperSize wxPrintPaperDatabase::GetSize(const wxSize& size)
268 {
269 wxPrintPaperType* type = FindPaperType(size);
270 if (type)
271 return type->GetId();
272 else
273 return wxPAPER_NONE;
274 }
275
276 // A module to allow initialization/cleanup of print paper
277 // things without calling these functions from app.cpp.
278
279 class WXDLLEXPORT wxPrintPaperModule: public wxModule
280 {
281 DECLARE_DYNAMIC_CLASS(wxPrintPaperModule)
282 public:
283 wxPrintPaperModule() {}
284 bool OnInit();
285 void OnExit();
286 };
287
288 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperModule, wxModule)
289
290 /*
291 * Initialization/cleanup module
292 */
293
294 bool wxPrintPaperModule::OnInit()
295 {
296 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
297 wxThePrintPaperDatabase->CreateDatabase();
298
299 return TRUE;
300 }
301
302 void wxPrintPaperModule::OnExit()
303 {
304 delete wxThePrintPaperDatabase;
305 wxThePrintPaperDatabase = NULL;
306 }
307