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