1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/svdtrans.hxx>
21 #include <unotools/localedatawrapper.hxx>
23 #include "colrowba.hxx"
24 #include "document.hxx"
26 #include "tabvwsh.hxx"
28 #include "appoptio.hxx"
29 #include "globstr.hrc"
30 #include "markdata.hxx"
32 // STATIC DATA -----------------------------------------------------------
34 //==================================================================
36 static String
lcl_MetricString( long nTwips
, const String
& rText
)
39 return ScGlobal::GetRscString(STR_TIP_HIDE
);
42 FieldUnit eUserMet
= SC_MOD()->GetAppOptions().GetAppMetric();
44 sal_Int64 nUserVal
= MetricField::ConvertValue( nTwips
*100, 1, 2, FUNIT_TWIP
, eUserMet
);
48 aStr
+= ScGlobal::pLocaleData
->getNum( nUserVal
, 2 );
50 aStr
+= SdrFormatter::GetUnitStr(eUserMet
);
56 //==================================================================
58 ScColBar::ScColBar( Window
* pParent
, ScViewData
* pData
, ScHSplitPos eWhichPos
,
59 ScHeaderFunctionSet
* pFunc
, ScHeaderSelectionEngine
* pEng
) :
60 ScHeaderControl( pParent
, pEng
, MAXCOL
+1, false ),
72 inline sal_Bool
ScColBar::UseNumericHeader() const
74 return pViewData
->GetDocument()->GetAddressConvention() == formula::FormulaGrammar::CONV_XL_R1C1
;
77 SCCOLROW
ScColBar::GetPos()
79 return pViewData
->GetPosX(eWhich
);
82 sal_uInt16
ScColBar::GetEntrySize( SCCOLROW nEntryNo
)
84 ScDocument
* pDoc
= pViewData
->GetDocument();
85 SCTAB nTab
= pViewData
->GetTabNo();
86 if (pDoc
->ColHidden(static_cast<SCCOL
>(nEntryNo
), nTab
))
89 return (sal_uInt16
) ScViewData::ToPixel( pDoc
->GetColWidth( static_cast<SCCOL
>(nEntryNo
), nTab
), pViewData
->GetPPTX() );
92 String
ScColBar::GetEntryText( SCCOLROW nEntryNo
)
94 return UseNumericHeader()
95 ? String::CreateFromInt32( nEntryNo
+ 1 )
96 : ScColToAlpha( static_cast<SCCOL
>(nEntryNo
) );
99 void ScColBar::SetEntrySize( SCCOLROW nPos
, sal_uInt16 nNewSize
)
101 sal_uInt16 nSizeTwips
;
102 ScSizeMode eMode
= SC_SIZE_DIRECT
;
103 if (nNewSize
>0 && nNewSize
<10) nNewSize
=10; // (Pixel)
105 if ( nNewSize
== HDR_SIZE_OPTIMUM
)
107 nSizeTwips
= STD_EXTRA_WIDTH
;
108 eMode
= SC_SIZE_OPTIMAL
;
111 nSizeTwips
= (sal_uInt16
) ( nNewSize
/ pViewData
->GetPPTX() );
113 ScMarkData
& rMark
= pViewData
->GetMarkData();
115 SCCOLROW
* pRanges
= new SCCOLROW
[MAXCOL
+1];
117 if ( rMark
.IsColumnMarked( static_cast<SCCOL
>(nPos
) ) )
120 while (nStart
<=MAXCOL
)
122 while (nStart
<MAXCOL
&& !rMark
.IsColumnMarked(nStart
))
124 if (rMark
.IsColumnMarked(nStart
))
127 while (nEnd
<MAXCOL
&& rMark
.IsColumnMarked(nEnd
))
129 if (!rMark
.IsColumnMarked(nEnd
))
131 pRanges
[static_cast<size_t>(2*nRangeCnt
) ] = nStart
;
132 pRanges
[static_cast<size_t>(2*nRangeCnt
+1)] = nEnd
;
147 pViewData
->GetView()->SetWidthOrHeight( sal_True
, nRangeCnt
, pRanges
, eMode
, nSizeTwips
);
151 void ScColBar::HideEntries( SCCOLROW nStart
, SCCOLROW nEnd
)
156 pViewData
->GetView()->SetWidthOrHeight( sal_True
, 1, nRange
, SC_SIZE_DIRECT
, 0 );
159 void ScColBar::SetMarking( sal_Bool bSet
)
161 pViewData
->GetMarkData().SetMarking( bSet
);
164 pViewData
->GetView()->UpdateAutoFillMark();
168 void ScColBar::SelectWindow()
170 ScTabViewShell
* pViewSh
= pViewData
->GetViewShell();
172 pViewSh
->SetActive(); // Appear and SetViewFrame
173 pViewSh
->DrawDeselectAll();
175 ScSplitPos eActive
= pViewData
->GetActivePart();
176 if (eWhich
==SC_SPLIT_LEFT
)
178 if (eActive
==SC_SPLIT_TOPRIGHT
) eActive
=SC_SPLIT_TOPLEFT
;
179 if (eActive
==SC_SPLIT_BOTTOMRIGHT
) eActive
=SC_SPLIT_BOTTOMLEFT
;
183 if (eActive
==SC_SPLIT_TOPLEFT
) eActive
=SC_SPLIT_TOPRIGHT
;
184 if (eActive
==SC_SPLIT_BOTTOMLEFT
) eActive
=SC_SPLIT_BOTTOMRIGHT
;
186 pViewSh
->ActivatePart( eActive
);
188 pFuncSet
->SetColumn( sal_True
);
189 pFuncSet
->SetWhich( eActive
);
191 pViewSh
->ActiveGrabFocus();
194 sal_Bool
ScColBar::IsDisabled()
196 ScModule
* pScMod
= SC_MOD();
197 return pScMod
->IsFormulaMode() || pScMod
->IsModalMode();
200 sal_Bool
ScColBar::ResizeAllowed()
202 return !pViewData
->HasEditView( pViewData
->GetActivePart() );
205 void ScColBar::DrawInvert( long nDragPosP
)
207 Rectangle
aRect( nDragPosP
,0, nDragPosP
+HDR_SLIDERSIZE
-1,GetOutputSizePixel().Width()-1 );
211 pViewData
->GetView()->InvertVertical(eWhich
,nDragPosP
);
214 String
ScColBar::GetDragHelp( long nVal
)
216 long nTwips
= (long) ( nVal
/ pViewData
->GetPPTX() );
217 return lcl_MetricString( nTwips
, ScGlobal::GetRscString(STR_TIP_WIDTH
) );
220 sal_Bool
ScColBar::IsLayoutRTL() // overloaded only for columns
222 return pViewData
->GetDocument()->IsLayoutRTL( pViewData
->GetTabNo() );
225 //==================================================================
227 ScRowBar::ScRowBar( Window
* pParent
, ScViewData
* pData
, ScVSplitPos eWhichPos
,
228 ScHeaderFunctionSet
* pFunc
, ScHeaderSelectionEngine
* pEng
) :
229 ScHeaderControl( pParent
, pEng
, MAXROW
+1, true ),
237 ScRowBar::~ScRowBar()
241 SCCOLROW
ScRowBar::GetPos()
243 return pViewData
->GetPosY(eWhich
);
246 sal_uInt16
ScRowBar::GetEntrySize( SCCOLROW nEntryNo
)
248 ScDocument
* pDoc
= pViewData
->GetDocument();
249 SCTAB nTab
= pViewData
->GetTabNo();
251 if (pDoc
->RowHidden(nEntryNo
, nTab
, NULL
, &nLastRow
))
254 return (sal_uInt16
) ScViewData::ToPixel( pDoc
->GetOriginalHeight( nEntryNo
,
255 nTab
), pViewData
->GetPPTY() );
258 String
ScRowBar::GetEntryText( SCCOLROW nEntryNo
)
260 return String::CreateFromInt32( nEntryNo
+ 1 );
263 void ScRowBar::SetEntrySize( SCCOLROW nPos
, sal_uInt16 nNewSize
)
265 sal_uInt16 nSizeTwips
;
266 ScSizeMode eMode
= SC_SIZE_DIRECT
;
267 if (nNewSize
>0 && nNewSize
<10) nNewSize
=10; // (Pixel)
269 if ( nNewSize
== HDR_SIZE_OPTIMUM
)
272 eMode
= SC_SIZE_OPTIMAL
;
275 nSizeTwips
= (sal_uInt16
) ( nNewSize
/ pViewData
->GetPPTY() );
277 ScMarkData
& rMark
= pViewData
->GetMarkData();
279 SCCOLROW
* pRanges
= new SCCOLROW
[MAXROW
+1];
281 if ( rMark
.IsRowMarked( nPos
) )
284 while (nStart
<=MAXROW
)
286 while (nStart
<MAXROW
&& !rMark
.IsRowMarked(nStart
))
288 if (rMark
.IsRowMarked(nStart
))
291 while (nEnd
<MAXROW
&& rMark
.IsRowMarked(nEnd
))
293 if (!rMark
.IsRowMarked(nEnd
))
295 pRanges
[static_cast<size_t>(2*nRangeCnt
) ] = nStart
;
296 pRanges
[static_cast<size_t>(2*nRangeCnt
+1)] = nEnd
;
311 pViewData
->GetView()->SetWidthOrHeight( false, nRangeCnt
, pRanges
, eMode
, nSizeTwips
);
315 void ScRowBar::HideEntries( SCCOLROW nStart
, SCCOLROW nEnd
)
320 pViewData
->GetView()->SetWidthOrHeight( false, 1, nRange
, SC_SIZE_DIRECT
, 0 );
323 void ScRowBar::SetMarking( sal_Bool bSet
)
325 pViewData
->GetMarkData().SetMarking( bSet
);
328 pViewData
->GetView()->UpdateAutoFillMark();
332 void ScRowBar::SelectWindow()
334 ScTabViewShell
* pViewSh
= pViewData
->GetViewShell();
336 pViewSh
->SetActive(); // Appear and SetViewFrame
337 pViewSh
->DrawDeselectAll();
339 ScSplitPos eActive
= pViewData
->GetActivePart();
340 if (eWhich
==SC_SPLIT_TOP
)
342 if (eActive
==SC_SPLIT_BOTTOMLEFT
) eActive
=SC_SPLIT_TOPLEFT
;
343 if (eActive
==SC_SPLIT_BOTTOMRIGHT
) eActive
=SC_SPLIT_TOPRIGHT
;
347 if (eActive
==SC_SPLIT_TOPLEFT
) eActive
=SC_SPLIT_BOTTOMLEFT
;
348 if (eActive
==SC_SPLIT_TOPRIGHT
) eActive
=SC_SPLIT_BOTTOMRIGHT
;
350 pViewSh
->ActivatePart( eActive
);
352 pFuncSet
->SetColumn( false );
353 pFuncSet
->SetWhich( eActive
);
355 pViewSh
->ActiveGrabFocus();
358 sal_Bool
ScRowBar::IsDisabled()
360 ScModule
* pScMod
= SC_MOD();
361 return pScMod
->IsFormulaMode() || pScMod
->IsModalMode();
364 sal_Bool
ScRowBar::ResizeAllowed()
366 return !pViewData
->HasEditView( pViewData
->GetActivePart() );
369 void ScRowBar::DrawInvert( long nDragPosP
)
371 Rectangle
aRect( 0,nDragPosP
, GetOutputSizePixel().Width()-1,nDragPosP
+HDR_SLIDERSIZE
-1 );
375 pViewData
->GetView()->InvertHorizontal(eWhich
,nDragPosP
);
378 String
ScRowBar::GetDragHelp( long nVal
)
380 long nTwips
= (long) ( nVal
/ pViewData
->GetPPTY() );
381 return lcl_MetricString( nTwips
, ScGlobal::GetRscString(STR_TIP_HEIGHT
) );
384 SCROW
ScRowBar::GetHiddenCount( SCROW nEntryNo
) // overloaded only for rows
386 ScDocument
* pDoc
= pViewData
->GetDocument();
387 SCTAB nTab
= pViewData
->GetTabNo();
388 return pDoc
->GetHiddenRowCount( nEntryNo
, nTab
);
391 sal_Bool
ScRowBar::IsMirrored() // overloaded only for rows
393 return pViewData
->GetDocument()->IsLayoutRTL( pViewData
->GetTabNo() );
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */