MythTV  master
Text.h
Go to the documentation of this file.
1 /* Text.h
2 
3  Copyright (C) David C. J. Matthews 2004 dm at prolingua.co.uk
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  as published by the Free Software Foundation; either version 2
8  of the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18  Or, point your browser to http://www.gnu.org/copyleft/gpl.html
19 
20 */
21 
22 
23 #if !defined(TEXT_H)
24 #define TEXT_H
25 
26 #include "Visible.h"
27 #include "BaseActions.h"
28 // Dependencies
29 #include "Presentable.h"
30 #include "Ingredients.h"
31 #include "Root.h"
32 #include "BaseClasses.h"
33 
34 class MHEngine;
35 class MHTextDisplay;
36 
37 class MHText : public MHVisible
38 {
39  public:
40  MHText() = default;
41  MHText(const MHText &ref);
42  ~MHText();
43  const char *ClassName() override // MHRoot
44  { return "Text"; }
45  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHVisible
46  void PrintMe(FILE *, int nTabs) const override; // MHVisible
47 
48  void Preparation(MHEngine *engine) override; // MHVisible
49  void ContentPreparation(MHEngine *engine) override; // MHIngredient
50  void ContentArrived(const unsigned char *data, int length, MHEngine *engine) override; // MHIngredient
51 
52  // Actions.
53  // Extract the text from an object. This can be used to load content from a file.
54  void GetTextData(MHRoot *pDestination, MHEngine *) override // MHRoot
55  { pDestination->SetVariableValue(m_Content); }
56  MHIngredient *Clone(MHEngine *) override // MHRoot
57  { return new MHText(*this); } // Create a clone of this ingredient.
58  void SetBackgroundColour(const MHColour &colour, MHEngine *engine) override; // MHRoot
59  void SetTextColour(const MHColour &colour, MHEngine *engine) override; // MHRoot
60  void SetFontAttributes(const MHOctetString &fontAttrs, MHEngine *engine) override; // MHRoot
61 
62  // Enumerated type lookup functions for the text parser.
63  static int GetJustification(const char *str);
64  static int GetLineOrientation(const char *str);
65  static int GetStartCorner(const char *str);
66 
67  // Display function.
68  void Display(MHEngine *engine) override; // MHVisible
69  QRegion GetOpaqueArea() override; // MHVisible
70 
71  protected:
72  void Redraw();
73 
77  int m_nCharSet {-1};
78 
86  bool m_fTextWrap {false};
87  // Internal attributes. The font colour, background colour and font attributes are
88  // internal attributes in UK MHEG.
89 // MHFontBody m_Font;
92  MHOctetString m_Content; // The content as an octet string
93 
94  MHTextDisplay *m_pDisplay {nullptr}; // Pointer to the display object.
95  bool m_fNeedsRedraw {false};
96 
97  // Create the Unicode content from the character input.
98  void CreateContent(const unsigned char *p, int s, MHEngine *engine);
99 };
100 
101 class MHHyperText : public MHText, public MHInteractible
102 {
103  public:
105  const char *ClassName() override // MHText
106  { return "HyperText"; }
107  virtual ~MHHyperText() = default;
108  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHText
109  void PrintMe(FILE *fd, int nTabs) const override; // MHText
110 
111  // Implement the actions in the main inheritance line.
112  void SetInteractionStatus(bool newStatus, MHEngine *engine) override // MHRoot
113  { InteractSetInteractionStatus(newStatus, engine); }
114  bool GetInteractionStatus(void) override // MHRoot
115  { return InteractGetInteractionStatus(); }
116  void SetHighlightStatus(bool newStatus, MHEngine *engine) override // MHRoot
117  { InteractSetHighlightStatus(newStatus, engine); }
118  bool GetHighlightStatus(void) override // MHRoot
119  { return InteractGetHighlightStatus(); }
120  void Deactivation(MHEngine */*engine*/) override // MHVisible
121  { InteractDeactivation(); }
122 };
123 
124 // Get Text Data - get the data out of a text object.
126 {
127  public:
128  MHGetTextData(): MHActionObjectRef(":GetTextData") {}
129  void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg) override // MHActionObjectRef
130  { pTarget->GetTextData(pArg, engine); }
131 };
132 
133 // Actions added in UK MHEG profile.
135  public:
136  MHSetBackgroundColour(): MHSetColour(":SetBackgroundColour") { }
137  protected:
138  void SetColour(const MHColour &colour, MHEngine *engine) override // MHSetColour
139  { Target(engine)->SetBackgroundColour(colour, engine); }
140 };
141 
143  public:
144  MHSetTextColour(): MHSetColour(":SetTextColour") { }
145  protected:
146  void SetColour(const MHColour &colour, MHEngine *engine) override // MHSetColour
147  { Target(engine)->SetTextColour(colour, engine); }
148 };
149 
151 {
152  public:
153  MHSetFontAttributes(): MHElemAction(":SetFontAttributes") {}
154  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHElemAction
155  void Perform(MHEngine *engine) override; // MHElemAction
156  protected:
157  void PrintArgs(FILE *fd, int /*nTabs*/) const override // MHElemAction
158  { m_FontAttrs.PrintMe(fd, 0); }
159  MHGenericOctetString m_FontAttrs; // New font attributes.
160 };
161 
162 
163 
164 #endif
void PrintMe(FILE *, int nTabs) const override
Definition: Text.cpp:203
MHText()=default
MHIngredient * Clone(MHEngine *) override
Definition: Text.h:56
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Text.cpp:906
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Text.cpp:57
bool GetHighlightStatus(void) override
Definition: Text.h:118
virtual void SetTextColour(const MHColour &, MHEngine *)
Definition: Root.h:106
void Deactivation(MHEngine *) override
Definition: Text.h:120
void Display(MHEngine *engine) override
Definition: Text.cpp:857
Justification m_HorizJ
Definition: Text.h:82
void PrintMe(FILE *fd, int nTabs) const
void CreateContent(const unsigned char *p, int s, MHEngine *engine)
Definition: Text.cpp:357
int m_nCharSet
Definition: Text.h:77
MHRoot * Target(MHEngine *engine)
Definition: BaseActions.cpp:46
const char * ClassName() override
Definition: Text.h:105
~MHText()
Definition: Text.cpp:51
void PrintMe(FILE *fd, int nTabs) const override
Definition: Text.cpp:894
void GetTextData(MHRoot *pDestination, MHEngine *) override
Definition: Text.h:54
void InteractSetInteractionStatus(bool newStatus, MHEngine *engine)
Definition: Visible.cpp:548
void SetColour(const MHColour &colour, MHEngine *engine) override
Definition: Text.h:146
MHColour m_textColour
Definition: Text.h:90
MHColour m_OriginalBgColour
Definition: Text.h:76
LineOrientation
Definition: Text.h:80
MHHyperText()
Definition: Text.h:104
void SetBackgroundColour(const MHColour &colour, MHEngine *engine) override
Definition: Text.cpp:372
MHOctetString m_fontAttrs
Definition: Text.h:91
MHFontBody m_OrigFont
Definition: Text.h:74
QRegion GetOpaqueArea() override
Definition: Text.cpp:877
MHColour m_OriginalTextColour
Definition: Text.h:76
bool GetInteractionStatus(void) override
Definition: Text.h:114
MHOctetString m_OriginalFontAttrs
Definition: Text.h:75
static int GetLineOrientation(const char *str)
Definition: Text.cpp:169
void SetHighlightStatus(bool newStatus, MHEngine *engine) override
Definition: Text.h:116
void SetInteractionStatus(bool newStatus, MHEngine *engine) override
Definition: Text.h:112
virtual ~MHHyperText()=default
void SetTextColour(const MHColour &colour, MHEngine *engine) override
Definition: Text.cpp:365
void InteractDeactivation(void)
Definition: Visible.h:160
MHTextDisplay * m_pDisplay
Definition: Text.h:94
void ContentArrived(const unsigned char *data, int length, MHEngine *engine) override
Definition: Text.cpp:346
bool InteractGetHighlightStatus(void)
Definition: Visible.h:157
bool InteractGetInteractionStatus(void)
Definition: Visible.h:155
static int GetStartCorner(const char *str)
Definition: Text.cpp:190
void PrintArgs(FILE *fd, int) const override
Definition: Text.h:157
Definition: Root.h:43
int FILE
Definition: mythburn.py:110
static int GetJustification(const char *str)
Definition: Text.cpp:150
void Redraw()
Definition: Text.cpp:539
bool m_fTextWrap
Definition: Text.h:86
MHOctetString m_Content
Definition: Text.h:92
void ContentPreparation(MHEngine *engine) override
Definition: Text.cpp:330
void SetFontAttributes(const MHOctetString &fontAttrs, MHEngine *engine) override
Definition: Text.cpp:380
StartCorner m_StartCorner
Definition: Text.h:85
MHSetTextColour()
Definition: Text.h:144
MHGenericOctetString m_FontAttrs
Definition: Text.h:159
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Text.cpp:887
void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg) override
Definition: Text.h:129
Definition: Text.h:37
void Preparation(MHEngine *engine) override
Definition: Text.cpp:281
void SetColour(const MHColour &colour, MHEngine *engine) override
Definition: Text.h:138
bool m_fNeedsRedraw
Definition: Text.h:95
StartCorner
Definition: Text.h:81
virtual void SetBackgroundColour(const MHColour &, MHEngine *)
Definition: Root.h:105
void Perform(MHEngine *engine) override
Definition: Text.cpp:912
Justification
Definition: Text.h:79
void InteractSetHighlightStatus(bool newStatus, MHEngine *engine)
Definition: Visible.cpp:569
MHColour m_bgColour
Definition: Text.h:90
Justification m_VertJ
Definition: Text.h:83
LineOrientation m_LineOrientation
Definition: Text.h:84
const char * ClassName() override
Definition: Text.h:43
MHGetTextData()
Definition: Text.h:128