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/stritem.hxx>
24 #include <svl/eitem.hxx>
25 #include <svx/svxids.hrc>
26 #include <editeng/sizeitem.hxx>
27 #include <fmtfsize.hxx>
28 #include <fldbas.hxx>
29 #include <uiitems.hxx>
30 #include <viewopt.hxx>
31 #include <cmdid.h>
32 #include <view.hxx>
33 #include <wrtsh.hxx>
34 #include <swundo.hxx>
35 #include <textsh.hxx>
36 #include <idxmrk.hxx>
37 #include <cnttab.hxx>
38 #include <toxmgr.hxx>
39 #include <swabstdlg.hxx>
40 #include <globals.hrc>
41 #include <memory>
42 
44 {
45  const SfxItemSet *pArgs = rReq.GetArgs();
46  const SfxPoolItem* pItem = nullptr;
47  const sal_uInt16 nSlot = rReq.GetSlot();
48  if(pArgs)
49  pArgs->GetItemState(nSlot, false, &pItem );
50 
51  SfxViewFrame* pVFrame = GetView().GetViewFrame();
52 
53  switch( nSlot )
54  {
56  {
59  pDlg->Execute();
60  }
61  break;
63  {
64  // no BASIC support
66  Invalidate(rReq.GetSlot());
67  }
68  break;
70  {
72  Invalidate(rReq.GetSlot());
73  }
74  break;
76  {
77  SwTOXMgr aMgr(GetShellPtr());
78  short nRet = RET_OK;
79  if(aMgr.GetTOXMarkCount() > 1)
80  { // Several marks, which should it be?
83  nRet = pMultDlg->Execute();
84  }
85  if( nRet == RET_OK)
86  {
89  pDlg->Execute();
90  }
91  break;
92  }
93  case FN_IDX_MARK_TO_IDX:
94  {
96  break;
97  }
99  {
100  SfxItemSet aSet(
101  GetPool(),
102  svl::Items<
106  RES_COL, RES_COL,
108  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
110  SwWrtShell& rSh = GetShell();
111  SwRect aRect;
112  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
113 
114  long nWidth = aRect.Width();
115  aSet.Put(SwFormatFrameSize(ATT_VAR_SIZE, nWidth));
116  // Height = width for a more consistent preview (analogous to edit range)
117  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
118  const SwTOXBase* pCurTOX = nullptr;
119  bool bGlobal = false;
120  if(pItem)
121  {
122  pCurTOX = static_cast<const SwTOXBase*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
123  bGlobal = true;
124  }
125  else
126  pCurTOX = rSh.GetCurTOX();
127  if(pCurTOX)
128  {
129  const SfxItemSet* pSet = pCurTOX->GetAttrSet();
130  if(pSet)
131  aSet.Put(*pSet);
132  }
135  GetView().GetFrameWeld(), aSet, rSh, const_cast<SwTOXBase*>(pCurTOX),
136  bGlobal));
137  pDlg->StartExecuteAsync([pDlg](sal_Int32 /*nResult*/){
138  pDlg->disposeOnce();
139  });
140  }
141  break;
142  case FN_REMOVE_CUR_TOX:
143  {
144  SwWrtShell& rSh = GetShell();
145  const SwTOXBase* pBase = rSh.GetCurTOX();
146  OSL_ENSURE(pBase, "no TOXBase to remove");
147  if( pBase )
148  rSh.DeleteTOX(*pBase, true);
149  }
150  break;
151  default:
152  OSL_ENSURE(false, "wrong dispatcher");
153  return;
154  }
155 }
156 
158 {
159  SwWrtShell& rSh = GetShell();
160  SfxViewFrame* pVFrame = GetView().GetViewFrame();
161  SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>(
163 
165 
166  const bool bHtmlMode = 0 != ::GetHtmlMode( GetView().GetDocShell() );
167  const SwTOXBase* pBase = nullptr;
168  if( bHtmlMode || nullptr != ( pBase = rSh.GetCurTOX()) )
169  {
170  if( pBase )
171  {
172  if(pBase->IsTOXBaseInReadonly())
173  {
175  }
176  }
177 
180 
181  if(!pIdxMrk)
183  else
185 
186  if(!pAuthMark)
188  else
190 
191  }
192  else if ( rSh.CursorInsideInputField() )
193  {
200  }
201  else
202  {
203 
204  bool bEnableEdit = true;
205  bool bInReadonly = rSh.HasReadonlySel();
206  if( rSh.HasSelection() || bInReadonly)
207  bEnableEdit = false;
208  else
209  {
211  rSh.GetCurTOXMarks( aArr );
212  if( aArr.empty())
213  bEnableEdit = false;
214  }
215 
216  if(!bEnableEdit)
218 
219  if(bInReadonly)
220  {
223  }
224  else
226  nullptr != pIdxMrk));
227 
228  SwField* pField = rSh.GetCurField();
229 
230  if(bInReadonly)
232  else
233  rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, nullptr != pAuthMark));
234 
235  if( bInReadonly || !pField ||
239  }
240 }
241 
242 /* 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:684
#define RES_FRM_SIZE
Definition: hintids.hxx:196
#define RES_COL
Definition: hintids.hxx:216
virtual VclPtr< VclAbstractDialog > CreateSwAutoMarkDialog(weld::Window *pParent, SwWrtShell &rSh)=0
SfxChildWindow * GetChildWindow(sal_uInt16)
void ExecIdx(SfxRequest const &)
Definition: textidx.cxx:43
SwView & GetView()
Definition: basesh.hxx:57
#define FN_REMOVE_CUR_TOX
Definition: cmdid.h:489
void GetIdxState(SfxItemSet &)
Definition: textidx.cxx:157
std::string GetValue
SwWrtShell * GetShellPtr()
Definition: basesh.cxx:2656
SwWrtShell & GetShell()
Definition: basesh.cxx:2651
std::vector< SwTOXMark * > SwTOXMarks
Definition: tox.hxx:44
Base class of all fields.
Definition: fldbas.hxx:280
#define FN_INSERT_AUTH_ENTRY_DLG
Definition: cmdid.h:274
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:90
void ToggleChildWindow(sal_uInt16)
#define FN_EDIT_AUTH_ENTRY_DLG
Definition: cmdid.h:132
#define XATTR_FILL_LAST
#define XATTR_FILL_FIRST
#define FN_EDIT_IDX_ENTRY_DLG
Definition: cmdid.h:73
SwField * GetCurField(const bool bIncludeInputFieldAtStart=false) const
Definition: crstrvl.cxx:927
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
#define RES_BACKGROUND
Definition: hintids.hxx:212
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:213
virtual VclPtr< VclAbstractDialog > CreateMultiTOXMarkDlg(weld::Window *pParent, SwTOXMgr &rTOXMgr)=0
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:340
sal_uInt16 GetTOXMarkCount() const
Definition: toxmgr.hxx:263
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
bool HasReadonlySel() const
Definition: crsrsh.cxx:3312
void GotoTOXMarkBase()
jump to index of TOXMark
Definition: crstrvl.cxx:366
SwFieldType * GetTyp() const
Definition: fldbas.hxx:383
#define RES_LR_SPACE
Definition: hintids.hxx:198
SwTOXMark * GetCurTOXMark()
Definition: toxmgr.hxx:266
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
void DisableItem(sal_uInt16 nWhich)
void Width(long nNew)
Definition: swrect.hxx:185
virtual void Invalidate(sal_uInt16 nId=0)
RET_OK
const SvxPageUsage aArr[]
void GetCurTOXMarks(SwTOXMarks &rMarks) const
Get all marks at current SPoint.
Definition: edtox.cxx:86
#define FN_PARAM_TOX_TYPE
Definition: cmdid.h:787
#define FN_INSERT_MULTI_TOX
Definition: cmdid.h:273
SwFieldIds Which() const
Definition: fldbas.hxx:266
Frame is variable in Var-direction.
Definition: fmtfsize.hxx:37
bool DeleteTOX(const SwTOXBase &rTOXBase, bool bDelNodes)
Definition: edtox.cxx:192
bool CursorInsideInputField() const
Definition: crstrvl.cxx:948