update dev300-m58
[ooovba.git] / sw / source / ui / wrtsh / wrtsh2.cxx
blob093f08417ea623284cf55e280fffe169139b5cdc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wrtsh2.cxx,v $
10 * $Revision: 1.33 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <hintids.hxx> // define ITEMIDs
35 #include <svtools/macitem.hxx>
36 #include <sfx2/frame.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <svtools/urihelper.hxx>
39 #include <svtools/eitem.hxx>
40 #include <svtools/stritem.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <sfx2/fcontnr.hxx>
43 #include <sfx2/dispatch.hxx>
44 #include <sfx2/linkmgr.hxx>
45 #include <fmtinfmt.hxx>
46 #include <frmatr.hxx>
47 #include <swtypes.hxx> // SET_CURR_SHELL
48 #include <wrtsh.hxx>
49 #include <docsh.hxx>
50 #include <fldbas.hxx> // Felder
51 #include <expfld.hxx>
52 #include <ddefld.hxx>
53 #include <docufld.hxx>
54 #include <reffld.hxx>
55 #include <swundo.hxx>
56 #include <doc.hxx>
57 #include <viewopt.hxx> // SwViewOptions
58 #include <frmfmt.hxx> // fuer UpdateTable
59 #include <swtable.hxx> // fuer UpdateTable
60 #include <mdiexp.hxx>
61 #include <view.hxx>
62 #include <swevent.hxx>
63 #include <poolfmt.hxx>
64 #include <section.hxx>
65 #include <navicont.hxx>
66 #include <navipi.hxx>
67 #include <crsskip.hxx>
68 #include <txtinet.hxx>
69 #include <cmdid.h>
70 #include <wrtsh.hrc>
71 #include "swabstdlg.hxx"
72 #include "fldui.hrc"
74 #include <undobj.hxx>
76 #include <com/sun/star/document/XDocumentProperties.hpp>
77 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
80 /*------------------------------------------------------------------------
81 Beschreibung:
82 ------------------------------------------------------------------------*/
84 void SwWrtShell::Insert(SwField &rFld)
86 ResetCursorStack();
87 if(!_CanInsert())
88 return;
89 StartAllAction();
91 SwRewriter aRewriter;
92 aRewriter.AddRule(UNDO_ARG1, rFld.GetDescription());
94 StartUndo(UNDO_INSERT, &aRewriter);
96 if( HasSelection() )
97 DelRight();
99 SwEditShell::Insert(rFld);
100 EndUndo(UNDO_INSERT);
101 EndAllAction();
104 /*--------------------------------------------------------------------
105 Beschreibung: Felder Update anschmeissen
106 --------------------------------------------------------------------*/
110 void SwWrtShell::UpdateInputFlds( SwInputFieldList* pLst, BOOL bOnlyInSel )
112 // ueber die Liste der Eingabefelder gehen und Updaten
113 SwInputFieldList* pTmp = pLst;
114 if( !pTmp )
115 pTmp = new SwInputFieldList( this );
117 if (bOnlyInSel)
118 pTmp->RemoveUnselectedFlds();
120 const USHORT nCnt = pTmp->Count();
121 if(nCnt)
123 pTmp->PushCrsr();
125 BOOL bCancel = FALSE;
126 ByteString aDlgPos;
127 for( USHORT i = 0; i < nCnt && !bCancel; ++i )
129 pTmp->GotoFieldPos( i );
130 SwField* pField = pTmp->GetField( i );
131 if(pField->GetTyp()->Which() == RES_DROPDOWN)
132 bCancel = StartDropDownFldDlg( pField, TRUE, &aDlgPos );
133 else
134 bCancel = StartInputFldDlg( pField, TRUE, 0, &aDlgPos);
136 // Sonst Updatefehler bei Multiselektion:
137 pTmp->GetField( i )->GetTyp()->UpdateFlds();
139 pTmp->PopCrsr();
142 if( !pLst )
143 delete pTmp;
147 /*--------------------------------------------------------------------
148 Beschreibung: EingabeDialog fuer ein bestimmtes Feld starten
149 --------------------------------------------------------------------*/
153 BOOL SwWrtShell::StartInputFldDlg( SwField* pFld, BOOL bNextButton,
154 Window* pParentWin, ByteString* pWindowState )
156 //JP 14.08.96: Bug 30332 - nach Umbau der modularietaet im SFX, muss jetzt
157 // das TopWindow der Application benutzt werden.
158 // SwFldInputDlg* pDlg = new SwFldInputDlg( GetWin(), *this, pFld );
160 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
161 DBG_ASSERT(pFact, "Dialogdiet fail!");
162 AbstractFldInputDlg* pDlg = pFact->CreateFldInputDlg( DLG_FLD_INPUT,
163 pParentWin, *this, pFld, bNextButton);
164 DBG_ASSERT(pDlg, "Dialogdiet fail!");
165 if(pWindowState && pWindowState->Len())
166 pDlg->SetWindowState(*pWindowState);
167 BOOL bRet = RET_CANCEL == pDlg->Execute();
168 if(pWindowState)
169 *pWindowState = pDlg->GetWindowState();
171 delete pDlg;
172 GetWin()->Update();
173 return bRet;
175 /* -----------------17.06.2003 10:18-----------------
177 --------------------------------------------------*/
178 BOOL SwWrtShell::StartDropDownFldDlg(SwField* pFld, BOOL bNextButton, ByteString* pWindowState)
180 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
181 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
183 AbstractDropDownFieldDialog* pDlg = pFact->CreateDropDownFieldDialog( NULL, *this, pFld, DLG_FLD_DROPDOWN ,bNextButton );
184 DBG_ASSERT(pDlg, "Dialogdiet fail!");
185 if(pWindowState && pWindowState->Len())
186 pDlg->SetWindowState(*pWindowState);
187 USHORT nRet = pDlg->Execute();
188 if(pWindowState)
189 *pWindowState = pDlg->GetWindowState();
190 delete pDlg;
191 BOOL bRet = RET_CANCEL == nRet;
192 GetWin()->Update();
193 if(RET_YES == nRet)
195 GetView().GetViewFrame()->GetDispatcher()->Execute(FN_EDIT_FIELD, SFX_CALLMODE_SYNCHRON);
197 return bRet;
200 /*--------------------------------------------------------------------
201 Beschreibung: Verzeichnis einfuegen Selektion loeschen
202 --------------------------------------------------------------------*/
206 void SwWrtShell::InsertTableOf(const SwTOXBase& rTOX, const SfxItemSet* pSet)
208 if(!_CanInsert())
209 return;
211 if(HasSelection())
212 DelRight();
214 SwEditShell::InsertTableOf(rTOX, pSet);
218 /*--------------------------------------------------------------------
219 Beschreibung: Verzeichnis Updaten Selektion loeschen
220 --------------------------------------------------------------------*/
222 BOOL SwWrtShell::UpdateTableOf(const SwTOXBase& rTOX, const SfxItemSet* pSet)
224 BOOL bResult = FALSE;
226 if(_CanInsert())
228 bResult = SwEditShell::UpdateTableOf(rTOX, pSet);
230 if (pSet == NULL)
232 SwDoc * _pDoc = GetDoc();
234 if (_pDoc != NULL)
235 _pDoc->DelAllUndoObj();
239 return bResult;
242 BOOL SwWrtShell::UpdateField( sw::mark::IFieldmark &fieldBM )
244 return SwEditShell::UpdateField(fieldBM);
249 // ein Klick aus das angegebene Feld. Der Cursor steht auf diesem.
250 // Fuehre die vor definierten Aktionen aus.
253 void SwWrtShell::ClickToField( const SwField& rFld )
255 bIsInClickToEdit = TRUE;
256 switch( rFld.GetTyp()->Which() )
258 case RES_JUMPEDITFLD:
260 USHORT nSlotId = 0;
261 switch( rFld.GetFormat() )
263 case JE_FMT_TABLE:
264 nSlotId = FN_INSERT_TABLE;
265 break;
267 case JE_FMT_FRAME:
268 nSlotId = FN_INSERT_FRAME;
269 break;
271 case JE_FMT_GRAPHIC: nSlotId = SID_INSERT_GRAPHIC; break;
272 case JE_FMT_OLE: nSlotId = SID_INSERT_OBJECT; break;
274 // case JE_FMT_TEXT:
277 Right( CRSR_SKIP_CHARS, TRUE, 1, FALSE ); // Feld selektieren
279 if( nSlotId )
281 StartUndo( UNDO_START );
282 //#97295# immediately select the right shell
283 GetView().StopShellTimer();
284 GetView().GetViewFrame()->GetDispatcher()->Execute( nSlotId,
285 SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD );
286 EndUndo( UNDO_END );
289 break;
291 case RES_MACROFLD:
293 const SwMacroField *pFld = (const SwMacroField*)&rFld;
294 String sText( rFld.GetPar2() );
295 String sRet( sText );
296 ExecMacro( pFld->GetSvxMacro(), &sRet );
298 // return Wert veraendert?
299 if( sRet != sText )
301 StartAllAction();
302 ((SwField&)rFld).SetPar2( sRet );
303 ((SwField&)rFld).GetTyp()->UpdateFlds();
304 EndAllAction();
307 break;
309 case RES_GETREFFLD:
310 StartAllAction();
311 SwCrsrShell::GotoRefMark( ((SwGetRefField&)rFld).GetSetRefName(),
312 ((SwGetRefField&)rFld).GetSubType(),
313 ((SwGetRefField&)rFld).GetSeqNo() );
314 EndAllAction();
315 break;
317 case RES_INPUTFLD:
318 StartInputFldDlg( (SwField*)&rFld, FALSE );
319 break;
321 case RES_SETEXPFLD:
322 if( ((SwSetExpField&)rFld).GetInputFlag() )
323 StartInputFldDlg( (SwField*)&rFld, FALSE );
324 break;
325 case RES_DROPDOWN :
326 StartDropDownFldDlg( (SwField*)&rFld, FALSE );
327 break;
330 bIsInClickToEdit = FALSE;
335 void SwWrtShell::ClickToINetAttr( const SwFmtINetFmt& rItem, USHORT nFilter )
337 if( !rItem.GetValue().Len() )
338 return ;
340 bIsInClickToEdit = TRUE;
342 // erstmal das evt. gesetzte ObjectSelect Macro ausfuehren
343 const SvxMacro* pMac = rItem.GetMacro( SFX_EVENT_MOUSECLICK_OBJECT );
344 if( pMac )
346 SwCallMouseEvent aCallEvent;
347 aCallEvent.Set( &rItem );
348 GetDoc()->CallEvent( SFX_EVENT_MOUSECLICK_OBJECT, aCallEvent, FALSE );
351 // damit die Vorlagenumsetzung sofort angezeigt wird
352 ::LoadURL( rItem.GetValue(), this, nFilter, &rItem.GetTargetFrame() );
353 const SwTxtINetFmt* pTxtAttr = rItem.GetTxtINetFmt();
354 if( pTxtAttr )
356 const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisited( true );
357 const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisitedValid( true );
360 bIsInClickToEdit = FALSE;
365 BOOL SwWrtShell::ClickToINetGrf( const Point& rDocPt, USHORT nFilter )
367 BOOL bRet = FALSE;
368 String sURL;
369 String sTargetFrameName;
370 const SwFrmFmt* pFnd = IsURLGrfAtPos( rDocPt, &sURL, &sTargetFrameName );
371 if( pFnd && sURL.Len() )
373 bRet = TRUE;
374 // erstmal das evt. gesetzte ObjectSelect Macro ausfuehren
375 const SvxMacro* pMac = &pFnd->GetMacro().GetMacro( SFX_EVENT_MOUSECLICK_OBJECT );
376 if( pMac )
378 SwCallMouseEvent aCallEvent;
379 aCallEvent.Set( EVENT_OBJECT_URLITEM, pFnd );
380 GetDoc()->CallEvent( SFX_EVENT_MOUSECLICK_OBJECT, aCallEvent, FALSE );
383 ::LoadURL( sURL, this, nFilter, &sTargetFrameName);
385 return bRet;
389 void LoadURL( const String& rURL, ViewShell* pVSh, USHORT nFilter,
390 const String *pTargetFrameName )
392 ASSERT( rURL.Len() && pVSh, "was soll hier geladen werden?" );
393 if( !rURL.Len() || !pVSh )
394 return ;
396 // die Shell kann auch 0 sein !!!!!
397 SwWrtShell *pSh = 0;
398 if ( pVSh && pVSh->ISA(SwCrsrShell) )
400 //Eine CrsrShell ist auch immer eine WrtShell
401 pSh = (SwWrtShell*)pVSh;
403 else
404 return;
406 SwDocShell* pDShell = pSh->GetView().GetDocShell();
407 DBG_ASSERT( pDShell, "No DocShell?!");
408 String sTargetFrame;
409 if( pTargetFrameName && pTargetFrameName->Len() )
410 sTargetFrame = *pTargetFrameName;
411 else if( pDShell ) {
412 using namespace ::com::sun::star;
413 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
414 pDShell->GetModel(), uno::UNO_QUERY_THROW);
415 uno::Reference<document::XDocumentProperties> xDocProps
416 = xDPS->getDocumentProperties();
417 sTargetFrame = xDocProps->getDefaultTarget();
420 String sReferer;
421 if( pDShell && pDShell->GetMedium() )
422 sReferer = pDShell->GetMedium()->GetName();
423 SfxViewFrame* pViewFrm = pSh->GetView().GetViewFrame();
424 SfxFrameItem aView( SID_DOCFRAME, pViewFrm );
425 SfxStringItem aName( SID_FILE_NAME, rURL );
426 SfxStringItem aTargetFrameName( SID_TARGETNAME, sTargetFrame );
427 SfxStringItem aReferer( SID_REFERER, sReferer );
429 SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, FALSE );
430 //#39076# Silent kann lt. SFX entfernt werden.
431 // SfxBoolItem aSilent( SID_SILENT, TRUE );
432 SfxBoolItem aBrowse( SID_BROWSE, TRUE );
434 if( nFilter & URLLOAD_NEWVIEW )
435 aTargetFrameName.SetValue( String::CreateFromAscii("_blank") );
437 const SfxPoolItem* aArr[] = {
438 &aName,
439 &aNewView, /*&aSilent,*/
440 &aReferer,
441 &aView, &aTargetFrameName,
442 &aBrowse,
446 pViewFrm->GetDispatcher()->GetBindings()->Execute( SID_OPENDOC, aArr,
447 SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD );
450 void SwWrtShell::NavigatorPaste( const NaviContentBookmark& rBkmk,
451 const USHORT nAction )
453 if( EXCHG_IN_ACTION_COPY == nAction )
455 // Einfuegen
456 String sURL = rBkmk.GetURL();
457 //handelt es sich um ein Sprung innerhalb des akt. Docs?
458 const SwDocShell* pDocShell = GetView().GetDocShell();
459 if(pDocShell->HasName())
461 const String rName = pDocShell->GetMedium()->GetURLObject().GetURLNoMark();
463 if(COMPARE_EQUAL == sURL.CompareTo(rName, rName.Len()))
464 sURL.Erase(0, rName.Len());
466 SwFmtINetFmt aFmt( sURL, aEmptyStr );
467 InsertURL( aFmt, rBkmk.GetDescription() );
469 else
471 SwSection aSection( FILE_LINK_SECTION, GetUniqueSectionName( 0 ) );
472 String aLinkFile( rBkmk.GetURL().GetToken(0, '#') );
473 aLinkFile += sfx2::cTokenSeperator;
474 aLinkFile += sfx2::cTokenSeperator;
475 aLinkFile += rBkmk.GetURL().GetToken(1, '#');
476 aSection.SetLinkFileName( aLinkFile );
477 aSection.SetProtect( TRUE );
478 const SwSection* pIns = InsertSection( aSection );
479 if( EXCHG_IN_ACTION_MOVE == nAction && pIns )
481 aSection = *pIns;
482 aSection.SetLinkFileName( aEmptyStr );
483 aSection.SetType( CONTENT_SECTION );
484 aSection.SetProtect( FALSE );
486 // the update of content from linked section at time delete
487 // the undostack. Then the change of the section dont create
488 // any undoobject. - BUG 69145
489 BOOL bDoesUndo = DoesUndo();
490 if( UNDO_INSSECTION != GetUndoIds() )
491 DoUndo( FALSE );
492 ChgSection( GetSectionFmtPos( *pIns->GetFmt() ), aSection );
493 DoUndo( bDoesUndo );