LibreOffice Module sw (master)  1
wrtundo.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 <svl/slstitm.hxx>
21 #include <wrtsh.hxx>
22 #include <swundo.hxx>
23 #include <IDocumentUndoRedo.hxx>
24 #include <swdtflvr.hxx>
25 #include <svtools/svtresid.hxx>
26 #include <svtools/strings.hrc>
27 
28 // Undo ends all modes. If a selection is emerged by the Undo,
29 // this must be considered for further action.
30 
31 void SwWrtShell::Do( DoType eDoType, sal_uInt16 nCnt )
32 {
33  // #105332# save current state of DoesUndo()
34  bool bSaveDoesUndo = DoesUndo();
35 
37  switch (eDoType)
38  {
39  case UNDO:
40  DoUndo(false); // #i21739#
41  // Reset modes
42  EnterStdMode();
43  SwEditShell::Undo(nCnt);
44  break;
45  case REDO:
46  DoUndo(false); // #i21739#
47  // Reset modes
48  EnterStdMode();
49  SwEditShell::Redo( nCnt );
50  break;
51  case REPEAT:
52  // #i21739# do not touch undo flag here !!!
53  SwEditShell::Repeat( nCnt );
54  break;
55  }
56  EndAllAction();
57  // #105332# restore undo state
58  DoUndo(bSaveDoesUndo);
59 
60  bool bCreateXSelection = false;
61  const bool bFrameSelected = IsFrameSelected() || IsObjSelected();
62  if ( IsSelection() )
63  {
64  if ( bFrameSelected )
65  UnSelectFrame();
66 
67  // Set the function pointer for canceling the selection at the
68  // cursor position.
71  bCreateXSelection = true;
72  }
73  else if ( bFrameSelected )
74  {
76  bCreateXSelection = true;
77  }
78  else if( (CNT_GRF | CNT_OLE ) & GetCntType() )
79  {
80  SelectObj( GetCharRect().Pos() );
82  bCreateXSelection = true;
83  }
84 
85  if( bCreateXSelection )
87 
88  // Bug 32918: After deleting of the numbering the object panel remains.
89  // Why is not here always a CallChgLink called?
90  CallChgLnk();
91 }
92 
93 OUString SwWrtShell::GetDoString( DoType eDoType ) const
94 {
95  OUString aUndoStr;
96  const char* pResStr = STR_UNDO;
97  switch( eDoType )
98  {
99  case UNDO:
100  pResStr = STR_UNDO;
101  (void)GetLastUndoInfo(&aUndoStr, nullptr, &m_rView);
102  break;
103  case REDO:
104  pResStr = STR_REDO;
105  (void)GetFirstRedoInfo(&aUndoStr, nullptr, &m_rView);
106  break;
107  default:;//prevent warning
108  }
109 
110  return SvtResId(pResStr) + aUndoStr;
111 }
112 
113 void SwWrtShell::GetDoStrings( DoType eDoType, SfxStringListItem& rStrs ) const
114 {
115  SwUndoComments_t comments;
116  switch( eDoType )
117  {
118  case UNDO:
119  comments = GetIDocumentUndoRedo().GetUndoComments();
120  break;
121  case REDO:
122  comments = GetIDocumentUndoRedo().GetRedoComments();
123  break;
124  default:;//prevent warning
125  }
126 
127  OUStringBuffer buf;
128  for (const OUString & comment : comments)
129  {
130  OSL_ENSURE(!comment.isEmpty(), "no Undo/Redo Text set");
131  buf.append(comment).append("\n");
132  }
133  rStrs.SetString(buf.makeStringAndClear());
134 }
135 
137 {
138  OUString str;
139  GetRepeatInfo(& str);
140 
141  if (str.isEmpty())
142  {
143  return str;
144  }
145 
146  return SvtResId(STR_REPEAT) + str;
147 }
148 
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString SvtResId(const char *pId)
OUString GetRepeatString() const
Definition: wrtundo.cxx:136
#define CNT_GRF
Definition: editsh.hxx:132
bool GetLastUndoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const
Definition: edws.cxx:236
virtual SwUndoComments_t GetUndoComments() const =0
Get comments of Undo actions.
void GetDoStrings(DoType eDoType, SfxStringListItem &rStrLstItem) const
Definition: wrtundo.cxx:113
void EnterStdMode()
Definition: select.cxx:550
void DoUndo(bool bOn=true)
Undo.
Definition: edws.cxx:199
virtual SwUndoComments_t GetRedoComments() const =0
Get comments of Redo actions.
void EndAllAction()
Definition: edws.cxx:96
void Redo(sal_uInt16 const nCount=1)
Definition: edundo.cxx:153
static void CreateSelection(SwWrtShell &rSh, const SwFrameShell *pCreator=nullptr)
Definition: swdtflvr.cxx:4036
SELECTFUNC m_fnSetCursor
Definition: wrtsh.hxx:109
OUString GetDoString(DoType eDoType) const
Definition: wrtundo.cxx:93
std::vector< OUString > SwUndoComments_t
Definition: swundo.hxx:26
bool IsSelection() const
Definition: crsrsh.hxx:883
void Repeat(sal_uInt16 const nCount)
Definition: edundo.cxx:203
void SetString(const OUString &)
long ResetSelect(const Point *, bool)
Definition: select.cxx:332
#define CNT_OLE
Definition: editsh.hxx:133
void CallChgLnk()
Definition: crsrsh.cxx:2500
IDocumentUndoRedo const & GetIDocumentUndoRedo() const
Provides access to the document undo/redo interface.
Definition: viewsh.cxx:2596
SwView & m_rView
Definition: wrtsh.hxx:542
SwUndoId GetRepeatInfo(OUString *const o_pStr) const
Definition: edws.cxx:250
void Do(DoType eDoType, sal_uInt16 nCnt=1)
Definition: wrtundo.cxx:31
sal_uInt16 GetCntType() const
Determine form of content. Return Type at CurrentCursor->SPoint.
Definition: edws.cxx:125
const SwRect & GetCharRect() const
Definition: crsrsh.hxx:520
size_t IsObjSelected() const
Definition: feshview.cxx:1150
void UnSelectFrame()
Definition: select.cxx:322
bool SelectObj(const Point &rSelPt, sal_uInt8 nFlag=0, SdrObject *pObj=nullptr)
If an object has been given, exactly this object is selected (instead of searching over position)...
Definition: feshview.cxx:176
SAL_DLLPRIVATE long SetCursorKillSel(const Point *, bool bProp)
Definition: select.cxx:315
bool GetFirstRedoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const
Definition: edws.cxx:243
void EnterSelFrameMode(const Point *pStartDrag=nullptr)
Definition: select.cxx:701
bool DoesUndo() const
Definition: edws.cxx:202
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
void Undo(sal_uInt16 const nCount=1)
Definition: edundo.cxx:97
bool IsFrameSelected() const
Definition: feshview.cxx:1158
SELECTFUNC m_fnKillSel
Definition: wrtsh.hxx:111
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo