summaryrefslogtreecommitdiff
path: root/fpicker/source/office/iconview.cxx
blob: b6571b72d1daa7422b93118b1046cbc77d4cf6cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <vcl/treelistentry.hxx>
#include <vcl/viewdataentry.hxx>
#include "fileview.hxx"
#include "iconview.hxx"
#include "iconviewimpl.hxx"

IconView::IconView( vcl::Window* pParent, WinBits nBits )
: SvTreeListBox( pParent, nBits )
{
    nColumns = 1;
    mbCenterAndClipText = true;
    SetEntryHeight( 100 );
    SetEntryWidth( 100 );

    pImpl.reset( new IconViewImpl( this, GetModel(), GetStyle() ) );
}

void IconView::Resize()
{
    Size aBoxSize = Control::GetParent()->GetOutputSizePixel();

    if ( !aBoxSize.Width() )
        return;

    SetSizePixel( aBoxSize );

    nColumns = aBoxSize.Width() / nEntryWidth;

    SvTreeListBox::Resize();
}

tools::Rectangle IconView::GetFocusRect( SvTreeListEntry*, long nEntryPos )
{
    Size aSize;
    aSize.setHeight( nEntryHeight );
    aSize.setWidth( nEntryWidth );

    Point aPos;
    aPos.setX( 0 );
    aPos.setY( 0 );

    tools::Rectangle aRect;

    short nCols = GetColumnsCount();

    if(nCols)
    {
        aPos.setY( ( nEntryPos / nCols ) * nEntryHeight );
        aPos.setX( ( nEntryPos % nCols ) * nEntryWidth );
    }

    aRect.SetPos( aPos );
    aRect.SetSize( aSize );

    return aRect;
}

void IconView::ClearAll()
{
    for ( sal_uLong i = 0; i < GetEntryCount(); ++i )
        delete static_cast<SvtContentEntry*>(GetEntry(i)->GetUserData());

    Clear();
}

void IconView::PaintEntry(SvTreeListEntry& rEntry, long nX, long nY,
                            vcl::RenderContext& rRenderContext)
{

    tools::Rectangle aRect; // multi purpose

    PreparePaint(rRenderContext, rEntry);

    pImpl->UpdateContextBmpWidthMax(&rEntry);

    short nTempEntryHeight = GetEntryHeight();
    short nTempEntryWidth = GetEntryWidth();

    Point aEntryPos;

    Color aBackupTextColor(rRenderContext.GetTextColor());
    vcl::Font aBackupFont(rRenderContext.GetFont());
    Color aBackupColor = rRenderContext.GetFillColor();

    bool bCurFontIsSel = false;
    const WinBits nWindowStyle = GetStyle();
    const bool bHideSelection = (nWindowStyle & WB_HIDESELECTION) !=0 && !HasFocus();
    const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();

    vcl::Font aHighlightFont(rRenderContext.GetFont());
    const Color aHighlightTextColor(rSettings.GetHighlightTextColor());
    aHighlightFont.SetColor(aHighlightTextColor);

    Size aRectSize(nTempEntryWidth, nTempEntryHeight);

    SvViewDataEntry* pViewDataEntry = GetViewDataEntry( &rEntry );

    sal_uInt16 nItemCount = rEntry.ItemCount();
    sal_uInt16 nCurItem = 0;
    sal_uInt16 nIconItem = nItemCount;

    while (nCurItem < nItemCount)
    {
        SvLBoxItem* pItem = nCurItem < nItemCount ? &rEntry.GetItem(nCurItem) : nullptr;
        SvLBoxItemType nItemType = pItem->GetType();

        if (nItemType == SvLBoxItemType::ContextBmp)
        {
            nIconItem = nCurItem;
            nCurItem++;
            continue;
        }

        auto nItemHeight = SvLBoxItem::GetHeight(pViewDataEntry, nCurItem);

        aEntryPos.setX( nX );
        aEntryPos.setY( nY );

        // set background pattern/color

        Wallpaper aWallpaper = rRenderContext.GetBackground();

        if (pViewDataEntry->IsHighlighted())
        {
            Color aNewWallColor = rSettings.GetHighlightColor();
            // if the face color is bright then the deactivate color is also bright
            // -> so you can't see any deactivate selection
            if (bHideSelection && !rSettings.GetFaceColor().IsBright()
               && aWallpaper.GetColor().IsBright() != rSettings.GetDeactiveColor().IsBright())
            {
                aNewWallColor = rSettings.GetDeactiveColor();
            }
            // set font color to highlight
            if (!bCurFontIsSel)
            {
                rRenderContext.SetTextColor(aHighlightTextColor);
                rRenderContext.SetFont(aHighlightFont);
                bCurFontIsSel = true;
            }
            aWallpaper.SetColor(aNewWallColor);
        }
        else  // no selection
        {
            if (bCurFontIsSel)
            {
                bCurFontIsSel = false;
                rRenderContext.SetTextColor(aBackupTextColor);
                rRenderContext.SetFont(aBackupFont);
            }
            else
            {
                aWallpaper.SetColor(rEntry.GetBackColor());
            }
        }

        // draw background
        if (!(nTreeFlags & SvTreeFlags::USESEL))
        {
            aRect.SetPos(aEntryPos);
            aRect.SetSize(aRectSize);

            Color aBackgroundColor = aWallpaper.GetColor();
            if (aBackgroundColor != COL_TRANSPARENT)
            {
                rRenderContext.SetFillColor(aBackgroundColor);
                // this case may occur for smaller horizontal resizes
                if (aRect.Left() < aRect.Right())
                    rRenderContext.DrawRect(aRect);
            }
        }

        // center vertically
        aEntryPos.AdjustY((nTempEntryHeight - nItemHeight) / 2 );

        // draw item
        pViewDataEntry->SetPaintRectangle(aRect);

        aEntryPos.AdjustY(15 );

        pItem->Paint(aEntryPos, *this, rRenderContext, pViewDataEntry, rEntry);

        rRenderContext.SetFillColor(aBackupColor);

        nCurItem++;
    }

    // draw icon
    if(nIconItem != nItemCount && nIconItem < nItemCount)
    {
        SvLBoxItem* pItem = &rEntry.GetItem(nIconItem);
        auto nItemWidth = pItem->GetWidth(this, pViewDataEntry, nIconItem);
        auto nItemHeight = SvLBoxItem::GetHeight(pViewDataEntry, nIconItem);

        aEntryPos.setX( nX );
        aEntryPos.setY( nY );

        // center horizontally
        aEntryPos.AdjustX((nTempEntryWidth - nItemWidth) / 2 );
        // center vertically
        aEntryPos.AdjustY((nTempEntryHeight - nItemHeight) / 2 );

        aEntryPos.AdjustY( -10 );

        pItem->Paint(aEntryPos, *this, rRenderContext, pViewDataEntry, rEntry);
    }

    if (bCurFontIsSel)
    {
        rRenderContext.SetTextColor(aBackupTextColor);
        rRenderContext.SetFont(aBackupFont);
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */