1*efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*efeef26fSAndrew Rist * distributed with this work for additional information 6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10*efeef26fSAndrew Rist * 11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*efeef26fSAndrew Rist * 13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*efeef26fSAndrew Rist * software distributed under the License is distributed on an 15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17*efeef26fSAndrew Rist * specific language governing permissions and limitations 18*efeef26fSAndrew Rist * under the License. 19*efeef26fSAndrew Rist * 20*efeef26fSAndrew Rist *************************************************************/ 21*efeef26fSAndrew Rist 22*efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sw.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <hintids.hxx> 29cdf0e10cSrcweir #include <editeng/wghtitem.hxx> 30cdf0e10cSrcweir #include <editeng/adjitem.hxx> 31cdf0e10cSrcweir #ifndef __RSC //autogen 32cdf0e10cSrcweir #include <tools/errinf.hxx> 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen 35cdf0e10cSrcweir #include <vcl/msgbox.hxx> 36cdf0e10cSrcweir #endif 37cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen 38cdf0e10cSrcweir #include <vcl/msgbox.hxx> 39cdf0e10cSrcweir #endif 40cdf0e10cSrcweir #include <svl/macitem.hxx> 41cdf0e10cSrcweir #include <sfx2/fcontnr.hxx> 42cdf0e10cSrcweir #include <sfx2/docfile.hxx> 43cdf0e10cSrcweir #define _SVSTDARR_STRINGS 44cdf0e10cSrcweir #include <svl/svstdarr.hxx> 45cdf0e10cSrcweir #include <svl/urihelper.hxx> 46cdf0e10cSrcweir #include <unotools/transliterationwrapper.hxx> 47cdf0e10cSrcweir #include <poolfmt.hxx> 48cdf0e10cSrcweir #include <fmtcol.hxx> 49cdf0e10cSrcweir #include <docary.hxx> 50cdf0e10cSrcweir #include <wrtsh.hxx> 51cdf0e10cSrcweir #include <uitool.hxx> // Fehlermeldungen 52cdf0e10cSrcweir #include <view.hxx> 53cdf0e10cSrcweir #include <swevent.hxx> 54cdf0e10cSrcweir #include <gloshdl.hxx> 55cdf0e10cSrcweir #include <glosdoc.hxx> 56cdf0e10cSrcweir #include <shellio.hxx> 57cdf0e10cSrcweir #include <swundo.hxx> // fuer Undo-Ids 58cdf0e10cSrcweir #include <expfld.hxx> 59cdf0e10cSrcweir #include <initui.hxx> // fuer ::GetGlossaries() 60cdf0e10cSrcweir #include <gloslst.hxx> 61cdf0e10cSrcweir #include <swdtflvr.hxx> 62cdf0e10cSrcweir #ifndef _DOCSH_HXX 63cdf0e10cSrcweir #include <docsh.hxx> 64cdf0e10cSrcweir #endif 65cdf0e10cSrcweir #include <crsskip.hxx> 66cdf0e10cSrcweir 67cdf0e10cSrcweir #ifndef _DOCHDL_HRC 68cdf0e10cSrcweir #include <dochdl.hrc> 69cdf0e10cSrcweir #endif 70cdf0e10cSrcweir #ifndef _SWERROR_H 71cdf0e10cSrcweir #include <swerror.h> 72cdf0e10cSrcweir #endif 73cdf0e10cSrcweir #include <frmmgr.hxx> 74cdf0e10cSrcweir #ifndef _LSTBOX_HXX //autogen 75cdf0e10cSrcweir #include <vcl/lstbox.hxx> 76cdf0e10cSrcweir #endif 77cdf0e10cSrcweir 78cdf0e10cSrcweir #include <editeng/acorrcfg.hxx> 79cdf0e10cSrcweir #include "swabstdlg.hxx" 80cdf0e10cSrcweir #include <misc.hrc> 81cdf0e10cSrcweir 82cdf0e10cSrcweir #include <IDocumentFieldsAccess.hxx> 83cdf0e10cSrcweir 84cdf0e10cSrcweir using namespace ::com::sun::star; 85cdf0e10cSrcweir 86cdf0e10cSrcweir 87cdf0e10cSrcweir const short RET_EDIT = 100; 88cdf0e10cSrcweir 89cdf0e10cSrcweir // PUBLIC METHODES ------------------------------------------------------- 90cdf0e10cSrcweir struct TextBlockInfo_Impl 91cdf0e10cSrcweir { 92cdf0e10cSrcweir String sTitle; 93cdf0e10cSrcweir String sLongName; 94cdf0e10cSrcweir String sGroupName; 95cdf0e10cSrcweir }; 96cdf0e10cSrcweir typedef TextBlockInfo_Impl* TextBlockInfo_ImplPtr; 97cdf0e10cSrcweir SV_DECL_PTRARR_DEL( TextBlockInfoArr, TextBlockInfo_ImplPtr, 0, 4 ) 98cdf0e10cSrcweir SV_IMPL_PTRARR( TextBlockInfoArr, TextBlockInfo_ImplPtr ) 99cdf0e10cSrcweir SV_IMPL_REF( SwDocShell ) 100cdf0e10cSrcweir /*------------------------------------------------------------------------ 101cdf0e10cSrcweir Beschreibung: Dialog fuer Bearbeiten Vorlagen 102cdf0e10cSrcweir ------------------------------------------------------------------------*/ 103cdf0e10cSrcweir 104cdf0e10cSrcweir 105cdf0e10cSrcweir void SwGlossaryHdl::GlossaryDlg() 106cdf0e10cSrcweir { 107cdf0e10cSrcweir SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); 108cdf0e10cSrcweir DBG_ASSERT(pFact, "Dialogdiet fail!"); 109cdf0e10cSrcweir AbstractGlossaryDlg* pDlg = pFact->CreateGlossaryDlg( DLG_RENAME_GLOS, 110cdf0e10cSrcweir pViewFrame, this, pWrtShell); 111cdf0e10cSrcweir DBG_ASSERT(pDlg, "Dialogdiet fail!"); 112cdf0e10cSrcweir String sName, sShortName; 113cdf0e10cSrcweir 114cdf0e10cSrcweir if( RET_EDIT == pDlg->Execute() ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir sName = pDlg->GetCurrGrpName(); 117cdf0e10cSrcweir sShortName = pDlg->GetCurrShortName(); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir delete pDlg; 121cdf0e10cSrcweir DELETEZ(pCurGrp); 122cdf0e10cSrcweir if(HasGlossaryList()) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir GetGlossaryList()->ClearGroups(); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir if( sName.Len() || sShortName.Len() ) 128cdf0e10cSrcweir rStatGlossaries.EditGroupDoc( sName, sShortName ); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir /*------------------------------------------------------------------------ 132cdf0e10cSrcweir Beschreibung: Setzen der aktuellen Gruppe; falls aus dem Dialog 133cdf0e10cSrcweir gerufen, wird die Gruppe temp. erzeugt fuer einen 134cdf0e10cSrcweir schnelleren Zugriff 135cdf0e10cSrcweir ------------------------------------------------------------------------*/ 136cdf0e10cSrcweir 137cdf0e10cSrcweir 138cdf0e10cSrcweir void SwGlossaryHdl::SetCurGroup(const String &rGrp, sal_Bool bApi, sal_Bool bAlwaysCreateNew ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir String sGroup(rGrp); 141cdf0e10cSrcweir if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM) && !FindGroupName(sGroup)) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir sGroup += GLOS_DELIM; 144cdf0e10cSrcweir sGroup += '0'; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir if(pCurGrp) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir sal_Bool bPathEqual = sal_False; 149cdf0e10cSrcweir if(!bAlwaysCreateNew) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir INetURLObject aTemp( pCurGrp->GetFileName() ); 152cdf0e10cSrcweir String sCurBase = aTemp.getBase(); 153cdf0e10cSrcweir aTemp.removeSegment(); 154cdf0e10cSrcweir const String sCurEntryPath = aTemp.GetMainURL(INetURLObject::NO_DECODE); 155cdf0e10cSrcweir const SvStrings* pPathArr = rStatGlossaries.GetPathArray(); 156cdf0e10cSrcweir sal_uInt16 nCurrentPath = USHRT_MAX; 157cdf0e10cSrcweir for(sal_uInt16 nPath = 0; nPath < pPathArr->Count(); nPath++) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir if(sCurEntryPath == *(*pPathArr)[nPath]) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir nCurrentPath = nPath; 162cdf0e10cSrcweir break; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir } 165cdf0e10cSrcweir String sPath = sGroup.GetToken(1, GLOS_DELIM); 166cdf0e10cSrcweir sal_uInt16 nComparePath = (sal_uInt16)sPath.ToInt32(); 167cdf0e10cSrcweir if(nCurrentPath == nComparePath && 168cdf0e10cSrcweir sGroup.GetToken(0, GLOS_DELIM) == sCurBase) 169cdf0e10cSrcweir bPathEqual = sal_True; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir // const String aMac_Tmp(pCurGrp->GetName()); 172cdf0e10cSrcweir // Beim Pfadwechsel kann man sich auf den Namen nicht verlassen 173cdf0e10cSrcweir if(!bAlwaysCreateNew && 174cdf0e10cSrcweir bPathEqual 175cdf0e10cSrcweir // aMac_Tmp == sGroup 176cdf0e10cSrcweir ) 177cdf0e10cSrcweir return; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir aCurGrp = sGroup; 180cdf0e10cSrcweir if(!bApi) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir if(pCurGrp) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir rStatGlossaries.PutGroupDoc(pCurGrp); 185cdf0e10cSrcweir pCurGrp = 0; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir pCurGrp = rStatGlossaries.GetGroupDoc(aCurGrp, sal_True); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir /*------------------------------------------------------------------------ 192cdf0e10cSrcweir Beschreibung: 193cdf0e10cSrcweir ------------------------------------------------------------------------*/ 194cdf0e10cSrcweir 195cdf0e10cSrcweir 196cdf0e10cSrcweir sal_uInt16 SwGlossaryHdl::GetGroupCnt() const 197cdf0e10cSrcweir { 198cdf0e10cSrcweir return rStatGlossaries.GetGroupCnt(); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir /*------------------------------------------------------------------------ 202cdf0e10cSrcweir Beschreibung: 203cdf0e10cSrcweir ------------------------------------------------------------------------*/ 204cdf0e10cSrcweir 205cdf0e10cSrcweir 206cdf0e10cSrcweir String SwGlossaryHdl::GetGroupName( sal_uInt16 nId, String* pTitle ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir String sRet = rStatGlossaries.GetGroupName(nId); 209cdf0e10cSrcweir if(pTitle) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir SwTextBlocks* pGroup = rStatGlossaries.GetGroupDoc(sRet, sal_False); 212cdf0e10cSrcweir if(pGroup && !pGroup->GetError()) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir *pTitle = pGroup->GetName(); 215cdf0e10cSrcweir if(!pTitle->Len()) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir *pTitle = sRet.GetToken(0, GLOS_DELIM); 218cdf0e10cSrcweir pGroup->SetName(*pTitle); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pGroup ); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir else 223cdf0e10cSrcweir sRet.Erase(); 224cdf0e10cSrcweir } 225cdf0e10cSrcweir return sRet; 226cdf0e10cSrcweir } 227cdf0e10cSrcweir /*------------------------------------------------------------------------ 228cdf0e10cSrcweir Beschreibung: 229cdf0e10cSrcweir ------------------------------------------------------------------------*/ 230cdf0e10cSrcweir 231cdf0e10cSrcweir 232cdf0e10cSrcweir sal_Bool SwGlossaryHdl::NewGroup(String &rGrpName, const String& rTitle) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir if(STRING_NOTFOUND == rGrpName.Search(GLOS_DELIM)) 235cdf0e10cSrcweir FindGroupName(rGrpName); 236cdf0e10cSrcweir return rStatGlossaries.NewGroupDoc(rGrpName, rTitle); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir /* -----------------23.11.98 13:10------------------- 239cdf0e10cSrcweir * Umbenennen eines Textbausteins 240cdf0e10cSrcweir * --------------------------------------------------*/ 241cdf0e10cSrcweir sal_Bool SwGlossaryHdl::RenameGroup(const String & rOld, String& rNew, const String& rNewTitle) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir sal_Bool bRet = sal_False; 244cdf0e10cSrcweir String sOldGroup(rOld); 245cdf0e10cSrcweir if(STRING_NOTFOUND == rOld.Search(GLOS_DELIM)) 246cdf0e10cSrcweir FindGroupName(sOldGroup); 247cdf0e10cSrcweir if(rOld == rNew) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir SwTextBlocks* pGroup = rStatGlossaries.GetGroupDoc(sOldGroup, sal_False); 250cdf0e10cSrcweir if(pGroup) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir pGroup->SetName(rNewTitle); 253cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pGroup ); 254cdf0e10cSrcweir bRet = sal_True; 255cdf0e10cSrcweir } 256cdf0e10cSrcweir } 257cdf0e10cSrcweir else 258cdf0e10cSrcweir { 259cdf0e10cSrcweir String sNewGroup(rNew); 260cdf0e10cSrcweir if(STRING_NOTFOUND == sNewGroup.Search(GLOS_DELIM)) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir sNewGroup += GLOS_DELIM; 263cdf0e10cSrcweir sNewGroup += '0'; 264cdf0e10cSrcweir } 265cdf0e10cSrcweir bRet = rStatGlossaries.RenameGroupDoc(sOldGroup, sNewGroup, rNewTitle); 266cdf0e10cSrcweir rNew = sNewGroup; 267cdf0e10cSrcweir } 268cdf0e10cSrcweir return bRet; 269cdf0e10cSrcweir } 270cdf0e10cSrcweir /* -----------------27.11.98 13:49------------------- 271cdf0e10cSrcweir * 272cdf0e10cSrcweir * --------------------------------------------------*/ 273cdf0e10cSrcweir sal_Bool SwGlossaryHdl::CopyOrMove( const String& rSourceGroupName, String& rSourceShortName, 274cdf0e10cSrcweir const String& rDestGroupName, const String& rLongName, sal_Bool bMove ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir SwTextBlocks* pSourceGroup = rStatGlossaries.GetGroupDoc(rSourceGroupName, sal_False); 277cdf0e10cSrcweir 278cdf0e10cSrcweir SwTextBlocks* pDestGroup = rStatGlossaries.GetGroupDoc(rDestGroupName, sal_False); 279cdf0e10cSrcweir if(pDestGroup->IsReadOnly() || (bMove && pSourceGroup->IsReadOnly()) ) 280cdf0e10cSrcweir return sal_False; 281cdf0e10cSrcweir /*if(pDestGroup->IsOld()&& 0!= pDestGroup->ConvertToNew()) 282cdf0e10cSrcweir return sal_False; 283cdf0e10cSrcweir if(bMove && pSourceGroup->IsOld() && 0 != pSourceGroup->ConvertToNew()) 284cdf0e10cSrcweir return sal_False;*/ 285cdf0e10cSrcweir 286cdf0e10cSrcweir //Der Index muss hier ermittelt werden, weil rSourceShortName in CopyBlock evtl veraendert wird 287cdf0e10cSrcweir sal_uInt16 nDeleteIdx = pSourceGroup->GetIndex( rSourceShortName ); 288cdf0e10cSrcweir DBG_ASSERT(USHRT_MAX != nDeleteIdx, "Eintrag nicht gefunden"); 289cdf0e10cSrcweir sal_uLong nRet = pSourceGroup->CopyBlock( *pDestGroup, rSourceShortName, rLongName ); 290cdf0e10cSrcweir if(!nRet && bMove) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir // der Index muss existieren 293cdf0e10cSrcweir nRet = pSourceGroup->Delete( nDeleteIdx ) ? 0 : 1; 294cdf0e10cSrcweir } 295cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pSourceGroup ); 296cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pDestGroup ); 297cdf0e10cSrcweir return !nRet; 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir /*------------------------------------------------------------------------ 301cdf0e10cSrcweir Beschreibung: Loeschen einer Textbausteindatei-Gruppe 302cdf0e10cSrcweir ------------------------------------------------------------------------*/ 303cdf0e10cSrcweir 304cdf0e10cSrcweir 305cdf0e10cSrcweir sal_Bool SwGlossaryHdl::DelGroup(const String &rGrpName) 306cdf0e10cSrcweir { 307cdf0e10cSrcweir String sGroup(rGrpName); 308cdf0e10cSrcweir if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM)) 309cdf0e10cSrcweir FindGroupName(sGroup); 310cdf0e10cSrcweir if( rStatGlossaries.DelGroupDoc(sGroup) ) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir if(pCurGrp) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir const String aMac_Tmp(pCurGrp->GetName()); 315cdf0e10cSrcweir if(aMac_Tmp == sGroup) 316cdf0e10cSrcweir DELETEZ(pCurGrp); 317cdf0e10cSrcweir } 318cdf0e10cSrcweir return sal_True; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir return sal_False; 321cdf0e10cSrcweir } 322cdf0e10cSrcweir 323cdf0e10cSrcweir /*------------------------------------------------------------------------ 324cdf0e10cSrcweir Beschreibung: Anzahl Textbausteine erfragen 325cdf0e10cSrcweir ------------------------------------------------------------------------*/ 326cdf0e10cSrcweir 327cdf0e10cSrcweir 328cdf0e10cSrcweir sal_uInt16 SwGlossaryHdl::GetGlossaryCnt() 329cdf0e10cSrcweir { 330cdf0e10cSrcweir return pCurGrp ? pCurGrp->GetCount() : 0; 331cdf0e10cSrcweir } 332cdf0e10cSrcweir 333cdf0e10cSrcweir /*------------------------------------------------------------------------ 334cdf0e10cSrcweir Beschreibung: 335cdf0e10cSrcweir ------------------------------------------------------------------------*/ 336cdf0e10cSrcweir 337cdf0e10cSrcweir 338cdf0e10cSrcweir String SwGlossaryHdl::GetGlossaryName( sal_uInt16 nId ) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir ASSERT(nId < GetGlossaryCnt(), Textbausteinarray ueberindiziert.); 341cdf0e10cSrcweir return pCurGrp->GetLongName( nId ); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir /* -----------------30.11.98 13:18------------------- 344cdf0e10cSrcweir * 345cdf0e10cSrcweir * --------------------------------------------------*/ 346cdf0e10cSrcweir String SwGlossaryHdl::GetGlossaryShortName(sal_uInt16 nId) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir ASSERT(nId < GetGlossaryCnt(), Textbausteinarray ueberindiziert.); 349cdf0e10cSrcweir return pCurGrp->GetShortName( nId ); 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352cdf0e10cSrcweir 353cdf0e10cSrcweir /*------------------------------------------------------------------------ 354cdf0e10cSrcweir Beschreibung: Kurzname erfragen 355cdf0e10cSrcweir ------------------------------------------------------------------------*/ 356cdf0e10cSrcweir 357cdf0e10cSrcweir 358cdf0e10cSrcweir String SwGlossaryHdl::GetGlossaryShortName(const String &rName) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir String sReturn; 361cdf0e10cSrcweir SwTextBlocks *pTmp = 362cdf0e10cSrcweir pCurGrp ? pCurGrp: rStatGlossaries.GetGroupDoc( aCurGrp, sal_False ); 363cdf0e10cSrcweir if(pTmp) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir sal_uInt16 nIdx = pTmp->GetLongIndex( rName ); 366cdf0e10cSrcweir if( nIdx != (sal_uInt16) -1 ) 367cdf0e10cSrcweir sReturn = pTmp->GetShortName( nIdx ); 368cdf0e10cSrcweir if( !pCurGrp ) 369cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pTmp ); 370cdf0e10cSrcweir } 371cdf0e10cSrcweir return sReturn; 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir /*------------------------------------------------------------------------ 375cdf0e10cSrcweir Beschreibung: Kuerzel fuer Textbaustein bereits verwendet? 376cdf0e10cSrcweir ------------------------------------------------------------------------*/ 377cdf0e10cSrcweir 378cdf0e10cSrcweir 379cdf0e10cSrcweir sal_Bool SwGlossaryHdl::HasShortName(const String& rShortName) const 380cdf0e10cSrcweir { 381cdf0e10cSrcweir SwTextBlocks *pBlock = pCurGrp ? pCurGrp 382cdf0e10cSrcweir : rStatGlossaries.GetGroupDoc( aCurGrp ); 383cdf0e10cSrcweir sal_Bool bRet = pBlock->GetIndex( rShortName ) != (sal_uInt16) -1; 384cdf0e10cSrcweir if( !pCurGrp ) 385cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pBlock ); 386cdf0e10cSrcweir return bRet; 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir /* -----------------------------20.03.01 10:52-------------------------------- 390cdf0e10cSrcweir 391cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 392cdf0e10cSrcweir sal_Bool SwGlossaryHdl::ConvertToNew(SwTextBlocks& /*rOld*/) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir /*if( rOld.IsOld() ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir QueryBox aAsk( pWrtShell->GetView().GetWindow(), SW_RES( MSG_UPDATE_NEW_GLOS_FMT ) ); 397cdf0e10cSrcweir if( aAsk.Execute() == RET_YES ) 398cdf0e10cSrcweir { 399cdf0e10cSrcweir if( rOld.ConvertToNew() ) 400cdf0e10cSrcweir { 401cdf0e10cSrcweir InfoBox(pWrtShell->GetView().GetWindow(), SW_RES(MSG_ERR_INSERT_GLOS)).Execute(); 402cdf0e10cSrcweir return sal_False; 403cdf0e10cSrcweir } 404cdf0e10cSrcweir } 405cdf0e10cSrcweir else 406cdf0e10cSrcweir return sal_False; 407cdf0e10cSrcweir }*/ 408cdf0e10cSrcweir return sal_True; 409cdf0e10cSrcweir } 410cdf0e10cSrcweir 411cdf0e10cSrcweir /*------------------------------------------------------------------------ 412cdf0e10cSrcweir Beschreibung: Erzeugen eines Textbausteines 413cdf0e10cSrcweir ------------------------------------------------------------------------*/ 414cdf0e10cSrcweir 415cdf0e10cSrcweir sal_Bool SwGlossaryHdl::NewGlossary(const String& rName, const String& rShortName, 416cdf0e10cSrcweir sal_Bool bCreateGroup, sal_Bool bNoAttr) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir SwTextBlocks *pTmp = 419cdf0e10cSrcweir pCurGrp ? pCurGrp: rStatGlossaries.GetGroupDoc( aCurGrp, bCreateGroup ); 420cdf0e10cSrcweir //pTmp == 0 if the AutoText path setting is wrong 421cdf0e10cSrcweir if(!pTmp) 422cdf0e10cSrcweir return sal_False; 423cdf0e10cSrcweir if(!ConvertToNew(*pTmp)) 424cdf0e10cSrcweir return sal_False; 425cdf0e10cSrcweir 426cdf0e10cSrcweir String sOnlyTxt; 427cdf0e10cSrcweir String* pOnlyTxt = 0; 428cdf0e10cSrcweir if( bNoAttr ) 429cdf0e10cSrcweir { 430cdf0e10cSrcweir if( !pWrtShell->GetSelectedText( sOnlyTxt, GETSELTXT_PARABRK_TO_ONLYCR )) 431cdf0e10cSrcweir return sal_False; 432cdf0e10cSrcweir pOnlyTxt = &sOnlyTxt; 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get(); 436cdf0e10cSrcweir 437cdf0e10cSrcweir const sal_uInt16 nSuccess = pWrtShell->MakeGlossary( *pTmp, rName, rShortName, 438cdf0e10cSrcweir pCfg->IsSaveRelFile(), pOnlyTxt ); 439cdf0e10cSrcweir if(nSuccess == (sal_uInt16) -1 ) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir InfoBox(pWrtShell->GetView().GetWindow(), SW_RES(MSG_ERR_INSERT_GLOS)).Execute(); 442cdf0e10cSrcweir } 443cdf0e10cSrcweir if( !pCurGrp ) 444cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pTmp ); 445cdf0e10cSrcweir return sal_Bool( nSuccess != (sal_uInt16) -1 ); 446cdf0e10cSrcweir } 447cdf0e10cSrcweir /*------------------------------------------------------------------------ 448cdf0e10cSrcweir Beschreibung: Loeschen eines Textbausteines 449cdf0e10cSrcweir ------------------------------------------------------------------------*/ 450cdf0e10cSrcweir 451cdf0e10cSrcweir 452cdf0e10cSrcweir sal_Bool SwGlossaryHdl::DelGlossary(const String &rShortName) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir SwTextBlocks *pGlossary = pCurGrp ? pCurGrp 455cdf0e10cSrcweir : rStatGlossaries.GetGroupDoc(aCurGrp); 456cdf0e10cSrcweir //pTmp == 0 if the AutoText path setting is wrong 457cdf0e10cSrcweir if(!pGlossary || !ConvertToNew(*pGlossary)) 458cdf0e10cSrcweir return sal_False; 459cdf0e10cSrcweir 460cdf0e10cSrcweir sal_uInt16 nIdx = pGlossary->GetIndex( rShortName ); 461cdf0e10cSrcweir if( nIdx != (sal_uInt16) -1 ) 462cdf0e10cSrcweir pGlossary->Delete( nIdx ); 463cdf0e10cSrcweir if( !pCurGrp ) 464cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pGlossary ); 465cdf0e10cSrcweir return sal_True; 466cdf0e10cSrcweir } 467cdf0e10cSrcweir 468cdf0e10cSrcweir /*------------------------------------------------------------------------ 469cdf0e10cSrcweir Beschreibung: Kurzform expandieren 470cdf0e10cSrcweir ------------------------------------------------------------------------*/ 471cdf0e10cSrcweir 472cdf0e10cSrcweir 473cdf0e10cSrcweir sal_Bool SwGlossaryHdl::ExpandGlossary() 474cdf0e10cSrcweir { 475cdf0e10cSrcweir ASSERT(pWrtShell->CanInsert(), illegal); 476cdf0e10cSrcweir SwTextBlocks *pGlossary; 477cdf0e10cSrcweir SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); 478cdf0e10cSrcweir DBG_ASSERT(pFact, "Dialogdiet fail!"); 479cdf0e10cSrcweir ::GlossaryGetCurrGroup fnGetCurrGroup = pFact->GetGlossaryCurrGroupFunc( DLG_RENAME_GLOS ); 480cdf0e10cSrcweir DBG_ASSERT(fnGetCurrGroup, "Dialogdiet fail!"); 481cdf0e10cSrcweir String sGroupName( (*fnGetCurrGroup)() ); 482cdf0e10cSrcweir if(STRING_NOTFOUND == sGroupName.Search(GLOS_DELIM)) 483cdf0e10cSrcweir FindGroupName(sGroupName); 484cdf0e10cSrcweir pGlossary = rStatGlossaries.GetGroupDoc(sGroupName); 485cdf0e10cSrcweir 486cdf0e10cSrcweir String aShortName; 487cdf0e10cSrcweir 488cdf0e10cSrcweir // bei Textselektion diese verwenden 489cdf0e10cSrcweir if(pWrtShell->SwCrsrShell::HasSelection() && !pWrtShell->IsBlockMode()) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir aShortName = pWrtShell->GetSelTxt(); 492cdf0e10cSrcweir } 493cdf0e10cSrcweir else 494cdf0e10cSrcweir { 495cdf0e10cSrcweir if(pWrtShell->IsAddMode()) 496cdf0e10cSrcweir pWrtShell->LeaveAddMode(); 497cdf0e10cSrcweir else if(pWrtShell->IsBlockMode()) 498cdf0e10cSrcweir pWrtShell->LeaveBlockMode(); 499cdf0e10cSrcweir else if(pWrtShell->IsExtMode()) 500cdf0e10cSrcweir pWrtShell->LeaveExtMode(); 501cdf0e10cSrcweir // Wort selektieren 502cdf0e10cSrcweir pWrtShell->SelNearestWrd(); 503cdf0e10cSrcweir // Wort erfragen 504cdf0e10cSrcweir if(pWrtShell->IsSelection()) 505cdf0e10cSrcweir aShortName = pWrtShell->GetSelTxt(); 506cdf0e10cSrcweir } 507cdf0e10cSrcweir return pGlossary ? Expand( aShortName, &rStatGlossaries, pGlossary ) : sal_False; 508cdf0e10cSrcweir } 509cdf0e10cSrcweir 510cdf0e10cSrcweir sal_Bool SwGlossaryHdl::Expand( const String& rShortName, 511cdf0e10cSrcweir SwGlossaries *pGlossaries, 512cdf0e10cSrcweir SwTextBlocks *pGlossary ) 513cdf0e10cSrcweir { 514cdf0e10cSrcweir TextBlockInfoArr aFoundArr; 515cdf0e10cSrcweir String aShortName( rShortName ); 516cdf0e10cSrcweir sal_Bool bCancel = sal_False; 517cdf0e10cSrcweir // search for text block 518cdf0e10cSrcweir //#b6633427# - don't prefer current group depending on configuration setting 519cdf0e10cSrcweir const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get(); 520cdf0e10cSrcweir sal_uInt16 nFound = !pCfg->IsSearchInAllCategories() ? pGlossary->GetIndex( aShortName ) : -1; 521cdf0e10cSrcweir // if not found then search in all groups 522cdf0e10cSrcweir if( nFound == (sal_uInt16) -1 ) 523cdf0e10cSrcweir { 524cdf0e10cSrcweir const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore(); 525cdf0e10cSrcweir SwGlossaryList* pGlossaryList = ::GetGlossaryList(); 526cdf0e10cSrcweir sal_uInt16 nGroupCount = pGlossaryList->GetGroupCount(); 527cdf0e10cSrcweir for(sal_uInt16 i = 1; i <= nGroupCount; i++) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir // Gruppenname mit Pfad-Extension besorgen 530cdf0e10cSrcweir String sTitle; 531cdf0e10cSrcweir String sGroupName = pGlossaryList->GetGroupName(i - 1, sal_False, &sTitle); 532cdf0e10cSrcweir if(sGroupName == pGlossary->GetName()) 533cdf0e10cSrcweir continue; 534cdf0e10cSrcweir sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1); 535cdf0e10cSrcweir if(nBlockCount) 536cdf0e10cSrcweir { 537cdf0e10cSrcweir for(sal_uInt16 j = 0; j < nBlockCount; j++) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir String sEntry; 540cdf0e10cSrcweir String sLongName(pGlossaryList->GetBlockName(i - 1, j, sEntry)); 541cdf0e10cSrcweir if( rSCmp.isEqual( rShortName, sEntry )) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir TextBlockInfo_Impl* pData = new TextBlockInfo_Impl; 544cdf0e10cSrcweir pData->sTitle = sTitle; 545cdf0e10cSrcweir pData->sLongName = sLongName; 546cdf0e10cSrcweir pData->sGroupName = sGroupName; 547cdf0e10cSrcweir aFoundArr.Insert(pData, aFoundArr.Count()); 548cdf0e10cSrcweir } 549cdf0e10cSrcweir } 550cdf0e10cSrcweir } 551cdf0e10cSrcweir } 552cdf0e10cSrcweir if( aFoundArr.Count() ) // einer wurde gefunden 553cdf0e10cSrcweir { 554cdf0e10cSrcweir pGlossaries->PutGroupDoc(pGlossary); 555cdf0e10cSrcweir if(1 == aFoundArr.Count()) 556cdf0e10cSrcweir { 557cdf0e10cSrcweir TextBlockInfo_Impl* pData = aFoundArr.GetObject(0); 558cdf0e10cSrcweir pGlossary = (SwTextBlocks *)pGlossaries->GetGroupDoc(pData->sGroupName); 559cdf0e10cSrcweir nFound = pGlossary->GetIndex( aShortName ); 560cdf0e10cSrcweir } 561cdf0e10cSrcweir else 562cdf0e10cSrcweir { 563cdf0e10cSrcweir SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); 564cdf0e10cSrcweir DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!"); 565cdf0e10cSrcweir 566cdf0e10cSrcweir AbstarctSwSelGlossaryDlg* pDlg = pFact->CreateSwSelGlossaryDlg( 0, aShortName, DLG_SEL_GLOS ); 567cdf0e10cSrcweir DBG_ASSERT(pDlg, "Dialogdiet fail!"); 568cdf0e10cSrcweir for(sal_uInt16 i = 0; i < aFoundArr.Count(); ++i) 569cdf0e10cSrcweir { 570cdf0e10cSrcweir TextBlockInfo_Impl* pData = aFoundArr.GetObject(i); 571cdf0e10cSrcweir pDlg->InsertGlos(pData->sTitle, pData->sLongName); 572cdf0e10cSrcweir } 573cdf0e10cSrcweir pDlg->SelectEntryPos(0); 574cdf0e10cSrcweir const sal_uInt16 nRet = RET_OK == pDlg->Execute()? 575cdf0e10cSrcweir pDlg->GetSelectedIdx(): 576cdf0e10cSrcweir LISTBOX_ENTRY_NOTFOUND; 577cdf0e10cSrcweir delete pDlg; 578cdf0e10cSrcweir if(LISTBOX_ENTRY_NOTFOUND != nRet) 579cdf0e10cSrcweir { 580cdf0e10cSrcweir TextBlockInfo_Impl* pData = aFoundArr.GetObject(nRet); 581cdf0e10cSrcweir pGlossary = (SwTextBlocks *)pGlossaries->GetGroupDoc(pData->sGroupName); 582cdf0e10cSrcweir nFound = pGlossary->GetIndex( aShortName ); 583cdf0e10cSrcweir } 584cdf0e10cSrcweir else 585cdf0e10cSrcweir { 586cdf0e10cSrcweir nFound = (sal_uInt16) -1; 587cdf0e10cSrcweir bCancel = sal_True; 588cdf0e10cSrcweir } 589cdf0e10cSrcweir } 590cdf0e10cSrcweir } 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir // nicht gefunden 594cdf0e10cSrcweir if( nFound == (sal_uInt16) -1 ) 595cdf0e10cSrcweir { 596cdf0e10cSrcweir if( !bCancel ) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir pGlossaries->PutGroupDoc(pGlossary); 599cdf0e10cSrcweir 600cdf0e10cSrcweir const sal_uInt16 nMaxLen = 50; 601cdf0e10cSrcweir if(pWrtShell->IsSelection() && aShortName.Len() > nMaxLen) 602cdf0e10cSrcweir { 603cdf0e10cSrcweir aShortName.Erase(nMaxLen); 604cdf0e10cSrcweir aShortName.AppendAscii(" ..."); 605cdf0e10cSrcweir } 606cdf0e10cSrcweir String aTmp( SW_RES(STR_NOGLOS)); 607cdf0e10cSrcweir aTmp.SearchAndReplaceAscii("%1", aShortName); 608cdf0e10cSrcweir InfoBox( pWrtShell->GetView().GetWindow(), aTmp ).Execute(); 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir return sal_False; 612cdf0e10cSrcweir } 613cdf0e10cSrcweir else 614cdf0e10cSrcweir { 615cdf0e10cSrcweir String aLongName = pGlossary->GetLongName( nFound ); 616cdf0e10cSrcweir SvxMacro aStartMacro(aEmptyStr, aEmptyStr, STARBASIC); 617cdf0e10cSrcweir SvxMacro aEndMacro(aEmptyStr, aEmptyStr, STARBASIC); 618cdf0e10cSrcweir GetMacros( aShortName, aStartMacro, aEndMacro, pGlossary ); 619cdf0e10cSrcweir 620cdf0e10cSrcweir // StartAction darf nich vor HasSelection und DelRight stehen, 621cdf0e10cSrcweir // sonst wird der moeglich Shellwechsel verzoegert und 622cdf0e10cSrcweir // API-Programme wuerden dann haengenbleiben 623cdf0e10cSrcweir // ausserdem darf das Ereignismacro ebenfalls nicht in einer Action gerufen werden 624cdf0e10cSrcweir pWrtShell->StartUndo(UNDO_INSGLOSSARY); 625cdf0e10cSrcweir if( aStartMacro.GetMacName().Len() ) 626cdf0e10cSrcweir pWrtShell->ExecMacro( aStartMacro ); 627cdf0e10cSrcweir if(pWrtShell->HasSelection()) 628cdf0e10cSrcweir pWrtShell->DelLeft(); 629cdf0e10cSrcweir pWrtShell->StartAllAction(); 630cdf0e10cSrcweir 631cdf0e10cSrcweir // alle InputFelder zwischenspeichern 632cdf0e10cSrcweir SwInputFieldList aFldLst( pWrtShell, sal_True ); 633cdf0e10cSrcweir 634cdf0e10cSrcweir pWrtShell->InsertGlossary(*pGlossary, aShortName); 635cdf0e10cSrcweir pWrtShell->EndAllAction(); 636cdf0e10cSrcweir if( aEndMacro.GetMacName().Len() ) 637cdf0e10cSrcweir { 638cdf0e10cSrcweir pWrtShell->ExecMacro( aEndMacro ); 639cdf0e10cSrcweir } 640cdf0e10cSrcweir pWrtShell->EndUndo(UNDO_INSGLOSSARY); 641cdf0e10cSrcweir 642cdf0e10cSrcweir // fuer alle neuen InputFelder die Eingaben abfordern 643cdf0e10cSrcweir if( aFldLst.BuildSortLst() ) 644cdf0e10cSrcweir pWrtShell->UpdateInputFlds( &aFldLst ); 645cdf0e10cSrcweir } 646cdf0e10cSrcweir pGlossaries->PutGroupDoc(pGlossary); 647cdf0e10cSrcweir return sal_True; 648cdf0e10cSrcweir } 649cdf0e10cSrcweir 650cdf0e10cSrcweir /*------------------------------------------------------------------------ 651cdf0e10cSrcweir Beschreibung: Textbaustein einfuegen 652cdf0e10cSrcweir ------------------------------------------------------------------------*/ 653cdf0e10cSrcweir 654cdf0e10cSrcweir 655cdf0e10cSrcweir sal_Bool SwGlossaryHdl::InsertGlossary(const String &rName) 656cdf0e10cSrcweir { 657cdf0e10cSrcweir ASSERT(pWrtShell->CanInsert(), illegal); 658cdf0e10cSrcweir 659cdf0e10cSrcweir SwTextBlocks *pGlos = 660cdf0e10cSrcweir pCurGrp? pCurGrp: rStatGlossaries.GetGroupDoc(aCurGrp); 661cdf0e10cSrcweir 662cdf0e10cSrcweir if (!pGlos) 663cdf0e10cSrcweir return sal_False; 664cdf0e10cSrcweir 665cdf0e10cSrcweir SvxMacro aStartMacro(aEmptyStr, aEmptyStr, STARBASIC); 666cdf0e10cSrcweir SvxMacro aEndMacro(aEmptyStr, aEmptyStr, STARBASIC); 667cdf0e10cSrcweir GetMacros( rName, aStartMacro, aEndMacro, pGlos ); 668cdf0e10cSrcweir 669cdf0e10cSrcweir // StartAction darf nich vor HasSelection und DelRight stehen, 670cdf0e10cSrcweir // sonst wird der moeglich Shellwechsel verzoegert und 671cdf0e10cSrcweir // API-Programme wuerden dann haengenbleiben 672cdf0e10cSrcweir // ausserdem darf das Ereignismacro ebenfalls nicht in einer Action gerufen werden 673cdf0e10cSrcweir if( aStartMacro.GetMacName().Len() ) 674cdf0e10cSrcweir pWrtShell->ExecMacro( aStartMacro ); 675cdf0e10cSrcweir if( pWrtShell->HasSelection() ) 676cdf0e10cSrcweir pWrtShell->DelRight(); 677cdf0e10cSrcweir pWrtShell->StartAllAction(); 678cdf0e10cSrcweir 679cdf0e10cSrcweir // alle InputFelder zwischenspeichern 680cdf0e10cSrcweir SwInputFieldList aFldLst( pWrtShell, sal_True ); 681cdf0e10cSrcweir 682cdf0e10cSrcweir pWrtShell->InsertGlossary(*pGlos, rName); 683cdf0e10cSrcweir pWrtShell->EndAllAction(); 684cdf0e10cSrcweir if( aEndMacro.GetMacName().Len() ) 685cdf0e10cSrcweir { 686cdf0e10cSrcweir pWrtShell->ExecMacro( aEndMacro ); 687cdf0e10cSrcweir } 688cdf0e10cSrcweir 689cdf0e10cSrcweir // fuer alle neuen InputFelder die Eingaben abfordern 690cdf0e10cSrcweir if( aFldLst.BuildSortLst() ) 691cdf0e10cSrcweir pWrtShell->UpdateInputFlds( &aFldLst ); 692cdf0e10cSrcweir 693cdf0e10cSrcweir if(!pCurGrp) 694cdf0e10cSrcweir rStatGlossaries.PutGroupDoc(pGlos); 695cdf0e10cSrcweir return sal_True; 696cdf0e10cSrcweir } 697cdf0e10cSrcweir 698cdf0e10cSrcweir /*------------------------------------------------------------------------ 699cdf0e10cSrcweir Beschreibung: Macro setzen / erfragen 700cdf0e10cSrcweir ------------------------------------------------------------------------*/ 701cdf0e10cSrcweir 702cdf0e10cSrcweir 703cdf0e10cSrcweir void SwGlossaryHdl::SetMacros(const String& rShortName, 704cdf0e10cSrcweir const SvxMacro* pStart, 705cdf0e10cSrcweir const SvxMacro* pEnd, 706cdf0e10cSrcweir SwTextBlocks *pGlossary ) 707cdf0e10cSrcweir { 708cdf0e10cSrcweir SwTextBlocks *pGlos = pGlossary ? pGlossary : 709cdf0e10cSrcweir pCurGrp ? pCurGrp 710cdf0e10cSrcweir : rStatGlossaries.GetGroupDoc( aCurGrp ); 711cdf0e10cSrcweir SvxMacroTableDtor aMacroTbl; 712cdf0e10cSrcweir if( pStart ) 713cdf0e10cSrcweir aMacroTbl.Insert( SW_EVENT_START_INS_GLOSSARY, new SvxMacro(*pStart)); 714cdf0e10cSrcweir if( pEnd ) 715cdf0e10cSrcweir aMacroTbl.Insert( SW_EVENT_END_INS_GLOSSARY, new SvxMacro(*pEnd)); 716cdf0e10cSrcweir sal_uInt16 nIdx = pGlos->GetIndex( rShortName ); 717cdf0e10cSrcweir if( !pGlos->SetMacroTable( nIdx, aMacroTbl ) && pGlos->GetError() ) 718cdf0e10cSrcweir ErrorHandler::HandleError( pGlos->GetError() ); 719cdf0e10cSrcweir 720cdf0e10cSrcweir if(!pCurGrp && !pGlossary) 721cdf0e10cSrcweir rStatGlossaries.PutGroupDoc(pGlos); 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir void SwGlossaryHdl::GetMacros( const String &rShortName, 725cdf0e10cSrcweir SvxMacro& rStart, 726cdf0e10cSrcweir SvxMacro& rEnd, 727cdf0e10cSrcweir SwTextBlocks *pGlossary ) 728cdf0e10cSrcweir { 729cdf0e10cSrcweir SwTextBlocks *pGlos = pGlossary ? pGlossary 730cdf0e10cSrcweir : pCurGrp ? pCurGrp 731cdf0e10cSrcweir : rStatGlossaries.GetGroupDoc(aCurGrp); 732cdf0e10cSrcweir sal_uInt16 nIndex = pGlos->GetIndex( rShortName ); 733cdf0e10cSrcweir if( nIndex != USHRT_MAX ) 734cdf0e10cSrcweir { 735cdf0e10cSrcweir SvxMacroTableDtor aMacroTbl; 736cdf0e10cSrcweir if( pGlos->GetMacroTable( nIndex, aMacroTbl ) ) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir SvxMacro *pMacro = aMacroTbl.Get( SW_EVENT_START_INS_GLOSSARY ); 739cdf0e10cSrcweir if( pMacro ) 740cdf0e10cSrcweir rStart = *pMacro; 741cdf0e10cSrcweir 742cdf0e10cSrcweir pMacro = aMacroTbl.Get( SW_EVENT_END_INS_GLOSSARY ); 743cdf0e10cSrcweir if( pMacro ) 744cdf0e10cSrcweir rEnd = *pMacro; 745cdf0e10cSrcweir } 746cdf0e10cSrcweir } 747cdf0e10cSrcweir 748cdf0e10cSrcweir if( !pCurGrp && !pGlossary ) 749cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pGlos ); 750cdf0e10cSrcweir } 751cdf0e10cSrcweir 752cdf0e10cSrcweir 753cdf0e10cSrcweir /*------------------------------------------------------------------------ 754cdf0e10cSrcweir Beschreibung: ctor, dtor 755cdf0e10cSrcweir ------------------------------------------------------------------------*/ 756cdf0e10cSrcweir 757cdf0e10cSrcweir 758cdf0e10cSrcweir SwGlossaryHdl::SwGlossaryHdl(SfxViewFrame* pVwFrm, SwWrtShell *pSh) 759cdf0e10cSrcweir : rStatGlossaries( *::GetGlossaries() ), 760cdf0e10cSrcweir aCurGrp( rStatGlossaries.GetDefName() ), 761cdf0e10cSrcweir pViewFrame( pVwFrm ), 762cdf0e10cSrcweir pWrtShell( pSh ), 763cdf0e10cSrcweir pCurGrp( 0 ) 764cdf0e10cSrcweir { 765cdf0e10cSrcweir } 766cdf0e10cSrcweir 767cdf0e10cSrcweir 768cdf0e10cSrcweir SwGlossaryHdl::~SwGlossaryHdl() 769cdf0e10cSrcweir { 770cdf0e10cSrcweir if( pCurGrp ) 771cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pCurGrp ); 772cdf0e10cSrcweir } 773cdf0e10cSrcweir 774cdf0e10cSrcweir /*------------------------------------------------------------------------ 775cdf0e10cSrcweir Beschreibung: Umbenennen eines Textbausteines 776cdf0e10cSrcweir ------------------------------------------------------------------------*/ 777cdf0e10cSrcweir 778cdf0e10cSrcweir 779cdf0e10cSrcweir sal_Bool SwGlossaryHdl::Rename(const String& rOldShort, const String& rNewShortName, 780cdf0e10cSrcweir const String& rNewName ) 781cdf0e10cSrcweir { 782cdf0e10cSrcweir sal_Bool bRet = sal_False; 783cdf0e10cSrcweir SwTextBlocks *pGlossary = pCurGrp ? pCurGrp 784cdf0e10cSrcweir : rStatGlossaries.GetGroupDoc(aCurGrp); 785cdf0e10cSrcweir if(pGlossary) 786cdf0e10cSrcweir { 787cdf0e10cSrcweir if(!ConvertToNew(*pGlossary)) 788cdf0e10cSrcweir return sal_False; 789cdf0e10cSrcweir 790cdf0e10cSrcweir sal_uInt16 nIdx = pGlossary->GetIndex( rOldShort ); 791cdf0e10cSrcweir sal_uInt16 nOldLongIdx = pGlossary->GetLongIndex( rNewName ); 792cdf0e10cSrcweir sal_uInt16 nOldIdx = pGlossary->GetIndex( rNewShortName ); 793cdf0e10cSrcweir 794cdf0e10cSrcweir if( nIdx != USHRT_MAX && 795cdf0e10cSrcweir (nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx )&& 796cdf0e10cSrcweir (nOldIdx == USHRT_MAX || nOldIdx == nIdx )) 797cdf0e10cSrcweir { 798cdf0e10cSrcweir String aNewShort( rNewShortName ); 799cdf0e10cSrcweir String aNewName( rNewName ); 800cdf0e10cSrcweir pGlossary->Rename( nIdx, &aNewShort, &aNewName ); 801cdf0e10cSrcweir bRet = pGlossary->GetError() == 0; 802cdf0e10cSrcweir } 803cdf0e10cSrcweir if( !pCurGrp ) 804cdf0e10cSrcweir rStatGlossaries.PutGroupDoc(pGlossary); 805cdf0e10cSrcweir } 806cdf0e10cSrcweir return bRet; 807cdf0e10cSrcweir } 808cdf0e10cSrcweir 809cdf0e10cSrcweir 810cdf0e10cSrcweir sal_Bool SwGlossaryHdl::IsReadOnly( const String* pGrpNm ) const 811cdf0e10cSrcweir { 812cdf0e10cSrcweir SwTextBlocks *pGlossary = 0; 813cdf0e10cSrcweir 814cdf0e10cSrcweir if (pGrpNm) 815cdf0e10cSrcweir pGlossary = rStatGlossaries.GetGroupDoc( *pGrpNm ); 816cdf0e10cSrcweir else if (pCurGrp) 817cdf0e10cSrcweir pGlossary = pCurGrp; 818cdf0e10cSrcweir else 819cdf0e10cSrcweir pGlossary = rStatGlossaries.GetGroupDoc(aCurGrp); 820cdf0e10cSrcweir 821cdf0e10cSrcweir sal_Bool bRet = pGlossary ? pGlossary->IsReadOnly() : sal_True; 822cdf0e10cSrcweir if( pGrpNm || !pCurGrp ) 823cdf0e10cSrcweir delete pGlossary; 824cdf0e10cSrcweir return bRet; 825cdf0e10cSrcweir } 826cdf0e10cSrcweir 827cdf0e10cSrcweir 828cdf0e10cSrcweir sal_Bool SwGlossaryHdl::IsOld() const 829cdf0e10cSrcweir { 830cdf0e10cSrcweir SwTextBlocks *pGlossary = pCurGrp ? pCurGrp 831cdf0e10cSrcweir : rStatGlossaries.GetGroupDoc(aCurGrp); 832cdf0e10cSrcweir sal_Bool bRet = pGlossary ? pGlossary->IsOld() : sal_False; 833cdf0e10cSrcweir if( !pCurGrp ) 834cdf0e10cSrcweir delete pGlossary; 835cdf0e10cSrcweir return bRet; 836cdf0e10cSrcweir } 837cdf0e10cSrcweir 838cdf0e10cSrcweir /*-----------------09.06.97 16:15------------------- 839cdf0e10cSrcweir Gruppe ohne Pfadindex finden 840cdf0e10cSrcweir --------------------------------------------------*/ 841cdf0e10cSrcweir sal_Bool SwGlossaryHdl::FindGroupName(String & rGroup) 842cdf0e10cSrcweir { 843cdf0e10cSrcweir return rStatGlossaries.FindGroupName(rGroup); 844cdf0e10cSrcweir } 845cdf0e10cSrcweir 846cdf0e10cSrcweir /* -----------------29.07.99 08:34------------------- 847cdf0e10cSrcweir 848cdf0e10cSrcweir --------------------------------------------------*/ 849cdf0e10cSrcweir sal_Bool SwGlossaryHdl::CopyToClipboard(SwWrtShell& rSh, const String& rShortName) 850cdf0e10cSrcweir { 851cdf0e10cSrcweir SwTextBlocks *pGlossary = pCurGrp ? pCurGrp 852cdf0e10cSrcweir : rStatGlossaries.GetGroupDoc(aCurGrp); 853cdf0e10cSrcweir 854cdf0e10cSrcweir SwTransferable* pTransfer = new SwTransferable( rSh ); 855cdf0e10cSrcweir /*??*/uno::Reference< 856cdf0e10cSrcweir datatransfer::XTransferable > xRef( pTransfer ); 857cdf0e10cSrcweir 858cdf0e10cSrcweir int nRet = pTransfer->CopyGlossary( *pGlossary, rShortName ); 859cdf0e10cSrcweir if( !pCurGrp ) 860cdf0e10cSrcweir rStatGlossaries.PutGroupDoc( pGlossary ); 861cdf0e10cSrcweir return 0 != nRet; 862cdf0e10cSrcweir } 863cdf0e10cSrcweir 864cdf0e10cSrcweir sal_Bool SwGlossaryHdl::ImportGlossaries( const String& rName ) 865cdf0e10cSrcweir { 866cdf0e10cSrcweir sal_Bool bRet = sal_False; 867cdf0e10cSrcweir if( rName.Len() ) 868cdf0e10cSrcweir { 869cdf0e10cSrcweir const SfxFilter* pFilter = 0; 870cdf0e10cSrcweir SfxMedium* pMed = new SfxMedium( rName, STREAM_READ, sal_True, 0, 0 ); 871cdf0e10cSrcweir SfxFilterMatcher aMatcher( String::CreateFromAscii("swriter") ); 872cdf0e10cSrcweir pMed->UseInteractionHandler( sal_True ); 873cdf0e10cSrcweir if( !aMatcher.GuessFilter( *pMed, &pFilter, sal_False ) ) 874cdf0e10cSrcweir { 875cdf0e10cSrcweir SwTextBlocks *pGlossary; 876cdf0e10cSrcweir pMed->SetFilter( pFilter ); 877cdf0e10cSrcweir Reader* pR = SwReaderWriter::GetReader( pFilter->GetUserData() ); 878cdf0e10cSrcweir if( pR && 0 != ( pGlossary = pCurGrp ? pCurGrp 879cdf0e10cSrcweir : rStatGlossaries.GetGroupDoc(aCurGrp)) ) 880cdf0e10cSrcweir { 881cdf0e10cSrcweir SwReader aReader( *pMed, rName ); 882cdf0e10cSrcweir if( aReader.HasGlossaries( *pR ) ) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get(); 885cdf0e10cSrcweir bRet = aReader.ReadGlossaries( *pR, *pGlossary, 886cdf0e10cSrcweir pCfg->IsSaveRelFile() ); 887cdf0e10cSrcweir } 888cdf0e10cSrcweir } 889cdf0e10cSrcweir } 890cdf0e10cSrcweir DELETEZ(pMed); 891cdf0e10cSrcweir } 892cdf0e10cSrcweir return bRet; 893cdf0e10cSrcweir } 894cdf0e10cSrcweir 895