update dev300-m58
[ooovba.git] / sw / source / ui / misc / glosbib.cxx
blob0b66dde4d5ae8ac238dd3fdff60f8f3296d40f5f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: glosbib.cxx,v $
10 * $Revision: 1.23 $
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"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
35 #endif
39 #define _SVSTDARR_STRINGS
40 #include <tools/urlobj.hxx>
41 #include <tools/stream.hxx>
42 #ifndef _MSGBOX_HXX //autogen
43 #include <vcl/msgbox.hxx>
44 #endif
45 #include <vcl/help.hxx>
46 #include <unotools/transliterationwrapper.hxx>
47 #include <unotools/tempfile.hxx>
49 #include <svtools/svstdarr.hxx>
50 #include <svtools/pathoptions.hxx>
51 #include <swtypes.hxx>
52 #include <glosbib.hxx>
53 #include <gloshdl.hxx>
54 #include <actctrl.hxx>
55 #include <glossary.hxx>
56 #include <glosdoc.hxx>
57 #include <swunohelper.hxx>
59 #ifndef _GLOSBIB_HRC
60 #include <glosbib.hrc>
61 #endif
62 #ifndef _MISC_HRC
63 #include <misc.hrc>
64 #endif
65 #ifndef _HELPID_H
66 #include <helpid.h>
67 #endif
70 #define PATH_CASE_SENSITIVE 0x01
71 #define PATH_READONLY 0x02
73 #define RENAME_TOKEN_DELIM (sal_Unicode)1
75 /*-----------------09.06.97 13:05-------------------
77 --------------------------------------------------*/
78 SwGlossaryGroupDlg::SwGlossaryGroupDlg(Window * pParent,
79 const SvStrings* pPathArr,
80 SwGlossaryHdl *pHdl) :
81 SvxStandardDialog(pParent, SW_RES(DLG_BIB_BASE)),
83 aNameED( this, SW_RES(ED_NAME)),
84 aPathLB( this, SW_RES(LB_PATH)),
85 aGroupTLB( this, SW_RES(TLB_GROUPS)),
87 aOkPB( this, SW_RES(BT_OK)),
88 aCancelPB( this, SW_RES(BT_CANCEL)),
89 aHelpPB( this, SW_RES(BT_HELP)),
90 aNewPB( this, SW_RES(PB_NEW)),
91 aDelPB( this, SW_RES(PB_DELETE)),
92 aRenamePB( this, SW_RES(PB_RENAME)),
93 aBibFT( this, SW_RES(FT_BIB)),
94 aPathFT( this, SW_RES(FT_PATH)),
95 aSelectFT( this, SW_RES(FT_SELECT)),
97 pRemovedArr(0),
98 pInsertedArr(0),
99 pRenamedArr(0),
100 pGlosHdl(pHdl)
102 USHORT i;
104 FreeResource();
106 long nTabs[] =
107 { 2, // Number of Tabs
108 0, 160
111 aGroupTLB.SetHelpId(HID_GLOS_GROUP_TREE);
112 aGroupTLB.SetTabs( &nTabs[0], MAP_APPFONT );
113 aGroupTLB.SetWindowBits(WB_HSCROLL|WB_CLIPCHILDREN|WB_SORT);
114 aGroupTLB.SetSelectHdl(LINK(this, SwGlossaryGroupDlg, SelectHdl));
115 aGroupTLB.GetModel()->SetSortMode(SortAscending);
116 aNewPB.SetClickHdl(LINK(this, SwGlossaryGroupDlg, NewHdl));
117 aDelPB.SetClickHdl(LINK(this, SwGlossaryGroupDlg, DeleteHdl));
118 aNameED.SetModifyHdl(LINK(this, SwGlossaryGroupDlg, ModifyHdl));
119 aPathLB.SetSelectHdl(LINK(this, SwGlossaryGroupDlg, ModifyHdl));
120 aRenamePB.SetClickHdl(LINK(this, SwGlossaryGroupDlg, RenameHdl));
121 for( i = 0; i < pPathArr->Count(); i++)
123 String sPath(*(*pPathArr)[i]);
124 INetURLObject aTempURL(sPath);
125 sPath = aTempURL.GetMainURL(INetURLObject::DECODE_WITH_CHARSET );
126 aPathLB.InsertEntry(sPath);
127 ULONG nCaseReadonly = 0;
128 utl::TempFile aTempFile(&sPath);
129 aTempFile.EnableKillingFile();
130 if(!aTempFile.IsValid())
131 nCaseReadonly |= PATH_READONLY;
132 else if( SWUnoHelper::UCB_IsCaseSensitiveFileName( aTempFile.GetURL()))
133 nCaseReadonly |= PATH_CASE_SENSITIVE;
134 aPathLB.SetEntryData(i, (void*)nCaseReadonly);
136 aPathLB.SelectEntryPos(0);
137 aPathLB.Enable(TRUE);
139 const USHORT nCount = pHdl->GetGroupCnt();
140 for(i = 0; i < nCount; ++i)
142 String sTitle;
143 String sGroup = pHdl->GetGroupName(i, &sTitle);
144 if(!sGroup.Len())
145 continue;
146 GlosBibUserData* pData = new GlosBibUserData;
147 pData->sGroupName = sGroup;
148 pData->sGroupTitle = sTitle;
149 String sTemp(sTitle);
150 //sGroup.GetToken(0, GLOS_DELIM)
151 sTemp += '\t';
152 pData->sPath = aPathLB.GetEntry((USHORT)sGroup.GetToken(1, GLOS_DELIM).ToInt32());
153 sTemp += pData->sPath;
154 SvLBoxEntry* pEntry = aGroupTLB.InsertEntry(sTemp);
155 pEntry->SetUserData(pData);
158 aGroupTLB.GetModel()->Resort();
161 /*-----------------09.06.97 13:05-------------------
163 --------------------------------------------------*/
164 SwGlossaryGroupDlg::~SwGlossaryGroupDlg()
167 if(pInsertedArr)
169 pInsertedArr->DeleteAndDestroy(0, pInsertedArr->Count());
170 delete pInsertedArr;
172 if(pRemovedArr)
174 pRemovedArr->DeleteAndDestroy(0, pRemovedArr->Count());
175 delete pRemovedArr;
177 if(pRenamedArr)
179 pRenamedArr->DeleteAndDestroy(0, pRenamedArr->Count());
180 delete pRenamedArr;
185 /*-----------------09.06.97 13:11-------------------
187 --------------------------------------------------*/
189 void __EXPORT SwGlossaryGroupDlg::Apply()
191 if(aNewPB.IsEnabled())
192 NewHdl(&aNewPB);
194 String aActGroup = SwGlossaryDlg::GetCurrGroup();
196 if(pRemovedArr && pRemovedArr->Count())
198 USHORT nCount = pRemovedArr->Count();
199 for(USHORT i = 0; i < nCount; ++i)
201 const String* pDelEntry = (*pRemovedArr)[i];
202 const String sDelGroup = pDelEntry->GetToken(0, '\t');
203 if( sDelGroup == aActGroup )
205 //soll die aktuelle Gruppe geloescht werden, muss die akt. Gruppe
206 //umgesetzt werden
207 if(aGroupTLB.GetEntryCount())
209 SvLBoxEntry* pFirst = aGroupTLB.First();
210 GlosBibUserData* pUserData = (GlosBibUserData*)pFirst->GetUserData();
211 pGlosHdl->SetCurGroup(pUserData->sGroupName);
214 String sMsg(SW_RES(STR_QUERY_DELETE_GROUP1));
215 String sTitle(pDelEntry->GetToken(1, '\t'));
216 if(sTitle.Len())
217 sMsg += sTitle;
218 else
219 sDelGroup.GetToken(1, GLOS_DELIM);
220 sMsg += SW_RESSTR(STR_QUERY_DELETE_GROUP2);
221 QueryBox aQuery(this->GetParent(), WB_YES_NO|WB_DEF_NO, sMsg );
222 if(RET_YES == aQuery.Execute())
223 pGlosHdl->DelGroup( sDelGroup );
227 //erst umbenennen, falls es schon eins gab
228 if(pRenamedArr && pRenamedArr->Count())
230 USHORT nCount = pRenamedArr->Count();
231 for(USHORT i = 0; i < nCount; ++i)
233 String * pEntry = (*pRenamedArr)[i];
234 xub_StrLen nStrSttPos = 0;
235 String sOld( pEntry->GetToken(0, RENAME_TOKEN_DELIM, nStrSttPos ) );
236 String sNew( pEntry->GetToken(0, RENAME_TOKEN_DELIM, nStrSttPos) );
237 String sTitle( pEntry->GetToken(0, RENAME_TOKEN_DELIM, nStrSttPos) );
238 pGlosHdl->RenameGroup(sOld, sNew, sTitle);
239 if(!i)
240 sCreatedGroup = sNew;
243 if(pInsertedArr && pInsertedArr->Count())
245 USHORT nCount = pInsertedArr->Count();
246 for(USHORT i = 0; i < nCount; ++i)
248 String sNewGroup = *(*pInsertedArr)[i];
249 String sNewTitle = sNewGroup.GetToken(0, GLOS_DELIM);
250 if( *(*pInsertedArr)[i] != aActGroup )
252 pGlosHdl->NewGroup(sNewGroup, sNewTitle);
253 if(!sCreatedGroup.Len())
254 sCreatedGroup = sNewGroup;
259 /*-----------------09.06.97 13:12-------------------
261 --------------------------------------------------*/
262 IMPL_LINK( SwGlossaryGroupDlg, SelectHdl, SvTabListBox*, EMPTYARG )
264 aNewPB.Enable(FALSE);
265 SvLBoxEntry* pFirstEntry = aGroupTLB.FirstSelected();
266 if(pFirstEntry)
268 GlosBibUserData* pUserData = (GlosBibUserData*)pFirstEntry->GetUserData();
269 String sEntry(pUserData->sGroupName);
270 String sName(aNameED.GetText());
271 BOOL bExists = FALSE;
272 ULONG nPos = aGroupTLB.GetEntryPos(sName, 0);
273 if( 0xffffffff > nPos)
275 SvLBoxEntry* pEntry = aGroupTLB.GetEntry(nPos);
276 GlosBibUserData* pFoundData = (GlosBibUserData*)pEntry->GetUserData();
277 String sGroup = pFoundData->sGroupName;
278 bExists = sGroup == sEntry;
281 aRenamePB.Enable(!bExists && sName.Len());
282 aDelPB.Enable(IsDeleteAllowed(sEntry));
284 return 0;
287 /*-----------------09.06.97 13:22-------------------
289 --------------------------------------------------*/
290 IMPL_LINK( SwGlossaryGroupDlg, NewHdl, Button*, EMPTYARG )
292 String sGroup(aNameED.GetText());
293 // sGroup.ToLower();
294 sGroup += GLOS_DELIM;
295 sGroup += String::CreateFromInt32(aPathLB.GetSelectEntryPos());
296 DBG_ASSERT(!pGlosHdl->FindGroupName(sGroup), "Gruppe bereits vorhanden!");
297 if(!pInsertedArr)
298 pInsertedArr = new SvStrings;
299 pInsertedArr->Insert(new String(sGroup), pInsertedArr->Count());
300 String sTemp(aNameED.GetText());
301 // sTemp.ToLower();
302 sTemp += '\t';
303 sTemp += aPathLB.GetSelectEntry();
304 SvLBoxEntry* pEntry = aGroupTLB.InsertEntry(sTemp);
305 GlosBibUserData* pData = new GlosBibUserData;
306 pData->sPath = aPathLB.GetSelectEntry();
307 pData->sGroupName = sGroup;
308 pData->sGroupTitle = aNameED.GetText();
309 pEntry->SetUserData(pData);
310 aGroupTLB.Select(pEntry);
311 aGroupTLB.MakeVisible(pEntry);
312 aGroupTLB.GetModel()->Resort();
314 return 0;
316 /*-----------------09.06.97 13:22-------------------
318 --------------------------------------------------*/
319 IMPL_LINK( SwGlossaryGroupDlg, DeleteHdl, Button*, pButton )
321 SvLBoxEntry* pEntry = aGroupTLB.FirstSelected();
322 if(!pEntry)
324 pButton->Enable(FALSE);
325 return 0;
327 GlosBibUserData* pUserData = (GlosBibUserData*)pEntry->GetUserData();
328 String sEntry(pUserData->sGroupName);
329 // befindet sich der zu loeschende Name schon unter den
330 // den neuen - dann weg damit
331 BOOL bDelete = TRUE;
332 if(pInsertedArr && pInsertedArr->Count())
334 USHORT nCount = pInsertedArr->Count();
335 for(USHORT i = 0; i < nCount; ++i)
337 const String* pTemp = (*pInsertedArr)[i];
338 if(*pTemp == sEntry)
340 pInsertedArr->Remove(i);
341 bDelete = FALSE;
342 break;
347 // moeglicherweise sollte es schon umbenannt werden?
348 if(bDelete)
350 if(pRenamedArr && pRenamedArr->Count())
352 USHORT nCount = pRenamedArr->Count();
353 for(USHORT i = 0; i < nCount; ++i)
355 const String* pTemp = (*pRenamedArr)[i];
356 String sTemp( pTemp->GetToken(0, RENAME_TOKEN_DELIM ));
357 if(sTemp == sEntry)
359 pRenamedArr->Remove(i);
360 bDelete = FALSE;
361 break;
366 if(bDelete)
368 if(!pRemovedArr)
369 pRemovedArr = new SvStrings;
370 String sGroupEntry(pUserData->sGroupName);
371 sGroupEntry += '\t';
372 sGroupEntry += pUserData->sGroupTitle;
373 pRemovedArr->Insert(new String(sGroupEntry), pRemovedArr->Count());
375 delete pUserData;
376 aGroupTLB.GetModel()->Remove(pEntry);
377 if(!aGroupTLB.First())
378 pButton->Enable(FALSE);
379 //the content must be deleted - otherwise the new handler would be called in Apply()
380 aNameED.SetText(aEmptyStr);
381 return 0;
384 /* -----------------23.11.98 12:26-------------------
386 * --------------------------------------------------*/
387 IMPL_LINK( SwGlossaryGroupDlg, RenameHdl, Button *, EMPTYARG )
389 SvLBoxEntry* pEntry = aGroupTLB.FirstSelected();
390 GlosBibUserData* pUserData = (GlosBibUserData*)pEntry->GetUserData();
391 String sEntryText(aGroupTLB.GetEntryText(pEntry));
392 String sEntry(pUserData->sGroupName);
394 String sNewName(aNameED.GetText());
395 String sNewTitle(sNewName);
397 sNewName += GLOS_DELIM;
398 sNewName += String::CreateFromInt32(aPathLB.GetSelectEntryPos());
399 DBG_ASSERT(!pGlosHdl->FindGroupName(sNewName), "Gruppe bereits vorhanden!");
401 // befindet sich der umzubenennende Name unter den
402 // den neuen - dann austauschen
403 BOOL bDone = FALSE;
404 if(pInsertedArr && pInsertedArr->Count())
406 USHORT nCount = pInsertedArr->Count();
407 for(USHORT i = 0; i < nCount; ++i)
409 const String* pTemp = (*pInsertedArr)[i];
410 if(*pTemp == sEntry)
412 pInsertedArr->Remove(i);
413 pInsertedArr->Insert(new String(sNewName), pInsertedArr->Count());
414 bDone = TRUE;
415 break;
419 if(!bDone)
421 if(!pRenamedArr)
422 pRenamedArr = new SvStrings;
423 sEntry += RENAME_TOKEN_DELIM;
424 sEntry += sNewName;
425 sEntry += RENAME_TOKEN_DELIM;
426 sEntry += sNewTitle;
427 pRenamedArr->Insert(new String(sEntry), pRenamedArr->Count());
429 delete (GlosBibUserData*)pEntry->GetUserData();
430 aGroupTLB.GetModel()->Remove(pEntry);
431 String sTemp(aNameED.GetText());
432 // sTemp.ToLower();
433 sTemp += '\t';
434 sTemp += aPathLB.GetSelectEntry();
435 pEntry = aGroupTLB.InsertEntry(sTemp);
436 GlosBibUserData* pData = new GlosBibUserData;
437 pData->sPath = aPathLB.GetSelectEntry();
438 pData->sGroupName = sNewName;
439 pData->sGroupTitle = sNewTitle;
440 pEntry->SetUserData(pData);
441 aGroupTLB.Select(pEntry);
442 aGroupTLB.MakeVisible(pEntry);
443 aGroupTLB.GetModel()->Resort();
444 return 0;
446 /*-----------------09.06.97 13:42-------------------
448 --------------------------------------------------*/
449 IMPL_LINK( SwGlossaryGroupDlg, ModifyHdl, Edit*, EMPTYARG )
451 String sEntry(aNameED.GetText());
452 // sEntry.ToLower();
453 BOOL bEnableNew = TRUE;
454 BOOL bEnableDel = FALSE;
455 ULONG nCaseReadonly =
456 (ULONG)aPathLB.GetEntryData(aPathLB.GetSelectEntryPos());
457 BOOL bDirReadonly = 0 != (nCaseReadonly&PATH_READONLY);
459 if(!sEntry.Len() || bDirReadonly)
460 bEnableNew = FALSE;
461 else if(sEntry.Len())
463 ULONG nPos = 0xffffffff;
466 nPos = aGroupTLB.GetEntryPos(sEntry, 0);
467 //ist es nicht case sensitive muss man selbst suchen
468 if( 0xffffffff == nPos)
470 const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
471 for(USHORT i = 0; i < aGroupTLB.GetEntryCount(); i++)
473 String sTemp = aGroupTLB.GetEntryText( i, 0 );
474 nCaseReadonly = (ULONG)aPathLB.GetEntryData(
475 aPathLB.GetEntryPos(aGroupTLB.GetEntryText(i,1)));
476 BOOL bCase = 0 != (nCaseReadonly & PATH_CASE_SENSITIVE);
478 if( !bCase && rSCmp.isEqual( sTemp, sEntry ))
480 nPos = i;
481 break;
485 if( 0xffffffff > nPos)
487 bEnableNew = FALSE;
488 aGroupTLB.Select(aGroupTLB.GetEntry( nPos ));
489 aGroupTLB.MakeVisible(aGroupTLB.GetEntry( nPos ));
492 SvLBoxEntry* pEntry = aGroupTLB.FirstSelected();
493 if(pEntry)
495 GlosBibUserData* pUserData = (GlosBibUserData*)pEntry->GetUserData();
496 bEnableDel = IsDeleteAllowed(pUserData->sGroupName);
498 // String sGroup = aGroupTLB.GetEntryText(pEntry, 0);
499 // sGroup += GLOS_DELIM;
500 // sGroup += String::CreateFromInt32(aPathLB.GetEntryPos(aGroupTLB.GetEntryText(pEntry, 1)));
501 // bEnableDel = IsDeleteAllowed(sGroup);
504 aDelPB.Enable(bEnableDel);
505 aNewPB.Enable(bEnableNew);
506 aRenamePB.Enable(bEnableNew && pEntry);
507 return 0;
510 /*------------------------------------------------------------------------
511 Beschreibung:
512 ------------------------------------------------------------------------*/
514 BOOL SwGlossaryGroupDlg::IsDeleteAllowed(const String &rGroup)
516 BOOL bDel = (!pGlosHdl->IsReadOnly(&rGroup));
518 // OM: befindet sich der Name unter den den neuen Bereichsnamen,
519 // dann ist er auch loeschbar! Bei noch nicht existenten Bereichsnamen
520 // liefert ReadOnly naemlich TRUE.
522 if(pInsertedArr && pInsertedArr->Count())
524 USHORT nCount = pInsertedArr->Count();
525 for(USHORT i = 0; i < nCount; ++i)
527 const String* pTemp = (*pInsertedArr)[i];
528 if(*pTemp == rGroup)
530 bDel = TRUE;
531 break;
536 return bDel;
539 /*-----------------18.07.97 19:06-------------------
541 --------------------------------------------------*/
542 void FEdit::KeyInput( const KeyEvent& rKEvent )
544 KeyCode aCode = rKEvent.GetKeyCode();
545 if( KEYGROUP_CURSOR == aCode.GetGroup() ||
546 ( KEYGROUP_MISC == aCode.GetGroup() &&
547 KEY_DELETE >= aCode.GetCode() ) ||
548 SVT_SEARCHPATH_DELIMITER != rKEvent.GetCharCode() )
549 Edit::KeyInput( rKEvent );
551 /* -----------------------------08.02.00 15:07--------------------------------
553 ---------------------------------------------------------------------------*/
554 void SwGlossaryGroupTLB::RequestHelp( const HelpEvent& rHEvt )
556 Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
557 SvLBoxEntry* pEntry = GetEntry( aPos );
558 if(pEntry)
560 SvLBoxTab* pTab;
561 SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
562 if(pItem)
564 aPos = GetEntryPosition( pEntry );
565 Size aSize(pItem->GetSize( this, pEntry ));
566 aPos.X() = GetTabPos( pEntry, pTab );
568 if((aPos.X() + aSize.Width()) > GetSizePixel().Width())
569 aSize.Width() = GetSizePixel().Width() - aPos.X();
570 aPos = OutputToScreenPixel(aPos);
571 Rectangle aItemRect( aPos, aSize );
572 String sMsg;
573 GlosBibUserData* pData = (GlosBibUserData*)pEntry->GetUserData();
574 sMsg = pData->sPath;
575 sMsg += INET_PATH_TOKEN;
576 sMsg += pData->sGroupName.GetToken(0, GLOS_DELIM);
577 sMsg += SwGlossaries::GetExtension();
579 Help::ShowQuickHelp( this, aItemRect, sMsg,
580 QUICKHELP_LEFT|QUICKHELP_VCENTER );