1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gloslst.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #define _SVSTDARR_STRINGSDTOR
37 #define _SVSTDARR_STRINGSISORTDTOR
38 #define _SVSTDARR_STRINGS
39 #include <svtools/svstdarr.hxx>
40 #include <tools/urlobj.hxx>
41 #include <vcl/dialog.hxx>
42 #include <vcl/msgbox.hxx>
43 #ifndef _SV_BUTTON_HXX //autogen
44 #include <vcl/button.hxx>
46 #ifndef _FIXED_HXX //autogen
47 #include <vcl/fixed.hxx>
49 #include <vcl/lstbox.hxx>
50 #ifndef SVTOOLS_FSTATHELPER_HXX
51 #include <svtools/fstathelper.hxx>
53 #include <svtools/pathoptions.hxx>
54 #include <unotools/transliterationwrapper.hxx>
55 #include <swtypes.hxx>
56 #include <swmodule.hxx>
57 #include <shellio.hxx>
59 #include <glosdoc.hxx>
60 #include <gloslst.hxx>
61 #include <swunohelper.hxx>
67 #include <gloslst.hrc>
71 #define STRING_DELIM (char)0x0A
72 #define GLOS_TIMEOUT 30000 // alle 30 s updaten
73 #define FIND_MAX_GLOS 20
83 typedef TripleString
* TripleStringPtr
;
84 SV_DECL_PTRARR_DEL( TripleStrings
, TripleStringPtr
, 0, 4 )
85 SV_IMPL_PTRARR( TripleStrings
, TripleStringPtr
)
87 class SwGlossDecideDlg
: public ModalDialog
95 DECL_LINK(DoubleClickHdl
, ListBox
*);
96 DECL_LINK(SelectHdl
, ListBox
*);
99 SwGlossDecideDlg(Window
* pParent
);
100 ListBox
& GetListBox() {return aListLB
;}
103 /*-----------------21.01.97 13.25-------------------
105 --------------------------------------------------*/
107 SwGlossDecideDlg::SwGlossDecideDlg(Window
* pParent
) :
108 ModalDialog(pParent
, SW_RES(DLG_GLOSSARY_DECIDE_DLG
)),
109 aOk(this, SW_RES(PB_OK
)),
110 aCancel(this, SW_RES(PB_CANCEL
)),
111 aHelp(this, SW_RES(PB_HELP
)),
112 aListLB(this, SW_RES(LB_LIST
)),
113 aFL(this, SW_RES(FL_GLOSS
))
116 aListLB
.SetDoubleClickHdl(LINK(this, SwGlossDecideDlg
, DoubleClickHdl
));
117 aListLB
.SetSelectHdl(LINK(this, SwGlossDecideDlg
, SelectHdl
));
120 /*-----------------21.01.97 13.25-------------------
122 --------------------------------------------------*/
124 IMPL_LINK(SwGlossDecideDlg
, DoubleClickHdl
, ListBox
*, EMPTYARG
)
129 /*-----------------21.01.97 13.29-------------------
131 --------------------------------------------------*/
133 IMPL_LINK(SwGlossDecideDlg
, SelectHdl
, ListBox
*, EMPTYARG
)
135 aOk
.Enable(LISTBOX_ENTRY_NOTFOUND
!= aListLB
.GetSelectEntryPos());
139 /********************************************************************
141 ********************************************************************/
144 SwGlossaryList::SwGlossaryList() :
147 SvtPathOptions aPathOpt
;
148 sPath
= aPathOpt
.GetAutoTextPath();
149 SetTimeout(GLOS_TIMEOUT
);
152 /********************************************************************
154 ********************************************************************/
157 SwGlossaryList::~SwGlossaryList()
162 /********************************************************************
163 * Wenn der GroupName bereits bekannt ist, dann wird nur
164 * rShortName gefuellt, sonst wird rGroupName ebenfals gesetzt und
165 * bei Bedarf nach der richtigen Gruppe gefragt
166 ********************************************************************/
169 BOOL
SwGlossaryList::GetShortName(const String
& rLongName
,
170 String
& rShortName
, String
& rGroupName
)
175 TripleStrings aTripleStrings
;
177 USHORT nCount
= aGroupArr
.Count();
179 for(USHORT i
= 0; i
< nCount
; i
++ )
181 AutoTextGroup
* pGroup
= aGroupArr
.GetObject(i
);
182 if(!rGroupName
.Len() || rGroupName
== pGroup
->sName
)
183 for(USHORT j
= 0; j
< pGroup
->nCount
; j
++)
185 String sLong
= pGroup
->sLongNames
.GetToken(j
, STRING_DELIM
);
186 if((rLongName
== sLong
))
188 TripleString
* pTriple
= new TripleString
;
189 pTriple
->sGroup
= pGroup
->sName
;
190 pTriple
->sBlock
= sLong
;
191 pTriple
->sShort
= pGroup
->sShortNames
.GetToken(j
, STRING_DELIM
);
192 aTripleStrings
.Insert(pTriple
, nFound
++);
198 nCount
= aTripleStrings
.Count();
201 TripleString
* pTriple
= aTripleStrings
[0];
202 rShortName
= pTriple
->sShort
;
203 rGroupName
= pTriple
->sGroup
;
208 SwGlossDecideDlg
aDlg(0);
209 String sTitle
= aDlg
.GetText();
211 sTitle
+= aTripleStrings
[0]->sBlock
;
212 aDlg
.SetText(sTitle
);
214 ListBox
& rLB
= aDlg
.GetListBox();
215 for(USHORT i
= 0; i
< nCount
; i
++ )
216 rLB
.InsertEntry(aTripleStrings
[i
]->sGroup
.GetToken(0, GLOS_DELIM
));
218 rLB
.SelectEntryPos(0);
219 if(RET_OK
== aDlg
.Execute() &&
220 LISTBOX_ENTRY_NOTFOUND
!= rLB
.GetSelectEntryPos())
222 TripleString
* pTriple
= aTripleStrings
[rLB
.GetSelectEntryPos()];
223 rShortName
= pTriple
->sShort
;
224 rGroupName
= pTriple
->sGroup
;
233 /********************************************************************
235 ********************************************************************/
238 USHORT
SwGlossaryList::GetGroupCount()
242 return aGroupArr
.Count();
245 /********************************************************************
247 ********************************************************************/
250 String
SwGlossaryList::GetGroupName(USHORT nPos
, BOOL bNoPath
, String
* pTitle
)
252 DBG_ASSERT(aGroupArr
.Count() > nPos
, "Gruppe nicht vorhanden");
253 String
sRet(aEmptyStr
);
254 if(nPos
< aGroupArr
.Count())
256 AutoTextGroup
* pGroup
= aGroupArr
.GetObject(nPos
);
257 sRet
= pGroup
->sName
;
259 sRet
= sRet
.GetToken(0, GLOS_DELIM
);
261 *pTitle
= pGroup
->sTitle
;
267 /********************************************************************
269 ********************************************************************/
272 USHORT
SwGlossaryList::GetBlockCount(USHORT nGroup
)
274 DBG_ASSERT(aGroupArr
.Count() > nGroup
, "Gruppe nicht vorhanden");
275 if(nGroup
< aGroupArr
.Count())
277 AutoTextGroup
* pGroup
= aGroupArr
.GetObject(nGroup
);
278 return pGroup
->nCount
;
283 /********************************************************************
285 ********************************************************************/
288 String
SwGlossaryList::GetBlockName(USHORT nGroup
, USHORT nBlock
, String
& rShortName
)
290 DBG_ASSERT(aGroupArr
.Count() > nGroup
, "Gruppe nicht vorhanden");
291 if(nGroup
< aGroupArr
.Count())
293 AutoTextGroup
* pGroup
= aGroupArr
.GetObject(nGroup
);
294 rShortName
= pGroup
->sShortNames
.GetToken(nBlock
, STRING_DELIM
);
295 return pGroup
->sLongNames
.GetToken(nBlock
, STRING_DELIM
);
300 /********************************************************************
302 ********************************************************************/
305 void SwGlossaryList::Update()
310 SvtPathOptions aPathOpt
;
311 String
sTemp( aPathOpt
.GetAutoTextPath() );
318 SwGlossaries
* pGlossaries
= ::GetGlossaries();
319 const SvStrings
* pPathArr
= pGlossaries
->GetPathArray();
320 String
sExt( SwGlossaries::GetExtension() );
323 USHORT nGroupCount
= pGlossaries
->GetGroupCnt();
324 for(USHORT i
= 0; i
< nGroupCount
; i
++)
326 String sGrpName
= pGlossaries
->GetGroupName(i
);
327 USHORT nPath
= (USHORT
)sGrpName
.GetToken(1, GLOS_DELIM
).ToInt32();
328 if(nPath
< pPathArr
->Count())
330 AutoTextGroup
* pGroup
= new AutoTextGroup
;
331 pGroup
->sName
= sGrpName
;
333 FillGroup(pGroup
, pGlossaries
);
334 String sName
= *(*pPathArr
)[nPath
];
335 sName
+= INET_PATH_TOKEN
;
336 sName
+= pGroup
->sName
.GetToken(0, GLOS_DELIM
);
339 FStatHelper::GetModifiedDateTimeOfFile( sName
,
340 &pGroup
->aDateModified
,
341 &pGroup
->aDateModified
);
343 aGroupArr
.Insert( pGroup
, i
);
350 for(USHORT nPath
= 0; nPath
< pPathArr
->Count(); nPath
++)
352 SvStringsDtor aFoundGroupNames
;
353 SvStrings
aFiles( 16, 16 );
354 SvPtrarr
aDateTimeArr( 16, 16 );
356 SWUnoHelper::UCB_GetFileListOfFolder( *(*pPathArr
)[nPath
], aFiles
,
357 &sExt
, &aDateTimeArr
);
358 for( USHORT nFiles
= 0, nFEnd
= aFiles
.Count();
359 nFiles
< nFEnd
; ++nFiles
)
361 String
* pTitle
= aFiles
[ nFiles
];
362 ::DateTime
* pDT
= (::DateTime
*) aDateTimeArr
[ nFiles
];
364 String
sName( pTitle
->Copy( 0, pTitle
->Len() - sExt
.Len() ));
366 aFoundGroupNames
.Insert( new String(sName
),
367 aFoundGroupNames
.Count());
369 sName
+= String::CreateFromInt32( nPath
);
370 AutoTextGroup
* pFound
= FindGroup( sName
);
373 pFound
= new AutoTextGroup
;
374 pFound
->sName
= sName
;
375 FillGroup( pFound
, pGlossaries
);
376 pFound
->aDateModified
= *pDT
;
378 aGroupArr
.Insert(pFound
, aGroupArr
.Count());
380 else if( pFound
->aDateModified
< *pDT
)
382 FillGroup(pFound
, pGlossaries
);
383 pFound
->aDateModified
= *pDT
;
386 // don't need any more these pointers
391 USHORT nArrCount
= aGroupArr
.Count();
392 for( USHORT i
= nArrCount
; i
; --i
)
394 // evtl. geloeschte Gruppen entfernen
395 AutoTextGroup
* pGroup
= aGroupArr
.GetObject(i
- 1);
396 USHORT nGroupPath
= (USHORT
)pGroup
->sName
.GetToken( 1,
397 GLOS_DELIM
).ToInt32();
398 // nur die Gruppen werden geprueft, die fuer den
399 // aktuellen Teilpfad registriert sind
400 if(nGroupPath
== nPath
)
403 String sCompareGroup
= pGroup
->sName
.GetToken(0, GLOS_DELIM
);
404 for( USHORT j
= 0; j
< aFoundGroupNames
.Count() && !bFound
; ++j
)
406 bFound
= sCompareGroup
== *aFoundGroupNames
[j
];
410 aGroupArr
.Remove(i
- 1);
419 /********************************************************************
421 ********************************************************************/
424 void SwGlossaryList::Timeout()
426 // nur, wenn eine SwView den Fokus hat, wird automatisch upgedated
427 if(::GetActiveView())
431 /********************************************************************
433 ********************************************************************/
436 AutoTextGroup
* SwGlossaryList::FindGroup(const String
& rGroupName
)
438 for(USHORT i
= 0; i
< aGroupArr
.Count(); i
++)
440 AutoTextGroup
* pRet
= aGroupArr
.GetObject(i
);
441 if(pRet
->sName
== rGroupName
)
447 /********************************************************************
449 ********************************************************************/
452 void SwGlossaryList::FillGroup(AutoTextGroup
* pGroup
, SwGlossaries
* pGlossaries
)
454 SwTextBlocks
* pBlock
= pGlossaries
->GetGroupDoc(pGroup
->sName
);
455 pGroup
->nCount
= pBlock
? pBlock
->GetCount() : 0;
456 pGroup
->sLongNames
= pGroup
->sShortNames
= aEmptyStr
;
458 pGroup
->sTitle
= pBlock
->GetName();
460 for(USHORT j
= 0; j
< pGroup
->nCount
; j
++)
462 pGroup
->sLongNames
+= pBlock
->GetLongName(j
);
463 pGroup
->sLongNames
+= STRING_DELIM
;
464 pGroup
->sShortNames
+= pBlock
->GetShortName(j
);
465 pGroup
->sShortNames
+= STRING_DELIM
;
467 pGlossaries
->PutGroupDoc(pBlock
);
470 /********************************************************************
471 Alle (nicht mehr als FIND_MAX_GLOS) gefunden Bausteine mit
472 passendem Anfang zurueckgeben
473 ********************************************************************/
475 BOOL
SwGlossaryList::HasLongName(const String
& rBegin
, SvStringsISortDtor
* pLongNames
)
480 USHORT nCount
= aGroupArr
.Count();
481 USHORT nBeginLen
= rBegin
.Len();
482 const ::utl::TransliterationWrapper
& rSCmp
= GetAppCmpStrIgnore();
484 for(USHORT i
= 0; i
< nCount
; i
++ )
486 AutoTextGroup
* pGroup
= aGroupArr
.GetObject(i
);
487 for(USHORT j
= 0; j
< pGroup
->nCount
; j
++)
489 String sBlock
= pGroup
->sLongNames
.GetToken(j
, STRING_DELIM
);
490 if( rSCmp
.isEqual( sBlock
.Copy(0, nBeginLen
), rBegin
) &&
491 nBeginLen
+ 1 < sBlock
.Len())
493 String
* pBlock
= new String(sBlock
);
494 pLongNames
->Insert(pBlock
);
496 if(FIND_MAX_GLOS
== nFound
)
504 /********************************************************************
506 ********************************************************************/
507 void SwGlossaryList::ClearGroups()
509 USHORT nCount
= aGroupArr
.Count();
510 for( USHORT i
= 0; i
< nCount
; ++i
)
511 delete aGroupArr
.GetObject( i
);
513 aGroupArr
.Remove( 0, nCount
);