OptionalContent.h 3.65 KB
Newer Older
1 2 3 4 5
//========================================================================
//
// OptionalContent.h
//
// Copyright 2007 Brad Hards <bradh@kde.org>
6
// Copyright 2008 Carlos Garcia Campos <carlosgc@gnome.org>
7
// Copyright 2013, 2018 Albert Astals Cid <aacid@kde.org>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
//
// Released under the GPL (version 2, or later, at your option)
//
//========================================================================

#ifndef OPTIONALCONTENT_H
#define OPTIONALCONTENT_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

#include "Object.h"
#include "CharTypes.h"

class GooString;
class GooList;
class XRef;

27 28
class OptionalContentGroup;
class OCDisplayNode;
29 30 31 32 33 34 35 36 37

//------------------------------------------------------------------------

class OCGs {
public:

  OCGs(Object *ocgObject, XRef *xref);
  ~OCGs();

38 39 40
  OCGs(const OCGs &) = delete;
  OCGs& operator=(const OCGs &) = delete;

41 42 43
  // Is OCGS valid?
  GBool isOk() { return ok; }
  
44 45 46 47 48
  bool hasOCGs();
  GooList *getOCGs() const { return optionalContentGroups; }

  OptionalContentGroup* findOcgByRef( const Ref &ref);

49 50 51 52
  // Get the root node of the optional content group display tree
  // (which does not necessarily include all of the OCGs).
  OCDisplayNode *getDisplayRoot();

53 54 55 56
  Array* getOrderArray() 
    { return (order.isArray() && order.arrayGetLength() > 0) ? order.getArray() : NULL; }
  Array* getRBGroupsArray() 
    { return (rbgroups.isArray() && rbgroups.arrayGetLength()) ? rbgroups.getArray() : NULL; }
57 58 59 60

  bool optContentIsVisible( Object *dictRef );

private:
61
  GBool ok;
62 63

  GBool evalOCVisibilityExpr(Object *expr, int recursion);
64 65 66 67 68 69 70
  bool allOn( Array *ocgArray );
  bool allOff( Array *ocgArray );
  bool anyOn( Array *ocgArray );
  bool anyOff( Array *ocgArray );

  GooList *optionalContentGroups;

71 72
  Object order;
  Object rbgroups;
73
  XRef *m_xref;
74
  OCDisplayNode *display; // root node of display tree
75 76 77 78 79 80 81 82
};

//------------------------------------------------------------------------

class OptionalContentGroup {
public:
  enum State { On, Off };

83 84 85 86 87 88 89
  // Values from the optional content usage dictionary.
  enum UsageState {
    ocUsageOn,
    ocUsageOff,
    ocUsageUnset
  };

90
  OptionalContentGroup(Dict *dict);
91 92 93 94 95

  OptionalContentGroup(GooString *label);

  ~OptionalContentGroup();

96 97 98
  OptionalContentGroup(const OptionalContentGroup &) = delete;
  OptionalContentGroup& operator=(const OptionalContentGroup &) = delete;

99
  GooString* getName() const;
100

101
  Ref getRef() const;
102 103
  void setRef(const Ref ref);

104
  State getState() { return m_state; };
105 106
  void setState(State state) { m_state = state; };

107 108 109
  UsageState getViewState() { return viewState; }
  UsageState getPrintState() { return printState; }

110 111 112
private:
  GooString *m_name;
  Ref m_ref;
113 114 115
  State m_state;
  UsageState viewState;	 // suggested state when viewing
  UsageState printState; // suggested state when printing
116 117
};

118 119 120 121 122 123 124 125 126
//------------------------------------------------------------------------

class OCDisplayNode {
public:

  static OCDisplayNode *parse(Object *obj, OCGs *oc, XRef *xref, int recursion = 0);
  OCDisplayNode();
  ~OCDisplayNode();

127 128 129
  OCDisplayNode(const OCDisplayNode &) = delete;
  OCDisplayNode& operator=(const OCDisplayNode &) = delete;

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  GooString *getName() { return name; }
  OptionalContentGroup *getOCG() { return ocg; }
  int getNumChildren();
  OCDisplayNode *getChild(int idx);

private:

  OCDisplayNode(GooString *nameA);
  OCDisplayNode(OptionalContentGroup *ocgA);
  void addChild(OCDisplayNode *child);
  void addChildren(GooList *childrenA);
  GooList *takeChildren();

  GooString *name;		// display name (may be NULL)
  OptionalContentGroup *ocg;	// NULL for display labels
  GooList *children;		// NULL if there are no children
				//   [OCDisplayNode]
};

149
#endif