xref: /trunk/main/sc/source/filter/qpro/qprostyle.cxx (revision b77af630)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b77af630Sdamjan #include "precompiled_scfilt.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <sal/config.h>
29cdf0e10cSrcweir #include <stdio.h>
30cdf0e10cSrcweir #include <sfx2/docfile.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "qproform.hxx"
33cdf0e10cSrcweir #include "qpro.hxx"
34cdf0e10cSrcweir #include "qprostyle.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <tools/color.hxx>
37cdf0e10cSrcweir #include <scitems.hxx>
38cdf0e10cSrcweir #include <svx/algitem.hxx>
39cdf0e10cSrcweir #include <editeng/udlnitem.hxx>
40cdf0e10cSrcweir #include <editeng/wghtitem.hxx>
41cdf0e10cSrcweir #include <editeng/postitem.hxx>
42cdf0e10cSrcweir #include <editeng/crsditem.hxx>
43cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
44cdf0e10cSrcweir #include <editeng/fontitem.hxx>
45cdf0e10cSrcweir #include <map>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include "global.hxx"
48cdf0e10cSrcweir #include "scerrors.hxx"
49cdf0e10cSrcweir #include "docpool.hxx"
50cdf0e10cSrcweir #include "patattr.hxx"
51cdf0e10cSrcweir #include "filter.hxx"
52cdf0e10cSrcweir #include "document.hxx"
53cdf0e10cSrcweir #include "cell.hxx"
54cdf0e10cSrcweir 
ScQProStyle()55cdf0e10cSrcweir ScQProStyle::ScQProStyle()
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	rtl_fillMemory (maAlign, sizeof (maAlign), 0);
58cdf0e10cSrcweir 	rtl_fillMemory (maFont, sizeof (maFont), 0);
59cdf0e10cSrcweir 	rtl_fillMemory (maFontRecord, sizeof (maFontRecord), 0);
60cdf0e10cSrcweir 	rtl_fillMemory (maFontHeight, sizeof (maFontHeight), 0);
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
SetFormat(ScDocument * pDoc,sal_uInt8 nCol,sal_uInt16 nRow,SCTAB nTab,sal_uInt16 nStyle)63cdf0e10cSrcweir void ScQProStyle::SetFormat( ScDocument *pDoc, sal_uInt8 nCol, sal_uInt16 nRow, SCTAB nTab, sal_uInt16 nStyle )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     if (nStyle >= maxsize)
66cdf0e10cSrcweir         return;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     ScPatternAttr aPattern(pDoc->GetPool());
69cdf0e10cSrcweir     SfxItemSet& rItemSet = aPattern.GetItemSet();
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     sal_uInt8 nTmp = maAlign[ nStyle ];
72cdf0e10cSrcweir     sal_uInt8 nHor = ( nTmp & 0x07 );
73cdf0e10cSrcweir     sal_uInt8 nVer = ( nTmp & 0x18 );
74cdf0e10cSrcweir     sal_uInt8 nOrient = ( nTmp & 0x60 );
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     // Horizontal Alignment
77cdf0e10cSrcweir     SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_STANDARD;
78cdf0e10cSrcweir     switch( nHor )
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         case 0x00:
81cdf0e10cSrcweir             eJustify = SVX_HOR_JUSTIFY_STANDARD;
82cdf0e10cSrcweir             break;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         case 0x01:
85cdf0e10cSrcweir             eJustify = SVX_HOR_JUSTIFY_LEFT;
86cdf0e10cSrcweir             break;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         case 0x02:
89cdf0e10cSrcweir             eJustify = SVX_HOR_JUSTIFY_CENTER;
90cdf0e10cSrcweir             break;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         case 0x03:
93cdf0e10cSrcweir             eJustify = SVX_HOR_JUSTIFY_RIGHT;
94cdf0e10cSrcweir             break;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         case 0x04:
97cdf0e10cSrcweir             eJustify = SVX_HOR_JUSTIFY_BLOCK;
98cdf0e10cSrcweir             break;
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir     rItemSet.Put( SvxHorJustifyItem( eJustify, ATTR_HOR_JUSTIFY ) );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     // Vertical Alignment
103cdf0e10cSrcweir     SvxCellVerJustify eVerJustify = SVX_VER_JUSTIFY_STANDARD;
104cdf0e10cSrcweir     switch( nVer )
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         case 0x00:
107cdf0e10cSrcweir             eVerJustify = SVX_VER_JUSTIFY_BOTTOM;
108cdf0e10cSrcweir             break;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         case 0x08:
111cdf0e10cSrcweir             eVerJustify = SVX_VER_JUSTIFY_CENTER;
112cdf0e10cSrcweir             break;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         case 0x10:
115cdf0e10cSrcweir             eVerJustify = SVX_VER_JUSTIFY_TOP;
116cdf0e10cSrcweir             break;
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     rItemSet.Put(SvxVerJustifyItem( eVerJustify, ATTR_VER_JUSTIFY ) );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     // Orientation
122cdf0e10cSrcweir     SvxCellOrientation eOrient = SVX_ORIENTATION_STANDARD;
123cdf0e10cSrcweir     switch( nOrient )
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         case 0x20:
126cdf0e10cSrcweir             eOrient = SVX_ORIENTATION_TOPBOTTOM;
127cdf0e10cSrcweir             break;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir     rItemSet.Put( SvxOrientationItem( eOrient, 0) );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     // Wrap cell contents
133cdf0e10cSrcweir     if( nTmp & 0x80 )
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         SfxBoolItem aWrapItem( ATTR_LINEBREAK );
136cdf0e10cSrcweir         aWrapItem.SetValue( sal_True );
137cdf0e10cSrcweir         rItemSet.Put( aWrapItem );
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     // Font Attributes
141cdf0e10cSrcweir     sal_uInt16 nTmpFnt = maFontRecord[ maFont[ nStyle ] ];
142cdf0e10cSrcweir     sal_Bool bIsBold, bIsItalic, bIsUnderLine, bIsStrikeThrough;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     bIsBold = ( nTmpFnt & 0x0001 ) != 0;
145cdf0e10cSrcweir     bIsItalic = ( nTmpFnt & 0x0002 ) != 0;
146cdf0e10cSrcweir     bIsUnderLine = ( nTmpFnt & 0x0004 ) != 0;
147cdf0e10cSrcweir     bIsStrikeThrough = (nTmpFnt & 0x0020 ) != 0;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     if( bIsBold )
150cdf0e10cSrcweir         rItemSet.Put( SvxWeightItem( WEIGHT_BOLD,ATTR_FONT_WEIGHT) );
151cdf0e10cSrcweir     if( bIsItalic )
152cdf0e10cSrcweir         rItemSet.Put( SvxPostureItem( ITALIC_NORMAL, ATTR_FONT_POSTURE ) );
153cdf0e10cSrcweir     if( bIsUnderLine )
154cdf0e10cSrcweir         rItemSet.Put( SvxUnderlineItem( UNDERLINE_SINGLE, ATTR_FONT_UNDERLINE ) );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	if (maFontHeight[ maFont [ nStyle ] ])
157cdf0e10cSrcweir         rItemSet.Put( SvxFontHeightItem( (sal_uLong) (20 * maFontHeight[ maFont[ nStyle ] ] ), 100, ATTR_FONT_HEIGHT ) );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     String fntName = maFontType[ maFont[ nStyle ] ];
160cdf0e10cSrcweir     rItemSet.Put( SvxFontItem( FAMILY_SYSTEM, fntName, EMPTY_STRING, PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, ATTR_FONT ) );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     pDoc->ApplyPattern( nCol, nRow, nTab, aPattern );
163cdf0e10cSrcweir }
164