Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sot/storage.hxx>
30 : : #include <sfx2/linkmgr.hxx>
31 : : #include <com/sun/star/uno/Sequence.h>
32 : : #include <doc.hxx>
33 : : #include <swtypes.hxx>
34 : : #include <swserv.hxx>
35 : : #include <swbaslnk.hxx>
36 : : #include <mvsave.hxx>
37 : : #include <IMark.hxx>
38 : : #include <bookmrk.hxx>
39 : : #include <pam.hxx>
40 : : #include <shellio.hxx>
41 : : #include <swerror.h>
42 : :
43 : : using namespace ::com::sun::star;
44 : :
45 : : SV_IMPL_REF( SwServerObject )
46 : :
47 : 0 : SwServerObject::~SwServerObject()
48 : : {
49 [ # # ]: 0 : }
50 : :
51 : :
52 : 0 : sal_Bool SwServerObject::GetData( uno::Any & rData,
53 : : const String & rMimeType, sal_Bool )
54 : : {
55 : 0 : sal_Bool bRet = sal_False;
56 : 0 : WriterRef xWrt;
57 [ # # # ]: 0 : switch( SotExchange::GetFormatIdFromMimeType( rMimeType ) )
[ # # ]
58 : : {
59 : : case FORMAT_STRING:
60 [ # # ][ # # ]: 0 : ::GetASCWriter( aEmptyStr, String(), xWrt );
[ # # ]
61 : 0 : break;
62 : :
63 : : case FORMAT_RTF:
64 : : // mba: no BaseURL for data exchange
65 [ # # ][ # # ]: 0 : ::GetRTFWriter( aEmptyStr, String(), xWrt );
[ # # ]
66 : 0 : break;
67 : : }
68 : :
69 [ # # ]: 0 : if( xWrt.Is() )
70 : : {
71 : 0 : SwPaM* pPam = 0;
72 [ # # # # : 0 : switch( eType )
# ]
73 : : {
74 : : case BOOKMARK_SERVER:
75 [ # # ][ # # ]: 0 : if( CNTNT_TYPE.pBkmk->IsExpanded() )
76 : : {
77 : : // Span area
78 : 0 : pPam = new SwPaM( CNTNT_TYPE.pBkmk->GetMarkPos(),
79 [ # # ][ # # ]: 0 : CNTNT_TYPE.pBkmk->GetOtherMarkPos() );
[ # # ][ # # ]
80 : : }
81 : 0 : break;
82 : :
83 : : case TABLE_SERVER:
84 : : pPam = new SwPaM( *CNTNT_TYPE.pTblNd,
85 [ # # ][ # # ]: 0 : *CNTNT_TYPE.pTblNd->EndOfSectionNode() );
86 : 0 : break;
87 : :
88 : : case SECTION_SERVER:
89 [ # # ][ # # ]: 0 : pPam = new SwPaM( SwPosition( *CNTNT_TYPE.pSectNd ) );
[ # # ][ # # ]
90 [ # # ]: 0 : pPam->Move( fnMoveForward );
91 [ # # ]: 0 : pPam->SetMark();
92 [ # # ]: 0 : pPam->GetPoint()->nNode = *CNTNT_TYPE.pSectNd->EndOfSectionNode();
93 [ # # ]: 0 : pPam->Move( fnMoveBackward );
94 : 0 : break;
95 : 0 : case NONE_SERVER: break;
96 : : }
97 : :
98 [ # # ]: 0 : if( pPam )
99 : : {
100 : : // Create stream
101 [ # # ]: 0 : SvMemoryStream aMemStm( 65535, 65535 );
102 [ # # ]: 0 : SwWriter aWrt( aMemStm, *pPam, sal_False );
103 [ # # ][ # # ]: 0 : if( !IsError( aWrt.Write( xWrt )) )
104 : : {
105 [ # # ]: 0 : aMemStm << '\0'; // append a zero char
106 : : rData <<= uno::Sequence< sal_Int8 >(
107 [ # # ]: 0 : (sal_Int8*)aMemStm.GetData(),
108 [ # # ][ # # ]: 0 : aMemStm.Seek( STREAM_SEEK_TO_END ) );
[ # # ][ # # ]
109 : 0 : bRet = sal_True;
110 : : }
111 : :
112 [ # # ][ # # ]: 0 : delete pPam;
[ # # ][ # # ]
113 : : }
114 : : }
115 [ # # ]: 0 : return bRet;
116 : : }
117 : :
118 : :
119 : 0 : sal_Bool SwServerObject::SetData( const String & ,
120 : : const uno::Any& )
121 : : {
122 : : // set new data into the "server" -> at first nothing to do
123 : 0 : return sal_False;
124 : : }
125 : :
126 : :
127 : 0 : void SwServerObject::SendDataChanged( const SwPosition& rPos )
128 : : {
129 : : // Is someone interested in our changes?
130 [ # # ]: 0 : if( HasDataLinks() )
131 : : {
132 : 0 : int bCall = sal_False;
133 : 0 : const SwStartNode* pNd = 0;
134 [ # # # # : 0 : switch( eType )
# ]
135 : : {
136 : : case BOOKMARK_SERVER:
137 [ # # ]: 0 : if( CNTNT_TYPE.pBkmk->IsExpanded() )
138 : : {
139 : 0 : bCall = CNTNT_TYPE.pBkmk->GetMarkStart() <= rPos
140 [ # # ][ # # ]: 0 : && rPos < CNTNT_TYPE.pBkmk->GetMarkEnd();
141 : : }
142 : 0 : break;
143 : :
144 : 0 : case TABLE_SERVER: pNd = CNTNT_TYPE.pTblNd; break;
145 : 0 : case SECTION_SERVER: pNd = CNTNT_TYPE.pSectNd; break;
146 : 0 : case NONE_SERVER: break;
147 : : }
148 [ # # ]: 0 : if( pNd )
149 : : {
150 : 0 : sal_uLong nNd = rPos.nNode.GetIndex();
151 [ # # ][ # # ]: 0 : bCall = pNd->GetIndex() < nNd && nNd < pNd->EndOfSectionIndex();
152 : : }
153 : :
154 [ # # ]: 0 : if( bCall )
155 : : {
156 : : // Recognize recursions and flag them
157 : 0 : IsLinkInServer( 0 );
158 : 0 : SvLinkSource::NotifyDataChanged();
159 : : }
160 : : }
161 : 0 : }
162 : :
163 : :
164 : 0 : void SwServerObject::SendDataChanged( const SwPaM& rRange )
165 : : {
166 : : // Is someone interested in our changes?
167 [ # # ]: 0 : if( HasDataLinks() )
168 : : {
169 : 0 : int bCall = sal_False;
170 : 0 : const SwStartNode* pNd = 0;
171 : 0 : const SwPosition* pStt = rRange.Start(), *pEnd = rRange.End();
172 [ # # # # : 0 : switch( eType )
# ]
173 : : {
174 : : case BOOKMARK_SERVER:
175 [ # # ]: 0 : if(CNTNT_TYPE.pBkmk->IsExpanded())
176 : : {
177 : 0 : bCall = *pStt <= CNTNT_TYPE.pBkmk->GetMarkEnd()
178 [ # # ][ # # ]: 0 : && *pEnd > CNTNT_TYPE.pBkmk->GetMarkStart();
179 : : }
180 : 0 : break;
181 : :
182 : 0 : case TABLE_SERVER: pNd = CNTNT_TYPE.pTblNd; break;
183 : 0 : case SECTION_SERVER: pNd = CNTNT_TYPE.pSectNd; break;
184 : 0 : case NONE_SERVER: break;
185 : : }
186 [ # # ]: 0 : if( pNd )
187 : : {
188 : : // Is the start area within the node area?
189 : 0 : bCall = pStt->nNode.GetIndex() < pNd->EndOfSectionIndex() &&
190 [ # # ][ # # ]: 0 : pEnd->nNode.GetIndex() >= pNd->GetIndex();
191 : : }
192 : :
193 [ # # ]: 0 : if( bCall )
194 : : {
195 : : // Recognize recursions and flag them
196 : 0 : IsLinkInServer( 0 );
197 : 0 : SvLinkSource::NotifyDataChanged();
198 : : }
199 : : }
200 : 0 : }
201 : :
202 : :
203 : 0 : sal_Bool SwServerObject::IsLinkInServer( const SwBaseLink* pChkLnk ) const
204 : : {
205 : 0 : sal_uLong nSttNd = 0, nEndNd = 0;
206 : 0 : xub_StrLen nStt = 0;
207 : 0 : xub_StrLen nEnd = 0;
208 : 0 : const SwNode* pNd = 0;
209 : 0 : const SwNodes* pNds = 0;
210 : :
211 [ # # # # : 0 : switch( eType )
# ]
212 : : {
213 : : case BOOKMARK_SERVER:
214 [ # # ]: 0 : if( CNTNT_TYPE.pBkmk->IsExpanded() )
215 : : {
216 : 0 : const SwPosition* pStt = &CNTNT_TYPE.pBkmk->GetMarkStart(),
217 : 0 : * pEnd = &CNTNT_TYPE.pBkmk->GetMarkEnd();
218 : :
219 : 0 : nSttNd = pStt->nNode.GetIndex();
220 : 0 : nStt = pStt->nContent.GetIndex();
221 : 0 : nEndNd = pEnd->nNode.GetIndex();
222 : 0 : nEnd = pEnd->nContent.GetIndex();
223 : 0 : pNds = &pStt->nNode.GetNodes();
224 : : }
225 : 0 : break;
226 : :
227 : 0 : case TABLE_SERVER: pNd = CNTNT_TYPE.pTblNd; break;
228 : 0 : case SECTION_SERVER: pNd = CNTNT_TYPE.pSectNd; break;
229 : :
230 : : case SECTION_SERVER+1:
231 : 0 : return sal_True;
232 : : }
233 : :
234 [ # # ]: 0 : if( pNd )
235 : : {
236 : 0 : nSttNd = pNd->GetIndex();
237 : 0 : nEndNd = pNd->EndOfSectionIndex();
238 : 0 : nStt = 0, nEnd = USHRT_MAX;
239 : 0 : pNds = &pNd->GetNodes();
240 : : }
241 : :
242 [ # # ][ # # ]: 0 : if( nSttNd && nEndNd )
243 : : {
244 : : // Get LinkManager
245 : 0 : const ::sfx2::SvBaseLinks& rLnks = pNds->GetDoc()->GetLinkManager().GetLinks();
246 : :
247 : : // To avoid recursions: convert ServerType!
248 : 0 : SwServerObject::ServerModes eSave = eType;
249 [ # # ]: 0 : if( !pChkLnk )
250 : 0 : ((SwServerObject*)this)->eType = NONE_SERVER;
251 [ # # ]: 0 : for( sal_uInt16 n = rLnks.size(); n; )
252 : : {
253 : 0 : const ::sfx2::SvBaseLink* pLnk = &(*rLnks[ --n ]);
254 [ # # # # : 0 : if( pLnk && OBJECT_CLIENT_GRF != pLnk->GetObjType() &&
# # # # ]
[ # # ][ # # ]
255 : 0 : pLnk->ISA( SwBaseLink ) &&
256 : 0 : !((SwBaseLink*)pLnk)->IsNoDataFlag() &&
257 : 0 : ((SwBaseLink*)pLnk)->IsInRange( nSttNd, nEndNd, nStt, nEnd ))
258 : : {
259 [ # # ]: 0 : if( pChkLnk )
260 : : {
261 [ # # # # ]: 0 : if( pLnk == pChkLnk ||
[ # # ]
262 : 0 : ((SwBaseLink*)pLnk)->IsRecursion( pChkLnk ) )
263 : 0 : return sal_True;
264 : : }
265 [ # # ]: 0 : else if( ((SwBaseLink*)pLnk)->IsRecursion( (SwBaseLink*)pLnk ) )
266 : 0 : ((SwBaseLink*)pLnk)->SetNoDataFlag();
267 : : }
268 : : }
269 [ # # ]: 0 : if( !pChkLnk )
270 : : // *((int*)&eType) = eSave;
271 : 0 : ((SwServerObject*)this)->eType = eSave;
272 : : }
273 : :
274 : 0 : return sal_False;
275 : : }
276 : :
277 : 0 : void SwServerObject::SetNoServer()
278 : : {
279 [ # # ][ # # ]: 0 : if(eType == BOOKMARK_SERVER && CNTNT_TYPE.pBkmk)
280 : : {
281 [ # # ]: 0 : ::sw::mark::DdeBookmark* const pDdeBookmark = dynamic_cast< ::sw::mark::DdeBookmark* >(CNTNT_TYPE.pBkmk);
282 [ # # ]: 0 : if(pDdeBookmark)
283 : : {
284 : 0 : CNTNT_TYPE.pBkmk = 0, eType = NONE_SERVER;
285 : 0 : pDdeBookmark->SetRefObject(NULL);
286 : : }
287 : : }
288 : 0 : }
289 : :
290 : 0 : void SwServerObject::SetDdeBookmark( ::sw::mark::IMark& rBookmark)
291 : : {
292 [ # # ]: 0 : ::sw::mark::DdeBookmark* const pDdeBookmark = dynamic_cast< ::sw::mark::DdeBookmark* >(&rBookmark);
293 [ # # ]: 0 : if(pDdeBookmark)
294 : : {
295 : 0 : eType = BOOKMARK_SERVER;
296 : 0 : CNTNT_TYPE.pBkmk = &rBookmark;
297 : 0 : pDdeBookmark->SetRefObject(this);
298 : : }
299 : : else
300 : : OSL_FAIL("SwServerObject::SetNoServer(..)"
301 : : " - setting an bookmark that is not DDE-capable");
302 : 0 : }
303 : :
304 : :
305 : :
306 : 181022 : SwDataChanged::SwDataChanged( const SwPaM& rPam, sal_uInt16 nTyp )
307 : 181022 : : pPam( &rPam ), pPos( 0 ), pDoc( rPam.GetDoc() ), nType( nTyp )
308 : : {
309 : 181022 : nNode = rPam.GetPoint()->nNode.GetIndex();
310 : 181022 : nCntnt = rPam.GetPoint()->nContent.GetIndex();
311 : 181022 : }
312 : :
313 : :
314 : 1268 : SwDataChanged::SwDataChanged( SwDoc* pDc, const SwPosition& rPos, sal_uInt16 nTyp )
315 : 1268 : : pPam( 0 ), pPos( &rPos ), pDoc( pDc ), nType( nTyp )
316 : : {
317 : 1268 : nNode = rPos.nNode.GetIndex();
318 : 1268 : nCntnt = rPos.nContent.GetIndex();
319 : 1268 : }
320 : :
321 : 182290 : SwDataChanged::~SwDataChanged()
322 : : {
323 : : // JP 09.04.96: Only if the Layout is available (thus during input)
324 [ + + ]: 182290 : if( pDoc->GetCurrentViewShell() ) //swmod 071108//swmod 071225
325 : : {
326 [ + - ]: 12338 : const ::sfx2::SvLinkSources& rServers = pDoc->GetLinkManager().GetServers();
327 : :
328 [ + - ]: 12338 : ::sfx2::SvLinkSources aTemp(rServers);
329 [ # # ][ + - ]: 12338 : for( ::sfx2::SvLinkSources::const_iterator it = aTemp.begin(); it != aTemp.end(); ++it )
[ - + ]
330 : : {
331 [ # # ]: 0 : ::sfx2::SvLinkSourceRef refObj( *it );
332 : : // Any one else interested in the Object?
333 [ # # ][ # # ]: 0 : if( refObj->HasDataLinks() && refObj->ISA( SwServerObject ))
[ # # ][ # # ]
[ # # ][ # # ]
334 : : {
335 : 0 : SwServerObject& rObj = *(SwServerObject*)&refObj;
336 [ # # ]: 0 : if( pPos )
337 [ # # ]: 0 : rObj.SendDataChanged( *pPos );
338 : : else
339 [ # # ]: 0 : rObj.SendDataChanged( *pPam );
340 : : }
341 : :
342 : : // We shouldn't have a connection anymore
343 [ # # ][ # # ]: 0 : if( !refObj->HasDataLinks() )
344 : : {
345 : : // Then remove from the list
346 [ # # ][ # # ]: 0 : pDoc->GetLinkManager().RemoveServer( *it );
[ # # ]
347 : : }
348 [ # # ]: 12338 : }
349 : : }
350 : 182290 : }
351 : :
352 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|