xref: /aoo42x/main/sw/source/ui/uiview/view.cxx (revision 1d2b8aac)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
29 #include <stdlib.h>
30 #include <hintids.hxx>
31 #include <rtl/logfile.hxx>
32 #include <vcl/graph.hxx>
33 #include <vcl/inputctx.hxx>
34 #include <basic/sbxobj.hxx>
35 #include <svl/eitem.hxx>
36 #include <unotools/undoopt.hxx>
37 #include <unotools/lingucfg.hxx>
38 #include <unotools/useroptions.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <sfx2/printer.hxx>
43 #include <sfx2/app.hxx>
44 #include <svx/ruler.hxx>
45 #include <editeng/protitem.hxx>
46 #include <svx/fmshell.hxx>
47 #include <svx/extrusionbar.hxx>
48 #include <svx/fontworkbar.hxx>
49 #include <unotxvw.hxx>
50 #include <cmdid.h>
51 #include <swhints.hxx>
52 #include <swmodule.hxx>
53 #include <inputwin.hxx>
54 #include <chartins.hxx>
55 #include <uivwimp.hxx>
56 #include <uitool.hxx>
57 #include <edtwin.hxx>
58 #include <textsh.hxx>
59 #include <listsh.hxx>
60 #include <tabsh.hxx>
61 #include <grfsh.hxx>
62 #include <mediash.hxx>
63 #include <docsh.hxx>
64 #include <frmsh.hxx>
65 #include <olesh.hxx>
66 #include <drawsh.hxx>
67 #include <drawbase.hxx>
68 #include <drformsh.hxx>
69 #include <drwtxtsh.hxx>
70 #include <beziersh.hxx>
71 #include <globdoc.hxx>
72 #include <scroll.hxx>
73 #include <navipi.hxx>
74 #include <gloshdl.hxx>
75 #include <usrpref.hxx>
76 #include <srcview.hxx>
77 #include <doc.hxx>
78 #include <IDocumentUndoRedo.hxx>
79 #include <drawdoc.hxx>
80 #include <wdocsh.hxx>
81 #include <wview.hxx>
82 #include <workctrl.hxx>
83 #include <wrtsh.hxx>
84 #include <barcfg.hxx>
85 #include <pview.hxx>
86 #include <swdtflvr.hxx>
87 #include <view.hrc>
88 #include <globdoc.hrc>
89 #include <frmui.hrc>
90 #include <cfgitems.hxx>
91 #include <prtopt.hxx>
92 #include <linguistic/lngprops.hxx>
93 #include <editeng/unolingu.hxx>
94 //#include <sfx2/app.hxx>
95 #include <com/sun/star/frame/FrameSearchFlag.hpp>
96 #include <com/sun/star/scanner/ScannerContext.hpp>
97 #include <com/sun/star/scanner/XScannerManager.hpp>
98 #include <toolkit/helper/vclunohelper.hxx>
99 #include <rtl/ustrbuf.hxx>
100 #include <xmloff/xmluconv.hxx>
101 
102 #include "formatclipboard.hxx"
103 #include <PostItMgr.hxx>
104 #include <annotsh.hxx>
105 
106 #include <fldbas.hxx>
107 
108 #include <unomid.h>
109 
110 #include <com/sun/star/document/XDocumentProperties.hpp>
111 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
112 
113 
114 using namespace ::com::sun::star;
115 using namespace ::com::sun::star::uno;
116 using namespace ::com::sun::star::lang;
117 using namespace ::com::sun::star::scanner;
118 using ::rtl::OUString;
119 using ::rtl::OUStringBuffer;
120 
121 
122 extern sal_Bool bNoInterrupt; // in mainwn.cxx
123 
124 #define SWVIEWFLAGS ( SFX_VIEW_CAN_PRINT| 				\
125 					  SFX_VIEW_HAS_PRINTOPTIONS)
126 
127 /*--------------------------------------------------------------------
128 	Description: statics
129  --------------------------------------------------------------------*/
130 
131 int bDocSzUpdated = 1;
132 
133 SvxSearchItem*	SwView::pSrchItem 	= 0;
134 
135 sal_uInt16 			SwView::nInsertCtrlState 		= FN_INSERT_TABLE;
136 sal_uInt16 			SwView::nWebInsertCtrlState		= FN_INSERT_TABLE;
137 sal_uInt16 			SwView::nInsertObjectCtrlState 	= SID_INSERT_DIAGRAM;
138 
139 sal_Bool			SwView::bExtra		= sal_False;
140 sal_Bool			SwView::bFound		= sal_False;
141 sal_Bool			SwView::bJustOpened	= sal_False;
142 
143 
144 SvxSearchDialog*	SwView::pSrchDlg	= 0;
145 SearchAttrItemList* SwView::pSrchList	= 0;
146 SearchAttrItemList* SwView::pReplList	= 0;
147 
DBG_NAME(viewhdl)148 DBG_NAME(viewhdl)
149 
150 /*--------------------------------------------------------------------
151 	Description:
152  --------------------------------------------------------------------*/
153 
154 inline SfxDispatcher &SwView::GetDispatcher()
155 {
156 	return *GetViewFrame()->GetDispatcher();
157 }
158 
159 /*--------------------------------------------------------------------
160 	Description:
161  --------------------------------------------------------------------*/
162 
ImpSetVerb(int nSelType)163 void SwView::ImpSetVerb( int nSelType )
164 {
165 	sal_Bool bResetVerbs = bVerbsActive;
166 	if ( !GetViewFrame()->GetFrame().IsInPlace() &&
167 		 (nsSelectionType::SEL_OLE|nsSelectionType::SEL_GRF) & nSelType )
168 	{
169 		if ( !pWrtShell->IsSelObjProtected(FLYPROTECT_CONTENT) )
170 		{
171 			if ( nSelType & nsSelectionType::SEL_OLE )
172 			{
173 				SetVerbs( GetWrtShell().GetOLEObject()->getSupportedVerbs() );
174 				bVerbsActive = sal_True;
175 				bResetVerbs = sal_False;
176 			}
177 		}
178 	}
179 	if ( bResetVerbs )
180 	{
181 		SetVerbs( Sequence< embed::VerbDescriptor >() );
182 		bVerbsActive = sal_False;
183 	}
184 }
185 
186 /*--------------------------------------------------------------------
187 	Description called by the SwEditWin when it gets the focus
188  --------------------------------------------------------------------*/
189 
GotFocus() const190 void SwView::GotFocus() const
191 {
192 	// if we got the focus, and the form shell *is* on the top of the dispatcher
193 	// stack, then we need to rebuild the stack (the form shell doesn't belong to
194 	// the top then)
195 	const SfxDispatcher& rDispatcher = const_cast< SwView* >( this )->GetDispatcher();
196 	SfxShell* pTopShell = rDispatcher.GetShell( 0 );
197 	FmFormShell* pAsFormShell = PTR_CAST( FmFormShell, pTopShell );
198 	if ( pAsFormShell )
199 	{
200 		pAsFormShell->ForgetActiveControl();
201 		const_cast< SwView* >( this )->AttrChangedNotify( pWrtShell );
202 	}
203 	else if ( mpPostItMgr )
204 	{
205 		SwAnnotationShell* pAsAnnotationShell = PTR_CAST( SwAnnotationShell, pTopShell );
206 		if ( pAsAnnotationShell )
207 		{
208 			mpPostItMgr->SetActiveSidebarWin(0);
209 			const_cast< SwView* >( this )->AttrChangedNotify( pWrtShell );
210 		}
211 	}
212 	if( GetWrtShellPtr() )
213 	{
214 		SwWrtShell& rWrtShell = GetWrtShell();
215 		rWrtShell.GetDoc()->SetCurrentViewShell( GetWrtShellPtr() );
216 		rWrtShell.GetDoc()->set( IDocumentSettingAccess::BROWSE_MODE,
217 								 rWrtShell.GetViewOptions()->getBrowseMode() );
218 	}
219 }
220 
221 /*--------------------------------------------------------------------
222 	Description:
223 	called by the FormShell when a form control is focused. This is
224 	a request to put the form shell on the top of the dispatcher
225 	stack
226  --------------------------------------------------------------------*/
227 
IMPL_LINK(SwView,FormControlActivated,FmFormShell *,EMPTYARG)228 IMPL_LINK( SwView, FormControlActivated, FmFormShell*, EMPTYARG )
229 {
230 	// if a form control has been activated, and the form shell is not on the top
231 	// of the dispatcher stack, then we need to activate it
232 	const SfxDispatcher& rDispatcher = GetDispatcher();
233 	const SfxShell* pTopShell = rDispatcher.GetShell( 0 );
234 	const FmFormShell* pAsFormShell = PTR_CAST( FmFormShell, pTopShell );
235 	if ( !pAsFormShell )
236 	{
237 		// if we're editing text currently, cancel this
238 		SdrView *pSdrView = pWrtShell ? pWrtShell->GetDrawView() : NULL;
239 		if ( pSdrView && pSdrView->IsTextEdit() )
240 			pSdrView->SdrEndTextEdit( sal_True );
241 
242 		const_cast< SwView* >( this )->AttrChangedNotify( pWrtShell );
243 	}
244 
245 	return 0L;
246 }
247 
SelectShell()248 void SwView::SelectShell()
249 {
250 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
251 //
252 //		Achtung: SelectShell fuer die WebView mitpflegen
253 //
254 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
255 
256 		  if(bInDtor)
257         return;
258 	// Entscheidung, ob UpdateTable gerufen werden muss
259 	sal_Bool bUpdateTable = sal_False;
260 	const SwFrmFmt* pCurTableFmt = pWrtShell->GetTableFmt();
261 	if(pCurTableFmt && pCurTableFmt != pLastTableFormat)
262 	{
263 		bUpdateTable = sal_True; // kann erst spaeter ausgefuehrt werden
264 	}
265 	pLastTableFormat = pCurTableFmt;
266 
267 	// SEL_TBL und SEL_TBL_CELLS koennen verodert sein!
268 	int nNewSelectionType = (pWrtShell->GetSelectionType()
269 								& ~nsSelectionType::SEL_TBL_CELLS);
270 
271 	if ( pFormShell && pFormShell->IsActiveControl() )
272 		nNewSelectionType |= nsSelectionType::SEL_FOC_FRM_CTRL;
273 
274 	if ( nNewSelectionType == nSelectionType )
275 	{
276 		GetViewFrame()->GetBindings().InvalidateAll( sal_False );
277 		if ( nSelectionType & nsSelectionType::SEL_OLE ||
278 			 nSelectionType & nsSelectionType::SEL_GRF )
279 			// Fuer Grafiken und OLE kann sich natuerlich das Verb aendern!
280 			ImpSetVerb( nNewSelectionType );
281 	}
282 	else
283 	{
284 
285 		SfxDispatcher &rDispatcher = GetDispatcher();
286 		SwToolbarConfigItem *pBarCfg = SW_MOD()->GetToolbarConfig();
287 
288 	//	DELETEZ(pxSelectionObj); // Selektionsobjekt loeschen
289 		if ( pShell )
290 		{
291 			rDispatcher.Flush(); // alle gecachten Shells wirklich loeschen
292 
293 			// Zur alten Selektion merken welche Toolbar sichtbar war
294 			sal_uInt16 nId = static_cast< sal_uInt16 >( rDispatcher.GetObjectBarId( SFX_OBJECTBAR_OBJECT ));
295 			if ( nId )
296 				pBarCfg->SetTopToolbar( nSelectionType, nId );
297 
298 			SfxShell *pSfxShell;
299 			for ( sal_uInt16 i = 0; sal_True; ++i )
300 			{
301 				pSfxShell = rDispatcher.GetShell( i );
302 				if  (  pSfxShell->ISA( SwBaseShell )
303                     || pSfxShell->ISA( SwDrawTextShell )
304                     || pSfxShell->ISA( svx::ExtrusionBar )
305                     || pSfxShell->ISA( svx::FontworkBar )
306                     || pSfxShell->ISA( SwAnnotationShell )
307                     )
308                 {
309                     rDispatcher.Pop( *pSfxShell, SFX_SHELL_POP_DELETE );
310                 }
311                 else if ( pSfxShell->ISA( FmFormShell ) )
312                 {
313                     rDispatcher.Pop( *pSfxShell );
314                 }
315                 else
316 					break;
317 			}
318 		}
319 
320 		sal_Bool bInitFormShell = sal_False;
321 		if (!pFormShell)
322 		{
323 			bInitFormShell = sal_True;
324 			pFormShell = new FmFormShell( this );
325 			pFormShell->SetControlActivationHandler( LINK( this, SwView, FormControlActivated ) );
326 			StartListening(*pFormShell);
327 		}
328 
329 		sal_Bool bSetExtInpCntxt = sal_False;
330 		nSelectionType = nNewSelectionType;
331 		ShellModes eShellMode;
332 
333 		if ( !( nSelectionType & nsSelectionType::SEL_FOC_FRM_CTRL ) )
334 			rDispatcher.Push( *pFormShell );
335 
336 		if ( nSelectionType & nsSelectionType::SEL_OLE )
337 		{
338 			eShellMode = SHELL_MODE_OBJECT;
339 			pShell = new SwOleShell( *this );
340 			rDispatcher.Push( *pShell );
341 		}
342 		else if ( nSelectionType & nsSelectionType::SEL_FRM
343 			|| nSelectionType & nsSelectionType::SEL_GRF)
344 		{
345 			eShellMode = SHELL_MODE_FRAME;
346 			pShell = new SwFrameShell( *this );
347 			rDispatcher.Push( *pShell );
348 			if(nSelectionType & nsSelectionType::SEL_GRF )
349 			{
350 				eShellMode = SHELL_MODE_GRAPHIC;
351 				pShell = new SwGrfShell( *this );
352 				rDispatcher.Push( *pShell );
353 			}
354 		}
355 		else if ( nSelectionType & nsSelectionType::SEL_DRW )
356 		{
357 			eShellMode = SHELL_MODE_DRAW;
358 			pShell = new SwDrawShell( *this );
359 			rDispatcher.Push( *pShell );
360 
361 			if ( nSelectionType & nsSelectionType::SEL_BEZ )
362 			{
363 				eShellMode = SHELL_MODE_BEZIER;
364 				pShell = new SwBezierShell( *this );
365 				rDispatcher.Push( *pShell );
366 			}
367 			else if( nSelectionType & nsSelectionType::SEL_MEDIA )
368 			{
369 				eShellMode = SHELL_MODE_MEDIA;
370 				pShell = new SwMediaShell( *this );
371 				rDispatcher.Push( *pShell );
372 			}
373 
374 			if (nSelectionType & nsSelectionType::SEL_EXTRUDED_CUSTOMSHAPE)
375 			{
376 				eShellMode = SHELL_MODE_EXTRUDED_CUSTOMSHAPE;
377 				pShell = new svx::ExtrusionBar(this);
378 				rDispatcher.Push( *pShell );
379 			}
380 			if (nSelectionType & nsSelectionType::SEL_FONTWORK)
381 			{
382 				eShellMode = SHELL_MODE_FONTWORK;
383 				pShell = new svx::FontworkBar(this);
384 				rDispatcher.Push( *pShell );
385 			}
386 		}
387 		else if ( nSelectionType & nsSelectionType::SEL_DRW_FORM )
388 		{
389 			eShellMode = SHELL_MODE_DRAW_FORM;
390 			pShell = new SwDrawFormShell( *this );
391 
392 			rDispatcher.Push( *pShell );
393 		}
394 		else if ( nSelectionType & nsSelectionType::SEL_DRW_TXT )
395 		{
396 			bSetExtInpCntxt = sal_True;
397 			eShellMode = SHELL_MODE_DRAWTEXT;
398 			rDispatcher.Push( *(new SwBaseShell( *this )) );
399 			pShell = new SwDrawTextShell( *this );
400 			rDispatcher.Push( *pShell );
401 		}
402 		else if ( nSelectionType & nsSelectionType::SEL_POSTIT )
403 		{
404 			eShellMode = SHELL_MODE_POSTIT;
405 			pShell = new SwAnnotationShell( *this );
406 			rDispatcher.Push( *pShell );
407 		}
408 		else
409 		{
410 			bSetExtInpCntxt = sal_True;
411 			eShellMode = SHELL_MODE_TEXT;
412 			sal_uInt32 nHelpId = 0;
413 			if ( nSelectionType & nsSelectionType::SEL_NUM )
414 			{
415 				eShellMode = SHELL_MODE_LIST_TEXT;
416 				pShell = new SwListShell( *this );
417 				nHelpId = pShell->GetHelpId();
418 				rDispatcher.Push( *pShell );
419 			}
420 			pShell = new SwTextShell(*this);
421 			if(nHelpId)
422 				pShell->SetHelpId(nHelpId);
423 			rDispatcher.Push( *pShell );
424 			if ( nSelectionType & nsSelectionType::SEL_TBL )
425 			{
426 				eShellMode = eShellMode == SHELL_MODE_LIST_TEXT ? SHELL_MODE_TABLE_LIST_TEXT
427 														: SHELL_MODE_TABLE_TEXT;
428 				pShell = new SwTableShell( *this );
429 				rDispatcher.Push( *pShell );
430 			}
431 		}
432 
433 		if ( nSelectionType & nsSelectionType::SEL_FOC_FRM_CTRL )
434 			rDispatcher.Push( *pFormShell );
435 
436 		pViewImpl->SetShellMode(eShellMode);
437 		ImpSetVerb( nSelectionType );
438 
439 		if( !GetDocShell()->IsReadOnly() )
440 		{
441 			if( bSetExtInpCntxt && GetWrtShell().HasReadonlySel() )
442 				bSetExtInpCntxt = sal_False;
443 
444 			InputContext aCntxt( GetEditWin().GetInputContext() );
445 			aCntxt.SetOptions( bSetExtInpCntxt
446 								? (aCntxt.GetOptions() |
447 										( INPUTCONTEXT_TEXT |
448 											INPUTCONTEXT_EXTTEXTINPUT ))
449 								: (aCntxt.GetOptions() & ~
450 										( INPUTCONTEXT_TEXT |
451 											INPUTCONTEXT_EXTTEXTINPUT )) );
452 			GetEditWin().SetInputContext( aCntxt );
453 		}
454 
455 		// Zur neuen Selektion die Toolbar aktivieren, die auch beim letzten Mal
456 		// aktiviert war
457 		// Vorher muss ein Flush() sein, betrifft aber lt. MBA nicht das UI und ist
458 		// kein Performance-Problem
459 		// TODO/LATER: maybe now the Flush() command is superfluous?!
460 		rDispatcher.Flush();
461 
462 		Point aPnt = GetEditWin().OutputToScreenPixel(GetEditWin().GetPointerPosPixel());
463 		aPnt = GetEditWin().PixelToLogic(aPnt);
464 		GetEditWin().UpdatePointer(aPnt);
465 
466 		SdrView* pDView = GetWrtShell().GetDrawView();
467 		if ( bInitFormShell && pDView )
468 			pFormShell->SetView(PTR_CAST(FmFormView, pDView));
469 
470 	}
471 	// Guenstiger Zeitpunkt fuer die Kommunikation mit OLE-Objekten?
472 	if ( GetDocShell()->GetDoc()->IsOLEPrtNotifyPending() )
473 		GetDocShell()->GetDoc()->PrtOLENotify( sal_False );
474 
475 	// jetzt das Tabellen-Update
476 	if(bUpdateTable)
477 		pWrtShell->UpdateTable();
478 
479 	GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged();
480 }
481 
482 // Zusammenspiel: AttrChangedNotify() und TimeoutHdl.
483 // Falls noch Actions offen sind keine Aktualisierung, da der
484 // Cursor auf der Core-Seite im Wald stehen kann.
485 // Da wir aber keine Stati mehr liefern koennen und wollen locken wir
486 // stattdessen den Dispatcher.
487 
488 
489 
490 extern "C"
491 {
lcl_CmpIds(const void * pFirst,const void * pSecond)492 	int lcl_CmpIds( const void *pFirst, const void *pSecond)
493 	{
494 		return (*(sal_uInt16*)pFirst) - (*(sal_uInt16*)pSecond);
495 	}
496 }
497 
498 
499 
IMPL_LINK(SwView,AttrChangedNotify,SwWrtShell *,EMPTYARG)500 IMPL_LINK( SwView, AttrChangedNotify, SwWrtShell *, EMPTYARG )
501 {
502  	if ( GetEditWin().IsChainMode() )
503 		GetEditWin().SetChainMode( sal_False );
504 
505 	// Opt: Nicht wenn PaintLocked. Beim Unlock wird dafuer nocheinmal ein
506 	// Notify ausgeloest.
507 	if( !pWrtShell->IsPaintLocked() && !bNoInterrupt &&
508 		GetDocShell()->IsReadOnly() )
509 		_CheckReadonlyState();
510 
511 	// JP 19.01.99: Cursor in Readonly Bereichen
512 	if( !pWrtShell->IsPaintLocked() && !bNoInterrupt )
513 		_CheckReadonlySelection();
514 
515 	if( !bAttrChgNotified )
516 	{
517 		if ( pWrtShell->BasicActionPend() || bNoInterrupt ||
518 			 GetDispatcher().IsLocked() || // do not confuse the SFX
519 			 GetViewFrame()->GetBindings().IsInUpdate() ) // do not confuse the SFX
520 		{
521 			bAttrChgNotified = sal_True;
522 			aTimer.Start();
523 
524 			const SfxPoolItem *pItem;
525 			if ( SFX_ITEM_SET != GetObjectShell()->GetMedium()->GetItemSet()->
526 									GetItemState( SID_HIDDEN, sal_False, &pItem ) ||
527 				 !((SfxBoolItem*)pItem)->GetValue() )
528 			{
529 				GetViewFrame()->GetBindings().ENTERREGISTRATIONS();
530 				bAttrChgNotifiedWithRegistrations = sal_True;
531 			}
532 
533 		}
534 		else
535 			SelectShell();
536 
537 	}
538 
539 	// #i6193#, change ui if cursor is at a SwPostItField
540 	if (mpPostItMgr)
541 	{
542 		mpPostItMgr->SetShadowState( pWrtShell->GetPostItFieldAtCursor() );
543 	}
544 
545 	return 0;
546 }
547 
548 
549 
IMPL_LINK(SwView,TimeoutHdl,Timer *,EMPTYARG)550 IMPL_LINK( SwView, TimeoutHdl, Timer *, EMPTYARG )
551 {
552 	DBG_PROFSTART(viewhdl);
553 
554 	if( pWrtShell->BasicActionPend() || bNoInterrupt )
555 	{
556 		aTimer.Start();
557 		DBG_PROFSTOP(viewhdl);
558 		return 0;
559 	}
560 
561 	if ( bAttrChgNotifiedWithRegistrations )
562 	{
563 		GetViewFrame()->GetBindings().LEAVEREGISTRATIONS();
564 		bAttrChgNotifiedWithRegistrations = sal_False;
565 	}
566 
567 	_CheckReadonlyState();
568 	_CheckReadonlySelection();
569 
570 	sal_Bool bOldUndo = pWrtShell->DoesUndo();
571 	pWrtShell->DoUndo( sal_False );
572 	SelectShell();
573 	pWrtShell->DoUndo( bOldUndo );
574 	bAttrChgNotified = sal_False;
575 	GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged();
576 
577 	DBG_PROFSTOP(viewhdl);
578 	return 0;
579 }
580 
_CheckReadonlyState()581 void SwView::_CheckReadonlyState()
582 {
583 	SfxDispatcher &rDis = GetDispatcher();
584 	// Um erkennen zu koennen ob bereits disabled ist!
585 	SfxItemState eStateRO, eStateProtAll;
586 	const SfxPoolItem *pItem;
587 	// JP 29.04.97: von einem nur uns bekannten Slot den Status abfragen.
588 	//				Ansonsten kennen andere den Slot; wie z.B. die BasidIde
589 	eStateRO = rDis.QueryState( FN_INSERT_BOOKMARK, pItem );
590 	eStateProtAll = rDis.QueryState( FN_EDIT_REGION, pItem );
591 	sal_Bool bChgd = sal_False;
592 
593 	if ( !pWrtShell->IsCrsrReadonly() )
594 	{
595 		static sal_uInt16 aROIds[] =
596 		{
597 			SID_DELETE, 				FN_BACKSPACE,				FN_SHIFT_BACKSPACE,
598 			SID_UNDO,
599 			SID_REDO,					SID_REPEAT,					SID_PASTE,
600 			SID_PASTE_UNFORMATTED,
601 			SID_PASTE_SPECIAL,			SID_SBA_BRW_INSERT,
602 			SID_BACKGROUND_COLOR,		FN_INSERT_BOOKMARK,
603 			SID_CHARMAP,				FN_INSERT_SOFT_HYPHEN,
604 			FN_INSERT_HARDHYPHEN,		FN_INSERT_HARD_SPACE,		FN_INSERT_BREAK,
605 			FN_INSERT_LINEBREAK,		FN_INSERT_COLUMN_BREAK,		FN_INSERT_BREAK_DLG,
606 			FN_DELETE_SENT,				FN_DELETE_BACK_SENT,		FN_DELETE_WORD,
607 			FN_DELETE_BACK_WORD,		FN_DELETE_LINE,				FN_DELETE_BACK_LINE,
608 			FN_DELETE_PARA,				FN_DELETE_BACK_PARA,		FN_DELETE_WHOLE_LINE,
609 			FN_CALCULATE,				FN_FORMAT_RESET,
610 			FN_POSTIT,					FN_JAVAEDIT,				SID_ATTR_PARA_ADJUST_LEFT,
611 			SID_ATTR_PARA_ADJUST_RIGHT,	SID_ATTR_PARA_ADJUST_CENTER,SID_ATTR_PARA_ADJUST_BLOCK,
612 			SID_ATTR_PARA_LINESPACE_10,	SID_ATTR_PARA_LINESPACE_15,	SID_ATTR_PARA_LINESPACE_20,
613 			SID_ATTR_CHAR_FONT,			SID_ATTR_CHAR_FONTHEIGHT,	SID_ATTR_CHAR_COLOR_BACKGROUND,
614 			SID_ATTR_CHAR_COLOR_BACKGROUND_EXT,						SID_ATTR_CHAR_COLOR_EXT,
615 			SID_ATTR_CHAR_COLOR,		SID_ATTR_CHAR_WEIGHT,		SID_ATTR_CHAR_POSTURE,
616 			SID_ATTR_CHAR_OVERLINE,
617 			SID_ATTR_CHAR_UNDERLINE,	SID_ATTR_FLASH,				SID_ATTR_CHAR_STRIKEOUT,
618 			FN_UNDERLINE_DOUBLE,		SID_ATTR_CHAR_CONTOUR,		SID_ATTR_CHAR_SHADOWED,
619 			SID_ATTR_CHAR_AUTOKERN,		SID_ATTR_CHAR_ESCAPEMENT,	FN_SET_SUPER_SCRIPT,
620 			FN_SET_SUB_SCRIPT,			SID_ATTR_CHAR_CASEMAP,		SID_ATTR_CHAR_LANGUAGE,
621 			SID_ATTR_CHAR_KERNING,		SID_CHAR_DLG,				SID_ATTR_CHAR_WORDLINEMODE,
622 			FN_GROW_FONT_SIZE,			FN_SHRINK_FONT_SIZE,		FN_TXTATR_INET,
623 			FN_FORMAT_DROPCAPS,			SID_ATTR_PARA_ADJUST,		SID_ATTR_PARA_LINESPACE,
624 			SID_ATTR_PARA_SPLIT,		SID_ATTR_PARA_KEEP,			SID_ATTR_PARA_WIDOWS,
625 			SID_ATTR_PARA_ORPHANS,
626 			SID_ATTR_PARA_MODEL,		SID_PARA_DLG,
627 			FN_SELECT_PARA,				SID_DEC_INDENT,
628 			SID_INC_INDENT
629 		};
630 		static sal_Bool bFirst = sal_True;
631 		if ( bFirst )
632 		{
633 			qsort( (void*)aROIds, sizeof(aROIds)/sizeof(sal_uInt16), sizeof(sal_uInt16), lcl_CmpIds );
634 			bFirst = sal_False;
635 		}
636 		if ( SFX_ITEM_DISABLED == eStateRO )
637 		{
638 			rDis.SetSlotFilter( sal_Bool(2), sizeof(aROIds)/sizeof(sal_uInt16), aROIds );
639 			bChgd = sal_True;
640 		}
641 	}
642 	else if( pWrtShell->IsAllProtect() )
643 	{
644 		if ( SFX_ITEM_DISABLED == eStateProtAll )
645 		{
646 			static sal_uInt16 aAllProtIds[] = { SID_SAVEDOC, FN_EDIT_REGION };
647 			static sal_Bool bAllProtFirst = sal_True;
648 			if ( bAllProtFirst )
649 			{
650 				qsort( (void*)aAllProtIds, sizeof(aAllProtIds)/sizeof(sal_uInt16), sizeof(sal_uInt16), lcl_CmpIds );
651 				bAllProtFirst = sal_False;
652 			}
653 			rDis.SetSlotFilter( sal_Bool(2),
654 								sizeof(aAllProtIds)/sizeof(sal_uInt16),
655 								aAllProtIds );
656 			bChgd = sal_True;
657 		}
658 	}
659 	else if ( SFX_ITEM_DISABLED != eStateRO ||
660 				SFX_ITEM_DISABLED != eStateProtAll )
661 	{
662 		bChgd = sal_True;
663 		rDis.SetSlotFilter();
664 	}
665 	if ( bChgd )
666 		GetViewFrame()->GetBindings().InvalidateAll(sal_True);
667 }
668 
_CheckReadonlySelection()669 void SwView::_CheckReadonlySelection()
670 {
671 	sal_uInt32 nDisableFlags = 0;
672 	SfxDispatcher &rDis = GetDispatcher();
673 
674 	if( pWrtShell->HasReadonlySel() &&
675 		( !pWrtShell->GetDrawView() ||
676 			!pWrtShell->GetDrawView()->GetMarkedObjectList().GetMarkCount() ))
677 		nDisableFlags |= SW_DISABLE_ON_PROTECTED_CURSOR;
678 
679 	if( (SW_DISABLE_ON_PROTECTED_CURSOR & nDisableFlags ) !=
680 		(SW_DISABLE_ON_PROTECTED_CURSOR & rDis.GetDisableFlags() ) )
681 	{
682 		// zusaetzlich am Window den InputContext umsetzen, damit in
683 		// japanischen / chinesischen Versionen die externe Eingabe
684 		// ab-/angeschaltet wird. Das aber nur wenn auch die richtige
685 		// Shell auf dem Stack steht.
686 		switch( pViewImpl->GetShellMode() )
687 		{
688 		case SHELL_MODE_TEXT:
689 		case SHELL_MODE_LIST_TEXT:
690 		case SHELL_MODE_TABLE_TEXT:
691 		case SHELL_MODE_TABLE_LIST_TEXT:
692 			{
693 // JP 22.01.99: temporaere Loesung!!! Sollte bei jeder Cursorbewegung
694 //			den Font von der akt. Einfuegeposition setzen, also ausserhalb
695 // 			dieses if's. Aber TH wertet den Font zur Zeit nicht aus und
696 //			das besorgen erscheint mir hier zu teuer zu sein.
697 //			Ausserdem haben wir keinen Font, sondern nur Attribute aus denen
698 //			die Textformatierung dann den richtigen Font zusammen baut.
699 
700 				InputContext aCntxt( GetEditWin().GetInputContext() );
701 				aCntxt.SetOptions( SW_DISABLE_ON_PROTECTED_CURSOR & nDisableFlags
702 									? (aCntxt.GetOptions() & ~
703 											( INPUTCONTEXT_TEXT |
704 												INPUTCONTEXT_EXTTEXTINPUT ))
705 									: (aCntxt.GetOptions() |
706 											( INPUTCONTEXT_TEXT |
707 												INPUTCONTEXT_EXTTEXTINPUT )) );
708 				GetEditWin().SetInputContext( aCntxt );
709 			}
710 			break;
711 		default:
712 			;
713 		}
714 
715 	}
716 
717 	if( nDisableFlags != rDis.GetDisableFlags() )
718 	{
719 		rDis.SetDisableFlags( nDisableFlags );
720 		GetViewFrame()->GetBindings().InvalidateAll( sal_True );
721 	}
722 }
723 
724 
SwView(SfxViewFrame * _pFrame,SfxViewShell * pOldSh)725 SwView::SwView( SfxViewFrame *_pFrame, SfxViewShell* pOldSh )
726 	: SfxViewShell( _pFrame, SWVIEWFLAGS ),
727 	aPageStr( SW_RES( STR_PAGE )),
728 	nNewPage(USHRT_MAX),
729 	nOldPageNum(0),
730 	pNumRuleNodeFromDoc(0), // #i23726#
731 	pEditWin( new SwEditWin( &_pFrame->GetWindow(), *this ) ),
732 	pWrtShell(0),
733 	pShell(0),
734 	pFormShell(0),
735 	pHScrollbar(0),
736 	pVScrollbar(0),
737 	pScrollFill(new ScrollBarBox( &_pFrame->GetWindow(), _pFrame->GetFrame().GetParentFrame() ? 0 : WB_SIZEABLE )),
738 	pHRuler( new SvxRuler(&GetViewFrame()->GetWindow(), pEditWin,
739 					SVXRULER_SUPPORT_TABS |
740 					SVXRULER_SUPPORT_PARAGRAPH_MARGINS |
741 					SVXRULER_SUPPORT_BORDERS |
742 					SVXRULER_SUPPORT_NEGATIVE_MARGINS|
743 					SVXRULER_SUPPORT_REDUCED_METRIC,
744 					GetViewFrame()->GetBindings(),
745 					WB_STDRULER | WB_EXTRAFIELD | WB_BORDER)),
746 	pVRuler(new SvxRuler(&GetViewFrame()->GetWindow(), pEditWin,
747                             SVXRULER_SUPPORT_TABS | SVXRULER_SUPPORT_PARAGRAPH_MARGINS_VERTICAL|
748                                 SVXRULER_SUPPORT_BORDERS | SVXRULER_SUPPORT_REDUCED_METRIC,
749 							GetViewFrame()->GetBindings(),
750                             WB_VSCROLL | WB_EXTRAFIELD | WB_BORDER )),
751 	pTogglePageBtn(0),
752 	pPageUpBtn(0),
753 	pPageDownBtn(0),
754 	pNaviBtn(0),
755 	pGlosHdl(0),
756 	pDrawActual(0),
757 	pLastTableFormat(0),
758 	pFormatClipboard(new SwFormatClipboard()),
759 	mpPostItMgr(0),
760 	nSelectionType( INT_MAX ),
761 	nPageCnt(0),
762 	nDrawSfxId( USHRT_MAX ),
763 	nFormSfxId( USHRT_MAX ),
764 	nLastPasteDestination( 0xFFFF ),
765 	nLeftBorderDistance( 0 ),
766 	nRightBorderDistance( 0 ),
767 	bInMailMerge(sal_False),
768 	bInDtor(sal_False),
769 	bOldShellWasPagePreView(sal_False),
770 	bIsPreviewDoubleClick(sal_False)
771 {
772 	// OD 18.12.2002 #103492# - According to discussion with MBA and further
773 	// investigations, no old SfxViewShell will be set as parameter <pOldSh>,
774 	// if function "New Window" is performed to open an additional view beside
775 	// an already existing one.
776 	// If the view is switch from one to another, the 'old' view is given by
777 	// parameter <pOldSh>.
778 
779 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwView::SwView" );
780 
781 	bCenterCrsr = bTopCrsr = bAllwaysShowSel = bTabColFromDoc = bTabRowFromDoc =
782 	bSetTabColFromDoc = bSetTabRowFromDoc = bAttrChgNotified = bAttrChgNotifiedWithRegistrations =
783 	bVerbsActive = bDrawRotate = bInOuterResizePixel = bInInnerResizePixel =
784 	bPasteState = bPasteSpecialState = bMakeSelectionVisible = sal_False;
785 
786 	bShowAtResize = bDrawSelMode = bDocSzUpdated = sal_True;
787 
788 	_CreateScrollbar( sal_True );
789 	_CreateScrollbar( sal_False );
790 
791 	pViewImpl = new SwView_Impl(this);
792 	SetName(C2S("View"));
793 	SetWindow( pEditWin );
794 
795 	aTimer.SetTimeout( 120 );
796 
797 	SwDocShell* pDocSh = PTR_CAST( SwDocShell, _pFrame->GetObjectShell() );
798 	sal_Bool bOldModifyFlag = pDocSh->IsEnableSetModified();
799 	if(bOldModifyFlag)
800 		pDocSh->EnableSetModified( sal_False );
801 	ASSERT( pDocSh, "View ohne DocShell." );
802 	SwWebDocShell* pWebDShell = PTR_CAST( SwWebDocShell, pDocSh );
803 
804 	const SwMasterUsrPref *pUsrPref = SW_MOD()->GetUsrPref(0 != pWebDShell);
805 	SwViewOption aUsrPref( *pUsrPref);
806 
807 	// ! get lingu options without loading lingu DLL
808 	SvtLinguOptions aLinguOpt;
809 	SvtLinguConfig().GetOptions( aLinguOpt );
810 	aUsrPref.SetOnlineSpell( aLinguOpt.bIsSpellAuto );
811 
812 	sal_Bool bOldShellWasSrcView = sal_False;
813 
814 	// OD 18.12.2002 #103492# - determine, if there is an existing view for
815 	// document
816 	SfxViewShell* pExistingSh = 0;
817 	if ( pOldSh )
818 	{
819 		pExistingSh = pOldSh;
820 		// determine type of existing view
821 		if( pExistingSh->IsA( TYPE( SwPagePreView ) ) )
822 		{
823             sSwViewData = ((SwPagePreView*)pExistingSh)->GetPrevSwViewData();
824             sNewCrsrPos = ((SwPagePreView*)pExistingSh)->GetNewCrsrPos();
825             nNewPage = ((SwPagePreView*)pExistingSh)->GetNewPage();
826             bOldShellWasPagePreView = sal_True;
827             bIsPreviewDoubleClick = sNewCrsrPos.Len() > 0 || nNewPage != USHRT_MAX;
828 		}
829 		else if( pExistingSh->IsA( TYPE( SwSrcView ) ) )
830 			bOldShellWasSrcView = sal_True;
831 	}
832 
833 	RTL_LOGFILE_CONTEXT_TRACE( aLog, "before create WrtShell" );
834 	if(PTR_CAST( SwView, pExistingSh))
835 	{
836 		pWrtShell = new SwWrtShell( *((SwView*)pExistingSh)->pWrtShell,
837 									pEditWin, *this);
838 	}
839 	else if( dynamic_cast<SwWrtShell*>( pDocSh->GetDoc()->GetCurrentViewShell() ) )
840 	{
841 		pWrtShell = new SwWrtShell( *(SwWrtShell*)pDocSh->GetDoc()->GetCurrentViewShell(),
842 									pEditWin, *this);
843 	}
844 	else
845 	{
846 		SwDoc& rDoc = *((SwDocShell*)pDocSh)->GetDoc();
847 
848 		if( !bOldShellWasSrcView && pWebDShell && !bOldShellWasPagePreView )
849 			aUsrPref.setBrowseMode( sal_True );
850 		else if( rDoc.IsLoaded() )
851 			aUsrPref.setBrowseMode( rDoc.get(IDocumentSettingAccess::BROWSE_MODE) );
852 
853 		// Fuer den BrowseMode wollen wir keinen Factor uebernehmen.
854 		if( aUsrPref.getBrowseMode() && aUsrPref.GetZoomType() != SVX_ZOOM_PERCENT )
855 		{
856 			aUsrPref.SetZoomType( SVX_ZOOM_PERCENT );
857 			aUsrPref.SetZoom( 100 );
858 		}
859 		if(pDocSh->IsPreview())
860 		{
861 			aUsrPref.SetZoomType( SVX_ZOOM_WHOLEPAGE );
862 			aUsrPref.SetViewLayoutBookMode( false );
863 			aUsrPref.SetViewLayoutColumns( 1 );
864 		}
865 		pWrtShell = new SwWrtShell( rDoc, pEditWin, *this, &aUsrPref );
866 		// #97610# creating an SwView from a SwPagePreView needs to
867 		// add the ViewShell to the ring of the other ViewShell(s)
868 		if(bOldShellWasPagePreView)
869 		{
870 			ViewShell& rPreviewViewShell = *((SwPagePreView*)pExistingSh)->GetViewShell();
871 			pWrtShell->MoveTo(&rPreviewViewShell);
872 			// #95521# to update the field command et.al. if necessary
873 			const SwViewOption* pPreViewOpt = rPreviewViewShell.GetViewOptions();
874 			if( pPreViewOpt->IsFldName() != aUsrPref.IsFldName() ||
875                     pPreViewOpt->IsShowHiddenField() != aUsrPref.IsShowHiddenField() ||
876                     pPreViewOpt->IsShowHiddenPara() != aUsrPref.IsShowHiddenPara() ||
877                     pPreViewOpt->IsShowHiddenChar() != aUsrPref.IsShowHiddenChar() )
878                 rPreviewViewShell.ApplyViewOptions(aUsrPref);
879             // OD 09.01.2003 #106334# - reset design mode at draw view for form
880             // shell, if needed.
881             if ( ((SwPagePreView*)pExistingSh)->ResetFormDesignMode() &&
882                  pWrtShell->HasDrawView() )
883             {
884                 SdrView* pDrawView = pWrtShell->GetDrawView();
885                 pDrawView->SetDesignMode( ((SwPagePreView*)pExistingSh)->FormDesignModeToReset() );
886 			}
887 		}
888 	}
889 	RTL_LOGFILE_CONTEXT_TRACE( aLog, "after create WrtShell" );
890 
891 	// --> OD 2005-02-11 #i38810# - assure that modified state of document
892 	// isn't reset, if document is already modified.
893 	const bool bIsDocModified = pWrtShell->GetDoc()->IsModified();
894 	// <--
895 
896 	// JP 05.02.99: Bug 61495 - damit unter anderem das HLineal im
897 	//				ReadonlyFall nicht angezeigt wird
898 	aUsrPref.SetReadonly( pWrtShell->GetViewOptions()->IsReadonly() );
899 
900 	// No margin for OLE!
901 	Size aBrwsBorder;
902 	if( SFX_CREATE_MODE_EMBEDDED != pDocSh->GetCreateMode() )
903 		aBrwsBorder = GetMargin();
904 
905 	pWrtShell->SetBrowseBorder( aBrwsBorder );
906 
907 	// Im CTOR duerfen keine Shell-Wechsel erfolgen, die muessen ueber
908 	// den Timer "zwischengespeichert" werden. Sonst raeumt der SFX
909 	// sie wieder vom Stack!
910 	sal_Bool bOld = bNoInterrupt;
911 	bNoInterrupt = sal_True;
912 
913 	pHRuler->SetActive( sal_True );
914 	pVRuler->SetActive( sal_True );
915 
916 	SfxViewFrame* pViewFrame = GetViewFrame();
917 	if( pViewFrame->GetFrame().GetParentFrame())
918 	{
919 		aUsrPref.SetViewHRuler(sal_False);
920 		aUsrPref.SetViewVRuler(sal_False);
921 	}
922 
923 	StartListening( *pViewFrame, sal_True );
924 	StartListening( *pDocSh, sal_True );
925 
926 	// Vom HLineal den ZOOM-Faktor einstellen
927 	Fraction aZoomFract( aUsrPref.GetZoom(), 100 );
928 	pHRuler->SetZoom( aZoomFract );
929 	pVRuler->SetZoom( aZoomFract );
930 	pHRuler->SetDoubleClickHdl(LINK( this, SwView, ExecRulerClick ));
931 	FieldUnit eMetric = pUsrPref->GetHScrollMetric();
932 	pHRuler->SetUnit( eMetric );
933 	eMetric = pUsrPref->GetVScrollMetric();
934 	pVRuler->SetUnit( eMetric );
935 
936 	// DocShell setzen
937 	pDocSh->SetView( this );
938 	SW_MOD()->SetView( this );
939 
940 	mpPostItMgr = new SwPostItMgr(this);
941 
942 	// Die DocSize erfragen und verarbeiten. Ueber die Handler konnte
943 	// die Shell nicht gefunden werden, weil die Shell innerhalb CTOR-Phase
944 	// nicht in der SFX-Verwaltung bekannt ist.
945 	DocSzChgd( pWrtShell->GetDocSize() );
946 
947 		// AttrChangedNotify Link setzen
948 	pWrtShell->SetChgLnk(LINK(this, SwView, AttrChangedNotify));
949 
950 	if( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED &&
951 		// TODO/LATER: why a cast here?
952 		//!((SvEmbeddedObject *)pDocSh)->GetVisArea().IsEmpty() )
953 		//SetVisArea( ((SvEmbeddedObject *)pDocSh)->GetVisArea(),sal_False);
954 		!pDocSh->GetVisArea(ASPECT_CONTENT).IsEmpty() )
955 		SetVisArea( pDocSh->GetVisArea(ASPECT_CONTENT),sal_False);
956 
957 	pWrtShell->DoUndo( 0 != SW_MOD()->GetUndoOptions().GetUndoCount() );
958 
959 	const sal_Bool bBrowse = pWrtShell->GetViewOptions()->getBrowseMode();
960 	// Disable "multiple window"
961 	SetNewWindowAllowed(!bBrowse);
962 	// End of disabled multiple window
963 
964 	ShowVScrollbar(aUsrPref.IsViewVScrollBar());
965 	ShowHScrollbar(aUsrPref.IsViewHScrollBar());
966 	pHScrollbar->SetAuto(bBrowse);
967 	if( aUsrPref.IsViewHRuler() )
968 		CreateTab();
969 	if( aUsrPref.IsViewVRuler() )
970 		CreateVLineal();
971 
972 	pWrtShell->SetUIOptions( aUsrPref );
973 	pWrtShell->SetReadOnlyAvailable( aUsrPref.IsCursorInProtectedArea() );
974 	pWrtShell->ApplyAccessiblityOptions(SW_MOD()->GetAccessibilityOptions());
975 
976 	if( pWrtShell->GetDoc()->IsUpdateExpFld() )
977 	{
978 		SET_CURR_SHELL( pWrtShell );
979 		pWrtShell->StartAction();
980 		pWrtShell->CalcLayout();
981 		pWrtShell->GetDoc()->UpdateFlds(NULL, false);
982 		pWrtShell->EndAction();
983 		pWrtShell->GetDoc()->SetUpdateExpFldStat( sal_False );
984 	}
985 
986 	// ggfs. alle Verzeichnisse updaten:
987 	if( pWrtShell->GetDoc()->IsUpdateTOX() )
988 	{
989 		SfxRequest aSfxRequest( FN_UPDATE_TOX, SFX_CALLMODE_SLOT, GetPool() );
990 		Execute( aSfxRequest );
991 		pWrtShell->GetDoc()->SetUpdateTOX( sal_False ); // wieder zurueck setzen
992 		pWrtShell->SttEndDoc(sal_True);
993 	}
994 
995 	// kein ResetModified, wenn es schone eine View auf dieses Doc gibt
996 	SfxViewFrame* pVFrame = GetViewFrame();
997 	SfxViewFrame* pFirst = SfxViewFrame::GetFirst(pDocSh);
998 	// zur Zeit(360) wird die View erst nach dem Ctor eingetragen
999 	// der folgende Ausdruck funktioniert auch, wenn sich das aendert
1000 	// JP 27.07.98: wenn per Undo nicht mehr die Modifizierung aufhebar ist,
1001 	//				so setze das Modified NICHT zurueck.
1002 	// --> OD 2005-02-11 #i38810# - no reset of modified state, if document
1003 	// was already modified.
1004 	if (!pWrtShell->GetDoc()->GetIDocumentUndoRedo().IsUndoNoResetModified() &&
1005 		( !pFirst || pFirst == pVFrame ) &&
1006 		!bIsDocModified )
1007 	// <--
1008 	{
1009 		pWrtShell->ResetModified();
1010 	}
1011 
1012 	bNoInterrupt = bOld;
1013 
1014 	// wird ein GlobalDoc neu angelegt, soll auch der Navigator erzeugt werden
1015 	if( pDocSh->IsA(SwGlobalDocShell::StaticType()) &&
1016 		!pVFrame->GetChildWindow( SID_NAVIGATOR ))
1017 	{
1018 		SfxBoolItem aNavi(SID_NAVIGATOR, sal_True);
1019 		GetDispatcher().Execute(SID_NAVIGATOR, SFX_CALLMODE_ASYNCHRON, &aNavi, 0L);
1020 	}
1021 
1022 
1023 	uno::Reference< frame::XFrame > xFrame = pVFrame->GetFrame().GetFrameInterface();
1024 
1025 	uno::Reference< frame::XFrame > xBeamerFrame = xFrame->findFrame(
1026 			OUString::createFromAscii("_beamer"), frame::FrameSearchFlag::CHILDREN);
1027 	if(xBeamerFrame.is())
1028 	{
1029 		SwDBData aData = pWrtShell->GetDBData();
1030 		SW_MOD()->ShowDBObj( *this, aData );
1031 	}
1032 
1033 	// has anybody calls the attrchanged handler in the constructor?
1034 	if( bAttrChgNotifiedWithRegistrations )
1035 	{
1036 		GetViewFrame()->GetBindings().LEAVEREGISTRATIONS();
1037 		if( aTimer.IsActive() )
1038 			aTimer.Stop();
1039 	}
1040 
1041 	aTimer.SetTimeoutHdl(LINK(this, SwView, TimeoutHdl));
1042 	bAttrChgNotified = bAttrChgNotifiedWithRegistrations = sal_False;
1043 	if(bOldModifyFlag)
1044 		pDocSh->EnableSetModified( sal_True );
1045 	InvalidateBorder();
1046 }
1047 
~SwView()1048 SwView::~SwView()
1049 {
1050 	delete mpPostItMgr;
1051 	// --> OD 2009-03-10 #i100035#
1052 	mpPostItMgr = 0;
1053 	// <--
1054 
1055 	bInDtor = sal_True;
1056 	pEditWin->Hide(); // damit kein Paint Aerger machen kann!
1057 	// An der SwDocShell den Pointer auf die View ruecksetzen
1058 	SwDocShell* pDocSh = GetDocShell();
1059 	if( pDocSh && pDocSh->GetView() == this )
1060 		pDocSh->SetView( 0 );
1061 	if ( SW_MOD()->GetView() == this )
1062 		SW_MOD()->SetView( 0 );
1063 
1064 	if( aTimer.IsActive() && bAttrChgNotifiedWithRegistrations )
1065 		GetViewFrame()->GetBindings().LEAVEREGISTRATIONS();
1066 
1067 	// JP 27.11.00: Bug 80631 - the last view must end the text edit
1068 	SdrView *pSdrView = pWrtShell ? pWrtShell->GetDrawView() : 0;
1069 	if( pSdrView && pSdrView->IsTextEdit() )
1070 		pSdrView->SdrEndTextEdit( sal_True );
1071 
1072 	SetWindow( 0 );
1073 
1074 	pViewImpl->Invalidate();
1075 	EndListening(*GetViewFrame());
1076 	EndListening(*GetDocShell());
1077 	delete pScrollFill;
1078 	delete pWrtShell;
1079 	pWrtShell = 0; // Auf 0 setzen, damit folgende DToren nicht drauf zugreifen
1080 	pShell = 0;
1081 	delete pHScrollbar;
1082 	delete pVScrollbar;
1083 	delete pHRuler;
1084 	delete pVRuler;
1085 	delete pTogglePageBtn;
1086 	delete pPageUpBtn;
1087 	delete pNaviBtn;
1088 	delete pPageDownBtn;
1089 	delete pGlosHdl;
1090 	delete pViewImpl;
1091 	delete pEditWin;
1092 	delete pFormatClipboard;
1093 }
1094 
GetDocShell()1095 SwDocShell* SwView::GetDocShell()
1096 {
1097 	SfxObjectShell* pDocShell = GetViewFrame()->GetObjectShell();
1098 	return PTR_CAST(SwDocShell, pDocShell);
1099 }
1100 
1101 /*--------------------------------------------------------------------
1102 	Description: CursorPos merken
1103  --------------------------------------------------------------------*/
1104 
1105 
WriteUserData(String & rUserData,sal_Bool bBrowse)1106 void SwView::WriteUserData( String &rUserData, sal_Bool bBrowse )
1107 {
1108 	// Das Browse-Flag wird vom Sfx durchgereicht, wenn Dokumente gebrowsed
1109 	// werden (nicht zu verwechseln mit dem BrowseMode).
1110 	// Die dann gespeicherten Daten sind nicht persistent!!
1111 
1112 	const SwRect& rRect = pWrtShell->GetCharRect();
1113 	const Rectangle& rVis = GetVisArea();
1114 
1115 	rUserData = String::CreateFromInt32( rRect.Left() );
1116 	rUserData += ';';
1117 	rUserData += String::CreateFromInt32( rRect.Top() );
1118 	rUserData += ';';
1119 	rUserData += String::CreateFromInt32( pWrtShell->GetViewOptions()->GetZoom() );
1120 	rUserData += ';';
1121 	rUserData += String::CreateFromInt32( rVis.Left() );
1122 	rUserData += ';';
1123 	rUserData += String::CreateFromInt32( rVis.Top() );
1124 	rUserData += ';';
1125 	rUserData += String::CreateFromInt32( bBrowse ? LONG_MIN : rVis.Right());
1126 	rUserData += ';';
1127 	rUserData += String::CreateFromInt32( bBrowse ? LONG_MIN : rVis.Bottom());
1128 	rUserData += ';';
1129 	rUserData += String::CreateFromInt32(
1130 			(sal_uInt16)pWrtShell->GetViewOptions()->GetZoomType()); // eZoom;
1131 	rUserData += ';';
1132 	rUserData += FRMTYPE_NONE == pWrtShell->GetSelFrmType() ? '0' : '1';
1133 }
1134 /*--------------------------------------------------------------------
1135 	Description: CursorPos setzen
1136  --------------------------------------------------------------------*/
1137 // #i43146# go to the last editing position when opening own files
lcl_IsOwnDocument(SwView & rView)1138 bool lcl_IsOwnDocument( SwView& rView )
1139 {
1140 	uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
1141 		rView.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
1142 	uno::Reference<document::XDocumentProperties> xDocProps
1143 		= xDPS->getDocumentProperties();
1144 	String Created = xDocProps->getAuthor();
1145 	String Changed = xDocProps->getModifiedBy();
1146 	String FullName = SW_MOD()->GetUserOptions().GetFullName();
1147 	return (FullName.Len() &&
1148             (Changed.Len() && Changed == FullName )) ||
1149             (!Changed.Len() && Created.Len() && Created == FullName );
1150 }
1151 
1152 
ReadUserData(const String & rUserData,sal_Bool bBrowse)1153 void SwView::ReadUserData( const String &rUserData, sal_Bool bBrowse )
1154 {
1155 	if ( rUserData.GetTokenCount() > 1 &&
1156 		// Fuer Dokumente ohne Layout nur im OnlineLayout oder beim
1157 		// Forward/Backward
1158 		 (!pWrtShell->IsNewLayout() || pWrtShell->GetViewOptions()->getBrowseMode() || bBrowse) )
1159 	{
1160 		// #i43146# go to the last editing position when opening own files
1161 		bool bIsOwnDocument = lcl_IsOwnDocument( *this );
1162 
1163 		SET_CURR_SHELL(pWrtShell);
1164 
1165 		sal_uInt16 nPos = 0;
1166 
1167 		// Nein, es ist *keine* gute Idee GetToken gleich im Point-Konstr.
1168 		// aufzurufen, denn welcher Parameter wird zuerst ausgewertet?
1169 		long nX = rUserData.GetToken( 0, ';', nPos ).ToInt32(),
1170 			 nY = rUserData.GetToken( 0, ';', nPos ).ToInt32();
1171 		Point aCrsrPos( nX, nY );
1172 
1173 		sal_uInt16 nZoomFactor =
1174 			static_cast< sal_uInt16 >( rUserData.GetToken(0, ';', nPos ).ToInt32() );
1175 
1176 		long nLeft	= rUserData.GetToken(0, ';', nPos ).ToInt32(),
1177 			 nTop	= rUserData.GetToken(0, ';', nPos ).ToInt32(),
1178 			 nRight = rUserData.GetToken(0, ';', nPos ).ToInt32(),
1179 			 nBottom= rUserData.GetToken(0, ';', nPos ).ToInt32();
1180 
1181 		const long nAdd = pWrtShell->GetViewOptions()->getBrowseMode() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
1182 		if ( nBottom <= (pWrtShell->GetDocSize().Height()+nAdd) )
1183 		{
1184 			pWrtShell->EnableSmooth( sal_False );
1185 
1186 			const Rectangle aVis( nLeft, nTop, nRight, nBottom );
1187 
1188 			sal_uInt16 nOff = 0;
1189 			SvxZoomType eZoom;
1190 			if( !pWrtShell->GetViewOptions()->getBrowseMode() )
1191 				eZoom = (SvxZoomType) (sal_uInt16)rUserData.GetToken(nOff, ';', nPos ).ToInt32();
1192 			else
1193 			{
1194 				eZoom = SVX_ZOOM_PERCENT;
1195 				++nOff;
1196 			}
1197 
1198 			sal_Bool bSelectObj = (0 != rUserData.GetToken( nOff, ';', nPos ).ToInt32())
1199 								&& pWrtShell->IsObjSelectable( aCrsrPos );
1200 
1201 			// #i33307# restore editing position
1202 			pViewImpl->SetRestorePosition(aCrsrPos, bSelectObj);
1203 			// OD 11.02.2003 #100556# - set flag value to avoid macro execution.
1204 			bool bSavedFlagValue = pWrtShell->IsMacroExecAllowed();
1205 			pWrtShell->SetMacroExecAllowed( false );
1206 // !!! pb (11.08.2004): #i32536#
1207 // os: changed: The user data has to be read if the view is switched back from page preview
1208 // #i43146# go to the last editing position when opening own files
1209             if(bOldShellWasPagePreView || bIsOwnDocument)
1210             {
1211                 pWrtShell->SwCrsrShell::SetCrsr( aCrsrPos, !bSelectObj );
1212             	if( bSelectObj )
1213             	{
1214             		pWrtShell->SelectObj( aCrsrPos );
1215             		pWrtShell->EnterSelFrmMode( &aCrsrPos );
1216             	}
1217             }
1218 
1219             // OD 11.02.2003 #100556# - reset flag value
1220             pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
1221 
1222             // OD 08.04.2003 #108693# - set visible area before applying
1223             // information from print preview. Otherwise, the applied information
1224             // is lost.
1225 // !!! pb (11.08.2004): #i32536#
1226 // os: changed: The user data has to be read if the view is switched back from page preview
1227 // #i43146# go to the last editing position when opening own files
1228             if(bOldShellWasPagePreView || bIsOwnDocument )
1229             {
1230                 if ( bBrowse )
1231                     SetVisArea( aVis.TopLeft() );
1232                 else
1233                     SetVisArea( aVis );
1234             }
1235 
1236 			// apply information from print preview - if available
1237 			if( sNewCrsrPos.Len() )
1238 			{
1239 				long nXTmp = sNewCrsrPos.GetToken( 0, ';' ).ToInt32(),
1240 				 	 nYTmp = sNewCrsrPos.GetToken( 1, ';' ).ToInt32();
1241 				Point aCrsrPos2( nXTmp, nYTmp );
1242 				bSelectObj = pWrtShell->IsObjSelectable( aCrsrPos2 );
1243 
1244                 pWrtShell->SwCrsrShell::SetCrsr( aCrsrPos2, sal_False );
1245                 if( bSelectObj )
1246                 {
1247                     pWrtShell->SelectObj( aCrsrPos2 );
1248                     pWrtShell->EnterSelFrmMode( &aCrsrPos2 );
1249                 }
1250                 pWrtShell->MakeSelVisible();
1251                 sNewCrsrPos.Erase();
1252 			}
1253 			else if(USHRT_MAX != nNewPage)
1254 			{
1255 				pWrtShell->GotoPage(nNewPage, sal_True);
1256 				nNewPage = USHRT_MAX;
1257 			}
1258 
1259 			SelectShell();
1260 
1261 			pWrtShell->StartAction();
1262 			const SwViewOption* pVOpt = pWrtShell->GetViewOptions();
1263 			if( pVOpt->GetZoom() != nZoomFactor || pVOpt->GetZoomType() != eZoom )
1264 				SetZoom( eZoom, nZoomFactor);
1265 
1266 			pWrtShell->LockView( sal_True );
1267 			pWrtShell->EndAction();
1268 			pWrtShell->LockView( sal_False );
1269 			pWrtShell->EnableSmooth( sal_True );
1270 		}
1271 	}
1272 }
1273 
ReadUserDataSequence(const uno::Sequence<beans::PropertyValue> & rSequence,sal_Bool bBrowse)1274 void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >& rSequence, sal_Bool bBrowse )
1275 {
1276 	if(GetDocShell()->IsPreview()||bIsPreviewDoubleClick)
1277 		return;
1278 	// #i43146# go to the last editing position when opening own files
1279 	bool bIsOwnDocument = lcl_IsOwnDocument( *this );
1280 	sal_Int32 nLength = rSequence.getLength();
1281 	if (nLength && (!pWrtShell->IsNewLayout() || pWrtShell->GetViewOptions()->getBrowseMode() || bBrowse) )
1282 	{
1283 		SET_CURR_SHELL(pWrtShell);
1284 		const beans::PropertyValue *pValue = rSequence.getConstArray();
1285 		const SwRect& rRect = pWrtShell->GetCharRect();
1286 		const Rectangle &rVis = GetVisArea();
1287 		const SwViewOption* pVOpt = pWrtShell->GetViewOptions();
1288 
1289 		long nX = rRect.Left(), nY = rRect.Top(), nLeft = rVis.Left(), nTop = rVis.Top();
1290 		long nRight = bBrowse ? LONG_MIN : rVis.Right(), nBottom = bBrowse ? LONG_MIN : rVis.Bottom();
1291 		sal_Int16 nZoomType = static_cast< sal_Int16 >(pVOpt->GetZoomType());
1292 		sal_Int16 nZoomFactor = static_cast < sal_Int16 > (pVOpt->GetZoom());
1293 		bool bViewLayoutBookMode = pVOpt->IsViewLayoutBookMode();
1294 		sal_Int16 nViewLayoutColumns = pVOpt->GetViewLayoutColumns();
1295 
1296 		sal_Bool bSelectedFrame = ( pWrtShell->GetSelFrmType() != FRMTYPE_NONE ),
1297 				 bGotViewLeft = sal_False, bGotViewTop = sal_False, bGotVisibleLeft = sal_False,
1298 				 bGotVisibleTop = sal_False, bGotVisibleRight = sal_False,
1299 				 bGotVisibleBottom = sal_False, bGotZoomType = sal_False,
1300 				 bGotZoomFactor = sal_False, bGotIsSelectedFrame = sal_False,
1301 				 bGotViewLayoutColumns = sal_False, bGotViewLayoutBookMode = sal_False;
1302 
1303 		for (sal_Int16 i = 0 ; i < nLength; i++)
1304 		{
1305 			if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ViewLeft" ) ) )
1306 			{
1307 				pValue->Value >>= nX;
1308 				nX = MM100_TO_TWIP( nX );
1309 				bGotViewLeft = sal_True;
1310 			}
1311 			else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ViewTop" ) ) )
1312 			{
1313 				pValue->Value >>= nY;
1314 				nY = MM100_TO_TWIP( nY );
1315 				bGotViewTop = sal_True;
1316 			}
1317 			else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "VisibleLeft" ) ) )
1318 			{
1319 				pValue->Value >>= nLeft;
1320 				nLeft = MM100_TO_TWIP( nLeft );
1321 				bGotVisibleLeft = sal_True;
1322 			}
1323 			else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "VisibleTop" ) ) )
1324 			{
1325 				pValue->Value >>= nTop;
1326 				nTop = MM100_TO_TWIP( nTop );
1327 				bGotVisibleTop = sal_True;
1328             }
1329             else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "VisibleRight" ) ) )
1330             {
1331                pValue->Value >>= nRight;
1332 			   nRight = MM100_TO_TWIP( nRight );
1333 			   bGotVisibleRight = sal_True;
1334             }
1335             else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "VisibleBottom" ) ) )
1336             {
1337                pValue->Value >>= nBottom;
1338 			   nBottom = MM100_TO_TWIP( nBottom );
1339 			   bGotVisibleBottom = sal_True;
1340             }
1341             else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ZoomType" ) ) )
1342             {
1343                pValue->Value >>= nZoomType;
1344 			   bGotZoomType = sal_True;
1345             }
1346             else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ZoomFactor" ) ) )
1347             {
1348 				pValue->Value >>= nZoomFactor;
1349 				bGotZoomFactor = sal_True;
1350 			}
1351 			else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ViewLayoutColumns" ) ) )
1352 			{
1353 				pValue->Value >>= nViewLayoutColumns;
1354 				bGotViewLayoutColumns = sal_True;
1355 			}
1356 			else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ViewLayoutBookMode" ) ) )
1357 			{
1358 				bViewLayoutBookMode = * (sal_Bool *) pValue->Value.getValue();
1359 				bGotViewLayoutBookMode = sal_True;
1360 			}
1361 			else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsSelectedFrame" ) ) )
1362 			{
1363 				pValue->Value >>= bSelectedFrame;
1364 				bGotIsSelectedFrame = sal_True;
1365 			}
1366 			pValue++;
1367 		}
1368 		if (bGotVisibleBottom)
1369 		{
1370 			Point aCrsrPos( nX, nY );
1371 			const long nAdd = pWrtShell->GetViewOptions()->getBrowseMode() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
1372 			if (nBottom <= (pWrtShell->GetDocSize().Height()+nAdd) )
1373 			{
1374 				pWrtShell->EnableSmooth( sal_False );
1375 				const Rectangle aVis( nLeft, nTop, nRight, nBottom );
1376 
1377 				sal_uInt16 nOff = 0;
1378 				SvxZoomType eZoom;
1379 				if ( !pWrtShell->GetViewOptions()->getBrowseMode() )
1380 					eZoom = static_cast < SvxZoomType > ( nZoomType );
1381 				else
1382 				{
1383 					eZoom = SVX_ZOOM_PERCENT;
1384 					++nOff;
1385 				}
1386 				if (bGotIsSelectedFrame)
1387 				{
1388 					sal_Bool bSelectObj = (sal_False != bSelectedFrame )
1389 										&& pWrtShell->IsObjSelectable( aCrsrPos );
1390 
1391                     // OD 11.02.2003 #100556# - set flag value to avoid macro execution.
1392                     bool bSavedFlagValue = pWrtShell->IsMacroExecAllowed();
1393                     pWrtShell->SetMacroExecAllowed( false );
1394 // !!! pb (11.08.2004): #i32536#
1395 // os: changed: The user data has to be read if the view is switched back from page preview
1396 // #i43146# go to the last editing position when opening own files
1397                     // #i33307# restore editing position
1398                     pViewImpl->SetRestorePosition(aCrsrPos, bSelectObj);
1399                     if(bOldShellWasPagePreView|| bIsOwnDocument)
1400                     {
1401 						pWrtShell->SwCrsrShell::SetCrsr( aCrsrPos, !bSelectObj );
1402 						if( bSelectObj )
1403 						{
1404 						    pWrtShell->SelectObj( aCrsrPos );
1405 						    pWrtShell->EnterSelFrmMode( &aCrsrPos );
1406 						}
1407 					}
1408 
1409                     // OD 11.02.2003 #100556# - reset flag value
1410                     pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
1411 				}
1412 				SelectShell();
1413 
1414                 // Set ViewLayoutSettings
1415                 const bool bSetViewLayoutSettings = bGotViewLayoutColumns && bGotViewLayoutBookMode &&
1416                                                     ( pVOpt->GetViewLayoutColumns() != nViewLayoutColumns || pVOpt->IsViewLayoutBookMode() != bViewLayoutBookMode );
1417 
1418                 const bool bSetViewSettings = bGotZoomType && bGotZoomFactor &&
1419                                               ( pVOpt->GetZoom() != nZoomFactor || pVOpt->GetZoomType() != eZoom );
1420 
1421                 // In case we have a 'fixed' view layout of 2 or more columns,
1422                 // we have to apply the view options *before* starting the action.
1423                 // Otherwise the SetZoom function cannot work correctly, because
1424                 // the view layout hasn't been calculated.
1425                 const bool bZoomNeedsViewLayout = bSetViewLayoutSettings &&
1426                                                   1 < nViewLayoutColumns &&
1427                                                   bSetViewSettings &&
1428                                                   eZoom != SVX_ZOOM_PERCENT;
1429 
1430 
1431 				if ( !bZoomNeedsViewLayout )
1432 					pWrtShell->StartAction();
1433 
1434 				if ( bSetViewLayoutSettings )
1435 					SetViewLayout( nViewLayoutColumns, bViewLayoutBookMode, sal_True );
1436 
1437 				if ( bZoomNeedsViewLayout )
1438 					pWrtShell->StartAction();
1439 
1440 				if ( bSetViewSettings )
1441 					SetZoom( eZoom, nZoomFactor, sal_True );
1442 
1443 // !!! pb (11.08.2004): #i32536#
1444 // os: changed: The user data has to be read if the view is switched back from page preview
1445 // #i43146# go to the last editing position when opening own files
1446                 if(bOldShellWasPagePreView||bIsOwnDocument)
1447                 {
1448     				if ( bBrowse && bGotVisibleLeft && bGotVisibleTop )
1449                     {
1450                         Point aTopLeft(aVis.TopLeft());
1451                         // #i76699# make sure the document is still centered
1452                         const SwTwips lBorder = IsDocumentBorder() ? DOCUMENTBORDER : 2 * DOCUMENTBORDER;
1453                         SwTwips nEditWidth = GetEditWin().GetOutputSize().Width();
1454                         if(nEditWidth > (aDocSz.Width() + lBorder ))
1455                             aTopLeft.X() = ( aDocSz.Width() + lBorder - nEditWidth ) / 2;
1456                         else
1457                         {
1458                             // check if the values are possible
1459                             long nXMax = pHScrollbar->GetRangeMax() - pHScrollbar->GetVisibleSize();
1460                             if( aTopLeft.X() > nXMax )
1461                                 aTopLeft.X() = nXMax < 0 ? 0 : nXMax;
1462                         }
1463                         SetVisArea( aTopLeft );
1464 					}
1465 					else if (bGotVisibleLeft && bGotVisibleTop && bGotVisibleRight && bGotVisibleBottom )
1466 						SetVisArea( aVis );
1467 				}
1468 
1469 				pWrtShell->LockView( sal_True );
1470 				pWrtShell->EndAction();
1471 				pWrtShell->LockView( sal_False );
1472 				pWrtShell->EnableSmooth( sal_True );
1473 			}
1474 		}
1475 	}
1476 }
1477 #define NUM_VIEW_SETTINGS 12
WriteUserDataSequence(uno::Sequence<beans::PropertyValue> & rSequence,sal_Bool bBrowse)1478 void SwView::WriteUserDataSequence ( uno::Sequence < beans::PropertyValue >& rSequence, sal_Bool bBrowse )
1479 {
1480 	const SwRect& rRect = pWrtShell->GetCharRect();
1481 	const Rectangle& rVis = GetVisArea();
1482 	Any aAny;
1483 
1484 	rSequence.realloc ( NUM_VIEW_SETTINGS );
1485 	sal_Int16 nIndex = 0;
1486 	beans::PropertyValue *pValue = rSequence.getArray();
1487 
1488 	sal_uInt16 nViewID( GetViewFrame()->GetCurViewId());
1489 	pValue->Name = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "ViewId" ) );
1490 	OUStringBuffer sBuffer ( OUString(RTL_CONSTASCII_USTRINGPARAM( "view" ) ) );
1491 	SvXMLUnitConverter::convertNumber(sBuffer, static_cast<sal_Int32>(nViewID));
1492 	pValue->Value <<= sBuffer.makeStringAndClear();
1493 	pValue++;nIndex++;
1494 
1495 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ViewLeft" ) );
1496 	pValue->Value <<= TWIP_TO_MM100 ( rRect.Left() );
1497 	pValue++;nIndex++;
1498 
1499 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ViewTop" ) );
1500 	pValue->Value <<= TWIP_TO_MM100 ( rRect.Top() );
1501 	pValue++;nIndex++;
1502 
1503 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "VisibleLeft" ) );
1504 	pValue->Value <<= TWIP_TO_MM100 ( rVis.Left() );
1505 	pValue++;nIndex++;
1506 
1507 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "VisibleTop" ) );
1508 	pValue->Value <<= TWIP_TO_MM100 ( rVis.Top() );
1509 	pValue++;nIndex++;
1510 
1511 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "VisibleRight" ) );
1512 	pValue->Value <<= TWIP_TO_MM100 ( bBrowse ? LONG_MIN : rVis.Right() );
1513 	pValue++;nIndex++;
1514 
1515 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "VisibleBottom" ) );
1516 	pValue->Value <<= TWIP_TO_MM100 ( bBrowse ? LONG_MIN : rVis.Bottom() );
1517 	pValue++;nIndex++;
1518 
1519 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZoomType" ) );
1520 	const sal_Int16 nZoomType = static_cast< sal_Int16 >(pWrtShell->GetViewOptions()->GetZoomType());
1521 	pValue->Value <<= nZoomType;
1522 	pValue++;nIndex++;
1523 
1524 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ViewLayoutColumns" ) );
1525 	const sal_Int16 nViewLayoutColumns = static_cast< sal_Int16 >(pWrtShell->GetViewOptions()->GetViewLayoutColumns());
1526 	pValue->Value <<= nViewLayoutColumns;
1527 	pValue++;nIndex++;
1528 
1529 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ViewLayoutBookMode" ) );
1530 	const sal_Bool bIsViewLayoutBookMode = pWrtShell->GetViewOptions()->IsViewLayoutBookMode();
1531 	pValue->Value.setValue( &bIsViewLayoutBookMode, ::getBooleanCppuType() );
1532 	pValue++;nIndex++;
1533 
1534 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZoomFactor" ) );
1535 	pValue->Value <<= static_cast < sal_Int16 > (pWrtShell->GetViewOptions()->GetZoom());
1536 	pValue++;nIndex++;
1537 
1538 	pValue->Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "IsSelectedFrame" ) );
1539 	const sal_Bool bIsSelected = FRMTYPE_NONE == pWrtShell->GetSelFrmType() ? sal_False : sal_True;
1540 	pValue->Value.setValue ( &bIsSelected, ::getBooleanCppuType() );
1541 	nIndex++;
1542 
1543 	if ( nIndex < NUM_VIEW_SETTINGS )
1544 		rSequence.realloc ( nIndex );
1545 }
1546 #undef NUM_VIEW_SETTINGS
1547 
1548 
1549 
ShowCursor(FASTBOOL bOn)1550 void SwView::ShowCursor( FASTBOOL bOn )
1551 {
1552 	// JP 10.10.2001: Bug 90461 - don't scroll the cursor into the visible area
1553 	sal_Bool bUnlockView = !pWrtShell->IsViewLocked();
1554 	pWrtShell->LockView( sal_True ); // lock visible section
1555 
1556 	if( !bOn )
1557 		pWrtShell->HideCrsr();
1558 	else if( !pWrtShell->IsFrmSelected() && !pWrtShell->IsObjSelected() )
1559 		pWrtShell->ShowCrsr();
1560 
1561 	if( bUnlockView )
1562 		pWrtShell->LockView( sal_False );
1563 }
1564 
1565 
1566 
DoVerb(long nVerb)1567 ErrCode SwView::DoVerb( long nVerb )
1568 {
1569 	if ( !GetViewFrame()->GetFrame().IsInPlace() )
1570 	{
1571 		SwWrtShell &rSh = GetWrtShell();
1572 		const int nSel = rSh.GetSelectionType();
1573 		if ( nSel & nsSelectionType::SEL_OLE )
1574 			rSh.LaunchOLEObj( nVerb );
1575 	}
1576 	return ERRCODE_NONE;
1577 }
1578 
1579 /*-----------------17.02.98 13:33-------------------
1580 	nur sal_True fuer eine Textselektion zurueck geben
1581 --------------------------------------------------*/
HasSelection(sal_Bool bText) const1582 sal_Bool SwView::HasSelection( sal_Bool bText ) const
1583 {
1584 	return bText ? GetWrtShell().SwCrsrShell::HasSelection()
1585 				 : GetWrtShell().HasSelection();
1586 }
1587 
1588 /*-----------------09/16/97 09:50am-----------------
1589 
1590 --------------------------------------------------*/
1591 
GetSelectionText(sal_Bool bCompleteWrds)1592 String SwView::GetSelectionText( sal_Bool bCompleteWrds )
1593 {
1594 	return GetSelectionTextParam( bCompleteWrds, sal_True );
1595 }
1596 
1597 /*-----------------09/16/97 09:50am-----------------
1598 
1599 --------------------------------------------------*/
GetSelectionTextParam(sal_Bool bCompleteWrds,sal_Bool bEraseTrail)1600 String	SwView::GetSelectionTextParam( sal_Bool bCompleteWrds,
1601 									   sal_Bool bEraseTrail )
1602 {
1603 	String sReturn;
1604 	if( bCompleteWrds && !GetWrtShell().HasSelection() )
1605 		GetWrtShell().SelWrd();
1606 
1607 	GetWrtShell().GetSelectedText( sReturn );
1608 	if( bEraseTrail )
1609 		sReturn.EraseTrailingChars();
1610 	return sReturn;
1611 }
1612 
1613 /*--------------------------------------------------------------------
1614 	Description:
1615  --------------------------------------------------------------------*/
1616 
1617 
1618 
GetGlosHdl()1619 SwGlossaryHdl* SwView::GetGlosHdl()
1620 {
1621 	if(!pGlosHdl)
1622 		pGlosHdl = new SwGlossaryHdl(GetViewFrame(), pWrtShell);
1623 	return pGlosHdl;
1624 }
1625 
1626 /*-----------------05.09.96 15.50-------------------
1627 
1628 --------------------------------------------------*/
1629 
1630 
1631 
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)1632 void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1633 {
1634 	sal_Bool bCallBase = sal_True;
1635 	if ( rHint.ISA(SfxSimpleHint) )
1636 	{
1637 		sal_uInt32 nId = ((SfxSimpleHint&)rHint).GetId();
1638 		switch ( nId )
1639 		{
1640 			// --> OD 2005-03-03 #i43775# - sub shells will be destroyed by the
1641 			// dispatcher, if the view frame is dying. Thus, reset member <pShell>.
1642 			case SFX_HINT_DYING:
1643 				{
1644 					if ( &rBC == GetViewFrame() )
1645 					{
1646 						ResetSubShell();
1647 					}
1648 				}
1649 				break;
1650 			// <--
1651 			case SFX_HINT_MODECHANGED:
1652 				{
1653 					// Modalmodus-Umschaltung?
1654 					sal_Bool bModal = GetDocShell()->IsInModalMode();
1655 					pHRuler->SetActive( !bModal );
1656 					pVRuler->SetActive( !bModal );
1657 				}
1658 
1659 				/* no break here */
1660 
1661 			case SFX_HINT_TITLECHANGED:
1662 				if ( GetDocShell()->IsReadOnly() != GetWrtShell().GetViewOptions()->IsReadonly() )
1663 				{
1664 					SwWrtShell &rSh = GetWrtShell();
1665 					rSh.SetReadonlyOption( GetDocShell()->IsReadOnly() );
1666 
1667                     if ( rSh.GetViewOptions()->IsViewVRuler() )
1668                         CreateVLineal();
1669 					else
1670                         KillVLineal();
1671                     if ( rSh.GetViewOptions()->IsViewHRuler() )
1672                         CreateTab();
1673 					else
1674                         KillTab();
1675 					bool bReadonly = GetDocShell()->IsReadOnly();
1676                     // #i76332# if document is to be opened in alive-mode then this has to be regarded while switching from readonly-mode to edit-mode
1677                     if( !bReadonly )
1678                     {
1679                         SwDrawModel* pDrawModel = 0;
1680 
1681                         if ( 0 != ( pDrawModel = GetDocShell()->GetDoc()->GetDrawModel() ) )
1682                         {
1683                             if( !pDrawModel->GetOpenInDesignMode() )
1684                                 break; // don't touch the design mode
1685                         }
1686                     }
1687                     SfxBoolItem aItem( SID_FM_DESIGN_MODE, !bReadonly);
1688                     GetDispatcher().Execute( SID_FM_DESIGN_MODE, SFX_CALLMODE_ASYNCHRON,
1689 												&aItem, 0L );
1690 				}
1691 				break;
1692 
1693 			case SW_BROADCAST_DRAWVIEWS_CREATED:
1694 				{
1695 					bCallBase = sal_False;
1696 					if ( GetFormShell() )
1697 					{
1698 						GetFormShell()->SetView(
1699 							PTR_CAST(FmFormView, GetWrtShell().GetDrawView()) );
1700 						SfxBoolItem aItem( SID_FM_DESIGN_MODE, !GetDocShell()->IsReadOnly());
1701 						GetDispatcher().Execute( SID_FM_DESIGN_MODE, SFX_CALLMODE_SYNCHRON,
1702 												  &aItem, 0L );
1703 					}
1704 				}
1705 				break;
1706 		}
1707 	}
1708 	else if(rHint.ISA(FmDesignModeChangedHint))
1709 	{
1710 		sal_Bool bDesignMode = ((FmDesignModeChangedHint&)rHint).GetDesignMode();
1711 		if (!bDesignMode && GetDrawFuncPtr())
1712 		{
1713 			GetDrawFuncPtr()->Deactivate();
1714 			SetDrawFuncPtr(NULL);
1715 			LeaveDrawCreate();
1716 			AttrChangedNotify(pWrtShell);
1717 		}
1718 	}
1719 
1720 	if ( bCallBase )
1721 		SfxViewShell::Notify(rBC, rHint);
1722 }
1723 
1724 /*-----------------02.12.96 12:36-------------------
1725 
1726 --------------------------------------------------*/
1727 #if defined WNT || defined UNX
1728 
ScannerEventHdl(const EventObject &)1729 void SwView::ScannerEventHdl( const EventObject& /*rEventObject*/ )
1730 {
1731 	uno::Reference< XScannerManager > xScanMgr = SW_MOD()->GetScannerManager();
1732 	if( xScanMgr.is() )
1733 	{
1734 		const ScannerContext	aContext( xScanMgr->getAvailableScanners().getConstArray()[ 0 ] );
1735 		const ScanError			eError = xScanMgr->getError( aContext );
1736 
1737 		if( ScanError_ScanErrorNone == eError )
1738 		{
1739 			const uno::Reference< awt::XBitmap > xBitmap( xScanMgr->getBitmap( aContext ) );
1740 
1741 			if( xBitmap.is() )
1742 			{
1743 				const BitmapEx aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) );
1744 
1745 				if( !!aScanBmp )
1746 				{
1747 					Graphic aGrf(aScanBmp);
1748 					pWrtShell->Insert( aEmptyStr, aEmptyStr, aGrf );
1749 				}
1750 			}
1751 		}
1752 	}
1753 	SfxBindings& rBind = GetViewFrame()->GetBindings();
1754 	rBind.Invalidate( SID_TWAIN_SELECT );
1755 	rBind.Invalidate( SID_TWAIN_TRANSFER );
1756 }
1757 #endif
1758 
1759 /*-----------------04.03.97 15:07-------------------
1760 
1761 --------------------------------------------------*/
1762 
1763 
StopShellTimer()1764 void	SwView::StopShellTimer()
1765 {
1766 	if(aTimer.IsActive())
1767 	{
1768 		aTimer.Stop();
1769 		if ( bAttrChgNotifiedWithRegistrations )
1770 		{
1771 			GetViewFrame()->GetBindings().LEAVEREGISTRATIONS();
1772 			bAttrChgNotifiedWithRegistrations = sal_False;
1773 		}
1774 		SelectShell();
1775 		bAttrChgNotified = sal_False;
1776 	}
1777 }
1778 
1779 /*-----------------09/03/97 04:12pm-----------------
1780 
1781 --------------------------------------------------*/
PrepareClose(sal_Bool bUI,sal_Bool bForBrowsing)1782 sal_uInt16 SwView::PrepareClose( sal_Bool bUI, sal_Bool bForBrowsing )
1783 {
1784 	SfxViewFrame* pVFrame = GetViewFrame();
1785 	pVFrame->SetChildWindow( SwInputChild::GetChildWindowId(), sal_False );
1786 	if( pVFrame->GetDispatcher()->IsLocked() )
1787 		pVFrame->GetDispatcher()->Lock(sal_False);
1788 
1789 	sal_uInt16 nRet;
1790 	if ( pFormShell &&
1791 		 sal_True != (nRet = pFormShell->PrepareClose( bUI, bForBrowsing )) )
1792 
1793 	{
1794 		return nRet;
1795 	}
1796 	return SfxViewShell::PrepareClose( bUI, bForBrowsing );
1797 }
1798 
1799 
1800 
1801 	// status methods for clipboard.
1802 	// Status changes now notified from the clipboard.
IsPasteAllowed()1803 sal_Bool SwView::IsPasteAllowed()
1804 {
1805 	sal_uInt16 nPasteDestination = SwTransferable::GetSotDestination( *pWrtShell );
1806 	if( nLastPasteDestination != nPasteDestination )
1807 	{
1808 		TransferableDataHelper aDataHelper(
1809 						TransferableDataHelper::CreateFromSystemClipboard(
1810 														&GetEditWin()) );
1811 		if( aDataHelper.GetXTransferable().is() )
1812 		{
1813 			bPasteState = SwTransferable::IsPaste( *pWrtShell, aDataHelper );
1814 			bPasteSpecialState = SwTransferable::IsPasteSpecial(
1815 													*pWrtShell, aDataHelper );
1816 		}
1817 		else
1818 			bPasteState = bPasteSpecialState = sal_False;
1819 
1820 		if( 0xFFFF == nLastPasteDestination ) // the init value
1821 			pViewImpl->AddClipboardListener();
1822 		nLastPasteDestination = nPasteDestination;
1823 	}
1824 	return bPasteState;
1825 }
1826 
IsPasteSpecialAllowed()1827 sal_Bool SwView::IsPasteSpecialAllowed()
1828 {
1829 	if ( pFormShell && pFormShell->IsActiveControl() )
1830 		return sal_False;
1831 
1832 	sal_uInt16 nPasteDestination = SwTransferable::GetSotDestination( *pWrtShell );
1833 	if( nLastPasteDestination != nPasteDestination )
1834 	{
1835 		TransferableDataHelper aDataHelper(
1836 						TransferableDataHelper::CreateFromSystemClipboard(
1837 														&GetEditWin()) );
1838 		if( aDataHelper.GetXTransferable().is() )
1839 		{
1840 			bPasteState = SwTransferable::IsPaste( *pWrtShell, aDataHelper );
1841 			bPasteSpecialState = SwTransferable::IsPasteSpecial(
1842 													*pWrtShell, aDataHelper );
1843 		}
1844 		else
1845 			bPasteState = bPasteSpecialState = sal_False;
1846 
1847 		if( 0xFFFF == nLastPasteDestination ) // the init value
1848 			pViewImpl->AddClipboardListener();
1849 	}
1850 	return bPasteSpecialState;
1851 }
1852 /* -----------------------------12.07.01 13:25--------------------------------
1853 
1854  ---------------------------------------------------------------------------*/
NotifyDBChanged()1855 void SwView::NotifyDBChanged()
1856 {
1857 	GetViewImpl()->GetUNOObject_Impl()->NotifyDBChanged();
1858 }
1859 
1860 /*--------------------------------------------------------------------
1861 	Description: print
1862  --------------------------------------------------------------------*/
1863 
1864 /* -----------------------------28.10.02 13:25--------------------------------
1865 
1866  ---------------------------------------------------------------------------*/
GetTmpSelectionDoc()1867 SfxObjectShellLock & SwView::GetTmpSelectionDoc()
1868 {
1869 	return GetViewImpl()->GetTmpSelectionDoc();
1870 }
1871 /* -----------------------------31.10.02 13:25--------------------------------
1872 
1873  ---------------------------------------------------------------------------*/
GetOrCreateTmpSelectionDoc()1874 SfxObjectShellLock & SwView::GetOrCreateTmpSelectionDoc()
1875 {
1876 	SfxObjectShellLock &rxTmpDoc = GetViewImpl()->GetTmpSelectionDoc();
1877 	if (!rxTmpDoc.Is())
1878 	{
1879 		SwXTextView *pImpl = GetViewImpl()->GetUNOObject_Impl();
1880 		rxTmpDoc = pImpl->BuildTmpSelectionDoc();
1881 	}
1882 	return rxTmpDoc;
1883 }
1884 /* -----------------3/31/2003 12:39PM----------------
1885 
1886  --------------------------------------------------*/
AddTransferable(SwTransferable & rTransferable)1887 void SwView::AddTransferable(SwTransferable& rTransferable)
1888 {
1889 	GetViewImpl()->AddTransferable(rTransferable);
1890 }
1891 
1892 /* --------------------------------------------------*/
1893 
1894 namespace sw {
1895 
InitPrintOptionsFromApplication(SwPrintData & o_rData,bool const bWeb)1896 void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb)
1897 {
1898 	o_rData = *SW_MOD()->GetPrtOptions(bWeb);
1899 }
1900 
1901 } // namespace sw
1902