1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
28 #include <uiitems.hxx>
29 #include <viewopt.hxx>
36 #include <swabstdlg.hxx>
37 #include <strings.hrc>
38 #include <svl/whiter.hxx>
42 #include <IDocumentFieldsAccess.hxx>
44 void SwTextShell::ExecIdx(SfxRequest
const &rReq
)
46 const SfxItemSet
* pArgs
= rReq
.GetArgs();
47 const SfxPoolItem
* pItem
= nullptr;
48 const sal_uInt16 nSlot
= rReq
.GetSlot();
50 pArgs
->GetItemState(nSlot
, false, &pItem
);
52 SfxViewFrame
& rVFrame
= GetView().GetViewFrame();
56 case FN_EDIT_AUTH_ENTRY_DLG
:
58 SwWrtShell
& rShell
= GetShell();
60 const bool bWasViewLocked
= rShell
.IsViewLocked();
61 rShell
.LockView(true);
63 if (const SwField
* const pCurrentField
= rShell
.GetCurField();
64 !rShell
.HasReadonlySel() && pCurrentField
!= nullptr
65 && pCurrentField
->GetTyp()->Which() == SwFieldIds::TableOfAuthorities
)
67 // Since the cursor is on a bibliography mark (e.g. "[1]"), open the edit dialog as usual
68 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
69 ScopedVclPtr
<VclAbstractDialog
> pDlg(
70 pFact
->CreateSwAutoMarkDialog(GetView().GetFrameWeld(), rShell
));
73 else if (const SwTOXBase
* const pCurrentTOX
= rShell
.GetCurTOX();
74 pCurrentTOX
!= nullptr && pCurrentTOX
->GetType() == TOX_AUTHORITIES
75 && (rShell
.GetCursor()->GetPoint()->GetNode()
76 .FindSectionNode()->GetSection().GetType()
77 == SectionType::ToxContent
))
79 // Since the cursor is in the bibliography table, find the first mark that would match the given row
80 const SwNode
* const pTableRowNode
= &rShell
.GetCursor()->GetPoint()->GetNode();
81 const OUString
& rTableRowText
82 = static_cast<const SwTextNode
*>(pTableRowNode
)->GetText();
84 const SwFieldType
* pAuthField
85 = rShell
.GetDoc()->getIDocumentFieldsAccess().GetFieldType(
86 SwFieldIds::TableOfAuthorities
, OUString(), false);
90 bool bMatchingMarkFound
= false;
92 std::vector
<SwFormatField
*> vFields
;
93 pAuthField
->GatherFields(vFields
);
94 for (auto pFormatField
: vFields
)
96 if (const SwField
* pIteratedField
= nullptr;
97 pFormatField
!= nullptr
98 && (pIteratedField
= pFormatField
->GetField()) != nullptr
99 && (pIteratedField
->GetTyp()->Which()
100 == SwFieldIds::TableOfAuthorities
))
103 = static_cast<const SwAuthorityField
*>(pIteratedField
)
104 ->GetAuthority(rShell
.GetLayout(),
105 &pCurrentTOX
->GetTOXForm());
107 if (sMarkText
== rTableRowText
)
109 // Since the text generated from the mark would match the given row
110 // move cursor to it, set bMatchingMarkFound and break
111 rShell
.GotoFormatField(*pFormatField
);
112 bMatchingMarkFound
= true;
119 if (bMatchingMarkFound
)
121 // Since matching mark has been found and cursor has been moved to it,
122 // open the edit dialog
123 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
124 ScopedVclPtr
<VclAbstractDialog
> pDlg(
125 pFact
->CreateSwAutoMarkDialog(GetView().GetFrameWeld(), rShell
));
129 rShell
.GetCursor_()->GetPoint()->Assign(*pTableRowNode
);
130 rShell
.UpdateTableOf(*pCurrentTOX
);
134 // I think this ideally should be a pop-up warning, right?
135 SAL_WARN("sw", "No matching bibliography mark found. "
136 "This feature is only guaranteed to work if the bibliography table is up to date.");
142 rShell
.LockView(false);
145 case FN_INSERT_AUTH_ENTRY_DLG
:
148 rVFrame
.ToggleChildWindow(FN_INSERT_AUTH_ENTRY_DLG
);
149 Invalidate(rReq
.GetSlot());
152 case FN_INSERT_IDX_ENTRY_DLG
:
154 rVFrame
.ToggleChildWindow(FN_INSERT_IDX_ENTRY_DLG
);
155 Invalidate(rReq
.GetSlot());
158 case FN_EDIT_IDX_ENTRY_DLG
:
160 SwTOXMgr
aMgr(GetShellPtr());
162 if(aMgr
.GetTOXMarkCount() > 1)
163 { // Several marks, which should it be?
164 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
165 ScopedVclPtr
<VclAbstractDialog
> pMultDlg(pFact
->CreateMultiTOXMarkDlg(GetView().GetFrameWeld(), aMgr
));
166 nRet
= pMultDlg
->Execute();
170 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
171 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateIndexMarkModalDlg(GetView().GetFrameWeld(), GetShell(), aMgr
.GetCurTOXMark()));
176 case FN_IDX_MARK_TO_IDX
:
178 GetShell().GotoTOXMarkBase();
181 case FN_INSERT_MULTI_TOX
:
184 RES_FRM_SIZE
, RES_FRM_SIZE
,
185 RES_LR_SPACE
, RES_LR_SPACE
,
186 RES_BACKGROUND
, RES_BACKGROUND
,
188 XATTR_FILL_FIRST
, XATTR_FILL_LAST
,
189 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
,
190 FN_PARAM_TOX_TYPE
, FN_PARAM_TOX_TYPE
> aSet( GetPool() );
191 SwWrtShell
& rSh
= GetShell();
193 rSh
.CalcBoundRect(aRect
, RndStdIds::FLY_AS_CHAR
);
195 tools::Long nWidth
= aRect
.Width();
196 aSet
.Put(SwFormatFrameSize(SwFrameSize::Variable
, nWidth
));
197 // Height = width for a more consistent preview (analogous to edit range)
198 aSet
.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE
, Size(nWidth
, nWidth
)));
199 const SwTOXBase
* pCurTOX
= nullptr;
200 bool bGlobal
= false;
203 pCurTOX
= static_cast<const SwTOXBase
*>(static_cast<const SwPtrItem
*>(pItem
)->GetValue());
207 pCurTOX
= rSh
.GetCurTOX();
210 const SfxItemSet
* pSet
= pCurTOX
->GetAttrSet();
214 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
215 VclPtr
<AbstractMultiTOXTabDialog
> pDlg(pFact
->CreateMultiTOXTabDialog(
216 GetView().GetFrameWeld(), aSet
, rSh
, const_cast<SwTOXBase
*>(pCurTOX
),
218 pDlg
->StartExecuteAsync([pDlg
](sal_Int32
/*nResult*/){
223 case FN_REMOVE_CUR_TOX
:
225 SwWrtShell
& rSh
= GetShell();
226 const SwTOXBase
* pBase
= rSh
.GetCurTOX();
227 OSL_ENSURE(pBase
, "no TOXBase to remove");
229 rSh
.DeleteTOX(*pBase
, true);
233 OSL_ENSURE(false, "wrong dispatcher");
238 void SwTextShell::GetIdxState(SfxItemSet
&rSet
)
240 SwWrtShell
& rSh
= GetShell();
241 SfxViewFrame
& rVFrame
= GetView().GetViewFrame();
242 SwInsertIdxMarkWrapper
*pIdxMrk
= static_cast<SwInsertIdxMarkWrapper
*>(
243 rVFrame
.GetChildWindow(FN_INSERT_IDX_ENTRY_DLG
));
245 SfxChildWindow
* pAuthMark
= rVFrame
.GetChildWindow(FN_INSERT_AUTH_ENTRY_DLG
);
247 const bool bHtmlMode
= 0 != ::GetHtmlMode( GetView().GetDocShell() );
248 const SwTOXBase
* pBase
= nullptr;
249 if( bHtmlMode
|| nullptr != ( pBase
= rSh
.GetCurTOX()) )
253 if(pBase
->IsTOXBaseInReadonly())
255 rSet
.DisableItem( FN_INSERT_MULTI_TOX
);
259 rSet
.DisableItem( FN_EDIT_IDX_ENTRY_DLG
);
260 if(pBase
== nullptr // tdf#72955: Hide the "Bibliography Entry" command if there is no TOX in the selection
261 || pBase
->GetType() != TOX_AUTHORITIES
// or if it is not a bibliography table
262 || (rSh
.GetCursor()->GetPoint()->GetNode().FindSectionNode()->GetSection().GetType() != SectionType::ToxContent
)) // or if it's the heading
263 rSet
.DisableItem(FN_EDIT_AUTH_ENTRY_DLG
);
266 rSet
.DisableItem( FN_INSERT_IDX_ENTRY_DLG
);
268 rSet
.Put(SfxBoolItem(FN_INSERT_IDX_ENTRY_DLG
, true));
271 rSet
.DisableItem( FN_INSERT_AUTH_ENTRY_DLG
);
273 rSet
.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG
, true));
277 SfxWhichIter
aIter(rSet
);
278 if (aIter
.FirstWhich() == FN_REMOVE_CUR_TOX
)
280 const OUString sLabel
= SwResId(STR_DELETEINDEX
).replaceAll("%1", pBase
->GetTypeName());
281 rSet
.Put(SfxStringItem(FN_REMOVE_CUR_TOX
, sLabel
));
285 else if ( rSh
.CursorInsideInputField() )
287 rSet
.DisableItem( FN_INSERT_IDX_ENTRY_DLG
);
288 rSet
.DisableItem( FN_INSERT_AUTH_ENTRY_DLG
);
289 rSet
.DisableItem( FN_EDIT_AUTH_ENTRY_DLG
);
290 rSet
.DisableItem( FN_EDIT_IDX_ENTRY_DLG
);
291 rSet
.DisableItem( FN_INSERT_MULTI_TOX
);
292 rSet
.DisableItem( FN_REMOVE_CUR_TOX
);
297 bool bEnableEdit
= true;
298 bool bInReadonly
= rSh
.HasReadonlySel();
304 rSh
.GetCurTOXMarks( aArr
);
310 rSet
.DisableItem( FN_EDIT_IDX_ENTRY_DLG
);
314 rSet
.DisableItem(FN_INSERT_IDX_ENTRY_DLG
);
315 rSet
.DisableItem( FN_INSERT_MULTI_TOX
);
318 rSet
.Put(SfxBoolItem(FN_INSERT_IDX_ENTRY_DLG
,
319 nullptr != pIdxMrk
));
321 SwField
* pField
= rSh
.GetCurField();
324 rSet
.DisableItem(FN_INSERT_AUTH_ENTRY_DLG
);
326 rSet
.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG
, nullptr != pAuthMark
));
328 if( bInReadonly
|| !pField
||
329 pField
->GetTyp()->Which() != SwFieldIds::TableOfAuthorities
)
330 rSet
.DisableItem(FN_EDIT_AUTH_ENTRY_DLG
);
331 rSet
.DisableItem(FN_REMOVE_CUR_TOX
);
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */