1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
53 #include "globals.hrc"
54 #include "cmdid.h" // FN_ ...
55 #include "globdoc.hxx"
60 #define GlobalContents
66 #define WebTextInTable
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>
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
);
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() ||
174 rVOpt
.IsLineBreak() ||
175 rVOpt
.IsShowHiddenChar() ||
178 rVOpt
.SetParagraph(bOn
);
180 rVOpt
.SetLineBreak(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,
197 //SID_AUTOSPELL_CHECK,
198 //SID_AUTOSPELL_MARKOFF,
200 FN_VIEW_GRAPHIC
, /*20213*/
202 FN_VIEW_FIELDS
, /*20215*/
203 FN_VLINEAL
, /*20216*/
204 FN_VSCROLLBAR
, /*20217*/
205 FN_HSCROLLBAR
, /*20218*/
206 FN_VIEW_META_CHARS
, /**/
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
);
220 if( GetWrtShell().GetViewOptions()->getBrowseMode() && SVX_ZOOM_PERCENT
!= (eType
= (SvxZoomType
)
221 GetWrtShell().GetViewOptions()->GetZoomType()) )
226 /*--------------------------------------------------------------------
227 State of view options
228 --------------------------------------------------------------------*/
229 void SwView::StateViewOptions(SfxItemSet
&rSet
)
231 SfxWhichIter
aIter(rSet
);
232 sal_uInt16 nWhich
= aIter
.FirstWhich();
234 const SwViewOption
* pOpt
= GetWrtShell().GetViewOptions();
235 const IDocumentSettingAccess
* pIDSA
= GetDocShell()->getIDocumentSettingAccess();
239 sal_Bool bReadonly
= GetDocShell()->IsReadOnly();
240 if ( bReadonly
&& nWhich
!= FN_VIEW_GRAPHIC
)
242 rSet
.DisableItem(nWhich
);
249 if(!pOpt
->IsViewHRuler(sal_True
) && !pOpt
->IsViewVRuler(sal_True
))
251 rSet
.DisableItem(nWhich
);
255 aBool
.SetValue( pOpt
->IsViewAnyRuler());
258 case SID_BROWSER_MODE
:
259 case FN_PRINT_LAYOUT
:
261 sal_Bool bState
= pOpt
->getBrowseMode();
262 if(FN_PRINT_LAYOUT
== nWhich
)
264 aBool
.SetValue( bState
);
268 aBool
.SetValue( SwViewOption::IsDocBoundaries()); break;
269 case FN_VIEW_GRAPHIC
:
270 aBool
.SetValue( !pOpt
->IsGraphic() ); break;
272 aBool
.SetValue( SwViewOption::IsFieldShadings() ); break;
273 case FN_VIEW_FIELDNAME
:
274 aBool
.SetValue( pOpt
->IsFldName() ); break;
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;
283 aBool
.SetValue( pOpt
->IsPostIts());
284 if (!GetPostItMgr()->HasNotes())
286 aBool
.SetWhich( nWhich
);
288 rSet
.DisableItem(nWhich
);
293 case FN_VIEW_HIDDEN_PARA
:
294 aBool
.SetValue( pOpt
->IsShowHiddenPara()); break;
295 case SID_GRID_VISIBLE
:
296 aBool
.SetValue( pOpt
->IsGridVisible() ); break;
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;
304 aBool
.SetValue( 0 != StatVRuler() ); break;
306 if( pOpt
->getBrowseMode() )
308 rSet
.DisableItem(nWhich
);
312 aBool
.SetValue( IsHScrollbarVisible() ); break;
314 aBool
.SetValue( IsVScrollbarVisible() ); break;
315 case SID_AUTOSPELL_CHECK
:
316 aBool
.SetValue( pOpt
->IsOnlineSpell() );
318 case FN_SHADOWCURSOR
:
319 if (pIDSA
== 0 || pOpt
->getBrowseMode() )
321 rSet
.DisableItem( nWhich
);
325 aBool
.SetValue( pOpt
->IsShadowCursor() );
332 aBool
.SetWhich( nWhich
);
335 nWhich
= aIter
.NextWhich();
339 /*--------------------------------------------------------------------
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() );
366 case FN_VIEW_GRAPHIC
:
368 if( STATE_TOGGLE
== eState
)
369 bFlag
= !pOpt
->IsGraphic();
370 pOpt
->SetGraphic( bFlag
);
374 if( STATE_TOGGLE
== eState
)
375 bFlag
= !SwViewOption::IsFieldShadings() ;
376 SwViewOption::SetAppearanceFlag(VIEWOPT_FIELD_SHADINGS
, bFlag
, sal_True
);
380 if( STATE_TOGGLE
== eState
)
381 bFlag
= !SwViewOption::IsDocBoundaries();
382 SwViewOption::SetAppearanceFlag(VIEWOPT_DOC_BOUNDARIES
, bFlag
, sal_True
);
385 case SID_GRID_VISIBLE
:
386 if( STATE_TOGGLE
== eState
)
387 bFlag
= !pOpt
->IsGridVisible();
389 pOpt
->SetGridVisible( bFlag
);
393 if( STATE_TOGGLE
== eState
)
394 bFlag
= !pOpt
->IsSnap();
396 pOpt
->SetSnap( bFlag
);
399 case SID_HELPLINES_MOVE
:
400 if( STATE_TOGGLE
== eState
)
401 bFlag
= !pOpt
->IsCrossHair();
403 pOpt
->SetCrossHair( bFlag
);
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
)
412 bBrowseModeChanged
= bFlag
!= pOpt
->getBrowseMode();
413 // Disable "multiple layout"
414 GetDocShell()->ToggleBrowserMode( bFlag
, this );
416 pOpt
->setBrowseMode( bFlag
);
420 if ( STATE_TOGGLE
== eState
)
421 bFlag
= !pOpt
->IsPostIts();
423 GetPostItMgr()->SetLayout();
424 pOpt
->SetPostIts( bFlag
);
425 if (pOpt
->IsPostIts())
426 GetPostItMgr()->CheckMetaText();
429 case FN_VIEW_HIDDEN_PARA
:
430 if ( STATE_TOGGLE
== eState
)
431 bFlag
= !pOpt
->IsShowHiddenPara();
433 pOpt
->SetShowHiddenPara( bFlag
);
436 case FN_VIEW_SMOOTH_SCROLL
:
438 if ( STATE_TOGGLE
== eState
)
439 bFlag
= !pOpt
->IsSmoothScroll();
441 pOpt
->SetSmoothScroll( bFlag
);
446 if( STATE_TOGGLE
== eState
)
447 bFlag
= !pOpt
->IsViewVRuler();
449 pOpt
->SetViewVRuler( bFlag
);
453 if( STATE_TOGGLE
== eState
)
454 bFlag
= !pOpt
->IsViewVScrollBar();
456 pOpt
->SetViewVScrollBar( bFlag
);
460 if( STATE_TOGGLE
== eState
)
461 bFlag
= !pOpt
->IsViewHScrollBar();
463 pOpt
->SetViewHScrollBar( bFlag
);
466 if( STATE_TOGGLE
== eState
)
467 bFlag
= !pOpt
->IsViewAnyRuler();
469 pOpt
->SetViewAnyRuler( bFlag
);
472 case FN_VIEW_TABLEGRID
:
473 if( STATE_TOGGLE
== eState
)
474 bFlag
= !SwViewOption::IsTableBoundaries();
475 SwViewOption::SetAppearanceFlag(VIEWOPT_TABLE_BOUNDARIES
, bFlag
, sal_True
);
478 case FN_VIEW_FIELDNAME
:
479 if( STATE_TOGGLE
== eState
)
480 bFlag
= !pOpt
->IsFldName() ;
482 pOpt
->SetFldName( bFlag
);
485 if( STATE_TOGGLE
== eState
)
486 bFlag
= !lcl_IsViewMarks(*pOpt
) ;
488 lcl_SetViewMarks( *pOpt
, bFlag
);
490 case FN_VIEW_META_CHARS
:
491 if( STATE_TOGGLE
== eState
)
492 bFlag
= !pOpt
->IsViewMetaChars();
494 lcl_SetViewMetaChars( *pOpt
, bFlag
);
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
);
506 aCfg
.SetProperty( aPropName
, aVal
);
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...
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
);
527 case FN_SHADOWCURSOR
:
528 if( STATE_TOGGLE
== eState
)
529 bFlag
= bSet
= !pOpt
->IsShadowCursor();
531 pOpt
->SetShadowCursor(bSet
);
535 OSL_FAIL("wrong request method");
539 // UserPrefs setzen Request als bearbeitet kennzeichnen
540 sal_Bool bWebView
= 0 != dynamic_cast<const SwWebView
*>(this);
541 SwWrtShell
&rSh
= GetWrtShell();
543 SwModule
* pModule
= SW_MOD();
544 if( !(*rSh
.GetViewOptions() == *pOpt
))
546 rSh
.ApplyViewOptions( *pOpt
);
547 if( bBrowseModeChanged
)
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.
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
);
577 Invalidate(rReq
.GetSlot());
579 rReq
.AppendItem(SfxBoolItem(nSlot
, (sal_Bool
)bFlag
));
583 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */