bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / uiview / view0.cxx
blobe5f7b3b4373370ddd7556b1f532f5112739e819a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "hintids.hxx"
22 #include <vcl/graph.hxx>
23 #include <svx/galbrws.hxx>
24 #include <svl/srchitem.hxx>
25 #include <SwSpellDialogChildWindow.hxx>
26 #include <svl/eitem.hxx>
27 #include <unotools/linguprops.hxx>
28 #include <unotools/lingucfg.hxx>
29 #include <viewopt.hxx>
30 #include <globals.h>
31 #include <sfx2/app.hxx>
32 #include <sfx2/infobar.hxx>
33 #include <sfx2/request.hxx>
34 #include <svl/whiter.hxx>
35 #include <svx/srchdlg.hxx>
36 #include <sfx2/templdlg.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <sfx2/bindings.hxx>
39 #include <sfx2/sidebar/SidebarChildWindow.hxx>
40 #include <uivwimp.hxx>
41 #include <avmedia/mediaplayer.hxx>
42 #include <swmodule.hxx>
43 #include <com/sun/star/linguistic2/XLinguProperties.hpp>
45 #include <sfx2/objface.hxx>
46 #include <navipi.hxx>
47 #include <wrtsh.hxx>
48 #include <edtwin.hxx>
49 #include "view.hxx"
50 #include "basesh.hxx"
51 #include "docsh.hxx"
52 #include "doc.hxx"
53 #include "globals.hrc"
54 #include "cmdid.h" // FN_ ...
55 #include "globdoc.hxx"
56 #include "wview.hxx"
57 #include "shells.hrc"
59 #define SwView
60 #define GlobalContents
61 #define Text
62 #define TextDrawText
63 #define TextInTable
64 #define ListInText
65 #define ListInTable
66 #define WebTextInTable
67 #define WebListInText
68 #define WebListInTable
69 #include <sfx2/msg.hxx>
70 #include "swslots.hxx"
71 #include <PostItMgr.hxx>
73 using namespace ::com::sun::star;
75 #include <unotools/moduleoptions.hxx>
77 #include <IDocumentSettingAccess.hxx>
79 #include <unomid.h>
81 SFX_IMPL_NAMED_VIEWFACTORY(SwView, "Default")
83 if ( SvtModuleOptions().IsWriter() )
85 SFX_VIEW_REGISTRATION(SwDocShell);
86 SFX_VIEW_REGISTRATION(SwGlobalDocShell);
90 SFX_IMPL_INTERFACE( SwView, SfxViewShell, SW_RES(RID_TOOLS_TOOLBOX) )
92 SFX_CHILDWINDOW_CONTEXT_REGISTRATION(SID_NAVIGATOR);
93 SFX_CHILDWINDOW_REGISTRATION(SID_TASKPANE);
94 SFX_CHILDWINDOW_REGISTRATION(::sfx2::sidebar::SidebarChildWindow::GetChildWindowId());
95 SFX_CHILDWINDOW_REGISTRATION(SfxTemplateDialogWrapper::GetChildWindowId());
96 SFX_CHILDWINDOW_REGISTRATION(SfxInfoBarContainerChild::GetChildWindowId());
97 SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
98 SFX_CHILDWINDOW_REGISTRATION(SwSpellDialogChildWindow::GetChildWindowId());
99 SFX_CHILDWINDOW_REGISTRATION(FN_REDLINE_ACCEPT);
100 SFX_CHILDWINDOW_REGISTRATION(SID_HYPERLINK_DIALOG);
101 SFX_CHILDWINDOW_REGISTRATION(FN_WORDCOUNT_DIALOG);
102 SFX_CHILDWINDOW_REGISTRATION(GalleryChildWindow::GetChildWindowId());
103 SFX_CHILDWINDOW_REGISTRATION(::avmedia::MediaPlayer::GetChildWindowId());
104 SFX_CHILDWINDOW_REGISTRATION(FN_INSERT_FIELD_DATA_ONLY);
105 SFX_FEATURED_CHILDWINDOW_REGISTRATION(FN_SYNC_LABELS, CHILDWIN_LABEL );
106 SFX_FEATURED_CHILDWINDOW_REGISTRATION(FN_MAILMERGE_CHILDWINDOW, CHILDWIN_MAILMERGE);
107 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS|
108 SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
109 SW_RES(RID_TOOLS_TOOLBOX) );
112 TYPEINIT1(SwView,SfxViewShell)
114 ShellModes SwView::GetShellMode()
116 return m_pViewImpl->GetShellMode();
119 view::XSelectionSupplier* SwView::GetUNOObject()
121 return m_pViewImpl->GetUNOObject();
124 void SwView::ApplyAccessiblityOptions(SvtAccessibilityOptions& rAccessibilityOptions)
126 m_pWrtShell->ApplyAccessiblityOptions(rAccessibilityOptions);
127 //to enable the right state of the selection cursor in readonly documents
128 if(GetDocShell()->IsReadOnly())
129 m_pWrtShell->ShowCrsr();
133 void SwView::SetMailMergeConfigItem(SwMailMergeConfigItem* pConfigItem,
134 sal_uInt16 nRestart, sal_Bool bIsSource)
136 m_pViewImpl->SetMailMergeConfigItem(pConfigItem, nRestart, bIsSource);
137 UIFeatureChanged();
140 SwMailMergeConfigItem* SwView::GetMailMergeConfigItem()
142 return m_pViewImpl->GetMailMergeConfigItem();
145 sal_uInt16 SwView::GetMailMergeRestartPage() const
147 return m_pViewImpl->GetMailMergeRestartPage();
150 sal_Bool SwView::IsMailMergeSourceView() const
152 return m_pViewImpl->IsMailMergeSourceView();
155 static sal_Bool lcl_IsViewMarks( const SwViewOption& rVOpt )
157 return rVOpt.IsHardBlank() &&
158 rVOpt.IsSoftHyph() &&
159 SwViewOption::IsFieldShadings();
161 static void lcl_SetViewMarks(SwViewOption& rVOpt, sal_Bool bOn )
163 rVOpt.SetHardBlank(bOn);
164 rVOpt.SetSoftHyph(bOn);
165 SwViewOption::SetAppearanceFlag(
166 VIEWOPT_FIELD_SHADINGS, bOn, sal_True);
169 static void lcl_SetViewMetaChars( SwViewOption& rVOpt, sal_Bool bOn)
171 rVOpt.SetViewMetaChars( bOn );
172 if(bOn && !(rVOpt.IsParagraph() ||
173 rVOpt.IsTab() ||
174 rVOpt.IsLineBreak() ||
175 rVOpt.IsShowHiddenChar() ||
176 rVOpt.IsBlank()))
178 rVOpt.SetParagraph(bOn);
179 rVOpt.SetTab(bOn);
180 rVOpt.SetLineBreak(bOn);
181 rVOpt.SetBlank(bOn);
182 rVOpt.SetShowHiddenChar(bOn);
186 void SwView::RecheckBrowseMode()
188 // OS: numerische Reihenfolge beachten!
189 static sal_uInt16 const aInva[] =
191 //SID_NEWWINDOW,/*5620*/
192 SID_BROWSER_MODE, /*6313*/
193 SID_RULER_BORDERS, SID_RULER_PAGE_POS,
194 //SID_ATTR_LONG_LRSPACE,
195 SID_HTML_MODE,
196 SID_RULER_PROTECT,
197 //SID_AUTOSPELL_CHECK,
198 //SID_AUTOSPELL_MARKOFF,
199 FN_RULER, /*20211*/
200 FN_VIEW_GRAPHIC, /*20213*/
201 FN_VIEW_BOUNDS, /**/
202 FN_VIEW_FIELDS, /*20215*/
203 FN_VLINEAL, /*20216*/
204 FN_VSCROLLBAR, /*20217*/
205 FN_HSCROLLBAR, /*20218*/
206 FN_VIEW_META_CHARS, /**/
207 FN_VIEW_MARKS, /**/
208 //FN_VIEW_FIELDNAME, /**/
209 FN_VIEW_TABLEGRID, /*20227*/
210 FN_PRINT_LAYOUT, /*20237*/
211 FN_QRY_MERGE, /*20364*/
212 FN_SHADOWCURSOR, /**/
215 // the view must not exist!
216 GetViewFrame()->GetBindings().Invalidate(aInva);
217 CheckVisArea();
219 SvxZoomType eType;
220 if( GetWrtShell().GetViewOptions()->getBrowseMode() && SVX_ZOOM_PERCENT != (eType = (SvxZoomType)
221 GetWrtShell().GetViewOptions()->GetZoomType()) )
222 SetZoom( eType );
223 InvalidateBorder();
226 /*--------------------------------------------------------------------
227 State of view options
228 --------------------------------------------------------------------*/
229 void SwView::StateViewOptions(SfxItemSet &rSet)
231 SfxWhichIter aIter(rSet);
232 sal_uInt16 nWhich = aIter.FirstWhich();
233 SfxBoolItem aBool;
234 const SwViewOption* pOpt = GetWrtShell().GetViewOptions();
235 const IDocumentSettingAccess* pIDSA = GetDocShell()->getIDocumentSettingAccess();
237 while(nWhich)
239 sal_Bool bReadonly = GetDocShell()->IsReadOnly();
240 if ( bReadonly && nWhich != FN_VIEW_GRAPHIC )
242 rSet.DisableItem(nWhich);
243 nWhich = 0;
245 switch(nWhich)
247 case FN_RULER:
249 if(!pOpt->IsViewHRuler(sal_True) && !pOpt->IsViewVRuler(sal_True))
251 rSet.DisableItem(nWhich);
252 nWhich = 0;
254 else
255 aBool.SetValue( pOpt->IsViewAnyRuler());
257 break;
258 case SID_BROWSER_MODE:
259 case FN_PRINT_LAYOUT:
261 sal_Bool bState = pOpt->getBrowseMode();
262 if(FN_PRINT_LAYOUT == nWhich)
263 bState = !bState;
264 aBool.SetValue( bState );
266 break;
267 case FN_VIEW_BOUNDS:
268 aBool.SetValue( SwViewOption::IsDocBoundaries()); break;
269 case FN_VIEW_GRAPHIC:
270 aBool.SetValue( !pOpt->IsGraphic() ); break;
271 case FN_VIEW_FIELDS:
272 aBool.SetValue( SwViewOption::IsFieldShadings() ); break;
273 case FN_VIEW_FIELDNAME:
274 aBool.SetValue( pOpt->IsFldName() ); break;
275 case FN_VIEW_MARKS:
276 aBool.SetValue( lcl_IsViewMarks(*pOpt) ); break;
277 case FN_VIEW_META_CHARS:
278 aBool.SetValue( pOpt->IsViewMetaChars() ); break;
279 case FN_VIEW_TABLEGRID:
280 aBool.SetValue( SwViewOption::IsTableBoundaries() ); break;
281 case FN_VIEW_NOTES:
283 aBool.SetValue( pOpt->IsPostIts());
284 if (!GetPostItMgr()->HasNotes())
286 aBool.SetWhich( nWhich );
287 rSet.Put( aBool );
288 rSet.DisableItem(nWhich);
289 nWhich = 0;
291 break;
293 case FN_VIEW_HIDDEN_PARA:
294 aBool.SetValue( pOpt->IsShowHiddenPara()); break;
295 case SID_GRID_VISIBLE:
296 aBool.SetValue( pOpt->IsGridVisible() ); break;
297 case SID_GRID_USE:
298 aBool.SetValue( pOpt->IsSnap() ); break;
299 case SID_HELPLINES_MOVE:
300 aBool.SetValue( pOpt->IsCrossHair() ); break;
301 case FN_VIEW_SMOOTH_SCROLL:
302 aBool.SetValue( pOpt->IsSmoothScroll()); break;
303 case FN_VLINEAL:
304 aBool.SetValue( 0 != StatVRuler() ); break;
305 case FN_HSCROLLBAR:
306 if( pOpt->getBrowseMode() )
308 rSet.DisableItem(nWhich);
309 nWhich = 0;
311 else
312 aBool.SetValue( IsHScrollbarVisible() ); break;
313 case FN_VSCROLLBAR:
314 aBool.SetValue( IsVScrollbarVisible() ); break;
315 case SID_AUTOSPELL_CHECK:
316 aBool.SetValue( pOpt->IsOnlineSpell() );
317 break;
318 case FN_SHADOWCURSOR:
319 if (pIDSA == 0 || pOpt->getBrowseMode() )
321 rSet.DisableItem( nWhich );
322 nWhich = 0;
324 else
325 aBool.SetValue( pOpt->IsShadowCursor() );
326 break;
330 if( nWhich )
332 aBool.SetWhich( nWhich );
333 rSet.Put( aBool );
335 nWhich = aIter.NextWhich();
339 /*--------------------------------------------------------------------
340 execute view options
341 --------------------------------------------------------------------*/
342 void SwView::ExecViewOptions(SfxRequest &rReq)
344 SwViewOption* pOpt = new SwViewOption( *GetWrtShell().GetViewOptions() );
345 sal_Bool bModified = GetWrtShell().IsModified();
347 int eState = STATE_TOGGLE;
348 sal_Bool bSet = sal_False;
349 bool bBrowseModeChanged = false;
351 const SfxItemSet *pArgs = rReq.GetArgs();
352 sal_uInt16 nSlot = rReq.GetSlot();
353 const SfxPoolItem* pAttr=NULL;
355 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nSlot , sal_False, &pAttr ))
357 bSet = ((SfxBoolItem*)pAttr)->GetValue();
358 eState = bSet ? STATE_ON : STATE_OFF;
361 sal_Bool bFlag = STATE_ON == eState;
362 uno::Reference< linguistic2::XLinguProperties > xLngProp( ::GetLinguPropertySet() );
364 switch ( nSlot )
366 case FN_VIEW_GRAPHIC:
368 if( STATE_TOGGLE == eState )
369 bFlag = !pOpt->IsGraphic();
370 pOpt->SetGraphic( bFlag );
371 break;
373 case FN_VIEW_FIELDS:
374 if( STATE_TOGGLE == eState )
375 bFlag = !SwViewOption::IsFieldShadings() ;
376 SwViewOption::SetAppearanceFlag(VIEWOPT_FIELD_SHADINGS, bFlag, sal_True );
377 break;
379 case FN_VIEW_BOUNDS:
380 if( STATE_TOGGLE == eState )
381 bFlag = !SwViewOption::IsDocBoundaries();
382 SwViewOption::SetAppearanceFlag(VIEWOPT_DOC_BOUNDARIES, bFlag, sal_True );
383 break;
385 case SID_GRID_VISIBLE:
386 if( STATE_TOGGLE == eState )
387 bFlag = !pOpt->IsGridVisible();
389 pOpt->SetGridVisible( bFlag );
390 break;
392 case SID_GRID_USE:
393 if( STATE_TOGGLE == eState )
394 bFlag = !pOpt->IsSnap();
396 pOpt->SetSnap( bFlag );
397 break;
399 case SID_HELPLINES_MOVE:
400 if( STATE_TOGGLE == eState )
401 bFlag = !pOpt->IsCrossHair();
403 pOpt->SetCrossHair( bFlag );
404 break;
406 case SID_BROWSER_MODE:
407 case FN_PRINT_LAYOUT:
408 if( STATE_TOGGLE == eState )
409 bFlag = !pOpt->getBrowseMode();
410 else if( nSlot == FN_PRINT_LAYOUT )
411 bFlag = !bFlag;
412 bBrowseModeChanged = bFlag != pOpt->getBrowseMode();
413 // Disable "multiple layout"
414 GetDocShell()->ToggleBrowserMode( bFlag, this );
416 pOpt->setBrowseMode( bFlag );
417 break;
419 case FN_VIEW_NOTES:
420 if ( STATE_TOGGLE == eState )
421 bFlag = !pOpt->IsPostIts();
423 GetPostItMgr()->SetLayout();
424 pOpt->SetPostIts( bFlag );
425 if (pOpt->IsPostIts())
426 GetPostItMgr()->CheckMetaText();
427 break;
429 case FN_VIEW_HIDDEN_PARA:
430 if ( STATE_TOGGLE == eState )
431 bFlag = !pOpt->IsShowHiddenPara();
433 pOpt->SetShowHiddenPara( bFlag );
434 break;
436 case FN_VIEW_SMOOTH_SCROLL:
438 if ( STATE_TOGGLE == eState )
439 bFlag = !pOpt->IsSmoothScroll();
441 pOpt->SetSmoothScroll( bFlag );
442 break;
445 case FN_VLINEAL:
446 if( STATE_TOGGLE == eState )
447 bFlag = !pOpt->IsViewVRuler();
449 pOpt->SetViewVRuler( bFlag );
450 break;
452 case FN_VSCROLLBAR:
453 if( STATE_TOGGLE == eState )
454 bFlag = !pOpt->IsViewVScrollBar();
456 pOpt->SetViewVScrollBar( bFlag );
457 break;
459 case FN_HSCROLLBAR:
460 if( STATE_TOGGLE == eState )
461 bFlag = !pOpt->IsViewHScrollBar();
463 pOpt->SetViewHScrollBar( bFlag );
464 break;
465 case FN_RULER:
466 if( STATE_TOGGLE == eState )
467 bFlag = !pOpt->IsViewAnyRuler();
469 pOpt->SetViewAnyRuler( bFlag );
470 break;
472 case FN_VIEW_TABLEGRID:
473 if( STATE_TOGGLE == eState )
474 bFlag = !SwViewOption::IsTableBoundaries();
475 SwViewOption::SetAppearanceFlag(VIEWOPT_TABLE_BOUNDARIES, bFlag, sal_True );
476 break;
478 case FN_VIEW_FIELDNAME:
479 if( STATE_TOGGLE == eState )
480 bFlag = !pOpt->IsFldName() ;
482 pOpt->SetFldName( bFlag );
483 break;
484 case FN_VIEW_MARKS:
485 if( STATE_TOGGLE == eState )
486 bFlag = !lcl_IsViewMarks(*pOpt) ;
488 lcl_SetViewMarks( *pOpt, bFlag );
489 break;
490 case FN_VIEW_META_CHARS:
491 if( STATE_TOGGLE == eState )
492 bFlag = !pOpt->IsViewMetaChars();
494 lcl_SetViewMetaChars( *pOpt, bFlag );
495 break;
496 case SID_AUTOSPELL_CHECK:
497 if( STATE_TOGGLE == eState )
498 bFlag = bSet = !pOpt->IsOnlineSpell();
500 pOpt->SetOnlineSpell(bSet);
502 uno::Any aVal( &bSet, ::getCppuBooleanType() );
503 OUString aPropName(UPN_IS_SPELL_AUTO);
505 SvtLinguConfig aCfg;
506 aCfg.SetProperty( aPropName, aVal );
508 if (xLngProp.is())
509 xLngProp->setIsSpellAuto( bSet );
511 // for the time being we do not have a specific option for grammarchecking.
512 // thus we'll use the one for spell checking...
513 if (bSet)
515 SwDocShell *pDocSh = GetDocShell();
516 SwDoc *pDoc = pDocSh? pDocSh->GetDoc() : NULL;
518 // right now we don't have view options for automatic grammar checking. Thus...
519 sal_Bool bIsAutoGrammar = sal_False;
520 aCfg.GetProperty( UPN_IS_GRAMMAR_AUTO ) >>= bIsAutoGrammar;
522 if (pDoc && bIsAutoGrammar)
523 StartGrammarChecking( *pDoc );
526 break;
527 case FN_SHADOWCURSOR:
528 if( STATE_TOGGLE == eState )
529 bFlag = bSet = !pOpt->IsShadowCursor();
531 pOpt->SetShadowCursor(bSet);
532 break;
534 default:
535 OSL_FAIL("wrong request method");
536 return;
539 // UserPrefs setzen Request als bearbeitet kennzeichnen
540 sal_Bool bWebView = 0 != dynamic_cast<const SwWebView*>(this);
541 SwWrtShell &rSh = GetWrtShell();
542 rSh.StartAction();
543 SwModule* pModule = SW_MOD();
544 if( !(*rSh.GetViewOptions() == *pOpt ))
546 rSh.ApplyViewOptions( *pOpt );
547 if( bBrowseModeChanged )
549 RecheckBrowseMode();
550 CheckVisArea();
553 //Die UsrPref muessen als Modified gekennzeichnet werden.
554 //call for initialization
555 pModule->GetUsrPref(bWebView);
556 pModule->CheckSpellChanges( pOpt->IsOnlineSpell(), false, false, false );
558 //OS: Modified wieder zuruecksetzen, weil Ansicht/Felder
559 // das Doc modified setzt.
560 if( !bModified )
561 rSh.ResetModified();
563 pModule->ApplyUsrPref( *pOpt, this, bWebView ? VIEWOPT_DEST_WEB : VIEWOPT_DEST_TEXT );
565 // #i6193# let postits know about new spellcheck setting
566 if ( nSlot == SID_AUTOSPELL_CHECK )
567 GetPostItMgr()->SetSpellChecking();
569 const sal_Bool bLockedView = rSh.IsViewLocked();
570 rSh.LockView( sal_True ); //lock visible section
571 GetWrtShell().EndAction();
572 if( bBrowseModeChanged && !bFlag )
573 CalcVisArea( GetEditWin().GetOutputSizePixel() );
574 rSh.LockView( bLockedView );
576 delete pOpt;
577 Invalidate(rReq.GetSlot());
578 if(!pArgs)
579 rReq.AppendItem(SfxBoolItem(nSlot, (sal_Bool)bFlag));
580 rReq.Done();
583 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */