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/.
10 #include <svx/dialog/ThemeDialog.hxx>
11 #include <docmodel/theme/ColorSet.hxx>
12 #include <docmodel/theme/Theme.hxx>
13 #include <svx/ColorSets.hxx>
14 #include <vcl/svapp.hxx>
15 #include <svx/colorbox.hxx>
16 #include <comphelper/lok.hxx>
20 ThemeDialog::ThemeDialog(weld::Window
* pParent
, model::Theme
* pTheme
)
21 : GenericDialogController(pParent
, "svx/ui/themedialog.ui", "ThemeDialog")
24 , mxValueSetThemeColors(new svx::ThemeColorValueSet
)
25 , mxValueSetThemeColorsWindow(
26 new weld::CustomWeld(*m_xBuilder
, "valueset_theme_colors", *mxValueSetThemeColors
))
27 , mxAdd(m_xBuilder
->weld_button("button_add"))
29 mxValueSetThemeColors
->SetColCount(3);
30 mxValueSetThemeColors
->SetLineCount(4);
31 mxValueSetThemeColors
->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor());
32 mxValueSetThemeColors
->SetDoubleClickHdl(LINK(this, ThemeDialog
, DoubleClickValueSetHdl
));
33 mxValueSetThemeColors
->SetSelectHdl(LINK(this, ThemeDialog
, SelectItem
));
35 mxAdd
->connect_clicked(LINK(this, ThemeDialog
, ButtonClicked
));
39 if (!maColorSets
.empty())
41 mxValueSetThemeColors
->SelectItem(1); // ItemId 1, position 0
42 mpCurrentColorSet
= std::make_shared
<model::ColorSet
>(maColorSets
[0]);
46 ThemeDialog::~ThemeDialog()
49 mxSubDialog
->response(RET_CANCEL
);
52 void ThemeDialog::initColorSets()
55 maColorSets
.push_back(*mpTheme
->getColorSet());
57 auto const& rColorSetVector
= ColorSets::get().getColorSetVector();
58 maColorSets
.insert(maColorSets
.end(), rColorSetVector
.begin(), rColorSetVector
.end());
60 for (auto const& rColorSet
: maColorSets
)
62 mxValueSetThemeColors
->insert(rColorSet
);
65 mxValueSetThemeColors
->SetOptimalSize();
68 IMPL_LINK_NOARG(ThemeDialog
, DoubleClickValueSetHdl
, ValueSet
*, void)
71 if (!comphelper::LibreOfficeKit::isActive())
72 m_xDialog
->response(RET_OK
);
75 IMPL_LINK_NOARG(ThemeDialog
, SelectItem
, ValueSet
*, void)
77 sal_uInt32 nItemId
= mxValueSetThemeColors
->GetSelectedItemId();
81 sal_uInt32 nIndex
= nItemId
- 1;
83 if (nIndex
>= maColorSets
.size())
86 mpCurrentColorSet
= std::make_shared
<model::ColorSet
>(maColorSets
[nIndex
]);
89 void ThemeDialog::runThemeColorEditDialog()
94 mxSubDialog
= std::make_shared
<svx::ThemeColorEditDialog
>(mpWindow
, *mpCurrentColorSet
);
96 weld::DialogController::runAsync(mxSubDialog
, [this](sal_uInt32 nResult
) {
97 if (nResult
!= RET_OK
)
99 mxAdd
->set_sensitive(true);
100 mxSubDialog
= nullptr;
103 auto aColorSet
= mxSubDialog
->getColorSet();
104 if (!aColorSet
.getName().isEmpty())
106 ColorSets::get().insert(aColorSet
, ColorSets::IdenticalNameAction::AutoRename
);
108 mxValueSetThemeColors
->Clear();
112 mxValueSetThemeColors
->SelectItem(maColorSets
.size() - 1);
114 = std::make_shared
<model::ColorSet
>(maColorSets
[maColorSets
.size() - 1]);
116 mxAdd
->set_sensitive(true);
117 mxSubDialog
= nullptr;
121 IMPL_LINK(ThemeDialog
, ButtonClicked
, weld::Button
&, rButton
, void)
123 mxAdd
->set_sensitive(false);
124 if (mpCurrentColorSet
&& mxAdd
.get() == &rButton
)
126 runThemeColorEditDialog();
130 } // end svx namespace
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */