update dev300-m58
[ooovba.git] / svx / source / items / paperinf.cxx
blob7a67a0009f0e764481a8d99bf7c0ee8e0a3c3be5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: paperinf.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
36 #include <limits.h>
37 #include <tools/shl.hxx>
38 #include <tools/debug.hxx>
39 #include <vcl/svapp.hxx>
41 #ifndef _SVX_DIALOGS_HRC
42 #include <svx/dialogs.hrc>
43 #endif
44 #include <svx/paperinf.hxx>
45 #include <svx/dialmgr.hxx>
47 /*--------------------------------------------------------------------
48 Beschreibung: Ist der Printer gueltig
49 --------------------------------------------------------------------*/
51 inline BOOL IsValidPrinter( const Printer* pPtr )
53 return pPtr->GetName().Len() ? TRUE : FALSE;
56 //------------------------------------------------------------------------
58 Size SvxPaperInfo::GetPaperSize( Paper ePaper, MapUnit eUnit )
60 PaperInfo aInfo(ePaper);
61 Size aRet(aInfo.getWidth(), aInfo.getHeight()); // in 100thMM
62 return eUnit == MAP_100TH_MM ? aRet : OutputDevice::LogicToLogic(aRet, MAP_100TH_MM, eUnit);
65 /*------------------------------------------------------------------------
66 Beschreibung: Papiergroesse der Druckers liefern, aligned auf
67 die eigenen Groessen.
68 Falls kein Printer im System eingestellt ist,
69 wird DIN A4 Portrait als Defaultpapiergroesse geliefert.
70 ------------------------------------------------------------------------*/
72 //Is this method may be confused about the units it returns ?
73 //Always returns TWIPS for known paper sizes or on failure.
74 //But in the case of PAPER_USER paper and with a Printer with a mapmode set
75 //will return in those printer units ?
76 Size SvxPaperInfo::GetPaperSize( const Printer* pPrinter )
78 if ( !IsValidPrinter(pPrinter) )
79 return GetPaperSize( PAPER_A4 );
80 const Paper ePaper = pPrinter->GetPaper();
82 if ( ePaper == PAPER_USER )
84 // Orientation nicht beruecksichtigen, da durch SV bereits
85 // die richtigen Masze eingestellt worden sind.
86 Size aPaperSize = pPrinter->GetPaperSize();
87 const Size aInvalidSize;
89 if ( aPaperSize == aInvalidSize )
90 return GetPaperSize(PAPER_A4);
91 MapMode aMap1 = pPrinter->GetMapMode();
92 MapMode aMap2;
94 if ( aMap1 == aMap2 )
95 aPaperSize =
96 pPrinter->PixelToLogic( aPaperSize, MapMode( MAP_TWIP ) );
97 return aPaperSize;
100 const Orientation eOrient = pPrinter->GetOrientation();
101 Size aSize( GetPaperSize( ePaper ) );
102 // bei Landscape die Seiten tauschen, ist bei SV schon geschehen
103 if ( eOrient == ORIENTATION_LANDSCAPE )
104 Swap( aSize );
105 return aSize;
108 // -----------------------------------------------------------------------
110 Paper SvxPaperInfo::GetSvxPaper( const Size &rSize, MapUnit eUnit, bool bSloppy )
112 Size aSize(eUnit == MAP_100TH_MM ? rSize : OutputDevice::LogicToLogic(rSize, eUnit, MAP_100TH_MM));
113 PaperInfo aInfo(aSize.Width(), aSize.Height());
114 if (bSloppy)
115 aInfo.doSloppyFit();
116 return aInfo.getPaper();
119 // -----------------------------------------------------------------------
121 long SvxPaperInfo::GetSloppyPaperDimension( long nSize, MapUnit eUnit )
123 nSize = eUnit == MAP_100TH_MM ? nSize : OutputDevice::LogicToLogic(nSize, eUnit, MAP_100TH_MM);
124 nSize = PaperInfo::sloppyFitPageDimension(nSize);
125 return eUnit == MAP_100TH_MM ? nSize : OutputDevice::LogicToLogic(nSize, MAP_100TH_MM, eUnit);
128 // -----------------------------------------------------------------------
130 Size SvxPaperInfo::GetDefaultPaperSize( MapUnit eUnit )
132 PaperInfo aInfo(PaperInfo::getSystemDefaultPaper());
133 Size aRet(aInfo.getWidth(), aInfo.getHeight());
134 return eUnit == MAP_100TH_MM ? aRet : OutputDevice::LogicToLogic(aRet, MAP_100TH_MM, eUnit);
137 /*------------------------------------------------------------------------
138 Beschreibung: String Repr"asentation f"ur die SV-Defines f"ur
139 Papiergroessen.
140 ------------------------------------------------------------------------*/
142 String SvxPaperInfo::GetName( Paper ePaper )
144 USHORT nResId = 0;
146 switch ( ePaper )
148 case PAPER_A0: nResId = RID_SVXSTR_PAPER_A0; break;
149 case PAPER_A1: nResId = RID_SVXSTR_PAPER_A1; break;
150 case PAPER_A2: nResId = RID_SVXSTR_PAPER_A2; break;
151 case PAPER_A3: nResId = RID_SVXSTR_PAPER_A3; break;
152 case PAPER_A4: nResId = RID_SVXSTR_PAPER_A4; break;
153 case PAPER_A5: nResId = RID_SVXSTR_PAPER_A5; break;
154 case PAPER_B4_ISO: nResId = RID_SVXSTR_PAPER_B4_ISO; break;
155 case PAPER_B5_ISO: nResId = RID_SVXSTR_PAPER_B5_ISO; break;
156 case PAPER_LETTER: nResId = RID_SVXSTR_PAPER_LETTER; break;
157 case PAPER_LEGAL: nResId = RID_SVXSTR_PAPER_LEGAL; break;
158 case PAPER_TABLOID: nResId = RID_SVXSTR_PAPER_TABLOID; break;
159 case PAPER_USER: nResId = RID_SVXSTR_PAPER_USER; break;
160 case PAPER_B6_ISO: nResId = RID_SVXSTR_PAPER_B6_ISO; break;
161 case PAPER_ENV_C4: nResId = RID_SVXSTR_PAPER_C4; break;
162 case PAPER_ENV_C5: nResId = RID_SVXSTR_PAPER_C5; break;
163 case PAPER_ENV_C6: nResId = RID_SVXSTR_PAPER_C6; break;
164 case PAPER_ENV_C65: nResId = RID_SVXSTR_PAPER_C65; break;
165 case PAPER_ENV_DL: nResId = RID_SVXSTR_PAPER_DL; break;
166 case PAPER_SLIDE_DIA: nResId = RID_SVXSTR_PAPER_DIA; break;
167 case PAPER_SCREEN: nResId = RID_SVXSTR_PAPER_SCREEN; break;
168 case PAPER_C: nResId = RID_SVXSTR_PAPER_C; break;
169 case PAPER_D: nResId = RID_SVXSTR_PAPER_D; break;
170 case PAPER_E: nResId = RID_SVXSTR_PAPER_E; break;
171 case PAPER_EXECUTIVE: nResId = RID_SVXSTR_PAPER_EXECUTIVE;break;
172 case PAPER_FANFOLD_LEGAL_DE: nResId = RID_SVXSTR_PAPER_LEGAL2; break;
173 case PAPER_ENV_MONARCH: nResId = RID_SVXSTR_PAPER_MONARCH; break;
174 case PAPER_ENV_PERSONAL: nResId = RID_SVXSTR_PAPER_COM675; break;
175 case PAPER_ENV_9: nResId = RID_SVXSTR_PAPER_COM9; break;
176 case PAPER_ENV_10: nResId = RID_SVXSTR_PAPER_COM10; break;
177 case PAPER_ENV_11: nResId = RID_SVXSTR_PAPER_COM11; break;
178 case PAPER_ENV_12: nResId = RID_SVXSTR_PAPER_COM12; break;
179 case PAPER_KAI16: nResId = RID_SVXSTR_PAPER_KAI16; break;
180 case PAPER_KAI32: nResId = RID_SVXSTR_PAPER_KAI32; break;
181 case PAPER_KAI32BIG: nResId = RID_SVXSTR_PAPER_KAI32BIG; break;
182 case PAPER_B4_JIS: nResId = RID_SVXSTR_PAPER_B4_JIS; break;
183 case PAPER_B5_JIS: nResId = RID_SVXSTR_PAPER_B5_JIS; break;
184 case PAPER_B6_JIS: nResId = RID_SVXSTR_PAPER_B6_JIS; break;
185 default: DBG_ERRORFILE( "unknown papersize" );
188 return ( nResId > 0 ) ? String( SVX_RES( nResId ) ) : String();