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 
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  pImpl->UpdateContextBmpWidthMax(&rEntry);
83 
84  short nTempEntryHeight = GetEntryHeight();
85  short nTempEntryWidth = GetEntryWidth();
86 
87  Point aEntryPos;
88 
89  Color aBackupTextColor(rRenderContext.GetTextColor());
90  vcl::Font aBackupFont(rRenderContext.GetFont());
91  Color aBackupColor = rRenderContext.GetFillColor();
92 
93  bool bCurFontIsSel = false;
94  const WinBits nWindowStyle = GetStyle();
95  const bool bHideSelection = (nWindowStyle & WB_HIDESELECTION) !=0 && !HasFocus();
96  const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
97 
98  vcl::Font aHighlightFont(rRenderContext.GetFont());
99  const Color aHighlightTextColor(rSettings.GetHighlightTextColor());
100  aHighlightFont.SetColor(aHighlightTextColor);
101 
102  Size aRectSize(nTempEntryWidth, nTempEntryHeight);
103 
104  SvViewDataEntry* pViewDataEntry = GetViewDataEntry( &rEntry );
105 
106  sal_uInt16 nItemCount = rEntry.ItemCount();
107  sal_uInt16 nCurItem = 0;
108  sal_uInt16 nIconItem = nItemCount;
109 
110  while (nCurItem < nItemCount)
111  {
112  SvLBoxItem* pItem = nCurItem < nItemCount ? &rEntry.GetItem(nCurItem) : nullptr;
113  SvLBoxItemType nItemType = pItem->GetType();
114 
115  if (nItemType == SvLBoxItemType::ContextBmp)
116  {
117  nIconItem = nCurItem;
118  nCurItem++;
119  continue;
120  }
121 
122  auto nItemHeight = SvLBoxItem::GetHeight(pViewDataEntry, nCurItem);
123 
124  aEntryPos.setX( nX );
125  aEntryPos.setY( nY );
126 
127  // set background pattern/color
128 
129  Wallpaper aWallpaper = rRenderContext.GetBackground();
130 
131  if (pViewDataEntry->IsHighlighted())
132  {
133  Color aNewWallColor = rSettings.GetHighlightColor();
134  // if the face color is bright then the deactivate color is also bright
135  // -> so you can't see any deactivate selection
136  if (bHideSelection && !rSettings.GetFaceColor().IsBright()
137  && aWallpaper.GetColor().IsBright() != rSettings.GetDeactiveColor().IsBright())
138  {
139  aNewWallColor = rSettings.GetDeactiveColor();
140  }
141  // set font color to highlight
142  if (!bCurFontIsSel)
143  {
144  rRenderContext.SetTextColor(aHighlightTextColor);
145  rRenderContext.SetFont(aHighlightFont);
146  bCurFontIsSel = true;
147  }
148  aWallpaper.SetColor(aNewWallColor);
149  }
150  else // no selection
151  {
152  if (bCurFontIsSel)
153  {
154  bCurFontIsSel = false;
155  rRenderContext.SetTextColor(aBackupTextColor);
156  rRenderContext.SetFont(aBackupFont);
157  }
158  else
159  {
160  aWallpaper.SetColor(rEntry.GetBackColor());
161  }
162  }
163 
164  // draw background
166  {
167  aRect.SetPos(aEntryPos);
168  aRect.SetSize(aRectSize);
169 
170  Color aBackgroundColor = aWallpaper.GetColor();
171  if (aBackgroundColor != COL_TRANSPARENT)
172  {
173  rRenderContext.SetFillColor(aBackgroundColor);
174  // this case may occur for smaller horizontal resizes
175  if (aRect.Left() < aRect.Right())
176  rRenderContext.DrawRect(aRect);
177  }
178  }
179 
180  // center vertically
181  aEntryPos.AdjustY((nTempEntryHeight - nItemHeight) / 2 );
182 
183  aEntryPos.AdjustY(15 );
184 
185  pItem->Paint(aEntryPos, *this, rRenderContext, pViewDataEntry, rEntry);
186 
187  rRenderContext.SetFillColor(aBackupColor);
188 
189  nCurItem++;
190  }
191 
192  // draw icon
193  if(nIconItem != nItemCount && nIconItem < nItemCount)
194  {
195  SvLBoxItem* pItem = &rEntry.GetItem(nIconItem);
196  auto nItemWidth = pItem->GetWidth(this, pViewDataEntry, nIconItem);
197  auto nItemHeight = SvLBoxItem::GetHeight(pViewDataEntry, nIconItem);
198 
199  aEntryPos.setX( nX );
200  aEntryPos.setY( nY );
201 
202  // center horizontally
203  aEntryPos.AdjustX((nTempEntryWidth - nItemWidth) / 2 );
204  // center vertically
205  aEntryPos.AdjustY((nTempEntryHeight - nItemHeight) / 2 );
206 
207  aEntryPos.AdjustY( -10 );
208 
209  pItem->Paint(aEntryPos, *this, rRenderContext, pViewDataEntry, rEntry);
210  }
211 
212  if (bCurFontIsSel)
213  {
214  rRenderContext.SetTextColor(aBackupTextColor);
215  rRenderContext.SetFont(aBackupFont);
216  }
217 }
218 
219 /* 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:1125
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)
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:666
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:2965
void setWidth(long nWidth)
friend class IconViewImpl
const Color & GetFillColor() const
Definition: outdev.hxx:635
void setHeight(long nHeight)