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 
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>
25 
26 SvxPresetListBox::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 
71 template <typename ListType, typename EntryType>
72 void 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 
84 void SvxPresetListBox::FillPresetListBox(XGradientList& pList, sal_uInt32 nStartIndex)
85 {
86  FillPresetListBoxImpl<XGradientList, XGradientEntry>(pList, nStartIndex);
87 }
88 
89 void SvxPresetListBox::FillPresetListBox(XHatchList& pList, sal_uInt32 nStartIndex)
90 {
91  FillPresetListBoxImpl<XHatchList, XHatchEntry>(pList, nStartIndex);
92 }
93 
94 void SvxPresetListBox::FillPresetListBox(XBitmapList& pList, sal_uInt32 nStartIndex)
95 {
96  FillPresetListBoxImpl<XBitmapList, XBitmapEntry>(pList, nStartIndex);
97 }
98 
99 void SvxPresetListBox::FillPresetListBox(XPatternList& pList, sal_uInt32 nStartIndex)
100 {
101  FillPresetListBoxImpl<XPatternList, XBitmapEntry>(pList, nStartIndex);
102 }
103 
104 void SvxPresetListBox::OnMenuItemSelected(std::string_view rIdent)
105 {
106  if (rIdent == "rename")
107  maRenameHdl.Call(this);
108  else if (rIdent == "delete")
109  maDeleteHdl.Call(this);
110 }
111 
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
sal_Int32 nIndex
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
long Long
void FillPresetListBoxImpl(ListType &pList, sal_uInt32 nStartIndex)
EntryType
sal_uInt16 GetSelectedItemId() const
WinBits const WB_VSCROLL
void SetStyle(WinBits nStyle)
void SetLineCount(sal_uInt16 nNewLines=0)
sal_Int64 WinBits
#define WB_ITEMBORDER
SvxPresetListBox(std::unique_ptr< weld::ScrolledWindow > pWindow)
WinBits GetStyle() const
void OnMenuItemSelected(std::string_view rIdent)
virtual void Resize() override
CommandEventId GetCommand() const
void InsertItem(sal_uInt16 nItemId, const Image &rImage)
Link< SvxPresetListBox *, void > maDeleteHdl
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
const Point & GetMousePosPixel() const
void FillPresetListBox(XGradientList &pList, sal_uInt32 nStartIndex=1)
void SetEdgeBlending(bool bNew)
Size const & GetIconSize() const
virtual void Resize() override
void SetColCount(sal_uInt16 nNewCols=1)
virtual bool Command(const CommandEvent &rEvent) override
Link< SvxPresetListBox *, void > maRenameHdl
static constexpr sal_uInt32 nColCount