InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CmdUtils.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Roey Horns
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __CMDUTILS__
25 #define __CMDUTILS__
26 
27 // these really shouldn't be here - but a lot of files rely on them (- Roey)
28 #include "ISession.h"
29 #include "CreateObject.h"
30 
31 
32 #include "PMTypes.h"
33 #include "CommandID.h"
34 #include "ICommand.h"
35 #include "ICommandSequence.h"
36 #include "ICommandProcessor.h"
37 
38 
39 #include "CmdUtilsMacros.h"
40 
41 
42 
54 class CmdUtils {
55 public:
56  // -----------------------------------------
57  // command creation
58  // -----------------------------------------
59 
64  static ICommand *CreateCommand(ClassID cmdType);
65 
66  // -----------------------------------------
67  // command execution
68  // -----------------------------------------
69 
77  static ErrorCode ProcessCommand(ICommand *cmd);
78 
84  static ErrorCode ScheduleCommand(ICommand *cmd, ICommand::Priority priority = ICommand::kLowPriority);
85 
93  static ErrorCode ExecuteDynamicCommand(ICommand *cmd);
102  static ErrorCode ExecuteDynamicCommand(ICommand *cmd, bool16 isActive);
103 
108  static bool16 ProcessScheduledCmds(ICommand::Priority downToPriority = ICommand::kLowestPriority);
109 
110  // -----------------------------------------
111  // command sequences
112  // -----------------------------------------
113 
120  static ICommandSequence *BeginCommandSequence(const char* trackingData = nullptr);
121 
127  static ErrorCode EndCommandSequence(ICommandSequence *sequence);
128 
137  static IAbortableCmdSeq *BeginAbortableCmdSeq(const char* trackingData = nullptr);
138 
144  static ErrorCode EndCommandSequence(IAbortableCmdSeq *sequence);
145 
151  static ErrorCode AbortCommandSequence(IAbortableCmdSeq *sequence);
152 
158  static SequenceMark SetSequenceMark(const IAbortableCmdSeq *sequence);
159 
165  static ErrorCode RollBackCommandSequence(const IAbortableCmdSeq *sequence, SequenceMark upToMark = SequenceMark());
166 
170  static void EnableBusyCursor(bool16 bEnable);
171 
177  static bool16 IsBusyCursorEnabled();
178 
182  static int32 GetMaxStackHeight();
183 
200  {
201  public:
205  SequenceContext(const PMString *name = nil);
211  bool16 Success() { return kSuccess == State(); }
216  ErrorCode State();
217 
218  private:
219  ICommandSequence* fSequence;
220  };
221 
234  {
235  public:
238  explicit SequencePtr() :
239  fSequence(CmdUtils::BeginCommandSequence(CONCAT_NAMES(__FILE__, __LINE__)))
240  {}
244  ~SequencePtr();
245 
248  bool16 Success() { return kSuccess == State(); }
253  ErrorCode State();
257  ICommandSequence* operator->() { return fSequence; }
258 
259  private:
260  //These are not implemented. They are private to prevent use.
261  SequencePtr(const SequencePtr&);
262  SequencePtr& operator=(const SequencePtr&);
263 
264  private:
265  ICommandSequence* fSequence;
266  };
267 
269  static ErrorCode ExecuteCommand(ICommand *cmd);
271  static ErrorCode LWProcessCommand(ICommand *cmd);
273  static bool8 IsCommandLWProcessed(ICommand *cmd);
274 
283  static IAutoUndoSequence *BeginAutoUndoSequence(IDataBase* target, const char* trackingData=nullptr);
284 
289  static ErrorCode EndAutoUndoSequence(IAutoUndoSequence *arg);
290 
296  {
297 
298  public:
302  explicit AutoUndoSequencePtr(IDataBase* target)
303  : fCookie(nil)
304  {
305  if (target)
306  fCookie = CmdUtils::BeginAutoUndoSequence(target, CONCAT_NAMES(__FILE__, __LINE__));
307  }
311  {
312  if (fCookie)
314  }
315 
316  private:
317  //These are not implemented. They are private to prevent use.
319  AutoUndoSequencePtr& operator=(const AutoUndoSequencePtr&);
320 
321  private:
322  IAutoUndoSequence* fCookie;
323  };
324 
325 private:
326 #ifdef DEBUG
327 
328  enum { kMaxStackHeight = 1500 };
329 #else
330  #ifdef MACINTOSH
331  enum { kMaxStackHeight = 25000 };
332  #else
333  #ifdef _M_IX86
334  enum { kMaxStackHeight = 10000 };
335  #else
336  enum { kMaxStackHeight = 25000 };
337  #endif
338  #endif
339 #endif
340 };
341 
342 
343 #endif // __CMDUTILS__