update dev300-m58
[ooovba.git] / sw / source / ui / dochdl / gloshdl.cxx
blobc46cf609461a02964c376d0ae591a4869e76d22b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gloshdl.cxx,v $
10 * $Revision: 1.32.240.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <svx/wghtitem.hxx>
37 #include <svx/adjitem.hxx>
38 #ifndef __RSC //autogen
39 #include <tools/errinf.hxx>
40 #endif
41 #ifndef _MSGBOX_HXX //autogen
42 #include <vcl/msgbox.hxx>
43 #endif
44 #ifndef _MSGBOX_HXX //autogen
45 #include <vcl/msgbox.hxx>
46 #endif
47 #include <svtools/macitem.hxx>
48 #include <sfx2/fcontnr.hxx>
49 #include <sfx2/docfile.hxx>
50 #define _SVSTDARR_STRINGS
51 #include <svtools/svstdarr.hxx>
52 #include <svtools/urihelper.hxx>
53 #include <unotools/transliterationwrapper.hxx>
54 #include <poolfmt.hxx>
55 #include <fmtcol.hxx>
56 #include <docary.hxx>
57 #include <wrtsh.hxx>
58 #include <uitool.hxx> // Fehlermeldungen
59 #include <view.hxx>
60 #include <swevent.hxx>
61 #include <gloshdl.hxx>
62 #include <glosdoc.hxx>
63 #include <shellio.hxx>
64 #include <swundo.hxx> // fuer Undo-Ids
65 #include <expfld.hxx>
66 #include <initui.hxx> // fuer ::GetGlossaries()
67 #include <gloslst.hxx>
68 #include <swdtflvr.hxx>
69 #ifndef _DOCSH_HXX
70 #include <docsh.hxx>
71 #endif
72 #include <crsskip.hxx>
74 #ifndef _DOCHDL_HRC
75 #include <dochdl.hrc>
76 #endif
77 #ifndef _SWERROR_H
78 #include <swerror.h>
79 #endif
80 #include <frmmgr.hxx>
81 #ifndef _LSTBOX_HXX //autogen
82 #include <vcl/lstbox.hxx>
83 #endif
85 #include <svx/acorrcfg.hxx>
86 #include "swabstdlg.hxx"
87 #include <misc.hrc>
89 #include <IDocumentFieldsAccess.hxx>
91 using namespace ::com::sun::star;
94 const short RET_EDIT = 100;
96 // PUBLIC METHODES -------------------------------------------------------
97 struct TextBlockInfo_Impl
99 String sTitle;
100 String sLongName;
101 String sGroupName;
103 typedef TextBlockInfo_Impl* TextBlockInfo_ImplPtr;
104 SV_DECL_PTRARR_DEL( TextBlockInfoArr, TextBlockInfo_ImplPtr, 0, 4 )
105 SV_IMPL_PTRARR( TextBlockInfoArr, TextBlockInfo_ImplPtr )
106 SV_IMPL_REF( SwDocShell )
107 /*------------------------------------------------------------------------
108 Beschreibung: Dialog fuer Bearbeiten Vorlagen
109 ------------------------------------------------------------------------*/
112 void SwGlossaryHdl::GlossaryDlg()
114 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
115 DBG_ASSERT(pFact, "Dialogdiet fail!");
116 AbstractGlossaryDlg* pDlg = pFact->CreateGlossaryDlg( DLG_RENAME_GLOS,
117 pViewFrame, this, pWrtShell);
118 DBG_ASSERT(pDlg, "Dialogdiet fail!");
119 String sName, sShortName;
121 if( RET_EDIT == pDlg->Execute() )
123 sName = pDlg->GetCurrGrpName();
124 sShortName = pDlg->GetCurrShortName();
127 delete pDlg;
128 DELETEZ(pCurGrp);
129 if(HasGlossaryList())
131 GetGlossaryList()->ClearGroups();
134 if( sName.Len() || sShortName.Len() )
135 rStatGlossaries.EditGroupDoc( sName, sShortName );
138 /*------------------------------------------------------------------------
139 Beschreibung: Setzen der aktuellen Gruppe; falls aus dem Dialog
140 gerufen, wird die Gruppe temp. erzeugt fuer einen
141 schnelleren Zugriff
142 ------------------------------------------------------------------------*/
145 void SwGlossaryHdl::SetCurGroup(const String &rGrp, BOOL bApi, BOOL bAlwaysCreateNew )
147 String sGroup(rGrp);
148 if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM) && !FindGroupName(sGroup))
150 sGroup += GLOS_DELIM;
151 sGroup += '0';
153 if(pCurGrp)
155 BOOL bPathEqual = FALSE;
156 if(!bAlwaysCreateNew)
158 INetURLObject aTemp( pCurGrp->GetFileName() );
159 String sCurBase = aTemp.getBase();
160 aTemp.removeSegment();
161 const String sCurEntryPath = aTemp.GetMainURL(INetURLObject::NO_DECODE);
162 const SvStrings* pPathArr = rStatGlossaries.GetPathArray();
163 USHORT nCurrentPath = USHRT_MAX;
164 for(USHORT nPath = 0; nPath < pPathArr->Count(); nPath++)
166 if(sCurEntryPath == *(*pPathArr)[nPath])
168 nCurrentPath = nPath;
169 break;
172 String sPath = sGroup.GetToken(1, GLOS_DELIM);
173 USHORT nComparePath = (USHORT)sPath.ToInt32();
174 if(nCurrentPath == nComparePath &&
175 sGroup.GetToken(0, GLOS_DELIM) == sCurBase)
176 bPathEqual = TRUE;
178 // const String aMac_Tmp(pCurGrp->GetName());
179 // Beim Pfadwechsel kann man sich auf den Namen nicht verlassen
180 if(!bAlwaysCreateNew &&
181 bPathEqual
182 // aMac_Tmp == sGroup
184 return;
186 aCurGrp = sGroup;
187 if(!bApi)
189 if(pCurGrp)
191 rStatGlossaries.PutGroupDoc(pCurGrp);
192 pCurGrp = 0;
194 pCurGrp = rStatGlossaries.GetGroupDoc(aCurGrp, TRUE);
198 /*------------------------------------------------------------------------
199 Beschreibung:
200 ------------------------------------------------------------------------*/
203 USHORT SwGlossaryHdl::GetGroupCnt() const
205 return rStatGlossaries.GetGroupCnt();
208 /*------------------------------------------------------------------------
209 Beschreibung:
210 ------------------------------------------------------------------------*/
213 String SwGlossaryHdl::GetGroupName( USHORT nId, String* pTitle )
215 String sRet = rStatGlossaries.GetGroupName(nId);
216 if(pTitle)
218 SwTextBlocks* pGroup = rStatGlossaries.GetGroupDoc(sRet, FALSE);
219 if(pGroup && !pGroup->GetError())
221 *pTitle = pGroup->GetName();
222 if(!pTitle->Len())
224 *pTitle = sRet.GetToken(0, GLOS_DELIM);
225 pGroup->SetName(*pTitle);
227 rStatGlossaries.PutGroupDoc( pGroup );
229 else
230 sRet.Erase();
232 return sRet;
234 /*------------------------------------------------------------------------
235 Beschreibung:
236 ------------------------------------------------------------------------*/
239 BOOL SwGlossaryHdl::NewGroup(String &rGrpName, const String& rTitle)
241 if(STRING_NOTFOUND == rGrpName.Search(GLOS_DELIM))
242 FindGroupName(rGrpName);
243 return rStatGlossaries.NewGroupDoc(rGrpName, rTitle);
245 /* -----------------23.11.98 13:10-------------------
246 * Umbenennen eines Textbausteins
247 * --------------------------------------------------*/
248 BOOL SwGlossaryHdl::RenameGroup(const String & rOld, String& rNew, const String& rNewTitle)
250 BOOL bRet = FALSE;
251 String sOldGroup(rOld);
252 if(STRING_NOTFOUND == rOld.Search(GLOS_DELIM))
253 FindGroupName(sOldGroup);
254 if(rOld == rNew)
256 SwTextBlocks* pGroup = rStatGlossaries.GetGroupDoc(sOldGroup, FALSE);
257 if(pGroup)
259 pGroup->SetName(rNewTitle);
260 rStatGlossaries.PutGroupDoc( pGroup );
261 bRet = TRUE;
264 else
266 String sNewGroup(rNew);
267 if(STRING_NOTFOUND == sNewGroup.Search(GLOS_DELIM))
269 sNewGroup += GLOS_DELIM;
270 sNewGroup += '0';
272 bRet = rStatGlossaries.RenameGroupDoc(sOldGroup, sNewGroup, rNewTitle);
273 rNew = sNewGroup;
275 return bRet;
277 /* -----------------27.11.98 13:49-------------------
279 * --------------------------------------------------*/
280 BOOL SwGlossaryHdl::CopyOrMove( const String& rSourceGroupName, String& rSourceShortName,
281 const String& rDestGroupName, const String& rLongName, BOOL bMove )
283 SwTextBlocks* pSourceGroup = rStatGlossaries.GetGroupDoc(rSourceGroupName, FALSE);
285 SwTextBlocks* pDestGroup = rStatGlossaries.GetGroupDoc(rDestGroupName, FALSE);
286 if(pDestGroup->IsReadOnly() || (bMove && pSourceGroup->IsReadOnly()) )
287 return FALSE;
288 /*if(pDestGroup->IsOld()&& 0!= pDestGroup->ConvertToNew())
289 return FALSE;
290 if(bMove && pSourceGroup->IsOld() && 0 != pSourceGroup->ConvertToNew())
291 return FALSE;*/
293 //Der Index muss hier ermittelt werden, weil rSourceShortName in CopyBlock evtl veraendert wird
294 USHORT nDeleteIdx = pSourceGroup->GetIndex( rSourceShortName );
295 DBG_ASSERT(USHRT_MAX != nDeleteIdx, "Eintrag nicht gefunden");
296 ULONG nRet = pSourceGroup->CopyBlock( *pDestGroup, rSourceShortName, rLongName );
297 if(!nRet && bMove)
299 // der Index muss existieren
300 nRet = pSourceGroup->Delete( nDeleteIdx ) ? 0 : 1;
302 rStatGlossaries.PutGroupDoc( pSourceGroup );
303 rStatGlossaries.PutGroupDoc( pDestGroup );
304 return !nRet;
307 /*------------------------------------------------------------------------
308 Beschreibung: Loeschen einer Textbausteindatei-Gruppe
309 ------------------------------------------------------------------------*/
312 BOOL SwGlossaryHdl::DelGroup(const String &rGrpName)
314 String sGroup(rGrpName);
315 if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM))
316 FindGroupName(sGroup);
317 if( rStatGlossaries.DelGroupDoc(sGroup) )
319 if(pCurGrp)
321 const String aMac_Tmp(pCurGrp->GetName());
322 if(aMac_Tmp == sGroup)
323 DELETEZ(pCurGrp);
325 return TRUE;
327 return FALSE;
330 /*------------------------------------------------------------------------
331 Beschreibung: Anzahl Textbausteine erfragen
332 ------------------------------------------------------------------------*/
335 USHORT SwGlossaryHdl::GetGlossaryCnt()
337 return pCurGrp ? pCurGrp->GetCount() : 0;
340 /*------------------------------------------------------------------------
341 Beschreibung:
342 ------------------------------------------------------------------------*/
345 String SwGlossaryHdl::GetGlossaryName( USHORT nId )
347 ASSERT(nId < GetGlossaryCnt(), Textbausteinarray ueberindiziert.);
348 return pCurGrp->GetLongName( nId );
350 /* -----------------30.11.98 13:18-------------------
352 * --------------------------------------------------*/
353 String SwGlossaryHdl::GetGlossaryShortName(USHORT nId)
355 ASSERT(nId < GetGlossaryCnt(), Textbausteinarray ueberindiziert.);
356 return pCurGrp->GetShortName( nId );
360 /*------------------------------------------------------------------------
361 Beschreibung: Kurzname erfragen
362 ------------------------------------------------------------------------*/
365 String SwGlossaryHdl::GetGlossaryShortName(const String &rName)
367 String sReturn;
368 SwTextBlocks *pTmp =
369 pCurGrp ? pCurGrp: rStatGlossaries.GetGroupDoc( aCurGrp, FALSE );
370 if(pTmp)
372 USHORT nIdx = pTmp->GetLongIndex( rName );
373 if( nIdx != (USHORT) -1 )
374 sReturn = pTmp->GetShortName( nIdx );
375 if( !pCurGrp )
376 rStatGlossaries.PutGroupDoc( pTmp );
378 return sReturn;
381 /*------------------------------------------------------------------------
382 Beschreibung: Kuerzel fuer Textbaustein bereits verwendet?
383 ------------------------------------------------------------------------*/
386 BOOL SwGlossaryHdl::HasShortName(const String& rShortName) const
388 SwTextBlocks *pBlock = pCurGrp ? pCurGrp
389 : rStatGlossaries.GetGroupDoc( aCurGrp );
390 BOOL bRet = pBlock->GetIndex( rShortName ) != (USHORT) -1;
391 if( !pCurGrp )
392 rStatGlossaries.PutGroupDoc( pBlock );
393 return bRet;
396 /* -----------------------------20.03.01 10:52--------------------------------
398 ---------------------------------------------------------------------------*/
399 BOOL SwGlossaryHdl::ConvertToNew(SwTextBlocks& /*rOld*/)
401 /*if( rOld.IsOld() )
403 QueryBox aAsk( pWrtShell->GetView().GetWindow(), SW_RES( MSG_UPDATE_NEW_GLOS_FMT ) );
404 if( aAsk.Execute() == RET_YES )
406 if( rOld.ConvertToNew() )
408 InfoBox(pWrtShell->GetView().GetWindow(), SW_RES(MSG_ERR_INSERT_GLOS)).Execute();
409 return FALSE;
412 else
413 return FALSE;
415 return TRUE;
418 /*------------------------------------------------------------------------
419 Beschreibung: Erzeugen eines Textbausteines
420 ------------------------------------------------------------------------*/
422 BOOL SwGlossaryHdl::NewGlossary(const String& rName, const String& rShortName,
423 BOOL bCreateGroup, BOOL bNoAttr)
425 SwTextBlocks *pTmp =
426 pCurGrp ? pCurGrp: rStatGlossaries.GetGroupDoc( aCurGrp, bCreateGroup );
427 //pTmp == 0 if the AutoText path setting is wrong
428 if(!pTmp)
429 return FALSE;
430 if(!ConvertToNew(*pTmp))
431 return FALSE;
433 String sOnlyTxt;
434 String* pOnlyTxt = 0;
435 if( bNoAttr )
437 if( !pWrtShell->GetSelectedText( sOnlyTxt, GETSELTXT_PARABRK_TO_ONLYCR ))
438 return FALSE;
439 pOnlyTxt = &sOnlyTxt;
442 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
444 const USHORT nSuccess = pWrtShell->MakeGlossary( *pTmp, rName, rShortName,
445 pCfg->IsSaveRelFile(), pOnlyTxt );
446 if(nSuccess == (USHORT) -1 )
448 InfoBox(pWrtShell->GetView().GetWindow(), SW_RES(MSG_ERR_INSERT_GLOS)).Execute();
450 if( !pCurGrp )
451 rStatGlossaries.PutGroupDoc( pTmp );
452 return BOOL( nSuccess != (USHORT) -1 );
454 /*------------------------------------------------------------------------
455 Beschreibung: Loeschen eines Textbausteines
456 ------------------------------------------------------------------------*/
459 BOOL SwGlossaryHdl::DelGlossary(const String &rShortName)
461 SwTextBlocks *pGlossary = pCurGrp ? pCurGrp
462 : rStatGlossaries.GetGroupDoc(aCurGrp);
463 //pTmp == 0 if the AutoText path setting is wrong
464 if(!pGlossary || !ConvertToNew(*pGlossary))
465 return FALSE;
467 USHORT nIdx = pGlossary->GetIndex( rShortName );
468 if( nIdx != (USHORT) -1 )
469 pGlossary->Delete( nIdx );
470 if( !pCurGrp )
471 rStatGlossaries.PutGroupDoc( pGlossary );
472 return TRUE;
475 /*------------------------------------------------------------------------
476 Beschreibung: Kurzform expandieren
477 ------------------------------------------------------------------------*/
480 BOOL SwGlossaryHdl::ExpandGlossary()
482 ASSERT(pWrtShell->CanInsert(), illegal);
483 SwTextBlocks *pGlossary;
484 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
485 DBG_ASSERT(pFact, "Dialogdiet fail!");
486 ::GlossaryGetCurrGroup fnGetCurrGroup = pFact->GetGlossaryCurrGroupFunc( DLG_RENAME_GLOS );
487 DBG_ASSERT(fnGetCurrGroup, "Dialogdiet fail!");
488 String sGroupName( (*fnGetCurrGroup)() );
489 if(STRING_NOTFOUND == sGroupName.Search(GLOS_DELIM))
490 FindGroupName(sGroupName);
491 pGlossary = rStatGlossaries.GetGroupDoc(sGroupName);
493 String aShortName;
495 // bei Textselektion diese verwenden
496 if(pWrtShell->SwCrsrShell::HasSelection() && !pWrtShell->IsBlockMode())
498 aShortName = pWrtShell->GetSelTxt();
500 else
502 if(pWrtShell->IsAddMode())
503 pWrtShell->LeaveAddMode();
504 else if(pWrtShell->IsBlockMode())
505 pWrtShell->LeaveBlockMode();
506 else if(pWrtShell->IsExtMode())
507 pWrtShell->LeaveExtMode();
508 // Wort selektieren
509 pWrtShell->SelNearestWrd();
510 // Wort erfragen
511 if(pWrtShell->IsSelection())
512 aShortName = pWrtShell->GetSelTxt();
514 return pGlossary ? Expand( aShortName, &rStatGlossaries, pGlossary ) : FALSE;
517 BOOL SwGlossaryHdl::Expand( const String& rShortName,
518 SwGlossaries *pGlossaries,
519 SwTextBlocks *pGlossary )
521 TextBlockInfoArr aFoundArr;
522 String aShortName( rShortName );
523 BOOL bCancel = FALSE;
524 // search for text block
525 //#b6633427# - don't prefer current group depending on configuration setting
526 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
527 USHORT nFound = !pCfg->IsSearchInAllCategories() ? pGlossary->GetIndex( aShortName ) : -1;
528 // if not found then search in all groups
529 if( nFound == (USHORT) -1 )
531 const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
532 SwGlossaryList* pGlossaryList = ::GetGlossaryList();
533 USHORT nGroupCount = pGlossaryList->GetGroupCount();
534 for(USHORT i = 1; i <= nGroupCount; i++)
536 // Gruppenname mit Pfad-Extension besorgen
537 String sTitle;
538 String sGroupName = pGlossaryList->GetGroupName(i - 1, FALSE, &sTitle);
539 if(sGroupName == pGlossary->GetName())
540 continue;
541 USHORT nBlockCount = pGlossaryList->GetBlockCount(i -1);
542 if(nBlockCount)
544 for(USHORT j = 0; j < nBlockCount; j++)
546 String sEntry;
547 String sLongName(pGlossaryList->GetBlockName(i - 1, j, sEntry));
548 if( rSCmp.isEqual( rShortName, sEntry ))
550 TextBlockInfo_Impl* pData = new TextBlockInfo_Impl;
551 pData->sTitle = sTitle;
552 pData->sLongName = sLongName;
553 pData->sGroupName = sGroupName;
554 aFoundArr.Insert(pData, aFoundArr.Count());
559 if( aFoundArr.Count() ) // einer wurde gefunden
561 pGlossaries->PutGroupDoc(pGlossary);
562 if(1 == aFoundArr.Count())
564 TextBlockInfo_Impl* pData = aFoundArr.GetObject(0);
565 pGlossary = (SwTextBlocks *)pGlossaries->GetGroupDoc(pData->sGroupName);
566 nFound = pGlossary->GetIndex( aShortName );
568 else
570 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
571 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
573 AbstarctSwSelGlossaryDlg* pDlg = pFact->CreateSwSelGlossaryDlg( 0, aShortName, DLG_SEL_GLOS );
574 DBG_ASSERT(pDlg, "Dialogdiet fail!");
575 for(USHORT i = 0; i < aFoundArr.Count(); ++i)
577 TextBlockInfo_Impl* pData = aFoundArr.GetObject(i);
578 pDlg->InsertGlos(pData->sTitle, pData->sLongName);
580 pDlg->SelectEntryPos(0);
581 const USHORT nRet = RET_OK == pDlg->Execute()?
582 pDlg->GetSelectedIdx():
583 LISTBOX_ENTRY_NOTFOUND;
584 delete pDlg;
585 if(LISTBOX_ENTRY_NOTFOUND != nRet)
587 TextBlockInfo_Impl* pData = aFoundArr.GetObject(nRet);
588 pGlossary = (SwTextBlocks *)pGlossaries->GetGroupDoc(pData->sGroupName);
589 nFound = pGlossary->GetIndex( aShortName );
591 else
593 nFound = (USHORT) -1;
594 bCancel = TRUE;
600 // nicht gefunden
601 if( nFound == (USHORT) -1 )
603 if( !bCancel )
605 pGlossaries->PutGroupDoc(pGlossary);
607 const USHORT nMaxLen = 50;
608 if(pWrtShell->IsSelection() && aShortName.Len() > nMaxLen)
610 aShortName.Erase(nMaxLen);
611 aShortName.AppendAscii(" ...");
613 if ( aShortName.EqualsAscii ( "StarWriterTeam", 0, 14 ) )
615 String sGraphicName ( RTL_CONSTASCII_USTRINGPARAM ( "StarWriter team photo" ) );
616 String sTeamCredits ( RTL_CONSTASCII_USTRINGPARAM ( "StarWriter team credits" ) );
617 pWrtShell->StartUndo ( UNDO_INSGLOSSARY );
618 pWrtShell->StartAllAction();
619 if(pWrtShell->HasSelection())
620 pWrtShell->DelLeft();
621 Bitmap aBitmap ( SW_RES ( BMP_SW_TEAM_MUGSHOT ) );
622 pWrtShell->Insert ( aEmptyStr, aEmptyStr, aBitmap);
623 pWrtShell->SetFlyName ( sGraphicName );
624 SwTxtFmtColl* pColl = pWrtShell->GetTxtCollFromPool ( RES_POOLCOLL_LABEL_ABB );
625 const IDocumentFieldsAccess* pIDFA = pWrtShell->getIDocumentFieldsAccess();
626 SwFieldType* pType = pIDFA->GetFldType( RES_SETEXPFLD, pColl->GetName(), false );
627 sal_uInt16 nId = pIDFA->GetFldTypes()->GetPos( pType );
628 pWrtShell->InsertLabel( LTYPE_OBJECT, aEmptyStr, aEmptyStr, aEmptyStr, FALSE, nId, aEmptyStr );
629 pWrtShell->SwFEShell::SetFlyName( sTeamCredits );
630 pWrtShell->SwFEShell::SelectObj ( Point ( ULONG_MAX, ULONG_MAX ) );
631 pWrtShell->EnterStdMode();
632 pWrtShell->EndPara ( TRUE );
633 String aTmp ( SW_RES ( STR_SW_TEAM_NAMES ) );
634 pWrtShell->Insert ( aTmp );
635 SvxAdjustItem aAdjustItem( SVX_ADJUST_CENTER, RES_PARATR_ADJUST );
636 pWrtShell->SetAttr( aAdjustItem );
637 pWrtShell->SttPara ();
638 pWrtShell->SplitNode();
639 pWrtShell->Left(CRSR_SKIP_CHARS, FALSE, 1, FALSE );
640 SvxWeightItem aWeightItem ( WEIGHT_BOLD, RES_CHRATR_WEIGHT );
641 pWrtShell->Insert ( String ( RTL_CONSTASCII_USTRINGPARAM ( "The StarWriter team!" ) ) );
642 pWrtShell->SttPara ( TRUE );
643 pWrtShell->SetAttr( aWeightItem);
644 pWrtShell->GotoFly ( sTeamCredits);
645 pWrtShell->EndAllAction();
646 pWrtShell->EndUndo( UNDO_INSGLOSSARY );
648 else if ( aShortName.EqualsAscii ( "GoOOTeam", 0, 14 ) )
650 String sGraphicName ( RTL_CONSTASCII_USTRINGPARAM ( "Go-oo Team photo" ) );
651 String sTeamCredits ( RTL_CONSTASCII_USTRINGPARAM ( "go-oo team credits" ) );
652 pWrtShell->StartUndo ( UNDO_INSGLOSSARY );
653 pWrtShell->StartAllAction();
654 if(pWrtShell->HasSelection())
655 pWrtShell->DelLeft();
656 Bitmap aBitmap ( SW_RES ( BMP_GO_OO_TEAM_MUGSHOT ) );
657 pWrtShell->Insert ( aEmptyStr, aEmptyStr, aBitmap);
658 pWrtShell->SetFlyName ( sGraphicName );
659 SwTxtFmtColl* pColl = pWrtShell->GetTxtCollFromPool ( RES_POOLCOLL_LABEL_ABB );
660 const IDocumentFieldsAccess* pIDFA = pWrtShell->getIDocumentFieldsAccess();
661 SwFieldType* pType = pIDFA->GetFldType( RES_SETEXPFLD, pColl->GetName(), false );
662 sal_uInt16 nId = pIDFA->GetFldTypes()->GetPos( pType );
663 pWrtShell->InsertLabel( LTYPE_OBJECT, aEmptyStr, aEmptyStr, aEmptyStr, FALSE, nId, aEmptyStr );
664 pWrtShell->SwFEShell::SetFlyName( sTeamCredits );
665 pWrtShell->SwFEShell::SelectObj ( Point ( ULONG_MAX, ULONG_MAX ) );
666 pWrtShell->EnterStdMode();
667 pWrtShell->EndPara ( TRUE );
668 String aTmp ( SW_RES ( STR_GO_OO_TEAM_NAMES ) );
669 pWrtShell->Insert ( aTmp );
670 SvxAdjustItem aAdjustItem( SVX_ADJUST_CENTER, RES_PARATR_ADJUST );
671 pWrtShell->SetAttr( aAdjustItem );
672 pWrtShell->SttPara ();
673 pWrtShell->SplitNode();
674 pWrtShell->Left(CRSR_SKIP_CHARS, FALSE, 1, FALSE );
675 SvxWeightItem aWeightItem ( WEIGHT_BOLD, RES_CHRATR_WEIGHT );
676 pWrtShell->Insert ( String ( RTL_CONSTASCII_USTRINGPARAM ( "The go-oo.org team!" ) ) );
677 pWrtShell->SttPara ( TRUE );
678 pWrtShell->SetAttr( aWeightItem);
679 pWrtShell->GotoFly ( sTeamCredits);
680 pWrtShell->EndAllAction();
681 pWrtShell->EndUndo( UNDO_INSGLOSSARY );
683 else
685 String aTmp( SW_RES(STR_NOGLOS));
686 aTmp.SearchAndReplaceAscii("%1", aShortName);
687 InfoBox( pWrtShell->GetView().GetWindow(), aTmp ).Execute();
692 return FALSE;
694 else
696 String aLongName = pGlossary->GetLongName( nFound );
697 SvxMacro aStartMacro(aEmptyStr, aEmptyStr, STARBASIC);
698 SvxMacro aEndMacro(aEmptyStr, aEmptyStr, STARBASIC);
699 GetMacros( aShortName, aStartMacro, aEndMacro, pGlossary );
701 // StartAction darf nich vor HasSelection und DelRight stehen,
702 // sonst wird der moeglich Shellwechsel verzoegert und
703 // API-Programme wuerden dann haengenbleiben
704 // ausserdem darf das Ereignismacro ebenfalls nicht in einer Action gerufen werden
705 pWrtShell->StartUndo(UNDO_INSGLOSSARY);
706 if( aStartMacro.GetMacName().Len() )
707 pWrtShell->ExecMacro( aStartMacro );
708 if(pWrtShell->HasSelection())
709 pWrtShell->DelLeft();
710 pWrtShell->StartAllAction();
712 // alle InputFelder zwischenspeichern
713 SwInputFieldList aFldLst( pWrtShell, TRUE );
715 pWrtShell->InsertGlossary(*pGlossary, aShortName);
716 pWrtShell->EndAllAction();
717 if( aEndMacro.GetMacName().Len() )
719 pWrtShell->ExecMacro( aEndMacro );
721 pWrtShell->EndUndo(UNDO_INSGLOSSARY);
723 // fuer alle neuen InputFelder die Eingaben abfordern
724 if( aFldLst.BuildSortLst() )
725 pWrtShell->UpdateInputFlds( &aFldLst );
727 pGlossaries->PutGroupDoc(pGlossary);
728 return TRUE;
731 /*------------------------------------------------------------------------
732 Beschreibung: Textbaustein einfuegen
733 ------------------------------------------------------------------------*/
736 BOOL SwGlossaryHdl::InsertGlossary(const String &rName)
738 ASSERT(pWrtShell->CanInsert(), illegal);
740 SwTextBlocks *pGlos =
741 pCurGrp? pCurGrp: rStatGlossaries.GetGroupDoc(aCurGrp);
743 if (!pGlos)
744 return FALSE;
746 SvxMacro aStartMacro(aEmptyStr, aEmptyStr, STARBASIC);
747 SvxMacro aEndMacro(aEmptyStr, aEmptyStr, STARBASIC);
748 GetMacros( rName, aStartMacro, aEndMacro, pGlos );
750 // StartAction darf nich vor HasSelection und DelRight stehen,
751 // sonst wird der moeglich Shellwechsel verzoegert und
752 // API-Programme wuerden dann haengenbleiben
753 // ausserdem darf das Ereignismacro ebenfalls nicht in einer Action gerufen werden
754 if( aStartMacro.GetMacName().Len() )
755 pWrtShell->ExecMacro( aStartMacro );
756 if( pWrtShell->HasSelection() )
757 pWrtShell->DelRight();
758 pWrtShell->StartAllAction();
760 // alle InputFelder zwischenspeichern
761 SwInputFieldList aFldLst( pWrtShell, TRUE );
763 pWrtShell->InsertGlossary(*pGlos, rName);
764 pWrtShell->EndAllAction();
765 if( aEndMacro.GetMacName().Len() )
767 pWrtShell->ExecMacro( aEndMacro );
770 // fuer alle neuen InputFelder die Eingaben abfordern
771 if( aFldLst.BuildSortLst() )
772 pWrtShell->UpdateInputFlds( &aFldLst );
774 if(!pCurGrp)
775 rStatGlossaries.PutGroupDoc(pGlos);
776 return TRUE;
779 /*------------------------------------------------------------------------
780 Beschreibung: Macro setzen / erfragen
781 ------------------------------------------------------------------------*/
784 void SwGlossaryHdl::SetMacros(const String& rShortName,
785 const SvxMacro* pStart,
786 const SvxMacro* pEnd,
787 SwTextBlocks *pGlossary )
789 SwTextBlocks *pGlos = pGlossary ? pGlossary :
790 pCurGrp ? pCurGrp
791 : rStatGlossaries.GetGroupDoc( aCurGrp );
792 SvxMacroTableDtor aMacroTbl;
793 if( pStart )
794 aMacroTbl.Insert( SW_EVENT_START_INS_GLOSSARY, new SvxMacro(*pStart));
795 if( pEnd )
796 aMacroTbl.Insert( SW_EVENT_END_INS_GLOSSARY, new SvxMacro(*pEnd));
797 USHORT nIdx = pGlos->GetIndex( rShortName );
798 if( !pGlos->SetMacroTable( nIdx, aMacroTbl ) && pGlos->GetError() )
799 ErrorHandler::HandleError( pGlos->GetError() );
801 if(!pCurGrp && !pGlossary)
802 rStatGlossaries.PutGroupDoc(pGlos);
805 void SwGlossaryHdl::GetMacros( const String &rShortName,
806 SvxMacro& rStart,
807 SvxMacro& rEnd,
808 SwTextBlocks *pGlossary )
810 SwTextBlocks *pGlos = pGlossary ? pGlossary
811 : pCurGrp ? pCurGrp
812 : rStatGlossaries.GetGroupDoc(aCurGrp);
813 USHORT nIndex = pGlos->GetIndex( rShortName );
814 if( nIndex != USHRT_MAX )
816 SvxMacroTableDtor aMacroTbl;
817 if( pGlos->GetMacroTable( nIndex, aMacroTbl ) )
819 SvxMacro *pMacro = aMacroTbl.Get( SW_EVENT_START_INS_GLOSSARY );
820 if( pMacro )
821 rStart = *pMacro;
823 pMacro = aMacroTbl.Get( SW_EVENT_END_INS_GLOSSARY );
824 if( pMacro )
825 rEnd = *pMacro;
829 if( !pCurGrp && !pGlossary )
830 rStatGlossaries.PutGroupDoc( pGlos );
834 /*------------------------------------------------------------------------
835 Beschreibung: ctor, dtor
836 ------------------------------------------------------------------------*/
839 SwGlossaryHdl::SwGlossaryHdl(SfxViewFrame* pVwFrm, SwWrtShell *pSh)
840 : rStatGlossaries( *::GetGlossaries() ),
841 aCurGrp( rStatGlossaries.GetDefName() ),
842 pViewFrame( pVwFrm ),
843 pWrtShell( pSh ),
844 pCurGrp( 0 )
849 SwGlossaryHdl::~SwGlossaryHdl()
851 if( pCurGrp )
852 rStatGlossaries.PutGroupDoc( pCurGrp );
855 /*------------------------------------------------------------------------
856 Beschreibung: Umbenennen eines Textbausteines
857 ------------------------------------------------------------------------*/
860 BOOL SwGlossaryHdl::Rename(const String& rOldShort, const String& rNewShortName,
861 const String& rNewName )
863 BOOL bRet = FALSE;
864 SwTextBlocks *pGlossary = pCurGrp ? pCurGrp
865 : rStatGlossaries.GetGroupDoc(aCurGrp);
866 if(pGlossary)
868 if(!ConvertToNew(*pGlossary))
869 return FALSE;
871 USHORT nIdx = pGlossary->GetIndex( rOldShort );
872 USHORT nOldLongIdx = pGlossary->GetLongIndex( rNewName );
873 USHORT nOldIdx = pGlossary->GetIndex( rNewShortName );
875 if( nIdx != USHRT_MAX &&
876 (nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx )&&
877 (nOldIdx == USHRT_MAX || nOldIdx == nIdx ))
879 String aNewShort( rNewShortName );
880 String aNewName( rNewName );
881 pGlossary->Rename( nIdx, &aNewShort, &aNewName );
882 bRet = pGlossary->GetError() == 0;
884 if( !pCurGrp )
885 rStatGlossaries.PutGroupDoc(pGlossary);
887 return bRet;
891 BOOL SwGlossaryHdl::IsReadOnly( const String* pGrpNm ) const
893 SwTextBlocks *pGlossary = 0;
895 if (pGrpNm)
896 pGlossary = rStatGlossaries.GetGroupDoc( *pGrpNm );
897 else if (pCurGrp)
898 pGlossary = pCurGrp;
899 else
900 pGlossary = rStatGlossaries.GetGroupDoc(aCurGrp);
902 BOOL bRet = pGlossary ? pGlossary->IsReadOnly() : TRUE;
903 if( pGrpNm || !pCurGrp )
904 delete pGlossary;
905 return bRet;
909 BOOL SwGlossaryHdl::IsOld() const
911 SwTextBlocks *pGlossary = pCurGrp ? pCurGrp
912 : rStatGlossaries.GetGroupDoc(aCurGrp);
913 BOOL bRet = pGlossary ? pGlossary->IsOld() : FALSE;
914 if( !pCurGrp )
915 delete pGlossary;
916 return bRet;
919 /*-----------------09.06.97 16:15-------------------
920 Gruppe ohne Pfadindex finden
921 --------------------------------------------------*/
922 BOOL SwGlossaryHdl::FindGroupName(String & rGroup)
924 return rStatGlossaries.FindGroupName(rGroup);
927 /* -----------------29.07.99 08:34-------------------
929 --------------------------------------------------*/
930 BOOL SwGlossaryHdl::CopyToClipboard(SwWrtShell& rSh, const String& rShortName)
932 SwTextBlocks *pGlossary = pCurGrp ? pCurGrp
933 : rStatGlossaries.GetGroupDoc(aCurGrp);
935 SwTransferable* pTransfer = new SwTransferable( rSh );
936 /*??*/uno::Reference<
937 datatransfer::XTransferable > xRef( pTransfer );
939 int nRet = pTransfer->CopyGlossary( *pGlossary, rShortName );
940 if( !pCurGrp )
941 rStatGlossaries.PutGroupDoc( pGlossary );
942 return 0 != nRet;
945 BOOL SwGlossaryHdl::ImportGlossaries( const String& rName )
947 BOOL bRet = FALSE;
948 if( rName.Len() )
950 const SfxFilter* pFilter = 0;
951 SfxMedium* pMed = new SfxMedium( rName, STREAM_READ, TRUE, 0, 0 );
952 SfxFilterMatcher aMatcher( String::CreateFromAscii("swriter") );
953 pMed->UseInteractionHandler( TRUE );
954 if( !aMatcher.GuessFilter( *pMed, &pFilter, FALSE ) )
956 SwTextBlocks *pGlossary;
957 pMed->SetFilter( pFilter );
958 Reader* pR = SwReaderWriter::GetReader( pFilter->GetUserData() );
959 if( pR && 0 != ( pGlossary = pCurGrp ? pCurGrp
960 : rStatGlossaries.GetGroupDoc(aCurGrp)) )
962 SwReader aReader( *pMed, rName );
963 if( aReader.HasGlossaries( *pR ) )
965 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
966 bRet = aReader.ReadGlossaries( *pR, *pGlossary,
967 pCfg->IsSaveRelFile() );
971 DELETEZ(pMed);
973 return bRet;