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 <fmtfsize.hxx>
26 #include <fldbas.hxx>
27 #include <uiitems.hxx>
28 #include <viewopt.hxx>
29 #include <cmdid.h>
30 #include <view.hxx>
31 #include <wrtsh.hxx>
32 #include <textsh.hxx>
33 #include <idxmrk.hxx>
34 #include <toxmgr.hxx>
35 #include <swabstdlg.hxx>
36 
38 {
39  const SfxItemSet *pArgs = rReq.GetArgs();
40  const SfxPoolItem* pItem = nullptr;
41  const sal_uInt16 nSlot = rReq.GetSlot();
42  if(pArgs)
43  pArgs->GetItemState(nSlot, false, &pItem );
44 
45  SfxViewFrame* pVFrame = GetView().GetViewFrame();
46 
47  switch( nSlot )
48  {
50  {
53  pDlg->Execute();
54  }
55  break;
57  {
58  // no BASIC support
60  Invalidate(rReq.GetSlot());
61  }
62  break;
64  {
66  Invalidate(rReq.GetSlot());
67  }
68  break;
70  {
71  SwTOXMgr aMgr(GetShellPtr());
72  short nRet = RET_OK;
73  if(aMgr.GetTOXMarkCount() > 1)
74  { // Several marks, which should it be?
77  nRet = pMultDlg->Execute();
78  }
79  if( nRet == RET_OK)
80  {
83  pDlg->Execute();
84  }
85  break;
86  }
87  case FN_IDX_MARK_TO_IDX:
88  {
90  break;
91  }
93  {
94  SfxItemSet aSet(
95  GetPool(),
96  svl::Items<
100  RES_COL, RES_COL,
102  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
104  SwWrtShell& rSh = GetShell();
105  SwRect aRect;
106  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
107 
108  long nWidth = aRect.Width();
109  aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth));
110  // Height = width for a more consistent preview (analogous to edit range)
111  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
112  const SwTOXBase* pCurTOX = nullptr;
113  bool bGlobal = false;
114  if(pItem)
115  {
116  pCurTOX = static_cast<const SwTOXBase*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
117  bGlobal = true;
118  }
119  else
120  pCurTOX = rSh.GetCurTOX();
121  if(pCurTOX)
122  {
123  const SfxItemSet* pSet = pCurTOX->GetAttrSet();
124  if(pSet)
125  aSet.Put(*pSet);
126  }
129  GetView().GetFrameWeld(), aSet, rSh, const_cast<SwTOXBase*>(pCurTOX),
130  bGlobal));
131  pDlg->StartExecuteAsync([pDlg](sal_Int32 /*nResult*/){
132  pDlg->disposeOnce();
133  });
134  }
135  break;
136  case FN_REMOVE_CUR_TOX:
137  {
138  SwWrtShell& rSh = GetShell();
139  const SwTOXBase* pBase = rSh.GetCurTOX();
140  OSL_ENSURE(pBase, "no TOXBase to remove");
141  if( pBase )
142  rSh.DeleteTOX(*pBase, true);
143  }
144  break;
145  default:
146  OSL_ENSURE(false, "wrong dispatcher");
147  return;
148  }
149 }
150 
152 {
153  SwWrtShell& rSh = GetShell();
154  SfxViewFrame* pVFrame = GetView().GetViewFrame();
155  SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>(
157 
159 
160  const bool bHtmlMode = 0 != ::GetHtmlMode( GetView().GetDocShell() );
161  const SwTOXBase* pBase = nullptr;
162  if( bHtmlMode || nullptr != ( pBase = rSh.GetCurTOX()) )
163  {
164  if( pBase )
165  {
166  if(pBase->IsTOXBaseInReadonly())
167  {
169  }
170  }
171 
174 
175  if(!pIdxMrk)
177  else
179 
180  if(!pAuthMark)
182  else
184 
185  }
186  else if ( rSh.CursorInsideInputField() )
187  {
194  }
195  else
196  {
197 
198  bool bEnableEdit = true;
199  bool bInReadonly = rSh.HasReadonlySel();
200  if( rSh.HasSelection() || bInReadonly)
201  bEnableEdit = false;
202  else
203  {
205  rSh.GetCurTOXMarks( aArr );
206  if( aArr.empty())
207  bEnableEdit = false;
208  }
209 
210  if(!bEnableEdit)
212 
213  if(bInReadonly)
214  {
217  }
218  else
220  nullptr != pIdxMrk));
221 
222  SwField* pField = rSh.GetCurField();
223 
224  if(bInReadonly)
226  else
227  rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, nullptr != pAuthMark));
228 
229  if( bInReadonly || !pField ||
233  }
234 }
235 
236 /* 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:699
virtual VclPtr< VclAbstractDialog > CreateSwAutoMarkDialog(weld::Window *pParent, SwWrtShell &rSh)=0
SfxChildWindow * GetChildWindow(sal_uInt16)
void ExecIdx(SfxRequest const &)
Definition: textidx.cxx:37
SwView & GetView()
Definition: basesh.hxx:57
#define FN_REMOVE_CUR_TOX
Definition: cmdid.h:504
void GetIdxState(SfxItemSet &)
Definition: textidx.cxx:151
std::string GetValue
constexpr TypedWhichId< SwFormatCol > RES_COL(109)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
SwWrtShell * GetShellPtr()
Definition: basesh.cxx:2685
SwWrtShell & GetShell()
Definition: basesh.cxx:2680
std::vector< SwTOXMark * > SwTOXMarks
Definition: tox.hxx:45
Base class of all fields.
Definition: fldbas.hxx:293
#define FN_INSERT_AUTH_ENTRY_DLG
Definition: cmdid.h:281
bool IsTOXBaseInReadonly() const
Definition: doctxm.cxx:2013
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
const SfxItemSet * GetArgs() const
virtual short Execute()=0
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
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:905
const SwTOXBase * GetCurTOX() const
Get current listing before or at the Cursor.
Definition: edtox.cxx:187
virtual VclPtr< AbstractMultiTOXTabDialog > CreateMultiTOXTabDialog(weld::Window *pParent, const SfxItemSet &rSet, SwWrtShell &rShell, SwTOXBase *pCurTOX, bool bGlobal)=0
SfxItemPool & GetPool() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
bool HasSelection() const
Definition: wrtsh.hxx:141
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define FN_INSERT_IDX_ENTRY_DLG
Definition: cmdid.h:218
virtual VclPtr< VclAbstractDialog > CreateMultiTOXMarkDlg(weld::Window *pParent, SwTOXMgr &rTOXMgr)=0
const SvxPageUsage aArr[]
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:337
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:3332
void GotoTOXMarkBase()
jump to index of TOXMark
Definition: crstrvl.cxx:367
SwFieldType * GetTyp() const
Definition: fldbas.hxx:396
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)
void Width(long nNew)
Definition: swrect.hxx:187
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:86
constexpr sal_uInt16 XATTR_FILL_LAST(XATTR_FILLBACKGROUND)
#define FN_PARAM_TOX_TYPE
Definition: cmdid.h:805
Frame is variable in Var-direction.
#define FN_INSERT_MULTI_TOX
Definition: cmdid.h:280
SwFieldIds Which() const
Definition: fldbas.hxx:272
bool DeleteTOX(const SwTOXBase &rTOXBase, bool bDelNodes)
Definition: edtox.cxx:192
bool CursorInsideInputField() const
Definition: crstrvl.cxx:926