Line data Source code
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 : */
12 :
13 : #include <edtwin.hxx>
14 : #include <FrameControlsManager.hxx>
15 : #include <HeaderFooterWin.hxx>
16 : #include <PageBreakWin.hxx>
17 : #include <pagefrm.hxx>
18 : #include <viewopt.hxx>
19 : #include <view.hxx>
20 : #include <wrtsh.hxx>
21 :
22 : using namespace std;
23 :
24 793 : SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) :
25 : m_pEditWin( pEditWin ),
26 793 : m_aControls( )
27 : {
28 793 : }
29 :
30 792 : SwFrameControlsManager::~SwFrameControlsManager()
31 : {
32 792 : }
33 :
34 0 : SwFrameControlsManager::SwFrameControlsManager( const SwFrameControlsManager& rCopy ) :
35 : m_pEditWin( rCopy.m_pEditWin ),
36 0 : m_aControls( rCopy.m_aControls )
37 : {
38 0 : }
39 :
40 0 : const SwFrameControlsManager& SwFrameControlsManager::operator=( const SwFrameControlsManager& rCopy )
41 : {
42 0 : m_pEditWin = rCopy.m_pEditWin;
43 0 : m_aControls = rCopy.m_aControls;
44 0 : return *this;
45 : }
46 :
47 2436 : SwFrameControlPtr SwFrameControlsManager::GetControl( FrameControlType eType, const SwFrm* pFrm )
48 : {
49 2436 : SwFrameControlPtrMap& rControls = m_aControls[eType];
50 :
51 2436 : SwFrameControlPtrMap::iterator aIt = rControls.find(pFrm);
52 :
53 2436 : if (aIt != rControls.end())
54 0 : return aIt->second;
55 :
56 2436 : return SwFrameControlPtr();
57 : }
58 :
59 9 : void SwFrameControlsManager::RemoveControls( const SwFrm* pFrm )
60 : {
61 9 : map< FrameControlType, SwFrameControlPtrMap >::iterator pIt = m_aControls.begin();
62 :
63 25 : while ( pIt != m_aControls.end() )
64 : {
65 7 : SwFrameControlPtrMap& rMap = pIt->second;
66 7 : rMap.erase(pFrm);
67 7 : ++pIt;
68 : }
69 9 : }
70 :
71 6160 : void SwFrameControlsManager::RemoveControlsByType( FrameControlType eType, const SwFrm* pFrm )
72 : {
73 6160 : SwFrameControlPtrMap& rMap = m_aControls[eType];
74 6160 : rMap.erase(pFrm);
75 6160 : }
76 :
77 0 : void SwFrameControlsManager::HideControls( FrameControlType eType )
78 : {
79 0 : SwFrameControlPtrMap::iterator pIt = m_aControls[eType].begin();
80 0 : while ( pIt != m_aControls[eType].end() )
81 : {
82 0 : pIt->second->ShowAll( false );
83 0 : ++pIt;
84 : }
85 0 : }
86 :
87 0 : void SwFrameControlsManager::SetReadonlyControls( bool bReadonly )
88 : {
89 0 : map< FrameControlType, SwFrameControlPtrMap >::iterator pIt = m_aControls.begin();
90 :
91 0 : while ( pIt != m_aControls.end() )
92 : {
93 0 : SwFrameControlPtrMap::iterator aCtrlIt = pIt->second.begin();
94 0 : while ( aCtrlIt != pIt->second.end() )
95 : {
96 0 : aCtrlIt->second->SetReadonly( bReadonly );
97 0 : ++aCtrlIt;
98 : }
99 0 : ++pIt;
100 : }
101 0 : }
102 :
103 0 : void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrm* pPageFrm, FrameControlType eType, Point aOffset )
104 : {
105 : OSL_ASSERT( eType == Header || eType == Footer );
106 :
107 : // Check if we already have the control
108 0 : SwFrameControlPtr pControl;
109 0 : const bool bHeader = ( eType == Header );
110 :
111 0 : SwFrameControlPtrMap& rControls = m_aControls[eType];
112 :
113 0 : SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrm);
114 0 : if (lb != rControls.end() && !(rControls.key_comp()(pPageFrm, lb->first)))
115 0 : pControl = lb->second;
116 : else
117 : {
118 0 : SwFrameControlPtr pNewControl( new SwHeaderFooterWin( m_pEditWin, pPageFrm, bHeader ) );
119 0 : const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
120 0 : pNewControl->SetReadonly( pViewOpt->IsReadonly() );
121 0 : rControls.insert(lb, make_pair(pPageFrm, pNewControl));
122 0 : pControl.swap( pNewControl );
123 : }
124 :
125 0 : Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrm->Frm().SVRect() );
126 :
127 0 : SwHeaderFooterWin* pHFWin = dynamic_cast< SwHeaderFooterWin* >( pControl.get() );
128 : assert(pHFWin->IsHeader() == bHeader);
129 0 : pHFWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
130 :
131 0 : if ( !pHFWin->IsVisible() )
132 0 : pControl->ShowAll( true );
133 0 : }
134 :
135 48 : void SwFrameControlsManager::SetPageBreakControl( const SwPageFrm* pPageFrm )
136 : {
137 : // Check if we already have the control
138 48 : SwFrameControlPtr pControl;
139 :
140 48 : SwFrameControlPtrMap& rControls = m_aControls[PageBreak];
141 :
142 48 : SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrm);
143 48 : if (lb != rControls.end() && !(rControls.key_comp()(pPageFrm, lb->first)))
144 19 : pControl = lb->second;
145 : else
146 : {
147 29 : SwFrameControlPtr pNewControl( new SwPageBreakWin( m_pEditWin, pPageFrm ) );
148 29 : const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
149 29 : pNewControl->SetReadonly( pViewOpt->IsReadonly() );
150 :
151 29 : rControls.insert(lb, make_pair(pPageFrm, pNewControl));
152 :
153 29 : pControl.swap( pNewControl );
154 : }
155 :
156 48 : SwPageBreakWin* pWin = dynamic_cast< SwPageBreakWin* >( pControl.get() );
157 48 : pWin->UpdatePosition();
158 48 : if ( !pWin->IsVisible() )
159 48 : pControl->ShowAll( true );
160 147 : }
161 :
162 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|