Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / appl / appchild.cxx
blob9ee356566479429c07de1337719757e8a4ca91ff
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 .
21 #include <osl/diagnose.h>
22 #include <tools/debug.hxx>
24 #include <sfx2/app.hxx>
25 #include <appdata.hxx>
26 #include <workwin.hxx>
27 #include <childwinimpl.hxx>
28 #include <sfx2/childwin.hxx>
29 #include <sfx2/module.hxx>
30 #include <sfx2/viewfrm.hxx>
33 void SfxApplication::RegisterChildWindow_Impl( SfxModule *pMod, std::unique_ptr<SfxChildWinFactory> pFact )
35 if ( pMod )
37 pMod->RegisterChildWindow( std::move(pFact) );
38 return;
41 if (!pImpl->pFactArr)
42 pImpl->pFactArr.reset(new SfxChildWinFactArr_Impl);
44 for (size_t nFactory=0; nFactory<pImpl->pFactArr->size(); ++nFactory)
46 if (pFact->nId == (*pImpl->pFactArr)[nFactory].nId)
48 pImpl->pFactArr->erase( pImpl->pFactArr->begin() + nFactory );
52 pImpl->pFactArr->push_back( std::move(pFact) );
55 void SfxApplication::RegisterChildWindowContext_Impl( SfxModule *pMod, sal_uInt16 nId,
56 std::unique_ptr<SfxChildWinContextFactory> pFact)
58 SfxChildWinFactArr_Impl *pFactories;
59 SfxChildWinFactory *pF = nullptr;
60 if ( pMod )
62 // Abandon Module, search there for ChildwindowFactory
63 pFactories = pMod->GetChildWinFactories_Impl();
64 if ( pFactories )
66 sal_uInt16 nCount = pFactories->size();
67 for (sal_uInt16 nFactory=0; nFactory<nCount; ++nFactory)
69 SfxChildWinFactory *pFac = &(*pFactories)[nFactory];
70 if ( nId == pFac->nId )
72 // Factory found, register Context here.
73 pF = pFac;
74 break;
80 if ( !pF )
82 // Search for Factory in the Application
83 DBG_ASSERT( pImpl, "No AppData!" );
84 DBG_ASSERT( pImpl->pFactArr, "No Factories!" );
86 pFactories = pImpl->pFactArr.get();
87 sal_uInt16 nCount = pFactories->size();
88 for (sal_uInt16 nFactory=0; nFactory<nCount; ++nFactory)
90 SfxChildWinFactory *pFac = &(*pFactories)[nFactory];
91 if ( nId == pFac->nId )
93 if ( pMod )
95 // If the context of a module has been registered, then the
96 // ChildWindowFactory must also be available there,
97 // else the ContextFactory would have be unsubscribed on
98 // DLL-exit
99 pF = new SfxChildWinFactory( pFac->pCtor, pFac->nId,
100 pFac->nPos );
101 pMod->RegisterChildWindow( std::unique_ptr<SfxChildWinFactory>(pF) );
103 else
104 pF = pFac;
105 break;
110 if ( pF )
112 if ( !pF->pArr )
113 pF->pArr.reset( new SfxChildWinContextArr_Impl );
114 pF->pArr->push_back( std::move(pFact) );
115 return;
118 OSL_FAIL( "No ChildWindow for this Context!" );
122 SfxChildWinFactArr_Impl& SfxApplication::GetChildWinFactories_Impl() const
124 return ( *(pImpl->pFactArr));
128 SfxWorkWindow* SfxApplication::GetWorkWindow_Impl(const SfxViewFrame *pFrame) const
130 if ( pFrame )
131 return pFrame->GetFrame().GetWorkWindow_Impl();
132 else if ( pImpl->pViewFrame )
133 return pImpl->pViewFrame->GetFrame().GetWorkWindow_Impl();
134 else
135 return nullptr;
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */