tdf#161412 - UI: fix warning in PDF password dialog didn't disappear
[LibreOffice.git] / svx / source / tbxctrls / SvxPresetListBox.cxx
blob39b34e9ae476225db5e14c619674adfb8e941d85
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)
29 , mnContextMenuItemId(0)
31 SetEdgeBlending(true);
34 void SvxPresetListBox::SetDrawingArea(weld::DrawingArea* pDrawingArea)
36 ValueSet::SetDrawingArea(pDrawingArea);
37 SetStyle(GetStyle() | WB_ITEMBORDER);
40 void SvxPresetListBox::Resize()
42 DrawLayout();
43 WinBits aWinBits(GetStyle());
44 aWinBits |= WB_VSCROLL;
45 SetStyle(aWinBits);
46 ValueSet::Resize();
49 bool SvxPresetListBox::Command(const CommandEvent& rEvent)
51 if (rEvent.GetCommand() != CommandEventId::ContextMenu)
52 return CustomWidgetController::Command(rEvent);
53 mnContextMenuItemId = GetHighlightedItemId();
54 if (mnContextMenuItemId > 0)
56 std::unique_ptr<weld::Builder> xBuilder(
57 Application::CreateBuilder(GetDrawingArea(), u"svx/ui/presetmenu.ui"_ustr));
58 std::unique_ptr<weld::Menu> xMenu(xBuilder->weld_menu(u"menu"_ustr));
59 OnMenuItemSelected(xMenu->popup_at_rect(
60 GetDrawingArea(), tools::Rectangle(rEvent.GetMousePosPixel(), Size(1, 1))));
62 mnContextMenuItemId = 0;
63 return true;
65 return false;
68 void SvxPresetListBox::DrawLayout()
70 SetColCount(nColCount);
71 SetLineCount(5);
74 template <typename ListType, typename EntryType>
75 void SvxPresetListBox::FillPresetListBoxImpl(ListType& pList, sal_uInt32 nStartIndex)
77 const Size aSize(GetIconSize());
78 BitmapEx aBitmap;
79 for (tools::Long nIndex = 0; nIndex < pList.Count(); nIndex++, nStartIndex++)
81 aBitmap = pList.GetBitmapForPreview(nIndex, aSize);
82 EntryType* pItem = static_cast<EntryType*>(pList.Get(nIndex));
83 InsertItem(nStartIndex, Image(aBitmap), pItem->GetName());
87 void SvxPresetListBox::FillPresetListBox(XGradientList& pList, sal_uInt32 nStartIndex)
89 FillPresetListBoxImpl<XGradientList, XGradientEntry>(pList, nStartIndex);
92 void SvxPresetListBox::FillPresetListBox(XHatchList& pList, sal_uInt32 nStartIndex)
94 FillPresetListBoxImpl<XHatchList, XHatchEntry>(pList, nStartIndex);
97 void SvxPresetListBox::FillPresetListBox(XBitmapList& pList, sal_uInt32 nStartIndex)
99 FillPresetListBoxImpl<XBitmapList, XBitmapEntry>(pList, nStartIndex);
102 void SvxPresetListBox::FillPresetListBox(XPatternList& pList, sal_uInt32 nStartIndex)
104 FillPresetListBoxImpl<XPatternList, XBitmapEntry>(pList, nStartIndex);
107 void SvxPresetListBox::OnMenuItemSelected(std::u16string_view rIdent)
109 if (rIdent == u"rename")
110 maRenameHdl.Call(this);
111 else if (rIdent == u"delete")
112 maDeleteHdl.Call(this);
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */