1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_toolkit.hxx"
30 #include <toolkit/helper/imagealign.hxx>
31 #include <com/sun/star/awt/ImagePosition.hpp>
32 #include <com/sun/star/awt/ImageAlign.hpp>
33 
34 //........................................................................
35 namespace toolkit
36 {
37 //........................................................................
38 
39     using namespace ::com::sun::star::awt::ImagePosition;
40     using namespace ::com::sun::star::awt::ImageAlign;
41 
42     sal_Int16 translateImagePosition( ImageAlign _eVCLAlign )
43     {
44         sal_Int16 nReturn = AboveCenter;
45         switch ( _eVCLAlign )
46         {
47         case IMAGEALIGN_LEFT:           nReturn = LeftCenter; break;
48         case IMAGEALIGN_TOP:            nReturn = AboveCenter;  break;
49         case IMAGEALIGN_RIGHT:          nReturn = RightCenter; break;
50         case IMAGEALIGN_BOTTOM:         nReturn = BelowCenter; break;
51         case IMAGEALIGN_LEFT_TOP:       nReturn = LeftTop; break;
52         case IMAGEALIGN_LEFT_BOTTOM:    nReturn = LeftBottom; break;
53         case IMAGEALIGN_TOP_LEFT:       nReturn = AboveLeft; break;
54         case IMAGEALIGN_TOP_RIGHT:      nReturn = AboveRight; break;
55         case IMAGEALIGN_RIGHT_TOP:      nReturn = RightTop; break;
56         case IMAGEALIGN_RIGHT_BOTTOM:   nReturn = RightBottom; break;
57         case IMAGEALIGN_BOTTOM_LEFT:    nReturn = BelowLeft; break;
58         case IMAGEALIGN_BOTTOM_RIGHT:   nReturn = BelowRight; break;
59         case IMAGEALIGN_CENTER:         nReturn = Centered; break;
60         default:
61             OSL_ENSURE( sal_False, "translateImagePosition: unknown IMAGEALIGN value!" );
62         }
63         return nReturn;
64     }
65 
66     ImageAlign translateImagePosition( sal_Int16 _eUNOAlign )
67     {
68         ImageAlign nReturn = IMAGEALIGN_TOP;
69         switch ( _eUNOAlign )
70         {
71         case LeftCenter:  nReturn = IMAGEALIGN_LEFT; break;
72         case AboveCenter: nReturn = IMAGEALIGN_TOP;  break;
73         case RightCenter: nReturn = IMAGEALIGN_RIGHT; break;
74         case BelowCenter: nReturn = IMAGEALIGN_BOTTOM; break;
75         case LeftTop:     nReturn = IMAGEALIGN_LEFT_TOP; break;
76         case LeftBottom:  nReturn = IMAGEALIGN_LEFT_BOTTOM; break;
77         case AboveLeft:   nReturn = IMAGEALIGN_TOP_LEFT; break;
78         case AboveRight:  nReturn = IMAGEALIGN_TOP_RIGHT; break;
79         case RightTop:    nReturn = IMAGEALIGN_RIGHT_TOP; break;
80         case RightBottom: nReturn = IMAGEALIGN_RIGHT_BOTTOM; break;
81         case BelowLeft:   nReturn = IMAGEALIGN_BOTTOM_LEFT; break;
82         case BelowRight:  nReturn = IMAGEALIGN_BOTTOM_RIGHT; break;
83         case Centered:    nReturn = IMAGEALIGN_CENTER; break;
84         default:
85             OSL_ENSURE( sal_False, "translateImagePosition: unknown css.awt.ImagePosition value!" );
86         }
87         return nReturn;
88     }
89 
90     sal_Int16 getCompatibleImageAlign( ImageAlign _eAlign )
91     {
92         sal_Int16 nReturn = TOP;
93         switch ( _eAlign )
94         {
95         case IMAGEALIGN_LEFT_TOP:
96         case IMAGEALIGN_LEFT:
97         case IMAGEALIGN_LEFT_BOTTOM:    nReturn = LEFT; break;
98 
99         case IMAGEALIGN_TOP_LEFT:
100         case IMAGEALIGN_TOP:
101         case IMAGEALIGN_TOP_RIGHT:      nReturn = TOP; break;
102 
103         case IMAGEALIGN_RIGHT_TOP:
104         case IMAGEALIGN_RIGHT:
105         case IMAGEALIGN_RIGHT_BOTTOM:   nReturn = RIGHT; break;
106 
107         case IMAGEALIGN_BOTTOM_LEFT:
108         case IMAGEALIGN_BOTTOM:
109         case IMAGEALIGN_BOTTOM_RIGHT:   nReturn = BOTTOM; break;
110 
111         case IMAGEALIGN_CENTER:         nReturn = TOP; break;
112         default:
113             OSL_ENSURE( sal_False, "getCompatibleImageAlign: unknown IMAGEALIGN value!" );
114         }
115         return nReturn;
116     }
117 
118     sal_Int16 getExtendedImagePosition( sal_Int16 _nImageAlign )
119     {
120         sal_Int16 nReturn = AboveCenter;
121         switch ( _nImageAlign )
122         {
123         case LEFT:   nReturn = LeftCenter; break;
124         case TOP:    nReturn = AboveCenter; break;
125         case RIGHT:  nReturn = RightCenter; break;
126         case BOTTOM: nReturn = BelowCenter; break;
127         default:
128             OSL_ENSURE( sal_False, "getExtendedImagePosition: unknown ImageAlign value!" );
129         }
130         return nReturn;
131     }
132 
133 //........................................................................
134 }   // namespace toolkit
135 //........................................................................
136