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