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 
39 {
40  const SfxItemSet *pArgs = rReq.GetArgs();
41  const SfxPoolItem* pItem = nullptr;
42  const sal_uInt16 nSlot = rReq.GetSlot();
43  if(pArgs)
44  pArgs->GetItemState(nSlot, false, &pItem );
45 
46  SfxViewFrame* pVFrame = GetView().GetViewFrame();
47 
48  switch( nSlot )
49  {
51  {
54  pDlg->Execute();
55  }
56  break;
58  {
59  // no BASIC support
61  Invalidate(rReq.GetSlot());
62  }
63  break;
65  {
67  Invalidate(rReq.GetSlot());
68  }
69  break;
71  {
72  SwTOXMgr aMgr(GetShellPtr());
73  short nRet = RET_OK;
74  if(aMgr.GetTOXMarkCount() > 1)
75  { // Several marks, which should it be?
78  nRet = pMultDlg->Execute();
79  }
80  if( nRet == RET_OK)
81  {
84  pDlg->Execute();
85  }
86  break;
87  }
88  case FN_IDX_MARK_TO_IDX:
89  {
91  break;
92  }
94  {
95  SfxItemSet aSet(
96  GetPool(),
97  svl::Items<
101  RES_COL, RES_COL,
103  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
105  SwWrtShell& rSh = GetShell();
106  SwRect aRect;
107  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
108 
109  tools::Long nWidth = aRect.Width();
111  // Height = width for a more consistent preview (analogous to edit range)
112  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
113  const SwTOXBase* pCurTOX = nullptr;
114  bool bGlobal = false;
115  if(pItem)
116  {
117  pCurTOX = static_cast<const SwTOXBase*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
118  bGlobal = true;
119  }
120  else
121  pCurTOX = rSh.GetCurTOX();
122  if(pCurTOX)
123  {
124  const SfxItemSet* pSet = pCurTOX->GetAttrSet();
125  if(pSet)
126  aSet.Put(*pSet);
127  }
130  GetView().GetFrameWeld(), aSet, rSh, const_cast<SwTOXBase*>(pCurTOX),
131  bGlobal));
132  pDlg->StartExecuteAsync([pDlg](sal_Int32 /*nResult*/){
133  pDlg->disposeOnce();
134  });
135  }
136  break;
137  case FN_REMOVE_CUR_TOX:
138  {
139  SwWrtShell& rSh = GetShell();
140  const SwTOXBase* pBase = rSh.GetCurTOX();
141  OSL_ENSURE(pBase, "no TOXBase to remove");
142  if( pBase )
143  rSh.DeleteTOX(*pBase, true);
144  }
145  break;
146  default:
147  OSL_ENSURE(false, "wrong dispatcher");
148  return;
149  }
150 }
151 
153 {
154  SwWrtShell& rSh = GetShell();
155  SfxViewFrame* pVFrame = GetView().GetViewFrame();
156  SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>(
158 
160 
161  const bool bHtmlMode = 0 != ::GetHtmlMode( GetView().GetDocShell() );
162  const SwTOXBase* pBase = nullptr;
163  if( bHtmlMode || nullptr != ( pBase = rSh.GetCurTOX()) )
164  {
165  if( pBase )
166  {
167  if(pBase->IsTOXBaseInReadonly())
168  {
170  }
171  }
172 
175 
176  if(!pIdxMrk)
178  else
180 
181  if(!pAuthMark)
183  else
185 
186  }
187  else if ( rSh.CursorInsideInputField() )
188  {
195  }
196  else
197  {
198 
199  bool bEnableEdit = true;
200  bool bInReadonly = rSh.HasReadonlySel();
201  if( rSh.HasSelection() || bInReadonly)
202  bEnableEdit = false;
203  else
204  {
206  rSh.GetCurTOXMarks( aArr );
207  if( aArr.empty())
208  bEnableEdit = false;
209  }
210 
211  if(!bEnableEdit)
213 
214  if(bInReadonly)
215  {
218  }
219  else
221  nullptr != pIdxMrk));
222 
223  SwField* pField = rSh.GetCurField();
224 
225  if(bInReadonly)
227  else
228  rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, nullptr != pAuthMark));
229 
230  if( bInReadonly || !pField ||
234  }
235 }
236 
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
virtual VclPtr< VclAbstractDialog > CreateIndexMarkModalDlg(weld::Window *pParent, SwWrtShell &rSh, SwTOXMark *pCurTOXMark)=0
const SfxItemSet * GetAttrSet() const
Definition: doctxm.cxx:2037
#define FN_IDX_MARK_TO_IDX
Definition: cmdid.h:701
virtual VclPtr< VclAbstractDialog > CreateSwAutoMarkDialog(weld::Window *pParent, SwWrtShell &rSh)=0
SfxChildWindow * GetChildWindow(sal_uInt16)
void ExecIdx(SfxRequest const &)
Definition: textidx.cxx:38
SwView & GetView()
Definition: basesh.hxx:59
#define FN_REMOVE_CUR_TOX
Definition: cmdid.h:506
static constexpr auto Items
void GetIdxState(SfxItemSet &)
Definition: textidx.cxx:152
std::string GetValue
constexpr TypedWhichId< SwFormatCol > RES_COL(109)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
SwWrtShell * GetShellPtr()
Definition: basesh.cxx:2768
SwWrtShell & GetShell()
Definition: basesh.cxx:2763
std::vector< SwTOXMark * > SwTOXMarks
Definition: tox.hxx:46
long Long
Base class of all fields.
Definition: fldbas.hxx:289
#define FN_INSERT_AUTH_ENTRY_DLG
Definition: cmdid.h:284
bool IsTOXBaseInReadonly() const
Definition: doctxm.cxx:2013
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
const SfxItemSet * GetArgs() const
virtual short Execute()=0
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
void ToggleChildWindow(sal_uInt16)
#define FN_EDIT_AUTH_ENTRY_DLG
Definition: cmdid.h:133
#define FN_EDIT_IDX_ENTRY_DLG
Definition: cmdid.h:74
SwField * GetCurField(const bool bIncludeInputFieldAtStart=false) const
Definition: crstrvl.cxx:908
void Width(tools::Long nNew)
Definition: swrect.hxx:186
const SwTOXBase * GetCurTOX() const
Get current listing before or at the Cursor.
Definition: edtox.cxx:191
SfxItemPool & GetPool() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
bool HasSelection() const
Definition: wrtsh.hxx:144
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define FN_INSERT_IDX_ENTRY_DLG
Definition: cmdid.h:221
virtual VclPtr< VclAbstractDialog > CreateMultiTOXMarkDlg(weld::Window *pParent, SwTOXMgr &rTOXMgr)=0
virtual VclPtr< AbstractMultiTOXTabDialog > CreateMultiTOXTabDialog(weld::Widget *pParent, const SfxItemSet &rSet, SwWrtShell &rShell, SwTOXBase *pCurTOX, bool bGlobal)=0
const SvxPageUsage aArr[]
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:354
constexpr sal_uInt16 XATTR_FILL_FIRST(XATTRSET_LINE+1)
sal_uInt16 GetTOXMarkCount() const
Definition: toxmgr.hxx:263
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
bool HasReadonlySel() const
Definition: crsrsh.cxx:3346
void GotoTOXMarkBase()
jump to index of TOXMark
Definition: crstrvl.cxx:370
SwFieldType * GetTyp() const
Definition: fldbas.hxx:392
void CalcBoundRect(SwRect &_orRect, const RndStdIds _nAnchorId, const sal_Int16 _eHoriRelOrient=css::text::RelOrientation::FRAME, const sal_Int16 _eVertRelOrient=css::text::RelOrientation::FRAME, const SwPosition *_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:691
SwTOXMark * GetCurTOXMark()
Definition: toxmgr.hxx:266
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
void DisableItem(sal_uInt16 nWhich)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
virtual void Invalidate(sal_uInt16 nId=0)
RET_OK
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
void GetCurTOXMarks(SwTOXMarks &rMarks) const
Get all marks at current SPoint.
Definition: edtox.cxx:87
constexpr sal_uInt16 XATTR_FILL_LAST(XATTR_FILLBACKGROUND)
#define FN_PARAM_TOX_TYPE
Definition: cmdid.h:810
Frame is variable in Var-direction.
#define FN_INSERT_MULTI_TOX
Definition: cmdid.h:283
SwFieldIds Which() const
Definition: fldbas.hxx:272
bool DeleteTOX(const SwTOXBase &rTOXBase, bool bDelNodes)
Definition: edtox.cxx:196
bool CursorInsideInputField() const
Definition: crstrvl.cxx:929