1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <toolbarmodedlg.hxx>
#include <toolbarmode.hrc>
#include <com/sun/star/frame/ModuleManager.hpp>
#include <comphelper/dispatchcommand.hxx>
#include <comphelper/types.hxx>
#include <dialmgr.hxx>
#include <officecfg/Office/Common.hxx>
#include <officecfg/Office/UI/ToolbarMode.hxx>
#include <osl/file.hxx>
#include <rtl/bootstrap.hxx>
#include <sfx2/viewfrm.hxx>
#include <strings.hrc>
#include <unotools/confignode.hxx>
#include <vcl/virdev.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/EnumContext.hxx>
#include <vcl/weld.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
static OUString GetCurrentApp()
{
OUString sResult;
if (SfxViewFrame* pViewFrame = SfxViewFrame::Current())
{
const auto xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
const auto xContext = comphelper::getProcessComponentContext();
const auto xModuleManager = css::frame::ModuleManager::create(xContext);
switch (vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xCurrentFrame)))
{
case vcl::EnumContext::Application::Writer:
sResult = "Writer";
break;
case vcl::EnumContext::Application::Calc:
sResult = "Calc";
break;
case vcl::EnumContext::Application::Impress:
sResult = "Impress";
break;
case vcl::EnumContext::Application::Draw:
sResult = "Draw";
break;
case vcl::EnumContext::Application::Formula:
sResult = "Formula";
break;
case vcl::EnumContext::Application::Base:
sResult = "Base";
break;
default:
sResult = "Unsupported";
}
}
return sResult;
}
static OUString GetCurrentMode()
{
OUString sResult;
if (SfxViewFrame::Current())
{
const auto xContext = comphelper::getProcessComponentContext();
const utl::OConfigurationTreeRoot aAppNode(
xContext, "org.openoffice.Office.UI.ToolbarMode/Applications/" + GetCurrentApp(), true);
if (aAppNode.isValid())
sResult = comphelper::getString(aAppNode.getNodeValue("Active"));
};
return sResult;
}
ToolbarmodeDialog::ToolbarmodeDialog(weld::Window* pParent)
: GenericDialogController(pParent, "cui/ui/toolbarmodedialog.ui", "ToolbarmodeDialog")
, m_pImage(m_xBuilder->weld_image("imImage"))
, m_pApply(m_xBuilder->weld_button("btnApply"))
, m_pApplyAll(m_xBuilder->weld_button("btnApplyAll"))
, m_pRadioButtons{ (m_xBuilder->weld_radio_button("rbButton1")),
(m_xBuilder->weld_radio_button("rbButton2")),
(m_xBuilder->weld_radio_button("rbButton3")),
(m_xBuilder->weld_radio_button("rbButton4")),
(m_xBuilder->weld_radio_button("rbButton5")),
(m_xBuilder->weld_radio_button("rbButton6")),
(m_xBuilder->weld_radio_button("rbButton7")),
(m_xBuilder->weld_radio_button("rbButton8")),
(m_xBuilder->weld_radio_button("rbButton9")) }
, m_pInfoLabel(m_xBuilder->weld_label("lbInfo"))
{
static_assert(SAL_N_ELEMENTS(m_pRadioButtons) == std::size(TOOLBARMODES_ARRAY));
Link<weld::Toggleable&, void> aLink = LINK(this, ToolbarmodeDialog, SelectToolbarmode);
const OUString sCurrentMode = GetCurrentMode();
for (std::size_t i = 0; i < std::size(m_pRadioButtons); ++i)
{
m_pRadioButtons[i]->connect_toggled(aLink);
if (sCurrentMode == std::get<1>(TOOLBARMODES_ARRAY[i]))
{
m_pRadioButtons[i]->set_active(true);
UpdateImage(std::get<2>(TOOLBARMODES_ARRAY[i]));
m_pInfoLabel->set_label(CuiResId(std::get<0>(TOOLBARMODES_ARRAY[i])));
}
}
m_pApply->set_label(CuiResId(RID_CUISTR_UI_APPLYALL).replaceFirst("%MODULE", GetCurrentApp()));
m_pApply->connect_clicked(LINK(this, ToolbarmodeDialog, OnApplyClick));
m_pApplyAll->connect_clicked(LINK(this, ToolbarmodeDialog, OnApplyClick));
if (!officecfg::Office::Common::Misc::ExperimentalMode::get())
{
m_pRadioButtons[nGroupedbarFull]->set_visible(false);
m_pRadioButtons[nContextualGroups]->set_visible(false);
}
}
ToolbarmodeDialog::~ToolbarmodeDialog() = default;
static bool file_exists(const OUString& fileName)
{
osl::File aFile(fileName);
return aFile.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None;
}
int ToolbarmodeDialog::GetActiveRadioButton()
{
for (std::size_t i = 0; i < std::size(m_pRadioButtons); ++i)
{
if (m_pRadioButtons[i]->get_active())
return i;
}
return -1;
}
void ToolbarmodeDialog::UpdateImage(std::u16string_view sFileName)
{
// load image
OUString aURL("$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/toolbarmode/");
rtl::Bootstrap::expandMacros(aURL);
aURL += sFileName;
if (sFileName.empty() || !file_exists(aURL))
return;
// draw image
Graphic aGraphic;
if (GraphicFilter::LoadGraphic(aURL, OUString(), aGraphic) == ERRCODE_NONE)
{
ScopedVclPtr<VirtualDevice> m_pVirDev = m_pImage->create_virtual_device();
m_pVirDev->SetOutputSizePixel(aGraphic.GetSizePixel());
m_pVirDev->DrawBitmapEx(Point(0, 0), aGraphic.GetBitmapEx());
m_pImage->set_image(m_pVirDev.get());
m_pVirDev.disposeAndClear();
}
}
IMPL_LINK_NOARG(ToolbarmodeDialog, SelectToolbarmode, weld::Toggleable&, void)
{
const int i = GetActiveRadioButton();
if (i > -1)
{
UpdateImage(std::get<2>(TOOLBARMODES_ARRAY[i]));
m_pInfoLabel->set_label(CuiResId(std::get<0>(TOOLBARMODES_ARRAY[i])));
}
}
IMPL_LINK(ToolbarmodeDialog, OnApplyClick, weld::Button&, rButton, void)
{
const int i = GetActiveRadioButton();
if (i == -1)
return;
const OUString sCmd = std::get<1>(TOOLBARMODES_ARRAY[i]);
//apply to all except current module
if (&rButton == m_pApplyAll.get())
{
std::shared_ptr<comphelper::ConfigurationChanges> aBatch(
comphelper::ConfigurationChanges::create());
officecfg::Office::UI::ToolbarMode::ActiveWriter::set(sCmd, aBatch);
officecfg::Office::UI::ToolbarMode::ActiveCalc::set(sCmd, aBatch);
officecfg::Office::UI::ToolbarMode::ActiveImpress::set(sCmd, aBatch);
officecfg::Office::UI::ToolbarMode::ActiveDraw::set(sCmd, aBatch);
aBatch->commit();
OUString sCurrentApp = GetCurrentApp();
if (SfxViewFrame::Current())
{
const auto xContext = comphelper::getProcessComponentContext();
const utl::OConfigurationTreeRoot aAppNode(
xContext, "org.openoffice.Office.UI.ToolbarMode/Applications/", true);
if (sCurrentApp != "Writer")
aAppNode.setNodeValue("Writer/Active", css::uno::Any(sCmd));
if (sCurrentApp != "Calc")
aAppNode.setNodeValue("Calc/Active", css::uno::Any(sCmd));
if (sCurrentApp != "Impress")
aAppNode.setNodeValue("Impress/Active", css::uno::Any(sCmd));
if (sCurrentApp != "Draw")
aAppNode.setNodeValue("Draw/Active", css::uno::Any(sCmd));
aAppNode.commit();
};
}
//apply to current module
comphelper::dispatchCommand(".uno:ToolbarMode?Mode:string=" + sCmd, {});
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|