1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright IBM Corporation 2009.
6  * Copyright 2009 by Sun Microsystems, Inc.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * $RCSfile: scdpoutputimpl.cxx,v $
11  * $Revision: 1.0 $
12  *
13  * This file is part of OpenOffice.org.
14  *
15  * OpenOffice.org is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU Lesser General Public License version 3
17  * only, as published by the Free Software Foundation.
18  *
19  * OpenOffice.org is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU Lesser General Public License version 3 for more details
23  * (a copy is included in the LICENSE file that accompanied this code).
24  *
25  * You should have received a copy of the GNU Lesser General Public License
26  * version 3 along with OpenOffice.org.  If not, see
27  * <http://www.openoffice.org/license.html>
28  * for a copy of the LGPLv3 License.
29  *
30  ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 
34 // INCLUDE ---------------------------------------------------------------
35 #include "scdpoutputimpl.hxx"
36 #include "scitems.hxx"
37 #include <editeng/boxitem.hxx>
38 // -----------------------------------------------------------------------
39 
40 namespace
41 {
42 	bool lcl_compareColfuc ( SCCOL i,  SCCOL j) { return (i<j); }
43 	bool lcl_compareRowfuc ( SCROW i,  SCROW j) { return (i<j); }
44 }
45 
46 
47 void OutputImpl::OutputDataArea()
48 {
49 	AddRow( mnDataStartRow );
50 	AddCol( mnDataStartCol );
51 
52 	mnCols.push_back( mnTabEndCol+1); //set last row bottom
53 	mnRows.push_back( mnTabEndRow+1); //set last col bottom
54 
55 	sal_Bool bAllRows = ( ( mnTabEndRow - mnDataStartRow + 2 ) == (SCROW) mnRows.size() );
56 
57 	std::sort( mnCols.begin(), mnCols.end(), lcl_compareColfuc );
58 	std::sort( mnRows.begin(), mnRows.end(), lcl_compareRowfuc );
59 
60 	for( SCCOL nCol = 0; nCol < (SCCOL)mnCols.size()-1; nCol ++ )
61 	{
62 		if ( !bAllRows )
63 		{
64 			if ( nCol < (SCCOL)mnCols.size()-2)
65 			{
66 				for ( SCROW i = nCol%2; i < (SCROW)mnRows.size()-2; i +=2 )
67 					OutputBlockFrame( mnCols[nCol], mnRows[i], mnCols[nCol+1]-1, mnRows[i+1]-1 );
68 				if ( mnRows.size()>=2 )
69 					OutputBlockFrame(  mnCols[nCol], mnRows[mnRows.size()-2], mnCols[nCol+1]-1, mnRows[mnRows.size()-1]-1 );
70 			}
71 			else
72 			{
73 				for ( SCROW i = 0 ; i < (SCROW)mnRows.size()-1; i++ )
74 					OutputBlockFrame(  mnCols[nCol], mnRows[i], mnCols[nCol+1]-1,  mnRows[i+1]-1 );
75 			}
76 		}
77 		else
78 			OutputBlockFrame( mnCols[nCol], mnRows.front(), mnCols[nCol+1]-1, mnRows.back()-1, bAllRows );
79 	}
80 	//out put rows area outer framer
81 	if ( mnTabStartCol != mnDataStartCol )
82 	{
83 		if ( mnTabStartRow != mnDataStartRow )
84 			OutputBlockFrame( mnTabStartCol, mnTabStartRow, mnDataStartCol-1, mnDataStartRow-1 );
85 		OutputBlockFrame( mnTabStartCol, mnDataStartRow, mnDataStartCol-1, mnTabEndRow );
86 	}
87 	//out put cols area outer framer
88 	OutputBlockFrame( mnDataStartCol, mnTabStartRow, mnTabEndCol, mnDataStartRow-1 );
89 }
90 
91 OutputImpl::OutputImpl( ScDocument*	pDoc, sal_uInt16 nTab,
92 		SCCOL	nTabStartCol,
93 		SCROW	nTabStartRow,
94 		SCCOL	nMemberStartCol,
95 		SCROW	nMemberStartRow,
96 		SCCOL nDataStartCol,
97 		SCROW nDataStartRow,
98 		SCCOL nTabEndCol,
99 		SCROW nTabEndRow ):
100 	mpDoc( pDoc ),
101 	mnTab( nTab ),
102 	mnTabStartCol( nTabStartCol ),
103 	mnTabStartRow( nTabStartRow ),
104 	mnMemberStartCol( nMemberStartCol),
105 	mnMemberStartRow( nMemberStartRow),
106 	mnDataStartCol ( nDataStartCol ),
107 	mnDataStartRow ( nDataStartRow ),
108 	mnTabEndCol(  nTabEndCol ),
109 	mnTabEndRow(  nTabEndRow )
110 {
111 	mbNeedLineCols.resize( nTabEndCol-nDataStartCol+1, false );
112 	mbNeedLineRows.resize( nTabEndRow-nDataStartRow+1, false );
113 
114 }
115 
116 sal_Bool OutputImpl::AddRow( SCROW nRow )
117 {
118 	if ( !mbNeedLineRows[ nRow - mnDataStartRow ] )
119 	{
120 		mbNeedLineRows[ nRow - mnDataStartRow ] = true;
121 		mnRows.push_back( nRow );
122 		return sal_True;
123 	}
124 	else
125 		return sal_False;
126 }
127 
128 sal_Bool OutputImpl::AddCol( SCCOL nCol )
129 {
130 
131 	if ( !mbNeedLineCols[ nCol - mnDataStartCol ] )
132 	{
133 		mbNeedLineCols[ nCol - mnDataStartCol ] = true;
134 		mnCols.push_back( nCol );
135 		return sal_True;
136 	}
137 	else
138 		return sal_False;
139 }
140 
141 void OutputImpl::OutputBlockFrame ( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, sal_Bool bHori )
142 {
143 
144 	SvxBorderLine aLine, aOutLine;
145 	aLine.SetColor( SC_DP_FRAME_COLOR );
146 	aLine.SetOutWidth( SC_DP_FRAME_INNER_BOLD );
147 	aOutLine.SetColor( SC_DP_FRAME_COLOR );
148 	aOutLine.SetOutWidth( SC_DP_FRAME_OUTER_BOLD );
149 
150 	SvxBoxItem aBox( ATTR_BORDER );
151 
152 	if ( nStartCol == mnTabStartCol )
153 		aBox.SetLine(&aOutLine, BOX_LINE_LEFT);
154 	else
155 		aBox.SetLine(&aLine, BOX_LINE_LEFT);
156 
157 	if ( nStartRow == mnTabStartRow )
158 		aBox.SetLine(&aOutLine, BOX_LINE_TOP);
159 	else
160 		aBox.SetLine(&aLine, BOX_LINE_TOP);
161 
162 	if ( nEndCol == mnTabEndCol ) //bottom row
163 		aBox.SetLine(&aOutLine, BOX_LINE_RIGHT);
164 	else
165 		aBox.SetLine(&aLine,  BOX_LINE_RIGHT);
166 
167  	if ( nEndRow == mnTabEndRow ) //bottom
168 		aBox.SetLine(&aOutLine,  BOX_LINE_BOTTOM);
169 	else
170 		aBox.SetLine(&aLine,  BOX_LINE_BOTTOM);
171 
172 
173 	SvxBoxInfoItem aBoxInfo( ATTR_BORDER_INNER );
174 	aBoxInfo.SetValid(VALID_VERT,sal_False );
175 	if ( bHori )
176 	{
177 		aBoxInfo.SetValid(VALID_HORI,sal_True);
178 		aBoxInfo.SetLine( &aLine, BOXINFO_LINE_HORI );
179 	}
180 	else
181 		aBoxInfo.SetValid(VALID_HORI,sal_False );
182 
183 	aBoxInfo.SetValid(VALID_DISTANCE,sal_False);
184 
185 	mpDoc->ApplyFrameAreaTab( ScRange(  nStartCol, nStartRow, mnTab, nEndCol, nEndRow , mnTab ), &aBox, &aBoxInfo );
186 
187 }
188