Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "swuiidxmrk.hxx"
21 : #include <hintids.hxx>
22 : #include <helpid.h>
23 : #include <comphelper/processfactory.hxx>
24 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 : #include <com/sun/star/beans/PropertyValue.hpp>
26 : #include <com/sun/star/beans/XPropertySet.hpp>
27 : #include <com/sun/star/frame/Bibliography.hpp>
28 : #include <com/sun/star/i18n/TransliterationModules.hpp>
29 : #include <com/sun/star/i18n/IndexEntrySupplier.hpp>
30 : #include <com/sun/star/util/SearchOptions.hpp>
31 : #include <com/sun/star/util/SearchFlags.hpp>
32 : #include <svl/stritem.hxx>
33 : #include <vcl/layout.hxx>
34 : #include <vcl/msgbox.hxx>
35 : #include <sfx2/dispatch.hxx>
36 : #include <svl/eitem.hxx>
37 : #include <unotools/textsearch.hxx>
38 : #include <editeng/scripttypeitem.hxx>
39 : #include <svl/itemset.hxx>
40 : #include <editeng/langitem.hxx>
41 : #include "editeng/unolingu.hxx"
42 : #include <swtypes.hxx>
43 : #include <idxmrk.hxx>
44 : #include <txttxmrk.hxx>
45 : #include <wrtsh.hxx>
46 : #include <view.hxx>
47 : #include <multmrk.hxx>
48 : #include <swundo.hxx> // for Undo-Ids
49 : #include <cmdid.h>
50 : #include <app.hrc>
51 : #include <index.hrc>
52 : #include <idxmrk.hrc>
53 : #include <swmodule.hxx>
54 : #include <fldmgr.hxx>
55 : #include <fldbas.hxx>
56 : #include <utlui.hrc>
57 : #include <swcont.hxx>
58 : #include <svl/cjkoptions.hxx>
59 : #include <ndtxt.hxx>
60 : #include <breakit.hxx>
61 : #include <SwRewriter.hxx>
62 :
63 : #include <unomid.h>
64 :
65 :
66 : #define POS_CONTENT 0
67 : #define POS_INDEX 1
68 :
69 : static sal_uInt16 nTypePos = 1; // TOX_INDEX as standard
70 : static sal_uInt16 nKey1Pos = USHRT_MAX;
71 :
72 : static sal_uInt16 nKey2Pos = USHRT_MAX;
73 :
74 : using namespace com::sun::star;
75 : using namespace com::sun::star::i18n;
76 : using namespace com::sun::star::lang;
77 : using namespace com::sun::star::util;
78 : using namespace ::comphelper;
79 : using namespace ::com::sun::star;
80 :
81 : /*--------------------------------------------------------------------
82 : Description: dialog to insert a directory selection
83 : --------------------------------------------------------------------*/
84 0 : SwIndexMarkPane::SwIndexMarkPane(Dialog &rDialog, sal_Bool bNewDlg,
85 : SwWrtShell& rWrtShell)
86 : : m_rDialog(rDialog)
87 : , bNewMark(bNewDlg)
88 : , bSelected(sal_False)
89 : , bPhoneticED0_ChangedByUser(sal_False)
90 : , bPhoneticED1_ChangedByUser(sal_False)
91 : , bPhoneticED2_ChangedByUser(sal_False)
92 : , nLangForPhoneticReading(LANGUAGE_CHINESE_SIMPLIFIED)
93 : , bIsPhoneticReadingEnabled(sal_False)
94 : , xExtendedIndexEntrySupplier(NULL)
95 : , pTOXMgr(0)
96 0 : , pSh(&rWrtShell)
97 : {
98 0 : rDialog.get(m_pFrame, "frame");
99 0 : rDialog.get(m_pTypeFT, "typeft");
100 0 : rDialog.get(m_pTypeDCB, "typecb");
101 0 : rDialog.get(m_pNewBT, "new");
102 0 : m_pNewBT->SetAccessibleRelationMemberOf(m_pFrame->get_label_widget());
103 0 : rDialog.get(m_pEntryED, "entryed");
104 0 : rDialog.get(m_pPhoneticFT0, "phonetic0ft");
105 0 : rDialog.get(m_pPhoneticED0, "phonetic0ed");
106 0 : rDialog.get(m_pKey1FT, "key1ft");
107 0 : rDialog.get(m_pKey1DCB, "key1cb");
108 0 : rDialog.get(m_pPhoneticFT1, "phonetic1ft");
109 0 : rDialog.get(m_pPhoneticED1, "phonetic1ed");
110 0 : rDialog.get(m_pKey2FT, "key2ft");
111 0 : rDialog.get(m_pKey2DCB, "key2cb");
112 0 : rDialog.get(m_pPhoneticFT2, "phonetic2ft");
113 0 : rDialog.get(m_pPhoneticED2, "phonetic2ed");
114 0 : rDialog.get(m_pLevelFT, "levelft");
115 0 : rDialog.get(m_pLevelNF, "levelnf");
116 0 : rDialog.get(m_pMainEntryCB, "mainentrycb");
117 0 : rDialog.get(m_pApplyToAllCB, "applytoallcb");
118 0 : rDialog.get(m_pSearchCaseSensitiveCB, "searchcasesensitivecb");
119 0 : rDialog.get(m_pSearchCaseWordOnlyCB, "searchcasewordonlycb");
120 0 : rDialog.get(m_pCloseBT, "close");
121 0 : rDialog.get(m_pDelBT, "delete");
122 0 : rDialog.get(m_pPrevSameBT, "first");
123 0 : rDialog.get(m_pNextSameBT, "last");
124 0 : rDialog.get(m_pPrevBT, "previous");
125 0 : rDialog.get(m_pNextBT, "next");
126 :
127 0 : if (SvtCJKOptions().IsCJKFontEnabled())
128 : {
129 0 : uno::Reference< uno::XComponentContext > xContext = getProcessComponentContext();
130 :
131 0 : xExtendedIndexEntrySupplier = i18n::IndexEntrySupplier::create(xContext);
132 :
133 0 : m_pPhoneticFT0->Show();
134 0 : m_pPhoneticED0->Show();
135 0 : m_pPhoneticFT1->Show();
136 0 : m_pPhoneticED1->Show();
137 0 : m_pPhoneticFT2->Show();
138 0 : m_pPhoneticED2->Show();
139 : }
140 :
141 0 : rDialog.SetText( SW_RESSTR( bNewMark ? STR_IDXMRK_INSERT : STR_IDXMRK_EDIT));
142 :
143 0 : m_pDelBT->SetClickHdl(LINK(this,SwIndexMarkPane, DelHdl));
144 0 : m_pPrevBT->SetClickHdl(LINK(this,SwIndexMarkPane, PrevHdl));
145 0 : m_pPrevSameBT->SetClickHdl(LINK(this,SwIndexMarkPane, PrevSameHdl));
146 0 : m_pNextBT->SetClickHdl(LINK(this,SwIndexMarkPane, NextHdl));
147 0 : m_pNextSameBT->SetClickHdl(LINK(this,SwIndexMarkPane, NextSameHdl));
148 0 : m_pTypeDCB->SetSelectHdl(LINK(this,SwIndexMarkPane, ModifyHdl));
149 0 : m_pKey1DCB->SetModifyHdl(LINK(this,SwIndexMarkPane, KeyDCBModifyHdl));
150 0 : m_pKey2DCB->SetModifyHdl(LINK(this,SwIndexMarkPane, KeyDCBModifyHdl));
151 0 : m_pCloseBT->SetClickHdl(LINK(this,SwIndexMarkPane, CloseHdl));
152 0 : m_pEntryED->SetModifyHdl(LINK(this,SwIndexMarkPane, ModifyHdl));
153 0 : m_pNewBT->SetClickHdl(LINK(this, SwIndexMarkPane, NewUserIdxHdl));
154 0 : m_pApplyToAllCB->SetClickHdl(LINK(this, SwIndexMarkPane, SearchTypeHdl));
155 0 : m_pPhoneticED0->SetModifyHdl(LINK(this,SwIndexMarkPane, PhoneticEDModifyHdl));
156 0 : m_pPhoneticED1->SetModifyHdl(LINK(this,SwIndexMarkPane, PhoneticEDModifyHdl));
157 0 : m_pPhoneticED2->SetModifyHdl(LINK(this,SwIndexMarkPane, PhoneticEDModifyHdl));
158 :
159 0 : if(bNewMark)
160 : {
161 0 : m_pDelBT->Hide();
162 0 : rDialog.get(m_pOKBT, "insert");
163 : }
164 : else
165 : {
166 0 : m_pNewBT->Hide();
167 0 : rDialog.get(m_pOKBT, "ok");
168 : }
169 0 : m_pOKBT->Show();
170 0 : m_pOKBT->SetClickHdl(LINK(this, SwIndexMarkPane, InsertHdl));
171 :
172 0 : m_pEntryED->GrabFocus();
173 0 : }
174 :
175 : /*--------------------------------------------------------------------
176 : Description: Newly initialise controls with the new selection
177 : --------------------------------------------------------------------*/
178 0 : void SwIndexMarkPane::InitControls()
179 : {
180 : OSL_ENSURE(pSh && pTOXMgr, "no shell?");
181 : // contents index
182 0 : const SwTOXType* pType = pTOXMgr->GetTOXType(TOX_CONTENT, 0);
183 : OSL_ENSURE(pType, "Kein Verzeichnistyp !!");
184 0 : String sTmpTypeSelection;
185 0 : if(m_pTypeDCB->GetSelectEntryCount())
186 0 : sTmpTypeSelection = m_pTypeDCB->GetSelectEntry();
187 0 : m_pTypeDCB->Clear();
188 0 : m_pTypeDCB->InsertEntry(pType->GetTypeName());
189 :
190 : // keyword index
191 0 : pType = pTOXMgr->GetTOXType(TOX_INDEX, 0);
192 : OSL_ENSURE(pType, "Kein Verzeichnistyp !!");
193 0 : m_pTypeDCB->InsertEntry(pType->GetTypeName());
194 :
195 : // user index
196 0 : sal_uInt16 nCount = pSh->GetTOXTypeCount(TOX_USER);
197 : sal_uInt16 i;
198 0 : for( i = 0; i < nCount; ++i )
199 0 : m_pTypeDCB->InsertEntry( pSh->GetTOXType(TOX_USER, i)->GetTypeName() );
200 :
201 : // read keywords primary
202 0 : std::vector<String> aArr;
203 0 : nCount = pSh->GetTOIKeys( TOI_PRIMARY, aArr );
204 0 : std::sort(aArr.begin(), aArr.end());
205 0 : for (std::vector<String>::iterator it = aArr.begin(); it != aArr.end(); ++it)
206 0 : m_pKey1DCB->InsertEntry( *it );
207 :
208 : // read keywords secondary
209 0 : nCount = pSh->GetTOIKeys( TOI_SECONDARY, aArr );
210 0 : std::sort(aArr.begin(), aArr.end());
211 0 : for (std::vector<String>::iterator it = aArr.begin(); it != aArr.end(); ++it)
212 0 : m_pKey2DCB->InsertEntry( *it );
213 :
214 0 : UpdateLanguageDependenciesForPhoneticReading();
215 :
216 : // current entry
217 0 : const SwTOXMark* pMark = pTOXMgr->GetCurTOXMark();
218 0 : if( pMark && !bNewMark)
219 : {
220 : // Controls-Handling
221 :
222 : // only if there are more than one
223 : // if equal it lands at the same entry
224 0 : pSh->SttCrsrMove();
225 :
226 : const SwTOXMark* pMoveMark;
227 0 : bool bShow = false;
228 :
229 0 : pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_PRV );
230 0 : if( pMoveMark != pMark )
231 0 : pSh->GotoTOXMark( *pMoveMark, TOX_NXT ), bShow = true;
232 0 : m_pPrevBT->Enable( pMoveMark != pMark );
233 0 : pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_NXT );
234 0 : if( pMoveMark != pMark )
235 0 : pSh->GotoTOXMark( *pMoveMark, TOX_PRV ), bShow = true;
236 0 : m_pNextBT->Enable( pMoveMark != pMark );
237 0 : if( bShow )
238 : {
239 0 : m_pPrevBT->Show();
240 0 : m_pNextBT->Show();
241 0 : bShow = false;
242 : }
243 :
244 0 : pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_SAME_PRV );
245 0 : if( pMoveMark != pMark )
246 0 : pSh->GotoTOXMark( *pMoveMark, TOX_SAME_NXT ), bShow = true;
247 0 : m_pPrevSameBT->Enable( pMoveMark != pMark );
248 0 : pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_SAME_NXT );
249 0 : if( pMoveMark != pMark )
250 0 : pSh->GotoTOXMark( *pMoveMark, TOX_SAME_PRV ), bShow = true;
251 0 : m_pNextSameBT->Enable( pMoveMark != pMark );
252 0 : if( bShow )
253 : {
254 0 : m_pNextSameBT->Show();
255 0 : m_pPrevSameBT->Show();
256 : }
257 0 : pSh->EndCrsrMove();
258 :
259 0 : m_pTypeFT->Show();
260 :
261 0 : m_pTypeDCB->Enable(sal_False);
262 0 : m_pTypeFT->Enable(sal_False);
263 :
264 0 : UpdateDialog();
265 : }
266 : else
267 : { // display current selection (first element) ????
268 0 : sal_uInt16 nCnt = pSh->GetCrsrCnt();
269 0 : if (nCnt < 2)
270 : {
271 0 : bSelected = !pSh->HasSelection();
272 0 : aOrgStr = pSh->GetView().GetSelectionTextParam(sal_True, sal_False);
273 0 : m_pEntryED->SetText(aOrgStr);
274 :
275 : //to include all equal entries may only be allowed in the body and even there
276 : //only when a simple selection exists
277 0 : const sal_uInt16 nFrmType = pSh->GetFrmType(0,sal_True);
278 0 : m_pApplyToAllCB->Show();
279 0 : m_pSearchCaseSensitiveCB->Show();
280 0 : m_pSearchCaseWordOnlyCB->Show();
281 0 : m_pApplyToAllCB->Enable(0 != aOrgStr.Len() &&
282 0 : 0 == (nFrmType & ( FRMTYPE_HEADER | FRMTYPE_FOOTER | FRMTYPE_FLY_ANY )));
283 0 : SearchTypeHdl(m_pApplyToAllCB);
284 : }
285 :
286 : // index type is default
287 0 : if( sTmpTypeSelection.Len() &&
288 0 : LISTBOX_ENTRY_NOTFOUND != m_pTypeDCB->GetEntryPos( sTmpTypeSelection ) )
289 0 : m_pTypeDCB->SelectEntry(sTmpTypeSelection);
290 : else
291 0 : m_pTypeDCB->SelectEntry(m_pTypeDCB->GetEntry(nTypePos));
292 0 : ModifyHdl(m_pTypeDCB);
293 0 : }
294 0 : }
295 :
296 0 : void SwIndexMarkPane::UpdateLanguageDependenciesForPhoneticReading()
297 : {
298 : //no phonetic reading if no global cjk support
299 0 : if( !xExtendedIndexEntrySupplier.is() )
300 : {
301 0 : bIsPhoneticReadingEnabled = sal_False;
302 0 : return;
303 : }
304 0 : bIsPhoneticReadingEnabled = sal_True;
305 :
306 : //get the current language
307 0 : if(!bNewMark) //if dialog is opened to iterate existing marks
308 : {
309 : OSL_ENSURE(pTOXMgr, "need TOXMgr");
310 0 : if(!pTOXMgr)
311 0 : return;
312 0 : SwTOXMark* pMark = pTOXMgr->GetCurTOXMark();
313 : OSL_ENSURE(pMark, "need current SwTOXMark");
314 0 : if(!pMark)
315 0 : return;
316 0 : SwTxtTOXMark* pTxtTOXMark = pMark->GetTxtTOXMark();
317 : OSL_ENSURE(pTxtTOXMark, "need current SwTxtTOXMark");
318 0 : if(!pTxtTOXMark)
319 0 : return;
320 0 : const SwTxtNode* pTxtNode = pTxtTOXMark->GetpTxtNd();
321 : OSL_ENSURE(pTxtNode, "need current SwTxtNode");
322 0 : if(!pTxtNode)
323 0 : return;
324 0 : xub_StrLen nTextIndex = *pTxtTOXMark->GetStart();
325 0 : nLangForPhoneticReading = pTxtNode->GetLang( nTextIndex );
326 : }
327 : else //if dialog is opened to create a new mark
328 : {
329 0 : sal_uInt16 nScriptType = pSh->GetScriptType();
330 : sal_uInt16 nWhich;
331 0 : switch(nScriptType)
332 : {
333 0 : case SCRIPTTYPE_ASIAN: nWhich = RES_CHRATR_CJK_LANGUAGE; break;
334 0 : case SCRIPTTYPE_COMPLEX:nWhich = RES_CHRATR_CTL_LANGUAGE; break;
335 0 : default:nWhich = RES_CHRATR_LANGUAGE; break;
336 : }
337 0 : SfxItemSet aLangSet(pSh->GetAttrPool(), nWhich, nWhich);
338 0 : pSh->GetCurAttr(aLangSet);
339 0 : nLangForPhoneticReading = ((const SvxLanguageItem&)aLangSet.Get(nWhich)).GetLanguage();
340 : }
341 :
342 : }
343 :
344 0 : String SwIndexMarkPane::GetDefaultPhoneticReading( const String& rText )
345 : {
346 0 : if( !bIsPhoneticReadingEnabled )
347 0 : return aEmptyStr;
348 :
349 0 : return xExtendedIndexEntrySupplier->getPhoneticCandidate(rText, LanguageTag( nLangForPhoneticReading ).getLocale());
350 : }
351 :
352 : /* --------------------------------------------------
353 : Change the content of m_pEntryED if text is selected
354 : --------------------------------------------------*/
355 0 : void SwIndexMarkPane::Activate()
356 : {
357 : // display current selection (first element) ????
358 0 : if(bNewMark)
359 : {
360 0 : sal_uInt16 nCnt = pSh->GetCrsrCnt();
361 0 : if (nCnt < 2)
362 : {
363 0 : bSelected = !pSh->HasSelection();
364 0 : aOrgStr = pSh->GetView().GetSelectionTextParam(sal_True, sal_False);
365 0 : m_pEntryED->SetText(aOrgStr);
366 :
367 : //to include all equal entries may only be allowed in the body and even there
368 : //only when a simple selection exists
369 0 : const sal_uInt16 nFrmType = pSh->GetFrmType(0,sal_True);
370 0 : m_pApplyToAllCB->Show();
371 0 : m_pSearchCaseSensitiveCB->Show();
372 0 : m_pSearchCaseWordOnlyCB->Show();
373 0 : m_pApplyToAllCB->Enable(0 != aOrgStr.Len() &&
374 0 : 0 == (nFrmType & ( FRMTYPE_HEADER | FRMTYPE_FOOTER | FRMTYPE_FLY_ANY )));
375 0 : SearchTypeHdl(m_pApplyToAllCB);
376 : }
377 0 : ModifyHdl(m_pTypeDCB);
378 : }
379 0 : }
380 :
381 : /*--------------------------------------------------------------------
382 : Description: evaluate Ok-Button
383 : --------------------------------------------------------------------*/
384 0 : void SwIndexMarkPane::Apply()
385 : {
386 0 : InsertUpdate();
387 0 : if(bSelected)
388 0 : pSh->ResetSelect(0, sal_False);
389 0 : }
390 :
391 : /*--------------------------------------------------------------------
392 : Description: apply changes
393 : --------------------------------------------------------------------*/
394 0 : void SwIndexMarkPane::InsertUpdate()
395 : {
396 0 : pSh->StartUndo(bDel ? UNDO_INDEX_ENTRY_DELETE : UNDO_INDEX_ENTRY_INSERT);
397 0 : pSh->StartAllAction();
398 :
399 0 : SwRewriter aRewriter;
400 :
401 0 : if( bNewMark )
402 : {
403 0 : InsertMark();
404 :
405 0 : if ( pTOXMgr->GetCurTOXMark())
406 0 : aRewriter.AddRule(UndoArg1, pTOXMgr->GetCurTOXMark()->GetText());
407 : }
408 0 : else if( !pSh->HasReadonlySel() )
409 : {
410 0 : if ( pTOXMgr->GetCurTOXMark())
411 : aRewriter.AddRule(UndoArg1,
412 0 : pTOXMgr->GetCurTOXMark()->GetText());
413 :
414 0 : if( bDel )
415 0 : pTOXMgr->DeleteTOXMark();
416 0 : else if( pTOXMgr->GetCurTOXMark() )
417 0 : UpdateMark();
418 : }
419 :
420 0 : pSh->EndAllAction();
421 0 : pSh->EndUndo(bDel ? UNDO_INDEX_ENTRY_DELETE : UNDO_INDEX_ENTRY_INSERT);
422 :
423 0 : if((nTypePos = m_pTypeDCB->GetEntryPos(m_pTypeDCB->GetSelectEntry())) == LISTBOX_ENTRY_NOTFOUND)
424 0 : nTypePos = 0;
425 :
426 0 : nKey1Pos = m_pKey1DCB->GetEntryPos(m_pKey1DCB->GetText());
427 0 : nKey2Pos = m_pKey2DCB->GetEntryPos(m_pKey2DCB->GetText());
428 0 : }
429 :
430 : /*--------------------------------------------------------------------
431 : Description: insert mark
432 : --------------------------------------------------------------------*/
433 0 : static void lcl_SelectSameStrings(SwWrtShell& rSh, sal_Bool bWordOnly, sal_Bool bCaseSensitive)
434 : {
435 0 : rSh.Push();
436 :
437 : SearchOptions aSearchOpt(
438 : SearchAlgorithms_ABSOLUTE,
439 : ( bWordOnly ? SearchFlags::NORM_WORD_ONLY : 0 ),
440 : rSh.GetSelTxt(), OUString(),
441 0 : GetAppLanguageTag().getLocale(),
442 : 0, 0, 0,
443 : (bCaseSensitive
444 : ? 0
445 0 : : TransliterationModules_IGNORE_CASE) );
446 :
447 0 : rSh.ClearMark();
448 : sal_Bool bCancel;
449 :
450 : //todo/mba: assuming that notes should not be searched
451 0 : sal_Bool bSearchInNotes = sal_False;
452 : rSh.Find( aSearchOpt, bSearchInNotes, DOCPOS_START, DOCPOS_END, bCancel,
453 0 : (FindRanges)(FND_IN_SELALL|FND_IN_BODYONLY), sal_False );
454 0 : }
455 :
456 :
457 0 : void SwIndexMarkPane::InsertMark()
458 : {
459 0 : sal_uInt16 nPos = m_pTypeDCB->GetEntryPos(m_pTypeDCB->GetSelectEntry());
460 : TOXTypes eType = nPos == POS_CONTENT ? TOX_CONTENT :
461 0 : nPos == POS_INDEX ? TOX_INDEX : TOX_USER;
462 :
463 0 : SwTOXMarkDescription aDesc(eType);
464 :
465 0 : sal_uInt16 nLevel = (sal_uInt16)m_pLevelNF->Denormalize(m_pLevelNF->GetValue());
466 0 : switch(nPos)
467 : {
468 0 : case POS_CONTENT : break;
469 : case POS_INDEX: // keyword index mark
470 : {
471 0 : UpdateKeyBoxes();
472 0 : String aPrim(m_pKey1DCB->GetText());
473 0 : String aSec(m_pKey2DCB->GetText());
474 0 : aDesc.SetPrimKey(aPrim);
475 0 : aDesc.SetSecKey(aSec);
476 0 : aDesc.SetMainEntry(m_pMainEntryCB->IsChecked());
477 0 : aDesc.SetPhoneticReadingOfAltStr(m_pPhoneticED0->GetText());
478 0 : aDesc.SetPhoneticReadingOfPrimKey(m_pPhoneticED1->GetText());
479 0 : aDesc.SetPhoneticReadingOfSecKey(m_pPhoneticED2->GetText());
480 : }
481 0 : break;
482 : default: // Userdefined index mark
483 : {
484 0 : String aName(m_pTypeDCB->GetSelectEntry());
485 0 : aDesc.SetTOUName(aName);
486 : }
487 : }
488 0 : if (OUString(aOrgStr) != m_pEntryED->GetText())
489 0 : aDesc.SetAltStr(m_pEntryED->GetText());
490 0 : sal_Bool bApplyAll = m_pApplyToAllCB->IsChecked();
491 0 : sal_Bool bWordOnly = m_pSearchCaseWordOnlyCB->IsChecked();
492 0 : sal_Bool bCaseSensitive = m_pSearchCaseSensitiveCB->IsChecked();
493 :
494 0 : pSh->StartAllAction();
495 : // all equal strings have to be selected here so that the
496 : // entry is apllied to all equal strings
497 0 : if(bApplyAll)
498 : {
499 0 : lcl_SelectSameStrings(*pSh, bWordOnly, bCaseSensitive);
500 : }
501 0 : aDesc.SetLevel(nLevel);
502 0 : SwTOXMgr aMgr(pSh);
503 0 : aMgr.InsertTOXMark(aDesc);
504 0 : if(bApplyAll)
505 0 : pSh->Pop(sal_False);
506 :
507 0 : pSh->EndAllAction();
508 0 : }
509 :
510 : /*--------------------------------------------------------------------
511 : Description: update mark
512 : --------------------------------------------------------------------*/
513 0 : void SwIndexMarkPane::UpdateMark()
514 : {
515 0 : String aAltText(m_pEntryED->GetText());
516 0 : String* pAltText = OUString(aOrgStr) != m_pEntryED->GetText() ? &aAltText : 0;
517 : //empty alternative texts are not allowed
518 0 : if(pAltText && !pAltText->Len())
519 0 : return;
520 :
521 0 : UpdateKeyBoxes();
522 :
523 0 : sal_uInt16 nPos = m_pTypeDCB->GetEntryPos(m_pTypeDCB->GetSelectEntry());
524 0 : TOXTypes eType = TOX_USER;
525 0 : if(POS_CONTENT == nPos)
526 0 : eType = TOX_CONTENT;
527 0 : else if(POS_INDEX == nPos)
528 0 : eType = TOX_INDEX;
529 :
530 0 : SwTOXMarkDescription aDesc(eType);
531 0 : aDesc.SetLevel( static_cast< int >(m_pLevelNF->GetValue()) );
532 0 : if(pAltText)
533 0 : aDesc.SetAltStr(*pAltText);
534 :
535 0 : String aPrim(m_pKey1DCB->GetText());
536 0 : if(aPrim.Len())
537 0 : aDesc.SetPrimKey(aPrim);
538 0 : String aSec(m_pKey2DCB->GetText());
539 0 : if(aSec.Len())
540 0 : aDesc.SetSecKey(aSec);
541 :
542 0 : if(eType == TOX_INDEX)
543 : {
544 0 : aDesc.SetPhoneticReadingOfAltStr(m_pPhoneticED0->GetText());
545 0 : aDesc.SetPhoneticReadingOfPrimKey(m_pPhoneticED1->GetText());
546 0 : aDesc.SetPhoneticReadingOfSecKey(m_pPhoneticED2->GetText());
547 : }
548 0 : aDesc.SetMainEntry(m_pMainEntryCB->IsVisible() && m_pMainEntryCB->IsChecked());
549 0 : pTOXMgr->UpdateTOXMark(aDesc);
550 : }
551 :
552 : /*--------------------------------------------------------------------
553 : Description: insert new keys
554 : --------------------------------------------------------------------*/
555 0 : void SwIndexMarkPane::UpdateKeyBoxes()
556 : {
557 0 : String aKey(m_pKey1DCB->GetText());
558 0 : sal_uInt16 nPos = m_pKey1DCB->GetEntryPos(aKey);
559 :
560 0 : if(nPos == LISTBOX_ENTRY_NOTFOUND && aKey.Len() > 0)
561 : { // create new key
562 0 : m_pKey1DCB->InsertEntry(aKey);
563 : }
564 :
565 0 : aKey = m_pKey2DCB->GetText();
566 0 : nPos = m_pKey2DCB->GetEntryPos(aKey);
567 :
568 0 : if(nPos == LISTBOX_ENTRY_NOTFOUND && aKey.Len() > 0)
569 : { // create new key
570 0 : m_pKey2DCB->InsertEntry(aKey);
571 0 : }
572 0 : }
573 :
574 0 : class SwNewUserIdxDlg : public ModalDialog
575 : {
576 : OKButton* m_pOKPB;
577 : Edit* m_pNameED;
578 :
579 : SwIndexMarkPane* m_pDlg;
580 :
581 : DECL_LINK( ModifyHdl, Edit*);
582 :
583 : public:
584 0 : SwNewUserIdxDlg(SwIndexMarkPane* pPane)
585 0 : : ModalDialog(&(pPane->GetDialog()), "NewUserIndexDialog",
586 : "modules/swriter/ui/newuserindexdialog.ui")
587 0 : , m_pDlg(pPane)
588 : {
589 0 : get(m_pOKPB, "ok");
590 0 : get(m_pNameED, "entry");
591 0 : m_pNameED->SetModifyHdl(LINK(this, SwNewUserIdxDlg, ModifyHdl));
592 0 : m_pOKPB->Enable(sal_False);
593 0 : m_pNameED->GrabFocus();
594 0 : }
595 :
596 : virtual void Apply();
597 0 : String GetName(){return m_pNameED->GetText();}
598 : };
599 0 : void SwNewUserIdxDlg::Apply()
600 : {
601 0 : }
602 :
603 0 : IMPL_LINK( SwNewUserIdxDlg, ModifyHdl, Edit*, pEdit)
604 : {
605 0 : m_pOKPB->Enable(!pEdit->GetText().isEmpty() && !m_pDlg->IsTOXType(pEdit->GetText()));
606 0 : return 0;
607 : }
608 :
609 0 : IMPL_LINK_NOARG(SwIndexMarkPane, NewUserIdxHdl)
610 : {
611 0 : SwNewUserIdxDlg* pDlg = new SwNewUserIdxDlg(this);
612 0 : if(RET_OK == pDlg->Execute())
613 : {
614 0 : String sNewName(pDlg->GetName());
615 0 : m_pTypeDCB->InsertEntry(sNewName);
616 0 : m_pTypeDCB->SelectEntry(sNewName);
617 : }
618 0 : delete pDlg;
619 0 : return 0;
620 : }
621 :
622 0 : IMPL_LINK( SwIndexMarkPane, SearchTypeHdl, CheckBox*, pBox)
623 : {
624 0 : sal_Bool bEnable = pBox->IsChecked() && pBox->IsEnabled();
625 0 : m_pSearchCaseWordOnlyCB->Enable(bEnable);
626 0 : m_pSearchCaseSensitiveCB->Enable(bEnable);
627 0 : return 0;
628 : }
629 :
630 0 : IMPL_LINK( SwIndexMarkPane, InsertHdl, Button *, pButton )
631 : {
632 0 : Apply();
633 : //close the dialog if only one entry is available
634 0 : if(!bNewMark && !m_pPrevBT->IsVisible() && !m_pNextBT->IsVisible())
635 0 : CloseHdl(pButton);
636 0 : return 0;
637 : }
638 :
639 0 : IMPL_LINK_NOARG(SwIndexMarkPane, CloseHdl)
640 : {
641 0 : if(bNewMark)
642 : {
643 0 : sal_uInt16 nSlot = FN_INSERT_IDX_ENTRY_DLG;
644 : SfxViewFrame::Current()->GetDispatcher()->Execute(nSlot,
645 0 : SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
646 : }
647 : else
648 : {
649 0 : m_rDialog.EndDialog(RET_CANCEL);
650 : }
651 0 : return 0;
652 : }
653 :
654 : /*--------------------------------------------------------------------
655 : Description: select index type only when inserting
656 : --------------------------------------------------------------------*/
657 0 : IMPL_LINK( SwIndexMarkPane, ModifyHdl, ListBox *, pBox )
658 : {
659 0 : if (m_pTypeDCB == pBox)
660 : {
661 : // set index type
662 0 : sal_uInt16 nPos = m_pTypeDCB->GetEntryPos(m_pTypeDCB->GetSelectEntry());
663 0 : sal_Bool bLevelEnable = sal_False,
664 0 : bKeyEnable = sal_False,
665 0 : bSetKey2 = sal_False,
666 0 : bKey2Enable = sal_False,
667 0 : bEntryHasText = sal_False,
668 0 : bKey1HasText = sal_False,
669 0 : bKey2HasText = sal_False;
670 0 : if(nPos == POS_INDEX)
671 : {
672 0 : if(!m_pEntryED->GetText().isEmpty())
673 0 : bEntryHasText = sal_True;
674 0 : m_pPhoneticED0->SetText(GetDefaultPhoneticReading(m_pEntryED->GetText()));
675 :
676 0 : bKeyEnable = sal_True;
677 0 : m_pKey1DCB->SetText(m_pKey1DCB->GetEntry(nKey1Pos));
678 0 : m_pPhoneticED1->SetText(GetDefaultPhoneticReading(m_pKey1DCB->GetText()));
679 0 : if(!m_pKey1DCB->GetText().isEmpty())
680 : {
681 0 : bKey1HasText = bSetKey2 = bKey2Enable = sal_True;
682 0 : m_pKey2DCB->SetText(m_pKey2DCB->GetEntry(nKey2Pos));
683 0 : m_pPhoneticED2->SetText(GetDefaultPhoneticReading(m_pKey2DCB->GetText()));
684 0 : if(!m_pKey2DCB->GetText().isEmpty())
685 0 : bKey2HasText = sal_True;
686 : }
687 : }
688 : else
689 : {
690 0 : bLevelEnable = sal_True;
691 0 : m_pLevelNF->SetMax(MAXLEVEL);
692 0 : m_pLevelNF->SetValue(m_pLevelNF->Normalize(0));
693 0 : bSetKey2 = sal_True;
694 : }
695 0 : m_pLevelFT->Show(bLevelEnable);
696 0 : m_pLevelNF->Show(bLevelEnable);
697 0 : m_pMainEntryCB->Show(nPos == POS_INDEX);
698 :
699 0 : m_pKey1FT->Enable(bKeyEnable);
700 0 : m_pKey1DCB->Enable(bKeyEnable);
701 0 : if ( bSetKey2 )
702 : {
703 0 : m_pKey2DCB->Enable(bKey2Enable);
704 0 : m_pKey2FT->Enable(bKey2Enable);
705 : }
706 0 : m_pPhoneticFT0->Enable(bKeyEnable&&bEntryHasText&&bIsPhoneticReadingEnabled);
707 0 : m_pPhoneticED0->Enable(bKeyEnable&&bEntryHasText&&bIsPhoneticReadingEnabled);
708 0 : m_pPhoneticFT1->Enable(bKeyEnable&&bKey1HasText&&bIsPhoneticReadingEnabled);
709 0 : m_pPhoneticED1->Enable(bKeyEnable&&bKey1HasText&&bIsPhoneticReadingEnabled);
710 0 : m_pPhoneticFT2->Enable(bKeyEnable&&bKey2HasText&&bIsPhoneticReadingEnabled);
711 0 : m_pPhoneticED2->Enable(bKeyEnable&&bKey2HasText&&bIsPhoneticReadingEnabled);
712 : }
713 : else //m_pEntryED !!m_pEntryED is not a ListBox but a Edit
714 : {
715 0 : bool bHasText = (!m_pEntryED->GetText().isEmpty());
716 0 : if(!bHasText)
717 : {
718 0 : m_pPhoneticED0->SetText(aEmptyStr);
719 0 : bPhoneticED0_ChangedByUser = sal_False;
720 : }
721 0 : else if(!bPhoneticED0_ChangedByUser)
722 0 : m_pPhoneticED0->SetText(GetDefaultPhoneticReading(m_pEntryED->GetText()));
723 :
724 0 : m_pPhoneticFT0->Enable(bHasText&&bIsPhoneticReadingEnabled);
725 0 : m_pPhoneticED0->Enable(bHasText&&bIsPhoneticReadingEnabled);
726 : }
727 0 : m_pOKBT->Enable(!pSh->HasReadonlySel() &&
728 0 : (!m_pEntryED->GetText().isEmpty() || pSh->GetCrsrCnt(sal_False)));
729 0 : return 0;
730 : }
731 :
732 0 : IMPL_LINK_NOARG_INLINE_START(SwIndexMarkPane, NextHdl)
733 : {
734 0 : InsertUpdate();
735 0 : pTOXMgr->NextTOXMark();
736 0 : UpdateDialog();
737 0 : return 0;
738 : }
739 0 : IMPL_LINK_NOARG_INLINE_END(SwIndexMarkPane, NextHdl)
740 :
741 0 : IMPL_LINK_NOARG_INLINE_START(SwIndexMarkPane, NextSameHdl)
742 : {
743 0 : InsertUpdate();
744 0 : pTOXMgr->NextTOXMark(sal_True);
745 0 : UpdateDialog();
746 0 : return 0;
747 : }
748 0 : IMPL_LINK_NOARG_INLINE_END(SwIndexMarkPane, NextSameHdl)
749 :
750 0 : IMPL_LINK_NOARG_INLINE_START(SwIndexMarkPane, PrevHdl)
751 : {
752 0 : InsertUpdate();
753 0 : pTOXMgr->PrevTOXMark();
754 0 : UpdateDialog();
755 0 : return 0;
756 : }
757 0 : IMPL_LINK_NOARG_INLINE_END(SwIndexMarkPane, PrevHdl)
758 :
759 0 : IMPL_LINK_NOARG_INLINE_START(SwIndexMarkPane, PrevSameHdl)
760 : {
761 0 : InsertUpdate();
762 0 : pTOXMgr->PrevTOXMark(sal_True);
763 0 : UpdateDialog();
764 :
765 0 : return 0;
766 : }
767 0 : IMPL_LINK_NOARG_INLINE_END(SwIndexMarkPane, PrevSameHdl)
768 :
769 0 : IMPL_LINK_NOARG(SwIndexMarkPane, DelHdl)
770 : {
771 0 : bDel = sal_True;
772 0 : InsertUpdate();
773 0 : bDel = sal_False;
774 :
775 0 : if(pTOXMgr->GetCurTOXMark())
776 0 : UpdateDialog();
777 : else
778 : {
779 0 : CloseHdl(m_pCloseBT);
780 0 : SfxViewFrame::Current()->GetBindings().Invalidate(FN_EDIT_IDX_ENTRY_DLG);
781 : }
782 0 : return 0;
783 : }
784 :
785 : /*--------------------------------------------------------------------
786 : Description: renew dialog view
787 : --------------------------------------------------------------------*/
788 0 : void SwIndexMarkPane::UpdateDialog()
789 : {
790 : OSL_ENSURE(pSh && pTOXMgr, "no shell?");
791 0 : SwTOXMark* pMark = pTOXMgr->GetCurTOXMark();
792 : OSL_ENSURE(pMark, "no current marker");
793 0 : if(!pMark)
794 0 : return;
795 :
796 0 : ViewShell::SetCareWin(&m_rDialog);
797 :
798 0 : aOrgStr = pMark->GetText();
799 0 : m_pEntryED->SetText(aOrgStr);
800 :
801 : // set index type
802 0 : sal_Bool bLevelEnable = sal_True,
803 0 : bKeyEnable = sal_False,
804 0 : bKey2Enable = sal_False,
805 0 : bEntryHasText = sal_False,
806 0 : bKey1HasText = sal_False,
807 0 : bKey2HasText = sal_False;
808 :
809 0 : TOXTypes eCurType = pMark->GetTOXType()->GetType();
810 0 : if(TOX_INDEX == eCurType)
811 : {
812 0 : bLevelEnable = sal_False;
813 0 : bKeyEnable = sal_True;
814 0 : bKey1HasText = bKey2Enable = 0 != pMark->GetPrimaryKey().Len();
815 0 : bKey2HasText = 0 != pMark->GetSecondaryKey().Len();
816 0 : bEntryHasText = 0 != pMark->GetText().Len();
817 0 : m_pKey1DCB->SetText( pMark->GetPrimaryKey() );
818 0 : m_pKey2DCB->SetText( pMark->GetSecondaryKey() );
819 0 : m_pPhoneticED0->SetText( pMark->GetTextReading() );
820 0 : m_pPhoneticED1->SetText( pMark->GetPrimaryKeyReading() );
821 0 : m_pPhoneticED2->SetText( pMark->GetSecondaryKeyReading() );
822 0 : m_pMainEntryCB->Check(pMark->IsMainEntry());
823 : }
824 0 : else if(TOX_CONTENT == eCurType || TOX_USER == eCurType)
825 : {
826 0 : m_pLevelNF->SetValue(m_pLevelNF->Normalize(pMark->GetLevel()));
827 : }
828 0 : m_pKey1FT->Enable(bKeyEnable);
829 0 : m_pKey1DCB->Enable(bKeyEnable);
830 0 : m_pLevelNF->SetMax(MAXLEVEL);
831 0 : m_pLevelFT->Show(bLevelEnable);
832 0 : m_pLevelNF->Show(bLevelEnable);
833 0 : m_pMainEntryCB->Show(!bLevelEnable);
834 0 : m_pKey2FT->Enable(bKey2Enable);
835 0 : m_pKey2DCB->Enable(bKey2Enable);
836 :
837 0 : UpdateLanguageDependenciesForPhoneticReading();
838 0 : m_pPhoneticFT0->Enable(bKeyEnable&&bEntryHasText&&bIsPhoneticReadingEnabled);
839 0 : m_pPhoneticED0->Enable(bKeyEnable&&bEntryHasText&&bIsPhoneticReadingEnabled);
840 0 : m_pPhoneticFT1->Enable(bKeyEnable&&bKey1HasText&&bIsPhoneticReadingEnabled);
841 0 : m_pPhoneticED1->Enable(bKeyEnable&&bKey1HasText&&bIsPhoneticReadingEnabled);
842 0 : m_pPhoneticFT2->Enable(bKeyEnable&&bKey2HasText&&bIsPhoneticReadingEnabled);
843 0 : m_pPhoneticED2->Enable(bKeyEnable&&bKey2HasText&&bIsPhoneticReadingEnabled);
844 :
845 : // set index type
846 0 : m_pTypeDCB->SelectEntry(pMark->GetTOXType()->GetTypeName());
847 :
848 : // set Next - Prev - Buttons
849 0 : pSh->SttCrsrMove();
850 0 : if( m_pPrevBT->IsVisible() )
851 : {
852 0 : const SwTOXMark* pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_PRV );
853 0 : if( pMoveMark != pMark )
854 0 : pSh->GotoTOXMark( *pMoveMark, TOX_NXT );
855 0 : m_pPrevBT->Enable( pMoveMark != pMark );
856 0 : pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_NXT );
857 0 : if( pMoveMark != pMark )
858 0 : pSh->GotoTOXMark( *pMoveMark, TOX_PRV );
859 0 : m_pNextBT->Enable( pMoveMark != pMark );
860 : }
861 :
862 0 : if( m_pPrevSameBT->IsVisible() )
863 : {
864 0 : const SwTOXMark* pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_SAME_PRV );
865 0 : if( pMoveMark != pMark )
866 0 : pSh->GotoTOXMark( *pMoveMark, TOX_SAME_NXT );
867 0 : m_pPrevSameBT->Enable( pMoveMark != pMark );
868 0 : pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_SAME_NXT );
869 0 : if( pMoveMark != pMark )
870 0 : pSh->GotoTOXMark( *pMoveMark, TOX_SAME_PRV );
871 0 : m_pNextSameBT->Enable( pMoveMark != pMark );
872 : }
873 :
874 0 : sal_Bool bEnable = !pSh->HasReadonlySel();
875 0 : m_pOKBT->Enable( bEnable );
876 0 : m_pDelBT->Enable( bEnable );
877 0 : m_pEntryED->SetReadOnly( !bEnable );
878 0 : m_pLevelNF->SetReadOnly( !bEnable );
879 0 : m_pKey1DCB->SetReadOnly( !bEnable );
880 0 : m_pKey2DCB->SetReadOnly( !bEnable );
881 :
882 0 : pSh->SelectTxtAttr( RES_TXTATR_TOXMARK, pMark->GetTxtTOXMark() );
883 : // we need the point at the start of the attribut
884 0 : pSh->SwapPam();
885 :
886 0 : pSh->EndCrsrMove();
887 : }
888 :
889 : /*--------------------------------------------------------------------
890 : Remind whether the edit boxes for Phonetic reading are changed manually
891 : --------------------------------------------------------------------*/
892 0 : IMPL_LINK( SwIndexMarkPane, PhoneticEDModifyHdl, Edit *, pEdit )
893 : {
894 0 : if (m_pPhoneticED0 == pEdit)
895 : {
896 0 : bPhoneticED0_ChangedByUser = !pEdit->GetText().isEmpty();
897 : }
898 0 : else if (m_pPhoneticED1 == pEdit)
899 : {
900 0 : bPhoneticED1_ChangedByUser = !pEdit->GetText().isEmpty();
901 : }
902 0 : else if (m_pPhoneticED2 == pEdit)
903 : {
904 0 : bPhoneticED2_ChangedByUser = !pEdit->GetText().isEmpty();
905 : }
906 0 : return 0;
907 : }
908 :
909 : /*--------------------------------------------------------------------
910 : Description: Enable Disable of the 2nd key
911 : --------------------------------------------------------------------*/
912 0 : IMPL_LINK( SwIndexMarkPane, KeyDCBModifyHdl, ComboBox *, pBox )
913 : {
914 0 : if (m_pKey1DCB == pBox)
915 : {
916 0 : sal_Bool bEnable = !pBox->GetText().isEmpty();
917 0 : if(!bEnable)
918 : {
919 0 : m_pKey2DCB->SetText(aEmptyStr);
920 0 : m_pPhoneticED1->SetText(aEmptyStr);
921 0 : m_pPhoneticED2->SetText(aEmptyStr);
922 0 : bPhoneticED1_ChangedByUser = sal_False;
923 0 : bPhoneticED2_ChangedByUser = sal_False;
924 : }
925 : else
926 : {
927 0 : if(pBox->IsInDropDown())
928 : {
929 : //reset bPhoneticED1_ChangedByUser if a completely new string is selected
930 0 : bPhoneticED1_ChangedByUser = sal_False;
931 : }
932 0 : if(!bPhoneticED1_ChangedByUser)
933 0 : m_pPhoneticED1->SetText(GetDefaultPhoneticReading(pBox->GetText()));
934 : }
935 0 : m_pKey2DCB->Enable(bEnable);
936 0 : m_pKey2FT->Enable(bEnable);
937 : }
938 0 : else if (m_pKey2DCB == pBox)
939 : {
940 0 : if(pBox->GetText().isEmpty())
941 : {
942 0 : m_pPhoneticED2->SetText(aEmptyStr);
943 0 : bPhoneticED2_ChangedByUser = sal_False;
944 : }
945 : else
946 : {
947 0 : if(pBox->IsInDropDown())
948 : {
949 : //reset bPhoneticED1_ChangedByUser if a completely new string is selected
950 0 : bPhoneticED2_ChangedByUser = sal_False;
951 : }
952 0 : if(!bPhoneticED2_ChangedByUser)
953 0 : m_pPhoneticED2->SetText(GetDefaultPhoneticReading(pBox->GetText()));
954 : }
955 : }
956 0 : bool bKey1HasText = (!m_pKey1DCB->GetText().isEmpty());
957 0 : bool bKey2HasText = (!m_pKey2DCB->GetText().isEmpty());
958 :
959 0 : m_pPhoneticFT1->Enable(bKey1HasText && bIsPhoneticReadingEnabled);
960 0 : m_pPhoneticED1->Enable(bKey1HasText && bIsPhoneticReadingEnabled);
961 0 : m_pPhoneticFT2->Enable(bKey2HasText && bIsPhoneticReadingEnabled);
962 0 : m_pPhoneticED2->Enable(bKey2HasText && bIsPhoneticReadingEnabled);
963 :
964 0 : return 0;
965 : }
966 :
967 : /*--------------------------------------------------
968 : overload dtor
969 : --------------------------------------------------*/
970 0 : SwIndexMarkPane::~SwIndexMarkPane()
971 : {
972 0 : delete pTOXMgr;
973 0 : ViewShell::SetCareWin( 0 );
974 0 : }
975 :
976 0 : void SwIndexMarkPane::ReInitDlg(SwWrtShell& rWrtShell, SwTOXMark* pCurTOXMark)
977 : {
978 0 : pSh = &rWrtShell;
979 0 : delete pTOXMgr;
980 0 : pTOXMgr = new SwTOXMgr(pSh);
981 0 : if(pCurTOXMark)
982 : {
983 0 : for(sal_uInt16 i = 0; i < pTOXMgr->GetTOXMarkCount(); i++)
984 0 : if(pTOXMgr->GetTOXMark(i) == pCurTOXMark)
985 : {
986 0 : pTOXMgr->SetCurTOXMark(i);
987 0 : break;
988 : }
989 : }
990 0 : InitControls();
991 0 : }
992 :
993 0 : SwIndexMarkFloatDlg::SwIndexMarkFloatDlg(SfxBindings* _pBindings,
994 : SfxChildWindow* pChild, Window *pParent,
995 : SfxChildWinInfo* pInfo, sal_Bool bNew)
996 : : SfxModelessDialog(_pBindings, pChild, pParent, "IndexEntryDialog", "modules/swriter/ui/indexentry.ui")
997 0 : , m_aContent(*this, bNew, *::GetActiveWrtShell())
998 : {
999 0 : m_aContent.ReInitDlg(*::GetActiveWrtShell());
1000 0 : Initialize(pInfo);
1001 0 : }
1002 :
1003 0 : void SwIndexMarkFloatDlg::Activate()
1004 : {
1005 0 : SfxModelessDialog::Activate();
1006 0 : m_aContent.Activate();
1007 0 : }
1008 :
1009 0 : void SwIndexMarkFloatDlg::ReInitDlg(SwWrtShell& rWrtShell)
1010 : {
1011 0 : m_aContent.ReInitDlg( rWrtShell );
1012 0 : }
1013 :
1014 0 : SwIndexMarkModalDlg::SwIndexMarkModalDlg(Window *pParent, SwWrtShell& rSh, SwTOXMark* pCurTOXMark)
1015 : : SvxStandardDialog(pParent, "IndexEntryDialog", "modules/swriter/ui/indexentry.ui")
1016 0 : , m_aContent(*this, sal_False, rSh)
1017 : {
1018 0 : m_aContent.ReInitDlg(rSh, pCurTOXMark);
1019 0 : }
1020 :
1021 0 : void SwIndexMarkModalDlg::Apply()
1022 : {
1023 0 : m_aContent.Apply();
1024 0 : }
1025 :
1026 : class SwCreateAuthEntryDlg_Impl : public ModalDialog
1027 : {
1028 : FixedText* pFixedTexts[AUTH_FIELD_END];
1029 : ListBox* pTypeListBox;
1030 : ComboBox* pIdentifierBox;
1031 : Edit* pEdits[AUTH_FIELD_END];
1032 :
1033 : OKButton* m_pOKBT;
1034 :
1035 : Link aShortNameCheckLink;
1036 :
1037 : SwWrtShell& rWrtSh;
1038 :
1039 : sal_Bool m_bNewEntryMode;
1040 : sal_Bool m_bNameAllowed;
1041 :
1042 : DECL_LINK(IdentifierHdl, ComboBox*);
1043 : DECL_LINK(ShortNameHdl, Edit*);
1044 : DECL_LINK(EnableHdl, ListBox* pBox);
1045 :
1046 : public:
1047 : SwCreateAuthEntryDlg_Impl(Window* pParent,
1048 : const String pFields[],
1049 : SwWrtShell& rSh,
1050 : sal_Bool bNewEntry,
1051 : bool bCreate);
1052 : ~SwCreateAuthEntryDlg_Impl();
1053 :
1054 : String GetEntryText(ToxAuthorityField eField) const;
1055 :
1056 0 : void SetCheckNameHdl(const Link& rLink) {aShortNameCheckLink = rLink;}
1057 :
1058 : };
1059 :
1060 : struct TextInfo
1061 : {
1062 : ToxAuthorityField nToxField;
1063 : const char* pHelpId;
1064 : };
1065 :
1066 : static const TextInfo aTextInfoArr[] =
1067 : {
1068 : {AUTH_FIELD_IDENTIFIER, HID_AUTH_FIELD_IDENTIFIER },
1069 : {AUTH_FIELD_AUTHORITY_TYPE, HID_AUTH_FIELD_AUTHORITY_TYPE },
1070 : {AUTH_FIELD_AUTHOR, HID_AUTH_FIELD_AUTHOR },
1071 : {AUTH_FIELD_TITLE, HID_AUTH_FIELD_TITLE },
1072 : {AUTH_FIELD_YEAR, HID_AUTH_FIELD_YEAR },
1073 : {AUTH_FIELD_PUBLISHER, HID_AUTH_FIELD_PUBLISHER },
1074 : {AUTH_FIELD_ADDRESS, HID_AUTH_FIELD_ADDRESS },
1075 : {AUTH_FIELD_ISBN, HID_AUTH_FIELD_ISBN },
1076 : {AUTH_FIELD_CHAPTER, HID_AUTH_FIELD_CHAPTER },
1077 : {AUTH_FIELD_PAGES, HID_AUTH_FIELD_PAGES },
1078 : {AUTH_FIELD_EDITOR, HID_AUTH_FIELD_EDITOR },
1079 : {AUTH_FIELD_EDITION, HID_AUTH_FIELD_EDITION },
1080 : {AUTH_FIELD_BOOKTITLE, HID_AUTH_FIELD_BOOKTITLE },
1081 : {AUTH_FIELD_VOLUME, HID_AUTH_FIELD_VOLUME },
1082 : {AUTH_FIELD_HOWPUBLISHED, HID_AUTH_FIELD_HOWPUBLISHED },
1083 : {AUTH_FIELD_ORGANIZATIONS, HID_AUTH_FIELD_ORGANIZATIONS },
1084 : {AUTH_FIELD_INSTITUTION, HID_AUTH_FIELD_INSTITUTION },
1085 : {AUTH_FIELD_SCHOOL, HID_AUTH_FIELD_SCHOOL },
1086 : {AUTH_FIELD_REPORT_TYPE, HID_AUTH_FIELD_REPORT_TYPE },
1087 : {AUTH_FIELD_MONTH, HID_AUTH_FIELD_MONTH },
1088 : {AUTH_FIELD_JOURNAL, HID_AUTH_FIELD_JOURNAL },
1089 : {AUTH_FIELD_NUMBER, HID_AUTH_FIELD_NUMBER },
1090 : {AUTH_FIELD_SERIES, HID_AUTH_FIELD_SERIES },
1091 : {AUTH_FIELD_ANNOTE, HID_AUTH_FIELD_ANNOTE },
1092 : {AUTH_FIELD_NOTE, HID_AUTH_FIELD_NOTE },
1093 : {AUTH_FIELD_URL, HID_AUTH_FIELD_URL },
1094 : {AUTH_FIELD_CUSTOM1, HID_AUTH_FIELD_CUSTOM1 },
1095 : {AUTH_FIELD_CUSTOM2, HID_AUTH_FIELD_CUSTOM2 },
1096 : {AUTH_FIELD_CUSTOM3, HID_AUTH_FIELD_CUSTOM3 },
1097 : {AUTH_FIELD_CUSTOM4, HID_AUTH_FIELD_CUSTOM4 },
1098 : {AUTH_FIELD_CUSTOM5, HID_AUTH_FIELD_CUSTOM5 }
1099 : };
1100 :
1101 : sal_Bool SwAuthorMarkPane::bIsFromComponent = sal_True;
1102 :
1103 0 : SwAuthorMarkPane::SwAuthorMarkPane(Dialog &rDialog, sal_Bool bNewDlg)
1104 : : m_rDialog(rDialog)
1105 : , bNewEntry(bNewDlg)
1106 : , bBibAccessInitialized(sal_False)
1107 0 : , pSh(0)
1108 : {
1109 0 : m_rDialog.get(m_pFromComponentRB, "frombibliography");
1110 0 : m_rDialog.get(m_pFromDocContentRB, "fromdocument");
1111 0 : m_rDialog.get(m_pAuthorFI, "author");
1112 0 : m_rDialog.get(m_pTitleFI, "title");
1113 0 : m_rDialog.get(m_pEntryED, "entryed");
1114 0 : m_rDialog.get(m_pEntryLB, "entrylb");
1115 : m_rDialog.get(m_pActionBT,
1116 0 : bNewEntry ? OString("insert") : OString("modify"));
1117 0 : m_pActionBT->Show(true);
1118 0 : m_rDialog.get(m_pCloseBT, "close");
1119 0 : m_rDialog.get(m_pCreateEntryPB, "new");
1120 0 : m_rDialog.get(m_pEditEntryPB, "edit");
1121 :
1122 0 : m_pFromComponentRB->Show(bNewEntry);
1123 0 : m_pFromDocContentRB->Show(bNewEntry);
1124 0 : m_pFromComponentRB->Check(bIsFromComponent);
1125 0 : m_pFromDocContentRB->Check(!bIsFromComponent);
1126 :
1127 0 : m_pActionBT->SetClickHdl(LINK(this,SwAuthorMarkPane, InsertHdl));
1128 0 : m_pCloseBT->SetClickHdl(LINK(this,SwAuthorMarkPane, CloseHdl));
1129 0 : m_pCreateEntryPB->SetClickHdl(LINK(this,SwAuthorMarkPane, CreateEntryHdl));
1130 0 : m_pEditEntryPB->SetClickHdl(LINK(this,SwAuthorMarkPane, CreateEntryHdl));
1131 0 : m_pFromComponentRB->SetClickHdl(LINK(this,SwAuthorMarkPane, ChangeSourceHdl));
1132 0 : m_pFromDocContentRB->SetClickHdl(LINK(this,SwAuthorMarkPane, ChangeSourceHdl));
1133 0 : m_pEntryED->SetModifyHdl(LINK(this,SwAuthorMarkPane, EditModifyHdl));
1134 :
1135 : m_rDialog.SetText(SW_RESSTR(
1136 0 : bNewEntry ? STR_AUTHMRK_INSERT : STR_AUTHMRK_EDIT));
1137 :
1138 0 : m_pEntryED->Show(!bNewEntry);
1139 0 : m_pEntryLB->Show(bNewEntry);
1140 0 : if(bNewEntry)
1141 : {
1142 0 : m_pEntryLB->SetSelectHdl(LINK(this, SwAuthorMarkPane, CompEntryHdl));
1143 : }
1144 0 : }
1145 :
1146 0 : void SwAuthorMarkPane::ReInitDlg(SwWrtShell& rWrtShell)
1147 : {
1148 0 : pSh = &rWrtShell;
1149 0 : InitControls();
1150 0 : }
1151 :
1152 0 : IMPL_LINK_NOARG(SwAuthorMarkPane, CloseHdl)
1153 : {
1154 0 : if(bNewEntry)
1155 : {
1156 0 : sal_uInt16 nSlot = FN_INSERT_AUTH_ENTRY_DLG;
1157 : SfxViewFrame::Current()->GetDispatcher()->Execute(nSlot,
1158 0 : SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
1159 : }
1160 : else
1161 : {
1162 0 : m_rDialog.EndDialog(RET_CANCEL);
1163 : }
1164 0 : return 0;
1165 : }
1166 :
1167 0 : static String lcl_FindColumnEntry(const beans::PropertyValue* pFields, sal_Int32 nLen, const String& rColumnTitle)
1168 : {
1169 0 : String sRet;
1170 0 : OUString uColumnTitle = rColumnTitle;
1171 0 : for(sal_uInt16 i = 0; i < nLen; i++)
1172 : {
1173 0 : OUString uTmp;
1174 0 : if(pFields[i].Name == uColumnTitle &&
1175 0 : (pFields[i].Value >>= uTmp))
1176 : {
1177 0 : sRet = String(uTmp);
1178 0 : break;
1179 : }
1180 0 : }
1181 0 : return sRet;
1182 : }
1183 :
1184 0 : IMPL_LINK( SwAuthorMarkPane, CompEntryHdl, ListBox*, pBox)
1185 : {
1186 0 : String sEntry(pBox->GetSelectEntry());
1187 0 : if(bIsFromComponent)
1188 : {
1189 0 : if(xBibAccess.is() && sEntry.Len())
1190 : {
1191 0 : OUString uEntry(sEntry);
1192 0 : if(xBibAccess->hasByName(uEntry))
1193 : {
1194 0 : uno::Any aEntry(xBibAccess->getByName(uEntry));
1195 0 : uno::Sequence<beans::PropertyValue> aFieldProps;
1196 0 : if(aEntry >>= aFieldProps)
1197 : {
1198 0 : const beans::PropertyValue* pProps = aFieldProps.getConstArray();
1199 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END && i < aFieldProps.getLength(); i++)
1200 : {
1201 0 : m_sFields[i] = lcl_FindColumnEntry(
1202 0 : pProps, aFieldProps.getLength(), m_sColumnTitles[i]);
1203 : }
1204 0 : }
1205 0 : }
1206 : }
1207 : }
1208 : else
1209 : {
1210 0 : if(sEntry.Len())
1211 : {
1212 : const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1213 0 : pSh->GetFldType(RES_AUTHORITY, aEmptyStr);
1214 0 : const SwAuthEntry* pEntry = pFType ? pFType->GetEntryByIdentifier(sEntry) : 0;
1215 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1216 0 : m_sFields[i] = pEntry ?
1217 0 : pEntry->GetAuthorField((ToxAuthorityField)i) : aEmptyStr;
1218 : }
1219 : }
1220 0 : if(!pBox->GetSelectEntry().Len())
1221 : {
1222 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1223 0 : m_sFields[i] = aEmptyStr;
1224 : }
1225 0 : m_pAuthorFI->SetText(m_sFields[AUTH_FIELD_AUTHOR]);
1226 0 : m_pTitleFI->SetText(m_sFields[AUTH_FIELD_TITLE]);
1227 0 : return 0;
1228 : }
1229 :
1230 0 : IMPL_LINK_NOARG(SwAuthorMarkPane, InsertHdl)
1231 : {
1232 : //insert or update the SwAuthorityField...
1233 0 : if(pSh)
1234 : {
1235 0 : sal_Bool bDifferent = sal_False;
1236 : OSL_ENSURE(m_sFields[AUTH_FIELD_IDENTIFIER].Len() , "No Id is set!");
1237 : OSL_ENSURE(m_sFields[AUTH_FIELD_AUTHORITY_TYPE].Len() , "No authority type is set!");
1238 : //check if the entry already exists with different content
1239 : const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1240 0 : pSh->GetFldType(RES_AUTHORITY, aEmptyStr);
1241 : const SwAuthEntry* pEntry = pFType ?
1242 0 : pFType->GetEntryByIdentifier( m_sFields[AUTH_FIELD_IDENTIFIER])
1243 0 : : 0;
1244 0 : if(pEntry)
1245 : {
1246 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END && !bDifferent; i++)
1247 0 : bDifferent |= m_sFields[i] != pEntry->GetAuthorField((ToxAuthorityField)i);
1248 0 : if(bDifferent)
1249 : {
1250 0 : QueryBox aQuery(&m_rDialog, SW_RES(DLG_CHANGE_AUTH_ENTRY));
1251 0 : if(RET_YES != aQuery.Execute())
1252 0 : return 0;
1253 : }
1254 : }
1255 :
1256 0 : SwFldMgr aMgr(pSh);
1257 0 : String sFields;
1258 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1259 : {
1260 0 : sFields += m_sFields[i];
1261 0 : sFields += TOX_STYLE_DELIMITER;
1262 : }
1263 0 : if(bNewEntry)
1264 : {
1265 0 : if(bDifferent)
1266 : {
1267 0 : SwAuthEntry aNewData;
1268 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1269 0 : aNewData.SetAuthorField((ToxAuthorityField)i, m_sFields[i]);
1270 0 : pSh->ChangeAuthorityData(&aNewData);
1271 : }
1272 0 : SwInsertFld_Data aData(TYP_AUTHORITY, 0, sFields, aEmptyStr, 0 );
1273 0 : aMgr.InsertFld( aData );
1274 : }
1275 0 : else if(aMgr.GetCurFld())
1276 : {
1277 0 : aMgr.UpdateCurFld(0, sFields, aEmptyStr);
1278 0 : }
1279 : }
1280 0 : if(!bNewEntry)
1281 0 : CloseHdl(0);
1282 0 : return 0;
1283 : }
1284 :
1285 0 : IMPL_LINK(SwAuthorMarkPane, CreateEntryHdl, PushButton*, pButton)
1286 : {
1287 0 : bool bCreate = pButton == m_pCreateEntryPB;
1288 0 : String sOldId = m_sCreatedEntry[0];
1289 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1290 0 : m_sCreatedEntry[i] = bCreate ? aEmptyStr : m_sFields[i];
1291 : SwCreateAuthEntryDlg_Impl aDlg(pButton,
1292 : bCreate ? m_sCreatedEntry : m_sFields,
1293 0 : *pSh, bNewEntry, bCreate);
1294 0 : if(bNewEntry)
1295 : {
1296 0 : aDlg.SetCheckNameHdl(LINK(this, SwAuthorMarkPane, IsEntryAllowedHdl));
1297 : }
1298 0 : if(RET_OK == aDlg.Execute())
1299 : {
1300 0 : if(bCreate && sOldId.Len())
1301 : {
1302 0 : m_pEntryLB->RemoveEntry(sOldId);
1303 : }
1304 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1305 : {
1306 0 : m_sFields[i] = aDlg.GetEntryText((ToxAuthorityField)i);
1307 0 : m_sCreatedEntry[i] = m_sFields[i];
1308 : }
1309 0 : if(bNewEntry && !m_pFromDocContentRB->IsChecked())
1310 : {
1311 0 : m_pFromDocContentRB->Check(sal_True);
1312 0 : ChangeSourceHdl(m_pFromDocContentRB);
1313 : }
1314 0 : if(bCreate)
1315 : {
1316 : OSL_ENSURE(LISTBOX_ENTRY_NOTFOUND ==
1317 : m_pEntryLB->GetEntryPos(m_sFields[AUTH_FIELD_IDENTIFIER]),
1318 : "entry exists!");
1319 0 : m_pEntryLB->InsertEntry(m_sFields[AUTH_FIELD_IDENTIFIER]);
1320 0 : m_pEntryLB->SelectEntry(m_sFields[AUTH_FIELD_IDENTIFIER]);
1321 : }
1322 0 : m_pEntryED->SetText(m_sFields[AUTH_FIELD_IDENTIFIER]);
1323 0 : m_pAuthorFI->SetText(m_sFields[AUTH_FIELD_AUTHOR]);
1324 0 : m_pTitleFI->SetText(m_sFields[AUTH_FIELD_TITLE]);
1325 0 : m_pActionBT->Enable();
1326 : }
1327 0 : return 0;
1328 : }
1329 :
1330 0 : IMPL_LINK(SwAuthorMarkPane, ChangeSourceHdl, RadioButton*, pButton)
1331 : {
1332 0 : sal_Bool bFromComp = (pButton == m_pFromComponentRB);
1333 0 : bIsFromComponent = bFromComp;
1334 0 : m_pCreateEntryPB->Enable(!bIsFromComponent);
1335 0 : m_pEntryLB->Clear();
1336 0 : if(bIsFromComponent)
1337 : {
1338 0 : if(!bBibAccessInitialized)
1339 : {
1340 0 : uno::Reference< uno::XComponentContext > xContext = getProcessComponentContext();
1341 0 : xBibAccess = frame::Bibliography::create( xContext );
1342 0 : uno::Reference< beans::XPropertySet > xPropSet(xBibAccess, uno::UNO_QUERY);
1343 0 : OUString uPropName("BibliographyDataFieldNames");
1344 0 : if(xPropSet.is() && xPropSet->getPropertySetInfo()->hasPropertyByName(uPropName))
1345 : {
1346 0 : uno::Any aNames = xPropSet->getPropertyValue(uPropName);
1347 0 : uno::Sequence<beans::PropertyValue> aSeq;
1348 0 : if( aNames >>= aSeq)
1349 : {
1350 0 : const beans::PropertyValue* pArr = aSeq.getConstArray();
1351 0 : for(sal_uInt16 i = 0; i < aSeq.getLength(); i++)
1352 : {
1353 0 : String sTitle = pArr[i].Name;
1354 0 : sal_Int16 nField = 0;
1355 0 : pArr[i].Value >>= nField;
1356 0 : if(nField >= 0 && nField < AUTH_FIELD_END)
1357 0 : m_sColumnTitles[nField] = sTitle;
1358 0 : }
1359 0 : }
1360 : }
1361 0 : bBibAccessInitialized = sal_True;
1362 : }
1363 0 : if(xBibAccess.is())
1364 : {
1365 0 : uno::Sequence<OUString> aIdentifiers = xBibAccess->getElementNames();
1366 0 : const OUString* pNames = aIdentifiers.getConstArray();
1367 0 : for(sal_uInt16 i = 0; i < aIdentifiers.getLength(); i++)
1368 : {
1369 0 : m_pEntryLB->InsertEntry(pNames[i]);
1370 0 : }
1371 : }
1372 : }
1373 : else
1374 : {
1375 : const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1376 0 : pSh->GetFldType(RES_AUTHORITY, aEmptyStr);
1377 0 : if(pFType)
1378 : {
1379 0 : std::vector<String> aIds;
1380 0 : pFType->GetAllEntryIdentifiers( aIds );
1381 0 : for(size_t n = 0; n < aIds.size(); ++n)
1382 0 : m_pEntryLB->InsertEntry(aIds[n]);
1383 : }
1384 0 : if(m_sCreatedEntry[AUTH_FIELD_IDENTIFIER].Len())
1385 0 : m_pEntryLB->InsertEntry(m_sCreatedEntry[AUTH_FIELD_IDENTIFIER]);
1386 : }
1387 0 : m_pEntryLB->SelectEntryPos(0);
1388 0 : CompEntryHdl(m_pEntryLB);
1389 0 : return 0;
1390 : }
1391 :
1392 0 : IMPL_LINK(SwAuthorMarkPane, EditModifyHdl, Edit*, pEdit)
1393 : {
1394 0 : Link aAllowed = LINK(this, SwAuthorMarkPane, IsEntryAllowedHdl);
1395 0 : long nResult = aAllowed.Call(pEdit);
1396 0 : m_pActionBT->Enable(nResult > 0);
1397 0 : if(nResult)
1398 : {
1399 0 : String sEntry(pEdit->GetText());
1400 0 : m_sFields[AUTH_FIELD_IDENTIFIER] = sEntry;
1401 0 : m_sCreatedEntry[AUTH_FIELD_IDENTIFIER] = sEntry;
1402 : }
1403 0 : return 0;
1404 : };
1405 :
1406 0 : IMPL_LINK(SwAuthorMarkPane, IsEntryAllowedHdl, Edit*, pEdit)
1407 : {
1408 0 : String sEntry = pEdit->GetText();
1409 0 : sal_Bool bAllowed = sal_False;
1410 0 : if(sEntry.Len())
1411 : {
1412 0 : if(m_pEntryLB->GetEntryPos(sEntry) != LISTBOX_ENTRY_NOTFOUND)
1413 0 : return 0;
1414 0 : else if(bIsFromComponent)
1415 : {
1416 : const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1417 0 : pSh->GetFldType(RES_AUTHORITY, aEmptyStr);
1418 0 : bAllowed = !pFType || !pFType->GetEntryByIdentifier(sEntry);
1419 : }
1420 : else
1421 : {
1422 0 : bAllowed = !xBibAccess.is() || !xBibAccess->hasByName(sEntry);
1423 : }
1424 : }
1425 0 : return bAllowed;
1426 : }
1427 :
1428 0 : void SwAuthorMarkPane::InitControls()
1429 : {
1430 : OSL_ENSURE(pSh, "no shell?");
1431 0 : SwField* pField = pSh->GetCurFld();
1432 : OSL_ENSURE(bNewEntry || pField, "no current marker");
1433 0 : if(bNewEntry)
1434 : {
1435 0 : ChangeSourceHdl(m_pFromComponentRB->IsChecked() ? m_pFromComponentRB : m_pFromDocContentRB);
1436 0 : m_pCreateEntryPB->Enable(!m_pFromComponentRB->IsChecked());
1437 0 : if(!m_pFromComponentRB->IsChecked() && m_sCreatedEntry[0].Len())
1438 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1439 0 : m_sFields[i] = m_sCreatedEntry[i];
1440 : }
1441 0 : if(bNewEntry || !pField || pField->GetTyp()->Which() != RES_AUTHORITY)
1442 0 : return;
1443 :
1444 0 : const SwAuthEntry* pEntry = ((SwAuthorityFieldType*)pField->GetTyp())->
1445 0 : GetEntryByHandle(((SwAuthorityField*)pField)->GetHandle());
1446 :
1447 : OSL_ENSURE(pEntry, "No authority entry found");
1448 0 : if(!pEntry)
1449 0 : return;
1450 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1451 0 : m_sFields[i] = pEntry->GetAuthorField((ToxAuthorityField)i);
1452 :
1453 0 : m_pEntryED->SetText(pEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER));
1454 0 : m_pAuthorFI->SetText(pEntry->GetAuthorField(AUTH_FIELD_AUTHOR));
1455 0 : m_pTitleFI->SetText(pEntry->GetAuthorField(AUTH_FIELD_TITLE));
1456 : }
1457 :
1458 0 : void SwAuthorMarkPane::Activate()
1459 : {
1460 0 : m_pActionBT->Enable(!pSh->HasReadonlySel());
1461 0 : }
1462 :
1463 0 : SwCreateAuthEntryDlg_Impl::SwCreateAuthEntryDlg_Impl(Window* pParent,
1464 : const String pFields[],
1465 : SwWrtShell& rSh,
1466 : sal_Bool bNewEntry,
1467 : bool bCreate)
1468 : : ModalDialog(pParent, "CreateAuthorEntryDialog", "modules/swriter/ui/createauthorentry.ui")
1469 :
1470 : ,
1471 :
1472 : pTypeListBox(0),
1473 : pIdentifierBox(0),
1474 : rWrtSh(rSh),
1475 : m_bNewEntryMode(bNewEntry),
1476 0 : m_bNameAllowed(sal_True)
1477 : {
1478 0 : get(m_pOKBT, "ok");
1479 :
1480 0 : VclGrid *pLeft = get<VclGrid>("leftgrid");
1481 0 : VclGrid *pRight = get<VclGrid>("rightgrid");
1482 :
1483 0 : bool bLeft = true;
1484 0 : sal_Int32 nLeftRow(0), nRightRow(0);
1485 0 : for(sal_uInt16 nIndex = 0; nIndex < AUTH_FIELD_END; nIndex++)
1486 : {
1487 0 : const TextInfo aCurInfo = aTextInfoArr[nIndex];
1488 :
1489 0 : pFixedTexts[nIndex] = new FixedText(bLeft ? pLeft : pRight, WB_VCENTER);
1490 :
1491 0 : pFixedTexts[nIndex]->set_grid_left_attach(0);
1492 0 : pFixedTexts[nIndex]->set_grid_top_attach(bLeft ? nLeftRow : nRightRow);
1493 0 : pFixedTexts[nIndex]->SetText(SW_RES(STR_AUTH_FIELD_START + aCurInfo.nToxField));
1494 0 : pFixedTexts[nIndex]->Show();
1495 0 : pEdits[nIndex] = 0;
1496 0 : if( AUTH_FIELD_AUTHORITY_TYPE == aCurInfo.nToxField )
1497 : {
1498 0 : pTypeListBox = new ListBox(bLeft ? pLeft : pRight, WB_DROPDOWN|WB_BORDER|WB_VCENTER);
1499 0 : for(sal_uInt16 j = 0; j < AUTH_TYPE_END; j++)
1500 0 : pTypeListBox->InsertEntry(SW_RESSTR(STR_AUTH_TYPE_START + j));
1501 0 : if(pFields[aCurInfo.nToxField].Len())
1502 : {
1503 0 : sal_uInt16 nIndexPos = static_cast< sal_uInt16 >(pFields[aCurInfo.nToxField].ToInt32());
1504 0 : pTypeListBox->SelectEntryPos(nIndexPos);
1505 : }
1506 0 : pTypeListBox->set_grid_left_attach(1);
1507 0 : pTypeListBox->set_grid_top_attach(bLeft ? nLeftRow : nRightRow);
1508 0 : pTypeListBox->set_hexpand(true);
1509 0 : pTypeListBox->Show();
1510 0 : pTypeListBox->SetSelectHdl(LINK(this, SwCreateAuthEntryDlg_Impl, EnableHdl));
1511 0 : pTypeListBox->SetHelpId(aCurInfo.pHelpId);
1512 0 : pFixedTexts[nIndex]->set_mnemonic_widget(pTypeListBox);
1513 : }
1514 0 : else if(AUTH_FIELD_IDENTIFIER == aCurInfo.nToxField && !m_bNewEntryMode)
1515 : {
1516 0 : pIdentifierBox = new ComboBox(bLeft ? pLeft : pRight, WB_BORDER|WB_DROPDOWN|WB_VCENTER);
1517 :
1518 : pIdentifierBox->SetSelectHdl(LINK(this,
1519 0 : SwCreateAuthEntryDlg_Impl, IdentifierHdl));
1520 :
1521 :
1522 : const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1523 0 : rSh.GetFldType(RES_AUTHORITY, aEmptyStr);
1524 0 : if(pFType)
1525 : {
1526 0 : std::vector<String> aIds;
1527 0 : pFType->GetAllEntryIdentifiers( aIds );
1528 0 : for(size_t n = 0; n < aIds.size(); ++n)
1529 0 : pIdentifierBox->InsertEntry(aIds[n]);
1530 : }
1531 0 : pIdentifierBox->SetText(pFields[aCurInfo.nToxField]);
1532 0 : pIdentifierBox->set_grid_left_attach(1);
1533 0 : pIdentifierBox->set_grid_top_attach(bLeft ? nLeftRow : nRightRow);
1534 0 : pIdentifierBox->set_hexpand(true);
1535 0 : pIdentifierBox->Show();
1536 0 : pIdentifierBox->SetHelpId(aCurInfo.pHelpId);
1537 0 : pFixedTexts[nIndex]->set_mnemonic_widget(pIdentifierBox);
1538 : }
1539 : else
1540 : {
1541 0 : pEdits[nIndex] = new Edit(bLeft ? pLeft : pRight, WB_BORDER|WB_VCENTER);
1542 0 : pEdits[nIndex]->SetWidthInChars(14);
1543 0 : pEdits[nIndex]->set_grid_left_attach(1);
1544 0 : pEdits[nIndex]->set_grid_top_attach(bLeft ? nLeftRow : nRightRow);
1545 0 : pEdits[nIndex]->set_hexpand(true);
1546 0 : pEdits[nIndex]->SetText(pFields[aCurInfo.nToxField]);
1547 0 : pEdits[nIndex]->Show();
1548 0 : pEdits[nIndex]->SetHelpId(aCurInfo.pHelpId);
1549 0 : if(AUTH_FIELD_IDENTIFIER == aCurInfo.nToxField)
1550 : {
1551 0 : pEdits[nIndex]->SetModifyHdl(LINK(this, SwCreateAuthEntryDlg_Impl, ShortNameHdl));
1552 0 : m_bNameAllowed = pFields[nIndex].Len() > 0;
1553 0 : if(!bCreate)
1554 : {
1555 0 : pFixedTexts[nIndex]->Enable(sal_False);
1556 0 : pEdits[nIndex]->Enable(sal_False);
1557 : }
1558 : }
1559 0 : pFixedTexts[nIndex]->set_mnemonic_widget(pEdits[nIndex]);
1560 : }
1561 0 : if(bLeft)
1562 0 : ++nLeftRow;
1563 : else
1564 0 : ++nRightRow;
1565 0 : bLeft = !bLeft;
1566 : }
1567 0 : EnableHdl(pTypeListBox);
1568 0 : }
1569 :
1570 0 : SwCreateAuthEntryDlg_Impl::~SwCreateAuthEntryDlg_Impl()
1571 : {
1572 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1573 : {
1574 0 : delete pFixedTexts[i];
1575 0 : delete pEdits[i];
1576 : }
1577 0 : delete pTypeListBox;
1578 0 : delete pIdentifierBox;
1579 0 : }
1580 :
1581 0 : String SwCreateAuthEntryDlg_Impl::GetEntryText(ToxAuthorityField eField) const
1582 : {
1583 0 : String sRet;
1584 0 : if( AUTH_FIELD_AUTHORITY_TYPE == eField )
1585 : {
1586 : OSL_ENSURE(pTypeListBox, "No ListBox");
1587 0 : sRet = OUString::number(pTypeListBox->GetSelectEntryPos());
1588 : }
1589 0 : else if( AUTH_FIELD_IDENTIFIER == eField && !m_bNewEntryMode)
1590 : {
1591 : OSL_ENSURE(pIdentifierBox, "No ComboBox");
1592 0 : sRet = pIdentifierBox->GetText();
1593 : }
1594 : else
1595 : {
1596 0 : for(sal_uInt16 nIndex = 0; nIndex < AUTH_FIELD_END; nIndex++)
1597 : {
1598 0 : const TextInfo aCurInfo = aTextInfoArr[nIndex];
1599 0 : if(aCurInfo.nToxField == eField)
1600 : {
1601 0 : sRet = pEdits[nIndex]->GetText();
1602 0 : break;
1603 : }
1604 : }
1605 : }
1606 0 : return sRet;
1607 : }
1608 :
1609 0 : IMPL_LINK(SwCreateAuthEntryDlg_Impl, IdentifierHdl, ComboBox*, pBox)
1610 : {
1611 : const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1612 0 : rWrtSh.GetFldType(RES_AUTHORITY, aEmptyStr);
1613 0 : if(pFType)
1614 : {
1615 : const SwAuthEntry* pEntry = pFType->GetEntryByIdentifier(
1616 0 : pBox->GetText());
1617 0 : if(pEntry)
1618 : {
1619 0 : for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1620 : {
1621 0 : const TextInfo aCurInfo = aTextInfoArr[i];
1622 0 : if(AUTH_FIELD_IDENTIFIER == aCurInfo.nToxField)
1623 0 : continue;
1624 0 : if(AUTH_FIELD_AUTHORITY_TYPE == aCurInfo.nToxField)
1625 : pTypeListBox->SelectEntry(
1626 0 : pEntry->GetAuthorField(aCurInfo.nToxField));
1627 : else
1628 0 : pEdits[i]->SetText(
1629 0 : pEntry->GetAuthorField(aCurInfo.nToxField));
1630 : }
1631 : }
1632 : }
1633 0 : return 0;
1634 : }
1635 :
1636 0 : IMPL_LINK(SwCreateAuthEntryDlg_Impl, ShortNameHdl, Edit*, pEdit)
1637 : {
1638 0 : if(aShortNameCheckLink.IsSet())
1639 : {
1640 0 : sal_Bool bEnable = 0 != aShortNameCheckLink.Call(pEdit);
1641 0 : m_bNameAllowed |= bEnable;
1642 0 : m_pOKBT->Enable(pTypeListBox->GetSelectEntryCount() && bEnable);
1643 : }
1644 0 : return 0;
1645 : }
1646 :
1647 0 : IMPL_LINK(SwCreateAuthEntryDlg_Impl, EnableHdl, ListBox*, pBox)
1648 : {
1649 0 : m_pOKBT->Enable(m_bNameAllowed && pBox->GetSelectEntryCount());
1650 0 : return 0;
1651 : };
1652 :
1653 0 : SwAuthMarkFloatDlg::SwAuthMarkFloatDlg(SfxBindings* _pBindings,
1654 : SfxChildWindow* pChild,
1655 : Window *pParent,
1656 : SfxChildWinInfo* pInfo,
1657 : sal_Bool bNew)
1658 : : SfxModelessDialog(_pBindings, pChild, pParent,
1659 : "BibliographyEntryDialog", "modules/swriter/ui/bibliographyentry.ui")
1660 0 : , m_aContent(*this, bNew)
1661 : {
1662 0 : Initialize(pInfo);
1663 0 : SwWrtShell* pWrtShell = ::GetActiveWrtShell();
1664 : OSL_ENSURE(pWrtShell, "No shell?");
1665 0 : m_aContent.ReInitDlg(*pWrtShell);
1666 0 : }
1667 :
1668 0 : void SwAuthMarkFloatDlg::Activate()
1669 : {
1670 0 : SfxModelessDialog::Activate();
1671 0 : m_aContent.Activate();
1672 0 : }
1673 :
1674 0 : void SwAuthMarkFloatDlg::ReInitDlg(SwWrtShell& rWrtShell)
1675 : {
1676 0 : m_aContent.ReInitDlg( rWrtShell );
1677 0 : }
1678 :
1679 0 : SwAuthMarkModalDlg::SwAuthMarkModalDlg(Window *pParent, SwWrtShell& rSh)
1680 : : SvxStandardDialog(pParent, "BibliographyEntryDialog",
1681 : "modules/swriter/ui/bibliographyentry.ui")
1682 0 : , m_aContent(*this, sal_False)
1683 : {
1684 0 : m_aContent.ReInitDlg(rSh);
1685 0 : }
1686 :
1687 0 : void SwAuthMarkModalDlg::Apply()
1688 : {
1689 0 : m_aContent.InsertHdl(0);
1690 0 : }
1691 :
1692 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|