merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / wrtsh / wrtsh2.cxx
blob12309648aefbdc1a7f0da5ac31bdc924f6bf2f7c
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 bool bDeleted = false;
97 if( HasSelection() )
99 bDeleted = DelRight() != 0;
102 SwEditShell::Insert2(rFld, bDeleted);
103 EndUndo(UNDO_INSERT);
104 EndAllAction();
107 /*--------------------------------------------------------------------
108 Beschreibung: Felder Update anschmeissen
109 --------------------------------------------------------------------*/
113 void SwWrtShell::UpdateInputFlds( SwInputFieldList* pLst, BOOL bOnlyInSel )
115 // ueber die Liste der Eingabefelder gehen und Updaten
116 SwInputFieldList* pTmp = pLst;
117 if( !pTmp )
118 pTmp = new SwInputFieldList( this );
120 if (bOnlyInSel)
121 pTmp->RemoveUnselectedFlds();
123 const USHORT nCnt = pTmp->Count();
124 if(nCnt)
126 pTmp->PushCrsr();
128 BOOL bCancel = FALSE;
129 ByteString aDlgPos;
130 for( USHORT i = 0; i < nCnt && !bCancel; ++i )
132 pTmp->GotoFieldPos( i );
133 SwField* pField = pTmp->GetField( i );
134 if(pField->GetTyp()->Which() == RES_DROPDOWN)
135 bCancel = StartDropDownFldDlg( pField, TRUE, &aDlgPos );
136 else
137 bCancel = StartInputFldDlg( pField, TRUE, 0, &aDlgPos);
139 // Sonst Updatefehler bei Multiselektion:
140 pTmp->GetField( i )->GetTyp()->UpdateFlds();
142 pTmp->PopCrsr();
145 if( !pLst )
146 delete pTmp;
150 /*--------------------------------------------------------------------
151 Beschreibung: EingabeDialog fuer ein bestimmtes Feld starten
152 --------------------------------------------------------------------*/
156 BOOL SwWrtShell::StartInputFldDlg( SwField* pFld, BOOL bNextButton,
157 Window* pParentWin, ByteString* pWindowState )
159 //JP 14.08.96: Bug 30332 - nach Umbau der modularietaet im SFX, muss jetzt
160 // das TopWindow der Application benutzt werden.
161 // SwFldInputDlg* pDlg = new SwFldInputDlg( GetWin(), *this, pFld );
163 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
164 DBG_ASSERT(pFact, "Dialogdiet fail!");
165 AbstractFldInputDlg* pDlg = pFact->CreateFldInputDlg( DLG_FLD_INPUT,
166 pParentWin, *this, pFld, bNextButton);
167 DBG_ASSERT(pDlg, "Dialogdiet fail!");
168 if(pWindowState && pWindowState->Len())
169 pDlg->SetWindowState(*pWindowState);
170 BOOL bRet = RET_CANCEL == pDlg->Execute();
171 if(pWindowState)
172 *pWindowState = pDlg->GetWindowState();
174 delete pDlg;
175 GetWin()->Update();
176 return bRet;
178 /* -----------------17.06.2003 10:18-----------------
180 --------------------------------------------------*/
181 BOOL SwWrtShell::StartDropDownFldDlg(SwField* pFld, BOOL bNextButton, ByteString* pWindowState)
183 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
184 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
186 AbstractDropDownFieldDialog* pDlg = pFact->CreateDropDownFieldDialog( NULL, *this, pFld, DLG_FLD_DROPDOWN ,bNextButton );
187 DBG_ASSERT(pDlg, "Dialogdiet fail!");
188 if(pWindowState && pWindowState->Len())
189 pDlg->SetWindowState(*pWindowState);
190 USHORT nRet = pDlg->Execute();
191 if(pWindowState)
192 *pWindowState = pDlg->GetWindowState();
193 delete pDlg;
194 BOOL bRet = RET_CANCEL == nRet;
195 GetWin()->Update();
196 if(RET_YES == nRet)
198 GetView().GetViewFrame()->GetDispatcher()->Execute(FN_EDIT_FIELD, SFX_CALLMODE_SYNCHRON);
200 return bRet;
203 /*--------------------------------------------------------------------
204 Beschreibung: Verzeichnis einfuegen Selektion loeschen
205 --------------------------------------------------------------------*/
209 void SwWrtShell::InsertTableOf(const SwTOXBase& rTOX, const SfxItemSet* pSet)
211 if(!_CanInsert())
212 return;
214 if(HasSelection())
215 DelRight();
217 SwEditShell::InsertTableOf(rTOX, pSet);
221 /*--------------------------------------------------------------------
222 Beschreibung: Verzeichnis Updaten Selektion loeschen
223 --------------------------------------------------------------------*/
225 BOOL SwWrtShell::UpdateTableOf(const SwTOXBase& rTOX, const SfxItemSet* pSet)
227 BOOL bResult = FALSE;
229 if(_CanInsert())
231 bResult = SwEditShell::UpdateTableOf(rTOX, pSet);
233 if (pSet == NULL)
235 SwDoc * _pDoc = GetDoc();
237 if (_pDoc != NULL)
238 _pDoc->DelAllUndoObj();
242 return bResult;
245 BOOL SwWrtShell::UpdateField( sw::mark::IFieldmark &fieldBM )
247 return SwEditShell::UpdateField(fieldBM);
252 // ein Klick aus das angegebene Feld. Der Cursor steht auf diesem.
253 // Fuehre die vor definierten Aktionen aus.
256 void SwWrtShell::ClickToField( const SwField& rFld )
258 bIsInClickToEdit = TRUE;
259 switch( rFld.GetTyp()->Which() )
261 case RES_JUMPEDITFLD:
263 USHORT nSlotId = 0;
264 switch( rFld.GetFormat() )
266 case JE_FMT_TABLE:
267 nSlotId = FN_INSERT_TABLE;
268 break;
270 case JE_FMT_FRAME:
271 nSlotId = FN_INSERT_FRAME;
272 break;
274 case JE_FMT_GRAPHIC: nSlotId = SID_INSERT_GRAPHIC; break;
275 case JE_FMT_OLE: nSlotId = SID_INSERT_OBJECT; break;
277 // case JE_FMT_TEXT:
280 Right( CRSR_SKIP_CHARS, TRUE, 1, FALSE ); // Feld selektieren
282 if( nSlotId )
284 StartUndo( UNDO_START );
285 //#97295# immediately select the right shell
286 GetView().StopShellTimer();
287 GetView().GetViewFrame()->GetDispatcher()->Execute( nSlotId,
288 SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD );
289 EndUndo( UNDO_END );
292 break;
294 case RES_MACROFLD:
296 const SwMacroField *pFld = (const SwMacroField*)&rFld;
297 String sText( rFld.GetPar2() );
298 String sRet( sText );
299 ExecMacro( pFld->GetSvxMacro(), &sRet );
301 // return Wert veraendert?
302 if( sRet != sText )
304 StartAllAction();
305 ((SwField&)rFld).SetPar2( sRet );
306 ((SwField&)rFld).GetTyp()->UpdateFlds();
307 EndAllAction();
310 break;
312 case RES_GETREFFLD:
313 StartAllAction();
314 SwCrsrShell::GotoRefMark( ((SwGetRefField&)rFld).GetSetRefName(),
315 ((SwGetRefField&)rFld).GetSubType(),
316 ((SwGetRefField&)rFld).GetSeqNo() );
317 EndAllAction();
318 break;
320 case RES_INPUTFLD:
321 StartInputFldDlg( (SwField*)&rFld, FALSE );
322 break;
324 case RES_SETEXPFLD:
325 if( ((SwSetExpField&)rFld).GetInputFlag() )
326 StartInputFldDlg( (SwField*)&rFld, FALSE );
327 break;
328 case RES_DROPDOWN :
329 StartDropDownFldDlg( (SwField*)&rFld, FALSE );
330 break;
333 bIsInClickToEdit = FALSE;
338 void SwWrtShell::ClickToINetAttr( const SwFmtINetFmt& rItem, USHORT nFilter )
340 if( !rItem.GetValue().Len() )
341 return ;
343 bIsInClickToEdit = TRUE;
345 // erstmal das evt. gesetzte ObjectSelect Macro ausfuehren
346 const SvxMacro* pMac = rItem.GetMacro( SFX_EVENT_MOUSECLICK_OBJECT );
347 if( pMac )
349 SwCallMouseEvent aCallEvent;
350 aCallEvent.Set( &rItem );
351 GetDoc()->CallEvent( SFX_EVENT_MOUSECLICK_OBJECT, aCallEvent, FALSE );
354 // damit die Vorlagenumsetzung sofort angezeigt wird
355 ::LoadURL( rItem.GetValue(), this, nFilter, &rItem.GetTargetFrame() );
356 const SwTxtINetFmt* pTxtAttr = rItem.GetTxtINetFmt();
357 if( pTxtAttr )
359 const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisited( true );
360 const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisitedValid( true );
363 bIsInClickToEdit = FALSE;
368 BOOL SwWrtShell::ClickToINetGrf( const Point& rDocPt, USHORT nFilter )
370 BOOL bRet = FALSE;
371 String sURL;
372 String sTargetFrameName;
373 const SwFrmFmt* pFnd = IsURLGrfAtPos( rDocPt, &sURL, &sTargetFrameName );
374 if( pFnd && sURL.Len() )
376 bRet = TRUE;
377 // erstmal das evt. gesetzte ObjectSelect Macro ausfuehren
378 const SvxMacro* pMac = &pFnd->GetMacro().GetMacro( SFX_EVENT_MOUSECLICK_OBJECT );
379 if( pMac )
381 SwCallMouseEvent aCallEvent;
382 aCallEvent.Set( EVENT_OBJECT_URLITEM, pFnd );
383 GetDoc()->CallEvent( SFX_EVENT_MOUSECLICK_OBJECT, aCallEvent, FALSE );
386 ::LoadURL( sURL, this, nFilter, &sTargetFrameName);
388 return bRet;
392 void LoadURL( const String& rURL, ViewShell* pVSh, USHORT nFilter,
393 const String *pTargetFrameName )
395 ASSERT( rURL.Len() && pVSh, "was soll hier geladen werden?" );
396 if( !rURL.Len() || !pVSh )
397 return ;
399 // die Shell kann auch 0 sein !!!!!
400 SwWrtShell *pSh = 0;
401 if ( pVSh && pVSh->ISA(SwCrsrShell) )
403 //Eine CrsrShell ist auch immer eine WrtShell
404 pSh = (SwWrtShell*)pVSh;
406 else
407 return;
409 SwDocShell* pDShell = pSh->GetView().GetDocShell();
410 DBG_ASSERT( pDShell, "No DocShell?!");
411 String sTargetFrame;
412 if( pTargetFrameName && pTargetFrameName->Len() )
413 sTargetFrame = *pTargetFrameName;
414 else if( pDShell ) {
415 using namespace ::com::sun::star;
416 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
417 pDShell->GetModel(), uno::UNO_QUERY_THROW);
418 uno::Reference<document::XDocumentProperties> xDocProps
419 = xDPS->getDocumentProperties();
420 sTargetFrame = xDocProps->getDefaultTarget();
423 String sReferer;
424 if( pDShell && pDShell->GetMedium() )
425 sReferer = pDShell->GetMedium()->GetName();
426 SfxViewFrame* pViewFrm = pSh->GetView().GetViewFrame();
427 SfxFrameItem aView( SID_DOCFRAME, pViewFrm );
428 SfxStringItem aName( SID_FILE_NAME, rURL );
429 SfxStringItem aTargetFrameName( SID_TARGETNAME, sTargetFrame );
430 SfxStringItem aReferer( SID_REFERER, sReferer );
432 SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, FALSE );
433 //#39076# Silent kann lt. SFX entfernt werden.
434 // SfxBoolItem aSilent( SID_SILENT, TRUE );
435 SfxBoolItem aBrowse( SID_BROWSE, TRUE );
437 if( nFilter & URLLOAD_NEWVIEW )
438 aTargetFrameName.SetValue( String::CreateFromAscii("_blank") );
440 const SfxPoolItem* aArr[] = {
441 &aName,
442 &aNewView, /*&aSilent,*/
443 &aReferer,
444 &aView, &aTargetFrameName,
445 &aBrowse,
449 pViewFrm->GetDispatcher()->GetBindings()->Execute( SID_OPENDOC, aArr,
450 SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD );
453 void SwWrtShell::NavigatorPaste( const NaviContentBookmark& rBkmk,
454 const USHORT nAction )
456 if( EXCHG_IN_ACTION_COPY == nAction )
458 // Einfuegen
459 String sURL = rBkmk.GetURL();
460 //handelt es sich um ein Sprung innerhalb des akt. Docs?
461 const SwDocShell* pDocShell = GetView().GetDocShell();
462 if(pDocShell->HasName())
464 const String rName = pDocShell->GetMedium()->GetURLObject().GetURLNoMark();
466 if(COMPARE_EQUAL == sURL.CompareTo(rName, rName.Len()))
467 sURL.Erase(0, rName.Len());
469 SwFmtINetFmt aFmt( sURL, aEmptyStr );
470 InsertURL( aFmt, rBkmk.GetDescription() );
472 else
474 SwSection aSection( FILE_LINK_SECTION, GetUniqueSectionName( 0 ) );
475 String aLinkFile( rBkmk.GetURL().GetToken(0, '#') );
476 aLinkFile += sfx2::cTokenSeperator;
477 aLinkFile += sfx2::cTokenSeperator;
478 aLinkFile += rBkmk.GetURL().GetToken(1, '#');
479 aSection.SetLinkFileName( aLinkFile );
480 aSection.SetProtect( TRUE );
481 const SwSection* pIns = InsertSection( aSection );
482 if( EXCHG_IN_ACTION_MOVE == nAction && pIns )
484 aSection = *pIns;
485 aSection.SetLinkFileName( aEmptyStr );
486 aSection.SetType( CONTENT_SECTION );
487 aSection.SetProtect( FALSE );
489 // the update of content from linked section at time delete
490 // the undostack. Then the change of the section dont create
491 // any undoobject. - BUG 69145
492 BOOL bDoesUndo = DoesUndo();
493 if( UNDO_INSSECTION != GetUndoIds() )
494 DoUndo( FALSE );
495 ChgSection( GetSectionFmtPos( *pIns->GetFmt() ), aSection );
496 DoUndo( bDoesUndo );