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: glosbib.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"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
39 #define _SVSTDARR_STRINGS
40 #include <tools/urlobj.hxx>
41 #include <tools/stream.hxx>
42 #ifndef _MSGBOX_HXX //autogen
43 #include <vcl/msgbox.hxx>
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>
60 #include <glosbib.hrc>
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
)),
107 { 2, // Number of Tabs
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
)
143 String sGroup
= pHdl
->GetGroupName(i
, &sTitle
);
146 GlosBibUserData
* pData
= new GlosBibUserData
;
147 pData
->sGroupName
= sGroup
;
148 pData
->sGroupTitle
= sTitle
;
149 String
sTemp(sTitle
);
150 //sGroup.GetToken(0, GLOS_DELIM)
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()
169 pInsertedArr
->DeleteAndDestroy(0, pInsertedArr
->Count());
174 pRemovedArr
->DeleteAndDestroy(0, pRemovedArr
->Count());
179 pRenamedArr
->DeleteAndDestroy(0, pRenamedArr
->Count());
185 /*-----------------09.06.97 13:11-------------------
187 --------------------------------------------------*/
189 void __EXPORT
SwGlossaryGroupDlg::Apply()
191 if(aNewPB
.IsEnabled())
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
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'));
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
);
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();
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
));
287 /*-----------------09.06.97 13:22-------------------
289 --------------------------------------------------*/
290 IMPL_LINK( SwGlossaryGroupDlg
, NewHdl
, Button
*, EMPTYARG
)
292 String
sGroup(aNameED
.GetText());
294 sGroup
+= GLOS_DELIM
;
295 sGroup
+= String::CreateFromInt32(aPathLB
.GetSelectEntryPos());
296 DBG_ASSERT(!pGlosHdl
->FindGroupName(sGroup
), "Gruppe bereits vorhanden!");
298 pInsertedArr
= new SvStrings
;
299 pInsertedArr
->Insert(new String(sGroup
), pInsertedArr
->Count());
300 String
sTemp(aNameED
.GetText());
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();
316 /*-----------------09.06.97 13:22-------------------
318 --------------------------------------------------*/
319 IMPL_LINK( SwGlossaryGroupDlg
, DeleteHdl
, Button
*, pButton
)
321 SvLBoxEntry
* pEntry
= aGroupTLB
.FirstSelected();
324 pButton
->Enable(FALSE
);
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
332 if(pInsertedArr
&& pInsertedArr
->Count())
334 USHORT nCount
= pInsertedArr
->Count();
335 for(USHORT i
= 0; i
< nCount
; ++i
)
337 const String
* pTemp
= (*pInsertedArr
)[i
];
340 pInsertedArr
->Remove(i
);
347 // moeglicherweise sollte es schon umbenannt werden?
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
));
359 pRenamedArr
->Remove(i
);
369 pRemovedArr
= new SvStrings
;
370 String
sGroupEntry(pUserData
->sGroupName
);
372 sGroupEntry
+= pUserData
->sGroupTitle
;
373 pRemovedArr
->Insert(new String(sGroupEntry
), pRemovedArr
->Count());
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
);
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
404 if(pInsertedArr
&& pInsertedArr
->Count())
406 USHORT nCount
= pInsertedArr
->Count();
407 for(USHORT i
= 0; i
< nCount
; ++i
)
409 const String
* pTemp
= (*pInsertedArr
)[i
];
412 pInsertedArr
->Remove(i
);
413 pInsertedArr
->Insert(new String(sNewName
), pInsertedArr
->Count());
422 pRenamedArr
= new SvStrings
;
423 sEntry
+= RENAME_TOKEN_DELIM
;
425 sEntry
+= RENAME_TOKEN_DELIM
;
427 pRenamedArr
->Insert(new String(sEntry
), pRenamedArr
->Count());
429 delete (GlosBibUserData
*)pEntry
->GetUserData();
430 aGroupTLB
.GetModel()->Remove(pEntry
);
431 String
sTemp(aNameED
.GetText());
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();
446 /*-----------------09.06.97 13:42-------------------
448 --------------------------------------------------*/
449 IMPL_LINK( SwGlossaryGroupDlg
, ModifyHdl
, Edit
*, EMPTYARG
)
451 String
sEntry(aNameED
.GetText());
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
)
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
))
485 if( 0xffffffff > nPos
)
488 aGroupTLB
.Select(aGroupTLB
.GetEntry( nPos
));
489 aGroupTLB
.MakeVisible(aGroupTLB
.GetEntry( nPos
));
492 SvLBoxEntry
* pEntry
= aGroupTLB
.FirstSelected();
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
);
510 /*------------------------------------------------------------------------
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
];
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
);
561 SvLBoxItem
* pItem
= GetItem( pEntry
, aPos
.X(), &pTab
);
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
);
573 GlosBibUserData
* pData
= (GlosBibUserData
*)pEntry
->GetUserData();
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
);