summaryrefslogtreecommitdiff
path: root/sfx2/source/control/templateview.cxx
blob: 4a44ea0d6004b3b8fca891a8979f5a809e3e05b9 (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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * Copyright 2012 LibreOffice contributors.
 *
 * 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/.
 */

#include "templatedlg.hxx"
#include <sfx2/templateview.hxx>

#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/range/b2drange.hxx>
#include <basegfx/vector/b2dvector.hxx>
#include <drawinglayer/attribute/fillbitmapattribute.hxx>
#include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
#include <drawinglayer/primitive2d/textlayoutdevice.hxx>
#include <drawinglayer/primitive2d/textprimitive2d.hxx>
#include <drawinglayer/processor2d/baseprocessor2d.hxx>
#include <sfx2/sfxresid.hxx>
#include <sfx2/templateviewitem.hxx>
#include <vcl/edit.hxx>

#include "templateview.hrc"

#define EDIT_HEIGHT 30

using namespace basegfx;
using namespace basegfx::tools;
using namespace drawinglayer::attribute;
using namespace drawinglayer::primitive2d;

TemplateView::TemplateView (Window *pParent)
    : ThumbnailView(pParent,WB_VSCROLL),
      maButtons(this, SfxResId(CONTROL_BUTTONS)),
      maAllButton(&maButtons, SfxResId(BTN_ALL_TEMPLATES)),
      maFTName(&maButtons, SfxResId(FT_NAME)),
      mnId(0)
{
    mnHeaderHeight = maButtons.GetSizePixel().getHeight();
    maAllButton.SetStyle(maAllButton.GetStyle() | WB_FLATBUTTON);
}

TemplateView::~TemplateView ()
{
}

void TemplateView::setName (const OUString &rName)
{
    maName = rName;
    maFTName.SetText(maName);
}

void TemplateView::InsertItems (const std::vector<TemplateItemProperties> &rTemplates)
{
    for (size_t i = 0, n = rTemplates.size(); i < n; ++i )
    {
        TemplateViewItem *pItem = new TemplateViewItem(*this);
        const TemplateItemProperties *pCur = &rTemplates[i];

        pItem->mnId = pCur->nId;
        pItem->maTitle = pCur->aName;
        pItem->setPath(pCur->aPath);
        pItem->maPreview1 = pCur->aThumbnail;
        if ( pCur->aThumbnail.IsEmpty() )
        {
            // Use the default thumbnail if we have nothing else
            pItem->maPreview1 = SfxTemplateManagerDlg::getDefaultThumbnail( pItem->getPath() );
        }
        pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));

        mItemList.push_back(pItem);
    }

    CalculateItemPositions();

    Invalidate();
}

void TemplateView::Resize()
{
    Size aWinSize = GetOutputSize();

    // Set the buttons panel and buttons size
    Size aPanelSize = maButtons.GetSizePixel();
    int nDeltaW = aWinSize.getWidth() - aPanelSize.getWidth();
    aPanelSize.setWidth(aWinSize.getWidth());
    maButtons.SetSizePixel(aPanelSize);

    Size aNameSize = maFTName.GetSizePixel();
    aNameSize.setWidth(aNameSize.getWidth() + nDeltaW);
    maFTName.SetSizePixel(aNameSize);

    ThumbnailView::Resize();
}

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