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