diff --git a/mythtv/libs/libmythfreemheg/Actions.cpp b/mythtv/libs/libmythfreemheg/Actions.cpp
index 50c46f6e5ee..75ede6a853e 100644
--- a/mythtv/libs/libmythfreemheg/Actions.cpp
+++ b/mythtv/libs/libmythfreemheg/Actions.cpp
@@ -43,12 +43,21 @@
// Temporary place-holder for actions we haven't done yet.
class MHUnimplementedAction: public MHElemAction
{
-public:
- MHUnimplementedAction(int nTag): MHElemAction("") { m_nTag = nTag; }
+ public:
+ MHUnimplementedAction(int nTag): MHElemAction("")
+ {
+ m_nTag = nTag;
+ }
virtual void Initialise(MHParseNode *, MHEngine *) {}
- virtual void PrintMe(FILE *fd, int /*nTabs*/) const { fprintf(fd, "****Missing action %d\n", m_nTag); }
- virtual void Perform(MHEngine *) { MHERROR(QString("Unimplemented action %1").arg(m_nTag)); }
-protected:
+ virtual void PrintMe(FILE *fd, int /*nTabs*/) const
+ {
+ fprintf(fd, "****Missing action %d\n", m_nTag);
+ }
+ virtual void Perform(MHEngine *)
+ {
+ MHERROR(QString("Unimplemented action %1").arg(m_nTag));
+ }
+ protected:
int m_nTag;
};
@@ -58,141 +67,390 @@ class MHUnimplementedAction: public MHElemAction
void MHActionSequence::Initialise(MHParseNode *p, MHEngine *engine)
{
// Depending on the caller we may have a tagged argument list or a sequence.
- for (int i = 0; i < p->GetArgCount(); i++) {
+ for (int i = 0; i < p->GetArgCount(); i++)
+ {
MHParseNode *pElemAction = p->GetArgN(i);
MHElemAction *pAction;
- switch (pElemAction->GetTagNo()) {
- case C_ACTIVATE: pAction = new MHActivate(":Activate", true); break;
- case C_ADD: pAction = new MHAdd; break;
- case C_ADD_ITEM: pAction = new MHAddItem; break;
- case C_APPEND: pAction = new MHAppend; break;
- case C_BRING_TO_FRONT: pAction = new MHBringToFront; break;
- case C_CALL: pAction = new MHCall(":Call", false); break;
- case C_CALL_ACTION_SLOT: pAction = new MHCallActionSlot; break;
- case C_CLEAR: pAction = new MHClear; break;
- case C_CLONE: pAction = new MHClone; break;
- case C_CLOSE_CONNECTION: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // ??
- case C_DEACTIVATE: pAction = new MHActivate(":Deactivate", false); break;
- case C_DEL_ITEM: pAction = new MHDelItem; break;
- case C_DESELECT: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // Button
- case C_DESELECT_ITEM: pAction = new MHDeselectItem; break;
- case C_DIVIDE: pAction = new MHDivide; break;
- case C_DRAW_ARC: pAction = new MHDrawArcSector(":DrawArc", false); break;
- case C_DRAW_LINE: pAction = new MHDrawLine; break;
- case C_DRAW_OVAL: pAction = new MHDrawOval; break;
- case C_DRAW_POLYGON: pAction = new MHDrawPoly(":DrawPolygon", true); break;
- case C_DRAW_POLYLINE: pAction = new MHDrawPoly(":DrawPolyline", false); break;
- case C_DRAW_RECTANGLE: pAction = new MHDrawRectangle; break;
- case C_DRAW_SECTOR: pAction = new MHDrawArcSector(":DrawSector", true); break;
- case C_FORK: pAction = new MHCall(":Fork", true); break;
- case C_GET_AVAILABILITY_STATUS: pAction = new MHGetAvailabilityStatus; break;
- case C_GET_BOX_SIZE: pAction = new MHGetBoxSize; break;
- case C_GET_CELL_ITEM: pAction = new MHGetCellItem; break;
- case C_GET_CURSOR_POSITION: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // ?
- case C_GET_ENGINE_SUPPORT: pAction = new MHGetEngineSupport; break;
- case C_GET_ENTRY_POINT: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // EntryField
- case C_GET_FILL_COLOUR: pAction = new MHGetFillColour; break;
- case C_GET_FIRST_ITEM: pAction = new MHGetFirstItem; break;
- case C_GET_HIGHLIGHT_STATUS: pAction = new MHGetHighlightStatus; break;
- case C_GET_INTERACTION_STATUS: pAction = new MHGetInteractionStatus; break;
- case C_GET_ITEM_STATUS: pAction = new MHGetItemStatus; break;
- case C_GET_LABEL: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break;// PushButton
- case C_GET_LAST_ANCHOR_FIRED: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break;// HyperText
- case C_GET_LINE_COLOUR: pAction = new MHGetLineColour; break;
- case C_GET_LINE_STYLE: pAction = new MHGetLineStyle; break;
- case C_GET_LINE_WIDTH: pAction = new MHGetLineWidth; break;
- case C_GET_LIST_ITEM: pAction = new MHGetListItem; break;
- case C_GET_LIST_SIZE: pAction = new MHGetListSize; break;
- case C_GET_OVERWRITE_MODE: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break;// ?
- case C_GET_PORTION: pAction = new MHGetPortion; break;
- case C_GET_POSITION: pAction = new MHGetPosition; break;
- case C_GET_RUNNING_STATUS: pAction = new MHGetRunningStatus; break;
- case C_GET_SELECTION_STATUS: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break;// ?
- case C_GET_SLIDER_VALUE: pAction = new MHGetSliderValue; break;
- case C_GET_TEXT_CONTENT: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break;// Text
- case C_GET_TEXT_DATA: pAction = new MHGetTextData; break;
- case C_GET_TOKEN_POSITION: pAction = new MHGetTokenPosition; break;
- case C_GET_VOLUME: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // ?
- case C_LAUNCH: pAction = new MHLaunch; break;
- case C_LOCK_SCREEN: pAction = new MHLockScreen; break;
- case C_MODULO: pAction = new MHModulo; break;
- case C_MOVE: pAction = new MHMove; break;
- case C_MOVE_TO: pAction = new MHMoveTo; break;
- case C_MULTIPLY: pAction = new MHMultiply; break;
- case C_OPEN_CONNECTION: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // ?
- case C_PRELOAD: pAction = new MHPreload; break;
- case C_PUT_BEFORE: pAction = new MHPutBefore; break;
- case C_PUT_BEHIND: pAction = new MHPutBehind; break;
- case C_QUIT: pAction = new MHQuit; break;
- case C_READ_PERSISTENT: pAction = new MHPersistent(":ReadPersistent", true); break;
- case C_RUN: pAction = new MHRun; break;
- case C_SCALE_BITMAP: pAction = new MHScaleBitmap; break;
- case C_SCALE_VIDEO: pAction = new MHScaleVideo; break;
- case C_SCROLL_ITEMS: pAction = new MHScrollItems; break;
- case C_SELECT: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // Button
- case C_SELECT_ITEM: pAction = new MHSelectItem; break;
- case C_SEND_EVENT: pAction = new MHSendEvent; break;
- case C_SEND_TO_BACK: pAction = new MHSendToBack; break;
- case C_SET_BOX_SIZE: pAction = new MHSetBoxSize; break;
- case C_SET_CACHE_PRIORITY: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // ?
- case C_SET_COUNTER_END_POSITION: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // Stream
- case C_SET_COUNTER_POSITION: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // Stream
- case C_SET_COUNTER_TRIGGER: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // Stream
- case C_SET_CURSOR_POSITION: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // ?
- case C_SET_CURSOR_SHAPE: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // ?
- case C_SET_DATA: pAction = new MHSetData; break;
- case C_SET_ENTRY_POINT: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // EntryField
- case C_SET_FILL_COLOUR: pAction = new MHSetFillColour; break;
- case C_SET_FIRST_ITEM: pAction = new MHSetFirstItem; break;
- case C_SET_FONT_REF: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // Text
- case C_SET_HIGHLIGHT_STATUS: pAction = new MHSetHighlightStatus; break;
- case C_SET_INTERACTION_STATUS: pAction = new MHSetInteractionStatus; break;
- case C_SET_LABEL: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // PushButton
- case C_SET_LINE_COLOUR: pAction = new MHSetLineColour; break;
- case C_SET_LINE_STYLE: pAction = new MHSetLineStyle; break;
- case C_SET_LINE_WIDTH: pAction = new MHSetLineWidth; break;
- case C_SET_OVERWRITE_MODE: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // EntryField
- case C_SET_PALETTE_REF: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // Visible
- case C_SET_PORTION: pAction = new MHSetPortion; break;
- case C_SET_POSITION: pAction = new MHSetPosition; break;
- case C_SET_SLIDER_VALUE: pAction = new MHSetSliderValue; break;
- case C_SET_SPEED: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // ?
- case C_SET_TIMER: pAction = new MHSetTimer; break;
- case C_SET_TRANSPARENCY: pAction = new MHSetTransparency; break;
- case C_SET_VARIABLE: pAction = new MHSetVariable; break;
- case C_SET_VOLUME: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // ?
- case C_SPAWN: pAction = new MHSpawn; break;
- case C_STEP: pAction = new MHStep; break;
- case C_STOP: pAction = new MHStop; break;
- case C_STORE_PERSISTENT: pAction = new MHPersistent(":StorePersistent", false); break;
- case C_SUBTRACT: pAction = new MHSubtract; break;
- case C_TEST_VARIABLE: pAction = new MHTestVariable; break;
- case C_TOGGLE: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // Button
- case C_TOGGLE_ITEM: pAction = new MHToggleItem; break;
- case C_TRANSITION_TO: pAction = new MHTransitionTo; break;
- case C_UNLOAD: pAction = new MHUnload; break;
- case C_UNLOCK_SCREEN: pAction = new MHUnlockScreen; break;
- // UK MHEG added actions.
- case C_SET_BACKGROUND_COLOUR: pAction = new MHSetBackgroundColour; break;
- case C_SET_CELL_POSITION: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // ?
- case C_SET_INPUT_REGISTER: pAction = new MHSetInputRegister; break;
- case C_SET_TEXT_COLOUR: pAction = new MHSetTextColour; break;
- case C_SET_FONT_ATTRIBUTES: pAction = new MHSetFontAttributes; break;
- case C_SET_VIDEO_DECODE_OFFSET: pAction = new MHSetVideoDecodeOffset; break;
- case C_GET_VIDEO_DECODE_OFFSET: pAction = new MHGetVideoDecodeOffset; break;
- case C_GET_FOCUS_POSITION: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // HyperText
- case C_SET_FOCUS_POSITION: pAction = new MHUnimplementedAction(pElemAction->GetTagNo()); break; // HyperText
- case C_SET_BITMAP_DECODE_OFFSET: pAction = new MHSetBitmapDecodeOffset; break;
- case C_GET_BITMAP_DECODE_OFFSET: pAction = new MHGetBitmapDecodeOffset; break;
- case C_SET_SLIDER_PARAMETERS: pAction = new MHSetSliderParameters; break;
- default:
- MHLOG(MHLogWarning, QString("Unknown action %1").arg(pElemAction->GetTagNo()));
- // Future proofing: ignore any actions that we don't know about.
- // Obviously these can only arise in the binary coding.
- pAction = NULL;
+ switch (pElemAction->GetTagNo())
+ {
+ case C_ACTIVATE:
+ pAction = new MHActivate(":Activate", true);
+ break;
+ case C_ADD:
+ pAction = new MHAdd;
+ break;
+ case C_ADD_ITEM:
+ pAction = new MHAddItem;
+ break;
+ case C_APPEND:
+ pAction = new MHAppend;
+ break;
+ case C_BRING_TO_FRONT:
+ pAction = new MHBringToFront;
+ break;
+ case C_CALL:
+ pAction = new MHCall(":Call", false);
+ break;
+ case C_CALL_ACTION_SLOT:
+ pAction = new MHCallActionSlot;
+ break;
+ case C_CLEAR:
+ pAction = new MHClear;
+ break;
+ case C_CLONE:
+ pAction = new MHClone;
+ break;
+ case C_CLOSE_CONNECTION:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // ??
+ case C_DEACTIVATE:
+ pAction = new MHActivate(":Deactivate", false);
+ break;
+ case C_DEL_ITEM:
+ pAction = new MHDelItem;
+ break;
+ case C_DESELECT:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // Button
+ case C_DESELECT_ITEM:
+ pAction = new MHDeselectItem;
+ break;
+ case C_DIVIDE:
+ pAction = new MHDivide;
+ break;
+ case C_DRAW_ARC:
+ pAction = new MHDrawArcSector(":DrawArc", false);
+ break;
+ case C_DRAW_LINE:
+ pAction = new MHDrawLine;
+ break;
+ case C_DRAW_OVAL:
+ pAction = new MHDrawOval;
+ break;
+ case C_DRAW_POLYGON:
+ pAction = new MHDrawPoly(":DrawPolygon", true);
+ break;
+ case C_DRAW_POLYLINE:
+ pAction = new MHDrawPoly(":DrawPolyline", false);
+ break;
+ case C_DRAW_RECTANGLE:
+ pAction = new MHDrawRectangle;
+ break;
+ case C_DRAW_SECTOR:
+ pAction = new MHDrawArcSector(":DrawSector", true);
+ break;
+ case C_FORK:
+ pAction = new MHCall(":Fork", true);
+ break;
+ case C_GET_AVAILABILITY_STATUS:
+ pAction = new MHGetAvailabilityStatus;
+ break;
+ case C_GET_BOX_SIZE:
+ pAction = new MHGetBoxSize;
+ break;
+ case C_GET_CELL_ITEM:
+ pAction = new MHGetCellItem;
+ break;
+ case C_GET_CURSOR_POSITION:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // ?
+ case C_GET_ENGINE_SUPPORT:
+ pAction = new MHGetEngineSupport;
+ break;
+ case C_GET_ENTRY_POINT:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // EntryField
+ case C_GET_FILL_COLOUR:
+ pAction = new MHGetFillColour;
+ break;
+ case C_GET_FIRST_ITEM:
+ pAction = new MHGetFirstItem;
+ break;
+ case C_GET_HIGHLIGHT_STATUS:
+ pAction = new MHGetHighlightStatus;
+ break;
+ case C_GET_INTERACTION_STATUS:
+ pAction = new MHGetInteractionStatus;
+ break;
+ case C_GET_ITEM_STATUS:
+ pAction = new MHGetItemStatus;
+ break;
+ case C_GET_LABEL:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break;// PushButton
+ case C_GET_LAST_ANCHOR_FIRED:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break;// HyperText
+ case C_GET_LINE_COLOUR:
+ pAction = new MHGetLineColour;
+ break;
+ case C_GET_LINE_STYLE:
+ pAction = new MHGetLineStyle;
+ break;
+ case C_GET_LINE_WIDTH:
+ pAction = new MHGetLineWidth;
+ break;
+ case C_GET_LIST_ITEM:
+ pAction = new MHGetListItem;
+ break;
+ case C_GET_LIST_SIZE:
+ pAction = new MHGetListSize;
+ break;
+ case C_GET_OVERWRITE_MODE:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break;// ?
+ case C_GET_PORTION:
+ pAction = new MHGetPortion;
+ break;
+ case C_GET_POSITION:
+ pAction = new MHGetPosition;
+ break;
+ case C_GET_RUNNING_STATUS:
+ pAction = new MHGetRunningStatus;
+ break;
+ case C_GET_SELECTION_STATUS:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break;// ?
+ case C_GET_SLIDER_VALUE:
+ pAction = new MHGetSliderValue;
+ break;
+ case C_GET_TEXT_CONTENT:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break;// Text
+ case C_GET_TEXT_DATA:
+ pAction = new MHGetTextData;
+ break;
+ case C_GET_TOKEN_POSITION:
+ pAction = new MHGetTokenPosition;
+ break;
+ case C_GET_VOLUME:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // ?
+ case C_LAUNCH:
+ pAction = new MHLaunch;
+ break;
+ case C_LOCK_SCREEN:
+ pAction = new MHLockScreen;
+ break;
+ case C_MODULO:
+ pAction = new MHModulo;
+ break;
+ case C_MOVE:
+ pAction = new MHMove;
+ break;
+ case C_MOVE_TO:
+ pAction = new MHMoveTo;
+ break;
+ case C_MULTIPLY:
+ pAction = new MHMultiply;
+ break;
+ case C_OPEN_CONNECTION:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // ?
+ case C_PRELOAD:
+ pAction = new MHPreload;
+ break;
+ case C_PUT_BEFORE:
+ pAction = new MHPutBefore;
+ break;
+ case C_PUT_BEHIND:
+ pAction = new MHPutBehind;
+ break;
+ case C_QUIT:
+ pAction = new MHQuit;
+ break;
+ case C_READ_PERSISTENT:
+ pAction = new MHPersistent(":ReadPersistent", true);
+ break;
+ case C_RUN:
+ pAction = new MHRun;
+ break;
+ case C_SCALE_BITMAP:
+ pAction = new MHScaleBitmap;
+ break;
+ case C_SCALE_VIDEO:
+ pAction = new MHScaleVideo;
+ break;
+ case C_SCROLL_ITEMS:
+ pAction = new MHScrollItems;
+ break;
+ case C_SELECT:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // Button
+ case C_SELECT_ITEM:
+ pAction = new MHSelectItem;
+ break;
+ case C_SEND_EVENT:
+ pAction = new MHSendEvent;
+ break;
+ case C_SEND_TO_BACK:
+ pAction = new MHSendToBack;
+ break;
+ case C_SET_BOX_SIZE:
+ pAction = new MHSetBoxSize;
+ break;
+ case C_SET_CACHE_PRIORITY:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // ?
+ case C_SET_COUNTER_END_POSITION:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // Stream
+ case C_SET_COUNTER_POSITION:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // Stream
+ case C_SET_COUNTER_TRIGGER:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // Stream
+ case C_SET_CURSOR_POSITION:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // ?
+ case C_SET_CURSOR_SHAPE:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // ?
+ case C_SET_DATA:
+ pAction = new MHSetData;
+ break;
+ case C_SET_ENTRY_POINT:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // EntryField
+ case C_SET_FILL_COLOUR:
+ pAction = new MHSetFillColour;
+ break;
+ case C_SET_FIRST_ITEM:
+ pAction = new MHSetFirstItem;
+ break;
+ case C_SET_FONT_REF:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // Text
+ case C_SET_HIGHLIGHT_STATUS:
+ pAction = new MHSetHighlightStatus;
+ break;
+ case C_SET_INTERACTION_STATUS:
+ pAction = new MHSetInteractionStatus;
+ break;
+ case C_SET_LABEL:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // PushButton
+ case C_SET_LINE_COLOUR:
+ pAction = new MHSetLineColour;
+ break;
+ case C_SET_LINE_STYLE:
+ pAction = new MHSetLineStyle;
+ break;
+ case C_SET_LINE_WIDTH:
+ pAction = new MHSetLineWidth;
+ break;
+ case C_SET_OVERWRITE_MODE:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // EntryField
+ case C_SET_PALETTE_REF:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // Visible
+ case C_SET_PORTION:
+ pAction = new MHSetPortion;
+ break;
+ case C_SET_POSITION:
+ pAction = new MHSetPosition;
+ break;
+ case C_SET_SLIDER_VALUE:
+ pAction = new MHSetSliderValue;
+ break;
+ case C_SET_SPEED:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // ?
+ case C_SET_TIMER:
+ pAction = new MHSetTimer;
+ break;
+ case C_SET_TRANSPARENCY:
+ pAction = new MHSetTransparency;
+ break;
+ case C_SET_VARIABLE:
+ pAction = new MHSetVariable;
+ break;
+ case C_SET_VOLUME:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // ?
+ case C_SPAWN:
+ pAction = new MHSpawn;
+ break;
+ case C_STEP:
+ pAction = new MHStep;
+ break;
+ case C_STOP:
+ pAction = new MHStop;
+ break;
+ case C_STORE_PERSISTENT:
+ pAction = new MHPersistent(":StorePersistent", false);
+ break;
+ case C_SUBTRACT:
+ pAction = new MHSubtract;
+ break;
+ case C_TEST_VARIABLE:
+ pAction = new MHTestVariable;
+ break;
+ case C_TOGGLE:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // Button
+ case C_TOGGLE_ITEM:
+ pAction = new MHToggleItem;
+ break;
+ case C_TRANSITION_TO:
+ pAction = new MHTransitionTo;
+ break;
+ case C_UNLOAD:
+ pAction = new MHUnload;
+ break;
+ case C_UNLOCK_SCREEN:
+ pAction = new MHUnlockScreen;
+ break;
+ // UK MHEG added actions.
+ case C_SET_BACKGROUND_COLOUR:
+ pAction = new MHSetBackgroundColour;
+ break;
+ case C_SET_CELL_POSITION:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // ?
+ case C_SET_INPUT_REGISTER:
+ pAction = new MHSetInputRegister;
+ break;
+ case C_SET_TEXT_COLOUR:
+ pAction = new MHSetTextColour;
+ break;
+ case C_SET_FONT_ATTRIBUTES:
+ pAction = new MHSetFontAttributes;
+ break;
+ case C_SET_VIDEO_DECODE_OFFSET:
+ pAction = new MHSetVideoDecodeOffset;
+ break;
+ case C_GET_VIDEO_DECODE_OFFSET:
+ pAction = new MHGetVideoDecodeOffset;
+ break;
+ case C_GET_FOCUS_POSITION:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // HyperText
+ case C_SET_FOCUS_POSITION:
+ pAction = new MHUnimplementedAction(pElemAction->GetTagNo());
+ break; // HyperText
+ case C_SET_BITMAP_DECODE_OFFSET:
+ pAction = new MHSetBitmapDecodeOffset;
+ break;
+ case C_GET_BITMAP_DECODE_OFFSET:
+ pAction = new MHGetBitmapDecodeOffset;
+ break;
+ case C_SET_SLIDER_PARAMETERS:
+ pAction = new MHSetSliderParameters;
+ break;
+
+ default:
+ MHLOG(MHLogWarning, QString("Unknown action %1").arg(pElemAction->GetTagNo()));
+ // Future proofing: ignore any actions that we don't know about.
+ // Obviously these can only arise in the binary coding.
+ pAction = NULL;
}
- if (pAction) {
+
+ if (pAction)
+ {
Append(pAction); // Add to the sequence.
pAction->Initialise(pElemAction, engine);
}
@@ -201,7 +459,8 @@ void MHActionSequence::Initialise(MHParseNode *p, MHEngine *engine)
void MHActionSequence::PrintMe(FILE *fd, int nTabs) const
{
- for (int i = 0; i < Size(); i++) {
+ for (int i = 0; i < Size(); i++)
+ {
GetAt(i)->PrintMe(fd, nTabs);
}
}
diff --git a/mythtv/libs/libmythfreemheg/Actions.h b/mythtv/libs/libmythfreemheg/Actions.h
index 766005ebcce..87906475618 100644
--- a/mythtv/libs/libmythfreemheg/Actions.h
+++ b/mythtv/libs/libmythfreemheg/Actions.h
@@ -27,7 +27,7 @@ class MHElemAction;
class MHActionSequence: public MHOwnPtrSequence
{
-public:
+ public:
MHActionSequence() {}
virtual ~MHActionSequence() {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
diff --git a/mythtv/libs/libmythfreemheg/BaseActions.cpp b/mythtv/libs/libmythfreemheg/BaseActions.cpp
index 5537993fa93..80fd50360f5 100644
--- a/mythtv/libs/libmythfreemheg/BaseActions.cpp
+++ b/mythtv/libs/libmythfreemheg/BaseActions.cpp
@@ -38,8 +38,8 @@ void MHElemAction::PrintMe(FILE *fd, int nTabs) const
{
PrintTabs(fd, nTabs);
fprintf(fd, "%s (", m_ActionName);
- m_Target.PrintMe(fd, nTabs+1);
- PrintArgs(fd, nTabs+1); // Any other arguments must be handled by the subclass.
+ m_Target.PrintMe(fd, nTabs + 1);
+ PrintArgs(fd, nTabs + 1); // Any other arguments must be handled by the subclass.
fprintf(fd, ")\n");
}
@@ -152,8 +152,8 @@ void MHActionInt6::PrintArgs(FILE *fd, int /*nTabs*/) const
void MHActionInt6::Perform(MHEngine *engine)
{
- CallAction(engine, Target(engine), m_Argument1.GetValue(engine), m_Argument2.GetValue(engine), m_Argument3.GetValue(engine),
- m_Argument4.GetValue(engine), m_Argument5.GetValue(engine), m_Argument6.GetValue(engine));
+ CallAction(engine, Target(engine), m_Argument1.GetValue(engine), m_Argument2.GetValue(engine), m_Argument3.GetValue(engine),
+ m_Argument4.GetValue(engine), m_Argument5.GetValue(engine), m_Argument6.GetValue(engine));
}
diff --git a/mythtv/libs/libmythfreemheg/BaseActions.h b/mythtv/libs/libmythfreemheg/BaseActions.h
index ab56cd6960c..077f7d9e1d5 100644
--- a/mythtv/libs/libmythfreemheg/BaseActions.h
+++ b/mythtv/libs/libmythfreemheg/BaseActions.h
@@ -30,16 +30,16 @@ class MHRoot;
// Abstract base class for MHEG elementary actions.
// The first argument of most (all?) actions is an object reference which is
// the target of the action so we can handle some of the parsing and printing
-// within this class rather than the derived classes.
-class MHElemAction
+// within this class rather than the derived classes.
+class MHElemAction
{
-public:
+ public:
MHElemAction(const char *name): m_ActionName(name) {}
virtual ~MHElemAction() {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintMe(FILE *fd, int nTabs) const;
virtual void Perform(MHEngine *engine) = 0; // Perform the action.
-protected:
+ protected:
virtual void PrintArgs(FILE *, int) const {}
MHRoot *Target(MHEngine *engine); // Look up the target
const char *m_ActionName;
@@ -50,65 +50,65 @@ class MHElemAction
// Base class for actions with a single integer argument.
class MHActionInt: public MHElemAction
{
-public:
+ public:
MHActionInt(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintArgs(FILE *fd, int) const { m_Argument.PrintMe(fd, 0); }
virtual void Perform(MHEngine *engine);
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) = 0;
-protected:
+ protected:
MHGenericInteger m_Argument;
};
// Base class for actions with a pair of integer arguments.
class MHActionIntInt: public MHElemAction
{
-public:
+ public:
MHActionIntInt(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintArgs(FILE *fd, int/* nTabs*/) const { m_Argument1.PrintMe(fd, 0); m_Argument2.PrintMe(fd, 0); }
virtual void Perform(MHEngine *engine);
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2) = 0;
-protected:
+ protected:
MHGenericInteger m_Argument1, m_Argument2;
};
// Base class for actions with three integers. Used for SetSliderParameters
class MHActionInt3: public MHElemAction
{
-public:
+ public:
MHActionInt3(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintArgs(FILE *fd, int nTabs) const;
virtual void Perform(MHEngine *engine);
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2, int nArg3) = 0;
-protected:
+ protected:
MHGenericInteger m_Argument1, m_Argument2, m_Argument3;
};
// Base class for actions with four integers. Used in the DynamicLineArt class
class MHActionInt4: public MHElemAction
{
-public:
+ public:
MHActionInt4(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintArgs(FILE *fd, int nTabs) const;
virtual void Perform(MHEngine *engine);
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2, int nArg3, int nArg4) = 0;
-protected:
+ protected:
MHGenericInteger m_Argument1, m_Argument2, m_Argument3, m_Argument4;
};
// Base class for actions with six integers. Used in the DynamicLineArt class
class MHActionInt6: public MHElemAction
{
-public:
+ public:
MHActionInt6(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintArgs(FILE *fd, int nTabs) const;
virtual void Perform(MHEngine *engine);
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2, int nArg3, int nArg4, int nArg5, int nArg6) = 0;
-protected:
+ protected:
MHGenericInteger m_Argument1, m_Argument2, m_Argument3, m_Argument4, m_Argument5, m_Argument6;
};
@@ -116,12 +116,12 @@ class MHActionInt6: public MHElemAction
// An action with an object reference as an argument.
class MHActionObjectRef: public MHElemAction
{
-public:
+ public:
MHActionObjectRef(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg) = 0;
-private:
+ private:
virtual void PrintArgs(FILE *fd, int/* nTabs*/) const { m_ResultVar.PrintMe(fd, 0); }
MHObjectRef m_ResultVar;
};
@@ -129,24 +129,24 @@ class MHActionObjectRef: public MHElemAction
// An action with two object references as an argument.
class MHActionObjectRef2: public MHElemAction
{
-public:
+ public:
MHActionObjectRef2(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg1, MHRoot *pArg2) = 0;
-private:
+ private:
virtual void PrintArgs(FILE *fd, int/* nTabs*/) const { m_ResultVar1.PrintMe(fd, 0); m_ResultVar2.PrintMe(fd, 0);}
MHObjectRef m_ResultVar1, m_ResultVar2;
};
class MHActionGenericObjectRef: public MHElemAction
{
-public:
+ public:
MHActionGenericObjectRef(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pObj) = 0;
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int/* nTabs*/) const { m_RefObject.PrintMe(fd, 0); }
MHGenericObjectRef m_RefObject;
};
@@ -155,13 +155,13 @@ class MHActionGenericObjectRef: public MHElemAction
// Base class for actions with a single boolean argument.
class MHActionBool: public MHElemAction
{
-public:
+ public:
MHActionBool(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintArgs(FILE *fd, int) const { m_Argument.PrintMe(fd, 0); }
virtual void Perform(MHEngine *engine);
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, bool fArg) = 0;
-protected:
+ protected:
MHGenericBoolean m_Argument;
};
diff --git a/mythtv/libs/libmythfreemheg/BaseClasses.cpp b/mythtv/libs/libmythfreemheg/BaseClasses.cpp
index 21f8bc30e9d..37643e27c2a 100644
--- a/mythtv/libs/libmythfreemheg/BaseClasses.cpp
+++ b/mythtv/libs/libmythfreemheg/BaseClasses.cpp
@@ -27,7 +27,7 @@
#ifdef _DEBUG
#undef THIS_FILE
-static char THIS_FILE[]=__FILE__;
+static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif
@@ -40,12 +40,26 @@ MHOctetString::MHOctetString()
// Construct from a string
MHOctetString::MHOctetString(const char *str, int nLen)
{
- if (nLen < 0) nLen = strlen(str);
+ if (nLen < 0)
+ {
+ nLen = strlen(str);
+ }
+
m_nLength = nLen;
- if (nLen == 0) m_pChars = 0;
- else {
- m_pChars = (unsigned char*)malloc(nLen);
- if (! m_pChars) throw "Out of memory";
+
+ if (nLen == 0)
+ {
+ m_pChars = 0;
+ }
+ else
+ {
+ m_pChars = (unsigned char *)malloc(nLen);
+
+ if (! m_pChars)
+ {
+ throw "Out of memory";
+ }
+
memcpy(m_pChars, str, nLen);
}
}
@@ -53,10 +67,20 @@ MHOctetString::MHOctetString(const char *str, int nLen)
MHOctetString::MHOctetString(const unsigned char *str, int nLen)
{
m_nLength = nLen;
- if (nLen == 0) m_pChars = 0;
- else {
- m_pChars = (unsigned char*)malloc(nLen);
- if (! m_pChars) throw "Out of memory";
+
+ if (nLen == 0)
+ {
+ m_pChars = 0;
+ }
+ else
+ {
+ m_pChars = (unsigned char *)malloc(nLen);
+
+ if (! m_pChars)
+ {
+ throw "Out of memory";
+ }
+
memcpy(m_pChars, str, nLen);
}
}
@@ -64,14 +88,36 @@ MHOctetString::MHOctetString(const unsigned char *str, int nLen)
// Construct a substring.
MHOctetString::MHOctetString(const MHOctetString &str, int nOffset, int nLen)
{
- if (nLen < 0) nLen = str.Size()-nOffset; // The rest of the string.
- if (nLen < 0) nLen = 0;
- if (nLen > str.Size()) nLen = str.Size();
+ if (nLen < 0)
+ {
+ nLen = str.Size() - nOffset; // The rest of the string.
+ }
+
+ if (nLen < 0)
+ {
+ nLen = 0;
+ }
+
+ if (nLen > str.Size())
+ {
+ nLen = str.Size();
+ }
+
m_nLength = nLen;
- if (nLen == 0) m_pChars = 0;
- else {
- m_pChars = (unsigned char*)malloc(nLen);
- if (! m_pChars) throw "Out of memory";
+
+ if (nLen == 0)
+ {
+ m_pChars = 0;
+ }
+ else
+ {
+ m_pChars = (unsigned char *)malloc(nLen);
+
+ if (! m_pChars)
+ {
+ throw "Out of memory";
+ }
+
memcpy(m_pChars, str.m_pChars + nOffset, nLen);
}
}
@@ -84,28 +130,46 @@ MHOctetString::~MHOctetString()
// Copy a string
void MHOctetString::Copy(const MHOctetString &str)
{
- free(m_pChars); m_pChars = NULL;
+ free(m_pChars);
+ m_pChars = NULL;
m_nLength = str.m_nLength;
- if (str.m_pChars) {
+
+ if (str.m_pChars)
+ {
// Allocate a copy of the string. For simplicity we always add a null.
- m_pChars = (unsigned char*)malloc(m_nLength+1);
- if (m_pChars == NULL) throw "Out of memory";
+ m_pChars = (unsigned char *)malloc(m_nLength + 1);
+
+ if (m_pChars == NULL)
+ {
+ throw "Out of memory";
+ }
+
memcpy(m_pChars, str.m_pChars, m_nLength);
m_pChars[m_nLength] = 0;
}
}
// Print the string in a suitable format.
-// For the moment it uses quoted printable.
+// For the moment it uses quoted printable.
void MHOctetString::PrintMe(FILE *fd, int /*nTabs*/) const
{
putc('\'', fd);
- for (int i = 0; i < m_nLength; i++) {
+
+ for (int i = 0; i < m_nLength; i++)
+ {
unsigned char ch = m_pChars[i];
+
// Escape a non-printable character or an equal sign or a quote.
- if (ch == '=' || ch == '\'' || ch < ' ' || ch >= 127) fprintf(fd, "=%02X", ch);
- else putc(ch, fd);
+ if (ch == '=' || ch == '\'' || ch < ' ' || ch >= 127)
+ {
+ fprintf(fd, "=%02X", ch);
+ }
+ else
+ {
+ putc(ch, fd);
+ }
}
+
putc('\'', fd);
}
@@ -113,43 +177,87 @@ void MHOctetString::PrintMe(FILE *fd, int /*nTabs*/) const
int MHOctetString::Compare(const MHOctetString &str) const
{
int nLength = m_nLength;
- if (nLength > str.m_nLength) nLength = str.m_nLength;
+
+ if (nLength > str.m_nLength)
+ {
+ nLength = str.m_nLength;
+ }
+
// Test up to the length of the shorter string.
int nTest = 0;
- if (nLength > 0) nTest = memcmp(str.m_pChars, m_pChars, nLength);
+
+ if (nLength > 0)
+ {
+ nTest = memcmp(str.m_pChars, m_pChars, nLength);
+ }
+
// If they differ return the result
- if (nTest != 0) return nTest;
+ if (nTest != 0)
+ {
+ return nTest;
+ }
+
// If they are the same then the longer string is greater.
- if (m_nLength == str.m_nLength) return 0;
- else if (m_nLength < str.m_nLength) return -1;
- else return 1;
+ if (m_nLength == str.m_nLength)
+ {
+ return 0;
+ }
+ else if (m_nLength < str.m_nLength)
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
}
// Add text to the end of the string.
void MHOctetString::Append(const MHOctetString &str)
{
- if (str.m_nLength == 0) return; // Nothing to do and it simplifies the code
+ if (str.m_nLength == 0)
+ {
+ return; // Nothing to do and it simplifies the code
+ }
+
int newLen = m_nLength + str.m_nLength;
// Allocate a new string big enough to contain both and initialised to the first string.
unsigned char *p = (unsigned char *)realloc(m_pChars, newLen);
- if (p == NULL) throw "Out of memory";
+
+ if (p == NULL)
+ {
+ throw "Out of memory";
+ }
+
m_pChars = p;
// Copy the second string onto the end of the first.
- memcpy(m_pChars+m_nLength, str.m_pChars, str.m_nLength);
+ memcpy(m_pChars + m_nLength, str.m_pChars, str.m_nLength);
m_nLength = newLen;
}
// Colour
void MHColour::Initialise(MHParseNode *p, MHEngine * /*engine*/)
{
- if (p->m_nNodeType == MHParseNode::PNInt) m_nColIndex = p->GetIntValue();
- else p->GetStringValue(m_ColStr);
+ if (p->m_nNodeType == MHParseNode::PNInt)
+ {
+ m_nColIndex = p->GetIntValue();
+ }
+ else
+ {
+ p->GetStringValue(m_ColStr);
+ }
}
void MHColour::PrintMe(FILE *fd, int nTabs) const
{
- if (m_nColIndex >= 0) fprintf(fd, " %d ", m_nColIndex);
- else m_ColStr.PrintMe(fd, nTabs);
+ if (m_nColIndex >= 0)
+ {
+ fprintf(fd, " %d ", m_nColIndex);
+ }
+ else
+ {
+ m_ColStr.PrintMe(fd, nTabs);
+ }
}
void MHColour::SetFromString(const char *str, int nLen)
@@ -172,24 +280,33 @@ MHObjectRef MHObjectRef::Null; // This has zero for the object number and an emp
// An object reference is either an integer or a pair of a group id and an integer.
void MHObjectRef::Initialise(MHParseNode *p, MHEngine *engine)
{
- if (p->m_nNodeType == MHParseNode::PNInt) {
+ if (p->m_nNodeType == MHParseNode::PNInt)
+ {
m_nObjectNo = p->GetIntValue();
// Set the group id to the id of this group.
m_GroupId.Copy(engine->GetGroupId());
}
- else if (p->m_nNodeType == MHParseNode::PNSeq) {
+ else if (p->m_nNodeType == MHParseNode::PNSeq)
+ {
MHParseNode *pFirst = p->GetSeqN(0);
MHOctetString groupId;
pFirst->GetStringValue(m_GroupId);
m_nObjectNo = p->GetSeqN(1)->GetIntValue();
}
- else p->Failure("ObjectRef: Argument is not int or sequence");
+ else
+ {
+ p->Failure("ObjectRef: Argument is not int or sequence");
+ }
}
void MHObjectRef::PrintMe(FILE *fd, int nTabs) const
{
- if (m_GroupId.Size() == 0) fprintf(fd, " %d ", m_nObjectNo);
- else {
+ if (m_GroupId.Size() == 0)
+ {
+ fprintf(fd, " %d ", m_nObjectNo);
+ }
+ else
+ {
fprintf(fd, " ( ");
m_GroupId.PrintMe(fd, nTabs);
fprintf(fd, " %d ) ", m_nObjectNo);
@@ -198,8 +315,14 @@ void MHObjectRef::PrintMe(FILE *fd, int nTabs) const
QString MHObjectRef::Printable() const
{
- if (m_GroupId.Size() == 0) return QString(" %1 ").arg(m_nObjectNo);
- else return QString(" ( ") + m_GroupId.Printable() + QString(" %1 ").arg(m_nObjectNo);
+ if (m_GroupId.Size() == 0)
+ {
+ return QString(" %1 ").arg(m_nObjectNo);
+ }
+ else
+ {
+ return QString(" ( ") + m_GroupId.Printable() + QString(" %1 ").arg(m_nObjectNo);
+ }
}
// Make a copy of an object reference.
@@ -225,12 +348,14 @@ bool MHContentRef::Equal(const MHContentRef &cr, MHEngine *engine) const
void MHGenericBoolean::Initialise(MHParseNode *pArg, MHEngine *engine)
{
- if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_INDIRECTREFERENCE) {
+ if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_INDIRECTREFERENCE)
+ {
// Indirect reference.
m_fIsDirect = false;
m_Indirect.Initialise(pArg->GetArgN(0), engine);
}
- else { // Simple integer value.
+ else // Simple integer value.
+ {
m_fIsDirect = true;
m_fDirect = pArg->GetBoolValue();
}
@@ -238,15 +363,26 @@ void MHGenericBoolean::Initialise(MHParseNode *pArg, MHEngine *engine)
void MHGenericBoolean::PrintMe(FILE *fd, int nTabs) const
{
- if (m_fIsDirect) fprintf(fd, "%s ", m_fDirect ? "true" : "false");
- else { fprintf(fd, ":IndirectRef "); m_Indirect.PrintMe(fd, nTabs+1); }
+ if (m_fIsDirect)
+ {
+ fprintf(fd, "%s ", m_fDirect ? "true" : "false");
+ }
+ else
+ {
+ fprintf(fd, ":IndirectRef ");
+ m_Indirect.PrintMe(fd, nTabs + 1);
+ }
}
// Return the value, looking up any indirect ref.
bool MHGenericBoolean::GetValue(MHEngine *engine) const
{
- if (m_fIsDirect) return m_fDirect;
- else {
+ if (m_fIsDirect)
+ {
+ return m_fDirect;
+ }
+ else
+ {
MHUnion result;
MHRoot *pBase = engine->FindObject(m_Indirect);
pBase->GetVariableValue(result, engine);
@@ -258,18 +394,24 @@ bool MHGenericBoolean::GetValue(MHEngine *engine) const
// Return the indirect reference or fail if it's direct
MHObjectRef *MHGenericBase::GetReference()
{
- if (m_fIsDirect) MHERROR("Expected indirect reference");
+ if (m_fIsDirect)
+ {
+ MHERROR("Expected indirect reference");
+ }
+
return &m_Indirect;
}
void MHGenericInteger::Initialise(MHParseNode *pArg, MHEngine *engine)
{
- if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_INDIRECTREFERENCE) {
+ if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_INDIRECTREFERENCE)
+ {
// Indirect reference.
m_fIsDirect = false;
m_Indirect.Initialise(pArg->GetArgN(0), engine);
}
- else { // Simple integer value.
+ else // Simple integer value.
+ {
m_fIsDirect = true;
m_nDirect = pArg->GetIntValue();
}
@@ -277,35 +419,69 @@ void MHGenericInteger::Initialise(MHParseNode *pArg, MHEngine *engine)
void MHGenericInteger::PrintMe(FILE *fd, int nTabs) const
{
- if (m_fIsDirect) fprintf(fd, "%d ", m_nDirect);
- else { fprintf(fd, ":IndirectRef "); m_Indirect.PrintMe(fd, nTabs+1); }
+ if (m_fIsDirect)
+ {
+ fprintf(fd, "%d ", m_nDirect);
+ }
+ else
+ {
+ fprintf(fd, ":IndirectRef ");
+ m_Indirect.PrintMe(fd, nTabs + 1);
+ }
}
// Return the value, looking up any indirect ref.
int MHGenericInteger::GetValue(MHEngine *engine) const
{
- if (m_fIsDirect) return m_nDirect;
- else {
+ if (m_fIsDirect)
+ {
+ return m_nDirect;
+ }
+ else
+ {
MHUnion result;
MHRoot *pBase = engine->FindObject(m_Indirect);
pBase->GetVariableValue(result, engine);
+
// From my reading of the MHEG documents implicit conversion is only
// performed when assigning variables. Nevertheless the Channel 4
// Teletext assumes that implicit conversion takes place here as well.
- if (result.m_Type == MHUnion::U_String) {
+ if (result.m_Type == MHUnion::U_String)
+ {
// Implicit conversion of string to integer.
int v = 0;
int p = 0;
bool fNegative = false;
- if (result.m_StrVal.Size() > 0 && result.m_StrVal.GetAt(0) == '-') { p++; fNegative = true; }
- for ( ; p < result.m_StrVal.Size(); p++) {
+
+ if (result.m_StrVal.Size() > 0 && result.m_StrVal.GetAt(0) == '-')
+ {
+ p++;
+ fNegative = true;
+ }
+
+ for (; p < result.m_StrVal.Size(); p++)
+ {
unsigned char ch = result.m_StrVal.GetAt(p);
- if (ch < '0' || ch > '9') break;
+
+ if (ch < '0' || ch > '9')
+ {
+ break;
+ }
+
v = v * 10 + ch - '0';
}
- if (fNegative) return -v; else return v;
+
+ if (fNegative)
+ {
+ return -v;
+ }
+ else
+ {
+ return v;
+ }
}
- else {
+ else
+ {
result.CheckType(MHUnion::U_Int);
return result.m_nIntVal;
}
@@ -314,12 +490,14 @@ int MHGenericInteger::GetValue(MHEngine *engine) const
void MHGenericOctetString::Initialise(MHParseNode *pArg, MHEngine *engine)
{
- if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_INDIRECTREFERENCE) {
+ if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_INDIRECTREFERENCE)
+ {
// Indirect reference.
m_fIsDirect = false;
m_Indirect.Initialise(pArg->GetArgN(0), engine);
}
- else { // Simple string value.
+ else // Simple string value.
+ {
m_fIsDirect = true;
pArg->GetStringValue(m_Direct);
}
@@ -327,22 +505,35 @@ void MHGenericOctetString::Initialise(MHParseNode *pArg, MHEngine *engine)
void MHGenericOctetString::PrintMe(FILE *fd, int /*nTabs*/) const
{
- if (m_fIsDirect) m_Direct.PrintMe(fd, 0);
- else { fprintf(fd, ":IndirectRef "); m_Indirect.PrintMe(fd, 0); }
+ if (m_fIsDirect)
+ {
+ m_Direct.PrintMe(fd, 0);
+ }
+ else
+ {
+ fprintf(fd, ":IndirectRef ");
+ m_Indirect.PrintMe(fd, 0);
+ }
}
// Return the value, looking up any indirect ref.
void MHGenericOctetString::GetValue(MHOctetString &str, MHEngine *engine) const
{
- if (m_fIsDirect) str.Copy(m_Direct);
- else {
+ if (m_fIsDirect)
+ {
+ str.Copy(m_Direct);
+ }
+ else
+ {
MHUnion result;
MHRoot *pBase = engine->FindObject(m_Indirect);
pBase->GetVariableValue(result, engine);
+
// From my reading of the MHEG documents implicit conversion is only
// performed when assigning variables. Nevertheless the Channel 4
// Teletext assumes that implicit conversion takes place here as well.
- if (result.m_Type == MHUnion::U_Int) {
+ if (result.m_Type == MHUnion::U_Int)
+ {
// Implicit conversion of int to string.
char buff[30]; // 30 chars is more than enough.
#ifdef WIN32
@@ -352,7 +543,8 @@ void MHGenericOctetString::GetValue(MHOctetString &str, MHEngine *engine) const
#endif
str.Copy(buff);
}
- else {
+ else
+ {
result.CheckType(MHUnion::U_String);
str.Copy(result.m_StrVal);
}
@@ -361,12 +553,14 @@ void MHGenericOctetString::GetValue(MHOctetString &str, MHEngine *engine) const
void MHGenericObjectRef::Initialise(MHParseNode *pArg, MHEngine *engine)
{
- if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_INDIRECTREFERENCE) {
+ if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_INDIRECTREFERENCE)
+ {
// Indirect reference.
m_fIsDirect = false;
m_Indirect.Initialise(pArg->GetArgN(0), engine);
}
- else { // Direct reference.
+ else // Direct reference.
+ {
m_fIsDirect = true;
m_ObjRef.Initialise(pArg, engine);
}
@@ -374,15 +568,26 @@ void MHGenericObjectRef::Initialise(MHParseNode *pArg, MHEngine *engine)
void MHGenericObjectRef::PrintMe(FILE *fd, int nTabs) const
{
- if (m_fIsDirect) m_ObjRef.PrintMe(fd, nTabs+1);
- else { fprintf(fd, ":IndirectRef "); m_Indirect.PrintMe(fd, nTabs+1); }
+ if (m_fIsDirect)
+ {
+ m_ObjRef.PrintMe(fd, nTabs + 1);
+ }
+ else
+ {
+ fprintf(fd, ":IndirectRef ");
+ m_Indirect.PrintMe(fd, nTabs + 1);
+ }
}
// Return the value, looking up any indirect ref.
void MHGenericObjectRef::GetValue(MHObjectRef &ref, MHEngine *engine) const
{
- if (m_fIsDirect) ref.Copy(m_ObjRef);
- else {
+ if (m_fIsDirect)
+ {
+ ref.Copy(m_ObjRef);
+ }
+ else
+ {
MHUnion result;
MHRoot *pBase = engine->FindObject(m_Indirect);
pBase->GetVariableValue(result, engine);
@@ -393,29 +598,45 @@ void MHGenericObjectRef::GetValue(MHObjectRef &ref, MHEngine *engine) const
void MHGenericContentRef::Initialise(MHParseNode *pArg, MHEngine *engine)
{
- if (pArg->GetTagNo() == C_INDIRECTREFERENCE) {
+ if (pArg->GetTagNo() == C_INDIRECTREFERENCE)
+ {
// Indirect reference.
m_fIsDirect = false;
m_Indirect.Initialise(pArg->GetArgN(0), engine);
}
- else if (pArg->GetTagNo() == C_CONTENT_REFERENCE){ // Direct reference.
+ else if (pArg->GetTagNo() == C_CONTENT_REFERENCE) // Direct reference.
+ {
m_fIsDirect = true;
m_Direct.Initialise(pArg->GetArgN(0), engine);
}
- else MHERROR("Expected direct or indirect content reference");
+ else
+ {
+ MHERROR("Expected direct or indirect content reference");
+ }
}
void MHGenericContentRef::PrintMe(FILE *fd, int /*nTabs*/) const
{
- if (m_fIsDirect) m_Direct.PrintMe(fd, 0);
- else { fprintf(fd, ":IndirectRef "); m_Indirect.PrintMe(fd, 0); }
+ if (m_fIsDirect)
+ {
+ m_Direct.PrintMe(fd, 0);
+ }
+ else
+ {
+ fprintf(fd, ":IndirectRef ");
+ m_Indirect.PrintMe(fd, 0);
+ }
}
// Return the value, looking up any indirect ref.
void MHGenericContentRef::GetValue(MHContentRef &ref, MHEngine *engine) const
{
- if (m_fIsDirect) ref.Copy(m_Direct);
- else {
+ if (m_fIsDirect)
+ {
+ ref.Copy(m_Direct);
+ }
+ else
+ {
MHUnion result;
MHRoot *pBase = engine->FindObject(m_Indirect);
pBase->GetVariableValue(result, engine);
@@ -424,63 +645,126 @@ void MHGenericContentRef::GetValue(MHContentRef &ref, MHEngine *engine) const
}
}
-// Copies the argument, getting the value of an indirect args.
+// Copies the argument, getting the value of an indirect args.
void MHUnion::GetValueFrom(const MHParameter &value, MHEngine *engine)
{
- switch (value.m_Type) {
- case MHParameter::P_Int: m_Type = U_Int; m_nIntVal = value.m_IntVal.GetValue(engine); break;
- case MHParameter::P_Bool: m_Type = U_Bool; m_fBoolVal = value.m_BoolVal.GetValue(engine); break;
- case MHParameter::P_String: m_Type = U_String; value.m_StrVal.GetValue(m_StrVal, engine); break;
- case MHParameter::P_ObjRef: m_Type = U_ObjRef; value.m_ObjRefVal.GetValue(m_ObjRefVal, engine); break;
- case MHParameter::P_ContentRef: m_Type = U_ContentRef; value.m_ContentRefVal.GetValue(m_ContentRefVal, engine); break;
- case MHParameter::P_Null: m_Type = U_None; break;
+ switch (value.m_Type)
+ {
+ case MHParameter::P_Int:
+ m_Type = U_Int;
+ m_nIntVal = value.m_IntVal.GetValue(engine);
+ break;
+ case MHParameter::P_Bool:
+ m_Type = U_Bool;
+ m_fBoolVal = value.m_BoolVal.GetValue(engine);
+ break;
+ case MHParameter::P_String:
+ m_Type = U_String;
+ value.m_StrVal.GetValue(m_StrVal, engine);
+ break;
+ case MHParameter::P_ObjRef:
+ m_Type = U_ObjRef;
+ value.m_ObjRefVal.GetValue(m_ObjRefVal, engine);
+ break;
+ case MHParameter::P_ContentRef:
+ m_Type = U_ContentRef;
+ value.m_ContentRefVal.GetValue(m_ContentRefVal, engine);
+ break;
+ case MHParameter::P_Null:
+ m_Type = U_None;
+ break;
}
}
const char *MHUnion::GetAsString(enum UnionTypes t)
{
- switch (t) {
- case U_Int: return "int";
- case U_Bool: return "bool";
- case U_String: return "string";
- case U_ObjRef: return "objref";
- case U_ContentRef: return "contentref";
- case U_None: return "none";
+ switch (t)
+ {
+ case U_Int:
+ return "int";
+ case U_Bool:
+ return "bool";
+ case U_String:
+ return "string";
+ case U_ObjRef:
+ return "objref";
+ case U_ContentRef:
+ return "contentref";
+ case U_None:
+ return "none";
}
+
return ""; // Not reached.
}
void MHUnion::CheckType(enum UnionTypes t) const
{
if (m_Type != t)
+ {
MHERROR(QString("Type mismatch - expected %1 found %2").arg(GetAsString(m_Type)).arg(GetAsString(t)));
+ }
}
// A parameter is a generic whose argument is either the value itself or an indirect reference.
void MHParameter::Initialise(MHParseNode *p, MHEngine *engine)
{
- switch (p->GetTagNo()) {
- case C_NEW_GENERIC_BOOLEAN: m_Type = P_Bool; m_BoolVal.Initialise(p->GetArgN(0), engine); break;
- case C_NEW_GENERIC_INTEGER: m_Type = P_Int; m_IntVal.Initialise(p->GetArgN(0), engine); break;
- case C_NEW_GENERIC_OCTETSTRING: m_Type = P_String; m_StrVal.Initialise(p->GetArgN(0), engine); break;
- case C_NEW_GENERIC_OBJECT_REF: m_Type = P_ObjRef; m_ObjRefVal.Initialise(p->GetArgN(0), engine); break;
- case C_NEW_GENERIC_CONTENT_REF: m_Type = P_ContentRef; m_ContentRefVal.Initialise(p->GetArgN(0), engine); break;
- default: p->Failure("Expected generic");
+ switch (p->GetTagNo())
+ {
+ case C_NEW_GENERIC_BOOLEAN:
+ m_Type = P_Bool;
+ m_BoolVal.Initialise(p->GetArgN(0), engine);
+ break;
+ case C_NEW_GENERIC_INTEGER:
+ m_Type = P_Int;
+ m_IntVal.Initialise(p->GetArgN(0), engine);
+ break;
+ case C_NEW_GENERIC_OCTETSTRING:
+ m_Type = P_String;
+ m_StrVal.Initialise(p->GetArgN(0), engine);
+ break;
+ case C_NEW_GENERIC_OBJECT_REF:
+ m_Type = P_ObjRef;
+ m_ObjRefVal.Initialise(p->GetArgN(0), engine);
+ break;
+ case C_NEW_GENERIC_CONTENT_REF:
+ m_Type = P_ContentRef;
+ m_ContentRefVal.Initialise(p->GetArgN(0), engine);
+ break;
+ default:
+ p->Failure("Expected generic");
}
}
void MHParameter::PrintMe(FILE *fd, int nTabs) const
{
PrintTabs(fd, nTabs);
- switch (m_Type) {
- // Direct values.
- case P_Int: fprintf(fd, ":GInteger "); m_IntVal.PrintMe(fd, 0); break;
- case P_Bool: fprintf(fd, ":GBoolean "); m_BoolVal.PrintMe(fd, 0); break;
- case P_String: fprintf(fd, ":GOctetString "); m_StrVal.PrintMe(fd, 0); break;
- case P_ObjRef: fprintf(fd, ":GObjectRef "); m_ObjRefVal.PrintMe(fd, 0); break;
- case P_ContentRef: fprintf(fd, ":GObjectRef "); m_ContentRefVal.PrintMe(fd, 0); break;
- case P_Null: break;
+
+ switch (m_Type)
+ {
+ // Direct values.
+ case P_Int:
+ fprintf(fd, ":GInteger ");
+ m_IntVal.PrintMe(fd, 0);
+ break;
+ case P_Bool:
+ fprintf(fd, ":GBoolean ");
+ m_BoolVal.PrintMe(fd, 0);
+ break;
+ case P_String:
+ fprintf(fd, ":GOctetString ");
+ m_StrVal.PrintMe(fd, 0);
+ break;
+ case P_ObjRef:
+ fprintf(fd, ":GObjectRef ");
+ m_ObjRefVal.PrintMe(fd, 0);
+ break;
+ case P_ContentRef:
+ fprintf(fd, ":GObjectRef ");
+ m_ContentRefVal.PrintMe(fd, 0);
+ break;
+ case P_Null:
+ break;
}
}
@@ -489,14 +773,22 @@ void MHParameter::PrintMe(FILE *fd, int nTabs) const
// the assignment.
MHObjectRef *MHParameter::GetReference()
{
- switch (m_Type) {
- case P_Int: return m_IntVal.GetReference();
- case P_Bool: return m_BoolVal.GetReference();
- case P_String: return m_StrVal.GetReference();
- case P_ObjRef: return m_ObjRefVal.GetReference();
- case P_ContentRef: return m_ContentRefVal.GetReference();
- case P_Null: return NULL;
+ switch (m_Type)
+ {
+ case P_Int:
+ return m_IntVal.GetReference();
+ case P_Bool:
+ return m_BoolVal.GetReference();
+ case P_String:
+ return m_StrVal.GetReference();
+ case P_ObjRef:
+ return m_ObjRefVal.GetReference();
+ case P_ContentRef:
+ return m_ContentRefVal.GetReference();
+ case P_Null:
+ return NULL;
}
+
return NULL; // To keep VC++ happy
}
@@ -510,14 +802,26 @@ void MHContentRef::Initialise(MHParseNode *p, MHEngine *)
void MHFontBody::Initialise(MHParseNode *p, MHEngine *engine)
{
- if (p->m_nNodeType == MHParseNode::PNString) p->GetStringValue(m_DirFont);
- else m_IndirFont.Initialise(p, engine);
+ if (p->m_nNodeType == MHParseNode::PNString)
+ {
+ p->GetStringValue(m_DirFont);
+ }
+ else
+ {
+ m_IndirFont.Initialise(p, engine);
+ }
}
void MHFontBody::PrintMe(FILE *fd, int nTabs) const
{
- if (m_DirFont.Size() > 0) m_DirFont.PrintMe(fd, nTabs);
- else m_IndirFont.PrintMe(fd, nTabs);
+ if (m_DirFont.Size() > 0)
+ {
+ m_DirFont.PrintMe(fd, nTabs);
+ }
+ else
+ {
+ m_IndirFont.PrintMe(fd, nTabs);
+ }
}
void MHFontBody::Copy(const MHFontBody &fb)
@@ -534,6 +838,9 @@ void MHPointArg::Initialise(MHParseNode *p, MHEngine *engine)
void MHPointArg::PrintMe(FILE *fd, int nTabs) const
{
- fprintf(fd, "( "); x.PrintMe(fd, nTabs); y.PrintMe(fd, nTabs); fprintf(fd, ") ");
+ fprintf(fd, "( ");
+ x.PrintMe(fd, nTabs);
+ y.PrintMe(fd, nTabs);
+ fprintf(fd, ") ");
}
diff --git a/mythtv/libs/libmythfreemheg/BaseClasses.h b/mythtv/libs/libmythfreemheg/BaseClasses.h
index 4c67a83f5bb..587577f0cdf 100644
--- a/mythtv/libs/libmythfreemheg/BaseClasses.h
+++ b/mythtv/libs/libmythfreemheg/BaseClasses.h
@@ -104,7 +104,7 @@ class MHParseNode;
// strings from 1. We use 0 indexing in calls to these functions.
class MHOctetString
{
-public:
+ public:
MHOctetString();
MHOctetString(const char *str, int nLen = -1); // From character string
MHOctetString(const unsigned char *str, int nLen); // From byte vector
@@ -132,7 +132,7 @@ class MHOctetString
// A colour is encoded as a string or the index into a palette.
// Palettes aren't defined in UK MHEG so the palette index isn't really relevant.
class MHColour {
-public:
+ public:
MHColour(): m_nColIndex(-1) {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
@@ -147,7 +147,7 @@ class MHColour {
// Internal objects have the m_pGroupId field empty.
class MHObjectRef
{
-public:
+ public:
MHObjectRef() { m_nObjectNo = 0; }
void Initialise(MHParseNode *p, MHEngine *engine);
void Copy(const MHObjectRef &objr);
@@ -166,7 +166,7 @@ class MHObjectRef
// A content reference gives the location (e.g. file name) to find the content.
class MHContentRef
{
-public:
+ public:
MHContentRef() {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const { m_ContentRef.PrintMe(fd, nTabs); }
@@ -182,7 +182,7 @@ class MHContentRef
// "Generic" versions of int, bool etc can be either the value or an indirect reference.
class MHGenericBase
{
-public:
+ public:
MHObjectRef *GetReference(); // Return the indirect reference or fail if it's direct
protected:
bool m_fIsDirect;
@@ -191,7 +191,7 @@ class MHGenericBase
class MHGenericBoolean: public MHGenericBase
{
-public:
+ public:
MHGenericBoolean() : m_fDirect(false) {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
@@ -202,7 +202,7 @@ class MHGenericBoolean: public MHGenericBase
class MHGenericInteger: public MHGenericBase
{
-public:
+ public:
MHGenericInteger() : m_nDirect(-1) {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
@@ -213,7 +213,7 @@ class MHGenericInteger: public MHGenericBase
class MHGenericOctetString: public MHGenericBase
{
-public:
+ public:
MHGenericOctetString() {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
@@ -224,7 +224,7 @@ class MHGenericOctetString: public MHGenericBase
class MHGenericObjectRef: public MHGenericBase
{
-public:
+ public:
MHGenericObjectRef() {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
@@ -235,7 +235,7 @@ class MHGenericObjectRef: public MHGenericBase
class MHGenericContentRef: public MHGenericBase
{
-public:
+ public:
MHGenericContentRef() {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
@@ -247,7 +247,7 @@ class MHGenericContentRef: public MHGenericBase
// In certain cases (e.g. parameters to Call) we have values which are the union of the base types.
class MHParameter
{
-public:
+ public:
MHParameter(): m_Type(P_Null) {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
@@ -265,7 +265,7 @@ class MHParameter
// A union type. Returned when a parameter is evaluated.
class MHUnion
{
-public:
+ public:
MHUnion() { m_Type = U_None; }
MHUnion(int nVal) { m_Type = U_Int; m_nIntVal = nVal; }
MHUnion(bool fVal) { m_Type = U_Bool; m_fBoolVal = fVal; }
@@ -288,7 +288,7 @@ class MHUnion
class MHFontBody {
// A font body can either be a string or an object reference
-public:
+ public:
MHFontBody() {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
@@ -301,7 +301,7 @@ class MHFontBody {
// This is used only in DynamicLineArt
class MHPointArg {
-public:
+ public:
MHPointArg() {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
diff --git a/mythtv/libs/libmythfreemheg/Bitmap.cpp b/mythtv/libs/libmythfreemheg/Bitmap.cpp
index f2fee9654d8..42c9df1b26b 100644
--- a/mythtv/libs/libmythfreemheg/Bitmap.cpp
+++ b/mythtv/libs/libmythfreemheg/Bitmap.cpp
@@ -67,60 +67,106 @@ void MHBitmap::Initialise(MHParseNode *p, MHEngine *engine)
MHVisible::Initialise(p, engine);
// Tiling - optional
MHParseNode *pTiling = p->GetNamedArg(C_TILING);
- if (pTiling) m_fTiling = pTiling->GetArgN(0)->GetBoolValue();
+
+ if (pTiling)
+ {
+ m_fTiling = pTiling->GetArgN(0)->GetBoolValue();
+ }
+
// Transparency - optional
MHParseNode *pTransparency = p->GetNamedArg(C_ORIGINAL_TRANSPARENCY);
- if (pTransparency) m_nOrigTransparency = pTransparency->GetArgN(0)->GetIntValue();
+
+ if (pTransparency)
+ {
+ m_nOrigTransparency = pTransparency->GetArgN(0)->GetIntValue();
+ }
+
m_pContent = engine->GetContext()->CreateBitmap(m_fTiling);
}
void MHBitmap::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:Bitmap ");
- MHVisible::PrintMe(fd, nTabs+1);
- if (m_fTiling) { PrintTabs(fd, nTabs+1); fprintf(fd, ":Tiling true\n"); }
- if (m_nOrigTransparency != 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":OrigTransparency %d\n", m_nOrigTransparency); }
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:Bitmap ");
+ MHVisible::PrintMe(fd, nTabs + 1);
+
+ if (m_fTiling)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":Tiling true\n");
+ }
+
+ if (m_nOrigTransparency != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OrigTransparency %d\n", m_nOrigTransparency);
+ }
+
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHBitmap::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return;
+ if (m_fAvailable)
+ {
+ return;
+ }
+
m_nTransparency = m_nOrigTransparency; // Transparency isn't used in UK MHEG
MHVisible::Preparation(engine);
}
-//
+//
void MHBitmap::ContentPreparation(MHEngine *engine)
{
MHVisible::ContentPreparation(engine);
+
if (m_ContentType == IN_NoContent)
+ {
MHERROR("Bitmap must contain a content");
+ }
+
if (m_ContentType == IN_IncludedContent) // We can't handle included content at the moment.
+ {
MHERROR("Included content in bitmap is not implemented");
+ }
}
// Decode the content.
void MHBitmap::ContentArrived(const unsigned char *data, int length, MHEngine *engine)
{
QRegion updateArea = GetVisibleArea(); // If there's any content already we have to redraw it.
- if (! m_pContent) return; // Shouldn't happen.
+
+ if (! m_pContent)
+ {
+ return; // Shouldn't happen.
+ }
int nCHook = m_nContentHook;
- if (nCHook == 0) nCHook = engine->GetDefaultBitmapCHook();
+
+ if (nCHook == 0)
+ {
+ nCHook = engine->GetDefaultBitmapCHook();
+ }
// TODO: What if we can't convert it?
- if (nCHook == 4) { // PNG.
+ if (nCHook == 4) // PNG.
+ {
m_pContent->CreateFromPNG(data, length);
}
// CHook 5 seems to be used by the BBC on Freesat for an MPEG I-frame for the
// background but enabling it here results in it overlaying the video.
// Presumably it is not simply the same as CHook 2.
- else if (nCHook == 2 /* ||nCHook == 5 */) { // MPEG I-frame.
+ else if (nCHook == 2 /* ||nCHook == 5 */) // MPEG I-frame.
+ {
m_pContent->CreateFromMPEG(data, length);
}
- else MHERROR(QString("Unknown bitmap content hook %1").arg(nCHook));
+ else
+ {
+ MHERROR(QString("Unknown bitmap content hook %1").arg(nCHook));
+ }
updateArea += GetVisibleArea(); // Redraw this bitmap.
engine->Redraw(updateArea); // Mark for redrawing
@@ -136,8 +182,16 @@ void MHBitmap::SetTransparency(int nTransPerCent, MHEngine *)
{
// The object transparency isn't actually used in UK MHEG.
// We want a value between 0 and 255
- if (nTransPerCent < 0) nTransPerCent = 0; // Make sure it's in the bounds
- if (nTransPerCent > 100) nTransPerCent = 100;
+ if (nTransPerCent < 0)
+ {
+ nTransPerCent = 0; // Make sure it's in the bounds
+ }
+
+ if (nTransPerCent > 100)
+ {
+ nTransPerCent = 100;
+ }
+
m_nTransparency = ((nTransPerCent * 255) + 50) / 100;
}
@@ -169,22 +223,29 @@ void MHBitmap::GetBitmapDecodeOffset(MHRoot *pXOffset, MHRoot *pYOffset)
void MHBitmap::Display(MHEngine *)
{
- if (! m_fRunning || ! m_pContent || m_nBoxWidth == 0 || m_nBoxHeight == 0) return; // Can't draw zero sized boxes.
+ if (! m_fRunning || ! m_pContent || m_nBoxWidth == 0 || m_nBoxHeight == 0)
+ {
+ return; // Can't draw zero sized boxes.
+ }
- m_pContent->Draw(m_nPosX+m_nXDecodeOffset, m_nPosY+m_nYDecodeOffset,
- QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight), m_fTiling);
+ m_pContent->Draw(m_nPosX + m_nXDecodeOffset, m_nPosY + m_nYDecodeOffset,
+ QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight), m_fTiling);
}
// Return the region drawn by the bitmap.
QRegion MHBitmap::GetVisibleArea()
{
- if (! m_fRunning || m_pContent == NULL) return QRegion();
+ if (! m_fRunning || m_pContent == NULL)
+ {
+ return QRegion();
+ }
+
// The visible area is the intersection of the containing box with the, possibly offset,
// bitmap.
QSize imageSize = m_pContent->GetSize();
QRegion boxRegion = QRegion(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight);
- QRegion bitmapRegion = QRegion(m_nPosX+m_nXDecodeOffset, m_nPosY+m_nYDecodeOffset,
- imageSize.width(), imageSize.height());
+ QRegion bitmapRegion = QRegion(m_nPosX + m_nXDecodeOffset, m_nPosY + m_nYDecodeOffset,
+ imageSize.width(), imageSize.height());
return boxRegion & bitmapRegion;
}
@@ -192,7 +253,13 @@ QRegion MHBitmap::GetVisibleArea()
QRegion MHBitmap::GetOpaqueArea()
{
// The area is empty unless the bitmap is opaque.
- if (! m_fRunning || m_pContent == NULL || ! m_pContent->IsOpaque()) return QRegion();
- else return GetVisibleArea();
+ if (! m_fRunning || m_pContent == NULL || ! m_pContent->IsOpaque())
+ {
+ return QRegion();
+ }
+ else
+ {
+ return GetVisibleArea();
+ }
}
diff --git a/mythtv/libs/libmythfreemheg/Bitmap.h b/mythtv/libs/libmythfreemheg/Bitmap.h
index 21827b904f4..06d5f0b02fb 100644
--- a/mythtv/libs/libmythfreemheg/Bitmap.h
+++ b/mythtv/libs/libmythfreemheg/Bitmap.h
@@ -35,7 +35,7 @@ class MHBitmapDisplay;
class MHBitmap : public MHVisible
{
-public:
+ public:
MHBitmap();
MHBitmap(const MHBitmap &ref);
virtual const char *ClassName() { return "Bitmap"; }
@@ -59,7 +59,7 @@ class MHBitmap : public MHVisible
virtual QRegion GetVisibleArea();
virtual QRegion GetOpaqueArea();
-protected:
+ protected:
bool m_fTiling;
int m_nOrigTransparency;
@@ -73,13 +73,13 @@ class MHBitmap : public MHVisible
// Actions.
class MHSetTransparency: public MHActionInt {
-public:
+ public:
MHSetTransparency(): MHActionInt(":SetTransparency") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) { pTarget->SetTransparency(nArg, engine); }
};
class MHScaleBitmap: public MHActionIntInt {
-public:
+ public:
MHScaleBitmap(): MHActionIntInt(":ScaleBitmap") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2) { pTarget->ScaleBitmap(nArg1, nArg2, engine); }
};
@@ -87,7 +87,7 @@ class MHScaleBitmap: public MHActionIntInt {
// Actions added in the UK MHEG profile.
class MHSetBitmapDecodeOffset: public MHActionIntInt
{
-public:
+ public:
MHSetBitmapDecodeOffset(): MHActionIntInt(":SetBitmapDecodeOffset") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2)
{ pTarget->SetBitmapDecodeOffset(nArg1, nArg2, engine); }
@@ -95,7 +95,7 @@ class MHSetBitmapDecodeOffset: public MHActionIntInt
class MHGetBitmapDecodeOffset: public MHActionObjectRef2
{
-public:
+ public:
MHGetBitmapDecodeOffset(): MHActionObjectRef2(":GetBitmapDecodeOffset") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pArg1, MHRoot *pArg2) { pTarget->GetBitmapDecodeOffset(pArg1, pArg2); }
};
diff --git a/mythtv/libs/libmythfreemheg/DynamicLineArt.cpp b/mythtv/libs/libmythfreemheg/DynamicLineArt.cpp
index eb86a700d24..b4b0c2433e3 100644
--- a/mythtv/libs/libmythfreemheg/DynamicLineArt.cpp
+++ b/mythtv/libs/libmythfreemheg/DynamicLineArt.cpp
@@ -50,9 +50,11 @@ void MHDynamicLineArt::Initialise(MHParseNode *p, MHEngine *engine)
void MHDynamicLineArt::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:DynamicLineArt ");
- MHLineArt::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:DynamicLineArt ");
+ MHLineArt::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHDynamicLineArt::Preparation(MHEngine *engine)
@@ -72,8 +74,14 @@ void MHDynamicLineArt::Display(MHEngine *)
// Get the opaque area. This is only opaque if the background is opaque.
QRegion MHDynamicLineArt::GetOpaqueArea()
{
- if ((GetColour(m_OrigFillColour)).alpha() == 255) return GetVisibleArea();
- else return QRegion();
+ if ((GetColour(m_OrigFillColour)).alpha() == 255)
+ {
+ return GetVisibleArea();
+ }
+ else
+ {
+ return QRegion();
+ }
}
// Reset the picture.
@@ -112,22 +120,35 @@ void MHDynamicLineArt::SetLineWidth(int nWidth)
}
// We don't actually use this at the moment.
-void MHDynamicLineArt::SetLineStyle(int nStyle) { m_LineStyle = nStyle; }
+void MHDynamicLineArt::SetLineStyle(int nStyle)
+{
+ m_LineStyle = nStyle;
+}
void MHDynamicLineArt::GetLineColour(MHRoot *pResult)
{
// Returns the palette index as an integer if it is an index or the colour as a string if not.
if (m_LineColour.m_nColIndex >= 0)
+ {
pResult->SetVariableValue(m_LineColour.m_nColIndex);
- else pResult->SetVariableValue(m_LineColour.m_ColStr);
+ }
+ else
+ {
+ pResult->SetVariableValue(m_LineColour.m_ColStr);
+ }
}
void MHDynamicLineArt::GetFillColour(MHRoot *pResult)
{
if (m_FillColour.m_nColIndex >= 0)
+ {
pResult->SetVariableValue(m_FillColour.m_nColIndex);
- else pResult->SetVariableValue(m_FillColour.m_ColStr);
+ }
+ else
+ {
+ pResult->SetVariableValue(m_FillColour.m_ColStr);
+ }
}
void MHDynamicLineArt::DrawLine(int x1, int y1, int x2, int y2, MHEngine *engine)
@@ -138,7 +159,7 @@ void MHDynamicLineArt::DrawLine(int x1, int y1, int x2, int y2, MHEngine *engine
void MHDynamicLineArt::DrawRectangle(int x1, int y1, int x2, int y2, MHEngine *engine)
{
- m_picture->DrawBorderedRectangle(x1, y1, x2-x1, y2-y1);
+ m_picture->DrawBorderedRectangle(x1, y1, x2 - x1, y2 - y1);
engine->Redraw(GetVisibleArea());
}
@@ -168,7 +189,9 @@ void MHDrawPoly::Initialise(MHParseNode *p, MHEngine *engine)
{
MHElemAction::Initialise(p, engine);
MHParseNode *args = p->GetArgN(1);
- for (int i = 0; i < args->GetSeqCount(); i++) {
+
+ for (int i = 0; i < args->GetSeqCount(); i++)
+ {
MHPointArg *pPoint = new MHPointArg;
m_Points.Append(pPoint);
pPoint->Initialise(args->GetSeqN(i), engine);
@@ -180,11 +203,14 @@ void MHDrawPoly::Perform(MHEngine *engine)
int nPoints = m_Points.Size();
int *xArray = new int[nPoints];
int *yArray = new int[nPoints];
- for (int i = 0; i < nPoints; i++) {
+
+ for (int i = 0; i < nPoints; i++)
+ {
MHPointArg *pPoint = m_Points[i];
xArray[i] = pPoint->x.GetValue(engine);
yArray[i] = pPoint->y.GetValue(engine);
}
+
Target(engine)->DrawPoly(m_fIsPolygon, nPoints, xArray, yArray, engine);
delete[](xArray);
delete[](yArray);
@@ -193,6 +219,11 @@ void MHDrawPoly::Perform(MHEngine *engine)
void MHDrawPoly::PrintArgs(FILE *fd, int /*nTabs*/) const
{
fprintf(fd, " ( ");
- for (int i = 0; i < m_Points.Size(); i++) m_Points[i]->PrintMe(fd, 0);
+
+ for (int i = 0; i < m_Points.Size(); i++)
+ {
+ m_Points[i]->PrintMe(fd, 0);
+ }
+
fprintf(fd, " )\n");
}
diff --git a/mythtv/libs/libmythfreemheg/DynamicLineArt.h b/mythtv/libs/libmythfreemheg/DynamicLineArt.h
index 06e0916bfba..af772c14e76 100644
--- a/mythtv/libs/libmythfreemheg/DynamicLineArt.h
+++ b/mythtv/libs/libmythfreemheg/DynamicLineArt.h
@@ -31,7 +31,7 @@ class MHDLADisplay;
class MHDynamicLineArt : public MHLineArt
{
-public:
+ public:
MHDynamicLineArt();
virtual ~MHDynamicLineArt();
virtual const char *ClassName() { return "DynamicLineArt"; }
@@ -65,7 +65,7 @@ class MHDynamicLineArt : public MHLineArt
virtual void DrawRectangle(int x1, int y1, int x2, int y2, MHEngine *);
virtual void DrawPoly(bool fIsPolygon, int nPoints, const int *xArray, const int *yArray, MHEngine *);
-protected:
+ protected:
MHDLADisplay *m_picture; // The sequence of drawing actions.
};
@@ -73,7 +73,7 @@ class MHDynamicLineArt : public MHLineArt
// Get Line Width - return the current line width.
class MHGetLineWidth: public MHActionObjectRef
{
-public:
+ public:
MHGetLineWidth(): MHActionObjectRef(":GetLineWidth") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pResult) { pTarget->GetLineWidth(pResult); }
};
@@ -81,67 +81,67 @@ class MHGetLineWidth: public MHActionObjectRef
// Get Line Style - return the current line style.
class MHGetLineStyle: public MHActionObjectRef
{
-public:
+ public:
MHGetLineStyle(): MHActionObjectRef(":GetLineStyle") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pResult) { pTarget->GetLineStyle(pResult); }
};
// Get Line Colour - return the current line colour.
class MHGetLineColour: public MHActionObjectRef
{
-public:
+ public:
MHGetLineColour(): MHActionObjectRef(":GetLineColour") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pResult) { pTarget->GetLineColour(pResult); }
};
// Get Fill Colour - return the current fill colour.
class MHGetFillColour: public MHActionObjectRef
{
-public:
+ public:
MHGetFillColour(): MHActionObjectRef(":GetFillColour") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pResult) { pTarget->GetLineWidth(pResult); }
};
// Clear - reset the drawing
class MHClear: public MHElemAction {
-public:
+ public:
MHClear(): MHElemAction(":Clear") {}
virtual void Perform(MHEngine *engine) { Target(engine)->Clear(); }
};
// Draw an arc or a sector (basically a filled arc).
class MHDrawArcSector: public MHActionInt6 {
-public:
+ public:
MHDrawArcSector(const char *name, bool fIsSector): MHActionInt6(name), m_fIsSector(fIsSector) {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2, int nArg3, int nArg4, int nArg5, int nArg6)
{ pTarget->DrawArcSector(m_fIsSector, nArg1, nArg2, nArg3, nArg4, nArg5, nArg6, engine); }
-protected:
+ protected:
bool m_fIsSector;
};
// Draw a line.
class MHDrawLine: public MHActionInt4 {
-public:
+ public:
MHDrawLine(): MHActionInt4(":DrawLine") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2, int nArg3, int nArg4)
{ pTarget->DrawLine(nArg1, nArg2, nArg3, nArg4, engine); }
};
// Draw an oval.
class MHDrawOval: public MHActionInt4 {
-public:
+ public:
MHDrawOval(): MHActionInt4(":DrawOval") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2, int nArg3, int nArg4)
{ pTarget->DrawOval(nArg1, nArg2, nArg3, nArg4, engine); }
};
// Draw a rectangle.
class MHDrawRectangle: public MHActionInt4 {
-public:
+ public:
MHDrawRectangle(): MHActionInt4(":DrawRectangle") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2, int nArg3, int nArg4)
{ pTarget->DrawRectangle(nArg1, nArg2, nArg3, nArg4, engine); }
};
// Polygon and PolyLine
class MHDrawPoly: public MHElemAction {
-public:
+ public:
MHDrawPoly(const char *name, bool fIsPolygon): MHElemAction(name), m_fIsPolygon(fIsPolygon) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int nTabs) const;
bool m_fIsPolygon;
MHOwnPtrSequence m_Points; // List of points
diff --git a/mythtv/libs/libmythfreemheg/Engine.cpp b/mythtv/libs/libmythfreemheg/Engine.cpp
index dc3e2011d78..3ef08254eb5 100644
--- a/mythtv/libs/libmythfreemheg/Engine.cpp
+++ b/mythtv/libs/libmythfreemheg/Engine.cpp
@@ -53,11 +53,19 @@ MHEngine::MHEngine(MHContext *context): m_Context(context)
MHEngine::~MHEngine()
{
while (!m_ApplicationStack.isEmpty())
- delete m_ApplicationStack.pop();
+ {
+ delete m_ApplicationStack.pop();
+ }
+
while (!m_EventQueue.isEmpty())
- delete m_EventQueue.dequeue();
+ {
+ delete m_EventQueue.dequeue();
+ }
+
while (!m_ExternContentTable.isEmpty())
+ {
delete m_ExternContentTable.takeFirst();
+ }
}
// Check for external content every 2 seconds.
@@ -67,14 +75,24 @@ MHEngine::~MHEngine()
int MHEngine::RunAll()
{
// Request to boot or reboot
- if (m_fBooting) {
+ if (m_fBooting)
+ {
// Reset everything
while (!m_ApplicationStack.isEmpty())
+ {
delete m_ApplicationStack.pop();
+ }
+
while (!m_EventQueue.isEmpty())
+ {
delete m_EventQueue.dequeue();
+ }
+
while (!m_ExternContentTable.isEmpty())
+ {
delete m_ExternContentTable.takeFirst();
+ }
+
m_LinkTable.clear();
// UK MHEG applications boot from ~//a or ~//startup. Actually the initial
@@ -82,26 +100,34 @@ int MHEngine::RunAll()
MHObjectRef startObj;
startObj.m_nObjectNo = 0;
startObj.m_GroupId.Copy(MHOctetString("~//a"));
+
// Launch will block until either it finds the appropriate object and
// begins the application or discovers that the file definitely isn't
// present in the carousel. It is possible that the object might appear
// if one of the containing directories is updated.
if (! Launch(startObj))
{
- startObj.m_GroupId.Copy(MHOctetString("~//startup"));
- if (! Launch(startObj))
- {
- MHLOG(MHLogWarning, "MHEG engine auto-boot failed");
- return -1;
- }
+ startObj.m_GroupId.Copy(MHOctetString("~//startup"));
+
+ if (! Launch(startObj))
+ {
+ MHLOG(MHLogWarning, "MHEG engine auto-boot failed");
+ return -1;
+ }
}
+
m_fBooting = false;
}
int nNextTime = 0;
- do {
+
+ do
+ {
// Check to see if we need to close.
- if (m_Context->CheckStop()) return 0;
+ if (m_Context->CheckStop())
+ {
+ return 0;
+ }
// Run queued actions.
RunActions();
@@ -114,28 +140,42 @@ int MHEngine::RunAll()
// Check the timers. This may result in timer events being raised.
nNextTime = CurrentScene() ? CurrentScene()->CheckTimers(this) : 0;
- if (CurrentApp()) {
+
+ if (CurrentApp())
+ {
// The UK MHEG profile allows applications to have timers.
int nAppTime = CurrentApp()->CheckTimers(this);
- if (nAppTime != 0 && (nNextTime == 0 || nAppTime < nNextTime)) nNextTime = nAppTime;
+
+ if (nAppTime != 0 && (nNextTime == 0 || nAppTime < nNextTime))
+ {
+ nNextTime = nAppTime;
+ }
}
- if (! m_ExternContentTable.isEmpty()) {
+
+ if (! m_ExternContentTable.isEmpty())
+ {
// If we have an outstanding request for external content we need to set a timer.
- if (nNextTime == 0 || nNextTime > CONTENT_CHECK_TIME) nNextTime = CONTENT_CHECK_TIME;
+ if (nNextTime == 0 || nNextTime > CONTENT_CHECK_TIME)
+ {
+ nNextTime = CONTENT_CHECK_TIME;
+ }
}
- if (! m_EventQueue.isEmpty()) {
+ if (! m_EventQueue.isEmpty())
+ {
MHAsynchEvent *pEvent = m_EventQueue.dequeue();
MHLOG(MHLogLinks, QString("Asynchronous event dequeued - %1 from %2")
- .arg(MHLink::EventTypeToString(pEvent->eventType))
- .arg(pEvent->pEventSource->m_ObjectReference.Printable()));
+ .arg(MHLink::EventTypeToString(pEvent->eventType))
+ .arg(pEvent->pEventSource->m_ObjectReference.Printable()));
CheckLinks(pEvent->pEventSource->m_ObjectReference, pEvent->eventType, pEvent->eventData);
delete pEvent;
}
- } while (! m_EventQueue.isEmpty() || ! m_ActionStack.isEmpty());
+ }
+ while (! m_EventQueue.isEmpty() || ! m_ActionStack.isEmpty());
// Redraw the display if necessary.
- if (! m_redrawRegion.isEmpty()) {
+ if (! m_redrawRegion.isEmpty())
+ {
m_Context->RequireRedraw(m_redrawRegion);
m_redrawRegion = QRegion();
}
@@ -147,7 +187,11 @@ int MHEngine::RunAll()
// Convert the parse tree for an application or scene into an object node.
MHGroup *MHEngine::ParseProgram(QByteArray &text)
{
- if (text.size() == 0) return NULL;
+ if (text.size() == 0)
+ {
+ return NULL;
+ }
+
// Look at the first byte to decide whether this is text or binary. Binary
// files will begin with 0xA0 or 0xA1, text files with white space, comment ('/')
// or curly bracket.
@@ -156,28 +200,45 @@ MHGroup *MHEngine::ParseProgram(QByteArray &text)
MHParseBase *parser = NULL;
MHParseNode *pTree = NULL;
MHGroup *pRes = NULL;
- if (ch >= 128) parser = new MHParseBinary(text);
- else parser = new MHParseText(text);
- try {
+ if (ch >= 128)
+ {
+ parser = new MHParseBinary(text);
+ }
+ else
+ {
+ parser = new MHParseText(text);
+ }
+
+ try
+ {
// Parse the binary or text.
pTree = parser->Parse();
- switch (pTree->GetTagNo()) { // The parse node should be a tagged item.
- case C_APPLICATION: pRes = new MHApplication; break;
- case C_SCENE: pRes = new MHScene; break;
- default: pTree->Failure("Expected Application or Scene"); // throws exception.
+ switch (pTree->GetTagNo()) // The parse node should be a tagged item.
+ {
+ case C_APPLICATION:
+ pRes = new MHApplication;
+ break;
+ case C_SCENE:
+ pRes = new MHScene;
+ break;
+ default:
+ pTree->Failure("Expected Application or Scene"); // throws exception.
}
+
pRes->Initialise(pTree, this); // Convert the parse tree.
delete(pTree);
delete(parser);
}
- catch (...) {
+ catch (...)
+ {
delete(parser);
delete(pTree);
delete(pRes);
throw;
}
+
return pRes;
}
@@ -185,18 +246,29 @@ MHGroup *MHEngine::ParseProgram(QByteArray &text)
bool MHEngine::Launch(const MHObjectRef &target, bool fIsSpawn)
{
QString csPath = GetPathName(target.m_GroupId); // Get path relative to root.
- if (csPath.length() == 0) return false; // No file name.
- if (m_fInTransition) {
+
+ if (csPath.length() == 0)
+ {
+ return false; // No file name.
+ }
+
+ if (m_fInTransition)
+ {
MHLOG(MHLogWarning, "Launch during transition - ignoring");
return false;
}
+
QByteArray text;
+
// Check that the file exists before we commit to the transition.
// This may block if we cannot be sure whether the object is present.
if (! m_Context->GetCarouselData(csPath, text))
{
if (CurrentApp())
- EventTriggered(CurrentApp(), EventEngineEvent, 2); // GroupIDRefError
+ {
+ EventTriggered(CurrentApp(), EventEngineEvent, 2); // GroupIDRefError
+ }
+
return false;
}
@@ -204,87 +276,137 @@ bool MHEngine::Launch(const MHObjectRef &target, bool fIsSpawn)
m_ActionStack.clear();
m_fInTransition = true; // Starting a transition
- try {
- if (CurrentApp()) {
- if (fIsSpawn) { // Run the CloseDown actions.
+
+ try
+ {
+ if (CurrentApp())
+ {
+ if (fIsSpawn) // Run the CloseDown actions.
+ {
AddActions(CurrentApp()->m_CloseDown);
RunActions();
}
- if (CurrentScene()) CurrentScene()->Destruction(this);
+
+ if (CurrentScene())
+ {
+ CurrentScene()->Destruction(this);
+ }
+
CurrentApp()->Destruction(this);
+
if (!fIsSpawn)
- delete m_ApplicationStack.pop(); // Pop and delete the current app.
+ {
+ delete m_ApplicationStack.pop(); // Pop and delete the current app.
+ }
}
- MHApplication *pProgram = (MHApplication*)ParseProgram(text);
+ MHApplication *pProgram = (MHApplication *)ParseProgram(text);
- if ((__mhlogoptions & MHLogScenes) && __mhlogStream != 0) { // Print it so we know what's going on.
+ if ((__mhlogoptions & MHLogScenes) && __mhlogStream != 0) // Print it so we know what's going on.
+ {
pProgram->PrintMe(__mhlogStream, 0);
}
- if (! pProgram->m_fIsApp) MHERROR("Expected an application");
+ if (! pProgram->m_fIsApp)
+ {
+ MHERROR("Expected an application");
+ }
// Save the path we use for this app.
pProgram->m_Path = csPath; // Record the path
int nPos = pProgram->m_Path.lastIndexOf('/');
- if (nPos < 0) pProgram->m_Path = "";
- else pProgram->m_Path = pProgram->m_Path.left(nPos);
- // Have now got the application.
- m_ApplicationStack.push(pProgram);
- // This isn't in the standard as far as I can tell but we have to do this because
- // we may have events referring to the old application.
- while (!m_EventQueue.isEmpty())
- delete m_EventQueue.dequeue();
+ if (nPos < 0)
+ {
+ pProgram->m_Path = "";
+ }
+ else
+ {
+ pProgram->m_Path = pProgram->m_Path.left(nPos);
+ }
+
+ // Have now got the application.
+ m_ApplicationStack.push(pProgram);
- // Activate the application. ....
- CurrentApp()->Activation(this);
- m_fInTransition = false; // The transition is complete
- return true;
+ // This isn't in the standard as far as I can tell but we have to do this because
+ // we may have events referring to the old application.
+ while (!m_EventQueue.isEmpty())
+ {
+ delete m_EventQueue.dequeue();
+ }
+
+ // Activate the application. ....
+ CurrentApp()->Activation(this);
+ m_fInTransition = false; // The transition is complete
+ return true;
}
- catch (...) {
- m_fInTransition = false; // The transition is complete
- return false;
+ catch (...)
+ {
+ m_fInTransition = false; // The transition is complete
+ return false;
}
}
void MHEngine::Quit()
{
- if (m_fInTransition) {
+ if (m_fInTransition)
+ {
MHLOG(MHLogWarning, "Quit during transition - ignoring");
return;
}
+
m_fInTransition = true; // Starting a transition
- if (CurrentScene()) CurrentScene()->Destruction(this);
+
+ if (CurrentScene())
+ {
+ CurrentScene()->Destruction(this);
+ }
+
CurrentApp()->Destruction(this);
+
// This isn't in the standard as far as I can tell but we have to do this because
// we may have events referring to the old application.
while (!m_EventQueue.isEmpty())
- delete m_EventQueue.dequeue();
+ {
+ delete m_EventQueue.dequeue();
+ }
delete m_ApplicationStack.pop();
+
// If the stack is now empty we return to boot mode.
if (m_ApplicationStack.isEmpty())
+ {
m_fBooting = true;
- else {
+ }
+ else
+ {
CurrentApp()->m_fRestarting = true;
CurrentApp()->Activation(this); // This will do any OnRestart actions.
// Note - this doesn't activate the previously active scene.
}
+
m_fInTransition = false; // The transition is complete
}
void MHEngine::TransitionToScene(const MHObjectRef &target)
{
int i;
- if (m_fInTransition) {
+
+ if (m_fInTransition)
+ {
// TransitionTo is not allowed in OnStartUp or OnCloseDown actions.
MHLOG(MHLogWarning, "TransitionTo during transition - ignoring");
return;
}
- if (target.m_GroupId.Size() == 0) return; // No file name.
+
+ if (target.m_GroupId.Size() == 0)
+ {
+ return; // No file name.
+ }
+
QString csPath = GetPathName(target.m_GroupId);
QByteArray text;
+
// Check that the file exists before we commit to the transition.
if (! m_Context->GetCarouselData(csPath, text))
{
@@ -294,22 +416,37 @@ void MHEngine::TransitionToScene(const MHObjectRef &target)
// Parse and run the file.
MHGroup *pProgram = ParseProgram(text);
- if (pProgram->m_fIsApp) MHERROR("Expected a scene");
+
+ if (pProgram->m_fIsApp)
+ {
+ MHERROR("Expected a scene");
+ }
+
// Clear the action queue of anything pending.
m_ActionStack.clear();
// At this point we have managed to load the scene.
// Deactivate any non-shared ingredients in the application.
MHApplication *pApp = CurrentApp();
- for (i = pApp->m_Items.Size(); i > 0; i--) {
- MHIngredient *pItem = pApp->m_Items.GetAt(i-1);
- if (! pItem->IsShared()) pItem->Deactivation(this); // This does not remove them from the display stack.
+
+ for (i = pApp->m_Items.Size(); i > 0; i--)
+ {
+ MHIngredient *pItem = pApp->m_Items.GetAt(i - 1);
+
+ if (! pItem->IsShared())
+ {
+ pItem->Deactivation(this); // This does not remove them from the display stack.
+ }
}
+
m_fInTransition = true; // TransitionTo etc are not allowed.
- if (pApp->m_pCurrentScene) {
+
+ if (pApp->m_pCurrentScene)
+ {
pApp->m_pCurrentScene->Deactivation(this); // This may involve a call to RunActions
pApp->m_pCurrentScene->Destruction(this);
}
+
// Everything that belongs to the previous scene should have been removed from the display stack.
// At this point we may have added actions to the queue as a result of synchronous
@@ -318,21 +455,26 @@ void MHEngine::TransitionToScene(const MHObjectRef &target)
// Remove any events from the asynch event queue unless they derive from
// the application itself or a shared ingredient.
MHAsynchEvent *pEvent;
- QQueue::iterator it = m_EventQueue.begin();
+ QQueue::iterator it = m_EventQueue.begin();
+
while (it != m_EventQueue.end())
{
pEvent = *it;
+
if (!pEvent->pEventSource->IsShared())
{
delete pEvent;
it = m_EventQueue.erase(it);
}
else
+ {
++it;
+ }
}
// Can now actually delete the old scene.
- if (pApp->m_pCurrentScene) {
+ if (pApp->m_pCurrentScene)
+ {
delete(pApp->m_pCurrentScene);
pApp->m_pCurrentScene = NULL;
}
@@ -340,13 +482,15 @@ void MHEngine::TransitionToScene(const MHObjectRef &target)
m_Interacting = 0;
// Switch to the new scene.
- CurrentApp()->m_pCurrentScene = (MHScene*) pProgram;
+ CurrentApp()->m_pCurrentScene = (MHScene *) pProgram;
SetInputRegister(CurrentScene()->m_nEventReg);
m_redrawRegion = QRegion(0, 0, CurrentScene()->m_nSceneCoordX, CurrentScene()->m_nSceneCoordY); // Redraw the whole screen
- if ((__mhlogoptions & MHLogScenes) && __mhlogStream != 0) { // Print it so we know what's going on.
+ if ((__mhlogoptions & MHLogScenes) && __mhlogStream != 0) // Print it so we know what's going on.
+ {
pProgram->PrintMe(__mhlogStream, 0);
}
+
pProgram->Preparation(this);
pProgram->Activation(this);
m_fInTransition = false; // The transition is complete
@@ -361,26 +505,55 @@ void MHEngine::SetInputRegister(int nReg)
QString MHEngine::GetPathName(const MHOctetString &str)
{
QString csPath;
- if (str.Size() != 0) csPath = QString::fromUtf8((const char *)str.Bytes(), str.Size());
- if (csPath.left(4) == "DSM:") csPath = csPath.mid(4); // Remove DSM:
+
+ if (str.Size() != 0)
+ {
+ csPath = QString::fromUtf8((const char *)str.Bytes(), str.Size());
+ }
+
+ if (csPath.left(4) == "DSM:")
+ {
+ csPath = csPath.mid(4); // Remove DSM:
+ }
+
// If it has any other prefix this isn't a request for a carousel object.
int firstColon = csPath.indexOf(':'), firstSlash = csPath.indexOf('/');
+
if (firstColon > 0 && firstSlash > 0 && firstColon < firstSlash)
+ {
return QString();
+ }
+
+ if (csPath.left(1) == "~")
+ {
+ csPath = csPath.mid(1); // Remove ~
+ }
- if (csPath.left(1) == "~") csPath = csPath.mid(1); // Remove ~
// Ignore "CI://"
- if (csPath.left(2) != "//") { //
+ if (csPath.left(2) != "//") //
+ {
// Add the current application's path name
- if (CurrentApp()) csPath = CurrentApp()->m_Path + csPath;
+ if (CurrentApp())
+ {
+ csPath = CurrentApp()->m_Path + csPath;
+ }
}
+
// Remove any occurrences of x/../
int nPos;
- while ((nPos = csPath.indexOf("/../")) >= 0) {
- int nEnd = nPos+4;
- while (nPos >= 1 && csPath[nPos-1] != '/') nPos--;
+
+ while ((nPos = csPath.indexOf("/../")) >= 0)
+ {
+ int nEnd = nPos + 4;
+
+ while (nPos >= 1 && csPath[nPos-1] != '/')
+ {
+ nPos--;
+ }
+
csPath = csPath.left(nPos) + csPath.mid(nEnd);
}
+
return csPath;
}
@@ -390,13 +563,28 @@ MHRoot *MHEngine::FindObject(const MHObjectRef &oRef, bool failOnNotFound)
// It should match either the application or the scene.
MHGroup *pSearch = NULL;
MHGroup *pScene = CurrentScene(), *pApp = CurrentApp();
- if (pScene && GetPathName(pScene->m_ObjectReference.m_GroupId) == GetPathName(oRef.m_GroupId)) pSearch = pScene;
- else if (pApp && GetPathName(pApp->m_ObjectReference.m_GroupId) == GetPathName(oRef.m_GroupId)) pSearch = pApp;
- if (pSearch) {
+
+ if (pScene && GetPathName(pScene->m_ObjectReference.m_GroupId) == GetPathName(oRef.m_GroupId))
+ {
+ pSearch = pScene;
+ }
+ else if (pApp && GetPathName(pApp->m_ObjectReference.m_GroupId) == GetPathName(oRef.m_GroupId))
+ {
+ pSearch = pApp;
+ }
+
+ if (pSearch)
+ {
MHRoot *pItem = pSearch->FindByObjectNo(oRef.m_nObjectNo);
- if (pItem) return pItem;
+
+ if (pItem)
+ {
+ return pItem;
+ }
}
- if (failOnNotFound) {
+
+ if (failOnNotFound)
+ {
// I've seen at least one case where MHEG code has quite deliberately referred to
// an object that may or may not exist at a particular time.
// Another case was a call to CallActionSlot with an object reference variable
@@ -404,23 +592,32 @@ MHRoot *MHEngine::FindObject(const MHObjectRef &oRef, bool failOnNotFound)
MHLOG(MHLogWarning, QString("Reference %1 not found").arg(oRef.m_nObjectNo));
throw "FindObject failed";
}
+
return NULL; // If we don't generate an error.
}
// Run queued actions.
void MHEngine::RunActions()
{
- while (! m_ActionStack.isEmpty()) {
+ while (! m_ActionStack.isEmpty())
+ {
// Remove the first action.
MHElemAction *pAction = m_ActionStack.pop();
+
// Run it. If it fails and throws an exception catch it and continue with the next.
- try {
- if ((__mhlogoptions & MHLogActions) && __mhlogStream != 0) { // Debugging
- fprintf(__mhlogStream, "Action - "); pAction->PrintMe(__mhlogStream, 0); fflush(__mhlogStream);
+ try
+ {
+ if ((__mhlogoptions & MHLogActions) && __mhlogStream != 0) // Debugging
+ {
+ fprintf(__mhlogStream, "Action - ");
+ pAction->PrintMe(__mhlogStream, 0);
+ fflush(__mhlogStream);
}
+
pAction->Perform(this);
}
- catch (char const *) {
+ catch (char const *)
+ {
}
}
}
@@ -429,49 +626,50 @@ void MHEngine::RunActions()
void MHEngine::EventTriggered(MHRoot *pSource, enum EventType ev, const MHUnion &evData)
{
MHLOG(MHLogLinks, QString("Event - %1 from %2")
- .arg(MHLink::EventTypeToString(ev)).arg(pSource->m_ObjectReference.Printable()));
-
- switch (ev) {
- case EventFirstItemPresented:
- case EventHeadItems:
- case EventHighlightOff:
- case EventHighlightOn:
- case EventIsAvailable:
- case EventIsDeleted:
- case EventIsDeselected:
- case EventIsRunning:
- case EventIsSelected:
- case EventIsStopped:
- case EventItemDeselected:
- case EventItemSelected:
- case EventLastItemPresented:
- case EventTailItems:
- case EventTestEvent:
- case EventTokenMovedFrom:
- case EventTokenMovedTo:
- // Synchronous events. Fire any links that are waiting.
- // The UK MHEG describes this as the preferred interpretation. We are checking the link
- // at the time we generate the event rather than queuing the synchronous events until
- // this elementary action is complete. That matters if we are processing an elementary action
- // which will activate or deactivate links.
- CheckLinks(pSource->m_ObjectReference, ev, evData);
- break;
- case EventAnchorFired:
- case EventAsyncStopped:
- case EventContentAvailable:
- case EventCounterTrigger:
- case EventCursorEnter:
- case EventCursorLeave:
- case EventEngineEvent:
- case EventEntryFieldFull:
- case EventInteractionCompleted:
- case EventStreamEvent:
- case EventStreamPlaying:
- case EventStreamStopped:
- case EventTimerFired:
- case EventUserInput:
- case EventFocusMoved: // UK MHEG. Generated by HyperText class
- case EventSliderValueChanged: // UK MHEG. Generated by Slider class
+ .arg(MHLink::EventTypeToString(ev)).arg(pSource->m_ObjectReference.Printable()));
+
+ switch (ev)
+ {
+ case EventFirstItemPresented:
+ case EventHeadItems:
+ case EventHighlightOff:
+ case EventHighlightOn:
+ case EventIsAvailable:
+ case EventIsDeleted:
+ case EventIsDeselected:
+ case EventIsRunning:
+ case EventIsSelected:
+ case EventIsStopped:
+ case EventItemDeselected:
+ case EventItemSelected:
+ case EventLastItemPresented:
+ case EventTailItems:
+ case EventTestEvent:
+ case EventTokenMovedFrom:
+ case EventTokenMovedTo:
+ // Synchronous events. Fire any links that are waiting.
+ // The UK MHEG describes this as the preferred interpretation. We are checking the link
+ // at the time we generate the event rather than queuing the synchronous events until
+ // this elementary action is complete. That matters if we are processing an elementary action
+ // which will activate or deactivate links.
+ CheckLinks(pSource->m_ObjectReference, ev, evData);
+ break;
+ case EventAnchorFired:
+ case EventAsyncStopped:
+ case EventContentAvailable:
+ case EventCounterTrigger:
+ case EventCursorEnter:
+ case EventCursorLeave:
+ case EventEngineEvent:
+ case EventEntryFieldFull:
+ case EventInteractionCompleted:
+ case EventStreamEvent:
+ case EventStreamPlaying:
+ case EventStreamStopped:
+ case EventTimerFired:
+ case EventUserInput:
+ case EventFocusMoved: // UK MHEG. Generated by HyperText class
+ case EventSliderValueChanged: // UK MHEG. Generated by Slider class
{
// Asynchronous events. Add to the event queue.
MHAsynchEvent *pEvent = new MHAsynchEvent;
@@ -492,7 +690,9 @@ void MHEngine::EventTriggered(MHRoot *pSource, enum EventType ev, const MHUnion
void MHEngine::CheckLinks(const MHObjectRef &sourceRef, enum EventType ev, const MHUnion &un)
{
for (int i = 0; i < m_LinkTable.size(); i++)
+ {
m_LinkTable.at(i)->MatchEvent(sourceRef, ev, un, this);
+ }
}
// Add and remove links to and from the active link table.
@@ -510,13 +710,20 @@ void MHEngine::RemoveLink(MHLink *pLink)
void MHEngine::AddActions(const MHActionSequence &actions)
{
// Put them on the stack in reverse order so that we will pop the first.
- for (int i = actions.Size(); i > 0; i--) m_ActionStack.push(actions.GetAt(i-1));
+ for (int i = actions.Size(); i > 0; i--)
+ {
+ m_ActionStack.push(actions.GetAt(i - 1));
+ }
}
// Add a visible to the display stack if it isn't already there.
void MHEngine::AddToDisplayStack(MHVisible *pVis)
{
- if (CurrentApp()->FindOnStack(pVis) != -1) return; // Return if it's already there.
+ if (CurrentApp()->FindOnStack(pVis) != -1)
+ {
+ return; // Return if it's already there.
+ }
+
CurrentApp()->m_DisplayStack.Append(pVis);
Redraw(pVis->GetVisibleArea()); // Request a redraw
}
@@ -525,7 +732,12 @@ void MHEngine::AddToDisplayStack(MHVisible *pVis)
void MHEngine::RemoveFromDisplayStack(MHVisible *pVis)
{
int nPos = CurrentApp()->FindOnStack(pVis);
- if (nPos == -1) return;
+
+ if (nPos == -1)
+ {
+ return;
+ }
+
CurrentApp()->m_DisplayStack.RemoveAt(nPos);
Redraw(pVis->GetVisibleArea()); // Request a redraw
}
@@ -534,18 +746,28 @@ void MHEngine::RemoveFromDisplayStack(MHVisible *pVis)
void MHEngine::BringToFront(const MHRoot *p)
{
int nPos = CurrentApp()->FindOnStack(p);
- if (nPos == -1) return; // If it's not there do nothing
- MHVisible *pVis = (MHVisible*)p; // Can now safely cast it.
+
+ if (nPos == -1)
+ {
+ return; // If it's not there do nothing
+ }
+
+ MHVisible *pVis = (MHVisible *)p; // Can now safely cast it.
CurrentApp()->m_DisplayStack.RemoveAt(nPos); // Remove it from its present posn
- CurrentApp()->m_DisplayStack.Append((MHVisible*)pVis); // Push it on the top.
+ CurrentApp()->m_DisplayStack.Append((MHVisible *)pVis); // Push it on the top.
Redraw(pVis->GetVisibleArea()); // Request a redraw
}
void MHEngine::SendToBack(const MHRoot *p)
{
int nPos = CurrentApp()->FindOnStack(p);
- if (nPos == -1) return; // If it's not there do nothing
- MHVisible *pVis = (MHVisible*)p; // Can now safely cast it.
+
+ if (nPos == -1)
+ {
+ return; // If it's not there do nothing
+ }
+
+ MHVisible *pVis = (MHVisible *)p; // Can now safely cast it.
CurrentApp()->m_DisplayStack.RemoveAt(nPos); // Remove it from its present posn
CurrentApp()->m_DisplayStack.InsertAt(pVis, 0); // Put it on the bottom.
Redraw(pVis->GetVisibleArea()); // Request a redraw
@@ -554,13 +776,28 @@ void MHEngine::SendToBack(const MHRoot *p)
void MHEngine::PutBefore(const MHRoot *p, const MHRoot *pRef)
{
int nPos = CurrentApp()->FindOnStack(p);
- if (nPos == -1) return; // If it's not there do nothing
- MHVisible *pVis = (MHVisible*)p; // Can now safely cast it.
+
+ if (nPos == -1)
+ {
+ return; // If it's not there do nothing
+ }
+
+ MHVisible *pVis = (MHVisible *)p; // Can now safely cast it.
int nRef = CurrentApp()->FindOnStack(pRef);
- if (nRef == -1) return; // If the reference visible isn't there do nothing.
+
+ if (nRef == -1)
+ {
+ return; // If the reference visible isn't there do nothing.
+ }
+
CurrentApp()->m_DisplayStack.RemoveAt(nPos);
- if (nRef >= nPos) nRef--; // The position of the reference may have shifted
- CurrentApp()->m_DisplayStack.InsertAt(pVis, nRef+1);
+
+ if (nRef >= nPos)
+ {
+ nRef--; // The position of the reference may have shifted
+ }
+
+ CurrentApp()->m_DisplayStack.InsertAt(pVis, nRef + 1);
// Redraw the area occupied by the moved item. We might be able to reduce
// the area to be redrawn by looking at the way it is affected by other items
// in the stack. We could also see whether it's currently active.
@@ -570,13 +807,28 @@ void MHEngine::PutBefore(const MHRoot *p, const MHRoot *pRef)
void MHEngine::PutBehind(const MHRoot *p, const MHRoot *pRef)
{
int nPos = CurrentApp()->FindOnStack(p);
- if (nPos == -1) return; // If it's not there do nothing
+
+ if (nPos == -1)
+ {
+ return; // If it's not there do nothing
+ }
+
int nRef = CurrentApp()->FindOnStack(pRef);
- if (nRef == -1) return; // If the reference visible isn't there do nothing.
- MHVisible *pVis = (MHVisible*)p; // Can now safely cast it.
+
+ if (nRef == -1)
+ {
+ return; // If the reference visible isn't there do nothing.
+ }
+
+ MHVisible *pVis = (MHVisible *)p; // Can now safely cast it.
CurrentApp()->m_DisplayStack.RemoveAt(nPos);
- if (nRef >= nPos) nRef--; // The position of the reference may have shifted
- CurrentApp()->m_DisplayStack.InsertAt((MHVisible*)pVis, nRef); // Shift the reference and anything above up.
+
+ if (nRef >= nPos)
+ {
+ nRef--; // The position of the reference may have shifted
+ }
+
+ CurrentApp()->m_DisplayStack.InsertAt((MHVisible *)pVis, nRef); // Shift the reference and anything above up.
Redraw(pVis->GetVisibleArea()); // Request a redraw
}
@@ -585,24 +837,32 @@ void MHEngine::PutBehind(const MHRoot *p, const MHRoot *pRef)
// transparency of items since items higher up the stack may be semi-transparent.
void MHEngine::DrawRegion(QRegion toDraw, int nStackPos)
{
- if (toDraw.isEmpty()) return; // Nothing left to draw.
+ if (toDraw.isEmpty())
+ {
+ return; // Nothing left to draw.
+ }
- while (nStackPos >= 0) {
+ while (nStackPos >= 0)
+ {
MHVisible *pItem = CurrentApp()->m_DisplayStack.GetAt(nStackPos);
// Work out how much of the area we want to draw is included in this visible.
// The visible area will be empty if the item is transparent or not active.
QRegion drawArea = pItem->GetVisibleArea() & toDraw;
- if (! drawArea.isEmpty()) { // It contributes something.
+
+ if (! drawArea.isEmpty()) // It contributes something.
+ {
// Remove the opaque area of this item from the region we have left.
// If this item is (semi-)transparent this will not remove anything.
QRegion newDraw = toDraw - pItem->GetOpaqueArea();
- DrawRegion(newDraw, nStackPos-1); // Do the items further down if any.
+ DrawRegion(newDraw, nStackPos - 1); // Do the items further down if any.
// Now we've drawn anything below this we can draw this item on top.
pItem->Display(this);
return;
}
+
nStackPos--;
}
+
// We've drawn all the visibles and there's still some undrawn area.
// Fill it with black.
m_Context->DrawBackground(toDraw);
@@ -611,8 +871,12 @@ void MHEngine::DrawRegion(QRegion toDraw, int nStackPos)
// Redraw an area of the display. This will be called via the context from Redraw.
void MHEngine::DrawDisplay(QRegion toDraw)
{
- if (m_fBooting) return;
- int nTopStack = CurrentApp() == NULL ? -1 : CurrentApp()->m_DisplayStack.Size()-1;
+ if (m_fBooting)
+ {
+ return;
+ }
+
+ int nTopStack = CurrentApp() == NULL ? -1 : CurrentApp()->m_DisplayStack.Size() - 1;
DrawRegion(toDraw, nTopStack);
}
@@ -626,7 +890,10 @@ void MHEngine::Redraw(QRegion region)
// Called to decrement the lock count.
void MHEngine::UnlockScreen()
{
- if (CurrentApp()->m_nLockCount > 0) CurrentApp()->m_nLockCount--;
+ if (CurrentApp()->m_nLockCount > 0)
+ {
+ CurrentApp()->m_nLockCount--;
+ }
}
@@ -634,30 +901,40 @@ void MHEngine::UnlockScreen()
void MHEngine::GenerateUserAction(int nCode)
{
MHScene *pScene = CurrentScene();
- if (! pScene) return;
+
+ if (! pScene)
+ {
+ return;
+ }
+
// Various keys generate engine events as well as user events.
// These are generated before the user events and even if there
// is an interactible.
switch (nCode)
{
- case 104:
- case 105: // Text key
- EventTriggered(pScene, EventEngineEvent, 4);
- break;
- case 16: // Text Exit/Cancel key
- case 100: // Red
- case 101: // Green
- case 102: // Yellow
- case 103: // Blue
- EventTriggered(pScene, EventEngineEvent, nCode);
- break;
+ case 104:
+ case 105: // Text key
+ EventTriggered(pScene, EventEngineEvent, 4);
+ break;
+ case 16: // Text Exit/Cancel key
+ case 100: // Red
+ case 101: // Green
+ case 102: // Yellow
+ case 103: // Blue
+ EventTriggered(pScene, EventEngineEvent, nCode);
+ break;
}
// If we are interacting with an interactible send the key
// there otherwise generate a user event.
if (m_Interacting)
+ {
m_Interacting->KeyEvent(this, nCode);
- else EventTriggered(pScene, EventUserInput, nCode);
+ }
+ else
+ {
+ EventTriggered(pScene, EventUserInput, nCode);
+ }
}
void MHEngine::EngineEvent(int nCode)
@@ -670,10 +947,15 @@ void MHEngine::RequestExternalContent(MHIngredient *pRequester)
{
// It seems that some MHEG applications contain active ingredients with empty contents
// This isn't correct but we simply ignore that.
- if (! pRequester->m_ContentRef.IsSet()) return;
+ if (! pRequester->m_ContentRef.IsSet())
+ {
+ return;
+ }
+
// Remove any existing content requests for this ingredient.
CancelExternalContentRequest(pRequester);
QString csPath = GetPathName(pRequester->m_ContentRef.m_ContentRef);
+
// Is this actually a carousel object? It could be a stream. We should deal
// with that separately.
if (csPath.isEmpty())
@@ -681,12 +963,16 @@ void MHEngine::RequestExternalContent(MHIngredient *pRequester)
MHLOG(MHLogWarning, "RequestExternalContent empty path");
return;
}
+
QByteArray text;
- if (m_Context->CheckCarouselObject(csPath) && m_Context->GetCarouselData(csPath, text)) {
+
+ if (m_Context->CheckCarouselObject(csPath) && m_Context->GetCarouselData(csPath, text))
+ {
// Available now - pass it to the ingredient.
pRequester->ContentArrived((const unsigned char *)text.data(), text.size(), this);
}
- else {
+ else
+ {
// Need to record this and check later.
MHLOG(MHLogLinks, QString("RequestExternalContent %1 pending").arg(csPath));
MHExternContent *pContent = new MHExternContent;
@@ -700,42 +986,52 @@ void MHEngine::RequestExternalContent(MHIngredient *pRequester)
// Remove any pending requests from the queue.
void MHEngine::CancelExternalContentRequest(MHIngredient *pRequester)
{
- QList::iterator it = m_ExternContentTable.begin();
+ QList::iterator it = m_ExternContentTable.begin();
MHExternContent *pContent;
+
while (it != m_ExternContentTable.end())
{
pContent = *it;
- if (pContent->m_pRequester == pRequester) {
+
+ if (pContent->m_pRequester == pRequester)
+ {
delete pContent;
it = m_ExternContentTable.erase(it);
return;
}
else
+ {
++it;
+ }
}
}
// See if we can satisfy any of the outstanding requests.
void MHEngine::CheckContentRequests()
{
- QList::iterator it = m_ExternContentTable.begin();
+ QList::iterator it = m_ExternContentTable.begin();
MHExternContent *pContent;
+
while (it != m_ExternContentTable.end())
{
pContent = *it;
QByteArray text;
+
if (m_Context->CheckCarouselObject(pContent->m_FileName) &&
m_Context->GetCarouselData(pContent->m_FileName, text))
{
// If the content is not recognized catch the exception and continue
- try {
+ try
+ {
MHLOG(MHLogLinks, QString("CheckContentRequests %1 arrived")
- .arg(pContent->m_FileName));
+ .arg(pContent->m_FileName));
pContent->m_pRequester->ContentArrived((const unsigned char *)text.data(),
text.size(), this);
}
- catch (char const *) {
+ catch (char const *)
+ {
}
+
// Remove from the list.
delete pContent;
it = m_ExternContentTable.erase(it);
@@ -743,13 +1039,15 @@ void MHEngine::CheckContentRequests()
else if (pContent->m_time.elapsed() > 60000) // TODO Get this from carousel
{
MHLOG(MHLogWarning, QString("CheckContentRequests %1 timed out")
- .arg(pContent->m_FileName));
+ .arg(pContent->m_FileName));
delete pContent;
it = m_ExternContentTable.erase(it);
EventTriggered(CurrentApp(), EventEngineEvent, 3); // ContentRefError
}
else
+ {
++it;
+ }
}
}
@@ -758,37 +1056,62 @@ bool MHEngine::LoadStorePersistent(bool fIsLoad, const MHOctetString &fileName,
// See if there is an entry there already.
MHPSEntry *pEntry = NULL;
int i;
- for (i = 0; i < m_PersistentStore.Size(); i++) {
+
+ for (i = 0; i < m_PersistentStore.Size(); i++)
+ {
pEntry = m_PersistentStore.GetAt(i);
- if (pEntry->m_FileName.Equal(fileName)) break;
+
+ if (pEntry->m_FileName.Equal(fileName))
+ {
+ break;
+ }
}
- if (i == m_PersistentStore.Size()) { // Not there.
+
+ if (i == m_PersistentStore.Size()) // Not there.
+ {
// If we're loading then we've failed.
- if (fIsLoad) return false;
+ if (fIsLoad)
+ {
+ return false;
+ }
+
// If we're storing we make a new entry.
pEntry = new MHPSEntry;
pEntry->m_FileName.Copy(fileName);
m_PersistentStore.Append(pEntry);
}
- if (fIsLoad) { // Copy the data into the variables.
+
+ if (fIsLoad) // Copy the data into the variables.
+ {
// Check that we have sufficient data before we continue?
- if (pEntry->m_Data.Size() < variables.Size()) return false;
+ if (pEntry->m_Data.Size() < variables.Size())
+ {
+ return false;
+ }
- for (i = 0; i < variables.Size(); i++) {
+ for (i = 0; i < variables.Size(); i++)
+ {
FindObject(*(variables.GetAt(i)))->SetVariableValue(*(pEntry->m_Data.GetAt(i)));
}
}
- else { // Get the data from the variables into the store.
+ else // Get the data from the variables into the store.
+ {
// Remove any existing data.
- while (pEntry->m_Data.Size() != 0) pEntry->m_Data.RemoveAt(0);
+ while (pEntry->m_Data.Size() != 0)
+ {
+ pEntry->m_Data.RemoveAt(0);
+ }
+
// Set the store to the values.
- for (i = 0; i < variables.Size(); i++) {
+ for (i = 0; i < variables.Size(); i++)
+ {
MHUnion *pValue = new MHUnion;
pEntry->m_Data.Append(pValue);
FindObject(*(variables.GetAt(i)))->GetVariableValue(*pValue, this);
}
}
+
return true;
}
@@ -798,74 +1121,168 @@ bool MHEngine::GetEngineSupport(const MHOctetString &feature)
QString csFeat = QString::fromUtf8((const char *)feature.Bytes(), feature.Size());
QStringList strings = csFeat.split(QRegExp("[\\(\\,\\)]"));
- if (strings[0] == "ApplicationStacking" || strings[0] == "ASt") return true;
+ if (strings[0] == "ApplicationStacking" || strings[0] == "ASt")
+ {
+ return true;
+ }
+
// We're required to support cloning for Text, Bitmap and Rectangle.
- if (strings[0] == "Cloning" || strings[0] == "Clo") return true;
- if (strings[0] == "SceneCoordinateSystem" || strings[0] == "SCS") {
+ if (strings[0] == "Cloning" || strings[0] == "Clo")
+ {
+ return true;
+ }
+
+ if (strings[0] == "SceneCoordinateSystem" || strings[0] == "SCS")
+ {
if (strings.count() >= 3 && strings[1] == "720" && strings[2] == "576")
+ {
return true;
- else return false;
- // I've also seen SceneCoordinateSystem(1,1)
+ }
+ else
+ {
+ return false;
+ }
+
+ // I've also seen SceneCoordinateSystem(1,1)
}
- if (strings[0] == "MultipleAudioStreams" || strings[0] == "MAS") {
+
+ if (strings[0] == "MultipleAudioStreams" || strings[0] == "MAS")
+ {
if (strings.count() >= 2 && (strings[1] == "0" || strings[1] == "1"))
+ {
return true;
- else return false;
+ }
+ else
+ {
+ return false;
+ }
}
- if (strings[0] == "MultipleVideoStreams" || strings[0] == "MVS") {
+
+ if (strings[0] == "MultipleVideoStreams" || strings[0] == "MVS")
+ {
if (strings.count() >= 2 && (strings[1] == "0" || strings[1] == "1"))
+ {
return true;
- else return false;
+ }
+ else
+ {
+ return false;
+ }
}
+
// We're supposed to return true for all values of N
- if (strings[0] == "OverlappingVisibles" || strings[0] == "OvV") return true;
+ if (strings[0] == "OverlappingVisibles" || strings[0] == "OvV")
+ {
+ return true;
+ }
- if (strings[0] == "SceneAspectRatio" || strings[0] == "SAR") {
- if (strings.count() < 3) return false;
+ if (strings[0] == "SceneAspectRatio" || strings[0] == "SAR")
+ {
+ if (strings.count() < 3)
+ {
+ return false;
+ }
else if ((strings[1] == "4" && strings[2] == "3") || (strings[1] == "16" && strings[2] == "9"))
+ {
return true;
- else return false;
+ }
+ else
+ {
+ return false;
+ }
}
// We're supposed to support these at least. May also support(10,1440,1152)
- if (strings[0] == "VideoScaling" || strings[0] == "VSc") {
- if (strings.count() < 4 || strings[1] != "10") return false;
+ if (strings[0] == "VideoScaling" || strings[0] == "VSc")
+ {
+ if (strings.count() < 4 || strings[1] != "10")
+ {
+ return false;
+ }
else if ((strings[2] == "720" && strings[3] == "576") || (strings[2] == "360" && strings[3] == "288"))
+ {
return true;
- else return false;
+ }
+ else
+ {
+ return false;
+ }
}
- if (strings[0] == "BitmapScaling" || strings[0] == "BSc") {
- if (strings.count() < 4 || strings[1] != "2") return false;
+
+ if (strings[0] == "BitmapScaling" || strings[0] == "BSc")
+ {
+ if (strings.count() < 4 || strings[1] != "2")
+ {
+ return false;
+ }
else if ((strings[2] == "720" && strings[3] == "576") || (strings[2] == "360" && strings[3] == "288"))
+ {
return true;
- else return false;
+ }
+ else
+ {
+ return false;
+ }
}
// I think we only support the video fully on screen
- if (strings[0] == "VideoDecodeOffset" || strings[0] == "VDO") {
- if (strings.count() >= 3 && strings[1] == "10" && strings[1] == "0") return true;
- else return false;
+ if (strings[0] == "VideoDecodeOffset" || strings[0] == "VDO")
+ {
+ if (strings.count() >= 3 && strings[1] == "10" && strings[1] == "0")
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
+
// We support bitmaps that are partially off screen (don't we?)
- if (strings[0] == "BitmapDecodeOffset" || strings[0] == "BDO") {
+ if (strings[0] == "BitmapDecodeOffset" || strings[0] == "BDO")
+ {
if (strings.count() >= 3 && strings[1] == "10" && (strings[2] == "0" || strings[2] == "1"))
+ {
return true;
- else return false;
+ }
+ else
+ {
+ return false;
+ }
}
- if (strings[0] == "UKEngineProfile" || strings[0] == "UniversalEngineProfile" || strings[0] == "UEP") {
- if (strings.count() < 2) return false;
+ if (strings[0] == "UKEngineProfile" || strings[0] == "UniversalEngineProfile" || strings[0] == "UEP")
+ {
+ if (strings.count() < 2)
+ {
+ return false;
+ }
+
if (strings[1] == MHEGEngineProviderIdString)
+ {
return true;
+ }
+
if (strings[1] == m_Context->GetReceiverId())
+ {
return true;
+ }
+
if (strings[1] == m_Context->GetDSMCCId())
+ {
return true;
+ }
+
// The UK profile 1.06 seems a bit confused on this point. It is not clear whether
// we are supposed to return true for UKEngineProfile(2) or not.
if (strings[1] == "2")
+ {
return true;
- else return false;
+ }
+ else
+ {
+ return false;
+ }
}
// Otherwise return false.
@@ -876,71 +1293,141 @@ bool MHEngine::GetEngineSupport(const MHOctetString &feature)
int MHEngine::GetDefaultCharSet()
{
MHApplication *pApp = CurrentApp();
- if (pApp && pApp->m_nCharSet > 0) return pApp->m_nCharSet;
- else return 10; // UK MHEG default.
+
+ if (pApp && pApp->m_nCharSet > 0)
+ {
+ return pApp->m_nCharSet;
+ }
+ else
+ {
+ return 10; // UK MHEG default.
+ }
}
void MHEngine::GetDefaultBGColour(MHColour &colour)
{
MHApplication *pApp = CurrentApp();
- if (pApp && pApp->m_BGColour.IsSet()) colour.Copy(pApp->m_BGColour);
- else colour.SetFromString("\000\000\000\377", 4); // '=00=00=00=FF' Default - transparent
+
+ if (pApp && pApp->m_BGColour.IsSet())
+ {
+ colour.Copy(pApp->m_BGColour);
+ }
+ else
+ {
+ colour.SetFromString("\000\000\000\377", 4); // '=00=00=00=FF' Default - transparent
+ }
}
void MHEngine::GetDefaultTextColour(MHColour &colour)
{
MHApplication *pApp = CurrentApp();
- if (pApp && pApp->m_TextColour.IsSet()) colour.Copy(pApp->m_TextColour);
- else colour.SetFromString("\377\377\377\000", 4); // '=FF=FF=FF=00' UK MHEG Default - white
+
+ if (pApp && pApp->m_TextColour.IsSet())
+ {
+ colour.Copy(pApp->m_TextColour);
+ }
+ else
+ {
+ colour.SetFromString("\377\377\377\000", 4); // '=FF=FF=FF=00' UK MHEG Default - white
+ }
}
void MHEngine::GetDefaultButtonRefColour(MHColour &colour)
{
MHApplication *pApp = CurrentApp();
- if (pApp && pApp->m_ButtonRefColour.IsSet()) colour.Copy(pApp->m_ButtonRefColour);
- else colour.SetFromString("\377\377\377\000", 4); // '=FF=FF=FF=00' ??? Not specified in UK MHEG
+
+ if (pApp && pApp->m_ButtonRefColour.IsSet())
+ {
+ colour.Copy(pApp->m_ButtonRefColour);
+ }
+ else
+ {
+ colour.SetFromString("\377\377\377\000", 4); // '=FF=FF=FF=00' ??? Not specified in UK MHEG
+ }
}
void MHEngine::GetDefaultHighlightRefColour(MHColour &colour)
{
MHApplication *pApp = CurrentApp();
- if (pApp && pApp->m_HighlightRefColour.IsSet()) colour.Copy(pApp->m_HighlightRefColour);
- else colour.SetFromString("\377\377\377\000", 4); // '=FF=FF=FF=00' UK MHEG Default - white
+
+ if (pApp && pApp->m_HighlightRefColour.IsSet())
+ {
+ colour.Copy(pApp->m_HighlightRefColour);
+ }
+ else
+ {
+ colour.SetFromString("\377\377\377\000", 4); // '=FF=FF=FF=00' UK MHEG Default - white
+ }
}
void MHEngine::GetDefaultSliderRefColour(MHColour &colour)
{
MHApplication *pApp = CurrentApp();
- if (pApp && pApp->m_SliderRefColour.IsSet()) colour.Copy(pApp->m_SliderRefColour);
- else colour.SetFromString("\377\377\377\000", 4); // '=FF=FF=FF=00' UK MHEG Default - white
+
+ if (pApp && pApp->m_SliderRefColour.IsSet())
+ {
+ colour.Copy(pApp->m_SliderRefColour);
+ }
+ else
+ {
+ colour.SetFromString("\377\377\377\000", 4); // '=FF=FF=FF=00' UK MHEG Default - white
+ }
}
int MHEngine::GetDefaultTextCHook()
{
MHApplication *pApp = CurrentApp();
- if (pApp && pApp->m_nTextCHook > 0) return pApp->m_nTextCHook;
- else return 10; // UK MHEG default.
+
+ if (pApp && pApp->m_nTextCHook > 0)
+ {
+ return pApp->m_nTextCHook;
+ }
+ else
+ {
+ return 10; // UK MHEG default.
+ }
}
int MHEngine::GetDefaultStreamCHook()
{
MHApplication *pApp = CurrentApp();
- if (pApp && pApp->m_nStrCHook > 0) return pApp->m_nStrCHook;
- else return 10; // UK MHEG default.
+
+ if (pApp && pApp->m_nStrCHook > 0)
+ {
+ return pApp->m_nStrCHook;
+ }
+ else
+ {
+ return 10; // UK MHEG default.
+ }
}
int MHEngine::GetDefaultBitmapCHook()
{
MHApplication *pApp = CurrentApp();
- if (pApp && pApp->m_nBitmapCHook > 0) return pApp->m_nBitmapCHook;
- else return 4; // UK MHEG default - PNG bitmap
+
+ if (pApp && pApp->m_nBitmapCHook > 0)
+ {
+ return pApp->m_nBitmapCHook;
+ }
+ else
+ {
+ return 4; // UK MHEG default - PNG bitmap
+ }
}
void MHEngine::GetDefaultFontAttrs(MHOctetString &str)
{
MHApplication *pApp = CurrentApp();
- if (pApp && pApp->m_FontAttrs.Size() > 0) str.Copy(pApp->m_FontAttrs);
- else str.Copy("plain.24.24.0"); // TODO: Check this.
+
+ if (pApp && pApp->m_FontAttrs.Size() > 0)
+ {
+ str.Copy(pApp->m_FontAttrs);
+ }
+ else
+ {
+ str.Copy("plain.24.24.0"); // TODO: Check this.
+ }
}
// An identifier string required by the UK profile. The "manufacturer" is GNU.
diff --git a/mythtv/libs/libmythfreemheg/Engine.h b/mythtv/libs/libmythfreemheg/Engine.h
index 34cf4c79790..e392cb1a1c4 100644
--- a/mythtv/libs/libmythfreemheg/Engine.h
+++ b/mythtv/libs/libmythfreemheg/Engine.h
@@ -42,7 +42,7 @@ class MHDLADisplay;
// Asynchronous event data.
class MHAsynchEvent {
-public:
+ public:
MHRoot *pEventSource;
enum EventType eventType;
MHUnion eventData;
@@ -52,7 +52,7 @@ class MHAsynchEvent {
// The UK MHEG profile says we shouldn't store type information. That complicates
// the code so for the moment we do.
class MHPSEntry {
-public:
+ public:
MHPSEntry() {}
MHOctetString m_FileName;
MHOwnPtrSequence m_Data;
@@ -60,7 +60,7 @@ class MHPSEntry {
// Entry in the pending external content list.
class MHExternContent {
-public:
+ public:
QString m_FileName;
MHIngredient *m_pRequester;
QTime m_time;
@@ -69,7 +69,7 @@ class MHExternContent {
class MHInteractible;
class MHEngine: public MHEG {
-public:
+ public:
MHEngine(MHContext *context);
virtual ~MHEngine();
@@ -161,7 +161,7 @@ class MHEngine: public MHEG {
int GetTuneInfo() { return CurrentApp() ? CurrentApp()->m_tuneinfo : 0; }
void SetTuneInfo(int tuneinfo) { if (CurrentApp()) CurrentApp()->m_tuneinfo = tuneinfo; }
-protected:
+ protected:
void CheckLinks(const MHObjectRef &sourceRef, enum EventType ev, const MHUnion &un);
MHGroup *ParseProgram(QByteArray &text);
void DrawRegion(QRegion toDraw, int nStackPos);
diff --git a/mythtv/libs/libmythfreemheg/Groups.cpp b/mythtv/libs/libmythfreemheg/Groups.cpp
index 94d0020a78d..df1fbfb58ab 100644
--- a/mythtv/libs/libmythfreemheg/Groups.cpp
+++ b/mythtv/libs/libmythfreemheg/Groups.cpp
@@ -47,32 +47,53 @@ MHGroup::MHGroup()
MHGroup::~MHGroup()
{
while (!m_Timers.isEmpty())
+ {
delete m_Timers.takeFirst();
+ }
}
void MHGroup::Initialise(MHParseNode *p, MHEngine *engine)
{
engine->GetGroupId().Copy(""); // Set to empty before we start (just in case).
MHRoot::Initialise(p, engine);
+
// Must be an external reference with an object number of zero.
if (m_ObjectReference.m_nObjectNo != 0 || m_ObjectReference.m_GroupId.Size() == 0)
+ {
MHERROR("Object reference for a group object must be zero and external");
+ }
+
// Set the group id for the rest of the group to this.
engine->GetGroupId().Copy(m_ObjectReference.m_GroupId);
// Some of the information is irrelevant.
-// MHParseNode *pStdId = p->GetNamedArg(C_STANDARD_IDENTIFIER);
-// MHParseNode *pStdVersion = p->GetNamedArg(C_STANDARD_VERSION);
-// MHParseNode *pObjectInfo = p->GetNamedArg(C_OBJECT_INFORMATION);
+ // MHParseNode *pStdId = p->GetNamedArg(C_STANDARD_IDENTIFIER);
+ // MHParseNode *pStdVersion = p->GetNamedArg(C_STANDARD_VERSION);
+ // MHParseNode *pObjectInfo = p->GetNamedArg(C_OBJECT_INFORMATION);
MHParseNode *pOnStartUp = p->GetNamedArg(C_ON_START_UP);
- if (pOnStartUp) m_StartUp.Initialise(pOnStartUp, engine);
+
+ if (pOnStartUp)
+ {
+ m_StartUp.Initialise(pOnStartUp, engine);
+ }
+
MHParseNode *pOnCloseDown = p->GetNamedArg(C_ON_CLOSE_DOWN);
- if (pOnCloseDown) m_CloseDown.Initialise(pOnCloseDown, engine);
+
+ if (pOnCloseDown)
+ {
+ m_CloseDown.Initialise(pOnCloseDown, engine);
+ }
+
MHParseNode *pOriginalGCPrio = p->GetNamedArg(C_ORIGINAL_GC_PRIORITY);
- if (pOriginalGCPrio) m_nOrigGCPriority = pOriginalGCPrio->GetArgN(0)->GetIntValue();
+
+ if (pOriginalGCPrio)
+ {
+ m_nOrigGCPriority = pOriginalGCPrio->GetArgN(0)->GetIntValue();
+ }
// Ignore the other stuff at the moment.
MHParseNode *pItems = p->GetNamedArg(C_ITEMS);
+
if (pItems == NULL)
{
p->Failure("Missing :Items block");
@@ -83,51 +104,113 @@ void MHGroup::Initialise(MHParseNode *p, MHEngine *engine)
{
MHParseNode *pItem = pItems->GetArgN(i);
MHIngredient *pIngredient = NULL;
- try {
+
+ try
+ {
// Generate the particular kind of ingredient.
- switch (pItem->GetTagNo()) {
- case C_RESIDENT_PROGRAM: pIngredient = new MHResidentProgram; break;
- case C_REMOTE_PROGRAM: pIngredient = new MHRemoteProgram; break;
- case C_INTERCHANGED_PROGRAM: pIngredient = new MHInterChgProgram; break;
- case C_PALETTE: pIngredient = new MHPalette; break;
- case C_FONT: pIngredient = new MHFont; break;
- case C_CURSOR_SHAPE: pIngredient = new MHCursorShape; break;
- case C_BOOLEAN_VARIABLE: pIngredient = new MHBooleanVar; break;
- case C_INTEGER_VARIABLE: pIngredient = new MHIntegerVar; break;
- case C_OCTET_STRING_VARIABLE: pIngredient = new MHOctetStrVar; break;
- case C_OBJECT_REF_VARIABLE: pIngredient = new MHObjectRefVar; break;
- case C_CONTENT_REF_VARIABLE: pIngredient = new MHContentRefVar; break;
- case C_LINK: pIngredient = new MHLink; break;
- case C_STREAM: pIngredient = new MHStream; break;
- case C_BITMAP: pIngredient = new MHBitmap; break;
- case C_LINE_ART: pIngredient = new MHLineArt; break;
- case C_DYNAMIC_LINE_ART: pIngredient = new MHDynamicLineArt; break;
- case C_RECTANGLE: pIngredient = new MHRectangle; break;
- case C_HOTSPOT: pIngredient = new MHHotSpot; break;
- case C_SWITCH_BUTTON: pIngredient = new MHSwitchButton; break;
- case C_PUSH_BUTTON: pIngredient = new MHPushButton; break;
- case C_TEXT: pIngredient = new MHText; break;
- case C_ENTRY_FIELD: pIngredient = new MHEntryField; break;
- case C_HYPER_TEXT: pIngredient = new MHHyperText; break;
- case C_SLIDER: pIngredient = new MHSlider; break;
- case C_TOKEN_GROUP: pIngredient = new MHTokenGroup; break;
- case C_LIST_GROUP: pIngredient = new MHListGroup; break;
- default:
- MHLOG(MHLogWarning, QString("Unknown ingredient %1").arg(pItem->GetTagNo()));
- // Future proofing: ignore any ingredients that we don't know about.
- // Obviously these can only arise in the binary coding.
+ switch (pItem->GetTagNo())
+ {
+ case C_RESIDENT_PROGRAM:
+ pIngredient = new MHResidentProgram;
+ break;
+ case C_REMOTE_PROGRAM:
+ pIngredient = new MHRemoteProgram;
+ break;
+ case C_INTERCHANGED_PROGRAM:
+ pIngredient = new MHInterChgProgram;
+ break;
+ case C_PALETTE:
+ pIngredient = new MHPalette;
+ break;
+ case C_FONT:
+ pIngredient = new MHFont;
+ break;
+ case C_CURSOR_SHAPE:
+ pIngredient = new MHCursorShape;
+ break;
+ case C_BOOLEAN_VARIABLE:
+ pIngredient = new MHBooleanVar;
+ break;
+ case C_INTEGER_VARIABLE:
+ pIngredient = new MHIntegerVar;
+ break;
+ case C_OCTET_STRING_VARIABLE:
+ pIngredient = new MHOctetStrVar;
+ break;
+ case C_OBJECT_REF_VARIABLE:
+ pIngredient = new MHObjectRefVar;
+ break;
+ case C_CONTENT_REF_VARIABLE:
+ pIngredient = new MHContentRefVar;
+ break;
+ case C_LINK:
+ pIngredient = new MHLink;
+ break;
+ case C_STREAM:
+ pIngredient = new MHStream;
+ break;
+ case C_BITMAP:
+ pIngredient = new MHBitmap;
+ break;
+ case C_LINE_ART:
+ pIngredient = new MHLineArt;
+ break;
+ case C_DYNAMIC_LINE_ART:
+ pIngredient = new MHDynamicLineArt;
+ break;
+ case C_RECTANGLE:
+ pIngredient = new MHRectangle;
+ break;
+ case C_HOTSPOT:
+ pIngredient = new MHHotSpot;
+ break;
+ case C_SWITCH_BUTTON:
+ pIngredient = new MHSwitchButton;
+ break;
+ case C_PUSH_BUTTON:
+ pIngredient = new MHPushButton;
+ break;
+ case C_TEXT:
+ pIngredient = new MHText;
+ break;
+ case C_ENTRY_FIELD:
+ pIngredient = new MHEntryField;
+ break;
+ case C_HYPER_TEXT:
+ pIngredient = new MHHyperText;
+ break;
+ case C_SLIDER:
+ pIngredient = new MHSlider;
+ break;
+ case C_TOKEN_GROUP:
+ pIngredient = new MHTokenGroup;
+ break;
+ case C_LIST_GROUP:
+ pIngredient = new MHListGroup;
+ break;
+ default:
+ MHLOG(MHLogWarning, QString("Unknown ingredient %1").arg(pItem->GetTagNo()));
+ // Future proofing: ignore any ingredients that we don't know about.
+ // Obviously these can only arise in the binary coding.
}
- if (pIngredient) {
+
+ if (pIngredient)
+ {
// Initialise it from its argments.
pIngredient->Initialise(pItem, engine);
+
// Remember the highest numbered ingredient
if (pIngredient->m_ObjectReference.m_nObjectNo > m_nLastId)
+ {
m_nLastId = pIngredient->m_ObjectReference.m_nObjectNo;
+ }
+
// Add it to the ingedients of this group.
m_Items.Append(pIngredient);
}
}
- catch (...) {
+ catch (...)
+ {
delete(pIngredient);
throw;
}
@@ -137,48 +220,84 @@ void MHGroup::Initialise(MHParseNode *p, MHEngine *engine)
void MHGroup::PrintMe(FILE *fd, int nTabs) const
{
MHRoot::PrintMe(fd, nTabs);
- if (m_StartUp.Size() != 0) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":OnStartUp (\n");
- m_StartUp.PrintMe(fd, nTabs+2);
- PrintTabs(fd, nTabs+2); fprintf(fd, ")\n");
+
+ if (m_StartUp.Size() != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OnStartUp (\n");
+ m_StartUp.PrintMe(fd, nTabs + 2);
+ PrintTabs(fd, nTabs + 2);
+ fprintf(fd, ")\n");
}
- if (m_CloseDown.Size() != 0) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":OnCloseDown (\n");
- m_CloseDown.PrintMe(fd, nTabs+2);
- PrintTabs(fd, nTabs+2); fprintf(fd, ")\n");
+
+ if (m_CloseDown.Size() != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OnCloseDown (\n");
+ m_CloseDown.PrintMe(fd, nTabs + 2);
+ PrintTabs(fd, nTabs + 2);
+ fprintf(fd, ")\n");
}
- if (m_nOrigGCPriority != 127) { PrintTabs(fd, nTabs+1); fprintf(fd, ":OrigGCPriority %d\n", m_nOrigGCPriority); }
- PrintTabs(fd, nTabs+1); fprintf(fd, ":Items ( \n");
- for (int i = 0; i < m_Items.Size(); i++) m_Items.GetAt(i)->PrintMe(fd, nTabs+2);
- PrintTabs(fd, nTabs+1); fprintf(fd, ")\n");
+
+ if (m_nOrigGCPriority != 127)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OrigGCPriority %d\n", m_nOrigGCPriority);
+ }
+
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":Items ( \n");
+
+ for (int i = 0; i < m_Items.Size(); i++)
+ {
+ m_Items.GetAt(i)->PrintMe(fd, nTabs + 2);
+ }
+
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ")\n");
}
// Preparation - sets up the run-time representation. Sets m_fAvailable and generates IsAvailable event.
void MHGroup::Preparation(MHEngine *engine)
{
- // Prepare the ingredients first if they are initially active or are initially available programs.
- for (int i = 0; i < m_Items.Size(); i++) {
+ // Prepare the ingredients first if they are initially active or are initially available programs.
+ for (int i = 0; i < m_Items.Size(); i++)
+ {
MHIngredient *pIngredient = m_Items.GetAt(i);
- if (pIngredient->InitiallyActive() || pIngredient->InitiallyAvailable()) {
+
+ if (pIngredient->InitiallyActive() || pIngredient->InitiallyAvailable())
+ {
pIngredient->Preparation(engine);
}
}
+
MHRoot::Preparation(engine); // Prepare the root object and send the IsAvailable event.
}
// Activation - starts running the object. Sets m_fRunning and generates IsRunning event.
void MHGroup::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHRoot::Activation(engine);
// Run any start-up actions.
engine->AddActions(m_StartUp);
engine->RunActions();
+
// Activate the ingredients in order.
- for (int i = 0; i < m_Items.Size(); i++) {
+ for (int i = 0; i < m_Items.Size(); i++)
+ {
MHIngredient *pIngredient = m_Items.GetAt(i);
- if (pIngredient->InitiallyActive()) pIngredient->Activation(engine);
+
+ if (pIngredient->InitiallyActive())
+ {
+ pIngredient->Activation(engine);
+ }
}
+
m_fRunning = true;
// Record the time here. This is the basis for absolute times.
m_StartTime.start();
@@ -188,7 +307,11 @@ void MHGroup::Activation(MHEngine *engine)
// Deactivation - stops running the object. Clears m_fRunning
void MHGroup::Deactivation(MHEngine *engine)
{
- if (! m_fRunning) return;
+ if (! m_fRunning)
+ {
+ return;
+ }
+
// Run any close-down actions.
engine->AddActions(m_CloseDown);
engine->RunActions();
@@ -198,18 +321,32 @@ void MHGroup::Deactivation(MHEngine *engine)
// Destruction - deletes the run-time representation. Clears m_fAvailable.
void MHGroup::Destruction(MHEngine *engine)
{
- for (int i = m_Items.Size(); i > 0; i--) m_Items.GetAt(i-1)->Destruction(engine);
+ for (int i = m_Items.Size(); i > 0; i--)
+ {
+ m_Items.GetAt(i - 1)->Destruction(engine);
+ }
+
MHRoot::Destruction(engine);
}
// Return an object if its object ID matches (or if it's a stream, if it has a matching component).
MHRoot *MHGroup::FindByObjectNo(int n)
{
- if (n == m_ObjectReference.m_nObjectNo) return this;
- for (int i = m_Items.Size(); i > 0; i--) {
- MHRoot *pResult = m_Items.GetAt(i-1)->FindByObjectNo(n);
- if (pResult) return pResult;
+ if (n == m_ObjectReference.m_nObjectNo)
+ {
+ return this;
}
+
+ for (int i = m_Items.Size(); i > 0; i--)
+ {
+ MHRoot *pResult = m_Items.GetAt(i - 1)->FindByObjectNo(n);
+
+ if (pResult)
+ {
+ return pResult;
+ }
+ }
+
return NULL;
}
@@ -217,46 +354,73 @@ MHRoot *MHGroup::FindByObjectNo(int n)
void MHGroup::SetTimer(int nTimerId, bool fAbsolute, int nMilliSecs, MHEngine *)
{
// First remove any existing timer with the same Id.
- for (int i = 0; i < m_Timers.size(); i++) {
+ for (int i = 0; i < m_Timers.size(); i++)
+ {
MHTimer *pTimer = m_Timers.at(i);
- if (pTimer->m_nTimerId == nTimerId) {
+
+ if (pTimer->m_nTimerId == nTimerId)
+ {
delete m_Timers.takeAt(i);
break;
}
}
+
// If the time has passed we don't set up a timer.
QTime currentTime;
currentTime.start(); // Set current time
- if (nMilliSecs < 0 || (fAbsolute && m_StartTime.addMSecs(nMilliSecs) < currentTime)) return;
+
+ if (nMilliSecs < 0 || (fAbsolute && m_StartTime.addMSecs(nMilliSecs) < currentTime))
+ {
+ return;
+ }
+
MHTimer *pTimer = new MHTimer;
m_Timers.append(pTimer);
pTimer->m_nTimerId = nTimerId;
- if (fAbsolute) pTimer->m_Time = m_StartTime.addMSecs(nMilliSecs);
- else pTimer->m_Time = currentTime.addMSecs(nMilliSecs);
+
+ if (fAbsolute)
+ {
+ pTimer->m_Time = m_StartTime.addMSecs(nMilliSecs);
+ }
+ else
+ {
+ pTimer->m_Time = currentTime.addMSecs(nMilliSecs);
+ }
}
// Fire any timers that have passed.
int MHGroup::CheckTimers(MHEngine *engine)
{
QTime currentTime = QTime::currentTime(); // Get current time
- QList::iterator it = m_Timers.begin();
+ QList::iterator it = m_Timers.begin();
MHTimer *pTimer;
int nMSecs = 0;
- while (it != m_Timers.end()) {
+
+ while (it != m_Timers.end())
+ {
pTimer = *it;
- if (pTimer->m_Time <= currentTime) { // Use <= rather than < here so we fire timers with zero time immediately.
+
+ if (pTimer->m_Time <= currentTime) // Use <= rather than < here so we fire timers with zero time immediately.
+ {
// If the time has passed trigger the event and remove the timer from the queue.
engine->EventTriggered(this, EventTimerFired, pTimer->m_nTimerId);
delete pTimer;
it = m_Timers.erase(it);
}
- else {
+ else
+ {
// This has not yet expired. Set "nMSecs" to the earliest time we have.
int nMSecsToGo = currentTime.msecsTo(pTimer->m_Time);
- if (nMSecs == 0 || nMSecsToGo < nMSecs) nMSecs = nMSecsToGo;
+
+ if (nMSecs == 0 || nMSecsToGo < nMSecs)
+ {
+ nMSecs = nMSecsToGo;
+ }
+
++it;
}
}
+
return nMSecs;
}
@@ -279,7 +443,7 @@ MHApplication::MHApplication()
m_nTextCHook = 0;
m_nIPCHook = 0;
m_nStrCHook = 0;
- m_nBitmapCHook = 0;
+ m_nBitmapCHook = 0;
m_nLineArtCHook = 0;
m_tuneinfo = 0;
@@ -290,7 +454,7 @@ MHApplication::MHApplication()
MHApplication::~MHApplication()
{
- delete(m_pCurrentScene);
+ delete(m_pCurrentScene);
}
void MHApplication::Initialise(MHParseNode *p, MHEngine *engine)
@@ -298,47 +462,130 @@ void MHApplication::Initialise(MHParseNode *p, MHEngine *engine)
MHGroup::Initialise(p, engine);
// OnSpawnCloseDown
MHParseNode *pOnSpawn = p->GetNamedArg(C_ON_SPAWN_CLOSE_DOWN);
- if (pOnSpawn) m_OnSpawnCloseDown.Initialise(pOnSpawn, engine);
+
+ if (pOnSpawn)
+ {
+ m_OnSpawnCloseDown.Initialise(pOnSpawn, engine);
+ }
+
// OnRestart
MHParseNode *pOnRestart = p->GetNamedArg(C_ON_RESTART);
- if (pOnRestart) m_OnRestart.Initialise(pOnRestart, engine);
+
+ if (pOnRestart)
+ {
+ m_OnRestart.Initialise(pOnRestart, engine);
+ }
+
// Default attributes. These are encoded in a group in binary.
MHParseNode *pDefattrs = p->GetNamedArg(C_DEFAULT_ATTRIBUTES);
+
// but in the text form they're encoded in the Application block.
- if (pDefattrs == NULL) pDefattrs = p;
+ if (pDefattrs == NULL)
+ {
+ pDefattrs = p;
+ }
+
MHParseNode *pCharSet = pDefattrs->GetNamedArg(C_CHARACTER_SET);
- if (pCharSet) m_nCharSet = pCharSet->GetArgN(0)->GetIntValue();
+
+ if (pCharSet)
+ {
+ m_nCharSet = pCharSet->GetArgN(0)->GetIntValue();
+ }
+
// Colours
MHParseNode *pBGColour = pDefattrs->GetNamedArg(C_BACKGROUND_COLOUR);
- if (pBGColour) m_BGColour.Initialise(pBGColour->GetArgN(0), engine);
+
+ if (pBGColour)
+ {
+ m_BGColour.Initialise(pBGColour->GetArgN(0), engine);
+ }
+
MHParseNode *pTextColour = pDefattrs->GetNamedArg(C_TEXT_COLOUR);
- if (pTextColour) m_TextColour.Initialise(pTextColour->GetArgN(0), engine);
+
+ if (pTextColour)
+ {
+ m_TextColour.Initialise(pTextColour->GetArgN(0), engine);
+ }
+
MHParseNode *pButtonRefColour = pDefattrs->GetNamedArg(C_BUTTON_REF_COLOUR);
- if (pButtonRefColour) m_ButtonRefColour.Initialise(pButtonRefColour->GetArgN(0), engine);
+
+ if (pButtonRefColour)
+ {
+ m_ButtonRefColour.Initialise(pButtonRefColour->GetArgN(0), engine);
+ }
+
MHParseNode *pHighlightRefColour = pDefattrs->GetNamedArg(C_HIGHLIGHT_REF_COLOUR);
- if (pHighlightRefColour) m_HighlightRefColour.Initialise(pHighlightRefColour->GetArgN(0), engine);
+
+ if (pHighlightRefColour)
+ {
+ m_HighlightRefColour.Initialise(pHighlightRefColour->GetArgN(0), engine);
+ }
+
MHParseNode *pSliderRefColour = pDefattrs->GetNamedArg(C_SLIDER_REF_COLOUR);
- if (pSliderRefColour) m_SliderRefColour.Initialise(pSliderRefColour->GetArgN(0), engine);
+
+ if (pSliderRefColour)
+ {
+ m_SliderRefColour.Initialise(pSliderRefColour->GetArgN(0), engine);
+ }
+
// Content hooks
MHParseNode *pTextCHook = pDefattrs->GetNamedArg(C_TEXT_CONTENT_HOOK);
- if (pTextCHook) m_nTextCHook = pTextCHook->GetArgN(0)->GetIntValue();
+
+ if (pTextCHook)
+ {
+ m_nTextCHook = pTextCHook->GetArgN(0)->GetIntValue();
+ }
+
MHParseNode *pIPCHook = pDefattrs->GetNamedArg(C_IP_CONTENT_HOOK);
- if (pIPCHook) m_nIPCHook = pIPCHook->GetArgN(0)->GetIntValue();
+
+ if (pIPCHook)
+ {
+ m_nIPCHook = pIPCHook->GetArgN(0)->GetIntValue();
+ }
+
MHParseNode *pStrCHook = pDefattrs->GetNamedArg(C_STREAM_CONTENT_HOOK);
- if (pStrCHook) m_nStrCHook = pStrCHook->GetArgN(0)->GetIntValue();
+
+ if (pStrCHook)
+ {
+ m_nStrCHook = pStrCHook->GetArgN(0)->GetIntValue();
+ }
+
MHParseNode *pBitmapCHook = pDefattrs->GetNamedArg(C_BITMAP_CONTENT_HOOK);
- if (pBitmapCHook) m_nBitmapCHook = pBitmapCHook->GetArgN(0)->GetIntValue();
+
+ if (pBitmapCHook)
+ {
+ m_nBitmapCHook = pBitmapCHook->GetArgN(0)->GetIntValue();
+ }
+
MHParseNode *pLineArtCHook = pDefattrs->GetNamedArg(C_LINE_ART_CONTENT_HOOK);
- if (pLineArtCHook) m_nLineArtCHook = pLineArtCHook->GetArgN(0)->GetIntValue();
+
+ if (pLineArtCHook)
+ {
+ m_nLineArtCHook = pLineArtCHook->GetArgN(0)->GetIntValue();
+ }
+
// Font. This is a little tricky. There are two attributes both called Font.
// In the binary notation the font here is encoded as 42 whereas the text form
// finds the first occurrence of :Font in the table and returns 13.
MHParseNode *pFont = pDefattrs->GetNamedArg(C_FONT2);
- if (pFont == NULL) pFont = pDefattrs->GetNamedArg(C_FONT);
- if (pFont) m_Font.Initialise(pFont->GetArgN(0), engine);
+
+ if (pFont == NULL)
+ {
+ pFont = pDefattrs->GetNamedArg(C_FONT);
+ }
+
+ if (pFont)
+ {
+ m_Font.Initialise(pFont->GetArgN(0), engine);
+ }
+
// Font attributes.
MHParseNode *pFontAttrs = pDefattrs->GetNamedArg(C_FONT_ATTRIBUTES);
- if (pFontAttrs) pFontAttrs->GetArgN(0)->GetStringValue(m_FontAttrs);
+
+ if (pFontAttrs)
+ {
+ pFontAttrs->GetArgN(0)->GetStringValue(m_FontAttrs);
+ }
}
void MHApplication::PrintMe(FILE *fd, int nTabs) const
@@ -346,27 +593,115 @@ void MHApplication::PrintMe(FILE *fd, int nTabs) const
PrintTabs(fd, nTabs);
fprintf(fd, "{:Application ");
MHGroup::PrintMe(fd, nTabs);
- if (m_OnSpawnCloseDown.Size() != 0) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":OnSpawnCloseDown");
- m_OnSpawnCloseDown.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
- }
- if (m_OnRestart.Size() != 0) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":OnRestart");
- m_OnRestart.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
- }
- if (m_nCharSet > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":CharacterSet %d\n", m_nCharSet); }
- if (m_BGColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":BackgroundColour "); m_BGColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
- if (m_nTextCHook > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":TextCHook %d\n", m_nTextCHook); }
- if (m_TextColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":TextColour"); m_TextColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
- if (m_Font.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":Font "); m_Font.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
- if (m_FontAttrs.Size() > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":FontAttributes "); m_FontAttrs.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
- if (m_nIPCHook > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":InterchgPrgCHook %d\n", m_nIPCHook); }
- if (m_nStrCHook > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":StreamCHook %d\n", m_nStrCHook); }
- if (m_nBitmapCHook > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":BitmapCHook %d\n", m_nBitmapCHook); }
- if (m_nLineArtCHook > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":LineArtCHook %d\n", m_nLineArtCHook); }
- if (m_ButtonRefColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":ButtonRefColour "); m_ButtonRefColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
- if (m_HighlightRefColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":HighlightRefColour "); m_HighlightRefColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
- if (m_SliderRefColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":SliderRefColour "); m_SliderRefColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
+
+ if (m_OnSpawnCloseDown.Size() != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OnSpawnCloseDown");
+ m_OnSpawnCloseDown.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_OnRestart.Size() != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OnRestart");
+ m_OnRestart.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_nCharSet > 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":CharacterSet %d\n", m_nCharSet);
+ }
+
+ if (m_BGColour.IsSet())
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":BackgroundColour ");
+ m_BGColour.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_nTextCHook > 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":TextCHook %d\n", m_nTextCHook);
+ }
+
+ if (m_TextColour.IsSet())
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":TextColour");
+ m_TextColour.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_Font.IsSet())
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":Font ");
+ m_Font.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_FontAttrs.Size() > 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":FontAttributes ");
+ m_FontAttrs.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_nIPCHook > 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":InterchgPrgCHook %d\n", m_nIPCHook);
+ }
+
+ if (m_nStrCHook > 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":StreamCHook %d\n", m_nStrCHook);
+ }
+
+ if (m_nBitmapCHook > 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":BitmapCHook %d\n", m_nBitmapCHook);
+ }
+
+ if (m_nLineArtCHook > 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":LineArtCHook %d\n", m_nLineArtCHook);
+ }
+
+ if (m_ButtonRefColour.IsSet())
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":ButtonRefColour ");
+ m_ButtonRefColour.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_HighlightRefColour.IsSet())
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":HighlightRefColour ");
+ m_HighlightRefColour.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_SliderRefColour.IsSet())
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":SliderRefColour ");
+ m_SliderRefColour.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
fprintf(fd, "}\n");
}
@@ -375,20 +710,32 @@ void MHApplication::PrintMe(FILE *fd, int nTabs) const
// OnRestart but allowed in events triggered by IsRunning.
void MHApplication::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHGroup::Activation(engine);
- if (m_fRestarting) { // Set by Quit
+
+ if (m_fRestarting) // Set by Quit
+ {
engine->AddActions(m_OnRestart);
engine->RunActions();
}
+
engine->EventTriggered(this, EventIsRunning);
}
int MHApplication::FindOnStack(const MHRoot *pVis) // Returns the index on the stack or -1 if it's not there.
{
- for (int i = 0; i < m_DisplayStack.Size(); i++) {
- if (m_DisplayStack.GetAt(i) == pVis) return i;
+ for (int i = 0; i < m_DisplayStack.Size(); i++)
+ {
+ if (m_DisplayStack.GetAt(i) == pVis)
+ {
+ return i;
+ }
}
+
return -1; // Not there
}
@@ -397,7 +744,8 @@ MHScene::MHScene()
m_fIsApp = false;
// TODO: In UK MHEG 1.06 the aspect ratio is optional and if not specified "the
// scene has no aspect ratio".
- m_nAspectRatioW = 4; m_nAspectRatioH = 3;
+ m_nAspectRatioW = 4;
+ m_nAspectRatioH = 3;
m_fMovingCursor = false;
}
@@ -406,23 +754,39 @@ void MHScene::Initialise(MHParseNode *p, MHEngine *engine)
MHGroup::Initialise(p, engine);
// Event register.
MHParseNode *pInputEventReg = p->GetNamedArg(C_INPUT_EVENT_REGISTER);
- if (pInputEventReg) m_nEventReg = pInputEventReg->GetArgN(0)->GetIntValue();
+
+ if (pInputEventReg)
+ {
+ m_nEventReg = pInputEventReg->GetArgN(0)->GetIntValue();
+ }
+
// Co-ordinate system
MHParseNode *pSceneCoords = p->GetNamedArg(C_SCENE_COORDINATE_SYSTEM);
- if (pSceneCoords) {
+
+ if (pSceneCoords)
+ {
m_nSceneCoordX = pSceneCoords->GetArgN(0)->GetIntValue();
m_nSceneCoordY = pSceneCoords->GetArgN(1)->GetIntValue();
}
+
// Aspect ratio
MHParseNode *pAspectRatio = p->GetNamedArg(C_ASPECT_RATIO);
- if (pAspectRatio) {
+
+ if (pAspectRatio)
+ {
// Is the binary encoded as a sequence or a pair of arguments?
m_nAspectRatioW = pAspectRatio->GetArgN(0)->GetIntValue();
m_nAspectRatioH = pAspectRatio->GetArgN(1)->GetIntValue();
}
+
// Moving cursor
MHParseNode *pMovingCursor = p->GetNamedArg(C_MOVING_CURSOR);
- if (pMovingCursor) pMovingCursor->GetArgN(0)->GetBoolValue();
+
+ if (pMovingCursor)
+ {
+ pMovingCursor->GetArgN(0)->GetBoolValue();
+ }
+
// Next scene sequence: this is just a hint and isn't implemented
}
@@ -431,21 +795,38 @@ void MHScene::PrintMe(FILE *fd, int nTabs) const
PrintTabs(fd, nTabs);
fprintf(fd, "{:Scene ");
MHGroup::PrintMe(fd, nTabs);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":InputEventReg %d\n", m_nEventReg);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":SceneCS %d %d\n", m_nSceneCoordX, m_nSceneCoordY);
- if (m_nAspectRatioW != 4 || m_nAspectRatioH != 3) { PrintTabs(fd, nTabs+1); fprintf(fd, ":AspectRatio %d %d\n", m_nAspectRatioW, m_nAspectRatioH); }
- if (m_fMovingCursor) { PrintTabs(fd, nTabs+1); fprintf(fd, ":MovingCursor true\n"); }
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":InputEventReg %d\n", m_nEventReg);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":SceneCS %d %d\n", m_nSceneCoordX, m_nSceneCoordY);
+
+ if (m_nAspectRatioW != 4 || m_nAspectRatioH != 3)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":AspectRatio %d %d\n", m_nAspectRatioW, m_nAspectRatioH);
+ }
+
+ if (m_fMovingCursor)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":MovingCursor true\n");
+ }
+
fprintf(fd, "}\n");
}
void MHScene::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHGroup::Activation(engine);
engine->EventTriggered(this, EventIsRunning);
}
-// Action added in UK MHEG profile. It doesn't define a new internal attribute for this.
+// Action added in UK MHEG profile. It doesn't define a new internal attribute for this.
void MHScene::SetInputRegister(int nReg, MHEngine *engine)
{
m_nEventReg = nReg;
@@ -458,7 +839,9 @@ void MHSendEvent::Initialise(MHParseNode *p, MHEngine *engine)
MHElemAction::Initialise(p, engine); // Target
m_EventSource.Initialise(p->GetArgN(1), engine);
m_EventType = (enum EventType)p->GetArgN(2)->GetEnumValue();
- if (p->GetArgCount() >= 4) {
+
+ if (p->GetArgCount() >= 4)
+ {
// TODO: We could check here that we only have bool, int or string and not object ref or content ref.
m_EventData.Initialise(p->GetArgN(3), engine);
}
@@ -470,7 +853,11 @@ void MHSendEvent::PrintArgs(FILE *fd, int) const
QByteArray tmp = MHLink::EventTypeToString(m_EventType).toAscii();
fprintf(fd, "%s", tmp.constData());
fprintf(fd, " ");
- if (m_EventData.m_Type != MHParameter::P_Null) m_EventData.PrintMe(fd, 0);
+
+ if (m_EventData.m_Type != MHParameter::P_Null)
+ {
+ m_EventData.PrintMe(fd, 0);
+ }
}
void MHSendEvent::Perform(MHEngine *engine)
@@ -479,10 +866,14 @@ void MHSendEvent::Perform(MHEngine *engine)
MHObjectRef target, source;
m_Target.GetValue(target, engine); // TODO: Check this is the scene?
m_EventSource.GetValue(source, engine);
+
// Generate the event.
if (m_EventData.m_Type == MHParameter::P_Null)
+ {
engine->EventTriggered(engine->FindObject(source), m_EventType);
- else {
+ }
+ else
+ {
MHUnion data;
data.GetValueFrom(m_EventData, engine);
engine->EventTriggered(engine->FindObject(source), m_EventType, data);
@@ -493,24 +884,38 @@ void MHSetTimer::Initialise(MHParseNode *p, MHEngine *engine)
{
MHElemAction::Initialise(p, engine);
m_TimerId.Initialise(p->GetArgN(1), engine); // The timer id
- if (p->GetArgCount() > 2) {
+
+ if (p->GetArgCount() > 2)
+ {
MHParseNode *pNewTimer = p->GetArgN(2);
m_TimerValue.Initialise(pNewTimer->GetSeqN(0), engine);
- if (pNewTimer->GetSeqCount() > 1) {
+
+ if (pNewTimer->GetSeqCount() > 1)
+ {
m_TimerType = ST_TimerAbsolute; // May be absolute - depends on the value.
m_AbsFlag.Initialise(pNewTimer->GetSeqN(1), engine);
}
- else m_TimerType = ST_TimerRelative;
+ else
+ {
+ m_TimerType = ST_TimerRelative;
+ }
}
}
void MHSetTimer::PrintArgs(FILE *fd, int /*nTabs*/) const
{
m_TimerId.PrintMe(fd, 0);
- if (m_TimerType != ST_NoNewTimer) {
+
+ if (m_TimerType != ST_NoNewTimer)
+ {
fprintf(fd, "( ");
m_TimerValue.PrintMe(fd, 0);
- if (m_TimerType == ST_TimerAbsolute) m_AbsFlag.PrintMe(fd, 0);
+
+ if (m_TimerType == ST_TimerAbsolute)
+ {
+ m_AbsFlag.PrintMe(fd, 0);
+ }
+
fprintf(fd, ") ");
}
}
@@ -520,11 +925,19 @@ void MHSetTimer::Perform(MHEngine *engine)
int nTimerId = m_TimerId.GetValue(engine);
bool fAbsolute = false; // Defaults to relative time.
int newTime = -1;
- switch (m_TimerType) {
- case ST_NoNewTimer: fAbsolute = true; newTime = -1; break; // We treat an absolute time of -1 as "cancel"
- case ST_TimerAbsolute: fAbsolute = m_AbsFlag.GetValue(engine); // And drop to the next
- case ST_TimerRelative: newTime = m_TimerValue.GetValue(engine);
+
+ switch (m_TimerType)
+ {
+ case ST_NoNewTimer:
+ fAbsolute = true;
+ newTime = -1;
+ break; // We treat an absolute time of -1 as "cancel"
+ case ST_TimerAbsolute:
+ fAbsolute = m_AbsFlag.GetValue(engine); // And drop to the next
+ case ST_TimerRelative:
+ newTime = m_TimerValue.GetValue(engine);
}
+
Target(engine)->SetTimer(nTimerId, fAbsolute, newTime, engine);
}
@@ -533,11 +946,14 @@ void MHPersistent::Initialise(MHParseNode *p, MHEngine *engine)
MHElemAction::Initialise(p, engine); // Target
m_Succeeded.Initialise(p->GetArgN(1), engine);
MHParseNode *pVarSeq = p->GetArgN(2);
- for (int i = 0; i < pVarSeq->GetSeqCount(); i++) {
+
+ for (int i = 0; i < pVarSeq->GetSeqCount(); i++)
+ {
MHObjectRef *pVar = new MHObjectRef;
m_Variables.Append(pVar);
pVar->Initialise(pVarSeq->GetSeqN(i), engine);
}
+
m_FileName.Initialise(p->GetArgN(3), engine);
}
@@ -545,7 +961,12 @@ void MHPersistent::PrintArgs(FILE *fd, int nTabs) const
{
m_Succeeded.PrintMe(fd, nTabs);
fprintf(fd, " ( ");
- for (int i = 0; i < m_Variables.Size(); i++) m_Variables.GetAt(i)->PrintMe(fd, 0);
+
+ for (int i = 0; i < m_Variables.Size(); i++)
+ {
+ m_Variables.GetAt(i)->PrintMe(fd, 0);
+ }
+
fprintf(fd, " ) ");
m_FileName.PrintMe(fd, nTabs);
}
@@ -571,14 +992,19 @@ void MHTransitionTo::Initialise(MHParseNode *p, MHEngine *engine)
{
MHElemAction::Initialise(p, engine); // Target
// The next one may be present but NULL in binary.
- if (p->GetArgCount() > 1) {
+ if (p->GetArgCount() > 1)
+ {
MHParseNode *pCtag = p->GetArgN(1);
- if (pCtag->m_nNodeType == MHParseNode::PNInt) {
+
+ if (pCtag->m_nNodeType == MHParseNode::PNInt)
+ {
m_fIsTagged = true;
m_nConnectionTag = pCtag->GetIntValue();
}
}
- if (p->GetArgCount() > 2) {
+
+ if (p->GetArgCount() > 2)
+ {
MHParseNode *pTrEff = p->GetArgN(2);
m_nTransitionEffect = pTrEff->GetIntValue();
}
@@ -586,9 +1012,19 @@ void MHTransitionTo::Initialise(MHParseNode *p, MHEngine *engine)
void MHTransitionTo::PrintArgs(FILE *fd, int /*nTabs*/) const
{
- if (m_fIsTagged) fprintf(fd, " %d ", m_nConnectionTag);
- else if (m_nTransitionEffect >= 0) fprintf(fd, " NULL ");
- if (m_nTransitionEffect >= 0) fprintf(fd, " %d", m_nTransitionEffect);
+ if (m_fIsTagged)
+ {
+ fprintf(fd, " %d ", m_nConnectionTag);
+ }
+ else if (m_nTransitionEffect >= 0)
+ {
+ fprintf(fd, " NULL ");
+ }
+
+ if (m_nTransitionEffect >= 0)
+ {
+ fprintf(fd, " %d", m_nTransitionEffect);
+ }
}
// Do the action - Transition to a new scene.
@@ -599,11 +1035,30 @@ void MHTransitionTo::Perform(MHEngine *engine)
engine->TransitionToScene(target);
}
-void MHLaunch::Perform(MHEngine *engine) { MHObjectRef target; m_Target.GetValue(target, engine); engine->Launch(target); }
-void MHQuit::Perform(MHEngine *engine) { engine->Quit(); }
-void MHSpawn::Perform(MHEngine *engine) { MHObjectRef target; m_Target.GetValue(target, engine); engine->Spawn(target); }
-void MHLockScreen::Perform(MHEngine *engine) { engine->LockScreen(); }
-void MHUnlockScreen::Perform(MHEngine *engine) { engine->UnlockScreen(); }
+void MHLaunch::Perform(MHEngine *engine)
+{
+ MHObjectRef target;
+ m_Target.GetValue(target, engine);
+ engine->Launch(target);
+}
+void MHQuit::Perform(MHEngine *engine)
+{
+ engine->Quit();
+}
+void MHSpawn::Perform(MHEngine *engine)
+{
+ MHObjectRef target;
+ m_Target.GetValue(target, engine);
+ engine->Spawn(target);
+}
+void MHLockScreen::Perform(MHEngine *engine)
+{
+ engine->LockScreen();
+}
+void MHUnlockScreen::Perform(MHEngine *engine)
+{
+ engine->UnlockScreen();
+}
void MHGetEngineSupport::Initialise(MHParseNode *p, MHEngine *engine)
{
diff --git a/mythtv/libs/libmythfreemheg/Groups.h b/mythtv/libs/libmythfreemheg/Groups.h
index d767f4b509d..62991ded34d 100644
--- a/mythtv/libs/libmythfreemheg/Groups.h
+++ b/mythtv/libs/libmythfreemheg/Groups.h
@@ -37,14 +37,14 @@ class MHVisible;
//
class MHTimer {
-public:
+ public:
int m_nTimerId;
QTime m_Time;
};
class MHGroup : public MHRoot
{
-public:
+ public:
MHGroup();
virtual ~MHGroup();
virtual void PrintMe(FILE *fd, int nTabs) const;
@@ -61,7 +61,7 @@ class MHGroup : public MHRoot
// This isn't an MHEG action as such but is used as part of the implementation of "Clone"
virtual void MakeClone(MHRoot *pTarget, MHRoot *pRef, MHEngine *engine);
-protected:
+ protected:
void Initialise(MHParseNode *p, MHEngine *engine); // Set this up from the parse tree.
// Standard ID, Standard version, Object information aren't recorded.
int m_nOrigGCPriority;
@@ -84,7 +84,7 @@ class MHGroup : public MHRoot
class MHScene : public MHGroup
{
-public:
+ public:
MHScene();
void Initialise(MHParseNode *p, MHEngine *engine); // Set this up from the parse tree.
virtual const char *ClassName() { return "Scene"; }
@@ -93,7 +93,7 @@ class MHScene : public MHGroup
// Actions.
virtual void SetInputRegister(int nReg, MHEngine *engine);
-protected:
+ protected:
int m_nEventReg;
int m_nSceneCoordX, m_nSceneCoordY;
int m_nAspectRatioW, m_nAspectRatioH;
@@ -106,7 +106,7 @@ class MHScene : public MHGroup
class MHApplication : public MHGroup
{
-public:
+ public:
MHApplication();
virtual ~MHApplication();
virtual const char *ClassName() { return "Application"; }
@@ -114,7 +114,7 @@ class MHApplication : public MHGroup
virtual void PrintMe(FILE *fd, int nTabs) const;
virtual bool IsShared() { return true; } // The application is "shared".
virtual void Activation(MHEngine *engine);
-protected:
+ protected:
MHActionSequence m_OnSpawnCloseDown, m_OnRestart;
// Default attributes.
int m_nCharSet;
@@ -141,7 +141,7 @@ class MHApplication : public MHGroup
class MHLaunch: public MHElemAction
{
-public:
+ public:
MHLaunch(): MHElemAction(":Launch") {}
virtual void Perform(MHEngine *engine);
};
@@ -149,7 +149,7 @@ class MHLaunch: public MHElemAction
// Quit the application.
class MHQuit: public MHElemAction
{
-public:
+ public:
MHQuit(): MHElemAction(":Quit") {}
virtual void Perform(MHEngine *engine);
};
@@ -157,12 +157,12 @@ class MHQuit: public MHElemAction
// SendEvent - generate an event
class MHSendEvent: public MHElemAction
{
-public:
+ public:
MHSendEvent(): MHElemAction(":SendEvent"), m_EventType(EventIsAvailable) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
virtual void PrintArgs(FILE *fd, int nTabs) const;
-protected:
+ protected:
MHGenericObjectRef m_EventSource; // Event source
enum EventType m_EventType; // Event type
MHParameter m_EventData; // Optional - Null means not specified. Can only be bool, int or string.
@@ -170,11 +170,11 @@ class MHSendEvent: public MHElemAction
class MHSetTimer: public MHElemAction
{
-public:
+ public:
MHSetTimer(): MHElemAction(":SetTimer"), m_TimerType(ST_NoNewTimer) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int nTabs) const;
MHGenericInteger m_TimerId;
// A new timer may not be specified in which case this cancels the timer.
@@ -186,7 +186,7 @@ class MHSetTimer: public MHElemAction
class MHSpawn: public MHElemAction
{
-public:
+ public:
MHSpawn(): MHElemAction(":Spawn") {}
virtual void Perform(MHEngine *engine);
};
@@ -194,11 +194,11 @@ class MHSpawn: public MHElemAction
// Read and Store persistent - read and save data to persistent store.
class MHPersistent: public MHElemAction
{
-public:
+ public:
MHPersistent(const char *name, bool fIsLoad): MHElemAction(name), m_fIsLoad(fIsLoad) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int nTabs) const;
bool m_fIsLoad;
MHObjectRef m_Succeeded;
@@ -210,11 +210,11 @@ class MHPersistent: public MHElemAction
// TransitionTo - move to a new scene.
class MHTransitionTo: public MHElemAction
{
-public:
+ public:
MHTransitionTo();
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int nTabs) const;
bool m_fIsTagged;
int m_nConnectionTag;
@@ -224,25 +224,25 @@ class MHTransitionTo: public MHElemAction
// Lock and unlock functions.
class MHLockScreen: public MHElemAction
{
-public:
+ public:
MHLockScreen(): MHElemAction(":LockScreen") {}
virtual void Perform(MHEngine *engine);
};
class MHUnlockScreen: public MHElemAction
{
-public:
+ public:
MHUnlockScreen(): MHElemAction(":UnlockScreen") {}
virtual void Perform(MHEngine *engine);
};
class MHGetEngineSupport: public MHElemAction
{
-public:
+ public:
MHGetEngineSupport(): MHElemAction(":GetEngineSupport") {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int /*nTabs*/) const { m_Feature.PrintMe(fd, 0); m_Answer.PrintMe(fd, 0); }
MHGenericOctetString m_Feature;
MHObjectRef m_Answer;
@@ -251,7 +251,7 @@ class MHGetEngineSupport: public MHElemAction
// Actions added in UK MHEG profile.
class MHSetInputRegister: public MHActionInt
{
-public:
+ public:
MHSetInputRegister(): MHActionInt(":SetInputRegister") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) { pTarget->SetInputRegister(nArg, engine); };
};
diff --git a/mythtv/libs/libmythfreemheg/Ingredients.cpp b/mythtv/libs/libmythfreemheg/Ingredients.cpp
index 87981632aba..dba627efb3c 100644
--- a/mythtv/libs/libmythfreemheg/Ingredients.cpp
+++ b/mythtv/libs/libmythfreemheg/Ingredients.cpp
@@ -62,62 +62,119 @@ void MHIngredient::Initialise(MHParseNode *p, MHEngine *engine)
{
MHRoot::Initialise(p, engine);
MHParseNode *pIA = p->GetNamedArg(C_INITIALLY_ACTIVE);
- if (pIA) m_fInitiallyActive = pIA->GetArgN(0)->GetBoolValue();
+
+ if (pIA)
+ {
+ m_fInitiallyActive = pIA->GetArgN(0)->GetBoolValue();
+ }
MHParseNode *pCHook = p->GetNamedArg(C_CONTENT_HOOK);
- if (pCHook) m_nContentHook = pCHook->GetArgN(0)->GetIntValue();
+
+ if (pCHook)
+ {
+ m_nContentHook = pCHook->GetArgN(0)->GetIntValue();
+ }
MHParseNode *pOrigContent = p->GetNamedArg(C_ORIGINAL_CONTENT);
- if (pOrigContent) {
+
+ if (pOrigContent)
+ {
MHParseNode *pArg = pOrigContent->GetArgN(0);
+
// Either a string - included content.
- if (pArg->m_nNodeType == MHParseNode::PNString) {
+ if (pArg->m_nNodeType == MHParseNode::PNString)
+ {
m_ContentType = IN_IncludedContent;
pArg->GetStringValue(m_OrigIncludedContent);
}
- else { // or a sequence - referenced content.
+ else // or a sequence - referenced content.
+ {
// In the text version this is tagged with :ContentRef
m_ContentType = IN_ReferencedContent;
- m_OrigContentRef.Initialise(pArg->GetArgN(0), engine);
+ m_OrigContentRef.Initialise(pArg->GetArgN(0), engine);
MHParseNode *pContentSize = pArg->GetNamedArg(C_CONTENT_SIZE);
- if (pContentSize) m_nOrigContentSize = pContentSize->GetArgN(0)->GetIntValue();
+
+ if (pContentSize)
+ {
+ m_nOrigContentSize = pContentSize->GetArgN(0)->GetIntValue();
+ }
+
MHParseNode *pCCPrio = pArg->GetNamedArg(C_CONTENT_CACHE_PRIORITY);
- if (pCCPrio) m_nOrigCCPrio = pCCPrio->GetArgN(0)->GetIntValue();
+
+ if (pCCPrio)
+ {
+ m_nOrigCCPrio = pCCPrio->GetArgN(0)->GetIntValue();
+ }
}
}
MHParseNode *pShared = p->GetNamedArg(C_SHARED);
- if (pShared) m_fShared = pShared->GetArgN(0)->GetBoolValue();
+
+ if (pShared)
+ {
+ m_fShared = pShared->GetArgN(0)->GetBoolValue();
+ }
}
void MHIngredient::PrintMe(FILE *fd, int nTabs) const
{
MHRoot::PrintMe(fd, nTabs);
- if (! m_fInitiallyActive) { PrintTabs(fd, nTabs); fprintf(fd, ":InitiallyActive false\n"); }
- if (m_nContentHook != 0) { PrintTabs(fd, nTabs); fprintf(fd, ":CHook %d\n", m_nContentHook); }
+
+ if (! m_fInitiallyActive)
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":InitiallyActive false\n");
+ }
+
+ if (m_nContentHook != 0)
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":CHook %d\n", m_nContentHook);
+ }
+
// Original content
- if (m_ContentType == IN_IncludedContent) {
+ if (m_ContentType == IN_IncludedContent)
+ {
PrintTabs(fd, nTabs);
fprintf(fd, ":OrigContent ");
- m_OrigIncludedContent.PrintMe(fd, nTabs+1);
+ m_OrigIncludedContent.PrintMe(fd, nTabs + 1);
fprintf(fd, "\n");
}
- else if (m_ContentType == IN_ReferencedContent) {
+ else if (m_ContentType == IN_ReferencedContent)
+ {
PrintTabs(fd, nTabs);
fprintf(fd, ":OrigContent (");
- m_OrigContentRef.PrintMe(fd, nTabs+1);
- if (m_nOrigContentSize) fprintf(fd, " :ContentSize %d", m_nOrigContentSize);
- if (m_nOrigCCPrio != 127) fprintf(fd, " :CCPriority %d", m_nOrigCCPrio);
+ m_OrigContentRef.PrintMe(fd, nTabs + 1);
+
+ if (m_nOrigContentSize)
+ {
+ fprintf(fd, " :ContentSize %d", m_nOrigContentSize);
+ }
+
+ if (m_nOrigCCPrio != 127)
+ {
+ fprintf(fd, " :CCPriority %d", m_nOrigCCPrio);
+ }
+
fprintf(fd, " )\n");
}
- if (m_fShared) { PrintTabs(fd, nTabs); fprintf(fd, ":Shared true\n"); }
+
+ if (m_fShared)
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":Shared true\n");
+ }
}
// Prepare the object as for the parent.
void MHIngredient::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return;
+ if (m_fAvailable)
+ {
+ return;
+ }
+
// Initialise the content information if any.
m_IncludedContent.Copy(m_OrigIncludedContent);
m_ContentRef.Copy(m_OrigContentRef);
@@ -135,11 +192,13 @@ void MHIngredient::Destruction(MHEngine *engine)
void MHIngredient::ContentPreparation(MHEngine *engine)
{
- if (m_ContentType == IN_IncludedContent) {
+ if (m_ContentType == IN_IncludedContent)
+ {
// Included content is there - generate ContentAvailable.
engine->EventTriggered(this, EventContentAvailable);
}
- else if (m_ContentType == IN_ReferencedContent) {
+ else if (m_ContentType == IN_ReferencedContent)
+ {
// We are requesting external content
engine->CancelExternalContentRequest(this);
engine->RequestExternalContent(this);
@@ -153,28 +212,42 @@ void MHIngredient::SetData(const MHOctetString &included, MHEngine *engine)
// and similarly for Referenced content. I've seen cases where SetData
// with included content has been used erroneously with the intention that
// this should be the file name for referenced content.
- if (m_ContentType == IN_ReferencedContent) {
+ if (m_ContentType == IN_ReferencedContent)
+ {
m_ContentRef.m_ContentRef.Copy(included);
}
- else if (m_ContentType == IN_IncludedContent) {
+ else if (m_ContentType == IN_IncludedContent)
+ {
m_IncludedContent.Copy(included);
-
+
}
- else MHLOG(MHLogWarning, "SetData with no content"); // MHEG Error
+ else
+ {
+ MHLOG(MHLogWarning, "SetData with no content"); // MHEG Error
+ }
+
ContentPreparation(engine);
}
void MHIngredient::SetData(const MHContentRef &referenced, bool /*fSizeGiven*/, int size, bool fCCGiven, int /*cc*/, MHEngine *engine)
{
if (m_ContentType != IN_ReferencedContent)
+ {
MHERROR("SetData with referenced content applied to an ingredient without referenced content");
+ }
+
m_ContentRef.Copy(referenced);
m_nContentSize = size;
- if (fCCGiven) m_nCCPrio = m_nOrigCCPrio;
+
+ if (fCCGiven)
+ {
+ m_nCCPrio = m_nOrigCCPrio;
+ }
+
ContentPreparation(engine);
}
-// Font
+// Font
MHFont::MHFont()
{
@@ -193,14 +266,16 @@ void MHFont::Initialise(MHParseNode *p, MHEngine *engine)
void MHFont::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:Font");
- MHIngredient::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:Font");
+ MHIngredient::PrintMe(fd, nTabs + 1);
fprintf(fd, "****TODO\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
-// CursorShape
+// CursorShape
MHCursorShape::MHCursorShape()
{
@@ -220,13 +295,15 @@ void MHCursorShape::Initialise(MHParseNode *p, MHEngine *engine)
void MHCursorShape::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:CursorShape");
- MHIngredient::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:CursorShape");
+ MHIngredient::PrintMe(fd, nTabs + 1);
fprintf(fd, "****TODO\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
-// Palette
+// Palette
MHPalette::MHPalette()
{
@@ -246,46 +323,61 @@ void MHPalette::Initialise(MHParseNode *p, MHEngine *engine)
void MHPalette::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:Palette");
- MHIngredient::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:Palette");
+ MHIngredient::PrintMe(fd, nTabs + 1);
fprintf(fd, "****TODO\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHSetData::Initialise(MHParseNode *p, MHEngine *engine)
{
MHElemAction::Initialise(p, engine); // Target
MHParseNode *pContent = p->GetArgN(1);
- if (pContent->m_nNodeType == MHParseNode::PNSeq) {
+
+ if (pContent->m_nNodeType == MHParseNode::PNSeq)
+ {
// Referenced content.
m_fIsIncluded = false;
m_fSizePresent = m_fCCPriorityPresent = false;
m_Referenced.Initialise(pContent->GetSeqN(0), engine);
- if (pContent->GetSeqCount() > 1) {
+ if (pContent->GetSeqCount() > 1)
+ {
MHParseNode *pArg = pContent->GetSeqN(1);
- if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_NEW_CONTENT_SIZE) {
+
+ if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_NEW_CONTENT_SIZE)
+ {
MHParseNode *pVal = pArg->GetArgN(0);
+
// It may be NULL as a place-holder
- if (pVal->m_nNodeType == MHParseNode::PNInt) {
+ if (pVal->m_nNodeType == MHParseNode::PNInt)
+ {
m_fSizePresent = true;
m_ContentSize.Initialise(pVal, engine);
}
}
}
- if (pContent->GetSeqCount() > 2) {
+ if (pContent->GetSeqCount() > 2)
+ {
MHParseNode *pArg = pContent->GetSeqN(2);
- if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_NEW_CONTENT_CACHE_PRIO) {
+
+ if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_NEW_CONTENT_CACHE_PRIO)
+ {
MHParseNode *pVal = pArg->GetArgN(0);
- if (pVal->m_nNodeType == MHParseNode::PNInt) {
+
+ if (pVal->m_nNodeType == MHParseNode::PNInt)
+ {
m_fCCPriorityPresent = true;
m_CCPriority.Initialise(pVal, engine);
}
}
}
}
- else {
+ else
+ {
m_Included.Initialise(pContent, engine);
m_fIsIncluded = true;
}
@@ -293,14 +385,22 @@ void MHSetData::Initialise(MHParseNode *p, MHEngine *engine)
void MHSetData::PrintArgs(FILE *fd, int) const
{
- if (m_fIsIncluded) m_Included.PrintMe(fd, 0);
- else {
+ if (m_fIsIncluded)
+ {
+ m_Included.PrintMe(fd, 0);
+ }
+ else
+ {
m_Referenced.PrintMe(fd, 0);
- if (m_fSizePresent){
+
+ if (m_fSizePresent)
+ {
fprintf(fd, " :NewContentSize ");
m_ContentSize.PrintMe(fd, 0);
}
- if (m_fCCPriorityPresent) {
+
+ if (m_fCCPriorityPresent)
+ {
fprintf(fd, " :NewCCPriority ");
m_CCPriority.PrintMe(fd, 0);
}
@@ -311,17 +411,37 @@ void MHSetData::Perform(MHEngine *engine)
{
MHObjectRef target;
m_Target.GetValue(target, engine); // Get the target
- if (m_fIsIncluded) { // Included content
+
+ if (m_fIsIncluded) // Included content
+ {
MHOctetString included;
m_Included.GetValue(included, engine);
engine->FindObject(target)->SetData(included, engine);
}
- else {
+ else
+ {
MHContentRef referenced;
int size, cc;
m_Referenced.GetValue(referenced, engine);
- if (m_fSizePresent) size = m_ContentSize.GetValue(engine); else size = 0;
- if (m_fCCPriorityPresent) cc = m_CCPriority.GetValue(engine); else cc = 0;
+
+ if (m_fSizePresent)
+ {
+ size = m_ContentSize.GetValue(engine);
+ }
+ else
+ {
+ size = 0;
+ }
+
+ if (m_fCCPriorityPresent)
+ {
+ cc = m_CCPriority.GetValue(engine);
+ }
+ else
+ {
+ cc = 0;
+ }
+
engine->FindObject(target)->SetData(referenced, m_fSizePresent, size, m_fCCPriorityPresent, cc, engine);
}
}
diff --git a/mythtv/libs/libmythfreemheg/Ingredients.h b/mythtv/libs/libmythfreemheg/Ingredients.h
index 04d87604659..9051864de2f 100644
--- a/mythtv/libs/libmythfreemheg/Ingredients.h
+++ b/mythtv/libs/libmythfreemheg/Ingredients.h
@@ -32,7 +32,7 @@ class MHParseNode;
// Abstract class for ingredients of a scene or application.
class MHIngredient : public MHRoot
{
-public:
+ public:
MHIngredient();
MHIngredient(const MHIngredient &ref);
virtual ~MHIngredient() {}
@@ -56,7 +56,7 @@ class MHIngredient : public MHRoot
// Called by the engine to deliver external content.
virtual void ContentArrived(const unsigned char *, int, MHEngine *) { }
-protected:
+ protected:
bool m_fInitiallyActive;
int m_nContentHook;
bool m_fShared;
@@ -78,53 +78,53 @@ class MHIngredient : public MHRoot
// Font - not needed for UK MHEG
class MHFont : public MHIngredient
{
-public:
+ public:
MHFont();
virtual ~MHFont();
virtual const char *ClassName() { return "Font"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintMe(FILE *fd, int nTabs) const;
-protected:
+ protected:
};
// CursorShape - not needed for UK MHEG
class MHCursorShape : public MHIngredient
{
-public:
+ public:
MHCursorShape();
virtual ~MHCursorShape();
virtual const char *ClassName() { return "CursorShape"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintMe(FILE *fd, int nTabs) const;
-protected:
+ protected:
};
// Paletter - not needed for UK MHEG
class MHPalette : public MHIngredient
{
-public:
+ public:
MHPalette();
virtual ~MHPalette();
virtual const char *ClassName() { return "Palette"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintMe(FILE *fd, int nTabs) const;
-protected:
+ protected:
};
// Actions.
// SetData - provide new content for an ingredient.
class MHSetData: public MHElemAction
{
-public:
+ public:
MHSetData(): MHElemAction(":SetData"), m_fIsIncluded(false),
m_fSizePresent(false), m_fCCPriorityPresent(false) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
virtual void PrintArgs(FILE *fd, int nTabs) const;
-protected:
+ protected:
// Either included content or referenced content.
bool m_fIsIncluded, m_fSizePresent, m_fCCPriorityPresent;
MHGenericOctetString m_Included;
@@ -136,14 +136,14 @@ class MHSetData: public MHElemAction
// Preload and unload
class MHPreload: public MHElemAction
{
-public:
+ public:
MHPreload(): MHElemAction(":Preload") {}
virtual void Perform(MHEngine *engine) { Target(engine)->Preload(engine); }
};
class MHUnload: public MHElemAction
{
-public:
+ public:
MHUnload(): MHElemAction(":Unload") {}
virtual void Perform(MHEngine *engine) { Target(engine)->Unload(engine); }
};
@@ -151,7 +151,7 @@ class MHUnload: public MHElemAction
// Clone - make a copy of an existing object.
class MHClone: public MHActionGenericObjectRef
{
-public:
+ public:
MHClone(): MHActionGenericObjectRef(":Clone") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pRef);
};
diff --git a/mythtv/libs/libmythfreemheg/Link.cpp b/mythtv/libs/libmythfreemheg/Link.cpp
index c13fd1ba83c..dff12ea8263 100644
--- a/mythtv/libs/libmythfreemheg/Link.cpp
+++ b/mythtv/libs/libmythfreemheg/Link.cpp
@@ -42,46 +42,91 @@ void MHLink::Initialise(MHParseNode *p, MHEngine *engine)
MHIngredient::Initialise(p, engine);
// The link condition is encoded differently in the binary and text representations.
MHParseNode *pLinkCond = p->GetNamedArg(C_LINK_CONDITION);
- if (pLinkCond) { // Only in binary.
+
+ if (pLinkCond) // Only in binary.
+ {
m_EventSource.Initialise(pLinkCond->GetArgN(0), engine); // Event source
m_nEventType = (enum EventType)pLinkCond->GetArgN(1)->GetEnumValue(); // Event type
// The event data is optional and type-dependent.
- if (pLinkCond->GetArgCount() >= 3) {
+ if (pLinkCond->GetArgCount() >= 3)
+ {
MHParseNode *pEventData = pLinkCond->GetArgN(2);
- switch (pEventData->m_nNodeType) {
- case MHParseNode::PNBool: m_EventData.m_fBoolVal = pEventData->GetBoolValue(); m_EventData.m_Type = MHUnion::U_Bool; break;
- case MHParseNode::PNInt: m_EventData.m_nIntVal = pEventData->GetIntValue(); m_EventData.m_Type = MHUnion::U_Int; break;
- case MHParseNode::PNString: pEventData->GetStringValue(m_EventData.m_StrVal); m_EventData.m_Type = MHUnion::U_String; break;
- default: pEventData->Failure("Unknown type of event data");
+
+ switch (pEventData->m_nNodeType)
+ {
+ case MHParseNode::PNBool:
+ m_EventData.m_fBoolVal = pEventData->GetBoolValue();
+ m_EventData.m_Type = MHUnion::U_Bool;
+ break;
+ case MHParseNode::PNInt:
+ m_EventData.m_nIntVal = pEventData->GetIntValue();
+ m_EventData.m_Type = MHUnion::U_Int;
+ break;
+ case MHParseNode::PNString:
+ pEventData->GetStringValue(m_EventData.m_StrVal);
+ m_EventData.m_Type = MHUnion::U_String;
+ break;
+ default:
+ pEventData->Failure("Unknown type of event data");
}
}
}
- else { // Only in text.
+ else // Only in text.
+ {
MHParseNode *pEventSource = p->GetNamedArg(P_EVENT_SOURCE); // Event source
+
if (! pEventSource)
+ {
p->Failure("Missing :EventSource");
+ }
else
+ {
m_EventSource.Initialise(pEventSource->GetArgN(0), engine);
-
+ }
+
MHParseNode *pEventType = p->GetNamedArg(P_EVENT_TYPE); // Event type
+
if (! pEventType)
+ {
p->Failure("Missing :EventType");
+ }
else
+ {
m_nEventType = (enum EventType)pEventType->GetArgN(0)->GetEnumValue();
+ }
+
MHParseNode *pEventData = p->GetNamedArg(P_EVENT_DATA); // Event data - optional
- if (pEventData) {
+
+ if (pEventData)
+ {
MHParseNode *pEventDataArg = pEventData->GetArgN(0);
- switch (pEventDataArg->m_nNodeType) {
- case MHParseNode::PNBool: m_EventData.m_fBoolVal = pEventDataArg->GetBoolValue(); m_EventData.m_Type = MHUnion::U_Bool; break;
- case MHParseNode::PNInt: m_EventData.m_nIntVal = pEventDataArg->GetIntValue(); m_EventData.m_Type = MHUnion::U_Int; break;
- case MHParseNode::PNString: pEventDataArg->GetStringValue(m_EventData.m_StrVal); m_EventData.m_Type = MHUnion::U_String; break;
- default: pEventDataArg->Failure("Unknown type of event data");
+
+ switch (pEventDataArg->m_nNodeType)
+ {
+ case MHParseNode::PNBool:
+ m_EventData.m_fBoolVal = pEventDataArg->GetBoolValue();
+ m_EventData.m_Type = MHUnion::U_Bool;
+ break;
+ case MHParseNode::PNInt:
+ m_EventData.m_nIntVal = pEventDataArg->GetIntValue();
+ m_EventData.m_Type = MHUnion::U_Int;
+ break;
+ case MHParseNode::PNString:
+ pEventDataArg->GetStringValue(m_EventData.m_StrVal);
+ m_EventData.m_Type = MHUnion::U_String;
+ break;
+ default:
+ pEventDataArg->Failure("Unknown type of event data");
}
}
}
MHParseNode *pLinkEffect = p->GetNamedArg(C_LINK_EFFECT);
- if (pLinkEffect) m_LinkEffect.Initialise(pLinkEffect, engine);
+
+ if (pLinkEffect)
+ {
+ m_LinkEffect.Initialise(pLinkEffect, engine);
+ }
}
static const char *rchEventType[] =
@@ -124,42 +169,80 @@ static const char *rchEventType[] =
// Look up the event type. Returns zero if it doesn't match.
int MHLink::GetEventType(const char *str)
{
- for (int i = 0; i < (int)(sizeof(rchEventType)/sizeof(rchEventType[0])); i++) {
- if (strcasecmp(str, rchEventType[i]) == 0) return (i+1); // Numbered from 1
+ for (int i = 0; i < (int)(sizeof(rchEventType) / sizeof(rchEventType[0])); i++)
+ {
+ if (strcasecmp(str, rchEventType[i]) == 0)
+ {
+ return (i + 1); // Numbered from 1
+ }
}
+
return 0;
}
QString MHLink::EventTypeToString(enum EventType ev)
{
- if (ev > 0 && ev <= (int)(sizeof(rchEventType)/sizeof(rchEventType[0]))) return rchEventType[ev-1];
- else return QString("Unknown event %1").arg(ev);
+ if (ev > 0 && ev <= (int)(sizeof(rchEventType) / sizeof(rchEventType[0])))
+ {
+ return rchEventType[ev-1];
+ }
+ else
+ {
+ return QString("Unknown event %1").arg(ev);
+ }
}
void MHLink::PrintMe(FILE *fd, int nTabs) const
{
PrintTabs(fd, nTabs);
- fprintf(fd, "{:Link"); MHIngredient::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":EventSource "); m_EventSource.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
- MHASSERT(m_nEventType > 0 && m_nEventType <= (int)(sizeof(rchEventType)/sizeof(rchEventType[0])));
- PrintTabs(fd, nTabs+1); fprintf(fd, ":EventType %s\n", rchEventType[m_nEventType-1]);
+ fprintf(fd, "{:Link");
+ MHIngredient::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":EventSource ");
+ m_EventSource.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ MHASSERT(m_nEventType > 0 && m_nEventType <= (int)(sizeof(rchEventType) / sizeof(rchEventType[0])));
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":EventType %s\n", rchEventType[m_nEventType-1]);
+
// The event data is optional and its format depends on the event type.
- switch (m_EventData.m_Type) {
- case MHUnion::U_Bool: PrintTabs(fd, nTabs+1); fprintf(fd, ":EventData %s\n", m_EventData.m_fBoolVal ? "true" : "false"); break;
- case MHUnion::U_Int: PrintTabs(fd, nTabs+1); fprintf(fd, ":EventData %d\n", m_EventData.m_nIntVal); break;
- case MHUnion::U_String: PrintTabs(fd, nTabs+1); fprintf(fd, ":EventData"); m_EventData.m_StrVal.PrintMe(fd, nTabs); fprintf(fd, "\n"); break;
- default: break; // None and others
+ switch (m_EventData.m_Type)
+ {
+ case MHUnion::U_Bool:
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":EventData %s\n", m_EventData.m_fBoolVal ? "true" : "false");
+ break;
+ case MHUnion::U_Int:
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":EventData %d\n", m_EventData.m_nIntVal);
+ break;
+ case MHUnion::U_String:
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":EventData");
+ m_EventData.m_StrVal.PrintMe(fd, nTabs);
+ fprintf(fd, "\n");
+ break;
+ default:
+ break; // None and others
}
- PrintTabs(fd, nTabs+1); fprintf(fd, ":LinkEffect (\n");
- m_LinkEffect.PrintMe(fd, nTabs+2);
- PrintTabs(fd, nTabs+1); fprintf(fd, ")\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":LinkEffect (\n");
+ m_LinkEffect.PrintMe(fd, nTabs + 2);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ")\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
// Activation.
void MHLink::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHIngredient::Activation(engine);
m_fRunning = true;
engine->AddLink(this);
@@ -168,7 +251,11 @@ void MHLink::Activation(MHEngine *engine)
void MHLink::Deactivation(MHEngine *engine)
{
- if (! m_fRunning) return;
+ if (! m_fRunning)
+ {
+ return;
+ }
+
engine->RemoveLink(this);
MHIngredient::Deactivation(engine);
}
@@ -176,11 +263,19 @@ void MHLink::Deactivation(MHEngine *engine)
// Activate or deactivate the link.
void MHLink::Activate(bool fActivate, MHEngine *engine)
{
- if (fActivate) {
- if (! m_fRunning) Activation(engine);
+ if (fActivate)
+ {
+ if (! m_fRunning)
+ {
+ Activation(engine);
+ }
}
- else {
- if (m_fRunning) Deactivation(engine);
+ else
+ {
+ if (m_fRunning)
+ {
+ Deactivation(engine);
+ }
}
}
@@ -188,20 +283,32 @@ void MHLink::Activate(bool fActivate, MHEngine *engine)
// any event data the link fires whatever the value of the data.
void MHLink::MatchEvent(const MHObjectRef &sourceRefRef, enum EventType ev, const MHUnion &evData, MHEngine *engine)
{
- if (m_fRunning && m_nEventType == ev && sourceRefRef.Equal(m_EventSource, engine)) { // Source and event type match.
+ if (m_fRunning && m_nEventType == ev && sourceRefRef.Equal(m_EventSource, engine)) // Source and event type match.
+ {
bool fMatch = false;
- switch (m_EventData.m_Type) {
- case MHUnion::U_None: fMatch = true; break; // No data specified - always matches.
- case MHUnion::U_Bool:
- fMatch = evData.m_Type == MHUnion::U_Bool && evData.m_fBoolVal == m_EventData.m_fBoolVal; break;
- case MHUnion::U_Int:
- fMatch = evData.m_Type == MHUnion::U_Int && evData.m_nIntVal == m_EventData.m_nIntVal; break;
- case MHUnion::U_String:
- fMatch = evData.m_Type == MHUnion::U_String && evData.m_StrVal.Equal(m_EventData.m_StrVal); break;
- default: fMatch = false; break;
+
+ switch (m_EventData.m_Type)
+ {
+ case MHUnion::U_None:
+ fMatch = true;
+ break; // No data specified - always matches.
+ case MHUnion::U_Bool:
+ fMatch = evData.m_Type == MHUnion::U_Bool && evData.m_fBoolVal == m_EventData.m_fBoolVal;
+ break;
+ case MHUnion::U_Int:
+ fMatch = evData.m_Type == MHUnion::U_Int && evData.m_nIntVal == m_EventData.m_nIntVal;
+ break;
+ case MHUnion::U_String:
+ fMatch = evData.m_Type == MHUnion::U_String && evData.m_StrVal.Equal(m_EventData.m_StrVal);
+ break;
+ default:
+ fMatch = false;
+ break;
}
+
// Fire the link
- if (fMatch) {
+ if (fMatch)
+ {
MHLOG(MHLogLinks, QString("Link fired - %1").arg(m_ObjectReference.Printable()));
engine->AddActions(m_LinkEffect);
}
diff --git a/mythtv/libs/libmythfreemheg/Link.h b/mythtv/libs/libmythfreemheg/Link.h
index 14424e38743..559dfaac7f8 100644
--- a/mythtv/libs/libmythfreemheg/Link.h
+++ b/mythtv/libs/libmythfreemheg/Link.h
@@ -35,7 +35,7 @@ class MHParseNode;
// Link - basically a guarded command.
class MHLink : public MHIngredient
{
-public:
+ public:
MHLink();
virtual const char *ClassName() { return "Link"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine); // Set this up from the parse tree.
@@ -54,7 +54,7 @@ class MHLink : public MHIngredient
// Called when an event has been triggered and fires this link if it matches.
virtual void MatchEvent(const MHObjectRef &sourceRef, enum EventType ev, const MHUnion &un, MHEngine *engine);
-protected:
+ protected:
MHObjectRef m_EventSource;
enum EventType m_nEventType;
MHUnion m_EventData;
@@ -65,10 +65,10 @@ class MHLink : public MHIngredient
// Activate and deactivate actions.
class MHActivate: public MHElemAction
{
-public:
+ public:
MHActivate(const char *name, bool fActivate): MHElemAction(name), m_fActivate(fActivate) {}
virtual void Perform(MHEngine *engine) { Target(engine)->Activate(m_fActivate, engine); }
-protected:
+ protected:
bool m_fActivate;
};
diff --git a/mythtv/libs/libmythfreemheg/ParseBinary.cpp b/mythtv/libs/libmythfreemheg/ParseBinary.cpp
index 1b63f94d798..f8032b96a56 100644
--- a/mythtv/libs/libmythfreemheg/ParseBinary.cpp
+++ b/mythtv/libs/libmythfreemheg/ParseBinary.cpp
@@ -45,7 +45,11 @@ MHParseBinary::MHParseBinary(QByteArray &program)
// and we throw an exception.
unsigned char MHParseBinary::GetNextChar()
{
- if (m_p >= (int)m_data.size()) MHERROR("Unexpected end of file");
+ if (m_p >= (int)m_data.size())
+ {
+ MHERROR("Unexpected end of file");
+ }
+
return m_data[m_p++];
}
@@ -53,13 +57,21 @@ unsigned char MHParseBinary::GetNextChar()
// Parse a string argument. ASN1 strings can include nulls as valid characters.
void MHParseBinary::ParseString(int endStr, MHOctetString &str)
{
- // TODO: Don't deal with indefinite length at the moment.
+ // TODO: Don't deal with indefinite length at the moment.
if (endStr == INDEFINITE_LENGTH)
+ {
MHERROR("Indefinite length strings are not implemented");
+ }
+
int nLength = endStr - m_p;
- unsigned char *stringValue = (unsigned char*)malloc(endStr - m_p);
+ unsigned char *stringValue = (unsigned char *)malloc(endStr - m_p);
unsigned char *p = stringValue;
- while (m_p < endStr) *p++ = GetNextChar();
+
+ while (m_p < endStr)
+ {
+ *p++ = GetNextChar();
+ }
+
str.Copy(MHOctetString((const char *)stringValue, nLength));
free(stringValue);
}
@@ -69,16 +81,27 @@ int MHParseBinary::ParseInt(int endInt)
{
int intVal = 0;
bool firstByte = true;
+
if (endInt == INDEFINITE_LENGTH)
+ {
MHERROR("Indefinite length integers are not implemented");
- while (m_p < endInt) {
+ }
+
+ while (m_p < endInt)
+ {
unsigned char ch = GetNextChar();
+
// Integer values are signed so if the top bit is set in the first byte
// we need to set the sign bit.
- if (firstByte && ch >= 128) intVal = -1;
+ if (firstByte && ch >= 128)
+ {
+ intVal = -1;
+ }
+
firstByte = false;
intVal = (intVal << 8) | ch;
}
+
return intVal;
}
@@ -99,127 +122,159 @@ MHParseNode *MHParseBinary::DoParse()
// ASN1 Coding rules: Top two bits (0 and 1) indicate the tag class.
// 0x00 - Universal, 0x40 - Application, 0x80 - Context-specific, 0xC0 - Private
// We only use Universal and Context.
- switch (ch & 0xC0) {
- case 0x00: // Universal
- tagClass = Universal;
- break;
- case 0x80:
- tagClass = Context;
- break;
- default:
- MHERROR(QString("Invalid tag class = %1").arg(ch, 0, 16));
+ switch (ch & 0xC0)
+ {
+ case 0x00: // Universal
+ tagClass = Universal;
+ break;
+ case 0x80:
+ tagClass = Context;
+ break;
+ default:
+ MHERROR(QString("Invalid tag class = %1").arg(ch, 0, 16));
}
+
// Bit 2 indicates whether it is a simple or compound type. Not used.
// Lower bits are the tag number.
tagNumber = ch & 0x1f;
- if (tagNumber == 0x1f) { // Except that if it is 0x1F then the tag is encoded in the following bytes.
+
+ if (tagNumber == 0x1f) // Except that if it is 0x1F then the tag is encoded in the following bytes.
+ {
tagNumber = 0;
- do {
+
+ do
+ {
ch = GetNextChar();
tagNumber = (tagNumber << 7) | (ch & 0x7f);
- } while (ch & 0x80); // Top bit set means there's more to come.
+ }
+ while (ch & 0x80); // Top bit set means there's more to come.
}
// Next byte is the length. If it is less than 128 it is the actual length, otherwise it
// gives the number of bytes containing the length, except that if this is zero the item
// has an "indefinite" length and is terminated by two zero bytes.
ch = GetNextChar();
- if (ch & 0x80) {
+
+ if (ch & 0x80)
+ {
int lengthOfLength = ch & 0x7f;
- if (lengthOfLength == 0) endOfItem = INDEFINITE_LENGTH;
- else {
+
+ if (lengthOfLength == 0)
+ {
+ endOfItem = INDEFINITE_LENGTH;
+ }
+ else
+ {
endOfItem = 0;
- while (lengthOfLength--) {
+
+ while (lengthOfLength--)
+ {
ch = GetNextChar();
endOfItem = (endOfItem << 8) | ch;
}
+
endOfItem += m_p;
}
}
- else endOfItem = ch + m_p;
+ else
+ {
+ endOfItem = ch + m_p;
+ }
- if (tagClass == Context) {
+ if (tagClass == Context)
+ {
MHPTagged *pNode = new MHPTagged(tagNumber);
- try {
+
+ try
+ {
// The argument here depends on the particular tag we're processing.
- switch (tagNumber) {
- case C_MULTIPLE_SELECTION:
- case C_OBSCURED_INPUT:
- case C_INITIALLY_AVAILABLE:
- case C_WRAP_AROUND:
- case C_TEXT_WRAPPING:
- case C_INITIALLY_ACTIVE:
- case C_MOVING_CURSOR:
- case C_SHARED:
- case C_ENGINE_RESP:
- case C_TILING:
- case C_BORDERED_BOUNDING_BOX:
- { // BOOL
+ switch (tagNumber)
+ {
+ case C_MULTIPLE_SELECTION:
+ case C_OBSCURED_INPUT:
+ case C_INITIALLY_AVAILABLE:
+ case C_WRAP_AROUND:
+ case C_TEXT_WRAPPING:
+ case C_INITIALLY_ACTIVE:
+ case C_MOVING_CURSOR:
+ case C_SHARED:
+ case C_ENGINE_RESP:
+ case C_TILING:
+ case C_BORDERED_BOUNDING_BOX:
+ {
+ // BOOL
// If there is no argument we need to indicate that so that it gets
// the correct default value.
- if (m_p != endOfItem){
+ if (m_p != endOfItem)
+ {
int intVal = ParseInt(endOfItem); // May raise an exception
pNode->AddArg(new MHPBool(intVal != 0));
}
+
break;
}
- case C_INPUT_TYPE:
- case C_SLIDER_STYLE:
- case C_TERMINATION:
- case C_ORIENTATION:
- case C_HORIZONTAL_JUSTIFICATION:
- case C_BUTTON_STYLE:
- case C_START_CORNER:
- case C_LINE_ORIENTATION:
- case C_VERTICAL_JUSTIFICATION:
- case C_STORAGE:
- { // ENUM
- if (m_p != endOfItem){
+ case C_INPUT_TYPE:
+ case C_SLIDER_STYLE:
+ case C_TERMINATION:
+ case C_ORIENTATION:
+ case C_HORIZONTAL_JUSTIFICATION:
+ case C_BUTTON_STYLE:
+ case C_START_CORNER:
+ case C_LINE_ORIENTATION:
+ case C_VERTICAL_JUSTIFICATION:
+ case C_STORAGE:
+ {
+ // ENUM
+ if (m_p != endOfItem)
+ {
int intVal = ParseInt(endOfItem); // May raise an exception
pNode->AddArg(new MHPEnum(intVal));
}
}
- case C_INITIAL_PORTION:
- case C_STEP_SIZE:
- case C_INPUT_EVENT_REGISTER:
- case C_INITIAL_VALUE:
- case C_IP_CONTENT_HOOK:
- case C_MAX_VALUE:
- case C_MIN_VALUE:
- case C_LINE_ART_CONTENT_HOOK:
- case C_BITMAP_CONTENT_HOOK:
- case C_TEXT_CONTENT_HOOK:
- case C_STREAM_CONTENT_HOOK:
- case C_MAX_LENGTH:
- case C_CHARACTER_SET:
- case C_ORIGINAL_TRANSPARENCY:
- case C_ORIGINAL_GC_PRIORITY:
- case C_LOOPING:
- case C_ORIGINAL_LINE_STYLE:
- case C_STANDARD_VERSION:
- case C_ORIGINAL_LINE_WIDTH:
- case C_CONTENT_HOOK:
- case C_CONTENT_CACHE_PRIORITY:
- case C_COMPONENT_TAG:
- case C_ORIGINAL_VOLUME:
- case C_PROGRAM_CONNECTION_TAG:
- case C_CONTENT_SIZE:
- { // INT
- if (m_p != endOfItem){
+ case C_INITIAL_PORTION:
+ case C_STEP_SIZE:
+ case C_INPUT_EVENT_REGISTER:
+ case C_INITIAL_VALUE:
+ case C_IP_CONTENT_HOOK:
+ case C_MAX_VALUE:
+ case C_MIN_VALUE:
+ case C_LINE_ART_CONTENT_HOOK:
+ case C_BITMAP_CONTENT_HOOK:
+ case C_TEXT_CONTENT_HOOK:
+ case C_STREAM_CONTENT_HOOK:
+ case C_MAX_LENGTH:
+ case C_CHARACTER_SET:
+ case C_ORIGINAL_TRANSPARENCY:
+ case C_ORIGINAL_GC_PRIORITY:
+ case C_LOOPING:
+ case C_ORIGINAL_LINE_STYLE:
+ case C_STANDARD_VERSION:
+ case C_ORIGINAL_LINE_WIDTH:
+ case C_CONTENT_HOOK:
+ case C_CONTENT_CACHE_PRIORITY:
+ case C_COMPONENT_TAG:
+ case C_ORIGINAL_VOLUME:
+ case C_PROGRAM_CONNECTION_TAG:
+ case C_CONTENT_SIZE:
+ {
+ // INT
+ if (m_p != endOfItem)
+ {
int intVal = ParseInt(endOfItem); // May raise an exception
pNode->AddArg(new MHPInt(intVal));
}
}
- case C_OBJECT_INFORMATION:
- case C_CONTENT_REFERENCE:
- case C_FONT_ATTRIBUTES:
- case C_CHAR_LIST:
- case C_NAME:
- case C_ORIGINAL_LABEL:
- { // STRING
+ case C_OBJECT_INFORMATION:
+ case C_CONTENT_REFERENCE:
+ case C_FONT_ATTRIBUTES:
+ case C_CHAR_LIST:
+ case C_NAME:
+ case C_ORIGINAL_LABEL:
+ {
+ // STRING
// Unlike INT, BOOL and ENUM we can't distinguish an empty string
// from a missing string.
MHOctetString str;
@@ -227,73 +282,89 @@ MHParseNode *MHParseBinary::DoParse()
pNode->AddArg(new MHPString(str));
}
- default:
+ default:
{
// Everything else has either no argument or is self-describing
// TODO: Handle indefinite length.
if (endOfItem == INDEFINITE_LENGTH)
+ {
MHERROR("Indefinite length arguments are not implemented");
- while (m_p < endOfItem) {
+ }
+
+ while (m_p < endOfItem)
+ {
pNode->AddArg(DoParse());
}
}
}
}
- catch (...) {
+ catch (...)
+ {
// Memory clean-up
delete pNode;
throw;
}
+
return pNode;
}
- else { // Universal - i.e. a primitive type.
+ else // Universal - i.e. a primitive type.
+ {
// Tag values
- switch (tagNumber) {
- case U_BOOL: // Boolean
+ switch (tagNumber)
+ {
+ case U_BOOL: // Boolean
{
int intVal = ParseInt(endOfItem);
- return new MHPBool(intVal != 0);
+ return new MHPBool(intVal != 0);
}
- case U_INT: // Integer
+ case U_INT: // Integer
{
int intVal = ParseInt(endOfItem);
return new MHPInt(intVal);
}
- case U_ENUM: // ENUM
+ case U_ENUM: // ENUM
{
int intVal = ParseInt(endOfItem);
return new MHPEnum(intVal);
}
- case U_STRING: // String
+ case U_STRING: // String
{
MHOctetString str;
ParseString(endOfItem, str);
return new MHPString(str);
}
- case U_NULL: // ASN1 NULL
+ case U_NULL: // ASN1 NULL
{
return new MHPNull;
}
- case U_SEQUENCE: // Sequence
+ case U_SEQUENCE: // Sequence
{
MHParseSequence *pNode = new MHParseSequence();
+
if (endOfItem == INDEFINITE_LENGTH)
+ {
MHERROR("Indefinite length sequences are not implemented");
- try {
- while (m_p < endOfItem) {
+ }
+
+ try
+ {
+ while (m_p < endOfItem)
+ {
pNode->Append(DoParse());
}
}
- catch (...) {
+ catch (...)
+ {
// Memory clean-up if error.
delete pNode;
throw;
}
+
return pNode;
}
- default:
- MHERROR(QString("Unknown universal %1").arg(tagNumber));
+ default:
+ MHERROR(QString("Unknown universal %1").arg(tagNumber));
}
}
}
diff --git a/mythtv/libs/libmythfreemheg/ParseBinary.h b/mythtv/libs/libmythfreemheg/ParseBinary.h
index 4a8a0e9d84c..13616b52902 100644
--- a/mythtv/libs/libmythfreemheg/ParseBinary.h
+++ b/mythtv/libs/libmythfreemheg/ParseBinary.h
@@ -30,20 +30,20 @@ class MHGroup;
class MHParseBinary: public MHParseBase
{
-public:
+ public:
MHParseBinary(QByteArray &program);
virtual ~MHParseBinary() {}
// Parse the binary and return a pointer to the parse tree
virtual MHParseNode *Parse() { return DoParse(); }
-private:
+ private:
MHParseNode *DoParse();
unsigned char GetNextChar();
void ParseString(int endStr, MHOctetString &str);
int ParseInt(int endInt);
-private:
+ private:
int m_p; // Count of bytes read
QByteArray m_data;
};
diff --git a/mythtv/libs/libmythfreemheg/ParseNode.cpp b/mythtv/libs/libmythfreemheg/ParseNode.cpp
index 42866005695..1b7bc2fb591 100644
--- a/mythtv/libs/libmythfreemheg/ParseNode.cpp
+++ b/mythtv/libs/libmythfreemheg/ParseNode.cpp
@@ -39,7 +39,10 @@ void MHPTagged::AddArg(MHParseNode *pArg)
// General utility function for display.
void PrintTabs(FILE *fd, int n)
{
- for (int i = 0; i < n; i++) fprintf(fd, " ");
+ for (int i = 0; i < n; i++)
+ {
+ fprintf(fd, " ");
+ }
}
// Report a failure. This can be called when we use the parse tree to set up object tree.
@@ -51,39 +54,65 @@ void MHParseNode::Failure(const char *p)
int MHParseNode::GetTagNo()
{
- if (m_nNodeType != PNTagged) Failure("Expected tagged value");
- return ((MHPTagged*)this)->m_TagNo;
+ if (m_nNodeType != PNTagged)
+ {
+ Failure("Expected tagged value");
+ }
+
+ return ((MHPTagged *)this)->m_TagNo;
}
// Return the number of items in the sequence.
int MHParseNode::GetArgCount()
{
- if (m_nNodeType == PNTagged) {
- MHPTagged *pTag = (MHPTagged*)this;
+ if (m_nNodeType == PNTagged)
+ {
+ MHPTagged *pTag = (MHPTagged *)this;
return pTag->m_Args.Size();
}
- else if (m_nNodeType == PNSeq) {
- MHParseSequence *pSeq = (MHParseSequence*)this;
+ else if (m_nNodeType == PNSeq)
+ {
+ MHParseSequence *pSeq = (MHParseSequence *)this;
return pSeq->Size();
}
- else Failure("Expected tagged value");
+ else
+ {
+ Failure("Expected tagged value");
+ }
+
return 0; // To keep the compiler happy
}
// Get the Nth entry.
MHParseNode *MHParseNode::GetArgN(int n)
{
- if (m_nNodeType == PNTagged) {
- MHPTagged *pTag = (MHPTagged*)this;
- if (n < 0 || n >= pTag->m_Args.Size()) Failure("Argument not found");
+ if (m_nNodeType == PNTagged)
+ {
+ MHPTagged *pTag = (MHPTagged *)this;
+
+ if (n < 0 || n >= pTag->m_Args.Size())
+ {
+ Failure("Argument not found");
+ }
+
return pTag->m_Args.GetAt(n);
}
- else if (m_nNodeType == PNSeq) {
- MHParseSequence *pSeq = (MHParseSequence*)this;
- if (n < 0 || n >= pSeq->Size()) Failure("Argument not found");
+ else if (m_nNodeType == PNSeq)
+ {
+ MHParseSequence *pSeq = (MHParseSequence *)this;
+
+ if (n < 0 || n >= pSeq->Size())
+ {
+ Failure("Argument not found");
+ }
+
return pSeq->GetAt(n);
}
- else Failure("Expected tagged value");
+ else
+ {
+ Failure("Expected tagged value");
+ }
+
return 0; // To keep the compiler happy
}
@@ -93,57 +122,103 @@ MHParseNode *MHParseNode::GetArgN(int n)
MHParseNode *MHParseNode::GetNamedArg(int nTag)
{
MHParseSequence *pArgs = NULL;
- if (m_nNodeType == PNTagged) pArgs = &((MHPTagged*)this)->m_Args;
- else if (m_nNodeType == PNSeq) pArgs = (MHParseSequence*)this;
- else Failure("Expected tagged value or sequence");
- for (int i = 0; i < pArgs->Size(); i++) {
+
+ if (m_nNodeType == PNTagged)
+ {
+ pArgs = &((MHPTagged *)this)->m_Args;
+ }
+ else if (m_nNodeType == PNSeq)
+ {
+ pArgs = (MHParseSequence *)this;
+ }
+ else
+ {
+ Failure("Expected tagged value or sequence");
+ }
+
+ for (int i = 0; i < pArgs->Size(); i++)
+ {
MHParseNode *p = pArgs->GetAt(i);
- if (p && p->m_nNodeType == PNTagged && ((MHPTagged*)p)->m_TagNo == nTag) return p;
+
+ if (p && p->m_nNodeType == PNTagged && ((MHPTagged *)p)->m_TagNo == nTag)
+ {
+ return p;
+ }
}
+
return NULL;
}
// Sequence.
int MHParseNode::GetSeqCount()
{
- if (m_nNodeType != PNSeq) Failure("Expected sequence");
- MHParseSequence *pSeq = (MHParseSequence*)this;
+ if (m_nNodeType != PNSeq)
+ {
+ Failure("Expected sequence");
+ }
+
+ MHParseSequence *pSeq = (MHParseSequence *)this;
return pSeq->Size();
}
MHParseNode *MHParseNode::GetSeqN(int n)
{
- if (m_nNodeType != PNSeq) Failure("Expected sequence");
- MHParseSequence *pSeq = (MHParseSequence*)this;
- if (n < 0 || n >= pSeq->Size()) Failure("Argument not found");
+ if (m_nNodeType != PNSeq)
+ {
+ Failure("Expected sequence");
+ }
+
+ MHParseSequence *pSeq = (MHParseSequence *)this;
+
+ if (n < 0 || n >= pSeq->Size())
+ {
+ Failure("Argument not found");
+ }
+
return pSeq->GetAt(n);
}
// Int
int MHParseNode::GetIntValue()
{
- if (m_nNodeType != PNInt) Failure("Expected integer");
- return ((MHPInt*)this)->m_Value;
+ if (m_nNodeType != PNInt)
+ {
+ Failure("Expected integer");
+ }
+
+ return ((MHPInt *)this)->m_Value;
}
// Enum
int MHParseNode::GetEnumValue()
{
- if (m_nNodeType != PNEnum) Failure("Expected enumerated type");
- return ((MHPEnum*)this)->m_Value;
+ if (m_nNodeType != PNEnum)
+ {
+ Failure("Expected enumerated type");
+ }
+
+ return ((MHPEnum *)this)->m_Value;
}
// Bool
bool MHParseNode::GetBoolValue()
{
- if (m_nNodeType != PNBool) Failure("Expected boolean");
- return ((MHPBool*)this)->m_Value;
+ if (m_nNodeType != PNBool)
+ {
+ Failure("Expected boolean");
+ }
+
+ return ((MHPBool *)this)->m_Value;
}
// String
void MHParseNode::GetStringValue(MHOctetString &str)
{
- if (m_nNodeType != PNString) Failure("Expected string");
- str.Copy(((MHPString*)this)->m_Value);
+ if (m_nNodeType != PNString)
+ {
+ Failure("Expected string");
+ }
+
+ str.Copy(((MHPString *)this)->m_Value);
}
diff --git a/mythtv/libs/libmythfreemheg/ParseNode.h b/mythtv/libs/libmythfreemheg/ParseNode.h
index ed8b44e32ac..1f7f939faaa 100644
--- a/mythtv/libs/libmythfreemheg/ParseNode.h
+++ b/mythtv/libs/libmythfreemheg/ParseNode.h
@@ -29,7 +29,7 @@ class MHGroup;
// Abstract base class for the text and binary parsers.
class MHParseBase {
-public:
+ public:
virtual ~MHParseBase() {}
virtual MHParseNode *Parse() = 0;
};
@@ -37,11 +37,11 @@ class MHParseBase {
// Element of the parse tree, basically a piece of the program.
class MHParseNode
{
-public:
+ public:
enum NodeType { PNTagged, PNBool, PNInt, PNEnum, PNString, PNNull, PNSeq };
-protected:
+ protected:
MHParseNode(enum NodeType nt): m_nNodeType(nt) {}
-public:
+ public:
virtual ~MHParseNode() {}
enum NodeType m_nNodeType;
@@ -72,7 +72,7 @@ class MHParseNode
// Sequence of parse nodes.
class MHParseSequence: public MHParseNode, public MHOwnPtrSequence
{
-public:
+ public:
MHParseSequence(): MHParseNode(PNSeq) {}
void PrintUnbracketed(int nTabs);
};
@@ -81,7 +81,7 @@ class MHParseSequence: public MHParseNode, public MHOwnPtrSequence
// to this class. We will make derived classes in due course.
class MHPTagged: public MHParseNode
{
-public:
+ public:
MHPTagged(int nTag);
void AddArg(MHParseNode *pNode);
@@ -92,46 +92,46 @@ class MHPTagged: public MHParseNode
// Primitive integer value.
class MHPInt: public MHParseNode
{
-public:
+ public:
MHPInt(int v): MHParseNode(PNInt), m_Value(v) {}
-public:
+ public:
int m_Value;
};
// Enumerated type - treat much as integer
class MHPEnum: public MHParseNode
{
-public:
+ public:
MHPEnum(int v): MHParseNode(PNEnum), m_Value(v) {}
-public:
+ public:
int m_Value;
};
// Primitive boolean value
class MHPBool: public MHParseNode
{
-public:
+ public:
MHPBool(bool v): MHParseNode(PNBool), m_Value(v) {}
-public:
+ public:
bool m_Value;
};
// Primitive string value
class MHPString: public MHParseNode
{
-public:
+ public:
MHPString(MHOctetString &pSrc): MHParseNode(PNString) { m_Value.Copy(pSrc); }
-public:
+ public:
MHOctetString m_Value;
};
// ASN1 NULL value.
class MHPNull: public MHParseNode
{
-public:
+ public:
MHPNull(): MHParseNode(PNNull) {}
};
diff --git a/mythtv/libs/libmythfreemheg/ParseText.cpp b/mythtv/libs/libmythfreemheg/ParseText.cpp
index bb21fc06c64..feba0472aef 100644
--- a/mythtv/libs/libmythfreemheg/ParseText.cpp
+++ b/mythtv/libs/libmythfreemheg/ParseText.cpp
@@ -46,9 +46,9 @@ MHParseText::MHParseText(QByteArray &program)
{
m_data = program;
m_lineCount = 1;
- m_String = (unsigned char*)malloc(100); // Initial size - may grow.
+ m_String = (unsigned char *)malloc(100); // Initial size - may grow.
m_p = 0;
- }
+}
MHParseText::~MHParseText()
{
@@ -59,8 +59,13 @@ MHParseText::~MHParseText()
void MHParseText::GetNextChar()
{
if ((int)m_p >= m_data.size())
+ {
m_ch = EOF;
- else m_ch = m_data[m_p++];
+ }
+ else
+ {
+ m_ch = m_data[m_p++];
+ }
}
// Maximum length of a tag (i.e. a symbol beginning with a colon). Actually the longest is around 22 chars.
@@ -305,7 +310,7 @@ const char *rchTagNames[] =
":NewContentSize",
":NewCCPriority",
":IndirectRef",
-/* UK MHEG */
+ /* UK MHEG */
":SetBackgroundColour",
":SetCellPosition",
":SetInputRegister",
@@ -318,7 +323,7 @@ const char *rchTagNames[] =
":SetBitmapDecodeOffset",
":GetBitmapDecodeOffset",
":SetSliderParameters",
-/* Pseudo-operations. These are encoded as LinkCondition in binary. */
+ /* Pseudo-operations. These are encoded as LinkCondition in binary. */
":EventSource",
":EventType",
":EventData",
@@ -326,30 +331,39 @@ const char *rchTagNames[] =
};
// Some example programs use these colour names
-static struct { const char *name; unsigned char r, g, b, t; } colourTable[] =
+static struct
+{
+ const char *name;
+ unsigned char r, g, b, t;
+} colourTable[] =
{
{ "black", 0, 0, 0, 0 },
{ "transparent", 0, 0, 0, 255 },
- { "gray"/*sic*/, 128,128,128,0 },
- { "darkgray"/*sic*/,192,192,192,0 },
- { "red", 255,0, 0, 0 },
- { "darkred", 128,0, 0, 0 },
- { "blue", 0, 0, 255,0 },
- { "darkblue", 0, 0, 128,0 },
- { "green", 0, 255,0, 0 },
- { "darkgreen", 0, 128,0, 0 },
- { "yellow", 255,255,0, 0 },
- { "cyan", 0, 255,255,0 },
- { "magenta", 255,0, 255,0 }
+ { "gray"/*sic*/, 128, 128, 128, 0 },
+ { "darkgray"/*sic*/, 192, 192, 192, 0 },
+ { "red", 255, 0, 0, 0 },
+ { "darkred", 128, 0, 0, 0 },
+ { "blue", 0, 0, 255, 0 },
+ { "darkblue", 0, 0, 128, 0 },
+ { "green", 0, 255, 0, 0 },
+ { "darkgreen", 0, 128, 0, 0 },
+ { "yellow", 255, 255, 0, 0 },
+ { "cyan", 0, 255, 255, 0 },
+ { "magenta", 255, 0, 255, 0 }
};
// Search for a tag and return it if it exists. Returns -1 if it isn't found.
static int FindTag(const char *p)
{
- for (int i = 0; i < (int)(sizeof(rchTagNames)/sizeof(rchTagNames[0])); i++) {
- if (stricmp(p, rchTagNames[i]) == 0) return i;
+ for (int i = 0; i < (int)(sizeof(rchTagNames) / sizeof(rchTagNames[0])); i++)
+ {
+ if (stricmp(p, rchTagNames[i]) == 0)
+ {
+ return i;
+ }
}
+
return -1;
}
@@ -365,188 +379,427 @@ void MHParseText::Error(const char *str)
// Lexical analysis. Get the next symbol.
void MHParseText::NextSym()
{
- while (1) {
+ while (1)
+ {
- switch (m_ch) {
- case '\n': m_lineCount++; // And drop to next
- case ' ': case '\r': case '\t': case '\f':
- // Skip white space.
- GetNextChar();
- continue;
+ switch (m_ch)
+ {
+ case '\n':
+ m_lineCount++; // And drop to next
+ case ' ':
+ case '\r':
+ case '\t':
+ case '\f':
+ // Skip white space.
+ GetNextChar();
+ continue;
- case '/':
- { // Comment.
+ case '/':
+ {
+ // Comment.
GetNextChar();
- if (m_ch != '/') Error("Malformed comment");
- do { GetNextChar(); } while (m_ch != '\n' && m_ch != '\f' && m_ch != '\r');
+
+ if (m_ch != '/')
+ {
+ Error("Malformed comment");
+ }
+
+ do
+ {
+ GetNextChar();
+ }
+ while (m_ch != '\n' && m_ch != '\f' && m_ch != '\r');
+
continue; // Next symbol
}
- case ':': // Start of a tag
+ case ':': // Start of a tag
{
m_nType = PTTag;
char buff[MAX_TAG_LENGTH+1];
char *p = buff;
- do {
+
+ do
+ {
*p++ = m_ch;
GetNextChar();
- if (p == buff + MAX_TAG_LENGTH) break;
- } while ((m_ch >= 'a' && m_ch <= 'z') || (m_ch >= 'A' && m_ch <= 'Z'));
+
+ if (p == buff + MAX_TAG_LENGTH)
+ {
+ break;
+ }
+ }
+ while ((m_ch >= 'a' && m_ch <= 'z') || (m_ch >= 'A' && m_ch <= 'Z'));
+
*p = 0;
// Look it up and return it if it's found.
m_nTag = FindTag(buff);
- if (m_nTag >= 0) return;
+
+ if (m_nTag >= 0)
+ {
+ return;
+ }
+
// Unrecognised tag.
Error("Unrecognised tag");
}
- case '"': // Start of a string
+ case '"': // Start of a string
{
m_nType = PTString;
// MHEG strings can include NULLs. For the moment we pass back the length and also
// null-terminate the strings.
m_nStringLength = 0;
- while (1) {
+
+ while (1)
+ {
GetNextChar();
- if (m_ch == '"') break; // Finished the string.
- if (m_ch == '\\') GetNextChar(); // Escape character. Include the next char in the string.
- if (m_ch == '\n' || m_ch == '\r') Error("Unterminated string");
+
+ if (m_ch == '"')
+ {
+ break; // Finished the string.
+ }
+
+ if (m_ch == '\\')
+ {
+ GetNextChar(); // Escape character. Include the next char in the string.
+ }
+
+ if (m_ch == '\n' || m_ch == '\r')
+ {
+ Error("Unterminated string");
+ }
+
// We grow the buffer to the largest string in the input.
- unsigned char *str = (unsigned char*)realloc(m_String, m_nStringLength+2);
- if (str == NULL) Error("Insufficient memory");
+ unsigned char *str = (unsigned char *)realloc(m_String, m_nStringLength + 2);
+
+ if (str == NULL)
+ {
+ Error("Insufficient memory");
+ }
+
m_String = str;
m_String[m_nStringLength++] = m_ch;
}
+
GetNextChar(); // Skip the closing quote
m_String[m_nStringLength] = 0;
return;
}
- case '\'': // Start of a string using quoted printable
+ case '\'': // Start of a string using quoted printable
{
m_nType = PTString;
m_nStringLength = 0;
+
// Quotable printable strings contain escape sequences beginning with the
// escape character '='. The strings can span lines but each line must
// end with an equal sign.
- while (1) {
+ while (1)
+ {
GetNextChar();
- if (m_ch == '\'') break;
- if (m_ch == '\n') Error("Unterminated string");
- if (m_ch == '=') { // Special code in quoted-printable.
+
+ if (m_ch == '\'')
+ {
+ break;
+ }
+
+ if (m_ch == '\n')
+ {
+ Error("Unterminated string");
+ }
+
+ if (m_ch == '=') // Special code in quoted-printable.
+ {
// Should be followed by two hex digits or by white space and a newline.
GetNextChar();
- if (m_ch == ' ' || m_ch == '\t' || m_ch == '\r' || m_ch == '\n') {
+
+ if (m_ch == ' ' || m_ch == '\t' || m_ch == '\r' || m_ch == '\n')
+ {
// White space. Remove everything up to the newline.
- while (m_ch != '\n') {
- if (! (m_ch == ' ' || m_ch == '\t' || m_ch == '\r')) {
+ while (m_ch != '\n')
+ {
+ if (!(m_ch == ' ' || m_ch == '\t' || m_ch == '\r'))
+ {
Error("Malformed quoted printable string");
}
+
GetNextChar();
}
+
continue; // continue with the first character on the next line
}
- else {
+ else
+ {
int byte = 0;
- if (m_ch >= '0' && m_ch <= '9') byte = m_ch - '0';
- else if (m_ch >= 'A' && m_ch <= 'F') byte = m_ch - 'A' + 10;
- else if (m_ch >= 'a' && m_ch <= 'f') byte = m_ch - 'a' + 10;
- else Error("Malformed quoted printable string");
+
+ if (m_ch >= '0' && m_ch <= '9')
+ {
+ byte = m_ch - '0';
+ }
+ else if (m_ch >= 'A' && m_ch <= 'F')
+ {
+ byte = m_ch - 'A' + 10;
+ }
+ else if (m_ch >= 'a' && m_ch <= 'f')
+ {
+ byte = m_ch - 'a' + 10;
+ }
+ else
+ {
+ Error("Malformed quoted printable string");
+ }
+
byte *= 16;
GetNextChar();
- if (m_ch >= '0' && m_ch <= '9') byte += m_ch - '0';
- else if (m_ch >= 'A' && m_ch <= 'F') byte += m_ch - 'A' + 10;
- else if (m_ch >= 'a' && m_ch <= 'f') byte += m_ch - 'a' + 10;
- else Error("Malformed quoted printable string");
+
+ if (m_ch >= '0' && m_ch <= '9')
+ {
+ byte += m_ch - '0';
+ }
+ else if (m_ch >= 'A' && m_ch <= 'F')
+ {
+ byte += m_ch - 'A' + 10;
+ }
+ else if (m_ch >= 'a' && m_ch <= 'f')
+ {
+ byte += m_ch - 'a' + 10;
+ }
+ else
+ {
+ Error("Malformed quoted printable string");
+ }
+
m_ch = byte; // Put this into the string.
}
}
+
// We grow the buffer to the largest string in the input.
- unsigned char *str = (unsigned char*)realloc(m_String, m_nStringLength+2);
- if (str == NULL) Error("Insufficient memory");
+ unsigned char *str = (unsigned char *)realloc(m_String, m_nStringLength + 2);
+
+ if (str == NULL)
+ {
+ Error("Insufficient memory");
+ }
+
m_String = str;
m_String[m_nStringLength++] = m_ch;
}
+
GetNextChar(); // Skip the closing quote
m_String[m_nStringLength] = 0;
return;
}
- case '`': // Start of a string using base 64
- // These can, presumably span lines.
- MHERROR("Base 64 string is not implemented");
- break;
+ case '`': // Start of a string using base 64
+ // These can, presumably span lines.
+ MHERROR("Base 64 string is not implemented");
+ break;
- case '#': // Start of 3-byte hex constant.
- MHERROR("3-byte hex constant is not implemented");
- break;
+ case '#': // Start of 3-byte hex constant.
+ MHERROR("3-byte hex constant is not implemented");
+ break;
- case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
+ case '-':
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
{
m_nType = PTInt;
bool negative = m_ch == '-';
- if (negative) {
+
+ if (negative)
+ {
GetNextChar();
- if (m_ch < '0' || m_ch > '9') Error("Expected digit after '-'");
+
+ if (m_ch < '0' || m_ch > '9')
+ {
+ Error("Expected digit after '-'");
+ }
}
+
// Start of a number. Hex can be represented as 0xn.
// Strictly speaking hex values cannot be preceded by a minus sign.
m_nInt = m_ch - '0';
GetNextChar();
- if (m_nInt == 0 && (m_ch == 'x' || m_ch == 'X')) {
+
+ if (m_nInt == 0 && (m_ch == 'x' || m_ch == 'X'))
+ {
MHERROR("Hex constant is not implemented");
}
- while (m_ch >= '0' && m_ch <= '9') {
+
+ while (m_ch >= '0' && m_ch <= '9')
+ {
m_nInt = m_nInt * 10 + m_ch - '0';
// TODO: What about overflow?
GetNextChar();
}
- if (negative) m_nInt = -m_nInt;
+
+ if (negative)
+ {
+ m_nInt = -m_nInt;
+ }
+
return;
}
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j':
- case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't':
- case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J':
- case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T':
- case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
- { // Start of an enumerated type.
+ case 'a':
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'e':
+ case 'f':
+ case 'g':
+ case 'h':
+ case 'i':
+ case 'j':
+ case 'k':
+ case 'l':
+ case 'm':
+ case 'n':
+ case 'o':
+ case 'p':
+ case 'q':
+ case 'r':
+ case 's':
+ case 't':
+ case 'u':
+ case 'v':
+ case 'w':
+ case 'x':
+ case 'y':
+ case 'z':
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'E':
+ case 'F':
+ case 'G':
+ case 'H':
+ case 'I':
+ case 'J':
+ case 'K':
+ case 'L':
+ case 'M':
+ case 'N':
+ case 'O':
+ case 'P':
+ case 'Q':
+ case 'R':
+ case 'S':
+ case 'T':
+ case 'U':
+ case 'V':
+ case 'W':
+ case 'X':
+ case 'Y':
+ case 'Z':
+ {
+ // Start of an enumerated type.
m_nType = PTEnum;
char buff[MAX_ENUM+1];
char *p = buff;
- do {
+
+ do
+ {
*p++ = m_ch;
GetNextChar();
- if (p == buff+MAX_ENUM) break;
+
+ if (p == buff + MAX_ENUM)
+ {
+ break;
+ }
}
while ((m_ch >= 'a' && m_ch <= 'z') || (m_ch >= 'A' && m_ch <= 'Z') || m_ch == '-');
+
*p = '\0';
- if (stricmp(buff, "NULL") == 0) { m_nType = PTNull; return; }
- if (stricmp(buff, "true") == 0) { m_nType = PTBool; m_fBool = true; return; }
- if (stricmp(buff, "false") == 0) { m_nType = PTBool; m_fBool = false; return; }
+
+ if (stricmp(buff, "NULL") == 0)
+ {
+ m_nType = PTNull;
+ return;
+ }
+
+ if (stricmp(buff, "true") == 0)
+ {
+ m_nType = PTBool;
+ m_fBool = true;
+ return;
+ }
+
+ if (stricmp(buff, "false") == 0)
+ {
+ m_nType = PTBool;
+ m_fBool = false;
+ return;
+ }
+
// Look up the tag in all the tables. Fortunately all the enumerations
// are distinct so we don't need to know the context.
m_nInt = MHLink::GetEventType(buff);
- if (m_nInt > 0) return;
+
+ if (m_nInt > 0)
+ {
+ return;
+ }
+
m_nInt = MHText::GetJustification(buff);
- if (m_nInt > 0) return;
+
+ if (m_nInt > 0)
+ {
+ return;
+ }
+
m_nInt = MHText::GetLineOrientation(buff);
- if (m_nInt > 0) return;
+
+ if (m_nInt > 0)
+ {
+ return;
+ }
+
m_nInt = MHText::GetStartCorner(buff);
- if (m_nInt > 0) return;
+
+ if (m_nInt > 0)
+ {
+ return;
+ }
+
m_nInt = MHSlider::GetOrientation(buff);
- if (m_nInt > 0) return;
+
+ if (m_nInt > 0)
+ {
+ return;
+ }
+
m_nInt = MHSlider::GetStyle(buff);
- if (m_nInt > 0) return;
+
+ if (m_nInt > 0)
+ {
+ return;
+ }
// Check the colour table. If it's there generate a string containing the colour info.
- for (int i = 0; i < (int)(sizeof(colourTable)/sizeof(colourTable[0])); i++) {
- if (stricmp(buff, colourTable[i].name) == 0) {
+ for (int i = 0; i < (int)(sizeof(colourTable) / sizeof(colourTable[0])); i++)
+ {
+ if (stricmp(buff, colourTable[i].name) == 0)
+ {
m_nType = PTString;
- unsigned char *str = (unsigned char*)realloc(m_String, 4+1);
- if (str == NULL) Error("Insufficient memory");
+ unsigned char *str = (unsigned char *)realloc(m_String, 4 + 1);
+
+ if (str == NULL)
+ {
+ Error("Insufficient memory");
+ }
+
m_String[0] = colourTable[i].r;
m_String[1] = colourTable[i].g;
m_String[2] = colourTable[i].b;
@@ -561,35 +814,35 @@ void MHParseText::NextSym()
break;
}
- case '{': // Start of a "section".
- // The standard indicates that open brace followed by a tag should be written
- // as a single word. We'll be more lenient and allow spaces or comments between them.
- m_nType = PTStartSection;
- GetNextChar();
- return;
-
- case '}': // End of a "section".
- m_nType = PTEndSection;
- GetNextChar();
- return;
-
- case '(': // Start of a sequence.
- m_nType = PTStartSeq;
- GetNextChar();
- return;
-
- case ')': // End of a sequence.
- m_nType = PTEndSeq;
- GetNextChar();
- return;
-
- case EOF:
- m_nType = PTEOF;
- return;
-
- default:
- Error("Unknown character");
- GetNextChar();
+ case '{': // Start of a "section".
+ // The standard indicates that open brace followed by a tag should be written
+ // as a single word. We'll be more lenient and allow spaces or comments between them.
+ m_nType = PTStartSection;
+ GetNextChar();
+ return;
+
+ case '}': // End of a "section".
+ m_nType = PTEndSection;
+ GetNextChar();
+ return;
+
+ case '(': // Start of a sequence.
+ m_nType = PTStartSeq;
+ GetNextChar();
+ return;
+
+ case ')': // End of a sequence.
+ m_nType = PTEndSeq;
+ GetNextChar();
+ return;
+
+ case EOF:
+ m_nType = PTEOF;
+ return;
+
+ default:
+ Error("Unknown character");
+ GetNextChar();
}
}
}
@@ -597,194 +850,220 @@ void MHParseText::NextSym()
MHParseNode *MHParseText::DoParse()
{
MHParseNode *pRes = NULL;
- try {
- switch (m_nType) {
- case PTStartSection: // Open curly bracket
+
+ try
+ {
+ switch (m_nType)
+ {
+ case PTStartSection: // Open curly bracket
{
NextSym();
+
// Should be followed by a tag.
- if (m_nType != PTTag) Error("Expected ':' after '{'");
+ if (m_nType != PTTag)
+ {
+ Error("Expected ':' after '{'");
+ }
+
MHPTagged *pTag = new MHPTagged(m_nTag);
pRes = pTag;
NextSym();
- while (m_nType != PTEndSection) {
+
+ while (m_nType != PTEndSection)
+ {
pTag->AddArg(DoParse());
}
+
NextSym(); // Remove the close curly bracket.
break;
}
- case PTTag: // Tag on its own.
+ case PTTag: // Tag on its own.
{
int nTag = m_nTag;
MHPTagged *pTag = new MHPTagged(nTag);
pRes = pTag;
NextSym();
- switch (nTag) {
- case C_ITEMS:
- case C_LINK_EFFECT:
- case C_ACTIVATE:
- case C_ADD:
- case C_ADD_ITEM:
- case C_APPEND:
- case C_BRING_TO_FRONT:
- case C_CALL:
- case C_CALL_ACTION_SLOT:
- case C_CLEAR:
- case C_CLONE:
- case C_CLOSE_CONNECTION:
- case C_DEACTIVATE:
- case C_DEL_ITEM:
- case C_DESELECT:
- case C_DESELECT_ITEM:
- case C_DIVIDE:
- case C_DRAW_ARC:
- case C_DRAW_LINE:
- case C_DRAW_OVAL:
- case C_DRAW_POLYGON:
- case C_DRAW_POLYLINE:
- case C_DRAW_RECTANGLE:
- case C_DRAW_SECTOR:
- case C_FORK:
- case C_GET_AVAILABILITY_STATUS:
- case C_GET_BOX_SIZE:
- case C_GET_CELL_ITEM:
- case C_GET_CURSOR_POSITION:
- case C_GET_ENGINE_SUPPORT:
- case C_GET_ENTRY_POINT:
- case C_GET_FILL_COLOUR:
- case C_GET_FIRST_ITEM:
- case C_GET_HIGHLIGHT_STATUS:
- case C_GET_INTERACTION_STATUS:
- case C_GET_ITEM_STATUS:
- case C_GET_LABEL:
- case C_GET_LAST_ANCHOR_FIRED:
- case C_GET_LINE_COLOUR:
- case C_GET_LINE_STYLE:
- case C_GET_LINE_WIDTH:
- case C_GET_LIST_ITEM:
- case C_GET_LIST_SIZE:
- case C_GET_OVERWRITE_MODE:
- case C_GET_PORTION:
- case C_GET_POSITION:
- case C_GET_RUNNING_STATUS:
- case C_GET_SELECTION_STATUS:
- case C_GET_SLIDER_VALUE:
- case C_GET_TEXT_CONTENT:
- case C_GET_TEXT_DATA:
- case C_GET_TOKEN_POSITION:
- case C_GET_VOLUME:
- case C_LAUNCH:
- case C_LOCK_SCREEN:
- case C_MODULO:
- case C_MOVE:
- case C_MOVE_TO:
- case C_MULTIPLY:
- case C_OPEN_CONNECTION:
- case C_PRELOAD:
- case C_PUT_BEFORE:
- case C_PUT_BEHIND:
- case C_QUIT:
- case C_READ_PERSISTENT:
- case C_RUN:
- case C_SCALE_BITMAP:
- case C_SCALE_VIDEO:
- case C_SCROLL_ITEMS:
- case C_SELECT:
- case C_SELECT_ITEM:
- case C_SEND_EVENT:
- case C_SEND_TO_BACK:
- case C_SET_BOX_SIZE:
- case C_SET_CACHE_PRIORITY:
- case C_SET_COUNTER_END_POSITION:
- case C_SET_COUNTER_POSITION:
- case C_SET_COUNTER_TRIGGER:
- case C_SET_CURSOR_POSITION:
- case C_SET_CURSOR_SHAPE:
- case C_SET_DATA:
- case C_SET_ENTRY_POINT:
- case C_SET_FILL_COLOUR:
- case C_SET_FIRST_ITEM:
- case C_SET_FONT_REF:
- case C_SET_HIGHLIGHT_STATUS:
- case C_SET_INTERACTION_STATUS:
- case C_SET_LABEL:
- case C_SET_LINE_COLOUR:
- case C_SET_LINE_STYLE:
- case C_SET_LINE_WIDTH:
- case C_SET_OVERWRITE_MODE:
- case C_SET_PALETTE_REF:
- case C_SET_PORTION:
- case C_SET_POSITION:
- case C_SET_SLIDER_VALUE:
- case C_SET_SPEED:
- case C_SET_TIMER:
- case C_SET_TRANSPARENCY:
- case C_SET_VARIABLE:
- case C_SET_VOLUME:
- case C_SPAWN:
- case C_STEP:
- case C_STOP:
- case C_STORE_PERSISTENT:
- case C_SUBTRACT:
- case C_TEST_VARIABLE:
- case C_TOGGLE:
- case C_TOGGLE_ITEM:
- case C_TRANSITION_TO:
- case C_UNLOAD:
- case C_UNLOCK_SCREEN:
- case C_CONTENT_REFERENCE:
- case C_TOKEN_GROUP_ITEMS:
- case C_POSITIONS:
- case C_MULTIPLEX:
- { // These are parenthesised in the text form. We have to remove the
+
+ switch (nTag)
+ {
+ case C_ITEMS:
+ case C_LINK_EFFECT:
+ case C_ACTIVATE:
+ case C_ADD:
+ case C_ADD_ITEM:
+ case C_APPEND:
+ case C_BRING_TO_FRONT:
+ case C_CALL:
+ case C_CALL_ACTION_SLOT:
+ case C_CLEAR:
+ case C_CLONE:
+ case C_CLOSE_CONNECTION:
+ case C_DEACTIVATE:
+ case C_DEL_ITEM:
+ case C_DESELECT:
+ case C_DESELECT_ITEM:
+ case C_DIVIDE:
+ case C_DRAW_ARC:
+ case C_DRAW_LINE:
+ case C_DRAW_OVAL:
+ case C_DRAW_POLYGON:
+ case C_DRAW_POLYLINE:
+ case C_DRAW_RECTANGLE:
+ case C_DRAW_SECTOR:
+ case C_FORK:
+ case C_GET_AVAILABILITY_STATUS:
+ case C_GET_BOX_SIZE:
+ case C_GET_CELL_ITEM:
+ case C_GET_CURSOR_POSITION:
+ case C_GET_ENGINE_SUPPORT:
+ case C_GET_ENTRY_POINT:
+ case C_GET_FILL_COLOUR:
+ case C_GET_FIRST_ITEM:
+ case C_GET_HIGHLIGHT_STATUS:
+ case C_GET_INTERACTION_STATUS:
+ case C_GET_ITEM_STATUS:
+ case C_GET_LABEL:
+ case C_GET_LAST_ANCHOR_FIRED:
+ case C_GET_LINE_COLOUR:
+ case C_GET_LINE_STYLE:
+ case C_GET_LINE_WIDTH:
+ case C_GET_LIST_ITEM:
+ case C_GET_LIST_SIZE:
+ case C_GET_OVERWRITE_MODE:
+ case C_GET_PORTION:
+ case C_GET_POSITION:
+ case C_GET_RUNNING_STATUS:
+ case C_GET_SELECTION_STATUS:
+ case C_GET_SLIDER_VALUE:
+ case C_GET_TEXT_CONTENT:
+ case C_GET_TEXT_DATA:
+ case C_GET_TOKEN_POSITION:
+ case C_GET_VOLUME:
+ case C_LAUNCH:
+ case C_LOCK_SCREEN:
+ case C_MODULO:
+ case C_MOVE:
+ case C_MOVE_TO:
+ case C_MULTIPLY:
+ case C_OPEN_CONNECTION:
+ case C_PRELOAD:
+ case C_PUT_BEFORE:
+ case C_PUT_BEHIND:
+ case C_QUIT:
+ case C_READ_PERSISTENT:
+ case C_RUN:
+ case C_SCALE_BITMAP:
+ case C_SCALE_VIDEO:
+ case C_SCROLL_ITEMS:
+ case C_SELECT:
+ case C_SELECT_ITEM:
+ case C_SEND_EVENT:
+ case C_SEND_TO_BACK:
+ case C_SET_BOX_SIZE:
+ case C_SET_CACHE_PRIORITY:
+ case C_SET_COUNTER_END_POSITION:
+ case C_SET_COUNTER_POSITION:
+ case C_SET_COUNTER_TRIGGER:
+ case C_SET_CURSOR_POSITION:
+ case C_SET_CURSOR_SHAPE:
+ case C_SET_DATA:
+ case C_SET_ENTRY_POINT:
+ case C_SET_FILL_COLOUR:
+ case C_SET_FIRST_ITEM:
+ case C_SET_FONT_REF:
+ case C_SET_HIGHLIGHT_STATUS:
+ case C_SET_INTERACTION_STATUS:
+ case C_SET_LABEL:
+ case C_SET_LINE_COLOUR:
+ case C_SET_LINE_STYLE:
+ case C_SET_LINE_WIDTH:
+ case C_SET_OVERWRITE_MODE:
+ case C_SET_PALETTE_REF:
+ case C_SET_PORTION:
+ case C_SET_POSITION:
+ case C_SET_SLIDER_VALUE:
+ case C_SET_SPEED:
+ case C_SET_TIMER:
+ case C_SET_TRANSPARENCY:
+ case C_SET_VARIABLE:
+ case C_SET_VOLUME:
+ case C_SPAWN:
+ case C_STEP:
+ case C_STOP:
+ case C_STORE_PERSISTENT:
+ case C_SUBTRACT:
+ case C_TEST_VARIABLE:
+ case C_TOGGLE:
+ case C_TOGGLE_ITEM:
+ case C_TRANSITION_TO:
+ case C_UNLOAD:
+ case C_UNLOCK_SCREEN:
+ case C_CONTENT_REFERENCE:
+ case C_TOKEN_GROUP_ITEMS:
+ case C_POSITIONS:
+ case C_MULTIPLEX:
+ {
+ // These are parenthesised in the text form. We have to remove the
// parentheses otherwise we will return a sequence which will not be
// be compatible with the binary form.
- if (m_nType != PTStartSeq) Error("Expected '('");
+ if (m_nType != PTStartSeq)
+ {
+ Error("Expected '('");
+ }
+
NextSym();
- while (m_nType != PTEndSeq) pTag->AddArg(DoParse());
+
+ while (m_nType != PTEndSeq)
+ {
+ pTag->AddArg(DoParse());
+ }
+
NextSym(); // Remove the close parenthesis.
break;
}
- case C_ORIGINAL_CONTENT:
- case C_NEW_GENERIC_BOOLEAN:
- case C_NEW_GENERIC_INTEGER:
- case C_NEW_GENERIC_OCTETSTRING:
- case C_NEW_GENERIC_OBJECT_REF:
- case C_NEW_GENERIC_CONTENT_REF:
- case C_ORIGINAL_VALUE:
- // These always have an argument which may be a tagged item.
+ case C_ORIGINAL_CONTENT:
+ case C_NEW_GENERIC_BOOLEAN:
+ case C_NEW_GENERIC_INTEGER:
+ case C_NEW_GENERIC_OCTETSTRING:
+ case C_NEW_GENERIC_OBJECT_REF:
+ case C_NEW_GENERIC_CONTENT_REF:
+ case C_ORIGINAL_VALUE:
+ // These always have an argument which may be a tagged item.
{
// Is it always the case that there is at least one argument so if we haven't
// had any arguments yet we should always process a tag as an argument?
pTag->AddArg(DoParse());
break;
}
- default:
- // This can be followed by an int, etc but a new tag is dealt with by the caller.
- while (m_nType == PTBool ||m_nType == PTInt || m_nType == PTString || m_nType == PTEnum || m_nType == PTStartSeq) {
- pTag->AddArg(DoParse());
- }
+ default:
+
+ // This can be followed by an int, etc but a new tag is dealt with by the caller.
+ while (m_nType == PTBool || m_nType == PTInt || m_nType == PTString || m_nType == PTEnum || m_nType == PTStartSeq)
+ {
+ pTag->AddArg(DoParse());
+ }
}
+
break;
}
- case PTInt:
+ case PTInt:
{
pRes = new MHPInt(m_nInt);
NextSym();
break;
}
- case PTBool:
+ case PTBool:
{
pRes = new MHPBool(m_fBool);
NextSym();
break;
}
- case PTString:
+ case PTString:
{
MHOctetString str;
str.Copy(MHOctetString((const char *)m_String, m_nStringLength));
@@ -793,36 +1072,43 @@ MHParseNode *MHParseText::DoParse()
break;
}
- case PTEnum:
+ case PTEnum:
{
pRes = new MHPEnum(m_nInt);
NextSym();
break;
}
- case PTNull:
+ case PTNull:
{
pRes = new MHPNull;
NextSym();
break;
}
- case PTStartSeq: // Open parenthesis.
+ case PTStartSeq: // Open parenthesis.
{
MHParseSequence *pSeq = new MHParseSequence;
pRes = pSeq;
NextSym();
- while (m_nType != PTEndSeq) pSeq->Append(DoParse());
+
+ while (m_nType != PTEndSeq)
+ {
+ pSeq->Append(DoParse());
+ }
+
NextSym(); // Remove the close parenthesis.
break;
}
- default:
- Error("Unexpected symbol");
+ default:
+ Error("Unexpected symbol");
}
+
return pRes;
}
- catch (...) {
+ catch (...)
+ {
delete(pRes);
throw;
}
diff --git a/mythtv/libs/libmythfreemheg/ParseText.h b/mythtv/libs/libmythfreemheg/ParseText.h
index d8dc548b96c..6048f17298b 100644
--- a/mythtv/libs/libmythfreemheg/ParseText.h
+++ b/mythtv/libs/libmythfreemheg/ParseText.h
@@ -29,14 +29,14 @@ class MHGroup;
class MHParseText: public MHParseBase
{
-public:
+ public:
MHParseText(QByteArray &program);
virtual ~MHParseText();
// Parse the text and return a pointer to the parse tree
virtual MHParseNode *Parse();
-private:
+ private:
void GetNextChar();
void NextSym();
MHParseNode *DoParse();
diff --git a/mythtv/libs/libmythfreemheg/Presentable.cpp b/mythtv/libs/libmythfreemheg/Presentable.cpp
index a5f868e9a82..62990d6346d 100644
--- a/mythtv/libs/libmythfreemheg/Presentable.cpp
+++ b/mythtv/libs/libmythfreemheg/Presentable.cpp
@@ -26,10 +26,16 @@
void MHPresentable::Run(MHEngine *engine)
{
- if (! m_fRunning) Activation(engine);
+ if (! m_fRunning)
+ {
+ Activation(engine);
+ }
}
void MHPresentable::Stop(MHEngine *engine)
{
- if (m_fRunning) Deactivation(engine);
+ if (m_fRunning)
+ {
+ Deactivation(engine);
+ }
}
diff --git a/mythtv/libs/libmythfreemheg/Presentable.h b/mythtv/libs/libmythfreemheg/Presentable.h
index c08e4ed85d4..faa48699021 100644
--- a/mythtv/libs/libmythfreemheg/Presentable.h
+++ b/mythtv/libs/libmythfreemheg/Presentable.h
@@ -33,7 +33,7 @@
class MHPresentable : public MHIngredient
{
-public:
+ public:
MHPresentable() {}
MHPresentable(const MHPresentable &ref): MHIngredient(ref) {}
// No new components.
@@ -51,14 +51,14 @@ class MHPresentable : public MHIngredient
// Run and stop actions.
class MHRun: public MHElemAction
{
-public:
+ public:
MHRun(): MHElemAction(":Run") {}
virtual void Perform(MHEngine *engine) { Target(engine)->Run(engine); }
};
class MHStop: public MHElemAction
{
-public:
+ public:
MHStop(): MHElemAction(":Stop") {}
virtual void Perform(MHEngine *engine) { Target(engine)->Stop(engine); }
};
diff --git a/mythtv/libs/libmythfreemheg/Programs.cpp b/mythtv/libs/libmythfreemheg/Programs.cpp
index c911c731203..a87a777009a 100644
--- a/mythtv/libs/libmythfreemheg/Programs.cpp
+++ b/mythtv/libs/libmythfreemheg/Programs.cpp
@@ -30,8 +30,8 @@
#include "freemheg.h"
#include
-#ifdef __FreeBSD__
-#include
+#ifdef __FreeBSD__
+#include
#else
#include
#endif
@@ -55,10 +55,19 @@ void MHProgram::Initialise(MHParseNode *p, MHEngine *engine)
{
MHIngredient::Initialise(p, engine);
MHParseNode *pCmdNode = p->GetNamedArg(C_NAME);
- if (pCmdNode) pCmdNode->GetArgN(0)->GetStringValue(m_Name); // Program name
+
+ if (pCmdNode)
+ {
+ pCmdNode->GetArgN(0)->GetStringValue(m_Name); // Program name
+ }
MHParseNode *pAvail = p->GetNamedArg(C_INITIALLY_AVAILABLE);
- if (pAvail) m_fInitiallyAvailable = pAvail->GetArgN(0)->GetBoolValue();
+
+ if (pAvail)
+ {
+ m_fInitiallyAvailable = pAvail->GetArgN(0)->GetBoolValue();
+ }
+
// The MHEG Standard says that InitiallyAvailable is mandatory and should be false.
// That doesn't seem to be the case in some MHEG programs so we force it here.
m_fInitiallyActive = false;
@@ -67,14 +76,27 @@ void MHProgram::Initialise(MHParseNode *p, MHEngine *engine)
void MHProgram::PrintMe(FILE *fd, int nTabs) const
{
MHIngredient::PrintMe(fd, nTabs);
- PrintTabs(fd, nTabs); fprintf(fd, ":Name "); m_Name.PrintMe(fd, 0); fprintf(fd, "\n");
- if (! m_fInitiallyAvailable) { PrintTabs(fd, nTabs); fprintf(fd, ":InitiallyAvailable false"); fprintf(fd, "\n"); }
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":Name ");
+ m_Name.PrintMe(fd, 0);
+ fprintf(fd, "\n");
+
+ if (! m_fInitiallyAvailable)
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":InitiallyAvailable false");
+ fprintf(fd, "\n");
+ }
}
// Set "running" and generate an IsRunning event.
void MHProgram::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHIngredient::Activation(engine);
m_fRunning = true;
engine->EventTriggered(this, EventIsRunning);
@@ -83,16 +105,22 @@ void MHProgram::Activation(MHEngine *engine)
// This can be called if we change scene while a forked program is running
void MHProgram::Deactivation(MHEngine *engine)
{
- if (! m_fRunning) return;
+ if (! m_fRunning)
+ {
+ return;
+ }
+
// TODO: Stop the forked program.
MHIngredient::Deactivation(engine);
}
void MHResidentProgram::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:ResidentPrg ");
- MHProgram::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:ResidentPrg ");
+ MHProgram::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
static void SetSuccessFlag(const MHObjectRef &success, bool result, MHEngine *engine)
@@ -120,28 +148,39 @@ static void GetString(MHParameter *parm, MHOctetString &str, MHEngine *engine)
void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, const MHSequence &args, MHEngine *engine)
{
- if (! m_fAvailable) Preparation(engine);
-// if (m_fRunning) return; // Strictly speaking there should be only one instance of a program running at a time.
+ if (! m_fAvailable)
+ {
+ Preparation(engine);
+ }
+
+ // if (m_fRunning) return; // Strictly speaking there should be only one instance of a program running at a time.
Activation(engine);
MHLOG(MHLogDetail, QString("Calling program %1").arg(m_Name.Printable()));
- try {
+
+ try
+ {
// Run the code.
- if (m_Name.Equal("GCD")) { // GetCurrentDate - returns local time.
- if (args.Size() == 2) {
+ if (m_Name.Equal("GCD")) // GetCurrentDate - returns local time.
+ {
+ if (args.Size() == 2)
+ {
struct timeb timebuffer;
#if HAVE_FTIME
ftime(&timebuffer);
#elif HAVE_GETTIMEOFDAY
- struct timeval time;
+ struct timeval time;
struct timezone zone;
- if (gettimeofday(&time,&zone) == -1)
+ if (gettimeofday(&time, &zone) == -1)
+ {
MHLOG(MHLogDetail, QString("gettimeofday() failed"));
+ }
+
timebuffer.time = time.tv_sec;
timebuffer.timezone = zone.tz_minuteswest;
timebuffer.dstflag = zone.tz_dsttime;
#else
- #error Configuration error? No ftime() or gettimeofday()?
+#error Configuration error? No ftime() or gettimeofday()?
#endif
// Adjust the time to local. TODO: Check this.
timebuffer.time -= timebuffer.timezone * 60;
@@ -155,11 +194,16 @@ void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, co
engine->FindObject(*(args.GetAt(1)->GetReference()))->SetVariableValue(nTimeAsSecs);
SetSuccessFlag(success, true, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("FDa")) { // FormatDate
- if (args.Size() == 4) {
+ else if (m_Name.Equal("FDa")) // FormatDate
+ {
+ if (args.Size() == 4)
+ {
// This is a bit like strftime but not quite.
MHOctetString format;
GetString(args.GetAt(0), format, engine);
@@ -169,54 +213,138 @@ void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, co
time_t timet = (date - 40587) * (24 * 60 * 60) + time;
struct tm *timeStr = gmtime(&timet);
MHOctetString result;
- for (int i = 0; i < format.Size(); i++) {
+
+ for (int i = 0; i < format.Size(); i++)
+ {
unsigned char ch = format.GetAt(i);
char buffer[5]; // Largest text is 4 chars for a year + null terminator
- if (ch == '%') {
+
+ if (ch == '%')
+ {
i++;
- if (i == format.Size()) break;
+
+ if (i == format.Size())
+ {
+ break;
+ }
+
ch = format.GetAt(i);
buffer[0] = 0;
+
switch (ch)
{
- case 'Y': sprintf(buffer, "%04d", timeStr->tm_year + 1900); break;
- case 'y': sprintf(buffer, "%02d", timeStr->tm_year % 100); break;
- case 'X': sprintf(buffer, "%02d", timeStr->tm_mon+1); break;
- case 'x': sprintf(buffer, "%1d", timeStr->tm_mon+1); break;
- case 'D': sprintf(buffer, "%02d", timeStr->tm_mday); break;
- case 'd': sprintf(buffer, "%1d", timeStr->tm_mday); break;
- case 'H': sprintf(buffer, "%02d", timeStr->tm_hour); break;
- case 'h': sprintf(buffer, "%1d", timeStr->tm_hour); break;
- case 'I':
- if (timeStr->tm_hour == 12 || timeStr->tm_hour == 0) strcpy(buffer, "12");
- else sprintf(buffer, "%02d", timeStr->tm_hour % 12);
- break;
- case 'i':
- if (timeStr->tm_hour == 12 || timeStr->tm_hour == 0) strcpy(buffer, "12");
- else sprintf(buffer, "%1d", timeStr->tm_hour % 12);
- break;
- case 'M': sprintf(buffer, "%02d", timeStr->tm_min); break;
- case 'm': sprintf(buffer, "%1d", timeStr->tm_min); break;
- case 'S': sprintf(buffer, "%02d", timeStr->tm_sec); break;
- case 's': sprintf(buffer, "%1d", timeStr->tm_sec); break;
- // TODO: These really should be localised.
- case 'A': if (timeStr->tm_hour < 12) strcpy(buffer, "AM"); else strcpy(buffer, "PM"); break;
- case 'a': if (timeStr->tm_hour < 12) strcpy(buffer, "am"); else strcpy(buffer, "pm"); break;
- default: buffer[0] = ch; buffer[1] = 0;
+ case 'Y':
+ sprintf(buffer, "%04d", timeStr->tm_year + 1900);
+ break;
+ case 'y':
+ sprintf(buffer, "%02d", timeStr->tm_year % 100);
+ break;
+ case 'X':
+ sprintf(buffer, "%02d", timeStr->tm_mon + 1);
+ break;
+ case 'x':
+ sprintf(buffer, "%1d", timeStr->tm_mon + 1);
+ break;
+ case 'D':
+ sprintf(buffer, "%02d", timeStr->tm_mday);
+ break;
+ case 'd':
+ sprintf(buffer, "%1d", timeStr->tm_mday);
+ break;
+ case 'H':
+ sprintf(buffer, "%02d", timeStr->tm_hour);
+ break;
+ case 'h':
+ sprintf(buffer, "%1d", timeStr->tm_hour);
+ break;
+ case 'I':
+
+ if (timeStr->tm_hour == 12 || timeStr->tm_hour == 0)
+ {
+ strcpy(buffer, "12");
+ }
+ else
+ {
+ sprintf(buffer, "%02d", timeStr->tm_hour % 12);
+ }
+
+ break;
+ case 'i':
+
+ if (timeStr->tm_hour == 12 || timeStr->tm_hour == 0)
+ {
+ strcpy(buffer, "12");
+ }
+ else
+ {
+ sprintf(buffer, "%1d", timeStr->tm_hour % 12);
+ }
+
+ break;
+ case 'M':
+ sprintf(buffer, "%02d", timeStr->tm_min);
+ break;
+ case 'm':
+ sprintf(buffer, "%1d", timeStr->tm_min);
+ break;
+ case 'S':
+ sprintf(buffer, "%02d", timeStr->tm_sec);
+ break;
+ case 's':
+ sprintf(buffer, "%1d", timeStr->tm_sec);
+ break;
+ // TODO: These really should be localised.
+ case 'A':
+
+ if (timeStr->tm_hour < 12)
+ {
+ strcpy(buffer, "AM");
+ }
+ else
+ {
+ strcpy(buffer, "PM");
+ }
+
+ break;
+ case 'a':
+
+ if (timeStr->tm_hour < 12)
+ {
+ strcpy(buffer, "am");
+ }
+ else
+ {
+ strcpy(buffer, "pm");
+ }
+
+ break;
+ default:
+ buffer[0] = ch;
+ buffer[1] = 0;
}
+
result.Append(buffer);
}
- else result.Append(MHOctetString(&ch, 1));
+ else
+ {
+ result.Append(MHOctetString(&ch, 1));
+ }
}
+
MHParameter *pResString = args.GetAt(3);
engine->FindObject(*(pResString->GetReference()))->SetVariableValue(result);
SetSuccessFlag(success, true, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("GDW")) { // GetDayOfWeek - returns the day of week that the date occurred on.
- if (args.Size() == 2) {
+ else if (m_Name.Equal("GDW")) // GetDayOfWeek - returns the day of week that the date occurred on.
+ {
+ if (args.Size() == 2)
+ {
int date = GetInt(args.GetAt(0), engine); // Date as produced in GCD
// Convert to a Unix date (secs since 1st Jan 1970) but adjusted for time zone.
time_t timet = (date - 40587) * (24 * 60 * 60);
@@ -224,23 +352,34 @@ void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, co
// 0 => Sunday, 1 => Monday etc.
engine->FindObject(*(args.GetAt(1)->GetReference()))->SetVariableValue(timeStr->tm_wday);
SetSuccessFlag(success, true, engine);
- } else SetSuccessFlag(success, false, engine);
+ }
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("Rnd")) { // Random
- if (args.Size() == 2) {
+ else if (m_Name.Equal("Rnd")) // Random
+ {
+ if (args.Size() == 2)
+ {
int nLimit = GetInt(args.GetAt(0), engine);
MHParameter *pResInt = args.GetAt(1);
- srand((unsigned)time( NULL ));
- engine->FindObject(*(pResInt->GetReference()))->SetVariableValue(rand() % nLimit +1);
+ srand((unsigned)time(NULL));
+ engine->FindObject(*(pResInt->GetReference()))->SetVariableValue(rand() % nLimit + 1);
SetSuccessFlag(success, true, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("CTC")) { // CastToContentRef
+ else if (m_Name.Equal("CTC")) // CastToContentRef
+ {
// Converts a string to a ContentRef.
- if (args.Size() == 2) {
+ if (args.Size() == 2)
+ {
MHOctetString string;
GetString(args.GetAt(0), string, engine);
MHContentRef result;
@@ -248,23 +387,33 @@ void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, co
engine->FindObject(*(args.GetAt(1)->GetReference()))->SetVariableValue(result);
SetSuccessFlag(success, true, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("CTO")) { // CastToObjectRef
+ else if (m_Name.Equal("CTO")) // CastToObjectRef
+ {
// Converts a string and an integer to an ObjectRef.
- if (args.Size() == 3) {
+ if (args.Size() == 3)
+ {
MHObjectRef result;
GetString(args.GetAt(0), result.m_GroupId, engine);
result.m_nObjectNo = GetInt(args.GetAt(1), engine);
engine->FindObject(*(args.GetAt(2)->GetReference()))->SetVariableValue(result);
SetSuccessFlag(success, true, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("GSL")) { // GetStringLength
- if (args.Size() == 2) {
+ else if (m_Name.Equal("GSL")) // GetStringLength
+ {
+ if (args.Size() == 2)
+ {
// Find a substring within a string and return an index to the position.
MHOctetString string;
GetString(args.GetAt(0), string, engine);
@@ -272,99 +421,176 @@ void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, co
SetSuccessFlag(success, true, engine);
engine->FindObject(*(pResInt->GetReference()))->SetVariableValue(string.Size());
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("GSS")) { // GetSubString
- if (args.Size() == 4) { // Extract a sub-string from a string.
+ else if (m_Name.Equal("GSS")) // GetSubString
+ {
+ if (args.Size() == 4) // Extract a sub-string from a string.
+ {
MHOctetString string;
GetString(args.GetAt(0), string, engine);
int nBeginExtract = GetInt(args.GetAt(1), engine);
int nEndExtract = GetInt(args.GetAt(2), engine);
- if (nBeginExtract < 1) nBeginExtract = 1;
- if (nBeginExtract > string.Size()) nBeginExtract = string.Size();
- if (nEndExtract < 1) nEndExtract = 1;
- if (nEndExtract > string.Size()) nEndExtract = string.Size();
+
+ if (nBeginExtract < 1)
+ {
+ nBeginExtract = 1;
+ }
+
+ if (nBeginExtract > string.Size())
+ {
+ nBeginExtract = string.Size();
+ }
+
+ if (nEndExtract < 1)
+ {
+ nEndExtract = 1;
+ }
+
+ if (nEndExtract > string.Size())
+ {
+ nEndExtract = string.Size();
+ }
+
MHParameter *pResString = args.GetAt(3);
// Returns beginExtract to endExtract inclusive.
engine->FindObject(*(pResString->GetReference()))->SetVariableValue(
- MHOctetString(string, nBeginExtract-1, nEndExtract-nBeginExtract+1));
+ MHOctetString(string, nBeginExtract - 1, nEndExtract - nBeginExtract + 1));
SetSuccessFlag(success, true, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("SSS")) { // SearchSubString
- if (args.Size() == 4) {
+ else if (m_Name.Equal("SSS")) // SearchSubString
+ {
+ if (args.Size() == 4)
+ {
// Find a substring within a string and return an index to the position.
MHOctetString string, searchString;
GetString(args.GetAt(0), string, engine);
int nStart = GetInt(args.GetAt(1), engine);
- if (nStart < 1) nStart = 1;
+
+ if (nStart < 1)
+ {
+ nStart = 1;
+ }
+
GetString(args.GetAt(2), searchString, engine);
// Strings are indexed from one.
int nPos;
- for (nPos = nStart-1; nPos <= string.Size() - searchString.Size(); nPos++) {
+
+ for (nPos = nStart - 1; nPos <= string.Size() - searchString.Size(); nPos++)
+ {
int i;
- for (i = 0; i < searchString.Size(); i++) {
- if (searchString.GetAt(i) != string.GetAt(i+nPos)) break;
+
+ for (i = 0; i < searchString.Size(); i++)
+ {
+ if (searchString.GetAt(i) != string.GetAt(i + nPos))
+ {
+ break;
+ }
+ }
+
+ if (i == searchString.Size())
+ {
+ break; // Found a match.
}
- if (i == searchString.Size()) break; // Found a match.
}
+
// Set the result.
MHParameter *pResInt = args.GetAt(3);
SetSuccessFlag(success, true, engine); // Set this first.
- if (nPos <= string.Size() - searchString.Size()) { // Found
+
+ if (nPos <= string.Size() - searchString.Size()) // Found
+ {
// Set the index to the position of the string, counting from 1.
- engine->FindObject(*(pResInt->GetReference()))->SetVariableValue(nPos+1);
+ engine->FindObject(*(pResInt->GetReference()))->SetVariableValue(nPos + 1);
}
- else { // Not found. Set the result index to -1
+ else // Not found. Set the result index to -1
+ {
engine->FindObject(*(pResInt->GetReference()))->SetVariableValue(-1);
}
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("SES")) { // SearchAndExtractSubString
- if (args.Size() == 5) {
+ else if (m_Name.Equal("SES")) // SearchAndExtractSubString
+ {
+ if (args.Size() == 5)
+ {
// Find a substring within a string and return an index to the position
// and the prefix to the substring.
MHOctetString string, searchString;
GetString(args.GetAt(0), string, engine);
int nStart = GetInt(args.GetAt(1), engine);
- if (nStart < 1) nStart = 1;
+
+ if (nStart < 1)
+ {
+ nStart = 1;
+ }
+
GetString(args.GetAt(2), searchString, engine);
// Strings are indexed from one.
int nPos;
- for (nPos = nStart-1; nPos <= string.Size() - searchString.Size(); nPos++) {
+
+ for (nPos = nStart - 1; nPos <= string.Size() - searchString.Size(); nPos++)
+ {
int i;
- for (i = 0; i < searchString.Size(); i++) {
- if (searchString.GetAt(i) != string.GetAt(i+nPos)) break; // Doesn't match
+
+ for (i = 0; i < searchString.Size(); i++)
+ {
+ if (searchString.GetAt(i) != string.GetAt(i + nPos))
+ {
+ break; // Doesn't match
+ }
+ }
+
+ if (i == searchString.Size())
+ {
+ break; // Found a match.
}
- if (i == searchString.Size()) break; // Found a match.
}
+
// Set the results.
MHParameter *pResString = args.GetAt(3);
MHParameter *pResInt = args.GetAt(4);
SetSuccessFlag(success, true, engine); // Set this first.
- if (nPos <= string.Size() - searchString.Size()) { // Found
+
+ if (nPos <= string.Size() - searchString.Size()) // Found
+ {
// Set the index to the position AFTER the string, counting from 1.
- engine->FindObject(*(pResInt->GetReference()))->SetVariableValue(nPos+1+searchString.Size());
+ engine->FindObject(*(pResInt->GetReference()))->SetVariableValue(nPos + 1 + searchString.Size());
// Return the sequence from nStart-1 of length nPos-nStart+1
- MHOctetString resultString(string, nStart-1, nPos-nStart+1);
+ MHOctetString resultString(string, nStart - 1, nPos - nStart + 1);
engine->FindObject(*(pResString->GetReference()))->SetVariableValue(resultString);
}
- else { // Not found. Set the result string to empty and the result index to -1
+ else // Not found. Set the result string to empty and the result index to -1
+ {
engine->FindObject(*(pResInt->GetReference()))->SetVariableValue(-1);
engine->FindObject(*(pResString->GetReference()))->SetVariableValue(MHOctetString(""));
}
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("GSI")) { // SI_GetServiceIndex
+ else if (m_Name.Equal("GSI")) // SI_GetServiceIndex
+ {
// Returns an index indicating the service
- if (args.Size() == 2) {
+ if (args.Size() == 2)
+ {
MHOctetString string;
GetString(args.GetAt(0), string, engine);
MHParameter *pResInt = args.GetAt(1);
@@ -376,38 +602,54 @@ void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, co
engine->FindObject(*(pResInt->GetReference()))->SetVariableValue(nResult);
SetSuccessFlag(success, nResult >= 0, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("TIn")) { // SI_TuneIndex - Fork not allowed
+ else if (m_Name.Equal("TIn")) // SI_TuneIndex - Fork not allowed
+ {
// Tunes to an index returned by GSI
- if (args.Size() == 1) {
+ if (args.Size() == 1)
+ {
int nChannel = GetInt(args.GetAt(0), engine);
bool res = nChannel >= 0 ? engine->GetContext()->TuneTo(
- nChannel, engine->GetTuneInfo()) : false;
+ nChannel, engine->GetTuneInfo()) : false;
SetSuccessFlag(success, res, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("TII")) { // SI_TuneIndexInfo
- // Indicates whether to perform a subsequent TIn quietly or normally.
- if (args.Size() == 1) {
+ else if (m_Name.Equal("TII")) // SI_TuneIndexInfo
+ {
+ // Indicates whether to perform a subsequent TIn quietly or normally.
+ if (args.Size() == 1)
+ {
int tuneinfo = GetInt(args.GetAt(0), engine);
engine->SetTuneInfo(tuneinfo);
SetSuccessFlag(success, true, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("BSI")) { // SI_GetBasicSI
+ else if (m_Name.Equal("BSI")) // SI_GetBasicSI
+ {
// Returns basic SI information about the service indicated by an index
// returned by GSI.
// Returns networkID, origNetworkID, transportStreamID, serviceID
- if (args.Size() == 5) {
+ if (args.Size() == 5)
+ {
int channelId = GetInt(args.GetAt(0), engine);
int netId, origNetId, transportId, serviceId;
// Look the information up in the database.
bool res = engine->GetContext()->GetServiceInfo(channelId, netId, origNetId,
- transportId, serviceId);
+ transportId, serviceId);
+
if (res)
{
engine->FindObject(*(args.GetAt(1)->GetReference()))->SetVariableValue(netId);
@@ -415,20 +657,27 @@ void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, co
engine->FindObject(*(args.GetAt(3)->GetReference()))->SetVariableValue(transportId);
engine->FindObject(*(args.GetAt(4)->GetReference()))->SetVariableValue(serviceId);
}
+
SetSuccessFlag(success, res, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("GBI")) { // GetBootInfo
+ else if (m_Name.Equal("GBI")) // GetBootInfo
+ {
// Gets the NB_info field.
MHERROR("GetBootInfo ResidentProgram is not implemented");
}
- else if (m_Name.Equal("CCR")) { // CheckContentRef
+ else if (m_Name.Equal("CCR")) // CheckContentRef
+ {
// Sees if an item with a particular content reference is available
// in the carousel. This looks like it should block until the file
// is available. The profile recommends that this should be forked
// rather than called.
- if (args.Size() == 3) {
+ if (args.Size() == 3)
+ {
MHUnion un;
un.GetValueFrom(*(args.GetAt(0)), engine);
un.CheckType(MHUnion::U_ContentRef);
@@ -437,9 +686,13 @@ void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, co
QString csPath = engine->GetPathName(fileName.m_ContentRef);
bool result = false;
QByteArray text;
+
// Try to load the object.
if (! csPath.isEmpty())
+ {
result = engine->GetContext()->GetCarouselData(csPath, text);
+ }
+
// Set the result variable.
MHParameter *pResFlag = args.GetAt(1);
engine->FindObject(*(pResFlag->GetReference()))->SetVariableValue(result);
@@ -448,36 +701,46 @@ void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, co
engine->FindObject(*(pResCR->GetReference()))->SetVariableValue(fileName);
SetSuccessFlag(success, true, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("CGR")) { // CheckGroupIDRef
+ else if (m_Name.Equal("CGR")) // CheckGroupIDRef
+ {
// Sees if an application or scene with a particular group id
// is available in the carousel.
MHERROR("CheckGroupIDRef ResidentProgram is not implemented");
}
- else if (m_Name.Equal("VTG")) { // VideoToGraphics
+ else if (m_Name.Equal("VTG")) // VideoToGraphics
+ {
// Video to graphics transformation.
MHERROR("VideoToGraphics ResidentProgram is not implemented");
}
- else if (m_Name.Equal("SWA")) { // SetWidescreenAlignment
+ else if (m_Name.Equal("SWA")) // SetWidescreenAlignment
+ {
// Sets either LetterBox or Centre-cut-out mode.
// Seems to be concerned with aligning a 4:3 scene with an underlying 16:9 video
MHERROR("SetWidescreenAlignment ResidentProgram is not implemented");
}
- else if (m_Name.Equal("GDA")) { // GetDisplayAspectRatio
+ else if (m_Name.Equal("GDA")) // GetDisplayAspectRatio
+ {
// Returns the aspcet ratio. 4:3 => 1, 16:9 => 2
MHERROR("GetDisplayAspectRatio ResidentProgram is not implemented");
}
- else if (m_Name.Equal("CIS")) { // CI_SendMessage
+ else if (m_Name.Equal("CIS")) // CI_SendMessage
+ {
// Sends a message to a DVB CI application
MHERROR("CI_SendMessage ResidentProgram is not implemented");
}
- else if (m_Name.Equal("SSM")) { // SetSubtitleMode
+ else if (m_Name.Equal("SSM")) // SetSubtitleMode
+ {
// Enable or disable subtitles in addition to MHEG.
MHERROR("SetSubtitleMode ResidentProgram is not implemented");
}
- else if (m_Name.Equal("WAI")) { // WhoAmI
+ else if (m_Name.Equal("WAI")) // WhoAmI
+ {
// Return a concatenation of the strings we respond to in
// GetEngineSupport(UKEngineProfile(X))
if (args.Size() == 1)
@@ -491,60 +754,78 @@ void MHResidentProgram::CallProgram(bool fIsFork, const MHObjectRef &success, co
engine->FindObject(*(args.GetAt(0)->GetReference()))->SetVariableValue(result);
SetSuccessFlag(success, true, engine);
}
- else SetSuccessFlag(success, false, engine);
+ else
+ {
+ SetSuccessFlag(success, false, engine);
+ }
}
- else if (m_Name.Equal("DBG")) { // Debug - optional
+ else if (m_Name.Equal("DBG")) // Debug - optional
+ {
QString message = "DEBUG: ";
- for (int i = 0; i < args.Size(); i++) {
+
+ for (int i = 0; i < args.Size(); i++)
+ {
MHUnion un;
un.GetValueFrom(*(args.GetAt(i)), engine);
- switch (un.m_Type) {
- case MHUnion::U_Int:
- message.append(QString("%1").arg(un.m_nIntVal));
- break;
- case MHParameter::P_Bool:
- message.append(un.m_fBoolVal ? "True" : "False");
- break;
- case MHParameter::P_String:
- message.append(QString::fromUtf8((const char *)un.m_StrVal.Bytes(), un.m_StrVal.Size()));
- break;
- case MHParameter::P_ObjRef:
- message.append(un.m_ObjRefVal.Printable());
- break;
- case MHParameter::P_ContentRef:
- message.append(un.m_ContentRefVal.Printable());
- break;
- case MHParameter::P_Null:
- break;
+
+ switch (un.m_Type)
+ {
+ case MHUnion::U_Int:
+ message.append(QString("%1").arg(un.m_nIntVal));
+ break;
+ case MHParameter::P_Bool:
+ message.append(un.m_fBoolVal ? "True" : "False");
+ break;
+ case MHParameter::P_String:
+ message.append(QString::fromUtf8((const char *)un.m_StrVal.Bytes(), un.m_StrVal.Size()));
+ break;
+ case MHParameter::P_ObjRef:
+ message.append(un.m_ObjRefVal.Printable());
+ break;
+ case MHParameter::P_ContentRef:
+ message.append(un.m_ContentRefVal.Printable());
+ break;
+ case MHParameter::P_Null:
+ break;
}
}
+
MHLOG(MHLogNotifications, message);
}
- else if (m_Name.Equal("SBI")) { // SetBroadcastInterrupt
+ else if (m_Name.Equal("SBI")) // SetBroadcastInterrupt
+ {
// Required for InteractionChannelExtension
// En/dis/able program interruptions e.g. green button
MHERROR("SetBroadcastInterrupt ResidentProgram is not implemented");
}
- else if (m_Name.Equal("GIS")) { // GetICStatus
+ else if (m_Name.Equal("GIS")) // GetICStatus
+ {
// Required for NativeApplicationExtension
MHERROR("GetICStatus ResidentProgram is not implemented");
}
- else {
+ else
+ {
MHERROR(QString("Unknown ResidentProgram %1").arg(m_Name.Printable()));
}
}
- catch (char const *) {
+ catch (char const *)
+ {
// If something went wrong set the succeeded flag to false
SetSuccessFlag(success, false, engine);
// And continue on. In particular we need to deactivate.
}
+
Deactivation(engine);
- // At the moment we always treat Fork as Call. If we do get a Fork we should signal that we're done.
- if (fIsFork) engine->EventTriggered(this, EventAsyncStopped);
+
+ // At the moment we always treat Fork as Call. If we do get a Fork we should signal that we're done.
+ if (fIsFork)
+ {
+ engine->EventTriggered(this, EventAsyncStopped);
+ }
}
MHRemoteProgram::MHRemoteProgram()
@@ -565,10 +846,12 @@ void MHRemoteProgram::Initialise(MHParseNode *p, MHEngine *engine)
void MHRemoteProgram::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:RemotePrg");
- MHProgram::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:RemotePrg");
+ MHProgram::PrintMe(fd, nTabs + 1);
fprintf(fd, "****TODO\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
MHInterChgProgram::MHInterChgProgram()
@@ -589,10 +872,12 @@ void MHInterChgProgram::Initialise(MHParseNode *p, MHEngine *engine)
void MHInterChgProgram::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:InterchgPrg");
- MHProgram::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:InterchgPrg");
+ MHProgram::PrintMe(fd, nTabs + 1);
fprintf(fd, "****TODO\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
// Actions.
@@ -602,7 +887,9 @@ void MHCall::Initialise(MHParseNode *p, MHEngine *engine)
m_Succeeded.Initialise(p->GetArgN(1), engine); // Call/fork succeeded flag
// Arguments.
MHParseNode *args = p->GetArgN(2);
- for (int i = 0; i < args->GetSeqCount(); i++) {
+
+ for (int i = 0; i < args->GetSeqCount(); i++)
+ {
MHParameter *pParm = new MHParameter;
m_Parameters.Append(pParm);
pParm->Initialise(args->GetSeqN(i), engine);
@@ -613,7 +900,12 @@ void MHCall::PrintArgs(FILE *fd, int nTabs) const
{
m_Succeeded.PrintMe(fd, nTabs);
fprintf(fd, " ( ");
- for (int i = 0; i < m_Parameters.Size(); i++) m_Parameters.GetAt(i)->PrintMe(fd, 0);
+
+ for (int i = 0; i < m_Parameters.Size(); i++)
+ {
+ m_Parameters.GetAt(i)->PrintMe(fd, 0);
+ }
+
fprintf(fd, " )\n");
}
diff --git a/mythtv/libs/libmythfreemheg/Programs.h b/mythtv/libs/libmythfreemheg/Programs.h
index 64c68c6390b..d0be57ec2a0 100644
--- a/mythtv/libs/libmythfreemheg/Programs.h
+++ b/mythtv/libs/libmythfreemheg/Programs.h
@@ -34,7 +34,7 @@ class MHEngine;
// Abstract base class for programs.
class MHProgram : public MHIngredient
{
-public:
+ public:
MHProgram();
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintMe(FILE *fd, int nTabs) const;
@@ -44,7 +44,7 @@ class MHProgram : public MHIngredient
// Action - Stop can be used to stop the code.
virtual void Stop(MHEngine *engine) { Deactivation(engine); }
-protected:
+ protected:
MHOctetString m_Name; // Name of the program
bool m_fInitiallyAvailable;
};
@@ -52,7 +52,7 @@ class MHProgram : public MHIngredient
// Resident program
class MHResidentProgram : public MHProgram
{
-public:
+ public:
MHResidentProgram() {}
virtual const char *ClassName() { return "ResidentProgram"; }
virtual void PrintMe(FILE *fd, int nTabs) const;
@@ -63,7 +63,7 @@ class MHResidentProgram : public MHProgram
// Remote program - not needed for UK MHEG
class MHRemoteProgram : public MHProgram
{
-public:
+ public:
MHRemoteProgram();
virtual const char *ClassName() { return "RemoteProgram"; }
virtual ~MHRemoteProgram();
@@ -74,7 +74,7 @@ class MHRemoteProgram : public MHProgram
// Interchange program - not needed for UK MHEG
class MHInterChgProgram : public MHProgram
{
-public:
+ public:
MHInterChgProgram();
virtual const char *ClassName() { return "InterChgProgram"; }
virtual ~MHInterChgProgram();
@@ -85,11 +85,11 @@ class MHInterChgProgram : public MHProgram
// Call and Fork - call a "program".
class MHCall: public MHElemAction
{
-public:
+ public:
MHCall(const char *name, bool fIsFork): MHElemAction(name), m_fIsFork(fIsFork) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int nTabs) const;
bool m_fIsFork;
MHObjectRef m_Succeeded; // Boolean variable set to call result
diff --git a/mythtv/libs/libmythfreemheg/Root.cpp b/mythtv/libs/libmythfreemheg/Root.cpp
index 5f5cd3bd90c..ffa184c2814 100644
--- a/mythtv/libs/libmythfreemheg/Root.cpp
+++ b/mythtv/libs/libmythfreemheg/Root.cpp
@@ -30,7 +30,7 @@
void MHRoot::Initialise(MHParseNode *p, MHEngine *engine)
{
MHParseNode *pArg = p->GetArgN(0); // The first argument should be present.
- // Extract the field.
+ // Extract the field.
m_ObjectReference.Initialise(pArg, engine);
}
@@ -51,7 +51,11 @@ void MHRoot::InvalidAction(const char *actionName)
// Preparation - sets up the run-time representation. Sets m_fAvailable and generates IsAvailable event.
void MHRoot::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return; // Already prepared
+ if (m_fAvailable)
+ {
+ return; // Already prepared
+ }
+
// Retrieve object
// Set the internal attributes.
m_fAvailable = true;
@@ -64,15 +68,27 @@ void MHRoot::Preparation(MHEngine *engine)
// Activation - starts running the object. Sets m_fRunning and generates IsRunning event.
void MHRoot::Activation(MHEngine *engine)
{
- if (m_fRunning) return; // Already running.
- if (! m_fAvailable) Preparation(engine); // Prepare it if that hasn't already been done.
+ if (m_fRunning)
+ {
+ return; // Already running.
+ }
+
+ if (! m_fAvailable)
+ {
+ Preparation(engine); // Prepare it if that hasn't already been done.
+ }
+
// The subclasses are responsible for setting m_fRunning and generating IsRunning.
}
// Deactivation - stops running the object. Clears m_fRunning
void MHRoot::Deactivation(MHEngine *engine)
{
- if (! m_fRunning) return; // Already stopped.
+ if (! m_fRunning)
+ {
+ return; // Already stopped.
+ }
+
m_fRunning = false;
engine->EventTriggered(this, EventIsStopped);
}
@@ -80,8 +96,16 @@ void MHRoot::Deactivation(MHEngine *engine)
// Destruction - deletes the run-time representation. Clears m_fAvailable.
void MHRoot::Destruction(MHEngine *engine)
{
- if (! m_fAvailable) return; // Already destroyed or never prepared.
- if (m_fRunning) Deactivation(engine); // Deactivate it if it's still running.
+ if (! m_fAvailable)
+ {
+ return; // Already destroyed or never prepared.
+ }
+
+ if (m_fRunning)
+ {
+ Deactivation(engine); // Deactivate it if it's still running.
+ }
+
// We're supposed to wait until it's stopped here.
m_fAvailable = false;
engine->EventTriggered(this, EventIsDeleted);
@@ -90,8 +114,14 @@ void MHRoot::Destruction(MHEngine *engine)
// Return this object if it matches.
MHRoot *MHRoot::FindByObjectNo(int n)
{
- if (n == m_ObjectReference.m_nObjectNo) return this;
- else return NULL;
+ if (n == m_ObjectReference.m_nObjectNo)
+ {
+ return this;
+ }
+ else
+ {
+ return NULL;
+ }
}
void MHGetAvailabilityStatus::Initialise(MHParseNode *p, MHEngine *engine)
@@ -107,6 +137,11 @@ void MHGetAvailabilityStatus::Perform(MHEngine *engine)
m_Target.GetValue(target, engine); // Get the target
MHRoot *pObject = engine->FindObject(target, false);
bool fResult = false; // Default result.
- if (pObject) fResult = pObject->GetAvailabilityStatus();
+
+ if (pObject)
+ {
+ fResult = pObject->GetAvailabilityStatus();
+ }
+
engine->FindObject(m_ResultVar)->SetVariableValue(fResult);
}
diff --git a/mythtv/libs/libmythfreemheg/Root.h b/mythtv/libs/libmythfreemheg/Root.h
index 7d74e21e06b..929c272afc4 100644
--- a/mythtv/libs/libmythfreemheg/Root.h
+++ b/mythtv/libs/libmythfreemheg/Root.h
@@ -42,7 +42,7 @@ enum EventType { EventIsAvailable = 1, EventContentAvailable, EventIsDeleted, Ev
class MHRoot
{
-public:
+ public:
MHRoot(): m_fAvailable(false), m_fRunning(false) {}
MHRoot(const MHRoot &/*ref*/): m_fAvailable(false), m_fRunning(false) {}
virtual ~MHRoot() {}
@@ -192,14 +192,14 @@ class MHRoot
virtual void SetSliderParameters(int /*newMin*/, int /*newMax*/, int /*newStep*/, MHEngine * /*engine*/)
{ InvalidAction("SetSliderParameters"); }
-protected:
+ protected:
void InvalidAction(const char *actionName);
-public:
+ public:
MHObjectRef m_ObjectReference; // Identifier of this object.
virtual const char *ClassName() = 0; // For debugging messages.
-protected:
+ protected:
bool m_fAvailable; // Set once Preparation has completed.
bool m_fRunning; // Set once Activation has completed.
@@ -209,11 +209,11 @@ class MHRoot
// Get Availability Status - Does the object exist and is it available?.
class MHGetAvailabilityStatus: public MHElemAction
{
-public:
+ public:
MHGetAvailabilityStatus(): MHElemAction(":GetAvailabilityStatus") {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int /*nTabs*/) const { m_ResultVar.PrintMe(fd, 0); }
MHObjectRef m_ResultVar;
};
@@ -221,7 +221,7 @@ class MHGetAvailabilityStatus: public MHElemAction
// Get Running Status - Is the object running?.
class MHGetRunningStatus: public MHActionObjectRef
{
-public:
+ public:
MHGetRunningStatus(): MHActionObjectRef(":GetRunningStatus") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pResult) { pResult->SetVariableValue(pTarget->GetRunningStatus());}
};
diff --git a/mythtv/libs/libmythfreemheg/Stream.cpp b/mythtv/libs/libmythfreemheg/Stream.cpp
index 5c0fdf08b89..aa20faabe9f 100644
--- a/mythtv/libs/libmythfreemheg/Stream.cpp
+++ b/mythtv/libs/libmythfreemheg/Stream.cpp
@@ -40,54 +40,100 @@ void MHStream::Initialise(MHParseNode *p, MHEngine *engine)
{
MHPresentable::Initialise(p, engine);
MHParseNode *pMultiplex = p->GetNamedArg(C_MULTIPLEX);
- if (pMultiplex) {
- for (int i = 0; i < pMultiplex->GetArgCount(); i++) {
+
+ if (pMultiplex)
+ {
+ for (int i = 0; i < pMultiplex->GetArgCount(); i++)
+ {
MHParseNode *pItem = pMultiplex->GetArgN(i);
- if (pItem->GetTagNo() == C_AUDIO) {
+
+ if (pItem->GetTagNo() == C_AUDIO)
+ {
MHAudio *pAudio = new MHAudio;
m_Multiplex.Append(pAudio);
pAudio->Initialise(pItem, engine);
}
- else if (pItem->GetTagNo() == C_VIDEO) {
+ else if (pItem->GetTagNo() == C_VIDEO)
+ {
MHVideo *pVideo = new MHVideo;
m_Multiplex.Append(pVideo);
pVideo->Initialise(pItem, engine);
}
- else if (pItem->GetTagNo() == C_RTGRAPHICS) {
+ else if (pItem->GetTagNo() == C_RTGRAPHICS)
+ {
MHRTGraphics *pRtGraph = new MHRTGraphics;
m_Multiplex.Append(pRtGraph);
pRtGraph->Initialise(pItem, engine);
}
+
// Ignore unknown items
}
}
+
MHParseNode *pStorage = p->GetNamedArg(C_STORAGE);
- if (pStorage) m_nStorage = (enum Storage) pStorage->GetArgN(0)->GetEnumValue();
+
+ if (pStorage)
+ {
+ m_nStorage = (enum Storage) pStorage->GetArgN(0)->GetEnumValue();
+ }
+
MHParseNode *pLooping = p->GetNamedArg(C_LOOPING);
- if (pLooping) m_nLooping = pLooping->GetArgN(0)->GetIntValue();
+
+ if (pLooping)
+ {
+ m_nLooping = pLooping->GetArgN(0)->GetIntValue();
+ }
}
void MHStream::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:Stream ");
- MHPresentable::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":Multiplex (\n");
- for (int i = 0; i < m_Multiplex.Size(); i++) m_Multiplex.GetAt(i)->PrintMe(fd, nTabs+2);
- PrintTabs(fd, nTabs+1); fprintf(fd, " )\n");
- if (m_nStorage != ST_Stream) { PrintTabs(fd, nTabs+1); fprintf(fd, ":Storage memory\n"); }
- if (m_nLooping != 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":Looping %d\n", m_nLooping); }
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:Stream ");
+ MHPresentable::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":Multiplex (\n");
+
+ for (int i = 0; i < m_Multiplex.Size(); i++)
+ {
+ m_Multiplex.GetAt(i)->PrintMe(fd, nTabs + 2);
+ }
+
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, " )\n");
+
+ if (m_nStorage != ST_Stream)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":Storage memory\n");
+ }
+
+ if (m_nLooping != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":Looping %d\n", m_nLooping);
+ }
+
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHStream::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return; // Already prepared
- for (int i = 0; i < m_Multiplex.Size(); i++) {
+ if (m_fAvailable)
+ {
+ return; // Already prepared
+ }
+
+ for (int i = 0; i < m_Multiplex.Size(); i++)
+ {
MHPresentable *pItem = m_Multiplex.GetAt(i);
- if (pItem->InitiallyActive()) {
+
+ if (pItem->InitiallyActive())
+ {
pItem->Activation(engine); // N.B. This will also call Preparation for the components.
}
}
+
MHPresentable::Preparation(engine);
}
@@ -95,27 +141,45 @@ void MHStream::Destruction(MHEngine *engine)
{
// Apply Destruction in reverse order.
for (int j = m_Multiplex.Size(); j > 0; j--)
- m_Multiplex.GetAt(j-1)->Destruction(engine);
+ {
+ m_Multiplex.GetAt(j - 1)->Destruction(engine);
+ }
+
MHPresentable::Destruction(engine);
}
void MHStream::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHPresentable::Activation(engine);
+
// Start playing all active stream components.
for (int i = 0; i < m_Multiplex.Size(); i++)
+ {
m_Multiplex.GetAt(i)->BeginPlaying(engine);
+ }
+
m_fRunning = true;
engine->EventTriggered(this, EventIsRunning);
}
void MHStream::Deactivation(MHEngine *engine)
{
- if (! m_fRunning) return;
+ if (! m_fRunning)
+ {
+ return;
+ }
+
// Stop playing all active Stream components
for (int i = 0; i < m_Multiplex.Size(); i++)
+ {
m_Multiplex.GetAt(i)->StopPlaying(engine);
+ }
+
MHPresentable::Deactivation(engine);
}
@@ -124,8 +188,11 @@ void MHStream::Deactivation(MHEngine *engine)
void MHStream::ContentPreparation(MHEngine *engine)
{
engine->EventTriggered(this, EventContentAvailable); // Perhaps test for the streams being available?
+
for (int i = 0; i < m_Multiplex.Size(); i++)
+ {
m_Multiplex.GetAt(i)->SetStreamRef(engine, m_ContentRef);
+ }
}
// TODO: Generate StreamPlaying and StreamStopped events. These are supposed
@@ -134,11 +201,21 @@ void MHStream::ContentPreparation(MHEngine *engine)
// Return an object if there is a matching component.
MHRoot *MHStream::FindByObjectNo(int n)
{
- if (n == m_ObjectReference.m_nObjectNo) return this;
- for (int i = m_Multiplex.Size(); i > 0; i--) {
- MHRoot *pResult = m_Multiplex.GetAt(i-1)->FindByObjectNo(n);
- if (pResult) return pResult;
+ if (n == m_ObjectReference.m_nObjectNo)
+ {
+ return this;
+ }
+
+ for (int i = m_Multiplex.Size(); i > 0; i--)
+ {
+ MHRoot *pResult = m_Multiplex.GetAt(i - 1)->FindByObjectNo(n);
+
+ if (pResult)
+ {
+ return pResult;
+ }
}
+
return NULL;
}
@@ -153,24 +230,46 @@ void MHAudio::Initialise(MHParseNode *p, MHEngine *engine)
{
MHPresentable::Initialise(p, engine);
MHParseNode *pComponentTagNode = p->GetNamedArg(C_COMPONENT_TAG);
- if (pComponentTagNode) m_nComponentTag = pComponentTagNode->GetArgN(0)->GetIntValue();
+
+ if (pComponentTagNode)
+ {
+ m_nComponentTag = pComponentTagNode->GetArgN(0)->GetIntValue();
+ }
+
MHParseNode *pOrigVol = p->GetNamedArg(C_ORIGINAL_VOLUME);
- if (pOrigVol) m_nOriginalVol = pOrigVol->GetIntValue();
+
+ if (pOrigVol)
+ {
+ m_nOriginalVol = pOrigVol->GetIntValue();
+ }
}
void MHAudio::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:Audio ");
- MHPresentable::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":ComponentTag %d\n", m_nComponentTag);
- if (m_nOriginalVol != 0) { PrintTabs(fd, nTabs+1); fprintf(fd, "OriginalVolume %d ", m_nOriginalVol); }
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:Audio ");
+ MHPresentable::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":ComponentTag %d\n", m_nComponentTag);
+
+ if (m_nOriginalVol != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, "OriginalVolume %d ", m_nOriginalVol);
+ }
+
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
// Activation for Audio is defined in the corrigendum
void MHAudio::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHPresentable::Activation(engine);
// Beginning presentation is started by the Stream object.
m_fRunning = true;
@@ -180,7 +279,12 @@ void MHAudio::Activation(MHEngine *engine)
{
QString stream;
MHOctetString &str = m_streamContentRef.m_ContentRef;
- if (str.Size() != 0) stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
+
+ if (str.Size() != 0)
+ {
+ stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
+ }
+
engine->GetContext()->BeginAudio(stream, m_nComponentTag);
}
}
@@ -188,11 +292,18 @@ void MHAudio::Activation(MHEngine *engine)
// Deactivation for Audio is defined in the corrigendum
void MHAudio::Deactivation(MHEngine *engine)
{
- if (! m_fRunning) return;
+ if (! m_fRunning)
+ {
+ return;
+ }
+
m_fRunning = false;
// Stop presenting the audio
- if (m_fStreamPlaying) engine->GetContext()->StopAudio();
+ if (m_fStreamPlaying)
+ {
+ engine->GetContext()->StopAudio();
+ }
MHPresentable::Deactivation(engine);
}
@@ -200,17 +311,27 @@ void MHAudio::Deactivation(MHEngine *engine)
void MHAudio::SetStreamRef(MHEngine *engine, const MHContentRef &cr)
{
m_streamContentRef.Copy(cr);
- if (m_fStreamPlaying) BeginPlaying(engine);
+
+ if (m_fStreamPlaying)
+ {
+ BeginPlaying(engine);
+ }
}
void MHAudio::BeginPlaying(MHEngine *engine)
{
m_fStreamPlaying = true;
+
if (m_fRunning && m_streamContentRef.IsSet())
{
QString stream;
MHOctetString &str = m_streamContentRef.m_ContentRef;
- if (str.Size() != 0) stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
+
+ if (str.Size() != 0)
+ {
+ stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
+ }
+
engine->GetContext()->BeginAudio(stream, m_nComponentTag);
}
}
@@ -218,7 +339,11 @@ void MHAudio::BeginPlaying(MHEngine *engine)
void MHAudio::StopPlaying(MHEngine *engine)
{
m_fStreamPlaying = false;
- if (m_fRunning) engine->GetContext()->StopAudio();
+
+ if (m_fRunning)
+ {
+ engine->GetContext()->StopAudio();
+ }
}
@@ -238,23 +363,45 @@ void MHVideo::Initialise(MHParseNode *p, MHEngine *engine)
{
MHVisible::Initialise(p, engine);
MHParseNode *pComponentTagNode = p->GetNamedArg(C_COMPONENT_TAG);
- if (pComponentTagNode) m_nComponentTag = pComponentTagNode->GetArgN(0)->GetIntValue();
+
+ if (pComponentTagNode)
+ {
+ m_nComponentTag = pComponentTagNode->GetArgN(0)->GetIntValue();
+ }
+
MHParseNode *pTerm = p->GetNamedArg(C_TERMINATION);
- if (pTerm) m_Termination = (enum Termination)pTerm->GetEnumValue();
+
+ if (pTerm)
+ {
+ m_Termination = (enum Termination)pTerm->GetEnumValue();
+ }
}
void MHVideo::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:Video ");
- MHVisible::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":ComponentTag %d\n", m_nComponentTag);
- if (m_Termination != VI_Disappear) { PrintTabs(fd, nTabs+1); fprintf(fd, "Termination freeze "); }
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:Video ");
+ MHVisible::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":ComponentTag %d\n", m_nComponentTag);
+
+ if (m_Termination != VI_Disappear)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, "Termination freeze ");
+ }
+
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHVideo::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return; // Already prepared
+ if (m_fAvailable)
+ {
+ return; // Already prepared
+ }
+
MHVisible::Preparation(engine); // Prepare the base class.
// Set up the internal attributes after MHVisible::Preparation.
m_nDecodeWidth = m_nBoxWidth;
@@ -270,20 +417,32 @@ void MHVideo::ContentPreparation(MHEngine *engine)
// Display the video.
void MHVideo::Display(MHEngine *engine)
{
- if (! m_fRunning) return;
- if (m_nBoxWidth == 0 || m_nBoxHeight == 0) return; // Can't draw zero sized boxes.
+ if (! m_fRunning)
+ {
+ return;
+ }
+
+ if (m_nBoxWidth == 0 || m_nBoxHeight == 0)
+ {
+ return; // Can't draw zero sized boxes.
+ }
+
// The bounding box is assumed always to be True.
// The full screen video is displayed in this rectangle. It is therefore scaled to
// m_nDecodeWidth/720 by m_nDecodeHeight/576.
- QRect videoRect = QRect(m_nPosX+m_nXDecodeOffset, m_nPosY+m_nYDecodeOffset,
- m_nDecodeWidth, m_nDecodeHeight);
+ QRect videoRect = QRect(m_nPosX + m_nXDecodeOffset, m_nPosY + m_nYDecodeOffset,
+ m_nDecodeWidth, m_nDecodeHeight);
QRect displayRect = videoRect.intersect(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
engine->GetContext()->DrawVideo(videoRect, displayRect);
}
void MHVideo::ScaleVideo(int xScale, int yScale, MHEngine *engine)
{
- if (xScale == m_nDecodeWidth && yScale == m_nDecodeHeight) return;
+ if (xScale == m_nDecodeWidth && yScale == m_nDecodeHeight)
+ {
+ return;
+ }
+
QRegion updateArea = GetVisibleArea(); // Redraw the area before the offset
m_nDecodeWidth = xScale;
m_nDecodeHeight = yScale;
@@ -311,49 +470,81 @@ void MHVideo::GetVideoDecodeOffset(MHRoot *pXOffset, MHRoot *pYOffset, MHEngine
// Return the region drawn by the bitmap.
QRegion MHVideo::GetVisibleArea()
{
- if (! m_fRunning) return QRegion();
+ if (! m_fRunning)
+ {
+ return QRegion();
+ }
+
// The visible area is the intersection of the containing box with the, possibly offset,
// video.
QRegion boxRegion = QRegion(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight);
- QRegion videoRegion = QRegion(m_nPosX+m_nXDecodeOffset, m_nPosY+m_nYDecodeOffset,
- m_nDecodeWidth, m_nDecodeHeight);
+ QRegion videoRegion = QRegion(m_nPosX + m_nXDecodeOffset, m_nPosY + m_nYDecodeOffset,
+ m_nDecodeWidth, m_nDecodeHeight);
return boxRegion & videoRegion;
}
void MHVideo::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHVisible::Activation(engine);
+
if (m_fStreamPlaying && m_streamContentRef.IsSet())
{
QString stream;
MHOctetString &str = m_streamContentRef.m_ContentRef;
- if (str.Size() != 0) stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
+
+ if (str.Size() != 0)
+ {
+ stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
+ }
+
engine->GetContext()->BeginVideo(stream, m_nComponentTag);
}
}
void MHVideo::Deactivation(MHEngine *engine)
{
- if (! m_fRunning) return;
+ if (! m_fRunning)
+ {
+ return;
+ }
+
MHVisible::Deactivation(engine);
- if (m_fStreamPlaying) engine->GetContext()->StopVideo();
+
+ if (m_fStreamPlaying)
+ {
+ engine->GetContext()->StopVideo();
+ }
}
void MHVideo::SetStreamRef(MHEngine *engine, const MHContentRef &cr)
{
m_streamContentRef.Copy(cr);
- if (m_fStreamPlaying) BeginPlaying(engine);
+
+ if (m_fStreamPlaying)
+ {
+ BeginPlaying(engine);
+ }
}
void MHVideo::BeginPlaying(MHEngine *engine)
{
m_fStreamPlaying = true;
+
if (m_fRunning && m_streamContentRef.IsSet())
{
QString stream;
MHOctetString &str = m_streamContentRef.m_ContentRef;
- if (str.Size() != 0) stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
+
+ if (str.Size() != 0)
+ {
+ stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
+ }
+
engine->GetContext()->BeginVideo(stream, m_nComponentTag);
}
}
@@ -361,7 +552,11 @@ void MHVideo::BeginPlaying(MHEngine *engine)
void MHVideo::StopPlaying(MHEngine *engine)
{
m_fStreamPlaying = false;
- if (m_fRunning) engine->GetContext()->StopVideo();
+
+ if (m_fRunning)
+ {
+ engine->GetContext()->StopVideo();
+ }
}
diff --git a/mythtv/libs/libmythfreemheg/Stream.h b/mythtv/libs/libmythfreemheg/Stream.h
index 16f36dda180..18dfb03b1d3 100644
--- a/mythtv/libs/libmythfreemheg/Stream.h
+++ b/mythtv/libs/libmythfreemheg/Stream.h
@@ -31,7 +31,7 @@
class MHStream : public MHPresentable
{
-public:
+ public:
MHStream();
virtual const char *ClassName() { return "Stream"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -44,7 +44,7 @@ class MHStream : public MHPresentable
virtual void ContentPreparation(MHEngine *engine);
virtual MHRoot *FindByObjectNo(int n);
-protected:
+ protected:
MHOwnPtrSequence m_Multiplex;
enum Storage { ST_Mem = 1, ST_Stream = 2 } m_nStorage;
int m_nLooping;
@@ -53,7 +53,7 @@ class MHStream : public MHPresentable
class MHAudio : public MHPresentable
{
-public:
+ public:
MHAudio();
virtual const char *ClassName() { return "Audio"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -66,7 +66,7 @@ class MHAudio : public MHPresentable
virtual void BeginPlaying(MHEngine *engine);
virtual void StopPlaying(MHEngine *engine);
-protected:
+ protected:
int m_nComponentTag;
int m_nOriginalVol;
@@ -76,7 +76,7 @@ class MHAudio : public MHPresentable
class MHVideo : public MHVisible
{
-public:
+ public:
MHVideo();
virtual const char *ClassName() { return "Video"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -101,7 +101,7 @@ class MHVideo : public MHVisible
virtual void BeginPlaying(MHEngine *engine);
virtual void StopPlaying(MHEngine *engine);
-protected:
+ protected:
int m_nComponentTag;
enum Termination { VI_Freeze = 1, VI_Disappear } m_Termination;
// Added in UK MHEG
@@ -115,7 +115,7 @@ class MHVideo : public MHVisible
// Real-time graphics - not needed for UK MHEG.
class MHRTGraphics : public MHVisible
{
-public:
+ public:
MHRTGraphics();
virtual const char *ClassName() { return "RTGraphics"; }
virtual ~MHRTGraphics();
@@ -126,7 +126,7 @@ class MHRTGraphics : public MHVisible
class MHScaleVideo: public MHActionIntInt {
-public:
+ public:
MHScaleVideo(): MHActionIntInt(":ScaleVideo") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2) { pTarget->ScaleVideo(nArg1, nArg2, engine); }
};
@@ -134,14 +134,14 @@ class MHScaleVideo: public MHActionIntInt {
// Actions added in the UK MHEG profile.
class MHSetVideoDecodeOffset: public MHActionIntInt
{
-public:
+ public:
MHSetVideoDecodeOffset(): MHActionIntInt(":SetVideoDecodeOffset") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2) { pTarget->SetVideoDecodeOffset(nArg1, nArg2, engine); }
};
class MHGetVideoDecodeOffset: public MHActionObjectRef2
{
-public:
+ public:
MHGetVideoDecodeOffset(): MHActionObjectRef2(":GetVideoDecodeOffset") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg1, MHRoot *pArg2) { pTarget->GetVideoDecodeOffset(pArg1, pArg2, engine); }
};
diff --git a/mythtv/libs/libmythfreemheg/Text.cpp b/mythtv/libs/libmythfreemheg/Text.cpp
index ceff8216a46..5575a4aea25 100644
--- a/mythtv/libs/libmythfreemheg/Text.cpp
+++ b/mythtv/libs/libmythfreemheg/Text.cpp
@@ -70,31 +70,80 @@ void MHText::Initialise(MHParseNode *p, MHEngine *engine)
MHVisible::Initialise(p, engine);
// Font and attributes.
MHParseNode *pFontBody = p->GetNamedArg(C_ORIGINAL_FONT);
- if (pFontBody) m_OrigFont.Initialise(pFontBody->GetArgN(0), engine);
+
+ if (pFontBody)
+ {
+ m_OrigFont.Initialise(pFontBody->GetArgN(0), engine);
+ }
+
MHParseNode *pFontAttrs = p->GetNamedArg(C_FONT_ATTRIBUTES);
- if (pFontAttrs) pFontAttrs->GetArgN(0)->GetStringValue(m_OriginalFontAttrs);
+
+ if (pFontAttrs)
+ {
+ pFontAttrs->GetArgN(0)->GetStringValue(m_OriginalFontAttrs);
+ }
+
// Colours
MHParseNode *pTextColour = p->GetNamedArg(C_TEXT_COLOUR);
- if (pTextColour) m_OriginalTextColour.Initialise(pTextColour->GetArgN(0), engine);
+
+ if (pTextColour)
+ {
+ m_OriginalTextColour.Initialise(pTextColour->GetArgN(0), engine);
+ }
+
MHParseNode *pBGColour = p->GetNamedArg(C_BACKGROUND_COLOUR);
- if (pBGColour) m_OriginalBgColour.Initialise(pBGColour->GetArgN(0), engine);
+
+ if (pBGColour)
+ {
+ m_OriginalBgColour.Initialise(pBGColour->GetArgN(0), engine);
+ }
+
// Character set
MHParseNode *pChset = p->GetNamedArg(C_CHARACTER_SET);
- if (pChset) m_nCharSet = pChset->GetArgN(0)->GetIntValue();
+
+ if (pChset)
+ {
+ m_nCharSet = pChset->GetArgN(0)->GetIntValue();
+ }
+
// Justification
MHParseNode *pHJust = p->GetNamedArg(C_HORIZONTAL_JUSTIFICATION);
- if (pHJust) m_HorizJ = (enum Justification)pHJust->GetArgN(0)->GetEnumValue();
+
+ if (pHJust)
+ {
+ m_HorizJ = (enum Justification)pHJust->GetArgN(0)->GetEnumValue();
+ }
+
MHParseNode *pVJust = p->GetNamedArg(C_VERTICAL_JUSTIFICATION);
- if (pVJust) m_VertJ = (enum Justification)pVJust->GetArgN(0)->GetEnumValue();
+
+ if (pVJust)
+ {
+ m_VertJ = (enum Justification)pVJust->GetArgN(0)->GetEnumValue();
+ }
+
// Line orientation
MHParseNode *pLineO = p->GetNamedArg(C_LINE_ORIENTATION);
- if (pLineO) m_LineOrientation = (enum LineOrientation)pLineO->GetArgN(0)->GetEnumValue();
+
+ if (pLineO)
+ {
+ m_LineOrientation = (enum LineOrientation)pLineO->GetArgN(0)->GetEnumValue();
+ }
+
// Start corner
MHParseNode *pStartC = p->GetNamedArg(C_START_CORNER);
- if (pStartC) m_StartCorner = (enum StartCorner)pStartC->GetArgN(0)->GetEnumValue();
+
+ if (pStartC)
+ {
+ m_StartCorner = (enum StartCorner)pStartC->GetArgN(0)->GetEnumValue();
+ }
+
// Text wrapping
MHParseNode *pTextWrap = p->GetNamedArg(C_TEXT_WRAPPING);
- if (pTextWrap) m_fTextWrap = pTextWrap->GetArgN(0)->GetBoolValue();
+
+ if (pTextWrap)
+ {
+ m_fTextWrap = pTextWrap->GetArgN(0)->GetBoolValue();
+ }
m_pDisplay = engine->GetContext()->CreateText();
m_fNeedsRedraw = true;
@@ -111,9 +160,14 @@ static const char *rchJustification[] =
// Look up the Justification. Returns zero if it doesn't match. Used in the text parser only.
int MHText::GetJustification(const char *str)
{
- for (int i = 0; i < (int)(sizeof(rchJustification)/sizeof(rchJustification[0])); i++) {
- if (strcasecmp(str, rchJustification[i]) == 0) return (i+1); // Numbered from 1
+ for (int i = 0; i < (int)(sizeof(rchJustification) / sizeof(rchJustification[0])); i++)
+ {
+ if (strcasecmp(str, rchJustification[i]) == 0)
+ {
+ return (i + 1); // Numbered from 1
+ }
}
+
return 0;
}
@@ -125,9 +179,14 @@ static const char *rchlineOrientation[] =
int MHText::GetLineOrientation(const char *str)
{
- for (int i = 0; i < (int)(sizeof(rchlineOrientation)/sizeof(rchlineOrientation[0])); i++) {
- if (strcasecmp(str, rchlineOrientation[i]) == 0) return (i+1);
+ for (int i = 0; i < (int)(sizeof(rchlineOrientation) / sizeof(rchlineOrientation[0])); i++)
+ {
+ if (strcasecmp(str, rchlineOrientation[i]) == 0)
+ {
+ return (i + 1);
+ }
}
+
return 0;
}
@@ -141,41 +200,132 @@ static const char *rchStartCorner[] =
int MHText::GetStartCorner(const char *str)
{
- for (int i = 0; i < (int)(sizeof(rchStartCorner)/sizeof(rchStartCorner[0])); i++) {
- if (strcasecmp(str, rchStartCorner[i]) == 0) return (i+1);
+ for (int i = 0; i < (int)(sizeof(rchStartCorner) / sizeof(rchStartCorner[0])); i++)
+ {
+ if (strcasecmp(str, rchStartCorner[i]) == 0)
+ {
+ return (i + 1);
+ }
}
+
return 0;
}
void MHText::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:Text ");
- MHVisible::PrintMe(fd, nTabs+1);
- if (m_OrigFont.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":OrigFont "); m_OrigFont.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
- if (m_OriginalFontAttrs.Size() > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":FontAttributes "); m_OriginalFontAttrs.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
- if (m_OriginalTextColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":TextColour "); m_OriginalTextColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
- if (m_OriginalBgColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":BackgroundColour "); m_OriginalBgColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
- if (m_nCharSet >= 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":CharacterSet %d\n", m_nCharSet); }
- if (m_HorizJ != Start) { PrintTabs(fd, nTabs+1); fprintf(fd, ":HJustification %s\n", rchJustification[m_HorizJ-1]); }
- if (m_VertJ != Start) { PrintTabs(fd, nTabs+1); fprintf(fd, ":VJustification %s\n", rchJustification[m_VertJ-1]); }
- if (m_LineOrientation != Horizontal) { PrintTabs(fd, nTabs+1); fprintf(fd, ":LineOrientation %s\n", rchlineOrientation[m_LineOrientation-1]); }
- if (m_StartCorner != UpperLeft) { PrintTabs(fd, nTabs+1); fprintf(fd, ":StartCorner %s\n", rchStartCorner[m_StartCorner-1]); }
- if (m_fTextWrap) { PrintTabs(fd, nTabs+1); fprintf(fd, ":TextWrapping true\n"); }
- PrintTabs(fd, nTabs);fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:Text ");
+ MHVisible::PrintMe(fd, nTabs + 1);
+
+ if (m_OrigFont.IsSet())
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OrigFont ");
+ m_OrigFont.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_OriginalFontAttrs.Size() > 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":FontAttributes ");
+ m_OriginalFontAttrs.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_OriginalTextColour.IsSet())
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":TextColour ");
+ m_OriginalTextColour.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_OriginalBgColour.IsSet())
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":BackgroundColour ");
+ m_OriginalBgColour.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ }
+
+ if (m_nCharSet >= 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":CharacterSet %d\n", m_nCharSet);
+ }
+
+ if (m_HorizJ != Start)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":HJustification %s\n", rchJustification[m_HorizJ-1]);
+ }
+
+ if (m_VertJ != Start)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":VJustification %s\n", rchJustification[m_VertJ-1]);
+ }
+
+ if (m_LineOrientation != Horizontal)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":LineOrientation %s\n", rchlineOrientation[m_LineOrientation-1]);
+ }
+
+ if (m_StartCorner != UpperLeft)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":StartCorner %s\n", rchStartCorner[m_StartCorner-1]);
+ }
+
+ if (m_fTextWrap)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":TextWrapping true\n");
+ }
+
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHText::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return;
+ if (m_fAvailable)
+ {
+ return;
+ }
+
// Set the colours and font up from the originals if specified otherwise use the application defaults.
-// if (m_OrigFont.IsSet()) m_Font.Copy(m_OrigFont);
-// else m_Font.Copy(engine->m_DefaultFont);
- if (m_OriginalTextColour.IsSet()) m_textColour.Copy(m_OriginalTextColour);
- else engine->GetDefaultTextColour(m_textColour);
- if (m_OriginalBgColour.IsSet()) m_bgColour.Copy(m_OriginalBgColour);
- else engine->GetDefaultBGColour(m_bgColour);
- if (m_OriginalFontAttrs.Size() > 0) m_fontAttrs.Copy(m_OriginalFontAttrs);
- else engine->GetDefaultFontAttrs(m_fontAttrs);
+ // if (m_OrigFont.IsSet()) m_Font.Copy(m_OrigFont);
+ // else m_Font.Copy(engine->m_DefaultFont);
+ if (m_OriginalTextColour.IsSet())
+ {
+ m_textColour.Copy(m_OriginalTextColour);
+ }
+ else
+ {
+ engine->GetDefaultTextColour(m_textColour);
+ }
+
+ if (m_OriginalBgColour.IsSet())
+ {
+ m_bgColour.Copy(m_OriginalBgColour);
+ }
+ else
+ {
+ engine->GetDefaultBGColour(m_bgColour);
+ }
+
+ if (m_OriginalFontAttrs.Size() > 0)
+ {
+ m_fontAttrs.Copy(m_OriginalFontAttrs);
+ }
+ else
+ {
+ engine->GetDefaultFontAttrs(m_fontAttrs);
+ }
+
MHVisible::Preparation(engine);
m_pDisplay->SetSize(m_nBoxWidth, m_nBoxHeight);
@@ -186,9 +336,16 @@ void MHText::Preparation(MHEngine *engine)
void MHText::ContentPreparation(MHEngine *engine)
{
MHVisible::ContentPreparation(engine);
+
if (m_ContentType == IN_NoContent)
+ {
MHERROR("Text object must have content");
- if (m_ContentType == IN_IncludedContent) CreateContent(m_IncludedContent.Bytes(), m_IncludedContent.Size(), engine);
+ }
+
+ if (m_ContentType == IN_IncludedContent)
+ {
+ CreateContent(m_IncludedContent.Bytes(), m_IncludedContent.Size(), engine);
+ }
}
// Called when external content is available.
@@ -200,13 +357,13 @@ void MHText::ContentArrived(const unsigned char *data, int length, MHEngine *eng
m_fNeedsRedraw = true;
}
-//
+//
void MHText::CreateContent(const unsigned char *p, int s, MHEngine *engine)
{
m_Content.Copy(MHOctetString((const char *)p, s));
engine->Redraw(GetVisibleArea()); // Have to redraw if the content has changed.
m_fNeedsRedraw = true;
-// fprintf(fd, "Text content is now "); m_Content.PrintMe(0); fprintf(fd, "\n");
+ // fprintf(fd, "Text content is now "); m_Content.PrintMe(0); fprintf(fd, "\n");
}
void MHText::SetTextColour(const MHColour &colour, MHEngine *engine)
@@ -235,48 +392,87 @@ void MHText::SetFontAttributes(const MHOctetString &fontAttrs, MHEngine *engine)
static void InterpretAttributes(const MHOctetString &attrs, int &style, int &size, int &lineSpace, int &letterSpace)
{
// Set the defaults.
- style = 0; size = 0x18; lineSpace = 0x18; letterSpace = 0;
- if (attrs.Size() == 5) { // Short form.
+ style = 0;
+ size = 0x18;
+ lineSpace = 0x18;
+ letterSpace = 0;
+
+ if (attrs.Size() == 5) // Short form.
+ {
style = attrs.GetAt(0); // Only the bottom nibble is significant.
size = attrs.GetAt(1);
lineSpace = attrs.GetAt(2);
// Is this big-endian or little-endian? Assume big.
letterSpace = attrs.GetAt(3) * 256 + attrs.GetAt(4);
- if (letterSpace > 32767) letterSpace -= 65536; // Signed.
+
+ if (letterSpace > 32767)
+ {
+ letterSpace -= 65536; // Signed.
+ }
}
- else { // Textual form.
+ else // Textual form.
+ {
const unsigned char *str = attrs.Bytes();
char *p = (char *)str;
char *q = strchr(p, '.'); // Find the terminating dot
- if (q != NULL) { // plain, italic etc.
- if (q-p == 6 && strncmp(p, "italic", 6) == 0) style = 1;
- else if (q-p == 4 && strncmp(p, "bold", 4) == 0) style = 2;
- else if (q-p == 11 && strncmp(p, "bold-italic", 11) == 0) style = 3;
+
+ if (q != NULL) // plain, italic etc.
+ {
+ if (q - p == 6 && strncmp(p, "italic", 6) == 0)
+ {
+ style = 1;
+ }
+ else if (q - p == 4 && strncmp(p, "bold", 4) == 0)
+ {
+ style = 2;
+ }
+ else if (q - p == 11 && strncmp(p, "bold-italic", 11) == 0)
+ {
+ style = 3;
+ }
+
// else it's plain.
- p = q+1;
+ p = q + 1;
q = strchr(p, '.'); // Find the next dot.
}
- if (q != NULL) { // Size
+
+ if (q != NULL) // Size
+ {
size = atoi(p);
- if (size == 0) size = 0x18;
- p = q+1;
+
+ if (size == 0)
+ {
+ size = 0x18;
+ }
+
+ p = q + 1;
q = strchr(p, '.'); // Find the next dot.
}
- if (q != NULL) { // lineSpacing
+
+ if (q != NULL) // lineSpacing
+ {
lineSpace = atoi(p);
- if (lineSpace == 0) size = 0x18;
- p = q+1;
+
+ if (lineSpace == 0)
+ {
+ size = 0x18;
+ }
+
+ p = q + 1;
q = strchr(p, '.'); // Find the next dot.
}
- if (q != NULL) { // letter spacing. May be zero or negative
+
+ if (q != NULL) // letter spacing. May be zero or negative
+ {
letterSpace = atoi(p);
}
}
}
// We break the text up into pieces of line segment.
-class MHTextItem {
-public:
+class MHTextItem
+{
+ public:
MHTextItem();
MHOctetString m_Text; // UTF-8 text
QString m_Unicode; // Unicode text
@@ -305,8 +501,9 @@ MHTextItem *MHTextItem::NewItem()
}
// A line consists of one or more sequences of text items.
-class MHTextLine {
-public:
+class MHTextLine
+{
+ public:
MHTextLine(): m_nLineWidth(0), m_nLineHeight(0), m_nDescent(0) {}
~MHTextLine();
MHSequence m_Items;
@@ -317,7 +514,10 @@ class MHTextLine {
MHTextLine::~MHTextLine()
{
- for (int i = 0; i < m_Items.Size(); i++) delete(m_Items.GetAt(i));
+ for (int i = 0; i < m_Items.Size(); i++)
+ {
+ delete(m_Items.GetAt(i));
+ }
}
// Tabs are set every 56 points (45 pixels).
@@ -330,15 +530,22 @@ MHTextLine::~MHTextLine()
// Recreate the image.
void MHText::Redraw()
{
- if (! m_fRunning || !m_pDisplay) return;
- if (m_nBoxWidth == 0 || m_nBoxHeight == 0) return; // Can't draw zero sized boxes.
+ if (! m_fRunning || !m_pDisplay)
+ {
+ return;
+ }
+
+ if (m_nBoxWidth == 0 || m_nBoxHeight == 0)
+ {
+ return; // Can't draw zero sized boxes.
+ }
m_pDisplay->SetSize(m_nBoxWidth, m_nBoxHeight);
m_pDisplay->Clear();
- MHRgba textColour = GetColour(m_textColour);
+ MHRgba textColour = GetColour(m_textColour);
// Process any escapes in the text and construct the text arrays.
- MHSequence theText;
+ MHSequence theText;
// Set up the first item on the first line.
MHTextItem *pCurrItem = new MHTextItem;
MHTextLine *pCurrLine = new MHTextLine;
@@ -349,15 +556,24 @@ void MHText::Redraw()
pCurrItem->m_Colour = textColour;
int i = 0;
- while (i < m_Content.Size()) {
+
+ while (i < m_Content.Size())
+ {
unsigned char ch = m_Content.GetAt(i++);
- if (ch == '\t') { // Tab - start a new item if we have any text in the existing one.
- if (pCurrItem->m_Text.Size() != 0) { pCurrItem = pCurrItem->NewItem(); pCurrLine->m_Items.Append(pCurrItem); }
+ if (ch == '\t') // Tab - start a new item if we have any text in the existing one.
+ {
+ if (pCurrItem->m_Text.Size() != 0)
+ {
+ pCurrItem = pCurrItem->NewItem();
+ pCurrLine->m_Items.Append(pCurrItem);
+ }
+
pCurrItem->m_nTabCount++;
}
- else if (ch == '\r') { // CR - line break.
+ else if (ch == '\r') // CR - line break.
+ {
// TODO: Two CRs next to one another are treated as
rather than
// This should also include the sequence CRLFCRLF.
pCurrLine = new MHTextLine;
@@ -366,40 +582,66 @@ void MHText::Redraw()
pCurrLine->m_Items.Append(pCurrItem);
}
- else if (ch == 0x1b) { // Escape - special codes.
- if (i == m_Content.Size()) break;
+ else if (ch == 0x1b) // Escape - special codes.
+ {
+ if (i == m_Content.Size())
+ {
+ break;
+ }
+
unsigned char code = m_Content.GetAt(i);
// The only codes we are interested in are the start and end of colour.
// TODO: We may also need "bold" and some hypertext colours.
- if (code >= 0x40 && code <= 0x5e) { // Start code
+ if (code >= 0x40 && code <= 0x5e) // Start code
+ {
// Start codes are followed by a parameter count and a number of parameter bytes.
- if (++i == m_Content.Size()) break;
+ if (++i == m_Content.Size())
+ {
+ break;
+ }
+
unsigned char paramCount = m_Content.GetAt(i);
i++;
- if (code == 0x43 && paramCount == 4 && i+paramCount <= m_Content.Size()) {
+
+ if (code == 0x43 && paramCount == 4 && i + paramCount <= m_Content.Size())
+ {
// Start of colour.
- if (pCurrItem->m_Text.Size() != 0) {
- pCurrItem = pCurrItem->NewItem(); pCurrLine->m_Items.Append(pCurrItem);
+ if (pCurrItem->m_Text.Size() != 0)
+ {
+ pCurrItem = pCurrItem->NewItem();
+ pCurrLine->m_Items.Append(pCurrItem);
}
- pCurrItem->m_Colour = MHRgba(m_Content.GetAt(i), m_Content.GetAt(i+1),
- m_Content.GetAt(i+2), 255-m_Content.GetAt(i+3));
+
+ pCurrItem->m_Colour = MHRgba(m_Content.GetAt(i), m_Content.GetAt(i + 1),
+ m_Content.GetAt(i + 2), 255 - m_Content.GetAt(i + 3));
// Push this colour onto the colour stack.
m_ColourStack.Push(pCurrItem->m_Colour);
}
- else MHLOG(MHLogWarning, QString("Unknown text escape code 0x%1").arg(code,2, 16));
+ else
+ {
+ MHLOG(MHLogWarning, QString("Unknown text escape code 0x%1").arg(code, 2, 16));
+ }
+
i += paramCount; // Skip the parameters
}
- else if (code >= 0x60 && code <= 0x7e) { // End code.
+ else if (code >= 0x60 && code <= 0x7e) // End code.
+ {
i++;
- if (code == 0x63) {
- if (m_ColourStack.Size() > 1) {
+
+ if (code == 0x63)
+ {
+ if (m_ColourStack.Size() > 1)
+ {
m_ColourStack.Pop();
+
// Start a new item since we're using a new colour.
- if (pCurrItem->m_Text.Size() != 0) {
+ if (pCurrItem->m_Text.Size() != 0)
+ {
pCurrItem = pCurrItem->NewItem();
pCurrLine->m_Items.Append(pCurrItem);
}
+
// Set the subsequent text in the colour we're using now.
pCurrItem->m_Colour = m_ColourStack.Top();
}
@@ -407,15 +649,22 @@ void MHText::Redraw()
}
}
- else if (ch <= 0x1f) {
+ else if (ch <= 0x1f)
+ {
// Certain characters including LF and the marker codes between 0x1c and 0x1f are
// explicitly intended to be ignored. Include all the other codes.
}
- else { // Add to the current text.
- int nStart = i-1;
- while (i < m_Content.Size() && m_Content.GetAt(i) >= 0x20) i++;
- pCurrItem->m_Text.Append(MHOctetString(m_Content, nStart, i-nStart));
+ else // Add to the current text.
+ {
+ int nStart = i - 1;
+
+ while (i < m_Content.Size() && m_Content.GetAt(i) >= 0x20)
+ {
+ i++;
+ }
+
+ pCurrItem->m_Text.Append(MHOctetString(m_Content, nStart, i - nStart));
}
}
@@ -426,63 +675,106 @@ void MHText::Redraw()
m_pDisplay->SetFont(size, (style & 2) != 0, (style & 1) != 0);
// Calculate the layout of each section.
- for (i = 0; i < theText.Size(); i++) {
+ for (i = 0; i < theText.Size(); i++)
+ {
MHTextLine *pLine = theText.GetAt(i);
pLine->m_nLineWidth = 0;
- for (int j = 0; j < pLine->m_Items.Size(); j++) {
+
+ for (int j = 0; j < pLine->m_Items.Size(); j++)
+ {
MHTextItem *pItem = pLine->m_Items.GetAt(j);
+
// Set any tabs.
- for (int k = 0; k < pItem->m_nTabCount; k++) pLine->m_nLineWidth += TABSTOP - pLine->m_nLineWidth % TABSTOP;
+ for (int k = 0; k < pItem->m_nTabCount; k++)
+ {
+ pLine->m_nLineWidth += TABSTOP - pLine->m_nLineWidth % TABSTOP;
+ }
- if (pItem->m_Unicode.isEmpty()) { // Convert UTF-8 to Unicode.
+ if (pItem->m_Unicode.isEmpty()) // Convert UTF-8 to Unicode.
+ {
int s = pItem->m_Text.Size();
- pItem->m_Unicode = QString::fromUtf8((const char*)pItem->m_Text.Bytes(), s);
+ pItem->m_Unicode = QString::fromUtf8((const char *)pItem->m_Text.Bytes(), s);
pItem->m_nUnicode = pItem->m_Unicode.length();
}
+
// Fit the text onto the line.
int nFullText = pItem->m_nUnicode;
// Get the box size and update pItem->m_nUnicode to the number that will fit.
QRect rect = m_pDisplay->GetBounds(pItem->m_Unicode, pItem->m_nUnicode, m_nBoxWidth - pLine->m_nLineWidth);
- if (nFullText != pItem->m_nUnicode && m_fTextWrap) { // Doesn't fit, we have to word-wrap.
+ if (nFullText != pItem->m_nUnicode && m_fTextWrap) // Doesn't fit, we have to word-wrap.
+ {
int nTruncated = pItem->m_nUnicode; // Just in case.
// Now remove characters until we find a word-break character.
- while (pItem->m_nUnicode > 0 && pItem->m_Unicode[pItem->m_nUnicode] != ' ') pItem->m_nUnicode--;
+ while (pItem->m_nUnicode > 0 && pItem->m_Unicode[pItem->m_nUnicode] != ' ')
+ {
+ pItem->m_nUnicode--;
+ }
+
// If there are now word-break characters we truncate the text.
- if (pItem->m_nUnicode == 0) pItem->m_nUnicode = nTruncated;
+ if (pItem->m_nUnicode == 0)
+ {
+ pItem->m_nUnicode = nTruncated;
+ }
+
// Special case to avoid infinite loop if the box is very narrow.
- if (pItem->m_nUnicode == 0) pItem->m_nUnicode = 1;
+ if (pItem->m_nUnicode == 0)
+ {
+ pItem->m_nUnicode = 1;
+ }
// We need to move the text we've cut off this line into a new line.
int nNewWidth = nFullText - pItem->m_nUnicode;
int nNewStart = pItem->m_nUnicode;
+
// Remove any spaces at the start of the new section.
- while (nNewWidth != 0 && pItem->m_Unicode[nNewStart] == ' ') { nNewStart++; nNewWidth--; }
- if (nNewWidth != 0) {
+ while (nNewWidth != 0 && pItem->m_Unicode[nNewStart] == ' ')
+ {
+ nNewStart++;
+ nNewWidth--;
+ }
+
+ if (nNewWidth != 0)
+ {
// Create a new line from the extra text.
MHTextLine *pNewLine = new MHTextLine;
- theText.InsertAt(pNewLine, i+1);
+ theText.InsertAt(pNewLine, i + 1);
// The first item on the new line is the rest of the text.
MHTextItem *pNewItem = pItem->NewItem();
pNewLine->m_Items.Append(pNewItem);
pNewItem->m_Unicode = pItem->m_Unicode.mid(nNewStart, nNewWidth);
pNewItem->m_nUnicode = nNewWidth;
+
// Move any remaining items, e.g. in a different colour, from this line onto the new line.
- while (pLine->m_Items.Size() > j+1) {
- pNewLine->m_Items.Append(pLine->m_Items.GetAt(j+1));
- pLine->m_Items.RemoveAt(j+1);
+ while (pLine->m_Items.Size() > j + 1)
+ {
+ pNewLine->m_Items.Append(pLine->m_Items.GetAt(j + 1));
+ pLine->m_Items.RemoveAt(j + 1);
}
}
+
// Remove any spaces at the end of the old section. If we don't do that and
// we are centering or right aligning the text we'll get it wrong.
- while (pItem->m_nUnicode > 1 && pItem->m_Unicode[pItem->m_nUnicode-1] == ' ') pItem->m_nUnicode--;
+ while (pItem->m_nUnicode > 1 && pItem->m_Unicode[pItem->m_nUnicode-1] == ' ')
+ {
+ pItem->m_nUnicode--;
+ }
+
rect = m_pDisplay->GetBounds(pItem->m_Unicode, pItem->m_nUnicode);
}
pItem->m_Width = rect.width();
pLine->m_nLineWidth += rect.width();
- if (rect.height() > pLine->m_nLineHeight) pLine->m_nLineHeight = rect.height();
- if (rect.bottom() > pLine->m_nDescent) pLine->m_nDescent = rect.bottom();
+
+ if (rect.height() > pLine->m_nLineHeight)
+ {
+ pLine->m_nLineHeight = rect.height();
+ }
+
+ if (rect.bottom() > pLine->m_nDescent)
+ {
+ pLine->m_nDescent = rect.bottom();
+ }
}
}
@@ -490,56 +782,103 @@ void MHText::Redraw()
int yOffset = 0;
// If there isn't space for all the lines we should drop extra lines.
int nNumLines = theText.Size();
- do {
- if (m_VertJ == End) yOffset = m_nBoxHeight - nNumLines * lineSpace;
- else if (m_VertJ == Centre) yOffset = (m_nBoxHeight - nNumLines * lineSpace)/2;
- if (yOffset < 0) nNumLines--;
- } while (yOffset < 0);
- for (i = 0; i < nNumLines; i++) {
+ do
+ {
+ if (m_VertJ == End)
+ {
+ yOffset = m_nBoxHeight - nNumLines * lineSpace;
+ }
+ else if (m_VertJ == Centre)
+ {
+ yOffset = (m_nBoxHeight - nNumLines * lineSpace) / 2;
+ }
+
+ if (yOffset < 0)
+ {
+ nNumLines--;
+ }
+ }
+ while (yOffset < 0);
+
+ for (i = 0; i < nNumLines; i++)
+ {
MHTextLine *pLine = theText.GetAt(i);
int xOffset = 0;
- if (m_HorizJ == End) xOffset = m_nBoxWidth - pLine->m_nLineWidth;
- else if (m_HorizJ == Centre) xOffset = (m_nBoxWidth - pLine->m_nLineWidth)/2;
- for (int j = 0; j < pLine->m_Items.Size(); j++) {
+ if (m_HorizJ == End)
+ {
+ xOffset = m_nBoxWidth - pLine->m_nLineWidth;
+ }
+ else if (m_HorizJ == Centre)
+ {
+ xOffset = (m_nBoxWidth - pLine->m_nLineWidth) / 2;
+ }
+
+ for (int j = 0; j < pLine->m_Items.Size(); j++)
+ {
MHTextItem *pItem = pLine->m_Items.GetAt(j);
+
// Tab across if necessary.
- for (int k = 0; k < pItem->m_nTabCount; k++) xOffset += TABSTOP - xOffset % TABSTOP;
+ for (int k = 0; k < pItem->m_nTabCount; k++)
+ {
+ xOffset += TABSTOP - xOffset % TABSTOP;
+ }
- if (! pItem->m_Unicode.isEmpty()) { // We may have blank lines.
- m_pDisplay->AddText(xOffset, yOffset + (pLine->m_nLineHeight + lineSpace)/2 - pLine->m_nDescent,
- pItem->m_Unicode.left(pItem->m_nUnicode), pItem->m_Colour);
+ if (! pItem->m_Unicode.isEmpty()) // We may have blank lines.
+ {
+ m_pDisplay->AddText(xOffset, yOffset + (pLine->m_nLineHeight + lineSpace) / 2 - pLine->m_nDescent,
+ pItem->m_Unicode.left(pItem->m_nUnicode), pItem->m_Colour);
}
+
xOffset += pItem->m_Width;
}
+
yOffset += lineSpace;
- if (yOffset + lineSpace > m_nBoxHeight) break;
+
+ if (yOffset + lineSpace > m_nBoxHeight)
+ {
+ break;
+ }
}
// Clean up.
- for (int k = 0; k < theText.Size(); k++) delete(theText.GetAt(k));
+ for (int k = 0; k < theText.Size(); k++)
+ {
+ delete(theText.GetAt(k));
+ }
}
void MHText::Display(MHEngine *engine)
{
- if (! m_fRunning || ! m_pDisplay || m_nBoxWidth == 0 || m_nBoxHeight == 0) return; // Can't draw zero sized boxes.
+ if (! m_fRunning || ! m_pDisplay || m_nBoxWidth == 0 || m_nBoxHeight == 0)
+ {
+ return; // Can't draw zero sized boxes.
+ }
+
// We only need to recreate the display if something has changed.
- if ( m_fNeedsRedraw)
+ if (m_fNeedsRedraw)
{
Redraw();
m_fNeedsRedraw = false;
}
+
// Draw the background first, then the text.
engine->GetContext()->DrawRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight, GetColour(m_bgColour));
m_pDisplay->Draw(m_nPosX, m_nPosY);
}
-// Return the area actually obscured. This is empty unless the background is opaque.
+// Return the area actually obscured. This is empty unless the background is opaque.
QRegion MHText::GetOpaqueArea()
{
- if (! m_fRunning || (GetColour(m_bgColour)).alpha() != 255) return QRegion();
- else return QRegion(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
+ if (! m_fRunning || (GetColour(m_bgColour)).alpha() != 255)
+ {
+ return QRegion();
+ }
+ else
+ {
+ return QRegion(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
+ }
}
@@ -562,11 +901,13 @@ void MHHyperText::Initialise(MHParseNode *p, MHEngine *engine)
void MHHyperText::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:HyperText ");
- MHText::PrintMe(fd, nTabs+1);
- MHInteractible::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:HyperText ");
+ MHText::PrintMe(fd, nTabs + 1);
+ MHInteractible::PrintMe(fd, nTabs + 1);
fprintf(fd, "****TODO\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
diff --git a/mythtv/libs/libmythfreemheg/Text.h b/mythtv/libs/libmythfreemheg/Text.h
index 9387467d847..192591cbe50 100644
--- a/mythtv/libs/libmythfreemheg/Text.h
+++ b/mythtv/libs/libmythfreemheg/Text.h
@@ -36,7 +36,7 @@ class MHTextDisplay;
class MHText : public MHVisible
{
-public:
+ public:
MHText();
MHText(const MHText &ref);
~MHText();
@@ -65,7 +65,7 @@ class MHText : public MHVisible
virtual void Display(MHEngine *d);
virtual QRegion GetOpaqueArea();
-protected:
+ protected:
void Redraw();
MHFontBody m_OrigFont;
@@ -92,7 +92,7 @@ class MHText : public MHVisible
class MHHyperText : public MHText, public MHInteractible
{
-public:
+ public:
MHHyperText();
virtual const char *ClassName() { return "HyperText"; }
virtual ~MHHyperText();
@@ -112,33 +112,33 @@ class MHHyperText : public MHText, public MHInteractible
// Get Text Data - get the data out of a text object.
class MHGetTextData: public MHActionObjectRef
{
-public:
+ public:
MHGetTextData(): MHActionObjectRef(":GetTextData") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg) { pTarget->GetTextData(pArg, engine); }
};
// Actions added in UK MHEG profile.
class MHSetBackgroundColour: public MHSetColour {
-public:
+ public:
MHSetBackgroundColour(): MHSetColour(":SetBackgroundColour") { }
-protected:
+ protected:
virtual void SetColour(const MHColour &colour, MHEngine *engine) { Target(engine)->SetBackgroundColour(colour, engine); }
};
class MHSetTextColour: public MHSetColour {
-public:
+ public:
MHSetTextColour(): MHSetColour(":SetTextColour") { }
-protected:
+ protected:
virtual void SetColour(const MHColour &colour, MHEngine *engine) { Target(engine)->SetTextColour(colour, engine); }
};
class MHSetFontAttributes: public MHElemAction
{
-public:
+ public:
MHSetFontAttributes(): MHElemAction(":SetFontAttributes") {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int /*nTabs*/) const { m_FontAttrs.PrintMe(fd, 0); }
MHGenericOctetString m_FontAttrs; // New font attributes.
};
diff --git a/mythtv/libs/libmythfreemheg/TokenGroup.cpp b/mythtv/libs/libmythfreemheg/TokenGroup.cpp
index c3def55b75a..b24160b24b3 100644
--- a/mythtv/libs/libmythfreemheg/TokenGroup.cpp
+++ b/mythtv/libs/libmythfreemheg/TokenGroup.cpp
@@ -33,46 +33,84 @@ void MHTokenGroupItem::Initialise(MHParseNode *p, MHEngine *engine)
{
// A pair consisting of an object reference and an optional action slot sequence.
m_Object.Initialise(p->GetSeqN(0), engine);
- if (p->GetSeqCount() > 1) {
+
+ if (p->GetSeqCount() > 1)
+ {
MHParseNode *pSlots = p->GetSeqN(1);
- for (int i = 0; i < pSlots->GetSeqCount(); i++) {
+
+ for (int i = 0; i < pSlots->GetSeqCount(); i++)
+ {
MHParseNode *pAct = pSlots->GetSeqN(i);
MHActionSequence *pActions = new MHActionSequence;
m_ActionSlots.Append(pActions);
+
// The action slot entry may be NULL.
- if (pAct->m_nNodeType != MHParseNode::PNNull) pActions->Initialise(pAct, engine);
+ if (pAct->m_nNodeType != MHParseNode::PNNull)
+ {
+ pActions->Initialise(pAct, engine);
+ }
}
}
}
void MHTokenGroupItem::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "( ");
- m_Object.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
- if (m_ActionSlots.Size() != 0) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":ActionSlots (\n");
- for (int i = 0; i < m_ActionSlots.Size(); i++) {
- PrintTabs(fd, nTabs+2); fprintf(fd, "(\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "( ");
+ m_Object.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+
+ if (m_ActionSlots.Size() != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":ActionSlots (\n");
+
+ for (int i = 0; i < m_ActionSlots.Size(); i++)
+ {
+ PrintTabs(fd, nTabs + 2);
+ fprintf(fd, "(\n");
MHActionSequence *pActions = m_ActionSlots.GetAt(i);
- if (pActions->Size() == 0)
- { PrintTabs(fd, nTabs+2); fprintf(fd, "NULL\n"); }
- else pActions->PrintMe(fd, nTabs+2);
- PrintTabs(fd, nTabs+2); fprintf(fd, ")\n");
+
+ if (pActions->Size() == 0)
+ {
+ PrintTabs(fd, nTabs + 2);
+ fprintf(fd, "NULL\n");
+ }
+ else
+ {
+ pActions->PrintMe(fd, nTabs + 2);
+ }
+
+ PrintTabs(fd, nTabs + 2);
+ fprintf(fd, ")\n");
}
- PrintTabs(fd, nTabs+1); fprintf(fd, ")\n");
+
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ")\n");
}
- PrintTabs(fd, nTabs); fprintf(fd, ")\n");
+
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ")\n");
}
void MHMovement::Initialise(MHParseNode *p, MHEngine * /*engine*/)
{
- for (int i = 0; i < p->GetSeqCount(); i++) m_Movement.Append(p->GetSeqN(i)->GetIntValue());
+ for (int i = 0; i < p->GetSeqCount(); i++)
+ {
+ m_Movement.Append(p->GetSeqN(i)->GetIntValue());
+ }
}
void MHMovement::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "( ");
- for (int i = 0; i < m_Movement.Size(); i++) fprintf(fd, "%d ", m_Movement.GetAt(i));
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "( ");
+
+ for (int i = 0; i < m_Movement.Size(); i++)
+ {
+ fprintf(fd, "%d ", m_Movement.GetAt(i));
+ }
+
fprintf(fd, ")\n");
}
@@ -85,29 +123,44 @@ void MHTokenGroup::Initialise(MHParseNode *p, MHEngine *engine)
{
MHPresentable::Initialise(p, engine);
MHParseNode *pMovements = p->GetNamedArg(C_MOVEMENT_TABLE);
- if (pMovements) {
- for (int i = 0; i < pMovements->GetArgCount(); i++) {
+
+ if (pMovements)
+ {
+ for (int i = 0; i < pMovements->GetArgCount(); i++)
+ {
MHMovement *pMove = new MHMovement;
m_MovementTable.Append(pMove);
pMove->Initialise(pMovements->GetArgN(i), engine);
}
}
+
MHParseNode *pTokenGrp = p->GetNamedArg(C_TOKEN_GROUP_ITEMS);
- if (pTokenGrp) {
- for (int i = 0; i < pTokenGrp->GetArgCount(); i++) {
+
+ if (pTokenGrp)
+ {
+ for (int i = 0; i < pTokenGrp->GetArgCount(); i++)
+ {
MHTokenGroupItem *pToken = new MHTokenGroupItem;
m_TokenGrpItems.Append(pToken);
pToken->Initialise(pTokenGrp->GetArgN(i), engine);
}
}
+
MHParseNode *pNoToken = p->GetNamedArg(C_NO_TOKEN_ACTION_SLOTS);
- if (pNoToken) {
- for (int i = 0; i < pNoToken->GetArgCount(); i++) {
+
+ if (pNoToken)
+ {
+ for (int i = 0; i < pNoToken->GetArgCount(); i++)
+ {
MHParseNode *pAct = pNoToken->GetArgN(i);
MHActionSequence *pActions = new MHActionSequence;
m_NoTokenActionSlots.Append(pActions);
+
// The action slot entry may be NULL.
- if (pAct->m_nNodeType != MHParseNode::PNNull) pActions->Initialise(pAct, engine);
+ if (pAct->m_nNodeType != MHParseNode::PNNull)
+ {
+ pActions->Initialise(pAct, engine);
+ }
}
}
}
@@ -115,58 +168,99 @@ void MHTokenGroup::Initialise(MHParseNode *p, MHEngine *engine)
// This is used to print the contents of the token group.
void MHTokenGroup::PrintContents(FILE *fd, int nTabs) const
{
- MHPresentable::PrintMe(fd, nTabs+1);
- if (m_MovementTable.Size() != 0) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":MovementTable (\n");
- for (int i = 0; i < m_MovementTable.Size(); i++) {
- m_MovementTable.GetAt(i)->PrintMe(fd, nTabs+2);
+ MHPresentable::PrintMe(fd, nTabs + 1);
+
+ if (m_MovementTable.Size() != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":MovementTable (\n");
+
+ for (int i = 0; i < m_MovementTable.Size(); i++)
+ {
+ m_MovementTable.GetAt(i)->PrintMe(fd, nTabs + 2);
}
- PrintTabs(fd, nTabs+1); fprintf(fd, ")\n");
+
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ")\n");
}
- if (m_TokenGrpItems.Size() != 0) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":TokenGroupItems (\n");
- for (int i = 0; i < m_TokenGrpItems.Size(); i++) {
- m_TokenGrpItems.GetAt(i)->PrintMe(fd, nTabs+2);
+
+ if (m_TokenGrpItems.Size() != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":TokenGroupItems (\n");
+
+ for (int i = 0; i < m_TokenGrpItems.Size(); i++)
+ {
+ m_TokenGrpItems.GetAt(i)->PrintMe(fd, nTabs + 2);
}
- PrintTabs(fd, nTabs+1); fprintf(fd, ")\n");
+
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ")\n");
}
- if (m_NoTokenActionSlots.Size() != 0) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":NoTokenActionSlots (\n");
- for (int i = 0; i < m_NoTokenActionSlots.Size(); i++) {
+
+ if (m_NoTokenActionSlots.Size() != 0)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":NoTokenActionSlots (\n");
+
+ for (int i = 0; i < m_NoTokenActionSlots.Size(); i++)
+ {
MHActionSequence *pActions = m_NoTokenActionSlots.GetAt(i);
- if (pActions->Size() == 0) { PrintTabs(fd, nTabs+2); fprintf(fd, "NULL "); }
- else pActions->PrintMe(fd, nTabs+2);
+
+ if (pActions->Size() == 0)
+ {
+ PrintTabs(fd, nTabs + 2);
+ fprintf(fd, "NULL ");
+ }
+ else
+ {
+ pActions->PrintMe(fd, nTabs + 2);
+ }
}
- PrintTabs(fd, nTabs+1); fprintf(fd, ")\n");
+
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ")\n");
}
}
void MHTokenGroup::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:TokenGroup ");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:TokenGroup ");
PrintContents(fd, nTabs);
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
// Activate the token group following the standard.
void MHTokenGroup::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHPresentable::Activation(engine);
+
// We're supposed to apply Activation to each of the "items" but it isn't clear
// exactly what that means. Assume it means each of the visibles.
- for (int i = 0; i < m_TokenGrpItems.Size(); i++) {
+ for (int i = 0; i < m_TokenGrpItems.Size(); i++)
+ {
MHObjectRef *pObject = &m_TokenGrpItems.GetAt(i)->m_Object;
+
// The object reference may be the null reference.
// Worse: it seems that sometimes in BBC's MHEG the reference simply doesn't exist.
if (pObject->IsSet())
{
- try {
+ try
+ {
engine->FindObject(m_TokenGrpItems.GetAt(i)->m_Object)->Activation(engine);
- } catch (char const *) {}
+ }
+ catch (char const *) {}
}
}
+
engine->EventTriggered(this, EventTokenMovedTo, m_nTokenPosition);
m_fRunning = true;
engine->EventTriggered(this, EventIsRunning);
@@ -174,7 +268,11 @@ void MHTokenGroup::Activation(MHEngine *engine)
void MHTokenGroup::Deactivation(MHEngine *engine)
{
- if (! m_fRunning) return;
+ if (! m_fRunning)
+ {
+ return;
+ }
+
engine->EventTriggered(this, EventTokenMovedFrom, m_nTokenPosition);
MHPresentable::Deactivation(engine);
}
@@ -182,7 +280,8 @@ void MHTokenGroup::Deactivation(MHEngine *engine)
// Internal function to generate the appropriate events.
void MHTokenGroup::TransferToken(int newPos, MHEngine *engine)
{
- if (newPos != m_nTokenPosition) {
+ if (newPos != m_nTokenPosition)
+ {
engine->EventTriggered(this, EventTokenMovedFrom, m_nTokenPosition);
m_nTokenPosition = newPos;
engine->EventTriggered(this, EventTokenMovedTo, m_nTokenPosition);
@@ -192,23 +291,37 @@ void MHTokenGroup::TransferToken(int newPos, MHEngine *engine)
// Perform the actions depending on where the token is.
void MHTokenGroup::CallActionSlot(int n, MHEngine *engine)
{
- if (m_nTokenPosition == 0) { // No slot has the token.
+ if (m_nTokenPosition == 0) // No slot has the token.
+ {
if (n > 0 && n <= m_NoTokenActionSlots.Size())
- engine->AddActions(*(m_NoTokenActionSlots.GetAt(n-1)));
+ {
+ engine->AddActions(*(m_NoTokenActionSlots.GetAt(n - 1)));
+ }
}
- else {
- if (m_nTokenPosition > 0 && m_nTokenPosition <= m_TokenGrpItems.Size()) {
- MHTokenGroupItem *pGroup = m_TokenGrpItems.GetAt(m_nTokenPosition-1);
+ else
+ {
+ if (m_nTokenPosition > 0 && m_nTokenPosition <= m_TokenGrpItems.Size())
+ {
+ MHTokenGroupItem *pGroup = m_TokenGrpItems.GetAt(m_nTokenPosition - 1);
+
if (n > 0 && n <= pGroup->m_ActionSlots.Size())
- engine->AddActions(*(pGroup->m_ActionSlots.GetAt(n-1)));
+ {
+ engine->AddActions(*(pGroup->m_ActionSlots.GetAt(n - 1)));
+ }
}
}
}
void MHTokenGroup::Move(int n, MHEngine *engine)
{
- if (m_nTokenPosition == 0 || n < 1 || n > m_MovementTable.Size()) TransferToken(0, engine); // Not in the standard
- else TransferToken(m_MovementTable.GetAt(n-1)->m_Movement.GetAt(m_nTokenPosition-1), engine);
+ if (m_nTokenPosition == 0 || n < 1 || n > m_MovementTable.Size())
+ {
+ TransferToken(0, engine); // Not in the standard
+ }
+ else
+ {
+ TransferToken(m_MovementTable.GetAt(n - 1)->m_Movement.GetAt(m_nTokenPosition - 1), engine);
+ }
}
// ListGroup. This is a complex class and the description was extensively revised in the MHEG corrigendum.
@@ -225,59 +338,102 @@ MHListGroup::MHListGroup()
MHListGroup::~MHListGroup()
{
while (!m_ItemList.isEmpty())
+ {
delete m_ItemList.takeFirst();
+ }
}
void MHListGroup::Initialise(MHParseNode *p, MHEngine *engine)
{
MHTokenGroup::Initialise(p, engine);
MHParseNode *pPositions = p->GetNamedArg(C_POSITIONS);
- if (pPositions) {
- for (int i = 0; i < pPositions->GetArgCount(); i++) {
+
+ if (pPositions)
+ {
+ for (int i = 0; i < pPositions->GetArgCount(); i++)
+ {
MHParseNode *pPos = pPositions->GetArgN(i);
QPoint pos(pPos->GetSeqN(0)->GetIntValue(), pPos->GetSeqN(1)->GetIntValue());
m_Positions.Append(pos);
}
}
+
MHParseNode *pWrap = p->GetNamedArg(C_WRAP_AROUND);
- if (pWrap) m_fWrapAround = pWrap->GetArgN(0)->GetBoolValue();
+
+ if (pWrap)
+ {
+ m_fWrapAround = pWrap->GetArgN(0)->GetBoolValue();
+ }
+
MHParseNode *pMultiple = p->GetNamedArg(C_WRAP_AROUND);
- if (pMultiple) m_fMultipleSelection = pMultiple->GetArgN(0)->GetBoolValue();
+
+ if (pMultiple)
+ {
+ m_fMultipleSelection = pMultiple->GetArgN(0)->GetBoolValue();
+ }
}
void MHListGroup::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:ListGroup ");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:ListGroup ");
MHTokenGroup::PrintContents(fd, nTabs);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":Positions (");
- for (int i = 0; i < m_Positions.Size(); i++) {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":Positions (");
+
+ for (int i = 0; i < m_Positions.Size(); i++)
+ {
fprintf(fd, " ( %d %d )", m_Positions.GetAt(i).x(), m_Positions.GetAt(i).y());
}
+
fprintf(fd, ")\n");
- if (m_fWrapAround) { PrintTabs(fd, nTabs+1); fprintf(fd, ":WrapAround true\n"); }
- if (m_fMultipleSelection) { PrintTabs(fd, nTabs+1); fprintf(fd, ":MultipleSelection true\n"); }
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+
+ if (m_fWrapAround)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":WrapAround true\n");
+ }
+
+ if (m_fMultipleSelection)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":MultipleSelection true\n");
+ }
+
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHListGroup::Preparation(MHEngine *engine)
{
MHTokenGroup::Preparation(engine);
- for (int i = 0; i < m_TokenGrpItems.Size(); i++) {
+
+ for (int i = 0; i < m_TokenGrpItems.Size(); i++)
+ {
// Find the item and add it to the list if it isn't already there.
- try {
- MHRoot *pItem = (MHRoot*)engine->FindObject(m_TokenGrpItems.GetAt(i)->m_Object);
+ try
+ {
+ MHRoot *pItem = (MHRoot *)engine->FindObject(m_TokenGrpItems.GetAt(i)->m_Object);
MHListItem *p = 0;
- QList::iterator it = m_ItemList.begin();
+ QList::iterator it = m_ItemList.begin();
+
for (; it != m_ItemList.end(); ++it)
{
p = *it;
+
if (p->m_pVisible == pItem)
+ {
break;
+ }
}
+
if (!p)
+ {
m_ItemList.append(new MHListItem(pItem));
+ }
}
- catch(...) { // Ignore invalid or null objects.
+ catch (...) // Ignore invalid or null objects.
+ {
}
}
}
@@ -286,7 +442,10 @@ void MHListGroup::Destruction(MHEngine *engine)
{
// Reset the positions of the visibles.
for (int j = 0; j < m_ItemList.size(); j++)
+ {
m_ItemList.at(j)->m_pVisible->ResetPosition();
+ }
+
MHTokenGroup::Destruction(engine);
}
@@ -302,7 +461,10 @@ void MHListGroup::Deactivation(MHEngine *engine)
{
// Deactivate the visibles.
for (int j = 0; j < m_ItemList.size(); j++)
+ {
m_ItemList.at(j)->m_pVisible->Deactivation(engine);
+ }
+
MHTokenGroup::Deactivation(engine);
}
@@ -310,55 +472,87 @@ void MHListGroup::Deactivation(MHEngine *engine)
// which aren't.
void MHListGroup::Update(MHEngine *engine)
{
- if (!m_ItemList.size()) { // Special cases when the list becomes empty
- if (m_fFirstItemDisplayed) {
+ if (!m_ItemList.size()) // Special cases when the list becomes empty
+ {
+ if (m_fFirstItemDisplayed)
+ {
m_fFirstItemDisplayed = false;
engine->EventTriggered(this, EventFirstItemPresented, false);
}
- if (m_fLastItemDisplayed) {
+
+ if (m_fLastItemDisplayed)
+ {
m_fLastItemDisplayed = false;
engine->EventTriggered(this, EventLastItemPresented, false);
}
}
- else { // Usual case.
- for (int i = 0; i < m_ItemList.size(); i++) {
+ else // Usual case.
+ {
+ for (int i = 0; i < m_ItemList.size(); i++)
+ {
MHRoot *pVis = m_ItemList.at(i)->m_pVisible;
- int nCell = i+1 - m_nFirstItem; // Which cell does this item map onto?
- if (nCell >= 0 && nCell < m_Positions.Size()) {
- if (i == 0 && ! m_fFirstItemDisplayed) {
+ int nCell = i + 1 - m_nFirstItem; // Which cell does this item map onto?
+
+ if (nCell >= 0 && nCell < m_Positions.Size())
+ {
+ if (i == 0 && ! m_fFirstItemDisplayed)
+ {
m_fFirstItemDisplayed = true;
engine->EventTriggered(this, EventFirstItemPresented, true);
}
- if (i == m_ItemList.size()-1 && ! m_fLastItemDisplayed) {
+
+ if (i == m_ItemList.size() - 1 && ! m_fLastItemDisplayed)
+ {
m_fLastItemDisplayed = true;
engine->EventTriggered(this, EventLastItemPresented, true);
}
- try {
- pVis->SetPosition(m_Positions.GetAt(i-m_nFirstItem+1).x(), m_Positions.GetAt(i-m_nFirstItem+1).y(), engine);
- } catch(...) {}
- if (! pVis->GetRunningStatus()) pVis->Activation(engine);
+
+ try
+ {
+ pVis->SetPosition(m_Positions.GetAt(i - m_nFirstItem + 1).x(), m_Positions.GetAt(i - m_nFirstItem + 1).y(), engine);
+ }
+ catch (...) {}
+
+ if (! pVis->GetRunningStatus())
+ {
+ pVis->Activation(engine);
+ }
}
- else {
- if (i == 0 && m_fFirstItemDisplayed) {
+ else
+ {
+ if (i == 0 && m_fFirstItemDisplayed)
+ {
m_fFirstItemDisplayed = false;
engine->EventTriggered(this, EventFirstItemPresented, false);
}
- if (i == m_ItemList.size()-1 && m_fLastItemDisplayed) {
+
+ if (i == m_ItemList.size() - 1 && m_fLastItemDisplayed)
+ {
m_fLastItemDisplayed = false;
engine->EventTriggered(this, EventLastItemPresented, false);
}
- if (pVis->GetRunningStatus()) { pVis->Deactivation(engine); pVis->ResetPosition(); }
+
+ if (pVis->GetRunningStatus())
+ {
+ pVis->Deactivation(engine);
+ pVis->ResetPosition();
+ }
}
}
}
+
// Generate the HeadItems and TailItems events. Even in the MHEG corrigendum this is unclear.
// I'm not at all sure this is right.
- if (m_nLastFirstItem != m_nFirstItem) {
+ if (m_nLastFirstItem != m_nFirstItem)
+ {
engine->EventTriggered(this, EventHeadItems, m_nFirstItem);
}
- if (m_nLastCount - m_nLastFirstItem != m_ItemList.size() - m_nFirstItem) {
+
+ if (m_nLastCount - m_nLastFirstItem != m_ItemList.size() - m_nFirstItem)
+ {
engine->EventTriggered(this, EventTailItems, m_ItemList.size() - m_nFirstItem);
}
+
m_nLastCount = m_ItemList.size();
m_nLastFirstItem = m_nFirstItem;
}
@@ -367,16 +561,30 @@ void MHListGroup::Update(MHEngine *engine)
void MHListGroup::AddItem(int nIndex, MHRoot *pItem, MHEngine *engine)
{
// See if the item is already there and ignore this if it is.
- QList::iterator it = m_ItemList.begin();
- for (; it != m_ItemList.end(); ++it) {
+ QList::iterator it = m_ItemList.begin();
+
+ for (; it != m_ItemList.end(); ++it)
+ {
if ((*it)->m_pVisible == pItem)
+ {
return;
+ }
}
+
// Ignore this if the index is out of range
- if (nIndex < 1 || nIndex > m_ItemList.size()+1) return;
+ if (nIndex < 1 || nIndex > m_ItemList.size() + 1)
+ {
+ return;
+ }
+
// Insert it at the appropriate position (MHEG indexes count from 1).
- m_ItemList.insert(nIndex-1, new MHListItem(pItem));
- if (nIndex <= m_nFirstItem && m_nFirstItem < m_ItemList.size()) m_nFirstItem++;
+ m_ItemList.insert(nIndex - 1, new MHListItem(pItem));
+
+ if (nIndex <= m_nFirstItem && m_nFirstItem < m_ItemList.size())
+ {
+ m_nFirstItem++;
+ }
+
Update(engine); // Apply the update behaviour
}
@@ -384,11 +592,18 @@ void MHListGroup::AddItem(int nIndex, MHRoot *pItem, MHEngine *engine)
void MHListGroup::DelItem(MHRoot *pItem, MHEngine *)
{
// See if the item is already there and ignore this if it is.
- for (int i = 0; i < m_ItemList.size(); i++) {
- if (m_ItemList.at(i)->m_pVisible == pItem) { // Found it - remove it from the list and reset the posn.
+ for (int i = 0; i < m_ItemList.size(); i++)
+ {
+ if (m_ItemList.at(i)->m_pVisible == pItem) // Found it - remove it from the list and reset the posn.
+ {
delete m_ItemList.takeAt(i);
pItem->ResetPosition();
- if (i+1 < m_nFirstItem && m_nFirstItem > 1) m_nFirstItem--;
+
+ if (i + 1 < m_nFirstItem && m_nFirstItem > 1)
+ {
+ m_nFirstItem--;
+ }
+
return;
}
}
@@ -397,13 +612,23 @@ void MHListGroup::DelItem(MHRoot *pItem, MHEngine *)
// Set the selection status of the item to true
void MHListGroup::Select(int nIndex, MHEngine *engine)
{
- MHListItem *pListItem = m_ItemList.at(nIndex-1);
- if (pListItem == 0 || pListItem->m_fSelected) return; // Ignore if already selected.
- if (! m_fMultipleSelection) {
+ MHListItem *pListItem = m_ItemList.at(nIndex - 1);
+
+ if (pListItem == 0 || pListItem->m_fSelected)
+ {
+ return; // Ignore if already selected.
+ }
+
+ if (! m_fMultipleSelection)
+ {
// Deselect any existing selections.
for (int i = 0; i < m_ItemList.size(); i++)
- if (m_ItemList.at(i)->m_fSelected) Deselect(i+1, engine);
+ if (m_ItemList.at(i)->m_fSelected)
+ {
+ Deselect(i + 1, engine);
+ }
}
+
pListItem->m_fSelected = true;
engine->EventTriggered(this, EventItemSelected, nIndex);
}
@@ -411,8 +636,13 @@ void MHListGroup::Select(int nIndex, MHEngine *engine)
// Set the selection status of the item to false
void MHListGroup::Deselect(int nIndex, MHEngine *engine)
{
- MHListItem *pListItem = m_ItemList.at(nIndex-1);
- if (pListItem == 0 || ! pListItem->m_fSelected) return; // Ignore if not selected.
+ MHListItem *pListItem = m_ItemList.at(nIndex - 1);
+
+ if (pListItem == 0 || ! pListItem->m_fSelected)
+ {
+ return; // Ignore if not selected.
+ }
+
pListItem->m_fSelected = false;
engine->EventTriggered(this, EventItemDeselected, nIndex);
}
@@ -420,73 +650,164 @@ void MHListGroup::Deselect(int nIndex, MHEngine *engine)
// Return the reference to the visible at the particular position.
void MHListGroup::GetCellItem(int nCell, const MHObjectRef &itemDest, MHEngine *engine)
{
- if (nCell < 1) nCell = 1; // First cell
- if (nCell > m_Positions.Size()) nCell = m_Positions.Size(); // Last cell.
+ if (nCell < 1)
+ {
+ nCell = 1; // First cell
+ }
+
+ if (nCell > m_Positions.Size())
+ {
+ nCell = m_Positions.Size(); // Last cell.
+ }
+
int nVisIndex = nCell + m_nFirstItem - 2;
- if (nVisIndex >= 0 && nVisIndex < m_ItemList.size()) {
+
+ if (nVisIndex >= 0 && nVisIndex < m_ItemList.size())
+ {
MHRoot *pVis = m_ItemList.at(nVisIndex)->m_pVisible;
engine->FindObject(itemDest)->SetVariableValue(pVis->m_ObjectReference);
}
- else engine->FindObject(itemDest)->SetVariableValue(MHObjectRef::Null);
+ else
+ {
+ engine->FindObject(itemDest)->SetVariableValue(MHObjectRef::Null);
+ }
}
int MHListGroup::AdjustIndex(int nIndex) // Added in the MHEG corrigendum
{
int nItems = m_ItemList.size();
- if (nItems == 0) return 1;
- if (nIndex > nItems) return ((nIndex-1) % nItems) + 1;
- else if (nIndex < 0) return nItems - ((-nIndex) % nItems);
- else return nIndex;
+
+ if (nItems == 0)
+ {
+ return 1;
+ }
+
+ if (nIndex > nItems)
+ {
+ return ((nIndex - 1) % nItems) + 1;
+ }
+ else if (nIndex < 0)
+ {
+ return nItems - ((-nIndex) % nItems);
+ }
+ else
+ {
+ return nIndex;
+ }
}
void MHListGroup::GetListItem(int nCell, const MHObjectRef &itemDest, MHEngine *engine)
{
- if (m_fWrapAround) nCell = AdjustIndex(nCell);
- if (nCell < 1 || nCell > m_ItemList.size()) return; // Ignore it if it's out of range and not wrapping
- engine->FindObject(itemDest)->SetVariableValue(m_ItemList.at(nCell-1)->m_pVisible->m_ObjectReference);
+ if (m_fWrapAround)
+ {
+ nCell = AdjustIndex(nCell);
+ }
+
+ if (nCell < 1 || nCell > m_ItemList.size())
+ {
+ return; // Ignore it if it's out of range and not wrapping
+ }
+
+ engine->FindObject(itemDest)->SetVariableValue(m_ItemList.at(nCell - 1)->m_pVisible->m_ObjectReference);
}
void MHListGroup::GetItemStatus(int nCell, const MHObjectRef &itemDest, MHEngine *engine)
{
- if (m_fWrapAround) nCell = AdjustIndex(nCell);
- if (nCell < 1 || nCell > m_ItemList.size()) return;
- engine->FindObject(itemDest)->SetVariableValue(m_ItemList.at(nCell-1)->m_fSelected);
+ if (m_fWrapAround)
+ {
+ nCell = AdjustIndex(nCell);
+ }
+
+ if (nCell < 1 || nCell > m_ItemList.size())
+ {
+ return;
+ }
+
+ engine->FindObject(itemDest)->SetVariableValue(m_ItemList.at(nCell - 1)->m_fSelected);
}
void MHListGroup::SelectItem(int nCell, MHEngine *engine)
{
- if (m_fWrapAround) nCell = AdjustIndex(nCell);
- if (nCell < 1 || nCell > m_ItemList.size()) return;
+ if (m_fWrapAround)
+ {
+ nCell = AdjustIndex(nCell);
+ }
+
+ if (nCell < 1 || nCell > m_ItemList.size())
+ {
+ return;
+ }
+
Select(nCell, engine);
}
void MHListGroup::DeselectItem(int nCell, MHEngine *engine)
{
- if (m_fWrapAround) nCell = AdjustIndex(nCell);
- if (nCell < 1 || nCell > m_ItemList.size()) return;
+ if (m_fWrapAround)
+ {
+ nCell = AdjustIndex(nCell);
+ }
+
+ if (nCell < 1 || nCell > m_ItemList.size())
+ {
+ return;
+ }
+
Deselect(nCell, engine);
}
void MHListGroup::ToggleItem(int nCell, MHEngine *engine)
{
- if (m_fWrapAround) nCell = AdjustIndex(nCell);
- if (nCell < 1 || nCell > m_ItemList.size()) return;
- if (m_ItemList.at(nCell-1)->m_fSelected) Deselect(nCell, engine); else Select(nCell, engine);
+ if (m_fWrapAround)
+ {
+ nCell = AdjustIndex(nCell);
+ }
+
+ if (nCell < 1 || nCell > m_ItemList.size())
+ {
+ return;
+ }
+
+ if (m_ItemList.at(nCell - 1)->m_fSelected)
+ {
+ Deselect(nCell, engine);
+ }
+ else
+ {
+ Select(nCell, engine);
+ }
}
void MHListGroup::ScrollItems(int nCell, MHEngine *engine)
{
nCell += m_nFirstItem;
- if (m_fWrapAround) nCell = AdjustIndex(nCell);
- if (nCell < 1 || nCell > m_ItemList.size()) return;
+
+ if (m_fWrapAround)
+ {
+ nCell = AdjustIndex(nCell);
+ }
+
+ if (nCell < 1 || nCell > m_ItemList.size())
+ {
+ return;
+ }
+
m_nFirstItem = nCell;
Update(engine);
}
void MHListGroup::SetFirstItem(int nCell, MHEngine *engine)
{
- if (m_fWrapAround) nCell = AdjustIndex(nCell);
- if (nCell < 1 || nCell > m_ItemList.size()) return;
+ if (m_fWrapAround)
+ {
+ nCell = AdjustIndex(nCell);
+ }
+
+ if (nCell < 1 || nCell > m_ItemList.size())
+ {
+ return;
+ }
+
m_nFirstItem = nCell;
Update(engine);
}
diff --git a/mythtv/libs/libmythfreemheg/TokenGroup.h b/mythtv/libs/libmythfreemheg/TokenGroup.h
index 3da039786ef..893ce33babf 100644
--- a/mythtv/libs/libmythfreemheg/TokenGroup.h
+++ b/mythtv/libs/libmythfreemheg/TokenGroup.h
@@ -38,7 +38,7 @@ class MHEngine;
class MHTokenGroupItem
{
-public:
+ public:
MHTokenGroupItem() {}
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
@@ -48,7 +48,7 @@ class MHTokenGroupItem
class MHMovement
{
-public:
+ public:
void Initialise(MHParseNode *p, MHEngine *engine);
void PrintMe(FILE *fd, int nTabs) const;
MHSequence m_Movement;
@@ -58,7 +58,7 @@ class MHMovement
// this class.
class MHTokenGroup : public MHPresentable
{
-public:
+ public:
MHTokenGroup();
virtual const char *ClassName() { return "TokenGroup"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -73,7 +73,7 @@ class MHTokenGroup : public MHPresentable
virtual void MoveTo(int n, MHEngine *engine) { TransferToken(n, engine); }
virtual void GetTokenPosition(MHRoot *pResult, MHEngine *) { pResult->SetVariableValue(m_nTokenPosition); }
-protected:
+ protected:
void PrintContents(FILE *fd, int nTabs) const;
void TransferToken(int newPos, MHEngine *engine);
@@ -89,7 +89,7 @@ class MHTokenGroup : public MHPresentable
// For simplicity we don't check that we have a Visible and instead use virtual functions
// which only work on visibles.
class MHListItem {
-public:
+ public:
MHListItem(MHRoot *pVis): m_pVisible(pVis), m_fSelected(false) {}
MHRoot *m_pVisible;
bool m_fSelected;
@@ -97,7 +97,7 @@ class MHListItem {
class MHListGroup : public MHTokenGroup
{
-public:
+ public:
MHListGroup();
~MHListGroup();
virtual const char *ClassName() { return "ListGroup"; }
@@ -122,7 +122,7 @@ class MHListGroup : public MHTokenGroup
virtual void GetFirstItem(MHRoot *pResult, MHEngine *) { pResult->SetVariableValue(m_nFirstItem); }
virtual void GetListSize(MHRoot *pResult, MHEngine *) { pResult->SetVariableValue((int)(m_ItemList.size())); }
-protected:
+ protected:
// MHEG Internal attributes.
void Update(MHEngine *engine);
void Select(int nIndex, MHEngine *engine);
@@ -142,7 +142,7 @@ class MHListGroup : public MHTokenGroup
// Call action slot.
class MHCallActionSlot: public MHActionInt
{
-public:
+ public:
MHCallActionSlot(): MHActionInt(":CallActionSlot") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) { pTarget->CallActionSlot(nArg, engine); }
};
@@ -150,7 +150,7 @@ class MHCallActionSlot: public MHActionInt
// Move - move the token in a token group according to the movement table.
class MHMove: public MHActionInt
{
-public:
+ public:
MHMove(): MHActionInt(":Move") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) { pTarget->Move(nArg, engine); }
};
@@ -158,102 +158,102 @@ class MHMove: public MHActionInt
// MoveTo - move the token to a particular slot.
class MHMoveTo: public MHActionInt
{
-public:
+ public:
MHMoveTo(): MHActionInt(":MoveTo") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) { pTarget->MoveTo(nArg, engine); }
};
class MHGetTokenPosition: public MHActionObjectRef {
-public:
+ public:
MHGetTokenPosition(): MHActionObjectRef(":GetTokenPosition") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg) { pTarget->GetTokenPosition(pArg, engine); }
};
class MHAddItem: public MHElemAction {
-public:
+ public:
MHAddItem(): MHElemAction(":AddItem") {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintArgs(FILE *fd, int) const;
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
MHGenericInteger m_Index;
MHGenericObjectRef m_Item;
};
class MHDelItem: public MHActionGenericObjectRef {
-public:
+ public:
MHDelItem(): MHActionGenericObjectRef(":DelItem") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pObj) { pTarget->DelItem(pObj, engine); }
};
// Base class for a few actions.
class MHGetListActionData: public MHElemAction {
-public:
+ public:
MHGetListActionData(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void PrintArgs(FILE *fd, int) const;
-protected:
+ protected:
MHGenericInteger m_Index;
MHObjectRef m_Result;
};
class MHGetCellItem: public MHGetListActionData {
-public:
+ public:
MHGetCellItem(): MHGetListActionData(":GetCellItem") {}
virtual void Perform(MHEngine *engine) { Target(engine)->GetCellItem(m_Index.GetValue(engine), m_Result, engine); }
};
class MHGetListItem: public MHGetListActionData {
-public:
+ public:
MHGetListItem(): MHGetListActionData(":GetListItem") {}
virtual void Perform(MHEngine *engine) { Target(engine)->GetListItem(m_Index.GetValue(engine), m_Result, engine); }
};
class MHGetItemStatus: public MHGetListActionData {
-public:
+ public:
MHGetItemStatus(): MHGetListActionData(":GetItemStatus") {}
virtual void Perform(MHEngine *engine) { Target(engine)->GetItemStatus(m_Index.GetValue(engine), m_Result, engine); }
};
class MHSelectItem: public MHActionInt {
-public:
+ public:
MHSelectItem(): MHActionInt(":SelectItem") {}
virtual void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, int nArg) { Target(engine)->SelectItem(nArg, engine); }
};
class MHDeselectItem: public MHActionInt {
-public:
+ public:
MHDeselectItem(): MHActionInt(":DeselectItem") {}
virtual void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, int nArg) { Target(engine)->DeselectItem(nArg, engine); }
};
class MHToggleItem: public MHActionInt {
-public:
+ public:
MHToggleItem(): MHActionInt(":ToggleItem") {}
virtual void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, int nArg) { Target(engine)->ToggleItem(nArg, engine); }
};
class MHScrollItems: public MHActionInt {
-public:
+ public:
MHScrollItems(): MHActionInt(":ScrollItems") {}
virtual void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, int nArg) { Target(engine)->ScrollItems(nArg, engine); }
};
class MHSetFirstItem: public MHActionInt {
-public:
+ public:
MHSetFirstItem(): MHActionInt(":SetFirstItem") {}
virtual void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, int nArg) { Target(engine)->SetFirstItem(nArg, engine); }
};
class MHGetFirstItem: public MHActionObjectRef {
-public:
+ public:
MHGetFirstItem(): MHActionObjectRef(":GetFirstItem") {}
virtual void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, MHRoot *pArg) { Target(engine)->GetFirstItem(pArg, engine); }
};
class MHGetListSize: public MHActionObjectRef {
-public:
+ public:
MHGetListSize(): MHActionObjectRef(":GetListSize") {}
virtual void CallAction(MHEngine *engine, MHRoot * /*pTarget*/, MHRoot *pArg) {Target(engine)->GetListSize(pArg, engine); }
};
diff --git a/mythtv/libs/libmythfreemheg/Variables.cpp b/mythtv/libs/libmythfreemheg/Variables.cpp
index 70e20bffc2e..c26ecd67e2f 100644
--- a/mythtv/libs/libmythfreemheg/Variables.cpp
+++ b/mythtv/libs/libmythfreemheg/Variables.cpp
@@ -33,21 +33,33 @@ enum TestCodes { TC_Equal = 1, TC_NotEqual, TC_Less, TC_LessOrEqual, TC_Greater,
static const char *TestToText(int tc)
{
- switch (tc) {
- case TC_Equal: return "Equal";
- case TC_NotEqual: return "NotEqual";
- case TC_Less: return "Less";
- case TC_LessOrEqual: return "LessOrEqual";
- case TC_Greater: return "Greater";
- case TC_GreaterOrEqual: return "GreaterOrEqual";
+ switch (tc)
+ {
+ case TC_Equal:
+ return "Equal";
+ case TC_NotEqual:
+ return "NotEqual";
+ case TC_Less:
+ return "Less";
+ case TC_LessOrEqual:
+ return "LessOrEqual";
+ case TC_Greater:
+ return "Greater";
+ case TC_GreaterOrEqual:
+ return "GreaterOrEqual";
}
+
return NULL; // To keep the compiler happy
}
// Normal activation behaviour.
void MHVariable::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHIngredient::Activation(engine);
m_fRunning = true;
engine->EventTriggered(this, EventIsRunning);
@@ -58,20 +70,31 @@ void MHBooleanVar::Initialise(MHParseNode *p, MHEngine *engine)
MHVariable::Initialise(p, engine);
// Original value should be a bool.
MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE);
- if (pInitial) m_fOriginalValue = pInitial->GetArgN(0)->GetBoolValue();
+
+ if (pInitial)
+ {
+ m_fOriginalValue = pInitial->GetArgN(0)->GetBoolValue();
+ }
}
void MHBooleanVar::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:BooleanVar");
- MHVariable::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":OrigValue %s\n", m_fOriginalValue ? "true" : "false");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:BooleanVar");
+ MHVariable::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OrigValue %s\n", m_fOriginalValue ? "true" : "false");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHBooleanVar::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return;
+ if (m_fAvailable)
+ {
+ return;
+ }
+
m_fValue = m_fOriginalValue;
MHVariable::Preparation(engine);
}
@@ -81,13 +104,21 @@ void MHBooleanVar::TestVariable(int nOp, const MHUnion &parm, MHEngine *engine)
{
parm.CheckType(MHUnion::U_Bool);
bool fRes = false;
- switch (nOp) {
- case TC_Equal: fRes = m_fValue == parm.m_fBoolVal; break;
- case TC_NotEqual: fRes = m_fValue != parm.m_fBoolVal; break;
- default: MHERROR("Invalid comparison for bool");
+
+ switch (nOp)
+ {
+ case TC_Equal:
+ fRes = m_fValue == parm.m_fBoolVal;
+ break;
+ case TC_NotEqual:
+ fRes = m_fValue != parm.m_fBoolVal;
+ break;
+ default:
+ MHERROR("Invalid comparison for bool");
}
+
MHLOG(MHLogDetail, QString("Comparison %1 between %2 and %3 => %4").arg(TestToText(nOp))
- .arg(m_fValue ? "true" : "false").arg(parm.m_fBoolVal ? "true" : "false").arg(fRes ? "true" : "false"));
+ .arg(m_fValue ? "true" : "false").arg(parm.m_fBoolVal ? "true" : "false").arg(fRes ? "true" : "false"));
engine->EventTriggered(this, EventTestEvent, fRes);
}
@@ -103,7 +134,7 @@ void MHBooleanVar::SetVariableValue(const MHUnion &value)
{
value.CheckType(MHUnion::U_Bool);
m_fValue = value.m_fBoolVal;
- MHLOG(MHLogDetail, QString("Update %1 := %2").arg(m_ObjectReference.Printable()).arg( m_fValue ? "true": "false"));
+ MHLOG(MHLogDetail, QString("Update %1 := %2").arg(m_ObjectReference.Printable()).arg(m_fValue ? "true" : "false"));
}
@@ -112,20 +143,31 @@ void MHIntegerVar::Initialise(MHParseNode *p, MHEngine *engine)
MHVariable::Initialise(p, engine);
// Original value should be an int.
MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE);
- if (pInitial) m_nOriginalValue = pInitial->GetArgN(0)->GetIntValue();
+
+ if (pInitial)
+ {
+ m_nOriginalValue = pInitial->GetArgN(0)->GetIntValue();
+ }
}
void MHIntegerVar::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:IntegerVar");
- MHVariable::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":OrigValue %d\n", m_nOriginalValue);
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:IntegerVar");
+ MHVariable::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OrigValue %d\n", m_nOriginalValue);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHIntegerVar::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return;
+ if (m_fAvailable)
+ {
+ return;
+ }
+
m_nValue = m_nOriginalValue;
MHVariable::Preparation(engine);
}
@@ -135,17 +177,33 @@ void MHIntegerVar::TestVariable(int nOp, const MHUnion &parm, MHEngine *engine)
{
parm.CheckType(MHUnion::U_Int);
bool fRes = false;
- switch (nOp) {
- case TC_Equal: fRes = m_nValue == parm.m_nIntVal; break;
- case TC_NotEqual: fRes = m_nValue != parm.m_nIntVal; break;
- case TC_Less: fRes = m_nValue < parm.m_nIntVal; break;
- case TC_LessOrEqual: fRes = m_nValue <= parm.m_nIntVal; break;
- case TC_Greater: fRes = m_nValue > parm.m_nIntVal; break;
- case TC_GreaterOrEqual: fRes = m_nValue >= parm.m_nIntVal; break;
- default: MHERROR("Invalid comparison for int"); // Shouldn't ever happen
+
+ switch (nOp)
+ {
+ case TC_Equal:
+ fRes = m_nValue == parm.m_nIntVal;
+ break;
+ case TC_NotEqual:
+ fRes = m_nValue != parm.m_nIntVal;
+ break;
+ case TC_Less:
+ fRes = m_nValue < parm.m_nIntVal;
+ break;
+ case TC_LessOrEqual:
+ fRes = m_nValue <= parm.m_nIntVal;
+ break;
+ case TC_Greater:
+ fRes = m_nValue > parm.m_nIntVal;
+ break;
+ case TC_GreaterOrEqual:
+ fRes = m_nValue >= parm.m_nIntVal;
+ break;
+ default:
+ MHERROR("Invalid comparison for int"); // Shouldn't ever happen
}
+
MHLOG(MHLogDetail, QString("Comparison %1 between %2 and %3 => %4").arg(TestToText(nOp))
- .arg(m_nValue).arg(parm.m_nIntVal).arg(fRes ? "true" : "false"));
+ .arg(m_nValue).arg(parm.m_nIntVal).arg(fRes ? "true" : "false"));
engine->EventTriggered(this, EventTestEvent, fRes);
}
@@ -159,23 +217,46 @@ void MHIntegerVar::GetVariableValue(MHUnion &value, MHEngine *)
// Implement the SetVariable action. Also used as part of Add, Subtract etc
void MHIntegerVar::SetVariableValue(const MHUnion &value)
{
- if (value.m_Type == MHUnion::U_String) {
+ if (value.m_Type == MHUnion::U_String)
+ {
// Implicit conversion of string to integer.
int v = 0;
int p = 0;
bool fNegative = false;
- if (value.m_StrVal.Size() > 0 && value.m_StrVal.GetAt(0) == '-') { p++; fNegative = true; }
- for ( ; p < value.m_StrVal.Size(); p++) {
+
+ if (value.m_StrVal.Size() > 0 && value.m_StrVal.GetAt(0) == '-')
+ {
+ p++;
+ fNegative = true;
+ }
+
+ for (; p < value.m_StrVal.Size(); p++)
+ {
unsigned char ch = value.m_StrVal.GetAt(p);
- if (ch < '0' || ch > '9') break;
+
+ if (ch < '0' || ch > '9')
+ {
+ break;
+ }
+
v = v * 10 + ch - '0';
}
- if (fNegative) m_nValue = -v; else m_nValue = v;
+
+ if (fNegative)
+ {
+ m_nValue = -v;
+ }
+ else
+ {
+ m_nValue = v;
+ }
}
- else {
+ else
+ {
value.CheckType(MHUnion::U_Int);
m_nValue = value.m_nIntVal;
}
+
MHLOG(MHLogDetail, QString("Update %1 := %2").arg(m_ObjectReference.Printable()).arg(m_nValue));
}
@@ -186,20 +267,33 @@ void MHOctetStrVar::Initialise(MHParseNode *p, MHEngine *engine)
MHVariable::Initialise(p, engine);
// Original value should be a string.
MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE);
- if (pInitial) pInitial->GetArgN(0)->GetStringValue(m_OriginalValue);
+
+ if (pInitial)
+ {
+ pInitial->GetArgN(0)->GetStringValue(m_OriginalValue);
+ }
}
void MHOctetStrVar::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:OStringVar");
- MHVariable::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":OrigValue "); m_OriginalValue.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:OStringVar");
+ MHVariable::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OrigValue ");
+ m_OriginalValue.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHOctetStrVar::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return;
+ if (m_fAvailable)
+ {
+ return;
+ }
+
m_Value.Copy(m_OriginalValue);
MHVariable::Preparation(engine);
}
@@ -210,19 +304,27 @@ void MHOctetStrVar::TestVariable(int nOp, const MHUnion &parm, MHEngine *engine)
parm.CheckType(MHUnion::U_String);
int nRes = m_Value.Compare(parm.m_StrVal);
bool fRes = false;
- switch (nOp) {
- case TC_Equal: fRes = nRes == 0; break;
- case TC_NotEqual: fRes = nRes != 0; break;
-/* case TC_Less: fRes = nRes < 0; break;
- case TC_LessOrEqual: fRes = nRes <= 0; break;
- case TC_Greater: fRes = nRes > 0; break;
- case TC_GreaterOrEqual: fRes = nRes >= 0; break;*/
- default: MHERROR("Invalid comparison for string"); // Shouldn't ever happen
+
+ switch (nOp)
+ {
+ case TC_Equal:
+ fRes = nRes == 0;
+ break;
+ case TC_NotEqual:
+ fRes = nRes != 0;
+ break;
+ /* case TC_Less: fRes = nRes < 0; break;
+ case TC_LessOrEqual: fRes = nRes <= 0; break;
+ case TC_Greater: fRes = nRes > 0; break;
+ case TC_GreaterOrEqual: fRes = nRes >= 0; break;*/
+ default:
+ MHERROR("Invalid comparison for string"); // Shouldn't ever happen
}
+
MHOctetString sample1(m_Value, 0, 10);
MHOctetString sample2(parm.m_StrVal, 0, 10);
MHLOG(MHLogDetail, QString("Comparison %1 %2 and %3 => %4").arg(TestToText(nOp))
- .arg(sample1.Printable()).arg(sample2.Printable()).arg(fRes ? "true" : "false"));
+ .arg(sample1.Printable()).arg(sample2.Printable()).arg(fRes ? "true" : "false"));
engine->EventTriggered(this, EventTestEvent, fRes);
}
@@ -236,20 +338,23 @@ void MHOctetStrVar::GetVariableValue(MHUnion &value, MHEngine *)
// Implement the SetVariable action.
void MHOctetStrVar::SetVariableValue(const MHUnion &value)
{
- if (value.m_Type == MHUnion::U_Int) {
+ if (value.m_Type == MHUnion::U_Int)
+ {
// Implicit conversion of int to string.
char buff[30]; // 30 chars is more than enough.
snprintf(buff, sizeof(buff), "%0d", value.m_nIntVal);
m_Value.Copy(buff);
}
- else {
+ else
+ {
value.CheckType(MHUnion::U_String);
m_Value.Copy(value.m_StrVal);
}
+
// Debug
MHOctetString sample(m_Value, 0, 60);
MHLOG(MHLogDetail, QString("Update %1 := %2").arg(m_ObjectReference.Printable())
- .arg(sample.Printable()));
+ .arg(sample.Printable()));
}
@@ -258,24 +363,39 @@ void MHObjectRefVar::Initialise(MHParseNode *p, MHEngine *engine)
MHVariable::Initialise(p, engine);
// Original value should be an object reference.
MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE);
+
// and this should be a ObjRef node.
- if (pInitial) {
+ if (pInitial)
+ {
MHParseNode *pArg = pInitial->GetNamedArg(C_OBJECT_REFERENCE);
- if (pArg) m_OriginalValue.Initialise(pArg->GetArgN(0), engine);
+
+ if (pArg)
+ {
+ m_OriginalValue.Initialise(pArg->GetArgN(0), engine);
+ }
}
}
void MHObjectRefVar::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:ObjectRefVar");
- MHVariable::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":OrigValue "); m_OriginalValue.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:ObjectRefVar");
+ MHVariable::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OrigValue ");
+ m_OriginalValue.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHObjectRefVar::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return;
+ if (m_fAvailable)
+ {
+ return;
+ }
+
m_Value.Copy(m_OriginalValue);
MHVariable::Preparation(engine);
}
@@ -285,11 +405,19 @@ void MHObjectRefVar::TestVariable(int nOp, const MHUnion &parm, MHEngine *engine
{
parm.CheckType(MHUnion::U_ObjRef);
bool fRes = false;
- switch (nOp) {
- case TC_Equal: fRes = m_Value.Equal(parm.m_ObjRefVal, engine); break;
- case TC_NotEqual: fRes = ! m_Value.Equal(parm.m_ObjRefVal, engine); break;
- default: MHERROR("Invalid comparison for object ref");
+
+ switch (nOp)
+ {
+ case TC_Equal:
+ fRes = m_Value.Equal(parm.m_ObjRefVal, engine);
+ break;
+ case TC_NotEqual:
+ fRes = ! m_Value.Equal(parm.m_ObjRefVal, engine);
+ break;
+ default:
+ MHERROR("Invalid comparison for object ref");
}
+
engine->EventTriggered(this, EventTestEvent, fRes);
}
@@ -314,24 +442,39 @@ void MHContentRefVar::Initialise(MHParseNode *p, MHEngine *engine)
MHVariable::Initialise(p, engine);
// Original value should be a content reference.
MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE);
+
// and this should be a ContentRef node.
- if (pInitial) {
+ if (pInitial)
+ {
MHParseNode *pArg = pInitial->GetNamedArg(C_CONTENT_REFERENCE);
- if (pArg) m_OriginalValue.Initialise(pArg->GetArgN(0), engine);
+
+ if (pArg)
+ {
+ m_OriginalValue.Initialise(pArg->GetArgN(0), engine);
+ }
}
}
void MHContentRefVar::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:ContentRefVar");
- MHVariable::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs+1); fprintf(fd, ":OrigValue "); m_OriginalValue.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:ContentRefVar");
+ MHVariable::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":OrigValue ");
+ m_OriginalValue.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHContentRefVar::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return;
+ if (m_fAvailable)
+ {
+ return;
+ }
+
m_Value.Copy(m_OriginalValue);
MHVariable::Preparation(engine);
}
@@ -341,11 +484,19 @@ void MHContentRefVar::TestVariable(int nOp, const MHUnion &parm, MHEngine *engin
{
parm.CheckType(MHUnion::U_ContentRef);
bool fRes = false;
- switch (nOp) {
- case TC_Equal: fRes = m_Value.Equal(parm.m_ContentRefVal, engine); break;
- case TC_NotEqual: fRes = !m_Value.Equal(parm.m_ContentRefVal, engine); break;
- default: MHERROR("Invalid comparison for content ref");
+
+ switch (nOp)
+ {
+ case TC_Equal:
+ fRes = m_Value.Equal(parm.m_ContentRefVal, engine);
+ break;
+ case TC_NotEqual:
+ fRes = !m_Value.Equal(parm.m_ContentRefVal, engine);
+ break;
+ default:
+ MHERROR("Invalid comparison for content ref");
}
+
engine->EventTriggered(this, EventTestEvent, fRes);
}
diff --git a/mythtv/libs/libmythfreemheg/Variables.h b/mythtv/libs/libmythfreemheg/Variables.h
index 3071cd22d7a..544a913b99e 100644
--- a/mythtv/libs/libmythfreemheg/Variables.h
+++ b/mythtv/libs/libmythfreemheg/Variables.h
@@ -30,7 +30,7 @@
class MHVariable : public MHIngredient
{
-public:
+ public:
MHVariable() {}
virtual ~MHVariable() {}
@@ -40,7 +40,7 @@ class MHVariable : public MHIngredient
class MHBooleanVar : public MHVariable
{
-public:
+ public:
MHBooleanVar(): m_fOriginalValue(false), m_fValue(false) {}
virtual const char *ClassName() { return "BooleanVariable"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -55,13 +55,13 @@ class MHBooleanVar : public MHVariable
virtual void GetVariableValue(MHUnion &value, MHEngine *);
virtual void SetVariableValue(const MHUnion &value);
-protected:
+ protected:
bool m_fOriginalValue, m_fValue;
};
class MHIntegerVar : public MHVariable
{
-public:
+ public:
MHIntegerVar(): m_nOriginalValue(0), m_nValue(0) {}
virtual const char *ClassName() { return "IntegerVariable"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -75,13 +75,13 @@ class MHIntegerVar : public MHVariable
virtual void TestVariable(int nOp, const MHUnion &parmm, MHEngine *engine);
virtual void GetVariableValue(MHUnion &value, MHEngine *);
virtual void SetVariableValue(const MHUnion &value);
-protected:
+ protected:
int m_nOriginalValue, m_nValue;
};
class MHOctetStrVar : public MHVariable
{
-public:
+ public:
MHOctetStrVar() {}
virtual const char *ClassName() { return "OctetStringVariable"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -95,13 +95,13 @@ class MHOctetStrVar : public MHVariable
virtual void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine);
virtual void GetVariableValue(MHUnion &value, MHEngine *);
virtual void SetVariableValue(const MHUnion &value);
-protected:
+ protected:
MHOctetString m_OriginalValue, m_Value;
};
class MHObjectRefVar : public MHVariable
{
-public:
+ public:
MHObjectRefVar() {}
virtual const char *ClassName() { return "ObjectRefVariable"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -115,13 +115,13 @@ class MHObjectRefVar : public MHVariable
virtual void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine);
virtual void GetVariableValue(MHUnion &value, MHEngine *);
virtual void SetVariableValue(const MHUnion &value);
-protected:
+ protected:
MHObjectRef m_OriginalValue, m_Value;
};
class MHContentRefVar : public MHVariable
{
-public:
+ public:
MHContentRefVar() {}
virtual const char *ClassName() { return "ContentRefVariable"; }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -135,7 +135,7 @@ class MHContentRefVar : public MHVariable
virtual void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine);
virtual void GetVariableValue(MHUnion &value, MHEngine *);
virtual void SetVariableValue(const MHUnion &value);
-protected:
+ protected:
MHContentRef m_OriginalValue, m_Value;
};
@@ -143,11 +143,11 @@ class MHContentRefVar : public MHVariable
// Set a variable to a value.
class MHSetVariable: public MHElemAction
{
-public:
+ public:
MHSetVariable():MHElemAction(":SetVariable") {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int /*nTabs*/) const { m_NewValue.PrintMe(fd, 0); }
MHParameter m_NewValue; // New value to store.
};
@@ -155,11 +155,11 @@ class MHSetVariable: public MHElemAction
// Compare a variable with a value and generate a TestEvent event on the result.
class MHTestVariable: public MHElemAction
{
-public:
+ public:
MHTestVariable(): MHElemAction(":TestVariable"), m_nOperator(0) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int nTabs) const;
int m_nOperator;
MHParameter m_Comparison; // Value to compare with.
@@ -170,59 +170,59 @@ class MHTestVariable: public MHElemAction
// Integer operations.
class MHIntegerAction: public MHElemAction
{
-public:
+ public:
MHIntegerAction(const char *name): MHElemAction(name) {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int /*nTabs*/) const { m_Operand.PrintMe(fd, 0); }
virtual int DoOp(int arg1, int arg2) = 0; // Do the operation.
MHGenericInteger m_Operand; // Value to add, subtract etc.
};
class MHAdd: public MHIntegerAction {
-public:
+ public:
MHAdd(): MHIntegerAction(":Add") {}
-protected:
+ protected:
virtual int DoOp(int arg1, int arg2) { return arg1+arg2; }
};
class MHSubtract: public MHIntegerAction {
-public:
+ public:
MHSubtract(): MHIntegerAction(":Subtract") {}
-protected:
+ protected:
virtual int DoOp(int arg1, int arg2) { return arg1-arg2; }
};
class MHMultiply: public MHIntegerAction {
-public:
+ public:
MHMultiply(): MHIntegerAction(":Multiply") {}
-protected:
+ protected:
virtual int DoOp(int arg1, int arg2) { return arg1*arg2; }
};
class MHDivide: public MHIntegerAction {
-public:
+ public:
MHDivide(): MHIntegerAction(":Divide") {}
-protected:
+ protected:
virtual int DoOp(int arg1, int arg2) { return arg1/arg2; } // What about divide by zero?
};
class MHModulo: public MHIntegerAction {
-public:
+ public:
MHModulo(): MHIntegerAction(":Modulo") {}
-protected:
+ protected:
virtual int DoOp(int arg1, int arg2) { return arg1%arg2; } // What about divide by zero?
};
// Append -
class MHAppend: public MHElemAction
{
-public:
+ public:
MHAppend(): MHElemAction(":Append") {}
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int /*nTabs*/) const { m_Operand.PrintMe(fd, 0); }
MHGenericOctetString m_Operand; // Value to append.
};
diff --git a/mythtv/libs/libmythfreemheg/Visible.cpp b/mythtv/libs/libmythfreemheg/Visible.cpp
index 6d1f7434250..1d69a397a93 100644
--- a/mythtv/libs/libmythfreemheg/Visible.cpp
+++ b/mythtv/libs/libmythfreemheg/Visible.cpp
@@ -60,8 +60,11 @@ void MHVisible::Initialise(MHParseNode *p, MHEngine *engine)
MHPresentable::Initialise(p, engine);
// Original box size - two integer arguments.
MHParseNode *pOriginalBox = p->GetNamedArg(C_ORIGINAL_BOX_SIZE);
+
if (! pOriginalBox)
+ {
p->Failure("OriginalBoxSize missing");
+ }
else
{
m_nOriginalBoxWidth = pOriginalBox->GetArgN(0)->GetIntValue();
@@ -70,31 +73,50 @@ void MHVisible::Initialise(MHParseNode *p, MHEngine *engine)
// Original position - two integer arguments. Optional
MHParseNode *pOriginalPos = p->GetNamedArg(C_ORIGINAL_POSITION);
- if (pOriginalPos) {
+
+ if (pOriginalPos)
+ {
m_nOriginalPosX = pOriginalPos->GetArgN(0)->GetIntValue();
m_nOriginalPosY = pOriginalPos->GetArgN(1)->GetIntValue();
}
- // OriginalPalette ref - optional.
+ // OriginalPalette ref - optional.
MHParseNode *pOriginalPaletteRef = p->GetNamedArg(C_ORIGINAL_PALETTE_REF);
- if (pOriginalPaletteRef) m_OriginalPaletteRef.Initialise(pOriginalPaletteRef->GetArgN(0), engine);
+
+ if (pOriginalPaletteRef)
+ {
+ m_OriginalPaletteRef.Initialise(pOriginalPaletteRef->GetArgN(0), engine);
+ }
}
void MHVisible::PrintMe(FILE *fd, int nTabs) const
{
MHPresentable::PrintMe(fd, nTabs);
- PrintTabs(fd, nTabs); fprintf(fd, ":OrigBoxSize %d %d\n", m_nOriginalBoxWidth, m_nOriginalBoxHeight);
- if (m_nOriginalPosX != 0 || m_nOriginalPosY != 0) {
- PrintTabs(fd, nTabs); fprintf(fd, ":OrigPosition %d %d\n", m_nOriginalPosX, m_nOriginalPosY);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":OrigBoxSize %d %d\n", m_nOriginalBoxWidth, m_nOriginalBoxHeight);
+
+ if (m_nOriginalPosX != 0 || m_nOriginalPosY != 0)
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":OrigPosition %d %d\n", m_nOriginalPosX, m_nOriginalPosY);
}
- if (m_OriginalPaletteRef.IsSet()) {
- PrintTabs(fd, nTabs); fprintf(fd, ":OrigPaletteRef"); m_OriginalPaletteRef.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
+
+ if (m_OriginalPaletteRef.IsSet())
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":OrigPaletteRef");
+ m_OriginalPaletteRef.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
}
}
void MHVisible::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return; // Already prepared
+ if (m_fAvailable)
+ {
+ return; // Already prepared
+ }
+
m_nBoxWidth = m_nOriginalBoxWidth;
m_nBoxHeight = m_nOriginalBoxHeight;
m_nPosX = m_nOriginalPosX;
@@ -113,7 +135,11 @@ void MHVisible::Destruction(MHEngine *engine)
void MHVisible::Activation(MHEngine *engine)
{
- if (m_fRunning) return;
+ if (m_fRunning)
+ {
+ return;
+ }
+
MHIngredient::Activation(engine);
m_fRunning = true;
engine->Redraw(GetVisibleArea()); // Display the visible.
@@ -122,7 +148,11 @@ void MHVisible::Activation(MHEngine *engine)
void MHVisible::Deactivation(MHEngine *engine)
{
- if (! m_fRunning) return;
+ if (! m_fRunning)
+ {
+ return;
+ }
+
// Stop displaying. We need to save the area before we turn off m_fRunning but
// only call Redraw once this is no longer visible so that the area beneath will be drawn.
QRegion region = GetVisibleArea();
@@ -135,20 +165,47 @@ MHRgba MHVisible::GetColour(const MHColour &colour)
{
int red = 0, green = 0, blue = 0, alpha = 0;
int cSize = colour.m_ColStr.Size();
- if (cSize != 4) MHLOG(MHLogWarning, QString("Colour string has length %1 not 4.").arg(cSize));
+
+ if (cSize != 4)
+ {
+ MHLOG(MHLogWarning, QString("Colour string has length %1 not 4.").arg(cSize));
+ }
+
// Just in case the length is short we handle those properly.
- if (cSize > 0) red = colour.m_ColStr.GetAt(0);
- if (cSize > 1) green = colour.m_ColStr.GetAt(1);
- if (cSize > 2) blue = colour.m_ColStr.GetAt(2);
- if (cSize > 3) alpha = 255 - colour.m_ColStr.GetAt(3); // Convert transparency to alpha
+ if (cSize > 0)
+ {
+ red = colour.m_ColStr.GetAt(0);
+ }
+
+ if (cSize > 1)
+ {
+ green = colour.m_ColStr.GetAt(1);
+ }
+
+ if (cSize > 2)
+ {
+ blue = colour.m_ColStr.GetAt(2);
+ }
+
+ if (cSize > 3)
+ {
+ alpha = 255 - colour.m_ColStr.GetAt(3); // Convert transparency to alpha
+ }
+
return MHRgba(red, green, blue, alpha);
}
// Get the visible region of this visible. This is the area that needs to be drawn.
QRegion MHVisible::GetVisibleArea()
{
- if (! m_fRunning) return QRegion(); // Not visible at all.
- else return QRegion(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
+ if (! m_fRunning)
+ {
+ return QRegion(); // Not visible at all.
+ }
+ else
+ {
+ return QRegion(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
+ }
}
// MHEG actions.
@@ -238,47 +295,112 @@ void MHLineArt::Initialise(MHParseNode *p, MHEngine *engine)
MHVisible::Initialise(p, engine);
// Bordered bounding box - optional
MHParseNode *pBBBox = p->GetNamedArg(C_BORDERED_BOUNDING_BOX);
- if (pBBBox) m_fBorderedBBox = pBBBox->GetArgN(0)->GetBoolValue();
+
+ if (pBBBox)
+ {
+ m_fBorderedBBox = pBBBox->GetArgN(0)->GetBoolValue();
+ }
+
// Original line width
MHParseNode *pOlw = p->GetNamedArg(C_ORIGINAL_LINE_WIDTH);
- if (pOlw) m_nOriginalLineWidth = pOlw->GetArgN(0)->GetIntValue();
+
+ if (pOlw)
+ {
+ m_nOriginalLineWidth = pOlw->GetArgN(0)->GetIntValue();
+ }
+
// Original line style. This is an integer not an enum.
MHParseNode *pOls = p->GetNamedArg(C_ORIGINAL_LINE_STYLE);
- if (pOls) m_OriginalLineStyle = pOls->GetArgN(0)->GetIntValue();
+
+ if (pOls)
+ {
+ m_OriginalLineStyle = pOls->GetArgN(0)->GetIntValue();
+ }
+
// Line colour.
MHParseNode *pOrlc = p->GetNamedArg(C_ORIGINAL_REF_LINE_COLOUR);
- if (pOrlc) m_OrigLineColour.Initialise(pOrlc->GetArgN(0), engine);
+
+ if (pOrlc)
+ {
+ m_OrigLineColour.Initialise(pOrlc->GetArgN(0), engine);
+ }
+
// Fill colour
MHParseNode *pOrfc = p->GetNamedArg(C_ORIGINAL_REF_FILL_COLOUR);
- if (pOrfc) m_OrigFillColour.Initialise(pOrfc->GetArgN(0), engine);
+
+ if (pOrfc)
+ {
+ m_OrigFillColour.Initialise(pOrfc->GetArgN(0), engine);
+ }
}
void MHLineArt::PrintMe(FILE *fd, int nTabs) const
{
MHVisible::PrintMe(fd, nTabs);
- if (! m_fBorderedBBox) { PrintTabs(fd, nTabs); fprintf(fd, ":BBBox false\n"); }
- if (m_nOriginalLineWidth != 1) { PrintTabs(fd, nTabs); fprintf(fd, ":OrigLineWidth %d\n", m_nOriginalLineWidth); }
- if (m_OriginalLineStyle != LineStyleSolid) {
- PrintTabs(fd, nTabs); fprintf(fd, ":OrigLineStyle %d\n", m_OriginalLineStyle);
+
+ if (! m_fBorderedBBox)
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":BBBox false\n");
+ }
+
+ if (m_nOriginalLineWidth != 1)
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":OrigLineWidth %d\n", m_nOriginalLineWidth);
+ }
+
+ if (m_OriginalLineStyle != LineStyleSolid)
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":OrigLineStyle %d\n", m_OriginalLineStyle);
}
- if (m_OrigLineColour.IsSet()) {
- PrintTabs(fd, nTabs); fprintf(fd, ":OrigRefLineColour "); m_OrigLineColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
+
+ if (m_OrigLineColour.IsSet())
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":OrigRefLineColour ");
+ m_OrigLineColour.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
}
- if (m_OrigFillColour.IsSet()) {
- PrintTabs(fd, nTabs); fprintf(fd, ":OrigRefFillColour "); m_OrigFillColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
+
+ if (m_OrigFillColour.IsSet())
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":OrigRefFillColour ");
+ m_OrigFillColour.PrintMe(fd, nTabs + 1);
+ fprintf(fd, "\n");
}
}
void MHLineArt::Preparation(MHEngine *engine)
{
- if (m_fAvailable) return; // Already prepared
+ if (m_fAvailable)
+ {
+ return; // Already prepared
+ }
+
// Set up the internal attributes.
m_nLineWidth = m_nOriginalLineWidth;
m_LineStyle = m_OriginalLineStyle;
- if (m_OrigLineColour.IsSet()) m_LineColour.Copy(m_OrigLineColour);
- else m_LineColour.SetFromString("\000\000\000\000", 4); // Default is black
- if (m_OrigFillColour.IsSet()) m_FillColour.Copy(m_OrigFillColour);
- else m_FillColour.SetFromString("\000\000\000\377", 4); // Default is transparent
+
+ if (m_OrigLineColour.IsSet())
+ {
+ m_LineColour.Copy(m_OrigLineColour);
+ }
+ else
+ {
+ m_LineColour.SetFromString("\000\000\000\000", 4); // Default is black
+ }
+
+ if (m_OrigFillColour.IsSet())
+ {
+ m_FillColour.Copy(m_OrigFillColour);
+ }
+ else
+ {
+ m_FillColour.SetFromString("\000\000\000\377", 4); // Default is transparent
+ }
MHVisible::Preparation(engine); // Prepare the base class.
}
@@ -312,50 +434,79 @@ void MHLineArt::SetLineStyle(int nStyle, MHEngine *engine)
// The rectangle class doesn't add much to the LineArt class
void MHRectangle::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:Rectangle ");
- MHLineArt::PrintMe(fd, nTabs+1);
- PrintTabs(fd, nTabs);fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:Rectangle ");
+ MHLineArt::PrintMe(fd, nTabs + 1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
// If this is opaque it obscures the underlying area.
QRegion MHRectangle::GetOpaqueArea()
{
- if (! m_fRunning) return QRegion();
+ if (! m_fRunning)
+ {
+ return QRegion();
+ }
+
MHRgba lineColour = GetColour(m_LineColour);
MHRgba fillColour = GetColour(m_FillColour);
+
// If the fill is transparent or semi-transparent we return an empty region and
// ignore the special case where the surrounding box is opaque.
- if (fillColour.alpha() != 255) return QRegion();
- if (lineColour.alpha() == 255 || m_nLineWidth == 0) return QRegion(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
- if (m_nBoxWidth <= 2*m_nLineWidth || m_nBoxHeight <= 2*m_nLineWidth) return QRegion();
+ if (fillColour.alpha() != 255)
+ {
+ return QRegion();
+ }
+
+ if (lineColour.alpha() == 255 || m_nLineWidth == 0)
+ {
+ return QRegion(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
+ }
+
+ if (m_nBoxWidth <= 2 * m_nLineWidth || m_nBoxHeight <= 2 * m_nLineWidth)
+ {
+ return QRegion();
+ }
else return QRegion(QRect(m_nPosX + m_nLineWidth, m_nPosY + m_nLineWidth,
- m_nBoxWidth - m_nLineWidth*2, m_nBoxHeight - m_nLineWidth*2));
+ m_nBoxWidth - m_nLineWidth * 2, m_nBoxHeight - m_nLineWidth * 2));
}
void MHRectangle::Display(MHEngine *engine)
{
- if (! m_fRunning) return;
- if (m_nBoxWidth == 0 || m_nBoxHeight == 0) return; // Can't draw zero sized boxes.
+ if (! m_fRunning)
+ {
+ return;
+ }
+
+ if (m_nBoxWidth == 0 || m_nBoxHeight == 0)
+ {
+ return; // Can't draw zero sized boxes.
+ }
+
// The bounding box is assumed always to be True.
MHRgba lineColour = GetColour(m_LineColour);
MHRgba fillColour = GetColour(m_FillColour);
MHContext *d = engine->GetContext();
+
// Fill the centre.
- if (m_nBoxHeight < m_nLineWidth*2 || m_nBoxWidth < m_nLineWidth*2) {
+ if (m_nBoxHeight < m_nLineWidth * 2 || m_nBoxWidth < m_nLineWidth * 2)
+ {
// If the area is very small but non-empty fill it with the line colour
d->DrawRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight, lineColour);
}
- else {
+ else
+ {
d->DrawRect(m_nPosX + m_nLineWidth, m_nPosY + m_nLineWidth,
- m_nBoxWidth - m_nLineWidth*2, m_nBoxHeight - m_nLineWidth*2, fillColour);
+ m_nBoxWidth - m_nLineWidth * 2, m_nBoxHeight - m_nLineWidth * 2, fillColour);
// Draw the lines round the outside. UK MHEG allows us to treat all line styles as solid.
// It isn't clear when we draw dashed and dotted lines what colour to put in the spaces.
d->DrawRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nLineWidth, lineColour);
d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - m_nLineWidth, m_nBoxWidth, m_nLineWidth, lineColour);
- d->DrawRect(m_nPosX, m_nPosY + m_nLineWidth, m_nLineWidth, m_nBoxHeight - m_nLineWidth*2, lineColour);
+ d->DrawRect(m_nPosX, m_nPosY + m_nLineWidth, m_nLineWidth, m_nBoxHeight - m_nLineWidth * 2, lineColour);
d->DrawRect(m_nPosX + m_nBoxWidth - m_nLineWidth, m_nPosY + m_nLineWidth,
- m_nLineWidth, m_nBoxHeight - m_nLineWidth*2, lineColour);
+ m_nLineWidth, m_nBoxHeight - m_nLineWidth * 2, lineColour);
}
}
@@ -376,23 +527,41 @@ void MHInteractible::Initialise(MHParseNode *p, MHEngine *engine)
{
// Engine Resp - optional
MHParseNode *pEngineResp = p->GetNamedArg(C_ENGINE_RESP);
- if (pEngineResp) m_fEngineResp = pEngineResp->GetArgN(0)->GetBoolValue();
+
+ if (pEngineResp)
+ {
+ m_fEngineResp = pEngineResp->GetArgN(0)->GetBoolValue();
+ }
+
// Highlight colour.
MHParseNode *phlCol = p->GetNamedArg(C_HIGHLIGHT_REF_COLOUR);
- if (phlCol) m_highlightRefColour.Initialise(phlCol->GetArgN(0), engine);
- else engine->GetDefaultHighlightRefColour(m_highlightRefColour);
+
+ if (phlCol)
+ {
+ m_highlightRefColour.Initialise(phlCol->GetArgN(0), engine);
+ }
+ else
+ {
+ engine->GetDefaultHighlightRefColour(m_highlightRefColour);
+ }
+
m_fHighlightStatus = false;
m_fInteractionStatus = false;
}
void MHInteractible::PrintMe(FILE *fd, int nTabs) const
{
- if (! m_fEngineResp) { PrintTabs(fd, nTabs); fprintf(fd, ":EngineResp false\n"); }
+ if (! m_fEngineResp)
+ {
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":EngineResp false\n");
+ }
- if (m_highlightRefColour.IsSet()) {
+ if (m_highlightRefColour.IsSet())
+ {
PrintTabs(fd, nTabs);
fprintf(fd, ":HighlightRefColour ");
- m_highlightRefColour.PrintMe(fd, nTabs+1);
+ m_highlightRefColour.PrintMe(fd, nTabs + 1);
fprintf(fd, "\n");
}
}
@@ -408,12 +577,17 @@ void MHInteractible::Interaction(MHEngine *engine)
void MHInteractible::InteractSetInteractionStatus(bool newStatus, MHEngine *engine)
{
- if (newStatus) { // Turning interaction on.
+ if (newStatus) // Turning interaction on.
+ {
if (engine->GetInteraction() == 0) // No current interactible
- Interaction(engine); // virtual function
+ {
+ Interaction(engine); // virtual function
+ }
}
- else { // Turning interaction off.
- if (m_fInteractionStatus) {
+ else // Turning interaction off.
+ {
+ if (m_fInteractionStatus)
+ {
m_fInteractionStatus = false;
engine->SetInteraction(0);
InteractionCompleted(engine); // Interaction is interrupted.
@@ -424,13 +598,21 @@ void MHInteractible::InteractSetInteractionStatus(bool newStatus, MHEngine *engi
void MHInteractible::InteractSetHighlightStatus(bool newStatus, MHEngine *engine)
{
- if (newStatus == m_fHighlightStatus) return;
+ if (newStatus == m_fHighlightStatus)
+ {
+ return;
+ }
+
m_fHighlightStatus = newStatus;
+
// If active redraw to show change of status.
if (m_parent->GetRunningStatus() && m_fEngineResp)
+ {
engine->Redraw(m_parent->GetVisibleArea());
+ }
+
// Generate the event for the change of highlight status.
- engine->EventTriggered(m_parent, m_fHighlightStatus ? EventHighlightOn: EventHighlightOff);
+ engine->EventTriggered(m_parent, m_fHighlightStatus ? EventHighlightOn : EventHighlightOff);
}
MHSlider::MHSlider(): MHInteractible(this)
@@ -450,39 +632,92 @@ void MHSlider::Initialise(MHParseNode *p, MHEngine *engine)
{
MHVisible::Initialise(p, engine);
MHInteractible::Initialise(p, engine);
- //
+ //
MHParseNode *pOrientation = p->GetNamedArg(C_ORIENTATION);
+
if (pOrientation)
+ {
m_orientation = (enum SliderOrientation)pOrientation->GetArgN(0)->GetEnumValue();
+ }
+
// This is not optional.
MHParseNode *pMin = p->GetNamedArg(C_MIN_VALUE);
- if (pMin) orig_min_value = pMin->GetArgN(0)->GetIntValue();
- else orig_min_value = 1;
+
+ if (pMin)
+ {
+ orig_min_value = pMin->GetArgN(0)->GetIntValue();
+ }
+ else
+ {
+ orig_min_value = 1;
+ }
MHParseNode *pMax = p->GetNamedArg(C_MAX_VALUE);
- if (pMax) orig_max_value = pMax->GetArgN(0)->GetIntValue();
- else orig_max_value = orig_min_value-1; // Unset
+
+ if (pMax)
+ {
+ orig_max_value = pMax->GetArgN(0)->GetIntValue();
+ }
+ else
+ {
+ orig_max_value = orig_min_value - 1; // Unset
+ }
MHParseNode *pInit = p->GetNamedArg(C_INITIAL_VALUE);
- if (pInit) initial_value = pInit->GetArgN(0)->GetIntValue();
- else initial_value = orig_min_value; // Default is min_value
+
+ if (pInit)
+ {
+ initial_value = pInit->GetArgN(0)->GetIntValue();
+ }
+ else
+ {
+ initial_value = orig_min_value; // Default is min_value
+ }
MHParseNode *pPortion = p->GetNamedArg(C_INITIAL_PORTION);
- if (pPortion) initial_portion = pPortion->GetArgN(0)->GetIntValue();
- else initial_portion = orig_min_value-1; // Unset
+
+ if (pPortion)
+ {
+ initial_portion = pPortion->GetArgN(0)->GetIntValue();
+ }
+ else
+ {
+ initial_portion = orig_min_value - 1; // Unset
+ }
MHParseNode *pStep = p->GetNamedArg(C_STEP_SIZE);
- if (pStep) orig_step_size = pStep->GetArgN(0)->GetIntValue();
- else orig_step_size = 1; // Unset
+
+ if (pStep)
+ {
+ orig_step_size = pStep->GetArgN(0)->GetIntValue();
+ }
+ else
+ {
+ orig_step_size = 1; // Unset
+ }
MHParseNode *pStyle = p->GetNamedArg(C_SLIDER_STYLE);
- if (pStyle) m_style = (enum SliderStyle)pStyle->GetArgN(0)->GetEnumValue();
- else m_style = SliderNormal;
+
+ if (pStyle)
+ {
+ m_style = (enum SliderStyle)pStyle->GetArgN(0)->GetEnumValue();
+ }
+ else
+ {
+ m_style = SliderNormal;
+ }
MHParseNode *pslCol = p->GetNamedArg(C_SLIDER_REF_COLOUR);
- if (pslCol) m_sliderRefColour.Initialise(pslCol->GetArgN(0), engine);
- else engine->GetDefaultSliderRefColour(m_sliderRefColour);
+
+ if (pslCol)
+ {
+ m_sliderRefColour.Initialise(pslCol->GetArgN(0), engine);
+ }
+ else
+ {
+ engine->GetDefaultSliderRefColour(m_sliderRefColour);
+ }
}
static const char *rchOrientation[] =
@@ -496,9 +731,14 @@ static const char *rchOrientation[] =
// Look up the Orientation. Returns zero if it doesn't match. Used in the text parser only.
int MHSlider::GetOrientation(const char *str)
{
- for (int i = 0; i < (int)(sizeof(rchOrientation)/sizeof(rchOrientation[0])); i++) {
- if (strcasecmp(str, rchOrientation[i]) == 0) return (i+1); // Numbered from 1
+ for (int i = 0; i < (int)(sizeof(rchOrientation) / sizeof(rchOrientation[0])); i++)
+ {
+ if (strcasecmp(str, rchOrientation[i]) == 0)
+ {
+ return (i + 1); // Numbered from 1
+ }
}
+
return 0;
}
@@ -511,54 +751,73 @@ static const char *rchStyle[] =
int MHSlider::GetStyle(const char *str)
{
- for (int i = 0; i < (int)(sizeof(rchStyle)/sizeof(rchStyle[0])); i++) {
- if (strcasecmp(str, rchStyle[i]) == 0) return (i+1); // Numbered from 1
+ for (int i = 0; i < (int)(sizeof(rchStyle) / sizeof(rchStyle[0])); i++)
+ {
+ if (strcasecmp(str, rchStyle[i]) == 0)
+ {
+ return (i + 1); // Numbered from 1
+ }
}
+
return 0;
}
void MHSlider::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:Slider ");
- MHVisible::PrintMe(fd, nTabs+1);
- MHInteractible::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:Slider ");
+ MHVisible::PrintMe(fd, nTabs + 1);
+ MHInteractible::PrintMe(fd, nTabs + 1);
- PrintTabs(fd, nTabs); fprintf(fd, ":Orientation %s\n", rchOrientation[m_orientation-1]);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, ":Orientation %s\n", rchOrientation[m_orientation-1]);
- if (initial_value >= orig_min_value) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":InitialValue %d\n", initial_value);
+ if (initial_value >= orig_min_value)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":InitialValue %d\n", initial_value);
}
- if (orig_min_value != 1) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":MinValue %d\n", orig_min_value);
+ if (orig_min_value != 1)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":MinValue %d\n", orig_min_value);
}
- if (orig_max_value > orig_min_value) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":MaxValue %d\n", orig_max_value);
+ if (orig_max_value > orig_min_value)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":MaxValue %d\n", orig_max_value);
}
- if (initial_portion >= orig_min_value) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":InitialPortion %d\n", initial_portion);
+ if (initial_portion >= orig_min_value)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":InitialPortion %d\n", initial_portion);
}
- if (orig_step_size != 1) {
- PrintTabs(fd, nTabs+1); fprintf(fd, ":StepSize %d\n", orig_step_size);
+ if (orig_step_size != 1)
+ {
+ PrintTabs(fd, nTabs + 1);
+ fprintf(fd, ":StepSize %d\n", orig_step_size);
}
if (m_style != SliderNormal)
{
- PrintTabs(fd, nTabs+1);
+ PrintTabs(fd, nTabs + 1);
fprintf(fd, ":SliderStyle %s\n", rchStyle[m_style-1]);
}
- if (m_sliderRefColour.IsSet()) {
- PrintTabs(fd, nTabs+1);
+ if (m_sliderRefColour.IsSet())
+ {
+ PrintTabs(fd, nTabs + 1);
fprintf(fd, ":SliderRefColour ");
- m_sliderRefColour.PrintMe(fd, nTabs+2);
+ m_sliderRefColour.PrintMe(fd, nTabs + 2);
fprintf(fd, "\n");
}
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
// The MHEG standard doesn't define where the internal values are
@@ -577,63 +836,82 @@ void MHSlider::Display(MHEngine *engine)
{
MHContext *d = engine->GetContext();
MHRgba colour;
+
if (m_fHighlightStatus && m_fEngineResp)
+ {
colour = GetColour(m_highlightRefColour);
- else colour = GetColour(m_sliderRefColour);
+ }
+ else
+ {
+ colour = GetColour(m_sliderRefColour);
+ }
int major; // Direction of change.
+
if (m_orientation == SliderLeft || m_orientation == SliderRight)
+ {
major = m_nBoxWidth;
- else major = m_nBoxHeight;
+ }
+ else
+ {
+ major = m_nBoxHeight;
+ }
- if (max_value <= min_value) return; // Avoid divide by zero if error.
+ if (max_value <= min_value)
+ {
+ return; // Avoid divide by zero if error.
+ }
if (m_style == SliderNormal)
{
// This is drawn as a 9 pixel wide "thumb" at the position.
major -= 9; // Width of "thumb"
- int posn = major * (slider_value-min_value) / (max_value-min_value);
+ int posn = major * (slider_value - min_value) / (max_value - min_value);
+
switch (m_orientation)
{
- case SliderLeft:
- d->DrawRect(m_nPosX + posn, m_nPosY, 9, m_nBoxHeight, colour);
- break;
- case SliderRight:
- d->DrawRect(m_nPosX + m_nBoxWidth - posn - 9, m_nPosY, 9, m_nBoxHeight, colour);
- break;
- case SliderUp:
- d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - posn - 9, m_nBoxWidth, 9, colour);
- break;
- case SliderDown:
- d->DrawRect(m_nPosX, m_nPosY + posn, m_nBoxWidth, 9, colour);
- break;
+ case SliderLeft:
+ d->DrawRect(m_nPosX + posn, m_nPosY, 9, m_nBoxHeight, colour);
+ break;
+ case SliderRight:
+ d->DrawRect(m_nPosX + m_nBoxWidth - posn - 9, m_nPosY, 9, m_nBoxHeight, colour);
+ break;
+ case SliderUp:
+ d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - posn - 9, m_nBoxWidth, 9, colour);
+ break;
+ case SliderDown:
+ d->DrawRect(m_nPosX, m_nPosY + posn, m_nBoxWidth, 9, colour);
+ break;
}
}
- else {
+ else
+ {
// Thermometer and proportional sliders are drawn as bars. Thermometers
// run from the start to the position, proportional sliders from the
// position for the "portion".
int start = 0;
- int end = major * (slider_value-min_value) / (max_value-min_value);
+ int end = major * (slider_value - min_value) / (max_value - min_value);
+
if (m_style == SliderProp)
{
start = end;
- end = major * (slider_value+portion -min_value) / (max_value-min_value);
+ end = major * (slider_value + portion - min_value) / (max_value - min_value);
}
+
switch (m_orientation)
{
- case SliderLeft:
- d->DrawRect(m_nPosX + start, m_nPosY, end-start, m_nBoxHeight, colour);
- break;
- case SliderRight:
- d->DrawRect(m_nPosX + m_nBoxWidth - end, m_nPosY, end-start, m_nBoxHeight, colour);
- break;
- case SliderUp:
- d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - end, m_nBoxWidth, end-start, colour);
- break;
- case SliderDown:
- d->DrawRect(m_nPosX, m_nPosY + start, m_nBoxWidth, end-start, colour);
- break;
+ case SliderLeft:
+ d->DrawRect(m_nPosX + start, m_nPosY, end - start, m_nBoxHeight, colour);
+ break;
+ case SliderRight:
+ d->DrawRect(m_nPosX + m_nBoxWidth - end, m_nPosY, end - start, m_nBoxHeight, colour);
+ break;
+ case SliderUp:
+ d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - end, m_nBoxWidth, end - start, colour);
+ break;
+ case SliderDown:
+ d->DrawRect(m_nPosX, m_nPosY + start, m_nBoxWidth, end - start, colour);
+ break;
}
}
@@ -662,48 +940,72 @@ void MHSlider::KeyEvent(MHEngine *engine, int nCode)
{
switch (nCode)
{
- case 15: // Select key
- case 16: // Cancel key
- m_fInteractionStatus = false;
- engine->SetInteraction(0);
- InteractionCompleted(engine); // Interaction is interrupted.
- engine->EventTriggered(this, EventInteractionCompleted);
- break;
-
- case 1: // Up
- if (m_orientation == SliderUp)
- Increment(engine);
- else if (m_orientation == SliderDown)
- Decrement(engine);
- break;
-
- case 2: // Down
- if (m_orientation == SliderUp)
- Decrement(engine);
- else if (m_orientation == SliderDown)
- Increment(engine);
- break;
-
- case 3: // Left
- if (m_orientation == SliderLeft)
- Increment(engine);
- else if (m_orientation == SliderRight)
- Decrement(engine);
- break;
-
- case 4: // Right
- if (m_orientation == SliderLeft)
- Decrement(engine);
- else if (m_orientation == SliderRight)
- Increment(engine);
- break;
+ case 15: // Select key
+ case 16: // Cancel key
+ m_fInteractionStatus = false;
+ engine->SetInteraction(0);
+ InteractionCompleted(engine); // Interaction is interrupted.
+ engine->EventTriggered(this, EventInteractionCompleted);
+ break;
+
+ case 1: // Up
+
+ if (m_orientation == SliderUp)
+ {
+ Increment(engine);
+ }
+ else if (m_orientation == SliderDown)
+ {
+ Decrement(engine);
+ }
+
+ break;
+
+ case 2: // Down
+
+ if (m_orientation == SliderUp)
+ {
+ Decrement(engine);
+ }
+ else if (m_orientation == SliderDown)
+ {
+ Increment(engine);
+ }
+
+ break;
+
+ case 3: // Left
+
+ if (m_orientation == SliderLeft)
+ {
+ Increment(engine);
+ }
+ else if (m_orientation == SliderRight)
+ {
+ Decrement(engine);
+ }
+
+ break;
+
+ case 4: // Right
+
+ if (m_orientation == SliderLeft)
+ {
+ Decrement(engine);
+ }
+ else if (m_orientation == SliderRight)
+ {
+ Increment(engine);
+ }
+
+ break;
}
}
void MHSlider::Increment(MHEngine *engine)
{
- if (slider_value+step_size <= max_value)
+ if (slider_value + step_size <= max_value)
{
slider_value += step_size;
engine->Redraw(GetVisibleArea());
@@ -713,7 +1015,7 @@ void MHSlider::Increment(MHEngine *engine)
void MHSlider::Decrement(MHEngine *engine)
{
- if (slider_value-step_size >= min_value)
+ if (slider_value - step_size >= min_value)
{
slider_value -= step_size;
engine->Redraw(GetVisibleArea());
@@ -724,21 +1026,36 @@ void MHSlider::Decrement(MHEngine *engine)
void MHSlider::Step(int nbSteps, MHEngine *engine)
{
step_size = nbSteps;
- if (m_fRunning) engine->Redraw(GetVisibleArea());
+
+ if (m_fRunning)
+ {
+ engine->Redraw(GetVisibleArea());
+ }
+
engine->EventTriggered(this, EventSliderValueChanged);
}
void MHSlider::SetSliderValue(int newValue, MHEngine *engine)
{
slider_value = newValue;
- if (m_fRunning) engine->Redraw(GetVisibleArea());
+
+ if (m_fRunning)
+ {
+ engine->Redraw(GetVisibleArea());
+ }
+
engine->EventTriggered(this, EventSliderValueChanged);
}
void MHSlider::SetPortion(int newPortion, MHEngine *engine)
{
portion = newPortion;
- if (m_fRunning) engine->Redraw(GetVisibleArea());
+
+ if (m_fRunning)
+ {
+ engine->Redraw(GetVisibleArea());
+ }
+
engine->EventTriggered(this, EventSliderValueChanged);
}
@@ -749,7 +1066,12 @@ void MHSlider::SetSliderParameters(int newMin, int newMax, int newStep, MHEngine
max_value = newMax;
step_size = newStep;
slider_value = newMin;
- if (m_fRunning) engine->Redraw(GetVisibleArea());
+
+ if (m_fRunning)
+ {
+ engine->Redraw(GetVisibleArea());
+ }
+
engine->EventTriggered(this, EventSliderValueChanged);
}
@@ -773,11 +1095,13 @@ void MHEntryField::Initialise(MHParseNode *p, MHEngine *engine)
void MHEntryField::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:EntryField ");
- MHVisible::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:EntryField ");
+ MHVisible::PrintMe(fd, nTabs + 1);
MHInteractible::PrintMe(fd, nTabs);
fprintf(fd, "****TODO\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
MHButton::MHButton()
@@ -820,10 +1144,12 @@ void MHHotSpot::Initialise(MHParseNode *p, MHEngine *engine)
void MHHotSpot::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:Hotspot ");
- MHButton::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:Hotspot ");
+ MHButton::PrintMe(fd, nTabs + 1);
fprintf(fd, "****TODO\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
MHPushButton::MHPushButton()
@@ -844,10 +1170,12 @@ void MHPushButton::Initialise(MHParseNode *p, MHEngine *engine)
void MHPushButton::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:PushButton ");
- MHButton::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:PushButton ");
+ MHButton::PrintMe(fd, nTabs + 1);
fprintf(fd, "****TODO\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
MHSwitchButton::MHSwitchButton()
@@ -868,28 +1196,49 @@ void MHSwitchButton::Initialise(MHParseNode *p, MHEngine *engine)
void MHSwitchButton::PrintMe(FILE *fd, int nTabs) const
{
- PrintTabs(fd, nTabs); fprintf(fd, "{:SwitchButton ");
- MHPushButton::PrintMe(fd, nTabs+1);
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "{:SwitchButton ");
+ MHPushButton::PrintMe(fd, nTabs + 1);
fprintf(fd, "****TODO\n");
- PrintTabs(fd, nTabs); fprintf(fd, "}\n");
+ PrintTabs(fd, nTabs);
+ fprintf(fd, "}\n");
}
void MHSetColour::Initialise(MHParseNode *p, MHEngine *engine)
{
MHElemAction::Initialise(p, engine);
- if (p->GetArgCount() > 1) {
+
+ if (p->GetArgCount() > 1)
+ {
MHParseNode *pIndexed = p->GetNamedArg(C_NEW_COLOUR_INDEX);
MHParseNode *pAbsolute = p->GetNamedArg(C_NEW_ABSOLUTE_COLOUR);
- if (pIndexed) { m_ColourType = CT_Indexed; m_Indexed.Initialise(pIndexed->GetArgN(0), engine); }
- else if (pAbsolute) { m_ColourType = CT_Absolute; m_Absolute.Initialise(pAbsolute->GetArgN(0), engine); }
+
+ if (pIndexed)
+ {
+ m_ColourType = CT_Indexed;
+ m_Indexed.Initialise(pIndexed->GetArgN(0), engine);
+ }
+ else if (pAbsolute)
+ {
+ m_ColourType = CT_Absolute;
+ m_Absolute.Initialise(pAbsolute->GetArgN(0), engine);
+ }
}
}
void MHSetColour::PrintArgs(FILE *fd, int) const
{
- if (m_ColourType == CT_Indexed) { fprintf(fd, ":NewColourIndex "); m_Indexed.PrintMe(fd, 0); }
- else if (m_ColourType == CT_Absolute) { fprintf(fd, ":NewAbsoluteColour "); m_Absolute.PrintMe(fd, 0); }
+ if (m_ColourType == CT_Indexed)
+ {
+ fprintf(fd, ":NewColourIndex ");
+ m_Indexed.PrintMe(fd, 0);
+ }
+ else if (m_ColourType == CT_Absolute)
+ {
+ fprintf(fd, ":NewAbsoluteColour ");
+ m_Absolute.PrintMe(fd, 0);
+ }
}
void MHSetColour::Perform(MHEngine *engine)
@@ -897,23 +1246,25 @@ void MHSetColour::Perform(MHEngine *engine)
MHObjectRef target;
m_Target.GetValue(target, engine); // Get the item to set.
MHColour newColour;
+
switch (m_ColourType)
{
- case CT_None:
+ case CT_None:
{
// If the colour is not specified use "transparent".
newColour.SetFromString("\000\000\000\377", 4);
break;
}
- case CT_Absolute:
+ case CT_Absolute:
{
MHOctetString colour;
m_Absolute.GetValue(colour, engine);
newColour.m_ColStr.Copy(colour);
break;
}
- case CT_Indexed:
- newColour.m_nColIndex = m_Indexed.GetValue(engine);
+ case CT_Indexed:
+ newColour.m_nColIndex = m_Indexed.GetValue(engine);
}
+
SetColour(newColour, engine); // Set the colour of the appropriate portion of the visible
}
diff --git a/mythtv/libs/libmythfreemheg/Visible.h b/mythtv/libs/libmythfreemheg/Visible.h
index 33a8debbee1..61fcd5a5207 100644
--- a/mythtv/libs/libmythfreemheg/Visible.h
+++ b/mythtv/libs/libmythfreemheg/Visible.h
@@ -34,7 +34,7 @@ class MHEngine;
class MHVisible : public MHPresentable
{
-public:
+ public:
MHVisible();
MHVisible(const MHVisible &ref);
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -67,7 +67,7 @@ class MHVisible : public MHPresentable
// Reset the position - used by ListGroup.
virtual void ResetPosition() { m_nPosX = m_nOriginalPosX; m_nPosY = m_nOriginalPosY; }
-protected:
+ protected:
// Exchange attributes
int m_nOriginalBoxWidth, m_nOriginalBoxHeight;
int m_nOriginalPosX, m_nOriginalPosY;
@@ -83,7 +83,7 @@ class MHVisible : public MHPresentable
class MHLineArt : public MHVisible
{
-public:
+ public:
MHLineArt();
MHLineArt(const MHLineArt &ref);
virtual const char *ClassName() { return "LineArt"; }
@@ -98,7 +98,7 @@ class MHLineArt : public MHVisible
virtual void SetLineWidth(int nWidth, MHEngine *engine);
virtual void SetLineStyle(int nStyle, MHEngine *engine);
-protected:
+ protected:
// Exchanged attributes,
bool m_fBorderedBBox; // Does it have lines round or not?
int m_nOriginalLineWidth;
@@ -113,7 +113,7 @@ class MHLineArt : public MHVisible
class MHRectangle : public MHLineArt
{
-public:
+ public:
MHRectangle() {}
MHRectangle(const MHRectangle &ref): MHLineArt(ref) {}
virtual const char *ClassName() { return "Rectangle"; }
@@ -128,7 +128,7 @@ class MHRectangle : public MHLineArt
// in various classes which complicates inheritance.
class MHInteractible
{
-public:
+ public:
MHInteractible(MHVisible *parent);
virtual ~MHInteractible();
void Initialise(MHParseNode *p, MHEngine *engine);
@@ -149,7 +149,7 @@ class MHInteractible
// of derived classes.
void InteractDeactivation(void) { m_fInteractionStatus = false; }
-protected:
+ protected:
// Exchanged attributes
bool m_fEngineResp;
MHColour m_highlightRefColour;
@@ -157,13 +157,13 @@ class MHInteractible
bool m_fHighlightStatus;
bool m_fInteractionStatus;
-private:
+ private:
MHVisible *m_parent;
};
class MHSlider : public MHVisible, public MHInteractible
{
-public:
+ public:
MHSlider();
virtual ~MHSlider();
virtual const char *ClassName() { return "Slider"; }
@@ -197,7 +197,7 @@ class MHSlider : public MHVisible, public MHInteractible
// Enumerated type lookup functions for the text parser.
static int GetOrientation(const char *str);
static int GetStyle(const char *str);
-protected:
+ protected:
void Increment(MHEngine *engine);
void Decrement(MHEngine *engine);
@@ -221,7 +221,7 @@ class MHSlider : public MHVisible, public MHInteractible
class MHEntryField : public MHVisible, public MHInteractible
{
-public:
+ public:
MHEntryField();
virtual ~MHEntryField();
virtual const char *ClassName() { return "EntryField"; }
@@ -242,7 +242,7 @@ class MHEntryField : public MHVisible, public MHInteractible
// Button - not needed for UK MHEG.
class MHButton : public MHVisible
{
-public:
+ public:
MHButton();
virtual ~MHButton();
virtual void Initialise(MHParseNode *p, MHEngine *engine);
@@ -253,7 +253,7 @@ class MHButton : public MHVisible
// HotSpot - not needed for UK MHEG.
class MHHotSpot : public MHButton
{
-public:
+ public:
MHHotSpot();
virtual ~MHHotSpot();
virtual const char *ClassName() { return "HotSpot"; }
@@ -265,7 +265,7 @@ class MHHotSpot : public MHButton
// PushButton - not needed for UK MHEG.
class MHPushButton : public MHButton
{
-public:
+ public:
MHPushButton();
virtual ~MHPushButton();
virtual const char *ClassName() { return "PushButton"; }
@@ -277,7 +277,7 @@ class MHPushButton : public MHButton
// SwitchButton - not needed for UK MHEG.
class MHSwitchButton : public MHPushButton
{
-public:
+ public:
MHSwitchButton();
virtual ~MHSwitchButton();
virtual const char *ClassName() { return "SwitchButton"; }
@@ -291,11 +291,11 @@ class MHSwitchButton : public MHPushButton
// Set Line or Fill colour
class MHSetColour: public MHElemAction
{
-public:
+ public:
MHSetColour(const char *name): MHElemAction(name), m_ColourType(CT_None) { }
virtual void Initialise(MHParseNode *p, MHEngine *engine);
virtual void Perform(MHEngine *engine);
-protected:
+ protected:
virtual void PrintArgs(FILE *fd, int nTabs) const;
virtual void SetColour(const MHColour &colour, MHEngine *engine) = 0;
// The colour can be specified as either an index or an absolute colour.
@@ -306,23 +306,23 @@ class MHSetColour: public MHElemAction
};
class MHSetLineColour: public MHSetColour {
-public:
+ public:
MHSetLineColour(): MHSetColour(":SetLineColour") { }
-protected:
+ protected:
virtual void SetColour(const MHColour &colour, MHEngine *engine) { Target(engine)->SetLineColour(colour, engine); }
};
class MHSetFillColour: public MHSetColour {
-public:
+ public:
MHSetFillColour(): MHSetColour(":SetFillColour") { }
-protected:
+ protected:
virtual void SetColour(const MHColour &colour, MHEngine *engine) { Target(engine)->SetFillColour(colour, engine); }
};
// BringToFront - bring a visible to the front of the display stack.
class MHBringToFront: public MHElemAction
{
-public:
+ public:
MHBringToFront(): MHElemAction(":BringToFront") {}
virtual void Perform(MHEngine *engine) { Target(engine)->BringToFront(engine); }
};
@@ -330,7 +330,7 @@ class MHBringToFront: public MHElemAction
// PutBefore - put a visible in front of another.
class MHPutBefore: public MHActionGenericObjectRef
{
-public:
+ public:
MHPutBefore(): MHActionGenericObjectRef(":PutBefore") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pRef) { pTarget->PutBefore(pRef, engine); }
};
@@ -338,7 +338,7 @@ class MHPutBefore: public MHActionGenericObjectRef
// PutBehind - put a visible behind another.
class MHPutBehind: public MHActionGenericObjectRef
{
-public:
+ public:
MHPutBehind(): MHActionGenericObjectRef(":PutBehind") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pRef) { pTarget->PutBehind(pRef, engine); }
};
@@ -346,21 +346,21 @@ class MHPutBehind: public MHActionGenericObjectRef
// SendToBack - put a visible at the bottom of the display stack.
class MHSendToBack: public MHElemAction
{
-public:
+ public:
MHSendToBack(): MHElemAction(":SendToBack") {}
virtual void Perform(MHEngine *engine) { Target(engine)->SendToBack(engine); }
};
class MHSetPosition: public MHActionIntInt
{
-public:
+ public:
MHSetPosition(): MHActionIntInt(":SetPosition") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2) { pTarget->SetPosition(nArg1, nArg2, engine); };
};
class MHSetBoxSize: public MHActionIntInt
{
-public:
+ public:
MHSetBoxSize(): MHActionIntInt(":SetBoxSize") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg1, int nArg2) { pTarget->SetBoxSize(nArg1, nArg2, engine); }
};
@@ -368,7 +368,7 @@ class MHSetBoxSize: public MHActionIntInt
// Get box size of a visible
class MHGetBoxSize: public MHActionObjectRef2
{
-public:
+ public:
MHGetBoxSize(): MHActionObjectRef2(":GetBoxSize") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pArg1, MHRoot *pArg2) { pTarget->GetBoxSize(pArg1, pArg2); }
};
@@ -376,28 +376,28 @@ class MHGetBoxSize: public MHActionObjectRef2
// GetPosition of a visible
class MHGetPosition: public MHActionObjectRef2
{
-public:
+ public:
MHGetPosition(): MHActionObjectRef2(":GetPosition") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pArg1, MHRoot *pArg2) { pTarget->GetPosition(pArg1, pArg2); }
};
class MHSetLineWidth: public MHActionInt
{
-public:
+ public:
MHSetLineWidth(): MHActionInt(":SetLineWidth") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) { pTarget->SetLineWidth(nArg, engine); };
};
class MHSetLineStyle: public MHActionInt
{
-public:
+ public:
MHSetLineStyle(): MHActionInt(":SetLineStyle") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) { pTarget->SetLineStyle(nArg, engine); };
};
class MHSetInteractionStatus: public MHActionBool
{
-public:
+ public:
MHSetInteractionStatus(): MHActionBool("SetInteractionStatus") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, bool newStatus)
{ Target(engine)->SetInteractionStatus(newStatus, engine); }
@@ -405,7 +405,7 @@ class MHSetInteractionStatus: public MHActionBool
class MHGetInteractionStatus: public MHActionObjectRef
{
-public:
+ public:
MHGetInteractionStatus(): MHActionObjectRef(":GetInteractionStatus") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pResult)
{ pResult->SetVariableValue(pTarget->GetInteractionStatus());}
@@ -413,7 +413,7 @@ class MHGetInteractionStatus: public MHActionObjectRef
class MHSetHighlightStatus: public MHActionBool
{
-public:
+ public:
MHSetHighlightStatus(): MHActionBool("SetHighlightStatus") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, bool newStatus)
{ Target(engine)->SetHighlightStatus(newStatus, engine); }
@@ -421,7 +421,7 @@ class MHSetHighlightStatus: public MHActionBool
class MHGetHighlightStatus: public MHActionObjectRef
{
-public:
+ public:
MHGetHighlightStatus(): MHActionObjectRef(":GetHighlightStatus") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pResult)
{ pResult->SetVariableValue(pTarget->GetHighlightStatus());}
@@ -429,21 +429,21 @@ class MHGetHighlightStatus: public MHActionObjectRef
class MHStep: public MHActionInt
{
-public:
+ public:
MHStep(): MHActionInt(":Step") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) { pTarget->Step(nArg, engine); };
};
class MHSetSliderValue: public MHActionInt
{
-public:
+ public:
MHSetSliderValue(): MHActionInt(":SetSliderValue") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) { pTarget->SetSliderValue(nArg, engine); };
};
class MHGetSliderValue: public MHActionObjectRef
{
-public:
+ public:
MHGetSliderValue(): MHActionObjectRef(":GetSliderValue") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pResult)
{ pResult->SetVariableValue(pTarget->GetSliderValue());}
@@ -451,14 +451,14 @@ class MHGetSliderValue: public MHActionObjectRef
class MHSetPortion: public MHActionInt
{
-public:
+ public:
MHSetPortion(): MHActionInt(":SetPortion") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int nArg) { pTarget->SetPortion(nArg, engine); };
};
class MHGetPortion: public MHActionObjectRef
{
-public:
+ public:
MHGetPortion(): MHActionObjectRef(":GetPortion") {}
virtual void CallAction(MHEngine *, MHRoot *pTarget, MHRoot *pResult)
{ pResult->SetVariableValue(pTarget->GetPortion());}
@@ -466,7 +466,7 @@ class MHGetPortion: public MHActionObjectRef
class MHSetSliderParameters: public MHActionInt3
{
-public:
+ public:
MHSetSliderParameters(): MHActionInt3(":SetSliderParameters") {}
virtual void CallAction(MHEngine *engine, MHRoot *pTarget, int newMin, int newMax, int newStep)
{ pTarget->SetSliderParameters(newMin, newMax, newStep, engine); };
diff --git a/mythtv/libs/libmythfreemheg/freemheg.h b/mythtv/libs/libmythfreemheg/freemheg.h
index 6421c229353..0b61f653bf0 100644
--- a/mythtv/libs/libmythfreemheg/freemheg.h
+++ b/mythtv/libs/libmythfreemheg/freemheg.h
@@ -41,7 +41,7 @@ extern void MHSetLogging(FILE *logStream, unsigned int logLevel);
// This abstract class is implemented by the MHEG Engine.
class MHEG
{
-public:
+ public:
virtual ~MHEG() {}
virtual void SetBooting() = 0;
virtual void DrawDisplay(QRegion toDraw) = 0;
@@ -68,7 +68,7 @@ enum {
class MHRgba
{
-public:
+ public:
MHRgba(int red, int green, int blue, int alpha):
m_red(red), m_green(green), m_blue(blue), m_alpha(alpha) {};
MHRgba(): m_red(0), m_green(0), m_blue(0), m_alpha(0) {};
@@ -76,7 +76,7 @@ class MHRgba
int green() const { return m_green; }
int blue() const { return m_blue; }
int alpha() const { return m_alpha; }
-private:
+ private:
unsigned char m_red, m_green, m_blue, m_alpha;
};
@@ -84,7 +84,7 @@ class MHRgba
// for the MHEG engine.
class MHContext
{
-public:
+ public:
virtual ~MHContext() {} // Declared to avoid warnings
// Interface to MHEG engine.
@@ -143,8 +143,9 @@ class MHContext
};
// Dynamic Line Art objects record a sequence of drawing actions.
-class MHDLADisplay {
-public:
+class MHDLADisplay
+{
+ public:
virtual ~MHDLADisplay() {}
// Draw the completed drawing onto the display.
virtual void Draw(int x, int y) = 0;
@@ -164,7 +165,7 @@ class MHDLADisplay {
};
class MHTextDisplay {
-public:
+ public:
virtual ~MHTextDisplay() {}
// Draw the completed drawing onto the display. x and y give the position of the image
// relative to the screen. rect gives the bounding box for the image, again relative to
@@ -179,8 +180,9 @@ class MHTextDisplay {
virtual void AddText(int x, int y, const QString &, MHRgba colour) = 0;
};
-class MHBitmapDisplay {
-public:
+class MHBitmapDisplay
+{
+ public:
virtual ~MHBitmapDisplay() {}
// Draw the completed drawing onto the display. x and y give the position of the image
// relative to the screen. rect gives the bounding box for the image, again relative to