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