1*efeef26fSAndrew Rist /**************************************************************
2*efeef26fSAndrew Rist *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <frmsidebarwincontainer.hxx>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <map>
30cdf0e10cSrcweir #include <fmtfld.hxx>
31cdf0e10cSrcweir #include <txtfld.hxx>
32cdf0e10cSrcweir #include <SidebarWin.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir namespace {
35cdf0e10cSrcweir struct SidebarWinKey
36cdf0e10cSrcweir {
37cdf0e10cSrcweir const xub_StrLen mnIndex;
38cdf0e10cSrcweir
SidebarWinKey__anon351a0ba00111::SidebarWinKey39cdf0e10cSrcweir explicit SidebarWinKey( const xub_StrLen nIndex )
40cdf0e10cSrcweir : mnIndex( nIndex )
41cdf0e10cSrcweir {}
42cdf0e10cSrcweir
operator <__anon351a0ba00111::SidebarWinKey43cdf0e10cSrcweir bool operator < ( const SidebarWinKey& rSidebarWinKey ) const
44cdf0e10cSrcweir {
45cdf0e10cSrcweir return mnIndex < rSidebarWinKey.mnIndex;
46cdf0e10cSrcweir }
47cdf0e10cSrcweir };
48cdf0e10cSrcweir
49cdf0e10cSrcweir struct SidebarWinOrder
50cdf0e10cSrcweir {
operator ()__anon351a0ba00111::SidebarWinOrder51cdf0e10cSrcweir sal_Bool operator()( const SidebarWinKey& rSidebarWinKeyA,
52cdf0e10cSrcweir const SidebarWinKey& rSidebarWinKeyB ) const
53cdf0e10cSrcweir {
54cdf0e10cSrcweir return rSidebarWinKeyA < rSidebarWinKeyB;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir };
57cdf0e10cSrcweir
58cdf0e10cSrcweir typedef ::std::map < SidebarWinKey, sw::sidebarwindows::SwSidebarWin*, SidebarWinOrder > SidebarWinContainer;
59cdf0e10cSrcweir
60cdf0e10cSrcweir struct FrmKey
61cdf0e10cSrcweir {
62cdf0e10cSrcweir const SwFrm* mpFrm;
63cdf0e10cSrcweir
FrmKey__anon351a0ba00111::FrmKey64cdf0e10cSrcweir explicit FrmKey( const SwFrm* pFrm )
65cdf0e10cSrcweir : mpFrm( pFrm )
66cdf0e10cSrcweir {}
67cdf0e10cSrcweir
operator <__anon351a0ba00111::FrmKey68cdf0e10cSrcweir bool operator < ( const FrmKey& rFrmKey ) const
69cdf0e10cSrcweir {
70cdf0e10cSrcweir return mpFrm < rFrmKey.mpFrm;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir };
73cdf0e10cSrcweir
74cdf0e10cSrcweir struct FrmOrder
75cdf0e10cSrcweir {
operator ()__anon351a0ba00111::FrmOrder76cdf0e10cSrcweir sal_Bool operator()( const FrmKey& rFrmKeyA,
77cdf0e10cSrcweir const FrmKey& rFrmKeyB ) const
78cdf0e10cSrcweir {
79cdf0e10cSrcweir return rFrmKeyA < rFrmKeyB;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir };
82cdf0e10cSrcweir
83cdf0e10cSrcweir typedef ::std::map < FrmKey, SidebarWinContainer, FrmOrder > _FrmSidebarWinContainer;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir namespace sw { namespace sidebarwindows {
87cdf0e10cSrcweir
88cdf0e10cSrcweir class FrmSidebarWinContainer : public _FrmSidebarWinContainer
89cdf0e10cSrcweir {
90cdf0e10cSrcweir };
91cdf0e10cSrcweir
SwFrmSidebarWinContainer()92cdf0e10cSrcweir SwFrmSidebarWinContainer::SwFrmSidebarWinContainer()
93cdf0e10cSrcweir : mpFrmSidebarWinContainer( new FrmSidebarWinContainer() )
94cdf0e10cSrcweir {}
95cdf0e10cSrcweir
~SwFrmSidebarWinContainer()96cdf0e10cSrcweir SwFrmSidebarWinContainer::~SwFrmSidebarWinContainer()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir mpFrmSidebarWinContainer->clear();
99cdf0e10cSrcweir delete mpFrmSidebarWinContainer;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
insert(const SwFrm & rFrm,const SwFmtFld & rFmtFld,SwSidebarWin & rSidebarWin)102cdf0e10cSrcweir bool SwFrmSidebarWinContainer::insert( const SwFrm& rFrm,
103cdf0e10cSrcweir const SwFmtFld& rFmtFld,
104cdf0e10cSrcweir SwSidebarWin& rSidebarWin )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir bool bInserted( false );
107cdf0e10cSrcweir
108cdf0e10cSrcweir FrmKey aFrmKey( &rFrm );
109cdf0e10cSrcweir SidebarWinContainer& rSidebarWinContainer = (*mpFrmSidebarWinContainer)[ aFrmKey ];
110cdf0e10cSrcweir
111cdf0e10cSrcweir SidebarWinKey aSidebarWinKey( *(rFmtFld.GetTxtFld()->GetStart()) );
112cdf0e10cSrcweir if ( rSidebarWinContainer.empty() ||
113cdf0e10cSrcweir rSidebarWinContainer.find( aSidebarWinKey) == rSidebarWinContainer.end() )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir rSidebarWinContainer[ aSidebarWinKey ] = &rSidebarWin;
116cdf0e10cSrcweir bInserted = true;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir return bInserted;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
remove(const SwFrm & rFrm,const SwSidebarWin & rSidebarWin)122cdf0e10cSrcweir bool SwFrmSidebarWinContainer::remove( const SwFrm& rFrm,
123cdf0e10cSrcweir const SwSidebarWin& rSidebarWin )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir bool bRemoved( false );
126cdf0e10cSrcweir
127cdf0e10cSrcweir FrmKey aFrmKey( &rFrm );
128cdf0e10cSrcweir FrmSidebarWinContainer::iterator aFrmIter = mpFrmSidebarWinContainer->find( aFrmKey );
129cdf0e10cSrcweir if ( aFrmIter != mpFrmSidebarWinContainer->end() )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir SidebarWinContainer& rSidebarWinContainer = (*aFrmIter).second;
132cdf0e10cSrcweir for ( SidebarWinContainer::iterator aIter = rSidebarWinContainer.begin();
133cdf0e10cSrcweir aIter != rSidebarWinContainer.end();
134cdf0e10cSrcweir ++aIter )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir if ( (*aIter).second == &rSidebarWin )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir rSidebarWinContainer.erase( aIter );
139cdf0e10cSrcweir bRemoved = true;
140cdf0e10cSrcweir break;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir return bRemoved;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
empty(const SwFrm & rFrm)148cdf0e10cSrcweir bool SwFrmSidebarWinContainer::empty( const SwFrm& rFrm )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir bool bEmpty( true );
151cdf0e10cSrcweir
152cdf0e10cSrcweir FrmKey aFrmKey( &rFrm );
153cdf0e10cSrcweir FrmSidebarWinContainer::iterator aFrmIter = mpFrmSidebarWinContainer->find( aFrmKey );
154cdf0e10cSrcweir if ( aFrmIter != mpFrmSidebarWinContainer->end() )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir bEmpty = (*aFrmIter).second.empty();
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir return bEmpty;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
get(const SwFrm & rFrm,const sal_Int32 nIndex)162cdf0e10cSrcweir SwSidebarWin* SwFrmSidebarWinContainer::get( const SwFrm& rFrm,
163cdf0e10cSrcweir const sal_Int32 nIndex )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir SwSidebarWin* pRet( 0 );
166cdf0e10cSrcweir
167cdf0e10cSrcweir FrmKey aFrmKey( &rFrm );
168cdf0e10cSrcweir FrmSidebarWinContainer::iterator aFrmIter = mpFrmSidebarWinContainer->find( aFrmKey );
169cdf0e10cSrcweir if ( aFrmIter != mpFrmSidebarWinContainer->end() )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir SidebarWinContainer& rSidebarWinContainer = (*aFrmIter).second;
172cdf0e10cSrcweir sal_Int32 nCounter( nIndex );
173cdf0e10cSrcweir for ( SidebarWinContainer::iterator aIter = rSidebarWinContainer.begin();
174cdf0e10cSrcweir nCounter >= 0 && aIter != rSidebarWinContainer.end();
175cdf0e10cSrcweir ++aIter )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir if ( nCounter == 0 )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir pRet = (*aIter).second;
180cdf0e10cSrcweir break;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir
183cdf0e10cSrcweir --nCounter;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
187cdf0e10cSrcweir return pRet;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir
getAll(const SwFrm & rFrm,std::vector<Window * > * pSidebarWins)190cdf0e10cSrcweir void SwFrmSidebarWinContainer::getAll( const SwFrm& rFrm,
191cdf0e10cSrcweir std::vector< Window* >* pSidebarWins )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir pSidebarWins->clear();
194cdf0e10cSrcweir
195cdf0e10cSrcweir FrmKey aFrmKey( &rFrm );
196cdf0e10cSrcweir FrmSidebarWinContainer::iterator aFrmIter = mpFrmSidebarWinContainer->find( aFrmKey );
197cdf0e10cSrcweir if ( aFrmIter != mpFrmSidebarWinContainer->end() )
198cdf0e10cSrcweir {
199cdf0e10cSrcweir SidebarWinContainer& rSidebarWinContainer = (*aFrmIter).second;
200cdf0e10cSrcweir for ( SidebarWinContainer::iterator aIter = rSidebarWinContainer.begin();
201cdf0e10cSrcweir aIter != rSidebarWinContainer.end();
202cdf0e10cSrcweir ++aIter )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir pSidebarWins->push_back( (*aIter).second );
205cdf0e10cSrcweir }
206cdf0e10cSrcweir }
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir } } // eof of namespace sw::sidebarwindows::
210