xref: /AOO41X/main/sc/source/core/data/scdpoutputimpl.cxx (revision d0626817eadca72252d341a27a0d42c4a6bf2287)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
24 #include "precompiled_sc.hxx"
25 
26 // INCLUDE ---------------------------------------------------------------
27 #include "scdpoutputimpl.hxx"
28 #include "scitems.hxx"
29 #include <editeng/boxitem.hxx>
30 // -----------------------------------------------------------------------
31 
32 namespace
33 {
lcl_compareColfuc(SCCOL i,SCCOL j)34     bool lcl_compareColfuc ( SCCOL i,  SCCOL j) { return (i<j); }
lcl_compareRowfuc(SCROW i,SCROW j)35     bool lcl_compareRowfuc ( SCROW i,  SCROW j) { return (i<j); }
36 }
37 
38 
OutputDataArea()39 void OutputImpl::OutputDataArea()
40 {
41     AddRow( mnDataStartRow );
42     AddCol( mnDataStartCol );
43 
44     mnCols.push_back( mnTabEndCol+1); //set last row bottom
45     mnRows.push_back( mnTabEndRow+1); //set last col bottom
46 
47     sal_Bool bAllRows = ( ( mnTabEndRow - mnDataStartRow + 2 ) == (SCROW) mnRows.size() );
48 
49     std::sort( mnCols.begin(), mnCols.end(), lcl_compareColfuc );
50     std::sort( mnRows.begin(), mnRows.end(), lcl_compareRowfuc );
51 
52     for( SCCOL nCol = 0; nCol < (SCCOL)mnCols.size()-1; nCol ++ )
53     {
54         if ( !bAllRows )
55         {
56             if ( nCol < (SCCOL)mnCols.size()-2)
57             {
58                 for ( SCROW i = nCol%2; i < (SCROW)mnRows.size()-2; i +=2 )
59                     OutputBlockFrame( mnCols[nCol], mnRows[i], mnCols[nCol+1]-1, mnRows[i+1]-1 );
60                 if ( mnRows.size()>=2 )
61                     OutputBlockFrame(  mnCols[nCol], mnRows[mnRows.size()-2], mnCols[nCol+1]-1, mnRows[mnRows.size()-1]-1 );
62             }
63             else
64             {
65                 for ( SCROW i = 0 ; i < (SCROW)mnRows.size()-1; i++ )
66                     OutputBlockFrame(  mnCols[nCol], mnRows[i], mnCols[nCol+1]-1,  mnRows[i+1]-1 );
67             }
68         }
69         else
70             OutputBlockFrame( mnCols[nCol], mnRows.front(), mnCols[nCol+1]-1, mnRows.back()-1, bAllRows );
71     }
72     //out put rows area outer framer
73     if ( mnTabStartCol != mnDataStartCol )
74     {
75         if ( mnTabStartRow != mnDataStartRow )
76             OutputBlockFrame( mnTabStartCol, mnTabStartRow, mnDataStartCol-1, mnDataStartRow-1 );
77         OutputBlockFrame( mnTabStartCol, mnDataStartRow, mnDataStartCol-1, mnTabEndRow );
78     }
79     //out put cols area outer framer
80     OutputBlockFrame( mnDataStartCol, mnTabStartRow, mnTabEndCol, mnDataStartRow-1 );
81 }
82 
OutputImpl(ScDocument * pDoc,sal_uInt16 nTab,SCCOL nTabStartCol,SCROW nTabStartRow,SCCOL nMemberStartCol,SCROW nMemberStartRow,SCCOL nDataStartCol,SCROW nDataStartRow,SCCOL nTabEndCol,SCROW nTabEndRow)83 OutputImpl::OutputImpl( ScDocument* pDoc, sal_uInt16 nTab,
84         SCCOL   nTabStartCol,
85         SCROW   nTabStartRow,
86         SCCOL   nMemberStartCol,
87         SCROW   nMemberStartRow,
88         SCCOL nDataStartCol,
89         SCROW nDataStartRow,
90         SCCOL nTabEndCol,
91         SCROW nTabEndRow ):
92     mpDoc( pDoc ),
93     mnTab( nTab ),
94     mnTabStartCol( nTabStartCol ),
95     mnTabStartRow( nTabStartRow ),
96     mnMemberStartCol( nMemberStartCol),
97     mnMemberStartRow( nMemberStartRow),
98     mnDataStartCol ( nDataStartCol ),
99     mnDataStartRow ( nDataStartRow ),
100     mnTabEndCol(  nTabEndCol ),
101     mnTabEndRow(  nTabEndRow )
102 {
103     mbNeedLineCols.resize( nTabEndCol-nDataStartCol+1, false );
104     mbNeedLineRows.resize( nTabEndRow-nDataStartRow+1, false );
105 
106 }
107 
AddRow(SCROW nRow)108 sal_Bool OutputImpl::AddRow( SCROW nRow )
109 {
110     if ( !mbNeedLineRows[ nRow - mnDataStartRow ] )
111     {
112         mbNeedLineRows[ nRow - mnDataStartRow ] = true;
113         mnRows.push_back( nRow );
114         return sal_True;
115     }
116     else
117         return sal_False;
118 }
119 
AddCol(SCCOL nCol)120 sal_Bool OutputImpl::AddCol( SCCOL nCol )
121 {
122 
123     if ( !mbNeedLineCols[ nCol - mnDataStartCol ] )
124     {
125         mbNeedLineCols[ nCol - mnDataStartCol ] = true;
126         mnCols.push_back( nCol );
127         return sal_True;
128     }
129     else
130         return sal_False;
131 }
132 
OutputBlockFrame(SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow,sal_Bool bHori)133 void OutputImpl::OutputBlockFrame ( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, sal_Bool bHori )
134 {
135 
136     SvxBorderLine aLine, aOutLine;
137     aLine.SetColor( SC_DP_FRAME_COLOR );
138     aLine.SetOutWidth( SC_DP_FRAME_INNER_BOLD );
139     aOutLine.SetColor( SC_DP_FRAME_COLOR );
140     aOutLine.SetOutWidth( SC_DP_FRAME_OUTER_BOLD );
141 
142     SvxBoxItem aBox( ATTR_BORDER );
143 
144     if ( nStartCol == mnTabStartCol )
145         aBox.SetLine(&aOutLine, BOX_LINE_LEFT);
146     else
147         aBox.SetLine(&aLine, BOX_LINE_LEFT);
148 
149     if ( nStartRow == mnTabStartRow )
150         aBox.SetLine(&aOutLine, BOX_LINE_TOP);
151     else
152         aBox.SetLine(&aLine, BOX_LINE_TOP);
153 
154     if ( nEndCol == mnTabEndCol ) //bottom row
155         aBox.SetLine(&aOutLine, BOX_LINE_RIGHT);
156     else
157         aBox.SetLine(&aLine,  BOX_LINE_RIGHT);
158 
159     if ( nEndRow == mnTabEndRow ) //bottom
160         aBox.SetLine(&aOutLine,  BOX_LINE_BOTTOM);
161     else
162         aBox.SetLine(&aLine,  BOX_LINE_BOTTOM);
163 
164 
165     SvxBoxInfoItem aBoxInfo( ATTR_BORDER_INNER );
166     aBoxInfo.SetValid(VALID_VERT,sal_False );
167     if ( bHori )
168     {
169         aBoxInfo.SetValid(VALID_HORI,sal_True);
170         aBoxInfo.SetLine( &aLine, BOXINFO_LINE_HORI );
171     }
172     else
173         aBoxInfo.SetValid(VALID_HORI,sal_False );
174 
175     aBoxInfo.SetValid(VALID_DISTANCE,sal_False);
176 
177     mpDoc->ApplyFrameAreaTab( ScRange(  nStartCol, nStartRow, mnTab, nEndCol, nEndRow , mnTab ), &aBox, &aBoxInfo );
178 
179 }
180