xref: /aoo41x/main/sc/source/ui/view/colrowba.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 // INCLUDE ---------------------------------------------------------------
34 
35 #include <svx/svdtrans.hxx>
36 #include <unotools/localedatawrapper.hxx>
37 
38 #include "colrowba.hxx"
39 #include "document.hxx"
40 #include "scmod.hxx"
41 #include "tabvwsh.hxx"
42 #include "docsh.hxx"
43 #include "appoptio.hxx"
44 #include "globstr.hrc"
45 
46 // STATIC DATA -----------------------------------------------------------
47 
48 //==================================================================
49 
50 String lcl_MetricString( long nTwips, const String& rText )
51 {
52 	if ( nTwips <= 0 )
53 		return ScGlobal::GetRscString(STR_TIP_HIDE);
54 	else
55 	{
56 		FieldUnit eUserMet = SC_MOD()->GetAppOptions().GetAppMetric();
57 
58         sal_Int64 nUserVal = MetricField::ConvertValue( nTwips*100, 1, 2, FUNIT_TWIP, eUserMet );
59 
60 		String aStr = rText;
61 		aStr += ' ';
62         aStr += ScGlobal::pLocaleData->getNum( nUserVal, 2 );
63 		aStr += ' ';
64 		aStr += SdrFormatter::GetUnitStr(eUserMet);
65 
66 		return aStr;
67 	}
68 }
69 
70 //==================================================================
71 
72 ScColBar::ScColBar( Window* pParent, ScViewData* pData, ScHSplitPos eWhichPos,
73 					ScHeaderFunctionSet* pFunc, ScHeaderSelectionEngine* pEng ) :
74 			ScHeaderControl( pParent, pEng, MAXCOL+1, HDR_HORIZONTAL ),
75 			pViewData( pData ),
76 			eWhich( eWhichPos ),
77 			pFuncSet( pFunc ),
78 			pSelEngine( pEng )
79 {
80 	Show();
81 }
82 
83 ScColBar::~ScColBar()
84 {
85 }
86 
87 inline sal_Bool ScColBar::UseNumericHeader() const
88 {
89     return pViewData->GetDocument()->GetAddressConvention() == formula::FormulaGrammar::CONV_XL_R1C1;
90 }
91 
92 SCCOLROW ScColBar::GetPos()
93 {
94 	return pViewData->GetPosX(eWhich);
95 }
96 
97 sal_uInt16 ScColBar::GetEntrySize( SCCOLROW nEntryNo )
98 {
99 	ScDocument* pDoc = pViewData->GetDocument();
100 	SCTAB nTab = pViewData->GetTabNo();
101 	SCCOL nLastCol = -1;
102 	if (pDoc->ColHidden(static_cast<SCCOL>(nEntryNo), nTab, nLastCol))
103 		return 0;
104 	else
105 		return (sal_uInt16) ScViewData::ToPixel( pDoc->GetColWidth( static_cast<SCCOL>(nEntryNo), nTab ), pViewData->GetPPTX() );
106 }
107 
108 String ScColBar::GetEntryText( SCCOLROW nEntryNo )
109 {
110 	return UseNumericHeader()
111 	    ? String::CreateFromInt32( nEntryNo + 1 )
112 	    : ScColToAlpha( static_cast<SCCOL>(nEntryNo) );
113 }
114 
115 void ScColBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
116 {
117 	sal_uInt16 nSizeTwips;
118 	ScSizeMode eMode = SC_SIZE_DIRECT;
119 	if (nNewSize>0 && nNewSize<10) nNewSize=10;				// (Pixel)
120 
121 	if ( nNewSize == HDR_SIZE_OPTIMUM )
122 	{
123 		nSizeTwips = STD_EXTRA_WIDTH;
124 		eMode = SC_SIZE_OPTIMAL;
125 	}
126 	else
127 		nSizeTwips = (sal_uInt16) ( nNewSize / pViewData->GetPPTX() );
128 
129 	ScMarkData& rMark = pViewData->GetMarkData();
130 //	SCTAB nTab = pViewData->GetTabNo();
131 
132 	SCCOLROW* pRanges = new SCCOLROW[MAXCOL+1];
133 	SCCOL nRangeCnt = 0;
134 	if ( rMark.IsColumnMarked( static_cast<SCCOL>(nPos) ) )
135 	{
136 		SCCOL nStart = 0;
137 		while (nStart<=MAXCOL)
138 		{
139 			while (nStart<MAXCOL && !rMark.IsColumnMarked(nStart))
140 				++nStart;
141 			if (rMark.IsColumnMarked(nStart))
142 			{
143 				SCCOL nEnd = nStart;
144 				while (nEnd<MAXCOL && rMark.IsColumnMarked(nEnd))
145 					++nEnd;
146 				if (!rMark.IsColumnMarked(nEnd))
147 					--nEnd;
148 				pRanges[static_cast<size_t>(2*nRangeCnt)  ] = nStart;
149 				pRanges[static_cast<size_t>(2*nRangeCnt+1)] = nEnd;
150 				++nRangeCnt;
151 				nStart = nEnd+1;
152 			}
153 			else
154 				nStart = MAXCOL+1;
155 		}
156 	}
157 	else
158 	{
159 		pRanges[0] = nPos;
160 		pRanges[1] = nPos;
161 		nRangeCnt = 1;
162 	}
163 
164 	pViewData->GetView()->SetWidthOrHeight( sal_True, nRangeCnt, pRanges, eMode, nSizeTwips );
165 	delete[] pRanges;
166 }
167 
168 void ScColBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
169 {
170 	SCCOLROW nRange[2];
171 	nRange[0] = nStart;
172 	nRange[1] = nEnd;
173 	pViewData->GetView()->SetWidthOrHeight( sal_True, 1, nRange, SC_SIZE_DIRECT, 0 );
174 }
175 
176 void ScColBar::SetMarking( sal_Bool bSet )
177 {
178 	pViewData->GetMarkData().SetMarking( bSet );
179 	if (!bSet)
180 	{
181 		pViewData->GetView()->UpdateAutoFillMark();
182 	}
183 }
184 
185 void ScColBar::SelectWindow()
186 {
187 	ScTabViewShell* pViewSh = pViewData->GetViewShell();
188 
189 	pViewSh->SetActive();			// Appear und SetViewFrame
190 	pViewSh->DrawDeselectAll();
191 
192 	ScSplitPos eActive = pViewData->GetActivePart();
193 	if (eWhich==SC_SPLIT_LEFT)
194 	{
195 		if (eActive==SC_SPLIT_TOPRIGHT)		eActive=SC_SPLIT_TOPLEFT;
196 		if (eActive==SC_SPLIT_BOTTOMRIGHT)	eActive=SC_SPLIT_BOTTOMLEFT;
197 	}
198 	else
199 	{
200 		if (eActive==SC_SPLIT_TOPLEFT)		eActive=SC_SPLIT_TOPRIGHT;
201 		if (eActive==SC_SPLIT_BOTTOMLEFT)	eActive=SC_SPLIT_BOTTOMRIGHT;
202 	}
203 	pViewSh->ActivatePart( eActive );
204 
205 	pFuncSet->SetColumn( sal_True );
206 	pFuncSet->SetWhich( eActive );
207 
208 	pViewSh->ActiveGrabFocus();
209 }
210 
211 sal_Bool ScColBar::IsDisabled()
212 {
213 	ScModule* pScMod = SC_MOD();
214 	return pScMod->IsFormulaMode() || pScMod->IsModalMode();
215 }
216 
217 sal_Bool ScColBar::ResizeAllowed()
218 {
219 	return !pViewData->HasEditView( pViewData->GetActivePart() ) &&
220 			!pViewData->GetDocShell()->IsReadOnly();
221 }
222 
223 void ScColBar::DrawInvert( long nDragPosP )
224 {
225 	Rectangle aRect( nDragPosP,0, nDragPosP+HDR_SLIDERSIZE-1,GetOutputSizePixel().Width()-1 );
226 	Update();
227 	Invert(aRect);
228 
229 	pViewData->GetView()->InvertVertical(eWhich,nDragPosP);
230 }
231 
232 String ScColBar::GetDragHelp( long nVal )
233 {
234 	long nTwips = (long) ( nVal / pViewData->GetPPTX() );
235 	return lcl_MetricString( nTwips, ScGlobal::GetRscString(STR_TIP_WIDTH) );
236 }
237 
238 sal_Bool ScColBar::IsLayoutRTL()		// overloaded only for columns
239 {
240 	return pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
241 }
242 
243 //==================================================================
244 
245 ScRowBar::ScRowBar( Window* pParent, ScViewData* pData, ScVSplitPos eWhichPos,
246 					ScHeaderFunctionSet* pFunc, ScHeaderSelectionEngine* pEng ) :
247 			ScHeaderControl( pParent, pEng, MAXROW+1, HDR_VERTICAL ),
248 			pViewData( pData ),
249 			eWhich( eWhichPos ),
250 			pFuncSet( pFunc ),
251 			pSelEngine( pEng )
252 {
253 	Show();
254 }
255 
256 ScRowBar::~ScRowBar()
257 {
258 }
259 
260 SCCOLROW ScRowBar::GetPos()
261 {
262 	return pViewData->GetPosY(eWhich);
263 }
264 
265 sal_uInt16 ScRowBar::GetEntrySize( SCCOLROW nEntryNo )
266 {
267 	ScDocument* pDoc = pViewData->GetDocument();
268 	SCTAB nTab = pViewData->GetTabNo();
269 	SCROW nLastRow = -1;
270 	if (pDoc->RowHidden(nEntryNo, nTab, nLastRow))
271 		return 0;
272 	else
273         return (sal_uInt16) ScViewData::ToPixel( pDoc->GetOriginalHeight( nEntryNo,
274                     nTab ), pViewData->GetPPTY() );
275 }
276 
277 String ScRowBar::GetEntryText( SCCOLROW nEntryNo )
278 {
279 	return String::CreateFromInt32( nEntryNo + 1 );
280 }
281 
282 void ScRowBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
283 {
284 	sal_uInt16 nSizeTwips;
285 	ScSizeMode eMode = SC_SIZE_DIRECT;
286 	if (nNewSize>0 && nNewSize<10) nNewSize=10;				// (Pixel)
287 
288 	if ( nNewSize == HDR_SIZE_OPTIMUM )
289 	{
290 		nSizeTwips = 0;
291 		eMode = SC_SIZE_OPTIMAL;
292 	}
293 	else
294 		nSizeTwips = (sal_uInt16) ( nNewSize / pViewData->GetPPTY() );
295 
296 	ScMarkData& rMark = pViewData->GetMarkData();
297 //	SCTAB nTab = pViewData->GetTabNo();
298 
299 	SCCOLROW* pRanges = new SCCOLROW[MAXROW+1];
300 	SCROW nRangeCnt = 0;
301 	if ( rMark.IsRowMarked( nPos ) )
302 	{
303 		SCROW nStart = 0;
304 		while (nStart<=MAXROW)
305 		{
306 			while (nStart<MAXROW && !rMark.IsRowMarked(nStart))
307 				++nStart;
308 			if (rMark.IsRowMarked(nStart))
309 			{
310 				SCROW nEnd = nStart;
311 				while (nEnd<MAXROW && rMark.IsRowMarked(nEnd))
312 					++nEnd;
313 				if (!rMark.IsRowMarked(nEnd))
314 					--nEnd;
315 				pRanges[static_cast<size_t>(2*nRangeCnt)  ] = nStart;
316 				pRanges[static_cast<size_t>(2*nRangeCnt+1)] = nEnd;
317 				++nRangeCnt;
318 				nStart = nEnd+1;
319 			}
320 			else
321 				nStart = MAXROW+1;
322 		}
323 	}
324 	else
325 	{
326 		pRanges[0] = nPos;
327 		pRanges[1] = nPos;
328 		nRangeCnt = 1;
329 	}
330 
331 	pViewData->GetView()->SetWidthOrHeight( sal_False, nRangeCnt, pRanges, eMode, nSizeTwips );
332 	delete[] pRanges;
333 }
334 
335 void ScRowBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
336 {
337 	SCCOLROW nRange[2];
338 	nRange[0] = nStart;
339 	nRange[1] = nEnd;
340 	pViewData->GetView()->SetWidthOrHeight( sal_False, 1, nRange, SC_SIZE_DIRECT, 0 );
341 }
342 
343 void ScRowBar::SetMarking( sal_Bool bSet )
344 {
345 	pViewData->GetMarkData().SetMarking( bSet );
346 	if (!bSet)
347 	{
348 		pViewData->GetView()->UpdateAutoFillMark();
349 	}
350 }
351 
352 void ScRowBar::SelectWindow()
353 {
354 	ScTabViewShell* pViewSh = pViewData->GetViewShell();
355 
356 	pViewSh->SetActive();			// Appear und SetViewFrame
357 	pViewSh->DrawDeselectAll();
358 
359 	ScSplitPos eActive = pViewData->GetActivePart();
360 	if (eWhich==SC_SPLIT_TOP)
361 	{
362 		if (eActive==SC_SPLIT_BOTTOMLEFT)	eActive=SC_SPLIT_TOPLEFT;
363 		if (eActive==SC_SPLIT_BOTTOMRIGHT)	eActive=SC_SPLIT_TOPRIGHT;
364 	}
365 	else
366 	{
367 		if (eActive==SC_SPLIT_TOPLEFT)		eActive=SC_SPLIT_BOTTOMLEFT;
368 		if (eActive==SC_SPLIT_TOPRIGHT)		eActive=SC_SPLIT_BOTTOMRIGHT;
369 	}
370 	pViewSh->ActivatePart( eActive );
371 
372 	pFuncSet->SetColumn( sal_False );
373 	pFuncSet->SetWhich( eActive );
374 
375 	pViewSh->ActiveGrabFocus();
376 }
377 
378 sal_Bool ScRowBar::IsDisabled()
379 {
380 	ScModule* pScMod = SC_MOD();
381 	return pScMod->IsFormulaMode() || pScMod->IsModalMode();
382 }
383 
384 sal_Bool ScRowBar::ResizeAllowed()
385 {
386 	return !pViewData->HasEditView( pViewData->GetActivePart() ) &&
387 			!pViewData->GetDocShell()->IsReadOnly();
388 }
389 
390 void ScRowBar::DrawInvert( long nDragPosP )
391 {
392 	Rectangle aRect( 0,nDragPosP, GetOutputSizePixel().Width()-1,nDragPosP+HDR_SLIDERSIZE-1 );
393 	Update();
394 	Invert(aRect);
395 
396 	pViewData->GetView()->InvertHorizontal(eWhich,nDragPosP);
397 }
398 
399 String ScRowBar::GetDragHelp( long nVal )
400 {
401 	long nTwips = (long) ( nVal / pViewData->GetPPTY() );
402 	return lcl_MetricString( nTwips, ScGlobal::GetRscString(STR_TIP_HEIGHT) );
403 }
404 
405 //	GetHiddenCount ist nur fuer Zeilen ueberladen
406 
407 SCROW ScRowBar::GetHiddenCount( SCROW nEntryNo )
408 {
409 	ScDocument* pDoc = pViewData->GetDocument();
410 	SCTAB nTab = pViewData->GetTabNo();
411 	return pDoc->GetHiddenRowCount( nEntryNo, nTab );
412 }
413 
414 sal_Bool ScRowBar::IsMirrored()			// overloaded only for rows
415 {
416 	return pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
417 }
418 
419 
420