merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / uiview / view0.cxx
blobd0055886038ac07b25137e3f8ce187dc1db56c08
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: view0.cxx,v $
10 * $Revision: 1.29 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #include "hintids.hxx"
37 #include <vcl/graph.hxx>
38 #include <svx/galbrws.hxx>
39 #include <svx/srchitem.hxx>
40 #include <SwSpellDialogChildWindow.hxx>
41 #include <svtools/eitem.hxx>
42 #include <svtools/linguprops.hxx>
43 #include <svtools/lingucfg.hxx>
44 #include <viewopt.hxx>
45 #include <globals.h>
46 #include <sfx2/app.hxx>
47 #include <sfx2/request.hxx>
48 #include <svtools/whiter.hxx>
49 #include <svx/srchdlg.hxx>
50 #include <sfx2/templdlg.hxx>
51 #include <uivwimp.hxx>
52 #include <avmedia/mediaplayer.hxx>
53 #include <swmodule.hxx>
55 #include <sfx2/objface.hxx>
56 #include <navipi.hxx>
57 #include <wrtsh.hxx>
58 #include "doc.hxx"
59 #include "view.hxx"
60 #include "basesh.hxx"
61 #include "docsh.hxx"
62 #include "globals.hrc"
63 #include "cmdid.h" // FN_ ...
64 #include "globdoc.hxx"
65 #include "wview.hxx"
66 #include "shells.hrc"
68 #define OLEObjects
69 #define SwView
70 #define SearchAttributes
71 #define ReplaceAttributes
72 #define SearchSettings
73 #define _ExecSearch ExecSearch
74 #define _StateSearch StateSearch
75 #define Frames
76 #define Graphics
77 #define Tables
78 #define Controls
79 #define GlobalContents
80 #define Text
81 #define Frame
82 #define Graphic
83 #define Object
84 #define Draw
85 #define TextDrawText
86 #define TextInTable
87 #define ListInText
88 #define ListInTable
89 #define WebTextInTable
90 #define WebListInText
91 #define WebListInTable
92 #define TextPage
93 #include <sfx2/msg.hxx>
94 #include <svx/svxslots.hxx>
95 #include "swslots.hxx"
96 #include <PostItMgr.hxx>
99 using namespace ::com::sun::star;
100 using ::rtl::OUString;
102 #include <svtools/moduleoptions.hxx>
104 #include <IDocumentSettingAccess.hxx>
106 #include <unomid.h>
109 SFX_IMPL_VIEWFACTORY(SwView, SW_RES(STR_NONAME))
111 if ( SvtModuleOptions().IsWriter() )
113 SFX_VIEW_REGISTRATION(SwDocShell);
114 SFX_VIEW_REGISTRATION(SwGlobalDocShell);
118 SFX_IMPL_INTERFACE( SwView, SfxViewShell, SW_RES(RID_TOOLS_TOOLBOX) )
120 SFX_CHILDWINDOW_CONTEXT_REGISTRATION(SID_NAVIGATOR);
121 SFX_CHILDWINDOW_REGISTRATION(SfxTemplateDialogWrapper::GetChildWindowId());
122 SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
123 SFX_CHILDWINDOW_REGISTRATION(SwSpellDialogChildWindow::GetChildWindowId());
124 SFX_CHILDWINDOW_REGISTRATION(FN_REDLINE_ACCEPT);
125 SFX_CHILDWINDOW_REGISTRATION(SID_HYPERLINK_DIALOG);
126 SFX_CHILDWINDOW_REGISTRATION(GalleryChildWindow::GetChildWindowId());
127 SFX_CHILDWINDOW_REGISTRATION(::avmedia::MediaPlayer::GetChildWindowId());
128 SFX_CHILDWINDOW_REGISTRATION(FN_INSERT_FIELD_DATA_ONLY);
129 SFX_FEATURED_CHILDWINDOW_REGISTRATION(FN_SYNC_LABELS, CHILDWIN_LABEL );
130 SFX_FEATURED_CHILDWINDOW_REGISTRATION(FN_MAILMERGE_CHILDWINDOW, CHILDWIN_MAILMERGE);
131 // SFX_CHILDWINDOW_REGISTRATION(FN_MAILMERGE_SENDMAIL_CHILDWINDOW);
132 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS|
133 SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
134 SW_RES(RID_TOOLS_TOOLBOX) );
137 TYPEINIT1(SwView,SfxViewShell)
139 /*-----------------13.12.97 11:06-------------------
141 --------------------------------------------------*/
142 ShellModes SwView::GetShellMode()
144 return pViewImpl->GetShellMode();
147 /*-----------------13.12.97 11:28-------------------
149 --------------------------------------------------*/
150 view::XSelectionSupplier* SwView::GetUNOObject()
152 return pViewImpl->GetUNOObject();
154 /* -----------------------------06.05.2002 13:18------------------------------
156 ---------------------------------------------------------------------------*/
157 void SwView::ApplyAccessiblityOptions(SvtAccessibilityOptions& rAccessibilityOptions)
159 pWrtShell->ApplyAccessiblityOptions(rAccessibilityOptions);
160 //to enable the right state of the selection cursor in readonly documents
161 if(GetDocShell()->IsReadOnly())
162 pWrtShell->ShowCrsr();
165 /*-- 26.05.2004 09:14:25---------------------------------------------------
167 -----------------------------------------------------------------------*/
168 void SwView::SetMailMergeConfigItem(SwMailMergeConfigItem* pConfigItem,
169 sal_uInt16 nRestart, sal_Bool bIsSource)
171 pViewImpl->SetMailMergeConfigItem(pConfigItem, nRestart, bIsSource);
172 UIFeatureChanged();
174 /*-- 26.05.2004 09:14:25---------------------------------------------------
176 -----------------------------------------------------------------------*/
177 SwMailMergeConfigItem* SwView::GetMailMergeConfigItem()
179 return pViewImpl->GetMailMergeConfigItem();
181 /*-- 26.05.2004 09:14:25---------------------------------------------------
183 -----------------------------------------------------------------------*/
184 sal_uInt16 SwView::GetMailMergeRestartPage() const
186 return pViewImpl->GetMailMergeRestartPage();
188 /*-- 03.09.2004 11:56:33---------------------------------------------------
190 -----------------------------------------------------------------------*/
191 sal_Bool SwView::IsMailMergeSourceView() const
193 return pViewImpl->IsMailMergeSourceView();
195 /*-- 12.04.2006 11:51:40---------------------------------------------------
197 -----------------------------------------------------------------------*/
198 sal_Bool lcl_IsViewMarks( const SwViewOption& rVOpt )
200 return rVOpt.IsHardBlank() &&
201 rVOpt.IsSoftHyph() &&
202 SwViewOption::IsFieldShadings();
204 void lcl_SetViewMarks(SwViewOption& rVOpt, sal_Bool bOn )
206 rVOpt.SetHardBlank(bOn);
207 rVOpt.SetSoftHyph(bOn);
208 SwViewOption::SetAppearanceFlag(
209 VIEWOPT_FIELD_SHADINGS, bOn, TRUE);
212 void lcl_SetViewMetaChars( SwViewOption& rVOpt, sal_Bool bOn)
214 rVOpt.SetViewMetaChars( bOn );
215 if(bOn && !(rVOpt.IsParagraph() ||
216 rVOpt.IsTab() ||
217 rVOpt.IsLineBreak() ||
218 rVOpt.IsShowHiddenChar() ||
219 rVOpt.IsBlank()))
221 rVOpt.SetParagraph(bOn);
222 rVOpt.SetTab(bOn);
223 rVOpt.SetLineBreak(bOn);
224 rVOpt.SetBlank(bOn);
225 rVOpt.SetShowHiddenChar(bOn);
229 /*--------------------------------------------------------------------
230 State of view options
231 --------------------------------------------------------------------*/
232 void SwView::StateViewOptions(SfxItemSet &rSet)
234 SfxWhichIter aIter(rSet);
235 sal_uInt16 nWhich = aIter.FirstWhich();
236 SfxBoolItem aBool;
237 const SwViewOption* pOpt = GetWrtShell().GetViewOptions();
238 const IDocumentSettingAccess* pIDSA = GetDocShell()->getIDocumentSettingAccess();
240 while(nWhich)
242 sal_Bool bReadonly = GetDocShell()->IsReadOnly();
243 sal_Bool bBrowse = pIDSA ? pIDSA->get( IDocumentSettingAccess::BROWSE_MODE ) : sal_False;
244 if ( bReadonly && nWhich != FN_VIEW_GRAPHIC )
246 rSet.DisableItem(nWhich);
247 nWhich = 0;
249 switch(nWhich)
251 case FN_RULER:
253 if(!pOpt->IsViewHRuler(TRUE) && !pOpt->IsViewVRuler(TRUE))
255 rSet.DisableItem(nWhich);
256 nWhich = 0;
258 else
259 aBool.SetValue( pOpt->IsViewAnyRuler());
261 break;
262 case FN_VIEW_BOUNDS:
263 aBool.SetValue( SwViewOption::IsDocBoundaries()); break;
264 case FN_VIEW_GRAPHIC:
265 aBool.SetValue( !pOpt->IsGraphic() ); break;
266 case FN_VIEW_FIELDS:
267 aBool.SetValue( SwViewOption::IsFieldShadings() ); break;
268 case FN_VIEW_FIELDNAME:
269 aBool.SetValue( pOpt->IsFldName() ); break;
270 case FN_VIEW_MARKS:
271 aBool.SetValue( lcl_IsViewMarks(*pOpt) ); break;
272 case FN_VIEW_META_CHARS:
273 aBool.SetValue( pOpt->IsViewMetaChars() ); break;
274 case FN_VIEW_TABLEGRID:
275 aBool.SetValue( SwViewOption::IsTableBoundaries() ); break;
276 case FN_VIEW_NOTES:
278 aBool.SetValue( pOpt->IsPostIts());
279 if (!GetPostItMgr()->HasNotes())
281 aBool.SetWhich( nWhich );
282 rSet.Put( aBool );
283 rSet.DisableItem(nWhich);
284 nWhich = 0;
286 break;
288 case FN_VIEW_HIDDEN_PARA:
289 aBool.SetValue( pOpt->IsShowHiddenPara()); break;
290 case SID_GRID_VISIBLE:
291 aBool.SetValue( pOpt->IsGridVisible() ); break;
292 case SID_GRID_USE:
293 aBool.SetValue( pOpt->IsSnap() ); break;
294 case SID_HELPLINES_MOVE:
295 aBool.SetValue( pOpt->IsCrossHair() ); break;
296 case FN_VIEW_SMOOTH_SCROLL:
297 aBool.SetValue( pOpt->IsSmoothScroll()); break;
298 case FN_VLINEAL:
299 aBool.SetValue( 0 != StatVLineal() ); break;
300 case FN_HSCROLLBAR:
301 if(bBrowse)
303 rSet.DisableItem(nWhich);
304 nWhich = 0;
306 else
307 aBool.SetValue( IsHScrollbarVisible() ); break;
308 case FN_VSCROLLBAR:
309 aBool.SetValue( IsVScrollbarVisible() ); break;
310 case SID_AUTOSPELL_CHECK:
311 aBool.SetValue( pOpt->IsOnlineSpell() );
312 break;
313 case FN_SHADOWCURSOR:
314 if (pIDSA == 0 || pIDSA->get( IDocumentSettingAccess::BROWSE_MODE ))
316 rSet.DisableItem( nWhich );
317 nWhich = 0;
319 else
320 aBool.SetValue( pOpt->IsShadowCursor() );
321 break;
325 if( nWhich )
327 aBool.SetWhich( nWhich );
328 rSet.Put( aBool );
330 nWhich = aIter.NextWhich();
334 /*--------------------------------------------------------------------
335 execute view options
336 --------------------------------------------------------------------*/
337 void SwView::ExecViewOptions(SfxRequest &rReq)
339 SwViewOption* pOpt = new SwViewOption( *GetWrtShell().GetViewOptions() );
340 sal_Bool bModified = GetWrtShell().IsModified();
342 int eState = STATE_TOGGLE;
343 sal_Bool bSet = sal_False;
345 const SfxItemSet *pArgs = rReq.GetArgs();
346 sal_uInt16 nSlot = rReq.GetSlot();
347 const SfxPoolItem* pAttr=NULL;
349 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nSlot , sal_False, &pAttr ))
351 bSet = ((SfxBoolItem*)pAttr)->GetValue();
352 eState = bSet ? STATE_ON : STATE_OFF;
355 BOOL bFlag = STATE_ON == eState;
356 uno::Reference< beans::XPropertySet > xLngProp( ::GetLinguPropertySet() );
358 switch ( nSlot )
360 case FN_VIEW_GRAPHIC:
362 if( STATE_TOGGLE == eState )
363 bFlag = !pOpt->IsGraphic();
364 pOpt->SetGraphic( bFlag );
365 break;
367 case FN_VIEW_FIELDS:
368 if( STATE_TOGGLE == eState )
369 bFlag = !SwViewOption::IsFieldShadings() ;
370 SwViewOption::SetAppearanceFlag(VIEWOPT_FIELD_SHADINGS, bFlag, TRUE );
371 break;
373 case FN_VIEW_BOUNDS:
374 if( STATE_TOGGLE == eState )
375 bFlag = !SwViewOption::IsDocBoundaries();
376 SwViewOption::SetAppearanceFlag(VIEWOPT_DOC_BOUNDARIES, bFlag, TRUE );
377 break;
379 case SID_GRID_VISIBLE:
380 if( STATE_TOGGLE == eState )
381 bFlag = !pOpt->IsGridVisible();
383 pOpt->SetGridVisible( bFlag );
384 break;
386 case SID_GRID_USE:
387 if( STATE_TOGGLE == eState )
388 bFlag = !pOpt->IsSnap();
390 pOpt->SetSnap( bFlag );
391 break;
393 case SID_HELPLINES_MOVE:
394 if( STATE_TOGGLE == eState )
395 bFlag = !pOpt->IsCrossHair();
397 pOpt->SetCrossHair( bFlag );
398 break;
400 case FN_VIEW_NOTES:
401 if ( STATE_TOGGLE == eState )
402 bFlag = !pOpt->IsPostIts();
404 GetPostItMgr()->SetLayout();
405 pOpt->SetPostIts( bFlag );
406 if (pOpt->IsPostIts())
407 GetPostItMgr()->CheckMetaText();
408 break;
410 case FN_VIEW_HIDDEN_PARA:
411 if ( STATE_TOGGLE == eState )
412 bFlag = !pOpt->IsShowHiddenPara();
414 pOpt->SetShowHiddenPara( bFlag );
415 break;
417 case FN_VIEW_SMOOTH_SCROLL:
419 if ( STATE_TOGGLE == eState )
420 bFlag = !pOpt->IsSmoothScroll();
422 pOpt->SetSmoothScroll( bFlag );
423 break;
426 case FN_VLINEAL:
427 if( STATE_TOGGLE == eState )
428 bFlag = !pOpt->IsViewVRuler();
430 pOpt->SetViewVRuler( bFlag );
431 break;
433 case FN_VSCROLLBAR:
434 if( STATE_TOGGLE == eState )
435 bFlag = !pOpt->IsViewVScrollBar();
437 pOpt->SetViewVScrollBar( bFlag );
438 break;
440 case FN_HSCROLLBAR:
441 if( STATE_TOGGLE == eState )
442 bFlag = !pOpt->IsViewHScrollBar();
444 pOpt->SetViewHScrollBar( bFlag );
445 break;
446 case FN_RULER:
447 if( STATE_TOGGLE == eState )
448 bFlag = !pOpt->IsViewAnyRuler();
450 pOpt->SetViewAnyRuler( bFlag );
451 break;
453 case FN_VIEW_TABLEGRID:
454 if( STATE_TOGGLE == eState )
455 bFlag = !SwViewOption::IsTableBoundaries();
456 SwViewOption::SetAppearanceFlag(VIEWOPT_TABLE_BOUNDARIES, bFlag, TRUE );
457 break;
459 case FN_VIEW_FIELDNAME:
460 if( STATE_TOGGLE == eState )
461 bFlag = !pOpt->IsFldName() ;
463 pOpt->SetFldName( bFlag );
464 break;
465 case FN_VIEW_MARKS:
466 if( STATE_TOGGLE == eState )
467 bFlag = !lcl_IsViewMarks(*pOpt) ;
469 lcl_SetViewMarks( *pOpt, bFlag );
470 break;
471 case FN_VIEW_META_CHARS:
472 if( STATE_TOGGLE == eState )
473 bFlag = !pOpt->IsViewMetaChars();
475 lcl_SetViewMetaChars( *pOpt, bFlag );
476 break;
477 case SID_AUTOSPELL_CHECK:
478 if( STATE_TOGGLE == eState )
479 bFlag = bSet = !pOpt->IsOnlineSpell();
481 pOpt->SetOnlineSpell(bSet);
483 uno::Any aVal( &bSet, ::getCppuBooleanType() );
484 String aPropName( C2S(UPN_IS_SPELL_AUTO) );
486 SvtLinguConfig aCfg;
487 aCfg.SetProperty( aPropName, aVal );
489 if (xLngProp.is())
490 xLngProp->setPropertyValue( aPropName, aVal );
492 // for the time being we do not have a specific option for grammarchecking.
493 // thus we'll use the one for spell checking...
494 if (bSet)
496 SwDocShell *pDocSh = GetDocShell();
497 SwDoc *pDoc = pDocSh? pDocSh->GetDoc() : NULL;
499 // right now we don't have view options for automatic grammar checking. Thus...
500 sal_Bool bIsAutoGrammar = sal_False;
501 aCfg.GetProperty( C2U( UPN_IS_GRAMMAR_AUTO ) ) >>= bIsAutoGrammar;
503 if (pDoc && bIsAutoGrammar)
504 StartGrammarChecking( *pDoc );
507 break;
508 case FN_SHADOWCURSOR:
509 if( STATE_TOGGLE == eState )
510 bFlag = bSet = !pOpt->IsShadowCursor();
512 pOpt->SetShadowCursor(bSet);
513 break;
515 default:
516 ASSERT(sal_False, Falsche Request-Methode);
517 return;
520 // UserPrefs setzen Request als bearbeitet kennzeichnen
521 sal_Bool bWebView = 0 != dynamic_cast<const SwWebView*>(this);
522 SwWrtShell &rSh = GetWrtShell();
523 rSh.StartAction();
524 SwModule* pModule = SW_MOD();
525 if( !(*rSh.GetViewOptions() == *pOpt ))
527 rSh.ApplyViewOptions( *pOpt );
529 //Die UsrPref muessen als Modified gekennzeichnet werden.
530 //call for initialization
531 pModule->GetUsrPref(bWebView);
532 pModule->CheckSpellChanges( pOpt->IsOnlineSpell(), sal_False, sal_False, sal_False );
534 //OS: Modified wieder zuruecksetzen, weil Ansicht/Felder
535 // das Doc modified setzt.
536 if( !bModified )
537 rSh.ResetModified();
539 pModule->ApplyUsrPref( *pOpt, this, bWebView ? VIEWOPT_DEST_WEB : VIEWOPT_DEST_TEXT );
541 //mod #i6193# let postits know about new spellcheck setting
542 if ( nSlot == SID_AUTOSPELL_CHECK )
543 GetPostItMgr()->SetSpellChecking();
545 const BOOL bLockedView = rSh.IsViewLocked();
546 rSh.LockView( TRUE ); //lock visible section
547 GetWrtShell().EndAction();
548 rSh.LockView( bLockedView );
550 delete pOpt;
551 Invalidate(rReq.GetSlot());
552 if(!pArgs)
553 rReq.AppendItem(SfxBoolItem(nSlot, (BOOL)bFlag));
554 rReq.Done();