InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CommandFactory.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Michael Burbidge
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 __CommandFactory_h__
25 #define __CommandFactory_h__
26 
27 #include "ICommandFactory.h"
28 #include "IBehaviorData.h"
29 #include "CmdUtils.h"
30 #include "CPMUnknown.h"
31 #include "BehaviorID.h"
32 
38 template <int32 CreateCmd, int32 EditCmd, int32 DeleteCmd, int32 DeferredScrapCmd>
39 class CommandFactory : public CPMUnknown<ICommandFactory>
40 {
41 public:
46  CPMUnknown<ICommandFactory>(boss) { }
47 
50  virtual ~CommandFactory() { }
51 
55  virtual ICommand* CreateCreateCommand() const
56  {
57  ICommand* cmd = CmdUtils::CreateCommand (CreateCmd);
58 
59  InterfacePtr<IBehaviorData> actionData(this, UseDefaultIID());
60  InterfacePtr<IBehaviorData> cmdActionData(cmd, UseDefaultIID());
61 
62  cmdActionData->Copy(actionData);
63 
64  return cmd;
65  }
66 
70  virtual ICommand* CreateEditCommand() const
71  {
72  ICommand* cmd = CmdUtils::CreateCommand (EditCmd);
73 
74  InterfacePtr<IBehaviorData> actionData(this, UseDefaultIID());
75  InterfacePtr<IBehaviorData> cmdActionData(cmd, UseDefaultIID());
76 
77  cmdActionData->Copy(actionData);
78 
79  return cmd;
80  }
81 
85  virtual ICommand* CreateDeleteCommand() const
86  {
87  ICommand* cmd = CmdUtils::CreateCommand (DeleteCmd);
88  return cmd;
89  }
90 
95  {
96  ICommand* cmd = nil;
97 
98  if (DeferredScrapCmd != kNoOpCmdBoss)
99  cmd = CmdUtils::CreateCommand (DeferredScrapCmd);
100 
101  return cmd;
102  }
103 };
104 
105 #endif // __CommandFactory_h__