LCOV - code coverage report
Current view: top level - sw/source/ui/misc - glossary.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 600 0.0 %
Date: 2014-04-11 Functions: 0 59 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/text/AutoTextContainer.hpp>
      41             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      42             : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
      43             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      44             : #include <svl/urihelper.hxx>
      45             : #include <unotools/charclass.hxx>
      46             : #include "svtools/treelistentry.hxx"
      47             : #include <swwait.hxx>
      48             : #include <swtypes.hxx>
      49             : #include <wrtsh.hxx>
      50             : #include <view.hxx>
      51             : #include <basesh.hxx>
      52             : #include <glossary.hxx>
      53             : #include <gloshdl.hxx>
      54             : #include <glosbib.hxx>
      55             : #include <initui.hxx>
      56             : #include <glosdoc.hxx>
      57             : #include <macassgn.hxx>
      58             : #include <swevent.hxx>
      59             : #include <docsh.hxx>
      60             : #include <shellio.hxx>
      61             : 
      62             : #include <cmdid.h>
      63             : #include <helpid.h>
      64             : #include <swerror.h>
      65             : #include <globals.hrc>
      66             : #include <misc.hrc>
      67             : #include <swmodule.hxx>
      68             : #include <sfx2/filedlghelper.hxx>
      69             : 
      70             : #include <boost/scoped_ptr.hpp>
      71             : 
      72             : #include "access.hrc"
      73             : 
      74             : using namespace ::com::sun::star;
      75             : using namespace ::com::sun::star::lang;
      76             : using namespace ::com::sun::star::uno;
      77             : using namespace ::com::sun::star::text;
      78             : using namespace ::com::sun::star::ucb;
      79             : using namespace ::com::sun::star::ui::dialogs;
      80             : using namespace ::ucbhelper;
      81             : using namespace ::sfx2;
      82             : 
      83           0 : static OUString lcl_GetValidShortCut( const OUString& rName )
      84             : {
      85           0 :     const sal_Int32 nSz = rName.getLength();
      86             : 
      87           0 :     if ( 0 == nSz )
      88           0 :         return rName;
      89             : 
      90           0 :     sal_Int32 nStart = 1;
      91           0 :     while( rName[nStart-1]==' ' && nStart < nSz )
      92           0 :         nStart++;
      93             : 
      94           0 :     OUString aBuf = OUString(rName[nStart-1]);
      95             : 
      96           0 :     for( ; nStart < nSz; ++nStart )
      97             :     {
      98           0 :         if( rName[nStart-1]==' ' && rName[nStart]!=' ')
      99           0 :             aBuf += OUString(rName[nStart]);
     100             :     }
     101           0 :     return aBuf;
     102             : }
     103             : 
     104           0 : struct GroupUserData
     105             : {
     106             :     OUString    sGroupName;
     107             :     sal_uInt16  nPathIdx;
     108             :     bool        bReadonly;
     109             : 
     110           0 :     GroupUserData()
     111             :         : nPathIdx(0),
     112           0 :           bReadonly(false)  {}
     113             : };
     114             : 
     115             : /*------------------------------------------------------------------------
     116             :  Description:   dialog for new block name
     117             : ------------------------------------------------------------------------*/
     118           0 : class SwNewGlosNameDlg : public ModalDialog
     119             : {
     120             :     Edit*        m_pNewName;
     121             :     NoSpaceEdit* m_pNewShort;
     122             :     OKButton*    m_pOk;
     123             :     Edit*        m_pOldName;
     124             :     Edit*        m_pOldShort;
     125             : 
     126             : protected:
     127             :     DECL_LINK( Modify, Edit * );
     128             :     DECL_LINK(Rename, void *);
     129             : 
     130             : public:
     131             :     SwNewGlosNameDlg( Window* pParent,
     132             :                       const OUString& rOldName,
     133             :                       const OUString& rOldShort );
     134             : 
     135           0 :     OUString GetNewName()  const { return m_pNewName->GetText(); }
     136           0 :     OUString GetNewShort() const { return m_pNewShort->GetText(); }
     137             : };
     138             : 
     139           0 : SwNewGlosNameDlg::SwNewGlosNameDlg(Window* pParent,
     140             :                             const OUString& rOldName,
     141             :                             const OUString& rOldShort )
     142             :     : ModalDialog(pParent, "RenameAutoTextDialog",
     143           0 :         "modules/swriter/ui/renameautotextdialog.ui")
     144             : {
     145           0 :     get(m_pNewName, "newname");
     146           0 :     get(m_pNewShort, "newsc");
     147           0 :     get(m_pOk, "ok");
     148           0 :     get(m_pOldName, "oldname");
     149           0 :     get(m_pOldShort, "oldsc");
     150             : 
     151           0 :     m_pOldName->SetText( rOldName );
     152           0 :     m_pOldShort->SetText( rOldShort );
     153           0 :     m_pNewName->SetModifyHdl(LINK(this, SwNewGlosNameDlg, Modify ));
     154           0 :     m_pNewShort->SetModifyHdl(LINK(this, SwNewGlosNameDlg, Modify ));
     155           0 :     m_pOk->SetClickHdl(LINK(this, SwNewGlosNameDlg, Rename ));
     156           0 :     m_pNewName->GrabFocus();
     157           0 : }
     158             : 
     159             : /*------------------------------------------------------------------------
     160             :  Description:   query / set currently set group
     161             : ------------------------------------------------------------------------*/
     162           0 : OUString SwGlossaryDlg::GetCurrGroup()
     163             : {
     164           0 :     if( !::GetCurrGlosGroup().isEmpty() )
     165           0 :         return ::GetCurrGlosGroup();
     166           0 :     return SwGlossaries::GetDefName();
     167             : }
     168             : 
     169           0 : void SwGlossaryDlg::SetActGroup(const OUString &rGrp)
     170             : {
     171           0 :     ::SetCurrGlosGroup(rGrp);
     172           0 : }
     173             : 
     174           0 : SwGlossaryDlg::SwGlossaryDlg(SfxViewFrame* pViewFrame,
     175             :                             SwGlossaryHdl * pGlosHdl, SwWrtShell *pWrtShell)
     176           0 :     : SvxStandardDialog(&pViewFrame->GetWindow(), "AutoTextDialog",
     177             :         "modules/swriter/ui/autotext.ui")
     178             :     , sReadonlyPath(SW_RESSTR(STR_READONLY_PATH))
     179             :     , pExampleFrame(0)
     180             :     , pGlossaryHdl(pGlosHdl)
     181             :     , bResume(false)
     182           0 :     , bSelection(pWrtShell->IsSelection())
     183             :     , bReadOnly(false)
     184             :     , bIsOld(false)
     185             :     , bIsDocReadOnly(false)
     186           0 :     , pSh(pWrtShell)
     187             : {
     188           0 :     get(m_pInsertTipCB, "inserttip");
     189           0 :     get(m_pNameED, "name");
     190           0 :     get(m_pShortNameLbl, "shortnameft");
     191           0 :     get(m_pShortNameEdit, "shortname");
     192           0 :     get(m_pCategoryBox, "category");
     193           0 :     get(m_pFileRelCB, "relfile");
     194           0 :     get(m_pNetRelCB, "relnet");
     195           0 :     get(m_pInsertBtn, "insert");
     196           0 :     get(m_pBibBtn, "categories");
     197           0 :     get(m_pPathBtn, "path");
     198           0 :     get(m_pExampleWIN, "example");
     199           0 :     get(m_pEditBtn, "autotext");
     200             : 
     201           0 :     SvtLinguConfig aLocalLinguConfig;
     202             : 
     203           0 :     PopupMenu *pMenu = m_pEditBtn->GetPopupMenu();
     204             :     assert(pMenu);
     205           0 :     pMenu->SetActivateHdl(LINK(this,SwGlossaryDlg,EnableHdl));
     206           0 :     pMenu->SetSelectHdl(LINK(this,SwGlossaryDlg,MenuHdl));
     207           0 :     m_pEditBtn->SetSelectHdl(LINK(this,SwGlossaryDlg,EditHdl));
     208           0 :     m_pPathBtn->SetClickHdl(LINK(this, SwGlossaryDlg, PathHdl));
     209             : 
     210           0 :     m_pNameED->SetModifyHdl(LINK(this,SwGlossaryDlg,NameModify));
     211           0 :     m_pShortNameEdit->SetModifyHdl(LINK(this,SwGlossaryDlg,NameModify));
     212             : 
     213           0 :     m_pCategoryBox->SetDoubleClickHdl(LINK(this,SwGlossaryDlg, NameDoubleClick));
     214           0 :     m_pCategoryBox->SetSelectHdl(LINK(this,SwGlossaryDlg,GrpSelect));
     215           0 :     m_pBibBtn->SetClickHdl(LINK(this,SwGlossaryDlg,BibHdl));
     216             : 
     217           0 :     m_pInsertBtn->SetClickHdl(LINK(this,SwGlossaryDlg,InsertHdl));
     218             : 
     219           0 :     ShowPreview();
     220             : 
     221           0 :     bIsDocReadOnly = pSh->GetView().GetDocShell()->IsReadOnly() ||
     222           0 :                       pSh->HasReadonlySel();
     223           0 :     if( bIsDocReadOnly )
     224           0 :         m_pInsertBtn->Enable(false);
     225           0 :     m_pNameED->GrabFocus();
     226           0 :     m_pCategoryBox->SetStyle(m_pCategoryBox->GetStyle()|WB_HASBUTTONS|WB_HASBUTTONSATROOT|WB_HSCROLL|WB_VSCROLL|WB_CLIPCHILDREN|WB_SORT);
     227           0 :     m_pCategoryBox->GetModel()->SetSortMode(SortAscending);
     228           0 :     m_pCategoryBox->SetHighlightRange();   // select over full width
     229           0 :     m_pCategoryBox->SetNodeDefaultImages( );
     230             : 
     231           0 :     Init();
     232           0 : }
     233             : 
     234           0 : SwGlossaryDlg::~SwGlossaryDlg()
     235             : {
     236           0 :     m_pCategoryBox->Clear();
     237           0 :     delete pExampleFrame;
     238           0 : }
     239             : 
     240             : /*------------------------------------------------------------------------
     241             :  Description:   select new group
     242             : ------------------------------------------------------------------------*/
     243           0 : IMPL_LINK( SwGlossaryDlg, GrpSelect, SvTreeListBox *, pBox )
     244             : {
     245           0 :     SvTreeListEntry* pEntry = pBox->FirstSelected();
     246           0 :     if(!pEntry)
     247           0 :         return 0;
     248           0 :     SvTreeListEntry* pParent = pBox->GetParent(pEntry) ? pBox->GetParent(pEntry) : pEntry;
     249           0 :     GroupUserData* pGroupData = (GroupUserData*)pParent->GetUserData();
     250             :     ::SetCurrGlosGroup(pGroupData->sGroupName
     251           0 :         + OUString(GLOS_DELIM)
     252           0 :         + OUString::number(pGroupData->nPathIdx));
     253           0 :     pGlossaryHdl->SetCurGroup(::GetCurrGlosGroup());
     254             :     // set current text block
     255           0 :     bReadOnly = pGlossaryHdl->IsReadOnly();
     256           0 :     EnableShortName( !bReadOnly );
     257           0 :     m_pEditBtn->Enable(!bReadOnly);
     258           0 :     bIsOld = pGlossaryHdl->IsOld();
     259           0 :     if( pParent != pEntry)
     260             :     {
     261           0 :         OUString aName(pBox->GetEntryText(pEntry));
     262           0 :         m_pNameED->SetText(aName);
     263           0 :         m_pShortNameEdit->SetText(*reinterpret_cast<OUString*>(pEntry->GetUserData()));
     264           0 :         m_pInsertBtn->Enable( !bIsDocReadOnly);
     265           0 :         ShowAutoText(::GetCurrGlosGroup(), m_pShortNameEdit->GetText());
     266             :     }
     267             :     else
     268           0 :         ShowAutoText(aEmptyOUStr, aEmptyOUStr);
     269             :     // update controls
     270           0 :     NameModify(m_pShortNameEdit);
     271           0 :     if( SfxRequest::HasMacroRecorder( pSh->GetView().GetViewFrame() ) )
     272             :     {
     273           0 :         SfxRequest aReq( pSh->GetView().GetViewFrame(), FN_SET_ACT_GLOSSARY );
     274           0 :         OUString sTemp(::GetCurrGlosGroup());
     275             :         // the zeroth path is not being recorded!
     276           0 :         if (sTemp.getToken(1, GLOS_DELIM).startsWith("0"))
     277           0 :             sTemp = sTemp.getToken(0, GLOS_DELIM);
     278           0 :         aReq.AppendItem(SfxStringItem(FN_SET_ACT_GLOSSARY, sTemp));
     279           0 :         aReq.Done();
     280             :     }
     281           0 :     return 0;
     282             : }
     283             : 
     284           0 : void SwGlossaryDlg::Apply()
     285             : {
     286           0 :     const OUString aGlosName(m_pShortNameEdit->GetText());
     287           0 :     if (!aGlosName.isEmpty())
     288             :     {
     289           0 :         pGlossaryHdl->InsertGlossary(aGlosName);
     290             :     }
     291           0 :     if( SfxRequest::HasMacroRecorder( pSh->GetView().GetViewFrame() ) )
     292             :     {
     293           0 :         SfxRequest aReq( pSh->GetView().GetViewFrame(), FN_INSERT_GLOSSARY );
     294           0 :         OUString sTemp(::GetCurrGlosGroup());
     295             :         // the zeroth path is not being recorded!
     296           0 :         if (sTemp.getToken(1, GLOS_DELIM).startsWith("0"))
     297           0 :             sTemp = sTemp.getToken(0, GLOS_DELIM);
     298           0 :         aReq.AppendItem(SfxStringItem(FN_INSERT_GLOSSARY, sTemp));
     299           0 :         aReq.AppendItem(SfxStringItem(FN_PARAM_1, aGlosName));
     300           0 :         aReq.Done();
     301           0 :     }
     302           0 : }
     303             : 
     304           0 : void SwGlossaryDlg::EnableShortName(sal_Bool bOn)
     305             : {
     306           0 :     m_pShortNameLbl->Enable(bOn);
     307           0 :     m_pShortNameEdit->Enable(bOn);
     308           0 : }
     309             : 
     310             : /* --------------------------------------------------
     311             :  * does the title exist in the selected group?
     312             :  * --------------------------------------------------*/
     313           0 : SvTreeListEntry* SwGlossaryDlg::DoesBlockExist(const OUString& rBlock,
     314             :                 const OUString& rShort)
     315             : {
     316             :     // look for possible entry in TreeListBox
     317           0 :     SvTreeListEntry* pEntry = m_pCategoryBox->FirstSelected();
     318           0 :     if(pEntry)
     319             :     {
     320           0 :         if(m_pCategoryBox->GetParent(pEntry))
     321           0 :             pEntry = m_pCategoryBox->GetParent(pEntry);
     322           0 :         sal_uInt32 nChildCount = m_pCategoryBox->GetChildCount( pEntry );
     323           0 :         for(sal_uInt32 i = 0; i < nChildCount; i++)
     324             :         {
     325           0 :             SvTreeListEntry* pChild = m_pCategoryBox->GetEntry( pEntry, i );
     326           0 :             if (rBlock == m_pCategoryBox->GetEntryText(pChild) &&
     327           0 :                 (rShort.isEmpty() ||
     328           0 :                  rShort==*reinterpret_cast<OUString*>(pChild->GetUserData()))
     329             :                )
     330             :             {
     331           0 :                 return pChild;
     332             :             }
     333             :         }
     334             :     }
     335           0 :     return 0;
     336             : }
     337             : 
     338           0 : IMPL_LINK( SwGlossaryDlg, NameModify, Edit *, pEdit )
     339             : {
     340           0 :     const OUString aName(m_pNameED->GetText());
     341           0 :     bool bNameED = pEdit == m_pNameED;
     342           0 :     if( aName.isEmpty() )
     343             :     {
     344           0 :         if(bNameED)
     345           0 :             m_pShortNameEdit->SetText(aName);
     346           0 :         m_pInsertBtn->Enable(false);
     347           0 :         return 0;
     348             :     }
     349           0 :     const bool bNotFound = !DoesBlockExist(aName, bNameED ? OUString() : pEdit->GetText());
     350           0 :     if(bNameED)
     351             :     {
     352             :             // did the text get in to the Listbbox in the Edit with a click?
     353           0 :         if(bNotFound)
     354             :         {
     355           0 :             m_pShortNameEdit->SetText( lcl_GetValidShortCut( aName ) );
     356           0 :             EnableShortName();
     357             :         }
     358             :         else
     359             :         {
     360           0 :             m_pShortNameEdit->SetText(pGlossaryHdl->GetGlossaryShortName(aName));
     361           0 :             EnableShortName(!bReadOnly);
     362             :         }
     363           0 :         m_pInsertBtn->Enable(!bNotFound && !bIsDocReadOnly);
     364             :     }
     365             :     else
     366             :     {
     367             :         //ShortNameEdit
     368           0 :         if(!bNotFound)
     369             :         {
     370           0 :             bool bEnable = !bNotFound;
     371           0 :             bEnable &= !bIsDocReadOnly;
     372           0 :             m_pInsertBtn->Enable(bEnable);
     373             :         }
     374             :     }
     375           0 :     return 0;
     376             : }
     377             : 
     378           0 : IMPL_LINK_INLINE_START( SwGlossaryDlg, NameDoubleClick, SvTreeListBox*, pBox )
     379             : {
     380           0 :     SvTreeListEntry* pEntry = pBox->FirstSelected();
     381           0 :     if(pBox->GetParent(pEntry) && !bIsDocReadOnly)
     382           0 :         EndDialog( RET_OK );
     383           0 :     return 0;
     384             : }
     385           0 : IMPL_LINK_INLINE_END( SwGlossaryDlg, NameDoubleClick, SvTreeListBox*, pBox )
     386             : 
     387           0 : IMPL_LINK( SwGlossaryDlg, EnableHdl, Menu *, pMn )
     388             : {
     389           0 :     SvTreeListEntry* pEntry = m_pCategoryBox->FirstSelected();
     390             : 
     391           0 :     const OUString aEditText(m_pNameED->GetText());
     392           0 :     const bool bHasEntry = !aEditText.isEmpty() && !m_pShortNameEdit->GetText().isEmpty();
     393           0 :     const bool bExists = 0 != DoesBlockExist(aEditText, m_pShortNameEdit->GetText());
     394           0 :     const bool bIsGroup = pEntry && !m_pCategoryBox->GetParent(pEntry);
     395           0 :     pMn->EnableItem("new", bSelection && bHasEntry && !bExists);
     396           0 :     pMn->EnableItem("newtext", bSelection && bHasEntry && !bExists);
     397           0 :     pMn->EnableItem("copy", bExists && !bIsGroup);
     398           0 :     pMn->EnableItem("replace", bSelection && bExists && !bIsGroup && !bIsOld );
     399           0 :     pMn->EnableItem("replacetext", bSelection && bExists && !bIsGroup && !bIsOld );
     400           0 :     pMn->EnableItem("edit", bExists && !bIsGroup );
     401           0 :     pMn->EnableItem("rename", bExists && !bIsGroup );
     402           0 :     pMn->EnableItem("delete", bExists && !bIsGroup );
     403           0 :     pMn->EnableItem("macro", bExists && !bIsGroup && !bIsOld &&
     404           0 :                                     !pGlossaryHdl->IsReadOnly() );
     405           0 :     pMn->EnableItem("import", bIsGroup && !bIsOld && !pGlossaryHdl->IsReadOnly() );
     406           0 :     return 1;
     407             : }
     408             : 
     409           0 : IMPL_LINK( SwGlossaryDlg, MenuHdl, Menu *, pMn )
     410             : {
     411           0 :     OString sItemIdent(pMn->GetCurItemIdent());
     412             : 
     413           0 :     if (sItemIdent == "replace")
     414             :     {
     415           0 :         pGlossaryHdl->NewGlossary(m_pNameED->GetText(),
     416           0 :                                   m_pShortNameEdit->GetText(),
     417           0 :                                   false, false);
     418             :     }
     419           0 :     else if (sItemIdent == "replacetext")
     420             :     {
     421           0 :         pGlossaryHdl->NewGlossary(m_pNameED->GetText(),
     422           0 :                                   m_pShortNameEdit->GetText(),
     423           0 :                                   false, true);
     424             :     }
     425           0 :     else if (sItemIdent == "new" || sItemIdent == "newtext")
     426             :     {
     427           0 :         bool bNoAttr = sItemIdent == "newtext";
     428             : 
     429           0 :         const OUString aStr(m_pNameED->GetText());
     430           0 :         const OUString aShortName(m_pShortNameEdit->GetText());
     431           0 :         if(pGlossaryHdl->HasShortName(aShortName))
     432             :         {
     433           0 :             InfoBox(this, SW_RES(MSG_DOUBLE_SHORTNAME)).Execute();
     434           0 :             m_pShortNameEdit->SetSelection(Selection(0, SELECTION_MAX));
     435           0 :             m_pShortNameEdit->GrabFocus();
     436           0 :             return 1;
     437             :         }
     438           0 :         if(pGlossaryHdl->NewGlossary(aStr, aShortName, sal_False, bNoAttr ))
     439             :         {
     440           0 :             SvTreeListEntry* pEntry = m_pCategoryBox->FirstSelected();
     441           0 :             if(m_pCategoryBox->GetParent(pEntry))
     442           0 :                 pEntry = m_pCategoryBox->GetParent(pEntry);
     443             : 
     444           0 :             SvTreeListEntry* pChild = m_pCategoryBox->InsertEntry(aStr, pEntry);
     445           0 :             pChild->SetUserData(new OUString(aShortName));
     446           0 :             m_pNameED->SetText(aStr);
     447           0 :             m_pShortNameEdit->SetText(aShortName);
     448           0 :             NameModify(m_pNameED);       // for toggling the buttons
     449             : 
     450           0 :             if( SfxRequest::HasMacroRecorder( pSh->GetView().GetViewFrame() ) )
     451             :             {
     452           0 :                 SfxRequest aReq(pSh->GetView().GetViewFrame(), FN_NEW_GLOSSARY);
     453           0 :                 OUString sTemp(::GetCurrGlosGroup());
     454             :                 // the zeroth path is not being recorded!
     455           0 :                 if (sTemp.getToken(1, GLOS_DELIM).startsWith("0"))
     456           0 :                     sTemp = sTemp.getToken(0, GLOS_DELIM);
     457           0 :                 aReq.AppendItem(SfxStringItem(FN_NEW_GLOSSARY, sTemp));
     458           0 :                 aReq.AppendItem(SfxStringItem(FN_PARAM_1, aShortName));
     459           0 :                 aReq.AppendItem(SfxStringItem(FN_PARAM_2, aStr));
     460           0 :                 aReq.Done();
     461             :             }
     462           0 :         }
     463             :     }
     464           0 :     else if (sItemIdent == "copy")
     465             :     {
     466           0 :         pGlossaryHdl->CopyToClipboard(*pSh, m_pShortNameEdit->GetText());
     467             :     }
     468           0 :     else if (sItemIdent == "rename")
     469             :     {
     470           0 :         m_pShortNameEdit->SetText(pGlossaryHdl->GetGlossaryShortName(m_pNameED->GetText()));
     471           0 :         SwNewGlosNameDlg* pNewNameDlg = new SwNewGlosNameDlg(this, m_pNameED->GetText(),
     472           0 :                                         m_pShortNameEdit->GetText() );
     473           0 :         if( RET_OK == pNewNameDlg->Execute() &&
     474           0 :             pGlossaryHdl->Rename( m_pShortNameEdit->GetText(),
     475             :                                     pNewNameDlg->GetNewShort(),
     476           0 :                                     pNewNameDlg->GetNewName()))
     477             :         {
     478           0 :             SvTreeListEntry* pEntry = m_pCategoryBox->FirstSelected();
     479             :             SvTreeListEntry* pNewEntry = m_pCategoryBox->InsertEntry(
     480           0 :                     pNewNameDlg->GetNewName(), m_pCategoryBox->GetParent(pEntry));
     481           0 :             pNewEntry->SetUserData(new OUString(pNewNameDlg->GetNewShort()));
     482           0 :             delete reinterpret_cast<OUString*>(pEntry->GetUserData());
     483           0 :             m_pCategoryBox->GetModel()->Remove(pEntry);
     484           0 :             m_pCategoryBox->Select(pNewEntry);
     485           0 :             m_pCategoryBox->MakeVisible(pNewEntry);
     486             :         }
     487           0 :         GrpSelect(m_pCategoryBox);
     488           0 :         delete pNewNameDlg;
     489             :     }
     490           0 :     else if (sItemIdent == "delete")
     491             :     {
     492           0 :         QueryBox aQuery(this, SW_RES(MSG_QUERY_DELETE));
     493           0 :         if(RET_YES == aQuery.Execute())
     494             :         {
     495           0 :             const OUString aShortName(m_pShortNameEdit->GetText());
     496           0 :             const OUString aTitle(m_pNameED->GetText());
     497           0 :             if (!aTitle.isEmpty() && pGlossaryHdl->DelGlossary(aShortName))
     498             :             {
     499           0 :                 SvTreeListEntry* pChild = DoesBlockExist(aTitle, aShortName);
     500             :                 OSL_ENSURE(pChild, "entry not found!");
     501           0 :                 SvTreeListEntry* pParent = m_pCategoryBox->GetParent(pChild);
     502           0 :                 m_pCategoryBox->Select(pParent);
     503             : 
     504           0 :                 m_pCategoryBox->GetModel()->Remove(pChild);
     505           0 :                 m_pNameED->SetText(OUString());
     506           0 :                 NameModify(m_pNameED);
     507           0 :             }
     508           0 :         }
     509             :     }
     510           0 :     else if (sItemIdent == "macro")
     511             :     {
     512           0 :         SfxItemSet aSet( pSh->GetAttrPool(), RES_FRMMACRO, RES_FRMMACRO, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 );
     513             : 
     514           0 :         SvxMacro aStart(aEmptyOUStr, aEmptyOUStr, STARBASIC);
     515           0 :         SvxMacro aEnd(aEmptyOUStr, aEmptyOUStr, STARBASIC);
     516           0 :         pGlossaryHdl->GetMacros(m_pShortNameEdit->GetText(), aStart, aEnd );
     517             : 
     518           0 :         SvxMacroItem aItem(RES_FRMMACRO);
     519           0 :         if( aStart.HasMacro() )
     520           0 :             aItem.SetMacro( SW_EVENT_START_INS_GLOSSARY, aStart );
     521           0 :         if( aEnd.HasMacro() )
     522           0 :             aItem.SetMacro( SW_EVENT_END_INS_GLOSSARY, aEnd );
     523             : 
     524           0 :         aSet.Put( aItem );
     525           0 :         aSet.Put( SwMacroAssignDlg::AddEvents( MACASSGN_AUTOTEXT ) );
     526             : 
     527             :         const SfxPoolItem* pItem;
     528           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     529             :         SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( this, aSet,
     530           0 :             pSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface(), SID_EVENTCONFIG );
     531           0 :         if ( pMacroDlg && pMacroDlg->Execute() == RET_OK &&
     532           0 :             SFX_ITEM_SET == pMacroDlg->GetOutputItemSet()->GetItemState( RES_FRMMACRO, false, &pItem ) )
     533             :         {
     534           0 :             const SvxMacroTableDtor& rTbl = ((SvxMacroItem*)pItem)->GetMacroTable();
     535           0 :             pGlossaryHdl->SetMacros( m_pShortNameEdit->GetText(),
     536             :                                         rTbl.Get( SW_EVENT_START_INS_GLOSSARY ),
     537           0 :                                         rTbl.Get( SW_EVENT_END_INS_GLOSSARY ) );
     538             :         }
     539             : 
     540           0 :         delete pMacroDlg;
     541             :     }
     542           0 :     else if (sItemIdent == "import")
     543             :     {
     544             :         // call the FileOpenDialog do find WinWord - Files with templates
     545           0 :         FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
     546           0 :         uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
     547             : 
     548           0 :         SvtPathOptions aPathOpt;
     549           0 :         xFP->setDisplayDirectory(aPathOpt.GetWorkPath() );
     550             : 
     551           0 :         uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
     552           0 :         SfxFilterMatcher aMatcher( OUString::createFromAscii(SwDocShell::Factory().GetShortName()) );
     553           0 :         SfxFilterMatcherIter aIter( aMatcher );
     554           0 :         const SfxFilter* pFilter = aIter.First();
     555           0 :         while ( pFilter )
     556             :         {
     557           0 :             if( pFilter->GetUserData() == FILTER_WW8 )
     558             :             {
     559           0 :                 xFltMgr->appendFilter( pFilter->GetUIName(),
     560           0 :                             pFilter->GetWildcard().getGlob() );
     561           0 :                 xFltMgr->setCurrentFilter( pFilter->GetUIName() ) ;
     562             :             }
     563             : 
     564           0 :             pFilter = aIter.Next();
     565             :         }
     566             : 
     567           0 :         if( aDlgHelper.Execute() == ERRCODE_NONE )
     568             :         {
     569           0 :             if( pGlossaryHdl->ImportGlossaries( xFP->getFiles().getConstArray()[0] ))
     570           0 :                 Init();
     571             :             else
     572             :             {
     573           0 :                 InfoBox(this, SW_RES( MSG_NO_GLOSSARIES )).Execute();
     574             :             }
     575           0 :         }
     576             :     }
     577             :     else
     578             :     {
     579           0 :         return 0;
     580             :     }
     581           0 :     return 1;
     582             : }
     583             : 
     584             : /*--------------------------------------------------------------------
     585             :      Description:   dialog manage regions
     586             :  --------------------------------------------------------------------*/
     587           0 : IMPL_LINK_NOARG(SwGlossaryDlg, BibHdl)
     588             : {
     589           0 :     SwGlossaries* pGloss = ::GetGlossaries();
     590           0 :     if( pGloss->IsGlosPathErr() )
     591           0 :         pGloss->ShowError();
     592             :     else
     593             :     {
     594             :         //check if at least one glossary path is write enabled
     595           0 :         SvtPathOptions aPathOpt;
     596           0 :         const OUString sGlosPath( aPathOpt.GetAutoTextPath() );
     597           0 :         const sal_Int32 nPaths = comphelper::string::getTokenCount(sGlosPath, ';');
     598           0 :         bool bIsWritable = false;
     599           0 :         for(sal_Int32 nPath = 0; nPath < nPaths; nPath++)
     600             :         {
     601             :             const OUString sPath = URIHelper::SmartRel2Abs(
     602             :                 INetURLObject(), sGlosPath.getToken(nPath, ';'),
     603           0 :                 URIHelper::GetMaybeFileHdl());
     604             :             try
     605             :             {
     606             :                 Content aTestContent( sPath,
     607             :                             uno::Reference< XCommandEnvironment >(),
     608           0 :                             comphelper::getProcessComponentContext() );
     609           0 :                 Any aAny = aTestContent.getPropertyValue( "IsReadOnly" );
     610           0 :                 if(aAny.hasValue())
     611             :                 {
     612           0 :                     bIsWritable = !*(sal_Bool*)aAny.getValue();
     613           0 :                 }
     614             :             }
     615           0 :             catch (const Exception&)
     616             :             {
     617             :             }
     618           0 :             if(bIsWritable)
     619           0 :                 break;
     620           0 :         }
     621           0 :         if(bIsWritable)
     622             :         {
     623             : 
     624           0 :             boost::scoped_ptr<SwGlossaryGroupDlg> pDlg(new SwGlossaryGroupDlg( this, pGloss->GetPathArray(), pGlossaryHdl ));
     625           0 :             if ( RET_OK == pDlg->Execute() )
     626             :             {
     627           0 :                 Init();
     628             :                 //if new groups were created - select one of them
     629           0 :                 const OUString sNewGroup = pDlg->GetCreatedGroupName();
     630           0 :                 SvTreeListEntry* pEntry = m_pCategoryBox->First();
     631           0 :                 while (!sNewGroup.isEmpty() && pEntry)
     632             :                 {
     633           0 :                     if(!m_pCategoryBox->GetParent(pEntry))
     634             :                     {
     635           0 :                         GroupUserData* pGroupData = (GroupUserData*)pEntry->GetUserData();
     636             :                         const OUString sGroup = pGroupData->sGroupName
     637           0 :                             + OUString(GLOS_DELIM)
     638           0 :                             + OUString::number(pGroupData->nPathIdx);
     639           0 :                         if(sGroup == sNewGroup)
     640             :                         {
     641           0 :                             m_pCategoryBox->Select(pEntry);
     642           0 :                             m_pCategoryBox->MakeVisible(pEntry);
     643           0 :                             GrpSelect(m_pCategoryBox);
     644           0 :                             break;
     645           0 :                         }
     646             :                     }
     647           0 :                     pEntry = m_pCategoryBox->Next(pEntry);
     648           0 :                 }
     649             : 
     650           0 :             }
     651             :         }
     652             :         else
     653             :         {
     654           0 :             QueryBox aBox(this, WB_YES_NO, sReadonlyPath);
     655           0 :             if(RET_YES == aBox.Execute())
     656           0 :                 PathHdl(m_pPathBtn);
     657           0 :         }
     658             :     }
     659           0 :     return 0;
     660             : }
     661             : 
     662             : /*------------------------------------------------------------------------
     663             :  Description:   initialisation; from Ctor and after editing regions
     664             : ------------------------------------------------------------------------*/
     665           0 : void SwGlossaryDlg::Init()
     666             : {
     667           0 :     m_pCategoryBox->SetUpdateMode( false );
     668           0 :     m_pCategoryBox->Clear();
     669             :     // display text block regions
     670           0 :     const sal_uInt16 nCnt = pGlossaryHdl->GetGroupCnt();
     671           0 :     SvTreeListEntry* pSelEntry = 0;
     672           0 :     const OUString sSelStr(::GetCurrGlosGroup().getToken(0, GLOS_DELIM));
     673           0 :     const sal_Int32 nSelPath = ::GetCurrGlosGroup().getToken(1, GLOS_DELIM).toInt32();
     674             :     // #i66304# - "My AutoText" comes from mytexts.bau, but should be translated
     675           0 :     const OUString sMyAutoTextEnglish("My AutoText");
     676           0 :     const OUString sMyAutoTextTranslated(SW_RES(STR_MY_AUTOTEXT));
     677           0 :     for(sal_uInt16 nId = 0; nId < nCnt; ++nId )
     678             :     {
     679           0 :         OUString sTitle;
     680           0 :         OUString sGroupName(pGlossaryHdl->GetGroupName(nId, &sTitle));
     681           0 :         if(sGroupName.isEmpty())
     682           0 :             continue;
     683           0 :         if(sTitle.isEmpty())
     684           0 :             sTitle = sGroupName.getToken( 0, GLOS_DELIM );
     685           0 :         if(sTitle == sMyAutoTextEnglish)
     686           0 :             sTitle = sMyAutoTextTranslated;
     687           0 :         SvTreeListEntry* pEntry = m_pCategoryBox->InsertEntry( sTitle );
     688           0 :         const sal_Int32 nPath = sGroupName.getToken( 1, GLOS_DELIM ).toInt32();
     689             : 
     690           0 :         GroupUserData* pData = new GroupUserData;
     691           0 :         pData->sGroupName = sGroupName.getToken(0, GLOS_DELIM);
     692           0 :         pData->nPathIdx = static_cast< sal_uInt16 >(nPath);
     693           0 :         pData->bReadonly = pGlossaryHdl->IsReadOnly(&sGroupName);
     694             : 
     695           0 :         pEntry->SetUserData(pData);
     696           0 :         if(sSelStr == pData->sGroupName && nSelPath == nPath)
     697           0 :             pSelEntry = pEntry;
     698             : 
     699             :         // fill entries for the groups
     700             :         {
     701           0 :             pGlossaryHdl->SetCurGroup(sGroupName, sal_False, sal_True);
     702           0 :             const sal_uInt16 nCount = pGlossaryHdl->GetGlossaryCnt();
     703           0 :             for(sal_uInt16 i = 0; i < nCount; ++i)
     704             :             {
     705             :                 SvTreeListEntry* pChild = m_pCategoryBox->InsertEntry(
     706           0 :                                     pGlossaryHdl->GetGlossaryName(i), pEntry);
     707           0 :                 pChild->SetUserData(new OUString(pGlossaryHdl->GetGlossaryShortName(i)));
     708             :             }
     709             :         }
     710           0 :     }
     711             :         // set current group and display text blocks
     712           0 :     if(!pSelEntry)
     713             :     {
     714             :         //find a non-readonly group
     715           0 :         SvTreeListEntry* pSearch = m_pCategoryBox->First();
     716           0 :         while(pSearch)
     717             :         {
     718           0 :             if(!m_pCategoryBox->GetParent(pSearch))
     719             :             {
     720           0 :                 GroupUserData* pData = (GroupUserData*)pSearch->GetUserData();
     721           0 :                 if(!pData->bReadonly)
     722             :                 {
     723           0 :                     pSelEntry = pSearch;
     724           0 :                     break;
     725             :                 }
     726             :             }
     727           0 :             pSearch = m_pCategoryBox->Next(pSearch);
     728             :         }
     729           0 :         if(!pSelEntry)
     730           0 :             pSelEntry = m_pCategoryBox->GetEntry(0);
     731             :     }
     732           0 :     if(pSelEntry)
     733             :     {
     734           0 :         m_pCategoryBox->Expand(pSelEntry);
     735           0 :         m_pCategoryBox->Select(pSelEntry);
     736           0 :         m_pCategoryBox->MakeVisible(pSelEntry);
     737           0 :         GrpSelect(m_pCategoryBox);
     738             :     }
     739             :     //JP 16.11.99: the SvxTreeListBox has a Bug. The Box dont recalc the
     740             :     //      outputsize, when all entries are insertet. The result is, that
     741             :     //      the Focus/Highlight rectangle is to large and paintet over the
     742             :     //      HScrollbar. -> Fix: call the resize
     743           0 :     m_pCategoryBox->Resize();
     744             : 
     745           0 :     m_pCategoryBox->GetModel()->Resort();
     746           0 :     m_pCategoryBox->SetUpdateMode( true );
     747           0 :     m_pCategoryBox->Update();
     748             : 
     749           0 :     const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
     750           0 :     m_pFileRelCB->Check( rCfg.IsSaveRelFile() );
     751           0 :     m_pFileRelCB->SetClickHdl(LINK(this, SwGlossaryDlg, CheckBoxHdl));
     752           0 :     m_pNetRelCB->Check( rCfg.IsSaveRelNet() );
     753           0 :     m_pNetRelCB->SetClickHdl(LINK(this, SwGlossaryDlg, CheckBoxHdl));
     754           0 :     m_pInsertTipCB->Check( rCfg.IsAutoTextTip() );
     755           0 :     m_pInsertTipCB->SetClickHdl(LINK(this, SwGlossaryDlg, CheckBoxHdl));
     756           0 : }
     757             : 
     758           0 : IMPL_LINK_NOARG_INLINE_START(SwGlossaryDlg, EditHdl)
     759             : {
     760             : // EndDialog must not be called in MenuHdl
     761           0 :     if (m_pEditBtn->GetCurItemIdent() == "edit")
     762             :     {
     763           0 :         SwTextBlocks *pGroup = ::GetGlossaries()->GetGroupDoc (  GetCurrGrpName () );
     764           0 :         sal_Bool bRet = pGlossaryHdl->ConvertToNew ( *pGroup );
     765           0 :         delete pGroup;
     766           0 :         if ( bRet )
     767           0 :             EndDialog(RET_EDIT);
     768             :     }
     769           0 :     return 0;
     770             : }
     771           0 : IMPL_LINK_NOARG_INLINE_END(SwGlossaryDlg, EditHdl)
     772             : 
     773             : /*------------------------------------------------------------------------
     774             :  Description:   KeyInput for ShortName - Edits without Spaces
     775             : ------------------------------------------------------------------------*/
     776           0 : IMPL_LINK( SwNewGlosNameDlg, Modify, Edit *, pBox )
     777             : {
     778           0 :     OUString aName(m_pNewName->GetText());
     779           0 :     SwGlossaryDlg* pDlg = (SwGlossaryDlg*)GetParent();
     780             : 
     781           0 :     if (pBox == m_pNewName)
     782           0 :         m_pNewShort->SetText( lcl_GetValidShortCut( aName ) );
     783             : 
     784           0 :     sal_Bool bEnable = !aName.isEmpty() && !m_pNewShort->GetText().isEmpty() &&
     785           0 :         (!pDlg->DoesBlockExist(aName, m_pNewShort->GetText())
     786           0 :             || aName == m_pOldName->GetText());
     787           0 :     m_pOk->Enable(bEnable);
     788           0 :     return 0;
     789             : }
     790             : 
     791           0 : IMPL_LINK_NOARG(SwNewGlosNameDlg, Rename)
     792             : {
     793           0 :     SwGlossaryDlg* pDlg = (SwGlossaryDlg*)GetParent();
     794           0 :     OUString sNew = GetAppCharClass().uppercase(m_pNewShort->GetText());
     795           0 :     if( pDlg->pGlossaryHdl->HasShortName(m_pNewShort->GetText())
     796           0 :         && sNew != m_pOldShort->GetText() )
     797             :     {
     798           0 :         InfoBox(this, SW_RES(MSG_DOUBLE_SHORTNAME)).Execute();
     799           0 :         m_pNewShort->GrabFocus();
     800             :     }
     801             :     else
     802           0 :         EndDialog(sal_True);
     803           0 :     return 0;
     804             : }
     805             : 
     806           0 : IMPL_LINK( SwGlossaryDlg, CheckBoxHdl, CheckBox *, pBox )
     807             : {
     808           0 :     SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
     809           0 :     bool bCheck = pBox->IsChecked();
     810           0 :     if (pBox == m_pInsertTipCB)
     811           0 :         rCfg.SetAutoTextTip(bCheck);
     812           0 :     else if(pBox == m_pFileRelCB)
     813           0 :         rCfg.SetSaveRelFile(bCheck);
     814             :     else
     815           0 :         rCfg.SetSaveRelNet(bCheck);
     816           0 :     return 0;
     817             : }
     818             : 
     819             : /* --------------------------------------------------
     820             :  * TreeListBox for groups and blocks
     821             :  * --------------------------------------------------*/
     822           0 : SwGlTreeListBox::SwGlTreeListBox(Window* pParent, WinBits nBits)
     823             :     : SvTreeListBox(pParent, nBits)
     824             :     , sReadonly(SW_RESSTR(SW_STR_READONLY)),
     825           0 :     pDragEntry(0)
     826             : {
     827           0 :     SetDragDropMode( SV_DRAGDROP_CTRL_MOVE|SV_DRAGDROP_CTRL_COPY );
     828           0 : }
     829             : 
     830           0 : Size SwGlTreeListBox::GetOptimalSize() const
     831             : {
     832           0 :     return LogicToPixel(Size(212, 84), MapMode(MAP_APPFONT));
     833             : }
     834             : 
     835           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSwGlTreeListBox(Window *pParent, VclBuilder::stringmap &)
     836             : {
     837           0 :     return new SwGlTreeListBox(pParent, WB_BORDER | WB_TABSTOP);
     838             : }
     839             : 
     840           0 : void SwGlTreeListBox::Clear()
     841             : {
     842           0 :     SvTreeListEntry* pEntry = First();
     843           0 :     while(pEntry)
     844             :     {
     845           0 :         if(GetParent(pEntry))
     846           0 :             delete reinterpret_cast<OUString*>(pEntry->GetUserData());
     847             :         else
     848           0 :             delete (GroupUserData*)pEntry->GetUserData();
     849           0 :         pEntry = Next(pEntry);
     850             :     }
     851           0 :     SvTreeListBox::Clear();
     852           0 : }
     853             : 
     854           0 : void SwGlTreeListBox::RequestHelp( const HelpEvent& rHEvt )
     855             : {
     856           0 :     Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
     857           0 :     SvTreeListEntry* pEntry = GetEntry( aPos );
     858             :     // there's only help for groups' names
     859           0 :     if(pEntry)
     860             :     {
     861             :         SvLBoxTab* pTab;
     862           0 :         SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
     863           0 :         if(pItem)
     864             :         {
     865           0 :             aPos = GetEntryPosition( pEntry );
     866           0 :              Size aSize(pItem->GetSize( this, pEntry ));
     867           0 :             aPos.X() = GetTabPos( pEntry, pTab );
     868             : 
     869           0 :             if((aPos.X() + aSize.Width()) > GetSizePixel().Width())
     870           0 :                 aSize.Width() = GetSizePixel().Width() - aPos.X();
     871           0 :             aPos = OutputToScreenPixel(aPos);
     872           0 :              Rectangle aItemRect( aPos, aSize );
     873           0 :             OUString sMsg;
     874           0 :             if(!GetParent(pEntry))
     875             :             {
     876           0 :                 GroupUserData* pData = (GroupUserData*)pEntry->GetUserData();
     877           0 :                 const std::vector<OUString> & rPathArr = ::GetGlossaries()->GetPathArray();
     878           0 :                 if( !rPathArr.empty() )
     879             :                 {
     880           0 :                     INetURLObject aTmp(rPathArr[pData->nPathIdx]
     881           0 :                                        + "/"
     882           0 :                                        + pData->sGroupName
     883           0 :                                        + SwGlossaries::GetExtension());
     884           0 :                     sMsg = aTmp.GetPath();
     885             : 
     886           0 :                     if(pData->bReadonly)
     887             :                     {
     888           0 :                         sMsg += " (" + sReadonly + ")";
     889           0 :                     }
     890             :                 }
     891             :             }
     892             :             else
     893           0 :                 sMsg = *reinterpret_cast<OUString*>(pEntry->GetUserData());
     894             :             Help::ShowQuickHelp( this, aItemRect, sMsg,
     895           0 :                         QUICKHELP_LEFT|QUICKHELP_VCENTER );
     896             :         }
     897             :     }
     898           0 : }
     899             : 
     900           0 : DragDropMode SwGlTreeListBox::NotifyStartDrag(
     901             :                     TransferDataContainer& /*rContainer*/,
     902             :                     SvTreeListEntry* pEntry )
     903             : {
     904             :     DragDropMode  eRet;
     905           0 :     pDragEntry = pEntry;
     906           0 :     if(!GetParent(pEntry))
     907           0 :         eRet = SV_DRAGDROP_NONE;
     908             :     else
     909             :     {
     910           0 :         SwGlossaryDlg* pDlg = (SwGlossaryDlg*)GetParentDialog();
     911           0 :         SvTreeListEntry* pParent = GetParent(pEntry);
     912             : 
     913           0 :         GroupUserData* pGroupData = (GroupUserData*)pParent->GetUserData();
     914             :         OUString sEntry = pGroupData->sGroupName
     915           0 :             + OUString(GLOS_DELIM)
     916           0 :             + OUString::number(pGroupData->nPathIdx);
     917           0 :         sal_Int8 nDragOption = DND_ACTION_COPY;
     918           0 :         eRet = SV_DRAGDROP_CTRL_COPY;
     919           0 :         if(!pDlg->pGlossaryHdl->IsReadOnly(&sEntry))
     920             :         {
     921           0 :             eRet |= SV_DRAGDROP_CTRL_MOVE;
     922           0 :             nDragOption |= DND_ACTION_MOVE;
     923             :         }
     924           0 :         SetDragOptions( nDragOption );
     925             :     }
     926           0 :     return eRet;
     927             : }
     928             : 
     929           0 : bool SwGlTreeListBox::NotifyAcceptDrop( SvTreeListEntry* pEntry)
     930             : {
     931             :     // TODO: Readonly - check still missing!
     932           0 :     SvTreeListEntry* pSrcParent = GetParent(pEntry) ? GetParent(pEntry) : pEntry;
     933             :     SvTreeListEntry* pDestParent =
     934           0 :         GetParent(pDragEntry ) ? GetParent(pDragEntry ) : pDragEntry ;
     935           0 :     return pDestParent != pSrcParent;
     936             : 
     937             : }
     938             : 
     939           0 : TriState SwGlTreeListBox::NotifyMoving(   SvTreeListEntry*  pTarget,
     940             :                                     SvTreeListEntry*  pEntry,
     941             :                                     SvTreeListEntry*& /*rpNewParent*/,
     942             :                                     sal_uLong&        /*rNewChildPos*/
     943             :                                 )
     944             : {
     945           0 :     return NotifyCopyingOrMoving(pTarget, pEntry, true);
     946             : }
     947             : 
     948           0 : TriState SwGlTreeListBox::NotifyCopying(   SvTreeListEntry*  pTarget,
     949             :                                     SvTreeListEntry*  pEntry,
     950             :                                     SvTreeListEntry*& /*rpNewParent*/,
     951             :                                     sal_uLong&        /*rNewChildPos*/
     952             :                                 )
     953             : {
     954           0 :     return NotifyCopyingOrMoving(pTarget, pEntry, false);
     955             : }
     956             : 
     957           0 : TriState SwGlTreeListBox::NotifyCopyingOrMoving(
     958             :     SvTreeListEntry*  pTarget,
     959             :     SvTreeListEntry*  pEntry,
     960             :     bool              bIsMove)
     961             : {
     962           0 :     pDragEntry = 0;
     963             :     // 1. move in different groups?
     964             :     // 2. allowed to write to both groups?
     965           0 :     if(!pTarget) // move to the beginning
     966             :     {
     967           0 :         pTarget = GetEntry(0);
     968             :     }
     969           0 :     SvTreeListEntry* pSrcParent = GetParent(pEntry);
     970             :     SvTreeListEntry* pDestParent =
     971           0 :         GetParent(pTarget) ? GetParent(pTarget) : pTarget;
     972           0 :     sal_Bool bRet = sal_False;
     973           0 :     if(pDestParent != pSrcParent)
     974             :     {
     975           0 :         SwGlossaryDlg* pDlg = (SwGlossaryDlg*)GetParentDialog();
     976           0 :         SwWait aWait( *pDlg->pSh->GetView().GetDocShell(), true );
     977             : 
     978           0 :         GroupUserData* pGroupData = (GroupUserData*)pSrcParent->GetUserData();
     979             :         OUString sSourceGroup = pGroupData->sGroupName
     980           0 :             + OUString(GLOS_DELIM)
     981           0 :             + OUString::number(pGroupData->nPathIdx);
     982             : 
     983           0 :         pDlg->pGlossaryHdl->SetCurGroup(sSourceGroup);
     984           0 :         OUString sTitle(GetEntryText(pEntry));
     985           0 :         OUString sShortName(*reinterpret_cast<OUString*>(pEntry->GetUserData()));
     986             : 
     987           0 :         GroupUserData* pDestData = (GroupUserData*)pDestParent->GetUserData();
     988             :         OUString sDestName = pDestData->sGroupName
     989           0 :             + OUString(GLOS_DELIM)
     990           0 :             + OUString::number(pDestData->nPathIdx);
     991             : 
     992             :         bRet = pDlg->pGlossaryHdl->CopyOrMove( sSourceGroup,  sShortName,
     993           0 :                         sDestName, sTitle, bIsMove );
     994           0 :         if(bRet)
     995             :         {
     996           0 :             SvTreeListEntry* pChild = InsertEntry(sTitle, pDestParent);
     997           0 :             pChild->SetUserData(new OUString(sShortName));
     998           0 :             if (bIsMove)
     999             :             {
    1000           0 :                 GetModel()->Remove(pEntry);
    1001             :             }
    1002           0 :         }
    1003             :     }
    1004           0 :     return TRISTATE_FALSE; // otherwise the entry is being set automatically
    1005             : }
    1006             : 
    1007           0 : OUString SwGlossaryDlg::GetCurrGrpName() const
    1008             : {
    1009           0 :     SvTreeListEntry* pEntry = m_pCategoryBox->FirstSelected();
    1010           0 :     if(pEntry)
    1011             :     {
    1012             :         pEntry =
    1013           0 :             m_pCategoryBox->GetParent(pEntry) ? m_pCategoryBox->GetParent(pEntry) : pEntry;
    1014           0 :         GroupUserData* pGroupData = (GroupUserData*)pEntry->GetUserData();
    1015           0 :         return pGroupData->sGroupName + OUString(GLOS_DELIM) + OUString::number(pGroupData->nPathIdx);
    1016             :     }
    1017           0 :     return OUString();
    1018             : }
    1019             : 
    1020           0 : IMPL_LINK( SwGlossaryDlg, PathHdl, Button *, pBtn )
    1021             : {
    1022           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    1023           0 :     if(pFact)
    1024             :     {
    1025           0 :         boost::scoped_ptr<AbstractSvxMultiPathDialog> pDlg(pFact->CreateSvxPathSelectDialog(pBtn));
    1026             :         OSL_ENSURE(pDlg, "Dialogdiet fail!");
    1027           0 :         SvtPathOptions aPathOpt;
    1028           0 :         const OUString sGlosPath( aPathOpt.GetAutoTextPath() );
    1029           0 :         pDlg->SetPath(sGlosPath);
    1030           0 :         if(RET_OK == pDlg->Execute())
    1031             :         {
    1032           0 :             const OUString sTmp(pDlg->GetPath());
    1033           0 :             if(sTmp != sGlosPath)
    1034             :             {
    1035           0 :                 aPathOpt.SetAutoTextPath( sTmp );
    1036           0 :                 ::GetGlossaries()->UpdateGlosPath( sal_True );
    1037           0 :                 Init();
    1038           0 :             }
    1039           0 :         }
    1040             :     }
    1041           0 :     return 0;
    1042             : }
    1043             : 
    1044           0 : IMPL_LINK_NOARG(SwGlossaryDlg, InsertHdl)
    1045             : {
    1046           0 :     EndDialog(RET_OK);
    1047           0 :     return 0;
    1048             : }
    1049             : 
    1050           0 : void SwGlossaryDlg::ShowPreview()
    1051             : {
    1052             :     //create example
    1053           0 :     if (!pExampleFrame)
    1054             :     {
    1055           0 :         Link aLink(LINK(this, SwGlossaryDlg, PreviewLoadedHdl));
    1056             :         pExampleFrame = new SwOneExampleFrame( *m_pExampleWIN,
    1057           0 :                         EX_SHOW_ONLINE_LAYOUT, &aLink );
    1058             :     }
    1059             : 
    1060           0 :     ShowAutoText(::GetCurrGlosGroup(), m_pShortNameEdit->GetText());
    1061           0 : };
    1062             : 
    1063           0 : IMPL_LINK_NOARG(SwGlossaryDlg, PreviewLoadedHdl)
    1064             : {
    1065           0 :     ResumeShowAutoText();
    1066           0 :     return 0;
    1067             : }
    1068             : 
    1069           0 : void SwGlossaryDlg::ShowAutoText(const OUString& rGroup, const OUString& rShortName)
    1070             : {
    1071           0 :     if(m_pExampleWIN->IsVisible())
    1072             :     {
    1073           0 :         SetResumeData(rGroup, rShortName);
    1074             :         //try to make an Undo()
    1075           0 :         pExampleFrame->ClearDocument( sal_True );
    1076             :     }
    1077           0 : }
    1078             : 
    1079           0 : void SwGlossaryDlg::ResumeShowAutoText()
    1080             : {
    1081           0 :     OUString sGroup;
    1082           0 :     OUString sShortName;
    1083           0 :     if(GetResumeData(sGroup, sShortName) && m_pExampleWIN->IsVisible())
    1084             :     {
    1085           0 :         if(!m_xAutoText.is())
    1086             :         {
    1087             :             //now the AutoText ListBoxes have to be filled
    1088           0 :             m_xAutoText = text::AutoTextContainer::create( comphelper::getProcessComponentContext() );
    1089             :         }
    1090             : 
    1091           0 :         uno::Reference< XTextCursor > & xCrsr = pExampleFrame->GetTextCursor();
    1092           0 :         if(xCrsr.is())
    1093             :         {
    1094           0 :             if (!sShortName.isEmpty())
    1095             :             {
    1096           0 :                 uno::Any aGroup = m_xAutoText->getByName(sGroup);
    1097           0 :                 uno::Reference< XAutoTextGroup >  xGroup;
    1098           0 :                 OUString uShortName(sShortName);
    1099           0 :                 if((aGroup >>= xGroup) && xGroup->hasByName(uShortName))
    1100             :                 {
    1101           0 :                     uno::Any aEntry(xGroup->getByName(uShortName));
    1102           0 :                     uno::Reference< XAutoTextEntry >  xEntry;
    1103           0 :                     aEntry >>= xEntry;
    1104           0 :                     uno::Reference< XTextRange >  xRange(xCrsr, uno::UNO_QUERY);
    1105           0 :                     xEntry->applyTo(xRange);
    1106           0 :                 }
    1107             :             }
    1108             :         }
    1109             :     }
    1110           0 :     ResetResumeData();
    1111           0 : }
    1112             : 
    1113             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10