InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ActiveScriptState.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Jonathan W. Brown
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 __ActiveScriptState__
25 #define __ActiveScriptState__
26 
27 #include "IAMSPManager.h"
28 #include "IApplication.h"
29 #include "IDialogMgr.h"
30 #include "IScriptEngine.h"
31 
32 #include "CAlert.h"
33 #include "ProgressBar.h"
34 #include "Utils.h"
39 {
40 public:
41  ActiveScriptState(IScriptEngine* eng) : fEng(eng), fShowAlerts(kFalse), fSuppressProgressBars(nil), fSuppressDialogs(kFalse), fShowWGAuthenticationUI(kFalse)
42  {
43  ASSERT_MSG( fEng != nil, "ActiveScriptState is missing IScriptEngine" ) ;
44  if ( fEng )
45  {
46  fEng->AddRef() ;
48  fShowAlerts = CAlert::GetShowAlerts() ;
50  ISession* session = GetExecutionContextSession();
51  if (session)
53  InterfacePtr<IDialogMgr> dialogMgr(app, UseDefaultIID());
54  if (dialogMgr)
55  fSuppressDialogs = dialogMgr->GetSuppressDialogs();
56 
57  InterfacePtr<IAMSPManager> iAMSPManager( session, UseDefaultIID() );
58  if ( iAMSPManager != nil )
59  fShowWGAuthenticationUI = iAMSPManager->IsAuthenticationUIEnabled();
60 
61  // We don't want to clobber the current ShowAlerts or SupressDialogs setting if someone else is trying to supress the UI(e.g. buildacceptance)
62  if(fShowAlerts)
64  if (dialogMgr && !fSuppressDialogs)
65  dialogMgr->SetSuppressDialogs( !fEng->GetShowDialogs() ) ;
66 
67  if ( !fEng->GetShowDialogs() )
68  fSuppressProgressBars = new SuppressProgressBarDisplay();
69  if ( iAMSPManager != nil )
70  iAMSPManager->EnableAuthenticationUI( fEng->GetShowDialogs() );
71  }
72  }
73 
75  {
76  if ( fEng )
77  {
78  InterfacePtr<IApplication> app(GetExecutionContextSession()->QueryApplication());
79  InterfacePtr<IDialogMgr> dialogMgr(app, UseDefaultIID());
80  if (dialogMgr)
81  dialogMgr->SetSuppressDialogs( fSuppressDialogs ) ;
82  CAlert::SetShowAlerts( fShowAlerts ) ;
83 
84  InterfacePtr<IAMSPManager> iAMSPManager( GetExecutionContextSession(), UseDefaultIID() );
85  if ( iAMSPManager != nil )
86  iAMSPManager->EnableAuthenticationUI( fShowWGAuthenticationUI );
87 
89  fEng->Release() ;
90  fEng = nil ;
91  if (fSuppressProgressBars)
92  delete fSuppressProgressBars;
93  }
94  }
95 
96  IScriptEngine* GetScriptEngine()
97  {
98  return fEng ;
99  }
100 
101 private:
102  IScriptEngine* fEng ;
103  SuppressProgressBarDisplay* fSuppressProgressBars;
104  bool16 fShowAlerts ;
105  bool16 fSuppressDialogs ;
106  bool16 fShowWGAuthenticationUI;
107 } ;
108 
109 #endif