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