1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wrtsh2.cxx,v $
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>
47 #include <swtypes.hxx> // SET_CURR_SHELL
50 #include <fldbas.hxx> // Felder
53 #include <docufld.hxx>
57 #include <viewopt.hxx> // SwViewOptions
58 #include <frmfmt.hxx> // fuer UpdateTable
59 #include <swtable.hxx> // fuer UpdateTable
62 #include <swevent.hxx>
63 #include <poolfmt.hxx>
64 #include <section.hxx>
65 #include <navicont.hxx>
67 #include <crsskip.hxx>
68 #include <txtinet.hxx>
71 #include "swabstdlg.hxx"
76 #include <com/sun/star/document/XDocumentProperties.hpp>
77 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
80 /*------------------------------------------------------------------------
82 ------------------------------------------------------------------------*/
84 void SwWrtShell::Insert(SwField
&rFld
)
92 aRewriter
.AddRule(UNDO_ARG1
, rFld
.GetDescription());
94 StartUndo(UNDO_INSERT
, &aRewriter
);
96 bool bDeleted
= false;
99 bDeleted
= DelRight() != 0;
102 SwEditShell::Insert2(rFld
, bDeleted
);
103 EndUndo(UNDO_INSERT
);
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
;
118 pTmp
= new SwInputFieldList( this );
121 pTmp
->RemoveUnselectedFlds();
123 const USHORT nCnt
= pTmp
->Count();
128 BOOL bCancel
= FALSE
;
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
);
137 bCancel
= StartInputFldDlg( pField
, TRUE
, 0, &aDlgPos
);
139 // Sonst Updatefehler bei Multiselektion:
140 pTmp
->GetField( i
)->GetTyp()->UpdateFlds();
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();
172 *pWindowState
= pDlg
->GetWindowState();
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();
192 *pWindowState
= pDlg
->GetWindowState();
194 BOOL bRet
= RET_CANCEL
== nRet
;
198 GetView().GetViewFrame()->GetDispatcher()->Execute(FN_EDIT_FIELD
, SFX_CALLMODE_SYNCHRON
);
203 /*--------------------------------------------------------------------
204 Beschreibung: Verzeichnis einfuegen Selektion loeschen
205 --------------------------------------------------------------------*/
209 void SwWrtShell::InsertTableOf(const SwTOXBase
& rTOX
, const SfxItemSet
* pSet
)
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
;
231 bResult
= SwEditShell::UpdateTableOf(rTOX
, pSet
);
235 SwDoc
* _pDoc
= GetDoc();
238 _pDoc
->DelAllUndoObj();
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
:
264 switch( rFld
.GetFormat() )
267 nSlotId
= FN_INSERT_TABLE
;
271 nSlotId
= FN_INSERT_FRAME
;
274 case JE_FMT_GRAPHIC
: nSlotId
= SID_INSERT_GRAPHIC
; break;
275 case JE_FMT_OLE
: nSlotId
= SID_INSERT_OBJECT
; break;
280 Right( CRSR_SKIP_CHARS
, TRUE
, 1, FALSE
); // Feld selektieren
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
);
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?
305 ((SwField
&)rFld
).SetPar2( sRet
);
306 ((SwField
&)rFld
).GetTyp()->UpdateFlds();
314 SwCrsrShell::GotoRefMark( ((SwGetRefField
&)rFld
).GetSetRefName(),
315 ((SwGetRefField
&)rFld
).GetSubType(),
316 ((SwGetRefField
&)rFld
).GetSeqNo() );
321 StartInputFldDlg( (SwField
*)&rFld
, FALSE
);
325 if( ((SwSetExpField
&)rFld
).GetInputFlag() )
326 StartInputFldDlg( (SwField
*)&rFld
, FALSE
);
329 StartDropDownFldDlg( (SwField
*)&rFld
, FALSE
);
333 bIsInClickToEdit
= FALSE
;
338 void SwWrtShell::ClickToINetAttr( const SwFmtINetFmt
& rItem
, USHORT nFilter
)
340 if( !rItem
.GetValue().Len() )
343 bIsInClickToEdit
= TRUE
;
345 // erstmal das evt. gesetzte ObjectSelect Macro ausfuehren
346 const SvxMacro
* pMac
= rItem
.GetMacro( SFX_EVENT_MOUSECLICK_OBJECT
);
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();
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
)
372 String sTargetFrameName
;
373 const SwFrmFmt
* pFnd
= IsURLGrfAtPos( rDocPt
, &sURL
, &sTargetFrameName
);
374 if( pFnd
&& sURL
.Len() )
377 // erstmal das evt. gesetzte ObjectSelect Macro ausfuehren
378 const SvxMacro
* pMac
= &pFnd
->GetMacro().GetMacro( SFX_EVENT_MOUSECLICK_OBJECT
);
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
);
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
)
399 // die Shell kann auch 0 sein !!!!!
401 if ( pVSh
&& pVSh
->ISA(SwCrsrShell
) )
403 //Eine CrsrShell ist auch immer eine WrtShell
404 pSh
= (SwWrtShell
*)pVSh
;
409 SwDocShell
* pDShell
= pSh
->GetView().GetDocShell();
410 DBG_ASSERT( pDShell
, "No DocShell?!");
412 if( pTargetFrameName
&& pTargetFrameName
->Len() )
413 sTargetFrame
= *pTargetFrameName
;
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();
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
[] = {
442 &aNewView
, /*&aSilent,*/
444 &aView
, &aTargetFrameName
,
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
)
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() );
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
)
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() )
495 ChgSection( GetSectionFmtPos( *pIns
->GetFmt() ), aSection
);