LibreOffice Module svx (master)  1
DefaultShapesPanel.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 #include <DefaultShapesPanel.hxx>
20 
21 #include <com/sun/star/lang/IllegalArgumentException.hpp>
24 #include <vcl/settings.hxx>
25 #include <vcl/svapp.hxx>
26 
27 namespace svx::sidebar {
28 
30  weld::Widget* pParent,
31  const css::uno::Reference<css::frame::XFrame>& rxFrame)
32  : PanelLayout(pParent, "DefaultShapesPanel", "svx/ui/defaultshapespanel.ui")
33  , mxLineArrowSet(new ValueSet(nullptr))
34  , mxLineArrowSetWin(new weld::CustomWeld(*m_xBuilder, "LinesArrows", *mxLineArrowSet))
35  , mxCurveSet(new ValueSet(nullptr))
36  , mxCurveSetWin(new weld::CustomWeld(*m_xBuilder, "Curves", *mxCurveSet))
37  , mxConnectorSet(new ValueSet(nullptr))
38  , mxConnectorSetWin(new weld::CustomWeld(*m_xBuilder, "Connectors", *mxConnectorSet))
39  , mxBasicShapeSet(new ValueSet(nullptr))
40  , mxBasicShapeSetWin(new weld::CustomWeld(*m_xBuilder, "BasicShapes", *mxBasicShapeSet))
41  , mxSymbolShapeSet(new ValueSet(nullptr))
42  , mxSymbolShapeSetWin(new weld::CustomWeld(*m_xBuilder, "SymbolShapes", *mxSymbolShapeSet))
43  , mxBlockArrowSet(new ValueSet(nullptr))
44  , mxBlockArrowSetWin(new weld::CustomWeld(*m_xBuilder, "BlockArrows", *mxBlockArrowSet))
45  , mxFlowchartSet(new ValueSet(nullptr))
46  , mxFlowchartSetWin(new weld::CustomWeld(*m_xBuilder, "Flowcharts", *mxFlowchartSet))
47  , mxCalloutSet(new ValueSet(nullptr))
48  , mxCalloutSetWin(new weld::CustomWeld(*m_xBuilder, "Callouts", *mxCalloutSet))
49  , mxStarSet(new ValueSet(nullptr))
50  , mxStarSetWin(new weld::CustomWeld(*m_xBuilder, "Stars", *mxStarSet))
51  , mx3DObjectSet(new ValueSet(nullptr))
52  , mx3DObjectSetWin(new weld::CustomWeld(*m_xBuilder, "3DObjects", *mx3DObjectSet))
53  , mxFrame(rxFrame)
54 {
55  Initialize();
56 }
57 
58 std::unique_ptr<PanelLayout> DefaultShapesPanel::Create(
59  weld::Widget* pParent,
60  const Reference< XFrame >& rxFrame)
61 {
62  if (pParent == nullptr)
63  throw lang::IllegalArgumentException("no parent Window given to DefaultShapesPanel::Create", nullptr, 0);
64  if ( ! rxFrame.is())
65  throw lang::IllegalArgumentException("no XFrame given to DefaultShapesPanel::Create", nullptr, 1);
66 
67  return std::make_unique<DefaultShapesPanel>(pParent, rxFrame);
68 }
69 
71 {
72  mpShapesSetMap = decltype(mpShapesSetMap){
73  { mxLineArrowSet.get(), mpLineShapes },
74  { mxCurveSet.get(), mpCurveShapes },
76  { mxBasicShapeSet.get(), mpBasicShapes },
80  { mxCalloutSet.get(), mpCalloutShapes },
81  { mxStarSet.get(), mpStarShapes },
82  { mx3DObjectSet.get(), mp3DShapes }
83  };
85  for(auto& aSetMap: mpShapesSetMap)
86  {
87  aSetMap.first->SetColor(Application::GetSettings().GetStyleSettings().GetDialogColor());
88  aSetMap.first->SetSelectHdl(LINK(this, DefaultShapesPanel, ShapeSelectHdl));
89  }
90 }
91 
93 {
94  mpShapesSetMap.clear();
95  mxLineArrowSetWin.reset();
96  mxLineArrowSet.reset();
97  mxCurveSetWin.reset();
98  mxCurveSet.reset();
99  mxConnectorSetWin.reset();
100  mxConnectorSet.reset();
101  mxBasicShapeSetWin.reset();
102  mxBasicShapeSet.reset();
103  mxSymbolShapeSetWin.reset();
104  mxSymbolShapeSet.reset();
105  mxBlockArrowSetWin.reset();
106  mxBlockArrowSet.reset();
107  mxFlowchartSetWin.reset();
108  mxFlowchartSet.reset();
109  mxCalloutSetWin.reset();
110  mxCalloutSet.reset();
111  mxStarSetWin.reset();
112  mxStarSet.reset();
113  mx3DObjectSetWin.reset();
114  mx3DObjectSet.reset();
115 }
116 
117 IMPL_LINK(DefaultShapesPanel, ShapeSelectHdl, ValueSet*, rValueSet, void)
118 {
119  for(auto& aSetMap : mpShapesSetMap)
120  {
121  if(rValueSet == aSetMap.first)
122  {
123  sal_uInt16 nSelectionId = aSetMap.first->GetSelectedItemId();
124  comphelper::dispatchCommand(aSetMap.second[nSelectionId - 1], {});
125  }
126  else
127  aSetMap.first->SetNoSelection();
128  }
129 }
130 
132 {
133  OUString sSlotStr, sLabel;
134  Image aSlotImage;
135  for(auto& aSet : mpShapesSetMap)
136  {
137  aSet.first->SetColCount(6);
138  for(std::map<sal_uInt16, OUString>::size_type i = 0; i < aSet.second.size(); i++)
139  {
140  sSlotStr = aSet.second[i];
145  sal_uInt16 nSelectionId = i + 1; // tdf#142767 id 0 is reserved for nothing-selected
146  aSet.first->InsertItem(nSelectionId, aSlotImage, sLabel);
147  }
148  }
149 }
150 
151 } // end of namespace svx::sidebar
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::map< sal_uInt16, OUString > mpFlowchartShapes
Definition: ShapesUtil.hxx:30
std::unique_ptr< weld::CustomWeld > mxConnectorSetWin
std::map< sal_uInt16, OUString > mpConnectorShapes
Definition: ShapesUtil.hxx:30
std::map< sal_uInt16, OUString > mpStarShapes
Definition: ShapesUtil.hxx:30
std::unique_ptr< ValueSet > mxBlockArrowSet
std::unique_ptr< weld::CustomWeld > mxSymbolShapeSetWin
std::unique_ptr< weld::CustomWeld > mxStarSetWin
std::map< sal_uInt16, OUString > mpLineShapes
Definition: ShapesUtil.hxx:30
static const AllSettings & GetSettings()
std::unique_ptr< weld::CustomWeld > mx3DObjectSetWin
std::map< sal_uInt16, OUString > mpBasicShapes
Definition: ShapesUtil.hxx:30
std::map< sal_uInt16, OUString > mpBlockArrowShapes
Definition: ShapesUtil.hxx:30
std::unique_ptr< ValueSet > mxStarSet
std::unique_ptr< weld::CustomWeld > mxLineArrowSetWin
This panel provides buttons for inserting shapes into a document.
PropertiesInfo aProperties
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
std::unique_ptr< ValueSet > mxSymbolShapeSet
std::map< sal_uInt16, OUString > mpCurveShapes
Definition: ShapesUtil.hxx:30
std::unique_ptr< weld::CustomWeld > mxBasicShapeSetWin
std::unique_ptr< ValueSet > mxLineArrowSet
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
std::unique_ptr< ValueSet > mxCalloutSet
IMPL_LINK(MediaPlaybackPanel, PlayToolBoxSelectHdl, const OString &, rId, void)
OUString GetModuleIdentifier(const Reference< frame::XFrame > &rxFrame)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame)
int i
std::unique_ptr< weld::CustomWeld > mxFlowchartSetWin
std::unique_ptr< ValueSet > mxBasicShapeSet
std::map< ValueSet *, std::map< sal_uInt16, OUString > > mpShapesSetMap
std::unique_ptr< weld::CustomWeld > mxBlockArrowSetWin
std::unique_ptr< ValueSet > mx3DObjectSet
std::unique_ptr< ValueSet > mxCurveSet
std::unique_ptr< weld::CustomWeld > mxCalloutSetWin
std::map< sal_uInt16, OUString > mpSymbolShapes
Definition: ShapesUtil.hxx:30
std::unique_ptr< weld::CustomWeld > mxCurveSetWin
Sequence< beans::PropertyValue > GetCommandProperties(const OUString &rsCommandName, const OUString &rsModuleName)
std::map< sal_uInt16, OUString > mp3DShapes
Definition: ShapesUtil.hxx:30
std::unique_ptr< ValueSet > mxConnectorSet
std::map< sal_uInt16, OUString > mpCalloutShapes
Definition: ShapesUtil.hxx:30
std::unique_ptr< ValueSet > mxFlowchartSet
DefaultShapesPanel(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame)
OUString GetTooltipForCommand(const OUString &rsCommandName, const css::uno::Sequence< css::beans::PropertyValue > &rProperties, const Reference< frame::XFrame > &rxFrame)