/src/libreoffice/svx/source/sidebar/shapes/DefaultShapesPanel.cxx
Line | Count | Source |
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> |
22 | | #include <comphelper/dispatchcommand.hxx> |
23 | | #include <utility> |
24 | | #include <vcl/commandinfoprovider.hxx> |
25 | | #include <vcl/settings.hxx> |
26 | | #include <vcl/svapp.hxx> |
27 | | |
28 | | namespace svx::sidebar { |
29 | | |
30 | | DefaultShapesPanel::DefaultShapesPanel ( |
31 | | weld::Widget* pParent, |
32 | | css::uno::Reference<css::frame::XFrame> xFrame) |
33 | 0 | : PanelLayout(pParent, u"DefaultShapesPanel"_ustr, u"svx/ui/defaultshapespanel.ui"_ustr) |
34 | 0 | , mxLineArrowSet(new ValueSet(nullptr)) |
35 | 0 | , mxLineArrowSetWin(new weld::CustomWeld(*m_xBuilder, u"LinesArrows"_ustr, *mxLineArrowSet)) |
36 | 0 | , mxCurveSet(new ValueSet(nullptr)) |
37 | 0 | , mxCurveSetWin(new weld::CustomWeld(*m_xBuilder, u"Curves"_ustr, *mxCurveSet)) |
38 | 0 | , mxConnectorSet(new ValueSet(nullptr)) |
39 | 0 | , mxConnectorSetWin(new weld::CustomWeld(*m_xBuilder, u"Connectors"_ustr, *mxConnectorSet)) |
40 | 0 | , mxBasicShapeSet(new ValueSet(nullptr)) |
41 | 0 | , mxBasicShapeSetWin(new weld::CustomWeld(*m_xBuilder, u"BasicShapes"_ustr, *mxBasicShapeSet)) |
42 | 0 | , mxSymbolShapeSet(new ValueSet(nullptr)) |
43 | 0 | , mxSymbolShapeSetWin(new weld::CustomWeld(*m_xBuilder, u"SymbolShapes"_ustr, *mxSymbolShapeSet)) |
44 | 0 | , mxBlockArrowSet(new ValueSet(nullptr)) |
45 | 0 | , mxBlockArrowSetWin(new weld::CustomWeld(*m_xBuilder, u"BlockArrows"_ustr, *mxBlockArrowSet)) |
46 | 0 | , mxFlowchartSet(new ValueSet(nullptr)) |
47 | 0 | , mxFlowchartSetWin(new weld::CustomWeld(*m_xBuilder, u"Flowcharts"_ustr, *mxFlowchartSet)) |
48 | 0 | , mxCalloutSet(new ValueSet(nullptr)) |
49 | 0 | , mxCalloutSetWin(new weld::CustomWeld(*m_xBuilder, u"Callouts"_ustr, *mxCalloutSet)) |
50 | 0 | , mxStarSet(new ValueSet(nullptr)) |
51 | 0 | , mxStarSetWin(new weld::CustomWeld(*m_xBuilder, u"Stars"_ustr, *mxStarSet)) |
52 | 0 | , mx3DObjectSet(new ValueSet(nullptr)) |
53 | 0 | , mx3DObjectSetWin(new weld::CustomWeld(*m_xBuilder, u"3DObjects"_ustr, *mx3DObjectSet)) |
54 | 0 | , mxFrame(std::move(xFrame)) |
55 | 0 | { |
56 | 0 | Initialize(); |
57 | 0 | pParent->set_size_request(pParent->get_approximate_digit_width() * 20, -1); |
58 | 0 | m_xContainer->set_size_request(m_xContainer->get_approximate_digit_width() * 25, -1); |
59 | 0 | } |
60 | | |
61 | | std::unique_ptr<PanelLayout> DefaultShapesPanel::Create( |
62 | | weld::Widget* pParent, |
63 | | const Reference< XFrame >& rxFrame) |
64 | 0 | { |
65 | 0 | if (pParent == nullptr) |
66 | 0 | throw lang::IllegalArgumentException(u"no parent Window given to DefaultShapesPanel::Create"_ustr, nullptr, 0); |
67 | 0 | if ( ! rxFrame.is()) |
68 | 0 | throw lang::IllegalArgumentException(u"no XFrame given to DefaultShapesPanel::Create"_ustr, nullptr, 1); |
69 | | |
70 | 0 | return std::make_unique<DefaultShapesPanel>(pParent, rxFrame); |
71 | 0 | } |
72 | | |
73 | | void DefaultShapesPanel::Initialize() |
74 | 0 | { |
75 | 0 | mpShapesSetMap = decltype(mpShapesSetMap){ |
76 | 0 | { mxLineArrowSet.get(), mpLineShapes }, |
77 | 0 | { mxCurveSet.get(), mpCurveShapes }, |
78 | 0 | { mxConnectorSet.get(), mpConnectorShapes }, |
79 | 0 | { mxBasicShapeSet.get(), mpBasicShapes }, |
80 | 0 | { mxSymbolShapeSet.get(), mpSymbolShapes }, |
81 | 0 | { mxBlockArrowSet.get(), mpBlockArrowShapes }, |
82 | 0 | { mxFlowchartSet.get(), mpFlowchartShapes }, |
83 | 0 | { mxCalloutSet.get(), mpCalloutShapes }, |
84 | 0 | { mxStarSet.get(), mpStarShapes }, |
85 | 0 | { mx3DObjectSet.get(), mp3DShapes } |
86 | 0 | }; |
87 | 0 | populateShapes(); |
88 | 0 | for(auto& aSetMap: mpShapesSetMap) |
89 | 0 | { |
90 | 0 | aSetMap.first->SetColor(Application::GetSettings().GetStyleSettings().GetDialogColor()); |
91 | 0 | aSetMap.first->SetSelectHdl(LINK(this, DefaultShapesPanel, ShapeSelectHdl)); |
92 | 0 | } |
93 | 0 | } |
94 | | |
95 | | DefaultShapesPanel::~DefaultShapesPanel() |
96 | 0 | { |
97 | 0 | mpShapesSetMap.clear(); |
98 | 0 | mxLineArrowSetWin.reset(); |
99 | 0 | mxLineArrowSet.reset(); |
100 | 0 | mxCurveSetWin.reset(); |
101 | 0 | mxCurveSet.reset(); |
102 | 0 | mxConnectorSetWin.reset(); |
103 | 0 | mxConnectorSet.reset(); |
104 | 0 | mxBasicShapeSetWin.reset(); |
105 | 0 | mxBasicShapeSet.reset(); |
106 | 0 | mxSymbolShapeSetWin.reset(); |
107 | 0 | mxSymbolShapeSet.reset(); |
108 | 0 | mxBlockArrowSetWin.reset(); |
109 | 0 | mxBlockArrowSet.reset(); |
110 | 0 | mxFlowchartSetWin.reset(); |
111 | 0 | mxFlowchartSet.reset(); |
112 | 0 | mxCalloutSetWin.reset(); |
113 | 0 | mxCalloutSet.reset(); |
114 | 0 | mxStarSetWin.reset(); |
115 | 0 | mxStarSet.reset(); |
116 | 0 | mx3DObjectSetWin.reset(); |
117 | 0 | mx3DObjectSet.reset(); |
118 | 0 | } |
119 | | |
120 | | IMPL_LINK(DefaultShapesPanel, ShapeSelectHdl, ValueSet*, rValueSet, void) |
121 | 0 | { |
122 | 0 | for(auto& aSetMap : mpShapesSetMap) |
123 | 0 | { |
124 | 0 | if(rValueSet == aSetMap.first) |
125 | 0 | { |
126 | 0 | sal_uInt16 nSelectionId = aSetMap.first->GetSelectedItemId(); |
127 | 0 | comphelper::dispatchCommand(aSetMap.second[nSelectionId - 1], {}); |
128 | 0 | } |
129 | 0 | else |
130 | 0 | aSetMap.first->SetNoSelection(); |
131 | 0 | } |
132 | 0 | } |
133 | | |
134 | | void DefaultShapesPanel::populateShapes() |
135 | 0 | { |
136 | 0 | OUString sSlotStr, sLabel; |
137 | 0 | Image aSlotImage; |
138 | 0 | for(auto& aSet : mpShapesSetMap) |
139 | 0 | { |
140 | 0 | aSet.first->SetColCount(6); |
141 | 0 | for(std::map<sal_uInt16, OUString>::size_type i = 0; i < aSet.second.size(); i++) |
142 | 0 | { |
143 | 0 | sSlotStr = aSet.second[i]; |
144 | 0 | aSlotImage = vcl::CommandInfoProvider::GetImageForCommand(sSlotStr, mxFrame); |
145 | 0 | auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(sSlotStr, |
146 | 0 | vcl::CommandInfoProvider::GetModuleIdentifier(mxFrame)); |
147 | 0 | sLabel = vcl::CommandInfoProvider::GetTooltipForCommand(sSlotStr, aProperties, mxFrame); |
148 | 0 | sal_uInt16 nSelectionId = i + 1; // tdf#142767 id 0 is reserved for nothing-selected |
149 | 0 | aSet.first->InsertItem(nSelectionId, aSlotImage, sLabel); |
150 | 0 | } |
151 | 0 | } |
152 | 0 | } |
153 | | |
154 | | } // end of namespace svx::sidebar |
155 | | |
156 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |