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