LibreOffice Module vcl (master)  1
iconview.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <vcl/treelistentry.hxx>
21 #include <vcl/viewdataentry.hxx>
22 #include <iconview.hxx>
23 #include "iconviewimpl.hxx"
24 
26  : SvTreeListBox( pParent, nBits )
27 {
28  nColumns = 1;
29  mbCenterAndClipText = true;
30  SetEntryHeight( 100 );
31  SetEntryWidth( 100 );
32 
33  pImpl.reset( new IconViewImpl( this, GetModel(), GetStyle() ) );
34 }
35 
37 {
39 
40  if ( !aBoxSize.Width() )
41  return;
42 
43  SetSizePixel( aBoxSize );
44 
45  nColumns = aBoxSize.Width() / nEntryWidth;
46 
48 }
49 
51 {
52  Size aSize;
53  aSize.setHeight( nEntryHeight );
54  aSize.setWidth( nEntryWidth );
55 
56  Point aPos;
57  aPos.setX( 0 );
58  aPos.setY( 0 );
59 
60  tools::Rectangle aRect;
61 
62  short nCols = GetColumnsCount();
63 
64  if(nCols)
65  {
66  aPos.setY( ( nEntryPos / nCols ) * nEntryHeight );
67  aPos.setX( ( nEntryPos % nCols ) * nEntryWidth );
68  }
69 
70  aRect.SetPos( aPos );
71  aRect.SetSize( aSize );
72 
73  return aRect;
74 }
75 
76 void IconView::PaintEntry(SvTreeListEntry& rEntry, long nX, long nY,
77  vcl::RenderContext& rRenderContext)
78 {
79 
80  tools::Rectangle aRect; // multi purpose
81 
82  PreparePaint(rRenderContext, rEntry);
83 
84  pImpl->UpdateContextBmpWidthMax(&rEntry);
85 
86  short nTempEntryHeight = GetEntryHeight();
87  short nTempEntryWidth = GetEntryWidth();
88 
89  Point aEntryPos;
90 
91  Color aBackupTextColor(rRenderContext.GetTextColor());
92  vcl::Font aBackupFont(rRenderContext.GetFont());
93  Color aBackupColor = rRenderContext.GetFillColor();
94 
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();
99 
100  vcl::Font aHighlightFont(rRenderContext.GetFont());
101  const Color aHighlightTextColor(rSettings.GetHighlightTextColor());
102  aHighlightFont.SetColor(aHighlightTextColor);
103 
104  Size aRectSize(nTempEntryWidth, nTempEntryHeight);
105 
106  SvViewDataEntry* pViewDataEntry = GetViewDataEntry( &rEntry );
107 
108  sal_uInt16 nItemCount = rEntry.ItemCount();
109  sal_uInt16 nCurItem = 0;
110  sal_uInt16 nIconItem = nItemCount;
111 
112  while (nCurItem < nItemCount)
113  {
114  SvLBoxItem* pItem = nCurItem < nItemCount ? &rEntry.GetItem(nCurItem) : nullptr;
115  SvLBoxItemType nItemType = pItem->GetType();
116 
117  if (nItemType == SvLBoxItemType::ContextBmp)
118  {
119  nIconItem = nCurItem;
120  nCurItem++;
121  continue;
122  }
123 
124  auto nItemHeight = SvLBoxItem::GetHeight(pViewDataEntry, nCurItem);
125 
126  aEntryPos.setX( nX );
127  aEntryPos.setY( nY );
128 
129  // set background pattern/color
130 
131  Wallpaper aWallpaper = rRenderContext.GetBackground();
132 
133  if (pViewDataEntry->IsHighlighted())
134  {
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())
140  {
141  aNewWallColor = rSettings.GetDeactiveColor();
142  }
143  // set font color to highlight
144  if (!bCurFontIsSel)
145  {
146  rRenderContext.SetTextColor(aHighlightTextColor);
147  rRenderContext.SetFont(aHighlightFont);
148  bCurFontIsSel = true;
149  }
150  aWallpaper.SetColor(aNewWallColor);
151  }
152  else // no selection
153  {
154  if (bCurFontIsSel)
155  {
156  bCurFontIsSel = false;
157  rRenderContext.SetTextColor(aBackupTextColor);
158  rRenderContext.SetFont(aBackupFont);
159  }
160  else
161  {
162  aWallpaper.SetColor(rEntry.GetBackColor());
163  }
164  }
165 
166  // draw background
168  {
169  aRect.SetPos(aEntryPos);
170  aRect.SetSize(aRectSize);
171 
172  Color aBackgroundColor = aWallpaper.GetColor();
173  if (aBackgroundColor != COL_TRANSPARENT)
174  {
175  rRenderContext.SetFillColor(aBackgroundColor);
176  // this case may occur for smaller horizontal resizes
177  if (aRect.Left() < aRect.Right())
178  rRenderContext.DrawRect(aRect);
179  }
180  }
181 
182  // center vertically
183  aEntryPos.AdjustY((nTempEntryHeight - nItemHeight) / 2 );
184 
185  aEntryPos.AdjustY(15 );
186 
187  pItem->Paint(aEntryPos, *this, rRenderContext, pViewDataEntry, rEntry);
188 
189  rRenderContext.SetFillColor(aBackupColor);
190 
191  nCurItem++;
192  }
193 
194  // draw icon
195  if(nIconItem != nItemCount && nIconItem < nItemCount)
196  {
197  SvLBoxItem* pItem = &rEntry.GetItem(nIconItem);
198  auto nItemWidth = pItem->GetWidth(this, pViewDataEntry, nIconItem);
199  auto nItemHeight = SvLBoxItem::GetHeight(pViewDataEntry, nIconItem);
200 
201  aEntryPos.setX( nX );
202  aEntryPos.setY( nY );
203 
204  // center horizontally
205  aEntryPos.AdjustX((nTempEntryWidth - nItemWidth) / 2 );
206  // center vertically
207  aEntryPos.AdjustY((nTempEntryHeight - nItemHeight) / 2 );
208 
209  aEntryPos.AdjustY( -10 );
210 
211  pItem->Paint(aEntryPos, *this, rRenderContext, pViewDataEntry, rEntry);
212  }
213 
214  if (bCurFontIsSel)
215  {
216  rRenderContext.SetTextColor(aBackupTextColor);
217  rRenderContext.SetFont(aBackupFont);
218  }
219 }
220 
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
IconView(vcl::Window *pParent, WinBits nBits)
Definition: iconview.cxx:25
const Color & GetTextColor() const
Definition: outdev.hxx:1127
void SetPos(const Point &rPoint)
const Wallpaper & GetBackground() const
Definition: outdev.hxx:643
const Color & GetDeactiveColor() const
const Color & GetBackColor() const
const Color & GetHighlightTextColor() const
bool IsHighlighted() const
SvTreeList * GetModel() const
const StyleSettings & GetStyleSettings() const
bool mbCenterAndClipText
const Color & GetFaceColor() const
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1262
void SetColor(const Color &rColor)
Definition: wall.cxx:195
short GetColumnsCount() const
View-dependent data for a tree list entry created in the virtual function SvTreeListBox::CreateViewDa...
const Color & GetHighlightColor() const
SvLBoxItemType
int GetHeight(const SvTreeListBox *pView, const SvTreeListEntry *pEntry) const
sal_Int64 WinBits
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
long Right() const
const vcl::Font & GetFont() const
Definition: outdev.hxx:649
short GetEntryHeight() const
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:51
virtual void Paint(const Point &rPos, SvTreeListBox &rOutDev, vcl::RenderContext &rRenderContext, const SvViewDataEntry *pView, const SvTreeListEntry &rEntry)=0
short GetEntryWidth() const
size_t ItemCount() const
void SetEntryWidth(short nWidth)
virtual void PreparePaint(vcl::RenderContext &rRenderContext, SvTreeListEntry &rEntry)
void SetSize(const Size &rSize)
bool IsBright() const
virtual void Resize() override
const Color & GetColor() const
Definition: wall.cxx:204
void SetFillColor()
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
std::unique_ptr< SvImpLBox > pImpl
void SetTextColor(const Color &rColor)
Definition: text.cxx:665
SvViewDataEntry * GetViewDataEntry(SvTreeListEntry const *pEntry) const
virtual tools::Rectangle GetFocusRect(const SvTreeListEntry *, long nEntryPos) override
Definition: iconview.cxx:50
const AllSettings & GetSettings() const
Definition: outdev.hxx:418
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
const SvLBoxItem & GetItem(size_t nPos) const
vcl::Window * GetParent() const
Definition: window2.cxx:1097
virtual void Resize() override
Definition: iconview.cxx:36
virtual SvLBoxItemType GetType() const =0
int GetWidth(const SvTreeListBox *pView, const SvTreeListEntry *pEntry) const
WinBits const WB_HIDESELECTION
void PaintEntry(SvTreeListEntry &, long nX, long nY, vcl::RenderContext &rRenderContext)
Definition: iconview.cxx:76
void SetFont(const vcl::Font &rNewFont)
VCL_DLLPRIVATE void SetEntryHeight(SvTreeListEntry const *pEntry)
long Left() const
WinBits GetStyle() const
Definition: window2.cxx:953
SvTreeFlags nTreeFlags
bool HasFocus() const
Definition: window.cxx:3011
void setWidth(long nWidth)
friend class IconViewImpl
const Color & GetFillColor() const
Definition: outdev.hxx:635
void setHeight(long nHeight)