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