LibreOffice Module svx (master) 1
SvxPresetListBox.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
21#include <svx/xtable.hxx>
22#include <vcl/commandevent.hxx>
23#include <vcl/image.hxx>
24#include <vcl/svapp.hxx>
25
26SvxPresetListBox::SvxPresetListBox(std::unique_ptr<weld::ScrolledWindow> pWindow)
27 : ValueSet(std::move(pWindow))
28 , aIconSize(60, 64)
29{
30 SetEdgeBlending(true);
31}
32
34{
35 ValueSet::SetDrawingArea(pDrawingArea);
37}
38
40{
41 DrawLayout();
42 WinBits aWinBits(GetStyle());
43 aWinBits |= WB_VSCROLL;
44 SetStyle(aWinBits);
46}
47
49{
50 if (rEvent.GetCommand() != CommandEventId::ContextMenu)
51 return CustomWidgetController::Command(rEvent);
52 const sal_uInt16 nIndex = GetSelectedItemId();
53 if (nIndex > 0)
54 {
55 std::unique_ptr<weld::Builder> xBuilder(
56 Application::CreateBuilder(GetDrawingArea(), "svx/ui/presetmenu.ui"));
57 std::unique_ptr<weld::Menu> xMenu(xBuilder->weld_menu("menu"));
58 OnMenuItemSelected(xMenu->popup_at_rect(
59 GetDrawingArea(), tools::Rectangle(rEvent.GetMousePosPixel(), Size(1, 1))));
60 return true;
61 }
62 return false;
63}
64
66{
68 SetLineCount(5);
69}
70
71template <typename ListType, typename EntryType>
72void SvxPresetListBox::FillPresetListBoxImpl(ListType& pList, sal_uInt32 nStartIndex)
73{
74 const Size aSize(GetIconSize());
75 BitmapEx aBitmap;
76 for (tools::Long nIndex = 0; nIndex < pList.Count(); nIndex++, nStartIndex++)
77 {
78 aBitmap = pList.GetBitmapForPreview(nIndex, aSize);
79 EntryType* pItem = static_cast<EntryType*>(pList.Get(nIndex));
80 InsertItem(nStartIndex, Image(aBitmap), pItem->GetName());
81 }
82}
83
84void SvxPresetListBox::FillPresetListBox(XGradientList& pList, sal_uInt32 nStartIndex)
85{
86 FillPresetListBoxImpl<XGradientList, XGradientEntry>(pList, nStartIndex);
87}
88
89void SvxPresetListBox::FillPresetListBox(XHatchList& pList, sal_uInt32 nStartIndex)
90{
91 FillPresetListBoxImpl<XHatchList, XHatchEntry>(pList, nStartIndex);
92}
93
94void SvxPresetListBox::FillPresetListBox(XBitmapList& pList, sal_uInt32 nStartIndex)
95{
96 FillPresetListBoxImpl<XBitmapList, XBitmapEntry>(pList, nStartIndex);
97}
98
99void SvxPresetListBox::FillPresetListBox(XPatternList& pList, sal_uInt32 nStartIndex)
100{
101 FillPresetListBoxImpl<XPatternList, XBitmapEntry>(pList, nStartIndex);
102}
103
104void SvxPresetListBox::OnMenuItemSelected(std::u16string_view rIdent)
105{
106 if (rIdent == u"rename")
107 maRenameHdl.Call(this);
108 else if (rIdent == u"delete")
109 maDeleteHdl.Call(this);
110}
111
112/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
Size const & GetIconSize() const
virtual void Resize() override
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
void FillPresetListBox(XGradientList &pList, sal_uInt32 nStartIndex=1)
virtual bool Command(const CommandEvent &rEvent) override
SvxPresetListBox(std::unique_ptr< weld::ScrolledWindow > pWindow)
Link< SvxPresetListBox *, void > maRenameHdl
static constexpr sal_uInt32 nColCount
void OnMenuItemSelected(std::u16string_view rIdent)
void FillPresetListBoxImpl(ListType &pList, sal_uInt32 nStartIndex)
Link< SvxPresetListBox *, void > maDeleteHdl
void InsertItem(sal_uInt16 nItemId, const Image &rImage)
void SetEdgeBlending(bool bNew)
void SetStyle(WinBits nStyle)
sal_uInt16 GetSelectedItemId() const
void SetLineCount(sal_uInt16 nNewLines=0)
WinBits GetStyle() const
void SetColCount(sal_uInt16 nNewCols=1)
virtual void Resize() override
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
float u
sal_Int32 nIndex
EntryType
long Long
#define WB_ITEMBORDER
sal_Int64 WinBits
WinBits const WB_VSCROLL