InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ScriptInfoDefs.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 __SCRIPTINFODEFS__
25 #define __SCRIPTINFODEFS__
26 
27 #include "K2Vector.h"
28 #include "K2Pair.h"
29 #include "RequestContext.h"
30 #include "ScriptingID.h"
31 
32 class IScriptProvider ;
33 
34 namespace ScriptInfo
35 {
36 
37 //----------------------------------------------------------------------------
38 // Enum definitions
39 //----------------------------------------------------------------------------
40 
44 enum ScriptElementType
45 {
47  kNoElement = 0x00,
49  kSuiteElement = 0x01,
51  kObjectElement = 0x02,
53  kMethodElement = 0x04,
55  kMethodParameterElement = 0x08,
57  kPropertyElement = 0x10,
59  kEnumElement = 0x20,
61  kEnumValueElement = 0x40,
63  kTypeDefElement = 0x80,
65  kEventElement = 0x100,
67  kStructField = 0x1000
68 } ;
69 
73 enum ErrorPolicy
74 {
76  kIgnoreErrors,
78  kReturnFirstError,
80  kReturnCompleteFailureOnly
81 } ;
82 
86 enum TypeFormattingInfo
87 {
89  kIncludeTypeInfo = 0,
91  kIncludeRangeData = 1,
93  kIncludeDefaultValue = 2,
95  kFormatAsPlural = 4,
96 
98  kGetEnumTypeByName = 0x10000000,
100  kDontTranslateKeyStringDefaultType = 0x20000000,
101 } ;
102 
106 enum SetPropertiesOrderPolicy
107 {
109  kDefaultOrder = 0,
111  kCustomOrder = 1
112 } ;
113 
114 //----------------------------------------------------------------------------
115 // Class definitions
116 //----------------------------------------------------------------------------
117 
123 {
124  public:
127  {
136  } ;
137 
139  enum Spacing
140  {
149  } ;
150 
152  FormatNamePolicy() :
153  fCapitalization( kUseDefaultCapitalization ), fSpacing( kUseDefaultSpacing ), fPrefix(), fSuffix() {}
155  FormatNamePolicy( Capitalization c, Spacing s, const PMString& prefix, const PMString& suffix ) :
156  fCapitalization( c ), fSpacing( s ), fPrefix( prefix ), fSuffix( suffix ) {}
157 
159  Capitalization GetCapitalization() const { return fCapitalization ; }
161  Spacing GetSpacing() const { return fSpacing ; }
163  const PMString& GetPrefix() const { return fPrefix ; }
165  const PMString& GetSuffix() const { return fSuffix ; }
166 
168  bool16 operator==( const FormatNamePolicy& other ) const { return ( fCapitalization == other.fCapitalization &&
169  fSpacing == other.fSpacing &&
170  fPrefix == other.fPrefix &&
171  fSuffix == other.fSuffix ) ; }
172 
174  void FormatName( PMString& name ) const ;
175 
176 private:
177  Capitalization fCapitalization ;
178  Spacing fSpacing ;
179  PMString fPrefix ;
180  PMString fSuffix ;
181 } ;
182 
183 class TypeDefScriptElement ;
184 class SuiteScriptElement ;
185 class ObjectScriptElement ;
186 class MethodScriptElement ;
187 class PropertyScriptElement ;
188 class EnumScriptElement ;
189 class EventScriptElement ;
190 
192 typedef K2Vector<ScriptID> ScriptIDList ;
194 typedef K2Vector<ScriptElementID> ScriptElementIDList ;
196 typedef K2Vector<const ObjectScriptElement*> ObjectScriptElementList ;
198 typedef K2Vector<const MethodScriptElement*> MethodScriptElementList ;
200 typedef K2Vector<const PropertyScriptElement*> PropertyScriptElementList ;
202 typedef K2Vector<const EventScriptElement*> EventScriptElementList ;
203 
205 typedef std::pair<uint32, uint32> ScriptMethodUniqueID;
207 typedef std::vector<ScriptMethodUniqueID> ScriptMethodUniqueIDList;
208 
214 template <class SI>
216 {
217  public:
219  ScriptElementIterator( const SI* const* inBegin, const SI* const* inEnd ) : fCurrent( inBegin ), fEnd( inEnd ) {}
221  ScriptElementIterator( const ScriptElementIterator& sei ) : fCurrent( sei.fCurrent ), fEnd( sei.fEnd ) {}
222 
224  ScriptElementIterator& operator++() { ++fCurrent ; return *this ;}
225 
227  operator const SI*() const { return *fCurrent ; }
229  const SI* operator->() const { return *fCurrent ; }
230 
232  const SI* const* current() const { return fCurrent ; }
234  const SI* const* end() const { return fEnd ; }
235 
236  private:
237  const SI* const* fCurrent ;
238  const SI* const* fEnd ;
239 
240  private:
241  //hide
242  ScriptElementIterator operator++(int) ; //{ ScriptElementIterator tmp(*this) ; ++(*this) ; return tmp ; }
243  ScriptElementIterator& operator=( const ScriptElementIterator& ) ;
244  bool16 operator==( const ScriptElementIterator& ) const ;
245 } ;
246 
248 typedef ScriptElementIterator<TypeDefScriptElement> TypeDefElementIterator ;
250 typedef ScriptElementIterator<SuiteScriptElement> SuiteElementIterator ;
252 typedef ScriptElementIterator<ObjectScriptElement> ObjectElementIterator ;
254 typedef ScriptElementIterator<MethodScriptElement> MethodElementIterator ;
256 typedef ScriptElementIterator<PropertyScriptElement> PropertyElementIterator ;
258 typedef ScriptElementIterator<EnumScriptElement> EnumElementIterator ;
260 typedef ScriptElementIterator<EventScriptElement> EventElementIterator ;
261 
268 {
269  public:
271  ElementContext() : fLocale(), fFirstVersion( kMinimumScriptVersion ), fLastVersion( kMaximumScriptVersion ), fClient( kCoreScriptManagerBoss ) {}
273  ElementContext( const PMLocaleId& locale, const ScriptVersion& firstVersion, const ScriptVersion& lastVersion, const ScriptClient& client ) :
274  fLocale( locale ), fFirstVersion( firstVersion ), fLastVersion( lastVersion ), fClient( client ) {}
276  ElementContext( const ElementContext& other ) { *this = other ; }
278  ~ElementContext() {}
279 
281  const PMLocaleId& GetLocale() const { return fLocale ; }
283  const ScriptVersion& GetFirstVersion() const { return fFirstVersion ; }
285  const ScriptVersion& GetLastVersion() const { return fLastVersion ; }
287  const ScriptClient& GetClient() const { return fClient ; }
288 
290  ElementContext& operator=( const ElementContext& ) ;
292  bool16 operator==( const ElementContext& other ) const { return ( fLocale == other.fLocale &&
293  fFirstVersion == other.fFirstVersion &&
294  fLastVersion == other.fLastVersion &&
295  fClient == other.fClient ) ; }
297  void ReadWrite( IPMStream* s ) ;
298 
299  private:
300  PMLocaleId fLocale ; //defined in PMLocaleId.h
301  ScriptVersion fFirstVersion ; //The first version for which this element applies (minimum is 0.0)
302  ScriptVersion fLastVersion ; //The first version for which this element is obsolete (maximum is kMaxInt32.kMaxInt32 (0x7FFFFFFF))
303  ScriptClient fClient ; //kCoreScriptManagerBoss indicates "always match"
304 
305 #ifdef ID_ENABLE_DEBUGGING
306  public:
308  ConstCString WhoAmI() const ;
309  mutable scoped_array<char> fWhoAmI ;
310 #endif
311 } ;
312 
319 {
320  public:
321  typedef object_type data_type ;
322 
324  ProviderPacket( const ElementContext& context, const ClassID& provider, const PluginID& pluginID,
325  bool16 surrogate, uint8 inheritance ) :
326  fContext( context ), fProvider( provider ), fPluginID( pluginID ), fSurrogate( surrogate ), fInheritance( inheritance ) {}
327 
329  const ElementContext& GetContext() const { return fContext ; }
331  const ClassID& GetProvider() const { return fProvider ; }
333  const PluginID& GetPluginID() const { return fPluginID ; }
334 
337 
339  void SetPluginID( const PluginID& pluginID ) { fPluginID = pluginID ; }
340 
341 #ifdef ID_ENABLE_DEBUGGING
342 
343  virtual ConstCString WhoAmI() const = 0 ;
344 #endif
345 
347  bool16 IsSurrogate() const { return fSurrogate ; }
349  bool16 IsInherited() const { return fInheritance > 0 ; }
351  uint8 GetInheritance() const { return fInheritance ; }
352 
353 private:
354  ElementContext fContext ;
355  ClassID fProvider ; //kInvalidClass for "don't match"
356  PluginID fPluginID ;
357  bool16 fSurrogate ; //A surrogate is not a formal parent/child relationship in the DOM hierarchy
358  uint8 fInheritance ;
359 } ;
360 
363 {
364  public:
366  ParentProviderPacket( const ObjectScriptElement* parent, const ElementContext& context, const ClassID& provider,
367  const PluginID& pluginID, bool16 surrogate, uint8 inheritance ) :
368  ProviderPacket( context, provider, pluginID, surrogate, inheritance ), fParent( parent ) {}
369 
371  const ObjectScriptElement* Element() const { return fParent ; }
372 
373 #ifdef ID_ENABLE_DEBUGGING
374 
375  virtual ConstCString WhoAmI() const ;
376 #endif
377 
378  private:
379  const ObjectScriptElement* fParent ;
380 } ;
381 
384 {
385  public:
387  ChildProviderPacket( const ObjectScriptElement* child, const ElementContext& context, const ClassID& provider,
388  const PluginID& pluginID, bool16 surrogate, uint8 inheritance ) :
389  ProviderPacket( context, provider, pluginID, surrogate, inheritance ), fChild( child ) {}
390 
392  const ObjectScriptElement* Element() const { return fChild ; }
393 
394 #ifdef ID_ENABLE_DEBUGGING
395 
396  virtual ConstCString WhoAmI() const ;
397 #endif
398 
399  private:
400  const ObjectScriptElement* fChild ;
401 } ;
402 
405 {
406  public:
408  MethodProviderPacket( const MethodScriptElement* method, const ElementContext& context, const ClassID& provider,
409  const PluginID& pluginID ) :
410  ProviderPacket( context, provider, pluginID, kFalse, 0 ), fMethod( method ) {}
411 
413  const MethodScriptElement* Element() const { return fMethod ; }
414 
415 #ifdef ID_ENABLE_DEBUGGING
416 
417  virtual ConstCString WhoAmI() const ;
418 #endif
419 
420  private:
421  const MethodScriptElement* fMethod ;
422 } ;
423 
426 {
427  public:
429  CollectionMethodProviderPacket( const MethodScriptElement* method, const ElementContext& context, const ClassID& provider,
430  const PluginID& pluginID, const ObjectScriptElement* parent, uint8 inheritance ) :
431  ProviderPacket( context, provider, pluginID, kFalse, inheritance ), fMethod( method ), fParent( parent ) {}
432 
434  const MethodScriptElement* Element() const { return fMethod ; }
436  const ObjectScriptElement* Parent() const { return fParent ; }
437 
438 #ifdef ID_ENABLE_DEBUGGING
439 
440  virtual ConstCString WhoAmI() const ;
441 #endif
442 
443  private:
444  const MethodScriptElement* fMethod ;
445  const ObjectScriptElement* fParent ;
446 } ;
447 
450 {
451  public:
453  PropertyProviderPacket( const PropertyScriptElement* property, const ElementContext& context, const ClassID& provider,
454  const PluginID& pluginID, bool16 readonly ) :
455  ProviderPacket( context, provider, pluginID, kFalse, 0 ), fProperty( property ), fReadOnly( readonly ) {}
456 
458  const PropertyScriptElement* Element() const { return fProperty ; }
460  bool16 IsReadWrite() const { return !fReadOnly ; }
462  bool16 IsReadOnly() const { return fReadOnly ; }
463 
464 #ifdef ID_ENABLE_DEBUGGING
465 
466  virtual ConstCString WhoAmI() const ;
467 #endif
468 
469  private:
470  const PropertyScriptElement* fProperty ;
471  bool16 fReadOnly ;
472 } ;
473 
476 {
477  public:
479  EventProviderPacket( const EventScriptElement* event, const ElementContext& context, const ClassID& provider,
480  const PluginID& pluginID ) :
481  ProviderPacket( context, provider, pluginID, kFalse, 0 ), fEvent( event ) {}
482 
484  const EventScriptElement* Element() const { return fEvent ; }
485 
486 #ifdef ID_ENABLE_DEBUGGING
487 
488  virtual ConstCString WhoAmI() const ;
489 #endif
490 
491  private:
492  const EventScriptElement* fEvent ;
493 } ;
494 
496 typedef K2Vector<ParentProviderPacket> ParentProviderLookup ;
498 typedef K2Vector<ChildProviderPacket> ChildProviderLookup ;
500 typedef K2Vector<MethodProviderPacket> MethodProviderLookup ;
502 typedef K2Vector<CollectionMethodProviderPacket> CollectionMethodProviderLookup ;
504 typedef K2Vector<PropertyProviderPacket> PropertyProviderLookup ;
506 typedef K2Vector<EventProviderPacket> EventProviderLookup ;
507 
508 class AccessParents ;
509 class AccessChildren ;
510 class AccessMethods ;
511 class AccessCollectionMethods ;
512 class AccessProperties ;
513 class AccessEvents ;
514 
520 template <class SI, class PP, class Access>
522 {
523  public:
524  typedef PP packet_type ;
525  typedef Access access_type ;
526 
528  ProviderPacketIterator( const SI* pSI, bool16 iterateBaseObjects, Access filter = Access() ) :
529  fSI( pSI ),
530  fIterateBaseObjects( iterateBaseObjects ),
531  fCurrent( nil ),
532  fEnd( nil ),
533  fAlreadySeen(),
534  fFilter( filter )
535  {
536  Initialize() ;
537  }
540  fSI( ppi.fSI ),
541  fIterateBaseObjects( ppi.fIterateBaseObjects ),
542  fCurrent( ppi.fCurrent ),
543  fEnd( ppi.fEnd ),
544  fAlreadySeen( ppi.fAlreadySeen ),
545  fFilter( ppi.fFilter )
546  {}*/
547 
549  ProviderPacketIterator& operator++(){ ++fCurrent ; IterateUntilValid() ; return *this ;}
550 
552  operator const PP*() const { return fCurrent ; }
554  const PP* operator->() const { return fCurrent ; }
555 
557  const PP* current() const { return fCurrent ; }
559  const PP* end() const { return fEnd ; }
560 
561  private:
563  void Initialize()
564  {
565  if ( fSI )
566  {
567  fCurrent = fSI->GetElements( (Access*) nil ).begin() ;
568  fEnd = fSI->GetElements( (Access*) nil ).end() ;
569  IterateUntilValid() ;
570  }
571  }
572 
574  void IterateUntilValid()
575  {
576  //Apply filter and skip duplicate elements
577  while ( fCurrent != fEnd && SkipPacket() )
578  ++fCurrent ;
579 
580  //Cache elements we've seen
581  if ( fCurrent != fEnd )
582  fAlreadySeen.push_back( fCurrent ) ;
583 
584  //Skip elements that are not supported (no provider)
585  if ( fCurrent != fEnd && fCurrent->GetProvider() == kInvalidClass )
586  {
587  ++fCurrent ;
588  IterateUntilValid() ;
589  }
590 
591  //Iterate the elements on the base object, if any
592  if ( fIterateBaseObjects && fCurrent == fEnd )
593  {
594  if ( fSI != nil )
595  fSI = fSI->FindBaseObject() ;
596 
597  Initialize() ;
598  }
599  }
600 
602  bool16 SkipPacket() const
603  {
604  if ( fFilter.SkipPacket( fCurrent ) )
605  return kTrue ;
606 
607  for ( const PP* const* iter = fAlreadySeen.begin() ; iter != fAlreadySeen.end() ; ++iter )
608  {
609  if ( fFilter.Matches( *iter, fCurrent ) )
610  return kTrue ;
611  }
612  return kFalse ;
613  }
614 
615  private:
616  const SI* fSI ;
617  bool16 fIterateBaseObjects ;
618  const PP* fCurrent ;
619  const PP* fEnd ;
620  K2Vector<const PP*> fAlreadySeen ;
621  Access fFilter ;
622 
623  private:
624  //hide
625  ProviderPacketIterator operator++(int) ; //{ ProviderPacketIterator tmp(*this) ; ++(*this) ; return tmp ; }
626  ProviderPacketIterator& operator=( const ProviderPacketIterator& ) ;
627  bool16 operator==( const ProviderPacketIterator& ) const ;
628 } ;
629 
631 typedef ProviderPacketIterator<ObjectScriptElement, ParentProviderPacket, AccessParents> ParentProviderIterator ;
633 typedef ProviderPacketIterator<ObjectScriptElement, ChildProviderPacket, AccessChildren> ChildProviderIterator ;
635 typedef ProviderPacketIterator<ObjectScriptElement, MethodProviderPacket, AccessMethods> MethodProviderIterator ;
637 typedef ProviderPacketIterator<ObjectScriptElement, CollectionMethodProviderPacket, AccessCollectionMethods> CollectionMethodProviderIterator ;
639 typedef ProviderPacketIterator<ObjectScriptElement, PropertyProviderPacket, AccessProperties> PropertyProviderIterator ;
641 typedef ProviderPacketIterator<ObjectScriptElement, EventProviderPacket, AccessEvents> EventProviderIterator ;
642 //Note: ObjectScriptElement has to be specified as a template class argument because it hasn't been defined yet
643 
645 typedef bool16 (*PacketComp)(const ChildProviderPacket left, const ChildProviderPacket right);
646 
647 } // End namespace ScriptInfo
648 
649 #endif //__SCRIPTINFODEFS__