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  {
101  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
102  FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE> aSet( GetPool() );
103  SwWrtShell& rSh = GetShell();
104  SwRect aRect;
105  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
106 
107  tools::Long nWidth = aRect.Width();
108  aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth));
109  // Height = width for a more consistent preview (analogous to edit range)
110  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
111  const SwTOXBase* pCurTOX = nullptr;
112  bool bGlobal = false;
113  if(pItem)
114  {
115  pCurTOX = static_cast<const SwTOXBase*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
116  bGlobal = true;
117  }
118  else
119  pCurTOX = rSh.GetCurTOX();
120  if(pCurTOX)
121  {
122  const SfxItemSet* pSet = pCurTOX->GetAttrSet();
123  if(pSet)
124  aSet.Put(*pSet);
125  }
128  GetView().GetFrameWeld(), aSet, rSh, const_cast<SwTOXBase*>(pCurTOX),
129  bGlobal));
130  pDlg->StartExecuteAsync([pDlg](sal_Int32 /*nResult*/){
131  pDlg->disposeOnce();
132  });
133  }
134  break;
135  case FN_REMOVE_CUR_TOX:
136  {
137  SwWrtShell& rSh = GetShell();
138  const SwTOXBase* pBase = rSh.GetCurTOX();
139  OSL_ENSURE(pBase, "no TOXBase to remove");
140  if( pBase )
141  rSh.DeleteTOX(*pBase, true);
142  }
143  break;
144  default:
145  OSL_ENSURE(false, "wrong dispatcher");
146  return;
147  }
148 }
149 
151 {
152  SwWrtShell& rSh = GetShell();
153  SfxViewFrame* pVFrame = GetView().GetViewFrame();
154  SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>(
156 
158 
159  const bool bHtmlMode = 0 != ::GetHtmlMode( GetView().GetDocShell() );
160  const SwTOXBase* pBase = nullptr;
161  if( bHtmlMode || nullptr != ( pBase = rSh.GetCurTOX()) )
162  {
163  if( pBase )
164  {
165  if(pBase->IsTOXBaseInReadonly())
166  {
168  }
169  }
170 
173 
174  if(!pIdxMrk)
176  else
178 
179  if(!pAuthMark)
181  else
183 
184  }
185  else if ( rSh.CursorInsideInputField() )
186  {
193  }
194  else
195  {
196 
197  bool bEnableEdit = true;
198  bool bInReadonly = rSh.HasReadonlySel();
199  if( rSh.HasSelection() || bInReadonly)
200  bEnableEdit = false;
201  else
202  {
204  rSh.GetCurTOXMarks( aArr );
205  if( aArr.empty())
206  bEnableEdit = false;
207  }
208 
209  if(!bEnableEdit)
211 
212  if(bInReadonly)
213  {
216  }
217  else
219  nullptr != pIdxMrk));
220 
221  SwField* pField = rSh.GetCurField();
222 
223  if(bInReadonly)
225  else
226  rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, nullptr != pAuthMark));
227 
228  if( bInReadonly || !pField ||
232  }
233 }
234 
235 /* 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:2115
#define FN_IDX_MARK_TO_IDX
Definition: cmdid.h:716
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:517
void GetIdxState(SfxItemSet &)
Definition: textidx.cxx:150
std::string GetValue
constexpr TypedWhichId< SwFormatCol > RES_COL(109)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
SwWrtShell * GetShellPtr()
Definition: basesh.cxx:2825
SwWrtShell & GetShell()
Definition: basesh.cxx:2820
std::vector< SwTOXMark * > SwTOXMarks
Definition: tox.hxx:44
long Long
Base class of all fields.
Definition: fldbas.hxx:291
#define FN_INSERT_AUTH_ENTRY_DLG
Definition: cmdid.h:295
bool IsTOXBaseInReadonly() const
Definition: doctxm.cxx:2091
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:96
void ToggleChildWindow(sal_uInt16)
#define FN_EDIT_AUTH_ENTRY_DLG
Definition: cmdid.h:140
#define FN_EDIT_IDX_ENTRY_DLG
Definition: cmdid.h:81
SwField * GetCurField(const bool bIncludeInputFieldAtStart=false) const
Definition: crstrvl.cxx:974
void Width(tools::Long nNew)
Definition: swrect.hxx:189
const SwTOXBase * GetCurTOX() const
Get current listing before or at the Cursor.
Definition: edtox.cxx:192
SfxItemPool & GetPool() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
bool HasSelection() const
Definition: wrtsh.hxx:147
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define FN_INSERT_IDX_ENTRY_DLG
Definition: cmdid.h:232
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:267
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
bool HasReadonlySel() const
Definition: crsrsh.cxx:3355
void GotoTOXMarkBase()
jump to index of TOXMark
Definition: crstrvl.cxx:371
SwFieldType * GetTyp() const
Definition: fldbas.hxx:398
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:270
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:88
constexpr sal_uInt16 XATTR_FILL_LAST(XATTR_FILLBACKGROUND)
#define FN_PARAM_TOX_TYPE
Definition: cmdid.h:820
Frame is variable in Var-direction.
#define FN_INSERT_MULTI_TOX
Definition: cmdid.h:294
SwFieldIds Which() const
Definition: fldbas.hxx:273
Built on top of SwWrtShell, provides functionality to insert, update or perform other actions on vari...
Definition: toxmgr.hxx:230
bool DeleteTOX(const SwTOXBase &rTOXBase, bool bDelNodes)
Definition: edtox.cxx:197
bool CursorInsideInputField() const
Definition: crstrvl.cxx:995