1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: colrowba.cxx,v $
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"
44 #include "tabvwsh.hxx"
46 #include "appoptio.hxx"
47 #include "globstr.hrc"
49 // STATIC DATA -----------------------------------------------------------
51 //==================================================================
53 String
lcl_MetricString( long nTwips
, const String
& rText
)
56 return ScGlobal::GetRscString(STR_TIP_HIDE
);
59 FieldUnit eUserMet
= SC_MOD()->GetAppOptions().GetAppMetric();
61 sal_Int64 nUserVal
= MetricField::ConvertValue( nTwips
*100, 1, 2, FUNIT_TWIP
, eUserMet
);
65 aStr
+= ScGlobal::pLocaleData
->getNum( nUserVal
, 2 );
67 aStr
+= SdrFormatter::GetUnitStr(eUserMet
);
73 //==================================================================
75 ScColBar::ScColBar( Window
* pParent
, ScViewData
* pData
, ScHSplitPos eWhichPos
,
76 ScHeaderFunctionSet
* pFunc
, ScHeaderSelectionEngine
* pEng
) :
77 ScHeaderControl( pParent
, pEng
, MAXCOL
+1, HDR_HORIZONTAL
),
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();
105 if (pDoc
->ColHidden(static_cast<SCCOL
>(nEntryNo
), nTab
, nLastCol
))
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
)
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
;
130 nSizeTwips
= (USHORT
) ( nNewSize
/ pViewData
->GetPPTX() );
132 ScMarkData
& rMark
= pViewData
->GetMarkData();
133 // SCTAB nTab = pViewData->GetTabNo();
135 SCCOLROW
* pRanges
= new SCCOLROW
[MAXCOL
+1];
137 if ( rMark
.IsColumnMarked( static_cast<SCCOL
>(nPos
) ) )
140 while (nStart
<=MAXCOL
)
142 while (nStart
<MAXCOL
&& !rMark
.IsColumnMarked(nStart
))
144 if (rMark
.IsColumnMarked(nStart
))
147 while (nEnd
<MAXCOL
&& rMark
.IsColumnMarked(nEnd
))
149 if (!rMark
.IsColumnMarked(nEnd
))
151 pRanges
[static_cast<size_t>(2*nRangeCnt
) ] = nStart
;
152 pRanges
[static_cast<size_t>(2*nRangeCnt
+1)] = nEnd
;
167 pViewData
->GetView()->SetWidthOrHeight( TRUE
, nRangeCnt
, pRanges
, eMode
, nSizeTwips
);
171 void ScColBar::HideEntries( SCCOLROW nStart
, SCCOLROW nEnd
)
176 pViewData
->GetView()->SetWidthOrHeight( TRUE
, 1, nRange
, SC_SIZE_DIRECT
, 0 );
179 void ScColBar::SetMarking( BOOL bSet
)
181 pViewData
->GetMarkData().SetMarking( 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
;
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 );
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
),
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();
272 if (pDoc
->RowHidden(nEntryNo
, nTab
, nLastRow
))
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
)
287 ScSizeMode eMode
= SC_SIZE_DIRECT
;
288 if (nNewSize
>0 && nNewSize
<10) nNewSize
=10; // (Pixel)
290 if ( nNewSize
== HDR_SIZE_OPTIMUM
)
293 eMode
= SC_SIZE_OPTIMAL
;
296 nSizeTwips
= (USHORT
) ( nNewSize
/ pViewData
->GetPPTY() );
298 ScMarkData
& rMark
= pViewData
->GetMarkData();
299 // SCTAB nTab = pViewData->GetTabNo();
301 SCCOLROW
* pRanges
= new SCCOLROW
[MAXROW
+1];
303 if ( rMark
.IsRowMarked( nPos
) )
306 while (nStart
<=MAXROW
)
308 while (nStart
<MAXROW
&& !rMark
.IsRowMarked(nStart
))
310 if (rMark
.IsRowMarked(nStart
))
313 while (nEnd
<MAXROW
&& rMark
.IsRowMarked(nEnd
))
315 if (!rMark
.IsRowMarked(nEnd
))
317 pRanges
[static_cast<size_t>(2*nRangeCnt
) ] = nStart
;
318 pRanges
[static_cast<size_t>(2*nRangeCnt
+1)] = nEnd
;
333 pViewData
->GetView()->SetWidthOrHeight( FALSE
, nRangeCnt
, pRanges
, eMode
, nSizeTwips
);
337 void ScRowBar::HideEntries( SCCOLROW nStart
, SCCOLROW nEnd
)
342 pViewData
->GetView()->SetWidthOrHeight( FALSE
, 1, nRange
, SC_SIZE_DIRECT
, 0 );
345 void ScRowBar::SetMarking( BOOL bSet
)
347 pViewData
->GetMarkData().SetMarking( 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
;
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 );
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() );