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 <vcl/svapp.hxx>
21 #include <vcl/taskpanelist.hxx>
22 #include <vcl/settings.hxx>
24 #include <olinewin.hxx>
25 #include <olinetab.hxx>
26 #include <document.hxx>
28 #include <strings.hrc>
29 #include <scresid.hxx>
30 #include <bitmaps.hlst>
32 const long SC_OL_BITMAPSIZE
= 12;
33 const long SC_OL_POSOFFSET
= 2;
35 const size_t SC_OL_NOLEVEL
= static_cast< size_t >( -1 );
36 const size_t SC_OL_HEADERENTRY
= static_cast< size_t >( -1 );
38 ScOutlineWindow::ScOutlineWindow( vcl::Window
* pParent
, ScOutlineMode eMode
, ScViewData
* pViewData
, ScSplitPos eWhich
) :
40 mrViewData( *pViewData
),
42 mbHoriz( eMode
== SC_OUTLINE_HOR
),
43 mbMirrorEntries( false ), // updated in SetHeaderSize
44 mbMirrorLevels( false ), // updated in SetHeaderSize
45 maLineColor( COL_BLACK
),
53 mnFocusEntry( SC_OL_HEADERENTRY
),
54 mbDontDrawFocus( false )
56 EnableRTL( false ); // mirroring is done manually
59 maFocusRect
.SetEmpty();
62 // insert the window into task pane list for "F6 cycling"
63 if( SystemWindow
* pSysWin
= GetSystemWindow() )
64 if( TaskPaneList
* pTaskPaneList
= pSysWin
->GetTaskPaneList() )
65 pTaskPaneList
->AddWindow( this );
68 ScOutlineWindow::~ScOutlineWindow()
73 void ScOutlineWindow::dispose()
75 // remove the window from task pane list
76 if( SystemWindow
* pSysWin
= GetSystemWindow() )
77 if( TaskPaneList
* pTaskPaneList
= pSysWin
->GetTaskPaneList() )
78 pTaskPaneList
->RemoveWindow( this );
79 vcl::Window::dispose();
82 void ScOutlineWindow::SetHeaderSize( long nNewSize
)
84 bool bLayoutRTL
= GetDoc().IsLayoutRTL( GetTab() );
85 mbMirrorEntries
= bLayoutRTL
&& mbHoriz
;
86 mbMirrorLevels
= bLayoutRTL
&& !mbHoriz
;
88 bool bNew
= (nNewSize
!= mnHeaderSize
);
89 mnHeaderSize
= nNewSize
;
90 mnHeaderPos
= mbMirrorEntries
? (GetOutputSizeEntry() - mnHeaderSize
) : 0;
91 mnMainFirstPos
= mbMirrorEntries
? 0 : mnHeaderSize
;
92 mnMainLastPos
= GetOutputSizeEntry() - (mbMirrorEntries
? mnHeaderSize
: 0) - 1;
97 long ScOutlineWindow::GetDepthSize() const
99 long nSize
= GetLevelCount() * SC_OL_BITMAPSIZE
;
101 nSize
+= 2 * SC_OL_POSOFFSET
+ 1;
105 void ScOutlineWindow::ScrollPixel( long nDiff
)
108 mbDontDrawFocus
= true;
110 long nStart
= mnMainFirstPos
;
111 long nEnd
= mnMainLastPos
;
113 long nInvStart
, nInvEnd
;
117 nInvStart
= nEnd
+ nDiff
;
124 nInvEnd
= nStart
+ nDiff
;
127 ScrollRel( nDiff
, nStart
, nEnd
);
128 Invalidate( GetRectangle( 0, nInvStart
, GetOutputSizeLevel() - 1, nInvEnd
) );
131 // if focus becomes invisible, move it to next visible button
132 ImplMoveFocusToVisible( nDiff
< 0 );
134 mbDontDrawFocus
= false;
138 void ScOutlineWindow::ScrollRel( long nEntryDiff
, long nEntryStart
, long nEntryEnd
)
140 tools::Rectangle
aRect( GetRectangle( 0, nEntryStart
, GetOutputSizeLevel() - 1, nEntryEnd
) );
142 Scroll( nEntryDiff
, 0, aRect
);
144 Scroll( 0, nEntryDiff
, aRect
);
147 // internal -------------------------------------------------------------------
149 void ScOutlineWindow::InitSettings()
151 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
152 SetBackground( rStyleSettings
.GetFaceColor() );
153 maLineColor
= rStyleSettings
.GetButtonTextColor();
157 const ScOutlineArray
* ScOutlineWindow::GetOutlineArray() const
159 const ScOutlineTable
* pTable
= GetDoc().GetOutlineTable( GetTab() );
160 if ( !pTable
) return nullptr;
161 return mbHoriz
? &pTable
->GetColArray() : &pTable
->GetRowArray();
164 const ScOutlineEntry
* ScOutlineWindow::GetOutlineEntry( size_t nLevel
, size_t nEntry
) const
166 const ScOutlineArray
* pArray
= GetOutlineArray();
167 return pArray
? pArray
->GetEntry( sal::static_int_cast
<sal_uInt16
>(nLevel
), sal::static_int_cast
<sal_uInt16
>(nEntry
) ) : nullptr;
170 bool ScOutlineWindow::IsHidden( SCCOLROW nColRowIndex
) const
173 GetDoc().ColHidden(static_cast<SCCOL
>(nColRowIndex
), GetTab()) :
174 GetDoc().RowHidden(static_cast<SCROW
>(nColRowIndex
), GetTab());
177 bool ScOutlineWindow::IsFiltered( SCCOLROW nColRowIndex
) const
179 // columns cannot be filtered
180 return !mbHoriz
&& GetDoc().RowFiltered( static_cast<SCROW
>(nColRowIndex
), GetTab() );
183 bool ScOutlineWindow::IsFirstVisible( SCCOLROW nColRowIndex
) const
185 bool bAllHidden
= true;
186 for ( SCCOLROW nPos
= 0; (nPos
< nColRowIndex
) && bAllHidden
; ++nPos
)
187 bAllHidden
= IsHidden( nPos
);
191 void ScOutlineWindow::GetVisibleRange( SCCOLROW
& rnColRowStart
, SCCOLROW
& rnColRowEnd
) const
195 rnColRowStart
= mrViewData
.GetPosX( WhichH( meWhich
) );
196 rnColRowEnd
= rnColRowStart
+ mrViewData
.VisibleCellsX( WhichH( meWhich
) );
200 rnColRowStart
= mrViewData
.GetPosY( WhichV( meWhich
) );
201 rnColRowEnd
= rnColRowStart
+ mrViewData
.VisibleCellsY( WhichV( meWhich
) );
204 // include collapsed columns/rows in front of visible range
205 while ( (rnColRowStart
> 0) && IsHidden( rnColRowStart
- 1 ) )
209 Point
ScOutlineWindow::GetPoint( long nLevelPos
, long nEntryPos
) const
211 return mbHoriz
? Point( nEntryPos
, nLevelPos
) : Point( nLevelPos
, nEntryPos
);
214 tools::Rectangle
ScOutlineWindow::GetRectangle(
215 long nLevelStart
, long nEntryStart
, long nLevelEnd
, long nEntryEnd
) const
217 return tools::Rectangle( GetPoint( nLevelStart
, nEntryStart
), GetPoint( nLevelEnd
, nEntryEnd
) );
220 long ScOutlineWindow::GetOutputSizeLevel() const
222 Size
aSize( GetOutputSizePixel() );
223 return mbHoriz
? aSize
.Height() : aSize
.Width();
226 long ScOutlineWindow::GetOutputSizeEntry() const
228 Size
aSize( GetOutputSizePixel() );
229 return mbHoriz
? aSize
.Width() : aSize
.Height();
232 size_t ScOutlineWindow::GetLevelCount() const
234 const ScOutlineArray
* pArray
= GetOutlineArray();
235 size_t nLevelCount
= pArray
? pArray
->GetDepth() : 0;
236 return nLevelCount
? (nLevelCount
+ 1) : 0;
239 long ScOutlineWindow::GetLevelPos( size_t nLevel
) const
241 // #i51970# must always return the *left* edge of the area used by a level
242 long nPos
= static_cast< long >( SC_OL_POSOFFSET
+ nLevel
* SC_OL_BITMAPSIZE
);
243 return mbMirrorLevels
? (GetOutputSizeLevel() - nPos
- SC_OL_BITMAPSIZE
) : nPos
;
246 size_t ScOutlineWindow::GetLevelFromPos( long nLevelPos
) const
248 if( mbMirrorLevels
) nLevelPos
= GetOutputSizeLevel() - nLevelPos
- 1;
249 long nStart
= SC_OL_POSOFFSET
;
250 if ( nLevelPos
< nStart
) return SC_OL_NOLEVEL
;
251 size_t nLevel
= static_cast< size_t >( (nLevelPos
- nStart
) / SC_OL_BITMAPSIZE
);
252 return (nLevel
< GetLevelCount()) ? nLevel
: SC_OL_NOLEVEL
;
255 long ScOutlineWindow::GetColRowPos( SCCOLROW nColRowIndex
) const
257 long nDocPos
= mbHoriz
?
258 mrViewData
.GetScrPos( static_cast<SCCOL
>(nColRowIndex
), 0, meWhich
, true ).X() :
259 mrViewData
.GetScrPos( 0, static_cast<SCROW
>(nColRowIndex
), meWhich
, true ).Y();
260 return mnMainFirstPos
+ nDocPos
;
263 long ScOutlineWindow::GetHeaderEntryPos() const
265 return mnHeaderPos
+ (mnHeaderSize
- SC_OL_BITMAPSIZE
) / 2;
268 bool ScOutlineWindow::GetEntryPos(
269 size_t nLevel
, size_t nEntry
,
270 long& rnStartPos
, long& rnEndPos
, long& rnImagePos
) const
272 const ScOutlineEntry
* pEntry
= GetOutlineEntry( nLevel
, nEntry
);
273 if ( !pEntry
|| !pEntry
->IsVisible() )
276 SCCOLROW nStart
= pEntry
->GetStart();
277 SCCOLROW nEnd
= pEntry
->GetEnd();
279 long nEntriesSign
= mbMirrorEntries
? -1 : 1;
281 // --- common calculation ---
283 rnStartPos
= GetColRowPos( nStart
);
284 rnEndPos
= GetColRowPos( nEnd
+ 1 );
286 bool bHidden
= IsHidden( nStart
);
287 rnImagePos
= bHidden
?
288 (rnStartPos
- ( SC_OL_BITMAPSIZE
/ 2 ) * nEntriesSign
) :
289 rnStartPos
+ nEntriesSign
;
290 long nCenter
= (rnStartPos
+ rnEndPos
- SC_OL_BITMAPSIZE
* nEntriesSign
+
291 ( mbMirrorEntries
? 1 : 0 )) / 2;
292 rnImagePos
= mbMirrorEntries
? std::max( rnImagePos
, nCenter
) : std::min( rnImagePos
, nCenter
);
294 // --- refinements ---
296 // do not cut leftmost/topmost image
297 if ( bHidden
&& IsFirstVisible( nStart
) )
298 rnImagePos
= rnStartPos
;
300 // do not cover previous collapsed image
301 bool bDoNoCover
= !bHidden
&& nEntry
;
302 const ScOutlineEntry
* pPrevEntry
= bDoNoCover
? GetOutlineEntry(nLevel
, nEntry
- 1) : nullptr;
305 SCCOLROW nPrevEnd
= pPrevEntry
->GetEnd();
306 if ( (nPrevEnd
+ 1 == nStart
) && IsHidden( nPrevEnd
) )
308 if ( IsFirstVisible( pPrevEntry
->GetStart() ) )
309 rnStartPos
+= SC_OL_BITMAPSIZE
* nEntriesSign
;
311 rnStartPos
+= ( SC_OL_BITMAPSIZE
/ 2 ) * nEntriesSign
;
312 rnImagePos
= rnStartPos
;
316 // restrict rnStartPos...rnEndPos to valid area
317 rnStartPos
= std::max( rnStartPos
, mnMainFirstPos
);
318 rnEndPos
= std::max( rnEndPos
, mnMainFirstPos
);
320 if ( mbMirrorEntries
)
321 rnImagePos
-= SC_OL_BITMAPSIZE
- 1; // start pos aligns with right edge of bitmap
323 // --- all rows filtered? ---
325 bool bVisible
= true;
329 for ( SCCOLROW nRow
= nStart
; (nRow
<= nEnd
) && !bVisible
; ++nRow
)
330 bVisible
= !IsFiltered( nRow
);
335 bool ScOutlineWindow::GetImagePos( size_t nLevel
, size_t nEntry
, Point
& rPos
) const
337 bool bRet
= nLevel
< GetLevelCount();
340 long nLevelPos
= GetLevelPos( nLevel
);
341 if ( nEntry
== SC_OL_HEADERENTRY
)
342 rPos
= GetPoint( nLevelPos
, GetHeaderEntryPos() );
345 long nStartPos
, nEndPos
, nImagePos
;
346 bRet
= GetEntryPos( nLevel
, nEntry
, nStartPos
, nEndPos
, nImagePos
);
347 rPos
= GetPoint( nLevelPos
, nImagePos
);
353 bool ScOutlineWindow::IsButtonVisible( size_t nLevel
, size_t nEntry
) const
356 if ( nEntry
== SC_OL_HEADERENTRY
)
357 bRet
= (mnHeaderSize
> 0) && (nLevel
< GetLevelCount());
360 const ScOutlineEntry
* pEntry
= GetOutlineEntry( nLevel
, nEntry
);
361 if ( pEntry
&& pEntry
->IsVisible() )
363 SCCOLROW nStart
, nEnd
;
364 GetVisibleRange( nStart
, nEnd
);
365 bRet
= (nStart
<= pEntry
->GetStart()) && (pEntry
->GetStart() <= nEnd
);
371 bool ScOutlineWindow::ItemHit( const Point
& rPos
, size_t& rnLevel
, size_t& rnEntry
, bool& rbButton
) const
373 const ScOutlineArray
* pArray
= GetOutlineArray();
374 if ( !pArray
) return false;
376 SCCOLROW nStartIndex
, nEndIndex
;
377 GetVisibleRange( nStartIndex
, nEndIndex
);
379 size_t nLevel
= GetLevelFromPos( mbHoriz
? rPos
.Y() : rPos
.X() );
380 if ( nLevel
== SC_OL_NOLEVEL
)
383 long nEntryMousePos
= mbHoriz
? rPos
.X() : rPos
.Y();
385 // --- level buttons ---
387 if ( mnHeaderSize
> 0 )
389 long nImagePos
= GetHeaderEntryPos();
390 if ( (nImagePos
<= nEntryMousePos
) && (nEntryMousePos
< nImagePos
+ SC_OL_BITMAPSIZE
) )
393 rnEntry
= SC_OL_HEADERENTRY
;
399 // --- expand/collapse buttons and expanded lines ---
401 // search outline entries backwards
402 size_t nEntry
= pArray
->GetCount( sal::static_int_cast
<sal_uInt16
>(nLevel
) );
407 const ScOutlineEntry
* pEntry
= pArray
->GetEntry( sal::static_int_cast
<sal_uInt16
>(nLevel
),
408 sal::static_int_cast
<sal_uInt16
>(nEntry
) );
409 SCCOLROW nStart
= pEntry
->GetStart();
410 SCCOLROW nEnd
= pEntry
->GetEnd();
412 if ( (nEnd
>= nStartIndex
) && (nStart
<= nEndIndex
) )
414 long nStartPos
, nEndPos
, nImagePos
;
415 if ( GetEntryPos( nLevel
, nEntry
, nStartPos
, nEndPos
, nImagePos
) )
421 if ( (nStart
>= nStartIndex
) && (nImagePos
<= nEntryMousePos
) && (nEntryMousePos
< nImagePos
+ SC_OL_BITMAPSIZE
) )
428 if ( mbMirrorEntries
)
429 ::std::swap( nStartPos
, nEndPos
); // in RTL mode, nStartPos is the larger value
430 if ( (nStartPos
<= nEntryMousePos
) && (nEntryMousePos
<= nEndPos
) )
442 bool ScOutlineWindow::ButtonHit( const Point
& rPos
, size_t& rnLevel
, size_t& rnEntry
) const
445 bool bRet
= ItemHit( rPos
, rnLevel
, rnEntry
, bButton
);
446 return bRet
&& bButton
;
449 bool ScOutlineWindow::LineHit( const Point
& rPos
, size_t& rnLevel
, size_t& rnEntry
) const
452 bool bRet
= ItemHit( rPos
, rnLevel
, rnEntry
, bButton
);
453 return bRet
&& !bButton
;
456 void ScOutlineWindow::DoFunction( size_t nLevel
, size_t nEntry
) const
458 ScDBFunc
& rFunc
= *mrViewData
.GetView();
459 if ( nEntry
== SC_OL_HEADERENTRY
)
460 rFunc
.SelectLevel( mbHoriz
, sal::static_int_cast
<sal_uInt16
>(nLevel
) );
463 const ScOutlineEntry
* pEntry
= GetOutlineEntry( nLevel
, nEntry
);
466 if ( pEntry
->IsHidden() )
467 rFunc
.ShowOutline( mbHoriz
, sal::static_int_cast
<sal_uInt16
>(nLevel
), sal::static_int_cast
<sal_uInt16
>(nEntry
) );
469 rFunc
.HideOutline( mbHoriz
, sal::static_int_cast
<sal_uInt16
>(nLevel
), sal::static_int_cast
<sal_uInt16
>(nEntry
) );
474 void ScOutlineWindow::DoExpand( size_t nLevel
, size_t nEntry
) const
476 const ScOutlineEntry
* pEntry
= GetOutlineEntry( nLevel
, nEntry
);
477 if ( pEntry
&& pEntry
->IsHidden() )
478 DoFunction( nLevel
, nEntry
);
481 void ScOutlineWindow::DoCollapse( size_t nLevel
, size_t nEntry
) const
483 const ScOutlineEntry
* pEntry
= GetOutlineEntry( nLevel
, nEntry
);
484 if ( pEntry
&& !pEntry
->IsHidden() )
485 DoFunction( nLevel
, nEntry
);
488 void ScOutlineWindow::Resize()
491 SetHeaderSize( mnHeaderSize
); // recalculates header/group positions
492 if ( !IsFocusButtonVisible() )
495 ShowFocus(); // calculates valid position
499 void ScOutlineWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
501 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
502 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
507 Window::DataChanged( rDCEvt
);
510 // drawing --------------------------------------------------------------------
512 void ScOutlineWindow::SetEntryAreaClipRegion()
514 SetClipRegion( vcl::Region(tools::Rectangle(
515 GetPoint( 0, mnMainFirstPos
),
516 GetPoint( GetOutputSizeLevel() - 1, mnMainLastPos
))));
519 void ScOutlineWindow::DrawLineRel(
520 long nLevelStart
, long nEntryStart
, long nLevelEnd
, long nEntryEnd
)
522 DrawLine( GetPoint( nLevelStart
, nEntryStart
), GetPoint( nLevelEnd
, nEntryEnd
) );
525 void ScOutlineWindow::DrawRectRel(
526 long nLevelStart
, long nEntryStart
, long nLevelEnd
, long nEntryEnd
)
528 DrawRect( GetRectangle( nLevelStart
, nEntryStart
, nLevelEnd
, nEntryEnd
) );
533 Image
GetImage(const OUString
& rId
)
535 return Image(BitmapEx(rId
));
539 void ScOutlineWindow::DrawImageRel(long nLevelPos
, long nEntryPos
, const OUString
& rId
)
541 const Image
& rImage
= GetImage(rId
);
543 SetFillColor( GetBackground().GetColor() );
544 Point
aPos( GetPoint( nLevelPos
, nEntryPos
) );
545 DrawRect( tools::Rectangle( aPos
, rImage
.GetSizePixel() ) );
546 DrawImage( aPos
, rImage
);
549 void ScOutlineWindow::DrawBorderRel( size_t nLevel
, size_t nEntry
, bool bPressed
)
552 if ( GetImagePos( nLevel
, nEntry
, aPos
) )
554 OUString sId
= bPressed
? OUString(RID_BMP_PRESSED
) : OUString(RID_BMP_NOTPRESSED
);
555 bool bClip
= (nEntry
!= SC_OL_HEADERENTRY
);
557 SetEntryAreaClipRegion();
558 DrawImage(aPos
, GetImage(sId
));
562 mbMTPressed
= bPressed
;
565 void ScOutlineWindow::ShowFocus()
569 // first move to a visible position
570 ImplMoveFocusToVisible( true );
572 if ( IsFocusButtonVisible() )
575 if ( GetImagePos( mnFocusLevel
, mnFocusEntry
, aPos
) )
577 aPos
+= Point( 1, 1 );
578 maFocusRect
= tools::Rectangle( aPos
, Size( SC_OL_BITMAPSIZE
- 2, SC_OL_BITMAPSIZE
- 2 ) );
579 bool bClip
= (mnFocusEntry
!= SC_OL_HEADERENTRY
);
581 SetEntryAreaClipRegion();
582 InvertTracking( maFocusRect
, ShowTrackFlags::Small
| ShowTrackFlags::TrackWindow
);
590 void ScOutlineWindow::HideFocus()
592 if ( !maFocusRect
.IsEmpty() )
594 bool bClip
= (mnFocusEntry
!= SC_OL_HEADERENTRY
);
596 SetEntryAreaClipRegion();
597 InvertTracking( maFocusRect
, ShowTrackFlags::Small
| ShowTrackFlags::TrackWindow
);
600 maFocusRect
.SetEmpty();
604 static const OUStringLiteral aLevelBmps
[]=
616 void ScOutlineWindow::Paint( vcl::RenderContext
& /*rRenderContext*/, const tools::Rectangle
& /* rRect */ )
618 long nEntriesSign
= mbMirrorEntries
? -1 : 1;
619 long nLevelsSign
= mbMirrorLevels
? -1 : 1;
621 Size aSize
= GetOutputSizePixel();
622 long nLevelEnd
= (mbHoriz
? aSize
.Height() : aSize
.Width()) - 1;
623 long nEntryEnd
= (mbHoriz
? aSize
.Width() : aSize
.Height()) - 1;
625 SetLineColor( maLineColor
);
626 long nBorderPos
= mbMirrorLevels
? 0 : nLevelEnd
;
627 DrawLineRel( nBorderPos
, 0, nBorderPos
, nEntryEnd
);
629 const ScOutlineArray
* pArray
= GetOutlineArray();
630 if ( !pArray
) return;
632 size_t nLevelCount
= GetLevelCount();
634 // --- draw header images ---
636 if ( mnHeaderSize
> 0 )
638 long nEntryPos
= GetHeaderEntryPos();
639 for ( size_t nLevel
= 0; nLevel
< nLevelCount
; ++nLevel
)
640 DrawImageRel(GetLevelPos(nLevel
), nEntryPos
, aLevelBmps
[nLevel
]);
642 SetLineColor( maLineColor
);
643 long nLinePos
= mnHeaderPos
+ (mbMirrorEntries
? 0 : (mnHeaderSize
- 1));
644 DrawLineRel( 0, nLinePos
, nLevelEnd
, nLinePos
);
647 // --- draw lines & collapse/expand images ---
649 SetEntryAreaClipRegion();
651 SCCOLROW nStartIndex
, nEndIndex
;
652 GetVisibleRange( nStartIndex
, nEndIndex
);
654 for ( size_t nLevel
= 0; nLevel
+ 1 < nLevelCount
; ++nLevel
)
656 long nLevelPos
= GetLevelPos( nLevel
);
657 long nEntryPos1
= 0, nEntryPos2
= 0, nImagePos
= 0;
659 size_t nEntryCount
= pArray
->GetCount( sal::static_int_cast
<sal_uInt16
>(nLevel
) );
662 // first draw all lines in the current level
664 SetFillColor( maLineColor
);
665 for ( nEntry
= 0; nEntry
< nEntryCount
; ++nEntry
)
667 const ScOutlineEntry
* pEntry
= pArray
->GetEntry( sal::static_int_cast
<sal_uInt16
>(nLevel
),
668 sal::static_int_cast
<sal_uInt16
>(nEntry
) );
669 SCCOLROW nStart
= pEntry
->GetStart();
670 SCCOLROW nEnd
= pEntry
->GetEnd();
673 bool bDraw
= (nEnd
>= nStartIndex
) && (nStart
<= nEndIndex
);
674 // find output coordinates
676 bDraw
= GetEntryPos( nLevel
, nEntry
, nEntryPos1
, nEntryPos2
, nImagePos
);
677 // draw, if not collapsed
678 if ( bDraw
&& !pEntry
->IsHidden() )
680 if ( nStart
>= nStartIndex
)
681 nEntryPos1
+= nEntriesSign
;
682 nEntryPos2
-= 2 * nEntriesSign
;
683 long nLinePos
= nLevelPos
;
684 if ( mbMirrorLevels
)
685 nLinePos
+= SC_OL_BITMAPSIZE
- 1; // align with right edge of bitmap
686 DrawRectRel( nLinePos
, nEntryPos1
, nLinePos
+ nLevelsSign
, nEntryPos2
);
688 if ( nEnd
<= nEndIndex
)
689 DrawRectRel( nLinePos
, nEntryPos2
- nEntriesSign
,
690 nLinePos
+ ( SC_OL_BITMAPSIZE
/ 3 ) * nLevelsSign
, nEntryPos2
);
694 // draw all images in the level from last to first
695 nEntry
= nEntryCount
;
700 const ScOutlineEntry
* pEntry
= pArray
->GetEntry( sal::static_int_cast
<sal_uInt16
>(nLevel
),
701 sal::static_int_cast
<sal_uInt16
>(nEntry
) );
702 SCCOLROW nStart
= pEntry
->GetStart();
705 bool bDraw
= (nStartIndex
<= nStart
) && (nStart
<= nEndIndex
+ 1);
706 // find output coordinates
708 bDraw
= GetEntryPos( nLevel
, nEntry
, nEntryPos1
, nEntryPos2
, nImagePos
);
709 // draw, if not hidden by higher levels
712 OUString sImageId
= pEntry
->IsHidden() ? OUString(RID_BMP_PLUS
) : OUString(RID_BMP_MINUS
);
713 DrawImageRel(nLevelPos
, nImagePos
, sImageId
);
720 if ( !mbDontDrawFocus
)
724 // focus ----------------------------------------------------------------------
726 /** Increments or decrements a value and wraps at the specified limits.
727 @return true = value wrapped. */
728 static bool lcl_RotateValue( size_t& rnValue
, size_t nMin
, size_t nMax
, bool bForward
)
730 OSL_ENSURE( nMin
<= nMax
, "lcl_RotateValue - invalid range" );
731 OSL_ENSURE( nMax
< static_cast< size_t >( -1 ), "lcl_RotateValue - range overflow" );
735 if ( rnValue
< nMax
)
745 if ( rnValue
> nMin
)
756 bool ScOutlineWindow::IsFocusButtonVisible() const
758 return IsButtonVisible( mnFocusLevel
, mnFocusEntry
);
761 bool ScOutlineWindow::ImplMoveFocusByEntry( bool bForward
, bool bFindVisible
)
763 const ScOutlineArray
* pArray
= GetOutlineArray();
767 bool bWrapped
= false;
768 size_t nEntryCount
= pArray
->GetCount( sal::static_int_cast
<sal_uInt16
>(mnFocusLevel
) );
769 // #i29530# entry count may be decreased after changing active sheet
770 if( mnFocusEntry
>= nEntryCount
)
771 mnFocusEntry
= SC_OL_HEADERENTRY
;
772 size_t nOldEntry
= mnFocusEntry
;
776 if ( mnFocusEntry
== SC_OL_HEADERENTRY
)
778 // move from header to first or last entry
779 if ( nEntryCount
> 0 )
780 mnFocusEntry
= bForward
? 0 : (nEntryCount
- 1);
781 /* wrapped, if forward from right header to first entry,
782 or if backward from left header to last entry */
783 // Header and entries are now always in consistent order,
784 // so there's no need to check for mirroring here.
785 if ( !nEntryCount
|| !bForward
)
788 else if ( lcl_RotateValue( mnFocusEntry
, 0, nEntryCount
- 1, bForward
) )
790 // lcl_RotateValue returns true -> wrapped the entry range -> move to header
791 mnFocusEntry
= SC_OL_HEADERENTRY
;
792 /* wrapped, if forward from last entry to left header,
793 or if backward from first entry to right header */
798 while ( bFindVisible
&& !IsFocusButtonVisible() && (nOldEntry
!= mnFocusEntry
) );
803 bool ScOutlineWindow::ImplMoveFocusByLevel( bool bForward
)
805 const ScOutlineArray
* pArray
= GetOutlineArray();
809 bool bWrapped
= false;
810 size_t nLevelCount
= GetLevelCount();
812 if ( mnFocusEntry
== SC_OL_HEADERENTRY
)
814 if ( nLevelCount
> 0 )
815 bWrapped
= lcl_RotateValue( mnFocusLevel
, 0, nLevelCount
- 1, bForward
);
819 const ScOutlineEntry
* pEntry
= pArray
->GetEntry(
820 mnFocusLevel
, mnFocusEntry
);
824 SCCOLROW nStart
= pEntry
->GetStart();
825 SCCOLROW nEnd
= pEntry
->GetEnd();
826 size_t nNewLevel
= mnFocusLevel
;
827 size_t nNewEntry
= 0;
830 if ( bForward
&& (mnFocusLevel
+ 2 < nLevelCount
) )
832 // next level -> find first child entry
833 nNewLevel
= mnFocusLevel
+ 1;
834 bFound
= pArray
->GetEntryIndexInRange(nNewLevel
, nStart
, nEnd
, nNewEntry
);
836 else if ( !bForward
&& (mnFocusLevel
> 0) )
838 // previous level -> find parent entry
839 nNewLevel
= mnFocusLevel
- 1;
840 bFound
= pArray
->GetEntryIndex(nNewLevel
, nStart
, nNewEntry
);
843 if ( bFound
&& IsButtonVisible( nNewLevel
, nNewEntry
) )
845 mnFocusLevel
= nNewLevel
;
846 mnFocusEntry
= nNewEntry
;
854 bool ScOutlineWindow::ImplMoveFocusByTabOrder( bool bForward
)
857 size_t nOldLevel
= mnFocusLevel
;
858 size_t nOldEntry
= mnFocusEntry
;
862 /* one level up, if backward from left header,
863 or one level down, if forward from right header */
864 if ( (!bForward
) && (mnFocusEntry
== SC_OL_HEADERENTRY
) )
865 bRet
|= ImplMoveFocusByLevel( bForward
);
866 // move to next/previous entry
867 bool bWrapInLevel
= ImplMoveFocusByEntry( bForward
, false );
868 bRet
|= bWrapInLevel
;
869 /* one level up, if wrapped backward to right header,
870 or one level down, if wrapped forward to right header */
871 if ( bForward
&& bWrapInLevel
)
872 bRet
|= ImplMoveFocusByLevel( bForward
);
874 while ( !IsFocusButtonVisible() && ((nOldLevel
!= mnFocusLevel
) || (nOldEntry
!= mnFocusEntry
)) );
879 void ScOutlineWindow::ImplMoveFocusToVisible( bool bForward
)
881 // first try to find an entry in the same level
882 if ( !IsFocusButtonVisible() )
883 ImplMoveFocusByEntry( bForward
, true );
884 // then try to find any other entry
885 if ( !IsFocusButtonVisible() )
886 ImplMoveFocusByTabOrder( bForward
);
889 void ScOutlineWindow::MoveFocusByEntry( bool bForward
)
892 ImplMoveFocusByEntry( bForward
, true );
896 void ScOutlineWindow::MoveFocusByLevel( bool bForward
)
899 ImplMoveFocusByLevel( bForward
);
903 void ScOutlineWindow::MoveFocusByTabOrder( bool bForward
)
906 ImplMoveFocusByTabOrder( bForward
);
910 void ScOutlineWindow::GetFocus()
916 void ScOutlineWindow::LoseFocus()
922 // mouse ----------------------------------------------------------------------
924 void ScOutlineWindow::StartMouseTracking( size_t nLevel
, size_t nEntry
)
929 DrawBorderRel( nLevel
, nEntry
, true );
932 void ScOutlineWindow::EndMouseTracking()
935 DrawBorderRel( mnMTLevel
, mnMTEntry
, false );
939 void ScOutlineWindow::MouseMove( const MouseEvent
& rMEvt
)
941 if ( IsMouseTracking() )
943 size_t nLevel
, nEntry
;
946 if ( ButtonHit( rMEvt
.GetPosPixel(), nLevel
, nEntry
) )
947 bHit
= (nLevel
== mnMTLevel
) && (nEntry
== mnMTEntry
);
949 if ( bHit
!= mbMTPressed
)
950 DrawBorderRel( mnMTLevel
, mnMTEntry
, bHit
);
954 void ScOutlineWindow::MouseButtonUp( const MouseEvent
& rMEvt
)
956 if ( IsMouseTracking() )
960 size_t nLevel
, nEntry
;
961 if ( ButtonHit( rMEvt
.GetPosPixel(), nLevel
, nEntry
) )
962 if ( (nLevel
== mnMTLevel
) && (nEntry
== mnMTEntry
) )
963 DoFunction( nLevel
, nEntry
);
967 void ScOutlineWindow::MouseButtonDown( const MouseEvent
& rMEvt
)
969 size_t nLevel
, nEntry
;
970 bool bHit
= ButtonHit( rMEvt
.GetPosPixel(), nLevel
, nEntry
);
972 StartMouseTracking( nLevel
, nEntry
);
973 else if ( rMEvt
.GetClicks() == 2 )
975 bHit
= LineHit( rMEvt
.GetPosPixel(), nLevel
, nEntry
);
977 DoFunction( nLevel
, nEntry
);
980 // if an item has been hit and window is focused, move focus to this item
981 if ( bHit
&& HasFocus() )
984 mnFocusLevel
= nLevel
;
985 mnFocusEntry
= nEntry
;
990 // keyboard -------------------------------------------------------------------
992 void ScOutlineWindow::KeyInput( const KeyEvent
& rKEvt
)
994 const vcl::KeyCode
& rKCode
= rKEvt
.GetKeyCode();
995 bool bNoMod
= !rKCode
.GetModifier();
996 bool bShift
= (rKCode
.GetModifier() == KEY_SHIFT
);
997 bool bCtrl
= (rKCode
.GetModifier() == KEY_MOD1
);
999 sal_uInt16 nCode
= rKCode
.GetCode();
1000 bool bUpDownKey
= (nCode
== KEY_UP
) || (nCode
== KEY_DOWN
);
1001 bool bLeftRightKey
= (nCode
== KEY_LEFT
) || (nCode
== KEY_RIGHT
);
1004 if ( (nCode
== KEY_TAB
) && (bNoMod
|| bShift
) )
1005 // move forward without SHIFT key
1006 MoveFocusByTabOrder( bNoMod
); // TAB uses logical order, regardless of mirroring
1008 // LEFT/RIGHT/UP/DOWN keys
1009 else if ( bNoMod
&& (bUpDownKey
|| bLeftRightKey
) )
1011 bool bForward
= (nCode
== KEY_DOWN
) || (nCode
== KEY_RIGHT
);
1012 if ( mbHoriz
== bLeftRightKey
)
1013 // move inside level with LEFT/RIGHT in horizontal and with UP/DOWN in vertical
1014 MoveFocusByEntry( bForward
!= mbMirrorEntries
);
1016 // move to next/prev level with LEFT/RIGHT in vertical and with UP/DOWN in horizontal
1017 MoveFocusByLevel( bForward
!= mbMirrorLevels
);
1021 else if ( bCtrl
&& (nCode
>= KEY_1
) && (nCode
<= KEY_9
) )
1023 size_t nLevel
= static_cast< size_t >( nCode
- KEY_1
);
1024 if ( nLevel
< GetLevelCount() )
1025 DoFunction( nLevel
, SC_OL_HEADERENTRY
);
1029 else switch ( rKCode
.GetFullCode() )
1031 case KEY_ADD
: DoExpand( mnFocusLevel
, mnFocusEntry
); break;
1032 case KEY_SUBTRACT
: DoCollapse( mnFocusLevel
, mnFocusEntry
); break;
1034 case KEY_RETURN
: DoFunction( mnFocusLevel
, mnFocusEntry
); break;
1035 default: Window::KeyInput( rKEvt
);
1039 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */