LibreOffice Module sw (master) 1
frmsidebarwincontainer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
22#include <map>
23#include <fmtfld.hxx>
24#include <txtfld.hxx>
25#include <AnnotationWin.hxx>
26
27namespace {
28 struct SidebarWinKey
29 {
30 const sal_Int32 mnIndex;
31
32 explicit SidebarWinKey( const sal_Int32 nIndex )
33 : mnIndex( nIndex )
34 {}
35
36 bool operator < ( const SidebarWinKey& rSidebarWinKey ) const
37 {
38 return mnIndex < rSidebarWinKey.mnIndex;
39 }
40 };
41
42 typedef std::map < SidebarWinKey, VclPtr<sw::annotation::SwAnnotationWin> > SidebarWinContainer;
43
44 struct FrameKey
45 {
46 const SwFrame* mpFrame;
47
48 explicit FrameKey( const SwFrame* pFrame )
49 : mpFrame( pFrame )
50 {}
51
52 bool operator < ( const FrameKey& rFrameKey ) const
53 {
54 return mpFrame < rFrameKey.mpFrame;
55 }
56 };
57
58 typedef std::map < FrameKey, SidebarWinContainer > FrameSidebarWinContainer_;
59}
60
61namespace sw::sidebarwindows {
62
63class FrameSidebarWinContainer : public FrameSidebarWinContainer_
64{
65};
66
68 : mpFrameSidebarWinContainer( new FrameSidebarWinContainer )
69{}
70
72{
75}
76
78 const SwFormatField& rFormatField,
80{
81 bool bInserted( false );
82
83 FrameKey aFrameKey( &rFrame );
84 SidebarWinContainer& rSidebarWinContainer = (*mpFrameSidebarWinContainer)[ aFrameKey ];
85
86 SidebarWinKey aSidebarWinKey( rFormatField.GetTextField()->GetStart() );
87 if ( rSidebarWinContainer.empty() ||
88 rSidebarWinContainer.find( aSidebarWinKey) == rSidebarWinContainer.end() )
89 {
90 rSidebarWinContainer[ aSidebarWinKey ] = &rSidebarWin;
91 bInserted = true;
92 }
93
94 return bInserted;
95}
96
98 const sw::annotation::SwAnnotationWin & rSidebarWin )
99{
100 bool bRemoved( false );
101
102 FrameKey aFrameKey( &rFrame );
103 FrameSidebarWinContainer::iterator aFrameIter = mpFrameSidebarWinContainer->find( aFrameKey );
104 if ( aFrameIter != mpFrameSidebarWinContainer->end() )
105 {
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() )
110 {
111 rSidebarWinContainer.erase( aIter );
112 bRemoved = true;
113 }
114 }
115
116 return bRemoved;
117}
118
120{
121 bool bEmpty( true );
122
123 FrameKey aFrameKey( &rFrame );
124 FrameSidebarWinContainer::iterator aFrameIter = mpFrameSidebarWinContainer->find( aFrameKey );
125 if ( aFrameIter != mpFrameSidebarWinContainer->end() )
126 {
127 bEmpty = (*aFrameIter).second.empty();
128 }
129
130 return bEmpty;
131}
132
134 const sal_Int32 nIndex )
135{
136 sw::annotation::SwAnnotationWin* pRet( nullptr );
137
138 FrameKey aFrameKey( &rFrame );
139 FrameSidebarWinContainer::iterator aFrameIter = mpFrameSidebarWinContainer->find( aFrameKey );
140 if ( aFrameIter != mpFrameSidebarWinContainer->end() && nIndex >= 0 )
141 {
142 SidebarWinContainer& rSidebarWinContainer = (*aFrameIter).second;
143 if (nIndex < sal_Int32(rSidebarWinContainer.size()))
144 {
145 auto aIter = rSidebarWinContainer.begin();
146 std::advance(aIter, nIndex);
147 pRet = (*aIter).second;
148 }
149 }
150 return pRet;
151}
152
154 std::vector< vcl::Window* >* pSidebarWins )
155{
156 pSidebarWins->clear();
157
158 FrameKey aFrameKey( &rFrame );
159 FrameSidebarWinContainer::iterator aFrameIter = mpFrameSidebarWinContainer->find( aFrameKey );
160 if ( aFrameIter != mpFrameSidebarWinContainer->end() )
161 {
162 SidebarWinContainer& rSidebarWinContainer = (*aFrameIter).second;
163 for ( const auto& rEntry : rSidebarWinContainer )
164 {
165 pSidebarWins->push_back( rEntry.second );
166 }
167 }
168}
169
170} // eof of namespace sw::sidebarwindows
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:149
Base class of the Writer layout elements.
Definition: frame.hxx:315
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
void getAll(const SwFrame &rFrame, std::vector< vcl::Window * > *pSidebarWins)
bool remove(const SwFrame &rFrame, const sw::annotation::SwAnnotationWin &rSidebarWin)
std::unique_ptr< FrameSidebarWinContainer > mpFrameSidebarWinContainer
bool insert(const SwFrame &rFrame, const SwFormatField &rFormatField, sw::annotation::SwAnnotationWin &rSidebarWin)
sw::annotation::SwAnnotationWin * get(const SwFrame &rFrame, const sal_Int32 nIndex)
sal_Int32 nIndex
sal_uInt32 mnIndex
bool operator<(const wwFont &r1, const wwFont &r2)
Definition: wrtw8sty.cxx:885