update dev300-m58
[ooovba.git] / svx / source / dialog / dlgutil.cxx
blob0934b1383ade46e5b0c1b7ac5376fd405f264795
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: dlgutil.cxx,v $
10 * $Revision: 1.17 $
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/urlobj.hxx>
39 #include <unolingu.hxx>
41 #include <svtools/langtab.hxx>
42 #include <svtools/itemset.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <sfx2/objsh.hxx>
46 #ifndef _SFXENUMITEM_HXX
47 #include <svtools/eitem.hxx>
48 #endif
50 #include <svx/dialogs.hrc>
52 #include "dlgutil.hxx"
53 #include <svx/dialmgr.hxx>
55 // -----------------------------------------------------------------------
57 String GetLanguageString( LanguageType eType )
59 static const SvtLanguageTable aLangTable;
60 return aLangTable.GetString( eType );
63 // -----------------------------------------------------------------------
65 String GetDicInfoStr( const String& rName, const USHORT nLang, const BOOL bNeg )
67 INetURLObject aURLObj;
68 aURLObj.SetSmartProtocol( INET_PROT_FILE );
69 aURLObj.SetSmartURL( rName, INetURLObject::ENCODE_ALL );
70 String aTmp( aURLObj.GetBase() );
71 aTmp += sal_Unicode( ' ' );
73 if ( bNeg )
75 sal_Char const sTmp[] = " (-) ";
76 aTmp.AppendAscii( sTmp );
79 if ( LANGUAGE_NONE == nLang )
80 aTmp += String( ResId( RID_SVXSTR_LANGUAGE_ALL, DIALOG_MGR() ) );
81 else
83 aTmp += sal_Unicode( '[' );
84 aTmp += ::GetLanguageString( (LanguageType)nLang );
85 aTmp += sal_Unicode( ']' );
88 return aTmp;
91 // -----------------------------------------------------------------------
93 void SetFieldUnit( MetricField& rField, FieldUnit eUnit, BOOL bAll )
95 sal_Int64 nFirst = rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) );
96 sal_Int64 nLast = rField.Denormalize( rField.GetLast( FUNIT_TWIP ) );
97 sal_Int64 nMin = rField.Denormalize( rField.GetMin( FUNIT_TWIP ) );
98 sal_Int64 nMax = rField.Denormalize( rField.GetMax( FUNIT_TWIP ) );
100 if ( !bAll )
102 switch ( eUnit )
104 case FUNIT_M:
105 case FUNIT_KM:
106 eUnit = FUNIT_CM;
107 break;
109 case FUNIT_FOOT:
110 case FUNIT_MILE:
111 eUnit = FUNIT_INCH;
112 break;
113 default: ;//prevent warning
116 rField.SetUnit( eUnit );
117 switch( eUnit )
119 // Amelia : sets the step of "char" and "line" unit , they are same as FUNIT_MM
120 case FUNIT_CHAR:
121 case FUNIT_LINE:
122 case FUNIT_MM:
123 rField.SetSpinSize( 50 );
124 break;
126 case FUNIT_INCH:
127 rField.SetSpinSize( 2 );
128 break;
130 default:
131 rField.SetSpinSize( 10 );
134 if ( FUNIT_POINT == eUnit )
136 if( rField.GetDecimalDigits() > 1 )
137 rField.SetDecimalDigits( 1 );
139 else
140 rField.SetDecimalDigits( 2 );
142 if ( !bAll )
144 rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
145 rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
146 rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
147 rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
151 // -----------------------------------------------------------------------
153 void SetFieldUnit( MetricBox& rBox, FieldUnit eUnit, BOOL bAll )
155 sal_Int64 nMin = rBox.Denormalize( rBox.GetMin( FUNIT_TWIP ) );
156 sal_Int64 nMax = rBox.Denormalize( rBox.GetMax( FUNIT_TWIP ) );
158 if ( !bAll )
160 switch ( eUnit )
162 case FUNIT_M:
163 case FUNIT_KM:
164 eUnit = FUNIT_CM;
165 break;
167 case FUNIT_FOOT:
168 case FUNIT_MILE:
169 eUnit = FUNIT_INCH;
170 break;
171 default: ;//prevent warning
174 rBox.SetUnit( eUnit );
176 if ( FUNIT_POINT == eUnit && rBox.GetDecimalDigits() > 1 )
177 rBox.SetDecimalDigits( 1 );
178 else
179 rBox.SetDecimalDigits( 2 );
181 if ( !bAll )
183 rBox.SetMin( rBox.Normalize( nMin ), FUNIT_TWIP );
184 rBox.SetMax( rBox.Normalize( nMax ), FUNIT_TWIP );
188 // -----------------------------------------------------------------------
190 FieldUnit GetModuleFieldUnit( const SfxItemSet* pSet )
192 FieldUnit eUnit = FUNIT_INCH;
193 const SfxPoolItem* pItem = NULL;
194 if ( pSet && SFX_ITEM_SET == pSet->GetItemState( SID_ATTR_METRIC, FALSE, &pItem ) )
195 eUnit = (FieldUnit)( (const SfxUInt16Item*)pItem )->GetValue();
196 else
198 SfxViewFrame* pFrame = SfxViewFrame::Current();
199 SfxObjectShell* pSh = NULL;
200 if ( pFrame )
201 pSh = pFrame->GetObjectShell();
202 if ( pSh ) // #93209# the object shell is not always available during reload
204 SfxModule* pModule = pSh->GetModule();
205 if ( pModule )
207 const SfxPoolItem* _pItem = pModule->GetItem( SID_ATTR_METRIC );
208 if ( _pItem )
209 eUnit = (FieldUnit)( (SfxUInt16Item*)_pItem )->GetValue();
211 else
213 DBG_ERRORFILE( "GetModuleFieldUnit(): no module found" );
217 return eUnit;
219 // -----------------------------------------------------------------------
220 BOOL GetApplyCharUnit( const SfxItemSet* pSet )
222 BOOL bUseCharUnit = FALSE;
223 const SfxPoolItem* pItem = NULL;
224 if ( pSet && SFX_ITEM_SET == pSet->GetItemState( SID_ATTR_APPLYCHARUNIT, FALSE, &pItem ) )
225 bUseCharUnit = (BOOL)( (const SfxBoolItem*)pItem )->GetValue();
226 else
228 SfxViewFrame* pFrame = SfxViewFrame::Current();
229 SfxObjectShell* pSh = NULL;
230 if ( pFrame )
231 pSh = pFrame->GetObjectShell();
232 if ( pSh ) // #93209# the object shell is not always available during reload
234 SfxModule* pModule = pSh->GetModule();
235 if ( pModule )
237 const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_APPLYCHARUNIT );
238 if ( pItem )
239 bUseCharUnit = (BOOL)( (SfxBoolItem*)pItem )->GetValue();
241 else
243 DBG_ERRORFILE( "GetApplyCharUnit(): no module found" );
247 return bUseCharUnit;
250 // -----------------------------------------------------------------------
251 void SetMetricValue( MetricField& rField, long nCoreValue, SfxMapUnit eUnit )
253 sal_Int64 nVal = OutputDevice::LogicToLogic( nCoreValue, (MapUnit)eUnit, MAP_100TH_MM );
254 nVal = rField.Normalize( nVal );
255 rField.SetValue( nVal, FUNIT_100TH_MM );
258 if ( SFX_MAPUNIT_100TH_MM == eUnit )
260 FieldUnit eFUnit = ( (MetricField&)rField ).GetUnit();
261 USHORT nDigits = rField.GetDecimalDigits();
263 if ( FUNIT_MM == eFUnit )
265 if ( 0 == nDigits )
266 lCoreValue /= 100;
267 else if ( 1 == nDigits )
268 lCoreValue /= 10;
269 else if ( nDigits > 2 )
271 DBG_ERROR( "too much decimal digits" );
272 return;
274 rField.SetValue( lCoreValue, FUNIT_MM );
275 return;
277 else if ( FUNIT_CM == eFUnit )
279 if ( 0 == nDigits )
280 lCoreValue /= 1000;
281 else if ( 1 == nDigits )
282 lCoreValue /= 100;
283 else if ( 2 == nDigits )
284 lCoreValue /= 10;
285 else if ( nDigits > 3 )
287 DBG_ERROR( "too much decimal digits" );
288 return;
290 rField.SetValue( lCoreValue, FUNIT_CM );
291 return;
294 rField.SetValue( rField.Normalize(
295 ConvertValueToUnit( lCoreValue, eUnit ) ), MapToFieldUnit( eUnit ) );
299 // -----------------------------------------------------------------------
301 long GetCoreValue( const MetricField& rField, SfxMapUnit eUnit )
303 sal_Int64 nVal = rField.GetValue( FUNIT_100TH_MM );
304 // avoid rounding issues
305 const sal_Int64 nSizeMask = 0xffffffffff000000LL;
306 bool bRoundBefore = true;
307 if( nVal >= 0 )
309 if( (nVal & nSizeMask) == 0 )
310 bRoundBefore = false;
312 else
314 if( ((-nVal) & nSizeMask ) == 0 )
315 bRoundBefore = false;
317 if( bRoundBefore )
318 nVal = rField.Denormalize( nVal );
319 sal_Int64 nUnitVal = OutputDevice::LogicToLogic( static_cast<long>(nVal), MAP_100TH_MM, (MapUnit)eUnit );
320 if( ! bRoundBefore )
321 nUnitVal = rField.Denormalize( nUnitVal );
322 return static_cast<long>(nUnitVal);
325 long nRet = rField.GetValue( MapToFieldUnit( eUnit ) );
326 FieldUnit eFUnit = ( (MetricField&)rField ).GetUnit();
327 USHORT nDigits = rField.GetDecimalDigits();
328 DBG_ASSERT( nDigits <= 2, "decimal digits > 2!" );
330 switch ( eUnit )
332 case SFX_MAPUNIT_100TH_MM:
334 if ( 2 == nDigits )
335 return nRet;
336 else if ( 1 == nDigits )
337 return nRet * 10;
338 else
339 return nRet * 100;
342 case SFX_MAPUNIT_TWIP:
344 if ( 2 == nDigits )
346 long nMod = 100;
347 long nTmp = nRet % nMod;
349 if ( nTmp >= 49 )
350 nRet += 100 - nTmp;
351 return nRet / 100;
353 else if ( 1 == nDigits )
355 long nMod = 10;
356 long nTmp = nRet % nMod;
358 if ( nTmp >= 4 )
359 nRet += 10 - nTmp;
360 return nRet / 10;
362 else
363 return nRet;
366 default:
367 DBG_ERROR( "this unit is not implemented" );
368 return 0;
372 /*!!!
373 return ConvertValueToMap( rField.Denormalize(
374 rField.GetValue( MapToFieldUnit( eUnit ) ) ), eUnit );
378 // -----------------------------------------------------------------------
380 long CalcToUnit( float nIn, SfxMapUnit eUnit )
382 // nIn ist in Points
384 DBG_ASSERT( eUnit == SFX_MAPUNIT_TWIP ||
385 eUnit == SFX_MAPUNIT_100TH_MM ||
386 eUnit == SFX_MAPUNIT_10TH_MM ||
387 eUnit == SFX_MAPUNIT_MM ||
388 eUnit == SFX_MAPUNIT_CM, "this unit is not implemented" );
390 float nTmp = nIn;
392 if ( SFX_MAPUNIT_TWIP != eUnit )
393 nTmp = nIn * 10 / 567;
395 switch ( eUnit )
397 case SFX_MAPUNIT_100TH_MM: nTmp *= 100; break;
398 case SFX_MAPUNIT_10TH_MM: nTmp *= 10; break;
399 case SFX_MAPUNIT_MM: break;
400 case SFX_MAPUNIT_CM: nTmp /= 10; break;
401 default: ;//prevent warning
404 nTmp *= 20;
405 long nRet = (long)nTmp;
406 return nRet;
407 //! return (long)(nTmp * 20);
410 // -----------------------------------------------------------------------
412 long ItemToControl( long nIn, SfxMapUnit eItem, SfxFieldUnit eCtrl )
414 long nOut = 0;
416 switch ( eItem )
418 case SFX_MAPUNIT_100TH_MM:
419 case SFX_MAPUNIT_10TH_MM:
420 case SFX_MAPUNIT_MM:
422 if ( eItem == SFX_MAPUNIT_10TH_MM )
423 nIn /= 10;
424 else if ( eItem == SFX_MAPUNIT_100TH_MM )
425 nIn /= 100;
426 nOut = TransformMetric( nIn, FUNIT_MM, (FieldUnit)eCtrl );
428 break;
430 case SFX_MAPUNIT_CM:
432 nOut = TransformMetric( nIn, FUNIT_CM, (FieldUnit)eCtrl );
434 break;
436 case SFX_MAPUNIT_1000TH_INCH:
437 case SFX_MAPUNIT_100TH_INCH:
438 case SFX_MAPUNIT_10TH_INCH:
439 case SFX_MAPUNIT_INCH:
441 if ( eItem == SFX_MAPUNIT_10TH_INCH )
442 nIn /= 10;
443 else if ( eItem == SFX_MAPUNIT_100TH_INCH )
444 nIn /= 100;
445 else if ( eItem == SFX_MAPUNIT_1000TH_INCH )
446 nIn /= 1000;
447 nOut = TransformMetric( nIn, FUNIT_INCH, (FieldUnit)eCtrl );
449 break;
451 case SFX_MAPUNIT_POINT:
453 nOut = TransformMetric( nIn, FUNIT_POINT, (FieldUnit)eCtrl );
455 break;
457 case SFX_MAPUNIT_TWIP:
459 nOut = TransformMetric( nIn, FUNIT_TWIP, (FieldUnit)eCtrl );
461 break;
462 default: ;//prevent warning
464 return nOut;
467 // -----------------------------------------------------------------------
469 long ControlToItem( long nIn, SfxFieldUnit eCtrl, SfxMapUnit eItem )
471 return ItemToControl( nIn, eItem, eCtrl );
474 // -----------------------------------------------------------------------
476 FieldUnit MapToFieldUnit( const SfxMapUnit eUnit )
478 switch ( eUnit )
480 case SFX_MAPUNIT_100TH_MM:
481 case SFX_MAPUNIT_10TH_MM:
482 case SFX_MAPUNIT_MM:
483 return FUNIT_MM;
485 case SFX_MAPUNIT_CM:
486 return FUNIT_CM;
488 case SFX_MAPUNIT_1000TH_INCH:
489 case SFX_MAPUNIT_100TH_INCH:
490 case SFX_MAPUNIT_10TH_INCH:
491 case SFX_MAPUNIT_INCH:
492 return FUNIT_INCH;
494 case SFX_MAPUNIT_POINT:
495 return FUNIT_POINT;
497 case SFX_MAPUNIT_TWIP:
498 return FUNIT_TWIP;
499 default: ;//prevent warning
501 return FUNIT_NONE;
504 // -----------------------------------------------------------------------
506 MapUnit FieldToMapUnit( const SfxFieldUnit /*eUnit*/ )
508 return MAP_APPFONT;
511 // -----------------------------------------------------------------------
513 long ConvertValueToMap( long nVal, SfxMapUnit eUnit )
515 long nNew = nVal;
517 switch ( eUnit )
519 case SFX_MAPUNIT_10TH_MM:
520 case SFX_MAPUNIT_10TH_INCH:
521 nNew *= 10;
522 break;
524 case SFX_MAPUNIT_100TH_MM:
525 case SFX_MAPUNIT_100TH_INCH:
526 nNew *= 100;
527 break;
529 case SFX_MAPUNIT_1000TH_INCH:
530 nNew *= 1000;
531 default: ;//prevent warning
533 return nNew;
536 // -----------------------------------------------------------------------
538 long ConvertValueToUnit( long nVal, SfxMapUnit eUnit )
540 long nNew = nVal;
542 switch ( eUnit )
544 case SFX_MAPUNIT_10TH_MM:
545 case SFX_MAPUNIT_10TH_INCH:
546 nNew /= 10;
547 break;
549 case SFX_MAPUNIT_100TH_MM:
550 case SFX_MAPUNIT_100TH_INCH:
551 nNew /= 100;
552 break;
554 case SFX_MAPUNIT_1000TH_INCH:
555 nNew /= 1000;
556 break;
557 default: ;//prevent warning
559 return nNew;
562 // -----------------------------------------------------------------------
564 long CalcToPoint( long nIn, SfxMapUnit eUnit, USHORT nFaktor )
566 DBG_ASSERT( eUnit == SFX_MAPUNIT_TWIP ||
567 eUnit == SFX_MAPUNIT_100TH_MM ||
568 eUnit == SFX_MAPUNIT_10TH_MM ||
569 eUnit == SFX_MAPUNIT_MM ||
570 eUnit == SFX_MAPUNIT_CM, "this unit is not implemented" );
572 long nRet = 0;
574 if ( SFX_MAPUNIT_TWIP == eUnit )
575 nRet = nIn;
576 else
577 nRet = nIn * 567;
579 switch ( eUnit )
581 case SFX_MAPUNIT_100TH_MM: nRet /= 100; break;
582 case SFX_MAPUNIT_10TH_MM: nRet /= 10; break;
583 case SFX_MAPUNIT_MM: break;
584 case SFX_MAPUNIT_CM: nRet *= 10; break;
585 default: ;//prevent warning
588 // ggf. aufrunden
589 if ( SFX_MAPUNIT_TWIP != eUnit )
591 long nMod = 10;
592 long nTmp = nRet % nMod;
594 if ( nTmp >= 4 )
595 nRet += 10 - nTmp;
596 nRet /= 10;
598 return nRet * nFaktor / 20;
601 // -----------------------------------------------------------------------
603 long CMToTwips( long nIn )
605 long nRet = 0;
607 if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
608 nRet = nIn * 567;
609 return nRet;
612 // -----------------------------------------------------------------------
614 long MMToTwips( long nIn )
616 long nRet = 0;
618 if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
619 nRet = nIn * 567 / 10;
620 return nRet;
623 // -----------------------------------------------------------------------
625 long InchToTwips( long nIn )
627 long nRet = 0;
629 if ( nIn <= ( LONG_MAX / 1440 ) && nIn >= ( LONG_MIN / 1440 ) )
630 nRet = nIn * 1440;
631 return nRet;
634 // -----------------------------------------------------------------------
636 long PointToTwips( long nIn )
638 long nRet = 0;
640 if ( nIn <= ( LONG_MAX / 20 ) && nIn >= ( LONG_MIN / 20 ) )
641 nRet = nIn * 20;
642 return nRet;
645 // -----------------------------------------------------------------------
647 long PicaToTwips( long nIn )
649 long nRet = 0;
651 if ( nIn <= ( LONG_MAX / 240 ) && nIn >= ( LONG_MIN / 240 ) )
652 nRet = nIn * 240;
653 return nRet;
656 // -----------------------------------------------------------------------
658 long TwipsToCM( long nIn )
660 long nRet = nIn / 567;
661 return nRet;
664 // -----------------------------------------------------------------------
666 long InchToCM( long nIn )
668 long nRet = 0;
670 if ( nIn <= ( LONG_MAX / 254 ) && nIn >= ( LONG_MIN / 254 ) )
671 nRet = nIn * 254 / 100;
672 return nRet;
675 // -----------------------------------------------------------------------
677 long MMToCM( long nIn )
679 long nRet = nIn / 10;
680 return nRet;
683 // -----------------------------------------------------------------------
685 long PointToCM( long nIn )
687 long nRet = 0;
689 if ( nIn <= ( LONG_MAX / 20 ) && nIn >= ( LONG_MIN / 20 ) )
690 nRet = nIn * 20 / 567;
691 return nRet;
694 // -----------------------------------------------------------------------
696 long PicaToCM( long nIn)
698 long nRet = 0;
700 if ( nIn <= ( LONG_MAX / 12 / 20 ) && nIn >= ( LONG_MIN / 12 / 20 ) )
701 nRet = nIn * 12 * 20 / 567;
702 return nRet;
705 // -----------------------------------------------------------------------
707 long TwipsToMM( long nIn )
709 long nRet = 0;
711 if ( nIn <= ( LONG_MAX / 10 ) && nIn >= ( LONG_MIN / 10 ) )
712 nRet = nIn * 10 / 566;
713 return nRet;
716 // -----------------------------------------------------------------------
718 long CMToMM( long nIn )
720 long nRet = 0;
722 if ( nIn <= ( LONG_MAX / 10 ) && nIn >= ( LONG_MIN / 10 ) )
723 nRet = nIn * 10;
724 return nRet;
727 // -----------------------------------------------------------------------
729 long InchToMM( long nIn )
731 long nRet = 0;
733 if ( nIn <= ( LONG_MAX / 254 ) && nIn >= ( LONG_MIN / 254 ) )
734 nRet = nIn * 254 / 10;
735 return nRet;
738 // -----------------------------------------------------------------------
740 long PointToMM( long nIn )
742 long nRet = 0;
744 if ( nIn <= ( LONG_MAX / 200 ) && nIn >= ( LONG_MIN / 200 ) )
745 nRet = nIn * 200 / 567;
746 return nRet;
749 // -----------------------------------------------------------------------
751 long PicaToMM( long nIn )
753 long nRet = 0;
755 if ( nIn <= ( LONG_MAX / 12 / 200 ) && nIn >= ( LONG_MIN / 12 / 200 ) )
756 nRet = nIn * 12 * 200 / 567;
757 return nRet;
760 // -----------------------------------------------------------------------
762 long TwipsToInch( long nIn )
764 long nRet = nIn / 1440;
765 return nRet;
768 // -----------------------------------------------------------------------
770 long CMToInch( long nIn )
772 long nRet = 0;
774 if ( nIn <= ( LONG_MAX / 100 ) && nIn >= ( LONG_MIN / 100 ) )
775 nRet = nIn * 100 / 254;
776 return nRet;
779 // -----------------------------------------------------------------------
781 long MMToInch( long nIn )
783 long nRet = 0;
785 if ( nIn <= ( LONG_MAX / 10 ) && nIn >= ( LONG_MIN / 10 ) )
786 nRet = nIn * 10 / 254;
787 return nRet;
790 // -----------------------------------------------------------------------
792 long PointToInch( long nIn )
794 long nRet = nIn / 72;
795 return nRet;
798 // -----------------------------------------------------------------------
800 long PicaToInch( long nIn )
802 long nRet = nIn / 6;
803 return nRet;
806 // -----------------------------------------------------------------------
808 long TwipsToPoint( long nIn )
810 long nRet = nIn / 20;
811 return nRet;
814 // -----------------------------------------------------------------------
816 long InchToPoint( long nIn )
818 long nRet = 0;
820 if ( nIn <= ( LONG_MAX / 72 ) && nIn >= ( LONG_MIN / 72 ) )
821 nRet = nIn * 72;
822 return nRet;
825 // -----------------------------------------------------------------------
827 long CMToPoint( long nIn )
829 long nRet = 0;
831 if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
832 nRet = nIn * 567 / 20;
833 return nRet;
836 // -----------------------------------------------------------------------
838 long MMToPoint( long nIn )
840 long nRet = 0;
842 if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
843 nRet = nIn * 567 / 200;
844 return nRet;
847 // -----------------------------------------------------------------------
849 long PicaToPoint( long nIn )
851 long nRet = nIn / 12;
852 return nRet;
855 // -----------------------------------------------------------------------
857 long TwipsToPica( long nIn )
859 long nRet = nIn / 240;
860 return nRet;
863 // -----------------------------------------------------------------------
865 long InchToPica( long nIn )
867 long nRet = 0;
869 if ( nIn <= ( LONG_MAX / 6 ) && nIn >= ( LONG_MIN / 6 ) )
870 nRet = nIn * 6;
871 return nRet;
874 // -----------------------------------------------------------------------
876 long PointToPica( long nIn )
878 long nRet = 0;
880 if ( nIn <= ( LONG_MAX / 12 ) && nIn >= ( LONG_MIN / 12 ) )
881 nRet = nIn * 12;
882 return nRet;
885 // -----------------------------------------------------------------------
887 long CMToPica( long nIn )
889 long nRet = 0;
891 if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
892 nRet = nIn * 567 / 20 / 12;
893 return nRet;
896 // -----------------------------------------------------------------------
898 long MMToPica( long nIn )
900 long nRet = 0;
902 if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
903 nRet = nIn * 567 / 200 / 12;
904 return nRet;
907 // -----------------------------------------------------------------------
909 long Nothing( long nIn )
911 long nRet = nIn;
912 return nRet;
915 FUNC_CONVERT ConvertTable[6][6] =
917 // CM, MM INCH POINT PICAS=32 TWIPS
918 { Nothing, CMToMM, CMToInch, CMToPoint, CMToPica, CMToTwips },
919 { MMToCM, Nothing, MMToInch, MMToPoint, MMToPica, MMToTwips },
920 { InchToCM, InchToMM, Nothing, InchToPoint, InchToPica, InchToTwips },
921 { PointToCM, PointToMM, PointToInch, Nothing, PointToPica, PointToTwips },
922 { PicaToCM, PicaToMM, PicaToInch, PicaToPoint, Nothing, PicaToTwips },
923 { TwipsToCM, TwipsToMM, TwipsToInch, TwipsToPoint,TwipsToPica, Nothing }
926 // -----------------------------------------------------------------------
928 long TransformMetric( long nVal, FieldUnit aOld, FieldUnit aNew )
930 if ( aOld == FUNIT_NONE || aNew == FUNIT_NONE ||
931 aOld == FUNIT_CUSTOM || aNew == FUNIT_CUSTOM )
933 return nVal;
936 USHORT nOld = 0;
937 USHORT nNew = 0;
939 switch ( aOld )
941 case FUNIT_CM:
942 nOld = 0; break;
943 case FUNIT_MM:
944 nOld = 1; break;
945 case FUNIT_INCH:
946 nOld = 2; break;
947 case FUNIT_POINT:
948 nOld = 3; break;
949 case FUNIT_PICA:
950 nOld = 4; break;
951 case FUNIT_TWIP:
952 nOld = 5; break;
953 default: ;//prevent warning
956 switch ( aNew )
958 case FUNIT_CM:
959 nNew = 0; break;
960 case FUNIT_MM:
961 nNew = 1; break;
962 case FUNIT_INCH:
963 nNew = 2; break;
964 case FUNIT_POINT:
965 nNew = 3; break;
966 case FUNIT_PICA:
967 nNew = 4; break;
968 case FUNIT_TWIP:
969 nNew = 5; break;
970 default: ;//prevent warning
972 return ConvertTable[nOld][nNew]( nVal );
975 String ConvertPosSizeToIniString( const Point& rPos, const Size& rSize )
977 String aRet = String::CreateFromInt32( rPos.X() );
978 aRet += '/';
979 aRet += String::CreateFromInt32( rPos.Y() );
980 aRet += '/';
981 aRet += String::CreateFromInt32( rSize.Width() );
982 aRet += '/';
983 aRet += String::CreateFromInt32( rSize.Height() );
984 return aRet;
987 sal_Bool ConvertIniStringToPosSize( const String& rIniStr, Point& rPos, Size& rSize )
989 if ( rIniStr.GetTokenCount('/') != 4 )
990 return sal_False;
992 USHORT nIdx = 0;
993 rPos.X() = rIniStr.GetToken( 0, '/', nIdx ).ToInt32();
994 rPos.Y() = rIniStr.GetToken( 0, '/', nIdx ).ToInt32();
995 rSize.Width() = rIniStr.GetToken( 0, '/', nIdx ).ToInt32();
996 rSize.Height() = rIniStr.GetToken( 0, '/', nIdx ).ToInt32();
998 // negative sizes are invalid
999 if ( rSize.Width() < 0 || rSize.Height() < 0 )
1000 return sal_False;
1002 return sal_True;