sd: keep a non-owning pointer to the OverridingShell
[LibreOffice.git] / sfx2 / source / dialog / documentfontsdialog.cxx
blob73918ca059d8585a6b5fb1700d5486937e2b7439
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <documentfontsdialog.hxx>
22 #include <sfx2/objsh.hxx>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/frame/XModel.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 using namespace ::com::sun::star;
30 std::unique_ptr<SfxTabPage> SfxDocumentFontsPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* set)
32 return std::make_unique<SfxDocumentFontsPage>(pPage, pController, *set);
35 SfxDocumentFontsPage::SfxDocumentFontsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& set)
36 : SfxTabPage(pPage, pController, u"sfx/ui/documentfontspage.ui"_ustr, u"DocumentFontsPage"_ustr, &set)
37 , embedFontsCheckbox(m_xBuilder->weld_check_button(u"embedFonts"_ustr))
38 , embedUsedFontsCheckbox(m_xBuilder->weld_check_button(u"embedUsedFonts"_ustr))
39 , embedLatinScriptFontsCheckbox(m_xBuilder->weld_check_button(u"embedLatinScriptFonts"_ustr))
40 , embedAsianScriptFontsCheckbox(m_xBuilder->weld_check_button(u"embedAsianScriptFonts"_ustr))
41 , embedComplexScriptFontsCheckbox(m_xBuilder->weld_check_button(u"embedComplexScriptFonts"_ustr))
45 SfxDocumentFontsPage::~SfxDocumentFontsPage()
49 void SfxDocumentFontsPage::Reset( const SfxItemSet* )
51 bool bEmbedFonts = false;
52 bool bEmbedUsedFonts = false;
54 bool bEmbedLatinScriptFonts = false;
55 bool bEmbedAsianScriptFonts = false;
56 bool bEmbedComplexScriptFonts = false;
58 SfxObjectShell* pDocSh = SfxObjectShell::Current();
59 if (pDocSh)
61 try
63 uno::Reference< lang::XMultiServiceFactory > xFac( pDocSh->GetModel(), uno::UNO_QUERY );
64 if (xFac)
66 uno::Reference< beans::XPropertySet > xProps( xFac->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY);
67 if (xProps)
69 xProps->getPropertyValue(u"EmbedFonts"_ustr) >>= bEmbedFonts;
70 xProps->getPropertyValue(u"EmbedOnlyUsedFonts"_ustr) >>= bEmbedUsedFonts;
71 xProps->getPropertyValue(u"EmbedLatinScriptFonts"_ustr) >>= bEmbedLatinScriptFonts;
72 xProps->getPropertyValue(u"EmbedAsianScriptFonts"_ustr) >>= bEmbedAsianScriptFonts;
73 xProps->getPropertyValue(u"EmbedComplexScriptFonts"_ustr) >>= bEmbedComplexScriptFonts;
77 catch( uno::Exception& )
81 embedFontsCheckbox->set_active(bEmbedFonts);
82 embedUsedFontsCheckbox->set_active(bEmbedUsedFonts);
84 embedLatinScriptFontsCheckbox->set_active(bEmbedLatinScriptFonts);
85 embedAsianScriptFontsCheckbox->set_active(bEmbedAsianScriptFonts);
86 embedComplexScriptFontsCheckbox->set_active(bEmbedComplexScriptFonts);
89 bool SfxDocumentFontsPage::FillItemSet( SfxItemSet* )
91 bool bEmbedFonts = embedFontsCheckbox->get_active();
92 bool bEmbedUsedFonts = embedUsedFontsCheckbox->get_active();
94 bool bEmbedLatinScriptFonts = embedLatinScriptFontsCheckbox->get_active();
95 bool bEmbedAsianScriptFonts = embedAsianScriptFontsCheckbox->get_active();
96 bool bEmbedComplexScriptFonts = embedComplexScriptFontsCheckbox->get_active();
98 SfxObjectShell* pDocSh = SfxObjectShell::Current();
99 if ( pDocSh )
103 uno::Reference< lang::XMultiServiceFactory > xFac( pDocSh->GetModel(), uno::UNO_QUERY );
104 if (xFac)
106 uno::Reference< beans::XPropertySet > xProps( xFac->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY );
107 if (xProps)
109 xProps->setPropertyValue(u"EmbedFonts"_ustr, uno::Any(bEmbedFonts));
110 xProps->setPropertyValue(u"EmbedOnlyUsedFonts"_ustr, uno::Any(bEmbedUsedFonts));
111 xProps->setPropertyValue(u"EmbedLatinScriptFonts"_ustr, uno::Any(bEmbedLatinScriptFonts));
112 xProps->setPropertyValue(u"EmbedAsianScriptFonts"_ustr, uno::Any(bEmbedAsianScriptFonts));
113 xProps->setPropertyValue(u"EmbedComplexScriptFonts"_ustr, uno::Any(bEmbedComplexScriptFonts));
117 catch( uno::Exception& )
121 return false;
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */