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
);
99 SwEditShell::Insert(rFld
);
100 EndUndo(UNDO_INSERT
);
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
;
115 pTmp
= new SwInputFieldList( this );
118 pTmp
->RemoveUnselectedFlds();
120 const USHORT nCnt
= pTmp
->Count();
125 BOOL bCancel
= FALSE
;
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
);
134 bCancel
= StartInputFldDlg( pField
, TRUE
, 0, &aDlgPos
);
136 // Sonst Updatefehler bei Multiselektion:
137 pTmp
->GetField( i
)->GetTyp()->UpdateFlds();
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();
169 *pWindowState
= pDlg
->GetWindowState();
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();
189 *pWindowState
= pDlg
->GetWindowState();
191 BOOL bRet
= RET_CANCEL
== nRet
;
195 GetView().GetViewFrame()->GetDispatcher()->Execute(FN_EDIT_FIELD
, SFX_CALLMODE_SYNCHRON
);
200 /*--------------------------------------------------------------------
201 Beschreibung: Verzeichnis einfuegen Selektion loeschen
202 --------------------------------------------------------------------*/
206 void SwWrtShell::InsertTableOf(const SwTOXBase
& rTOX
, const SfxItemSet
* pSet
)
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
;
228 bResult
= SwEditShell::UpdateTableOf(rTOX
, pSet
);
232 SwDoc
* _pDoc
= GetDoc();
235 _pDoc
->DelAllUndoObj();
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
:
261 switch( rFld
.GetFormat() )
264 nSlotId
= FN_INSERT_TABLE
;
268 nSlotId
= FN_INSERT_FRAME
;
271 case JE_FMT_GRAPHIC
: nSlotId
= SID_INSERT_GRAPHIC
; break;
272 case JE_FMT_OLE
: nSlotId
= SID_INSERT_OBJECT
; break;
277 Right( CRSR_SKIP_CHARS
, TRUE
, 1, FALSE
); // Feld selektieren
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
);
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?
302 ((SwField
&)rFld
).SetPar2( sRet
);
303 ((SwField
&)rFld
).GetTyp()->UpdateFlds();
311 SwCrsrShell::GotoRefMark( ((SwGetRefField
&)rFld
).GetSetRefName(),
312 ((SwGetRefField
&)rFld
).GetSubType(),
313 ((SwGetRefField
&)rFld
).GetSeqNo() );
318 StartInputFldDlg( (SwField
*)&rFld
, FALSE
);
322 if( ((SwSetExpField
&)rFld
).GetInputFlag() )
323 StartInputFldDlg( (SwField
*)&rFld
, FALSE
);
326 StartDropDownFldDlg( (SwField
*)&rFld
, FALSE
);
330 bIsInClickToEdit
= FALSE
;
335 void SwWrtShell::ClickToINetAttr( const SwFmtINetFmt
& rItem
, USHORT nFilter
)
337 if( !rItem
.GetValue().Len() )
340 bIsInClickToEdit
= TRUE
;
342 // erstmal das evt. gesetzte ObjectSelect Macro ausfuehren
343 const SvxMacro
* pMac
= rItem
.GetMacro( SFX_EVENT_MOUSECLICK_OBJECT
);
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();
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
)
369 String sTargetFrameName
;
370 const SwFrmFmt
* pFnd
= IsURLGrfAtPos( rDocPt
, &sURL
, &sTargetFrameName
);
371 if( pFnd
&& sURL
.Len() )
374 // erstmal das evt. gesetzte ObjectSelect Macro ausfuehren
375 const SvxMacro
* pMac
= &pFnd
->GetMacro().GetMacro( SFX_EVENT_MOUSECLICK_OBJECT
);
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
);
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
)
396 // die Shell kann auch 0 sein !!!!!
398 if ( pVSh
&& pVSh
->ISA(SwCrsrShell
) )
400 //Eine CrsrShell ist auch immer eine WrtShell
401 pSh
= (SwWrtShell
*)pVSh
;
406 SwDocShell
* pDShell
= pSh
->GetView().GetDocShell();
407 DBG_ASSERT( pDShell
, "No DocShell?!");
409 if( pTargetFrameName
&& pTargetFrameName
->Len() )
410 sTargetFrame
= *pTargetFrameName
;
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();
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
[] = {
439 &aNewView
, /*&aSilent,*/
441 &aView
, &aTargetFrameName
,
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
)
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() );
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
)
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() )
492 ChgSection( GetSectionFmtPos( *pIns
->GetFmt() ), aSection
);