Update ooo320-m1
[ooovba.git] / sc / source / filter / qpro / qprostyle.cxx
blobc20e70d7ef7c03275994c8bd38d7e73683f93487
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: qprostyle.cxx,v $
10 * $Revision: 1.7 $
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_sc.hxx"
35 #include <sal/config.h>
36 #include <stdio.h>
37 #include <sfx2/docfile.hxx>
39 #include "qproform.hxx"
40 #include "qpro.hxx"
41 #include "qprostyle.hxx"
43 #include <tools/color.hxx>
44 #include <scitems.hxx>
45 #include <svx/algitem.hxx>
46 #include <svx/udlnitem.hxx>
47 #include <svx/wghtitem.hxx>
48 #include <svx/postitem.hxx>
49 #include <svx/crsditem.hxx>
50 #include <svx/fhgtitem.hxx>
51 #include <svx/fontitem.hxx>
52 #include <map>
54 #include "global.hxx"
55 #include "scerrors.hxx"
56 #include "docpool.hxx"
57 #include "patattr.hxx"
58 #include "filter.hxx"
59 #include "document.hxx"
60 #include "cell.hxx"
62 ScQProStyle::ScQProStyle()
64 rtl_fillMemory (maAlign, sizeof (maAlign), 0);
65 rtl_fillMemory (maFont, sizeof (maFont), 0);
66 rtl_fillMemory (maFontRecord, sizeof (maFontRecord), 0);
67 rtl_fillMemory (maFontHeight, sizeof (maFontHeight), 0);
70 void ScQProStyle::SetFormat( ScDocument *pDoc, sal_uInt8 nCol, sal_uInt16 nRow, SCTAB nTab, sal_uInt16 nStyle )
72 if (nStyle >= maxsize)
73 return;
75 ScPatternAttr aPattern(pDoc->GetPool());
76 SfxItemSet& rItemSet = aPattern.GetItemSet();
78 sal_uInt8 nTmp = maAlign[ nStyle ];
79 sal_uInt8 nHor = ( nTmp & 0x07 );
80 sal_uInt8 nVer = ( nTmp & 0x18 );
81 sal_uInt8 nOrient = ( nTmp & 0x60 );
83 // Horizontal Alignment
84 SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_STANDARD;
85 switch( nHor )
87 case 0x00:
88 eJustify = SVX_HOR_JUSTIFY_STANDARD;
89 break;
91 case 0x01:
92 eJustify = SVX_HOR_JUSTIFY_LEFT;
93 break;
95 case 0x02:
96 eJustify = SVX_HOR_JUSTIFY_CENTER;
97 break;
99 case 0x03:
100 eJustify = SVX_HOR_JUSTIFY_RIGHT;
101 break;
103 case 0x04:
104 eJustify = SVX_HOR_JUSTIFY_BLOCK;
105 break;
107 rItemSet.Put( SvxHorJustifyItem( eJustify, ATTR_HOR_JUSTIFY ) );
109 // Vertical Alignment
110 SvxCellVerJustify eVerJustify = SVX_VER_JUSTIFY_STANDARD;
111 switch( nVer )
113 case 0x00:
114 eVerJustify = SVX_VER_JUSTIFY_BOTTOM;
115 break;
117 case 0x08:
118 eVerJustify = SVX_VER_JUSTIFY_CENTER;
119 break;
121 case 0x10:
122 eVerJustify = SVX_VER_JUSTIFY_TOP;
123 break;
126 rItemSet.Put(SvxVerJustifyItem( eVerJustify, ATTR_VER_JUSTIFY ) );
128 // Orientation
129 SvxCellOrientation eOrient = SVX_ORIENTATION_STANDARD;
130 switch( nOrient )
132 case 0x20:
133 eOrient = SVX_ORIENTATION_TOPBOTTOM;
134 break;
137 rItemSet.Put( SvxOrientationItem( eOrient, 0) );
139 // Wrap cell contents
140 if( nTmp & 0x80 )
142 SfxBoolItem aWrapItem( ATTR_LINEBREAK );
143 aWrapItem.SetValue( TRUE );
144 rItemSet.Put( aWrapItem );
147 // Font Attributes
148 sal_uInt16 nTmpFnt = maFontRecord[ maFont[ nStyle ] ];
149 BOOL bIsBold, bIsItalic, bIsUnderLine, bIsStrikeThrough;
151 bIsBold = ( nTmpFnt & 0x0001 ) != 0;
152 bIsItalic = ( nTmpFnt & 0x0002 ) != 0;
153 bIsUnderLine = ( nTmpFnt & 0x0004 ) != 0;
154 bIsStrikeThrough = (nTmpFnt & 0x0020 ) != 0;
156 if( bIsBold )
157 rItemSet.Put( SvxWeightItem( WEIGHT_BOLD,ATTR_FONT_WEIGHT) );
158 if( bIsItalic )
159 rItemSet.Put( SvxPostureItem( ITALIC_NORMAL, ATTR_FONT_POSTURE ) );
160 if( bIsUnderLine )
161 rItemSet.Put( SvxUnderlineItem( UNDERLINE_SINGLE, ATTR_FONT_UNDERLINE ) );
163 if (maFontHeight[ maFont [ nStyle ] ])
164 rItemSet.Put( SvxFontHeightItem( (ULONG) (20 * maFontHeight[ maFont[ nStyle ] ] ), 100, ATTR_FONT_HEIGHT ) );
166 String fntName = maFontType[ maFont[ nStyle ] ];
167 rItemSet.Put( SvxFontItem( FAMILY_SYSTEM, fntName, EMPTY_STRING, PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, ATTR_FONT ) );
169 pDoc->ApplyPattern( nCol, nRow, nTab, aPattern );