PageRenderTime 64ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/mythtv/libs/libmythfreemheg/Root.h

http://github.com/MythTV/mythtv
C Header | 279 lines | 191 code | 32 blank | 56 comment | 0 complexity | a94cef50feee189bdb53df7e309ee88f MD5 | raw file
Possible License(s): CC-BY-SA-3.0, MIT, GPL-2.0, LGPL-2.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. /* Root.h
  2. Copyright (C) David C. J. Matthews 2004 dm at prolingua.co.uk
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  14. Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  15. */
  16. #if !defined(ROOTCLASS_H)
  17. #define ROOTCLASS_H
  18. #include "BaseClasses.h"
  19. #include "BaseActions.h"
  20. class MHParseNode;
  21. class MHLink;
  22. class MHIngredient;
  23. class MHEngine;
  24. enum EventType { EventIsAvailable = 1, EventContentAvailable, EventIsDeleted, EventIsRunning, EventIsStopped,
  25. EventUserInput, EventAnchorFired, EventTimerFired, EventAsyncStopped, EventInteractionCompleted,
  26. EventTokenMovedFrom, EventTokenMovedTo, EventStreamEvent, EventStreamPlaying, EventStreamStopped,
  27. EventCounterTrigger, EventHighlightOn, EventHighlightOff, EventCursorEnter, EventCursorLeave,
  28. EventIsSelected, EventIsDeselected, EventTestEvent, EventFirstItemPresented, EventLastItemPresented,
  29. EventHeadItems, EventTailItems, EventItemSelected, EventItemDeselected, EventEntryFieldFull,
  30. EventEngineEvent,
  31. // The next two events are added in UK MHEG.
  32. EventFocusMoved, EventSliderValueChanged };
  33. class MHRoot
  34. {
  35. public:
  36. MHRoot() = default;
  37. MHRoot(const MHRoot &/*ref*/) {}
  38. virtual ~MHRoot() = default;
  39. // Initialise - set up the item from the parse tree.
  40. virtual void Initialise(MHParseNode *p, MHEngine *engine); // Set this up from the parse tree.
  41. // Print this item.
  42. virtual void PrintMe(FILE *fd, int nTabs) const;
  43. // Test for shared status.
  44. virtual bool IsShared() { return false; }
  45. // MHEG Actions.
  46. // Preparation - sets up the run-time representation. Sets m_fAvailable and generates IsAvailable event.
  47. virtual void Preparation(MHEngine *engine);
  48. // Activation - starts running the object. Sets m_fRunning and generates IsRunning event.
  49. virtual void Activation(MHEngine *engine);
  50. // Deactivation - stops running the object. Clears m_fRunning
  51. virtual void Deactivation(MHEngine *engine);
  52. // Destruction - deletes the run-time representation. Clears m_fAvailable.
  53. virtual void Destruction(MHEngine *engine);
  54. // Prepare the content - This action is added in the corrigendum to the standard.
  55. virtual void ContentPreparation(MHEngine */*engine*/) {}
  56. // Return an object with a given object number. In the root class this returns this object
  57. // if it matches. Group and Stream classes also search their components.
  58. virtual MHRoot *FindByObjectNo(int n);
  59. // Actions. The default behaviour if a sub-class doesn't override them is to fail.
  60. // Actions on Root class
  61. virtual bool GetAvailabilityStatus() { return m_fAvailable; }
  62. virtual bool GetRunningStatus() { return m_fRunning; }
  63. // Actions on Groups
  64. virtual void SetTimer(int/*nTimerId*/, bool/*fAbsolute*/, int /*nMilliSecs*/, MHEngine */*engine*/)
  65. { InvalidAction("SetTimer"); }
  66. // This isn't an MHEG action as such but is used as part of the implementation of "Clone"
  67. virtual void MakeClone(MHRoot* /*pTarget*/, MHRoot* /*pRef*/, MHEngine */*engine*/)
  68. { InvalidAction("MakeClone"); }
  69. virtual void SetInputRegister(int /*nReg*/, MHEngine */*engine*/)
  70. { InvalidAction("SetInputRegister"); }
  71. // Actions on Ingredients.
  72. virtual void SetData(const MHOctetString &/*included*/, MHEngine */*engine*/)
  73. { InvalidAction("SetData"); }
  74. virtual void SetData(const MHContentRef &/*referenced*/, bool /*fSizeGiven*/,
  75. int /*size*/, bool /*fCCGiven*/, int /*cc*/, MHEngine */*engine*/)
  76. { InvalidAction("SetData"); }
  77. virtual void Preload(MHEngine */*engine*/) { InvalidAction("Preload"); }
  78. virtual void Unload(MHEngine */*engine*/) { InvalidAction("Unload"); }
  79. // The UK MHEG profile only requires cloning for Text, Bitmap and Rectangle.
  80. virtual MHIngredient *Clone(MHEngine */*engine*/) { InvalidAction("Clone"); return nullptr; }
  81. // Actions on Presentables. The Run/Stop actions on presentables and the Activate/Deactivate actions
  82. // on Links have identical effects. They could be merged.
  83. virtual void Run(MHEngine */*engine*/) { InvalidAction("Run"); }
  84. virtual void Stop(MHEngine */*engine*/) { InvalidAction("Stop"); }
  85. // Actions on variables.
  86. virtual void TestVariable(int /*nOp*/, const MHUnion &/*parm*/, MHEngine */*engine*/)
  87. { InvalidAction("TestVariable"); }
  88. virtual void GetVariableValue(MHUnion &/*value*/, MHEngine */*engine*/)
  89. { InvalidAction("GetVariableValue"); }
  90. virtual void SetVariableValue(const MHUnion &/*value*/)
  91. { InvalidAction("SetVariableValue"); }
  92. // Actions on Text objects
  93. virtual void GetTextData(MHRoot * /*pDestination*/, MHEngine */*engine*/)
  94. { InvalidAction("GetTextData"); }
  95. virtual void SetBackgroundColour(const MHColour &/*colour*/, MHEngine */*engine*/)
  96. { InvalidAction("SetBackgroundColour"); }
  97. virtual void SetTextColour(const MHColour &/*colour*/, MHEngine */*engine*/)
  98. { InvalidAction("SetTextColour"); }
  99. virtual void SetFontAttributes(const MHOctetString &/*fontAttrs*/, MHEngine */*engine*/)
  100. { InvalidAction("SetFontAttributes"); }
  101. // Actions on Links
  102. virtual void Activate(bool /*f*/, MHEngine */*engine*/)
  103. { InvalidAction("Activate/Deactivate"); } // Activate/Deactivate
  104. // Actions on Programs.
  105. virtual void CallProgram(bool /*fIsFork*/, const MHObjectRef &/*success*/,
  106. const MHSequence<MHParameter *> &/*args*/, MHEngine */*engine*/)
  107. { InvalidAction("CallProgram"); }
  108. // Actions on TokenGroups
  109. virtual void CallActionSlot(int /*n*/, MHEngine */*engine*/) { InvalidAction("CallActionSlot"); }
  110. virtual void Move(int /*n*/, MHEngine */*engine*/) { InvalidAction("Move"); }
  111. virtual void MoveTo(int /*n*/, MHEngine */*engine*/) { InvalidAction("MoveTo"); }
  112. virtual void GetTokenPosition(MHRoot * /*pResult*/, MHEngine */*engine*/)
  113. { InvalidAction("GetTokenPosition"); }
  114. // Actions on ListGroups
  115. virtual void AddItem(int /*nIndex*/, MHRoot * /*pItem*/, MHEngine */*engine*/)
  116. { InvalidAction("GetCellItem"); }
  117. virtual void DelItem(MHRoot * /*pItem*/, MHEngine */*engine*/)
  118. { InvalidAction("GetCellItem"); }
  119. virtual void GetCellItem(int /*nCell*/, const MHObjectRef &/*itemDest*/, MHEngine */*engine*/)
  120. { InvalidAction("GetCellItem"); }
  121. virtual void GetListItem(int /*nCell*/, const MHObjectRef &/*itemDest*/, MHEngine */*engine*/)
  122. { InvalidAction("GetCellItem"); }
  123. virtual void GetItemStatus(int /*nCell*/, const MHObjectRef &/*itemDest*/, MHEngine */*engine*/)
  124. { InvalidAction("GetItemStatus"); }
  125. virtual void SelectItem(int /*nCell*/, MHEngine */*engine*/) { InvalidAction("SelectItem"); }
  126. virtual void DeselectItem(int /*nCell*/, MHEngine */*engine*/) { InvalidAction("DeselectItem"); }
  127. virtual void ToggleItem(int /*nCell*/, MHEngine */*engine*/) { InvalidAction("ToggleItem"); }
  128. virtual void ScrollItems(int /*nCell*/, MHEngine */*engine*/) { InvalidAction("ScrollItems"); }
  129. virtual void SetFirstItem(int /*nCell*/, MHEngine */*engine*/) { InvalidAction("SetFirstItem"); }
  130. virtual void GetFirstItem(MHRoot * /*pResult*/, MHEngine */*engine*/) { InvalidAction("GetFirstItem"); }
  131. virtual void GetListSize(MHRoot * /*pResult*/, MHEngine */*engine*/) { InvalidAction("GetListSize"); }
  132. // Actions on Visibles.
  133. virtual void SetPosition(int /*nXPosition*/, int /*nYPosition*/, MHEngine */*engine*/)
  134. { InvalidAction("SetPosition"); }
  135. virtual void GetPosition(MHRoot * /*pXPosN*/, MHRoot * /*pYPosN*/)
  136. { InvalidAction("GetPosition"); }
  137. virtual void SetBoxSize(int /*nWidth*/, int /*nHeight*/, MHEngine */*engine*/)
  138. { InvalidAction("SetBoxSize"); }
  139. virtual void GetBoxSize(MHRoot * /*pWidthDest*/, MHRoot * /*HeightDest*/)
  140. { InvalidAction("GetBoxSize"); }
  141. virtual void SetPaletteRef(const MHObjectRef /*newPalette*/, MHEngine */*engine*/)
  142. { InvalidAction("SetPaletteRef"); }
  143. virtual void BringToFront(MHEngine */*engine*/) { InvalidAction("BringToFront"); }
  144. virtual void SendToBack(MHEngine */*engine*/) { InvalidAction("SendToBack"); }
  145. virtual void PutBefore(const MHRoot * /*pRef*/, MHEngine */*engine*/) { InvalidAction("PutBefore"); }
  146. virtual void PutBehind(const MHRoot * /*pRef*/, MHEngine */*engine*/) { InvalidAction("PutBehind"); }
  147. virtual void ResetPosition() { InvalidAction("ResetPosition"); } // Used internally by ListGroup
  148. // Actions on LineArt
  149. virtual void SetFillColour(const MHColour &/*colour*/, MHEngine */*engine*/)
  150. { InvalidAction("SetFillColour"); }
  151. virtual void SetLineColour(const MHColour &/*colour*/, MHEngine */*engine*/)
  152. { InvalidAction("SetLineColour"); }
  153. virtual void SetLineWidth(int /*nWidth*/, MHEngine */*engine*/) { InvalidAction("SetLineWidth"); }
  154. virtual void SetLineStyle(int /*nStyle*/, MHEngine */*engine*/) { InvalidAction("SetLineStyle"); }
  155. // Actions on Bitmaps
  156. virtual void SetTransparency(int /*nTransPerCent*/, MHEngine */*engine*/)
  157. { InvalidAction("SetTransparency"); }
  158. virtual void ScaleBitmap(int /*xScale*/, int /*yScale*/, MHEngine */*engine*/)
  159. { InvalidAction("ScaleBitmap"); }
  160. virtual void SetBitmapDecodeOffset(int /*newXOffset*/, int /*newYOffset*/, MHEngine */*engine*/)
  161. { InvalidAction("SetBitmapDecodeOffset"); }
  162. virtual void GetBitmapDecodeOffset(MHRoot * /*pXOffset*/, MHRoot * /*pYOffset*/)
  163. { InvalidAction("GetBitmapDecodeOffset"); }
  164. // Actions on Dynamic Line Art
  165. virtual void Clear() { InvalidAction(""); }
  166. virtual void GetLineWidth(MHRoot * /*pResult*/) { InvalidAction("GetLineWidth"); }
  167. virtual void GetLineStyle(MHRoot * /*pResult*/) { InvalidAction("GetLineStyle"); }
  168. virtual void GetLineColour(MHRoot * /*pResult*/) { InvalidAction("GetLineColour"); }
  169. virtual void GetFillColour(MHRoot * /*pResult*/) { InvalidAction("GetFillColour"); }
  170. virtual void DrawArcSector(bool /*fIsSector*/, int /*x*/, int /*y*/, int /*width*/, int /*height*/, int /*start*/,
  171. int /*arc*/, MHEngine */*engine*/) { InvalidAction("DrawArc/Sector"); }
  172. virtual void DrawLine(int /*x1*/, int /*y1*/, int /*x2*/, int /*y2*/, MHEngine */*engine*/)
  173. { InvalidAction("DrawLine"); }
  174. virtual void DrawOval(int /*x1*/, int /*y1*/, int /*width*/, int /*height*/, MHEngine */*engine*/)
  175. { InvalidAction("DrawOval"); }
  176. virtual void DrawRectangle(int /*x1*/, int /*y1*/, int /*x2*/, int /*y2*/, MHEngine */*engine*/)
  177. { InvalidAction("DrawRectangle"); }
  178. virtual void DrawPoly(bool /*fIsPolygon*/, int /*nPoints*/, const int * /*xArray*/, const int * /*yArray*/, MHEngine */*engine*/)
  179. { InvalidAction("DrawPoly(gon/line)"); }
  180. // Actions on Video streams.
  181. virtual void ScaleVideo(int /*xScale*/, int /*yScale*/, MHEngine */*engine*/)
  182. { InvalidAction("ScaleVideo"); }
  183. virtual void SetVideoDecodeOffset(int /*newXOffset*/, int /*newYOffset*/, MHEngine */*engine*/)
  184. { InvalidAction("SetVideoDecodeOffset"); }
  185. virtual void GetVideoDecodeOffset(MHRoot * /*pXOffset*/, MHRoot * /*pYOffset*/, MHEngine */*engine*/)
  186. { InvalidAction("GetVideoDecodeOffset"); }
  187. virtual void GetCounterPosition(MHRoot * /*pPos*/, MHEngine */*engine*/)
  188. { InvalidAction("GetCounterPosition"); }
  189. virtual void GetCounterMaxPosition(MHRoot * /*pPos*/, MHEngine */*engine*/)
  190. { InvalidAction("GetCounterMaxPosition"); }
  191. virtual void SetCounterPosition(int /*pos*/, MHEngine */*engine*/)
  192. { InvalidAction("SetCounterPosition"); }
  193. virtual void SetSpeed(int /*speed 0=stop*/, MHEngine */*engine*/)
  194. { InvalidAction("SetSpeed"); }
  195. // Actions on Interactibles.
  196. virtual void SetInteractionStatus(bool /*newStatus*/, MHEngine */*engine*/)
  197. { InvalidAction("SetInteractionStatus"); }
  198. virtual bool GetInteractionStatus(void) { InvalidAction("GetInteractionStatus"); return false; }
  199. virtual void SetHighlightStatus(bool /*newStatus*/, MHEngine */*engine*/)
  200. { InvalidAction("SetHighlightStatus"); }
  201. virtual bool GetHighlightStatus(void) { InvalidAction("GetHighlightStatus"); return false; }
  202. // Actions on Sliders.
  203. virtual void Step(int /*nbSteps*/, MHEngine * /*engine*/) { InvalidAction("Step"); }
  204. virtual void SetSliderValue(int /*nbSteps*/, MHEngine * /*engine*/)
  205. { InvalidAction("SetSliderValue"); }
  206. virtual int GetSliderValue(void) { InvalidAction("GetSliderValue"); return 0; }
  207. virtual void SetPortion(int /*newPortion*/, MHEngine * /*engine*/) { InvalidAction("SetPortion"); }
  208. virtual int GetPortion(void) { InvalidAction("GetPortion"); return 0; }
  209. // Additional action defined in UK MHEG.
  210. virtual void SetSliderParameters(int /*newMin*/, int /*newMax*/, int /*newStep*/, MHEngine * /*engine*/)
  211. { InvalidAction("SetSliderParameters"); }
  212. protected:
  213. void InvalidAction(const char *actionName);
  214. public:
  215. MHObjectRef m_ObjectReference; // Identifier of this object.
  216. virtual const char *ClassName() = 0; // For debugging messages.
  217. protected:
  218. bool m_fAvailable {false}; // Set once Preparation has completed.
  219. bool m_fRunning {false}; // Set once Activation has completed.
  220. friend class MHEngine;
  221. };
  222. // Get Availability Status - Does the object exist and is it available?.
  223. class MHGetAvailabilityStatus: public MHElemAction
  224. {
  225. public:
  226. MHGetAvailabilityStatus(): MHElemAction(":GetAvailabilityStatus") {}
  227. void Initialise(MHParseNode *p, MHEngine *engine) override; // MHElemAction
  228. void Perform(MHEngine *engine) override; // MHElemAction
  229. protected:
  230. void PrintArgs(FILE *fd, int /*nTabs*/) const override // MHElemAction
  231. { m_ResultVar.PrintMe(fd, 0); }
  232. MHObjectRef m_ResultVar;
  233. };
  234. // Get Running Status - Is the object running?.
  235. class MHGetRunningStatus: public MHActionObjectRef
  236. {
  237. public:
  238. MHGetRunningStatus(): MHActionObjectRef(":GetRunningStatus") {}
  239. void CallAction(MHEngine */*engine*/, MHRoot *pTarget, MHRoot *pResult) override // MHActionObjectRef
  240. { pResult->SetVariableValue(pTarget->GetRunningStatus());}
  241. };
  242. #endif