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  : SvtValueSet(std::move(pWindow))
28  , aIconSize(60, 64)
29 {
30  SetEdgeBlending(true);
31  SetExtraSpacing(4);
32 }
33 
35 {
36  DrawLayout();
37  WinBits aWinBits(GetStyle());
38  aWinBits |= WB_VSCROLL;
39  SetStyle(aWinBits);
41 }
42 
44 {
45  if (rEvent.GetCommand() != CommandEventId::ContextMenu)
46  return CustomWidgetController::Command(rEvent);
47  const sal_uInt16 nIndex = GetSelectedItemId();
48  if(nIndex > 0)
49  {
50  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDrawingArea(), "svx/ui/presetmenu.ui"));
51  std::unique_ptr<weld::Menu> xMenu(xBuilder->weld_menu("menu"));
52  OnMenuItemSelected(xMenu->popup_at_rect(GetDrawingArea(), tools::Rectangle(rEvent.GetMousePosPixel(), Size(1,1))));
53  return true;
54  }
55  return false;
56 }
57 
59 {
61  SetLineCount(5);
62 }
63 
64 template< typename ListType, typename EntryType >
65 void SvxPresetListBox::FillPresetListBoxImpl(ListType & pList, sal_uInt32 nStartIndex)
66 {
67  const Size aSize( GetIconSize() );
68  BitmapEx aBitmap;
69  for(long nIndex = 0; nIndex < pList.Count(); nIndex++, nStartIndex++)
70  {
71  aBitmap = pList.GetBitmapForPreview(nIndex, aSize);
72  EntryType* pItem = static_cast<EntryType*>( pList.Get(nIndex) );
73  InsertItem(nStartIndex, Image(aBitmap), pItem->GetName());
74  }
75 }
76 
77 void SvxPresetListBox::FillPresetListBox(XGradientList& pList, sal_uInt32 nStartIndex)
78 {
79  FillPresetListBoxImpl< XGradientList, XGradientEntry>( pList, nStartIndex );
80 }
81 
82 void SvxPresetListBox::FillPresetListBox(XHatchList& pList, sal_uInt32 nStartIndex)
83 {
84  FillPresetListBoxImpl< XHatchList, XHatchEntry>( pList, nStartIndex );
85 }
86 
87 void SvxPresetListBox::FillPresetListBox(XBitmapList& pList, sal_uInt32 nStartIndex)
88 {
89  FillPresetListBoxImpl< XBitmapList, XBitmapEntry >( pList, nStartIndex );
90 }
91 
92 void SvxPresetListBox::FillPresetListBox(XPatternList& pList, sal_uInt32 nStartIndex)
93 {
94  FillPresetListBoxImpl< XPatternList, XBitmapEntry >( pList, nStartIndex );
95 }
96 
97 void SvxPresetListBox::OnMenuItemSelected(const OString& rIdent)
98 {
99  if (rIdent == "rename")
100  maRenameHdl.Call(this);
101  else if (rIdent == "delete")
102  maDeleteHdl.Call(this);
103 }
104 
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nIndex
void FillPresetListBoxImpl(ListType &pList, sal_uInt32 nStartIndex)
EntryType
WinBits const WB_VSCROLL
virtual void Resize() override
WinBits GetStyle() const
sal_Int64 WinBits
void SetEdgeBlending(bool bNew)
SvxPresetListBox(std::unique_ptr< weld::ScrolledWindow > pWindow)
sal_uInt16 GetSelectedItemId() const
void SetStyle(WinBits nStyle)
virtual void Resize() override
CommandEventId GetCommand() const
Link< SvxPresetListBox *, void > maDeleteHdl
const Point & GetMousePosPixel() const
void FillPresetListBox(XGradientList &pList, sal_uInt32 nStartIndex=1)
void SetExtraSpacing(sal_uInt16 nNewSpacing)
void OnMenuItemSelected(const OString &rIdent)
void SetLineCount(sal_uInt16 nNewLines=0)
Size const & GetIconSize() const
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
void SetColCount(sal_uInt16 nNewCols=1)
virtual bool Command(const CommandEvent &rEvent) override
void InsertItem(sal_uInt16 nItemId, const Image &rImage)
Link< SvxPresetListBox *, void > maRenameHdl
static constexpr sal_uInt32 nColCount