diff options
Diffstat (limited to 'sw/source/uibase/app')
-rw-r--r-- | sw/source/uibase/app/appenv.cxx | 508 | ||||
-rw-r--r-- | sw/source/uibase/app/apphdl.cxx | 898 | ||||
-rw-r--r-- | sw/source/uibase/app/applab.cxx | 413 | ||||
-rw-r--r-- | sw/source/uibase/app/appopt.cxx | 528 | ||||
-rw-r--r-- | sw/source/uibase/app/docsh.cxx | 1328 | ||||
-rw-r--r-- | sw/source/uibase/app/docsh2.cxx | 1584 | ||||
-rw-r--r-- | sw/source/uibase/app/docshdrw.cxx | 55 | ||||
-rw-r--r-- | sw/source/uibase/app/docshini.cxx | 683 | ||||
-rw-r--r-- | sw/source/uibase/app/docst.cxx | 1279 | ||||
-rw-r--r-- | sw/source/uibase/app/docstyle.cxx | 2980 | ||||
-rw-r--r-- | sw/source/uibase/app/mainwn.cxx | 141 | ||||
-rw-r--r-- | sw/source/uibase/app/swdll.cxx | 164 | ||||
-rw-r--r-- | sw/source/uibase/app/swdllimpl.hxx | 36 | ||||
-rw-r--r-- | sw/source/uibase/app/swmodul1.cxx | 659 | ||||
-rw-r--r-- | sw/source/uibase/app/swmodule.cxx | 421 | ||||
-rw-r--r-- | sw/source/uibase/app/swwait.cxx | 84 |
16 files changed, 11761 insertions, 0 deletions
diff --git a/sw/source/uibase/app/appenv.cxx b/sw/source/uibase/app/appenv.cxx new file mode 100644 index 000000000000..afce13a19041 --- /dev/null +++ b/sw/source/uibase/app/appenv.cxx @@ -0,0 +1,508 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <cstdarg> + +#include <hintids.hxx> + +#include <comphelper/string.hxx> +#include <sfx2/request.hxx> +#include <svx/svxids.hrc> + +#include <svtools/svmedit.hxx> +#include <vcl/svapp.hxx> +#include <vcl/wrkwin.hxx> +#include <sfx2/app.hxx> +#include <sfx2/docfac.hxx> +#include <sfx2/printer.hxx> +#include <vcl/msgbox.hxx> +#include <sfx2/dispatch.hxx> +#include <editeng/boxitem.hxx> +#include <editeng/lrspitem.hxx> +#include <editeng/ulspitem.hxx> +#include <editeng/pbinitem.hxx> +#include <editeng/paperinf.hxx> +#include <editeng/formatbreakitem.hxx> +#include <fmthdft.hxx> +#include <swwait.hxx> +#include <paratr.hxx> +#include <swmodule.hxx> +#include <wrtsh.hxx> +#include <view.hxx> +#include <docsh.hxx> +#include <frmatr.hxx> +#include <fldbas.hxx> +#include <swundo.hxx> +#include <IDocumentDeviceAccess.hxx> +#include <dbmgr.hxx> +#include <fmtcol.hxx> +#include <frmmgr.hxx> +#include <fldmgr.hxx> +#include <pagedesc.hxx> +#include <poolfmt.hxx> +#include <expfld.hxx> +#include <SwStyleNameMapper.hxx> +#include <crsskip.hxx> + +#include <cmdid.h> +#include <globals.hrc> +#include <app.hrc> +#include <poolfmt.hrc> +#include "swabstdlg.hxx" +#include "envelp.hrc" +#include "envimg.hxx" + +#include <boost/scoped_ptr.hpp> + +#define ENV_NEWDOC RET_OK +#define ENV_INSERT RET_USER + +// Function used for labels and envelopes in applab.cxx and appenv.cxx +OUString InsertLabEnvText( SwWrtShell& rSh, SwFldMgr& rFldMgr, const OUString& rText ) +{ + OUString sRet; + OUString aText(comphelper::string::remove(rText, '\r')); + + sal_Int32 nTokenPos = 0; + while( -1 != nTokenPos ) + { + OUString aLine = aText.getToken( 0, '\n', nTokenPos ); + while ( !aLine.isEmpty() ) + { + OUString sTmpText; + bool bField = false; + + sal_Int32 nPos = aLine.indexOf( '<' ); + if (0 != nPos) + { + sal_Int32 const nCopy((nPos != -1) ? nPos : aLine.getLength()); + sTmpText = aLine.copy(0, nCopy); + aLine = aLine.copy(nCopy); + } + else + { + nPos = aLine.indexOf( '>' ); + if ( nPos == -1 ) + { + sTmpText = aLine; + aLine = ""; + } + else + { + sTmpText = aLine.copy( 0, nPos + 1); + aLine = aLine.copy( nPos + 1); + + // Database fields must contain at least 3 points! + OUString sDBName( sTmpText.copy( 1, sTmpText.getLength() - 2)); + sal_uInt16 nCnt = comphelper::string::getTokenCount(sDBName, '.'); + if (nCnt >= 3) + { + sDBName = ::ReplacePoint(sDBName, true); + SwInsertFld_Data aData(TYP_DBFLD, 0, sDBName, aEmptyOUStr, 0, &rSh ); + rFldMgr.InsertFld( aData ); + sRet = sDBName; + bField = true; + } + } + } + if ( !bField ) + rSh.Insert( sTmpText ); + } + rSh.InsertLineBreak(); + } + rSh.DelLeft(); // Again remove last linebreak + + return sRet; +} + +static void lcl_CopyCollAttr(SwWrtShell* pOldSh, SwWrtShell* pNewSh, sal_uInt16 nCollId) +{ + sal_uInt16 nCollCnt = pOldSh->GetTxtFmtCollCount(); + SwTxtFmtColl* pColl; + for( sal_uInt16 nCnt = 0; nCnt < nCollCnt; ++nCnt ) + if(nCollId == (pColl = &pOldSh->GetTxtFmtColl(nCnt))->GetPoolFmtId()) + pNewSh->GetTxtCollFromPool(nCollId)->SetFmtAttr(pColl->GetAttrSet()); +} + +void SwModule::InsertEnv( SfxRequest& rReq ) +{ + static sal_uInt16 nTitleNo = 0; + + SwDocShell *pMyDocSh; + SfxViewFrame *pFrame; + SwView *pNewView; + SwWrtShell *pOldSh, + *pSh; + + // Get current shell + pMyDocSh = (SwDocShell*) SfxObjectShell::Current(); + pOldSh = pMyDocSh ? pMyDocSh->GetWrtShell() : 0; + + // Create new document (don't show!) + SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD ) ); + xDocSh->DoInitNew( 0 ); + pFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 ); + pNewView = (SwView*) pFrame->GetViewShell(); + pNewView->AttrChangedNotify( &pNewView->GetWrtShell() ); // so that SelectShell is being called + pSh = pNewView->GetWrtShellPtr(); + + OUString aTmp( SW_RES(STR_ENV_TITLE) ); + aTmp += OUString::number( ++nTitleNo ); + xDocSh->SetTitle( aTmp ); + + // if applicable, copy the old Collections "Sender" and "Receiver" to + // a new document + if ( pOldSh ) + { + ::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_JAKETADRESS); + ::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_SENDADRESS); + } + + // Read SwEnvItem from config + SwEnvCfgItem aEnvCfg; + + // Check if there's already an envelope. + bool bEnvChange = false; + + SfxItemSet aSet(GetPool(), FN_ENVELOP, FN_ENVELOP, 0); + aSet.Put(aEnvCfg.GetItem()); + + SfxPrinter* pTempPrinter = pSh->getIDocumentDeviceAccess()->getPrinter( true ); + if(pOldSh ) + { + const SwPageDesc& rCurPageDesc = pOldSh->GetPageDesc(pOldSh->GetCurPageDesc()); + OUString sJacket; + SwStyleNameMapper::FillUIName( RES_POOLPAGE_JAKET, sJacket ); + bEnvChange = rCurPageDesc.GetName() == sJacket; + + IDocumentDeviceAccess* pIDDA_old = pOldSh->getIDocumentDeviceAccess(); + if( pIDDA_old->getPrinter( false ) ) + { + IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess(); + pIDDA->setJobsetup( *pIDDA_old->getJobsetup() ); + //#69563# if it isn't the same printer then the pointer has been invalidated! + pTempPrinter = pIDDA->getPrinter( true ); + } + pTempPrinter->SetPaperBin(rCurPageDesc.GetMaster().GetPaperBin().GetValue()); + + } + + Window *pParent = pOldSh ? pOldSh->GetWin() : 0; + boost::scoped_ptr<SfxAbstractTabDialog> pDlg; + short nMode = ENV_INSERT; + + SFX_REQUEST_ARG( rReq, pItem, SwEnvItem, FN_ENVELOP, false ); + if ( !pItem ) + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!"); + + pDlg.reset(pFact->CreateSwEnvDlg( pParent, aSet, pOldSh, pTempPrinter, !bEnvChange )); + OSL_ENSURE(pDlg, "Dialogdiet fail!"); + nMode = pDlg->Execute(); + } + else + { + SFX_REQUEST_ARG( rReq, pBoolItem, SfxBoolItem, FN_PARAM_1, false ); + if ( pBoolItem && pBoolItem->GetValue() ) + nMode = ENV_NEWDOC; + } + + if (nMode == ENV_NEWDOC || nMode == ENV_INSERT) + { + SwWait aWait( (SwDocShell&)*xDocSh, true ); + + // Read dialog and save item to config + const SwEnvItem& rItem = pItem ? *pItem : (const SwEnvItem&) pDlg->GetOutputItemSet()->Get(FN_ENVELOP); + aEnvCfg.GetItem() = rItem; + aEnvCfg.Commit(); + + // When we print we take the Jobsetup that is set up in the dialog. + // Information has to be set here, before a possible destruction of + // the new shell because the shell's printer has been handed to the + // dialog. + if ( nMode != ENV_NEWDOC ) + { + OSL_ENSURE(pOldSh, "No document - wasn't 'Insert' disabled???"); + SvxPaperBinItem aItem( RES_PAPER_BIN ); + aItem.SetValue((sal_uInt8)pSh->getIDocumentDeviceAccess()->getPrinter(true)->GetPaperBin()); + pOldSh->GetPageDescFromPool(RES_POOLPAGE_JAKET)->GetMaster().SetFmtAttr(aItem); + } + + SwWrtShell *pTmp = nMode == ENV_INSERT ? pOldSh : pSh; + const SwPageDesc* pFollow = 0; + SwTxtFmtColl *pSend = pTmp->GetTxtCollFromPool( RES_POOLCOLL_SENDADRESS ), + *pAddr = pTmp->GetTxtCollFromPool( RES_POOLCOLL_JAKETADRESS); + const OUString sSendMark = pSend->GetName(); + const OUString sAddrMark = pAddr->GetName(); + + if (nMode == ENV_INSERT) + { + + SetView(&pOldSh->GetView()); // Set pointer to top view + + // Delete new document + xDocSh->DoClose(); + pSh = pOldSh; + //#i4251# selected text or objects in the document should + //not be deleted on inserting envelopes + pSh->EnterStdMode(); + // Here it goes (insert) + pSh->StartUndo(UNDO_UI_INSERT_ENVELOPE, NULL); + pSh->StartAllAction(); + pSh->SttEndDoc(true); + + if (bEnvChange) + { + // followup template: page 2 + pFollow = pSh->GetPageDesc(pSh->GetCurPageDesc()).GetFollow(); + + // Delete text from the first page + if ( !pSh->SttNxtPg(true) ) + pSh->EndPg(true); + pSh->DelRight(); + // Delete frame of the first page + if ( pSh->GotoFly(sSendMark) ) + { + pSh->EnterSelFrmMode(); + pSh->DelRight(); + } + if ( pSh->GotoFly(sAddrMark) ) + { + pSh->EnterSelFrmMode(); + pSh->DelRight(); + } + pSh->SttEndDoc(true); + } + else + // Followup template: page 1 + pFollow = &pSh->GetPageDesc(pSh->GetCurPageDesc()); + + // Insert page break + if ( pSh->IsCrsrInTbl() ) + { + pSh->SplitNode(); + pSh->Right( CRSR_SKIP_CHARS, false, 1, false ); + SfxItemSet aBreakSet( pSh->GetAttrPool(), RES_BREAK, RES_BREAK, 0 ); + aBreakSet.Put( SvxFmtBreakItem(SVX_BREAK_PAGE_BEFORE, RES_BREAK) ); + pSh->SetTblAttr( aBreakSet ); + } + else + pSh->InsertPageBreak(0, boost::none); + pSh->SttEndDoc(true); + } + else + { + pFollow = &pSh->GetPageDesc(pSh->GetCurPageDesc()); + // Let's go (print) + pSh->StartAllAction(); + pSh->DoUndo(false); + + // Again, copy the new collections "Sender" and "Receiver" to + // a new document + if ( pOldSh ) + { + ::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_JAKETADRESS); + ::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_SENDADRESS); + } + } + + SET_CURR_SHELL(pSh); + pSh->SetNewDoc(); // Avoid performance problems + + // Remember Flys of this site + std::vector<SwFrmFmt*> aFlyArr; + if( ENV_NEWDOC != nMode && !bEnvChange ) + pSh->GetPageObjs( aFlyArr ); + + // Get page description + SwPageDesc* pDesc = pSh->GetPageDescFromPool(RES_POOLPAGE_JAKET); + SwFrmFmt& rFmt = pDesc->GetMaster(); + + Printer *pPrt = pSh->getIDocumentDeviceAccess()->getPrinter( true ); + + // Borders (are put together by Shift-Offset and alignment) + Size aPaperSize = pPrt->PixelToLogic( pPrt->GetPaperSizePixel(), + MAP_TWIP); + if ( !aPaperSize.Width() && !aPaperSize.Height() ) + aPaperSize = SvxPaperInfo::GetPaperSize(PAPER_A4); + if ( aPaperSize.Width() > aPaperSize.Height() ) + Swap( aPaperSize ); + + long lLeft = rItem.lShiftRight, + lUpper = rItem.lShiftDown; + + sal_uInt16 nPageW = (sal_uInt16) std::max(rItem.lWidth, rItem.lHeight), + nPageH = (sal_uInt16) std::min(rItem.lWidth, rItem.lHeight); + + switch (rItem.eAlign) + { + case ENV_HOR_LEFT: break; + case ENV_HOR_CNTR: lLeft += std::max(0L, long(aPaperSize.Width() - nPageW)) / 2; + break; + case ENV_HOR_RGHT: lLeft += std::max(0L, long(aPaperSize.Width() - nPageW)); + break; + case ENV_VER_LEFT: lUpper += std::max(0L, long(aPaperSize.Width() - nPageH)); + break; + case ENV_VER_CNTR: lUpper += std::max(0L, long(aPaperSize.Width() - nPageH)) / 2; + break; + case ENV_VER_RGHT: break; + } + SvxLRSpaceItem aLRMargin( RES_LR_SPACE ); + SvxULSpaceItem aULMargin( RES_UL_SPACE ); + aLRMargin.SetLeft ((sal_uInt16) lLeft ); + aULMargin.SetUpper((sal_uInt16) lUpper); + aLRMargin.SetRight(0); + aULMargin.SetLower(0); + rFmt.SetFmtAttr(aLRMargin); + rFmt.SetFmtAttr(aULMargin); + + // Header and footer + rFmt.SetFmtAttr(SwFmtHeader(false)); + pDesc->ChgHeaderShare(false); + rFmt.SetFmtAttr(SwFmtFooter(false)); + pDesc->ChgFooterShare(false); + + // Page numbering + pDesc->SetUseOn(nsUseOnPage::PD_ALL); + + // Page size + rFmt.SetFmtAttr(SwFmtFrmSize(ATT_FIX_SIZE, + nPageW + lLeft, nPageH + lUpper)); + + // Set type of page numbering + SvxNumberType aType; + aType.SetNumberingType(SVX_NUM_NUMBER_NONE); + pDesc->SetNumType(aType); + + // Followup template + if (pFollow) + pDesc->SetFollow(pFollow); + + // Landscape + pDesc->SetLandscape( rItem.eAlign >= ENV_VER_LEFT && + rItem.eAlign <= ENV_VER_RGHT); + + // Apply page description + + sal_uInt16 nPos; + pSh->FindPageDescByName( pDesc->GetName(), + false, + &nPos ); + + pSh->ChgPageDesc( nPos, *pDesc); + pSh->ChgCurPageDesc(*pDesc); + + // Insert Frame + SwFlyFrmAttrMgr aMgr(false, pSh, FRMMGR_TYPE_ENVELP); + SwFldMgr aFldMgr; + aMgr.SetHeightSizeType(ATT_VAR_SIZE); + + // Overwrite defaults! + aMgr.GetAttrSet().Put( SvxBoxItem(RES_BOX) ); + aMgr.SetULSpace( 0L, 0L ); + aMgr.SetLRSpace( 0L, 0L ); + + // Sender + if (rItem.bSend) + { + pSh->SttEndDoc(true); + aMgr.InsertFlyFrm(FLY_AT_PAGE, + Point(rItem.lSendFromLeft + lLeft, rItem.lSendFromTop + lUpper), + Size (rItem.lAddrFromLeft - rItem.lSendFromLeft, 0)); + + pSh->EnterSelFrmMode(); + pSh->SetFlyName(sSendMark); + pSh->UnSelectFrm(); + pSh->LeaveSelFrmMode(); + pSh->SetTxtFmtColl( pSend ); + InsertLabEnvText( *pSh, aFldMgr, rItem.aSendText ); + aMgr.UpdateAttrMgr(); + } + + // Addressee + pSh->SttEndDoc(true); + + aMgr.InsertFlyFrm(FLY_AT_PAGE, + Point(rItem.lAddrFromLeft + lLeft, rItem.lAddrFromTop + lUpper), + Size (nPageW - rItem.lAddrFromLeft - 566, 0)); + pSh->EnterSelFrmMode(); + pSh->SetFlyName(sAddrMark); + pSh->UnSelectFrm(); + pSh->LeaveSelFrmMode(); + pSh->SetTxtFmtColl( pAddr ); + InsertLabEnvText(*pSh, aFldMgr, rItem.aAddrText); + + // Move Flys to the "old" pages + if (!aFlyArr.empty()) + pSh->SetPageObjsNewPage(aFlyArr, 1); + + // Finished + pSh->SttEndDoc(true); + + pSh->EndAllAction(); + + if (nMode == ENV_NEWDOC) + pSh->DoUndo(true); + else + pSh->EndUndo(UNDO_UI_INSERT_ENVELOPE); + + if (nMode == ENV_NEWDOC) + { + pFrame->GetFrame().Appear(); + + if ( rItem.aAddrText.indexOf('<') >= 0 ) + { + static sal_uInt16 const aInva[] = + { + SID_SBA_BRW_UPDATE, + SID_SBA_BRW_INSERT, + SID_SBA_BRW_MERGE, + 0 + }; + pFrame->GetBindings().Invalidate( aInva ); + + // Open database beamer + ShowDBObj(*pNewView, pSh->GetDBData()); + } + } + + if ( !pItem ) + { + rReq.AppendItem( rItem ); + if ( nMode == ENV_NEWDOC ) + rReq.AppendItem( SfxBoolItem( FN_PARAM_1, true ) ); + } + + rReq.Done(); + } + else // Abort + { + rReq.Ignore(); + + xDocSh->DoClose(); + --nTitleNo; + + // Set pointer to top view + if (pOldSh) + SetView(&pOldSh->GetView()); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx new file mode 100644 index 000000000000..502a336d633a --- /dev/null +++ b/sw/source/uibase/app/apphdl.cxx @@ -0,0 +1,898 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <config_features.h> + +#include <hintids.hxx> + +#include <osl/diagnose.h> +#include <tools/link.hxx> +#include <svl/urihelper.hxx> +#include <unotools/pathoptions.hxx> +#include <svtools/accessibilityoptions.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/event.hxx> +#include <sfx2/objitem.hxx> +#include <svx/dataaccessdescriptor.hxx> +#include <svl/srchitem.hxx> +#include <svtools/colorcfg.hxx> +#include <svl/eitem.hxx> +#include <svl/whiter.hxx> +#include <svl/isethint.hxx> +#include <sfx2/request.hxx> +#include <sfx2/fcontnr.hxx> +#include <svl/stritem.hxx> +#include <svl/ctloptions.hxx> +#include <unotools/useroptions.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/wrkwin.hxx> +#include <svx/insctrl.hxx> +#include <svx/selctrl.hxx> +#include <com/sun/star/document/UpdateDocMode.hpp> +#include <sfx2/docfile.hxx> +#include <svx/xmlsecctrl.hxx> +#include <navicfg.hxx> + +#include <sfx2/objface.hxx> +#include <sfx2/app.hxx> + +#include <view.hxx> +#include <pview.hxx> +#include <srcview.hxx> +#include <wrtsh.hxx> +#include <docsh.hxx> +#include <cmdid.h> +#include <initui.hxx> +#include <uitool.hxx> +#include <swmodule.hxx> +#include <wdocsh.hxx> +#include <wview.hxx> +#include <usrpref.hxx> +#include <gloslst.hxx> +#include <glosdoc.hxx> +#include <doc.hxx> +#include <IDocumentUndoRedo.hxx> +#include <cfgitems.hxx> +#include <prtopt.hxx> +#include <modcfg.hxx> +#include <globals.h> +#include <app.hrc> +#include <fontcfg.hxx> +#include <barcfg.hxx> +#include <uinums.hxx> +#include <dbconfig.hxx> +#include <mmconfigitem.hxx> +#include <mailmergechildwindow.hxx> +#include <linguistic/lngprops.hxx> +#include <editeng/unolingu.hxx> +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include <com/sun/star/beans/XFastPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/beans/XPropertyStateChangeListener.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/beans/XPropertyAccess.hpp> +#include <com/sun/star/beans/XPropertyContainer.hpp> +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> +#include <com/sun/star/sdbc/XDataSource.hpp> +#include <swabstdlg.hxx> + +#include <vcl/status.hxx> + +#include <salhelper/simplereferenceobject.hxx> +#include <rtl/ref.hxx> + +#include <unomid.h> + +using namespace ::com::sun::star; + +// Slotmaps for the application's methods + +// here are the SlotID's being included +// see Idl-file +#define SwModule +#include <sfx2/msg.hxx> +#include "swslots.hxx" +#include <cfgid.h> + +#include <shells.hrc> + +SFX_IMPL_INTERFACE(SwModule, SfxModule, SW_RES(RID_SW_NAME) ) + +void SwModule::InitInterface_Impl() +{ + GetStaticInterface()->RegisterStatusBar(SW_RES(CFG_STATUSBAR)); + + GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_DESKTOP | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_CLIENT | SFX_VISIBILITY_VIEWER, + SW_RES(RID_MODULE_TOOLBOX)); +} + +// other states +void SwModule::StateOther(SfxItemSet &rSet) +{ + SfxWhichIter aIter(rSet); + sal_uInt16 nWhich = aIter.FirstWhich(); + + SwView* pActView = ::GetActiveView(); + bool bWebView = 0 != PTR_CAST(SwWebView, pActView); + + while(nWhich) + { + switch(nWhich) + { + case FN_BUSINESS_CARD: + case FN_LABEL: + case FN_ENVELOP: + { + bool bDisable = false; + SfxViewShell* pCurrView = SfxViewShell::Current(); + if( !pCurrView || (pCurrView && !pCurrView->ISA(SwView)) ) + bDisable = true; + SwDocShell *pDocSh = (SwDocShell*) SfxObjectShell::Current(); + if ( bDisable || + (pDocSh && (pDocSh->IsReadOnly() || + pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED)) ) + rSet.DisableItem( nWhich ); + + } + break; + case FN_XFORMS_INIT: + // slot is always active! + break; + case FN_EDIT_FORMULA: + { + SwWrtShell* pSh = 0; + int nSelection = 0; + if( pActView ) + pSh = &pActView->GetWrtShell(); + if( pSh ) + nSelection = pSh->GetSelectionType(); + + if( (pSh && pSh->HasSelection()) || + !(nSelection & (nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL))) + rSet.DisableItem(nWhich); + } + break; + case SID_ATTR_METRIC: + rSet.Put( SfxUInt16Item( SID_ATTR_METRIC, static_cast< sal_uInt16 >(::GetDfltMetric(bWebView)))); + break; + case FN_SET_MODOPT_TBLNUMFMT: + rSet.Put( SfxBoolItem( nWhich, pModuleConfig-> + IsInsTblFormatNum( bWebView ))); + break; + default: + OSL_FAIL("::StateOther: default"); + } + nWhich = aIter.NextWhich(); + } +} + +// start field dialog +void NewXForms( SfxRequest& rReq ); // implementation: below + +#if HAVE_FEATURE_DBCONNECTIVITY + +namespace +{ + +SwView* lcl_LoadDoc(SwView* pView, const OUString& rURL) +{ + SwView* pNewView = 0; + if(!rURL.isEmpty()) + { + SfxStringItem aURL(SID_FILE_NAME, rURL); + SfxStringItem aTargetFrameName( SID_TARGETNAME, OUString("_blank") ); + SfxBoolItem aHidden( SID_HIDDEN, true ); + SfxStringItem aReferer(SID_REFERER, pView->GetDocShell()->GetTitle()); + SfxObjectItem* pItem = (SfxObjectItem*)pView->GetViewFrame()->GetDispatcher()-> + Execute(SID_OPENDOC, SFX_CALLMODE_SYNCHRON, + &aURL, &aHidden, &aReferer, &aTargetFrameName, 0L); + SfxShell* pShell = pItem ? pItem->GetShell() : 0; + + if(pShell) + { + SfxViewShell* pViewShell = pShell->GetViewShell(); + if(pViewShell) + { + if( pViewShell->ISA(SwView) ) + { + pNewView = PTR_CAST(SwView,pViewShell); + pNewView->GetViewFrame()->GetFrame().Appear(); + } + else + { + pViewShell->GetViewFrame()->DoClose(); + } + } + } + } + else + { + SfxStringItem aFactory(SID_NEWDOCDIRECT, SwDocShell::Factory().GetFilterContainer()->GetName()); + const SfxFrameItem* pItem = (SfxFrameItem*) + pView->GetViewFrame()->GetDispatcher()->Execute(SID_NEWDOCDIRECT, + SFX_CALLMODE_SYNCHRON, &aFactory, 0L); + SfxFrame* pFrm = pItem ? pItem->GetFrame() : 0; + SfxViewFrame* pFrame = pFrm ? pFrm->GetCurrentViewFrame() : 0; + pNewView = pFrame ? PTR_CAST(SwView, pFrame->GetViewShell()) : 0; + } + + return pNewView; +} + +class SwMailMergeWizardExecutor : public salhelper::SimpleReferenceObject +{ + SwView* m_pView; // never owner + SwView* m_pView2Close; // never owner + SwMailMergeConfigItem* m_pMMConfig; // sometimes owner + AbstractMailMergeWizard* m_pWizard; // always owner + + DECL_LINK( EndDialogHdl, AbstractMailMergeWizard* ); + DECL_LINK( DestroyDialogHdl, void* ); + DECL_LINK( DestroyWizardHdl, AbstractMailMergeWizard* ); + DECL_LINK( CancelHdl, void* ); + DECL_LINK( CloseFrameHdl, void* ); + + void ExecutionFinished( bool bDeleteConfigItem ); + void ExecuteWizard(); + +public: + SwMailMergeWizardExecutor(); + virtual ~SwMailMergeWizardExecutor(); + + void ExecuteMailMergeWizard( const SfxItemSet * pArgs ); +}; + +SwMailMergeWizardExecutor::SwMailMergeWizardExecutor() + : m_pView( 0 ), + m_pView2Close( NULL ), + m_pMMConfig( 0 ), + m_pWizard( 0 ) +{ +} + +SwMailMergeWizardExecutor::~SwMailMergeWizardExecutor() +{ + OSL_ENSURE( m_pWizard == 0, "SwMailMergeWizardExecutor: m_pWizard must be Null!" ); + OSL_ENSURE( m_pMMConfig == 0, "SwMailMergeWizardExecutor: m_pMMConfig must be Null!" ); +} + +void SwMailMergeWizardExecutor::ExecuteMailMergeWizard( const SfxItemSet * pArgs ) +{ + if ( m_pView ) + { + OSL_FAIL("SwMailMergeWizardExecutor::ExecuteMailMergeWizard: Already executing the wizard!" ); + return; + } + + m_pView = ::GetActiveView(); // not owner! + OSL_ENSURE(m_pView, "no current view?"); + if(m_pView) + { + // keep self alive until done. + acquire(); + + // if called from the child window - get the config item and close the ChildWindow, then restore + // the wizard + SwMailMergeChildWindow* pChildWin = + static_cast<SwMailMergeChildWindow*>(m_pView->GetViewFrame()->GetChildWindow(FN_MAILMERGE_CHILDWINDOW)); + bool bRestoreWizard = false; + sal_uInt16 nRestartPage = 0; + if(pChildWin && pChildWin->IsVisible()) + { + m_pMMConfig = m_pView->GetMailMergeConfigItem(); + nRestartPage = m_pView->GetMailMergeRestartPage(); + if(m_pView->IsMailMergeSourceView()) + m_pMMConfig->SetSourceView( m_pView ); + m_pView->SetMailMergeConfigItem(0, 0, true); + SfxViewFrame* pViewFrame = m_pView->GetViewFrame(); + pViewFrame->ShowChildWindow(FN_MAILMERGE_CHILDWINDOW, false); + OSL_ENSURE(m_pMMConfig, "no MailMergeConfigItem available"); + bRestoreWizard = true; + } + // to make it bullet proof ;-) + if(!m_pMMConfig) + { + m_pMMConfig = new SwMailMergeConfigItem; + m_pMMConfig->SetSourceView(m_pView); + + //set the first used database as default source on the config item + const SfxPoolItem* pItem = 0; + if(pArgs && SFX_ITEM_SET == pArgs->GetItemState( + FN_PARAM_DATABASE_PROPERTIES, false, &pItem)) + { + //mailmerge has been called from the database beamer + uno::Sequence< beans::PropertyValue> aDBValues; + if(static_cast<const SfxUsrAnyItem*>(pItem)->GetValue() >>= aDBValues) + { + SwDBData aDBData; + svx::ODataAccessDescriptor aDescriptor(aDBValues); + aDescriptor[svx::daDataSource] >>= aDBData.sDataSource; + aDescriptor[svx::daCommand] >>= aDBData.sCommand; + aDescriptor[svx::daCommandType] >>= aDBData.nCommandType; + + uno::Sequence< uno::Any > aSelection; + uno::Reference< sdbc::XConnection> xConnection; + uno::Reference< sdbc::XDataSource> xSource; + uno::Reference< sdbcx::XColumnsSupplier> xColumnsSupplier; + if ( aDescriptor.has(svx::daSelection) ) + aDescriptor[svx::daSelection] >>= aSelection; + if ( aDescriptor.has(svx::daConnection) ) + aDescriptor[svx::daConnection] >>= xConnection; + uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY); + if(xChild.is()) + xSource = uno::Reference<sdbc::XDataSource>( + xChild->getParent(), uno::UNO_QUERY); + m_pMMConfig->SetCurrentConnection( + xSource, SharedConnection( xConnection, SharedConnection::NoTakeOwnership ), + xColumnsSupplier, aDBData); + } + } + else + { + std::vector<OUString> aDBNameList; + std::vector<OUString> aAllDBNames; + m_pView->GetWrtShell().GetAllUsedDB( aDBNameList, &aAllDBNames ); + if(!aDBNameList.empty()) + { + OUString sDBName(aDBNameList[0]); + SwDBData aDBData; + aDBData.sDataSource = sDBName.getToken(0, DB_DELIM); + aDBData.sCommand = sDBName.getToken(1, DB_DELIM); + aDBData.nCommandType = sDBName.getToken(2, DB_DELIM ).toInt32(); + //set the currently used database for the wizard + m_pMMConfig->SetCurrentDBData( aDBData ); + } + } + } + + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + m_pWizard = pFact->CreateMailMergeWizard(*m_pView, *m_pMMConfig); + + if(bRestoreWizard) + { + m_pWizard->ShowPage( nRestartPage ); + } + + ExecuteWizard(); + } +} + +void SwMailMergeWizardExecutor::ExecutionFinished( bool bDeleteConfigItem ) +{ + m_pMMConfig->Commit(); + if ( bDeleteConfigItem ) // owner? + delete m_pMMConfig; + + m_pMMConfig = 0; + + // release/destroy asynchronously + Application::PostUserEvent( LINK( this, SwMailMergeWizardExecutor, DestroyDialogHdl ) ); +} + +void SwMailMergeWizardExecutor::ExecuteWizard() +{ + m_pWizard->StartExecuteModal( + LINK( this, SwMailMergeWizardExecutor, EndDialogHdl ) ); +} + +IMPL_LINK( SwMailMergeWizardExecutor, EndDialogHdl, AbstractMailMergeWizard*, pDialog ) +{ + OSL_ENSURE( pDialog == m_pWizard, "wrong dialog passed to EndDialogHdl!" ); + (void) pDialog; + + long nRet = m_pWizard->GetResult(); + sal_uInt16 nRestartPage = m_pWizard->GetRestartPage(); + + switch ( nRet ) + { + case RET_LOAD_DOC: + { + SwView* pNewView = lcl_LoadDoc(m_pView, m_pWizard->GetReloadDocument()); + + // destroy wizard asynchronously + Application::PostUserEvent( + LINK( this, SwMailMergeWizardExecutor, DestroyWizardHdl ), m_pWizard ); + + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + if(pNewView) + { + m_pView = pNewView; + m_pMMConfig->DocumentReloaded(); + //new source view! + m_pMMConfig->SetSourceView( m_pView ); + m_pWizard = pFact->CreateMailMergeWizard(*m_pView, *m_pMMConfig); + m_pWizard->ShowPage( nRestartPage ); + } + else + { + m_pWizard = pFact->CreateMailMergeWizard(*m_pView, *m_pMMConfig); + } + + // execute the wizard again + ExecuteWizard(); + break; + } + case RET_TARGET_CREATED: + { + SwView* pTargetView = m_pMMConfig->GetTargetView(); + uno::Reference< frame::XFrame > xFrame = + m_pView->GetViewFrame()->GetFrame().GetFrameInterface(); + xFrame->getContainerWindow()->setVisible(sal_False); + OSL_ENSURE(pTargetView, "No target view has been created"); + if(pTargetView) + { + // destroy wizard asynchronously + Application::PostUserEvent( + LINK( this, SwMailMergeWizardExecutor, DestroyWizardHdl ), m_pWizard ); + + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + m_pWizard = pFact->CreateMailMergeWizard(*pTargetView, *m_pMMConfig); + m_pWizard->ShowPage( nRestartPage ); + + // execute the wizard again + ExecuteWizard(); + } + else + { + // should not happen - just in case no target view has been created + ExecutionFinished( true ); + } + break; + } + case RET_EDIT_DOC: + case RET_EDIT_RESULT_DOC: + { + //create a non-modal dialog that allows to return to the wizard + //the ConfigItem ownership moves to this dialog + bool bResult = nRet == RET_EDIT_RESULT_DOC && m_pMMConfig->GetTargetView(); + SwView* pTempView = bResult ? m_pMMConfig->GetTargetView() : m_pMMConfig->GetSourceView(); + pTempView->SetMailMergeConfigItem(m_pMMConfig, m_pWizard->GetRestartPage(), !bResult); + SfxViewFrame* pViewFrame = pTempView->GetViewFrame(); + pViewFrame->GetDispatcher()->Execute( + FN_MAILMERGE_CHILDWINDOW, SFX_CALLMODE_SYNCHRON); + ExecutionFinished( false ); + break; + } + case RET_REMOVE_TARGET: + { + SwView* pTargetView = m_pMMConfig->GetTargetView(); + SwView* pSourceView = m_pMMConfig->GetSourceView(); + OSL_ENSURE(pTargetView && pSourceView, "source or target view not available" ); + if(pTargetView && pSourceView) + { + m_pView2Close = pTargetView; + pTargetView->GetViewFrame()->GetTopViewFrame()->GetWindow().Hide(); + pSourceView->GetViewFrame()->GetFrame().AppearWithUpdate(); + // the current view has be be set when the target is destroyed + m_pView = pSourceView; + m_pMMConfig->SetTargetView(0); + + // destroy wizard asynchronously + Application::PostUserEvent( + LINK( this, SwMailMergeWizardExecutor, CloseFrameHdl ), m_pWizard ); + + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + m_pWizard = pFact->CreateMailMergeWizard(*pSourceView, *m_pMMConfig); + m_pWizard->ShowPage( nRestartPage ); + + // execute the wizard again + ExecuteWizard(); + } + else + { + // should not happen - just in case no target view has been created + ExecutionFinished( true ); + } + break; + } + case RET_CANCEL: + { + // close frame and destroy wizard asynchronously + Application::PostUserEvent( + LINK( this, SwMailMergeWizardExecutor, CancelHdl ), m_pWizard ); + break; + } + default: // finish + { + SwView* pSourceView = m_pMMConfig->GetSourceView(); + if(pSourceView) + { + SwDocShell* pDocShell = pSourceView->GetDocShell(); + if(pDocShell->HasName() && !pDocShell->IsModified()) + m_pMMConfig->GetSourceView()->GetViewFrame()->DoClose(); + else + m_pMMConfig->GetSourceView()->GetViewFrame()->GetFrame().Appear(); + } + ExecutionFinished( true ); + break; + } + + } // switch + + return 0L; +} + +IMPL_LINK_NOARG(SwMailMergeWizardExecutor, DestroyDialogHdl) +{ + delete m_pWizard; + m_pWizard = 0; + + release(); + return 0L; +} + +IMPL_LINK( SwMailMergeWizardExecutor, DestroyWizardHdl, AbstractMailMergeWizard*, pDialog ) +{ + delete pDialog; + return 0L; +} + +IMPL_LINK_NOARG(SwMailMergeWizardExecutor, CancelHdl) +{ + if(m_pMMConfig->GetTargetView()) + { + m_pMMConfig->GetTargetView()->GetViewFrame()->DoClose(); + m_pMMConfig->SetTargetView(0); + } + if(m_pMMConfig->GetSourceView()) + m_pMMConfig->GetSourceView()->GetViewFrame()->GetFrame().AppearWithUpdate(); + + m_pMMConfig->Commit(); + delete m_pMMConfig; + m_pMMConfig = 0; + // m_pWizard already deleted by closing the target view + m_pWizard = 0; + release(); + + return 0L; +} + +IMPL_LINK_NOARG(SwMailMergeWizardExecutor, CloseFrameHdl) +{ + if ( m_pView2Close ) + { + m_pView2Close->GetViewFrame()->DoClose(); + m_pView2Close = NULL; + } + + return 0L; +} + +} // namespace + +#endif // HAVE_FEATURE_DBCONNECTIVITY + +void SwModule::ExecOther(SfxRequest& rReq) +{ + const SfxItemSet *pArgs = rReq.GetArgs(); + const SfxPoolItem* pItem = 0; + + sal_uInt16 nWhich = rReq.GetSlot(); + switch (nWhich) + { + case FN_ENVELOP: + InsertEnv( rReq ); + break; + + case FN_BUSINESS_CARD: + case FN_LABEL: + InsertLab(rReq, nWhich == FN_LABEL); + break; + + case FN_XFORMS_INIT: + NewXForms( rReq ); + break; + + case SID_ATTR_METRIC: + if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(nWhich, false, &pItem)) + { + FieldUnit eUnit = (FieldUnit)((const SfxUInt16Item*)pItem)->GetValue(); + switch( eUnit ) + { + case FUNIT_MM: + case FUNIT_CM: + case FUNIT_INCH: + case FUNIT_PICA: + case FUNIT_POINT: + { + SwView* pActView = ::GetActiveView(); + bool bWebView = 0 != PTR_CAST(SwWebView, pActView); + ::SetDfltMetric(eUnit, bWebView); + } + break; + default:;//prevent warning + } + } + break; + + case FN_SET_MODOPT_TBLNUMFMT: + { + bool bWebView = 0 != PTR_CAST(SwWebView, ::GetActiveView() ), + bSet; + + if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( + nWhich, false, &pItem )) + bSet = ((SfxBoolItem*)pItem)->GetValue(); + else + bSet = !pModuleConfig->IsInsTblFormatNum( bWebView ); + + pModuleConfig->SetInsTblFormatNum( bWebView, bSet ); + } + break; +#if HAVE_FEATURE_DBCONNECTIVITY + case FN_MAILMERGE_WIZARD: + { + rtl::Reference< SwMailMergeWizardExecutor > xEx( new SwMailMergeWizardExecutor ); + xEx->ExecuteMailMergeWizard( pArgs ); + } +#endif + break; + } +} + +// Catch notifications + +// Catch hint for DocInfo +void SwModule::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if( rHint.ISA( SfxEventHint ) ) + { + SfxEventHint& rEvHint = (SfxEventHint&) rHint; + SwDocShell* pDocSh = PTR_CAST( SwDocShell, rEvHint.GetObjShell() ); + if( pDocSh ) + { + SwWrtShell* pWrtSh = pDocSh->GetWrtShell(); + switch( rEvHint.GetEventId() ) + { + case SFX_EVENT_LOADFINISHED: + OSL_ASSERT(!pWrtSh); + // if it is a new document created from a template, + // update fixed fields + if (pDocSh->GetMedium()) + { + SFX_ITEMSET_ARG( pDocSh->GetMedium()->GetItemSet(), + pTemplateItem, SfxBoolItem, + SID_TEMPLATE, false); + if (pTemplateItem && pTemplateItem->GetValue()) + { + pDocSh->GetDoc()->SetFixFields(false, 0); + } + } + break; + case SFX_EVENT_CREATEDOC: + // Update all FIX-Date/Time fields + if( pWrtSh ) + { + SFX_ITEMSET_ARG( pDocSh->GetMedium()->GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, false); + bool bUpdateFields = true; + if( pUpdateDocItem && pUpdateDocItem->GetValue() == document::UpdateDocMode::NO_UPDATE) + bUpdateFields = false; + if(bUpdateFields) + { + pWrtSh->UpdateInputFlds(); + + // Are database fields contained? + // Get all used databases for the first time + SwDoc *pDoc = pDocSh->GetDoc(); + std::vector<OUString> aDBNameList; + pDoc->GetAllUsedDB( aDBNameList ); + if(!aDBNameList.empty()) + { // Open database beamer + ShowDBObj(pWrtSh->GetView(), pDoc->GetDBData()); + } + } + } + break; + } + } + } + else if(rHint.ISA(SfxItemSetHint)) + { + if( SFX_ITEM_SET == ((SfxItemSetHint&)rHint).GetItemSet().GetItemState(SID_ATTR_PATHNAME)) + { + ::GetGlossaries()->UpdateGlosPath( false ); + SwGlossaryList* pList = ::GetGlossaryList(); + if(pList->IsActive()) + pList->Update(); + } + } + else if(rHint.ISA(SfxSimpleHint)) + { + sal_uInt16 nHintId = ((SfxSimpleHint&)rHint).GetId(); + if(SFX_HINT_DEINITIALIZING == nHintId) + { + DELETEZ(pWebUsrPref); + DELETEZ(pUsrPref) ; + DELETEZ(pModuleConfig); + DELETEZ(pPrtOpt) ; + DELETEZ(pWebPrtOpt) ; + DELETEZ(pChapterNumRules); + DELETEZ(pStdFontConfig) ; + DELETEZ(pNavigationConfig) ; + DELETEZ(pToolbarConfig) ; + DELETEZ(pWebToolbarConfig) ; + DELETEZ(pAuthorNames) ; + DELETEZ(pDBConfig); + if( pColorConfig ) + { + pColorConfig->RemoveListener(this); + DELETEZ(pColorConfig); + } + if( pAccessibilityOptions ) + { + pAccessibilityOptions->RemoveListener(this); + DELETEZ(pAccessibilityOptions); + } + if( pCTLOptions ) + { + pCTLOptions->RemoveListener(this); + DELETEZ(pCTLOptions); + } + if( pUserOptions ) + { + pUserOptions->RemoveListener(this); + DELETEZ(pUserOptions); + } + } + } +} + +void SwModule::ConfigurationChanged( utl::ConfigurationBroadcaster* pBrdCst, sal_uInt32 ) +{ + if( pBrdCst == pUserOptions ) + { + bAuthorInitialised = false; + } + else if ( pBrdCst == pColorConfig || pBrdCst == pAccessibilityOptions ) + { + bool bAccessibility = false; + if( pBrdCst == pColorConfig ) + SwViewOption::ApplyColorConfigValues(*pColorConfig); + else + bAccessibility = true; + + //invalidate all edit windows + const TypeId aSwViewTypeId = TYPE(SwView); + const TypeId aSwPreviewTypeId = TYPE(SwPagePreview); + const TypeId aSwSrcViewTypeId = TYPE(SwSrcView); + SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + while(pViewShell) + { + if(pViewShell->GetWindow()) + { + if((pViewShell->IsA(aSwViewTypeId) || + pViewShell->IsA(aSwPreviewTypeId) || + pViewShell->IsA(aSwSrcViewTypeId))) + { + if(bAccessibility) + { + if(pViewShell->IsA(aSwViewTypeId)) + ((SwView*)pViewShell)->ApplyAccessiblityOptions(*pAccessibilityOptions); + else if(pViewShell->IsA(aSwPreviewTypeId)) + ((SwPagePreview*)pViewShell)->ApplyAccessiblityOptions(*pAccessibilityOptions); + } + pViewShell->GetWindow()->Invalidate(); + } + } + pViewShell = SfxViewShell::GetNext( *pViewShell ); + } + } + else if( pBrdCst == pCTLOptions ) + { + const SfxObjectShell* pObjSh = SfxObjectShell::GetFirst(); + while( pObjSh ) + { + if( pObjSh->IsA(TYPE(SwDocShell)) ) + { + const SwDoc* pDoc = ((SwDocShell*)pObjSh)->GetDoc(); + SwViewShell* pVSh = 0; + pDoc->GetEditShell( &pVSh ); + if ( pVSh ) + pVSh->ChgNumberDigits(); + } + pObjSh = SfxObjectShell::GetNext(*pObjSh); + } + } + +} + +SwDBConfig* SwModule::GetDBConfig() +{ + if(!pDBConfig) + pDBConfig = new SwDBConfig; + return pDBConfig; +} + +svtools::ColorConfig& SwModule::GetColorConfig() +{ + if(!pColorConfig) + { + pColorConfig = new svtools::ColorConfig; + SwViewOption::ApplyColorConfigValues(*pColorConfig); + pColorConfig->AddListener(this); + } + return *pColorConfig; +} + +SvtAccessibilityOptions& SwModule::GetAccessibilityOptions() +{ + if(!pAccessibilityOptions) + { + pAccessibilityOptions = new SvtAccessibilityOptions; + pAccessibilityOptions->AddListener(this); + } + return *pAccessibilityOptions; +} + +SvtCTLOptions& SwModule::GetCTLOptions() +{ + if(!pCTLOptions) + { + pCTLOptions = new SvtCTLOptions; + pCTLOptions->AddListener(this); + } + return *pCTLOptions; +} + +SvtUserOptions& SwModule::GetUserOptions() +{ + if(!pUserOptions) + { + pUserOptions = new SvtUserOptions; + pUserOptions->AddListener(this); + } + return *pUserOptions; +} + +const SwMasterUsrPref *SwModule::GetUsrPref(bool bWeb) const +{ + SwModule* pNonConstModule = (SwModule*)this; + if(bWeb && !pWebUsrPref) + { + // The SpellChecker is needed in SwMasterUsrPref's Load, but it must not + // be created there #58256# + pNonConstModule->pWebUsrPref = new SwMasterUsrPref(true); + } + else if(!bWeb && !pUsrPref) + { + pNonConstModule->pUsrPref = new SwMasterUsrPref(false); + } + return bWeb ? pWebUsrPref : pUsrPref; +} + +void NewXForms( SfxRequest& rReq ) +{ + // copied & excerpted from SwModule::InsertLab(..) + + // create new document + SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD) ); + xDocSh->DoInitNew( 0 ); + + // initialize XForms + static_cast<SwDocShell*>( &xDocSh )->GetDoc()->initXForms( true ); + + // load document into frame + SfxViewFrame::DisplayNewDocument( *xDocSh, rReq ); + + // set return value + rReq.SetReturnValue( SfxVoidItem( rReq.GetSlot() ) ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/applab.cxx b/sw/source/uibase/app/applab.cxx new file mode 100644 index 000000000000..9d9436daa94e --- /dev/null +++ b/sw/source/uibase/app/applab.cxx @@ -0,0 +1,413 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <config_features.h> + +#include <cstdarg> + +#include <hintids.hxx> + +#include <comphelper/string.hxx> +#include <vcl/svapp.hxx> +#include <vcl/wrkwin.hxx> +#include <vcl/msgbox.hxx> +#include <sfx2/app.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/printer.hxx> +#include <sfx2/request.hxx> +#include <sfx2/linkmgr.hxx> +#include <editeng/pbinitem.hxx> +#include <editeng/ulspitem.hxx> +#include <editeng/lrspitem.hxx> +#include <editeng/boxitem.hxx> +#include <editeng/paperinf.hxx> +#include <editeng/protitem.hxx> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <fmthdft.hxx> +#include <fmtanchr.hxx> +#include <fmtfsize.hxx> +#include <fmtornt.hxx> +#include <swwait.hxx> +#include <gloshdl.hxx> +#include <mdiexp.hxx> +#include <frmatr.hxx> +#include <paratr.hxx> +#include <swmodule.hxx> +#include <view.hxx> +#include <docsh.hxx> +#include <fldbas.hxx> +#include <swundo.hxx> +#include <wrtsh.hxx> +#include <cmdid.h> +#include <dbmgr.hxx> +#include <fmtcol.hxx> +#include <expfld.hxx> +#include <fldmgr.hxx> +#include <label.hxx> +#include <labimg.hxx> +#include <section.hxx> +#include <pagedesc.hxx> +#include <poolfmt.hxx> + +#include <app.hrc> +#include <poolfmt.hrc> +#include "swabstdlg.hxx" +#include "envelp.hrc" +#include <misc.hrc> + +#include <IDocumentDeviceAccess.hxx> + +#include <boost/scoped_ptr.hpp> + +using namespace ::com::sun::star; + +// is in appenv.cxx +extern OUString InsertLabEnvText( SwWrtShell& , SwFldMgr& , const OUString& ); + +const char MASTER_LABEL[] = "MasterLabel"; + +static const SwFrmFmt *lcl_InsertBCText( SwWrtShell& rSh, const SwLabItem& rItem, + SwFrmFmt &rFmt, + sal_uInt16 nCol, sal_uInt16 nRow ) +{ + SfxItemSet aSet(rSh.GetAttrPool(), RES_ANCHOR, RES_ANCHOR, + RES_VERT_ORIENT, RES_VERT_ORIENT, RES_HORI_ORIENT, RES_HORI_ORIENT, 0 ); + sal_uInt16 nPhyPageNum, nVirtPageNum; + rSh.GetPageNum( nPhyPageNum, nVirtPageNum ); + + //anchor frame to page + aSet.Put( SwFmtAnchor( FLY_AT_PAGE, nPhyPageNum ) ); + aSet.Put( SwFmtHoriOrient( rItem.lLeft + nCol * rItem.lHDist, + text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME ) ); + aSet.Put( SwFmtVertOrient( rItem.lUpper + nRow * rItem.lVDist, + text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME ) ); + const SwFrmFmt *pFmt = rSh.NewFlyFrm(aSet, true, &rFmt ); // Insert Fly + OSL_ENSURE( pFmt, "Fly not inserted" ); + + rSh.UnSelectFrm(); //Frame was selected automatically + + rSh.SetTxtFmtColl( rSh.GetTxtCollFromPool( RES_POOLCOLL_STANDARD ) ); + + if(!rItem.bSynchron || !(nCol|nRow)) + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + OSL_ENSURE(pFact, "Dialogdiet fail!"); + ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc(); + if ( fnSetActGroup ) + (*fnSetActGroup)( rItem.sGlossaryGroup ); + SwGlossaryHdl* pGlosHdl = rSh.GetView().GetGlosHdl(); + pGlosHdl->SetCurGroup(rItem.sGlossaryGroup, true); + pGlosHdl->InsertGlossary( rItem.sGlossaryBlockName ); + } + + return pFmt; +} + +static const SwFrmFmt *lcl_InsertLabText( SwWrtShell& rSh, const SwLabItem& rItem, + SwFrmFmt &rFmt, SwFldMgr& rFldMgr, + sal_uInt16 nCol, sal_uInt16 nRow, bool bLast ) +{ + SfxItemSet aSet(rSh.GetAttrPool(), RES_ANCHOR, RES_ANCHOR, + RES_VERT_ORIENT, RES_VERT_ORIENT, RES_HORI_ORIENT, RES_HORI_ORIENT, 0 ); + sal_uInt16 nPhyPageNum, nVirtPageNum; + rSh.GetPageNum( nPhyPageNum, nVirtPageNum ); + + //anchor frame to page + aSet.Put( SwFmtAnchor( FLY_AT_PAGE, nPhyPageNum ) ); + aSet.Put( SwFmtHoriOrient( rItem.lLeft + nCol * rItem.lHDist, + text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME ) ); + aSet.Put( SwFmtVertOrient( rItem.lUpper + nRow * rItem.lVDist, + text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME ) ); + const SwFrmFmt *pFmt = rSh.NewFlyFrm(aSet, true, &rFmt ); // Insert Fly + OSL_ENSURE( pFmt, "Fly not inserted" ); + + rSh.UnSelectFrm(); //Frame was selected automatically + + rSh.SetTxtFmtColl( rSh.GetTxtCollFromPool( RES_POOLCOLL_STANDARD ) ); + + // If applicable "next dataset" + OUString sDBName; + if( (!rItem.bSynchron || !(nCol|nRow)) && !(sDBName = InsertLabEnvText( rSh, rFldMgr, rItem.aWriting )).isEmpty() && !bLast ) + { + sDBName = comphelper::string::setToken(sDBName, 3, DB_DELIM, "True"); + SwInsertFld_Data aData(TYP_DBNEXTSETFLD, 0, sDBName, aEmptyOUStr, 0, &rSh ); + rFldMgr.InsertFld( aData ); + } + + return pFmt; +} + +void SwModule::InsertLab(SfxRequest& rReq, bool bLabel) +{ + static sal_uInt16 nLabelTitleNo = 0; + static sal_uInt16 nBCTitleNo = 0; + +#if HAVE_FEATURE_DBCONNECTIVITY + // Create DB-Manager + boost::scoped_ptr<SwDBManager> pDBManager(new SwDBManager); +#endif + + // Read SwLabItem from Config + SwLabCfgItem aLabCfg(bLabel); + + // Move up Dialog + SfxItemSet aSet( GetPool(), FN_LABEL, FN_LABEL, 0 ); + aSet.Put( aLabCfg.GetItem() ); + + SwAbstractDialogFactory* pDialogFactory = SwAbstractDialogFactory::Create(); + OSL_ENSURE(pDialogFactory, "SwAbstractDialogFactory fail!"); + + boost::scoped_ptr<AbstractSwLabDlg> pDlg(pDialogFactory->CreateSwLabDlg(0, aSet, +#if HAVE_FEATURE_DBCONNECTIVITY + pDBManager.get(), +#else + NULL, +#endif + bLabel)); + OSL_ENSURE(pDlg, "Dialogdiet fail!"); + + if ( RET_OK == pDlg->Execute() ) + { + // Read dialog, store item in config + const SwLabItem& rItem = (const SwLabItem&) pDlg-> + GetOutputItemSet()->Get(FN_LABEL); + aLabCfg.GetItem() = rItem; + aLabCfg.Commit(); + + // Create new document + SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD)); + xDocSh->DoInitNew( 0 ); + + // Printer + Printer *pPrt = pDlg->GetPrt(); + if (pPrt) + { + SwDocShell *pDocSh = (SwDocShell*)(&*xDocSh); + pDocSh->getIDocumentDeviceAccess()->setJobsetup(pPrt->GetJobSetup()); + } + + SfxViewFrame* pViewFrame = SfxViewFrame::DisplayNewDocument( *xDocSh, rReq ); + + SwView *pNewView = (SwView*) pViewFrame->GetViewShell(); + pNewView->AttrChangedNotify( &pNewView->GetWrtShell() );// So that SelectShell is being called. + + // Set document title + OUString aTmp; + if(bLabel) + { + aTmp = SW_RES( STR_LAB_TITLE); + aTmp += OUString::number(++nLabelTitleNo ); + } + else + { + aTmp = pDlg->GetBusinessCardStr(); + aTmp += OUString::number( ++nBCTitleNo ); + } + xDocSh->SetTitle( aTmp ); + + pViewFrame->GetFrame().Appear(); + + // Determine Shell + SwWrtShell *pSh = pNewView->GetWrtShellPtr(); + OSL_ENSURE( pSh, "missing WrtShell" ); + + { // block for locks the dispatcher!! + + SwWait aWait( (SwDocShell&)*xDocSh, true ); + + SET_CURR_SHELL(pSh); + pSh->SetLabelDoc(rItem.bSynchron); + pSh->DoUndo( false ); + pSh->StartAllAction(); + + pSh->SetNewDoc(); // Avoid performance problems + + SwPageDesc aDesc = pSh->GetPageDesc( 0 ); + SwFrmFmt& rFmt = aDesc.GetMaster(); + + // Borders + SvxLRSpaceItem aLRMargin( RES_LR_SPACE ); + SvxULSpaceItem aULMargin( RES_UL_SPACE ); + aLRMargin.SetLeft ((sal_uInt16) rItem.lLeft ); + aULMargin.SetUpper((sal_uInt16) rItem.lUpper); + aLRMargin.SetRight( 0 ); + aULMargin.SetLower( 0 ); + rFmt.SetFmtAttr(aLRMargin); + rFmt.SetFmtAttr(aULMargin); + + // Header and footer + rFmt.SetFmtAttr(SwFmtHeader(false)); + aDesc.ChgHeaderShare(false); + rFmt.SetFmtAttr(SwFmtFooter(false)); + aDesc.ChgFooterShare(false); + + aDesc.SetUseOn(nsUseOnPage::PD_ALL); // Site numbering + + // Set page size + long lPgWidth, lPgHeight; + lPgWidth = (rItem.lPWidth > MINLAY ? rItem.lPWidth : MINLAY); + lPgHeight = (rItem.lPHeight > MINLAY ? rItem.lPHeight : MINLAY); + rFmt.SetFmtAttr( SwFmtFrmSize( ATT_FIX_SIZE, lPgWidth, lPgHeight )); + // Numbering type + SvxNumberType aType; + aType.SetNumberingType(SVX_NUM_NUMBER_NONE); + aDesc.SetNumType( aType ); + + // Followup template + const SwPageDesc &rFollow = pSh->GetPageDesc( pSh->GetCurPageDesc() ); + aDesc.SetFollow( &rFollow ); + + pPrt = pSh->getIDocumentDeviceAccess()->getPrinter( true ); + SvxPaperBinItem aItem( RES_PAPER_BIN ); + aItem.SetValue((sal_Int8)pPrt->GetPaperBin()); + rFmt.SetFmtAttr(aItem); + + // Determine orientation of the resulting page + aDesc.SetLandscape(rItem.lPWidth > rItem.lPHeight); + + pSh->ChgPageDesc( 0, aDesc ); + + // Insert frame + boost::scoped_ptr<SwFldMgr> pFldMgr(new SwFldMgr); + pFldMgr->SetEvalExpFlds(false); + + // Prepare border template + SwFrmFmt* pFmt = pSh->GetFrmFmtFromPool( RES_POOLFRM_LABEL ); + sal_Int32 iResultWidth = rItem.lLeft + (rItem.nCols - 1) * rItem.lHDist + rItem.lWidth - rItem.lPWidth; + sal_Int32 iResultHeight = rItem.lUpper + (rItem.nRows - 1) * rItem.lVDist + rItem.lHeight - rItem.lPHeight; + sal_Int32 iWidth = (iResultWidth > 0 ? rItem.lWidth - (iResultWidth / rItem.nCols) - 1 : rItem.lWidth); + sal_Int32 iHeight = (iResultHeight > 0 ? rItem.lHeight - (iResultHeight / rItem.nRows) - 1 : rItem.lHeight); + SwFmtFrmSize aFrmSize( ATT_FIX_SIZE, iWidth, iHeight ); + pFmt->SetFmtAttr( aFrmSize ); + + //frame represents label itself, no border space + SvxULSpaceItem aFrmNoULSpace( 0, 0, RES_UL_SPACE ); + SvxLRSpaceItem aFrmNoLRSpace( 0, 0, 0, 0, RES_LR_SPACE ); + pFmt->SetFmtAttr( aFrmNoULSpace ); + pFmt->SetFmtAttr( aFrmNoLRSpace ); + + const SwFrmFmt *pFirstFlyFmt = 0; + if ( rItem.bPage ) + { + SwFmtVertOrient aFrmVertOrient( pFmt->GetVertOrient() ); + aFrmVertOrient.SetVertOrient( text::VertOrientation::TOP ); + pFmt->SetFmtAttr(aFrmVertOrient); + + for ( sal_uInt16 i = 0; i < rItem.nRows; ++i ) + { + for ( sal_uInt16 j = 0; j < rItem.nCols; ++j ) + { + pSh->Push(); + const SwFrmFmt *pTmp = ( bLabel ? + lcl_InsertLabText( *pSh, rItem, *pFmt, *pFldMgr, j, i, + i == rItem.nRows - 1 && j == rItem.nCols - 1 ) : + lcl_InsertBCText( *pSh, rItem, *pFmt, j, i ) ); + if (!(i|j)) + { + pFirstFlyFmt = pTmp; + + if (rItem.bSynchron) + { + // if there is no content in the fly then + // dont leave the fly!!! + pSh->Push(); + pSh->SttDoc(); + bool bInFly = 0 != pSh->WizzardGetFly(); + pSh->Pop( bInFly ); + + if( bInFly ) + pSh->EndDoc(true); // select all content + // in the fly + else + pSh->SetMark(); // set only the mark + + SwSectionData aSect(CONTENT_SECTION, + OUString(MASTER_LABEL)); + pSh->InsertSection(aSect); + } + } + else if (rItem.bSynchron) + { + SwSectionData aSect(FILE_LINK_SECTION, + pSh->GetUniqueSectionName()); + OUStringBuffer sLinkName; + sLinkName.append(sfx2::cTokenSeparator); + sLinkName.append(sfx2::cTokenSeparator); + sLinkName.append(MASTER_LABEL); + aSect.SetLinkFileName(sLinkName.makeStringAndClear()); + aSect.SetProtectFlag(true); + pSh->Insert("."); // Dummytext to allocate the Section + pSh->SttDoc(); + pSh->EndDoc(true); // Select everything in the frame + pSh->InsertSection(aSect); + } + pSh->Pop( false ); + } + } + } + else + { + pFirstFlyFmt = bLabel ? + lcl_InsertLabText( *pSh, rItem, *pFmt, *pFldMgr, + static_cast< sal_uInt16 >(rItem.nCol - 1), + static_cast< sal_uInt16 >(rItem.nRow - 1), true ) : + lcl_InsertBCText(*pSh, rItem, *pFmt, + static_cast< sal_uInt16 >(rItem.nCol - 1), + static_cast< sal_uInt16 >(rItem.nRow - 1)); + } + + //fill the user fields + if(!bLabel) + { + uno::Reference< frame::XModel > xModel = pSh->GetView().GetDocShell()->GetBaseModel(); + OSL_ENSURE(pDialogFactory, "SwAbstractDialogFactory fail!"); + SwLabDlgMethod SwLabDlgUpdateFieldInformation = pDialogFactory->GetSwLabDlgStaticMethod (); + SwLabDlgUpdateFieldInformation(xModel, rItem); + } + + pFldMgr->SetEvalExpFlds(true); + pFldMgr->EvalExpFlds(pSh); + + pFldMgr.reset(); + + if (pFirstFlyFmt) + pSh->GotoFly(pFirstFlyFmt->GetName(), FLYCNTTYPE_ALL, false); + + pSh->EndAllAction(); + pSh->DoUndo( true ); + } + + if( rItem.aWriting.indexOf( '<' ) >= 0 ) + { + // Open database browser on recently used database + ShowDBObj( *pNewView, pSh->GetDBData() ); + } + + if( rItem.bSynchron ) + { + SfxDispatcher* pDisp = pViewFrame->GetDispatcher(); + OSL_ENSURE(pDisp, "No dispatcher in frame?"); + pDisp->Execute(FN_SYNC_LABELS, SFX_CALLMODE_ASYNCHRON); + } + rReq.SetReturnValue(SfxVoidItem(bLabel ? FN_LABEL : FN_BUSINESS_CARD)); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/appopt.cxx b/sw/source/uibase/app/appopt.cxx new file mode 100644 index 000000000000..9af525d744ad --- /dev/null +++ b/sw/source/uibase/app/appopt.cxx @@ -0,0 +1,528 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <cmdid.h> + +#include <com/sun/star/i18n/ScriptType.hpp> + +#include <hintids.hxx> +#include <vcl/msgbox.hxx> +#include <svl/eitem.hxx> +#include <sfx2/request.hxx> +#include <sfx2/app.hxx> +#include <sfx2/printer.hxx> +#include <sfx2/htmlmode.hxx> +#include <sfx2/bindings.hxx> +#include <editeng/brushitem.hxx> +#include <editeng/tstpitem.hxx> +#include <svx/optgrid.hxx> +#include <svx/svxdlg.hxx> +#include <svx/dialogs.hrc> +#include <i18nlangtag/mslangid.hxx> +#include <i18nlangtag/languagetag.hxx> +#include <fontcfg.hxx> +#include <optload.hxx> +#include <optcomp.hxx> +#include <edtwin.hxx> +#include <swmodule.hxx> +#include <view.hxx> +#include <doc.hxx> +#include <wrtsh.hxx> +#include <IDocumentDeviceAccess.hxx> +#include <uitool.hxx> +#include <initui.hxx> +#include <fldbas.hxx> +#include <wview.hxx> +#include <cfgitems.hxx> +#include <prtopt.hxx> +#include <pview.hxx> +#include <usrpref.hxx> +#include <modcfg.hxx> +#include <glosdoc.hxx> +#include <uiitems.hxx> +#include <editeng/langitem.hxx> +#include <unotools/lingucfg.hxx> +#include <editeng/unolingu.hxx> +#include <globals.hrc> +#include <globals.h> +#include <svl/slstitm.hxx> +#include "swabstdlg.hxx" +#include <swwrtshitem.hxx> + +#include <unomid.h> + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; + +SfxItemSet* SwModule::CreateItemSet( sal_uInt16 nId ) +{ + bool bTextDialog = (nId == SID_SW_EDITOPTIONS); + + // the options for the Web- and Textdialog are put together here + SwViewOption aViewOpt = *GetUsrPref(!bTextDialog); + SwMasterUsrPref* pPref = bTextDialog ? pUsrPref : pWebUsrPref; + // no MakeUsrPref, because only options from textdoks can be used here + SwView* pAppView = GetView(); + if(pAppView && pAppView->GetViewFrame() != SfxViewFrame::Current()) + pAppView = 0; + if(pAppView) + { + // if Text then no WebView and vice versa + bool bWebView = 0 != PTR_CAST(SwWebView, pAppView); + if( (bWebView && !bTextDialog) ||(!bWebView && bTextDialog)) + { + aViewOpt = *pAppView->GetWrtShell().GetViewOptions(); + } + else + pAppView = 0; // with View, there's nothing to win here + } + + // Options/Edit + SfxItemSet* pRet = new SfxItemSet (GetPool(), FN_PARAM_DOCDISP, FN_PARAM_ELEM, + SID_PRINTPREVIEW, SID_PRINTPREVIEW, + SID_ATTR_GRID_OPTIONS, SID_ATTR_GRID_OPTIONS, + FN_PARAM_PRINTER, FN_PARAM_STDFONTS, + FN_PARAM_WRTSHELL, FN_PARAM_WRTSHELL, + FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER, + SID_ATTR_METRIC, SID_ATTR_METRIC, + SID_ATTR_APPLYCHARUNIT, SID_ATTR_APPLYCHARUNIT, + SID_ATTR_DEFTABSTOP, SID_ATTR_DEFTABSTOP, + RES_BACKGROUND, RES_BACKGROUND, + SID_HTML_MODE, SID_HTML_MODE, + FN_PARAM_SHADOWCURSOR, FN_PARAM_SHADOWCURSOR, + FN_PARAM_CRSR_IN_PROTECTED, FN_PARAM_CRSR_IN_PROTECTED, + FN_HSCROLL_METRIC, FN_VSCROLL_METRIC, + SID_ATTR_LANGUAGE, SID_ATTR_LANGUAGE, + SID_ATTR_CHAR_CJK_LANGUAGE, SID_ATTR_CHAR_CJK_LANGUAGE, + SID_ATTR_CHAR_CTL_LANGUAGE, SID_ATTR_CHAR_CTL_LANGUAGE, +#if OSL_DEBUG_LEVEL > 1 + FN_PARAM_SWTEST, FN_PARAM_SWTEST, +#endif + 0); + + pRet->Put( SwDocDisplayItem( aViewOpt, FN_PARAM_DOCDISP) ); + pRet->Put( SwElemItem( aViewOpt, FN_PARAM_ELEM) ); + if( bTextDialog ) + { + pRet->Put( SwShadowCursorItem( aViewOpt, FN_PARAM_SHADOWCURSOR )); + pRet->Put( SfxBoolItem(FN_PARAM_CRSR_IN_PROTECTED, aViewOpt.IsCursorInProtectedArea())); + } + + if( pAppView ) + { + SwWrtShell& rWrtShell = pAppView->GetWrtShell(); + + SfxPrinter* pPrt = rWrtShell.getIDocumentDeviceAccess()->getPrinter( false ); + if( pPrt ) + pRet->Put(SwPtrItem(FN_PARAM_PRINTER, pPrt)); + pRet->Put(SwPtrItem(FN_PARAM_WRTSHELL, &rWrtShell)); + + pRet->Put((const SvxLanguageItem&) + rWrtShell.GetDefault(RES_CHRATR_LANGUAGE), SID_ATTR_LANGUAGE); + + pRet->Put((const SvxLanguageItem&) + rWrtShell.GetDefault(RES_CHRATR_CJK_LANGUAGE), SID_ATTR_CHAR_CJK_LANGUAGE); + + pRet->Put((const SvxLanguageItem&) + rWrtShell.GetDefault(RES_CHRATR_CTL_LANGUAGE), SID_ATTR_CHAR_CTL_LANGUAGE); + } + else + { + SvtLinguConfig aLinguCfg; + com::sun::star::lang::Locale aLocale; + LanguageType nLang; + + using namespace ::com::sun::star::i18n::ScriptType; + + Any aLang = aLinguCfg.GetProperty(OUString("DefaultLocale")); + aLang >>= aLocale; + nLang = MsLangId::resolveSystemLanguageByScriptType(LanguageTag::convertToLanguageType( aLocale, false), LATIN); + pRet->Put(SvxLanguageItem(nLang, SID_ATTR_LANGUAGE)); + + aLang = aLinguCfg.GetProperty(OUString("DefaultLocale_CJK")); + aLang >>= aLocale; + nLang = MsLangId::resolveSystemLanguageByScriptType(LanguageTag::convertToLanguageType( aLocale, false), ASIAN); + pRet->Put(SvxLanguageItem(nLang, SID_ATTR_CHAR_CJK_LANGUAGE)); + + aLang = aLinguCfg.GetProperty(OUString("DefaultLocale_CTL")); + aLang >>= aLocale; + nLang = MsLangId::resolveSystemLanguageByScriptType(LanguageTag::convertToLanguageType( aLocale, false), COMPLEX); + pRet->Put(SvxLanguageItem(nLang, SID_ATTR_CHAR_CTL_LANGUAGE)); + } + if(bTextDialog) + pRet->Put(SwPtrItem(FN_PARAM_STDFONTS, GetStdFontConfig())); + if( PTR_CAST( SwPagePreview, SfxViewShell::Current())!=0) + { + SfxBoolItem aBool(SfxBoolItem(SID_PRINTPREVIEW, true)); + pRet->Put(aBool); + } + + FieldUnit eUnit = pPref->GetHScrollMetric(); + if(pAppView) + pAppView->GetHRulerMetric(eUnit); + pRet->Put(SfxUInt16Item( FN_HSCROLL_METRIC, static_cast< sal_uInt16 >(eUnit))); + + eUnit = pPref->GetVScrollMetric(); + if(pAppView) + pAppView->GetVRulerMetric(eUnit); + pRet->Put(SfxUInt16Item( FN_VSCROLL_METRIC, static_cast< sal_uInt16 >(eUnit) )); + pRet->Put(SfxUInt16Item( SID_ATTR_METRIC, static_cast< sal_uInt16 >(pPref->GetMetric()) )); + pRet->Put(SfxBoolItem(SID_ATTR_APPLYCHARUNIT, pPref->IsApplyCharUnit())); + if(bTextDialog) + { + if(pAppView) + { + const SvxTabStopItem& rDefTabs = + (const SvxTabStopItem&)pAppView->GetWrtShell(). + GetDefault(RES_PARATR_TABSTOP); + pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP, (sal_uInt16)::GetTabDist(rDefTabs))); + } + else + pRet->Put(SfxUInt16Item( SID_ATTR_DEFTABSTOP, (sal_uInt16)pPref->GetDefTab())); + } + + // Options for GridTabPage + SvxGridItem aGridItem( SID_ATTR_GRID_OPTIONS); + + aGridItem.SetUseGridSnap( aViewOpt.IsSnap()); + aGridItem.SetSynchronize( aViewOpt.IsSynchronize()); + aGridItem.SetGridVisible( aViewOpt.IsGridVisible()); + + const Size& rSnapSize = aViewOpt.GetSnapSize(); + aGridItem.SetFldDrawX( (sal_uInt16) (rSnapSize.Width() )); + aGridItem.SetFldDrawY( (sal_uInt16) (rSnapSize.Height())); + + aGridItem.SetFldDivisionX( aViewOpt.GetDivisionX()); + aGridItem.SetFldDivisionY( aViewOpt.GetDivisionY()); + + pRet->Put(aGridItem); + + // Options for PrintTabPage + const SwPrintData* pOpt = pAppView ? + &pAppView->GetWrtShell().getIDocumentDeviceAccess()->getPrintData() : + 0; + + if(!pOpt) + pOpt = GetPrtOptions(!bTextDialog); + + SwAddPrinterItem aAddPrinterItem (FN_PARAM_ADDPRINTER, *pOpt ); + pRet->Put(aAddPrinterItem); + + // Options for Web background + if(!bTextDialog) + { + pRet->Put(SvxBrushItem(aViewOpt.GetRetoucheColor(), RES_BACKGROUND)); + } + + if(!bTextDialog) + pRet->Put(SfxUInt16Item(SID_HTML_MODE, HTMLMODE_ON)); + return pRet; +} + +void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) +{ + bool bTextDialog = nId == SID_SW_EDITOPTIONS; + SwView* pAppView = GetView(); + if(pAppView && pAppView->GetViewFrame() != SfxViewFrame::Current()) + pAppView = 0; + if(pAppView) + { + // the text dialog mustn't apply data to the web view and vice versa + bool bWebView = 0 != PTR_CAST(SwWebView, pAppView); + if(bWebView == bTextDialog) + pAppView = 0; + } + + SwViewOption aViewOpt = *GetUsrPref(!bTextDialog); + SwMasterUsrPref* pPref = bTextDialog ? pUsrPref : pWebUsrPref; + + const SfxPoolItem* pItem; + SfxBindings *pBindings = pAppView ? &pAppView->GetViewFrame()->GetBindings() + : NULL; + + // Interpret the page Documentview + if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_DOCDISP, false, &pItem )) + { + const SwDocDisplayItem* pDocDispItem = (const SwDocDisplayItem*)pItem; + + if(!aViewOpt.IsViewMetaChars()) + { + if( (!aViewOpt.IsTab( true ) && pDocDispItem->bTab) || + (!aViewOpt.IsBlank( true ) && pDocDispItem->bSpace) || + (!aViewOpt.IsParagraph( true ) && pDocDispItem->bParagraphEnd) || + (!aViewOpt.IsLineBreak( true ) && pDocDispItem->bManualBreak) ) + { + aViewOpt.SetViewMetaChars(true); + if(pBindings) + pBindings->Invalidate(FN_VIEW_META_CHARS); + } + + } + pDocDispItem->FillViewOptions( aViewOpt ); + if(pBindings) + { + pBindings->Invalidate(FN_VIEW_GRAPHIC); + pBindings->Invalidate(FN_VIEW_HIDDEN_PARA); + } + } + + // Elements - interpret Item + if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_ELEM, false, &pItem ) ) + { + const SwElemItem* pElemItem = (const SwElemItem*)pItem; + pElemItem->FillViewOptions( aViewOpt ); + + } + + if( SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_METRIC, false, &pItem ) ) + { + SFX_APP()->SetOptions(rSet); + PutItem(*pItem); + const SfxUInt16Item* pMetricItem = (const SfxUInt16Item*)pItem; + ::SetDfltMetric((FieldUnit)pMetricItem->GetValue(), !bTextDialog); + } + if( SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_APPLYCHARUNIT, + false, &pItem ) ) + { + SFX_APP()->SetOptions(rSet); + const SfxBoolItem* pCharItem = (const SfxBoolItem*)pItem; + ::SetApplyCharUnit(pCharItem->GetValue(), !bTextDialog); + } + + if( SFX_ITEM_SET == rSet.GetItemState(FN_HSCROLL_METRIC, false, &pItem ) ) + { + const SfxUInt16Item* pMetricItem = (const SfxUInt16Item*)pItem; + FieldUnit eUnit = (FieldUnit)pMetricItem->GetValue(); + pPref->SetHScrollMetric(eUnit); + if(pAppView) + pAppView->ChangeTabMetric(eUnit); + } + + if( SFX_ITEM_SET == rSet.GetItemState(FN_VSCROLL_METRIC, false, &pItem ) ) + { + const SfxUInt16Item* pMetricItem = (const SfxUInt16Item*)pItem; + FieldUnit eUnit = (FieldUnit)pMetricItem->GetValue(); + pPref->SetVScrollMetric(eUnit); + if(pAppView) + pAppView->ChangeVRulerMetric(eUnit); + } + + if( SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_DEFTABSTOP, false, &pItem ) ) + { + sal_uInt16 nTabDist = ((const SfxUInt16Item*)pItem)->GetValue(); + pPref->SetDefTab(nTabDist); + if(pAppView) + { + SvxTabStopItem aDefTabs( 0, 0, SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP ); + MakeDefTabs( nTabDist, aDefTabs ); + pAppView->GetWrtShell().SetDefault( aDefTabs ); + } + } + + // Background only in WebDialog + if(SFX_ITEM_SET == rSet.GetItemState(RES_BACKGROUND)) + { + const SvxBrushItem& rBrushItem = (const SvxBrushItem&)rSet.Get( + RES_BACKGROUND); + aViewOpt.SetRetoucheColor( rBrushItem.GetColor() ); + } + + // Interpret page Grid Settings + if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS, false, &pItem )) + { + const SvxGridItem* pGridItem = (const SvxGridItem*)pItem; + + aViewOpt.SetSnap( pGridItem->GetUseGridSnap() ); + aViewOpt.SetSynchronize(pGridItem->GetSynchronize()); + if( aViewOpt.IsGridVisible() != pGridItem->GetGridVisible() ) + aViewOpt.SetGridVisible( pGridItem->GetGridVisible()); + Size aSize = Size( pGridItem->GetFldDrawX() , + pGridItem->GetFldDrawY() ); + if( aViewOpt.GetSnapSize() != aSize ) + aViewOpt.SetSnapSize( aSize ); + short nDiv = (short)pGridItem->GetFldDivisionX() ; + if( aViewOpt.GetDivisionX() != nDiv ) + aViewOpt.SetDivisionX( nDiv ); + nDiv = (short)pGridItem->GetFldDivisionY(); + if( aViewOpt.GetDivisionY() != nDiv ) + aViewOpt.SetDivisionY( nDiv ); + + if(pBindings) + { + pBindings->Invalidate(SID_GRID_VISIBLE); + pBindings->Invalidate(SID_GRID_USE); + } + } + + // Interpret Writer Printer Options + if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, false, &pItem )) + { + SwPrintOptions* pOpt = GetPrtOptions(!bTextDialog); + if (pOpt) + { + const SwAddPrinterItem* pAddPrinterAttr = (const SwAddPrinterItem*)pItem; + *pOpt = *pAddPrinterAttr; + + if(pAppView) + pAppView->GetWrtShell().getIDocumentDeviceAccess()->setPrintData( *pOpt ); + } + + } + + if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_SHADOWCURSOR, false, &pItem )) + { + ((SwShadowCursorItem*)pItem)->FillViewOptions( aViewOpt ); + if(pBindings) + pBindings->Invalidate(FN_SHADOWCURSOR); + } + + if( pAppView ) + { + SwWrtShell &rWrtSh = pAppView->GetWrtShell(); + const bool bAlignFormulas = rWrtSh.GetDoc()->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT ); + pPref->SetAlignMathObjectsToBaseline( bAlignFormulas ); + + // don't align formulas in documents that are currently loading + if (bAlignFormulas && !rWrtSh.GetDoc()->IsInReading()) + rWrtSh.AlignAllFormulasToBaseline(); + } + + if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_CRSR_IN_PROTECTED, false, &pItem )) + { + aViewOpt.SetCursorInProtectedArea(((const SfxBoolItem*)pItem)->GetValue()); + } + + // set elements for the current view and shell + ApplyUsrPref( aViewOpt, pAppView, bTextDialog? VIEWOPT_DEST_TEXT : VIEWOPT_DEST_WEB); +} + +SfxTabPage* SwModule::CreateTabPage( sal_uInt16 nId, Window* pParent, const SfxItemSet& rSet ) +{ + SfxTabPage* pRet = NULL; + SfxAllItemSet aSet(*(rSet.GetPool())); + switch( nId ) + { + case RID_SW_TP_CONTENT_OPT: + case RID_SW_TP_HTML_CONTENT_OPT: + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( nId ); + pRet = (*fnCreatePage)( pParent, rSet ); + break; + } + case RID_SW_TP_HTML_OPTGRID_PAGE: + case RID_SVXPAGE_GRID: + pRet = SvxGridTabPage::Create(pParent, rSet); + break; + + case RID_SW_TP_STD_FONT: + case RID_SW_TP_STD_FONT_CJK: + case RID_SW_TP_STD_FONT_CTL: + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( nId ); + pRet = (*fnCreatePage)( pParent, rSet ); + if(RID_SW_TP_STD_FONT != nId) + { + aSet.Put (SfxUInt16Item(SID_FONTMODE_TYPE, RID_SW_TP_STD_FONT_CJK == nId ? FONT_GROUP_CJK : FONT_GROUP_CTL)); + pRet->PageCreated(aSet); + } + } + break; + case RID_SW_TP_HTML_OPTPRINT_PAGE: + case RID_SW_TP_OPTPRINT_PAGE: + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( nId ); + pRet = (*fnCreatePage)( pParent, rSet ); + aSet.Put (SfxBoolItem(SID_FAX_LIST, true)); + pRet->PageCreated(aSet); + } + break; + case RID_SW_TP_HTML_OPTTABLE_PAGE: + case RID_SW_TP_OPTTABLE_PAGE: + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( nId ); + pRet = (*fnCreatePage)( pParent, rSet ); + SwView* pCurrView = GetView(); + if(pCurrView) + { + // if text then not WebView and vice versa + bool bWebView = 0 != PTR_CAST(SwWebView, pCurrView); + if( (bWebView && RID_SW_TP_HTML_OPTTABLE_PAGE == nId) || + (!bWebView && RID_SW_TP_HTML_OPTTABLE_PAGE != nId) ) + { + aSet.Put (SwWrtShellItem(SID_WRT_SHELL,pCurrView->GetWrtShellPtr())); + pRet->PageCreated(aSet); + } + } + } + break; + case RID_SW_TP_OPTSHDWCRSR: + case RID_SW_TP_HTML_OPTSHDWCRSR: + case RID_SW_TP_REDLINE_OPT: + case RID_SW_TP_COMPARISON_OPT: + case RID_SW_TP_OPTLOAD_PAGE: + case RID_SW_TP_OPTCOMPATIBILITY_PAGE: + case RID_SW_TP_MAILCONFIG: + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( nId ); + pRet = (*fnCreatePage)( pParent, rSet ); + if (nId == RID_SW_TP_OPTSHDWCRSR || nId == RID_SW_TP_HTML_OPTSHDWCRSR) + { + SwView* pCurrView = GetView(); + if(pCurrView) + { + aSet.Put( SwWrtShellItem( SID_WRT_SHELL, pCurrView->GetWrtShellPtr() ) ); + pRet->PageCreated(aSet); + } + } + } + break; + case RID_SW_TP_OPTTEST_PAGE: + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( nId ); + pRet = (*fnCreatePage)( pParent, rSet ); + break; + } + case RID_SW_TP_BACKGROUND: + { + SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); + ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ); + pRet = (*fnCreatePage)( pParent, rSet ); + break; + } + case RID_SW_TP_OPTCAPTION_PAGE: + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( RID_SW_TP_OPTCAPTION_PAGE ); + pRet = (*fnCreatePage)( pParent, rSet ); + } + break; + } + + if(!pRet) + SAL_WARN( "sw", "SwModule::CreateTabPage(): Unknown tabpage id " << nId ); + return pRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx new file mode 100644 index 000000000000..6272f021af8f --- /dev/null +++ b/sw/source/uibase/app/docsh.cxx @@ -0,0 +1,1328 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <hintids.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/svapp.hxx> +#include <vcl/wrkwin.hxx> +#include <vcl/jobset.hxx> +#include <svl/whiter.hxx> +#include <svl/zforlist.hxx> +#include <svl/eitem.hxx> +#include <svl/stritem.hxx> +#include <svl/PasswordHelper.hxx> +#include <editeng/adjustitem.hxx> +#include <basic/sbx.hxx> +#include <unotools/moduleoptions.hxx> +#include <unotools/misccfg.hxx> +#include <sfx2/request.hxx> +#include <sfx2/passwd.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/evntconf.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/printer.hxx> +#include <sfx2/linkmgr.hxx> +#include <svl/srchitem.hxx> +#include <editeng/flstitem.hxx> +#include <sfx2/htmlmode.hxx> +#include <svtools/soerr.hxx> +#include <comphelper/classids.hxx> +#include <basic/basmgr.hxx> +#include <basic/sbmod.hxx> +#include <swevent.hxx> +#include <fmtpdsc.hxx> +#include <fmtfsize.hxx> +#include <fmtfld.hxx> +#include <node.hxx> +#include <swwait.hxx> +#include <printdata.hxx> +#include <frmatr.hxx> +#include <view.hxx> +#include <edtwin.hxx> +#include <PostItMgr.hxx> +#include <wrtsh.hxx> +#include <docsh.hxx> +#include <basesh.hxx> +#include <viewopt.hxx> +#include <wdocsh.hxx> +#include <swmodule.hxx> +#include <globdoc.hxx> +#include <usrpref.hxx> +#include <shellio.hxx> +#include <docstyle.hxx> +#include <doc.hxx> +#include <IDocumentUndoRedo.hxx> +#include <docstat.hxx> +#include <pagedesc.hxx> +#include <pview.hxx> +#include <mdiexp.hxx> +#include <swbaslnk.hxx> +#include <srcview.hxx> +#include <ndindex.hxx> +#include <ndole.hxx> +#include <swcli.hxx> +#include <txtftn.hxx> +#include <ftnidx.hxx> +#include <fldbas.hxx> +#include <docary.hxx> +#include <swerror.h> +#include <helpid.h> +#include <cmdid.h> +#include <globals.hrc> +#include <app.hrc> + +#include <cfgid.h> +#include <unotools/fltrcfg.hxx> +#include <svtools/htmlcfg.hxx> +#include <sfx2/fcontnr.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/objface.hxx> +#include <comphelper/storagehelper.hxx> + +#define SwDocShell +#include <sfx2/msg.hxx> +#include <swslots.hxx> +#include <com/sun/star/document/UpdateDocMode.hpp> + +#include <com/sun/star/document/XDocumentProperties.hpp> +#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> + +#include <unomid.h> +#include <unotextrange.hxx> + +#include <sfx2/Metadatable.hxx> +#include <switerator.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::script; +using namespace ::com::sun::star::container; + +SFX_IMPL_INTERFACE(SwDocShell, SfxObjectShell, SW_RES(0) ) + +void SwDocShell::InitInterface_Impl() +{ +} + +TYPEINIT2(SwDocShell, SfxObjectShell, SfxListener); + +SFX_IMPL_OBJECTFACTORY(SwDocShell, SvGlobalName(SO3_SW_CLASSID), SFXOBJECTSHELL_STD_NORMAL|SFXOBJECTSHELL_HASMENU, "swriter" ) + +bool SwDocShell::InsertGeneratedStream(SfxMedium & rMedium, + uno::Reference<text::XTextRange> const& xInsertPosition) +{ + SwUnoInternalPaM aPam(*GetDoc()); // must have doc since called from SwView + if (!::sw::XTextRangeToSwPaM(aPam, xInsertPosition)) + return false; + // similar to SwView::InsertMedium + SwReader *pReader(0); + Reader *const pRead = StartConvertFrom(rMedium, &pReader, 0, &aPam); + if (!pRead) + return false; + sal_uLong const nError = pReader->Read(*pRead); + delete pReader; + return 0 == nError; +} + +// Prepare loading +Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr, + SwCrsrShell *pCrsrShell, + SwPaM* pPaM ) +{ + bool bAPICall = false; + const SfxPoolItem* pApiItem; + const SfxItemSet* pMedSet; + if( 0 != ( pMedSet = rMedium.GetItemSet() ) && SFX_ITEM_SET == + pMedSet->GetItemState( FN_API_CALL, true, &pApiItem ) ) + bAPICall = ((const SfxBoolItem*)pApiItem)->GetValue(); + + const SfxFilter* pFlt = rMedium.GetFilter(); + if( !pFlt ) + { + if(!bAPICall) + { + InfoBox( 0, SW_RESSTR(STR_CANTOPEN)).Execute(); + } + return 0; + } + OUString aFileName( rMedium.GetName() ); + SwRead pRead = SwReaderWriter::GetReader( pFlt->GetUserData() ); + if( !pRead ) + return 0; + + if( rMedium.IsStorage() + ? SW_STORAGE_READER & pRead->GetReaderType() + : SW_STREAM_READER & pRead->GetReaderType() ) + { + *ppRdr = pPaM ? new SwReader( rMedium, aFileName, *pPaM ) : + pCrsrShell ? + new SwReader( rMedium, aFileName, *pCrsrShell->GetCrsr() ) + : new SwReader( rMedium, aFileName, pDoc ); + } + else + return 0; + + // Check password + OUString aPasswd; + if ((*ppRdr)->NeedsPasswd( *pRead )) + { + if(!bAPICall) + { + SfxPasswordDialog* pPasswdDlg = + new SfxPasswordDialog( 0 ); + if(RET_OK == pPasswdDlg->Execute()) + aPasswd = pPasswdDlg->GetPassword(); + } + else + { + const SfxItemSet* pSet = rMedium.GetItemSet(); + const SfxPoolItem *pPassItem; + if(pSet && SFX_ITEM_SET == pSet->GetItemState(SID_PASSWORD, true, &pPassItem)) + aPasswd = ((const SfxStringItem *)pPassItem)->GetValue(); + } + + if (!(*ppRdr)->CheckPasswd( aPasswd, *pRead )) + { + InfoBox( 0, SW_RES(MSG_ERROR_PASSWD)).Execute(); + delete *ppRdr; + return 0; + } + } + + // #i30171# set the UpdateDocMode at the SwDocShell + SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, false); + nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE; + + if (!pFlt->GetDefaultTemplate().isEmpty()) + pRead->SetTemplateName( pFlt->GetDefaultTemplate() ); + + if( pRead == ReadAscii && 0 != rMedium.GetInStream() && + pFlt->GetUserData() == FILTER_TEXT_DLG ) + { + SwAsciiOptions aOpt; + const SfxItemSet* pSet; + const SfxPoolItem* pItem; + if( 0 != ( pSet = rMedium.GetItemSet() ) && SFX_ITEM_SET == + pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) ) + aOpt.ReadUserData( ((const SfxStringItem*)pItem)->GetValue() ); + + if( pRead ) + pRead->GetReaderOpt().SetASCIIOpts( aOpt ); + } + + return pRead; +} + +// Loading +bool SwDocShell::ConvertFrom( SfxMedium& rMedium ) +{ + SwReader* pRdr; + SwRead pRead = StartConvertFrom(rMedium, &pRdr); + if (!pRead) + return false; // #129881# return if no reader is found + SotStorageRef pStg=pRead->getSotStorageRef(); // #i45333# save sot storage ref in case of recursive calls + + pDoc->setDocAccTitle(OUString()); + SfxViewFrame* pFrame1 = SfxViewFrame::GetFirst( this ); + if (pFrame1) + { + Window* pWindow = &pFrame1->GetWindow(); + if ( pWindow ) + { + Window* pSysWin = pWindow->GetSystemWindow(); + if ( pSysWin ) + { + pSysWin->SetAccessibleName(OUString()); + } + } + } + SwWait aWait( *this, true ); + + // Suppress SfxProgress, when we are Embedded + SW_MOD()->SetEmbeddedLoadSave( + SFX_CREATE_MODE_EMBEDDED == GetCreateMode() ); + + pRdr->GetDoc()->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell)); + + /* #106748# Restore the pool default if reading a saved document. */ + pDoc->RemoveAllFmtLanguageDependencies(); + + sal_uLong nErr = pRdr->Read( *pRead ); + + // Maybe put away one old Doc + if ( pDoc != pRdr->GetDoc() ) + { + RemoveLink(); + pDoc = pRdr->GetDoc(); + + AddLink(); + + if ( !mxBasePool.is() ) + mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() ); + } + + UpdateFontList(); + InitDraw(); + + delete pRdr; + + SW_MOD()->SetEmbeddedLoadSave( false ); + + SetError( nErr, OUString( OSL_LOG_PREFIX ) ); + bool bOk = !IsError( nErr ); + + if ( bOk && !pDoc->IsInLoadAsynchron() ) + { + LoadingFinished(); + } + + pRead->setSotStorageRef(pStg); // #i45333# save sot storage ref in case of recursive calls + + return bOk; +} + +// Saving the Default-Format, Stg present +bool SwDocShell::Save() +{ + //#i3370# remove quick help to prevent saving of autocorrection suggestions + if(pView) + pView->GetEditWin().StopQuickHelp(); + SwWait aWait( *this, true ); + + CalcLayoutForOLEObjects(); // format for OLE objets + // #i62875# + // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible + if ( pWrtShell && pDoc && + pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) && + docfunc::AllDrawObjsOnPage( *pDoc ) ) + { + pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false); + } + + sal_uLong nErr = ERR_SWG_WRITE_ERROR, nVBWarning = ERRCODE_NONE; + if( SfxObjectShell::Save() ) + { + switch( GetCreateMode() ) + { + case SFX_CREATE_MODE_INTERNAL: + nErr = 0; + break; + + case SFX_CREATE_MODE_ORGANIZER: + { + WriterRef xWrt; + ::GetXMLWriter( aEmptyOUStr, GetMedium()->GetBaseURL( true ), xWrt ); + xWrt->SetOrganizerMode( true ); + SwWriter aWrt( *GetMedium(), *pDoc ); + nErr = aWrt.Write( xWrt ); + xWrt->SetOrganizerMode( false ); + } + break; + + case SFX_CREATE_MODE_EMBEDDED: + // Suppress SfxProgress, if we are Embedded + SW_MOD()->SetEmbeddedLoadSave( true ); + // no break; + + case SFX_CREATE_MODE_STANDARD: + case SFX_CREATE_MODE_PREVIEW: + default: + { + if( pDoc->ContainsMSVBasic() ) + { + if( SvtFilterOptions::Get().IsLoadWordBasicStorage() ) + nVBWarning = GetSaveWarningOfMSVBAStorage( (SfxObjectShell&) (*this) ); + pDoc->SetContainsMSVBasic( false ); + } + + // End TableBox Edit! + if( pWrtShell ) + pWrtShell->EndAllTblBoxEdit(); + + WriterRef xWrt; + ::GetXMLWriter( aEmptyOUStr, GetMedium()->GetBaseURL( true ), xWrt ); + + bool bLockedView(false); + if ( pWrtShell ) + { + bLockedView = pWrtShell->IsViewLocked(); + pWrtShell->LockView( true ); //lock visible section + } + + SwWriter aWrt( *GetMedium(), *pDoc ); + nErr = aWrt.Write( xWrt ); + + if ( pWrtShell ) + pWrtShell->LockView( bLockedView ); + } + break; + } + SW_MOD()->SetEmbeddedLoadSave( false ); + } + SetError( nErr ? nErr : nVBWarning, OUString( OSL_LOG_PREFIX ) ); + + SfxViewFrame* pFrm = pWrtShell ? pWrtShell->GetView().GetViewFrame() : 0; + if( pFrm ) + { + pFrm->GetBindings().SetState(SfxBoolItem(SID_DOC_MODIFIED, false)); + } + return !IsError( nErr ); +} + +// Save using the Defaultformat +bool SwDocShell::SaveAs( SfxMedium& rMedium ) +{ + SwWait aWait( *this, true ); + //#i3370# remove quick help to prevent saving of autocorrection suggestions + if(pView) + pView->GetEditWin().StopQuickHelp(); + + //#i91811# mod if we have an active margin window, write back the text + if ( pView && + pView->GetPostItMgr() && + pView->GetPostItMgr()->HasActiveSidebarWin() ) + { + pView->GetPostItMgr()->UpdateDataOnActiveSidebarWin(); + } + + if( pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) && + !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS) ) + RemoveOLEObjects(); + + { + // Task 75666 - is the Document imported by our Microsoft-Filters? + const SfxFilter* pOldFilter = GetMedium()->GetFilter(); + if( pOldFilter && + ( pOldFilter->GetUserData() == FILTER_WW8 || + pOldFilter->GetUserData() == "CWW6" || + pOldFilter->GetUserData() == "WW6" || + pOldFilter->GetUserData() == "WW1" ) ) + { + // when saving it in our own fileformat, then remove the template + // name from the docinfo. + uno::Reference<document::XDocumentPropertiesSupplier> xDPS( + GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<document::XDocumentProperties> xDocProps + = xDPS->getDocumentProperties(); + xDocProps->setTemplateName(OUString()); + xDocProps->setTemplateURL(OUString()); + xDocProps->setTemplateDate(::util::DateTime()); + } + } + + CalcLayoutForOLEObjects(); // format for OLE objets + // #i62875# + // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible + if ( pWrtShell && + pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) && + docfunc::AllDrawObjsOnPage( *pDoc ) ) + { + pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false); + } + + sal_uLong nErr = ERR_SWG_WRITE_ERROR, nVBWarning = ERRCODE_NONE; + uno::Reference < embed::XStorage > xStor = rMedium.GetOutputStorage(); + if( SfxObjectShell::SaveAs( rMedium ) ) + { + if( GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) && !ISA( SwGlobalDocShell ) ) + { + // This is to set the correct class id if SaveAs is + // called from SwDoc::SplitDoc to save a normal doc as + // global doc. In this case, SaveAs is called at a + // normal doc shell, therefore, SfxInplaceObject::SaveAs + // will set the wrong class id. + SvGlobalName aClassName; + // The document is closed explicitly, but using SfxObjectShellLock is still more correct here + SfxObjectShellLock xDocSh = + new SwGlobalDocShell( SFX_CREATE_MODE_INTERNAL ); + // the global document can not be a template + xDocSh->SetupStorage( xStor, SotStorage::GetVersion( xStor ), false ); + xDocSh->DoClose(); + } + + if( pDoc->ContainsMSVBasic() ) + { + if( SvtFilterOptions::Get().IsLoadWordBasicStorage() ) + nVBWarning = GetSaveWarningOfMSVBAStorage( (SfxObjectShell&) *this ); + pDoc->SetContainsMSVBasic( false ); + } + + // End TableBox Edit! + if( pWrtShell ) + pWrtShell->EndAllTblBoxEdit(); + + // Remember and preserve Modified-Flag without calling the Link + // (for OLE; after Statement from MM) + bool bIsModified = pDoc->IsModified(); + pDoc->GetIDocumentUndoRedo().LockUndoNoModifiedPosition(); + Link aOldOLELnk( pDoc->GetOle2Link() ); + pDoc->SetOle2Link( Link() ); + + // Suppress SfxProgress when we are Embedded + SW_MOD()->SetEmbeddedLoadSave( + SFX_CREATE_MODE_EMBEDDED == GetCreateMode() ); + + WriterRef xWrt; + ::GetXMLWriter( aEmptyOUStr, rMedium.GetBaseURL( true ), xWrt ); + + bool bLockedView(false); + if ( pWrtShell ) + { + bLockedView = pWrtShell->IsViewLocked(); + pWrtShell->LockView( true ); //lock visible section + } + + SwWriter aWrt( rMedium, *pDoc ); + nErr = aWrt.Write( xWrt ); + + if ( pWrtShell ) + pWrtShell->LockView( bLockedView ); + + if( bIsModified ) + { + pDoc->SetModified(); + pDoc->GetIDocumentUndoRedo().UnLockUndoNoModifiedPosition(); + } + pDoc->SetOle2Link( aOldOLELnk ); + + SW_MOD()->SetEmbeddedLoadSave( false ); + + // Increase RSID + pDoc->setRsid( pDoc->getRsid() ); + } + SetError( nErr ? nErr : nVBWarning, OUString( OSL_LOG_PREFIX ) ); + + return !IsError( nErr ); +} + +// Save all Formats +static SwSrcView* lcl_GetSourceView( SwDocShell* pSh ) +{ + // are we in SourceView? + SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( pSh ); + SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : 0; + return PTR_CAST( SwSrcView, pViewShell); +} + +bool SwDocShell::ConvertTo( SfxMedium& rMedium ) +{ + const SfxFilter* pFlt = rMedium.GetFilter(); + if( !pFlt ) + return false; + + WriterRef xWriter; + SwReaderWriter::GetWriter( pFlt->GetUserData(), rMedium.GetBaseURL( true ), xWriter ); + if( !xWriter.Is() ) + { // Filter not available + InfoBox( 0, + SW_RESSTR(STR_DLLNOTFOUND) ).Execute(); + return false; + } + + //#i3370# remove quick help to prevent saving of autocorrection suggestions + if(pView) + pView->GetEditWin().StopQuickHelp(); + + //#i91811# mod if we have an active margin window, write back the text + if ( pView && + pView->GetPostItMgr() && + pView->GetPostItMgr()->HasActiveSidebarWin() ) + { + pView->GetPostItMgr()->UpdateDataOnActiveSidebarWin(); + } + + sal_uLong nVBWarning = 0; + + if( pDoc->ContainsMSVBasic() ) + { + bool bSave = pFlt->GetUserData() == "CWW8" + && SvtFilterOptions::Get().IsLoadWordBasicStorage(); + + if ( bSave ) + { + SvStorageRef xStg = new SotStorage( rMedium.GetOutStream(), false ); + OSL_ENSURE( !xStg->GetError(), "No storage available for storing VBA macros!" ); + if ( !xStg->GetError() ) + { + nVBWarning = SaveOrDelMSVBAStorage( (SfxObjectShell&) *this, *xStg, bSave, OUString("Macros") ); + xStg->Commit(); + pDoc->SetContainsMSVBasic( true ); + } + } + } + + // End TableBox Edit! + if( pWrtShell ) + pWrtShell->EndAllTblBoxEdit(); + + if( pFlt->GetUserData() == "HTML" ) + { +#ifndef DISABLE_SCRIPTING + SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get(); + if( !rHtmlOpt.IsStarBasic() && rHtmlOpt.IsStarBasicWarning() && HasBasic() ) + { + uno::Reference< XLibraryContainer > xLibCont(GetBasicContainer(), UNO_QUERY); + uno::Reference< XNameAccess > xLib; + Sequence<OUString> aNames = xLibCont->getElementNames(); + const OUString* pNames = aNames.getConstArray(); + for(sal_Int32 nLib = 0; nLib < aNames.getLength(); nLib++) + { + Any aLib = xLibCont->getByName(pNames[nLib]); + aLib >>= xLib; + if(xLib.is()) + { + Sequence<OUString> aModNames = xLib->getElementNames(); + if(aModNames.getLength()) + { + SetError(WARN_SWG_HTML_NO_MACROS, OUString( OSL_LOG_PREFIX ) ); + break; + } + } + } + } +#endif + } + + // #i76360# Update document statistics + pDoc->UpdateDocStat(); + + CalcLayoutForOLEObjects(); // format for OLE objets + // #i62875# + // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible + if ( pWrtShell && + pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) && + docfunc::AllDrawObjsOnPage( *pDoc ) ) + { + pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false); + } + + if( xWriter->IsStgWriter() && + ( pFlt->GetUserData() == FILTER_XML || + pFlt->GetUserData() == FILTER_XMLV || + pFlt->GetUserData() == FILTER_XMLVW ) ) + { + // determine the own Type + sal_uInt8 nMyType = 0; + if( ISA( SwWebDocShell) ) + nMyType = 1; + else if( ISA( SwGlobalDocShell) ) + nMyType = 2; + + // determine the desired Type + sal_uInt8 nSaveType = 0; + sal_uLong nSaveClipId = pFlt->GetFormat(); + if( SOT_FORMATSTR_ID_STARWRITERWEB_8 == nSaveClipId || + SOT_FORMATSTR_ID_STARWRITERWEB_60 == nSaveClipId || + SOT_FORMATSTR_ID_STARWRITERWEB_50 == nSaveClipId || + SOT_FORMATSTR_ID_STARWRITERWEB_40 == nSaveClipId ) + nSaveType = 1; + else if( SOT_FORMATSTR_ID_STARWRITERGLOB_8 == nSaveClipId || + SOT_FORMATSTR_ID_STARWRITERGLOB_60 == nSaveClipId || + SOT_FORMATSTR_ID_STARWRITERGLOB_50 == nSaveClipId || + SOT_FORMATSTR_ID_STARWRITERGLOB_40 == nSaveClipId ) + nSaveType = 2; + + // Change Flags of the Document accordingly + bool bIsHTMLModeSave = GetDoc()->get(IDocumentSettingAccess::HTML_MODE); + bool bIsGlobalDocSave = GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT); + bool bIsGlblDocSaveLinksSave = GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS); + if( nMyType != nSaveType ) + { + GetDoc()->set(IDocumentSettingAccess::HTML_MODE, 1 == nSaveType); + GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, 2 == nSaveType); + if( 2 != nSaveType ) + GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, false); + } + + // if the target format is storage based, then the output storage must be already created + if ( rMedium.IsStorage() ) + { + // set MediaType on target storage + // (MediaType will be queried during SaveAs) + try + { + // TODO/MBA: testing + uno::Reference < beans::XPropertySet > xSet( rMedium.GetStorage(), uno::UNO_QUERY ); + if ( xSet.is() ) + xSet->setPropertyValue("MediaType", uno::makeAny( OUString( SotExchange::GetFormatMimeType( nSaveClipId ) ) ) ); + } + catch (const uno::Exception&) + { + } + } + + // Now normally save the Document + bool bRet = SaveAs( rMedium ); + + if( nMyType != nSaveType ) + { + GetDoc()->set(IDocumentSettingAccess::HTML_MODE, bIsHTMLModeSave ); + GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, bIsGlobalDocSave); + GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, bIsGlblDocSaveLinksSave); + } + + return bRet; + } + + if( pFlt->GetUserData() == FILTER_TEXT_DLG && + ( pWrtShell || !::lcl_GetSourceView( this ) )) + { + SwAsciiOptions aOpt; + OUString sItemOpt; + const SfxItemSet* pSet; + const SfxPoolItem* pItem; + if( 0 != ( pSet = rMedium.GetItemSet() ) ) + { + if( SFX_ITEM_SET == pSet->GetItemState( SID_FILE_FILTEROPTIONS, + true, &pItem ) ) + sItemOpt = ((const SfxStringItem*)pItem)->GetValue(); + } + if(!sItemOpt.isEmpty()) + aOpt.ReadUserData( sItemOpt ); + + xWriter->SetAsciiOptions( aOpt ); + } + + // Suppress SfxProgress when we are Embedded + SW_MOD()->SetEmbeddedLoadSave( + SFX_CREATE_MODE_EMBEDDED == GetCreateMode()); + + // Span Context in order to suppress the Selection's View + sal_uLong nErrno; + const OUString aFileName( rMedium.GetName() ); + + // No View, so the whole Document! + if ( pWrtShell && !Application::IsHeadlessModeEnabled() ) + { + SwWait aWait( *this, true ); + // #i106906# + const bool bFormerLockView = pWrtShell->IsViewLocked(); + pWrtShell->LockView( true ); + pWrtShell->StartAllAction(); + pWrtShell->Push(); + SwWriter aWrt( rMedium, *pWrtShell, true ); + nErrno = aWrt.Write( xWriter, &aFileName ); + //JP 16.05.97: In case the SFX revokes the View while saving + if( pWrtShell ) + { + pWrtShell->Pop(false); + pWrtShell->EndAllAction(); + // #i106906# + pWrtShell->LockView( bFormerLockView ); + } + } + else + { + // are we in SourceView? + SwSrcView* pSrcView = ::lcl_GetSourceView( this ); + if( pSrcView ) + { + pSrcView->SaveContentTo(rMedium); + nErrno = 0; + } + else + { + SwWriter aWrt( rMedium, *pDoc ); + nErrno = aWrt.Write( xWriter, &aFileName ); + } + } + + SW_MOD()->SetEmbeddedLoadSave( false ); + SetError( nErrno ? nErrno : nVBWarning, OUString( OSL_LOG_PREFIX ) ); + if( !rMedium.IsStorage() ) + rMedium.CloseOutStream(); + + return !IsError( nErrno ); +} + +// Hands off +// do not yet activate, must deliver TRUE +bool SwDocShell::SaveCompleted( const uno::Reference < embed::XStorage >& xStor ) +{ + bool bRet = SfxObjectShell::SaveCompleted( xStor ); + if( bRet ) + { + // Do not decide until here, whether Saving was successful or not + if( IsModified() ) + pDoc->SetModified(); + else + pDoc->ResetModified(); + } + + if( pOLEChildList ) + { + bool bResetModified = IsEnableSetModified(); + if( bResetModified ) + EnableSetModified( false ); + + uno::Sequence < OUString > aNames = pOLEChildList->GetObjectNames(); + for( sal_Int32 n = aNames.getLength(); n; n-- ) + { + if ( !pOLEChildList->MoveEmbeddedObject( aNames[n-1], GetEmbeddedObjectContainer() ) ) + { + OSL_FAIL("Copying of objects didn't work!" ); + } + } + + DELETEZ( pOLEChildList ); + if( bResetModified ) + EnableSetModified( true ); + } + return bRet; +} + +// Draw()-Overload for OLE2 (Sfx) +void SwDocShell::Draw( OutputDevice* pDev, const JobSetup& rSetup, + sal_uInt16 nAspect ) +{ + //fix #25341# Draw should not affect the Modified + bool bResetModified; + if ( (bResetModified = IsEnableSetModified()) ) + EnableSetModified( false ); + + // When there is a JobSetup connected to the Document, we copy it to + // reconnect it after PrtOle2. We don't use an empty JobSetup because + // that would only lead to questionable results after expensive + // reformatting (Preview!) + JobSetup *pOrig = 0; + if ( !rSetup.GetPrinterName().isEmpty() && ASPECT_THUMBNAIL != nAspect ) + { + pOrig = const_cast<JobSetup*>(pDoc->getJobsetup()); + if( pOrig ) // then we copy that + pOrig = new JobSetup( *pOrig ); + pDoc->setJobsetup( rSetup ); + } + + Rectangle aRect( nAspect == ASPECT_THUMBNAIL ? + GetVisArea( nAspect ) : GetVisArea( ASPECT_CONTENT ) ); + + pDev->Push(); + pDev->SetFillColor(); + pDev->SetLineColor(); + pDev->SetBackground(); + const bool bWeb = this->ISA(SwWebDocShell); + SwPrintData aOpts; + SwViewShell::PrtOle2( pDoc, SW_MOD()->GetUsrPref(bWeb), aOpts, pDev, aRect ); + pDev->Pop(); + + if( pOrig ) + { + pDoc->setJobsetup( *pOrig ); + delete pOrig; + } + if ( bResetModified ) + EnableSetModified( true ); +} + +void SwDocShell::SetVisArea( const Rectangle &rRect ) +{ + Rectangle aRect( rRect ); + if ( pView ) + { + Size aSz( pView->GetDocSz() ); + aSz.Width() += DOCUMENTBORDER; aSz.Height() += DOCUMENTBORDER; + long nMoveX = 0, nMoveY = 0; + if ( aRect.Right() > aSz.Width() ) + nMoveX = aSz.Width() - aRect.Right(); + if ( aRect.Bottom() > aSz.Height() ) + nMoveY = aSz.Height() - aRect.Bottom(); + aRect.Move( nMoveX, nMoveY ); + nMoveX = aRect.Left() < 0 ? -aRect.Left() : 0; + nMoveY = aRect.Top() < 0 ? -aRect.Top() : 0; + aRect.Move( nMoveX, nMoveY ); + + // Calls SfxInPlaceObject::SetVisArea()! + pView->SetVisArea( aRect, true ); + } + else + SfxObjectShell::SetVisArea( aRect ); +} + +Rectangle SwDocShell::GetVisArea( sal_uInt16 nAspect ) const +{ + if ( nAspect == ASPECT_THUMBNAIL ) + { + // Preview: set VisArea to the first page. + SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 1 ); + SwCntntNode* pNd = pDoc->GetNodes().GoNext( &aIdx ); + + const SwRect aPageRect = pNd->FindPageFrmRect( false, 0, false ); + return aPageRect.SVRect(); + } + return SfxObjectShell::GetVisArea( nAspect ); +} + +Printer *SwDocShell::GetDocumentPrinter() +{ + return pDoc->getPrinter( false ); +} + +OutputDevice* SwDocShell::GetDocumentRefDev() +{ + return pDoc->getReferenceDevice( false ); +} + +void SwDocShell::OnDocumentPrinterChanged( Printer * pNewPrinter ) +{ + if ( pNewPrinter ) + GetDoc()->setJobsetup( pNewPrinter->GetJobSetup() ); + else + GetDoc()->setPrinter( 0, true, true ); +} + +sal_uLong SwDocShell::GetMiscStatus() const +{ + return SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE; +} + +// #i20883# Digital Signatures and Encryption +sal_uInt16 SwDocShell::GetHiddenInformationState( sal_uInt16 nStates ) +{ + // get global state like HIDDENINFORMATION_DOCUMENTVERSIONS + sal_uInt16 nState = SfxObjectShell::GetHiddenInformationState( nStates ); + + if ( nStates & HIDDENINFORMATION_RECORDEDCHANGES ) + { + if ( !GetDoc()->GetRedlineTbl().empty() ) + nState |= HIDDENINFORMATION_RECORDEDCHANGES; + } + if ( nStates & HIDDENINFORMATION_NOTES ) + { + OSL_ENSURE( GetWrtShell(), "No SwWrtShell, no information" ); + if ( GetWrtShell() ) + { + SwFieldType* pType = GetWrtShell()->GetFldType( RES_POSTITFLD, aEmptyOUStr ); + SwIterator<SwFmtFld,SwFieldType> aIter( *pType ); + SwFmtFld* pFirst = aIter.First(); + while( pFirst ) + { + if( pFirst->GetTxtFld() && pFirst->IsFldInDoc() ) + { + nState |= HIDDENINFORMATION_NOTES; + break; + } + pFirst = aIter.Next(); + } + } + } + + return nState; +} + +void SwDocShell::GetState(SfxItemSet& rSet) +{ + SfxWhichIter aIter(rSet); + sal_uInt16 nWhich = aIter.FirstWhich(); + + while (nWhich) + { + switch (nWhich) + { + case SID_PRINTPREVIEW: + { + bool bDisable = IsInPlaceActive(); + // Disable "multiple layout" + if ( !bDisable ) + { + SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this); + while (pTmpFrm) // Look for Preview + { + if ( PTR_CAST(SwView, pTmpFrm->GetViewShell()) && + ((SwView*)pTmpFrm->GetViewShell())->GetWrtShell().GetViewOptions()->getBrowseMode() ) + { + bDisable = true; + break; + } + pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this); + } + } + // End of disabled "multiple layout" + if ( bDisable ) + rSet.DisableItem( SID_PRINTPREVIEW ); + else + { + SfxBoolItem aBool( SID_PRINTPREVIEW, false ); + if( PTR_CAST( SwPagePreview, SfxViewShell::Current()) ) + aBool.SetValue( true ); + rSet.Put( aBool ); + } + } + break; + case SID_SOURCEVIEW: + { + SfxViewShell* pCurrView = GetView() ? (SfxViewShell*)GetView() + : SfxViewShell::Current(); + bool bSourceView = 0 != PTR_CAST(SwSrcView, pCurrView); + rSet.Put(SfxBoolItem(SID_SOURCEVIEW, bSourceView)); + } + break; + case SID_HTML_MODE: + rSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this))); + break; + + case FN_ABSTRACT_STARIMPRESS: + case FN_OUTLINE_TO_IMPRESS: + { + SvtModuleOptions aMOpt; + if ( !aMOpt.IsImpress() ) + rSet.DisableItem( nWhich ); + } + /* no break here */ + case FN_ABSTRACT_NEWDOC: + case FN_OUTLINE_TO_CLIPBOARD: + { + if ( GetDoc()->GetNodes().GetOutLineNds().empty() ) + rSet.DisableItem( nWhich ); + } + break; + case SID_BROWSER_MODE: + case FN_PRINT_LAYOUT: + { + bool bState = GetDoc()->get(IDocumentSettingAccess::BROWSE_MODE); + if(FN_PRINT_LAYOUT == nWhich) + bState = !bState; + rSet.Put( SfxBoolItem( nWhich, bState)); + } + break; + + case FN_NEW_GLOBAL_DOC: + if ( ISA(SwGlobalDocShell) ) + rSet.DisableItem( nWhich ); + break; + + case FN_NEW_HTML_DOC: + if( ISA( SwWebDocShell ) ) + rSet.DisableItem( nWhich ); + break; + + case FN_OPEN_FILE: + if( ISA( SwWebDocShell ) ) + rSet.DisableItem( nWhich ); + break; + + case SID_ATTR_YEAR2000: + { + const SvNumberFormatter* pFmtr = pDoc->GetNumberFormatter(false); + rSet.Put( SfxUInt16Item( nWhich, + static_cast< sal_uInt16 >( + pFmtr ? pFmtr->GetYear2000() + : ::utl::MiscCfg().GetYear2000() ))); + } + break; + case SID_ATTR_CHAR_FONTLIST: + { + rSet.Put( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) ); + } + break; + case SID_MAIL_PREPAREEXPORT: + { + //check if linked content or possibly hidden content is available + //pDoc->UpdateFlds( NULL, false ); + sfx2::LinkManager& rLnkMgr = pDoc->GetLinkManager(); + const ::sfx2::SvBaseLinks& rLnks = rLnkMgr.GetLinks(); + bool bRet = false; + if( !rLnks.empty() ) + bRet = true; + else + { + //sections with hidden flag, hidden character attribute, hidden paragraph/text or conditional text fields + bRet = pDoc->HasInvisibleContent(); + } + rSet.Put( SfxBoolItem( nWhich, bRet ) ); + } + break; + + default: OSL_ENSURE(!this,"You cannot get here!"); + + } + nWhich = aIter.NextWhich(); + } +} + +// OLE-Hdls +IMPL_LINK( SwDocShell, Ole2ModifiedHdl, void *, p ) +{ + // the Status is handed over from Doc (see doc.cxx) + // Bit 0: -> old state + // Bit 1: -> new state + sal_IntPtr nStatus = (sal_IntPtr)p; + if( IsEnableSetModified() ) + SetModified( (nStatus & 2) ? sal_True : sal_False ); + return 0; +} + +// return Pool here, because virtual +SfxStyleSheetBasePool* SwDocShell::GetStyleSheetPool() +{ + return mxBasePool.get(); +} + +void SwDocShell::SetView(SwView* pVw) +{ + if ( 0 != (pView = pVw) ) + pWrtShell = &pView->GetWrtShell(); + else + pWrtShell = 0; +} + +void SwDocShell::PrepareReload() +{ + ::DelAllGrfCacheEntries( pDoc ); +} + +// #i59688# +// linked graphics are now loaded on demand. +// Thus, loading of linked graphics no longer needed and necessary for +// the load of document being finished. +void SwDocShell::LoadingFinished() +{ + // #i38810# + // Original fix fails after integration of cws xmlsec11: + // interface <SfxObjectShell::EnableSetModified(..)> no longer works, because + // <SfxObjectShell::FinishedLoading(..)> doesn't care about its status and + // enables the document modification again. + // Thus, manuell modify the document, if its modified and its links are updated + // before <FinishedLoading(..)> is called. + const bool bHasDocToStayModified( pDoc->IsModified() && pDoc->LinksUpdated() ); + + FinishedLoading( SFX_LOADED_ALL ); + SfxViewFrame* pVFrame = SfxViewFrame::GetFirst(this); + if(pVFrame) + { + SfxViewShell* pShell = pVFrame->GetViewShell(); + if(PTR_CAST(SwSrcView, pShell)) + ((SwSrcView*)pShell)->Load(this); + } + + // #i38810# + if ( bHasDocToStayModified && !pDoc->IsModified() ) + { + pDoc->SetModified(); + } +} + +// a Transfer is cancelled (is called from SFX) +void SwDocShell::CancelTransfers() +{ + // Cancel all links from LinkManager + aFinishedTimer.Stop(); + pDoc->GetLinkManager().CancelTransfers(); + SfxObjectShell::CancelTransfers(); +} + +SwFEShell* SwDocShell::GetFEShell() +{ + return pWrtShell; +} + +void SwDocShell::RemoveOLEObjects() +{ + SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() ); + for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() ) + { + SwOLENode* pOLENd = pNd->GetOLENode(); + if( pOLENd && ( pOLENd->IsOLEObjectDeleted() || + pOLENd->IsInGlobalDocSection() ) ) + { + if( !pOLEChildList ) + pOLEChildList = new comphelper::EmbeddedObjectContainer; + + OUString aObjName = pOLENd->GetOLEObj().GetCurrentPersistName(); + GetEmbeddedObjectContainer().MoveEmbeddedObject( aObjName, *pOLEChildList ); + } + } +} + +// When a document is loaded, SwDoc::PrtOLENotify is called to update +// the sizes of math objects. However, for objects that do not have a +// SwFrm at this time, only a flag is set (bIsOLESizeInvalid) and the +// size change takes place later, while calculating the layout in the +// idle handler. If this document is saved now, it is saved with invalid +// sizes. For this reason, the layout has to be calculated before a document is +// saved, but of course only id there are OLE objects with bOLESizeInvalid set. +void SwDocShell::CalcLayoutForOLEObjects() +{ + if( !pWrtShell ) + return; + + SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() ); + for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() ) + { + SwOLENode* pOLENd = pNd->GetOLENode(); + if( pOLENd && pOLENd->IsOLESizeInvalid() ) + { + pWrtShell->CalcLayout(); + break; + } + } +} + +// #i42634# Overwrites SfxObjectShell::UpdateLinks +// This new function is necessary to trigger update of links in docs +// read by the binary filter: +void SwDocShell::UpdateLinks() +{ + GetDoc()->UpdateLinks(true); + // #i50703# Update footnote numbers + SwTxtFtn::SetUniqueSeqRefNo( *GetDoc() ); + SwNodeIndex aTmp( GetDoc()->GetNodes() ); + GetDoc()->GetFtnIdxs().UpdateFtn( aTmp ); +} + +uno::Reference< frame::XController > + SwDocShell::GetController() +{ + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > aRet; + // #i82346# No view in page preview + if ( GetView() ) + aRet = GetView()->GetController(); + return aRet; +} + +void SwDocShell::setDocAccTitle( const OUString& rTitle ) +{ + if (pDoc) + { + pDoc->setDocAccTitle( rTitle ); + } +} + +const OUString SwDocShell::getDocAccTitle() const +{ + OUString sRet; + if (pDoc) + { + sRet = pDoc->getDocAccTitle(); + } + + return sRet; +} + +static const char* s_EventNames[] = +{ + "OnPageCountChange", + "OnMailMerge", + "OnMailMergeFinished", + "OnFieldMerge", + "OnFieldMergeFinished", + "OnLayoutFinished" +}; +static sal_Int32 const s_nEvents(sizeof(s_EventNames)/sizeof(s_EventNames[0])); + +Sequence< OUString > SwDocShell::GetEventNames() +{ + Sequence< OUString > aRet = SfxObjectShell::GetEventNames(); + sal_Int32 nLen = aRet.getLength(); + aRet.realloc(nLen + 6); + OUString* pNames = aRet.getArray(); + pNames[nLen++] = GetEventName(0); + pNames[nLen++] = GetEventName(1); + pNames[nLen++] = GetEventName(2); + pNames[nLen++] = GetEventName(3); + pNames[nLen++] = GetEventName(4); + pNames[nLen] = GetEventName(5); + + return aRet; +} + +OUString SwDocShell::GetEventName( sal_Int32 nIndex ) +{ + if (nIndex < s_nEvents) + { + return OUString::createFromAscii(s_EventNames[nIndex]); + } + return OUString(); +} + +const ::sfx2::IXmlIdRegistry* SwDocShell::GetXmlIdRegistry() const +{ + return pDoc ? &pDoc->GetXmlIdRegistry() : 0; +} + +bool SwDocShell::IsChangeRecording() const +{ + return (pWrtShell->GetRedlineMode() & nsRedlineMode_t::REDLINE_ON) != 0; +} + +bool SwDocShell::HasChangeRecordProtection() const +{ + return pWrtShell->getIDocumentRedlineAccess()->GetRedlinePassword().getLength() > 0; +} + +void SwDocShell::SetChangeRecording( bool bActivate ) +{ + sal_uInt16 nOn = bActivate ? nsRedlineMode_t::REDLINE_ON : 0; + sal_uInt16 nMode = pWrtShell->GetRedlineMode(); + pWrtShell->SetRedlineModeAndCheckInsMode( (nMode & ~nsRedlineMode_t::REDLINE_ON) | nOn); +} + +bool SwDocShell::SetProtectionPassword( const OUString &rNewPassword ) +{ + const SfxAllItemSet aSet( GetPool() ); + const SfxItemSet* pArgs = &aSet; + const SfxPoolItem* pItem = NULL; + + IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess(); + Sequence< sal_Int8 > aPasswd = pIDRA->GetRedlinePassword(); + if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_REDLINE_PROTECT, false, &pItem ) + && ((SfxBoolItem*)pItem)->GetValue() == (aPasswd.getLength() > 0)) + return false; + + bool bRes = false; + + if (!rNewPassword.isEmpty()) + { + // when password protection is applied change tracking must always be active + SetChangeRecording( true ); + + Sequence< sal_Int8 > aNewPasswd; + SvPasswordHelper::GetHashPassword( aNewPasswd, rNewPassword ); + pIDRA->SetRedlinePassword( aNewPasswd ); + bRes = true; + } + else + { + pIDRA->SetRedlinePassword( Sequence< sal_Int8 >() ); + bRes = true; + } + + return bRes; +} + +bool SwDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash ) +{ + bool bRes = false; + + const SfxAllItemSet aSet( GetPool() ); + const SfxItemSet* pArgs = &aSet; + const SfxPoolItem* pItem = NULL; + + IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess(); + Sequence< sal_Int8 > aPasswdHash( pIDRA->GetRedlinePassword() ); + if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_REDLINE_PROTECT, false, &pItem ) + && ((SfxBoolItem*)pItem)->GetValue() == (aPasswdHash.getLength() != 0)) + return false; + rPasswordHash = aPasswdHash; + bRes = true; + + return bRes; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx new file mode 100644 index 000000000000..8cdac97949cb --- /dev/null +++ b/sw/source/uibase/app/docsh2.cxx @@ -0,0 +1,1584 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <com/sun/star/drawing/ModuleDispatcher.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/frame/DispatchHelper.hpp> + +#include <comphelper/processfactory.hxx> + +#include <hintids.hxx> +#include <tools/urlobj.hxx> +#include <unotools/tempfile.hxx> +#include <vcl/wrkwin.hxx> +#include <vcl/msgbox.hxx> +#include <svl/lckbitem.hxx> +#include <svl/eitem.hxx> +#include <svl/zforlist.hxx> +#include <svl/zformat.hxx> +#include <unotools/pathoptions.hxx> +#include <svtools/transfer.hxx> +#include <sfx2/dialogs.hrc> +#include <sfx2/dinfdlg.hxx> +#include <sfx2/request.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/new.hxx> +#include <sfx2/filedlghelper.hxx> +#include <sfx2/printer.hxx> +#include <sfx2/evntconf.hxx> +#include <svtools/sfxecode.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/docfilt.hxx> +#include <svx/svxids.hrc> +#include <svx/drawitem.hxx> +#include <editeng/svxacorr.hxx> +#include <editeng/langitem.hxx> +#include <svx/fmshell.hxx> +#include <sfx2/linkmgr.hxx> + +#include <svtools/htmlcfg.hxx> +#include <svx/ofaitem.hxx> +#include <SwSmartTagMgr.hxx> +#include <sfx2/app.hxx> +#include <basic/sbstar.hxx> +#include <basic/basmgr.hxx> +#include <sot/storage.hxx> +#include <comphelper/classids.hxx> +#include <fmtcol.hxx> +#include <swevent.hxx> +#include <view.hxx> +#include <docsh.hxx> +#include <docary.hxx> +#include <wrtsh.hxx> +#include <fldbas.hxx> +#include <viewopt.hxx> +#include <globdoc.hxx> +#include <fldwrap.hxx> +#include <redlndlg.hxx> +#include <docstyle.hxx> +#include <doc.hxx> +#include <IDocumentUndoRedo.hxx> +#include <pagedesc.hxx> +#include <shellio.hxx> +#include <pview.hxx> +#include <srcview.hxx> +#include <poolfmt.hxx> +#include <usrpref.hxx> +#include <wdocsh.hxx> +#include <unotxdoc.hxx> +#include <acmplwrd.hxx> +#include <swmodule.hxx> +#include <unobaseclass.hxx> +#include <swwait.hxx> +#include <swcli.hxx> + +#include <cmdid.h> +#include <globals.h> +#include <helpid.h> +#include <app.hrc> +#include <poolfmt.hrc> +#include <globals.hrc> +#include <com/sun/star/ui/dialogs/XFilePicker.hpp> +#include <com/sun/star/ui/dialogs/XFilterManager.hpp> +#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> +#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> +#include <com/sun/star/ui/dialogs/ListboxControlActions.hpp> +#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> +#include <com/sun/star/ui/dialogs/TemplateDescription.hpp> +#include <com/sun/star/script/vba/XVBAEventProcessor.hpp> +#include <com/sun/star/script/vba/VBAEventId.hpp> +#include <editeng/acorrcfg.hxx> +#include <SwStyleNameMapper.hxx> + +#include <sfx2/fcontnr.hxx> + +#include "dialog.hrc" +#include "swabstdlg.hxx" + +#include <ndtxt.hxx> + +#include <boost/scoped_ptr.hpp> + +using namespace ::com::sun::star::ui::dialogs; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star; +using namespace ::sfx2; + +// create DocInfo (virtual) +SfxDocumentInfoDialog* SwDocShell::CreateDocumentInfoDialog( + Window *pParent, const SfxItemSet &rSet) +{ + SfxDocumentInfoDialog* pDlg = new SfxDocumentInfoDialog(pParent, rSet); + //only with statistics, when this document is being shown, not + //from within the Doc-Manager + SwDocShell* pDocSh = (SwDocShell*) SfxObjectShell::Current(); + if( pDocSh == this ) + { + //Not for SourceView. + SfxViewShell *pVSh = SfxViewShell::Current(); + if ( pVSh && !pVSh->ISA(SwSrcView) ) + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!"); + pDlg->AddFontTabPage(); + pDlg->AddTabPage(TP_DOC_STAT, SW_RESSTR(STR_DOC_STAT),pFact->GetTabPageCreatorFunc( TP_DOC_STAT ),0); + } + } + return pDlg; +} + +// Disable "multiple layout" + +void SwDocShell::ToggleBrowserMode(bool bSet, SwView* _pView ) +{ + GetDoc()->set(IDocumentSettingAccess::BROWSE_MODE, bSet ); + UpdateFontList(); + SwView* pTempView = _pView ? _pView : (SwView*)GetView(); + if( pTempView ) + { + pTempView->GetViewFrame()->GetBindings().Invalidate(FN_SHADOWCURSOR); + if( !GetDoc()->getPrinter( false ) ) + pTempView->SetPrinter( GetDoc()->getPrinter( false ), SFX_PRINTER_PRINTER | SFX_PRINTER_JOBSETUP ); + GetDoc()->CheckDefaultPageFmt(); + SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this, false); + while (pTmpFrm) + { + if( pTmpFrm != pTempView->GetViewFrame() ) + { + pTmpFrm->DoClose(); + pTmpFrm = SfxViewFrame::GetFirst(this, false); + } + else + pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this, false); + } + const SwViewOption& rViewOptions = *pTempView->GetWrtShell().GetViewOptions(); + pTempView->GetWrtShell().CheckBrowseView( true ); + pTempView->CheckVisArea(); + if( bSet ) + { + const SvxZoomType eType = (SvxZoomType)rViewOptions.GetZoomType(); + if ( SVX_ZOOM_PERCENT != eType) + ((SwView*)GetView())->SetZoom( eType ); + } + pTempView->InvalidateBorder(); + pTempView->SetNewWindowAllowed(!bSet); + } +} +// End of disabled "multiple layout" + +// update text fields on document properties changes +void SwDocShell::DoFlushDocInfo() +{ + if ( !pDoc ) return; + + bool bUnlockView(true); + if ( pWrtShell ) { + bUnlockView = !pWrtShell->IsViewLocked(); + pWrtShell->LockView( true ); // lock visible section + pWrtShell->StartAllAction(); + } + + pDoc->DocInfoChgd(); + + if ( pWrtShell ) { + pWrtShell->EndAllAction(); + if ( bUnlockView ) { + pWrtShell->LockView( false ); + } + } +} + +static void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XVBAEventProcessor >& xVbaEvents, const SfxHint& rHint ) +{ + using namespace com::sun::star::script::vba::VBAEventId; + if ( rHint.ISA( SfxEventHint ) ) + { + uno::Sequence< uno::Any > aArgs; + sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId(); + switch( nEventId ) + { + case SFX_EVENT_CREATEDOC: + xVbaEvents->processVbaEvent( DOCUMENT_NEW, aArgs ); + break; + case SFX_EVENT_OPENDOC: + xVbaEvents->processVbaEvent( DOCUMENT_OPEN, aArgs ); + break; + } + } +} + +// Notification on DocInfo changes +void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) +{ + if( !pDoc ) + { + return ; + } + + uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor(); + if( xVbaEvents.is() ) + lcl_processCompatibleSfxHint( xVbaEvents, rHint ); + + sal_uInt16 nAction = 0; + if( rHint.ISA(SfxSimpleHint) ) + { + // switch for more actions + switch( ((SfxSimpleHint&) rHint).GetId() ) + { + case SFX_HINT_TITLECHANGED: + if( GetMedium() ) + nAction = 2; + break; + } + } + else if( rHint.ISA(SfxEventHint) && + ((SfxEventHint&) rHint).GetEventId() == SFX_EVENT_LOADFINISHED ) + { + // #i38126# - own action id + nAction = 3; + } + + if( nAction ) + { + bool bUnlockView = true; //initializing prevents warning + if( pWrtShell ) + { + bUnlockView = !pWrtShell->IsViewLocked(); + pWrtShell->LockView( true ); //lock visible section + pWrtShell->StartAllAction(); + } + switch( nAction ) + { + case 2: + pDoc->GetSysFldType( RES_FILENAMEFLD )->UpdateFlds(); + break; + // #i38126# - own action for event LOADFINISHED + // in order to avoid a modified document. + // #i41679# - Also for the instance of <SwDoc> + // it has to be assured, that it's not modified. + // Perform the same as for action id 1, but disable <SetModified>. + case 3: + { + const bool bResetModified = IsEnableSetModified(); + if ( bResetModified ) + EnableSetModified( false ); + // #i41679# + const bool bIsDocModified = pDoc->IsModified(); + + pDoc->DocInfoChgd( ); + + // #i41679# + if ( !bIsDocModified ) + pDoc->ResetModified(); + if ( bResetModified ) + EnableSetModified( true ); + } + break; + } + + if( pWrtShell ) + { + pWrtShell->EndAllAction(); + if( bUnlockView ) + pWrtShell->LockView( false ); + } + } +} + +// Notification Close Doc +bool SwDocShell::PrepareClose( bool bUI ) +{ + bool nRet = SfxObjectShell::PrepareClose( bUI ); + + if( nRet ) + EndListening( *this ); + + if( pDoc && IsInPrepareClose() ) + { + uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor(); + if( xVbaEvents.is() ) + { + using namespace com::sun::star::script::vba::VBAEventId; + uno::Sequence< uno::Any > aArgs; + xVbaEvents->processVbaEvent( DOCUMENT_CLOSE, aArgs ); + } + } + return nRet; +} + +void SwDocShell::Execute(SfxRequest& rReq) +{ + const SfxItemSet* pArgs = rReq.GetArgs(); + const SfxPoolItem* pItem; + sal_uInt16 nWhich = rReq.GetSlot(); + bool bDone = false; + switch ( nWhich ) + { + case SID_AUTO_CORRECT_DLG: + { + SvxSwAutoFmtFlags* pAFlags = &SvxAutoCorrCfg::Get().GetAutoCorrect()->GetSwFlags(); + SwAutoCompleteWord& rACW = SwDoc::GetAutoCompleteWords(); + + bool bOldLocked = rACW.IsLockWordLstLocked(), + bOldAutoCmpltCollectWords = pAFlags->bAutoCmpltCollectWords; + + rACW.SetLockWordLstLocked( true ); + + editeng::SortedAutoCompleteStrings aTmpLst( rACW.GetWordList() ); + pAFlags->m_pAutoCompleteList = &aTmpLst; + + SfxApplication* pApp = SFX_APP(); + SfxRequest aAppReq(SID_AUTO_CORRECT_DLG, SFX_CALLMODE_SYNCHRON, pApp->GetPool()); + SfxBoolItem aSwOptions( SID_AUTO_CORRECT_DLG, true ); + aAppReq.AppendItem(aSwOptions); + + pAFlags->pSmartTagMgr = &SwSmartTagMgr::Get(); + + SfxItemSet aSet( pApp->GetPool(), SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG, SID_OPEN_SMARTTAGOPTIONS, SID_OPEN_SMARTTAGOPTIONS, 0 ); + aSet.Put( aSwOptions ); + + const SfxPoolItem* pOpenSmartTagOptionsItem = 0; + if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_OPEN_SMARTTAGOPTIONS, false, &pOpenSmartTagOptionsItem ) ) + aSet.Put( *static_cast<const SfxBoolItem*>(pOpenSmartTagOptionsItem) ); + + SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); + SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog( RID_OFA_AUTOCORR_DLG, NULL, &aSet, NULL ); + pDlg->Execute(); + delete pDlg; + + rACW.SetLockWordLstLocked( bOldLocked ); + + SwEditShell::SetAutoFmtFlags( pAFlags ); + rACW.SetMinWordLen( pAFlags->nAutoCmpltWordLen ); + rACW.SetMaxCount( pAFlags->nAutoCmpltListLen ); + if (pAFlags->m_pAutoCompleteList) // any changes? + { + rACW.CheckChangedList( aTmpLst ); + // clear the temp WordList pointer + pAFlags->m_pAutoCompleteList = 0; + } + // remove all pointer we never delete the strings + aTmpLst.clear(); + + if( !bOldAutoCmpltCollectWords && bOldAutoCmpltCollectWords != + pAFlags->bAutoCmpltCollectWords ) + { + // call on all Docs the idle formatter to start + // the collection of Words + TypeId aType = TYPE(SwDocShell); + for( SwDocShell *pDocSh = (SwDocShell*)SfxObjectShell::GetFirst(&aType); + pDocSh; + pDocSh = (SwDocShell*)SfxObjectShell::GetNext( *pDocSh, &aType ) ) + { + SwDoc* pTmp = pDocSh->GetDoc(); + if ( pTmp->GetCurrentViewShell() ) + pTmp->InvalidateAutoCompleteFlag(); + } + } + } + break; + + case SID_PRINTPREVIEW: + { + bool bSet = false; + bool bFound = false, bOnly = true; + SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this); + SfxViewShell* pViewShell = SfxViewShell::Current(); + SwView* pCurrView = dynamic_cast< SwView *> ( pViewShell ); + bool bCurrent = IS_TYPE( SwPagePreview, pViewShell ); + + while( pTmpFrm ) // search Preview + { + if( IS_TYPE( SwView, pTmpFrm->GetViewShell()) ) + bOnly = false; + else if( IS_TYPE( SwPagePreview, pTmpFrm->GetViewShell())) + { + pTmpFrm->GetFrame().Appear(); + bFound = true; + } + if( bFound && !bOnly ) + break; + pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this); + } + + if( pArgs && SFX_ITEM_SET == + pArgs->GetItemState( SID_PRINTPREVIEW, false, &pItem )) + bSet = ((SfxBoolItem*)pItem)->GetValue(); + else + bSet = !bCurrent; + + sal_uInt16 nSlotId = 0; + if( bSet && !bFound ) // Nothing found, so create new Preview + nSlotId = SID_VIEWSHELL1; + else if( bFound && !bSet ) + nSlotId = bOnly ? SID_VIEWSHELL0 : SID_VIEWSHELL1; + + if( nSlotId ) + { + // PagePreview in the WebDocShell + // is found under Id VIEWSHELL2. + if( ISA(SwWebDocShell) && SID_VIEWSHELL1 == nSlotId ) + nSlotId = SID_VIEWSHELL2; + + if( pCurrView && pCurrView->GetDocShell() == this ) + pTmpFrm = pCurrView->GetViewFrame(); + else + pTmpFrm = SfxViewFrame::GetFirst( this ); + + if (pTmpFrm) + pTmpFrm->GetDispatcher()->Execute( nSlotId, 0, 0, SFX_CALLMODE_ASYNCHRON ); + } + + rReq.SetReturnValue(SfxBoolItem(SID_PRINTPREVIEW, bSet )); + } + break; + case SID_TEMPLATE_LOAD: + { + OUString aFileName; + static bool bText = true; + static bool bFrame = false; + static bool bPage = false; + static bool bNum = false; + static bool bMerge = false; + sal_uInt16 nRet = USHRT_MAX; + + sal_uInt16 nFlags = bFrame ? SFX_LOAD_FRAME_STYLES : 0; + if(bPage) + nFlags|= SFX_LOAD_PAGE_STYLES; + if(bNum) + nFlags|= SFX_LOAD_NUM_STYLES; + if(!nFlags || bText) + nFlags|= SFX_LOAD_TEXT_STYLES; + if(bMerge) + nFlags|= SFX_MERGE_STYLES; + + if ( pArgs ) + { + SFX_REQUEST_ARG( rReq, pTemplateItem, SfxStringItem, SID_TEMPLATE_NAME, false ); + if ( pTemplateItem ) + { + aFileName = pTemplateItem->GetValue(); + SFX_REQUEST_ARG( rReq, pFlagsItem, SfxInt32Item, SID_TEMPLATE_LOAD, false ); + if ( pFlagsItem ) + nFlags = (sal_uInt16) pFlagsItem->GetValue(); + } + } + + if ( aFileName.isEmpty() ) + { + SvtPathOptions aPathOpt; + SfxNewFileDialog* pNewFileDlg = + new SfxNewFileDialog(&GetView()->GetViewFrame()->GetWindow(), SFXWB_LOAD_TEMPLATE); + pNewFileDlg->SetTemplateFlags(nFlags); + + nRet = pNewFileDlg->Execute(); + if(RET_TEMPLATE_LOAD == nRet) + { + FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 ); + uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); + + xFP->setDisplayDirectory( aPathOpt.GetWorkPath() ); + + SfxObjectFactory &rFact = GetFactory(); + SfxFilterMatcher aMatcher( OUString::createFromAscii(rFact.GetShortName()) ); + SfxFilterMatcherIter aIter( aMatcher ); + uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY); + const SfxFilter* pFlt = aIter.First(); + while( pFlt ) + { + // --> OD #i117339# + if( pFlt && pFlt->IsAllowedAsTemplate() && + ( pFlt->GetUserData() == "CXML" || + pFlt->GetUserData() == "CXMLV" ) ) + { + const OUString sWild = pFlt->GetWildcard().getGlob(); + xFltMgr->appendFilter( pFlt->GetUIName(), sWild ); + } + pFlt = aIter.Next(); + } + bool bWeb = 0 != dynamic_cast< SwWebDocShell *>( this ); + const SfxFilter *pOwnFlt = + SwDocShell::Factory().GetFilterContainer()-> + GetFilter4FilterName(OUString("writer8")); + + // make sure the default file format is also available + if(bWeb) + { + const OUString sWild = pOwnFlt->GetWildcard().getGlob(); + xFltMgr->appendFilter( pOwnFlt->GetUIName(), sWild ); + } + + bool bError = false; + // catch exception if wrong filter is selected - should not happen anymore + try + { + xFltMgr->setCurrentFilter( pOwnFlt->GetUIName() ); + } + catch (const uno::Exception&) + { + bError = true; + } + + if( !bError && ERRCODE_NONE == aDlgHelper.Execute() ) + { + aFileName = xFP->getFiles().getConstArray()[0]; + } + } + else if( RET_OK == nRet) + { + aFileName = pNewFileDlg->GetTemplateFileName(); + } + + nFlags = pNewFileDlg->GetTemplateFlags(); + rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aFileName ) ); + rReq.AppendItem( SfxInt32Item( SID_TEMPLATE_LOAD, (long) nFlags ) ); + delete pNewFileDlg; + } + + if( !aFileName.isEmpty() ) + { + SwgReaderOption aOpt; + aOpt.SetTxtFmts( bText = (0 != (nFlags&SFX_LOAD_TEXT_STYLES) )); + aOpt.SetFrmFmts( bFrame = (0 != (nFlags&SFX_LOAD_FRAME_STYLES))); + aOpt.SetPageDescs( bPage = (0 != (nFlags&SFX_LOAD_PAGE_STYLES ))); + aOpt.SetNumRules( bNum = (0 != (nFlags&SFX_LOAD_NUM_STYLES ))); + //different meaning between SFX_MERGE_STYLES and aOpt.SetMerge! + bMerge = 0 != (nFlags&SFX_MERGE_STYLES); + aOpt.SetMerge( !bMerge ); + + SetError( LoadStylesFromFile( aFileName, aOpt, false ), OUString( OSL_LOG_PREFIX )); + if ( !GetError() ) + rReq.Done(); + } + } + break; + case SID_SOURCEVIEW: + { + SfxViewShell* pViewShell = GetView() + ? (SfxViewShell*)GetView() + : SfxViewShell::Current(); + SfxViewFrame* pViewFrm = pViewShell->GetViewFrame(); + SwSrcView* pSrcView = dynamic_cast< SwSrcView *>( pViewShell ); + if(!pSrcView) + { + // 3 possible state: + // 1 - file unsaved -> save as HTML + // 2 - file modified and HTML filter active -> save + // 3 - file saved in non-HTML -> QueryBox to save as HTML + const SfxFilter* pHtmlFlt = + SwIoSystem::GetFilterOfFormat( + OUString("HTML"), + SwWebDocShell::Factory().GetFilterContainer() ); + bool bLocalHasName = HasName(); + if(bLocalHasName) + { + //check for filter type + const SfxFilter* pFlt = GetMedium()->GetFilter(); + if(!pFlt || pFlt->GetUserData() != pHtmlFlt->GetUserData()) + { + MessageDialog aQuery(&pViewFrm->GetWindow(), + "SaveAsHTMLDialog", "modules/swriter/ui/saveashtmldialog.ui"); + + if(RET_YES == aQuery.Execute()) + bLocalHasName = false; + else + break; + } + } + if(!bLocalHasName) + { + FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 ); + aDlgHelper.AddFilter( pHtmlFlt->GetFilterName(), pHtmlFlt->GetDefaultExtension() ); + aDlgHelper.SetCurrentFilter( pHtmlFlt->GetFilterName() ); + if( ERRCODE_NONE != aDlgHelper.Execute()) + { + break; + } + OUString sPath = aDlgHelper.GetPath(); + SfxStringItem aName(SID_FILE_NAME, sPath); + SfxStringItem aFilter(SID_FILTER_NAME, pHtmlFlt->GetName()); + const SfxBoolItem* pBool = (const SfxBoolItem*) + pViewFrm->GetDispatcher()->Execute( + SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON, &aName, &aFilter, 0L ); + if(!pBool || !pBool->GetValue()) + break; + } + } + + OSL_ENSURE(dynamic_cast<SwWebDocShell*>(this), + "SourceView only in WebDocShell"); + + // the SourceView is not the 1 for SwWebDocShell + sal_uInt16 nSlot = SID_VIEWSHELL1; + bool bSetModified = false; + SfxPrinter* pSavePrinter = 0; + if( 0 != pSrcView) + { + SfxPrinter* pTemp = GetDoc()->getPrinter( false ); + if(pTemp) + pSavePrinter = new SfxPrinter(*pTemp); + bSetModified = IsModified() || pSrcView->IsModified(); + if(pSrcView->IsModified()||pSrcView->HasSourceSaved()) + { + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + pSrcView->SaveContent(aTempFile.GetURL()); + bDone = true; + SvxMacro aMac(aEmptyOUStr, aEmptyOUStr, STARBASIC); + SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_OPENDOC ), aMac, this); + SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEDOC ), aMac, this); + SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_ACTIVATEDOC ), aMac, this); + SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_DEACTIVATEDOC ), aMac, this); + ReloadFromHtml(aTempFile.GetURL(), pSrcView); + nSlot = 0; + } + else + { + nSlot = SID_VIEWSHELL0; + } + } + if(nSlot) + pViewFrm->GetDispatcher()->Execute(nSlot, SFX_CALLMODE_SYNCHRON); + if(bSetModified) + GetDoc()->SetModified(); + if(pSavePrinter) + { + GetDoc()->setPrinter( pSavePrinter, true, true); + //pSavePrinter must not be deleted again + } + pViewFrm->GetBindings().SetState(SfxBoolItem(SID_SOURCEVIEW, nSlot == SID_VIEWSHELL2)); + pViewFrm->GetBindings().Invalidate( SID_NEWWINDOW ); + pViewFrm->GetBindings().Invalidate( SID_BROWSER_MODE ); + pViewFrm->GetBindings().Invalidate( FN_PRINT_LAYOUT ); + } + break; + case SID_GET_COLORLIST: + { + SvxColorListItem* pColItem = (SvxColorListItem*)GetItem(SID_COLOR_TABLE); + XColorListRef pList = pColItem->GetColorList(); + rReq.SetReturnValue(OfaRefItem<XColorList>(SID_GET_COLORLIST, pList)); + } + break; + case FN_ABSTRACT_STARIMPRESS: + case FN_ABSTRACT_NEWDOC: + { + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!"); + + boost::scoped_ptr<AbstractSwInsertAbstractDlg> pDlg(pFact->CreateSwInsertAbstractDlg(0)); + OSL_ENSURE(pDlg, "Dialogdiet fail!"); + if(RET_OK == pDlg->Execute()) + { + sal_uInt8 nLevel = pDlg->GetLevel(); + sal_uInt8 nPara = pDlg->GetPara(); + SwDoc* pSmryDoc = new SwDoc(); + SfxObjectShellLock xDocSh( new SwDocShell( pSmryDoc, SFX_CREATE_MODE_STANDARD)); + xDocSh->DoInitNew( 0 ); + + bool bImpress = FN_ABSTRACT_STARIMPRESS == nWhich; + pDoc->Summary( pSmryDoc, nLevel, nPara, bImpress ); + if( bImpress ) + { + WriterRef xWrt; + // mba: looks as if relative URLs don't make sense here + ::GetRTFWriter( aEmptyOUStr, OUString(), xWrt ); + SvMemoryStream *pStrm = new SvMemoryStream(); + pStrm->SetBufferSize( 16348 ); + SwWriter aWrt( *pStrm, *pSmryDoc ); + ErrCode eErr = aWrt.Write( xWrt ); + if( !ERRCODE_TOERROR( eErr ) ) + { + uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); + uno::Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext ); + + OUString aCmd("SendOutlineToImpress"); + uno::Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) ); + pStrm->Seek( STREAM_SEEK_TO_END ); + pStrm->WriteChar( '\0' ); + pStrm->Seek( STREAM_SEEK_TO_BEGIN ); + + // Transfer ownership of stream to a lockbytes object + SvLockBytes aLockBytes( pStrm, true ); + SvLockBytesStat aStat; + if ( aLockBytes.Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE ) + { + sal_uInt32 nLen = aStat.nSize; + sal_uLong nRead = 0; + uno::Sequence< sal_Int8 > aSeq( nLen ); + aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead ); + + uno::Sequence< beans::PropertyValue > aArgs(1); + aArgs[0].Name = "RtfOutline"; + aArgs[0].Value <<= aSeq; + xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aArgs ); + } + } + else + ErrorHandler::HandleError(ErrCode( eErr )); + } + else + { + // Create new document + SfxViewFrame *pFrame = SfxViewFrame::LoadDocument( *xDocSh, 0 ); + SwView *pCurrView = (SwView*) pFrame->GetViewShell(); + + // Set document's title + OUString aTmp( SW_RES(STR_ABSTRACT_TITLE) ); + aTmp += GetTitle(); + xDocSh->SetTitle( aTmp ); + pCurrView->GetWrtShell().SetNewDoc(); + pFrame->Show(); + pSmryDoc->SetModified(); + } + + } + } + break; + case FN_OUTLINE_TO_CLIPBOARD: + case FN_OUTLINE_TO_IMPRESS: + { + bool bEnable = IsEnableSetModified(); + EnableSetModified( false ); + WriterRef xWrt; + // mba: looks as if relative URLs don't make sense here + ::GetRTFWriter( OUString('O'), OUString(), xWrt ); + SvMemoryStream *pStrm = new SvMemoryStream(); + pStrm->SetBufferSize( 16348 ); + SwWriter aWrt( *pStrm, *GetDoc() ); + ErrCode eErr = aWrt.Write( xWrt ); + EnableSetModified( bEnable ); + if( !ERRCODE_TOERROR( eErr ) ) + { + pStrm->Seek( STREAM_SEEK_TO_END ); + pStrm->WriteChar( '\0' ); + pStrm->Seek( STREAM_SEEK_TO_BEGIN ); + if ( nWhich == FN_OUTLINE_TO_IMPRESS ) + { + uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); + uno::Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext ); + + OUString aCmd("SendOutlineToImpress"); + uno::Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) ); + pStrm->Seek( STREAM_SEEK_TO_END ); + pStrm->WriteChar( '\0' ); + pStrm->Seek( STREAM_SEEK_TO_BEGIN ); + + // Transfer ownership of stream to a lockbytes object + SvLockBytes aLockBytes( pStrm, true ); + SvLockBytesStat aStat; + if ( aLockBytes.Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE ) + { + sal_uInt32 nLen = aStat.nSize; + sal_uLong nRead = 0; + uno::Sequence< sal_Int8 > aSeq( nLen ); + aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead ); + + uno::Sequence< beans::PropertyValue > aArgs(1); + aArgs[0].Name = "RtfOutline"; + aArgs[0].Value <<= aSeq; + xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aArgs ); + } + } + else + { + TransferDataContainer* pClipCntnr = + new TransferDataContainer; + ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > + xRef( pClipCntnr ); + + pClipCntnr->CopyAnyData( FORMAT_RTF, (sal_Char*) + pStrm->GetData(), pStrm->GetEndOfData() ); + pClipCntnr->CopyToClipboard( + GetView()? (Window*)&GetView()->GetEditWin() : 0 ); + delete pStrm; + } + } + else + ErrorHandler::HandleError(ErrCode( eErr )); + } + break; + case SID_SPELLCHECKER_CHANGED: + //! false, true, true is on the save side but a probably overdone + SW_MOD()->CheckSpellChanges(false, true, true, false ); + break; + + case SID_MAIL_PREPAREEXPORT: + { + //pWrtShell is not set in page preview + if(pWrtShell) + pWrtShell->StartAllAction(); + pDoc->UpdateFlds( NULL, false ); + pDoc->EmbedAllLinks(); + pDoc->RemoveInvisibleContent(); + if(pWrtShell) + pWrtShell->EndAllAction(); + } + break; + + case SID_MAIL_EXPORT_FINISHED: + { + if(pWrtShell) + pWrtShell->StartAllAction(); + //try to undo the removal of invisible content + pDoc->RestoreInvisibleContent(); + if(pWrtShell) + pWrtShell->EndAllAction(); + } + break; + case FN_NEW_HTML_DOC: + case FN_NEW_GLOBAL_DOC: + { + bDone = false; + bool bCreateHtml = FN_NEW_HTML_DOC == nWhich; + + bool bCreateByOutlineLevel = false; + sal_Int32 nTemplateOutlineLevel = 0; + + OUString aFileName, aTemplateName; + if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nWhich, false, &pItem ) ) + { + aFileName = ((const SfxStringItem*)pItem)->GetValue(); + SFX_ITEMSET_ARG( pArgs, pTemplItem, SfxStringItem, SID_TEMPLATE_NAME, false ); + if ( pTemplItem ) + aTemplateName = pTemplItem->GetValue(); + } + bool bError = false; + if ( aFileName.isEmpty() ) + { + FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE, 0 ); + + const sal_Int16 nControlIds[] = { + CommonFilePickerElementIds::PUSHBUTTON_OK, + CommonFilePickerElementIds::PUSHBUTTON_CANCEL, + CommonFilePickerElementIds::LISTBOX_FILTER, + CommonFilePickerElementIds::CONTROL_FILEVIEW, + CommonFilePickerElementIds::EDIT_FILEURL, + ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, + ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, + 0 + }; + + const char* aHTMLHelpIds[] = + { + HID_SEND_HTML_CTRL_PUSHBUTTON_OK, + HID_SEND_HTML_CTRL_PUSHBUTTON_CANCEL, + HID_SEND_HTML_CTRL_LISTBOX_FILTER, + HID_SEND_HTML_CTRL_CONTROL_FILEVIEW, + HID_SEND_HTML_CTRL_EDIT_FILEURL, + HID_SEND_HTML_CTRL_CHECKBOX_AUTOEXTENSION, + HID_SEND_HTML_CTRL_LISTBOX_TEMPLATE, + "" + }; + + const char* aMasterHelpIds[] = + { + HID_SEND_MASTER_CTRL_PUSHBUTTON_OK, + HID_SEND_MASTER_CTRL_PUSHBUTTON_CANCEL, + HID_SEND_MASTER_CTRL_LISTBOX_FILTER, + HID_SEND_MASTER_CTRL_CONTROL_FILEVIEW, + HID_SEND_MASTER_CTRL_EDIT_FILEURL, + HID_SEND_MASTER_CTRL_CHECKBOX_AUTOEXTENSION, + HID_SEND_MASTER_CTRL_LISTBOX_TEMPLATE, + "" + }; + + const char** pHelpIds = bCreateHtml ? aHTMLHelpIds : aMasterHelpIds; + aDlgHelper.SetControlHelpIds( nControlIds, pHelpIds ); + uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); + + const SfxFilter* pFlt; + sal_uInt16 nStrId; + + if( bCreateHtml ) + { + // for HTML there is only one filter!! + pFlt = SwIoSystem::GetFilterOfFormat( + OUString("HTML"), + SwWebDocShell::Factory().GetFilterContainer() ); + nStrId = STR_LOAD_HTML_DOC; + } + else + { + // for Global-documents we now only offer the current one. + pFlt = SwGlobalDocShell::Factory().GetFilterContainer()-> + GetFilter4Extension( OUString("odm") ); + nStrId = STR_LOAD_GLOBAL_DOC; + } + + if( pFlt ) + { + uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY); + const OUString sWild = pFlt->GetWildcard().getGlob(); + xFltMgr->appendFilter( pFlt->GetUIName(), sWild ); + try + { + xFltMgr->setCurrentFilter( pFlt->GetUIName() ) ; + } + catch (const uno::Exception&) + { + bError = true; + } + } + if(!bError) + { + uno::Reference<XFilePickerControlAccess> xCtrlAcc(xFP, UNO_QUERY); + + bool bOutline[MAXLEVEL] = {false}; + const SwOutlineNodes& rOutlNds = pDoc->GetNodes().GetOutLineNds(); + if( !rOutlNds.empty() ) + { + int nLevel; + for(sal_uInt16 n = 0; n < rOutlNds.size(); ++n ) + if( ( nLevel = rOutlNds[n]->GetTxtNode()->GetAttrOutlineLevel()) > 0 && + ! bOutline[nLevel-1] ) + { + bOutline[nLevel-1] = true; + } + } + + const sal_uInt16 nStyleCount = pDoc->GetTxtFmtColls()->size(); + Sequence<OUString> aListBoxEntries( MAXLEVEL + nStyleCount); + OUString* pEntries = aListBoxEntries.getArray(); + sal_Int32 nIdx = 0 ; + + OUString sOutline( SW_RESSTR(STR_FDLG_OUTLINE_LEVEL) ); + for( sal_uInt16 i = 0; i < MAXLEVEL; ++i ) + { + if( bOutline[i] ) + pEntries[nIdx++] = sOutline + OUString::number( i+1 ); + } + + OUString sStyle( SW_RESSTR(STR_FDLG_STYLE) ); + for(sal_uInt16 i = 0; i < nStyleCount; ++i) + { + SwTxtFmtColl &rTxtColl = *(*pDoc->GetTxtFmtColls())[ i ]; + if( !rTxtColl.IsDefault() && rTxtColl.IsAtDocNodeSet() ) + { + pEntries[nIdx++] = sStyle + rTxtColl.GetName(); + } + } + + aListBoxEntries.realloc(nIdx); + sal_Int16 nSelect = 0; + + try + { + Any aTemplates(&aListBoxEntries, ::getCppuType(&aListBoxEntries)); + + xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, + ListboxControlActions::ADD_ITEMS , aTemplates ); + Any aSelectPos(&nSelect, ::getCppuType(&nSelect)); + xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, + ListboxControlActions::SET_SELECT_ITEM, aSelectPos ); + xCtrlAcc->setLabel( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, + OUString(SW_RES( STR_FDLG_TEMPLATE_NAME ))); + } + catch (const Exception&) + { + OSL_FAIL("control acces failed"); + } + + xFP->setTitle( SW_RESSTR( nStrId )); + SvtPathOptions aPathOpt; + xFP->setDisplayDirectory( aPathOpt.GetWorkPath() ); + if( ERRCODE_NONE == aDlgHelper.Execute()) + { + aFileName = xFP->getFiles().getConstArray()[0]; + Any aTemplateValue = xCtrlAcc->getValue( + ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, + ListboxControlActions::GET_SELECTED_ITEM ); + OUString sTmpl; + aTemplateValue >>= sTmpl; + + sal_Int32 nColonPos = sTmpl.indexOf( ':' ); + OUString sPrefix = sTmpl.copy( 0L, nColonPos ); + if ( sPrefix == "Style" ) + { + aTemplateName = sTmpl.copy( 7L ); //get string behind "Style: " + } + else if ( sPrefix == "Outline" ) + { + nTemplateOutlineLevel = ( sTmpl.copy( 15L )).toInt32(); //get string behind "Outline: Leve "; + bCreateByOutlineLevel = true; + } + + if ( !aFileName.isEmpty() ) + { + rReq.AppendItem( SfxStringItem( nWhich, aFileName ) ); + if( !aTemplateName.isEmpty() ) + rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aTemplateName ) ); + } + } + } + } + + if( !aFileName.isEmpty() ) + { + if( PrepareClose( false ) ) + { + SwWait aWait( *this, true ); + + if ( bCreateByOutlineLevel ) + { + bDone = bCreateHtml + ? pDoc->GenerateHTMLDoc( aFileName, nTemplateOutlineLevel ) + : pDoc->GenerateGlobalDoc( aFileName, nTemplateOutlineLevel ); + } + else + { + const SwTxtFmtColl* pSplitColl = 0; + if ( !aTemplateName.isEmpty() ) + pSplitColl = pDoc->FindTxtFmtCollByName(aTemplateName); + bDone = bCreateHtml + ? pDoc->GenerateHTMLDoc( aFileName, pSplitColl ) + : pDoc->GenerateGlobalDoc( aFileName, pSplitColl ); + } + if( bDone ) + { + SfxStringItem aName( SID_FILE_NAME, aFileName ); + SfxStringItem aReferer( SID_REFERER, aEmptyOUStr ); + SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + while(pViewShell) + { + //search for the view that created the call + if(pViewShell->GetObjectShell() == this && pViewShell->GetDispatcher()) + { + SfxFrameItem* pFrameItem = new SfxFrameItem( SID_DOCFRAME, + pViewShell->GetViewFrame() ); + SfxDispatcher* pDispatch = pViewShell->GetDispatcher(); + pDispatch->Execute( + SID_OPENDOC, + SFX_CALLMODE_ASYNCHRON, + &aName, + &aReferer, + pFrameItem, 0L ); + + delete pFrameItem; + break; + } + pViewShell = SfxViewShell::GetNext(*pViewShell); + } + } + } + if( !bDone && !rReq.IsAPI() ) + { + InfoBox( 0, SW_RESSTR( STR_CANTCREATE )).Execute(); + } + } + } + rReq.SetReturnValue(SfxBoolItem( nWhich, bDone )); + if (bDone) + rReq.Done(); + else + rReq.Ignore(); + break; + + case SID_ATTR_YEAR2000: + if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nWhich , false, &pItem )) + { + OSL_ENSURE(pItem->ISA(SfxUInt16Item), "wrong Item"); + sal_uInt16 nYear2K = ((SfxUInt16Item*)pItem)->GetValue(); + // iterate over Views and put the State to FormShells + + SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( this ); + SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : 0; + SwView* pCurrView = dynamic_cast< SwView* >( pViewShell ); + while(pCurrView) + { + FmFormShell* pFormShell = pCurrView->GetFormShell(); + if(pFormShell) + pFormShell->SetY2KState(nYear2K); + pVFrame = SfxViewFrame::GetNext( *pVFrame, this ); + pViewShell = pVFrame ? pVFrame->GetViewShell() : 0; + pCurrView = dynamic_cast<SwView*>( pViewShell ); + } + pDoc->GetNumberFormatter(true)->SetYear2000(nYear2K); + } + break; + case FN_OPEN_FILE: + { + SfxViewShell* pViewShell = GetView(); + if (!pViewShell) + pViewShell = SfxViewShell::Current(); + + if (!pViewShell) + // Ok. I did my best. + break; + + SfxStringItem aApp(SID_DOC_SERVICE, OUString("com.sun.star.text.TextDocument")); + SfxStringItem aTarget(SID_TARGETNAME, OUString("_blank")); + pViewShell->GetDispatcher()->Execute( + SID_OPENDOC, SFX_CALLMODE_API|SFX_CALLMODE_SYNCHRON, &aApp, &aTarget, 0L); + } + break; + + default: OSL_FAIL("wrong Dispatcher"); + } +} + + // #FIXME - align with NEW event stuff ( if possible ) +#if 0 +void lcl_processCompatibleSfxHint( const uno::Reference< document::XVbaEventsHelper >& xVbaEventsHelper, const SfxHint& rHint ) +{ + if ( rHint.ISA( SfxEventHint ) ) + { + uno::Sequence< uno::Any > aArgs; + sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId(); + switch( nEventId ) + { + case SFX_EVENT_CREATEDOC: + { + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_DOCUMENT_NEW, aArgs ); + break; + } + case SFX_EVENT_OPENDOC: + { + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_DOCUMENT_OPEN, aArgs ); + break; + } + default: + { + //do nothing + } + } + } +} +#endif + +bool SwDocShell::DdeGetData( const OUString& rItem, const OUString& rMimeType, + uno::Any & rValue ) +{ + return pDoc->GetData( rItem, rMimeType, rValue ); +} + +bool SwDocShell::DdeSetData( const OUString& rItem, const OUString& rMimeType, + const uno::Any & rValue ) +{ + return pDoc->SetData( rItem, rMimeType, rValue ); +} + +::sfx2::SvLinkSource* SwDocShell::DdeCreateLinkSource( const OUString& rItem ) +{ + return pDoc->CreateLinkSource( rItem ); +} + +void SwDocShell::ReconnectDdeLink(SfxObjectShell& rServer) +{ + if ( pDoc ) { + ::sfx2::LinkManager& rLinkManager = pDoc->GetLinkManager(); + rLinkManager.ReconnectDdeLink(rServer); + } +} + +void SwDocShell::FillClass( SvGlobalName * pClassName, + sal_uInt32 * pClipFormat, + OUString * /*pAppName*/, + OUString * pLongUserName, + OUString * pUserName, + sal_Int32 nVersion, + bool bTemplate /* = false */) const +{ + if (nVersion == SOFFICE_FILEFORMAT_60) + { + *pClassName = SvGlobalName( SO3_SW_CLASSID_60 ); + *pClipFormat = SOT_FORMATSTR_ID_STARWRITER_60; + *pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE); + } + else if (nVersion == SOFFICE_FILEFORMAT_8) + { + *pClassName = SvGlobalName( SO3_SW_CLASSID_60 ); + *pClipFormat = bTemplate ? SOT_FORMATSTR_ID_STARWRITER_8_TEMPLATE : SOT_FORMATSTR_ID_STARWRITER_8; + *pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE); + } +// #FIXME check with new Event handling +#if 0 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper = pDoc->GetVbaEventsHelper(); + if( xVbaEventsHelper.is() ) + lcl_processCompatibleSfxHint( xVbaEventsHelper, rHint ); +#endif + + *pUserName = SW_RESSTR(STR_HUMAN_SWDOC_NAME); +} + +void SwDocShell::SetModified( bool bSet ) +{ + SfxObjectShell::SetModified( bSet ); + if( IsEnableSetModified()) + { + if (!pDoc->IsInCallModified() ) + { + EnableSetModified( false ); + if( bSet ) + { + bool bOld = pDoc->IsModified(); + pDoc->SetModified(); + if( !bOld ) + { + pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified(); + } + } + else + pDoc->ResetModified(); + + EnableSetModified( true ); + } + + UpdateChildWindows(); + Broadcast(SfxSimpleHint(SFX_HINT_DOCCHANGED)); + } +} + +void SwDocShell::UpdateChildWindows() +{ + // if necessary newly initialize Flddlg (i.e. for TYP_SETVAR) + if(!GetView()) + return; + SfxViewFrame* pVFrame = GetView()->GetViewFrame(); + SwFldDlgWrapper *pWrp = (SwFldDlgWrapper*)pVFrame-> + GetChildWindow( SwFldDlgWrapper::GetChildWindowId() ); + if( pWrp ) + pWrp->ReInitDlg( this ); + + // if necessary newly initialize RedlineDlg + SwRedlineAcceptChild *pRed = (SwRedlineAcceptChild*)pVFrame-> + GetChildWindow( SwRedlineAcceptChild::GetChildWindowId() ); + if( pRed ) + pRed->ReInitDlg( this ); +} + +// #i48748# +class SwReloadFromHtmlReader : public SwReader +{ + public: + SwReloadFromHtmlReader( SfxMedium& _rTmpMedium, + const OUString& _rFilename, + SwDoc* _pDoc ) + : SwReader( _rTmpMedium, _rFilename, _pDoc ) + { + SetBaseURL( _rFilename ); + } +}; + +void SwDocShell::ReloadFromHtml( const OUString& rStreamName, SwSrcView* pSrcView ) +{ + bool bModified = IsModified(); + + // The HTTP-Header fields have to be removed, otherwise + // there are some from Meta-Tags dublicated or triplicated afterwards. + ClearHeaderAttributesForSourceViewHack(); + +#ifndef DISABLE_SCRIPTING + // The Document-Basic also bites the dust ... + // A EnterBasicCall is not needed here, because nothing is called and + // there can't be any Dok-Basic, that has not yet been loaded inside + // of an HTML document. + SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get(); + //#59620# HasBasic() shows, that there already is a BasicManager at the DocShell. + // That was always generated in HTML-Import, when there are + // Macros in the source code. + if( rHtmlOptions.IsStarBasic() && HasBasic()) + { + BasicManager *pBasicMan = GetBasicManager(); + if( pBasicMan && (pBasicMan != SFX_APP()->GetBasicManager()) ) + { + sal_uInt16 nLibCount = pBasicMan->GetLibCount(); + while( nLibCount ) + { + StarBASIC *pBasic = pBasicMan->GetLib( --nLibCount ); + if( pBasic ) + { + // Notify the IDE + SfxUsrAnyItem aShellItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( GetModel() ) ); + OUString aLibName( pBasic->GetName() ); + SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName ); + pSrcView->GetViewFrame()->GetDispatcher()->Execute( + SID_BASICIDE_LIBREMOVED, + SFX_CALLMODE_SYNCHRON, + &aShellItem, &aLibNameItem, 0L ); + + // Only the modules are deleted from the standard-lib + if( nLibCount ) + pBasicMan->RemoveLib( nLibCount, true ); + else + pBasic->Clear(); + } + } + + OSL_ENSURE( pBasicMan->GetLibCount() <= 1, + "Deleting Basics didn't work" ); + } + } +#endif + bool bWasBrowseMode = pDoc->get(IDocumentSettingAccess::BROWSE_MODE); + RemoveLink(); + + // now also the UNO-Model has to be informed about the new Doc #51535# + uno::Reference<text::XTextDocument> xDoc(GetBaseModel(), uno::UNO_QUERY); + text::XTextDocument* pxDoc = xDoc.get(); + ((SwXTextDocument*)pxDoc)->InitNewDoc(); + + AddLink(); + //#116402# update font list when new document is created + UpdateFontList(); + pDoc->set(IDocumentSettingAccess::BROWSE_MODE, bWasBrowseMode); + pSrcView->SetPool(&GetPool()); + + const OUString& rMedname = GetMedium()->GetName(); + + // The HTML template still has to be set + SetHTMLTemplate( *GetDoc() ); //Styles from HTML.vor + + SfxViewShell* pViewShell = GetView() ? (SfxViewShell*)GetView() + : SfxViewShell::Current(); + SfxViewFrame* pViewFrm = pViewShell->GetViewFrame(); + pViewFrm->GetDispatcher()->Execute( SID_VIEWSHELL0, SFX_CALLMODE_SYNCHRON ); + + SubInitNew(); + + SfxMedium aMed( rStreamName, STREAM_READ ); + // #i48748# - use class <SwReloadFromHtmlReader>, because + // the base URL has to be set to the filename of the document <rMedname> + // and not to the base URL of the temporary file <aMed> in order to get + // the URLs of the linked graphics correctly resolved. + SwReloadFromHtmlReader aReader( aMed, rMedname, pDoc ); + + aReader.Read( *ReadHTML ); + + const SwView* pCurrView = GetView(); + //in print layout the first page(s) may have been formatted as a mix of browse + //and print layout + if(!bWasBrowseMode && pCurrView) + { + SwWrtShell& rWrtSh = pCurrView->GetWrtShell(); + if( rWrtSh.GetLayout()) + rWrtSh.CheckBrowseView( true ); + } + + // Take HTTP-Header-Attibutes over into the DokInfo again. + // The Base-URL doesn't matter here because TLX uses the one from the document + // for absolutization. + SetHeaderAttributesForSourceViewHack(); + + if(bModified && !IsReadOnly()) + SetModified(); + else + pDoc->ResetModified(); +} + +sal_uLong SwDocShell::LoadStylesFromFile( const OUString& rURL, + SwgReaderOption& rOpt, bool bUnoCall ) +{ + sal_uLong nErr = 0; + + // Set filter: + OUString sFactory(OUString::createFromAscii(SwDocShell::Factory().GetShortName())); + SfxFilterMatcher aMatcher( sFactory ); + + // search for filter in WebDocShell, too + SfxMedium aMed( rURL, STREAM_STD_READ ); + const SfxFilter* pFlt = 0; + aMatcher.DetectFilter( aMed, &pFlt, false, false ); + if(!pFlt) + { + OUString sWebFactory(OUString::createFromAscii(SwWebDocShell::Factory().GetShortName())); + SfxFilterMatcher aWebMatcher( sWebFactory ); + aWebMatcher.DetectFilter( aMed, &pFlt, false, false ); + } + // --> OD #i117339# - trigger import only for own formats + bool bImport( false ); + { + if ( aMed.IsStorage() ) + { + // As <SfxMedium.GetFilter().IsOwnFormat() resp. IsOwnTemplateFormat() + // does not work correct (e.g., MS Word 2007 XML Template), + // use workaround provided by MAV. + uno::Reference< embed::XStorage > xStorage = aMed.GetStorage(); + if ( xStorage.is() ) + { + // use <try-catch> on retrieving <MediaType> in order to check, + // if the storage is one of our own ones. + try + { + uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY_THROW ); + const OUString aMediaTypePropName( "MediaType" ); + xProps->getPropertyValue( aMediaTypePropName ); + bImport = true; + } + catch (const uno::Exception&) + { + bImport = false; + } + } + } + } + if ( bImport ) + { + SwRead pRead = ReadXML; + boost::scoped_ptr<SwReader> pReader; + boost::scoped_ptr<SwPaM> pPam; + // the SW3IO - Reader need the pam/wrtshell, because only then he + // insert the styles! + if( bUnoCall ) + { + SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfContent(), -1 ); + pPam.reset(new SwPaM( aIdx )); + pReader.reset(new SwReader( aMed, rURL, *pPam )); + } + else + { + pReader.reset(new SwReader( aMed, rURL, *pWrtShell->GetCrsr() )); + } + + pRead->GetReaderOpt().SetTxtFmts( rOpt.IsTxtFmts() ); + pRead->GetReaderOpt().SetFrmFmts( rOpt.IsFrmFmts() ); + pRead->GetReaderOpt().SetPageDescs( rOpt.IsPageDescs() ); + pRead->GetReaderOpt().SetNumRules( rOpt.IsNumRules() ); + pRead->GetReaderOpt().SetMerge( rOpt.IsMerge() ); + + if( bUnoCall ) + { + UnoActionContext aAction( pDoc ); + nErr = pReader->Read( *pRead ); + } + else + { + pWrtShell->StartAllAction(); + nErr = pReader->Read( *pRead ); + pWrtShell->EndAllAction(); + } + } + + return nErr; +} + +// Get a client for an embedded object if possible. +SfxInPlaceClient* SwDocShell::GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef ) +{ + SfxInPlaceClient* pResult = NULL; + + SwWrtShell* pShell = GetWrtShell(); + if ( pShell ) + { + pResult = pShell->GetView().FindIPClient( xObjRef.GetObject(), (Window*)&pShell->GetView().GetEditWin() ); + if ( !pResult ) + pResult = new SwOleClient( &pShell->GetView(), &pShell->GetView().GetEditWin(), xObjRef ); + } + + return pResult; +} + +int SwFindDocShell( SfxObjectShellRef& xDocSh, + SfxObjectShellLock& xLockRef, + const OUString& rFileName, + const OUString& rPasswd, + const OUString& rFilter, + sal_Int16 nVersion, + SwDocShell* pDestSh ) +{ + if ( rFileName.isEmpty() ) + return 0; + + // 1. Does the file already exist in the list of all Documents? + INetURLObject aTmpObj( rFileName ); + aTmpObj.SetMark( OUString() ); + + // Iterate over the DocShell and get the ones with the name + TypeId aType( TYPE(SwDocShell) ); + + SfxObjectShell* pShell = pDestSh; + bool bFirst = 0 != pShell; + + if( !bFirst ) + // No DocShell passed, starting with the first from the DocShell list + pShell = SfxObjectShell::GetFirst( &aType ); + + while( pShell ) + { + // We want this one + SfxMedium* pMed = pShell->GetMedium(); + if( pMed && pMed->GetURLObject() == aTmpObj ) + { + const SfxPoolItem* pItem; + if( ( SFX_ITEM_SET == pMed->GetItemSet()->GetItemState( + SID_VERSION, false, &pItem ) ) + ? (nVersion == ((SfxInt16Item*)pItem)->GetValue()) + : !nVersion ) + { + // Found, thus return + xDocSh = pShell; + return 1; + } + } + + if( bFirst ) + { + bFirst = false; + pShell = SfxObjectShell::GetFirst( &aType ); + } + else + pShell = SfxObjectShell::GetNext( *pShell, &aType ); + } + + // 2. Open the file ourselves + SfxMedium* pMed = new SfxMedium( aTmpObj.GetMainURL( + INetURLObject::NO_DECODE ), STREAM_READ ); + if( INET_PROT_FILE == aTmpObj.GetProtocol() ) + pMed->Download(); // Touch the medium (download it) + + const SfxFilter* pSfxFlt = 0; + if( !pMed->GetError() ) + { + SfxFilterMatcher aMatcher( OUString::createFromAscii(SwDocShell::Factory().GetShortName()) ); + + // No Filter, so search for it. Else test if the one passed is a valid one + if( !rFilter.isEmpty() ) + { + pSfxFlt = aMatcher.GetFilter4FilterName( rFilter ); + } + + if( nVersion ) + pMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion )); + + if( !rPasswd.isEmpty() ) + pMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd )); + + if( !pSfxFlt ) + aMatcher.DetectFilter( *pMed, &pSfxFlt, false, false ); + + if( pSfxFlt ) + { + // We cannot do anything without a Filter + pMed->SetFilter( pSfxFlt ); + + // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure + xLockRef = new SwDocShell( SFX_CREATE_MODE_INTERNAL ); + xDocSh = (SfxObjectShell*)xLockRef; + if( xDocSh->DoLoad( pMed ) ) + return 2; + } + } + + if( !xDocSh.Is() ) // Medium still needs to be deleted + delete pMed; + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/docshdrw.cxx b/sw/source/uibase/app/docshdrw.cxx new file mode 100644 index 000000000000..90070c96518b --- /dev/null +++ b/sw/source/uibase/app/docshdrw.cxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <hintids.hxx> +#include <svx/svxids.hrc> +#include <svl/stritem.hxx> +#include <svx/drawitem.hxx> +#include <svx/svdmodel.hxx> +#include <svx/svdoutl.hxx> +#include <svx/xtable.hxx> + +#include <docsh.hxx> +#include <doc.hxx> + +using namespace ::com::sun::star; + +// Load Document +void SwDocShell::InitDraw() +{ + SdrModel *pDrDoc = pDoc->GetDrawModel(); + if( pDrDoc ) + { + // create Lists and Tables DocShell's ItemSet + PutItem( SvxGradientListItem( pDrDoc->GetGradientList(), SID_GRADIENT_LIST ) ); + PutItem( SvxHatchListItem( pDrDoc->GetHatchList(), SID_HATCH_LIST ) ); + PutItem( SvxBitmapListItem( pDrDoc->GetBitmapList(), SID_BITMAP_LIST ) ); + PutItem( SvxDashListItem( pDrDoc->GetDashList(), SID_DASH_LIST ) ); + PutItem( SvxLineEndListItem( pDrDoc->GetLineEndList(), SID_LINEEND_LIST ) ); + PutItem( SvxColorListItem( pDrDoc->GetColorList(), SID_COLOR_TABLE )); + + Outliner& rOutliner = pDrDoc->GetDrawOutliner(); + uno::Reference<linguistic2::XHyphenator> xHyphenator( ::GetHyphenator() ); + rOutliner.SetHyphenator( xHyphenator ); + } + else + PutItem( SvxColorListItem( XColorList::GetStdColorList(), SID_COLOR_TABLE )); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/docshini.cxx b/sw/source/uibase/app/docshini.cxx new file mode 100644 index 000000000000..39c10b8ceed2 --- /dev/null +++ b/sw/source/uibase/app/docshini.cxx @@ -0,0 +1,683 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <hintids.hxx> + +#include <svx/dialogs.hrc> +#include <i18nlangtag/mslangid.hxx> +#include <sot/storinfo.hxx> +#include <sot/storage.hxx> +#include <svl/zforlist.hxx> +#include <svtools/ctrltool.hxx> +#include <unotools/lingucfg.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/sfxmodelfactory.hxx> +#include <sfx2/printer.hxx> +#include <sfx2/bindings.hxx> +#include <svl/asiancfg.hxx> +#include <editeng/unolingu.hxx> +#include <sfx2/request.hxx> +#include <svl/intitem.hxx> +#include <editeng/adjustitem.hxx> +#include <editeng/autokernitem.hxx> +#include <linguistic/lngprops.hxx> +#include <com/sun/star/document/UpdateDocMode.hpp> +#include <com/sun/star/i18n/ScriptType.hpp> +#include <sfx2/docfilt.hxx> +#include <svx/xtable.hxx> +#include <svx/drawitem.hxx> +#include <editeng/fhgtitem.hxx> +#include <editeng/fontitem.hxx> +#include <editeng/flstitem.hxx> +#include <editeng/tstpitem.hxx> +#include <editeng/langitem.hxx> +#include <editeng/colritem.hxx> +#include <editeng/hyphenzoneitem.hxx> +#include <editeng/svxacorr.hxx> +#include <vcl/svapp.hxx> +#include <vcl/settings.hxx> +#include <view.hxx> +#include <prtopt.hxx> +#include <fmtcol.hxx> +#include <docsh.hxx> +#include <wdocsh.hxx> +#include <swmodule.hxx> +#include <doc.hxx> +#include <docfac.hxx> +#include <docstyle.hxx> +#include <shellio.hxx> +#include <tox.hxx> +#include <swdtflvr.hxx> +#include <dbmgr.hxx> +#include <usrpref.hxx> +#include <fontcfg.hxx> +#include <poolfmt.hxx> +#include <modcfg.hxx> +#include <globdoc.hxx> +#include <ndole.hxx> +#include <mdiexp.hxx> +#include <unotxdoc.hxx> +#include <linkenum.hxx> +#include <swwait.hxx> +#include <wrtsh.hxx> +#include <swerror.h> +#include <globals.hrc> +#include <unochart.hxx> + +// text grid +#include <tgrditem.hxx> + +using namespace ::com::sun::star::i18n; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star; + +// Load Document +bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor ) +{ + bool bRet = SfxObjectShell::InitNew( xStor ); + OSL_ENSURE( GetMapUnit() == MAP_TWIP, "map unit is not twip!" ); + bool bHTMLTemplSet = false; + if( bRet ) + { + AddLink(); // create pDoc / pIo if applicable + + bool bWeb = ISA( SwWebDocShell ); + if ( bWeb ) + bHTMLTemplSet = SetHTMLTemplate( *GetDoc() );// Styles from HTML.vor + else if( ISA( SwGlobalDocShell ) ) + GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true); // Globaldokument + + if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) + SwTransferable::InitOle( this, *pDoc ); + + // set forbidden characters if necessary + SvxAsianConfig aAsian; + Sequence<lang::Locale> aLocales = aAsian.GetStartEndCharLocales(); + if(aLocales.getLength()) + { + const lang::Locale* pLocales = aLocales.getConstArray(); + for(sal_Int32 i = 0; i < aLocales.getLength(); i++) + { + ForbiddenCharacters aForbidden; + aAsian.GetStartEndChars( pLocales[i], aForbidden.beginLine, aForbidden.endLine); + LanguageType eLang = LanguageTag::convertToLanguageType(pLocales[i]); + pDoc->setForbiddenCharacters( eLang, aForbidden); + } + } + pDoc->set(IDocumentSettingAccess::KERN_ASIAN_PUNCTUATION, + !aAsian.IsKerningWesternTextOnly()); + pDoc->setCharacterCompressionType(static_cast<SwCharCompressType>(aAsian.GetCharDistanceCompression())); + pDoc->setPrintData(*SW_MOD()->GetPrtOptions(bWeb)); + + SubInitNew(); + + // for all + + SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig(); + SfxPrinter* pPrt = pDoc->getPrinter( false ); + + OUString sEntry; + sal_uInt16 aFontWhich[] = + { RES_CHRATR_FONT, + RES_CHRATR_CJK_FONT, + RES_CHRATR_CTL_FONT + }; + sal_uInt16 aFontHeightWhich[] = + { + RES_CHRATR_FONTSIZE, + RES_CHRATR_CJK_FONTSIZE, + RES_CHRATR_CTL_FONTSIZE + }; + sal_uInt16 aFontIds[] = + { + FONT_STANDARD, + FONT_STANDARD_CJK, + FONT_STANDARD_CTL + }; + sal_uInt16 nFontTypes[] = + { + DEFAULTFONT_LATIN_TEXT, + DEFAULTFONT_CJK_TEXT, + DEFAULTFONT_CTL_TEXT + }; + sal_uInt16 aLangTypes[] = + { + RES_CHRATR_LANGUAGE, + RES_CHRATR_CJK_LANGUAGE, + RES_CHRATR_CTL_LANGUAGE + }; + + for(sal_uInt8 i = 0; i < 3; i++) + { + sal_uInt16 nFontWhich = aFontWhich[i]; + sal_uInt16 nFontId = aFontIds[i]; + SvxFontItem* pFontItem = 0; + const SvxLanguageItem& rLang = (const SvxLanguageItem&)pDoc->GetDefault( aLangTypes[i] ); + LanguageType eLanguage = rLang.GetLanguage(); + if(!pStdFont->IsFontDefault(nFontId)) + { + sEntry = pStdFont->GetFontFor(nFontId); + + Font aFont( sEntry, Size( 0, 10 ) ); + if( pPrt ) + { + aFont = pPrt->GetFontMetric( aFont ); + } + + pFontItem = new SvxFontItem(aFont.GetFamily(), aFont.GetName(), + aEmptyOUStr, aFont.GetPitch(), aFont.GetCharSet(), nFontWhich); + } + else + { + // #107782# OJ use korean language if latin was used + if ( i == 0 ) + { + LanguageType eUiLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType(); + if (MsLangId::isKorean(eUiLanguage)) + eLanguage = eUiLanguage; + } + + Font aLangDefFont = OutputDevice::GetDefaultFont( + nFontTypes[i], + eLanguage, + DEFAULTFONT_FLAGS_ONLYONE ); + pFontItem = new SvxFontItem(aLangDefFont.GetFamily(), aLangDefFont.GetName(), + aEmptyOUStr, aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich); + } + pDoc->SetDefault(*pFontItem); + if( !bHTMLTemplSet ) + { + SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD); + pColl->ResetFmtAttr(nFontWhich); + } + delete pFontItem; + sal_Int32 nFontHeight = pStdFont->GetFontHeight( FONT_STANDARD, i, eLanguage ); + if(nFontHeight <= 0) + nFontHeight = pStdFont->GetDefaultHeightFor( nFontId, eLanguage ); + pDoc->SetDefault(SvxFontHeightItem( nFontHeight, 100, aFontHeightWhich[i] )); + if( !bHTMLTemplSet ) + { + SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD); + pColl->ResetFmtAttr(aFontHeightWhich[i]); + } + + } + sal_uInt16 aFontIdPoolId[] = + { + FONT_OUTLINE, RES_POOLCOLL_HEADLINE_BASE, + FONT_LIST, RES_POOLCOLL_NUMBUL_BASE, + FONT_CAPTION, RES_POOLCOLL_LABEL, + FONT_INDEX, RES_POOLCOLL_REGISTER_BASE, + FONT_OUTLINE_CJK, RES_POOLCOLL_HEADLINE_BASE, + FONT_LIST_CJK, RES_POOLCOLL_NUMBUL_BASE, + FONT_CAPTION_CJK, RES_POOLCOLL_LABEL, + FONT_INDEX_CJK, RES_POOLCOLL_REGISTER_BASE, + FONT_OUTLINE_CTL, RES_POOLCOLL_HEADLINE_BASE, + FONT_LIST_CTL, RES_POOLCOLL_NUMBUL_BASE, + FONT_CAPTION_CTL, RES_POOLCOLL_LABEL, + FONT_INDEX_CTL, RES_POOLCOLL_REGISTER_BASE + }; + + sal_uInt16 nFontWhich = RES_CHRATR_FONT; + sal_uInt16 nFontHeightWhich = RES_CHRATR_FONTSIZE; + LanguageType eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_LANGUAGE )).GetLanguage(); + for(sal_uInt8 nIdx = 0; nIdx < 24; nIdx += 2) + { + if(nIdx == 8) + { + nFontWhich = RES_CHRATR_CJK_FONT; + nFontHeightWhich = RES_CHRATR_CJK_FONTSIZE; + eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CJK_LANGUAGE )).GetLanguage(); + } + else if(nIdx == 16) + { + nFontWhich = RES_CHRATR_CTL_FONT; + nFontHeightWhich = RES_CHRATR_CTL_FONTSIZE; + eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CTL_LANGUAGE )).GetLanguage(); + } + SwTxtFmtColl *pColl = 0; + if(!pStdFont->IsFontDefault(aFontIdPoolId[nIdx])) + { + sEntry = pStdFont->GetFontFor(aFontIdPoolId[nIdx]); + + Font aFont( sEntry, Size( 0, 10 ) ); + if( pPrt ) + aFont = pPrt->GetFontMetric( aFont ); + + pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]); + if( !bHTMLTemplSet || + SFX_ITEM_SET != pColl->GetAttrSet().GetItemState( + nFontWhich, false ) ) + { + pColl->SetFmtAttr(SvxFontItem(aFont.GetFamily(), aFont.GetName(), + aEmptyOUStr, aFont.GetPitch(), aFont.GetCharSet(), nFontWhich)); + } + } + sal_Int32 nFontHeight = pStdFont->GetFontHeight( static_cast< sal_Int8 >(aFontIdPoolId[nIdx]), 0, eLanguage ); + if(nFontHeight <= 0) + nFontHeight = pStdFont->GetDefaultHeightFor( aFontIdPoolId[nIdx], eLanguage ); + if(!pColl) + pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]); + SvxFontHeightItem aFontHeight( (const SvxFontHeightItem&)pColl->GetFmtAttr( nFontHeightWhich, true )); + if(aFontHeight.GetHeight() != sal::static_int_cast<sal_uInt32, sal_Int32>(nFontHeight)) + { + aFontHeight.SetHeight(nFontHeight); + pColl->SetFmtAttr( aFontHeight ); + } + } + + // the default for documents created via 'File/New' should be 'on' + // (old documents, where this property was not yet implemented, will get the + // value 'false' in the SwDoc c-tor) + pDoc->set( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT, + SW_MOD()->GetUsrPref( bWeb )->IsAlignMathObjectsToBaseline() ); + } + + /* #106748# If the default frame direction of a document is RTL + the default adjusment is to the right. */ + if( !bHTMLTemplSet && + FRMDIR_HORI_RIGHT_TOP == GetDefaultFrameDirection(GetAppLanguage()) ) + pDoc->SetDefault( SvxAdjustItem(SVX_ADJUST_RIGHT, RES_PARATR_ADJUST ) ); + +// #i29550# + pDoc->SetDefault( SfxBoolItem( RES_COLLAPSING_BORDERS, true ) ); +// <-- collapsing + + //#i16874# AutoKerning as default for new documents + pDoc->SetDefault( SvxAutoKernItem( true, RES_CHRATR_AUTOKERN ) ); + + // #i42080# - Due to the several calls of method <SetDefault(..)> + // at the document instance, the document is modified. Thus, reset this + // status here. Note: In method <SubInitNew()> this is also done. + pDoc->ResetModified(); + + return bRet; +} + +// Ctor with SfxCreateMode ????? +SwDocShell::SwDocShell( SfxObjectCreateMode eMode ) : + SfxObjectShell ( eMode ), + pDoc(0), + pFontList(0), + pView( 0 ), + pWrtShell( 0 ), + pOLEChildList( 0 ), + nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG), + bInUpdateFontList(false), + bIsATemplate(false) +{ + Init_Impl(); +} + +// Ctor / Dtor +SwDocShell::SwDocShell( const sal_uInt64 i_nSfxCreationFlags ) : + SfxObjectShell ( i_nSfxCreationFlags ), + pDoc(0), + pFontList(0), + pView( 0 ), + pWrtShell( 0 ), + pOLEChildList( 0 ), + nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG), + bInUpdateFontList(false), + bIsATemplate(false) +{ + Init_Impl(); +} + +// Ctor / Dtor +SwDocShell::SwDocShell( SwDoc *pD, SfxObjectCreateMode eMode ): + SfxObjectShell ( eMode ), + pDoc(pD), + pFontList(0), + pView( 0 ), + pWrtShell( 0 ), + pOLEChildList( 0 ), + nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG), + bInUpdateFontList(false), + bIsATemplate(false) +{ + Init_Impl(); +} + +// Dtor +SwDocShell::~SwDocShell() +{ + // disable chart related objects now because in ~SwDoc it may be to late for this + if( pDoc ) + { + pDoc->GetChartControllerHelper().Disconnect(); + SwChartDataProvider *pPCD = pDoc->GetChartDataProvider(); + if (pPCD) + pPCD->dispose(); + } + + RemoveLink(); + delete pFontList; + + // we, as BroadCaster also become our own Listener + // (for DocInfo/FileNames/....) + EndListening( *this ); + + delete pOLEChildList; +} + +void SwDocShell::Init_Impl() +{ + SetPool(&SW_MOD()->GetPool()); + SetBaseModel(new SwXTextDocument(this)); + // we, as BroadCaster also become our own Listener + // (for DocInfo/FileNames/....) + StartListening( *this ); + //position of the "Automatic" style filter for the stylist (app.src) + SetAutoStyleFilterIndex(3); + + // set map unit to twip + SetMapUnit( MAP_TWIP ); +} + +void SwDocShell::AddLink() +{ + if( !pDoc ) + { + SwDocFac aFactory; + pDoc = aFactory.GetDoc(); + pDoc->acquire(); + pDoc->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell) ); + } + else + pDoc->acquire(); + pDoc->SetDocShell( this ); // set the DocShell-Pointer for Doc + uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY); + ((SwXTextDocument*)xDoc.get())->Reactivate(this); + + SetPool(&pDoc->GetAttrPool()); + + // most suitably not until a sdbcx::View is created!!! + pDoc->SetOle2Link(LINK(this, SwDocShell, Ole2ModifiedHdl)); +} + +// create new FontList Change Printer +void SwDocShell::UpdateFontList() +{ + if(!bInUpdateFontList) + { + bInUpdateFontList = true; + OSL_ENSURE(pDoc, "No Doc no FontList"); + if( pDoc ) + { + delete pFontList; + pFontList = new FontList( pDoc->getReferenceDevice( true ) ); + PutItem( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) ); + } + bInUpdateFontList = false; + } +} + +void SwDocShell::RemoveLink() +{ + // disconnect Uno-Object + uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY); + ((SwXTextDocument*)xDoc.get())->Invalidate(); + aFinishedTimer.Stop(); + if(pDoc) + { + if( mxBasePool.is() ) + { + static_cast<SwDocStyleSheetPool*>(mxBasePool.get())->dispose(); + mxBasePool.clear(); + } + sal_Int8 nRefCt = static_cast< sal_Int8 >(pDoc->release()); + pDoc->SetOle2Link(Link()); + pDoc->SetDocShell( 0 ); + if( !nRefCt ) + delete pDoc; + pDoc = 0; // we don't have the Doc anymore!! + } +} +void SwDocShell::InvalidateModel() +{ + // disconnect Uno-Object + uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY); + ((SwXTextDocument*)xDoc.get())->Invalidate(); +} +void SwDocShell::ReactivateModel() +{ + // disconnect Uno-Object + uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY); + ((SwXTextDocument*)xDoc.get())->Reactivate(this); +} + +// Load, Default-Format +bool SwDocShell::Load( SfxMedium& rMedium ) +{ + bool bRet = false; + if( SfxObjectShell::Load( rMedium )) + { + SAL_INFO( "sw.ui", "after SfxInPlaceObject::Load" ); + if( pDoc ) // for last version!! + RemoveLink(); // release the existing + + AddLink(); // set Link and update Data!! + + // Loading + // for MD + OSL_ENSURE( !mxBasePool.is(), "who hasn't destroyed their Pool?" ); + mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() ); + if(GetCreateMode() != SFX_CREATE_MODE_ORGANIZER) + { + SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, false); + nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE; + } + + SwWait aWait( *this, true ); + sal_uInt32 nErr = ERR_SWG_READ_ERROR; + switch( GetCreateMode() ) + { + case SFX_CREATE_MODE_ORGANIZER: + { + if( ReadXML ) + { + ReadXML->SetOrganizerMode( true ); + SwReader aRdr( rMedium, aEmptyOUStr, pDoc ); + nErr = aRdr.Read( *ReadXML ); + ReadXML->SetOrganizerMode( false ); + } + } + break; + + case SFX_CREATE_MODE_INTERNAL: + case SFX_CREATE_MODE_EMBEDDED: + { + // for MWERKS (Mac-Compiler): can't cast autonomously + SwTransferable::InitOle( this, *pDoc ); + } + // suppress SfxProgress, when we are Embedded + SW_MOD()->SetEmbeddedLoadSave( true ); + // no break; + + case SFX_CREATE_MODE_STANDARD: + case SFX_CREATE_MODE_PREVIEW: + { + Reader *pReader = ReadXML; + if( pReader ) + { + // set Doc's DocInfo at DocShell-Medium + SAL_INFO( "sw.ui", "before ReadDocInfo" ); + SwReader aRdr( rMedium, aEmptyOUStr, pDoc ); + SAL_INFO( "sw.ui", "before Read" ); + nErr = aRdr.Read( *pReader ); + SAL_INFO( "sw.ui", "after Read" ); + // If a XML document is loaded, the global doc/web doc + // flags have to be set, because they aren't loaded + // by this formats. + if( ISA( SwWebDocShell ) ) + { + if( !pDoc->get(IDocumentSettingAccess::HTML_MODE) ) + pDoc->set(IDocumentSettingAccess::HTML_MODE, true); + } + if( ISA( SwGlobalDocShell ) ) + { + if( !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) ) + pDoc->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true); + } + } + } + break; + + default: + OSL_ENSURE( !this, "Load: new CreateMode?" ); + } + + UpdateFontList(); + InitDraw(); + + SetError( nErr, OUString( OSL_LOG_PREFIX ) ); + bRet = !IsError( nErr ); + + if ( bRet && !pDoc->IsInLoadAsynchron() && + GetCreateMode() == SFX_CREATE_MODE_STANDARD ) + { + LoadingFinished(); + } + + // suppress SfxProgress, when we are Embedded + SW_MOD()->SetEmbeddedLoadSave( false ); + } + + return bRet; +} + +bool SwDocShell::LoadFrom( SfxMedium& rMedium ) +{ + bool bRet = false; + if( pDoc ) + RemoveLink(); + + AddLink(); // set Link and update Data!! + + do { // middle check loop + sal_uInt32 nErr = ERR_SWG_READ_ERROR; + OUString aStreamName = "styles.xml"; + uno::Reference < container::XNameAccess > xAccess( rMedium.GetStorage(), uno::UNO_QUERY ); + if ( xAccess->hasByName( aStreamName ) && rMedium.GetStorage()->isStreamElement( aStreamName ) ) + { + // Loading + SwWait aWait( *this, true ); + { + OSL_ENSURE( !mxBasePool.is(), "who hasn't destroyed their Pool?" ); + mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() ); + if( ReadXML ) + { + ReadXML->SetOrganizerMode( true ); + SwReader aRdr( rMedium, aEmptyOUStr, pDoc ); + nErr = aRdr.Read( *ReadXML ); + ReadXML->SetOrganizerMode( false ); + } + } + } + else + { + OSL_FAIL("Code removed!"); + } + + SetError( nErr, OUString( OSL_LOG_PREFIX ) ); + bRet = !IsError( nErr ); + + } while( false ); + + SfxObjectShell::LoadFrom( rMedium ); + pDoc->ResetModified(); + return bRet; +} + +void SwDocShell::SubInitNew() +{ + OSL_ENSURE( !mxBasePool.is(), "who hasn't destroyed their Pool?" ); + mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() ); + UpdateFontList(); + InitDraw(); + + pDoc->setLinkUpdateMode( GLOBALSETTING ); + pDoc->setFieldUpdateFlags( AUTOUPD_GLOBALSETTING ); + + bool bWeb = ISA(SwWebDocShell); + + sal_uInt16 nRange[] = { + RES_PARATR_ADJUST, RES_PARATR_ADJUST, + RES_CHRATR_COLOR, RES_CHRATR_COLOR, + RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE, + RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE, + RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE, + 0, 0, 0 }; + if(!bWeb) + { + nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 3 ] = RES_PARATR_TABSTOP; + nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 2 ] = RES_PARATR_HYPHENZONE; + } + SfxItemSet aDfltSet( pDoc->GetAttrPool(), nRange ); + + //! get lingu options without loading lingu DLL + SvtLinguOptions aLinguOpt; + + SvtLinguConfig().GetOptions( aLinguOpt ); + + sal_Int16 nVal = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN), + eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN), + eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX); + aDfltSet.Put( SvxLanguageItem( nVal, RES_CHRATR_LANGUAGE ) ); + aDfltSet.Put( SvxLanguageItem( eCJK, RES_CHRATR_CJK_LANGUAGE ) ); + aDfltSet.Put( SvxLanguageItem( eCTL, RES_CHRATR_CTL_LANGUAGE ) ); + + if(!bWeb) + { + SvxHyphenZoneItem aHyp( (SvxHyphenZoneItem&) pDoc->GetDefault( + RES_PARATR_HYPHENZONE) ); + aHyp.GetMinLead() = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinLeading); + aHyp.GetMinTrail() = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinTrailing); + + aDfltSet.Put( aHyp ); + + sal_uInt16 nNewPos = static_cast< sal_uInt16 >(SW_MOD()->GetUsrPref(false)->GetDefTab()); + if( nNewPos ) + aDfltSet.Put( SvxTabStopItem( 1, nNewPos, + SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP ) ); + } + aDfltSet.Put( SvxColorItem( Color( COL_AUTO ), RES_CHRATR_COLOR ) ); + + pDoc->SetDefault( aDfltSet ); + + //default page mode for text grid + if(!bWeb) + { + bool bSquaredPageMode = SW_MOD()->GetUsrPref(false)->IsSquaredPageMode(); + pDoc->SetDefaultPageMode( bSquaredPageMode ); + } + + pDoc->ResetModified(); +} + +/* + * Document Interface Access + */ +IDocumentDeviceAccess* SwDocShell::getIDocumentDeviceAccess() { return pDoc->getIDocumentDeviceAccess(); } +const IDocumentSettingAccess* SwDocShell::getIDocumentSettingAccess() const { return pDoc; } +IDocumentChartDataProviderAccess* SwDocShell::getIDocumentChartDataProviderAccess() { return pDoc; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx new file mode 100644 index 000000000000..36e29fc85b9e --- /dev/null +++ b/sw/source/uibase/app/docst.cxx @@ -0,0 +1,1279 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> + +#include <comphelper/flagguard.hxx> + +#include <hintids.hxx> +#include <sfx2/app.hxx> +#include <svl/whiter.hxx> +#include <sfx2/templdlg.hxx> +#include <sfx2/tplpitem.hxx> +#include <sfx2/request.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/newstyle.hxx> +#include <sfx2/printer.hxx> +#include <svl/macitem.hxx> +#include <svl/stritem.hxx> +#include <svl/languageoptions.hxx> +#include <editeng/eeitem.hxx> +#include <sfx2/htmlmode.hxx> +#include <swmodule.hxx> +#include <wdocsh.hxx> +#include <fmtfsize.hxx> +#include <fchrfmt.hxx> +#include <svtools/htmlcfg.hxx> +#include <svx/xdef.hxx> +#include <SwStyleNameMapper.hxx> +#include <SwRewriter.hxx> +#include <numrule.hxx> +#include <swundo.hxx> + +#include "view.hxx" +#include "wrtsh.hxx" +#include "docsh.hxx" +#include "uitool.hxx" +#include "cmdid.h" +#include "globals.hrc" +#include "viewopt.hxx" +#include <doc.hxx> +#include <IDocumentUndoRedo.hxx> +#include "swstyle.h" +#include "frmfmt.hxx" +#include "charfmt.hxx" +#include "poolfmt.hxx" +#include "pagedesc.hxx" +#include "docstyle.hxx" +#include "uiitems.hxx" +#include "fmtcol.hxx" +#include "frmmgr.hxx" +#include "swevent.hxx" +#include "edtwin.hxx" +#include "unochart.hxx" + +#include "app.hrc" +#include "swabstdlg.hxx" + +#include <list.hxx> + +#include <paratr.hxx> + +extern bool bNoInterrupt; // in mainwn.cxx + +using namespace ::com::sun::star; + +void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh) +{ + SfxWhichIter aIter(rSet); + sal_uInt16 nWhich = aIter.FirstWhich(); + sal_uInt16 nActualFamily = USHRT_MAX; + + SwWrtShell* pShell = pSh ? pSh : GetWrtShell(); + if(!pShell) + { + while (nWhich) + { + rSet.DisableItem(nWhich); + nWhich = aIter.NextWhich(); + } + return; + } + else + { + SfxViewFrame* pFrame = pShell->GetView().GetViewFrame(); + const ISfxTemplateCommon* pCommon = SFX_APP()->GetCurrentTemplateCommon(pFrame->GetBindings()); + if( pCommon ) + nActualFamily = static_cast< sal_uInt16 >(pCommon->GetActualFamily()); + } + + while (nWhich) + { + // determine current template to every family + OUString aName; + switch (nWhich) + { + case SID_STYLE_APPLY: + {// here the template and its family are passed to the StyleBox + // so that this family is being showed + if(pShell->IsFrmSelected()) + { + SwFrmFmt* pFmt = pShell->GetCurFrmFmt(); + if( pFmt ) + aName = pFmt->GetName(); + } + else + { + SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl(); + if(pColl) + aName = pColl->GetName(); + } + rSet.Put(SfxTemplateItem(nWhich, aName)); + } + break; + case SID_STYLE_FAMILY1: + if( !pShell->IsFrmSelected() ) + { + SwCharFmt* pFmt = pShell->GetCurCharFmt(); + if(pFmt) + aName = pFmt->GetName(); + else + aName = SwStyleNameMapper::GetTextUINameArray()[ + RES_POOLCOLL_STANDARD - RES_POOLCOLL_TEXT_BEGIN ]; + rSet.Put(SfxTemplateItem(nWhich, aName)); + } + break; + + case SID_STYLE_FAMILY2: + if(!pShell->IsFrmSelected()) + { + SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl(); + if(pColl) + aName = pColl->GetName(); + + SfxTemplateItem aItem(nWhich, aName); + + sal_uInt16 nMask = 0; + if( pDoc->get(IDocumentSettingAccess::HTML_MODE) ) + nMask = SWSTYLEBIT_HTML; + else + { + const int nSelection = pShell->GetFrmType(0,true); + if(pShell->GetCurTOX()) + nMask = SWSTYLEBIT_IDX ; + else if(nSelection & FRMTYPE_HEADER || + nSelection & FRMTYPE_FOOTER || + nSelection & FRMTYPE_TABLE || + nSelection & FRMTYPE_FLY_ANY || + nSelection & FRMTYPE_FOOTNOTE || + nSelection & FRMTYPE_FTNPAGE) + nMask = SWSTYLEBIT_EXTRA; + else + nMask = SWSTYLEBIT_TEXT; + } + + aItem.SetValue(nMask); + rSet.Put(aItem); + } + + break; + + case SID_STYLE_FAMILY3: + + if( pDoc->get(IDocumentSettingAccess::HTML_MODE) ) + rSet.DisableItem( nWhich ); + else + { + SwFrmFmt* pFmt = pShell->GetCurFrmFmt(); + if(pFmt && pShell->IsFrmSelected()) + { + aName = pFmt->GetName(); + rSet.Put(SfxTemplateItem(nWhich, aName)); + } + } + break; + + case SID_STYLE_FAMILY4: + { + SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get(); + if( pDoc->get(IDocumentSettingAccess::HTML_MODE) && !rHtmlOpt.IsPrintLayoutExtension()) + rSet.DisableItem( nWhich ); + else + { + sal_uInt16 n = pShell->GetCurPageDesc( false ); + if( n < pShell->GetPageDescCnt() ) + aName = pShell->GetPageDesc( n ).GetName(); + + rSet.Put(SfxTemplateItem(nWhich, aName)); + } + } + break; + case SID_STYLE_FAMILY5: + { + const SwNumRule* pRule = pShell->GetNumRuleAtCurrCrsrPos(); + if( pRule ) + aName = pRule->GetName(); + + rSet.Put(SfxTemplateItem(nWhich, aName)); + } + break; + + case SID_STYLE_WATERCAN: + { + SwEditWin& rEdtWin = pShell->GetView().GetEditWin(); + SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate(); + rSet.Put(SfxBoolItem(nWhich, pApply && pApply->eType != 0)); + } + break; + case SID_STYLE_UPDATE_BY_EXAMPLE: + if( pShell->IsFrmSelected() + ? SFX_STYLE_FAMILY_FRAME != nActualFamily + : ( SFX_STYLE_FAMILY_FRAME == nActualFamily || + SFX_STYLE_FAMILY_PAGE == nActualFamily || + (SFX_STYLE_FAMILY_PSEUDO == nActualFamily && !pShell->GetNumRuleAtCurrCrsrPos())) ) + { + rSet.DisableItem( nWhich ); + } + break; + + case SID_STYLE_NEW_BY_EXAMPLE: + if( (pShell->IsFrmSelected() + ? SFX_STYLE_FAMILY_FRAME != nActualFamily + : SFX_STYLE_FAMILY_FRAME == nActualFamily) || + (SFX_STYLE_FAMILY_PSEUDO == nActualFamily && !pShell->GetNumRuleAtCurrCrsrPos()) ) + { + rSet.DisableItem( nWhich ); + } + break; + + default: + OSL_FAIL("Invalid SlotId"); + } + nWhich = aIter.NextWhich(); + } +} + +// evaluate StyleSheet-Requests +void SwDocShell::ExecStyleSheet( SfxRequest& rReq ) +{ + sal_uInt16 nSlot = rReq.GetSlot(); + sal_uInt16 nRet = SFXSTYLEBIT_ALL; + + const SfxItemSet* pArgs = rReq.GetArgs(); + const SfxPoolItem* pItem; + SwWrtShell* pActShell = 0; + switch (nSlot) + { + case SID_STYLE_NEW: + if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_FAMILY, + false, &pItem )) + { + const sal_uInt16 nFamily = ((const SfxUInt16Item*)pItem)->GetValue(); + + OUString sName; + sal_uInt16 nMask = 0; + if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_NEW, + false, &pItem )) + sName = ((const SfxStringItem*)pItem)->GetValue(); + if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_MASK, + false, &pItem )) + nMask = ((const SfxUInt16Item*)pItem)->GetValue(); + OUString sParent; + if( SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_REFERENCE, + false, &pItem )) + sParent = ((const SfxStringItem*)pItem)->GetValue(); + + nRet = Edit( sName, sParent, nFamily, nMask, true, OString(), 0, rReq.IsAPI() ); + } + break; + + case SID_STYLE_APPLY: + if( !pArgs ) + { + GetView()->GetViewFrame()->GetDispatcher()->Execute(SID_STYLE_DESIGNER, sal_False); + break; + } + else + { + // convert internal StyleName to DisplayName (slot implementation uses the latter) + SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_APPLY_STYLE, false ); + SFX_REQUEST_ARG( rReq, pFamilyItem, SfxStringItem, SID_STYLE_FAMILYNAME, false ); + if ( pFamilyItem && pNameItem ) + { + uno::Reference< style::XStyleFamiliesSupplier > xModel(GetModel(), uno::UNO_QUERY); + try + { + uno::Reference< container::XNameAccess > xStyles; + uno::Reference< container::XNameAccess > xCont = xModel->getStyleFamilies(); + xCont->getByName(pFamilyItem->GetValue()) >>= xStyles; + uno::Reference< beans::XPropertySet > xInfo; + xStyles->getByName( pNameItem->GetValue() ) >>= xInfo; + OUString aUIName; + xInfo->getPropertyValue("DisplayName") >>= aUIName; + if ( !aUIName.isEmpty() ) + rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) ); + } + catch (const uno::Exception&) + { + } + } + } + + // intentionally no break + + case SID_STYLE_EDIT: + case SID_STYLE_DELETE: + case SID_STYLE_HIDE: + case SID_STYLE_SHOW: + case SID_STYLE_WATERCAN: + case SID_STYLE_FAMILY: + case SID_STYLE_UPDATE_BY_EXAMPLE: + case SID_STYLE_NEW_BY_EXAMPLE: + { + OUString aParam; + sal_uInt16 nFamily = SFX_STYLE_FAMILY_PARA; + sal_uInt16 nMask = 0; + + if( !pArgs ) + { + nFamily = SFX_STYLE_FAMILY_PARA; + + switch (nSlot) + { + case SID_STYLE_NEW_BY_EXAMPLE: + { + boost::scoped_ptr<SfxNewStyleDlg> pDlg(new SfxNewStyleDlg( 0, + *GetStyleSheetPool())); + if(RET_OK == pDlg->Execute()) + { + aParam = pDlg->GetName(); + rReq.AppendItem(SfxStringItem(nSlot, aParam)); + } + } + break; + + case SID_STYLE_UPDATE_BY_EXAMPLE: + case SID_STYLE_EDIT: + { + SwTxtFmtColl* pColl = GetWrtShell()->GetCurTxtFmtColl(); + if(pColl) + { + aParam = pColl->GetName(); + rReq.AppendItem(SfxStringItem(nSlot, aParam)); + } + } + break; + } + } + else + { + SAL_WARN_IF( !pArgs->Count(), "sw.ui", "SfxBug ItemSet is empty" ); + + SwWrtShell* pShell = GetWrtShell(); + if( SFX_ITEM_SET == pArgs->GetItemState(nSlot, false, &pItem )) + aParam = ((const SfxStringItem*)pItem)->GetValue(); + + if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_FAMILY, + false, &pItem )) + nFamily = ((const SfxUInt16Item*)pItem)->GetValue(); + + if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_FAMILYNAME, false, &pItem )) + { + OUString aFamily = ((const SfxStringItem*)pItem)->GetValue(); + if(aFamily.equalsAscii("CharacterStyles")) + nFamily = SFX_STYLE_FAMILY_CHAR; + else + if(aFamily.equalsAscii("ParagraphStyles")) + nFamily = SFX_STYLE_FAMILY_PARA; + else + if(aFamily.equalsAscii("PageStyles")) + nFamily = SFX_STYLE_FAMILY_PAGE; + else + if(aFamily.equalsAscii("FrameStyles")) + nFamily = SFX_STYLE_FAMILY_FRAME; + else + if(aFamily.equalsAscii("NumberingStyles")) + nFamily = SFX_STYLE_FAMILY_PSEUDO; + } + + if( SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_MASK, + false, &pItem )) + nMask = ((const SfxUInt16Item*)pItem)->GetValue(); + if( SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_WRTSHELL, + false, &pItem )) + pActShell = pShell = (SwWrtShell*)((SwPtrItem*)pItem)->GetValue(); + + if( nSlot == SID_STYLE_UPDATE_BY_EXAMPLE ) + { + switch( nFamily ) + { + case SFX_STYLE_FAMILY_PARA: + { + SwTxtFmtColl* pColl = pShell->GetCurTxtFmtColl(); + if(pColl) + aParam = pColl->GetName(); + } + break; + case SFX_STYLE_FAMILY_FRAME: + { + SwFrmFmt* pFrm = pWrtShell->GetCurFrmFmt(); + if( pFrm ) + aParam = pFrm->GetName(); + } + break; + case SFX_STYLE_FAMILY_CHAR: + { + SwCharFmt* pChar = pWrtShell->GetCurCharFmt(); + if( pChar ) + aParam = pChar->GetName(); + } + break; + case SFX_STYLE_FAMILY_PSEUDO: + if(SFX_ITEM_SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, false, &pItem)) + { + aParam = ((const SfxStringItem*)pItem)->GetValue(); + } + break; + } + rReq.AppendItem(SfxStringItem(nSlot, aParam)); + } + } + if (!aParam.isEmpty() || nSlot == SID_STYLE_WATERCAN ) + { + switch(nSlot) + { + case SID_STYLE_EDIT: + nRet = Edit(aParam, aEmptyOUStr, nFamily, nMask, false, OString(), pActShell ); + break; + case SID_STYLE_DELETE: + nRet = Delete(aParam, nFamily); + break; + case SID_STYLE_HIDE: + case SID_STYLE_SHOW: + nRet = Hide(aParam, nFamily, nSlot == SID_STYLE_HIDE); + break; + case SID_STYLE_APPLY: + // Shell-switch in ApplyStyles + nRet = ApplyStyles(aParam, nFamily, pActShell, rReq.GetModifier() ); + break; + case SID_STYLE_WATERCAN: + nRet = DoWaterCan(aParam, nFamily); + break; + case SID_STYLE_UPDATE_BY_EXAMPLE: + nRet = UpdateStyle(aParam, nFamily, pActShell); + break; + case SID_STYLE_NEW_BY_EXAMPLE: + { + nRet = MakeByExample(aParam, nFamily, nMask, pActShell ); + SfxTemplateDialog* pDlg = SFX_APP()->GetTemplateDialog(); + + if(pDlg && pDlg->IsVisible()) + pDlg->Update(); + } + break; + + default: + OSL_FAIL("Invalid SlotId"); + } + + rReq.Done(); + } + + break; + } + } + + if(rReq.IsAPI()) // Basic only gets TRUE or FALSE + rReq.SetReturnValue(SfxUInt16Item(nSlot, sal_uInt16(nRet !=0))); + else + rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet)); +} + +class ApplyStyle +{ +public: + ApplyStyle(SwDocShell &rDocSh, bool bNew, SfxStyleSheetBase* pStyle, + sal_uInt16 nRet, rtl::Reference< SwDocStyleSheet > xTmp, + sal_uInt16 nFamily, SfxAbstractApplyTabDialog *pDlg, + rtl::Reference< SfxStyleSheetBasePool > xBasePool, + bool bModified) + : m_rDocSh(rDocSh) + , m_bNew(bNew) + , m_pStyle(pStyle) + , m_nRet(nRet) + , m_xTmp(xTmp) + , m_nFamily(nFamily) + , m_pDlg(pDlg) + , m_xBasePool(xBasePool) + , m_bModified(bModified) + { + } + DECL_LINK( ApplyHdl, void* ); + void apply() + { + ApplyHdl(NULL); + } + sal_uInt16 getRet() const { return m_nRet; } +private: + SwDocShell &m_rDocSh; + bool m_bNew; + SfxStyleSheetBase* m_pStyle; + sal_uInt16 m_nRet; + rtl::Reference< SwDocStyleSheet > m_xTmp; + sal_uInt16 m_nFamily; + SfxAbstractApplyTabDialog *m_pDlg; + rtl::Reference< SfxStyleSheetBasePool > m_xBasePool; + bool m_bModified; +}; + +IMPL_LINK_NOARG(ApplyStyle, ApplyHdl) +{ + SwWrtShell* pWrtShell = m_rDocSh.GetWrtShell(); + SwDoc* pDoc = m_rDocSh.GetDoc(); + SwView* pView = m_rDocSh.GetView(); + + pWrtShell->StartAllAction(); + + // newly set the mask only with paragraph-templates + if( m_bNew ) + { + m_nRet = SFX_STYLE_FAMILY_PARA == m_pStyle->GetFamily() + ? m_xTmp->GetMask() + : SFXSTYLEBIT_USERDEF; + } + else if( m_pStyle->GetMask() != m_xTmp->GetMask() ) + m_nRet = m_xTmp->GetMask(); + + if( SFX_STYLE_FAMILY_PARA == m_nFamily ) + { + SfxItemSet aSet( *m_pDlg->GetOutputItemSet() ); + ::SfxToSwPageDescAttr( *pWrtShell, aSet ); + // reset indent attributes at paragraph style, if a list style + // will be applied and no indent attributes will be applied. + m_xTmp->SetItemSet( aSet, true ); + } + else + { + if(SFX_STYLE_FAMILY_PAGE == m_nFamily) + { + static const sal_uInt16 aInval[] = { + SID_IMAGE_ORIENTATION, + SID_ATTR_CHAR_FONT, + FN_INSERT_CTRL, FN_INSERT_OBJ_CTRL, 0}; + pView->GetViewFrame()->GetBindings().Invalidate(aInval); + } + SfxItemSet aTmpSet( *m_pDlg->GetOutputItemSet() ); + if( SFX_STYLE_FAMILY_CHAR == m_nFamily ) + { + ::ConvertAttrGenToChar(aTmpSet, CONV_ATTR_STD); + } + + //UUUU + if(m_bNew && SFX_STYLE_FAMILY_FRAME == m_nFamily) + { + // clear FillStyle so that it works as a derived attribute + aTmpSet.ClearItem(XATTR_FILLSTYLE); + } + + m_xTmp->SetItemSet( aTmpSet ); + + if( SFX_STYLE_FAMILY_PAGE == m_nFamily && SvtLanguageOptions().IsCTLFontEnabled() ) + { + const SfxPoolItem *pItem = NULL; + if( aTmpSet.GetItemState( m_rDocSh.GetPool().GetTrueWhich( SID_ATTR_FRAMEDIRECTION, false ) , true, &pItem ) == SFX_ITEM_SET ) + SwChartHelper::DoUpdateAllCharts( pDoc ); + } + } + if(SFX_STYLE_FAMILY_PAGE == m_nFamily) + pView->InvalidateRulerPos(); + + if( m_bNew ) + m_xBasePool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *m_xTmp.get() ) ); + + pDoc->SetModified(); + if( !m_bModified ) + { + pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified(); + } + + pWrtShell->EndAllAction(); + + return m_nRet; +} + +//UUUU +//#include <svx/svdmodel.hxx> +//#include <svx/drawitem.hxx> + +sal_uInt16 SwDocShell::Edit( + const OUString &rName, + const OUString &rParent, + const sal_uInt16 nFamily, + sal_uInt16 nMask, + const bool bNew, + const OString& sPage, + SwWrtShell* pActShell, + const bool bBasic ) +{ + assert( GetWrtShell() ); + SfxStyleSheetBase *pStyle = 0; + + sal_uInt16 nRet = nMask; + bool bModified = pDoc->IsModified(); + + if( bNew ) + { + if( SFXSTYLEBIT_ALL != nMask && SFXSTYLEBIT_USED != nMask ) + nMask |= SFXSTYLEBIT_USERDEF; + else + nMask = SFXSTYLEBIT_USERDEF; + + pStyle = &mxBasePool->Make( rName, (SfxStyleFamily)nFamily, nMask ); + + // set the current one as Parent + SwDocStyleSheet* pDStyle = (SwDocStyleSheet*)pStyle; + switch( nFamily ) + { + case SFX_STYLE_FAMILY_PARA: + { + if(!rParent.isEmpty()) + { + SwTxtFmtColl* pColl = pWrtShell->FindTxtFmtCollByName( rParent ); + if(!pColl) + { + sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL); + if(USHRT_MAX != nId) + pColl = pWrtShell->GetTxtCollFromPool( nId ); + } + pDStyle->GetCollection()->SetDerivedFrom( pColl ); + pDStyle->PresetParent( rParent ); + + /*When a new paragraph style is created based on a "to outline style + assigned" paragraph style, the outline level attribute and the list + style attribute of the new paragraph style have to be set to 0 + respectively "".*/ + if (pColl && pColl->IsAssignedToListLevelOfOutlineStyle()) + { + SwNumRuleItem aItem(aEmptyOUStr); + pDStyle->GetCollection()->SetFmtAttr( aItem ); + pDStyle->GetCollection()->SetAttrOutlineLevel( 0 ); + } + } + else + { + SwTxtFmtColl* pColl = pWrtShell->GetCurTxtFmtColl(); + pDStyle->GetCollection()->SetDerivedFrom( pColl ); + if( pColl ) + pDStyle->PresetParent( pColl->GetName() ); + } + } + break; + case SFX_STYLE_FAMILY_CHAR: + { + if(!rParent.isEmpty()) + { + SwCharFmt* pCFmt = pWrtShell->FindCharFmtByName( rParent ); + if(!pCFmt) + { + sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT); + if(USHRT_MAX != nId) + pCFmt = pWrtShell->GetCharFmtFromPool( nId ); + } + + pDStyle->GetCharFmt()->SetDerivedFrom( pCFmt ); + pDStyle->PresetParent( rParent ); + } + else + { + SwCharFmt* pCFmt = pWrtShell->GetCurCharFmt(); + pDStyle->GetCharFmt()->SetDerivedFrom( pCFmt ); + if( pCFmt ) + pDStyle->PresetParent( pCFmt->GetName() ); + } + } + break; + case SFX_STYLE_FAMILY_FRAME : + { + if(!rParent.isEmpty()) + { + SwFrmFmt* pFFmt = pWrtShell->GetDoc()->FindFrmFmtByName( rParent ); + if(!pFFmt) + { + sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT); + if(USHRT_MAX != nId) + pFFmt = pWrtShell->GetFrmFmtFromPool( nId ); + } + pDStyle->GetFrmFmt()->SetDerivedFrom( pFFmt ); + pDStyle->PresetParent( rParent ); + } + } + break; + } + } + else + { + pStyle = mxBasePool->Find( rName, (SfxStyleFamily)nFamily ); + SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" ); + } + + if(!pStyle) + return sal_False; + + // put dialogues together + rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) ); + if( SFX_STYLE_FAMILY_PARA == nFamily ) + { + SfxItemSet& rSet = xTmp->GetItemSet(); + ::SwToSfxPageDescAttr( rSet ); + // firstly only a Zero + rSet.Put(SwBackgroundDestinationItem(SID_PARA_BACKGRND_DESTINATION, 0)); + // merge list level indent attributes into the item set if needed + xTmp->MergeIndentAttrsOfListStyle( rSet ); + } + else if( SFX_STYLE_FAMILY_CHAR == nFamily ) + { + ::ConvertAttrCharToGen(xTmp->GetItemSet(), CONV_ATTR_STD); + } + if (!bBasic) + { + //UUUU + //if(SFX_STYLE_FAMILY_FRAME == nFamily) + //{ + // //UUUU create needed items for XPropertyList entries from the DrawModel so that + // // the Area TabPage can access them + // SfxItemSet& rSet = xTmp->GetItemSet(); + // const SdrModel* pDrawModel = GetDoc()->GetDrawModel(); + // + // rSet.Put(SvxColorTableItem(pDrawModel->GetColorTableFromSdrModel(), SID_COLOR_TABLE)); + // rSet.Put(SvxGradientListItem(pDrawModel->GetGradientListFromSdrModel(), SID_GRADIENT_LIST)); + // rSet.Put(SvxHatchListItem(pDrawModel->GetHatchListFromSdrModel(), SID_HATCH_LIST)); + // rSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapListFromSdrModel(), SID_BITMAP_LIST)); + //} + + // prior to the dialog the HtmlMode at the DocShell is being sunk + sal_uInt16 nHtmlMode = ::GetHtmlMode(this); + + // In HTML mode, we do not always have a printer. In order to show + // the correct page size in the Format - Page dialog, we have to + // get one here. + SwWrtShell* pCurrShell = ( pActShell ? pActShell : pWrtShell ); + if( ( HTMLMODE_ON & nHtmlMode ) && + !pCurrShell->getIDocumentDeviceAccess()->getPrinter( false ) ) + pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess()->getPrinter( true ) ); + + PutItem(SfxUInt16Item(SID_HTML_MODE, nHtmlMode)); + FieldUnit eMetric = ::GetDfltMetric(0 != (HTMLMODE_ON&nHtmlMode)); + SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric))); + SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); + assert( pFact ); + boost::scoped_ptr<SfxAbstractApplyTabDialog> pDlg(pFact->CreateTemplateDialog( + 0, *(xTmp.get()), nFamily, sPage, + pActShell ? pActShell : pWrtShell, bNew)); + assert( pDlg ); + ApplyStyle aApplyStyleHelper(*this, bNew, pStyle, nRet, xTmp, nFamily, pDlg.get(), mxBasePool, bModified); + pDlg->SetApplyHdl(LINK(&aApplyStyleHelper, ApplyStyle, ApplyHdl)); + + if (RET_OK == pDlg->Execute()) + { + aApplyStyleHelper.apply(); + } + else + { + if( bNew ) + { + GetWrtShell()->Undo(1); + pDoc->GetIDocumentUndoRedo().ClearRedo(); + } + + if( !bModified ) + pDoc->ResetModified(); + } + + nRet = aApplyStyleHelper.getRet(); + } + else + { + // prior to the dialog the HtmlMode at the DocShell is being sunk + PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this))); + + GetWrtShell()->StartAllAction(); + + // newly set the mask only with paragraph-templates + if( bNew ) + { + nRet = SFX_STYLE_FAMILY_PARA == pStyle->GetFamily() + ? xTmp->GetMask() + : SFXSTYLEBIT_USERDEF; + } + else if( pStyle->GetMask() != xTmp->GetMask() ) + nRet = xTmp->GetMask(); + + if( SFX_STYLE_FAMILY_PARA == nFamily ) + ::SfxToSwPageDescAttr( *GetWrtShell(), xTmp->GetItemSet() ); + else + { + ::ConvertAttrGenToChar(xTmp->GetItemSet(), CONV_ATTR_STD); + } + if(SFX_STYLE_FAMILY_PAGE == nFamily) + pView->InvalidateRulerPos(); + + if( bNew ) + mxBasePool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xTmp.get() ) ); + + pDoc->SetModified(); + if( !bModified ) // Bug 57028 + { + pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified(); + } + GetWrtShell()->EndAllAction(); + } + + return nRet; +} + +sal_uInt16 SwDocShell::Delete(const OUString &rName, sal_uInt16 nFamily) +{ + SfxStyleSheetBase *pStyle = mxBasePool->Find(rName, (SfxStyleFamily)nFamily); + + if(pStyle) + { + assert( GetWrtShell() ); + + GetWrtShell()->StartAllAction(); + mxBasePool->Remove(pStyle); + GetWrtShell()->EndAllAction(); + + return sal_True; + } + return sal_False; +} + +sal_uInt16 SwDocShell::Hide(const OUString &rName, sal_uInt16 nFamily, bool bHidden) +{ + SfxStyleSheetBase *pStyle = mxBasePool->Find(rName, (SfxStyleFamily)nFamily); + + if(pStyle) + { + assert( GetWrtShell() ); + + GetWrtShell()->StartAllAction(); + rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) ); + xTmp->SetHidden( bHidden ); + GetWrtShell()->EndAllAction(); + + return sal_True; + } + return sal_False; +} + +// apply template +sal_uInt16 SwDocShell::ApplyStyles(const OUString &rName, sal_uInt16 nFamily, + SwWrtShell* pShell, const sal_uInt16 nMode ) +{ + SwDocStyleSheet* pStyle = (SwDocStyleSheet*) mxBasePool->Find( rName, (SfxStyleFamily) nFamily ); + + SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" ); + + if(!pStyle) + return sal_False; + + SwWrtShell *pSh = pShell ? pShell : GetWrtShell(); + + assert( pSh ); + + pSh->StartAllAction(); + + switch (nFamily) + { + case SFX_STYLE_FAMILY_CHAR: + { + SwFmtCharFmt aFmt(pStyle->GetCharFmt()); + pSh->SetAttrItem( aFmt, (nMode & KEY_SHIFT) ? + nsSetAttrMode::SETATTR_DONTREPLACE : nsSetAttrMode::SETATTR_DEFAULT ); + break; + } + case SFX_STYLE_FAMILY_PARA: + { + // #i62675# + // clear also list attributes at affected text nodes, if paragraph + // style has the list style attribute set. + pSh->SetTxtFmtColl( pStyle->GetCollection(), true ); + break; + } + case SFX_STYLE_FAMILY_FRAME: + { + if ( pSh->IsFrmSelected() ) + pSh->SetFrmFmt( pStyle->GetFrmFmt() ); + break; + } + case SFX_STYLE_FAMILY_PAGE: + { + pSh->SetPageStyle(pStyle->GetPageDesc()->GetName()); + break; + } + case SFX_STYLE_FAMILY_PSEUDO: + { + // reset indent attribute on applying list style + // continue list of list style + const SwNumRule* pNumRule = pStyle->GetNumRule(); + const OUString sListIdForStyle =pNumRule->GetDefaultListId(); + pSh->SetCurNumRule( *pNumRule, false, sListIdForStyle, true ); + break; + } + default: + OSL_FAIL("Unknown family"); + } + pSh->EndAllAction(); + + return nFamily; +} + +// start watering-can +sal_uInt16 SwDocShell::DoWaterCan(const OUString &rName, sal_uInt16 nFamily) +{ + assert( GetWrtShell() ); + + SwEditWin& rEdtWin = pView->GetEditWin(); + SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate(); + bool bWaterCan = !(pApply && pApply->eType != 0); + + if( rName.isEmpty() ) + bWaterCan = false; + + SwApplyTemplate aTemplate; + aTemplate.eType = nFamily; + + if(bWaterCan) + { + SwDocStyleSheet* pStyle = + (SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily); + + SAL_WARN_IF( !pStyle, "sw.ui", "Where's the StyleSheet" ); + + if(!pStyle) return nFamily; + + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR: + aTemplate.aColl.pCharFmt = pStyle->GetCharFmt(); + break; + case SFX_STYLE_FAMILY_PARA: + aTemplate.aColl.pTxtColl = pStyle->GetCollection(); + break; + case SFX_STYLE_FAMILY_FRAME: + aTemplate.aColl.pFrmFmt = pStyle->GetFrmFmt(); + break; + case SFX_STYLE_FAMILY_PAGE: + aTemplate.aColl.pPageDesc = (SwPageDesc*)pStyle->GetPageDesc(); + break; + case SFX_STYLE_FAMILY_PSEUDO: + aTemplate.aColl.pNumRule = (SwNumRule*)pStyle->GetNumRule(); + break; + + default: + OSL_FAIL("Unknown family"); + } + } + else + aTemplate.eType = 0; + + pView->GetEditWin().SetApplyTemplate(aTemplate); + + return nFamily; +} + +// update template +sal_uInt16 SwDocShell::UpdateStyle(const OUString &rName, sal_uInt16 nFamily, SwWrtShell* pShell) +{ + SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell(); + assert( pCurrWrtShell ); + + SwDocStyleSheet* pStyle = + (SwDocStyleSheet*)mxBasePool->Find(rName, (SfxStyleFamily)nFamily); + + if(!pStyle) + return nFamily; + + switch(nFamily) + { + case SFX_STYLE_FAMILY_PARA: + { + SwTxtFmtColl* pColl = pStyle->GetCollection(); + if(pColl && !pColl->IsDefault()) + { + GetWrtShell()->StartAllAction(); + + SwRewriter aRewriter; + aRewriter.AddRule(UndoArg1, pColl->GetName()); + + GetWrtShell()->StartUndo(UNDO_INSFMTATTR, &aRewriter); + GetWrtShell()->FillByEx(pColl); + // also apply template to remove hard set attributes + GetWrtShell()->SetTxtFmtColl( pColl ); + GetWrtShell()->EndUndo(); + GetWrtShell()->EndAllAction(); + } + break; + } + case SFX_STYLE_FAMILY_FRAME: + { + SwFrmFmt* pFrm = pStyle->GetFrmFmt(); + if( pCurrWrtShell->IsFrmSelected() && pFrm && !pFrm->IsDefault() ) + { + SfxItemSet aSet( GetPool(), aFrmFmtSetRange ); + pCurrWrtShell->StartAllAction(); + pCurrWrtShell->GetFlyFrmAttr( aSet ); + + // #i105535# + // no update of anchor attribute + aSet.ClearItem( RES_ANCHOR ); + + pFrm->SetFmtAttr( aSet ); + + // also apply template to remove hard set attributes + pCurrWrtShell->SetFrmFmt( pFrm, true ); + pCurrWrtShell->EndAllAction(); + } + } + break; + case SFX_STYLE_FAMILY_CHAR: + { + SwCharFmt* pChar = pStyle->GetCharFmt(); + if( pChar && !pChar->IsDefault() ) + { + pCurrWrtShell->StartAllAction(); + pCurrWrtShell->FillByEx(pChar); + // also apply template to remove hard set attributes + pCurrWrtShell->EndAllAction(); + } + + } + break; + case SFX_STYLE_FAMILY_PSEUDO: + { + const SwNumRule* pCurRule; + if( pStyle->GetNumRule() && + 0 != ( pCurRule = pCurrWrtShell->GetNumRuleAtCurrCrsrPos() )) + { + SwNumRule aRule( *pCurRule ); + // #i91400# + aRule.SetName( pStyle->GetNumRule()->GetName(), + *(pCurrWrtShell->GetDoc()) ); + pCurrWrtShell->ChgNumRuleFmts( aRule ); + } + } + break; + } + return nFamily; +} + +// NewByExample +sal_uInt16 SwDocShell::MakeByExample( const OUString &rName, sal_uInt16 nFamily, + sal_uInt16 nMask, SwWrtShell* pShell ) +{ + SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell(); + SwDocStyleSheet* pStyle = (SwDocStyleSheet*)mxBasePool->Find( + rName, (SfxStyleFamily)nFamily ); + if(!pStyle) + { + // preserve the current mask of PI, then the new one is + // immediately merged with the viewable area + if( SFXSTYLEBIT_ALL == nMask || SFXSTYLEBIT_USED == nMask ) + nMask = SFXSTYLEBIT_USERDEF; + else + nMask |= SFXSTYLEBIT_USERDEF; + + pStyle = (SwDocStyleSheet*)&mxBasePool->Make(rName, + (SfxStyleFamily)nFamily, nMask ); + } + + switch(nFamily) + { + case SFX_STYLE_FAMILY_PARA: + { + SwTxtFmtColl* pColl = pStyle->GetCollection(); + if(pColl && !pColl->IsDefault()) + { + pCurrWrtShell->StartAllAction(); + pCurrWrtShell->FillByEx(pColl); + // also apply template to remove hard set attributes + pColl->SetDerivedFrom(pCurrWrtShell->GetCurTxtFmtColl()); + + // set the mask at the Collection: + sal_uInt16 nId = pColl->GetPoolFmtId() & 0x87ff; + switch( nMask & 0x0fff ) + { + case SWSTYLEBIT_TEXT: + nId |= COLL_TEXT_BITS; + break; + case SWSTYLEBIT_CHAPTER: + nId |= COLL_DOC_BITS; + break; + case SWSTYLEBIT_LIST: + nId |= COLL_LISTS_BITS; + break; + case SWSTYLEBIT_IDX: + nId |= COLL_REGISTER_BITS; + break; + case SWSTYLEBIT_EXTRA: + nId |= COLL_EXTRA_BITS; + break; + case SWSTYLEBIT_HTML: + nId |= COLL_HTML_BITS; + break; + } + pColl->SetPoolFmtId(nId); + + pCurrWrtShell->SetTxtFmtColl(pColl); + pCurrWrtShell->EndAllAction(); + } + } + break; + case SFX_STYLE_FAMILY_FRAME: + { + SwFrmFmt* pFrm = pStyle->GetFrmFmt(); + if(pCurrWrtShell->IsFrmSelected() && pFrm && !pFrm->IsDefault()) + { + pCurrWrtShell->StartAllAction(); + + SfxItemSet aSet(GetPool(), aFrmFmtSetRange ); + pCurrWrtShell->GetFlyFrmAttr( aSet ); + + SwFrmFmt* pFFmt = pCurrWrtShell->GetCurFrmFmt(); + pFrm->SetDerivedFrom( pFFmt ); + + pFrm->SetFmtAttr( aSet ); + // also apply template to remove hard set attributes + pCurrWrtShell->SetFrmFmt( pFrm ); + pCurrWrtShell->EndAllAction(); + } + } + break; + case SFX_STYLE_FAMILY_CHAR: + { + SwCharFmt* pChar = pStyle->GetCharFmt(); + if(pChar && !pChar->IsDefault()) + { + pCurrWrtShell->StartAllAction(); + pCurrWrtShell->FillByEx( pChar ); + pChar->SetDerivedFrom( pCurrWrtShell->GetCurCharFmt() ); + SwFmtCharFmt aFmt( pChar ); + pCurrWrtShell->SetAttrItem( aFmt ); + pCurrWrtShell->EndAllAction(); + } + } + break; + + case SFX_STYLE_FAMILY_PAGE: + { + pCurrWrtShell->StartAllAction(); + sal_uInt16 nPgDsc = pCurrWrtShell->GetCurPageDesc(); + SwPageDesc& rSrc = (SwPageDesc&)pCurrWrtShell->GetPageDesc( nPgDsc ); + SwPageDesc& rDest = *(SwPageDesc*)pStyle->GetPageDesc(); + + sal_uInt16 nPoolId = rDest.GetPoolFmtId(); + sal_uInt16 nHId = rDest.GetPoolHelpId(); + sal_uInt8 nHFId = rDest.GetPoolHlpFileId(); + + pCurrWrtShell->GetDoc()->CopyPageDesc( rSrc, rDest ); + + // PoolId must NEVER be copied! + rDest.SetPoolFmtId( nPoolId ); + rDest.SetPoolHelpId( nHId ); + rDest.SetPoolHlpFileId( nHFId ); + + // when Headers/Footers are created, there is no Undo anymore! + pCurrWrtShell->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj(); + + pCurrWrtShell->EndAllAction(); + } + break; + + case SFX_STYLE_FAMILY_PSEUDO: + { + const SwNumRule* pCurRule = pCurrWrtShell->GetNumRuleAtCurrCrsrPos(); + + if (pCurRule) + { + pCurrWrtShell->StartAllAction(); + + SwNumRule aRule( *pCurRule ); + OUString sOrigRule( aRule.GetName() ); + // #i91400# + aRule.SetName( pStyle->GetNumRule()->GetName(), + *(pCurrWrtShell->GetDoc()) ); + pCurrWrtShell->ChgNumRuleFmts( aRule ); + + pCurrWrtShell->ReplaceNumRule( sOrigRule, aRule.GetName() ); + + pCurrWrtShell->EndAllAction(); + } + } + break; + } + return nFamily; +} + +void SwDocShell::LoadStyles( SfxObjectShell& rSource ) +{ + _LoadStyles(rSource, false); +} + +// bPreserveCurrentDocument determines whether SetFixFields() is called +// This call modifies the source document. This mustn't happen when the source +// is a document the user is working on. +// Calls of ::LoadStyles() normally use files especially loaded for the purpose +// of importing styles. +void SwDocShell::_LoadStyles( SfxObjectShell& rSource, bool bPreserveCurrentDocument ) +{ +/* [Description] + + This method is called by SFx if Styles have to be reloaded from a + document-template. Existing Styles should be overwritten by that. + That's why the document has to be reformatted. Therefore applications + will usually overload this method and call the baseclass' implementation + in their implementation. +*/ + // When the source is our document, we do the checking ourselves + // (much quicker and doesn't use the crutch StxStylePool). + if( rSource.ISA( SwDocShell )) + { + // in order for the Headers/Footers not to get the fixed content + // of the template, update all the Source's + // FixFields once. + if(!bPreserveCurrentDocument) + ((SwDocShell&)rSource).pDoc->SetFixFields(false, NULL); + if( pWrtShell ) + { + // rhbz#818557, fdo#58893: EndAllAction will call SelectShell(), + // which pushes a bunch of SfxShells that are not cleared + // (for unknown reasons) when closing the document, causing crash; + // setting bNoInterrupt appears to avoid the problem. + ::comphelper::FlagRestorationGuard g(bNoInterrupt, true); + pWrtShell->StartAllAction(); + pDoc->ReplaceStyles( *((SwDocShell&)rSource).pDoc ); + pWrtShell->EndAllAction(); + } + else + { + bool bModified = pDoc->IsModified(); + pDoc->ReplaceStyles( *((SwDocShell&)rSource).pDoc ); + if( !bModified && pDoc->IsModified() && !pView ) + { + // the View is created later, but overwrites the Modify-Flag. + // Undo doesn't work anymore anyways. + pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified(); + } + } + } + else + SfxObjectShell::LoadStyles( rSource ); +} + +void SwDocShell::FormatPage( + const OUString& rPage, + const OString& rPageId, + SwWrtShell& rActShell ) +{ + Edit( rPage, aEmptyOUStr, SFX_STYLE_FAMILY_PAGE, 0, false, rPageId, &rActShell); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx new file mode 100644 index 000000000000..4a6d6860093c --- /dev/null +++ b/sw/source/uibase/app/docstyle.cxx @@ -0,0 +1,2980 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <svl/smplhint.hxx> +#include <hintids.hxx> +#include <svl/itemiter.hxx> +#include <svl/eitem.hxx> +#include <unotools/syslocale.hxx> +#include <editeng/boxitem.hxx> +#include <editeng/numitem.hxx> +#include <editeng/lrspitem.hxx> +#include <fmtcol.hxx> +#include <uitool.hxx> +#include <swmodule.hxx> +#include <wrtsh.hxx> +#include <docsh.hxx> +#include <frmfmt.hxx> +#include <charfmt.hxx> +#include <poolfmt.hxx> +#include <pagedesc.hxx> +#include <docstyle.hxx> +#include <docary.hxx> +#include <ccoll.hxx> +#include <doc.hxx> +#include <IDocumentUndoRedo.hxx> +#include <cmdid.h> +#include <swstyle.h> +#include <app.hrc> +#include <paratr.hxx> +#include <SwStyleNameMapper.hxx> +#include <svl/cjkoptions.hxx> +#include <comphelper/processfactory.hxx> +#include <unotools/localedatawrapper.hxx> +#include <unotools/intlwrapper.hxx> +#include <numrule.hxx> +#include <fmthdft.hxx> +#include <svx/svxids.hrc> +#include <svx/xdef.hxx> +#include <SwRewriter.hxx> + +using namespace com::sun::star; + +// The Format names in the list of all names have the +// following family as their first character: + +#define cCHAR (sal_Unicode)'c' +#define cPARA (sal_Unicode)'p' +#define cFRAME (sal_Unicode)'f' +#define cPAGE (sal_Unicode)'g' +#define cNUMRULE (sal_Unicode)'n' + +// At the names' publication, this character is removed again and the +// family is newly generated. + +// In addition now there is the Bit bPhysical. In case this Bit is +// TRUE, the Pool-Formatnames are not being submitted. + +class SwImplShellAction +{ + SwWrtShell* pSh; + CurrShell* pCurrSh; +public: + SwImplShellAction( SwDoc& rDoc ); + ~SwImplShellAction(); +}; + +SwImplShellAction::SwImplShellAction( SwDoc& rDoc ) + : pCurrSh( 0 ) +{ + if( rDoc.GetDocShell() ) + pSh = rDoc.GetDocShell()->GetWrtShell(); + else + pSh = 0; + + if( pSh ) + { + pCurrSh = new CurrShell( pSh ); + pSh->StartAllAction(); + } +} + +SwImplShellAction::~SwImplShellAction() +{ + if( pCurrSh ) + { + pSh->EndAllAction(); + delete pCurrSh; + } +} + +// find/create SwCharFormate +// possibly fill Style +static SwCharFmt* lcl_FindCharFmt( SwDoc& rDoc, + const OUString& rName, + SwDocStyleSheet* pStyle = 0, + bool bCreate = true ) +{ + SwCharFmt* pFmt = 0; + if (!rName.isEmpty()) + { + pFmt = rDoc.FindCharFmtByName( rName ); + if( !pFmt && rName == SwStyleNameMapper::GetTextUINameArray()[ RES_POOLCOLL_STANDARD - + RES_POOLCOLL_TEXT_BEGIN ] ) + { + // Standard-Character template + pFmt = (SwCharFmt*)rDoc.GetDfltCharFmt(); + } + + if( !pFmt && bCreate ) + { // explore Pool + const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT); + if(nId != USHRT_MAX) + pFmt = rDoc.GetCharFmtFromPool(nId); + } + } + if(pStyle) + { + if(pFmt) + { + pStyle->SetPhysical(true); + SwFmt* p = pFmt->DerivedFrom(); + if( p && !p->IsDefault() ) + pStyle->PresetParent( p->GetName() ); + else + pStyle->PresetParent( OUString() ); + } + else + pStyle->SetPhysical(false); + } + return pFmt; +} + +// find/create ParaFormats +// fill Style +static SwTxtFmtColl* lcl_FindParaFmt( SwDoc& rDoc, + const OUString& rName, + SwDocStyleSheet* pStyle = 0, + bool bCreate = true ) +{ + SwTxtFmtColl* pColl = 0; + + if (!rName.isEmpty()) + { + pColl = rDoc.FindTxtFmtCollByName( rName ); + if( !pColl && bCreate ) + { // explore Pool + const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL); + if(nId != USHRT_MAX) + pColl = rDoc.GetTxtCollFromPool(nId); + } + } + + if(pStyle) + { + if(pColl) + { + pStyle->SetPhysical(true); + if( pColl->DerivedFrom() && !pColl->DerivedFrom()->IsDefault() ) + pStyle->PresetParent( pColl->DerivedFrom()->GetName() ); + else + pStyle->PresetParent( OUString() ); + + SwTxtFmtColl& rNext = pColl->GetNextTxtFmtColl(); + pStyle->PresetFollow(rNext.GetName()); + } + else + pStyle->SetPhysical(false); + } + return pColl; +} + +// Border formats +static SwFrmFmt* lcl_FindFrmFmt( SwDoc& rDoc, + const OUString& rName, + SwDocStyleSheet* pStyle = 0, + bool bCreate = true ) +{ + SwFrmFmt* pFmt = 0; + if( !rName.isEmpty() ) + { + pFmt = rDoc.FindFrmFmtByName( rName ); + if( !pFmt && bCreate ) + { // explore Pool + const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT); + if(nId != USHRT_MAX) + pFmt = rDoc.GetFrmFmtFromPool(nId); + } + } + + if(pStyle) + { + if(pFmt) + { + pStyle->SetPhysical(true); + if( pFmt->DerivedFrom() && !pFmt->DerivedFrom()->IsDefault() ) + pStyle->PresetParent( pFmt->DerivedFrom()->GetName() ); + else + pStyle->PresetParent( OUString() ); + } + else + pStyle->SetPhysical(false); + } + return pFmt; +} + +// Page descriptors +static const SwPageDesc* lcl_FindPageDesc( SwDoc& rDoc, + const OUString& rName, + SwDocStyleSheet* pStyle = 0, + bool bCreate = true ) +{ + const SwPageDesc* pDesc = 0; + + if (!rName.isEmpty()) + { + pDesc = rDoc.FindPageDescByName( rName ); + if( !pDesc && bCreate ) + { + sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC); + if(nId != USHRT_MAX) + pDesc = rDoc.GetPageDescFromPool(nId); + } + } + + if(pStyle) + { + if(pDesc) + { + pStyle->SetPhysical(true); + if(pDesc->GetFollow()) + pStyle->PresetFollow(pDesc->GetFollow()->GetName()); + else + pStyle->PresetParent( OUString() ); + } + else + pStyle->SetPhysical(false); + } + return pDesc; +} + +static const SwNumRule* lcl_FindNumRule( SwDoc& rDoc, + const OUString& rName, + SwDocStyleSheet* pStyle = 0, + bool bCreate = true ) +{ + const SwNumRule* pRule = 0; + + if (!rName.isEmpty()) + { + pRule = rDoc.FindNumRulePtr( rName ); + if( !pRule && bCreate ) + { + sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE); + if(nId != USHRT_MAX) + pRule = rDoc.GetNumRuleFromPool(nId); + } + } + + if(pStyle) + { + if(pRule) + { + pStyle->SetPhysical(true); + pStyle->PresetParent( OUString() ); + } + else + pStyle->SetPhysical(false); + } + return pRule; +} + +static sal_uInt16 lcl_FindName(const SwPoolFmtList& rLst, SfxStyleFamily eFam, + const OUString& rName) +{ + if(!rLst.empty()) + { + sal_Unicode cStyle(0); + switch( eFam ) + { + case SFX_STYLE_FAMILY_CHAR: + cStyle = cCHAR; + break; + case SFX_STYLE_FAMILY_PARA: + cStyle = cPARA; + break; + case SFX_STYLE_FAMILY_FRAME: + cStyle = cFRAME; + break; + case SFX_STYLE_FAMILY_PAGE: + cStyle = cPAGE; + break; + case SFX_STYLE_FAMILY_PSEUDO: + cStyle = cNUMRULE; + break; + default: + cStyle = ' '; + break; + } + const OUString sSrch = OUString(cStyle) + rName; + for(size_t i = 0; i < rLst.size(); ++i) + if(rLst[i] == sSrch) + return i; + } + return USHRT_MAX; +} + +// Add Strings to the list of templates +void SwPoolFmtList::Append( char cChar, const OUString& rStr ) +{ + const OUString aStr = OUString(cChar) + rStr; + for(std::vector<OUString>::const_iterator i = begin(); i != end(); ++i) + if(*i == aStr) + return; + push_back(aStr); +} + +// Erase the list completely +void SwPoolFmtList::Erase() +{ + clear(); +} + +// UI-sided implementation of StyleSheets +// uses the Core-Engine +SwDocStyleSheet::SwDocStyleSheet( SwDoc& rDocument, + const OUString& rName, + SwDocStyleSheetPool* _rPool, + SfxStyleFamily eFam, + sal_uInt16 _nMask) : + + SfxStyleSheetBase( rName, _rPool, eFam, _nMask ), + pCharFmt(0), + pColl(0), + pFrmFmt(0), + pDesc(0), + pNumRule(0), + + rDoc(rDocument), + aCoreSet(GetPool().GetPool(), //UUUU sorted by indices, one double removed + RES_CHRATR_BEGIN, RES_CHRATR_END - 1, // [1 + RES_PARATR_BEGIN, RES_PARATR_END - 1, // [60 + RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1, // [77 + RES_FRMATR_BEGIN, RES_FRMATR_END - 1, // [82 + RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1, // [143 + + //UUUU FillAttribute support + XATTR_FILL_FIRST, XATTR_FILL_LAST, // [1014 + + SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER, // [10023 + SID_ATTR_PAGE, SID_ATTR_PAGE_EXT1, // [10050 + SID_ATTR_PAGE_HEADERSET,SID_ATTR_PAGE_FOOTERSET, // [10058 + SID_ATTR_PARA_MODEL, SID_ATTR_PARA_MODEL, // [10065 + + //UUUU items to hand over XPropertyList things like + // XColorList, XHatchList, XGradientList and XBitmapList + // to the Area TabPage + SID_COLOR_TABLE, SID_BITMAP_LIST, // [10179 + + SID_SWREGISTER_COLLECTION, SID_SWREGISTER_COLLECTION, // [10451 + SID_ATTR_PARA_PAGENUM, SID_ATTR_PARA_PAGENUM, // [10457 + SID_SWREGISTER_MODE, SID_SWREGISTER_MODE, // [10467 + SID_PARA_BACKGRND_DESTINATION, SID_ATTR_BRUSH_CHAR, // [10590 + SID_ATTR_NUMBERING_RULE, SID_ATTR_NUMBERING_RULE, // [10855 + SID_ATTR_AUTO_STYLE_UPDATE, SID_ATTR_AUTO_STYLE_UPDATE, // [12065 + FN_PARAM_FTN_INFO, FN_PARAM_FTN_INFO, // [21123 + FN_COND_COLL, FN_COND_COLL, // [22401 + 0), + bPhysical(false) +{ + nHelpId = UCHAR_MAX; +} + +SwDocStyleSheet::SwDocStyleSheet( const SwDocStyleSheet& rOrg) : + SfxStyleSheetBase(rOrg), + pCharFmt(rOrg.pCharFmt), + pColl(rOrg.pColl), + pFrmFmt(rOrg.pFrmFmt), + pDesc(rOrg.pDesc), + pNumRule(rOrg.pNumRule), + rDoc(rOrg.rDoc), + aCoreSet(rOrg.aCoreSet), + bPhysical(rOrg.bPhysical) +{ +} + + SwDocStyleSheet::~SwDocStyleSheet() +{ +} + +void SwDocStyleSheet::Reset() +{ + aName = ""; + aFollow = ""; + aParent = ""; + SetPhysical(false); +} + +void SwDocStyleSheet::SetGrabBagItem(const uno::Any& rVal) +{ + bool bChg = false; + if (!bPhysical) + FillStyleSheet(FillPhysical); + + SwFmt* pFmt = 0; + switch (nFamily) + { + case SFX_STYLE_FAMILY_CHAR: + pFmt = rDoc.FindCharFmtByName(aName); + if (pFmt) + { + pFmt->SetGrabBagItem(rVal); + bChg = true; + } + break; + case SFX_STYLE_FAMILY_PARA: + pFmt = rDoc.FindTxtFmtCollByName(aName); + if (pFmt) + { + pFmt->SetGrabBagItem(rVal); + bChg = true; + } + break; + case SFX_STYLE_FAMILY_PSEUDO: + { + SwNumRule* pRule = rDoc.FindNumRulePtr(aName); + if (pRule) + { + pRule->SetGrabBagItem(rVal); + bChg = true; + } + } + break; + default: + break; + } + + if (bChg) + { + dynamic_cast<SwDocStyleSheetPool&>(*pPool).InvalidateIterator(); + pPool->Broadcast(SfxStyleSheetHint(SFX_STYLESHEET_MODIFIED, *this)); + SwEditShell* pSh = rDoc.GetEditShell(); + if (pSh) + pSh->CallChgLnk(); + } +} + +void SwDocStyleSheet::GetGrabBagItem(uno::Any& rVal) const +{ + SwFmt* pFmt = 0; + switch (nFamily) + { + case SFX_STYLE_FAMILY_CHAR: + pFmt = rDoc.FindCharFmtByName(aName); + if (pFmt) + pFmt->GetGrabBagItem(rVal); + break; + case SFX_STYLE_FAMILY_PARA: + pFmt = rDoc.FindTxtFmtCollByName(aName); + if (pFmt) + pFmt->GetGrabBagItem(rVal); + break; + case SFX_STYLE_FAMILY_PSEUDO: + { + SwNumRule* pRule = rDoc.FindNumRulePtr(aName); + if (pRule) + pRule->GetGrabBagItem(rVal); + } + break; + default: + break; + } +} +// virtual methods +void SwDocStyleSheet::SetHidden( bool bValue ) +{ + bool bChg = false; + if(!bPhysical) + FillStyleSheet( FillPhysical ); + + SwFmt* pFmt = 0; + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR: + pFmt = rDoc.FindCharFmtByName( aName ); + if ( pFmt ) + { + pFmt->SetHidden( bValue ); + bChg = true; + } + break; + + case SFX_STYLE_FAMILY_PARA: + pFmt = rDoc.FindTxtFmtCollByName( aName ); + if ( pFmt ) + { + pFmt->SetHidden( bValue ); + bChg = true; + } + break; + + case SFX_STYLE_FAMILY_FRAME: + pFmt = rDoc.FindFrmFmtByName( aName ); + if ( pFmt ) + { + pFmt->SetHidden( bValue ); + bChg = true; + } + break; + + case SFX_STYLE_FAMILY_PAGE: + { + SwPageDesc* pPgDesc = rDoc.FindPageDescByName( aName ); + if ( pPgDesc ) + { + pPgDesc->SetHidden( bValue ); + bChg = true; + } + } + break; + + case SFX_STYLE_FAMILY_PSEUDO: + { + SwNumRule* pRule = rDoc.FindNumRulePtr( aName ); + if ( pRule ) + { + pRule->SetHidden( bValue ); + bChg = true; + } + } + default:; + } + + if( bChg ) + { + // calling pPool->First() here would be quite slow... + dynamic_cast<SwDocStyleSheetPool&>(*pPool).InvalidateIterator(); // internal list has to be updated + pPool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) ); + SwEditShell* pSh = rDoc.GetEditShell(); + if( pSh ) + pSh->CallChgLnk(); + } +} + +bool SwDocStyleSheet::IsHidden( ) const +{ + bool bRet = false; + + SwFmt* pFmt = 0; + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR: + pFmt = rDoc.FindCharFmtByName( aName ); + bRet = pFmt && pFmt->IsHidden( ); + break; + + case SFX_STYLE_FAMILY_PARA: + pFmt = rDoc.FindTxtFmtCollByName( aName ); + bRet = pFmt && pFmt->IsHidden( ); + break; + + case SFX_STYLE_FAMILY_FRAME: + pFmt = rDoc.FindFrmFmtByName( aName ); + bRet = pFmt && pFmt->IsHidden( ); + break; + + case SFX_STYLE_FAMILY_PAGE: + { + SwPageDesc* pPgDesc = rDoc.FindPageDescByName( aName ); + bRet = pPgDesc && pPgDesc->IsHidden( ); + } + break; + case SFX_STYLE_FAMILY_PSEUDO: + { + SwNumRule* pRule = rDoc.FindNumRulePtr( aName ); + bRet = pRule && pRule->IsHidden( ); + } + default:; + } + + return bRet; +} + +const OUString& SwDocStyleSheet::GetParent() const +{ + if( !bPhysical ) + { + // check if it's already in document + SwFmt* pFmt = 0; + SwGetPoolIdFromName eGetType; + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR: + pFmt = rDoc.FindCharFmtByName( aName ); + eGetType = nsSwGetPoolIdFromName::GET_POOLID_CHRFMT; + break; + + case SFX_STYLE_FAMILY_PARA: + pFmt = rDoc.FindTxtFmtCollByName( aName ); + eGetType = nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL; + break; + + case SFX_STYLE_FAMILY_FRAME: + pFmt = rDoc.FindFrmFmtByName( aName ); + eGetType = nsSwGetPoolIdFromName::GET_POOLID_FRMFMT; + break; + + case SFX_STYLE_FAMILY_PAGE: + case SFX_STYLE_FAMILY_PSEUDO: + default: + return aEmptyOUStr; // there's no parent + } + + OUString sTmp; + if( !pFmt ) // not yet there, so default Parent + { + sal_uInt16 i = SwStyleNameMapper::GetPoolIdFromUIName( aName, eGetType ); + i = ::GetPoolParent( i ); + if( i && USHRT_MAX != i ) + SwStyleNameMapper::FillUIName( i, sTmp ); + } + else + { + SwFmt* p = pFmt->DerivedFrom(); + if( p && !p->IsDefault() ) + sTmp = p->GetName(); + } + SwDocStyleSheet* pThis = (SwDocStyleSheet*)this; + pThis->aParent = sTmp; + } + return aParent; +} + +// Follower +const OUString& SwDocStyleSheet::GetFollow() const +{ + if( !bPhysical ) + { + SwDocStyleSheet* pThis = (SwDocStyleSheet*)this; + pThis->FillStyleSheet( FillAllInfo ); + } + return aFollow; +} + +// What Linkage is possible +bool SwDocStyleSheet::HasFollowSupport() const +{ + switch(nFamily) + { + case SFX_STYLE_FAMILY_PARA : + case SFX_STYLE_FAMILY_PAGE : return true; + case SFX_STYLE_FAMILY_FRAME: + case SFX_STYLE_FAMILY_CHAR : + case SFX_STYLE_FAMILY_PSEUDO: return false; + default: + OSL_ENSURE(!this, "unknown style family"); + } + return false; +} + +// Parent ? +bool SwDocStyleSheet::HasParentSupport() const +{ + bool bRet = false; + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR : + case SFX_STYLE_FAMILY_PARA : + case SFX_STYLE_FAMILY_FRAME: bRet = true; + default:; //prevent warning + } + return bRet; +} + +bool SwDocStyleSheet::HasClearParentSupport() const +{ + bool bRet = false; + switch(nFamily) + { + case SFX_STYLE_FAMILY_PARA : + case SFX_STYLE_FAMILY_CHAR : + case SFX_STYLE_FAMILY_FRAME: bRet = true; + default:; //prevent warning + } + return bRet; +} + +// determine textual description +OUString SwDocStyleSheet::GetDescription(SfxMapUnit eUnit) +{ + IntlWrapper aIntlWrapper( SvtSysLocale().GetLanguageTag() ); + + const OUString sPlus(" + "); + if ( SFX_STYLE_FAMILY_PAGE == nFamily ) + { + if( !pSet ) + GetItemSet(); + + SfxItemIter aIter( *pSet ); + OUString aDesc; + + for (const SfxPoolItem* pItem = aIter.FirstItem(); pItem; pItem = aIter.NextItem()) + { + if(!IsInvalidItem(pItem)) + { + switch ( pItem->Which() ) + { + case RES_LR_SPACE: + case SID_ATTR_PAGE_SIZE: + case SID_ATTR_PAGE_MAXSIZE: + case SID_ATTR_PAGE_PAPERBIN: + case SID_ATTR_PAGE_APP: + case SID_ATTR_BORDER_INNER: + break; + default: + { + OUString aItemPresentation; + if ( !IsInvalidItem( pItem ) && + pPool->GetPool().GetPresentation( + *pItem, SFX_ITEM_PRESENTATION_COMPLETE, + eUnit, aItemPresentation, &aIntlWrapper ) ) + { + if ( !aDesc.isEmpty() && !aItemPresentation.isEmpty() ) + aDesc += sPlus; + aDesc += aItemPresentation; + } + } + } + } + } + return aDesc; + } + + if ( SFX_STYLE_FAMILY_FRAME == nFamily || SFX_STYLE_FAMILY_PARA == nFamily) + { + if( !pSet ) + GetItemSet(); + + SfxItemIter aIter( *pSet ); + OUString aDesc; + OUString sPageNum; + OUString sModel; + OUString sBreak; + bool bHasWesternFontPrefix = false; + bool bHasCJKFontPrefix = false; + SvtCJKOptions aCJKOptions; + + for ( const SfxPoolItem* pItem = aIter.FirstItem(); pItem; pItem = aIter.NextItem() ) + { + if(!IsInvalidItem(pItem)) + { + switch ( pItem->Which() ) + { + case SID_ATTR_AUTO_STYLE_UPDATE: + case SID_PARA_BACKGRND_DESTINATION: + case RES_PAGEDESC: + //CTL not yet supported + case RES_CHRATR_CTL_FONT: + case RES_CHRATR_CTL_FONTSIZE: + case RES_CHRATR_CTL_LANGUAGE: + case RES_CHRATR_CTL_POSTURE: + case RES_CHRATR_CTL_WEIGHT: + break; + default: + { + OUString aItemPresentation; + if ( !IsInvalidItem( pItem ) && + pPool->GetPool().GetPresentation( + *pItem, SFX_ITEM_PRESENTATION_COMPLETE, + eUnit, aItemPresentation, &aIntlWrapper ) ) + { + bool bIsDefault = false; + switch ( pItem->Which() ) + { + case SID_ATTR_PARA_PAGENUM: + sPageNum = aItemPresentation; + break; + case SID_ATTR_PARA_MODEL: + sModel = aItemPresentation; + break; + case RES_BREAK: + sBreak = aItemPresentation; + break; + case RES_CHRATR_CJK_FONT: + case RES_CHRATR_CJK_FONTSIZE: + case RES_CHRATR_CJK_LANGUAGE: + case RES_CHRATR_CJK_POSTURE: + case RES_CHRATR_CJK_WEIGHT: + if(aCJKOptions.IsCJKFontEnabled()) + bIsDefault = true; + if(!bHasCJKFontPrefix) + { + aItemPresentation = SW_RESSTR(STR_CJK_FONT) + aItemPresentation; + bHasCJKFontPrefix = true; + } + break; + case RES_CHRATR_FONT: + case RES_CHRATR_FONTSIZE: + case RES_CHRATR_LANGUAGE: + case RES_CHRATR_POSTURE: + case RES_CHRATR_WEIGHT: + if(!bHasWesternFontPrefix) + { + aItemPresentation = SW_RESSTR(STR_WESTERN_FONT) + aItemPresentation; + bHasWesternFontPrefix = true; + bIsDefault = true; + } + // no break; + default: + bIsDefault = true; + } + if(bIsDefault) + { + if ( !aDesc.isEmpty() && !aItemPresentation.isEmpty() ) + aDesc += sPlus; + aDesc += aItemPresentation; + } + } + } + } + } + } + // Special treatment for Break, Page template and Site offset + if (!sModel.isEmpty()) + { + if (!aDesc.isEmpty()) + aDesc += sPlus; + aDesc += SW_RESSTR(STR_PAGEBREAK) + sPlus + sModel; + if (sPageNum != "0") + { + aDesc += sPlus + SW_RESSTR(STR_PAGEOFFSET) + sPageNum; + } + } + else if (!sBreak.isEmpty()) // Break can be valid only when NO Model + { + if (!aDesc.isEmpty()) + aDesc += sPlus; + aDesc += sBreak; + } + return aDesc; + } + + if( SFX_STYLE_FAMILY_PSEUDO == nFamily ) + { + return OUString(); + } + + return SfxStyleSheetBase::GetDescription(eUnit); +} + +OUString SwDocStyleSheet::GetDescription() +{ + return GetDescription(SFX_MAPUNIT_CM); +} + +// Set names +bool SwDocStyleSheet::SetName( const OUString& rStr) +{ + if( rStr.isEmpty() ) + return false; + + if( aName != rStr ) + { + if( !SfxStyleSheetBase::SetName( rStr )) + return false; + } + else if(!bPhysical) + FillStyleSheet( FillPhysical ); + + bool bChg = false; + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR : + { + OSL_ENSURE(pCharFmt, "SwCharFormat missing!"); + if( pCharFmt && pCharFmt->GetName() != rStr ) + { + pCharFmt->SetName( rStr ); + bChg = true; + } + break; + } + case SFX_STYLE_FAMILY_PARA : + { + OSL_ENSURE(pColl, "Collection missing!"); + if( pColl && pColl->GetName() != rStr ) + { + if (!pColl->GetName().isEmpty()) + rDoc.RenameFmt(*pColl, rStr); + else + pColl->SetName(rStr); + + bChg = true; + } + break; + } + case SFX_STYLE_FAMILY_FRAME: + { + OSL_ENSURE(pFrmFmt, "FrmFmt missing!"); + if( pFrmFmt && pFrmFmt->GetName() != rStr ) + { + if (!pFrmFmt->GetName().isEmpty()) + rDoc.RenameFmt(*pFrmFmt, rStr); + else + pFrmFmt->SetName( rStr ); + + bChg = true; + } + break; + } + case SFX_STYLE_FAMILY_PAGE : + OSL_ENSURE(pDesc, "PageDesc missing!"); + if( pDesc && pDesc->GetName() != rStr ) + { + // Set PageDesc - copy with earlier one - probably not + // necessary for setting the name. So here we allow a + // cast. + SwPageDesc aPageDesc(*((SwPageDesc*)pDesc)); + const OUString aOldName(aPageDesc.GetName()); + + aPageDesc.SetName( rStr ); + bool const bDoesUndo = rDoc.GetIDocumentUndoRedo().DoesUndo(); + + rDoc.GetIDocumentUndoRedo().DoUndo(!aOldName.isEmpty()); + rDoc.ChgPageDesc(aOldName, aPageDesc); + rDoc.GetIDocumentUndoRedo().DoUndo(bDoesUndo); + + rDoc.SetModified(); + bChg = true; + } + break; + case SFX_STYLE_FAMILY_PSEUDO: + OSL_ENSURE(pNumRule, "NumRule missing!"); + + if (pNumRule) + { + OUString aOldName = pNumRule->GetName(); + + if (!aOldName.isEmpty()) + { + if ( aOldName != rStr && + rDoc.RenameNumRule(aOldName, rStr)) + { + pNumRule = rDoc.FindNumRulePtr(rStr); + rDoc.SetModified(); + + bChg = true; + } + } + else + { + // #i91400# + ((SwNumRule*)pNumRule)->SetName( rStr, rDoc ); + rDoc.SetModified(); + + bChg = true; + } + } + + break; + + default: + OSL_ENSURE(!this, "unknown style family"); + } + + if( bChg ) + { + pPool->First(); // internal list has to be updated + pPool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) ); + SwEditShell* pSh = rDoc.GetEditShell(); + if( pSh ) + pSh->CallChgLnk(); + } + return true; +} + +// hierarchy of deduction +bool SwDocStyleSheet::SetParent( const OUString& rStr) +{ + SwFmt* pFmt = 0, *pParent = 0; + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR : + OSL_ENSURE( pCharFmt, "SwCharFormat missing!" ); + if( 0 != ( pFmt = pCharFmt ) && !rStr.isEmpty() ) + pParent = lcl_FindCharFmt(rDoc, rStr); + break; + + case SFX_STYLE_FAMILY_PARA : + OSL_ENSURE( pColl, "Collektion missing!"); + if( 0 != ( pFmt = pColl ) && !rStr.isEmpty() ) + pParent = lcl_FindParaFmt( rDoc, rStr ); + break; + + case SFX_STYLE_FAMILY_FRAME: + OSL_ENSURE(pFrmFmt, "FrameFormat missing!"); + if( 0 != ( pFmt = pFrmFmt ) && !rStr.isEmpty() ) + pParent = lcl_FindFrmFmt( rDoc, rStr ); + break; + + case SFX_STYLE_FAMILY_PAGE: + case SFX_STYLE_FAMILY_PSEUDO: + break; + default: + OSL_ENSURE(!this, "unknown style family"); + } + + bool bRet = false; + if( pFmt && pFmt->DerivedFrom() && + pFmt->DerivedFrom()->GetName() != rStr ) + { + { + SwImplShellAction aTmp( rDoc ); + bRet = pFmt->SetDerivedFrom( pParent ); + } + + if( bRet ) + { + aParent = rStr; + pPool->Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, + *this ) ); + } + } + + return bRet; +} + +// Set Follower +bool SwDocStyleSheet::SetFollow( const OUString& rStr) +{ + if( !rStr.isEmpty() && !SfxStyleSheetBase::SetFollow( rStr )) + return false; + + SwImplShellAction aTmpSh( rDoc ); + switch(nFamily) + { + case SFX_STYLE_FAMILY_PARA : + { + OSL_ENSURE(pColl, "Collection missing!"); + if( pColl ) + { + SwTxtFmtColl* pFollow = pColl; + if( !rStr.isEmpty() && 0 == (pFollow = lcl_FindParaFmt(rDoc, rStr) )) + pFollow = pColl; + + pColl->SetNextTxtFmtColl(*pFollow); + } + break; + } + case SFX_STYLE_FAMILY_PAGE : + { + OSL_ENSURE(pDesc, "PageDesc missing!"); + if( pDesc ) + { + const SwPageDesc* pFollowDesc = !rStr.isEmpty() + ? lcl_FindPageDesc(rDoc, rStr) + : 0; + sal_uInt16 nId = 0; + if( pFollowDesc != pDesc->GetFollow() && + rDoc.FindPageDescByName( pDesc->GetName(), &nId ) ) + { + SwPageDesc aDesc( *pDesc ); + aDesc.SetFollow( pFollowDesc ); + rDoc.ChgPageDesc( nId, aDesc ); + pDesc = &rDoc.GetPageDesc( nId ); + } + } + break; + } + case SFX_STYLE_FAMILY_CHAR: + case SFX_STYLE_FAMILY_FRAME: + case SFX_STYLE_FAMILY_PSEUDO: + break; + default: + OSL_ENSURE(!this, "unknwown style family"); + } + + return true; +} + +// extract ItemSet to Name and Family, Mask + +//UUUU +#include <svx/svdmodel.hxx> +#include <svx/drawitem.hxx> + +SfxItemSet& SwDocStyleSheet::GetItemSet() +{ + if(!bPhysical) + FillStyleSheet( FillPhysical ); + + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR: + case SFX_STYLE_FAMILY_PARA: + case SFX_STYLE_FAMILY_FRAME: + { + SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER ); + aBoxInfo.SetTable( false ); + aBoxInfo.SetDist( true ); // always show gap field + aBoxInfo.SetMinDist( true );// set minimum size in tables and paragraphs + aBoxInfo.SetDefDist( MIN_BORDER_DIST );// always set Default-Gap + // Single lines can only have DontCare-Status in tables + aBoxInfo.SetValid( VALID_DISABLE, true ); + + if( nFamily == SFX_STYLE_FAMILY_CHAR ) + { + SAL_WARN_IF(!pCharFmt, "sw.ui", "Where's SwCharFmt"); + aCoreSet.Put(pCharFmt->GetAttrSet()); + aCoreSet.Put( aBoxInfo ); + + if(pCharFmt->DerivedFrom()) + aCoreSet.SetParent(&pCharFmt->DerivedFrom()->GetAttrSet()); + } + else if ( nFamily == SFX_STYLE_FAMILY_PARA ) + { + OSL_ENSURE(pColl, "Where's Collection"); + aCoreSet.Put(pColl->GetAttrSet()); + aCoreSet.Put( aBoxInfo ); + aCoreSet.Put(SfxBoolItem(SID_ATTR_AUTO_STYLE_UPDATE, pColl->IsAutoUpdateFmt())); + + if(pColl->DerivedFrom()) + aCoreSet.SetParent(&pColl->DerivedFrom()->GetAttrSet()); + } + else + { + OSL_ENSURE(pFrmFmt, "Where's FrmFmt"); + aCoreSet.Put(pFrmFmt->GetAttrSet()); + aCoreSet.Put( aBoxInfo ); + aCoreSet.Put(SfxBoolItem(SID_ATTR_AUTO_STYLE_UPDATE, pFrmFmt->IsAutoUpdateFmt())); + + if(pFrmFmt->DerivedFrom()) + aCoreSet.SetParent(&pFrmFmt->DerivedFrom()->GetAttrSet()); + + //UUUU create needed items for XPropertyList entries from the DrawModel so that + // the Area TabPage can access them + const SdrModel* pDrawModel = rDoc.GetDrawModel(); + + aCoreSet.Put(SvxColorListItem(pDrawModel->GetColorList(), SID_COLOR_TABLE)); + aCoreSet.Put(SvxGradientListItem(pDrawModel->GetGradientList(), SID_GRADIENT_LIST)); + aCoreSet.Put(SvxHatchListItem(pDrawModel->GetHatchList(), SID_HATCH_LIST)); + aCoreSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapList(), SID_BITMAP_LIST)); + } + } + break; + + case SFX_STYLE_FAMILY_PAGE : + { + OSL_ENSURE(pDesc, "No PageDescriptor"); + ::PageDescToItemSet(*((SwPageDesc*)pDesc), aCoreSet); + } + break; + + case SFX_STYLE_FAMILY_PSEUDO: + { + OSL_ENSURE(pNumRule, "No NumRule"); + SvxNumRule aRule = pNumRule->MakeSvxNumRule(); + aCoreSet.Put(SvxNumBulletItem(aRule)); + } + break; + + default: + OSL_ENSURE(!this, "unknown style family"); + } + // Member of Baseclass + pSet = &aCoreSet; + + return aCoreSet; +} + +void SwDocStyleSheet::MergeIndentAttrsOfListStyle( SfxItemSet& rSet ) +{ + if ( nFamily != SFX_STYLE_FAMILY_PARA ) + { + return; + } + + OSL_ENSURE( pColl, "<SwDocStyleSheet::MergeIndentAttrsOfListStyle(..)> - missing paragraph style"); + if ( pColl->AreListLevelIndentsApplicable() ) + { + OSL_ENSURE( pColl->GetItemState( RES_PARATR_NUMRULE ) == SFX_ITEM_SET, + "<SwDocStyleSheet::MergeIndentAttrsOfListStyle(..)> - list level indents are applicable at paragraph style, but no list style found. Serious defect -> please inform OD." ); + const OUString sNumRule = pColl->GetNumRule().GetValue(); + if (!sNumRule.isEmpty()) + { + const SwNumRule* pRule = rDoc.FindNumRulePtr( sNumRule ); + if( pRule ) + { + const SwNumFmt& rFmt = pRule->Get( 0 ); + if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) + { + SvxLRSpaceItem aLR( RES_LR_SPACE ); + aLR.SetTxtLeft( rFmt.GetIndentAt() ); + aLR.SetTxtFirstLineOfst( static_cast<short>(rFmt.GetFirstLineIndent()) ); + rSet.Put( aLR ); + } + } + } + } +} + +// handling of parameter <bResetIndentAttrsAtParagraphStyle> +void SwDocStyleSheet::SetItemSet( const SfxItemSet& rSet, + const bool bResetIndentAttrsAtParagraphStyle ) +{ + // if applicable determine format first + if(!bPhysical) + FillStyleSheet( FillPhysical ); + + SwImplShellAction aTmpSh( rDoc ); + + OSL_ENSURE( &rSet != &aCoreSet, "SetItemSet with own Set is not allowed" ); + + if (rDoc.GetIDocumentUndoRedo().DoesUndo()) + { + SwRewriter aRewriter; + aRewriter.AddRule( UndoArg1, GetName() ); + rDoc.GetIDocumentUndoRedo().StartUndo( UNDO_INSFMTATTR, &aRewriter ); + } + + SwFmt* pFmt = 0; + SwPageDesc* pNewDsc = 0; + sal_uInt16 nPgDscPos = 0; + + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR : + { + OSL_ENSURE(pCharFmt, "Where's CharFormat"); + pFmt = pCharFmt; + } + break; + + case SFX_STYLE_FAMILY_PARA : + { + OSL_ENSURE(pColl, "Where's Collection"); + const SfxPoolItem* pAutoUpdate; + if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_AUTO_STYLE_UPDATE,false, &pAutoUpdate )) + { + pColl->SetAutoUpdateFmt(((const SfxBoolItem*)pAutoUpdate)->GetValue()); + } + + const SwCondCollItem* pCondItem; + if( SFX_ITEM_SET != rSet.GetItemState( FN_COND_COLL, false, + (const SfxPoolItem**)&pCondItem )) + pCondItem = 0; + + if( RES_CONDTXTFMTCOLL == pColl->Which() && pCondItem ) + { + const CommandStruct* pCmds = SwCondCollItem::GetCmds(); + for(sal_uInt16 i = 0; i < COND_COMMAND_COUNT; i++) + { + SwCollCondition aCond( 0, pCmds[ i ].nCnd, pCmds[ i ].nSubCond ); + ((SwConditionTxtFmtColl*)pColl)->RemoveCondition( aCond ); + const OUString sStyle = pCondItem->GetStyle( i ); + if (sStyle.isEmpty()) + continue; + SwFmt *const pFindFmt = lcl_FindParaFmt( rDoc, sStyle, 0, true ); + if (pFindFmt) + { + aCond.RegisterToFormat( *pFindFmt ); + ((SwConditionTxtFmtColl*)pColl)->InsertCondition( aCond ); + } + } + + // Update document to new conditions + SwCondCollCondChg aMsg( pColl ); + pColl->ModifyNotification( &aMsg, &aMsg ); + } + else if( pCondItem && !pColl->GetDepends() ) + { + // no conditional template, then first create and adopt + // all important values + SwConditionTxtFmtColl* pCColl = rDoc.MakeCondTxtFmtColl( + pColl->GetName(), (SwTxtFmtColl*)pColl->DerivedFrom() ); + if( pColl != &pColl->GetNextTxtFmtColl() ) + pCColl->SetNextTxtFmtColl( pColl->GetNextTxtFmtColl() ); + + if( pColl->IsAssignedToListLevelOfOutlineStyle()) + pCColl->AssignToListLevelOfOutlineStyle(pColl->GetAssignedOutlineStyleLevel()); + else + pCColl->DeleteAssignmentToListLevelOfOutlineStyle(); + + const CommandStruct* pCmds = SwCondCollItem::GetCmds(); + for( sal_uInt16 i = 0; i < COND_COMMAND_COUNT; ++i ) + { + const OUString sStyle = pCondItem->GetStyle( i ); + if (sStyle.isEmpty()) + continue; + SwTxtFmtColl *const pFindFmt = lcl_FindParaFmt( rDoc, sStyle, 0, true ); + if (pFindFmt) + { + pCColl->InsertCondition( SwCollCondition( pFindFmt, + pCmds[ i ].nCnd, pCmds[ i ].nSubCond ) ); + } + } + + rDoc.DelTxtFmtColl( pColl ); + pColl = pCColl; + } + if ( bResetIndentAttrsAtParagraphStyle && + rSet.GetItemState( RES_PARATR_NUMRULE, false, 0 ) == SFX_ITEM_SET && + rSet.GetItemState( RES_LR_SPACE, false, 0 ) != SFX_ITEM_SET && + pColl->GetItemState( RES_LR_SPACE, false, 0 ) == SFX_ITEM_SET ) + { + rDoc.ResetAttrAtFormat( RES_LR_SPACE, *pColl ); + } + + // #i56252: If a standard numbering style is assigned to a standard paragraph style + // we have to create a physical instance of the numbering style. If we do not and + // neither the paragraph style nor the numbering style is used in the document + // the numbering style will not be saved with the document and the assignment got lost. + const SfxPoolItem* pNumRuleItem = 0; + if( SFX_ITEM_SET == rSet.GetItemState( RES_PARATR_NUMRULE, false, &pNumRuleItem ) ) + { // Setting a numbering rule? + const OUString sNumRule = ((SwNumRuleItem*)pNumRuleItem)->GetValue(); + if (!sNumRule.isEmpty()) + { + SwNumRule* pRule = rDoc.FindNumRulePtr( sNumRule ); + if( !pRule ) + { // Numbering rule not in use yet. + sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( sNumRule, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE ); + if( USHRT_MAX != nPoolId ) // It's a standard numbering rule + { + rDoc.GetNumRuleFromPool( nPoolId ); // Create numbering rule (physical) + } + } + } + } + + pFmt = pColl; + + sal_uInt16 nId = pColl->GetPoolFmtId() & + ~ ( COLL_GET_RANGE_BITS | POOLGRP_NOCOLLID ); + switch( GetMask() & ( 0x0fff & ~SWSTYLEBIT_CONDCOLL ) ) + { + case SWSTYLEBIT_TEXT: + nId |= COLL_TEXT_BITS; + break; + case SWSTYLEBIT_CHAPTER: + nId |= COLL_DOC_BITS; + break; + case SWSTYLEBIT_LIST: + nId |= COLL_LISTS_BITS; + break; + case SWSTYLEBIT_IDX: + nId |= COLL_REGISTER_BITS; + break; + case SWSTYLEBIT_EXTRA: + nId |= COLL_EXTRA_BITS; + break; + case SWSTYLEBIT_HTML: + nId |= COLL_HTML_BITS; + break; + } + pColl->SetPoolFmtId( nId ); + break; + } + case SFX_STYLE_FAMILY_FRAME: + { + OSL_ENSURE(pFrmFmt, "Where's FrmFmt"); + const SfxPoolItem* pAutoUpdate; + if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_AUTO_STYLE_UPDATE,false, &pAutoUpdate )) + { + pFrmFmt->SetAutoUpdateFmt(((const SfxBoolItem*)pAutoUpdate)->GetValue()); + } + pFmt = pFrmFmt; + } + break; + + case SFX_STYLE_FAMILY_PAGE : + { + OSL_ENSURE(pDesc, "Where's PageDescriptor"); + + if( rDoc.FindPageDescByName( pDesc->GetName(), &nPgDscPos )) + { + pNewDsc = new SwPageDesc( *pDesc ); + // #i48949# - no undo actions for the + // copy of the page style + ::sw::UndoGuard const ug(rDoc.GetIDocumentUndoRedo()); + rDoc.CopyPageDesc(*pDesc, *pNewDsc); // #i7983# + + pFmt = &pNewDsc->GetMaster(); + } + } + break; + + case SFX_STYLE_FAMILY_PSEUDO: + { + OSL_ENSURE(pNumRule, "Where's NumRule"); + + if (!pNumRule) + break; + + const SfxPoolItem* pItem; + switch( rSet.GetItemState( SID_ATTR_NUMBERING_RULE, false, &pItem )) + { + case SFX_ITEM_SET: + { + SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule(); + pSetRule->UnLinkGraphics(); + SwNumRule aSetRule(*pNumRule); + aSetRule.SetSvxRule(*pSetRule, &rDoc); + rDoc.ChgNumRuleFmts( aSetRule ); + } + break; + case SFX_ITEM_DONTCARE: + // set NumRule to default values + // what are the default values? + { + SwNumRule aRule( pNumRule->GetName(), + // #i89178# + numfunc::GetDefaultPositionAndSpaceMode() ); + rDoc.ChgNumRuleFmts( aRule ); + } + break; + } + } + break; + + default: + OSL_ENSURE(!this, "unknown style family"); + } + + if( pFmt && rSet.Count()) + { + SfxItemIter aIter( rSet ); + const SfxPoolItem* pItem = aIter.GetCurItem(); + while( true ) + { + if( IsInvalidItem( pItem ) ) // Clear + { + // use method <SwDoc::ResetAttrAtFormat(..)> in order to + // create an Undo object for the attribute reset. + rDoc.ResetAttrAtFormat( rSet.GetWhichByPos(aIter.GetCurPos()), + *pFmt ); + } + + if( aIter.IsAtEnd() ) + break; + pItem = aIter.NextItem(); + } + SfxItemSet aSet(rSet); + aSet.ClearInvalidItems(); + + if(SFX_STYLE_FAMILY_FRAME == nFamily) + { + //UUUU Need to check for unique item for DrawingLayer items of type NameOrIndex + // and evtl. correct that item to ensure unique names for that type. This call may + // modify/correct entries inside of the given SfxItemSet + rDoc.CheckForUniqueItemForLineFillNameOrIndex(aSet); + } + + aCoreSet.ClearItem(); + + if( pNewDsc ) + { + ::ItemSetToPageDesc( aSet, *pNewDsc ); + rDoc.ChgPageDesc( nPgDscPos, *pNewDsc ); + pDesc = &rDoc.GetPageDesc( nPgDscPos ); + rDoc.PreDelPageDesc(pNewDsc); // #i7983# + delete pNewDsc; + } + else + rDoc.ChgFmt(*pFmt, aSet); // put all that is set + } + else + { + aCoreSet.ClearItem(); + if( pNewDsc ) // we still need to delete it + { + rDoc.PreDelPageDesc(pNewDsc); // #i7983# + delete pNewDsc; + } + } + + if (rDoc.GetIDocumentUndoRedo().DoesUndo()) + { + rDoc.GetIDocumentUndoRedo().EndUndo(UNDO_END, 0); + } +} + +static void lcl_SaveStyles( sal_uInt16 nFamily, std::vector<void*>& rArr, SwDoc& rDoc ) +{ + switch( nFamily ) + { + case SFX_STYLE_FAMILY_CHAR: + { + const SwCharFmts& rTbl = *rDoc.GetCharFmts(); + for( sal_uInt16 n = 0, nCnt = rTbl.size(); n < nCnt; ++n ) + { + rArr.push_back( rTbl[ n ] ); + } + } + break; + case SFX_STYLE_FAMILY_PARA: + { + const SwTxtFmtColls& rTbl = *rDoc.GetTxtFmtColls(); + for( sal_uInt16 n = 0, nCnt = rTbl.size(); n < nCnt; ++n ) + { + rArr.push_back( rTbl[ n ] ); + } + } + break; + case SFX_STYLE_FAMILY_FRAME: + { + const SwFrmFmts& rTbl = *rDoc.GetFrmFmts(); + for( sal_uInt16 n = 0, nCnt = rTbl.size(); n < nCnt; ++n ) + { + rArr.push_back( rTbl[ n ] ); + } + } + break; + + case SFX_STYLE_FAMILY_PAGE: + { + for( sal_uInt16 n = 0, nCnt = rDoc.GetPageDescCnt(); n < nCnt; ++n ) + { + rArr.push_back( &rDoc.GetPageDesc( n ) ); + } + } + break; + + case SFX_STYLE_FAMILY_PSEUDO: + { + const SwNumRuleTbl& rTbl = rDoc.GetNumRuleTbl(); + for( sal_uInt16 n = 0, nCnt = rTbl.size(); n < nCnt; ++n ) + { + rArr.push_back( rTbl[ n ] ); + } + } + break; + } +} + +static bool lcl_Contains(const std::vector<void*>& rArr, const void* p) +{ + return std::find( rArr.begin(), rArr.end(), p ) != rArr.end(); +} + +static void lcl_DeleteInfoStyles( sal_uInt16 nFamily, std::vector<void*>& rArr, SwDoc& rDoc ) +{ + sal_uInt16 n, nCnt; + switch( nFamily ) + { + case SFX_STYLE_FAMILY_CHAR: + { + std::deque<sal_uInt16> aDelArr; + const SwCharFmts& rTbl = *rDoc.GetCharFmts(); + for( n = 0, nCnt = rTbl.size(); n < nCnt; ++n ) + { + if( !lcl_Contains( rArr, rTbl[ n ] )) + aDelArr.push_front( n ); + } + for( n = 0, nCnt = aDelArr.size(); n < nCnt; ++n ) + rDoc.DelCharFmt( aDelArr[ n ] ); + } + break; + + case SFX_STYLE_FAMILY_PARA : + { + std::deque<sal_uInt16> aDelArr; + const SwTxtFmtColls& rTbl = *rDoc.GetTxtFmtColls(); + for( n = 0, nCnt = rTbl.size(); n < nCnt; ++n ) + { + if( !lcl_Contains( rArr, rTbl[ n ] )) + aDelArr.push_front( n ); + } + for( n = 0, nCnt = aDelArr.size(); n < nCnt; ++n ) + rDoc.DelTxtFmtColl( aDelArr[ n ] ); + } + break; + + case SFX_STYLE_FAMILY_FRAME: + { + std::deque<SwFrmFmt*> aDelArr; + const SwFrmFmts& rTbl = *rDoc.GetFrmFmts(); + for( n = 0, nCnt = rTbl.size(); n < nCnt; ++n ) + { + if( !lcl_Contains( rArr, rTbl[ n ] )) + aDelArr.push_front( rTbl[ n ] ); + } + for( n = 0, nCnt = aDelArr.size(); n < nCnt; ++n ) + rDoc.DelFrmFmt( aDelArr[ n ] ); + } + break; + + case SFX_STYLE_FAMILY_PAGE: + { + std::deque<sal_uInt16> aDelArr; + for( n = 0, nCnt = rDoc.GetPageDescCnt(); n < nCnt; ++n ) + { + if( !lcl_Contains( rArr, &rDoc.GetPageDesc( n ) )) + aDelArr.push_front( n ); + } + for( n = 0, nCnt = aDelArr.size(); n < nCnt; ++n ) + rDoc.DelPageDesc( aDelArr[ n ] ); + } + break; + + case SFX_STYLE_FAMILY_PSEUDO: + { + std::deque<SwNumRule*> aDelArr; + const SwNumRuleTbl& rTbl = rDoc.GetNumRuleTbl(); + for( n = 0, nCnt = rTbl.size(); n < nCnt; ++n ) + { + if( !lcl_Contains( rArr, rTbl[ n ] )) + aDelArr.push_front( rTbl[ n ] ); + } + for( n = 0, nCnt = aDelArr.size(); n < nCnt; ++n ) + rDoc.DelNumRule( aDelArr[ n ]->GetName() ); + } + break; + } +} + +// determine the format +bool SwDocStyleSheet::FillStyleSheet( FillStyleType eFType ) +{ + bool bRet = false; + sal_uInt16 nPoolId = USHRT_MAX; + SwFmt* pFmt = 0; + + bool bCreate = FillPhysical == eFType; + bool bDeleteInfo = false; + bool bFillOnlyInfo = FillAllInfo == eFType; + std::vector<void*> aDelArr; + + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR: + pCharFmt = lcl_FindCharFmt(rDoc, aName, this, bCreate ); + bPhysical = 0 != pCharFmt; + if( bFillOnlyInfo && !bPhysical ) + { + bDeleteInfo = true; + ::lcl_SaveStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc ); + pCharFmt = lcl_FindCharFmt(rDoc, aName, this, true ); + } + + pFmt = pCharFmt; + if( !bCreate && !pFmt ) + { + if( aName == SwStyleNameMapper::GetTextUINameArray()[ RES_POOLCOLL_STANDARD - + RES_POOLCOLL_TEXT_BEGIN ] ) + nPoolId = 0; + else + nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT ); + } + + bRet = 0 != pCharFmt || USHRT_MAX != nPoolId; + + if( bDeleteInfo ) + pCharFmt = 0; + break; + + case SFX_STYLE_FAMILY_PARA: + { + pColl = lcl_FindParaFmt(rDoc, aName, this, bCreate); + bPhysical = 0 != pColl; + if( bFillOnlyInfo && !bPhysical ) + { + bDeleteInfo = true; + ::lcl_SaveStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc ); + pColl = lcl_FindParaFmt(rDoc, aName, this, true ); + } + + pFmt = pColl; + if( pColl ) + PresetFollow( pColl->GetNextTxtFmtColl().GetName() ); + else if( !bCreate ) + nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); + + bRet = 0 != pColl || USHRT_MAX != nPoolId; + + if( bDeleteInfo ) + pColl = 0; + } + break; + + case SFX_STYLE_FAMILY_FRAME: + pFrmFmt = lcl_FindFrmFmt(rDoc, aName, this, bCreate); + bPhysical = 0 != pFrmFmt; + if( bFillOnlyInfo && bPhysical ) + { + bDeleteInfo = true; + ::lcl_SaveStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc ); + pFrmFmt = lcl_FindFrmFmt(rDoc, aName, this, true ); + } + pFmt = pFrmFmt; + if( !bCreate && !pFmt ) + nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT ); + + bRet = 0 != pFrmFmt || USHRT_MAX != nPoolId; + + if( bDeleteInfo ) + pFrmFmt = 0; + break; + + case SFX_STYLE_FAMILY_PAGE: + pDesc = lcl_FindPageDesc(rDoc, aName, this, bCreate); + bPhysical = 0 != pDesc; + if( bFillOnlyInfo && !pDesc ) + { + bDeleteInfo = true; + ::lcl_SaveStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc ); + pDesc = lcl_FindPageDesc( rDoc, aName, this, true ); + } + + if( pDesc ) + { + nPoolId = pDesc->GetPoolFmtId(); + nHelpId = pDesc->GetPoolHelpId(); + if( pDesc->GetPoolHlpFileId() != UCHAR_MAX ) + aHelpFile = *rDoc.GetDocPattern( pDesc->GetPoolHlpFileId() ); + else + aHelpFile = ""; + } + else if( !bCreate ) + nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC ); + SetMask( USER_FMT & nPoolId ? SFXSTYLEBIT_USERDEF : 0 ); + + bRet = 0 != pDesc || USHRT_MAX != nPoolId; + if( bDeleteInfo ) + pDesc = 0; + break; + + case SFX_STYLE_FAMILY_PSEUDO: + pNumRule = lcl_FindNumRule(rDoc, aName, this, bCreate); + bPhysical = 0 != pNumRule; + if( bFillOnlyInfo && !pNumRule ) + { + bDeleteInfo = true; + ::lcl_SaveStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc ); + pNumRule = lcl_FindNumRule( rDoc, aName, this, true ); + } + + if( pNumRule ) + { + nPoolId = pNumRule->GetPoolFmtId(); + nHelpId = pNumRule->GetPoolHelpId(); + if( pNumRule->GetPoolHlpFileId() != UCHAR_MAX ) + aHelpFile = *rDoc.GetDocPattern( pNumRule->GetPoolHlpFileId() ); + else + aHelpFile = ""; + } + else if( !bCreate ) + nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE ); + SetMask( USER_FMT & nPoolId ? SFXSTYLEBIT_USERDEF : 0 ); + + bRet = 0 != pNumRule || USHRT_MAX != nPoolId; + + if( bDeleteInfo ) + pNumRule = 0; + break; + default:; //prevent warning + } + + if( SFX_STYLE_FAMILY_CHAR == nFamily || + SFX_STYLE_FAMILY_PARA == nFamily || + SFX_STYLE_FAMILY_FRAME == nFamily ) + { + if( pFmt ) + nPoolId = pFmt->GetPoolFmtId(); + + sal_uInt16 _nMask = 0; + if( pFmt == rDoc.GetDfltCharFmt() ) + _nMask |= SFXSTYLEBIT_READONLY; + else if( USER_FMT & nPoolId ) + _nMask |= SFXSTYLEBIT_USERDEF; + + switch ( COLL_GET_RANGE_BITS & nPoolId ) + { + case COLL_TEXT_BITS: _nMask |= SWSTYLEBIT_TEXT; break; + case COLL_DOC_BITS : _nMask |= SWSTYLEBIT_CHAPTER; break; + case COLL_LISTS_BITS: _nMask |= SWSTYLEBIT_LIST; break; + case COLL_REGISTER_BITS: _nMask |= SWSTYLEBIT_IDX; break; + case COLL_EXTRA_BITS: _nMask |= SWSTYLEBIT_EXTRA; break; + case COLL_HTML_BITS: _nMask |= SWSTYLEBIT_HTML; break; + } + + if( pFmt ) + { + OSL_ENSURE( bPhysical, "Format not found" ); + + nHelpId = pFmt->GetPoolHelpId(); + if( pFmt->GetPoolHlpFileId() != UCHAR_MAX ) + aHelpFile = *rDoc.GetDocPattern( pFmt->GetPoolHlpFileId() ); + else + aHelpFile = ""; + + if( RES_CONDTXTFMTCOLL == pFmt->Which() ) + _nMask |= SWSTYLEBIT_CONDCOLL; + } + + SetMask( _nMask ); + } + if( bDeleteInfo && bFillOnlyInfo ) + ::lcl_DeleteInfoStyles( static_cast< sal_uInt16 >(nFamily), aDelArr, rDoc ); + return bRet; +} + +// Create new format in Core +void SwDocStyleSheet::Create() +{ + switch(nFamily) + { + case SFX_STYLE_FAMILY_CHAR : + pCharFmt = lcl_FindCharFmt( rDoc, aName ); + if( !pCharFmt ) + pCharFmt = rDoc.MakeCharFmt(aName, + rDoc.GetDfltCharFmt()); + pCharFmt->SetAuto( false ); + break; + + case SFX_STYLE_FAMILY_PARA : + pColl = lcl_FindParaFmt( rDoc, aName ); + if( !pColl ) + { + SwTxtFmtColl *pPar = (*rDoc.GetTxtFmtColls())[0]; + if( nMask & SWSTYLEBIT_CONDCOLL ) + pColl = rDoc.MakeCondTxtFmtColl( aName, pPar ); + else + pColl = rDoc.MakeTxtFmtColl( aName, pPar ); + } + break; + + case SFX_STYLE_FAMILY_FRAME: + pFrmFmt = lcl_FindFrmFmt( rDoc, aName ); + if( !pFrmFmt ) + pFrmFmt = rDoc.MakeFrmFmt(aName, rDoc.GetDfltFrmFmt(), false, false); + + break; + + case SFX_STYLE_FAMILY_PAGE : + pDesc = lcl_FindPageDesc( rDoc, aName ); + if( !pDesc ) + { + sal_uInt16 nId = rDoc.MakePageDesc(aName); + pDesc = &rDoc.GetPageDesc(nId); + } + break; + + case SFX_STYLE_FAMILY_PSEUDO: + pNumRule = lcl_FindNumRule( rDoc, aName ); + if( !pNumRule ) + { + const OUString sTmpNm( aName.isEmpty() ? rDoc.GetUniqueNumRuleName() : aName ); + SwNumRule* pRule = rDoc.GetNumRuleTbl()[ + rDoc.MakeNumRule( sTmpNm, 0, false, + // #i89178# + numfunc::GetDefaultPositionAndSpaceMode() ) ]; + pRule->SetAutoRule( false ); + if( aName.isEmpty() ) + { + // #i91400# + pRule->SetName( aName, rDoc ); + } + pNumRule = pRule; + } + break; + default:; //prevent warning + } + bPhysical = true; + aCoreSet.ClearItem(); +} + +SwCharFmt* SwDocStyleSheet::GetCharFmt() +{ + if(!bPhysical) + FillStyleSheet( FillPhysical ); + return pCharFmt; +} + +SwTxtFmtColl* SwDocStyleSheet::GetCollection() +{ + if(!bPhysical) + FillStyleSheet( FillPhysical ); + return pColl; +} + +const SwPageDesc* SwDocStyleSheet::GetPageDesc() +{ + if(!bPhysical) + FillStyleSheet( FillPhysical ); + return pDesc; +} + +const SwNumRule * SwDocStyleSheet::GetNumRule() +{ + if(!bPhysical) + FillStyleSheet( FillPhysical ); + return pNumRule; +} + +void SwDocStyleSheet::SetNumRule(const SwNumRule& rRule) +{ + OSL_ENSURE(pNumRule, "Wo ist die NumRule"); + rDoc.ChgNumRuleFmts( rRule ); +} + +// re-generate Name AND Family from String +// First() and Next() (see below) insert an identification letter at Pos.1 + +void SwDocStyleSheet::PresetNameAndFamily(const OUString& rName) +{ + switch( rName[0] ) + { + case cPARA: nFamily = SFX_STYLE_FAMILY_PARA; break; + case cFRAME: nFamily = SFX_STYLE_FAMILY_FRAME; break; + case cPAGE: nFamily = SFX_STYLE_FAMILY_PAGE; break; + case cNUMRULE: nFamily = SFX_STYLE_FAMILY_PSEUDO; break; + default: nFamily = SFX_STYLE_FAMILY_CHAR; break; + } + aName = rName.copy(1); +} + +// Is the format physically present yet +void SwDocStyleSheet::SetPhysical(bool bPhys) +{ + bPhysical = bPhys; + + if(!bPhys) + { + pCharFmt = 0; + pColl = 0; + pFrmFmt = 0; + pDesc = 0; + } +} + +SwFrmFmt* SwDocStyleSheet::GetFrmFmt() +{ + if(!bPhysical) + FillStyleSheet( FillPhysical ); + return pFrmFmt; +} + +bool SwDocStyleSheet::IsUsed() const +{ + if( !bPhysical ) + { + SwDocStyleSheet* pThis = (SwDocStyleSheet*)this; + pThis->FillStyleSheet( FillOnlyName ); + } + + if( !bPhysical ) + return false; + + const SwModify* pMod; + switch( nFamily ) + { + case SFX_STYLE_FAMILY_CHAR : pMod = pCharFmt; break; + case SFX_STYLE_FAMILY_PARA : pMod = pColl; break; + case SFX_STYLE_FAMILY_FRAME: pMod = pFrmFmt; break; + case SFX_STYLE_FAMILY_PAGE : pMod = pDesc; break; + + case SFX_STYLE_FAMILY_PSEUDO: + return pNumRule && rDoc.IsUsed( *pNumRule ); + + default: + OSL_ENSURE(!this, "unknown style family"); + return false; + } + return rDoc.IsUsed( *pMod ); +} + +sal_uLong SwDocStyleSheet::GetHelpId( OUString& rFile ) +{ + sal_uInt16 nId = 0; + sal_uInt16 nPoolId = 0; + unsigned char nFileId = UCHAR_MAX; + + rFile = "swrhlppi.hlp"; + + const SwFmt* pTmpFmt = 0; + switch( nFamily ) + { + case SFX_STYLE_FAMILY_CHAR : + if( !pCharFmt && + 0 == (pCharFmt = lcl_FindCharFmt( rDoc, aName, 0, false )) ) + { + nId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT ); + return USHRT_MAX == nId ? 0 : nId; + } + pTmpFmt = pCharFmt; + break; + + case SFX_STYLE_FAMILY_PARA: + if( !pColl && + 0 == ( pColl = lcl_FindParaFmt( rDoc, aName, 0, false )) ) + { + nId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); + return USHRT_MAX == nId ? 0 : nId; + } + pTmpFmt = pColl; + break; + + case SFX_STYLE_FAMILY_FRAME: + if( !pFrmFmt && + 0 == ( pFrmFmt = lcl_FindFrmFmt( rDoc, aName, 0, false ) ) ) + { + nId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT ); + return USHRT_MAX == nId ? 0 : nId; + } + pTmpFmt = pFrmFmt; + break; + + case SFX_STYLE_FAMILY_PAGE: + if( !pDesc && + 0 == ( pDesc = lcl_FindPageDesc( rDoc, aName, 0, false ) ) ) + { + nId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC ); + return USHRT_MAX == nId ? 0 : nId; + } + + nId = pDesc->GetPoolHelpId(); + nFileId = pDesc->GetPoolHlpFileId(); + nPoolId = pDesc->GetPoolFmtId(); + break; + + case SFX_STYLE_FAMILY_PSEUDO: + if( !pNumRule && + 0 == ( pNumRule = lcl_FindNumRule( rDoc, aName, 0, false ) ) ) + { + nId = SwStyleNameMapper::GetPoolIdFromUIName( aName, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE ); + return USHRT_MAX == nId ? 0 : nId; + } + + nId = pNumRule->GetPoolHelpId(); + nFileId = pNumRule->GetPoolHlpFileId(); + nPoolId = pNumRule->GetPoolFmtId(); + break; + + default: + OSL_ENSURE(!this, "unknown style family"); + return 0; + } + + if( pTmpFmt ) + { + nId = pTmpFmt->GetPoolHelpId(); + nFileId = pTmpFmt->GetPoolHlpFileId(); + nPoolId = pTmpFmt->GetPoolFmtId(); + } + + if( UCHAR_MAX != nFileId ) + { + const OUString *pTemplate = rDoc.GetDocPattern( nFileId ); + if( pTemplate ) + { + rFile = *pTemplate; + } + } + else if( !IsPoolUserFmt( nPoolId ) ) + { + nId = nPoolId; + } + + // because SFX acts like that, with HelpId: + if( USHRT_MAX == nId ) + nId = 0; // don't show Help accordingly + + return nId; +} + +void SwDocStyleSheet::SetHelpId( const OUString& r, sal_uLong nId ) +{ + sal_uInt8 nFileId = static_cast< sal_uInt8 >(rDoc.SetDocPattern( r )); + sal_uInt16 nHId = static_cast< sal_uInt16 >(nId); //!! SFX changed over to ULONG arbitrarily! + + SwFmt* pTmpFmt = 0; + switch( nFamily ) + { + case SFX_STYLE_FAMILY_CHAR : pTmpFmt = pCharFmt; break; + case SFX_STYLE_FAMILY_PARA : pTmpFmt = pColl; break; + case SFX_STYLE_FAMILY_FRAME: pTmpFmt = pFrmFmt; break; + case SFX_STYLE_FAMILY_PAGE : + ((SwPageDesc*)pDesc)->SetPoolHelpId( nHId ); + ((SwPageDesc*)pDesc)->SetPoolHlpFileId( nFileId ); + break; + + case SFX_STYLE_FAMILY_PSEUDO: + ((SwNumRule*)pNumRule)->SetPoolHelpId( nHId ); + ((SwNumRule*)pNumRule)->SetPoolHlpFileId( nFileId ); + break; + + default: + OSL_ENSURE(!this, "unknown style family"); + return ; + } + if( pTmpFmt ) + { + pTmpFmt->SetPoolHelpId( nHId ); + pTmpFmt->SetPoolHlpFileId( nFileId ); + } +} + +// methods for DocStyleSheetPool +SwDocStyleSheetPool::SwDocStyleSheetPool( SwDoc& rDocument, bool bOrg ) +: SfxStyleSheetBasePool( rDocument.GetAttrPool() ) +, mxStyleSheet( new SwDocStyleSheet( rDocument, OUString(), this, SFX_STYLE_FAMILY_CHAR, 0 ) ) +, rDoc( rDocument ) +{ + bOrganizer = bOrg; +} + + SwDocStyleSheetPool::~SwDocStyleSheetPool() +{ +} + +void SAL_CALL SwDocStyleSheetPool::acquire( ) throw () +{ + comphelper::OWeakTypeObject::acquire(); +} + +void SAL_CALL SwDocStyleSheetPool::release( ) throw () +{ + comphelper::OWeakTypeObject::release(); +} + +SfxStyleSheetBase& SwDocStyleSheetPool::Make( const OUString& rName, + SfxStyleFamily eFam, + sal_uInt16 _nMask) +{ + mxStyleSheet->PresetName(rName); + mxStyleSheet->PresetParent(OUString()); + mxStyleSheet->PresetFollow(OUString()); + mxStyleSheet->SetMask(_nMask) ; + mxStyleSheet->SetFamily(eFam); + mxStyleSheet->SetPhysical(true); + mxStyleSheet->Create(); + + return *mxStyleSheet.get(); +} + +SfxStyleSheetBase* SwDocStyleSheetPool::Create( const SfxStyleSheetBase& /*rOrg*/) +{ + OSL_ENSURE(!this , "Create im SW-Stylesheet-Pool geht nicht" ); + return NULL; +} + +SfxStyleSheetBase* SwDocStyleSheetPool::Create( const OUString &, + SfxStyleFamily, sal_uInt16 ) +{ + OSL_ENSURE( !this, "Create im SW-Stylesheet-Pool geht nicht" ); + return NULL; +} + +void SwDocStyleSheetPool::Replace( SfxStyleSheetBase& rSource, + SfxStyleSheetBase& rTarget ) +{ + SfxStyleFamily eFamily( rSource.GetFamily() ); + if( rSource.HasParentSupport()) + { + const OUString sParentName = rSource.GetParent(); + if (!sParentName.isEmpty()) + { + SfxStyleSheetBase* pParentOfNew = Find( sParentName, eFamily ); + if( pParentOfNew ) + rTarget.SetParent( sParentName ); + } + } + if( rSource.HasFollowSupport()) + { + const OUString sFollowName = rSource.GetFollow(); + if (!sFollowName.isEmpty()) + { + SfxStyleSheetBase* pFollowOfNew = Find( sFollowName, eFamily ); + if( pFollowOfNew ) + rTarget.SetFollow( sFollowName ); + } + } + + SwImplShellAction aTmpSh( rDoc ); + + bool bSwSrcPool = GetAppName() == rSource.GetPool().GetAppName(); + if( SFX_STYLE_FAMILY_PAGE == eFamily && bSwSrcPool ) + { + // deal with separately! + SwPageDesc* pDestDsc = + (SwPageDesc*)((SwDocStyleSheet&)rTarget).GetPageDesc(); + SwPageDesc* pCpyDsc = + (SwPageDesc*)((SwDocStyleSheet&)rSource).GetPageDesc(); + rDoc.CopyPageDesc( *pCpyDsc, *pDestDsc ); + } + else + { + const SwFmt *pSourceFmt = 0; + SwFmt *pTargetFmt = 0; + sal_uInt16 nPgDscPos = USHRT_MAX; + switch( eFamily ) + { + case SFX_STYLE_FAMILY_CHAR : + if( bSwSrcPool ) + pSourceFmt = ((SwDocStyleSheet&)rSource).GetCharFmt(); + pTargetFmt = ((SwDocStyleSheet&)rTarget).GetCharFmt(); + break; + case SFX_STYLE_FAMILY_PARA : + if( bSwSrcPool ) + pSourceFmt = ((SwDocStyleSheet&)rSource).GetCollection(); + pTargetFmt = ((SwDocStyleSheet&)rTarget).GetCollection(); + break; + case SFX_STYLE_FAMILY_FRAME: + if( bSwSrcPool ) + pSourceFmt = ((SwDocStyleSheet&)rSource).GetFrmFmt(); + pTargetFmt = ((SwDocStyleSheet&)rTarget).GetFrmFmt(); + break; + case SFX_STYLE_FAMILY_PAGE: + { + SwPageDesc *pDesc = rDoc.FindPageDescByName( + ((SwDocStyleSheet&)rTarget).GetPageDesc()->GetName(), + &nPgDscPos ); + + if( pDesc ) + pTargetFmt = &pDesc->GetMaster(); + } + break; + case SFX_STYLE_FAMILY_PSEUDO: + // A NumRule only consists of one Item, so nothing has + // to be deleted here. + break; + default:; //prevent warning + } + if( pTargetFmt ) + { + if( pSourceFmt ) + pTargetFmt->DelDiffs( *pSourceFmt ); + else if( USHRT_MAX != nPgDscPos ) + pTargetFmt->ResetFmtAttr( RES_PAGEDESC, RES_FRMATR_END-1 ); + else + { + // #i73790# - method renamed + pTargetFmt->ResetAllFmtAttr(); + } + + if( USHRT_MAX != nPgDscPos ) + rDoc.ChgPageDesc( nPgDscPos, + rDoc.GetPageDesc(nPgDscPos) ); + } + ((SwDocStyleSheet&)rTarget).SetItemSet( rSource.GetItemSet() ); + } +} + +SfxStyleSheetIteratorPtr SwDocStyleSheetPool::CreateIterator( SfxStyleFamily eFam, sal_uInt16 _nMask ) +{ + return SfxStyleSheetIteratorPtr(new SwStyleSheetIterator( this, eFam, _nMask )); +} + +void SwDocStyleSheetPool::dispose() +{ + mxStyleSheet.clear(); +} + +void SwDocStyleSheetPool::Remove( SfxStyleSheetBase* pStyle) +{ + if( !pStyle ) + return; + + bool bBroadcast = true; + SwImplShellAction aTmpSh( rDoc ); + const OUString sName = pStyle->GetName(); + switch( pStyle->GetFamily() ) + { + case SFX_STYLE_FAMILY_CHAR: + { + SwCharFmt* pFmt = lcl_FindCharFmt(rDoc, sName, 0, false ); + if(pFmt) + rDoc.DelCharFmt(pFmt); + } + break; + case SFX_STYLE_FAMILY_PARA: + { + SwTxtFmtColl* pColl = lcl_FindParaFmt(rDoc, sName, 0, false ); + if(pColl) + rDoc.DelTxtFmtColl(pColl); + } + break; + case SFX_STYLE_FAMILY_FRAME: + { + SwFrmFmt* pFmt = lcl_FindFrmFmt(rDoc, sName, 0, false ); + if(pFmt) + rDoc.DelFrmFmt(pFmt); + } + break; + case SFX_STYLE_FAMILY_PAGE : + { + sal_uInt16 nPos; + if( rDoc.FindPageDescByName( sName, &nPos )) + rDoc.DelPageDesc( nPos ); + } + break; + + case SFX_STYLE_FAMILY_PSEUDO: + { + if( !rDoc.DelNumRule( sName ) ) + // Only send Broadcast, when something was deleted + bBroadcast = false; + } + break; + + default: + OSL_ENSURE(!this, "unknown style family"); + bBroadcast = false; + } + + if( bBroadcast ) + Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *pStyle ) ); +} + +bool SwDocStyleSheetPool::SetParent( SfxStyleFamily eFam, + const OUString &rStyle, const OUString &rParent ) +{ + SwFmt* pFmt = 0, *pParent = 0; + switch( eFam ) + { + case SFX_STYLE_FAMILY_CHAR : + if( 0 != ( pFmt = lcl_FindCharFmt( rDoc, rStyle ) ) && !rParent.isEmpty() ) + pParent = lcl_FindCharFmt(rDoc, rParent ); + break; + + case SFX_STYLE_FAMILY_PARA : + if( 0 != ( pFmt = lcl_FindParaFmt( rDoc, rStyle ) ) && !rParent.isEmpty() ) + pParent = lcl_FindParaFmt( rDoc, rParent ); + break; + + case SFX_STYLE_FAMILY_FRAME: + if( 0 != ( pFmt = lcl_FindFrmFmt( rDoc, rStyle ) ) && !rParent.isEmpty() ) + pParent = lcl_FindFrmFmt( rDoc, rParent ); + break; + + case SFX_STYLE_FAMILY_PAGE: + case SFX_STYLE_FAMILY_PSEUDO: + break; + + default: + OSL_ENSURE(!this, "unknown style family"); + } + + bool bRet = false; + if( pFmt && pFmt->DerivedFrom() && + pFmt->DerivedFrom()->GetName() != rParent ) + { + { + SwImplShellAction aTmpSh( rDoc ); + bRet = pFmt->SetDerivedFrom( pParent ); + } + + if( bRet ) + { + // only for Broadcasting + mxStyleSheet->PresetName( rStyle ); + mxStyleSheet->PresetParent( rParent ); + if( SFX_STYLE_FAMILY_PARA == eFam ) + mxStyleSheet->PresetFollow( ((SwTxtFmtColl*)pFmt)-> + GetNextTxtFmtColl().GetName() ); + else + mxStyleSheet->PresetFollow( OUString() ); + + Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, + *(mxStyleSheet.get()) ) ); + } + } + + return bRet; +} + +SfxStyleSheetBase* SwDocStyleSheetPool::Find( const OUString& rName, + SfxStyleFamily eFam, sal_uInt16 n ) +{ + sal_uInt16 nSMask = n; + if( SFX_STYLE_FAMILY_PARA == eFam && rDoc.get(IDocumentSettingAccess::HTML_MODE) ) + { + // then only HTML-Templates are of interest + if( USHRT_MAX == nSMask ) + nSMask = SWSTYLEBIT_HTML | SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED; + else + nSMask &= SFXSTYLEBIT_USED | SFXSTYLEBIT_USERDEF | + SWSTYLEBIT_CONDCOLL | SWSTYLEBIT_HTML; + if( !nSMask ) + nSMask = SWSTYLEBIT_HTML; + } + + const bool bSearchUsed = ( n != SFXSTYLEBIT_ALL && n & SFXSTYLEBIT_USED ); + const SwModify* pMod = 0; + + mxStyleSheet->SetPhysical( false ); + mxStyleSheet->PresetName( rName ); + mxStyleSheet->SetFamily( eFam ); + bool bFnd = mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName ); + + if( mxStyleSheet->IsPhysical() ) + { + switch( eFam ) + { + case SFX_STYLE_FAMILY_CHAR: + pMod = mxStyleSheet->GetCharFmt(); + break; + + case SFX_STYLE_FAMILY_PARA: + pMod = mxStyleSheet->GetCollection(); + break; + + case SFX_STYLE_FAMILY_FRAME: + pMod = mxStyleSheet->GetFrmFmt(); + break; + + case SFX_STYLE_FAMILY_PAGE: + pMod = mxStyleSheet->GetPageDesc(); + break; + + case SFX_STYLE_FAMILY_PSEUDO: + { + const SwNumRule* pRule = mxStyleSheet->GetNumRule(); + if( pRule && + !bSearchUsed && + (( nSMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF + ? !(pRule->GetPoolFmtId() & USER_FMT) + // searched for used and found none + : bSearchUsed )) + bFnd = false; + } + break; + + default: + OSL_ENSURE(!this, "unknown style family"); + } + } + + // then evaluate the mask: + if( pMod && !bSearchUsed ) + { + const sal_uInt16 nId = SFX_STYLE_FAMILY_PAGE == eFam + ? ((SwPageDesc*)pMod)->GetPoolFmtId() + : ((SwFmt*)pMod)->GetPoolFmtId(); + + if( ( nSMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF + ? !(nId & USER_FMT) + // searched for used and found none + : bSearchUsed ) + bFnd = false; + } + return bFnd ? mxStyleSheet.get() : 0; +} + +SwStyleSheetIterator::SwStyleSheetIterator( SwDocStyleSheetPool* pBase, + SfxStyleFamily eFam, sal_uInt16 n ) + : SfxStyleSheetIterator( pBase, eFam, n ), + mxIterSheet( new SwDocStyleSheet( pBase->GetDoc(), OUString(), pBase, SFX_STYLE_FAMILY_CHAR, 0 ) ), + mxStyleSheet( new SwDocStyleSheet( pBase->GetDoc(), OUString(), pBase, SFX_STYLE_FAMILY_CHAR, 0 ) ) +{ + bFirstCalled = false; + nLastPos = 0; + StartListening( *pBase ); +} + +SwStyleSheetIterator::~SwStyleSheetIterator() +{ + EndListening( mxIterSheet->GetPool() ); +} + +sal_uInt16 SwStyleSheetIterator::Count() +{ + // let the list fill correctly!! + if( !bFirstCalled ) + First(); + return aLst.size(); +} + +SfxStyleSheetBase* SwStyleSheetIterator::operator[]( sal_uInt16 nIdx ) +{ + // found + if( !bFirstCalled ) + First(); + mxStyleSheet->PresetNameAndFamily( aLst[ nIdx ] ); + mxStyleSheet->SetPhysical( false ); + mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName ); + + return mxStyleSheet.get(); +} + +SfxStyleSheetBase* SwStyleSheetIterator::First() +{ + // Delete old list + bFirstCalled = true; + nLastPos = 0; + aLst.Erase(); + + // Delete current + mxIterSheet->Reset(); + + SwDoc& rDoc = ((SwDocStyleSheetPool*)pBasePool)->GetDoc(); + const sal_uInt16 nSrchMask = nMask; + const bool bIsSearchUsed = SearchUsed(); + + bool bSearchHidden = ( nMask & SFXSTYLEBIT_HIDDEN ); + bool bOnlyHidden = nMask == SFXSTYLEBIT_HIDDEN; + + const bool bOrganizer = ((SwDocStyleSheetPool*)pBasePool)->IsOrganizerMode(); + bool bAll = ( nSrchMask & SFXSTYLEBIT_ALL_VISIBLE ) == SFXSTYLEBIT_ALL_VISIBLE; + + if( nSearchFamily == SFX_STYLE_FAMILY_CHAR + || nSearchFamily == SFX_STYLE_FAMILY_ALL ) + { + const sal_uInt16 nArrLen = rDoc.GetCharFmts()->size(); + for( sal_uInt16 i = 0; i < nArrLen; i++ ) + { + SwCharFmt* pFmt = (*rDoc.GetCharFmts())[ i ]; + + const bool bUsed = bIsSearchUsed && (bOrganizer || rDoc.IsUsed(*pFmt)); + if( ( !bSearchHidden && pFmt->IsHidden() && !bUsed ) || ( pFmt->IsDefault() && pFmt != rDoc.GetDfltCharFmt() ) ) + continue; + + if ( nSrchMask == SFXSTYLEBIT_HIDDEN && !pFmt->IsHidden( ) ) + continue; + + if( !bUsed ) + { + // Standard is no User template + const sal_uInt16 nId = rDoc.GetDfltCharFmt() == pFmt ? + sal_uInt16( RES_POOLCHR_INET_NORMAL ): + pFmt->GetPoolFmtId(); + if( (nSrchMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF + ? !(nId & USER_FMT) + // searched for used and found none + : bIsSearchUsed ) + { + continue; + } + + if( rDoc.get(IDocumentSettingAccess::HTML_MODE) && !(nId & USER_FMT) && + !( RES_POOLCHR_HTML_BEGIN <= nId && + nId < RES_POOLCHR_HTML_END ) && + RES_POOLCHR_INET_NORMAL != nId && + RES_POOLCHR_INET_VISIT != nId && + RES_POOLCHR_FOOTNOTE != nId && + RES_POOLCHR_ENDNOTE != nId ) + continue; + } + + aLst.Append( cCHAR, pFmt == rDoc.GetDfltCharFmt() + ? SwStyleNameMapper::GetTextUINameArray()[ RES_POOLCOLL_STANDARD - + RES_POOLCOLL_TEXT_BEGIN ] + : pFmt->GetName() ); + } + + // PoolFormate + if( bAll ) + { + if( !rDoc.get(IDocumentSettingAccess::HTML_MODE) ) + AppendStyleList(SwStyleNameMapper::GetChrFmtUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, + nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, cCHAR); + else + { + aLst.Append( cCHAR, SwStyleNameMapper::GetChrFmtUINameArray()[ + RES_POOLCHR_INET_NORMAL - RES_POOLCHR_BEGIN ] ); + aLst.Append( cCHAR, SwStyleNameMapper::GetChrFmtUINameArray()[ + RES_POOLCHR_INET_VISIT - RES_POOLCHR_BEGIN ] ); + aLst.Append( cCHAR, SwStyleNameMapper::GetChrFmtUINameArray()[ + RES_POOLCHR_ENDNOTE - RES_POOLCHR_BEGIN ] ); + aLst.Append( cCHAR, SwStyleNameMapper::GetChrFmtUINameArray()[ + RES_POOLCHR_FOOTNOTE - RES_POOLCHR_BEGIN ] ); + } + AppendStyleList(SwStyleNameMapper::GetHTMLChrFmtUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, + nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, cCHAR); + } + } + + if( nSearchFamily == SFX_STYLE_FAMILY_PARA || + nSearchFamily == SFX_STYLE_FAMILY_ALL ) + { + sal_uInt16 nSMask = nSrchMask; + if( rDoc.get(IDocumentSettingAccess::HTML_MODE) ) + { + // then only HTML-Template are of interest + if( SFXSTYLEBIT_ALL_VISIBLE == ( nSMask & SFXSTYLEBIT_ALL_VISIBLE ) ) + nSMask = SWSTYLEBIT_HTML | SFXSTYLEBIT_USERDEF | + SFXSTYLEBIT_USED; + else + nSMask &= SFXSTYLEBIT_USED | SFXSTYLEBIT_USERDEF | + SWSTYLEBIT_CONDCOLL | SWSTYLEBIT_HTML; + if( !nSMask ) + nSMask = SWSTYLEBIT_HTML; + } + + const sal_uInt16 nArrLen = rDoc.GetTxtFmtColls()->size(); + for( sal_uInt16 i = 0; i < nArrLen; i++ ) + { + SwTxtFmtColl* pColl = (*rDoc.GetTxtFmtColls())[ i ]; + + const bool bUsed = bOrganizer || rDoc.IsUsed(*pColl); + if ( ( !bSearchHidden && pColl->IsHidden( ) && !bUsed ) || pColl->IsDefault() ) + continue; + + if ( nSMask == SFXSTYLEBIT_HIDDEN && !pColl->IsHidden( ) ) + continue; + + if( !(bIsSearchUsed && bUsed )) + { + const sal_uInt16 nId = pColl->GetPoolFmtId(); + switch ( (nSMask & ~SFXSTYLEBIT_USED) ) + { + case SFXSTYLEBIT_USERDEF: + if(!IsPoolUserFmt(nId)) continue; + break; + case SWSTYLEBIT_TEXT: + if((nId & COLL_GET_RANGE_BITS) != COLL_TEXT_BITS) continue; + break; + case SWSTYLEBIT_CHAPTER: + if((nId & COLL_GET_RANGE_BITS) != COLL_DOC_BITS) continue; + break; + case SWSTYLEBIT_LIST: + if((nId & COLL_GET_RANGE_BITS) != COLL_LISTS_BITS) continue; + break; + case SWSTYLEBIT_IDX: + if((nId & COLL_GET_RANGE_BITS) != COLL_REGISTER_BITS) continue; + break; + case SWSTYLEBIT_EXTRA: + if((nId & COLL_GET_RANGE_BITS) != COLL_EXTRA_BITS) continue; + break; + case SWSTYLEBIT_HTML | SFXSTYLEBIT_USERDEF: + if(IsPoolUserFmt(nId)) + break; + // otherwise move on + case SWSTYLEBIT_HTML: + if( (nId & COLL_GET_RANGE_BITS) != COLL_HTML_BITS) + { + // but some we also want to see in this section + bool bContinue = true; + switch( nId ) + { + case RES_POOLCOLL_SENDADRESS: // --> ADDRESS + case RES_POOLCOLL_TABLE_HDLN: // --> TH + case RES_POOLCOLL_TABLE: // --> TD + case RES_POOLCOLL_TEXT: // --> P + case RES_POOLCOLL_HEADLINE_BASE:// --> H + case RES_POOLCOLL_HEADLINE1: // --> H1 + case RES_POOLCOLL_HEADLINE2: // --> H2 + case RES_POOLCOLL_HEADLINE3: // --> H3 + case RES_POOLCOLL_HEADLINE4: // --> H4 + case RES_POOLCOLL_HEADLINE5: // --> H5 + case RES_POOLCOLL_HEADLINE6: // --> H6 + case RES_POOLCOLL_STANDARD: // --> P + case RES_POOLCOLL_FOOTNOTE: + case RES_POOLCOLL_ENDNOTE: + bContinue = false; + break; + } + if( bContinue ) + continue; + } + break; + case SWSTYLEBIT_CONDCOLL: + if( RES_CONDTXTFMTCOLL != pColl->Which() ) continue; + break; + default: + // searched for used and found none + if( bIsSearchUsed ) + continue; + } + } + aLst.Append( cPARA, pColl->GetName() ); + } + + bAll = ( nSMask & SFXSTYLEBIT_ALL_VISIBLE ) == SFXSTYLEBIT_ALL_VISIBLE; + if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_TEXT ) + AppendStyleList(SwStyleNameMapper::GetTextUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ); + if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_CHAPTER ) + AppendStyleList(SwStyleNameMapper::GetDocUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ) ; + if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_LIST ) + AppendStyleList(SwStyleNameMapper::GetListsUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ) ; + if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_IDX ) + AppendStyleList(SwStyleNameMapper::GetRegisterUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ) ; + if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_EXTRA ) + AppendStyleList(SwStyleNameMapper::GetExtraUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ) ; + if ( bAll || (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_CONDCOLL ) + { + if( !bIsSearchUsed || + rDoc.IsPoolTxtCollUsed( RES_POOLCOLL_TEXT )) + aLst.Append( cPARA, SwStyleNameMapper::GetTextUINameArray()[ + RES_POOLCOLL_TEXT - RES_POOLCOLL_TEXT_BEGIN ] ); + } + if ( bAll || + (nSMask & ~SFXSTYLEBIT_USED) == SWSTYLEBIT_HTML || + (nSMask & ~SFXSTYLEBIT_USED) == + (SWSTYLEBIT_HTML | SFXSTYLEBIT_USERDEF) ) + { + AppendStyleList(SwStyleNameMapper::GetHTMLUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, cPARA ) ; + if( !bAll ) + { + // then also the ones, that we are mapping: + static sal_uInt16 aPoolIds[] = { + RES_POOLCOLL_SENDADRESS, // --> ADDRESS + RES_POOLCOLL_TABLE_HDLN, // --> TH + RES_POOLCOLL_TABLE, // --> TD + RES_POOLCOLL_STANDARD, // --> P + RES_POOLCOLL_TEXT, // --> P + RES_POOLCOLL_HEADLINE_BASE, // --> H + RES_POOLCOLL_HEADLINE1, // --> H1 + RES_POOLCOLL_HEADLINE2, // --> H2 + RES_POOLCOLL_HEADLINE3, // --> H3 + RES_POOLCOLL_HEADLINE4, // --> H4 + RES_POOLCOLL_HEADLINE5, // --> H5 + RES_POOLCOLL_HEADLINE6, // --> H6 + RES_POOLCOLL_FOOTNOTE, + RES_POOLCOLL_ENDNOTE, + 0 + }; + + sal_uInt16* pPoolIds = aPoolIds; + OUString s; + while( *pPoolIds ) + { + if( !bIsSearchUsed || rDoc.IsPoolTxtCollUsed( *pPoolIds ) ) + aLst.Append( cPARA, + s = SwStyleNameMapper::GetUIName( *pPoolIds, s )); + ++pPoolIds; + } + } + } + } + + if( nSearchFamily == SFX_STYLE_FAMILY_FRAME || + nSearchFamily == SFX_STYLE_FAMILY_ALL ) + { + const sal_uInt16 nArrLen = rDoc.GetFrmFmts()->size(); + for( sal_uInt16 i = 0; i < nArrLen; i++ ) + { + SwFrmFmt* pFmt = (*rDoc.GetFrmFmts())[ i ]; + + bool bUsed = bIsSearchUsed && ( bOrganizer || rDoc.IsUsed(*pFmt)); + if( ( !bSearchHidden && pFmt->IsHidden( ) && !bUsed ) || pFmt->IsDefault() || pFmt->IsAuto() ) + continue; + + if ( nSrchMask == SFXSTYLEBIT_HIDDEN && !pFmt->IsHidden( ) ) + continue; + + const sal_uInt16 nId = pFmt->GetPoolFmtId(); + if( !bUsed ) + { + if( (nSrchMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF + ? !(nId & USER_FMT) + // searched for used and found none + : bIsSearchUsed ) + { + continue; + } + } + + aLst.Append( cFRAME, pFmt->GetName() ); + } + + // PoolFormate + if ( bAll ) + AppendStyleList(SwStyleNameMapper::GetFrmFmtUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, nsSwGetPoolIdFromName::GET_POOLID_FRMFMT, cFRAME); + } + + if( nSearchFamily == SFX_STYLE_FAMILY_PAGE || + nSearchFamily == SFX_STYLE_FAMILY_ALL ) + { + const sal_uInt16 nCount = rDoc.GetPageDescCnt(); + for(sal_uInt16 i = 0; i < nCount; ++i) + { + const SwPageDesc& rDesc = rDoc.GetPageDesc(i); + const sal_uInt16 nId = rDesc.GetPoolFmtId(); + bool bUsed = bIsSearchUsed && ( bOrganizer || rDoc.IsUsed(rDesc)); + if( !bUsed ) + { + if ( ( !bSearchHidden && rDesc.IsHidden() ) || + ( (nSrchMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF + ? !(nId & USER_FMT) + // searched for used and found none + : bIsSearchUsed ) ) + continue; + } + + if ( nSrchMask == SFXSTYLEBIT_HIDDEN && !rDesc.IsHidden( ) ) + continue; + + aLst.Append( cPAGE, rDesc.GetName() ); + } + if ( bAll ) + AppendStyleList(SwStyleNameMapper::GetPageDescUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, cPAGE); + } + + if( nSearchFamily == SFX_STYLE_FAMILY_PSEUDO || + nSearchFamily == SFX_STYLE_FAMILY_ALL ) + { + const SwNumRuleTbl& rNumTbl = rDoc.GetNumRuleTbl(); + for(sal_uInt16 i = 0; i < rNumTbl.size(); ++i) + { + const SwNumRule& rRule = *rNumTbl[ i ]; + if( !rRule.IsAutoRule() ) + { + if ( nSrchMask == SFXSTYLEBIT_HIDDEN && !rRule.IsHidden( ) ) + continue; + + bool bUsed = bIsSearchUsed && ( bOrganizer || rDoc.IsUsed(rRule) ); + if( !bUsed ) + { + if( ( !bSearchHidden && rRule.IsHidden() ) || + ( (nSrchMask & ~SFXSTYLEBIT_USED) == SFXSTYLEBIT_USERDEF + ? !(rRule.GetPoolFmtId() & USER_FMT) + // searched for used and found none + : bIsSearchUsed ) ) + continue; + } + + aLst.Append( cNUMRULE, rRule.GetName() ); + } + } + if ( bAll ) + AppendStyleList(SwStyleNameMapper::GetNumRuleUINameArray(), + bIsSearchUsed, bSearchHidden, bOnlyHidden, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE, cNUMRULE); + } + + if(!aLst.empty()) + { + nLastPos = USHRT_MAX; + return Next(); + } + return 0; +} + +SfxStyleSheetBase* SwStyleSheetIterator::Next() +{ + assert(bFirstCalled); + ++nLastPos; + if(!aLst.empty() && nLastPos < aLst.size()) + { + mxIterSheet->PresetNameAndFamily(aLst[nLastPos]); + mxIterSheet->SetPhysical( false ); + mxIterSheet->SetMask( nMask ); + if(mxIterSheet->pSet) + { + mxIterSheet->pSet->ClearItem(0); + mxIterSheet->pSet= 0; + } + return mxIterSheet.get(); + } + return 0; +} + +SfxStyleSheetBase* SwStyleSheetIterator::Find(const OUString& rName) +{ + // searching + if( !bFirstCalled ) + First(); + + nLastPos = lcl_FindName( aLst, nSearchFamily, rName ); + if( USHRT_MAX != nLastPos ) + { + // found + mxStyleSheet->PresetNameAndFamily(aLst[nLastPos]); + // new name is set, so determine its Data + mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName ); + if( !mxStyleSheet->IsPhysical() ) + mxStyleSheet->SetPhysical( false ); + + return mxStyleSheet.get(); + } + return 0; +} + +void SwStyleSheetIterator::AppendStyleList(const ::std::vector<OUString>& rList, + bool bTestUsed, bool bTestHidden, bool bOnlyHidden, + sal_uInt16 nSection, char cType ) +{ + SwDoc& rDoc = ((SwDocStyleSheetPool*)pBasePool)->GetDoc(); + bool bUsed = false; + for ( sal_uInt16 i=0; i < rList.size(); ++i ) + { + bool bHidden = false; + sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rList[i], (SwGetPoolIdFromName)nSection); + switch ( nSection ) + { + case nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL: + { + bUsed = rDoc.IsPoolTxtCollUsed( nId ); + SwFmt* pFmt = rDoc.FindTxtFmtCollByName( rList[i] ); + bHidden = pFmt && pFmt->IsHidden( ); + } + break; + case nsSwGetPoolIdFromName::GET_POOLID_CHRFMT: + { + bUsed = rDoc.IsPoolFmtUsed( nId ); + SwFmt* pFmt = rDoc.FindCharFmtByName( rList[i] ); + bHidden = pFmt && pFmt->IsHidden( ); + } + break; + case nsSwGetPoolIdFromName::GET_POOLID_FRMFMT: + { + bUsed = rDoc.IsPoolFmtUsed( nId ); + SwFmt* pFmt = rDoc.FindFrmFmtByName( rList[i] ); + bHidden = pFmt && pFmt->IsHidden( ); + } + break; + case nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC: + { + bUsed = rDoc.IsPoolPageDescUsed( nId ); + SwPageDesc* pPgDesc = rDoc.FindPageDescByName( rList[i] ); + bHidden = pPgDesc && pPgDesc->IsHidden( ); + } + break; + case nsSwGetPoolIdFromName::GET_POOLID_NUMRULE: + { + SwNumRule* pRule = rDoc.FindNumRulePtr( rList[i] ); + bUsed = pRule && rDoc.IsUsed( *pRule ); + bHidden = pRule && pRule->IsHidden( ); + } + break; + default: + OSL_ENSURE( !this, "unknown PoolFmt-Id" ); + } + + bool bMatchHidden = ( bTestHidden && ( bHidden || !bOnlyHidden ) ) || ( !bTestHidden && ( !bHidden || bUsed ) ); + if ( ( !bTestUsed && bMatchHidden ) || ( bTestUsed && bUsed ) ) + aLst.Append( cType, rList[i] ); + } +} + +void SwDocStyleSheetPool::InvalidateIterator() +{ + dynamic_cast<SwStyleSheetIterator&>(GetIterator_Impl()).InvalidateIterator(); +} + +void SwStyleSheetIterator::InvalidateIterator() +{ + // potentially we could send an SfxHint to Notify but currently it's + // iterating over the vector anyway so would still be slow - why does + // this iterator not use a map? + bFirstCalled = false; + nLastPos = 0; + aLst.Erase(); +} + +void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint ) +{ + // search and remove from View-List!! + if( rHint.ISA( SfxStyleSheetHint ) && + SFX_STYLESHEET_ERASED == ((SfxStyleSheetHint&) rHint).GetHint() ) + { + SfxStyleSheetBase* pStyle = ((SfxStyleSheetHint&)rHint).GetStyleSheet(); + + if (pStyle) + { + sal_uInt16 nTmpPos = lcl_FindName( aLst, pStyle->GetFamily(), + pStyle->GetName() ); + if( nTmpPos < aLst.size() ) + aLst.erase(aLst.begin() + nTmpPos); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/mainwn.cxx b/sw/source/uibase/app/mainwn.cxx new file mode 100644 index 000000000000..d7553a064e80 --- /dev/null +++ b/sw/source/uibase/app/mainwn.cxx @@ -0,0 +1,141 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <mdiexp.hxx> +#include <tools/shl.hxx> +#include <sfx2/progress.hxx> +#include <tools/resid.hxx> +#include <docsh.hxx> +#include <swmodule.hxx> +#include "swtypes.hxx" + +class SwDocShell; + +struct SwProgress +{ + long nStartValue, + nStartCount; + SwDocShell *pDocShell; + SfxProgress *pProgress; +}; + +static std::vector<SwProgress*> *pProgressContainer = 0; + +static SwProgress *lcl_SwFindProgress( SwDocShell *pDocShell ) +{ + for ( sal_uInt16 i = 0; i < pProgressContainer->size(); ++i ) + { + SwProgress *pTmp = (*pProgressContainer)[i]; + if ( pTmp->pDocShell == pDocShell ) + return pTmp; + } + return 0; +} + +void StartProgress( sal_uInt16 nMessResId, long nStartValue, long nEndValue, + SwDocShell *pDocShell ) +{ + if( !SW_MOD()->IsEmbeddedLoadSave() ) + { + SwProgress *pProgress = 0; + + if ( !pProgressContainer ) + pProgressContainer = new std::vector<SwProgress*>; + else + { + if ( 0 != (pProgress = lcl_SwFindProgress( pDocShell )) ) + ++pProgress->nStartCount; + } + if ( !pProgress ) + { + pProgress = new SwProgress; + pProgress->pProgress = new SfxProgress( pDocShell, + SW_RESSTR(nMessResId), + nEndValue - nStartValue, + false, + true ); + pProgress->nStartCount = 1; + pProgress->pDocShell = pDocShell; + pProgressContainer->insert( pProgressContainer->begin(), pProgress ); + } + pProgress->nStartValue = nStartValue; + } +} + +void SetProgressState( long nPosition, SwDocShell *pDocShell ) +{ + if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() ) + { + SwProgress *pProgress = lcl_SwFindProgress( pDocShell ); + if ( pProgress ) + pProgress->pProgress->SetState(nPosition - pProgress->nStartValue); + } +} + +void EndProgress( SwDocShell *pDocShell ) +{ + if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() ) + { + SwProgress *pProgress = 0; + sal_uInt16 i; + for ( i = 0; i < pProgressContainer->size(); ++i ) + { + SwProgress *pTmp = (SwProgress*)(*pProgressContainer)[i]; + if ( pTmp->pDocShell == pDocShell ) + { + pProgress = pTmp; + break; + } + } + + if ( pProgress && 0 == --pProgress->nStartCount ) + { + pProgress->pProgress->Stop(); + pProgressContainer->erase( pProgressContainer->begin() + i ); + delete pProgress->pProgress; + delete pProgress; + //#112337# it may happen that the container has been removed + //while rescheduling + if ( pProgressContainer && pProgressContainer->empty() ) + delete pProgressContainer, pProgressContainer = 0; + } + } +} + +void SetProgressText( sal_uInt16 nId, SwDocShell *pDocShell ) +{ + if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() ) + { + SwProgress *pProgress = lcl_SwFindProgress( pDocShell ); + if ( pProgress ) + pProgress->pProgress->SetStateText( 0, SW_RESSTR(nId) ); + } +} + +void RescheduleProgress( SwDocShell *pDocShell ) +{ + if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() ) + { + SwProgress *pProgress = lcl_SwFindProgress( pDocShell ); + if ( pProgress ) + pProgress->pProgress->Reschedule(); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/swdll.cxx b/sw/source/uibase/app/swdll.cxx new file mode 100644 index 000000000000..cb6d19e079e1 --- /dev/null +++ b/sw/source/uibase/app/swdll.cxx @@ -0,0 +1,164 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <config_features.h> + +#include <svx/svdobj.hxx> + +#include "globdoc.hrc" + +#include <swdll.hxx> +#include <wdocsh.hxx> +#include <globdoc.hxx> +#include <initui.hxx> +#include <swmodule.hxx> +#include <swtypes.hxx> +#include <init.hxx> +#include <dobjfac.hxx> +#include <cfgid.h> + +#include <com/sun/star/frame/Desktop.hpp> +#include <unotools/moduleoptions.hxx> +#include <comphelper/scoped_disposing_ptr.hxx> +#include <comphelper/processfactory.hxx> + +#include <svx/fmobjfac.hxx> +#include <svx/svdfield.hxx> +#include <svx/objfac3d.hxx> + +#include <unomid.h> + +#include "swdllimpl.hxx" + +using namespace com::sun::star; + +namespace +{ + //Holds a SwDLL and release it on exit, or dispose of the + //default XComponent, whichever comes first + class SwDLLInstance : public comphelper::scoped_disposing_solar_mutex_reset_ptr<SwDLL> + { + public: + SwDLLInstance() : comphelper::scoped_disposing_solar_mutex_reset_ptr<SwDLL>(uno::Reference<lang::XComponent>( frame::Desktop::create(comphelper::getProcessComponentContext()), uno::UNO_QUERY_THROW), new SwDLL) + { + } + }; + + struct theSwDLLInstance : public rtl::Static<SwDLLInstance, theSwDLLInstance> {}; +} + +namespace SwGlobals +{ + void ensure() + { + theSwDLLInstance::get(); + } + + sw::Filters & getFilters() + { + return theSwDLLInstance::get().get()->getFilters(); + } +} + +SwDLL::SwDLL() +{ + // the SdModule must be created + SwModule** ppShlPtr = (SwModule**) GetAppData(SHL_WRITER); + if ( *ppShlPtr ) + return; + + SvtModuleOptions aOpt; + SfxObjectFactory* pDocFact = 0; + SfxObjectFactory* pGlobDocFact = 0; + if ( aOpt.IsWriter() ) + { + pDocFact = &SwDocShell::Factory(); + pGlobDocFact = &SwGlobalDocShell::Factory(); + } + + SfxObjectFactory* pWDocFact = &SwWebDocShell::Factory(); + + SwModule* pModule = new SwModule( pWDocFact, pDocFact, pGlobDocFact ); + *ppShlPtr = pModule; + + pWDocFact->SetDocumentServiceName(OUString("com.sun.star.text.WebDocument")); + + if ( aOpt.IsWriter() ) + { + pGlobDocFact->SetDocumentServiceName(OUString("com.sun.star.text.GlobalDocument")); + pDocFact->SetDocumentServiceName(OUString("com.sun.star.text.TextDocument")); + } + + // register SvDraw-Fields + SdrRegisterFieldClasses(); + + // register 3D-Objekt-Factory + E3dObjFactory(); + + // register form::component::Form-Objekt-Factory + FmFormObjFactory(); + + SdrObjFactory::InsertMakeObjectHdl( LINK( &aSwObjectFactory, SwObjectFactory, MakeObject ) ); + + SAL_INFO( "sw.ui", "Init Core/UI/Filter" ); + // Initialisation of Statics + ::_InitCore(); + filters_.reset(new sw::Filters); + ::_InitUI(); + + pModule->InitAttrPool(); + // now SWModule can create its Pool + + // register your view-factories here + RegisterFactories(); + +#if HAVE_FEATURE_DESKTOP + // register your shell-interfaces here + RegisterInterfaces(); + + // register your controllers here + RegisterControls(); +#endif +} + +SwDLL::~SwDLL() +{ + // Pool has to be deleted before statics are + SW_MOD()->RemoveAttrPool(); + + ::_FinitUI(); + filters_.reset(); + ::_FinitCore(); + // sign out Objekt-Factory + SdrObjFactory::RemoveMakeObjectHdl(LINK(&aSwObjectFactory, SwObjectFactory, MakeObject )); +#if 0 + // the SwModule must be destroyed + SwModule** ppShlPtr = (SwModule**) GetAppData(SHL_WRITER); + delete (*ppShlPtr); + (*ppShlPtr) = NULL; +#endif +} + +sw::Filters & SwDLL::getFilters() +{ + OSL_ASSERT(filters_); + return *filters_.get(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/swdllimpl.hxx b/sw/source/uibase/app/swdllimpl.hxx new file mode 100644 index 000000000000..34eb956cb45a --- /dev/null +++ b/sw/source/uibase/app/swdllimpl.hxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SW_SOURCE_CORE_UIBASE_APP_SWDLLIMPL_HXX +#define INCLUDED_SW_SOURCE_CORE_UIBASE_APP_SWDLLIMPL_HXX + +#include <sal/config.h> + +#include <boost/noncopyable.hpp> +#include <boost/scoped_ptr.hpp> + +namespace sw { class Filters; } + +class SwDLL: private boost::noncopyable +{ +public: + static void RegisterFactories(); + static void RegisterInterfaces(); + static void RegisterControls(); + + SwDLL(); + ~SwDLL(); + + sw::Filters & getFilters(); + +private: + boost::scoped_ptr< sw::Filters > filters_; +}; + +#endif diff --git a/sw/source/uibase/app/swmodul1.cxx b/sw/source/uibase/app/swmodul1.cxx new file mode 100644 index 000000000000..dcdfc0101625 --- /dev/null +++ b/sw/source/uibase/app/swmodul1.cxx @@ -0,0 +1,659 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <boost/scoped_ptr.hpp> + +#include <hintids.hxx> +#include <sfx2/request.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/childwin.hxx> +#include <unotools/useroptions.hxx> +#include <cppuhelper/weak.hxx> +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <cppuhelper/implbase1.hxx> +#include <svx/dataaccessdescriptor.hxx> +#include <editeng/wghtitem.hxx> +#include <editeng/postitem.hxx> +#include <editeng/udlnitem.hxx> +#include <editeng/crossedoutitem.hxx> +#include <editeng/cmapitem.hxx> +#include <editeng/colritem.hxx> +#include <editeng/brushitem.hxx> +#include <vcl/msgbox.hxx> +#include <svl/cjkoptions.hxx> +#include <swmodule.hxx> +#include <swtypes.hxx> +#include <usrpref.hxx> +#include <modcfg.hxx> +#include <view.hxx> +#include <pview.hxx> +#include <wview.hxx> +#include <wrtsh.hxx> +#include <docsh.hxx> +#include <dbmgr.hxx> +#include <uinums.hxx> +#include <prtopt.hxx> +#include <navicfg.hxx> +#include <doc.hxx> +#include <cmdid.h> +#include <app.hrc> +#include "helpid.h" + +#include <unomid.h> +#include <tools/color.hxx> +#include "PostItMgr.hxx" + +using namespace ::svx; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::view; +using namespace ::com::sun::star::lang; + +static void lcl_SetUIPrefs(const SwViewOption &rPref, SwView* pView, SwViewShell* pSh ) +{ + // in FrameSets the actual visibility can differ from the ViewOption's setting + bool bVScrollChanged = rPref.IsViewVScrollBar() != pSh->GetViewOptions()->IsViewVScrollBar(); + bool bHScrollChanged = rPref.IsViewHScrollBar() != pSh->GetViewOptions()->IsViewHScrollBar(); + bool bVAlignChanged = rPref.IsVRulerRight() != pSh->GetViewOptions()->IsVRulerRight(); + + pSh->SetUIOptions(rPref); + const SwViewOption* pNewPref = pSh->GetViewOptions(); + + // Scrollbars on / off + if(bVScrollChanged) + { + pView->EnableVScrollbar(pNewPref->IsViewVScrollBar()); + } + if(bHScrollChanged) + { + pView->EnableHScrollbar( pNewPref->IsViewHScrollBar() || pNewPref->getBrowseMode() ); + } + //if only the position of the vertical ruler has been changed initiate an update + if(bVAlignChanged && !bHScrollChanged && !bVScrollChanged) + pView->InvalidateBorder(); + + // Rulers on / off + if(pNewPref->IsViewVRuler()) + pView->CreateVRuler(); + else + pView->KillVRuler(); + + // TabWindow on / off + if(pNewPref->IsViewHRuler()) + pView->CreateTab(); + else + pView->KillTab(); + + pView->GetPostItMgr()->PrepareView(true); +} + +SwWrtShell* GetActiveWrtShell() +{ + SwView *pActive = ::GetActiveView(); + if( pActive ) + return &pActive->GetWrtShell(); + return 0; +} + +SwView* GetActiveView() +{ + SfxViewShell* pView = SfxViewShell::Current(); + return PTR_CAST( SwView, pView ); +} + +SwView* SwModule::GetFirstView() +{ + // returns only sivible SwView + const TypeId aTypeId = TYPE(SwView); + SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId); + return pView; +} + +SwView* SwModule::GetNextView(SwView* pView) +{ + OSL_ENSURE(PTR_CAST(SwView, pView),"return no SwView"); + const TypeId aTypeId = TYPE(SwView); + SwView* pNView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId, true); + return pNView; +} + +// New Master for the settings is set; this affects the current view and all following. +void SwModule::ApplyUsrPref(const SwViewOption &rUsrPref, SwView* pActView, + sal_uInt16 nDest ) +{ + SwView* pCurrView = pActView; + SwViewShell* pSh = pCurrView ? &pCurrView->GetWrtShell() : 0; + + SwMasterUsrPref* pPref = (SwMasterUsrPref*)GetUsrPref( + VIEWOPT_DEST_WEB == nDest ? true : + VIEWOPT_DEST_TEXT== nDest ? false : + pCurrView && pCurrView->ISA(SwWebView) ); + + // with Uno, only sdbcx::View, but not the Module should be changed + bool bViewOnly = VIEWOPT_DEST_VIEW_ONLY == nDest; + // fob Preview off + SwPagePreview* pPPView; + if( !pCurrView && 0 != (pPPView = PTR_CAST( SwPagePreview, SfxViewShell::Current())) ) + { + if(!bViewOnly) + pPref->SetUIOptions( rUsrPref ); + pPPView->EnableVScrollbar(pPref->IsViewVScrollBar()); + pPPView->EnableHScrollbar(pPref->IsViewHScrollBar()); + if(!bViewOnly) + { + pPref->SetPagePrevRow(rUsrPref.GetPagePrevRow()); + pPref->SetPagePrevCol(rUsrPref.GetPagePrevCol()); + } + return; + } + + if(!bViewOnly) + { + pPref->SetUsrPref( rUsrPref ); + pPref->SetModified(); + } + + if( !pCurrView ) + return; + + // Passing on to CORE + bool bReadonly; + const SwDocShell* pDocSh = pCurrView->GetDocShell(); + if (pDocSh) + bReadonly = pDocSh->IsReadOnly(); + else //Use existing option if DocShell missing + bReadonly = pSh->GetViewOptions()->IsReadonly(); + boost::scoped_ptr<SwViewOption> xViewOpt; + if (!bViewOnly) + xViewOpt.reset(new SwViewOption(*pPref)); + else + xViewOpt.reset(new SwViewOption(rUsrPref)); + xViewOpt->SetReadonly( bReadonly ); + if( !(*pSh->GetViewOptions() == *xViewOpt) ) + { + //is maybe only a SwViewShell + pSh->StartAction(); + pSh->ApplyViewOptions( *xViewOpt ); + ((SwWrtShell*)pSh)->SetReadOnlyAvailable(xViewOpt->IsCursorInProtectedArea()); + pSh->EndAction(); + } + if ( pSh->GetViewOptions()->IsReadonly() != bReadonly ) + pSh->SetReadonlyOption(bReadonly); + + lcl_SetUIPrefs(*xViewOpt, pCurrView, pSh); + + // in the end the Idle-Flag is set again + pPref->SetIdle(true); +} + +void SwModule::ApplyUserMetric( FieldUnit eMetric, bool bWeb ) +{ + SwMasterUsrPref* pPref; + if(bWeb) + { + if(!pWebUsrPref) + GetUsrPref(true); + pPref = pWebUsrPref; + } + else + { + if(!pUsrPref) + GetUsrPref(false); + pPref = pUsrPref; + } + FieldUnit eOldMetric = pPref->GetMetric(); + if(eOldMetric != eMetric) + pPref->SetMetric(eMetric); + + FieldUnit eHScrollMetric = pPref->IsHScrollMetric() ? pPref->GetHScrollMetric() : eMetric; + FieldUnit eVScrollMetric = pPref->IsVScrollMetric() ? pPref->GetVScrollMetric() : eMetric; + + SwView* pTmpView = SwModule::GetFirstView(); + // switch the ruler for all MDI-Windows + while(pTmpView) + { + if(bWeb == (0 != PTR_CAST(SwWebView, pTmpView))) + { + pTmpView->ChangeVRulerMetric(eVScrollMetric); + pTmpView->ChangeTabMetric(eHScrollMetric); + } + + pTmpView = SwModule::GetNextView(pTmpView); + } +} + +void SwModule::ApplyRulerMetric( FieldUnit eMetric, bool bHorizontal, bool bWeb ) +{ + SwMasterUsrPref* pPref; + if(bWeb) + { + if(!pWebUsrPref) + GetUsrPref(true); + pPref = pWebUsrPref; + } + else + { + if(!pUsrPref) + GetUsrPref(false); + pPref = pUsrPref; + } + if( bHorizontal ) + pPref->SetHScrollMetric(eMetric); + else + pPref->SetVScrollMetric(eMetric); + + SwView* pTmpView = SwModule::GetFirstView(); + // switch metric at the appropriate rulers + while(pTmpView) + { + if(bWeb == (0 != dynamic_cast<SwWebView *>( pTmpView ))) + { + if( bHorizontal ) + pTmpView->ChangeTabMetric(eMetric); + else + pTmpView->ChangeVRulerMetric(eMetric); + } + pTmpView = SwModule::GetNextView(pTmpView); + } +} + +//set the usrpref 's char unit attribute and set rulers unit as char if the "apply char unit" is checked +void SwModule::ApplyUserCharUnit(bool bApplyChar, bool bWeb) +{ + SwMasterUsrPref* pPref; + if(bWeb) + { + if(!pWebUsrPref) + GetUsrPref(true); + pPref = pWebUsrPref; + } + else + { + if(!pUsrPref) + GetUsrPref(false); + pPref = pUsrPref; + } + bool bOldApplyCharUnit = pPref->IsApplyCharUnit(); + bool bHasChanged = false; + if(bOldApplyCharUnit != bApplyChar) + { + pPref->SetApplyCharUnit(bApplyChar); + bHasChanged = true; + } + + if( !bHasChanged ) + return; + + FieldUnit eHScrollMetric = pPref->IsHScrollMetric() ? pPref->GetHScrollMetric() : pPref->GetMetric(); + FieldUnit eVScrollMetric = pPref->IsVScrollMetric() ? pPref->GetVScrollMetric() : pPref->GetMetric(); + if(bApplyChar) + { + eHScrollMetric = FUNIT_CHAR; + eVScrollMetric = FUNIT_LINE; + } + else + { + SvtCJKOptions aCJKOptions; + if ( !aCJKOptions.IsAsianTypographyEnabled() && ( eHScrollMetric == FUNIT_CHAR )) + eHScrollMetric = FUNIT_INCH; + else if ( eHScrollMetric == FUNIT_CHAR ) + eHScrollMetric = FUNIT_CM; + if ( !aCJKOptions.IsAsianTypographyEnabled() && ( eVScrollMetric == FUNIT_LINE )) + eVScrollMetric = FUNIT_INCH; + else if ( eVScrollMetric == FUNIT_LINE ) + eVScrollMetric = FUNIT_CM; + } + SwView* pTmpView = SwModule::GetFirstView(); + // switch rulers for all MDI-Windows + while(pTmpView) + { + if(bWeb == (0 != PTR_CAST(SwWebView, pTmpView))) + { + pTmpView->ChangeVRulerMetric(eVScrollMetric); + pTmpView->ChangeTabMetric(eHScrollMetric); + } + + pTmpView = SwModule::GetNextView(pTmpView); + } +} + +SwNavigationConfig* SwModule::GetNavigationConfig() +{ + if(!pNavigationConfig) + { + pNavigationConfig = new SwNavigationConfig; + } + return pNavigationConfig; +} + +SwPrintOptions* SwModule::GetPrtOptions(bool bWeb) +{ + if(bWeb && !pWebPrtOpt) + { + pWebPrtOpt = new SwPrintOptions(true); + } + else if(!bWeb && !pPrtOpt) + { + pPrtOpt = new SwPrintOptions(false); + } + + return bWeb ? pWebPrtOpt : pPrtOpt; +} + +SwChapterNumRules* SwModule::GetChapterNumRules() +{ + if(!pChapterNumRules) + pChapterNumRules = new SwChapterNumRules; + return pChapterNumRules; +} + +void SwModule::ShowDBObj(SwView& rView, const SwDBData& rData, bool /*bOnlyIfAvailable*/) +{ + Reference<XFrame> xFrame = rView.GetViewFrame()->GetFrame().GetFrameInterface(); + Reference<XDispatchProvider> xDP(xFrame, uno::UNO_QUERY); + + uno::Reference<XFrame> xBeamerFrame = xFrame->findFrame("_beamer", FrameSearchFlag::CHILDREN); + if (xBeamerFrame.is()) + { // the beamer has been opened by the SfxViewFrame + Reference<XController> xController = xBeamerFrame->getController(); + Reference<XSelectionSupplier> xControllerSelection(xController, UNO_QUERY); + if (xControllerSelection.is()) + { + + ODataAccessDescriptor aSelection; + aSelection.setDataSource(rData.sDataSource); + aSelection[daCommand] <<= rData.sCommand; + aSelection[daCommandType] <<= rData.nCommandType; + xControllerSelection->select(makeAny(aSelection.createPropertyValueSequence())); + } + else { + OSL_FAIL("no selection supplier in the beamer!"); + } + } +} + +sal_uInt16 SwModule::GetRedlineAuthor() +{ + if (!bAuthorInitialised) + { + const SvtUserOptions& rOpt = GetUserOptions(); + sActAuthor = rOpt.GetFullName(); + if (sActAuthor.isEmpty()) + { + sActAuthor = rOpt.GetID(); + if (sActAuthor.isEmpty()) + sActAuthor = SW_RESSTR( STR_REDLINE_UNKNOWN_AUTHOR ); + } + bAuthorInitialised = true; + } + return InsertRedlineAuthor( sActAuthor ); +} + +void SwModule::SetRedlineAuthor(const OUString &rAuthor) +{ + bAuthorInitialised = true; + sActAuthor = rAuthor; + InsertRedlineAuthor( sActAuthor ); +} + +OUString SwModule::GetRedlineAuthor(sal_uInt16 nPos) +{ + OSL_ENSURE(nPos < pAuthorNames->size(), "author not found!"); //#i45342# RTF doc with no author table caused reader to crash + while(!(nPos < pAuthorNames->size())) + { + InsertRedlineAuthor("nn"); + } + return (*pAuthorNames)[nPos]; +} + +sal_uInt16 SwModule::InsertRedlineAuthor(const OUString& rAuthor) +{ + sal_uInt16 nPos = 0; + + while(nPos < pAuthorNames->size() && (*pAuthorNames)[nPos] != rAuthor) + ++nPos; + + if (nPos == pAuthorNames->size()) + pAuthorNames->push_back(rAuthor); + + return nPos; +} + +static void lcl_FillAuthorAttr( sal_uInt16 nAuthor, SfxItemSet &rSet, + const AuthorCharAttr &rAttr ) +{ + Color aCol( rAttr.nColor ); + + if( COL_TRANSPARENT == rAttr.nColor ) + { + static const ColorData aColArr[] = { + COL_AUTHOR1_DARK, COL_AUTHOR2_DARK, COL_AUTHOR3_DARK, + COL_AUTHOR4_DARK, COL_AUTHOR5_DARK, COL_AUTHOR6_DARK, + COL_AUTHOR7_DARK, COL_AUTHOR8_DARK, COL_AUTHOR9_DARK }; + + aCol.SetColor( aColArr[ nAuthor % (sizeof( aColArr ) / + sizeof( aColArr[0] )) ] ); + } + + bool bBackGr = COL_NONE == rAttr.nColor; + + switch (rAttr.nItemId) + { + case SID_ATTR_CHAR_WEIGHT: + { + SvxWeightItem aW( (FontWeight)rAttr.nAttr, RES_CHRATR_WEIGHT ); + rSet.Put( aW ); + aW.SetWhich( RES_CHRATR_CJK_WEIGHT ); + rSet.Put( aW ); + aW.SetWhich( RES_CHRATR_CTL_WEIGHT ); + rSet.Put( aW ); + } + break; + + case SID_ATTR_CHAR_POSTURE: + { + SvxPostureItem aP( (FontItalic)rAttr.nAttr, RES_CHRATR_POSTURE ); + rSet.Put( aP ); + aP.SetWhich( RES_CHRATR_CJK_POSTURE ); + rSet.Put( aP ); + aP.SetWhich( RES_CHRATR_CTL_POSTURE ); + rSet.Put( aP ); + } + break; + + case SID_ATTR_CHAR_UNDERLINE: + rSet.Put( SvxUnderlineItem( (FontUnderline)rAttr.nAttr, + RES_CHRATR_UNDERLINE)); + break; + + case SID_ATTR_CHAR_STRIKEOUT: + rSet.Put(SvxCrossedOutItem( (FontStrikeout)rAttr.nAttr, + RES_CHRATR_CROSSEDOUT)); + break; + + case SID_ATTR_CHAR_CASEMAP: + rSet.Put( SvxCaseMapItem( (SvxCaseMap)rAttr.nAttr, + RES_CHRATR_CASEMAP)); + break; + + case SID_ATTR_BRUSH: + rSet.Put( SvxBrushItem( aCol, RES_CHRATR_BACKGROUND )); + bBackGr = true; + break; + } + + if( !bBackGr ) + rSet.Put( SvxColorItem( aCol, RES_CHRATR_COLOR ) ); +} + +void SwModule::GetInsertAuthorAttr(sal_uInt16 nAuthor, SfxItemSet &rSet) +{ + lcl_FillAuthorAttr(nAuthor, rSet, pModuleConfig->GetInsertAuthorAttr()); +} + +void SwModule::GetDeletedAuthorAttr(sal_uInt16 nAuthor, SfxItemSet &rSet) +{ + lcl_FillAuthorAttr(nAuthor, rSet, pModuleConfig->GetDeletedAuthorAttr()); +} + +// For future extension: +void SwModule::GetFormatAuthorAttr( sal_uInt16 nAuthor, SfxItemSet &rSet ) +{ + lcl_FillAuthorAttr( nAuthor, rSet, pModuleConfig->GetFormatAuthorAttr() ); +} + +sal_uInt16 SwModule::GetRedlineMarkPos() +{ + return pModuleConfig->GetMarkAlignMode(); +} + +bool SwModule::IsInsTblFormatNum(bool bHTML) const +{ + return pModuleConfig->IsInsTblFormatNum(bHTML); +} + +bool SwModule::IsInsTblChangeNumFormat(bool bHTML) const +{ + return pModuleConfig->IsInsTblChangeNumFormat(bHTML); +} + +bool SwModule::IsInsTblAlignNum(bool bHTML) const +{ + return pModuleConfig->IsInsTblAlignNum(bHTML); +} + +const Color &SwModule::GetRedlineMarkColor() +{ + return pModuleConfig->GetMarkAlignColor(); +} + +const SwViewOption* SwModule::GetViewOption(bool bWeb) +{ + return GetUsrPref( bWeb ); +} + +OUString SwModule::GetDocStatWordDelim() const +{ + return pModuleConfig->GetWordDelimiter(); +} + +// Passing-through of the ModuleConfig's Metric (for HTML-Export) +sal_uInt16 SwModule::GetMetric( bool bWeb ) const +{ + SwMasterUsrPref* pPref; + if(bWeb) + { + if(!pWebUsrPref) + GetUsrPref(true); + pPref = pWebUsrPref; + } + else + { + if(!pUsrPref) + GetUsrPref(false); + pPref = pUsrPref; + } + return static_cast< sal_uInt16 >(pPref->GetMetric()); +} + +// Pass-through Update-Status +sal_uInt16 SwModule::GetLinkUpdMode( bool ) const +{ + if(!pUsrPref) + GetUsrPref(false); + return (sal_uInt16)pUsrPref->GetUpdateLinkMode(); +} + +SwFldUpdateFlags SwModule::GetFldUpdateFlags( bool ) const +{ + if(!pUsrPref) + GetUsrPref(false); + return pUsrPref->GetFldUpdateFlags(); +} + +void SwModule::ApplyFldUpdateFlags(SwFldUpdateFlags eFldFlags) +{ + if(!pUsrPref) + GetUsrPref(false); + pUsrPref->SetFldUpdateFlags(eFldFlags); +} + +void SwModule::ApplyLinkMode(sal_Int32 nNewLinkMode) +{ + if(!pUsrPref) + GetUsrPref(false); + pUsrPref->SetUpdateLinkMode(nNewLinkMode); +} + +void SwModule::CheckSpellChanges( bool bOnlineSpelling, + bool bIsSpellWrongAgain, bool bIsSpellAllAgain, bool bSmartTags ) +{ + bool bOnlyWrong = bIsSpellWrongAgain && !bIsSpellAllAgain; + bool bInvalid = bOnlyWrong || bIsSpellAllAgain; + if( bOnlineSpelling || bInvalid ) + { + TypeId aType = TYPE(SwDocShell); + for( SwDocShell *pDocSh = (SwDocShell*)SfxObjectShell::GetFirst(&aType); + pDocSh; + pDocSh = (SwDocShell*)SfxObjectShell::GetNext( *pDocSh, &aType ) ) + { + SwDoc* pTmp = pDocSh->GetDoc(); + if ( pTmp->GetCurrentViewShell() ) + { + pTmp->SpellItAgainSam( bInvalid, bOnlyWrong, bSmartTags ); + SwViewShell* pViewShell = 0; + pTmp->GetEditShell( &pViewShell ); + if ( bSmartTags && pViewShell && pViewShell->GetWin() ) + pViewShell->GetWin()->Invalidate(); + } + } + } +} + +void SwModule::ApplyDefaultPageMode(bool bIsSquaredPageMode) +{ + if(!pUsrPref) + GetUsrPref(false); + pUsrPref->SetDefaultPageMode(bIsSquaredPageMode); +} + +SvxCompareMode SwModule::GetCompareMode() const +{ + return pModuleConfig->GetCompareMode(); +} + +bool SwModule::IsUseRsid() const +{ + return pModuleConfig->IsUseRsid(); +} + +bool SwModule::IsIgnorePieces() const +{ + return pModuleConfig->IsIgnorePieces(); +} + +sal_uInt16 SwModule::GetPieceLen() const +{ + return pModuleConfig->GetPieceLen(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/swmodule.cxx b/sw/source/uibase/app/swmodule.cxx new file mode 100644 index 000000000000..f2f33eed0209 --- /dev/null +++ b/sw/source/uibase/app/swmodule.cxx @@ -0,0 +1,421 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <config_features.h> + +#include <hintids.hxx> +#include <swerror.h> +#include <vcl/wrkwin.hxx> +#include <vcl/graph.hxx> +#include <svx/galbrws.hxx> +#include <svx/svdobj.hxx> +#include <svtools/ehdl.hxx> +#include <svx/fntszctl.hxx> +#include <svx/fntctl.hxx> +#include <svx/SmartTagCtl.hxx> +#include <svx/pszctrl.hxx> +#include <svx/insctrl.hxx> +#include <svx/selctrl.hxx> +#include <svx/linectrl.hxx> +#include <svx/tbxctl.hxx> +#include <svx/fillctrl.hxx> +#include <svx/tbcontrl.hxx> +#include <svx/verttexttbxctrl.hxx> +#include <svx/formatpaintbrushctrl.hxx> +#include <svx/contdlg.hxx> +#include <svx/layctrl.hxx> +#include <svx/fontwork.hxx> +#include <SwSpellDialogChildWindow.hxx> +#include <svx/tbxalign.hxx> +#include <svx/grafctrl.hxx> +#include <svx/tbxcolor.hxx> +#include <svx/clipboardctl.hxx> +#include <svx/lboxctrl.hxx> +#include <svx/tbxcustomshapes.hxx> +#include <svx/imapdlg.hxx> +#include <svx/srchdlg.hxx> +#include <svx/hyperdlg.hxx> +#include <svx/fontworkgallery.hxx> +#include <svx/modctrl.hxx> +#include <com/sun/star/scanner/ScannerManager.hpp> +#include <com/sun/star/container/XSet.hpp> +#include <com/sun/star/linguistic2/LanguageGuessing.hpp> +#include <comphelper/processfactory.hxx> +#include <docsh.hxx> +#include <swmodule.hxx> +#include <swevent.hxx> +#include <swacorr.hxx> +#include <cmdid.h> +#include <dobjfac.hxx> +#include <init.hxx> +#include <pview.hxx> +#include <wview.hxx> +#include <wdocsh.hxx> +#include <globdoc.hxx> +#include <srcview.hxx> +#include <glshell.hxx> +#include <tabsh.hxx> +#include <listsh.hxx> +#include <grfsh.hxx> +#include <mediash.hxx> +#include <olesh.hxx> +#include <drawsh.hxx> +#include <wformsh.hxx> +#include <drwtxtsh.hxx> +#include <beziersh.hxx> +#include <wtextsh.hxx> +#include <wfrmsh.hxx> +#include <drformsh.hxx> +#include <wgrfsh.hxx> +#include <wolesh.hxx> +#include <wlistsh.hxx> +#include <wtabsh.hxx> +#include <navipi.hxx> +#include <chartins.hxx> +#include <inputwin.hxx> +#include <usrpref.hxx> +#include <uinums.hxx> +#include <prtopt.hxx> +#include <bookctrl.hxx> +#include <tmplctrl.hxx> +#include <viewlayoutctrl.hxx> +#include <svx/zoomsliderctrl.hxx> +#include <tblctrl.hxx> +#include <zoomctrl.hxx> +#include <wordcountctrl.hxx> +#include <workctrl.hxx> +#include <tbxanchr.hxx> +#include <fldwrap.hxx> +#include <redlndlg.hxx> +#include <syncbtn.hxx> +#include <mailmergechildwindow.hxx> +#include <modcfg.hxx> +#include <fontcfg.hxx> +#include <sfx2/sidebar/SidebarChildWindow.hxx> +#include <sfx2/taskpane.hxx> +#include <sfx2/evntconf.hxx> +#include <swatrset.hxx> +#include <idxmrk.hxx> +#include <wordcountdialog.hxx> +#include <dlelstnr.hxx> +#include <barcfg.hxx> +#include <svx/rubydialog.hxx> +#include <svtools/colorcfg.hxx> + +#include <editeng/acorrcfg.hxx> +#include <unotools/moduleoptions.hxx> + +#include <avmedia/mediaplayer.hxx> +#include <avmedia/mediatoolbox.hxx> + +#include <annotsh.hxx> +#include <navsh.hxx> + +#include <app.hrc> +#include <svx/xmlsecctrl.hxx> +ResMgr *pSwResMgr = 0; +bool bNoInterrupt = false; + +#include <sfx2/app.hxx> + +#include <svx/svxerr.hxx> + +#include <unomid.h> + +#include "swdllimpl.hxx" + +using namespace com::sun::star; + +TYPEINIT1( SwModule, SfxModule ); + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +SwModule::SwModule( SfxObjectFactory* pWebFact, + SfxObjectFactory* pFact, + SfxObjectFactory* pGlobalFact ) + : SfxModule( SfxApplication::CreateResManager( "sw" ), false, pWebFact, + pFact, pGlobalFact, NULL ), + pModuleConfig(0), + pUsrPref(0), + pWebUsrPref(0), + pPrtOpt(0), + pWebPrtOpt(0), + pChapterNumRules(0), + pStdFontConfig(0), + pNavigationConfig(0), + pToolbarConfig(0), + pWebToolbarConfig(0), + pDBConfig(0), + pColorConfig(0), + pAccessibilityOptions(0), + pCTLOptions(0), + pUserOptions(0), + pAttrPool(0), + pView(0), + bAuthorInitialised(false), + bEmbeddedLoadSave( false ), + pDragDrop( 0 ), + pXSelection( 0 ) +{ + SetName( OUString("StarWriter") ); + pSwResMgr = GetResMgr(); + SvxErrorHandler::ensure(); + pErrorHdl = new SfxErrorHandler( RID_SW_ERRHDL, + ERRCODE_AREA_SW, + ERRCODE_AREA_SW_END, + pSwResMgr ); + + pModuleConfig = new SwModuleOptions; + + // We need them anyways + pToolbarConfig = new SwToolbarConfigItem( false ); + pWebToolbarConfig = new SwToolbarConfigItem( true ); + + pStdFontConfig = new SwStdFontConfig; + + pAuthorNames = new std::vector<OUString>; // All Redlining-Authors + + // replace SvxAutocorrect with SwAutocorrect + SvxAutoCorrCfg& rACfg = SvxAutoCorrCfg::Get(); + const SvxAutoCorrect* pOld = rACfg.GetAutoCorrect(); + rACfg.SetAutoCorrect(new SwAutoCorrect( *pOld )); + + StartListening( *SFX_APP() ); + + // OD 14.02.2003 #107424# - init color configuration + // member <pColorConfig> is created and the color configuration is applied + // at the view options. + GetColorConfig(); +} +uno::Reference< scanner::XScannerManager2 > +SwModule::GetScannerManager() +{ + if (!m_xScannerManager.is()) + { + m_xScannerManager = scanner::ScannerManager::create( comphelper::getProcessComponentContext() ); + } + return m_xScannerManager; +} + +uno::Reference< linguistic2::XLanguageGuessing > SwModule::GetLanguageGuesser() +{ + if (!m_xLanguageGuesser.is()) + { + m_xLanguageGuesser = linguistic2::LanguageGuessing::create( comphelper::getProcessComponentContext() ); + } + return m_xLanguageGuesser; +} + +SwModule::~SwModule() +{ + delete pErrorHdl; + EndListening( *SFX_APP() ); +} + +void SwModule::CreateLngSvcEvtListener() +{ + if (!xLngSvcEvtListener.is()) + xLngSvcEvtListener = new SwLinguServiceEventListener; +} + +void SwDLL::RegisterFactories() +{ + // These Id's must not be changed. Through these Id's the View (resume Documentview) + // is created by Sfx. + if ( SvtModuleOptions().IsWriter() ) + SwView::RegisterFactory ( 2 ); + +#if HAVE_FEATURE_DESKTOP + SwWebView::RegisterFactory ( 5 ); + + if ( SvtModuleOptions().IsWriter() ) + { + SwSrcView::RegisterFactory ( 6 ); + SwPagePreview::RegisterFactory ( 7 ); + } +#endif +} + +void SwDLL::RegisterInterfaces() +{ + SwModule* pMod = SW_MOD(); + SwModule::RegisterInterface( pMod ); + SwDocShell::RegisterInterface( pMod ); + SwWebDocShell::RegisterInterface( pMod ); + SwGlosDocShell::RegisterInterface( pMod ); + SwWebGlosDocShell::RegisterInterface( pMod ); + SwView::RegisterInterface( pMod ); + SwWebView::RegisterInterface( pMod ); + SwPagePreview::RegisterInterface( pMod ); + SwSrcView::RegisterInterface( pMod ); + + SwBaseShell::RegisterInterface(pMod); + SwTextShell::RegisterInterface(pMod); + SwTableShell::RegisterInterface(pMod); + SwListShell::RegisterInterface(pMod); + SwFrameShell::RegisterInterface(pMod); + SwDrawBaseShell::RegisterInterface(pMod); + SwDrawShell::RegisterInterface(pMod); + SwDrawFormShell::RegisterInterface(pMod); + SwDrawTextShell::RegisterInterface(pMod); + SwBezierShell::RegisterInterface(pMod); + SwGrfShell::RegisterInterface(pMod); + SwOleShell::RegisterInterface(pMod); + SwNavigationShell::RegisterInterface(pMod); + SwWebTextShell::RegisterInterface(pMod); + SwWebFrameShell::RegisterInterface(pMod); + SwWebGrfShell::RegisterInterface(pMod); + SwWebListShell::RegisterInterface(pMod); + SwWebTableShell::RegisterInterface(pMod); + SwWebDrawFormShell::RegisterInterface(pMod); + SwWebOleShell::RegisterInterface(pMod); + SwMediaShell::RegisterInterface(pMod); + SwAnnotationShell::RegisterInterface(pMod); +} + +void SwDLL::RegisterControls() +{ + SwModule* pMod = SW_MOD(); + + SfxRecentFilesToolBoxControl::RegisterControl( FN_OPEN_FILE, pMod ); + SvxTbxCtlDraw::RegisterControl(SID_INSERT_DRAW, pMod ); + SvxTbxCtlAlign::RegisterControl(SID_OBJECT_ALIGN, pMod ); + SwTbxAnchor::RegisterControl(FN_TOOL_ANCHOR, pMod ); + SwTbxInsertCtrl::RegisterControl(FN_INSERT_CTRL, pMod ); + SwTbxInsertCtrl::RegisterControl(FN_INSERT_OBJ_CTRL, pMod ); + SwTbxFieldCtrl::RegisterControl(FN_INSERT_FIELD_CTRL, pMod ); + SwTbxAutoTextCtrl::RegisterControl(FN_GLOSSARY_DLG, pMod ); + + SvxTbxCtlCustomShapes::RegisterControl( SID_DRAWTBX_CS_BASIC, pMod ); + SvxTbxCtlCustomShapes::RegisterControl( SID_DRAWTBX_CS_SYMBOL, pMod ); + SvxTbxCtlCustomShapes::RegisterControl( SID_DRAWTBX_CS_ARROW, pMod ); + SvxTbxCtlCustomShapes::RegisterControl( SID_DRAWTBX_CS_FLOWCHART, pMod ); + SvxTbxCtlCustomShapes::RegisterControl( SID_DRAWTBX_CS_CALLOUT, pMod ); + SvxTbxCtlCustomShapes::RegisterControl( SID_DRAWTBX_CS_STAR, pMod ); + + SvxColorToolBoxControl::RegisterControl( SID_EXTRUSION_3D_COLOR, pMod ); + svx::FontWorkShapeTypeControl::RegisterControl( SID_FONTWORK_SHAPE_TYPE, pMod ); + + SvxClipBoardControl::RegisterControl(SID_PASTE, pMod ); + SvxUndoRedoControl::RegisterControl(SID_UNDO, pMod ); + SvxUndoRedoControl::RegisterControl(SID_REDO, pMod ); + svx::FormatPaintBrushToolBoxControl::RegisterControl(SID_FORMATPAINTBRUSH, pMod ); + + SvxFillToolBoxControl::RegisterControl(SID_ATTR_FILL_STYLE, pMod ); + SvxLineStyleToolBoxControl::RegisterControl(SID_ATTR_LINE_STYLE, pMod ); + SvxLineWidthToolBoxControl::RegisterControl(SID_ATTR_LINE_WIDTH, pMod ); + SvxLineColorToolBoxControl::RegisterControl(SID_ATTR_LINE_COLOR, pMod ); + SvxLineEndToolBoxControl::RegisterControl(SID_ATTR_LINEEND_STYLE, pMod ); + + SvxFontNameToolBoxControl::RegisterControl(SID_ATTR_CHAR_FONT, pMod ); + SvxColorToolBoxControl::RegisterControl(SID_ATTR_CHAR_COLOR, pMod ); + SvxColorToolBoxControl::RegisterControl(SID_ATTR_CHAR_COLOR2, pMod ); + SvxColorToolBoxControl::RegisterControl(SID_ATTR_CHAR_COLOR_BACKGROUND, pMod ); + SvxStyleToolBoxControl::RegisterControl(SID_STYLE_APPLY, pMod ); + SvxColorToolBoxControl::RegisterControl( SID_BACKGROUND_COLOR, pMod ); + SvxFrameToolBoxControl::RegisterControl(SID_ATTR_BORDER, pMod ); + SvxFrameLineStyleToolBoxControl::RegisterControl(SID_FRAME_LINESTYLE, pMod ); + SvxColorToolBoxControl::RegisterControl(SID_FRAME_LINECOLOR, pMod ); + + SvxColumnsToolBoxControl::RegisterControl(FN_INSERT_FRAME_INTERACT, pMod ); + SvxColumnsToolBoxControl::RegisterControl(FN_INSERT_FRAME, pMod ); + SvxColumnsToolBoxControl::RegisterControl(FN_INSERT_REGION, pMod ); + SvxTableToolBoxControl::RegisterControl(FN_INSERT_TABLE, pMod ); + SvxTableToolBoxControl::RegisterControl(FN_SHOW_MULTIPLE_PAGES, pMod ); + + SvxFontMenuControl::RegisterControl(SID_ATTR_CHAR_FONT, pMod ); + SvxFontSizeMenuControl::RegisterControl(SID_ATTR_CHAR_FONTHEIGHT, pMod ); + + SwZoomControl::RegisterControl(SID_ATTR_ZOOM, pMod ); + SwPreviewZoomControl::RegisterControl(FN_PREVIEW_ZOOM, pMod); + SvxPosSizeStatusBarControl::RegisterControl(0, pMod ); + SvxInsertStatusBarControl::RegisterControl(SID_ATTR_INSERT, pMod ); + SvxSelectionModeControl::RegisterControl(FN_STAT_SELMODE, pMod ); + XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE, pMod ); + SwWordCountStatusBarControl::RegisterControl(FN_STAT_WORDCOUNT, pMod); + + SwBookmarkControl::RegisterControl(FN_STAT_PAGE, pMod ); + SwTemplateControl::RegisterControl(FN_STAT_TEMPLATE, pMod ); + SwViewLayoutControl::RegisterControl( SID_ATTR_VIEWLAYOUT, pMod ); + SvxModifyControl::RegisterControl( SID_DOC_MODIFIED, pMod ); + SvxZoomSliderControl::RegisterControl( SID_ATTR_ZOOMSLIDER, pMod ); + + SwTableOptimizeCtrl::RegisterControl(FN_OPTIMIZE_TABLE, pMod); + + SvxIMapDlgChildWindow::RegisterChildWindow( false, pMod ); + SvxSearchDialogWrapper::RegisterChildWindow( false, pMod ); + SvxHlinkDlgWrapper::RegisterChildWindow( false, pMod ); + SvxFontWorkChildWindow::RegisterChildWindow( false, pMod ); + SwFldDlgWrapper::RegisterChildWindow( false, pMod ); + SwFldDataOnlyDlgWrapper::RegisterChildWindow( false, pMod ); + SvxContourDlgChildWindow::RegisterChildWindow( false, pMod ); + SwNavigationChild::RegisterChildWindowContext( pMod ); + SwInputChild::RegisterChildWindow( false, pMod, SFX_CHILDWIN_FORCEDOCK ); + SwRedlineAcceptChild::RegisterChildWindow( false, pMod ); + SwSyncChildWin::RegisterChildWindow( true, pMod ); + SwMailMergeChildWindow::RegisterChildWindow( false, pMod ); + SwInsertIdxMarkWrapper::RegisterChildWindow( false, pMod ); + SwInsertAuthMarkWrapper::RegisterChildWindow( false, pMod ); + SwWordCountWrapper::RegisterChildWindow( false, pMod ); + SvxRubyChildWindow::RegisterChildWindow( false, pMod); + SwSpellDialogChildWindow::RegisterChildWindow(false, pMod); + + SvxGrafRedToolBoxControl::RegisterControl( SID_ATTR_GRAF_RED, pMod ); + SvxGrafGreenToolBoxControl::RegisterControl( SID_ATTR_GRAF_GREEN, pMod ); + SvxGrafBlueToolBoxControl::RegisterControl( SID_ATTR_GRAF_BLUE, pMod ); + SvxGrafLuminanceToolBoxControl::RegisterControl( SID_ATTR_GRAF_LUMINANCE, pMod ); + SvxGrafContrastToolBoxControl::RegisterControl( SID_ATTR_GRAF_CONTRAST, pMod ); + SvxGrafGammaToolBoxControl::RegisterControl( SID_ATTR_GRAF_GAMMA, pMod ); + SvxGrafTransparenceToolBoxControl::RegisterControl( SID_ATTR_GRAF_TRANSPARENCE, pMod ); + SvxGrafModeToolBoxControl::RegisterControl( SID_ATTR_GRAF_MODE, pMod ); + SvxGrafFilterToolBoxControl::RegisterControl( SID_GRFFILTER, pMod ); + SvxVertTextTbxCtrl::RegisterControl(SID_TEXTDIRECTION_LEFT_TO_RIGHT, pMod); + SvxVertTextTbxCtrl::RegisterControl(SID_TEXTDIRECTION_TOP_TO_BOTTOM, pMod); + SvxVertTextTbxCtrl::RegisterControl(SID_DRAW_CAPTION_VERTICAL, pMod); + SvxVertTextTbxCtrl::RegisterControl(SID_DRAW_TEXT_VERTICAL, pMod); + + SvxCTLTextTbxCtrl::RegisterControl(SID_ATTR_PARA_LEFT_TO_RIGHT, pMod); + SvxCTLTextTbxCtrl::RegisterControl(SID_ATTR_PARA_RIGHT_TO_LEFT, pMod); + + GalleryChildWindow::RegisterChildWindow(false, pMod); + + ::avmedia::MediaToolBoxControl::RegisterControl(SID_AVMEDIA_TOOLBOX, pMod); + ::avmedia::MediaPlayer::RegisterChildWindow(false, pMod); + + SvxSmartTagsControl::RegisterControl(SID_OPEN_SMARTTAGMENU, pMod); + ::sfx2::sidebar::SidebarChildWindow::RegisterChildWindow(false, pMod); + ::sfx2::TaskPaneWrapper::RegisterChildWindow(false, pMod); +} + +// Load Module (only dummy for linking of the DLL) +void SwModule::InitAttrPool() +{ + OSL_ENSURE(!pAttrPool, "Pool already exists!"); + pAttrPool = new SwAttrPool(0); + SetPool(pAttrPool); +} + +void SwModule::RemoveAttrPool() +{ + SetPool(0); + SfxItemPool::Free(pAttrPool); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/swwait.cxx b/sw/source/uibase/app/swwait.cxx new file mode 100644 index 000000000000..01647c62a7bf --- /dev/null +++ b/sw/source/uibase/app/swwait.cxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <swwait.hxx> +#include <docsh.hxx> + +#include <sfx2/viewfrm.hxx> +#include <sfx2/dispatch.hxx> +#include <vcl/window.hxx> + +SwWait::SwWait( + SwDocShell &rDocShell, + const bool bLockUnlockDispatcher ) + : mrDoc ( rDocShell ) + , mbLockUnlockDispatcher( bLockUnlockDispatcher ) + , mpLockedDispatchers() +{ + EnterWaitAndLockDispatcher(); +} + +SwWait::~SwWait() +{ + LeaveWaitAndUnlockDispatcher(); +} + +void SwWait::EnterWaitAndLockDispatcher() +{ + SfxViewFrame *pFrame = SfxViewFrame::GetFirst( &mrDoc, false ); + while ( pFrame ) + { + pFrame->GetWindow().EnterWait(); + if ( mbLockUnlockDispatcher ) + { + // do not look already locked dispatchers + SfxDispatcher* pDispatcher = pFrame->GetDispatcher(); + if ( !pDispatcher->IsLocked() ) + { + pDispatcher->Lock( true ); + mpLockedDispatchers.insert( pDispatcher ); + } + } + + pFrame = SfxViewFrame::GetNext( *pFrame, &mrDoc, false ); + } +} + +void SwWait::LeaveWaitAndUnlockDispatcher() +{ + SfxViewFrame *pFrame = SfxViewFrame::GetFirst( &mrDoc, false ); + while ( pFrame ) + { + pFrame->GetWindow().LeaveWait(); + if ( mbLockUnlockDispatcher ) + { + // only unlock dispatchers which had been locked + SfxDispatcher* pDispatcher = pFrame->GetDispatcher(); + if ( mpLockedDispatchers.find( pDispatcher ) != mpLockedDispatchers.end() ) + { + mpLockedDispatchers.erase( pDispatcher ); + pDispatcher->Lock( false ); + } + } + + pFrame = SfxViewFrame::GetNext( *pFrame, &mrDoc, false ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |