Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / tbxctrls / SvxPresetListBox.cxx
blobbbbfa736345208b9e3a7da8d049efec7dda49467
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/SvxPresetListBox.hxx>
21 #include <svx/xtable.hxx>
22 #include <vcl/commandevent.hxx>
23 #include <vcl/image.hxx>
24 #include <vcl/svapp.hxx>
26 SvxPresetListBox::SvxPresetListBox(std::unique_ptr<weld::ScrolledWindow> pWindow)
27 : ValueSet(std::move(pWindow))
28 , aIconSize(60, 64)
30 SetEdgeBlending(true);
33 void SvxPresetListBox::SetDrawingArea(weld::DrawingArea* pDrawingArea)
35 ValueSet::SetDrawingArea(pDrawingArea);
36 SetStyle(GetStyle() | WB_ITEMBORDER);
39 void SvxPresetListBox::Resize()
41 DrawLayout();
42 WinBits aWinBits(GetStyle());
43 aWinBits |= WB_VSCROLL;
44 SetStyle(aWinBits);
45 ValueSet::Resize();
48 bool SvxPresetListBox::Command(const CommandEvent& rEvent)
50 if (rEvent.GetCommand() != CommandEventId::ContextMenu)
51 return CustomWidgetController::Command(rEvent);
52 const sal_uInt16 nIndex = GetSelectedItemId();
53 if (nIndex > 0)
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;
62 return false;
65 void SvxPresetListBox::DrawLayout()
67 SetColCount(nColCount);
68 SetLineCount(5);
71 template <typename ListType, typename EntryType>
72 void SvxPresetListBox::FillPresetListBoxImpl(ListType& pList, sal_uInt32 nStartIndex)
74 const Size aSize(GetIconSize());
75 BitmapEx aBitmap;
76 for (tools::Long nIndex = 0; nIndex < pList.Count(); nIndex++, nStartIndex++)
78 aBitmap = pList.GetBitmapForPreview(nIndex, aSize);
79 EntryType* pItem = static_cast<EntryType*>(pList.Get(nIndex));
80 InsertItem(nStartIndex, Image(aBitmap), pItem->GetName());
84 void SvxPresetListBox::FillPresetListBox(XGradientList& pList, sal_uInt32 nStartIndex)
86 FillPresetListBoxImpl<XGradientList, XGradientEntry>(pList, nStartIndex);
89 void SvxPresetListBox::FillPresetListBox(XHatchList& pList, sal_uInt32 nStartIndex)
91 FillPresetListBoxImpl<XHatchList, XHatchEntry>(pList, nStartIndex);
94 void SvxPresetListBox::FillPresetListBox(XBitmapList& pList, sal_uInt32 nStartIndex)
96 FillPresetListBoxImpl<XBitmapList, XBitmapEntry>(pList, nStartIndex);
99 void SvxPresetListBox::FillPresetListBox(XPatternList& pList, sal_uInt32 nStartIndex)
101 FillPresetListBoxImpl<XPatternList, XBitmapEntry>(pList, nStartIndex);
104 void SvxPresetListBox::OnMenuItemSelected(std::u16string_view rIdent)
106 if (rIdent == u"rename")
107 maRenameHdl.Call(this);
108 else if (rIdent == u"delete")
109 maDeleteHdl.Call(this);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */