xref: /AOO41X/main/sw/source/ui/uiview/view2.cxx (revision ff0525f24f03981d56b7579b645949f111420994)
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 #include <com/sun/star/util/SearchOptions.hpp>
28 #include <com/sun/star/util/SearchFlags.hpp>
29 #include <com/sun/star/i18n/TransliterationModules.hpp>
30 #include <svtools/filter.hxx>
31 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
32 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
33 #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
34 
35 #define _SVSTDARR_STRINGSSORTDTOR
36 #include <svl/svstdarr.hxx>
37 #include <svl/aeitem.hxx>
38 
39 #include <SwStyleNameMapper.hxx>
40 #include <docary.hxx>
41 #include <hintids.hxx>
42 #include <SwRewriter.hxx>
43 #include <numrule.hxx>
44 #include <swundo.hxx>
45 #include <caption.hxx>
46 #include <svl/PasswordHelper.hxx>
47 #include <svl/urihelper.hxx>
48 #include <sfx2/passwd.hxx>
49 #include <sfx2/sfxdlg.hxx>
50 #include <sfx2/filedlghelper.hxx>
51 #include <sfx2/sfxhelp.hxx>
52 #include <editeng/langitem.hxx>
53 #include <svx/viewlayoutitem.hxx>
54 #include <svx/zoomslideritem.hxx>
55 #include <svtools/xwindowitem.hxx>
56 #include <svx/htmlmode.hxx>
57 #include <vcl/svapp.hxx>
58 #include <vcl/wrkwin.hxx>
59 #include <sfx2/app.hxx>
60 #include <sfx2/request.hxx>
61 #include <sfx2/bindings.hxx>
62 #include <editeng/lrspitem.hxx>
63 #include <svtools/txtcmp.hxx>
64 #include "editeng/unolingu.hxx"
65 #include <vcl/msgbox.hxx>
66 #include <editeng/tstpitem.hxx>
67 #include <sfx2/event.hxx>
68 #include <sfx2/docfile.hxx>
69 #include <sfx2/docfilt.hxx>
70 #include <sfx2/fcontnr.hxx>
71 #include <editeng/sizeitem.hxx>
72 #include <sfx2/dispatch.hxx>
73 #include <svl/whiter.hxx>
74 #include <svl/ptitem.hxx>
75 #include <sfx2/linkmgr.hxx>
76 #include <tools/errinf.hxx>
77 #include <tools/urlobj.hxx>
78 #include <svx/svdview.hxx>
79 #include <swtypes.hxx>
80 #include <swwait.hxx>
81 #include <redlndlg.hxx>
82 #include <view.hxx>
83 #include <uivwimp.hxx>
84 #include <docsh.hxx>
85 #include <doc.hxx>
86 #include <IDocumentUndoRedo.hxx>
87 #include <wrtsh.hxx>
88 #include <viewopt.hxx>
89 #include <basesh.hxx>
90 #include <swmodule.hxx>
91 #include <uitool.hxx>
92 #include <shellio.hxx>
93 #include <fmtinfmt.hxx>
94 #include <mdiexp.hxx>
95 #include <drawbase.hxx>
96 #include <frmmgr.hxx>
97 #include <pagedesc.hxx>
98 #include <section.hxx>
99 #include <usrpref.hxx>
100 #include <IMark.hxx>
101 #include <navipi.hxx>
102 #include <tox.hxx>
103 #include <workctrl.hxx>
104 #include <scroll.hxx>
105 #include <edtwin.hxx>
106 #include <wview.hxx>
107 #include <textsh.hxx>
108 #include <tabsh.hxx>
109 #include <listsh.hxx>
110 #include <cmdid.h>
111 #include <comcore.hrc>
112 #include <poolfmt.hrc>
113 #include <statstr.hrc>
114 #include <swerror.h>
115 #include <globals.hrc>
116 #include <shells.hrc>
117 #include <web.hrc>
118 #include <view.hrc>
119 #include <app.hrc>
120 #include <fmtclds.hxx>
121 #include <helpid.h>
122 #include <svtools/templdlg.hxx>
123 #include <dbconfig.hxx>
124 #include <dbmgr.hxx>
125 
126 #include <PostItMgr.hxx>
127 
128 #include <ndtxt.hxx> //#outline level,added by zhaojianwei
129 
130 #include <comphelper/processfactory.hxx>
131 
132 #include <svx/svxdlg.hxx>
133 #include <svx/dialogs.hrc>
134 #include "swabstdlg.hxx"
135 #include "globals.hrc"
136 #include <envelp.hrc>
137 #include <fmthdft.hxx>
138 #include <svx/ofaitem.hxx>
139 #include <unomid.h>
140 
141 const char __FAR_DATA sStatusDelim[] = " : ";
142 const char __FAR_DATA sStatusComma[] = " , ";//#outlinelevel, define a Variable for "," add by zhaojianwei
143 
144 using ::rtl::OUString;
145 using namespace sfx2;
146 using namespace ::com::sun::star;
147 using namespace ::com::sun::star::i18n;
148 using namespace ::com::sun::star::util;
149 using namespace ::com::sun::star::uno;
150 using namespace ::com::sun::star::lang;
151 using namespace ::com::sun::star::scanner;
152 using namespace ::com::sun::star::i18n;
153 using namespace ::com::sun::star::beans;
154 using namespace ::com::sun::star::container;
155 using namespace ::com::sun::star::ui::dialogs;
156 
157 
158 static void lcl_SetAllTextToDefaultLanguage( SwWrtShell &rWrtSh, sal_uInt16 nWhichId )
159 {
160     if (nWhichId == RES_CHRATR_LANGUAGE ||
161         nWhichId == RES_CHRATR_CJK_LANGUAGE ||
162         nWhichId == RES_CHRATR_CTL_LANGUAGE)
163     {
164         rWrtSh.StartAction();
165         rWrtSh.LockView( sal_True );
166         rWrtSh.Push();
167 
168         // prepare to apply new language to all text in document
169         rWrtSh.SelAll();
170         rWrtSh.ExtendedSelectAll();
171 
172         // set language attribute to default for all text
173         SvUShortsSort aAttribs;
174         aAttribs.Insert( nWhichId );
175         rWrtSh.ResetAttr( &aAttribs );
176 
177         rWrtSh.Pop( sal_False );
178         rWrtSh.LockView( sal_False );
179         rWrtSh.EndAction();
180     }
181 }
182 
183 /*---------------------------------------------------------------------------
184     Beschreibung:   String fuer die Seitenanzeige in der Statusbar basteln.
185  ----------------------------------------------------------------------------*/
186 
187 String SwView::GetPageStr( sal_uInt16 nPg, sal_uInt16 nLogPg,
188                             const String& rDisplay )
189 {
190     String aStr( aPageStr );
191     if( rDisplay.Len() )
192         aStr += rDisplay;
193     else
194         aStr += String::CreateFromInt32(nLogPg);
195 
196     if( nLogPg && nLogPg != nPg )
197     {
198         aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM("   "));
199         aStr += String::CreateFromInt32(nPg);
200     }
201     aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM(" / "));
202     aStr += String::CreateFromInt32( GetWrtShell().GetPageCnt() );
203 
204     return aStr;
205 }
206 
207 
208 int SwView::InsertGraphic( const String &rPath, const String &rFilter,
209                                 sal_Bool bLink, GraphicFilter *pFlt,
210                                 Graphic* pPreviewGrf, sal_Bool bRule )
211 {
212     SwWait aWait( *GetDocShell(), sal_True );
213 
214     Graphic aGrf;
215     int nRes = GRFILTER_OK;
216     if ( pPreviewGrf )
217         aGrf = *pPreviewGrf;
218     else
219     {
220         if( !pFlt )
221             pFlt = GraphicFilter::GetGraphicFilter();
222         nRes = GraphicFilter::LoadGraphic( rPath, rFilter, aGrf, pFlt /*, nFilter*/ );
223     }
224 
225     if( GRFILTER_OK == nRes )
226     {
227         SwFlyFrmAttrMgr aFrmMgr( sal_True, GetWrtShellPtr(), FRMMGR_TYPE_GRF );
228 
229         SwWrtShell &rSh = GetWrtShell();
230         rSh.StartAction();
231         if( bLink )
232         {
233             SwDocShell* pDocSh = GetDocShell();
234             INetURLObject aTemp(
235                 pDocSh->HasName() ?
236                     pDocSh->GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) :
237                     rtl::OUString());
238 
239             String sURL = URIHelper::SmartRel2Abs(
240                 aTemp, rPath, URIHelper::GetMaybeFileHdl() );
241 
242             rSh.Insert( sURL,
243                         rFilter, aGrf, &aFrmMgr, bRule );
244         }
245         else
246             rSh.Insert( aEmptyStr, aEmptyStr, aGrf, &aFrmMgr );
247         // nach dem EndAction ist es zu spaet, weil die Shell dann schon zerstoert sein kann
248         rSh.EndAction();
249     }
250     return nRes;
251 }
252 
253 
254 sal_Bool SwView::InsertGraphicDlg( SfxRequest& rReq )
255 {
256 #ifndef ENABLE_PROP_WITHOUTLINK
257 #define ENABLE_PROP_WITHOUTLINK 0x08
258 #endif
259 
260     sal_Bool bReturn = sal_False;
261     SwDocShell* pDocShell = GetDocShell();
262     sal_uInt16 nHtmlMode = ::GetHtmlMode(pDocShell);
263     // im HTML-Mode nur verknuepft einfuegen
264     FileDialogHelper* pFileDlg = new FileDialogHelper( SFXWB_GRAPHIC | SFXWB_SHOWSTYLES );
265     pFileDlg->SetTitle(SW_RESSTR(STR_INSERT_GRAPHIC ));
266     pFileDlg->SetContext( FileDialogHelper::SW_INSERT_GRAPHIC );
267     uno::Reference < XFilePicker > xFP = pFileDlg->GetFilePicker();
268     uno::Reference < XFilePickerControlAccess > xCtrlAcc(xFP, UNO_QUERY);
269     if(nHtmlMode & HTMLMODE_ON)
270     {
271         sal_Bool bTrue = sal_True;
272         Any aVal(&bTrue, ::getBooleanCppuType());
273         xCtrlAcc->setValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, aVal);
274         xCtrlAcc->enableControl( ExtendedFilePickerElementIds::CHECKBOX_LINK, sal_False);
275     }
276 
277     SvStringsSortDtor aFormats;
278     SwDoc* pDoc = pDocShell->GetDoc();
279     const sal_uInt16 nArrLen = pDoc->GetFrmFmts()->Count();
280     sal_uInt16 i;
281     for( i = 0; i < nArrLen; i++ )
282     {
283         SwFrmFmt* pFmt = (*pDoc->GetFrmFmts())[ i ];
284         if(pFmt->IsDefault() || pFmt->IsAuto())
285             continue;
286         String *pFormat = new String(pFmt->GetName());
287         aFormats.Insert(pFormat);
288     }
289 
290     // pool formats
291     //
292     const SvStringsDtor& rFrmPoolArr = SwStyleNameMapper::GetFrmFmtUINameArray();
293     for( i = 0; i < rFrmPoolArr.Count(); i++ )
294     {
295         String *pFormat = new String(*rFrmPoolArr[i]);
296         if (!aFormats.Insert(pFormat))
297             delete pFormat;
298     }
299 
300     Sequence<OUString> aListBoxEntries(aFormats.Count());
301     OUString* pEntries = aListBoxEntries.getArray();
302     sal_Int16 nSelect = 0;
303     String sGraphicFormat = SW_RESSTR(STR_POOLFRM_GRAPHIC);
304     for(i = 0; i < aFormats.Count(); ++i)
305     {
306         pEntries[i] = *aFormats[i];
307         if(pEntries[i].equals(sGraphicFormat))
308             nSelect = i;
309     }
310     try
311     {
312         Any aTemplates(&aListBoxEntries, ::getCppuType(&aListBoxEntries));
313 
314         xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE,
315             ListboxControlActions::ADD_ITEMS , aTemplates );
316 
317         Any aSelectPos(&nSelect, ::getCppuType(&nSelect));
318         xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE,
319             ListboxControlActions::SET_SELECT_ITEM, aSelectPos );
320     }
321     catch(Exception& )
322     {
323         DBG_ERROR("control acces failed");
324     }
325 
326     SFX_REQUEST_ARG( rReq, pName, SfxStringItem, SID_INSERT_GRAPHIC , sal_False );
327     sal_Bool bShowError = !pName;
328     if( pName || ERRCODE_NONE == pFileDlg->Execute() )
329     {
330 
331         String aFileName, aFilterName;
332         if ( pName )
333         {
334             aFileName = pName->GetValue();
335             SFX_REQUEST_ARG( rReq, pFilter, SfxStringItem, FN_PARAM_FILTER , sal_False );
336             if ( pFilter )
337                 aFilterName = pFilter->GetValue();
338         }
339         else
340         {
341             aFileName = pFileDlg->GetPath();
342             aFilterName = pFileDlg->GetCurrentFilter();
343             rReq.AppendItem( SfxStringItem( SID_INSERT_GRAPHIC, aFileName ) );
344             rReq.AppendItem( SfxStringItem( FN_PARAM_FILTER, aFilterName ) );
345 
346             sal_Bool bAsLink = sal_False;
347             if(nHtmlMode & HTMLMODE_ON)
348                 bAsLink = sal_True;
349             else
350             {
351                 try
352                 {
353                     Any aVal = xCtrlAcc->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0);
354                     DBG_ASSERT(aVal.hasValue(), "Value CBX_INSERT_AS_LINK not found");
355                     bAsLink = aVal.hasValue() ? *(sal_Bool*) aVal.getValue() : sal_True;
356                     Any aTemplateValue = xCtrlAcc->getValue(
357                         ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE,
358                         ListboxControlActions::GET_SELECTED_ITEM );
359                     OUString sTmpl;
360                     aTemplateValue >>= sTmpl;
361                     rReq.AppendItem( SfxStringItem( FN_PARAM_2, sTmpl) );
362                 }
363                 catch(Exception& )
364                 {
365                     DBG_ERROR("control acces failed");
366                 }
367             }
368             rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bAsLink ) );
369         }
370 
371         SFX_REQUEST_ARG( rReq, pAsLink, SfxBoolItem, FN_PARAM_1 , sal_False );
372         SFX_REQUEST_ARG( rReq, pStyle, SfxStringItem, FN_PARAM_2 , sal_False );
373 
374         sal_Bool bAsLink = sal_False;
375         if( nHtmlMode & HTMLMODE_ON )
376             bAsLink = sal_True;
377         else
378         {
379             if ( rReq.GetArgs() )
380             {
381                 if ( pAsLink )
382                     bAsLink = pAsLink->GetValue();
383                 if ( pStyle && pStyle->GetValue().Len() )
384                     sGraphicFormat = pStyle->GetValue();
385             }
386             else
387             {
388                 Any aVal = xCtrlAcc->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0);
389                 DBG_ASSERT(aVal.hasValue(), "Value CBX_INSERT_AS_LINK not found");
390                 bAsLink = aVal.hasValue() ? *(sal_Bool*) aVal.getValue() : sal_True;
391                 Any aTemplateValue = xCtrlAcc->getValue(
392                     ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE,
393                     ListboxControlActions::GET_SELECTED_ITEM );
394                 OUString sTmpl;
395                 aTemplateValue >>= sTmpl;
396                 if( sTmpl.getLength() )
397                     sGraphicFormat = sTmpl;
398                 rReq.AppendItem( SfxStringItem( FN_PARAM_2, sGraphicFormat ) );
399                 rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bAsLink ) );
400             }
401         }
402 
403         SwWrtShell& rSh = GetWrtShell();
404         rSh.LockPaint();
405         rSh.StartAction();
406 
407         /// #111827#
408         SwRewriter aRewriter;
409         aRewriter.AddRule(UNDO_ARG1, String(SW_RES(STR_GRAPHIC_DEFNAME)));
410 
411         rSh.StartUndo(UNDO_INSERT, &aRewriter);
412 
413         int nError = InsertGraphic( aFileName, aFilterName, bAsLink, GraphicFilter::GetGraphicFilter() );
414 
415         // Format ist ungleich Current Filter, jetzt mit auto. detection
416         if( nError == GRFILTER_FORMATERROR )
417             nError = InsertGraphic( aFileName, aEmptyStr, bAsLink, GraphicFilter::GetGraphicFilter() );
418         if ( rSh.IsFrmSelected() )
419         {
420             SwFrmFmt* pFmt = pDoc->FindFrmFmtByName( sGraphicFormat );
421             if(!pFmt)
422                 pFmt = pDoc->MakeFrmFmt(sGraphicFormat,
423                                         pDocShell->GetDoc()->GetDfltFrmFmt(),
424                                         sal_True, sal_False);
425             rSh.SetFrmFmt( pFmt );
426         }
427 
428         RESOURCE_TYPE nResId = 0;
429         switch( nError )
430         {
431             case GRFILTER_OPENERROR:
432                 nResId = STR_GRFILTER_OPENERROR;
433                 break;
434             case GRFILTER_IOERROR:
435                 nResId = STR_GRFILTER_IOERROR;
436                 break;
437             case GRFILTER_FORMATERROR:
438                 nResId = STR_GRFILTER_FORMATERROR;
439                 break;
440             case GRFILTER_VERSIONERROR:
441                 nResId = STR_GRFILTER_VERSIONERROR;
442                 break;
443             case GRFILTER_FILTERERROR:
444                 nResId = STR_GRFILTER_FILTERERROR;
445                 break;
446             case GRFILTER_TOOBIG:
447                 nResId = STR_GRFILTER_TOOBIG;
448                 break;
449         }
450 
451         rSh.EndAction();
452         rSh.UnlockPaint();
453         if( nResId )
454         {
455             if( bShowError )
456             {
457                 InfoBox aInfoBox( GetWindow(), SW_RESSTR( nResId ));
458                 aInfoBox.Execute();
459             }
460             rReq.Ignore();
461         }
462         else
463         {
464             // set the specific graphic attrbutes to the graphic
465             bReturn = sal_True;
466             AutoCaption( GRAPHIC_CAP );
467             rReq.Done();
468         }
469 
470         rSh.EndUndo(); // due to possible change of Shell
471     }
472 
473     delete pFileDlg;
474 
475     return bReturn;
476 }
477 
478 
479 void __EXPORT SwView::Execute(SfxRequest &rReq)
480 {
481     sal_uInt16 nSlot = rReq.GetSlot();
482     const SfxItemSet* pArgs = rReq.GetArgs();
483     const SfxPoolItem* pItem;
484     sal_Bool bIgnore = sal_False;
485     switch( nSlot )
486     {
487         case SID_CREATE_SW_DRAWVIEW:
488             // --> OD 2005-08-08 #i52858# - method name changed
489             pWrtShell->getIDocumentDrawModelAccess()->GetOrCreateDrawModel();
490             // <--
491             break;
492 
493         case FN_LINE_NUMBERING_DLG:
494         {
495             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
496             DBG_ASSERT(pFact, "Dialogdiet fail!");
497             VclAbstractDialog* pDlg = pFact->CreateVclSwViewDialog( DLG_LINE_NUMBERING,    *this);
498             DBG_ASSERT(pDlg, "Dialogdiet fail!");
499             pDlg->Execute();
500             delete pDlg;
501             break;
502         }
503         case FN_EDIT_LINK_DLG:
504             EditLinkDlg();
505             break;
506         case FN_REFRESH_VIEW:
507             GetEditWin().Invalidate();
508             break;
509         case FN_PAGEUP:
510         case FN_PAGEUP_SEL:
511         case FN_PAGEDOWN:
512         case FN_PAGEDOWN_SEL:
513         {
514             Rectangle aVis( GetVisArea() );
515             SwEditWin& rTmpWin = GetEditWin();
516             if ( FN_PAGEUP == nSlot || FN_PAGEUP_SEL == nSlot )
517                 PageUpCrsr(FN_PAGEUP_SEL == nSlot);
518             else
519                 PageDownCrsr(FN_PAGEDOWN_SEL == nSlot);
520 
521             rReq.SetReturnValue(SfxBoolItem(nSlot,
522                                                 aVis != GetVisArea()));
523             //#i42732# - notify the edit window that from now on we do not use the input language
524             rTmpWin.SetUseInputLanguage( sal_False );
525         }
526         break;
527         case FN_REDLINE_ON:
528         {
529             if( pArgs &&
530                 SFX_ITEM_SET == pArgs->GetItemState(nSlot, sal_False, &pItem ))
531             {
532                 IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess();
533                 Sequence <sal_Int8> aPasswd = pIDRA->GetRedlinePassword();
534                 if( aPasswd.getLength() )
535                 {
536                     DBG_ASSERT( !((const SfxBoolItem*)pItem)->GetValue(), "SwView::Execute(): password set an redlining off doesn't match!" );
537                     // xmlsec05:    new password dialog
538                     Window* pParent;
539                     const SfxPoolItem* pParentItem;
540                     if( SFX_ITEM_SET == pArgs->GetItemState( SID_ATTR_XWINDOW, sal_False, &pParentItem ) )
541                         pParent = ( ( const XWindowItem* ) pParentItem )->GetWindowPtr();
542                     else
543                         pParent = &GetViewFrame()->GetWindow();
544                     SfxPasswordDialog aPasswdDlg( pParent );
545                     aPasswdDlg.SetMinLen( 1 );
546                     //#i69751# the result of Execute() can be ignored
547                     aPasswdDlg.Execute();
548                     String sNewPasswd( aPasswdDlg.GetPassword() );
549                     Sequence <sal_Int8> aNewPasswd = pIDRA->GetRedlinePassword();
550                     SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd );
551                     if(SvPasswordHelper::CompareHashPassword(aPasswd, sNewPasswd))
552                         pIDRA->SetRedlinePassword(Sequence <sal_Int8> ());
553                     else
554                     {   // xmlsec05: message box for wrong password
555                         break;
556                     }
557                 }
558 
559                 sal_uInt16 nOn = ((const SfxBoolItem*)pItem)->GetValue() ? nsRedlineMode_t::REDLINE_ON : 0;
560                 sal_uInt16 nMode = pWrtShell->GetRedlineMode();
561                 pWrtShell->SetRedlineModeAndCheckInsMode( (nMode & ~nsRedlineMode_t::REDLINE_ON) | nOn);
562             }
563         }
564         break;
565         case FN_REDLINE_PROTECT :
566         {
567             IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess();
568             Sequence <sal_Int8> aPasswd = pIDRA->GetRedlinePassword();
569             if( pArgs && SFX_ITEM_SET == pArgs->GetItemState(nSlot, sal_False, &pItem )
570                 && ((SfxBoolItem*)pItem)->GetValue() == ( aPasswd.getLength() != 0 ) )
571                 break;
572 
573             // xmlsec05:    new password dialog
574             //              message box for wrong password
575             Window* pParent;
576             const SfxPoolItem* pParentItem;
577             if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_ATTR_XWINDOW, sal_False, &pParentItem ) )
578                 pParent = ( ( const XWindowItem* ) pParentItem )->GetWindowPtr();
579             else
580                 pParent = &GetViewFrame()->GetWindow();
581             SfxPasswordDialog aPasswdDlg( pParent );
582             aPasswdDlg.SetMinLen( 1 );
583             if(!aPasswd.getLength())
584                 aPasswdDlg.ShowExtras(SHOWEXTRAS_CONFIRM);
585             if (aPasswdDlg.Execute())
586             {
587                 sal_uInt16 nOn = nsRedlineMode_t::REDLINE_ON;
588                 String sNewPasswd( aPasswdDlg.GetPassword() );
589                 Sequence <sal_Int8> aNewPasswd =
590                         pIDRA->GetRedlinePassword();
591                 SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd );
592                 if(!aPasswd.getLength())
593                 {
594                     pIDRA->SetRedlinePassword(aNewPasswd);
595                 }
596                 else if(SvPasswordHelper::CompareHashPassword(aPasswd, sNewPasswd))
597                 {
598                     pIDRA->SetRedlinePassword(Sequence <sal_Int8> ());
599                     nOn = 0;
600                 }
601                 sal_uInt16 nMode = pIDRA->GetRedlineMode();
602                 pWrtShell->SetRedlineModeAndCheckInsMode( (nMode & ~nsRedlineMode_t::REDLINE_ON) | nOn);
603                 rReq.AppendItem( SfxBoolItem( FN_REDLINE_PROTECT, ((nMode&nsRedlineMode_t::REDLINE_ON)==0) ) );
604             }
605             else
606                 bIgnore = sal_True;
607         }
608         break;
609         case FN_REDLINE_SHOW:
610 
611             if( pArgs &&
612                 SFX_ITEM_SET == pArgs->GetItemState(nSlot, sal_False, &pItem))
613             {
614                 sal_uInt16 nMode = ( ~(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE)
615                         & pWrtShell->GetRedlineMode() ) | nsRedlineMode_t::REDLINE_SHOW_INSERT;
616                 if( ((const SfxBoolItem*)pItem)->GetValue() )
617                     nMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;
618 
619                 pWrtShell->SetRedlineModeAndCheckInsMode( nMode );
620             }
621             break;
622         case FN_MAILMERGE_SENDMAIL_CHILDWINDOW:
623         case FN_REDLINE_ACCEPT:
624             GetViewFrame()->ToggleChildWindow(nSlot);
625         break;
626         case FN_REDLINE_ACCEPT_DIRECT:
627         case FN_REDLINE_REJECT_DIRECT:
628         {
629             SwContentAtPos aCntntAtPos( SwContentAtPos::SW_REDLINE );
630             Point aCrsrPos = pWrtShell->GetCrsrDocPos( sal_True );
631             if( pWrtShell->GetContentAtPos( aCrsrPos, aCntntAtPos ) )
632             {
633                 sal_uInt16 nCount = pWrtShell->GetRedlineCount();
634                 for( sal_uInt16 nRedline = 0; nRedline < nCount; ++nRedline )
635                 {
636                     const SwRedline& rRedline = pWrtShell->GetRedline( nRedline );
637                     if( *aCntntAtPos.aFnd.pRedl == rRedline )
638                     {
639                         if( FN_REDLINE_ACCEPT_DIRECT == nSlot )
640                             pWrtShell->AcceptRedline( nRedline );
641                         else
642                             pWrtShell->RejectRedline( nRedline );
643                         break;
644                     }
645                 }
646             }
647         }
648         break;
649         case SID_DOCUMENT_COMPARE:
650         case SID_DOCUMENT_MERGE:
651             {
652                 String sFileName, sFilterName;
653                 sal_Int16 nVersion = 0;
654                 bool bHasFileName = false;
655                 pViewImpl->SetParam( 0 );
656 
657                 if( pArgs )
658                 {
659                     if( SFX_ITEM_SET == pArgs->GetItemState( SID_FILE_NAME, sal_False, &pItem ))
660                         sFileName = ((const SfxStringItem*)pItem)->GetValue();
661                     bHasFileName = ( sFileName.Len() > 0 );
662 
663                     if( SFX_ITEM_SET == pArgs->GetItemState( SID_FILTER_NAME, sal_False, &pItem ))
664                         sFilterName = ((const SfxStringItem*)pItem)->GetValue();
665 
666                     if( SFX_ITEM_SET == pArgs->GetItemState( SID_VERSION, sal_False, &pItem ))
667                     {
668                         nVersion = ((const SfxInt16Item *)pItem)->GetValue();
669                         pViewImpl->SetParam( nVersion );
670                     }
671                 }
672 
673                 pViewImpl->InitRequest( rReq );
674                 long nFound = InsertDoc( nSlot, sFileName, sFilterName, nVersion );
675 
676                 if ( bHasFileName )
677                 {
678                     rReq.SetReturnValue( SfxInt32Item( nSlot, nFound ));
679 
680                     if (nFound > 0) // Redline-Browser anzeigen
681                     {
682                         SfxViewFrame* pVFrame = GetViewFrame();
683                         pVFrame->ShowChildWindow(FN_REDLINE_ACCEPT);
684 
685                         // RedlineDlg neu initialisieren
686                         sal_uInt16 nId = SwRedlineAcceptChild::GetChildWindowId();
687                         SwRedlineAcceptChild *pRed = (SwRedlineAcceptChild*)
688                                                 pVFrame->GetChildWindow(nId);
689                         if (pRed)
690                             pRed->ReInitDlg(GetDocShell());
691                     }
692                 }
693                 else
694                     bIgnore = sal_True;
695             }
696         break;
697         case FN_SYNC_LABELS:
698         case FN_MAILMERGE_CHILDWINDOW:
699             GetViewFrame()->ShowChildWindow(nSlot, sal_True);
700         break;
701         case FN_ESCAPE:
702         {
703             if ( pWrtShell->HasDrawView() && pWrtShell->GetDrawView()->IsDragObj() )
704             {
705                 pWrtShell->BreakDrag();
706                 pWrtShell->EnterSelFrmMode();
707             }
708             else if ( pWrtShell->IsDrawCreate() )
709             {
710                 GetDrawFuncPtr()->BreakCreate();
711                 AttrChangedNotify(pWrtShell); // ggf Shellwechsel...
712             }
713             else if ( pWrtShell->HasSelection() || IsDrawMode() )
714             {
715                 SdrView *pSdrView = pWrtShell->HasDrawView() ? pWrtShell->GetDrawView() : 0;
716                 if(pSdrView && pSdrView->AreObjectsMarked() &&
717                     pSdrView->GetHdlList().GetFocusHdl())
718                 {
719                     ((SdrHdlList&)pSdrView->GetHdlList()).ResetFocusHdl();
720                 }
721                 else
722                 {
723                     if(pSdrView)
724                     {
725                         LeaveDrawCreate();
726                         Point aPt(LONG_MIN, LONG_MIN);
727                         //go out of the frame
728                         pWrtShell->SelectObj(aPt, SW_LEAVE_FRAME);
729                         SfxBindings& rBind = GetViewFrame()->GetBindings();
730                         rBind.Invalidate( SID_ATTR_SIZE );
731                     }
732                     pWrtShell->EnterStdMode();
733                     AttrChangedNotify(pWrtShell); // ggf Shellwechsel...
734                 }
735             }
736             else if ( GetEditWin().GetApplyTemplate() )
737             {
738                 GetEditWin().SetApplyTemplate(SwApplyTemplate());
739             }
740             else if( ((SfxObjectShell*)GetDocShell())->IsInPlaceActive() )
741             {
742                 Escape();
743             }
744             else if ( GetEditWin().IsChainMode() )
745             {
746                 GetEditWin().SetChainMode( sal_False );
747             }
748             else if( pWrtShell->GetFlyFrmFmt() )
749             {
750                 const SwFrmFmt* pFmt = pWrtShell->GetFlyFrmFmt();
751                 if(pWrtShell->GotoFly( pFmt->GetName(), FLYCNTTYPE_FRM ))
752                 {
753                     pWrtShell->HideCrsr();
754                     pWrtShell->EnterSelFrmMode();
755                 }
756             }
757             else
758             {
759                 SfxBoolItem aItem( SID_WIN_FULLSCREEN, sal_False );
760                 GetViewFrame()->GetDispatcher()->Execute( SID_WIN_FULLSCREEN, SFX_CALLMODE_RECORD, &aItem, 0L );
761                 bIgnore = sal_True;
762             }
763         }
764         break;
765         case SID_ATTR_BORDER_INNER:
766         case SID_ATTR_BORDER_OUTER:
767         case SID_ATTR_BORDER_SHADOW:
768             if(pArgs)
769                 pWrtShell->SetAttr(*pArgs);
770             break;
771 
772         case SID_ATTR_PAGE:
773         case SID_ATTR_PAGE_SIZE:
774         case SID_ATTR_PAGE_MAXSIZE:
775         case SID_ATTR_PAGE_PAPERBIN:
776         case SID_ATTR_PAGE_EXT1:
777         case FN_PARAM_FTN_INFO:
778         {
779             if(pArgs)
780             {
781                 const sal_uInt16 nCurIdx = pWrtShell->GetCurPageDesc();
782                 SwPageDesc aPageDesc( pWrtShell->GetPageDesc( nCurIdx ) );
783                 ::ItemSetToPageDesc( *pArgs, aPageDesc );
784                 // Den Descriptor der Core veraendern.
785                 pWrtShell->ChgPageDesc( nCurIdx, aPageDesc );
786             }
787         }
788         break;
789         case FN_NAVIGATION_PI_GOTO_PAGE:
790         {
791             SfxViewFrame* pVFrame = GetViewFrame();
792             SfxChildWindow* pCh = pVFrame->GetChildWindow( SID_NAVIGATOR );
793             if(!pCh)
794             {
795                 pVFrame->ToggleChildWindow( SID_NAVIGATOR );
796                 pCh = pVFrame->GetChildWindow( SID_NAVIGATOR );
797 
798             }
799                 ((SwNavigationPI*) pCh->GetContextWindow(SW_MOD()))->GotoPage();
800         }
801         break;
802         case  FN_EDIT_CURRENT_TOX:
803         {
804             GetViewFrame()->GetDispatcher()->Execute(
805                                 FN_INSERT_MULTI_TOX, SFX_CALLMODE_ASYNCHRON);
806         }
807         break;
808         case FN_UPDATE_CUR_TOX:
809         {
810             const SwTOXBase* pBase = pWrtShell->GetCurTOX();
811             if(pBase)
812             {
813                 pWrtShell->StartAction();
814                 if(TOX_INDEX == pBase->GetType())
815                     pWrtShell->ApplyAutoMark();
816                 pWrtShell->UpdateTableOf( *pBase );
817                 pWrtShell->EndAction();
818             }
819         }
820         break;
821         case FN_UPDATE_TOX:
822         {
823             pWrtShell->StartAction();
824             pWrtShell->EnterStdMode();
825             sal_Bool bOldCrsrInReadOnly = pWrtShell->IsReadOnlyAvailable();
826             pWrtShell->SetReadOnlyAvailable( sal_True );
827 
828             for( sal_uInt16 i = 0; i < 2; ++i )
829             {
830                 sal_uInt16 nCount = pWrtShell->GetTOXCount();
831                 if( 1 == nCount )
832                     ++i;
833 
834                 while( pWrtShell->GotoPrevTOXBase() )
835                     ;   // aufs erste Verzeichnis springen
836 
837                 // falls wir nicht mehr in einem stehen, dann zum naechsten
838                 // springen.
839                 const SwTOXBase* pBase = pWrtShell->GetCurTOX();
840                 if( !pBase )
841                 {
842                     pWrtShell->GotoNextTOXBase();
843                     pBase = pWrtShell->GetCurTOX();
844                 }
845 
846                 sal_Bool bAutoMarkApplied = sal_False;
847                 while( pBase )
848                 {
849                     if(TOX_INDEX == pBase->GetType() && !bAutoMarkApplied)
850                     {
851                         pWrtShell->ApplyAutoMark();
852                         bAutoMarkApplied = sal_True;
853                     }
854                     // JP 15.07.96: das pBase wird nur fuer die Schnittstelle
855                     //              benoetigt. Muss mal umgetstellt werden!!!
856                     pWrtShell->UpdateTableOf( *pBase );
857 
858                     if( pWrtShell->GotoNextTOXBase() )
859                         pBase = pWrtShell->GetCurTOX();
860                     else
861                         pBase = 0;
862                 }
863             }
864             pWrtShell->SetReadOnlyAvailable( bOldCrsrInReadOnly );
865             pWrtShell->EndAction();
866         }
867         break;
868         case SID_ATTR_BRUSH:
869         {
870             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(RES_BACKGROUND, sal_False, &pItem))
871             {
872                 const sal_uInt16 nCurIdx = pWrtShell->GetCurPageDesc();
873                 SwPageDesc aDesc( pWrtShell->GetPageDesc( nCurIdx ));
874                 SwFrmFmt& rMaster = aDesc.GetMaster();
875                 rMaster.SetFmtAttr(*pItem);
876                 pWrtShell->ChgPageDesc( nCurIdx, aDesc);
877             }
878         }
879         break;
880         case SID_CLEARHISTORY:
881         {
882             pWrtShell->DelAllUndoObj();
883         }
884         break;
885         case SID_UNDO:
886         {
887             pShell->ExecuteSlot(rReq);
888         }
889         break;
890         case FN_INSERT_CTRL:
891         case FN_INSERT_OBJ_CTRL:
892         {
893             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(nSlot, sal_False, &pItem))
894             {
895                 sal_uInt16 nValue = ((SfxUInt16Item*)pItem)->GetValue();
896                 switch ( nSlot )
897                 {
898                     case FN_INSERT_CTRL:
899                     {
900                         sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
901                         if(bWeb)
902                             SwView::nWebInsertCtrlState = nValue;
903                         else
904                             SwView::nInsertCtrlState = nValue;
905                     }
906                     break;
907                     case FN_INSERT_OBJ_CTRL:    SwView::nInsertObjectCtrlState = nValue  ;break;
908                 }
909 
910             }
911             GetViewFrame()->GetBindings().Invalidate( nSlot );
912         }
913         break;
914 #if defined WNT || defined UNX
915         case SID_TWAIN_SELECT:
916         case SID_TWAIN_TRANSFER:
917             GetViewImpl()->ExecuteScan( rReq );
918         break;
919 #endif
920 
921         case SID_ATTR_DEFTABSTOP:
922         {
923             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_DEFTABSTOP, sal_False, &pItem))
924             {
925                 SvxTabStopItem aDefTabs( 0, 0, SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP );
926                 sal_uInt16 nTab = ((const SfxUInt16Item*)pItem)->GetValue();
927                 MakeDefTabs( nTab, aDefTabs );
928                 pWrtShell->SetDefault( aDefTabs );
929             }
930         }
931         break;
932         case SID_ATTR_LANGUAGE  :
933         if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_LANGUAGE, sal_False, &pItem))
934         {
935             SvxLanguageItem aLang(((SvxLanguageItem*)pItem)->GetLanguage(), RES_CHRATR_LANGUAGE);
936             pWrtShell->SetDefault( aLang );
937             lcl_SetAllTextToDefaultLanguage( *pWrtShell, RES_CHRATR_LANGUAGE );
938         }
939         break;
940         case  SID_ATTR_CHAR_CTL_LANGUAGE:
941         if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(RES_CHRATR_CTL_LANGUAGE, sal_False, &pItem))
942         {
943             pWrtShell->SetDefault( *pItem );
944             lcl_SetAllTextToDefaultLanguage( *pWrtShell, RES_CHRATR_CTL_LANGUAGE );
945         }
946         break;
947         case  SID_ATTR_CHAR_CJK_LANGUAGE:
948         if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(RES_CHRATR_CJK_LANGUAGE, sal_False, &pItem))
949         {
950             pWrtShell->SetDefault( *pItem );
951             lcl_SetAllTextToDefaultLanguage( *pWrtShell, RES_CHRATR_CJK_LANGUAGE );
952         }
953         break;
954         case FN_SCROLL_NEXT_PREV:
955             if(pArgs && pArgs->GetItemState(FN_SCROLL_NEXT_PREV, sal_False, &pItem))
956             {
957                 // call the handlers of PageUp/DownButtons, only
958                 bool* pbNext = new bool ( ((const SfxBoolItem*)pItem)->GetValue() );
959                 // #i75416# move the execution of the search to an asynchronously called static link
960                 Application::PostUserEvent( STATIC_LINK(this, SwView, MoveNavigationHdl), pbNext );
961             }
962             break;
963         case SID_JUMPTOMARK:
964             if( pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_JUMPTOMARK, sal_False, &pItem))
965                 JumpToSwMark( (( const SfxStringItem*)pItem)->GetValue() );
966             break;
967         case SID_GALLERY :
968             GetViewFrame()->ChildWindowExecute(rReq);//ToggleChildWindow(SID_GALLERY);
969         break;
970         case SID_AVMEDIA_PLAYER :
971             GetViewFrame()->ChildWindowExecute(rReq);//ToggleChildWindow(SID_AVMEDIA_PLAYER);
972         break;
973         case SID_VIEW_DATA_SOURCE_BROWSER:
974         {
975             SfxViewFrame* pVFrame = GetViewFrame();
976             pVFrame->ChildWindowExecute(rReq);
977             if(pVFrame->HasChildWindow(SID_BROWSER))
978             {
979                 const SwDBData& rData = GetWrtShell().GetDBDesc();
980                 SW_MOD()->ShowDBObj(*this, rData, sal_False);
981             }
982         }
983         break;
984         case FN_INSERT_FIELD_DATA_ONLY :
985         {
986             sal_Bool bShow = sal_False;
987             if( pArgs &&
988                 SFX_ITEM_SET == pArgs->GetItemState(nSlot, sal_False, &pItem ))
989                 bShow = ((const SfxBoolItem*)pItem)->GetValue();
990             //GetViewFrame()->ShowChildWindow(nSlot, bShow && bInMailMerge);
991             if((bShow && bInMailMerge) != GetViewFrame()->HasChildWindow(nSlot))
992                 GetViewFrame()->ToggleChildWindow(nSlot);
993             //if fields have been succesfully inserted call the "real"
994             //mail merge dialog
995             SwWrtShell &rSh = GetWrtShell();
996             if(bInMailMerge && rSh.IsAnyDatabaseFieldInDoc())
997             {
998                 SwNewDBMgr* pNewDBMgr = rSh.GetNewDBMgr();
999                 if (pNewDBMgr)
1000                 {
1001                     SwDBData aData;
1002                     aData = rSh.GetDBData();
1003                     rSh.EnterStdMode(); // Wechsel in Textshell erzwingen; ist fuer
1004                                         // das Mischen von DB-Feldern notwendig.
1005                     AttrChangedNotify( &rSh );
1006                     pNewDBMgr->SetMergeType( DBMGR_MERGE );
1007 
1008                     Sequence<PropertyValue> aProperties(3);
1009                     PropertyValue* pValues = aProperties.getArray();
1010                     pValues[0].Name = C2U("DataSourceName");
1011                     pValues[1].Name = C2U("Command");
1012                     pValues[2].Name = C2U("CommandType");
1013                     pValues[0].Value <<= aData.sDataSource;
1014                     pValues[1].Value <<= aData.sCommand;
1015                     pValues[2].Value <<= aData.nCommandType;
1016                     pNewDBMgr->ExecuteFormLetter(rSh, aProperties, sal_True);
1017                 }
1018             }
1019             bInMailMerge &= bShow;
1020             GetViewFrame()->GetBindings().Invalidate(FN_INSERT_FIELD);
1021         }
1022         break;
1023         case FN_QRY_MERGE:
1024         {
1025             sal_Bool bUseCurrentDocument = sal_True;
1026             sal_Bool bQuery = !pArgs||SFX_ITEM_SET != pArgs->GetItemState(nSlot);
1027             if(bQuery)
1028             {
1029                 SfxViewFrame* pTmpFrame = GetViewFrame();
1030                 SfxHelp::OpenHelpAgent( &pTmpFrame->GetFrame(), HID_MAIL_MERGE_SELECT );
1031                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1032                 DBG_ASSERT(pFact, "Dialogdiet fail!");
1033                 AbstractMailMergeCreateFromDlg* pDlg = pFact->CreateMailMergeCreateFromDlg( DLG_MERGE_CREATE,
1034                                                         &pTmpFrame->GetWindow());
1035                 DBG_ASSERT(pDlg, "Dialogdiet fail!");
1036                 if(RET_OK == pDlg->Execute())
1037                     bUseCurrentDocument = pDlg->IsThisDocument();
1038                 else
1039                     break;
1040             }
1041             GenerateFormLetter(bUseCurrentDocument);
1042         }
1043         break;
1044         case SID_RECHECK_DOCUMENT:
1045         {
1046             SwDocShell* pDocShell = GetDocShell();
1047             SwDoc* pDoc = pDocShell->GetDoc();
1048             uno::Reference< linguistic2::XProofreadingIterator >  xGCIterator( pDoc->GetGCIterator() );
1049             if( xGCIterator.is() )
1050             {
1051                 xGCIterator->resetIgnoreRules();
1052             }
1053             // reset ignore lists
1054             pDoc->SpellItAgainSam( sal_True, sal_False, sal_False );
1055             // clear ignore dictionary
1056             uno::Reference< linguistic2::XDictionary > xDictionary( SvxGetIgnoreAllList(), uno::UNO_QUERY );
1057             if( xDictionary.is() )
1058                 xDictionary->clear();
1059             // put cursor to the start of the document
1060             pWrtShell->SttDoc();
1061         }
1062         // no break; - but call spell/grammar dialog
1063         case FN_SPELL_GRAMMAR_DIALOG:
1064         {
1065             SfxViewFrame* pViewFrame = GetViewFrame();
1066             if (rReq.GetArgs() != NULL)
1067                 pViewFrame->SetChildWindow (FN_SPELL_GRAMMAR_DIALOG,
1068                     ((const SfxBoolItem&) (rReq.GetArgs()->
1069                         Get(FN_SPELL_GRAMMAR_DIALOG))).GetValue());
1070             else
1071                 pViewFrame->ToggleChildWindow(FN_SPELL_GRAMMAR_DIALOG);
1072 
1073             pViewFrame->GetBindings().Invalidate(FN_SPELL_GRAMMAR_DIALOG);
1074             rReq.Ignore ();
1075         }
1076         break;
1077         case SID_ALIGN_ANY_LEFT :
1078         case SID_ALIGN_ANY_HCENTER  :
1079         case SID_ALIGN_ANY_RIGHT    :
1080         case SID_ALIGN_ANY_JUSTIFIED:
1081         case SID_ALIGN_ANY_TOP      :
1082         case SID_ALIGN_ANY_VCENTER  :
1083         case SID_ALIGN_ANY_BOTTOM   :
1084         case SID_ALIGN_ANY_HDEFAULT :
1085         case SID_ALIGN_ANY_VDEFAULT :
1086         {
1087             sal_uInt16 nAlias = 0;
1088             if( nSelectionType & (nsSelectionType::SEL_DRW_TXT|nsSelectionType::SEL_TXT) )
1089             {
1090                 switch( nSlot )
1091                 {
1092                     case SID_ALIGN_ANY_LEFT :       nAlias = SID_ATTR_PARA_ADJUST_LEFT; break;
1093                     case SID_ALIGN_ANY_HCENTER  :   nAlias = SID_ATTR_PARA_ADJUST_CENTER; break;
1094                     case SID_ALIGN_ANY_RIGHT    :   nAlias = SID_ATTR_PARA_ADJUST_RIGHT; break;
1095                     case SID_ALIGN_ANY_JUSTIFIED:   nAlias = SID_ATTR_PARA_ADJUST_BLOCK; break;
1096                     case SID_ALIGN_ANY_TOP      :   nAlias = FN_TABLE_VERT_NONE; break;
1097                     case SID_ALIGN_ANY_VCENTER  :   nAlias = FN_TABLE_VERT_CENTER; break;
1098                     case SID_ALIGN_ANY_BOTTOM   :   nAlias = FN_TABLE_VERT_BOTTOM; break;
1099                 }
1100             }
1101             else
1102             {
1103                 switch( nSlot )
1104                 {
1105                     case SID_ALIGN_ANY_LEFT :       nAlias = SID_OBJECT_ALIGN_LEFT    ; break;
1106                     case SID_ALIGN_ANY_HCENTER  :   nAlias = SID_OBJECT_ALIGN_CENTER ; break;
1107                     case SID_ALIGN_ANY_RIGHT    :   nAlias = SID_OBJECT_ALIGN_RIGHT  ; break;
1108                     case SID_ALIGN_ANY_TOP      :   nAlias = SID_OBJECT_ALIGN_UP     ;  break;
1109                     case SID_ALIGN_ANY_VCENTER  :   nAlias = SID_OBJECT_ALIGN_MIDDLE ;  break;
1110                     case SID_ALIGN_ANY_BOTTOM   :   nAlias = SID_OBJECT_ALIGN_DOWN    ; break;
1111                 }
1112             }
1113             //special handling for the draw shell
1114             if(nAlias && (nSelectionType & (nsSelectionType::SEL_DRW)))
1115             {
1116                 SfxAllEnumItem aEnumItem(SID_OBJECT_ALIGN, nAlias - SID_OBJECT_ALIGN_LEFT);
1117                 GetViewFrame()->GetDispatcher()->Execute(
1118                                 SID_OBJECT_ALIGN, SFX_CALLMODE_ASYNCHRON, &aEnumItem, 0L);
1119             }
1120             else if(nAlias)
1121             //these slots are either re-mapped to text or object alignment
1122                 GetViewFrame()->GetDispatcher()->Execute(
1123                                 nAlias, SFX_CALLMODE_ASYNCHRON);
1124         }
1125         break;
1126         case SID_RESTORE_EDITING_VIEW:
1127         {
1128             //#i33307# restore editing position
1129             Point aCrsrPos;
1130             bool bSelectObj;
1131             if(pViewImpl->GetRestorePosition(aCrsrPos, bSelectObj))
1132             {
1133                 pWrtShell->SwCrsrShell::SetCrsr( aCrsrPos, !bSelectObj );
1134                 if( bSelectObj )
1135                 {
1136                     pWrtShell->SelectObj( aCrsrPos );
1137                     pWrtShell->EnterSelFrmMode( &aCrsrPos );
1138                 }
1139             }
1140         }
1141         break;
1142         case SID_INSERT_GRAPHIC:
1143         {
1144             rReq.SetReturnValue(SfxBoolItem(nSlot, InsertGraphicDlg( rReq )));
1145         }
1146         break;
1147 
1148 
1149         default:
1150             ASSERT(!this, falscher Dispatcher);
1151             return;
1152     }
1153     if(!bIgnore)
1154         rReq.Done();
1155 }
1156 
1157 /*--------------------------------------------------------------------
1158     Beschreibung:   SeitenNr-Feld invalidieren
1159  --------------------------------------------------------------------*/
1160 
1161 void SwView::UpdatePageNums(sal_uInt16 nPhyNum, sal_uInt16 nVirtNum, const String& rPgStr)
1162 {
1163     String sTemp(GetPageStr( nPhyNum, nVirtNum, rPgStr ));
1164     const SfxStringItem aTmp( FN_STAT_PAGE, sTemp );
1165     SfxBindings &rBnd = GetViewFrame()->GetBindings();
1166     rBnd.SetState( aTmp );
1167     rBnd.Update( FN_STAT_PAGE );
1168 }
1169 
1170 /*--------------------------------------------------------------------
1171     Beschreibung:   Status der Stauszeile
1172  --------------------------------------------------------------------*/
1173 
1174 
1175 void SwView::StateStatusLine(SfxItemSet &rSet)
1176 {
1177     SwWrtShell& rShell = GetWrtShell();
1178 
1179     SfxWhichIter aIter( rSet );
1180     sal_uInt16 nWhich = aIter.FirstWhich();
1181     ASSERT( nWhich, "leeres Set");
1182 
1183     while( nWhich )
1184     {
1185         switch( nWhich )
1186         {
1187             case FN_STAT_PAGE:
1188 /*
1189 //JP 07.01.00: is a nice feature - show the selektion of DrawObjects
1190             if( rShell.IsObjSelected()
1191 //???               || rShell.IsFrmSelected()
1192                 )
1193             {
1194                 String sDisplay( rShell.GetDrawView()->GetMarkedObjectList().
1195                                     GetDescriptionOfMarkedObjects() );
1196                 rSet.Put( SfxStringItem( FN_STAT_PAGE, sDisplay ));
1197             }
1198             else
1199 */          {
1200                 // Anzahl der Seiten, log. SeitenNr. SeitenNr ermitteln
1201                 sal_uInt16 nPage, nLogPage;
1202                 String sDisplay;
1203                 rShell.GetPageNumber( -1, rShell.IsCrsrVisible(), nPage, nLogPage, sDisplay );
1204                 rSet.Put( SfxStringItem( FN_STAT_PAGE,
1205                             GetPageStr( nPage, nLogPage, sDisplay) ));
1206 
1207                 sal_uInt16 nCnt = GetWrtShell().GetPageCnt();
1208                 if (nPageCnt != nCnt)   // Basic benachrichtigen
1209                 {
1210                     nPageCnt = nCnt;
1211                     SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_PAGE_COUNT, SwDocShell::GetEventName(STR_SW_EVENT_PAGE_COUNT), GetViewFrame()->GetObjectShell()), sal_False);
1212                 }
1213             }
1214             break;
1215             case FN_STAT_TEMPLATE:
1216             {
1217                 rSet.Put(SfxStringItem( FN_STAT_TEMPLATE,
1218                                         rShell.GetCurPageStyle(sal_False)));
1219 
1220             }
1221             break;
1222             case SID_ATTR_ZOOM:
1223             {
1224                 if ( ( GetDocShell()->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) || !GetDocShell()->IsInPlaceActive() )
1225                 {
1226                     const SwViewOption* pVOpt = rShell.GetViewOptions();
1227                     SvxZoomType eZoom = (SvxZoomType) pVOpt->GetZoomType();
1228                     SvxZoomItem aZoom(eZoom,
1229                                         pVOpt->GetZoom());
1230                     if( pVOpt->getBrowseMode() )
1231                     {
1232                         aZoom.SetValueSet(
1233                                 SVX_ZOOM_ENABLE_50|
1234                                 SVX_ZOOM_ENABLE_75|
1235                                 SVX_ZOOM_ENABLE_100|
1236                                 SVX_ZOOM_ENABLE_150|
1237                                 SVX_ZOOM_ENABLE_200);
1238                     }
1239                     rSet.Put( aZoom );
1240                 }
1241                 else
1242                     rSet.DisableItem( SID_ATTR_ZOOM );
1243             }
1244             break;
1245             case SID_ATTR_VIEWLAYOUT:
1246             {
1247                 if ( ( GetDocShell()->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) || !GetDocShell()->IsInPlaceActive() )
1248                 {
1249                     const SwViewOption* pVOpt = rShell.GetViewOptions();
1250                     const sal_uInt16 nColumns  = pVOpt->GetViewLayoutColumns();
1251                     const bool  bBookMode = pVOpt->IsViewLayoutBookMode();
1252                     SvxViewLayoutItem aViewLayout(nColumns, bBookMode);
1253                     rSet.Put( aViewLayout );
1254                 }
1255                 else
1256                     rSet.DisableItem( SID_ATTR_VIEWLAYOUT );
1257             }
1258             break;
1259             case SID_ATTR_ZOOMSLIDER:
1260             {
1261                 if ( ( GetDocShell()->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) || !GetDocShell()->IsInPlaceActive() )
1262                 {
1263                     const SwViewOption* pVOpt = rShell.GetViewOptions();
1264                     const sal_uInt16 nCurrentZoom = pVOpt->GetZoom();
1265                     SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM );
1266                     aZoomSliderItem.AddSnappingPoint( 100 );
1267 
1268                     if ( !pWrtShell->getIDocumentSettingAccess()->get(IDocumentSettingAccess::BROWSE_MODE) )
1269                     {
1270                         const sal_uInt16 nColumns = pVOpt->GetViewLayoutColumns();
1271                         const bool bAutomaticViewLayout = 0 == nColumns;
1272                         const SwPostItMgr* pMgr = GetPostItMgr();
1273 
1274                         // snapping points:
1275                         // automatic mode: 1 Page, 2 Pages, 100%
1276                         // n Columns mode: n Pages, 100%
1277                         // n Columns book mode: nPages without gaps, 100%
1278                         const SwRect aPageRect( pWrtShell->GetAnyCurRect( RECT_PAGE_CALC ) );
1279                         const SwRect aRootRect( pWrtShell->GetAnyCurRect( RECT_PAGES_AREA ) ); // width of columns
1280                         Size aPageSize( aPageRect.SSize() );
1281                         aPageSize.Width() += pMgr->HasNotes() && pMgr->ShowNotes() ?
1282                                              pMgr->GetSidebarWidth() + pMgr->GetSidebarBorderWidth() :
1283                                              0;
1284 
1285                         Size aRootSize( aRootRect.SSize() );
1286 
1287                         const MapMode aTmpMap( MAP_TWIP );
1288                         const Size& rEditSize = GetEditWin().GetOutputSizePixel();
1289                         const Size aWindowSize( GetEditWin().PixelToLogic( rEditSize, aTmpMap ) );
1290 
1291                         const long nOf = DOCUMENTBORDER * 2L;
1292                         long nTmpWidth = bAutomaticViewLayout ? aPageSize.Width() : aRootSize.Width();
1293                         nTmpWidth += nOf;
1294                         aPageSize.Height() += nOf;
1295                         long nFac = aWindowSize.Width() * 100 / nTmpWidth;
1296 
1297                         long nVisPercent = aWindowSize.Height() * 100 / aPageSize.Height();
1298                         nFac = Min( nFac, nVisPercent );
1299 
1300                         aZoomSliderItem.AddSnappingPoint( nFac );
1301 
1302                         if ( bAutomaticViewLayout )
1303                         {
1304                             nTmpWidth += aPageSize.Width() + GAPBETWEENPAGES;
1305                             nFac = aWindowSize.Width() * 100 / nTmpWidth;
1306                             nFac = Min( nFac, nVisPercent );
1307                             aZoomSliderItem.AddSnappingPoint( nFac );
1308                         }
1309                     }
1310 
1311                     rSet.Put( aZoomSliderItem );
1312                 }
1313                 else
1314                     rSet.DisableItem( SID_ATTR_ZOOMSLIDER );
1315             }
1316             break;
1317             case SID_ATTR_POSITION:
1318             case SID_ATTR_SIZE:
1319             {
1320                 if( !rShell.IsFrmSelected() && !rShell.IsObjSelected() )
1321                     SwBaseShell::_SetFrmMode( FLY_DRAG_END );
1322                 else
1323                 {
1324                     FlyMode eFrameMode = SwBaseShell::GetFrmMode();
1325                     if ( eFrameMode == FLY_DRAG_START || eFrameMode == FLY_DRAG )
1326                     {
1327                         if ( nWhich == SID_ATTR_POSITION )
1328                             rSet.Put( SfxPointItem( SID_ATTR_POSITION,
1329                                                     rShell.GetAnchorObjDiff()));
1330                         else
1331                             rSet.Put( SvxSizeItem( SID_ATTR_SIZE,
1332                                                    rShell.GetObjSize()));
1333                     }
1334                 }
1335             }
1336             break;
1337             case SID_TABLE_CELL:
1338 
1339             if( rShell.IsFrmSelected() || rShell.IsObjSelected() )
1340             {
1341                 // #i39171# Don't put a SvxSizeItem into a slot which is defined as SfxStringItem.
1342                 // SvxPosSizeStatusBarControl no longer resets to empty display if only one slot
1343                 // has no item, so SID_TABLE_CELL can remain empty (the SvxSizeItem is supplied
1344                 // in SID_ATTR_SIZE).
1345             }
1346             else
1347             {
1348                 String sStr;
1349                 if( rShell.IsCrsrInTbl() )
1350                 {
1351                     // table name + cell coordinate
1352                     sStr = rShell.GetTableFmt()->GetName();
1353                     sStr += ':';
1354                     sStr += rShell.GetBoxNms();
1355                 }
1356                 else
1357                 {
1358                     const SwSection* pCurrSect = rShell.GetCurrSection();
1359                     if( pCurrSect )
1360                     {
1361                         switch( pCurrSect->GetType() )
1362                         {
1363                         case TOX_HEADER_SECTION:
1364                         case TOX_CONTENT_SECTION:
1365                             {
1366                                 const SwTOXBase* pTOX = pWrtShell->GetCurTOX();
1367                                 if( pTOX )
1368                                     sStr = pTOX->GetTOXName();
1369                                 else
1370                                 {
1371                                     ASSERT( !this,
1372                                         "was ist das fuer ein Verzeichnis?" );
1373                                     sStr = pCurrSect->GetSectionName();
1374                                 }
1375                             }
1376                             break;
1377                         default:
1378                             sStr = pCurrSect->GetSectionName();
1379                             break;
1380                         }
1381                     }
1382                 }
1383 
1384                 //#outline level, removed by zhaojianwei
1385                 //const SwNumRule* pNumRule = rShell.GetCurNumRule();
1386                 //if (pNumRule) // Cursor in Numerierung
1387                 //{
1388                 //  sal_uInt8 nNumLevel = rShell.GetNumLevel();
1389                 //  if( IsShowNum(nNumLevel) && MAXLEVEL >
1390                 //      ( nNumLevel = GetRealLevel( nNumLevel )) )
1391                 //  {
1392                 //      if( sStr.Len() )
1393                 //          sStr.AppendAscii(sStatusDelim);
1394                 //      sStr += SW_RESSTR(STR_NUM_LEVEL);
1395                 //      sStr += String::CreateFromInt32( nNumLevel + 1 );
1396                 //      if(!pNumRule->IsAutoRule())
1397                 //      {
1398                 //          SfxItemSet aSet(GetPool(),
1399                 //              RES_PARATR_NUMRULE, RES_PARATR_NUMRULE);
1400                 //          rShell.GetCurAttr(aSet);
1401                 //          /* const SfxPoolItem* pItem; */
1402                 //          if(SFX_ITEM_AVAILABLE <=
1403                 //              aSet.GetItemState(RES_PARATR_NUMRULE, sal_True
1404                 //              /*, &pItem */ ))
1405                 //          {
1406                 //              const String& rNumStyle =
1407                 //                  ((const SfxStringItem &)
1408                 //                  aSet.Get(RES_PARATR_NUMRULE)).GetValue();
1409                 //              /* #i5116# GetItemState does not necessarily
1410                 //              change pItem */
1411                 //              // ((const SfxStringItem*)pItem)->GetValue();
1412                 //              if(rNumStyle.Len())
1413                 //              {
1414                 //                  sStr.AppendAscii(sStatusDelim);
1415                 //                  sStr += rNumStyle;
1416                 //              }
1417                 //          }
1418                 //      }
1419                 //  }
1420                 //}//<-removed end ,zhaojianwei
1421 
1422                 //-->#outline level,added by zhaojianwei
1423                 const SwNumRule* pNumRule = rShell.GetCurNumRule();
1424                 const bool bOutlineNum = pNumRule ? pNumRule->IsOutlineRule() : 0;
1425                        //((SwTxtFmtColl*)rShell.GetCrsr()->GetNode()->GetTxtNode()->GetFmtColl())->IsAssignedToListLevelOfOutlineStyle();
1426 
1427                 if (pNumRule && !bOutlineNum )  // Cursor in Numerierung
1428                 {
1429                     sal_uInt8 nNumLevel = rShell.GetNumLevel();
1430                     // --> OD 2008-04-02 #refactorlists#
1431 //                    if( IsShowNum(nNumLevel) && MAXLEVEL >
1432 //                        ( nNumLevel = GetRealLevel( nNumLevel )) )
1433                     if ( nNumLevel < MAXLEVEL )
1434                     // <--
1435                     {
1436                         if(!pNumRule->IsAutoRule())
1437                         {
1438                             SfxItemSet aSet(GetPool(),
1439                                     RES_PARATR_NUMRULE, RES_PARATR_NUMRULE);
1440                             rShell.GetCurAttr(aSet);
1441                             /* const SfxPoolItem* pItem; */
1442                             if(SFX_ITEM_AVAILABLE <=
1443                                aSet.GetItemState(RES_PARATR_NUMRULE, sal_True
1444                                                  /*, &pItem */ ))
1445                             {
1446                                 const String& rNumStyle =
1447                                     ((const SfxStringItem &)
1448                                      aSet.Get(RES_PARATR_NUMRULE)).GetValue();
1449                                 /* #i5116# GetItemState does not necessarily
1450                                    change pItem */
1451                                 // ((const SfxStringItem*)pItem)->GetValue();
1452                                 if(rNumStyle.Len())
1453                                 {
1454                                     if( sStr.Len() )
1455                                         sStr.AppendAscii(sStatusDelim);
1456                                     sStr += rNumStyle;
1457                                 }
1458                             }
1459                         }
1460                         if( sStr.Len() )
1461                             sStr.AppendAscii(sStatusDelim);
1462                         sStr += SW_RESSTR(STR_NUM_LEVEL);
1463                         sStr += String::CreateFromInt32( nNumLevel + 1 );
1464 
1465                     }
1466                 }
1467                 const int nOutlineLevel = rShell.GetCurrentParaOutlineLevel();
1468                 if( nOutlineLevel != 0 )
1469                 {
1470                     if( sStr.Len() )
1471                         sStr.AppendAscii(sStatusComma);
1472                     if( bOutlineNum )
1473                     {
1474                         sStr += SW_RESSTR(STR_OUTLINE_NUMBERING);
1475                         sStr.AppendAscii(sStatusDelim);
1476                         sStr += SW_RESSTR(STR_NUM_LEVEL);
1477                     }
1478                     else
1479                         sStr += SW_RESSTR(STR_NUM_OUTLINE);
1480                     sStr += String::CreateFromInt32( nOutlineLevel);
1481                 }
1482                 //<-end ,zhaojianwei
1483 
1484                 if( rShell.HasReadonlySel() )
1485                 {
1486                     if( sStr.Len() )
1487                         sStr.InsertAscii( sStatusDelim, 0 );
1488                     sStr.Insert( SW_RESSTR( STR_READONLY_SEL ), 0 );
1489                 }
1490                 if( sStr.Len() )
1491                     rSet.Put( SfxStringItem( SID_TABLE_CELL, sStr ));
1492             }
1493             break;
1494             case FN_STAT_SELMODE:
1495             {
1496                 if(rShell.IsStdMode())
1497                     rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 0));
1498                 else if(rShell.IsAddMode())
1499                     rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 2));
1500                 else if(rShell.IsBlockMode())
1501                     rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 3));
1502                 else
1503                     rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 1));
1504                 break;
1505             }
1506             case SID_ATTR_INSERT:
1507                 if( rShell.IsRedlineOn() )
1508                     rSet.DisableItem( nWhich );
1509                 else
1510                 {
1511                     rSet.Put(SfxBoolItem(SID_ATTR_INSERT,rShell.IsInsMode()));
1512                 }
1513                 break;
1514         }
1515         nWhich = aIter.NextWhich();
1516     }
1517 }
1518 
1519 /*--------------------------------------------------------------------
1520     Beschreibung:   Execute fuer die Stauszeile
1521  --------------------------------------------------------------------*/
1522 
1523 
1524 void SwView::ExecuteStatusLine(SfxRequest &rReq)
1525 {
1526     SwWrtShell &rSh = GetWrtShell();
1527     const SfxItemSet* pArgs = rReq.GetArgs();
1528     const SfxPoolItem* pItem=NULL;
1529     sal_Bool bUp = sal_False;
1530     sal_uInt16 nWhich = rReq.GetSlot();
1531     switch( nWhich )
1532     {
1533         case FN_STAT_PAGE:
1534         {
1535             GetViewFrame()->GetDispatcher()->Execute( SID_NAVIGATOR,
1536                                       SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD );
1537         }
1538         break;
1539 
1540         case FN_STAT_BOOKMARK:
1541         if ( pArgs )
1542         {
1543             if (SFX_ITEM_SET == pArgs->GetItemState( nWhich, sal_True, &pItem))
1544             {
1545                 const IDocumentMarkAccess* pMarkAccess = rSh.getIDocumentMarkAccess();
1546                 const sal_Int32 nIdx = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1547                 if(nIdx < pMarkAccess->getBookmarksCount())
1548                 {
1549                     const IDocumentMarkAccess::const_iterator_t ppBookmark = rSh.getIDocumentMarkAccess()->getBookmarksBegin() + nIdx;
1550                     rSh.EnterStdMode();
1551                     rSh.GotoMark( ppBookmark->get() );
1552                 }
1553                 else
1554                     OSL_ENSURE(false,
1555                         "SwView::ExecuteStatusLine(..)"
1556                         " - Ignoring out of range bookmark index");
1557             }
1558         }
1559         break;
1560 
1561         case FN_STAT_TEMPLATE:
1562         {
1563             GetViewFrame()->GetDispatcher()->Execute(FN_FORMAT_PAGE_DLG,
1564                                         SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD );
1565         }
1566         break;
1567         case SID_ATTR_ZOOM:
1568         {
1569             if ( ( GetDocShell()->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) || !GetDocShell()->IsInPlaceActive() )
1570             {
1571                 const SfxItemSet *pSet = 0;
1572                 AbstractSvxZoomDialog *pDlg = 0;
1573                 if ( pArgs )
1574                     pSet = pArgs;
1575                 else
1576                 {
1577                     const SwViewOption& rViewOptions = *rSh.GetViewOptions();
1578                     SfxItemSet aCoreSet(pShell->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM, SID_ATTR_VIEWLAYOUT, SID_ATTR_VIEWLAYOUT, 0 );
1579                     SvxZoomItem aZoom( (SvxZoomType)rViewOptions.GetZoomType(), rViewOptions.GetZoom() );
1580 
1581                     const bool bBrowseMode = rSh.GetViewOptions()->getBrowseMode();
1582                     if( bBrowseMode )
1583                     {
1584                         aZoom.SetValueSet(
1585                                 SVX_ZOOM_ENABLE_50|
1586                                 SVX_ZOOM_ENABLE_75|
1587                                 SVX_ZOOM_ENABLE_100|
1588                                 SVX_ZOOM_ENABLE_150|
1589                                 SVX_ZOOM_ENABLE_200);
1590                     }
1591                     aCoreSet.Put( aZoom );
1592 
1593                     // PAGES01
1594                     if ( !bBrowseMode )
1595                     {
1596                         const SvxViewLayoutItem aViewLayout( rViewOptions.GetViewLayoutColumns(), rViewOptions.IsViewLayoutBookMode() );
1597                         aCoreSet.Put( aViewLayout );
1598                     }
1599 
1600                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1601                     if(pFact)
1602                     {
1603                         pDlg = pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aCoreSet);
1604                         DBG_ASSERT(pDlg, "Dialogdiet fail!");
1605                     }
1606 
1607                     pDlg->SetLimits( MINZOOM, MAXZOOM );
1608 
1609                     if( pDlg->Execute() != RET_CANCEL )
1610                         pSet = pDlg->GetOutputItemSet();
1611                 }
1612 
1613                 // PAGES01
1614                 const SfxPoolItem* pViewLayoutItem = 0;
1615                 if ( pSet && SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_VIEWLAYOUT, sal_True, &pViewLayoutItem))
1616                 {
1617                     const sal_uInt16 nColumns = ((const SvxViewLayoutItem *)pViewLayoutItem)->GetValue();
1618                     const bool bBookMode  = ((const SvxViewLayoutItem *)pViewLayoutItem)->IsBookMode();
1619                     SetViewLayout( nColumns, bBookMode );
1620                 }
1621 
1622                 if ( pSet && SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_ZOOM, sal_True, &pItem))
1623                 {
1624                     enum SvxZoomType eType = ((const SvxZoomItem *)pItem)->GetType();
1625                     SetZoom( eType, ((const SvxZoomItem *)pItem)->GetValue() );
1626                 }
1627                 bUp = sal_True;
1628                 if ( pItem )
1629                     rReq.AppendItem( *pItem );
1630                 rReq.Done();
1631 
1632                 delete pDlg;
1633             }
1634         }
1635         break;
1636 
1637         case SID_ATTR_VIEWLAYOUT:
1638         {
1639             if ( pArgs && !rSh.getIDocumentSettingAccess()->get(IDocumentSettingAccess::BROWSE_MODE) &&
1640                 ( ( GetDocShell()->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) || !GetDocShell()->IsInPlaceActive() ) )
1641             {
1642                 // PAGES01
1643                 if ( SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_VIEWLAYOUT, sal_True, &pItem ))
1644                 {
1645                     const sal_uInt16 nColumns = ((const SvxViewLayoutItem *)pItem)->GetValue();
1646                     const bool bBookMode  = (0 == nColumns || 0 != (nColumns % 2)) ?
1647                                             false :
1648                                             ((const SvxViewLayoutItem *)pItem)->IsBookMode();
1649 
1650                     SetViewLayout( nColumns, bBookMode );
1651                 }
1652 
1653                 bUp = sal_True;
1654                 rReq.Done();
1655 
1656                 InvalidateRulerPos();
1657             }
1658         }
1659         break;
1660 
1661         case SID_ATTR_ZOOMSLIDER:
1662         {
1663             if ( pArgs && ( ( GetDocShell()->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) || !GetDocShell()->IsInPlaceActive() ) )
1664             {
1665                 // PAGES01
1666                 if ( SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, sal_True, &pItem ))
1667                 {
1668                     const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue();
1669                     SetZoom( SVX_ZOOM_PERCENT, nCurrentZoom );
1670                 }
1671 
1672                 bUp = sal_True;
1673                 rReq.Done();
1674             }
1675         }
1676         break;
1677 
1678         case SID_ATTR_SIZE:
1679         {
1680             sal_uLong nId = FN_INSERT_FIELD;
1681             if( rSh.IsCrsrInTbl() )
1682                 nId = FN_FORMAT_TABLE_DLG;
1683             else if( rSh.GetCurTOX() )
1684                 nId = FN_INSERT_MULTI_TOX;
1685             else if( rSh.GetCurrSection() )
1686                 nId = FN_EDIT_REGION;
1687             else
1688             {
1689                 const SwNumRule* pNumRule = rSh.GetCurNumRule();
1690                 if( pNumRule )  // Cursor in Numerierung
1691                 {
1692                     if( pNumRule->IsAutoRule() )
1693                         nId = FN_NUMBER_BULLETS;
1694                     else
1695                     {
1696                         // Dialog vom Gestalter starten ;-)
1697                         nId = 0;
1698                     }
1699                 }
1700                 else if( rSh.IsFrmSelected() )
1701                     nId = FN_FORMAT_FRAME_DLG;
1702                 else if( rSh.IsObjSelected() )
1703                     nId = SID_ATTR_TRANSFORM;
1704             }
1705             if( nId )
1706                 GetViewFrame()->GetDispatcher()->Execute(
1707                     static_cast< sal_uInt16 >( nId ), SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
1708         }
1709         break;
1710 
1711         case FN_STAT_SELMODE:
1712         {
1713             if ( pArgs )
1714             {
1715                 if (SFX_ITEM_SET == pArgs->GetItemState( nWhich, sal_True, &pItem))
1716                 {
1717                     switch ( ((const SfxUInt16Item *)pItem)->GetValue() )
1718                     {
1719                         case 0: rSh.EnterStdMode(); break;
1720                         case 1: rSh.EnterExtMode(); break;
1721                         case 2: rSh.EnterAddMode(); break;
1722                         case 3: rSh.EnterBlockMode(); break;
1723                     }
1724                 }
1725             }
1726             else
1727             {
1728 
1729                 if( !rSh.IsAddMode() && !rSh.IsExtMode() && !rSh.IsBlockMode() )
1730                     rSh.ToggleExtMode();
1731                 else if ( rSh.IsExtMode() )
1732                 {
1733                     rSh.ToggleExtMode();
1734                     rSh.ToggleAddMode();
1735                 }
1736                 else if ( rSh.IsAddMode() )
1737                 {
1738                     rSh.ToggleAddMode();
1739                     rSh.ToggleBlockMode();
1740                 }
1741                 else
1742                     rSh.ToggleBlockMode();
1743             }
1744             bUp = sal_True;
1745             break;
1746         }
1747         case FN_SET_ADD_MODE:
1748             rSh.ToggleAddMode();
1749             nWhich = FN_STAT_SELMODE;
1750             bUp = sal_True;
1751         break;
1752         case FN_SET_BLOCK_MODE:
1753             rSh.ToggleBlockMode();
1754             nWhich = FN_STAT_SELMODE;
1755             bUp = sal_True;
1756         break;
1757         case FN_SET_EXT_MODE:
1758             rSh.ToggleExtMode();
1759             nWhich = FN_STAT_SELMODE;
1760             bUp = sal_True;
1761         break;
1762         case SID_ATTR_INSERT:
1763             SwPostItMgr* pMgr = GetPostItMgr();
1764             if ( pMgr && pMgr->HasActiveSidebarWin() )
1765             {
1766                 pMgr->ToggleInsModeOnActiveSidebarWin();
1767             }
1768             else
1769                 rSh.ToggleInsMode();
1770             bUp = sal_True;
1771         break;
1772 
1773     }
1774     if ( bUp )
1775     {
1776         SfxBindings &rBnd = GetViewFrame()->GetBindings();
1777         rBnd.Invalidate(nWhich);
1778         rBnd.Update(nWhich);
1779     }
1780 }
1781 
1782 void SwView::InsFrmMode(sal_uInt16 nCols)
1783 {
1784     if ( pWrtShell->HasWholeTabSelection() )
1785     {
1786         SwFlyFrmAttrMgr aMgr( sal_True, pWrtShell, FRMMGR_TYPE_TEXT );
1787 
1788         const SwFrmFmt &rPageFmt =
1789                 pWrtShell->GetPageDesc(pWrtShell->GetCurPageDesc()).GetMaster();
1790         SwTwips lWidth = rPageFmt.GetFrmSize().GetWidth();
1791         const SvxLRSpaceItem &rLR = rPageFmt.GetLRSpace();
1792         lWidth -= rLR.GetLeft() + rLR.GetRight();
1793         aMgr.SetSize(Size(lWidth, aMgr.GetSize().Height()));
1794         if(nCols > 1)
1795         {
1796             SwFmtCol aCol;
1797             aCol.Init( nCols, aCol.GetGutterWidth(), aCol.GetWishWidth() );
1798             aMgr.SetCol( aCol );
1799         }
1800         aMgr.InsertFlyFrm();
1801     }
1802     else
1803         GetEditWin().InsFrm(nCols);
1804 }
1805 
1806 /*--------------------------------------------------------------------
1807     Beschreibung:   Links bearbeiten
1808  --------------------------------------------------------------------*/
1809 
1810 void SwView::EditLinkDlg()
1811 {
1812     sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
1813     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1814     SfxAbstractLinksDialog* pDlg = pFact->CreateLinksDialog( &GetViewFrame()->GetWindow(), &GetWrtShell().GetLinkManager(), bWeb );
1815     if ( pDlg )
1816     {
1817         pDlg->Execute();
1818         delete pDlg;
1819     }
1820 /*
1821     SwLinkDlg* pDlg = new SwLinkDlg(GetFrameWindow());
1822     pDlg->SetShell(&GetWrtShell());
1823     pDlg->Execute();
1824 
1825     DELETEZ(pDlg);
1826 */
1827 }
1828 
1829 sal_Bool SwView::JumpToSwMark( const String& rMark )
1830 {
1831     sal_Bool bRet = sal_False;
1832     if( rMark.Len() )
1833     {
1834         // wir wollen den Bookmark aber am oberen Rand haben
1835         sal_Bool bSaveCC = IsCrsrAtCenter();
1836         sal_Bool bSaveCT = IsCrsrAtTop();
1837         SetCrsrAtTop( sal_True );
1838 
1839         //JP 27.04.98: Bug 49786
1840         // Damit in FrameSet auch gescrollt werden kann, muss die
1841         // entsprechende Shell auch das Focus-Flag gesetzt haben!
1842         sal_Bool bHasShFocus = pWrtShell->HasShFcs();
1843         if( !bHasShFocus )
1844             pWrtShell->ShGetFcs( sal_False );
1845 
1846         const SwFmtINetFmt* pINet;
1847         String sCmp, sMark( INetURLObject::decode( rMark, INET_HEX_ESCAPE,
1848                                         INetURLObject::DECODE_WITH_CHARSET,
1849                                         RTL_TEXTENCODING_UTF8 ));
1850 
1851         xub_StrLen nLastPos, nPos = sMark.Search( cMarkSeperator );
1852         if( STRING_NOTFOUND != nPos )
1853             while( STRING_NOTFOUND != ( nLastPos =
1854                 sMark.Search( cMarkSeperator, nPos + 1 )) )
1855                 nPos = nLastPos;
1856 
1857         IDocumentMarkAccess::const_iterator_t ppMark;
1858         IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess();
1859         if( STRING_NOTFOUND != nPos &&
1860             ( sCmp = sMark.Copy( nPos + 1 ) ).EraseAllChars().Len() )
1861         {
1862             String sName( sMark.Copy( 0, nPos ) );
1863             sCmp.ToLowerAscii();
1864             FlyCntType eFlyType = FLYCNTTYPE_ALL;
1865 
1866             if( COMPARE_EQUAL == sCmp.CompareToAscii( pMarkToRegion ) )
1867             {
1868                 pWrtShell->EnterStdMode();
1869                 bRet = pWrtShell->GotoRegion( sName );
1870             }
1871             else if( COMPARE_EQUAL == sCmp.CompareToAscii( pMarkToOutline ) )
1872             {
1873                 pWrtShell->EnterStdMode();
1874                 bRet = pWrtShell->GotoOutline( sName );
1875             }
1876             else if( COMPARE_EQUAL == sCmp.CompareToAscii( pMarkToFrame ) )
1877                 eFlyType = FLYCNTTYPE_FRM;
1878             else if( COMPARE_EQUAL == sCmp.CompareToAscii( pMarkToGraphic ) )
1879                 eFlyType = FLYCNTTYPE_GRF;
1880             else if( COMPARE_EQUAL == sCmp.CompareToAscii( pMarkToOLE ) )
1881                 eFlyType = FLYCNTTYPE_OLE;
1882             else if( COMPARE_EQUAL == sCmp.CompareToAscii( pMarkToTable ) )
1883             {
1884                 pWrtShell->EnterStdMode();
1885                 bRet = pWrtShell->GotoTable( sName );
1886             }
1887             else if( COMPARE_EQUAL == sCmp.CompareToAscii( pMarkToText ) )
1888             {
1889                 // Normale Textsuche
1890                 pWrtShell->EnterStdMode();
1891 
1892                 SearchOptions aSearchOpt(
1893                                     SearchAlgorithms_ABSOLUTE, 0,
1894                                     sName, rtl::OUString(),
1895                                     SvxCreateLocale( LANGUAGE_SYSTEM ),
1896                                     0,0,0,
1897                                     TransliterationModules_IGNORE_CASE );
1898 
1899                 //todo/mba: assuming that notes shouldn't be searched
1900                 sal_Bool bSearchInNotes = sal_False;
1901                 if( pWrtShell->SearchPattern( aSearchOpt, bSearchInNotes, DOCPOS_START, DOCPOS_END ))
1902                 {
1903                     pWrtShell->EnterStdMode();      // Selektion wieder aufheben
1904                     bRet = sal_True;
1905                 }
1906             }
1907             else if( pMarkAccess->getMarksEnd() != (ppMark = pMarkAccess->findMark(sMark)) )
1908                 pWrtShell->GotoMark( ppMark->get(), sal_False, sal_True ), bRet = sal_True;
1909             else if( 0 != ( pINet = pWrtShell->FindINetAttr( sMark ) ))
1910                 bRet = pWrtShell->GotoINetAttr( *pINet->GetTxtINetFmt() );
1911 
1912             // fuer alle Arten von Flys
1913             if( FLYCNTTYPE_ALL != eFlyType && pWrtShell->GotoFly( sName, eFlyType ))
1914             {
1915                 bRet = sal_True;
1916                 if( FLYCNTTYPE_FRM == eFlyType )
1917                 {
1918                     // TextFrames: Cursor in den Frame setzen
1919                     pWrtShell->UnSelectFrm();
1920                     pWrtShell->LeaveSelFrmMode();
1921                 }
1922                 else
1923                 {
1924                     pWrtShell->HideCrsr();
1925                     pWrtShell->EnterSelFrmMode();
1926                 }
1927             }
1928         }
1929         else if( pMarkAccess->getMarksEnd() != (ppMark = pMarkAccess->findMark(sMark)))
1930             pWrtShell->GotoMark( ppMark->get(), sal_False, sal_True ), bRet = sal_True;
1931         else if( 0 != ( pINet = pWrtShell->FindINetAttr( sMark ) ))
1932             bRet = pWrtShell->GotoINetAttr( *pINet->GetTxtINetFmt() );
1933 
1934         // #b6330459# make selection visible later
1935         if ( aVisArea.IsEmpty() )
1936             bMakeSelectionVisible = sal_True;
1937 
1938         // ViewStatus wieder zurueck setzen
1939         SetCrsrAtTop( bSaveCT, bSaveCC );
1940 
1941         if( !bHasShFocus )
1942             pWrtShell->ShLooseFcs();
1943     }
1944     return bRet;
1945 }
1946 
1947 // #i67305, #1367991: Undo after insert from file:
1948 // Undo "Insert form file" crashes with documents imported from binary filter (.sdw) => disabled
1949 // Undo "Insert form file" crashes with (.odt) documents crashes if these documents contains
1950 // page styles with active header/footer => disabled for those documents
1951 
1952 sal_uInt16 lcl_PageDescWithHeader( const SwDoc& rDoc )
1953 {
1954     sal_uInt16 nRet = 0;
1955     sal_uInt16 nCnt = rDoc.GetPageDescCnt();
1956     for( sal_uInt16 i = 0; i < nCnt; ++i )
1957     {
1958         const SwPageDesc& rPageDesc = rDoc.GetPageDesc( i );
1959         const SwFrmFmt& rMaster = rPageDesc.GetMaster();
1960         const SfxPoolItem* pItem;
1961         if( ( SFX_ITEM_SET == rMaster.GetAttrSet().GetItemState( RES_HEADER, sal_False, &pItem ) &&
1962               ((SwFmtHeader*)pItem)->IsActive() ) ||
1963             ( SFX_ITEM_SET == rMaster.GetAttrSet().GetItemState( RES_FOOTER, sal_False, &pItem )  &&
1964               ((SwFmtFooter*)pItem)->IsActive()) )
1965             ++nRet;
1966     }
1967     return nRet; // number of page styles with active header/footer
1968 }
1969 
1970 /*--------------------------------------------------------------------
1971     Beschreibung:   Links bearbeiten
1972  --------------------------------------------------------------------*/
1973 
1974 void SwView::ExecuteInsertDoc( SfxRequest& rRequest, const SfxPoolItem* pItem )
1975 {
1976     pViewImpl->InitRequest( rRequest );
1977     pViewImpl->SetParam( pItem ? 1 : 0 );
1978     sal_uInt16 nSlot = rRequest.GetSlot();
1979 
1980     if ( !pItem )
1981     {
1982         String sEmpty;
1983         InsertDoc( nSlot, sEmpty, sEmpty );
1984     }
1985     else
1986     {
1987         String sFile, sFilter;
1988         sFile = ( (const SfxStringItem *)pItem )->GetValue();
1989         if ( SFX_ITEM_SET == rRequest.GetArgs()->GetItemState( FN_PARAM_1, sal_True, &pItem ) )
1990             sFilter = ( (const SfxStringItem *)pItem )->GetValue();
1991 
1992         bool bHasFileName = ( sFile.Len() > 0 );
1993         long nFound = InsertDoc( nSlot, sFile, sFilter );
1994 
1995         if ( bHasFileName )
1996         {
1997             rRequest.SetReturnValue( SfxBoolItem( nSlot, nFound != -1 ) );
1998             rRequest.Done();
1999         }
2000     }
2001 }
2002 
2003 long SwView::InsertDoc( sal_uInt16 nSlotId, const String& rFileName, const String& rFilterName, sal_Int16 nVersion )
2004 {
2005     SfxMedium* pMed = 0;
2006     SwDocShell* pDocSh = GetDocShell();
2007 
2008     if( rFileName.Len() )
2009     {
2010         SfxObjectFactory& rFact = pDocSh->GetFactory();
2011         const SfxFilter* pFilter = rFact.GetFilterContainer()->GetFilter4FilterName( rFilterName );
2012         if ( !pFilter )
2013         {
2014             pMed = new SfxMedium(rFileName, STREAM_READ, sal_True, 0, 0 );
2015             SfxFilterMatcher aMatcher( rFact.GetFilterContainer()->GetName() );
2016             pMed->UseInteractionHandler( sal_True );
2017             ErrCode nErr = aMatcher.GuessFilter( *pMed, &pFilter, sal_False );
2018             if ( nErr )
2019                 DELETEZ(pMed);
2020             else
2021                 pMed->SetFilter( pFilter );
2022         }
2023         else
2024             pMed = new SfxMedium(rFileName, STREAM_READ, sal_True, pFilter, 0);
2025     }
2026     else
2027     {
2028         String sFactory = String::CreateFromAscii( pDocSh->GetFactory().GetShortName() );
2029         pViewImpl->StartDocumentInserter( sFactory, LINK( this, SwView, DialogClosedHdl ) );
2030         return -1;
2031     }
2032 
2033     if( !pMed )
2034         return -1;
2035 
2036     return InsertMedium( nSlotId, pMed, nVersion );
2037 }
2038 
2039 long SwView::InsertMedium( sal_uInt16 nSlotId, SfxMedium* pMedium, sal_Int16 nVersion )
2040 {
2041     sal_Bool bInsert = sal_False, bCompare = sal_False, bMerge = sal_False;
2042     long nFound = 0;
2043     SwDocShell* pDocSh = GetDocShell();
2044 
2045     switch( nSlotId )
2046     {
2047         case SID_DOCUMENT_MERGE:        bMerge = sal_True;      break;
2048         case SID_DOCUMENT_COMPARE:      bCompare = sal_True;    break;
2049         case SID_INSERTDOC:             bInsert = sal_True;     break;
2050 
2051         default:
2052             ASSERT( !this, "Unbekannte SlotId!" );
2053             bInsert = sal_True;
2054             nSlotId = SID_INSERTDOC;
2055             break;
2056     }
2057 
2058     if( bInsert )
2059     {
2060         uno::Reference< frame::XDispatchRecorder > xRecorder =
2061                 GetViewFrame()->GetBindings().GetRecorder();
2062         if ( xRecorder.is() )
2063         {
2064             SfxRequest aRequest(GetViewFrame(), SID_INSERTDOC);
2065             aRequest.AppendItem(SfxStringItem(SID_INSERTDOC, pMedium->GetOrigURL()));
2066             if(pMedium->GetFilter())
2067             aRequest.AppendItem(SfxStringItem(FN_PARAM_1, pMedium->GetFilter()->GetName()));
2068             aRequest.Done();
2069         }
2070 
2071         SfxObjectShellRef aRef( pDocSh );
2072 
2073         sal_uInt32 nError = SfxObjectShell::HandleFilter( pMedium, pDocSh );
2074         // #i16722# aborted?
2075         if(nError != ERRCODE_NONE)
2076         {
2077             delete pMedium;
2078             return -1;
2079         }
2080         pDocSh->RegisterTransfer( *pMedium );
2081         pMedium->DownLoad();    // ggfs. den DownLoad anstossen
2082         if( aRef.Is() && 1 < aRef->GetRefCount() )  // noch gueltige Ref?
2083         {
2084             SwReader* pRdr;
2085             Reader *pRead = pDocSh->StartConvertFrom( *pMedium, &pRdr, pWrtShell );
2086             if( pRead ||
2087                 (pMedium->GetFilter()->GetFilterFlags() & SFX_FILTER_STARONEFILTER) != 0 )
2088             {
2089                 sal_uInt16 nUndoCheck = 0;
2090                 SwDoc *pDoc = pDocSh->GetDoc();
2091                 if( pRead && pDocSh->GetDoc() )
2092                     nUndoCheck = lcl_PageDescWithHeader( *pDoc );
2093                 sal_uLong nErrno;
2094                 {   //Scope for SwWait-Object, to be able to execute slots
2095                     //outside this scope.
2096                     SwWait aWait( *GetDocShell(), sal_True );
2097                     pWrtShell->StartAllAction();
2098                     if ( pWrtShell->HasSelection() )
2099                         pWrtShell->DelRight();      // Selektionen loeschen
2100                     if( pRead )
2101                     {
2102                         nErrno = pRdr->Read( *pRead );  // und Dokument einfuegen
2103                         delete pRdr;
2104                     }
2105                     else
2106                     {
2107                         ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
2108                         nErrno = pDocSh->InsertFrom( *pMedium ) ? 0 : ERR_SWG_READ_ERROR;
2109                     }
2110 
2111                 }
2112 
2113                 // ggfs. alle Verzeichnisse updaten:
2114                 if( pWrtShell->IsUpdateTOX() )
2115                 {
2116                     SfxRequest aReq( FN_UPDATE_TOX, SFX_CALLMODE_SLOT, GetPool() );
2117                     Execute( aReq );
2118                     pWrtShell->SetUpdateTOX( sal_False );       // wieder zurueck setzen
2119                 }
2120 
2121                 if( pDoc )
2122                 { // Disable Undo for .sdw (136991) or
2123                   // if the number of page styles with header/footer has changed (#i67305)
2124                     if( !pRead || nUndoCheck != lcl_PageDescWithHeader( *pDoc ) )
2125                     {
2126                         pDoc->GetIDocumentUndoRedo().DelAllUndoObj();
2127                     }
2128                 }
2129 
2130                 pWrtShell->EndAllAction();
2131                 if( nErrno )
2132                 {
2133                     ErrorHandler::HandleError( nErrno );
2134                     nFound = IsError( nErrno ) ? -1 : 0;
2135                 }
2136                 else
2137                     nFound = 0;
2138             }
2139         }
2140     }
2141     else
2142     {
2143         SfxObjectShellRef xDocSh;
2144         SfxObjectShellLock xLockRef;
2145 
2146 extern int lcl_FindDocShell( SfxObjectShellRef& xDocSh, SfxObjectShellLock& xLockRef,
2147                             const String& rFileName, const String& rPasswd,
2148                             String& rFilter, sal_Int16 nVersion,
2149                             SwDocShell* pDestSh );
2150 
2151         String sFltNm;
2152         int nRet = lcl_FindDocShell( xDocSh, xLockRef, pMedium->GetName(), aEmptyStr,
2153                                     sFltNm, nVersion, pDocSh );
2154         if( nRet )
2155         {
2156             SwWait aWait( *GetDocShell(), sal_True );
2157             pWrtShell->StartAllAction();
2158 
2159             pWrtShell->EnterStdMode();          // Selektionen loeschen
2160 
2161             if( bCompare )
2162                 nFound = pWrtShell->CompareDoc( *((SwDocShell*)&xDocSh)->GetDoc() );
2163             else
2164                 nFound = pWrtShell->MergeDoc( *((SwDocShell*)&xDocSh)->GetDoc() );
2165 
2166             pWrtShell->EndAllAction();
2167 
2168             if (!bCompare && !nFound)
2169             {
2170                 Window* pWin = &GetEditWin();
2171                 InfoBox(pWin, SW_RES(MSG_NO_MERGE_ENTRY)).Execute();
2172             }
2173         }
2174         if( 2 == nRet && xDocSh.Is() )
2175             xDocSh->DoClose();
2176     }
2177 
2178     delete pMedium;
2179     return nFound;
2180 }
2181 /* -----------------05.02.2003 12:06-----------------
2182  *
2183  * --------------------------------------------------*/
2184 void SwView::EnableMailMerge(sal_Bool bEnable )
2185 {
2186     bInMailMerge = bEnable;
2187     SfxBindings& rBind = GetViewFrame()->GetBindings();
2188     rBind.Invalidate(FN_INSERT_FIELD_DATA_ONLY);
2189     rBind.Update(FN_INSERT_FIELD_DATA_ONLY);
2190 }
2191 /*
2192 */
2193 namespace
2194 {
2195     sal_Bool lcl_NeedAdditionalDataSource( const uno::Reference< XNameAccess >& _rDatasourceContext )
2196     {
2197         Sequence < OUString > aNames = _rDatasourceContext->getElementNames();
2198 
2199         return  (   !aNames.getLength()
2200                 ||  (   ( 1 == aNames.getLength() )
2201                     &&  aNames.getConstArray()[0] == SW_MOD()->GetDBConfig()->GetBibliographySource().sDataSource
2202                     )
2203                 );
2204     }
2205 }
2206 
2207 /* -----------------27.11.2002 12:12-----------------
2208  *
2209  * --------------------------------------------------*/
2210 
2211 class SwMergeSourceWarningBox_Impl : public ModalDialog
2212 {
2213         FixedInfo       aMessageFI;
2214         OKButton        aOK;
2215         CancelButton    aCancel;
2216 
2217         FixedImage      aWarnImage;
2218     public:
2219         SwMergeSourceWarningBox_Impl( Window* pParent ) :
2220             ModalDialog( pParent, SW_RES( DLG_MERGE_SOURCE_UNAVAILABLE   ) ),
2221                     aMessageFI( this, SW_RES( ST_MERGE_SOURCE_UNAVAILABLE ) ),
2222                     aOK(        this, SW_RES( PB_MERGE_OK                 ) ),
2223                     aCancel(    this, SW_RES( PB_MERGE_CANCEL             ) ),
2224                     aWarnImage( this, SW_RES( IMG_MERGE                   ) )
2225                     {
2226                         FreeResource();
2227                         SetText( Application::GetDisplayName() );
2228                         const Image& rImg = WarningBox::GetStandardImage();
2229                         aWarnImage.SetImage( rImg );
2230                         Size aImageSize( rImg.GetSizePixel() );
2231                         aImageSize.Width()  += 4;
2232                         aImageSize.Height() += 4;
2233                         aWarnImage.SetSizePixel( aImageSize );
2234 
2235                         aImageSize.Width() += aWarnImage.GetPosPixel().X();
2236                         Size aSz(GetSizePixel());
2237                         aSz.Width() += aImageSize.Width();
2238                         SetSizePixel(aSz);
2239 
2240                         Point aPos(aMessageFI.GetPosPixel());
2241                         aPos.X() += aImageSize.Width();
2242                         aMessageFI.SetPosPixel( aPos );
2243 
2244                         aPos = aOK.GetPosPixel();
2245                         aPos.X() += aImageSize.Width();
2246                         aOK.SetPosPixel( aPos );
2247                         aPos = aCancel.GetPosPixel();
2248                         aPos.X() += aImageSize.Width();
2249                         aCancel.SetPosPixel( aPos );
2250 
2251                     }
2252 
2253         String          GetMessText() const { return aMessageFI.GetText(); }
2254         void            SetMessText( const String& rText ) { aMessageFI.SetText( rText ); }
2255 };
2256 
2257 
2258 
2259 
2260 void SwView::GenerateFormLetter(sal_Bool bUseCurrentDocument)
2261 {
2262     if(bUseCurrentDocument)
2263     {
2264         if(!GetWrtShell().IsAnyDatabaseFieldInDoc())
2265         {
2266             //check availability of data sources (except biblio source)
2267             uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
2268             uno::Reference<XNameAccess>  xDBContext;
2269             if( xMgr.is() )
2270             {
2271                 uno::Reference<XInterface> xInstance = xMgr->createInstance(
2272                     OUString::createFromAscii( "com.sun.star.sdb.DatabaseContext" ));
2273                 xDBContext = uno::Reference<XNameAccess>(xInstance, UNO_QUERY) ;
2274             }
2275             if(!xDBContext.is())
2276                 return ;
2277             sal_Bool bCallAddressPilot = sal_False;
2278             if ( lcl_NeedAdditionalDataSource( xDBContext ) )
2279             {
2280                 // no data sources are available - create a new one
2281                 WarningBox aWarning(
2282                             &GetViewFrame()->GetWindow(),
2283                             SW_RES(MSG_DATA_SOURCES_UNAVAILABLE));
2284                 // no cancel allowed
2285                 if ( RET_OK != aWarning.Execute() )
2286                     return;
2287                 bCallAddressPilot = sal_True;
2288             }
2289             else
2290             {
2291                 //take an existing data source or create a new one?
2292                     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2293                     DBG_ASSERT(pFact, "Dialogdiet fail!");
2294                     AbstractMailMergeFieldConnectionsDlg* pConnectionsDlg = pFact->CreateMailMergeFieldConnectionsDlg(
2295                                                         DLG_MERGE_FIELD_CONNECTIONS,
2296                                                         &GetViewFrame()->GetWindow());
2297                     DBG_ASSERT(pConnectionsDlg, "Dialogdiet fail!");
2298                     if(RET_OK == pConnectionsDlg->Execute())
2299                         bCallAddressPilot = !pConnectionsDlg->IsUseExistingConnections();
2300                     else
2301                         return;
2302 
2303             }
2304             if(bCallAddressPilot)
2305             {
2306                 GetViewFrame()->GetDispatcher()->Execute(
2307                                 SID_ADDRESS_DATA_SOURCE, SFX_CALLMODE_SYNCHRON);
2308                 if ( lcl_NeedAdditionalDataSource( xDBContext ) )
2309                     // no additional data source has been created
2310                     // -> assume that the user has cancelled the pilot
2311                     return;
2312             }
2313 
2314             //call insert fields with database field page available, only
2315             SfxViewFrame* pVFrame = GetViewFrame();
2316             //at first hide the default field dialog if currently visible
2317             pVFrame->SetChildWindow(FN_INSERT_FIELD, sal_False);
2318             //enable the status of the db field dialog - it is disabled in the status method
2319             //to prevent creation of the dialog without mail merge active
2320             EnableMailMerge();
2321             //then show the "Data base only" field dialog
2322             SfxBoolItem aOn(FN_INSERT_FIELD_DATA_ONLY, sal_True);
2323             pVFrame->GetDispatcher()->Execute(FN_INSERT_FIELD_DATA_ONLY,
2324                                                 SFX_CALLMODE_SYNCHRON, &aOn, 0L);
2325             return;
2326         }
2327         else
2328         {
2329             // check whether the
2330             String sSource;
2331             if(!GetWrtShell().IsFieldDataSourceAvailable(sSource))
2332             {
2333                 SwMergeSourceWarningBox_Impl aWarning( &GetViewFrame()->GetWindow());
2334                 String sTmp(aWarning.GetMessText());
2335                 sTmp.SearchAndReplaceAscii("%1", sSource);
2336                 aWarning.SetMessText(sTmp);
2337                 if(RET_OK == aWarning.Execute())
2338                 {
2339                     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
2340                     if ( pFact )
2341                     {
2342                         VclAbstractDialog* pDlg = pFact->CreateVclDialog( NULL, SID_OPTIONS_DATABASES );
2343                         pDlg->Execute();
2344                         delete pDlg;
2345                     }
2346                 }
2347                 return ;
2348             }
2349         }
2350         SwNewDBMgr* pNewDBMgr = GetWrtShell().GetNewDBMgr();
2351 
2352         SwDBData aData;
2353         SwWrtShell &rSh = GetWrtShell();
2354         aData = rSh.GetDBData();
2355         rSh.EnterStdMode(); // Wechsel in Textshell erzwingen; ist fuer
2356                             // das Mischen von DB-Feldern notwendig.
2357         AttrChangedNotify( &rSh );
2358         pNewDBMgr->SetMergeType( DBMGR_MERGE );
2359 
2360         if (pNewDBMgr)
2361         {
2362             Sequence<PropertyValue> aProperties(3);
2363             PropertyValue* pValues = aProperties.getArray();
2364             pValues[0].Name = C2U("DataSourceName");
2365             pValues[1].Name = C2U("Command");
2366             pValues[2].Name = C2U("CommandType");
2367             pValues[0].Value <<= aData.sDataSource;
2368             pValues[1].Value <<= aData.sCommand;
2369             pValues[2].Value <<= aData.nCommandType;
2370             pNewDBMgr->ExecuteFormLetter(GetWrtShell(), aProperties, sal_True);
2371         }
2372     }
2373     else
2374     {
2375         //call documents and template dialog
2376         SfxApplication* pSfxApp = SFX_APP();
2377         Window* pTopWin = pSfxApp->GetTopWindow();
2378         SvtDocumentTemplateDialog* pDocTemplDlg = new SvtDocumentTemplateDialog( pTopWin );
2379         pDocTemplDlg->SelectTemplateFolder();
2380 
2381         int nRet = pDocTemplDlg->Execute();
2382         sal_Bool bNewWin = sal_False;
2383         if ( nRet == RET_OK )
2384         {
2385             if ( pTopWin != pSfxApp->GetTopWindow() )
2386             {
2387                 // the dialogue opens a document -> a new TopWindow appears
2388                 pTopWin = pSfxApp->GetTopWindow();
2389                 bNewWin = sal_True;
2390             }
2391         }
2392 
2393         delete pDocTemplDlg;
2394         if ( bNewWin )
2395             // after the destruction of the dialogue its parent comes to top,
2396             // but we want that the new document is on top
2397             pTopWin->ToTop();
2398 
2399 //        return;
2400     }
2401 }
2402 
2403 IMPL_LINK( SwView, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
2404 {
2405     if ( ERRCODE_NONE == _pFileDlg->GetError() )
2406     {
2407         SfxMedium* pMed = pViewImpl->CreateMedium();
2408         if ( pMed )
2409         {
2410             sal_uInt16 nSlot = pViewImpl->GetRequest()->GetSlot();
2411             long nFound = InsertMedium( nSlot, pMed, pViewImpl->GetParam() );
2412 
2413             if ( SID_INSERTDOC == nSlot )
2414             {
2415                 if ( pViewImpl->GetParam() == 0 )
2416                 {
2417                     pViewImpl->GetRequest()->SetReturnValue( SfxBoolItem( nSlot, nFound != -1 ) );
2418                     pViewImpl->GetRequest()->Ignore();
2419                 }
2420                 else
2421                 {
2422                     pViewImpl->GetRequest()->SetReturnValue( SfxBoolItem( nSlot, nFound != -1 ) );
2423                     pViewImpl->GetRequest()->Done();
2424                 }
2425             }
2426             else if ( SID_DOCUMENT_COMPARE == nSlot || SID_DOCUMENT_MERGE == nSlot )
2427             {
2428                 pViewImpl->GetRequest()->SetReturnValue( SfxInt32Item( nSlot, nFound ) );
2429 
2430                 if ( nFound > 0 ) // Redline-Browser anzeigen
2431                 {
2432                     SfxViewFrame* pVFrame = GetViewFrame();
2433                     pVFrame->ShowChildWindow(FN_REDLINE_ACCEPT);
2434 
2435                     // RedlineDlg neu initialisieren
2436                     sal_uInt16 nId = SwRedlineAcceptChild::GetChildWindowId();
2437                     SwRedlineAcceptChild* pRed = (SwRedlineAcceptChild*)pVFrame->GetChildWindow( nId );
2438                     if ( pRed )
2439                         pRed->ReInitDlg( GetDocShell() );
2440                 }
2441             }
2442         }
2443     }
2444     return 0;
2445 }
2446 
2447 void SwView::ExecuteScan( SfxRequest& rReq )
2448 {
2449     if (pViewImpl)
2450         pViewImpl->ExecuteScan(rReq) ;
2451 }
2452 
2453