android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / uibase / docvw / frmsidebarwincontainer.cxx
blob17da0beee4f80681117658682f497671ebab7386
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 "frmsidebarwincontainer.hxx"
22 #include <map>
23 #include <fmtfld.hxx>
24 #include <txtfld.hxx>
25 #include <AnnotationWin.hxx>
27 namespace {
28 struct SidebarWinKey
30 const sal_Int32 mnIndex;
32 explicit SidebarWinKey( const sal_Int32 nIndex )
33 : mnIndex( nIndex )
36 bool operator < ( const SidebarWinKey& rSidebarWinKey ) const
38 return mnIndex < rSidebarWinKey.mnIndex;
42 typedef std::map < SidebarWinKey, VclPtr<sw::annotation::SwAnnotationWin> > SidebarWinContainer;
44 struct FrameKey
46 const SwFrame* mpFrame;
48 explicit FrameKey( const SwFrame* pFrame )
49 : mpFrame( pFrame )
52 bool operator < ( const FrameKey& rFrameKey ) const
54 return mpFrame < rFrameKey.mpFrame;
58 typedef std::map < FrameKey, SidebarWinContainer > FrameSidebarWinContainer_;
61 namespace sw::sidebarwindows {
63 class FrameSidebarWinContainer : public FrameSidebarWinContainer_
67 SwFrameSidebarWinContainer::SwFrameSidebarWinContainer()
68 : mpFrameSidebarWinContainer( new FrameSidebarWinContainer )
71 SwFrameSidebarWinContainer::~SwFrameSidebarWinContainer()
73 mpFrameSidebarWinContainer->clear();
74 mpFrameSidebarWinContainer.reset();
77 bool SwFrameSidebarWinContainer::insert( const SwFrame& rFrame,
78 const SwFormatField& rFormatField,
79 sw::annotation::SwAnnotationWin& rSidebarWin )
81 bool bInserted( false );
83 FrameKey aFrameKey( &rFrame );
84 SidebarWinContainer& rSidebarWinContainer = (*mpFrameSidebarWinContainer)[ aFrameKey ];
86 SidebarWinKey aSidebarWinKey( rFormatField.GetTextField()->GetStart() );
87 if ( rSidebarWinContainer.empty() ||
88 rSidebarWinContainer.find( aSidebarWinKey) == rSidebarWinContainer.end() )
90 rSidebarWinContainer[ aSidebarWinKey ] = &rSidebarWin;
91 bInserted = true;
94 return bInserted;
97 bool SwFrameSidebarWinContainer::remove( const SwFrame& rFrame,
98 const sw::annotation::SwAnnotationWin & rSidebarWin )
100 bool bRemoved( false );
102 FrameKey aFrameKey( &rFrame );
103 FrameSidebarWinContainer::iterator aFrameIter = mpFrameSidebarWinContainer->find( aFrameKey );
104 if ( aFrameIter != mpFrameSidebarWinContainer->end() )
106 SidebarWinContainer& rSidebarWinContainer = (*aFrameIter).second;
107 auto aIter = std::find_if(rSidebarWinContainer.begin(), rSidebarWinContainer.end(),
108 [&rSidebarWin](const SidebarWinContainer::value_type& rEntry) { return rEntry.second == &rSidebarWin; });
109 if ( aIter != rSidebarWinContainer.end() )
111 rSidebarWinContainer.erase( aIter );
112 bRemoved = true;
116 return bRemoved;
119 bool SwFrameSidebarWinContainer::empty( const SwFrame& rFrame )
121 bool bEmpty( true );
123 FrameKey aFrameKey( &rFrame );
124 FrameSidebarWinContainer::iterator aFrameIter = mpFrameSidebarWinContainer->find( aFrameKey );
125 if ( aFrameIter != mpFrameSidebarWinContainer->end() )
127 bEmpty = (*aFrameIter).second.empty();
130 return bEmpty;
133 sw::annotation::SwAnnotationWin* SwFrameSidebarWinContainer::get( const SwFrame& rFrame,
134 const sal_Int32 nIndex )
136 sw::annotation::SwAnnotationWin* pRet( nullptr );
138 FrameKey aFrameKey( &rFrame );
139 FrameSidebarWinContainer::iterator aFrameIter = mpFrameSidebarWinContainer->find( aFrameKey );
140 if ( aFrameIter != mpFrameSidebarWinContainer->end() && nIndex >= 0 )
142 SidebarWinContainer& rSidebarWinContainer = (*aFrameIter).second;
143 if (nIndex < sal_Int32(rSidebarWinContainer.size()))
145 auto aIter = rSidebarWinContainer.begin();
146 std::advance(aIter, nIndex);
147 pRet = (*aIter).second;
150 return pRet;
153 void SwFrameSidebarWinContainer::getAll( const SwFrame& rFrame,
154 std::vector< vcl::Window* >* pSidebarWins )
156 pSidebarWins->clear();
158 FrameKey aFrameKey( &rFrame );
159 FrameSidebarWinContainer::iterator aFrameIter = mpFrameSidebarWinContainer->find( aFrameKey );
160 if ( aFrameIter != mpFrameSidebarWinContainer->end() )
162 SidebarWinContainer& rSidebarWinContainer = (*aFrameIter).second;
163 for ( const auto& rEntry : rSidebarWinContainer )
165 pSidebarWins->push_back( rEntry.second );
170 } // eof of namespace sw::sidebarwindows
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */