1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_toolkit.hxx"
26 #include <toolkit/helper/imagealign.hxx>
27 #include <com/sun/star/awt/ImagePosition.hpp>
28 #include <com/sun/star/awt/ImageAlign.hpp>
29 
30 //........................................................................
31 namespace toolkit
32 {
33 //........................................................................
34 
35     using namespace ::com::sun::star::awt::ImagePosition;
36     using namespace ::com::sun::star::awt::ImageAlign;
37 
translateImagePosition(ImageAlign _eVCLAlign)38     sal_Int16 translateImagePosition( ImageAlign _eVCLAlign )
39     {
40         sal_Int16 nReturn = AboveCenter;
41         switch ( _eVCLAlign )
42         {
43         case IMAGEALIGN_LEFT:           nReturn = LeftCenter; break;
44         case IMAGEALIGN_TOP:            nReturn = AboveCenter;  break;
45         case IMAGEALIGN_RIGHT:          nReturn = RightCenter; break;
46         case IMAGEALIGN_BOTTOM:         nReturn = BelowCenter; break;
47         case IMAGEALIGN_LEFT_TOP:       nReturn = LeftTop; break;
48         case IMAGEALIGN_LEFT_BOTTOM:    nReturn = LeftBottom; break;
49         case IMAGEALIGN_TOP_LEFT:       nReturn = AboveLeft; break;
50         case IMAGEALIGN_TOP_RIGHT:      nReturn = AboveRight; break;
51         case IMAGEALIGN_RIGHT_TOP:      nReturn = RightTop; break;
52         case IMAGEALIGN_RIGHT_BOTTOM:   nReturn = RightBottom; break;
53         case IMAGEALIGN_BOTTOM_LEFT:    nReturn = BelowLeft; break;
54         case IMAGEALIGN_BOTTOM_RIGHT:   nReturn = BelowRight; break;
55         case IMAGEALIGN_CENTER:         nReturn = Centered; break;
56         default:
57             OSL_ENSURE( sal_False, "translateImagePosition: unknown IMAGEALIGN value!" );
58         }
59         return nReturn;
60     }
61 
translateImagePosition(sal_Int16 _eUNOAlign)62     ImageAlign translateImagePosition( sal_Int16 _eUNOAlign )
63     {
64         ImageAlign nReturn = IMAGEALIGN_TOP;
65         switch ( _eUNOAlign )
66         {
67         case LeftCenter:  nReturn = IMAGEALIGN_LEFT; break;
68         case AboveCenter: nReturn = IMAGEALIGN_TOP;  break;
69         case RightCenter: nReturn = IMAGEALIGN_RIGHT; break;
70         case BelowCenter: nReturn = IMAGEALIGN_BOTTOM; break;
71         case LeftTop:     nReturn = IMAGEALIGN_LEFT_TOP; break;
72         case LeftBottom:  nReturn = IMAGEALIGN_LEFT_BOTTOM; break;
73         case AboveLeft:   nReturn = IMAGEALIGN_TOP_LEFT; break;
74         case AboveRight:  nReturn = IMAGEALIGN_TOP_RIGHT; break;
75         case RightTop:    nReturn = IMAGEALIGN_RIGHT_TOP; break;
76         case RightBottom: nReturn = IMAGEALIGN_RIGHT_BOTTOM; break;
77         case BelowLeft:   nReturn = IMAGEALIGN_BOTTOM_LEFT; break;
78         case BelowRight:  nReturn = IMAGEALIGN_BOTTOM_RIGHT; break;
79         case Centered:    nReturn = IMAGEALIGN_CENTER; break;
80         default:
81             OSL_ENSURE( sal_False, "translateImagePosition: unknown css.awt.ImagePosition value!" );
82         }
83         return nReturn;
84     }
85 
getCompatibleImageAlign(ImageAlign _eAlign)86     sal_Int16 getCompatibleImageAlign( ImageAlign _eAlign )
87     {
88         sal_Int16 nReturn = TOP;
89         switch ( _eAlign )
90         {
91         case IMAGEALIGN_LEFT_TOP:
92         case IMAGEALIGN_LEFT:
93         case IMAGEALIGN_LEFT_BOTTOM:    nReturn = LEFT; break;
94 
95         case IMAGEALIGN_TOP_LEFT:
96         case IMAGEALIGN_TOP:
97         case IMAGEALIGN_TOP_RIGHT:      nReturn = TOP; break;
98 
99         case IMAGEALIGN_RIGHT_TOP:
100         case IMAGEALIGN_RIGHT:
101         case IMAGEALIGN_RIGHT_BOTTOM:   nReturn = RIGHT; break;
102 
103         case IMAGEALIGN_BOTTOM_LEFT:
104         case IMAGEALIGN_BOTTOM:
105         case IMAGEALIGN_BOTTOM_RIGHT:   nReturn = BOTTOM; break;
106 
107         case IMAGEALIGN_CENTER:         nReturn = TOP; break;
108         default:
109             OSL_ENSURE( sal_False, "getCompatibleImageAlign: unknown IMAGEALIGN value!" );
110         }
111         return nReturn;
112     }
113 
getExtendedImagePosition(sal_Int16 _nImageAlign)114     sal_Int16 getExtendedImagePosition( sal_Int16 _nImageAlign )
115     {
116         sal_Int16 nReturn = AboveCenter;
117         switch ( _nImageAlign )
118         {
119         case LEFT:   nReturn = LeftCenter; break;
120         case TOP:    nReturn = AboveCenter; break;
121         case RIGHT:  nReturn = RightCenter; break;
122         case BOTTOM: nReturn = BelowCenter; break;
123         default:
124             OSL_ENSURE( sal_False, "getExtendedImagePosition: unknown ImageAlign value!" );
125         }
126         return nReturn;
127     }
128 
129 //........................................................................
130 }   // namespace toolkit
131 //........................................................................
132