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