merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / view / colrowba.cxx
blobe7613c13f4827e35f1b40ab2409be44a8e1daa3f
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: colrowba.cxx,v $
10 * $Revision: 1.17 $
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"
36 // INCLUDE ---------------------------------------------------------------
38 #include <svx/svdtrans.hxx>
39 #include <unotools/localedatawrapper.hxx>
41 #include "colrowba.hxx"
42 #include "document.hxx"
43 #include "scmod.hxx"
44 #include "tabvwsh.hxx"
45 #include "docsh.hxx"
46 #include "appoptio.hxx"
47 #include "globstr.hrc"
49 // STATIC DATA -----------------------------------------------------------
51 //==================================================================
53 String lcl_MetricString( long nTwips, const String& rText )
55 if ( nTwips <= 0 )
56 return ScGlobal::GetRscString(STR_TIP_HIDE);
57 else
59 FieldUnit eUserMet = SC_MOD()->GetAppOptions().GetAppMetric();
61 sal_Int64 nUserVal = MetricField::ConvertValue( nTwips*100, 1, 2, FUNIT_TWIP, eUserMet );
63 String aStr = rText;
64 aStr += ' ';
65 aStr += ScGlobal::pLocaleData->getNum( nUserVal, 2 );
66 aStr += ' ';
67 aStr += SdrFormatter::GetUnitStr(eUserMet);
69 return aStr;
73 //==================================================================
75 ScColBar::ScColBar( Window* pParent, ScViewData* pData, ScHSplitPos eWhichPos,
76 ScHeaderFunctionSet* pFunc, ScHeaderSelectionEngine* pEng ) :
77 ScHeaderControl( pParent, pEng, MAXCOL+1, HDR_HORIZONTAL ),
78 pViewData( pData ),
79 eWhich( eWhichPos ),
80 pFuncSet( pFunc ),
81 pSelEngine( pEng )
83 Show();
86 ScColBar::~ScColBar()
90 inline BOOL ScColBar::UseNumericHeader() const
92 return pViewData->GetDocument()->GetAddressConvention() == formula::FormulaGrammar::CONV_XL_R1C1;
95 SCCOLROW ScColBar::GetPos()
97 return pViewData->GetPosX(eWhich);
100 USHORT ScColBar::GetEntrySize( SCCOLROW nEntryNo )
102 ScDocument* pDoc = pViewData->GetDocument();
103 SCTAB nTab = pViewData->GetTabNo();
104 SCCOL nLastCol = -1;
105 if (pDoc->ColHidden(static_cast<SCCOL>(nEntryNo), nTab, nLastCol))
106 return 0;
107 else
108 return (USHORT) ScViewData::ToPixel( pDoc->GetColWidth( static_cast<SCCOL>(nEntryNo), nTab ), pViewData->GetPPTX() );
111 String ScColBar::GetEntryText( SCCOLROW nEntryNo )
113 return UseNumericHeader()
114 ? String::CreateFromInt32( nEntryNo + 1 )
115 : ScColToAlpha( static_cast<SCCOL>(nEntryNo) );
118 void ScColBar::SetEntrySize( SCCOLROW nPos, USHORT nNewSize )
120 USHORT nSizeTwips;
121 ScSizeMode eMode = SC_SIZE_DIRECT;
122 if (nNewSize>0 && nNewSize<10) nNewSize=10; // (Pixel)
124 if ( nNewSize == HDR_SIZE_OPTIMUM )
126 nSizeTwips = STD_EXTRA_WIDTH;
127 eMode = SC_SIZE_OPTIMAL;
129 else
130 nSizeTwips = (USHORT) ( nNewSize / pViewData->GetPPTX() );
132 ScMarkData& rMark = pViewData->GetMarkData();
133 // SCTAB nTab = pViewData->GetTabNo();
135 SCCOLROW* pRanges = new SCCOLROW[MAXCOL+1];
136 SCCOL nRangeCnt = 0;
137 if ( rMark.IsColumnMarked( static_cast<SCCOL>(nPos) ) )
139 SCCOL nStart = 0;
140 while (nStart<=MAXCOL)
142 while (nStart<MAXCOL && !rMark.IsColumnMarked(nStart))
143 ++nStart;
144 if (rMark.IsColumnMarked(nStart))
146 SCCOL nEnd = nStart;
147 while (nEnd<MAXCOL && rMark.IsColumnMarked(nEnd))
148 ++nEnd;
149 if (!rMark.IsColumnMarked(nEnd))
150 --nEnd;
151 pRanges[static_cast<size_t>(2*nRangeCnt) ] = nStart;
152 pRanges[static_cast<size_t>(2*nRangeCnt+1)] = nEnd;
153 ++nRangeCnt;
154 nStart = nEnd+1;
156 else
157 nStart = MAXCOL+1;
160 else
162 pRanges[0] = nPos;
163 pRanges[1] = nPos;
164 nRangeCnt = 1;
167 pViewData->GetView()->SetWidthOrHeight( TRUE, nRangeCnt, pRanges, eMode, nSizeTwips );
168 delete[] pRanges;
171 void ScColBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
173 SCCOLROW nRange[2];
174 nRange[0] = nStart;
175 nRange[1] = nEnd;
176 pViewData->GetView()->SetWidthOrHeight( TRUE, 1, nRange, SC_SIZE_DIRECT, 0 );
179 void ScColBar::SetMarking( BOOL bSet )
181 pViewData->GetMarkData().SetMarking( bSet );
182 if (!bSet)
184 pViewData->GetView()->UpdateAutoFillMark();
188 void ScColBar::SelectWindow()
190 ScTabViewShell* pViewSh = pViewData->GetViewShell();
192 pViewSh->SetActive(); // Appear und SetViewFrame
193 pViewSh->DrawDeselectAll();
195 ScSplitPos eActive = pViewData->GetActivePart();
196 if (eWhich==SC_SPLIT_LEFT)
198 if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_TOPLEFT;
199 if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_BOTTOMLEFT;
201 else
203 if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_TOPRIGHT;
204 if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_BOTTOMRIGHT;
206 pViewSh->ActivatePart( eActive );
208 pFuncSet->SetColumn( TRUE );
209 pFuncSet->SetWhich( eActive );
211 pViewSh->ActiveGrabFocus();
214 BOOL ScColBar::IsDisabled()
216 ScModule* pScMod = SC_MOD();
217 return pScMod->IsFormulaMode() || pScMod->IsModalMode();
220 BOOL ScColBar::ResizeAllowed()
222 return !pViewData->HasEditView( pViewData->GetActivePart() );
225 void ScColBar::DrawInvert( long nDragPosP )
227 Rectangle aRect( nDragPosP,0, nDragPosP+HDR_SLIDERSIZE-1,GetOutputSizePixel().Width()-1 );
228 Update();
229 Invert(aRect);
231 pViewData->GetView()->InvertVertical(eWhich,nDragPosP);
234 String ScColBar::GetDragHelp( long nVal )
236 long nTwips = (long) ( nVal / pViewData->GetPPTX() );
237 return lcl_MetricString( nTwips, ScGlobal::GetRscString(STR_TIP_WIDTH) );
240 BOOL ScColBar::IsLayoutRTL() // overloaded only for columns
242 return pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
245 //==================================================================
247 ScRowBar::ScRowBar( Window* pParent, ScViewData* pData, ScVSplitPos eWhichPos,
248 ScHeaderFunctionSet* pFunc, ScHeaderSelectionEngine* pEng ) :
249 ScHeaderControl( pParent, pEng, MAXROW+1, HDR_VERTICAL ),
250 pViewData( pData ),
251 eWhich( eWhichPos ),
252 pFuncSet( pFunc ),
253 pSelEngine( pEng )
255 Show();
258 ScRowBar::~ScRowBar()
262 SCCOLROW ScRowBar::GetPos()
264 return pViewData->GetPosY(eWhich);
267 USHORT ScRowBar::GetEntrySize( SCCOLROW nEntryNo )
269 ScDocument* pDoc = pViewData->GetDocument();
270 SCTAB nTab = pViewData->GetTabNo();
271 SCROW nLastRow = -1;
272 if (pDoc->RowHidden(nEntryNo, nTab, nLastRow))
273 return 0;
274 else
275 return (USHORT) ScViewData::ToPixel( pDoc->GetOriginalHeight( nEntryNo,
276 nTab ), pViewData->GetPPTY() );
279 String ScRowBar::GetEntryText( SCCOLROW nEntryNo )
281 return String::CreateFromInt32( nEntryNo + 1 );
284 void ScRowBar::SetEntrySize( SCCOLROW nPos, USHORT nNewSize )
286 USHORT nSizeTwips;
287 ScSizeMode eMode = SC_SIZE_DIRECT;
288 if (nNewSize>0 && nNewSize<10) nNewSize=10; // (Pixel)
290 if ( nNewSize == HDR_SIZE_OPTIMUM )
292 nSizeTwips = 0;
293 eMode = SC_SIZE_OPTIMAL;
295 else
296 nSizeTwips = (USHORT) ( nNewSize / pViewData->GetPPTY() );
298 ScMarkData& rMark = pViewData->GetMarkData();
299 // SCTAB nTab = pViewData->GetTabNo();
301 SCCOLROW* pRanges = new SCCOLROW[MAXROW+1];
302 SCROW nRangeCnt = 0;
303 if ( rMark.IsRowMarked( nPos ) )
305 SCROW nStart = 0;
306 while (nStart<=MAXROW)
308 while (nStart<MAXROW && !rMark.IsRowMarked(nStart))
309 ++nStart;
310 if (rMark.IsRowMarked(nStart))
312 SCROW nEnd = nStart;
313 while (nEnd<MAXROW && rMark.IsRowMarked(nEnd))
314 ++nEnd;
315 if (!rMark.IsRowMarked(nEnd))
316 --nEnd;
317 pRanges[static_cast<size_t>(2*nRangeCnt) ] = nStart;
318 pRanges[static_cast<size_t>(2*nRangeCnt+1)] = nEnd;
319 ++nRangeCnt;
320 nStart = nEnd+1;
322 else
323 nStart = MAXROW+1;
326 else
328 pRanges[0] = nPos;
329 pRanges[1] = nPos;
330 nRangeCnt = 1;
333 pViewData->GetView()->SetWidthOrHeight( FALSE, nRangeCnt, pRanges, eMode, nSizeTwips );
334 delete[] pRanges;
337 void ScRowBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
339 SCCOLROW nRange[2];
340 nRange[0] = nStart;
341 nRange[1] = nEnd;
342 pViewData->GetView()->SetWidthOrHeight( FALSE, 1, nRange, SC_SIZE_DIRECT, 0 );
345 void ScRowBar::SetMarking( BOOL bSet )
347 pViewData->GetMarkData().SetMarking( bSet );
348 if (!bSet)
350 pViewData->GetView()->UpdateAutoFillMark();
354 void ScRowBar::SelectWindow()
356 ScTabViewShell* pViewSh = pViewData->GetViewShell();
358 pViewSh->SetActive(); // Appear und SetViewFrame
359 pViewSh->DrawDeselectAll();
361 ScSplitPos eActive = pViewData->GetActivePart();
362 if (eWhich==SC_SPLIT_TOP)
364 if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_TOPLEFT;
365 if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_TOPRIGHT;
367 else
369 if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_BOTTOMLEFT;
370 if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_BOTTOMRIGHT;
372 pViewSh->ActivatePart( eActive );
374 pFuncSet->SetColumn( FALSE );
375 pFuncSet->SetWhich( eActive );
377 pViewSh->ActiveGrabFocus();
380 BOOL ScRowBar::IsDisabled()
382 ScModule* pScMod = SC_MOD();
383 return pScMod->IsFormulaMode() || pScMod->IsModalMode();
386 BOOL ScRowBar::ResizeAllowed()
388 return !pViewData->HasEditView( pViewData->GetActivePart() );
391 void ScRowBar::DrawInvert( long nDragPosP )
393 Rectangle aRect( 0,nDragPosP, GetOutputSizePixel().Width()-1,nDragPosP+HDR_SLIDERSIZE-1 );
394 Update();
395 Invert(aRect);
397 pViewData->GetView()->InvertHorizontal(eWhich,nDragPosP);
400 String ScRowBar::GetDragHelp( long nVal )
402 long nTwips = (long) ( nVal / pViewData->GetPPTY() );
403 return lcl_MetricString( nTwips, ScGlobal::GetRscString(STR_TIP_HEIGHT) );
406 // GetHiddenCount ist nur fuer Zeilen ueberladen
408 SCROW ScRowBar::GetHiddenCount( SCROW nEntryNo )
410 ScDocument* pDoc = pViewData->GetDocument();
411 SCTAB nTab = pViewData->GetTabNo();
412 return pDoc->GetHiddenRowCount( nEntryNo, nTab );
415 BOOL ScRowBar::IsMirrored() // overloaded only for rows
417 return pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );