1*cdf0e10cSrcweir/*************************************************************************
2*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3*cdf0e10cSrcweir *
4*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates.
5*cdf0e10cSrcweir *
6*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite
7*cdf0e10cSrcweir *
8*cdf0e10cSrcweir * This file is part of OpenOffice.org.
9*cdf0e10cSrcweir *
10*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify
11*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3
12*cdf0e10cSrcweir * only, as published by the Free Software Foundation.
13*cdf0e10cSrcweir *
14*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful,
15*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of
16*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details
18*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code).
19*cdf0e10cSrcweir *
20*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License
21*cdf0e10cSrcweir * version 3 along with OpenOffice.org.  If not, see
22*cdf0e10cSrcweir * <http://www.openoffice.org/license.html>
23*cdf0e10cSrcweir * for a copy of the LGPLv3 License.
24*cdf0e10cSrcweir *
25*cdf0e10cSrcweir ************************************************************************/
26*cdf0e10cSrcweir
27*cdf0e10cSrcweir#ifndef __com_sun_star_document_XUndoManager_idl__
28*cdf0e10cSrcweir#define __com_sun_star_document_XUndoManager_idl__
29*cdf0e10cSrcweir
30*cdf0e10cSrcweir#include <com/sun/star/document/EmptyUndoStackException.idl>
31*cdf0e10cSrcweir#include <com/sun/star/document/UndoContextNotClosedException.idl>
32*cdf0e10cSrcweir#include <com/sun/star/document/UndoFailedException.idl>
33*cdf0e10cSrcweir#include <com/sun/star/util/InvalidStateException.idl>
34*cdf0e10cSrcweir#include <com/sun/star/util/XLockable.idl>
35*cdf0e10cSrcweir#include <com/sun/star/container/XChild.idl>
36*cdf0e10cSrcweir#include <com/sun/star/lang/IllegalArgumentException.idl>
37*cdf0e10cSrcweir#include <com/sun/star/lang/WrappedTargetException.idl>
38*cdf0e10cSrcweir
39*cdf0e10cSrcweir//==================================================================================================================
40*cdf0e10cSrcweir
41*cdf0e10cSrcweirmodule com { module sun { module star { module document {
42*cdf0e10cSrcweir
43*cdf0e10cSrcweirpublished interface XUndoAction;
44*cdf0e10cSrcweirpublished interface XUndoManagerListener;
45*cdf0e10cSrcweir
46*cdf0e10cSrcweir//==================================================================================================================
47*cdf0e10cSrcweir
48*cdf0e10cSrcweir/** provides access to the undo/redo stacks of a document
49*cdf0e10cSrcweir
50*cdf0e10cSrcweir    <h3>Undo</h3>
51*cdf0e10cSrcweir    <p>Changes to a document usually result in recording of information how to undo those changes, if desired. A so-called
52*cdf0e10cSrcweir    undo action records the information how to undo a single change. Undo actions are maintained in a stack, so that
53*cdf0e10cSrcweir    the changes they represent can be undo in the reverse order they have originally been applied.</p>
54*cdf0e10cSrcweir
55*cdf0e10cSrcweir    <h3>Redo</h3>
56*cdf0e10cSrcweir    <p>Additionally, the Undo manager manages a Redo stack: Actions which are undone are moved from the Undo to the Redo
57*cdf0e10cSrcweir    stack, so it is possible to re-apply the changes to the document.</p>
58*cdf0e10cSrcweir
59*cdf0e10cSrcweir    <h3>Undo contexts</h3>
60*cdf0e10cSrcweir    <p>For collecting multiple changes in a single undo action, so-called Undo contexts are provided. When an Undo
61*cdf0e10cSrcweir    context is entered, all subsequently added Undo actions are not pushed onto the undo stack directly, but considered
62*cdf0e10cSrcweir    a sub action of the Undo context. Once the Undo context is left, a single undo action is pushed onto the undo stack,
63*cdf0e10cSrcweir    which comprises all those single Undo actions.<br/>
64*cdf0e10cSrcweir    Undo contexts can be arbitrarily nested.</p>
65*cdf0e10cSrcweir
66*cdf0e10cSrcweir    <h3>Hidden Undo actions</h3>
67*cdf0e10cSrcweir    <p>Hidden Undo actions are those which in no observable way contribute to the undo stack. That is,
68*cdf0e10cSrcweir    any method retrieving information about the stack will behave as if the undo action does not exist. Nonetheless,
69*cdf0e10cSrcweir    calling <member>undo</member> respectively <member>redo</member> will include those actions.<br/>
70*cdf0e10cSrcweir    Hidden Undo actions can be created by calling <member>enterHiddenUndoContext</member>, following by
71*cdf0e10cSrcweir    <member>leaveUndoContext</member>.</p>
72*cdf0e10cSrcweir
73*cdf0e10cSrcweir    <a name="locking"></a>
74*cdf0e10cSrcweir    <h3>Locking</h3>
75*cdf0e10cSrcweir    <p>An Undo manager can be locked and unlocked, using the <member>XLockable::lock</member> and
76*cdf0e10cSrcweir    <member>XLockable::unlock</member> methods. When it is locked, then every attempt to add an undo action, or to
77*cdf0e10cSrcweir    enter or leave an Undo context, will be silently ignored.</p>
78*cdf0e10cSrcweir */
79*cdf0e10cSrcweirpublished interface XUndoManager
80*cdf0e10cSrcweir{
81*cdf0e10cSrcweir    /** allows <a href="#locking">locking</a> the undo manager.
82*cdf0e10cSrcweir    */
83*cdf0e10cSrcweir    interface ::com::sun::star::util::XLockable;
84*cdf0e10cSrcweir
85*cdf0e10cSrcweir    /** allows accessing the component, usually a document, which the undo manager works for.
86*cdf0e10cSrcweir
87*cdf0e10cSrcweir        <p><member scope="com::sun::star::container">XChild::setParent</member> is not supported, and will throw
88*cdf0e10cSrcweir        an <type scope="com::sun::star::lang">NoSupportException</type>.</p>
89*cdf0e10cSrcweir    */
90*cdf0e10cSrcweir    interface ::com::sun::star::container::XChild;
91*cdf0e10cSrcweir
92*cdf0e10cSrcweir    /** enters a new undo context.
93*cdf0e10cSrcweir
94*cdf0e10cSrcweir        <p>A new undo action will be added to the undo stack, with the title given as <code>i_title</code>. As long
95*cdf0e10cSrcweir        as the context is not left, every undo action added to the stack will be treated as sub action. This means
96*cdf0e10cSrcweir        it will not be directly accessible at the Undo manager, not appear in any user interface, and cannot be
97*cdf0e10cSrcweir        separately undone or re-done.</p>
98*cdf0e10cSrcweir
99*cdf0e10cSrcweir        <p>Each call to <code>enterUndoContext</code> must be paired by a call to <member>leaveUndoContext</member>,
100*cdf0e10cSrcweir        otherwise, the document's undo stack is left in an inconsistent state.</p>
101*cdf0e10cSrcweir
102*cdf0e10cSrcweir        <p>Undo contexts can be nested, i.e. it is legitimate to call <code>enterUndoContext</code> and
103*cdf0e10cSrcweir        <member>enterHiddenUndoContext</member> multiple times without calling <member>leaveUndoContext</member> inbetween.</p>
104*cdf0e10cSrcweir
105*cdf0e10cSrcweir        @see leaveUndoContext
106*cdf0e10cSrcweir    */
107*cdf0e10cSrcweir    void    enterUndoContext(
108*cdf0e10cSrcweir                [in] string i_title
109*cdf0e10cSrcweir            );
110*cdf0e10cSrcweir
111*cdf0e10cSrcweir    /** enters a new undo context, creating a hidden undo action.
112*cdf0e10cSrcweir
113*cdf0e10cSrcweir        <p>A hidden undo action does not, in any visible way, contribute to the undo stack. This means
114*cdf0e10cSrcweir        that
115*cdf0e10cSrcweir        <ul><li>Calling <member>undo</member> when the top-element is a hidden undo action will transparently
116*cdf0e10cSrcweir                undo this action, and also undo the new top element of the stack.</li>
117*cdf0e10cSrcweir            <li>Calling <member>redo</member> when the top-element is a hidden action will transparently
118*cdf0e10cSrcweir                redo this action, and also redo the new top element of the stack.</li>
119*cdf0e10cSrcweir            <li>In any user interface presenting the current Undo or Redo actions to the user, a hidden
120*cdf0e10cSrcweir                action will not be listed.</p>
121*cdf0e10cSrcweir        </ul>
122*cdf0e10cSrcweir
123*cdf0e10cSrcweir        <p>A new undo action will be added to the undo stack. As long as the context is not left, every undo action
124*cdf0e10cSrcweir        added to the stack will be treated as sub action. This means it will not be directly accessible at the undo
125*cdf0e10cSrcweir        manager, not appear in any user interface, and cannot be separately undone or re-done.</p>
126*cdf0e10cSrcweir
127*cdf0e10cSrcweir        <p>Each call to <code>enterHiddenUndoContext</code> must be paired by a call to <member>leaveUndoContext</member>,
128*cdf0e10cSrcweir        otherwise, the document's undo stack is left in an inconsistent state.</p>
129*cdf0e10cSrcweir
130*cdf0e10cSrcweir        <p>Undo contexts can be nested, i.e. it is legitimate to call <member>enterUndoContext</member> and
131*cdf0e10cSrcweir        <code>enterHiddenUndoContext</code> multiple times without calling <member>leaveUndoContext</member> inbetween.</p>
132*cdf0e10cSrcweir
133*cdf0e10cSrcweir        @throws EmptyUndoStackException
134*cdf0e10cSrcweir            if the undo stack is currently empty, in which case it is impossible to push a hidden undo action onto
135*cdf0e10cSrcweir            it.
136*cdf0e10cSrcweir
137*cdf0e10cSrcweir        @see enterUndoContext
138*cdf0e10cSrcweir        @see leaveUndoContext
139*cdf0e10cSrcweir    */
140*cdf0e10cSrcweir    void    enterHiddenUndoContext()
141*cdf0e10cSrcweir        raises( EmptyUndoStackException );
142*cdf0e10cSrcweir
143*cdf0e10cSrcweir    /** leaves the undo context previously opened via <member>enterUndoContext</member> respectively
144*cdf0e10cSrcweir        <member>enterHiddenUndoContext</member>.
145*cdf0e10cSrcweir
146*cdf0e10cSrcweir        <p>If no undo action has been added since the context has been opened, the context is not only left,
147*cdf0e10cSrcweir        but silently removed, and does not contribute to the undo stack at all. In this case, possible
148*cdf0e10cSrcweir        listeners will be notified via <member>XUndoManagerListener::cancelledContext</member>.</p>
149*cdf0e10cSrcweir
150*cdf0e10cSrcweir        <p>Otherwise, the undo context will be closed, and added to the Undo stack; the redo stack will be cleared,
151*cdf0e10cSrcweir        and listeners will be notified via <member>XUndoManagerListener::leftContext</member> resp.
152*cdf0e10cSrcweir        <member>XUndoManagerListener::leftHiddenContext</member></p>
153*cdf0e10cSrcweir
154*cdf0e10cSrcweir        @throws ::com::sun::star::util::InvalidStateException
155*cdf0e10cSrcweir            if no undo context is currently open.
156*cdf0e10cSrcweir
157*cdf0e10cSrcweir        @see enterUndoContext
158*cdf0e10cSrcweir        @see enterHiddenUndoContext
159*cdf0e10cSrcweir    */
160*cdf0e10cSrcweir    void    leaveUndoContext()
161*cdf0e10cSrcweir        raises( ::com::sun::star::util::InvalidStateException );
162*cdf0e10cSrcweir
163*cdf0e10cSrcweir    /** adds the given undo action to the undo stack.
164*cdf0e10cSrcweir
165*cdf0e10cSrcweir        <p>The redo stack is cleared when a new action is pushed onto the undo stack.</p>
166*cdf0e10cSrcweir
167*cdf0e10cSrcweir        <p>The Undo manager takes ownership of any actions pushed onto the undo stack. This means that if the
168*cdf0e10cSrcweir        action is finally removed from the Undo manager's control (e.g. by calling <member>clear</member> resp.
169*cdf0e10cSrcweir        <member>clearRedo</member>), it will be disposed, as long as it supports the <member scope="com::sun::star::lang">XComponent</member>
170*cdf0e10cSrcweir        interface.</p>
171*cdf0e10cSrcweir
172*cdf0e10cSrcweir        <p>If the Undo manager is <a href="#locking">locked</a> at the moment the method is called, the call will be ignored, and the undo action
173*cdf0e10cSrcweir        will immediately be disposed, if applicable.</p>
174*cdf0e10cSrcweir
175*cdf0e10cSrcweir        @throws ::com::sun::star::lang::IllegalArgumentException
176*cdf0e10cSrcweir            if the given undo action is <NULL/>.
177*cdf0e10cSrcweir    */
178*cdf0e10cSrcweir    void    addUndoAction(
179*cdf0e10cSrcweir                [in] XUndoAction i_action
180*cdf0e10cSrcweir            )
181*cdf0e10cSrcweir            raises( ::com::sun::star::lang::IllegalArgumentException );
182*cdf0e10cSrcweir
183*cdf0e10cSrcweir    /** reverts the most recent action on the document.
184*cdf0e10cSrcweir
185*cdf0e10cSrcweir        <p>Effectively, invoking this method will
186*cdf0e10cSrcweir        <ul><li>invoke <member>XUndoAction::undo</member> on the top-most action of the undo stack</li>
187*cdf0e10cSrcweir            <li>move this undo action from the undo stack to the redo stack</li>
188*cdf0e10cSrcweir        </ul></p>
189*cdf0e10cSrcweir
190*cdf0e10cSrcweir        @throws EmptyUndoStackException
191*cdf0e10cSrcweir            if the undo stack is currently empty
192*cdf0e10cSrcweir
193*cdf0e10cSrcweir        @throws UndoContextNotClosedException
194*cdf0e10cSrcweir            if there currently is an open undo context
195*cdf0e10cSrcweir
196*cdf0e10cSrcweir        @throws UndoFailedException
197*cdf0e10cSrcweir            if the invocation of <member>XUndoAction::undo</member> raised this exception. In this case, the undo stack
198*cdf0e10cSrcweir            of the undo manager will have been cleared.
199*cdf0e10cSrcweir
200*cdf0e10cSrcweir        @see redo
201*cdf0e10cSrcweir        @see enterUndoContext
202*cdf0e10cSrcweir    */
203*cdf0e10cSrcweir    void    undo()
204*cdf0e10cSrcweir            raises( ::com::sun::star::document::EmptyUndoStackException,
205*cdf0e10cSrcweir                    ::com::sun::star::document::UndoContextNotClosedException,
206*cdf0e10cSrcweir                    ::com::sun::star::document::UndoFailedException );
207*cdf0e10cSrcweir
208*cdf0e10cSrcweir    /** replays the action on the document which has most recently been undone
209*cdf0e10cSrcweir
210*cdf0e10cSrcweir        <p>Effectively, invoking this method will
211*cdf0e10cSrcweir        <ul><li>invoke <member>XUndoAction::redo</member> on the top-most action of the redo stack</li>
212*cdf0e10cSrcweir            <li>move this action from the redo stack to the undo stack</li>
213*cdf0e10cSrcweir        </ul></p>
214*cdf0e10cSrcweir
215*cdf0e10cSrcweir        @throws EmptyUndoStackException
216*cdf0e10cSrcweir            when the Redo stack is currently empty
217*cdf0e10cSrcweir
218*cdf0e10cSrcweir        @throws UndoContextNotClosedException
219*cdf0e10cSrcweir            if there currently is an open undo context
220*cdf0e10cSrcweir
221*cdf0e10cSrcweir        @throws UndoFailedException
222*cdf0e10cSrcweir            if the invocation of <member>XUndoAction::redo</member> raised this exception. In this case, the redo stack
223*cdf0e10cSrcweir            of the undo manager will have been cleared.
224*cdf0e10cSrcweir
225*cdf0e10cSrcweir        @see undo
226*cdf0e10cSrcweir    */
227*cdf0e10cSrcweir    void    redo()
228*cdf0e10cSrcweir            raises( ::com::sun::star::document::EmptyUndoStackException,
229*cdf0e10cSrcweir                    ::com::sun::star::document::UndoContextNotClosedException,
230*cdf0e10cSrcweir                    ::com::sun::star::document::UndoFailedException );
231*cdf0e10cSrcweir
232*cdf0e10cSrcweir    /** determines whether <member>undo</member> can reasonably be expected to succeed.
233*cdf0e10cSrcweir
234*cdf0e10cSrcweir        @return
235*cdf0e10cSrcweir            <FALSE/> if and only if the undo stack is currently empty, or there is an open and not-yet-closed
236*cdf0e10cSrcweir            undo context.
237*cdf0e10cSrcweir    */
238*cdf0e10cSrcweir    boolean isUndoPossible();
239*cdf0e10cSrcweir
240*cdf0e10cSrcweir    /** determines whether <member>redo</member> can reasonably be expected to succeed.
241*cdf0e10cSrcweir
242*cdf0e10cSrcweir        @return
243*cdf0e10cSrcweir            <FALSE/> if and only if the redo stack is currently empty, or there is an open and not-yet-closed
244*cdf0e10cSrcweir            undo context.
245*cdf0e10cSrcweir    */
246*cdf0e10cSrcweir    boolean isRedoPossible();
247*cdf0e10cSrcweir
248*cdf0e10cSrcweir    /** returns the title of the top-most action on the undo stack
249*cdf0e10cSrcweir
250*cdf0e10cSrcweir        @throws EmptyUndoStackException
251*cdf0e10cSrcweir            when the undo stack is currently empty
252*cdf0e10cSrcweir
253*cdf0e10cSrcweir        @see XUndoAction::Title
254*cdf0e10cSrcweir    */
255*cdf0e10cSrcweir    string  getCurrentUndoActionTitle()
256*cdf0e10cSrcweir            raises( ::com::sun::star::document::EmptyUndoStackException );
257*cdf0e10cSrcweir
258*cdf0e10cSrcweir    /** returns the title of the top-most action on the Redo stack
259*cdf0e10cSrcweir
260*cdf0e10cSrcweir        @throws EmptyUndoStackException
261*cdf0e10cSrcweir            when the Redo stack is currently empty
262*cdf0e10cSrcweir        @see XUndoAction::Title
263*cdf0e10cSrcweir    */
264*cdf0e10cSrcweir    string  getCurrentRedoActionTitle()
265*cdf0e10cSrcweir            raises( ::com::sun::star::document::EmptyUndoStackException );
266*cdf0e10cSrcweir
267*cdf0e10cSrcweir    /** returns the titles of all actions currently on the undo stack, from top to bottom
268*cdf0e10cSrcweir        @see XUndoAction::Title
269*cdf0e10cSrcweir    */
270*cdf0e10cSrcweir    sequence< string >
271*cdf0e10cSrcweir            getAllUndoActionTitles();
272*cdf0e10cSrcweir
273*cdf0e10cSrcweir    /** returns the titles of all actions currently on the Redo stack, from top to bottom
274*cdf0e10cSrcweir
275*cdf0e10cSrcweir        @see XUndoAction::Title
276*cdf0e10cSrcweir    */
277*cdf0e10cSrcweir    sequence< string >
278*cdf0e10cSrcweir            getAllRedoActionTitles();
279*cdf0e10cSrcweir
280*cdf0e10cSrcweir    /** clears the undo and the redo stack.
281*cdf0e10cSrcweir
282*cdf0e10cSrcweir        <p>All actions will be removed from both the Undo and the Redo stack. Actions which implement the
283*cdf0e10cSrcweir        <type scope="com::sun::star::lang">XComponent</type> interface will be disposed.</p>
284*cdf0e10cSrcweir
285*cdf0e10cSrcweir        @throws UndoContextNotClosedException
286*cdf0e10cSrcweir            if the method is invoked while an undo context is still open
287*cdf0e10cSrcweir    */
288*cdf0e10cSrcweir    void    clear()
289*cdf0e10cSrcweir            raises( ::com::sun::star::document::UndoContextNotClosedException );
290*cdf0e10cSrcweir
291*cdf0e10cSrcweir    /** clears the redo stack.
292*cdf0e10cSrcweir
293*cdf0e10cSrcweir        <p>All actions will be removed from the Redo stack. Actions which implement the <type scope="com::sun::star::lang">XComponent</type>
294*cdf0e10cSrcweir        interface will be disposed.</p>
295*cdf0e10cSrcweir
296*cdf0e10cSrcweir        @throws UndoContextNotClosedException
297*cdf0e10cSrcweir            if the method is invoked while an undo context is still open
298*cdf0e10cSrcweir    */
299*cdf0e10cSrcweir    void    clearRedo()
300*cdf0e10cSrcweir            raises( ::com::sun::star::document::UndoContextNotClosedException );
301*cdf0e10cSrcweir
302*cdf0e10cSrcweir    /** resets the Undo manager
303*cdf0e10cSrcweir
304*cdf0e10cSrcweir        <p>In particular, this method will
305*cdf0e10cSrcweir            <ul><li>remove all locks from the undo manager</li>
306*cdf0e10cSrcweir                <li>close all open undo contexts</li>
307*cdf0e10cSrcweir                <li>clear the undo stack</li>
308*cdf0e10cSrcweir                <li>clear the redo stack</li>
309*cdf0e10cSrcweir            </ul></p>
310*cdf0e10cSrcweir
311*cdf0e10cSrcweir        <p>Note that possible listeners will not get notifications for the single parts of the reset, i.e. there
312*cdf0e10cSrcweir        will be no single <member>XUndoManagerListener::allActionsCleared</member>,
313*cdf0e10cSrcweir        <member>XUndoManagerListener::leftContext</member>, etc., notifications. Instead, listeners will be
314*cdf0e10cSrcweir        notified of the reset by calling their <member>XUndoManagerListener::resetAll</member> method.</p>
315*cdf0e10cSrcweir    */
316*cdf0e10cSrcweir    void    reset();
317*cdf0e10cSrcweir
318*cdf0e10cSrcweir    /** adds a listener to be notified of changes in the Undo/Redo stacks.
319*cdf0e10cSrcweir    */
320*cdf0e10cSrcweir    void    addUndoManagerListener(
321*cdf0e10cSrcweir                [in] XUndoManagerListener i_listener
322*cdf0e10cSrcweir            );
323*cdf0e10cSrcweir
324*cdf0e10cSrcweir    /** removes a previously added listener
325*cdf0e10cSrcweir    */
326*cdf0e10cSrcweir    void    removeUndoManagerListener(
327*cdf0e10cSrcweir                [in] XUndoManagerListener i_listener
328*cdf0e10cSrcweir            );
329*cdf0e10cSrcweir};
330*cdf0e10cSrcweir
331*cdf0e10cSrcweir//==================================================================================================================
332*cdf0e10cSrcweir
333*cdf0e10cSrcweir}; }; }; };
334*cdf0e10cSrcweir
335*cdf0e10cSrcweir//==================================================================================================================
336*cdf0e10cSrcweir
337*cdf0e10cSrcweir#endif
338