LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/misc - glossary.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 637 0.0 %
Date: 2012-12-27 Functions: 0 55 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <hintids.hxx>
      21             : 
      22             : #include <vcl/menu.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <vcl/help.hxx>
      25             : #include <svl/stritem.hxx>
      26             : #include <unotools/pathoptions.hxx>
      27             : #include <unotools/lingucfg.hxx>
      28             : #include <sfx2/request.hxx>
      29             : #include <sfx2/fcontnr.hxx>
      30             : 
      31             : #include <svx/svxdlg.hxx>
      32             : #include <svx/dialogs.hrc>
      33             : #include <editeng/acorrcfg.hxx>
      34             : #include <sfx2/viewfrm.hxx>
      35             : #include <unocrsr.hxx>
      36             : #include <unotools.hxx>
      37             : #include <comphelper/processfactory.hxx>
      38             : #include <comphelper/string.hxx>
      39             : #include <ucbhelper/content.hxx>
      40             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      41             : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
      42             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      43             : #include <svl/urihelper.hxx>
      44             : #include <unotools/charclass.hxx>
      45             : #include "svtools/treelistentry.hxx"
      46             : #include <swwait.hxx>
      47             : #include <swtypes.hxx>
      48             : #include <wrtsh.hxx>
      49             : #include <view.hxx>
      50             : #include <basesh.hxx>
      51             : #include <glossary.hxx>
      52             : #include <gloshdl.hxx>
      53             : #include <glosbib.hxx>
      54             : #include <initui.hxx>                   // for ::GetGlossaries()
      55             : #include <glosdoc.hxx>
      56             : #include <macassgn.hxx>
      57             : #include <swevent.hxx>
      58             : #include <docsh.hxx>
      59             : #include <shellio.hxx>
      60             : 
      61             : #include <cmdid.h>
      62             : #include <helpid.h>
      63             : #include <swerror.h>
      64             : #include <globals.hrc>
      65             : #include <misc.hrc>
      66             : #include <glossary.hrc>
      67             : #include <swmodule.hxx>
      68             : #include <sfx2/filedlghelper.hxx>
      69             : 
      70             : #include "access.hrc"
      71             : 
      72             : #define LONG_LENGTH 60
      73             : #define SHORT_LENGTH 30
      74             : 
      75             : 
      76             : using namespace ::com::sun::star;
      77             : using namespace ::com::sun::star::lang;
      78             : using namespace ::com::sun::star::uno;
      79             : using namespace ::com::sun::star::text;
      80             : using namespace ::com::sun::star::ucb;
      81             : using namespace ::com::sun::star::ui::dialogs;
      82             : using namespace ::comphelper;
      83             : using namespace ::ucbhelper;
      84             : using ::rtl::OUString;
      85             : using namespace ::sfx2;
      86             : 
      87           0 : static String lcl_GetValidShortCut( const String& rName )
      88             : {
      89           0 :     const sal_uInt16 nSz = rName.Len();
      90             : 
      91           0 :     if ( 0 == nSz )
      92           0 :         return rName;
      93             : 
      94           0 :     sal_uInt16 nStart = 1;
      95           0 :     while( rName.GetChar( nStart-1 ) == ' ' && nStart < nSz )
      96           0 :         nStart++;
      97             : 
      98           0 :     String aBuf = rtl::OUString(rName.GetChar(nStart-1));
      99             : 
     100           0 :     for( ; nStart < nSz; ++nStart )
     101             :     {
     102           0 :         if( rName.GetChar( nStart-1 ) == ' ' && rName.GetChar( nStart ) != ' ')
     103           0 :             aBuf += rName.GetChar( nStart );
     104             :     }
     105           0 :     return aBuf;
     106             : }
     107             : 
     108           0 : struct GroupUserData
     109             : {
     110             :     String      sGroupName;
     111             :     sal_uInt16  nPathIdx;
     112             :     sal_Bool        bReadonly;
     113             : 
     114           0 :     GroupUserData()
     115             :         : nPathIdx(0),
     116           0 :           bReadonly(sal_False)  {}
     117             : };
     118             : 
     119             : /*------------------------------------------------------------------------
     120             :  Description:   dialog for new block name
     121             : ------------------------------------------------------------------------*/
     122           0 : class SwNewGlosNameDlg : public ModalDialog
     123             : {
     124             :     FixedText       aNNFT;
     125             :     Edit            aNewName;
     126             :     FixedText       aNSFT;
     127             :     NoSpaceEdit     aNewShort;
     128             :     OKButton        aOk;
     129             :     CancelButton    aCancel;
     130             :     FixedText       aONFT;
     131             :     Edit            aOldName;
     132             :     FixedText       aOSFT;
     133             :     Edit            aOldShort;
     134             :     FixedLine       aFL;
     135             : 
     136             : protected:
     137             :     DECL_LINK( Modify, Edit * );
     138             :     DECL_LINK(Rename, void *);
     139             : 
     140             : public:
     141             :     SwNewGlosNameDlg( Window* pParent,
     142             :                       const String& rOldName,
     143             :                       const String& rOldShort );
     144             : 
     145           0 :     String GetNewName()  const { return aNewName.GetText(); }
     146           0 :     String GetNewShort() const { return aNewShort.GetText(); }
     147             : };
     148             : 
     149           0 : SwNewGlosNameDlg::SwNewGlosNameDlg(Window* pParent,
     150             :                             const String& rOldName,
     151             :                             const String& rOldShort ) :
     152             :     ModalDialog( pParent, SW_RES( DLG_RENAME_GLOS ) ),
     153             :     aNNFT   (this, SW_RES( FT_NN    )),
     154             :     aNewName(this, SW_RES( ED_NN    )),
     155             :     aNSFT   (this, SW_RES( FT_NS    )),
     156             :     aNewShort(this,SW_RES( ED_NS    )),
     157             :     aOk     (this, SW_RES( BT_OKNEW)),
     158             :     aCancel (this, SW_RES( BT_CANCEL)),
     159             :     aONFT   (this, SW_RES( FT_ON    )),
     160             :     aOldName(this, SW_RES( ED_ON    )),
     161             :     aOSFT   (this, SW_RES( FT_OS    )),
     162             :     aOldShort(this,SW_RES( ED_OS    )),
     163           0 :     aFL    (this, SW_RES( FL_NN    ))
     164             : 
     165             : {
     166           0 :     FreeResource();
     167           0 :     aOldName.SetText( rOldName );
     168           0 :     aOldShort.SetText( rOldShort );
     169           0 :     aNewShort.SetMaxTextLen(SHORT_LENGTH);
     170           0 :     aNewName.SetMaxTextLen(LONG_LENGTH);
     171           0 :     aNewName.SetModifyHdl(LINK(this, SwNewGlosNameDlg, Modify ));
     172           0 :     aNewShort.SetModifyHdl(LINK(this, SwNewGlosNameDlg, Modify ));
     173           0 :     aOk.SetClickHdl(LINK(this, SwNewGlosNameDlg, Rename ));
     174           0 :     aNewName.GrabFocus();
     175           0 : }
     176             : 
     177             : /*------------------------------------------------------------------------
     178             :  Description:   query / set currently set group
     179             : ------------------------------------------------------------------------*/
     180           0 : String SwGlossaryDlg::GetCurrGroup()
     181             : {
     182           0 :     if( ::GetCurrGlosGroup() && ::GetCurrGlosGroup()->Len() )
     183           0 :         return *(::GetCurrGlosGroup());
     184           0 :     return SwGlossaries::GetDefName();
     185             : }
     186             : 
     187           0 : void SwGlossaryDlg::SetActGroup(const String &rGrp)
     188             : {
     189           0 :     if( !::GetCurrGlosGroup() )
     190           0 :         ::SetCurrGlosGroup( new String );
     191           0 :     *(::GetCurrGlosGroup()) = rGrp;
     192           0 : }
     193             : 
     194           0 : SwGlossaryDlg::SwGlossaryDlg(SfxViewFrame* pViewFrame,
     195             :                             SwGlossaryHdl * pGlosHdl, SwWrtShell *pWrtShell) :
     196             : 
     197           0 :     SvxStandardDialog(&pViewFrame->GetWindow(), SW_RES(DLG_GLOSSARY)),
     198             : 
     199             :     aInsertTipCB  (this, SW_RES(CB_INSERT_TIP)),
     200             :     aNameLbl      (this, SW_RES(FT_NAME)),
     201             :     aNameED       (this, SW_RES(ED_NAME)),
     202             :     aShortNameLbl (this, SW_RES(FT_SHORTNAME)),
     203             :     aShortNameEdit(this, SW_RES(ED_SHORTNAME)),
     204             :     aCategoryBox  (this, SW_RES(LB_BIB)),
     205             :     aRelativeFL   (this, SW_RES(FL_RELATIVE)),
     206             :     aFileRelCB    (this, SW_RES(CB_FILE_REL)),
     207             :     aNetRelCB     (this, SW_RES(CB_NET_REL)),
     208             :     aExampleWIN   (this, SW_RES(WIN_EXAMPLE )),
     209             :     aExampleDummyWIN(this, SW_RES(WIN_EXAMPLE_DUMMY )),
     210             :     aShowExampleCB(this, SW_RES(CB_SHOW_EXAMPLE )),
     211             :     aInsertBtn    (this, SW_RES(PB_INSERT)),
     212             :     aCloseBtn     (this, SW_RES(PB_CLOSE)),
     213             :     aHelpBtn      (this, SW_RES(PB_HELP)),
     214             :     aEditBtn      (this, SW_RES(PB_EDIT)),
     215             :     aBibBtn       (this, SW_RES(PB_BIB)),
     216             :     aPathBtn      (this, SW_RES(PB_PATH)),
     217             : 
     218             :     sReadonlyPath (SW_RES(ST_READONLY_PATH)),
     219             :     pExampleFrame(0),
     220             : 
     221           0 :     pMenu         (new PopupMenu(SW_RES(MNU_EDIT))),
     222             :     pGlossaryHdl  (pGlosHdl),
     223             : 
     224             :     bResume(sal_False),
     225             : 
     226           0 :     bSelection( pWrtShell->IsSelection() ),
     227             :     bReadOnly( sal_False ),
     228             :     bIsOld( sal_False ),
     229             :     bIsDocReadOnly(sal_False),
     230             : 
     231           0 :     pSh           (pWrtShell)
     232             : {
     233           0 :     SvtLinguConfig aLocalLinguConfig;
     234             : 
     235             :     // initialise static-pointer
     236           0 :     if( !::GetCurrGlosGroup() )
     237           0 :         ::SetCurrGlosGroup(new String);//(SwGlossaries::GetDefName());
     238             : 
     239           0 :     pMenu->SetActivateHdl(LINK(this,SwGlossaryDlg,EnableHdl));
     240           0 :     pMenu->SetSelectHdl(LINK(this,SwGlossaryDlg,MenuHdl));
     241           0 :     aEditBtn.SetPopupMenu(pMenu);
     242           0 :     aEditBtn.SetSelectHdl(LINK(this,SwGlossaryDlg,EditHdl));
     243           0 :     aPathBtn.SetClickHdl(LINK(this, SwGlossaryDlg, PathHdl));
     244             : 
     245           0 :     aNameED.SetModifyHdl(LINK(this,SwGlossaryDlg,NameModify));
     246           0 :     aShortNameEdit.SetModifyHdl(LINK(this,SwGlossaryDlg,NameModify));
     247             : 
     248           0 :     aCategoryBox.SetDoubleClickHdl(LINK(this,SwGlossaryDlg, NameDoubleClick));
     249           0 :     aCategoryBox.SetSelectHdl(LINK(this,SwGlossaryDlg,GrpSelect));
     250           0 :     aBibBtn.SetClickHdl(LINK(this,SwGlossaryDlg,BibHdl));
     251           0 :     aShowExampleCB.SetClickHdl(LINK(this, SwGlossaryDlg, ShowPreviewHdl));
     252             : 
     253           0 :     aShortNameEdit.SetMaxTextLen(SHORT_LENGTH);
     254           0 :     aNameED.SetMaxTextLen(LONG_LENGTH);
     255           0 :     FreeResource();
     256             : 
     257           0 :     const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
     258             : 
     259           0 :     aShowExampleCB.Check( rCfg.IsAutoTextPreview());
     260           0 :     ShowPreviewHdl(&aShowExampleCB);
     261             : 
     262           0 :     bIsDocReadOnly = pSh->GetView().GetDocShell()->IsReadOnly() ||
     263           0 :                       pSh->HasReadonlySel();
     264           0 :     if( bIsDocReadOnly )
     265           0 :         aInsertBtn.Enable(sal_False);
     266           0 :     aNameED.GrabFocus();
     267           0 :     aCategoryBox.SetHelpId(HID_MD_GLOS_CATEGORY);
     268           0 :     aCategoryBox.SetStyle(aCategoryBox.GetStyle()|WB_HASBUTTONS|WB_HASBUTTONSATROOT|WB_HSCROLL|WB_VSCROLL|WB_CLIPCHILDREN|WB_SORT);
     269           0 :     aCategoryBox.GetModel()->SetSortMode(SortAscending);
     270           0 :     aCategoryBox.SetHighlightRange();   // select over full width
     271           0 :     aCategoryBox.SetNodeDefaultImages( );
     272           0 :     aCategoryBox.SetAccessibleName(SW_RES(STR_ACCESS_SW_CATEGORY));
     273           0 :     aCategoryBox.SetAccessibleRelationLabeledBy(&aInsertTipCB);
     274             : 
     275           0 :     Init();
     276           0 : }
     277             : 
     278           0 : SwGlossaryDlg::~SwGlossaryDlg()
     279             : {
     280           0 :     SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
     281           0 :     rCfg.SetAutoTextPreview(aShowExampleCB.IsChecked()) ;
     282             : 
     283           0 :     aCategoryBox.Clear();
     284           0 :     aEditBtn.SetPopupMenu(0);
     285           0 :     delete pMenu;
     286           0 :     delete pExampleFrame;
     287           0 : }
     288             : 
     289             : /*------------------------------------------------------------------------
     290             :  Description:   select new group
     291             : ------------------------------------------------------------------------*/
     292           0 : IMPL_LINK( SwGlossaryDlg, GrpSelect, SvTreeListBox *, pBox )
     293             : {
     294           0 :     SvTreeListEntry* pEntry = pBox->FirstSelected();
     295           0 :     if(!pEntry)
     296           0 :         return 0;
     297           0 :     SvTreeListEntry* pParent = pBox->GetParent(pEntry) ? pBox->GetParent(pEntry) : pEntry;
     298           0 :     GroupUserData* pGroupData = (GroupUserData*)pParent->GetUserData();
     299           0 :     String *pGlosGroup = ::GetCurrGlosGroup();
     300           0 :     (*pGlosGroup) = pGroupData->sGroupName;
     301           0 :     (*pGlosGroup) += GLOS_DELIM;
     302           0 :     (*pGlosGroup) += String::CreateFromInt32(pGroupData->nPathIdx);
     303           0 :     pGlossaryHdl->SetCurGroup(*pGlosGroup);
     304             :     // set current text block
     305           0 :     bReadOnly = pGlossaryHdl->IsReadOnly();
     306           0 :     EnableShortName( !bReadOnly );
     307           0 :     aEditBtn.Enable(!bReadOnly);
     308           0 :     bIsOld = pGlossaryHdl->IsOld();
     309           0 :     if( pParent != pEntry)
     310             :     {
     311           0 :         String aName(pBox->GetEntryText(pEntry));
     312           0 :         aNameED.SetText(aName);
     313           0 :         aShortNameEdit.SetText(*(String*)pEntry->GetUserData());
     314           0 :         pEntry = pBox->GetParent(pEntry);
     315           0 :         aInsertBtn.Enable( !bIsDocReadOnly);
     316           0 :         ShowAutoText(*::GetCurrGlosGroup(), aShortNameEdit.GetText());
     317             :     }
     318             :     else
     319           0 :         ShowAutoText(aEmptyStr, aEmptyStr);
     320             :     // update controls
     321           0 :     NameModify(&aShortNameEdit);
     322           0 :     if( SfxRequest::HasMacroRecorder( pSh->GetView().GetViewFrame() ) )
     323             :     {
     324           0 :         SfxRequest aReq( pSh->GetView().GetViewFrame(), FN_SET_ACT_GLOSSARY );
     325           0 :         String sTemp(*::GetCurrGlosGroup());
     326             :         // the zeroth path is not being recorded!
     327           0 :         if('0' == sTemp.GetToken(1, GLOS_DELIM).GetChar(0))
     328           0 :             sTemp = sTemp.GetToken(0, GLOS_DELIM);
     329           0 :         aReq.AppendItem(SfxStringItem(FN_SET_ACT_GLOSSARY, sTemp));
     330           0 :         aReq.Done();
     331             :     }
     332           0 :     return 0;
     333             : }
     334             : 
     335           0 : void SwGlossaryDlg::Apply()
     336             : {
     337           0 :     const String aGlosName(aShortNameEdit.GetText());
     338           0 :     if(aGlosName.Len()) pGlossaryHdl->InsertGlossary(aGlosName);
     339           0 :     if( SfxRequest::HasMacroRecorder( pSh->GetView().GetViewFrame() ) )
     340             :     {
     341           0 :         SfxRequest aReq( pSh->GetView().GetViewFrame(), FN_INSERT_GLOSSARY );
     342           0 :         String sTemp(*::GetCurrGlosGroup());
     343             :         // the zeroth path is not being recorded!
     344           0 :         if('0' == sTemp.GetToken(1, GLOS_DELIM).GetChar(0))
     345           0 :             sTemp = sTemp.GetToken(0, GLOS_DELIM);
     346           0 :         aReq.AppendItem(SfxStringItem(FN_INSERT_GLOSSARY, sTemp));
     347           0 :         aReq.AppendItem(SfxStringItem(FN_PARAM_1, aGlosName));
     348           0 :         aReq.Done();
     349           0 :     }
     350           0 : }
     351             : 
     352           0 : /* inline */ void SwGlossaryDlg::EnableShortName(sal_Bool bOn)
     353             : {
     354           0 :     aShortNameLbl.Enable(bOn);
     355           0 :     aShortNameEdit.Enable(bOn);
     356           0 : }
     357             : 
     358             : /* --------------------------------------------------
     359             :  * does the title exist in the selected group?
     360             :  * --------------------------------------------------*/
     361           0 : SvTreeListEntry* SwGlossaryDlg::DoesBlockExist(const String& rBlock,
     362             :                 const String& rShort)
     363             : {
     364             :     // look for possible entry in TreeListBox
     365           0 :     SvTreeListEntry* pEntry = aCategoryBox.FirstSelected();
     366           0 :     if(pEntry)
     367             :     {
     368           0 :         if(aCategoryBox.GetParent(pEntry))
     369           0 :             pEntry = aCategoryBox.GetParent(pEntry);
     370           0 :         sal_uInt32 nChildCount = aCategoryBox.GetChildCount( pEntry );
     371           0 :         for(sal_uInt32 i = 0; i < nChildCount; i++)
     372             :         {
     373           0 :             SvTreeListEntry* pChild = aCategoryBox.GetEntry( pEntry, i );
     374           0 :             if(rBlock == aCategoryBox.GetEntryText(pChild) &&
     375           0 :                 (!rShort.Len() || rShort == *(String*)pChild->GetUserData()))
     376             :             {
     377           0 :                 return pChild;
     378             :             }
     379             :         }
     380             :     }
     381           0 :     return 0;
     382             : }
     383             : 
     384           0 : IMPL_LINK( SwGlossaryDlg, NameModify, Edit *, pEdit )
     385             : {
     386           0 :     String aName(aNameED.GetText());
     387           0 :     sal_Bool bNameED = pEdit == &aNameED;
     388           0 :     if( !aName.Len() )
     389             :     {
     390           0 :         if(bNameED)
     391           0 :             aShortNameEdit.SetText(aName);
     392           0 :         aInsertBtn.Enable(sal_False);
     393           0 :         return 0;
     394             :     }
     395           0 :     String sShortSearch;
     396           0 :     if(!bNameED)
     397           0 :         sShortSearch = pEdit->GetText();
     398           0 :     sal_Bool bNotFound = !DoesBlockExist(aName, sShortSearch);
     399           0 :     if(bNameED)
     400             :     {
     401             :             // did the text get in to the Listbbox in the Edit with a click?
     402           0 :         if(bNotFound)
     403             :         {
     404           0 :             aShortNameEdit.SetText( lcl_GetValidShortCut( aName ) );
     405           0 :             EnableShortName();
     406             :         }
     407             :         else
     408             :         {
     409           0 :             aShortNameEdit.SetText(pGlossaryHdl->GetGlossaryShortName(aName));
     410           0 :             EnableShortName(!bReadOnly);
     411             :         }
     412           0 :         aInsertBtn.Enable(!bNotFound && !bIsDocReadOnly);
     413             :     }
     414             :     else
     415             :     {
     416             :         //ShortNameEdit
     417           0 :         if(!bNotFound)
     418             :         {
     419           0 :             sal_Bool bEnable = !bNotFound;
     420           0 :             bEnable &= !bIsDocReadOnly;
     421           0 :             aInsertBtn.Enable(bEnable);
     422             :         }
     423             :     }
     424           0 :     return 0;
     425             : }
     426             : 
     427           0 : IMPL_LINK_INLINE_START( SwGlossaryDlg, NameDoubleClick, SvTreeListBox*, pBox )
     428             : {
     429           0 :     SvTreeListEntry* pEntry = pBox->FirstSelected();
     430           0 :     if(pBox->GetParent(pEntry) && !bIsDocReadOnly)
     431           0 :         EndDialog( RET_OK );
     432           0 :     return 0;
     433             : }
     434           0 : IMPL_LINK_INLINE_END( SwGlossaryDlg, NameDoubleClick, SvTreeListBox*, pBox )
     435             : 
     436           0 : IMPL_LINK( SwGlossaryDlg, EnableHdl, Menu *, pMn )
     437             : {
     438           0 :     SvTreeListEntry* pEntry = aCategoryBox.FirstSelected();
     439             : 
     440           0 :     const String aEditText(aNameED.GetText());
     441           0 :     const sal_Bool bHasEntry = aEditText.Len() && aShortNameEdit.GetText().Len();
     442           0 :     const sal_Bool bExists = 0 != DoesBlockExist(aEditText, aShortNameEdit.GetText());
     443           0 :     const sal_Bool bIsGroup = pEntry && !aCategoryBox.GetParent(pEntry);
     444           0 :     pMn->EnableItem(FN_GL_DEFINE, bSelection && bHasEntry && !bExists);
     445           0 :     pMn->EnableItem(FN_GL_DEFINE_TEXT, bSelection && bHasEntry && !bExists);
     446           0 :     pMn->EnableItem(FN_GL_COPY_TO_CLIPBOARD, bExists && !bIsGroup);
     447           0 :     pMn->EnableItem(FN_GL_REPLACE, bSelection && bExists && !bIsGroup && !bIsOld );
     448           0 :     pMn->EnableItem(FN_GL_REPLACE_TEXT, bSelection && bExists && !bIsGroup && !bIsOld );
     449           0 :     pMn->EnableItem(FN_GL_EDIT, bExists && !bIsGroup );
     450           0 :     pMn->EnableItem(FN_GL_RENAME, bExists && !bIsGroup );
     451           0 :     pMn->EnableItem(FN_GL_DELETE, bExists && !bIsGroup );
     452           0 :     pMn->EnableItem(FN_GL_MACRO, bExists && !bIsGroup && !bIsOld &&
     453           0 :                                     !pGlossaryHdl->IsReadOnly() );
     454           0 :     pMn->EnableItem( FN_GL_IMPORT, bIsGroup && !bIsOld && !pGlossaryHdl->IsReadOnly() );
     455           0 :     return 1;
     456             : }
     457             : 
     458           0 : IMPL_LINK( SwGlossaryDlg, MenuHdl, Menu *, pMn )
     459             : {
     460           0 :     sal_Bool bNoAttr = sal_False;
     461             : 
     462           0 :     switch(pMn->GetCurItemId())
     463             :     {
     464             :         case FN_GL_REPLACE:
     465             :         case FN_GL_REPLACE_TEXT:
     466             :             pGlossaryHdl->NewGlossary(  aNameED.GetText(),
     467             :                                         aShortNameEdit.GetText(),
     468             :                                         sal_False,
     469           0 :                                         pMn->GetCurItemId() == FN_GL_REPLACE_TEXT);
     470           0 :         break;
     471             :         case FN_GL_DEFINE_TEXT:
     472           0 :             bNoAttr = sal_True;
     473             :             // no break!!!
     474             :         case FN_GL_DEFINE:
     475             :         {
     476           0 :             const String aStr(aNameED.GetText());
     477           0 :             const String aShortName(aShortNameEdit.GetText());
     478           0 :             if(pGlossaryHdl->HasShortName(aShortName))
     479             :             {
     480           0 :                 InfoBox(this, SW_RES(MSG_DOUBLE_SHORTNAME)).Execute();
     481           0 :                 aShortNameEdit.SetSelection(Selection(0, SELECTION_MAX));
     482           0 :                 aShortNameEdit.GrabFocus();
     483             :                 break;
     484             :             }
     485           0 :             if(pGlossaryHdl->NewGlossary(aStr, aShortName, sal_False, bNoAttr ))
     486             :             {
     487           0 :                 SvTreeListEntry* pEntry = aCategoryBox.FirstSelected();
     488           0 :                 if(aCategoryBox.GetParent(pEntry))
     489           0 :                     pEntry = aCategoryBox.GetParent(pEntry);
     490             : 
     491           0 :                 SvTreeListEntry* pChild = aCategoryBox.InsertEntry(aStr, pEntry);
     492           0 :                 pChild->SetUserData(new String(aShortName));
     493           0 :                 aNameED.SetText(aStr);
     494           0 :                 aShortNameEdit.SetText(aShortName);
     495           0 :                 NameModify(&aNameED);       // for toggling the buttons
     496             : 
     497           0 :                 if( SfxRequest::HasMacroRecorder( pSh->GetView().GetViewFrame() ) )
     498             :                 {
     499           0 :                     SfxRequest aReq(pSh->GetView().GetViewFrame(), FN_NEW_GLOSSARY);
     500           0 :                     String sTemp(*::GetCurrGlosGroup());
     501             :                     // the zeroth path is not being recorded!
     502           0 :                     if('0' == sTemp.GetToken(1, GLOS_DELIM).GetChar(0))
     503           0 :                         sTemp = sTemp.GetToken(0, GLOS_DELIM);
     504           0 :                     aReq.AppendItem(SfxStringItem(FN_NEW_GLOSSARY, sTemp));
     505           0 :                     aReq.AppendItem(SfxStringItem(FN_PARAM_1, aShortName));
     506           0 :                     aReq.AppendItem(SfxStringItem(FN_PARAM_2, aStr));
     507           0 :                     aReq.Done();
     508             :                 }
     509           0 :             }
     510             :         }
     511           0 :         break;
     512             :         case FN_GL_COPY_TO_CLIPBOARD :
     513             :         {
     514           0 :             pGlossaryHdl->CopyToClipboard(*pSh, aShortNameEdit.GetText());
     515             :         }
     516           0 :         break;
     517             :         case FN_GL_EDIT:
     518           0 :         break;
     519             :         case FN_GL_RENAME:
     520             :         {
     521           0 :             aShortNameEdit.SetText(pGlossaryHdl->GetGlossaryShortName(aNameED.GetText()));
     522             :             SwNewGlosNameDlg* pNewNameDlg = new SwNewGlosNameDlg(this, aNameED.GetText(),
     523           0 :                                             aShortNameEdit.GetText() );
     524           0 :             if( RET_OK == pNewNameDlg->Execute() &&
     525             :                 pGlossaryHdl->Rename( aShortNameEdit.GetText(),
     526             :                                         pNewNameDlg->GetNewShort(),
     527           0 :                                         pNewNameDlg->GetNewName()))
     528             :             {
     529           0 :                 SvTreeListEntry* pEntry = aCategoryBox.FirstSelected();
     530             :                 SvTreeListEntry* pNewEntry = aCategoryBox.InsertEntry(
     531           0 :                         pNewNameDlg->GetNewName(), aCategoryBox.GetParent(pEntry));
     532           0 :                 pNewEntry->SetUserData(new String(pNewNameDlg->GetNewShort()));
     533           0 :                 delete (String*)pEntry->GetUserData();
     534           0 :                 aCategoryBox.GetModel()->Remove(pEntry);
     535           0 :                 aCategoryBox.Select(pNewEntry);
     536           0 :                 aCategoryBox.MakeVisible(pNewEntry);
     537             :             }
     538           0 :             GrpSelect( &aCategoryBox );
     539           0 :             delete pNewNameDlg;
     540             :         }
     541           0 :         break;
     542             :         case FN_GL_DELETE:
     543             :         {
     544           0 :             QueryBox aQuery(this, SW_RES(MSG_QUERY_DELETE));
     545           0 :             if(RET_YES == aQuery.Execute())
     546             :             {
     547           0 :                 const String aShortName(aShortNameEdit.GetText());
     548           0 :                 const String aTitle(aNameED.GetText());
     549           0 :                 if(aTitle.Len() && pGlossaryHdl->DelGlossary(aShortName))
     550             :                 {
     551           0 :                     SvTreeListEntry* pChild = DoesBlockExist(aTitle, aShortName);
     552             :                     OSL_ENSURE(pChild, "entry not found!");
     553           0 :                     SvTreeListEntry* pParent = aCategoryBox.GetParent(pChild);
     554           0 :                     aCategoryBox.Select(pParent);
     555             : 
     556           0 :                     aCategoryBox.GetModel()->Remove(pChild);
     557           0 :                     aNameED.SetText( aEmptyStr );
     558           0 :                     NameModify(&aNameED);
     559           0 :                 }
     560           0 :             }
     561             :         }
     562           0 :         break;
     563             :         case FN_GL_MACRO:
     564             :         {
     565           0 :             SfxItemSet aSet( pSh->GetAttrPool(), RES_FRMMACRO, RES_FRMMACRO, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 );
     566             : 
     567           0 :             SvxMacro aStart(aEmptyStr, aEmptyStr, STARBASIC);
     568           0 :             SvxMacro aEnd(aEmptyStr, aEmptyStr, STARBASIC);
     569           0 :             pGlossaryHdl->GetMacros(aShortNameEdit.GetText(), aStart, aEnd );
     570             : 
     571           0 :             SvxMacroItem aItem(RES_FRMMACRO);
     572           0 :             if( aStart.HasMacro() )
     573           0 :                 aItem.SetMacro( SW_EVENT_START_INS_GLOSSARY, aStart );
     574           0 :             if( aEnd.HasMacro() )
     575           0 :                 aItem.SetMacro( SW_EVENT_END_INS_GLOSSARY, aEnd );
     576             : 
     577           0 :             aSet.Put( aItem );
     578           0 :             aSet.Put( SwMacroAssignDlg::AddEvents( MACASSGN_AUTOTEXT ) );
     579             : 
     580             :             const SfxPoolItem* pItem;
     581           0 :             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     582             :             SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( this, aSet,
     583           0 :                 pSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface(), SID_EVENTCONFIG );
     584           0 :             if ( pMacroDlg && pMacroDlg->Execute() == RET_OK &&
     585           0 :                 SFX_ITEM_SET == pMacroDlg->GetOutputItemSet()->GetItemState( RES_FRMMACRO, sal_False, &pItem ) )
     586             :             {
     587           0 :                 const SvxMacroTableDtor& rTbl = ((SvxMacroItem*)pItem)->GetMacroTable();
     588             :                 pGlossaryHdl->SetMacros( aShortNameEdit.GetText(),
     589             :                                             rTbl.Get( SW_EVENT_START_INS_GLOSSARY ),
     590           0 :                                             rTbl.Get( SW_EVENT_END_INS_GLOSSARY ) );
     591             :             }
     592             : 
     593           0 :             delete pMacroDlg;
     594             :         }
     595           0 :         break;
     596             : 
     597             :         case FN_GL_IMPORT:
     598             :         {
     599             :             // call the FileOpenDialog do find WinWord - Files with templates
     600           0 :             FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
     601           0 :             uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
     602             : 
     603           0 :             SvtPathOptions aPathOpt;
     604           0 :             xFP->setDisplayDirectory(aPathOpt.GetWorkPath() );
     605             : 
     606           0 :             uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
     607           0 :             SfxFilterMatcher aMatcher( rtl::OUString::createFromAscii(SwDocShell::Factory().GetShortName()) );
     608           0 :             SfxFilterMatcherIter aIter( aMatcher );
     609           0 :             const SfxFilter* pFilter = aIter.First();
     610           0 :             while ( pFilter )
     611             :             {
     612           0 :                 if( pFilter->GetUserData() == FILTER_WW8 )
     613             :                 {
     614           0 :                     xFltMgr->appendFilter( pFilter->GetUIName(),
     615           0 :                                 pFilter->GetWildcard().getGlob() );
     616           0 :                     xFltMgr->setCurrentFilter( pFilter->GetUIName() ) ;
     617             :                 }
     618             : 
     619           0 :                 pFilter = aIter.Next();
     620             :             }
     621             : 
     622           0 :             if( aDlgHelper.Execute() == ERRCODE_NONE )
     623             :             {
     624           0 :                 if( pGlossaryHdl->ImportGlossaries( xFP->getFiles().getConstArray()[0] ))
     625           0 :                     Init();
     626             :                 else
     627             :                 {
     628           0 :                     InfoBox(this, SW_RES( MSG_NO_GLOSSARIES )).Execute();
     629             :                 }
     630           0 :             }
     631             :         }
     632           0 :            break;
     633             : 
     634             :         default:
     635           0 :             return 0;
     636             :     }
     637           0 :     return 1;
     638             : }
     639             : 
     640             : /*--------------------------------------------------------------------
     641             :      Description:   dialog manage regions
     642             :  --------------------------------------------------------------------*/
     643           0 : IMPL_LINK_NOARG(SwGlossaryDlg, BibHdl)
     644             : {
     645           0 :     SwGlossaries* pGloss = ::GetGlossaries();
     646           0 :     if( pGloss->IsGlosPathErr() )
     647           0 :         pGloss->ShowError();
     648             :     else
     649             :     {
     650             :         //check if at least one glossary path is write enabled
     651           0 :         SvtPathOptions aPathOpt;
     652           0 :         String sGlosPath( aPathOpt.GetAutoTextPath() );
     653           0 :         sal_uInt16 nPaths = comphelper::string::getTokenCount(sGlosPath, ';');
     654           0 :         sal_Bool bIsWritable = sal_False;
     655           0 :         for(sal_uInt16 nPath = 0; nPath < nPaths; nPath++)
     656             :         {
     657             :             String sPath = URIHelper::SmartRel2Abs(
     658             :                 INetURLObject(), sGlosPath.GetToken(nPath, ';'),
     659           0 :                 URIHelper::GetMaybeFileHdl());
     660             :             try
     661             :             {
     662             :                 Content aTestContent( sPath,
     663             :                             uno::Reference< XCommandEnvironment >(),
     664           0 :                             comphelper::getProcessComponentContext() );
     665           0 :                 Any aAny = aTestContent.getPropertyValue( "IsReadOnly" );
     666           0 :                 if(aAny.hasValue())
     667             :                 {
     668           0 :                     bIsWritable = !*(sal_Bool*)aAny.getValue();
     669           0 :                 }
     670             :             }
     671           0 :             catch (const Exception&)
     672             :             {
     673             :             }
     674           0 :             if(bIsWritable)
     675             :                 break;
     676           0 :         }
     677           0 :         if(bIsWritable)
     678             :         {
     679             : 
     680           0 :             SwGlossaryGroupDlg *pDlg = new SwGlossaryGroupDlg( this, pGloss->GetPathArray(), pGlossaryHdl );
     681           0 :             if ( RET_OK == pDlg->Execute() )
     682             :             {
     683           0 :                 Init();
     684             :                 //if new groups were created - select one of them
     685           0 :                 String sNewGroup = pDlg->GetCreatedGroupName();
     686           0 :                 SvTreeListEntry* pEntry = aCategoryBox.First();
     687           0 :                 while(sNewGroup.Len() && pEntry)
     688             :                 {
     689           0 :                     if(!aCategoryBox.GetParent(pEntry))
     690             :                     {
     691           0 :                         GroupUserData* pGroupData = (GroupUserData*)pEntry->GetUserData();
     692           0 :                         String sGroup = pGroupData->sGroupName;
     693           0 :                         sGroup += GLOS_DELIM;
     694           0 :                         sGroup += String::CreateFromInt32(pGroupData->nPathIdx);
     695           0 :                         if(sGroup == sNewGroup)
     696             :                         {
     697           0 :                             aCategoryBox.Select(pEntry);
     698           0 :                             aCategoryBox.MakeVisible(pEntry);
     699           0 :                             GrpSelect(&aCategoryBox);
     700             :                             break;
     701           0 :                         }
     702             :                     }
     703           0 :                     pEntry = aCategoryBox.Next(pEntry);
     704           0 :                 }
     705             : 
     706             :             }
     707           0 :             delete pDlg;
     708             :         }
     709             :         else
     710             :         {
     711           0 :             QueryBox aBox(this, WB_YES_NO, sReadonlyPath);
     712           0 :             if(RET_YES == aBox.Execute())
     713           0 :                 PathHdl(&aPathBtn);
     714           0 :         }
     715             :     }
     716           0 :     return 0;
     717             : }
     718             : 
     719             : /*------------------------------------------------------------------------
     720             :  Description:   initialisation; from Ctor and after editing regions
     721             : ------------------------------------------------------------------------*/
     722           0 : void SwGlossaryDlg::Init()
     723             : {
     724           0 :     aCategoryBox.SetUpdateMode( sal_False );
     725           0 :     aCategoryBox.Clear();
     726             :     // display text block regions
     727           0 :     const sal_uInt16 nCnt = pGlossaryHdl->GetGroupCnt();
     728           0 :     SvTreeListEntry* pSelEntry = 0;
     729           0 :     const String sSelStr(::GetCurrGlosGroup()->GetToken(0, GLOS_DELIM));
     730           0 :     const sal_uInt16 nSelPath = static_cast< sal_uInt16 >(::GetCurrGlosGroup()->GetToken(1, GLOS_DELIM).ToInt32());
     731             :     // #i66304# - "My AutoText" comes from mytexts.bau, but should be translated
     732           0 :     const String sMyAutoTextEnglish(RTL_CONSTASCII_USTRINGPARAM("My AutoText"));
     733           0 :     const String sMyAutoTextTranslated(SW_RESSTR(STR_MY_AUTOTEXT));
     734           0 :     for(sal_uInt16 nId = 0; nId < nCnt; ++nId )
     735             :     {
     736           0 :         String sTitle;
     737           0 :         String sGroupName(pGlossaryHdl->GetGroupName(nId, &sTitle));
     738           0 :         if(!sGroupName.Len())
     739           0 :             continue;
     740           0 :         if(!sTitle.Len())
     741           0 :             sTitle = sGroupName.GetToken( 0, GLOS_DELIM );
     742           0 :         if(sTitle == sMyAutoTextEnglish)
     743           0 :             sTitle = sMyAutoTextTranslated;
     744           0 :         SvTreeListEntry* pEntry = aCategoryBox.InsertEntry( sTitle );
     745           0 :         sal_uInt16 nPath = static_cast< sal_uInt16 >(sGroupName.GetToken( 1, GLOS_DELIM ).ToInt32());
     746             : 
     747           0 :         GroupUserData* pData = new GroupUserData;
     748           0 :         pData->sGroupName = sGroupName.GetToken(0, GLOS_DELIM);
     749           0 :         pData->nPathIdx = nPath;
     750           0 :         pData->bReadonly = pGlossaryHdl->IsReadOnly(&sGroupName);
     751             : 
     752           0 :         pEntry->SetUserData(pData);
     753           0 :         if(sSelStr == pData->sGroupName && nSelPath == nPath)
     754           0 :             pSelEntry = pEntry;
     755             : 
     756             :         // fill entries for the groups
     757             :         {
     758           0 :             pGlossaryHdl->SetCurGroup(sGroupName, sal_False, sal_True);
     759           0 :             const sal_uInt16 nCount = pGlossaryHdl->GetGlossaryCnt();
     760           0 :             for(sal_uInt16 i = 0; i < nCount; ++i)
     761             :             {
     762           0 :                 String sGroupTitle(pGlossaryHdl->GetGlossaryName(i));
     763             :                 SvTreeListEntry* pChild = aCategoryBox.InsertEntry(
     764           0 :                                     sGroupTitle, pEntry);
     765           0 :                 pChild->SetUserData(new String(pGlossaryHdl->GetGlossaryShortName(i)));
     766           0 :             }
     767             :         }
     768           0 :     }
     769             :         // set current group and display text blocks
     770           0 :     if(!pSelEntry)
     771             :     {
     772             :         //find a non-readonly group
     773           0 :         SvTreeListEntry* pSearch = aCategoryBox.First();
     774           0 :         while(pSearch)
     775             :         {
     776           0 :             if(!aCategoryBox.GetParent(pSearch))
     777             :             {
     778           0 :                 GroupUserData* pData = (GroupUserData*)pSearch->GetUserData();
     779           0 :                 if(!pData->bReadonly)
     780             :                 {
     781           0 :                     pSelEntry = pSearch;
     782           0 :                     break;
     783             :                 }
     784             :             }
     785           0 :             pSearch = aCategoryBox.Next(pSearch);
     786             :         }
     787           0 :         if(!pSelEntry)
     788           0 :             pSelEntry = aCategoryBox.GetEntry(0);
     789             :     }
     790           0 :     if(pSelEntry)
     791             :     {
     792           0 :         aCategoryBox.Expand(pSelEntry);
     793           0 :         aCategoryBox.Select(pSelEntry);
     794           0 :         aCategoryBox.MakeVisible(pSelEntry);
     795           0 :         GrpSelect(&aCategoryBox);
     796             :     }
     797             :     //JP 16.11.99: the SvxTreeListBox has a Bug. The Box dont recalc the
     798             :     //      outputsize, when all entries are insertet. The result is, that
     799             :     //      the Focus/Highlight rectangle is to large and paintet over the
     800             :     //      HScrollbar. -> Fix: call the resize
     801           0 :     aCategoryBox.Resize();
     802             : 
     803           0 :     aCategoryBox.GetModel()->Resort();
     804           0 :     aCategoryBox.SetUpdateMode( sal_True );
     805           0 :     aCategoryBox.Update();
     806             : 
     807           0 :     const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
     808           0 :     aFileRelCB.Check( rCfg.IsSaveRelFile() );
     809           0 :     aFileRelCB.SetClickHdl(LINK(this, SwGlossaryDlg, CheckBoxHdl));
     810           0 :     aNetRelCB.Check( rCfg.IsSaveRelNet() );
     811           0 :     aNetRelCB.SetClickHdl(LINK(this, SwGlossaryDlg, CheckBoxHdl));
     812           0 :     aInsertTipCB.Check( rCfg.IsAutoTextTip() );
     813           0 :     aInsertTipCB.SetClickHdl(LINK(this, SwGlossaryDlg, CheckBoxHdl));
     814           0 : }
     815             : 
     816           0 : IMPL_LINK_NOARG_INLINE_START(SwGlossaryDlg, EditHdl)
     817             : {
     818             : // EndDialog must not be called in MenuHdl
     819           0 :     if(aEditBtn.GetCurItemId() == FN_GL_EDIT )
     820             :     {
     821           0 :         SwTextBlocks *pGroup = ::GetGlossaries()->GetGroupDoc (  GetCurrGrpName () );
     822           0 :         sal_Bool bRet = pGlossaryHdl->ConvertToNew ( *pGroup );
     823           0 :         delete pGroup;
     824           0 :         if ( bRet )
     825           0 :             EndDialog(RET_EDIT);
     826             :     }
     827           0 :     return 0;
     828             : }
     829           0 : IMPL_LINK_NOARG_INLINE_END(SwGlossaryDlg, EditHdl)
     830             : 
     831             : /*------------------------------------------------------------------------
     832             :  Description:   KeyInput for ShortName - Edits without Spaces
     833             : ------------------------------------------------------------------------*/
     834           0 : IMPL_LINK( SwNewGlosNameDlg, Modify, Edit *, pBox )
     835             : {
     836           0 :     String aName(aNewName.GetText());
     837           0 :     SwGlossaryDlg* pDlg = (SwGlossaryDlg*)GetParent();
     838             : 
     839           0 :     if( pBox == &aNewName )
     840           0 :         aNewShort.SetText( lcl_GetValidShortCut( aName ) );
     841             : 
     842           0 :     sal_Bool bEnable = aName.Len() && aNewShort.GetText().Len() &&
     843           0 :         (!pDlg->DoesBlockExist(aName, aNewShort.GetText())
     844           0 :             || aName == aOldName.GetText());
     845           0 :     aOk.Enable(bEnable);
     846           0 :     return 0;
     847             : }
     848             : 
     849           0 : IMPL_LINK_NOARG(SwNewGlosNameDlg, Rename)
     850             : {
     851           0 :     SwGlossaryDlg* pDlg = (SwGlossaryDlg*)GetParent();
     852           0 :     String sNew = GetAppCharClass().uppercase(aNewShort.GetText());
     853           0 :     if( pDlg->pGlossaryHdl->HasShortName(aNewShort.GetText())
     854           0 :         && sNew != aOldShort.GetText() )
     855             :     {
     856           0 :         InfoBox(this, SW_RES(MSG_DOUBLE_SHORTNAME)).Execute();
     857           0 :         aNewShort.GrabFocus();
     858             :     }
     859             :     else
     860           0 :         EndDialog(sal_True);
     861           0 :     return 0;
     862             : }
     863             : 
     864           0 : IMPL_LINK( SwGlossaryDlg, CheckBoxHdl, CheckBox *, pBox )
     865             : {
     866           0 :     SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
     867           0 :     sal_Bool bCheck = pBox->IsChecked();
     868           0 :     if( pBox == &aInsertTipCB )
     869           0 :         rCfg.SetAutoTextTip(bCheck);
     870           0 :     else if(pBox == &aFileRelCB)
     871           0 :         rCfg.SetSaveRelFile(bCheck);
     872             :     else
     873           0 :         rCfg.SetSaveRelNet(bCheck);
     874           0 :     return 0;
     875             : }
     876             : 
     877             : /* --------------------------------------------------
     878             :  * TreeListBox for groups and blocks
     879             :  * --------------------------------------------------*/
     880           0 : SwGlTreeListBox::SwGlTreeListBox(Window* pParent, const ResId& rResId) :
     881             :     SvTreeListBox(pParent, rResId),
     882             :     sReadonly     (SW_RES(ST_READONLY)),
     883           0 :     pDragEntry(0)
     884             : {
     885           0 :     FreeResource();
     886           0 :     SetDragDropMode( SV_DRAGDROP_CTRL_MOVE|SV_DRAGDROP_CTRL_COPY );
     887           0 : }
     888             : 
     889           0 : void SwGlTreeListBox::Clear()
     890             : {
     891           0 :     SvTreeListEntry* pEntry = First();
     892           0 :     while(pEntry)
     893             :     {
     894           0 :         if(GetParent(pEntry))
     895           0 :             delete (String*)pEntry->GetUserData();
     896             :         else
     897           0 :             delete (GroupUserData*)pEntry->GetUserData();
     898           0 :         pEntry = Next(pEntry);
     899             :     }
     900           0 :     SvTreeListBox::Clear();
     901           0 : }
     902             : 
     903           0 : void SwGlTreeListBox::RequestHelp( const HelpEvent& rHEvt )
     904             : {
     905           0 :     Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
     906           0 :     SvTreeListEntry* pEntry = GetEntry( aPos );
     907             :     // there's only help for groups' names
     908           0 :     if(pEntry)
     909             :     {
     910             :         SvLBoxTab* pTab;
     911           0 :         SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
     912           0 :         if(pItem)
     913             :         {
     914           0 :             aPos = GetEntryPosition( pEntry );
     915           0 :              Size aSize(pItem->GetSize( this, pEntry ));
     916           0 :             aPos.X() = GetTabPos( pEntry, pTab );
     917             : 
     918           0 :             if((aPos.X() + aSize.Width()) > GetSizePixel().Width())
     919           0 :                 aSize.Width() = GetSizePixel().Width() - aPos.X();
     920           0 :             aPos = OutputToScreenPixel(aPos);
     921           0 :              Rectangle aItemRect( aPos, aSize );
     922           0 :             String sMsg;
     923           0 :             if(!GetParent(pEntry))
     924             :             {
     925           0 :                 GroupUserData* pData = (GroupUserData*)pEntry->GetUserData();
     926           0 :                 const std::vector<String> & rPathArr = ::GetGlossaries()->GetPathArray();
     927           0 :                 if( !rPathArr.empty() )
     928             :                 {
     929           0 :                     sMsg = rPathArr[pData->nPathIdx];
     930           0 :                     sMsg += INET_PATH_TOKEN;
     931           0 :                     sMsg += pData->sGroupName;
     932           0 :                     sMsg += SwGlossaries::GetExtension();
     933           0 :                     INetURLObject aTmp(sMsg);
     934           0 :                     sMsg = aTmp.GetPath();
     935             : 
     936           0 :                     if(pData->bReadonly)
     937             :                     {
     938           0 :                         sMsg += ' ';
     939           0 :                         sMsg += '(';
     940           0 :                         sMsg += sReadonly;
     941           0 :                         sMsg += ')';
     942           0 :                     }
     943             : 
     944             : 
     945             :                 }
     946             :             }
     947             :             else
     948           0 :                 sMsg = *(String*)pEntry->GetUserData();
     949             :             Help::ShowQuickHelp( this, aItemRect, sMsg,
     950           0 :                         QUICKHELP_LEFT|QUICKHELP_VCENTER );
     951             :         }
     952             :     }
     953           0 : }
     954             : 
     955           0 : DragDropMode SwGlTreeListBox::NotifyStartDrag(
     956             :                     TransferDataContainer& /*rContainer*/,
     957             :                     SvTreeListEntry* pEntry )
     958             : {
     959             :     DragDropMode  eRet;
     960           0 :     pDragEntry = pEntry;
     961           0 :     if(!GetParent(pEntry))
     962           0 :         eRet = SV_DRAGDROP_NONE;
     963             :     else
     964             :     {
     965           0 :         SwGlossaryDlg* pDlg = (SwGlossaryDlg*)Window::GetParent();
     966           0 :         SvTreeListEntry* pParent = GetParent(pEntry);
     967             : 
     968           0 :         GroupUserData* pGroupData = (GroupUserData*)pParent->GetUserData();
     969           0 :         String sEntry(pGroupData->sGroupName);
     970           0 :         sEntry += GLOS_DELIM;
     971           0 :         sEntry += String::CreateFromInt32(pGroupData->nPathIdx);
     972           0 :         sal_Int8 nDragOption = DND_ACTION_COPY;
     973           0 :         eRet = SV_DRAGDROP_CTRL_COPY;
     974           0 :         if(!pDlg->pGlossaryHdl->IsReadOnly(&sEntry))
     975             :         {
     976           0 :             eRet |= SV_DRAGDROP_CTRL_MOVE;
     977           0 :             nDragOption |= DND_ACTION_MOVE;
     978             :         }
     979           0 :         SetDragOptions( nDragOption );
     980             :     }
     981           0 :     return eRet;
     982             : }
     983             : 
     984           0 : sal_Bool    SwGlTreeListBox::NotifyAcceptDrop( SvTreeListEntry* pEntry)
     985             : {
     986             :     // TODO: Readonly - check still missing!
     987           0 :     SvTreeListEntry* pSrcParent = GetParent(pEntry) ? GetParent(pEntry) : pEntry;
     988             :     SvTreeListEntry* pDestParent =
     989           0 :         GetParent(pDragEntry ) ? GetParent(pDragEntry ) : pDragEntry ;
     990           0 :     return pDestParent != pSrcParent;
     991             : 
     992             : }
     993             : 
     994           0 : sal_Bool  SwGlTreeListBox::NotifyMoving(   SvTreeListEntry*  pTarget,
     995             :                                     SvTreeListEntry*  pEntry,
     996             :                                     SvTreeListEntry*& /*rpNewParent*/,
     997             :                                     sal_uLong&        /*rNewChildPos*/
     998             :                                 )
     999             : {
    1000           0 :     pDragEntry = 0;
    1001           0 :     if(!pTarget) // move to the beginning
    1002             :     {
    1003           0 :         pTarget = GetEntry(0);
    1004             :     }
    1005             :     // 1. move to different groups?
    1006             :     // 2. allowed to write in both groups?
    1007           0 :     SvTreeListEntry* pSrcParent = GetParent(pEntry);
    1008             :     SvTreeListEntry* pDestParent =
    1009           0 :         GetParent(pTarget) ? GetParent(pTarget) : pTarget;
    1010           0 :     sal_Bool bRet = sal_False;
    1011           0 :     if(pDestParent != pSrcParent)
    1012             :     {
    1013           0 :         SwGlossaryDlg* pDlg = (SwGlossaryDlg*)Window::GetParent();
    1014           0 :         SwWait aWait( *pDlg->pSh->GetView().GetDocShell(), sal_True );
    1015             : 
    1016           0 :         GroupUserData* pGroupData = (GroupUserData*)pSrcParent->GetUserData();
    1017           0 :         String sSourceGroup(pGroupData->sGroupName);
    1018           0 :         sSourceGroup += GLOS_DELIM;
    1019           0 :         sSourceGroup += String::CreateFromInt32(pGroupData->nPathIdx);
    1020           0 :         pDlg->pGlossaryHdl->SetCurGroup(sSourceGroup);
    1021           0 :         String sTitle(GetEntryText(pEntry));
    1022           0 :         String sShortName(*(String*)pEntry->GetUserData());
    1023             : 
    1024           0 :         GroupUserData* pDestData = (GroupUserData*)pDestParent->GetUserData();
    1025           0 :         String sDestName = pDestData->sGroupName;
    1026           0 :         sDestName += GLOS_DELIM;
    1027           0 :         sDestName += String::CreateFromInt32(pDestData->nPathIdx);
    1028             :         bRet = pDlg->pGlossaryHdl->CopyOrMove( sSourceGroup,  sShortName,
    1029           0 :                         sDestName, sTitle, sal_True );
    1030           0 :         if(bRet)
    1031             :         {
    1032           0 :             SvTreeListEntry* pChild = InsertEntry(sTitle, pDestParent);
    1033           0 :             pChild->SetUserData(new String(sShortName));
    1034           0 :             GetModel()->Remove(pEntry);
    1035           0 :         }
    1036             :     }
    1037           0 :     return sal_False; // otherwise the entry is being set automatically
    1038             : }
    1039             : 
    1040           0 : sal_Bool  SwGlTreeListBox::NotifyCopying(   SvTreeListEntry*  pTarget,
    1041             :                                     SvTreeListEntry*  pEntry,
    1042             :                                     SvTreeListEntry*& /*rpNewParent*/,
    1043             :                                     sal_uLong&        /*rNewChildPos*/
    1044             :                                 )
    1045             : {
    1046           0 :     pDragEntry = 0;
    1047             :     // 1. move in different groups?
    1048             :     // 2. allowed to write to both groups?
    1049           0 :     if(!pTarget) // move to the beginning
    1050             :     {
    1051           0 :         pTarget = GetEntry(0);
    1052             :     }
    1053           0 :     SvTreeListEntry* pSrcParent = GetParent(pEntry);
    1054             :     SvTreeListEntry* pDestParent =
    1055           0 :         GetParent(pTarget) ? GetParent(pTarget) : pTarget;
    1056           0 :     sal_Bool bRet = sal_False;
    1057           0 :     if(pDestParent != pSrcParent)
    1058             :     {
    1059           0 :         SwGlossaryDlg* pDlg = (SwGlossaryDlg*)Window::GetParent();
    1060           0 :         SwWait aWait( *pDlg->pSh->GetView().GetDocShell(), sal_True );
    1061             : 
    1062           0 :         GroupUserData* pGroupData = (GroupUserData*)pSrcParent->GetUserData();
    1063           0 :         String sSourceGroup(pGroupData->sGroupName);
    1064           0 :         sSourceGroup += GLOS_DELIM;
    1065           0 :         sSourceGroup += String::CreateFromInt32(pGroupData->nPathIdx);
    1066             : 
    1067           0 :         pDlg->pGlossaryHdl->SetCurGroup(sSourceGroup);
    1068           0 :         String sTitle(GetEntryText(pEntry));
    1069           0 :         String sShortName(*(String*)pEntry->GetUserData());
    1070             : 
    1071           0 :         GroupUserData* pDestData = (GroupUserData*)pDestParent->GetUserData();
    1072           0 :         String sDestName = pDestData->sGroupName;
    1073           0 :         sDestName += GLOS_DELIM;
    1074           0 :         sDestName += String::CreateFromInt32(pDestData->nPathIdx);
    1075             : 
    1076             :         bRet = pDlg->pGlossaryHdl->CopyOrMove( sSourceGroup,  sShortName,
    1077           0 :                         sDestName, sTitle, sal_False );
    1078           0 :         if(bRet)
    1079             :         {
    1080           0 :             SvTreeListEntry* pChild = InsertEntry(sTitle, pDestParent);
    1081           0 :             pChild->SetUserData(new String(sShortName));
    1082           0 :         }
    1083             :     }
    1084           0 :     return sal_False; // otherwise the entry is being set automatically
    1085             : }
    1086             : 
    1087           0 : String SwGlossaryDlg::GetCurrGrpName() const
    1088             : {
    1089           0 :     SvTreeListEntry* pEntry = aCategoryBox.FirstSelected();
    1090           0 :     String sRet;
    1091           0 :     if(pEntry)
    1092             :     {
    1093             :         pEntry =
    1094           0 :             aCategoryBox.GetParent(pEntry) ? aCategoryBox.GetParent(pEntry) : pEntry;
    1095           0 :         GroupUserData* pGroupData = (GroupUserData*)pEntry->GetUserData();
    1096           0 :         sRet = pGroupData->sGroupName;
    1097           0 :         sRet += GLOS_DELIM;
    1098           0 :         sRet += String::CreateFromInt32(pGroupData->nPathIdx);
    1099             :     }
    1100           0 :     return sRet;
    1101             : }
    1102             : 
    1103           0 : IMPL_LINK( SwGlossaryDlg, PathHdl, Button *, pBtn )
    1104             : {
    1105           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    1106           0 :     if(pFact)
    1107             :     {
    1108           0 :         AbstractSvxMultiPathDialog* pDlg = pFact->CreateSvxMultiPathDialog( pBtn );
    1109             :         OSL_ENSURE(pDlg, "Dialogdiet fail!");
    1110           0 :         SvtPathOptions aPathOpt;
    1111           0 :         String sGlosPath( aPathOpt.GetAutoTextPath() );
    1112           0 :         pDlg->SetPath(sGlosPath);
    1113           0 :         if(RET_OK == pDlg->Execute())
    1114             :         {
    1115           0 :             String sTmp(pDlg->GetPath());
    1116           0 :             if(sTmp != sGlosPath)
    1117             :             {
    1118           0 :                 aPathOpt.SetAutoTextPath( sTmp );
    1119           0 :                 ::GetGlossaries()->UpdateGlosPath( sal_True );
    1120           0 :                 Init();
    1121           0 :             }
    1122             :         }
    1123           0 :         delete pDlg;
    1124             :     }
    1125           0 :     return 0;
    1126             : }
    1127             : 
    1128           0 : IMPL_LINK( SwGlossaryDlg, ShowPreviewHdl, CheckBox *, pBox )
    1129             : {
    1130           0 :     sal_Bool bCreated = sal_False;
    1131           0 :     if(pBox->IsChecked())
    1132             :     {
    1133             :         //create example
    1134           0 :         if(!pExampleFrame)
    1135             :         {
    1136           0 :             Link aLink(LINK(this, SwGlossaryDlg, PreviewLoadedHdl));
    1137             :             pExampleFrame = new SwOneExampleFrame( aExampleWIN,
    1138           0 :                             EX_SHOW_ONLINE_LAYOUT, &aLink );
    1139           0 :             bCreated = sal_True;
    1140             :         }
    1141             :     }
    1142             : 
    1143           0 :     sal_Bool bShow = pBox->IsChecked() && !bCreated;
    1144           0 :     aExampleWIN.Show( bShow );
    1145           0 :     aExampleDummyWIN.Show(!bShow);
    1146           0 :     if( ::GetCurrGlosGroup() )
    1147           0 :         ShowAutoText(*::GetCurrGlosGroup(), aShortNameEdit.GetText());
    1148             : 
    1149           0 :     return 0;
    1150             : };
    1151             : 
    1152           0 : IMPL_LINK_NOARG(SwGlossaryDlg, PreviewLoadedHdl)
    1153             : {
    1154           0 :     sal_Bool bShow = aShowExampleCB.IsChecked();
    1155           0 :     aExampleWIN.Show( bShow );
    1156           0 :     aExampleDummyWIN.Show(!bShow);
    1157           0 :     ResumeShowAutoText();
    1158           0 :     return 0;
    1159             : }
    1160             : 
    1161           0 : void SwGlossaryDlg::ShowAutoText(const String& rGroup, const String& rShortName)
    1162             : {
    1163           0 :     if(aExampleWIN.IsVisible())
    1164             :     {
    1165           0 :         SetResumeData(rGroup, rShortName);
    1166             :         //try to make an Undo()
    1167           0 :         pExampleFrame->ClearDocument( sal_True );
    1168             :     }
    1169           0 : }
    1170             : 
    1171           0 : void    SwGlossaryDlg::ResumeShowAutoText()
    1172             : {
    1173           0 :     String sGroup, sShortName;
    1174           0 :     if(GetResumeData(sGroup, sShortName) && aExampleWIN.IsVisible())
    1175             :     {
    1176           0 :         if(!_xAutoText.is())
    1177             :         {
    1178             :             uno::Reference< lang::XMultiServiceFactory >
    1179           0 :                                     xMgr = getProcessServiceFactory();
    1180             :             //now the AutoText ListBoxes have to be filled
    1181             : 
    1182           0 :             uno::Reference< uno::XInterface >  xAText = xMgr->createInstance( "com.sun.star.text.AutoTextContainer" );
    1183           0 :             _xAutoText = uno::Reference< container::XNameAccess >(xAText, uno::UNO_QUERY);
    1184             :         }
    1185             : 
    1186           0 :         uno::Reference< XTextCursor > & xCrsr = pExampleFrame->GetTextCursor();
    1187           0 :         if(xCrsr.is())
    1188             :         {
    1189           0 :             if(sShortName.Len())
    1190             :             {
    1191           0 :                 uno::Any aGroup = _xAutoText->getByName(sGroup);
    1192           0 :                 uno::Reference< XAutoTextGroup >  xGroup;
    1193           0 :                 OUString uShortName(sShortName);
    1194           0 :                 if((aGroup >>= xGroup) && xGroup->hasByName(uShortName))
    1195             :                 {
    1196           0 :                     uno::Any aEntry(xGroup->getByName(uShortName));
    1197           0 :                     uno::Reference< XAutoTextEntry >  xEntry;
    1198           0 :                     aEntry >>= xEntry;
    1199           0 :                     uno::Reference< XTextRange >  xRange(xCrsr, uno::UNO_QUERY);
    1200           0 :                     xEntry->applyTo(xRange);
    1201           0 :                 }
    1202             :             }
    1203             :         }
    1204             :     }
    1205           0 :     ResetResumeData();
    1206           0 : }
    1207             : 
    1208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10