Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * [ Copyright (C) 2011 SUSE <cbosdonnat@suse.com> (initial developer) ]
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include <edtwin.hxx>
30 : #include <FrameControlsManager.hxx>
31 : #include <HeaderFooterWin.hxx>
32 : #include <PageBreakWin.hxx>
33 : #include <pagefrm.hxx>
34 : #include <viewopt.hxx>
35 : #include <view.hxx>
36 : #include <wrtsh.hxx>
37 :
38 : using namespace std;
39 :
40 236 : SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) :
41 : m_pEditWin( pEditWin ),
42 236 : m_aControls( )
43 : {
44 236 : }
45 :
46 63 : SwFrameControlsManager::~SwFrameControlsManager()
47 : {
48 63 : }
49 :
50 0 : SwFrameControlsManager::SwFrameControlsManager( const SwFrameControlsManager& rCopy ) :
51 : m_pEditWin( rCopy.m_pEditWin ),
52 0 : m_aControls( rCopy.m_aControls )
53 : {
54 0 : }
55 :
56 0 : const SwFrameControlsManager& SwFrameControlsManager::operator=( const SwFrameControlsManager& rCopy )
57 : {
58 0 : m_pEditWin = rCopy.m_pEditWin;
59 0 : m_aControls = rCopy.m_aControls;
60 0 : return *this;
61 : }
62 :
63 4 : SwFrameControlPtr SwFrameControlsManager::GetControl( FrameControlType eType, const SwFrm* pFrm )
64 : {
65 4 : SwFrameControlPtrMap& rControls = m_aControls[eType];
66 :
67 4 : SwFrameControlPtrMap::iterator aIt = rControls.find(pFrm);
68 :
69 4 : if (aIt != rControls.end())
70 2 : return aIt->second;
71 :
72 2 : return SwFrameControlPtr();
73 : }
74 :
75 0 : void SwFrameControlsManager::RemoveControls( const SwFrm* pFrm )
76 : {
77 0 : map< FrameControlType, SwFrameControlPtrMap >::iterator pIt = m_aControls.begin();
78 :
79 0 : while ( pIt != m_aControls.end() )
80 : {
81 0 : SwFrameControlPtrMap& rMap = pIt->second;
82 0 : rMap.erase(pFrm);
83 0 : ++pIt;
84 : }
85 0 : }
86 :
87 264 : void SwFrameControlsManager::RemoveControlsByType( FrameControlType eType, const SwFrm* pFrm )
88 : {
89 264 : SwFrameControlPtrMap& rMap = m_aControls[eType];
90 264 : rMap.erase(pFrm);
91 264 : }
92 :
93 0 : void SwFrameControlsManager::HideControls( FrameControlType eType )
94 : {
95 0 : SwFrameControlPtrMap::iterator pIt = m_aControls[eType].begin();
96 0 : while ( pIt != m_aControls[eType].end() )
97 : {
98 0 : pIt->second->ShowAll( false );
99 0 : ++pIt;
100 : }
101 0 : }
102 :
103 0 : void SwFrameControlsManager::SetReadonlyControls( bool bReadonly )
104 : {
105 0 : map< FrameControlType, SwFrameControlPtrMap >::iterator pIt = m_aControls.begin();
106 :
107 0 : while ( pIt != m_aControls.end() )
108 : {
109 0 : SwFrameControlPtrMap::iterator aCtrlIt = pIt->second.begin();
110 0 : while ( aCtrlIt != pIt->second.end() )
111 : {
112 0 : aCtrlIt->second->SetReadonly( bReadonly );
113 0 : ++aCtrlIt;
114 : }
115 0 : ++pIt;
116 : }
117 0 : }
118 :
119 0 : void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrm* pPageFrm, FrameControlType eType, Point aOffset )
120 : {
121 : OSL_ASSERT( eType == Header || eType == Footer );
122 :
123 : // Check if we already have the control
124 0 : SwFrameControlPtr pControl;
125 0 : const bool bHeader = ( eType == Header );
126 :
127 0 : SwFrameControlPtrMap& rControls = m_aControls[eType];
128 :
129 0 : SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrm);
130 0 : if (lb != rControls.end() && !(rControls.key_comp()(pPageFrm, lb->first)))
131 0 : pControl = lb->second;
132 : else
133 : {
134 0 : SwFrameControlPtr pNewControl( new SwHeaderFooterWin( m_pEditWin, pPageFrm, bHeader ) );
135 0 : const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
136 0 : pNewControl->SetReadonly( pViewOpt->IsReadonly() );
137 0 : rControls.insert(lb, make_pair(pPageFrm, pNewControl));
138 0 : pControl.swap( pNewControl );
139 : }
140 :
141 0 : Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrm->Frm().SVRect() );
142 :
143 0 : SwHeaderFooterWin* pHFWin = dynamic_cast< SwHeaderFooterWin* >( pControl.get() );
144 : assert(pHFWin->IsHeader() == bHeader);
145 0 : pHFWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
146 :
147 0 : if ( !pHFWin->IsVisible() )
148 0 : pControl->ShowAll( true );
149 0 : }
150 :
151 23 : void SwFrameControlsManager::SetPageBreakControl( const SwPageFrm* pPageFrm )
152 : {
153 : // Check if we already have the control
154 23 : SwFrameControlPtr pControl;
155 :
156 23 : SwFrameControlPtrMap& rControls = m_aControls[PageBreak];
157 :
158 23 : SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrm);
159 23 : if (lb != rControls.end() && !(rControls.key_comp()(pPageFrm, lb->first)))
160 10 : pControl = lb->second;
161 : else
162 : {
163 13 : SwFrameControlPtr pNewControl( new SwPageBreakWin( m_pEditWin, pPageFrm ) );
164 13 : const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
165 13 : pNewControl->SetReadonly( pViewOpt->IsReadonly() );
166 :
167 13 : rControls.insert(lb, make_pair(pPageFrm, pNewControl));
168 :
169 13 : pControl.swap( pNewControl );
170 : }
171 :
172 23 : SwPageBreakWin* pWin = dynamic_cast< SwPageBreakWin* >( pControl.get() );
173 23 : pWin->UpdatePosition();
174 23 : if ( !pWin->IsVisible() )
175 23 : pControl->ShowAll( true );
176 23 : }
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|