LibreOffice Module sw (master) 1
textidx.cxx
Go to the documentation of this file.
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
38#include <ndtxt.hxx>
39#include <fmtfld.hxx>
41
43{
44 const SfxItemSet* pArgs = rReq.GetArgs();
45 const SfxPoolItem* pItem = nullptr;
46 const sal_uInt16 nSlot = rReq.GetSlot();
47 if (pArgs)
48 pArgs->GetItemState(nSlot, false, &pItem);
49
50 SfxViewFrame& rVFrame = GetView().GetViewFrame();
51
52 switch (nSlot)
53 {
55 {
56 SwWrtShell& rShell = GetShell();
57
58 const bool bWasViewLocked = rShell.IsViewLocked();
59 rShell.LockView(true);
60
61 if (const SwField* const pCurrentField = rShell.GetCurField();
62 !rShell.HasReadonlySel() && pCurrentField != nullptr
63 && pCurrentField->GetTyp()->Which() == SwFieldIds::TableOfAuthorities)
64 {
65 // Since the cursor is on a bibliography mark (e.g. "[1]"), open the edit dialog as usual
68 pFact->CreateSwAutoMarkDialog(GetView().GetFrameWeld(), rShell));
69 pDlg->Execute();
70 }
71 else if (const SwTOXBase* const pCurrentTOX = rShell.GetCurTOX();
72 pCurrentTOX != nullptr && pCurrentTOX->GetType() == TOX_AUTHORITIES
73 && (rShell.GetCursor()->GetPoint()->GetNode()
76 {
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();
81
82 const SwFieldType* pAuthField
84 SwFieldIds::TableOfAuthorities, OUString(), false);
85
86 if (pAuthField)
87 {
88 bool bMatchingMarkFound = false;
89 {
90 std::vector<SwFormatField*> vFields;
91 pAuthField->GatherFields(vFields);
92 for (auto pFormatField : vFields)
93 {
94 if (const SwField* pIteratedField = nullptr;
95 pFormatField != nullptr
96 && (pIteratedField = pFormatField->GetField()) != nullptr
97 && (pIteratedField->GetTyp()->Which()
99 {
100 OUString sMarkText
101 = static_cast<const SwAuthorityField*>(pIteratedField)
102 ->GetAuthority(rShell.GetLayout(),
103 &pCurrentTOX->GetTOXForm());
104
105 if (sMarkText == rTableRowText)
106 {
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;
111 break;
112 }
113 }
114 }
115 }
116
117 if (bMatchingMarkFound)
118 {
119 // Since matching mark has been found and cursor has been moved to it,
120 // open the edit dialog
123 pFact->CreateSwAutoMarkDialog(GetView().GetFrameWeld(), rShell));
124 pDlg->Execute();
125
126 // Refresh TOX
127 rShell.GetCursor_()->GetPoint()->Assign(*pTableRowNode);
128 rShell.UpdateTableOf(*pCurrentTOX);
129 }
130 }
131 }
132
133 if (!bWasViewLocked)
134 rShell.LockView(false);
135 }
136 break;
138 {
139 // no BASIC support
141 Invalidate(rReq.GetSlot());
142 }
143 break;
145 {
147 Invalidate(rReq.GetSlot());
148 }
149 break;
151 {
152 SwTOXMgr aMgr(GetShellPtr());
153 short nRet = RET_OK;
154 if(aMgr.GetTOXMarkCount() > 1)
155 { // Several marks, which should it be?
158 nRet = pMultDlg->Execute();
159 }
160 if( nRet == RET_OK)
161 {
164 pDlg->Execute();
165 }
166 break;
167 }
169 {
171 break;
172 }
174 {
181 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
183 SwWrtShell& rSh = GetShell();
184 SwRect aRect;
185 rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
186
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;
193 if(pItem)
194 {
195 pCurTOX = static_cast<const SwTOXBase*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
196 bGlobal = true;
197 }
198 else
199 pCurTOX = rSh.GetCurTOX();
200 if(pCurTOX)
201 {
202 const SfxItemSet* pSet = pCurTOX->GetAttrSet();
203 if(pSet)
204 aSet.Put(*pSet);
205 }
208 GetView().GetFrameWeld(), aSet, rSh, const_cast<SwTOXBase*>(pCurTOX),
209 bGlobal));
210 pDlg->StartExecuteAsync([pDlg](sal_Int32 /*nResult*/){
211 pDlg->disposeOnce();
212 });
213 }
214 break;
216 {
217 SwWrtShell& rSh = GetShell();
218 const SwTOXBase* pBase = rSh.GetCurTOX();
219 OSL_ENSURE(pBase, "no TOXBase to remove");
220 if( pBase )
221 rSh.DeleteTOX(*pBase, true);
222 }
223 break;
224 default:
225 OSL_ENSURE(false, "wrong dispatcher");
226 return;
227 }
228}
229
231{
232 SwWrtShell& rSh = GetShell();
233 SfxViewFrame& rVFrame = GetView().GetViewFrame();
234 SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>(
236
238
239 const bool bHtmlMode = 0 != ::GetHtmlMode( GetView().GetDocShell() );
240 const SwTOXBase* pBase = nullptr;
241 if( bHtmlMode || nullptr != ( pBase = rSh.GetCurTOX()) )
242 {
243 if( pBase )
244 {
245 if(pBase->IsTOXBaseInReadonly())
246 {
248 }
249 }
250
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
256
257 if(!pIdxMrk)
259 else
261
262 if(!pAuthMark)
264 else
266
267 }
268 else if ( rSh.CursorInsideInputField() )
269 {
276 }
277 else
278 {
279
280 bool bEnableEdit = true;
281 bool bInReadonly = rSh.HasReadonlySel();
282 if(bInReadonly)
283 bEnableEdit = false;
284 else
285 {
287 rSh.GetCurTOXMarks( aArr );
288 if( aArr.empty())
289 bEnableEdit = false;
290 }
291
292 if(!bEnableEdit)
294
295 if(bInReadonly)
296 {
299 }
300 else
302 nullptr != pIdxMrk));
303
304 SwField* pField = rSh.GetCurField();
305
306 if(bInReadonly)
308 else
309 rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, nullptr != pAuthMark));
310
311 if( bInReadonly || !pField ||
315 }
316}
317
318/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const =0
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void DisableItem(sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
SfxItemPool & GetPool() const
virtual void Invalidate(sal_uInt16 nId=0)
void ToggleChildWindow(sal_uInt16)
SfxChildWindow * GetChildWindow(sal_uInt16)
SfxViewFrame & GetViewFrame() const
virtual VclPtr< AbstractMultiTOXTabDialog > CreateMultiTOXTabDialog(weld::Widget *pParent, const SfxItemSet &rSet, SwWrtShell &rShell, SwTOXBase *pCurTOX, bool bGlobal)=0
virtual VclPtr< VclAbstractDialog > CreateMultiTOXMarkDlg(weld::Window *pParent, SwTOXMgr &rTOXMgr)=0
virtual VclPtr< VclAbstractDialog > CreateSwAutoMarkDialog(weld::Window *pParent, SwWrtShell &rSh)=0
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
virtual VclPtr< VclAbstractDialog > CreateIndexMarkModalDlg(weld::Window *pParent, SwWrtShell &rSh, SwTOXMark *pCurTOXMark)=0
Represents an inserted bibliography entry, created using Insert -> Table of Contents and Index -> Bib...
Definition: authfld.hxx:161
SwWrtShell & GetShell()
Definition: basesh.cxx:3001
SwView & GetView()
Definition: basesh.hxx:59
SwWrtShell * GetShellPtr()
Definition: basesh.cxx:3006
void GotoTOXMarkBase()
jump to index of TOXMark
Definition: crstrvl.cxx:362
SwShellCursor * GetCursor_()
Definition: crsrsh.hxx:343
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:194
bool CursorInsideInputField() const
Definition: crstrvl.cxx:1094
SwField * GetCurField(const bool bIncludeInputFieldAtStart=false) const
Definition: crstrvl.cxx:1073
bool HasReadonlySel(bool isReplace=false) const
Definition: crsrsh.cxx:3662
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:371
const SwTOXBase * GetCurTOX() const
Get current listing before or at the Cursor.
Definition: edtox.cxx:191
bool DeleteTOX(const SwTOXBase &rTOXBase, bool bDelNodes)
Definition: edtox.cxx:196
void GetCurTOXMarks(SwTOXMarks &rMarks) const
Get all marks at current SPoint.
Definition: edtox.cxx:87
void CalcBoundRect(SwRect &_orRect, const RndStdIds _nAnchorId, const sal_Int16 _eHoriRelOrient=css::text::RelOrientation::FRAME, const sal_Int16 _eVertRelOrient=css::text::RelOrientation::FRAME, const SwFormatAnchor *_pToCharContentPos=nullptr, const bool _bFollowTextFlow=false, bool _bMirror=false, Point *_opRef=nullptr, Size *_opPercent=nullptr, const SwFormatFrameSize *pFormatFrameSize=nullptr) const
i#17567 - adjustments to allow negative vertical positions for fly frames anchored to paragraph or to...
Definition: fews.cxx:690
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:247
SwFieldIds Which() const
Definition: fldbas.hxx:276
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:205
Base class of all fields.
Definition: fldbas.hxx:296
SwFieldType * GetTyp() const
Definition: fldbas.hxx:402
Base class of the Writer document model elements.
Definition: node.hxx:98
SwSectionNode * FindSectionNode()
Search section node, in which it is.
Definition: ndsect.cxx:968
const SwPosition * GetPoint() const
Definition: pam.hxx:253
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Width(tools::Long nNew)
Definition: swrect.hxx:189
const SwSection & GetSection() const
Definition: node.hxx:590
SectionType GetType() const
Definition: section.hxx:173
const SfxItemSet * GetAttrSet() const
Definition: doctxm.cxx:2119
TOXTypes GetType() const
Definition: tox.hxx:722
bool IsTOXBaseInReadonly() const
Definition: doctxm.cxx:2095
Built on top of SwWrtShell, provides functionality to insert, update or perform other actions on vari...
Definition: toxmgr.hxx:231
SwTOXMark * GetCurTOXMark()
Definition: toxmgr.hxx:270
sal_uInt16 GetTOXMarkCount() const
Definition: toxmgr.hxx:267
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
void GetIdxState(SfxItemSet &)
Definition: textidx.cxx:230
void ExecIdx(SfxRequest const &)
Definition: textidx.cxx:42
bool IsViewLocked() const
Definition: viewsh.hxx:490
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2163
SwDoc * GetDoc() const
Definition: viewsh.hxx:308
void LockView(bool b)
Definition: viewsh.hxx:491
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void GotoFormatField(const SwFormatField &rField)
Definition: move.cxx:740
void UpdateTableOf(const SwTOXBase &rTOX, const SfxItemSet *pSet=nullptr)
Definition: wrtsh2.cxx:331
#define FN_REMOVE_CUR_TOX
Definition: cmdid.h:539
#define FN_EDIT_AUTH_ENTRY_DLG
Definition: cmdid.h:139
#define FN_INSERT_IDX_ENTRY_DLG
Definition: cmdid.h:240
#define FN_INSERT_AUTH_ENTRY_DLG
Definition: cmdid.h:304
#define FN_EDIT_IDX_ENTRY_DLG
Definition: cmdid.h:82
#define FN_IDX_MARK_TO_IDX
Definition: cmdid.h:739
#define FN_PARAM_TOX_TYPE
Definition: cmdid.h:843
#define FN_INSERT_MULTI_TOX
Definition: cmdid.h:303
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
@ TableOfAuthorities
@ Variable
Frame is variable in Var-direction.
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
constexpr TypedWhichId< SwFormatCol > RES_COL(115)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(111)
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(97)
const SvxPageUsage aArr[]
long Long
const char GetValue[]
static SfxItemSet & rSet
SwNode & GetNode() const
Definition: pam.hxx:81
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:231
std::vector< SwTOXMark * > SwTOXMarks
Definition: tox.hxx:46
@ TOX_AUTHORITIES
Definition: toxe.hxx:47
RET_OK
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:415
constexpr sal_uInt16 XATTR_FILL_FIRST(XATTRSET_LINE+1)
constexpr sal_uInt16 XATTR_FILL_LAST(XATTR_FILLUSESLIDEBACKGROUND)