cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / view / WindowUpdater.cxx
blob3aa53fe0d2f64f6b98e970f0b0197837097193e2
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 <WindowUpdater.hxx>
21 #include <drawdoc.hxx>
23 #include <vcl/outdev.hxx>
24 #include <vcl/vclptr.hxx>
25 #include <vcl/window.hxx>
27 #include <algorithm>
29 namespace sd {
31 WindowUpdater::WindowUpdater()
32 : mpDocument (nullptr)
34 maCTLOptions.AddListener(this);
37 WindowUpdater::~WindowUpdater() noexcept
39 maCTLOptions.RemoveListener(this);
42 void WindowUpdater::RegisterWindow (vcl::Window* pWindow)
44 if (pWindow != nullptr)
46 tWindowList::iterator aWindowIterator (
47 ::std::find (
48 maWindowList.begin(), maWindowList.end(), pWindow));
49 if (aWindowIterator == maWindowList.end())
51 // Update the device once right now and add it to the list.
52 Update (pWindow->GetOutDev());
53 maWindowList.emplace_back(pWindow);
58 void WindowUpdater::UnregisterWindow (vcl::Window* pWindow)
60 tWindowList::iterator aWindowIterator (
61 ::std::find (
62 maWindowList.begin(), maWindowList.end(), pWindow));
63 if (aWindowIterator != maWindowList.end())
65 maWindowList.erase (aWindowIterator);
69 void WindowUpdater::SetDocument (SdDrawDocument* pDocument)
71 mpDocument = pDocument;
74 /*static*/ void WindowUpdater::Update (OutputDevice* pDevice)
76 if (pDevice != nullptr)
78 UpdateWindow (pDevice);
82 /*static*/ void WindowUpdater::UpdateWindow (OutputDevice* pDevice)
84 if (pDevice == nullptr)
85 return;
87 SvtCTLOptions::TextNumerals aNumeralMode (SvtCTLOptions::GetCTLTextNumerals());
89 LanguageType aLanguage;
90 // Now this is a bit confusing. The numerals in arabic languages
91 // are Hindi numerals and what the western world generally uses are
92 // arabic numerals. The digits used in the Hindi language are not
93 // used at all.
94 switch (aNumeralMode)
96 case SvtCTLOptions::NUMERALS_HINDI:
97 aLanguage = LANGUAGE_ARABIC_SAUDI_ARABIA;
98 break;
100 case SvtCTLOptions::NUMERALS_SYSTEM:
101 aLanguage = LANGUAGE_SYSTEM;
102 break;
104 case SvtCTLOptions::NUMERALS_ARABIC:
105 default:
106 aLanguage = LANGUAGE_ENGLISH;
107 break;
110 pDevice->SetDigitLanguage (aLanguage);
113 void WindowUpdater::ConfigurationChanged( utl::ConfigurationBroadcaster*, ConfigurationHints )
115 // Set the current state at all registered output devices.
116 for (auto& rxWindow : maWindowList)
117 Update (rxWindow->GetOutDev());
119 // Reformat the document for the modified state to take effect.
120 if (mpDocument != nullptr)
121 mpDocument->ReformatAllTextObjects();
123 // Invalidate the windows to make the modified state visible.
124 for (auto& rxWindow : maWindowList)
125 rxWindow->Invalidate();
128 } // end of namespace sd
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */