xref: /aoo41x/main/sw/source/ui/wrtsh/wrtundo.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 
29 #define _SVSTDARR_STRINGSDTOR
30 #include <tools/resid.hxx>
31 #include <sfx2/app.hxx>
32 #include <svl/slstitm.hxx>
33 #include <wrtsh.hxx>
34 #include <swundo.hxx>               	// fuer Undo-Ids
35 #include <IDocumentUndoRedo.hxx>
36 #include <swdtflvr.hxx>
37 #include <svtools/svtdata.hxx>
38 #include <svtools/svtools.hrc>
39 #include <svtools/svtdata.hxx>
40 #include <wrtsh.hrc>
41 #include <sfx2/sfx.hrc>
42 
43 
44 // Undo beendet alle Modi. Falls eine Selektion durch das Undo entstanden
45 // ist, muss die fuer die weiteren Aktionen beruecksichtigt werden.
46 
47 
Do(DoType eDoType,sal_uInt16 nCnt)48 void SwWrtShell::Do( DoType eDoType, sal_uInt16 nCnt )
49 {
50     // #105332# save current state of DoesUndo()
51     sal_Bool bSaveDoesUndo = DoesUndo();
52 
53 	StartAllAction();
54  	switch( eDoType )
55 	{
56 		case UNDO:
57             DoUndo(sal_False); // #i21739#
58 			// Modi zuruecksetzen
59 			EnterStdMode();
60             SwEditShell::Undo(nCnt);
61 			break;
62 		case REDO:
63             DoUndo(sal_False); // #i21739#
64 			// Modi zuruecksetzen
65 			EnterStdMode();
66 			SwEditShell::Redo( nCnt );
67 			break;
68 		case REPEAT:
69             // #i21739# do not touch undo flag here !!!
70 			SwEditShell::Repeat( nCnt );
71 			break;
72 	}
73 	EndAllAction();
74     // #105332# restore undo state
75     DoUndo(bSaveDoesUndo);
76 
77 	sal_Bool bCreateXSelection = sal_False;
78 	const sal_Bool bFrmSelected = IsFrmSelected() || IsObjSelected();
79 	if ( IsSelection() )
80 	{
81 		if ( bFrmSelected )
82 			UnSelectFrm();
83 
84 		// Funktionspointer fuer das Aufheben der Selektion setzen
85 		// bei Cursor setzen
86 		fnKillSel = &SwWrtShell::ResetSelect;
87 		fnSetCrsr = &SwWrtShell::SetCrsrKillSel;
88 		bCreateXSelection = sal_True;
89 	}
90 	else if ( bFrmSelected )
91 	{
92 		EnterSelFrmMode();
93 		bCreateXSelection = sal_True;
94 	}
95 	else if( (CNT_GRF | CNT_OLE ) & GetCntType() )
96 	{
97 		SelectObj( GetCharRect().Pos() );
98 		EnterSelFrmMode();
99 		bCreateXSelection = sal_True;
100 	}
101 
102 	if( bCreateXSelection )
103 		SwTransferable::CreateSelection( *this );
104 
105 	// Bug 32918: nach loeschen der Numerierung bleibt die Obj. Leiste stehen
106 	//			Warum wird hier nicht immer ein CallChgLink gerufen?
107 	CallChgLnk();
108 }
109 
110 
GetDoString(DoType eDoType) const111 String SwWrtShell::GetDoString( DoType eDoType ) const
112 {
113     ::rtl::OUString aUndoStr;
114     sal_uInt16 nResStr = STR_UNDO;
115 	switch( eDoType )
116 	{
117 	case UNDO:
118 		nResStr = STR_UNDO;
119         GetLastUndoInfo(& aUndoStr, 0);
120 		break;
121 	case REDO:
122 		nResStr = STR_REDO;
123         GetFirstRedoInfo(& aUndoStr);
124 		break;
125     default:;//prevent warning
126 	}
127 
128     ::rtl::OUStringBuffer buf = ::rtl::OUStringBuffer( String( SvtResId( nResStr ) ) );
129     buf.append(aUndoStr);
130 
131     return buf.makeStringAndClear();
132 }
133 
GetDoStrings(DoType eDoType,SfxStringListItem & rStrs) const134 sal_uInt16 SwWrtShell::GetDoStrings( DoType eDoType, SfxStringListItem& rStrs ) const
135 {
136     SwUndoComments_t comments;
137 	switch( eDoType )
138 	{
139 	case UNDO:
140         comments = GetIDocumentUndoRedo().GetUndoComments();
141 		break;
142 	case REDO:
143         comments = GetIDocumentUndoRedo().GetRedoComments();
144 		break;
145     default:;//prevent warning
146 	}
147 
148     ::rtl::OUStringBuffer buf;
149     for (size_t i = 0; i < comments.size(); ++i)
150     {
151         OSL_ENSURE(comments[i].getLength(), "no Undo/Redo Text set");
152         buf.append(comments[i]);
153         buf.append(sal_Unicode('\n'));
154     }
155     rStrs.SetString(buf.makeStringAndClear());
156     return static_cast<sal_uInt16>(comments.size());
157 }
158 
159 
GetRepeatString() const160 String SwWrtShell::GetRepeatString() const
161 {
162     ::rtl::OUString str;
163     GetRepeatInfo(& str);
164 
165     if (str.getLength() == 0)
166     {
167         return str;
168     }
169 
170     ::rtl::OUStringBuffer buf( String(SvtResId(STR_REPEAT)) );
171     buf.append(str);
172     return buf.makeStringAndClear();
173 }
174 
175 
176