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>
40 #include <IDocumentFieldsAccess.hxx>
42 void SwTextShell::ExecIdx(SfxRequest
const &rReq
)
44 const SfxItemSet
* pArgs
= rReq
.GetArgs();
45 const SfxPoolItem
* pItem
= nullptr;
46 const sal_uInt16 nSlot
= rReq
.GetSlot();
48 pArgs
->GetItemState(nSlot
, false, &pItem
);
50 SfxViewFrame
& rVFrame
= GetView().GetViewFrame();
54 case FN_EDIT_AUTH_ENTRY_DLG
:
56 SwWrtShell
& rShell
= GetShell();
58 const bool bWasViewLocked
= rShell
.IsViewLocked();
59 rShell
.LockView(true);
61 if (const SwField
* const pCurrentField
= rShell
.GetCurField();
62 !rShell
.HasReadonlySel() && pCurrentField
!= nullptr
63 && pCurrentField
->GetTyp()->Which() == SwFieldIds::TableOfAuthorities
)
65 // Since the cursor is on a bibliography mark (e.g. "[1]"), open the edit dialog as usual
66 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
67 ScopedVclPtr
<VclAbstractDialog
> pDlg(
68 pFact
->CreateSwAutoMarkDialog(GetView().GetFrameWeld(), rShell
));
71 else if (const SwTOXBase
* const pCurrentTOX
= rShell
.GetCurTOX();
72 pCurrentTOX
!= nullptr && pCurrentTOX
->GetType() == TOX_AUTHORITIES
73 && (rShell
.GetCursor()->GetPoint()->GetNode()
74 .FindSectionNode()->GetSection().GetType()
75 == SectionType::ToxContent
))
77 // Since the cursor is in the bibliography table, find the first mark that would match the given row
78 const SwNode
* const pTableRowNode
= &rShell
.GetCursor()->GetPoint()->GetNode();
79 const OUString
& rTableRowText
80 = static_cast<const SwTextNode
*>(pTableRowNode
)->GetText();
82 const SwFieldType
* pAuthField
83 = rShell
.GetDoc()->getIDocumentFieldsAccess().GetFieldType(
84 SwFieldIds::TableOfAuthorities
, OUString(), false);
88 bool bMatchingMarkFound
= false;
90 std::vector
<SwFormatField
*> vFields
;
91 pAuthField
->GatherFields(vFields
);
92 for (auto pFormatField
: vFields
)
94 if (const SwField
* pIteratedField
= nullptr;
95 pFormatField
!= nullptr
96 && (pIteratedField
= pFormatField
->GetField()) != nullptr
97 && (pIteratedField
->GetTyp()->Which()
98 == SwFieldIds::TableOfAuthorities
))
101 = static_cast<const SwAuthorityField
*>(pIteratedField
)
102 ->GetAuthority(rShell
.GetLayout(),
103 &pCurrentTOX
->GetTOXForm());
105 if (sMarkText
== rTableRowText
)
107 // Since the text generated from the mark would match the given row
108 // move cursor to it, set bMatchingMarkFound and break
109 rShell
.GotoFormatField(*pFormatField
);
110 bMatchingMarkFound
= true;
117 if (bMatchingMarkFound
)
119 // Since matching mark has been found and cursor has been moved to it,
120 // open the edit dialog
121 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
122 ScopedVclPtr
<VclAbstractDialog
> pDlg(
123 pFact
->CreateSwAutoMarkDialog(GetView().GetFrameWeld(), rShell
));
127 rShell
.GetCursor_()->GetPoint()->Assign(*pTableRowNode
);
128 rShell
.UpdateTableOf(*pCurrentTOX
);
134 rShell
.LockView(false);
137 case FN_INSERT_AUTH_ENTRY_DLG
:
140 rVFrame
.ToggleChildWindow(FN_INSERT_AUTH_ENTRY_DLG
);
141 Invalidate(rReq
.GetSlot());
144 case FN_INSERT_IDX_ENTRY_DLG
:
146 rVFrame
.ToggleChildWindow(FN_INSERT_IDX_ENTRY_DLG
);
147 Invalidate(rReq
.GetSlot());
150 case FN_EDIT_IDX_ENTRY_DLG
:
152 SwTOXMgr
aMgr(GetShellPtr());
154 if(aMgr
.GetTOXMarkCount() > 1)
155 { // Several marks, which should it be?
156 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
157 ScopedVclPtr
<VclAbstractDialog
> pMultDlg(pFact
->CreateMultiTOXMarkDlg(GetView().GetFrameWeld(), aMgr
));
158 nRet
= pMultDlg
->Execute();
162 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
163 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateIndexMarkModalDlg(GetView().GetFrameWeld(), GetShell(), aMgr
.GetCurTOXMark()));
168 case FN_IDX_MARK_TO_IDX
:
170 GetShell().GotoTOXMarkBase();
173 case FN_INSERT_MULTI_TOX
:
176 RES_FRM_SIZE
, RES_FRM_SIZE
,
177 RES_LR_SPACE
, RES_LR_SPACE
,
178 RES_BACKGROUND
, RES_BACKGROUND
,
180 XATTR_FILL_FIRST
, XATTR_FILL_LAST
,
181 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
,
182 FN_PARAM_TOX_TYPE
, FN_PARAM_TOX_TYPE
> aSet( GetPool() );
183 SwWrtShell
& rSh
= GetShell();
185 rSh
.CalcBoundRect(aRect
, RndStdIds::FLY_AS_CHAR
);
187 tools::Long nWidth
= aRect
.Width();
188 aSet
.Put(SwFormatFrameSize(SwFrameSize::Variable
, nWidth
));
189 // Height = width for a more consistent preview (analogous to edit range)
190 aSet
.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE
, Size(nWidth
, nWidth
)));
191 const SwTOXBase
* pCurTOX
= nullptr;
192 bool bGlobal
= false;
195 pCurTOX
= static_cast<const SwTOXBase
*>(static_cast<const SwPtrItem
*>(pItem
)->GetValue());
199 pCurTOX
= rSh
.GetCurTOX();
202 const SfxItemSet
* pSet
= pCurTOX
->GetAttrSet();
206 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
207 VclPtr
<AbstractMultiTOXTabDialog
> pDlg(pFact
->CreateMultiTOXTabDialog(
208 GetView().GetFrameWeld(), aSet
, rSh
, const_cast<SwTOXBase
*>(pCurTOX
),
210 pDlg
->StartExecuteAsync([pDlg
](sal_Int32
/*nResult*/){
215 case FN_REMOVE_CUR_TOX
:
217 SwWrtShell
& rSh
= GetShell();
218 const SwTOXBase
* pBase
= rSh
.GetCurTOX();
219 OSL_ENSURE(pBase
, "no TOXBase to remove");
221 rSh
.DeleteTOX(*pBase
, true);
225 OSL_ENSURE(false, "wrong dispatcher");
230 void SwTextShell::GetIdxState(SfxItemSet
&rSet
)
232 SwWrtShell
& rSh
= GetShell();
233 SfxViewFrame
& rVFrame
= GetView().GetViewFrame();
234 SwInsertIdxMarkWrapper
*pIdxMrk
= static_cast<SwInsertIdxMarkWrapper
*>(
235 rVFrame
.GetChildWindow(FN_INSERT_IDX_ENTRY_DLG
));
237 SfxChildWindow
* pAuthMark
= rVFrame
.GetChildWindow(FN_INSERT_AUTH_ENTRY_DLG
);
239 const bool bHtmlMode
= 0 != ::GetHtmlMode( GetView().GetDocShell() );
240 const SwTOXBase
* pBase
= nullptr;
241 if( bHtmlMode
|| nullptr != ( pBase
= rSh
.GetCurTOX()) )
245 if(pBase
->IsTOXBaseInReadonly())
247 rSet
.DisableItem( FN_INSERT_MULTI_TOX
);
251 rSet
.DisableItem( FN_EDIT_IDX_ENTRY_DLG
);
252 if(pBase
== nullptr // tdf#72955: Hide the "Bibliography Entry" command if there is no TOX in the selection
253 || pBase
->GetType() != TOX_AUTHORITIES
// or if it is not a bibliography table
254 || (rSh
.GetCursor()->GetPoint()->GetNode().FindSectionNode()->GetSection().GetType() != SectionType::ToxContent
)) // or if it's the heading
255 rSet
.DisableItem(FN_EDIT_AUTH_ENTRY_DLG
);
258 rSet
.DisableItem( FN_INSERT_IDX_ENTRY_DLG
);
260 rSet
.Put(SfxBoolItem(FN_INSERT_IDX_ENTRY_DLG
, true));
263 rSet
.DisableItem( FN_INSERT_AUTH_ENTRY_DLG
);
265 rSet
.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG
, true));
268 else if ( rSh
.CursorInsideInputField() )
270 rSet
.DisableItem( FN_INSERT_IDX_ENTRY_DLG
);
271 rSet
.DisableItem( FN_INSERT_AUTH_ENTRY_DLG
);
272 rSet
.DisableItem( FN_EDIT_AUTH_ENTRY_DLG
);
273 rSet
.DisableItem( FN_EDIT_IDX_ENTRY_DLG
);
274 rSet
.DisableItem( FN_INSERT_MULTI_TOX
);
275 rSet
.DisableItem( FN_REMOVE_CUR_TOX
);
280 bool bEnableEdit
= true;
281 bool bInReadonly
= rSh
.HasReadonlySel();
287 rSh
.GetCurTOXMarks( aArr
);
293 rSet
.DisableItem( FN_EDIT_IDX_ENTRY_DLG
);
297 rSet
.DisableItem(FN_INSERT_IDX_ENTRY_DLG
);
298 rSet
.DisableItem( FN_INSERT_MULTI_TOX
);
301 rSet
.Put(SfxBoolItem(FN_INSERT_IDX_ENTRY_DLG
,
302 nullptr != pIdxMrk
));
304 SwField
* pField
= rSh
.GetCurField();
307 rSet
.DisableItem(FN_INSERT_AUTH_ENTRY_DLG
);
309 rSet
.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG
, nullptr != pAuthMark
));
311 if( bInReadonly
|| !pField
||
312 pField
->GetTyp()->Which() != SwFieldIds::TableOfAuthorities
)
313 rSet
.DisableItem(FN_EDIT_AUTH_ENTRY_DLG
);
314 rSet
.DisableItem(FN_REMOVE_CUR_TOX
);
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */