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/treelistentry.hxx>
21 #include <vcl/viewdataentry.hxx>
22 #include <iconview.hxx>
23 #include "iconviewimpl.hxx"
25 IconView::IconView( vcl::Window
* pParent
, WinBits nBits
)
26 : SvTreeListBox( pParent
, nBits
)
29 mbCenterAndClipText
= true;
30 SetEntryHeight( 100 );
33 pImpl
.reset( new IconViewImpl( this, GetModel(), GetStyle() ) );
36 void IconView::Resize()
38 Size aBoxSize
= Control::GetParent()->GetOutputSizePixel();
40 if ( !aBoxSize
.Width() )
43 SetSizePixel( aBoxSize
);
45 nColumns
= aBoxSize
.Width() / nEntryWidth
;
47 SvTreeListBox::Resize();
50 tools::Rectangle
IconView::GetFocusRect( SvTreeListEntry
*, long nEntryPos
)
53 aSize
.setHeight( nEntryHeight
);
54 aSize
.setWidth( nEntryWidth
);
60 tools::Rectangle aRect
;
62 short nCols
= GetColumnsCount();
66 aPos
.setY( ( nEntryPos
/ nCols
) * nEntryHeight
);
67 aPos
.setX( ( nEntryPos
% nCols
) * nEntryWidth
);
71 aRect
.SetSize( aSize
);
76 void IconView::PaintEntry(SvTreeListEntry
& rEntry
, long nX
, long nY
,
77 vcl::RenderContext
& rRenderContext
)
80 tools::Rectangle aRect
; // multi purpose
82 PreparePaint(rRenderContext
, rEntry
);
84 pImpl
->UpdateContextBmpWidthMax(&rEntry
);
86 short nTempEntryHeight
= GetEntryHeight();
87 short nTempEntryWidth
= GetEntryWidth();
91 Color
aBackupTextColor(rRenderContext
.GetTextColor());
92 vcl::Font
aBackupFont(rRenderContext
.GetFont());
93 Color aBackupColor
= rRenderContext
.GetFillColor();
95 bool bCurFontIsSel
= false;
96 const WinBits nWindowStyle
= GetStyle();
97 const bool bHideSelection
= (nWindowStyle
& WB_HIDESELECTION
) !=0 && !HasFocus();
98 const StyleSettings
& rSettings
= rRenderContext
.GetSettings().GetStyleSettings();
100 vcl::Font
aHighlightFont(rRenderContext
.GetFont());
101 const Color
aHighlightTextColor(rSettings
.GetHighlightTextColor());
102 aHighlightFont
.SetColor(aHighlightTextColor
);
104 Size
aRectSize(nTempEntryWidth
, nTempEntryHeight
);
106 SvViewDataEntry
* pViewDataEntry
= GetViewDataEntry( &rEntry
);
108 sal_uInt16 nItemCount
= rEntry
.ItemCount();
109 sal_uInt16 nCurItem
= 0;
110 sal_uInt16 nIconItem
= nItemCount
;
112 while (nCurItem
< nItemCount
)
114 SvLBoxItem
* pItem
= nCurItem
< nItemCount
? &rEntry
.GetItem(nCurItem
) : nullptr;
115 SvLBoxItemType nItemType
= pItem
->GetType();
117 if (nItemType
== SvLBoxItemType::ContextBmp
)
119 nIconItem
= nCurItem
;
124 auto nItemHeight
= SvLBoxItem::GetHeight(pViewDataEntry
, nCurItem
);
126 aEntryPos
.setX( nX
);
127 aEntryPos
.setY( nY
);
129 // set background pattern/color
131 Wallpaper aWallpaper
= rRenderContext
.GetBackground();
133 if (pViewDataEntry
->IsHighlighted())
135 Color aNewWallColor
= rSettings
.GetHighlightColor();
136 // if the face color is bright then the deactivate color is also bright
137 // -> so you can't see any deactivate selection
138 if (bHideSelection
&& !rSettings
.GetFaceColor().IsBright()
139 && aWallpaper
.GetColor().IsBright() != rSettings
.GetDeactiveColor().IsBright())
141 aNewWallColor
= rSettings
.GetDeactiveColor();
143 // set font color to highlight
146 rRenderContext
.SetTextColor(aHighlightTextColor
);
147 rRenderContext
.SetFont(aHighlightFont
);
148 bCurFontIsSel
= true;
150 aWallpaper
.SetColor(aNewWallColor
);
156 bCurFontIsSel
= false;
157 rRenderContext
.SetTextColor(aBackupTextColor
);
158 rRenderContext
.SetFont(aBackupFont
);
162 aWallpaper
.SetColor(rEntry
.GetBackColor());
167 if (!(nTreeFlags
& SvTreeFlags::USESEL
))
169 aRect
.SetPos(aEntryPos
);
170 aRect
.SetSize(aRectSize
);
172 Color aBackgroundColor
= aWallpaper
.GetColor();
173 if (aBackgroundColor
!= COL_TRANSPARENT
)
175 rRenderContext
.SetFillColor(aBackgroundColor
);
176 // this case may occur for smaller horizontal resizes
177 if (aRect
.Left() < aRect
.Right())
178 rRenderContext
.DrawRect(aRect
);
183 aEntryPos
.AdjustY((nTempEntryHeight
- nItemHeight
) / 2 );
186 pViewDataEntry
->SetPaintRectangle(aRect
);
188 aEntryPos
.AdjustY(15 );
190 pItem
->Paint(aEntryPos
, *this, rRenderContext
, pViewDataEntry
, rEntry
);
192 rRenderContext
.SetFillColor(aBackupColor
);
198 if(nIconItem
!= nItemCount
&& nIconItem
< nItemCount
)
200 SvLBoxItem
* pItem
= &rEntry
.GetItem(nIconItem
);
201 auto nItemWidth
= pItem
->GetWidth(this, pViewDataEntry
, nIconItem
);
202 auto nItemHeight
= SvLBoxItem::GetHeight(pViewDataEntry
, nIconItem
);
204 aEntryPos
.setX( nX
);
205 aEntryPos
.setY( nY
);
207 // center horizontally
208 aEntryPos
.AdjustX((nTempEntryWidth
- nItemWidth
) / 2 );
210 aEntryPos
.AdjustY((nTempEntryHeight
- nItemHeight
) / 2 );
212 aEntryPos
.AdjustY( -10 );
214 pItem
->Paint(aEntryPos
, *this, rRenderContext
, pViewDataEntry
, rEntry
);
219 rRenderContext
.SetTextColor(aBackupTextColor
);
220 rRenderContext
.SetFont(aBackupFont
);
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */