1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #include <DefaultShapesPanel.hxx>
21 #include <com/sun/star/lang/IllegalArgumentException.hpp>
22 #include <comphelper/dispatchcommand.hxx>
24 #include <vcl/commandinfoprovider.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/svapp.hxx>
28 namespace svx::sidebar
{
30 DefaultShapesPanel::DefaultShapesPanel (
31 weld::Widget
* pParent
,
32 css::uno::Reference
<css::frame::XFrame
> xFrame
)
33 : PanelLayout(pParent
, u
"DefaultShapesPanel"_ustr
, u
"svx/ui/defaultshapespanel.ui"_ustr
)
34 , mxLineArrowSet(new ValueSet(nullptr))
35 , mxLineArrowSetWin(new weld::CustomWeld(*m_xBuilder
, u
"LinesArrows"_ustr
, *mxLineArrowSet
))
36 , mxCurveSet(new ValueSet(nullptr))
37 , mxCurveSetWin(new weld::CustomWeld(*m_xBuilder
, u
"Curves"_ustr
, *mxCurveSet
))
38 , mxConnectorSet(new ValueSet(nullptr))
39 , mxConnectorSetWin(new weld::CustomWeld(*m_xBuilder
, u
"Connectors"_ustr
, *mxConnectorSet
))
40 , mxBasicShapeSet(new ValueSet(nullptr))
41 , mxBasicShapeSetWin(new weld::CustomWeld(*m_xBuilder
, u
"BasicShapes"_ustr
, *mxBasicShapeSet
))
42 , mxSymbolShapeSet(new ValueSet(nullptr))
43 , mxSymbolShapeSetWin(new weld::CustomWeld(*m_xBuilder
, u
"SymbolShapes"_ustr
, *mxSymbolShapeSet
))
44 , mxBlockArrowSet(new ValueSet(nullptr))
45 , mxBlockArrowSetWin(new weld::CustomWeld(*m_xBuilder
, u
"BlockArrows"_ustr
, *mxBlockArrowSet
))
46 , mxFlowchartSet(new ValueSet(nullptr))
47 , mxFlowchartSetWin(new weld::CustomWeld(*m_xBuilder
, u
"Flowcharts"_ustr
, *mxFlowchartSet
))
48 , mxCalloutSet(new ValueSet(nullptr))
49 , mxCalloutSetWin(new weld::CustomWeld(*m_xBuilder
, u
"Callouts"_ustr
, *mxCalloutSet
))
50 , mxStarSet(new ValueSet(nullptr))
51 , mxStarSetWin(new weld::CustomWeld(*m_xBuilder
, u
"Stars"_ustr
, *mxStarSet
))
52 , mx3DObjectSet(new ValueSet(nullptr))
53 , mx3DObjectSetWin(new weld::CustomWeld(*m_xBuilder
, u
"3DObjects"_ustr
, *mx3DObjectSet
))
54 , mxFrame(std::move(xFrame
))
57 pParent
->set_size_request(pParent
->get_approximate_digit_width() * 20, -1);
58 m_xContainer
->set_size_request(m_xContainer
->get_approximate_digit_width() * 25, -1);
61 std::unique_ptr
<PanelLayout
> DefaultShapesPanel::Create(
62 weld::Widget
* pParent
,
63 const Reference
< XFrame
>& rxFrame
)
65 if (pParent
== nullptr)
66 throw lang::IllegalArgumentException(u
"no parent Window given to DefaultShapesPanel::Create"_ustr
, nullptr, 0);
68 throw lang::IllegalArgumentException(u
"no XFrame given to DefaultShapesPanel::Create"_ustr
, nullptr, 1);
70 return std::make_unique
<DefaultShapesPanel
>(pParent
, rxFrame
);
73 void DefaultShapesPanel::Initialize()
75 mpShapesSetMap
= decltype(mpShapesSetMap
){
76 { mxLineArrowSet
.get(), mpLineShapes
},
77 { mxCurveSet
.get(), mpCurveShapes
},
78 { mxConnectorSet
.get(), mpConnectorShapes
},
79 { mxBasicShapeSet
.get(), mpBasicShapes
},
80 { mxSymbolShapeSet
.get(), mpSymbolShapes
},
81 { mxBlockArrowSet
.get(), mpBlockArrowShapes
},
82 { mxFlowchartSet
.get(), mpFlowchartShapes
},
83 { mxCalloutSet
.get(), mpCalloutShapes
},
84 { mxStarSet
.get(), mpStarShapes
},
85 { mx3DObjectSet
.get(), mp3DShapes
}
88 for(auto& aSetMap
: mpShapesSetMap
)
90 aSetMap
.first
->SetColor(Application::GetSettings().GetStyleSettings().GetDialogColor());
91 aSetMap
.first
->SetSelectHdl(LINK(this, DefaultShapesPanel
, ShapeSelectHdl
));
95 DefaultShapesPanel::~DefaultShapesPanel()
97 mpShapesSetMap
.clear();
98 mxLineArrowSetWin
.reset();
99 mxLineArrowSet
.reset();
100 mxCurveSetWin
.reset();
102 mxConnectorSetWin
.reset();
103 mxConnectorSet
.reset();
104 mxBasicShapeSetWin
.reset();
105 mxBasicShapeSet
.reset();
106 mxSymbolShapeSetWin
.reset();
107 mxSymbolShapeSet
.reset();
108 mxBlockArrowSetWin
.reset();
109 mxBlockArrowSet
.reset();
110 mxFlowchartSetWin
.reset();
111 mxFlowchartSet
.reset();
112 mxCalloutSetWin
.reset();
113 mxCalloutSet
.reset();
114 mxStarSetWin
.reset();
116 mx3DObjectSetWin
.reset();
117 mx3DObjectSet
.reset();
120 IMPL_LINK(DefaultShapesPanel
, ShapeSelectHdl
, ValueSet
*, rValueSet
, void)
122 for(auto& aSetMap
: mpShapesSetMap
)
124 if(rValueSet
== aSetMap
.first
)
126 sal_uInt16 nSelectionId
= aSetMap
.first
->GetSelectedItemId();
127 comphelper::dispatchCommand(aSetMap
.second
[nSelectionId
- 1], {});
130 aSetMap
.first
->SetNoSelection();
134 void DefaultShapesPanel::populateShapes()
136 OUString sSlotStr
, sLabel
;
138 for(auto& aSet
: mpShapesSetMap
)
140 aSet
.first
->SetColCount(6);
141 for(std::map
<sal_uInt16
, OUString
>::size_type i
= 0; i
< aSet
.second
.size(); i
++)
143 sSlotStr
= aSet
.second
[i
];
144 aSlotImage
= vcl::CommandInfoProvider::GetImageForCommand(sSlotStr
, mxFrame
);
145 auto aProperties
= vcl::CommandInfoProvider::GetCommandProperties(sSlotStr
,
146 vcl::CommandInfoProvider::GetModuleIdentifier(mxFrame
));
147 sLabel
= vcl::CommandInfoProvider::GetTooltipForCommand(sSlotStr
, aProperties
, mxFrame
);
148 sal_uInt16 nSelectionId
= i
+ 1; // tdf#142767 id 0 is reserved for nothing-selected
149 aSet
.first
->InsertItem(nSelectionId
, aSlotImage
, sLabel
);
154 } // end of namespace svx::sidebar
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */