MythTV  master
TokenGroup.h
Go to the documentation of this file.
1 /* TokenGroup.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(TOKENGROUP_H)
24 #define TOKENGROUP_H
25 
26 #include "Presentable.h"
27 // Dependencies
28 #include "Ingredients.h"
29 #include "Root.h"
30 #include "BaseClasses.h"
31 #include "BaseActions.h"
32 #include "Actions.h"
33 
34 #include <QPoint>
35 #include <QList>
36 
37 class MHEngine;
38 
40 {
41  public:
42  MHTokenGroupItem() = default;
43  void Initialise(MHParseNode *p, MHEngine *engine);
44  void PrintMe(FILE *fd, int nTabs) const;
47 };
48 
50 {
51  public:
52  void Initialise(MHParseNode *p, MHEngine *engine);
53  void PrintMe(FILE *fd, int nTabs) const;
55 };
56 
57 // TokenGroup. The standard defines a TokenManager class but that is incorporated in
58 // this class.
59 class MHTokenGroup : public MHPresentable
60 {
61  public:
62  MHTokenGroup() = default;
63  const char *ClassName() override // MHRoot
64  { return "TokenGroup"; }
65  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHIngredient
66  void PrintMe(FILE *fd, int nTabs) const override; // MHIngredient
67 
68  void Activation(MHEngine *engine) override; // MHRoot
69  void Deactivation(MHEngine *engine) override; // MHRoot
70 
71  // Actions
72  void CallActionSlot(int n, MHEngine *engine) override; // MHRoot
73  void Move(int n, MHEngine *engine) override; // MHRoot
74  void MoveTo(int n, MHEngine *engine) override // MHRoot
75  { TransferToken(n, engine); }
76  void GetTokenPosition(MHRoot *pResult, MHEngine */*engine*/) override // MHRoot
77  { pResult->SetVariableValue(m_nTokenPosition); }
78 
79  protected:
80  void PrintContents(FILE *fd, int nTabs) const;
81  void TransferToken(int newPos, MHEngine *engine);
82 
86 
87  // Internal attributes
88  int m_nTokenPosition {1}; // Initial value
89 };
90 
91 // Items in the list group consist of a Visible and a "selected" flag.
92 // For simplicity we don't check that we have a Visible and instead use virtual functions
93 // which only work on visibles.
94 class MHListItem {
95  public:
96  explicit MHListItem(MHRoot *pVis): m_pVisible(pVis), m_fSelected(false) {}
99 };
100 
101 class MHListGroup : public MHTokenGroup
102 {
103  public:
104  MHListGroup() = default;
105  ~MHListGroup() override;
106  const char *ClassName() override // MHTokenGroup
107  { return "ListGroup"; }
108  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHTokenGroup
109  void PrintMe(FILE *fd, int nTabs) const override; // MHTokenGroup
110  void Preparation(MHEngine *engine) override; // MHIngredient
111  void Destruction(MHEngine *engine) override; // MHIngredient
112  void Activation(MHEngine *engine) override; // MHTokenGroup
113  void Deactivation(MHEngine *engine) override; // MHTokenGroup
114 
115  // Actions
116  void AddItem(int nIndex, MHRoot *pItem, MHEngine *engine) override; // MHRoot
117  void DelItem(MHRoot *pItem, MHEngine *engine) override; // MHRoot
118  void GetCellItem(int nCell, const MHObjectRef &itemDest, MHEngine *engine) override; // MHRoot
119  void GetListItem(int nCell, const MHObjectRef &itemDest, MHEngine *engine) override; // MHRoot
120  void GetItemStatus(int nCell, const MHObjectRef &itemDest, MHEngine *engine) override; // MHRoot
121  void SelectItem(int nCell, MHEngine *engine) override; // MHRoot
122  void DeselectItem(int nCell, MHEngine *engine) override; // MHRoot
123  void ToggleItem(int nCell, MHEngine *engine) override; // MHRoot
124  void ScrollItems(int nCell, MHEngine *engine) override; // MHRoot
125  void SetFirstItem(int nCell, MHEngine *engine) override; // MHRoot
126  void GetFirstItem(MHRoot *pResult, MHEngine */*engine*/) override // MHRoot
127  { pResult->SetVariableValue(m_nFirstItem); }
128  void GetListSize(MHRoot *pResult, MHEngine */*engine*/) override // MHRoot
129  { pResult->SetVariableValue(m_ItemList.size()); }
130 
131  protected:
132  // MHEG Internal attributes.
133  void Update(MHEngine *engine);
134  void Select(int nIndex, MHEngine *engine);
135  void Deselect(int nIndex, MHEngine *engine);
136  int AdjustIndex(int nIndex); // Added in the MHEG corrigendum
137 
138  // Exchanged attributes
140  bool m_fWrapAround {false};
141  bool m_fMultipleSelection {false};
142  //Internal attributes
143  QList<MHListItem*> m_ItemList; // Items found by looking up the object refs
144  int m_nFirstItem {1}; // First item displayed - N.B. MHEG indexes from 1.
145  bool m_fFirstItemDisplayed {false};
146  bool m_fLastItemDisplayed {false};
147  int m_nLastCount {0};
149 };
150 
151 // Call action slot.
153 {
154  public:
155  MHCallActionSlot(): MHActionInt(":CallActionSlot") {}
156  void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) override // MHActionInt
157  { pTarget->CallActionSlot(nArg, engine); }
158 };
159 
160 // Move - move the token in a token group according to the movement table.
161 class MHMove: public MHActionInt
162 {
163  public:
164  MHMove(): MHActionInt(":Move") {}
165  void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) override // MHActionInt
166  { pTarget->Move(nArg, engine); }
167 };
168 
169 // MoveTo - move the token to a particular slot.
170 class MHMoveTo: public MHActionInt
171 {
172  public:
173  MHMoveTo(): MHActionInt(":MoveTo") {}
174  void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) override // MHActionInt
175  { pTarget->MoveTo(nArg, engine); }
176 };
177 
179  public:
180  MHGetTokenPosition(): MHActionObjectRef(":GetTokenPosition") {}
181  void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg) override // MHActionObjectRef
182  { pTarget->GetTokenPosition(pArg, engine); }
183 };
184 
185 class MHAddItem: public MHElemAction {
186  public:
187  MHAddItem(): MHElemAction(":AddItem") {}
188  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHElemAction
189  void PrintArgs(FILE *fd, int /*nTabs*/) const override; // MHElemAction
190  void Perform(MHEngine *engine) override; // MHElemAction
191  protected:
194 
195 };
196 
198  public:
200  void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pObj) override // MHActionGenericObjectRef
201  { pTarget->DelItem(pObj, engine); }
202 };
203 
204 // Base class for a few actions.
206  public:
207  explicit MHGetListActionData(const char *name): MHElemAction(name) {}
208  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHElemAction
209  void PrintArgs(FILE *fd, int /*nTabs*/) const override; // MHElemAction
210  protected:
213 };
214 
216  public:
217  MHGetCellItem(): MHGetListActionData(":GetCellItem") {}
218  void Perform(MHEngine *engine) override // MHElemAction
219  { Target(engine)->GetCellItem(m_Index.GetValue(engine), m_Result, engine); }
220 };
221 
223  public:
224  MHGetListItem(): MHGetListActionData(":GetListItem") {}
225  void Perform(MHEngine *engine) override // MHElemAction
226  { Target(engine)->GetListItem(m_Index.GetValue(engine), m_Result, engine); }
227 };
228 
230  public:
231  MHGetItemStatus(): MHGetListActionData(":GetItemStatus") {}
232  void Perform(MHEngine *engine) override // MHElemAction
233  { Target(engine)->GetItemStatus(m_Index.GetValue(engine), m_Result, engine); }
234 };
235 
236 class MHSelectItem: public MHActionInt {
237  public:
238  MHSelectItem(): MHActionInt(":SelectItem") {}
239  void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, int nArg) override // MHActionInt
240  { Target(engine)->SelectItem(nArg, engine); }
241 };
242 
244  public:
245  MHDeselectItem(): MHActionInt(":DeselectItem") {}
246  void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, int nArg) override // MHActionInt
247  { Target(engine)->DeselectItem(nArg, engine); }
248 };
249 
250 class MHToggleItem: public MHActionInt {
251  public:
252  MHToggleItem(): MHActionInt(":ToggleItem") {}
253  void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, int nArg) override // MHActionInt
254  { Target(engine)->ToggleItem(nArg, engine); }
255 };
256 
257 class MHScrollItems: public MHActionInt {
258  public:
259  MHScrollItems(): MHActionInt(":ScrollItems") {}
260  void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, int nArg) override // MHActionInt
261  { Target(engine)->ScrollItems(nArg, engine); }
262 };
263 
265  public:
266  MHSetFirstItem(): MHActionInt(":SetFirstItem") {}
267  void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, int nArg) override // MHActionInt
268  { Target(engine)->SetFirstItem(nArg, engine); }
269 };
270 
272  public:
273  MHGetFirstItem(): MHActionObjectRef(":GetFirstItem") {}
274  void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, MHRoot *pArg) override // MHActionObjectRef
275  { Target(engine)->GetFirstItem(pArg, engine); }
276 };
277 
279  public:
280  MHGetListSize(): MHActionObjectRef(":GetListSize") {}
281  void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, MHRoot *pArg) override // MHActionObjectRef
282  { Target(engine)->GetListSize(pArg, engine); }
283 };
284 
285 #endif
bool m_fMultipleSelection
Definition: TokenGroup.h:141
virtual void GetListSize(MHRoot *, MHEngine *)
Definition: Root.h:154
virtual void DeselectItem(int, MHEngine *)
Definition: Root.h:149
void GetCellItem(int nCell, const MHObjectRef &itemDest, MHEngine *engine) override
Definition: TokenGroup.cpp:635
void Activation(MHEngine *engine) override
Definition: TokenGroup.cpp:232
int m_nFirstItem
Definition: TokenGroup.h:144
void Destruction(MHEngine *engine) override
Definition: TokenGroup.cpp:429
void TransferToken(int newPos, MHEngine *engine)
Definition: TokenGroup.cpp:278
void SelectItem(int nCell, MHEngine *engine) override
Definition: TokenGroup.cpp:710
void PrintArgs(FILE *fd, int) const override
Definition: TokenGroup.cpp:826
void PrintMe(FILE *fd, int nTabs) const override
Definition: TokenGroup.cpp:222
MHRoot * Target(MHEngine *engine)
Definition: BaseActions.cpp:46
MHObjectRef m_Result
Definition: TokenGroup.h:212
void AddItem(int nIndex, MHRoot *pItem, MHEngine *engine) override
Definition: TokenGroup.cpp:545
virtual void SetFirstItem(int, MHEngine *)
Definition: Root.h:152
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: TokenGroup.cpp:819
void Initialise(MHParseNode *p, MHEngine *engine)
Definition: TokenGroup.cpp:32
MHOwnPtrSequence< MHMovement > m_MovementTable
Definition: TokenGroup.h:83
void MoveTo(int n, MHEngine *engine) override
Definition: TokenGroup.h:74
int GetValue(MHEngine *engine) const
void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) override
Definition: TokenGroup.h:165
MHGenericInteger m_Index
Definition: TokenGroup.h:192
bool m_fFirstItemDisplayed
Definition: TokenGroup.h:145
void GetListSize(MHRoot *pResult, MHEngine *) override
Definition: TokenGroup.h:128
virtual void GetItemStatus(int, const MHObjectRef &, MHEngine *)
Definition: Root.h:146
MHRoot * m_pVisible
Definition: TokenGroup.h:97
virtual void GetListItem(int, const MHObjectRef &, MHEngine *)
Definition: Root.h:144
void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) override
Definition: TokenGroup.h:156
void ScrollItems(int nCell, MHEngine *engine) override
Definition: TokenGroup.cpp:762
const char * ClassName() override
Definition: TokenGroup.h:63
MHOwnPtrSequence< MHTokenGroupItem > m_TokenGrpItems
Definition: TokenGroup.h:84
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
void Perform(MHEngine *engine) override
Definition: TokenGroup.h:232
void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg) override
Definition: TokenGroup.h:181
void CallAction(MHEngine *engine, MHRoot *, int nArg) override
Definition: TokenGroup.h:246
MHMove()
Definition: TokenGroup.h:164
virtual void SelectItem(int, MHEngine *)
Definition: Root.h:148
virtual void ToggleItem(int, MHEngine *)
Definition: Root.h:150
void CallAction(MHEngine *engine, MHRoot *, int nArg) override
Definition: TokenGroup.h:260
MHOwnPtrSequence< MHActionSequence > m_NoTokenActionSlots
Definition: TokenGroup.h:85
virtual void ScrollItems(int, MHEngine *)
Definition: Root.h:151
MHListGroup()=default
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: TokenGroup.cpp:335
void Perform(MHEngine *engine) override
Definition: TokenGroup.cpp:812
MHGetListActionData(const char *name)
Definition: TokenGroup.h:207
int m_nLastCount
Definition: TokenGroup.h:147
void DeselectItem(int nCell, MHEngine *engine) override
Definition: TokenGroup.cpp:725
~MHListGroup() override
Definition: TokenGroup.cpp:327
void Deselect(int nIndex, MHEngine *engine)
Definition: TokenGroup.cpp:621
void GetTokenPosition(MHRoot *pResult, MHEngine *) override
Definition: TokenGroup.h:76
void ToggleItem(int nCell, MHEngine *engine) override
Definition: TokenGroup.cpp:740
MHGenericObjectRef m_Item
Definition: TokenGroup.h:193
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: TokenGroup.cpp:117
MHTokenGroup()=default
Definition: Root.h:43
int FILE
Definition: mythburn.py:139
void Perform(MHEngine *engine) override
Definition: TokenGroup.h:218
void Initialise(MHParseNode *p, MHEngine *engine)
Definition: TokenGroup.cpp:96
void CallAction(MHEngine *engine, MHRoot *, int nArg) override
Definition: TokenGroup.h:267
virtual void GetCellItem(int, const MHObjectRef &, MHEngine *)
Definition: Root.h:142
void CallAction(MHEngine *engine, MHRoot *, MHRoot *pArg) override
Definition: TokenGroup.h:281
MHSequence< QPoint > m_Positions
Definition: TokenGroup.h:139
void Deactivation(MHEngine *engine) override
Definition: TokenGroup.cpp:446
void DelItem(MHRoot *pItem, MHEngine *engine) override
Definition: TokenGroup.cpp:574
void GetListItem(int nCell, const MHObjectRef &itemDest, MHEngine *engine) override
Definition: TokenGroup.cpp:680
void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pObj) override
Definition: TokenGroup.h:200
void CallAction(MHEngine *engine, MHRoot *, int nArg) override
Definition: TokenGroup.h:239
void GetItemStatus(int nCell, const MHObjectRef &itemDest, MHEngine *engine) override
Definition: TokenGroup.cpp:695
void CallActionSlot(int n, MHEngine *engine) override
Definition: TokenGroup.cpp:289
bool m_fWrapAround
Definition: TokenGroup.h:140
void Update(MHEngine *engine)
Definition: TokenGroup.cpp:457
QList< MHListItem * > m_ItemList
Definition: TokenGroup.h:143
bool m_fLastItemDisplayed
Definition: TokenGroup.h:146
void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) override
Definition: TokenGroup.h:174
void Perform(MHEngine *engine) override
Definition: TokenGroup.h:225
int AdjustIndex(int nIndex)
Definition: TokenGroup.cpp:660
MHObjectRef m_Object
Definition: TokenGroup.h:45
bool m_fSelected
Definition: TokenGroup.h:98
void Preparation(MHEngine *engine) override
Definition: TokenGroup.cpp:396
MHListItem(MHRoot *pVis)
Definition: TokenGroup.h:96
MHSequence< int > m_Movement
Definition: TokenGroup.h:54
MHOwnPtrSequence< MHActionSequence > m_ActionSlots
Definition: TokenGroup.h:46
MHTokenGroupItem()=default
void PrintMe(FILE *fd, int nTabs) const
Definition: TokenGroup.cpp:104
int m_nLastFirstItem
Definition: TokenGroup.h:148
void CallAction(MHEngine *engine, MHRoot *, MHRoot *pArg) override
Definition: TokenGroup.h:274
void PrintArgs(FILE *fd, int) const override
Definition: TokenGroup.cpp:806
void SetFirstItem(int nCell, MHEngine *engine) override
Definition: TokenGroup.cpp:780
void Select(int nIndex, MHEngine *engine)
Definition: TokenGroup.cpp:595
int m_nTokenPosition
Definition: TokenGroup.h:88
void GetFirstItem(MHRoot *pResult, MHEngine *) override
Definition: TokenGroup.h:126
MHGenericInteger m_Index
Definition: TokenGroup.h:211
void CallAction(MHEngine *engine, MHRoot *, int nArg) override
Definition: TokenGroup.h:253
void PrintMe(FILE *fd, int nTabs) const override
Definition: TokenGroup.cpp:365
void Move(int n, MHEngine *engine) override
Definition: TokenGroup.cpp:312
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: TokenGroup.cpp:799
void Activation(MHEngine *engine) override
Definition: TokenGroup.cpp:438
void Deactivation(MHEngine *engine) override
Definition: TokenGroup.cpp:266
const char * ClassName() override
Definition: TokenGroup.h:106
void PrintContents(FILE *fd, int nTabs) const
Definition: TokenGroup.cpp:164
virtual void GetFirstItem(MHRoot *, MHEngine *)
Definition: Root.h:153
void PrintMe(FILE *fd, int nTabs) const
Definition: TokenGroup.cpp:56