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  vcl::Window *pMDI = &pVFrame->GetWindow();
53 
54  switch( nSlot )
55  {
57  {
60  pDlg->Execute();
61  }
62  break;
64  {
65  // no BASIC support
67  Invalidate(rReq.GetSlot());
68  }
69  break;
71  {
73  Invalidate(rReq.GetSlot());
74  }
75  break;
77  {
78  SwTOXMgr aMgr(GetShellPtr());
79  short nRet = RET_OK;
80  if(aMgr.GetTOXMarkCount() > 1)
81  { // Several marks, which should it be?
84  nRet = pMultDlg->Execute();
85  }
86  if( nRet == RET_OK)
87  {
90  pDlg->Execute();
91  }
92  break;
93  }
94  case FN_IDX_MARK_TO_IDX:
95  {
97  break;
98  }
100  {
101  SfxItemSet aSet(
102  GetPool(),
103  svl::Items<
107  RES_COL, RES_COL,
109  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
111  SwWrtShell& rSh = GetShell();
112  SwRect aRect;
113  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
114 
115  long nWidth = aRect.Width();
116  aSet.Put(SwFormatFrameSize(ATT_VAR_SIZE, nWidth));
117  // Height = width for a more consistent preview (analogous to edit range)
118  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
119  const SwTOXBase* pCurTOX = nullptr;
120  bool bGlobal = false;
121  if(pItem)
122  {
123  pCurTOX = static_cast<const SwTOXBase*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
124  bGlobal = true;
125  }
126  else
127  pCurTOX = rSh.GetCurTOX();
128  if(pCurTOX)
129  {
130  const SfxItemSet* pSet = pCurTOX->GetAttrSet();
131  if(pSet)
132  aSet.Put(*pSet);
133  }
136  pMDI, aSet, rSh, const_cast<SwTOXBase*>(pCurTOX),
137  bGlobal));
138  pDlg->StartExecuteAsync(nullptr);
139  }
140  break;
141  case FN_REMOVE_CUR_TOX:
142  {
143  SwWrtShell& rSh = GetShell();
144  const SwTOXBase* pBase = rSh.GetCurTOX();
145  OSL_ENSURE(pBase, "no TOXBase to remove");
146  if( pBase )
147  rSh.DeleteTOX(*pBase, true);
148  }
149  break;
150  default:
151  OSL_ENSURE(false, "wrong dispatcher");
152  return;
153  }
154 }
155 
157 {
158  SwWrtShell& rSh = GetShell();
159  SfxViewFrame* pVFrame = GetView().GetViewFrame();
160  SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>(
162 
164 
165  const bool bHtmlMode = 0 != ::GetHtmlMode( GetView().GetDocShell() );
166  const SwTOXBase* pBase = nullptr;
167  if( bHtmlMode || nullptr != ( pBase = rSh.GetCurTOX()) )
168  {
169  if( pBase )
170  {
171  if(pBase->IsTOXBaseInReadonly())
172  {
174  }
175  }
176 
179 
180  if(!pIdxMrk)
182  else
184 
185  if(!pAuthMark)
187  else
189 
190  }
191  else if ( rSh.CursorInsideInputField() )
192  {
199  }
200  else
201  {
202 
203  bool bEnableEdit = true;
204  bool bInReadonly = rSh.HasReadonlySel();
205  if( rSh.HasSelection() || bInReadonly)
206  bEnableEdit = false;
207  else
208  {
210  rSh.GetCurTOXMarks( aArr );
211  if( aArr.empty())
212  bEnableEdit = false;
213  }
214 
215  if(!bEnableEdit)
217 
218  if(bInReadonly)
219  {
222  }
223  else
225  nullptr != pIdxMrk));
226 
227  SwField* pField = rSh.GetCurField();
228 
229  if(bInReadonly)
231  else
232  rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, nullptr != pAuthMark));
233 
234  if( bInReadonly || !pField ||
238  }
239 }
240 
241 /* 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:2044
#define FN_IDX_MARK_TO_IDX
Definition: cmdid.h:678
virtual VclPtr< AbstractMultiTOXTabDialog > CreateMultiTOXTabDialog(vcl::Window *pParent, const SfxItemSet &rSet, SwWrtShell &rShell, SwTOXBase *pCurTOX, bool bGlobal)=0
#define RES_FRM_SIZE
Definition: hintids.hxx:194
#define RES_COL
Definition: hintids.hxx:214
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:59
#define FN_REMOVE_CUR_TOX
Definition: cmdid.h:485
void GetIdxState(SfxItemSet &)
Definition: textidx.cxx:156
std::string GetValue
SwWrtShell * GetShellPtr()
Definition: basesh.cxx:2585
SwWrtShell & GetShell()
Definition: basesh.cxx:2580
std::vector< SwTOXMark * > SwTOXMarks
Definition: tox.hxx:44
Base class of all fields.
Definition: fldbas.hxx:279
#define FN_INSERT_AUTH_ENTRY_DLG
Definition: cmdid.h:273
bool IsTOXBaseInReadonly() const
Definition: doctxm.cxx:2020
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:86
void ToggleChildWindow(sal_uInt16)
#define FN_EDIT_AUTH_ENTRY_DLG
Definition: cmdid.h:132
vcl::Window & GetWindow() const
#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:195
SfxItemPool & GetPool() const
#define RES_BACKGROUND
Definition: hintids.hxx:210
bool HasSelection() const
Definition: wrtsh.hxx:137
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define FN_INSERT_IDX_ENTRY_DLG
Definition: cmdid.h:212
virtual VclPtr< VclAbstractDialog > CreateMultiTOXMarkDlg(weld::Window *pParent, SwTOXMgr &rTOXMgr)=0
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:339
weld::Window * GetFrameWeld(SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
bool HasReadonlySel() const
Definition: crsrsh.cxx:3227
void GotoTOXMarkBase()
jump to index of TOXMark
Definition: crstrvl.cxx:366
SwFieldType * GetTyp() const
Definition: fldbas.hxx:382
#define RES_LR_SPACE
Definition: hintids.hxx:196
sal_uInt16 GetTOXMarkCount()
Definition: toxmgr.hxx:263
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:94
#define FN_PARAM_TOX_TYPE
Definition: cmdid.h:780
#define FN_INSERT_MULTI_TOX
Definition: cmdid.h:272
SwFieldIds Which() const
Definition: fldbas.hxx:265
Frame is variable in Var-direction.
Definition: fmtfsize.hxx:37
bool DeleteTOX(const SwTOXBase &rTOXBase, bool bDelNodes)
Definition: edtox.cxx:200
bool CursorInsideInputField() const
Definition: crstrvl.cxx:948