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