Files
libreoffice/sw/source/ui/uiview/srcview.cxx

976 lines
32 KiB
C++
Raw Normal View History

2000-09-18 16:15:01 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 16:15:01 +00:00
*
* Copyright 2008 by Sun Microsystems, Inc.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:15:01 +00:00
*
* $RCSfile: srcview.cxx,v $
* $Revision: 1.59 $
2000-09-18 16:15:01 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 16:15:01 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 16:15:01 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
2000-09-18 16:15:01 +00:00
#include <hintids.hxx>
#include <com/sun/star/util/SearchOptions.hpp>
#include <com/sun/star/util/SearchFlags.hpp>
#include <com/sun/star/i18n/TransliterationModules.hpp>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
2000-11-06 08:30:33 +00:00
#include <unotools/tempfile.hxx>
2000-09-18 16:15:01 +00:00
#include <tools/urlobj.hxx>
#include <vcl/print.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/wrkwin.hxx>
#include <vcl/metric.hxx>
#include <svtools/ctrltool.hxx>
#include <svtools/intitem.hxx>
#include <svtools/stritem.hxx>
2000-10-06 12:41:54 +00:00
#include <svtools/pathoptions.hxx>
2000-09-18 16:15:01 +00:00
#include <svtools/undo.hxx>
#include <svtools/txtcmp.hxx>
#include <svtools/eitem.hxx>
#include <svtools/whiter.hxx>
2000-10-06 12:41:54 +00:00
#include <svtools/saveopt.hxx>
2001-05-08 18:56:30 +00:00
#include <svtools/transfer.hxx>
#include <svx/htmlcfg.hxx>
#include <sfx2/app.hxx>
#include <sfx2/objface.hxx>
#include <sfx2/viewfrm.hxx>
2000-09-18 16:15:01 +00:00
#include <sfx2/docfilt.hxx>
#include <sfx2/fcontnr.hxx>
2000-09-18 16:15:01 +00:00
#include <sfx2/request.hxx>
#include <sfx2/prnmon.hxx>
#include <sfx2/docfile.hxx>
#include <svx/fhgtitem.hxx>
#include <svx/srchdlg.hxx>
#include <svx/srchitem.hxx>
#include <svx/fontitem.hxx>
#include <svx/flstitem.hxx>
#include "svx/unolingu.hxx"
2001-07-26 04:53:10 +00:00
#include <sfx2/sfxhtml.hxx>
2000-09-18 16:15:01 +00:00
#include <swtypes.hxx>
#include <swmodule.hxx>
#include <docsh.hxx>
#include <wdocsh.hxx>
#include <srcview.hxx>
#include <viewfunc.hxx>
#include <doc.hxx>
#include <itemdef.hxx>
#include <shellio.hxx>
#include <cmdid.h> // FN_ ...
#include <helpid.h>
#include <globals.hrc>
#include <shells.hrc>
#include <popup.hrc>
#include <web.hrc>
#include <view.hrc>
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
#include <sfx2/filedlghelper.hxx>
2000-09-18 16:15:01 +00:00
#define SwSrcView
#define SearchSettings
#define _ExecSearch Execute
#define _StateSearch GetState
#include <svx/svxslots.hxx>
#include "swslots.hxx"
#include <unomid.h>
#include <com/sun/star/document/XDocumentProperties.hpp>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::i18n;
2001-05-15 09:14:56 +00:00
using namespace ::com::sun::star::lang;
using namespace ::sfx2;
CWS-TOOLING: integrate CWS libmsword 2008-12-18 12:33:19 +0100 kendy r265681 : Export less symbols. 2008-12-17 19:26:56 +0100 kendy r265655 : Move libmsword to the -writer package. 2008-12-15 17:46:16 +0100 kendy r265516 : Enable exceptions for iodetect.cxx. 2008-12-15 15:17:53 +0100 kendy r265504 : Deliver the msword.dll. 2008-12-09 19:38:17 +0100 kendy r265138 : Remove accidentally added method. 2008-12-09 19:33:57 +0100 kendy r265137 : Fix linking on Win32. 2008-12-09 18:37:16 +0100 kendy r265135 : Move SwFltControlStack::Delete() to ww1/fltshell.cxx to fix linking. 2008-12-09 18:01:56 +0100 kendy r265127 : Visibility fixes. 2008-12-09 15:51:52 +0100 kendy r265109 : Fix ambiguous usage of class Color. 2008-12-09 14:54:27 +0100 kendy r265091 : Add #include "precompiled_sw.hxx" to fix --enable-pch build. 2008-12-09 14:44:59 +0100 kendy r265088 : Add #include "precompiled_sw.hxx" to fix --enable-pch build. 2008-12-08 19:14:49 +0100 kendy r265015 : #i96313# Get rid of inc/iodetect.cxx, it's a really bad idea to share code by #ifdefing parts of it, and #including a .cxx file ;-) This change moves it to iodetect.cxx, which is compiled to a .o/.obj that is used where needed. 2008-11-20 17:45:08 +0100 kendy r264083 : #i96313# Make the destruction of Readers consistent. 2008-11-20 17:18:11 +0100 kendy r264070 : #i96313# Added missing SW_DLLPUBLIC for (Import|Export)(DOC|RTF). 2008-11-18 19:21:07 +0100 kendy r263797 : #i96313# Remove accidentally added file. 2008-11-18 17:14:31 +0100 kendy r263790 : #i96313# Split doc and rtf filters into a separate library From: Radek Doulik <rodo@novell.com> fix SwFieldBookmark class visibility (suggested by kendy) 2008-11-18 17:14:01 +0100 kendy r263789 : #i96313# Split doc and rtf filters into a separate library From: Fridrich Strba <fstrba@novell.com> add visibility markup to allow linking 2008-11-18 17:13:29 +0100 kendy r263788 : #i96313# Split doc and rtf filters into a separate library From: Jan Holesovsky <kendy@suse.cz> Visibility markup for libmsword. This is the most trivial approach, every class that had a symbol that needed to be visible was marked with SW_DLLPUBLIC; the correct (but more time consuming) way would be to mark just the exact methods that were needed. To be done later if generally shows that the separate libmsword makes sense; and also now we have the upper limit of symbols that needed to be added, and we can only make it better [decrease the number] ;-) 2008-11-18 17:12:58 +0100 kendy r263787 : #i96313# Split doc and rtf filters into a separate library From: Jan Holesovsky <kendy@suse.cz> Added the missing msword.map. 2008-11-18 17:12:25 +0100 kendy r263786 : #i96313# Split doc and rtf filters into a separate library From: Jan Holesovsky <kendy@suse.cz> scp2 change for libmsword. 2008-11-18 17:11:55 +0100 kendy r263785 : #i96313# Split doc and rtf filters into a separate library From: Jan Holesovsky <kendy@suse.cz> Convert the binary .doc and .rtf filters into a separate library. It is called 'libmsword' and loaded on demand when either of the formats (.doc, .rtf) is loaded or saved.
2009-01-05 14:06:42 +00:00
using ::rtl::OUString;
using ::com::sun::star::util::SearchOptions;
2000-09-18 16:15:01 +00:00
#define SWSRCVIEWFLAGS ( SFX_VIEW_MAXIMIZE_FIRST| \
SFX_VIEW_OBJECTSIZE_EMBEDDED| \
SFX_VIEW_CAN_PRINT|\
SFX_VIEW_NO_NEWWINDOW )
#define SRC_SEARCHOPTIONS (0xFFFF & ~(SEARCH_OPTIONS_FORMAT|SEARCH_OPTIONS_FAMILIES|SEARCH_OPTIONS_SEARCH_ALL))
// Druckraender -> wie Basic - Ide
#define LMARGPRN 1700
#define RMARGPRN 900
#define TMARGPRN 2000
#define BMARGPRN 1000
#define BORDERPRN 300
SFX_IMPL_VIEWFACTORY(SwSrcView, SW_RES(STR_NONAME))
{
SFX_VIEW_REGISTRATION(SwWebDocShell);
}
SFX_IMPL_INTERFACE( SwSrcView, SfxViewShell, SW_RES(0) )
{
SFX_POPUPMENU_REGISTRATION(SW_RES(MN_SRCVIEW_POPUPMENU));
SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS|
SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
SW_RES(RID_WEBTOOLS_TOOLBOX) );
SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
}
TYPEINIT1(SwSrcView, SfxViewShell)
/*-----------------18.11.96 08.05-------------------
--------------------------------------------------*/
void lcl_PrintHeader( Printer* pPrinter, USHORT nPages, USHORT nCurPage, const String& rTitle )
{
short nLeftMargin = LMARGPRN;
Size aSz = pPrinter->GetOutputSize();
short nBorder = BORDERPRN;
Color aOldFillColor( pPrinter->GetFillColor() );
Font aOldFont( pPrinter->GetFont() );
pPrinter->SetFillColor( Color(COL_TRANSPARENT) );
Font aFont( aOldFont );
aFont.SetWeight( WEIGHT_BOLD );
aFont.SetAlign( ALIGN_BOTTOM );
pPrinter->SetFont( aFont );
long nFontHeight = pPrinter->GetTextHeight();
// 1.Border => Strich, 2+3 Border = Freiraum.
long nYTop = TMARGPRN-3*nBorder-nFontHeight;
long nXLeft = nLeftMargin-nBorder;
long nXRight = aSz.Width()-RMARGPRN+nBorder;
pPrinter->DrawRect( Rectangle(
Point( nXLeft, nYTop ),
Size( nXRight-nXLeft, aSz.Height() - nYTop - BMARGPRN + nBorder ) ) );
long nY = TMARGPRN-2*nBorder;
Point aPos( nLeftMargin, nY );
pPrinter->DrawText( aPos, rTitle );
if ( nPages != 1 )
{
aFont.SetWeight( WEIGHT_NORMAL );
pPrinter->SetFont( aFont );
String aPageStr( C2S(" [") );
aPageStr += String( SW_RES( STR_PAGE ) );
aPageStr += ' ';
aPageStr += String::CreateFromInt32( nCurPage );
aPageStr += ']';
aPos.X() += pPrinter->GetTextWidth( rTitle );
pPrinter->DrawText( aPos, aPageStr );
}
nY = TMARGPRN-nBorder;
pPrinter->DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
pPrinter->SetFont( aOldFont );
pPrinter->SetFillColor( aOldFillColor );
}
/* -----------------13.11.2003 16:24-----------------
2000-09-18 16:15:01 +00:00
--------------------------------------------------*/
rtl_TextEncoding lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding)
{
rtl_TextEncoding eRet = eLoadEncoding;
if(RTL_TEXTENCODING_DONTKNOW == eRet)
{
SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get();
const sal_Char *pCharSet =
rtl_getBestMimeCharsetFromTextEncoding( pHtmlOptions->GetTextEncoding() );
eRet = rtl_getTextEncodingFromMimeCharset( pCharSet );
}
return eRet;
}
2000-09-18 16:15:01 +00:00
/*-----------------18.11.96 08.21-------------------
--------------------------------------------------*/
void lcl_ConvertTabsToSpaces( String& rLine )
{
if ( rLine.Len() )
{
USHORT nPos = 0;
USHORT nMax = rLine.Len();
while ( nPos < nMax )
{
if ( rLine.GetChar(nPos) == '\t' )
{
// Nicht 4 Blanks, sondern an 4er TabPos:
String aBlanker;
aBlanker.Fill( ( 4 - ( nPos % 4 ) ), ' ' );
rLine.Erase( nPos, 1 );
rLine.Insert( aBlanker, nPos );
nMax = rLine.Len();
}
nPos++; // Nicht optimal, falls Tab, aber auch nicht verkehrt...
}
}
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
SwSrcView::SwSrcView(SfxViewFrame* pViewFrame, SfxViewShell*) :
SfxViewShell( pViewFrame, SWSRCVIEWFLAGS ),
aEditWin( &pViewFrame->GetWindow(), this ),
2000-09-18 16:15:01 +00:00
pSearchItem(0),
2002-01-11 08:43:53 +00:00
bSourceSaved(FALSE),
eLoadEncoding(RTL_TEXTENCODING_DONTKNOW)
2000-09-18 16:15:01 +00:00
{
Init();
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
SwSrcView::~SwSrcView()
{
SwDocShell* pDocShell = GetDocShell();
DBG_ASSERT(PTR_CAST(SwWebDocShell, pDocShell), "Wieso keine WebDocShell?");
2000-09-18 16:15:01 +00:00
const TextSelection& rSel = aEditWin.GetTextView()->GetSelection();
((SwWebDocShell*)pDocShell)->SetSourcePara( static_cast< USHORT >( rSel.GetStart().GetPara() ) );
2000-09-18 16:15:01 +00:00
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
pDocShell->GetModel(), uno::UNO_QUERY_THROW);
uno::Reference<document::XDocumentProperties> xDocProps
= xDPS->getDocumentProperties();
::rtl::OUString url = xDocProps->getAutoloadURL();
sal_Int32 delay = xDocProps->getAutoloadSecs();
pDocShell->SetAutoLoad(INetURLObject(url), delay,
(delay != 0) || !url.equalsAscii(""));
2000-09-18 16:15:01 +00:00
// EndListening(*GetViewFrame());
EndListening(*pDocShell);
delete pSearchItem;
}
/*-----------------24.04.97 10:37-------------------
--------------------------------------------------*/
void SwSrcView::SaveContentTo(SfxMedium& rMed)
{
SvStream* pOutStream = rMed.GetOutStream();
pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding));
aEditWin.Write( *pOutStream );//, EE_FORMAT_TEXT);
2000-09-18 16:15:01 +00:00
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
void SwSrcView::Init()
{
SetHelpId(SW_SRC_VIEWSHELL);
SetName(C2S("Source"));
SetWindow( &aEditWin );
SwDocShell* pDocShell = GetDocShell();
// wird das Doc noch geladen, dann muss die DocShell das Load
// anwerfen, wenn das Laden abgeschlossen ist
if(!pDocShell->IsLoading())
Load(pDocShell);
else
{
aEditWin.SetReadonly(TRUE);
}
// StartListening(*GetViewFrame());
StartListening(*pDocShell,TRUE);
2000-09-18 16:15:01 +00:00
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
SwDocShell* SwSrcView::GetDocShell()
{
SfxObjectShell* pObjShell = GetViewFrame()->GetObjectShell();
return PTR_CAST(SwDocShell, pObjShell);
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
void SwSrcView::SaveContent(const String& rTmpFile)
{
SfxMedium aMedium( rTmpFile, STREAM_WRITE, TRUE);
SvStream* pOutStream = aMedium.GetOutStream();
pOutStream->SetStreamCharSet( lcl_GetStreamCharSet(eLoadEncoding) );
2000-09-18 16:15:01 +00:00
aEditWin.Write(*pOutStream);//, EE_FORMAT_TEXT);
aMedium.Commit();
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
2000-10-06 12:41:54 +00:00
void SwSrcView::Execute(SfxRequest& rReq)
2000-09-18 16:15:01 +00:00
{
USHORT nSlot = rReq.GetSlot();
TextView* pTextView = aEditWin.GetTextView();
switch( nSlot )
{
case SID_SAVEASDOC:
{
2000-10-06 12:41:54 +00:00
SvtPathOptions aPathOpt;
// filesave dialog with autoextension
FileDialogHelper aDlgHelper(
TemplateDescription::FILESAVE_AUTOEXTENSION,
TemplateDescription::FILESAVE_SIMPLE );
uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
// pFileDlg->SetHelpId(HID_FILEDLG_SRCVIEW);
uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
2001-05-15 09:14:56 +00:00
// search for an html filter for export
SfxFilterContainer* pFilterCont = GetObjectShell()->GetFactory().GetFilterContainer();
const SfxFilter* pFilter =
pFilterCont->GetFilter4Extension( C2S("html"), SFX_FILTER_EXPORT );
if ( pFilter )
{
// filter found -> use its uiname and wildcard
const String& rUIName = pFilter->GetUIName();
const WildCard& rCard = pFilter->GetWildcard();
xFltMgr->appendFilter( rUIName, rCard() );
xFltMgr->setCurrentFilter( rUIName ) ;
}
else
{
// filter not found
String sHtml(C2S("HTML"));
xFltMgr->appendFilter( sHtml, C2S("*.html;*.htm") );
xFltMgr->setCurrentFilter( sHtml ) ;
}
2001-05-15 09:14:56 +00:00
xFP->setDisplayDirectory( aPathOpt.GetWorkPath() );
if( aDlgHelper.Execute() == ERRCODE_NONE)
2000-09-18 16:15:01 +00:00
{
SfxMedium aMedium( xFP->getFiles().getConstArray()[0],
2000-11-01 18:32:39 +00:00
STREAM_WRITE | STREAM_SHARE_DENYNONE,
FALSE );
SvStream* pOutStream = aMedium.GetOutStream();
pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding));
aEditWin.Write( *pOutStream );
2000-11-01 18:32:39 +00:00
aMedium.Commit();
2000-09-18 16:15:01 +00:00
}
}
break;
case SID_SAVEDOC:
{
SwDocShell* pDocShell = GetDocShell();
SfxMedium* pMed = 0;
if(pDocShell->HasName())
pMed = pDocShell->GetMedium();
else
{
SfxBoolItem* pItem = (SfxBoolItem*)pDocShell->ExecuteSlot(rReq, pDocShell->GetInterface());
if(pItem && pItem->GetValue())
pMed = pDocShell->GetMedium();
}
if(pMed)
{
SvStream* pOutStream = pMed->GetOutStream();
pOutStream->Seek(0);
pOutStream->SetStreamSize(0);
pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding));
aEditWin.Write( *pOutStream );
pMed->CloseOutStream();
2000-09-18 16:15:01 +00:00
pMed->Commit();
pDocShell->GetDoc()->ResetModified();
SourceSaved();
aEditWin.ClearModifyFlag();
}
}
break;
case FID_SEARCH_NOW:
{
const SfxItemSet* pTmpArgs = rReq.GetArgs();
2000-09-18 16:15:01 +00:00
USHORT nWhich = pTmpArgs->GetWhichByPos( 0 );
2000-09-18 16:15:01 +00:00
DBG_ASSERT( nWhich, "Wich fuer SearchItem ?" );
const SfxPoolItem& rItem = pTmpArgs->Get( nWhich );
2000-09-18 16:15:01 +00:00
SetSearchItem( (const SvxSearchItem&)rItem);
StartSearchAndReplace( (const SvxSearchItem&)rItem, FALSE, rReq.IsAPI() );
if(aEditWin.IsModified())
GetDocShell()->GetDoc()->SetModified();
}
break;
case FN_REPEAT_SEARCH:
{
SvxSearchItem* pSrchItem = GetSearchItem();
if(pSrchItem)
{
StartSearchAndReplace( *pSrchItem, FALSE, rReq.IsAPI() );
if(aEditWin.IsModified())
GetDocShell()->GetDoc()->SetModified();
}
}
break;
2000-09-18 16:15:01 +00:00
case SID_PRINTDOC:
case SID_PRINTDOCDIRECT:
{
SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() );
}
break;
case SID_UNDO:
pTextView->Undo();
break;
case SID_REDO:
pTextView->Redo();
break;
case SID_REPEAT:
break;
case SID_CUT:
pTextView->Cut();
break;
case SID_COPY:
pTextView->Copy();
break;
case SID_PASTE:
pTextView->Paste();
break;
case SID_SELECTALL:
pTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
break;
}
aEditWin.Invalidate();
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
2000-10-06 12:41:54 +00:00
void SwSrcView::GetState(SfxItemSet& rSet)
2000-09-18 16:15:01 +00:00
{
SfxWhichIter aIter(rSet);
USHORT nWhich = aIter.FirstWhich();
TextView* pTextView = aEditWin.GetTextView();
while(nWhich)
{
switch(nWhich)
{
case SID_SAVEASDOC:
rSet.Put(SfxStringItem(nWhich, String(SW_RES(STR_SAVEAS_SRC))));
break;
case SID_SAVEDOC:
{
SwDocShell* pDocShell = GetDocShell();
if(!pDocShell->IsModified())
rSet.DisableItem(nWhich);
}
break;
case SID_PRINTDOC:
case SID_PRINTDOCDIRECT:
break;
case SID_TABLE_CELL:
{
String aPos( SW_RES(STR_SRCVIEW_ROW) );
TextSelection aSel = pTextView->GetSelection();
aPos += String::CreateFromInt32( aSel.GetEnd().GetPara()+1 );
aPos +=C2S(" : ");
aPos += String(SW_RES(STR_SRCVIEW_COL));
aPos += String::CreateFromInt32( aSel.GetEnd().GetIndex()+1 );
SfxStringItem aItem( nWhich, aPos );
rSet.Put( aItem );
}
break;
case SID_SEARCH_OPTIONS:
{
USHORT nOpt = SRC_SEARCHOPTIONS;
if(GetDocShell()->IsReadOnly())
nOpt &= ~(SEARCH_OPTIONS_REPLACE|SEARCH_OPTIONS_REPLACE_ALL);
rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOpt) );
}
break;
case SID_SEARCH_ITEM:
{
String sSelected;
if ( !pTextView->HasSelection() )
{
const TextSelection& rSel = pTextView->GetSelection();
sSelected = aEditWin.GetTextEngine()->GetWord( rSel.GetStart());
}
else
{
sSelected = pTextView->GetSelected();
}
SvxSearchItem * pSrchItem = GetSearchItem();
pSrchItem->SetSearchString( sSelected );
rSet.Put( *pSrchItem );
}
break;
case FN_REPEAT_SEARCH:
{
if(!GetSearchItem())
rSet.DisableItem(nWhich);
};
break;
2000-09-18 16:15:01 +00:00
case SID_UNDO:
case SID_REDO:
{
SfxUndoManager& rMgr = pTextView->GetTextEngine()->GetUndoManager();
USHORT nCount = 0;
if(nWhich == SID_UNDO)
{
nCount = rMgr.GetUndoActionCount();
if(nCount)
{
String aStr(ResId( STR_UNDO, *SFX_APP()->GetSfxResManager() ));;
2000-09-18 16:15:01 +00:00
aStr += rMgr.GetUndoActionComment(--nCount);
rSet.Put(SfxStringItem(nWhich, aStr));
}
else
rSet.DisableItem(nWhich);
}
else
{
nCount = rMgr.GetRedoActionCount();
if(nCount)
{
String aStr(ResId( STR_REDO, *SFX_APP()->GetSfxResManager() ));;
2000-09-18 16:15:01 +00:00
aStr += rMgr.GetRedoActionComment(--nCount);
rSet.Put(SfxStringItem(nWhich,aStr));
}
else
rSet.DisableItem(nWhich);
}
}
break;
case SID_MAIL_SENDDOCASPDF:
case SID_MAIL_SENDDOC :
case SID_EXPORTDOCASPDF:
case SID_DIRECTEXPORTDOCASPDF:
case SID_EXPORTDOC:
2000-09-18 16:15:01 +00:00
case SID_REPEAT:
rSet.DisableItem(nWhich);
break;
case SID_CUT:
case SID_COPY:
if(!pTextView->HasSelection())
rSet.DisableItem(nWhich);
break;
case SID_PASTE:
{
2001-05-08 18:56:30 +00:00
BOOL bDisable = 0 == SW_MOD()->pClipboard;
if( bDisable )
2000-09-18 16:15:01 +00:00
{
2001-05-08 18:56:30 +00:00
TransferableDataHelper aDataHelper(
TransferableDataHelper::CreateFromSystemClipboard(
&aEditWin) );
bDisable = !aDataHelper.GetXTransferable().is() ||
2001-05-08 18:56:30 +00:00
0 == aDataHelper.GetFormatCount();
2000-09-18 16:15:01 +00:00
}
2001-03-23 14:55:45 +00:00
if( bDisable )
2000-09-18 16:15:01 +00:00
rSet.DisableItem(nWhich);
}
break;
}
nWhich = aIter.NextWhich();
}
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
SvxSearchItem* SwSrcView::GetSearchItem()
{
if(!pSearchItem)
{
pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
}
return pSearchItem;
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
void SwSrcView::SetSearchItem( const SvxSearchItem& rItem )
{
delete pSearchItem;
pSearchItem = (SvxSearchItem*)rItem.Clone();
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
USHORT SwSrcView::StartSearchAndReplace(const SvxSearchItem& rSearchItem,
BOOL bFromStart,
BOOL bApi,
BOOL bRecursive)
{
ExtTextView* pTextView = aEditWin.GetTextView();
TextSelection aSel;
2001-03-27 20:47:24 +00:00
TextPaM aPaM;
2000-09-18 16:15:01 +00:00
BOOL bForward = !rSearchItem.GetBackward();
2001-03-27 20:47:24 +00:00
BOOL bAtStart = pTextView->GetSelection() == TextSelection( aPaM, aPaM );
if( !bForward )
aPaM = TextPaM( (ULONG)-1, (USHORT)-1 );
if( bFromStart )
2000-09-18 16:15:01 +00:00
{
aSel = pTextView->GetSelection();
2001-03-27 20:47:24 +00:00
pTextView->SetSelection( TextSelection( aPaM, aPaM ));
2000-09-18 16:15:01 +00:00
}
CWS-TOOLING: integrate CWS os121 2008-11-28 13:44:51 +0100 os r264551 : Copy Hyperlink Location added 2008-11-28 13:36:20 +0100 os r264547 : Copy Hyperlink Location added 2008-11-25 15:43:53 +0100 os r264311 : label of EditHyperlink fixed 2008-11-25 15:42:42 +0100 os r264310 : use ResetAttr to remove hyperlink 2008-11-25 10:08:02 +0100 os r264276 : edit/remove hyperlink names fixed 2008-11-11 15:47:22 +0100 os r263565 : typo fixed 2008-11-10 18:46:00 +0100 os r263536 : CWS-TOOLING: rebase CWS os121 to trunk@263288 (milestone: DEV300:m35) 2008-11-07 15:34:41 +0100 os r263422 : #i6191# accept/reject changes;#i7311# remove hyperlink 2008-11-07 15:34:05 +0100 os r263421 : #i6191# accept/reject changes;#i7311# remove hyperlink 2008-11-06 17:26:18 +0100 os r263402 : #i43971# words from online help documents must not be added to AutoCompletion 2008-11-06 16:08:27 +0100 os r263397 : #i6191# accept/reject changes added to context menu 2008-11-06 16:07:49 +0100 os r263396 : #i6191# accept/reject changes added to context menu 2008-11-06 16:07:16 +0100 os r263395 : #i6191# accept/reject changes added to context menu 2008-11-06 16:06:18 +0100 os r263394 : #i6191# accept/reject changes added to context menu 2008-10-30 14:31:32 +0100 os r262826 : #i84980# less options changed to fewer options 2008-10-30 11:44:41 +0100 os r262824 : #i95624# don't add paragraph numbering in getString() 2008-10-27 10:46:04 +0100 os r262665 : #i88235# SvCheckListBox::SelectEntryPos() paints a CheckBox to the wrong device if page is not visible, yet - call moved to ::Reset() 2008-10-24 15:49:27 +0200 os r262648 : #i77230# make repeating headers the default 2008-10-23 16:49:42 +0200 os r262625 : #i95350# RTL output of table window fixed 2008-10-23 15:37:40 +0200 os r262623 : #i76723# RTL related patch removed - it is now done by vcl 2008-10-22 14:05:58 +0200 os r262601 : #b6297019#,#i49754# LoadStyles: restore outline settings 2008-10-22 14:05:17 +0200 os r262600 : #b6297019#,#i49754# LoadStyles: restore outline settings 2008-10-20 15:39:18 +0200 os r262323 : #i95059# border attribute: which id of SID_ATTR_BORDER_INNER fixed 2008-10-20 09:30:28 +0200 os r262305 : #i95123# conflict css::util::Color and ::Color solved 2008-10-17 11:44:16 +0200 os r262280 : #i93714# merge to PDF: convert fields to text before export 2008-10-17 10:30:11 +0200 os r262275 : #i94364# 2008-10-17 10:11:56 +0200 os r262274 : +i94536# default font ListBoxes: prevent entry duplication if 'Back' button is pressed
2008-12-09 07:49:49 +00:00
util::SearchOptions aSearchOpt( rSearchItem.GetSearchOptions() );
aSearchOpt.Locale = SvxCreateLocale(
static_cast< LanguageType >( GetAppLanguage() ) );
2001-03-27 20:47:24 +00:00
USHORT nFound;
BOOL bAll = FALSE;
switch( rSearchItem.GetCommand() )
2000-09-18 16:15:01 +00:00
{
2001-03-27 20:47:24 +00:00
case SVX_SEARCHCMD_FIND:
case SVX_SEARCHCMD_FIND_ALL:
nFound = pTextView->Search( aSearchOpt, bForward );
2001-03-27 20:47:24 +00:00
break;
case SVX_SEARCHCMD_REPLACE_ALL: bAll = TRUE;
case SVX_SEARCHCMD_REPLACE:
nFound = pTextView->Replace( aSearchOpt, bAll, bForward );
break;
2001-03-27 20:47:24 +00:00
default:
nFound = 0;
2000-09-18 16:15:01 +00:00
}
2001-03-27 20:47:24 +00:00
if( !nFound )
2000-09-18 16:15:01 +00:00
{
BOOL bNotFoundMessage = FALSE;
if(!bRecursive)
{
if(!bFromStart)
{
bNotFoundMessage = bAtStart;
}
else
{
bNotFoundMessage = TRUE;
pTextView->SetSelection( aSel );
}
}
else if(bAtStart)
{
bNotFoundMessage = TRUE;
}
if(!bApi)
if(bNotFoundMessage)
{
InfoBox( 0, SW_RES(MSG_NOT_FOUND)).Execute();
}
else if(!bRecursive && RET_YES ==
QueryBox(0, SW_RES( bForward ? MSG_SEARCH_END
: MSG_SEARCH_START)).Execute())
{
2001-03-27 20:47:24 +00:00
pTextView->SetSelection( TextSelection( aPaM, aPaM ) );
StartSearchAndReplace( rSearchItem, FALSE, FALSE, TRUE );
2000-09-18 16:15:01 +00:00
}
}
return nFound;
}
/*-----------------02.07.97 09:29-------------------
--------------------------------------------------*/
USHORT SwSrcView::SetPrinter(SfxPrinter* pNew, USHORT nDiffFlags, bool )
2000-09-18 16:15:01 +00:00
{
SwDocShell* pDocSh = GetDocShell();
if ( (SFX_PRINTER_JOBSETUP | SFX_PRINTER_PRINTER) & nDiffFlags )
{
pDocSh->GetDoc()->setPrinter( pNew, true, true );
2000-09-18 16:15:01 +00:00
if ( nDiffFlags & SFX_PRINTER_PRINTER )
pDocSh->SetModified();
}
if ( nDiffFlags & SFX_PRINTER_OPTIONS )
::SetPrinter( pDocSh->getIDocumentDeviceAccess(), pNew, TRUE );
2000-09-18 16:15:01 +00:00
const BOOL bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ? TRUE : FALSE;
const BOOL bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE ? TRUE : FALSE;
if ( bChgOri || bChgSize )
{
pDocSh->SetModified();
}
return 0;
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
ErrCode SwSrcView::DoPrint( SfxPrinter *pPrinter, PrintDialog *pDlg, BOOL bSilent, BOOL bIsAPI )
2000-09-18 16:15:01 +00:00
{
SfxPrintProgress *pProgress = new SfxPrintProgress( this, !bSilent );
SfxPrinter *pDocPrinter = GetPrinter(TRUE);
if ( !pPrinter )
pPrinter = pDocPrinter;
else if ( pDocPrinter != pPrinter )
{
pProgress->RestoreOnEndPrint( pDocPrinter->Clone() );
SetPrinter( pPrinter, SFX_PRINTER_PRINTER );
}
pProgress->SetWaitMode(FALSE);
// Drucker starten
PreparePrint( pDlg );
SfxViewShell::Print(*pProgress, bIsAPI, pDlg ); //???
2000-09-18 16:15:01 +00:00
MapMode eOldMapMode( pPrinter->GetMapMode() );
Font aOldFont( pPrinter->Printer::GetFont() );
TextEngine* pTextEngine = aEditWin.GetTextEngine();
pPrinter->SetMapMode(MAP_100TH_MM);
Font aFont(aEditWin.GetOutWin()->GetFont());
Size aSize(aFont.GetSize());
aSize = aEditWin.GetOutWin()->PixelToLogic(aSize, MAP_100TH_MM);
aFont.SetSize(aSize);
aFont.SetColor(COL_BLACK);
pPrinter->SetFont( aFont );
String aTitle( GetViewFrame()->GetWindow().GetText() );
USHORT nLineHeight = (USHORT) pPrinter->GetTextHeight(); // etwas mehr.
USHORT nParaSpace = 10;
Size aPaperSz = pPrinter->GetOutputSize();
aPaperSz.Width() -= (LMARGPRN+RMARGPRN);
aPaperSz.Height() -= (TMARGPRN+BMARGPRN);
// nLinepPage stimmt nicht, wenn Zeilen umgebrochen werden muessen...
USHORT nLinespPage = (USHORT) (aPaperSz.Height()/nLineHeight);
USHORT nCharspLine = (USHORT) (aPaperSz.Width() / pPrinter->GetTextWidth( 'X' ));
USHORT nParas = static_cast< USHORT >( pTextEngine->GetParagraphCount() );
2000-09-18 16:15:01 +00:00
USHORT nPages = (USHORT) (nParas/nLinespPage+1 );
USHORT nCurPage = 1;
BOOL bStartJob = pPrinter->StartJob( aTitle );
if( bStartJob )
{
pPrinter->StartPage();
// Header drucken...
lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle );
Point aPos( LMARGPRN, TMARGPRN );
for ( USHORT nPara = 0; nPara < nParas; nPara++ )
{
String aLine( pTextEngine->GetText( nPara ) );
lcl_ConvertTabsToSpaces( aLine );
USHORT nLines = aLine.Len()/nCharspLine+1;
for ( USHORT nLine = 0; nLine < nLines; nLine++ )
{
String aTmpLine( aLine, nLine*nCharspLine, nCharspLine );
aPos.Y() += nLineHeight;
if ( aPos.Y() > ( aPaperSz.Height()+TMARGPRN ) )
{
nCurPage++;
pPrinter->EndPage();
pPrinter->StartPage();
lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle );
aPos = Point( LMARGPRN, TMARGPRN+nLineHeight );
}
pPrinter->DrawText( aPos, aTmpLine );
}
aPos.Y() += nParaSpace;
}
pPrinter->EndPage();
}
pPrinter->SetFont( aOldFont );
pPrinter->SetMapMode( eOldMapMode );
if ( !bStartJob )
{
// Printer konnte nicht gestartet werden
delete pProgress;
return ERRCODE_IO_ABORT;
}
pProgress->Stop();
pProgress->DeleteOnEndPrint();
pPrinter->EndJob();
return pPrinter->GetError();
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
2000-10-06 12:41:54 +00:00
SfxPrinter* SwSrcView::GetPrinter( BOOL bCreate )
2000-09-18 16:15:01 +00:00
{
return GetDocShell()->GetDoc()->getPrinter( bCreate );
2000-09-18 16:15:01 +00:00
}
/*--------------------------------------------------------------------
Beschreibung:
--------------------------------------------------------------------*/
2000-10-06 12:41:54 +00:00
void SwSrcView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
2000-09-18 16:15:01 +00:00
{
if ( rHint.ISA(SfxSimpleHint) &&
(((SfxSimpleHint&) rHint).GetId() == SFX_HINT_MODECHANGED) ||
(((SfxSimpleHint&) rHint).GetId() == SFX_HINT_TITLECHANGED &&
!GetDocShell()->IsReadOnly() && aEditWin.IsReadonly()))
{
// Broadcast kommt nur einmal!
const SwDocShell* pDocSh = GetDocShell();
const BOOL bReadonly = pDocSh->IsReadOnly();
aEditWin.SetReadonly(bReadonly);
}
SfxViewShell::Notify(rBC, rHint);
}
/*-----------------19.04.97 10:19-------------------
--------------------------------------------------*/
void SwSrcView::Load(SwDocShell* pDocShell)
{
SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get();
2000-09-18 16:15:01 +00:00
const sal_Char *pCharSet =
2001-07-26 04:53:10 +00:00
rtl_getBestMimeCharsetFromTextEncoding( pHtmlOptions->GetTextEncoding() );
2000-09-18 16:15:01 +00:00
rtl_TextEncoding eDestEnc = rtl_getTextEncodingFromMimeCharset( pCharSet );
2001-07-26 04:53:10 +00:00
2000-09-18 16:15:01 +00:00
aEditWin.SetReadonly(pDocShell->IsReadOnly());
aEditWin.SetTextEncoding(eDestEnc);
2000-09-18 16:15:01 +00:00
SfxMedium* pMedium = pDocShell->GetMedium();
const SfxFilter* pFilter = pMedium->GetFilter();
2001-07-10 07:51:04 +00:00
BOOL bHtml = pFilter && pFilter->GetUserData().EqualsAscii("HTML");
2000-09-18 16:15:01 +00:00
BOOL bDocModified = pDocShell->IsModified();
if(bHtml && !bDocModified && pDocShell->HasName())
{
SvStream* pStream = pMedium->GetInStream();
if(pStream && 0 == pStream->GetError() )
{
rtl_TextEncoding eHeaderEnc =
SfxHTMLParser::GetEncodingByHttpHeader(
pDocShell->GetHeaderAttributes() );
if( RTL_TEXTENCODING_DONTKNOW == eHeaderEnc )
{
const sal_Char *pTmpCharSet =
rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1 );
eHeaderEnc = rtl_getTextEncodingFromMimeCharset( pTmpCharSet );
}
if( RTL_TEXTENCODING_DONTKNOW != eHeaderEnc &&
eDestEnc != eHeaderEnc )
{
eDestEnc = eHeaderEnc;
aEditWin.SetTextEncoding(eDestEnc);
}
2000-09-18 16:15:01 +00:00
pStream->SetStreamCharSet( eDestEnc );
pStream->Seek(0);
TextEngine* pTextEngine = aEditWin.GetTextEngine();
pTextEngine->EnableUndo(FALSE);
2000-09-18 16:15:01 +00:00
aEditWin.Read(*pStream);//, EE_FORMAT_TEXT);
pTextEngine->EnableUndo(TRUE);
2000-09-18 16:15:01 +00:00
}
else
{
Window *pTmpWindow = &GetViewFrame()->GetWindow();
InfoBox(pTmpWindow, SW_RES(MSG_ERR_SRCSTREAM)).Execute();
2000-09-18 16:15:01 +00:00
}
}
else
{
2000-11-06 08:30:33 +00:00
utl::TempFile aTempFile;
2000-09-18 16:15:01 +00:00
aTempFile.EnableKillingFile();
String sFileURL( aTempFile.GetURL() );
2000-10-06 12:41:54 +00:00
SvtSaveOptions aOpt;
2000-09-18 16:15:01 +00:00
{
SfxMedium aMedium( sFileURL,STREAM_READWRITE, TRUE );
SwWriter aWriter( aMedium, *pDocShell->GetDoc() );
WriterRef xWriter;
::GetHTMLWriter(aEmptyStr, aMedium.GetBaseURL( true ), xWriter);
2000-09-18 16:15:01 +00:00
String sWriteName = pDocShell->HasName() ?
pMedium->GetName() :
(const String&) sFileURL;
ULONG nRes = aWriter.Write(xWriter, &sWriteName);
if(nRes)
{
ErrorHandler::HandleError(ErrCode(nRes));
aEditWin.SetReadonly(TRUE);
}
aMedium.Commit();
2000-09-18 16:15:01 +00:00
SvStream* pInStream = aMedium.GetInStream();
pInStream->Seek(0);
pInStream->SetStreamCharSet( eDestEnc );
aEditWin.Read(*pInStream);//, EE_FORMAT_TEXT);
}
}
aEditWin.ClearModifyFlag();
eLoadEncoding = eDestEnc;
2000-09-18 16:15:01 +00:00
if(bDocModified)
pDocShell->SetModified();// das Flag wird zwischendurch zurueckgesetzt
// AutoLoad abschalten
pDocShell->SetAutoLoad(INetURLObject(), 0, FALSE);
DBG_ASSERT(PTR_CAST(SwWebDocShell, pDocShell), "Wieso keine WebDocShell?");
2000-09-18 16:15:01 +00:00
USHORT nLine = ((SwWebDocShell*)pDocShell)->GetSourcePara();
aEditWin.SetStartLine(nLine);
aEditWin.GetTextEngine()->ResetUndo();
aEditWin.GetOutWin()->GrabFocus();
}