bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / treelist / iconview.cxx
blob45740a38cde5b6db68f78f0bedea69454e456f36
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 )
28 nColumns = 1;
29 mbCenterAndClipText = true;
30 SetEntryHeight( 100 );
31 SetEntryWidth( 100 );
33 pImpl.reset( new IconViewImpl( this, GetModel(), GetStyle() ) );
36 void IconView::Resize()
38 Size aBoxSize = Control::GetParent()->GetOutputSizePixel();
40 if ( !aBoxSize.Width() )
41 return;
43 SetSizePixel( aBoxSize );
45 nColumns = aBoxSize.Width() / nEntryWidth;
47 SvTreeListBox::Resize();
50 tools::Rectangle IconView::GetFocusRect( SvTreeListEntry*, long nEntryPos )
52 Size aSize;
53 aSize.setHeight( nEntryHeight );
54 aSize.setWidth( nEntryWidth );
56 Point aPos;
57 aPos.setX( 0 );
58 aPos.setY( 0 );
60 tools::Rectangle aRect;
62 short nCols = GetColumnsCount();
64 if(nCols)
66 aPos.setY( ( nEntryPos / nCols ) * nEntryHeight );
67 aPos.setX( ( nEntryPos % nCols ) * nEntryWidth );
70 aRect.SetPos( aPos );
71 aRect.SetSize( aSize );
73 return aRect;
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();
89 Point aEntryPos;
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;
120 nCurItem++;
121 continue;
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
144 if (!bCurFontIsSel)
146 rRenderContext.SetTextColor(aHighlightTextColor);
147 rRenderContext.SetFont(aHighlightFont);
148 bCurFontIsSel = true;
150 aWallpaper.SetColor(aNewWallColor);
152 else // no selection
154 if (bCurFontIsSel)
156 bCurFontIsSel = false;
157 rRenderContext.SetTextColor(aBackupTextColor);
158 rRenderContext.SetFont(aBackupFont);
160 else
162 aWallpaper.SetColor(rEntry.GetBackColor());
166 // draw background
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);
182 // center vertically
183 aEntryPos.AdjustY((nTempEntryHeight - nItemHeight) / 2 );
185 // draw item
186 pViewDataEntry->SetPaintRectangle(aRect);
188 aEntryPos.AdjustY(15 );
190 pItem->Paint(aEntryPos, *this, rRenderContext, pViewDataEntry, rEntry);
192 rRenderContext.SetFillColor(aBackupColor);
194 nCurItem++;
197 // draw icon
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 );
209 // center vertically
210 aEntryPos.AdjustY((nTempEntryHeight - nItemHeight) / 2 );
212 aEntryPos.AdjustY( -10 );
214 pItem->Paint(aEntryPos, *this, rRenderContext, pViewDataEntry, rEntry);
217 if (bCurFontIsSel)
219 rRenderContext.SetTextColor(aBackupTextColor);
220 rRenderContext.SetFont(aBackupFont);
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */