/src/libreoffice/sw/source/uibase/shells/textidx.cxx
Line | Count | Source |
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 <hintids.hxx> |
21 | | #include <sfx2/request.hxx> |
22 | | #include <sfx2/viewfrm.hxx> |
23 | | #include <svl/eitem.hxx> |
24 | | #include <editeng/sizeitem.hxx> |
25 | | #include <osl/diagnose.h> |
26 | | #include <fmtfsize.hxx> |
27 | | #include <fldbas.hxx> |
28 | | #include <uiitems.hxx> |
29 | | #include <viewopt.hxx> |
30 | | #include <cmdid.h> |
31 | | #include <view.hxx> |
32 | | #include <wrtsh.hxx> |
33 | | #include <textsh.hxx> |
34 | | #include <idxmrk.hxx> |
35 | | #include <toxmgr.hxx> |
36 | | #include <swabstdlg.hxx> |
37 | | #include <strings.hrc> |
38 | | #include <svl/whiter.hxx> |
39 | | |
40 | | #include <ndtxt.hxx> |
41 | | #include <fmtfld.hxx> |
42 | | #include <IDocumentFieldsAccess.hxx> |
43 | | |
44 | | void SwTextShell::ExecIdx(SfxRequest const &rReq) |
45 | 0 | { |
46 | 0 | const SfxItemSet* pArgs = rReq.GetArgs(); |
47 | 0 | const SfxPoolItem* pItem = nullptr; |
48 | 0 | const sal_uInt16 nSlot = rReq.GetSlot(); |
49 | 0 | if (pArgs) |
50 | 0 | pArgs->GetItemState(nSlot, false, &pItem); |
51 | |
|
52 | 0 | SfxViewFrame& rVFrame = GetView().GetViewFrame(); |
53 | |
|
54 | 0 | switch (nSlot) |
55 | 0 | { |
56 | 0 | case FN_EDIT_AUTH_ENTRY_DLG: |
57 | 0 | { |
58 | 0 | SwWrtShell& rShell = GetShell(); |
59 | |
|
60 | 0 | const bool bWasViewLocked = rShell.IsViewLocked(); |
61 | 0 | rShell.LockView(true); |
62 | |
|
63 | 0 | if (const SwField* const pCurrentField = rShell.GetCurField(); |
64 | 0 | !rShell.HasReadonlySel() && pCurrentField != nullptr |
65 | 0 | && pCurrentField->GetTyp()->Which() == SwFieldIds::TableOfAuthorities) |
66 | 0 | { |
67 | | // Since the cursor is on a bibliography mark (e.g. "[1]"), open the edit dialog as usual |
68 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
69 | 0 | ScopedVclPtr<VclAbstractDialog> pDlg( |
70 | 0 | pFact->CreateSwAutoMarkDialog(GetView().GetFrameWeld(), rShell)); |
71 | 0 | pDlg->Execute(); |
72 | 0 | } |
73 | 0 | else if (const SwTOXBase* const pCurrentTOX = rShell.GetCurTOX(); |
74 | 0 | pCurrentTOX != nullptr && pCurrentTOX->GetType() == TOX_AUTHORITIES |
75 | 0 | && (rShell.GetCursor()->GetPoint()->GetNode() |
76 | 0 | .FindSectionNode()->GetSection().GetType() |
77 | 0 | == SectionType::ToxContent)) |
78 | 0 | { |
79 | | // Since the cursor is in the bibliography table, find the first mark that would match the given row |
80 | 0 | const SwNode* const pTableRowNode = &rShell.GetCursor()->GetPoint()->GetNode(); |
81 | 0 | const OUString& rTableRowText |
82 | 0 | = static_cast<const SwTextNode*>(pTableRowNode)->GetText(); |
83 | |
|
84 | 0 | const SwFieldType* pAuthField |
85 | 0 | = rShell.GetDoc()->getIDocumentFieldsAccess().GetFieldType( |
86 | 0 | SwFieldIds::TableOfAuthorities, OUString(), false); |
87 | |
|
88 | 0 | if (pAuthField) |
89 | 0 | { |
90 | 0 | bool bMatchingMarkFound = false; |
91 | 0 | { |
92 | 0 | std::vector<SwFormatField*> vFields; |
93 | 0 | pAuthField->GatherFields(vFields); |
94 | 0 | for (auto pFormatField : vFields) |
95 | 0 | { |
96 | 0 | if (const SwField* pIteratedField = nullptr; |
97 | 0 | pFormatField != nullptr |
98 | 0 | && (pIteratedField = pFormatField->GetField()) != nullptr |
99 | 0 | && (pIteratedField->GetTyp()->Which() |
100 | 0 | == SwFieldIds::TableOfAuthorities)) |
101 | 0 | { |
102 | 0 | OUString sMarkText |
103 | 0 | = static_cast<const SwAuthorityField*>(pIteratedField) |
104 | 0 | ->GetAuthority(rShell.GetLayout(), |
105 | 0 | &pCurrentTOX->GetTOXForm()); |
106 | |
|
107 | 0 | if (sMarkText == rTableRowText) |
108 | 0 | { |
109 | | // Since the text generated from the mark would match the given row |
110 | | // move cursor to it, set bMatchingMarkFound and break |
111 | 0 | rShell.GotoFormatField(*pFormatField); |
112 | 0 | bMatchingMarkFound = true; |
113 | 0 | break; |
114 | 0 | } |
115 | 0 | } |
116 | 0 | } |
117 | 0 | } |
118 | |
|
119 | 0 | if (bMatchingMarkFound) |
120 | 0 | { |
121 | | // Since matching mark has been found and cursor has been moved to it, |
122 | | // open the edit dialog |
123 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
124 | 0 | ScopedVclPtr<VclAbstractDialog> pDlg( |
125 | 0 | pFact->CreateSwAutoMarkDialog(GetView().GetFrameWeld(), rShell)); |
126 | 0 | pDlg->Execute(); |
127 | | |
128 | | // Refresh TOX |
129 | 0 | rShell.GetCursor_()->GetPoint()->Assign(*pTableRowNode); |
130 | 0 | rShell.UpdateTableOf(*pCurrentTOX); |
131 | 0 | } |
132 | 0 | else |
133 | 0 | { |
134 | | // I think this ideally should be a pop-up warning, right? |
135 | 0 | SAL_WARN("sw", "No matching bibliography mark found. " |
136 | 0 | "This feature is only guaranteed to work if the bibliography table is up to date."); |
137 | 0 | } |
138 | 0 | } |
139 | 0 | } |
140 | | |
141 | 0 | if (!bWasViewLocked) |
142 | 0 | rShell.LockView(false); |
143 | 0 | } |
144 | 0 | break; |
145 | 0 | case FN_INSERT_AUTH_ENTRY_DLG: |
146 | 0 | { |
147 | | // no BASIC support |
148 | 0 | rVFrame.ToggleChildWindow(FN_INSERT_AUTH_ENTRY_DLG); |
149 | 0 | Invalidate(rReq.GetSlot()); |
150 | 0 | } |
151 | 0 | break; |
152 | 0 | case FN_INSERT_IDX_ENTRY_DLG: |
153 | 0 | { |
154 | 0 | rVFrame.ToggleChildWindow(FN_INSERT_IDX_ENTRY_DLG); |
155 | 0 | Invalidate(rReq.GetSlot()); |
156 | 0 | } |
157 | 0 | break; |
158 | 0 | case FN_EDIT_IDX_ENTRY_DLG: |
159 | 0 | { |
160 | 0 | SwTOXMgr aMgr(GetShellPtr()); |
161 | 0 | short nRet = RET_OK; |
162 | 0 | if(aMgr.GetTOXMarkCount() > 1) |
163 | 0 | { // Several marks, which should it be? |
164 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
165 | 0 | ScopedVclPtr<VclAbstractDialog> pMultDlg(pFact->CreateMultiTOXMarkDlg(GetView().GetFrameWeld(), aMgr)); |
166 | 0 | nRet = pMultDlg->Execute(); |
167 | 0 | } |
168 | 0 | if( nRet == RET_OK) |
169 | 0 | { |
170 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
171 | 0 | ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateIndexMarkModalDlg(GetView().GetFrameWeld(), GetShell(), aMgr.GetCurTOXMark())); |
172 | 0 | pDlg->Execute(); |
173 | 0 | } |
174 | 0 | break; |
175 | 0 | } |
176 | 0 | case FN_IDX_MARK_TO_IDX: |
177 | 0 | { |
178 | 0 | GetShell().GotoTOXMarkBase(); |
179 | 0 | break; |
180 | 0 | } |
181 | 0 | case FN_INSERT_MULTI_TOX: |
182 | 0 | { |
183 | 0 | SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_FRM_SIZE, RES_FRM_SIZE, |
184 | 0 | RES_LR_SPACE, RES_LR_SPACE, |
185 | 0 | RES_BACKGROUND, RES_BACKGROUND, |
186 | 0 | RES_COL, RES_COL, |
187 | 0 | XATTR_FILL_FIRST, XATTR_FILL_LAST, |
188 | 0 | SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE, |
189 | 0 | FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE>(GetPool())); |
190 | 0 | SwWrtShell& rSh = GetShell(); |
191 | 0 | SwRect aRect; |
192 | 0 | rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR); |
193 | |
|
194 | 0 | tools::Long nWidth = aRect.Width(); |
195 | 0 | aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth)); |
196 | | // Height = width for a more consistent preview (analogous to edit range) |
197 | 0 | aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth))); |
198 | 0 | const SwTOXBase* pCurTOX = nullptr; |
199 | 0 | bool bGlobal = false; |
200 | 0 | if(pItem) |
201 | 0 | { |
202 | 0 | pCurTOX = static_cast<const SwTOXBase*>(static_cast<const SwPtrItem*>(pItem)->GetValue()); |
203 | 0 | bGlobal = true; |
204 | 0 | } |
205 | 0 | else |
206 | 0 | pCurTOX = rSh.GetCurTOX(); |
207 | 0 | if(pCurTOX) |
208 | 0 | { |
209 | 0 | const SfxItemSet* pSet = pCurTOX->GetAttrSet(); |
210 | 0 | if(pSet) |
211 | 0 | aSet.Put(*pSet); |
212 | 0 | } |
213 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
214 | 0 | VclPtr<AbstractMultiTOXTabDialog> pDlg(pFact->CreateMultiTOXTabDialog( |
215 | 0 | GetView().GetFrameWeld(), aSet, rSh, const_cast<SwTOXBase*>(pCurTOX), |
216 | 0 | bGlobal)); |
217 | 0 | pDlg->StartExecuteAsync([pDlg](sal_Int32 /*nResult*/){ |
218 | 0 | pDlg->disposeOnce(); |
219 | 0 | }); |
220 | 0 | } |
221 | 0 | break; |
222 | 0 | case FN_REMOVE_CUR_TOX: |
223 | 0 | { |
224 | 0 | SwWrtShell& rSh = GetShell(); |
225 | 0 | const SwTOXBase* pBase = rSh.GetCurTOX(); |
226 | 0 | OSL_ENSURE(pBase, "no TOXBase to remove"); |
227 | 0 | if( pBase ) |
228 | 0 | rSh.DeleteTOX(*pBase, true); |
229 | 0 | } |
230 | 0 | break; |
231 | 0 | default: |
232 | 0 | OSL_ENSURE(false, "wrong dispatcher"); |
233 | 0 | return; |
234 | 0 | } |
235 | 0 | } |
236 | | |
237 | | void SwTextShell::GetIdxState(SfxItemSet &rSet) |
238 | 0 | { |
239 | 0 | SwWrtShell& rSh = GetShell(); |
240 | 0 | SfxViewFrame& rVFrame = GetView().GetViewFrame(); |
241 | 0 | SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>( |
242 | 0 | rVFrame.GetChildWindow(FN_INSERT_IDX_ENTRY_DLG)); |
243 | |
|
244 | 0 | SfxChildWindow* pAuthMark = rVFrame.GetChildWindow(FN_INSERT_AUTH_ENTRY_DLG); |
245 | |
|
246 | 0 | const bool bHtmlMode = 0 != ::GetHtmlMode( GetView().GetDocShell() ); |
247 | 0 | const SwTOXBase* pBase = nullptr; |
248 | 0 | if( bHtmlMode || nullptr != ( pBase = rSh.GetCurTOX()) ) |
249 | 0 | { |
250 | 0 | if( pBase ) |
251 | 0 | { |
252 | 0 | if(pBase->IsTOXBaseInReadonly()) |
253 | 0 | { |
254 | 0 | rSet.DisableItem( FN_INSERT_MULTI_TOX ); |
255 | 0 | } |
256 | 0 | } |
257 | |
|
258 | 0 | rSet.DisableItem( FN_EDIT_IDX_ENTRY_DLG ); |
259 | 0 | if(pBase == nullptr // tdf#72955: Hide the "Bibliography Entry" command if there is no TOX in the selection |
260 | 0 | || pBase->GetType() != TOX_AUTHORITIES // or if it is not a bibliography table |
261 | 0 | || (rSh.GetCursor()->GetPoint()->GetNode().FindSectionNode()->GetSection().GetType() != SectionType::ToxContent)) // or if it's the heading |
262 | 0 | rSet.DisableItem(FN_EDIT_AUTH_ENTRY_DLG); |
263 | |
|
264 | 0 | if(!pIdxMrk) |
265 | 0 | rSet.DisableItem( FN_INSERT_IDX_ENTRY_DLG ); |
266 | 0 | else |
267 | 0 | rSet.Put(SfxBoolItem(FN_INSERT_IDX_ENTRY_DLG, true)); |
268 | |
|
269 | 0 | if(!pAuthMark) |
270 | 0 | rSet.DisableItem( FN_INSERT_AUTH_ENTRY_DLG ); |
271 | 0 | else |
272 | 0 | rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, true)); |
273 | |
|
274 | 0 | if (pBase) |
275 | 0 | { |
276 | 0 | SfxWhichIter aIter(rSet); |
277 | 0 | if (aIter.FirstWhich() == FN_REMOVE_CUR_TOX) |
278 | 0 | { |
279 | 0 | const OUString sLabel = SwResId(STR_DELETEINDEX).replaceAll("%1", pBase->GetTypeName()); |
280 | 0 | rSet.Put(SfxStringItem(FN_REMOVE_CUR_TOX, sLabel)); |
281 | 0 | } |
282 | 0 | } |
283 | 0 | } |
284 | 0 | else if ( rSh.CursorInsideInputField() ) |
285 | 0 | { |
286 | 0 | rSet.DisableItem( FN_INSERT_IDX_ENTRY_DLG ); |
287 | 0 | rSet.DisableItem( FN_INSERT_AUTH_ENTRY_DLG ); |
288 | 0 | rSet.DisableItem( FN_EDIT_AUTH_ENTRY_DLG ); |
289 | 0 | rSet.DisableItem( FN_EDIT_IDX_ENTRY_DLG ); |
290 | 0 | rSet.DisableItem( FN_INSERT_MULTI_TOX ); |
291 | 0 | rSet.DisableItem( FN_REMOVE_CUR_TOX ); |
292 | 0 | } |
293 | 0 | else |
294 | 0 | { |
295 | |
|
296 | 0 | bool bEnableEdit = true; |
297 | 0 | bool bInReadonly = rSh.HasReadonlySel(); |
298 | 0 | if(bInReadonly) |
299 | 0 | bEnableEdit = false; |
300 | 0 | else |
301 | 0 | { |
302 | 0 | SwTOXMarks aArr; |
303 | 0 | rSh.GetCurTOXMarks( aArr ); |
304 | 0 | if( aArr.empty()) |
305 | 0 | bEnableEdit = false; |
306 | 0 | } |
307 | |
|
308 | 0 | if(!bEnableEdit) |
309 | 0 | rSet.DisableItem( FN_EDIT_IDX_ENTRY_DLG ); |
310 | |
|
311 | 0 | if(bInReadonly) |
312 | 0 | { |
313 | 0 | rSet.DisableItem(FN_INSERT_IDX_ENTRY_DLG); |
314 | 0 | rSet.DisableItem( FN_INSERT_MULTI_TOX ); |
315 | 0 | } |
316 | 0 | else |
317 | 0 | rSet.Put(SfxBoolItem(FN_INSERT_IDX_ENTRY_DLG, |
318 | 0 | nullptr != pIdxMrk)); |
319 | |
|
320 | 0 | SwField* pField = rSh.GetCurField(); |
321 | |
|
322 | 0 | if(bInReadonly) |
323 | 0 | rSet.DisableItem(FN_INSERT_AUTH_ENTRY_DLG); |
324 | 0 | else |
325 | 0 | rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, nullptr != pAuthMark)); |
326 | |
|
327 | 0 | if( bInReadonly || !pField || |
328 | 0 | pField->GetTyp()->Which() != SwFieldIds::TableOfAuthorities) |
329 | 0 | rSet.DisableItem(FN_EDIT_AUTH_ENTRY_DLG); |
330 | 0 | rSet.DisableItem(FN_REMOVE_CUR_TOX); |
331 | 0 | } |
332 | 0 | } |
333 | | |
334 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |