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")
34  , mxLineArrowSet(new ValueSet(nullptr))
35  , mxLineArrowSetWin(new weld::CustomWeld(*m_xBuilder, "LinesArrows", *mxLineArrowSet))
36  , mxCurveSet(new ValueSet(nullptr))
37  , mxCurveSetWin(new weld::CustomWeld(*m_xBuilder, "Curves", *mxCurveSet))
38  , mxConnectorSet(new ValueSet(nullptr))
39  , mxConnectorSetWin(new weld::CustomWeld(*m_xBuilder, "Connectors", *mxConnectorSet))
40  , mxBasicShapeSet(new ValueSet(nullptr))
41  , mxBasicShapeSetWin(new weld::CustomWeld(*m_xBuilder, "BasicShapes", *mxBasicShapeSet))
42  , mxSymbolShapeSet(new ValueSet(nullptr))
43  , mxSymbolShapeSetWin(new weld::CustomWeld(*m_xBuilder, "SymbolShapes", *mxSymbolShapeSet))
44  , mxBlockArrowSet(new ValueSet(nullptr))
45  , mxBlockArrowSetWin(new weld::CustomWeld(*m_xBuilder, "BlockArrows", *mxBlockArrowSet))
46  , mxFlowchartSet(new ValueSet(nullptr))
47  , mxFlowchartSetWin(new weld::CustomWeld(*m_xBuilder, "Flowcharts", *mxFlowchartSet))
48  , mxCalloutSet(new ValueSet(nullptr))
49  , mxCalloutSetWin(new weld::CustomWeld(*m_xBuilder, "Callouts", *mxCalloutSet))
50  , mxStarSet(new ValueSet(nullptr))
51  , mxStarSetWin(new weld::CustomWeld(*m_xBuilder, "Stars", *mxStarSet))
52  , mx3DObjectSet(new ValueSet(nullptr))
53  , mx3DObjectSetWin(new weld::CustomWeld(*m_xBuilder, "3DObjects", *mx3DObjectSet))
54  , mxFrame(rxFrame)
55 {
56  Initialize();
57 }
58 
59 std::unique_ptr<PanelLayout> DefaultShapesPanel::Create(
60  weld::Widget* pParent,
61  const Reference< XFrame >& rxFrame)
62 {
63  if (pParent == nullptr)
64  throw lang::IllegalArgumentException("no parent Window given to DefaultShapesPanel::Create", nullptr, 0);
65  if ( ! rxFrame.is())
66  throw lang::IllegalArgumentException("no XFrame given to DefaultShapesPanel::Create", nullptr, 1);
67 
68  return std::make_unique<DefaultShapesPanel>(pParent, rxFrame);
69 }
70 
72 {
73  mpShapesSetMap = decltype(mpShapesSetMap){
74  { mxLineArrowSet.get(), mpLineShapes },
75  { mxCurveSet.get(), mpCurveShapes },
77  { mxBasicShapeSet.get(), mpBasicShapes },
81  { mxCalloutSet.get(), mpCalloutShapes },
82  { mxStarSet.get(), mpStarShapes },
83  { mx3DObjectSet.get(), mp3DShapes }
84  };
86  for(auto& aSetMap: mpShapesSetMap)
87  {
88  aSetMap.first->SetColor(Application::GetSettings().GetStyleSettings().GetDialogColor());
89  aSetMap.first->SetSelectHdl(LINK(this, DefaultShapesPanel, ShapeSelectHdl));
90  }
91 }
92 
94 {
95  mpShapesSetMap.clear();
96  mxLineArrowSetWin.reset();
97  mxLineArrowSet.reset();
98  mxCurveSetWin.reset();
99  mxCurveSet.reset();
100  mxConnectorSetWin.reset();
101  mxConnectorSet.reset();
102  mxBasicShapeSetWin.reset();
103  mxBasicShapeSet.reset();
104  mxSymbolShapeSetWin.reset();
105  mxSymbolShapeSet.reset();
106  mxBlockArrowSetWin.reset();
107  mxBlockArrowSet.reset();
108  mxFlowchartSetWin.reset();
109  mxFlowchartSet.reset();
110  mxCalloutSetWin.reset();
111  mxCalloutSet.reset();
112  mxStarSetWin.reset();
113  mxStarSet.reset();
114  mx3DObjectSetWin.reset();
115  mx3DObjectSet.reset();
116 }
117 
118 IMPL_LINK(DefaultShapesPanel, ShapeSelectHdl, ValueSet*, rValueSet, void)
119 {
120  for(auto& aSetMap : mpShapesSetMap)
121  {
122  if(rValueSet == aSetMap.first)
123  {
124  sal_uInt16 nSelectionId = aSetMap.first->GetSelectedItemId();
125  comphelper::dispatchCommand(aSetMap.second[nSelectionId - 1], {});
126  }
127  else
128  aSetMap.first->SetNoSelection();
129  }
130 }
131 
133 {
134  OUString sSlotStr, sLabel;
135  Image aSlotImage;
136  for(auto& aSet : mpShapesSetMap)
137  {
138  aSet.first->SetColCount(6);
139  for(std::map<sal_uInt16, OUString>::size_type i = 0; i < aSet.second.size(); i++)
140  {
141  sSlotStr = aSet.second[i];
146  sal_uInt16 nSelectionId = i + 1; // tdf#142767 id 0 is reserved for nothing-selected
147  aSet.first->InsertItem(nSelectionId, aSlotImage, sLabel);
148  }
149  }
150 }
151 
152 } // end of namespace svx::sidebar
153 
154 /* 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)